@jungvonmatt/contentful-migrations 6.2.5 → 7.0.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.
- package/README.md +22 -11
- package/cli.js +314 -171
- package/index.d.ts +9 -9
- package/lib/backend.js +155 -107
- package/lib/content.js +5 -5
- package/lib/contentful.js +90 -43
- package/lib/diff.js +46 -32
- package/lib/helpers/locale.d.ts +3 -3
- package/lib/helpers/validation.d.ts +94 -15
- package/lib/helpers/validation.js +4 -4
- package/lib/migration.js +68 -51
- package/package.json +54 -117
- package/lib/helpers/validation.test.js +0 -381
- package/lib/helpers/validation.utils.test.js +0 -45
|
@@ -1,381 +0,0 @@
|
|
|
1
|
-
const { getValidationHelpers } = require('./validation');
|
|
2
|
-
|
|
3
|
-
describe('getValidationHelpers', () => {
|
|
4
|
-
const getTestContentType = () => ({
|
|
5
|
-
fields: [
|
|
6
|
-
{
|
|
7
|
-
id: 'selectWithOtherValidationProps',
|
|
8
|
-
type: 'Text',
|
|
9
|
-
validations: [
|
|
10
|
-
{
|
|
11
|
-
foo: 'test',
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
in: ['foo', 'bar', 'baz'],
|
|
15
|
-
message: 'Some message',
|
|
16
|
-
},
|
|
17
|
-
],
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
id: 'select',
|
|
21
|
-
type: 'Text',
|
|
22
|
-
validations: [
|
|
23
|
-
{
|
|
24
|
-
in: ['foo', 'bar', 'baz'],
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
id: 'reference',
|
|
30
|
-
type: 'Text',
|
|
31
|
-
validations: [
|
|
32
|
-
{
|
|
33
|
-
linkContentType: ['foo', 'bar', 'baz'],
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
id: 'string',
|
|
39
|
-
type: 'Text',
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
id: 'string-array',
|
|
43
|
-
type: 'Array',
|
|
44
|
-
items: [],
|
|
45
|
-
},
|
|
46
|
-
{
|
|
47
|
-
id: 'richTextNoValidations',
|
|
48
|
-
type: 'RichText',
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
id: 'richTextFullValidations',
|
|
52
|
-
type: 'RichText',
|
|
53
|
-
validations: [
|
|
54
|
-
{
|
|
55
|
-
enabledMarks: ['bold', 'italic'],
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
enabledNodeTypes: [
|
|
59
|
-
'blockquote',
|
|
60
|
-
'embedded-entry-block',
|
|
61
|
-
'hyperlink',
|
|
62
|
-
'entry-hyperlink',
|
|
63
|
-
'embedded-entry-inline',
|
|
64
|
-
],
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
nodes: {
|
|
68
|
-
'embedded-entry-block': [
|
|
69
|
-
{
|
|
70
|
-
linkContentType: ['foo', 'baz'],
|
|
71
|
-
},
|
|
72
|
-
],
|
|
73
|
-
'embedded-entry-inline': [
|
|
74
|
-
{
|
|
75
|
-
linkContentType: ['foo'],
|
|
76
|
-
},
|
|
77
|
-
],
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
const context = {
|
|
86
|
-
makeRequest: () => Promise.resolve(getTestContentType()),
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
let resultValidation;
|
|
90
|
-
|
|
91
|
-
const migration = {
|
|
92
|
-
editContentType: () => ({
|
|
93
|
-
editField: () => ({
|
|
94
|
-
validations: (validationObject) => {
|
|
95
|
-
resultValidation = validationObject;
|
|
96
|
-
},
|
|
97
|
-
}),
|
|
98
|
-
}),
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
beforeEach(() => {
|
|
102
|
-
resultValidation = undefined;
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
describe('addInValues', () => {
|
|
106
|
-
it('should add values at the end', async () => {
|
|
107
|
-
const validations = getValidationHelpers(migration, context);
|
|
108
|
-
await validations.addInValues('some-content-type', 'selectWithOtherValidationProps', 'bat');
|
|
109
|
-
expect(resultValidation).toEqual([
|
|
110
|
-
{
|
|
111
|
-
foo: 'test',
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
in: ['foo', 'bar', 'baz', 'bat'],
|
|
115
|
-
message: 'Some message',
|
|
116
|
-
},
|
|
117
|
-
]);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('should only add new values', async () => {
|
|
121
|
-
const validations = getValidationHelpers(migration, context);
|
|
122
|
-
await validations.addInValues('some-content-type', 'select', ['bat', 'foo', 'test']);
|
|
123
|
-
expect(resultValidation).toEqual([
|
|
124
|
-
{
|
|
125
|
-
in: ['foo', 'bar', 'baz', 'bat', 'test'],
|
|
126
|
-
},
|
|
127
|
-
]);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('should add new values sorted', async () => {
|
|
131
|
-
const validations = getValidationHelpers(migration, context);
|
|
132
|
-
await validations.addInValues('some-content-type', 'select', ['bat', 'foo', 'test'], { mode: 'sorted' });
|
|
133
|
-
expect(resultValidation).toEqual([
|
|
134
|
-
{
|
|
135
|
-
in: ['bar', 'bat', 'baz', 'foo', 'test'],
|
|
136
|
-
},
|
|
137
|
-
]);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('should add values where none where defined', async () => {
|
|
141
|
-
const validations = getValidationHelpers(migration, context);
|
|
142
|
-
await validations.addInValues('some-content-type', 'string', 'foo');
|
|
143
|
-
expect(resultValidation).toEqual([
|
|
144
|
-
{
|
|
145
|
-
in: ['foo'],
|
|
146
|
-
},
|
|
147
|
-
]);
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe('removeInValues', () => {
|
|
152
|
-
it('should remove values', async () => {
|
|
153
|
-
const validations = getValidationHelpers(migration, context);
|
|
154
|
-
await validations.removeInValues('some-content-type', 'select', ['foo', 'baz']);
|
|
155
|
-
expect(resultValidation).toEqual([
|
|
156
|
-
{
|
|
157
|
-
in: ['bar'],
|
|
158
|
-
},
|
|
159
|
-
]);
|
|
160
|
-
});
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
describe('modifyInValues', () => {
|
|
164
|
-
it('should modify values with custom function', async () => {
|
|
165
|
-
const validations = getValidationHelpers(migration, context);
|
|
166
|
-
await validations.modifyInValues('some-content-type', 'select', (values) => {
|
|
167
|
-
const result = values.slice(0, values.length - 1); // remove bar
|
|
168
|
-
result.push('test');
|
|
169
|
-
return result;
|
|
170
|
-
});
|
|
171
|
-
expect(resultValidation).toEqual([
|
|
172
|
-
{
|
|
173
|
-
in: ['foo', 'bar', 'test'],
|
|
174
|
-
},
|
|
175
|
-
]);
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
describe('addLinkContentTypeValues', () => {
|
|
180
|
-
it('should add values at the end', async () => {
|
|
181
|
-
const validations = getValidationHelpers(migration, context);
|
|
182
|
-
await validations.addLinkContentTypeValues('some-content-type', 'reference', 'bat');
|
|
183
|
-
expect(resultValidation).toEqual([
|
|
184
|
-
{
|
|
185
|
-
linkContentType: ['foo', 'bar', 'baz', 'bat'],
|
|
186
|
-
},
|
|
187
|
-
]);
|
|
188
|
-
});
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
describe('removeLinkContentTypeValues', () => {
|
|
192
|
-
it('should remove values', async () => {
|
|
193
|
-
const validations = getValidationHelpers(migration, context);
|
|
194
|
-
await validations.removeLinkContentTypeValues('some-content-type', 'reference', ['foo', 'baz']);
|
|
195
|
-
expect(resultValidation).toEqual([
|
|
196
|
-
{
|
|
197
|
-
linkContentType: ['bar'],
|
|
198
|
-
},
|
|
199
|
-
]);
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
describe('modifyLinkContentTypeValues', () => {
|
|
204
|
-
it('should modify unique values with custom function', async () => {
|
|
205
|
-
const validations = getValidationHelpers(migration, context);
|
|
206
|
-
await validations.modifyLinkContentTypeValues('some-content-type', 'reference', (values) => {
|
|
207
|
-
const result = values.slice(0, values.length - 1); // remove bar
|
|
208
|
-
result.push('test');
|
|
209
|
-
result.push('foo'); // should be removed since it exists
|
|
210
|
-
return result;
|
|
211
|
-
});
|
|
212
|
-
expect(resultValidation).toEqual([
|
|
213
|
-
{
|
|
214
|
-
linkContentType: ['foo', 'bar', 'test'],
|
|
215
|
-
},
|
|
216
|
-
]);
|
|
217
|
-
});
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
describe('richText', () => {
|
|
221
|
-
describe('addEnabledMarksValue', () => {
|
|
222
|
-
it('should add values at the end', async () => {
|
|
223
|
-
const validations = getValidationHelpers(migration, context);
|
|
224
|
-
await validations.richText.addEnabledMarksValues('some-content-type', 'richTextFullValidations', 'code');
|
|
225
|
-
expect(resultValidation).toContainEqual({
|
|
226
|
-
enabledMarks: ['bold', 'italic', 'code'],
|
|
227
|
-
});
|
|
228
|
-
});
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
describe('removeEnabledMarksValue', () => {
|
|
232
|
-
it('should remove values', async () => {
|
|
233
|
-
const validations = getValidationHelpers(migration, context);
|
|
234
|
-
await validations.richText.removeEnabledMarksValues('some-content-type', 'richTextFullValidations', 'bold');
|
|
235
|
-
expect(resultValidation).toContainEqual({
|
|
236
|
-
enabledMarks: ['italic'],
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
describe('modifyEnabledMarksValue', () => {
|
|
242
|
-
it('should modify unique values with custom function', async () => {
|
|
243
|
-
const validations = getValidationHelpers(migration, context);
|
|
244
|
-
await validations.richText.modifyEnabledMarksValues(
|
|
245
|
-
'some-content-type',
|
|
246
|
-
'richTextFullValidations',
|
|
247
|
-
(values) => {
|
|
248
|
-
const result = values.slice(0, values.length - 1); // remove italic
|
|
249
|
-
result.push('code');
|
|
250
|
-
result.push('bold'); // should be removed since it exists
|
|
251
|
-
return result;
|
|
252
|
-
}
|
|
253
|
-
);
|
|
254
|
-
expect(resultValidation).toContainEqual({
|
|
255
|
-
enabledMarks: ['bold', 'code'],
|
|
256
|
-
});
|
|
257
|
-
});
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
describe('addEnabledNodeTypeValue', () => {
|
|
261
|
-
it('should add values at the end', async () => {
|
|
262
|
-
const validations = getValidationHelpers(migration, context);
|
|
263
|
-
await validations.richText.addEnabledNodeTypeValues('some-content-type', 'richTextFullValidations', 'hr');
|
|
264
|
-
expect(resultValidation).toContainEqual({
|
|
265
|
-
enabledNodeTypes: [
|
|
266
|
-
'blockquote',
|
|
267
|
-
'embedded-entry-block',
|
|
268
|
-
'hyperlink',
|
|
269
|
-
'entry-hyperlink',
|
|
270
|
-
'embedded-entry-inline',
|
|
271
|
-
'hr',
|
|
272
|
-
],
|
|
273
|
-
});
|
|
274
|
-
});
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
describe('removeEnabledNodeTypeValue', () => {
|
|
278
|
-
it('should remove values', async () => {
|
|
279
|
-
const validations = getValidationHelpers(migration, context);
|
|
280
|
-
await validations.richText.removeEnabledNodeTypeValues(
|
|
281
|
-
'some-content-type',
|
|
282
|
-
'richTextFullValidations',
|
|
283
|
-
'blockquote'
|
|
284
|
-
);
|
|
285
|
-
expect(resultValidation).toContainEqual({
|
|
286
|
-
enabledNodeTypes: ['embedded-entry-block', 'hyperlink', 'entry-hyperlink', 'embedded-entry-inline'],
|
|
287
|
-
});
|
|
288
|
-
});
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
describe('modifyEnabledNodeTypeValue', () => {
|
|
292
|
-
it('should modify unique values with custom function', async () => {
|
|
293
|
-
const validations = getValidationHelpers(migration, context);
|
|
294
|
-
await validations.richText.modifyEnabledNodeTypeValues(
|
|
295
|
-
'some-content-type',
|
|
296
|
-
'richTextFullValidations',
|
|
297
|
-
(values) => {
|
|
298
|
-
const result = values.slice(0, values.length - 1); // remove embedded-entry-inline
|
|
299
|
-
result.push('hr');
|
|
300
|
-
result.push('blockquote'); // should be removed since it exists
|
|
301
|
-
return result;
|
|
302
|
-
}
|
|
303
|
-
);
|
|
304
|
-
expect(resultValidation).toContainEqual({
|
|
305
|
-
enabledNodeTypes: ['blockquote', 'embedded-entry-block', 'hyperlink', 'entry-hyperlink', 'hr'],
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
describe('addNodeContentTypeValues', () => {
|
|
311
|
-
it('should add values at the end', async () => {
|
|
312
|
-
const validations = getValidationHelpers(migration, context);
|
|
313
|
-
await validations.richText.addNodeContentTypeValues(
|
|
314
|
-
'some-content-type',
|
|
315
|
-
'richTextFullValidations',
|
|
316
|
-
'embedded-entry-block',
|
|
317
|
-
'bar'
|
|
318
|
-
);
|
|
319
|
-
expect(resultValidation.find((v) => v.nodes).nodes['embedded-entry-block']).toEqual([
|
|
320
|
-
{
|
|
321
|
-
linkContentType: ['foo', 'baz', 'bar'],
|
|
322
|
-
},
|
|
323
|
-
]);
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
it('should add complete entry if not existing', async () => {
|
|
327
|
-
const validations = getValidationHelpers(migration, context);
|
|
328
|
-
await validations.richText.addNodeContentTypeValues(
|
|
329
|
-
'some-content-type',
|
|
330
|
-
'richTextFullValidations',
|
|
331
|
-
'entry-hyperlink',
|
|
332
|
-
'bar'
|
|
333
|
-
);
|
|
334
|
-
expect(resultValidation.find((v) => v.nodes).nodes['entry-hyperlink']).toEqual([
|
|
335
|
-
{
|
|
336
|
-
linkContentType: ['bar'],
|
|
337
|
-
},
|
|
338
|
-
]);
|
|
339
|
-
});
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
describe('removeNodeContentTypeValues', () => {
|
|
343
|
-
it('should remove values', async () => {
|
|
344
|
-
const validations = getValidationHelpers(migration, context);
|
|
345
|
-
await validations.richText.removeNodeContentTypeValues(
|
|
346
|
-
'some-content-type',
|
|
347
|
-
'richTextFullValidations',
|
|
348
|
-
'embedded-entry-block',
|
|
349
|
-
'foo'
|
|
350
|
-
);
|
|
351
|
-
expect(resultValidation.find((v) => v.nodes).nodes['embedded-entry-block']).toEqual([
|
|
352
|
-
{
|
|
353
|
-
linkContentType: ['baz'],
|
|
354
|
-
},
|
|
355
|
-
]);
|
|
356
|
-
});
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
describe('modifyNodeContentTypeValues', () => {
|
|
360
|
-
it('should modify unique values with custom function', async () => {
|
|
361
|
-
const validations = getValidationHelpers(migration, context);
|
|
362
|
-
await validations.richText.modifyNodeContentTypeValues(
|
|
363
|
-
'some-content-type',
|
|
364
|
-
'richTextFullValidations',
|
|
365
|
-
'embedded-entry-block',
|
|
366
|
-
(values) => {
|
|
367
|
-
const result = values.slice(0, values.length - 1); // remove foo
|
|
368
|
-
result.push('bar');
|
|
369
|
-
result.push('baz'); // should be removed since it exists
|
|
370
|
-
return result;
|
|
371
|
-
}
|
|
372
|
-
);
|
|
373
|
-
expect(resultValidation.find((v) => v.nodes).nodes['embedded-entry-block']).toEqual([
|
|
374
|
-
{
|
|
375
|
-
linkContentType: ['foo', 'bar', 'baz'],
|
|
376
|
-
},
|
|
377
|
-
]);
|
|
378
|
-
});
|
|
379
|
-
});
|
|
380
|
-
});
|
|
381
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
const { addOrdered, addValues, unique } = require('./validation.utils');
|
|
2
|
-
|
|
3
|
-
describe('unique', () => {
|
|
4
|
-
it('should remove duplicates', async () => {
|
|
5
|
-
expect(unique(['foo', 'bar', 'foo', 'baz', 'bar'])).toEqual(['foo', 'bar', 'baz']);
|
|
6
|
-
});
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
describe('addOrdered', () => {
|
|
10
|
-
const a1 = ['foo', 'bar'];
|
|
11
|
-
const a2 = ['baz', 'bar', 'bat'];
|
|
12
|
-
|
|
13
|
-
it('should add unique values and order the list', async () => {
|
|
14
|
-
expect(addOrdered(a1, a2)).toEqual(['bar', 'bat', 'baz', 'foo']);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
describe('addValues', () => {
|
|
19
|
-
const a1 = ['foo', 'bar', 'test'];
|
|
20
|
-
const a2 = ['baz', 'bar', 'bat'];
|
|
21
|
-
|
|
22
|
-
it('should add values sorted', async () => {
|
|
23
|
-
expect(addValues(a1, a2, { mode: 'sorted' })).toEqual(['bar', 'bat', 'baz', 'foo', 'test']);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it('should add values at start', async () => {
|
|
27
|
-
expect(addValues(a1, a2, { mode: 'start' })).toEqual(['baz', 'bar', 'bat', 'foo', 'test']);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('should add values at end', async () => {
|
|
31
|
-
expect(addValues(a1, a2, { mode: 'end' })).toEqual(['foo', 'bar', 'test', 'baz', 'bat']);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should add values before', async () => {
|
|
35
|
-
expect(addValues(a1, a2, { mode: 'before', ref: 'bar' })).toEqual(['foo', 'baz', 'bar', 'bat', 'test']);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('should add values before fallback', async () => {
|
|
39
|
-
expect(addValues(a1, a2, { mode: 'before', ref: 'unknown' })).toEqual(['foo', 'bar', 'test', 'baz', 'bat']);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should add values after', async () => {
|
|
43
|
-
expect(addValues(a1, a2, { mode: 'after', ref: 'bar' })).toEqual(['foo', 'bar', 'baz', 'bat', 'test']);
|
|
44
|
-
});
|
|
45
|
-
});
|