@payloadcms/plugin-import-export 3.84.1 → 3.85.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 (90) hide show
  1. package/dist/export/batchProcessor.d.ts +9 -1
  2. package/dist/export/batchProcessor.d.ts.map +1 -1
  3. package/dist/export/batchProcessor.js +57 -15
  4. package/dist/export/batchProcessor.js.map +1 -1
  5. package/dist/export/createExport.d.ts.map +1 -1
  6. package/dist/export/createExport.js +98 -20
  7. package/dist/export/createExport.js.map +1 -1
  8. package/dist/export/handlePreview.d.ts.map +1 -1
  9. package/dist/export/handlePreview.js +38 -13
  10. package/dist/export/handlePreview.js.map +1 -1
  11. package/dist/exports/types.d.ts +1 -1
  12. package/dist/exports/types.d.ts.map +1 -1
  13. package/dist/exports/types.js.map +1 -1
  14. package/dist/import/batchProcessor.d.ts +14 -2
  15. package/dist/import/batchProcessor.d.ts.map +1 -1
  16. package/dist/import/batchProcessor.js +49 -27
  17. package/dist/import/batchProcessor.js.map +1 -1
  18. package/dist/import/createImport.d.ts +1 -10
  19. package/dist/import/createImport.d.ts.map +1 -1
  20. package/dist/import/createImport.js +33 -52
  21. package/dist/import/createImport.js.map +1 -1
  22. package/dist/import/handlePreview.d.ts.map +1 -1
  23. package/dist/import/handlePreview.js +32 -6
  24. package/dist/import/handlePreview.js.map +1 -1
  25. package/dist/index.d.ts +58 -3
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +18 -1
  28. package/dist/index.js.map +1 -1
  29. package/dist/types.d.ts +218 -39
  30. package/dist/types.d.ts.map +1 -1
  31. package/dist/types.js.map +1 -1
  32. package/dist/utilities/applyFieldHooks.d.ts +23 -0
  33. package/dist/utilities/applyFieldHooks.d.ts.map +1 -0
  34. package/dist/utilities/applyFieldHooks.js +118 -0
  35. package/dist/utilities/applyFieldHooks.js.map +1 -0
  36. package/dist/utilities/applyFieldHooks.spec.js +205 -0
  37. package/dist/utilities/applyFieldHooks.spec.js.map +1 -0
  38. package/dist/utilities/collectDisabledFieldPaths.d.ts.map +1 -1
  39. package/dist/utilities/collectDisabledFieldPaths.js +1 -1
  40. package/dist/utilities/collectDisabledFieldPaths.js.map +1 -1
  41. package/dist/utilities/flattenObject.d.ts +8 -6
  42. package/dist/utilities/flattenObject.d.ts.map +1 -1
  43. package/dist/utilities/flattenObject.js +95 -75
  44. package/dist/utilities/flattenObject.js.map +1 -1
  45. package/dist/utilities/flattenObject.spec.js +158 -0
  46. package/dist/utilities/flattenObject.spec.js.map +1 -0
  47. package/dist/utilities/flattenedFields.d.ts +21 -0
  48. package/dist/utilities/flattenedFields.d.ts.map +1 -0
  49. package/dist/utilities/flattenedFields.js +34 -0
  50. package/dist/utilities/flattenedFields.js.map +1 -0
  51. package/dist/utilities/getExportFieldFunctions.d.ts +5 -5
  52. package/dist/utilities/getExportFieldFunctions.d.ts.map +1 -1
  53. package/dist/utilities/getExportFieldFunctions.js +92 -98
  54. package/dist/utilities/getExportFieldFunctions.js.map +1 -1
  55. package/dist/utilities/getExportFieldFunctions.spec.js +50 -0
  56. package/dist/utilities/getExportFieldFunctions.spec.js.map +1 -0
  57. package/dist/utilities/getImportFieldFunctions.d.ts +5 -5
  58. package/dist/utilities/getImportFieldFunctions.d.ts.map +1 -1
  59. package/dist/utilities/getImportFieldFunctions.js +103 -103
  60. package/dist/utilities/getImportFieldFunctions.js.map +1 -1
  61. package/dist/utilities/getImportFieldFunctions.spec.js +167 -0
  62. package/dist/utilities/getImportFieldFunctions.spec.js.map +1 -0
  63. package/dist/utilities/isPlainObject.d.ts +2 -0
  64. package/dist/utilities/isPlainObject.d.ts.map +1 -0
  65. package/dist/utilities/isPlainObject.js +3 -0
  66. package/dist/utilities/isPlainObject.js.map +1 -0
  67. package/dist/utilities/legacyHookDispatch.spec.js +227 -0
  68. package/dist/utilities/legacyHookDispatch.spec.js.map +1 -0
  69. package/dist/utilities/polymorphicRel.d.ts +14 -0
  70. package/dist/utilities/polymorphicRel.d.ts.map +1 -0
  71. package/dist/utilities/polymorphicRel.js +17 -0
  72. package/dist/utilities/polymorphicRel.js.map +1 -0
  73. package/dist/utilities/processRichTextField.js.map +1 -1
  74. package/dist/utilities/removeDisabledFields.js.map +1 -1
  75. package/dist/utilities/setNestedValue.d.ts.map +1 -1
  76. package/dist/utilities/setNestedValue.js +10 -8
  77. package/dist/utilities/setNestedValue.js.map +1 -1
  78. package/dist/utilities/siblingDoc.spec.js +278 -0
  79. package/dist/utilities/siblingDoc.spec.js.map +1 -0
  80. package/dist/utilities/unflattenObject.d.ts +4 -3
  81. package/dist/utilities/unflattenObject.d.ts.map +1 -1
  82. package/dist/utilities/unflattenObject.js +57 -169
  83. package/dist/utilities/unflattenObject.js.map +1 -1
  84. package/dist/utilities/unflattenObject.spec.js +33 -0
  85. package/dist/utilities/unflattenObject.spec.js.map +1 -1
  86. package/dist/utilities/unflattenPostProcess.d.ts +11 -0
  87. package/dist/utilities/unflattenPostProcess.d.ts.map +1 -0
  88. package/dist/utilities/unflattenPostProcess.js +148 -0
  89. package/dist/utilities/unflattenPostProcess.js.map +1 -0
  90. package/package.json +7 -7
@@ -0,0 +1,167 @@
1
+ import { describe, expect, it, vi } from 'vitest';
2
+ import { getImportFieldFunctions } from './getImportFieldFunctions.js';
3
+ const mockReq = {
4
+ payload: {
5
+ logger: {
6
+ error: vi.fn()
7
+ }
8
+ }
9
+ };
10
+ const callHook = (hooks, key, value)=>{
11
+ const entry = hooks[key];
12
+ if (!entry || entry.type !== 'beforeImport') {
13
+ throw new Error(`Expected beforeImport hook for ${key}`);
14
+ }
15
+ return entry.fn({
16
+ columnName: key,
17
+ data: {},
18
+ format: 'csv',
19
+ operation: 'create',
20
+ req: mockReq,
21
+ siblingData: {},
22
+ siblingDoc: {},
23
+ value
24
+ });
25
+ };
26
+ describe('getImportFieldFunctions empty-cell guards', ()=>{
27
+ describe('checkbox', ()=>{
28
+ const fields = [
29
+ {
30
+ name: 'flag',
31
+ type: 'checkbox'
32
+ }
33
+ ];
34
+ it('should return undefined for empty string instead of false', ()=>{
35
+ const hooks = getImportFieldFunctions({
36
+ fields
37
+ });
38
+ expect(callHook(hooks, 'flag', '')).toBeUndefined();
39
+ });
40
+ it('should return undefined for null', ()=>{
41
+ const hooks = getImportFieldFunctions({
42
+ fields
43
+ });
44
+ expect(callHook(hooks, 'flag', null)).toBeUndefined();
45
+ });
46
+ it('should return undefined for undefined', ()=>{
47
+ const hooks = getImportFieldFunctions({
48
+ fields
49
+ });
50
+ expect(callHook(hooks, 'flag', undefined)).toBeUndefined();
51
+ });
52
+ it('should still parse "true" as true', ()=>{
53
+ const hooks = getImportFieldFunctions({
54
+ fields
55
+ });
56
+ expect(callHook(hooks, 'flag', 'true')).toBe(true);
57
+ });
58
+ it('should still parse "false" as false', ()=>{
59
+ const hooks = getImportFieldFunctions({
60
+ fields
61
+ });
62
+ expect(callHook(hooks, 'flag', 'false')).toBe(false);
63
+ });
64
+ it('should still pass through real booleans', ()=>{
65
+ const hooks = getImportFieldFunctions({
66
+ fields
67
+ });
68
+ expect(callHook(hooks, 'flag', true)).toBe(true);
69
+ expect(callHook(hooks, 'flag', false)).toBe(false);
70
+ });
71
+ });
72
+ describe('number (without hasMany)', ()=>{
73
+ const fields = [
74
+ {
75
+ name: 'count',
76
+ type: 'number'
77
+ }
78
+ ];
79
+ it('should return undefined for empty string instead of 0', ()=>{
80
+ const hooks = getImportFieldFunctions({
81
+ fields
82
+ });
83
+ expect(callHook(hooks, 'count', '')).toBeUndefined();
84
+ });
85
+ it('should return undefined for null', ()=>{
86
+ const hooks = getImportFieldFunctions({
87
+ fields
88
+ });
89
+ expect(callHook(hooks, 'count', null)).toBeUndefined();
90
+ });
91
+ it('should return undefined for undefined', ()=>{
92
+ const hooks = getImportFieldFunctions({
93
+ fields
94
+ });
95
+ expect(callHook(hooks, 'count', undefined)).toBeUndefined();
96
+ });
97
+ it('should still parse a numeric string', ()=>{
98
+ const hooks = getImportFieldFunctions({
99
+ fields
100
+ });
101
+ expect(callHook(hooks, 'count', '42')).toBe(42);
102
+ });
103
+ it('should still pass through a real number', ()=>{
104
+ const hooks = getImportFieldFunctions({
105
+ fields
106
+ });
107
+ expect(callHook(hooks, 'count', 7)).toBe(7);
108
+ });
109
+ });
110
+ describe('date', ()=>{
111
+ const fields = [
112
+ {
113
+ name: 'when',
114
+ type: 'date'
115
+ }
116
+ ];
117
+ it('should return undefined for empty string', ()=>{
118
+ const hooks = getImportFieldFunctions({
119
+ fields
120
+ });
121
+ expect(callHook(hooks, 'when', '')).toBeUndefined();
122
+ });
123
+ it('should return undefined for null', ()=>{
124
+ const hooks = getImportFieldFunctions({
125
+ fields
126
+ });
127
+ expect(callHook(hooks, 'when', null)).toBeUndefined();
128
+ });
129
+ it('should still parse a valid ISO date', ()=>{
130
+ const hooks = getImportFieldFunctions({
131
+ fields
132
+ });
133
+ const iso = '2026-05-06T00:00:00.000Z';
134
+ expect(callHook(hooks, 'when', iso)).toBe(iso);
135
+ });
136
+ });
137
+ describe('json', ()=>{
138
+ const fields = [
139
+ {
140
+ name: 'meta',
141
+ type: 'json'
142
+ }
143
+ ];
144
+ it('should return undefined for empty string', ()=>{
145
+ const hooks = getImportFieldFunctions({
146
+ fields
147
+ });
148
+ expect(callHook(hooks, 'meta', '')).toBeUndefined();
149
+ });
150
+ it('should return undefined for null', ()=>{
151
+ const hooks = getImportFieldFunctions({
152
+ fields
153
+ });
154
+ expect(callHook(hooks, 'meta', null)).toBeUndefined();
155
+ });
156
+ it('should still parse a valid JSON string', ()=>{
157
+ const hooks = getImportFieldFunctions({
158
+ fields
159
+ });
160
+ expect(callHook(hooks, 'meta', '{"a":1}')).toEqual({
161
+ a: 1
162
+ });
163
+ });
164
+ });
165
+ });
166
+
167
+ //# sourceMappingURL=getImportFieldFunctions.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/getImportFieldFunctions.spec.ts"],"sourcesContent":["import { FlattenedField, PayloadRequest } from 'payload'\n\nimport { describe, expect, it, vi } from 'vitest'\n\nimport { getImportFieldFunctions } from './getImportFieldFunctions.js'\n\nconst mockReq = {\n payload: {\n logger: {\n error: vi.fn(),\n },\n },\n} as unknown as PayloadRequest\n\nconst callHook = (\n hooks: ReturnType<typeof getImportFieldFunctions>,\n key: string,\n value: unknown,\n) => {\n const entry = hooks[key]\n if (!entry || entry.type !== 'beforeImport') {\n throw new Error(`Expected beforeImport hook for ${key}`)\n }\n return entry.fn({\n columnName: key,\n data: {},\n format: 'csv',\n operation: 'create',\n req: mockReq,\n siblingData: {},\n siblingDoc: {},\n value,\n })\n}\n\ndescribe('getImportFieldFunctions empty-cell guards', () => {\n describe('checkbox', () => {\n const fields: FlattenedField[] = [{ name: 'flag', type: 'checkbox' } as FlattenedField]\n\n it('should return undefined for empty string instead of false', () => {\n const hooks = getImportFieldFunctions({ fields })\n expect(callHook(hooks, 'flag', '')).toBeUndefined()\n })\n\n it('should return undefined for null', () => {\n const hooks = getImportFieldFunctions({ fields })\n expect(callHook(hooks, 'flag', null)).toBeUndefined()\n })\n\n it('should return undefined for undefined', () => {\n const hooks = getImportFieldFunctions({ fields })\n expect(callHook(hooks, 'flag', undefined)).toBeUndefined()\n })\n\n it('should still parse \"true\" as true', () => {\n const hooks = getImportFieldFunctions({ fields })\n expect(callHook(hooks, 'flag', 'true')).toBe(true)\n })\n\n it('should still parse \"false\" as false', () => {\n const hooks = getImportFieldFunctions({ fields })\n expect(callHook(hooks, 'flag', 'false')).toBe(false)\n })\n\n it('should still pass through real booleans', () => {\n const hooks = getImportFieldFunctions({ fields })\n expect(callHook(hooks, 'flag', true)).toBe(true)\n expect(callHook(hooks, 'flag', false)).toBe(false)\n })\n })\n\n describe('number (without hasMany)', () => {\n const fields: FlattenedField[] = [{ name: 'count', type: 'number' } as FlattenedField]\n\n it('should return undefined for empty string instead of 0', () => {\n const hooks = getImportFieldFunctions({ fields })\n expect(callHook(hooks, 'count', '')).toBeUndefined()\n })\n\n it('should return undefined for null', () => {\n const hooks = getImportFieldFunctions({ fields })\n expect(callHook(hooks, 'count', null)).toBeUndefined()\n })\n\n it('should return undefined for undefined', () => {\n const hooks = getImportFieldFunctions({ fields })\n expect(callHook(hooks, 'count', undefined)).toBeUndefined()\n })\n\n it('should still parse a numeric string', () => {\n const hooks = getImportFieldFunctions({ fields })\n expect(callHook(hooks, 'count', '42')).toBe(42)\n })\n\n it('should still pass through a real number', () => {\n const hooks = getImportFieldFunctions({ fields })\n expect(callHook(hooks, 'count', 7)).toBe(7)\n })\n })\n\n describe('date', () => {\n const fields: FlattenedField[] = [{ name: 'when', type: 'date' } as FlattenedField]\n\n it('should return undefined for empty string', () => {\n const hooks = getImportFieldFunctions({ fields })\n expect(callHook(hooks, 'when', '')).toBeUndefined()\n })\n\n it('should return undefined for null', () => {\n const hooks = getImportFieldFunctions({ fields })\n expect(callHook(hooks, 'when', null)).toBeUndefined()\n })\n\n it('should still parse a valid ISO date', () => {\n const hooks = getImportFieldFunctions({ fields })\n const iso = '2026-05-06T00:00:00.000Z'\n expect(callHook(hooks, 'when', iso)).toBe(iso)\n })\n })\n\n describe('json', () => {\n const fields: FlattenedField[] = [{ name: 'meta', type: 'json' } as FlattenedField]\n\n it('should return undefined for empty string', () => {\n const hooks = getImportFieldFunctions({ fields })\n expect(callHook(hooks, 'meta', '')).toBeUndefined()\n })\n\n it('should return undefined for null', () => {\n const hooks = getImportFieldFunctions({ fields })\n expect(callHook(hooks, 'meta', null)).toBeUndefined()\n })\n\n it('should still parse a valid JSON string', () => {\n const hooks = getImportFieldFunctions({ fields })\n expect(callHook(hooks, 'meta', '{\"a\":1}')).toEqual({ a: 1 })\n })\n })\n})\n"],"names":["describe","expect","it","vi","getImportFieldFunctions","mockReq","payload","logger","error","fn","callHook","hooks","key","value","entry","type","Error","columnName","data","format","operation","req","siblingData","siblingDoc","fields","name","toBeUndefined","undefined","toBe","iso","toEqual","a"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAA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Oe,aAAa;QACrD;QAEAxB,GAAG,uCAAuC;YACxC,MAAMS,QAAQP,wBAAwB;gBAAEoB;YAAO;YAC/C,MAAMK,MAAM;YACZ5B,OAAOS,SAASC,OAAO,QAAQkB,MAAMD,IAAI,CAACC;QAC5C;IACF;IAEA7B,SAAS,QAAQ;QACf,MAAMwB,SAA2B;YAAC;gBAAEC,MAAM;gBAAQV,MAAM;YAAO;SAAoB;QAEnFb,GAAG,4CAA4C;YAC7C,MAAMS,QAAQP,wBAAwB;gBAAEoB;YAAO;YAC/CvB,OAAOS,SAASC,OAAO,QAAQ,KAAKe,aAAa;QACnD;QAEAxB,GAAG,oCAAoC;YACrC,MAAMS,QAAQP,wBAAwB;gBAAEoB;YAAO;YAC/CvB,OAAOS,SAASC,OAAO,QAAQ,OAAOe,aAAa;QACrD;QAEAxB,GAAG,0CAA0C;YAC3C,MAAMS,QAAQP,wBAAwB;gBAAEoB;YAAO;YAC/CvB,OAAOS,SAASC,OAAO,QAAQ,YAAYmB,OAAO,CAAC;gBAAEC,GAAG;YAAE;QAC5D;IACF;AACF"}
@@ -0,0 +1,2 @@
1
+ export declare const isPlainObject: (value: unknown) => value is Record<string, unknown>;
2
+ //# sourceMappingURL=isPlainObject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isPlainObject.d.ts","sourceRoot":"","sources":["../../src/utilities/isPlainObject.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,UAAW,OAAO,KAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CACR,CAAA"}
@@ -0,0 +1,3 @@
1
+ export const isPlainObject = (value)=>typeof value === 'object' && value !== null && !Array.isArray(value);
2
+
3
+ //# sourceMappingURL=isPlainObject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/isPlainObject.ts"],"sourcesContent":["export const isPlainObject = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value)\n"],"names":["isPlainObject","value","Array","isArray"],"mappings":"AAAA,OAAO,MAAMA,gBAAgB,CAACC,QAC5B,OAAOA,UAAU,YAAYA,UAAU,QAAQ,CAACC,MAAMC,OAAO,CAACF,OAAM"}
@@ -0,0 +1,227 @@
1
+ import { flattenObject } from './flattenObject.js';
2
+ import { getExportFieldFunctions } from './getExportFieldFunctions.js';
3
+ import { getImportFieldFunctions } from './getImportFieldFunctions.js';
4
+ import { unflattenObject } from './unflattenObject.js';
5
+ import { describe, expect, it, vi } from 'vitest';
6
+ const mockReq = {
7
+ payload: {
8
+ logger: {
9
+ error: vi.fn()
10
+ }
11
+ }
12
+ };
13
+ describe('legacy toCSV / fromCSV argument shape', ()=>{
14
+ describe('toCSV receives { columnName, data, doc, row, siblingDoc, value }', ()=>{
15
+ it('should pass row as flat row accumulator, doc as top-level doc, and siblingDoc as source doc', ()=>{
16
+ const received = [];
17
+ const fields = [
18
+ {
19
+ name: 'legacy',
20
+ type: 'text',
21
+ custom: {
22
+ 'plugin-import-export': {
23
+ toCSV: (args)=>{
24
+ received.push(args);
25
+ args.row[`${args.columnName}_extra`] = 'added';
26
+ return String(args.value) + '_transformed';
27
+ }
28
+ }
29
+ }
30
+ }
31
+ ];
32
+ const exportFieldHooks = getExportFieldFunctions({
33
+ fields
34
+ });
35
+ const doc = {
36
+ legacy: 'hello',
37
+ title: 'Top'
38
+ };
39
+ const result = flattenObject({
40
+ data: doc,
41
+ exportFieldHooks,
42
+ format: 'csv',
43
+ req: mockReq
44
+ });
45
+ expect(received).toHaveLength(1);
46
+ const args = received[0];
47
+ expect(args.columnName).toBe('legacy');
48
+ expect(args.value).toBe('hello');
49
+ // doc should be the top-level document
50
+ expect(args.doc).toBe(doc);
51
+ // siblingDoc should be the source doc at the current nesting level (top-level == doc)
52
+ expect(args.siblingDoc).toBe(doc);
53
+ // row should be the flat row accumulator (a different object from doc)
54
+ expect(args.row).not.toBe(doc);
55
+ // data is kept as alias for row to avoid breaking legacy usage
56
+ expect(args.data).toBe(args.row);
57
+ expect(result.legacy).toBe('hello_transformed');
58
+ expect(result.legacy_extra).toBe('added');
59
+ });
60
+ it('should not pass legacy args to hooks.beforeExport', ()=>{
61
+ const received = [];
62
+ const fields = [
63
+ {
64
+ name: 'modern',
65
+ type: 'text',
66
+ custom: {
67
+ 'plugin-import-export': {
68
+ hooks: {
69
+ beforeExport: (args)=>{
70
+ received.push(args);
71
+ return String(args.value) + '_modern';
72
+ }
73
+ }
74
+ }
75
+ }
76
+ }
77
+ ];
78
+ const exportFieldHooks = getExportFieldFunctions({
79
+ fields
80
+ });
81
+ const doc = {
82
+ modern: 'v',
83
+ title: 'Top'
84
+ };
85
+ flattenObject({
86
+ data: doc,
87
+ exportFieldHooks,
88
+ format: 'csv',
89
+ req: mockReq
90
+ });
91
+ expect(received).toHaveLength(1);
92
+ const args = received[0];
93
+ // Modern signature: data === top-level doc
94
+ expect(args.data).toBe(doc);
95
+ // Modern signature: siblingData === flat row accumulator (not source doc)
96
+ expect(args.siblingData).not.toBe(doc);
97
+ expect(args.format).toBe('csv');
98
+ // Legacy-only args should not be present
99
+ expect(args.doc).toBeUndefined();
100
+ expect(args.row).toBeUndefined();
101
+ // `siblingDoc` is part of the modern signature too (read-only source view)
102
+ expect(args.siblingDoc).toBeDefined();
103
+ });
104
+ it('should prefer hooks.beforeExport when both are defined on a field', ()=>{
105
+ const legacyCalls = [];
106
+ const modernCalls = [];
107
+ const fields = [
108
+ {
109
+ name: 'both',
110
+ type: 'text',
111
+ custom: {
112
+ 'plugin-import-export': {
113
+ hooks: {
114
+ beforeExport: ({ value })=>{
115
+ modernCalls.push(String(value));
116
+ return `${value}_modern`;
117
+ }
118
+ },
119
+ toCSV: ({ value })=>{
120
+ legacyCalls.push(String(value));
121
+ return `${value}_legacy`;
122
+ }
123
+ }
124
+ }
125
+ }
126
+ ];
127
+ const exportFieldHooks = getExportFieldFunctions({
128
+ fields
129
+ });
130
+ const result = flattenObject({
131
+ data: {
132
+ both: 'x'
133
+ },
134
+ exportFieldHooks,
135
+ format: 'csv',
136
+ req: mockReq
137
+ });
138
+ expect(modernCalls).toEqual([
139
+ 'x'
140
+ ]);
141
+ expect(legacyCalls).toEqual([]);
142
+ expect(result.both).toBe('x_modern');
143
+ });
144
+ });
145
+ describe('fromCSV receives { columnName, data, value } with data as full flat row', ()=>{
146
+ it('should pass the full flat row as data', ()=>{
147
+ const received = [];
148
+ const fields = [
149
+ {
150
+ name: 'legacy',
151
+ type: 'text',
152
+ custom: {
153
+ 'plugin-import-export': {
154
+ fromCSV: (args)=>{
155
+ received.push(args);
156
+ return String(args.value) + '_imported';
157
+ }
158
+ }
159
+ }
160
+ }
161
+ ];
162
+ const importFieldHooks = getImportFieldFunctions({
163
+ fields
164
+ });
165
+ const flatRow = {
166
+ legacy: 'incoming',
167
+ title: 'Top'
168
+ };
169
+ const result = unflattenObject({
170
+ data: flatRow,
171
+ fields,
172
+ format: 'csv',
173
+ importFieldHooks,
174
+ req: mockReq
175
+ });
176
+ expect(received).toHaveLength(1);
177
+ expect(received[0].columnName).toBe('legacy');
178
+ expect(received[0].value).toBe('incoming');
179
+ // data should be the full flat row
180
+ expect(received[0].data).toBe(flatRow);
181
+ expect(result.legacy).toBe('incoming_imported');
182
+ });
183
+ it('should prefer hooks.beforeImport when both are defined on a field', ()=>{
184
+ const legacyCalls = [];
185
+ const modernCalls = [];
186
+ const fields = [
187
+ {
188
+ name: 'both',
189
+ type: 'text',
190
+ custom: {
191
+ 'plugin-import-export': {
192
+ fromCSV: ({ value })=>{
193
+ legacyCalls.push(String(value));
194
+ return `${value}_legacy`;
195
+ },
196
+ hooks: {
197
+ beforeImport: ({ value })=>{
198
+ modernCalls.push(String(value));
199
+ return `${value}_modern`;
200
+ }
201
+ }
202
+ }
203
+ }
204
+ }
205
+ ];
206
+ const importFieldHooks = getImportFieldFunctions({
207
+ fields
208
+ });
209
+ const result = unflattenObject({
210
+ data: {
211
+ both: 'x'
212
+ },
213
+ fields,
214
+ format: 'csv',
215
+ importFieldHooks,
216
+ req: mockReq
217
+ });
218
+ expect(modernCalls).toEqual([
219
+ 'x'
220
+ ]);
221
+ expect(legacyCalls).toEqual([]);
222
+ expect(result.both).toBe('x_modern');
223
+ });
224
+ });
225
+ });
226
+
227
+ //# sourceMappingURL=legacyHookDispatch.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/legacyHookDispatch.spec.ts"],"sourcesContent":["import { FlattenedField, PayloadRequest } from 'payload'\n\nimport type { FromCSVFunction, ToCSVFunction } from '../types.js'\n\nimport { flattenObject } from './flattenObject.js'\nimport { getExportFieldFunctions } from './getExportFieldFunctions.js'\nimport { getImportFieldFunctions } from './getImportFieldFunctions.js'\nimport { unflattenObject } from './unflattenObject.js'\n\nimport { describe, expect, it, vi } from 'vitest'\n\nconst mockReq = {\n payload: {\n logger: {\n error: vi.fn(),\n },\n },\n} as unknown as PayloadRequest\n\ndescribe('legacy toCSV / fromCSV argument shape', () => {\n describe('toCSV receives { columnName, data, doc, row, siblingDoc, value }', () => {\n it('should pass row as flat row accumulator, doc as top-level doc, and siblingDoc as source doc', () => {\n const received: Parameters<ToCSVFunction>[0][] = []\n\n const fields: FlattenedField[] = [\n {\n name: 'legacy',\n type: 'text',\n custom: {\n 'plugin-import-export': {\n toCSV: ((args) => {\n received.push(args)\n args.row[`${args.columnName}_extra`] = 'added'\n return String(args.value) + '_transformed'\n }) satisfies ToCSVFunction,\n },\n },\n } as FlattenedField,\n ]\n\n const exportFieldHooks = getExportFieldFunctions({ fields })\n\n const doc = { legacy: 'hello', title: 'Top' }\n const result = flattenObject({\n data: doc,\n exportFieldHooks,\n format: 'csv',\n req: mockReq,\n })\n\n expect(received).toHaveLength(1)\n const args = received[0]!\n expect(args.columnName).toBe('legacy')\n expect(args.value).toBe('hello')\n // doc should be the top-level document\n expect(args.doc).toBe(doc)\n // siblingDoc should be the source doc at the current nesting level (top-level == doc)\n expect(args.siblingDoc).toBe(doc)\n // row should be the flat row accumulator (a different object from doc)\n expect(args.row).not.toBe(doc)\n // data is kept as alias for row to avoid breaking legacy usage\n expect(args.data).toBe(args.row)\n\n expect(result.legacy).toBe('hello_transformed')\n expect(result.legacy_extra).toBe('added')\n })\n\n it('should not pass legacy args to hooks.beforeExport', () => {\n const received: Array<Record<string, unknown>> = []\n\n const fields: FlattenedField[] = [\n {\n name: 'modern',\n type: 'text',\n custom: {\n 'plugin-import-export': {\n hooks: {\n beforeExport: (args) => {\n received.push(args as unknown as Record<string, unknown>)\n return String(args.value) + '_modern'\n },\n },\n },\n },\n } as FlattenedField,\n ]\n\n const exportFieldHooks = getExportFieldFunctions({ fields })\n\n const doc = { modern: 'v', title: 'Top' }\n flattenObject({ data: doc, exportFieldHooks, format: 'csv', req: mockReq })\n\n expect(received).toHaveLength(1)\n const args = received[0]!\n // Modern signature: data === top-level doc\n expect(args.data).toBe(doc)\n // Modern signature: siblingData === flat row accumulator (not source doc)\n expect(args.siblingData).not.toBe(doc)\n expect(args.format).toBe('csv')\n // Legacy-only args should not be present\n expect(args.doc).toBeUndefined()\n expect(args.row).toBeUndefined()\n // `siblingDoc` is part of the modern signature too (read-only source view)\n expect(args.siblingDoc).toBeDefined()\n })\n\n it('should prefer hooks.beforeExport when both are defined on a field', () => {\n const legacyCalls: string[] = []\n const modernCalls: string[] = []\n\n const fields: FlattenedField[] = [\n {\n name: 'both',\n type: 'text',\n custom: {\n 'plugin-import-export': {\n hooks: {\n beforeExport: ({ value }) => {\n modernCalls.push(String(value))\n return `${value}_modern`\n },\n },\n toCSV: ({ value }: { value: unknown }) => {\n legacyCalls.push(String(value))\n return `${value}_legacy`\n },\n },\n },\n } as FlattenedField,\n ]\n\n const exportFieldHooks = getExportFieldFunctions({ fields })\n const result = flattenObject({\n data: { both: 'x' },\n exportFieldHooks,\n format: 'csv',\n req: mockReq,\n })\n\n expect(modernCalls).toEqual(['x'])\n expect(legacyCalls).toEqual([])\n expect(result.both).toBe('x_modern')\n })\n })\n\n describe('fromCSV receives { columnName, data, value } with data as full flat row', () => {\n it('should pass the full flat row as data', () => {\n const received: Parameters<FromCSVFunction>[0][] = []\n\n const fields: FlattenedField[] = [\n {\n name: 'legacy',\n type: 'text',\n custom: {\n 'plugin-import-export': {\n fromCSV: ((args) => {\n received.push(args)\n return String(args.value) + '_imported'\n }) satisfies FromCSVFunction,\n },\n },\n } as FlattenedField,\n ]\n\n const importFieldHooks = getImportFieldFunctions({ fields })\n\n const flatRow = { legacy: 'incoming', title: 'Top' }\n const result = unflattenObject({\n data: flatRow,\n fields,\n format: 'csv',\n importFieldHooks,\n req: mockReq,\n })\n\n expect(received).toHaveLength(1)\n expect(received[0]!.columnName).toBe('legacy')\n expect(received[0]!.value).toBe('incoming')\n // data should be the full flat row\n expect(received[0]!.data).toBe(flatRow)\n\n expect(result.legacy).toBe('incoming_imported')\n })\n\n it('should prefer hooks.beforeImport when both are defined on a field', () => {\n const legacyCalls: string[] = []\n const modernCalls: string[] = []\n\n const fields: FlattenedField[] = [\n {\n name: 'both',\n type: 'text',\n custom: {\n 'plugin-import-export': {\n fromCSV: ({ value }: { value: unknown }) => {\n legacyCalls.push(String(value))\n return `${value}_legacy`\n },\n hooks: {\n beforeImport: ({ value }) => {\n modernCalls.push(String(value))\n return `${value}_modern`\n },\n },\n },\n },\n } as FlattenedField,\n ]\n\n const importFieldHooks = getImportFieldFunctions({ fields })\n const result = unflattenObject({\n data: { both: 'x' },\n fields,\n format: 'csv',\n importFieldHooks,\n req: mockReq,\n })\n\n expect(modernCalls).toEqual(['x'])\n expect(legacyCalls).toEqual([])\n expect(result.both).toBe('x_modern')\n })\n })\n})\n"],"names":["flattenObject","getExportFieldFunctions","getImportFieldFunctions","unflattenObject","describe","expect","it","vi","mockReq","payload","logger","error","fn","received","fields","name","type","custom","toCSV","args","push","row","columnName","String","value","exportFieldHooks","doc","legacy","title","result","data","format","req","toHaveLength","toBe","siblingDoc","not","legacy_extra","hooks","beforeExport","modern","siblingData","toBeUndefined","toBeDefined","legacyCalls","modernCalls","both","toEqual","fromC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EAAEY,IAAI,CAAC;YACrC7B,OAAOQ,QAAQ,CAAC,EAAE,CAAEW,KAAK,EAAEU,IAAI,CAAC;YAChC,mCAAmC;YACnC7B,OAAOQ,QAAQ,CAAC,EAAE,CAAEiB,IAAI,EAAEI,IAAI,CAACgB;YAE/B7C,OAAOwB,OAAOF,MAAM,EAAEO,IAAI,CAAC;QAC7B;QAEA5B,GAAG,qEAAqE;YACtE,MAAMsC,cAAwB,EAAE;YAChC,MAAMC,cAAwB,EAAE;YAEhC,MAAM/B,SAA2B;gBAC/B;oBACEC,MAAM;oBACNC,MAAM;oBACNC,QAAQ;wBACN,wBAAwB;4BACtB+B,SAAS,CAAC,EAAExB,KAAK,EAAsB;gCACrCoB,YAAYxB,IAAI,CAACG,OAAOC;gCACxB,OAAO,GAAGA,MAAM,OAAO,CAAC;4BAC1B;4BACAc,OAAO;gCACLa,cAAc,CAAC,EAAE3B,KAAK,EAAE;oCACtBqB,YAAYzB,IAAI,CAACG,OAAOC;oCACxB,OAAO,GAAGA,MAAM,OAAO,CAAC;gCAC1B;4BACF;wBACF;oBACF;gBACF;aACD;YAED,MAAMyB,mBAAmB/C,wBAAwB;gBAAEY;YAAO;YAC1D,MAAMe,SAAS1B,gBAAgB;gBAC7B2B,MAAM;oBAAEgB,MAAM;gBAAI;gBAClBhC;gBACAiB,QAAQ;gBACRkB;gBACAjB,KAAKxB;YACP;YAEAH,OAAOwC,aAAaE,OAAO,CAAC;gBAAC;aAAI;YACjC1C,OAAOuC,aAAaG,OAAO,CAAC,EAAE;YAC9B1C,OAAOwB,OAAOiB,IAAI,EAAEZ,IAAI,CAAC;QAC3B;IACF;AACF"}
@@ -0,0 +1,14 @@
1
+ export type PolymorphicRelValue = {
2
+ relationTo: string;
3
+ value: {
4
+ id: number | string;
5
+ } | number | string;
6
+ };
7
+ export declare const isPolymorphicRelValue: (v: unknown) => v is PolymorphicRelValue;
8
+ /**
9
+ * Returns the id of a populated polymorphic relationship value, or `undefined`
10
+ * if the inner value is missing. Handles both depth=0 (`value` is the bare id)
11
+ * and depth>=1 (`value` is the populated doc).
12
+ */
13
+ export declare const getPolymorphicRelId: (v: PolymorphicRelValue) => number | string | undefined;
14
+ //# sourceMappingURL=polymorphicRel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polymorphicRel.d.ts","sourceRoot":"","sources":["../../src/utilities/polymorphicRel.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG;IAChC,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE;QAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAAG,MAAM,GAAG,MAAM,CAAA;CACjD,CAAA;AAED,eAAO,MAAM,qBAAqB,MAAO,OAAO,KAAG,CAAC,IAAI,mBACkB,CAAA;AAE1E;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,MAAO,mBAAmB,KAAG,MAAM,GAAG,MAAM,GAAG,SAS9E,CAAA"}
@@ -0,0 +1,17 @@
1
+ export const isPolymorphicRelValue = (v)=>typeof v === 'object' && v !== null && 'relationTo' in v && 'value' in v;
2
+ /**
3
+ * Returns the id of a populated polymorphic relationship value, or `undefined`
4
+ * if the inner value is missing. Handles both depth=0 (`value` is the bare id)
5
+ * and depth>=1 (`value` is the populated doc).
6
+ */ export const getPolymorphicRelId = (v)=>{
7
+ const inner = v.value;
8
+ if (inner == null) {
9
+ return undefined;
10
+ }
11
+ if (typeof inner === 'object') {
12
+ return inner.id;
13
+ }
14
+ return inner;
15
+ };
16
+
17
+ //# sourceMappingURL=polymorphicRel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utilities/polymorphicRel.ts"],"sourcesContent":["export type PolymorphicRelValue = {\n relationTo: string\n value: { id: number | string } | number | string\n}\n\nexport const isPolymorphicRelValue = (v: unknown): v is PolymorphicRelValue =>\n typeof v === 'object' && v !== null && 'relationTo' in v && 'value' in v\n\n/**\n * Returns the id of a populated polymorphic relationship value, or `undefined`\n * if the inner value is missing. Handles both depth=0 (`value` is the bare id)\n * and depth>=1 (`value` is the populated doc).\n */\nexport const getPolymorphicRelId = (v: PolymorphicRelValue): number | string | undefined => {\n const inner = v.value\n if (inner == null) {\n return undefined\n }\n if (typeof inner === 'object') {\n return (inner as { id?: number | string }).id\n }\n return inner\n}\n"],"names":["isPolymorphicRelValue","v","getPolymorphicRelId","inner","value","undefined","id"],"mappings":"AAKA,OAAO,MAAMA,wBAAwB,CAACC,IACpC,OAAOA,MAAM,YAAYA,MAAM,QAAQ,gBAAgBA,KAAK,WAAWA,EAAC;AAE1E;;;;CAIC,GACD,OAAO,MAAMC,sBAAsB,CAACD;IAClC,MAAME,QAAQF,EAAEG,KAAK;IACrB,IAAID,SAAS,MAAM;QACjB,OAAOE;IACT;IACA,IAAI,OAAOF,UAAU,UAAU;QAC7B,OAAO,AAACA,MAAmCG,EAAE;IAC/C;IACA,OAAOH;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/processRichTextField.ts"],"sourcesContent":["/**\n * Process rich text fields to ensure proper data types for Lexical editor.\n * Lexical expects certain properties to be numbers, not strings.\n */\nexport const processRichTextField = (value: unknown): unknown => {\n if (!value || typeof value !== 'object') {\n return value\n }\n\n // Properties that should be numbers in Lexical\n const numericProperties = [\n 'detail',\n 'format',\n 'indent',\n 'version',\n 'value',\n 'start',\n 'textFormat',\n 'textStyle',\n ]\n\n const processNode = (node: any): any => {\n if (!node || typeof node !== 'object') {\n return node\n }\n\n // Process current node's properties\n const processed: any = {}\n for (const [key, val] of Object.entries(node)) {\n if (numericProperties.includes(key) && typeof val === 'string') {\n // Convert string numbers to actual numbers\n const num = parseFloat(val)\n processed[key] = isNaN(num) ? val : num\n } else if (key === 'children' && Array.isArray(val)) {\n // Recursively process children\n processed[key] = val.map((child) => processNode(child))\n } else if (typeof val === 'object' && val !== null) {\n // Recursively process nested objects\n processed[key] = processNode(val)\n } else {\n processed[key] = val\n }\n }\n\n return processed\n }\n\n return processNode(value)\n}\n"],"names":["processRichTextField","value","numericProperties","processNode","node","processed","key","val","Object","entries","includes","num","parseFloat","isNaN","Array","isArray","map","child"],"mappings":"AAAA;;;CAGC,GACD,OAAO,MAAMA,uBAAuB,CAACC;IACnC,IAAI,CAACA,SAAS,OAAOA,UAAU,UAAU;QACvC,OAAOA;IACT;IAEA,+CAA+C;IAC/C,MAAMC,oBAAoB;QACxB;QACA;QACA;QACA;QACA;QACA;QACA;QACA;KACD;IAED,MAAMC,cAAc,CAACC;QACnB,IAAI,CAACA,QAAQ,OAAOA,SAAS,UAAU;YACrC,OAAOA;QACT;QAEA,oCAAoC;QACpC,MAAMC,YAAiB,CAAC;QACxB,KAAK,MAAM,CAACC,KAAKC,IAAI,IAAIC,OAAOC,OAAO,CAACL,MAAO;YAC7C,IAAIF,kBAAkBQ,QAAQ,CAACJ,QAAQ,OAAOC,QAAQ,UAAU;gBAC9D,2CAA2C;gBAC3C,MAAMI,MAAMC,WAAWL;gBACvBF,SAAS,CAACC,IAAI,GAAGO,MAAMF,OAAOJ,MAAMI;YACtC,OAAO,IAAIL,QAAQ,cAAcQ,MAAMC,OAAO,CAACR,MAAM;gBACnD,+BAA+B;gBAC/BF,SAAS,CAACC,IAAI,GAAGC,IAAIS,GAAG,CAAC,CAACC,QAAUd,YAAYc;YAClD,OAAO,IAAI,OAAOV,QAAQ,YAAYA,QAAQ,MAAM;gBAClD,qCAAqC;gBACrCF,SAAS,CAACC,IAAI,GAAGH,YAAYI;YAC/B,OAAO;gBACLF,SAAS,CAACC,IAAI,GAAGC;YACnB;QACF;QAEA,OAAOF;IACT;IAEA,OAAOF,YAAYF;AACrB,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/processRichTextField.ts"],"sourcesContent":["/**\n * Process rich text fields to ensure proper data types for Lexical editor.\n * Lexical expects certain properties to be numbers, not strings.\n */\nexport const processRichTextField = (value: unknown): unknown => {\n if (!value || typeof value !== 'object') {\n return value\n }\n\n // Properties that should be numbers in Lexical\n const numericProperties = [\n 'detail',\n 'format',\n 'indent',\n 'version',\n 'value',\n 'start',\n 'textFormat',\n 'textStyle',\n ]\n\n const processNode = (node: unknown): unknown => {\n if (!node || typeof node !== 'object') {\n return node\n }\n\n // Process current node's properties\n const processed: Record<string, unknown> = {}\n for (const [key, val] of Object.entries(node as Record<string, unknown>)) {\n if (numericProperties.includes(key) && typeof val === 'string') {\n // Convert string numbers to actual numbers\n const num = parseFloat(val)\n processed[key] = isNaN(num) ? val : num\n } else if (key === 'children' && Array.isArray(val)) {\n // Recursively process children\n processed[key] = val.map((child) => processNode(child))\n } else if (typeof val === 'object' && val !== null) {\n // Recursively process nested objects\n processed[key] = processNode(val)\n } else {\n processed[key] = val\n }\n }\n\n return processed\n }\n\n return processNode(value)\n}\n"],"names":["processRichTextField","value","numericProperties","processNode","node","processed","key","val","Object","entries","includes","num","parseFloat","isNaN","Array","isArray","map","child"],"mappings":"AAAA;;;CAGC,GACD,OAAO,MAAMA,uBAAuB,CAACC;IACnC,IAAI,CAACA,SAAS,OAAOA,UAAU,UAAU;QACvC,OAAOA;IACT;IAEA,+CAA+C;IAC/C,MAAMC,oBAAoB;QACxB;QACA;QACA;QACA;QACA;QACA;QACA;QACA;KACD;IAED,MAAMC,cAAc,CAACC;QACnB,IAAI,CAACA,QAAQ,OAAOA,SAAS,UAAU;YACrC,OAAOA;QACT;QAEA,oCAAoC;QACpC,MAAMC,YAAqC,CAAC;QAC5C,KAAK,MAAM,CAACC,KAAKC,IAAI,IAAIC,OAAOC,OAAO,CAACL,MAAkC;YACxE,IAAIF,kBAAkBQ,QAAQ,CAACJ,QAAQ,OAAOC,QAAQ,UAAU;gBAC9D,2CAA2C;gBAC3C,MAAMI,MAAMC,WAAWL;gBACvBF,SAAS,CAACC,IAAI,GAAGO,MAAMF,OAAOJ,MAAMI;YACtC,OAAO,IAAIL,QAAQ,cAAcQ,MAAMC,OAAO,CAACR,MAAM;gBACnD,+BAA+B;gBAC/BF,SAAS,CAACC,IAAI,GAAGC,IAAIS,GAAG,CAAC,CAACC,QAAUd,YAAYc;YAClD,OAAO,IAAI,OAAOV,QAAQ,YAAYA,QAAQ,MAAM;gBAClD,qCAAqC;gBACrCF,SAAS,CAACC,IAAI,GAAGH,YAAYI;YAC/B,OAAO;gBACLF,SAAS,CAACC,IAAI,GAAGC;YACnB;QACF;QAEA,OAAOF;IACT;IAEA,OAAOF,YAAYF;AACrB,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/removeDisabledFields.ts"],"sourcesContent":["/**\n * Recursively removes fields from a deeply nested object based on dot-notation paths.\n *\n * This utility supports removing:\n * - Nested fields in plain objects (e.g., \"group.value\")\n * - Fields inside arrays of objects (e.g., \"group.array.field1\")\n *\n * It safely traverses both object and array structures and avoids mutating the original input.\n *\n * @param obj - The original object to clean.\n * @param disabled - An array of dot-separated paths indicating which fields to remove.\n * @returns A deep clone of the original object with specified fields removed.\n */\n\nexport const removeDisabledFields = (\n obj: Record<string, unknown>,\n disabled: string[] = [],\n): Record<string, unknown> => {\n if (!disabled.length) {\n return obj\n }\n\n const clone = structuredClone(obj)\n\n // Process each disabled path independently\n for (const path of disabled) {\n const parts = path.split('.')\n\n /**\n * Recursively walks the object tree according to the dot path,\n * and deletes the field once the full path is reached.\n *\n * @param target - The current object or array being traversed\n * @param i - The index of the current path part\n */\n const removeRecursively = (target: any, i = 0): void => {\n if (target == null) {\n return\n }\n\n const key = parts[i]\n\n // If at the final part of the path, perform the deletion\n if (i === parts.length - 1) {\n // If the current level is an array, delete the key from each item\n if (Array.isArray(target)) {\n for (const item of target) {\n if (item && typeof item === 'object' && key !== undefined) {\n delete item[key as keyof typeof item]\n }\n }\n } else if (typeof target === 'object' && key !== undefined) {\n delete target[key]\n }\n return\n }\n\n if (key === undefined) {\n return\n }\n\n // Traverse to the next level in the path\n const next = target[key]\n\n if (Array.isArray(next)) {\n // If the next value is an array, recurse into each item\n for (const item of next) {\n removeRecursively(item, i + 1)\n }\n } else {\n // Otherwise, continue down the object path\n removeRecursively(next, i + 1)\n }\n }\n\n removeRecursively(clone)\n }\n\n return clone\n}\n"],"names":["removeDisabledFields","obj","disabled","length","clone","structuredClone","path","parts","split","removeRecursively","target","i","key","Array","isArray","item","undefined","next"],"mappings":"AAAA;;;;;;;;;;;;CAYC,GAED,OAAO,MAAMA,uBAAuB,CAClCC,KACAC,WAAqB,EAAE;IAEvB,IAAI,CAACA,SAASC,MAAM,EAAE;QACpB,OAAOF;IACT;IAEA,MAAMG,QAAQC,gBAAgBJ;IAE9B,2CAA2C;IAC3C,KAAK,MAAMK,QAAQJ,SAAU;QAC3B,MAAMK,QAAQD,KAAKE,KAAK,CAAC;QAEzB;;;;;;KAMC,GACD,MAAMC,oBAAoB,CAACC,QAAaC,IAAI,CAAC;YAC3C,IAAID,UAAU,MAAM;gBAClB;YACF;YAEA,MAAME,MAAML,KAAK,CAACI,EAAE;YAEpB,yDAAyD;YACzD,IAAIA,MAAMJ,MAAMJ,MAAM,GAAG,GAAG;gBAC1B,kEAAkE;gBAClE,IAAIU,MAAMC,OAAO,CAACJ,SAAS;oBACzB,KAAK,MAAMK,QAAQL,OAAQ;wBACzB,IAAIK,QAAQ,OAAOA,SAAS,YAAYH,QAAQI,WAAW;4BACzD,OAAOD,IAAI,CAACH,IAAyB;wBACvC;oBACF;gBACF,OAAO,IAAI,OAAOF,WAAW,YAAYE,QAAQI,WAAW;oBAC1D,OAAON,MAAM,CAACE,IAAI;gBACpB;gBACA;YACF;YAEA,IAAIA,QAAQI,WAAW;gBACrB;YACF;YAEA,yCAAyC;YACzC,MAAMC,OAAOP,MAAM,CAACE,IAAI;YAExB,IAAIC,MAAMC,OAAO,CAACG,OAAO;gBACvB,wDAAwD;gBACxD,KAAK,MAAMF,QAAQE,KAAM;oBACvBR,kBAAkBM,MAAMJ,IAAI;gBAC9B;YACF,OAAO;gBACL,2CAA2C;gBAC3CF,kBAAkBQ,MAAMN,IAAI;YAC9B;QACF;QAEAF,kBAAkBL;IACpB;IAEA,OAAOA;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/removeDisabledFields.ts"],"sourcesContent":["/**\n * Recursively removes fields from a deeply nested object based on dot-notation paths.\n *\n * This utility supports removing:\n * - Nested fields in plain objects (e.g., \"group.value\")\n * - Fields inside arrays of objects (e.g., \"group.array.field1\")\n *\n * It safely traverses both object and array structures and avoids mutating the original input.\n *\n * @param obj - The original object to clean.\n * @param disabled - An array of dot-separated paths indicating which fields to remove.\n * @returns A deep clone of the original object with specified fields removed.\n */\n\nexport const removeDisabledFields = (\n obj: Record<string, unknown>,\n disabled: string[] = [],\n): Record<string, unknown> => {\n if (!disabled.length) {\n return obj\n }\n\n const clone = structuredClone(obj)\n\n // Process each disabled path independently\n for (const path of disabled) {\n const parts = path.split('.')\n\n /**\n * Recursively walks the object tree according to the dot path,\n * and deletes the field once the full path is reached.\n *\n * @param target - The current object or array being traversed\n * @param i - The index of the current path part\n */\n const removeRecursively = (target: unknown, i = 0): void => {\n if (target == null) {\n return\n }\n\n const key = parts[i]\n\n // If at the final part of the path, perform the deletion\n if (i === parts.length - 1) {\n // If the current level is an array, delete the key from each item\n if (Array.isArray(target)) {\n for (const item of target) {\n if (item && typeof item === 'object' && key !== undefined) {\n delete (item as Record<string, unknown>)[key]\n }\n }\n } else if (typeof target === 'object' && key !== undefined) {\n delete (target as Record<string, unknown>)[key]\n }\n return\n }\n\n if (key === undefined) {\n return\n }\n\n // Traverse to the next level in the path\n const next = (target as Record<string, unknown>)[key]\n\n if (Array.isArray(next)) {\n // If the next value is an array, recurse into each item\n for (const item of next) {\n removeRecursively(item, i + 1)\n }\n } else {\n // Otherwise, continue down the object path\n removeRecursively(next, i + 1)\n }\n }\n\n removeRecursively(clone)\n }\n\n return clone\n}\n"],"names":["removeDisabledFields","obj","disabled","length","clone","structuredClone","path","parts","split","removeRecursively","target","i","key","Array","isArray","item","undefined","next"],"mappings":"AAAA;;;;;;;;;;;;CAYC,GAED,OAAO,MAAMA,uBAAuB,CAClCC,KACAC,WAAqB,EAAE;IAEvB,IAAI,CAACA,SAASC,MAAM,EAAE;QACpB,OAAOF;IACT;IAEA,MAAMG,QAAQC,gBAAgBJ;IAE9B,2CAA2C;IAC3C,KAAK,MAAMK,QAAQJ,SAAU;QAC3B,MAAMK,QAAQD,KAAKE,KAAK,CAAC;QAEzB;;;;;;KAMC,GACD,MAAMC,oBAAoB,CAACC,QAAiBC,IAAI,CAAC;YAC/C,IAAID,UAAU,MAAM;gBAClB;YACF;YAEA,MAAME,MAAML,KAAK,CAACI,EAAE;YAEpB,yDAAyD;YACzD,IAAIA,MAAMJ,MAAMJ,MAAM,GAAG,GAAG;gBAC1B,kEAAkE;gBAClE,IAAIU,MAAMC,OAAO,CAACJ,SAAS;oBACzB,KAAK,MAAMK,QAAQL,OAAQ;wBACzB,IAAIK,QAAQ,OAAOA,SAAS,YAAYH,QAAQI,WAAW;4BACzD,OAAO,AAACD,IAAgC,CAACH,IAAI;wBAC/C;oBACF;gBACF,OAAO,IAAI,OAAOF,WAAW,YAAYE,QAAQI,WAAW;oBAC1D,OAAO,AAACN,MAAkC,CAACE,IAAI;gBACjD;gBACA;YACF;YAEA,IAAIA,QAAQI,WAAW;gBACrB;YACF;YAEA,yCAAyC;YACzC,MAAMC,OAAO,AAACP,MAAkC,CAACE,IAAI;YAErD,IAAIC,MAAMC,OAAO,CAACG,OAAO;gBACvB,wDAAwD;gBACxD,KAAK,MAAMF,QAAQE,KAAM;oBACvBR,kBAAkBM,MAAMJ,IAAI;gBAC9B;YACF,OAAO;gBACL,2CAA2C;gBAC3CF,kBAAkBQ,MAAMN,IAAI;YAC9B;QACF;QAEAF,kBAAkBL;IACpB;IAEA,OAAOA;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"setNestedValue.d.ts","sourceRoot":"","sources":["../../src/utilities/setNestedValue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,eAAO,MAAM,cAAc,QACpB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QACtB,MAAM,SACL,OAAO,KACb,IA0CF,CAAA"}
1
+ {"version":3,"file":"setNestedValue.d.ts","sourceRoot":"","sources":["../../src/utilities/setNestedValue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,eAAO,MAAM,cAAc,QACpB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,QACtB,MAAM,SACL,OAAO,KACb,IA8CF,CAAA"}
@@ -27,26 +27,28 @@
27
27
  if (!Array.isArray(current)) {
28
28
  current = [];
29
29
  }
30
+ const currentArray = current;
30
31
  // Ensure the array slot is initialized
31
- if (!current[index]) {
32
- current[index] = {};
32
+ if (!currentArray[index]) {
33
+ currentArray[index] = {};
33
34
  }
34
35
  if (isLast) {
35
- current[index] = value;
36
+ currentArray[index] = value;
36
37
  } else {
37
- current = current[index];
38
+ current = currentArray[index];
38
39
  }
39
40
  } else {
41
+ const currentObj = current;
40
42
  // Ensure the object key exists
41
43
  if (isLast) {
42
44
  if (typeof part === 'string') {
43
- current[part] = value;
45
+ currentObj[part] = value;
44
46
  }
45
47
  } else {
46
- if (typeof current[part] !== 'object' || current[part] === null) {
47
- current[part] = {};
48
+ if (typeof currentObj[part] !== 'object' || currentObj[part] === null) {
49
+ currentObj[part] = {};
48
50
  }
49
- current = current[part];
51
+ current = currentObj[part];
50
52
  }
51
53
  }
52
54
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/setNestedValue.ts"],"sourcesContent":["/**\n * Sets a value deeply into a nested object or array, based on a dot-notation path.\n *\n * This function:\n * - Supports array indexing (e.g., \"array.0.field1\")\n * - Creates intermediate arrays/objects as needed\n * - Mutates the target object directly\n *\n * @example\n * const obj = {}\n * setNestedValue(obj, 'group.array.0.field1', 'hello')\n * // Result: { group: { array: [ { field1: 'hello' } ] } }\n *\n * @param obj - The target object to mutate.\n * @param path - A dot-separated string path indicating where to assign the value.\n * @param value - The value to set at the specified path.\n */\n\nexport const setNestedValue = (\n obj: Record<string, unknown>,\n path: string,\n value: unknown,\n): void => {\n const parts = path.split('.')\n let current: any = obj\n\n for (let i = 0; i < parts.length; i++) {\n const part = parts[i]\n const isLast = i === parts.length - 1\n const isIndex = !Number.isNaN(Number(part))\n\n if (isIndex) {\n const index = Number(part)\n\n // Ensure the current target is an array\n if (!Array.isArray(current)) {\n current = []\n }\n\n // Ensure the array slot is initialized\n if (!current[index]) {\n current[index] = {}\n }\n\n if (isLast) {\n current[index] = value\n } else {\n current = current[index] as Record<string, unknown>\n }\n } else {\n // Ensure the object key exists\n if (isLast) {\n if (typeof part === 'string') {\n current[part] = value\n }\n } else {\n if (typeof current[part as string] !== 'object' || current[part as string] === null) {\n current[part as string] = {}\n }\n\n current = current[part as string] as Record<string, unknown>\n }\n }\n }\n}\n"],"names":["setNestedValue","obj","path","value","parts","split","current","i","length","part","isLast","isIndex","Number","isNaN","index","Array","isArray"],"mappings":"AAAA;;;;;;;;;;;;;;;;CAgBC,GAED,OAAO,MAAMA,iBAAiB,CAC5BC,KACAC,MACAC;IAEA,MAAMC,QAAQF,KAAKG,KAAK,CAAC;IACzB,IAAIC,UAAeL;IAEnB,IAAK,IAAIM,IAAI,GAAGA,IAAIH,MAAMI,MAAM,EAAED,IAAK;QACrC,MAAME,OAAOL,KAAK,CAACG,EAAE;QACrB,MAAMG,SAASH,MAAMH,MAAMI,MAAM,GAAG;QACpC,MAAMG,UAAU,CAACC,OAAOC,KAAK,CAACD,OAAOH;QAErC,IAAIE,SAAS;YACX,MAAMG,QAAQF,OAAOH;YAErB,wCAAwC;YACxC,IAAI,CAACM,MAAMC,OAAO,CAACV,UAAU;gBAC3BA,UAAU,EAAE;YACd;YAEA,uCAAuC;YACvC,IAAI,CAACA,OAAO,CAACQ,MAAM,EAAE;gBACnBR,OAAO,CAACQ,MAAM,GAAG,CAAC;YACpB;YAEA,IAAIJ,QAAQ;gBACVJ,OAAO,CAACQ,MAAM,GAAGX;YACnB,OAAO;gBACLG,UAAUA,OAAO,CAACQ,MAAM;YAC1B;QACF,OAAO;YACL,+BAA+B;YAC/B,IAAIJ,QAAQ;gBACV,IAAI,OAAOD,SAAS,UAAU;oBAC5BH,OAAO,CAACG,KAAK,GAAGN;gBAClB;YACF,OAAO;gBACL,IAAI,OAAOG,OAAO,CAACG,KAAe,KAAK,YAAYH,OAAO,CAACG,KAAe,KAAK,MAAM;oBACnFH,OAAO,CAACG,KAAe,GAAG,CAAC;gBAC7B;gBAEAH,UAAUA,OAAO,CAACG,KAAe;YACnC;QACF;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/setNestedValue.ts"],"sourcesContent":["/**\n * Sets a value deeply into a nested object or array, based on a dot-notation path.\n *\n * This function:\n * - Supports array indexing (e.g., \"array.0.field1\")\n * - Creates intermediate arrays/objects as needed\n * - Mutates the target object directly\n *\n * @example\n * const obj = {}\n * setNestedValue(obj, 'group.array.0.field1', 'hello')\n * // Result: { group: { array: [ { field1: 'hello' } ] } }\n *\n * @param obj - The target object to mutate.\n * @param path - A dot-separated string path indicating where to assign the value.\n * @param value - The value to set at the specified path.\n */\n\nexport const setNestedValue = (\n obj: Record<string, unknown>,\n path: string,\n value: unknown,\n): void => {\n const parts = path.split('.')\n let current: unknown = obj\n\n for (let i = 0; i < parts.length; i++) {\n const part = parts[i]\n const isLast = i === parts.length - 1\n const isIndex = !Number.isNaN(Number(part))\n\n if (isIndex) {\n const index = Number(part)\n\n // Ensure the current target is an array\n if (!Array.isArray(current)) {\n current = []\n }\n\n const currentArray = current as unknown[]\n\n // Ensure the array slot is initialized\n if (!currentArray[index]) {\n currentArray[index] = {}\n }\n\n if (isLast) {\n currentArray[index] = value\n } else {\n current = currentArray[index]\n }\n } else {\n const currentObj = current as Record<string, unknown>\n\n // Ensure the object key exists\n if (isLast) {\n if (typeof part === 'string') {\n currentObj[part] = value\n }\n } else {\n if (typeof currentObj[part as string] !== 'object' || currentObj[part as string] === null) {\n currentObj[part as string] = {}\n }\n\n current = currentObj[part as string]\n }\n }\n }\n}\n"],"names":["setNestedValue","obj","path","value","parts","split","current","i","length","part","isLast","isIndex","Number","isNaN","index","Array","isArray","currentArray","currentObj"],"mappings":"AAAA;;;;;;;;;;;;;;;;CAgBC,GAED,OAAO,MAAMA,iBAAiB,CAC5BC,KACAC,MACAC;IAEA,MAAMC,QAAQF,KAAKG,KAAK,CAAC;IACzB,IAAIC,UAAmBL;IAEvB,IAAK,IAAIM,IAAI,GAAGA,IAAIH,MAAMI,MAAM,EAAED,IAAK;QACrC,MAAME,OAAOL,KAAK,CAACG,EAAE;QACrB,MAAMG,SAASH,MAAMH,MAAMI,MAAM,GAAG;QACpC,MAAMG,UAAU,CAACC,OAAOC,KAAK,CAACD,OAAOH;QAErC,IAAIE,SAAS;YACX,MAAMG,QAAQF,OAAOH;YAErB,wCAAwC;YACxC,IAAI,CAACM,MAAMC,OAAO,CAACV,UAAU;gBAC3BA,UAAU,EAAE;YACd;YAEA,MAAMW,eAAeX;YAErB,uCAAuC;YACvC,IAAI,CAACW,YAAY,CAACH,MAAM,EAAE;gBACxBG,YAAY,CAACH,MAAM,GAAG,CAAC;YACzB;YAEA,IAAIJ,QAAQ;gBACVO,YAAY,CAACH,MAAM,GAAGX;YACxB,OAAO;gBACLG,UAAUW,YAAY,CAACH,MAAM;YAC/B;QACF,OAAO;YACL,MAAMI,aAAaZ;YAEnB,+BAA+B;YAC/B,IAAII,QAAQ;gBACV,IAAI,OAAOD,SAAS,UAAU;oBAC5BS,UAAU,CAACT,KAAK,GAAGN;gBACrB;YACF,OAAO;gBACL,IAAI,OAAOe,UAAU,CAACT,KAAe,KAAK,YAAYS,UAAU,CAACT,KAAe,KAAK,MAAM;oBACzFS,UAAU,CAACT,KAAe,GAAG,CAAC;gBAChC;gBAEAH,UAAUY,UAAU,CAACT,KAAe;YACtC;QACF;IACF;AACF,EAAC"}