stepzen 0.19.0-beta.0 → 0.19.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -3
- package/lib/commands/deploy.js +1 -1
- package/lib/commands/import.d.ts +19 -6
- package/lib/commands/import.js +124 -74
- package/lib/commands/init.js +2 -2
- package/lib/commands/lint.js +2 -2
- package/lib/commands/list.js +1 -1
- package/lib/commands/login.js +3 -3
- package/lib/commands/logout.js +1 -1
- package/lib/commands/start.js +14 -12
- package/lib/commands/transpile.js +5 -5
- package/lib/commands/upload.js +1 -1
- package/lib/commands/validate.js +6 -4
- package/lib/commands/whoami.js +3 -3
- package/lib/generate/curl2sdl.d.ts +2 -2
- package/lib/generate/curl2sdl.js +24 -15
- package/lib/generate/graphql2sdl.d.ts +3 -3
- package/lib/generate/graphql2sdl.js +19 -5
- package/lib/generate/helpers.d.ts +7 -1
- package/lib/generate/helpers.js +35 -21
- package/lib/generate/index.js +6 -6
- package/lib/generate/sql2sdl.d.ts +6 -5
- package/lib/generate/sql2sdl.js +37 -10
- package/lib/hooks/prerun/check-upgrade.js +13 -10
- package/lib/hooks/prerun/ensure-config-file.js +3 -3
- package/lib/index.js +1 -0
- package/lib/shared/actions.js +9 -6
- package/lib/shared/configuration.js +20 -14
- package/lib/shared/constants.d.ts +2 -0
- package/lib/shared/constants.js +8 -5
- package/lib/shared/curl-parser.js +3 -2
- package/lib/shared/errors.js +2 -1
- package/lib/shared/header-params-parser.js +6 -4
- package/lib/shared/header.js +2 -1
- package/lib/shared/moniker.js +5 -3
- package/lib/shared/path-params-parser.d.ts +1 -1
- package/lib/shared/path-params-parser.js +5 -3
- package/lib/shared/stepzen-sdk.d.ts +1 -1
- package/lib/shared/stepzen-sdk.js +1 -1
- package/lib/shared/utils.d.ts +2 -0
- package/lib/shared/utils.js +31 -8
- package/lib/shared/validation.js +4 -2
- package/lib/shared/workspace.js +21 -16
- package/lib/shared/zen-command.js +7 -7
- package/lib/start/console.d.ts +1 -1
- package/lib/start/console.js +16 -9
- package/lib/start/index.js +1 -0
- package/oclif.manifest.json +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -20,6 +20,7 @@ To verify your CLI installation, use the `stepzen --version` command:
|
|
|
20
20
|
* [Installing](#installing)
|
|
21
21
|
* [Verifying your installation](#verifying-your-installation)
|
|
22
22
|
* [Usage](#usage)
|
|
23
|
+
* [QA from cloned repo](#qa-from-cloned-repo)
|
|
23
24
|
* [Commands](#commands)
|
|
24
25
|
<!-- tocstop -->
|
|
25
26
|
# Usage
|
|
@@ -29,13 +30,19 @@ $ npm install -g stepzen
|
|
|
29
30
|
$ stepzen COMMAND
|
|
30
31
|
running command...
|
|
31
32
|
$ stepzen (-v|--version|version)
|
|
32
|
-
stepzen/0.19.0-beta.
|
|
33
|
+
stepzen/0.19.0-beta.1 darwin-x64 node-v14.19.3
|
|
33
34
|
$ stepzen --help [COMMAND]
|
|
34
35
|
USAGE
|
|
35
36
|
$ stepzen COMMAND
|
|
36
37
|
...
|
|
37
38
|
```
|
|
38
39
|
<!-- usagestop -->
|
|
40
|
+
|
|
41
|
+
# QA from cloned repo
|
|
42
|
+
<!-- QA -->
|
|
43
|
+
To run from code: `path-to-repo/bin/run start` (start or whatever command you're QAing)
|
|
44
|
+
<!-- QAstop -->
|
|
45
|
+
|
|
39
46
|
# Commands
|
|
40
47
|
<!-- commands -->
|
|
41
48
|
* [`stepzen deploy DESTINATION`](#stepzen-deploy-destination)
|
|
@@ -84,7 +91,7 @@ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v5.1.1
|
|
|
84
91
|
|
|
85
92
|
## `stepzen import SCHEMA`
|
|
86
93
|
|
|
87
|
-
import a schema for an external data source or
|
|
94
|
+
import a schema for an external data source or an API endpoint to your GraphQL API
|
|
88
95
|
|
|
89
96
|
```
|
|
90
97
|
USAGE
|
|
@@ -107,8 +114,11 @@ OPTIONS
|
|
|
107
114
|
--db-host=db-host
|
|
108
115
|
[mysql, postgresql] database host
|
|
109
116
|
|
|
117
|
+
--db-include=(tables-only|views-only|tables-and-views)
|
|
118
|
+
[mysql, postgresql] Should the generated GraphQL schema be based only on database views, only on tables or on both.
|
|
119
|
+
|
|
110
120
|
--db-link-types
|
|
111
|
-
[mysql, postgresql] Automatically link types
|
|
121
|
+
[mysql, postgresql] Automatically link types based on foreign key relationships using @materializer
|
|
112
122
|
(https://stepzen.com/docs/features/linking-types)
|
|
113
123
|
|
|
114
124
|
--db-password=db-password
|
package/lib/commands/deploy.js
CHANGED
|
@@ -27,7 +27,7 @@ class Deploy extends zen_command_1.default {
|
|
|
27
27
|
? `${flags.configurationsets},stepzen/public`
|
|
28
28
|
: 'stepzen/public';
|
|
29
29
|
}
|
|
30
|
-
const response = await actions_1.deploy(args.destination, flags.configurationsets, flags.schema);
|
|
30
|
+
const response = await (0, actions_1.deploy)(args.destination, flags.configurationsets, flags.schema);
|
|
31
31
|
if (response.success) {
|
|
32
32
|
if (!flags.silent) {
|
|
33
33
|
this.log(response.message || 'Success');
|
package/lib/commands/import.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { flags } from '@oclif/command';
|
|
2
|
+
import { Input } from '@oclif/parser';
|
|
2
3
|
import type { CommonImportOptions } from '../generate';
|
|
3
4
|
import ZenCommand from '../shared/zen-command';
|
|
4
5
|
import { HeaderInput } from '../shared/header';
|
|
5
6
|
import { Workspace } from '../shared/types';
|
|
7
|
+
declare type Flags<Command> = Command extends Input<infer F> ? F : never;
|
|
6
8
|
export default class Import extends ZenCommand {
|
|
7
9
|
static description: string;
|
|
8
10
|
static commonIntrospectionFlags: {
|
|
@@ -21,6 +23,7 @@ export default class Import extends ZenCommand {
|
|
|
21
23
|
'db-password': flags.IOptionFlag<string | undefined>;
|
|
22
24
|
'db-database': flags.IOptionFlag<string | undefined>;
|
|
23
25
|
'db-link-types': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
26
|
+
'db-include': flags.IOptionFlag<string>;
|
|
24
27
|
};
|
|
25
28
|
static postgresqlFlags: {
|
|
26
29
|
'db-schema': flags.IOptionFlag<string | undefined>;
|
|
@@ -46,6 +49,7 @@ export default class Import extends ZenCommand {
|
|
|
46
49
|
'db-password': flags.IOptionFlag<string | undefined>;
|
|
47
50
|
'db-database': flags.IOptionFlag<string | undefined>;
|
|
48
51
|
'db-link-types': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
52
|
+
'db-include': flags.IOptionFlag<string>;
|
|
49
53
|
};
|
|
50
54
|
schemas: string[];
|
|
51
55
|
} | {
|
|
@@ -61,6 +65,7 @@ export default class Import extends ZenCommand {
|
|
|
61
65
|
'db-password': flags.IOptionFlag<string | undefined>;
|
|
62
66
|
'db-database': flags.IOptionFlag<string | undefined>;
|
|
63
67
|
'db-link-types': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
68
|
+
'db-include': flags.IOptionFlag<string>;
|
|
64
69
|
'query-name': flags.IOptionFlag<string | undefined>;
|
|
65
70
|
'query-type': flags.IOptionFlag<string | undefined>;
|
|
66
71
|
'path-params': flags.IOptionFlag<string | undefined>;
|
|
@@ -80,10 +85,10 @@ export default class Import extends ZenCommand {
|
|
|
80
85
|
}[];
|
|
81
86
|
static strict: boolean;
|
|
82
87
|
run(): Promise<void>;
|
|
83
|
-
importCurl(argv: string[], flags:
|
|
84
|
-
importGraphQL(argv: string[], flags:
|
|
85
|
-
importSql(schema:
|
|
86
|
-
importFromGeneratorEngines(schema: string,
|
|
88
|
+
importCurl(argv: string[], flags: Flags<typeof Import>, commonOptions: CommonImportOptions): Promise<string>;
|
|
89
|
+
importGraphQL(argv: string[], flags: Flags<typeof Import>, commonOptions: CommonImportOptions): Promise<string>;
|
|
90
|
+
importSql(schema: 'mysql' | 'postgresql', flags: Flags<typeof Import>, fixedOptions: CommonImportOptions): Promise<string>;
|
|
91
|
+
importFromGeneratorEngines(schema: string, flags: any, fixedOptions: CommonImportOptions): Promise<string>;
|
|
87
92
|
ensureOnConflictBehavior(workspace: Workspace, schema: string, flags: ReturnType<Import['parseWorkaround']>['flags']): Promise<"overwrite" | "append">;
|
|
88
93
|
warnAboutIgnoredFlags(schema: string, usedFlags: {
|
|
89
94
|
[key: string]: any;
|
|
@@ -95,6 +100,7 @@ export default class Import extends ZenCommand {
|
|
|
95
100
|
'db-password': string | undefined;
|
|
96
101
|
'db-database': string | undefined;
|
|
97
102
|
'db-link-types': boolean;
|
|
103
|
+
'db-include': string;
|
|
98
104
|
'query-name': string | undefined;
|
|
99
105
|
'query-type': string | undefined;
|
|
100
106
|
'path-params': string | undefined;
|
|
@@ -111,7 +117,14 @@ export default class Import extends ZenCommand {
|
|
|
111
117
|
[name: string]: any;
|
|
112
118
|
}>;
|
|
113
119
|
parseHeaderFlags(headerFlagValues?: string[], headerParamFlagValues?: string[]): HeaderInput[];
|
|
114
|
-
getSqlOptionsFromFlags(flags:
|
|
115
|
-
|
|
120
|
+
getSqlOptionsFromFlags(flags: Flags<typeof Import>): {
|
|
121
|
+
host: string | undefined;
|
|
122
|
+
user: string | undefined;
|
|
123
|
+
password: string | undefined;
|
|
124
|
+
database: string | undefined;
|
|
125
|
+
linkTypes: boolean;
|
|
126
|
+
schema: string | undefined;
|
|
127
|
+
include: "tables-only" | "views-only" | "tables-and-views" | undefined;
|
|
116
128
|
};
|
|
117
129
|
}
|
|
130
|
+
export {};
|
package/lib/commands/import.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const chalk = require("chalk");
|
|
5
5
|
const fs = require("fs-extra");
|
|
6
|
+
const glob = require("glob");
|
|
6
7
|
const path = require("path");
|
|
7
8
|
const inquirer = require("inquirer");
|
|
8
9
|
const command_1 = require("@oclif/command");
|
|
@@ -17,6 +18,7 @@ const curl_parser_1 = require("../shared/curl-parser");
|
|
|
17
18
|
const zen_command_1 = require("../shared/zen-command");
|
|
18
19
|
const graphql2sdl_1 = require("../generate/graphql2sdl");
|
|
19
20
|
const sql2sdl_1 = require("../generate/sql2sdl");
|
|
21
|
+
const validate_1 = require("../commands/validate");
|
|
20
22
|
const constants_1 = require("../shared/constants");
|
|
21
23
|
const path_params_parser_1 = require("../shared/path-params-parser");
|
|
22
24
|
const header_params_parser_1 = require("../shared/header-params-parser");
|
|
@@ -25,51 +27,78 @@ class Import extends zen_command_1.default {
|
|
|
25
27
|
async run() {
|
|
26
28
|
const { args, argv, flags } = this.parseWorkaround();
|
|
27
29
|
// Get a list of schemas you're asking for
|
|
28
|
-
const schema = helpers_1.getSchema(args.schema);
|
|
30
|
+
const schema = (0, helpers_1.getSchema)(args.schema);
|
|
29
31
|
// Get or create a StepZen workspace (possibly interactive)
|
|
30
32
|
const workspace = await this.ensureStepZenWorkspace({ directory: flags.dir });
|
|
33
|
+
if (schema !== 'curl' && schema !== 'graphql') {
|
|
34
|
+
try {
|
|
35
|
+
if (glob.sync('**/*.graphql', { cwd: workspace.schema }).length > 0) {
|
|
36
|
+
// The workspace schema has to be valid for import to work because when
|
|
37
|
+
// importing any other schemas than `curl` and `graphql` the CLI tries
|
|
38
|
+
// to _merge_ the imported schema into the workspace schema, and that's
|
|
39
|
+
// going to fail if the workspace schema is invalid to start with.
|
|
40
|
+
await validate_1.default.run([workspace.schema]);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
throw new errors_1.CLIError(`Could not import a ${schema} schema into the workspace.` +
|
|
45
|
+
` The workspace needs to have a valid GraphQL schema before` +
|
|
46
|
+
` ${chalk.bold(`stepzen import ${schema}`)} could start.` +
|
|
47
|
+
`\n` +
|
|
48
|
+
`\nThe following issues with the GraphQL schema were detected:` +
|
|
49
|
+
`\n${error.message}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
31
52
|
// Define a sane onConflict behaviour (possibly interactive)
|
|
32
53
|
const onConflict = await this.ensureOnConflictBehavior(workspace, schema, flags);
|
|
33
54
|
this.warnAboutIgnoredFlags(schema, flags);
|
|
34
55
|
// Common options for all import schemas
|
|
35
|
-
const
|
|
56
|
+
const commonOptions = {
|
|
36
57
|
name: flags.name,
|
|
37
58
|
source: workspace.schema,
|
|
38
59
|
onConflict,
|
|
39
60
|
};
|
|
40
61
|
// Select an import execution flow:
|
|
41
|
-
// - v1
|
|
42
|
-
// - v2
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
// - v1 (deprecated) through the `generator-engines` cloud function
|
|
63
|
+
// - v2 (default) directly call the DB and REST introspection service APIs
|
|
64
|
+
const useGeneratorEngines = (0, utils_1.getFeatureFlag)(constants_1.USE_GENERATOR_ENGINES);
|
|
65
|
+
let importFn = undefined;
|
|
66
|
+
switch (schema) {
|
|
67
|
+
case 'curl':
|
|
68
|
+
importFn = () => this.importCurl(argv, flags, commonOptions);
|
|
69
|
+
break;
|
|
70
|
+
case 'graphql':
|
|
71
|
+
importFn = () => this.importGraphQL(argv, flags, commonOptions);
|
|
72
|
+
break;
|
|
73
|
+
case 'mysql':
|
|
74
|
+
case 'postgresql':
|
|
75
|
+
importFn = useGeneratorEngines
|
|
76
|
+
? () => this.importFromGeneratorEngines(schema, flags, commonOptions)
|
|
77
|
+
: () => this.importSql(schema, flags, commonOptions);
|
|
78
|
+
break;
|
|
79
|
+
default:
|
|
80
|
+
if (useGeneratorEngines) {
|
|
81
|
+
importFn = () => this.importFromGeneratorEngines(schema, flags, commonOptions);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
throw new errors_1.CLIError(`Cannot find the schema ${schema}`);
|
|
85
|
+
}
|
|
56
86
|
}
|
|
87
|
+
const result = await importFn();
|
|
57
88
|
// Housekeeping
|
|
58
89
|
fs.copySync(result, workspace.schema);
|
|
59
90
|
fs.removeSync(result);
|
|
60
91
|
// Nice message
|
|
61
92
|
this.log(chalk.green(`Successfully imported schema ${chalk.bold(schema)} from StepZen`));
|
|
62
93
|
}
|
|
63
|
-
async importCurl(argv, flags,
|
|
94
|
+
async importCurl(argv, flags, commonOptions) {
|
|
64
95
|
const headers = this.parseHeaderFlags(flags.header, flags['header-param']);
|
|
65
|
-
// LATER: offload the check to the graphqlize service or fetch
|
|
66
|
-
// the list of supported data sources and compare agains it.
|
|
67
96
|
this.log(chalk.yellow(`NOTE: ${chalk.bold('stepzen import curl')} is a ${chalk.bold('new')} feature.`));
|
|
68
97
|
this.log(chalk.yellow('If you have any issues, please check if they have been addressed ' +
|
|
69
98
|
'in the latest version, or reach out to StepZen on Discord: ' +
|
|
70
99
|
constants_1.STEPZEN_DISCORD_URL));
|
|
71
100
|
let curl2sdlOptions;
|
|
72
|
-
const
|
|
101
|
+
const curlFlagValues = {
|
|
73
102
|
queryName: flags['query-name'],
|
|
74
103
|
rootType: flags['query-type'],
|
|
75
104
|
typePrefix: flags.prefix,
|
|
@@ -83,29 +112,29 @@ class Import extends zen_command_1.default {
|
|
|
83
112
|
'StepZen API. curl syntax is supported so that you copy and paste a ' +
|
|
84
113
|
'curl command instead of the URL.');
|
|
85
114
|
console.log();
|
|
86
|
-
const
|
|
87
|
-
curl2sdlOptions = Object.assign(Object.assign(Object.assign({},
|
|
115
|
+
const interactiveOptions = await (0, curl2sdl_1.askCurlQuestions)(curlFlagValues);
|
|
116
|
+
curl2sdlOptions = Object.assign(Object.assign(Object.assign({}, commonOptions), interactiveOptions), {
|
|
88
117
|
// include boths headers passed via flags and headers entered interactively
|
|
89
|
-
headers: headers.concat(
|
|
118
|
+
headers: headers.concat(interactiveOptions.curlArgs.headers) });
|
|
90
119
|
}
|
|
91
120
|
else {
|
|
92
|
-
// run non-
|
|
93
|
-
const argsOrError = curl_parser_1.parseCurlArgv(argv);
|
|
121
|
+
// run non-interactively
|
|
122
|
+
const argsOrError = (0, curl_parser_1.parseCurlArgv)(argv);
|
|
94
123
|
if ('error' in argsOrError) {
|
|
95
124
|
throw new errors_1.CLIError(argsOrError.error);
|
|
96
125
|
}
|
|
97
|
-
const parsedPathParamsOrError = path_params_parser_1.parsePathParamsPattern(argsOrError.url, flags['path-params']);
|
|
126
|
+
const parsedPathParamsOrError = (0, path_params_parser_1.parsePathParamsPattern)(argsOrError.url, flags['path-params']);
|
|
98
127
|
if ('error' in parsedPathParamsOrError) {
|
|
99
128
|
throw new errors_1.CLIError(parsedPathParamsOrError.error);
|
|
100
129
|
}
|
|
101
|
-
const maybeDuplicateParamsMessage = curl2sdl_1.makeDuplicateParamsMessage(headers, parsedPathParamsOrError, argsOrError.url);
|
|
130
|
+
const maybeDuplicateParamsMessage = (0, curl2sdl_1.makeDuplicateParamsMessage)(headers, parsedPathParamsOrError, argsOrError.url);
|
|
102
131
|
if (maybeDuplicateParamsMessage) {
|
|
103
132
|
throw new errors_1.CLIError(maybeDuplicateParamsMessage);
|
|
104
133
|
}
|
|
105
|
-
curl2sdlOptions = Object.assign(Object.assign(Object.assign({},
|
|
134
|
+
curl2sdlOptions = Object.assign(Object.assign(Object.assign({}, commonOptions), curlFlagValues), { pathParams: parsedPathParamsOrError, headers: headers, curlArgs: argsOrError });
|
|
106
135
|
}
|
|
107
136
|
core_1.CliUx.ux.action.start('Starting');
|
|
108
|
-
const resultOrError = await curl2sdl_1.curl2sdl(curl2sdlOptions);
|
|
137
|
+
const resultOrError = await (0, curl2sdl_1.curl2sdl)(curl2sdlOptions);
|
|
109
138
|
core_1.CliUx.ux.action.stop();
|
|
110
139
|
if ('error' in resultOrError) {
|
|
111
140
|
this.log('A problem occured while processing your import. ' +
|
|
@@ -115,24 +144,25 @@ class Import extends zen_command_1.default {
|
|
|
115
144
|
}
|
|
116
145
|
return resultOrError.outPath;
|
|
117
146
|
}
|
|
118
|
-
async importGraphQL(argv, flags,
|
|
147
|
+
async importGraphQL(argv, flags, commonOptions) {
|
|
119
148
|
const headers = this.parseHeaderFlags(flags.header, flags['header-param']);
|
|
120
|
-
|
|
149
|
+
let graphql2sdlOptions;
|
|
150
|
+
const graphqlFlagValues = {
|
|
121
151
|
typePrefix: flags.prefix,
|
|
122
|
-
headers: headers,
|
|
123
152
|
};
|
|
124
|
-
let answers;
|
|
125
153
|
if (argv.length === 1) {
|
|
126
|
-
// interactive
|
|
127
|
-
|
|
154
|
+
// no parameters given: start an interactive prompt
|
|
155
|
+
const interactiveOptions = await (0, graphql2sdl_1.askGraphQLQuestions)(graphqlFlagValues);
|
|
156
|
+
graphql2sdlOptions = Object.assign(Object.assign(Object.assign({}, commonOptions), interactiveOptions), {
|
|
157
|
+
// include boths headers passed via flags and headers entered interactively
|
|
158
|
+
headers: headers.concat(interactiveOptions.headers) });
|
|
128
159
|
}
|
|
129
160
|
else {
|
|
130
|
-
// non-
|
|
131
|
-
|
|
161
|
+
// run non-interactively
|
|
162
|
+
graphql2sdlOptions = Object.assign(Object.assign(Object.assign({}, commonOptions), graphqlFlagValues), { endpoint: argv[1], headers: headers });
|
|
132
163
|
}
|
|
133
|
-
const options = Object.assign(Object.assign({}, fixedOptions), answers);
|
|
134
164
|
core_1.CliUx.ux.action.start('Starting');
|
|
135
|
-
const resultOrError = await graphql2sdl_1.graphql2sdl(
|
|
165
|
+
const resultOrError = await (0, graphql2sdl_1.graphql2sdl)(graphql2sdlOptions);
|
|
136
166
|
core_1.CliUx.ux.action.stop();
|
|
137
167
|
if ('error' in resultOrError) {
|
|
138
168
|
this.log('A problem occured while processing your import.');
|
|
@@ -141,27 +171,23 @@ class Import extends zen_command_1.default {
|
|
|
141
171
|
}
|
|
142
172
|
return resultOrError.outPath;
|
|
143
173
|
}
|
|
144
|
-
async importSql(schema,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
editableOptions.user !== undefined &&
|
|
154
|
-
editableOptions.password !== undefined) {
|
|
155
|
-
// non-interactive
|
|
156
|
-
answers = editableOptions;
|
|
174
|
+
async importSql(schema, flags, fixedOptions) {
|
|
175
|
+
let sql2sdlOptions;
|
|
176
|
+
const sqlFlagValues = this.getSqlOptionsFromFlags(flags);
|
|
177
|
+
if (sqlFlagValues.host !== undefined &&
|
|
178
|
+
sqlFlagValues.database !== undefined &&
|
|
179
|
+
sqlFlagValues.user !== undefined &&
|
|
180
|
+
sqlFlagValues.password !== undefined) {
|
|
181
|
+
// run non-interactively
|
|
182
|
+
sql2sdlOptions = Object.assign(Object.assign(Object.assign({}, fixedOptions), sqlFlagValues), sqlFlagValues);
|
|
157
183
|
}
|
|
158
184
|
else {
|
|
159
|
-
// interactive
|
|
160
|
-
|
|
185
|
+
// one or more required parameters are missing: start an interactive prompt
|
|
186
|
+
const interactiveOptions = await (0, sql2sdl_1.askSqlQuestions)(schema, sqlFlagValues);
|
|
187
|
+
sql2sdlOptions = Object.assign(Object.assign(Object.assign({}, fixedOptions), interactiveOptions), { include: sqlFlagValues.include });
|
|
161
188
|
}
|
|
162
|
-
const options = Object.assign(Object.assign({}, fixedOptions), answers);
|
|
163
189
|
core_1.CliUx.ux.action.start('Starting');
|
|
164
|
-
const resultOrError = await sql2sdl_1.sql2sdl(schema,
|
|
190
|
+
const resultOrError = await (0, sql2sdl_1.sql2sdl)(schema, sql2sdlOptions);
|
|
165
191
|
core_1.CliUx.ux.action.stop();
|
|
166
192
|
if ('error' in resultOrError) {
|
|
167
193
|
this.log('A problem occured while processing your import. ' +
|
|
@@ -171,26 +197,26 @@ class Import extends zen_command_1.default {
|
|
|
171
197
|
}
|
|
172
198
|
return resultOrError.outPath;
|
|
173
199
|
}
|
|
174
|
-
async importFromGeneratorEngines(schema,
|
|
175
|
-
|
|
200
|
+
async importFromGeneratorEngines(schema, flags, fixedOptions) {
|
|
201
|
+
let preAnswered = {};
|
|
176
202
|
if (schema === 'mysql' || schema === 'postgresql') {
|
|
177
|
-
|
|
178
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
179
|
-
|
|
203
|
+
preAnswered = this.getSqlOptionsFromFlags(flags);
|
|
204
|
+
if (Object.prototype.hasOwnProperty.call(preAnswered, 'linkTypes')) {
|
|
205
|
+
preAnswered.linkTypes = preAnswered.linkTypes ? 'Yes' : 'No';
|
|
180
206
|
}
|
|
181
207
|
}
|
|
182
208
|
// Let's go!
|
|
183
|
-
const result = await generate_1.default(Object.assign(Object.assign({}, fixedOptions), { schema,
|
|
209
|
+
const result = await (0, generate_1.default)(Object.assign(Object.assign({}, fixedOptions), { schema,
|
|
184
210
|
preAnswered }));
|
|
185
211
|
// Validate
|
|
186
|
-
await transpiler_1.validate(result, {
|
|
187
|
-
extensions: await utils_1.getStepZenExtensions(),
|
|
212
|
+
await (0, transpiler_1.validate)(result, {
|
|
213
|
+
extensions: await (0, utils_1.getStepZenExtensions)(),
|
|
188
214
|
});
|
|
189
215
|
return result;
|
|
190
216
|
}
|
|
191
217
|
async ensureOnConflictBehavior(workspace, schema, flags) {
|
|
192
|
-
const
|
|
193
|
-
if (
|
|
218
|
+
const detectNameConflicts = (0, utils_1.getFeatureFlag)(constants_1.DETECT_NAME_CONFLICTS);
|
|
219
|
+
if (!detectNameConflicts) {
|
|
194
220
|
return 'append';
|
|
195
221
|
}
|
|
196
222
|
const name = flags.name || schema;
|
|
@@ -292,7 +318,7 @@ class Import extends zen_command_1.default {
|
|
|
292
318
|
const headers = [];
|
|
293
319
|
if (headerFlagValues) {
|
|
294
320
|
headerFlagValues.forEach(value => {
|
|
295
|
-
const headerOrError = header_1.parseHeader(value);
|
|
321
|
+
const headerOrError = (0, header_1.parseHeader)(value);
|
|
296
322
|
if (headerOrError && 'error' in headerOrError) {
|
|
297
323
|
throw new errors_1.CLIError(headerOrError.error);
|
|
298
324
|
}
|
|
@@ -304,19 +330,37 @@ class Import extends zen_command_1.default {
|
|
|
304
330
|
}
|
|
305
331
|
});
|
|
306
332
|
}
|
|
307
|
-
const headersOrError = header_params_parser_1.makeHeaders(headers, headerParamFlagValues);
|
|
333
|
+
const headersOrError = (0, header_params_parser_1.makeHeaders)(headers, headerParamFlagValues);
|
|
308
334
|
if ('error' in headersOrError) {
|
|
309
335
|
throw new errors_1.CLIError(headersOrError.error);
|
|
310
336
|
}
|
|
311
337
|
return headersOrError;
|
|
312
338
|
}
|
|
313
339
|
getSqlOptionsFromFlags(flags) {
|
|
314
|
-
const
|
|
315
|
-
|
|
340
|
+
const options = {
|
|
341
|
+
host: flags['db-host'],
|
|
342
|
+
user: flags['db-user'],
|
|
343
|
+
password: flags['db-password'],
|
|
344
|
+
database: flags['db-database'],
|
|
345
|
+
linkTypes: flags['db-link-types'],
|
|
346
|
+
schema: flags['db-schema'],
|
|
347
|
+
include: flags['db-include'],
|
|
348
|
+
};
|
|
349
|
+
if ((0, utils_1.getFeatureFlag)(constants_1.USE_GENERATOR_ENGINES)) {
|
|
350
|
+
// Explicitly delete all `undefined` properties to keep the
|
|
351
|
+
// `generator-engines` cloud function happy
|
|
352
|
+
Object.keys(options).forEach(key => {
|
|
353
|
+
const k = key;
|
|
354
|
+
if (options[k] === undefined) {
|
|
355
|
+
delete options[k];
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
return options;
|
|
316
360
|
}
|
|
317
361
|
}
|
|
318
362
|
exports.default = Import;
|
|
319
|
-
Import.description = 'import a schema for an external data source or
|
|
363
|
+
Import.description = 'import a schema for an external data source or an API endpoint to your GraphQL API';
|
|
320
364
|
Import.commonIntrospectionFlags = {
|
|
321
365
|
prefix: command_1.flags.string({
|
|
322
366
|
description: '[curl, graphql] prefix to add every type in the generated schema.',
|
|
@@ -376,10 +420,16 @@ Import.sqlFlags = {
|
|
|
376
420
|
description: '[mysql, postgresql] name of database to import',
|
|
377
421
|
}),
|
|
378
422
|
'db-link-types': command_1.flags.boolean({
|
|
379
|
-
description: `[mysql, postgresql] Automatically link types
|
|
380
|
-
`
|
|
423
|
+
description: `[mysql, postgresql] Automatically link types based on` +
|
|
424
|
+
` foreign key relationships using @materializer` +
|
|
381
425
|
` ${chalk.dim('(https://stepzen.com/docs/features/linking-types)')}`,
|
|
382
426
|
}),
|
|
427
|
+
'db-include': command_1.flags.enum({
|
|
428
|
+
options: ['tables-only', 'views-only', 'tables-and-views'],
|
|
429
|
+
description: `[mysql, postgresql] Should the generated GraphQL schema be based` +
|
|
430
|
+
` only on database views, only on tables or on both.`,
|
|
431
|
+
hidden: (0, utils_1.getFeatureFlag)(constants_1.USE_GENERATOR_ENGINES),
|
|
432
|
+
}),
|
|
383
433
|
};
|
|
384
434
|
Import.postgresqlFlags = {
|
|
385
435
|
'db-schema': command_1.flags.string({
|
package/lib/commands/init.js
CHANGED
|
@@ -7,7 +7,7 @@ const zen_command_1 = require("../shared/zen-command");
|
|
|
7
7
|
class Init extends zen_command_1.default {
|
|
8
8
|
async run() {
|
|
9
9
|
const { args, flags } = this.parse(Init);
|
|
10
|
-
const created = await workspace_1.initWorkspace({
|
|
10
|
+
const created = await (0, workspace_1.initWorkspace)({
|
|
11
11
|
directory: args.directory,
|
|
12
12
|
endpoint: flags.endpoint,
|
|
13
13
|
yes: flags.yes,
|
|
@@ -17,7 +17,7 @@ class Init extends zen_command_1.default {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
exports.default = Init;
|
|
20
|
-
Init.description = '
|
|
20
|
+
Init.description = 'Initialize a StepZen workspace in the current directory';
|
|
21
21
|
Init.hidden = true;
|
|
22
22
|
Init.flags = Object.assign(Object.assign({}, zen_command_1.default.flags), { endpoint: command_1.flags.string({ hidden: true }), help: command_1.flags.help({ char: 'h' }), yes: command_1.flags.boolean({ default: false, hidden: true }) });
|
|
23
23
|
Init.args = [
|
package/lib/commands/lint.js
CHANGED
|
@@ -9,7 +9,7 @@ class Init extends zen_command_1.default {
|
|
|
9
9
|
async run() {
|
|
10
10
|
const { flags } = this.parse(Init);
|
|
11
11
|
// Get the correct directory
|
|
12
|
-
const directory = utils_1.getDirectory(flags.dir);
|
|
12
|
+
const directory = (0, utils_1.getDirectory)(flags.dir);
|
|
13
13
|
this.log(directory);
|
|
14
14
|
// Take over console.log
|
|
15
15
|
console.log = (msg) => {
|
|
@@ -18,7 +18,7 @@ class Init extends zen_command_1.default {
|
|
|
18
18
|
this.log(formatted);
|
|
19
19
|
};
|
|
20
20
|
// Lint
|
|
21
|
-
await transpiler_1.lint(directory);
|
|
21
|
+
await (0, transpiler_1.lint)(directory);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
exports.default = Init;
|
package/lib/commands/list.js
CHANGED
|
@@ -14,7 +14,7 @@ class List extends zen_command_1.default {
|
|
|
14
14
|
var _a;
|
|
15
15
|
const { args } = this.parse(List);
|
|
16
16
|
await this.ensureStepZenAccount();
|
|
17
|
-
const response = await actions_1.list(args.type);
|
|
17
|
+
const response = await (0, actions_1.list)(args.type);
|
|
18
18
|
if (response.success) {
|
|
19
19
|
if (((_a = response.results) === null || _a === void 0 ? void 0 : _a.length) === 0) {
|
|
20
20
|
// Success, but no results
|
package/lib/commands/login.js
CHANGED
|
@@ -15,7 +15,7 @@ class Login extends zen_command_1.default {
|
|
|
15
15
|
const { flags } = this.parse(Login);
|
|
16
16
|
let configuration;
|
|
17
17
|
if (flags.public) {
|
|
18
|
-
const { uuid } = await configuration_1.readConfiguration();
|
|
18
|
+
const { uuid } = await (0, configuration_1.readConfiguration)();
|
|
19
19
|
configuration = await stepzen_sdk_1.default.createAnonymousAccount(uuid);
|
|
20
20
|
}
|
|
21
21
|
else {
|
|
@@ -23,7 +23,7 @@ class Login extends zen_command_1.default {
|
|
|
23
23
|
let adminkey;
|
|
24
24
|
// If the --config flag is provided, try and log in using the details in the file
|
|
25
25
|
if (flags.config) {
|
|
26
|
-
const config = await configuration_1.importConfiguration(flags.config);
|
|
26
|
+
const config = await (0, configuration_1.importConfiguration)(flags.config);
|
|
27
27
|
account = config.account;
|
|
28
28
|
adminkey = config.adminkey;
|
|
29
29
|
}
|
|
@@ -49,7 +49,7 @@ class Login extends zen_command_1.default {
|
|
|
49
49
|
configuration = await stepzen_sdk_1.default.login(adminkey, account);
|
|
50
50
|
}
|
|
51
51
|
// Change the default account.
|
|
52
|
-
configuration_1.writeCredentialsToConfigFile(configuration);
|
|
52
|
+
(0, configuration_1.writeCredentialsToConfigFile)(configuration);
|
|
53
53
|
this.log(`You have successfully logged in as ${chalk.bold(configuration.account)}.`);
|
|
54
54
|
}
|
|
55
55
|
}
|
package/lib/commands/logout.js
CHANGED
|
@@ -9,7 +9,7 @@ const zen_command_1 = require("../shared/zen-command");
|
|
|
9
9
|
class Logout extends zen_command_1.default {
|
|
10
10
|
async run() {
|
|
11
11
|
// Remove the configuration from the login file.
|
|
12
|
-
configuration_1.removeCredentialsFromConfigFile();
|
|
12
|
+
(0, configuration_1.removeCredentialsFromConfigFile)();
|
|
13
13
|
this.log('You have been logged out.');
|
|
14
14
|
}
|
|
15
15
|
}
|
package/lib/commands/start.js
CHANGED
|
@@ -27,25 +27,27 @@ class Start extends zen_command_1.default {
|
|
|
27
27
|
if (flags.endpoint) {
|
|
28
28
|
workspace.endpoint = flags.endpoint;
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
if (!flags['no-dashboard']) {
|
|
31
|
+
// Check the port is available
|
|
32
|
+
const port = await detect(flags.port);
|
|
33
|
+
if (flags.port !== port) {
|
|
34
|
+
throw new errors_1.CLIError(`Could not start - port ${flags.port} is already in use`);
|
|
35
|
+
}
|
|
34
36
|
}
|
|
35
|
-
const printEndpointDetailsOnce = lodash_1.once(() => {
|
|
36
|
-
start_1.success({
|
|
37
|
+
const printEndpointDetailsOnce = (0, lodash_1.once)(() => {
|
|
38
|
+
(0, start_1.success)({
|
|
37
39
|
workspace,
|
|
38
40
|
account: configuration.account,
|
|
39
|
-
port: flags.port,
|
|
41
|
+
port: flags['no-dashboard'] ? undefined : flags.port,
|
|
40
42
|
});
|
|
41
43
|
this.log();
|
|
42
44
|
});
|
|
43
45
|
// This is the file watcher
|
|
44
46
|
if (!flags['no-watcher']) {
|
|
45
|
-
const redeploy = throttle_debounce_1.debounce(500, (path) => {
|
|
47
|
+
const redeploy = (0, throttle_debounce_1.debounce)(500, (path) => {
|
|
46
48
|
debug('stepzen:start')(`chokidar decected change to ${path}`);
|
|
47
|
-
start_1.changed({ workspace, file: path });
|
|
48
|
-
start_1.deploy({ workspace, flags }).then(didDeploy => {
|
|
49
|
+
(0, start_1.changed)({ workspace, file: path });
|
|
50
|
+
(0, start_1.deploy)({ workspace, flags }).then(didDeploy => {
|
|
49
51
|
didDeploy && printEndpointDetailsOnce();
|
|
50
52
|
});
|
|
51
53
|
});
|
|
@@ -65,7 +67,7 @@ class Start extends zen_command_1.default {
|
|
|
65
67
|
let didDeploy = false;
|
|
66
68
|
// Unless explicitly disabled, auto-init
|
|
67
69
|
if (!flags['no-init']) {
|
|
68
|
-
didDeploy = await start_1.deploy({ workspace, flags });
|
|
70
|
+
didDeploy = await (0, start_1.deploy)({ workspace, flags });
|
|
69
71
|
}
|
|
70
72
|
// Create the dashboard
|
|
71
73
|
if (!flags['no-dashboard']) {
|
|
@@ -96,7 +98,7 @@ class Start extends zen_command_1.default {
|
|
|
96
98
|
printEndpointDetailsOnce();
|
|
97
99
|
}
|
|
98
100
|
if (!flags['no-watcher']) {
|
|
99
|
-
start_1.watching(workspace);
|
|
101
|
+
(0, start_1.watching)(workspace);
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
104
|
}
|
|
@@ -12,10 +12,10 @@ const zen_command_1 = require("../shared/zen-command");
|
|
|
12
12
|
class Transpile extends zen_command_1.default {
|
|
13
13
|
async run() {
|
|
14
14
|
const { args, flags } = this.parse(Transpile);
|
|
15
|
-
const folder = utils_1.getDirectory(args.folder);
|
|
15
|
+
const folder = (0, utils_1.getDirectory)(args.folder);
|
|
16
16
|
// CONFIG
|
|
17
17
|
if (flags['output-configuration']) {
|
|
18
|
-
const config = await transpiler_1.configure(folder, flags.silent);
|
|
18
|
+
const config = await (0, transpiler_1.configure)(folder, flags.silent);
|
|
19
19
|
if (flags['hide-output']) {
|
|
20
20
|
return config;
|
|
21
21
|
}
|
|
@@ -24,9 +24,9 @@ class Transpile extends zen_command_1.default {
|
|
|
24
24
|
}
|
|
25
25
|
// SCHEMA
|
|
26
26
|
try {
|
|
27
|
-
const schema = transpiler_1.stitch(folder);
|
|
28
|
-
transpiler_1.validate(schema, {
|
|
29
|
-
extensions: await utils_1.getStepZenExtensions(),
|
|
27
|
+
const schema = (0, transpiler_1.stitch)(folder);
|
|
28
|
+
(0, transpiler_1.validate)(schema, {
|
|
29
|
+
extensions: await (0, utils_1.getStepZenExtensions)(),
|
|
30
30
|
});
|
|
31
31
|
const file = path.join(schema, 'index.graphql');
|
|
32
32
|
const stitched = fs.readFileSync(file, 'utf8');
|