@constructive-io/graphql-codegen 3.2.0 → 3.3.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 (216) hide show
  1. package/README.md +25 -30
  2. package/cli/index.js +36 -41
  3. package/cli/shared.d.ts +15 -17
  4. package/cli/shared.js +113 -21
  5. package/client/error.js +31 -9
  6. package/client/execute.js +2 -2
  7. package/client/index.d.ts +3 -3
  8. package/client/index.js +6 -6
  9. package/core/ast.d.ts +1 -1
  10. package/core/ast.js +1 -1
  11. package/core/codegen/babel-ast.d.ts +1 -1
  12. package/core/codegen/babel-ast.js +2 -2
  13. package/core/codegen/barrel.d.ts +0 -6
  14. package/core/codegen/barrel.js +22 -19
  15. package/core/codegen/client.d.ts +2 -12
  16. package/core/codegen/client.js +7 -21
  17. package/core/codegen/custom-mutations.d.ts +0 -14
  18. package/core/codegen/custom-mutations.js +139 -88
  19. package/core/codegen/custom-queries.d.ts +0 -14
  20. package/core/codegen/custom-queries.js +483 -193
  21. package/core/codegen/hooks-ast.d.ts +75 -0
  22. package/core/codegen/hooks-ast.js +522 -0
  23. package/core/codegen/index.d.ts +16 -18
  24. package/core/codegen/index.js +42 -88
  25. package/core/codegen/invalidation.d.ts +1 -7
  26. package/core/codegen/invalidation.js +50 -16
  27. package/core/codegen/mutation-keys.d.ts +1 -10
  28. package/core/codegen/mutation-keys.js +22 -8
  29. package/core/codegen/mutations.d.ts +0 -13
  30. package/core/codegen/mutations.js +301 -366
  31. package/core/codegen/orm/barrel.d.ts +0 -5
  32. package/core/codegen/orm/barrel.js +5 -0
  33. package/core/codegen/orm/client-generator.d.ts +0 -5
  34. package/core/codegen/orm/client-generator.js +7 -2
  35. package/core/codegen/orm/client.js +3 -1
  36. package/core/codegen/orm/custom-ops-generator.d.ts +0 -6
  37. package/core/codegen/orm/custom-ops-generator.js +104 -51
  38. package/core/codegen/orm/index.d.ts +4 -4
  39. package/core/codegen/orm/index.js +28 -15
  40. package/core/codegen/orm/input-types-generator.d.ts +1 -13
  41. package/core/codegen/orm/input-types-generator.js +85 -23
  42. package/core/codegen/orm/model-generator.d.ts +0 -5
  43. package/core/codegen/orm/model-generator.js +309 -131
  44. package/core/codegen/orm/select-types.d.ts +19 -14
  45. package/core/codegen/queries.d.ts +0 -8
  46. package/core/codegen/queries.js +360 -559
  47. package/core/codegen/query-keys.d.ts +1 -1
  48. package/core/codegen/query-keys.js +37 -23
  49. package/core/codegen/scalars.js +3 -1
  50. package/core/codegen/schema-types-generator.d.ts +1 -1
  51. package/core/codegen/schema-types-generator.js +17 -2
  52. package/core/codegen/select-helpers.d.ts +19 -0
  53. package/core/codegen/select-helpers.js +40 -0
  54. package/core/codegen/selection.d.ts +4 -0
  55. package/core/codegen/selection.js +65 -0
  56. package/core/codegen/shared/index.d.ts +2 -15
  57. package/core/codegen/shared/index.js +17 -4
  58. package/core/codegen/templates/hooks-client.ts +49 -0
  59. package/core/codegen/templates/hooks-selection.ts +58 -0
  60. package/core/codegen/templates/orm-client.ts +8 -6
  61. package/core/codegen/templates/query-builder.ts +250 -46
  62. package/core/codegen/templates/select-types.ts +31 -14
  63. package/core/codegen/type-resolver.d.ts +1 -5
  64. package/core/codegen/type-resolver.js +0 -22
  65. package/core/codegen/types.d.ts +0 -3
  66. package/core/codegen/types.js +71 -14
  67. package/core/codegen/utils.d.ts +1 -4
  68. package/core/codegen/utils.js +4 -1
  69. package/core/config/index.d.ts +1 -1
  70. package/core/config/resolver.js +1 -3
  71. package/core/generate.js +38 -50
  72. package/core/index.d.ts +3 -3
  73. package/core/index.js +3 -4
  74. package/core/introspect/index.d.ts +6 -6
  75. package/core/introspect/index.js +5 -8
  76. package/core/introspect/infer-tables.d.ts +0 -14
  77. package/core/introspect/infer-tables.js +15 -1
  78. package/core/introspect/source/database.js +1 -1
  79. package/core/introspect/source/endpoint.d.ts +0 -6
  80. package/core/introspect/source/endpoint.js +7 -1
  81. package/core/introspect/source/index.d.ts +4 -4
  82. package/core/introspect/source/index.js +5 -9
  83. package/core/introspect/source/pgpm-module.js +3 -3
  84. package/core/introspect/transform-schema.d.ts +2 -2
  85. package/core/introspect/transform-schema.js +2 -2
  86. package/core/output/index.d.ts +1 -1
  87. package/core/output/index.js +2 -2
  88. package/core/output/writer.d.ts +3 -0
  89. package/core/output/writer.js +20 -1
  90. package/core/pipeline/index.d.ts +2 -2
  91. package/core/query-builder.d.ts +2 -2
  92. package/core/query-builder.js +1 -1
  93. package/core/watch/index.d.ts +4 -4
  94. package/core/watch/index.js +9 -9
  95. package/core/watch/orchestrator.js +5 -3
  96. package/esm/cli/index.js +37 -42
  97. package/esm/cli/shared.d.ts +15 -17
  98. package/esm/cli/shared.js +103 -20
  99. package/esm/client/error.js +31 -9
  100. package/esm/client/execute.js +2 -2
  101. package/esm/client/index.d.ts +3 -3
  102. package/esm/client/index.js +3 -3
  103. package/esm/core/ast.d.ts +1 -1
  104. package/esm/core/ast.js +1 -1
  105. package/esm/core/codegen/babel-ast.d.ts +1 -1
  106. package/esm/core/codegen/babel-ast.js +2 -2
  107. package/esm/core/codegen/barrel.d.ts +0 -6
  108. package/esm/core/codegen/barrel.js +23 -20
  109. package/esm/core/codegen/client.d.ts +2 -12
  110. package/esm/core/codegen/client.js +7 -21
  111. package/esm/core/codegen/custom-mutations.d.ts +0 -14
  112. package/esm/core/codegen/custom-mutations.js +141 -90
  113. package/esm/core/codegen/custom-queries.d.ts +0 -14
  114. package/esm/core/codegen/custom-queries.js +486 -196
  115. package/esm/core/codegen/hooks-ast.d.ts +75 -0
  116. package/esm/core/codegen/hooks-ast.js +424 -0
  117. package/esm/core/codegen/index.d.ts +16 -18
  118. package/esm/core/codegen/index.js +26 -71
  119. package/esm/core/codegen/invalidation.d.ts +1 -7
  120. package/esm/core/codegen/invalidation.js +51 -17
  121. package/esm/core/codegen/mutation-keys.d.ts +1 -10
  122. package/esm/core/codegen/mutation-keys.js +23 -9
  123. package/esm/core/codegen/mutations.d.ts +0 -13
  124. package/esm/core/codegen/mutations.js +302 -367
  125. package/esm/core/codegen/orm/barrel.d.ts +0 -5
  126. package/esm/core/codegen/orm/barrel.js +6 -1
  127. package/esm/core/codegen/orm/client-generator.d.ts +0 -5
  128. package/esm/core/codegen/orm/client-generator.js +7 -2
  129. package/esm/core/codegen/orm/client.js +3 -1
  130. package/esm/core/codegen/orm/custom-ops-generator.d.ts +0 -6
  131. package/esm/core/codegen/orm/custom-ops-generator.js +103 -50
  132. package/esm/core/codegen/orm/index.d.ts +4 -4
  133. package/esm/core/codegen/orm/index.js +25 -12
  134. package/esm/core/codegen/orm/input-types-generator.d.ts +1 -13
  135. package/esm/core/codegen/orm/input-types-generator.js +85 -23
  136. package/esm/core/codegen/orm/model-generator.d.ts +0 -5
  137. package/esm/core/codegen/orm/model-generator.js +310 -132
  138. package/esm/core/codegen/orm/select-types.d.ts +19 -14
  139. package/esm/core/codegen/queries.d.ts +0 -8
  140. package/esm/core/codegen/queries.js +362 -561
  141. package/esm/core/codegen/query-keys.d.ts +1 -1
  142. package/esm/core/codegen/query-keys.js +38 -24
  143. package/esm/core/codegen/scalars.js +3 -1
  144. package/esm/core/codegen/schema-types-generator.d.ts +1 -1
  145. package/esm/core/codegen/schema-types-generator.js +17 -2
  146. package/esm/core/codegen/select-helpers.d.ts +19 -0
  147. package/esm/core/codegen/select-helpers.js +35 -0
  148. package/esm/core/codegen/selection.d.ts +4 -0
  149. package/esm/core/codegen/selection.js +29 -0
  150. package/esm/core/codegen/shared/index.d.ts +2 -15
  151. package/esm/core/codegen/shared/index.js +16 -3
  152. package/esm/core/codegen/type-resolver.d.ts +1 -5
  153. package/esm/core/codegen/type-resolver.js +1 -22
  154. package/esm/core/codegen/types.d.ts +0 -3
  155. package/esm/core/codegen/types.js +72 -15
  156. package/esm/core/codegen/utils.d.ts +1 -4
  157. package/esm/core/codegen/utils.js +4 -1
  158. package/esm/core/config/index.d.ts +1 -1
  159. package/esm/core/config/resolver.js +2 -4
  160. package/esm/core/generate.js +38 -50
  161. package/esm/core/index.d.ts +3 -3
  162. package/esm/core/index.js +2 -3
  163. package/esm/core/introspect/index.d.ts +6 -6
  164. package/esm/core/introspect/index.js +3 -6
  165. package/esm/core/introspect/infer-tables.d.ts +0 -14
  166. package/esm/core/introspect/infer-tables.js +16 -2
  167. package/esm/core/introspect/source/database.js +2 -2
  168. package/esm/core/introspect/source/endpoint.d.ts +0 -6
  169. package/esm/core/introspect/source/endpoint.js +7 -1
  170. package/esm/core/introspect/source/index.d.ts +4 -4
  171. package/esm/core/introspect/source/index.js +6 -10
  172. package/esm/core/introspect/source/pgpm-module.js +3 -3
  173. package/esm/core/introspect/transform-schema.d.ts +2 -2
  174. package/esm/core/introspect/transform-schema.js +2 -2
  175. package/esm/core/output/index.d.ts +1 -1
  176. package/esm/core/output/index.js +1 -1
  177. package/esm/core/output/writer.d.ts +3 -0
  178. package/esm/core/output/writer.js +20 -1
  179. package/esm/core/pipeline/index.d.ts +2 -2
  180. package/esm/core/pipeline/index.js +2 -2
  181. package/esm/core/query-builder.d.ts +2 -2
  182. package/esm/core/query-builder.js +2 -2
  183. package/esm/core/watch/index.d.ts +4 -4
  184. package/esm/core/watch/index.js +3 -3
  185. package/esm/core/watch/orchestrator.js +5 -3
  186. package/esm/generators/index.d.ts +3 -3
  187. package/esm/generators/index.js +3 -3
  188. package/esm/generators/mutations.d.ts +1 -1
  189. package/esm/generators/select.d.ts +1 -1
  190. package/esm/index.d.ts +3 -3
  191. package/esm/index.js +1 -4
  192. package/esm/types/config.d.ts +0 -10
  193. package/esm/types/config.js +0 -2
  194. package/esm/types/index.d.ts +6 -6
  195. package/esm/types/index.js +1 -1
  196. package/generators/index.d.ts +3 -3
  197. package/generators/index.js +8 -8
  198. package/generators/mutations.d.ts +1 -1
  199. package/generators/select.d.ts +1 -1
  200. package/index.d.ts +3 -3
  201. package/index.js +11 -5
  202. package/package.json +11 -11
  203. package/types/config.d.ts +0 -10
  204. package/types/config.js +0 -2
  205. package/types/index.d.ts +6 -6
  206. package/types/index.js +2 -2
  207. package/core/codegen/gql-ast.d.ts +0 -41
  208. package/core/codegen/gql-ast.js +0 -353
  209. package/core/codegen/schema-gql-ast.d.ts +0 -51
  210. package/core/codegen/schema-gql-ast.js +0 -385
  211. package/core/codegen/templates/client.browser.ts +0 -271
  212. package/core/codegen/templates/client.node.ts +0 -337
  213. package/esm/core/codegen/gql-ast.d.ts +0 -41
  214. package/esm/core/codegen/gql-ast.js +0 -312
  215. package/esm/core/codegen/schema-gql-ast.d.ts +0 -51
  216. package/esm/core/codegen/schema-gql-ast.js +0 -343
@@ -1,20 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateInvalidationFile = exports.generateMutationKeysFile = exports.generateQueryKeysFile = exports.generateCustomMutationsBarrel = exports.generateCustomQueriesBarrel = exports.generateMainBarrel = exports.generateMutationsBarrel = exports.generateQueriesBarrel = exports.generateCustomMutationHook = exports.generateAllCustomMutationHooks = exports.generateCustomQueryHook = exports.generateAllCustomQueryHooks = exports.generateDeleteMutationHook = exports.generateUpdateMutationHook = exports.generateCreateMutationHook = exports.generateAllMutationHooks = exports.generateSingleQueryHook = exports.generateListQueryHook = exports.generateAllQueryHooks = exports.generateTypesFile = exports.generateClientFile = void 0;
3
+ exports.generateQueryKeysFile = exports.generateSingleQueryHook = exports.generateListQueryHook = exports.generateAllQueryHooks = exports.generateUpdateMutationHook = exports.generateDeleteMutationHook = exports.generateCreateMutationHook = exports.generateAllMutationHooks = exports.generateMutationKeysFile = exports.generateInvalidationFile = exports.generateCustomQueryHook = exports.generateAllCustomQueryHooks = exports.generateCustomMutationHook = exports.generateAllCustomMutationHooks = exports.generateClientFile = exports.generateQueriesBarrel = exports.generateMutationsBarrel = exports.generateMainBarrel = exports.generateCustomQueriesBarrel = exports.generateCustomMutationsBarrel = void 0;
4
4
  exports.generateAllFiles = generateAllFiles;
5
5
  exports.generate = generate;
6
6
  const config_1 = require("../../types/config");
7
+ const barrel_1 = require("./barrel");
7
8
  const client_1 = require("./client");
8
- const types_1 = require("./types");
9
- const schema_types_generator_1 = require("./schema-types-generator");
10
- const queries_1 = require("./queries");
11
- const mutations_1 = require("./mutations");
12
- const custom_queries_1 = require("./custom-queries");
13
9
  const custom_mutations_1 = require("./custom-mutations");
14
- const query_keys_1 = require("./query-keys");
15
- const mutation_keys_1 = require("./mutation-keys");
10
+ const custom_queries_1 = require("./custom-queries");
16
11
  const invalidation_1 = require("./invalidation");
17
- const barrel_1 = require("./barrel");
12
+ const mutation_keys_1 = require("./mutation-keys");
13
+ const mutations_1 = require("./mutations");
14
+ const queries_1 = require("./queries");
15
+ const query_keys_1 = require("./query-keys");
16
+ const selection_1 = require("./selection");
18
17
  const utils_1 = require("./utils");
19
18
  // ============================================================================
20
19
  // Main orchestrator
@@ -32,68 +31,30 @@ function generateAllFiles(tables, config) {
32
31
  * (they're expected to exist in the shared types directory).
33
32
  */
34
33
  function generate(options) {
35
- const { tables, customOperations, config, sharedTypesPath } = options;
34
+ const { tables, customOperations, config } = options;
36
35
  const files = [];
37
36
  // Extract codegen options
38
- const maxDepth = config.codegen.maxFieldDepth;
39
37
  const skipQueryField = config.codegen.skipQueryField;
40
38
  const reactQueryEnabled = config.reactQuery;
41
39
  // Query key configuration (use defaults if not provided)
42
40
  const queryKeyConfig = config.queryKeys ?? config_1.DEFAULT_QUERY_KEY_CONFIG;
43
41
  const useCentralizedKeys = queryKeyConfig.generateScopedKeys;
44
42
  const hasRelationships = Object.keys(queryKeyConfig.relationships).length > 0;
45
- // 1. Generate client.ts
43
+ // 1. Generate client.ts (ORM client wrapper)
46
44
  files.push({
47
45
  path: 'client.ts',
48
- content: (0, client_1.generateClientFile)({
49
- browserCompatible: config.browserCompatible ?? true,
50
- }),
46
+ content: (0, client_1.generateClientFile)(),
47
+ });
48
+ // 1b. Generate selection.ts (shared selection adapters for hooks)
49
+ files.push({
50
+ path: 'selection.ts',
51
+ content: (0, selection_1.generateSelectionFile)(),
51
52
  });
52
53
  // Collect table type names for import path resolution
53
54
  const tableTypeNames = new Set(tables.map((t) => (0, utils_1.getTableNames)(t).typeName));
54
- // When using shared types, skip generating types.ts and schema-types.ts
55
- // They're already generated in the shared directory
56
- let hasSchemaTypes = false;
57
- let generatedEnumNames = [];
58
- if (sharedTypesPath) {
59
- // Using shared types - check if schema-types would be generated
60
- if (customOperations && customOperations.typeRegistry) {
61
- const schemaTypesResult = (0, schema_types_generator_1.generateSchemaTypesFile)({
62
- typeRegistry: customOperations.typeRegistry,
63
- tableTypeNames,
64
- });
65
- if (schemaTypesResult.content.split('\n').length > 10) {
66
- hasSchemaTypes = true;
67
- generatedEnumNames = schemaTypesResult.generatedEnums || [];
68
- }
69
- }
70
- }
71
- else {
72
- // 2. Generate schema-types.ts for custom operations (if any)
73
- // NOTE: This must come BEFORE types.ts so that types.ts can import enum types
74
- if (customOperations && customOperations.typeRegistry) {
75
- const schemaTypesResult = (0, schema_types_generator_1.generateSchemaTypesFile)({
76
- typeRegistry: customOperations.typeRegistry,
77
- tableTypeNames,
78
- });
79
- // Only include if there's meaningful content
80
- if (schemaTypesResult.content.split('\n').length > 10) {
81
- files.push({
82
- path: 'schema-types.ts',
83
- content: schemaTypesResult.content,
84
- });
85
- hasSchemaTypes = true;
86
- generatedEnumNames = schemaTypesResult.generatedEnums || [];
87
- }
88
- }
89
- // 3. Generate types.ts (can now import enums from schema-types)
90
- files.push({
91
- path: 'types.ts',
92
- content: (0, types_1.generateTypesFile)(tables, {
93
- enumsFromSchemaTypes: generatedEnumNames,
94
- }),
95
- });
96
- }
55
+ // NOTE: types.ts and schema-types.ts are no longer generated here.
56
+ // Hooks now import types directly from the ORM's input-types.ts,
57
+ // which serves as the single source of truth for all types.
97
58
  // 3b. Generate centralized query keys (query-keys.ts)
98
59
  let hasQueryKeys = false;
99
60
  if (useCentralizedKeys) {
@@ -153,7 +114,6 @@ function generate(options) {
153
114
  customQueryHooks = (0, custom_queries_1.generateAllCustomQueryHooks)({
154
115
  operations: customOperations.queries,
155
116
  typeRegistry: customOperations.typeRegistry,
156
- maxDepth,
157
117
  skipQueryField,
158
118
  reactQueryEnabled,
159
119
  tableTypeNames,
@@ -176,10 +136,7 @@ function generate(options) {
176
136
  // 6. Generate table-based mutation hooks (mutations/*.ts)
177
137
  const mutationHooks = (0, mutations_1.generateAllMutationHooks)(tables, {
178
138
  reactQueryEnabled,
179
- enumsFromSchemaTypes: generatedEnumNames,
180
139
  useCentralizedKeys,
181
- hasRelationships,
182
- tableTypeNames,
183
140
  });
184
141
  for (const hook of mutationHooks) {
185
142
  files.push({
@@ -193,7 +150,6 @@ function generate(options) {
193
150
  customMutationHooks = (0, custom_mutations_1.generateAllCustomMutationHooks)({
194
151
  operations: customOperations.mutations,
195
152
  typeRegistry: customOperations.typeRegistry,
196
- maxDepth,
197
153
  skipQueryField,
198
154
  reactQueryEnabled,
199
155
  tableTypeNames,
@@ -217,11 +173,11 @@ function generate(options) {
217
173
  : (0, barrel_1.generateMutationsBarrel)(tables),
218
174
  });
219
175
  }
220
- // 9. Generate main index.ts barrel (with schema-types if present)
176
+ // 9. Generate main index.ts barrel
177
+ // No longer includes types.ts or schema-types.ts - hooks import from ORM directly
221
178
  files.push({
222
179
  path: 'index.ts',
223
180
  content: (0, barrel_1.generateMainBarrel)(tables, {
224
- hasSchemaTypes,
225
181
  hasMutations,
226
182
  hasQueryKeys,
227
183
  hasMutationKeys,
@@ -243,34 +199,32 @@ function generate(options) {
243
199
  // ============================================================================
244
200
  // Re-exports for convenience
245
201
  // ============================================================================
202
+ var barrel_2 = require("./barrel");
203
+ Object.defineProperty(exports, "generateCustomMutationsBarrel", { enumerable: true, get: function () { return barrel_2.generateCustomMutationsBarrel; } });
204
+ Object.defineProperty(exports, "generateCustomQueriesBarrel", { enumerable: true, get: function () { return barrel_2.generateCustomQueriesBarrel; } });
205
+ Object.defineProperty(exports, "generateMainBarrel", { enumerable: true, get: function () { return barrel_2.generateMainBarrel; } });
206
+ Object.defineProperty(exports, "generateMutationsBarrel", { enumerable: true, get: function () { return barrel_2.generateMutationsBarrel; } });
207
+ Object.defineProperty(exports, "generateQueriesBarrel", { enumerable: true, get: function () { return barrel_2.generateQueriesBarrel; } });
246
208
  var client_2 = require("./client");
247
209
  Object.defineProperty(exports, "generateClientFile", { enumerable: true, get: function () { return client_2.generateClientFile; } });
248
- var types_2 = require("./types");
249
- Object.defineProperty(exports, "generateTypesFile", { enumerable: true, get: function () { return types_2.generateTypesFile; } });
250
- var queries_2 = require("./queries");
251
- Object.defineProperty(exports, "generateAllQueryHooks", { enumerable: true, get: function () { return queries_2.generateAllQueryHooks; } });
252
- Object.defineProperty(exports, "generateListQueryHook", { enumerable: true, get: function () { return queries_2.generateListQueryHook; } });
253
- Object.defineProperty(exports, "generateSingleQueryHook", { enumerable: true, get: function () { return queries_2.generateSingleQueryHook; } });
210
+ var custom_mutations_2 = require("./custom-mutations");
211
+ Object.defineProperty(exports, "generateAllCustomMutationHooks", { enumerable: true, get: function () { return custom_mutations_2.generateAllCustomMutationHooks; } });
212
+ Object.defineProperty(exports, "generateCustomMutationHook", { enumerable: true, get: function () { return custom_mutations_2.generateCustomMutationHook; } });
213
+ var custom_queries_2 = require("./custom-queries");
214
+ Object.defineProperty(exports, "generateAllCustomQueryHooks", { enumerable: true, get: function () { return custom_queries_2.generateAllCustomQueryHooks; } });
215
+ Object.defineProperty(exports, "generateCustomQueryHook", { enumerable: true, get: function () { return custom_queries_2.generateCustomQueryHook; } });
216
+ var invalidation_2 = require("./invalidation");
217
+ Object.defineProperty(exports, "generateInvalidationFile", { enumerable: true, get: function () { return invalidation_2.generateInvalidationFile; } });
218
+ var mutation_keys_2 = require("./mutation-keys");
219
+ Object.defineProperty(exports, "generateMutationKeysFile", { enumerable: true, get: function () { return mutation_keys_2.generateMutationKeysFile; } });
254
220
  var mutations_2 = require("./mutations");
255
221
  Object.defineProperty(exports, "generateAllMutationHooks", { enumerable: true, get: function () { return mutations_2.generateAllMutationHooks; } });
256
222
  Object.defineProperty(exports, "generateCreateMutationHook", { enumerable: true, get: function () { return mutations_2.generateCreateMutationHook; } });
257
- Object.defineProperty(exports, "generateUpdateMutationHook", { enumerable: true, get: function () { return mutations_2.generateUpdateMutationHook; } });
258
223
  Object.defineProperty(exports, "generateDeleteMutationHook", { enumerable: true, get: function () { return mutations_2.generateDeleteMutationHook; } });
259
- var custom_queries_2 = require("./custom-queries");
260
- Object.defineProperty(exports, "generateAllCustomQueryHooks", { enumerable: true, get: function () { return custom_queries_2.generateAllCustomQueryHooks; } });
261
- Object.defineProperty(exports, "generateCustomQueryHook", { enumerable: true, get: function () { return custom_queries_2.generateCustomQueryHook; } });
262
- var custom_mutations_2 = require("./custom-mutations");
263
- Object.defineProperty(exports, "generateAllCustomMutationHooks", { enumerable: true, get: function () { return custom_mutations_2.generateAllCustomMutationHooks; } });
264
- Object.defineProperty(exports, "generateCustomMutationHook", { enumerable: true, get: function () { return custom_mutations_2.generateCustomMutationHook; } });
265
- var barrel_2 = require("./barrel");
266
- Object.defineProperty(exports, "generateQueriesBarrel", { enumerable: true, get: function () { return barrel_2.generateQueriesBarrel; } });
267
- Object.defineProperty(exports, "generateMutationsBarrel", { enumerable: true, get: function () { return barrel_2.generateMutationsBarrel; } });
268
- Object.defineProperty(exports, "generateMainBarrel", { enumerable: true, get: function () { return barrel_2.generateMainBarrel; } });
269
- Object.defineProperty(exports, "generateCustomQueriesBarrel", { enumerable: true, get: function () { return barrel_2.generateCustomQueriesBarrel; } });
270
- Object.defineProperty(exports, "generateCustomMutationsBarrel", { enumerable: true, get: function () { return barrel_2.generateCustomMutationsBarrel; } });
224
+ Object.defineProperty(exports, "generateUpdateMutationHook", { enumerable: true, get: function () { return mutations_2.generateUpdateMutationHook; } });
225
+ var queries_2 = require("./queries");
226
+ Object.defineProperty(exports, "generateAllQueryHooks", { enumerable: true, get: function () { return queries_2.generateAllQueryHooks; } });
227
+ Object.defineProperty(exports, "generateListQueryHook", { enumerable: true, get: function () { return queries_2.generateListQueryHook; } });
228
+ Object.defineProperty(exports, "generateSingleQueryHook", { enumerable: true, get: function () { return queries_2.generateSingleQueryHook; } });
271
229
  var query_keys_2 = require("./query-keys");
272
230
  Object.defineProperty(exports, "generateQueryKeysFile", { enumerable: true, get: function () { return query_keys_2.generateQueryKeysFile; } });
273
- var mutation_keys_2 = require("./mutation-keys");
274
- Object.defineProperty(exports, "generateMutationKeysFile", { enumerable: true, get: function () { return mutation_keys_2.generateMutationKeysFile; } });
275
- var invalidation_2 = require("./invalidation");
276
- Object.defineProperty(exports, "generateInvalidationFile", { enumerable: true, get: function () { return invalidation_2.generateInvalidationFile; } });
@@ -1,11 +1,5 @@
1
- /**
2
- * Cache invalidation helpers generator
3
- *
4
- * Generates type-safe cache invalidation utilities with cascade support
5
- * for parent-child entity relationships.
6
- */
7
- import type { CleanTable } from '../../types/schema';
8
1
  import type { QueryKeyConfig } from '../../types/config';
2
+ import type { CleanTable } from '../../types/schema';
9
3
  export interface InvalidationGeneratorOptions {
10
4
  tables: CleanTable[];
11
5
  config: QueryKeyConfig;
@@ -34,9 +34,15 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.generateInvalidationFile = generateInvalidationFile;
37
- const utils_1 = require("./utils");
37
+ /**
38
+ * Cache invalidation helpers generator
39
+ *
40
+ * Generates type-safe cache invalidation utilities with cascade support
41
+ * for parent-child entity relationships.
42
+ */
38
43
  const t = __importStar(require("@babel/types"));
39
44
  const babel_ast_1 = require("./babel-ast");
45
+ const utils_1 = require("./utils");
40
46
  /**
41
47
  * Build a map of parent -> children for cascade invalidation
42
48
  */
@@ -83,7 +89,11 @@ function buildEntityInvalidateProperty(table, relationships, childrenMap, allTab
83
89
  const queryClientTypeRef = () => t.tsTypeReference(t.identifier('QueryClient'));
84
90
  const stringOrNumberType = () => t.tsUnionType([t.tsStringKeyword(), t.tsNumberKeyword()]);
85
91
  // Helper to create queryClient.invalidateQueries({ queryKey: ... })
86
- const invalidateCall = (queryKeyExpr) => t.callExpression(t.memberExpression(t.identifier('queryClient'), t.identifier('invalidateQueries')), [t.objectExpression([t.objectProperty(t.identifier('queryKey'), queryKeyExpr)])]);
92
+ const invalidateCall = (queryKeyExpr) => t.callExpression(t.memberExpression(t.identifier('queryClient'), t.identifier('invalidateQueries')), [
93
+ t.objectExpression([
94
+ t.objectProperty(t.identifier('queryKey'), queryKeyExpr),
95
+ ]),
96
+ ]);
87
97
  // all property
88
98
  const allArrowFn = t.arrowFunctionExpression([(0, babel_ast_1.typedParam)('queryClient', queryClientTypeRef())], invalidateCall(t.memberExpression(t.identifier(keysName), t.identifier('all'))));
89
99
  const allProp = t.objectProperty(t.identifier('all'), allArrowFn);
@@ -108,11 +118,18 @@ function buildEntityInvalidateProperty(table, relationships, childrenMap, allTab
108
118
  if (hasParent) {
109
119
  const scopeTypeName = `${typeName}Scope`;
110
120
  const scopeParam = (0, babel_ast_1.typedParam)('scope', t.tsTypeReference(t.identifier(scopeTypeName)), true);
111
- const detailArrowFn = t.arrowFunctionExpression([(0, babel_ast_1.typedParam)('queryClient', queryClientTypeRef()), (0, babel_ast_1.typedParam)('id', stringOrNumberType()), scopeParam], invalidateCall(t.callExpression(t.memberExpression(t.identifier(keysName), t.identifier('detail')), [t.identifier('id'), t.identifier('scope')])));
121
+ const detailArrowFn = t.arrowFunctionExpression([
122
+ (0, babel_ast_1.typedParam)('queryClient', queryClientTypeRef()),
123
+ (0, babel_ast_1.typedParam)('id', stringOrNumberType()),
124
+ scopeParam,
125
+ ], invalidateCall(t.callExpression(t.memberExpression(t.identifier(keysName), t.identifier('detail')), [t.identifier('id'), t.identifier('scope')])));
112
126
  detailProp = t.objectProperty(t.identifier('detail'), detailArrowFn);
113
127
  }
114
128
  else {
115
- const detailArrowFn = t.arrowFunctionExpression([(0, babel_ast_1.typedParam)('queryClient', queryClientTypeRef()), (0, babel_ast_1.typedParam)('id', stringOrNumberType())], invalidateCall(t.callExpression(t.memberExpression(t.identifier(keysName), t.identifier('detail')), [t.identifier('id')])));
129
+ const detailArrowFn = t.arrowFunctionExpression([
130
+ (0, babel_ast_1.typedParam)('queryClient', queryClientTypeRef()),
131
+ (0, babel_ast_1.typedParam)('id', stringOrNumberType()),
132
+ ], invalidateCall(t.callExpression(t.memberExpression(t.identifier(keysName), t.identifier('detail')), [t.identifier('id')])));
116
133
  detailProp = t.objectProperty(t.identifier('detail'), detailArrowFn);
117
134
  }
118
135
  (0, babel_ast_1.addJSDocComment)(detailProp, [`Invalidate a specific ${singularName}`]);
@@ -156,7 +173,10 @@ function buildEntityInvalidateProperty(table, relationships, childrenMap, allTab
156
173
  }
157
174
  }
158
175
  }
159
- const withChildrenArrowFn = t.arrowFunctionExpression([(0, babel_ast_1.typedParam)('queryClient', queryClientTypeRef()), (0, babel_ast_1.typedParam)('id', stringOrNumberType())], t.blockStatement(cascadeStatements));
176
+ const withChildrenArrowFn = t.arrowFunctionExpression([
177
+ (0, babel_ast_1.typedParam)('queryClient', queryClientTypeRef()),
178
+ (0, babel_ast_1.typedParam)('id', stringOrNumberType()),
179
+ ], t.blockStatement(cascadeStatements));
160
180
  const withChildrenProp = t.objectProperty(t.identifier('withChildren'), withChildrenArrowFn);
161
181
  (0, babel_ast_1.addJSDocComment)(withChildrenProp, [
162
182
  `Invalidate ${singularName} and all child entities`,
@@ -179,19 +199,30 @@ function buildEntityRemoveProperty(table, relationships) {
179
199
  const queryClientTypeRef = () => t.tsTypeReference(t.identifier('QueryClient'));
180
200
  const stringOrNumberType = () => t.tsUnionType([t.tsStringKeyword(), t.tsNumberKeyword()]);
181
201
  // Helper to create queryClient.removeQueries({ queryKey: ... })
182
- const removeCall = (queryKeyExpr) => t.callExpression(t.memberExpression(t.identifier('queryClient'), t.identifier('removeQueries')), [t.objectExpression([t.objectProperty(t.identifier('queryKey'), queryKeyExpr)])]);
202
+ const removeCall = (queryKeyExpr) => t.callExpression(t.memberExpression(t.identifier('queryClient'), t.identifier('removeQueries')), [
203
+ t.objectExpression([
204
+ t.objectProperty(t.identifier('queryKey'), queryKeyExpr),
205
+ ]),
206
+ ]);
183
207
  let removeProp;
184
208
  if (relationship) {
185
209
  const scopeTypeName = `${typeName}Scope`;
186
210
  const scopeParam = (0, babel_ast_1.typedParam)('scope', t.tsTypeReference(t.identifier(scopeTypeName)), true);
187
- const removeArrowFn = t.arrowFunctionExpression([(0, babel_ast_1.typedParam)('queryClient', queryClientTypeRef()), (0, babel_ast_1.typedParam)('id', stringOrNumberType()), scopeParam], t.blockStatement([
188
- t.expressionStatement(removeCall(t.callExpression(t.memberExpression(t.identifier(keysName), t.identifier('detail')), [t.identifier('id'), t.identifier('scope')])))
211
+ const removeArrowFn = t.arrowFunctionExpression([
212
+ (0, babel_ast_1.typedParam)('queryClient', queryClientTypeRef()),
213
+ (0, babel_ast_1.typedParam)('id', stringOrNumberType()),
214
+ scopeParam,
215
+ ], t.blockStatement([
216
+ t.expressionStatement(removeCall(t.callExpression(t.memberExpression(t.identifier(keysName), t.identifier('detail')), [t.identifier('id'), t.identifier('scope')]))),
189
217
  ]));
190
218
  removeProp = t.objectProperty(t.identifier(singularName), removeArrowFn);
191
219
  }
192
220
  else {
193
- const removeArrowFn = t.arrowFunctionExpression([(0, babel_ast_1.typedParam)('queryClient', queryClientTypeRef()), (0, babel_ast_1.typedParam)('id', stringOrNumberType())], t.blockStatement([
194
- t.expressionStatement(removeCall(t.callExpression(t.memberExpression(t.identifier(keysName), t.identifier('detail')), [t.identifier('id')])))
221
+ const removeArrowFn = t.arrowFunctionExpression([
222
+ (0, babel_ast_1.typedParam)('queryClient', queryClientTypeRef()),
223
+ (0, babel_ast_1.typedParam)('id', stringOrNumberType()),
224
+ ], t.blockStatement([
225
+ t.expressionStatement(removeCall(t.callExpression(t.memberExpression(t.identifier(keysName), t.identifier('detail')), [t.identifier('id')]))),
195
226
  ]));
196
227
  removeProp = t.objectProperty(t.identifier(singularName), removeArrowFn);
197
228
  }
@@ -207,7 +238,9 @@ function generateInvalidationFile(options) {
207
238
  const childrenMap = buildChildrenMap(relationships);
208
239
  const statements = [];
209
240
  // Import QueryClient type
210
- const queryClientImport = t.importDeclaration([t.importSpecifier(t.identifier('QueryClient'), t.identifier('QueryClient'))], t.stringLiteral('@tanstack/react-query'));
241
+ const queryClientImport = t.importDeclaration([
242
+ t.importSpecifier(t.identifier('QueryClient'), t.identifier('QueryClient')),
243
+ ], t.stringLiteral('@tanstack/react-query'));
211
244
  queryClientImport.importKind = 'type';
212
245
  statements.push(queryClientImport);
213
246
  // Import query keys
@@ -216,7 +249,7 @@ function generateInvalidationFile(options) {
216
249
  const { typeName } = (0, utils_1.getTableNames)(table);
217
250
  keyImports.push(`${(0, utils_1.lcFirst)(typeName)}Keys`);
218
251
  }
219
- statements.push(t.importDeclaration(keyImports.map(name => t.importSpecifier(t.identifier(name), t.identifier(name))), t.stringLiteral('./query-keys')));
252
+ statements.push(t.importDeclaration(keyImports.map((name) => t.importSpecifier(t.identifier(name), t.identifier(name))), t.stringLiteral('./query-keys')));
220
253
  // Import scope types if needed
221
254
  const scopeTypes = [];
222
255
  for (const table of tables) {
@@ -226,7 +259,7 @@ function generateInvalidationFile(options) {
226
259
  }
227
260
  }
228
261
  if (scopeTypes.length > 0) {
229
- const scopeImport = t.importDeclaration(scopeTypes.map(name => t.importSpecifier(t.identifier(name), t.identifier(name))), t.stringLiteral('./query-keys'));
262
+ const scopeImport = t.importDeclaration(scopeTypes.map((name) => t.importSpecifier(t.identifier(name), t.identifier(name))), t.stringLiteral('./query-keys'));
230
263
  scopeImport.importKind = 'type';
231
264
  statements.push(scopeImport);
232
265
  }
@@ -236,7 +269,7 @@ function generateInvalidationFile(options) {
236
269
  invalidateProperties.push(buildEntityInvalidateProperty(table, relationships, childrenMap, tables));
237
270
  }
238
271
  const invalidateDecl = t.exportNamedDeclaration(t.variableDeclaration('const', [
239
- t.variableDeclarator(t.identifier('invalidate'), (0, babel_ast_1.asConst)(t.objectExpression(invalidateProperties)))
272
+ t.variableDeclarator(t.identifier('invalidate'), (0, babel_ast_1.asConst)(t.objectExpression(invalidateProperties))),
240
273
  ]));
241
274
  // Build JSDoc for invalidate
242
275
  const invalidateDocLines = [
@@ -267,7 +300,7 @@ function generateInvalidationFile(options) {
267
300
  removeProperties.push(buildEntityRemoveProperty(table, relationships));
268
301
  }
269
302
  const removeDecl = t.exportNamedDeclaration(t.variableDeclaration('const', [
270
- t.variableDeclarator(t.identifier('remove'), (0, babel_ast_1.asConst)(t.objectExpression(removeProperties)))
303
+ t.variableDeclarator(t.identifier('remove'), (0, babel_ast_1.asConst)(t.objectExpression(removeProperties))),
271
304
  ]));
272
305
  (0, babel_ast_1.addJSDocComment)(removeDecl, [
273
306
  'Remove queries from cache (for delete operations)',
@@ -300,7 +333,8 @@ ${description}
300
333
  for (let i = 0; i < codeLines.length; i++) {
301
334
  const line = codeLines[i];
302
335
  // Detect invalidation section (after imports)
303
- if (!addedInvalidationSection && line.includes('* Type-safe query invalidation helpers')) {
336
+ if (!addedInvalidationSection &&
337
+ line.includes('* Type-safe query invalidation helpers')) {
304
338
  content += `// ============================================================================
305
339
  // Invalidation Helpers
306
340
  // ============================================================================
@@ -1,14 +1,5 @@
1
- /**
2
- * Mutation key factory generator
3
- *
4
- * Generates centralized mutation keys for tracking in-flight mutations.
5
- * Useful for:
6
- * - Optimistic updates with rollback
7
- * - Mutation deduplication
8
- * - Tracking mutation state with useIsMutating
9
- */
10
- import type { CleanTable, CleanOperation } from '../../types/schema';
11
1
  import type { QueryKeyConfig } from '../../types/config';
2
+ import type { CleanOperation, CleanTable } from '../../types/schema';
12
3
  export interface MutationKeyGeneratorOptions {
13
4
  tables: CleanTable[];
14
5
  customMutations: CleanOperation[];
@@ -34,9 +34,18 @@ var __importStar = (this && this.__importStar) || (function () {
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.generateMutationKeysFile = generateMutationKeysFile;
37
- const utils_1 = require("./utils");
37
+ /**
38
+ * Mutation key factory generator
39
+ *
40
+ * Generates centralized mutation keys for tracking in-flight mutations.
41
+ * Useful for:
42
+ * - Optimistic updates with rollback
43
+ * - Mutation deduplication
44
+ * - Tracking mutation state with useIsMutating
45
+ */
38
46
  const t = __importStar(require("@babel/types"));
39
47
  const babel_ast_1 = require("./babel-ast");
48
+ const utils_1 = require("./utils");
40
49
  /**
41
50
  * Generate mutation keys declaration for a single table entity
42
51
  */
@@ -61,7 +70,7 @@ function generateEntityMutationKeysDeclaration(table, relationships) {
61
70
  t.stringLiteral(entityKey),
62
71
  t.stringLiteral('create'),
63
72
  t.objectExpression([
64
- t.objectProperty(t.identifier(relationship.foreignKey), t.identifier(relationship.foreignKey), false, true)
73
+ t.objectProperty(t.identifier(relationship.foreignKey), t.identifier(relationship.foreignKey), false, true),
65
74
  ]),
66
75
  ]), (0, babel_ast_1.constArray)([
67
76
  t.stringLiteral('mutation'),
@@ -81,7 +90,9 @@ function generateEntityMutationKeysDeclaration(table, relationships) {
81
90
  (0, babel_ast_1.addJSDocComment)(createProp, [`Create ${singularName} mutation key`]);
82
91
  properties.push(createProp);
83
92
  // update property
84
- const updateArrowFn = t.arrowFunctionExpression([(0, babel_ast_1.typedParam)('id', t.tsUnionType([t.tsStringKeyword(), t.tsNumberKeyword()]))], (0, babel_ast_1.constArray)([
93
+ const updateArrowFn = t.arrowFunctionExpression([
94
+ (0, babel_ast_1.typedParam)('id', t.tsUnionType([t.tsStringKeyword(), t.tsNumberKeyword()])),
95
+ ], (0, babel_ast_1.constArray)([
85
96
  t.stringLiteral('mutation'),
86
97
  t.stringLiteral(entityKey),
87
98
  t.stringLiteral('update'),
@@ -91,7 +102,9 @@ function generateEntityMutationKeysDeclaration(table, relationships) {
91
102
  (0, babel_ast_1.addJSDocComment)(updateProp, [`Update ${singularName} mutation key`]);
92
103
  properties.push(updateProp);
93
104
  // delete property
94
- const deleteArrowFn = t.arrowFunctionExpression([(0, babel_ast_1.typedParam)('id', t.tsUnionType([t.tsStringKeyword(), t.tsNumberKeyword()]))], (0, babel_ast_1.constArray)([
105
+ const deleteArrowFn = t.arrowFunctionExpression([
106
+ (0, babel_ast_1.typedParam)('id', t.tsUnionType([t.tsStringKeyword(), t.tsNumberKeyword()])),
107
+ ], (0, babel_ast_1.constArray)([
95
108
  t.stringLiteral('mutation'),
96
109
  t.stringLiteral(entityKey),
97
110
  t.stringLiteral('delete'),
@@ -101,7 +114,7 @@ function generateEntityMutationKeysDeclaration(table, relationships) {
101
114
  (0, babel_ast_1.addJSDocComment)(deleteProp, [`Delete ${singularName} mutation key`]);
102
115
  properties.push(deleteProp);
103
116
  return t.exportNamedDeclaration(t.variableDeclaration('const', [
104
- t.variableDeclarator(t.identifier(keysName), (0, babel_ast_1.asConst)(t.objectExpression(properties)))
117
+ t.variableDeclarator(t.identifier(keysName), (0, babel_ast_1.asConst)(t.objectExpression(properties))),
105
118
  ]));
106
119
  }
107
120
  /**
@@ -133,7 +146,7 @@ function generateCustomMutationKeysDeclaration(operations) {
133
146
  properties.push(prop);
134
147
  }
135
148
  return t.exportNamedDeclaration(t.variableDeclaration('const', [
136
- t.variableDeclarator(t.identifier('customMutationKeys'), (0, babel_ast_1.asConst)(t.objectExpression(properties)))
149
+ t.variableDeclarator(t.identifier('customMutationKeys'), (0, babel_ast_1.asConst)(t.objectExpression(properties))),
137
150
  ]));
138
151
  }
139
152
  /**
@@ -150,7 +163,7 @@ function generateUnifiedMutationStoreDeclaration(tables, hasCustomMutations) {
150
163
  properties.push(t.objectProperty(t.identifier('custom'), t.identifier('customMutationKeys')));
151
164
  }
152
165
  const decl = t.exportNamedDeclaration(t.variableDeclaration('const', [
153
- t.variableDeclarator(t.identifier('mutationKeys'), (0, babel_ast_1.asConst)(t.objectExpression(properties)))
166
+ t.variableDeclarator(t.identifier('mutationKeys'), (0, babel_ast_1.asConst)(t.objectExpression(properties))),
154
167
  ]));
155
168
  (0, babel_ast_1.addJSDocComment)(decl, [
156
169
  'Unified mutation key store',
@@ -219,7 +232,8 @@ ${description}
219
232
  for (let i = 0; i < codeLines.length; i++) {
220
233
  const line = codeLines[i];
221
234
  // Detect custom mutation keys section
222
- if (!addedCustomSection && line.startsWith('export const customMutationKeys')) {
235
+ if (!addedCustomSection &&
236
+ line.startsWith('export const customMutationKeys')) {
223
237
  content += `
224
238
  // ============================================================================
225
239
  // Custom Mutation Keys
@@ -1,12 +1,3 @@
1
- /**
2
- * Mutation hook generators using Babel AST-based code generation
3
- *
4
- * Output structure:
5
- * mutations/
6
- * useCreateCarMutation.ts
7
- * useUpdateCarMutation.ts
8
- * useDeleteCarMutation.ts
9
- */
10
1
  import type { CleanTable } from '../../types/schema';
11
2
  export interface GeneratedMutationFile {
12
3
  fileName: string;
@@ -14,11 +5,7 @@ export interface GeneratedMutationFile {
14
5
  }
15
6
  export interface MutationGeneratorOptions {
16
7
  reactQueryEnabled?: boolean;
17
- enumsFromSchemaTypes?: string[];
18
8
  useCentralizedKeys?: boolean;
19
- hasRelationships?: boolean;
20
- /** All table type names for determining which types to import from types.ts vs schema-types.ts */
21
- tableTypeNames?: Set<string>;
22
9
  }
23
10
  export declare function generateCreateMutationHook(table: CleanTable, options?: MutationGeneratorOptions): GeneratedMutationFile | null;
24
11
  export declare function generateUpdateMutationHook(table: CleanTable, options?: MutationGeneratorOptions): GeneratedMutationFile | null;