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