@constructive-io/graphql-codegen 4.0.1 → 4.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 (97) hide show
  1. package/cli/handler.d.ts +13 -0
  2. package/cli/handler.js +74 -0
  3. package/cli/index.js +11 -60
  4. package/cli/shared.d.ts +1 -1
  5. package/cli/shared.js +2 -5
  6. package/core/codegen/barrel.d.ts +1 -0
  7. package/core/codegen/barrel.js +5 -2
  8. package/core/codegen/cli/arg-mapper.d.ts +4 -0
  9. package/core/codegen/cli/arg-mapper.js +117 -0
  10. package/core/codegen/cli/command-map-generator.d.ts +16 -0
  11. package/core/codegen/cli/command-map-generator.js +338 -0
  12. package/core/codegen/cli/custom-command-generator.d.ts +8 -0
  13. package/core/codegen/cli/custom-command-generator.js +155 -0
  14. package/core/codegen/cli/docs-generator.d.ts +26 -0
  15. package/core/codegen/cli/docs-generator.js +1399 -0
  16. package/core/codegen/cli/executor-generator.d.ts +11 -0
  17. package/core/codegen/cli/executor-generator.js +217 -0
  18. package/core/codegen/cli/index.d.ts +53 -0
  19. package/core/codegen/cli/index.js +153 -0
  20. package/core/codegen/cli/infra-generator.d.ts +9 -0
  21. package/core/codegen/cli/infra-generator.js +1195 -0
  22. package/core/codegen/cli/table-command-generator.d.ts +7 -0
  23. package/core/codegen/cli/table-command-generator.js +323 -0
  24. package/core/codegen/docs-utils.d.ts +30 -0
  25. package/core/codegen/docs-utils.js +122 -0
  26. package/core/codegen/hooks-docs-generator.d.ts +6 -0
  27. package/core/codegen/hooks-docs-generator.js +468 -0
  28. package/core/codegen/orm/docs-generator.d.ts +6 -0
  29. package/core/codegen/orm/docs-generator.js +416 -0
  30. package/core/codegen/target-docs-generator.d.ts +20 -0
  31. package/core/codegen/target-docs-generator.js +110 -0
  32. package/core/database/index.d.ts +0 -12
  33. package/core/database/index.js +2 -19
  34. package/core/generate.d.ts +34 -2
  35. package/core/generate.js +453 -12
  36. package/core/index.d.ts +0 -2
  37. package/core/index.js +0 -2
  38. package/core/introspect/source/database.js +2 -2
  39. package/core/introspect/source/pgpm-module.js +2 -2
  40. package/core/output/index.d.ts +1 -1
  41. package/core/output/index.js +1 -2
  42. package/core/output/writer.d.ts +0 -10
  43. package/core/output/writer.js +0 -31
  44. package/esm/cli/handler.d.ts +13 -0
  45. package/esm/cli/handler.js +71 -0
  46. package/esm/cli/index.js +11 -60
  47. package/esm/cli/shared.d.ts +1 -1
  48. package/esm/cli/shared.js +2 -5
  49. package/esm/core/codegen/barrel.d.ts +1 -0
  50. package/esm/core/codegen/barrel.js +5 -2
  51. package/esm/core/codegen/cli/arg-mapper.d.ts +4 -0
  52. package/esm/core/codegen/cli/arg-mapper.js +80 -0
  53. package/esm/core/codegen/cli/command-map-generator.d.ts +16 -0
  54. package/esm/core/codegen/cli/command-map-generator.js +301 -0
  55. package/esm/core/codegen/cli/custom-command-generator.d.ts +8 -0
  56. package/esm/core/codegen/cli/custom-command-generator.js +119 -0
  57. package/esm/core/codegen/cli/docs-generator.d.ts +26 -0
  58. package/esm/core/codegen/cli/docs-generator.js +1387 -0
  59. package/esm/core/codegen/cli/executor-generator.d.ts +11 -0
  60. package/esm/core/codegen/cli/executor-generator.js +180 -0
  61. package/esm/core/codegen/cli/index.d.ts +53 -0
  62. package/esm/core/codegen/cli/index.js +128 -0
  63. package/esm/core/codegen/cli/infra-generator.d.ts +9 -0
  64. package/esm/core/codegen/cli/infra-generator.js +1156 -0
  65. package/esm/core/codegen/cli/table-command-generator.d.ts +7 -0
  66. package/esm/core/codegen/cli/table-command-generator.js +287 -0
  67. package/esm/core/codegen/docs-utils.d.ts +30 -0
  68. package/esm/core/codegen/docs-utils.js +112 -0
  69. package/esm/core/codegen/hooks-docs-generator.d.ts +6 -0
  70. package/esm/core/codegen/hooks-docs-generator.js +462 -0
  71. package/esm/core/codegen/orm/docs-generator.d.ts +6 -0
  72. package/esm/core/codegen/orm/docs-generator.js +410 -0
  73. package/esm/core/codegen/target-docs-generator.d.ts +20 -0
  74. package/esm/core/codegen/target-docs-generator.js +105 -0
  75. package/esm/core/database/index.d.ts +0 -12
  76. package/esm/core/database/index.js +1 -17
  77. package/esm/core/generate.d.ts +34 -2
  78. package/esm/core/generate.js +417 -12
  79. package/esm/core/index.d.ts +0 -2
  80. package/esm/core/index.js +0 -2
  81. package/esm/core/introspect/source/database.js +2 -2
  82. package/esm/core/introspect/source/pgpm-module.js +2 -2
  83. package/esm/core/output/index.d.ts +1 -1
  84. package/esm/core/output/index.js +1 -1
  85. package/esm/core/output/writer.d.ts +0 -10
  86. package/esm/core/output/writer.js +0 -30
  87. package/esm/generators/index.d.ts +0 -3
  88. package/esm/generators/index.js +0 -3
  89. package/esm/index.d.ts +4 -3
  90. package/esm/index.js +4 -2
  91. package/esm/types/config.d.ts +78 -0
  92. package/generators/index.d.ts +0 -3
  93. package/generators/index.js +0 -3
  94. package/index.d.ts +4 -3
  95. package/index.js +7 -2
  96. package/package.json +8 -7
  97. package/types/config.d.ts +78 -0
@@ -0,0 +1,468 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateHooksReadme = generateHooksReadme;
4
+ exports.generateHooksAgentsDocs = generateHooksAgentsDocs;
5
+ exports.getHooksMcpTools = getHooksMcpTools;
6
+ exports.generateHooksSkills = generateHooksSkills;
7
+ const docs_utils_1 = require("./docs-utils");
8
+ const utils_1 = require("./utils");
9
+ function getCustomHookName(op) {
10
+ if (op.kind === 'query') {
11
+ return `use${(0, utils_1.ucFirst)(op.name)}Query`;
12
+ }
13
+ return `use${(0, utils_1.ucFirst)(op.name)}Mutation`;
14
+ }
15
+ function generateHooksReadme(tables, customOperations) {
16
+ const lines = [];
17
+ lines.push(...(0, docs_utils_1.getReadmeHeader)('React Query Hooks'));
18
+ lines.push('## Setup');
19
+ lines.push('');
20
+ lines.push('```typescript');
21
+ lines.push("import { QueryClient, QueryClientProvider } from '@tanstack/react-query';");
22
+ lines.push("import { configure } from './hooks';");
23
+ lines.push('');
24
+ lines.push('configure({');
25
+ lines.push(" endpoint: 'https://api.example.com/graphql',");
26
+ lines.push(" headers: { Authorization: 'Bearer <token>' },");
27
+ lines.push('});');
28
+ lines.push('');
29
+ lines.push('const queryClient = new QueryClient();');
30
+ lines.push('');
31
+ lines.push('function App() {');
32
+ lines.push(' return (');
33
+ lines.push(' <QueryClientProvider client={queryClient}>');
34
+ lines.push(' <YourApp />');
35
+ lines.push(' </QueryClientProvider>');
36
+ lines.push(' );');
37
+ lines.push('}');
38
+ lines.push('```');
39
+ lines.push('');
40
+ lines.push('## Hooks');
41
+ lines.push('');
42
+ lines.push('| Hook | Type | Description |');
43
+ lines.push('|------|------|-------------|');
44
+ for (const table of tables) {
45
+ const { singularName, pluralName } = (0, utils_1.getTableNames)(table);
46
+ lines.push(`| \`${(0, utils_1.getListQueryHookName)(table)}\` | Query | List all ${pluralName} |`);
47
+ if ((0, utils_1.hasValidPrimaryKey)(table)) {
48
+ lines.push(`| \`${(0, utils_1.getSingleQueryHookName)(table)}\` | Query | Get one ${singularName} |`);
49
+ }
50
+ lines.push(`| \`${(0, utils_1.getCreateMutationHookName)(table)}\` | Mutation | Create a ${singularName} |`);
51
+ if ((0, utils_1.hasValidPrimaryKey)(table)) {
52
+ lines.push(`| \`${(0, utils_1.getUpdateMutationHookName)(table)}\` | Mutation | Update a ${singularName} |`);
53
+ lines.push(`| \`${(0, utils_1.getDeleteMutationHookName)(table)}\` | Mutation | Delete a ${singularName} |`);
54
+ }
55
+ }
56
+ for (const op of customOperations) {
57
+ lines.push(`| \`${getCustomHookName(op)}\` | ${(0, utils_1.ucFirst)(op.kind)} | ${op.description || op.name} |`);
58
+ }
59
+ lines.push('');
60
+ if (tables.length > 0) {
61
+ lines.push('## Table Hooks');
62
+ lines.push('');
63
+ for (const table of tables) {
64
+ const { singularName, pluralName } = (0, utils_1.getTableNames)(table);
65
+ const pk = (0, utils_1.getPrimaryKeyInfo)(table)[0];
66
+ const scalarFields = (0, utils_1.getScalarFields)(table);
67
+ lines.push(`### ${table.name}`);
68
+ lines.push('');
69
+ lines.push('```typescript');
70
+ lines.push(`// List all ${pluralName}`);
71
+ lines.push(`const { data, isLoading } = ${(0, utils_1.getListQueryHookName)(table)}({`);
72
+ lines.push(` selection: { fields: { ${scalarFields.map((f) => `${f.name}: true`).join(', ')} } },`);
73
+ lines.push('});');
74
+ lines.push('');
75
+ if ((0, utils_1.hasValidPrimaryKey)(table)) {
76
+ lines.push(`// Get one ${singularName}`);
77
+ lines.push(`const { data: item } = ${(0, utils_1.getSingleQueryHookName)(table)}({`);
78
+ lines.push(` ${pk.name}: '<value>',`);
79
+ lines.push(` selection: { fields: { ${scalarFields.map((f) => `${f.name}: true`).join(', ')} } },`);
80
+ lines.push('});');
81
+ lines.push('');
82
+ }
83
+ lines.push(`// Create a ${singularName}`);
84
+ lines.push(`const { mutate: create } = ${(0, utils_1.getCreateMutationHookName)(table)}({`);
85
+ lines.push(` selection: { fields: { ${pk.name}: true } },`);
86
+ lines.push('});');
87
+ lines.push(`create({ ${scalarFields.filter((f) => f.name !== pk.name && f.name !== 'nodeId' && f.name !== 'createdAt' && f.name !== 'updatedAt').map((f) => `${f.name}: '<value>'`).join(', ')} });`);
88
+ lines.push('```');
89
+ lines.push('');
90
+ }
91
+ }
92
+ if (customOperations.length > 0) {
93
+ lines.push('## Custom Operation Hooks');
94
+ lines.push('');
95
+ for (const op of customOperations) {
96
+ const hookName = getCustomHookName(op);
97
+ lines.push(`### \`${hookName}\``);
98
+ lines.push('');
99
+ lines.push(op.description || op.name);
100
+ lines.push('');
101
+ lines.push(`- **Type:** ${op.kind}`);
102
+ if (op.args.length > 0) {
103
+ lines.push('- **Arguments:**');
104
+ lines.push('');
105
+ lines.push(' | Argument | Type |');
106
+ lines.push(' |----------|------|');
107
+ for (const arg of op.args) {
108
+ lines.push(` | \`${arg.name}\` | ${(0, docs_utils_1.formatArgType)(arg)} |`);
109
+ }
110
+ }
111
+ else {
112
+ lines.push('- **Arguments:** none');
113
+ }
114
+ lines.push('');
115
+ }
116
+ }
117
+ lines.push(...(0, docs_utils_1.getReadmeFooter)());
118
+ return {
119
+ fileName: 'README.md',
120
+ content: lines.join('\n'),
121
+ };
122
+ }
123
+ function generateHooksAgentsDocs(tables, customOperations) {
124
+ const lines = [];
125
+ lines.push('# React Query Hooks - Agent Reference');
126
+ lines.push('');
127
+ lines.push('> @generated by @constructive-io/graphql-codegen - DO NOT EDIT');
128
+ lines.push('> This document is structured for LLM/agent consumption.');
129
+ lines.push('');
130
+ lines.push('## OVERVIEW');
131
+ lines.push('');
132
+ lines.push('React Query hooks wrapping ORM operations for data fetching and mutations.');
133
+ lines.push('All query hooks return `UseQueryResult`. All mutation hooks return `UseMutationResult`.');
134
+ lines.push('');
135
+ lines.push('## SETUP');
136
+ lines.push('');
137
+ lines.push('```typescript');
138
+ lines.push("import { configure } from './hooks';");
139
+ lines.push("import { QueryClient, QueryClientProvider } from '@tanstack/react-query';");
140
+ lines.push('');
141
+ lines.push("configure({ endpoint: 'https://api.example.com/graphql' });");
142
+ lines.push('const queryClient = new QueryClient();');
143
+ lines.push('// Wrap app in <QueryClientProvider client={queryClient}>');
144
+ lines.push('```');
145
+ lines.push('');
146
+ lines.push('## HOOKS');
147
+ lines.push('');
148
+ for (const table of tables) {
149
+ const { singularName, pluralName } = (0, utils_1.getTableNames)(table);
150
+ const pk = (0, utils_1.getPrimaryKeyInfo)(table)[0];
151
+ const scalarFields = (0, utils_1.getScalarFields)(table);
152
+ lines.push(`### HOOK: ${(0, utils_1.getListQueryHookName)(table)}`);
153
+ lines.push('');
154
+ lines.push(`List all ${pluralName}.`);
155
+ lines.push('');
156
+ lines.push('```');
157
+ lines.push(`TYPE: query`);
158
+ lines.push(`USAGE: ${(0, utils_1.getListQueryHookName)(table)}({ selection: { fields: { ... } } })`);
159
+ lines.push('');
160
+ lines.push('INPUT:');
161
+ lines.push(' selection: { fields: Record<string, boolean> } - Fields to select');
162
+ lines.push('');
163
+ lines.push('OUTPUT: UseQueryResult<Array<{');
164
+ for (const f of scalarFields) {
165
+ lines.push(` ${f.name}: ${(0, utils_1.fieldTypeToTs)(f.type)}`);
166
+ }
167
+ lines.push('}>>');
168
+ lines.push('```');
169
+ lines.push('');
170
+ if ((0, utils_1.hasValidPrimaryKey)(table)) {
171
+ lines.push(`### HOOK: ${(0, utils_1.getSingleQueryHookName)(table)}`);
172
+ lines.push('');
173
+ lines.push(`Get a single ${singularName} by ${pk.name}.`);
174
+ lines.push('');
175
+ lines.push('```');
176
+ lines.push(`TYPE: query`);
177
+ lines.push(`USAGE: ${(0, utils_1.getSingleQueryHookName)(table)}({ ${pk.name}: '<value>', selection: { fields: { ... } } })`);
178
+ lines.push('');
179
+ lines.push('INPUT:');
180
+ lines.push(` ${pk.name}: ${pk.tsType} (required)`);
181
+ lines.push(' selection: { fields: Record<string, boolean> } - Fields to select');
182
+ lines.push('');
183
+ lines.push('OUTPUT: UseQueryResult<{');
184
+ for (const f of scalarFields) {
185
+ lines.push(` ${f.name}: ${(0, utils_1.fieldTypeToTs)(f.type)}`);
186
+ }
187
+ lines.push('}>');
188
+ lines.push('```');
189
+ lines.push('');
190
+ }
191
+ lines.push(`### HOOK: ${(0, utils_1.getCreateMutationHookName)(table)}`);
192
+ lines.push('');
193
+ lines.push(`Create a new ${singularName}.`);
194
+ lines.push('');
195
+ lines.push('```');
196
+ lines.push('TYPE: mutation');
197
+ lines.push(`USAGE: const { mutate } = ${(0, utils_1.getCreateMutationHookName)(table)}({ selection: { fields: { ... } } })`);
198
+ lines.push('');
199
+ lines.push('OUTPUT: UseMutationResult');
200
+ lines.push('```');
201
+ lines.push('');
202
+ if ((0, utils_1.hasValidPrimaryKey)(table)) {
203
+ lines.push(`### HOOK: ${(0, utils_1.getUpdateMutationHookName)(table)}`);
204
+ lines.push('');
205
+ lines.push(`Update an existing ${singularName}.`);
206
+ lines.push('');
207
+ lines.push('```');
208
+ lines.push('TYPE: mutation');
209
+ lines.push(`USAGE: const { mutate } = ${(0, utils_1.getUpdateMutationHookName)(table)}({ selection: { fields: { ... } } })`);
210
+ lines.push('');
211
+ lines.push('OUTPUT: UseMutationResult');
212
+ lines.push('```');
213
+ lines.push('');
214
+ lines.push(`### HOOK: ${(0, utils_1.getDeleteMutationHookName)(table)}`);
215
+ lines.push('');
216
+ lines.push(`Delete a ${singularName}.`);
217
+ lines.push('');
218
+ lines.push('```');
219
+ lines.push('TYPE: mutation');
220
+ lines.push(`USAGE: const { mutate } = ${(0, utils_1.getDeleteMutationHookName)(table)}({})`);
221
+ lines.push('');
222
+ lines.push('OUTPUT: UseMutationResult');
223
+ lines.push('```');
224
+ lines.push('');
225
+ }
226
+ }
227
+ if (customOperations.length > 0) {
228
+ lines.push('## CUSTOM OPERATION HOOKS');
229
+ lines.push('');
230
+ for (const op of customOperations) {
231
+ const hookName = getCustomHookName(op);
232
+ lines.push(`### HOOK: ${hookName}`);
233
+ lines.push('');
234
+ lines.push(op.description || op.name);
235
+ lines.push('');
236
+ lines.push('```');
237
+ lines.push(`TYPE: ${op.kind}`);
238
+ if (op.args.length > 0) {
239
+ if (op.kind === 'mutation') {
240
+ lines.push(`USAGE: const { mutate } = ${hookName}()`);
241
+ lines.push(` mutate({ ${op.args.map((a) => `${a.name}: <value>`).join(', ')} })`);
242
+ }
243
+ else {
244
+ lines.push(`USAGE: ${hookName}({ ${op.args.map((a) => `${a.name}: <value>`).join(', ')} })`);
245
+ }
246
+ lines.push('');
247
+ lines.push('INPUT:');
248
+ for (const arg of op.args) {
249
+ lines.push(` ${arg.name}: ${(0, docs_utils_1.formatArgType)(arg)}`);
250
+ }
251
+ }
252
+ else {
253
+ lines.push(`USAGE: ${hookName}()`);
254
+ lines.push('');
255
+ lines.push('INPUT: none');
256
+ }
257
+ lines.push('');
258
+ lines.push(`OUTPUT: ${op.kind === 'query' ? 'UseQueryResult' : 'UseMutationResult'}`);
259
+ lines.push('```');
260
+ lines.push('');
261
+ }
262
+ }
263
+ return {
264
+ fileName: 'AGENTS.md',
265
+ content: lines.join('\n'),
266
+ };
267
+ }
268
+ function getHooksMcpTools(tables, customOperations) {
269
+ const tools = [];
270
+ for (const table of tables) {
271
+ const { singularName, pluralName } = (0, utils_1.getTableNames)(table);
272
+ const pk = (0, utils_1.getPrimaryKeyInfo)(table)[0];
273
+ const scalarFields = (0, utils_1.getScalarFields)(table);
274
+ tools.push({
275
+ name: `hooks_${(0, utils_1.lcFirst)(pluralName)}_query`,
276
+ description: `React Query hook to list all ${pluralName}`,
277
+ inputSchema: {
278
+ type: 'object',
279
+ properties: {
280
+ fields: {
281
+ type: 'object',
282
+ description: `Fields to select: { ${scalarFields.map((f) => f.name).join(', ')} }`,
283
+ },
284
+ },
285
+ },
286
+ });
287
+ if ((0, utils_1.hasValidPrimaryKey)(table)) {
288
+ tools.push({
289
+ name: `hooks_${(0, utils_1.lcFirst)(singularName)}_query`,
290
+ description: `React Query hook to get a single ${singularName} by ${pk.name}`,
291
+ inputSchema: {
292
+ type: 'object',
293
+ properties: {
294
+ [pk.name]: {
295
+ type: (0, docs_utils_1.gqlTypeToJsonSchemaType)(pk.gqlType),
296
+ description: `${table.name} ${pk.name}`,
297
+ },
298
+ },
299
+ required: [pk.name],
300
+ },
301
+ });
302
+ }
303
+ tools.push({
304
+ name: `hooks_create_${(0, utils_1.lcFirst)(singularName)}_mutation`,
305
+ description: `React Query mutation hook to create a ${singularName}`,
306
+ inputSchema: {
307
+ type: 'object',
308
+ properties: Object.fromEntries(scalarFields
309
+ .filter((f) => f.name !== pk.name &&
310
+ f.name !== 'nodeId' &&
311
+ f.name !== 'createdAt' &&
312
+ f.name !== 'updatedAt')
313
+ .map((f) => [
314
+ f.name,
315
+ {
316
+ type: (0, docs_utils_1.gqlTypeToJsonSchemaType)(f.type.gqlType),
317
+ description: `${table.name} ${f.name}`,
318
+ },
319
+ ])),
320
+ },
321
+ });
322
+ if ((0, utils_1.hasValidPrimaryKey)(table)) {
323
+ tools.push({
324
+ name: `hooks_update_${(0, utils_1.lcFirst)(singularName)}_mutation`,
325
+ description: `React Query mutation hook to update a ${singularName}`,
326
+ inputSchema: {
327
+ type: 'object',
328
+ properties: {
329
+ [pk.name]: {
330
+ type: (0, docs_utils_1.gqlTypeToJsonSchemaType)(pk.gqlType),
331
+ description: `${table.name} ${pk.name}`,
332
+ },
333
+ },
334
+ required: [pk.name],
335
+ },
336
+ });
337
+ tools.push({
338
+ name: `hooks_delete_${(0, utils_1.lcFirst)(singularName)}_mutation`,
339
+ description: `React Query mutation hook to delete a ${singularName}`,
340
+ inputSchema: {
341
+ type: 'object',
342
+ properties: {
343
+ [pk.name]: {
344
+ type: (0, docs_utils_1.gqlTypeToJsonSchemaType)(pk.gqlType),
345
+ description: `${table.name} ${pk.name}`,
346
+ },
347
+ },
348
+ required: [pk.name],
349
+ },
350
+ });
351
+ }
352
+ }
353
+ for (const op of customOperations) {
354
+ const hookName = getCustomHookName(op);
355
+ const props = {};
356
+ const required = [];
357
+ for (const arg of op.args) {
358
+ const isRequired = arg.type.kind === 'NON_NULL';
359
+ const baseType = isRequired && arg.type.ofType ? arg.type.ofType : arg.type;
360
+ props[arg.name] = {
361
+ type: (0, docs_utils_1.gqlTypeToJsonSchemaType)(baseType.name ?? 'String'),
362
+ description: arg.description || arg.name,
363
+ };
364
+ if (isRequired) {
365
+ required.push(arg.name);
366
+ }
367
+ }
368
+ tools.push({
369
+ name: `hooks_${hookName}`,
370
+ description: op.description || `${(0, utils_1.ucFirst)(op.kind)} hook for ${op.name}`,
371
+ inputSchema: {
372
+ type: 'object',
373
+ properties: props,
374
+ ...(required.length > 0 ? { required } : {}),
375
+ },
376
+ });
377
+ }
378
+ return tools;
379
+ }
380
+ function generateHooksSkills(tables, customOperations) {
381
+ const files = [];
382
+ for (const table of tables) {
383
+ const { singularName, pluralName } = (0, utils_1.getTableNames)(table);
384
+ const pk = (0, utils_1.getPrimaryKeyInfo)(table)[0];
385
+ const scalarFields = (0, utils_1.getScalarFields)(table);
386
+ const selectFields = scalarFields
387
+ .map((f) => `${f.name}: true`)
388
+ .join(', ');
389
+ files.push({
390
+ fileName: `skills/${(0, utils_1.lcFirst)(singularName)}.md`,
391
+ content: (0, docs_utils_1.buildSkillFile)({
392
+ name: `hooks-${(0, utils_1.lcFirst)(singularName)}`,
393
+ description: `React Query hooks for ${table.name} data operations`,
394
+ language: 'typescript',
395
+ usage: [
396
+ `${(0, utils_1.getListQueryHookName)(table)}({ selection: { fields: { ${selectFields} } } })`,
397
+ ...((0, utils_1.hasValidPrimaryKey)(table)
398
+ ? [
399
+ `${(0, utils_1.getSingleQueryHookName)(table)}({ ${pk.name}: '<value>', selection: { fields: { ${selectFields} } } })`,
400
+ ]
401
+ : []),
402
+ `${(0, utils_1.getCreateMutationHookName)(table)}({ selection: { fields: { ${pk.name}: true } } })`,
403
+ ...((0, utils_1.hasValidPrimaryKey)(table)
404
+ ? [
405
+ `${(0, utils_1.getUpdateMutationHookName)(table)}({ selection: { fields: { ${pk.name}: true } } })`,
406
+ `${(0, utils_1.getDeleteMutationHookName)(table)}({})`,
407
+ ]
408
+ : []),
409
+ ],
410
+ examples: [
411
+ {
412
+ description: `List all ${pluralName}`,
413
+ code: [
414
+ `const { data, isLoading } = ${(0, utils_1.getListQueryHookName)(table)}({`,
415
+ ` selection: { fields: { ${selectFields} } },`,
416
+ '});',
417
+ ],
418
+ },
419
+ {
420
+ description: `Create a ${singularName}`,
421
+ code: [
422
+ `const { mutate } = ${(0, utils_1.getCreateMutationHookName)(table)}({`,
423
+ ` selection: { fields: { ${pk.name}: true } },`,
424
+ '});',
425
+ `mutate({ ${scalarFields.filter((f) => f.name !== pk.name && f.name !== 'nodeId' && f.name !== 'createdAt' && f.name !== 'updatedAt').map((f) => `${f.name}: '<value>'`).join(', ')} });`,
426
+ ],
427
+ },
428
+ ],
429
+ }),
430
+ });
431
+ }
432
+ for (const op of customOperations) {
433
+ const hookName = getCustomHookName(op);
434
+ const callArgs = op.args.length > 0
435
+ ? `{ ${op.args.map((a) => `${a.name}: '<value>'`).join(', ')} }`
436
+ : '';
437
+ files.push({
438
+ fileName: `skills/${op.name}.md`,
439
+ content: (0, docs_utils_1.buildSkillFile)({
440
+ name: `hooks-${op.name}`,
441
+ description: op.description ||
442
+ `React Query ${op.kind} hook for ${op.name}`,
443
+ language: 'typescript',
444
+ usage: [
445
+ op.kind === 'mutation'
446
+ ? `const { mutate } = ${hookName}(); mutate(${callArgs});`
447
+ : `${hookName}(${callArgs})`,
448
+ ],
449
+ examples: [
450
+ {
451
+ description: `Use ${hookName}`,
452
+ code: op.kind === 'mutation'
453
+ ? [
454
+ `const { mutate, isLoading } = ${hookName}();`,
455
+ ...(callArgs
456
+ ? [`mutate(${callArgs});`]
457
+ : ['mutate();']),
458
+ ]
459
+ : [
460
+ `const { data, isLoading } = ${hookName}(${callArgs});`,
461
+ ],
462
+ },
463
+ ],
464
+ }),
465
+ });
466
+ }
467
+ return files;
468
+ }
@@ -0,0 +1,6 @@
1
+ import type { CleanOperation, CleanTable } from '../../../types/schema';
2
+ import type { GeneratedDocFile, McpTool } from '../docs-utils';
3
+ export declare function generateOrmReadme(tables: CleanTable[], customOperations: CleanOperation[]): GeneratedDocFile;
4
+ export declare function generateOrmAgentsDocs(tables: CleanTable[], customOperations: CleanOperation[]): GeneratedDocFile;
5
+ export declare function getOrmMcpTools(tables: CleanTable[], customOperations: CleanOperation[]): McpTool[];
6
+ export declare function generateOrmSkills(tables: CleanTable[], customOperations: CleanOperation[]): GeneratedDocFile[];