@constructive-io/graphql-codegen 4.0.2 → 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.
- package/cli/handler.d.ts +13 -0
- package/cli/handler.js +74 -0
- package/cli/index.js +11 -57
- package/core/codegen/barrel.d.ts +1 -0
- package/core/codegen/barrel.js +5 -2
- package/core/codegen/cli/arg-mapper.d.ts +4 -0
- package/core/codegen/cli/arg-mapper.js +117 -0
- package/core/codegen/cli/command-map-generator.d.ts +16 -0
- package/core/codegen/cli/command-map-generator.js +338 -0
- package/core/codegen/cli/custom-command-generator.d.ts +8 -0
- package/core/codegen/cli/custom-command-generator.js +155 -0
- package/core/codegen/cli/docs-generator.d.ts +26 -0
- package/core/codegen/cli/docs-generator.js +1399 -0
- package/core/codegen/cli/executor-generator.d.ts +11 -0
- package/core/codegen/cli/executor-generator.js +217 -0
- package/core/codegen/cli/index.d.ts +53 -0
- package/core/codegen/cli/index.js +153 -0
- package/core/codegen/cli/infra-generator.d.ts +9 -0
- package/core/codegen/cli/infra-generator.js +1195 -0
- package/core/codegen/cli/table-command-generator.d.ts +7 -0
- package/core/codegen/cli/table-command-generator.js +323 -0
- package/core/codegen/docs-utils.d.ts +30 -0
- package/core/codegen/docs-utils.js +122 -0
- package/core/codegen/hooks-docs-generator.d.ts +6 -0
- package/core/codegen/hooks-docs-generator.js +468 -0
- package/core/codegen/orm/docs-generator.d.ts +6 -0
- package/core/codegen/orm/docs-generator.js +416 -0
- package/core/codegen/target-docs-generator.d.ts +20 -0
- package/core/codegen/target-docs-generator.js +110 -0
- package/core/database/index.d.ts +0 -12
- package/core/database/index.js +2 -19
- package/core/generate.d.ts +34 -2
- package/core/generate.js +453 -12
- package/core/index.d.ts +0 -2
- package/core/index.js +0 -2
- package/core/introspect/source/database.js +2 -2
- package/core/introspect/source/pgpm-module.js +2 -2
- package/core/output/index.d.ts +1 -1
- package/core/output/index.js +1 -2
- package/core/output/writer.d.ts +0 -10
- package/core/output/writer.js +0 -31
- package/esm/cli/handler.d.ts +13 -0
- package/esm/cli/handler.js +71 -0
- package/esm/cli/index.js +11 -57
- package/esm/core/codegen/barrel.d.ts +1 -0
- package/esm/core/codegen/barrel.js +5 -2
- package/esm/core/codegen/cli/arg-mapper.d.ts +4 -0
- package/esm/core/codegen/cli/arg-mapper.js +80 -0
- package/esm/core/codegen/cli/command-map-generator.d.ts +16 -0
- package/esm/core/codegen/cli/command-map-generator.js +301 -0
- package/esm/core/codegen/cli/custom-command-generator.d.ts +8 -0
- package/esm/core/codegen/cli/custom-command-generator.js +119 -0
- package/esm/core/codegen/cli/docs-generator.d.ts +26 -0
- package/esm/core/codegen/cli/docs-generator.js +1387 -0
- package/esm/core/codegen/cli/executor-generator.d.ts +11 -0
- package/esm/core/codegen/cli/executor-generator.js +180 -0
- package/esm/core/codegen/cli/index.d.ts +53 -0
- package/esm/core/codegen/cli/index.js +128 -0
- package/esm/core/codegen/cli/infra-generator.d.ts +9 -0
- package/esm/core/codegen/cli/infra-generator.js +1156 -0
- package/esm/core/codegen/cli/table-command-generator.d.ts +7 -0
- package/esm/core/codegen/cli/table-command-generator.js +287 -0
- package/esm/core/codegen/docs-utils.d.ts +30 -0
- package/esm/core/codegen/docs-utils.js +112 -0
- package/esm/core/codegen/hooks-docs-generator.d.ts +6 -0
- package/esm/core/codegen/hooks-docs-generator.js +462 -0
- package/esm/core/codegen/orm/docs-generator.d.ts +6 -0
- package/esm/core/codegen/orm/docs-generator.js +410 -0
- package/esm/core/codegen/target-docs-generator.d.ts +20 -0
- package/esm/core/codegen/target-docs-generator.js +105 -0
- package/esm/core/database/index.d.ts +0 -12
- package/esm/core/database/index.js +1 -17
- package/esm/core/generate.d.ts +34 -2
- package/esm/core/generate.js +417 -12
- package/esm/core/index.d.ts +0 -2
- package/esm/core/index.js +0 -2
- package/esm/core/introspect/source/database.js +2 -2
- package/esm/core/introspect/source/pgpm-module.js +2 -2
- package/esm/core/output/index.d.ts +1 -1
- package/esm/core/output/index.js +1 -1
- package/esm/core/output/writer.d.ts +0 -10
- package/esm/core/output/writer.js +0 -30
- package/esm/generators/index.d.ts +0 -3
- package/esm/generators/index.js +0 -3
- package/esm/index.d.ts +4 -3
- package/esm/index.js +4 -2
- package/esm/types/config.d.ts +78 -0
- package/generators/index.d.ts +0 -3
- package/generators/index.js +0 -3
- package/index.d.ts +4 -3
- package/index.js +7 -2
- package/package.json +8 -7
- 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[];
|