@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/types.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import eq from 'semver/functions/eq';
|
|
2
|
+
import coerce from 'semver/functions/coerce';
|
|
3
|
+
import has from 'lodash/has';
|
|
4
|
+
import isString from 'lodash/isString';
|
|
5
|
+
import isObject from 'lodash/isObject';
|
|
6
|
+
import isArray from 'lodash/isArray';
|
|
7
|
+
import isPlainObject from 'lodash/isPlainObject';
|
|
8
|
+
import { CURRENT_SCHEMA_VERSION } from './versions';
|
|
9
|
+
export function isBasicResolver(resolver) {
|
|
10
|
+
return resolver ? isString(resolver.name) && isString(resolver.service) : false;
|
|
11
|
+
}
|
|
12
|
+
export function isComposeResolver(resolver) {
|
|
13
|
+
return resolver ? resolver.compose !== undefined : false;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Remote service configuration types
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Old service authentication
|
|
21
|
+
* @deprecated
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Test all required props, currently:
|
|
26
|
+
* "name", "slug", "provider", "serviceType", "authenticationType"
|
|
27
|
+
*/
|
|
28
|
+
export function isAnyServiceConfig(maybeConfig) {
|
|
29
|
+
return maybeConfig && isString(maybeConfig.title) && isString(maybeConfig.id) && isString(maybeConfig.provider) && isString(maybeConfig.serviceType) && isString(maybeConfig.authenticationType);
|
|
30
|
+
}
|
|
31
|
+
export function isRESTServiceConfig(maybeConfig) {
|
|
32
|
+
return isAnyServiceConfig(maybeConfig) && maybeConfig.serviceType === 'rest';
|
|
33
|
+
}
|
|
34
|
+
export function isGraphQLServiceConfig(maybeConfig) {
|
|
35
|
+
var _maybeConfig$options;
|
|
36
|
+
|
|
37
|
+
return isAnyServiceConfig(maybeConfig) && maybeConfig.serviceType === 'graphql' && isString((_maybeConfig$options = maybeConfig.options) === null || _maybeConfig$options === void 0 ? void 0 : _maybeConfig$options.endpoint);
|
|
38
|
+
}
|
|
39
|
+
export function isOpenAPIServiceConfig(maybeConfig) {
|
|
40
|
+
return isAnyServiceConfig(maybeConfig) && maybeConfig.serviceType === 'openapi';
|
|
41
|
+
}
|
|
42
|
+
export function isEncryptedServiceConfig(maybeConfig) {
|
|
43
|
+
return isAnyServiceConfig(maybeConfig) && isString(maybeConfig.authentication);
|
|
44
|
+
}
|
|
45
|
+
export function isServiceAuthentication(maybeAuthentication) {
|
|
46
|
+
return maybeAuthentication && isObject(maybeAuthentication);
|
|
47
|
+
}
|
|
48
|
+
export function isBearerAuthentication(maybeAuthentication) {
|
|
49
|
+
return isServiceAuthentication(maybeAuthentication) && isString(maybeAuthentication.token);
|
|
50
|
+
}
|
|
51
|
+
export function isBasicAuthentication(maybeAuthentication) {
|
|
52
|
+
return isServiceAuthentication(maybeAuthentication) && (isString(maybeAuthentication.username) || isString(maybeAuthentication.password));
|
|
53
|
+
}
|
|
54
|
+
export function isSearchParamsAuthentication(maybeAuthentication) {
|
|
55
|
+
return isArray(maybeAuthentication) && maybeAuthentication.every(value => isObject(value) && Object.entries(value).every(([k, v]) => (k === 'name' || k === 'value') && isString(v)));
|
|
56
|
+
}
|
|
57
|
+
export function isOAuth2Authentication(maybeAuthentication) {
|
|
58
|
+
return isServiceAuthentication(maybeAuthentication) && isString(maybeAuthentication.clientId);
|
|
59
|
+
}
|
|
60
|
+
export function isServiceConfigWithOAuth2Authentication(maybeServiceConfig) {
|
|
61
|
+
return isAnyServiceConfig(maybeServiceConfig) && maybeServiceConfig.authenticationType === 'oauth2' && isOAuth2Authentication(maybeServiceConfig.authentication);
|
|
62
|
+
}
|
|
63
|
+
export function isServiceConfigWithCustomAuthentication(maybeServiceConfig) {
|
|
64
|
+
return isAnyServiceConfig(maybeServiceConfig) && maybeServiceConfig.authenticationType === 'custom' && isServiceAuthentication(maybeServiceConfig.authentication);
|
|
65
|
+
}
|
|
66
|
+
export function isProjectSchemaWithServices(schema) {
|
|
67
|
+
return typeof schema.dataKey !== 'undefined' && typeof schema.services !== 'undefined';
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Types of refs
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
export let RefType;
|
|
74
|
+
/**
|
|
75
|
+
* Stub of a ContentSchema that may contain a `$ref` or `@ref`.
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
(function (RefType) {
|
|
79
|
+
RefType["@ref"] = "@ref";
|
|
80
|
+
RefType["$ref"] = "$ref";
|
|
81
|
+
})(RefType || (RefType = {}));
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* A utility to return the type of ref present on a schema.
|
|
85
|
+
*
|
|
86
|
+
* @param refSchema Any schema that may have a `ref` property.
|
|
87
|
+
*/
|
|
88
|
+
export const getRefType = refSchema => {
|
|
89
|
+
if (has(refSchema, '@ref')) {
|
|
90
|
+
return RefType['@ref'];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (has(refSchema, '$ref')) {
|
|
94
|
+
return RefType.$ref;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Types of args
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
export let ArgsType;
|
|
102
|
+
|
|
103
|
+
(function (ArgsType) {
|
|
104
|
+
ArgsType["@args"] = "@args";
|
|
105
|
+
ArgsType["args"] = "args";
|
|
106
|
+
})(ArgsType || (ArgsType = {}));
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* A utility to return the type of args present on a schema.
|
|
110
|
+
*
|
|
111
|
+
* @param argsSchema Any schema that may have an `args` property.
|
|
112
|
+
*/
|
|
113
|
+
export const getArgsType = argsSchema => {
|
|
114
|
+
if (has(argsSchema, '@args')) {
|
|
115
|
+
return ArgsType['@args'];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (has(argsSchema, 'args')) {
|
|
119
|
+
return ArgsType.args;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Typeguards for different types of shape schemas
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
export function isRefSchema(maybeRefSchema) {
|
|
127
|
+
return isString(maybeRefSchema['@ref']) || isString(maybeRefSchema.$ref);
|
|
128
|
+
}
|
|
129
|
+
export function isRefSchemaLegacy(maybeRefSchema) {
|
|
130
|
+
return isString(maybeRefSchema.$ref);
|
|
131
|
+
}
|
|
132
|
+
export function isAllOfSchema(maybeExtendableSchema) {
|
|
133
|
+
return isArray(maybeExtendableSchema.allOf);
|
|
134
|
+
}
|
|
135
|
+
export function isOneOfSchema(maybeExclusiveOrSchema) {
|
|
136
|
+
return isArray(maybeExclusiveOrSchema.oneOf);
|
|
137
|
+
}
|
|
138
|
+
export function isArraySchema(maybeArraySchema) {
|
|
139
|
+
return maybeArraySchema.type === 'array' && isObject(maybeArraySchema.items);
|
|
140
|
+
}
|
|
141
|
+
export function isObjectSchema(maybeObjectSchema) {
|
|
142
|
+
return maybeObjectSchema.type === 'object' && isObject(maybeObjectSchema.properties);
|
|
143
|
+
}
|
|
144
|
+
export function isContentObjectSchema(maybeSchema) {
|
|
145
|
+
return isRefSchema(maybeSchema) || isAllOfSchema(maybeSchema) || isObjectSchema(maybeSchema);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function createVersionPredicate(schemaVersion) {
|
|
149
|
+
const expectedSemver = coerce(schemaVersion);
|
|
150
|
+
return projectSchema => {
|
|
151
|
+
var _projectSchema$schema;
|
|
152
|
+
|
|
153
|
+
const schemaSemver = coerce((_projectSchema$schema = projectSchema.schemaVersion) !== null && _projectSchema$schema !== void 0 ? _projectSchema$schema : '1');
|
|
154
|
+
return Boolean(expectedSemver && schemaSemver && eq(schemaSemver, expectedSemver));
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export const isProjectSchemaV1 = createVersionPredicate('1');
|
|
159
|
+
export const isProjectSchemaV3 = createVersionPredicate('3');
|
|
160
|
+
export const isProjectSchemaV3_1 = createVersionPredicate('3.1.0');
|
|
161
|
+
export const isProjectSchemaV3_2 = createVersionPredicate('3.2.0');
|
|
162
|
+
export const isProjectSchemaV3_3 = createVersionPredicate('3.3.0');
|
|
163
|
+
export const isProjectSchemaV3_4 = createVersionPredicate('3.4.0');
|
|
164
|
+
export const isProjectSchemaV3_5 = createVersionPredicate('3.5.0');
|
|
165
|
+
export const isProjectSchemaV3_5_1 = createVersionPredicate('3.5.1');
|
|
166
|
+
export const isProjectSchemaV3_6 = createVersionPredicate('3.6.0');
|
|
167
|
+
export const isLatestProjectSchema = createVersionPredicate(CURRENT_SCHEMA_VERSION);
|
|
168
|
+
/**
|
|
169
|
+
* Determine whether a given project schema is any project schema.
|
|
170
|
+
*/
|
|
171
|
+
|
|
172
|
+
export function isAnyProjectSchema(maybeSchema) {
|
|
173
|
+
return isObject(maybeSchema) && isString(maybeSchema.projectId) && (isProjectSchemaV1(maybeSchema) || isProjectSchemaV3(maybeSchema) || isProjectSchemaV3_1(maybeSchema) || isProjectSchemaV3_2(maybeSchema) || isProjectSchemaV3_3(maybeSchema) || isProjectSchemaV3_4(maybeSchema) || isProjectSchemaV3_5(maybeSchema) || isProjectSchemaV3_5_1(maybeSchema) || isProjectSchemaV3_6(maybeSchema));
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Types supporting schema iterators
|
|
177
|
+
*/
|
|
178
|
+
|
|
179
|
+
export function isShopifyServiceConfig(maybeShopify) {
|
|
180
|
+
return maybeShopify.provider === 'shopify';
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Determine whether the ambiguous Directive structure is a DirectiveMappingMap
|
|
185
|
+
*/
|
|
186
|
+
export function isDirectiveMappingMap(maybeMap) {
|
|
187
|
+
return isPlainObject(maybeMap) && Object.keys(maybeMap).length > 0;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Determine whether the ambiguous Directive structure is a DirectiveMappingArray
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
export function isDirectiveMappingArray(maybeArray) {
|
|
194
|
+
return isArray(maybeArray) && isArray(maybeArray[0]) && isString(maybeArray[0][0]) && isArray(maybeArray[0][1]);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Determine whether the ambiguous Directive structure is a DirectiveConfig array
|
|
198
|
+
*/
|
|
199
|
+
|
|
200
|
+
export function isDirectiveConfig(maybeConfig) {
|
|
201
|
+
return isArray(maybeConfig) && isArray(maybeConfig[0]) && isString(maybeConfig[0][0]) && isObject(maybeConfig[0][1]);
|
|
202
|
+
}
|
package/es/unions.js
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { getRef, refItemToShapeName } from './refs';
|
|
2
|
+
import { camelCase, isObject } from '@takeshape/util';
|
|
3
|
+
import omit from 'lodash/omit';
|
|
4
|
+
import { getContentTransform, toName } from './content-schema-transform';
|
|
5
|
+
import { isRefSchema } from './types';
|
|
6
|
+
import { BadDataError } from '@takeshape/errors';
|
|
7
|
+
import { getShapeById } from './schema-util';
|
|
8
|
+
export function enumerateOneOfKeys(projectSchema, oneOf) {
|
|
9
|
+
const result = [];
|
|
10
|
+
|
|
11
|
+
for (const child of oneOf) {
|
|
12
|
+
const refItem = getRef(projectSchema, child);
|
|
13
|
+
|
|
14
|
+
if (refItem) {
|
|
15
|
+
const shapeName = refItemToShapeName(refItem);
|
|
16
|
+
|
|
17
|
+
if (projectSchema.shapes[shapeName]) {
|
|
18
|
+
const shapeId = projectSchema.shapes[shapeName].id;
|
|
19
|
+
result.push({
|
|
20
|
+
propName: camelCase(refItem.typeName),
|
|
21
|
+
propSchema: child,
|
|
22
|
+
shapeName,
|
|
23
|
+
shapeId
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function getOneOf(schema) {
|
|
33
|
+
if (!schema.oneOf) {
|
|
34
|
+
throw new Error(`Expected ${JSON.stringify(schema)} to be a oneOf schema`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return schema.oneOf;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function isUnionSchema(schema) {
|
|
41
|
+
var _schema$oneOf;
|
|
42
|
+
|
|
43
|
+
return Boolean((_schema$oneOf = schema.oneOf) === null || _schema$oneOf === void 0 ? void 0 : _schema$oneOf.every(isRefSchema));
|
|
44
|
+
}
|
|
45
|
+
export function oneOfToObject(projectSchema, schema) {
|
|
46
|
+
const properties = {};
|
|
47
|
+
|
|
48
|
+
for (const {
|
|
49
|
+
propName,
|
|
50
|
+
propSchema: child
|
|
51
|
+
} of enumerateOneOfKeys(projectSchema, getOneOf(schema))) {
|
|
52
|
+
properties[propName] = child;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return { ...omit(schema, 'oneOf'),
|
|
56
|
+
type: 'object',
|
|
57
|
+
properties
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function formatKeys(keys) {
|
|
62
|
+
return keys.map(k => `"${k}"`).join(', ');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// eslint-disable-next-line max-params
|
|
66
|
+
export const createUnwrapTransform = projectSchema => (obj, schema, name, shape, next) => {
|
|
67
|
+
if (isObject(obj)) {
|
|
68
|
+
const oneOfKeys = enumerateOneOfKeys(projectSchema, getOneOf(schema));
|
|
69
|
+
const objectKeys = Object.keys(obj);
|
|
70
|
+
|
|
71
|
+
if (objectKeys.length !== 1) {
|
|
72
|
+
const propNames = oneOfKeys.map(k => k.propName);
|
|
73
|
+
throw new BadDataError(`Object should only specify one of the following keys: ${formatKeys(propNames)}, but found keys: ${formatKeys(objectKeys)}`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
for (const {
|
|
77
|
+
propName,
|
|
78
|
+
shapeId,
|
|
79
|
+
propSchema
|
|
80
|
+
} of oneOfKeys) {
|
|
81
|
+
const propValue = obj[propName];
|
|
82
|
+
|
|
83
|
+
if (isObject(propValue)) {
|
|
84
|
+
const transformedPropValue = next(propValue, propSchema, name);
|
|
85
|
+
|
|
86
|
+
if (isObject(transformedPropValue)) {
|
|
87
|
+
return { ...transformedPropValue,
|
|
88
|
+
_shapeId: shapeId
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}; // eslint-disable-next-line max-params
|
|
95
|
+
|
|
96
|
+
export const createWrapTransform = projectSchema => (obj, schema, name, shape, next) => {
|
|
97
|
+
if (isObject(obj) && typeof obj._shapeId === 'string') {
|
|
98
|
+
const shape = getShapeById(projectSchema, obj._shapeId);
|
|
99
|
+
|
|
100
|
+
if (shape) {
|
|
101
|
+
return {
|
|
102
|
+
[camelCase(shape.name)]: next(omit(obj, '_shapeId'), shape.schema, name)
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
export function transformOneOf(process) {
|
|
108
|
+
return (projectSchema, schema, obj) => {
|
|
109
|
+
const transform = getContentTransform({
|
|
110
|
+
sourceKeyTransform: toName,
|
|
111
|
+
keyTransform: toName,
|
|
112
|
+
passThrough: true,
|
|
113
|
+
projectSchema,
|
|
114
|
+
transforms: {
|
|
115
|
+
'*': [{
|
|
116
|
+
filter: isUnionSchema,
|
|
117
|
+
process: process(projectSchema)
|
|
118
|
+
}]
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
return transform(schema, obj);
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Unwrap oneOf objects in "GraphQL oneOf" style wrapper objects
|
|
126
|
+
* See https://github.com/graphql/graphql-spec/pull/825 for more on "GraphQL oneOf"
|
|
127
|
+
* Opposite of `wrapOneOfObjects`
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
export const unwrapOneOfObjects = transformOneOf(createUnwrapTransform);
|
|
131
|
+
/**
|
|
132
|
+
* Wrap oneOf objects in "GraphQL oneOf" style wrapper objects
|
|
133
|
+
* See https://github.com/graphql/graphql-spec/pull/825 for more on "GraphQL oneOf"
|
|
134
|
+
* Opposite of `unwrapOneOfObjects`
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
export const wrapOneOfObjects = transformOneOf(createWrapTransform);
|
|
File without changes
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { getRef, refItemToShape } from '../refs';
|
|
2
|
+
|
|
3
|
+
function immutableSetAdd(set, str) {
|
|
4
|
+
const result = new Set(set);
|
|
5
|
+
result.add(str);
|
|
6
|
+
return result;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Use a basic depth-first search to dertermine whether a schema contains a cycle
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
export function hasCycle(projectSchema, schema, shapesSeen = new Set()) {
|
|
14
|
+
var _ref, _schema$oneOf;
|
|
15
|
+
|
|
16
|
+
const refItem = getRef(projectSchema, schema);
|
|
17
|
+
|
|
18
|
+
if (refItem) {
|
|
19
|
+
const refShape = refItemToShape(projectSchema, refItem); // If we have a refItem, but no shape, this is a dangling ref and has no cycles
|
|
20
|
+
|
|
21
|
+
if (!refShape) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (shapesSeen.has(refShape.name)) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return hasCycle(projectSchema, refShape.schema, immutableSetAdd(shapesSeen, refShape.name));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const combo = (_ref = (_schema$oneOf = schema.oneOf) !== null && _schema$oneOf !== void 0 ? _schema$oneOf : schema.allOf) !== null && _ref !== void 0 ? _ref : schema.anyOf;
|
|
33
|
+
|
|
34
|
+
if (combo) {
|
|
35
|
+
return combo.some(childSchema => hasCycle(projectSchema, childSchema, shapesSeen));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (schema.items) {
|
|
39
|
+
return hasCycle(projectSchema, schema.items, shapesSeen);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const {
|
|
43
|
+
properties
|
|
44
|
+
} = schema;
|
|
45
|
+
|
|
46
|
+
if (properties) {
|
|
47
|
+
return Object.keys(properties).some(name => {
|
|
48
|
+
const propSchema = properties[name];
|
|
49
|
+
return hasCycle(projectSchema, propSchema, shapesSeen);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return false;
|
|
54
|
+
}
|
package/es/util/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './detect-cycles';
|