@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,71 @@
|
|
|
1
|
+
import type { ServiceMap, ServiceKey, ProjectSchemaV3X } from './types';
|
|
2
|
+
import type { ProjectSchema, StoredServiceMap, StoredServiceConfig, ServiceConfig, EncryptedGenericServiceConfigV3_0_0, ServiceAuthentication, StoredServiceConfigV3_1_0, ServiceConfigV3_1_0 } from './project-schema';
|
|
3
|
+
import type { Maybe } from '@takeshape/util';
|
|
4
|
+
import { Overwrite } from '@takeshape/util';
|
|
5
|
+
import { ServiceInfo, PatternGenerator } from './types';
|
|
6
|
+
import { SERVICE_OBJECT_PATTERN_NAME } from './schema-util';
|
|
7
|
+
import { Shape } from './project-schema';
|
|
8
|
+
/**
|
|
9
|
+
* Decrypt an encrypted authentication JSON string
|
|
10
|
+
* Throws an error if decryption fails
|
|
11
|
+
*/
|
|
12
|
+
export declare type DecryptFn = (authentication: string) => ServiceAuthentication;
|
|
13
|
+
/**
|
|
14
|
+
* Decrypt an encrypted authentication JSON string
|
|
15
|
+
* Returns undefined if decryption fails
|
|
16
|
+
*/
|
|
17
|
+
export declare type SafeDecryptFn = (authentication: string) => ServiceAuthentication | undefined;
|
|
18
|
+
export declare type EncryptFn = (authentication: ServiceAuthentication) => string;
|
|
19
|
+
/**
|
|
20
|
+
* `graphql:my-key` `my-key`
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseV3ServiceStr(service: string): {
|
|
23
|
+
provider?: string;
|
|
24
|
+
id: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Given a `StoredServiceConfig` returns a usable `ServiceConfig` with the
|
|
28
|
+
* authentication object decrypted.
|
|
29
|
+
*/
|
|
30
|
+
export declare function decryptServiceConfig(decryptFn: DecryptFn, storedServiceConfig: StoredServiceConfig): ServiceConfig;
|
|
31
|
+
/**
|
|
32
|
+
* Given a `StoredServiceMap` returns a usable `ServiceMap` with all the
|
|
33
|
+
* authentication objects decrypted.
|
|
34
|
+
*/
|
|
35
|
+
export declare function decryptServiceMap(decryptFn: DecryptFn, storedServiceMap: StoredServiceMap): Promise<ServiceMap>;
|
|
36
|
+
/**
|
|
37
|
+
* Prepare a `ServiceConfig` object update, validating the overall structure
|
|
38
|
+
* and encrypting the `ServiceAuthentication` object.
|
|
39
|
+
*/
|
|
40
|
+
export declare function prepareServiceUpdate(encryptFn: EncryptFn, decryptFn: DecryptFn, projectSchema: ProjectSchema, partialServiceConfig: Partial<ServiceConfig>, serviceKey: string): StoredServiceConfig;
|
|
41
|
+
/**
|
|
42
|
+
* Get a service config from a project schema.
|
|
43
|
+
*/
|
|
44
|
+
export declare function getStoredServiceConfig(projectSchema: ProjectSchema, serviceKey: ServiceKey): Maybe<StoredServiceConfig>;
|
|
45
|
+
/**
|
|
46
|
+
* Migration-related Functions
|
|
47
|
+
*
|
|
48
|
+
* All the following code is used in the migration process. At some point
|
|
49
|
+
* migraton code should live outside the standard runtime code.
|
|
50
|
+
*/
|
|
51
|
+
/**
|
|
52
|
+
* Ensures a consistent service config, inluding updating the service
|
|
53
|
+
* authentication object.
|
|
54
|
+
*/
|
|
55
|
+
export declare function updateServiceConfigV3ToV3_1(serviceConfig: Record<string, unknown>, serviceKey: ServiceKey): StoredServiceConfigV3_1_0 | ServiceConfigV3_1_0;
|
|
56
|
+
export declare function getServiceNamespace(serviceConfig: StoredServiceConfig | EncryptedGenericServiceConfigV3_0_0): string | undefined;
|
|
57
|
+
/**
|
|
58
|
+
* Get a `Map` keyed with all the service namespaces.
|
|
59
|
+
*
|
|
60
|
+
* @param context A partial project schema
|
|
61
|
+
*
|
|
62
|
+
* @returns A `Map` with namespaces as keys, and service keys as values.
|
|
63
|
+
*/
|
|
64
|
+
export declare function getServiceNamespaces(context: Pick<ProjectSchemaV3X, 'services'>): Map<string, string>;
|
|
65
|
+
export declare type ServiceInfoWithServiceObject = Overwrite<ServiceInfo, {
|
|
66
|
+
generators: {
|
|
67
|
+
[SERVICE_OBJECT_PATTERN_NAME]: PatternGenerator;
|
|
68
|
+
};
|
|
69
|
+
}>;
|
|
70
|
+
export declare function getServiceObjectFields(projectSchema: ProjectSchema, shape: Shape, provider: string): ServiceInfoWithServiceObject[];
|
|
71
|
+
//# sourceMappingURL=services.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../../src/services.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,UAAU,EAAE,UAAU,EAA4B,gBAAgB,EAAC,MAAM,SAAS,CAAC;AAEhG,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,EACb,mCAAmC,EACnC,qBAAqB,EACrB,yBAAyB,EACzB,mBAAmB,EAEpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAC,KAAK,EAAC,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAwB,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAEjE,OAAO,EAA+C,WAAW,EAAE,gBAAgB,EAAC,MAAM,SAAS,CAAC;AAOpG,OAAO,EAAiB,2BAA2B,EAAC,MAAM,eAAe,CAAC;AAC1E,OAAO,EAAC,KAAK,EAAC,MAAM,kBAAkB,CAAC;AAEvC;;;GAGG;AACH,oBAAY,SAAS,GAAG,CAAC,cAAc,EAAE,MAAM,KAAK,qBAAqB,CAAC;AAC1E;;;GAGG;AACH,oBAAY,aAAa,GAAG,CAAC,cAAc,EAAE,MAAM,KAAK,qBAAqB,GAAG,SAAS,CAAC;AAC1F,oBAAY,SAAS,GAAG,CAAC,cAAc,EAAE,qBAAqB,KAAK,MAAM,CAAC;AAE1E;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAC,CAGlF;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,SAAS,EAAE,mBAAmB,EAAE,mBAAmB,GAAG,aAAa,CAWlH;AAED;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,SAAS,EAAE,SAAS,EAAE,gBAAgB,EAAE,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,CAIrH;AAsCD;;;GAGG;AAEH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,aAAa,EAC5B,oBAAoB,EAAE,OAAO,CAAC,aAAa,CAAC,EAC5C,UAAU,EAAE,MAAM,GACjB,mBAAmB,CA6CrB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,aAAa,EAAE,aAAa,EAC5B,UAAU,EAAE,UAAU,GACrB,KAAK,CAAC,mBAAmB,CAAC,CAE5B;AAED;;;;;GAKG;AAEH;;;GAGG;AAEH,wBAAgB,2BAA2B,CACzC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACtC,UAAU,EAAE,UAAU,GACrB,yBAAyB,GAAG,mBAAmB,CAiGjD;AAuED,wBAAgB,mBAAmB,CACjC,aAAa,EAAE,mBAAmB,GAAG,mCAAmC,GACvE,MAAM,GAAG,SAAS,CAOpB;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,IAAI,CAAC,gBAAgB,EAAE,UAAU,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAcrG;AAED,oBAAY,4BAA4B,GAAG,SAAS,CAClD,WAAW,EACX;IAAC,UAAU,EAAE;QAAC,CAAC,2BAA2B,CAAC,EAAE,gBAAgB,CAAA;KAAC,CAAA;CAAC,CAChE,CAAC;AAEF,wBAAgB,sBAAsB,CACpC,aAAa,EAAE,aAAa,EAC5B,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,MAAM,GACf,4BAA4B,EAAE,CAIhC"}
|
package/lib/services.js
ADDED
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.parseV3ServiceStr = parseV3ServiceStr;
|
|
7
|
+
exports.decryptServiceConfig = decryptServiceConfig;
|
|
8
|
+
exports.decryptServiceMap = decryptServiceMap;
|
|
9
|
+
exports.prepareServiceUpdate = prepareServiceUpdate;
|
|
10
|
+
exports.getStoredServiceConfig = getStoredServiceConfig;
|
|
11
|
+
exports.updateServiceConfigV3ToV3_1 = updateServiceConfigV3ToV3_1;
|
|
12
|
+
exports.getServiceNamespace = getServiceNamespace;
|
|
13
|
+
exports.getServiceNamespaces = getServiceNamespaces;
|
|
14
|
+
exports.getServiceObjectFields = getServiceObjectFields;
|
|
15
|
+
|
|
16
|
+
var _util = require("@takeshape/util");
|
|
17
|
+
|
|
18
|
+
var _merge = require("@takeshape/util/lib/merge");
|
|
19
|
+
|
|
20
|
+
var _types = require("./types");
|
|
21
|
+
|
|
22
|
+
var _v = _interopRequireDefault(require("./schemas/project-schema/v3.1.0.json"));
|
|
23
|
+
|
|
24
|
+
var _jsonSchema = require("@takeshape/json-schema");
|
|
25
|
+
|
|
26
|
+
var _isObject = _interopRequireDefault(require("lodash/isObject"));
|
|
27
|
+
|
|
28
|
+
var _isNull = _interopRequireDefault(require("lodash/isNull"));
|
|
29
|
+
|
|
30
|
+
var _isString = _interopRequireDefault(require("lodash/isString"));
|
|
31
|
+
|
|
32
|
+
var _isUndefined = _interopRequireDefault(require("lodash/isUndefined"));
|
|
33
|
+
|
|
34
|
+
var _schemaUtil = require("./schema-util");
|
|
35
|
+
|
|
36
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* `graphql:my-key` `my-key`
|
|
40
|
+
*/
|
|
41
|
+
function parseV3ServiceStr(service) {
|
|
42
|
+
const parts = service.split(':');
|
|
43
|
+
return {
|
|
44
|
+
provider: parts.length > 1 ? parts[0] : undefined,
|
|
45
|
+
id: parts.length > 1 ? parts[1] : parts[0]
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Given a `StoredServiceConfig` returns a usable `ServiceConfig` with the
|
|
50
|
+
* authentication object decrypted.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
function decryptServiceConfig(decryptFn, storedServiceConfig) {
|
|
55
|
+
let authentication;
|
|
56
|
+
|
|
57
|
+
if ((0, _types.isEncryptedServiceConfig)(storedServiceConfig)) {
|
|
58
|
+
authentication = decryptFn(storedServiceConfig.authentication);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return { ...storedServiceConfig,
|
|
62
|
+
authentication
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Given a `StoredServiceMap` returns a usable `ServiceMap` with all the
|
|
67
|
+
* authentication objects decrypted.
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
async function decryptServiceMap(decryptFn, storedServiceMap) {
|
|
72
|
+
return Object.entries(storedServiceMap).reduce((result, [serviceKey, serviceConfig]) => {
|
|
73
|
+
return result.set(serviceKey, decryptServiceConfig(decryptFn, serviceConfig));
|
|
74
|
+
}, new Map());
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Provides a `ServiceConfig` validator based on the JSON-schema.
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
function createServiceConfigValidator() {
|
|
82
|
+
const {
|
|
83
|
+
serviceConfig: schema,
|
|
84
|
+
...definitions
|
|
85
|
+
} = _v.default.definitions;
|
|
86
|
+
const validationSchema = {
|
|
87
|
+
$id: '#serviceConfig',
|
|
88
|
+
definitions,
|
|
89
|
+
...schema
|
|
90
|
+
};
|
|
91
|
+
return (0, _jsonSchema.createSchemaValidator)(validationSchema);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Provides a `ServiceAuthentication` validator. Due to a behavior of `oneOf` and
|
|
95
|
+
* the `removeAdditional` setting, where valid properties are being stripped,
|
|
96
|
+
* this is validated separate from the overall config. May have something to do with
|
|
97
|
+
* JSON Schema's lack of handling for discriminated unions?
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
function createServiceAuthenticationValidator() {
|
|
102
|
+
const {
|
|
103
|
+
serviceAuthentication: schema,
|
|
104
|
+
...definitions
|
|
105
|
+
} = _v.default.definitions;
|
|
106
|
+
const validationSchema = {
|
|
107
|
+
$id: '#serviceAuthentication',
|
|
108
|
+
definitions,
|
|
109
|
+
...schema
|
|
110
|
+
};
|
|
111
|
+
return (0, _jsonSchema.createSchemaValidator)(validationSchema, [], {
|
|
112
|
+
removeAdditional: false
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const serviceConfigValidator = createServiceConfigValidator();
|
|
117
|
+
const serviceAuthenticationValidator = createServiceAuthenticationValidator();
|
|
118
|
+
/**
|
|
119
|
+
* Prepare a `ServiceConfig` object update, validating the overall structure
|
|
120
|
+
* and encrypting the `ServiceAuthentication` object.
|
|
121
|
+
*/
|
|
122
|
+
// eslint-disable-next-line max-params
|
|
123
|
+
|
|
124
|
+
function prepareServiceUpdate(encryptFn, decryptFn, projectSchema, partialServiceConfig, serviceKey) {
|
|
125
|
+
var _projectSchema$servic;
|
|
126
|
+
|
|
127
|
+
const storedServiceConfig = (_projectSchema$servic = projectSchema.services) === null || _projectSchema$servic === void 0 ? void 0 : _projectSchema$servic[serviceKey];
|
|
128
|
+
let newServiceConfig = partialServiceConfig;
|
|
129
|
+
|
|
130
|
+
if (storedServiceConfig) {
|
|
131
|
+
const existingServiceConfig = decryptServiceConfig(decryptFn, storedServiceConfig);
|
|
132
|
+
newServiceConfig = (0, _merge.mergeWithArrayMerge)(existingServiceConfig, partialServiceConfig);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if ((0, _isNull.default)(newServiceConfig.authentication)) {
|
|
136
|
+
delete newServiceConfig.authentication;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
let authentication;
|
|
140
|
+
|
|
141
|
+
if (newServiceConfig.authentication) {
|
|
142
|
+
// Copy authentication, to ensure validation doesn't remove any properties
|
|
143
|
+
authentication = (0, _util.deepClone)(newServiceConfig.authentication);
|
|
144
|
+
const {
|
|
145
|
+
errorsText: authenticationErrors
|
|
146
|
+
} = serviceAuthenticationValidator(authentication);
|
|
147
|
+
|
|
148
|
+
if (authenticationErrors) {
|
|
149
|
+
throw new Error(authenticationErrors);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const {
|
|
154
|
+
errorsText: configErrors
|
|
155
|
+
} = serviceConfigValidator(newServiceConfig);
|
|
156
|
+
|
|
157
|
+
if (configErrors) {
|
|
158
|
+
throw new Error(configErrors);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
let serviceConfig;
|
|
162
|
+
|
|
163
|
+
if (authentication) {
|
|
164
|
+
serviceConfig = { ...newServiceConfig,
|
|
165
|
+
authentication: encryptFn(authentication)
|
|
166
|
+
};
|
|
167
|
+
} else {
|
|
168
|
+
serviceConfig = newServiceConfig;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return serviceConfig;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Get a service config from a project schema.
|
|
175
|
+
*/
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
function getStoredServiceConfig(projectSchema, serviceKey) {
|
|
179
|
+
var _projectSchema$servic2;
|
|
180
|
+
|
|
181
|
+
return (_projectSchema$servic2 = projectSchema.services) === null || _projectSchema$servic2 === void 0 ? void 0 : _projectSchema$servic2[serviceKey];
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Migration-related Functions
|
|
185
|
+
*
|
|
186
|
+
* All the following code is used in the migration process. At some point
|
|
187
|
+
* migraton code should live outside the standard runtime code.
|
|
188
|
+
*/
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Ensures a consistent service config, inluding updating the service
|
|
192
|
+
* authentication object.
|
|
193
|
+
*/
|
|
194
|
+
// eslint-disable-next-line complexity
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
function updateServiceConfigV3ToV3_1(serviceConfig, serviceKey) {
|
|
198
|
+
if ((0, _types.isAnyServiceConfig)(serviceConfig)) {
|
|
199
|
+
if ((0, _isString.default)(serviceConfig.authentication) || (0, _isUndefined.default)(serviceConfig.authentication)) {
|
|
200
|
+
return serviceConfig;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return serviceConfig;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const auth = serviceConfig.auth;
|
|
207
|
+
const serviceParams = serviceConfig.params || {};
|
|
208
|
+
let {
|
|
209
|
+
provider: serviceKeyProvider,
|
|
210
|
+
id: serviceKeyId
|
|
211
|
+
} = parseV3ServiceStr(serviceKey);
|
|
212
|
+
const authType = serviceParams.authType || undefined;
|
|
213
|
+
const title = serviceParams.name || serviceKeyId;
|
|
214
|
+
|
|
215
|
+
if (serviceKeyId === 'vercel') {
|
|
216
|
+
serviceKeyProvider = 'vercel';
|
|
217
|
+
} else if (serviceKeyId === 'netlify') {
|
|
218
|
+
serviceKeyProvider = 'netlify';
|
|
219
|
+
} // Example schemas had this in params, which are untyped, so adding here just in case
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
if (serviceParams.type === 'rest') {
|
|
223
|
+
serviceKeyProvider = 'rest';
|
|
224
|
+
} else if (serviceParams.type === 'graphql' && serviceKeyProvider !== 'shopify') {
|
|
225
|
+
serviceKeyProvider = 'graphql';
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
let provider;
|
|
229
|
+
let authenticationType;
|
|
230
|
+
let serviceType;
|
|
231
|
+
let namespace;
|
|
232
|
+
|
|
233
|
+
if (serviceKeyProvider === 'shopify') {
|
|
234
|
+
var _serviceParams$namesp;
|
|
235
|
+
|
|
236
|
+
provider = 'shopify';
|
|
237
|
+
authenticationType = 'oauth2Bearer';
|
|
238
|
+
serviceType = 'graphql';
|
|
239
|
+
namespace = (_serviceParams$namesp = serviceParams.namespace) !== null && _serviceParams$namesp !== void 0 ? _serviceParams$namesp : 'Shopify';
|
|
240
|
+
} else if (serviceKeyProvider === 'takeshape') {
|
|
241
|
+
var _serviceParams$namesp2;
|
|
242
|
+
|
|
243
|
+
provider = 'takeshape';
|
|
244
|
+
authenticationType = 'none';
|
|
245
|
+
serviceType = 'takeshape';
|
|
246
|
+
namespace = (_serviceParams$namesp2 = serviceParams.namespace) !== null && _serviceParams$namesp2 !== void 0 ? _serviceParams$namesp2 : 'TakeShape';
|
|
247
|
+
} else if (serviceKeyProvider === 'bigcommerce') {
|
|
248
|
+
var _serviceParams$namesp3;
|
|
249
|
+
|
|
250
|
+
provider = 'bigcommerce';
|
|
251
|
+
authenticationType = 'bearer';
|
|
252
|
+
serviceType = 'graphql';
|
|
253
|
+
namespace = (_serviceParams$namesp3 = serviceParams.namespace) !== null && _serviceParams$namesp3 !== void 0 ? _serviceParams$namesp3 : 'BigCommerce';
|
|
254
|
+
} else if (serviceKeyProvider === 'rest') {
|
|
255
|
+
var _serviceParams$namesp4;
|
|
256
|
+
|
|
257
|
+
provider = 'generic';
|
|
258
|
+
authenticationType = mapAuthType(authType, auth);
|
|
259
|
+
serviceType = 'rest';
|
|
260
|
+
namespace = (_serviceParams$namesp4 = serviceParams.namespace) !== null && _serviceParams$namesp4 !== void 0 ? _serviceParams$namesp4 : (0, _util.upperCamel)(title);
|
|
261
|
+
} else if (serviceKeyProvider === 'graphql') {
|
|
262
|
+
var _serviceParams$namesp5;
|
|
263
|
+
|
|
264
|
+
provider = 'generic';
|
|
265
|
+
authenticationType = mapAuthType(authType, auth);
|
|
266
|
+
serviceType = 'graphql';
|
|
267
|
+
namespace = (_serviceParams$namesp5 = serviceParams.namespace) !== null && _serviceParams$namesp5 !== void 0 ? _serviceParams$namesp5 : (0, _util.upperCamel)(title);
|
|
268
|
+
} else if (serviceKeyProvider === 'vercel') {
|
|
269
|
+
provider = 'vercel';
|
|
270
|
+
authenticationType = 'oauth2Bearer';
|
|
271
|
+
serviceType = 'deployment';
|
|
272
|
+
} else if (serviceKeyProvider === 'netlify') {
|
|
273
|
+
provider = 'netlify';
|
|
274
|
+
authenticationType = 'oauth2Bearer';
|
|
275
|
+
serviceType = 'deployment';
|
|
276
|
+
} else {
|
|
277
|
+
var _serviceParams$namesp6;
|
|
278
|
+
|
|
279
|
+
provider = 'generic';
|
|
280
|
+
authenticationType = mapAuthType(authType, auth);
|
|
281
|
+
serviceType = 'unknown';
|
|
282
|
+
namespace = (_serviceParams$namesp6 = serviceParams.namespace) !== null && _serviceParams$namesp6 !== void 0 ? _serviceParams$namesp6 : (0, _util.upperCamel)(title);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const updatedServiceConfig = {
|
|
286
|
+
title,
|
|
287
|
+
id: serviceKey,
|
|
288
|
+
provider,
|
|
289
|
+
namespace,
|
|
290
|
+
serviceType,
|
|
291
|
+
authenticationType,
|
|
292
|
+
options: { ...serviceParams
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
if (serviceConfig.auth && (0, _isObject.default)(serviceConfig.auth)) {
|
|
297
|
+
const authentication = updateServiceAuthentication(updatedServiceConfig.authenticationType, serviceConfig.auth, serviceParams);
|
|
298
|
+
return { ...updatedServiceConfig,
|
|
299
|
+
authentication
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return updatedServiceConfig;
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* V1/V3 unencrypted `auth` -> V3.1 `authentication
|
|
307
|
+
*/
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
function updateServiceAuthentication(authenticationType, legacyAuth, legacyParams) {
|
|
311
|
+
if (authenticationType === 'oauth2Bearer') {
|
|
312
|
+
return {
|
|
313
|
+
token: legacyAuth.accessToken,
|
|
314
|
+
scope: legacyAuth.scope,
|
|
315
|
+
header: legacyParams.authHeader
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (authenticationType === 'searchParams' && legacyParams.authProp) {
|
|
320
|
+
return [{
|
|
321
|
+
name: legacyParams.authProp,
|
|
322
|
+
value: legacyAuth.accessToken
|
|
323
|
+
}];
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if (authenticationType === 'basic') {
|
|
327
|
+
const [username, password] = Buffer.from(legacyAuth.accessToken, 'base64').toString('utf-8').split(':');
|
|
328
|
+
return {
|
|
329
|
+
username,
|
|
330
|
+
password
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (authenticationType === 'bearer') {
|
|
335
|
+
return {
|
|
336
|
+
token: legacyAuth.accessToken,
|
|
337
|
+
header: legacyParams.authHeader
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function mapAuthType(authType, auth) {
|
|
343
|
+
if (authType === 'none') {
|
|
344
|
+
return 'none';
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
if (authType === 'searchParams') {
|
|
348
|
+
return 'searchParams';
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (authType === 'bearer') {
|
|
352
|
+
return 'bearer';
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (authType === 'bearer') {
|
|
356
|
+
return 'basic';
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
if (!auth) {
|
|
360
|
+
return 'none';
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (auth) {
|
|
364
|
+
return 'bearer';
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
return 'unknown';
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
function getServiceNamespace(serviceConfig) {
|
|
371
|
+
var _serviceConfig$params;
|
|
372
|
+
|
|
373
|
+
if ('namespace' in serviceConfig && serviceConfig.namespace) {
|
|
374
|
+
return serviceConfig.namespace;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if ('params' in serviceConfig && (_serviceConfig$params = serviceConfig.params) !== null && _serviceConfig$params !== void 0 && _serviceConfig$params.namespace) {
|
|
378
|
+
return serviceConfig.params.namespace;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Get a `Map` keyed with all the service namespaces.
|
|
383
|
+
*
|
|
384
|
+
* @param context A partial project schema
|
|
385
|
+
*
|
|
386
|
+
* @returns A `Map` with namespaces as keys, and service keys as values.
|
|
387
|
+
*/
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
function getServiceNamespaces(context) {
|
|
391
|
+
let namespaces = new Map();
|
|
392
|
+
const {
|
|
393
|
+
services
|
|
394
|
+
} = context;
|
|
395
|
+
|
|
396
|
+
if (services) {
|
|
397
|
+
Object.keys(services).forEach(serviceKey => {
|
|
398
|
+
const namespace = getServiceNamespace(services[serviceKey]);
|
|
399
|
+
|
|
400
|
+
if (namespace) {
|
|
401
|
+
namespaces.set(namespace, serviceKey);
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
return namespaces;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
function getServiceObjectFields(projectSchema, shape, provider) {
|
|
410
|
+
var _getServiceInfo$provi;
|
|
411
|
+
|
|
412
|
+
return ((_getServiceInfo$provi = (0, _schemaUtil.getServiceInfo)(projectSchema, shape)[provider]) !== null && _getServiceInfo$provi !== void 0 ? _getServiceInfo$provi : []).filter(serviceInfo => serviceInfo.generators[_schemaUtil.SERVICE_OBJECT_PATTERN_NAME]);
|
|
413
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ProjectSchema, Shape } from './project-schema';
|
|
2
|
+
export interface TaxonomyField {
|
|
3
|
+
name: string;
|
|
4
|
+
key?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface Taxonomy {
|
|
7
|
+
shapeId: string;
|
|
8
|
+
field: TaxonomyField;
|
|
9
|
+
}
|
|
10
|
+
export declare function getFirstStringFieldV3(shape: Shape, projectSchema: ProjectSchema): {
|
|
11
|
+
name: string;
|
|
12
|
+
key?: string;
|
|
13
|
+
} | null;
|
|
14
|
+
export declare const getTaxonomyField: (shape: Shape, projectSchema: ProjectSchema) => TaxonomyField | null;
|
|
15
|
+
export declare const getTaxonomies: (projectSchema: ProjectSchema) => Taxonomy[];
|
|
16
|
+
//# sourceMappingURL=taxonomies.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"taxonomies.d.ts","sourceRoot":"","sources":["../../src/taxonomies.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,aAAa,EAAE,KAAK,EAAC,MAAM,kBAAkB,CAAC;AAI3D,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,aAAa,CAAC;CACtB;AAQD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,KAAK,EAAE,aAAa,EAAE,aAAa,GAAG;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAC,GAAG,IAAI,CAUrH;AAED,eAAO,MAAM,gBAAgB,UAAuB,KAAK,iBAAiB,aAAa,KAAG,aAAa,GAAG,IAEzG,CAAC;AAEF,eAAO,MAAM,aAAa,kBAA+B,aAAa,KAAG,QAAQ,EAU/E,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getFirstStringFieldV3 = getFirstStringFieldV3;
|
|
7
|
+
exports.getTaxonomies = exports.getTaxonomyField = void 0;
|
|
8
|
+
|
|
9
|
+
var _memoize = _interopRequireDefault(require("lodash/memoize"));
|
|
10
|
+
|
|
11
|
+
var _schemaUtil = require("./schema-util");
|
|
12
|
+
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
|
|
15
|
+
function weakMemoize(fn) {
|
|
16
|
+
const memoized = (0, _memoize.default)(fn);
|
|
17
|
+
memoized.cache = new WeakMap();
|
|
18
|
+
return memoized;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getFirstStringFieldV3(shape, projectSchema) {
|
|
22
|
+
var _projectSchema$forms;
|
|
23
|
+
|
|
24
|
+
const forms = (_projectSchema$forms = projectSchema.forms) === null || _projectSchema$forms === void 0 ? void 0 : _projectSchema$forms[shape.name];
|
|
25
|
+
|
|
26
|
+
if (!forms || !forms.default) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const schemaProperties = (0, _schemaUtil.createSchemaPropertyAccessor)(projectSchema, shape.schema);
|
|
31
|
+
const {
|
|
32
|
+
order
|
|
33
|
+
} = forms.default;
|
|
34
|
+
const name = order.find(name => {
|
|
35
|
+
var _schemaProperties$get;
|
|
36
|
+
|
|
37
|
+
return ((_schemaProperties$get = schemaProperties.getValue(name)) === null || _schemaProperties$get === void 0 ? void 0 : _schemaProperties$get.type) === 'string';
|
|
38
|
+
});
|
|
39
|
+
return name ? {
|
|
40
|
+
name,
|
|
41
|
+
key: schemaProperties.getKey(name)
|
|
42
|
+
} : null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const getTaxonomyField = weakMemoize((shape, projectSchema) => {
|
|
46
|
+
var _shape$model;
|
|
47
|
+
|
|
48
|
+
return ((_shape$model = shape.model) === null || _shape$model === void 0 ? void 0 : _shape$model.type) === 'taxonomy' ? getFirstStringFieldV3(shape, projectSchema) : null;
|
|
49
|
+
});
|
|
50
|
+
exports.getTaxonomyField = getTaxonomyField;
|
|
51
|
+
const getTaxonomies = weakMemoize(projectSchema => {
|
|
52
|
+
const {
|
|
53
|
+
shapes
|
|
54
|
+
} = projectSchema;
|
|
55
|
+
return Object.keys(shapes).reduce((result, shapeName) => {
|
|
56
|
+
const shape = shapes[shapeName];
|
|
57
|
+
const field = getTaxonomyField(shape, projectSchema);
|
|
58
|
+
|
|
59
|
+
if (field) {
|
|
60
|
+
result.push({
|
|
61
|
+
shapeId: shape.id,
|
|
62
|
+
field
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return result;
|
|
67
|
+
}, []);
|
|
68
|
+
});
|
|
69
|
+
exports.getTaxonomies = getTaxonomies;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ReturnShape } from './project-schema';
|
|
2
|
+
import { ProjectSchemaV3X } from './types';
|
|
3
|
+
import { RefItem } from './refs';
|
|
4
|
+
export declare const knownTemplateShapes: Set<string>;
|
|
5
|
+
/**
|
|
6
|
+
* Check if a string is a known template such as `PaginatedList`
|
|
7
|
+
*/
|
|
8
|
+
export declare function isValidTemplate(template: string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Parse a template like `PaginatedList<Post>` and return both the template and the shape name.
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseTemplateShape(shape: string): {
|
|
13
|
+
template: string | undefined;
|
|
14
|
+
shapeName: string;
|
|
15
|
+
};
|
|
16
|
+
export interface ParsedReturnShape {
|
|
17
|
+
isArray: boolean;
|
|
18
|
+
template?: string;
|
|
19
|
+
shapeName: string;
|
|
20
|
+
ref?: RefItem;
|
|
21
|
+
}
|
|
22
|
+
export declare function parseReturnShape(projectSchema: ProjectSchemaV3X, shape: ReturnShape): ParsedReturnShape;
|
|
23
|
+
/**
|
|
24
|
+
* Create a template string like `PaginatedList<Post>` from a template and shape name.
|
|
25
|
+
*/
|
|
26
|
+
export declare function createTemplateShapeName(template: string, shapeName: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* If the string is a template like `PaginatedList<Post>`, return the shape name,
|
|
29
|
+
* in this case `Post`. Otherwise return the input.
|
|
30
|
+
*/
|
|
31
|
+
export declare const untemplate: (input: string) => string;
|
|
32
|
+
//# sourceMappingURL=template-shapes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-shapes.d.ts","sourceRoot":"","sources":["../../src/template-shapes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAc,gBAAgB,EAAC,MAAM,SAAS,CAAC;AACtD,OAAO,EAAiC,OAAO,EAAqB,MAAM,QAAQ,CAAC;AAEnF,eAAO,MAAM,mBAAmB,aAa9B,CAAC;AAEH;;GAEG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG;IAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAC,CAMnG;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,gBAAgB,EAAE,KAAK,EAAE,WAAW,GAAG,iBAAiB,CAmBvG;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAEnF;AAED;;;GAGG;AACH,eAAO,MAAM,UAAU,UAAW,MAAM,WAEvC,CAAC"}
|