@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,1353 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isBuiltinShape = isBuiltinShape;
|
|
7
|
+
exports.isBuiltinQuery = isBuiltinQuery;
|
|
8
|
+
exports.isBuiltinMutation = isBuiltinMutation;
|
|
9
|
+
exports.isBuiltinType = isBuiltinType;
|
|
10
|
+
exports.getServiceIdFieldName = getServiceIdFieldName;
|
|
11
|
+
exports.getGeneratorVersion = getGeneratorVersion;
|
|
12
|
+
exports.getServiceInfo = getServiceInfo;
|
|
13
|
+
exports.pathBetween = pathBetween;
|
|
14
|
+
exports.getShapeQueriesAndMutations = getShapeQueriesAndMutations;
|
|
15
|
+
exports.getBuiltInProperties = getBuiltInProperties;
|
|
16
|
+
exports.applyBuiltinPropertiesToShape = applyBuiltinPropertiesToShape;
|
|
17
|
+
exports.mergeSchemaProperties = mergeSchemaProperties;
|
|
18
|
+
exports.mergeFormProperties = mergeFormProperties;
|
|
19
|
+
exports.applyDefaultsToSchema = applyDefaultsToSchema;
|
|
20
|
+
exports.findExistingRelationships = findExistingRelationships;
|
|
21
|
+
exports.stringifyQuerySource = stringifyQuerySource;
|
|
22
|
+
exports.parseQuerySource = parseQuerySource;
|
|
23
|
+
exports.parseQueryResolver = parseQueryResolver;
|
|
24
|
+
exports.getShapeById = getShapeById;
|
|
25
|
+
exports.isModelShape = isModelShape;
|
|
26
|
+
exports.getArgsReference = getArgsReference;
|
|
27
|
+
exports.getArgsReferenceWithPath = getArgsReferenceWithPath;
|
|
28
|
+
exports.getArgsShapeSchema = getArgsShapeSchema;
|
|
29
|
+
exports.shapeToContentSchema = shapeToContentSchema;
|
|
30
|
+
exports.projectSchemaToJSONSchema = projectSchemaToJSONSchema;
|
|
31
|
+
exports.getShapeDependencies = getShapeDependencies;
|
|
32
|
+
exports.getRelevantShapes = getRelevantShapes;
|
|
33
|
+
exports.visitSchemaProperties = visitSchemaProperties;
|
|
34
|
+
exports.visitShapeProperties = visitShapeProperties;
|
|
35
|
+
exports.getAllRefsInShapes = getAllRefsInShapes;
|
|
36
|
+
exports.getAllRefsInQuery = getAllRefsInQuery;
|
|
37
|
+
exports.getAllRefsInQueries = getAllRefsInQueries;
|
|
38
|
+
exports.getAllRefs = getAllRefs;
|
|
39
|
+
exports.parseMapping = parseMapping;
|
|
40
|
+
exports.splitMapping = splitMapping;
|
|
41
|
+
exports.findMapping = findMapping;
|
|
42
|
+
exports.getFirstMapping = getFirstMapping;
|
|
43
|
+
exports.getFullyQualifiedShapeName = getFullyQualifiedShapeName;
|
|
44
|
+
exports.getKey = getKey;
|
|
45
|
+
exports.getPropertyService = getPropertyService;
|
|
46
|
+
exports.emptySchema = emptySchema;
|
|
47
|
+
exports.getShapesById = getShapesById;
|
|
48
|
+
exports.getAllNamespaceShapes = getAllNamespaceShapes;
|
|
49
|
+
exports.getNamespacedShapeNameList = getNamespacedShapeNameList;
|
|
50
|
+
exports.filterGraphQLServiceMap = filterGraphQLServiceMap;
|
|
51
|
+
exports.collectReferencedShapeNames = collectReferencedShapeNames;
|
|
52
|
+
exports.getProtectedSchema = getProtectedSchema;
|
|
53
|
+
exports.dereferenceSchema = dereferenceSchema;
|
|
54
|
+
exports.dereferenceObjectSchema = dereferenceObjectSchema;
|
|
55
|
+
exports.findShapeFormConfig = findShapeFormConfig;
|
|
56
|
+
exports.getDefaultMutationName = exports.findMutation = exports.findQuery = exports.createSchemaPropertyAccessor = exports.createSchemaPropertyList = exports.getBuiltInPropertyNames = exports.nonStructuralSchemaKeys = exports.multipleRelationshipSchemaKeys = exports.arraySchemaKeys = exports.objectSchemaKeys = exports.scalarSchemaKeys = exports.commonSchemaKeys = exports.schemaMetadataKeys = exports.SERVICE_OBJECT_PATTERN_NAME = void 0;
|
|
57
|
+
|
|
58
|
+
var _find = _interopRequireDefault(require("lodash/find"));
|
|
59
|
+
|
|
60
|
+
var _mapValues = _interopRequireDefault(require("lodash/mapValues"));
|
|
61
|
+
|
|
62
|
+
var _omitBy = _interopRequireDefault(require("lodash/omitBy"));
|
|
63
|
+
|
|
64
|
+
var _omit = _interopRequireDefault(require("lodash/fp/omit"));
|
|
65
|
+
|
|
66
|
+
var _assign = _interopRequireDefault(require("lodash/fp/assign"));
|
|
67
|
+
|
|
68
|
+
var _pickBy = _interopRequireDefault(require("lodash/pickBy"));
|
|
69
|
+
|
|
70
|
+
var _get = _interopRequireDefault(require("lodash/get"));
|
|
71
|
+
|
|
72
|
+
var _union = _interopRequireDefault(require("lodash/union"));
|
|
73
|
+
|
|
74
|
+
var _keyBy = _interopRequireDefault(require("lodash/keyBy"));
|
|
75
|
+
|
|
76
|
+
var _isEmpty = _interopRequireDefault(require("lodash/isEmpty"));
|
|
77
|
+
|
|
78
|
+
var _isObject = _interopRequireDefault(require("lodash/isObject"));
|
|
79
|
+
|
|
80
|
+
var _curry = _interopRequireDefault(require("lodash/fp/curry"));
|
|
81
|
+
|
|
82
|
+
var _orderBy2 = _interopRequireDefault(require("lodash/fp/orderBy"));
|
|
83
|
+
|
|
84
|
+
var _uniq = _interopRequireDefault(require("lodash/uniq"));
|
|
85
|
+
|
|
86
|
+
var _util = require("@takeshape/util");
|
|
87
|
+
|
|
88
|
+
var _merge = require("@takeshape/util/lib/merge");
|
|
89
|
+
|
|
90
|
+
var _workflows = require("./workflows");
|
|
91
|
+
|
|
92
|
+
var _versions = require("./versions");
|
|
93
|
+
|
|
94
|
+
var _apiVersion = require("./api-version");
|
|
95
|
+
|
|
96
|
+
var _builtinSchema = require("./builtin-schema");
|
|
97
|
+
|
|
98
|
+
var _templateShapes = require("./template-shapes");
|
|
99
|
+
|
|
100
|
+
var _types = require("./types");
|
|
101
|
+
|
|
102
|
+
var _services = require("./services");
|
|
103
|
+
|
|
104
|
+
var _refs = require("./refs");
|
|
105
|
+
|
|
106
|
+
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
107
|
+
|
|
108
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
109
|
+
|
|
110
|
+
const SERVICE_OBJECT_PATTERN_NAME = 'pattern:service-object';
|
|
111
|
+
exports.SERVICE_OBJECT_PATTERN_NAME = SERVICE_OBJECT_PATTERN_NAME;
|
|
112
|
+
|
|
113
|
+
function isBuiltinShape(shapeName) {
|
|
114
|
+
return Boolean(_builtinSchema.builtInShapes[shapeName]);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const builtInQueriesAndMutations = getShapeQueriesAndMutations(Object.values(_builtinSchema.builtInShapes));
|
|
118
|
+
|
|
119
|
+
function isBuiltinQuery(name) {
|
|
120
|
+
return builtInQueriesAndMutations.queries[name] !== undefined;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function isBuiltinMutation(name) {
|
|
124
|
+
return builtInQueriesAndMutations.mutations[name] !== undefined;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function isBuiltinType(projectSchema, refSchema) {
|
|
128
|
+
const shapeName = (0, _refs.getRefShapeName)(projectSchema, refSchema);
|
|
129
|
+
return shapeName !== undefined && isBuiltinShape(shapeName);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const schemaMetadataKeys = ['$comment', 'title', 'description', '@l10n', '@deprecationReason', '@tag', '@tags', '@syncLocaleStructure', '@sensitive'];
|
|
133
|
+
exports.schemaMetadataKeys = schemaMetadataKeys;
|
|
134
|
+
const commonSchemaKeys = ['type', 'default', 'readOnly', ...schemaMetadataKeys];
|
|
135
|
+
exports.commonSchemaKeys = commonSchemaKeys;
|
|
136
|
+
const scalarSchemaKeys = [...commonSchemaKeys, 'format', 'oneOf', 'multipleOf', 'maximum', 'exclusiveMaximum', 'minimum', 'exclusiveMinimum', 'maxLength', 'minLength', 'pattern'];
|
|
137
|
+
exports.scalarSchemaKeys = scalarSchemaKeys;
|
|
138
|
+
const objectSchemaKeys = [...commonSchemaKeys, 'properties', 'required'];
|
|
139
|
+
exports.objectSchemaKeys = objectSchemaKeys;
|
|
140
|
+
const arraySchemaKeys = [...commonSchemaKeys, 'items', 'additionalItems', 'maxItems', 'minItems', 'uniqueItems'];
|
|
141
|
+
exports.arraySchemaKeys = arraySchemaKeys;
|
|
142
|
+
const multipleRelationshipSchemaKeys = [...schemaMetadataKeys, 'maxItems', 'minItems']; // all properties except properties, items, additionalItems
|
|
143
|
+
|
|
144
|
+
exports.multipleRelationshipSchemaKeys = multipleRelationshipSchemaKeys;
|
|
145
|
+
const nonStructuralSchemaKeys = [...scalarSchemaKeys, '@relationship', 'required', 'maxItems', 'minItems', 'uniqueItems'];
|
|
146
|
+
exports.nonStructuralSchemaKeys = nonStructuralSchemaKeys;
|
|
147
|
+
const commonProperties = {
|
|
148
|
+
_id: {
|
|
149
|
+
title: 'Id',
|
|
150
|
+
type: 'string'
|
|
151
|
+
},
|
|
152
|
+
_version: {
|
|
153
|
+
title: 'Version',
|
|
154
|
+
type: 'integer'
|
|
155
|
+
},
|
|
156
|
+
_shapeId: {
|
|
157
|
+
title: 'Shape Id',
|
|
158
|
+
type: 'string'
|
|
159
|
+
},
|
|
160
|
+
_shapeName: {
|
|
161
|
+
title: 'Shape Name',
|
|
162
|
+
type: 'string'
|
|
163
|
+
},
|
|
164
|
+
_createdAt: {
|
|
165
|
+
title: 'Created',
|
|
166
|
+
type: 'string',
|
|
167
|
+
format: 'date-time'
|
|
168
|
+
},
|
|
169
|
+
_createdBy: {
|
|
170
|
+
title: 'Created By',
|
|
171
|
+
type: 'string',
|
|
172
|
+
'@user': true
|
|
173
|
+
},
|
|
174
|
+
_updatedAt: {
|
|
175
|
+
title: 'Updated',
|
|
176
|
+
type: 'string',
|
|
177
|
+
format: 'date-time'
|
|
178
|
+
},
|
|
179
|
+
_updatedBy: {
|
|
180
|
+
title: 'Updated By',
|
|
181
|
+
type: 'string',
|
|
182
|
+
'@user': true
|
|
183
|
+
},
|
|
184
|
+
_schemaVersion: {
|
|
185
|
+
title: 'Schema Version',
|
|
186
|
+
type: 'number'
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
function getServiceIdFieldName(serviceFieldName) {
|
|
191
|
+
return `${serviceFieldName}Id`;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const generatorVersions = {
|
|
195
|
+
[SERVICE_OBJECT_PATTERN_NAME]: '1'
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
function getGeneratorVersion(generator) {
|
|
199
|
+
return generatorVersions[generator];
|
|
200
|
+
} // Returns info for all services found in shape, keyed by provider
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
function getServiceInfo(projectSchema, shape) {
|
|
204
|
+
const result = {};
|
|
205
|
+
const depShapes = getShapeDependencies(projectSchema, shape).map(name => projectSchema.shapes[name]);
|
|
206
|
+
const shapesToCheck = [shape, ...depShapes];
|
|
207
|
+
shapesToCheck.forEach(thisShape => {
|
|
208
|
+
createSchemaPropertyList(projectSchema, thisShape.schema).forEach(([key, value]) => {
|
|
209
|
+
const resolver = value['@resolver'];
|
|
210
|
+
|
|
211
|
+
if (!(0, _types.isBasicResolver)(resolver)) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const serviceConfig = (0, _services.getStoredServiceConfig)(projectSchema, resolver.service);
|
|
216
|
+
|
|
217
|
+
if (!serviceConfig) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const provider = serviceConfig.provider;
|
|
222
|
+
const generators = {};
|
|
223
|
+
const tag = value['@tag'];
|
|
224
|
+
|
|
225
|
+
if (tag !== null && tag !== void 0 && tag.startsWith(SERVICE_OBJECT_PATTERN_NAME)) {
|
|
226
|
+
var _resolver$options;
|
|
227
|
+
|
|
228
|
+
const idFieldName = getServiceIdFieldName(key);
|
|
229
|
+
const version = tag.substr(tag.lastIndexOf(':') + 1);
|
|
230
|
+
generators[SERVICE_OBJECT_PATTERN_NAME] = {
|
|
231
|
+
version,
|
|
232
|
+
currentVersion: getGeneratorVersion(SERVICE_OBJECT_PATTERN_NAME),
|
|
233
|
+
idFieldName,
|
|
234
|
+
serviceObjectType: (_resolver$options = resolver.options) === null || _resolver$options === void 0 ? void 0 : _resolver$options.fieldName
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const serviceInfo = {
|
|
239
|
+
service: resolver.service,
|
|
240
|
+
fieldName: key,
|
|
241
|
+
path: pathBetween(shape, thisShape, projectSchema),
|
|
242
|
+
generators
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
if (Array.isArray(result[provider])) {
|
|
246
|
+
// dedupe service info
|
|
247
|
+
if (!result[provider].find(existingServiceInfo => (0, _isEqual.default)(existingServiceInfo, serviceInfo))) {
|
|
248
|
+
result[provider].push(serviceInfo);
|
|
249
|
+
}
|
|
250
|
+
} else {
|
|
251
|
+
result[provider] = [serviceInfo];
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
return result;
|
|
256
|
+
} // Follow refs to find the path between two shapes in a schema
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
function pathBetween(fromShape, toShape, projectSchema) {
|
|
260
|
+
if (fromShape.name === toShape.name) {
|
|
261
|
+
return [];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const toShapeName = toShape.name;
|
|
265
|
+
let shortestPath;
|
|
266
|
+
let shortestPathLength = Number.MAX_SAFE_INTEGER;
|
|
267
|
+
|
|
268
|
+
const pathBetweenHelper = (schema, pathSoFar, seen) => {
|
|
269
|
+
const refItem = (0, _refs.getRefOrItemsRef)(projectSchema, schema);
|
|
270
|
+
|
|
271
|
+
if (refItem) {
|
|
272
|
+
const referenced = (0, _refs.refItemToShape)(projectSchema, refItem);
|
|
273
|
+
|
|
274
|
+
if (referenced) {
|
|
275
|
+
if (referenced.name === toShapeName && pathSoFar.length < shortestPathLength) {
|
|
276
|
+
shortestPath = pathSoFar;
|
|
277
|
+
shortestPathLength = pathSoFar.length;
|
|
278
|
+
} else if (!seen.has(referenced.name)) {
|
|
279
|
+
pathBetweenHelper(referenced.schema, pathSoFar, new Set([...seen, referenced.name]));
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
} else if (pathSoFar.length + 1 < shortestPathLength && (schema.oneOf || schema.allOf || schema.properties)) {
|
|
283
|
+
if (schema.oneOf) {
|
|
284
|
+
for (const itemSchema of schema.oneOf) {
|
|
285
|
+
pathBetweenHelper(itemSchema, pathSoFar, seen);
|
|
286
|
+
}
|
|
287
|
+
} else {
|
|
288
|
+
for (const [propName, propSchema] of createSchemaPropertyList(projectSchema, schema).getNodes()) {
|
|
289
|
+
pathBetweenHelper(propSchema, pathSoFar.concat(String(propName)), seen);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
pathBetweenHelper(fromShape.schema, [], new Set([fromShape.name]));
|
|
296
|
+
|
|
297
|
+
if (!shortestPath) {
|
|
298
|
+
throw new Error(`No path between ${fromShape.name} and ${toShape.name}`);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
return shortestPath;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function getShapeQueriesAndMutations(shapeList) {
|
|
305
|
+
const queries = {};
|
|
306
|
+
const mutations = {};
|
|
307
|
+
|
|
308
|
+
for (const shape of shapeList) {
|
|
309
|
+
const {
|
|
310
|
+
name,
|
|
311
|
+
model
|
|
312
|
+
} = shape;
|
|
313
|
+
const service = stringifyQuerySource('takeshape', 'local');
|
|
314
|
+
|
|
315
|
+
if (model) {
|
|
316
|
+
const isSingleton = model.type === 'single';
|
|
317
|
+
queries[`get${name}`] = {
|
|
318
|
+
shape: name,
|
|
319
|
+
resolver: {
|
|
320
|
+
name: 'takeshape:get',
|
|
321
|
+
service,
|
|
322
|
+
options: {
|
|
323
|
+
model: name
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
description: `Get a ${name} by ID`,
|
|
327
|
+
args: isSingleton ? (0, _templateShapes.createTemplateShapeName)('TSGetSingletonArgs', name) : (0, _templateShapes.createTemplateShapeName)('TSGetArgs', name)
|
|
328
|
+
};
|
|
329
|
+
mutations[`update${name}`] = {
|
|
330
|
+
shape: (0, _templateShapes.createTemplateShapeName)('UpdateResult', name),
|
|
331
|
+
resolver: {
|
|
332
|
+
name: 'takeshape:update',
|
|
333
|
+
service,
|
|
334
|
+
options: {
|
|
335
|
+
model: name
|
|
336
|
+
}
|
|
337
|
+
},
|
|
338
|
+
description: `Update ${name}`,
|
|
339
|
+
args: (0, _templateShapes.createTemplateShapeName)('UpdateArgs', name)
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
if (!isSingleton) {
|
|
343
|
+
queries[`get${name}List`] = {
|
|
344
|
+
shape: (0, _templateShapes.createTemplateShapeName)('PaginatedList', name),
|
|
345
|
+
resolver: {
|
|
346
|
+
name: 'takeshape:list',
|
|
347
|
+
service,
|
|
348
|
+
options: {
|
|
349
|
+
model: name
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
description: `Returns a list ${name} in natural order.`,
|
|
353
|
+
args: (0, _templateShapes.createTemplateShapeName)('TSListArgs', name)
|
|
354
|
+
};
|
|
355
|
+
mutations[`create${name}`] = {
|
|
356
|
+
shape: (0, _templateShapes.createTemplateShapeName)('CreateResult', name),
|
|
357
|
+
resolver: {
|
|
358
|
+
name: 'takeshape:create',
|
|
359
|
+
service,
|
|
360
|
+
options: {
|
|
361
|
+
model: name
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
description: `Create ${name}`,
|
|
365
|
+
args: (0, _templateShapes.createTemplateShapeName)('CreateArgs', name)
|
|
366
|
+
};
|
|
367
|
+
mutations[`duplicate${name}`] = {
|
|
368
|
+
shape: (0, _templateShapes.createTemplateShapeName)('DuplicateResult', name),
|
|
369
|
+
resolver: {
|
|
370
|
+
name: 'takeshape:duplicate',
|
|
371
|
+
service,
|
|
372
|
+
options: {
|
|
373
|
+
model: name
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
description: `Duplicate ${name}`,
|
|
377
|
+
args: (0, _templateShapes.createTemplateShapeName)('DuplicateArgs', name)
|
|
378
|
+
};
|
|
379
|
+
mutations[`delete${name}`] = {
|
|
380
|
+
shape: (0, _templateShapes.createTemplateShapeName)('DeleteResult', name),
|
|
381
|
+
resolver: {
|
|
382
|
+
name: 'takeshape:delete',
|
|
383
|
+
service,
|
|
384
|
+
options: {
|
|
385
|
+
model: name
|
|
386
|
+
}
|
|
387
|
+
},
|
|
388
|
+
description: `Delete ${name}`,
|
|
389
|
+
args: (0, _templateShapes.createTemplateShapeName)('DeleteArgs', name)
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return {
|
|
396
|
+
queries,
|
|
397
|
+
mutations
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function getBuiltInProperties(apiVersion = _versions.CURRENT_API_VERSION) {
|
|
402
|
+
const showV1Deprecation = apiVersion !== '1';
|
|
403
|
+
return { ...commonProperties,
|
|
404
|
+
_enabled: {
|
|
405
|
+
title: 'Enabled',
|
|
406
|
+
type: 'boolean',
|
|
407
|
+
'@deprecationReason': showV1Deprecation ? 'Use _status instead' : undefined
|
|
408
|
+
},
|
|
409
|
+
_enabledAt: {
|
|
410
|
+
title: 'Enabled Date',
|
|
411
|
+
type: 'string',
|
|
412
|
+
format: 'date-time',
|
|
413
|
+
'@deprecationReason': showV1Deprecation ? 'Use a custom date field instead' : undefined
|
|
414
|
+
}
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Return all the built in property names,
|
|
419
|
+
*/
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
const getBuiltInPropertyNames = (apiVersion = _versions.CURRENT_API_VERSION) => new Set([...Object.keys(getBuiltInProperties()), (0, _apiVersion.workflowsEnabled)(apiVersion) ? '_status' : undefined].filter(_util.isDefined));
|
|
423
|
+
|
|
424
|
+
exports.getBuiltInPropertyNames = getBuiltInPropertyNames;
|
|
425
|
+
|
|
426
|
+
function applyBuiltinPropertiesToShape(projectSchema, shape) {
|
|
427
|
+
return { ...shape,
|
|
428
|
+
schema: { ...shape.schema,
|
|
429
|
+
properties: { ...(0, _omitBy.default)(dereferenceObjectSchema(projectSchema, shape.schema).properties, (_, name) => name.startsWith('_')),
|
|
430
|
+
...getBuiltInProperties(projectSchema.apiVersion),
|
|
431
|
+
...((0, _apiVersion.workflowsEnabled)(projectSchema.apiVersion) && {
|
|
432
|
+
_status: (0, _workflows.getStatusField)(projectSchema.workflows, shape)
|
|
433
|
+
})
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
function mergeSchemaProperties(base, overrides) {
|
|
440
|
+
const result = { ...base,
|
|
441
|
+
properties: { ...base.properties,
|
|
442
|
+
...overrides.properties
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
const required = (0, _union.default)(base.required, overrides.required);
|
|
446
|
+
|
|
447
|
+
if (required.length) {
|
|
448
|
+
result.required = required;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
return result;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
function mergeFormProperties(base, overrides) {
|
|
455
|
+
const result = { ...base,
|
|
456
|
+
properties: { ...base.properties,
|
|
457
|
+
...overrides.properties
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
const order = (0, _union.default)(base.order, overrides.order);
|
|
461
|
+
|
|
462
|
+
if (order.length) {
|
|
463
|
+
result.order = order;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
return result;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
function applyDefaultsToSchema(projectSchema) {
|
|
470
|
+
return { ...projectSchema,
|
|
471
|
+
workflows: { ...projectSchema.workflows,
|
|
472
|
+
...((0, _apiVersion.workflowsEnabled)(projectSchema.apiVersion) && {
|
|
473
|
+
default: _workflows.defaultWorkflow
|
|
474
|
+
})
|
|
475
|
+
},
|
|
476
|
+
queries: { ...builtInQueriesAndMutations.queries,
|
|
477
|
+
...projectSchema.queries
|
|
478
|
+
},
|
|
479
|
+
mutations: { ...builtInQueriesAndMutations.mutations,
|
|
480
|
+
...projectSchema.mutations
|
|
481
|
+
},
|
|
482
|
+
shapes: (0, _mapValues.default)({ ..._builtinSchema.builtInShapes,
|
|
483
|
+
...projectSchema.shapes
|
|
484
|
+
}, shape => {
|
|
485
|
+
const builtInShape = _builtinSchema.builtInShapes[shape.name];
|
|
486
|
+
|
|
487
|
+
if (builtInShape && builtInShape !== shape) {
|
|
488
|
+
shape = { ...shape,
|
|
489
|
+
schema: mergeSchemaProperties(dereferenceObjectSchema(projectSchema, shape.schema), dereferenceObjectSchema(projectSchema, builtInShape.schema))
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
return isModelShape(shape) ? applyBuiltinPropertiesToShape(projectSchema, shape) : shape;
|
|
494
|
+
}),
|
|
495
|
+
forms: (0, _mapValues.default)({ ..._builtinSchema.builtInForms,
|
|
496
|
+
...projectSchema.forms
|
|
497
|
+
}, (formsConfig, shapeName) => {
|
|
498
|
+
const builtInFormsConfig = _builtinSchema.builtInForms[shapeName];
|
|
499
|
+
|
|
500
|
+
if (builtInFormsConfig && builtInFormsConfig !== formsConfig) {
|
|
501
|
+
formsConfig = { ...formsConfig,
|
|
502
|
+
default: mergeFormProperties(formsConfig.default, builtInFormsConfig.default)
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
return formsConfig;
|
|
507
|
+
})
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
function addRelationship(relationships, id, env) {
|
|
512
|
+
if (!relationships[id]) {
|
|
513
|
+
relationships[id] = [];
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
relationships[id].push(env);
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Finds all relationships in the schema and returns an object indexed by shape.id that lists all of the shapes
|
|
520
|
+
* properties that reference it
|
|
521
|
+
*/
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
function findExistingRelationships(projectSchema, shapes) {
|
|
525
|
+
const relationships = {};
|
|
526
|
+
const shapeArray = Object.values(shapes);
|
|
527
|
+
const shapesSeen = new Set();
|
|
528
|
+
const shapeIds = new Set(shapeArray.map(shape => shape.id));
|
|
529
|
+
|
|
530
|
+
const findRelationships = (schema, path) => {
|
|
531
|
+
const shapeName = (0, _refs.getRefShapeName)(projectSchema, schema);
|
|
532
|
+
|
|
533
|
+
if (shapeName && !shapes[shapeName]) {
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
const prop = shapeName ? (0, _refs.followRef)(projectSchema, schema) : schema;
|
|
538
|
+
|
|
539
|
+
if (prop['@relationship']) {
|
|
540
|
+
const {
|
|
541
|
+
shapeIds: relatedShapeIds,
|
|
542
|
+
relatedName
|
|
543
|
+
} = prop['@relationship'];
|
|
544
|
+
|
|
545
|
+
for (const shapeId of relatedShapeIds) {
|
|
546
|
+
if (shapeIds.has(shapeId)) {
|
|
547
|
+
addRelationship(relationships, shapeId, {
|
|
548
|
+
relatedName,
|
|
549
|
+
path: path.slice(1),
|
|
550
|
+
shapeId: path[0]
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
if (shapeName) {
|
|
557
|
+
// skip shapes we have already seen to avoid cycles
|
|
558
|
+
if (shapesSeen.has(shapeName)) {
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
shapesSeen.add(shapeName);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
if (prop.properties) {
|
|
566
|
+
for (const name of Object.keys(prop.properties)) {
|
|
567
|
+
findRelationships(prop.properties[name], path.concat(name));
|
|
568
|
+
}
|
|
569
|
+
} else if (prop.items) {
|
|
570
|
+
findRelationships(prop.items, path);
|
|
571
|
+
}
|
|
572
|
+
};
|
|
573
|
+
|
|
574
|
+
for (const shape of shapeArray) {
|
|
575
|
+
if (isModelShape(shape)) {
|
|
576
|
+
const {
|
|
577
|
+
schema,
|
|
578
|
+
id
|
|
579
|
+
} = shape;
|
|
580
|
+
findRelationships(schema, [id]);
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
return relationships;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
function stringifyQuerySource(providerId, serviceId) {
|
|
588
|
+
return `${providerId}:${serviceId}`;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
function parseQuerySource(source) {
|
|
592
|
+
const [providerId, serviceId] = source.split(':');
|
|
593
|
+
return {
|
|
594
|
+
providerId,
|
|
595
|
+
serviceId
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
function parseQueryResolver(resolver) {
|
|
600
|
+
const [providerId, verb] = resolver.split(':');
|
|
601
|
+
return {
|
|
602
|
+
providerId,
|
|
603
|
+
verb
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
function getShapeById(projectSchema, shapeId) {
|
|
608
|
+
return (0, _find.default)(projectSchema.shapes, shape => shape.id === shapeId);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
function isModelShape(shape) {
|
|
612
|
+
return Boolean(shape.model);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
function getArgsReference(projectSchema, argsSchema) {
|
|
616
|
+
var _argsSchema$Args;
|
|
617
|
+
|
|
618
|
+
const args = (_argsSchema$Args = argsSchema['@args']) !== null && _argsSchema$Args !== void 0 ? _argsSchema$Args : argsSchema.args;
|
|
619
|
+
|
|
620
|
+
if (args && typeof args === 'string') {
|
|
621
|
+
// @args: ShapeName OR Namespace_TypeName
|
|
622
|
+
return (0, _refs.refExpressionToRefItem)(projectSchema, args);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
function getArgsReferenceWithPath(projectSchema, argsSchema, schemaPath = []) {
|
|
627
|
+
const refItem = getArgsReference(projectSchema, argsSchema);
|
|
628
|
+
|
|
629
|
+
if (refItem) {
|
|
630
|
+
const argsType = (0, _types.getArgsType)(argsSchema);
|
|
631
|
+
return { ...refItem,
|
|
632
|
+
path: schemaPath.concat([argsType])
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
function getArgsShapeSchema(projectSchema, argsSchema) {
|
|
638
|
+
var _argsSchema$Args2;
|
|
639
|
+
|
|
640
|
+
const args = (_argsSchema$Args2 = argsSchema['@args']) !== null && _argsSchema$Args2 !== void 0 ? _argsSchema$Args2 : argsSchema.args;
|
|
641
|
+
|
|
642
|
+
if (args && typeof args === 'string') {
|
|
643
|
+
const refItem = getArgsReference(projectSchema, argsSchema);
|
|
644
|
+
|
|
645
|
+
if (refItem) {
|
|
646
|
+
return (0, _refs.refItemToShapeSchema)(projectSchema, refItem);
|
|
647
|
+
}
|
|
648
|
+
} else if (args) {
|
|
649
|
+
return args;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* Helper fn to omit `allOf` props from the target schema, and then extend it with the source schema.
|
|
654
|
+
*/
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
const omitAllOfAndExtend = (targetSchema, sourceSchema) => (0, _assign.default)((0, _omit.default)(['allOf'], targetSchema), sourceSchema);
|
|
658
|
+
|
|
659
|
+
const createShapeToContentSchema = (projectSchema, definitions, definitionNames, useShapeIdDiscriminator = true) => {
|
|
660
|
+
const rewriteRefs = (shape, addDiscriminator = false) => {
|
|
661
|
+
const shapeSchemaCopy = dereferenceObjectSchema(projectSchema, (0, _util.deepClone)(shape.schema));
|
|
662
|
+
|
|
663
|
+
if (useShapeIdDiscriminator) {
|
|
664
|
+
if (addDiscriminator && shapeSchemaCopy.properties) {
|
|
665
|
+
shapeSchemaCopy.properties._shapeId = {
|
|
666
|
+
type: 'string',
|
|
667
|
+
enum: [shape.id]
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
if (addDiscriminator && shape.title) {
|
|
672
|
+
shapeSchemaCopy.title = shape.title;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
const handleSchema = (propSchema, addDiscriminator = false) => {
|
|
677
|
+
var _propSchema$items;
|
|
678
|
+
|
|
679
|
+
// unwrap array schema
|
|
680
|
+
propSchema = (_propSchema$items = propSchema.items) !== null && _propSchema$items !== void 0 ? _propSchema$items : propSchema;
|
|
681
|
+
|
|
682
|
+
if ((0, _types.isOneOfSchema)(propSchema)) {
|
|
683
|
+
propSchema.oneOf.forEach(schema => {
|
|
684
|
+
handleSchema(schema, true);
|
|
685
|
+
});
|
|
686
|
+
return;
|
|
687
|
+
} // Add workflow validation
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
if (propSchema['@workflow']) {
|
|
691
|
+
const workflowName = propSchema['@workflow'];
|
|
692
|
+
const workflow = projectSchema.workflows[workflowName] || _workflows.defaultWorkflow;
|
|
693
|
+
propSchema.oneOf = workflow.steps.map(step => ({
|
|
694
|
+
enum: [step.key, step.name],
|
|
695
|
+
title: step.title
|
|
696
|
+
}));
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
const refItem = (0, _refs.getRef)(projectSchema, propSchema);
|
|
700
|
+
|
|
701
|
+
if (refItem) {
|
|
702
|
+
const shapeName = (0, _refs.refItemToShapeName)(refItem);
|
|
703
|
+
const shape = (0, _refs.refItemToShape)(projectSchema, refItem);
|
|
704
|
+
|
|
705
|
+
if (shape) {
|
|
706
|
+
delete propSchema['@ref'];
|
|
707
|
+
propSchema.$ref = `#/definitions/${shapeName}`;
|
|
708
|
+
|
|
709
|
+
if (!definitionNames.has(shapeName)) {
|
|
710
|
+
definitionNames.add(shapeName);
|
|
711
|
+
definitions[shapeName] = rewriteRefs(shape, addDiscriminator);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
|
|
717
|
+
Object.values(shapeSchemaCopy.properties).forEach(schema => {
|
|
718
|
+
handleSchema(schema);
|
|
719
|
+
});
|
|
720
|
+
return shapeSchemaCopy;
|
|
721
|
+
};
|
|
722
|
+
|
|
723
|
+
return rewriteRefs;
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
function shapeToContentSchema(projectSchema, shape) {
|
|
727
|
+
const definitions = {};
|
|
728
|
+
const definitionNames = new Set();
|
|
729
|
+
const convert = createShapeToContentSchema(projectSchema, definitions, definitionNames);
|
|
730
|
+
return { ...convert(shape),
|
|
731
|
+
definitions
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
function projectSchemaToJSONSchema(projectSchema) {
|
|
736
|
+
const definitions = {};
|
|
737
|
+
const definitionNames = new Set();
|
|
738
|
+
const convert = createShapeToContentSchema(projectSchema, definitions, definitionNames, false);
|
|
739
|
+
|
|
740
|
+
for (const shape of Object.values(projectSchema.shapes)) {
|
|
741
|
+
definitions[shape.name] = convert(shape);
|
|
742
|
+
definitionNames.add(shape.name);
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
return {
|
|
746
|
+
definitions
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
function getShapeDependencies(projectSchema, shape) {
|
|
751
|
+
const shapeNames = new Set();
|
|
752
|
+
|
|
753
|
+
const findDependencies = schema => {
|
|
754
|
+
var _schema$items;
|
|
755
|
+
|
|
756
|
+
schema = (_schema$items = schema.items) !== null && _schema$items !== void 0 ? _schema$items : schema;
|
|
757
|
+
const refItem = (0, _refs.getRef)(projectSchema, schema);
|
|
758
|
+
|
|
759
|
+
if (refItem) {
|
|
760
|
+
const refShape = (0, _refs.refItemToShape)(projectSchema, refItem);
|
|
761
|
+
|
|
762
|
+
if (refShape && !shapeNames.has(refShape.name)) {
|
|
763
|
+
shapeNames.add(refShape.name);
|
|
764
|
+
findDependencies(dereferenceSchema(projectSchema, refShape.schema));
|
|
765
|
+
}
|
|
766
|
+
} else if ((0, _types.isObjectSchema)(schema) || (0, _types.isAllOfSchema)(schema) || (0, _types.isOneOfSchema)(schema)) {
|
|
767
|
+
visitSchemaProperties(schema, [], findDependencies);
|
|
768
|
+
}
|
|
769
|
+
};
|
|
770
|
+
|
|
771
|
+
findDependencies(shape.schema);
|
|
772
|
+
return [...shapeNames];
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
function getRelevantShapes(projectSchema, params) {
|
|
776
|
+
const {
|
|
777
|
+
shapeIds,
|
|
778
|
+
shapeNames,
|
|
779
|
+
byId = false,
|
|
780
|
+
includeDependencies = true
|
|
781
|
+
} = params;
|
|
782
|
+
|
|
783
|
+
if (shapeNames !== null && shapeNames !== void 0 && shapeNames.length || shapeIds !== null && shapeIds !== void 0 && shapeIds.length) {
|
|
784
|
+
const ids = new Set(shapeIds);
|
|
785
|
+
const names = new Set(shapeNames);
|
|
786
|
+
const shapes = {};
|
|
787
|
+
|
|
788
|
+
for (const shape of Object.values(projectSchema.shapes)) {
|
|
789
|
+
if (ids.has(shape.id) || names.has(shape.name)) {
|
|
790
|
+
const shapeNames = includeDependencies ? [shape.name].concat(getShapeDependencies(projectSchema, shape)) : [shape.name];
|
|
791
|
+
|
|
792
|
+
for (const shapeName of shapeNames) {
|
|
793
|
+
const dependentShape = projectSchema.shapes[shapeName];
|
|
794
|
+
shapes[byId ? dependentShape.id : dependentShape.name] = dependentShape;
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
return shapes;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
return {};
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
function visitSchemaProperties(schema, path, callback) {
|
|
806
|
+
if ((0, _types.isObjectSchema)(schema)) {
|
|
807
|
+
for (const [name, propSchema] of Object.entries(schema.properties)) {
|
|
808
|
+
const newPath = [...path, 'properties', name];
|
|
809
|
+
callback(propSchema, newPath);
|
|
810
|
+
|
|
811
|
+
if ((0, _types.isObjectSchema)(propSchema) || (0, _types.isAllOfSchema)(propSchema) || (0, _types.isOneOfSchema)(propSchema)) {
|
|
812
|
+
visitSchemaProperties(propSchema, newPath, callback);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
} else if ((0, _types.isAllOfSchema)(schema)) {
|
|
816
|
+
for (const [index, propSchema] of Object.entries(schema.allOf)) {
|
|
817
|
+
const newPath = [...path, 'allOf', index];
|
|
818
|
+
callback(propSchema, newPath);
|
|
819
|
+
|
|
820
|
+
if ((0, _types.isObjectSchema)(propSchema) || (0, _types.isAllOfSchema)(propSchema) || (0, _types.isOneOfSchema)(propSchema)) {
|
|
821
|
+
visitSchemaProperties(propSchema, newPath, callback);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
} else if ((0, _types.isOneOfSchema)(schema)) {
|
|
825
|
+
for (const [index, propSchema] of Object.entries(schema.oneOf)) {
|
|
826
|
+
const newPath = [...path, 'oneOf', index];
|
|
827
|
+
callback(propSchema, newPath);
|
|
828
|
+
|
|
829
|
+
if ((0, _types.isObjectSchema)(propSchema) || (0, _types.isAllOfSchema)(propSchema) || (0, _types.isOneOfSchema)(propSchema)) {
|
|
830
|
+
visitSchemaProperties(propSchema, newPath, callback);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
} else {
|
|
834
|
+
callback(schema, path);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
function visitShapeProperties(shapes, callback) {
|
|
839
|
+
for (const [shapeName, shape] of Object.entries(shapes)) {
|
|
840
|
+
visitSchemaProperties(shape.schema, ['shapes', shapeName, 'schema'], callback);
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
function addRef(refs, ref, predicate) {
|
|
845
|
+
if (ref && (!predicate || predicate(ref))) {
|
|
846
|
+
refs.push(ref);
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
/**
|
|
850
|
+
* Walk through a `ProjectSchema` and collect all the `ref`s.
|
|
851
|
+
*/
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
function getAllRefsInShapes(projectSchema, predicate) {
|
|
855
|
+
const items = [];
|
|
856
|
+
|
|
857
|
+
const shapeVisitor = (schema, schemaPath) => {
|
|
858
|
+
var _schema$items2;
|
|
859
|
+
|
|
860
|
+
if (schema['@args'] && typeof schema['@args'] === 'object') {
|
|
861
|
+
visitSchemaProperties(schema['@args'], schemaPath.concat(['@args']), (argSchema, argPath) => {
|
|
862
|
+
addRef(items, (0, _refs.getRefOrItemsRef)(projectSchema, argSchema, argPath), predicate);
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
addRef(items, getArgsReferenceWithPath(projectSchema, schema, schemaPath), predicate);
|
|
867
|
+
const newPath = schema.items ? schemaPath.concat('items') : schemaPath;
|
|
868
|
+
const newSchema = (_schema$items2 = schema.items) !== null && _schema$items2 !== void 0 ? _schema$items2 : schema;
|
|
869
|
+
|
|
870
|
+
if ((0, _types.isRefSchema)(newSchema)) {
|
|
871
|
+
addRef(items, (0, _refs.getRefOrItemsRef)(projectSchema, newSchema, newPath), predicate);
|
|
872
|
+
} else if ((0, _types.isObjectSchema)(newSchema) || (0, _types.isAllOfSchema)(newSchema) || (0, _types.isOneOfSchema)(newSchema)) {
|
|
873
|
+
visitSchemaProperties(newSchema, newPath, shapeVisitor);
|
|
874
|
+
}
|
|
875
|
+
};
|
|
876
|
+
|
|
877
|
+
for (const [shapeName, shape] of Object.entries(projectSchema.shapes)) {
|
|
878
|
+
visitSchemaProperties(shape.schema, ['shapes', shapeName, 'schema'], shapeVisitor);
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
return items;
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* Get all refs
|
|
885
|
+
*/
|
|
886
|
+
|
|
887
|
+
|
|
888
|
+
function getAllRefsInQuery(projectSchema, queryPath, query, predicate) {
|
|
889
|
+
const refItems = [];
|
|
890
|
+
|
|
891
|
+
const propertyVisitor = (propSchema, propSchemaPath) => {
|
|
892
|
+
addRef(refItems, (0, _refs.getRefOrItemsRef)(projectSchema, propSchema, propSchemaPath), predicate);
|
|
893
|
+
};
|
|
894
|
+
|
|
895
|
+
if (query.args && typeof query.args === 'string') {
|
|
896
|
+
addRef(refItems, getArgsReferenceWithPath(projectSchema, query, queryPath), predicate);
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
if (query.args && typeof query.args === 'object') {
|
|
900
|
+
visitSchemaProperties(dereferenceObjectSchema(projectSchema, query.args), queryPath, propertyVisitor);
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
if (query.shape) {
|
|
904
|
+
const refItem = (0, _templateShapes.parseReturnShape)(projectSchema, query.shape).ref;
|
|
905
|
+
|
|
906
|
+
if (refItem) {
|
|
907
|
+
addRef(refItems, { ...refItem,
|
|
908
|
+
path: queryPath.concat(['shape'])
|
|
909
|
+
}, predicate);
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
return refItems;
|
|
914
|
+
}
|
|
915
|
+
/**
|
|
916
|
+
* Collect refs from `queries` or `mutations`.
|
|
917
|
+
*/
|
|
918
|
+
|
|
919
|
+
|
|
920
|
+
function getAllRefsInQueries(projectSchema, rootPropertyName, predicate) {
|
|
921
|
+
const refItems = [];
|
|
922
|
+
const rootPath = [rootPropertyName];
|
|
923
|
+
|
|
924
|
+
for (const [queryName, query] of Object.entries(projectSchema[rootPropertyName])) {
|
|
925
|
+
const queryPath = rootPath.concat([queryName]);
|
|
926
|
+
const queryRefs = getAllRefsInQuery(projectSchema, queryPath, query, predicate);
|
|
927
|
+
|
|
928
|
+
if (queryRefs.length) {
|
|
929
|
+
refItems.push(...queryRefs);
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
return refItems;
|
|
934
|
+
}
|
|
935
|
+
/**
|
|
936
|
+
* Get all refs in a ProjectSchema
|
|
937
|
+
* @param predicate return true to include the ref in
|
|
938
|
+
*/
|
|
939
|
+
|
|
940
|
+
|
|
941
|
+
function getAllRefs(projectSchema, predicate) {
|
|
942
|
+
return [...getAllRefsInShapes(projectSchema, predicate), ...getAllRefsInQueries(projectSchema, 'queries', predicate), ...getAllRefsInQueries(projectSchema, 'mutations', predicate)];
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
function parseMapping(mapping) {
|
|
946
|
+
const [providerId, serviceId, coordinate] = mapping.split(':');
|
|
947
|
+
const [shapeName, key] = coordinate.split('.');
|
|
948
|
+
return {
|
|
949
|
+
providerId,
|
|
950
|
+
serviceId,
|
|
951
|
+
shapeName,
|
|
952
|
+
key
|
|
953
|
+
};
|
|
954
|
+
}
|
|
955
|
+
|
|
956
|
+
function splitMapping(mapping) {
|
|
957
|
+
return mapping.split('.');
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
function findMapping(schema, predicate) {
|
|
961
|
+
const mapping = schema['@mapping'];
|
|
962
|
+
|
|
963
|
+
if (Array.isArray(mapping)) {
|
|
964
|
+
return mapping.find(predicate);
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
return mapping && predicate(mapping) ? mapping : undefined;
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
function getFirstMapping(schema) {
|
|
971
|
+
return Array.isArray(schema['@mapping']) ? schema['@mapping'][0] : schema['@mapping'];
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
function getFullyQualifiedShapeName(schema) {
|
|
975
|
+
const first = getFirstMapping(schema);
|
|
976
|
+
return first ? splitMapping(first)[0] : undefined;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
function getKey(schema) {
|
|
980
|
+
const first = getFirstMapping(schema);
|
|
981
|
+
return first ? splitMapping(first)[1] : undefined;
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
function getPropertyService(schema) {
|
|
985
|
+
const first = getFirstMapping(schema);
|
|
986
|
+
const split = first === null || first === void 0 ? void 0 : first.split(':');
|
|
987
|
+
return split ? `${split[0]}:${split[1]}` : undefined;
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
function emptySchema(projectId, dataKey) {
|
|
991
|
+
const now = new Date().toISOString();
|
|
992
|
+
return {
|
|
993
|
+
projectId,
|
|
994
|
+
dataKey,
|
|
995
|
+
version: 1,
|
|
996
|
+
created: now,
|
|
997
|
+
updated: now,
|
|
998
|
+
defaultLocale: 'en-us',
|
|
999
|
+
locales: ['en-us'],
|
|
1000
|
+
apiVersion: '2',
|
|
1001
|
+
schemaVersion: _versions.CURRENT_SCHEMA_VERSION,
|
|
1002
|
+
queries: {},
|
|
1003
|
+
mutations: {},
|
|
1004
|
+
shapes: {},
|
|
1005
|
+
workflows: {},
|
|
1006
|
+
forms: {}
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
function getShapesById(projectSchema) {
|
|
1011
|
+
return (0, _keyBy.default)(Object.values(projectSchema.shapes), 'id');
|
|
1012
|
+
}
|
|
1013
|
+
/**
|
|
1014
|
+
* Walk through the project schema and return an array of all
|
|
1015
|
+
* referenced shape names that are in a service namespace.
|
|
1016
|
+
*
|
|
1017
|
+
* @param projectSchema A V3 project schema.
|
|
1018
|
+
*
|
|
1019
|
+
* @returns A `string` array with all the shapes that are in namespaces.
|
|
1020
|
+
*/
|
|
1021
|
+
|
|
1022
|
+
|
|
1023
|
+
function getAllNamespaceShapes(projectSchema) {
|
|
1024
|
+
return (0, _uniq.default)(getAllRefs(projectSchema, refItem => Boolean(refItem.serviceNamespace)).map(_refs.refItemToShapeName));
|
|
1025
|
+
}
|
|
1026
|
+
/**
|
|
1027
|
+
* Returns a list of all shape names in a service namespace, excluding any
|
|
1028
|
+
* that have been set directly in the project schema
|
|
1029
|
+
*
|
|
1030
|
+
* @todo It's unsound to discard dependencies in this way, should avoid
|
|
1031
|
+
* collisions with aliases or similar any remote shape that collides,
|
|
1032
|
+
* e.g., Shopify_Product -> Shopify_Product_2
|
|
1033
|
+
*
|
|
1034
|
+
* @param projectSchema A V3 project schema with remote service configs.
|
|
1035
|
+
*
|
|
1036
|
+
* @returns A `Set` of shape names.
|
|
1037
|
+
*/
|
|
1038
|
+
|
|
1039
|
+
|
|
1040
|
+
function getNamespacedShapeNameList(projectSchema) {
|
|
1041
|
+
const requiredShapeNames = new Set(); // All the shape names
|
|
1042
|
+
|
|
1043
|
+
const existingShapeNames = new Set(Object.keys(projectSchema.shapes)); // All the referenced shape names with namespaces that belong to a service
|
|
1044
|
+
|
|
1045
|
+
const namespacedShapeNames = new Set(getAllNamespaceShapes(projectSchema)); // Add all namespaced shapes to the schema if they are not already present,
|
|
1046
|
+
// e.g. Shopify_Product
|
|
1047
|
+
|
|
1048
|
+
namespacedShapeNames.forEach(name => {
|
|
1049
|
+
if (!existingShapeNames.has(name)) {
|
|
1050
|
+
requiredShapeNames.add(name);
|
|
1051
|
+
}
|
|
1052
|
+
});
|
|
1053
|
+
return requiredShapeNames;
|
|
1054
|
+
}
|
|
1055
|
+
/**
|
|
1056
|
+
* Filter the service map to return only services passing the GraphQL Service
|
|
1057
|
+
* typeguard.
|
|
1058
|
+
*
|
|
1059
|
+
* @param serviceMap A service map.
|
|
1060
|
+
*
|
|
1061
|
+
* @returns A new map with the filtered list of services
|
|
1062
|
+
*/
|
|
1063
|
+
|
|
1064
|
+
|
|
1065
|
+
function filterGraphQLServiceMap(serviceMap) {
|
|
1066
|
+
const filtered = new Map();
|
|
1067
|
+
|
|
1068
|
+
for (const [serviceKey, serviceConfig] of serviceMap) {
|
|
1069
|
+
if (serviceConfig.serviceType === 'graphql') {
|
|
1070
|
+
filtered.set(serviceKey, serviceConfig);
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
return filtered;
|
|
1075
|
+
}
|
|
1076
|
+
/**
|
|
1077
|
+
* Add all referenced shape names to the refSet meant to be used as a callback to visitSchemaProperties
|
|
1078
|
+
*/
|
|
1079
|
+
|
|
1080
|
+
|
|
1081
|
+
function collectReferencedShapeNames(projectSchema, refSet) {
|
|
1082
|
+
const collect = schema => {
|
|
1083
|
+
const args = schema['@args'];
|
|
1084
|
+
|
|
1085
|
+
if (args && (0, _isObject.default)(args) && (0, _types.isObjectSchema)(args)) {
|
|
1086
|
+
Object.values(args.properties).forEach(collect);
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
const argsRefItem = getArgsReference(projectSchema, schema);
|
|
1090
|
+
|
|
1091
|
+
if (argsRefItem) {
|
|
1092
|
+
refSet.add((0, _refs.refItemToShapeName)(argsRefItem));
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
const refItem = (0, _refs.getRefOrItemsRef)(projectSchema, schema);
|
|
1096
|
+
|
|
1097
|
+
if (refItem) {
|
|
1098
|
+
refSet.add((0, _refs.refItemToShapeName)(refItem));
|
|
1099
|
+
}
|
|
1100
|
+
};
|
|
1101
|
+
|
|
1102
|
+
return collect;
|
|
1103
|
+
}
|
|
1104
|
+
/**
|
|
1105
|
+
* Get the subset of a schema that was automatically created or should otherwise
|
|
1106
|
+
* have special protection against editing or deleting.
|
|
1107
|
+
*/
|
|
1108
|
+
|
|
1109
|
+
|
|
1110
|
+
function getProtectedSchema(schema) {
|
|
1111
|
+
const shapeQueriesAndMutations = getShapeQueriesAndMutations(Object.values({ ..._builtinSchema.builtInShapes,
|
|
1112
|
+
...schema.shapes
|
|
1113
|
+
}));
|
|
1114
|
+
const namespaceShapes = getAllNamespaceShapes(schema);
|
|
1115
|
+
return {
|
|
1116
|
+
shapes: (0, _pickBy.default)(schema.shapes, (_, key) => {
|
|
1117
|
+
return namespaceShapes.includes(key) || isBuiltinShape(key);
|
|
1118
|
+
}),
|
|
1119
|
+
queries: (0, _pickBy.default)(schema.queries, (_, key) => {
|
|
1120
|
+
return shapeQueriesAndMutations.queries[key] !== undefined;
|
|
1121
|
+
}),
|
|
1122
|
+
mutations: (0, _pickBy.default)(schema.mutations, (_, key) => {
|
|
1123
|
+
return shapeQueriesAndMutations.mutations[key] !== undefined;
|
|
1124
|
+
})
|
|
1125
|
+
};
|
|
1126
|
+
}
|
|
1127
|
+
/**
|
|
1128
|
+
* Given a schema, will resolve any `allOf` or `ref` objects. This function has
|
|
1129
|
+
* to fully resolve all refs, because attempting to extend an object schema with
|
|
1130
|
+
* a ref property would create an invalid schema, potentially containing both
|
|
1131
|
+
* a ref and properties.
|
|
1132
|
+
*
|
|
1133
|
+
* If it can't create a valid schema it returns the input.
|
|
1134
|
+
*/
|
|
1135
|
+
|
|
1136
|
+
|
|
1137
|
+
function dereferenceSchema(context, shapeOrFieldSchema, schemaPath = []) {
|
|
1138
|
+
var _resolveAll;
|
|
1139
|
+
|
|
1140
|
+
const resolveAll = (resolveSchema, resolvePath) => {
|
|
1141
|
+
try {
|
|
1142
|
+
if ((0, _types.isAllOfSchema)(resolveSchema)) {
|
|
1143
|
+
const allOfSchema = resolveSchema.allOf.map((stub, index) => resolveAll(stub, [...resolvePath, 'allOf', index])).reduce((prev, curr) => (0, _merge.mergeWithArrayConcat)(prev, curr), {});
|
|
1144
|
+
return (0, _isEmpty.default)(allOfSchema) ? undefined : omitAllOfAndExtend(resolveSchema, allOfSchema);
|
|
1145
|
+
}
|
|
1146
|
+
|
|
1147
|
+
if ((0, _types.isRefSchema)(resolveSchema)) {
|
|
1148
|
+
const refItem = (0, _refs.getRefWithPath)(context, resolveSchema);
|
|
1149
|
+
|
|
1150
|
+
if (!refItem) {
|
|
1151
|
+
throw new Error('ref could not be parsed');
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
const refSchema = (0, _refs.refItemToShapeSchema)(context, refItem);
|
|
1155
|
+
|
|
1156
|
+
if (refSchema) {
|
|
1157
|
+
return resolveAll((0, _refs.omitRefAndExtend)(resolveSchema, refSchema), refItem.path);
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
return;
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
return resolveSchema;
|
|
1164
|
+
} catch (err) {
|
|
1165
|
+
throw new Error(`error at '${resolvePath.join('.')}', ${err.message}`);
|
|
1166
|
+
}
|
|
1167
|
+
};
|
|
1168
|
+
|
|
1169
|
+
return (_resolveAll = resolveAll(shapeOrFieldSchema, schemaPath)) !== null && _resolveAll !== void 0 ? _resolveAll : shapeOrFieldSchema;
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
function dereferenceObjectSchema(context, shapeOrFieldSchema, schemaPath = []) {
|
|
1173
|
+
const schema = dereferenceSchema(context, shapeOrFieldSchema, schemaPath);
|
|
1174
|
+
|
|
1175
|
+
if (!(0, _types.isObjectSchema)(schema)) {
|
|
1176
|
+
throw new Error(`provided schema at '${schemaPath.join('.')}' could not be resolved to an object schema`);
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
return schema;
|
|
1180
|
+
}
|
|
1181
|
+
/**
|
|
1182
|
+
* Creates a schema property list chainable fn, allowing you to manipulate and
|
|
1183
|
+
* iterate the properties in a schema.
|
|
1184
|
+
*/
|
|
1185
|
+
|
|
1186
|
+
|
|
1187
|
+
const createSchemaPropertyList = (0, _curry.default)((context, shapeOrFieldSchema) => {
|
|
1188
|
+
const schema = (0, _types.isContentObjectSchema)(shapeOrFieldSchema) ? dereferenceSchema(context, shapeOrFieldSchema) : shapeOrFieldSchema;
|
|
1189
|
+
const propertyIterator = new Map((0, _types.isObjectSchema)(schema) ? Object.entries(schema.properties) : undefined);
|
|
1190
|
+
const defaultOrderByIteratees = [n => n[0]];
|
|
1191
|
+
const defaultOrderByOrders = ['asc'];
|
|
1192
|
+
|
|
1193
|
+
const _orderBy = (iteratees = defaultOrderByIteratees, orders = defaultOrderByOrders) => {
|
|
1194
|
+
self._propertyIterator = new Map((0, _orderBy2.default)(iteratees, orders, Array.from(self._propertyIterator)));
|
|
1195
|
+
return self;
|
|
1196
|
+
};
|
|
1197
|
+
|
|
1198
|
+
const _sortWith = comparator => {
|
|
1199
|
+
self._propertyIterator = new Map(Array.from(self._propertyIterator).sort(comparator));
|
|
1200
|
+
return self;
|
|
1201
|
+
};
|
|
1202
|
+
|
|
1203
|
+
const _sortByNamesWithList = comparatorArray => {
|
|
1204
|
+
// If no array is provided, the original sort is preserved
|
|
1205
|
+
if (comparatorArray) {
|
|
1206
|
+
self._propertyIterator = new Map(Array.from(self._propertyIterator).filter(([name]) => comparatorArray.includes(name)).sort(([nameA], [nameB]) => {
|
|
1207
|
+
const indexA = comparatorArray.indexOf(nameA);
|
|
1208
|
+
const indexB = comparatorArray.indexOf(nameB);
|
|
1209
|
+
return (indexA > -1 ? indexA : Infinity) - (indexB > -1 ? indexB : Infinity);
|
|
1210
|
+
}));
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
return self;
|
|
1214
|
+
};
|
|
1215
|
+
|
|
1216
|
+
const _filterBy = predicate => {
|
|
1217
|
+
self._propertyIterator = new Map(Array.from(self._propertyIterator).filter(predicate));
|
|
1218
|
+
return self;
|
|
1219
|
+
};
|
|
1220
|
+
|
|
1221
|
+
const _forEach = iteratee => {
|
|
1222
|
+
Array.from(self._propertyIterator).forEach(iteratee);
|
|
1223
|
+
return self;
|
|
1224
|
+
};
|
|
1225
|
+
|
|
1226
|
+
const _getNodes = () => {
|
|
1227
|
+
return Array.from(self._propertyIterator);
|
|
1228
|
+
};
|
|
1229
|
+
|
|
1230
|
+
const _getObject = () => {
|
|
1231
|
+
return Array.from(self._propertyIterator).reduce((curr, node) => Object.assign(curr, {
|
|
1232
|
+
[node[0]]: node[1]
|
|
1233
|
+
}), {});
|
|
1234
|
+
};
|
|
1235
|
+
|
|
1236
|
+
const _getNames = () => {
|
|
1237
|
+
return Array.from(self._propertyIterator, ([name]) => name);
|
|
1238
|
+
};
|
|
1239
|
+
|
|
1240
|
+
const _getValues = () => {
|
|
1241
|
+
return Array.from(self._propertyIterator, ([, value]) => value);
|
|
1242
|
+
};
|
|
1243
|
+
|
|
1244
|
+
const self = {
|
|
1245
|
+
_propertyIterator: propertyIterator,
|
|
1246
|
+
orderBy: _orderBy,
|
|
1247
|
+
sortWith: _sortWith,
|
|
1248
|
+
sortByNamesWithList: _sortByNamesWithList,
|
|
1249
|
+
filterBy: _filterBy,
|
|
1250
|
+
forEach: _forEach,
|
|
1251
|
+
getNodes: _getNodes,
|
|
1252
|
+
getObject: _getObject,
|
|
1253
|
+
getNames: _getNames,
|
|
1254
|
+
getValues: _getValues
|
|
1255
|
+
};
|
|
1256
|
+
return self;
|
|
1257
|
+
});
|
|
1258
|
+
/**
|
|
1259
|
+
* Creates a schema property accessor, allowing you to safely access schema
|
|
1260
|
+
* properties.
|
|
1261
|
+
*/
|
|
1262
|
+
|
|
1263
|
+
exports.createSchemaPropertyList = createSchemaPropertyList;
|
|
1264
|
+
const createSchemaPropertyAccessor = (0, _curry.default)((context, shapeOrFieldSchema) => {
|
|
1265
|
+
const schema = (0, _types.isContentObjectSchema)(shapeOrFieldSchema) ? dereferenceSchema(context, shapeOrFieldSchema) : shapeOrFieldSchema;
|
|
1266
|
+
const propertyIterator = new Map((0, _types.isObjectSchema)(schema) ? Object.entries(schema.properties) : undefined);
|
|
1267
|
+
|
|
1268
|
+
const _getValue = propertyName => {
|
|
1269
|
+
return propertyIterator.get(propertyName);
|
|
1270
|
+
};
|
|
1271
|
+
|
|
1272
|
+
const _findValue = predicate => {
|
|
1273
|
+
var _Array$from$find;
|
|
1274
|
+
|
|
1275
|
+
return (_Array$from$find = Array.from(propertyIterator).find(predicate)) === null || _Array$from$find === void 0 ? void 0 : _Array$from$find[1];
|
|
1276
|
+
};
|
|
1277
|
+
|
|
1278
|
+
const _findName = predicate => {
|
|
1279
|
+
var _Array$from$find2;
|
|
1280
|
+
|
|
1281
|
+
return (_Array$from$find2 = Array.from(propertyIterator).find(predicate)) === null || _Array$from$find2 === void 0 ? void 0 : _Array$from$find2[0];
|
|
1282
|
+
};
|
|
1283
|
+
|
|
1284
|
+
const _getKey = propertyName => {
|
|
1285
|
+
const value = propertyIterator.get(propertyName);
|
|
1286
|
+
|
|
1287
|
+
if (value) {
|
|
1288
|
+
return getKey(value);
|
|
1289
|
+
}
|
|
1290
|
+
};
|
|
1291
|
+
|
|
1292
|
+
return {
|
|
1293
|
+
getValue: _getValue,
|
|
1294
|
+
findValue: _findValue,
|
|
1295
|
+
findName: _findName,
|
|
1296
|
+
getKey: _getKey
|
|
1297
|
+
};
|
|
1298
|
+
});
|
|
1299
|
+
exports.createSchemaPropertyAccessor = createSchemaPropertyAccessor;
|
|
1300
|
+
|
|
1301
|
+
const findHelper = (projectSchema, shapeName, resolver, type) => {
|
|
1302
|
+
const schemaPath = type === 'query' ? 'queries' : 'mutations';
|
|
1303
|
+
const foundQuery = Object.keys(projectSchema[schemaPath]).find(queryName => {
|
|
1304
|
+
var _options;
|
|
1305
|
+
|
|
1306
|
+
const queryOrMutation = projectSchema[schemaPath][queryName];
|
|
1307
|
+
return queryOrMutation.resolver.name === resolver && ((_options = queryOrMutation.resolver.options) === null || _options === void 0 ? void 0 : _options.model) === shapeName;
|
|
1308
|
+
});
|
|
1309
|
+
|
|
1310
|
+
if (!foundQuery) {
|
|
1311
|
+
throw new Error(`Failed find a "${resolver}" ${type} for shape "${shapeName}"`);
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
return foundQuery;
|
|
1315
|
+
};
|
|
1316
|
+
/**
|
|
1317
|
+
* Find the query in the schema that corresponds to the given shape and resolver.
|
|
1318
|
+
*/
|
|
1319
|
+
|
|
1320
|
+
|
|
1321
|
+
const findQuery = (projectSchema, shapeName, resolver) => {
|
|
1322
|
+
return findHelper(projectSchema, shapeName, resolver, 'query');
|
|
1323
|
+
};
|
|
1324
|
+
/**
|
|
1325
|
+
* Find the query in the schema that corresponds to the given shape and resolver.
|
|
1326
|
+
*/
|
|
1327
|
+
|
|
1328
|
+
|
|
1329
|
+
exports.findQuery = findQuery;
|
|
1330
|
+
|
|
1331
|
+
const findMutation = (projectSchema, shapeName, resolver) => {
|
|
1332
|
+
return findHelper(projectSchema, shapeName, resolver, 'mutation');
|
|
1333
|
+
};
|
|
1334
|
+
/**
|
|
1335
|
+
* Find the form config for a given shape name and the form key.
|
|
1336
|
+
*/
|
|
1337
|
+
|
|
1338
|
+
|
|
1339
|
+
exports.findMutation = findMutation;
|
|
1340
|
+
|
|
1341
|
+
function findShapeFormConfig(projectSchema, shapeName, formName) {
|
|
1342
|
+
return (0, _get.default)(projectSchema, ['forms', shapeName, formName]);
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1345
|
+
/**
|
|
1346
|
+
* Find the query in the schema that corresponds to the given shape and resolver.
|
|
1347
|
+
*/
|
|
1348
|
+
const getDefaultMutationName = (shapeName, resolver) => {
|
|
1349
|
+
const action = resolver.substring(resolver.indexOf(':') + 1);
|
|
1350
|
+
return `${action}${shapeName}`;
|
|
1351
|
+
};
|
|
1352
|
+
|
|
1353
|
+
exports.getDefaultMutationName = getDefaultMutationName;
|