@constructive-io/graphql-codegen 4.8.0 → 4.9.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/core/codegen/cli/command-map-generator.js +36 -11
- package/core/codegen/cli/custom-command-generator.js +59 -13
- package/core/codegen/cli/executor-generator.js +20 -6
- package/core/codegen/cli/infra-generator.js +17 -14
- package/core/codegen/cli/table-command-generator.js +218 -55
- package/esm/core/codegen/cli/command-map-generator.js +36 -11
- package/esm/core/codegen/cli/custom-command-generator.js +60 -14
- package/esm/core/codegen/cli/executor-generator.js +20 -6
- package/esm/core/codegen/cli/infra-generator.js +17 -14
- package/esm/core/codegen/cli/table-command-generator.js +219 -56
- package/package.json +2 -2
|
@@ -48,6 +48,25 @@ function createNamedImportDeclaration(moduleSpecifier, namedImports, typeOnly =
|
|
|
48
48
|
decl.importKind = typeOnly ? 'type' : 'value';
|
|
49
49
|
return decl;
|
|
50
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Build the command handler function type:
|
|
53
|
+
* (argv: Partial<Record<string, unknown>>, prompter: Inquirerer, options: CLIOptions) => Promise<void>
|
|
54
|
+
* This matches the actual exported handler signatures from table/custom command files.
|
|
55
|
+
*/
|
|
56
|
+
function buildCommandHandlerType() {
|
|
57
|
+
const argvParam = t.identifier('argv');
|
|
58
|
+
argvParam.typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Partial'), t.tsTypeParameterInstantiation([
|
|
59
|
+
t.tsTypeReference(t.identifier('Record'), t.tsTypeParameterInstantiation([
|
|
60
|
+
t.tsStringKeyword(),
|
|
61
|
+
t.tsUnknownKeyword(),
|
|
62
|
+
])),
|
|
63
|
+
])));
|
|
64
|
+
const prompterParam = t.identifier('prompter');
|
|
65
|
+
prompterParam.typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Inquirerer')));
|
|
66
|
+
const optionsParam = t.identifier('options');
|
|
67
|
+
optionsParam.typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier('CLIOptions')));
|
|
68
|
+
return t.tsFunctionType(null, [argvParam, prompterParam, optionsParam], t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Promise'), t.tsTypeParameterInstantiation([t.tsVoidKeyword()]))));
|
|
69
|
+
}
|
|
51
70
|
function generateCommandMap(tables, customOperations, toolName) {
|
|
52
71
|
const statements = [];
|
|
53
72
|
statements.push(createNamedImportDeclaration('inquirerer', [
|
|
@@ -74,18 +93,17 @@ function generateCommandMap(tables, customOperations, toolName) {
|
|
|
74
93
|
statements.push(createImportDeclaration(`./commands/${kebab}`, importName));
|
|
75
94
|
}
|
|
76
95
|
const mapProperties = commandEntries.map((entry) => t.objectProperty(t.stringLiteral(entry.kebab), t.identifier(entry.importName)));
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
])));
|
|
96
|
+
// Build command handler type matching actual handler signature:
|
|
97
|
+
// (argv: Partial<Record<string, unknown>>, prompter: Inquirerer, options: CLIOptions) => Promise<void>
|
|
98
|
+
const commandHandlerType = buildCommandHandlerType();
|
|
84
99
|
const createCommandMapId = t.identifier('createCommandMap');
|
|
85
100
|
createCommandMapId.typeAnnotation = t.tsTypeAnnotation(t.tsParenthesizedType(t.tsFunctionType(null, [], t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Record'), t.tsTypeParameterInstantiation([
|
|
86
101
|
t.tsStringKeyword(),
|
|
87
|
-
|
|
102
|
+
commandHandlerType,
|
|
88
103
|
]))))));
|
|
104
|
+
const createCommandMapFunc = t.variableDeclaration('const', [
|
|
105
|
+
t.variableDeclarator(createCommandMapId, t.arrowFunctionExpression([], t.objectExpression(mapProperties))),
|
|
106
|
+
]);
|
|
89
107
|
statements.push(createCommandMapFunc);
|
|
90
108
|
const usageLines = [
|
|
91
109
|
'',
|
|
@@ -152,7 +170,7 @@ function generateCommandMap(tables, customOperations, toolName) {
|
|
|
152
170
|
]),
|
|
153
171
|
]))),
|
|
154
172
|
]),
|
|
155
|
-
t.expressionStatement(t.assignmentExpression('=', t.identifier('command'), t.memberExpression(t.identifier('answer'), t.identifier('command')))),
|
|
173
|
+
t.expressionStatement(t.assignmentExpression('=', t.identifier('command'), t.tsAsExpression(t.memberExpression(t.identifier('answer'), t.identifier('command')), t.tsStringKeyword()))),
|
|
156
174
|
])),
|
|
157
175
|
t.variableDeclaration('const', [
|
|
158
176
|
t.variableDeclarator(t.identifier('commandFn'), t.memberExpression(t.identifier('commandMap'), t.identifier('command'), true)),
|
|
@@ -223,8 +241,15 @@ function generateMultiTargetCommandMap(input) {
|
|
|
223
241
|
}
|
|
224
242
|
}
|
|
225
243
|
const mapProperties = commandEntries.map((entry) => t.objectProperty(t.stringLiteral(entry.kebab), t.identifier(entry.importName)));
|
|
244
|
+
// Build command handler type matching actual handler signature
|
|
245
|
+
const multiTargetCommandHandlerType = buildCommandHandlerType();
|
|
246
|
+
const multiTargetCreateCommandMapId = t.identifier('createCommandMap');
|
|
247
|
+
multiTargetCreateCommandMapId.typeAnnotation = t.tsTypeAnnotation(t.tsParenthesizedType(t.tsFunctionType(null, [], t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Record'), t.tsTypeParameterInstantiation([
|
|
248
|
+
t.tsStringKeyword(),
|
|
249
|
+
multiTargetCommandHandlerType,
|
|
250
|
+
]))))));
|
|
226
251
|
const createCommandMapFunc = t.variableDeclaration('const', [
|
|
227
|
-
t.variableDeclarator(
|
|
252
|
+
t.variableDeclarator(multiTargetCreateCommandMapId, t.arrowFunctionExpression([], t.objectExpression(mapProperties))),
|
|
228
253
|
]);
|
|
229
254
|
statements.push(createCommandMapFunc);
|
|
230
255
|
const usageLines = [
|
|
@@ -298,7 +323,7 @@ function generateMultiTargetCommandMap(input) {
|
|
|
298
323
|
]),
|
|
299
324
|
]))),
|
|
300
325
|
]),
|
|
301
|
-
t.expressionStatement(t.assignmentExpression('=', t.identifier('command'), t.memberExpression(t.identifier('answer'), t.identifier('command')))),
|
|
326
|
+
t.expressionStatement(t.assignmentExpression('=', t.identifier('command'), t.tsAsExpression(t.memberExpression(t.identifier('answer'), t.identifier('command')), t.tsStringKeyword()))),
|
|
302
327
|
])),
|
|
303
328
|
t.variableDeclaration('const', [
|
|
304
329
|
t.variableDeclarator(t.identifier('commandFn'), t.memberExpression(t.identifier('commandMap'), t.identifier('command'), true)),
|
|
@@ -101,22 +101,33 @@ function buildDefaultSelectString(returnType, isMutation) {
|
|
|
101
101
|
}
|
|
102
102
|
return '';
|
|
103
103
|
}
|
|
104
|
-
function buildOrmCustomCall(opKind, opName, argsExpr, selectExpr, hasArgs = true) {
|
|
104
|
+
function buildOrmCustomCall(opKind, opName, argsExpr, selectExpr, hasArgs = true, selectTypeName) {
|
|
105
105
|
const callArgs = [];
|
|
106
|
+
// Helper: wrap { select } and cast to `{ select: XxxSelect }` via `unknown`.
|
|
107
|
+
// The ORM method's second parameter is `{ select: S } & StrictSelect<S, XxxSelect>`.
|
|
108
|
+
// We import the concrete Select type (e.g. CheckPasswordPayloadSelect) and cast
|
|
109
|
+
// `{ select: selectFields } as unknown as { select: XxxSelect }` so TS infers
|
|
110
|
+
// `S = XxxSelect` and StrictSelect is satisfied.
|
|
111
|
+
const castSelectWrapper = (sel) => {
|
|
112
|
+
const selectObj = t.objectExpression([
|
|
113
|
+
t.objectProperty(t.identifier('select'), sel),
|
|
114
|
+
]);
|
|
115
|
+
if (!selectTypeName)
|
|
116
|
+
return selectObj;
|
|
117
|
+
return t.tsAsExpression(t.tsAsExpression(selectObj, t.tsUnknownKeyword()), t.tsTypeLiteral([
|
|
118
|
+
t.tsPropertySignature(t.identifier('select'), t.tsTypeAnnotation(t.tsTypeReference(t.identifier(selectTypeName)))),
|
|
119
|
+
]));
|
|
120
|
+
};
|
|
106
121
|
if (hasArgs) {
|
|
107
|
-
// Operation has arguments: pass args as first param, select as second
|
|
122
|
+
// Operation has arguments: pass args as first param, select as second.
|
|
108
123
|
callArgs.push(argsExpr);
|
|
109
124
|
if (selectExpr) {
|
|
110
|
-
callArgs.push(
|
|
111
|
-
t.objectProperty(t.identifier('select'), selectExpr),
|
|
112
|
-
]));
|
|
125
|
+
callArgs.push(castSelectWrapper(selectExpr));
|
|
113
126
|
}
|
|
114
127
|
}
|
|
115
128
|
else if (selectExpr) {
|
|
116
|
-
// No arguments: pass { select } as the only param (ORM signature)
|
|
117
|
-
callArgs.push(
|
|
118
|
-
t.objectProperty(t.identifier('select'), selectExpr),
|
|
119
|
-
]));
|
|
129
|
+
// No arguments: pass { select } as the only param (ORM signature).
|
|
130
|
+
callArgs.push(castSelectWrapper(selectExpr));
|
|
120
131
|
}
|
|
121
132
|
return t.callExpression(t.memberExpression(t.callExpression(t.memberExpression(t.memberExpression(t.identifier('client'), t.identifier(opKind)), t.identifier(opName)), callArgs), t.identifier('execute')), []);
|
|
122
133
|
}
|
|
@@ -152,6 +163,18 @@ function generateCustomCommand(op, options) {
|
|
|
152
163
|
if (utilsImports.length > 0) {
|
|
153
164
|
statements.push(createImportDeclaration(utilsPath, utilsImports));
|
|
154
165
|
}
|
|
166
|
+
// Import the Variables type for this operation from the ORM query/mutation module.
|
|
167
|
+
// Custom operations define their own Variables types (e.g. CheckPasswordVariables)
|
|
168
|
+
// in the ORM layer. We import and cast CLI answers to this type for proper typing.
|
|
169
|
+
if (op.args.length > 0) {
|
|
170
|
+
const variablesTypeName = `${(0, utils_1.ucFirst)(op.name)}Variables`;
|
|
171
|
+
// Commands are at cli/commands/xxx.ts (no target) or cli/commands/{target}/xxx.ts (with target).
|
|
172
|
+
// ORM query/mutation is at orm/{opKind}/ — two or three levels up from commands.
|
|
173
|
+
const ormOpPath = options?.targetName
|
|
174
|
+
? `../../../orm/${opKind}`
|
|
175
|
+
: `../../orm/${opKind}`;
|
|
176
|
+
statements.push(createImportDeclaration(ormOpPath, [variablesTypeName], true));
|
|
177
|
+
}
|
|
155
178
|
const questionsArray = op.args.length > 0
|
|
156
179
|
? (0, arg_mapper_1.buildQuestionsArray)(op.args)
|
|
157
180
|
: t.arrayExpression([]);
|
|
@@ -189,10 +212,16 @@ function generateCustomCommand(op, options) {
|
|
|
189
212
|
])),
|
|
190
213
|
]));
|
|
191
214
|
}
|
|
215
|
+
// Cast args to the specific Variables type for this operation.
|
|
216
|
+
// The ORM expects typed variables (e.g. CheckPasswordVariables), and CLI
|
|
217
|
+
// prompt answers are Record<string, unknown>. We cast through `unknown`
|
|
218
|
+
// first because Record<string, unknown> doesn't directly overlap with
|
|
219
|
+
// Variables types that have specific property types (like `input: SomeInput`).
|
|
220
|
+
const variablesTypeName = `${(0, utils_1.ucFirst)(op.name)}Variables`;
|
|
192
221
|
const argsExpr = op.args.length > 0
|
|
193
|
-
? (hasInputObjectArg
|
|
222
|
+
? t.tsAsExpression(t.tsAsExpression(hasInputObjectArg
|
|
194
223
|
? t.identifier('parsedAnswers')
|
|
195
|
-
: t.identifier('answers'))
|
|
224
|
+
: t.identifier('answers'), t.tsUnknownKeyword()), t.tsTypeReference(t.identifier(variablesTypeName)))
|
|
196
225
|
: t.objectExpression([]);
|
|
197
226
|
// For OBJECT return types, generate runtime select from --select flag
|
|
198
227
|
// For scalar return types, no select is needed
|
|
@@ -202,14 +231,31 @@ function generateCustomCommand(op, options) {
|
|
|
202
231
|
// Generate: const selectFields = buildSelectFromPaths(argv.select ?? 'defaultFields')
|
|
203
232
|
bodyStatements.push(t.variableDeclaration('const', [
|
|
204
233
|
t.variableDeclarator(t.identifier('selectFields'), t.callExpression(t.identifier('buildSelectFromPaths'), [
|
|
205
|
-
t.logicalExpression('??', t.memberExpression(t.identifier('argv'), t.identifier('select')), t.stringLiteral(defaultSelect)),
|
|
234
|
+
t.logicalExpression('??', t.tsAsExpression(t.memberExpression(t.identifier('argv'), t.identifier('select')), t.tsStringKeyword()), t.stringLiteral(defaultSelect)),
|
|
206
235
|
])),
|
|
207
236
|
]));
|
|
208
237
|
selectExpr = t.identifier('selectFields');
|
|
209
238
|
}
|
|
239
|
+
// Derive the Select type name from the operation's return type.
|
|
240
|
+
// e.g. CheckPasswordPayload → CheckPasswordPayloadSelect
|
|
241
|
+
// This is used to cast { select } to the proper type for StrictSelect.
|
|
242
|
+
let selectTypeName;
|
|
243
|
+
if (isObjectReturn) {
|
|
244
|
+
const baseReturnType = unwrapType(op.returnType);
|
|
245
|
+
if (baseReturnType.name) {
|
|
246
|
+
selectTypeName = `${baseReturnType.name}Select`;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
// Import the Select type from orm/input-types if we have one
|
|
250
|
+
if (selectTypeName) {
|
|
251
|
+
const inputTypesPath = options?.targetName
|
|
252
|
+
? `../../../orm/input-types`
|
|
253
|
+
: `../../orm/input-types`;
|
|
254
|
+
statements.push(createImportDeclaration(inputTypesPath, [selectTypeName], true));
|
|
255
|
+
}
|
|
210
256
|
const hasArgs = op.args.length > 0;
|
|
211
257
|
bodyStatements.push(t.variableDeclaration('const', [
|
|
212
|
-
t.variableDeclarator(t.identifier('result'), t.awaitExpression(buildOrmCustomCall(opKind, op.name, argsExpr, selectExpr, hasArgs))),
|
|
258
|
+
t.variableDeclarator(t.identifier('result'), t.awaitExpression(buildOrmCustomCall(opKind, op.name, argsExpr, selectExpr, hasArgs, selectTypeName))),
|
|
213
259
|
]));
|
|
214
260
|
if (options?.saveToken) {
|
|
215
261
|
bodyStatements.push(t.ifStatement(t.logicalExpression('&&', t.memberExpression(t.identifier('argv'), t.identifier('saveToken')), t.identifier('result')), t.blockStatement([
|
|
@@ -86,9 +86,16 @@ function generateExecutorFile(toolName, options) {
|
|
|
86
86
|
])),
|
|
87
87
|
])),
|
|
88
88
|
])),
|
|
89
|
-
|
|
90
|
-
t.
|
|
91
|
-
|
|
89
|
+
(() => {
|
|
90
|
+
const headersId = t.identifier('headers');
|
|
91
|
+
headersId.typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Record'), t.tsTypeParameterInstantiation([
|
|
92
|
+
t.tsStringKeyword(),
|
|
93
|
+
t.tsStringKeyword(),
|
|
94
|
+
])));
|
|
95
|
+
return t.variableDeclaration('const', [
|
|
96
|
+
t.variableDeclarator(headersId, t.objectExpression([])),
|
|
97
|
+
]);
|
|
98
|
+
})(),
|
|
92
99
|
t.ifStatement(t.callExpression(t.memberExpression(t.identifier('store'), t.identifier('hasValidCredentials')), [t.memberExpression(t.identifier('ctx'), t.identifier('name'))]), t.blockStatement([
|
|
93
100
|
t.variableDeclaration('const', [
|
|
94
101
|
t.variableDeclarator(t.identifier('creds'), t.callExpression(t.memberExpression(t.identifier('store'), t.identifier('getCredentials')), [t.memberExpression(t.identifier('ctx'), t.identifier('name'))])),
|
|
@@ -193,9 +200,16 @@ function generateMultiTargetExecutorFile(toolName, targets, options) {
|
|
|
193
200
|
], [t.identifier('targetName')]),
|
|
194
201
|
])),
|
|
195
202
|
])),
|
|
196
|
-
|
|
197
|
-
t.
|
|
198
|
-
|
|
203
|
+
(() => {
|
|
204
|
+
const headersId = t.identifier('headers');
|
|
205
|
+
headersId.typeAnnotation = t.tsTypeAnnotation(t.tsTypeReference(t.identifier('Record'), t.tsTypeParameterInstantiation([
|
|
206
|
+
t.tsStringKeyword(),
|
|
207
|
+
t.tsStringKeyword(),
|
|
208
|
+
])));
|
|
209
|
+
return t.variableDeclaration('const', [
|
|
210
|
+
t.variableDeclarator(headersId, t.objectExpression([])),
|
|
211
|
+
]);
|
|
212
|
+
})(),
|
|
199
213
|
t.variableDeclaration('let', [
|
|
200
214
|
t.variableDeclarator(t.identifier('endpoint'), t.stringLiteral('')),
|
|
201
215
|
]),
|
|
@@ -135,7 +135,7 @@ Create Options:
|
|
|
135
135
|
]))),
|
|
136
136
|
]),
|
|
137
137
|
t.returnStatement(t.callExpression(t.identifier('handleSubcommand'), [
|
|
138
|
-
t.memberExpression(t.identifier('answer'), t.identifier('subcommand')),
|
|
138
|
+
t.tsAsExpression(t.memberExpression(t.identifier('answer'), t.identifier('subcommand')), t.tsStringKeyword()),
|
|
139
139
|
t.identifier('newArgv'),
|
|
140
140
|
t.identifier('prompter'),
|
|
141
141
|
t.identifier('store'),
|
|
@@ -224,7 +224,7 @@ function buildCreateHandler() {
|
|
|
224
224
|
])),
|
|
225
225
|
]),
|
|
226
226
|
t.variableDeclaration('const', [
|
|
227
|
-
t.variableDeclarator(t.identifier('answers'), t.awaitExpression(t.callExpression(t.memberExpression(t.identifier('prompter'), t.identifier('prompt')), [
|
|
227
|
+
t.variableDeclarator(t.identifier('answers'), t.tsAsExpression(t.tsAsExpression(t.awaitExpression(t.callExpression(t.memberExpression(t.identifier('prompter'), t.identifier('prompt')), [
|
|
228
228
|
t.objectExpression([
|
|
229
229
|
t.objectProperty(t.identifier('name'), t.identifier('name'), false, true),
|
|
230
230
|
t.spreadElement(t.identifier('restArgv')),
|
|
@@ -243,7 +243,10 @@ function buildCreateHandler() {
|
|
|
243
243
|
t.objectProperty(t.identifier('required'), t.booleanLiteral(true)),
|
|
244
244
|
]),
|
|
245
245
|
]),
|
|
246
|
-
]))),
|
|
246
|
+
])), t.tsUnknownKeyword()), t.tsTypeReference(t.identifier('Record'), t.tsTypeParameterInstantiation([
|
|
247
|
+
t.tsStringKeyword(),
|
|
248
|
+
t.tsStringKeyword(),
|
|
249
|
+
])))),
|
|
247
250
|
]),
|
|
248
251
|
t.variableDeclaration('const', [
|
|
249
252
|
t.variableDeclarator(t.identifier('contextName'), t.memberExpression(t.identifier('answers'), t.identifier('name'))),
|
|
@@ -380,7 +383,7 @@ function buildUseHandler() {
|
|
|
380
383
|
]),
|
|
381
384
|
]))),
|
|
382
385
|
]),
|
|
383
|
-
t.expressionStatement(t.assignmentExpression('=', t.identifier('contextName'), t.memberExpression(t.identifier('answer'), t.identifier('name')))),
|
|
386
|
+
t.expressionStatement(t.assignmentExpression('=', t.identifier('contextName'), t.tsAsExpression(t.memberExpression(t.identifier('answer'), t.identifier('name')), t.tsStringKeyword()))),
|
|
384
387
|
])),
|
|
385
388
|
t.ifStatement(t.callExpression(t.memberExpression(t.identifier('store'), t.identifier('setCurrentContext')), [t.identifier('contextName')]), t.blockStatement([
|
|
386
389
|
t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('console'), t.identifier('log')), [
|
|
@@ -496,7 +499,7 @@ function buildDeleteHandler() {
|
|
|
496
499
|
]),
|
|
497
500
|
]))),
|
|
498
501
|
]),
|
|
499
|
-
t.expressionStatement(t.assignmentExpression('=', t.identifier('contextName'), t.memberExpression(t.identifier('answer'), t.identifier('name')))),
|
|
502
|
+
t.expressionStatement(t.assignmentExpression('=', t.identifier('contextName'), t.tsAsExpression(t.memberExpression(t.identifier('answer'), t.identifier('name')), t.tsStringKeyword()))),
|
|
500
503
|
])),
|
|
501
504
|
t.ifStatement(t.callExpression(t.memberExpression(t.identifier('store'), t.identifier('deleteContext')), [t.identifier('contextName')]), t.blockStatement([
|
|
502
505
|
t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('console'), t.identifier('log')), [
|
|
@@ -588,7 +591,7 @@ Options:
|
|
|
588
591
|
]))),
|
|
589
592
|
]),
|
|
590
593
|
t.returnStatement(t.callExpression(t.identifier('handleAuthSubcommand'), [
|
|
591
|
-
t.memberExpression(t.identifier('answer'), t.identifier('subcommand')),
|
|
594
|
+
t.tsAsExpression(t.memberExpression(t.identifier('answer'), t.identifier('subcommand')), t.tsStringKeyword()),
|
|
592
595
|
t.identifier('newArgv'),
|
|
593
596
|
t.identifier('prompter'),
|
|
594
597
|
t.identifier('store'),
|
|
@@ -690,7 +693,7 @@ function buildSetTokenHandler() {
|
|
|
690
693
|
]),
|
|
691
694
|
]))),
|
|
692
695
|
]),
|
|
693
|
-
t.expressionStatement(t.assignmentExpression('=', t.identifier('tokenValue'), t.memberExpression(t.identifier('answer'), t.identifier('token')))),
|
|
696
|
+
t.expressionStatement(t.assignmentExpression('=', t.identifier('tokenValue'), t.tsAsExpression(t.memberExpression(t.identifier('answer'), t.identifier('token')), t.tsStringKeyword()))),
|
|
694
697
|
])),
|
|
695
698
|
t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('store'), t.identifier('setCredentials')), [
|
|
696
699
|
t.memberExpression(t.identifier('current'), t.identifier('name')),
|
|
@@ -809,7 +812,7 @@ function buildLogoutHandler() {
|
|
|
809
812
|
]),
|
|
810
813
|
]))),
|
|
811
814
|
]),
|
|
812
|
-
t.ifStatement(t.unaryExpression('!', t.memberExpression(t.identifier('confirm'), t.identifier('confirm'))), t.blockStatement([t.returnStatement()])),
|
|
815
|
+
t.ifStatement(t.unaryExpression('!', t.tsAsExpression(t.memberExpression(t.identifier('confirm'), t.identifier('confirm')), t.tsBooleanKeyword())), t.blockStatement([t.returnStatement()])),
|
|
813
816
|
t.ifStatement(t.callExpression(t.memberExpression(t.identifier('store'), t.identifier('removeCredentials')), [
|
|
814
817
|
t.memberExpression(t.identifier('current'), t.identifier('name')),
|
|
815
818
|
]), t.blockStatement([
|
|
@@ -909,7 +912,7 @@ ${targets.map((tgt) => ` --${tgt.name}-endpoint <url> ${tgt.name} endpoint (de
|
|
|
909
912
|
]))),
|
|
910
913
|
]),
|
|
911
914
|
t.returnStatement(t.callExpression(t.identifier('handleSubcommand'), [
|
|
912
|
-
t.memberExpression(t.identifier('answer'), t.identifier('subcommand')),
|
|
915
|
+
t.tsAsExpression(t.memberExpression(t.identifier('answer'), t.identifier('subcommand')), t.tsStringKeyword()),
|
|
913
916
|
t.identifier('newArgv'),
|
|
914
917
|
t.identifier('prompter'),
|
|
915
918
|
t.identifier('store'),
|
|
@@ -1008,7 +1011,7 @@ function buildMultiTargetCreateHandler(targets) {
|
|
|
1008
1011
|
const targetsObjProps = targets.map((target) => {
|
|
1009
1012
|
const fieldName = `${target.name}Endpoint`;
|
|
1010
1013
|
return t.objectProperty(t.stringLiteral(target.name), t.objectExpression([
|
|
1011
|
-
t.objectProperty(t.identifier('endpoint'), t.memberExpression(t.identifier('answers'), t.identifier(fieldName))),
|
|
1014
|
+
t.objectProperty(t.identifier('endpoint'), t.tsAsExpression(t.memberExpression(t.identifier('answers'), t.identifier(fieldName)), t.tsStringKeyword())),
|
|
1012
1015
|
]));
|
|
1013
1016
|
});
|
|
1014
1017
|
const body = [
|
|
@@ -1030,7 +1033,7 @@ function buildMultiTargetCreateHandler(targets) {
|
|
|
1030
1033
|
]))),
|
|
1031
1034
|
]),
|
|
1032
1035
|
t.variableDeclaration('const', [
|
|
1033
|
-
t.variableDeclarator(t.identifier('contextName'), t.memberExpression(t.identifier('answers'), t.identifier('name'))),
|
|
1036
|
+
t.variableDeclarator(t.identifier('contextName'), t.tsAsExpression(t.memberExpression(t.identifier('answers'), t.identifier('name')), t.tsStringKeyword())),
|
|
1034
1037
|
]),
|
|
1035
1038
|
t.variableDeclaration('const', [
|
|
1036
1039
|
t.variableDeclarator(t.identifier('targets'), t.objectExpression(targetsObjProps)),
|
|
@@ -1038,7 +1041,7 @@ function buildMultiTargetCreateHandler(targets) {
|
|
|
1038
1041
|
t.expressionStatement(t.callExpression(t.memberExpression(t.identifier('store'), t.identifier('createContext')), [
|
|
1039
1042
|
t.identifier('contextName'),
|
|
1040
1043
|
t.objectExpression([
|
|
1041
|
-
t.objectProperty(t.identifier('endpoint'), t.memberExpression(t.identifier('answers'), t.identifier(`${targets[0].name}Endpoint`))),
|
|
1044
|
+
t.objectProperty(t.identifier('endpoint'), t.tsAsExpression(t.memberExpression(t.identifier('answers'), t.identifier(`${targets[0].name}Endpoint`)), t.tsStringKeyword())),
|
|
1042
1045
|
t.objectProperty(t.identifier('targets'), t.identifier('targets')),
|
|
1043
1046
|
]),
|
|
1044
1047
|
])),
|
|
@@ -1061,7 +1064,7 @@ function buildMultiTargetCreateHandler(targets) {
|
|
|
1061
1064
|
t.templateLiteral([
|
|
1062
1065
|
t.templateElement({ raw: ` ${target.name}: `, cooked: ` ${target.name}: ` }),
|
|
1063
1066
|
t.templateElement({ raw: '', cooked: '' }, true),
|
|
1064
|
-
], [t.memberExpression(t.identifier('answers'), t.identifier(fieldName))]),
|
|
1067
|
+
], [t.tsAsExpression(t.memberExpression(t.identifier('answers'), t.identifier(fieldName)), t.tsStringKeyword())]),
|
|
1065
1068
|
])));
|
|
1066
1069
|
}
|
|
1067
1070
|
const func = t.functionDeclaration(t.identifier('handleCreate'), [argvParam, prompterParam, storeParam], t.blockStatement(body), false, true);
|
|
@@ -1137,7 +1140,7 @@ Options:
|
|
|
1137
1140
|
]))),
|
|
1138
1141
|
]),
|
|
1139
1142
|
t.returnStatement(t.callExpression(t.identifier('handleAuthSubcommand'), [
|
|
1140
|
-
t.memberExpression(t.identifier('answer'), t.identifier('subcommand')),
|
|
1143
|
+
t.tsAsExpression(t.memberExpression(t.identifier('answer'), t.identifier('subcommand')), t.tsStringKeyword()),
|
|
1141
1144
|
t.identifier('newArgv'),
|
|
1142
1145
|
t.identifier('prompter'),
|
|
1143
1146
|
t.identifier('store'),
|