@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,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admin Queries Generator
|
|
3
|
+
*
|
|
4
|
+
* Generates typed React hooks for administration layer queries:
|
|
5
|
+
* - use{Model}Records - List records with filtering
|
|
6
|
+
* - use{Model}Record - Get single record with variants
|
|
7
|
+
* - use{Model}Versions - Get version history
|
|
8
|
+
*
|
|
9
|
+
* @generated by UniformGen
|
|
10
|
+
*/
|
|
11
|
+
import type { EntityModel } from '../../fetcher/fetch-schemas.js';
|
|
12
|
+
/**
|
|
13
|
+
* Generate React admin query hooks for a model
|
|
14
|
+
*/
|
|
15
|
+
export declare function generateAdminQueriesReact(model: EntityModel, _allModels: EntityModel[]): string;
|
|
16
|
+
/**
|
|
17
|
+
* Generate Remix/Hydrogen admin query functions for a model
|
|
18
|
+
*/
|
|
19
|
+
export declare function generateAdminQueriesRemix(model: EntityModel, _allModels: EntityModel[]): string;
|
|
20
|
+
//# sourceMappingURL=queries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../../src/generators/admin/queries.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAIlE;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,WAAW,EAClB,UAAU,EAAE,WAAW,EAAE,GACxB,MAAM,CA0VR;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,WAAW,EAClB,UAAU,EAAE,WAAW,EAAE,GACxB,MAAM,CAkJR"}
|
|
@@ -0,0 +1,476 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admin Queries Generator
|
|
3
|
+
*
|
|
4
|
+
* Generates typed React hooks for administration layer queries:
|
|
5
|
+
* - use{Model}Records - List records with filtering
|
|
6
|
+
* - use{Model}Record - Get single record with variants
|
|
7
|
+
* - use{Model}Versions - Get version history
|
|
8
|
+
*
|
|
9
|
+
* @generated by UniformGen
|
|
10
|
+
*/
|
|
11
|
+
import { toPascalCase, toCamelCase } from '../../utils/field-mapping.js';
|
|
12
|
+
import { isInlineOnlyModel } from './types.js';
|
|
13
|
+
/**
|
|
14
|
+
* Generate React admin query hooks for a model
|
|
15
|
+
*/
|
|
16
|
+
export function generateAdminQueriesReact(model, _allModels) {
|
|
17
|
+
if (isInlineOnlyModel(model)) {
|
|
18
|
+
return '';
|
|
19
|
+
}
|
|
20
|
+
const typeName = toPascalCase(model.key);
|
|
21
|
+
const camelName = toCamelCase(model.key);
|
|
22
|
+
const pluralName = model.pluralName
|
|
23
|
+
? toCamelCase(model.pluralName.replace(/\s+/g, ''))
|
|
24
|
+
: `${camelName}s`;
|
|
25
|
+
const lines = [];
|
|
26
|
+
// File header
|
|
27
|
+
lines.push(`/**`);
|
|
28
|
+
lines.push(` * ${model.name} - Admin Query Hooks`);
|
|
29
|
+
lines.push(` *`);
|
|
30
|
+
lines.push(` * React hooks for querying ${model.name} records in admin UIs.`);
|
|
31
|
+
lines.push(` *`);
|
|
32
|
+
lines.push(` * @generated by UniformGen - DO NOT EDIT MANUALLY`);
|
|
33
|
+
lines.push(` */`);
|
|
34
|
+
lines.push('');
|
|
35
|
+
// Imports
|
|
36
|
+
lines.push(`import { useQuery, type QueryHookOptions } from '@apollo/client';`);
|
|
37
|
+
lines.push(`import { gql } from '@apollo/client';`);
|
|
38
|
+
lines.push(`import type {`);
|
|
39
|
+
lines.push(` ${typeName}Record,`);
|
|
40
|
+
lines.push(` ${typeName}RecordWithVariants,`);
|
|
41
|
+
lines.push(` ${typeName}Version,`);
|
|
42
|
+
lines.push(` ${typeName}FilterInput,`);
|
|
43
|
+
lines.push(`} from './types/${model.key}.js';`);
|
|
44
|
+
lines.push('');
|
|
45
|
+
// Re-export types
|
|
46
|
+
lines.push(`// Re-export types for convenience`);
|
|
47
|
+
lines.push(`export type {`);
|
|
48
|
+
lines.push(` ${typeName}Record,`);
|
|
49
|
+
lines.push(` ${typeName}RecordWithVariants,`);
|
|
50
|
+
lines.push(` ${typeName}Version,`);
|
|
51
|
+
lines.push(` ${typeName}FilterInput,`);
|
|
52
|
+
lines.push(`} from './types/${model.key}.js';`);
|
|
53
|
+
lines.push('');
|
|
54
|
+
// List result interface
|
|
55
|
+
lines.push(`/** List result for ${model.name} records */`);
|
|
56
|
+
lines.push(`export interface ${typeName}ListResult {`);
|
|
57
|
+
lines.push(` items: ${typeName}Record[];`);
|
|
58
|
+
lines.push(` total: number;`);
|
|
59
|
+
lines.push(` hasMore: boolean;`);
|
|
60
|
+
lines.push(`}`);
|
|
61
|
+
lines.push('');
|
|
62
|
+
// GraphQL Queries
|
|
63
|
+
lines.push(`// ============================================================================`);
|
|
64
|
+
lines.push(`// GraphQL Queries`);
|
|
65
|
+
lines.push(`// ============================================================================`);
|
|
66
|
+
lines.push('');
|
|
67
|
+
// List records query
|
|
68
|
+
lines.push(`const LIST_${typeName.toUpperCase()}_RECORDS = gql\``);
|
|
69
|
+
lines.push(` query List${typeName}Records(`);
|
|
70
|
+
lines.push(` $limit: Int`);
|
|
71
|
+
lines.push(` $offset: Int`);
|
|
72
|
+
lines.push(` $filters: [FilterInput!]`);
|
|
73
|
+
lines.push(` $sort: SortInput`);
|
|
74
|
+
lines.push(` ) {`);
|
|
75
|
+
lines.push(` entityRecords(modelKey: "${model.key}", limit: $limit, offset: $offset, filters: $filters, sort: $sort) {`);
|
|
76
|
+
lines.push(` items {`);
|
|
77
|
+
lines.push(` id`);
|
|
78
|
+
lines.push(` naturalKey`);
|
|
79
|
+
lines.push(` metadata`);
|
|
80
|
+
lines.push(` status`);
|
|
81
|
+
lines.push(` createdAt`);
|
|
82
|
+
lines.push(` updatedAt`);
|
|
83
|
+
lines.push(` currentVersion {`);
|
|
84
|
+
lines.push(` versionNumber`);
|
|
85
|
+
lines.push(` content`);
|
|
86
|
+
lines.push(` }`);
|
|
87
|
+
lines.push(` publishedVersion {`);
|
|
88
|
+
lines.push(` versionNumber`);
|
|
89
|
+
lines.push(` }`);
|
|
90
|
+
lines.push(` }`);
|
|
91
|
+
lines.push(` total`);
|
|
92
|
+
lines.push(` hasMore`);
|
|
93
|
+
lines.push(` }`);
|
|
94
|
+
lines.push(` }`);
|
|
95
|
+
lines.push(`\`;`);
|
|
96
|
+
lines.push('');
|
|
97
|
+
// Get record with variants query
|
|
98
|
+
lines.push(`const GET_${typeName.toUpperCase()}_RECORD = gql\``);
|
|
99
|
+
lines.push(` query Get${typeName}Record($id: ID!) {`);
|
|
100
|
+
lines.push(` entityRecord(id: $id) {`);
|
|
101
|
+
lines.push(` id`);
|
|
102
|
+
lines.push(` naturalKey`);
|
|
103
|
+
lines.push(` metadata`);
|
|
104
|
+
lines.push(` status`);
|
|
105
|
+
lines.push(` createdAt`);
|
|
106
|
+
lines.push(` updatedAt`);
|
|
107
|
+
lines.push(` currentVersion {`);
|
|
108
|
+
lines.push(` id`);
|
|
109
|
+
lines.push(` versionNumber`);
|
|
110
|
+
lines.push(` content`);
|
|
111
|
+
lines.push(` isPublished`);
|
|
112
|
+
lines.push(` createdAt`);
|
|
113
|
+
lines.push(` createdBy`);
|
|
114
|
+
lines.push(` }`);
|
|
115
|
+
lines.push(` publishedVersion {`);
|
|
116
|
+
lines.push(` id`);
|
|
117
|
+
lines.push(` versionNumber`);
|
|
118
|
+
lines.push(` }`);
|
|
119
|
+
lines.push(` variants {`);
|
|
120
|
+
lines.push(` items {`);
|
|
121
|
+
lines.push(` id`);
|
|
122
|
+
lines.push(` variantKey`);
|
|
123
|
+
lines.push(` catalogKey`);
|
|
124
|
+
lines.push(` currentVersion {`);
|
|
125
|
+
lines.push(` id`);
|
|
126
|
+
lines.push(` versionNumber`);
|
|
127
|
+
lines.push(` content`);
|
|
128
|
+
lines.push(` isPublished`);
|
|
129
|
+
lines.push(` createdAt`);
|
|
130
|
+
lines.push(` createdBy`);
|
|
131
|
+
lines.push(` }`);
|
|
132
|
+
lines.push(` publishedVersion {`);
|
|
133
|
+
lines.push(` id`);
|
|
134
|
+
lines.push(` versionNumber`);
|
|
135
|
+
lines.push(` content`);
|
|
136
|
+
lines.push(` isPublished`);
|
|
137
|
+
lines.push(` createdAt`);
|
|
138
|
+
lines.push(` }`);
|
|
139
|
+
lines.push(` versionCount`);
|
|
140
|
+
lines.push(` }`);
|
|
141
|
+
lines.push(` }`);
|
|
142
|
+
lines.push(` }`);
|
|
143
|
+
lines.push(` }`);
|
|
144
|
+
lines.push(`\`;`);
|
|
145
|
+
lines.push('');
|
|
146
|
+
// Get versions query
|
|
147
|
+
lines.push(`const GET_${typeName.toUpperCase()}_VERSIONS = gql\``);
|
|
148
|
+
lines.push(` query Get${typeName}Versions($variantId: ID!, $limit: Int, $offset: Int) {`);
|
|
149
|
+
lines.push(` entityVersions(variantId: $variantId, limit: $limit, offset: $offset) {`);
|
|
150
|
+
lines.push(` items {`);
|
|
151
|
+
lines.push(` id`);
|
|
152
|
+
lines.push(` variantId`);
|
|
153
|
+
lines.push(` versionNumber`);
|
|
154
|
+
lines.push(` content`);
|
|
155
|
+
lines.push(` isPublished`);
|
|
156
|
+
lines.push(` createdAt`);
|
|
157
|
+
lines.push(` createdBy`);
|
|
158
|
+
lines.push(` }`);
|
|
159
|
+
lines.push(` total`);
|
|
160
|
+
lines.push(` hasMore`);
|
|
161
|
+
lines.push(` }`);
|
|
162
|
+
lines.push(` }`);
|
|
163
|
+
lines.push(`\`;`);
|
|
164
|
+
lines.push('');
|
|
165
|
+
// Parse helpers
|
|
166
|
+
lines.push(`// ============================================================================`);
|
|
167
|
+
lines.push(`// Parse Helpers`);
|
|
168
|
+
lines.push(`// ============================================================================`);
|
|
169
|
+
lines.push('');
|
|
170
|
+
lines.push(`function parse${typeName}Record(entity: any): ${typeName}Record {`);
|
|
171
|
+
lines.push(` return {`);
|
|
172
|
+
lines.push(` id: entity.id,`);
|
|
173
|
+
lines.push(` modelKey: '${model.key}',`);
|
|
174
|
+
lines.push(` naturalKey: entity.naturalKey,`);
|
|
175
|
+
lines.push(` data: entity.currentVersion?.content,`);
|
|
176
|
+
lines.push(` metadata: entity.metadata,`);
|
|
177
|
+
lines.push(` versionNumber: entity.currentVersion?.versionNumber ?? 0,`);
|
|
178
|
+
lines.push(` publishedVersionNumber: entity.publishedVersion?.versionNumber,`);
|
|
179
|
+
lines.push(` status: entity.status,`);
|
|
180
|
+
lines.push(` createdAt: entity.createdAt,`);
|
|
181
|
+
lines.push(` updatedAt: entity.updatedAt,`);
|
|
182
|
+
lines.push(` };`);
|
|
183
|
+
lines.push(`}`);
|
|
184
|
+
lines.push('');
|
|
185
|
+
lines.push(`function parse${typeName}RecordWithVariants(entity: any): ${typeName}RecordWithVariants {`);
|
|
186
|
+
lines.push(` const record = parse${typeName}Record(entity);`);
|
|
187
|
+
lines.push(` return {`);
|
|
188
|
+
lines.push(` ...record,`);
|
|
189
|
+
lines.push(` variants: entity.variants?.items?.map((v: any) => ({`);
|
|
190
|
+
lines.push(` id: v.id,`);
|
|
191
|
+
lines.push(` variantKey: v.variantKey,`);
|
|
192
|
+
lines.push(` catalogKey: v.catalogKey,`);
|
|
193
|
+
lines.push(` currentVersion: v.currentVersion ? {`);
|
|
194
|
+
lines.push(` id: v.currentVersion.id,`);
|
|
195
|
+
lines.push(` variantId: v.id,`);
|
|
196
|
+
lines.push(` versionNumber: v.currentVersion.versionNumber,`);
|
|
197
|
+
lines.push(` content: v.currentVersion.content,`);
|
|
198
|
+
lines.push(` isPublished: v.currentVersion.isPublished,`);
|
|
199
|
+
lines.push(` createdAt: v.currentVersion.createdAt,`);
|
|
200
|
+
lines.push(` createdBy: v.currentVersion.createdBy,`);
|
|
201
|
+
lines.push(` } : undefined,`);
|
|
202
|
+
lines.push(` publishedVersion: v.publishedVersion ? {`);
|
|
203
|
+
lines.push(` id: v.publishedVersion.id,`);
|
|
204
|
+
lines.push(` variantId: v.id,`);
|
|
205
|
+
lines.push(` versionNumber: v.publishedVersion.versionNumber,`);
|
|
206
|
+
lines.push(` content: v.publishedVersion.content,`);
|
|
207
|
+
lines.push(` isPublished: v.publishedVersion.isPublished,`);
|
|
208
|
+
lines.push(` createdAt: v.publishedVersion.createdAt,`);
|
|
209
|
+
lines.push(` } : undefined,`);
|
|
210
|
+
lines.push(` versionCount: v.versionCount ?? 0,`);
|
|
211
|
+
lines.push(` })) ?? [],`);
|
|
212
|
+
lines.push(` };`);
|
|
213
|
+
lines.push(`}`);
|
|
214
|
+
lines.push('');
|
|
215
|
+
lines.push(`function parse${typeName}Version(version: any): ${typeName}Version {`);
|
|
216
|
+
lines.push(` return {`);
|
|
217
|
+
lines.push(` id: version.id,`);
|
|
218
|
+
lines.push(` variantId: version.variantId,`);
|
|
219
|
+
lines.push(` versionNumber: version.versionNumber,`);
|
|
220
|
+
lines.push(` content: version.content,`);
|
|
221
|
+
lines.push(` isPublished: version.isPublished,`);
|
|
222
|
+
lines.push(` createdAt: version.createdAt,`);
|
|
223
|
+
lines.push(` createdBy: version.createdBy,`);
|
|
224
|
+
lines.push(` };`);
|
|
225
|
+
lines.push(`}`);
|
|
226
|
+
lines.push('');
|
|
227
|
+
// Hooks
|
|
228
|
+
lines.push(`// ============================================================================`);
|
|
229
|
+
lines.push(`// Query Hooks`);
|
|
230
|
+
lines.push(`// ============================================================================`);
|
|
231
|
+
lines.push('');
|
|
232
|
+
// use{Model}Records hook
|
|
233
|
+
lines.push(`/**`);
|
|
234
|
+
lines.push(` * List ${model.name} records with optional filtering`);
|
|
235
|
+
lines.push(` *`);
|
|
236
|
+
lines.push(` * @example`);
|
|
237
|
+
lines.push(` * const { ${pluralName}, loading } = use${typeName}Records({`);
|
|
238
|
+
lines.push(` * filters: { status: 'PUBLISHED' },`);
|
|
239
|
+
lines.push(` * limit: 20,`);
|
|
240
|
+
lines.push(` * });`);
|
|
241
|
+
lines.push(` */`);
|
|
242
|
+
lines.push(`export function use${typeName}Records(options?: {`);
|
|
243
|
+
lines.push(` filters?: ${typeName}FilterInput;`);
|
|
244
|
+
lines.push(` limit?: number;`);
|
|
245
|
+
lines.push(` offset?: number;`);
|
|
246
|
+
lines.push(` sort?: { field: string; direction: 'ASC' | 'DESC' };`);
|
|
247
|
+
lines.push(` queryOptions?: Omit<QueryHookOptions, 'variables'>;`);
|
|
248
|
+
lines.push(`}) {`);
|
|
249
|
+
lines.push(` const { filters, queryOptions, ...rest } = options ?? {};`);
|
|
250
|
+
lines.push('');
|
|
251
|
+
lines.push(` // Convert typed filters to API format`);
|
|
252
|
+
lines.push(` const apiFilters = filters ? [`);
|
|
253
|
+
lines.push(` ...(filters.search ? [{ field: 'search', operator: 'contains', value: filters.search }] : []),`);
|
|
254
|
+
lines.push(` ...(filters.status ? [{ field: 'status', operator: 'eq', value: filters.status }] : []),`);
|
|
255
|
+
lines.push(` ...(filters.naturalKey ? [{ field: 'naturalKey', operator: 'eq', value: filters.naturalKey }] : []),`);
|
|
256
|
+
lines.push(` ...(filters.createdAfter ? [{ field: 'createdAt', operator: 'gte', value: filters.createdAfter }] : []),`);
|
|
257
|
+
lines.push(` ...(filters.createdBefore ? [{ field: 'createdAt', operator: 'lte', value: filters.createdBefore }] : []),`);
|
|
258
|
+
lines.push(` ...(filters.updatedAfter ? [{ field: 'updatedAt', operator: 'gte', value: filters.updatedAfter }] : []),`);
|
|
259
|
+
lines.push(` ...(filters.updatedBefore ? [{ field: 'updatedAt', operator: 'lte', value: filters.updatedBefore }] : []),`);
|
|
260
|
+
lines.push(` ] : undefined;`);
|
|
261
|
+
lines.push('');
|
|
262
|
+
lines.push(` const result = useQuery(LIST_${typeName.toUpperCase()}_RECORDS, {`);
|
|
263
|
+
lines.push(` ...queryOptions,`);
|
|
264
|
+
lines.push(` variables: { ...rest, filters: apiFilters },`);
|
|
265
|
+
lines.push(` });`);
|
|
266
|
+
lines.push('');
|
|
267
|
+
lines.push(` const data: ${typeName}ListResult | undefined = result.data?.entityRecords`);
|
|
268
|
+
lines.push(` ? {`);
|
|
269
|
+
lines.push(` items: result.data.entityRecords.items.map(parse${typeName}Record),`);
|
|
270
|
+
lines.push(` total: result.data.entityRecords.total,`);
|
|
271
|
+
lines.push(` hasMore: result.data.entityRecords.hasMore,`);
|
|
272
|
+
lines.push(` }`);
|
|
273
|
+
lines.push(` : undefined;`);
|
|
274
|
+
lines.push('');
|
|
275
|
+
lines.push(` return {`);
|
|
276
|
+
lines.push(` ...result,`);
|
|
277
|
+
lines.push(` data,`);
|
|
278
|
+
lines.push(` ${pluralName}: data,`);
|
|
279
|
+
lines.push(` };`);
|
|
280
|
+
lines.push(`}`);
|
|
281
|
+
lines.push('');
|
|
282
|
+
// use{Model}Record hook
|
|
283
|
+
lines.push(`/**`);
|
|
284
|
+
lines.push(` * Get a single ${model.name} record with all variants`);
|
|
285
|
+
lines.push(` *`);
|
|
286
|
+
lines.push(` * @example`);
|
|
287
|
+
lines.push(` * const { ${camelName}, loading } = use${typeName}Record('record-id');`);
|
|
288
|
+
lines.push(` */`);
|
|
289
|
+
lines.push(`export function use${typeName}Record(`);
|
|
290
|
+
lines.push(` id: string,`);
|
|
291
|
+
lines.push(` options?: Omit<QueryHookOptions, 'variables'>`);
|
|
292
|
+
lines.push(`) {`);
|
|
293
|
+
lines.push(` const result = useQuery(GET_${typeName.toUpperCase()}_RECORD, {`);
|
|
294
|
+
lines.push(` ...options,`);
|
|
295
|
+
lines.push(` variables: { id },`);
|
|
296
|
+
lines.push(` skip: !id,`);
|
|
297
|
+
lines.push(` });`);
|
|
298
|
+
lines.push('');
|
|
299
|
+
lines.push(` const data = result.data?.entityRecord`);
|
|
300
|
+
lines.push(` ? parse${typeName}RecordWithVariants(result.data.entityRecord)`);
|
|
301
|
+
lines.push(` : undefined;`);
|
|
302
|
+
lines.push('');
|
|
303
|
+
lines.push(` return {`);
|
|
304
|
+
lines.push(` ...result,`);
|
|
305
|
+
lines.push(` data,`);
|
|
306
|
+
lines.push(` ${camelName}: data,`);
|
|
307
|
+
lines.push(` };`);
|
|
308
|
+
lines.push(`}`);
|
|
309
|
+
lines.push('');
|
|
310
|
+
// use{Model}Versions hook
|
|
311
|
+
lines.push(`/**`);
|
|
312
|
+
lines.push(` * Get version history for a ${model.name} variant`);
|
|
313
|
+
lines.push(` *`);
|
|
314
|
+
lines.push(` * @example`);
|
|
315
|
+
lines.push(` * const { versions, loading } = use${typeName}Versions('variant-id', { limit: 10 });`);
|
|
316
|
+
lines.push(` */`);
|
|
317
|
+
lines.push(`export function use${typeName}Versions(`);
|
|
318
|
+
lines.push(` variantId: string,`);
|
|
319
|
+
lines.push(` options?: {`);
|
|
320
|
+
lines.push(` limit?: number;`);
|
|
321
|
+
lines.push(` offset?: number;`);
|
|
322
|
+
lines.push(` queryOptions?: Omit<QueryHookOptions, 'variables'>;`);
|
|
323
|
+
lines.push(` }`);
|
|
324
|
+
lines.push(`) {`);
|
|
325
|
+
lines.push(` const { queryOptions, ...rest } = options ?? {};`);
|
|
326
|
+
lines.push('');
|
|
327
|
+
lines.push(` const result = useQuery(GET_${typeName.toUpperCase()}_VERSIONS, {`);
|
|
328
|
+
lines.push(` ...queryOptions,`);
|
|
329
|
+
lines.push(` variables: { variantId, ...rest },`);
|
|
330
|
+
lines.push(` skip: !variantId,`);
|
|
331
|
+
lines.push(` });`);
|
|
332
|
+
lines.push('');
|
|
333
|
+
lines.push(` const versions = result.data?.entityVersions?.items?.map(parse${typeName}Version);`);
|
|
334
|
+
lines.push('');
|
|
335
|
+
lines.push(` return {`);
|
|
336
|
+
lines.push(` ...result,`);
|
|
337
|
+
lines.push(` versions,`);
|
|
338
|
+
lines.push(` total: result.data?.entityVersions?.total,`);
|
|
339
|
+
lines.push(` hasMore: result.data?.entityVersions?.hasMore,`);
|
|
340
|
+
lines.push(` };`);
|
|
341
|
+
lines.push(`}`);
|
|
342
|
+
return lines.join('\n') + '\n';
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Generate Remix/Hydrogen admin query functions for a model
|
|
346
|
+
*/
|
|
347
|
+
export function generateAdminQueriesRemix(model, _allModels) {
|
|
348
|
+
if (isInlineOnlyModel(model)) {
|
|
349
|
+
return '';
|
|
350
|
+
}
|
|
351
|
+
const typeName = toPascalCase(model.key);
|
|
352
|
+
const lines = [];
|
|
353
|
+
// File header
|
|
354
|
+
lines.push(`/**`);
|
|
355
|
+
lines.push(` * ${model.name} - Admin Query Functions`);
|
|
356
|
+
lines.push(` *`);
|
|
357
|
+
lines.push(` * Server-side functions for querying ${model.name} records.`);
|
|
358
|
+
lines.push(` * Use in Remix loaders or Hydrogen server functions.`);
|
|
359
|
+
lines.push(` *`);
|
|
360
|
+
lines.push(` * @generated by UniformGen - DO NOT EDIT MANUALLY`);
|
|
361
|
+
lines.push(` */`);
|
|
362
|
+
lines.push('');
|
|
363
|
+
// Imports
|
|
364
|
+
lines.push(`import type {`);
|
|
365
|
+
lines.push(` ${typeName}Record,`);
|
|
366
|
+
lines.push(` ${typeName}RecordWithVariants,`);
|
|
367
|
+
lines.push(` ${typeName}Version,`);
|
|
368
|
+
lines.push(` ${typeName}FilterInput,`);
|
|
369
|
+
lines.push(`} from './types/${model.key}.js';`);
|
|
370
|
+
lines.push('');
|
|
371
|
+
// Re-export types
|
|
372
|
+
lines.push(`// Re-export types for convenience`);
|
|
373
|
+
lines.push(`export type {`);
|
|
374
|
+
lines.push(` ${typeName}Record,`);
|
|
375
|
+
lines.push(` ${typeName}RecordWithVariants,`);
|
|
376
|
+
lines.push(` ${typeName}Version,`);
|
|
377
|
+
lines.push(` ${typeName}FilterInput,`);
|
|
378
|
+
lines.push(`} from './types/${model.key}.js';`);
|
|
379
|
+
lines.push('');
|
|
380
|
+
// GraphQL client interface
|
|
381
|
+
lines.push(`/** GraphQL client interface */`);
|
|
382
|
+
lines.push(`export interface GraphQLClient {`);
|
|
383
|
+
lines.push(` request<T>(query: string, variables?: Record<string, unknown>): Promise<T>;`);
|
|
384
|
+
lines.push(`}`);
|
|
385
|
+
lines.push('');
|
|
386
|
+
// List result interface
|
|
387
|
+
lines.push(`/** List result for ${model.name} records */`);
|
|
388
|
+
lines.push(`export interface ${typeName}ListResult {`);
|
|
389
|
+
lines.push(` items: ${typeName}Record[];`);
|
|
390
|
+
lines.push(` total: number;`);
|
|
391
|
+
lines.push(` hasMore: boolean;`);
|
|
392
|
+
lines.push(`}`);
|
|
393
|
+
lines.push('');
|
|
394
|
+
// GraphQL Queries (as strings for server-side use)
|
|
395
|
+
lines.push(`// GraphQL Queries`);
|
|
396
|
+
lines.push(`const LIST_${typeName.toUpperCase()}_RECORDS = \``);
|
|
397
|
+
lines.push(` query List${typeName}Records($limit: Int, $offset: Int, $filters: [FilterInput!], $sort: SortInput) {`);
|
|
398
|
+
lines.push(` entityRecords(modelKey: "${model.key}", limit: $limit, offset: $offset, filters: $filters, sort: $sort) {`);
|
|
399
|
+
lines.push(` items { id naturalKey metadata status createdAt updatedAt currentVersion { versionNumber content } publishedVersion { versionNumber } }`);
|
|
400
|
+
lines.push(` total hasMore`);
|
|
401
|
+
lines.push(` }`);
|
|
402
|
+
lines.push(` }`);
|
|
403
|
+
lines.push(`\`;`);
|
|
404
|
+
lines.push('');
|
|
405
|
+
lines.push(`const GET_${typeName.toUpperCase()}_RECORD = \``);
|
|
406
|
+
lines.push(` query Get${typeName}Record($id: ID!) {`);
|
|
407
|
+
lines.push(` entityRecord(id: $id) {`);
|
|
408
|
+
lines.push(` id naturalKey metadata status createdAt updatedAt`);
|
|
409
|
+
lines.push(` currentVersion { id versionNumber content isPublished createdAt createdBy }`);
|
|
410
|
+
lines.push(` publishedVersion { id versionNumber }`);
|
|
411
|
+
lines.push(` variants { items { id variantKey catalogKey currentVersion { id versionNumber content isPublished createdAt createdBy } publishedVersion { id versionNumber content isPublished createdAt } versionCount } }`);
|
|
412
|
+
lines.push(` }`);
|
|
413
|
+
lines.push(` }`);
|
|
414
|
+
lines.push(`\`;`);
|
|
415
|
+
lines.push('');
|
|
416
|
+
lines.push(`const GET_${typeName.toUpperCase()}_VERSIONS = \``);
|
|
417
|
+
lines.push(` query Get${typeName}Versions($variantId: ID!, $limit: Int, $offset: Int) {`);
|
|
418
|
+
lines.push(` entityVersions(variantId: $variantId, limit: $limit, offset: $offset) {`);
|
|
419
|
+
lines.push(` items { id variantId versionNumber content isPublished createdAt createdBy }`);
|
|
420
|
+
lines.push(` total hasMore`);
|
|
421
|
+
lines.push(` }`);
|
|
422
|
+
lines.push(` }`);
|
|
423
|
+
lines.push(`\`;`);
|
|
424
|
+
lines.push('');
|
|
425
|
+
// Parse helpers (same logic, just not exported differently)
|
|
426
|
+
lines.push(`// Parse helpers`);
|
|
427
|
+
lines.push(`function parse${typeName}Record(entity: any): ${typeName}Record {`);
|
|
428
|
+
lines.push(` return { id: entity.id, modelKey: '${model.key}', naturalKey: entity.naturalKey, data: entity.currentVersion?.content, metadata: entity.metadata, versionNumber: entity.currentVersion?.versionNumber ?? 0, publishedVersionNumber: entity.publishedVersion?.versionNumber, status: entity.status, createdAt: entity.createdAt, updatedAt: entity.updatedAt };`);
|
|
429
|
+
lines.push(`}`);
|
|
430
|
+
lines.push('');
|
|
431
|
+
lines.push(`function parse${typeName}RecordWithVariants(entity: any): ${typeName}RecordWithVariants {`);
|
|
432
|
+
lines.push(` return { ...parse${typeName}Record(entity), variants: entity.variants?.items?.map((v: any) => ({ id: v.id, variantKey: v.variantKey, catalogKey: v.catalogKey, currentVersion: v.currentVersion ? { id: v.currentVersion.id, variantId: v.id, versionNumber: v.currentVersion.versionNumber, content: v.currentVersion.content, isPublished: v.currentVersion.isPublished, createdAt: v.currentVersion.createdAt, createdBy: v.currentVersion.createdBy } : undefined, publishedVersion: v.publishedVersion ? { id: v.publishedVersion.id, variantId: v.id, versionNumber: v.publishedVersion.versionNumber, content: v.publishedVersion.content, isPublished: v.publishedVersion.isPublished, createdAt: v.publishedVersion.createdAt } : undefined, versionCount: v.versionCount ?? 0 })) ?? [] };`);
|
|
433
|
+
lines.push(`}`);
|
|
434
|
+
lines.push('');
|
|
435
|
+
// Server functions
|
|
436
|
+
lines.push(`// ============================================================================`);
|
|
437
|
+
lines.push(`// Query Functions`);
|
|
438
|
+
lines.push(`// ============================================================================`);
|
|
439
|
+
lines.push('');
|
|
440
|
+
lines.push(`/**`);
|
|
441
|
+
lines.push(` * List ${model.name} records`);
|
|
442
|
+
lines.push(` */`);
|
|
443
|
+
lines.push(`export async function list${typeName}Records(`);
|
|
444
|
+
lines.push(` client: GraphQLClient,`);
|
|
445
|
+
lines.push(` options?: { filters?: ${typeName}FilterInput; limit?: number; offset?: number; sort?: { field: string; direction: 'ASC' | 'DESC' } }`);
|
|
446
|
+
lines.push(`): Promise<${typeName}ListResult> {`);
|
|
447
|
+
lines.push(` const { filters, ...rest } = options ?? {};`);
|
|
448
|
+
lines.push(` const apiFilters = filters ? [`);
|
|
449
|
+
lines.push(` ...(filters.search ? [{ field: 'search', operator: 'contains', value: filters.search }] : []),`);
|
|
450
|
+
lines.push(` ...(filters.status ? [{ field: 'status', operator: 'eq', value: filters.status }] : []),`);
|
|
451
|
+
lines.push(` ] : undefined;`);
|
|
452
|
+
lines.push(` const result = await client.request<{ entityRecords: any }>(LIST_${typeName.toUpperCase()}_RECORDS, { ...rest, filters: apiFilters });`);
|
|
453
|
+
lines.push(` return { items: result.entityRecords.items.map(parse${typeName}Record), total: result.entityRecords.total, hasMore: result.entityRecords.hasMore };`);
|
|
454
|
+
lines.push(`}`);
|
|
455
|
+
lines.push('');
|
|
456
|
+
lines.push(`/**`);
|
|
457
|
+
lines.push(` * Get a single ${model.name} record with variants`);
|
|
458
|
+
lines.push(` */`);
|
|
459
|
+
lines.push(`export async function get${typeName}Record(client: GraphQLClient, id: string): Promise<${typeName}RecordWithVariants | null> {`);
|
|
460
|
+
lines.push(` const result = await client.request<{ entityRecord: any }>(GET_${typeName.toUpperCase()}_RECORD, { id });`);
|
|
461
|
+
lines.push(` return result.entityRecord ? parse${typeName}RecordWithVariants(result.entityRecord) : null;`);
|
|
462
|
+
lines.push(`}`);
|
|
463
|
+
lines.push('');
|
|
464
|
+
lines.push(`/**`);
|
|
465
|
+
lines.push(` * Get version history for a ${model.name} variant`);
|
|
466
|
+
lines.push(` */`);
|
|
467
|
+
lines.push(`export async function get${typeName}Versions(`);
|
|
468
|
+
lines.push(` client: GraphQLClient,`);
|
|
469
|
+
lines.push(` variantId: string,`);
|
|
470
|
+
lines.push(` options?: { limit?: number; offset?: number }`);
|
|
471
|
+
lines.push(`): Promise<{ items: ${typeName}Version[]; total: number; hasMore: boolean }> {`);
|
|
472
|
+
lines.push(` const result = await client.request<{ entityVersions: any }>(GET_${typeName.toUpperCase()}_VERSIONS, { variantId, ...options });`);
|
|
473
|
+
lines.push(` return { items: result.entityVersions.items.map((v: any) => ({ id: v.id, variantId: v.variantId, versionNumber: v.versionNumber, content: v.content, isPublished: v.isPublished, createdAt: v.createdAt, createdBy: v.createdBy })), total: result.entityVersions.total, hasMore: result.entityVersions.hasMore };`);
|
|
474
|
+
lines.push(`}`);
|
|
475
|
+
return lines.join('\n') + '\n';
|
|
476
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admin Types Generator
|
|
3
|
+
*
|
|
4
|
+
* Generates TypeScript types for administration layer:
|
|
5
|
+
* - Record types with variants
|
|
6
|
+
* - Version types for history
|
|
7
|
+
* - Filter and input types
|
|
8
|
+
*
|
|
9
|
+
* @generated by UniformGen
|
|
10
|
+
*/
|
|
11
|
+
import type { EntityModel } from '../../fetcher/fetch-schemas.js';
|
|
12
|
+
/**
|
|
13
|
+
* Generate metadata type for a model
|
|
14
|
+
*/
|
|
15
|
+
export declare function generateMetadataType(model: EntityModel): string | null;
|
|
16
|
+
/**
|
|
17
|
+
* Check if model is inline-only (no records mode)
|
|
18
|
+
*/
|
|
19
|
+
export declare function isInlineOnlyModel(model: EntityModel): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Generate admin types for a model
|
|
22
|
+
*/
|
|
23
|
+
export declare function generateAdminTypes(model: EntityModel, _allModels: EntityModel[]): string;
|
|
24
|
+
/**
|
|
25
|
+
* Generate index file for admin types
|
|
26
|
+
*/
|
|
27
|
+
export declare function generateAdminTypesIndex(models: EntityModel[]): string;
|
|
28
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/generators/admin/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAuB,MAAM,gCAAgC,CAAC;AA2EvF;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,GAAG,IAAI,CAMtE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAE7D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,WAAW,EAClB,UAAU,EAAE,WAAW,EAAE,GACxB,MAAM,CA6IR;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,CAgCrE"}
|