@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/es/mocks.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { emptySchema, applyDefaultsToSchema } from './schema-util';
|
|
2
|
+
import { upperCamel } from '@takeshape/util';
|
|
3
|
+
/**
|
|
4
|
+
* Like emptySchema, but setting a default `dataKey`. Only suitable for tests.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export function createMockSchema(projectId, schema = {}) {
|
|
8
|
+
var _schema$dataKey;
|
|
9
|
+
|
|
10
|
+
return { ...emptySchema(projectId, (_schema$dataKey = schema.dataKey) !== null && _schema$dataKey !== void 0 ? _schema$dataKey : 'supersecret'),
|
|
11
|
+
...schema
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Capturing a common pattern used in tests. Creates an empty schema, with a `dataKey` and defaults.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export function createMockSchemaWithDefaults(projectId, schema = {}) {
|
|
19
|
+
var _schema$dataKey2;
|
|
20
|
+
|
|
21
|
+
return applyDefaultsToSchema({ ...emptySchema(projectId, (_schema$dataKey2 = schema.dataKey) !== null && _schema$dataKey2 !== void 0 ? _schema$dataKey2 : 'supersecret'),
|
|
22
|
+
...schema
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export function createMockServiceConfig(serviceKey, serviceConfig) {
|
|
26
|
+
return {
|
|
27
|
+
id: serviceKey,
|
|
28
|
+
title: upperCamel(serviceKey),
|
|
29
|
+
provider: 'generic',
|
|
30
|
+
serviceType: 'graphql',
|
|
31
|
+
namespace: upperCamel(serviceKey),
|
|
32
|
+
authenticationType: 'bearer',
|
|
33
|
+
authentication: {
|
|
34
|
+
token: 'abc123'
|
|
35
|
+
},
|
|
36
|
+
options: {
|
|
37
|
+
endpoint: 'https://example.test/graphql'
|
|
38
|
+
},
|
|
39
|
+
...serviceConfig
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export function createMockStoredServiceConfig(serviceKey, serviceConfig) {
|
|
43
|
+
return { ...createMockServiceConfig(serviceKey),
|
|
44
|
+
authentication: 'encrypted-abc123',
|
|
45
|
+
...serviceConfig
|
|
46
|
+
};
|
|
47
|
+
}
|
package/es/patterns.js
ADDED
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// This file is generated by "pnpm json2ts"
|
|
2
|
+
export * from './v3.6.0';
|
|
3
|
+
export * from './v3.5.1';
|
|
4
|
+
export * from './v3.5.0';
|
|
5
|
+
export * from './v3.4.0';
|
|
6
|
+
export * from './v3.3.0';
|
|
7
|
+
export * from './v3.2.0';
|
|
8
|
+
export * from './v3.1.0';
|
|
9
|
+
export * from './v3.0.0';
|
|
10
|
+
export * from './v1.0.0';
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/es/refs.js
ADDED
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { getRefType, isAllOfSchema, isOneOfSchema, isRefSchema, isRefSchemaLegacy } from './types';
|
|
2
|
+
import { parseTemplateShape } from './template-shapes';
|
|
3
|
+
import get from 'lodash/get';
|
|
4
|
+
import assign from 'lodash/fp/assign';
|
|
5
|
+
import omit from 'lodash/fp/omit';
|
|
6
|
+
import { getServiceNamespace, getServiceNamespaces } from './services';
|
|
7
|
+
|
|
8
|
+
function $refToPath(ref) {
|
|
9
|
+
return ref.substr(2).split('/');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function $refToShapeName(ref) {
|
|
13
|
+
return $refToPath(ref)[1];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function $refToAtRef($ref, service, namespace) {
|
|
17
|
+
const shapeName = $refToShapeName($ref);
|
|
18
|
+
|
|
19
|
+
if (service === 'local') {
|
|
20
|
+
return `local:${shapeName}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return `${service}:${namespace === undefined ? shapeName : shapeName.replace(`${namespace}_`, '')}`;
|
|
24
|
+
}
|
|
25
|
+
export function refSchemaToPath(context, refSchema) {
|
|
26
|
+
const refItem = getRef(context, refSchema);
|
|
27
|
+
|
|
28
|
+
if (refItem === undefined) {
|
|
29
|
+
throw new Error('Invalid ref in refSchemaToPath');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return refItemToShapePath(refItem);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Safely turn a "template" shape reference (`@args`, `args`, `shape`) into a `RefItem`
|
|
36
|
+
*
|
|
37
|
+
* @param context A partial project schema
|
|
38
|
+
* @param refExpression
|
|
39
|
+
* A ref expression might include "template" name and refer to a local or remote
|
|
40
|
+
* shape, `Foo` or `CreateArgs<Foo>` or `CreateArgs<remote:Foo>`.*
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
export function refExpressionToRefItem(context, refExpression) {
|
|
44
|
+
const {
|
|
45
|
+
shapeName,
|
|
46
|
+
template
|
|
47
|
+
} = parseTemplateShape(refExpression);
|
|
48
|
+
|
|
49
|
+
if (shapeName.includes(':')) {
|
|
50
|
+
return atRefToRefItem(context, shapeName, template);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return refToRefItem(context, `#/shapes/${shapeName}/schema`, template);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Sugar for converting a `refExpression` directly into a shape, without the
|
|
57
|
+
* intermediate `refItem`.
|
|
58
|
+
*
|
|
59
|
+
* @param context A partial project schema
|
|
60
|
+
* @param refExpression
|
|
61
|
+
* A ref expression might include "template" name and refer to a local or remote
|
|
62
|
+
* shape, `Foo` or `CreateArgs<Foo>` or `CreateArgs<remote:Foo>`.
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
export function refExpressionToShape(context, refExpression) {
|
|
66
|
+
return refItemToShape(context, refExpressionToRefItem(context, refExpression));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Provided a service name and a referenced type. Supports 2 or 3 part
|
|
70
|
+
* references, e.g., `shopify:my-store:ProductInput` or `my-store:ProductInput`.
|
|
71
|
+
*
|
|
72
|
+
* @returns
|
|
73
|
+
* A 2 member array, where 0 is the service name, 1 is the referenced type.
|
|
74
|
+
*/
|
|
75
|
+
|
|
76
|
+
export function splitAtRef(atRef) {
|
|
77
|
+
const refParts = atRef.split(':');
|
|
78
|
+
const serviceKey = refParts.length === 2 ? refParts[0] : `${refParts[0]}:${refParts[1]}`;
|
|
79
|
+
const referencedType = refParts.length === 2 ? refParts[1] : refParts[2];
|
|
80
|
+
return [serviceKey, referencedType];
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Parses and returns a typeName, serviceKey, and potentially a namespace for
|
|
84
|
+
* the type.
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
export function atRefToRefItem(context, atRef, template) {
|
|
88
|
+
var _context$services;
|
|
89
|
+
|
|
90
|
+
const [serviceKey, typeName] = splitAtRef(atRef); // It's possible the service doesn't have a namespace, or is local and has
|
|
91
|
+
// no service config.
|
|
92
|
+
|
|
93
|
+
const serviceConfig = (_context$services = context.services) === null || _context$services === void 0 ? void 0 : _context$services[serviceKey];
|
|
94
|
+
const serviceNamespace = serviceConfig && getServiceNamespace(serviceConfig);
|
|
95
|
+
return {
|
|
96
|
+
typeName,
|
|
97
|
+
serviceKey,
|
|
98
|
+
serviceNamespace,
|
|
99
|
+
template,
|
|
100
|
+
isForeign: Boolean(serviceConfig)
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export function refToRefItem(context, $ref, template) {
|
|
104
|
+
var _typeName, _serviceKey;
|
|
105
|
+
|
|
106
|
+
const shapeName = $refToShapeName($ref);
|
|
107
|
+
const shapeNameParts = shapeName.split('_');
|
|
108
|
+
let typeName;
|
|
109
|
+
let serviceKey;
|
|
110
|
+
let serviceNamespace;
|
|
111
|
+
|
|
112
|
+
if (shapeNameParts.length > 1) {
|
|
113
|
+
const namespaces = getServiceNamespaces(context);
|
|
114
|
+
const maybeNamespace = shapeNameParts[0];
|
|
115
|
+
serviceKey = namespaces.get(maybeNamespace);
|
|
116
|
+
|
|
117
|
+
if (serviceKey) {
|
|
118
|
+
typeName = shapeNameParts.slice(1).join('_');
|
|
119
|
+
serviceNamespace = maybeNamespace;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
typeName: (_typeName = typeName) !== null && _typeName !== void 0 ? _typeName : shapeName,
|
|
125
|
+
serviceKey: (_serviceKey = serviceKey) !== null && _serviceKey !== void 0 ? _serviceKey : 'local',
|
|
126
|
+
serviceNamespace,
|
|
127
|
+
template,
|
|
128
|
+
isForeign: Boolean(serviceKey)
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Given a content schema and project schema, finds a `@ref` or `$ref` and
|
|
133
|
+
* returns a `RefItem` suitable for loading a referenced schema...
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
export function getRef(context, refSchema) {
|
|
137
|
+
if (refSchema['@ref']) {
|
|
138
|
+
// @ref: my-service:ShapeName
|
|
139
|
+
return atRefToRefItem(context, refSchema['@ref']);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (refSchema.$ref) {
|
|
143
|
+
// $ref: #/shapes/[ShapeName OR Namespace_TypeName]/schema
|
|
144
|
+
return refToRefItem(context, refSchema.$ref);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
export function getRefWithPath(context, refSchema, schemaPath = []) {
|
|
148
|
+
const refItem = getRef(context, refSchema);
|
|
149
|
+
|
|
150
|
+
if (refItem) {
|
|
151
|
+
const refType = getRefType(refSchema);
|
|
152
|
+
return { ...refItem,
|
|
153
|
+
path: schemaPath.concat([refType])
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Tests for a `@ref` or `$ref` property directly on the passed schema.
|
|
159
|
+
*
|
|
160
|
+
* @param schema Any schema that might could have a ref property.
|
|
161
|
+
*/
|
|
162
|
+
|
|
163
|
+
export function hasRefProperty(schema) {
|
|
164
|
+
var _schema$Ref;
|
|
165
|
+
|
|
166
|
+
return Boolean((_schema$Ref = schema['@ref']) !== null && _schema$Ref !== void 0 ? _schema$Ref : schema.$ref);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* From a schema with a ref, will return the top-level ref, and potentially
|
|
170
|
+
* a ref item from a nested `items` property.
|
|
171
|
+
*/
|
|
172
|
+
|
|
173
|
+
export function getRefOrItemsRef(context, refSchema, schemaPath = []) {
|
|
174
|
+
const refItem = getRefWithPath(context, refSchema, schemaPath);
|
|
175
|
+
|
|
176
|
+
if (refItem) {
|
|
177
|
+
return refItem;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
if (refSchema.items) {
|
|
181
|
+
return getRefOrItemsRef(context, refSchema.items, schemaPath.concat(['items']));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Turns a `RefItem` into an `@ref`.
|
|
186
|
+
*/
|
|
187
|
+
|
|
188
|
+
export function refItemToAtRef(refItem) {
|
|
189
|
+
return `${refItem.serviceKey}:${refItem.typeName}`;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Turns a `RefItem` into a standard shape name, namespacing if present.
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
export function refItemToShapeName(refItem) {
|
|
196
|
+
const {
|
|
197
|
+
serviceNamespace,
|
|
198
|
+
typeName
|
|
199
|
+
} = refItem;
|
|
200
|
+
return serviceNamespace ? `${serviceNamespace}_${typeName}` : typeName;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Turns a `RefItem` into a path suitable for `lodash.get`.
|
|
204
|
+
*/
|
|
205
|
+
|
|
206
|
+
export function refItemToShapePath(refItem) {
|
|
207
|
+
return ['shapes', refItemToShapeName(refItem)];
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Get a Shape referenced by a `RefItem`.
|
|
211
|
+
*/
|
|
212
|
+
|
|
213
|
+
export function refItemToShape(context, refItem) {
|
|
214
|
+
const shapePath = refItemToShapePath(refItem);
|
|
215
|
+
return get(context, shapePath);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Get a Shape schema referenced by a `RefItem`.
|
|
219
|
+
*/
|
|
220
|
+
|
|
221
|
+
export function refItemToShapeSchema(context, refItem) {
|
|
222
|
+
const shapePath = refItemToShapePath(refItem);
|
|
223
|
+
return get(context, [...shapePath, 'schema']);
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Sugar, for when you really just need a string...
|
|
227
|
+
*/
|
|
228
|
+
|
|
229
|
+
export function getRefShapeName(context, refSchema) {
|
|
230
|
+
const refItem = getRef(context, refSchema);
|
|
231
|
+
return refItem ? refItemToShapeName(refItem) : undefined;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Sugar, for when you really just need a path...
|
|
235
|
+
*/
|
|
236
|
+
|
|
237
|
+
export function anyRefToShapeSchemaPath(context, refSchema) {
|
|
238
|
+
const refItem = getRef(context, refSchema);
|
|
239
|
+
return refItem ? [...refItemToShapePath(refItem), 'schema'] : undefined;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Helper fn to omit `ref` props from the target schema, and then extend it with the source schema.
|
|
243
|
+
*/
|
|
244
|
+
|
|
245
|
+
export const omitRefAndExtend = (targetSchema, sourceSchema) => assign(omit(['@ref', '$ref'], targetSchema), sourceSchema);
|
|
246
|
+
/**
|
|
247
|
+
* If there is a $ref, this will insert a content schema from the top level
|
|
248
|
+
* in place of the reference.
|
|
249
|
+
*/
|
|
250
|
+
|
|
251
|
+
export function followRef(context, contentSchema) {
|
|
252
|
+
const refItem = getRef(context, contentSchema);
|
|
253
|
+
|
|
254
|
+
if (refItem) {
|
|
255
|
+
const referencedSchema = refItemToShapeSchema(context, refItem);
|
|
256
|
+
|
|
257
|
+
if (referencedSchema) {
|
|
258
|
+
return omitRefAndExtend(contentSchema, referencedSchema);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
return contentSchema;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Returns whether a schema has refs.
|
|
266
|
+
*/
|
|
267
|
+
|
|
268
|
+
export function hasRef(contentSchema) {
|
|
269
|
+
if (isRefSchema(contentSchema) || isRefSchemaLegacy(contentSchema)) {
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (isAllOfSchema(contentSchema)) {
|
|
274
|
+
return Boolean(contentSchema.allOf.find(hasRef));
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (isOneOfSchema(contentSchema)) {
|
|
278
|
+
return Boolean(contentSchema.oneOf.find(hasRef));
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Returns whether a schema has refs which can be followed.
|
|
285
|
+
*/
|
|
286
|
+
|
|
287
|
+
export function hasResolvableRef(context, contentSchema) {
|
|
288
|
+
if (isRefSchema(contentSchema) || isRefSchemaLegacy(contentSchema)) {
|
|
289
|
+
return Boolean(refItemToShapeSchema(context, getRef(context, contentSchema)));
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (isAllOfSchema(contentSchema)) {
|
|
293
|
+
return Boolean(contentSchema.allOf.find(s => hasResolvableRef(context, s)));
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
if (isOneOfSchema(contentSchema)) {
|
|
297
|
+
return Boolean(contentSchema.oneOf.find(s => hasResolvableRef(context, s)));
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return false;
|
|
301
|
+
}
|
package/es/resolvers.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export const modelResolvers = ['takeshape:get', 'takeshape:list', 'takeshape:create', 'takeshape:update', 'takeshape:delete', 'takeshape:duplicate', 'takeshape:find'];
|
|
2
|
+
export const resolverList = [...modelResolvers, 'graphql:query', 'graphql:mutation', 'rest:get', 'rest:head', 'rest:post', 'rest:put', 'rest:patch', 'rest:delete', 'debug:noop', 'util:wrap', 'awsLambda:invoke'];
|
package/es/scalars.js
ADDED