@takeshape/schema 8.31.0 → 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.
Files changed (135) hide show
  1. package/es/index.js +3 -3
  2. package/es/migration/index.js +82 -0
  3. package/es/migration/to/v3.0.0.js +245 -0
  4. package/es/migration/to/v3.1.0.js +218 -0
  5. package/es/migration/to/v3.10.0.js +56 -0
  6. package/es/migration/to/v3.11.0.js +99 -0
  7. package/es/migration/to/v3.2.0.js +10 -0
  8. package/es/migration/to/v3.3.0.js +16 -0
  9. package/es/migration/to/v3.4.0.js +10 -0
  10. package/es/migration/to/v3.5.0.js +10 -0
  11. package/es/migration/to/v3.5.1.js +10 -0
  12. package/es/migration/to/v3.6.0.js +10 -0
  13. package/es/migration/to/v3.7.0.js +10 -0
  14. package/es/migration/to/v3.8.0.js +10 -0
  15. package/es/migration/to/v3.9.0.js +83 -0
  16. package/es/migration/types.js +1 -0
  17. package/es/migration/utils.js +23 -0
  18. package/es/mocks.js +1 -0
  19. package/es/project-schema/index.js +1 -0
  20. package/es/project-schema/v3.11.0.js +1 -0
  21. package/es/schema-util.js +15 -10
  22. package/es/schemas/index.js +4 -3
  23. package/es/schemas/index.ts +4 -2
  24. package/es/schemas/project-schema/v3.11.0.json +2135 -0
  25. package/es/services.js +57 -255
  26. package/es/types/types.js +9 -0
  27. package/es/types/utils.js +19 -12
  28. package/examples/latest/blog-schema.json +2 -1
  29. package/examples/latest/brewery-schema.json +2 -1
  30. package/examples/latest/complex-project-schema.json +2 -1
  31. package/examples/latest/fabric-ecommerce.json +2 -2
  32. package/examples/latest/frank-and-fred-schema.json +2 -1
  33. package/examples/latest/massive-schema.json +2 -1
  34. package/examples/latest/mill-components-schema.json +2 -1
  35. package/examples/latest/pet-oneof-array.json +2 -1
  36. package/examples/latest/post-schema.json +2 -1
  37. package/examples/latest/pruned-shopify-product-schema.json +2 -2
  38. package/examples/latest/real-world-schema.json +2 -1
  39. package/examples/latest/recursive-repeater-schema.json +2 -1
  40. package/examples/latest/recursive-schema.json +2 -1
  41. package/examples/latest/rick-and-morty-ast.json +1 -1
  42. package/examples/latest/rick-and-morty-graphql.json +1 -1
  43. package/examples/latest/rick-and-morty-rest.json +1 -1
  44. package/examples/latest/schema-with-repeater-draftjs.json +2 -1
  45. package/examples/latest/shape-books-v3_2_0.json +2 -1
  46. package/examples/latest/shape-books.json +2 -1
  47. package/examples/latest/shopify-lookbook.json +1 -1
  48. package/examples/latest/shopify-store-with-widget.json +2 -2
  49. package/examples/latest/stripe-starter-resolved.json +2 -2
  50. package/examples/latest/user-schema-no-required.json +2 -1
  51. package/examples/latest/user-schema-with-defaults.json +2 -1
  52. package/lib/index.d.ts +3 -3
  53. package/lib/index.d.ts.map +1 -1
  54. package/lib/index.js +13 -36
  55. package/lib/migration/index.d.ts +7 -0
  56. package/lib/migration/index.d.ts.map +1 -0
  57. package/lib/migration/index.js +128 -0
  58. package/lib/migration/to/v3.0.0.d.ts +4 -0
  59. package/lib/migration/to/v3.0.0.d.ts.map +1 -0
  60. package/lib/migration/to/v3.0.0.js +260 -0
  61. package/lib/migration/to/v3.1.0.d.ts +5 -0
  62. package/lib/migration/to/v3.1.0.d.ts.map +1 -0
  63. package/lib/migration/to/v3.1.0.js +233 -0
  64. package/lib/migration/to/v3.10.0.d.ts +4 -0
  65. package/lib/migration/to/v3.10.0.d.ts.map +1 -0
  66. package/lib/migration/to/v3.10.0.js +66 -0
  67. package/lib/migration/to/v3.11.0.d.ts +5 -0
  68. package/lib/migration/to/v3.11.0.d.ts.map +1 -0
  69. package/lib/migration/to/v3.11.0.js +109 -0
  70. package/lib/migration/to/v3.2.0.d.ts +4 -0
  71. package/lib/migration/to/v3.2.0.d.ts.map +1 -0
  72. package/lib/migration/to/v3.2.0.js +18 -0
  73. package/lib/migration/to/v3.3.0.d.ts +5 -0
  74. package/lib/migration/to/v3.3.0.d.ts.map +1 -0
  75. package/lib/migration/to/v3.3.0.js +24 -0
  76. package/lib/migration/to/v3.4.0.d.ts +4 -0
  77. package/lib/migration/to/v3.4.0.d.ts.map +1 -0
  78. package/lib/migration/to/v3.4.0.js +18 -0
  79. package/lib/migration/to/v3.5.0.d.ts +4 -0
  80. package/lib/migration/to/v3.5.0.d.ts.map +1 -0
  81. package/lib/migration/to/v3.5.0.js +18 -0
  82. package/lib/migration/to/v3.5.1.d.ts +4 -0
  83. package/lib/migration/to/v3.5.1.d.ts.map +1 -0
  84. package/lib/migration/to/v3.5.1.js +18 -0
  85. package/lib/migration/to/v3.6.0.d.ts +4 -0
  86. package/lib/migration/to/v3.6.0.d.ts.map +1 -0
  87. package/lib/migration/to/v3.6.0.js +18 -0
  88. package/lib/migration/to/v3.7.0.d.ts +4 -0
  89. package/lib/migration/to/v3.7.0.d.ts.map +1 -0
  90. package/lib/migration/to/v3.7.0.js +18 -0
  91. package/lib/migration/to/v3.8.0.d.ts +4 -0
  92. package/lib/migration/to/v3.8.0.d.ts.map +1 -0
  93. package/lib/migration/to/v3.8.0.js +18 -0
  94. package/lib/migration/to/v3.9.0.d.ts +4 -0
  95. package/lib/migration/to/v3.9.0.d.ts.map +1 -0
  96. package/lib/migration/to/v3.9.0.js +91 -0
  97. package/lib/migration/types.d.ts +14 -0
  98. package/lib/migration/types.d.ts.map +1 -0
  99. package/lib/migration/types.js +5 -0
  100. package/lib/migration/utils.d.ts +5 -0
  101. package/lib/migration/utils.d.ts.map +1 -0
  102. package/lib/migration/utils.js +34 -0
  103. package/lib/mocks.d.ts.map +1 -1
  104. package/lib/mocks.js +1 -0
  105. package/lib/project-schema/index.d.ts +3 -1
  106. package/lib/project-schema/index.d.ts.map +1 -1
  107. package/lib/project-schema/index.js +26 -13
  108. package/lib/project-schema/latest.d.ts +26 -17
  109. package/lib/project-schema/latest.d.ts.map +1 -1
  110. package/lib/project-schema/v3.11.0.d.ts +1211 -0
  111. package/lib/project-schema/v3.11.0.d.ts.map +1 -0
  112. package/lib/project-schema/v3.11.0.js +5 -0
  113. package/lib/schema-util.d.ts.map +1 -1
  114. package/lib/schema-util.js +16 -10
  115. package/lib/schemas/index.d.ts +2051 -2
  116. package/lib/schemas/index.d.ts.map +1 -1
  117. package/lib/schemas/index.js +17 -15
  118. package/lib/schemas/index.ts +4 -2
  119. package/lib/schemas/project-schema/v3.11.0.json +2135 -0
  120. package/lib/services.d.ts +11 -27
  121. package/lib/services.d.ts.map +1 -1
  122. package/lib/services.js +54 -261
  123. package/lib/types/types.d.ts +16 -5
  124. package/lib/types/types.d.ts.map +1 -1
  125. package/lib/types/types.js +9 -0
  126. package/lib/types/utils.d.ts +8 -5
  127. package/lib/types/utils.d.ts.map +1 -1
  128. package/lib/types/utils.js +25 -13
  129. package/lib/validate.d.ts +1 -1
  130. package/lib/validate.d.ts.map +1 -1
  131. package/package.json +6 -5
  132. package/es/migration.js +0 -576
  133. package/lib/migration.d.ts +0 -59
  134. package/lib/migration.d.ts.map +0 -1
  135. package/lib/migration.js +0 -634
package/es/migration.js DELETED
@@ -1,576 +0,0 @@
1
- import pReduce from 'p-reduce';
2
- import forEach from 'lodash/forEach';
3
- import pick from 'lodash/pick';
4
- import { pascalCase, deepClone, visit } from '@takeshape/util';
5
- import { arraySchemaKeys, getShapeQueriesAndMutations, multipleRelationshipSchemaKeys, objectSchemaKeys, scalarSchemaKeys, schemaMetadataKeys } from './schema-util';
6
- import { updateServiceConfigV3ToV3_1 } from './services';
7
- import { isServiceAuthentication, isProjectSchemaV1, isProjectSchemaV3, isLatestProjectSchema, isProjectSchemaV3_1, isProjectSchemaV3_2, isProjectSchemaV3_3, isProjectSchemaV3_4, isProjectSchemaV3_5, isProjectSchemaV3_5_1, isProjectSchemaV3_6, isProjectSchemaV3_7, isProjectSchemaV3_8, isProjectSchemaV3_9 } from './types/utils';
8
- import mapValues from 'lodash/mapValues';
9
- export const listTypePrefix = 'PaginatedList';
10
- const annotationMap = {
11
- l10n: '@l10n',
12
- sensitive: '@sensitive',
13
- syncLocaleStructure: '@syncLocaleStructure'
14
- };
15
- export function getRelationshipSchema(relationship) {
16
- const itemSchema = {
17
- $ref: '#/shapes/TSRelationship/schema'
18
- };
19
-
20
- if (relationship.type === 'multiple') {
21
- return {
22
- type: 'array',
23
- items: itemSchema,
24
- '@relationship': relationship
25
- };
26
- }
27
-
28
- return { ...itemSchema,
29
- '@relationship': relationship
30
- };
31
- }
32
-
33
- function isColor(schema) {
34
- const {
35
- type,
36
- properties
37
- } = schema;
38
- return Boolean(type === 'object' && properties && properties.hsl && properties.hsv && properties.rgb && properties.hex);
39
- } // eslint-disable-next-line complexity
40
-
41
-
42
- export function migrateToContentSchemaV3(params) {
43
- const {
44
- schema,
45
- service,
46
- name,
47
- key,
48
- setSource,
49
- omitAllSources
50
- } = params;
51
- const {
52
- type
53
- } = schema;
54
- const mapping = !omitAllSources && key && setSource !== false && name !== key ? `${service}.${key}` : undefined;
55
- forEach(schema, (value, key) => {
56
- if (annotationMap[key]) {
57
- const newAnnotation = annotationMap[key];
58
- schema[newAnnotation] = value; // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
59
-
60
- delete schema[key];
61
- }
62
- });
63
-
64
- if (type === 'string' || type === 'boolean' || type === 'number' || type === 'integer') {
65
- return {
66
- schema: { ...pick(schema, scalarSchemaKeys),
67
- '@mapping': mapping
68
- }
69
- };
70
- }
71
-
72
- const {
73
- relationship
74
- } = schema;
75
-
76
- if (relationship) {
77
- const {
78
- contentTypeIds,
79
- type: relationshipType,
80
- relatedName
81
- } = relationship;
82
- return {
83
- schema: { ...pick(schema, relationshipType === 'multiple' ? multipleRelationshipSchemaKeys : schemaMetadataKeys),
84
- '@mapping': mapping,
85
- ...getRelationshipSchema({
86
- shapeIds: contentTypeIds,
87
- type: relationshipType ?? 'single',
88
- // Type is optional on assets
89
- relatedName
90
- })
91
- }
92
- };
93
- }
94
-
95
- if (type === 'object' && schema.draftjs) {
96
- return {
97
- schema: { ...pick(schema, scalarSchemaKeys),
98
- '@mapping': mapping,
99
- '@tag': 'draftjs'
100
- }
101
- };
102
- }
103
-
104
- if (isColor(schema)) {
105
- return {
106
- schema: { ...pick(schema, scalarSchemaKeys),
107
- $ref: '#/shapes/TSColor/schema',
108
- '@mapping': mapping
109
- }
110
- };
111
- }
112
-
113
- if (type === 'object' && schema.properties) {
114
- const properties = {};
115
- const shapes = {};
116
- const shapeTitle = [params.shapeTitle, pascalCase(schema.title ?? params.name)].filter(Boolean).join(' ');
117
- const shapeName = `${params.shapeName}${pascalCase(params.name)}`;
118
- const contentSourceId = `takeshape:local:${shapeName}`;
119
- forEach(schema.properties, (propSchema, name) => {
120
- const {
121
- schema: migratedPropSchema,
122
- hoistedShapes
123
- } = migrateToContentSchemaV3({ ...params,
124
- shapeName,
125
- shapeTitle,
126
- depth: params.depth + 1,
127
- schema: propSchema,
128
- parentSchema: schema,
129
- service: contentSourceId,
130
- key: propSchema.key ?? name,
131
- name,
132
- setSource: true
133
- });
134
- properties[name] = migratedPropSchema;
135
- Object.assign(shapes, hoistedShapes);
136
- });
137
-
138
- if (params.depth > 0) {
139
- const {
140
- title,
141
- description,
142
- ...rest
143
- } = schema;
144
- return {
145
- schema: {
146
- title,
147
- description,
148
- '@mapping': mapping,
149
- $ref: `#/shapes/${shapeName}/schema`
150
- },
151
- hoistedShapes: { ...shapes,
152
- [shapeName]: {
153
- id: name === key ? shapeName : key,
154
- name: shapeName,
155
- title: shapeTitle,
156
- schema: { ...pick(rest, objectSchemaKeys),
157
- type: 'object',
158
- properties
159
- }
160
- }
161
- }
162
- };
163
- }
164
-
165
- return {
166
- schema: { ...pick(schema, objectSchemaKeys),
167
- properties,
168
- '@mapping': mapping
169
- },
170
- hoistedShapes: shapes
171
- };
172
- }
173
-
174
- if (schema.type === 'array' && schema.items) {
175
- const {
176
- schema: itemSchema,
177
- hoistedShapes
178
- } = migrateToContentSchemaV3({ ...params,
179
- schema: schema.items,
180
- parentSchema: schema,
181
- service: 'parent',
182
- setSource: false
183
- });
184
- return {
185
- schema: { ...pick(schema, arraySchemaKeys),
186
- items: itemSchema,
187
- '@mapping': mapping
188
- },
189
- hoistedShapes
190
- };
191
- }
192
-
193
- throw new Error(`Unknown schema type "${type}"`);
194
- }
195
-
196
- function getModelType(contentType) {
197
- if (contentType.single) {
198
- return 'single';
199
- }
200
-
201
- if (contentType.taxonomy) {
202
- return 'taxonomy';
203
- }
204
-
205
- return 'multiple';
206
- }
207
-
208
- export function contentTypeToShape(contentType, contentTypeId) {
209
- const title = contentType.title ?? contentType.name;
210
- const name = pascalCase(contentType.name);
211
- const contentSourceId = `takeshape:local:${name}`;
212
- const {
213
- schema,
214
- hoistedShapes
215
- } = migrateToContentSchemaV3({
216
- shapeName: name,
217
- shapeTitle: title,
218
- schema: contentType.schema,
219
- service: contentSourceId,
220
- name: '',
221
- key: '',
222
- depth: 0
223
- });
224
- return {
225
- [name]: {
226
- id: contentTypeId,
227
- name,
228
- title,
229
- model: {
230
- type: getModelType(contentType)
231
- },
232
- workflow: contentType.workflow,
233
- schema: schema
234
- },
235
- ...hoistedShapes
236
- };
237
- }
238
-
239
- function formatDate(timestamp) {
240
- return (timestamp ? new Date(timestamp) : new Date()).toISOString();
241
- }
242
-
243
- export function migrateToV3(projectSchema) {
244
- const {
245
- contentTypes,
246
- created,
247
- updated,
248
- ...rest
249
- } = projectSchema;
250
- const shapes = {};
251
- const forms = {};
252
- Object.keys(contentTypes).forEach(contentTypeId => {
253
- const contentType = contentTypes[contentTypeId];
254
- Object.assign(shapes, contentTypeToShape(contentType, contentTypeId));
255
- forms[pascalCase(contentType.name)] = contentType.forms;
256
- }); // Use deepClone to drop undefined values, this improves compatibility with validation and testing
257
- // Schemas are typically saved in Dynamo or JSON files which also remove undefined values
258
- // Dropping them here is done for consistency's sake
259
-
260
- return deepClone({ ...rest,
261
- ...getShapeQueriesAndMutations(Object.values(shapes)),
262
- schemaVersion: '3',
263
- created: formatDate(created),
264
- updated: formatDate(updated),
265
- shapes,
266
- forms
267
- });
268
- }
269
- export async function migrateToV3_1(context, projectSchema) {
270
- const {
271
- encryptFn,
272
- decryptFn
273
- } = context;
274
- let services;
275
- /**
276
- * Services can only be migrated if a dataKey is present, otherwise they will need to be discarded.
277
- */
278
-
279
- if (projectSchema.services) {
280
- services = await pReduce(Object.entries(projectSchema.services), async (serviceMap, [serviceKey, serviceConfig]) => {
281
- const auth = serviceConfig.auth && decryptFn(serviceConfig.auth);
282
- const updatedServiceConfig = updateServiceConfigV3ToV3_1({ ...serviceConfig,
283
- auth
284
- }, serviceKey);
285
- const authentication = updatedServiceConfig === null || updatedServiceConfig === void 0 ? void 0 : updatedServiceConfig.authentication;
286
- serviceMap[serviceKey] = { ...updatedServiceConfig,
287
- authentication: isServiceAuthentication(authentication) ? encryptFn(authentication) : authentication
288
- };
289
- return serviceMap;
290
- }, {});
291
- }
292
-
293
- return deepClone({ ...projectSchema,
294
- services,
295
- schemaVersion: '3.1.0'
296
- });
297
- }
298
- export function migrateToV3_2(projectSchema) {
299
- /**
300
- * No migration needed all changes are backwards compatible.
301
- */
302
- return { ...projectSchema,
303
- schemaVersion: '3.2.0'
304
- };
305
- }
306
- export async function migrateToV3_3(context, projectSchema) {
307
- const {
308
- generateDataKeyFn
309
- } = context;
310
- const dataKey = projectSchema.dataKey ? projectSchema.dataKey : await generateDataKeyFn();
311
- /**
312
- * Generate a dataKey if none is present.
313
- */
314
-
315
- return { ...projectSchema,
316
- schemaVersion: '3.3.0',
317
- dataKey
318
- };
319
- }
320
- export function migrateToV3_4(projectSchema) {
321
- /**
322
- * No migration needed all changes are backwards compatible.
323
- */
324
- return { ...projectSchema,
325
- schemaVersion: '3.4.0'
326
- };
327
- }
328
- export function migrateToV3_5(projectSchema) {
329
- /**
330
- * No migration needed all changes are backwards compatible.
331
- */
332
- return { ...projectSchema,
333
- schemaVersion: '3.5.0'
334
- };
335
- }
336
- export function migrateToV3_5_1(projectSchema) {
337
- /**
338
- * No migration needed all changes are backwards compatible.
339
- */
340
- return { ...projectSchema,
341
- schemaVersion: '3.5.1'
342
- };
343
- }
344
- export function migrateToV3_6(projectSchema) {
345
- /**
346
- * No migration needed all changes are backwards compatible.
347
- */
348
- return { ...projectSchema,
349
- schemaVersion: '3.6.0'
350
- };
351
- }
352
- export function migrateToV3_7(projectSchema) {
353
- /**
354
- * No migration needed all changes are backwards compatible.
355
- */
356
- return { ...projectSchema,
357
- schemaVersion: '3.7.0'
358
- };
359
- }
360
- export function migrateToV3_8(projectSchema) {
361
- /**
362
- * No migration needed all changes are backwards compatible.
363
- */
364
- return { ...projectSchema,
365
- schemaVersion: '3.8.0'
366
- };
367
- }
368
- export function migrateToV3_9_0(projectSchema) {
369
- /**
370
- * Resolver props that are guaranteed in this version, and dependent on the
371
- * resolver type. Ensure they exist.
372
- */
373
- const ensureResolverOptions = resolver => {
374
- if (resolver.name.startsWith('takeshape')) {
375
- if (!resolver.shapeName) {
376
- var _resolver$options, _resolver$options2, _resolver$options3, _resolver$options4;
377
-
378
- 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) ?? '';
379
- (_resolver$options3 = resolver.options) === null || _resolver$options3 === void 0 ? true : delete _resolver$options3.model;
380
- (_resolver$options4 = resolver.options) === null || _resolver$options4 === void 0 ? true : delete _resolver$options4.indexedShape;
381
- }
382
- }
383
-
384
- if (resolver.name.startsWith('graphql')) {
385
- if (!resolver.fieldName) {
386
- var _resolver$options5, _resolver$options6;
387
-
388
- resolver.fieldName = ((_resolver$options5 = resolver.options) === null || _resolver$options5 === void 0 ? void 0 : _resolver$options5.fieldName) ?? '';
389
- (_resolver$options6 = resolver.options) === null || _resolver$options6 === void 0 ? true : delete _resolver$options6.fieldName;
390
- }
391
- }
392
-
393
- if (resolver.name.startsWith('awsLambda')) {
394
- if (!resolver.functionName) {
395
- var _resolver$options7, _resolver$options8;
396
-
397
- resolver.functionName = ((_resolver$options7 = resolver.options) === null || _resolver$options7 === void 0 ? void 0 : _resolver$options7.functionName) ?? '';
398
- (_resolver$options8 = resolver.options) === null || _resolver$options8 === void 0 ? true : delete _resolver$options8.functionName;
399
- }
400
- }
401
-
402
- if (resolver.name.startsWith('rest')) {
403
- if (!resolver.path) {
404
- var _resolver$options11;
405
-
406
- if (resolver.pathParams) {
407
- var _resolver$options9;
408
-
409
- resolver.path = { ...resolver.pathParams,
410
- serialize: { ...resolver.pathParams.serialize,
411
- template: (_resolver$options9 = resolver.options) === null || _resolver$options9 === void 0 ? void 0 : _resolver$options9.path
412
- }
413
- };
414
- } else {
415
- var _resolver$options10;
416
-
417
- resolver.path = ((_resolver$options10 = resolver.options) === null || _resolver$options10 === void 0 ? void 0 : _resolver$options10.path) ?? '';
418
- }
419
-
420
- (_resolver$options11 = resolver.options) === null || _resolver$options11 === void 0 ? true : delete _resolver$options11.path;
421
- }
422
- }
423
- /**
424
- * `resolver.name` was previously validated with app code and v3.9.0
425
- * enumerates the previous validation, making this assertion safe.
426
- */
427
-
428
-
429
- return resolver;
430
- };
431
- /**
432
- * Function will visit each resolver in the schema and mutate them.
433
- */
434
-
435
-
436
- visit(projectSchema, ['resolver', '@resolver'], resolver => {
437
- if (resolver.compose) {
438
- resolver.compose.forEach(ensureResolverOptions);
439
- } else {
440
- ensureResolverOptions(resolver);
441
- }
442
- });
443
- return { ...projectSchema,
444
- schemaVersion: '3.9.0'
445
- };
446
- }
447
-
448
- function migrateQueryToV3_10(query, queryName) {
449
- const {
450
- args,
451
- shape
452
- } = query;
453
-
454
- if (typeof args === 'object' && ('oneOf' in args || 'allOf' in args || '$ref' in args || '@ref' in args)) {
455
- // As of 11/15/2021 no production schemas contained queries with these args
456
- throw new Error(`Query "${queryName}" contains an unsupported arg schema ${JSON.stringify(args)}. Please contact support`);
457
- }
458
-
459
- if (typeof shape === 'object' && !shape.items['@ref']) {
460
- // As of 11/15/2021 no production schemas contained queries with array return shapes that are not @refs
461
- throw new Error(`Query "${queryName}" contains an unsupported shape schema ${JSON.stringify(shape)}. Please contact support`);
462
- }
463
-
464
- return query;
465
- }
466
-
467
- function migrateShapeToV3_10(shape) {
468
- const {
469
- schema,
470
- ...rest
471
- } = shape; // As of 11/15/2021 no production schemas contained shapes with array schemas
472
-
473
- if ('type' in schema && schema.type === 'array') {
474
- throw new Error(`Shape ${shape.name} uses an unsupported array schema. Please contact support`);
475
- }
476
-
477
- const newSchema = '$ref' in schema || '@ref' in schema ? {
478
- allOf: [schema]
479
- } : schema;
480
- return { ...rest,
481
- schema: newSchema
482
- };
483
- }
484
-
485
- export function migrateToV3_10(projectSchema) {
486
- const {
487
- queries,
488
- mutations,
489
- shapes,
490
- schemaVersion,
491
- ...rest
492
- } = projectSchema;
493
- return { ...rest,
494
- queries: mapValues(queries, migrateQueryToV3_10),
495
- mutations: mapValues(mutations, migrateQueryToV3_10),
496
- shapes: mapValues(shapes, migrateShapeToV3_10),
497
- schemaVersion: '3.10.0'
498
- };
499
- }
500
- export async function migrateToLatestProjectSchema(context, projectSchema) {
501
- if (projectSchema.schemaVersion === '4.0.0') {
502
- throw new Error('You are using an unreleased schema version. Migration is not possible');
503
- }
504
-
505
- if (isProjectSchemaV1(projectSchema)) {
506
- projectSchema = migrateToV3(projectSchema);
507
- }
508
-
509
- if (isProjectSchemaV3(projectSchema)) {
510
- projectSchema = await migrateToV3_1(context, projectSchema);
511
- }
512
-
513
- if (isProjectSchemaV3_1(projectSchema)) {
514
- projectSchema = migrateToV3_2(projectSchema);
515
- }
516
-
517
- if (isProjectSchemaV3_2(projectSchema)) {
518
- projectSchema = await migrateToV3_3(context, projectSchema);
519
- }
520
-
521
- if (isProjectSchemaV3_3(projectSchema)) {
522
- projectSchema = migrateToV3_4(projectSchema);
523
- }
524
-
525
- if (isProjectSchemaV3_4(projectSchema)) {
526
- projectSchema = migrateToV3_5(projectSchema);
527
- }
528
-
529
- if (isProjectSchemaV3_5(projectSchema)) {
530
- projectSchema = migrateToV3_5_1(projectSchema);
531
- }
532
-
533
- if (isProjectSchemaV3_5_1(projectSchema)) {
534
- projectSchema = migrateToV3_6(projectSchema);
535
- }
536
-
537
- if (isProjectSchemaV3_6(projectSchema)) {
538
- projectSchema = migrateToV3_7(projectSchema);
539
- }
540
-
541
- if (isProjectSchemaV3_7(projectSchema)) {
542
- projectSchema = migrateToV3_8(projectSchema);
543
- }
544
-
545
- if (isProjectSchemaV3_8(projectSchema)) {
546
- projectSchema = migrateToV3_9_0(projectSchema);
547
- }
548
-
549
- if (isProjectSchemaV3_9(projectSchema)) {
550
- projectSchema = migrateToV3_10(projectSchema);
551
- }
552
-
553
- return projectSchema;
554
- }
555
- export function normalizeSchemaVersion(version) {
556
- return version === undefined ? '1' : version;
557
- }
558
- export function isV1Like(schema) {
559
- return Boolean(schema.schemaVersion === '1' || schema.schemaVersion === undefined);
560
- }
561
- export function isV1(schema) {
562
- return Boolean(isV1Like(schema));
563
- }
564
- export function isV3Like(schema) {
565
- return schema.schemaVersion === '3';
566
- }
567
- export function isV3(schema) {
568
- return isV3Like(schema);
569
- }
570
- export async function ensureLatest(context, schema) {
571
- if (!schema || isLatestProjectSchema(schema)) {
572
- return schema;
573
- }
574
-
575
- return migrateToLatestProjectSchema(context, schema);
576
- }
@@ -1,59 +0,0 @@
1
- import type { ProjectSchema, AnyProjectSchema, ProjectSchemaV1_0_0, ProjectSchemaV3_0_0, ProjectSchemaV3_1_0, ProjectSchemaV3_2_0, ProjectSchemaV3_3_0, ProjectSchemaV3_4_0, ProjectSchemaV3_5_0, ProjectSchemaV3_5_1, ProjectSchemaV3_6_0, ProjectSchemaV3_7_0, ProjectSchemaV3_8_0, ProjectSchemaV3_9_0, ProjectSchemaV3_10_0, PropertySchema, ContentTypeV1_0_0, ContentSchemaV1_0_0, Relationship, FormConfig, Workflow, Shape, ShapeMapV3_0_0, ContentSchemaV3_0_0 } from './project-schema';
2
- import type { EncryptFn } from './services';
3
- import { SafeDecryptFn } from './services';
4
- export declare const listTypePrefix = "PaginatedList";
5
- interface ConversionParams {
6
- shapeName: string;
7
- shapeTitle: string;
8
- schema: ContentSchemaV1_0_0;
9
- service: string;
10
- key: string;
11
- name: string;
12
- depth: number;
13
- setSource?: boolean;
14
- omitAllSources?: boolean;
15
- parentSchema?: ContentSchemaV1_0_0;
16
- }
17
- export interface ProjectSchemaUpdate extends Omit<Partial<ProjectSchema>, 'shapes' | 'forms' | 'workflows'> {
18
- shapes?: Record<string, Shape | null>;
19
- forms?: Record<string, FormConfig | null>;
20
- workflows?: Record<string, Workflow | null>;
21
- deactivated?: number;
22
- }
23
- declare type GenerateDataKeyFn = () => Promise<string>;
24
- export interface ProjectSchemaMigrationContext {
25
- generateDataKeyFn: GenerateDataKeyFn;
26
- encryptFn: EncryptFn;
27
- decryptFn: SafeDecryptFn;
28
- }
29
- export declare function getRelationshipSchema(relationship: Relationship): PropertySchema;
30
- export declare function migrateToContentSchemaV3(params: ConversionParams): {
31
- schema: ContentSchemaV3_0_0;
32
- hoistedShapes?: ShapeMapV3_0_0;
33
- };
34
- export declare function contentTypeToShape(contentType: ContentTypeV1_0_0, contentTypeId: string): ShapeMapV3_0_0;
35
- export declare function migrateToV3(projectSchema: ProjectSchemaV1_0_0): ProjectSchemaV3_0_0;
36
- export declare function migrateToV3_1(context: ProjectSchemaMigrationContext, projectSchema: ProjectSchemaV3_0_0): Promise<ProjectSchemaV3_1_0>;
37
- export declare function migrateToV3_2(projectSchema: ProjectSchemaV3_1_0): ProjectSchemaV3_2_0;
38
- export declare function migrateToV3_3(context: ProjectSchemaMigrationContext, projectSchema: ProjectSchemaV3_2_0): Promise<ProjectSchemaV3_3_0>;
39
- export declare function migrateToV3_4(projectSchema: ProjectSchemaV3_3_0): ProjectSchemaV3_4_0;
40
- export declare function migrateToV3_5(projectSchema: ProjectSchemaV3_4_0): ProjectSchemaV3_5_0;
41
- export declare function migrateToV3_5_1(projectSchema: ProjectSchemaV3_5_0): ProjectSchemaV3_5_1;
42
- export declare function migrateToV3_6(projectSchema: ProjectSchemaV3_5_1): ProjectSchemaV3_6_0;
43
- export declare function migrateToV3_7(projectSchema: ProjectSchemaV3_6_0): ProjectSchemaV3_7_0;
44
- export declare function migrateToV3_8(projectSchema: ProjectSchemaV3_7_0): ProjectSchemaV3_8_0;
45
- export declare function migrateToV3_9_0(projectSchema: ProjectSchemaV3_8_0): ProjectSchemaV3_9_0;
46
- export declare function migrateToV3_10(projectSchema: ProjectSchemaV3_9_0): ProjectSchemaV3_10_0;
47
- export declare function migrateToLatestProjectSchema(context: ProjectSchemaMigrationContext, projectSchema: AnyProjectSchema): Promise<ProjectSchema>;
48
- export declare function normalizeSchemaVersion(version?: string): string;
49
- export declare function isV1Like(schema: {
50
- schemaVersion?: string;
51
- }): boolean;
52
- export declare function isV1(schema: AnyProjectSchema): schema is ProjectSchemaV1_0_0;
53
- export declare function isV3Like(schema: {
54
- schemaVersion?: string;
55
- }): boolean;
56
- export declare function isV3(schema: AnyProjectSchema): schema is ProjectSchemaV3_0_0;
57
- export declare function ensureLatest(context: ProjectSchemaMigrationContext, schema?: AnyProjectSchema): Promise<ProjectSchema | undefined>;
58
- export {};
59
- //# sourceMappingURL=migration.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"migration.d.ts","sourceRoot":"","sources":["../../src/migration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EASpB,cAAc,EACd,iBAAiB,EAEjB,mBAAmB,EACnB,YAAY,EACZ,UAAU,EACV,QAAQ,EAER,KAAK,EACL,cAAc,EAOd,mBAAmB,EAEpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,YAAY,CAAC;AAc1C,OAAO,EAAC,aAAa,EAA8B,M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