@wix/patterns-cms 1.10.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/cjs/adapter/__tests__/createCmsSchemaSource.spec.js +10 -11
  2. package/dist/cjs/adapter/__tests__/createCmsSchemaSource.spec.js.map +1 -1
  3. package/dist/cjs/adapter/createCmsSchemaSource.js +4 -12
  4. package/dist/cjs/adapter/createCmsSchemaSource.js.map +1 -1
  5. package/dist/cjs/adapter/index.js +3 -1
  6. package/dist/cjs/adapter/index.js.map +1 -1
  7. package/dist/cjs/adapter/listCmsCollections.js +15 -0
  8. package/dist/cjs/adapter/listCmsCollections.js.map +1 -0
  9. package/dist/cjs/testkit/cmsFetchMocks.js +165 -0
  10. package/dist/cjs/testkit/cmsFetchMocks.js.map +1 -0
  11. package/dist/cjs/testkit/index.js +10 -0
  12. package/dist/cjs/testkit/index.js.map +1 -0
  13. package/dist/esm/adapter/__tests__/createCmsSchemaSource.spec.js +6 -15
  14. package/dist/esm/adapter/__tests__/createCmsSchemaSource.spec.js.map +1 -1
  15. package/dist/esm/adapter/createCmsSchemaSource.js +4 -20
  16. package/dist/esm/adapter/createCmsSchemaSource.js.map +1 -1
  17. package/dist/esm/adapter/index.js +1 -0
  18. package/dist/esm/adapter/index.js.map +1 -1
  19. package/dist/esm/adapter/listCmsCollections.js +13 -0
  20. package/dist/esm/adapter/listCmsCollections.js.map +1 -0
  21. package/dist/esm/testkit/cmsFetchMocks.js +115 -0
  22. package/dist/esm/testkit/cmsFetchMocks.js.map +1 -0
  23. package/dist/esm/testkit/index.js +2 -0
  24. package/dist/esm/testkit/index.js.map +1 -0
  25. package/dist/types/adapter/createCmsSchemaSource.d.ts.map +1 -1
  26. package/dist/types/adapter/index.d.ts +1 -0
  27. package/dist/types/adapter/index.d.ts.map +1 -1
  28. package/dist/types/adapter/listCmsCollections.d.ts +7 -0
  29. package/dist/types/adapter/listCmsCollections.d.ts.map +1 -0
  30. package/dist/types/testkit/cmsFetchMocks.d.ts +47 -0
  31. package/dist/types/testkit/cmsFetchMocks.d.ts.map +1 -0
  32. package/dist/types/testkit/index.d.ts +2 -0
  33. package/dist/types/testkit/index.d.ts.map +1 -0
  34. package/package.json +20 -6
  35. package/testkit/package.json +6 -0
@@ -10,21 +10,20 @@ jest.mock('@wix/essentials', () => ({
10
10
  }));
11
11
  const httpClient = {};
12
12
  describe('createCmsSchemaSource', () => {
13
- it('offers the CMS creatable field types in display order', () => {
13
+ it('declares the creatable types in display order — labels come from the standard names in the UI', () => {
14
14
  const source = (0, _createCmsSchemaSource.createCmsSchemaSource)({
15
15
  collectionId: 'Pokemon',
16
16
  httpClient
17
17
  });
18
- expect(source.creatableFieldTypes.map(t => t.patternsType)).toEqual(['SHORT_TEXT', 'NUMBER', 'BOOLEAN', 'DATE']);
19
- });
20
- it('carries label keys for the UI to resolve', () => {
21
- const source = (0, _createCmsSchemaSource.createCmsSchemaSource)({
22
- collectionId: 'Pokemon',
23
- httpClient
24
- });
25
- const shortText = source.creatableFieldTypes.find(t => t.patternsType === 'SHORT_TEXT');
26
- expect(shortText == null ? void 0 : shortText.labelKey).toBe('cairo.customFields.fieldType.shortText');
27
- expect(shortText == null ? void 0 : shortText.namePlaceholderKey).toBe('cairo.customFields.fieldType.shortText.Name.placeholder');
18
+ expect(source.creatableFieldTypes).toEqual([{
19
+ patternsType: 'SHORT_TEXT'
20
+ }, {
21
+ patternsType: 'NUMBER'
22
+ }, {
23
+ patternsType: 'BOOLEAN'
24
+ }, {
25
+ patternsType: 'DATE'
26
+ }]);
28
27
  });
29
28
  it('names the collection query after the collectionId', () => {
30
29
  const source = (0, _createCmsSchemaSource.createCmsSchemaSource)({
@@ -1 +1 @@
1
- {"version":3,"names":["_createCmsSchemaSource","require","jest","mock","errorHandler","withErrorHandler","fn","httpClient","describe","it","source","createCmsSchemaSource","collectionId","expect","creatableFieldTypes","map","t","patternsType","toEqual","shortText","find","labelKey","toBe","namePlaceholderKey","collectionConfig","queryName"],"sources":["../../../../src/adapter/__tests__/createCmsSchemaSource.spec.ts"],"sourcesContent":["import { createCmsSchemaSource } from '../createCmsSchemaSource';\nimport type { CreateCmsSchemaSourceDeps } from '../createCmsSchemaSource';\n\n// loadCmsSchema imports errorHandler at evaluation time; stub it so importing\n// the source factory is side-effect free. The loader itself isn't run here.\njest.mock('@wix/essentials', () => ({\n errorHandler: {\n withErrorHandler: (fn: () => unknown) => fn(),\n },\n}));\n\nconst httpClient = {} as unknown as CreateCmsSchemaSourceDeps['httpClient'];\n\ndescribe('createCmsSchemaSource', () => {\n it('offers the CMS creatable field types in display order', () => {\n const source = createCmsSchemaSource({\n collectionId: 'Pokemon',\n httpClient,\n });\n\n expect(source.creatableFieldTypes.map((t) => t.patternsType)).toEqual([\n 'SHORT_TEXT',\n 'NUMBER',\n 'BOOLEAN',\n 'DATE',\n ]);\n });\n\n it('carries label keys for the UI to resolve', () => {\n const source = createCmsSchemaSource({\n collectionId: 'Pokemon',\n httpClient,\n });\n\n const shortText = source.creatableFieldTypes.find(\n (t) => t.patternsType === 'SHORT_TEXT',\n );\n expect(shortText?.labelKey).toBe('cairo.customFields.fieldType.shortText');\n expect(shortText?.namePlaceholderKey).toBe(\n 'cairo.customFields.fieldType.shortText.Name.placeholder',\n );\n });\n\n it('names the collection query after the collectionId', () => {\n const source = createCmsSchemaSource({\n collectionId: 'Pokemon',\n httpClient,\n });\n\n expect(source.collectionId).toBe('Pokemon');\n expect(source.collectionConfig.queryName).toBe('Pokemon');\n });\n});\n"],"mappings":";;AAAA,IAAAA,sBAAA,GAAAC,OAAA;AAGA;AACA;AACAC,IAAI,CAACC,IAAI,CAAC,iBAAiB,EAAE,OAAO;EAClCC,YAAY,EAAE;IACZC,gBAAgB,EAAGC,EAAiB,IAAKA,EAAE,CAAC;EAC9C;AACF,CAAC,CAAC,CAAC;AAEH,MAAMC,UAAU,GAAG,CAAC,CAAuD;AAE3EC,QAAQ,CAAC,uBAAuB,EAAE,MAAM;EACtCC,EAAE,CAAC,uDAAuD,EAAE,MAAM;IAChE,MAAMC,MAAM,GAAG,IAAAC,4CAAqB,EAAC;MACnCC,YAAY,EAAE,SAAS;MACvBL;IACF,CAAC,CAAC;IAEFM,MAAM,CAACH,MAAM,CAACI,mBAAmB,CAACC,GAAG,CAAEC,CAAC,IAAKA,CAAC,CAACC,YAAY,CAAC,CAAC,CAACC,OAAO,CAAC,CACpE,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,MAAM,CACP,CAAC;EACJ,CAAC,CAAC;EAEFT,EAAE,CAAC,0CAA0C,EAAE,MAAM;IACnD,MAAMC,MAAM,GAAG,IAAAC,4CAAqB,EAAC;MACnCC,YAAY,EAAE,SAAS;MACvBL;IACF,CAAC,CAAC;IAEF,MAAMY,SAAS,GAAGT,MAAM,CAACI,mBAAmB,CAACM,IAAI,CAC9CJ,CAAC,IAAKA,CAAC,CAACC,YAAY,KAAK,YAC5B,CAAC;IACDJ,MAAM,CAACM,SAAS,oBAATA,SAAS,CAAEE,QAAQ,CAAC,CAACC,IAAI,CAAC,wCAAwC,CAAC;IAC1ET,MAAM,CAACM,SAAS,oBAATA,SAAS,CAAEI,kBAAkB,CAAC,CAACD,IAAI,CACxC,yDACF,CAAC;EACH,CAAC,CAAC;EAEFb,EAAE,CAAC,mDAAmD,EAAE,MAAM;IAC5D,MAAMC,MAAM,GAAG,IAAAC,4CAAqB,EAAC;MACnCC,YAAY,EAAE,SAAS;MACvBL;IACF,CAAC,CAAC;IAEFM,MAAM,CAACH,MAAM,CAACE,YAAY,CAAC,CAACU,IAAI,CAAC,SAAS,CAAC;IAC3CT,MAAM,CAACH,MAAM,CAACc,gBAAgB,CAACC,SAAS,CAAC,CAACH,IAAI,CAAC,SAAS,CAAC;EAC3D,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["_createCmsSchemaSource","require","jest","mock","errorHandler","withErrorHandler","fn","httpClient","describe","it","source","createCmsSchemaSource","collectionId","expect","creatableFieldTypes","toEqual","patternsType","toBe","collectionConfig","queryName"],"sources":["../../../../src/adapter/__tests__/createCmsSchemaSource.spec.ts"],"sourcesContent":["import { createCmsSchemaSource } from '../createCmsSchemaSource';\nimport type { CreateCmsSchemaSourceDeps } from '../createCmsSchemaSource';\n\n// loadCmsSchema imports errorHandler at evaluation time; stub it so importing\n// the source factory is side-effect free. The loader itself isn't run here.\njest.mock('@wix/essentials', () => ({\n errorHandler: {\n withErrorHandler: (fn: () => unknown) => fn(),\n },\n}));\n\nconst httpClient = {} as unknown as CreateCmsSchemaSourceDeps['httpClient'];\n\ndescribe('createCmsSchemaSource', () => {\n it('declares the creatable types in display order — labels come from the standard names in the UI', () => {\n const source = createCmsSchemaSource({\n collectionId: 'Pokemon',\n httpClient,\n });\n\n expect(source.creatableFieldTypes).toEqual([\n { patternsType: 'SHORT_TEXT' },\n { patternsType: 'NUMBER' },\n { patternsType: 'BOOLEAN' },\n { patternsType: 'DATE' },\n ]);\n });\n\n it('names the collection query after the collectionId', () => {\n const source = createCmsSchemaSource({\n collectionId: 'Pokemon',\n httpClient,\n });\n\n expect(source.collectionId).toBe('Pokemon');\n expect(source.collectionConfig.queryName).toBe('Pokemon');\n });\n});\n"],"mappings":";;AAAA,IAAAA,sBAAA,GAAAC,OAAA;AAGA;AACA;AACAC,IAAI,CAACC,IAAI,CAAC,iBAAiB,EAAE,OAAO;EAClCC,YAAY,EAAE;IACZC,gBAAgB,EAAGC,EAAiB,IAAKA,EAAE,CAAC;EAC9C;AACF,CAAC,CAAC,CAAC;AAEH,MAAMC,UAAU,GAAG,CAAC,CAAuD;AAE3EC,QAAQ,CAAC,uBAAuB,EAAE,MAAM;EACtCC,EAAE,CAAC,+FAA+F,EAAE,MAAM;IACxG,MAAMC,MAAM,GAAG,IAAAC,4CAAqB,EAAC;MACnCC,YAAY,EAAE,SAAS;MACvBL;IACF,CAAC,CAAC;IAEFM,MAAM,CAACH,MAAM,CAACI,mBAAmB,CAAC,CAACC,OAAO,CAAC,CACzC;MAAEC,YAAY,EAAE;IAAa,CAAC,EAC9B;MAAEA,YAAY,EAAE;IAAS,CAAC,EAC1B;MAAEA,YAAY,EAAE;IAAU,CAAC,EAC3B;MAAEA,YAAY,EAAE;IAAO,CAAC,CACzB,CAAC;EACJ,CAAC,CAAC;EAEFP,EAAE,CAAC,mDAAmD,EAAE,MAAM;IAC5D,MAAMC,MAAM,GAAG,IAAAC,4CAAqB,EAAC;MACnCC,YAAY,EAAE,SAAS;MACvBL;IACF,CAAC,CAAC;IAEFM,MAAM,CAACH,MAAM,CAACE,YAAY,CAAC,CAACK,IAAI,CAAC,SAAS,CAAC;IAC3CJ,MAAM,CAACH,MAAM,CAACQ,gBAAgB,CAACC,SAAS,CAAC,CAACF,IAAI,CAAC,SAAS,CAAC;EAC3D,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -7,21 +7,13 @@ var _loadCmsSchema = require("./loadCmsSchema");
7
7
  // The field types the add/edit modal offers, in display order. These are the
8
8
  // only types @wix/data can create (see PatternsFieldTypeToCmsFieldType).
9
9
  const CMS_CREATABLE_TYPES = [{
10
- patternsType: 'SHORT_TEXT',
11
- labelKey: 'cairo.customFields.fieldType.shortText',
12
- namePlaceholderKey: 'cairo.customFields.fieldType.shortText.Name.placeholder'
10
+ patternsType: 'SHORT_TEXT'
13
11
  }, {
14
- patternsType: 'NUMBER',
15
- labelKey: 'cairo.customFields.fieldType.numberInteger',
16
- namePlaceholderKey: 'cairo.customFields.fieldType.numberInteger.Name.placeholder'
12
+ patternsType: 'NUMBER'
17
13
  }, {
18
- patternsType: 'BOOLEAN',
19
- labelKey: 'cairo.customFields.fieldType.checkbox',
20
- namePlaceholderKey: 'cairo.customFields.fieldType.checkbox.Name.placeholder'
14
+ patternsType: 'BOOLEAN'
21
15
  }, {
22
- patternsType: 'DATE',
23
- labelKey: 'cairo.customFields.fieldType.date',
24
- namePlaceholderKey: 'cairo.customFields.fieldType.date.Name.placeholder'
16
+ patternsType: 'DATE'
25
17
  }];
26
18
  /**
27
19
  * Builds a ready-to-use `SchemaSource` for a CMS collection: wraps the CMS
@@ -1 +1 @@
1
- {"version":3,"names":["_bexCore","require","_loadCmsSchema","CMS_CREATABLE_TYPES","patternsType","labelKey","namePlaceholderKey","createCmsSchemaSource","deps","collectionId","loaderDeps","loader","createCmsSchemaLoader","defineSchemaSource","loadSchema","creatableFieldTypes"],"sources":["../../../src/adapter/createCmsSchemaSource.ts"],"sourcesContent":["import { defineSchemaSource } from '@wix/bex-core';\nimport type { CreatableFieldType, SchemaSource } from '@wix/bex-core';\nimport {\n createCmsSchemaLoader,\n type CreateCmsSchemaLoaderDeps,\n} from './loadCmsSchema';\n\n// The field types the add/edit modal offers, in display order. These are the\n// only types @wix/data can create (see PatternsFieldTypeToCmsFieldType).\nconst CMS_CREATABLE_TYPES: CreatableFieldType[] = [\n {\n patternsType: 'SHORT_TEXT',\n labelKey: 'cairo.customFields.fieldType.shortText',\n namePlaceholderKey:\n 'cairo.customFields.fieldType.shortText.Name.placeholder',\n },\n {\n patternsType: 'NUMBER',\n labelKey: 'cairo.customFields.fieldType.numberInteger',\n namePlaceholderKey:\n 'cairo.customFields.fieldType.numberInteger.Name.placeholder',\n },\n {\n patternsType: 'BOOLEAN',\n labelKey: 'cairo.customFields.fieldType.checkbox',\n namePlaceholderKey:\n 'cairo.customFields.fieldType.checkbox.Name.placeholder',\n },\n {\n patternsType: 'DATE',\n labelKey: 'cairo.customFields.fieldType.date',\n namePlaceholderKey: 'cairo.customFields.fieldType.date.Name.placeholder',\n },\n];\n\nexport interface CreateCmsSchemaSourceDeps extends CreateCmsSchemaLoaderDeps {\n collectionId: string;\n}\n\n/**\n * Builds a ready-to-use `SchemaSource` for a CMS collection: wraps the CMS\n * schema loader and supplies the CMS field types. Pass it to `<Table>` and spread\n * its `collectionConfig` into the collection hook.\n */\nexport function createCmsSchemaSource<\n T extends Record<string, unknown> = Record<string, unknown>,\n>(deps: CreateCmsSchemaSourceDeps): SchemaSource<T> {\n const { collectionId, ...loaderDeps } = deps;\n const loader = createCmsSchemaLoader<T>(loaderDeps);\n return defineSchemaSource<T>({\n collectionId,\n loadSchema: () => loader(collectionId),\n creatableFieldTypes: CMS_CREATABLE_TYPES,\n });\n}\n"],"mappings":";;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,cAAA,GAAAD,OAAA;AAKA;AACA;AACA,MAAME,mBAAyC,GAAG,CAChD;EACEC,YAAY,EAAE,YAAY;EAC1BC,QAAQ,EAAE,wCAAwC;EAClDC,kBAAkB,EAChB;AACJ,CAAC,EACD;EACEF,YAAY,EAAE,QAAQ;EACtBC,QAAQ,EAAE,4CAA4C;EACtDC,kBAAkB,EAChB;AACJ,CAAC,EACD;EACEF,YAAY,EAAE,SAAS;EACvBC,QAAQ,EAAE,uCAAuC;EACjDC,kBAAkB,EAChB;AACJ,CAAC,EACD;EACEF,YAAY,EAAE,MAAM;EACpBC,QAAQ,EAAE,mCAAmC;EAC7CC,kBAAkB,EAAE;AACtB,CAAC,CACF;AAMD;AACA;AACA;AACA;AACA;AACO,SAASC,qBAAqBA,CAEnCC,IAA+B,EAAmB;EAClD,MAAM;IAAEC,YAAY;IAAE,GAAGC;EAAW,CAAC,GAAGF,IAAI;EAC5C,MAAMG,MAAM,GAAG,IAAAC,oCAAqB,EAAIF,UAAU,CAAC;EACnD,OAAO,IAAAG,2BAAkB,EAAI;IAC3BJ,YAAY;IACZK,UAAU,EAAEA,CAAA,KAAMH,MAAM,CAACF,YAAY,CAAC;IACtCM,mBAAmB,EAAEZ;EACvB,CAAC,CAAC;AACJ","ignoreList":[]}
1
+ {"version":3,"names":["_bexCore","require","_loadCmsSchema","CMS_CREATABLE_TYPES","patternsType","createCmsSchemaSource","deps","collectionId","loaderDeps","loader","createCmsSchemaLoader","defineSchemaSource","loadSchema","creatableFieldTypes"],"sources":["../../../src/adapter/createCmsSchemaSource.ts"],"sourcesContent":["import { defineSchemaSource } from '@wix/bex-core';\nimport type { CreatableFieldType, SchemaSource } from '@wix/bex-core';\nimport {\n createCmsSchemaLoader,\n type CreateCmsSchemaLoaderDeps,\n} from './loadCmsSchema';\n\n// The field types the add/edit modal offers, in display order. These are the\n// only types @wix/data can create (see PatternsFieldTypeToCmsFieldType).\nconst CMS_CREATABLE_TYPES: CreatableFieldType[] = [\n { patternsType: 'SHORT_TEXT' },\n { patternsType: 'NUMBER' },\n { patternsType: 'BOOLEAN' },\n { patternsType: 'DATE' },\n];\n\nexport interface CreateCmsSchemaSourceDeps extends CreateCmsSchemaLoaderDeps {\n collectionId: string;\n}\n\n/**\n * Builds a ready-to-use `SchemaSource` for a CMS collection: wraps the CMS\n * schema loader and supplies the CMS field types. Pass it to `<Table>` and spread\n * its `collectionConfig` into the collection hook.\n */\nexport function createCmsSchemaSource<\n T extends Record<string, unknown> = Record<string, unknown>,\n>(deps: CreateCmsSchemaSourceDeps): SchemaSource<T> {\n const { collectionId, ...loaderDeps } = deps;\n const loader = createCmsSchemaLoader<T>(loaderDeps);\n return defineSchemaSource<T>({\n collectionId,\n loadSchema: () => loader(collectionId),\n creatableFieldTypes: CMS_CREATABLE_TYPES,\n });\n}\n"],"mappings":";;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAEA,IAAAC,cAAA,GAAAD,OAAA;AAKA;AACA;AACA,MAAME,mBAAyC,GAAG,CAChD;EAAEC,YAAY,EAAE;AAAa,CAAC,EAC9B;EAAEA,YAAY,EAAE;AAAS,CAAC,EAC1B;EAAEA,YAAY,EAAE;AAAU,CAAC,EAC3B;EAAEA,YAAY,EAAE;AAAO,CAAC,CACzB;AAMD;AACA;AACA;AACA;AACA;AACO,SAASC,qBAAqBA,CAEnCC,IAA+B,EAAmB;EAClD,MAAM;IAAEC,YAAY;IAAE,GAAGC;EAAW,CAAC,GAAGF,IAAI;EAC5C,MAAMG,MAAM,GAAG,IAAAC,oCAAqB,EAAIF,UAAU,CAAC;EACnD,OAAO,IAAAG,2BAAkB,EAAI;IAC3BJ,YAAY;IACZK,UAAU,EAAEA,CAAA,KAAMH,MAAM,CAACF,YAAY,CAAC;IACtCM,mBAAmB,EAAEV;EACvB,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.transformCmsSchema = exports.pollUntilReady = exports.getFieldKey = exports.fetchUserPermissions = exports.fetchExternalDbConnections = exports.fetchCmsCollection = exports.createCmsSchemaSource = exports.createCmsSchemaLoader = exports.createCmsFieldActions = exports.createCmsBackupConfig = exports.createCmsBackend = exports.computeCmsPermissions = exports.addSortToDataQuery = exports.addSearchToDataQuery = exports.addFiltersToDataQuery = exports.PatternsFieldTypeToCmsFieldType = exports.CmsFieldTypeToPatternsFieldType = exports.CMS_EMAIL_TYPE = void 0;
4
+ exports.transformCmsSchema = exports.pollUntilReady = exports.listCmsCollections = exports.getFieldKey = exports.fetchUserPermissions = exports.fetchExternalDbConnections = exports.fetchCmsCollection = exports.createCmsSchemaSource = exports.createCmsSchemaLoader = exports.createCmsFieldActions = exports.createCmsBackupConfig = exports.createCmsBackend = exports.computeCmsPermissions = exports.addSortToDataQuery = exports.addSearchToDataQuery = exports.addFiltersToDataQuery = exports.PatternsFieldTypeToCmsFieldType = exports.CmsFieldTypeToPatternsFieldType = exports.CMS_EMAIL_TYPE = void 0;
5
5
  var _loadCmsSchema = require("./loadCmsSchema");
6
6
  exports.createCmsSchemaLoader = _loadCmsSchema.createCmsSchemaLoader;
7
7
  exports.fetchCmsCollection = _loadCmsSchema.fetchCmsCollection;
8
8
  var _createCmsSchemaSource = require("./createCmsSchemaSource");
9
9
  exports.createCmsSchemaSource = _createCmsSchemaSource.createCmsSchemaSource;
10
+ var _listCmsCollections = require("./listCmsCollections");
11
+ exports.listCmsCollections = _listCmsCollections.listCmsCollections;
10
12
  var _transformCmsSchema = require("./transformCmsSchema");
11
13
  exports.transformCmsSchema = _transformCmsSchema.transformCmsSchema;
12
14
  var _createCmsBackend = require("./createCmsBackend");
@@ -1 +1 @@
1
- {"version":3,"names":["_loadCmsSchema","require","exports","createCmsSchemaLoader","fetchCmsCollection","_createCmsSchemaSource","createCmsSchemaSource","_transformCmsSchema","transformCmsSchema","_createCmsBackend","createCmsBackend","_createCmsFieldActions","createCmsFieldActions","_cmsPermissions","computeCmsPermissions","_cmsFieldTypeMap","CmsFieldTypeToPatternsFieldType","PatternsFieldTypeToCmsFieldType","CMS_EMAIL_TYPE","_filterUtils","addFiltersToDataQuery","_searchUtils","addSearchToDataQuery","_sortUtils","addSortToDataQuery","_getFieldKey","getFieldKey","_cmsBackup","createCmsBackupConfig","_pollUntilReady","pollUntilReady","_fetchExternalDbConnections","fetchExternalDbConnections","_fetchUserPermissions","fetchUserPermissions"],"sources":["../../../src/adapter/index.ts"],"sourcesContent":["export {\n createCmsSchemaLoader,\n fetchCmsCollection,\n type CreateCmsSchemaLoaderDeps,\n} from './loadCmsSchema';\nexport {\n createCmsSchemaSource,\n type CreateCmsSchemaSourceDeps,\n} from './createCmsSchemaSource';\nexport {\n transformCmsSchema,\n type TransformCmsSchemaOptions,\n} from './transformCmsSchema';\nexport { createCmsBackend } from './createCmsBackend';\nexport { createCmsFieldActions } from './createCmsFieldActions';\nexport {\n computeCmsPermissions,\n type CmsPermissions,\n type ExternalDbConnection,\n} from './cmsPermissions';\nexport {\n CmsFieldTypeToPatternsFieldType,\n PatternsFieldTypeToCmsFieldType,\n CMS_EMAIL_TYPE,\n} from './cmsFieldTypeMap';\nexport { addFiltersToDataQuery } from './filterUtils';\nexport { addSearchToDataQuery } from './searchUtils';\nexport { addSortToDataQuery } from './sortUtils';\nexport { getFieldKey } from './getFieldKey';\nexport { createCmsBackupConfig } from './cmsBackup';\nexport { pollUntilReady, type PollOptions } from './pollUntilReady';\nexport { fetchExternalDbConnections } from './fetchExternalDbConnections';\nexport { fetchUserPermissions } from './fetchUserPermissions';\n"],"mappings":";;;;AAAA,IAAAA,cAAA,GAAAC,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qBAAA;AACpD,IAAAC,eAAA,GAAA5B,OAAA;AAAoEC,OAAA,CAAA4B,cAAA,GAAAD,eAAA,CAAAC,cAAA;AACpE,IAAAC,2BAAA,GAAA9B,OAAA;AAA0EC,OAAA,CAAA8B,0BAAA,GAAAD,2BAAA,CAAAC,0BAAA;AAC1E,IAAAC,qBAAA,GAAAhC,OAAA;AAA8DC,OAAA,CAAAgC,oBAAA,GAAAD,qBAAA,CAAAC,oBAAA","ignoreList":[]}
1
+ {"version":3,"names":["_loadCmsSchema","require","exports","createCmsSchemaLoader","fetchCmsCollection","_createCmsSchemaSource","createCmsSchemaSource","_listCmsCollections","listCmsCollections","_transformCmsSchema","transformCmsSchema","_createCmsBackend","createCmsBackend","_createCmsFieldActions","createCmsFieldActions","_cmsPermissions","computeCmsPermissions","_cmsFieldTypeMap","CmsFieldTypeToPatternsFieldType","PatternsFieldTypeToCmsFieldType","CMS_EMAIL_TYPE","_filterUtils","addFiltersToDataQuery","_searchUtils","addSearchToDataQuery","_sortUtils","addSortToDataQuery","_getFieldKey","getFieldKey","_cmsBackup","createCmsBackupConfig","_pollUntilReady","pollUntilReady","_fetchExternalDbConnections","fetchExternalDbConnections","_fetchUserPermissions","fetchUserPermissions"],"sources":["../../../src/adapter/index.ts"],"sourcesContent":["export {\n createCmsSchemaLoader,\n fetchCmsCollection,\n type CreateCmsSchemaLoaderDeps,\n} from './loadCmsSchema';\nexport {\n createCmsSchemaSource,\n type CreateCmsSchemaSourceDeps,\n} from './createCmsSchemaSource';\nexport {\n listCmsCollections,\n type CmsCollectionSummary,\n} from './listCmsCollections';\nexport {\n transformCmsSchema,\n type TransformCmsSchemaOptions,\n} from './transformCmsSchema';\nexport { createCmsBackend } from './createCmsBackend';\nexport { createCmsFieldActions } from './createCmsFieldActions';\nexport {\n computeCmsPermissions,\n type CmsPermissions,\n type ExternalDbConnection,\n} from './cmsPermissions';\nexport {\n CmsFieldTypeToPatternsFieldType,\n PatternsFieldTypeToCmsFieldType,\n CMS_EMAIL_TYPE,\n} from './cmsFieldTypeMap';\nexport { addFiltersToDataQuery } from './filterUtils';\nexport { addSearchToDataQuery } from './searchUtils';\nexport { addSortToDataQuery } from './sortUtils';\nexport { getFieldKey } from './getFieldKey';\nexport { createCmsBackupConfig } from './cmsBackup';\nexport { pollUntilReady, type PollOptions } from './pollUntilReady';\nexport { fetchExternalDbConnections } from './fetchExternalDbConnections';\nexport { fetchUserPermissions } from './fetchUserPermissions';\n"],"mappings":";;;;AAAA,IAAAA,cAAA,GAAAC,OAAA;AAIyBC,OAAA,CAAAC,qBAAA,GAAAH,cAAA,CAAAG,qBAAA;AAAAD,OAAA,CAAAE,kBAAA,GAAAJ,cAAA,CAAAI,kBAAA;AACzB,IAAAC,sBAAA,GAAAJ,OAAA;AAGiCC,OAAA,CAAAI,qBAAA,GAAAD,sBAAA,CAAAC,qBAAA;AACjC,IAAAC,mBAAA,GAAAN,OAAA;AAG8BC,OAAA,CAAAM,kBAAA,GAAAD,mBAAA,CAAAC,kBAAA;AAC9B,IAAAC,mBAAA,GAAAR,OAAA;AAG8BC,OAAA,CAAAQ,kBAAA,GAAAD,mBAAA,CAAAC,kBAAA;AAC9B,IAAAC,iBAAA,GAAAV,OAAA;AAAsDC,OAAA,CAAAU,gBAAA,GAAAD,iBAAA,CAAAC,gBAAA;AACtD,IAAAC,sBAAA,GAAAZ,OAAA;AAAgEC,OAAA,CAAAY,qBAAA,GAAAD,sBAAA,CAAAC,qBAAA;AAChE,IAAAC,eAAA,GAAAd,OAAA;AAI0BC,OAAA,CAAAc,qBAAA,GAAAD,eAAA,CAAAC,qBAAA;AAC1B,IAAAC,gBAAA,GAAAhB,OAAA;AAI2BC,OAAA,CAAAgB,+BAAA,GAAAD,gBAAA,CAAAC,+BAAA;AAAAhB,OAAA,CAAAiB,+BAAA,GAAAF,gBAAA,CAAAE,+BAAA;AAAAjB,OAAA,CAAAkB,cAAA,GAAAH,gBAAA,CAAAG,cAAA;AAC3B,IAAAC,YAAA,GAAApB,OAAA;AAAsDC,OAAA,CAAAoB,qBAAA,GAAAD,YAAA,CAAAC,qBAAA;AACtD,IAAAC,YAAA,GAAAtB,OAAA;AAAqDC,OAAA,CAAAsB,oBAAA,GAAAD,YAAA,CAAAC,oBAAA;AACrD,IAAAC,UAAA,GAAAxB,OAAA;AAAiDC,OAAA,CAAAwB,kBAAA,GAAAD,UAAA,CAAAC,kBAAA;AACjD,IAAAC,YAAA,GAAA1B,OAAA;AAA4CC,OAAA,CAAA0B,WAAA,GAAAD,YAAA,CAAAC,WAAA;AAC5C,IAAAC,UAAA,GAAA5B,OAAA;AAAoDC,OAAA,CAAA4B,qBAAA,GAAAD,UAAA,CAAAC,qBAAA;AACpD,IAAAC,eAAA,GAAA9B,OAAA;AAAoEC,OAAA,CAAA8B,cAAA,GAAAD,eAAA,CAAAC,cAAA;AACpE,IAAAC,2BAAA,GAAAhC,OAAA;AAA0EC,OAAA,CAAAgC,0BAAA,GAAAD,2BAAA,CAAAC,0BAAA;AAC1E,IAAAC,qBAAA,GAAAlC,OAAA;AAA8DC,OAAA,CAAAkC,oBAAA,GAAAD,qBAAA,CAAAC,oBAAA","ignoreList":[]}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.listCmsCollections = listCmsCollections;
5
+ var _data = require("@wix/data");
6
+ var _essentials = require("@wix/essentials");
7
+ /** Lists the site's CMS collections — for collection pickers. */
8
+ async function listCmsCollections() {
9
+ const response = await _essentials.errorHandler.withErrorHandler(async () => _data.collections.listDataCollections(), {});
10
+ return (response.collections ?? []).map(collection => ({
11
+ id: collection._id ?? '',
12
+ displayName: collection.displayName ?? collection._id ?? ''
13
+ })).filter(collection => collection.id !== '');
14
+ }
15
+ //# sourceMappingURL=listCmsCollections.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_data","require","_essentials","listCmsCollections","response","errorHandler","withErrorHandler","collections","listDataCollections","map","collection","id","_id","displayName","filter"],"sources":["../../../src/adapter/listCmsCollections.ts"],"sourcesContent":["import { collections } from '@wix/data';\nimport { errorHandler } from '@wix/essentials';\n\nexport interface CmsCollectionSummary {\n id: string;\n displayName: string;\n}\n\n/** Lists the site's CMS collections — for collection pickers. */\nexport async function listCmsCollections(): Promise<CmsCollectionSummary[]> {\n const response = await errorHandler.withErrorHandler(\n async () => collections.listDataCollections(),\n {},\n );\n return (response.collections ?? [])\n .map((collection) => ({\n id: collection._id ?? '',\n displayName: collection.displayName ?? collection._id ?? '',\n }))\n .filter((collection) => collection.id !== '');\n}\n"],"mappings":";;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAOA;AACO,eAAeE,kBAAkBA,CAAA,EAAoC;EAC1E,MAAMC,QAAQ,GAAG,MAAMC,wBAAY,CAACC,gBAAgB,CAClD,YAAYC,iBAAW,CAACC,mBAAmB,CAAC,CAAC,EAC7C,CAAC,CACH,CAAC;EACD,OAAO,CAACJ,QAAQ,CAACG,WAAW,IAAI,EAAE,EAC/BE,GAAG,CAAEC,UAAU,KAAM;IACpBC,EAAE,EAAED,UAAU,CAACE,GAAG,IAAI,EAAE;IACxBC,WAAW,EAAEH,UAAU,CAACG,WAAW,IAAIH,UAAU,CAACE,GAAG,IAAI;EAC3D,CAAC,CAAC,CAAC,CACFE,MAAM,CAAEJ,UAAU,IAAKA,UAAU,CAACC,EAAE,KAAK,EAAE,CAAC;AACjD","ignoreList":[]}
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.mockCmsCollection = mockCmsCollection;
5
+ exports.mockCmsItems = mockCmsItems;
6
+ var _fetchMock = require("@wix/sdk-testkit/fetch-mock");
7
+ var _meta = require("@wix/data/meta");
8
+ var _data = require("@wix/data");
9
+ var _cmsFieldTypeMap = require("../adapter/cmsFieldTypeMap");
10
+ var itemsApi = _interopRequireWildcard(require("@wix/wix-data-items-sdk/build/cjs/src/data-items-api-client"));
11
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
12
+ // The query endpoint's request options aren't exposed on any public entry, so
13
+ // reach into the items SDK internals to derive its URL (no @wix/data/meta entry).
14
+ // eslint-disable-next-line no-restricted-imports
15
+
16
+ /**
17
+ * Mock the collection schema (`getDataCollection`) either from explicit CMS fields
18
+ * or straight from a schema source — a `createInMemorySchemaSource` becomes the
19
+ * single source of truth for the schema, its contract fields converted back to CMS
20
+ * fields (types with no CMS mapping fall back to text — enough to render).
21
+ */
22
+
23
+ function toCmsFields(fields, idField) {
24
+ return Object.values(fields).filter(field => field != null).map(field => ({
25
+ key: field.id,
26
+ displayName: field.displayName,
27
+ type: _cmsFieldTypeMap.PatternsFieldTypeToCmsFieldType[field.type] ?? _data.collections.Type.TEXT,
28
+ ...(field.id === idField ? {
29
+ systemField: true
30
+ } : {})
31
+ }));
32
+ }
33
+ function collectionResponse(collectionId, fields, displayField) {
34
+ return {
35
+ referencedCollections: [],
36
+ collection: {
37
+ id: collectionId,
38
+ collectionType: _data.collections.CollectionType.WIX_APP,
39
+ pagingModes: [_data.collections.PagingMode.OFFSET],
40
+ plugins: [],
41
+ displayField,
42
+ fields
43
+ }
44
+ };
45
+ }
46
+
47
+ /**
48
+ * Routes the collection schema (`getDataCollection`) that `createCmsSchemaSource`
49
+ * loads. `@wix/data` issues real fetch calls; the caller's fetch-mock instance
50
+ * intercepts them by URL.
51
+ */
52
+ function mockCmsCollection(fetchMock, options) {
53
+ if ('source' in options) {
54
+ const {
55
+ source
56
+ } = options;
57
+ const [url] = (0, _fetchMock.when)(_meta.collections.getDataCollection()).withParams({
58
+ dataCollectionId: source.collectionId
59
+ }).reply(undefined);
60
+ fetchMock.route(url, async () => {
61
+ const {
62
+ schema
63
+ } = await source.loadSchema();
64
+ return collectionResponse(source.collectionId, toCmsFields(schema.fields, schema.idField), schema.displayField);
65
+ });
66
+ return;
67
+ }
68
+ const {
69
+ collectionId,
70
+ fields,
71
+ displayField = 'name'
72
+ } = options;
73
+ const [url, data] = (0, _fetchMock.when)(_meta.collections.getDataCollection()).withParams({
74
+ dataCollectionId: collectionId
75
+ }).reply(collectionResponse(collectionId, fields, displayField));
76
+ fetchMock.route(url, data);
77
+ }
78
+
79
+ // The items-query endpoint has no `@wix/data/meta` entry, so derive its URL from
80
+ // the wix-data-items SDK request options.
81
+ function queryDataItemsMeta() {
82
+ return {
83
+ getUrl: context =>
84
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
85
+ itemsApi.reqOptions(itemsApi.queryDataItemsRequestOptions, {})(context).url,
86
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
+ httpMethod: itemsApi.queryDataItemsRequestOptions.method,
88
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
89
+ path: itemsApi.queryDataItemsRequestOptions.httpPath,
90
+ pathParams: {},
91
+ __requestType: null,
92
+ __originalRequestType: null,
93
+ __responseType: null,
94
+ __originalResponseType: null
95
+ };
96
+ }
97
+
98
+ // A resolver reads a page of rows for a decoded query — this is exactly a schema
99
+ // source's `collectionConfig.fetchData`, so an in-memory source wires straight
100
+ // in. A plain array is normalized to one below.
101
+
102
+ /**
103
+ * What `mockCmsItems` serves: either plain rows or a resolver that returns a page
104
+ * per query (a schema source's `collectionConfig.fetchData` is exactly a resolver).
105
+ */
106
+
107
+ /**
108
+ * Mock the rows either from explicit items/resolver or straight from a schema
109
+ * source — pass `{ source }` and a `createInMemorySchemaSource` becomes the single
110
+ * source of truth for the rows too.
111
+ */
112
+
113
+ // The @wix/data query is sent as a base64 `.r` search param; decode it back to
114
+ // the offset/limit a resolver expects.
115
+
116
+ function decodeOffsetQuery(opts) {
117
+ var _JSON$parse, _query$paging, _query$paging2;
118
+ const raw = opts.queryParams.get('.r');
119
+ const query = raw ? (_JSON$parse = JSON.parse(atob(raw))) == null ? void 0 : _JSON$parse.query : undefined;
120
+ return {
121
+ offset: (query == null || (_query$paging = query.paging) == null ? void 0 : _query$paging.offset) ?? 0,
122
+ limit: (query == null || (_query$paging2 = query.paging) == null ? void 0 : _query$paging2.limit) ?? 100
123
+ };
124
+ }
125
+ function toResolver(items) {
126
+ if (typeof items === 'function') {
127
+ return items;
128
+ }
129
+ // Plain array: slice by the requested page, report the full count as total.
130
+ return async query => {
131
+ const offset = query.offset ?? 0;
132
+ const limit = query.limit ?? items.length;
133
+ const page = items.slice(offset, offset + limit);
134
+ return {
135
+ items: page,
136
+ total: items.length,
137
+ hasNext: offset + page.length < items.length
138
+ };
139
+ };
140
+ }
141
+
142
+ /**
143
+ * Routes the collection's rows (`items.query(...).find()`). Pass plain rows, or a
144
+ * resolver `(query) => Promise<{ items, total }>` — the latter is a schema source's
145
+ * `collectionConfig.fetchData`, so an in-memory source drives paging per request.
146
+ */
147
+ function mockCmsItems(fetchMock, options) {
148
+ const resolve = 'source' in options ? options.source.collectionConfig.fetchData : toResolver(options.items);
149
+ const [url] = (0, _fetchMock.when)(queryDataItemsMeta()).reply(null);
150
+ fetchMock.route(url, async opts => {
151
+ const {
152
+ items: page,
153
+ total
154
+ } = await resolve(decodeOffsetQuery(opts));
155
+ return {
156
+ dataItems: page.map(data => ({
157
+ data
158
+ })),
159
+ pagingMetadata: {
160
+ total
161
+ }
162
+ };
163
+ });
164
+ }
165
+ //# sourceMappingURL=cmsFetchMocks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_fetchMock","require","_meta","_data","_cmsFieldTypeMap","itemsApi","_interopRequireWildcard","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","toCmsFields","fields","idField","values","filter","field","map","key","id","displayName","type","PatternsFieldTypeToCmsFieldType","collections","Type","TEXT","systemField","collectionResponse","collectionId","displayField","referencedCollections","collection","collectionType","CollectionType","WIX_APP","pagingModes","PagingMode","OFFSET","plugins","mockCmsCollection","fetchMock","options","source","url","when","collectionsMeta","getDataCollection","withParams","dataCollectionId","reply","undefined","route","schema","loadSchema","data","queryDataItemsMeta","getUrl","context","reqOptions","queryDataItemsRequestOptions","httpMethod","method","path","httpPath","pathParams","__requestType","__originalRequestType","__responseType","__originalResponseType","decodeOffsetQuery","opts","_JSON$parse","_query$paging","_query$paging2","raw","queryParams","query","JSON","parse","atob","offset","paging","limit","toResolver","items","length","page","slice","total","hasNext","mockCmsItems","resolve","collectionConfig","fetchData","dataItems","pagingMetadata"],"sources":["../../../src/testkit/cmsFetchMocks.ts"],"sourcesContent":["import { when } from '@wix/sdk-testkit/fetch-mock';\nimport { collections as collectionsMeta } from '@wix/data/meta';\nimport { collections } from '@wix/data';\nimport type { Schema, SchemaSource } from '@wix/bex-core';\nimport { PatternsFieldTypeToCmsFieldType } from '../adapter/cmsFieldTypeMap';\n// The query endpoint's request options aren't exposed on any public entry, so\n// reach into the items SDK internals to derive its URL (no @wix/data/meta entry).\n// eslint-disable-next-line no-restricted-imports\nimport * as itemsApi from '@wix/wix-data-items-sdk/build/cjs/src/data-items-api-client';\nimport type { FetchMock } from 'fetch-mock';\n\nexport type WixDataFields = NonNullable<\n collections.GetDataCollectionResponse['collection']\n>['fields'];\n\n/**\n * Mock the collection schema (`getDataCollection`) either from explicit CMS fields\n * or straight from a schema source — a `createInMemorySchemaSource` becomes the\n * single source of truth for the schema, its contract fields converted back to CMS\n * fields (types with no CMS mapping fall back to text — enough to render).\n */\nexport type MockCmsCollectionOptions<\n T extends Record<string, unknown> = Record<string, unknown>,\n> =\n | { collectionId: string; fields: WixDataFields; displayField?: string }\n | { source: SchemaSource<T> };\n\nfunction toCmsFields(fields: Schema['fields'], idField: string): WixDataFields {\n return Object.values(fields)\n .filter((field): field is NonNullable<typeof field> => field != null)\n .map((field) => ({\n key: field.id,\n displayName: field.displayName,\n type:\n PatternsFieldTypeToCmsFieldType[field.type] ?? collections.Type.TEXT,\n ...(field.id === idField ? { systemField: true } : {}),\n }));\n}\n\nfunction collectionResponse(\n collectionId: string,\n fields: WixDataFields,\n displayField: string,\n): collections.GetDataCollectionResponse {\n return {\n referencedCollections: [],\n collection: {\n id: collectionId,\n collectionType: collections.CollectionType.WIX_APP,\n pagingModes: [collections.PagingMode.OFFSET],\n plugins: [],\n displayField,\n fields,\n },\n } as collections.GetDataCollectionResponse;\n}\n\n/**\n * Routes the collection schema (`getDataCollection`) that `createCmsSchemaSource`\n * loads. `@wix/data` issues real fetch calls; the caller's fetch-mock instance\n * intercepts them by URL.\n */\nexport function mockCmsCollection<\n T extends Record<string, unknown> = Record<string, unknown>,\n>(fetchMock: FetchMock, options: MockCmsCollectionOptions<T>): void {\n if ('source' in options) {\n const { source } = options;\n const [url] = when(collectionsMeta.getDataCollection())\n .withParams({ dataCollectionId: source.collectionId })\n .reply(undefined);\n\n fetchMock.route(url, async () => {\n const { schema } = await source.loadSchema();\n return collectionResponse(\n source.collectionId,\n toCmsFields(schema.fields, schema.idField),\n schema.displayField,\n );\n });\n return;\n }\n\n const { collectionId, fields, displayField = 'name' } = options;\n const [url, data] = when(collectionsMeta.getDataCollection())\n .withParams({ dataCollectionId: collectionId })\n .reply(collectionResponse(collectionId, fields, displayField));\n\n fetchMock.route(url, data);\n}\n\n// The items-query endpoint has no `@wix/data/meta` entry, so derive its URL from\n// the wix-data-items SDK request options.\nfunction queryDataItemsMeta() {\n return {\n getUrl: (context: unknown) =>\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (itemsApi.reqOptions as any)(\n itemsApi.queryDataItemsRequestOptions,\n {},\n )(context).url,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n httpMethod: (itemsApi.queryDataItemsRequestOptions as any).method,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n path: (itemsApi.queryDataItemsRequestOptions as any).httpPath,\n pathParams: {},\n __requestType: null,\n __originalRequestType: null,\n __responseType: null,\n __originalResponseType: null,\n };\n}\n\n// A resolver reads a page of rows for a decoded query — this is exactly a schema\n// source's `collectionConfig.fetchData`, so an in-memory source wires straight\n// in. A plain array is normalized to one below.\ntype ItemsResolver<T> = SchemaSource<T>['collectionConfig']['fetchData'];\ntype OffsetQuery<T> = Parameters<ItemsResolver<T>>[0];\n\n/**\n * What `mockCmsItems` serves: either plain rows or a resolver that returns a page\n * per query (a schema source's `collectionConfig.fetchData` is exactly a resolver).\n */\nexport type CmsItems<T extends Record<string, unknown>> =\n | T[]\n | ItemsResolver<T>;\n\n/**\n * Mock the rows either from explicit items/resolver or straight from a schema\n * source — pass `{ source }` and a `createInMemorySchemaSource` becomes the single\n * source of truth for the rows too.\n */\nexport type MockCmsItemsOptions<T extends Record<string, unknown>> =\n | { items: CmsItems<T> }\n | { source: SchemaSource<T> };\n\n// The @wix/data query is sent as a base64 `.r` search param; decode it back to\n// the offset/limit a resolver expects.\ninterface QueryCall {\n queryParams: { get(name: string): string | null };\n}\n\nfunction decodeOffsetQuery<T extends Record<string, unknown>>(\n opts: QueryCall,\n): OffsetQuery<T> {\n const raw = opts.queryParams.get('.r');\n const query = raw ? JSON.parse(atob(raw))?.query : undefined;\n return {\n offset: query?.paging?.offset ?? 0,\n limit: query?.paging?.limit ?? 100,\n } as OffsetQuery<T>;\n}\n\nfunction toResolver<T extends Record<string, unknown>>(\n items: CmsItems<T>,\n): ItemsResolver<T> {\n if (typeof items === 'function') {\n return items;\n }\n // Plain array: slice by the requested page, report the full count as total.\n return (async (query: OffsetQuery<T>) => {\n const offset = query.offset ?? 0;\n const limit = query.limit ?? items.length;\n const page = items.slice(offset, offset + limit);\n return {\n items: page,\n total: items.length,\n hasNext: offset + page.length < items.length,\n };\n }) as ItemsResolver<T>;\n}\n\n/**\n * Routes the collection's rows (`items.query(...).find()`). Pass plain rows, or a\n * resolver `(query) => Promise<{ items, total }>` — the latter is a schema source's\n * `collectionConfig.fetchData`, so an in-memory source drives paging per request.\n */\nexport function mockCmsItems<T extends Record<string, unknown>>(\n fetchMock: FetchMock,\n options: MockCmsItemsOptions<T>,\n): void {\n const resolve =\n 'source' in options\n ? options.source.collectionConfig.fetchData\n : toResolver(options.items);\n const [url] = when(queryDataItemsMeta()).reply(null);\n\n fetchMock.route(url, async (opts: QueryCall) => {\n const { items: page, total } = await resolve(decodeOffsetQuery<T>(opts));\n return {\n dataItems: page.map((data) => ({ data })),\n pagingMetadata: { total },\n };\n });\n}\n"],"mappings":";;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAEA,IAAAG,gBAAA,GAAAH,OAAA;AAIA,IAAAI,QAAA,GAAAC,uBAAA,CAAAL,OAAA;AAAwF,SAAAK,wBAAAC,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAH,uBAAA,YAAAA,CAAAC,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,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,IAAI,GAAGF,KAAK,CAACG,KAAK,CAACP,MAAM,EAAEA,MAAM,GAAGE,KAAK,CAAC;IAChD,OAAO;MACLE,KAAK,EAAEE,IAAI;MACXE,KAAK,EAAEJ,KAAK,CAACC,MAAM;MACnBI,OAAO,EAAET,MAAM,GAAGM,IAAI,CAACD,MAAM,GAAGD,KAAK,CAACC;IACxC,CAAC;EACH,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACO,SAASK,YAAYA,CAC1BlD,SAAoB,EACpBC,OAA+B,EACzB;EACN,MAAMkD,OAAO,GACX,QAAQ,IAAIlD,OAAO,GACfA,OAAO,CAACC,MAAM,CAACkD,gBAAgB,CAACC,SAAS,GACzCV,UAAU,CAAC1C,OAAO,CAAC2C,KAAK,CAAC;EAC/B,MAAM,CAACzC,GAAG,CAAC,GAAG,IAAAC,eAAI,EAACW,kBAAkB,CAAC,CAAC,CAAC,CAACN,KAAK,CAAC,IAAI,CAAC;EAEpDT,SAAS,CAACW,KAAK,CAACR,GAAG,EAAE,MAAO2B,IAAe,IAAK;IAC9C,MAAM;MAAEc,KAAK,EAAEE,IAAI;MAAEE;IAAM,CAAC,GAAG,MAAMG,OAAO,CAACtB,iBAAiB,CAAIC,IAAI,CAAC,CAAC;IACxE,OAAO;MACLwB,SAAS,EAAER,IAAI,CAACrE,GAAG,CAAEqC,IAAI,KAAM;QAAEA;MAAK,CAAC,CAAC,CAAC;MACzCyC,cAAc,EAAE;QAAEP;MAAM;IAC1B,CAAC;EACH,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ var _cmsFetchMocks = require("./cmsFetchMocks");
5
+ Object.keys(_cmsFetchMocks).forEach(function (key) {
6
+ if (key === "default" || key === "__esModule") return;
7
+ if (key in exports && exports[key] === _cmsFetchMocks[key]) return;
8
+ exports[key] = _cmsFetchMocks[key];
9
+ });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_cmsFetchMocks","require","Object","keys","forEach","key","exports"],"sources":["../../../src/testkit/index.ts"],"sourcesContent":["export * from './cmsFetchMocks';\n"],"mappings":";;;AAAA,IAAAA,cAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,cAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,cAAA,CAAAK,GAAA;EAAAC,OAAA,CAAAD,GAAA,IAAAL,cAAA,CAAAK,GAAA;AAAA","ignoreList":[]}
@@ -8,27 +8,18 @@ jest.mock('@wix/essentials', () => ({
8
8
  }));
9
9
  const httpClient = {};
10
10
  describe('createCmsSchemaSource', () => {
11
- it('offers the CMS creatable field types in display order', () => {
11
+ it('declares the creatable types in display order — labels come from the standard names in the UI', () => {
12
12
  const source = createCmsSchemaSource({
13
13
  collectionId: 'Pokemon',
14
14
  httpClient,
15
15
  });
16
- expect(source.creatableFieldTypes.map((t) => t.patternsType)).toEqual([
17
- 'SHORT_TEXT',
18
- 'NUMBER',
19
- 'BOOLEAN',
20
- 'DATE',
16
+ expect(source.creatableFieldTypes).toEqual([
17
+ { patternsType: 'SHORT_TEXT' },
18
+ { patternsType: 'NUMBER' },
19
+ { patternsType: 'BOOLEAN' },
20
+ { patternsType: 'DATE' },
21
21
  ]);
22
22
  });
23
- it('carries label keys for the UI to resolve', () => {
24
- const source = createCmsSchemaSource({
25
- collectionId: 'Pokemon',
26
- httpClient,
27
- });
28
- const shortText = source.creatableFieldTypes.find((t) => t.patternsType === 'SHORT_TEXT');
29
- expect(shortText?.labelKey).toBe('cairo.customFields.fieldType.shortText');
30
- expect(shortText?.namePlaceholderKey).toBe('cairo.customFields.fieldType.shortText.Name.placeholder');
31
- });
32
23
  it('names the collection query after the collectionId', () => {
33
24
  const source = createCmsSchemaSource({
34
25
  collectionId: 'Pokemon',
@@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AAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE;QAC3D,MAAM,MAAM,GAAG,qBAAqB,CAAC;YACnC,YAAY,EAAE,SAAS;YACvB,UAAU;SACX,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAC5C,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -3,26 +3,10 @@ import { createCmsSchemaLoader, } from './loadCmsSchema';
3
3
  // The field types the add/edit modal offers, in display order. These are the
4
4
  // only types @wix/data can create (see PatternsFieldTypeToCmsFieldType).
5
5
  const CMS_CREATABLE_TYPES = [
6
- {
7
- patternsType: 'SHORT_TEXT',
8
- labelKey: 'cairo.customFields.fieldType.shortText',
9
- namePlaceholderKey: 'cairo.customFields.fieldType.shortText.Name.placeholder',
10
- },
11
- {
12
- patternsType: 'NUMBER',
13
- labelKey: 'cairo.customFields.fieldType.numberInteger',
14
- namePlaceholderKey: 'cairo.customFields.fieldType.numberInteger.Name.placeholder',
15
- },
16
- {
17
- patternsType: 'BOOLEAN',
18
- labelKey: 'cairo.customFields.fieldType.checkbox',
19
- namePlaceholderKey: 'cairo.customFields.fieldType.checkbox.Name.placeholder',
20
- },
21
- {
22
- patternsType: 'DATE',
23
- labelKey: 'cairo.customFields.fieldType.date',
24
- namePlaceholderKey: 'cairo.customFields.fieldType.date.Name.placeholder',
25
- },
6
+ { patternsType: 'SHORT_TEXT' },
7
+ { patternsType: 'NUMBER' },
8
+ { patternsType: 'BOOLEAN' },
9
+ { patternsType: 'DATE' },
26
10
  ];
27
11
  /**
28
12
  * Builds a ready-to-use `SchemaSource` for a CMS collection: wraps the CMS
@@ -1 +1 @@
1
- {"version":3,"file":"createCmsSchemaSource.js","sourceRoot":"","sources":["../../../src/adapter/createCmsSchemaSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EACL,qBAAqB,GAEtB,MAAM,iBAAiB,CAAC;AAEzB,6EAA6E;AAC7E,yEAAyE;AACzE,MAAM,mBAAmB,GAAyB;IAChD;QACE,YAAY,EAAE,YAAY;QAC1B,QAAQ,EAAE,wCAAwC;QAClD,kBAAkB,EAChB,yDAAyD;KAC5D;IACD;QACE,YAAY,EAAE,QAAQ;QACtB,QAAQ,EAAE,4CAA4C;QACtD,kBAAkB,EAChB,6DAA6D;KAChE;IACD;QACE,YAAY,EAAE,SAAS;QACvB,QAAQ,EAAE,uCAAuC;QACjD,kBAAkB,EAChB,wDAAwD;KAC3D;IACD;QACE,YAAY,EAAE,MAAM;QACpB,QAAQ,EAAE,mCAAmC;QAC7C,kBAAkB,EAAE,oDAAoD;KACzE;CACF,CAAC;AAMF;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAEnC,IAA+B;IAC/B,MAAM,EAAE,YAAY,EAAE,GAAG,UAAU,EAAE,GAAG,IAAI,CAAC;IAC7C,MAAM,MAAM,GAAG,qBAAqB,CAAI,UAAU,CAAC,CAAC;IACpD,OAAO,kBAAkB,CAAI;QAC3B,YAAY;QACZ,UAAU,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC;QACtC,mBAAmB,EAAE,mBAAmB;KACzC,CAAC,CAAC;AACL,CAAC"}
1
+ {"version":3,"file":"createCmsSchemaSource.js","sourceRoot":"","sources":["../../../src/adapter/createCmsSchemaSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EACL,qBAAqB,GAEtB,MAAM,iBAAiB,CAAC;AAEzB,6EAA6E;AAC7E,yEAAyE;AACzE,MAAM,mBAAmB,GAAyB;IAChD,EAAE,YAAY,EAAE,YAAY,EAAE;IAC9B,EAAE,YAAY,EAAE,QAAQ,EAAE;IAC1B,EAAE,YAAY,EAAE,SAAS,EAAE;IAC3B,EAAE,YAAY,EAAE,MAAM,EAAE;CACzB,CAAC;AAMF;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAEnC,IAA+B;IAC/B,MAAM,EAAE,YAAY,EAAE,GAAG,UAAU,EAAE,GAAG,IAAI,CAAC;IAC7C,MAAM,MAAM,GAAG,qBAAqB,CAAI,UAAU,CAAC,CAAC;IACpD,OAAO,kBAAkB,CAAI;QAC3B,YAAY;QACZ,UAAU,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC;QACtC,mBAAmB,EAAE,mBAAmB;KACzC,CAAC,CAAC;AACL,CAAC"}
@@ -1,5 +1,6 @@
1
1
  export { createCmsSchemaLoader, fetchCmsCollection, } from './loadCmsSchema';
2
2
  export { createCmsSchemaSource, } from './createCmsSchemaSource';
3
+ export { listCmsCollections, } from './listCmsCollections';
3
4
  export { transformCmsSchema, } from './transformCmsSchema';
4
5
  export { createCmsBackend } from './createCmsBackend';
5
6
  export { createCmsFieldActions } from './createCmsFieldActions';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/adapter/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,kBAAkB,GAEnB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,qBAAqB,GAEtB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,kBAAkB,GAEnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EACL,qBAAqB,GAGtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,+BAA+B,EAC/B,+BAA+B,EAC/B,cAAc,GACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE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O,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { collections } from '@wix/data';
2
+ import { errorHandler } from '@wix/essentials';
3
+ /** Lists the site's CMS collections — for collection pickers. */
4
+ export async function listCmsCollections() {
5
+ const response = await errorHandler.withErrorHandler(async () => collections.listDataCollections(), {});
6
+ return (response.collections ?? [])
7
+ .map((collection) => ({
8
+ id: collection._id ?? '',
9
+ displayName: collection.displayName ?? collection._id ?? '',
10
+ }))
11
+ .filter((collection) => collection.id !== '');
12
+ }
13
+ //# sourceMappingURL=listCmsCollections.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listCmsCollections.js","sourceRoot":"","sources":["../../../src/adapter/listCmsCollections.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAO/C,iEAAiE;AACjE,MAAM,CAAC,KAAK,UAAU,kBAAkB;IACtC,MAAM,QAAQ,GAAG,MAAM,YAAY,CAAC,gBAAgB,CAClD,KAAK,IAAI,EAAE,CAAC,WAAW,CAAC,mBAAmB,EAAE,EAC7C,EAAE,CACH,CAAC;IACF,OAAO,CAAC,QAAQ,CAAC,WAAW,IAAI,EAAE,CAAC;SAChC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;QACpB,EAAE,EAAE,UAAU,CAAC,GAAG,IAAI,EAAE;QACxB,WAAW,EAAE,UAAU,CAAC,WAAW,IAAI,UAAU,CAAC,GAAG,IAAI,EAAE;KAC5D,CAAC,CAAC;SACF,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,115 @@
1
+ import { when } from '@wix/sdk-testkit/fetch-mock';
2
+ import { collections as collectionsMeta } from '@wix/data/meta';
3
+ import { collections } from '@wix/data';
4
+ import { PatternsFieldTypeToCmsFieldType } from '../adapter/cmsFieldTypeMap';
5
+ // The query endpoint's request options aren't exposed on any public entry, so
6
+ // reach into the items SDK internals to derive its URL (no @wix/data/meta entry).
7
+ // eslint-disable-next-line no-restricted-imports
8
+ import * as itemsApi from '@wix/wix-data-items-sdk/build/cjs/src/data-items-api-client';
9
+ function toCmsFields(fields, idField) {
10
+ return Object.values(fields)
11
+ .filter((field) => field != null)
12
+ .map((field) => ({
13
+ key: field.id,
14
+ displayName: field.displayName,
15
+ type: PatternsFieldTypeToCmsFieldType[field.type] ?? collections.Type.TEXT,
16
+ ...(field.id === idField ? { systemField: true } : {}),
17
+ }));
18
+ }
19
+ function collectionResponse(collectionId, fields, displayField) {
20
+ return {
21
+ referencedCollections: [],
22
+ collection: {
23
+ id: collectionId,
24
+ collectionType: collections.CollectionType.WIX_APP,
25
+ pagingModes: [collections.PagingMode.OFFSET],
26
+ plugins: [],
27
+ displayField,
28
+ fields,
29
+ },
30
+ };
31
+ }
32
+ /**
33
+ * Routes the collection schema (`getDataCollection`) that `createCmsSchemaSource`
34
+ * loads. `@wix/data` issues real fetch calls; the caller's fetch-mock instance
35
+ * intercepts them by URL.
36
+ */
37
+ export function mockCmsCollection(fetchMock, options) {
38
+ if ('source' in options) {
39
+ const { source } = options;
40
+ const [url] = when(collectionsMeta.getDataCollection())
41
+ .withParams({ dataCollectionId: source.collectionId })
42
+ .reply(undefined);
43
+ fetchMock.route(url, async () => {
44
+ const { schema } = await source.loadSchema();
45
+ return collectionResponse(source.collectionId, toCmsFields(schema.fields, schema.idField), schema.displayField);
46
+ });
47
+ return;
48
+ }
49
+ const { collectionId, fields, displayField = 'name' } = options;
50
+ const [url, data] = when(collectionsMeta.getDataCollection())
51
+ .withParams({ dataCollectionId: collectionId })
52
+ .reply(collectionResponse(collectionId, fields, displayField));
53
+ fetchMock.route(url, data);
54
+ }
55
+ // The items-query endpoint has no `@wix/data/meta` entry, so derive its URL from
56
+ // the wix-data-items SDK request options.
57
+ function queryDataItemsMeta() {
58
+ return {
59
+ getUrl: (context) =>
60
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
+ itemsApi.reqOptions(itemsApi.queryDataItemsRequestOptions, {})(context).url,
62
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
+ httpMethod: itemsApi.queryDataItemsRequestOptions.method,
64
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
+ path: itemsApi.queryDataItemsRequestOptions.httpPath,
66
+ pathParams: {},
67
+ __requestType: null,
68
+ __originalRequestType: null,
69
+ __responseType: null,
70
+ __originalResponseType: null,
71
+ };
72
+ }
73
+ function decodeOffsetQuery(opts) {
74
+ const raw = opts.queryParams.get('.r');
75
+ const query = raw ? JSON.parse(atob(raw))?.query : undefined;
76
+ return {
77
+ offset: query?.paging?.offset ?? 0,
78
+ limit: query?.paging?.limit ?? 100,
79
+ };
80
+ }
81
+ function toResolver(items) {
82
+ if (typeof items === 'function') {
83
+ return items;
84
+ }
85
+ // Plain array: slice by the requested page, report the full count as total.
86
+ return (async (query) => {
87
+ const offset = query.offset ?? 0;
88
+ const limit = query.limit ?? items.length;
89
+ const page = items.slice(offset, offset + limit);
90
+ return {
91
+ items: page,
92
+ total: items.length,
93
+ hasNext: offset + page.length < items.length,
94
+ };
95
+ });
96
+ }
97
+ /**
98
+ * Routes the collection's rows (`items.query(...).find()`). Pass plain rows, or a
99
+ * resolver `(query) => Promise<{ items, total }>` — the latter is a schema source's
100
+ * `collectionConfig.fetchData`, so an in-memory source drives paging per request.
101
+ */
102
+ export function mockCmsItems(fetchMock, options) {
103
+ const resolve = 'source' in options
104
+ ? options.source.collectionConfig.fetchData
105
+ : toResolver(options.items);
106
+ const [url] = when(queryDataItemsMeta()).reply(null);
107
+ fetchMock.route(url, async (opts) => {
108
+ const { items: page, total } = await resolve(decodeOffsetQuery(opts));
109
+ return {
110
+ dataItems: page.map((data) => ({ data })),
111
+ pagingMetadata: { total },
112
+ };
113
+ });
114
+ }
115
+ //# sourceMappingURL=cmsFetchMocks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cmsFetchMocks.js","sourceRoot":"","sources":["../../../src/testkit/cmsFetchMocks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AACnD,OAAO,EAAE,WAAW,IAAI,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,OAAO,EAAE,+BAA+B,EAAE,MAAM,4BAA4B,CAAC;AAC7E,8EAA8E;AAC9E,kFAAkF;AAClF,iDAAiD;AACjD,OAAO,KAAK,QAAQ,MAAM,6DAA6D,CAAC;AAmBxF,SAAS,WAAW,CAAC,MAAwB,EAAE,OAAe;IAC5D,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;SACzB,MAAM,CAAC,CAAC,KAAK,EAAsC,EAAE,CAAC,KAAK,IAAI,IAAI,CAAC;SACpE,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QACf,GAAG,EAAE,KAAK,CAAC,EAAE;QACb,WAAW,EAAE,KAAK,CAAC,WAAW;QAC9B,IAAI,EACF,+BAA+B,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,IAAI,CAAC,IAAI;QACtE,GAAG,CAAC,KAAK,CAAC,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACvD,CAAC,CAAC,CAAC;AACR,CAAC;AAED,SAAS,kBAAkB,CACzB,YAAoB,EACpB,MAAqB,EACrB,YAAoB;IAEpB,OAAO;QACL,qBAAqB,EAAE,EAAE;QACzB,UAAU,EAAE;YACV,EAAE,EAAE,YAAY;YAChB,cAAc,EAAE,WAAW,CAAC,cAAc,CAAC,OAAO;YAClD,WAA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,MAAM,GAAG,KAAK,CAAC,CAAC;QACjD,OAAO;YACL,KAAK,EAAE,IAAI;YACX,KAAK,EAAE,KAAK,CAAC,MAAM;YACnB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM;SAC7C,CAAC;IACJ,CAAC,CAAqB,CAAC;AACzB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAC1B,SAAoB,EACpB,OAA+B;IAE/B,MAAM,OAAO,GACX,QAAQ,IAAI,OAAO;QACjB,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,SAAS;QAC3C,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAChC,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAErD,SAAS,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,EAAE,IAAe,EAAE,EAAE;QAC7C,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,OAAO,CAAC,iBAAiB,CAAI,IAAI,CAAC,CAAC,CAAC;QACzE,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;YACzC,cAAc,EAAE,EAAE,KAAK,EAAE;SAC1B,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './cmsFetchMocks';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/testkit/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createCmsSchemaSource.d.ts","sourceRoot":"","sources":["../../../src/adapter/createCmsSchemaSource.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAsB,YAAY,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAEL,KAAK,yBAAyB,EAC/B,MAAM,iBAAiB,CAAC;AA8BzB,MAAM,WAAW,yBAA0B,SAAQ,yBAAyB;IAC1E,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3D,IAAI,EAAE,yBAAyB,GAAG,YAAY,CAAC,CAAC,CAAC,CAQlD"}
1
+ {"version":3,"file":"createCmsSchemaSource.d.ts","sourceRoot":"","sources":["../../../src/adapter/createCmsSchemaSource.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAsB,YAAY,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,EAEL,KAAK,yBAAyB,EAC/B,MAAM,iBAAiB,CAAC;AAWzB,MAAM,WAAW,yBAA0B,SAAQ,yBAAyB;IAC1E,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3D,IAAI,EAAE,yBAAyB,GAAG,YAAY,CAAC,CAAC,CAAC,CAQlD"}
@@ -1,5 +1,6 @@
1
1
  export { createCmsSchemaLoader, fetchCmsCollection, type CreateCmsSchemaLoaderDeps, } from './loadCmsSchema';
2
2
  export { createCmsSchemaSource, type CreateCmsSchemaSourceDeps, } from './createCmsSchemaSource';
3
+ export { listCmsCollections, type CmsCollectionSummary, } from './listCmsCollections';
3
4
  export { transformCmsSchema, type TransformCmsSchemaOptions, } from './transformCmsSchema';
4
5
  export { createCmsBackend } from './createCmsBackend';
5
6
  export { createCmsFieldActions } from './createCmsFieldActions';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapter/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,KAAK,yBAAyB,GAC/B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,qBAAqB,EACrB,KAAK,yBAAyB,GAC/B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,kBAAkB,EAClB,KAAK,yBAAyB,GAC/B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EACL,qBAAqB,EACrB,KAAK,cAAc,EACnB,KAAK,oBAAoB,GAC1B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,+BAA+B,EAC/B,+BAA+B,EAC/B,cAAc,GACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapter/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,qBAAqB,EACrB,kBAAkB,EAClB,KAAK,yBAAyB,GAC/B,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,qBAAqB,EACrB,KAAK,yBAAyB,GAC/B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,kBAAkB,EAClB,KAAK,oBAAoB,GAC1B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,kBAAkB,EAClB,KAAK,yBAAyB,GAC/B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EACL,qBAAqB,EACrB,KAAK,cAAc,EACnB,KAAK,oBAAoB,GAC1B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,+BAA+B,EAC/B,+BAA+B,EAC/B,cAAc,GACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,7 @@
1
+ export interface CmsCollectionSummary {
2
+ id: string;
3
+ displayName: string;
4
+ }
5
+ /** Lists the site's CMS collections — for collection pickers. */
6
+ export declare function listCmsCollections(): Promise<CmsCollectionSummary[]>;
7
+ //# sourceMappingURL=listCmsCollections.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"listCmsCollections.d.ts","sourceRoot":"","sources":["../../../src/adapter/listCmsCollections.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,iEAAiE;AACjE,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAW1E"}
@@ -0,0 +1,47 @@
1
+ import { collections } from '@wix/data';
2
+ import type { SchemaSource } from '@wix/bex-core';
3
+ import type { FetchMock } from 'fetch-mock';
4
+ export type WixDataFields = NonNullable<collections.GetDataCollectionResponse['collection']>['fields'];
5
+ /**
6
+ * Mock the collection schema (`getDataCollection`) either from explicit CMS fields
7
+ * or straight from a schema source — a `createInMemorySchemaSource` becomes the
8
+ * single source of truth for the schema, its contract fields converted back to CMS
9
+ * fields (types with no CMS mapping fall back to text — enough to render).
10
+ */
11
+ export type MockCmsCollectionOptions<T extends Record<string, unknown> = Record<string, unknown>> = {
12
+ collectionId: string;
13
+ fields: WixDataFields;
14
+ displayField?: string;
15
+ } | {
16
+ source: SchemaSource<T>;
17
+ };
18
+ /**
19
+ * Routes the collection schema (`getDataCollection`) that `createCmsSchemaSource`
20
+ * loads. `@wix/data` issues real fetch calls; the caller's fetch-mock instance
21
+ * intercepts them by URL.
22
+ */
23
+ export declare function mockCmsCollection<T extends Record<string, unknown> = Record<string, unknown>>(fetchMock: FetchMock, options: MockCmsCollectionOptions<T>): void;
24
+ type ItemsResolver<T> = SchemaSource<T>['collectionConfig']['fetchData'];
25
+ /**
26
+ * What `mockCmsItems` serves: either plain rows or a resolver that returns a page
27
+ * per query (a schema source's `collectionConfig.fetchData` is exactly a resolver).
28
+ */
29
+ export type CmsItems<T extends Record<string, unknown>> = T[] | ItemsResolver<T>;
30
+ /**
31
+ * Mock the rows either from explicit items/resolver or straight from a schema
32
+ * source — pass `{ source }` and a `createInMemorySchemaSource` becomes the single
33
+ * source of truth for the rows too.
34
+ */
35
+ export type MockCmsItemsOptions<T extends Record<string, unknown>> = {
36
+ items: CmsItems<T>;
37
+ } | {
38
+ source: SchemaSource<T>;
39
+ };
40
+ /**
41
+ * Routes the collection's rows (`items.query(...).find()`). Pass plain rows, or a
42
+ * resolver `(query) => Promise<{ items, total }>` — the latter is a schema source's
43
+ * `collectionConfig.fetchData`, so an in-memory source drives paging per request.
44
+ */
45
+ export declare function mockCmsItems<T extends Record<string, unknown>>(fetchMock: FetchMock, options: MockCmsItemsOptions<T>): void;
46
+ export {};
47
+ //# sourceMappingURL=cmsFetchMocks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cmsFetchMocks.d.ts","sourceRoot":"","sources":["../../../src/testkit/cmsFetchMocks.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,KAAK,EAAU,YAAY,EAAE,MAAM,eAAe,CAAC;AAM1D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,MAAM,MAAM,aAAa,GAAG,WAAW,CACrC,WAAW,CAAC,yBAAyB,CAAC,YAAY,CAAC,CACpD,CAAC,QAAQ,CAAC,CAAC;AAEZ;;;;;GAKG;AACH,MAAM,MAAM,wBAAwB,CAClC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAEzD;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,aAAa,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,GACtE;IAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC;AAgChC;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3D,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,wBAAwB,CAAC,CAAC,CAAC,GAAG,IAAI,CAwBlE;AA2BD,KAAK,aAAa,CAAC,CAAC,IAAI,YAAY,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,WAAW,CAAC,CAAC;AAGzE;;;GAGG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAClD,CAAC,EAAE,GACH,aAAa,CAAC,CAAC,CAAC,CAAC;AAErB;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAC7D;IAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;CAAE,GACtB;IAAE,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,CAAA;CAAE,CAAC;AAsChC;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5D,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAC9B,IAAI,CAcN"}
@@ -0,0 +1,2 @@
1
+ export * from './cmsFetchMocks';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/testkit/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/patterns-cms",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "license": "UNLICENSED",
5
5
  "author": {
6
6
  "name": "Cairo",
@@ -23,25 +23,39 @@
23
23
  "files": [
24
24
  "dist/cjs",
25
25
  "dist/esm",
26
- "dist/types"
26
+ "dist/types",
27
+ "testkit"
27
28
  ],
28
29
  "dependencies": {
29
30
  "@babel/runtime": "^7.0.0",
30
- "@wix/bex-core": "2.332.0",
31
- "@wix/bex-utils": "2.119.0",
31
+ "@wix/bex-core": "2.333.0",
32
+ "@wix/bex-utils": "2.120.0",
32
33
  "@wix/data": "^1.0.323",
34
+ "@wix/wix-data-items-sdk": "^1.0.504",
33
35
  "lodash": "^4.17.20",
34
36
  "tslib": "^2.0.0"
35
37
  },
36
38
  "peerDependencies": {
37
- "@wix/essentials": ">=0.1.26"
39
+ "@wix/essentials": ">=0.1.26",
40
+ "@wix/sdk-testkit": ">=0.1.6",
41
+ "fetch-mock": ">=12.5.2"
42
+ },
43
+ "peerDependenciesMeta": {
44
+ "@wix/sdk-testkit": {
45
+ "optional": true
46
+ },
47
+ "fetch-mock": {
48
+ "optional": true
49
+ }
38
50
  },
39
51
  "devDependencies": {
40
52
  "@types/lodash": "^4.14.168",
41
53
  "@wix/eslint-config-yoshi": "^6.74.0",
42
54
  "@wix/essentials": "^0.1.26",
43
55
  "@wix/jest-yoshi-preset-base": "^6.74.0",
56
+ "@wix/sdk-testkit": "^0.1.6",
44
57
  "@wix/yoshi-flow-library": "^6.74.0",
58
+ "fetch-mock": "^12.5.2",
45
59
  "ts-node": "^10.9.1",
46
60
  "typescript": "~4.9.5"
47
61
  },
@@ -119,5 +133,5 @@
119
133
  "wallaby": {
120
134
  "autoDetect": true
121
135
  },
122
- "falconPackageHash": "94ba918d8c02193e752d29bf1f9a30ccfbffcae0517640e3a177b5fc"
136
+ "falconPackageHash": "b778bb61a618d44cd686bc11c5646a2fdc4f7b2ea33908335200bd2f"
123
137
  }
@@ -0,0 +1,6 @@
1
+ {
2
+ "main": "../dist/cjs/testkit/index.js",
3
+ "module": "../dist/esm/testkit/index.js",
4
+ "types": "../dist/types/testkit/index.d.ts",
5
+ "sideEffects": false
6
+ }