@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,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getType = getType;
|
|
7
|
+
exports.toName = toName;
|
|
8
|
+
exports.preferKey = preferKey;
|
|
9
|
+
exports.findTransforms = findTransforms;
|
|
10
|
+
exports.getContentTransform = getContentTransform;
|
|
11
|
+
exports.getPropertyInfo = getPropertyInfo;
|
|
12
|
+
|
|
13
|
+
var _forEach = _interopRequireDefault(require("lodash/forEach"));
|
|
14
|
+
|
|
15
|
+
var _difference = _interopRequireDefault(require("lodash/difference"));
|
|
16
|
+
|
|
17
|
+
var _pick = _interopRequireDefault(require("lodash/pick"));
|
|
18
|
+
|
|
19
|
+
var _schemaUtil = require("./schema-util");
|
|
20
|
+
|
|
21
|
+
var _types = require("./types");
|
|
22
|
+
|
|
23
|
+
var _refs = require("./refs");
|
|
24
|
+
|
|
25
|
+
var _unions = require("./unions");
|
|
26
|
+
|
|
27
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
28
|
+
|
|
29
|
+
const typeCache = new WeakMap();
|
|
30
|
+
|
|
31
|
+
function getType(schema) {
|
|
32
|
+
let type = typeCache.get(schema);
|
|
33
|
+
|
|
34
|
+
if (type) {
|
|
35
|
+
return type;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
type = schema.type; // handle nullable types for example: ['object', 'null']
|
|
39
|
+
|
|
40
|
+
if (Array.isArray(type)) {
|
|
41
|
+
const filtered = type.filter(name => name !== 'null');
|
|
42
|
+
|
|
43
|
+
if (!filtered.length) {
|
|
44
|
+
throw new Error(`Invalid schema`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type = filtered[0];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
typeCache.set(schema, type);
|
|
51
|
+
return type;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function toName(name) {
|
|
55
|
+
return name;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function ensureArray(value) {
|
|
59
|
+
return Array.isArray(value) ? value : [value];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function preferKey(name, schema) {
|
|
63
|
+
var _getKey;
|
|
64
|
+
|
|
65
|
+
return (_getKey = (0, _schemaUtil.getKey)(schema)) !== null && _getKey !== void 0 ? _getKey : name;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function findTransforms(pluginMap, schema, name, shape) {
|
|
69
|
+
const type = getType(schema);
|
|
70
|
+
|
|
71
|
+
if (pluginMap && (pluginMap[type] || pluginMap['*'])) {
|
|
72
|
+
var _pluginMap$type, _pluginMap$;
|
|
73
|
+
|
|
74
|
+
const plugins = ((_pluginMap$type = pluginMap[type]) !== null && _pluginMap$type !== void 0 ? _pluginMap$type : []).concat((_pluginMap$ = pluginMap['*']) !== null && _pluginMap$ !== void 0 ? _pluginMap$ : []);
|
|
75
|
+
return plugins.find(plugin => plugin.filter(schema, name, shape));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return undefined;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function getContentTransform({
|
|
82
|
+
transforms,
|
|
83
|
+
accumulators,
|
|
84
|
+
keyTransform = preferKey,
|
|
85
|
+
sourceKeyTransform = preferKey,
|
|
86
|
+
passThrough = true,
|
|
87
|
+
projectSchema
|
|
88
|
+
}) {
|
|
89
|
+
const prepare = (schema, obj, name = '') => {
|
|
90
|
+
const shapeName = (0, _refs.getRefShapeName)(projectSchema, schema);
|
|
91
|
+
schema = (0, _schemaUtil.dereferenceSchema)(projectSchema, schema);
|
|
92
|
+
|
|
93
|
+
if (accumulators) {
|
|
94
|
+
accumulators.forEach(accumulator => {
|
|
95
|
+
accumulator.accumulate(obj, schema, name);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const shape = shapeName ? projectSchema.shapes[shapeName] : undefined;
|
|
100
|
+
const transform = findTransforms(transforms, schema, name, shape);
|
|
101
|
+
|
|
102
|
+
if (transform) {
|
|
103
|
+
const next = (value, schema, name) => prepare(schema, value, name);
|
|
104
|
+
|
|
105
|
+
return transform.process(obj, schema, name, shape, next);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (obj && (0, _unions.isUnionSchema)(schema)) {
|
|
109
|
+
for (const {
|
|
110
|
+
shapeId,
|
|
111
|
+
propSchema
|
|
112
|
+
} of (0, _unions.enumerateOneOfKeys)(projectSchema, schema.oneOf)) {
|
|
113
|
+
if (obj._shapeId === shapeId) {
|
|
114
|
+
return prepare(propSchema, obj, name);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (obj && (0, _types.isObjectSchema)(schema)) {
|
|
120
|
+
const result = {};
|
|
121
|
+
const assigned = new Set();
|
|
122
|
+
(0, _forEach.default)(schema.properties, (fieldSchema, name) => {
|
|
123
|
+
const sourceKeys = ensureArray(sourceKeyTransform(name, fieldSchema));
|
|
124
|
+
|
|
125
|
+
for (const sourceKey of sourceKeys) {
|
|
126
|
+
const value = prepare(fieldSchema, obj === null || obj === void 0 ? void 0 : obj[sourceKey], name);
|
|
127
|
+
|
|
128
|
+
if (value !== undefined) {
|
|
129
|
+
assigned.add(sourceKey);
|
|
130
|
+
const transform = findTransforms(transforms, (0, _schemaUtil.dereferenceSchema)(projectSchema, fieldSchema), name);
|
|
131
|
+
const getKey = transform !== null && transform !== void 0 && transform.keyTransform ? transform.keyTransform : keyTransform;
|
|
132
|
+
result[getKey(name, fieldSchema, sourceKey)] = value;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
if (passThrough && obj) {
|
|
138
|
+
const keys = (0, _difference.default)(Object.keys(obj), [...assigned]);
|
|
139
|
+
|
|
140
|
+
if (keys.length) {
|
|
141
|
+
Object.assign(result, (0, _pick.default)(obj, keys));
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
if ((0, _types.isArraySchema)(schema)) {
|
|
149
|
+
const itemSchema = schema.items;
|
|
150
|
+
|
|
151
|
+
if (Array.isArray(obj)) {
|
|
152
|
+
return obj.map(item => prepare(itemSchema, item, name));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (obj === undefined) {
|
|
156
|
+
prepare(itemSchema, obj, name);
|
|
157
|
+
}
|
|
158
|
+
} // allow properties that have not been transformed
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
return passThrough ? obj : undefined;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
return prepare;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function transformKey(transforms, propSchema, name, transform = preferKey) {
|
|
168
|
+
const schemaTransform = findTransforms(transforms, propSchema, name);
|
|
169
|
+
|
|
170
|
+
if (schemaTransform !== null && schemaTransform !== void 0 && schemaTransform.keyTransform) {
|
|
171
|
+
transform = schemaTransform.keyTransform;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return transform(name, propSchema);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function getPropertyInfo(context, schema, path) {
|
|
178
|
+
const {
|
|
179
|
+
projectSchema,
|
|
180
|
+
transforms,
|
|
181
|
+
keyTransform
|
|
182
|
+
} = context;
|
|
183
|
+
const result = [];
|
|
184
|
+
|
|
185
|
+
const findProperty = (currentSchema, name, rest, path) => {
|
|
186
|
+
if ((0, _types.isObjectSchema)(currentSchema)) {
|
|
187
|
+
const propSchema = currentSchema.properties[name];
|
|
188
|
+
|
|
189
|
+
if (!propSchema) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const refSchema = (0, _schemaUtil.dereferenceSchema)(projectSchema, propSchema);
|
|
194
|
+
const nextPath = path.concat(transformKey(transforms, refSchema, name, keyTransform));
|
|
195
|
+
|
|
196
|
+
if (rest.length) {
|
|
197
|
+
const [nextName, ...nextRest] = rest;
|
|
198
|
+
findProperty(refSchema, nextName, nextRest, nextPath);
|
|
199
|
+
} else {
|
|
200
|
+
result.push({
|
|
201
|
+
schema: refSchema,
|
|
202
|
+
key: nextPath.join('.')
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
} else if ((0, _unions.isUnionSchema)(currentSchema)) {
|
|
206
|
+
for (const optionSchema of currentSchema.oneOf) {
|
|
207
|
+
findProperty((0, _schemaUtil.dereferenceSchema)(projectSchema, optionSchema), name, rest, path);
|
|
208
|
+
}
|
|
209
|
+
} else if ((0, _types.isArraySchema)(currentSchema)) {
|
|
210
|
+
findProperty((0, _schemaUtil.dereferenceSchema)(projectSchema, currentSchema.items), name, rest, path);
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const [first, ...rest] = path.split('.');
|
|
215
|
+
findProperty((0, _schemaUtil.dereferenceSchema)(projectSchema, schema), first, rest, []);
|
|
216
|
+
return result;
|
|
217
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=entitlements.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entitlements.d.ts","sourceRoot":"","sources":["../../src/entitlements.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/lib/enum.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../src/enum.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAE/C,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAW3D"}
|
package/lib/enum.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isEnumSchema = isEnumSchema;
|
|
7
|
+
|
|
8
|
+
function isEnumSchema(schema) {
|
|
9
|
+
if (schema.enum) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (schema.oneOf) {
|
|
14
|
+
return schema.oneOf.every(optionSchema => optionSchema.title !== undefined && (optionSchema.enum || optionSchema.const));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-is-leaf.d.ts","sourceRoot":"","sources":["../../src/get-is-leaf.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,aAAa,EAAE,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAsB9D,oBAAY,MAAM,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC;AAE/C,wBAAgB,SAAS,CAAC,aAAa,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,GAAG,MAAM,CAsC1F"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getIsLeaf = getIsLeaf;
|
|
7
|
+
|
|
8
|
+
var _contentSchemaTransform = require("./content-schema-transform");
|
|
9
|
+
|
|
10
|
+
var _schemaUtil = require("./schema-util");
|
|
11
|
+
|
|
12
|
+
var _refs = require("./refs");
|
|
13
|
+
|
|
14
|
+
const scalarTags = new Set(['draftjs']);
|
|
15
|
+
|
|
16
|
+
function isLeafTypeV3(projectSchema, contentSchema) {
|
|
17
|
+
const type = (0, _contentSchemaTransform.getType)(contentSchema);
|
|
18
|
+
return Boolean( // must have key
|
|
19
|
+
(0, _schemaUtil.getKey)(contentSchema) && ( // if is not a structure, then is a leaf
|
|
20
|
+
!['object', 'array'].includes(type) || // if is relationship, then is a leaf
|
|
21
|
+
contentSchema['@relationship'] || contentSchema['@tag'] && scalarTags.has(contentSchema['@tag']) || // if is array, then should not be a synchronized structure
|
|
22
|
+
type === 'array' && !contentSchema['@syncLocaleStructure'] || (0, _schemaUtil.isBuiltinType)(projectSchema, contentSchema)));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getIsLeaf(projectSchema, shapeSchema) {
|
|
26
|
+
const leafMap = new Set();
|
|
27
|
+
const shapesSeen = new Set();
|
|
28
|
+
|
|
29
|
+
const collectLeaves = schema => {
|
|
30
|
+
var _schema$oneOf;
|
|
31
|
+
|
|
32
|
+
const shapeName = (0, _refs.getRefShapeName)(projectSchema, schema);
|
|
33
|
+
schema = shapeName ? (0, _refs.followRef)(projectSchema, schema) : schema;
|
|
34
|
+
const key = (0, _schemaUtil.getKey)(schema);
|
|
35
|
+
|
|
36
|
+
if (key && isLeafTypeV3(projectSchema, schema)) {
|
|
37
|
+
leafMap.add(key);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (shapeName) {
|
|
41
|
+
// skip shapes we have already seen to avoid cycles
|
|
42
|
+
if (shapesSeen.has(shapeName)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
shapesSeen.add(shapeName);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const combo = (_schema$oneOf = schema.oneOf) !== null && _schema$oneOf !== void 0 ? _schema$oneOf : schema.allOf;
|
|
50
|
+
|
|
51
|
+
if (combo) {
|
|
52
|
+
combo.map(collectLeaves);
|
|
53
|
+
} else if (schema.properties) {
|
|
54
|
+
for (const name of Object.keys(schema.properties)) {
|
|
55
|
+
collectLeaves(schema.properties[name]);
|
|
56
|
+
}
|
|
57
|
+
} else if (schema.items) {
|
|
58
|
+
collectLeaves(schema.items);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
collectLeaves(shapeSchema);
|
|
63
|
+
return key => {
|
|
64
|
+
// remove locale suffix
|
|
65
|
+
key = key ? key.split(':')[0] : key;
|
|
66
|
+
return Boolean(key && leafMap.has(key));
|
|
67
|
+
};
|
|
68
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type { ProjectSchemaUpdate, ProjectSchemaMigrationContext } from './migration';
|
|
2
|
+
export * from './content-schema-transform';
|
|
3
|
+
export * from './get-is-leaf';
|
|
4
|
+
export * from './project-schema';
|
|
5
|
+
export * from './schema-util';
|
|
6
|
+
export * from './services';
|
|
7
|
+
export * from './template-shapes';
|
|
8
|
+
export * from './taxonomies';
|
|
9
|
+
export * from './types';
|
|
10
|
+
export * from './workflows';
|
|
11
|
+
export * from './builtin-schema';
|
|
12
|
+
export * from './auth-schemas';
|
|
13
|
+
export type { User } from './user-schema';
|
|
14
|
+
export * from './api-version';
|
|
15
|
+
export { listTypePrefix, ensureLatest, normalizeSchemaVersion, getRelationshipSchema, migrateToLatestProjectSchema } from './migration';
|
|
16
|
+
export * from './validate';
|
|
17
|
+
export { builtInShapes } from './builtin-schema';
|
|
18
|
+
export * from './versions';
|
|
19
|
+
export * from './mocks';
|
|
20
|
+
export * from './util';
|
|
21
|
+
export * from './resolvers';
|
|
22
|
+
export * from './scalars';
|
|
23
|
+
export * from './refs';
|
|
24
|
+
export * from './unions';
|
|
25
|
+
export * from './enum';
|
|
26
|
+
export * from './patterns';
|
|
27
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAC,mBAAmB,EAAE,6BAA6B,EAAC,MAAM,aAAa,CAAC;AACpF,cAAc,4BAA4B,CAAC;AAC3C,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC;AAE/B,YAAY,EAAC,IAAI,EAAC,MAAM,eAAe,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,OAAO,EACL,cAAc,EACd,YAAY,EACZ,sBAAsB,EACtB,qBAAqB,EACrB,4BAA4B,EAC7B,MAAM,aAAa,CAAC;AACrB,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAC/C,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC"}
|