@takeshape/schema 8.35.1 → 8.35.2
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/es/index.js +3 -3
- package/es/migration/index.js +82 -0
- package/es/migration/to/v3.0.0.js +245 -0
- package/es/{migration-utils.js → migration/to/v3.1.0.js} +40 -8
- package/es/migration/to/v3.10.0.js +56 -0
- package/es/migration/to/v3.11.0.js +99 -0
- package/es/migration/to/v3.2.0.js +10 -0
- package/es/migration/to/v3.3.0.js +16 -0
- package/es/migration/to/v3.4.0.js +10 -0
- package/es/migration/to/v3.5.0.js +10 -0
- package/es/migration/to/v3.5.1.js +10 -0
- package/es/migration/to/v3.6.0.js +10 -0
- package/es/migration/to/v3.7.0.js +10 -0
- package/es/migration/to/v3.8.0.js +10 -0
- package/es/migration/to/v3.9.0.js +83 -0
- package/es/migration/types.js +1 -0
- package/es/migration/utils.js +23 -0
- package/lib/index.d.ts +3 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +13 -36
- package/lib/migration/index.d.ts +7 -0
- package/lib/migration/index.d.ts.map +1 -0
- package/lib/migration/index.js +128 -0
- package/lib/migration/to/v3.0.0.d.ts +4 -0
- package/lib/migration/to/v3.0.0.d.ts.map +1 -0
- package/lib/migration/to/v3.0.0.js +260 -0
- package/lib/migration/to/v3.1.0.d.ts +5 -0
- package/lib/migration/to/v3.1.0.d.ts.map +1 -0
- package/lib/{migration-utils.js → migration/to/v3.1.0.js} +40 -10
- package/lib/migration/to/v3.10.0.d.ts +4 -0
- package/lib/migration/to/v3.10.0.d.ts.map +1 -0
- package/lib/migration/to/v3.10.0.js +66 -0
- package/lib/migration/to/v3.11.0.d.ts +5 -0
- package/lib/migration/to/v3.11.0.d.ts.map +1 -0
- package/lib/migration/to/v3.11.0.js +109 -0
- package/lib/migration/to/v3.2.0.d.ts +4 -0
- package/lib/migration/to/v3.2.0.d.ts.map +1 -0
- package/lib/migration/to/v3.2.0.js +18 -0
- package/lib/migration/to/v3.3.0.d.ts +5 -0
- package/lib/migration/to/v3.3.0.d.ts.map +1 -0
- package/lib/migration/to/v3.3.0.js +24 -0
- package/lib/migration/to/v3.4.0.d.ts +4 -0
- package/lib/migration/to/v3.4.0.d.ts.map +1 -0
- package/lib/migration/to/v3.4.0.js +18 -0
- package/lib/migration/to/v3.5.0.d.ts +4 -0
- package/lib/migration/to/v3.5.0.d.ts.map +1 -0
- package/lib/migration/to/v3.5.0.js +18 -0
- package/lib/migration/to/v3.5.1.d.ts +4 -0
- package/lib/migration/to/v3.5.1.d.ts.map +1 -0
- package/lib/migration/to/v3.5.1.js +18 -0
- package/lib/migration/to/v3.6.0.d.ts +4 -0
- package/lib/migration/to/v3.6.0.d.ts.map +1 -0
- package/lib/migration/to/v3.6.0.js +18 -0
- package/lib/migration/to/v3.7.0.d.ts +4 -0
- package/lib/migration/to/v3.7.0.d.ts.map +1 -0
- package/lib/migration/to/v3.7.0.js +18 -0
- package/lib/migration/to/v3.8.0.d.ts +4 -0
- package/lib/migration/to/v3.8.0.d.ts.map +1 -0
- package/lib/migration/to/v3.8.0.js +18 -0
- package/lib/migration/to/v3.9.0.d.ts +4 -0
- package/lib/migration/to/v3.9.0.d.ts.map +1 -0
- package/lib/migration/to/v3.9.0.js +91 -0
- package/lib/migration/types.d.ts +14 -0
- package/lib/migration/types.d.ts.map +1 -0
- package/lib/migration/types.js +5 -0
- package/lib/migration/utils.d.ts +5 -0
- package/lib/migration/utils.d.ts.map +1 -0
- package/lib/migration/utils.js +34 -0
- package/package.json +4 -4
- package/es/migration.js +0 -677
- package/lib/migration-utils.d.ts +0 -18
- package/lib/migration-utils.d.ts.map +0 -1
- package/lib/migration.d.ts +0 -59
- package/lib/migration.d.ts.map +0 -1
- package/lib/migration.js +0 -739
package/es/migration.js
DELETED
|
@@ -1,677 +0,0 @@
|
|
|
1
|
-
import pReduce from 'p-reduce';
|
|
2
|
-
import forEach from 'lodash/forEach';
|
|
3
|
-
import pick from 'lodash/pick';
|
|
4
|
-
import mapValues from 'lodash/mapValues';
|
|
5
|
-
import isObject from 'lodash/isObject';
|
|
6
|
-
import fromPairs from 'lodash/fromPairs';
|
|
7
|
-
import { pascalCase, deepClone, visit } from '@takeshape/util';
|
|
8
|
-
import { arraySchemaKeys, getShapeQueriesAndMutations, multipleRelationshipSchemaKeys, objectSchemaKeys, scalarSchemaKeys, schemaMetadataKeys } from './schema-util';
|
|
9
|
-
import { updateServiceConfigV3ToV3_1 } from './migration-utils';
|
|
10
|
-
import { isProjectSchemaV1, isProjectSchemaV3, isLatestProjectSchema, isProjectSchemaV3_1, isProjectSchemaV3_2, isProjectSchemaV3_3, isProjectSchemaV3_4, isProjectSchemaV3_5, isProjectSchemaV3_5_1, isProjectSchemaV3_6, isProjectSchemaV3_7, isProjectSchemaV3_8, isProjectSchemaV3_9, isProjectSchemaV3_10 } from './types/utils';
|
|
11
|
-
export const listTypePrefix = 'PaginatedList';
|
|
12
|
-
const annotationMap = {
|
|
13
|
-
l10n: '@l10n',
|
|
14
|
-
sensitive: '@sensitive',
|
|
15
|
-
syncLocaleStructure: '@syncLocaleStructure'
|
|
16
|
-
};
|
|
17
|
-
export function getRelationshipSchema(relationship) {
|
|
18
|
-
const itemSchema = {
|
|
19
|
-
$ref: '#/shapes/TSRelationship/schema'
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
if (relationship.type === 'multiple') {
|
|
23
|
-
return {
|
|
24
|
-
type: 'array',
|
|
25
|
-
items: itemSchema,
|
|
26
|
-
'@relationship': relationship
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return { ...itemSchema,
|
|
31
|
-
'@relationship': relationship
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function isColor(schema) {
|
|
36
|
-
const {
|
|
37
|
-
type,
|
|
38
|
-
properties
|
|
39
|
-
} = schema;
|
|
40
|
-
return Boolean(type === 'object' && properties && properties.hsl && properties.hsv && properties.rgb && properties.hex);
|
|
41
|
-
} // eslint-disable-next-line complexity
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
export function migrateToContentSchemaV3(params) {
|
|
45
|
-
const {
|
|
46
|
-
schema,
|
|
47
|
-
service,
|
|
48
|
-
name,
|
|
49
|
-
key,
|
|
50
|
-
setSource,
|
|
51
|
-
omitAllSources
|
|
52
|
-
} = params;
|
|
53
|
-
const {
|
|
54
|
-
type
|
|
55
|
-
} = schema;
|
|
56
|
-
const mapping = !omitAllSources && key && setSource !== false && name !== key ? `${service}.${key}` : undefined;
|
|
57
|
-
forEach(schema, (value, key) => {
|
|
58
|
-
if (annotationMap[key]) {
|
|
59
|
-
const newAnnotation = annotationMap[key];
|
|
60
|
-
schema[newAnnotation] = value; // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
61
|
-
|
|
62
|
-
delete schema[key];
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
if (type === 'string' || type === 'boolean' || type === 'number' || type === 'integer') {
|
|
67
|
-
return {
|
|
68
|
-
schema: { ...pick(schema, scalarSchemaKeys),
|
|
69
|
-
'@mapping': mapping
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const {
|
|
75
|
-
relationship
|
|
76
|
-
} = schema;
|
|
77
|
-
|
|
78
|
-
if (relationship) {
|
|
79
|
-
const {
|
|
80
|
-
contentTypeIds,
|
|
81
|
-
type: relationshipType,
|
|
82
|
-
relatedName
|
|
83
|
-
} = relationship;
|
|
84
|
-
return {
|
|
85
|
-
schema: { ...pick(schema, relationshipType === 'multiple' ? multipleRelationshipSchemaKeys : schemaMetadataKeys),
|
|
86
|
-
'@mapping': mapping,
|
|
87
|
-
...getRelationshipSchema({
|
|
88
|
-
shapeIds: contentTypeIds,
|
|
89
|
-
type: relationshipType ?? 'single',
|
|
90
|
-
// Type is optional on assets
|
|
91
|
-
relatedName
|
|
92
|
-
})
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (type === 'object' && schema.draftjs) {
|
|
98
|
-
return {
|
|
99
|
-
schema: { ...pick(schema, scalarSchemaKeys),
|
|
100
|
-
'@mapping': mapping,
|
|
101
|
-
'@tag': 'draftjs'
|
|
102
|
-
}
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (isColor(schema)) {
|
|
107
|
-
return {
|
|
108
|
-
schema: { ...pick(schema, scalarSchemaKeys),
|
|
109
|
-
$ref: '#/shapes/TSColor/schema',
|
|
110
|
-
'@mapping': mapping
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (type === 'object' && schema.properties) {
|
|
116
|
-
const properties = {};
|
|
117
|
-
const shapes = {};
|
|
118
|
-
const shapeTitle = [params.shapeTitle, pascalCase(schema.title ?? params.name)].filter(Boolean).join(' ');
|
|
119
|
-
const shapeName = `${params.shapeName}${pascalCase(params.name)}`;
|
|
120
|
-
const contentSourceId = `takeshape:local:${shapeName}`;
|
|
121
|
-
forEach(schema.properties, (propSchema, name) => {
|
|
122
|
-
const {
|
|
123
|
-
schema: migratedPropSchema,
|
|
124
|
-
hoistedShapes
|
|
125
|
-
} = migrateToContentSchemaV3({ ...params,
|
|
126
|
-
shapeName,
|
|
127
|
-
shapeTitle,
|
|
128
|
-
depth: params.depth + 1,
|
|
129
|
-
schema: propSchema,
|
|
130
|
-
parentSchema: schema,
|
|
131
|
-
service: contentSourceId,
|
|
132
|
-
key: propSchema.key ?? name,
|
|
133
|
-
name,
|
|
134
|
-
setSource: true
|
|
135
|
-
});
|
|
136
|
-
properties[name] = migratedPropSchema;
|
|
137
|
-
Object.assign(shapes, hoistedShapes);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
if (params.depth > 0) {
|
|
141
|
-
const {
|
|
142
|
-
title,
|
|
143
|
-
description,
|
|
144
|
-
...rest
|
|
145
|
-
} = schema;
|
|
146
|
-
return {
|
|
147
|
-
schema: {
|
|
148
|
-
title,
|
|
149
|
-
description,
|
|
150
|
-
'@mapping': mapping,
|
|
151
|
-
$ref: `#/shapes/${shapeName}/schema`
|
|
152
|
-
},
|
|
153
|
-
hoistedShapes: { ...shapes,
|
|
154
|
-
[shapeName]: {
|
|
155
|
-
id: name === key ? shapeName : key,
|
|
156
|
-
name: shapeName,
|
|
157
|
-
title: shapeTitle,
|
|
158
|
-
schema: { ...pick(rest, objectSchemaKeys),
|
|
159
|
-
type: 'object',
|
|
160
|
-
properties
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return {
|
|
168
|
-
schema: { ...pick(schema, objectSchemaKeys),
|
|
169
|
-
properties,
|
|
170
|
-
'@mapping': mapping
|
|
171
|
-
},
|
|
172
|
-
hoistedShapes: shapes
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (schema.type === 'array' && schema.items) {
|
|
177
|
-
const {
|
|
178
|
-
schema: itemSchema,
|
|
179
|
-
hoistedShapes
|
|
180
|
-
} = migrateToContentSchemaV3({ ...params,
|
|
181
|
-
schema: schema.items,
|
|
182
|
-
parentSchema: schema,
|
|
183
|
-
service: 'parent',
|
|
184
|
-
setSource: false
|
|
185
|
-
});
|
|
186
|
-
return {
|
|
187
|
-
schema: { ...pick(schema, arraySchemaKeys),
|
|
188
|
-
items: itemSchema,
|
|
189
|
-
'@mapping': mapping
|
|
190
|
-
},
|
|
191
|
-
hoistedShapes
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
throw new Error(`Unknown schema type "${type}"`);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function getModelType(contentType) {
|
|
199
|
-
if (contentType.single) {
|
|
200
|
-
return 'single';
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (contentType.taxonomy) {
|
|
204
|
-
return 'taxonomy';
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return 'multiple';
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
export function contentTypeToShape(contentType, contentTypeId) {
|
|
211
|
-
const title = contentType.title ?? contentType.name;
|
|
212
|
-
const name = pascalCase(contentType.name);
|
|
213
|
-
const contentSourceId = `takeshape:local:${name}`;
|
|
214
|
-
const {
|
|
215
|
-
schema,
|
|
216
|
-
hoistedShapes
|
|
217
|
-
} = migrateToContentSchemaV3({
|
|
218
|
-
shapeName: name,
|
|
219
|
-
shapeTitle: title,
|
|
220
|
-
schema: contentType.schema,
|
|
221
|
-
service: contentSourceId,
|
|
222
|
-
name: '',
|
|
223
|
-
key: '',
|
|
224
|
-
depth: 0
|
|
225
|
-
});
|
|
226
|
-
return {
|
|
227
|
-
[name]: {
|
|
228
|
-
id: contentTypeId,
|
|
229
|
-
name,
|
|
230
|
-
title,
|
|
231
|
-
model: {
|
|
232
|
-
type: getModelType(contentType)
|
|
233
|
-
},
|
|
234
|
-
workflow: contentType.workflow,
|
|
235
|
-
schema: schema
|
|
236
|
-
},
|
|
237
|
-
...hoistedShapes
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function formatDate(timestamp) {
|
|
242
|
-
return (timestamp ? new Date(timestamp) : new Date()).toISOString();
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
export function migrateToV3(projectSchema) {
|
|
246
|
-
const {
|
|
247
|
-
contentTypes,
|
|
248
|
-
created,
|
|
249
|
-
updated,
|
|
250
|
-
...rest
|
|
251
|
-
} = projectSchema;
|
|
252
|
-
const shapes = {};
|
|
253
|
-
const forms = {};
|
|
254
|
-
Object.keys(contentTypes).forEach(contentTypeId => {
|
|
255
|
-
const contentType = contentTypes[contentTypeId];
|
|
256
|
-
Object.assign(shapes, contentTypeToShape(contentType, contentTypeId));
|
|
257
|
-
forms[pascalCase(contentType.name)] = contentType.forms;
|
|
258
|
-
}); // Use deepClone to drop undefined values, this improves compatibility with validation and testing
|
|
259
|
-
// Schemas are typically saved in Dynamo or JSON files which also remove undefined values
|
|
260
|
-
// Dropping them here is done for consistency's sake
|
|
261
|
-
|
|
262
|
-
return deepClone({ ...rest,
|
|
263
|
-
...getShapeQueriesAndMutations(Object.values(shapes)),
|
|
264
|
-
schemaVersion: '3',
|
|
265
|
-
created: formatDate(created),
|
|
266
|
-
updated: formatDate(updated),
|
|
267
|
-
shapes,
|
|
268
|
-
forms
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
export async function migrateToV3_1(context, projectSchema) {
|
|
272
|
-
const {
|
|
273
|
-
encryptFn,
|
|
274
|
-
decryptFn
|
|
275
|
-
} = context;
|
|
276
|
-
let services;
|
|
277
|
-
/**
|
|
278
|
-
* Services can only be migrated if a dataKey is present, otherwise they will need to be discarded.
|
|
279
|
-
*/
|
|
280
|
-
|
|
281
|
-
if (projectSchema.services) {
|
|
282
|
-
services = await pReduce(Object.entries(projectSchema.services), async (serviceMap, [serviceKey, serviceConfig]) => {
|
|
283
|
-
const auth = serviceConfig.auth && decryptFn(serviceConfig.auth);
|
|
284
|
-
const updatedServiceConfig = updateServiceConfigV3ToV3_1({ ...serviceConfig,
|
|
285
|
-
auth
|
|
286
|
-
}, serviceKey);
|
|
287
|
-
const authentication = updatedServiceConfig === null || updatedServiceConfig === void 0 ? void 0 : updatedServiceConfig.authentication;
|
|
288
|
-
serviceMap[serviceKey] = { ...updatedServiceConfig,
|
|
289
|
-
authentication: authentication && isObject(authentication) ? encryptFn(authentication) : authentication
|
|
290
|
-
};
|
|
291
|
-
return serviceMap;
|
|
292
|
-
}, {});
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
return deepClone({ ...projectSchema,
|
|
296
|
-
services,
|
|
297
|
-
schemaVersion: '3.1.0'
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
export function migrateToV3_2(projectSchema) {
|
|
301
|
-
/**
|
|
302
|
-
* No migration needed all changes are backwards compatible.
|
|
303
|
-
*/
|
|
304
|
-
return { ...projectSchema,
|
|
305
|
-
schemaVersion: '3.2.0'
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
export async function migrateToV3_3(context, projectSchema) {
|
|
309
|
-
const {
|
|
310
|
-
generateDataKeyFn
|
|
311
|
-
} = context;
|
|
312
|
-
const dataKey = projectSchema.dataKey ? projectSchema.dataKey : await generateDataKeyFn();
|
|
313
|
-
/**
|
|
314
|
-
* Generate a dataKey if none is present.
|
|
315
|
-
*/
|
|
316
|
-
|
|
317
|
-
return { ...projectSchema,
|
|
318
|
-
schemaVersion: '3.3.0',
|
|
319
|
-
dataKey
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
export function migrateToV3_4(projectSchema) {
|
|
323
|
-
/**
|
|
324
|
-
* No migration needed all changes are backwards compatible.
|
|
325
|
-
*/
|
|
326
|
-
return { ...projectSchema,
|
|
327
|
-
schemaVersion: '3.4.0'
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
export function migrateToV3_5(projectSchema) {
|
|
331
|
-
/**
|
|
332
|
-
* No migration needed all changes are backwards compatible.
|
|
333
|
-
*/
|
|
334
|
-
return { ...projectSchema,
|
|
335
|
-
schemaVersion: '3.5.0'
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
export function migrateToV3_5_1(projectSchema) {
|
|
339
|
-
/**
|
|
340
|
-
* No migration needed all changes are backwards compatible.
|
|
341
|
-
*/
|
|
342
|
-
return { ...projectSchema,
|
|
343
|
-
schemaVersion: '3.5.1'
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
export function migrateToV3_6(projectSchema) {
|
|
347
|
-
/**
|
|
348
|
-
* No migration needed all changes are backwards compatible.
|
|
349
|
-
*/
|
|
350
|
-
return { ...projectSchema,
|
|
351
|
-
schemaVersion: '3.6.0'
|
|
352
|
-
};
|
|
353
|
-
}
|
|
354
|
-
export function migrateToV3_7(projectSchema) {
|
|
355
|
-
/**
|
|
356
|
-
* No migration needed all changes are backwards compatible.
|
|
357
|
-
*/
|
|
358
|
-
return { ...projectSchema,
|
|
359
|
-
schemaVersion: '3.7.0'
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
export function migrateToV3_8(projectSchema) {
|
|
363
|
-
/**
|
|
364
|
-
* No migration needed all changes are backwards compatible.
|
|
365
|
-
*/
|
|
366
|
-
return { ...projectSchema,
|
|
367
|
-
schemaVersion: '3.8.0'
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
export function migrateToV3_9_0(projectSchema) {
|
|
371
|
-
/**
|
|
372
|
-
* Resolver props that are guaranteed in this version, and dependent on the
|
|
373
|
-
* resolver type. Ensure they exist.
|
|
374
|
-
*/
|
|
375
|
-
const ensureResolverOptions = resolver => {
|
|
376
|
-
if (resolver.name.startsWith('takeshape')) {
|
|
377
|
-
if (!resolver.shapeName) {
|
|
378
|
-
var _resolver$options, _resolver$options2, _resolver$options3, _resolver$options4;
|
|
379
|
-
|
|
380
|
-
resolver.shapeName = ((_resolver$options = resolver.options) === null || _resolver$options === void 0 ? void 0 : _resolver$options.model) ?? ((_resolver$options2 = resolver.options) === null || _resolver$options2 === void 0 ? void 0 : _resolver$options2.indexedShape) ?? '';
|
|
381
|
-
(_resolver$options3 = resolver.options) === null || _resolver$options3 === void 0 ? true : delete _resolver$options3.model;
|
|
382
|
-
(_resolver$options4 = resolver.options) === null || _resolver$options4 === void 0 ? true : delete _resolver$options4.indexedShape;
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
if (resolver.name.startsWith('graphql')) {
|
|
387
|
-
if (!resolver.fieldName) {
|
|
388
|
-
var _resolver$options5, _resolver$options6;
|
|
389
|
-
|
|
390
|
-
resolver.fieldName = ((_resolver$options5 = resolver.options) === null || _resolver$options5 === void 0 ? void 0 : _resolver$options5.fieldName) ?? '';
|
|
391
|
-
(_resolver$options6 = resolver.options) === null || _resolver$options6 === void 0 ? true : delete _resolver$options6.fieldName;
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
if (resolver.name.startsWith('awsLambda')) {
|
|
396
|
-
if (!resolver.functionName) {
|
|
397
|
-
var _resolver$options7, _resolver$options8;
|
|
398
|
-
|
|
399
|
-
resolver.functionName = ((_resolver$options7 = resolver.options) === null || _resolver$options7 === void 0 ? void 0 : _resolver$options7.functionName) ?? '';
|
|
400
|
-
(_resolver$options8 = resolver.options) === null || _resolver$options8 === void 0 ? true : delete _resolver$options8.functionName;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
if (resolver.name.startsWith('rest')) {
|
|
405
|
-
if (!resolver.path) {
|
|
406
|
-
var _resolver$options11;
|
|
407
|
-
|
|
408
|
-
if (resolver.pathParams) {
|
|
409
|
-
var _resolver$options9;
|
|
410
|
-
|
|
411
|
-
resolver.path = { ...resolver.pathParams,
|
|
412
|
-
serialize: { ...resolver.pathParams.serialize,
|
|
413
|
-
template: (_resolver$options9 = resolver.options) === null || _resolver$options9 === void 0 ? void 0 : _resolver$options9.path
|
|
414
|
-
}
|
|
415
|
-
};
|
|
416
|
-
} else {
|
|
417
|
-
var _resolver$options10;
|
|
418
|
-
|
|
419
|
-
resolver.path = ((_resolver$options10 = resolver.options) === null || _resolver$options10 === void 0 ? void 0 : _resolver$options10.path) ?? '';
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
(_resolver$options11 = resolver.options) === null || _resolver$options11 === void 0 ? true : delete _resolver$options11.path;
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
/**
|
|
426
|
-
* `resolver.name` was previously validated with app code and v3.9.0
|
|
427
|
-
* enumerates the previous validation, making this assertion safe.
|
|
428
|
-
*/
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
return resolver;
|
|
432
|
-
};
|
|
433
|
-
/**
|
|
434
|
-
* Function will visit each resolver in the schema and mutate them.
|
|
435
|
-
*/
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
visit(projectSchema, ['resolver', '@resolver'], resolver => {
|
|
439
|
-
if (resolver.compose) {
|
|
440
|
-
resolver.compose.forEach(ensureResolverOptions);
|
|
441
|
-
} else {
|
|
442
|
-
ensureResolverOptions(resolver);
|
|
443
|
-
}
|
|
444
|
-
});
|
|
445
|
-
return { ...projectSchema,
|
|
446
|
-
schemaVersion: '3.9.0'
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
function migrateQueryToV3_10(query, queryName) {
|
|
451
|
-
const {
|
|
452
|
-
args,
|
|
453
|
-
shape
|
|
454
|
-
} = query;
|
|
455
|
-
|
|
456
|
-
if (typeof args === 'object' && ('oneOf' in args || 'allOf' in args || '$ref' in args || '@ref' in args)) {
|
|
457
|
-
// As of 11/15/2021 no production schemas contained queries with these args
|
|
458
|
-
throw new Error(`Query "${queryName}" contains an unsupported arg schema ${JSON.stringify(args)}. Please contact support`);
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
if (typeof shape === 'object' && !shape.items['@ref']) {
|
|
462
|
-
// As of 11/15/2021 no production schemas contained queries with array return shapes that are not @refs
|
|
463
|
-
throw new Error(`Query "${queryName}" contains an unsupported shape schema ${JSON.stringify(shape)}. Please contact support`);
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
return query;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
function migrateShapeToV3_10(shape) {
|
|
470
|
-
const {
|
|
471
|
-
schema,
|
|
472
|
-
...rest
|
|
473
|
-
} = shape; // As of 11/15/2021 no production schemas contained shapes with array schemas
|
|
474
|
-
|
|
475
|
-
if ('type' in schema && schema.type === 'array') {
|
|
476
|
-
throw new Error(`Shape ${shape.name} uses an unsupported array schema. Please contact support`);
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
const newSchema = '$ref' in schema || '@ref' in schema ? {
|
|
480
|
-
allOf: [schema]
|
|
481
|
-
} : schema;
|
|
482
|
-
return { ...rest,
|
|
483
|
-
schema: newSchema
|
|
484
|
-
};
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
export function migrateToV3_10(projectSchema) {
|
|
488
|
-
const {
|
|
489
|
-
queries,
|
|
490
|
-
mutations,
|
|
491
|
-
shapes,
|
|
492
|
-
schemaVersion,
|
|
493
|
-
...rest
|
|
494
|
-
} = projectSchema;
|
|
495
|
-
return { ...rest,
|
|
496
|
-
queries: mapValues(queries, migrateQueryToV3_10),
|
|
497
|
-
mutations: mapValues(mutations, migrateQueryToV3_10),
|
|
498
|
-
shapes: mapValues(shapes, migrateShapeToV3_10),
|
|
499
|
-
schemaVersion: '3.10.0'
|
|
500
|
-
};
|
|
501
|
-
}
|
|
502
|
-
export function migrateToV3_11_0({
|
|
503
|
-
decryptFn,
|
|
504
|
-
encryptFn
|
|
505
|
-
}, projectSchema) {
|
|
506
|
-
const migratedServices = [];
|
|
507
|
-
|
|
508
|
-
for (const [serviceKey, serviceConfig] of Object.entries(projectSchema.services ?? {})) {
|
|
509
|
-
const {
|
|
510
|
-
authenticationType,
|
|
511
|
-
authentication
|
|
512
|
-
} = serviceConfig; // Migrate authentication, ensuring now required properties
|
|
513
|
-
|
|
514
|
-
if (authentication && authenticationType !== 'unknown' && authenticationType !== 'none') {
|
|
515
|
-
const decrypted = decryptFn(authentication);
|
|
516
|
-
|
|
517
|
-
if (!decrypted) {
|
|
518
|
-
throw new Error(`Service "${serviceKey}" authentication could not be decrypted. Please contact support.`);
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
let migrated;
|
|
522
|
-
|
|
523
|
-
if (authenticationType === 'searchParams') {
|
|
524
|
-
migrated = {
|
|
525
|
-
params: decrypted,
|
|
526
|
-
type: authenticationType
|
|
527
|
-
};
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
if (authenticationType === 'basic') {
|
|
531
|
-
migrated = {
|
|
532
|
-
username: '',
|
|
533
|
-
password: '',
|
|
534
|
-
...decrypted,
|
|
535
|
-
type: authenticationType
|
|
536
|
-
};
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
if (authenticationType === 'bearer') {
|
|
540
|
-
migrated = {
|
|
541
|
-
token: '',
|
|
542
|
-
...decrypted,
|
|
543
|
-
type: authenticationType
|
|
544
|
-
};
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
if (authenticationType === 'oauth2Bearer') {
|
|
548
|
-
migrated = {
|
|
549
|
-
token: '',
|
|
550
|
-
...decrypted,
|
|
551
|
-
type: authenticationType
|
|
552
|
-
};
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
if (authenticationType === 'oauth2') {
|
|
556
|
-
migrated = {
|
|
557
|
-
grantType: 'clientCredentials',
|
|
558
|
-
clientId: '',
|
|
559
|
-
...decrypted,
|
|
560
|
-
type: authenticationType
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
if (authenticationType === 'aws') {
|
|
565
|
-
migrated = {
|
|
566
|
-
awsAccessKeyId: '',
|
|
567
|
-
awsSecretAccessKey: '',
|
|
568
|
-
...decrypted,
|
|
569
|
-
type: authenticationType
|
|
570
|
-
};
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
if (authenticationType === 'custom') {
|
|
574
|
-
migrated = { ...decrypted,
|
|
575
|
-
type: authenticationType
|
|
576
|
-
};
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
if (migrated) {
|
|
580
|
-
const migratedServiceConfig = { ...serviceConfig,
|
|
581
|
-
authentication: encryptFn(migrated)
|
|
582
|
-
};
|
|
583
|
-
migratedServices.push([serviceKey, migratedServiceConfig]);
|
|
584
|
-
} else {
|
|
585
|
-
migratedServices.push([serviceKey, serviceConfig]);
|
|
586
|
-
}
|
|
587
|
-
} else {
|
|
588
|
-
migratedServices.push([serviceKey, serviceConfig]);
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
return { ...projectSchema,
|
|
593
|
-
services: fromPairs(migratedServices),
|
|
594
|
-
schemaVersion: '3.11.0'
|
|
595
|
-
};
|
|
596
|
-
}
|
|
597
|
-
export async function migrateToLatestProjectSchema(context, projectSchema) {
|
|
598
|
-
if (projectSchema.schemaVersion === '4.0.0') {
|
|
599
|
-
throw new Error('You are using an unreleased schema version. Migration is not possible');
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
if (isProjectSchemaV1(projectSchema)) {
|
|
603
|
-
projectSchema = migrateToV3(projectSchema);
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
if (isProjectSchemaV3(projectSchema)) {
|
|
607
|
-
projectSchema = await migrateToV3_1(context, projectSchema);
|
|
608
|
-
}
|
|
609
|
-
|
|
610
|
-
if (isProjectSchemaV3_1(projectSchema)) {
|
|
611
|
-
projectSchema = migrateToV3_2(projectSchema);
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
if (isProjectSchemaV3_2(projectSchema)) {
|
|
615
|
-
projectSchema = await migrateToV3_3(context, projectSchema);
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
if (isProjectSchemaV3_3(projectSchema)) {
|
|
619
|
-
projectSchema = migrateToV3_4(projectSchema);
|
|
620
|
-
}
|
|
621
|
-
|
|
622
|
-
if (isProjectSchemaV3_4(projectSchema)) {
|
|
623
|
-
projectSchema = migrateToV3_5(projectSchema);
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
if (isProjectSchemaV3_5(projectSchema)) {
|
|
627
|
-
projectSchema = migrateToV3_5_1(projectSchema);
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
if (isProjectSchemaV3_5_1(projectSchema)) {
|
|
631
|
-
projectSchema = migrateToV3_6(projectSchema);
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
if (isProjectSchemaV3_6(projectSchema)) {
|
|
635
|
-
projectSchema = migrateToV3_7(projectSchema);
|
|
636
|
-
}
|
|
637
|
-
|
|
638
|
-
if (isProjectSchemaV3_7(projectSchema)) {
|
|
639
|
-
projectSchema = migrateToV3_8(projectSchema);
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
if (isProjectSchemaV3_8(projectSchema)) {
|
|
643
|
-
projectSchema = migrateToV3_9_0(projectSchema);
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
if (isProjectSchemaV3_9(projectSchema)) {
|
|
647
|
-
projectSchema = migrateToV3_10(projectSchema);
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
if (isProjectSchemaV3_10(projectSchema)) {
|
|
651
|
-
projectSchema = migrateToV3_11_0(context, projectSchema);
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
return projectSchema;
|
|
655
|
-
}
|
|
656
|
-
export function normalizeSchemaVersion(version) {
|
|
657
|
-
return version === undefined ? '1' : version;
|
|
658
|
-
}
|
|
659
|
-
export function isV1Like(schema) {
|
|
660
|
-
return Boolean(schema.schemaVersion === '1' || schema.schemaVersion === undefined);
|
|
661
|
-
}
|
|
662
|
-
export function isV1(schema) {
|
|
663
|
-
return Boolean(isV1Like(schema));
|
|
664
|
-
}
|
|
665
|
-
export function isV3Like(schema) {
|
|
666
|
-
return schema.schemaVersion === '3';
|
|
667
|
-
}
|
|
668
|
-
export function isV3(schema) {
|
|
669
|
-
return isV3Like(schema);
|
|
670
|
-
}
|
|
671
|
-
export async function ensureLatest(context, schema) {
|
|
672
|
-
if (!schema || isLatestProjectSchema(schema)) {
|
|
673
|
-
return schema;
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
return migrateToLatestProjectSchema(context, schema);
|
|
677
|
-
}
|
package/lib/migration-utils.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is a stop-gap for this story: https://app.shortcut.com/takeshape/story/7140/reorganize-schema-migration-ts-into-a-directory
|
|
3
|
-
*/
|
|
4
|
-
import type { ServiceKey } from './types/types';
|
|
5
|
-
import type { StoredServiceConfigV3_1_0, ServiceConfigV3_1_0 } from './project-schema';
|
|
6
|
-
/**
|
|
7
|
-
* `graphql:my-key` `my-key`
|
|
8
|
-
*/
|
|
9
|
-
export declare function parseV3ServiceStr(service: string): {
|
|
10
|
-
provider?: string;
|
|
11
|
-
id: string;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* Ensures a consistent service config, inluding updating the service
|
|
15
|
-
* authentication object.
|
|
16
|
-
*/
|
|
17
|
-
export declare function updateServiceConfigV3ToV3_1(serviceConfig: Record<string, unknown>, serviceKey: ServiceKey): StoredServiceConfigV3_1_0 | ServiceConfigV3_1_0;
|
|
18
|
-
//# sourceMappingURL=migration-utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"migration-utils.d.ts","sourceRoot":"","sources":["../../src/migration-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAC,UAAU,EAA2B,MAAM,eAAe,CAAC;AACxE,OAAO,KAAK,EAAC,yBAAyB,EAAE,mBAAmB,EAA8B,MAAM,kBAAkB,CAAC;AAQlH;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAC,CAGlF;AAED;;;GAGG;AAEH,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACtC,UAAU,EAAE,UAAU,GACrB,yBAAyB,GAAG,mBAAmB,CAkGjD"}
|