@eide/uniformgen 0.1.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 +356 -0
- package/dist/auth/credentials.d.ts +58 -0
- package/dist/auth/credentials.d.ts.map +1 -0
- package/dist/auth/credentials.js +107 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +563 -0
- package/dist/commands/init.d.ts +11 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +113 -0
- package/dist/commands/login.d.ts +9 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/login.js +158 -0
- package/dist/commands/logout.d.ts +5 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/logout.js +13 -0
- package/dist/commands/push.d.ts +13 -0
- package/dist/commands/push.d.ts.map +1 -0
- package/dist/commands/push.js +328 -0
- package/dist/commands/scaffold.d.ts +19 -0
- package/dist/commands/scaffold.d.ts.map +1 -0
- package/dist/commands/scaffold.js +366 -0
- package/dist/commands/seed.d.ts +20 -0
- package/dist/commands/seed.d.ts.map +1 -0
- package/dist/commands/seed.js +380 -0
- package/dist/commands/select-project.d.ts +10 -0
- package/dist/commands/select-project.d.ts.map +1 -0
- package/dist/commands/select-project.js +277 -0
- package/dist/commands/setup.d.ts +5 -0
- package/dist/commands/setup.d.ts.map +1 -0
- package/dist/commands/setup.js +51 -0
- package/dist/commands/sync.d.ts +13 -0
- package/dist/commands/sync.d.ts.map +1 -0
- package/dist/commands/sync.js +318 -0
- package/dist/commands/whoami.d.ts +5 -0
- package/dist/commands/whoami.d.ts.map +1 -0
- package/dist/commands/whoami.js +31 -0
- package/dist/config/load-config.d.ts +6 -0
- package/dist/config/load-config.d.ts.map +1 -0
- package/dist/config/load-config.js +103 -0
- package/dist/config/settings.d.ts +20 -0
- package/dist/config/settings.d.ts.map +1 -0
- package/dist/config/settings.js +64 -0
- package/dist/config/types.d.ts +152 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +94 -0
- package/dist/fetcher/fetch-schemas.d.ts +140 -0
- package/dist/fetcher/fetch-schemas.d.ts.map +1 -0
- package/dist/fetcher/fetch-schemas.js +223 -0
- package/dist/fetcher/fetch-workflows.d.ts +53 -0
- package/dist/fetcher/fetch-workflows.d.ts.map +1 -0
- package/dist/fetcher/fetch-workflows.js +164 -0
- package/dist/generated/hooks/customer-detail.d.ts +74 -0
- package/dist/generated/hooks/customer-detail.d.ts.map +1 -0
- package/dist/generated/hooks/customer-detail.js +113 -0
- package/dist/generated/hooks/design-system.d.ts +74 -0
- package/dist/generated/hooks/design-system.d.ts.map +1 -0
- package/dist/generated/hooks/design-system.js +109 -0
- package/dist/generated/hooks/index.d.ts +16 -0
- package/dist/generated/hooks/index.d.ts.map +1 -0
- package/dist/generated/hooks/index.js +14 -0
- package/dist/generated/hooks/shopify-collection.d.ts +74 -0
- package/dist/generated/hooks/shopify-collection.d.ts.map +1 -0
- package/dist/generated/hooks/shopify-collection.js +113 -0
- package/dist/generated/hooks/shopify-market.d.ts +74 -0
- package/dist/generated/hooks/shopify-market.d.ts.map +1 -0
- package/dist/generated/hooks/shopify-market.js +109 -0
- package/dist/generated/hooks/shopify-product.d.ts +74 -0
- package/dist/generated/hooks/shopify-product.d.ts.map +1 -0
- package/dist/generated/hooks/shopify-product.js +113 -0
- package/dist/generated/hooks/shopify-variant.d.ts +74 -0
- package/dist/generated/hooks/shopify-variant.d.ts.map +1 -0
- package/dist/generated/hooks/shopify-variant.js +113 -0
- package/dist/generated/hooks/template.d.ts +74 -0
- package/dist/generated/hooks/template.d.ts.map +1 -0
- package/dist/generated/hooks/template.js +107 -0
- package/dist/generated/types/config.d.ts +88 -0
- package/dist/generated/types/config.d.ts.map +1 -0
- package/dist/generated/types/config.js +14 -0
- package/dist/generated/types/data-models/index.d.ts +7 -0
- package/dist/generated/types/data-models/index.d.ts.map +1 -0
- package/dist/generated/types/data-models/index.js +6 -0
- package/dist/generated/types/data-models/test.d.ts +29 -0
- package/dist/generated/types/data-models/test.d.ts.map +1 -0
- package/dist/generated/types/data-models/test.js +1 -0
- package/dist/generated/types/data-models/watch.d.ts +26 -0
- package/dist/generated/types/data-models/watch.d.ts.map +1 -0
- package/dist/generated/types/data-models/watch.js +1 -0
- package/dist/generated/types/field-types.d.ts +255 -0
- package/dist/generated/types/field-types.d.ts.map +1 -0
- package/dist/generated/types/field-types.js +35 -0
- package/dist/generated/types/hooks.d.ts +106 -0
- package/dist/generated/types/hooks.d.ts.map +1 -0
- package/dist/generated/types/hooks.js +9 -0
- package/dist/generated/types/index.d.ts +10 -0
- package/dist/generated/types/index.d.ts.map +1 -0
- package/dist/generated/types/index.js +9 -0
- package/dist/generated/types/models/button-variant.d.ts +16 -0
- package/dist/generated/types/models/button-variant.d.ts.map +1 -0
- package/dist/generated/types/models/button-variant.js +1 -0
- package/dist/generated/types/models/color-palette.d.ts +27 -0
- package/dist/generated/types/models/color-palette.d.ts.map +1 -0
- package/dist/generated/types/models/color-palette.js +1 -0
- package/dist/generated/types/models/color-with-scale.d.ts +15 -0
- package/dist/generated/types/models/color-with-scale.d.ts.map +1 -0
- package/dist/generated/types/models/color-with-scale.js +1 -0
- package/dist/generated/types/models/context.d.ts +53 -0
- package/dist/generated/types/models/context.d.ts.map +1 -0
- package/dist/generated/types/models/context.js +51 -0
- package/dist/generated/types/models/customer-detail.d.ts +32 -0
- package/dist/generated/types/models/customer-detail.d.ts.map +1 -0
- package/dist/generated/types/models/customer-detail.js +26 -0
- package/dist/generated/types/models/design-system-badges.d.ts +16 -0
- package/dist/generated/types/models/design-system-badges.d.ts.map +1 -0
- package/dist/generated/types/models/design-system-badges.js +1 -0
- package/dist/generated/types/models/design-system-buttons.d.ts +17 -0
- package/dist/generated/types/models/design-system-buttons.d.ts.map +1 -0
- package/dist/generated/types/models/design-system-buttons.js +1 -0
- package/dist/generated/types/models/design-system-cards.d.ts +16 -0
- package/dist/generated/types/models/design-system-cards.d.ts.map +1 -0
- package/dist/generated/types/models/design-system-cards.js +1 -0
- package/dist/generated/types/models/design-system-colors.d.ts +12 -0
- package/dist/generated/types/models/design-system-colors.d.ts.map +1 -0
- package/dist/generated/types/models/design-system-colors.js +1 -0
- package/dist/generated/types/models/design-system-dark-mode.d.ts +13 -0
- package/dist/generated/types/models/design-system-dark-mode.d.ts.map +1 -0
- package/dist/generated/types/models/design-system-dark-mode.js +1 -0
- package/dist/generated/types/models/design-system-focus-ring.d.ts +14 -0
- package/dist/generated/types/models/design-system-focus-ring.d.ts.map +1 -0
- package/dist/generated/types/models/design-system-focus-ring.js +1 -0
- package/dist/generated/types/models/design-system-grid.d.ts +18 -0
- package/dist/generated/types/models/design-system-grid.d.ts.map +1 -0
- package/dist/generated/types/models/design-system-grid.js +1 -0
- package/dist/generated/types/models/design-system-inputs.d.ts +26 -0
- package/dist/generated/types/models/design-system-inputs.d.ts.map +1 -0
- package/dist/generated/types/models/design-system-inputs.js +1 -0
- package/dist/generated/types/models/design-system-links.d.ts +16 -0
- package/dist/generated/types/models/design-system-links.d.ts.map +1 -0
- package/dist/generated/types/models/design-system-links.js +1 -0
- package/dist/generated/types/models/design-system-shadows.d.ts +20 -0
- package/dist/generated/types/models/design-system-shadows.d.ts.map +1 -0
- package/dist/generated/types/models/design-system-shadows.js +1 -0
- package/dist/generated/types/models/design-system-spacing.d.ts +13 -0
- package/dist/generated/types/models/design-system-spacing.d.ts.map +1 -0
- package/dist/generated/types/models/design-system-spacing.js +1 -0
- package/dist/generated/types/models/design-system-transitions.d.ts +15 -0
- package/dist/generated/types/models/design-system-transitions.d.ts.map +1 -0
- package/dist/generated/types/models/design-system-transitions.js +1 -0
- package/dist/generated/types/models/design-system-typography.d.ts +21 -0
- package/dist/generated/types/models/design-system-typography.d.ts.map +1 -0
- package/dist/generated/types/models/design-system-typography.js +1 -0
- package/dist/generated/types/models/design-system.d.ts +138 -0
- package/dist/generated/types/models/design-system.d.ts.map +1 -0
- package/dist/generated/types/models/design-system.js +64 -0
- package/dist/generated/types/models/experiment.d.ts +57 -0
- package/dist/generated/types/models/experiment.d.ts.map +1 -0
- package/dist/generated/types/models/experiment.js +55 -0
- package/dist/generated/types/models/font-file.d.ts +16 -0
- package/dist/generated/types/models/font-file.d.ts.map +1 -0
- package/dist/generated/types/models/font-file.js +1 -0
- package/dist/generated/types/models/index.d.ts +38 -0
- package/dist/generated/types/models/index.d.ts.map +1 -0
- package/dist/generated/types/models/index.js +12 -0
- package/dist/generated/types/models/integration.d.ts +32 -0
- package/dist/generated/types/models/integration.d.ts.map +1 -0
- package/dist/generated/types/models/integration.js +26 -0
- package/dist/generated/types/models/route-tree.d.ts +43 -0
- package/dist/generated/types/models/route-tree.d.ts.map +1 -0
- package/dist/generated/types/models/route-tree.js +39 -0
- package/dist/generated/types/models/segment.d.ts +57 -0
- package/dist/generated/types/models/segment.d.ts.map +1 -0
- package/dist/generated/types/models/segment.js +55 -0
- package/dist/generated/types/models/shopify-collection.d.ts +32 -0
- package/dist/generated/types/models/shopify-collection.d.ts.map +1 -0
- package/dist/generated/types/models/shopify-collection.js +26 -0
- package/dist/generated/types/models/shopify-market.d.ts +32 -0
- package/dist/generated/types/models/shopify-market.d.ts.map +1 -0
- package/dist/generated/types/models/shopify-market.js +26 -0
- package/dist/generated/types/models/shopify-product.d.ts +32 -0
- package/dist/generated/types/models/shopify-product.d.ts.map +1 -0
- package/dist/generated/types/models/shopify-product.js +26 -0
- package/dist/generated/types/models/shopify-variant.d.ts +32 -0
- package/dist/generated/types/models/shopify-variant.d.ts.map +1 -0
- package/dist/generated/types/models/shopify-variant.js +26 -0
- package/dist/generated/types/models/template.d.ts +53 -0
- package/dist/generated/types/models/template.d.ts.map +1 -0
- package/dist/generated/types/models/template.js +40 -0
- package/dist/generated/types/models/typography-variant.d.ts +15 -0
- package/dist/generated/types/models/typography-variant.d.ts.map +1 -0
- package/dist/generated/types/models/typography-variant.js +1 -0
- package/dist/generated/types/scalars.d.ts +56 -0
- package/dist/generated/types/scalars.d.ts.map +1 -0
- package/dist/generated/types/scalars.js +6 -0
- package/dist/generators/admin/index.d.ts +32 -0
- package/dist/generators/admin/index.d.ts.map +1 -0
- package/dist/generators/admin/index.js +219 -0
- package/dist/generators/admin/mutations.d.ts +23 -0
- package/dist/generators/admin/mutations.d.ts.map +1 -0
- package/dist/generators/admin/mutations.js +424 -0
- package/dist/generators/admin/queries.d.ts +20 -0
- package/dist/generators/admin/queries.d.ts.map +1 -0
- package/dist/generators/admin/queries.js +476 -0
- package/dist/generators/admin/types.d.ts +28 -0
- package/dist/generators/admin/types.d.ts.map +1 -0
- package/dist/generators/admin/types.js +254 -0
- package/dist/generators/cms/index.d.ts +29 -0
- package/dist/generators/cms/index.d.ts.map +1 -0
- package/dist/generators/cms/index.js +126 -0
- package/dist/generators/cms/route.d.ts +27 -0
- package/dist/generators/cms/route.d.ts.map +1 -0
- package/dist/generators/cms/route.js +409 -0
- package/dist/generators/cms/types.d.ts +15 -0
- package/dist/generators/cms/types.d.ts.map +1 -0
- package/dist/generators/cms/types.js +137 -0
- package/dist/generators/contexts/index.d.ts +25 -0
- package/dist/generators/contexts/index.d.ts.map +1 -0
- package/dist/generators/contexts/index.js +591 -0
- package/dist/generators/documents/data-models.d.ts +6 -0
- package/dist/generators/documents/data-models.d.ts.map +1 -0
- package/dist/generators/documents/data-models.js +61 -0
- package/dist/generators/documents/entity-models.d.ts +7 -0
- package/dist/generators/documents/entity-models.d.ts.map +1 -0
- package/dist/generators/documents/entity-models.js +87 -0
- package/dist/generators/documents/workflows.d.ts +11 -0
- package/dist/generators/documents/workflows.d.ts.map +1 -0
- package/dist/generators/documents/workflows.js +101 -0
- package/dist/generators/filters/index.d.ts +16 -0
- package/dist/generators/filters/index.d.ts.map +1 -0
- package/dist/generators/filters/index.js +384 -0
- package/dist/generators/hooks/agnostic.d.ts +16 -0
- package/dist/generators/hooks/agnostic.d.ts.map +1 -0
- package/dist/generators/hooks/agnostic.js +248 -0
- package/dist/generators/hooks/index.d.ts +9 -0
- package/dist/generators/hooks/index.d.ts.map +1 -0
- package/dist/generators/hooks/index.js +8 -0
- package/dist/generators/hooks/react.d.ts +16 -0
- package/dist/generators/hooks/react.d.ts.map +1 -0
- package/dist/generators/hooks/react.js +394 -0
- package/dist/generators/hooks/remix.d.ts +16 -0
- package/dist/generators/hooks/remix.d.ts.map +1 -0
- package/dist/generators/hooks/remix.js +349 -0
- package/dist/generators/hooks/workflows.d.ts +23 -0
- package/dist/generators/hooks/workflows.d.ts.map +1 -0
- package/dist/generators/hooks/workflows.js +312 -0
- package/dist/generators/resolve/index.d.ts +13 -0
- package/dist/generators/resolve/index.d.ts.map +1 -0
- package/dist/generators/resolve/index.js +13 -0
- package/dist/generators/resolve/platform.d.ts +29 -0
- package/dist/generators/resolve/platform.d.ts.map +1 -0
- package/dist/generators/resolve/platform.js +479 -0
- package/dist/generators/types/config.d.ts +7 -0
- package/dist/generators/types/config.d.ts.map +1 -0
- package/dist/generators/types/config.js +113 -0
- package/dist/generators/types/data-models.d.ts +10 -0
- package/dist/generators/types/data-models.d.ts.map +1 -0
- package/dist/generators/types/data-models.js +100 -0
- package/dist/generators/types/entity-models.d.ts +13 -0
- package/dist/generators/types/entity-models.d.ts.map +1 -0
- package/dist/generators/types/entity-models.js +241 -0
- package/dist/generators/types/field-types.d.ts +9 -0
- package/dist/generators/types/field-types.d.ts.map +1 -0
- package/dist/generators/types/field-types.js +651 -0
- package/dist/generators/types/hooks.d.ts +7 -0
- package/dist/generators/types/hooks.d.ts.map +1 -0
- package/dist/generators/types/hooks.js +132 -0
- package/dist/generators/types/scalars.d.ts +6 -0
- package/dist/generators/types/scalars.d.ts.map +1 -0
- package/dist/generators/types/scalars.js +68 -0
- package/dist/generators/types/user-details.d.ts +6 -0
- package/dist/generators/types/user-details.d.ts.map +1 -0
- package/dist/generators/types/user-details.js +60 -0
- package/dist/generators/types/workflows.d.ts +15 -0
- package/dist/generators/types/workflows.d.ts.map +1 -0
- package/dist/generators/types/workflows.js +163 -0
- package/dist/graphql/generated/gql.d.ts +47 -0
- package/dist/graphql/generated/gql.d.ts.map +1 -0
- package/dist/graphql/generated/gql.js +10 -0
- package/dist/graphql/generated/graphql.d.ts +8455 -0
- package/dist/graphql/generated/graphql.d.ts.map +1 -0
- package/dist/graphql/generated/graphql.js +573 -0
- package/dist/graphql/generated/index.d.ts +2 -0
- package/dist/graphql/generated/index.d.ts.map +1 -0
- package/dist/graphql/generated/index.js +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/schema/define-entity-model.d.ts +122 -0
- package/dist/schema/define-entity-model.d.ts.map +1 -0
- package/dist/schema/define-entity-model.js +59 -0
- package/dist/schema/schema-loader.d.ts +10 -0
- package/dist/schema/schema-loader.d.ts.map +1 -0
- package/dist/schema/schema-loader.js +91 -0
- package/dist/utils/field-mapping.d.ts +83 -0
- package/dist/utils/field-mapping.d.ts.map +1 -0
- package/dist/utils/field-mapping.js +334 -0
- package/dist/writer/write-files.d.ts +12 -0
- package/dist/writer/write-files.d.ts.map +1 -0
- package/dist/writer/write-files.js +35 -0
- package/package.json +70 -0
|
@@ -0,0 +1,591 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context Types Generator
|
|
3
|
+
*
|
|
4
|
+
* Generates typed context helpers for variant resolution.
|
|
5
|
+
* Contexts define the available dimensions for personalizing content.
|
|
6
|
+
*
|
|
7
|
+
* Unlike other generators, contexts are queried at RUNTIME since their
|
|
8
|
+
* values can change dynamically in the database.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Generate the typed contexts file with runtime query support
|
|
12
|
+
*/
|
|
13
|
+
export function generateContextsFile(contexts) {
|
|
14
|
+
const lines = [];
|
|
15
|
+
// File header
|
|
16
|
+
lines.push(`/**`);
|
|
17
|
+
lines.push(` * Available Contexts for Variant Resolution`);
|
|
18
|
+
lines.push(` *`);
|
|
19
|
+
lines.push(` * This file provides runtime context fetching and type definitions.`);
|
|
20
|
+
lines.push(` * Context values are queried from the API since they can change dynamically.`);
|
|
21
|
+
lines.push(` *`);
|
|
22
|
+
lines.push(` * @generated by UniformGen - DO NOT EDIT MANUALLY`);
|
|
23
|
+
lines.push(` */`);
|
|
24
|
+
lines.push('');
|
|
25
|
+
lines.push(`import { gql } from 'graphql-request';`);
|
|
26
|
+
lines.push(`import { useState, useEffect, useCallback } from 'react';`);
|
|
27
|
+
lines.push('');
|
|
28
|
+
// Generate type definitions
|
|
29
|
+
lines.push(`// =============================================================================`);
|
|
30
|
+
lines.push(`// TYPE DEFINITIONS`);
|
|
31
|
+
lines.push(`// =============================================================================`);
|
|
32
|
+
lines.push('');
|
|
33
|
+
lines.push(`/**`);
|
|
34
|
+
lines.push(` * Context definition from the API`);
|
|
35
|
+
lines.push(` */`);
|
|
36
|
+
lines.push(`export interface ContextDefinition {`);
|
|
37
|
+
lines.push(` key: string;`);
|
|
38
|
+
lines.push(` name: string;`);
|
|
39
|
+
lines.push(` entityModelKey: string;`);
|
|
40
|
+
lines.push(` outputKeys: {`);
|
|
41
|
+
lines.push(` valueKey: string;`);
|
|
42
|
+
lines.push(` idKey: string;`);
|
|
43
|
+
lines.push(` };`);
|
|
44
|
+
lines.push(`}`);
|
|
45
|
+
lines.push('');
|
|
46
|
+
lines.push(`/**`);
|
|
47
|
+
lines.push(` * Context value (an instance of a context, e.g., a specific market)`);
|
|
48
|
+
lines.push(` */`);
|
|
49
|
+
lines.push(`export interface ContextValue {`);
|
|
50
|
+
lines.push(` key: string;`);
|
|
51
|
+
lines.push(` name: string;`);
|
|
52
|
+
lines.push(` isPrimary: boolean;`);
|
|
53
|
+
lines.push(`}`);
|
|
54
|
+
lines.push('');
|
|
55
|
+
lines.push(`/**`);
|
|
56
|
+
lines.push(` * Full context with its available values`);
|
|
57
|
+
lines.push(` */`);
|
|
58
|
+
lines.push(`export interface ContextWithValues extends ContextDefinition {`);
|
|
59
|
+
lines.push(` values: ContextValue[];`);
|
|
60
|
+
lines.push(`}`);
|
|
61
|
+
lines.push('');
|
|
62
|
+
// Generate the typed contexts interface based on known context keys
|
|
63
|
+
lines.push(`/**`);
|
|
64
|
+
lines.push(` * Typed contexts object for variant resolution`);
|
|
65
|
+
lines.push(` *`);
|
|
66
|
+
lines.push(` * Pass this to resolve functions to select the appropriate variant.`);
|
|
67
|
+
lines.push(` * Values are strings validated at runtime via useAvailableContexts.`);
|
|
68
|
+
lines.push(` */`);
|
|
69
|
+
lines.push(`export interface TypedContexts {`);
|
|
70
|
+
for (const context of contexts) {
|
|
71
|
+
const valueKey = context.definition.outputKeys.valueKey;
|
|
72
|
+
const idKey = context.definition.outputKeys.idKey;
|
|
73
|
+
lines.push(` /** ${context.definition.name || context.definition.key} context value */`);
|
|
74
|
+
lines.push(` ${valueKey}?: string;`);
|
|
75
|
+
lines.push(` /** ${context.definition.name || context.definition.key} context ID */`);
|
|
76
|
+
lines.push(` ${idKey}?: string;`);
|
|
77
|
+
}
|
|
78
|
+
// Add common context fields
|
|
79
|
+
lines.push(` /** Device type (e.g., 'mobile', 'desktop') */`);
|
|
80
|
+
lines.push(` device?: 'mobile' | 'tablet' | 'desktop' | string;`);
|
|
81
|
+
lines.push(` /** Whether user is authenticated */`);
|
|
82
|
+
lines.push(` authenticated?: boolean;`);
|
|
83
|
+
lines.push(` /** Customer ID for segment/experiment resolution */`);
|
|
84
|
+
lines.push(` customerId?: string;`);
|
|
85
|
+
lines.push(` /** Additional custom context values */`);
|
|
86
|
+
lines.push(` [key: string]: unknown;`);
|
|
87
|
+
lines.push(`}`);
|
|
88
|
+
lines.push('');
|
|
89
|
+
// Generate context keys
|
|
90
|
+
lines.push(`/**`);
|
|
91
|
+
lines.push(` * Known context keys (from generation time)`);
|
|
92
|
+
lines.push(` */`);
|
|
93
|
+
lines.push(`export const CONTEXT_KEYS = [`);
|
|
94
|
+
for (const context of contexts) {
|
|
95
|
+
lines.push(` '${context.definition.outputKeys.valueKey}',`);
|
|
96
|
+
}
|
|
97
|
+
lines.push(`] as const;`);
|
|
98
|
+
lines.push('');
|
|
99
|
+
lines.push(`export type ContextKey = (typeof CONTEXT_KEYS)[number];`);
|
|
100
|
+
lines.push('');
|
|
101
|
+
// Generate GraphQL query
|
|
102
|
+
lines.push(`// =============================================================================`);
|
|
103
|
+
lines.push(`// GRAPHQL QUERY`);
|
|
104
|
+
lines.push(`// =============================================================================`);
|
|
105
|
+
lines.push('');
|
|
106
|
+
lines.push(`/**`);
|
|
107
|
+
lines.push(` * GraphQL query to fetch available contexts and their values`);
|
|
108
|
+
lines.push(` */`);
|
|
109
|
+
lines.push(`export const GET_AVAILABLE_CONTEXTS = gql\``);
|
|
110
|
+
lines.push(` query GetAvailableContexts {`);
|
|
111
|
+
lines.push(` entityRecords(modelKey: "context", limit: 100) {`);
|
|
112
|
+
lines.push(` items {`);
|
|
113
|
+
lines.push(` naturalKey`);
|
|
114
|
+
lines.push(` variants(limit: 1) {`);
|
|
115
|
+
lines.push(` items {`);
|
|
116
|
+
lines.push(` publishedVersion {`);
|
|
117
|
+
lines.push(` content`);
|
|
118
|
+
lines.push(` }`);
|
|
119
|
+
lines.push(` }`);
|
|
120
|
+
lines.push(` }`);
|
|
121
|
+
lines.push(` }`);
|
|
122
|
+
lines.push(` }`);
|
|
123
|
+
lines.push(` }`);
|
|
124
|
+
lines.push(`\`;`);
|
|
125
|
+
lines.push('');
|
|
126
|
+
lines.push(`/**`);
|
|
127
|
+
lines.push(` * GraphQL query to fetch values for a specific context type`);
|
|
128
|
+
lines.push(` */`);
|
|
129
|
+
lines.push(`export const GET_CONTEXT_VALUES = gql\``);
|
|
130
|
+
lines.push(` query GetContextValues($modelKey: String!) {`);
|
|
131
|
+
lines.push(` entityRecords(modelKey: $modelKey, limit: 1000) {`);
|
|
132
|
+
lines.push(` items {`);
|
|
133
|
+
lines.push(` naturalKey`);
|
|
134
|
+
lines.push(` metadata`);
|
|
135
|
+
lines.push(` variants(limit: 1) {`);
|
|
136
|
+
lines.push(` items {`);
|
|
137
|
+
lines.push(` publishedVersion {`);
|
|
138
|
+
lines.push(` content`);
|
|
139
|
+
lines.push(` }`);
|
|
140
|
+
lines.push(` }`);
|
|
141
|
+
lines.push(` }`);
|
|
142
|
+
lines.push(` }`);
|
|
143
|
+
lines.push(` }`);
|
|
144
|
+
lines.push(` }`);
|
|
145
|
+
lines.push(`\`;`);
|
|
146
|
+
lines.push('');
|
|
147
|
+
// Generate React hook
|
|
148
|
+
lines.push(`// =============================================================================`);
|
|
149
|
+
lines.push(`// REACT HOOK`);
|
|
150
|
+
lines.push(`// =============================================================================`);
|
|
151
|
+
lines.push('');
|
|
152
|
+
lines.push(`/**`);
|
|
153
|
+
lines.push(` * Hook to fetch available contexts and their values`);
|
|
154
|
+
lines.push(` *`);
|
|
155
|
+
lines.push(` * @example`);
|
|
156
|
+
lines.push(` * const { contexts, loading, error } = useAvailableContexts(client);`);
|
|
157
|
+
lines.push(` * const markets = contexts.find(c => c.key === 'market')?.values;`);
|
|
158
|
+
lines.push(` */`);
|
|
159
|
+
lines.push(`export function useAvailableContexts(`);
|
|
160
|
+
lines.push(` client: { request: <T>(query: string, variables?: Record<string, unknown>) => Promise<T> },`);
|
|
161
|
+
lines.push(` options?: { skip?: boolean }`);
|
|
162
|
+
lines.push(`): {`);
|
|
163
|
+
lines.push(` contexts: ContextWithValues[];`);
|
|
164
|
+
lines.push(` loading: boolean;`);
|
|
165
|
+
lines.push(` error: Error | null;`);
|
|
166
|
+
lines.push(` refetch: () => Promise<void>;`);
|
|
167
|
+
lines.push(`} {`);
|
|
168
|
+
lines.push(` // This is a simplified implementation - in practice you'd use your framework's`);
|
|
169
|
+
lines.push(` // data fetching primitives (React Query, Apollo, SWR, etc.)`);
|
|
170
|
+
lines.push(` const [contexts, setContexts] = useState<ContextWithValues[]>([]);`);
|
|
171
|
+
lines.push(` const [loading, setLoading] = useState(!options?.skip);`);
|
|
172
|
+
lines.push(` const [error, setError] = useState<Error | null>(null);`);
|
|
173
|
+
lines.push('');
|
|
174
|
+
lines.push(` const fetchContexts = useCallback(async () => {`);
|
|
175
|
+
lines.push(` if (options?.skip) return;`);
|
|
176
|
+
lines.push(` setLoading(true);`);
|
|
177
|
+
lines.push(` setError(null);`);
|
|
178
|
+
lines.push(` try {`);
|
|
179
|
+
lines.push(` const result = await fetchAvailableContexts(client);`);
|
|
180
|
+
lines.push(` setContexts(result);`);
|
|
181
|
+
lines.push(` } catch (e) {`);
|
|
182
|
+
lines.push(` setError(e instanceof Error ? e : new Error('Failed to fetch contexts'));`);
|
|
183
|
+
lines.push(` } finally {`);
|
|
184
|
+
lines.push(` setLoading(false);`);
|
|
185
|
+
lines.push(` }`);
|
|
186
|
+
lines.push(` }, [client, options?.skip]);`);
|
|
187
|
+
lines.push('');
|
|
188
|
+
lines.push(` useEffect(() => {`);
|
|
189
|
+
lines.push(` fetchContexts();`);
|
|
190
|
+
lines.push(` }, [fetchContexts]);`);
|
|
191
|
+
lines.push('');
|
|
192
|
+
lines.push(` return { contexts, loading, error, refetch: fetchContexts };`);
|
|
193
|
+
lines.push(`}`);
|
|
194
|
+
lines.push('');
|
|
195
|
+
// Generate fetch function (non-hook version)
|
|
196
|
+
lines.push(`// =============================================================================`);
|
|
197
|
+
lines.push(`// FETCH FUNCTIONS`);
|
|
198
|
+
lines.push(`// =============================================================================`);
|
|
199
|
+
lines.push('');
|
|
200
|
+
lines.push(`/**`);
|
|
201
|
+
lines.push(` * Fetch available contexts and their values (non-hook version)`);
|
|
202
|
+
lines.push(` *`);
|
|
203
|
+
lines.push(` * @example`);
|
|
204
|
+
lines.push(` * const contexts = await fetchAvailableContexts(client);`);
|
|
205
|
+
lines.push(` */`);
|
|
206
|
+
lines.push(`export async function fetchAvailableContexts(`);
|
|
207
|
+
lines.push(` client: { request: <T>(query: string, variables?: Record<string, unknown>) => Promise<T> }`);
|
|
208
|
+
lines.push(`): Promise<ContextWithValues[]> {`);
|
|
209
|
+
lines.push(` // Fetch context definitions`);
|
|
210
|
+
lines.push(` const contextsResponse = await client.request<{`);
|
|
211
|
+
lines.push(` entityRecords: {`);
|
|
212
|
+
lines.push(` items: Array<{`);
|
|
213
|
+
lines.push(` naturalKey: string;`);
|
|
214
|
+
lines.push(` variants: {`);
|
|
215
|
+
lines.push(` items: Array<{`);
|
|
216
|
+
lines.push(` publishedVersion?: {`);
|
|
217
|
+
lines.push(` content: {`);
|
|
218
|
+
lines.push(` entityModelKey?: string;`);
|
|
219
|
+
lines.push(` outputKeys?: { valueKey: string; idKey: string };`);
|
|
220
|
+
lines.push(` };`);
|
|
221
|
+
lines.push(` };`);
|
|
222
|
+
lines.push(` }>;`);
|
|
223
|
+
lines.push(` };`);
|
|
224
|
+
lines.push(` }>;`);
|
|
225
|
+
lines.push(` };`);
|
|
226
|
+
lines.push(` }>(GET_AVAILABLE_CONTEXTS);`);
|
|
227
|
+
lines.push('');
|
|
228
|
+
lines.push(` const contextDefs = contextsResponse.entityRecords.items`);
|
|
229
|
+
lines.push(` .filter((item) => item.variants?.items?.[0]?.publishedVersion?.content)`);
|
|
230
|
+
lines.push(` .map((item) => {`);
|
|
231
|
+
lines.push(` const content = item.variants.items[0].publishedVersion!.content;`);
|
|
232
|
+
lines.push(` return {`);
|
|
233
|
+
lines.push(` key: item.naturalKey,`);
|
|
234
|
+
lines.push(` name: item.naturalKey,`);
|
|
235
|
+
lines.push(` entityModelKey: content.entityModelKey || '',`);
|
|
236
|
+
lines.push(` outputKeys: content.outputKeys || {`);
|
|
237
|
+
lines.push(` valueKey: item.naturalKey,`);
|
|
238
|
+
lines.push(` idKey: \`\${item.naturalKey}Id\`,`);
|
|
239
|
+
lines.push(` },`);
|
|
240
|
+
lines.push(` };`);
|
|
241
|
+
lines.push(` });`);
|
|
242
|
+
lines.push('');
|
|
243
|
+
lines.push(` // Fetch values for each context`);
|
|
244
|
+
lines.push(` const contextsWithValues: ContextWithValues[] = [];`);
|
|
245
|
+
lines.push('');
|
|
246
|
+
lines.push(` for (const contextDef of contextDefs) {`);
|
|
247
|
+
lines.push(` const valuesResponse = await client.request<{`);
|
|
248
|
+
lines.push(` entityRecords: {`);
|
|
249
|
+
lines.push(` items: Array<{`);
|
|
250
|
+
lines.push(` naturalKey: string;`);
|
|
251
|
+
lines.push(` metadata?: Record<string, unknown>;`);
|
|
252
|
+
lines.push(` variants: {`);
|
|
253
|
+
lines.push(` items: Array<{`);
|
|
254
|
+
lines.push(` publishedVersion?: {`);
|
|
255
|
+
lines.push(` content: Record<string, unknown>;`);
|
|
256
|
+
lines.push(` };`);
|
|
257
|
+
lines.push(` }>;`);
|
|
258
|
+
lines.push(` };`);
|
|
259
|
+
lines.push(` }>;`);
|
|
260
|
+
lines.push(` };`);
|
|
261
|
+
lines.push(` }>(GET_CONTEXT_VALUES, { modelKey: contextDef.entityModelKey });`);
|
|
262
|
+
lines.push('');
|
|
263
|
+
lines.push(` const values = valuesResponse.entityRecords.items.map((item) => {`);
|
|
264
|
+
lines.push(` const content = item.variants?.items?.[0]?.publishedVersion?.content;`);
|
|
265
|
+
lines.push(` return {`);
|
|
266
|
+
lines.push(` key: item.naturalKey,`);
|
|
267
|
+
lines.push(` name: (content?.name as string) || (item.metadata?.name as string) || item.naturalKey,`);
|
|
268
|
+
lines.push(` isPrimary: (content?.isPrimary as boolean) ?? false,`);
|
|
269
|
+
lines.push(` };`);
|
|
270
|
+
lines.push(` });`);
|
|
271
|
+
lines.push('');
|
|
272
|
+
lines.push(` contextsWithValues.push({ ...contextDef, values });`);
|
|
273
|
+
lines.push(` }`);
|
|
274
|
+
lines.push('');
|
|
275
|
+
lines.push(` return contextsWithValues;`);
|
|
276
|
+
lines.push(`}`);
|
|
277
|
+
lines.push('');
|
|
278
|
+
// Generate validation helpers
|
|
279
|
+
lines.push(`// =============================================================================`);
|
|
280
|
+
lines.push(`// VALIDATION HELPERS`);
|
|
281
|
+
lines.push(`// =============================================================================`);
|
|
282
|
+
lines.push('');
|
|
283
|
+
lines.push(`/**`);
|
|
284
|
+
lines.push(` * Validate a context value against available values`);
|
|
285
|
+
lines.push(` */`);
|
|
286
|
+
lines.push(`export function isValidContextValue(`);
|
|
287
|
+
lines.push(` contexts: ContextWithValues[],`);
|
|
288
|
+
lines.push(` contextKey: string,`);
|
|
289
|
+
lines.push(` value: string`);
|
|
290
|
+
lines.push(`): boolean {`);
|
|
291
|
+
lines.push(` const context = contexts.find(`);
|
|
292
|
+
lines.push(` (c) => c.key === contextKey || c.outputKeys.valueKey === contextKey`);
|
|
293
|
+
lines.push(` );`);
|
|
294
|
+
lines.push(` if (!context) return true; // Unknown context, allow any value`);
|
|
295
|
+
lines.push(` return context.values.some((v) => v.key === value);`);
|
|
296
|
+
lines.push(`}`);
|
|
297
|
+
lines.push('');
|
|
298
|
+
lines.push(`/**`);
|
|
299
|
+
lines.push(` * Get the primary/default value for a context`);
|
|
300
|
+
lines.push(` */`);
|
|
301
|
+
lines.push(`export function getDefaultContextValue(`);
|
|
302
|
+
lines.push(` contexts: ContextWithValues[],`);
|
|
303
|
+
lines.push(` contextKey: string`);
|
|
304
|
+
lines.push(`): string | undefined {`);
|
|
305
|
+
lines.push(` const context = contexts.find(`);
|
|
306
|
+
lines.push(` (c) => c.key === contextKey || c.outputKeys.valueKey === contextKey`);
|
|
307
|
+
lines.push(` );`);
|
|
308
|
+
lines.push(` if (!context || context.values.length === 0) return undefined;`);
|
|
309
|
+
lines.push(` const primary = context.values.find((v) => v.isPrimary);`);
|
|
310
|
+
lines.push(` return primary?.key ?? context.values[0]?.key;`);
|
|
311
|
+
lines.push(`}`);
|
|
312
|
+
lines.push('');
|
|
313
|
+
lines.push(`/**`);
|
|
314
|
+
lines.push(` * Get available values for a context`);
|
|
315
|
+
lines.push(` */`);
|
|
316
|
+
lines.push(`export function getContextValues(`);
|
|
317
|
+
lines.push(` contexts: ContextWithValues[],`);
|
|
318
|
+
lines.push(` contextKey: string`);
|
|
319
|
+
lines.push(`): ContextValue[] {`);
|
|
320
|
+
lines.push(` const context = contexts.find(`);
|
|
321
|
+
lines.push(` (c) => c.key === contextKey || c.outputKeys.valueKey === contextKey`);
|
|
322
|
+
lines.push(` );`);
|
|
323
|
+
lines.push(` return context?.values ?? [];`);
|
|
324
|
+
lines.push(`}`);
|
|
325
|
+
lines.push('');
|
|
326
|
+
return lines.join('\n') + '\n';
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Generate empty contexts file when no contexts are defined
|
|
330
|
+
*/
|
|
331
|
+
export function generateEmptyContextsFile() {
|
|
332
|
+
return `/**
|
|
333
|
+
* Available Contexts for Variant Resolution
|
|
334
|
+
*
|
|
335
|
+
* No contexts are currently defined for this project.
|
|
336
|
+
* Create context entities to enable typed context support.
|
|
337
|
+
*
|
|
338
|
+
* @generated by UniformGen - DO NOT EDIT MANUALLY
|
|
339
|
+
*/
|
|
340
|
+
|
|
341
|
+
import { gql } from 'graphql-request';
|
|
342
|
+
import { useState, useEffect, useCallback } from 'react';
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Context definition from the API
|
|
346
|
+
*/
|
|
347
|
+
export interface ContextDefinition {
|
|
348
|
+
key: string;
|
|
349
|
+
name: string;
|
|
350
|
+
entityModelKey: string;
|
|
351
|
+
outputKeys: {
|
|
352
|
+
valueKey: string;
|
|
353
|
+
idKey: string;
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Context value (an instance of a context, e.g., a specific market)
|
|
359
|
+
*/
|
|
360
|
+
export interface ContextValue {
|
|
361
|
+
key: string;
|
|
362
|
+
name: string;
|
|
363
|
+
isPrimary: boolean;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Full context with its available values
|
|
368
|
+
*/
|
|
369
|
+
export interface ContextWithValues extends ContextDefinition {
|
|
370
|
+
values: ContextValue[];
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Typed contexts object for variant resolution
|
|
375
|
+
*
|
|
376
|
+
* Pass this to resolve functions to select the appropriate variant.
|
|
377
|
+
*/
|
|
378
|
+
export interface TypedContexts {
|
|
379
|
+
/** Locale code (e.g., 'en-US', 'ja-JP') */
|
|
380
|
+
locale?: string;
|
|
381
|
+
/** Device type (e.g., 'mobile', 'desktop') */
|
|
382
|
+
device?: 'mobile' | 'tablet' | 'desktop' | string;
|
|
383
|
+
/** Whether user is authenticated */
|
|
384
|
+
authenticated?: boolean;
|
|
385
|
+
/** Customer ID for segment/experiment resolution */
|
|
386
|
+
customerId?: string;
|
|
387
|
+
/** Additional custom context values */
|
|
388
|
+
[key: string]: unknown;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/** No context keys defined at generation time */
|
|
392
|
+
export const CONTEXT_KEYS: string[] = [];
|
|
393
|
+
|
|
394
|
+
export type ContextKey = string;
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* GraphQL query to fetch available contexts and their values
|
|
398
|
+
*/
|
|
399
|
+
export const GET_AVAILABLE_CONTEXTS = gql\`
|
|
400
|
+
query GetAvailableContexts {
|
|
401
|
+
entityRecords(modelKey: "context", limit: 100) {
|
|
402
|
+
items {
|
|
403
|
+
naturalKey
|
|
404
|
+
variants(limit: 1) {
|
|
405
|
+
items {
|
|
406
|
+
publishedVersion {
|
|
407
|
+
content
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
\`;
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* GraphQL query to fetch values for a specific context type
|
|
418
|
+
*/
|
|
419
|
+
export const GET_CONTEXT_VALUES = gql\`
|
|
420
|
+
query GetContextValues($modelKey: String!) {
|
|
421
|
+
entityRecords(modelKey: $modelKey, limit: 1000) {
|
|
422
|
+
items {
|
|
423
|
+
naturalKey
|
|
424
|
+
metadata
|
|
425
|
+
variants(limit: 1) {
|
|
426
|
+
items {
|
|
427
|
+
publishedVersion {
|
|
428
|
+
content
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
\`;
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Hook to fetch available contexts and their values
|
|
439
|
+
*/
|
|
440
|
+
export function useAvailableContexts(
|
|
441
|
+
client: { request: <T>(query: string, variables?: Record<string, unknown>) => Promise<T> },
|
|
442
|
+
options?: { skip?: boolean }
|
|
443
|
+
): {
|
|
444
|
+
contexts: ContextWithValues[];
|
|
445
|
+
loading: boolean;
|
|
446
|
+
error: Error | null;
|
|
447
|
+
refetch: () => Promise<void>;
|
|
448
|
+
} {
|
|
449
|
+
const [contexts, setContexts] = useState<ContextWithValues[]>([]);
|
|
450
|
+
const [loading, setLoading] = useState(!options?.skip);
|
|
451
|
+
const [error, setError] = useState<Error | null>(null);
|
|
452
|
+
|
|
453
|
+
const fetchContexts = useCallback(async () => {
|
|
454
|
+
if (options?.skip) return;
|
|
455
|
+
setLoading(true);
|
|
456
|
+
setError(null);
|
|
457
|
+
try {
|
|
458
|
+
const result = await fetchAvailableContexts(client);
|
|
459
|
+
setContexts(result);
|
|
460
|
+
} catch (e) {
|
|
461
|
+
setError(e instanceof Error ? e : new Error('Failed to fetch contexts'));
|
|
462
|
+
} finally {
|
|
463
|
+
setLoading(false);
|
|
464
|
+
}
|
|
465
|
+
}, [client, options?.skip]);
|
|
466
|
+
|
|
467
|
+
useEffect(() => {
|
|
468
|
+
fetchContexts();
|
|
469
|
+
}, [fetchContexts]);
|
|
470
|
+
|
|
471
|
+
return { contexts, loading, error, refetch: fetchContexts };
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Fetch available contexts and their values (non-hook version)
|
|
476
|
+
*/
|
|
477
|
+
export async function fetchAvailableContexts(
|
|
478
|
+
client: { request: <T>(query: string, variables?: Record<string, unknown>) => Promise<T> }
|
|
479
|
+
): Promise<ContextWithValues[]> {
|
|
480
|
+
// Implementation same as in generateContextsFile - contexts discovered at runtime
|
|
481
|
+
const contextsResponse = await client.request<{
|
|
482
|
+
entityRecords: {
|
|
483
|
+
items: Array<{
|
|
484
|
+
naturalKey: string;
|
|
485
|
+
variants: {
|
|
486
|
+
items: Array<{
|
|
487
|
+
publishedVersion?: {
|
|
488
|
+
content: {
|
|
489
|
+
entityModelKey?: string;
|
|
490
|
+
outputKeys?: { valueKey: string; idKey: string };
|
|
491
|
+
};
|
|
492
|
+
};
|
|
493
|
+
}>;
|
|
494
|
+
};
|
|
495
|
+
}>;
|
|
496
|
+
};
|
|
497
|
+
}>(GET_AVAILABLE_CONTEXTS);
|
|
498
|
+
|
|
499
|
+
const contextDefs = contextsResponse.entityRecords.items
|
|
500
|
+
.filter((item) => item.variants?.items?.[0]?.publishedVersion?.content)
|
|
501
|
+
.map((item) => {
|
|
502
|
+
const content = item.variants.items[0].publishedVersion!.content;
|
|
503
|
+
return {
|
|
504
|
+
key: item.naturalKey,
|
|
505
|
+
name: item.naturalKey,
|
|
506
|
+
entityModelKey: content.entityModelKey || '',
|
|
507
|
+
outputKeys: content.outputKeys || {
|
|
508
|
+
valueKey: item.naturalKey,
|
|
509
|
+
idKey: \`\${item.naturalKey}Id\`,
|
|
510
|
+
},
|
|
511
|
+
};
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
const contextsWithValues: ContextWithValues[] = [];
|
|
515
|
+
|
|
516
|
+
for (const contextDef of contextDefs) {
|
|
517
|
+
const valuesResponse = await client.request<{
|
|
518
|
+
entityRecords: {
|
|
519
|
+
items: Array<{
|
|
520
|
+
naturalKey: string;
|
|
521
|
+
metadata?: Record<string, unknown>;
|
|
522
|
+
variants: {
|
|
523
|
+
items: Array<{
|
|
524
|
+
publishedVersion?: {
|
|
525
|
+
content: Record<string, unknown>;
|
|
526
|
+
};
|
|
527
|
+
}>;
|
|
528
|
+
};
|
|
529
|
+
}>;
|
|
530
|
+
};
|
|
531
|
+
}>(GET_CONTEXT_VALUES, { modelKey: contextDef.entityModelKey });
|
|
532
|
+
|
|
533
|
+
const values = valuesResponse.entityRecords.items.map((item) => {
|
|
534
|
+
const content = item.variants?.items?.[0]?.publishedVersion?.content;
|
|
535
|
+
return {
|
|
536
|
+
key: item.naturalKey,
|
|
537
|
+
name: (content?.name as string) || (item.metadata?.name as string) || item.naturalKey,
|
|
538
|
+
isPrimary: (content?.isPrimary as boolean) ?? false,
|
|
539
|
+
};
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
contextsWithValues.push({ ...contextDef, values });
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
return contextsWithValues;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Validate a context value against available values
|
|
550
|
+
*/
|
|
551
|
+
export function isValidContextValue(
|
|
552
|
+
contexts: ContextWithValues[],
|
|
553
|
+
contextKey: string,
|
|
554
|
+
value: string
|
|
555
|
+
): boolean {
|
|
556
|
+
const context = contexts.find(
|
|
557
|
+
(c) => c.key === contextKey || c.outputKeys.valueKey === contextKey
|
|
558
|
+
);
|
|
559
|
+
if (!context) return true;
|
|
560
|
+
return context.values.some((v) => v.key === value);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Get the primary/default value for a context
|
|
565
|
+
*/
|
|
566
|
+
export function getDefaultContextValue(
|
|
567
|
+
contexts: ContextWithValues[],
|
|
568
|
+
contextKey: string
|
|
569
|
+
): string | undefined {
|
|
570
|
+
const context = contexts.find(
|
|
571
|
+
(c) => c.key === contextKey || c.outputKeys.valueKey === contextKey
|
|
572
|
+
);
|
|
573
|
+
if (!context || context.values.length === 0) return undefined;
|
|
574
|
+
const primary = context.values.find((v) => v.isPrimary);
|
|
575
|
+
return primary?.key ?? context.values[0]?.key;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Get available values for a context
|
|
580
|
+
*/
|
|
581
|
+
export function getContextValues(
|
|
582
|
+
contexts: ContextWithValues[],
|
|
583
|
+
contextKey: string
|
|
584
|
+
): ContextValue[] {
|
|
585
|
+
const context = contexts.find(
|
|
586
|
+
(c) => c.key === contextKey || c.outputKeys.valueKey === contextKey
|
|
587
|
+
);
|
|
588
|
+
return context?.values ?? [];
|
|
589
|
+
}
|
|
590
|
+
`;
|
|
591
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-models.d.ts","sourceRoot":"","sources":["../../../src/generators/documents/data-models.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAGtE;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,CAyDzE"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { toPascalCase } from '../../utils/field-mapping.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generate GraphQL documents for a data model
|
|
4
|
+
*/
|
|
5
|
+
export function generateDataModelDocuments(model) {
|
|
6
|
+
const typeName = toPascalCase(model.handle);
|
|
7
|
+
return `# Generated GraphQL operations for ${model.name}
|
|
8
|
+
# @generated by UniformGen - DO NOT EDIT MANUALLY
|
|
9
|
+
|
|
10
|
+
fragment ${typeName}Fields on DataModelRecord {
|
|
11
|
+
id
|
|
12
|
+
data
|
|
13
|
+
translations
|
|
14
|
+
createdAt
|
|
15
|
+
updatedAt
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
query Get${typeName}($id: ID!) {
|
|
19
|
+
dataRecord(id: $id) {
|
|
20
|
+
...${typeName}Fields
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
query List${model.pluralName.replace(/\s+/g, '')}(
|
|
25
|
+
$dataModelId: ID!
|
|
26
|
+
$limit: Int
|
|
27
|
+
$offset: Int
|
|
28
|
+
$search: String
|
|
29
|
+
) {
|
|
30
|
+
dataRecords(
|
|
31
|
+
dataModelId: $dataModelId
|
|
32
|
+
limit: $limit
|
|
33
|
+
offset: $offset
|
|
34
|
+
search: $search
|
|
35
|
+
) {
|
|
36
|
+
records {
|
|
37
|
+
...${typeName}Fields
|
|
38
|
+
}
|
|
39
|
+
total
|
|
40
|
+
limit
|
|
41
|
+
offset
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
mutation Create${typeName}($input: CreateDataRecordInput!) {
|
|
46
|
+
createDataRecord(input: $input) {
|
|
47
|
+
...${typeName}Fields
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
mutation Update${typeName}($input: UpdateDataRecordInput!) {
|
|
52
|
+
updateDataRecord(input: $input) {
|
|
53
|
+
...${typeName}Fields
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
mutation Delete${typeName}($id: ID!) {
|
|
58
|
+
deleteDataRecord(id: $id)
|
|
59
|
+
}
|
|
60
|
+
`;
|
|
61
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { EntityModel } from '../../fetcher/fetch-schemas.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generate GraphQL documents for an entity model
|
|
4
|
+
* Uses generic entity/entities operations
|
|
5
|
+
*/
|
|
6
|
+
export declare function generateEntityModelDocuments(model: EntityModel): string;
|
|
7
|
+
//# sourceMappingURL=entity-models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-models.d.ts","sourceRoot":"","sources":["../../../src/generators/documents/entity-models.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAGlE;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAkFvE"}
|