This feature is in Developer Preview and is subject to change.
CLI Documentation Notice
You're viewing documentation for the new Wix CLI, which we recommend for all new projects. Determine which CLI your project uses.
When you generate a data collections extension, the CLI adds the following files to your project:
data-collections.extension.ts: Builds the data collections extension.<your-collection-name>.ts: Defines the collection's schema, permissions, indexes, and initial data. Each file represents a collection.The CLI also adds an import and a .use() call to your project's extensions.ts file so the extension is registered with your project.
Note: You can move these files to any location in the src/ folder and update the references in your extensions.ts file. Learn more about the flexible file system.
The data-collections.extension.ts file contains the data collections extension's builder configuration. The builder is defined using the following schema:
Here's an example builder definition with 2 registered collections:
The following fields can be used in the builder's configuration object:
| Field | Type | Description |
|---|---|---|
id | string | Required. The data collections extension ID as a GUID. Wix automatically generates it when you add the extension. It must be unique across all extensions in the project. |
name | string | Required. A human-readable name for the extension. Defaults to 'Data Collections'. You can edit it directly in the file, and view it in the app dashboard under Extensions. |
collections | array | Required. The default exports from each <your-collection-name>.ts collection definition file you want this extension to register. Each time you generate a new collection, the CLI adds it to this array. |
Each <your-collection-name>.ts file defines a single collection. The default export is an object that follows the schema documented in the data collections extension JSON reference.
Each collection definition file comes with default fields, default permissions, and other configuration that you can customize. The starting file looks like this:
The file also exports a named constant, collectionIdSuffix, which has the same string used as idSuffix. To reference this collection elsewhere in your project, import this constant from your backend code.
The default export object accepts the following top-level fields. For the full schema, including supported field types, permission roles, index options, and the initial-data format, see the data collections extension JSON reference.
| Field | Type | Description |
|---|---|---|
idSuffix | string | Required. The suffix appended to the full collection ID. The full ID in the CMS becomes @<company>/<app-name>/<idSuffix>. It must be 1-36 characters and can only contain letters, numbers, underscores, and hyphens. |
displayName | string | Required. The collection's display name in the CMS. |
displayField | string | Required. The key of the field used to identify items in this collection when they're referenced from other collections. |
fields | array | Required. The collection's schema. See the supported field types. |
dataPermissions | object | Required. The role required for each item action: itemInsert, itemRead, itemRemove, and itemUpdate. |
indexes | array | Indexes to improve query performance. |
initialData | array | Items to seed the collection with when it's first created on a site. Each item must conform to the schema declared in fields. |