@zmdb/cli 1.0.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/LICENSE +674 -0
- package/README.md +19 -0
- package/dist/__fixtures__/http-client/src/contract.d.ts +38 -0
- package/dist/__fixtures__/http-client/src/contract.d.ts.map +1 -0
- package/dist/__fixtures__/http-client/src/contract.js +121 -0
- package/dist/__fixtures__/http-client/src/contract.js.map +1 -0
- package/dist/__fixtures__/http-client/src/models.d.ts +11 -0
- package/dist/__fixtures__/http-client/src/models.d.ts.map +1 -0
- package/dist/__fixtures__/http-client/src/models.js +2 -0
- package/dist/__fixtures__/http-client/src/models.js.map +1 -0
- package/dist/__fixtures__/http-client/src/schema.d.ts +4 -0
- package/dist/__fixtures__/http-client/src/schema.d.ts.map +1 -0
- package/dist/__fixtures__/http-client/src/schema.js +2 -0
- package/dist/__fixtures__/http-client/src/schema.js.map +1 -0
- package/dist/__fixtures__/http-client/src/unrelated.d.ts +2 -0
- package/dist/__fixtures__/http-client/src/unrelated.d.ts.map +1 -0
- package/dist/__fixtures__/http-client/src/unrelated.js +2 -0
- package/dist/__fixtures__/http-client/src/unrelated.js.map +1 -0
- package/dist/__fixtures__/http-client/zmdb.config.d.ts +16 -0
- package/dist/__fixtures__/http-client/zmdb.config.d.ts.map +1 -0
- package/dist/__fixtures__/http-client/zmdb.config.js +12 -0
- package/dist/__fixtures__/http-client/zmdb.config.js.map +1 -0
- package/dist/__fixtures__/project/src/schema.d.ts +6 -0
- package/dist/__fixtures__/project/src/schema.d.ts.map +1 -0
- package/dist/__fixtures__/project/src/schema.js +2 -0
- package/dist/__fixtures__/project/src/schema.js.map +1 -0
- package/dist/__fixtures__/project/zmdb.config.d.ts +22 -0
- package/dist/__fixtures__/project/zmdb.config.d.ts.map +1 -0
- package/dist/__fixtures__/project/zmdb.config.js +55 -0
- package/dist/__fixtures__/project/zmdb.config.js.map +1 -0
- package/dist/application-loader.d.ts +4 -0
- package/dist/application-loader.d.ts.map +1 -0
- package/dist/application-loader.js +102 -0
- package/dist/application-loader.js.map +1 -0
- package/dist/args.d.ts +23 -0
- package/dist/args.d.ts.map +1 -0
- package/dist/args.js +353 -0
- package/dist/args.js.map +1 -0
- package/dist/atomic.d.ts +13 -0
- package/dist/atomic.d.ts.map +1 -0
- package/dist/atomic.js +28 -0
- package/dist/atomic.js.map +1 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +4 -0
- package/dist/bin.js.map +1 -0
- package/dist/commands/check.d.ts +5 -0
- package/dist/commands/check.d.ts.map +1 -0
- package/dist/commands/check.js +7 -0
- package/dist/commands/check.js.map +1 -0
- package/dist/commands/client.d.ts +38 -0
- package/dist/commands/client.d.ts.map +1 -0
- package/dist/commands/client.js +347 -0
- package/dist/commands/client.js.map +1 -0
- package/dist/commands/codegen.d.ts +9 -0
- package/dist/commands/codegen.d.ts.map +1 -0
- package/dist/commands/codegen.js +56 -0
- package/dist/commands/codegen.js.map +1 -0
- package/dist/commands/embed.d.ts +8 -0
- package/dist/commands/embed.d.ts.map +1 -0
- package/dist/commands/embed.js +17 -0
- package/dist/commands/embed.js.map +1 -0
- package/dist/commands/export.d.ts +5 -0
- package/dist/commands/export.d.ts.map +1 -0
- package/dist/commands/export.js +6 -0
- package/dist/commands/export.js.map +1 -0
- package/dist/commands/generate.d.ts +5 -0
- package/dist/commands/generate.d.ts.map +1 -0
- package/dist/commands/generate.js +6 -0
- package/dist/commands/generate.js.map +1 -0
- package/dist/commands/migrate.d.ts +9 -0
- package/dist/commands/migrate.d.ts.map +1 -0
- package/dist/commands/migrate.js +18 -0
- package/dist/commands/migrate.js.map +1 -0
- package/dist/commands/new.d.ts +4 -0
- package/dist/commands/new.d.ts.map +1 -0
- package/dist/commands/new.js +35 -0
- package/dist/commands/new.js.map +1 -0
- package/dist/commands/pull.d.ts +5 -0
- package/dist/commands/pull.d.ts.map +1 -0
- package/dist/commands/pull.js +14 -0
- package/dist/commands/pull.js.map +1 -0
- package/dist/commands/push.d.ts +6 -0
- package/dist/commands/push.d.ts.map +1 -0
- package/dist/commands/push.js +11 -0
- package/dist/commands/push.js.map +1 -0
- package/dist/commands/studio.d.ts +31 -0
- package/dist/commands/studio.d.ts.map +1 -0
- package/dist/commands/studio.js +154 -0
- package/dist/commands/studio.js.map +1 -0
- package/dist/commands/upgrade.d.ts +5 -0
- package/dist/commands/upgrade.d.ts.map +1 -0
- package/dist/commands/upgrade.js +11 -0
- package/dist/commands/upgrade.js.map +1 -0
- package/dist/database.d.ts +4 -0
- package/dist/database.d.ts.map +1 -0
- package/dist/database.js +8 -0
- package/dist/database.js.map +1 -0
- package/dist/errors.d.ts +7 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +20 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +626 -0
- package/dist/index.js.map +1 -0
- package/dist/lifecycle.d.ts +6 -0
- package/dist/lifecycle.d.ts.map +1 -0
- package/dist/lifecycle.js +75 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/migration-project.d.ts +14 -0
- package/dist/migration-project.d.ts.map +1 -0
- package/dist/migration-project.js +74 -0
- package/dist/migration-project.js.map +1 -0
- package/dist/output.d.ts +27 -0
- package/dist/output.d.ts.map +1 -0
- package/dist/output.js +60 -0
- package/dist/output.js.map +1 -0
- package/dist/repl.d.ts +48 -0
- package/dist/repl.d.ts.map +1 -0
- package/dist/repl.js +265 -0
- package/dist/repl.js.map +1 -0
- package/dist/scaffold.d.ts +28 -0
- package/dist/scaffold.d.ts.map +1 -0
- package/dist/scaffold.js +414 -0
- package/dist/scaffold.js.map +1 -0
- package/dist/studio/index.d.ts +20 -0
- package/dist/studio/index.d.ts.map +1 -0
- package/dist/studio/index.js +607 -0
- package/dist/studio/index.js.map +1 -0
- package/dist/templates/command.d.ts +3 -0
- package/dist/templates/command.d.ts.map +1 -0
- package/dist/templates/command.js +65 -0
- package/dist/templates/command.js.map +1 -0
- package/dist/templates/controller.d.ts +3 -0
- package/dist/templates/controller.d.ts.map +1 -0
- package/dist/templates/controller.js +41 -0
- package/dist/templates/controller.js.map +1 -0
- package/dist/templates/index.d.ts +4 -0
- package/dist/templates/index.d.ts.map +1 -0
- package/dist/templates/index.js +18 -0
- package/dist/templates/index.js.map +1 -0
- package/dist/templates/module.d.ts +3 -0
- package/dist/templates/module.d.ts.map +1 -0
- package/dist/templates/module.js +41 -0
- package/dist/templates/module.js.map +1 -0
- package/dist/templates/project.d.ts +3 -0
- package/dist/templates/project.d.ts.map +1 -0
- package/dist/templates/project.js +280 -0
- package/dist/templates/project.js.map +1 -0
- package/dist/templates/repository.d.ts +3 -0
- package/dist/templates/repository.d.ts.map +1 -0
- package/dist/templates/repository.js +66 -0
- package/dist/templates/repository.js.map +1 -0
- package/dist/templates/schema.d.ts +3 -0
- package/dist/templates/schema.d.ts.map +1 -0
- package/dist/templates/schema.js +36 -0
- package/dist/templates/schema.js.map +1 -0
- package/dist/templates/types.d.ts +25 -0
- package/dist/templates/types.d.ts.map +1 -0
- package/dist/templates/types.js +17 -0
- package/dist/templates/types.js.map +1 -0
- package/package.json +72 -0
- package/src/__fixtures__/http-client/package.json +5 -0
- package/src/__fixtures__/http-client/src/contract.ts +85 -0
- package/src/__fixtures__/http-client/src/models.ts +12 -0
- package/src/__fixtures__/http-client/src/schema.ts +3 -0
- package/src/__fixtures__/http-client/src/unrelated.ts +1 -0
- package/src/__fixtures__/http-client/tsconfig.json +17 -0
- package/src/__fixtures__/http-client/zmdb.config.ts +12 -0
- package/src/__fixtures__/project/package.json +5 -0
- package/src/__fixtures__/project/src/schema.ts +6 -0
- package/src/__fixtures__/project/tsconfig.json +24 -0
- package/src/__fixtures__/project/zmdb.config.ts +57 -0
- package/src/application-loader.ts +108 -0
- package/src/args.ts +391 -0
- package/src/atomic.ts +43 -0
- package/src/bin.ts +5 -0
- package/src/commands/check.ts +11 -0
- package/src/commands/client.ts +415 -0
- package/src/commands/codegen.ts +73 -0
- package/src/commands/embed.ts +36 -0
- package/src/commands/export.ts +10 -0
- package/src/commands/generate.ts +14 -0
- package/src/commands/migrate.ts +38 -0
- package/src/commands/new.ts +48 -0
- package/src/commands/pull.ts +32 -0
- package/src/commands/push.ts +21 -0
- package/src/commands/studio.ts +200 -0
- package/src/commands/upgrade.ts +14 -0
- package/src/database.ts +9 -0
- package/src/errors.ts +19 -0
- package/src/index.ts +710 -0
- package/src/lifecycle.ts +73 -0
- package/src/migration-project.ts +91 -0
- package/src/output.ts +77 -0
- package/src/repl.ts +328 -0
- package/src/scaffold.ts +485 -0
- package/src/studio/index.ts +674 -0
- package/src/templates/command.ts +66 -0
- package/src/templates/controller.ts +42 -0
- package/src/templates/index.ts +29 -0
- package/src/templates/module.ts +42 -0
- package/src/templates/project.ts +281 -0
- package/src/templates/repository.ts +67 -0
- package/src/templates/schema.ts +37 -0
- package/src/templates/types.ts +46 -0
package/dist/args.js
ADDED
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import { parseArgs } from 'node:util';
|
|
3
|
+
const COMMON_OPTIONS = {
|
|
4
|
+
config: {
|
|
5
|
+
type: 'string',
|
|
6
|
+
valueName: 'path',
|
|
7
|
+
description: 'Use this config file instead of discovery.',
|
|
8
|
+
},
|
|
9
|
+
project: {
|
|
10
|
+
type: 'string',
|
|
11
|
+
valueName: 'tsconfig',
|
|
12
|
+
description: "Override the config's TypeScript project.",
|
|
13
|
+
},
|
|
14
|
+
json: {
|
|
15
|
+
type: 'boolean',
|
|
16
|
+
description: 'Write one machine-readable result document to stdout.',
|
|
17
|
+
},
|
|
18
|
+
yes: {
|
|
19
|
+
type: 'boolean',
|
|
20
|
+
description: 'Answer permitted prompts without reading stdin.',
|
|
21
|
+
},
|
|
22
|
+
force: {
|
|
23
|
+
type: 'boolean',
|
|
24
|
+
description: 'Permit destructive database operations where supported.',
|
|
25
|
+
},
|
|
26
|
+
help: {
|
|
27
|
+
type: 'boolean',
|
|
28
|
+
short: 'h',
|
|
29
|
+
description: 'Show help for this command.',
|
|
30
|
+
},
|
|
31
|
+
version: {
|
|
32
|
+
type: 'boolean',
|
|
33
|
+
description: 'Print the installed zmdb version.',
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
const DATABASE_COMMANDS = {
|
|
37
|
+
generate: {
|
|
38
|
+
usage: 'zmdb generate [--name <slug>]',
|
|
39
|
+
summary: 'Create a migration and update the stored snapshot.',
|
|
40
|
+
options: {
|
|
41
|
+
name: {
|
|
42
|
+
type: 'string',
|
|
43
|
+
valueName: 'slug',
|
|
44
|
+
description: 'Name the migration; otherwise derive a name from the plan.',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
maximumPositionals: 0,
|
|
48
|
+
},
|
|
49
|
+
embed: {
|
|
50
|
+
usage: 'zmdb embed [--out <file>] [--with-down]',
|
|
51
|
+
summary: 'Compile SQLite migrations into a bundle-resident TypeScript module.',
|
|
52
|
+
options: {
|
|
53
|
+
out: {
|
|
54
|
+
type: 'string',
|
|
55
|
+
valueName: 'file',
|
|
56
|
+
description: 'Write this module instead of migrations/embedded.ts.',
|
|
57
|
+
},
|
|
58
|
+
'with-down': {
|
|
59
|
+
type: 'boolean',
|
|
60
|
+
description: 'Include down sections for development tooling.',
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
maximumPositionals: 0,
|
|
64
|
+
},
|
|
65
|
+
migrate: {
|
|
66
|
+
usage: 'zmdb migrate',
|
|
67
|
+
summary: 'Apply pending migrations.',
|
|
68
|
+
options: {},
|
|
69
|
+
maximumPositionals: 0,
|
|
70
|
+
},
|
|
71
|
+
rollback: {
|
|
72
|
+
usage: 'zmdb rollback [--to <version>]',
|
|
73
|
+
summary: 'Revert the latest migration or roll back to a version.',
|
|
74
|
+
options: {
|
|
75
|
+
to: {
|
|
76
|
+
type: 'string',
|
|
77
|
+
valueName: 'version',
|
|
78
|
+
description: 'Revert down to, but not including, this version.',
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
maximumPositionals: 0,
|
|
82
|
+
},
|
|
83
|
+
status: {
|
|
84
|
+
usage: 'zmdb status',
|
|
85
|
+
summary: 'List migration versions and their applied state.',
|
|
86
|
+
options: {},
|
|
87
|
+
maximumPositionals: 0,
|
|
88
|
+
},
|
|
89
|
+
push: {
|
|
90
|
+
usage: 'zmdb push --force --yes',
|
|
91
|
+
summary: 'Apply declaration changes directly to a development database.',
|
|
92
|
+
options: {},
|
|
93
|
+
maximumPositionals: 0,
|
|
94
|
+
},
|
|
95
|
+
check: {
|
|
96
|
+
usage: 'zmdb check',
|
|
97
|
+
summary: 'Report schema, migration and snapshot findings.',
|
|
98
|
+
options: {},
|
|
99
|
+
maximumPositionals: 0,
|
|
100
|
+
},
|
|
101
|
+
upgrade: {
|
|
102
|
+
usage: 'zmdb upgrade',
|
|
103
|
+
summary: 'Upgrade the stored snapshot format without touching a database.',
|
|
104
|
+
options: {},
|
|
105
|
+
maximumPositionals: 0,
|
|
106
|
+
},
|
|
107
|
+
export: {
|
|
108
|
+
usage: 'zmdb export',
|
|
109
|
+
summary: 'Print the declaration set as dialect DDL.',
|
|
110
|
+
options: {},
|
|
111
|
+
maximumPositionals: 0,
|
|
112
|
+
},
|
|
113
|
+
pull: {
|
|
114
|
+
usage: 'zmdb pull [--dry-run] [--check]',
|
|
115
|
+
summary: 'Write declarations from a live database catalogue.',
|
|
116
|
+
options: {
|
|
117
|
+
'dry-run': {
|
|
118
|
+
type: 'boolean',
|
|
119
|
+
description: 'Print every generated declaration and write nothing.',
|
|
120
|
+
},
|
|
121
|
+
check: {
|
|
122
|
+
type: 'boolean',
|
|
123
|
+
description: 'Exit non-zero when the generated declarations are not current.',
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
maximumPositionals: 0,
|
|
127
|
+
},
|
|
128
|
+
up: {
|
|
129
|
+
usage: 'zmdb up',
|
|
130
|
+
summary: 'Refused: use migrate for the database or upgrade for a snapshot.',
|
|
131
|
+
options: {},
|
|
132
|
+
maximumPositionals: 0,
|
|
133
|
+
hidden: true,
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
const APPLICATION_COMMANDS = {
|
|
137
|
+
client: {
|
|
138
|
+
usage: 'zmdb client generate [--check] [--watch]',
|
|
139
|
+
summary: 'Generate OpenAPI and a typed HTTP client from configured contracts.',
|
|
140
|
+
options: {
|
|
141
|
+
check: {
|
|
142
|
+
type: 'boolean',
|
|
143
|
+
description: 'Write nothing and fail when either generated artifact is stale.',
|
|
144
|
+
},
|
|
145
|
+
watch: {
|
|
146
|
+
type: 'boolean',
|
|
147
|
+
description: 'Regenerate after an input in the compiled contract dependency set changes.',
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
maximumPositionals: 1,
|
|
151
|
+
},
|
|
152
|
+
new: {
|
|
153
|
+
usage: 'zmdb new <project|schema|controller|module|repository|command> <name> [--package <pkg>]',
|
|
154
|
+
summary: 'Create a formatter-clean project or application component.',
|
|
155
|
+
options: {
|
|
156
|
+
package: {
|
|
157
|
+
type: 'string',
|
|
158
|
+
valueName: 'pkg',
|
|
159
|
+
description: 'Target this named package when invoked from a workspace.',
|
|
160
|
+
},
|
|
161
|
+
'dry-run': {
|
|
162
|
+
type: 'boolean',
|
|
163
|
+
description: 'Print every generated file and write nothing.',
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
maximumPositionals: 2,
|
|
167
|
+
},
|
|
168
|
+
modules: {
|
|
169
|
+
usage: 'zmdb modules [path#export] [--format tree|dot] [--providers]\n' +
|
|
170
|
+
' [--module <name>] [--token <description>] [--depth <n>]',
|
|
171
|
+
summary: 'Describe application declarations without constructing providers.',
|
|
172
|
+
options: {
|
|
173
|
+
format: {
|
|
174
|
+
type: 'string',
|
|
175
|
+
valueName: 'tree|dot',
|
|
176
|
+
description: 'Choose the human-readable graph format.',
|
|
177
|
+
},
|
|
178
|
+
providers: {
|
|
179
|
+
type: 'boolean',
|
|
180
|
+
description: 'Include provider nodes.',
|
|
181
|
+
},
|
|
182
|
+
module: {
|
|
183
|
+
type: 'string',
|
|
184
|
+
valueName: 'name',
|
|
185
|
+
description: 'Limit output to one module.',
|
|
186
|
+
},
|
|
187
|
+
token: {
|
|
188
|
+
type: 'string',
|
|
189
|
+
valueName: 'description',
|
|
190
|
+
description: 'Limit output to providers matching a token description.',
|
|
191
|
+
},
|
|
192
|
+
depth: {
|
|
193
|
+
type: 'string',
|
|
194
|
+
valueName: 'n',
|
|
195
|
+
description: 'Limit traversal to a non-negative depth.',
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
maximumPositionals: 1,
|
|
199
|
+
},
|
|
200
|
+
repl: {
|
|
201
|
+
usage: 'zmdb repl [path#export] [--no-history]',
|
|
202
|
+
summary: 'Boot an application into a local interactive session.',
|
|
203
|
+
options: {
|
|
204
|
+
history: {
|
|
205
|
+
type: 'boolean',
|
|
206
|
+
default: true,
|
|
207
|
+
description: 'Use private REPL history; pass --no-history to disable it.',
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
maximumPositionals: 1,
|
|
211
|
+
},
|
|
212
|
+
studio: {
|
|
213
|
+
usage: 'zmdb studio [--port <port>]',
|
|
214
|
+
summary: 'Browse configured tables through a read-only loopback server.',
|
|
215
|
+
options: {
|
|
216
|
+
port: {
|
|
217
|
+
type: 'string',
|
|
218
|
+
valueName: 'port',
|
|
219
|
+
description: 'Bind this loopback port instead of selecting an ephemeral one.',
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
maximumPositionals: 0,
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
const COMMANDS = {
|
|
226
|
+
codegen: {
|
|
227
|
+
usage: 'zmdb codegen [--project <tsconfig>] [--check] [--watch]',
|
|
228
|
+
summary: 'Generate validator artifacts from a TypeScript project.',
|
|
229
|
+
options: {
|
|
230
|
+
check: { type: 'boolean', description: 'Write nothing and fail when generated artifacts are stale.' },
|
|
231
|
+
watch: { type: 'boolean', description: 'Regenerate on source changes using one compiler session.' },
|
|
232
|
+
},
|
|
233
|
+
maximumPositionals: 0,
|
|
234
|
+
},
|
|
235
|
+
...DATABASE_COMMANDS,
|
|
236
|
+
...APPLICATION_COMMANDS,
|
|
237
|
+
};
|
|
238
|
+
export function isCommand(command) {
|
|
239
|
+
return Object.hasOwn(COMMANDS, command);
|
|
240
|
+
}
|
|
241
|
+
export function parseCommand(command, argv, cwd) {
|
|
242
|
+
const definition = COMMANDS[command];
|
|
243
|
+
if (definition === undefined) {
|
|
244
|
+
return {
|
|
245
|
+
error: `unknown command "${command}"`,
|
|
246
|
+
command,
|
|
247
|
+
config: attemptedConfig(argv, cwd),
|
|
248
|
+
json: argv.includes('--json'),
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
try {
|
|
252
|
+
const { values, positionals } = parseArgs({
|
|
253
|
+
args: argv,
|
|
254
|
+
options: parseOptions({ ...COMMON_OPTIONS, ...definition.options }),
|
|
255
|
+
strict: true,
|
|
256
|
+
allowPositionals: true,
|
|
257
|
+
allowNegative: true,
|
|
258
|
+
});
|
|
259
|
+
if (positionals.length > definition.maximumPositionals) {
|
|
260
|
+
return {
|
|
261
|
+
error: `unexpected positional argument "${positionals[definition.maximumPositionals] ?? ''}"`,
|
|
262
|
+
command,
|
|
263
|
+
config: configValue(values, cwd),
|
|
264
|
+
json: values.json === true,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
return {
|
|
268
|
+
parsed: {
|
|
269
|
+
command,
|
|
270
|
+
config: configValue(values, cwd),
|
|
271
|
+
...(typeof values.project === 'string' ? { project: values.project } : {}),
|
|
272
|
+
json: values.json === true,
|
|
273
|
+
help: values.help === true,
|
|
274
|
+
version: values.version === true,
|
|
275
|
+
positionals,
|
|
276
|
+
values,
|
|
277
|
+
},
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
return {
|
|
282
|
+
error: parseError(error),
|
|
283
|
+
command,
|
|
284
|
+
config: attemptedConfig(argv, cwd),
|
|
285
|
+
json: argv.includes('--json'),
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
export function globalHelp() {
|
|
290
|
+
const commandRows = Object.entries(COMMANDS)
|
|
291
|
+
.filter(([, definition]) => definition.hidden !== true)
|
|
292
|
+
.map(([name, definition]) => ` ${name.padEnd(10)} ${definition.summary}`);
|
|
293
|
+
return [
|
|
294
|
+
'zmdb — schema and application developer tools.',
|
|
295
|
+
'',
|
|
296
|
+
'Usage:',
|
|
297
|
+
' zmdb <command> [options]',
|
|
298
|
+
'',
|
|
299
|
+
'Commands:',
|
|
300
|
+
...commandRows,
|
|
301
|
+
'',
|
|
302
|
+
'Run `zmdb <command> --help` for command-specific options.',
|
|
303
|
+
'',
|
|
304
|
+
].join('\n');
|
|
305
|
+
}
|
|
306
|
+
export function commandHelp(command) {
|
|
307
|
+
const definition = COMMANDS[command];
|
|
308
|
+
if (definition === undefined)
|
|
309
|
+
return globalHelp();
|
|
310
|
+
const options = { ...COMMON_OPTIONS, ...definition.options };
|
|
311
|
+
const optionRows = Object.entries(options).map(([name, option]) => {
|
|
312
|
+
const longName = name === 'history' ? '--no-history' : `--${name}`;
|
|
313
|
+
const short = option.short === undefined ? '' : `-${option.short}, `;
|
|
314
|
+
const value = option.valueName === undefined ? '' : ` <${option.valueName}>`;
|
|
315
|
+
return ` ${`${short}${longName}${value}`.padEnd(30)} ${option.description}`;
|
|
316
|
+
});
|
|
317
|
+
return [definition.summary, '', 'Usage:', ` ${definition.usage}`, '', 'Options:', ...optionRows, ''].join('\n');
|
|
318
|
+
}
|
|
319
|
+
function parseOptions(definitions) {
|
|
320
|
+
const options = {};
|
|
321
|
+
for (const [name, definition] of Object.entries(definitions)) {
|
|
322
|
+
options[name] = {
|
|
323
|
+
type: definition.type,
|
|
324
|
+
...(definition.short === undefined ? {} : { short: definition.short }),
|
|
325
|
+
...(definition.default === undefined ? {} : { default: definition.default }),
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
return options;
|
|
329
|
+
}
|
|
330
|
+
function configValue(values, cwd) {
|
|
331
|
+
return resolve(cwd, typeof values.config === 'string' ? values.config : 'zmdb.config.ts');
|
|
332
|
+
}
|
|
333
|
+
function attemptedConfig(argv, cwd) {
|
|
334
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
335
|
+
const argument = argv[index];
|
|
336
|
+
if (argument === '--config') {
|
|
337
|
+
const value = argv[index + 1];
|
|
338
|
+
if (value !== undefined)
|
|
339
|
+
return resolve(cwd, value);
|
|
340
|
+
}
|
|
341
|
+
if (argument?.startsWith('--config='))
|
|
342
|
+
return resolve(cwd, argument.slice('--config='.length));
|
|
343
|
+
}
|
|
344
|
+
return resolve(cwd, 'zmdb.config.ts');
|
|
345
|
+
}
|
|
346
|
+
function parseError(error) {
|
|
347
|
+
if (!(error instanceof Error))
|
|
348
|
+
return String(error);
|
|
349
|
+
const message = error.message.replace(/^Option usage error:\s*/i, '');
|
|
350
|
+
const unknown = /^Unknown option '([^']+)'/.exec(message);
|
|
351
|
+
return unknown === null ? message : `unknown option "${unknown[1] ?? ''}"`;
|
|
352
|
+
}
|
|
353
|
+
//# sourceMappingURL=args.js.map
|
package/dist/args.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.js","sourceRoot":"","sources":["../src/args.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAA+D,MAAM,WAAW,CAAC;AAiBnG,MAAM,cAAc,GAAsB;IACxC,MAAM,EAAE;QACN,IAAI,EAAE,QAAQ;QACd,SAAS,EAAE,MAAM;QACjB,WAAW,EAAE,4CAA4C;KAC1D;IACD,OAAO,EAAE;QACP,IAAI,EAAE,QAAQ;QACd,SAAS,EAAE,UAAU;QACrB,WAAW,EAAE,2CAA2C;KACzD;IACD,IAAI,EAAE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KAAK,IAAI,CAAC,EAAE,CAAC;QACpD,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;QAC7B,IAAI,QAAQ,KAAK,UAAU,EAAE,CAAC;YAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;YAC9B,IAAI,KAAK,KAAK,SAAS;gBAAE,OAAO,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACtD,CAAC;QACD,IAAI,QAAQ,EAAE,UAAU,CAAC,WAAW,CAAC;YAAE,OAAO,OAAO,CAAC,GAAG,EAAE,QAAQ,CAAC,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IACjG,CAAC;IACD,OAAO,OAAO,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;AACxC,CAAC;AAED,SAAS,UAAU,CAAC,KAAc;IAChC,IAAI,CAAC,CAAC,KAAK,YAAY,KAAK,CAAC;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACpD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,0BAA0B,EAAE,EAAE,CAAC,CAAC;IACtE,MAAM,OAAO,GAAG,2BAA2B,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC1D,OAAO,OAAO,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,mBAAmB,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC;AAC7E,CAAC"}
|
package/dist/atomic.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface AtomicWriteOperations {
|
|
2
|
+
readonly write: (path: string, text: string) => Promise<void>;
|
|
3
|
+
readonly rename: (from: string, to: string) => Promise<void>;
|
|
4
|
+
readonly remove: (path: string) => Promise<void>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Replace one text file with a complete sibling written first.
|
|
8
|
+
*
|
|
9
|
+
* The temporary file lives in the destination directory, so `rename` is the
|
|
10
|
+
* atomic filesystem operation rather than a cross-device copy.
|
|
11
|
+
*/
|
|
12
|
+
export declare function writeTextAtomically(path: string, text: string, operations?: AtomicWriteOperations): Promise<void>;
|
|
13
|
+
//# sourceMappingURL=atomic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atomic.d.ts","sourceRoot":"","sources":["../src/atomic.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9D,QAAQ,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7D,QAAQ,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CAClD;AAUD;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,UAAU,GAAE,qBAAuC,GAClD,OAAO,CAAC,IAAI,CAAC,CAef"}
|
package/dist/atomic.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { mkdir, rename, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { basename, dirname, join } from 'node:path';
|
|
3
|
+
const FILE_OPERATIONS = {
|
|
4
|
+
write: (path, text) => writeFile(path, text, { flag: 'wx' }),
|
|
5
|
+
rename,
|
|
6
|
+
remove: path => rm(path, { force: true }),
|
|
7
|
+
};
|
|
8
|
+
let temporaryFileSequence = 0;
|
|
9
|
+
/**
|
|
10
|
+
* Replace one text file with a complete sibling written first.
|
|
11
|
+
*
|
|
12
|
+
* The temporary file lives in the destination directory, so `rename` is the
|
|
13
|
+
* atomic filesystem operation rather than a cross-device copy.
|
|
14
|
+
*/
|
|
15
|
+
export async function writeTextAtomically(path, text, operations = FILE_OPERATIONS) {
|
|
16
|
+
await mkdir(dirname(path), { recursive: true });
|
|
17
|
+
temporaryFileSequence += 1;
|
|
18
|
+
const temporary = join(dirname(path), `.${basename(path)}.${String(process.pid)}.${String(temporaryFileSequence)}.tmp`);
|
|
19
|
+
try {
|
|
20
|
+
await operations.write(temporary, text);
|
|
21
|
+
await operations.rename(temporary, path);
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
await operations.remove(temporary);
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=atomic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"atomic.js","sourceRoot":"","sources":["../src/atomic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAQpD,MAAM,eAAe,GAA0B;IAC7C,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAC5D,MAAM;IACN,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;CAC1C,CAAC;AAEF,IAAI,qBAAqB,GAAG,CAAC,CAAC;AAE9B;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,IAAY,EACZ,IAAY,EACZ,UAAU,GAA0B,eAAe;IAEnD,MAAM,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAChD,qBAAqB,IAAI,CAAC,CAAC;IAC3B,MAAM,SAAS,GAAG,IAAI,CACpB,OAAO,CAAC,IAAI,CAAC,EACb,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,qBAAqB,CAAC,MAAM,CACjF,CAAC;IAEF,IAAI,CAAC;QACH,MAAM,UAAU,CAAC,KAAK,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QACxC,MAAM,UAAU,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC3C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;QACnC,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC"}
|
package/dist/bin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":""}
|
package/dist/bin.js
ADDED
package/dist/bin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,OAAO,CAAC,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ResolvedConfig } from '@zmdb/compiler/config';
|
|
2
|
+
import { type CheckResult } from '@zmdb/migrations/files';
|
|
3
|
+
export type { CheckFinding, CheckFindingKind, CheckResult } from '@zmdb/migrations/files';
|
|
4
|
+
export declare function checkProject(config: ResolvedConfig): Promise<CheckResult>;
|
|
5
|
+
//# sourceMappingURL=check.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/commands/check.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAyC,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAIjG,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1F,wBAAsB,YAAY,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC,CAG/E"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { checkProject as checkMigrationProject } from '@zmdb/migrations/files';
|
|
2
|
+
import { configuredMigrationDriver, reflectedMigrationProject } from '../migration-project.js';
|
|
3
|
+
export async function checkProject(config) {
|
|
4
|
+
const driver = config.driver === undefined ? undefined : await configuredMigrationDriver(config);
|
|
5
|
+
return checkMigrationProject(reflectedMigrationProject(config, driver));
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=check.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check.js","sourceRoot":"","sources":["../../src/commands/check.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,IAAI,qBAAqB,EAAoB,MAAM,wBAAwB,CAAC;AAEjG,OAAO,EAAE,yBAAyB,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAI/F,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,MAAsB;IACvD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,yBAAyB,CAAC,MAAM,CAAC,CAAC;IACjG,OAAO,qBAAqB,CAAC,yBAAyB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAC1E,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ResolvedConfig } from '@zmdb/compiler/config';
|
|
2
|
+
import { ReflectSession } from '@zmdb/compiler/reflect';
|
|
3
|
+
export interface ClientGenerateResult {
|
|
4
|
+
readonly out: {
|
|
5
|
+
readonly openApi: string;
|
|
6
|
+
readonly client: string;
|
|
7
|
+
};
|
|
8
|
+
readonly operations: readonly string[];
|
|
9
|
+
readonly changed: boolean;
|
|
10
|
+
readonly contractFormat: 1;
|
|
11
|
+
readonly generatorVersion: string;
|
|
12
|
+
}
|
|
13
|
+
export interface HttpArtifactGeneration {
|
|
14
|
+
readonly result: ClientGenerateResult;
|
|
15
|
+
/** Missing or byte-different outputs before this run. */
|
|
16
|
+
readonly stale: readonly string[];
|
|
17
|
+
/** Exact project-source dependency set used for watch invalidation. */
|
|
18
|
+
readonly dependencies: readonly string[];
|
|
19
|
+
}
|
|
20
|
+
export interface GenerateHttpArtifactsOptions {
|
|
21
|
+
readonly check?: boolean;
|
|
22
|
+
/** A caller-owned session is retained and remains open after generation. */
|
|
23
|
+
readonly session?: ReflectSession;
|
|
24
|
+
}
|
|
25
|
+
export interface WatchHttpArtifactsOptions {
|
|
26
|
+
readonly debounceMs?: number;
|
|
27
|
+
readonly until?: Promise<unknown>;
|
|
28
|
+
readonly session?: ReflectSession;
|
|
29
|
+
readonly log?: (generation: HttpArtifactGeneration) => void;
|
|
30
|
+
}
|
|
31
|
+
/** Compile once, project both public artifacts, and write or check their exact bytes. */
|
|
32
|
+
export declare function generateHttpArtifacts(config: ResolvedConfig, options?: GenerateHttpArtifactsOptions): Promise<HttpArtifactGeneration>;
|
|
33
|
+
/**
|
|
34
|
+
* Keep one reflection session open and regenerate only after an input in the
|
|
35
|
+
* last compiled dependency set changes.
|
|
36
|
+
*/
|
|
37
|
+
export declare function watchHttpArtifacts(config: ResolvedConfig, options?: WatchHttpArtifactsOptions): Promise<HttpArtifactGeneration>;
|
|
38
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/commands/client.ts"],"names":[],"mappings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