@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.
Files changed (299) hide show
  1. package/README.md +356 -0
  2. package/dist/auth/credentials.d.ts +58 -0
  3. package/dist/auth/credentials.d.ts.map +1 -0
  4. package/dist/auth/credentials.js +107 -0
  5. package/dist/cli.d.ts +3 -0
  6. package/dist/cli.d.ts.map +1 -0
  7. package/dist/cli.js +563 -0
  8. package/dist/commands/init.d.ts +11 -0
  9. package/dist/commands/init.d.ts.map +1 -0
  10. package/dist/commands/init.js +113 -0
  11. package/dist/commands/login.d.ts +9 -0
  12. package/dist/commands/login.d.ts.map +1 -0
  13. package/dist/commands/login.js +158 -0
  14. package/dist/commands/logout.d.ts +5 -0
  15. package/dist/commands/logout.d.ts.map +1 -0
  16. package/dist/commands/logout.js +13 -0
  17. package/dist/commands/push.d.ts +13 -0
  18. package/dist/commands/push.d.ts.map +1 -0
  19. package/dist/commands/push.js +328 -0
  20. package/dist/commands/scaffold.d.ts +19 -0
  21. package/dist/commands/scaffold.d.ts.map +1 -0
  22. package/dist/commands/scaffold.js +366 -0
  23. package/dist/commands/seed.d.ts +20 -0
  24. package/dist/commands/seed.d.ts.map +1 -0
  25. package/dist/commands/seed.js +380 -0
  26. package/dist/commands/select-project.d.ts +10 -0
  27. package/dist/commands/select-project.d.ts.map +1 -0
  28. package/dist/commands/select-project.js +277 -0
  29. package/dist/commands/setup.d.ts +5 -0
  30. package/dist/commands/setup.d.ts.map +1 -0
  31. package/dist/commands/setup.js +51 -0
  32. package/dist/commands/sync.d.ts +13 -0
  33. package/dist/commands/sync.d.ts.map +1 -0
  34. package/dist/commands/sync.js +318 -0
  35. package/dist/commands/whoami.d.ts +5 -0
  36. package/dist/commands/whoami.d.ts.map +1 -0
  37. package/dist/commands/whoami.js +31 -0
  38. package/dist/config/load-config.d.ts +6 -0
  39. package/dist/config/load-config.d.ts.map +1 -0
  40. package/dist/config/load-config.js +103 -0
  41. package/dist/config/settings.d.ts +20 -0
  42. package/dist/config/settings.d.ts.map +1 -0
  43. package/dist/config/settings.js +64 -0
  44. package/dist/config/types.d.ts +152 -0
  45. package/dist/config/types.d.ts.map +1 -0
  46. package/dist/config/types.js +94 -0
  47. package/dist/fetcher/fetch-schemas.d.ts +140 -0
  48. package/dist/fetcher/fetch-schemas.d.ts.map +1 -0
  49. package/dist/fetcher/fetch-schemas.js +223 -0
  50. package/dist/fetcher/fetch-workflows.d.ts +53 -0
  51. package/dist/fetcher/fetch-workflows.d.ts.map +1 -0
  52. package/dist/fetcher/fetch-workflows.js +164 -0
  53. package/dist/generated/hooks/customer-detail.d.ts +74 -0
  54. package/dist/generated/hooks/customer-detail.d.ts.map +1 -0
  55. package/dist/generated/hooks/customer-detail.js +113 -0
  56. package/dist/generated/hooks/design-system.d.ts +74 -0
  57. package/dist/generated/hooks/design-system.d.ts.map +1 -0
  58. package/dist/generated/hooks/design-system.js +109 -0
  59. package/dist/generated/hooks/index.d.ts +16 -0
  60. package/dist/generated/hooks/index.d.ts.map +1 -0
  61. package/dist/generated/hooks/index.js +14 -0
  62. package/dist/generated/hooks/shopify-collection.d.ts +74 -0
  63. package/dist/generated/hooks/shopify-collection.d.ts.map +1 -0
  64. package/dist/generated/hooks/shopify-collection.js +113 -0
  65. package/dist/generated/hooks/shopify-market.d.ts +74 -0
  66. package/dist/generated/hooks/shopify-market.d.ts.map +1 -0
  67. package/dist/generated/hooks/shopify-market.js +109 -0
  68. package/dist/generated/hooks/shopify-product.d.ts +74 -0
  69. package/dist/generated/hooks/shopify-product.d.ts.map +1 -0
  70. package/dist/generated/hooks/shopify-product.js +113 -0
  71. package/dist/generated/hooks/shopify-variant.d.ts +74 -0
  72. package/dist/generated/hooks/shopify-variant.d.ts.map +1 -0
  73. package/dist/generated/hooks/shopify-variant.js +113 -0
  74. package/dist/generated/hooks/template.d.ts +74 -0
  75. package/dist/generated/hooks/template.d.ts.map +1 -0
  76. package/dist/generated/hooks/template.js +107 -0
  77. package/dist/generated/types/config.d.ts +88 -0
  78. package/dist/generated/types/config.d.ts.map +1 -0
  79. package/dist/generated/types/config.js +14 -0
  80. package/dist/generated/types/data-models/index.d.ts +7 -0
  81. package/dist/generated/types/data-models/index.d.ts.map +1 -0
  82. package/dist/generated/types/data-models/index.js +6 -0
  83. package/dist/generated/types/data-models/test.d.ts +29 -0
  84. package/dist/generated/types/data-models/test.d.ts.map +1 -0
  85. package/dist/generated/types/data-models/test.js +1 -0
  86. package/dist/generated/types/data-models/watch.d.ts +26 -0
  87. package/dist/generated/types/data-models/watch.d.ts.map +1 -0
  88. package/dist/generated/types/data-models/watch.js +1 -0
  89. package/dist/generated/types/field-types.d.ts +255 -0
  90. package/dist/generated/types/field-types.d.ts.map +1 -0
  91. package/dist/generated/types/field-types.js +35 -0
  92. package/dist/generated/types/hooks.d.ts +106 -0
  93. package/dist/generated/types/hooks.d.ts.map +1 -0
  94. package/dist/generated/types/hooks.js +9 -0
  95. package/dist/generated/types/index.d.ts +10 -0
  96. package/dist/generated/types/index.d.ts.map +1 -0
  97. package/dist/generated/types/index.js +9 -0
  98. package/dist/generated/types/models/button-variant.d.ts +16 -0
  99. package/dist/generated/types/models/button-variant.d.ts.map +1 -0
  100. package/dist/generated/types/models/button-variant.js +1 -0
  101. package/dist/generated/types/models/color-palette.d.ts +27 -0
  102. package/dist/generated/types/models/color-palette.d.ts.map +1 -0
  103. package/dist/generated/types/models/color-palette.js +1 -0
  104. package/dist/generated/types/models/color-with-scale.d.ts +15 -0
  105. package/dist/generated/types/models/color-with-scale.d.ts.map +1 -0
  106. package/dist/generated/types/models/color-with-scale.js +1 -0
  107. package/dist/generated/types/models/context.d.ts +53 -0
  108. package/dist/generated/types/models/context.d.ts.map +1 -0
  109. package/dist/generated/types/models/context.js +51 -0
  110. package/dist/generated/types/models/customer-detail.d.ts +32 -0
  111. package/dist/generated/types/models/customer-detail.d.ts.map +1 -0
  112. package/dist/generated/types/models/customer-detail.js +26 -0
  113. package/dist/generated/types/models/design-system-badges.d.ts +16 -0
  114. package/dist/generated/types/models/design-system-badges.d.ts.map +1 -0
  115. package/dist/generated/types/models/design-system-badges.js +1 -0
  116. package/dist/generated/types/models/design-system-buttons.d.ts +17 -0
  117. package/dist/generated/types/models/design-system-buttons.d.ts.map +1 -0
  118. package/dist/generated/types/models/design-system-buttons.js +1 -0
  119. package/dist/generated/types/models/design-system-cards.d.ts +16 -0
  120. package/dist/generated/types/models/design-system-cards.d.ts.map +1 -0
  121. package/dist/generated/types/models/design-system-cards.js +1 -0
  122. package/dist/generated/types/models/design-system-colors.d.ts +12 -0
  123. package/dist/generated/types/models/design-system-colors.d.ts.map +1 -0
  124. package/dist/generated/types/models/design-system-colors.js +1 -0
  125. package/dist/generated/types/models/design-system-dark-mode.d.ts +13 -0
  126. package/dist/generated/types/models/design-system-dark-mode.d.ts.map +1 -0
  127. package/dist/generated/types/models/design-system-dark-mode.js +1 -0
  128. package/dist/generated/types/models/design-system-focus-ring.d.ts +14 -0
  129. package/dist/generated/types/models/design-system-focus-ring.d.ts.map +1 -0
  130. package/dist/generated/types/models/design-system-focus-ring.js +1 -0
  131. package/dist/generated/types/models/design-system-grid.d.ts +18 -0
  132. package/dist/generated/types/models/design-system-grid.d.ts.map +1 -0
  133. package/dist/generated/types/models/design-system-grid.js +1 -0
  134. package/dist/generated/types/models/design-system-inputs.d.ts +26 -0
  135. package/dist/generated/types/models/design-system-inputs.d.ts.map +1 -0
  136. package/dist/generated/types/models/design-system-inputs.js +1 -0
  137. package/dist/generated/types/models/design-system-links.d.ts +16 -0
  138. package/dist/generated/types/models/design-system-links.d.ts.map +1 -0
  139. package/dist/generated/types/models/design-system-links.js +1 -0
  140. package/dist/generated/types/models/design-system-shadows.d.ts +20 -0
  141. package/dist/generated/types/models/design-system-shadows.d.ts.map +1 -0
  142. package/dist/generated/types/models/design-system-shadows.js +1 -0
  143. package/dist/generated/types/models/design-system-spacing.d.ts +13 -0
  144. package/dist/generated/types/models/design-system-spacing.d.ts.map +1 -0
  145. package/dist/generated/types/models/design-system-spacing.js +1 -0
  146. package/dist/generated/types/models/design-system-transitions.d.ts +15 -0
  147. package/dist/generated/types/models/design-system-transitions.d.ts.map +1 -0
  148. package/dist/generated/types/models/design-system-transitions.js +1 -0
  149. package/dist/generated/types/models/design-system-typography.d.ts +21 -0
  150. package/dist/generated/types/models/design-system-typography.d.ts.map +1 -0
  151. package/dist/generated/types/models/design-system-typography.js +1 -0
  152. package/dist/generated/types/models/design-system.d.ts +138 -0
  153. package/dist/generated/types/models/design-system.d.ts.map +1 -0
  154. package/dist/generated/types/models/design-system.js +64 -0
  155. package/dist/generated/types/models/experiment.d.ts +57 -0
  156. package/dist/generated/types/models/experiment.d.ts.map +1 -0
  157. package/dist/generated/types/models/experiment.js +55 -0
  158. package/dist/generated/types/models/font-file.d.ts +16 -0
  159. package/dist/generated/types/models/font-file.d.ts.map +1 -0
  160. package/dist/generated/types/models/font-file.js +1 -0
  161. package/dist/generated/types/models/index.d.ts +38 -0
  162. package/dist/generated/types/models/index.d.ts.map +1 -0
  163. package/dist/generated/types/models/index.js +12 -0
  164. package/dist/generated/types/models/integration.d.ts +32 -0
  165. package/dist/generated/types/models/integration.d.ts.map +1 -0
  166. package/dist/generated/types/models/integration.js +26 -0
  167. package/dist/generated/types/models/route-tree.d.ts +43 -0
  168. package/dist/generated/types/models/route-tree.d.ts.map +1 -0
  169. package/dist/generated/types/models/route-tree.js +39 -0
  170. package/dist/generated/types/models/segment.d.ts +57 -0
  171. package/dist/generated/types/models/segment.d.ts.map +1 -0
  172. package/dist/generated/types/models/segment.js +55 -0
  173. package/dist/generated/types/models/shopify-collection.d.ts +32 -0
  174. package/dist/generated/types/models/shopify-collection.d.ts.map +1 -0
  175. package/dist/generated/types/models/shopify-collection.js +26 -0
  176. package/dist/generated/types/models/shopify-market.d.ts +32 -0
  177. package/dist/generated/types/models/shopify-market.d.ts.map +1 -0
  178. package/dist/generated/types/models/shopify-market.js +26 -0
  179. package/dist/generated/types/models/shopify-product.d.ts +32 -0
  180. package/dist/generated/types/models/shopify-product.d.ts.map +1 -0
  181. package/dist/generated/types/models/shopify-product.js +26 -0
  182. package/dist/generated/types/models/shopify-variant.d.ts +32 -0
  183. package/dist/generated/types/models/shopify-variant.d.ts.map +1 -0
  184. package/dist/generated/types/models/shopify-variant.js +26 -0
  185. package/dist/generated/types/models/template.d.ts +53 -0
  186. package/dist/generated/types/models/template.d.ts.map +1 -0
  187. package/dist/generated/types/models/template.js +40 -0
  188. package/dist/generated/types/models/typography-variant.d.ts +15 -0
  189. package/dist/generated/types/models/typography-variant.d.ts.map +1 -0
  190. package/dist/generated/types/models/typography-variant.js +1 -0
  191. package/dist/generated/types/scalars.d.ts +56 -0
  192. package/dist/generated/types/scalars.d.ts.map +1 -0
  193. package/dist/generated/types/scalars.js +6 -0
  194. package/dist/generators/admin/index.d.ts +32 -0
  195. package/dist/generators/admin/index.d.ts.map +1 -0
  196. package/dist/generators/admin/index.js +219 -0
  197. package/dist/generators/admin/mutations.d.ts +23 -0
  198. package/dist/generators/admin/mutations.d.ts.map +1 -0
  199. package/dist/generators/admin/mutations.js +424 -0
  200. package/dist/generators/admin/queries.d.ts +20 -0
  201. package/dist/generators/admin/queries.d.ts.map +1 -0
  202. package/dist/generators/admin/queries.js +476 -0
  203. package/dist/generators/admin/types.d.ts +28 -0
  204. package/dist/generators/admin/types.d.ts.map +1 -0
  205. package/dist/generators/admin/types.js +254 -0
  206. package/dist/generators/cms/index.d.ts +29 -0
  207. package/dist/generators/cms/index.d.ts.map +1 -0
  208. package/dist/generators/cms/index.js +126 -0
  209. package/dist/generators/cms/route.d.ts +27 -0
  210. package/dist/generators/cms/route.d.ts.map +1 -0
  211. package/dist/generators/cms/route.js +409 -0
  212. package/dist/generators/cms/types.d.ts +15 -0
  213. package/dist/generators/cms/types.d.ts.map +1 -0
  214. package/dist/generators/cms/types.js +137 -0
  215. package/dist/generators/contexts/index.d.ts +25 -0
  216. package/dist/generators/contexts/index.d.ts.map +1 -0
  217. package/dist/generators/contexts/index.js +591 -0
  218. package/dist/generators/documents/data-models.d.ts +6 -0
  219. package/dist/generators/documents/data-models.d.ts.map +1 -0
  220. package/dist/generators/documents/data-models.js +61 -0
  221. package/dist/generators/documents/entity-models.d.ts +7 -0
  222. package/dist/generators/documents/entity-models.d.ts.map +1 -0
  223. package/dist/generators/documents/entity-models.js +87 -0
  224. package/dist/generators/documents/workflows.d.ts +11 -0
  225. package/dist/generators/documents/workflows.d.ts.map +1 -0
  226. package/dist/generators/documents/workflows.js +101 -0
  227. package/dist/generators/filters/index.d.ts +16 -0
  228. package/dist/generators/filters/index.d.ts.map +1 -0
  229. package/dist/generators/filters/index.js +384 -0
  230. package/dist/generators/hooks/agnostic.d.ts +16 -0
  231. package/dist/generators/hooks/agnostic.d.ts.map +1 -0
  232. package/dist/generators/hooks/agnostic.js +248 -0
  233. package/dist/generators/hooks/index.d.ts +9 -0
  234. package/dist/generators/hooks/index.d.ts.map +1 -0
  235. package/dist/generators/hooks/index.js +8 -0
  236. package/dist/generators/hooks/react.d.ts +16 -0
  237. package/dist/generators/hooks/react.d.ts.map +1 -0
  238. package/dist/generators/hooks/react.js +394 -0
  239. package/dist/generators/hooks/remix.d.ts +16 -0
  240. package/dist/generators/hooks/remix.d.ts.map +1 -0
  241. package/dist/generators/hooks/remix.js +349 -0
  242. package/dist/generators/hooks/workflows.d.ts +23 -0
  243. package/dist/generators/hooks/workflows.d.ts.map +1 -0
  244. package/dist/generators/hooks/workflows.js +312 -0
  245. package/dist/generators/resolve/index.d.ts +13 -0
  246. package/dist/generators/resolve/index.d.ts.map +1 -0
  247. package/dist/generators/resolve/index.js +13 -0
  248. package/dist/generators/resolve/platform.d.ts +29 -0
  249. package/dist/generators/resolve/platform.d.ts.map +1 -0
  250. package/dist/generators/resolve/platform.js +479 -0
  251. package/dist/generators/types/config.d.ts +7 -0
  252. package/dist/generators/types/config.d.ts.map +1 -0
  253. package/dist/generators/types/config.js +113 -0
  254. package/dist/generators/types/data-models.d.ts +10 -0
  255. package/dist/generators/types/data-models.d.ts.map +1 -0
  256. package/dist/generators/types/data-models.js +100 -0
  257. package/dist/generators/types/entity-models.d.ts +13 -0
  258. package/dist/generators/types/entity-models.d.ts.map +1 -0
  259. package/dist/generators/types/entity-models.js +241 -0
  260. package/dist/generators/types/field-types.d.ts +9 -0
  261. package/dist/generators/types/field-types.d.ts.map +1 -0
  262. package/dist/generators/types/field-types.js +651 -0
  263. package/dist/generators/types/hooks.d.ts +7 -0
  264. package/dist/generators/types/hooks.d.ts.map +1 -0
  265. package/dist/generators/types/hooks.js +132 -0
  266. package/dist/generators/types/scalars.d.ts +6 -0
  267. package/dist/generators/types/scalars.d.ts.map +1 -0
  268. package/dist/generators/types/scalars.js +68 -0
  269. package/dist/generators/types/user-details.d.ts +6 -0
  270. package/dist/generators/types/user-details.d.ts.map +1 -0
  271. package/dist/generators/types/user-details.js +60 -0
  272. package/dist/generators/types/workflows.d.ts +15 -0
  273. package/dist/generators/types/workflows.d.ts.map +1 -0
  274. package/dist/generators/types/workflows.js +163 -0
  275. package/dist/graphql/generated/gql.d.ts +47 -0
  276. package/dist/graphql/generated/gql.d.ts.map +1 -0
  277. package/dist/graphql/generated/gql.js +10 -0
  278. package/dist/graphql/generated/graphql.d.ts +8455 -0
  279. package/dist/graphql/generated/graphql.d.ts.map +1 -0
  280. package/dist/graphql/generated/graphql.js +573 -0
  281. package/dist/graphql/generated/index.d.ts +2 -0
  282. package/dist/graphql/generated/index.d.ts.map +1 -0
  283. package/dist/graphql/generated/index.js +1 -0
  284. package/dist/index.d.ts +13 -0
  285. package/dist/index.d.ts.map +1 -0
  286. package/dist/index.js +9 -0
  287. package/dist/schema/define-entity-model.d.ts +122 -0
  288. package/dist/schema/define-entity-model.d.ts.map +1 -0
  289. package/dist/schema/define-entity-model.js +59 -0
  290. package/dist/schema/schema-loader.d.ts +10 -0
  291. package/dist/schema/schema-loader.d.ts.map +1 -0
  292. package/dist/schema/schema-loader.js +91 -0
  293. package/dist/utils/field-mapping.d.ts +83 -0
  294. package/dist/utils/field-mapping.d.ts.map +1 -0
  295. package/dist/utils/field-mapping.js +334 -0
  296. package/dist/writer/write-files.d.ts +12 -0
  297. package/dist/writer/write-files.d.ts.map +1 -0
  298. package/dist/writer/write-files.js +35 -0
  299. package/package.json +70 -0
@@ -0,0 +1,219 @@
1
+ /**
2
+ * Admin Generator
3
+ *
4
+ * Generates typed hooks/functions for the administration layer:
5
+ * - CRUD operations for managing content
6
+ * - Versioning operations (save, publish, revert)
7
+ * - Building custom admin UIs
8
+ *
9
+ * @generated by UniformGen
10
+ */
11
+ import { toPascalCase } from '../../utils/field-mapping.js';
12
+ import { generateAdminTypes, isInlineOnlyModel } from './types.js';
13
+ import { generateAdminQueriesReact, generateAdminQueriesRemix } from './queries.js';
14
+ import { generateAdminMutationsReact, generateAdminMutationsRemix } from './mutations.js';
15
+ export { generateAdminTypes, generateAdminTypesIndex, isInlineOnlyModel } from './types.js';
16
+ export { generateAdminQueriesReact, generateAdminQueriesRemix } from './queries.js';
17
+ export { generateAdminMutationsReact, generateAdminMutationsRemix } from './mutations.js';
18
+ /**
19
+ * Generate combined React admin hooks file for a model
20
+ * Combines queries and mutations into a single file per model
21
+ */
22
+ export function generateAdminHooksReact(model, allModels) {
23
+ if (isInlineOnlyModel(model)) {
24
+ return '';
25
+ }
26
+ const typeName = toPascalCase(model.key);
27
+ const dataTypeName = `${typeName}Data`;
28
+ const lines = [];
29
+ // File header
30
+ lines.push(`/**`);
31
+ lines.push(` * ${model.name} - Admin Hooks`);
32
+ lines.push(` *`);
33
+ lines.push(` * React hooks for administration layer (CRUD, versioning).`);
34
+ lines.push(` *`);
35
+ lines.push(` * @generated by UniformGen - DO NOT EDIT MANUALLY`);
36
+ lines.push(` */`);
37
+ lines.push('');
38
+ // Imports
39
+ lines.push(`import { useQuery, useMutation, type QueryHookOptions, type MutationHookOptions } from '@apollo/client';`);
40
+ lines.push(`import { gql } from '@apollo/client';`);
41
+ lines.push(`import type { ${dataTypeName} } from '../../types/models/${model.key}.js';`);
42
+ lines.push('');
43
+ // Inline the types from types.ts content
44
+ const typesContent = generateAdminTypes(model, allModels);
45
+ // Extract just the interface definitions (skip the header and imports)
46
+ const typesLines = typesContent.split('\n');
47
+ const startIndex = typesLines.findIndex(line => line.startsWith('/** Typed metadata') || line.startsWith('/** '));
48
+ if (startIndex > 0) {
49
+ lines.push(...typesLines.slice(startIndex));
50
+ lines.push('');
51
+ }
52
+ // Inline queries content (skip header and imports)
53
+ const queriesContent = generateAdminQueriesReact(model, allModels);
54
+ const queriesLines = queriesContent.split('\n');
55
+ const queriesStartIndex = queriesLines.findIndex(line => line.startsWith('/** List result'));
56
+ if (queriesStartIndex > 0) {
57
+ lines.push(...queriesLines.slice(queriesStartIndex));
58
+ lines.push('');
59
+ }
60
+ // Inline mutations content (skip header and imports)
61
+ const mutationsContent = generateAdminMutationsReact(model, allModels);
62
+ const mutationsLines = mutationsContent.split('\n');
63
+ const mutationsStartIndex = mutationsLines.findIndex(line => line.includes('GraphQL Mutations'));
64
+ if (mutationsStartIndex > 0) {
65
+ lines.push(...mutationsLines.slice(mutationsStartIndex));
66
+ }
67
+ return lines.join('\n') + '\n';
68
+ }
69
+ /**
70
+ * Generate combined Remix/Hydrogen admin functions file for a model
71
+ */
72
+ export function generateAdminHooksRemix(model, allModels) {
73
+ if (isInlineOnlyModel(model)) {
74
+ return '';
75
+ }
76
+ const typeName = toPascalCase(model.key);
77
+ const dataTypeName = `${typeName}Data`;
78
+ const lines = [];
79
+ // File header
80
+ lines.push(`/**`);
81
+ lines.push(` * ${model.name} - Admin Functions`);
82
+ lines.push(` *`);
83
+ lines.push(` * Server-side functions for administration layer (CRUD, versioning).`);
84
+ lines.push(` * Use in Remix loaders/actions or Hydrogen server functions.`);
85
+ lines.push(` *`);
86
+ lines.push(` * @generated by UniformGen - DO NOT EDIT MANUALLY`);
87
+ lines.push(` */`);
88
+ lines.push('');
89
+ // Imports
90
+ lines.push(`import type { ${dataTypeName} } from '../../types/models/${model.key}.js';`);
91
+ lines.push('');
92
+ // GraphQL client interface
93
+ lines.push(`/** GraphQL client interface */`);
94
+ lines.push(`export interface GraphQLClient {`);
95
+ lines.push(` request<T>(query: string, variables?: Record<string, unknown>): Promise<T>;`);
96
+ lines.push(`}`);
97
+ lines.push('');
98
+ // Inline types
99
+ const typesContent = generateAdminTypes(model, allModels);
100
+ const typesLines = typesContent.split('\n');
101
+ const startIndex = typesLines.findIndex(line => line.startsWith('/** Typed metadata') || line.startsWith('/** '));
102
+ if (startIndex > 0) {
103
+ lines.push(...typesLines.slice(startIndex));
104
+ lines.push('');
105
+ }
106
+ // Inline queries content
107
+ const queriesContent = generateAdminQueriesRemix(model, allModels);
108
+ const queriesLines = queriesContent.split('\n');
109
+ const queriesStartIndex = queriesLines.findIndex(line => line.startsWith('/** List result'));
110
+ if (queriesStartIndex > 0) {
111
+ lines.push(...queriesLines.slice(queriesStartIndex));
112
+ lines.push('');
113
+ }
114
+ // Inline mutations content
115
+ const mutationsContent = generateAdminMutationsRemix(model, allModels);
116
+ const mutationsLines = mutationsContent.split('\n');
117
+ const mutationsStartIndex = mutationsLines.findIndex(line => line.includes('GraphQL Mutations'));
118
+ if (mutationsStartIndex > 0) {
119
+ lines.push(...mutationsLines.slice(mutationsStartIndex));
120
+ }
121
+ return lines.join('\n') + '\n';
122
+ }
123
+ /**
124
+ * Generate index file for admin hooks (React)
125
+ */
126
+ export function generateAdminHooksIndexReact(models) {
127
+ const recordModels = models.filter((m) => m.modes.records && m.modes.publicApi);
128
+ let indexCode = `/**
129
+ * Admin Hooks
130
+ *
131
+ * React hooks for administration layer (CRUD, versioning).
132
+ *
133
+ * @generated by UniformGen - DO NOT EDIT MANUALLY
134
+ */\n\n`;
135
+ for (const model of recordModels) {
136
+ const typeName = toPascalCase(model.key);
137
+ const hasMetadata = model.metadataSchema?.fields && model.metadataSchema.fields.length > 0;
138
+ indexCode += `// ${model.name}\n`;
139
+ indexCode += `export {\n`;
140
+ // Types
141
+ indexCode += ` type ${typeName}Record,\n`;
142
+ indexCode += ` type ${typeName}RecordWithVariants,\n`;
143
+ indexCode += ` type ${typeName}Variant,\n`;
144
+ indexCode += ` type ${typeName}Version,\n`;
145
+ indexCode += ` type ${typeName}FilterInput,\n`;
146
+ indexCode += ` type ${typeName}ListResult,\n`;
147
+ indexCode += ` type Create${typeName}Input,\n`;
148
+ indexCode += ` type Update${typeName}Input,\n`;
149
+ indexCode += ` type Save${typeName}ContentInput,\n`;
150
+ indexCode += ` type Save${typeName}ContentResult,\n`;
151
+ if (hasMetadata) {
152
+ indexCode += ` type ${typeName}Metadata,\n`;
153
+ }
154
+ // Query hooks
155
+ indexCode += ` use${typeName}Records,\n`;
156
+ indexCode += ` use${typeName}Record,\n`;
157
+ indexCode += ` use${typeName}Versions,\n`;
158
+ // Mutation hooks
159
+ indexCode += ` useCreate${typeName}Record,\n`;
160
+ indexCode += ` useUpdate${typeName}Record,\n`;
161
+ indexCode += ` useDelete${typeName}Record,\n`;
162
+ indexCode += ` useSave${typeName}Content,\n`;
163
+ indexCode += ` usePublish${typeName}Version,\n`;
164
+ indexCode += ` useRevert${typeName}Version,\n`;
165
+ indexCode += `} from './${model.key}.js';\n\n`;
166
+ }
167
+ return indexCode;
168
+ }
169
+ /**
170
+ * Generate index file for admin functions (Remix)
171
+ */
172
+ export function generateAdminHooksIndexRemix(models) {
173
+ const recordModels = models.filter((m) => m.modes.records && m.modes.publicApi);
174
+ let indexCode = `/**
175
+ * Admin Functions
176
+ *
177
+ * Server-side functions for administration layer (CRUD, versioning).
178
+ *
179
+ * @generated by UniformGen - DO NOT EDIT MANUALLY
180
+ */\n\n`;
181
+ // Export GraphQL client type from first model
182
+ const firstModel = recordModels[0];
183
+ if (firstModel) {
184
+ indexCode += `export type { GraphQLClient } from './${firstModel.key}.js';\n\n`;
185
+ }
186
+ for (const model of recordModels) {
187
+ const typeName = toPascalCase(model.key);
188
+ const hasMetadata = model.metadataSchema?.fields && model.metadataSchema.fields.length > 0;
189
+ indexCode += `// ${model.name}\n`;
190
+ indexCode += `export {\n`;
191
+ // Types
192
+ indexCode += ` type ${typeName}Record,\n`;
193
+ indexCode += ` type ${typeName}RecordWithVariants,\n`;
194
+ indexCode += ` type ${typeName}Variant,\n`;
195
+ indexCode += ` type ${typeName}Version,\n`;
196
+ indexCode += ` type ${typeName}FilterInput,\n`;
197
+ indexCode += ` type ${typeName}ListResult,\n`;
198
+ indexCode += ` type Create${typeName}Input,\n`;
199
+ indexCode += ` type Update${typeName}Input,\n`;
200
+ indexCode += ` type Save${typeName}ContentInput,\n`;
201
+ indexCode += ` type Save${typeName}ContentResult,\n`;
202
+ if (hasMetadata) {
203
+ indexCode += ` type ${typeName}Metadata,\n`;
204
+ }
205
+ // Query functions
206
+ indexCode += ` list${typeName}Records,\n`;
207
+ indexCode += ` get${typeName}Record,\n`;
208
+ indexCode += ` get${typeName}Versions,\n`;
209
+ // Mutation functions
210
+ indexCode += ` create${typeName}Record,\n`;
211
+ indexCode += ` update${typeName}Record,\n`;
212
+ indexCode += ` delete${typeName}Record,\n`;
213
+ indexCode += ` save${typeName}Content,\n`;
214
+ indexCode += ` publish${typeName}Version,\n`;
215
+ indexCode += ` revert${typeName}Version,\n`;
216
+ indexCode += `} from './${model.key}.js';\n\n`;
217
+ }
218
+ return indexCode;
219
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Admin Mutations Generator
3
+ *
4
+ * Generates typed React hooks for administration layer mutations:
5
+ * - useCreate{Model}Record - Create new record
6
+ * - useUpdate{Model}Record - Update record metadata
7
+ * - useDelete{Model}Record - Delete record
8
+ * - useSave{Model}Content - Save content (creates version)
9
+ * - usePublish{Model}Version - Publish a version
10
+ * - useRevert{Model}Version - Revert to a previous version
11
+ *
12
+ * @generated by UniformGen
13
+ */
14
+ import type { EntityModel } from '../../fetcher/fetch-schemas.js';
15
+ /**
16
+ * Generate React admin mutation hooks for a model
17
+ */
18
+ export declare function generateAdminMutationsReact(model: EntityModel, _allModels: EntityModel[]): string;
19
+ /**
20
+ * Generate Remix/Hydrogen admin mutation functions for a model
21
+ */
22
+ export declare function generateAdminMutationsRemix(model: EntityModel, _allModels: EntityModel[]): string;
23
+ //# sourceMappingURL=mutations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mutations.d.ts","sourceRoot":"","sources":["../../../src/generators/admin/mutations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAIlE;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,WAAW,EAClB,UAAU,EAAE,WAAW,EAAE,GACxB,MAAM,CAsUR;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,KAAK,EAAE,WAAW,EAClB,UAAU,EAAE,WAAW,EAAE,GACxB,MAAM,CA8GR"}
@@ -0,0 +1,424 @@
1
+ /**
2
+ * Admin Mutations Generator
3
+ *
4
+ * Generates typed React hooks for administration layer mutations:
5
+ * - useCreate{Model}Record - Create new record
6
+ * - useUpdate{Model}Record - Update record metadata
7
+ * - useDelete{Model}Record - Delete record
8
+ * - useSave{Model}Content - Save content (creates version)
9
+ * - usePublish{Model}Version - Publish a version
10
+ * - useRevert{Model}Version - Revert to a previous version
11
+ *
12
+ * @generated by UniformGen
13
+ */
14
+ import { toPascalCase } from '../../utils/field-mapping.js';
15
+ import { isInlineOnlyModel } from './types.js';
16
+ /**
17
+ * Generate React admin mutation hooks for a model
18
+ */
19
+ export function generateAdminMutationsReact(model, _allModels) {
20
+ if (isInlineOnlyModel(model)) {
21
+ return '';
22
+ }
23
+ const typeName = toPascalCase(model.key);
24
+ const lines = [];
25
+ // File header
26
+ lines.push(`/**`);
27
+ lines.push(` * ${model.name} - Admin Mutation Hooks`);
28
+ lines.push(` *`);
29
+ lines.push(` * React hooks for managing ${model.name} records in admin UIs.`);
30
+ lines.push(` *`);
31
+ lines.push(` * @generated by UniformGen - DO NOT EDIT MANUALLY`);
32
+ lines.push(` */`);
33
+ lines.push('');
34
+ // Imports
35
+ lines.push(`import { useMutation, type MutationHookOptions } from '@apollo/client';`);
36
+ lines.push(`import { gql } from '@apollo/client';`);
37
+ lines.push(`import type {`);
38
+ lines.push(` ${typeName}Record,`);
39
+ lines.push(` ${typeName}Variant,`);
40
+ lines.push(` ${typeName}Version,`);
41
+ lines.push(` Create${typeName}Input,`);
42
+ lines.push(` Update${typeName}Input,`);
43
+ lines.push(` Save${typeName}ContentInput,`);
44
+ lines.push(` Save${typeName}ContentResult,`);
45
+ lines.push(`} from './types/${model.key}.js';`);
46
+ lines.push('');
47
+ // Re-export types
48
+ lines.push(`// Re-export types for convenience`);
49
+ lines.push(`export type {`);
50
+ lines.push(` Create${typeName}Input,`);
51
+ lines.push(` Update${typeName}Input,`);
52
+ lines.push(` Save${typeName}ContentInput,`);
53
+ lines.push(` Save${typeName}ContentResult,`);
54
+ lines.push(`} from './types/${model.key}.js';`);
55
+ lines.push('');
56
+ // GraphQL Mutations
57
+ lines.push(`// ============================================================================`);
58
+ lines.push(`// GraphQL Mutations`);
59
+ lines.push(`// ============================================================================`);
60
+ lines.push('');
61
+ // Create record mutation
62
+ lines.push(`const CREATE_${typeName.toUpperCase()}_RECORD = gql\``);
63
+ lines.push(` mutation Create${typeName}Record($input: CreateEntityRecordInput!) {`);
64
+ lines.push(` createEntityRecord(input: $input) {`);
65
+ lines.push(` id`);
66
+ lines.push(` naturalKey`);
67
+ lines.push(` metadata`);
68
+ lines.push(` status`);
69
+ lines.push(` createdAt`);
70
+ lines.push(` updatedAt`);
71
+ lines.push(` currentVersion {`);
72
+ lines.push(` versionNumber`);
73
+ lines.push(` content`);
74
+ lines.push(` }`);
75
+ lines.push(` }`);
76
+ lines.push(` }`);
77
+ lines.push(`\`;`);
78
+ lines.push('');
79
+ // Update record mutation
80
+ lines.push(`const UPDATE_${typeName.toUpperCase()}_RECORD = gql\``);
81
+ lines.push(` mutation Update${typeName}Record($id: ID!, $input: UpdateEntityRecordInput!) {`);
82
+ lines.push(` updateEntityRecord(id: $id, input: $input) {`);
83
+ lines.push(` id`);
84
+ lines.push(` naturalKey`);
85
+ lines.push(` metadata`);
86
+ lines.push(` status`);
87
+ lines.push(` updatedAt`);
88
+ lines.push(` }`);
89
+ lines.push(` }`);
90
+ lines.push(`\`;`);
91
+ lines.push('');
92
+ // Delete record mutation
93
+ lines.push(`const DELETE_${typeName.toUpperCase()}_RECORD = gql\``);
94
+ lines.push(` mutation Delete${typeName}Record($id: ID!) {`);
95
+ lines.push(` deleteEntityRecord(id: $id) {`);
96
+ lines.push(` success`);
97
+ lines.push(` message`);
98
+ lines.push(` }`);
99
+ lines.push(` }`);
100
+ lines.push(`\`;`);
101
+ lines.push('');
102
+ // Save content mutation (creates version)
103
+ lines.push(`const SAVE_${typeName.toUpperCase()}_CONTENT = gql\``);
104
+ lines.push(` mutation Save${typeName}Content($input: SaveContentInput!) {`);
105
+ lines.push(` saveContent(input: $input) {`);
106
+ lines.push(` variantId`);
107
+ lines.push(` versionId`);
108
+ lines.push(` versionNumber`);
109
+ lines.push(` }`);
110
+ lines.push(` }`);
111
+ lines.push(`\`;`);
112
+ lines.push('');
113
+ // Publish version mutation
114
+ lines.push(`const PUBLISH_${typeName.toUpperCase()}_VERSION = gql\``);
115
+ lines.push(` mutation Publish${typeName}Version($versionId: ID!) {`);
116
+ lines.push(` publishVersion(versionId: $versionId) {`);
117
+ lines.push(` id`);
118
+ lines.push(` variantKey`);
119
+ lines.push(` catalogKey`);
120
+ lines.push(` publishedVersion {`);
121
+ lines.push(` id`);
122
+ lines.push(` versionNumber`);
123
+ lines.push(` content`);
124
+ lines.push(` isPublished`);
125
+ lines.push(` }`);
126
+ lines.push(` }`);
127
+ lines.push(` }`);
128
+ lines.push(`\`;`);
129
+ lines.push('');
130
+ // Revert version mutation
131
+ lines.push(`const REVERT_${typeName.toUpperCase()}_VERSION = gql\``);
132
+ lines.push(` mutation Revert${typeName}Version($versionId: ID!) {`);
133
+ lines.push(` revertToVersion(versionId: $versionId) {`);
134
+ lines.push(` id`);
135
+ lines.push(` variantId`);
136
+ lines.push(` versionNumber`);
137
+ lines.push(` content`);
138
+ lines.push(` isPublished`);
139
+ lines.push(` createdAt`);
140
+ lines.push(` }`);
141
+ lines.push(` }`);
142
+ lines.push(`\`;`);
143
+ lines.push('');
144
+ // Mutation Hooks
145
+ lines.push(`// ============================================================================`);
146
+ lines.push(`// Mutation Hooks`);
147
+ lines.push(`// ============================================================================`);
148
+ lines.push('');
149
+ // useCreate{Model}Record
150
+ lines.push(`/**`);
151
+ lines.push(` * Create a new ${model.name} record`);
152
+ lines.push(` *`);
153
+ lines.push(` * @example`);
154
+ lines.push(` * const { create, loading, error } = useCreate${typeName}Record();`);
155
+ lines.push(` * const record = await create({ data: { title: 'New Record' } });`);
156
+ lines.push(` */`);
157
+ lines.push(`export function useCreate${typeName}Record(options?: MutationHookOptions) {`);
158
+ lines.push(` const [mutate, result] = useMutation(CREATE_${typeName.toUpperCase()}_RECORD, options);`);
159
+ lines.push('');
160
+ lines.push(` const create = async (input: Create${typeName}Input): Promise<${typeName}Record> => {`);
161
+ lines.push(` const response = await mutate({`);
162
+ lines.push(` variables: {`);
163
+ lines.push(` input: {`);
164
+ lines.push(` modelKey: '${model.key}',`);
165
+ lines.push(` naturalKey: input.naturalKey,`);
166
+ lines.push(` data: input.data,`);
167
+ lines.push(` metadata: input.metadata,`);
168
+ lines.push(` },`);
169
+ lines.push(` },`);
170
+ lines.push(` });`);
171
+ lines.push(` const entity = response.data?.createEntityRecord;`);
172
+ lines.push(` return {`);
173
+ lines.push(` id: entity.id,`);
174
+ lines.push(` modelKey: '${model.key}',`);
175
+ lines.push(` naturalKey: entity.naturalKey,`);
176
+ lines.push(` data: entity.currentVersion?.content,`);
177
+ lines.push(` metadata: entity.metadata,`);
178
+ lines.push(` versionNumber: entity.currentVersion?.versionNumber ?? 1,`);
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(` return { create, ...result };`);
186
+ lines.push(`}`);
187
+ lines.push('');
188
+ // useUpdate{Model}Record
189
+ lines.push(`/**`);
190
+ lines.push(` * Update a ${model.name} record's metadata (not content)`);
191
+ lines.push(` *`);
192
+ lines.push(` * @example`);
193
+ lines.push(` * const { update, loading } = useUpdate${typeName}Record();`);
194
+ lines.push(` * await update('record-id', { metadata: { featured: true } });`);
195
+ lines.push(` */`);
196
+ lines.push(`export function useUpdate${typeName}Record(options?: MutationHookOptions) {`);
197
+ lines.push(` const [mutate, result] = useMutation(UPDATE_${typeName.toUpperCase()}_RECORD, options);`);
198
+ lines.push('');
199
+ lines.push(` const update = async (id: string, input: Update${typeName}Input): Promise<${typeName}Record> => {`);
200
+ lines.push(` const response = await mutate({`);
201
+ lines.push(` variables: { id, input },`);
202
+ lines.push(` });`);
203
+ lines.push(` const entity = response.data?.updateEntityRecord;`);
204
+ lines.push(` return {`);
205
+ lines.push(` id: entity.id,`);
206
+ lines.push(` modelKey: '${model.key}',`);
207
+ lines.push(` naturalKey: entity.naturalKey,`);
208
+ lines.push(` data: {} as any, // Partial update doesn't return full data`);
209
+ lines.push(` metadata: entity.metadata,`);
210
+ lines.push(` versionNumber: 0,`);
211
+ lines.push(` status: entity.status,`);
212
+ lines.push(` createdAt: '',`);
213
+ lines.push(` updatedAt: entity.updatedAt,`);
214
+ lines.push(` };`);
215
+ lines.push(` };`);
216
+ lines.push('');
217
+ lines.push(` return { update, ...result };`);
218
+ lines.push(`}`);
219
+ lines.push('');
220
+ // useDelete{Model}Record
221
+ lines.push(`/**`);
222
+ lines.push(` * Delete a ${model.name} record (soft delete)`);
223
+ lines.push(` *`);
224
+ lines.push(` * @example`);
225
+ lines.push(` * const { remove, loading } = useDelete${typeName}Record();`);
226
+ lines.push(` * await remove('record-id');`);
227
+ lines.push(` */`);
228
+ lines.push(`export function useDelete${typeName}Record(options?: MutationHookOptions) {`);
229
+ lines.push(` const [mutate, result] = useMutation(DELETE_${typeName.toUpperCase()}_RECORD, options);`);
230
+ lines.push('');
231
+ lines.push(` const remove = async (id: string): Promise<boolean> => {`);
232
+ lines.push(` const response = await mutate({ variables: { id } });`);
233
+ lines.push(` return response.data?.deleteEntityRecord?.success ?? false;`);
234
+ lines.push(` };`);
235
+ lines.push('');
236
+ lines.push(` return { remove, ...result };`);
237
+ lines.push(`}`);
238
+ lines.push('');
239
+ // useSave{Model}Content
240
+ lines.push(`/**`);
241
+ lines.push(` * Save ${model.name} content (creates a new version)`);
242
+ lines.push(` *`);
243
+ lines.push(` * @example`);
244
+ lines.push(` * const { save, loading } = useSave${typeName}Content();`);
245
+ lines.push(` * const result = await save({ variantId: 'v-id', content: { ... } });`);
246
+ lines.push(` */`);
247
+ lines.push(`export function useSave${typeName}Content(options?: MutationHookOptions) {`);
248
+ lines.push(` const [mutate, result] = useMutation(SAVE_${typeName.toUpperCase()}_CONTENT, options);`);
249
+ lines.push('');
250
+ lines.push(` const save = async (input: Save${typeName}ContentInput): Promise<Save${typeName}ContentResult> => {`);
251
+ lines.push(` const response = await mutate({`);
252
+ lines.push(` variables: { input },`);
253
+ lines.push(` });`);
254
+ lines.push(` const data = response.data?.saveContent;`);
255
+ lines.push(` return {`);
256
+ lines.push(` variantId: data.variantId,`);
257
+ lines.push(` versionId: data.versionId,`);
258
+ lines.push(` versionNumber: data.versionNumber,`);
259
+ lines.push(` };`);
260
+ lines.push(` };`);
261
+ lines.push('');
262
+ lines.push(` return { save, ...result };`);
263
+ lines.push(`}`);
264
+ lines.push('');
265
+ // usePublish{Model}Version
266
+ lines.push(`/**`);
267
+ lines.push(` * Publish a ${model.name} version`);
268
+ lines.push(` *`);
269
+ lines.push(` * @example`);
270
+ lines.push(` * const { publish, loading } = usePublish${typeName}Version();`);
271
+ lines.push(` * const variant = await publish('version-id');`);
272
+ lines.push(` */`);
273
+ lines.push(`export function usePublish${typeName}Version(options?: MutationHookOptions) {`);
274
+ lines.push(` const [mutate, result] = useMutation(PUBLISH_${typeName.toUpperCase()}_VERSION, options);`);
275
+ lines.push('');
276
+ lines.push(` const publish = async (versionId: string): Promise<${typeName}Variant> => {`);
277
+ lines.push(` const response = await mutate({ variables: { versionId } });`);
278
+ lines.push(` const v = response.data?.publishVersion;`);
279
+ lines.push(` return {`);
280
+ lines.push(` id: v.id,`);
281
+ lines.push(` variantKey: v.variantKey,`);
282
+ lines.push(` catalogKey: v.catalogKey,`);
283
+ lines.push(` publishedVersion: v.publishedVersion ? {`);
284
+ lines.push(` id: v.publishedVersion.id,`);
285
+ lines.push(` variantId: v.id,`);
286
+ lines.push(` versionNumber: v.publishedVersion.versionNumber,`);
287
+ lines.push(` content: v.publishedVersion.content,`);
288
+ lines.push(` isPublished: v.publishedVersion.isPublished,`);
289
+ lines.push(` createdAt: '',`);
290
+ lines.push(` } : undefined,`);
291
+ lines.push(` versionCount: 0,`);
292
+ lines.push(` };`);
293
+ lines.push(` };`);
294
+ lines.push('');
295
+ lines.push(` return { publish, ...result };`);
296
+ lines.push(`}`);
297
+ lines.push('');
298
+ // useRevert{Model}Version
299
+ lines.push(`/**`);
300
+ lines.push(` * Revert to a previous ${model.name} version`);
301
+ lines.push(` *`);
302
+ lines.push(` * @example`);
303
+ lines.push(` * const { revert, loading } = useRevert${typeName}Version();`);
304
+ lines.push(` * const newVersion = await revert('version-id');`);
305
+ lines.push(` */`);
306
+ lines.push(`export function useRevert${typeName}Version(options?: MutationHookOptions) {`);
307
+ lines.push(` const [mutate, result] = useMutation(REVERT_${typeName.toUpperCase()}_VERSION, options);`);
308
+ lines.push('');
309
+ lines.push(` const revert = async (versionId: string): Promise<${typeName}Version> => {`);
310
+ lines.push(` const response = await mutate({ variables: { versionId } });`);
311
+ lines.push(` const v = response.data?.revertToVersion;`);
312
+ lines.push(` return {`);
313
+ lines.push(` id: v.id,`);
314
+ lines.push(` variantId: v.variantId,`);
315
+ lines.push(` versionNumber: v.versionNumber,`);
316
+ lines.push(` content: v.content,`);
317
+ lines.push(` isPublished: v.isPublished,`);
318
+ lines.push(` createdAt: v.createdAt,`);
319
+ lines.push(` };`);
320
+ lines.push(` };`);
321
+ lines.push('');
322
+ lines.push(` return { revert, ...result };`);
323
+ lines.push(`}`);
324
+ return lines.join('\n') + '\n';
325
+ }
326
+ /**
327
+ * Generate Remix/Hydrogen admin mutation functions for a model
328
+ */
329
+ export function generateAdminMutationsRemix(model, _allModels) {
330
+ if (isInlineOnlyModel(model)) {
331
+ return '';
332
+ }
333
+ const typeName = toPascalCase(model.key);
334
+ const lines = [];
335
+ // File header
336
+ lines.push(`/**`);
337
+ lines.push(` * ${model.name} - Admin Mutation Functions`);
338
+ lines.push(` *`);
339
+ lines.push(` * Server-side functions for managing ${model.name} records.`);
340
+ lines.push(` * Use in Remix actions or Hydrogen server functions.`);
341
+ lines.push(` *`);
342
+ lines.push(` * @generated by UniformGen - DO NOT EDIT MANUALLY`);
343
+ lines.push(` */`);
344
+ lines.push('');
345
+ // Imports
346
+ lines.push(`import type {`);
347
+ lines.push(` ${typeName}Record,`);
348
+ lines.push(` ${typeName}Variant,`);
349
+ lines.push(` ${typeName}Version,`);
350
+ lines.push(` Create${typeName}Input,`);
351
+ lines.push(` Update${typeName}Input,`);
352
+ lines.push(` Save${typeName}ContentInput,`);
353
+ lines.push(` Save${typeName}ContentResult,`);
354
+ lines.push(`} from './types/${model.key}.js';`);
355
+ lines.push('');
356
+ // Re-export types
357
+ lines.push(`export type {`);
358
+ lines.push(` Create${typeName}Input,`);
359
+ lines.push(` Update${typeName}Input,`);
360
+ lines.push(` Save${typeName}ContentInput,`);
361
+ lines.push(` Save${typeName}ContentResult,`);
362
+ lines.push(`} from './types/${model.key}.js';`);
363
+ lines.push('');
364
+ // GraphQL client interface
365
+ lines.push(`/** GraphQL client interface */`);
366
+ lines.push(`export interface GraphQLClient {`);
367
+ lines.push(` request<T>(query: string, variables?: Record<string, unknown>): Promise<T>;`);
368
+ lines.push(`}`);
369
+ lines.push('');
370
+ // GraphQL Mutations (as strings)
371
+ lines.push(`// GraphQL Mutations`);
372
+ lines.push(`const CREATE_${typeName.toUpperCase()}_RECORD = \`mutation Create${typeName}Record($input: CreateEntityRecordInput!) { createEntityRecord(input: $input) { id naturalKey metadata status createdAt updatedAt currentVersion { versionNumber content } } }\`;`);
373
+ lines.push(`const UPDATE_${typeName.toUpperCase()}_RECORD = \`mutation Update${typeName}Record($id: ID!, $input: UpdateEntityRecordInput!) { updateEntityRecord(id: $id, input: $input) { id naturalKey metadata status updatedAt } }\`;`);
374
+ lines.push(`const DELETE_${typeName.toUpperCase()}_RECORD = \`mutation Delete${typeName}Record($id: ID!) { deleteEntityRecord(id: $id) { success message } }\`;`);
375
+ lines.push(`const SAVE_${typeName.toUpperCase()}_CONTENT = \`mutation Save${typeName}Content($input: SaveContentInput!) { saveContent(input: $input) { variantId versionId versionNumber } }\`;`);
376
+ lines.push(`const PUBLISH_${typeName.toUpperCase()}_VERSION = \`mutation Publish${typeName}Version($versionId: ID!) { publishVersion(versionId: $versionId) { id variantKey catalogKey publishedVersion { id versionNumber content isPublished } } }\`;`);
377
+ lines.push(`const REVERT_${typeName.toUpperCase()}_VERSION = \`mutation Revert${typeName}Version($versionId: ID!) { revertToVersion(versionId: $versionId) { id variantId versionNumber content isPublished createdAt } }\`;`);
378
+ lines.push('');
379
+ // Server functions
380
+ lines.push(`// ============================================================================`);
381
+ lines.push(`// Mutation Functions`);
382
+ lines.push(`// ============================================================================`);
383
+ lines.push('');
384
+ lines.push(`/** Create a new ${model.name} record */`);
385
+ lines.push(`export async function create${typeName}Record(client: GraphQLClient, input: Create${typeName}Input): Promise<${typeName}Record> {`);
386
+ lines.push(` const response = await client.request<{ createEntityRecord: any }>(CREATE_${typeName.toUpperCase()}_RECORD, { input: { modelKey: '${model.key}', ...input } });`);
387
+ lines.push(` const e = response.createEntityRecord;`);
388
+ lines.push(` return { id: e.id, modelKey: '${model.key}', naturalKey: e.naturalKey, data: e.currentVersion?.content, metadata: e.metadata, versionNumber: e.currentVersion?.versionNumber ?? 1, status: e.status, createdAt: e.createdAt, updatedAt: e.updatedAt };`);
389
+ lines.push(`}`);
390
+ lines.push('');
391
+ lines.push(`/** Update a ${model.name} record's metadata */`);
392
+ lines.push(`export async function update${typeName}Record(client: GraphQLClient, id: string, input: Update${typeName}Input): Promise<${typeName}Record> {`);
393
+ lines.push(` const response = await client.request<{ updateEntityRecord: any }>(UPDATE_${typeName.toUpperCase()}_RECORD, { id, input });`);
394
+ lines.push(` const e = response.updateEntityRecord;`);
395
+ lines.push(` return { id: e.id, modelKey: '${model.key}', naturalKey: e.naturalKey, data: {} as any, metadata: e.metadata, versionNumber: 0, status: e.status, createdAt: '', updatedAt: e.updatedAt };`);
396
+ lines.push(`}`);
397
+ lines.push('');
398
+ lines.push(`/** Delete a ${model.name} record */`);
399
+ lines.push(`export async function delete${typeName}Record(client: GraphQLClient, id: string): Promise<boolean> {`);
400
+ lines.push(` const response = await client.request<{ deleteEntityRecord: { success: boolean } }>(DELETE_${typeName.toUpperCase()}_RECORD, { id });`);
401
+ lines.push(` return response.deleteEntityRecord?.success ?? false;`);
402
+ lines.push(`}`);
403
+ lines.push('');
404
+ lines.push(`/** Save ${model.name} content (creates a new version) */`);
405
+ lines.push(`export async function save${typeName}Content(client: GraphQLClient, input: Save${typeName}ContentInput): Promise<Save${typeName}ContentResult> {`);
406
+ lines.push(` const response = await client.request<{ saveContent: any }>(SAVE_${typeName.toUpperCase()}_CONTENT, { input });`);
407
+ lines.push(` return response.saveContent;`);
408
+ lines.push(`}`);
409
+ lines.push('');
410
+ lines.push(`/** Publish a ${model.name} version */`);
411
+ lines.push(`export async function publish${typeName}Version(client: GraphQLClient, versionId: string): Promise<${typeName}Variant> {`);
412
+ lines.push(` const response = await client.request<{ publishVersion: any }>(PUBLISH_${typeName.toUpperCase()}_VERSION, { versionId });`);
413
+ lines.push(` const v = response.publishVersion;`);
414
+ lines.push(` return { id: v.id, variantKey: v.variantKey, catalogKey: v.catalogKey, publishedVersion: v.publishedVersion ? { id: v.publishedVersion.id, variantId: v.id, versionNumber: v.publishedVersion.versionNumber, content: v.publishedVersion.content, isPublished: true, createdAt: '' } : undefined, versionCount: 0 };`);
415
+ lines.push(`}`);
416
+ lines.push('');
417
+ lines.push(`/** Revert to a previous ${model.name} version */`);
418
+ lines.push(`export async function revert${typeName}Version(client: GraphQLClient, versionId: string): Promise<${typeName}Version> {`);
419
+ lines.push(` const response = await client.request<{ revertToVersion: any }>(REVERT_${typeName.toUpperCase()}_VERSION, { versionId });`);
420
+ lines.push(` const v = response.revertToVersion;`);
421
+ lines.push(` return { id: v.id, variantId: v.variantId, versionNumber: v.versionNumber, content: v.content, isPublished: v.isPublished, createdAt: v.createdAt };`);
422
+ lines.push(`}`);
423
+ return lines.join('\n') + '\n';
424
+ }