@wix/patterns-cms 1.10.0 → 1.14.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 (64) hide show
  1. package/dist/cjs/adapter/__tests__/transformCmsSchema.spec.js +9 -0
  2. package/dist/cjs/adapter/__tests__/transformCmsSchema.spec.js.map +1 -1
  3. package/dist/cjs/adapter/__tests__/useCmsSchemaSource.spec.js +142 -0
  4. package/dist/cjs/adapter/__tests__/useCmsSchemaSource.spec.js.map +1 -0
  5. package/dist/cjs/adapter/createCmsBackend.js +2 -0
  6. package/dist/cjs/adapter/createCmsBackend.js.map +1 -1
  7. package/dist/cjs/adapter/index.js +5 -3
  8. package/dist/cjs/adapter/index.js.map +1 -1
  9. package/dist/cjs/adapter/listCmsCollections.js +15 -0
  10. package/dist/cjs/adapter/listCmsCollections.js.map +1 -0
  11. package/dist/cjs/adapter/transformCmsSchema.js +4 -1
  12. package/dist/cjs/adapter/transformCmsSchema.js.map +1 -1
  13. package/dist/cjs/adapter/useCmsSchemaSource.js +72 -0
  14. package/dist/cjs/adapter/useCmsSchemaSource.js.map +1 -0
  15. package/dist/cjs/testkit/cmsFetchMocks.js +166 -0
  16. package/dist/cjs/testkit/cmsFetchMocks.js.map +1 -0
  17. package/dist/cjs/testkit/index.js +10 -0
  18. package/dist/cjs/testkit/index.js.map +1 -0
  19. package/dist/esm/adapter/__tests__/transformCmsSchema.spec.js +5 -0
  20. package/dist/esm/adapter/__tests__/transformCmsSchema.spec.js.map +1 -1
  21. package/dist/esm/adapter/__tests__/useCmsSchemaSource.spec.js +117 -0
  22. package/dist/esm/adapter/__tests__/useCmsSchemaSource.spec.js.map +1 -0
  23. package/dist/esm/adapter/createCmsBackend.js.map +1 -1
  24. package/dist/esm/adapter/index.js +2 -1
  25. package/dist/esm/adapter/index.js.map +1 -1
  26. package/dist/esm/adapter/listCmsCollections.js +13 -0
  27. package/dist/esm/adapter/listCmsCollections.js.map +1 -0
  28. package/dist/esm/adapter/transformCmsSchema.js +4 -1
  29. package/dist/esm/adapter/transformCmsSchema.js.map +1 -1
  30. package/dist/esm/adapter/useCmsSchemaSource.js +56 -0
  31. package/dist/esm/adapter/useCmsSchemaSource.js.map +1 -0
  32. package/dist/esm/testkit/cmsFetchMocks.js +116 -0
  33. package/dist/esm/testkit/cmsFetchMocks.js.map +1 -0
  34. package/dist/esm/testkit/index.js +2 -0
  35. package/dist/esm/testkit/index.js.map +1 -0
  36. package/dist/types/adapter/__tests__/useCmsSchemaSource.spec.d.ts +2 -0
  37. package/dist/types/adapter/__tests__/useCmsSchemaSource.spec.d.ts.map +1 -0
  38. package/dist/types/adapter/createCmsBackend.d.ts +4 -2
  39. package/dist/types/adapter/createCmsBackend.d.ts.map +1 -1
  40. package/dist/types/adapter/index.d.ts +2 -1
  41. package/dist/types/adapter/index.d.ts.map +1 -1
  42. package/dist/types/adapter/listCmsCollections.d.ts +7 -0
  43. package/dist/types/adapter/listCmsCollections.d.ts.map +1 -0
  44. package/dist/types/adapter/transformCmsSchema.d.ts.map +1 -1
  45. package/dist/types/adapter/useCmsSchemaSource.d.ts +19 -0
  46. package/dist/types/adapter/useCmsSchemaSource.d.ts.map +1 -0
  47. package/dist/types/testkit/cmsFetchMocks.d.ts +48 -0
  48. package/dist/types/testkit/cmsFetchMocks.d.ts.map +1 -0
  49. package/dist/types/testkit/index.d.ts +2 -0
  50. package/dist/types/testkit/index.d.ts.map +1 -0
  51. package/package.json +21 -6
  52. package/testkit/package.json +6 -0
  53. package/dist/cjs/adapter/__tests__/createCmsSchemaSource.spec.js +0 -38
  54. package/dist/cjs/adapter/__tests__/createCmsSchemaSource.spec.js.map +0 -1
  55. package/dist/cjs/adapter/createCmsSchemaSource.js +0 -43
  56. package/dist/cjs/adapter/createCmsSchemaSource.js.map +0 -1
  57. package/dist/esm/adapter/__tests__/createCmsSchemaSource.spec.js +0 -41
  58. package/dist/esm/adapter/__tests__/createCmsSchemaSource.spec.js.map +0 -1
  59. package/dist/esm/adapter/createCmsSchemaSource.js +0 -41
  60. package/dist/esm/adapter/createCmsSchemaSource.js.map +0 -1
  61. package/dist/types/adapter/__tests__/createCmsSchemaSource.spec.d.ts +0 -2
  62. package/dist/types/adapter/__tests__/createCmsSchemaSource.spec.d.ts.map +0 -1
  63. package/dist/types/adapter/createCmsSchemaSource.d.ts +0 -12
  64. package/dist/types/adapter/createCmsSchemaSource.d.ts.map +0 -1
@@ -0,0 +1,116 @@
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 { sourceFetchData } from '@wix/bex-core';
5
+ import { PatternsFieldTypeToCmsFieldType } from '../adapter/cmsFieldTypeMap';
6
+ // The query endpoint's request options aren't exposed on any public entry, so
7
+ // reach into the items SDK internals to derive its URL (no @wix/data/meta entry).
8
+ // eslint-disable-next-line no-restricted-imports
9
+ import * as itemsApi from '@wix/wix-data-items-sdk/build/cjs/src/data-items-api-client';
10
+ function toCmsFields(fields, idField) {
11
+ return Object.values(fields)
12
+ .filter((field) => field != null)
13
+ .map((field) => ({
14
+ key: field.id,
15
+ displayName: field.displayName,
16
+ type: PatternsFieldTypeToCmsFieldType[field.type] ?? collections.Type.TEXT,
17
+ ...(field.id === idField ? { systemField: true } : {}),
18
+ }));
19
+ }
20
+ function collectionResponse(collectionId, fields, displayField) {
21
+ return {
22
+ referencedCollections: [],
23
+ collection: {
24
+ id: collectionId,
25
+ collectionType: collections.CollectionType.WIX_APP,
26
+ pagingModes: [collections.PagingMode.OFFSET],
27
+ plugins: [],
28
+ displayField,
29
+ fields,
30
+ },
31
+ };
32
+ }
33
+ /**
34
+ * Routes the collection schema (`getDataCollection`) that `useCmsSchemaSource`
35
+ * loads. `@wix/data` issues real fetch calls; the caller's fetch-mock instance
36
+ * intercepts them by URL.
37
+ */
38
+ export function mockCmsCollection(fetchMock, options) {
39
+ if ('source' in options) {
40
+ const { source } = options;
41
+ const [url] = when(collectionsMeta.getDataCollection())
42
+ .withParams({ dataCollectionId: source.collectionId })
43
+ .reply(undefined);
44
+ fetchMock.route(url, async () => {
45
+ const { schema } = await source.loadSchema();
46
+ return collectionResponse(source.collectionId, toCmsFields(schema.fields, schema.idField), schema.displayField);
47
+ });
48
+ return;
49
+ }
50
+ const { collectionId, fields, displayField = 'name' } = options;
51
+ const [url, data] = when(collectionsMeta.getDataCollection())
52
+ .withParams({ dataCollectionId: collectionId })
53
+ .reply(collectionResponse(collectionId, fields, displayField));
54
+ fetchMock.route(url, data);
55
+ }
56
+ // The items-query endpoint has no `@wix/data/meta` entry, so derive its URL from
57
+ // the wix-data-items SDK request options.
58
+ function queryDataItemsMeta() {
59
+ return {
60
+ getUrl: (context) =>
61
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
62
+ itemsApi.reqOptions(itemsApi.queryDataItemsRequestOptions, {})(context).url,
63
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
64
+ httpMethod: itemsApi.queryDataItemsRequestOptions.method,
65
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
66
+ path: itemsApi.queryDataItemsRequestOptions.httpPath,
67
+ pathParams: {},
68
+ __requestType: null,
69
+ __originalRequestType: null,
70
+ __responseType: null,
71
+ __originalResponseType: null,
72
+ };
73
+ }
74
+ function decodeOffsetQuery(opts) {
75
+ const raw = opts.queryParams.get('.r');
76
+ const query = raw ? JSON.parse(atob(raw))?.query : undefined;
77
+ return {
78
+ offset: query?.paging?.offset ?? 0,
79
+ limit: query?.paging?.limit ?? 100,
80
+ };
81
+ }
82
+ function toResolver(items) {
83
+ if (typeof items === 'function') {
84
+ return items;
85
+ }
86
+ // Plain array: slice by the requested page, report the full count as total.
87
+ return (async (query) => {
88
+ const offset = query.offset ?? 0;
89
+ const limit = query.limit ?? items.length;
90
+ const page = items.slice(offset, offset + limit);
91
+ return {
92
+ items: page,
93
+ total: items.length,
94
+ hasNext: offset + page.length < items.length,
95
+ };
96
+ });
97
+ }
98
+ /**
99
+ * Routes the collection's rows (`items.query(...).find()`). Pass plain rows, or a
100
+ * resolver `(query) => Promise<{ items, total }>` — the latter is a schema source's
101
+ * `sourceFetchData(source)`, so an in-memory source drives paging per request.
102
+ */
103
+ export function mockCmsItems(fetchMock, options) {
104
+ const resolve = 'source' in options
105
+ ? sourceFetchData(options.source)
106
+ : toResolver(options.items);
107
+ const [url] = when(queryDataItemsMeta()).reply(null);
108
+ fetchMock.route(url, async (opts) => {
109
+ const { items: page, total } = await resolve(decodeOffsetQuery(opts));
110
+ return {
111
+ dataItems: page.map((data) => ({ data })),
112
+ pagingMetadata: { total },
113
+ };
114
+ });
115
+ }
116
+ //# 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;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,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,CA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,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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=useCmsSchemaSource.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCmsSchemaSource.spec.d.ts","sourceRoot":"","sources":["../../../../src/adapter/__tests__/useCmsSchemaSource.spec.ts"],"names":[],"mappings":""}
@@ -1,9 +1,11 @@
1
- import type { CollectionBackend, Schema } from '@wix/bex-core';
1
+ import type { CollectionBackend, CollectionBackendBase, Schema } from '@wix/bex-core';
2
2
  type SchemaFields = Schema['fields'];
3
+ /** CMS supports every item capability except `move`. */
4
+ export type CmsCollectionBackend<T extends Record<string, unknown> = Record<string, unknown>> = CollectionBackend<T> & Required<Omit<CollectionBackendBase<T>, 'move'>>;
3
5
  /**
4
6
  * Builds the `CollectionBackend` for a CMS collection over `@wix/data`. Reference
5
7
  * fields are expanded via `.include(...)` on `get`/`find`.
6
8
  */
7
- export declare function createCmsBackend<T extends Record<string, unknown> = Record<string, unknown>>(collectionId: string, fields: SchemaFields): CollectionBackend<T>;
9
+ export declare function createCmsBackend<T extends Record<string, unknown> = Record<string, unknown>>(collectionId: string, fields: SchemaFields): CmsCollectionBackend<T>;
8
10
  export {};
9
11
  //# sourceMappingURL=createCmsBackend.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createCmsBackend.d.ts","sourceRoot":"","sources":["../../../src/adapter/createCmsBackend.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,iBAAiB,EAIjB,MAAM,EACP,MAAM,eAAe,CAAC;AAMvB,KAAK,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AAuCrC;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3D,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,iBAAiB,CAAC,CAAC,CAAC,CA6HlE"}
1
+ {"version":3,"file":"createCmsBackend.d.ts","sourceRoot":"","sources":["../../../src/adapter/createCmsBackend.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,iBAAiB,EACjB,qBAAqB,EAIrB,MAAM,EACP,MAAM,eAAe,CAAC;AAMvB,KAAK,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AAuCrC,wDAAwD;AACxD,MAAM,MAAM,oBAAoB,CAC9B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IACzD,iBAAiB,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;AAE5E;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3D,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,oBAAoB,CAAC,CAAC,CAAC,CA6HrE"}
@@ -1,5 +1,6 @@
1
1
  export { createCmsSchemaLoader, fetchCmsCollection, type CreateCmsSchemaLoaderDeps, } from './loadCmsSchema';
2
- export { createCmsSchemaSource, type CreateCmsSchemaSourceDeps, } from './createCmsSchemaSource';
2
+ export { useCmsSchemaSource, type UseCmsSchemaSourceDeps, } from './useCmsSchemaSource';
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,kBAAkB,EAClB,KAAK,sBAAsB,GAC5B,MAAM,sBAAsB,CAAC;AAC9B,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"}
@@ -1 +1 @@
1
- {"version":3,"file":"transformCmsSchema.d.ts","sourceRoot":"","sources":["../../../src/adapter/transformCmsSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,KAAK,EAAS,MAAM,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,kBAAkB,CAAC;AAE1B,MAAM,WAAW,yBAAyB;IACxC,8CAA8C;IAC9C,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,uEAAuE;IACvE,qBAAqB,CAAC,EAAE,oBAAoB,EAAE,CAAC;CAChD;AAED,sFAAsF;AACtF,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,WAAW,CAAC,cAAc,EAClC,OAAO,GAAE,yBAA8B,GACtC,MAAM,CAkFR"}
1
+ {"version":3,"file":"transformCmsSchema.d.ts","sourceRoot":"","sources":["../../../src/adapter/transformCmsSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,KAAK,EAAS,MAAM,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,kBAAkB,CAAC;AAE1B,MAAM,WAAW,yBAAyB;IACxC,8CAA8C;IAC9C,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B,uEAAuE;IACvE,qBAAqB,CAAC,EAAE,oBAAoB,EAAE,CAAC;CAChD;AAED,sFAAsF;AACtF,wBAAgB,kBAAkB,CAChC,MAAM,EAAE,WAAW,CAAC,cAAc,EAClC,OAAO,GAAE,yBAA8B,GACtC,MAAM,CAsFR"}
@@ -0,0 +1,19 @@
1
+ import type { SchemaSource, SchemaSourceInput } from '@wix/bex-core';
2
+ import { type CreateCmsSchemaLoaderDeps } from './loadCmsSchema';
3
+ export interface UseCmsSchemaSourceDeps extends Omit<CreateCmsSchemaLoaderDeps, 'httpClient'> {
4
+ collectionId: string;
5
+ /** Default: the patterns container's client. */
6
+ httpClient?: CreateCmsSchemaLoaderDeps['httpClient'];
7
+ /** Seed sources for referenced collections, keyed by referenced collection
8
+ * id. Usually unnecessary — reference fields are resolved automatically from
9
+ * the loaded schema. Provide an entry only to override the auto-built one. */
10
+ references?: Record<string, SchemaSource<any>>;
11
+ }
12
+ export declare function cmsSchemaSourceInput<T extends Record<string, unknown> = Record<string, unknown>>(deps: UseCmsSchemaSourceDeps & Pick<CreateCmsSchemaLoaderDeps, 'httpClient'>): SchemaSourceInput<T>;
13
+ /**
14
+ * A ready-to-use `SchemaSource` for a CMS collection: wraps the CMS schema
15
+ * loader and supplies the CMS field types. Pass it to a `@wix/patterns/schema`
16
+ * collection hook.
17
+ */
18
+ export declare function useCmsSchemaSource<T extends Record<string, unknown> = Record<string, unknown>>(deps: UseCmsSchemaSourceDeps): SchemaSource<T>;
19
+ //# sourceMappingURL=useCmsSchemaSource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCmsSchemaSource.d.ts","sourceRoot":"","sources":["../../../src/adapter/useCmsSchemaSource.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,YAAY,EACZ,iBAAiB,EAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EAEL,KAAK,yBAAyB,EAC/B,MAAM,iBAAiB,CAAC;AAWzB,MAAM,WAAW,sBACf,SAAQ,IAAI,CAAC,yBAAyB,EAAE,YAAY,CAAC;IACrD,YAAY,EAAE,MAAM,CAAC;IACrB,gDAAgD;IAChD,UAAU,CAAC,EAAE,yBAAyB,CAAC,YAAY,CAAC,CAAC;IACrD;;mFAE+E;IAC/E,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC;CAChD;AAED,wBAAgB,oBAAoB,CAClC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAE3D,IAAI,EAAE,sBAAsB,GAAG,IAAI,CAAC,yBAAyB,EAAE,YAAY,CAAC,GAC3E,iBAAiB,CAAC,CAAC,CAAC,CAqCtB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC3D,IAAI,EAAE,sBAAsB,GAAG,YAAY,CAAC,CAAC,CAAC,CAQ/C"}
@@ -0,0 +1,48 @@
1
+ import { collections } from '@wix/data';
2
+ import { sourceFetchData } from '@wix/bex-core';
3
+ import type { SchemaSource } from '@wix/bex-core';
4
+ import type { FetchMock } from 'fetch-mock';
5
+ export type WixDataFields = NonNullable<collections.GetDataCollectionResponse['collection']>['fields'];
6
+ /**
7
+ * Mock the collection schema (`getDataCollection`) either from explicit CMS fields
8
+ * or straight from a schema source — a `createInMemorySchemaSource` becomes the
9
+ * single source of truth for the schema, its contract fields converted back to CMS
10
+ * fields (types with no CMS mapping fall back to text — enough to render).
11
+ */
12
+ export type MockCmsCollectionOptions<T extends Record<string, unknown> = Record<string, unknown>> = {
13
+ collectionId: string;
14
+ fields: WixDataFields;
15
+ displayField?: string;
16
+ } | {
17
+ source: SchemaSource<T>;
18
+ };
19
+ /**
20
+ * Routes the collection schema (`getDataCollection`) that `useCmsSchemaSource`
21
+ * loads. `@wix/data` issues real fetch calls; the caller's fetch-mock instance
22
+ * intercepts them by URL.
23
+ */
24
+ export declare function mockCmsCollection<T extends Record<string, unknown> = Record<string, unknown>>(fetchMock: FetchMock, options: MockCmsCollectionOptions<T>): void;
25
+ type ItemsResolver<T> = ReturnType<typeof sourceFetchData<T>>;
26
+ /**
27
+ * What `mockCmsItems` serves: either plain rows or a resolver that returns a page
28
+ * per query (a schema source's derived fetch is exactly a resolver).
29
+ */
30
+ export type CmsItems<T extends Record<string, unknown>> = T[] | ItemsResolver<T>;
31
+ /**
32
+ * Mock the rows either from explicit items/resolver or straight from a schema
33
+ * source — pass `{ source }` and a `createInMemorySchemaSource` becomes the single
34
+ * source of truth for the rows too.
35
+ */
36
+ export type MockCmsItemsOptions<T extends Record<string, unknown>> = {
37
+ items: CmsItems<T>;
38
+ } | {
39
+ source: SchemaSource<T>;
40
+ };
41
+ /**
42
+ * Routes the collection's rows (`items.query(...).find()`). Pass plain rows, or a
43
+ * resolver `(query) => Promise<{ items, total }>` — the latter is a schema source's
44
+ * `sourceFetchData(source)`, so an in-memory source drives paging per request.
45
+ */
46
+ export declare function mockCmsItems<T extends Record<string, unknown>>(fetchMock: FetchMock, options: MockCmsItemsOptions<T>): void;
47
+ export {};
48
+ //# 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,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,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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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.14.0",
4
4
  "license": "UNLICENSED",
5
5
  "author": {
6
6
  "name": "Cairo",
@@ -23,25 +23,40 @@
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.336.0",
32
+ "@wix/bex-utils": "2.123.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
+ "react": "^16.13.1 || ^17.0.0 || ^18.0.0"
43
+ },
44
+ "peerDependenciesMeta": {
45
+ "@wix/sdk-testkit": {
46
+ "optional": true
47
+ },
48
+ "fetch-mock": {
49
+ "optional": true
50
+ }
38
51
  },
39
52
  "devDependencies": {
40
53
  "@types/lodash": "^4.14.168",
41
54
  "@wix/eslint-config-yoshi": "^6.74.0",
42
55
  "@wix/essentials": "^0.1.26",
43
56
  "@wix/jest-yoshi-preset-base": "^6.74.0",
57
+ "@wix/sdk-testkit": "^0.1.6",
44
58
  "@wix/yoshi-flow-library": "^6.74.0",
59
+ "fetch-mock": "^12.5.2",
45
60
  "ts-node": "^10.9.1",
46
61
  "typescript": "~4.9.5"
47
62
  },
@@ -119,5 +134,5 @@
119
134
  "wallaby": {
120
135
  "autoDetect": true
121
136
  },
122
- "falconPackageHash": "94ba918d8c02193e752d29bf1f9a30ccfbffcae0517640e3a177b5fc"
137
+ "falconPackageHash": "27c83118bf877a3a4fd8b401b06ecd9864e85679cfe165d8b1d9c36d"
123
138
  }
@@ -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
+ }
@@ -1,38 +0,0 @@
1
- "use strict";
2
-
3
- var _createCmsSchemaSource = require("../createCmsSchemaSource");
4
- // loadCmsSchema imports errorHandler at evaluation time; stub it so importing
5
- // the source factory is side-effect free. The loader itself isn't run here.
6
- jest.mock('@wix/essentials', () => ({
7
- errorHandler: {
8
- withErrorHandler: fn => fn()
9
- }
10
- }));
11
- const httpClient = {};
12
- describe('createCmsSchemaSource', () => {
13
- it('offers the CMS creatable field types in display order', () => {
14
- const source = (0, _createCmsSchemaSource.createCmsSchemaSource)({
15
- collectionId: 'Pokemon',
16
- httpClient
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');
28
- });
29
- it('names the collection query after the collectionId', () => {
30
- const source = (0, _createCmsSchemaSource.createCmsSchemaSource)({
31
- collectionId: 'Pokemon',
32
- httpClient
33
- });
34
- expect(source.collectionId).toBe('Pokemon');
35
- expect(source.collectionConfig.queryName).toBe('Pokemon');
36
- });
37
- });
38
- //# sourceMappingURL=createCmsSchemaSource.spec.js.map
@@ -1 +0,0 @@
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,C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,gBAAgB,CAACC,SAAS,CAAC,CAACH,IAAI,CAAC,SAAS,CAAC;EAC3D,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- exports.__esModule = true;
4
- exports.createCmsSchemaSource = createCmsSchemaSource;
5
- var _bexCore = require("@wix/bex-core");
6
- var _loadCmsSchema = require("./loadCmsSchema");
7
- // The field types the add/edit modal offers, in display order. These are the
8
- // only types @wix/data can create (see PatternsFieldTypeToCmsFieldType).
9
- const CMS_CREATABLE_TYPES = [{
10
- patternsType: 'SHORT_TEXT',
11
- labelKey: 'cairo.customFields.fieldType.shortText',
12
- namePlaceholderKey: 'cairo.customFields.fieldType.shortText.Name.placeholder'
13
- }, {
14
- patternsType: 'NUMBER',
15
- labelKey: 'cairo.customFields.fieldType.numberInteger',
16
- namePlaceholderKey: 'cairo.customFields.fieldType.numberInteger.Name.placeholder'
17
- }, {
18
- patternsType: 'BOOLEAN',
19
- labelKey: 'cairo.customFields.fieldType.checkbox',
20
- namePlaceholderKey: 'cairo.customFields.fieldType.checkbox.Name.placeholder'
21
- }, {
22
- patternsType: 'DATE',
23
- labelKey: 'cairo.customFields.fieldType.date',
24
- namePlaceholderKey: 'cairo.customFields.fieldType.date.Name.placeholder'
25
- }];
26
- /**
27
- * Builds a ready-to-use `SchemaSource` for a CMS collection: wraps the CMS
28
- * schema loader and supplies the CMS field types. Pass it to `<Table>` and spread
29
- * its `collectionConfig` into the collection hook.
30
- */
31
- function createCmsSchemaSource(deps) {
32
- const {
33
- collectionId,
34
- ...loaderDeps
35
- } = deps;
36
- const loader = (0, _loadCmsSchema.createCmsSchemaLoader)(loaderDeps);
37
- return (0, _bexCore.defineSchemaSource)({
38
- collectionId,
39
- loadSchema: () => loader(collectionId),
40
- creatableFieldTypes: CMS_CREATABLE_TYPES
41
- });
42
- }
43
- //# sourceMappingURL=createCmsSchemaSource.js.map
@@ -1 +0,0 @@
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,41 +0,0 @@
1
- import { createCmsSchemaSource } from '../createCmsSchemaSource';
2
- // loadCmsSchema imports errorHandler at evaluation time; stub it so importing
3
- // the source factory is side-effect free. The loader itself isn't run here.
4
- jest.mock('@wix/essentials', () => ({
5
- errorHandler: {
6
- withErrorHandler: (fn) => fn(),
7
- },
8
- }));
9
- const httpClient = {};
10
- describe('createCmsSchemaSource', () => {
11
- it('offers the CMS creatable field types in display order', () => {
12
- const source = createCmsSchemaSource({
13
- collectionId: 'Pokemon',
14
- httpClient,
15
- });
16
- expect(source.creatableFieldTypes.map((t) => t.patternsType)).toEqual([
17
- 'SHORT_TEXT',
18
- 'NUMBER',
19
- 'BOOLEAN',
20
- 'DATE',
21
- ]);
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
- it('names the collection query after the collectionId', () => {
33
- const source = createCmsSchemaSource({
34
- collectionId: 'Pokemon',
35
- httpClient,
36
- });
37
- expect(source.collectionId).toBe('Pokemon');
38
- expect(source.collectionConfig.queryName).toBe('Pokemon');
39
- });
40
- });
41
- //# sourceMappingURL=createCmsSchemaSource.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createCmsSchemaSource.spec.js","sourceRoot":"","sources":["../../../../src/adapter/__tests__/createCmsSchemaSource.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAGjE,8EAA8E;AAC9E,4EAA4E;AAC5E,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,GAAG,EAAE,CAAC,CAAC;IAClC,YAAY,EAAE;QACZ,gBAAgB,EAAE,CAAC,EAAiB,EAAE,EAAE,CAAC,EAAE,EAAE;KAC9C;CACF,CAAC,CAAC,CAAC;AAEJ,MAAM,UAAU,GAAG,EAAwD,CAAC;AAE5E,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,EAAE,CAAC,uDAAuD,EAAE,GAAG,EAAE;QAC/D,MAAM,MAAM,GAAG,qBAAqB,CAAC;YACnC,YAAY,EAAE,SAAS;YACvB,UAAU;SACX,CAAC,CAAC;QAEH,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC;YACpE,YAAY;YACZ,QAAQ;YACR,SAAS;YACT,MAAM;SACP,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;QAClD,MAAM,MAAM,GAAG,qBAAqB,CAAC;YACnC,YAAY,EAAE,SAAS;YACvB,UAAU;SACX,CAAC,CAAC;QAEH,MAAM,SAAS,GAAG,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAC/C,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,KAAK,YAAY,CACvC,CAAC;QACF,MAAM,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;QAC3E,MAAM,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAC,IAAI,CACxC,yDAAyD,CAC1D,CAAC;IACJ,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"}
@@ -1,41 +0,0 @@
1
- import { defineSchemaSource } from '@wix/bex-core';
2
- import { createCmsSchemaLoader, } from './loadCmsSchema';
3
- // The field types the add/edit modal offers, in display order. These are the
4
- // only types @wix/data can create (see PatternsFieldTypeToCmsFieldType).
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
- },
26
- ];
27
- /**
28
- * Builds a ready-to-use `SchemaSource` for a CMS collection: wraps the CMS
29
- * schema loader and supplies the CMS field types. Pass it to `<Table>` and spread
30
- * its `collectionConfig` into the collection hook.
31
- */
32
- export function createCmsSchemaSource(deps) {
33
- const { collectionId, ...loaderDeps } = deps;
34
- const loader = createCmsSchemaLoader(loaderDeps);
35
- return defineSchemaSource({
36
- collectionId,
37
- loadSchema: () => loader(collectionId),
38
- creatableFieldTypes: CMS_CREATABLE_TYPES,
39
- });
40
- }
41
- //# sourceMappingURL=createCmsSchemaSource.js.map
@@ -1 +0,0 @@
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,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=createCmsSchemaSource.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createCmsSchemaSource.spec.d.ts","sourceRoot":"","sources":["../../../../src/adapter/__tests__/createCmsSchemaSource.spec.ts"],"names":[],"mappings":""}
@@ -1,12 +0,0 @@
1
- import type { SchemaSource } from '@wix/bex-core';
2
- import { type CreateCmsSchemaLoaderDeps } from './loadCmsSchema';
3
- export interface CreateCmsSchemaSourceDeps extends CreateCmsSchemaLoaderDeps {
4
- collectionId: string;
5
- }
6
- /**
7
- * Builds a ready-to-use `SchemaSource` for a CMS collection: wraps the CMS
8
- * schema loader and supplies the CMS field types. Pass it to `<Table>` and spread
9
- * its `collectionConfig` into the collection hook.
10
- */
11
- export declare function createCmsSchemaSource<T extends Record<string, unknown> = Record<string, unknown>>(deps: CreateCmsSchemaSourceDeps): SchemaSource<T>;
12
- //# sourceMappingURL=createCmsSchemaSource.d.ts.map
@@ -1 +0,0 @@
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"}