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.
Files changed (119) hide show
  1. package/README.md +417 -54
  2. package/lib/commands/import/curl.d.ts +48 -0
  3. package/lib/commands/import/curl.d.ts.map +1 -0
  4. package/lib/commands/import/curl.js +246 -0
  5. package/lib/commands/import/curl.js.map +1 -0
  6. package/lib/commands/import/graphql.d.ts +34 -0
  7. package/lib/commands/import/graphql.d.ts.map +1 -0
  8. package/lib/commands/import/graphql.js +118 -0
  9. package/lib/commands/import/graphql.js.map +1 -0
  10. package/lib/commands/import/index.d.ts +22 -0
  11. package/lib/commands/import/index.d.ts.map +1 -0
  12. package/lib/commands/import/index.js +165 -0
  13. package/lib/commands/import/index.js.map +1 -0
  14. package/lib/commands/import/mysql.d.ts +48 -0
  15. package/lib/commands/import/mysql.d.ts.map +1 -0
  16. package/lib/commands/import/mysql.js +145 -0
  17. package/lib/commands/import/mysql.js.map +1 -0
  18. package/lib/commands/import/postgresql.d.ts +51 -0
  19. package/lib/commands/import/postgresql.d.ts.map +1 -0
  20. package/lib/commands/import/postgresql.js +150 -0
  21. package/lib/commands/import/postgresql.js.map +1 -0
  22. package/lib/commands/import/presto.d.ts +49 -0
  23. package/lib/commands/import/presto.d.ts.map +1 -0
  24. package/lib/commands/import/presto.js +152 -0
  25. package/lib/commands/import/presto.js.map +1 -0
  26. package/lib/commands/import/snowflake.d.ts +53 -0
  27. package/lib/commands/import/snowflake.d.ts.map +1 -0
  28. package/lib/commands/import/snowflake.js +181 -0
  29. package/lib/commands/import/snowflake.js.map +1 -0
  30. package/lib/commands/list.d.ts.map +1 -1
  31. package/lib/commands/list.js +0 -2
  32. package/lib/commands/list.js.map +1 -1
  33. package/lib/commands/request.js +6 -6
  34. package/lib/commands/request.js.map +1 -1
  35. package/lib/commands/service.d.ts +1 -1
  36. package/lib/commands/service.d.ts.map +1 -1
  37. package/lib/commands/service.js +12 -12
  38. package/lib/commands/service.js.map +1 -1
  39. package/lib/generate/curl2sdl.d.ts +13 -25
  40. package/lib/generate/curl2sdl.d.ts.map +1 -1
  41. package/lib/generate/curl2sdl.js +52 -114
  42. package/lib/generate/curl2sdl.js.map +1 -1
  43. package/lib/generate/flags.d.ts +19 -0
  44. package/lib/generate/flags.d.ts.map +1 -0
  45. package/lib/generate/flags.js +74 -0
  46. package/lib/generate/flags.js.map +1 -0
  47. package/lib/generate/graphql2sdl.d.ts +5 -16
  48. package/lib/generate/graphql2sdl.d.ts.map +1 -1
  49. package/lib/generate/graphql2sdl.js +4 -49
  50. package/lib/generate/graphql2sdl.js.map +1 -1
  51. package/lib/generate/helpers.d.ts +5 -9
  52. package/lib/generate/helpers.d.ts.map +1 -1
  53. package/lib/generate/helpers.js +30 -37
  54. package/lib/generate/helpers.js.map +1 -1
  55. package/lib/generate/import-command.d.ts +25 -0
  56. package/lib/generate/import-command.d.ts.map +1 -0
  57. package/lib/generate/import-command.js +176 -0
  58. package/lib/generate/import-command.js.map +1 -0
  59. package/lib/generate/questions.d.ts +30 -0
  60. package/lib/generate/questions.d.ts.map +1 -0
  61. package/lib/generate/questions.js +50 -0
  62. package/lib/generate/questions.js.map +1 -0
  63. package/lib/generate/sql2sdl.d.ts +14 -18
  64. package/lib/generate/sql2sdl.d.ts.map +1 -1
  65. package/lib/generate/sql2sdl.js +29 -92
  66. package/lib/generate/sql2sdl.js.map +1 -1
  67. package/lib/hooks/prerun/check-upgrade.js +4 -4
  68. package/lib/hooks/prerun/check-upgrade.js.map +1 -1
  69. package/lib/shared/constants.d.ts +1 -0
  70. package/lib/shared/constants.d.ts.map +1 -1
  71. package/lib/shared/constants.js +2 -1
  72. package/lib/shared/constants.js.map +1 -1
  73. package/lib/shared/curl-parser.d.ts +3 -3
  74. package/lib/shared/curl-parser.d.ts.map +1 -1
  75. package/lib/shared/curl-parser.js +52 -39
  76. package/lib/shared/curl-parser.js.map +1 -1
  77. package/lib/shared/docker.d.ts +8 -36
  78. package/lib/shared/docker.d.ts.map +1 -1
  79. package/lib/shared/docker.js +44 -42
  80. package/lib/shared/docker.js.map +1 -1
  81. package/lib/shared/dsn-parser.d.ts +3 -0
  82. package/lib/shared/dsn-parser.d.ts.map +1 -0
  83. package/lib/shared/dsn-parser.js +28 -0
  84. package/lib/shared/dsn-parser.js.map +1 -0
  85. package/lib/shared/header-params-parser.d.ts +7 -5
  86. package/lib/shared/header-params-parser.d.ts.map +1 -1
  87. package/lib/shared/header-params-parser.js +55 -43
  88. package/lib/shared/header-params-parser.js.map +1 -1
  89. package/lib/shared/header.d.ts +2 -2
  90. package/lib/shared/header.d.ts.map +1 -1
  91. package/lib/shared/header.js +13 -7
  92. package/lib/shared/header.js.map +1 -1
  93. package/lib/shared/inquirer.d.ts +2 -0
  94. package/lib/shared/inquirer.d.ts.map +1 -1
  95. package/lib/shared/inquirer.js +12 -4
  96. package/lib/shared/inquirer.js.map +1 -1
  97. package/lib/shared/path-params-parser.d.ts +2 -2
  98. package/lib/shared/path-params-parser.d.ts.map +1 -1
  99. package/lib/shared/path-params-parser.js +11 -7
  100. package/lib/shared/path-params-parser.js.map +1 -1
  101. package/lib/shared/request-variables-parser.d.ts +2 -9
  102. package/lib/shared/request-variables-parser.d.ts.map +1 -1
  103. package/lib/shared/request-variables-parser.js +8 -8
  104. package/lib/shared/request-variables-parser.js.map +1 -1
  105. package/lib/shared/types.d.ts +33 -6
  106. package/lib/shared/types.d.ts.map +1 -1
  107. package/lib/shared/utils.d.ts +5 -13
  108. package/lib/shared/utils.d.ts.map +1 -1
  109. package/lib/shared/utils.js.map +1 -1
  110. package/oclif.manifest.json +684 -197
  111. package/package.json +6 -6
  112. package/lib/commands/import.d.ts +0 -85
  113. package/lib/commands/import.d.ts.map +0 -1
  114. package/lib/commands/import.js +0 -645
  115. package/lib/commands/import.js.map +0 -1
  116. package/lib/generate/index.d.ts +0 -6
  117. package/lib/generate/index.d.ts.map +0 -1
  118. package/lib/generate/index.js +0 -4
  119. package/lib/generate/index.js.map +0 -1
@@ -0,0 +1,246 @@
1
+ "use strict";
2
+ // Copyright (c) 2020,2021,2022,2023, StepZen, Inc.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const core_1 = require("@oclif/core");
5
+ const errors_1 = require("@oclif/core/lib/errors");
6
+ const errors_2 = require("@oclif/core/lib/parser/errors");
7
+ const chalk = require("chalk");
8
+ const string_argv_1 = require("string-argv");
9
+ const curl2sdl_1 = require("../../generate/curl2sdl");
10
+ const flags_1 = require("../../generate/flags");
11
+ const helpers_1 = require("../../generate/helpers");
12
+ const configuration_1 = require("../../shared/configuration");
13
+ const constants_1 = require("../../shared/constants");
14
+ const curl_parser_1 = require("../../shared/curl-parser");
15
+ const inquirer = require("../../shared/inquirer");
16
+ const path_params_parser_1 = require("../../shared/path-params-parser");
17
+ const utils_1 = require("../../shared/utils");
18
+ const import_command_1 = require("../../generate/import-command");
19
+ const questions_1 = require("../../generate/questions");
20
+ class ImportCurl extends import_command_1.ImportCommandBase {
21
+ get source() {
22
+ return 'curl';
23
+ }
24
+ async import(commonOptions) {
25
+ const { flags, argv } = await this.parse(ImportCurl);
26
+ const nonInteractiveOptions = {
27
+ queryName: flags['query-name'],
28
+ rootType: flags['query-type'],
29
+ typePrefix: flags.prefix,
30
+ pathParams: flags['path-params'],
31
+ headers: (0, helpers_1.parseHeaderFlags)(flags.header, flags['header-param']),
32
+ };
33
+ let curl2sdlOptions;
34
+ if (argv.length > 0) {
35
+ // Non-empty argv means that the user has passed in a curl command
36
+ // => running non-interactively
37
+ const { result: curlArgs, error: curlError } = (0, curl_parser_1.parseCurlArgv)(argv);
38
+ if (curlError) {
39
+ throw new errors_1.CLIError(curlError.message);
40
+ }
41
+ const { result: pathParams, error: pathParamsError } = (0, path_params_parser_1.parsePathParamsPattern)(curlArgs.url, flags['path-params']);
42
+ if (pathParamsError) {
43
+ throw new errors_1.CLIError(pathParamsError.message);
44
+ }
45
+ const maybeDuplicateParamsMessage = (0, curl2sdl_1.makeDuplicateParamsMessage)(nonInteractiveOptions.headers, pathParams, curlArgs.url);
46
+ if (maybeDuplicateParamsMessage) {
47
+ throw new errors_1.CLIError(maybeDuplicateParamsMessage);
48
+ }
49
+ curl2sdlOptions = {
50
+ ...commonOptions,
51
+ ...nonInteractiveOptions,
52
+ pathParams,
53
+ curlArgs,
54
+ };
55
+ }
56
+ else {
57
+ if (flags['non-interactive']) {
58
+ throw new errors_1.CLIError('Please provide a REST endpoint URL or a full curl command.' +
59
+ chalk `\nSee more help with {bold stepzen import curl --help}`);
60
+ }
61
+ // no parameters given: start an interactive prompt
62
+ if (!flags.silent) {
63
+ this.log();
64
+ this.log(chalk `{bold stepzen import curl} - ` +
65
+ chalk.dim('introspect a REST API endpoint and extend your GraphQL schema' +
66
+ ' with the types and a query field for accessing it through' +
67
+ chalk ` your StepZen API. The {bold {underline curl}} command` +
68
+ ' syntax is supported so that you can copy and paste a full' +
69
+ ' curl command instead of the URL.'));
70
+ this.log();
71
+ }
72
+ const interactiveOptions = await this.getImportOptionsInteractively(nonInteractiveOptions);
73
+ curl2sdlOptions = {
74
+ ...commonOptions,
75
+ ...interactiveOptions,
76
+ // include boths headers passed via flags and headers entered interactively
77
+ headers: [
78
+ ...nonInteractiveOptions.headers,
79
+ ...interactiveOptions.curlArgs.headers,
80
+ ],
81
+ };
82
+ }
83
+ const configuration = await (0, configuration_1.readConfiguration)();
84
+ curl2sdlOptions.curlArgs.url = (0, utils_1.rewriteLocalhostToHostGatewayInURL)(configuration, curl2sdlOptions.curlArgs.url);
85
+ const { result, error } = await this.wrapInProgressAndTimeout((0, curl2sdl_1.curl2sdl)(curl2sdlOptions, configuration));
86
+ if (error) {
87
+ return {
88
+ error: {
89
+ message: 'Please check that the given curl command is valid.\n' +
90
+ error.message,
91
+ },
92
+ };
93
+ }
94
+ return { result };
95
+ }
96
+ // special parsing to support curl flags and options
97
+ async parse(options, argv = this.argv) {
98
+ try {
99
+ const parsed = await super.parse(options, argv);
100
+ // "unparse" the curl flags and args into the argv array
101
+ // (to be parsed again by the curl-parser code later)
102
+ //
103
+ // The main reason for this non-optimal approach:
104
+ // - In StepZen CLI, a curl command parser with support for
105
+ // curl-specific validation and error messages has been historically
106
+ // implemented without using the oclif parser. (This was done
107
+ // because the curl syntax conventions for command line flags and
108
+ // options slightly differ from those in oclif.)
109
+ // - The custom curl parser is used in 2 places: to initially parse
110
+ // the command line when running the Import command, and also to
111
+ // parse the user answer to the "URL or a whole curl command"
112
+ // question in the `askCurlQuestions()` function.
113
+ // - The workarounds added to the oclif's `parse()` method in the
114
+ // ZenCommand base class make it feasible to use the customised
115
+ // oclif parser also for the curl command line. However, considering
116
+ // the two options:
117
+ // 1. "unparse" the oclif parser output and keep using a custom
118
+ // curl parser as before
119
+ // 2. remove the custom curl parser and use the oclif parser in
120
+ // both places
121
+ // the first option seems to provide more specific error messages,
122
+ // and it is not drastically more complex than the second one
123
+ // (calling the oclif parser directly outisde of the `parse()`
124
+ // method is non-trivial).
125
+ parsed.argv.push(...(parsed.flags.data
126
+ ? parsed.flags.data.flatMap((data) => ['-d', data])
127
+ : []), ...(parsed.flags.request ? ['-X', parsed.flags.request] : []), ...(parsed.flags.url ? [parsed.flags.url] : []));
128
+ return parsed;
129
+ }
130
+ catch (error) {
131
+ if (!(error instanceof errors_2.CLIParseError)) {
132
+ throw error;
133
+ }
134
+ const unsupportedFlags = error.parse.output?.nonExistentFlags;
135
+ if (!unsupportedFlags || unsupportedFlags.length === 0) {
136
+ throw error;
137
+ }
138
+ // show a curl-specific error message for unsupported flags
139
+ throw new errors_1.CLIError(`Unsupported curl flag${unsupportedFlags.length > 1 ? 's' : ''}: ${unsupportedFlags.join(', ')}.` +
140
+ ` If this is a blocker for you, please let us know on Discord` +
141
+ ` (${constants_1.STEPZEN_DISCORD_URL})`);
142
+ }
143
+ }
144
+ async getImportOptionsInteractively(defaults = {}) {
145
+ const questions = inquirer.overrideDefaults([
146
+ {
147
+ name: 'url',
148
+ message: 'Endpoint URL or a full curl command',
149
+ },
150
+ {
151
+ name: 'pathParams',
152
+ message: 'Parameters for endpoint URL path',
153
+ },
154
+ {
155
+ name: 'queryName',
156
+ message: 'Query name to use when generating schema (leave blank to use defaults)',
157
+ },
158
+ {
159
+ name: 'rootType',
160
+ message: 'Query type name to use when generating schema (leave blank to use defaults)',
161
+ },
162
+ questions_1.ImportQuestions.prefix(),
163
+ ], defaults);
164
+ const answers = await inquirer.prompt('import-curl', questions);
165
+ const { result: curlArgs, error: curlError } = (0, curl_parser_1.parseCurlArgv)((0, string_argv_1.default)(answers.url));
166
+ if (curlError) {
167
+ this.log();
168
+ this.log(chalk.red('A problem occurred while parsing the curl command:\n', curlError.message), '\nPlease enter a URL or a supported curl command.');
169
+ this.log();
170
+ return this.getImportOptionsInteractively(answers);
171
+ }
172
+ const { result: pathParams, error: pathParamsError } = (0, path_params_parser_1.parsePathParamsPattern)(curlArgs.url, answers.pathParams);
173
+ if (pathParamsError) {
174
+ this.log();
175
+ this.log(chalk.red('A problem occurred while parsing path parameters pattern:\n', pathParamsError.message));
176
+ this.log();
177
+ this.log(`Please enter a path parameter specification that` +
178
+ ` can be formed by taking the original path and replacing the variable` +
179
+ ` segments with ${chalk.bold('$paramName')} placeholders.`);
180
+ this.log();
181
+ this.log('Example:\n' +
182
+ `\tendpoint URL: https://example.com/users/jane/posts/12\n ` +
183
+ `\tpath parameters: /users/${chalk.bold('$userId')}/posts/${chalk.bold('$postId')}`);
184
+ this.log();
185
+ return this.getImportOptionsInteractively(answers);
186
+ }
187
+ return {
188
+ curlArgs,
189
+ queryName: answers.queryName,
190
+ rootType: answers.rootType,
191
+ typePrefix: answers.typePrefix.trim() === ''
192
+ ? undefined
193
+ : answers.typePrefix.trim(),
194
+ pathParams,
195
+ };
196
+ }
197
+ }
198
+ exports.default = ImportCurl;
199
+ ImportCurl.description = `Import a schema for a REST endpoint into your GraphQL API (uses the curl` +
200
+ ` syntax).` +
201
+ `\n` +
202
+ chalk `\n{bold stepzen import curl} automatically introspects a REST` +
203
+ ` endpoint, generates a GraphQL schema for accessing this endpoint` +
204
+ ` through a StepZen API, and adds the generated types and a query` +
205
+ ` field into your GraphQL schema.`;
206
+ ImportCurl.flags = {
207
+ ...import_command_1.ImportCommandBase.flags,
208
+ prefix: flags_1.ImportFlags.prefix(),
209
+ data: core_1.Flags.string({
210
+ char: 'd',
211
+ hidden: true,
212
+ aliases: ['data-ascii', 'data-raw', 'data-binary'],
213
+ multiple: true,
214
+ }),
215
+ request: core_1.Flags.string({
216
+ char: 'X',
217
+ hidden: true,
218
+ }),
219
+ url: core_1.Flags.string({
220
+ hidden: true,
221
+ multiple: true,
222
+ }),
223
+ header: flags_1.ImportFlags.header(),
224
+ 'header-param': flags_1.ImportFlags.headerParam(),
225
+ 'query-name': core_1.Flags.string({
226
+ description: 'Property name to add to the Query type as a way to' +
227
+ ' access the imported endpoint',
228
+ }),
229
+ 'query-type': core_1.Flags.string({
230
+ description: 'Name for the type returned by the curl request in the ' +
231
+ `generated schema. The name specified by ${chalk.bold('--query-type')} is not prefixed by ${chalk.bold('--prefix')} if both flags are present.`,
232
+ }),
233
+ 'path-params': core_1.Flags.string({
234
+ description: `Specifies path parameters in the URL path.` +
235
+ ` Can be formed by taking the original path and replacing the` +
236
+ ` variable segments with ${chalk.bold('$paramName')} placeholders.` +
237
+ `\n` +
238
+ `\nExample:` +
239
+ `\nstepzen import curl https://example.com/users/jane/posts/12` +
240
+ ` --path-params` +
241
+ ` '/users/${chalk.bold('$userId')}/posts/${chalk.bold('$postId')}'`,
242
+ }),
243
+ };
244
+ // allow any number of arguments to support `import curl [url] [curl flags and options]`
245
+ ImportCurl.strict = false;
246
+ //# sourceMappingURL=curl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"curl.js","sourceRoot":"","sources":["../../../src/commands/import/curl.ts"],"names":[],"mappings":";AAAA,mDAAmD;;AAEnD,sCAAiC;AACjC,mDAA+C;AAC/C,0DAA2D;AAC3D,+BAA8B;AAC9B,6CA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MAAM,CAAC;QAC1B,WAAW,EACT,4CAA4C;YAC5C,8DAA8D;YAC9D,2BAA2B,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC,gBAAgB;YACnE,IAAI;YACJ,YAAY;YACZ,+DAA+D;YAC/D,gBAAgB;YAChB,YAAY,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG;KACtE,CAAC;CACH,CAAA;AAED,wFAAwF;AACjF,iBAAM,GAAG,KAAK,CAAA"}
@@ -0,0 +1,34 @@
1
+ import { ImportCommandBase } from '../../generate/import-command';
2
+ import type { GraphQL2SdlOptions } from '../../generate/graphql2sdl';
3
+ import type { CommonImportOptions } from '../../generate/import-command';
4
+ declare type InteractiveGraphQL2SdlOptions = Pick<GraphQL2SdlOptions, 'endpoint' | 'typePrefix' | 'includeRootOperations' | 'headers'>;
5
+ declare type GraphQLAnswers = {
6
+ endpoint: string;
7
+ typePrefix: string;
8
+ includeRootOperations: boolean;
9
+ header: string;
10
+ };
11
+ export default class ImportGraphQL extends ImportCommandBase {
12
+ static description: string;
13
+ get source(): "graphql";
14
+ static flags: {
15
+ prefix: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
16
+ header: import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
17
+ 'header-param': import("@oclif/core/lib/interfaces").OptionFlag<string[] | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
18
+ dir: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
19
+ silent: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
20
+ name: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
21
+ overwrite: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
22
+ help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
23
+ 'non-interactive': import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
24
+ };
25
+ static args: {
26
+ url: import("@oclif/core/lib/interfaces/parser").Arg<string | undefined, Record<string, unknown>>;
27
+ };
28
+ protected import(commonOptions: CommonImportOptions): Promise<import("../../shared/types").ErrorOr<import("../../generate/helpers").IntrospectionServiceResponse, {
29
+ message: string;
30
+ }>>;
31
+ getImportOptionsInteractively(defaults?: Partial<GraphQLAnswers>): Promise<InteractiveGraphQL2SdlOptions>;
32
+ }
33
+ export {};
34
+ //# sourceMappingURL=graphql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../../../src/commands/import/graphql.ts"],"names":[],"mappings":"AAMA,OAAO,EAAC,iBAAiB,EAAC,MAAM,+BAA+B,CAAA;AAO/D,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,4BAA4B,CAAA;AAClE,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,+BAA+B,CAAA;AAKtE,aAAK,6BAA6B,GAAG,IAAI,CACvC,kBAAkB,EAClB,UAAU,GAAG,YAAY,GAAG,uBAAuB,GAAG,SAAS,CAChE,CAAA;AAED,aAAK,cAAc,GAAG;IACpB,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,qBAAqB,EAAE,OAAO,CAAA;IAC9B,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,iBAAiB;IAC1D,MAAM,CAAC,WAAW,SAMN;IAEZ,IAAI,MAAM,cAET;IAED,MAAM,CAAC,KAAK;;;;;;;;;;MAKX;IAED,MAAM,CAAC,IAAI;;MAIV;cAEe,MAAM,CAAC,aAAa,EAAE,mBAAmB;;;IAqEnD,6BAA6B,CACjC,QAAQ,GAAE,OAAO,CAAC,cAAc,CAAM,GACrC,OAAO,CAAC,6BAA6B,CAAC;CAyC1C"}
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // Copyright (c) 2020,2021,2022,2023, StepZen, Inc.
4
+ const core_1 = require("@oclif/core");
5
+ const chalk = require("chalk");
6
+ const graphql2sdl_1 = require("../../generate/graphql2sdl");
7
+ const helpers_1 = require("../../generate/helpers");
8
+ const import_command_1 = require("../../generate/import-command");
9
+ const questions_1 = require("../../generate/questions");
10
+ const configuration_1 = require("../../shared/configuration");
11
+ const inquirer = require("../../shared/inquirer");
12
+ const utils_1 = require("../../shared/utils");
13
+ const flags_1 = require("../../generate/flags");
14
+ const header_1 = require("../../shared/header");
15
+ const errors_1 = require("@oclif/core/lib/errors");
16
+ class ImportGraphQL extends import_command_1.ImportCommandBase {
17
+ get source() {
18
+ return 'graphql';
19
+ }
20
+ async import(commonOptions) {
21
+ const { args, flags } = await this.parse(ImportGraphQL);
22
+ const nonInteractiveOptions = {
23
+ typePrefix: flags.prefix,
24
+ endpoint: args.url,
25
+ headers: (0, helpers_1.parseHeaderFlags)(flags.header, flags['header-param']),
26
+ };
27
+ let graphql2sdlOptions;
28
+ if (nonInteractiveOptions.endpoint) {
29
+ // an ugly hint for the TS compiler because it is not smart enough to figure this :(
30
+ const typedNonInteractiveOptions = nonInteractiveOptions;
31
+ // run non-interactively
32
+ graphql2sdlOptions = {
33
+ ...commonOptions,
34
+ ...typedNonInteractiveOptions,
35
+ };
36
+ }
37
+ else {
38
+ if (flags['non-interactive']) {
39
+ throw new errors_1.CLIError('Please provide a GraphQL endpoint URL.' +
40
+ chalk `\nSee more help with {bold stepzen import graphql --help}`);
41
+ }
42
+ // no parameters given: start an interactive prompt
43
+ if (!flags.silent) {
44
+ this.log();
45
+ this.log(chalk `{bold stepzen import graphql} - ` +
46
+ chalk.dim('introspect a GraphQL API endpoint and extend your GraphQL schema' +
47
+ ' with the types, queries and mutations for accessing it through' +
48
+ ' a StepZen API.'));
49
+ this.log();
50
+ }
51
+ // no parameters given: start an interactive prompt
52
+ const interactiveOptions = await this.getImportOptionsInteractively(nonInteractiveOptions);
53
+ graphql2sdlOptions = {
54
+ ...commonOptions,
55
+ ...interactiveOptions,
56
+ // include boths headers passed via flags and headers entered interactively
57
+ headers: [
58
+ ...nonInteractiveOptions.headers,
59
+ ...interactiveOptions.headers,
60
+ ],
61
+ };
62
+ }
63
+ const configuration = await (0, configuration_1.readConfiguration)();
64
+ graphql2sdlOptions.endpoint = (0, utils_1.rewriteLocalhostToHostGatewayInURL)(configuration, graphql2sdlOptions.endpoint);
65
+ return this.wrapInProgressAndTimeout((0, graphql2sdl_1.graphql2sdl)(graphql2sdlOptions, configuration));
66
+ }
67
+ async getImportOptionsInteractively(defaults = {}) {
68
+ const questions = inquirer.overrideDefaults([
69
+ {
70
+ name: 'endpoint',
71
+ message: 'What is the GraphQL endpoint URL?',
72
+ validate: input => input.trim() !== '',
73
+ },
74
+ questions_1.ImportQuestions.prefix(),
75
+ {
76
+ name: 'includeRootOperations',
77
+ type: 'confirm',
78
+ message: 'Should type prefix be added to query and mutation fields as well?',
79
+ when: answers => Boolean(answers.typePrefix),
80
+ },
81
+ {
82
+ name: 'header',
83
+ type: 'input',
84
+ message: 'Add an HTTP header, e.g. Header-Name: header value (leave blank for none)',
85
+ validate: input => input === '' || header_1.HEADER_REGEX.test(input.trim()) || 'invalid header',
86
+ },
87
+ ], defaults);
88
+ const answers = await inquirer.prompt('import-graphql', questions);
89
+ const { result: header } = (0, header_1.parseHeader)(answers.header);
90
+ return {
91
+ endpoint: answers.endpoint,
92
+ typePrefix: answers.typePrefix.trim() === ''
93
+ ? undefined
94
+ : answers.typePrefix.trim(),
95
+ includeRootOperations: answers.includeRootOperations,
96
+ headers: header ? [header] : [],
97
+ };
98
+ }
99
+ }
100
+ exports.default = ImportGraphQL;
101
+ ImportGraphQL.description = `Import a GraphQL API as a subgraph into your GraphQL API.` +
102
+ `\n` +
103
+ chalk `\n{bold stepzen import graphql} automatically introspects a GraphQL` +
104
+ ` endpoint and merges the types, queries, mutations and subscriptions` +
105
+ ` for accessing this endpoint through a StepZen API into your GraphQL` +
106
+ ` schema.`;
107
+ ImportGraphQL.flags = {
108
+ ...import_command_1.ImportCommandBase.flags,
109
+ prefix: flags_1.ImportFlags.prefix(),
110
+ header: flags_1.ImportFlags.header(),
111
+ 'header-param': flags_1.ImportFlags.headerParam(),
112
+ };
113
+ ImportGraphQL.args = {
114
+ url: core_1.Args.string({
115
+ name: 'GraphQL endpoint URL',
116
+ }),
117
+ };
118
+ //# sourceMappingURL=graphql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graphql.js","sourceRoot":"","sources":["../../../src/commands/import/graphql.ts"],"names":[],"mappings":";;AAAA,mDAAmD;AACnD,sCAAgC;AAChC,+BAA8B;AAE9B,4DAAsD;AACtD,oDAAuD;AACvD,kEAA+D;AAC/D,wDAAwD;AACxD,8DAA4D;AAC5D,kDAAiD;AACjD,8CAAqE;AAErE,gDAAgD;AAGhD,gDAA6D;AAE7D,mDAA+C;AAc/C,MAAqB,aAAc,SAAQ,kCAAiB;IAS1D,IAAI,MAAM;QACR,OAAO,SAAkB,CAAA;IAC3B,CAAC;IAeS,KAAK,CAAC,MAAM,CAAC,aAAkC;QACvD,MAAM,EAAC,IAAI,EAAE,KAAK,EAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;QAErD,MAAM,qBAAqB,GAAG;YAC5B,UAAU,EAAE,KAAK,CAAC,MAAM;YACxB,QAAQ,EAAE,IAAI,CAAC,GAAG;YAClB,OAAO,EAAE,IAAA,0BAAgB,EAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,cAAc,CAAC,CAAC;SAC/D,CAAA;QAED,IAAI,kBAAsC,CAAA;QAC1C,IAAI,qBAAqB,CAAC,QAAQ,EAAE;YAClC,oFAAoF;YACpF,MAAM,0BAA0B,GAC9B,qBACyD,CAAA;YAE3D,wBAAwB;YACxB,kBAAkB,GAAG;g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IAC5B,MAAM,EAAE,mBAAW,CAAC,MAAM,EAAE;IAC5B,cAAc,EAAE,mBAAW,CAAC,WAAW,EAAE;CAC1C,CAAA;AAEM,kBAAI,GAAG;IACZ,GAAG,EAAE,WAAI,CAAC,MAAM,CAAC;QACf,IAAI,EAAE,sBAAsB;KAC7B,CAAC;CACH,CAAA"}
@@ -0,0 +1,22 @@
1
+ import ZenCommand from '../../shared/zen-command';
2
+ import type { ArgOutput, FlagOutput, Input, ParserOutput } from '@oclif/core/lib/interfaces/parser';
3
+ export default class Import extends ZenCommand {
4
+ static description: string;
5
+ static flags: {
6
+ dir: import("@oclif/core/lib/interfaces/parser").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
7
+ help: import("@oclif/core/lib/interfaces/parser").BooleanFlag<void>;
8
+ 'non-interactive': import("@oclif/core/lib/interfaces/parser").BooleanFlag<boolean>;
9
+ };
10
+ static args: {
11
+ source: import("@oclif/core/lib/interfaces/parser").Arg<string | undefined, Record<string, unknown>>;
12
+ };
13
+ run(): Promise<unknown>;
14
+ protected parse<F extends FlagOutput, B extends FlagOutput, A extends ArgOutput>(options?: Input<F, B, A>, argv?: string[]): Promise<ParserOutput<F, B, A> & {
15
+ argv: string[];
16
+ }>;
17
+ parseSourceArg(arg: string): {
18
+ source: string;
19
+ dsn: string | undefined;
20
+ };
21
+ }
22
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/import/index.ts"],"names":[],"mappings":"AAUA,OAAO,UAAU,MAAM,0BAA0B,CAAA;AASjD,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EACV,KAAK,EACL,YAAY,EACb,MAAM,mCAAmC,CAAA;AAK1C,MAAM,CAAC,OAAO,OAAO,MAAO,SAAQ,UAAU;IAC5C,MAAM,CAAC,WAAW,SAEoD;IAEtE,MAAM,CAAC,KAAK;;;;MAGX;IAED,MAAM,CAAC,IAAI;;MAMV;IAEK,GAAG;cA6GO,KAAK,CACnB,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,UAAU,EACpB,CAAC,SAAS,SAAS,EAEnB,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EACxB,IAAI,GAAE,MAAM,EAAc,GACzB,OAAO,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG;QAAC,IAAI,EAAE,MAAM,EAAE,CAAA;KAAC,CAAC;IAkBpD,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;KAAC;CAiCvE"}
@@ -0,0 +1,165 @@
1
+ "use strict";
2
+ // Copyright (c) 2020,2021,2022,2023, StepZen, Inc.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const core_1 = require("@oclif/core");
5
+ const errors_1 = require("@oclif/core/lib/errors");
6
+ const errors_2 = require("@oclif/core/lib/parser/errors");
7
+ const chalk = require("chalk");
8
+ const constants_1 = require("../../shared/constants");
9
+ const inquirer = require("../../shared/inquirer");
10
+ const utils_1 = require("../../shared/utils");
11
+ const zen_command_1 = require("../../shared/zen-command");
12
+ const curl_1 = require("./curl");
13
+ const graphql_1 = require("./graphql");
14
+ const mysql_1 = require("./mysql");
15
+ const postgresql_1 = require("./postgresql");
16
+ const presto_1 = require("./presto");
17
+ const snowflake_1 = require("./snowflake");
18
+ const SOURCES = ['curl', 'graphql', 'mysql', 'postgresql', 'snowflake'];
19
+ class Import extends zen_command_1.default {
20
+ async run() {
21
+ const { args, flags } = await this.parse(Import);
22
+ let sourceArg;
23
+ const argvMinusSource = [...this.argv];
24
+ if (args.source) {
25
+ sourceArg = args.source;
26
+ argvMinusSource.shift();
27
+ }
28
+ else {
29
+ if (flags['non-interactive']) {
30
+ throw new errors_1.CLIError(chalk `The {bold SOURCE} argument is required when running in a non-interactive mode.` +
31
+ chalk `\nSee more help with {bold stepzen import --help}`);
32
+ }
33
+ this.log();
34
+ this.log(chalk `{bold stepzen import} - ` +
35
+ chalk.dim('introspect an external data source and extend your GraphQL' +
36
+ ' schema with the types, queries and mutations for accessing' +
37
+ ' this data source through your StepZen API.'));
38
+ this.log();
39
+ const answers = await inquirer.prompt('import', [
40
+ {
41
+ name: 'source',
42
+ message: 'What kind of data source do you want to import?',
43
+ type: 'list',
44
+ loop: false,
45
+ pageSize: 10,
46
+ choices: [
47
+ { value: 'curl', name: 'REST' },
48
+ { value: 'graphql', name: 'GraphQL' },
49
+ { type: 'separator' },
50
+ { value: 'mysql', name: 'MySQL' },
51
+ { value: 'postgresql', name: 'PostgreSQL' },
52
+ // the GA version of the introspection service does not support Presto yet
53
+ ...((0, utils_1.getFeatureFlag)(constants_1.ENABLE_PRESTO_IMPORT)
54
+ ? [{ value: 'presto', name: 'Presto' }]
55
+ : []),
56
+ { value: 'singlestore', name: 'SingleStore' },
57
+ { value: 'snowflake', name: 'Snowflake' },
58
+ ],
59
+ },
60
+ ]);
61
+ sourceArg = answers.source;
62
+ }
63
+ // Get the schema you're asking for; may be a DSN
64
+ const { source, dsn } = this.parseSourceArg(sourceArg);
65
+ let ImportCommand;
66
+ switch (source) {
67
+ case 'curl':
68
+ if (dsn) {
69
+ throw new errors_1.CLIError(`Please use ${chalk.bold('stepzen import curl [url]')}`);
70
+ }
71
+ ImportCommand = curl_1.default;
72
+ break;
73
+ case 'graphql':
74
+ if (dsn) {
75
+ throw new errors_1.CLIError(`Please use ${chalk.bold('stepzen import graphql [url]')}`);
76
+ }
77
+ ImportCommand = graphql_1.default;
78
+ break;
79
+ case 'mysql':
80
+ ImportCommand = mysql_1.default;
81
+ break;
82
+ case 'postgresql':
83
+ ImportCommand = postgresql_1.default;
84
+ break;
85
+ case 'snowflake':
86
+ ImportCommand = snowflake_1.default;
87
+ break;
88
+ case 'presto':
89
+ ImportCommand = presto_1.default;
90
+ break;
91
+ default:
92
+ throw new errors_1.CLIError(chalk `Unsupported data source: {bold ${source}}.` +
93
+ chalk `\n\tStepZen CLI does not support introspection and automatic` +
94
+ chalk ` GraphQL schema generation for {bold ${source}} data sources.` +
95
+ chalk ` Please write a schema for it manually.` +
96
+ chalk `\n\tSee {bold stepzen import --help} for a list of supported` +
97
+ chalk ` data sources.`);
98
+ }
99
+ return ImportCommand.run(dsn
100
+ ? [dsn, ...argvMinusSource, '--silent']
101
+ : [...argvMinusSource, '--silent']);
102
+ }
103
+ // Ignore the "unknown flag" errors if the SOURCE arg is provided.
104
+ //
105
+ // Allow the `import [DSN] [extra-flags]` syntax without having to declare
106
+ // flags of each DSN-supporting import command in this command as well.
107
+ //
108
+ // e.g. `import postgresql://user:password@host:port/database --name sales --db-link-types`
109
+ async parse(options, argv = this.argv) {
110
+ try {
111
+ const parsed = await super.parse(options, argv);
112
+ return parsed;
113
+ }
114
+ catch (error) {
115
+ if (error instanceof errors_2.CLIParseError &&
116
+ error.parse.output &&
117
+ error.parse.output.args.source &&
118
+ error.parse.output.nonExistentFlags) {
119
+ return error.parse.output;
120
+ }
121
+ throw error;
122
+ }
123
+ }
124
+ parseSourceArg(arg) {
125
+ const trimmed = arg.trim();
126
+ const hasDsn = trimmed.includes('://');
127
+ let source;
128
+ let dsn;
129
+ if (hasDsn) {
130
+ source = trimmed.split('://')[0];
131
+ dsn = trimmed;
132
+ }
133
+ else {
134
+ // Now supports importing only one schema at a time:
135
+ // https://github.com/steprz/stepzen-cli/issues/628
136
+ if (trimmed.includes(',') || trimmed.includes(' ')) {
137
+ throw new errors_1.CLIError("Cannot import multiple schemas in one command; please specify only one (e.g. 'stepzen import mysql')");
138
+ }
139
+ source = trimmed;
140
+ }
141
+ // support `postgres` as an alias to `postgresql`
142
+ // https://github.com/steprz/stepzen-cli/issues/431
143
+ if (source.toLowerCase() === 'postgres') {
144
+ source = 'postgresql';
145
+ }
146
+ // treat `singlestore` as an alias to `mysql`
147
+ if (source.toLowerCase() === 'singlestore') {
148
+ source = 'mysql';
149
+ }
150
+ return { source, dsn };
151
+ }
152
+ }
153
+ exports.default = Import;
154
+ Import.description = chalk `Import a schema for an external data source or an API endpoint into your GraphQL API.` +
155
+ chalk `\nSee more details with {bold stepzen import [SOURCE] --help}`;
156
+ Import.flags = {
157
+ ...zen_command_1.default.flags,
158
+ dir: core_1.Flags.string({ description: 'Working directory' }),
159
+ };
160
+ Import.args = {
161
+ source: core_1.Args.string({
162
+ description: chalk `kind of the data source: ${SOURCES.map(s => chalk.bold(s)).join(', ')} (or a full DSN string)`,
163
+ }),
164
+ };
165
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/import/index.ts"],"names":[],"mappings":";AAAA,mDAAmD;;AAEnD,sCAAuC;AACvC,mDAA+C;AAC/C,0DAA2D;AAC3D,+BAA8B;AAE9B,sDAA2D;AAC3D,kDAAiD;AACjD,8CAAiD;AACjD,0DAAiD;AAEjD,iCAA+B;AAC/B,uCAAqC;AACrC,mCAAiC;AACjC,6CAA2C;AAC3C,qCAAmC;AACnC,2CAAyC;AAUzC,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,CAAC,CAAA;AAEvE,MAAqB,MAAO,SAAQ,qBAAU;IAkB5C,KAAK,CAAC,GAAG;QACP,MAAM,EAAC,IAAI,EAAE,KAAK,EAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QAE9C,IAAI,SAAS,CAAA;QACb,MAAM,eAAe,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAA;QACtC,IAAI,IAAI,CAAC,MAAM,EAAE;YACf,SAAS,GAAG,IAAI,CAAC,MAAM,CAAA;YACvB,eAAe,CAAC,KAAK,EAAE,CAAA;SACxB;aAAM;YACL,IAAI,KAAK,CAAC,iBAAiB,CAAC,EAAE;gBAC5B,MAAM,IAA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