@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.
- 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,11 @@
|
|
|
1
|
+
export interface GeneratedFile {
|
|
2
|
+
fileName: string;
|
|
3
|
+
content: string;
|
|
4
|
+
}
|
|
5
|
+
export interface MultiTargetExecutorInput {
|
|
6
|
+
name: string;
|
|
7
|
+
endpoint: string;
|
|
8
|
+
ormImportPath: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function generateExecutorFile(toolName: string): GeneratedFile;
|
|
11
|
+
export declare function generateMultiTargetExecutorFile(toolName: string, targets: MultiTargetExecutorInput[]): GeneratedFile;
|
|
@@ -0,0 +1,217 @@
|
|
|
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.generateExecutorFile = generateExecutorFile;
|
|
37
|
+
exports.generateMultiTargetExecutorFile = generateMultiTargetExecutorFile;
|
|
38
|
+
const t = __importStar(require("@babel/types"));
|
|
39
|
+
const babel_ast_1 = require("../babel-ast");
|
|
40
|
+
const utils_1 = require("../utils");
|
|
41
|
+
function createImportDeclaration(moduleSpecifier, namedImports, typeOnly = false) {
|
|
42
|
+
const specifiers = namedImports.map((name) => t.importSpecifier(t.identifier(name), t.identifier(name)));
|
|
43
|
+
const decl = t.importDeclaration(specifiers, t.stringLiteral(moduleSpecifier));
|
|
44
|
+
decl.importKind = typeOnly ? 'type' : 'value';
|
|
45
|
+
return decl;
|
|
46
|
+
}
|
|
47
|
+
function generateExecutorFile(toolName) {
|
|
48
|
+
const statements = [];
|
|
49
|
+
statements.push(createImportDeclaration('appstash', ['createConfigStore']));
|
|
50
|
+
statements.push(createImportDeclaration('../orm', ['createClient']));
|
|
51
|
+
statements.push(t.variableDeclaration('const', [
|
|
52
|
+
t.variableDeclarator(t.identifier('store'), t.callExpression(t.identifier('createConfigStore'), [
|
|
53
|
+
t.stringLiteral(toolName),
|
|
54
|
+
])),
|
|
55
|
+
]));
|
|
56
|
+
const getStoreExport = t.variableDeclaration('const', [
|
|
57
|
+
t.variableDeclarator(t.identifier('getStore'), t.arrowFunctionExpression([], t.identifier('store'))),
|
|
58
|
+
]);
|
|
59
|
+
statements.push(t.exportNamedDeclaration(getStoreExport));
|
|
60
|
+
const contextNameParam = t.identifier('contextName');
|
|
61
|
+
contextNameParam.optional = true;
|
|
62
|
+
contextNameParam.typeAnnotation = t.tsTypeAnnotation(t.tsStringKeyword());
|
|
63
|
+
const getClientBody = t.blockStatement([
|
|
64
|
+
t.variableDeclaration('let', [
|
|
65
|
+
t.variableDeclarator(t.identifier('ctx'), t.nullLiteral()),
|
|
66
|
+
]),
|
|
67
|
+
t.ifStatement(t.identifier('contextName'), t.blockStatement([
|
|
68
|
+
t.expressionStatement(t.assignmentExpression('=', t.identifier('ctx'), t.callExpression(t.memberExpression(t.identifier('store'), t.identifier('loadContext')), [t.identifier('contextName')]))),
|
|
69
|
+
t.ifStatement(t.unaryExpression('!', t.identifier('ctx')), t.blockStatement([
|
|
70
|
+
t.throwStatement(t.newExpression(t.identifier('Error'), [
|
|
71
|
+
t.templateLiteral([
|
|
72
|
+
t.templateElement({ raw: 'Context "', cooked: 'Context "' }),
|
|
73
|
+
t.templateElement({ raw: '" not found.', cooked: '" not found.' }, true),
|
|
74
|
+
], [t.identifier('contextName')]),
|
|
75
|
+
])),
|
|
76
|
+
])),
|
|
77
|
+
]), t.blockStatement([
|
|
78
|
+
t.expressionStatement(t.assignmentExpression('=', t.identifier('ctx'), t.callExpression(t.memberExpression(t.identifier('store'), t.identifier('getCurrentContext')), []))),
|
|
79
|
+
t.ifStatement(t.unaryExpression('!', t.identifier('ctx')), t.blockStatement([
|
|
80
|
+
t.throwStatement(t.newExpression(t.identifier('Error'), [
|
|
81
|
+
t.stringLiteral('No active context. Run "context create" or "context use" first.'),
|
|
82
|
+
])),
|
|
83
|
+
])),
|
|
84
|
+
])),
|
|
85
|
+
t.variableDeclaration('const', [
|
|
86
|
+
t.variableDeclarator(t.identifier('headers'), t.objectExpression([])),
|
|
87
|
+
]),
|
|
88
|
+
t.ifStatement(t.callExpression(t.memberExpression(t.identifier('store'), t.identifier('hasValidCredentials')), [t.memberExpression(t.identifier('ctx'), t.identifier('name'))]), t.blockStatement([
|
|
89
|
+
t.variableDeclaration('const', [
|
|
90
|
+
t.variableDeclarator(t.identifier('creds'), t.callExpression(t.memberExpression(t.identifier('store'), t.identifier('getCredentials')), [t.memberExpression(t.identifier('ctx'), t.identifier('name'))])),
|
|
91
|
+
]),
|
|
92
|
+
t.ifStatement(t.optionalMemberExpression(t.identifier('creds'), t.identifier('token'), false, true), t.blockStatement([
|
|
93
|
+
t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier('headers'), t.identifier('Authorization')), t.templateLiteral([
|
|
94
|
+
t.templateElement({ raw: 'Bearer ', cooked: 'Bearer ' }),
|
|
95
|
+
t.templateElement({ raw: '', cooked: '' }, true),
|
|
96
|
+
], [
|
|
97
|
+
t.memberExpression(t.identifier('creds'), t.identifier('token')),
|
|
98
|
+
]))),
|
|
99
|
+
])),
|
|
100
|
+
])),
|
|
101
|
+
t.returnStatement(t.callExpression(t.identifier('createClient'), [
|
|
102
|
+
t.objectExpression([
|
|
103
|
+
t.objectProperty(t.identifier('endpoint'), t.memberExpression(t.identifier('ctx'), t.identifier('endpoint'))),
|
|
104
|
+
t.objectProperty(t.identifier('headers'), t.identifier('headers')),
|
|
105
|
+
]),
|
|
106
|
+
])),
|
|
107
|
+
]);
|
|
108
|
+
const getClientFunc = t.functionDeclaration(t.identifier('getClient'), [contextNameParam], getClientBody);
|
|
109
|
+
statements.push(t.exportNamedDeclaration(getClientFunc));
|
|
110
|
+
const header = (0, utils_1.getGeneratedFileHeader)('Executor and config store for CLI');
|
|
111
|
+
const code = (0, babel_ast_1.generateCode)(statements);
|
|
112
|
+
return {
|
|
113
|
+
fileName: 'executor.ts',
|
|
114
|
+
content: header + '\n' + code,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function generateMultiTargetExecutorFile(toolName, targets) {
|
|
118
|
+
const statements = [];
|
|
119
|
+
statements.push(createImportDeclaration('appstash', ['createConfigStore']));
|
|
120
|
+
for (const target of targets) {
|
|
121
|
+
const aliasName = `create${target.name[0].toUpperCase()}${target.name.slice(1)}Client`;
|
|
122
|
+
const specifier = t.importSpecifier(t.identifier(aliasName), t.identifier('createClient'));
|
|
123
|
+
statements.push(t.importDeclaration([specifier], t.stringLiteral(target.ormImportPath)));
|
|
124
|
+
}
|
|
125
|
+
statements.push(t.variableDeclaration('const', [
|
|
126
|
+
t.variableDeclarator(t.identifier('store'), t.callExpression(t.identifier('createConfigStore'), [
|
|
127
|
+
t.stringLiteral(toolName),
|
|
128
|
+
])),
|
|
129
|
+
]));
|
|
130
|
+
const getStoreExport = t.variableDeclaration('const', [
|
|
131
|
+
t.variableDeclarator(t.identifier('getStore'), t.arrowFunctionExpression([], t.identifier('store'))),
|
|
132
|
+
]);
|
|
133
|
+
statements.push(t.exportNamedDeclaration(getStoreExport));
|
|
134
|
+
const targetClientsProps = targets.map((target) => {
|
|
135
|
+
const aliasName = `create${target.name[0].toUpperCase()}${target.name.slice(1)}Client`;
|
|
136
|
+
return t.objectProperty(t.stringLiteral(target.name), t.identifier(aliasName));
|
|
137
|
+
});
|
|
138
|
+
const targetClientsDecl = t.variableDeclaration('const', [
|
|
139
|
+
t.variableDeclarator(t.identifier('targetClients'), t.objectExpression(targetClientsProps)),
|
|
140
|
+
]);
|
|
141
|
+
statements.push(targetClientsDecl);
|
|
142
|
+
const defaultEndpointProps = targets.map((target) => t.objectProperty(t.stringLiteral(target.name), t.stringLiteral(target.endpoint)));
|
|
143
|
+
const defaultEndpointsDecl = t.variableDeclaration('const', [
|
|
144
|
+
t.variableDeclarator(t.identifier('defaultEndpoints'), t.objectExpression(defaultEndpointProps)),
|
|
145
|
+
]);
|
|
146
|
+
statements.push(defaultEndpointsDecl);
|
|
147
|
+
const getTargetNamesFunc = t.variableDeclaration('const', [
|
|
148
|
+
t.variableDeclarator(t.identifier('getTargetNames'), t.arrowFunctionExpression([], t.callExpression(t.memberExpression(t.identifier('Object'), t.identifier('keys')), [t.identifier('targetClients')]))),
|
|
149
|
+
]);
|
|
150
|
+
statements.push(t.exportNamedDeclaration(getTargetNamesFunc));
|
|
151
|
+
const getDefaultEndpointParam = t.identifier('targetName');
|
|
152
|
+
getDefaultEndpointParam.typeAnnotation = t.tsTypeAnnotation(t.tsStringKeyword());
|
|
153
|
+
const getDefaultEndpointFunc = t.variableDeclaration('const', [
|
|
154
|
+
t.variableDeclarator(t.identifier('getDefaultEndpoint'), t.arrowFunctionExpression([getDefaultEndpointParam], t.logicalExpression('||', t.memberExpression(t.identifier('defaultEndpoints'), t.identifier('targetName'), true), t.stringLiteral('')))),
|
|
155
|
+
]);
|
|
156
|
+
statements.push(t.exportNamedDeclaration(getDefaultEndpointFunc));
|
|
157
|
+
const targetNameParam = t.identifier('targetName');
|
|
158
|
+
targetNameParam.typeAnnotation = t.tsTypeAnnotation(t.tsStringKeyword());
|
|
159
|
+
const contextNameParam = t.identifier('contextName');
|
|
160
|
+
contextNameParam.optional = true;
|
|
161
|
+
contextNameParam.typeAnnotation = t.tsTypeAnnotation(t.tsStringKeyword());
|
|
162
|
+
const getClientBody = t.blockStatement([
|
|
163
|
+
t.variableDeclaration('const', [
|
|
164
|
+
t.variableDeclarator(t.identifier('createFn'), t.memberExpression(t.identifier('targetClients'), t.identifier('targetName'), true)),
|
|
165
|
+
]),
|
|
166
|
+
t.ifStatement(t.unaryExpression('!', t.identifier('createFn')), t.blockStatement([
|
|
167
|
+
t.throwStatement(t.newExpression(t.identifier('Error'), [
|
|
168
|
+
t.templateLiteral([
|
|
169
|
+
t.templateElement({ raw: 'Unknown target: ', cooked: 'Unknown target: ' }),
|
|
170
|
+
t.templateElement({ raw: '', cooked: '' }, true),
|
|
171
|
+
], [t.identifier('targetName')]),
|
|
172
|
+
])),
|
|
173
|
+
])),
|
|
174
|
+
t.variableDeclaration('const', [
|
|
175
|
+
t.variableDeclarator(t.identifier('headers'), t.objectExpression([])),
|
|
176
|
+
]),
|
|
177
|
+
t.variableDeclaration('let', [
|
|
178
|
+
t.variableDeclarator(t.identifier('endpoint'), t.stringLiteral('')),
|
|
179
|
+
]),
|
|
180
|
+
t.variableDeclaration('const', [
|
|
181
|
+
t.variableDeclarator(t.identifier('ctx'), t.conditionalExpression(t.identifier('contextName'), t.callExpression(t.memberExpression(t.identifier('store'), t.identifier('loadContext')), [t.identifier('contextName')]), t.callExpression(t.memberExpression(t.identifier('store'), t.identifier('getCurrentContext')), []))),
|
|
182
|
+
]),
|
|
183
|
+
t.ifStatement(t.identifier('ctx'), t.blockStatement([
|
|
184
|
+
t.variableDeclaration('const', [
|
|
185
|
+
t.variableDeclarator(t.identifier('resolved'), t.callExpression(t.memberExpression(t.identifier('store'), t.identifier('getTargetEndpoint')), [t.identifier('targetName'), t.memberExpression(t.identifier('ctx'), t.identifier('name'))])),
|
|
186
|
+
]),
|
|
187
|
+
t.expressionStatement(t.assignmentExpression('=', t.identifier('endpoint'), t.logicalExpression('||', t.identifier('resolved'), t.logicalExpression('||', t.memberExpression(t.identifier('defaultEndpoints'), t.identifier('targetName'), true), t.stringLiteral(''))))),
|
|
188
|
+
t.ifStatement(t.callExpression(t.memberExpression(t.identifier('store'), t.identifier('hasValidCredentials')), [t.memberExpression(t.identifier('ctx'), t.identifier('name'))]), t.blockStatement([
|
|
189
|
+
t.variableDeclaration('const', [
|
|
190
|
+
t.variableDeclarator(t.identifier('creds'), t.callExpression(t.memberExpression(t.identifier('store'), t.identifier('getCredentials')), [t.memberExpression(t.identifier('ctx'), t.identifier('name'))])),
|
|
191
|
+
]),
|
|
192
|
+
t.ifStatement(t.optionalMemberExpression(t.identifier('creds'), t.identifier('token'), false, true), t.blockStatement([
|
|
193
|
+
t.expressionStatement(t.assignmentExpression('=', t.memberExpression(t.identifier('headers'), t.identifier('Authorization')), t.templateLiteral([
|
|
194
|
+
t.templateElement({ raw: 'Bearer ', cooked: 'Bearer ' }),
|
|
195
|
+
t.templateElement({ raw: '', cooked: '' }, true),
|
|
196
|
+
], [t.memberExpression(t.identifier('creds'), t.identifier('token'))]))),
|
|
197
|
+
])),
|
|
198
|
+
])),
|
|
199
|
+
]), t.blockStatement([
|
|
200
|
+
t.expressionStatement(t.assignmentExpression('=', t.identifier('endpoint'), t.logicalExpression('||', t.memberExpression(t.identifier('defaultEndpoints'), t.identifier('targetName'), true), t.stringLiteral('')))),
|
|
201
|
+
])),
|
|
202
|
+
t.returnStatement(t.callExpression(t.identifier('createFn'), [
|
|
203
|
+
t.objectExpression([
|
|
204
|
+
t.objectProperty(t.identifier('endpoint'), t.identifier('endpoint')),
|
|
205
|
+
t.objectProperty(t.identifier('headers'), t.identifier('headers')),
|
|
206
|
+
]),
|
|
207
|
+
])),
|
|
208
|
+
]);
|
|
209
|
+
const getClientFunc = t.functionDeclaration(t.identifier('getClient'), [targetNameParam, contextNameParam], getClientBody);
|
|
210
|
+
statements.push(t.exportNamedDeclaration(getClientFunc));
|
|
211
|
+
const header = (0, utils_1.getGeneratedFileHeader)('Multi-target executor and config store for CLI');
|
|
212
|
+
const code = (0, babel_ast_1.generateCode)(statements);
|
|
213
|
+
return {
|
|
214
|
+
fileName: 'executor.ts',
|
|
215
|
+
content: header + '\n' + code,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { BuiltinNames, GraphQLSDKConfigTarget } from '../../../types/config';
|
|
2
|
+
import type { CleanOperation, CleanTable } from '../../../types/schema';
|
|
3
|
+
import type { GeneratedFile } from './executor-generator';
|
|
4
|
+
export interface GenerateCliOptions {
|
|
5
|
+
tables: CleanTable[];
|
|
6
|
+
customOperations?: {
|
|
7
|
+
queries: CleanOperation[];
|
|
8
|
+
mutations: CleanOperation[];
|
|
9
|
+
};
|
|
10
|
+
config: GraphQLSDKConfigTarget;
|
|
11
|
+
}
|
|
12
|
+
export interface GenerateCliResult {
|
|
13
|
+
files: GeneratedFile[];
|
|
14
|
+
stats: {
|
|
15
|
+
tables: number;
|
|
16
|
+
customQueries: number;
|
|
17
|
+
customMutations: number;
|
|
18
|
+
infraFiles: number;
|
|
19
|
+
totalFiles: number;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export declare function generateCli(options: GenerateCliOptions): GenerateCliResult;
|
|
23
|
+
export interface MultiTargetCliTarget {
|
|
24
|
+
name: string;
|
|
25
|
+
endpoint: string;
|
|
26
|
+
ormImportPath: string;
|
|
27
|
+
tables: CleanTable[];
|
|
28
|
+
customOperations: {
|
|
29
|
+
queries: CleanOperation[];
|
|
30
|
+
mutations: CleanOperation[];
|
|
31
|
+
};
|
|
32
|
+
isAuthTarget?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface GenerateMultiTargetCliOptions {
|
|
35
|
+
toolName: string;
|
|
36
|
+
builtinNames?: BuiltinNames;
|
|
37
|
+
targets: MultiTargetCliTarget[];
|
|
38
|
+
}
|
|
39
|
+
export declare function resolveBuiltinNames(targetNames: string[], userOverrides?: BuiltinNames): {
|
|
40
|
+
auth: string;
|
|
41
|
+
context: string;
|
|
42
|
+
};
|
|
43
|
+
export declare function generateMultiTargetCli(options: GenerateMultiTargetCliOptions): GenerateCliResult;
|
|
44
|
+
export { generateExecutorFile, generateMultiTargetExecutorFile } from './executor-generator';
|
|
45
|
+
export { generateTableCommand } from './table-command-generator';
|
|
46
|
+
export { generateCustomCommand } from './custom-command-generator';
|
|
47
|
+
export { generateCommandMap, generateMultiTargetCommandMap } from './command-map-generator';
|
|
48
|
+
export { generateContextCommand, generateAuthCommand, generateMultiTargetContextCommand, generateAuthCommandWithName, } from './infra-generator';
|
|
49
|
+
export { generateReadme, generateAgentsDocs, getCliMcpTools, generateSkills, generateMultiTargetReadme, generateMultiTargetAgentsDocs, getMultiTargetCliMcpTools, generateMultiTargetSkills, } from './docs-generator';
|
|
50
|
+
export type { MultiTargetDocsInput } from './docs-generator';
|
|
51
|
+
export { resolveDocsConfig } from '../docs-utils';
|
|
52
|
+
export type { GeneratedDocFile, McpTool } from '../docs-utils';
|
|
53
|
+
export type { GeneratedFile, MultiTargetExecutorInput } from './executor-generator';
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveDocsConfig = exports.generateMultiTargetSkills = exports.getMultiTargetCliMcpTools = exports.generateMultiTargetAgentsDocs = exports.generateMultiTargetReadme = exports.generateSkills = exports.getCliMcpTools = exports.generateAgentsDocs = exports.generateReadme = exports.generateAuthCommandWithName = exports.generateMultiTargetContextCommand = exports.generateAuthCommand = exports.generateContextCommand = exports.generateMultiTargetCommandMap = exports.generateCommandMap = exports.generateCustomCommand = exports.generateTableCommand = exports.generateMultiTargetExecutorFile = exports.generateExecutorFile = void 0;
|
|
4
|
+
exports.generateCli = generateCli;
|
|
5
|
+
exports.resolveBuiltinNames = resolveBuiltinNames;
|
|
6
|
+
exports.generateMultiTargetCli = generateMultiTargetCli;
|
|
7
|
+
const command_map_generator_1 = require("./command-map-generator");
|
|
8
|
+
const custom_command_generator_1 = require("./custom-command-generator");
|
|
9
|
+
const executor_generator_1 = require("./executor-generator");
|
|
10
|
+
const infra_generator_1 = require("./infra-generator");
|
|
11
|
+
const table_command_generator_1 = require("./table-command-generator");
|
|
12
|
+
function generateCli(options) {
|
|
13
|
+
const { tables, customOperations, config } = options;
|
|
14
|
+
const files = [];
|
|
15
|
+
const cliConfig = config.cli;
|
|
16
|
+
const toolName = typeof cliConfig === 'object' && cliConfig.toolName
|
|
17
|
+
? cliConfig.toolName
|
|
18
|
+
: 'app';
|
|
19
|
+
const executorFile = (0, executor_generator_1.generateExecutorFile)(toolName);
|
|
20
|
+
files.push(executorFile);
|
|
21
|
+
const contextFile = (0, infra_generator_1.generateContextCommand)(toolName);
|
|
22
|
+
files.push(contextFile);
|
|
23
|
+
const authFile = (0, infra_generator_1.generateAuthCommand)(toolName);
|
|
24
|
+
files.push(authFile);
|
|
25
|
+
for (const table of tables) {
|
|
26
|
+
const tableFile = (0, table_command_generator_1.generateTableCommand)(table);
|
|
27
|
+
files.push(tableFile);
|
|
28
|
+
}
|
|
29
|
+
const allCustomOps = [
|
|
30
|
+
...(customOperations?.queries ?? []),
|
|
31
|
+
...(customOperations?.mutations ?? []),
|
|
32
|
+
];
|
|
33
|
+
for (const op of allCustomOps) {
|
|
34
|
+
const customFile = (0, custom_command_generator_1.generateCustomCommand)(op);
|
|
35
|
+
files.push(customFile);
|
|
36
|
+
}
|
|
37
|
+
const commandMapFile = (0, command_map_generator_1.generateCommandMap)(tables, allCustomOps, toolName);
|
|
38
|
+
files.push(commandMapFile);
|
|
39
|
+
return {
|
|
40
|
+
files,
|
|
41
|
+
stats: {
|
|
42
|
+
tables: tables.length,
|
|
43
|
+
customQueries: customOperations?.queries.length ?? 0,
|
|
44
|
+
customMutations: customOperations?.mutations.length ?? 0,
|
|
45
|
+
infraFiles: 3,
|
|
46
|
+
totalFiles: files.length,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function resolveBuiltinNames(targetNames, userOverrides) {
|
|
51
|
+
let authName = userOverrides?.auth ?? 'auth';
|
|
52
|
+
let contextName = userOverrides?.context ?? 'context';
|
|
53
|
+
if (targetNames.includes(authName) && !userOverrides?.auth) {
|
|
54
|
+
authName = 'credentials';
|
|
55
|
+
}
|
|
56
|
+
if (targetNames.includes(contextName) && !userOverrides?.context) {
|
|
57
|
+
contextName = 'env';
|
|
58
|
+
}
|
|
59
|
+
return { auth: authName, context: contextName };
|
|
60
|
+
}
|
|
61
|
+
function generateMultiTargetCli(options) {
|
|
62
|
+
const { toolName, targets } = options;
|
|
63
|
+
const files = [];
|
|
64
|
+
const targetNames = targets.map((t) => t.name);
|
|
65
|
+
const builtinNames = resolveBuiltinNames(targetNames, options.builtinNames);
|
|
66
|
+
const executorInputs = targets.map((t) => ({
|
|
67
|
+
name: t.name,
|
|
68
|
+
endpoint: t.endpoint,
|
|
69
|
+
ormImportPath: t.ormImportPath,
|
|
70
|
+
}));
|
|
71
|
+
const executorFile = (0, executor_generator_1.generateMultiTargetExecutorFile)(toolName, executorInputs);
|
|
72
|
+
files.push(executorFile);
|
|
73
|
+
const contextFile = (0, infra_generator_1.generateMultiTargetContextCommand)(toolName, builtinNames.context, targets.map((t) => ({ name: t.name, endpoint: t.endpoint })));
|
|
74
|
+
files.push(contextFile);
|
|
75
|
+
const authFile = (0, infra_generator_1.generateAuthCommandWithName)(toolName, builtinNames.auth);
|
|
76
|
+
files.push(authFile);
|
|
77
|
+
let totalTables = 0;
|
|
78
|
+
let totalQueries = 0;
|
|
79
|
+
let totalMutations = 0;
|
|
80
|
+
const commandMapTargets = [];
|
|
81
|
+
for (const target of targets) {
|
|
82
|
+
const allOps = [
|
|
83
|
+
...(target.customOperations?.queries ?? []),
|
|
84
|
+
...(target.customOperations?.mutations ?? []),
|
|
85
|
+
];
|
|
86
|
+
for (const table of target.tables) {
|
|
87
|
+
const tableFile = (0, table_command_generator_1.generateTableCommand)(table, {
|
|
88
|
+
targetName: target.name,
|
|
89
|
+
executorImportPath: '../../executor',
|
|
90
|
+
});
|
|
91
|
+
files.push(tableFile);
|
|
92
|
+
}
|
|
93
|
+
for (const op of allOps) {
|
|
94
|
+
const isSaveToken = !!target.isAuthTarget && op.kind === 'mutation';
|
|
95
|
+
const customFile = (0, custom_command_generator_1.generateCustomCommand)(op, {
|
|
96
|
+
targetName: target.name,
|
|
97
|
+
executorImportPath: '../../executor',
|
|
98
|
+
saveToken: isSaveToken,
|
|
99
|
+
});
|
|
100
|
+
files.push(customFile);
|
|
101
|
+
}
|
|
102
|
+
totalTables += target.tables.length;
|
|
103
|
+
totalQueries += target.customOperations?.queries?.length ?? 0;
|
|
104
|
+
totalMutations += target.customOperations?.mutations?.length ?? 0;
|
|
105
|
+
commandMapTargets.push({
|
|
106
|
+
name: target.name,
|
|
107
|
+
tables: target.tables,
|
|
108
|
+
customOperations: allOps,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const commandMapFile = (0, command_map_generator_1.generateMultiTargetCommandMap)({
|
|
112
|
+
toolName,
|
|
113
|
+
builtinNames,
|
|
114
|
+
targets: commandMapTargets,
|
|
115
|
+
});
|
|
116
|
+
files.push(commandMapFile);
|
|
117
|
+
return {
|
|
118
|
+
files,
|
|
119
|
+
stats: {
|
|
120
|
+
tables: totalTables,
|
|
121
|
+
customQueries: totalQueries,
|
|
122
|
+
customMutations: totalMutations,
|
|
123
|
+
infraFiles: 3,
|
|
124
|
+
totalFiles: files.length,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
var executor_generator_2 = require("./executor-generator");
|
|
129
|
+
Object.defineProperty(exports, "generateExecutorFile", { enumerable: true, get: function () { return executor_generator_2.generateExecutorFile; } });
|
|
130
|
+
Object.defineProperty(exports, "generateMultiTargetExecutorFile", { enumerable: true, get: function () { return executor_generator_2.generateMultiTargetExecutorFile; } });
|
|
131
|
+
var table_command_generator_2 = require("./table-command-generator");
|
|
132
|
+
Object.defineProperty(exports, "generateTableCommand", { enumerable: true, get: function () { return table_command_generator_2.generateTableCommand; } });
|
|
133
|
+
var custom_command_generator_2 = require("./custom-command-generator");
|
|
134
|
+
Object.defineProperty(exports, "generateCustomCommand", { enumerable: true, get: function () { return custom_command_generator_2.generateCustomCommand; } });
|
|
135
|
+
var command_map_generator_2 = require("./command-map-generator");
|
|
136
|
+
Object.defineProperty(exports, "generateCommandMap", { enumerable: true, get: function () { return command_map_generator_2.generateCommandMap; } });
|
|
137
|
+
Object.defineProperty(exports, "generateMultiTargetCommandMap", { enumerable: true, get: function () { return command_map_generator_2.generateMultiTargetCommandMap; } });
|
|
138
|
+
var infra_generator_2 = require("./infra-generator");
|
|
139
|
+
Object.defineProperty(exports, "generateContextCommand", { enumerable: true, get: function () { return infra_generator_2.generateContextCommand; } });
|
|
140
|
+
Object.defineProperty(exports, "generateAuthCommand", { enumerable: true, get: function () { return infra_generator_2.generateAuthCommand; } });
|
|
141
|
+
Object.defineProperty(exports, "generateMultiTargetContextCommand", { enumerable: true, get: function () { return infra_generator_2.generateMultiTargetContextCommand; } });
|
|
142
|
+
Object.defineProperty(exports, "generateAuthCommandWithName", { enumerable: true, get: function () { return infra_generator_2.generateAuthCommandWithName; } });
|
|
143
|
+
var docs_generator_1 = require("./docs-generator");
|
|
144
|
+
Object.defineProperty(exports, "generateReadme", { enumerable: true, get: function () { return docs_generator_1.generateReadme; } });
|
|
145
|
+
Object.defineProperty(exports, "generateAgentsDocs", { enumerable: true, get: function () { return docs_generator_1.generateAgentsDocs; } });
|
|
146
|
+
Object.defineProperty(exports, "getCliMcpTools", { enumerable: true, get: function () { return docs_generator_1.getCliMcpTools; } });
|
|
147
|
+
Object.defineProperty(exports, "generateSkills", { enumerable: true, get: function () { return docs_generator_1.generateSkills; } });
|
|
148
|
+
Object.defineProperty(exports, "generateMultiTargetReadme", { enumerable: true, get: function () { return docs_generator_1.generateMultiTargetReadme; } });
|
|
149
|
+
Object.defineProperty(exports, "generateMultiTargetAgentsDocs", { enumerable: true, get: function () { return docs_generator_1.generateMultiTargetAgentsDocs; } });
|
|
150
|
+
Object.defineProperty(exports, "getMultiTargetCliMcpTools", { enumerable: true, get: function () { return docs_generator_1.getMultiTargetCliMcpTools; } });
|
|
151
|
+
Object.defineProperty(exports, "generateMultiTargetSkills", { enumerable: true, get: function () { return docs_generator_1.generateMultiTargetSkills; } });
|
|
152
|
+
var docs_utils_1 = require("../docs-utils");
|
|
153
|
+
Object.defineProperty(exports, "resolveDocsConfig", { enumerable: true, get: function () { return docs_utils_1.resolveDocsConfig; } });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { GeneratedFile } from './executor-generator';
|
|
2
|
+
export declare function generateContextCommand(toolName: string): GeneratedFile;
|
|
3
|
+
export declare function generateAuthCommand(toolName: string): GeneratedFile;
|
|
4
|
+
export interface MultiTargetContextInput {
|
|
5
|
+
name: string;
|
|
6
|
+
endpoint: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function generateMultiTargetContextCommand(toolName: string, commandName: string, targets: MultiTargetContextInput[]): GeneratedFile;
|
|
9
|
+
export declare function generateAuthCommandWithName(toolName: string, commandName: string): GeneratedFile;
|