Data Collections Extension Files and Code

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:

Copy

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.

Data collections builder file

The data-collections.extension.ts file contains the data collections extension's builder configuration. The builder is defined using the following schema:

Copy

Here's an example builder definition with 2 registered collections:

Copy

Data collection builder fields

The following fields can be used in the builder's configuration object:

FieldTypeDescription
idstringRequired. 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.
namestringRequired. 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.
collectionsarrayRequired. 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.

Data collection definition file

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:

Copy

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.

Collection fields

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.

FieldTypeDescription
idSuffixstringRequired. 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.
displayNamestringRequired. The collection's display name in the CMS.
displayFieldstringRequired. The key of the field used to identify items in this collection when they're referenced from other collections.
fieldsarrayRequired. The collection's schema. See the supported field types.
dataPermissionsobjectRequired. The role required for each item action: itemInsert, itemRead, itemRemove, and itemUpdate.
indexesarrayIndexes to improve query performance.
initialDataarrayItems to seed the collection with when it's first created on a site. Each item must conform to the schema declared in fields.

See also

Did this help?