@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,338 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.generateCommandMap = generateCommandMap;
37
+ exports.generateMultiTargetCommandMap = generateMultiTargetCommandMap;
38
+ const t = __importStar(require("@babel/types"));
39
+ const komoji_1 = require("komoji");
40
+ const babel_ast_1 = require("../babel-ast");
41
+ const utils_1 = require("../utils");
42
+ function createImportDeclaration(moduleSpecifier, defaultImportName) {
43
+ return t.importDeclaration([t.importDefaultSpecifier(t.identifier(defaultImportName))], t.stringLiteral(moduleSpecifier));
44
+ }
45
+ function createNamedImportDeclaration(moduleSpecifier, namedImports, typeOnly = false) {
46
+ const specifiers = namedImports.map((name) => t.importSpecifier(t.identifier(name), t.identifier(name)));
47
+ const decl = t.importDeclaration(specifiers, t.stringLiteral(moduleSpecifier));
48
+ decl.importKind = typeOnly ? 'type' : 'value';
49
+ return decl;
50
+ }
51
+ function generateCommandMap(tables, customOperations, toolName) {
52
+ const statements = [];
53
+ statements.push(createNamedImportDeclaration('inquirerer', [
54
+ 'CLIOptions',
55
+ 'Inquirerer',
56
+ 'extractFirst',
57
+ ]));
58
+ const commandEntries = [];
59
+ commandEntries.push({ kebab: 'context', importName: 'contextCmd' });
60
+ statements.push(createImportDeclaration('./commands/context', 'contextCmd'));
61
+ commandEntries.push({ kebab: 'auth', importName: 'authCmd' });
62
+ statements.push(createImportDeclaration('./commands/auth', 'authCmd'));
63
+ for (const table of tables) {
64
+ const { singularName } = (0, utils_1.getTableNames)(table);
65
+ const kebab = (0, komoji_1.toKebabCase)(singularName);
66
+ const importName = `${singularName}Cmd`;
67
+ commandEntries.push({ kebab, importName });
68
+ statements.push(createImportDeclaration(`./commands/${kebab}`, importName));
69
+ }
70
+ for (const op of customOperations) {
71
+ const kebab = (0, komoji_1.toKebabCase)(op.name);
72
+ const importName = `${op.name}Cmd`;
73
+ commandEntries.push({ kebab, importName });
74
+ statements.push(createImportDeclaration(`./commands/${kebab}`, importName));
75
+ }
76
+ const mapProperties = commandEntries.map((entry) => t.objectProperty(t.stringLiteral(entry.kebab), t.identifier(entry.importName)));
77
+ const createCommandMapFunc = t.variableDeclaration('const', [
78
+ t.variableDeclarator(t.identifier('createCommandMap'), t.arrowFunctionExpression([], t.objectExpression(mapProperties))),
79
+ ]);
80
+ const createCommandMapAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Record'), t.tsTypeParameterInstantiation([
81
+ t.tsStringKeyword(),
82
+ t.tsFunctionType(null, [], t.tsTypeAnnotation(t.tsAnyKeyword())),
83
+ ])));
84
+ const createCommandMapId = t.identifier('createCommandMap');
85
+ createCommandMapId.typeAnnotation = t.tsTypeAnnotation(t.tsParenthesizedType(t.tsFunctionType(null, [], t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Record'), t.tsTypeParameterInstantiation([
86
+ t.tsStringKeyword(),
87
+ t.tsFunctionType(null, [], t.tsTypeAnnotation(t.tsUnknownKeyword())),
88
+ ]))))));
89
+ statements.push(createCommandMapFunc);
90
+ const usageLines = [
91
+ '',
92
+ `${toolName} <command>`,
93
+ '',
94
+ 'Commands:',
95
+ ' context Manage API contexts',
96
+ ' auth Manage authentication',
97
+ ];
98
+ for (const table of tables) {
99
+ const { singularName } = (0, utils_1.getTableNames)(table);
100
+ const kebab = (0, komoji_1.toKebabCase)(singularName);
101
+ usageLines.push(` ${kebab.padEnd(20)} ${singularName} CRUD operations`);
102
+ }
103
+ for (const op of customOperations) {
104
+ const kebab = (0, komoji_1.toKebabCase)(op.name);
105
+ usageLines.push(` ${kebab.padEnd(20)} ${op.description || op.name}`);
106
+ }
107
+ usageLines.push('');
108
+ usageLines.push(' --help, -h Show this help message');
109
+ usageLines.push(' --version, -v Show version');
110
+ usageLines.push('');
111
+ statements.push(t.variableDeclaration('const', [
112
+ t.variableDeclarator(t.identifier('usage'), t.stringLiteral(usageLines.join('\n'))),
113
+ ]));
114
+ const argvParam = t.identifier('argv');
115
+ argvParam.typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Partial'), t.tsTypeParameterInstantiation([
116
+ t.tsTypeReference(t.identifier('Record'), t.tsTypeParameterInstantiation([
117
+ t.tsStringKeyword(),
118
+ t.tsUnknownKeyword(),
119
+ ])),
120
+ ])));
121
+ const prompterParam = t.identifier('prompter');
122
+ prompterParam.typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Inquirerer')));
123
+ const optionsParam = t.identifier('options');
124
+ optionsParam.typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CLIOptions')));
125
+ const commandsBody = [
126
+ t.ifStatement(t.logicalExpression('||', t.memberExpression(t.identifier('argv'), t.identifier('help')), t.memberExpression(t.identifier('argv'), t.identifier('h'))), t.blockStatement([
127
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('console'), t.identifier('log')), [t.identifier('usage')])),
128
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('process'), t.identifier('exit')), [t.numericLiteral(0)])),
129
+ ])),
130
+ t.variableDeclaration('let', [
131
+ t.variableDeclarator(t.objectPattern([
132
+ t.objectProperty(t.identifier('first'), t.identifier('command')),
133
+ t.objectProperty(t.identifier('newArgv'), t.identifier('newArgv'), false, true),
134
+ ]), t.callExpression(t.identifier('extractFirst'), [
135
+ t.identifier('argv'),
136
+ ])),
137
+ ]),
138
+ t.variableDeclaration('const', [
139
+ t.variableDeclarator(t.identifier('commandMap'), t.callExpression(t.identifier('createCommandMap'), [])),
140
+ ]),
141
+ t.ifStatement(t.unaryExpression('!', t.identifier('command')), t.blockStatement([
142
+ t.variableDeclaration('const', [
143
+ t.variableDeclarator(t.identifier('answer'), t.awaitExpression(t.callExpression(t.memberExpression(t.identifier('prompter'), t.identifier('prompt')), [
144
+ t.identifier('argv'),
145
+ t.arrayExpression([
146
+ t.objectExpression([
147
+ t.objectProperty(t.identifier('type'), t.stringLiteral('autocomplete')),
148
+ t.objectProperty(t.identifier('name'), t.stringLiteral('command')),
149
+ t.objectProperty(t.identifier('message'), t.stringLiteral('What do you want to do?')),
150
+ t.objectProperty(t.identifier('options'), t.callExpression(t.memberExpression(t.identifier('Object'), t.identifier('keys')), [t.identifier('commandMap')])),
151
+ ]),
152
+ ]),
153
+ ]))),
154
+ ]),
155
+ t.expressionStatement(t.assignmentExpression('=', t.identifier('command'), t.memberExpression(t.identifier('answer'), t.identifier('command')))),
156
+ ])),
157
+ t.variableDeclaration('const', [
158
+ t.variableDeclarator(t.identifier('commandFn'), t.memberExpression(t.identifier('commandMap'), t.identifier('command'), true)),
159
+ ]),
160
+ t.ifStatement(t.unaryExpression('!', t.identifier('commandFn')), t.blockStatement([
161
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('console'), t.identifier('log')), [t.identifier('usage')])),
162
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('console'), t.identifier('error')), [
163
+ t.templateLiteral([
164
+ t.templateElement({
165
+ raw: 'Unknown command: ',
166
+ cooked: 'Unknown command: ',
167
+ }),
168
+ t.templateElement({ raw: '', cooked: '' }, true),
169
+ ], [t.identifier('command')]),
170
+ ])),
171
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('process'), t.identifier('exit')), [t.numericLiteral(1)])),
172
+ ])),
173
+ t.expressionStatement(t.awaitExpression(t.callExpression(t.identifier('commandFn'), [
174
+ t.identifier('newArgv'),
175
+ t.identifier('prompter'),
176
+ t.identifier('options'),
177
+ ]))),
178
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('prompter'), t.identifier('close')), [])),
179
+ t.returnStatement(t.identifier('argv')),
180
+ ];
181
+ const commandsFunc = t.arrowFunctionExpression([argvParam, prompterParam, optionsParam], t.blockStatement(commandsBody), true);
182
+ const commandsDecl = t.variableDeclaration('const', [
183
+ t.variableDeclarator(t.identifier('commands'), commandsFunc),
184
+ ]);
185
+ statements.push(t.exportNamedDeclaration(commandsDecl));
186
+ const header = (0, utils_1.getGeneratedFileHeader)('CLI command map and entry point');
187
+ const code = (0, babel_ast_1.generateCode)(statements);
188
+ return {
189
+ fileName: 'commands.ts',
190
+ content: header + '\n' + code,
191
+ };
192
+ }
193
+ function generateMultiTargetCommandMap(input) {
194
+ const { toolName, builtinNames, targets } = input;
195
+ const statements = [];
196
+ statements.push(createNamedImportDeclaration('inquirerer', [
197
+ 'CLIOptions',
198
+ 'Inquirerer',
199
+ 'extractFirst',
200
+ ]));
201
+ const commandEntries = [];
202
+ const contextImportName = `${builtinNames.context}Cmd`;
203
+ commandEntries.push({ kebab: builtinNames.context, importName: contextImportName });
204
+ statements.push(createImportDeclaration(`./commands/${builtinNames.context}`, contextImportName));
205
+ const authImportName = `${builtinNames.auth}Cmd`;
206
+ commandEntries.push({ kebab: builtinNames.auth, importName: authImportName });
207
+ statements.push(createImportDeclaration(`./commands/${builtinNames.auth}`, authImportName));
208
+ for (const target of targets) {
209
+ for (const table of target.tables) {
210
+ const { singularName } = (0, utils_1.getTableNames)(table);
211
+ const kebab = (0, komoji_1.toKebabCase)(singularName);
212
+ const prefixedKebab = `${target.name}:${kebab}`;
213
+ const importName = `${target.name}${singularName[0].toUpperCase()}${singularName.slice(1)}Cmd`;
214
+ commandEntries.push({ kebab: prefixedKebab, importName });
215
+ statements.push(createImportDeclaration(`./commands/${target.name}/${kebab}`, importName));
216
+ }
217
+ for (const op of target.customOperations) {
218
+ const kebab = (0, komoji_1.toKebabCase)(op.name);
219
+ const prefixedKebab = `${target.name}:${kebab}`;
220
+ const importName = `${target.name}${op.name[0].toUpperCase()}${op.name.slice(1)}Cmd`;
221
+ commandEntries.push({ kebab: prefixedKebab, importName });
222
+ statements.push(createImportDeclaration(`./commands/${target.name}/${kebab}`, importName));
223
+ }
224
+ }
225
+ const mapProperties = commandEntries.map((entry) => t.objectProperty(t.stringLiteral(entry.kebab), t.identifier(entry.importName)));
226
+ const createCommandMapFunc = t.variableDeclaration('const', [
227
+ t.variableDeclarator(t.identifier('createCommandMap'), t.arrowFunctionExpression([], t.objectExpression(mapProperties))),
228
+ ]);
229
+ statements.push(createCommandMapFunc);
230
+ const usageLines = [
231
+ '',
232
+ `${toolName} <command>`,
233
+ '',
234
+ 'Commands:',
235
+ ` ${builtinNames.context.padEnd(20)} Manage API contexts`,
236
+ ` ${builtinNames.auth.padEnd(20)} Manage authentication`,
237
+ ];
238
+ for (const target of targets) {
239
+ usageLines.push('');
240
+ usageLines.push(` ${target.name}:`);
241
+ for (const table of target.tables) {
242
+ const { singularName } = (0, utils_1.getTableNames)(table);
243
+ const kebab = (0, komoji_1.toKebabCase)(singularName);
244
+ const cmd = `${target.name}:${kebab}`;
245
+ usageLines.push(` ${cmd.padEnd(22)} ${singularName} CRUD operations`);
246
+ }
247
+ for (const op of target.customOperations) {
248
+ const kebab = (0, komoji_1.toKebabCase)(op.name);
249
+ const cmd = `${target.name}:${kebab}`;
250
+ usageLines.push(` ${cmd.padEnd(22)} ${op.description || op.name}`);
251
+ }
252
+ }
253
+ usageLines.push('');
254
+ usageLines.push(' --help, -h Show this help message');
255
+ usageLines.push(' --version, -v Show version');
256
+ usageLines.push('');
257
+ statements.push(t.variableDeclaration('const', [
258
+ t.variableDeclarator(t.identifier('usage'), t.stringLiteral(usageLines.join('\n'))),
259
+ ]));
260
+ const argvParam = t.identifier('argv');
261
+ argvParam.typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Partial'), t.tsTypeParameterInstantiation([
262
+ t.tsTypeReference(t.identifier('Record'), t.tsTypeParameterInstantiation([
263
+ t.tsStringKeyword(),
264
+ t.tsUnknownKeyword(),
265
+ ])),
266
+ ])));
267
+ const prompterParam = t.identifier('prompter');
268
+ prompterParam.typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Inquirerer')));
269
+ const optionsParam = t.identifier('options');
270
+ optionsParam.typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CLIOptions')));
271
+ const commandsBody = [
272
+ t.ifStatement(t.logicalExpression('||', t.memberExpression(t.identifier('argv'), t.identifier('help')), t.memberExpression(t.identifier('argv'), t.identifier('h'))), t.blockStatement([
273
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('console'), t.identifier('log')), [t.identifier('usage')])),
274
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('process'), t.identifier('exit')), [t.numericLiteral(0)])),
275
+ ])),
276
+ t.variableDeclaration('let', [
277
+ t.variableDeclarator(t.objectPattern([
278
+ t.objectProperty(t.identifier('first'), t.identifier('command')),
279
+ t.objectProperty(t.identifier('newArgv'), t.identifier('newArgv'), false, true),
280
+ ]), t.callExpression(t.identifier('extractFirst'), [
281
+ t.identifier('argv'),
282
+ ])),
283
+ ]),
284
+ t.variableDeclaration('const', [
285
+ t.variableDeclarator(t.identifier('commandMap'), t.callExpression(t.identifier('createCommandMap'), [])),
286
+ ]),
287
+ t.ifStatement(t.unaryExpression('!', t.identifier('command')), t.blockStatement([
288
+ t.variableDeclaration('const', [
289
+ t.variableDeclarator(t.identifier('answer'), t.awaitExpression(t.callExpression(t.memberExpression(t.identifier('prompter'), t.identifier('prompt')), [
290
+ t.identifier('argv'),
291
+ t.arrayExpression([
292
+ t.objectExpression([
293
+ t.objectProperty(t.identifier('type'), t.stringLiteral('autocomplete')),
294
+ t.objectProperty(t.identifier('name'), t.stringLiteral('command')),
295
+ t.objectProperty(t.identifier('message'), t.stringLiteral('What do you want to do?')),
296
+ t.objectProperty(t.identifier('options'), t.callExpression(t.memberExpression(t.identifier('Object'), t.identifier('keys')), [t.identifier('commandMap')])),
297
+ ]),
298
+ ]),
299
+ ]))),
300
+ ]),
301
+ t.expressionStatement(t.assignmentExpression('=', t.identifier('command'), t.memberExpression(t.identifier('answer'), t.identifier('command')))),
302
+ ])),
303
+ t.variableDeclaration('const', [
304
+ t.variableDeclarator(t.identifier('commandFn'), t.memberExpression(t.identifier('commandMap'), t.identifier('command'), true)),
305
+ ]),
306
+ t.ifStatement(t.unaryExpression('!', t.identifier('commandFn')), t.blockStatement([
307
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('console'), t.identifier('log')), [t.identifier('usage')])),
308
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('console'), t.identifier('error')), [
309
+ t.templateLiteral([
310
+ t.templateElement({
311
+ raw: 'Unknown command: ',
312
+ cooked: 'Unknown command: ',
313
+ }),
314
+ t.templateElement({ raw: '', cooked: '' }, true),
315
+ ], [t.identifier('command')]),
316
+ ])),
317
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('process'), t.identifier('exit')), [t.numericLiteral(1)])),
318
+ ])),
319
+ t.expressionStatement(t.awaitExpression(t.callExpression(t.identifier('commandFn'), [
320
+ t.identifier('newArgv'),
321
+ t.identifier('prompter'),
322
+ t.identifier('options'),
323
+ ]))),
324
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('prompter'), t.identifier('close')), [])),
325
+ t.returnStatement(t.identifier('argv')),
326
+ ];
327
+ const commandsFunc = t.arrowFunctionExpression([argvParam, prompterParam, optionsParam], t.blockStatement(commandsBody), true);
328
+ const commandsDecl = t.variableDeclaration('const', [
329
+ t.variableDeclarator(t.identifier('commands'), commandsFunc),
330
+ ]);
331
+ statements.push(t.exportNamedDeclaration(commandsDecl));
332
+ const header = (0, utils_1.getGeneratedFileHeader)('Multi-target CLI command map and entry point');
333
+ const code = (0, babel_ast_1.generateCode)(statements);
334
+ return {
335
+ fileName: 'commands.ts',
336
+ content: header + '\n' + code,
337
+ };
338
+ }
@@ -0,0 +1,8 @@
1
+ import type { CleanOperation } from '../../../types/schema';
2
+ import type { GeneratedFile } from './executor-generator';
3
+ export interface CustomCommandOptions {
4
+ targetName?: string;
5
+ executorImportPath?: string;
6
+ saveToken?: boolean;
7
+ }
8
+ export declare function generateCustomCommand(op: CleanOperation, options?: CustomCommandOptions): GeneratedFile;
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.generateCustomCommand = generateCustomCommand;
37
+ const t = __importStar(require("@babel/types"));
38
+ const komoji_1 = require("komoji");
39
+ const babel_ast_1 = require("../babel-ast");
40
+ const utils_1 = require("../utils");
41
+ const arg_mapper_1 = require("./arg-mapper");
42
+ function createImportDeclaration(moduleSpecifier, namedImports, typeOnly = false) {
43
+ const specifiers = namedImports.map((name) => t.importSpecifier(t.identifier(name), t.identifier(name)));
44
+ const decl = t.importDeclaration(specifiers, t.stringLiteral(moduleSpecifier));
45
+ decl.importKind = typeOnly ? 'type' : 'value';
46
+ return decl;
47
+ }
48
+ function buildArgvType() {
49
+ return t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Partial'), t.tsTypeParameterInstantiation([
50
+ t.tsTypeReference(t.identifier('Record'), t.tsTypeParameterInstantiation([
51
+ t.tsStringKeyword(),
52
+ t.tsUnknownKeyword(),
53
+ ])),
54
+ ])));
55
+ }
56
+ function buildJsonLog(expr) {
57
+ return t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('console'), t.identifier('log')), [
58
+ t.callExpression(t.memberExpression(t.identifier('JSON'), t.identifier('stringify')), [expr, t.nullLiteral(), t.numericLiteral(2)]),
59
+ ]));
60
+ }
61
+ function buildErrorCatch(errorMessage) {
62
+ return t.catchClause(t.identifier('error'), t.blockStatement([
63
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('console'), t.identifier('error')), [t.stringLiteral(errorMessage)])),
64
+ t.ifStatement(t.binaryExpression('instanceof', t.identifier('error'), t.identifier('Error')), t.blockStatement([
65
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('console'), t.identifier('error')), [
66
+ t.memberExpression(t.identifier('error'), t.identifier('message')),
67
+ ])),
68
+ ])),
69
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('process'), t.identifier('exit')), [t.numericLiteral(1)])),
70
+ ]));
71
+ }
72
+ function buildOrmCustomCall(opKind, opName, argsExpr) {
73
+ return t.callExpression(t.memberExpression(t.callExpression(t.memberExpression(t.memberExpression(t.identifier('client'), t.identifier(opKind)), t.identifier(opName)), [argsExpr]), t.identifier('execute')), []);
74
+ }
75
+ function generateCustomCommand(op, options) {
76
+ const commandName = (0, komoji_1.toKebabCase)(op.name);
77
+ const opKind = op.kind === 'mutation' ? 'mutation' : 'query';
78
+ const statements = [];
79
+ const executorPath = options?.executorImportPath ?? '../executor';
80
+ const imports = ['getClient'];
81
+ if (options?.saveToken) {
82
+ imports.push('getStore');
83
+ }
84
+ statements.push(createImportDeclaration('inquirerer', ['CLIOptions', 'Inquirerer']));
85
+ statements.push(createImportDeclaration(executorPath, imports));
86
+ const questionsArray = op.args.length > 0
87
+ ? (0, arg_mapper_1.buildQuestionsArray)(op.args)
88
+ : t.arrayExpression([]);
89
+ const argvParam = t.identifier('argv');
90
+ argvParam.typeAnnotation = buildArgvType();
91
+ const prompterParam = t.identifier('prompter');
92
+ prompterParam.typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Inquirerer')));
93
+ const optionsParam = t.identifier('_options');
94
+ optionsParam.typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CLIOptions')));
95
+ const bodyStatements = [
96
+ t.ifStatement(t.logicalExpression('||', t.memberExpression(t.identifier('argv'), t.identifier('help')), t.memberExpression(t.identifier('argv'), t.identifier('h'))), t.blockStatement([
97
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('console'), t.identifier('log')), [
98
+ t.stringLiteral(`${commandName} - ${op.description || op.name}\n\nUsage: ${commandName} [OPTIONS]\n`),
99
+ ])),
100
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('process'), t.identifier('exit')), [t.numericLiteral(0)])),
101
+ ])),
102
+ ];
103
+ if (op.args.length > 0) {
104
+ bodyStatements.push(t.variableDeclaration('const', [
105
+ t.variableDeclarator(t.identifier('answers'), t.awaitExpression(t.callExpression(t.memberExpression(t.identifier('prompter'), t.identifier('prompt')), [t.identifier('argv'), questionsArray]))),
106
+ ]));
107
+ }
108
+ const getClientArgs = options?.targetName
109
+ ? [t.stringLiteral(options.targetName)]
110
+ : [];
111
+ bodyStatements.push(t.variableDeclaration('const', [
112
+ t.variableDeclarator(t.identifier('client'), t.callExpression(t.identifier('getClient'), getClientArgs)),
113
+ ]));
114
+ const argsExpr = op.args.length > 0
115
+ ? t.identifier('answers')
116
+ : t.objectExpression([]);
117
+ bodyStatements.push(t.variableDeclaration('const', [
118
+ t.variableDeclarator(t.identifier('result'), t.awaitExpression(buildOrmCustomCall(opKind, op.name, argsExpr))),
119
+ ]));
120
+ if (options?.saveToken) {
121
+ bodyStatements.push(t.ifStatement(t.logicalExpression('&&', t.memberExpression(t.identifier('argv'), t.identifier('saveToken')), t.identifier('result')), t.blockStatement([
122
+ t.variableDeclaration('const', [
123
+ t.variableDeclarator(t.identifier('tokenValue'), t.logicalExpression('||', t.memberExpression(t.identifier('result'), t.identifier('token'), false), t.logicalExpression('||', t.memberExpression(t.identifier('result'), t.identifier('jwtToken'), false), t.memberExpression(t.identifier('result'), t.identifier('accessToken'), false)))),
124
+ ]),
125
+ t.ifStatement(t.identifier('tokenValue'), t.blockStatement([
126
+ t.variableDeclaration('const', [
127
+ t.variableDeclarator(t.identifier('s'), t.callExpression(t.identifier('getStore'), [])),
128
+ ]),
129
+ t.variableDeclaration('const', [
130
+ t.variableDeclarator(t.identifier('ctx'), t.callExpression(t.memberExpression(t.identifier('s'), t.identifier('getCurrentContext')), [])),
131
+ ]),
132
+ t.ifStatement(t.identifier('ctx'), t.blockStatement([
133
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('s'), t.identifier('setCredentials')), [
134
+ t.memberExpression(t.identifier('ctx'), t.identifier('name')),
135
+ t.objectExpression([
136
+ t.objectProperty(t.identifier('token'), t.identifier('tokenValue')),
137
+ ]),
138
+ ])),
139
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('console'), t.identifier('log')), [t.stringLiteral('Token saved to current context.')])),
140
+ ])),
141
+ ])),
142
+ ])));
143
+ }
144
+ bodyStatements.push(buildJsonLog(t.identifier('result')));
145
+ const tryBlock = t.tryStatement(t.blockStatement(bodyStatements), buildErrorCatch(`Failed: ${op.name}`));
146
+ statements.push(t.exportDefaultDeclaration(t.arrowFunctionExpression([argvParam, prompterParam, optionsParam], t.blockStatement([tryBlock]), true)));
147
+ const header = (0, utils_1.getGeneratedFileHeader)(`CLI command for ${op.kind} ${op.name}`);
148
+ const code = (0, babel_ast_1.generateCode)(statements);
149
+ return {
150
+ fileName: options?.targetName
151
+ ? `commands/${options.targetName}/${commandName}.ts`
152
+ : `commands/${commandName}.ts`,
153
+ content: header + '\n' + code,
154
+ };
155
+ }
@@ -0,0 +1,26 @@
1
+ import type { CleanTable, CleanOperation } from '../../../types/schema';
2
+ import type { GeneratedDocFile, McpTool } from '../docs-utils';
3
+ export { resolveDocsConfig } from '../docs-utils';
4
+ export type { GeneratedDocFile, McpTool } from '../docs-utils';
5
+ export declare function generateReadme(tables: CleanTable[], customOperations: CleanOperation[], toolName: string): GeneratedDocFile;
6
+ export declare function generateAgentsDocs(tables: CleanTable[], customOperations: CleanOperation[], toolName: string): GeneratedDocFile;
7
+ export declare function getCliMcpTools(tables: CleanTable[], customOperations: CleanOperation[], toolName: string): McpTool[];
8
+ export declare function generateSkills(tables: CleanTable[], customOperations: CleanOperation[], toolName: string): GeneratedDocFile[];
9
+ export interface MultiTargetDocsInput {
10
+ toolName: string;
11
+ builtinNames: {
12
+ auth: string;
13
+ context: string;
14
+ };
15
+ targets: Array<{
16
+ name: string;
17
+ endpoint: string;
18
+ tables: CleanTable[];
19
+ customOperations: CleanOperation[];
20
+ isAuthTarget?: boolean;
21
+ }>;
22
+ }
23
+ export declare function generateMultiTargetReadme(input: MultiTargetDocsInput): GeneratedDocFile;
24
+ export declare function generateMultiTargetAgentsDocs(input: MultiTargetDocsInput): GeneratedDocFile;
25
+ export declare function getMultiTargetCliMcpTools(input: MultiTargetDocsInput): McpTool[];
26
+ export declare function generateMultiTargetSkills(input: MultiTargetDocsInput): GeneratedDocFile[];