@takeshape/schema 7.194.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 +5 -0
- package/es/api-version.js +21 -0
- package/es/auth-schemas.js +0 -0
- package/es/builtin-schema.js +590 -0
- package/es/content-schema-transform.js +192 -0
- package/es/entitlements.js +0 -0
- package/es/enum.js +11 -0
- package/es/get-is-leaf.js +58 -0
- package/es/index.js +25 -0
- package/es/migration.js +413 -0
- package/es/mocks.js +47 -0
- package/es/patterns.js +0 -0
- package/es/project-schema/index.js +10 -0
- package/es/project-schema/v1.0.0.js +0 -0
- package/es/project-schema/v3.0.0.js +0 -0
- package/es/project-schema/v3.1.0.js +0 -0
- package/es/project-schema/v3.2.0.js +0 -0
- package/es/project-schema/v3.3.0.js +0 -0
- package/es/project-schema/v3.4.0.js +0 -0
- package/es/project-schema/v3.5.0.js +0 -0
- package/es/project-schema/v3.5.1.js +0 -0
- package/es/project-schema/v3.6.0.js +0 -0
- package/es/refs.js +301 -0
- package/es/resolvers.js +2 -0
- package/es/scalars.js +4 -0
- package/es/schema-util.js +1197 -0
- package/es/schemas/auth-schemas.json +313 -0
- package/es/schemas/project-schema/meta-schema-v1.0.0.json +209 -0
- package/es/schemas/project-schema/meta-schema-v3.0.0.json +609 -0
- package/es/schemas/project-schema/meta-schema-v3.1.0.json +609 -0
- package/es/schemas/project-schema/meta-schema-v3.2.0.json +613 -0
- package/es/schemas/project-schema/meta-schema-v3.3.0.json +613 -0
- package/es/schemas/project-schema/meta-schema-v3.4.0.json +613 -0
- package/es/schemas/project-schema/meta-schema-v3.5.0.json +627 -0
- package/es/schemas/project-schema/meta-schema-v3.5.1.json +630 -0
- package/es/schemas/project-schema/meta-schema-v3.6.0.json +633 -0
- package/es/schemas/project-schema/v1.0.0.json +321 -0
- package/es/schemas/project-schema/v3.0.0.json +411 -0
- package/es/schemas/project-schema/v3.1.0.json +569 -0
- package/es/schemas/project-schema/v3.2.0.json +577 -0
- package/es/schemas/project-schema/v3.3.0.json +578 -0
- package/es/schemas/project-schema/v3.4.0.json +568 -0
- package/es/schemas/project-schema/v3.5.0.json +568 -0
- package/es/schemas/project-schema/v3.5.1.json +568 -0
- package/es/schemas/project-schema/v3.6.0.json +584 -0
- package/es/schemas/project-schema.json +16 -0
- package/es/schemas/user-schema.json +58 -0
- package/es/services.js +379 -0
- package/es/taxonomies.js +55 -0
- package/es/template-shapes.js +79 -0
- package/es/types.js +202 -0
- package/es/unions.js +137 -0
- package/es/user-schema.js +0 -0
- package/es/util/detect-cycles.js +54 -0
- package/es/util/index.js +1 -0
- package/es/validate.js +764 -0
- package/es/versions.js +4 -0
- package/es/workflows.js +69 -0
- package/examples/.pnpm-debug.log +20 -0
- package/examples/v1_0_0/beer-schema.json +125 -0
- package/examples/v1_0_0/blog-schema.json +192 -0
- package/examples/v1_0_0/brewery-schema.json +232 -0
- package/examples/v1_0_0/complex-project-schema.json +3197 -0
- package/examples/v1_0_0/error-schema.json +275 -0
- package/examples/v1_0_0/frank-and-fred-schema.json +21387 -0
- package/examples/v1_0_0/massive-schema.json +6930 -0
- package/examples/v1_0_0/post-schema.json +83 -0
- package/examples/v1_0_0/real-world-schema.json +797 -0
- package/examples/v1_0_0/recursive-repeater-schema.json +69 -0
- package/examples/v1_0_0/recursive-schema.json +79 -0
- package/examples/v1_0_0/schema-with-repeater-draftjs.json +292 -0
- package/examples/v1_0_0/shape-books.json +797 -0
- package/examples/v1_0_0/user-schema-no-required.json +84 -0
- package/examples/v1_0_0/user-schema-with-defaults.json +105 -0
- package/examples/v1_0_0/user-schema-with-obj-prop.json +92 -0
- package/examples/v1_0_0/user-schema.json +87 -0
- package/examples/v3_0_0/rick-and-morty-rest.json +62 -0
- package/examples/v3_0_0/shopify-lookbook.json +1172 -0
- package/examples/v3_0_0/shopify-store-with-widget.json +11323 -0
- package/examples/v3_2_0/blog-schema.json +378 -0
- package/examples/v3_2_0/brewery-schema.json +385 -0
- package/examples/v3_2_0/complex-project-schema.json +3748 -0
- package/examples/v3_2_0/frank-and-fred-schema.json +19217 -0
- package/examples/v3_2_0/massive-schema.json +6676 -0
- package/examples/v3_2_0/pet-oneof-array.json +323 -0
- package/examples/v3_2_0/post-schema.json +265 -0
- package/examples/v3_2_0/real-world-schema.json +970 -0
- package/examples/v3_2_0/recursive-repeater-schema.json +144 -0
- package/examples/v3_2_0/recursive-schema.json +151 -0
- package/examples/v3_2_0/rick-and-morty-rest.json +65 -0
- package/examples/v3_2_0/schema-with-repeater-draftjs.json +381 -0
- package/examples/v3_2_0/shape-books.json +1044 -0
- package/examples/v3_2_0/shopify-store-with-widget.json +11016 -0
- package/examples/v3_2_0/user-schema-no-required.json +174 -0
- package/examples/v3_2_0/user-schema-with-defaults.json +187 -0
- package/examples/v3_3_0/blog-schema.json +405 -0
- package/examples/v3_3_0/brewery-schema.json +406 -0
- package/examples/v3_3_0/complex-project-schema.json +4076 -0
- package/examples/v3_3_0/frank-and-fred-schema.json +20913 -0
- package/examples/v3_3_0/massive-schema.json +7309 -0
- package/examples/v3_3_0/pet-oneof-array.json +380 -0
- package/examples/v3_3_0/post-schema.json +248 -0
- package/examples/v3_3_0/real-world-schema.json +1046 -0
- package/examples/v3_3_0/recursive-repeater-schema.json +154 -0
- package/examples/v3_3_0/recursive-schema.json +161 -0
- package/examples/v3_3_0/rick-and-morty-rest.json +101 -0
- package/examples/v3_3_0/schema-with-repeater-draftjs.json +393 -0
- package/examples/v3_3_0/shape-books.json +1121 -0
- package/examples/v3_3_0/shopify-lookbook.json +1196 -0
- package/examples/v3_3_0/shopify-store-with-widget.json +11320 -0
- package/examples/v3_3_0/user-schema-no-required.json +185 -0
- package/examples/v3_3_0/user-schema-with-defaults.json +210 -0
- package/examples/v3_4_0/blog-schema.json +405 -0
- package/examples/v3_4_0/brewery-schema.json +406 -0
- package/examples/v3_4_0/complex-project-schema.json +4076 -0
- package/examples/v3_4_0/frank-and-fred-schema.json +20913 -0
- package/examples/v3_4_0/massive-schema.json +7309 -0
- package/examples/v3_4_0/pet-oneof-array.json +420 -0
- package/examples/v3_4_0/post-schema.json +248 -0
- package/examples/v3_4_0/real-world-schema.json +1046 -0
- package/examples/v3_4_0/recursive-repeater-schema.json +154 -0
- package/examples/v3_4_0/recursive-schema.json +161 -0
- package/examples/v3_4_0/rick-and-morty-rest.json +101 -0
- package/examples/v3_4_0/schema-with-repeater-draftjs.json +393 -0
- package/examples/v3_4_0/shape-books.json +1121 -0
- package/examples/v3_4_0/shopify-lookbook.json +1196 -0
- package/examples/v3_4_0/shopify-store-with-widget.json +11323 -0
- package/examples/v3_4_0/user-schema-no-required.json +185 -0
- package/examples/v3_4_0/user-schema-with-defaults.json +210 -0
- package/examples/v3_5_0/blog-schema.json +405 -0
- package/examples/v3_5_0/brewery-schema.json +406 -0
- package/examples/v3_5_0/complex-project-schema.json +4076 -0
- package/examples/v3_5_0/frank-and-fred-schema.json +20913 -0
- package/examples/v3_5_0/massive-schema.json +7309 -0
- package/examples/v3_5_0/pet-oneof-array.json +420 -0
- package/examples/v3_5_0/post-schema.json +248 -0
- package/examples/v3_5_0/real-world-schema.json +1046 -0
- package/examples/v3_5_0/recursive-repeater-schema.json +154 -0
- package/examples/v3_5_0/recursive-schema.json +161 -0
- package/examples/v3_5_0/rick-and-morty-rest.json +101 -0
- package/examples/v3_5_0/schema-with-repeater-draftjs.json +393 -0
- package/examples/v3_5_0/shape-books.json +1121 -0
- package/examples/v3_5_0/shopify-lookbook.json +1196 -0
- package/examples/v3_5_0/shopify-store-with-widget.json +12271 -0
- package/examples/v3_5_0/user-schema-no-required.json +185 -0
- package/examples/v3_5_0/user-schema-with-defaults.json +210 -0
- package/examples/v3_5_1/blog-schema.json +405 -0
- package/examples/v3_5_1/brewery-schema.json +406 -0
- package/examples/v3_5_1/complex-project-schema.json +4076 -0
- package/examples/v3_5_1/frank-and-fred-schema.json +20913 -0
- package/examples/v3_5_1/massive-schema.json +7309 -0
- package/examples/v3_5_1/pet-oneof-array.json +420 -0
- package/examples/v3_5_1/post-schema.json +248 -0
- package/examples/v3_5_1/real-world-schema.json +1046 -0
- package/examples/v3_5_1/recursive-repeater-schema.json +154 -0
- package/examples/v3_5_1/recursive-schema.json +161 -0
- package/examples/v3_5_1/rick-and-morty-rest.json +101 -0
- package/examples/v3_5_1/schema-with-repeater-draftjs.json +393 -0
- package/examples/v3_5_1/shape-books.json +1121 -0
- package/examples/v3_5_1/shopify-lookbook.json +1196 -0
- package/examples/v3_5_1/shopify-store-with-widget.json +12271 -0
- package/examples/v3_5_1/stripe-starter-resolved.json +21419 -0
- package/examples/v3_5_1/user-schema-no-required.json +185 -0
- package/examples/v3_5_1/user-schema-with-defaults.json +210 -0
- package/examples/v3_6_0/blog-schema.json +405 -0
- package/examples/v3_6_0/brewery-schema.json +406 -0
- package/examples/v3_6_0/complex-project-schema.json +4076 -0
- package/examples/v3_6_0/frank-and-fred-schema.json +20913 -0
- package/examples/v3_6_0/massive-schema.json +7309 -0
- package/examples/v3_6_0/pet-oneof-array.json +420 -0
- package/examples/v3_6_0/post-schema.json +248 -0
- package/examples/v3_6_0/real-world-schema.json +1046 -0
- package/examples/v3_6_0/recursive-repeater-schema.json +154 -0
- package/examples/v3_6_0/recursive-schema.json +161 -0
- package/examples/v3_6_0/rick-and-morty-rest.json +101 -0
- package/examples/v3_6_0/schema-with-repeater-draftjs.json +393 -0
- package/examples/v3_6_0/shape-books.json +1121 -0
- package/examples/v3_6_0/shopify-lookbook.json +1196 -0
- package/examples/v3_6_0/shopify-store-with-widget.json +12271 -0
- package/examples/v3_6_0/stripe-starter-resolved.json +21419 -0
- package/examples/v3_6_0/user-schema-no-required.json +185 -0
- package/examples/v3_6_0/user-schema-with-defaults.json +210 -0
- package/lib/api-version.d.ts +6 -0
- package/lib/api-version.d.ts.map +1 -0
- package/lib/api-version.js +36 -0
- package/lib/auth-schemas.d.ts +105 -0
- package/lib/auth-schemas.d.ts.map +1 -0
- package/lib/auth-schemas.js +1 -0
- package/lib/builtin-schema.d.ts +8 -0
- package/lib/builtin-schema.d.ts.map +1 -0
- package/lib/builtin-schema.js +606 -0
- package/lib/content-schema-transform.d.ts +41 -0
- package/lib/content-schema-transform.d.ts.map +1 -0
- package/lib/content-schema-transform.js +217 -0
- package/lib/entitlements.d.ts +1 -0
- package/lib/entitlements.d.ts.map +1 -0
- package/lib/entitlements.js +1 -0
- package/lib/enum.d.ts +3 -0
- package/lib/enum.d.ts.map +1 -0
- package/lib/enum.js +18 -0
- package/lib/get-is-leaf.d.ts +4 -0
- package/lib/get-is-leaf.d.ts.map +1 -0
- package/lib/get-is-leaf.js +68 -0
- package/lib/index.d.ts +27 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +359 -0
- package/lib/migration.d.ts +55 -0
- package/lib/migration.d.ts.map +1 -0
- package/lib/migration.js +463 -0
- package/lib/mocks.d.ts +13 -0
- package/lib/mocks.d.ts.map +1 -0
- package/lib/mocks.js +61 -0
- package/lib/patterns.d.ts +13 -0
- package/lib/patterns.d.ts.map +1 -0
- package/lib/patterns.js +1 -0
- package/lib/project-schema/index.d.ts +21 -0
- package/lib/project-schema/index.d.ts.map +1 -0
- package/lib/project-schema/index.js +122 -0
- package/lib/project-schema/v1.0.0.d.ts +293 -0
- package/lib/project-schema/v1.0.0.d.ts.map +1 -0
- package/lib/project-schema/v1.0.0.js +1 -0
- package/lib/project-schema/v3.0.0.d.ts +480 -0
- package/lib/project-schema/v3.0.0.d.ts.map +1 -0
- package/lib/project-schema/v3.0.0.js +1 -0
- package/lib/project-schema/v3.1.0.d.ts +623 -0
- package/lib/project-schema/v3.1.0.d.ts.map +1 -0
- package/lib/project-schema/v3.1.0.js +1 -0
- package/lib/project-schema/v3.2.0.d.ts +634 -0
- package/lib/project-schema/v3.2.0.d.ts.map +1 -0
- package/lib/project-schema/v3.2.0.js +1 -0
- package/lib/project-schema/v3.3.0.d.ts +634 -0
- package/lib/project-schema/v3.3.0.d.ts.map +1 -0
- package/lib/project-schema/v3.3.0.js +1 -0
- package/lib/project-schema/v3.4.0.d.ts +626 -0
- package/lib/project-schema/v3.4.0.d.ts.map +1 -0
- package/lib/project-schema/v3.4.0.js +1 -0
- package/lib/project-schema/v3.5.0.d.ts +651 -0
- package/lib/project-schema/v3.5.0.d.ts.map +1 -0
- package/lib/project-schema/v3.5.0.js +1 -0
- package/lib/project-schema/v3.5.1.d.ts +651 -0
- package/lib/project-schema/v3.5.1.d.ts.map +1 -0
- package/lib/project-schema/v3.5.1.js +1 -0
- package/lib/project-schema/v3.6.0.d.ts +660 -0
- package/lib/project-schema/v3.6.0.d.ts.map +1 -0
- package/lib/project-schema/v3.6.0.js +1 -0
- package/lib/refs.d.ts +122 -0
- package/lib/refs.d.ts.map +1 -0
- package/lib/refs.js +359 -0
- package/lib/resolvers.d.ts +4 -0
- package/lib/resolvers.d.ts.map +1 -0
- package/lib/resolvers.js +10 -0
- package/lib/scalars.d.ts +3 -0
- package/lib/scalars.d.ts.map +1 -0
- package/lib/scalars.js +13 -0
- package/lib/schema-util.d.ts +201 -0
- package/lib/schema-util.d.ts.map +1 -0
- package/lib/schema-util.js +1353 -0
- package/lib/schemas/auth-schemas.json +313 -0
- package/lib/schemas/project-schema/meta-schema-v1.0.0.json +209 -0
- package/lib/schemas/project-schema/meta-schema-v3.0.0.json +609 -0
- package/lib/schemas/project-schema/meta-schema-v3.1.0.json +609 -0
- package/lib/schemas/project-schema/meta-schema-v3.2.0.json +613 -0
- package/lib/schemas/project-schema/meta-schema-v3.3.0.json +613 -0
- package/lib/schemas/project-schema/meta-schema-v3.4.0.json +613 -0
- package/lib/schemas/project-schema/meta-schema-v3.5.0.json +627 -0
- package/lib/schemas/project-schema/meta-schema-v3.5.1.json +630 -0
- package/lib/schemas/project-schema/meta-schema-v3.6.0.json +633 -0
- package/lib/schemas/project-schema/v1.0.0.json +321 -0
- package/lib/schemas/project-schema/v3.0.0.json +411 -0
- package/lib/schemas/project-schema/v3.1.0.json +569 -0
- package/lib/schemas/project-schema/v3.2.0.json +577 -0
- package/lib/schemas/project-schema/v3.3.0.json +578 -0
- package/lib/schemas/project-schema/v3.4.0.json +568 -0
- package/lib/schemas/project-schema/v3.5.0.json +568 -0
- package/lib/schemas/project-schema/v3.5.1.json +568 -0
- package/lib/schemas/project-schema/v3.6.0.json +584 -0
- package/lib/schemas/project-schema.json +16 -0
- package/lib/schemas/user-schema.json +58 -0
- package/lib/services.d.ts +71 -0
- package/lib/services.d.ts.map +1 -0
- package/lib/services.js +413 -0
- package/lib/taxonomies.d.ts +16 -0
- package/lib/taxonomies.d.ts.map +1 -0
- package/lib/taxonomies.js +69 -0
- package/lib/template-shapes.d.ts +32 -0
- package/lib/template-shapes.d.ts.map +1 -0
- package/lib/template-shapes.js +100 -0
- package/lib/types.d.ts +187 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +289 -0
- package/lib/unions.d.ts +29 -0
- package/lib/unions.d.ts.map +1 -0
- package/lib/unions.js +167 -0
- package/lib/user-schema.d.ts +39 -0
- package/lib/user-schema.d.ts.map +1 -0
- package/lib/user-schema.js +1 -0
- package/lib/util/detect-cycles.d.ts +6 -0
- package/lib/util/detect-cycles.d.ts.map +1 -0
- package/lib/util/detect-cycles.js +61 -0
- package/lib/util/index.d.ts +2 -0
- package/lib/util/index.d.ts.map +1 -0
- package/lib/util/index.js +18 -0
- package/lib/validate.d.ts +49 -0
- package/lib/validate.d.ts.map +1 -0
- package/lib/validate.js +823 -0
- package/lib/versions.d.ts +5 -0
- package/lib/versions.d.ts.map +1 -0
- package/lib/versions.js +14 -0
- package/lib/workflows.d.ts +15 -0
- package/lib/workflows.d.ts.map +1 -0
- package/lib/workflows.js +92 -0
- package/package.json +65 -0
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import forEach from 'lodash/forEach';
|
|
2
|
+
import difference from 'lodash/difference';
|
|
3
|
+
import pick from 'lodash/pick';
|
|
4
|
+
import { getKey, dereferenceSchema } from './schema-util';
|
|
5
|
+
import { isArraySchema, isObjectSchema } from './types';
|
|
6
|
+
import { getRefShapeName } from './refs';
|
|
7
|
+
import { enumerateOneOfKeys, isUnionSchema } from './unions';
|
|
8
|
+
const typeCache = new WeakMap();
|
|
9
|
+
export function getType(schema) {
|
|
10
|
+
let type = typeCache.get(schema);
|
|
11
|
+
|
|
12
|
+
if (type) {
|
|
13
|
+
return type;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
type = schema.type; // handle nullable types for example: ['object', 'null']
|
|
17
|
+
|
|
18
|
+
if (Array.isArray(type)) {
|
|
19
|
+
const filtered = type.filter(name => name !== 'null');
|
|
20
|
+
|
|
21
|
+
if (!filtered.length) {
|
|
22
|
+
throw new Error(`Invalid schema`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type = filtered[0];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
typeCache.set(schema, type);
|
|
29
|
+
return type;
|
|
30
|
+
}
|
|
31
|
+
export function toName(name) {
|
|
32
|
+
return name;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function ensureArray(value) {
|
|
36
|
+
return Array.isArray(value) ? value : [value];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function preferKey(name, schema) {
|
|
40
|
+
var _getKey;
|
|
41
|
+
|
|
42
|
+
return (_getKey = getKey(schema)) !== null && _getKey !== void 0 ? _getKey : name;
|
|
43
|
+
}
|
|
44
|
+
export function findTransforms(pluginMap, schema, name, shape) {
|
|
45
|
+
const type = getType(schema);
|
|
46
|
+
|
|
47
|
+
if (pluginMap && (pluginMap[type] || pluginMap['*'])) {
|
|
48
|
+
var _pluginMap$type, _pluginMap$;
|
|
49
|
+
|
|
50
|
+
const plugins = ((_pluginMap$type = pluginMap[type]) !== null && _pluginMap$type !== void 0 ? _pluginMap$type : []).concat((_pluginMap$ = pluginMap['*']) !== null && _pluginMap$ !== void 0 ? _pluginMap$ : []);
|
|
51
|
+
return plugins.find(plugin => plugin.filter(schema, name, shape));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
export function getContentTransform({
|
|
57
|
+
transforms,
|
|
58
|
+
accumulators,
|
|
59
|
+
keyTransform = preferKey,
|
|
60
|
+
sourceKeyTransform = preferKey,
|
|
61
|
+
passThrough = true,
|
|
62
|
+
projectSchema
|
|
63
|
+
}) {
|
|
64
|
+
const prepare = (schema, obj, name = '') => {
|
|
65
|
+
const shapeName = getRefShapeName(projectSchema, schema);
|
|
66
|
+
schema = dereferenceSchema(projectSchema, schema);
|
|
67
|
+
|
|
68
|
+
if (accumulators) {
|
|
69
|
+
accumulators.forEach(accumulator => {
|
|
70
|
+
accumulator.accumulate(obj, schema, name);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const shape = shapeName ? projectSchema.shapes[shapeName] : undefined;
|
|
75
|
+
const transform = findTransforms(transforms, schema, name, shape);
|
|
76
|
+
|
|
77
|
+
if (transform) {
|
|
78
|
+
const next = (value, schema, name) => prepare(schema, value, name);
|
|
79
|
+
|
|
80
|
+
return transform.process(obj, schema, name, shape, next);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (obj && isUnionSchema(schema)) {
|
|
84
|
+
for (const {
|
|
85
|
+
shapeId,
|
|
86
|
+
propSchema
|
|
87
|
+
} of enumerateOneOfKeys(projectSchema, schema.oneOf)) {
|
|
88
|
+
if (obj._shapeId === shapeId) {
|
|
89
|
+
return prepare(propSchema, obj, name);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (obj && isObjectSchema(schema)) {
|
|
95
|
+
const result = {};
|
|
96
|
+
const assigned = new Set();
|
|
97
|
+
forEach(schema.properties, (fieldSchema, name) => {
|
|
98
|
+
const sourceKeys = ensureArray(sourceKeyTransform(name, fieldSchema));
|
|
99
|
+
|
|
100
|
+
for (const sourceKey of sourceKeys) {
|
|
101
|
+
const value = prepare(fieldSchema, obj === null || obj === void 0 ? void 0 : obj[sourceKey], name);
|
|
102
|
+
|
|
103
|
+
if (value !== undefined) {
|
|
104
|
+
assigned.add(sourceKey);
|
|
105
|
+
const transform = findTransforms(transforms, dereferenceSchema(projectSchema, fieldSchema), name);
|
|
106
|
+
const getKey = transform !== null && transform !== void 0 && transform.keyTransform ? transform.keyTransform : keyTransform;
|
|
107
|
+
result[getKey(name, fieldSchema, sourceKey)] = value;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
if (passThrough && obj) {
|
|
113
|
+
const keys = difference(Object.keys(obj), [...assigned]);
|
|
114
|
+
|
|
115
|
+
if (keys.length) {
|
|
116
|
+
Object.assign(result, pick(obj, keys));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (isArraySchema(schema)) {
|
|
124
|
+
const itemSchema = schema.items;
|
|
125
|
+
|
|
126
|
+
if (Array.isArray(obj)) {
|
|
127
|
+
return obj.map(item => prepare(itemSchema, item, name));
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (obj === undefined) {
|
|
131
|
+
prepare(itemSchema, obj, name);
|
|
132
|
+
}
|
|
133
|
+
} // allow properties that have not been transformed
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
return passThrough ? obj : undefined;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
return prepare;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function transformKey(transforms, propSchema, name, transform = preferKey) {
|
|
143
|
+
const schemaTransform = findTransforms(transforms, propSchema, name);
|
|
144
|
+
|
|
145
|
+
if (schemaTransform !== null && schemaTransform !== void 0 && schemaTransform.keyTransform) {
|
|
146
|
+
transform = schemaTransform.keyTransform;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return transform(name, propSchema);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function getPropertyInfo(context, schema, path) {
|
|
153
|
+
const {
|
|
154
|
+
projectSchema,
|
|
155
|
+
transforms,
|
|
156
|
+
keyTransform
|
|
157
|
+
} = context;
|
|
158
|
+
const result = [];
|
|
159
|
+
|
|
160
|
+
const findProperty = (currentSchema, name, rest, path) => {
|
|
161
|
+
if (isObjectSchema(currentSchema)) {
|
|
162
|
+
const propSchema = currentSchema.properties[name];
|
|
163
|
+
|
|
164
|
+
if (!propSchema) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const refSchema = dereferenceSchema(projectSchema, propSchema);
|
|
169
|
+
const nextPath = path.concat(transformKey(transforms, refSchema, name, keyTransform));
|
|
170
|
+
|
|
171
|
+
if (rest.length) {
|
|
172
|
+
const [nextName, ...nextRest] = rest;
|
|
173
|
+
findProperty(refSchema, nextName, nextRest, nextPath);
|
|
174
|
+
} else {
|
|
175
|
+
result.push({
|
|
176
|
+
schema: refSchema,
|
|
177
|
+
key: nextPath.join('.')
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
} else if (isUnionSchema(currentSchema)) {
|
|
181
|
+
for (const optionSchema of currentSchema.oneOf) {
|
|
182
|
+
findProperty(dereferenceSchema(projectSchema, optionSchema), name, rest, path);
|
|
183
|
+
}
|
|
184
|
+
} else if (isArraySchema(currentSchema)) {
|
|
185
|
+
findProperty(dereferenceSchema(projectSchema, currentSchema.items), name, rest, path);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const [first, ...rest] = path.split('.');
|
|
190
|
+
findProperty(dereferenceSchema(projectSchema, schema), first, rest, []);
|
|
191
|
+
return result;
|
|
192
|
+
}
|
|
File without changes
|
package/es/enum.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { getType } from './content-schema-transform';
|
|
2
|
+
import { getKey, isBuiltinType } from './schema-util';
|
|
3
|
+
import { followRef, getRefShapeName } from './refs';
|
|
4
|
+
const scalarTags = new Set(['draftjs']);
|
|
5
|
+
|
|
6
|
+
function isLeafTypeV3(projectSchema, contentSchema) {
|
|
7
|
+
const type = getType(contentSchema);
|
|
8
|
+
return Boolean( // must have key
|
|
9
|
+
getKey(contentSchema) && ( // if is not a structure, then is a leaf
|
|
10
|
+
!['object', 'array'].includes(type) || // if is relationship, then is a leaf
|
|
11
|
+
contentSchema['@relationship'] || contentSchema['@tag'] && scalarTags.has(contentSchema['@tag']) || // if is array, then should not be a synchronized structure
|
|
12
|
+
type === 'array' && !contentSchema['@syncLocaleStructure'] || isBuiltinType(projectSchema, contentSchema)));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function getIsLeaf(projectSchema, shapeSchema) {
|
|
16
|
+
const leafMap = new Set();
|
|
17
|
+
const shapesSeen = new Set();
|
|
18
|
+
|
|
19
|
+
const collectLeaves = schema => {
|
|
20
|
+
var _schema$oneOf;
|
|
21
|
+
|
|
22
|
+
const shapeName = getRefShapeName(projectSchema, schema);
|
|
23
|
+
schema = shapeName ? followRef(projectSchema, schema) : schema;
|
|
24
|
+
const key = getKey(schema);
|
|
25
|
+
|
|
26
|
+
if (key && isLeafTypeV3(projectSchema, schema)) {
|
|
27
|
+
leafMap.add(key);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (shapeName) {
|
|
31
|
+
// skip shapes we have already seen to avoid cycles
|
|
32
|
+
if (shapesSeen.has(shapeName)) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
shapesSeen.add(shapeName);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const combo = (_schema$oneOf = schema.oneOf) !== null && _schema$oneOf !== void 0 ? _schema$oneOf : schema.allOf;
|
|
40
|
+
|
|
41
|
+
if (combo) {
|
|
42
|
+
combo.map(collectLeaves);
|
|
43
|
+
} else if (schema.properties) {
|
|
44
|
+
for (const name of Object.keys(schema.properties)) {
|
|
45
|
+
collectLeaves(schema.properties[name]);
|
|
46
|
+
}
|
|
47
|
+
} else if (schema.items) {
|
|
48
|
+
collectLeaves(schema.items);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
collectLeaves(shapeSchema);
|
|
53
|
+
return key => {
|
|
54
|
+
// remove locale suffix
|
|
55
|
+
key = key ? key.split(':')[0] : key;
|
|
56
|
+
return Boolean(key && leafMap.has(key));
|
|
57
|
+
};
|
|
58
|
+
}
|
package/es/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export * from './content-schema-transform';
|
|
2
|
+
export * from './get-is-leaf';
|
|
3
|
+
export * from './project-schema';
|
|
4
|
+
export * from './schema-util';
|
|
5
|
+
export * from './services';
|
|
6
|
+
export * from './template-shapes';
|
|
7
|
+
export * from './taxonomies';
|
|
8
|
+
export * from './types';
|
|
9
|
+
export * from './workflows';
|
|
10
|
+
export * from './builtin-schema';
|
|
11
|
+
export * from './auth-schemas'; // Only export User here since AccessPolicyDocument is in auth-schemas
|
|
12
|
+
|
|
13
|
+
export * from './api-version';
|
|
14
|
+
export { listTypePrefix, ensureLatest, normalizeSchemaVersion, getRelationshipSchema, migrateToLatestProjectSchema } from './migration';
|
|
15
|
+
export * from './validate';
|
|
16
|
+
export { builtInShapes } from './builtin-schema';
|
|
17
|
+
export * from './versions';
|
|
18
|
+
export * from './mocks';
|
|
19
|
+
export * from './util';
|
|
20
|
+
export * from './resolvers';
|
|
21
|
+
export * from './scalars';
|
|
22
|
+
export * from './refs';
|
|
23
|
+
export * from './unions';
|
|
24
|
+
export * from './enum';
|
|
25
|
+
export * from './patterns';
|
package/es/migration.js
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
import pReduce from 'p-reduce';
|
|
2
|
+
import forEach from 'lodash/forEach';
|
|
3
|
+
import pick from 'lodash/pick';
|
|
4
|
+
import { upperCamel, deepClone } from '@takeshape/util';
|
|
5
|
+
import { arraySchemaKeys, getShapeQueriesAndMutations, multipleRelationshipSchemaKeys, objectSchemaKeys, scalarSchemaKeys, schemaMetadataKeys } from './schema-util';
|
|
6
|
+
import { updateServiceConfigV3ToV3_1 } from './services';
|
|
7
|
+
import { isProjectSchemaV1, isProjectSchemaV3, isLatestProjectSchema, isServiceAuthentication, isProjectSchemaV3_1, isProjectSchemaV3_2, isProjectSchemaV3_3, isProjectSchemaV3_4, isProjectSchemaV3_5, isProjectSchemaV3_5_1 } from './types';
|
|
8
|
+
export const listTypePrefix = 'PaginatedList';
|
|
9
|
+
const annotationMap = {
|
|
10
|
+
l10n: '@l10n',
|
|
11
|
+
sensitive: '@sensitive',
|
|
12
|
+
syncLocaleStructure: '@syncLocaleStructure'
|
|
13
|
+
};
|
|
14
|
+
export function getRelationshipSchema(relationship) {
|
|
15
|
+
const itemSchema = {
|
|
16
|
+
$ref: '#/shapes/TSRelationship/schema'
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
if (relationship.type === 'multiple') {
|
|
20
|
+
return {
|
|
21
|
+
type: 'array',
|
|
22
|
+
items: itemSchema,
|
|
23
|
+
'@relationship': relationship
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return { ...itemSchema,
|
|
28
|
+
'@relationship': relationship
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function isColor(schema) {
|
|
33
|
+
const {
|
|
34
|
+
type,
|
|
35
|
+
properties
|
|
36
|
+
} = schema;
|
|
37
|
+
return Boolean(type === 'object' && properties && properties.hsl && properties.hsv && properties.rgb && properties.hex);
|
|
38
|
+
} // eslint-disable-next-line complexity
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
export function migrateToContentSchemaV3(params) {
|
|
42
|
+
const {
|
|
43
|
+
schema,
|
|
44
|
+
service,
|
|
45
|
+
name,
|
|
46
|
+
key,
|
|
47
|
+
setSource,
|
|
48
|
+
omitAllSources
|
|
49
|
+
} = params;
|
|
50
|
+
const {
|
|
51
|
+
type
|
|
52
|
+
} = schema;
|
|
53
|
+
const mapping = !omitAllSources && key && setSource !== false && name !== key ? `${service}.${key}` : undefined;
|
|
54
|
+
forEach(schema, (value, key) => {
|
|
55
|
+
if (annotationMap[key]) {
|
|
56
|
+
const newAnnotation = annotationMap[key];
|
|
57
|
+
schema[newAnnotation] = value; // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
58
|
+
|
|
59
|
+
delete schema[key];
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
if (type === 'string' || type === 'boolean' || type === 'number' || type === 'integer') {
|
|
64
|
+
return {
|
|
65
|
+
schema: { ...pick(schema, scalarSchemaKeys),
|
|
66
|
+
'@mapping': mapping
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const {
|
|
72
|
+
relationship
|
|
73
|
+
} = schema;
|
|
74
|
+
|
|
75
|
+
if (relationship) {
|
|
76
|
+
const {
|
|
77
|
+
contentTypeIds,
|
|
78
|
+
type: relationshipType,
|
|
79
|
+
relatedName
|
|
80
|
+
} = relationship;
|
|
81
|
+
return {
|
|
82
|
+
schema: { ...pick(schema, relationshipType === 'multiple' ? multipleRelationshipSchemaKeys : schemaMetadataKeys),
|
|
83
|
+
'@mapping': mapping,
|
|
84
|
+
...getRelationshipSchema({
|
|
85
|
+
shapeIds: contentTypeIds,
|
|
86
|
+
type: relationshipType !== null && relationshipType !== void 0 ? relationshipType : 'single',
|
|
87
|
+
// type is optional on assets
|
|
88
|
+
relatedName
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (type === 'object' && schema.draftjs) {
|
|
95
|
+
return {
|
|
96
|
+
schema: { ...pick(schema, scalarSchemaKeys),
|
|
97
|
+
'@mapping': mapping,
|
|
98
|
+
'@tag': 'draftjs'
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (isColor(schema)) {
|
|
104
|
+
return {
|
|
105
|
+
schema: { ...pick(schema, scalarSchemaKeys),
|
|
106
|
+
$ref: '#/shapes/TSColor/schema',
|
|
107
|
+
'@mapping': mapping
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (type === 'object' && schema.properties) {
|
|
113
|
+
var _schema$title;
|
|
114
|
+
|
|
115
|
+
const properties = {};
|
|
116
|
+
let shapes = {};
|
|
117
|
+
const shapeTitle = [params.shapeTitle, upperCamel((_schema$title = schema.title) !== null && _schema$title !== void 0 ? _schema$title : params.name)].filter(Boolean).join(' ');
|
|
118
|
+
const shapeName = `${params.shapeName}${upperCamel(params.name)}`;
|
|
119
|
+
const contentSourceId = `takeshape:local:${shapeName}`;
|
|
120
|
+
forEach(schema.properties, (propSchema, name) => {
|
|
121
|
+
var _propSchema$key;
|
|
122
|
+
|
|
123
|
+
const {
|
|
124
|
+
schema: migratedPropSchema,
|
|
125
|
+
hoistedShapes
|
|
126
|
+
} = migrateToContentSchemaV3({ ...params,
|
|
127
|
+
shapeName,
|
|
128
|
+
shapeTitle,
|
|
129
|
+
depth: params.depth + 1,
|
|
130
|
+
schema: propSchema,
|
|
131
|
+
parentSchema: schema,
|
|
132
|
+
service: contentSourceId,
|
|
133
|
+
key: (_propSchema$key = propSchema.key) !== null && _propSchema$key !== void 0 ? _propSchema$key : name,
|
|
134
|
+
name,
|
|
135
|
+
setSource: true
|
|
136
|
+
});
|
|
137
|
+
properties[name] = migratedPropSchema;
|
|
138
|
+
Object.assign(shapes, hoistedShapes);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
if (params.depth > 0) {
|
|
142
|
+
const {
|
|
143
|
+
title,
|
|
144
|
+
description,
|
|
145
|
+
...rest
|
|
146
|
+
} = schema;
|
|
147
|
+
return {
|
|
148
|
+
schema: {
|
|
149
|
+
title,
|
|
150
|
+
description,
|
|
151
|
+
'@mapping': mapping,
|
|
152
|
+
$ref: `#/shapes/${shapeName}/schema`
|
|
153
|
+
},
|
|
154
|
+
hoistedShapes: { ...shapes,
|
|
155
|
+
[shapeName]: {
|
|
156
|
+
id: name === key ? shapeName : key,
|
|
157
|
+
name: shapeName,
|
|
158
|
+
title: shapeTitle,
|
|
159
|
+
schema: { ...pick(rest, objectSchemaKeys),
|
|
160
|
+
type: 'object',
|
|
161
|
+
properties
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
schema: { ...pick(schema, objectSchemaKeys),
|
|
170
|
+
properties,
|
|
171
|
+
'@mapping': mapping
|
|
172
|
+
},
|
|
173
|
+
hoistedShapes: shapes
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (schema.type === 'array' && schema.items) {
|
|
178
|
+
const {
|
|
179
|
+
schema: itemSchema,
|
|
180
|
+
hoistedShapes
|
|
181
|
+
} = migrateToContentSchemaV3({ ...params,
|
|
182
|
+
schema: schema.items,
|
|
183
|
+
parentSchema: schema,
|
|
184
|
+
service: 'parent',
|
|
185
|
+
setSource: false
|
|
186
|
+
});
|
|
187
|
+
return {
|
|
188
|
+
schema: { ...pick(schema, arraySchemaKeys),
|
|
189
|
+
items: itemSchema,
|
|
190
|
+
'@mapping': mapping
|
|
191
|
+
},
|
|
192
|
+
hoistedShapes
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
throw new Error(`Unknown schema type "${type}"`);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function getModelType(contentType) {
|
|
200
|
+
if (contentType.single) {
|
|
201
|
+
return 'single';
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (contentType.taxonomy) {
|
|
205
|
+
return 'taxonomy';
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return 'multiple';
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
export function contentTypeToShape(contentType, contentTypeId) {
|
|
212
|
+
var _contentType$title;
|
|
213
|
+
|
|
214
|
+
const title = (_contentType$title = contentType.title) !== null && _contentType$title !== void 0 ? _contentType$title : contentType.name;
|
|
215
|
+
const name = upperCamel(contentType.name);
|
|
216
|
+
const contentSourceId = `takeshape:local:${name}`;
|
|
217
|
+
const {
|
|
218
|
+
schema,
|
|
219
|
+
hoistedShapes
|
|
220
|
+
} = migrateToContentSchemaV3({
|
|
221
|
+
shapeName: name,
|
|
222
|
+
shapeTitle: title,
|
|
223
|
+
schema: contentType.schema,
|
|
224
|
+
service: contentSourceId,
|
|
225
|
+
name: '',
|
|
226
|
+
key: '',
|
|
227
|
+
depth: 0
|
|
228
|
+
});
|
|
229
|
+
return {
|
|
230
|
+
[name]: {
|
|
231
|
+
id: contentTypeId,
|
|
232
|
+
name,
|
|
233
|
+
title,
|
|
234
|
+
model: {
|
|
235
|
+
type: getModelType(contentType)
|
|
236
|
+
},
|
|
237
|
+
workflow: contentType.workflow,
|
|
238
|
+
schema: schema
|
|
239
|
+
},
|
|
240
|
+
...hoistedShapes
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function formatDate(timestamp) {
|
|
245
|
+
return (timestamp ? new Date(timestamp) : new Date()).toISOString();
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export function migrateToV3(projectSchema) {
|
|
249
|
+
const {
|
|
250
|
+
contentTypes,
|
|
251
|
+
created,
|
|
252
|
+
updated,
|
|
253
|
+
...rest
|
|
254
|
+
} = projectSchema;
|
|
255
|
+
const shapes = {};
|
|
256
|
+
const forms = {};
|
|
257
|
+
Object.keys(contentTypes).forEach(contentTypeId => {
|
|
258
|
+
const contentType = contentTypes[contentTypeId];
|
|
259
|
+
Object.assign(shapes, contentTypeToShape(contentType, contentTypeId));
|
|
260
|
+
forms[upperCamel(contentType.name)] = contentType.forms;
|
|
261
|
+
}); // Use deepClone to drop undefined values, this improves compatibility with validation and testing
|
|
262
|
+
// Schemas are typically saved in Dynamo or JSON files which also remove undefined values
|
|
263
|
+
// Dropping them here is done for consistency's sake
|
|
264
|
+
|
|
265
|
+
return deepClone({ ...rest,
|
|
266
|
+
...getShapeQueriesAndMutations(Object.values(shapes)),
|
|
267
|
+
schemaVersion: '3',
|
|
268
|
+
created: formatDate(created),
|
|
269
|
+
updated: formatDate(updated),
|
|
270
|
+
shapes,
|
|
271
|
+
forms
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
export async function migrateToV3_1(context, projectSchema) {
|
|
275
|
+
const {
|
|
276
|
+
encryptFn,
|
|
277
|
+
decryptFn
|
|
278
|
+
} = context;
|
|
279
|
+
let services;
|
|
280
|
+
/**
|
|
281
|
+
* Services can only be migrated if a dataKey is present, otherwise they will need to be discarded.
|
|
282
|
+
*/
|
|
283
|
+
|
|
284
|
+
if (projectSchema.services) {
|
|
285
|
+
services = await pReduce(Object.entries(projectSchema.services), async (serviceMap, [serviceKey, serviceConfig]) => {
|
|
286
|
+
const auth = serviceConfig.auth && decryptFn(serviceConfig.auth);
|
|
287
|
+
const updatedServiceConfig = updateServiceConfigV3ToV3_1({ ...serviceConfig,
|
|
288
|
+
auth
|
|
289
|
+
}, serviceKey);
|
|
290
|
+
const authentication = updatedServiceConfig === null || updatedServiceConfig === void 0 ? void 0 : updatedServiceConfig.authentication;
|
|
291
|
+
serviceMap[serviceKey] = { ...updatedServiceConfig,
|
|
292
|
+
authentication: isServiceAuthentication(authentication) ? encryptFn(authentication) : authentication
|
|
293
|
+
};
|
|
294
|
+
return serviceMap;
|
|
295
|
+
}, {});
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return deepClone({ ...projectSchema,
|
|
299
|
+
services,
|
|
300
|
+
schemaVersion: '3.1.0'
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
export function migrateToV3_2(projectSchema) {
|
|
304
|
+
/**
|
|
305
|
+
* No migration needed all changes are backwards compatible.
|
|
306
|
+
*/
|
|
307
|
+
return { ...projectSchema,
|
|
308
|
+
schemaVersion: '3.2.0'
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
export async function migrateToV3_3(context, projectSchema) {
|
|
312
|
+
const {
|
|
313
|
+
generateDataKeyFn
|
|
314
|
+
} = context;
|
|
315
|
+
const dataKey = projectSchema.dataKey ? projectSchema.dataKey : await generateDataKeyFn();
|
|
316
|
+
/**
|
|
317
|
+
* Generate a dataKey if none is present.
|
|
318
|
+
*/
|
|
319
|
+
|
|
320
|
+
return { ...projectSchema,
|
|
321
|
+
schemaVersion: '3.3.0',
|
|
322
|
+
dataKey
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
export function migrateToV3_4(projectSchema) {
|
|
326
|
+
/**
|
|
327
|
+
* No migration needed all changes are backwards compatible.
|
|
328
|
+
*/
|
|
329
|
+
return { ...projectSchema,
|
|
330
|
+
schemaVersion: '3.4.0'
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
export function migrateToV3_5(projectSchema) {
|
|
334
|
+
/**
|
|
335
|
+
* No migration needed all changes are backwards compatible.
|
|
336
|
+
*/
|
|
337
|
+
return { ...projectSchema,
|
|
338
|
+
schemaVersion: '3.5.0'
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
export function migrateToV3_5_1(projectSchema) {
|
|
342
|
+
/**
|
|
343
|
+
* No migration needed all changes are backwards compatible.
|
|
344
|
+
*/
|
|
345
|
+
return { ...projectSchema,
|
|
346
|
+
schemaVersion: '3.5.1'
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
export function migrateToV3_6(projectSchema) {
|
|
350
|
+
/**
|
|
351
|
+
* No migration needed all changes are backwards compatible.
|
|
352
|
+
*/
|
|
353
|
+
return { ...projectSchema,
|
|
354
|
+
schemaVersion: '3.6.0'
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
export async function migrateToLatestProjectSchema(context, projectSchema) {
|
|
358
|
+
if (isProjectSchemaV1(projectSchema)) {
|
|
359
|
+
projectSchema = migrateToV3(projectSchema);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
if (isProjectSchemaV3(projectSchema)) {
|
|
363
|
+
projectSchema = await migrateToV3_1(context, projectSchema);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (isProjectSchemaV3_1(projectSchema)) {
|
|
367
|
+
projectSchema = migrateToV3_2(projectSchema);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
if (isProjectSchemaV3_2(projectSchema)) {
|
|
371
|
+
projectSchema = await migrateToV3_3(context, projectSchema);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (isProjectSchemaV3_3(projectSchema)) {
|
|
375
|
+
projectSchema = migrateToV3_4(projectSchema);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
if (isProjectSchemaV3_4(projectSchema)) {
|
|
379
|
+
projectSchema = migrateToV3_5(projectSchema);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (isProjectSchemaV3_5(projectSchema)) {
|
|
383
|
+
projectSchema = migrateToV3_5_1(projectSchema);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
if (isProjectSchemaV3_5_1(projectSchema)) {
|
|
387
|
+
projectSchema = migrateToV3_6(projectSchema);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
return projectSchema;
|
|
391
|
+
}
|
|
392
|
+
export function normalizeSchemaVersion(version) {
|
|
393
|
+
return version === undefined ? '1' : version;
|
|
394
|
+
}
|
|
395
|
+
export function isV1Like(schema) {
|
|
396
|
+
return Boolean(schema.schemaVersion === '1' || schema.schemaVersion === undefined);
|
|
397
|
+
}
|
|
398
|
+
export function isV1(schema) {
|
|
399
|
+
return Boolean(isV1Like(schema));
|
|
400
|
+
}
|
|
401
|
+
export function isV3Like(schema) {
|
|
402
|
+
return schema.schemaVersion === '3';
|
|
403
|
+
}
|
|
404
|
+
export function isV3(schema) {
|
|
405
|
+
return isV3Like(schema);
|
|
406
|
+
}
|
|
407
|
+
export async function ensureLatest(context, schema) {
|
|
408
|
+
if (!schema || isLatestProjectSchema(schema)) {
|
|
409
|
+
return schema;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
return migrateToLatestProjectSchema(context, schema);
|
|
413
|
+
}
|