stepzen 0.29.0 → 0.30.0-beta.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/README.md +417 -54
- package/lib/commands/import/curl.d.ts +48 -0
- package/lib/commands/import/curl.d.ts.map +1 -0
- package/lib/commands/import/curl.js +246 -0
- package/lib/commands/import/curl.js.map +1 -0
- package/lib/commands/import/graphql.d.ts +34 -0
- package/lib/commands/import/graphql.d.ts.map +1 -0
- package/lib/commands/import/graphql.js +118 -0
- package/lib/commands/import/graphql.js.map +1 -0
- package/lib/commands/import/index.d.ts +22 -0
- package/lib/commands/import/index.d.ts.map +1 -0
- package/lib/commands/import/index.js +165 -0
- package/lib/commands/import/index.js.map +1 -0
- package/lib/commands/import/mysql.d.ts +48 -0
- package/lib/commands/import/mysql.d.ts.map +1 -0
- package/lib/commands/import/mysql.js +145 -0
- package/lib/commands/import/mysql.js.map +1 -0
- package/lib/commands/import/postgresql.d.ts +51 -0
- package/lib/commands/import/postgresql.d.ts.map +1 -0
- package/lib/commands/import/postgresql.js +150 -0
- package/lib/commands/import/postgresql.js.map +1 -0
- package/lib/commands/import/presto.d.ts +49 -0
- package/lib/commands/import/presto.d.ts.map +1 -0
- package/lib/commands/import/presto.js +152 -0
- package/lib/commands/import/presto.js.map +1 -0
- package/lib/commands/import/snowflake.d.ts +53 -0
- package/lib/commands/import/snowflake.d.ts.map +1 -0
- package/lib/commands/import/snowflake.js +181 -0
- package/lib/commands/import/snowflake.js.map +1 -0
- package/lib/commands/list.d.ts.map +1 -1
- package/lib/commands/list.js +0 -2
- package/lib/commands/list.js.map +1 -1
- package/lib/commands/request.js +6 -6
- package/lib/commands/request.js.map +1 -1
- package/lib/commands/service.d.ts +1 -1
- package/lib/commands/service.d.ts.map +1 -1
- package/lib/commands/service.js +12 -12
- package/lib/commands/service.js.map +1 -1
- package/lib/generate/curl2sdl.d.ts +13 -25
- package/lib/generate/curl2sdl.d.ts.map +1 -1
- package/lib/generate/curl2sdl.js +52 -114
- package/lib/generate/curl2sdl.js.map +1 -1
- package/lib/generate/flags.d.ts +19 -0
- package/lib/generate/flags.d.ts.map +1 -0
- package/lib/generate/flags.js +74 -0
- package/lib/generate/flags.js.map +1 -0
- package/lib/generate/graphql2sdl.d.ts +5 -16
- package/lib/generate/graphql2sdl.d.ts.map +1 -1
- package/lib/generate/graphql2sdl.js +4 -49
- package/lib/generate/graphql2sdl.js.map +1 -1
- package/lib/generate/helpers.d.ts +5 -9
- package/lib/generate/helpers.d.ts.map +1 -1
- package/lib/generate/helpers.js +30 -37
- package/lib/generate/helpers.js.map +1 -1
- package/lib/generate/import-command.d.ts +25 -0
- package/lib/generate/import-command.d.ts.map +1 -0
- package/lib/generate/import-command.js +176 -0
- package/lib/generate/import-command.js.map +1 -0
- package/lib/generate/questions.d.ts +30 -0
- package/lib/generate/questions.d.ts.map +1 -0
- package/lib/generate/questions.js +50 -0
- package/lib/generate/questions.js.map +1 -0
- package/lib/generate/sql2sdl.d.ts +14 -18
- package/lib/generate/sql2sdl.d.ts.map +1 -1
- package/lib/generate/sql2sdl.js +29 -92
- package/lib/generate/sql2sdl.js.map +1 -1
- package/lib/hooks/prerun/check-upgrade.js +4 -4
- package/lib/hooks/prerun/check-upgrade.js.map +1 -1
- package/lib/shared/constants.d.ts +1 -0
- package/lib/shared/constants.d.ts.map +1 -1
- package/lib/shared/constants.js +2 -1
- package/lib/shared/constants.js.map +1 -1
- package/lib/shared/curl-parser.d.ts +3 -3
- package/lib/shared/curl-parser.d.ts.map +1 -1
- package/lib/shared/curl-parser.js +52 -39
- package/lib/shared/curl-parser.js.map +1 -1
- package/lib/shared/docker.d.ts +8 -36
- package/lib/shared/docker.d.ts.map +1 -1
- package/lib/shared/docker.js +44 -42
- package/lib/shared/docker.js.map +1 -1
- package/lib/shared/dsn-parser.d.ts +3 -0
- package/lib/shared/dsn-parser.d.ts.map +1 -0
- package/lib/shared/dsn-parser.js +28 -0
- package/lib/shared/dsn-parser.js.map +1 -0
- package/lib/shared/header-params-parser.d.ts +7 -5
- package/lib/shared/header-params-parser.d.ts.map +1 -1
- package/lib/shared/header-params-parser.js +55 -43
- package/lib/shared/header-params-parser.js.map +1 -1
- package/lib/shared/header.d.ts +2 -2
- package/lib/shared/header.d.ts.map +1 -1
- package/lib/shared/header.js +13 -7
- package/lib/shared/header.js.map +1 -1
- package/lib/shared/inquirer.d.ts +2 -0
- package/lib/shared/inquirer.d.ts.map +1 -1
- package/lib/shared/inquirer.js +12 -4
- package/lib/shared/inquirer.js.map +1 -1
- package/lib/shared/path-params-parser.d.ts +2 -2
- package/lib/shared/path-params-parser.d.ts.map +1 -1
- package/lib/shared/path-params-parser.js +11 -7
- package/lib/shared/path-params-parser.js.map +1 -1
- package/lib/shared/request-variables-parser.d.ts +2 -9
- package/lib/shared/request-variables-parser.d.ts.map +1 -1
- package/lib/shared/request-variables-parser.js +8 -8
- package/lib/shared/request-variables-parser.js.map +1 -1
- package/lib/shared/types.d.ts +33 -6
- package/lib/shared/types.d.ts.map +1 -1
- package/lib/shared/utils.d.ts +5 -13
- package/lib/shared/utils.d.ts.map +1 -1
- package/lib/shared/utils.js.map +1 -1
- package/oclif.manifest.json +684 -197
- package/package.json +6 -6
- package/lib/commands/import.d.ts +0 -85
- package/lib/commands/import.d.ts.map +0 -1
- package/lib/commands/import.js +0 -645
- package/lib/commands/import.js.map +0 -1
- package/lib/generate/index.d.ts +0 -6
- package/lib/generate/index.d.ts.map +0 -1
- package/lib/generate/index.js +0 -4
- package/lib/generate/index.js.map +0 -1
package/lib/generate/curl2sdl.js
CHANGED
|
@@ -1,15 +1,61 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright (c) 2020,2021,2022,2023, StepZen, Inc.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.makeDuplicateParamsMessage = exports.compileParameterList = exports.curl2sdl = void 0;
|
|
5
5
|
const chalk = require("chalk");
|
|
6
6
|
const lodash_1 = require("lodash");
|
|
7
|
-
const string_argv_1 = require("string-argv");
|
|
8
|
-
const inquirer = require("../shared/inquirer");
|
|
9
|
-
const curl_parser_1 = require("../shared/curl-parser");
|
|
10
|
-
const path_params_parser_1 = require("../shared/path-params-parser");
|
|
11
|
-
const helpers_1 = require("./helpers");
|
|
12
7
|
const constants_1 = require("../shared/constants");
|
|
8
|
+
const helpers_1 = require("./helpers");
|
|
9
|
+
const curl2sdl = async ({ curlArgs, queryName, rootType, typePrefix, pathParams, headers, }, configuration) => {
|
|
10
|
+
const { result, error } = await (0, helpers_1.queryIntrospectionService)((0, constants_1.getIntrospectionUrl)(configuration), {
|
|
11
|
+
operation: 'getSDLFromCurl',
|
|
12
|
+
variables: {
|
|
13
|
+
command: {
|
|
14
|
+
type: 'String!',
|
|
15
|
+
value: curlArgs.url,
|
|
16
|
+
},
|
|
17
|
+
queryName: {
|
|
18
|
+
type: 'String',
|
|
19
|
+
value: queryName || null,
|
|
20
|
+
},
|
|
21
|
+
rootType: {
|
|
22
|
+
type: 'String',
|
|
23
|
+
value: rootType || null,
|
|
24
|
+
},
|
|
25
|
+
typePrefix: {
|
|
26
|
+
type: 'String',
|
|
27
|
+
value: typePrefix || null,
|
|
28
|
+
},
|
|
29
|
+
headers: {
|
|
30
|
+
type: '[HeaderInput!]',
|
|
31
|
+
value: headers && headers.length > 0 ? headers : null,
|
|
32
|
+
},
|
|
33
|
+
data: {
|
|
34
|
+
type: 'String',
|
|
35
|
+
value: curlArgs.data || null,
|
|
36
|
+
},
|
|
37
|
+
method: {
|
|
38
|
+
type: 'HTTPMethod!',
|
|
39
|
+
value: curlArgs.method,
|
|
40
|
+
},
|
|
41
|
+
pathParams: {
|
|
42
|
+
type: '[PathParamInput!]',
|
|
43
|
+
value: pathParams.length > 0 ? pathParams : null,
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
if (error) {
|
|
48
|
+
return error.message.includes('Query was interrupted after timeout')
|
|
49
|
+
? {
|
|
50
|
+
error: {
|
|
51
|
+
message: 'The StepZen REST introspection service has timed out.',
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
: { error };
|
|
55
|
+
}
|
|
56
|
+
return { result };
|
|
57
|
+
};
|
|
58
|
+
exports.curl2sdl = curl2sdl;
|
|
13
59
|
/**
|
|
14
60
|
* Collect together all query parameters from HTTP headers and from the
|
|
15
61
|
* pathname, and return them as a uniform list.
|
|
@@ -90,112 +136,4 @@ const makeDuplicateParamsMessage = (headers, pathParams, url) => {
|
|
|
90
136
|
return null;
|
|
91
137
|
};
|
|
92
138
|
exports.makeDuplicateParamsMessage = makeDuplicateParamsMessage;
|
|
93
|
-
const askCurlQuestions = async (defaultAnswers = {}) => {
|
|
94
|
-
const questions = [
|
|
95
|
-
{
|
|
96
|
-
name: 'url',
|
|
97
|
-
message: 'Endpoint URL or a full curl command',
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
name: 'pathParams',
|
|
101
|
-
message: 'Parameters for endpoint URL path',
|
|
102
|
-
},
|
|
103
|
-
{
|
|
104
|
-
name: 'queryName',
|
|
105
|
-
message: 'Query name to use when generating schema (leave blank to use defaults)',
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
name: 'rootType',
|
|
109
|
-
message: 'Query type name to use when generating schema (leave blank to use defaults)',
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
name: 'typePrefix',
|
|
113
|
-
message: 'Prefix to add to all generated type names (leave blank to use defaults)',
|
|
114
|
-
},
|
|
115
|
-
];
|
|
116
|
-
const answers = await inquirer.prompt('import-curl', (0, helpers_1.overrideDefaults)(questions, defaultAnswers));
|
|
117
|
-
const curlArgs = (0, curl_parser_1.parseCurlArgv)((0, string_argv_1.default)(answers.url));
|
|
118
|
-
if ('error' in curlArgs) {
|
|
119
|
-
console.log();
|
|
120
|
-
console.log(chalk.red('A problem occurred while parsing the curl command:\n', curlArgs.error), '\nPlease enter a URL or a supported curl command.');
|
|
121
|
-
console.log();
|
|
122
|
-
return (0, exports.askCurlQuestions)(answers);
|
|
123
|
-
}
|
|
124
|
-
const parsedPathParamsOrError = (0, path_params_parser_1.parsePathParamsPattern)(curlArgs.url, answers.pathParams);
|
|
125
|
-
if ('error' in parsedPathParamsOrError) {
|
|
126
|
-
console.log();
|
|
127
|
-
console.log(chalk.red('A problem occurred while parsing path parameters pattern:\n', parsedPathParamsOrError.error));
|
|
128
|
-
console.log();
|
|
129
|
-
console.log(`Please enter a path parameter specification that` +
|
|
130
|
-
` can be formed by taking the original path and replacing the variable` +
|
|
131
|
-
` segments with ${chalk.bold('$paramName')} placeholders.`);
|
|
132
|
-
console.log();
|
|
133
|
-
console.log('Example:\n' +
|
|
134
|
-
`\tendpoint URL: https://example.com/users/jane/posts/12\n ` +
|
|
135
|
-
`\tpath parameters: /users/${chalk.bold('$userId')}/posts/${chalk.bold('$postId')}`);
|
|
136
|
-
console.log();
|
|
137
|
-
return (0, exports.askCurlQuestions)(answers);
|
|
138
|
-
}
|
|
139
|
-
return {
|
|
140
|
-
curlArgs,
|
|
141
|
-
queryName: answers.queryName,
|
|
142
|
-
rootType: answers.rootType,
|
|
143
|
-
typePrefix: answers.typePrefix,
|
|
144
|
-
pathParams: parsedPathParamsOrError,
|
|
145
|
-
};
|
|
146
|
-
};
|
|
147
|
-
exports.askCurlQuestions = askCurlQuestions;
|
|
148
|
-
const curl2sdl = async ({ curlArgs, name, source, queryName, rootType, typePrefix, pathParams, headers, onConflict, }, configuration) => {
|
|
149
|
-
const response = await (0, helpers_1.queryIntrospectionService)((0, constants_1.getIntrospectionUrl)(configuration), {
|
|
150
|
-
operation: 'getSDLFromCurl',
|
|
151
|
-
variables: {
|
|
152
|
-
command: {
|
|
153
|
-
type: 'String!',
|
|
154
|
-
value: curlArgs.url,
|
|
155
|
-
},
|
|
156
|
-
queryName: {
|
|
157
|
-
type: 'String',
|
|
158
|
-
value: queryName || null,
|
|
159
|
-
},
|
|
160
|
-
rootType: {
|
|
161
|
-
type: 'String',
|
|
162
|
-
value: rootType || null,
|
|
163
|
-
},
|
|
164
|
-
typePrefix: {
|
|
165
|
-
type: 'String',
|
|
166
|
-
value: typePrefix || null,
|
|
167
|
-
},
|
|
168
|
-
headers: {
|
|
169
|
-
type: '[HeaderInput!]',
|
|
170
|
-
value: headers && headers.length > 0 ? headers : null,
|
|
171
|
-
},
|
|
172
|
-
data: {
|
|
173
|
-
type: 'String',
|
|
174
|
-
value: curlArgs.data || null,
|
|
175
|
-
},
|
|
176
|
-
method: {
|
|
177
|
-
type: 'HTTPMethod!',
|
|
178
|
-
value: curlArgs.method,
|
|
179
|
-
},
|
|
180
|
-
pathParams: {
|
|
181
|
-
type: '[PathParamInput!]',
|
|
182
|
-
value: pathParams.length > 0 ? pathParams : null,
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
});
|
|
186
|
-
if (response.error) {
|
|
187
|
-
return {
|
|
188
|
-
error: response.error.includes('Query was interrupted after timeout')
|
|
189
|
-
? 'The StepZen REST introspection service has timed out.'
|
|
190
|
-
: response.error,
|
|
191
|
-
};
|
|
192
|
-
}
|
|
193
|
-
return (0, helpers_1.writeSdlAndConfig)({
|
|
194
|
-
name: name || 'curl',
|
|
195
|
-
source,
|
|
196
|
-
onConflict,
|
|
197
|
-
response,
|
|
198
|
-
});
|
|
199
|
-
};
|
|
200
|
-
exports.curl2sdl = curl2sdl;
|
|
201
139
|
//# sourceMappingURL=curl2sdl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"curl2sdl.js","sourceRoot":"","sources":["../../src/generate/curl2sdl.ts"],"names":[],"mappings":";AAAA,mDAAmD;;;AAEnD,+BAA8B;
|
|
1
|
+
{"version":3,"file":"curl2sdl.js","sourceRoot":"","sources":["../../src/generate/curl2sdl.ts"],"names":[],"mappings":";AAAA,mDAAmD;;;AAEnD,+BAA8B;AAC9B,mCAAuC;AAEvC,mDAAuD;AACvD,uCAAmD;AAwB5C,MAAM,Q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,CAAC,EAAE,CAAC,EAAE,EAAE,CACrB,KAAK,CAAC,GAAG,CAAC,MAAM,KAAK,YAAY,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CACvD;aACA,IAAI,CAAC,IAAI,CAAC,EAAE,CAClB,CAAA;IAEH,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;QACrB,OAAO,CACL,yDAAyD;YACzD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;YACjB,mEAAmE,CACpE,CAAA;KACF;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AA5CY,QAAA,0BAA0B,8BA4CtC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A helper to share flags between several import commands.
|
|
3
|
+
*/
|
|
4
|
+
export declare const ImportFlags: {
|
|
5
|
+
prefix: () => import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
6
|
+
header: () => import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
7
|
+
headerParam: () => import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
|
+
dbHost: () => import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
9
|
+
dbUser: () => import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
10
|
+
dbPassword: () => import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
11
|
+
dbDatabase: () => import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
12
|
+
dbSchema: (opts?: {
|
|
13
|
+
default?: string;
|
|
14
|
+
}) => import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
15
|
+
dbLinkTypes: () => import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
16
|
+
dbInclude: () => import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
17
|
+
dbUseDeprecatedNaming: () => import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=flags.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flags.d.ts","sourceRoot":"","sources":["../../src/generate/flags.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,eAAO,MAAM,WAAW;;;;;;;;sBAkDL;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAC;;;;CAoCpC,CAAA"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2020,2021,2022,2023, StepZen, Inc.
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ImportFlags = void 0;
|
|
5
|
+
const core_1 = require("@oclif/core");
|
|
6
|
+
const chalk = require("chalk");
|
|
7
|
+
/**
|
|
8
|
+
* A helper to share flags between several import commands.
|
|
9
|
+
*/
|
|
10
|
+
exports.ImportFlags = {
|
|
11
|
+
prefix: () => core_1.Flags.string({
|
|
12
|
+
description: 'Prefix to add to every type in the generated schema',
|
|
13
|
+
}),
|
|
14
|
+
header: () => core_1.Flags.string({
|
|
15
|
+
char: 'H',
|
|
16
|
+
description: `Specifies a request header to pass` +
|
|
17
|
+
`\n` +
|
|
18
|
+
`\nExample:` +
|
|
19
|
+
`\nstepzen import curl https://example.com/api/customers \\` +
|
|
20
|
+
`\n\t-H ${chalk.bold('"Authorization: apikey SecretAPIKeyValue"')}`,
|
|
21
|
+
multiple: true,
|
|
22
|
+
}),
|
|
23
|
+
headerParam: () => core_1.Flags.string({
|
|
24
|
+
description: `Specifies a parameter in a header value.` +
|
|
25
|
+
` Can be formed by taking a ${chalk.bold('-H, --header')} flag and replacing the` +
|
|
26
|
+
` variable part of the header value with a ${chalk.bold('$paramName')} placeholder. Repeat this flag once for each header with a parameter.` +
|
|
27
|
+
`\n` +
|
|
28
|
+
`\nExample:` +
|
|
29
|
+
`\nstepzen import curl https://example.com/api/customers \\` +
|
|
30
|
+
`\n\t-H "Authorization: apikey SecretAPIKeyValue" \\` +
|
|
31
|
+
`\n\t--header-param 'Authorization: apikey ${chalk.bold('$apikey')}'`,
|
|
32
|
+
multiple: true,
|
|
33
|
+
}),
|
|
34
|
+
dbHost: () => core_1.Flags.string({
|
|
35
|
+
description: 'Database host and optional port (as HOST[:PORT])',
|
|
36
|
+
}),
|
|
37
|
+
dbUser: () => core_1.Flags.string({
|
|
38
|
+
description: 'Database user name',
|
|
39
|
+
}),
|
|
40
|
+
dbPassword: () => core_1.Flags.string({
|
|
41
|
+
description: 'Database password',
|
|
42
|
+
}),
|
|
43
|
+
dbDatabase: () => core_1.Flags.string({
|
|
44
|
+
description: 'Name of database to import',
|
|
45
|
+
}),
|
|
46
|
+
dbSchema: (opts = {}) => core_1.Flags.string({
|
|
47
|
+
description: `Database schema to import tables from (default: ${opts.default || 'public'})`,
|
|
48
|
+
}),
|
|
49
|
+
dbLinkTypes: () => core_1.Flags.boolean({
|
|
50
|
+
description: `Automatically link types based on` +
|
|
51
|
+
` foreign key relationships using @materializer` +
|
|
52
|
+
` ${chalk.dim('(https://stepzen.com/docs/features/linking-types)')}`,
|
|
53
|
+
}),
|
|
54
|
+
dbInclude: () => core_1.Flags.string({
|
|
55
|
+
description: `Should the generated GraphQL schema` +
|
|
56
|
+
` be based only on database views, only on tables or on both`,
|
|
57
|
+
options: ['tables-only', 'views-only', 'tables-and-views'],
|
|
58
|
+
}),
|
|
59
|
+
dbUseDeprecatedNaming: () => core_1.Flags.boolean({
|
|
60
|
+
description: chalk `Use the {yellow deprecated} pre-2023 naming convention in the` +
|
|
61
|
+
chalk ` generated GraphQL schema:` +
|
|
62
|
+
chalk `\n\t- the generated type and property names are auto-capitalized` +
|
|
63
|
+
chalk ` into PascalCase` +
|
|
64
|
+
chalk `\n\t- the generated field names use the {italic getCustomer} and` +
|
|
65
|
+
chalk ` {italic getCustomerList} style.` +
|
|
66
|
+
chalk `\n` +
|
|
67
|
+
chalk `\nOn the other hand, when using the default naming convention:` +
|
|
68
|
+
chalk `\n\t- the generated type and property names match exactly the` +
|
|
69
|
+
chalk ` DB table and column names` +
|
|
70
|
+
chalk `\n\t- the generated field names use the {italic customer} and` +
|
|
71
|
+
chalk ` {italic customerList} style.`,
|
|
72
|
+
}),
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=flags.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flags.js","sourceRoot":"","sources":["../../src/generate/flags.ts"],"names":[],"mappings":";AAAA,mDAAmD;;;AAEnD,sCAAiC;AACjC,+BAA8B;AAE9B;;GAEG;AACU,QAAA,WAAW,GAAG;IACzB,MAAM,EAAE,GAAG,EAAE,CACX,YAAK,CAAC,MAAM,CAAC;QACX,WAAW,EAAE,qDAAqD;KACnE,CAAC;IACJ,MAAM,EAAE,GAAG,EAAE,CACX,YAAK,CAAC,MAAM,CAAC;QACX,IAAI,EAAE,GAAG;QACT,WAAW,EACT,oCAAoC;YACpC,IAAI;YACJ,YAAY;YACZ,4DAA4D;YAC5D,UAAU,KAAK,CAAC,IAAI,CAAC,2CAA2C,CAAC,EAAE;QACrE,QAAQ,EAAE,IAAI;KACf,CAAC;IACJ,WAAW,EAAE,GAAG,EAAE,CAChB,YAAK,CAAC,MAAM,CAAC;QACX,WAAW,EACT,0CAA0C;YAC1C,8BAA8B,KAAK,CAAC,IAAI,CACtC,cAAc,CACf,yBAAyB;YAC1B,6CAA6C,KAAK,CAAC,IAAI,CACrD,YAAY,CACb,uEAAuE;YACxE,IAAI;YACJ,YAA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,kCAAkC;YACvC,KAAK,CAAA,IAAI;YACT,KAAK,CAAA,gEAAgE;YACrE,KAAK,CAAA,+DAA+D;YACpE,KAAK,CAAA,4BAA4B;YACjC,KAAK,CAAA,+DAA+D;YACpE,KAAK,CAAA,+BAA+B;KACvC,CAAC;CACL,CAAA"}
|
|
@@ -1,23 +1,12 @@
|
|
|
1
|
-
import { HeaderInput } from '../shared/header';
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
1
|
+
import type { HeaderInput } from '../shared/header';
|
|
2
|
+
import type { ErrorOr, MachineConfiguration } from '../shared/types';
|
|
3
|
+
import type { IntrospectionServiceResponse } from './helpers';
|
|
4
|
+
import { CommonImportOptions } from './import-command';
|
|
4
5
|
export declare type GraphQL2SdlOptions = CommonImportOptions & {
|
|
5
6
|
endpoint: string;
|
|
6
7
|
typePrefix?: string;
|
|
7
8
|
includeRootOperations?: boolean;
|
|
8
9
|
headers: readonly HeaderInput[];
|
|
9
10
|
};
|
|
10
|
-
export declare
|
|
11
|
-
export declare type GraphQLAnswers = {
|
|
12
|
-
endpoint: string;
|
|
13
|
-
typePrefix: string;
|
|
14
|
-
includeRootOperations: boolean;
|
|
15
|
-
header: string;
|
|
16
|
-
};
|
|
17
|
-
export declare const askGraphQLQuestions: (defaultAnswers?: Partial<GraphQLAnswers>) => Promise<InteractiveGraphQL2SdlOptions>;
|
|
18
|
-
export declare const graphql2sdl: ({ name, source, endpoint, typePrefix, includeRootOperations, headers, onConflict, }: GraphQL2SdlOptions, configuration: MachineConfiguration) => Promise<{
|
|
19
|
-
error: string;
|
|
20
|
-
} | {
|
|
21
|
-
outPath: string;
|
|
22
|
-
}>;
|
|
11
|
+
export declare const graphql2sdl: ({ endpoint, typePrefix, includeRootOperations, headers }: GraphQL2SdlOptions, configuration: MachineConfiguration) => Promise<ErrorOr<IntrospectionServiceResponse>>;
|
|
23
12
|
//# sourceMappingURL=graphql2sdl.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql2sdl.d.ts","sourceRoot":"","sources":["../../src/generate/graphql2sdl.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"graphql2sdl.d.ts","sourceRoot":"","sources":["../../src/generate/graphql2sdl.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,kBAAkB,CAAA;AACjD,OAAO,KAAK,EAAC,OAAO,EAAE,oBAAoB,EAAC,MAAM,iBAAiB,CAAA;AAClE,OAAO,KAAK,EAAC,4BAA4B,EAAC,MAAM,WAAW,CAAA;AAC3D,OAAO,EAAC,mBAAmB,EAAC,MAAM,kBAAkB,CAAA;AAEpD,oBAAY,kBAAkB,GAAG,mBAAmB,GAAG;IACrD,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAC/B,OAAO,EAAE,SAAS,WAAW,EAAE,CAAA;CAChC,CAAA;AAED,eAAO,MAAM,WAAW,6DACkC,kBAAkB,iBAC3D,oBAAoB,KAClC,QAAQ,QAAQ,4BAA4B,CAAC,CAsB/C,CAAA"}
|
|
@@ -1,47 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright (c) 2020,2021,2022,2023, StepZen, Inc.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.graphql2sdl =
|
|
5
|
-
const inquirer = require("../shared/inquirer");
|
|
6
|
-
const header_1 = require("../shared/header");
|
|
7
|
-
const helpers_1 = require("./helpers");
|
|
4
|
+
exports.graphql2sdl = void 0;
|
|
8
5
|
const constants_1 = require("../shared/constants");
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
name: 'endpoint',
|
|
13
|
-
message: 'What is the GraphQL endpoint URL?',
|
|
14
|
-
validate: input => input.trim() !== '',
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
name: 'typePrefix',
|
|
18
|
-
message: 'Prefix to add to all generated type names (leave blank for none)',
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
name: 'includeRootOperations',
|
|
22
|
-
type: 'confirm',
|
|
23
|
-
message: 'Should type prefix be added to query and mutation fields as well?',
|
|
24
|
-
when: answers => Boolean(answers.typePrefix),
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
name: 'header',
|
|
28
|
-
type: 'input',
|
|
29
|
-
message: 'Add an HTTP header, e.g. Header-Name: header value (leave blank for none)',
|
|
30
|
-
validate: input => input === '' || header_1.HEADER_REGEX.test(input.trim()) || 'invalid header',
|
|
31
|
-
},
|
|
32
|
-
];
|
|
33
|
-
const answers = await inquirer.prompt('import-graphql', (0, helpers_1.overrideDefaults)(questions, defaultAnswers));
|
|
34
|
-
const header = (0, header_1.parseHeader)(answers.header);
|
|
35
|
-
return {
|
|
36
|
-
endpoint: answers.endpoint,
|
|
37
|
-
typePrefix: answers.typePrefix.trim() === '' ? undefined : answers.typePrefix.trim(),
|
|
38
|
-
includeRootOperations: answers.includeRootOperations,
|
|
39
|
-
headers: header && !('error' in header) ? [header] : [],
|
|
40
|
-
};
|
|
41
|
-
};
|
|
42
|
-
exports.askGraphQLQuestions = askGraphQLQuestions;
|
|
43
|
-
const graphql2sdl = async ({ name, source, endpoint, typePrefix, includeRootOperations, headers, onConflict, }, configuration) => {
|
|
44
|
-
const response = await (0, helpers_1.queryIntrospectionService)((0, constants_1.getIntrospectionUrl)(configuration), {
|
|
6
|
+
const helpers_1 = require("./helpers");
|
|
7
|
+
const graphql2sdl = async ({ endpoint, typePrefix, includeRootOperations, headers }, configuration) => {
|
|
8
|
+
return (0, helpers_1.queryIntrospectionService)((0, constants_1.getIntrospectionUrl)(configuration), {
|
|
45
9
|
operation: 'getSDLFromGraphQL',
|
|
46
10
|
variables: {
|
|
47
11
|
endpoint: {
|
|
@@ -62,15 +26,6 @@ const graphql2sdl = async ({ name, source, endpoint, typePrefix, includeRootOper
|
|
|
62
26
|
},
|
|
63
27
|
},
|
|
64
28
|
});
|
|
65
|
-
if (response.error) {
|
|
66
|
-
return { error: response.error };
|
|
67
|
-
}
|
|
68
|
-
return (0, helpers_1.writeSdlAndConfig)({
|
|
69
|
-
name: name || 'graphql',
|
|
70
|
-
source,
|
|
71
|
-
onConflict,
|
|
72
|
-
response,
|
|
73
|
-
});
|
|
74
29
|
};
|
|
75
30
|
exports.graphql2sdl = graphql2sdl;
|
|
76
31
|
//# sourceMappingURL=graphql2sdl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graphql2sdl.js","sourceRoot":"","sources":["../../src/generate/graphql2sdl.ts"],"names":[],"mappings":";AAAA,mDAAmD;;;AAEnD
|
|
1
|
+
{"version":3,"file":"graphql2sdl.js","sourceRoot":"","sources":["../../src/generate/graphql2sdl.ts"],"names":[],"mappings":";AAAA,mDAAmD;;;AAEnD,mDAAuD;AACvD,uCAAmD;AAc5C,MAAM,WAAW,GAAG,KAAK,EAC9B,EAAC,QAAQ,EAAE,UAAU,EAAE,qBAAqB,EAAE,OAAO,EAAqB,EAC1E,aAAmC,EACa,EAAE;IAClD,OAAO,IAAA,mCAAyB,EAAC,IAAA,+BAAmB,EAAC,aAAa,CAAC,EAAE;QACnE,SAAS,EAAE,mBAAmB;QAC9B,SAAS,EAAE;YACT,QAAQ,EAAE;gBACR,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE,QAAQ;aAChB;YACD,UAAU,EAAE;gBACV,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,UAAU,IAAI,IAAI;aAC1B;YACD,qBAAqB,EAAE;gBACrB,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE,qBAAqB,IAAI,IAAI;aACrC;YACD,OAAO,EAAE;gBACP,IAAI,EAAE,gBAAgB;gBACtB,KAAK,EAAE,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI;aACtD;SACF;KACF,CAAC,CAAA;AACJ,CAAC,CAAA;AAzBY,QAAA,WAAW,eAyBvB"}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
source: string;
|
|
4
|
-
dsn: string | undefined;
|
|
5
|
-
};
|
|
1
|
+
import type { HeaderInput } from '../shared/header';
|
|
2
|
+
import type { ErrorOr } from '../shared/types';
|
|
6
3
|
export declare type IntrospectionServiceQuery = {
|
|
7
4
|
operation: string;
|
|
8
5
|
variables: {
|
|
@@ -13,11 +10,10 @@ export declare type IntrospectionServiceQuery = {
|
|
|
13
10
|
};
|
|
14
11
|
};
|
|
15
12
|
export declare type IntrospectionServiceResponse = {
|
|
16
|
-
sdl
|
|
13
|
+
sdl: string;
|
|
17
14
|
config?: string;
|
|
18
|
-
error?: string;
|
|
19
15
|
};
|
|
20
|
-
export declare const queryIntrospectionService: (serverUrl: string, query: IntrospectionServiceQuery) => Promise<IntrospectionServiceResponse
|
|
16
|
+
export declare const queryIntrospectionService: (serverUrl: string, query: IntrospectionServiceQuery) => Promise<ErrorOr<IntrospectionServiceResponse>>;
|
|
21
17
|
export declare const writeSdlAndConfig: ({ name, source, mergeTypes, onConflict, response, }: {
|
|
22
18
|
name: string;
|
|
23
19
|
source: string;
|
|
@@ -27,5 +23,5 @@ export declare const writeSdlAndConfig: ({ name, source, mergeTypes, onConflict,
|
|
|
27
23
|
}) => Promise<{
|
|
28
24
|
outPath: string;
|
|
29
25
|
}>;
|
|
30
|
-
export declare const
|
|
26
|
+
export declare const parseHeaderFlags: (headerFlagValues?: string[], headerParamFlagValues?: string[]) => HeaderInput[];
|
|
31
27
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/generate/helpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/generate/helpers.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAS,WAAW,EAAC,MAAM,kBAAkB,CAAA;AACzD,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,iBAAiB,CAAA;AAE5C,oBAAY,yBAAyB,GAAG;IACtC,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE;QAAC,CAAC,EAAE,EAAE,MAAM,GAAG;YAAC,IAAI,EAAE,MAAM,CAAC;YAAC,KAAK,EAAE,GAAG,GAAG,IAAI,CAAA;SAAC,CAAA;KAAC,CAAA;CAC7D,CAAA;AAED,oBAAY,4BAA4B,GAAG;IACzC,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,yBAAyB,cACzB,MAAM,SACV,yBAAyB,KAC/B,QAAQ,QAAQ,4BAA4B,CAAC,CAwG/C,CAAA;AAED,eAAO,MAAM,iBAAiB;UAOtB,MAAM;YACJ,MAAM;;gBAEF,WAAW,GAAG,QAAQ;cACxB,4BAA4B;;;EA0CvC,CAAA;AAED,eAAO,MAAM,gBAAgB,sBACR,MAAM,EAAE,0BACH,MAAM,EAAE,KAC/B,WAAW,EAqBb,CAAA"}
|
package/lib/generate/helpers.js
CHANGED
|
@@ -1,44 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright (c) 2020,2021,2022,2023, StepZen, Inc.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.parseHeaderFlags = exports.writeSdlAndConfig = exports.queryIntrospectionService = void 0;
|
|
5
5
|
const errors_1 = require("@oclif/core/lib/errors");
|
|
6
|
-
const debug = require("debug");
|
|
7
6
|
const fetch_1 = require("@stepzen/fetch");
|
|
7
|
+
const transpiler = require("@stepzen/transpiler");
|
|
8
|
+
const debug = require("debug");
|
|
8
9
|
const fsx = require("fs-extra");
|
|
9
10
|
const lodash_1 = require("lodash");
|
|
10
11
|
const os = require("os");
|
|
11
12
|
const path = require("path");
|
|
12
|
-
const transpiler = require("@stepzen/transpiler");
|
|
13
13
|
const prettier = require("prettier");
|
|
14
14
|
const errors_2 = require("../shared/errors");
|
|
15
|
-
const
|
|
15
|
+
const header_1 = require("../shared/header");
|
|
16
|
+
const header_params_parser_1 = require("../shared/header-params-parser");
|
|
16
17
|
const rmtemp_1 = require("../shared/rmtemp");
|
|
17
|
-
const
|
|
18
|
-
const trimmed = arg.trim();
|
|
19
|
-
const hasDsn = trimmed.includes('://');
|
|
20
|
-
let source;
|
|
21
|
-
let dsn;
|
|
22
|
-
// Now supports importing only one schema at a time:
|
|
23
|
-
// https://github.com/steprz/stepzen-cli/issues/628
|
|
24
|
-
if (hasDsn) {
|
|
25
|
-
source = trimmed.split('://')[0];
|
|
26
|
-
dsn = trimmed;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
if (trimmed.includes(',') || trimmed.includes(' ')) {
|
|
30
|
-
throw new errors_1.CLIError("Cannot import multiple schemas in one command; please specify only one (e.g. 'stepzen import mysql')");
|
|
31
|
-
}
|
|
32
|
-
source = trimmed;
|
|
33
|
-
}
|
|
34
|
-
// support `postgres` as an alias to `postgresql`
|
|
35
|
-
// https://github.com/steprz/stepzen-cli/issues/431
|
|
36
|
-
if (source.toLowerCase() === 'postgres') {
|
|
37
|
-
source = 'postgresql';
|
|
38
|
-
}
|
|
39
|
-
return { source, dsn };
|
|
40
|
-
};
|
|
41
|
-
exports.getSource = getSource;
|
|
18
|
+
const utils_1 = require("../shared/utils");
|
|
42
19
|
const queryIntrospectionService = async (serverUrl, query) => {
|
|
43
20
|
let json;
|
|
44
21
|
try {
|
|
@@ -101,7 +78,7 @@ const queryIntrospectionService = async (serverUrl, query) => {
|
|
|
101
78
|
? `: ${JSON.stringify(error.extensions.cause)}`
|
|
102
79
|
: ''));
|
|
103
80
|
};
|
|
104
|
-
return { error: json.errors.map(compileError).join('\n') };
|
|
81
|
+
return { error: { message: json.errors.map(compileError).join('\n') } };
|
|
105
82
|
}
|
|
106
83
|
if (!json.data[query.operation]) {
|
|
107
84
|
debug('stepzen:introspection')('expected the response from the introspection service ' +
|
|
@@ -115,7 +92,7 @@ const queryIntrospectionService = async (serverUrl, query) => {
|
|
|
115
92
|
`\`${query.operation}.sdl\` properties`);
|
|
116
93
|
throw new errors_1.CLIError(errors_2.PERMANENT_STEPZEN_ERROR);
|
|
117
94
|
}
|
|
118
|
-
return { config, sdl };
|
|
95
|
+
return { result: { config, sdl } };
|
|
119
96
|
};
|
|
120
97
|
exports.queryIntrospectionService = queryIntrospectionService;
|
|
121
98
|
const writeSdlAndConfig = async ({ name, source, mergeTypes = false, onConflict, response, }) => {
|
|
@@ -148,11 +125,27 @@ const writeSdlAndConfig = async ({ name, source, mergeTypes = false, onConflict,
|
|
|
148
125
|
}
|
|
149
126
|
};
|
|
150
127
|
exports.writeSdlAndConfig = writeSdlAndConfig;
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
128
|
+
const parseHeaderFlags = (headerFlagValues, headerParamFlagValues) => {
|
|
129
|
+
const headers = [];
|
|
130
|
+
if (headerFlagValues) {
|
|
131
|
+
headerFlagValues.forEach(value => {
|
|
132
|
+
const { result, error } = (0, header_1.parseHeader)(value);
|
|
133
|
+
if (error) {
|
|
134
|
+
throw new errors_1.CLIError(error.message);
|
|
135
|
+
}
|
|
136
|
+
// A `null` from parseHeader() means a header should NOT be
|
|
137
|
+
// sent. This is not supported by zenserv / the introspection service
|
|
138
|
+
// so the CLI simply omits such headers
|
|
139
|
+
if (result) {
|
|
140
|
+
headers.push(result); // header
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
const { result, error } = (0, header_params_parser_1.makeHeaders)(headers, headerParamFlagValues);
|
|
145
|
+
if (error) {
|
|
146
|
+
throw new errors_1.CLIError(error.message);
|
|
147
|
+
}
|
|
148
|
+
return result;
|
|
156
149
|
};
|
|
157
|
-
exports.
|
|
150
|
+
exports.parseHeaderFlags = parseHeaderFlags;
|
|
158
151
|
//# sourceMappingURL=helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/generate/helpers.ts"],"names":[],"mappings":";AAAA,mDAAmD;;;AAEnD,mDAA+C;AAC/C,+BAA8B;AAC9B,
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/generate/helpers.ts"],"names":[],"mappings":";AAAA,mDAAmD;;;AAEnD,mDAA+C;AAC/C,0CAAkC;AAClC,kDAAiD;AACjD,+BAA8B;AAC9B,gCAA+B;AAC/B,mCAAgC;AAChC,yBAAwB;AACxB,6BAA4B;AAC5B,qCAAoC;AAEpC,6CAAwD;AACxD,6CAA4C;AAC5C,yEAA0D;AAC1D,6CAAuC;AACvC,2CAAoD;AAe7C,MAAM,yBAAyB,GAAG,KAAK,EAC5C,SAAiB,EACjB,KAAgC,EACgB,EAAE;IAClD,IAAI,IAA8B,CAAA;IAClC,IAAI;QACF,KAAK,CAAC,uBAAuB,CAAC,CAAC,SAAS,CAAC,CAAA;QACzC,MAAM,WAAW,GAAG;QAChB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,CACnC,CAAC,CAAC,EAAE,EAAE,EAAC,IAAI,EAAC,CAAC,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,IAAI,EAAE,CACpC;;UAEG,KAAK,CAAC,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,CACvD,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CACtB;;;;MAIC,CAAA;QACF,KAAK,CAAC,uBAAuB,CAAC,CAAC,WAAW,CAAC,CAAA;QAC3C,KAAK,CAAC,uBAAuB,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;QAE/C,MAAM,OAAO,GAAG,IAAI,CAA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sT, Workspace } from '../shared/types';
|
|
3
|
+
import type { IntrospectionServiceResponse } from './helpers';
|
|
4
|
+
export declare type OnConflictType = 'overwrite' | 'append';
|
|
5
|
+
export declare type CommonImportOptions = {
|
|
6
|
+
name?: string;
|
|
7
|
+
source: string;
|
|
8
|
+
onConflict: OnConflictType;
|
|
9
|
+
};
|
|
10
|
+
export declare abstract class ImportCommandBase extends ZenCommand {
|
|
11
|
+
protected abstract get source(): string;
|
|
12
|
+
protected abstract import(commonOptions: CommonImportOptions): Promise<ErrorOr<IntrospectionServiceResponse>>;
|
|
13
|
+
static flags: {
|
|
14
|
+
dir: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
15
|
+
silent: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
16
|
+
name: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
17
|
+
overwrite: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
18
|
+
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
19
|
+
'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
20
|
+
};
|
|
21
|
+
run(): Promise<undefined>;
|
|
22
|
+
protected ensureOnConflictBehavior(workspace: Workspace, flags: FlagsT<typeof ImportCommandBase>): Promise<OnConflictType>;
|
|
23
|
+
protected wrapInProgressAndTimeout<T>(importPromise: Promise<ErrorOr<T>>): Promise<ErrorOr<T>>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=import-command.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-command.d.ts","sourceRoot":"","sources":["../../src/generate/import-command.ts"],"names":[],"mappings":"AAYA,OAAO,UAAU,MAAM,uBAAuB,CAAA;AAG9C,OAAO,KAAK,EAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAC,MAAM,iBAAiB,CAAA;AAC/D,OAAO,KAAK,EAAC,4BAA4B,EAAC,MAAM,WAAW,CAAA;AAE3D,oBAAY,cAAc,GAAG,WAAW,GAAG,QAAQ,CAAA;AAEnD,oBAAY,mBAAmB,GAAG;IAChC,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,UAAU,EAAE,cAAc,CAAA;CAC3B,CAAA;AAED,8BAAsB,iBAAkB,SAAQ,UAAU;IACxD,SAAS,CAAC,QAAQ,KAAK,MAAM,IAAI,MAAM,CAAA;IAEvC,SAAS,CAAC,QAAQ,CAAC,MAAM,CACvB,aAAa,EAAE,mBAAmB,GACjC,OAAO,CAAC,OAAO,CAAC,4BAA4B,CAAC,CAAC;IAEjD,MAAM,CAAC,KAAK;;;;;;;MAuBX;IAEK,GAAG;cA8DO,wBAAwB,CACtC,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,MAAM,CAAC,OAAO,iBAAiB,CAAC,GACtC,OAAO,CAAC,cAAc,CAAC;cAiEV,wBAAwB,CAAC,CAAC,EACxC,aAAa,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GACjC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;CAiDvB"}
|