@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
package/lib/unions.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.enumerateOneOfKeys = enumerateOneOfKeys;
|
|
7
|
+
exports.isUnionSchema = isUnionSchema;
|
|
8
|
+
exports.oneOfToObject = oneOfToObject;
|
|
9
|
+
exports.transformOneOf = transformOneOf;
|
|
10
|
+
exports.wrapOneOfObjects = exports.unwrapOneOfObjects = exports.createWrapTransform = exports.createUnwrapTransform = void 0;
|
|
11
|
+
|
|
12
|
+
var _refs = require("./refs");
|
|
13
|
+
|
|
14
|
+
var _util = require("@takeshape/util");
|
|
15
|
+
|
|
16
|
+
var _omit = _interopRequireDefault(require("lodash/omit"));
|
|
17
|
+
|
|
18
|
+
var _contentSchemaTransform = require("./content-schema-transform");
|
|
19
|
+
|
|
20
|
+
var _types = require("./types");
|
|
21
|
+
|
|
22
|
+
var _errors = require("@takeshape/errors");
|
|
23
|
+
|
|
24
|
+
var _schemaUtil = require("./schema-util");
|
|
25
|
+
|
|
26
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
+
|
|
28
|
+
function enumerateOneOfKeys(projectSchema, oneOf) {
|
|
29
|
+
const result = [];
|
|
30
|
+
|
|
31
|
+
for (const child of oneOf) {
|
|
32
|
+
const refItem = (0, _refs.getRef)(projectSchema, child);
|
|
33
|
+
|
|
34
|
+
if (refItem) {
|
|
35
|
+
const shapeName = (0, _refs.refItemToShapeName)(refItem);
|
|
36
|
+
|
|
37
|
+
if (projectSchema.shapes[shapeName]) {
|
|
38
|
+
const shapeId = projectSchema.shapes[shapeName].id;
|
|
39
|
+
result.push({
|
|
40
|
+
propName: (0, _util.camelCase)(refItem.typeName),
|
|
41
|
+
propSchema: child,
|
|
42
|
+
shapeName,
|
|
43
|
+
shapeId
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function getOneOf(schema) {
|
|
53
|
+
if (!schema.oneOf) {
|
|
54
|
+
throw new Error(`Expected ${JSON.stringify(schema)} to be a oneOf schema`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return schema.oneOf;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function isUnionSchema(schema) {
|
|
61
|
+
var _schema$oneOf;
|
|
62
|
+
|
|
63
|
+
return Boolean((_schema$oneOf = schema.oneOf) === null || _schema$oneOf === void 0 ? void 0 : _schema$oneOf.every(_types.isRefSchema));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function oneOfToObject(projectSchema, schema) {
|
|
67
|
+
const properties = {};
|
|
68
|
+
|
|
69
|
+
for (const {
|
|
70
|
+
propName,
|
|
71
|
+
propSchema: child
|
|
72
|
+
} of enumerateOneOfKeys(projectSchema, getOneOf(schema))) {
|
|
73
|
+
properties[propName] = child;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return { ...(0, _omit.default)(schema, 'oneOf'),
|
|
77
|
+
type: 'object',
|
|
78
|
+
properties
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function formatKeys(keys) {
|
|
83
|
+
return keys.map(k => `"${k}"`).join(', ');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// eslint-disable-next-line max-params
|
|
87
|
+
const createUnwrapTransform = projectSchema => (obj, schema, name, shape, next) => {
|
|
88
|
+
if ((0, _util.isObject)(obj)) {
|
|
89
|
+
const oneOfKeys = enumerateOneOfKeys(projectSchema, getOneOf(schema));
|
|
90
|
+
const objectKeys = Object.keys(obj);
|
|
91
|
+
|
|
92
|
+
if (objectKeys.length !== 1) {
|
|
93
|
+
const propNames = oneOfKeys.map(k => k.propName);
|
|
94
|
+
throw new _errors.BadDataError(`Object should only specify one of the following keys: ${formatKeys(propNames)}, but found keys: ${formatKeys(objectKeys)}`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
for (const {
|
|
98
|
+
propName,
|
|
99
|
+
shapeId,
|
|
100
|
+
propSchema
|
|
101
|
+
} of oneOfKeys) {
|
|
102
|
+
const propValue = obj[propName];
|
|
103
|
+
|
|
104
|
+
if ((0, _util.isObject)(propValue)) {
|
|
105
|
+
const transformedPropValue = next(propValue, propSchema, name);
|
|
106
|
+
|
|
107
|
+
if ((0, _util.isObject)(transformedPropValue)) {
|
|
108
|
+
return { ...transformedPropValue,
|
|
109
|
+
_shapeId: shapeId
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}; // eslint-disable-next-line max-params
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
exports.createUnwrapTransform = createUnwrapTransform;
|
|
119
|
+
|
|
120
|
+
const createWrapTransform = projectSchema => (obj, schema, name, shape, next) => {
|
|
121
|
+
if ((0, _util.isObject)(obj) && typeof obj._shapeId === 'string') {
|
|
122
|
+
const shape = (0, _schemaUtil.getShapeById)(projectSchema, obj._shapeId);
|
|
123
|
+
|
|
124
|
+
if (shape) {
|
|
125
|
+
return {
|
|
126
|
+
[(0, _util.camelCase)(shape.name)]: next((0, _omit.default)(obj, '_shapeId'), shape.schema, name)
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
exports.createWrapTransform = createWrapTransform;
|
|
133
|
+
|
|
134
|
+
function transformOneOf(process) {
|
|
135
|
+
return (projectSchema, schema, obj) => {
|
|
136
|
+
const transform = (0, _contentSchemaTransform.getContentTransform)({
|
|
137
|
+
sourceKeyTransform: _contentSchemaTransform.toName,
|
|
138
|
+
keyTransform: _contentSchemaTransform.toName,
|
|
139
|
+
passThrough: true,
|
|
140
|
+
projectSchema,
|
|
141
|
+
transforms: {
|
|
142
|
+
'*': [{
|
|
143
|
+
filter: isUnionSchema,
|
|
144
|
+
process: process(projectSchema)
|
|
145
|
+
}]
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
return transform(schema, obj);
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Unwrap oneOf objects in "GraphQL oneOf" style wrapper objects
|
|
153
|
+
* See https://github.com/graphql/graphql-spec/pull/825 for more on "GraphQL oneOf"
|
|
154
|
+
* Opposite of `wrapOneOfObjects`
|
|
155
|
+
*/
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
const unwrapOneOfObjects = transformOneOf(createUnwrapTransform);
|
|
159
|
+
/**
|
|
160
|
+
* Wrap oneOf objects in "GraphQL oneOf" style wrapper objects
|
|
161
|
+
* See https://github.com/graphql/graphql-spec/pull/825 for more on "GraphQL oneOf"
|
|
162
|
+
* Opposite of `unwrapOneOfObjects`
|
|
163
|
+
*/
|
|
164
|
+
|
|
165
|
+
exports.unwrapOneOfObjects = unwrapOneOfObjects;
|
|
166
|
+
const wrapOneOfObjects = transformOneOf(createWrapTransform);
|
|
167
|
+
exports.wrapOneOfObjects = wrapOneOfObjects;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file was automatically generated by json-schema-to-typescript.
|
|
3
|
+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
|
|
4
|
+
* and run json-schema-to-typescript to regenerate this file.
|
|
5
|
+
*/
|
|
6
|
+
export interface User {
|
|
7
|
+
id: string;
|
|
8
|
+
email: string;
|
|
9
|
+
fullName: string;
|
|
10
|
+
created: number;
|
|
11
|
+
updated: number;
|
|
12
|
+
firstTime: boolean;
|
|
13
|
+
avatarPath?: string;
|
|
14
|
+
intercomHash?: string;
|
|
15
|
+
googleUserId?: string;
|
|
16
|
+
comcastId?: string;
|
|
17
|
+
token?: string;
|
|
18
|
+
policies?: AccessPolicyDocument[];
|
|
19
|
+
preferences?: {
|
|
20
|
+
[k: string]: any;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export interface AccessPolicyDocument {
|
|
24
|
+
Version: string;
|
|
25
|
+
Statement: {
|
|
26
|
+
Effect?: 'Allow' | 'Deny';
|
|
27
|
+
Sid?: string;
|
|
28
|
+
Action?: string[];
|
|
29
|
+
NotAction?: string[];
|
|
30
|
+
Resource?: string[];
|
|
31
|
+
NotResource?: string[];
|
|
32
|
+
Principal?: {
|
|
33
|
+
AWS?: string[];
|
|
34
|
+
Service?: string[];
|
|
35
|
+
};
|
|
36
|
+
Condition?: {};
|
|
37
|
+
}[];
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=user-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-schema.d.ts","sourceRoot":"","sources":["../../src/user-schema.ts"],"names":[],"mappings":"AACA;;;;GAIG;AAEH,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,oBAAoB,EAAE,CAAC;IAClC,WAAW,CAAC,EAAE;QACZ,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;KAClB,CAAC;CACH;AACD,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE;QACT,MAAM,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;QAC1B,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;QAClB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QACrB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;QACpB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;QACvB,SAAS,CAAC,EAAE;YACV,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC;YACf,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;SACpB,CAAC;QACF,SAAS,CAAC,EAAE,EAAE,CAAC;KAChB,EAAE,CAAC;CACL"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ProjectSchema, ContentSchema } from '../project-schema';
|
|
2
|
+
/**
|
|
3
|
+
* Use a basic depth-first search to dertermine whether a schema contains a cycle
|
|
4
|
+
*/
|
|
5
|
+
export declare function hasCycle(projectSchema: ProjectSchema, schema: ContentSchema, shapesSeen?: Set<string>): boolean;
|
|
6
|
+
//# sourceMappingURL=detect-cycles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect-cycles.d.ts","sourceRoot":"","sources":["../../../src/util/detect-cycles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAE,aAAa,EAAC,MAAM,mBAAmB,CAAC;AAS/D;;GAEG;AACH,wBAAgB,QAAQ,CACtB,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,aAAa,EACrB,UAAU,GAAE,GAAG,CAAC,MAAM,CAAa,GAClC,OAAO,CAoCT"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.hasCycle = hasCycle;
|
|
7
|
+
|
|
8
|
+
var _refs = require("../refs");
|
|
9
|
+
|
|
10
|
+
function immutableSetAdd(set, str) {
|
|
11
|
+
const result = new Set(set);
|
|
12
|
+
result.add(str);
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Use a basic depth-first search to dertermine whether a schema contains a cycle
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
function hasCycle(projectSchema, schema, shapesSeen = new Set()) {
|
|
21
|
+
var _ref, _schema$oneOf;
|
|
22
|
+
|
|
23
|
+
const refItem = (0, _refs.getRef)(projectSchema, schema);
|
|
24
|
+
|
|
25
|
+
if (refItem) {
|
|
26
|
+
const refShape = (0, _refs.refItemToShape)(projectSchema, refItem); // If we have a refItem, but no shape, this is a dangling ref and has no cycles
|
|
27
|
+
|
|
28
|
+
if (!refShape) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (shapesSeen.has(refShape.name)) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return hasCycle(projectSchema, refShape.schema, immutableSetAdd(shapesSeen, refShape.name));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const combo = (_ref = (_schema$oneOf = schema.oneOf) !== null && _schema$oneOf !== void 0 ? _schema$oneOf : schema.allOf) !== null && _ref !== void 0 ? _ref : schema.anyOf;
|
|
40
|
+
|
|
41
|
+
if (combo) {
|
|
42
|
+
return combo.some(childSchema => hasCycle(projectSchema, childSchema, shapesSeen));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (schema.items) {
|
|
46
|
+
return hasCycle(projectSchema, schema.items, shapesSeen);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const {
|
|
50
|
+
properties
|
|
51
|
+
} = schema;
|
|
52
|
+
|
|
53
|
+
if (properties) {
|
|
54
|
+
return Object.keys(properties).some(name => {
|
|
55
|
+
const propSchema = properties[name];
|
|
56
|
+
return hasCycle(projectSchema, propSchema, shapesSeen);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/util/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _detectCycles = require("./detect-cycles");
|
|
8
|
+
|
|
9
|
+
Object.keys(_detectCycles).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _detectCycles[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _detectCycles[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { RoleImport, RoleInput } from './auth-schemas';
|
|
2
|
+
import type { AnyProjectSchema, ProjectSchema, ProjectSchemaV3_0_0 } from './project-schema';
|
|
3
|
+
import { SchemaValidationErrorItem } from '@takeshape/errors';
|
|
4
|
+
import Ajv, { ErrorObject } from 'ajv';
|
|
5
|
+
export declare function addProjectSchemasToAjv(ajv: Ajv): Ajv;
|
|
6
|
+
export declare type SchemaValidationResult = {
|
|
7
|
+
valid: true;
|
|
8
|
+
schema: AnyProjectSchema;
|
|
9
|
+
errors: undefined;
|
|
10
|
+
} | {
|
|
11
|
+
valid: false;
|
|
12
|
+
schema: undefined;
|
|
13
|
+
errors: SchemaValidationErrorItem[];
|
|
14
|
+
};
|
|
15
|
+
export declare function formatError(error: ErrorObject): SchemaValidationErrorItem;
|
|
16
|
+
export interface Validation {
|
|
17
|
+
version: string;
|
|
18
|
+
schemaId: string;
|
|
19
|
+
isVersion: (schemaVersion?: string) => Boolean;
|
|
20
|
+
validate: (schema: unknown, options?: ValidateOptions) => SchemaValidationResult;
|
|
21
|
+
}
|
|
22
|
+
export interface ValidateOptions {
|
|
23
|
+
additionalShapeNames?: string[];
|
|
24
|
+
additionalModelShapeIds?: string[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Validates a schema using a matching validation based on the `schemaVersion` property.
|
|
28
|
+
*/
|
|
29
|
+
export declare function validateSchema(obj: unknown, options?: ValidateOptions): SchemaValidationResult;
|
|
30
|
+
export declare function ensureValidV3Schema(obj: unknown): ProjectSchemaV3_0_0;
|
|
31
|
+
export declare function ensureValidLatestSchema(obj: unknown): ProjectSchema;
|
|
32
|
+
/**
|
|
33
|
+
* Validates and returns a `RoleInput`, which is a subset of the `Role`
|
|
34
|
+
* type's properties suitable for importing.
|
|
35
|
+
*/
|
|
36
|
+
export declare function validateRoleInput(maybeRoleInput: unknown): RoleInput;
|
|
37
|
+
/**
|
|
38
|
+
* Validates and returns a `RoleImport` array, which is a collection of `RoleInput`s.
|
|
39
|
+
*/
|
|
40
|
+
export declare function validateRoleImport(maybeRoles: unknown): RoleImport;
|
|
41
|
+
/**
|
|
42
|
+
* Only use when validating an imported schema!
|
|
43
|
+
*
|
|
44
|
+
* New style validation for parity with the `validateRoleImport` fn. Returns
|
|
45
|
+
* a valid, and potentially cleaned `AnyProjectSchema` or throws a
|
|
46
|
+
* `SchemaValidationError`.
|
|
47
|
+
*/
|
|
48
|
+
export declare function validateProjectSchemaImport(maybeSchema: unknown): AnyProjectSchema;
|
|
49
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../src/validate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,UAAU,EAAE,SAAS,EAAC,MAAM,gBAAgB,CAAC;AAC1D,OAAO,KAAK,EAEV,gBAAgB,EAChB,aAAa,EAEb,mBAAmB,EAcpB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAwB,yBAAyB,EAAC,MAAM,mBAAmB,CAAC;AAOnF,OAAO,GAAG,EAAE,EAAC,WAAW,EAAC,MAAM,KAAK,CAAC;AA0YrC,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CA6BpD;AAED,oBAAY,sBAAsB,GAC9B;IAAC,KAAK,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,gBAAgB,CAAC;IAAC,MAAM,EAAE,SAAS,CAAA;CAAC,GAC1D;IAAC,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,yBAAyB,EAAE,CAAA;CAAC,CAAC;AAI3E,wBAAgB,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,yBAAyB,CAmBzE;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,CAAC,aAAa,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC;IAC/C,QAAQ,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,KAAK,sBAAsB,CAAC;CAClF;AACD,MAAM,WAAW,eAAe;IAC9B,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,EAAE,CAAC;CACpC;AA2ID;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,sBAAsB,CAqB9F;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,mBAAmB,CAgBrE;AAED,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,OAAO,GAAG,aAAa,CAgBnE;AAgBD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,cAAc,EAAE,OAAO,GAAG,SAAS,CAQpE;AAgBD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,OAAO,GAAG,UAAU,CAQlE;AAqBD;;;;;;GAMG;AACH,wBAAgB,2BAA2B,CAAC,WAAW,EAAE,OAAO,GAAG,gBAAgB,CASlF"}
|