@payloadcms/plugin-import-export 4.0.0-internal.af6aad0 → 4.0.0-internal.b8a92d2
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/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 +4 -2
- package/dist/utilities/getSelect.js.map +1 -1
- package/dist/utilities/setNestedValue.d.ts.map +1 -1
- package/dist/utilities/setNestedValue.js +20 -6
- package/dist/utilities/setNestedValue.js.map +1 -1
- package/package.json +8 -8
- 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/fieldPath.d.ts +0 -2
- package/dist/utilities/fieldPath.d.ts.map +0 -1
- package/dist/utilities/fieldPath.js +0 -8
- package/dist/utilities/fieldPath.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/getSelect.spec.js +0 -70
- package/dist/utilities/getSelect.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/setNestedValue.spec.js +0 -164
- package/dist/utilities/setNestedValue.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,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,UAAU;gBAAC;gBAAM;gBAAS;gBAAoB;gBAA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,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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/flattenObject.spec.ts"],"sourcesContent":["import { PayloadRequest } from 'payload'\n\nimport type { ExportFieldHookEntry } from '../types.js'\n\nimport { describe, expect, it, vi } from 'vitest'\n\nimport { flattenObject } from './flattenObject.js'\n\nconst mockReq = {\n payload: {\n logger: {\n error: vi.fn(),\n },\n },\n} as unknown as PayloadRequest\n\ndescribe('flattenObject parent + child traversal', () => {\n it('should run a parent group hook and still apply child field hooks against the transformed value', () => {\n const exportFieldHooks: 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 row = flattenObject({\n data: { meta: { slug: 'raw' } },\n exportFieldHooks,\n format: 'csv',\n req: mockReq,\n })\n\n expect(row.meta_slug).toBe('raw-from-parent-from-child')\n })\n\n it('should still recurse into children when the parent group hook returns undefined', () => {\n const childCalls: unknown[] = []\n const exportFieldHooks: Record<string, ExportFieldHookEntry> = {\n meta: {\n type: 'beforeExport',\n fn: () => undefined,\n },\n meta_slug: {\n type: 'beforeExport',\n fn: ({ value }) => {\n childCalls.push(value)\n return `${value}-from-child`\n },\n },\n }\n\n const row = flattenObject({\n data: { meta: { slug: 'raw' } },\n exportFieldHooks,\n format: 'csv',\n req: mockReq,\n })\n\n expect(childCalls).toEqual(['raw'])\n expect(row.meta_slug).toBe('raw-from-child')\n })\n\n it('should not recurse into children when the parent hook returns a primitive', () => {\n const childFn = vi.fn(({ value }: { value: unknown }) => `${value}-from-child`)\n const exportFieldHooks: 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 row = flattenObject({\n data: { meta: { slug: 'raw' } },\n exportFieldHooks,\n format: 'csv',\n req: mockReq,\n })\n\n expect(row.meta).toBe('serialized')\n expect(row.meta_slug).toBeUndefined()\n expect(childFn).not.toHaveBeenCalled()\n })\n\n 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', () => {\n const exportFieldHooks: Record<string, ExportFieldHookEntry> = {\n tag: {\n type: 'beforeExport',\n fn: () => undefined,\n },\n }\n\n const row = flattenObject({\n data: { tag_meta: 'sibling-set-first', tag: ['a', 'b'] },\n exportFieldHooks,\n format: 'csv',\n req: mockReq,\n })\n\n expect(row.tag_meta).toBe('sibling-set-first')\n expect(row.tag_0).toBe('a')\n expect(row.tag_1).toBe('b')\n })\n\n it('should run a parent array hook then child hooks for each item', () => {\n const exportFieldHooks: 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 row = flattenObject({\n data: { items: [{ note: 'a' }, { note: 'b' }] },\n exportFieldHooks,\n format: 'csv',\n req: mockReq,\n })\n\n expect(row.items_0_note).toBe('a-parent-child')\n expect(row.items_1_note).toBe('b-parent-child')\n })\n})\n"],"names":["describe","expect","it","vi","flattenObject","mockReq","payload","logger","error","fn","exportFieldHooks","meta","type","value","obj","slug","meta_slug","row","data","format","req","toBe","childCalls","undefined","push","toEqual","childFn","toBeUndefined","not","toHaveBeenCalled","tag","tag_meta","tag_0","tag_1","items","Array","isArray","map","item","note","items_note","items_0_note","items_1_note"],"mappings":"AAIA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,SAAQ;AAEjD,SAASC,aAAa,QAAQ,qBAAoB;AAElD,MAAMC,UAAU;IACdC,SAAS;QACPC,QAAQ;YACNC,OAAOL,GAAGM,EAAE;QACd;IACF;AACF;AAEAT,SAAS,0CAA0C;IACjDE,GAAG,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AEK,MAAM;oBAAI;oBAAG;wBAAEA,MAAM;oBAAI;iBAAE;YAAC;YAC9C7B;YACAS,QAAQ;YACRC,KAAKf;QACP;QAEAJ,OAAOgB,IAAIwB,YAAY,EAAEpB,IAAI,CAAC;QAC9BpB,OAAOgB,IAAIyB,YAAY,EAAErB,IAAI,CAAC;IAChC;AACF"}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { getExportFieldFunctions } from './getExportFieldFunctions.js';
|
|
3
|
-
describe('getExportFieldFunctions registration', ()=>{
|
|
4
|
-
it('should not collide bare-key entries when two same-named fields with built-in handlers exist in different positions', ()=>{
|
|
5
|
-
const fields = [
|
|
6
|
-
{
|
|
7
|
-
name: 'groupA',
|
|
8
|
-
type: 'group',
|
|
9
|
-
flattenedFields: [
|
|
10
|
-
{
|
|
11
|
-
name: 'data',
|
|
12
|
-
type: 'json'
|
|
13
|
-
}
|
|
14
|
-
]
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
name: 'groupB',
|
|
18
|
-
type: 'group',
|
|
19
|
-
flattenedFields: [
|
|
20
|
-
{
|
|
21
|
-
name: 'data',
|
|
22
|
-
type: 'json'
|
|
23
|
-
}
|
|
24
|
-
]
|
|
25
|
-
}
|
|
26
|
-
];
|
|
27
|
-
const result = getExportFieldFunctions({
|
|
28
|
-
fields
|
|
29
|
-
});
|
|
30
|
-
// Both nested paths must be registered (not overwritten by collision)
|
|
31
|
-
expect(result['groupA_data']).toBeDefined();
|
|
32
|
-
expect(result['groupB_data']).toBeDefined();
|
|
33
|
-
// No bare-key fallback should exist for nested fields — that's the bug
|
|
34
|
-
expect(result['data']).toBeUndefined();
|
|
35
|
-
});
|
|
36
|
-
it('should still register a top-level field at its name', ()=>{
|
|
37
|
-
const fields = [
|
|
38
|
-
{
|
|
39
|
-
name: 'topLevelData',
|
|
40
|
-
type: 'json'
|
|
41
|
-
}
|
|
42
|
-
];
|
|
43
|
-
const result = getExportFieldFunctions({
|
|
44
|
-
fields
|
|
45
|
-
});
|
|
46
|
-
expect(result['topLevelData']).toBeDefined();
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
//# sourceMappingURL=getExportFieldFunctions.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getExportFieldFunctions.spec.ts"],"sourcesContent":["import { FlattenedField } from 'payload'\n\nimport { describe, expect, it } from 'vitest'\n\nimport { getExportFieldFunctions } from './getExportFieldFunctions.js'\n\ndescribe('getExportFieldFunctions registration', () => {\n it('should not collide bare-key entries when two same-named fields with built-in handlers exist in different positions', () => {\n const fields: FlattenedField[] = [\n {\n name: 'groupA',\n type: 'group',\n flattenedFields: [{ name: 'data', type: 'json' } as FlattenedField],\n } as unknown as FlattenedField,\n {\n name: 'groupB',\n type: 'group',\n flattenedFields: [{ name: 'data', type: 'json' } as FlattenedField],\n } as unknown as FlattenedField,\n ]\n\n const result = getExportFieldFunctions({ fields })\n\n // Both nested paths must be registered (not overwritten by collision)\n expect(result['groupA_data']).toBeDefined()\n expect(result['groupB_data']).toBeDefined()\n\n // No bare-key fallback should exist for nested fields — that's the bug\n expect(result['data']).toBeUndefined()\n })\n\n it('should still register a top-level field at its name', () => {\n const fields: FlattenedField[] = [{ name: 'topLevelData', type: 'json' } as FlattenedField]\n\n const result = getExportFieldFunctions({ fields })\n\n expect(result['topLevelData']).toBeDefined()\n })\n})\n"],"names":["describe","expect","it","getExportFieldFunctions","fields","name","type","flattenedFields","result","toBeDefined","toBeUndefined"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,SAAQ;AAE7C,SAASC,uBAAuB,QAAQ,+BAA8B;AAEtEH,SAAS,wCAAwC;IAC/CE,GAAG,sHAAsH;QACvH,MAAME,SAA2B;YAC/B;gBACEC,MAAM;gBACNC,MAAM;gBACNC,iBAAiB;oBAAC;wBAAEF,MAAM;wBAAQC,MAAM;oBAAO;iBAAoB;YACrE;YACA;gBACED,MAAM;gBACNC,MAAM;gBACNC,iBAAiB;oBAAC;wBAAEF,MAAM;wBAAQC,MAAM;oBAAO;iBAAoB;YACrE;SACD;QAED,MAAME,SAASL,wBAAwB;YAAEC;QAAO;QAEhD,sEAAsE;QACtEH,OAAOO,MAAM,CAAC,cAAc,EAAEC,WAAW;QACzCR,OAAOO,MAAM,CAAC,cAAc,EAAEC,WAAW;QAEzC,uEAAuE;QACvER,OAAOO,MAAM,CAAC,OAAO,EAAEE,aAAa;IACtC;IAEAR,GAAG,uDAAuD;QACxD,MAAME,SAA2B;YAAC;gBAAEC,MAAM;gBAAgBC,MAAM;YAAO;SAAoB;QAE3F,MAAME,SAASL,wBAAwB;YAAEC;QAAO;QAEhDH,OAAOO,MAAM,CAAC,eAAe,EAAEC,WAAW;IAC5C;AACF"}
|
|
@@ -1,167 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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,QAAQ,SAAQ;AAEjD,SAASC,uBAAuB,QAAQ,+BAA8B;AAEtE,MAAMC,UAAU;IACdC,SAAS;QACPC,QAAQ;YACNC,OAAOL,GAAGM,EAAE;QACd;IACF;AACF;AAEA,MAAMC,WAAW,CACfC,OACAC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