payload 3.71.1 → 3.72.0-internal.3e70d4c
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/collections/config/sanitize.d.ts.map +1 -1
- package/dist/collections/config/sanitize.js +19 -4
- package/dist/collections/config/sanitize.js.map +1 -1
- package/dist/collections/endpoints/create.d.ts.map +1 -1
- package/dist/collections/endpoints/create.js +2 -1
- package/dist/collections/endpoints/create.js.map +1 -1
- package/dist/collections/endpoints/update.d.ts.map +1 -1
- package/dist/collections/endpoints/update.js +3 -1
- package/dist/collections/endpoints/update.js.map +1 -1
- package/dist/collections/endpoints/updateByID.d.ts.map +1 -1
- package/dist/collections/endpoints/updateByID.js +4 -2
- package/dist/collections/endpoints/updateByID.js.map +1 -1
- package/dist/collections/operations/create.d.ts +1 -0
- package/dist/collections/operations/create.d.ts.map +1 -1
- package/dist/collections/operations/create.js +23 -3
- package/dist/collections/operations/create.js.map +1 -1
- package/dist/collections/operations/local/create.d.ts +4 -0
- package/dist/collections/operations/local/create.d.ts.map +1 -1
- package/dist/collections/operations/local/create.js +2 -1
- package/dist/collections/operations/local/create.js.map +1 -1
- package/dist/collections/operations/local/update.d.ts +12 -0
- package/dist/collections/operations/local/update.d.ts.map +1 -1
- package/dist/collections/operations/local/update.js +3 -1
- package/dist/collections/operations/local/update.js.map +1 -1
- package/dist/collections/operations/update.d.ts +2 -0
- package/dist/collections/operations/update.d.ts.map +1 -1
- package/dist/collections/operations/update.js +4 -3
- package/dist/collections/operations/update.js.map +1 -1
- package/dist/collections/operations/updateByID.d.ts +2 -0
- package/dist/collections/operations/updateByID.d.ts.map +1 -1
- package/dist/collections/operations/updateByID.js +4 -3
- package/dist/collections/operations/updateByID.js.map +1 -1
- package/dist/collections/operations/utilities/update.d.ts +4 -3
- package/dist/collections/operations/utilities/update.d.ts.map +1 -1
- package/dist/collections/operations/utilities/update.js +81 -31
- package/dist/collections/operations/utilities/update.js.map +1 -1
- package/dist/config/types.d.ts +16 -0
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js.map +1 -1
- package/dist/database/migrations/templates/localizeStatus.d.ts +10 -0
- package/dist/database/migrations/templates/localizeStatus.d.ts.map +1 -0
- package/dist/database/migrations/templates/localizeStatus.js +54 -0
- package/dist/database/migrations/templates/localizeStatus.js.map +1 -0
- package/dist/exports/migrations.d.ts +19 -0
- package/dist/exports/migrations.d.ts.map +1 -0
- package/dist/exports/migrations.js +19 -0
- package/dist/exports/migrations.js.map +1 -0
- package/dist/exports/shared.d.ts +1 -1
- package/dist/exports/shared.d.ts.map +1 -1
- package/dist/exports/shared.js +1 -1
- package/dist/exports/shared.js.map +1 -1
- package/dist/globals/config/sanitize.d.ts.map +1 -1
- package/dist/globals/config/sanitize.js +11 -1
- package/dist/globals/config/sanitize.js.map +1 -1
- package/dist/globals/endpoints/update.d.ts.map +1 -1
- package/dist/globals/endpoints/update.js +5 -1
- package/dist/globals/endpoints/update.js.map +1 -1
- package/dist/globals/operations/local/update.d.ts +10 -0
- package/dist/globals/operations/local/update.d.ts.map +1 -1
- package/dist/globals/operations/local/update.js +4 -2
- package/dist/globals/operations/local/update.js.map +1 -1
- package/dist/globals/operations/update.d.ts +2 -0
- package/dist/globals/operations/update.d.ts.map +1 -1
- package/dist/globals/operations/update.js +63 -15
- package/dist/globals/operations/update.js.map +1 -1
- package/dist/index.bundled.d.ts +102 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/utilities/getVersionsConfig.d.ts +4 -0
- package/dist/utilities/getVersionsConfig.d.ts.map +1 -1
- package/dist/utilities/getVersionsConfig.js +7 -2
- package/dist/utilities/getVersionsConfig.js.map +1 -1
- package/dist/utilities/mergeLocalizedData.d.ts +20 -0
- package/dist/utilities/mergeLocalizedData.d.ts.map +1 -0
- package/dist/utilities/mergeLocalizedData.js +277 -0
- package/dist/utilities/mergeLocalizedData.js.map +1 -0
- package/dist/utilities/mergeLocalizedData.spec.js +784 -0
- package/dist/utilities/mergeLocalizedData.spec.js.map +1 -0
- package/dist/utilities/miniChalk.d.ts +15 -0
- package/dist/utilities/miniChalk.d.ts.map +1 -0
- package/dist/utilities/miniChalk.js +34 -0
- package/dist/utilities/miniChalk.js.map +1 -0
- package/dist/utilities/parseParams/index.d.ts +24 -20
- package/dist/utilities/parseParams/index.d.ts.map +1 -1
- package/dist/utilities/parseParams/index.js.map +1 -1
- package/dist/utilities/traverseForLocalizedFields.d.ts +3 -0
- package/dist/utilities/traverseForLocalizedFields.d.ts.map +1 -0
- package/dist/utilities/traverseForLocalizedFields.js +41 -0
- package/dist/utilities/traverseForLocalizedFields.js.map +1 -0
- package/dist/versions/baseFields.d.ts +3 -1
- package/dist/versions/baseFields.d.ts.map +1 -1
- package/dist/versions/baseFields.js +16 -15
- package/dist/versions/baseFields.js.map +1 -1
- package/dist/versions/drafts/replaceWithDraftIfAvailable.d.ts.map +1 -1
- package/dist/versions/drafts/replaceWithDraftIfAvailable.js +28 -2
- package/dist/versions/drafts/replaceWithDraftIfAvailable.js.map +1 -1
- package/dist/versions/migrations/localizeStatus/index.d.ts +12 -0
- package/dist/versions/migrations/localizeStatus/index.d.ts.map +1 -0
- package/dist/versions/migrations/localizeStatus/index.js +33 -0
- package/dist/versions/migrations/localizeStatus/index.js.map +1 -0
- package/dist/versions/migrations/localizeStatus/mongo/down.d.ts +9 -0
- package/dist/versions/migrations/localizeStatus/mongo/down.d.ts.map +1 -0
- package/dist/versions/migrations/localizeStatus/mongo/down.js +112 -0
- package/dist/versions/migrations/localizeStatus/mongo/down.js.map +1 -0
- package/dist/versions/migrations/localizeStatus/mongo/index.d.ts +8 -0
- package/dist/versions/migrations/localizeStatus/mongo/index.d.ts.map +1 -0
- package/dist/versions/migrations/localizeStatus/mongo/index.js +8 -0
- package/dist/versions/migrations/localizeStatus/mongo/index.js.map +1 -0
- package/dist/versions/migrations/localizeStatus/mongo/up.d.ts +9 -0
- package/dist/versions/migrations/localizeStatus/mongo/up.d.ts.map +1 -0
- package/dist/versions/migrations/localizeStatus/mongo/up.js +220 -0
- package/dist/versions/migrations/localizeStatus/mongo/up.js.map +1 -0
- package/dist/versions/migrations/localizeStatus/shared.d.ts +59 -0
- package/dist/versions/migrations/localizeStatus/shared.d.ts.map +1 -0
- package/dist/versions/migrations/localizeStatus/shared.js +122 -0
- package/dist/versions/migrations/localizeStatus/shared.js.map +1 -0
- package/dist/versions/migrations/localizeStatus/sql/down.d.ts +11 -0
- package/dist/versions/migrations/localizeStatus/sql/down.d.ts.map +1 -0
- package/dist/versions/migrations/localizeStatus/sql/down.js +213 -0
- package/dist/versions/migrations/localizeStatus/sql/down.js.map +1 -0
- package/dist/versions/migrations/localizeStatus/sql/index.d.ts +8 -0
- package/dist/versions/migrations/localizeStatus/sql/index.d.ts.map +1 -0
- package/dist/versions/migrations/localizeStatus/sql/index.js +8 -0
- package/dist/versions/migrations/localizeStatus/sql/index.js.map +1 -0
- package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.d.ts +13 -0
- package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.d.ts.map +1 -0
- package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.js +51 -0
- package/dist/versions/migrations/localizeStatus/sql/migrateMainCollection.js.map +1 -0
- package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.d.ts +13 -0
- package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.d.ts.map +1 -0
- package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.js +54 -0
- package/dist/versions/migrations/localizeStatus/sql/migrateMainGlobal.js.map +1 -0
- package/dist/versions/migrations/localizeStatus/sql/up.d.ts +11 -0
- package/dist/versions/migrations/localizeStatus/sql/up.d.ts.map +1 -0
- package/dist/versions/migrations/localizeStatus/sql/up.js +277 -0
- package/dist/versions/migrations/localizeStatus/sql/up.js.map +1 -0
- package/dist/versions/saveSnapshot.d.ts.map +1 -1
- package/dist/versions/saveSnapshot.js +0 -1
- package/dist/versions/saveSnapshot.js.map +1 -1
- package/dist/versions/saveVersion.js +0 -3
- package/dist/versions/saveVersion.js.map +1 -1
- package/dist/versions/types.d.ts +18 -0
- package/dist/versions/types.d.ts.map +1 -1
- package/dist/versions/types.js.map +1 -1
- package/package.json +7 -2
- package/dist/uploads/imageResizer.d.ts +0 -40
- package/dist/uploads/imageResizer.d.ts.map +0 -1
- package/dist/uploads/imageResizer.js +0 -356
- package/dist/uploads/imageResizer.js.map +0 -1
|
@@ -0,0 +1,784 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { mergeLocalizedData } from './mergeLocalizedData.js';
|
|
3
|
+
describe('mergeLocalizedData', ()=>{
|
|
4
|
+
const selectedLocales = [
|
|
5
|
+
'en'
|
|
6
|
+
];
|
|
7
|
+
const configBlockReferences = [];
|
|
8
|
+
describe('simple fields', ()=>{
|
|
9
|
+
it('should merge localized field values for selected locales', ()=>{
|
|
10
|
+
const fields = [
|
|
11
|
+
{
|
|
12
|
+
name: 'title',
|
|
13
|
+
type: 'text',
|
|
14
|
+
localized: true
|
|
15
|
+
}
|
|
16
|
+
];
|
|
17
|
+
const docWithLocales = {
|
|
18
|
+
title: {
|
|
19
|
+
en: 'English Title',
|
|
20
|
+
es: 'Spanish Title',
|
|
21
|
+
de: 'German Title'
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const dataWithLocales = {
|
|
25
|
+
title: {
|
|
26
|
+
en: 'Updated English Title',
|
|
27
|
+
es: 'Updated Spanish Title'
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const result = mergeLocalizedData({
|
|
31
|
+
configBlockReferences: [],
|
|
32
|
+
dataWithLocales,
|
|
33
|
+
docWithLocales,
|
|
34
|
+
fields,
|
|
35
|
+
selectedLocales
|
|
36
|
+
});
|
|
37
|
+
expect(result.title).toEqual({
|
|
38
|
+
en: 'Updated English Title',
|
|
39
|
+
es: 'Spanish Title',
|
|
40
|
+
de: 'German Title'
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
it('should keep doc value for non-localized fields', ()=>{
|
|
44
|
+
const fields = [
|
|
45
|
+
{
|
|
46
|
+
name: 'title',
|
|
47
|
+
type: 'text',
|
|
48
|
+
localized: false
|
|
49
|
+
}
|
|
50
|
+
];
|
|
51
|
+
const result = mergeLocalizedData({
|
|
52
|
+
configBlockReferences: [],
|
|
53
|
+
dataWithLocales: {
|
|
54
|
+
title: 'New Title'
|
|
55
|
+
},
|
|
56
|
+
docWithLocales: {
|
|
57
|
+
title: 'Old Title'
|
|
58
|
+
},
|
|
59
|
+
fields,
|
|
60
|
+
selectedLocales
|
|
61
|
+
});
|
|
62
|
+
expect(result.title).toBe('New Title');
|
|
63
|
+
const missingData = mergeLocalizedData({
|
|
64
|
+
configBlockReferences: [],
|
|
65
|
+
dataWithLocales: {},
|
|
66
|
+
docWithLocales: {
|
|
67
|
+
title: 'Old Title'
|
|
68
|
+
},
|
|
69
|
+
fields,
|
|
70
|
+
selectedLocales
|
|
71
|
+
});
|
|
72
|
+
expect(missingData.title).toBe('Old Title');
|
|
73
|
+
const updatedData = mergeLocalizedData({
|
|
74
|
+
configBlockReferences: [],
|
|
75
|
+
dataWithLocales: {
|
|
76
|
+
title: 'Updated Title'
|
|
77
|
+
},
|
|
78
|
+
docWithLocales: {},
|
|
79
|
+
fields,
|
|
80
|
+
selectedLocales
|
|
81
|
+
});
|
|
82
|
+
expect(updatedData.title).toBe('Updated Title');
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe('groups', ()=>{
|
|
86
|
+
it('should merge localized group with locale keys at top level', ()=>{
|
|
87
|
+
const fields = [
|
|
88
|
+
{
|
|
89
|
+
name: 'meta',
|
|
90
|
+
type: 'group',
|
|
91
|
+
localized: true,
|
|
92
|
+
fields: [
|
|
93
|
+
{
|
|
94
|
+
name: 'title',
|
|
95
|
+
type: 'text'
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: 'description',
|
|
99
|
+
type: 'text'
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
];
|
|
104
|
+
const docWithLocales = {
|
|
105
|
+
meta: {
|
|
106
|
+
en: {
|
|
107
|
+
title: 'EN Title',
|
|
108
|
+
description: 'EN Desc'
|
|
109
|
+
},
|
|
110
|
+
es: {
|
|
111
|
+
title: 'ES Title',
|
|
112
|
+
description: 'ES Desc'
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
const dataWithLocales = {
|
|
117
|
+
meta: {
|
|
118
|
+
en: {
|
|
119
|
+
title: 'Updated EN Title',
|
|
120
|
+
description: 'Updated EN Desc'
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const result = mergeLocalizedData({
|
|
125
|
+
configBlockReferences: [],
|
|
126
|
+
dataWithLocales,
|
|
127
|
+
docWithLocales,
|
|
128
|
+
fields,
|
|
129
|
+
selectedLocales
|
|
130
|
+
});
|
|
131
|
+
expect(result.meta).toEqual({
|
|
132
|
+
en: {
|
|
133
|
+
title: 'Updated EN Title',
|
|
134
|
+
description: 'Updated EN Desc'
|
|
135
|
+
},
|
|
136
|
+
es: {
|
|
137
|
+
title: 'ES Title',
|
|
138
|
+
description: 'ES Desc'
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
it('should handle non-localized group with localized children', ()=>{
|
|
143
|
+
const fields = [
|
|
144
|
+
{
|
|
145
|
+
name: 'meta',
|
|
146
|
+
type: 'group',
|
|
147
|
+
localized: false,
|
|
148
|
+
fields: [
|
|
149
|
+
{
|
|
150
|
+
name: 'title',
|
|
151
|
+
type: 'text',
|
|
152
|
+
localized: true
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
name: 'version',
|
|
156
|
+
type: 'number',
|
|
157
|
+
localized: false
|
|
158
|
+
}
|
|
159
|
+
]
|
|
160
|
+
}
|
|
161
|
+
];
|
|
162
|
+
const docWithLocales = {
|
|
163
|
+
meta: {
|
|
164
|
+
title: {
|
|
165
|
+
en: 'EN Title',
|
|
166
|
+
es: 'ES Title'
|
|
167
|
+
},
|
|
168
|
+
version: 1
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
const dataWithLocales = {
|
|
172
|
+
meta: {
|
|
173
|
+
title: {
|
|
174
|
+
en: 'Updated EN Title'
|
|
175
|
+
},
|
|
176
|
+
version: 2
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
const result = mergeLocalizedData({
|
|
180
|
+
configBlockReferences: [],
|
|
181
|
+
dataWithLocales,
|
|
182
|
+
docWithLocales,
|
|
183
|
+
fields,
|
|
184
|
+
selectedLocales
|
|
185
|
+
});
|
|
186
|
+
expect(result.meta).toEqual({
|
|
187
|
+
title: {
|
|
188
|
+
en: 'Updated EN Title',
|
|
189
|
+
es: 'ES Title'
|
|
190
|
+
},
|
|
191
|
+
version: 2
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
describe('arrays', ()=>{
|
|
196
|
+
it('should merge localized array with locale keys at top level', ()=>{
|
|
197
|
+
const fields = [
|
|
198
|
+
{
|
|
199
|
+
name: 'items',
|
|
200
|
+
type: 'array',
|
|
201
|
+
localized: true,
|
|
202
|
+
fields: [
|
|
203
|
+
{
|
|
204
|
+
name: 'name',
|
|
205
|
+
type: 'text'
|
|
206
|
+
}
|
|
207
|
+
]
|
|
208
|
+
}
|
|
209
|
+
];
|
|
210
|
+
const docWithLocales = {
|
|
211
|
+
items: {
|
|
212
|
+
en: [
|
|
213
|
+
{
|
|
214
|
+
name: 'EN Item 1'
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
name: 'EN Item 2'
|
|
218
|
+
}
|
|
219
|
+
],
|
|
220
|
+
es: [
|
|
221
|
+
{
|
|
222
|
+
name: 'ES Item 1'
|
|
223
|
+
}
|
|
224
|
+
]
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
const dataWithLocales = {
|
|
228
|
+
items: {
|
|
229
|
+
en: [
|
|
230
|
+
{
|
|
231
|
+
name: 'Updated EN Item 1'
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
name: 'Updated EN Item 2'
|
|
235
|
+
}
|
|
236
|
+
]
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
const result = mergeLocalizedData({
|
|
240
|
+
configBlockReferences: [],
|
|
241
|
+
dataWithLocales,
|
|
242
|
+
docWithLocales,
|
|
243
|
+
fields,
|
|
244
|
+
selectedLocales
|
|
245
|
+
});
|
|
246
|
+
expect(result.items).toEqual({
|
|
247
|
+
en: [
|
|
248
|
+
{
|
|
249
|
+
name: 'Updated EN Item 1'
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
name: 'Updated EN Item 2'
|
|
253
|
+
}
|
|
254
|
+
],
|
|
255
|
+
es: [
|
|
256
|
+
{
|
|
257
|
+
name: 'ES Item 1'
|
|
258
|
+
}
|
|
259
|
+
]
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
it('should handle non-localized array with localized children', ()=>{
|
|
263
|
+
const fields = [
|
|
264
|
+
{
|
|
265
|
+
name: 'items',
|
|
266
|
+
type: 'array',
|
|
267
|
+
localized: false,
|
|
268
|
+
fields: [
|
|
269
|
+
{
|
|
270
|
+
name: 'name',
|
|
271
|
+
type: 'text',
|
|
272
|
+
localized: true
|
|
273
|
+
}
|
|
274
|
+
]
|
|
275
|
+
}
|
|
276
|
+
];
|
|
277
|
+
const docWithLocales = {
|
|
278
|
+
items: [
|
|
279
|
+
{
|
|
280
|
+
name: {
|
|
281
|
+
en: 'EN Item 1',
|
|
282
|
+
es: 'ES Item 1'
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
name: {
|
|
287
|
+
en: 'EN Item 2',
|
|
288
|
+
es: 'ES Item 2'
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
]
|
|
292
|
+
};
|
|
293
|
+
const dataWithLocales = {
|
|
294
|
+
items: [
|
|
295
|
+
{
|
|
296
|
+
name: {
|
|
297
|
+
en: 'Updated EN Item 1'
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
name: {
|
|
302
|
+
en: 'Updated EN Item 2'
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
]
|
|
306
|
+
};
|
|
307
|
+
const result = mergeLocalizedData({
|
|
308
|
+
configBlockReferences: [],
|
|
309
|
+
dataWithLocales,
|
|
310
|
+
docWithLocales,
|
|
311
|
+
fields,
|
|
312
|
+
selectedLocales
|
|
313
|
+
});
|
|
314
|
+
expect(result.items).toEqual([
|
|
315
|
+
{
|
|
316
|
+
name: {
|
|
317
|
+
en: 'Updated EN Item 1',
|
|
318
|
+
es: 'ES Item 1'
|
|
319
|
+
}
|
|
320
|
+
},
|
|
321
|
+
{
|
|
322
|
+
name: {
|
|
323
|
+
en: 'Updated EN Item 2',
|
|
324
|
+
es: 'ES Item 2'
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
]);
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
describe('blocks', ()=>{
|
|
331
|
+
it('should merge localized blocks with locale keys at top level', ()=>{
|
|
332
|
+
const fields = [
|
|
333
|
+
{
|
|
334
|
+
name: 'content',
|
|
335
|
+
type: 'blocks',
|
|
336
|
+
localized: true,
|
|
337
|
+
blocks: [
|
|
338
|
+
{
|
|
339
|
+
slug: 'text',
|
|
340
|
+
fields: [
|
|
341
|
+
{
|
|
342
|
+
name: 'text',
|
|
343
|
+
type: 'text'
|
|
344
|
+
}
|
|
345
|
+
]
|
|
346
|
+
}
|
|
347
|
+
]
|
|
348
|
+
}
|
|
349
|
+
];
|
|
350
|
+
const docWithLocales = {
|
|
351
|
+
content: {
|
|
352
|
+
en: [
|
|
353
|
+
{
|
|
354
|
+
blockType: 'text',
|
|
355
|
+
text: 'EN Text'
|
|
356
|
+
}
|
|
357
|
+
],
|
|
358
|
+
es: [
|
|
359
|
+
{
|
|
360
|
+
blockType: 'text',
|
|
361
|
+
text: 'ES Text'
|
|
362
|
+
}
|
|
363
|
+
]
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
const dataWithLocales = {
|
|
367
|
+
content: {
|
|
368
|
+
en: [
|
|
369
|
+
{
|
|
370
|
+
blockType: 'text',
|
|
371
|
+
text: 'Updated EN Text'
|
|
372
|
+
}
|
|
373
|
+
]
|
|
374
|
+
}
|
|
375
|
+
};
|
|
376
|
+
const result = mergeLocalizedData({
|
|
377
|
+
configBlockReferences: [],
|
|
378
|
+
dataWithLocales,
|
|
379
|
+
docWithLocales,
|
|
380
|
+
fields,
|
|
381
|
+
selectedLocales
|
|
382
|
+
});
|
|
383
|
+
expect(result.content).toEqual({
|
|
384
|
+
en: [
|
|
385
|
+
{
|
|
386
|
+
blockType: 'text',
|
|
387
|
+
text: 'Updated EN Text'
|
|
388
|
+
}
|
|
389
|
+
],
|
|
390
|
+
es: [
|
|
391
|
+
{
|
|
392
|
+
blockType: 'text',
|
|
393
|
+
text: 'ES Text'
|
|
394
|
+
}
|
|
395
|
+
]
|
|
396
|
+
});
|
|
397
|
+
});
|
|
398
|
+
it('should handle blocks with nested arrays', ()=>{
|
|
399
|
+
const fields = [
|
|
400
|
+
{
|
|
401
|
+
name: 'content',
|
|
402
|
+
type: 'blocks',
|
|
403
|
+
localized: true,
|
|
404
|
+
blocks: [
|
|
405
|
+
{
|
|
406
|
+
slug: 'nested',
|
|
407
|
+
fields: [
|
|
408
|
+
{
|
|
409
|
+
name: 'items',
|
|
410
|
+
type: 'array',
|
|
411
|
+
fields: [
|
|
412
|
+
{
|
|
413
|
+
name: 'name',
|
|
414
|
+
type: 'text'
|
|
415
|
+
}
|
|
416
|
+
]
|
|
417
|
+
}
|
|
418
|
+
]
|
|
419
|
+
}
|
|
420
|
+
]
|
|
421
|
+
}
|
|
422
|
+
];
|
|
423
|
+
const docWithLocales = {
|
|
424
|
+
content: {
|
|
425
|
+
en: [
|
|
426
|
+
{
|
|
427
|
+
blockType: 'nested',
|
|
428
|
+
items: [
|
|
429
|
+
{
|
|
430
|
+
name: 'EN Item 1'
|
|
431
|
+
}
|
|
432
|
+
]
|
|
433
|
+
}
|
|
434
|
+
],
|
|
435
|
+
es: [
|
|
436
|
+
{
|
|
437
|
+
blockType: 'nested',
|
|
438
|
+
items: [
|
|
439
|
+
{
|
|
440
|
+
name: 'ES Item 1'
|
|
441
|
+
}
|
|
442
|
+
]
|
|
443
|
+
}
|
|
444
|
+
]
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
const dataWithLocales = {
|
|
448
|
+
content: {
|
|
449
|
+
en: [
|
|
450
|
+
{
|
|
451
|
+
blockType: 'nested',
|
|
452
|
+
items: [
|
|
453
|
+
{
|
|
454
|
+
name: 'Updated EN Item 1'
|
|
455
|
+
}
|
|
456
|
+
]
|
|
457
|
+
}
|
|
458
|
+
]
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
const result = mergeLocalizedData({
|
|
462
|
+
configBlockReferences: [],
|
|
463
|
+
dataWithLocales,
|
|
464
|
+
docWithLocales,
|
|
465
|
+
fields,
|
|
466
|
+
selectedLocales
|
|
467
|
+
});
|
|
468
|
+
expect(result.content).toEqual({
|
|
469
|
+
en: [
|
|
470
|
+
{
|
|
471
|
+
blockType: 'nested',
|
|
472
|
+
items: [
|
|
473
|
+
{
|
|
474
|
+
name: 'Updated EN Item 1'
|
|
475
|
+
}
|
|
476
|
+
]
|
|
477
|
+
}
|
|
478
|
+
],
|
|
479
|
+
es: [
|
|
480
|
+
{
|
|
481
|
+
blockType: 'nested',
|
|
482
|
+
items: [
|
|
483
|
+
{
|
|
484
|
+
name: 'ES Item 1'
|
|
485
|
+
}
|
|
486
|
+
]
|
|
487
|
+
}
|
|
488
|
+
]
|
|
489
|
+
});
|
|
490
|
+
});
|
|
491
|
+
});
|
|
492
|
+
describe('tabs', ()=>{
|
|
493
|
+
it('should merge localized named tabs with locale keys at top level', ()=>{
|
|
494
|
+
const fields = [
|
|
495
|
+
{
|
|
496
|
+
type: 'tabs',
|
|
497
|
+
tabs: [
|
|
498
|
+
{
|
|
499
|
+
name: 'meta',
|
|
500
|
+
localized: true,
|
|
501
|
+
fields: [
|
|
502
|
+
{
|
|
503
|
+
name: 'title',
|
|
504
|
+
type: 'text'
|
|
505
|
+
}
|
|
506
|
+
]
|
|
507
|
+
}
|
|
508
|
+
]
|
|
509
|
+
}
|
|
510
|
+
];
|
|
511
|
+
const docWithLocales = {
|
|
512
|
+
meta: {
|
|
513
|
+
en: {
|
|
514
|
+
title: 'EN Title'
|
|
515
|
+
},
|
|
516
|
+
es: {
|
|
517
|
+
title: 'ES Title'
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
const dataWithLocales = {
|
|
522
|
+
meta: {
|
|
523
|
+
en: {
|
|
524
|
+
title: 'Updated EN Title'
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
const result = mergeLocalizedData({
|
|
529
|
+
configBlockReferences: [],
|
|
530
|
+
dataWithLocales,
|
|
531
|
+
docWithLocales,
|
|
532
|
+
fields,
|
|
533
|
+
selectedLocales
|
|
534
|
+
});
|
|
535
|
+
expect(result.meta).toEqual({
|
|
536
|
+
en: {
|
|
537
|
+
title: 'Updated EN Title'
|
|
538
|
+
},
|
|
539
|
+
es: {
|
|
540
|
+
title: 'ES Title'
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
});
|
|
544
|
+
it('should handle unnamed tabs with localized fields', ()=>{
|
|
545
|
+
const fields = [
|
|
546
|
+
{
|
|
547
|
+
type: 'tabs',
|
|
548
|
+
tabs: [
|
|
549
|
+
{
|
|
550
|
+
label: 'tab1',
|
|
551
|
+
fields: [
|
|
552
|
+
{
|
|
553
|
+
name: 'title',
|
|
554
|
+
type: 'text',
|
|
555
|
+
localized: true
|
|
556
|
+
}
|
|
557
|
+
]
|
|
558
|
+
}
|
|
559
|
+
]
|
|
560
|
+
}
|
|
561
|
+
];
|
|
562
|
+
const docWithLocales = {
|
|
563
|
+
title: {
|
|
564
|
+
en: 'EN Title',
|
|
565
|
+
es: 'ES Title'
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
const dataWithLocales = {
|
|
569
|
+
title: {
|
|
570
|
+
en: 'Updated EN Title'
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
const result = mergeLocalizedData({
|
|
574
|
+
configBlockReferences: [],
|
|
575
|
+
dataWithLocales,
|
|
576
|
+
docWithLocales,
|
|
577
|
+
fields,
|
|
578
|
+
selectedLocales
|
|
579
|
+
});
|
|
580
|
+
expect(result.title).toEqual({
|
|
581
|
+
en: 'Updated EN Title',
|
|
582
|
+
es: 'ES Title'
|
|
583
|
+
});
|
|
584
|
+
});
|
|
585
|
+
});
|
|
586
|
+
describe('deeply nested structures', ()=>{
|
|
587
|
+
it('should handle multiple levels of nesting with locale keys only at topmost localized field', ()=>{
|
|
588
|
+
const fields = [
|
|
589
|
+
{
|
|
590
|
+
name: 'outer',
|
|
591
|
+
type: 'group',
|
|
592
|
+
localized: true,
|
|
593
|
+
fields: [
|
|
594
|
+
{
|
|
595
|
+
name: 'inner',
|
|
596
|
+
type: 'group',
|
|
597
|
+
localized: false,
|
|
598
|
+
fields: [
|
|
599
|
+
{
|
|
600
|
+
name: 'items',
|
|
601
|
+
type: 'array',
|
|
602
|
+
localized: false,
|
|
603
|
+
fields: [
|
|
604
|
+
{
|
|
605
|
+
name: 'text',
|
|
606
|
+
type: 'text',
|
|
607
|
+
localized: false
|
|
608
|
+
}
|
|
609
|
+
]
|
|
610
|
+
}
|
|
611
|
+
]
|
|
612
|
+
}
|
|
613
|
+
]
|
|
614
|
+
}
|
|
615
|
+
];
|
|
616
|
+
const docWithLocales = {
|
|
617
|
+
outer: {
|
|
618
|
+
en: {
|
|
619
|
+
inner: {
|
|
620
|
+
items: [
|
|
621
|
+
{
|
|
622
|
+
text: 'EN Item 1'
|
|
623
|
+
}
|
|
624
|
+
]
|
|
625
|
+
}
|
|
626
|
+
},
|
|
627
|
+
es: {
|
|
628
|
+
inner: {
|
|
629
|
+
items: [
|
|
630
|
+
{
|
|
631
|
+
text: 'ES Item 1'
|
|
632
|
+
}
|
|
633
|
+
]
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
const dataWithLocales = {
|
|
639
|
+
outer: {
|
|
640
|
+
en: {
|
|
641
|
+
inner: {
|
|
642
|
+
items: [
|
|
643
|
+
{
|
|
644
|
+
text: 'Updated EN Item 1'
|
|
645
|
+
}
|
|
646
|
+
]
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
};
|
|
651
|
+
const result = mergeLocalizedData({
|
|
652
|
+
configBlockReferences: [],
|
|
653
|
+
dataWithLocales,
|
|
654
|
+
docWithLocales,
|
|
655
|
+
fields,
|
|
656
|
+
selectedLocales
|
|
657
|
+
});
|
|
658
|
+
expect(result.outer).toEqual({
|
|
659
|
+
en: {
|
|
660
|
+
inner: {
|
|
661
|
+
items: [
|
|
662
|
+
{
|
|
663
|
+
text: 'Updated EN Item 1'
|
|
664
|
+
}
|
|
665
|
+
]
|
|
666
|
+
}
|
|
667
|
+
},
|
|
668
|
+
es: {
|
|
669
|
+
inner: {
|
|
670
|
+
items: [
|
|
671
|
+
{
|
|
672
|
+
text: 'ES Item 1'
|
|
673
|
+
}
|
|
674
|
+
]
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
});
|
|
678
|
+
});
|
|
679
|
+
});
|
|
680
|
+
describe('multiple selected locales', ()=>{
|
|
681
|
+
it('should merge multiple locales when selected', ()=>{
|
|
682
|
+
const fields = [
|
|
683
|
+
{
|
|
684
|
+
name: 'title',
|
|
685
|
+
type: 'text',
|
|
686
|
+
localized: true
|
|
687
|
+
}
|
|
688
|
+
];
|
|
689
|
+
const docWithLocales = {
|
|
690
|
+
title: {
|
|
691
|
+
en: 'EN Title',
|
|
692
|
+
es: 'ES Title',
|
|
693
|
+
de: 'DE Title',
|
|
694
|
+
fr: 'FR Title'
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
const dataWithLocales = {
|
|
698
|
+
title: {
|
|
699
|
+
en: 'Updated EN Title',
|
|
700
|
+
es: 'Updated ES Title'
|
|
701
|
+
}
|
|
702
|
+
};
|
|
703
|
+
const result = mergeLocalizedData({
|
|
704
|
+
configBlockReferences: [],
|
|
705
|
+
dataWithLocales,
|
|
706
|
+
docWithLocales,
|
|
707
|
+
fields,
|
|
708
|
+
selectedLocales: [
|
|
709
|
+
'en',
|
|
710
|
+
'es'
|
|
711
|
+
]
|
|
712
|
+
});
|
|
713
|
+
expect(result.title).toEqual({
|
|
714
|
+
en: 'Updated EN Title',
|
|
715
|
+
es: 'Updated ES Title',
|
|
716
|
+
de: 'DE Title',
|
|
717
|
+
fr: 'FR Title'
|
|
718
|
+
});
|
|
719
|
+
});
|
|
720
|
+
});
|
|
721
|
+
describe('pass through fields, rows, collapsibles, unnamed tabs, unnamed groups', ()=>{
|
|
722
|
+
it('should not lose merged locale data when processing unnamed tabs', ()=>{
|
|
723
|
+
const fields = [
|
|
724
|
+
{
|
|
725
|
+
name: 'title',
|
|
726
|
+
type: 'text',
|
|
727
|
+
localized: true
|
|
728
|
+
},
|
|
729
|
+
{
|
|
730
|
+
type: 'tabs',
|
|
731
|
+
tabs: [
|
|
732
|
+
{
|
|
733
|
+
label: 'Other Fields',
|
|
734
|
+
fields: [
|
|
735
|
+
{
|
|
736
|
+
name: 'description',
|
|
737
|
+
type: 'text',
|
|
738
|
+
localized: true
|
|
739
|
+
}
|
|
740
|
+
]
|
|
741
|
+
}
|
|
742
|
+
]
|
|
743
|
+
}
|
|
744
|
+
];
|
|
745
|
+
const docWithLocales = {
|
|
746
|
+
title: {
|
|
747
|
+
en: 'English Title'
|
|
748
|
+
},
|
|
749
|
+
description: {
|
|
750
|
+
en: 'English Description'
|
|
751
|
+
}
|
|
752
|
+
};
|
|
753
|
+
const dataWithLocales = {
|
|
754
|
+
title: {
|
|
755
|
+
en: 'English Title',
|
|
756
|
+
es: 'Spanish Title'
|
|
757
|
+
},
|
|
758
|
+
description: {
|
|
759
|
+
en: 'English Description',
|
|
760
|
+
es: 'Spanish Description'
|
|
761
|
+
}
|
|
762
|
+
};
|
|
763
|
+
const result = mergeLocalizedData({
|
|
764
|
+
configBlockReferences: [],
|
|
765
|
+
dataWithLocales,
|
|
766
|
+
docWithLocales,
|
|
767
|
+
fields,
|
|
768
|
+
selectedLocales: [
|
|
769
|
+
'es'
|
|
770
|
+
]
|
|
771
|
+
});
|
|
772
|
+
expect(result.title).toEqual({
|
|
773
|
+
en: 'English Title',
|
|
774
|
+
es: 'Spanish Title'
|
|
775
|
+
});
|
|
776
|
+
expect(result.description).toEqual({
|
|
777
|
+
en: 'English Description',
|
|
778
|
+
es: 'Spanish Description'
|
|
779
|
+
});
|
|
780
|
+
});
|
|
781
|
+
});
|
|
782
|
+
});
|
|
783
|
+
|
|
784
|
+
//# sourceMappingURL=mergeLocalizedData.spec.js.map
|