@constructive-io/graphql-codegen 4.0.2 → 4.1.1

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 (93) hide show
  1. package/cli/handler.d.ts +13 -0
  2. package/cli/handler.js +74 -0
  3. package/cli/index.js +11 -57
  4. package/core/codegen/barrel.d.ts +1 -0
  5. package/core/codegen/barrel.js +5 -2
  6. package/core/codegen/cli/arg-mapper.d.ts +4 -0
  7. package/core/codegen/cli/arg-mapper.js +117 -0
  8. package/core/codegen/cli/command-map-generator.d.ts +16 -0
  9. package/core/codegen/cli/command-map-generator.js +338 -0
  10. package/core/codegen/cli/custom-command-generator.d.ts +8 -0
  11. package/core/codegen/cli/custom-command-generator.js +155 -0
  12. package/core/codegen/cli/docs-generator.d.ts +26 -0
  13. package/core/codegen/cli/docs-generator.js +1399 -0
  14. package/core/codegen/cli/executor-generator.d.ts +11 -0
  15. package/core/codegen/cli/executor-generator.js +217 -0
  16. package/core/codegen/cli/index.d.ts +53 -0
  17. package/core/codegen/cli/index.js +153 -0
  18. package/core/codegen/cli/infra-generator.d.ts +9 -0
  19. package/core/codegen/cli/infra-generator.js +1195 -0
  20. package/core/codegen/cli/table-command-generator.d.ts +7 -0
  21. package/core/codegen/cli/table-command-generator.js +323 -0
  22. package/core/codegen/docs-utils.d.ts +30 -0
  23. package/core/codegen/docs-utils.js +122 -0
  24. package/core/codegen/hooks-docs-generator.d.ts +6 -0
  25. package/core/codegen/hooks-docs-generator.js +468 -0
  26. package/core/codegen/orm/docs-generator.d.ts +6 -0
  27. package/core/codegen/orm/docs-generator.js +416 -0
  28. package/core/codegen/target-docs-generator.d.ts +20 -0
  29. package/core/codegen/target-docs-generator.js +110 -0
  30. package/core/database/index.d.ts +0 -12
  31. package/core/database/index.js +2 -19
  32. package/core/generate.d.ts +34 -2
  33. package/core/generate.js +453 -12
  34. package/core/index.d.ts +0 -2
  35. package/core/index.js +0 -2
  36. package/core/introspect/source/database.js +2 -2
  37. package/core/introspect/source/pgpm-module.js +2 -2
  38. package/core/output/index.d.ts +1 -1
  39. package/core/output/index.js +1 -2
  40. package/core/output/writer.d.ts +0 -10
  41. package/core/output/writer.js +0 -31
  42. package/esm/cli/handler.d.ts +13 -0
  43. package/esm/cli/handler.js +71 -0
  44. package/esm/cli/index.js +11 -57
  45. package/esm/core/codegen/barrel.d.ts +1 -0
  46. package/esm/core/codegen/barrel.js +5 -2
  47. package/esm/core/codegen/cli/arg-mapper.d.ts +4 -0
  48. package/esm/core/codegen/cli/arg-mapper.js +80 -0
  49. package/esm/core/codegen/cli/command-map-generator.d.ts +16 -0
  50. package/esm/core/codegen/cli/command-map-generator.js +301 -0
  51. package/esm/core/codegen/cli/custom-command-generator.d.ts +8 -0
  52. package/esm/core/codegen/cli/custom-command-generator.js +119 -0
  53. package/esm/core/codegen/cli/docs-generator.d.ts +26 -0
  54. package/esm/core/codegen/cli/docs-generator.js +1387 -0
  55. package/esm/core/codegen/cli/executor-generator.d.ts +11 -0
  56. package/esm/core/codegen/cli/executor-generator.js +180 -0
  57. package/esm/core/codegen/cli/index.d.ts +53 -0
  58. package/esm/core/codegen/cli/index.js +128 -0
  59. package/esm/core/codegen/cli/infra-generator.d.ts +9 -0
  60. package/esm/core/codegen/cli/infra-generator.js +1156 -0
  61. package/esm/core/codegen/cli/table-command-generator.d.ts +7 -0
  62. package/esm/core/codegen/cli/table-command-generator.js +287 -0
  63. package/esm/core/codegen/docs-utils.d.ts +30 -0
  64. package/esm/core/codegen/docs-utils.js +112 -0
  65. package/esm/core/codegen/hooks-docs-generator.d.ts +6 -0
  66. package/esm/core/codegen/hooks-docs-generator.js +462 -0
  67. package/esm/core/codegen/orm/docs-generator.d.ts +6 -0
  68. package/esm/core/codegen/orm/docs-generator.js +410 -0
  69. package/esm/core/codegen/target-docs-generator.d.ts +20 -0
  70. package/esm/core/codegen/target-docs-generator.js +105 -0
  71. package/esm/core/database/index.d.ts +0 -12
  72. package/esm/core/database/index.js +1 -17
  73. package/esm/core/generate.d.ts +34 -2
  74. package/esm/core/generate.js +417 -12
  75. package/esm/core/index.d.ts +0 -2
  76. package/esm/core/index.js +0 -2
  77. package/esm/core/introspect/source/database.js +2 -2
  78. package/esm/core/introspect/source/pgpm-module.js +2 -2
  79. package/esm/core/output/index.d.ts +1 -1
  80. package/esm/core/output/index.js +1 -1
  81. package/esm/core/output/writer.d.ts +0 -10
  82. package/esm/core/output/writer.js +0 -30
  83. package/esm/generators/index.d.ts +0 -3
  84. package/esm/generators/index.js +0 -3
  85. package/esm/index.d.ts +4 -3
  86. package/esm/index.js +4 -2
  87. package/esm/types/config.d.ts +78 -0
  88. package/generators/index.d.ts +0 -3
  89. package/generators/index.js +0 -3
  90. package/index.d.ts +4 -3
  91. package/index.js +7 -2
  92. package/package.json +8 -7
  93. package/types/config.d.ts +78 -0
@@ -0,0 +1,119 @@
1
+ import * as t from '@babel/types';
2
+ import { toKebabCase } from 'komoji';
3
+ import { generateCode } from '../babel-ast';
4
+ import { getGeneratedFileHeader } from '../utils';
5
+ import { buildQuestionsArray } from './arg-mapper';
6
+ function createImportDeclaration(moduleSpecifier, namedImports, typeOnly = false) {
7
+ const specifiers = namedImports.map((name) => t.importSpecifier(t.identifier(name), t.identifier(name)));
8
+ const decl = t.importDeclaration(specifiers, t.stringLiteral(moduleSpecifier));
9
+ decl.importKind = typeOnly ? 'type' : 'value';
10
+ return decl;
11
+ }
12
+ function buildArgvType() {
13
+ return t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Partial'), t.tsTypeParameterInstantiation([
14
+ t.tsTypeReference(t.identifier('Record'), t.tsTypeParameterInstantiation([
15
+ t.tsStringKeyword(),
16
+ t.tsUnknownKeyword(),
17
+ ])),
18
+ ])));
19
+ }
20
+ function buildJsonLog(expr) {
21
+ return t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('console'), t.identifier('log')), [
22
+ t.callExpression(t.memberExpression(t.identifier('JSON'), t.identifier('stringify')), [expr, t.nullLiteral(), t.numericLiteral(2)]),
23
+ ]));
24
+ }
25
+ function buildErrorCatch(errorMessage) {
26
+ return t.catchClause(t.identifier('error'), t.blockStatement([
27
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('console'), t.identifier('error')), [t.stringLiteral(errorMessage)])),
28
+ t.ifStatement(t.binaryExpression('instanceof', t.identifier('error'), t.identifier('Error')), t.blockStatement([
29
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('console'), t.identifier('error')), [
30
+ t.memberExpression(t.identifier('error'), t.identifier('message')),
31
+ ])),
32
+ ])),
33
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('process'), t.identifier('exit')), [t.numericLiteral(1)])),
34
+ ]));
35
+ }
36
+ function buildOrmCustomCall(opKind, opName, argsExpr) {
37
+ return t.callExpression(t.memberExpression(t.callExpression(t.memberExpression(t.memberExpression(t.identifier('client'), t.identifier(opKind)), t.identifier(opName)), [argsExpr]), t.identifier('execute')), []);
38
+ }
39
+ export function generateCustomCommand(op, options) {
40
+ const commandName = toKebabCase(op.name);
41
+ const opKind = op.kind === 'mutation' ? 'mutation' : 'query';
42
+ const statements = [];
43
+ const executorPath = options?.executorImportPath ?? '../executor';
44
+ const imports = ['getClient'];
45
+ if (options?.saveToken) {
46
+ imports.push('getStore');
47
+ }
48
+ statements.push(createImportDeclaration('inquirerer', ['CLIOptions', 'Inquirerer']));
49
+ statements.push(createImportDeclaration(executorPath, imports));
50
+ const questionsArray = op.args.length > 0
51
+ ? buildQuestionsArray(op.args)
52
+ : t.arrayExpression([]);
53
+ const argvParam = t.identifier('argv');
54
+ argvParam.typeAnnotation = buildArgvType();
55
+ const prompterParam = t.identifier('prompter');
56
+ prompterParam.typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Inquirerer')));
57
+ const optionsParam = t.identifier('_options');
58
+ optionsParam.typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CLIOptions')));
59
+ const bodyStatements = [
60
+ t.ifStatement(t.logicalExpression('||', t.memberExpression(t.identifier('argv'), t.identifier('help')), t.memberExpression(t.identifier('argv'), t.identifier('h'))), t.blockStatement([
61
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('console'), t.identifier('log')), [
62
+ t.stringLiteral(`${commandName} - ${op.description || op.name}\n\nUsage: ${commandName} [OPTIONS]\n`),
63
+ ])),
64
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('process'), t.identifier('exit')), [t.numericLiteral(0)])),
65
+ ])),
66
+ ];
67
+ if (op.args.length > 0) {
68
+ bodyStatements.push(t.variableDeclaration('const', [
69
+ t.variableDeclarator(t.identifier('answers'), t.awaitExpression(t.callExpression(t.memberExpression(t.identifier('prompter'), t.identifier('prompt')), [t.identifier('argv'), questionsArray]))),
70
+ ]));
71
+ }
72
+ const getClientArgs = options?.targetName
73
+ ? [t.stringLiteral(options.targetName)]
74
+ : [];
75
+ bodyStatements.push(t.variableDeclaration('const', [
76
+ t.variableDeclarator(t.identifier('client'), t.callExpression(t.identifier('getClient'), getClientArgs)),
77
+ ]));
78
+ const argsExpr = op.args.length > 0
79
+ ? t.identifier('answers')
80
+ : t.objectExpression([]);
81
+ bodyStatements.push(t.variableDeclaration('const', [
82
+ t.variableDeclarator(t.identifier('result'), t.awaitExpression(buildOrmCustomCall(opKind, op.name, argsExpr))),
83
+ ]));
84
+ if (options?.saveToken) {
85
+ bodyStatements.push(t.ifStatement(t.logicalExpression('&&', t.memberExpression(t.identifier('argv'), t.identifier('saveToken')), t.identifier('result')), t.blockStatement([
86
+ t.variableDeclaration('const', [
87
+ 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)))),
88
+ ]),
89
+ t.ifStatement(t.identifier('tokenValue'), t.blockStatement([
90
+ t.variableDeclaration('const', [
91
+ t.variableDeclarator(t.identifier('s'), t.callExpression(t.identifier('getStore'), [])),
92
+ ]),
93
+ t.variableDeclaration('const', [
94
+ t.variableDeclarator(t.identifier('ctx'), t.callExpression(t.memberExpression(t.identifier('s'), t.identifier('getCurrentContext')), [])),
95
+ ]),
96
+ t.ifStatement(t.identifier('ctx'), t.blockStatement([
97
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('s'), t.identifier('setCredentials')), [
98
+ t.memberExpression(t.identifier('ctx'), t.identifier('name')),
99
+ t.objectExpression([
100
+ t.objectProperty(t.identifier('token'), t.identifier('tokenValue')),
101
+ ]),
102
+ ])),
103
+ t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('console'), t.identifier('log')), [t.stringLiteral('Token saved to current context.')])),
104
+ ])),
105
+ ])),
106
+ ])));
107
+ }
108
+ bodyStatements.push(buildJsonLog(t.identifier('result')));
109
+ const tryBlock = t.tryStatement(t.blockStatement(bodyStatements), buildErrorCatch(`Failed: ${op.name}`));
110
+ statements.push(t.exportDefaultDeclaration(t.arrowFunctionExpression([argvParam, prompterParam, optionsParam], t.blockStatement([tryBlock]), true)));
111
+ const header = getGeneratedFileHeader(`CLI command for ${op.kind} ${op.name}`);
112
+ const code = generateCode(statements);
113
+ return {
114
+ fileName: options?.targetName
115
+ ? `commands/${options.targetName}/${commandName}.ts`
116
+ : `commands/${commandName}.ts`,
117
+ content: header + '\n' + code,
118
+ };
119
+ }
@@ -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[];