Hub JS Package

Hub JS Package

  • Users
  • Buckets
  • Threads
  • Textile Docs

@textile/hub > CollectionConfig

CollectionConfig interface

CollectionConfig is the configuration options for creating and updating a Collection. It supports the following configuration options: - Name: The name of the collection, e.g, "Animals" (must be unique per DB). - Schema: A JSON Schema), which is used for instance validation. - Indexes: An optional list of index configurations, which define how instances are indexed. - WriteValidator: An optional JavaScript (ECMAScript 5.1) function that is used to validate instances on write. - ReadFilter: An optional JavaScript (ECMAScript 5.1) function that is used to filter instances on read.

The writeValidator function receives three arguments: - writer: The multibase-encoded public key identity of the writer. - event: An object describing the update event (see core.Event). - instance: The current instance as a JavaScript object before the update event is applied.

A falsy return value indicates a failed validation. Note that the function arguments must be named as documented here (writer, event, instance). These functions run in a secure sandbox where these argument names are specified.

Having access to writer, event, and instance opens the door to a variety of app-specific logic. Textile Buckets file-level access roles are implemented in part with a write validator.

The readFilter function receives three arguments: - reader: The multibase-encoded public key identity of the reader. - instance: The current instance as a JavaScript object.

The function must return a JavaScript object. Most implementations will modify and return the current instance. Note that the function arguments must be named as documented here (reader, instance). These functions run in a secure sandbox where these argument names are specified. Like write validation, read filtering opens the door to a variety of app-specific logic. Textile Buckets file-level access roles are implemented in part with a read filter.

Signature:

export interface CollectionConfig<W = any, R = W> 

Properties

PropertyTypeDescription
indexes?pb.Index.AsObject[](Optional)
namestring
readFilter?((reader: string, instance: R) => R) | string(Optional)
schema?JSONSchema3or4 | any(Optional)
writeValidator?((writer: string, event: Event, instance: W) => boolean) | string(Optional)
  • CollectionConfig interface
  • Properties
Hub JS Package
Docs
Getting StartedThreadDBBuckets
Resources
All DocumentationProject SlackBlog
More
GitHubStar
Follow @textileio