@payloadcms/plugin-import-export 4.0.0-internal.7e57eed → 4.0.0-internal.8089ef7
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.
- package/dist/components/CollectionField/index.d.ts +3 -2
- package/dist/components/CollectionField/index.d.ts.map +1 -1
- package/dist/components/CollectionField/index.js.map +1 -1
- package/dist/components/ExportListMenuItem/index.d.ts.map +1 -1
- package/dist/components/ExportListMenuItem/index.js +14 -12
- package/dist/components/ExportListMenuItem/index.js.map +1 -1
- package/dist/components/ExportPreview/index.css +0 -3
- package/dist/components/ExportPreview/index.d.ts.map +1 -1
- package/dist/components/ExportPreview/index.js +11 -1
- package/dist/components/ExportPreview/index.js.map +1 -1
- package/dist/components/FieldsToExport/index.d.ts +3 -2
- package/dist/components/FieldsToExport/index.d.ts.map +1 -1
- package/dist/components/FieldsToExport/index.js +18 -15
- package/dist/components/FieldsToExport/index.js.map +1 -1
- package/dist/components/FieldsToExport/reduceFields.d.ts +6 -0
- package/dist/components/FieldsToExport/reduceFields.d.ts.map +1 -1
- package/dist/components/FieldsToExport/reduceFields.js +4 -0
- package/dist/components/FieldsToExport/reduceFields.js.map +1 -1
- package/dist/components/FormatField/index.d.ts +3 -2
- package/dist/components/FormatField/index.d.ts.map +1 -1
- package/dist/components/FormatField/index.js.map +1 -1
- package/dist/components/ImportListMenuItem/index.d.ts.map +1 -1
- package/dist/components/ImportListMenuItem/index.js +14 -12
- package/dist/components/ImportListMenuItem/index.js.map +1 -1
- package/dist/components/ImportPreview/index.css +0 -3
- package/dist/components/ImportPreview/index.d.ts.map +1 -1
- package/dist/components/ImportPreview/index.js +27 -8
- package/dist/components/ImportPreview/index.js.map +1 -1
- package/dist/components/LimitField/index.d.ts +3 -2
- package/dist/components/LimitField/index.d.ts.map +1 -1
- package/dist/components/LimitField/index.js.map +1 -1
- package/dist/components/LocaleField/index.d.ts +3 -2
- package/dist/components/LocaleField/index.d.ts.map +1 -1
- package/dist/components/LocaleField/index.js.map +1 -1
- package/dist/components/Page/index.d.ts +3 -2
- package/dist/components/Page/index.d.ts.map +1 -1
- package/dist/components/Page/index.js.map +1 -1
- package/dist/components/RelationshipCell/getRelationshipGroupKey.d.ts +7 -0
- package/dist/components/RelationshipCell/getRelationshipGroupKey.d.ts.map +1 -0
- package/dist/components/RelationshipCell/getRelationshipGroupKey.js +3 -0
- package/dist/components/RelationshipCell/getRelationshipGroupKey.js.map +1 -0
- package/dist/components/RelationshipCell/getRelationshipGroups.d.ts +43 -0
- package/dist/components/RelationshipCell/getRelationshipGroups.d.ts.map +1 -0
- package/dist/components/RelationshipCell/getRelationshipGroups.js +109 -0
- package/dist/components/RelationshipCell/getRelationshipGroups.js.map +1 -0
- package/dist/components/RelationshipCell/index.css +30 -0
- package/dist/components/RelationshipCell/index.d.ts +15 -0
- package/dist/components/RelationshipCell/index.d.ts.map +1 -0
- package/dist/components/RelationshipCell/index.js +57 -0
- package/dist/components/RelationshipCell/index.js.map +1 -0
- package/dist/components/SortBy/index.d.ts +3 -2
- package/dist/components/SortBy/index.d.ts.map +1 -1
- package/dist/components/SortBy/index.js.map +1 -1
- package/dist/components/SortOrder/index.d.ts +3 -2
- package/dist/components/SortOrder/index.d.ts.map +1 -1
- package/dist/components/SortOrder/index.js.map +1 -1
- package/dist/export/batchProcessor.d.ts +2 -1
- package/dist/export/batchProcessor.d.ts.map +1 -1
- package/dist/export/batchProcessor.js +6 -2
- package/dist/export/batchProcessor.js.map +1 -1
- package/dist/export/createExport.d.ts +2 -0
- package/dist/export/createExport.d.ts.map +1 -1
- package/dist/export/createExport.js +6 -1
- package/dist/export/createExport.js.map +1 -1
- package/dist/export/getCreateExportCollectionTask.d.ts.map +1 -1
- package/dist/export/getCreateExportCollectionTask.js +11 -0
- package/dist/export/getCreateExportCollectionTask.js.map +1 -1
- package/dist/export/getExportCollection.d.ts.map +1 -1
- package/dist/export/getExportCollection.js +5 -0
- package/dist/export/getExportCollection.js.map +1 -1
- package/dist/export/handleDownload.d.ts.map +1 -1
- package/dist/export/handleDownload.js +7 -3
- package/dist/export/handleDownload.js.map +1 -1
- package/dist/export/handlePreview.d.ts.map +1 -1
- package/dist/export/handlePreview.js +24 -5
- package/dist/export/handlePreview.js.map +1 -1
- package/dist/exports/types.d.ts +1 -1
- package/dist/exports/types.d.ts.map +1 -1
- package/dist/exports/types.js.map +1 -1
- package/dist/import/batchProcessor.d.ts +2 -1
- package/dist/import/batchProcessor.d.ts.map +1 -1
- package/dist/import/batchProcessor.js +15 -8
- package/dist/import/batchProcessor.js.map +1 -1
- package/dist/import/createImport.d.ts +3 -2
- package/dist/import/createImport.d.ts.map +1 -1
- package/dist/import/createImport.js +8 -1
- package/dist/import/createImport.js.map +1 -1
- package/dist/import/getCreateImportCollectionTask.d.ts.map +1 -1
- package/dist/import/getCreateImportCollectionTask.js +5 -2
- package/dist/import/getCreateImportCollectionTask.js.map +1 -1
- package/dist/import/getImportCollection.d.ts.map +1 -1
- package/dist/import/getImportCollection.js +2 -0
- package/dist/import/getImportCollection.js.map +1 -1
- package/dist/import/handlePreview.d.ts.map +1 -1
- package/dist/import/handlePreview.js +5 -1
- package/dist/import/handlePreview.js.map +1 -1
- package/dist/types.d.ts +17 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/getExportFieldFunctions.js +64 -27
- package/dist/utilities/getExportFieldFunctions.js.map +1 -1
- package/dist/utilities/getFileFromDoc.js +3 -3
- package/dist/utilities/getFileFromDoc.js.map +1 -1
- package/dist/utilities/getSelect.d.ts.map +1 -1
- package/dist/utilities/getSelect.js +11 -3
- package/dist/utilities/getSelect.js.map +1 -1
- package/dist/utilities/getSubmittedFormValues.d.ts +12 -0
- package/dist/utilities/getSubmittedFormValues.d.ts.map +1 -0
- package/dist/utilities/getSubmittedFormValues.js +24 -0
- package/dist/utilities/getSubmittedFormValues.js.map +1 -0
- package/dist/utilities/setNestedValue.d.ts +2 -1
- package/dist/utilities/setNestedValue.d.ts.map +1 -1
- package/dist/utilities/setNestedValue.js +65 -34
- package/dist/utilities/setNestedValue.js.map +1 -1
- package/package.json +9 -9
- package/dist/components/FieldsToExport/reduceFields.spec.js +0 -239
- package/dist/components/FieldsToExport/reduceFields.spec.js.map +0 -1
- package/dist/utilities/applyFieldHooks.spec.js +0 -205
- package/dist/utilities/applyFieldHooks.spec.js.map +0 -1
- package/dist/utilities/buildDisabledFieldRegex.spec.js +0 -64
- package/dist/utilities/buildDisabledFieldRegex.spec.js.map +0 -1
- package/dist/utilities/fieldToRegex.spec.js +0 -151
- package/dist/utilities/fieldToRegex.spec.js.map +0 -1
- package/dist/utilities/filterToSelectedFields.spec.js +0 -204
- package/dist/utilities/filterToSelectedFields.spec.js.map +0 -1
- package/dist/utilities/flattenObject.spec.js +0 -158
- package/dist/utilities/flattenObject.spec.js.map +0 -1
- package/dist/utilities/getExportFieldFunctions.spec.js +0 -50
- package/dist/utilities/getExportFieldFunctions.spec.js.map +0 -1
- package/dist/utilities/getImportFieldFunctions.spec.js +0 -167
- package/dist/utilities/getImportFieldFunctions.spec.js.map +0 -1
- package/dist/utilities/getSchemaColumns.spec.js +0 -157
- package/dist/utilities/getSchemaColumns.spec.js.map +0 -1
- package/dist/utilities/parseCSV.spec.js +0 -195
- package/dist/utilities/parseCSV.spec.js.map +0 -1
- package/dist/utilities/processRichTextField.spec.js +0 -308
- package/dist/utilities/processRichTextField.spec.js.map +0 -1
- package/dist/utilities/siblingDoc.spec.js +0 -278
- package/dist/utilities/siblingDoc.spec.js.map +0 -1
- package/dist/utilities/unflattenObject.spec.js +0 -819
- package/dist/utilities/unflattenObject.spec.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/applyFieldHooks.spec.ts"],"sourcesContent":["import { FlattenedField, PayloadRequest } from 'payload'\n\nimport type { ExportFieldHookEntry, ImportFieldHookEntry } from '../types.js'\n\nimport { describe, expect, it, vi } from 'vitest'\n\nimport { applyFieldHooks } from './applyFieldHooks.js'\n\nconst mockReq = {\n payload: {\n logger: {\n error: vi.fn(),\n },\n },\n} as unknown as PayloadRequest\n\ndescribe('applyFieldHooks parent + child traversal', () => {\n it('should run a parent group hook and still run child field hooks against the transformed value (export)', () => {\n const fields: FlattenedField[] = [\n {\n name: 'meta',\n type: 'group',\n flattenedFields: [{ name: 'slug', type: 'text' } as FlattenedField],\n } as unknown as FlattenedField,\n ]\n\n const fieldHooks: Record<string, ExportFieldHookEntry> = {\n meta: {\n type: 'beforeExport',\n fn: ({ value }) => {\n const obj = (value ?? {}) as Record<string, unknown>\n return { ...obj, slug: `${obj.slug ?? ''}-from-parent` }\n },\n },\n meta_slug: {\n type: 'beforeExport',\n fn: ({ value }) => `${value}-from-child`,\n },\n }\n\n const result = applyFieldHooks({\n type: 'beforeExport',\n data: { meta: { slug: 'raw' } },\n fieldHooks,\n fields,\n format: 'json',\n operation: 'export',\n req: mockReq,\n })\n\n // Parent hook ran first ('raw' → 'raw-from-parent'), then child hook ran against\n // the transformed value ('raw-from-parent' → 'raw-from-parent-from-child').\n expect(result.meta).toEqual({ slug: 'raw-from-parent-from-child' })\n })\n\n it('should run a parent group hook and still run child field hooks (import)', () => {\n const fields: FlattenedField[] = [\n {\n name: 'meta',\n type: 'group',\n flattenedFields: [{ name: 'slug', type: 'text' } as FlattenedField],\n } as unknown as FlattenedField,\n ]\n\n const fieldHooks: Record<string, ImportFieldHookEntry> = {\n meta: {\n type: 'beforeImport',\n fn: ({ value }) => {\n const obj = (value ?? {}) as Record<string, unknown>\n return { ...obj, slug: `${obj.slug ?? ''}-from-parent` }\n },\n },\n meta_slug: {\n type: 'beforeImport',\n fn: ({ value }) => `${value}-from-child`,\n },\n }\n\n const result = applyFieldHooks({\n type: 'beforeImport',\n data: { meta: { slug: 'raw' } },\n fieldHooks,\n fields,\n format: 'json',\n operation: 'import',\n req: mockReq,\n })\n\n expect(result.meta).toEqual({ slug: 'raw-from-parent-from-child' })\n })\n\n it('should run a parent array hook then child hooks for each item', () => {\n const fields: FlattenedField[] = [\n {\n name: 'items',\n type: 'array',\n flattenedFields: [{ name: 'note', type: 'text' } as FlattenedField],\n } as unknown as FlattenedField,\n ]\n\n const fieldHooks: Record<string, ExportFieldHookEntry> = {\n items: {\n type: 'beforeExport',\n fn: ({ value }) => {\n if (!Array.isArray(value)) {\n return value\n }\n return value.map((item) => ({\n ...(item as Record<string, unknown>),\n note: `${(item as Record<string, unknown>).note ?? ''}-parent`,\n }))\n },\n },\n items_note: {\n type: 'beforeExport',\n fn: ({ value }) => `${value}-child`,\n },\n }\n\n const result = applyFieldHooks({\n type: 'beforeExport',\n data: { items: [{ note: 'a' }, { note: 'b' }] },\n fieldHooks,\n fields,\n format: 'json',\n operation: 'export',\n req: mockReq,\n })\n\n expect(result.items).toEqual([{ note: 'a-parent-child' }, { note: 'b-parent-child' }])\n })\n\n it('should not recurse into children when the parent hook returns a primitive', () => {\n const fields: FlattenedField[] = [\n {\n name: 'meta',\n type: 'group',\n flattenedFields: [{ name: 'slug', type: 'text' } as FlattenedField],\n } as unknown as FlattenedField,\n ]\n\n const childFn = vi.fn(({ value }: { value: unknown }) => `${value}-from-child`)\n const fieldHooks: Record<string, ExportFieldHookEntry> = {\n meta: {\n type: 'beforeExport',\n fn: () => 'serialized',\n },\n meta_slug: {\n type: 'beforeExport',\n fn: childFn,\n },\n }\n\n const result = applyFieldHooks({\n type: 'beforeExport',\n data: { meta: { slug: 'raw' } },\n fieldHooks,\n fields,\n format: 'json',\n operation: 'export',\n req: mockReq,\n })\n\n expect(result.meta).toBe('serialized')\n expect(childFn).not.toHaveBeenCalled()\n })\n})\n"],"names":["describe","expect","it","vi","applyFieldHooks","mockReq","payload","logger","error","fn","fields","name","type","flattenedFields","fieldHooks","meta","value","obj","slug","meta_slug","result","data","format","operation","req","toEqual","items","Array","isArray","map","item","note","items_note","childFn","toBe","not","toHaveBeenCalled"],"mappings":"AAIA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,E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EAAED,OAAO,CAAC;YAAC;gBAAEM,MAAM;YAAiB;YAAG;gBAAEA,MAAM;YAAiB;SAAE;IACvF;IAEA7B,GAAG,6EAA6E;QAC9E,MAAMQ,SAA2B;YAC/B;gBACEC,MAAM;gBACNC,MAAM;gBACNC,iBAAiB;oBAAC;wBAAEF,MAAM;wBAAQC,MAAM;oBAAO;iBAAoB;YACrE;SACD;QAED,MAAMqB,UAAU9B,GAAGM,EAAE,CAAC,CAAC,EAAEO,KAAK,EAAsB,GAAK,GAAGA,MAAM,WAAW,CAAC;QAC9E,MAAMF,aAAmD;YACvDC,MAAM;gBACJH,MAAM;gBACNH,IAAI,IAAM;YACZ;YACAU,WAAW;gBACTP,MAAM;gBACNH,IAAIwB;YACN;QACF;QAEA,MAAMb,SAAShB,gBAAgB;YAC7BQ,MAAM;YACNS,MAAM;gBAAEN,MAAM;oBAAEG,MAAM;gBAAM;YAAE;YAC9BJ;YACAJ;YACAY,QAAQ;YACRC,WAAW;YACXC,KAAKnB;QACP;QAEAJ,OAAOmB,OAAOL,IAAI,EAAEmB,IAAI,CAAC;QACzBjC,OAAOgC,SAASE,GAAG,CAACC,gBAAgB;IACtC;AACF"}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { buildDisabledFieldRegex } from './buildDisabledFieldRegex.js';
|
|
3
|
-
describe('buildDisabledFieldRegex', ()=>{
|
|
4
|
-
describe('simple field paths', ()=>{
|
|
5
|
-
it('should match exact field name', ()=>{
|
|
6
|
-
const matcher = buildDisabledFieldRegex('title');
|
|
7
|
-
expect(matcher.test('title')).toBe(true);
|
|
8
|
-
});
|
|
9
|
-
it('should match field with array index', ()=>{
|
|
10
|
-
const matcher = buildDisabledFieldRegex('items');
|
|
11
|
-
expect(matcher.test('items_0')).toBe(true);
|
|
12
|
-
expect(matcher.test('items_1')).toBe(true);
|
|
13
|
-
});
|
|
14
|
-
it('should match nested fields under array items', ()=>{
|
|
15
|
-
const matcher = buildDisabledFieldRegex('items');
|
|
16
|
-
expect(matcher.test('items_0_title')).toBe(true);
|
|
17
|
-
});
|
|
18
|
-
it('should not match unrelated fields', ()=>{
|
|
19
|
-
const matcher = buildDisabledFieldRegex('title');
|
|
20
|
-
expect(matcher.test('otherField')).toBe(false);
|
|
21
|
-
expect(matcher.test('titleExtra')).toBe(false);
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
describe('block type slug handling', ()=>{
|
|
25
|
-
it('should match field path with block type slug', ()=>{
|
|
26
|
-
const matcher = buildDisabledFieldRegex('blocks.content');
|
|
27
|
-
// Standard cases
|
|
28
|
-
expect(matcher.test('blocks_content')).toBe(true);
|
|
29
|
-
expect(matcher.test('blocks_0_content')).toBe(true);
|
|
30
|
-
// With block type slug (hero, cta, etc.)
|
|
31
|
-
expect(matcher.test('blocks_0_hero_content')).toBe(true);
|
|
32
|
-
expect(matcher.test('blocks_1_cta_content')).toBe(true);
|
|
33
|
-
expect(matcher.test('blocks_hero_content')).toBe(true);
|
|
34
|
-
});
|
|
35
|
-
it('should match nested fields within blocks', ()=>{
|
|
36
|
-
const matcher = buildDisabledFieldRegex('blocks.content');
|
|
37
|
-
expect(matcher.test('blocks_0_hero_content_title')).toBe(true);
|
|
38
|
-
expect(matcher.test('blocks_0_content_richText')).toBe(true);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
describe('deeply nested paths', ()=>{
|
|
42
|
-
it('should match three-level nesting with indices and slugs', ()=>{
|
|
43
|
-
const matcher = buildDisabledFieldRegex('layout.sections.items');
|
|
44
|
-
expect(matcher.test('layout_sections_items')).toBe(true);
|
|
45
|
-
expect(matcher.test('layout_0_sections_items')).toBe(true);
|
|
46
|
-
expect(matcher.test('layout_0_sections_1_items')).toBe(true);
|
|
47
|
-
expect(matcher.test('layout_0_hero_sections_1_items')).toBe(true);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
describe('edge cases', ()=>{
|
|
51
|
-
it('should not match partial field names', ()=>{
|
|
52
|
-
const matcher = buildDisabledFieldRegex('block');
|
|
53
|
-
expect(matcher.test('blocks')).toBe(false);
|
|
54
|
-
expect(matcher.test('blockType')).toBe(false);
|
|
55
|
-
});
|
|
56
|
-
it('should handle field names with numbers', ()=>{
|
|
57
|
-
const matcher = buildDisabledFieldRegex('field1.field2');
|
|
58
|
-
expect(matcher.test('field1_field2')).toBe(true);
|
|
59
|
-
expect(matcher.test('field1_0_field2')).toBe(true);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
//# sourceMappingURL=buildDisabledFieldRegex.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/buildDisabledFieldRegex.spec.ts"],"sourcesContent":["import { describe, expect, it } from 'vitest'\n\nimport { buildDisabledFieldRegex } from './buildDisabledFieldRegex.js'\n\ndescribe('buildDisabledFieldRegex', () => {\n describe('simple field paths', () => {\n it('should match exact field name', () => {\n const matcher = buildDisabledFieldRegex('title')\n\n expect(matcher.test('title')).toBe(true)\n })\n\n it('should match field with array index', () => {\n const matcher = buildDisabledFieldRegex('items')\n\n expect(matcher.test('items_0')).toBe(true)\n expect(matcher.test('items_1')).toBe(true)\n })\n\n it('should match nested fields under array items', () => {\n const matcher = buildDisabledFieldRegex('items')\n\n expect(matcher.test('items_0_title')).toBe(true)\n })\n\n it('should not match unrelated fields', () => {\n const matcher = buildDisabledFieldRegex('title')\n\n expect(matcher.test('otherField')).toBe(false)\n expect(matcher.test('titleExtra')).toBe(false)\n })\n })\n\n describe('block type slug handling', () => {\n it('should match field path with block type slug', () => {\n const matcher = buildDisabledFieldRegex('blocks.content')\n\n // Standard cases\n expect(matcher.test('blocks_content')).toBe(true)\n expect(matcher.test('blocks_0_content')).toBe(true)\n\n // With block type slug (hero, cta, etc.)\n expect(matcher.test('blocks_0_hero_content')).toBe(true)\n expect(matcher.test('blocks_1_cta_content')).toBe(true)\n expect(matcher.test('blocks_hero_content')).toBe(true)\n })\n\n it('should match nested fields within blocks', () => {\n const matcher = buildDisabledFieldRegex('blocks.content')\n\n expect(matcher.test('blocks_0_hero_content_title')).toBe(true)\n expect(matcher.test('blocks_0_content_richText')).toBe(true)\n })\n })\n\n describe('deeply nested paths', () => {\n it('should match three-level nesting with indices and slugs', () => {\n const matcher = buildDisabledFieldRegex('layout.sections.items')\n\n expect(matcher.test('layout_sections_items')).toBe(true)\n expect(matcher.test('layout_0_sections_items')).toBe(true)\n expect(matcher.test('layout_0_sections_1_items')).toBe(true)\n expect(matcher.test('layout_0_hero_sections_1_items')).toBe(true)\n })\n })\n\n describe('edge cases', () => {\n it('should not match partial field names', () => {\n const matcher = buildDisabledFieldRegex('block')\n\n expect(matcher.test('blocks')).toBe(false)\n expect(matcher.test('blockType')).toBe(false)\n })\n\n it('should handle field names with numbers', () => {\n const matcher = buildDisabledFieldRegex('field1.field2')\n\n expect(matcher.test('field1_field2')).toBe(true)\n expect(matcher.test('field1_0_field2')).toBe(true)\n })\n })\n})\n"],"names":["describe","expect","it","buildDisabledFieldRegex","matcher","test","toBe"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SAASC,uBAAuB,QAAQ,+BAA8B;AAEtEH,SAAS,2BAA2B;IAClCA,SAAS,sBAAsB;QAC7BE,GAAG,iCAAiC;YAClC,MAAME,UAAUD,wBAAwB;YAExCF,OAAOG,QAAQC,IAAI,CAAC,UAAUC,IAAI,CAAC;QACrC;QAEAJ,GAAG,uCAAuC;YACxC,MAAME,UAAUD,wBAAwB;YAExCF,OAAOG,QAAQC,IAAI,CAAC,YAAYC,IAAI,CAAC;YACrCL,OAAOG,QAAQC,IAAI,CAAC,YAAYC,IAAI,CAAC;QACvC;QAEAJ,GAAG,gDAAgD;YACjD,MAAME,UAAUD,wBAAwB;YAExCF,OAAOG,QAAQC,IAAI,CAAC,kBAAkBC,IAAI,CAAC;QAC7C;QAEAJ,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3C,MAAME,UAAUD,wBAAwB;YAExCF,OAAOG,QAAQC,IAAI,CAAC,kBAAkBC,IAAI,CAAC;YAC3CL,OAAOG,QAAQC,IAAI,CAAC,oBAAoBC,IAAI,CAAC;QAC/C;IACF;AACF"}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { fieldToRegex } from './fieldToRegex.js';
|
|
3
|
-
describe('fieldToRegex', ()=>{
|
|
4
|
-
describe('simple field paths', ()=>{
|
|
5
|
-
it('should match exact field name', ()=>{
|
|
6
|
-
const regex = fieldToRegex('title');
|
|
7
|
-
expect(regex.test('title')).toBe(true);
|
|
8
|
-
});
|
|
9
|
-
it('should match field with array index', ()=>{
|
|
10
|
-
const regex = fieldToRegex('items');
|
|
11
|
-
expect(regex.test('items_0')).toBe(true);
|
|
12
|
-
expect(regex.test('items_1')).toBe(true);
|
|
13
|
-
expect(regex.test('items_99')).toBe(true);
|
|
14
|
-
});
|
|
15
|
-
it('should match nested fields under array items', ()=>{
|
|
16
|
-
const regex = fieldToRegex('items');
|
|
17
|
-
expect(regex.test('items_0_title')).toBe(true);
|
|
18
|
-
expect(regex.test('items_1_description')).toBe(true);
|
|
19
|
-
});
|
|
20
|
-
it('should not match unrelated fields', ()=>{
|
|
21
|
-
const regex = fieldToRegex('title');
|
|
22
|
-
expect(regex.test('otherField')).toBe(false);
|
|
23
|
-
expect(regex.test('titleExtra')).toBe(false);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
describe('dotted field paths', ()=>{
|
|
27
|
-
it('should match nested field path without indices', ()=>{
|
|
28
|
-
const regex = fieldToRegex('blocks.content');
|
|
29
|
-
expect(regex.test('blocks_content')).toBe(true);
|
|
30
|
-
});
|
|
31
|
-
it('should match nested field path with array index in middle', ()=>{
|
|
32
|
-
const regex = fieldToRegex('blocks.content');
|
|
33
|
-
expect(regex.test('blocks_0_content')).toBe(true);
|
|
34
|
-
expect(regex.test('blocks_1_content')).toBe(true);
|
|
35
|
-
expect(regex.test('blocks_42_content')).toBe(true);
|
|
36
|
-
});
|
|
37
|
-
it('should match deeply nested paths with multiple indices', ()=>{
|
|
38
|
-
const regex = fieldToRegex('blocks.content.items');
|
|
39
|
-
expect(regex.test('blocks_0_content_items')).toBe(true);
|
|
40
|
-
expect(regex.test('blocks_0_content_0_items')).toBe(true);
|
|
41
|
-
expect(regex.test('blocks_1_content_2_items')).toBe(true);
|
|
42
|
-
});
|
|
43
|
-
it('should match nested fields under the matched path', ()=>{
|
|
44
|
-
const regex = fieldToRegex('blocks.content');
|
|
45
|
-
expect(regex.test('blocks_0_content_title')).toBe(true);
|
|
46
|
-
expect(regex.test('blocks_0_content_richText')).toBe(true);
|
|
47
|
-
expect(regex.test('blocks_1_content_0_value')).toBe(true);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
describe('complex nested structures', ()=>{
|
|
51
|
-
it('should handle three-level nesting', ()=>{
|
|
52
|
-
const regex = fieldToRegex('layout.sections.items');
|
|
53
|
-
expect(regex.test('layout_sections_items')).toBe(true);
|
|
54
|
-
expect(regex.test('layout_0_sections_items')).toBe(true);
|
|
55
|
-
expect(regex.test('layout_0_sections_1_items')).toBe(true);
|
|
56
|
-
expect(regex.test('layout_0_sections_1_items_2')).toBe(true);
|
|
57
|
-
expect(regex.test('layout_0_sections_1_items_2_title')).toBe(true);
|
|
58
|
-
});
|
|
59
|
-
it('should not match partial field name matches', ()=>{
|
|
60
|
-
const regex = fieldToRegex('block');
|
|
61
|
-
expect(regex.test('blocks')).toBe(false);
|
|
62
|
-
expect(regex.test('blocks_0_content')).toBe(false);
|
|
63
|
-
expect(regex.test('blockType')).toBe(false);
|
|
64
|
-
});
|
|
65
|
-
it('should handle field names that look like array indices', ()=>{
|
|
66
|
-
const regex = fieldToRegex('data.row');
|
|
67
|
-
expect(regex.test('data_row')).toBe(true);
|
|
68
|
-
expect(regex.test('data_0_row')).toBe(true);
|
|
69
|
-
expect(regex.test('data_0_row_1')).toBe(true);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
describe('edge cases', ()=>{
|
|
73
|
-
it('should handle single character field names', ()=>{
|
|
74
|
-
const regex = fieldToRegex('a.b.c');
|
|
75
|
-
expect(regex.test('a_b_c')).toBe(true);
|
|
76
|
-
expect(regex.test('a_0_b_c')).toBe(true);
|
|
77
|
-
expect(regex.test('a_0_b_1_c')).toBe(true);
|
|
78
|
-
});
|
|
79
|
-
it('should handle field names with numbers', ()=>{
|
|
80
|
-
const regex = fieldToRegex('field1.field2');
|
|
81
|
-
expect(regex.test('field1_field2')).toBe(true);
|
|
82
|
-
expect(regex.test('field1_0_field2')).toBe(true);
|
|
83
|
-
});
|
|
84
|
-
it('should match field at end of key exactly', ()=>{
|
|
85
|
-
const regex = fieldToRegex('meta.title');
|
|
86
|
-
expect(regex.test('meta_title')).toBe(true);
|
|
87
|
-
expect(regex.test('meta_0_title')).toBe(true);
|
|
88
|
-
// Should not match if title is a prefix of another word
|
|
89
|
-
expect(regex.test('meta_titleExtra')).toBe(false);
|
|
90
|
-
});
|
|
91
|
-
it('should handle field names starting with underscore', ()=>{
|
|
92
|
-
const regex = fieldToRegex('_status');
|
|
93
|
-
expect(regex.test('_status')).toBe(true);
|
|
94
|
-
expect(regex.test('_status_0')).toBe(true);
|
|
95
|
-
expect(regex.test('_statusExtra')).toBe(false);
|
|
96
|
-
});
|
|
97
|
-
it('should handle field names containing underscores', ()=>{
|
|
98
|
-
const regex = fieldToRegex('my_field');
|
|
99
|
-
expect(regex.test('my_field')).toBe(true);
|
|
100
|
-
expect(regex.test('my_field_0')).toBe(true);
|
|
101
|
-
expect(regex.test('my_fieldExtra')).toBe(false);
|
|
102
|
-
});
|
|
103
|
-
it('should handle nested paths with underscore fields', ()=>{
|
|
104
|
-
const regex = fieldToRegex('group._status');
|
|
105
|
-
expect(regex.test('group__status')).toBe(true);
|
|
106
|
-
expect(regex.test('group_0__status')).toBe(true);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
describe('date fields with timezone companions', ()=>{
|
|
110
|
-
it('should match date field and its _tz companion', ()=>{
|
|
111
|
-
const regex = fieldToRegex('publishedDate');
|
|
112
|
-
expect(regex.test('publishedDate')).toBe(true);
|
|
113
|
-
expect(regex.test('publishedDate_tz')).toBe(true);
|
|
114
|
-
});
|
|
115
|
-
it('should match nested date field and its _tz companion', ()=>{
|
|
116
|
-
const regex = fieldToRegex('meta.publishedDate');
|
|
117
|
-
expect(regex.test('meta_publishedDate')).toBe(true);
|
|
118
|
-
expect(regex.test('meta_publishedDate_tz')).toBe(true);
|
|
119
|
-
expect(regex.test('meta_0_publishedDate')).toBe(true);
|
|
120
|
-
expect(regex.test('meta_0_publishedDate_tz')).toBe(true);
|
|
121
|
-
});
|
|
122
|
-
it('should match date fields in arrays with _tz companions', ()=>{
|
|
123
|
-
const regex = fieldToRegex('events.startDate');
|
|
124
|
-
expect(regex.test('events_0_startDate')).toBe(true);
|
|
125
|
-
expect(regex.test('events_0_startDate_tz')).toBe(true);
|
|
126
|
-
expect(regex.test('events_1_startDate')).toBe(true);
|
|
127
|
-
expect(regex.test('events_1_startDate_tz')).toBe(true);
|
|
128
|
-
});
|
|
129
|
-
it('should match deeply nested date fields with _tz companions', ()=>{
|
|
130
|
-
const regex = fieldToRegex('blocks.content.scheduledAt');
|
|
131
|
-
expect(regex.test('blocks_0_content_scheduledAt')).toBe(true);
|
|
132
|
-
expect(regex.test('blocks_0_content_scheduledAt_tz')).toBe(true);
|
|
133
|
-
expect(regex.test('blocks_0_content_0_scheduledAt')).toBe(true);
|
|
134
|
-
expect(regex.test('blocks_0_content_0_scheduledAt_tz')).toBe(true);
|
|
135
|
-
});
|
|
136
|
-
it('should not match _tz suffix on unrelated fields', ()=>{
|
|
137
|
-
const regex = fieldToRegex('title');
|
|
138
|
-
expect(regex.test('title')).toBe(true);
|
|
139
|
-
expect(regex.test('title_tz')).toBe(true); // _tz is treated as a nested field suffix
|
|
140
|
-
expect(regex.test('publishedDate_tz')).toBe(false);
|
|
141
|
-
});
|
|
142
|
-
it('should handle date fields with underscores in name', ()=>{
|
|
143
|
-
const regex = fieldToRegex('start_date');
|
|
144
|
-
expect(regex.test('start_date')).toBe(true);
|
|
145
|
-
expect(regex.test('start_date_tz')).toBe(true);
|
|
146
|
-
expect(regex.test('start_date_0')).toBe(true);
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
//# sourceMappingURL=fieldToRegex.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/fieldToRegex.spec.ts"],"sourcesContent":["import { describe, expect, it } from 'vitest'\n\nimport { fieldToRegex } from './fieldToRegex.js'\n\ndescribe('fieldToRegex', () => {\n describe('simple field paths', () => {\n it('should match exact field name', () => {\n const regex = fieldToRegex('title')\n\n expect(regex.test('title')).toBe(true)\n })\n\n it('should match field with array index', () => {\n const regex = fieldToRegex('items')\n\n expect(regex.test('items_0')).toBe(true)\n expect(regex.test('items_1')).toBe(true)\n expect(regex.test('items_99')).toBe(true)\n })\n\n it('should match nested fields under array items', () => {\n const regex = fieldToRegex('items')\n\n expect(regex.test('items_0_title')).toBe(true)\n expect(regex.test('items_1_description')).toBe(true)\n })\n\n it('should not match unrelated fields', () => {\n const regex = fieldToRegex('title')\n\n expect(regex.test('otherField')).toBe(false)\n expect(regex.test('titleExtra')).toBe(false)\n })\n })\n\n describe('dotted field paths', () => {\n it('should match nested field path without indices', () => {\n const regex = fieldToRegex('blocks.content')\n\n expect(regex.test('blocks_content')).toBe(true)\n })\n\n it('should match nested field path with array index in middle', () => {\n const regex = fieldToRegex('blocks.content')\n\n expect(regex.test('blocks_0_content')).toBe(true)\n expect(regex.test('blocks_1_content')).toBe(true)\n expect(regex.test('blocks_42_content')).toBe(true)\n })\n\n it('should match deeply nested paths with multiple indices', () => {\n const regex = fieldToRegex('blocks.content.items')\n\n expect(regex.test('blocks_0_content_items')).toBe(true)\n expect(regex.test('blocks_0_content_0_items')).toBe(true)\n expect(regex.test('blocks_1_content_2_items')).toBe(true)\n })\n\n it('should match nested fields under the matched path', () => {\n const regex = fieldToRegex('blocks.content')\n\n expect(regex.test('blocks_0_content_title')).toBe(true)\n expect(regex.test('blocks_0_content_richText')).toBe(true)\n expect(regex.test('blocks_1_content_0_value')).toBe(true)\n })\n })\n\n describe('complex nested structures', () => {\n it('should handle three-level nesting', () => {\n const regex = fieldToRegex('layout.sections.items')\n\n expect(regex.test('layout_sections_items')).toBe(true)\n expect(regex.test('layout_0_sections_items')).toBe(true)\n expect(regex.test('layout_0_sections_1_items')).toBe(true)\n expect(regex.test('layout_0_sections_1_items_2')).toBe(true)\n expect(regex.test('layout_0_sections_1_items_2_title')).toBe(true)\n })\n\n it('should not match partial field name matches', () => {\n const regex = fieldToRegex('block')\n\n expect(regex.test('blocks')).toBe(false)\n expect(regex.test('blocks_0_content')).toBe(false)\n expect(regex.test('blockType')).toBe(false)\n })\n\n it('should handle field names that look like array indices', () => {\n const regex = fieldToRegex('data.row')\n\n expect(regex.test('data_row')).toBe(true)\n expect(regex.test('data_0_row')).toBe(true)\n expect(regex.test('data_0_row_1')).toBe(true)\n })\n })\n\n describe('edge cases', () => {\n it('should handle single character field names', () => {\n const regex = fieldToRegex('a.b.c')\n\n expect(regex.test('a_b_c')).toBe(true)\n expect(regex.test('a_0_b_c')).toBe(true)\n expect(regex.test('a_0_b_1_c')).toBe(true)\n })\n\n it('should handle field names with numbers', () => {\n const regex = fieldToRegex('field1.field2')\n\n expect(regex.test('field1_field2')).toBe(true)\n expect(regex.test('field1_0_field2')).toBe(true)\n })\n\n it('should match field at end of key exactly', () => {\n const regex = fieldToRegex('meta.title')\n\n expect(regex.test('meta_title')).toBe(true)\n expect(regex.test('meta_0_title')).toBe(true)\n // Should not match if title is a prefix of another word\n expect(regex.test('meta_titleExtra')).toBe(false)\n })\n\n it('should handle field names starting with underscore', () => {\n const regex = fieldToRegex('_status')\n\n expect(regex.test('_status')).toBe(true)\n expect(regex.test('_status_0')).toBe(true)\n expect(regex.test('_statusExtra')).toBe(false)\n })\n\n it('should handle field names containing underscores', () => {\n const regex = fieldToRegex('my_field')\n\n expect(regex.test('my_field')).toBe(true)\n expect(regex.test('my_field_0')).toBe(true)\n expect(regex.test('my_fieldExtra')).toBe(false)\n })\n\n it('should handle nested paths with underscore fields', () => {\n const regex = fieldToRegex('group._status')\n\n expect(regex.test('group__status')).toBe(true)\n expect(regex.test('group_0__status')).toBe(true)\n })\n })\n\n describe('date fields with timezone companions', () => {\n it('should match date field and its _tz companion', () => {\n const regex = fieldToRegex('publishedDate')\n\n expect(regex.test('publishedDate')).toBe(true)\n expect(regex.test('publishedDate_tz')).toBe(true)\n })\n\n it('should match nested date field and its _tz companion', () => {\n const regex = fieldToRegex('meta.publishedDate')\n\n expect(regex.test('meta_publishedDate')).toBe(true)\n expect(regex.test('meta_publishedDate_tz')).toBe(true)\n expect(regex.test('meta_0_publishedDate')).toBe(true)\n expect(regex.test('meta_0_publishedDate_tz')).toBe(true)\n })\n\n it('should match date fields in arrays with _tz companions', () => {\n const regex = fieldToRegex('events.startDate')\n\n expect(regex.test('events_0_startDate')).toBe(true)\n expect(regex.test('events_0_startDate_tz')).toBe(true)\n expect(regex.test('events_1_startDate')).toBe(true)\n expect(regex.test('events_1_startDate_tz')).toBe(true)\n })\n\n it('should match deeply nested date fields with _tz companions', () => {\n const regex = fieldToRegex('blocks.content.scheduledAt')\n\n expect(regex.test('blocks_0_content_scheduledAt')).toBe(true)\n expect(regex.test('blocks_0_content_scheduledAt_tz')).toBe(true)\n expect(regex.test('blocks_0_content_0_scheduledAt')).toBe(true)\n expect(regex.test('blocks_0_content_0_scheduledAt_tz')).toBe(true)\n })\n\n it('should not match _tz suffix on unrelated fields', () => {\n const regex = fieldToRegex('title')\n\n expect(regex.test('title')).toBe(true)\n expect(regex.test('title_tz')).toBe(true) // _tz is treated as a nested field suffix\n expect(regex.test('publishedDate_tz')).toBe(false)\n })\n\n it('should handle date fields with underscores in name', () => {\n const regex = fieldToRegex('start_date')\n\n expect(regex.test('start_date')).toBe(true)\n expect(regex.test('start_date_tz')).toBe(true)\n expect(regex.test('start_date_0')).toBe(true)\n })\n })\n})\n"],"names":["describe","expect","it","fieldToRegex","regex","test","toBe"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SAASC,YAAY,QAAQ,oBAAmB;AAEhDH,SAAS,gBAAgB;IACvBA,SAAS,sBAAsB;QAC7BE,GAAG,iCAAiC;YAClC,MAAME,QAAQD,aAAa;YAE3BF,OAAOG,MAAMC,IAAI,CAAC,UAAUC,IAAI,CAAC;QACnC;QAEAJ,GAAG,uCAAuC;YACxC,MAAME,QAAQD,aAAa;YAE3BF,OAAOG,MAAMC,IAAI,CAAC,YAAYC,IAAI,CAAC;YACnCL,OAAOG,MAAMC,IAAI,CAAC,YAAYC,IAAI,CAAC;YACnCL,OAAOG,MAAMC,IAAI,CAAC,aAAaC,IAAI,CAAC;QACtC;QAEAJ,GAAG,gDAAgD;YACjD,MAAME,QAAQD,aAAa;YAE3BF,OAAOG,MAAMC,IAAI,CAAC,kBAAkBC,IAAI,CAAC;YACzCL,OAAOG,MAAMC,IAAI,CAAC,wBAAwBC,IAAI,CAAC;QACjD;QAEAJ,GAAG,qCAAqC;YACtC,MAAME,QAAQD,aAAa;YAE3BF,OAAOG,MAAMC,IAAI,CAAC,eAAeC,IAAI,CAAC;YACtCL,OAAOG,MAAMC,IAAI,CAAC,eAAeC,IAAI,CAAC;QACxC;IACF;IAEAN,SAAS,sBAAsB;QAC7BE,GAAG,kDAAkD;YACnD,MAAME,QAAQD,aAAa;YAE3BF,OAAOG,MAAMC,IAAI,CAAC,mBAAmBC,IAAI,CAAC;QAC5C;QAEAJ,GAAG,6DAA6D;YAC9D,MAAME,QAAQD,aAAa;YAE3BF,OAAOG,MAAMC,IAAI,CAAC,qBAAqBC,IAAI,CAAC;YAC5CL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AAMC,IAAI,CAAC,UAAUC,IAAI,CAAC;YACjCL,OAAOG,MAAMC,IAAI,CAAC,aAAaC,IAAI,CAAC,OAAM,0CAA0C;YACpFL,OAAOG,MAAMC,IAAI,CAAC,qBAAqBC,IAAI,CAAC;QAC9C;QAEAJ,GAAG,sDAAsD;YACvD,MAAME,QAAQD,aAAa;YAE3BF,OAAOG,MAAMC,IAAI,CAAC,eAAeC,IAAI,CAAC;YACtCL,OAAOG,MAAMC,IAAI,CAAC,kBAAkBC,IAAI,CAAC;YACzCL,OAAOG,MAAMC,IAAI,CAAC,iBAAiBC,IAAI,CAAC;QAC1C;IACF;AACF"}
|
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { filterToSelectedFields } from './getSchemaColumns.js';
|
|
3
|
-
describe('filterToSelectedFields', ()=>{
|
|
4
|
-
describe('fields with their own column', ()=>{
|
|
5
|
-
it('should include only the exact column for a date with timezones field', ()=>{
|
|
6
|
-
const columns = [
|
|
7
|
-
'id',
|
|
8
|
-
'title',
|
|
9
|
-
'dateWithTimezone',
|
|
10
|
-
'dateWithTimezone_tz',
|
|
11
|
-
'createdAt'
|
|
12
|
-
];
|
|
13
|
-
const result = filterToSelectedFields(columns, [
|
|
14
|
-
'title'
|
|
15
|
-
]);
|
|
16
|
-
expect(result).toEqual([
|
|
17
|
-
'title'
|
|
18
|
-
]);
|
|
19
|
-
});
|
|
20
|
-
it('should not include timezone companion when only date field is selected', ()=>{
|
|
21
|
-
const columns = [
|
|
22
|
-
'id',
|
|
23
|
-
'dateWithTimezone',
|
|
24
|
-
'dateWithTimezone_tz',
|
|
25
|
-
'createdAt'
|
|
26
|
-
];
|
|
27
|
-
const result = filterToSelectedFields(columns, [
|
|
28
|
-
'dateWithTimezone'
|
|
29
|
-
]);
|
|
30
|
-
expect(result).toEqual([
|
|
31
|
-
'dateWithTimezone'
|
|
32
|
-
]);
|
|
33
|
-
expect(result).not.toContain('dateWithTimezone_tz');
|
|
34
|
-
});
|
|
35
|
-
it('should include both date and timezone companion when both are explicitly selected', ()=>{
|
|
36
|
-
const columns = [
|
|
37
|
-
'id',
|
|
38
|
-
'dateWithTimezone',
|
|
39
|
-
'dateWithTimezone_tz',
|
|
40
|
-
'createdAt'
|
|
41
|
-
];
|
|
42
|
-
const result = filterToSelectedFields(columns, [
|
|
43
|
-
'dateWithTimezone',
|
|
44
|
-
'dateWithTimezone_tz'
|
|
45
|
-
]);
|
|
46
|
-
expect(result).toEqual([
|
|
47
|
-
'dateWithTimezone',
|
|
48
|
-
'dateWithTimezone_tz'
|
|
49
|
-
]);
|
|
50
|
-
});
|
|
51
|
-
it('should preserve user-specified ordering', ()=>{
|
|
52
|
-
const columns = [
|
|
53
|
-
'id',
|
|
54
|
-
'title',
|
|
55
|
-
'email',
|
|
56
|
-
'createdAt'
|
|
57
|
-
];
|
|
58
|
-
const result = filterToSelectedFields(columns, [
|
|
59
|
-
'email',
|
|
60
|
-
'title',
|
|
61
|
-
'id'
|
|
62
|
-
]);
|
|
63
|
-
expect(result).toEqual([
|
|
64
|
-
'email',
|
|
65
|
-
'title',
|
|
66
|
-
'id'
|
|
67
|
-
]);
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
describe('fields without their own column (groups, arrays, blocks)', ()=>{
|
|
71
|
-
it('should expand a group to include its nested fields', ()=>{
|
|
72
|
-
const columns = [
|
|
73
|
-
'id',
|
|
74
|
-
'group_name',
|
|
75
|
-
'group_age',
|
|
76
|
-
'createdAt'
|
|
77
|
-
];
|
|
78
|
-
const result = filterToSelectedFields(columns, [
|
|
79
|
-
'group'
|
|
80
|
-
]);
|
|
81
|
-
expect(result).toEqual([
|
|
82
|
-
'group_name',
|
|
83
|
-
'group_age'
|
|
84
|
-
]);
|
|
85
|
-
});
|
|
86
|
-
it('should expand an array to include its nested fields', ()=>{
|
|
87
|
-
const columns = [
|
|
88
|
-
'id',
|
|
89
|
-
'items_0_title',
|
|
90
|
-
'items_0_value',
|
|
91
|
-
'createdAt'
|
|
92
|
-
];
|
|
93
|
-
const result = filterToSelectedFields(columns, [
|
|
94
|
-
'items'
|
|
95
|
-
]);
|
|
96
|
-
expect(result).toEqual([
|
|
97
|
-
'items_0_title',
|
|
98
|
-
'items_0_value'
|
|
99
|
-
]);
|
|
100
|
-
});
|
|
101
|
-
it('should expand blocks to include their nested fields', ()=>{
|
|
102
|
-
const columns = [
|
|
103
|
-
'id',
|
|
104
|
-
'blocks_0_hero_blockType',
|
|
105
|
-
'blocks_0_hero_title',
|
|
106
|
-
'createdAt'
|
|
107
|
-
];
|
|
108
|
-
const result = filterToSelectedFields(columns, [
|
|
109
|
-
'blocks'
|
|
110
|
-
]);
|
|
111
|
-
expect(result).toEqual([
|
|
112
|
-
'blocks_0_hero_blockType',
|
|
113
|
-
'blocks_0_hero_title'
|
|
114
|
-
]);
|
|
115
|
-
});
|
|
116
|
-
it('should expand a hasMany select to include indexed columns', ()=>{
|
|
117
|
-
const columns = [
|
|
118
|
-
'id',
|
|
119
|
-
'colors_0',
|
|
120
|
-
'createdAt'
|
|
121
|
-
];
|
|
122
|
-
const result = filterToSelectedFields(columns, [
|
|
123
|
-
'colors'
|
|
124
|
-
]);
|
|
125
|
-
expect(result).toEqual([
|
|
126
|
-
'colors_0'
|
|
127
|
-
]);
|
|
128
|
-
});
|
|
129
|
-
it('should expand a polymorphic relationship to include relationTo and id columns', ()=>{
|
|
130
|
-
const columns = [
|
|
131
|
-
'id',
|
|
132
|
-
'relField_relationTo',
|
|
133
|
-
'relField_id',
|
|
134
|
-
'createdAt'
|
|
135
|
-
];
|
|
136
|
-
const result = filterToSelectedFields(columns, [
|
|
137
|
-
'relField'
|
|
138
|
-
]);
|
|
139
|
-
expect(result).toEqual([
|
|
140
|
-
'relField_relationTo',
|
|
141
|
-
'relField_id'
|
|
142
|
-
]);
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
describe('nested field selections with dot notation', ()=>{
|
|
146
|
-
it('should resolve a specific nested field within a group', ()=>{
|
|
147
|
-
const columns = [
|
|
148
|
-
'id',
|
|
149
|
-
'group_name',
|
|
150
|
-
'group_age',
|
|
151
|
-
'createdAt'
|
|
152
|
-
];
|
|
153
|
-
const result = filterToSelectedFields(columns, [
|
|
154
|
-
'group.name'
|
|
155
|
-
]);
|
|
156
|
-
expect(result).toEqual([
|
|
157
|
-
'group_name'
|
|
158
|
-
]);
|
|
159
|
-
expect(result).not.toContain('group_age');
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
describe('mixed selections', ()=>{
|
|
163
|
-
it('should handle groups and date fields together without sibling leakage', ()=>{
|
|
164
|
-
const columns = [
|
|
165
|
-
'id',
|
|
166
|
-
'title',
|
|
167
|
-
'group_name',
|
|
168
|
-
'group_age',
|
|
169
|
-
'dateWithTimezone',
|
|
170
|
-
'dateWithTimezone_tz',
|
|
171
|
-
'createdAt'
|
|
172
|
-
];
|
|
173
|
-
const result = filterToSelectedFields(columns, [
|
|
174
|
-
'id',
|
|
175
|
-
'group',
|
|
176
|
-
'dateWithTimezone'
|
|
177
|
-
]);
|
|
178
|
-
expect(result).toEqual([
|
|
179
|
-
'id',
|
|
180
|
-
'group_name',
|
|
181
|
-
'group_age',
|
|
182
|
-
'dateWithTimezone'
|
|
183
|
-
]);
|
|
184
|
-
expect(result).not.toContain('dateWithTimezone_tz');
|
|
185
|
-
});
|
|
186
|
-
it('should not produce duplicates when a group and its nested field are both selected', ()=>{
|
|
187
|
-
const columns = [
|
|
188
|
-
'id',
|
|
189
|
-
'group_name',
|
|
190
|
-
'group_age'
|
|
191
|
-
];
|
|
192
|
-
const result = filterToSelectedFields(columns, [
|
|
193
|
-
'group',
|
|
194
|
-
'group.name'
|
|
195
|
-
]);
|
|
196
|
-
const uniqueResult = [
|
|
197
|
-
...new Set(result)
|
|
198
|
-
];
|
|
199
|
-
expect(result).toEqual(uniqueResult);
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
//# sourceMappingURL=filterToSelectedFields.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/filterToSelectedFields.spec.ts"],"sourcesContent":["import { describe, expect, it } from 'vitest'\n\nimport { filterToSelectedFields } from './getSchemaColumns.js'\n\ndescribe('filterToSelectedFields', () => {\n describe('fields with their own column', () => {\n it('should include only the exact column for a date with timezones field', () => {\n const columns = ['id', 'title', 'dateWithTimezone', 'dateWithTimezone_tz', 'createdAt']\n\n const result = filterToSelectedFields(columns, ['title'])\n\n expect(result).toEqual(['title'])\n })\n\n it('should not include timezone companion when only date field is selected', () => {\n const columns = ['id', 'dateWithTimezone', 'dateWithTimezone_tz', 'createdAt']\n\n const result = filterToSelectedFields(columns, ['dateWithTimezone'])\n\n expect(result).toEqual(['dateWithTimezone'])\n expect(result).not.toContain('dateWithTimezone_tz')\n })\n\n it('should include both date and timezone companion when both are explicitly selected', () => {\n const columns = ['id', 'dateWithTimezone', 'dateWithTimezone_tz', 'createdAt']\n\n const result = filterToSelectedFields(columns, ['dateWithTimezone', 'dateWithTimezone_tz'])\n\n expect(result).toEqual(['dateWithTimezone', 'dateWithTimezone_tz'])\n })\n\n it('should preserve user-specified ordering', () => {\n const columns = ['id', 'title', 'email', 'createdAt']\n\n const result = filterToSelectedFields(columns, ['email', 'title', 'id'])\n\n expect(result).toEqual(['email', 'title', 'id'])\n })\n })\n\n describe('fields without their own column (groups, arrays, blocks)', () => {\n it('should expand a group to include its nested fields', () => {\n const columns = ['id', 'group_name', 'group_age', 'createdAt']\n\n const result = filterToSelectedFields(columns, ['group'])\n\n expect(result).toEqual(['group_name', 'group_age'])\n })\n\n it('should expand an array to include its nested fields', () => {\n const columns = ['id', 'items_0_title', 'items_0_value', 'createdAt']\n\n const result = filterToSelectedFields(columns, ['items'])\n\n expect(result).toEqual(['items_0_title', 'items_0_value'])\n })\n\n it('should expand blocks to include their nested fields', () => {\n const columns = ['id', 'blocks_0_hero_blockType', 'blocks_0_hero_title', 'createdAt']\n\n const result = filterToSelectedFields(columns, ['blocks'])\n\n expect(result).toEqual(['blocks_0_hero_blockType', 'blocks_0_hero_title'])\n })\n\n it('should expand a hasMany select to include indexed columns', () => {\n const columns = ['id', 'colors_0', 'createdAt']\n\n const result = filterToSelectedFields(columns, ['colors'])\n\n expect(result).toEqual(['colors_0'])\n })\n\n it('should expand a polymorphic relationship to include relationTo and id columns', () => {\n const columns = ['id', 'relField_relationTo', 'relField_id', 'createdAt']\n\n const result = filterToSelectedFields(columns, ['relField'])\n\n expect(result).toEqual(['relField_relationTo', 'relField_id'])\n })\n })\n\n describe('nested field selections with dot notation', () => {\n it('should resolve a specific nested field within a group', () => {\n const columns = ['id', 'group_name', 'group_age', 'createdAt']\n\n const result = filterToSelectedFields(columns, ['group.name'])\n\n expect(result).toEqual(['group_name'])\n expect(result).not.toContain('group_age')\n })\n })\n\n describe('mixed selections', () => {\n it('should handle groups and date fields together without sibling leakage', () => {\n const columns = [\n 'id',\n 'title',\n 'group_name',\n 'group_age',\n 'dateWithTimezone',\n 'dateWithTimezone_tz',\n 'createdAt',\n ]\n\n const result = filterToSelectedFields(columns, ['id', 'group', 'dateWithTimezone'])\n\n expect(result).toEqual(['id', 'group_name', 'group_age', 'dateWithTimezone'])\n expect(result).not.toContain('dateWithTimezone_tz')\n })\n\n it('should not produce duplicates when a group and its nested field are both selected', () => {\n const columns = ['id', 'group_name', 'group_age']\n\n const result = filterToSelectedFields(columns, ['group', 'group.name'])\n\n const uniqueResult = [...new Set(result)]\n\n expect(result).toEqual(uniqueResult)\n })\n })\n})\n"],"names":["describe","expect","it","filterToSelectedFields","columns","result","toEqual","not","toContain","uniqueResult","Set"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SAASC,sBAAsB,QAAQ,wBAAuB;AAE9DH,SAAS,0BAA0B;IACjCA,SAAS,gCAAgC;QACvCE,GAAG,wEAAwE;YACzE,MAAME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AIC,IAAIL;aAAQ;YAEzCJ,OAAOI,QAAQC,OAAO,CAACG;QACzB;IACF;AACF"}
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
-
import { flattenObject } from './flattenObject.js';
|
|
3
|
-
const mockReq = {
|
|
4
|
-
payload: {
|
|
5
|
-
logger: {
|
|
6
|
-
error: vi.fn()
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
describe('flattenObject parent + child traversal', ()=>{
|
|
11
|
-
it('should run a parent group hook and still apply child field hooks against the transformed value', ()=>{
|
|
12
|
-
const exportFieldHooks = {
|
|
13
|
-
meta: {
|
|
14
|
-
type: 'beforeExport',
|
|
15
|
-
fn: ({ value })=>{
|
|
16
|
-
const obj = value ?? {};
|
|
17
|
-
return {
|
|
18
|
-
...obj,
|
|
19
|
-
slug: `${obj.slug ?? ''}-from-parent`
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
meta_slug: {
|
|
24
|
-
type: 'beforeExport',
|
|
25
|
-
fn: ({ value })=>`${value}-from-child`
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
const row = flattenObject({
|
|
29
|
-
data: {
|
|
30
|
-
meta: {
|
|
31
|
-
slug: 'raw'
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
exportFieldHooks,
|
|
35
|
-
format: 'csv',
|
|
36
|
-
req: mockReq
|
|
37
|
-
});
|
|
38
|
-
expect(row.meta_slug).toBe('raw-from-parent-from-child');
|
|
39
|
-
});
|
|
40
|
-
it('should still recurse into children when the parent group hook returns undefined', ()=>{
|
|
41
|
-
const childCalls = [];
|
|
42
|
-
const exportFieldHooks = {
|
|
43
|
-
meta: {
|
|
44
|
-
type: 'beforeExport',
|
|
45
|
-
fn: ()=>undefined
|
|
46
|
-
},
|
|
47
|
-
meta_slug: {
|
|
48
|
-
type: 'beforeExport',
|
|
49
|
-
fn: ({ value })=>{
|
|
50
|
-
childCalls.push(value);
|
|
51
|
-
return `${value}-from-child`;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
const row = flattenObject({
|
|
56
|
-
data: {
|
|
57
|
-
meta: {
|
|
58
|
-
slug: 'raw'
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
exportFieldHooks,
|
|
62
|
-
format: 'csv',
|
|
63
|
-
req: mockReq
|
|
64
|
-
});
|
|
65
|
-
expect(childCalls).toEqual([
|
|
66
|
-
'raw'
|
|
67
|
-
]);
|
|
68
|
-
expect(row.meta_slug).toBe('raw-from-child');
|
|
69
|
-
});
|
|
70
|
-
it('should not recurse into children when the parent hook returns a primitive', ()=>{
|
|
71
|
-
const childFn = vi.fn(({ value })=>`${value}-from-child`);
|
|
72
|
-
const exportFieldHooks = {
|
|
73
|
-
meta: {
|
|
74
|
-
type: 'beforeExport',
|
|
75
|
-
fn: ()=>'serialized'
|
|
76
|
-
},
|
|
77
|
-
meta_slug: {
|
|
78
|
-
type: 'beforeExport',
|
|
79
|
-
fn: childFn
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
const row = flattenObject({
|
|
83
|
-
data: {
|
|
84
|
-
meta: {
|
|
85
|
-
slug: 'raw'
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
exportFieldHooks,
|
|
89
|
-
format: 'csv',
|
|
90
|
-
req: mockReq
|
|
91
|
-
});
|
|
92
|
-
expect(row.meta).toBe('serialized');
|
|
93
|
-
expect(row.meta_slug).toBeUndefined();
|
|
94
|
-
expect(childFn).not.toHaveBeenCalled();
|
|
95
|
-
});
|
|
96
|
-
it('should fall back to default array flattening when an undefined-returning hook did not write any keys, even if a sibling key with a matching prefix exists', ()=>{
|
|
97
|
-
const exportFieldHooks = {
|
|
98
|
-
tag: {
|
|
99
|
-
type: 'beforeExport',
|
|
100
|
-
fn: ()=>undefined
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
const row = flattenObject({
|
|
104
|
-
data: {
|
|
105
|
-
tag_meta: 'sibling-set-first',
|
|
106
|
-
tag: [
|
|
107
|
-
'a',
|
|
108
|
-
'b'
|
|
109
|
-
]
|
|
110
|
-
},
|
|
111
|
-
exportFieldHooks,
|
|
112
|
-
format: 'csv',
|
|
113
|
-
req: mockReq
|
|
114
|
-
});
|
|
115
|
-
expect(row.tag_meta).toBe('sibling-set-first');
|
|
116
|
-
expect(row.tag_0).toBe('a');
|
|
117
|
-
expect(row.tag_1).toBe('b');
|
|
118
|
-
});
|
|
119
|
-
it('should run a parent array hook then child hooks for each item', ()=>{
|
|
120
|
-
const exportFieldHooks = {
|
|
121
|
-
items: {
|
|
122
|
-
type: 'beforeExport',
|
|
123
|
-
fn: ({ value })=>{
|
|
124
|
-
if (!Array.isArray(value)) {
|
|
125
|
-
return value;
|
|
126
|
-
}
|
|
127
|
-
return value.map((item)=>({
|
|
128
|
-
...item,
|
|
129
|
-
note: `${item.note ?? ''}-parent`
|
|
130
|
-
}));
|
|
131
|
-
}
|
|
132
|
-
},
|
|
133
|
-
items_note: {
|
|
134
|
-
type: 'beforeExport',
|
|
135
|
-
fn: ({ value })=>`${value}-child`
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
const row = flattenObject({
|
|
139
|
-
data: {
|
|
140
|
-
items: [
|
|
141
|
-
{
|
|
142
|
-
note: 'a'
|
|
143
|
-
},
|
|
144
|
-
{
|
|
145
|
-
note: 'b'
|
|
146
|
-
}
|
|
147
|
-
]
|
|
148
|
-
},
|
|
149
|
-
exportFieldHooks,
|
|
150
|
-
format: 'csv',
|
|
151
|
-
req: mockReq
|
|
152
|
-
});
|
|
153
|
-
expect(row.items_0_note).toBe('a-parent-child');
|
|
154
|
-
expect(row.items_1_note).toBe('b-parent-child');
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
//# sourceMappingURL=flattenObject.spec.js.map
|