@duraxis/cli 0.3.0 → 0.5.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/CHANGELOG.md +29 -0
- package/README.md +20 -71
- package/dist/admin.command-Dt5MnwJw.js +299 -0
- package/dist/admin.command-Dt5MnwJw.js.map +1 -0
- package/dist/cli.d.ts +7 -0
- package/dist/commands/admin.command.d.ts +3 -0
- package/dist/commands/doctor.command.d.ts +9 -0
- package/dist/commands/init.command.d.ts +3 -0
- package/dist/commands/migration.command.d.ts +3 -0
- package/dist/commands/minimal-admin.d.ts +4 -0
- package/dist/config-BKscNXeW.js +204 -0
- package/dist/config-BKscNXeW.js.map +1 -0
- package/dist/config.d.ts +10 -8
- package/dist/dependencies/configured-registry.d.ts +3 -0
- package/dist/dependencies/dependency-resolver.d.ts +2 -0
- package/dist/dependencies/installed-package.d.ts +1 -0
- package/dist/dependencies/package-manager.d.ts +10 -0
- package/dist/dependencies/registry-client.d.ts +21 -0
- package/dist/dependencies/version-compatibility.d.ts +9 -0
- package/dist/file-plan-D-Sj3yv0.js +130 -0
- package/dist/file-plan-D-Sj3yv0.js.map +1 -0
- package/dist/filesystem/file-plan.d.ts +32 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +366 -551
- package/dist/index.js.map +1 -1
- package/dist/init/initialization-options.d.ts +32 -0
- package/dist/init/initialization-planner.d.ts +10 -0
- package/dist/init/nest-integration.d.ts +2 -0
- package/dist/init/project-detector.d.ts +27 -0
- package/dist/init/static-config.d.ts +16 -0
- package/dist/init.command-DrO29773.js +167 -0
- package/dist/init.command-DrO29773.js.map +1 -0
- package/dist/initialization-planner-B41PNGWc.js +315 -0
- package/dist/initialization-planner-B41PNGWc.js.map +1 -0
- package/dist/migration.command-dhRbN4UI.js +361 -0
- package/dist/migration.command-dhRbN4UI.js.map +1 -0
- package/dist/minimal-admin-B4ur_cON.js +232 -0
- package/dist/minimal-admin-B4ur_cON.js.map +1 -0
- package/dist/nest-integration-KCc7ZaG6.js +93 -0
- package/dist/nest-integration-KCc7ZaG6.js.map +1 -0
- package/dist/package-manager-Ca5ArUf-.js +269 -0
- package/dist/package-manager-Ca5ArUf-.js.map +1 -0
- package/dist/project-detector-BQWeQZ8Q.js +174 -0
- package/dist/project-detector-BQWeQZ8Q.js.map +1 -0
- package/dist/registry/argument-parser.d.ts +65 -0
- package/dist/registry/command-registry.d.ts +198 -0
- package/dist/rolldown-runtime-D8jQpDG7.js +12 -0
- package/dist/static-config-g_7qN12_.js +109 -0
- package/dist/static-config-g_7qN12_.js.map +1 -0
- package/dist/templates/project.d.ts +10 -0
- package/dist/terminal/prompts.d.ts +2 -0
- package/package.json +13 -8
package/dist/index.js
CHANGED
|
@@ -1,579 +1,394 @@
|
|
|
1
|
+
import { o as disposeTypeScriptLoader, r as loadConfig } from "./config-BKscNXeW.js";
|
|
1
2
|
import { parseArgs } from "node:util";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
|
|
3
|
+
// src/registry/command-registry.ts
|
|
4
|
+
var options = {
|
|
5
|
+
config: { type: "string" },
|
|
6
|
+
database: { type: "string" },
|
|
7
|
+
json: { type: "boolean" },
|
|
8
|
+
help: {
|
|
9
|
+
type: "boolean",
|
|
10
|
+
short: "h"
|
|
11
|
+
},
|
|
12
|
+
version: { type: "boolean" },
|
|
13
|
+
framework: { type: "string" },
|
|
14
|
+
driver: { type: "string" },
|
|
15
|
+
orm: { type: "boolean" },
|
|
16
|
+
"no-orm": { type: "boolean" },
|
|
17
|
+
migrations: { type: "boolean" },
|
|
18
|
+
"no-migrations": { type: "boolean" },
|
|
19
|
+
"package-manager": { type: "string" },
|
|
20
|
+
language: { type: "string" },
|
|
21
|
+
"module-format": { type: "string" },
|
|
22
|
+
namespace: { type: "string" },
|
|
23
|
+
directory: { type: "string" },
|
|
24
|
+
"source-dir": { type: "string" },
|
|
25
|
+
"storage-directory": { type: "string" },
|
|
26
|
+
bucket: { type: "string" },
|
|
27
|
+
prefix: { type: "string" },
|
|
28
|
+
region: { type: "string" },
|
|
29
|
+
endpoint: { type: "string" },
|
|
30
|
+
"force-path-style": { type: "boolean" },
|
|
31
|
+
"schema-mode": { type: "string" },
|
|
32
|
+
example: { type: "boolean" },
|
|
33
|
+
"no-example": { type: "boolean" },
|
|
34
|
+
install: { type: "boolean" },
|
|
35
|
+
"no-install": { type: "boolean" },
|
|
36
|
+
"dry-run": { type: "boolean" },
|
|
37
|
+
yes: { type: "boolean" },
|
|
38
|
+
steps: { type: "string" },
|
|
39
|
+
to: { type: "string" },
|
|
40
|
+
"allow-destructive": { type: "boolean" },
|
|
41
|
+
offline: { type: "boolean" },
|
|
42
|
+
persisted: { type: "boolean" },
|
|
43
|
+
schema: { type: "string" },
|
|
44
|
+
live: { type: "boolean" },
|
|
45
|
+
evaluate: { type: "boolean" },
|
|
46
|
+
check: { type: "boolean" },
|
|
47
|
+
apply: { type: "boolean" },
|
|
48
|
+
registry: { type: "string" },
|
|
49
|
+
prerelease: { type: "boolean" },
|
|
50
|
+
"custom-module": { type: "string" },
|
|
51
|
+
"custom-export": { type: "string" },
|
|
52
|
+
"custom-constructor": { type: "boolean" },
|
|
53
|
+
"custom-options": { type: "string" },
|
|
54
|
+
"max-stored-bytes": { type: "string" },
|
|
55
|
+
"max-object-bytes": { type: "string" },
|
|
56
|
+
"max-entries": { type: "string" },
|
|
57
|
+
"max-metadata-bytes": { type: "string" },
|
|
58
|
+
"max-journal-bytes": { type: "string" },
|
|
59
|
+
"max-queued-operations": { type: "string" },
|
|
60
|
+
"max-pending-operations": { type: "string" },
|
|
61
|
+
"max-attempts": { type: "string" },
|
|
62
|
+
"ownership-recovery": { type: "string" },
|
|
63
|
+
"application-id": { type: "string" },
|
|
64
|
+
"resources-file": { type: "string" },
|
|
65
|
+
"cursor-key-env": { type: "string" }
|
|
26
66
|
};
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
load(url, context, nextLoad) {
|
|
76
|
-
if (!modules.has(url)) return nextLoad(url, context);
|
|
77
|
-
const file = localFile(url);
|
|
78
|
-
if (!file) return nextLoad(url, context);
|
|
79
|
-
const path = fileURLToPath(file);
|
|
80
|
-
if (!/\.(?:ts|mts|cts)$/.test(path) || /\.d\.(?:ts|mts|cts)$/.test(path)) return nextLoad(url, context);
|
|
81
|
-
const commonjs = path.endsWith(".cts");
|
|
82
|
-
const result = ts.transpileModule(readFileSync(file, "utf8"), {
|
|
83
|
-
fileName: path,
|
|
84
|
-
reportDiagnostics: true,
|
|
85
|
-
compilerOptions: {
|
|
86
|
-
target: ts.ScriptTarget.ES2022,
|
|
87
|
-
module: commonjs ? ts.ModuleKind.NodeNext : ts.ModuleKind.ESNext,
|
|
88
|
-
...commonjs ? { moduleResolution: ts.ModuleResolutionKind.NodeNext } : {},
|
|
89
|
-
experimentalDecorators: true,
|
|
90
|
-
emitDecoratorMetadata: true,
|
|
91
|
-
useDefineForClassFields: false,
|
|
92
|
-
sourceMap: false
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
const errors = (result.diagnostics ?? []).filter((item) => item.category == ts.DiagnosticCategory.Error);
|
|
96
|
-
if (errors.length) throw new Error(ts.formatDiagnosticsWithColorAndContext(errors, {
|
|
97
|
-
getCurrentDirectory: () => process.cwd(),
|
|
98
|
-
getCanonicalFileName: (file) => file,
|
|
99
|
-
getNewLine: () => "\n"
|
|
100
|
-
}));
|
|
101
|
-
return {
|
|
102
|
-
format: commonjs ? "commonjs" : "module",
|
|
103
|
-
source: (commonjs ? "\"use strict\";\nrequire = require(\"node:module\").createRequire(__filename);\n" : "") + result.outputText,
|
|
104
|
-
shortCircuit: true
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
/** Call only when no config/entity/migration callbacks need further dynamic imports. Node's module cache is retained. */
|
|
110
|
-
function disposeTypeScriptLoader() {
|
|
111
|
-
hooks?.deregister();
|
|
112
|
-
hooks = void 0;
|
|
113
|
-
}
|
|
114
|
-
// src/config.ts
|
|
115
|
-
function defineDuraxisConfig(config) {
|
|
116
|
-
return config;
|
|
117
|
-
}
|
|
118
|
-
async function importFile(path) {
|
|
119
|
-
const url = path instanceof URL ? path : pathToFileURL(path);
|
|
120
|
-
initializeTypeScriptLoader(url);
|
|
121
|
-
return import(url.href);
|
|
122
|
-
}
|
|
123
|
-
async function loadConfig(cwd, explicit, database) {
|
|
124
|
-
let path;
|
|
125
|
-
if (explicit) path = resolve(cwd, explicit);
|
|
126
|
-
else {
|
|
127
|
-
let directory = resolve(cwd);
|
|
128
|
-
while (true) {
|
|
129
|
-
for (const name of [
|
|
130
|
-
"duraxis.config.ts",
|
|
131
|
-
"duraxis.config.mts",
|
|
132
|
-
"duraxis.config.js",
|
|
133
|
-
"duraxis.config.mjs",
|
|
134
|
-
"duraxis.config.cts",
|
|
135
|
-
"duraxis.config.cjs"
|
|
136
|
-
]) {
|
|
137
|
-
const candidate = resolve(directory, name);
|
|
138
|
-
try {
|
|
139
|
-
await access(candidate);
|
|
140
|
-
path = candidate;
|
|
141
|
-
break;
|
|
142
|
-
} catch (error) {
|
|
143
|
-
if (error.code != "ENOENT") throw error;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (path || dirname(directory) == directory) break;
|
|
147
|
-
directory = dirname(directory);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
if (!path) throw new Error("No duraxis.config.ts or JavaScript configuration found");
|
|
151
|
-
const base = (await importFile(path)).default;
|
|
152
|
-
const config = database ? base?.databases?.[database] : base;
|
|
153
|
-
if (!config || typeof config.createDatabase != "function" || !Array.isArray(config.entities) && typeof config.entities != "function" || typeof config.migrations?.directory != "string" || typeof config.migrations.snapshots != "string" || config.migrations.format !== void 0 && !["ts", "js"].includes(config.migrations.format)) throw new Error("Invalid Duraxis configuration or unknown named database");
|
|
67
|
+
var initOptions = [
|
|
68
|
+
"framework",
|
|
69
|
+
"driver",
|
|
70
|
+
"orm",
|
|
71
|
+
"no-orm",
|
|
72
|
+
"migrations",
|
|
73
|
+
"no-migrations",
|
|
74
|
+
"package-manager",
|
|
75
|
+
"language",
|
|
76
|
+
"module-format",
|
|
77
|
+
"namespace",
|
|
78
|
+
"directory",
|
|
79
|
+
"source-dir",
|
|
80
|
+
"storage-directory",
|
|
81
|
+
"bucket",
|
|
82
|
+
"prefix",
|
|
83
|
+
"region",
|
|
84
|
+
"endpoint",
|
|
85
|
+
"force-path-style",
|
|
86
|
+
"schema-mode",
|
|
87
|
+
"example",
|
|
88
|
+
"no-example",
|
|
89
|
+
"install",
|
|
90
|
+
"no-install",
|
|
91
|
+
"dry-run",
|
|
92
|
+
"yes",
|
|
93
|
+
"registry",
|
|
94
|
+
"prerelease",
|
|
95
|
+
"custom-module",
|
|
96
|
+
"custom-export",
|
|
97
|
+
"custom-constructor",
|
|
98
|
+
"custom-options",
|
|
99
|
+
"max-stored-bytes",
|
|
100
|
+
"max-object-bytes",
|
|
101
|
+
"max-entries",
|
|
102
|
+
"max-metadata-bytes",
|
|
103
|
+
"max-journal-bytes",
|
|
104
|
+
"max-queued-operations",
|
|
105
|
+
"max-pending-operations",
|
|
106
|
+
"max-attempts",
|
|
107
|
+
"resources-file",
|
|
108
|
+
"cursor-key-env",
|
|
109
|
+
"ownership-recovery",
|
|
110
|
+
"application-id"
|
|
111
|
+
];
|
|
112
|
+
function command(name, category, description, handler, extra = {}) {
|
|
154
113
|
return {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
114
|
+
name,
|
|
115
|
+
category,
|
|
116
|
+
description,
|
|
117
|
+
handler,
|
|
118
|
+
aliases: [],
|
|
119
|
+
positional: [],
|
|
120
|
+
options: [],
|
|
121
|
+
required: [],
|
|
122
|
+
defaults: {},
|
|
123
|
+
exclusive: [],
|
|
124
|
+
examples: [`duraxis ${name}`],
|
|
125
|
+
configuration: "none",
|
|
126
|
+
database: false,
|
|
127
|
+
interactive: false,
|
|
128
|
+
...extra
|
|
158
129
|
};
|
|
159
130
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
};
|
|
218
|
-
}
|
|
219
|
-
function migrationId(name, previous) {
|
|
220
|
-
if (name.includes("..") || /[\\/]/.test(name)) throw new Error("Migration names cannot contain paths");
|
|
221
|
-
const slug = name.toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
|
|
222
|
-
if (!slug || slug.length > 64) throw new Error("Invalid migration name");
|
|
223
|
-
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/\D/g, "");
|
|
224
|
-
const previousStamp = previous?.slice(0, 17);
|
|
225
|
-
return `${previousStamp && previousStamp >= stamp ? (BigInt(previousStamp) + 1n).toString().padStart(17, "0") : stamp}_${slug}`;
|
|
226
|
-
}
|
|
227
|
-
function literal(value) {
|
|
228
|
-
return JSON.stringify(value, null, 2).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
|
|
229
|
-
}
|
|
230
|
-
function renderMigration(id, plan) {
|
|
231
|
-
if (!plan) return `import { defineMigration } from "@duraxis/migrations";\n\nexport default defineMigration({\n id: ${JSON.stringify(id)},\n async up(context) {\n throw new Error("Unfinished migration: implement up and provide its expected snapshot");\n },\n});\n`;
|
|
232
|
-
const inverse = diffSchemas(plan.after, plan.before);
|
|
233
|
-
const reversible = !plan.operations.some((operation) => operation.kind == "collection" && operation.after == null) && inverse.operations.every((operation) => operation.risk != "requires-data-transformation");
|
|
234
|
-
return `import { defineMigration, applySchemaPlan } from "@duraxis/migrations";\n\nexport default defineMigration({\n id: ${JSON.stringify(id)},\n async up(context) {\n await applySchemaPlan(context, ${literal(plan)});\n },\n${reversible ? ` async down(context) {\n${inverse.operations.filter((operation) => operation.kind == "collection" && operation.after == null).map((operation) => ` for await (const row of context.scan(${JSON.stringify(operation.collection)})) throw new Error("Cannot drop a populated collection during generated rollback");\n`).join("")} await applySchemaPlan(context, ${literal(inverse)});\n },\n` : " // Irreversible automatically: write an explicit data-safe down() if needed.\n"} });\n`;
|
|
235
|
-
}
|
|
236
|
-
async function withArtifactLock(directory, callback) {
|
|
237
|
-
await mkdir(directory, { recursive: true });
|
|
238
|
-
const lock = join(directory, ".duraxis-artifacts.lock");
|
|
239
|
-
await writeFile(lock, canonicalJSON({
|
|
240
|
-
pid: process.pid,
|
|
241
|
-
purpose: "artifact update; inspect files before removing a stale guard"
|
|
242
|
-
}), { flag: "wx" });
|
|
243
|
-
try {
|
|
244
|
-
return await callback();
|
|
245
|
-
} finally {
|
|
246
|
-
await unlink(lock);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
async function writePair(migrationPath, source, snapshotPath, snapshot) {
|
|
250
|
-
await mkdir(resolve(snapshotPath, ".."), { recursive: true });
|
|
251
|
-
await writeFile(migrationPath, source, { flag: "wx" });
|
|
252
|
-
try {
|
|
253
|
-
await writeFile(snapshotPath, JSON.stringify(snapshot, null, 2) + "\n", { flag: "wx" });
|
|
254
|
-
} catch (error) {
|
|
255
|
-
await unlink(migrationPath);
|
|
256
|
-
throw error;
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
async function removePair(migrationPath, snapshotPath) {
|
|
260
|
-
const suffix = `.removing-${randomBytes(6).toString("hex")}`;
|
|
261
|
-
await rename(migrationPath, migrationPath + suffix);
|
|
262
|
-
try {
|
|
263
|
-
await rename(snapshotPath, snapshotPath + suffix);
|
|
264
|
-
} catch (error) {
|
|
265
|
-
await rename(migrationPath + suffix, migrationPath);
|
|
266
|
-
throw error;
|
|
267
|
-
}
|
|
268
|
-
await unlink(migrationPath + suffix);
|
|
269
|
-
await unlink(snapshotPath + suffix);
|
|
270
|
-
}
|
|
271
|
-
// src/cli.ts
|
|
272
|
-
var help = `duraxis <command> [options]
|
|
273
|
-
init
|
|
274
|
-
migration:create <name>
|
|
275
|
-
migration:generate <name> [--allow-destructive]
|
|
276
|
-
migration:snapshot --schema <collections.json>
|
|
277
|
-
migration:remove --yes
|
|
278
|
-
migration:baseline <name> --yes
|
|
279
|
-
migrate:up [--steps N | --to ID] [--dry-run] [--allow-destructive]
|
|
280
|
-
migrate:down [--steps N | --to ID] --yes
|
|
281
|
-
migrate:status
|
|
282
|
-
migrate:diff [--persisted]
|
|
283
|
-
migrate:check [--offline]
|
|
284
|
-
Options: --config PATH --database NAME --json
|
|
285
|
-
Rollback --to retains the target version. Dry-run is a static preview only.`;
|
|
286
|
-
async function withDatabase(config, callback) {
|
|
287
|
-
const database = await config.createDatabase();
|
|
288
|
-
try {
|
|
289
|
-
return await callback(database);
|
|
290
|
-
} finally {
|
|
291
|
-
await database.close({ closeStorage: true });
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
function summary(plan) {
|
|
295
|
-
return plan.operations.length ? plan.operations.map((operation) => `${operation.before == null ? "+" : operation.after == null ? "-" : "~"} ${operation.kind} ${operation.collection}/${operation.name} (${operation.risk})`).join("\n") : "No schema differences.";
|
|
296
|
-
}
|
|
297
|
-
async function init(cwd) {
|
|
298
|
-
const configPath = resolve(cwd, "duraxis.config.ts");
|
|
299
|
-
const base = resolve(cwd, "duraxis/snapshots/baseline.json");
|
|
300
|
-
for (const path of [configPath, base]) try {
|
|
301
|
-
await access(path);
|
|
302
|
-
throw new Error(`Refusing to overwrite ${path}`);
|
|
303
|
-
} catch (error) {
|
|
304
|
-
if (error.code != "ENOENT") throw error;
|
|
305
|
-
}
|
|
306
|
-
await mkdir(resolve(cwd, "duraxis/migrations"), { recursive: true });
|
|
307
|
-
await mkdir(resolve(cwd, "duraxis/snapshots"), { recursive: true });
|
|
308
|
-
await writeFile(configPath, `import { defineDuraxisConfig } from "@duraxis/cli";
|
|
309
|
-
|
|
310
|
-
export default defineDuraxisConfig({
|
|
311
|
-
entities: [], // Import your decorated entity classes here.
|
|
312
|
-
migrations: { directory: "./duraxis/migrations", snapshots: "./duraxis/snapshots", format: "ts" },
|
|
313
|
-
async createDatabase() {
|
|
314
|
-
// Return a DuraxisDatabase configured with your storage driver.
|
|
315
|
-
// The CLI closes this database and its storage after every command.
|
|
316
|
-
throw new Error("Configure createDatabase() before accessing a database");
|
|
317
|
-
},
|
|
318
|
-
});
|
|
319
|
-
`, { flag: "wx" });
|
|
320
|
-
try {
|
|
321
|
-
await writeFile(base, JSON.stringify(createSnapshot(null, null, []), null, 2) + "\n", { flag: "wx" });
|
|
322
|
-
} catch (error) {
|
|
323
|
-
await unlink(configPath);
|
|
324
|
-
throw error;
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
async function runCLI(args, io = {}) {
|
|
328
|
-
const cwd = io.cwd ?? process.cwd();
|
|
329
|
-
const out = io.out ?? console.log;
|
|
330
|
-
const errorOut = io.error ?? console.error;
|
|
331
|
-
let jsonErrors = false;
|
|
332
|
-
try {
|
|
333
|
-
const { values, positionals } = parseArgs({
|
|
334
|
-
args: [...args],
|
|
335
|
-
allowPositionals: true,
|
|
336
|
-
strict: true,
|
|
337
|
-
options: {
|
|
338
|
-
config: { type: "string" },
|
|
339
|
-
database: { type: "string" },
|
|
340
|
-
json: { type: "boolean" },
|
|
341
|
-
steps: { type: "string" },
|
|
342
|
-
to: { type: "string" },
|
|
343
|
-
"dry-run": { type: "boolean" },
|
|
344
|
-
"allow-destructive": { type: "boolean" },
|
|
345
|
-
yes: { type: "boolean" },
|
|
346
|
-
offline: { type: "boolean" },
|
|
347
|
-
persisted: { type: "boolean" },
|
|
348
|
-
schema: { type: "string" },
|
|
349
|
-
help: { type: "boolean" }
|
|
350
|
-
}
|
|
351
|
-
});
|
|
352
|
-
jsonErrors = values.json ?? false;
|
|
353
|
-
const command = positionals[0];
|
|
354
|
-
const name = positionals[1];
|
|
355
|
-
if (!command || values.help) {
|
|
356
|
-
out(help);
|
|
357
|
-
return 0;
|
|
358
|
-
}
|
|
359
|
-
if (![
|
|
360
|
-
"init",
|
|
131
|
+
var commands = [
|
|
132
|
+
command("init", "SETUP", "Initialize and configure Duraxis", "init", {
|
|
133
|
+
options: initOptions,
|
|
134
|
+
interactive: true,
|
|
135
|
+
defaults: {
|
|
136
|
+
driver: "disk",
|
|
137
|
+
framework: "auto",
|
|
138
|
+
language: "auto",
|
|
139
|
+
"module-format": "auto",
|
|
140
|
+
namespace: "default",
|
|
141
|
+
install: true
|
|
142
|
+
},
|
|
143
|
+
exclusive: [
|
|
144
|
+
["orm", "no-orm"],
|
|
145
|
+
["migrations", "no-migrations"],
|
|
146
|
+
["install", "no-install"],
|
|
147
|
+
["example", "no-example"]
|
|
148
|
+
],
|
|
149
|
+
examples: ["duraxis init --driver disk --migrations --yes", "duraxis init --driver memory --no-orm --no-install --yes"]
|
|
150
|
+
}),
|
|
151
|
+
command("doctor", "SETUP", "Diagnose project and environment without executing configuration", "admin"),
|
|
152
|
+
command("config:show", "CONFIGURATION", "Show redacted static configuration (or trusted code with --evaluate)", "admin", {
|
|
153
|
+
options: ["evaluate"],
|
|
154
|
+
configuration: "static"
|
|
155
|
+
}),
|
|
156
|
+
command("config:validate", "CONFIGURATION", "Validate configuration without opening storage", "admin", {
|
|
157
|
+
options: ["evaluate"],
|
|
158
|
+
configuration: "static"
|
|
159
|
+
}),
|
|
160
|
+
command("config:set", "CONFIGURATION", "Safely edit literal connection settings", "admin", {
|
|
161
|
+
positional: ["key", "value"],
|
|
162
|
+
options: ["dry-run"],
|
|
163
|
+
configuration: "static"
|
|
164
|
+
}),
|
|
165
|
+
command("connection:add", "CONFIGURATION", "Add a named connection to the central configuration", "admin", {
|
|
166
|
+
positional: ["name"],
|
|
167
|
+
options: initOptions,
|
|
168
|
+
configuration: "static"
|
|
169
|
+
}),
|
|
170
|
+
command("connection:list", "CONFIGURATION", "List connections without opening databases", "admin", { configuration: "static" }),
|
|
171
|
+
command("storage:list", "STORAGE", "List official drivers and operational limits", "admin"),
|
|
172
|
+
command("storage:check", "STORAGE", "Check configuration; --live opens storage read-only", "admin", {
|
|
173
|
+
options: ["live"],
|
|
174
|
+
configuration: "static"
|
|
175
|
+
}),
|
|
176
|
+
command("generate:entity", "GENERATORS", "Generate an ORM entity discovered by file convention", "admin", {
|
|
177
|
+
positional: ["name"],
|
|
178
|
+
options: ["dry-run"],
|
|
179
|
+
configuration: "static"
|
|
180
|
+
}),
|
|
181
|
+
command("generate:module", "GENERATORS", "Generate a NestJS feature module", "admin", {
|
|
182
|
+
positional: ["name"],
|
|
183
|
+
options: ["dry-run"],
|
|
184
|
+
configuration: "static"
|
|
185
|
+
}),
|
|
186
|
+
...[
|
|
187
|
+
[
|
|
361
188
|
"migration:create",
|
|
189
|
+
"Create a manual migration",
|
|
190
|
+
["name"],
|
|
191
|
+
[]
|
|
192
|
+
],
|
|
193
|
+
[
|
|
362
194
|
"migration:generate",
|
|
195
|
+
"Generate a schema migration",
|
|
196
|
+
["name"],
|
|
197
|
+
["allow-destructive"]
|
|
198
|
+
],
|
|
199
|
+
[
|
|
363
200
|
"migration:snapshot",
|
|
201
|
+
"Save expected schema snapshot",
|
|
202
|
+
[],
|
|
203
|
+
["schema"]
|
|
204
|
+
],
|
|
205
|
+
[
|
|
364
206
|
"migration:remove",
|
|
207
|
+
"Remove latest unpublished migration",
|
|
208
|
+
[],
|
|
209
|
+
["yes"]
|
|
210
|
+
],
|
|
211
|
+
[
|
|
365
212
|
"migration:baseline",
|
|
213
|
+
"Adopt existing schema",
|
|
214
|
+
["name"],
|
|
215
|
+
["yes"]
|
|
216
|
+
],
|
|
217
|
+
[
|
|
366
218
|
"migrate:up",
|
|
367
|
-
"
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
"migrate:check"
|
|
371
|
-
].includes(command)) throw new Error(`Unknown command: ${command}`);
|
|
372
|
-
if (positionals.length > 2 || name && ![
|
|
373
|
-
"migration:create",
|
|
374
|
-
"migration:generate",
|
|
375
|
-
"migration:baseline"
|
|
376
|
-
].includes(command)) throw new Error("Unexpected positional arguments");
|
|
377
|
-
const allowed = {
|
|
378
|
-
init: [],
|
|
379
|
-
"migration:create": [],
|
|
380
|
-
"migration:generate": ["allow-destructive"],
|
|
381
|
-
"migration:snapshot": ["schema"],
|
|
382
|
-
"migration:remove": ["yes"],
|
|
383
|
-
"migration:baseline": ["yes"],
|
|
384
|
-
"migrate:up": [
|
|
219
|
+
"Apply pending migrations",
|
|
220
|
+
[],
|
|
221
|
+
[
|
|
385
222
|
"steps",
|
|
386
223
|
"to",
|
|
387
224
|
"dry-run",
|
|
388
225
|
"allow-destructive"
|
|
389
|
-
]
|
|
390
|
-
|
|
226
|
+
]
|
|
227
|
+
],
|
|
228
|
+
[
|
|
229
|
+
"migrate:down",
|
|
230
|
+
"Roll back migrations (target retained)",
|
|
231
|
+
[],
|
|
232
|
+
[
|
|
391
233
|
"steps",
|
|
392
234
|
"to",
|
|
393
235
|
"yes"
|
|
394
|
-
]
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
"migrate:
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
"
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
]
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
236
|
+
]
|
|
237
|
+
],
|
|
238
|
+
[
|
|
239
|
+
"migrate:status",
|
|
240
|
+
"Display migration history",
|
|
241
|
+
[],
|
|
242
|
+
[]
|
|
243
|
+
],
|
|
244
|
+
[
|
|
245
|
+
"migrate:diff",
|
|
246
|
+
"Compare schemas",
|
|
247
|
+
[],
|
|
248
|
+
["persisted"]
|
|
249
|
+
],
|
|
250
|
+
[
|
|
251
|
+
"migrate:check",
|
|
252
|
+
"Validate migration integrity",
|
|
253
|
+
[],
|
|
254
|
+
["offline"]
|
|
255
|
+
]
|
|
256
|
+
].map(([name, description, positional, supported]) => command(name, "MIGRATIONS", description, "migration", {
|
|
257
|
+
positional,
|
|
258
|
+
options: supported,
|
|
259
|
+
configuration: "migration",
|
|
260
|
+
required: name === "migration:snapshot" ? ["schema"] : [
|
|
261
|
+
"migration:remove",
|
|
262
|
+
"migration:baseline",
|
|
263
|
+
"migrate:down"
|
|
264
|
+
].includes(name) ? ["yes"] : [],
|
|
265
|
+
database: name.startsWith("migrate:") ? "conditional" : ["migration:baseline", "migration:remove"].includes(name),
|
|
266
|
+
exclusive: [["steps", "to"]]
|
|
267
|
+
})),
|
|
268
|
+
command("upgrade", "DEPENDENCIES", "Check or explicitly apply compatible published updates", "admin", {
|
|
269
|
+
options: [
|
|
270
|
+
"check",
|
|
271
|
+
"apply",
|
|
272
|
+
"package-manager",
|
|
273
|
+
"registry",
|
|
274
|
+
"prerelease"
|
|
275
|
+
],
|
|
276
|
+
exclusive: [["check", "apply"]],
|
|
277
|
+
defaults: { check: true }
|
|
278
|
+
}),
|
|
279
|
+
command("help", "INFORMATION", "Display command documentation", "help", {
|
|
280
|
+
positional: ["command"],
|
|
281
|
+
optionalPositionals: true
|
|
282
|
+
}),
|
|
283
|
+
command("version", "INFORMATION", "Display the CLI version", "version", { aliases: ["--version"] })
|
|
284
|
+
];
|
|
285
|
+
function findCommand(name) {
|
|
286
|
+
const found = commands.find((c) => c.name === name || c.aliases.includes(name));
|
|
287
|
+
if (!found) throw new Error(`Unknown command: ${name}. Run duraxis help.`);
|
|
288
|
+
return found;
|
|
289
|
+
}
|
|
290
|
+
function helpText(definition) {
|
|
291
|
+
if (!definition) return `Duraxis CLI\n\nUsage: duraxis <command> [options]\n\n${[...new Set(commands.map((c) => c.category))].map((category) => `${category}\n${commands.filter((c) => c.category === category).map((c) => ` ${c.name.padEnd(22)} ${c.description}`).join("\n")}`).join("\n\n")}\n\nExamples:\n duraxis init\n duraxis doctor\n duraxis help init\n duraxis migrate:status\n duraxis upgrade --check\n`;
|
|
292
|
+
const supportedOptions = [
|
|
293
|
+
"config",
|
|
294
|
+
"database",
|
|
295
|
+
"json",
|
|
296
|
+
"help",
|
|
297
|
+
...definition.options
|
|
298
|
+
];
|
|
299
|
+
return `${definition.description}\n\nUsage: duraxis ${definition.name} ${definition.positional.map((p) => `<${p}>`).join(" ")} [options]\n\n${supportedOptions.map((name) => ` --${name}${options[name].type === "string" ? " <value>" : ""}${definition.defaults[name] !== void 0 ? ` (default: ${definition.defaults[name]})` : ""}${definition.required.includes(name) ? " (required)" : ""}`).join("\n")}\n\nConfiguration: ${definition.configuration}; database access: ${definition.database === "conditional" ? "depends on command flags" : definition.database ? "required" : "not required by default"}.\n${definition.exclusive.map((group) => `Mutually exclusive: ${group.map((n) => `--${n}`).join(", ")}`).join("\n")}\n${definition.name === "storage:check" ? "Live Disk checks may acquire exclusive directory ownership. No test objects are written." : ""}\nExamples:\n${definition.examples.map((e) => ` ${e}`).join("\n")}`;
|
|
300
|
+
}
|
|
301
|
+
// src/registry/argument-parser.ts
|
|
302
|
+
function parseCommand(args) {
|
|
303
|
+
const parsed = parseArgs({
|
|
304
|
+
args: [...args],
|
|
305
|
+
options,
|
|
306
|
+
allowPositionals: true,
|
|
307
|
+
strict: true
|
|
308
|
+
});
|
|
309
|
+
const name = parsed.values.version ? "version" : parsed.positionals[0] ?? "help";
|
|
310
|
+
const definition = findCommand(name);
|
|
311
|
+
const positionals = parsed.positionals.slice(parsed.positionals[0] ? 1 : 0);
|
|
312
|
+
if (positionals.length > definition.positional.length) throw new Error("Unexpected positional arguments");
|
|
313
|
+
for (const option of Object.keys(parsed.values)) if (![
|
|
314
|
+
"config",
|
|
315
|
+
"database",
|
|
316
|
+
"json",
|
|
317
|
+
"help",
|
|
318
|
+
"version",
|
|
319
|
+
...definition.options
|
|
320
|
+
].includes(option)) throw new Error(`Option --${option} is not supported by ${name}`);
|
|
321
|
+
if (!parsed.values.help) {
|
|
322
|
+
if (!definition.optionalPositionals && positionals.length < definition.positional.length) throw new Error(`Missing positional arguments: ${definition.positional.join(", ")}`);
|
|
323
|
+
for (const group of definition.exclusive) if (group.filter((n) => parsed.values[n] !== void 0).length > 1) throw new Error(`Mutually exclusive options: ${group.map((n) => `--${n}`).join(", ")}`);
|
|
324
|
+
for (const option of definition.required) if (parsed.values[option] === void 0) throw new Error(`Missing required --${option}`);
|
|
325
|
+
}
|
|
326
|
+
return {
|
|
327
|
+
...parsed,
|
|
328
|
+
definition,
|
|
329
|
+
positionals
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
// src/cli.ts
|
|
333
|
+
async function runCLI(args, io = {}) {
|
|
334
|
+
const out = io.out ?? console.log;
|
|
335
|
+
const error = io.error ?? console.error;
|
|
336
|
+
let json = args.includes("--json");
|
|
337
|
+
let migrationCommand = false;
|
|
338
|
+
const controller = new AbortController();
|
|
339
|
+
const interrupt = () => controller.abort(/* @__PURE__ */ new Error("Operation cancelled"));
|
|
340
|
+
process.once("SIGINT", interrupt);
|
|
341
|
+
const context = {
|
|
342
|
+
...io,
|
|
343
|
+
signal: io.signal ? AbortSignal.any([io.signal, controller.signal]) : controller.signal
|
|
344
|
+
};
|
|
345
|
+
try {
|
|
346
|
+
const parsed = parseCommand(args);
|
|
347
|
+
json = parsed.values.json ?? false;
|
|
348
|
+
if (parsed.values.help || parsed.definition.handler === "help") {
|
|
349
|
+
const target = parsed.definition.handler === "help" && parsed.positionals[0] ? findCommand(parsed.positionals[0]) : parsed.definition.handler === "help" ? void 0 : parsed.definition;
|
|
350
|
+
out(json ? JSON.stringify({ help: helpText(target) }) : helpText(target));
|
|
487
351
|
return 0;
|
|
488
352
|
}
|
|
489
|
-
if (
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
try {
|
|
500
|
-
await access(snapshotPath);
|
|
501
|
-
} catch (error) {
|
|
502
|
-
if (error.code != "ENOENT") throw error;
|
|
503
|
-
await unlink(join(directory, latestFile));
|
|
504
|
-
return;
|
|
353
|
+
if (parsed.definition.handler === "version") {
|
|
354
|
+
const { readFile } = await import("node:fs/promises");
|
|
355
|
+
const { dirname, join } = await import("node:path");
|
|
356
|
+
let root = import.meta.dirname;
|
|
357
|
+
while (true) {
|
|
358
|
+
try {
|
|
359
|
+
const manifest = JSON.parse(await readFile(join(root, "package.json"), "utf8"));
|
|
360
|
+
if (manifest && typeof manifest === "object" && "name" in manifest && manifest.name === "@duraxis/cli" && "version" in manifest) {
|
|
361
|
+
out(json ? JSON.stringify({ version: manifest.version }) : String(manifest.version));
|
|
362
|
+
return 0;
|
|
505
363
|
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
const local = await loadArtifacts(config, root);
|
|
513
|
-
if (command == "migrate:diff" && !values.persisted) {
|
|
514
|
-
const plan = diffSchemas(local.artifacts.at(-1)?.snapshot.collections ?? [], await entities());
|
|
515
|
-
print(plan, summary(plan));
|
|
516
|
-
return 0;
|
|
517
|
-
}
|
|
518
|
-
if (command == "migrate:check" && values.offline) {
|
|
519
|
-
validateArtifacts(local.artifacts);
|
|
520
|
-
const plan = diffSchemas(local.artifacts.at(-1)?.snapshot.collections ?? [], await entities());
|
|
521
|
-
if (plan.operations.length) throw new Error(`Unrepresented entity changes:\n${summary(plan)}`);
|
|
522
|
-
print({
|
|
523
|
-
valid: true,
|
|
524
|
-
mode: "offline"
|
|
525
|
-
}, "Local files, snapshots, and entity schema are valid. Database history was not checked.");
|
|
526
|
-
return 0;
|
|
364
|
+
} catch (cause) {
|
|
365
|
+
if (!(cause instanceof Error && "code" in cause && cause.code === "ENOENT")) throw cause;
|
|
366
|
+
}
|
|
367
|
+
if (dirname(root) === root) throw new Error("CLI package version unavailable");
|
|
368
|
+
root = dirname(root);
|
|
369
|
+
}
|
|
527
370
|
}
|
|
528
|
-
if (
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
print({
|
|
534
|
-
dryRun: true,
|
|
535
|
-
appliedStateChecked: false,
|
|
536
|
-
candidates
|
|
537
|
-
}, `Static preview only; database was not opened and applied state was not checked. Migration callbacks were not executed.\n${candidates.join("\n")}`);
|
|
538
|
-
return 0;
|
|
371
|
+
if (parsed.definition.handler === "migration") {
|
|
372
|
+
migrationCommand = true;
|
|
373
|
+
const code = await (await import("./migration.command-dhRbN4UI.js")).executeMigration(parsed, context);
|
|
374
|
+
context.signal.throwIfAborted();
|
|
375
|
+
return code;
|
|
539
376
|
}
|
|
540
|
-
await
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
} else if (command == "migrate:down") {
|
|
551
|
-
if (!values.yes) throw new Error("Rollback requires --yes; review backups and down() first");
|
|
552
|
-
const reverted = await runner.down({
|
|
553
|
-
...options,
|
|
554
|
-
allowDestructive: true
|
|
555
|
-
});
|
|
556
|
-
print({ reverted }, `Reverted ${reverted.length} migration(s).`);
|
|
557
|
-
} else if (command == "migrate:status") {
|
|
558
|
-
const status = await runner.status();
|
|
559
|
-
print(status, `Duraxis migration status\nDatabase: ${values.database ?? "default"}\n\nApplied:\n${status.applied.map((entry) => ` ${entry.id}`).join("\n")}\nPending:\n${status.pending.map((id) => ` ${id}`).join("\n")}\nSchema drift: none\n${status.applied.length} applied, ${status.pending.length} pending`);
|
|
560
|
-
} else if (command == "migrate:diff") {
|
|
561
|
-
const plan = await runner.drift();
|
|
562
|
-
print(plan, summary(plan));
|
|
563
|
-
} else if (command == "migrate:check") {
|
|
564
|
-
await runner.status();
|
|
565
|
-
const plan = diffSchemas(local.artifacts.at(-1)?.snapshot.collections ?? [], await entities());
|
|
566
|
-
if (plan.operations.length) throw new Error(`Unrepresented entity changes:\n${summary(plan)}`);
|
|
567
|
-
print({ valid: true }, "Migration files, snapshots, history, schema, and entities are valid.");
|
|
568
|
-
}
|
|
569
|
-
});
|
|
570
|
-
return 0;
|
|
571
|
-
} catch (error) {
|
|
572
|
-
const message = error instanceof CommitOutcomeUnknownError ? `Commit outcome is unknown for transaction ${error.transactionId}. Reconcile migration status before retrying; do not repeat external side effects.` : error instanceof ResourceExhaustedError ? error.message : error instanceof OperationCancelledError ? "Duraxis operation cancelled or deadline exceeded. Check configured resource deadlines and storage health." : error instanceof Error ? error.message : String(error);
|
|
573
|
-
errorOut(jsonErrors ? JSON.stringify({ error: message }) : message);
|
|
377
|
+
const result = parsed.definition.handler === "init" ? await (await import("./init.command-DrO29773.js")).initialize(parsed, context) : await (await import("./admin.command-Dt5MnwJw.js")).administer(parsed, context);
|
|
378
|
+
out(json ? JSON.stringify(result) : typeof result === "string" ? result : JSON.stringify(result, null, 2));
|
|
379
|
+
return result && typeof result === "object" && "failed" in result && result.failed === true ? 1 : 0;
|
|
380
|
+
} catch (cause) {
|
|
381
|
+
const cleanupFailed = cause instanceof Error && cause.name === "DuraxisMigrationCleanupError";
|
|
382
|
+
const message = cleanupFailed ? "Migration database cleanup failed; inspect storage health and migration status before retrying" : context.signal.aborted ? migrationCommand ? "Migration operation cancelled. Inspect local artifacts and migrate:status before retrying; publication may have completed." : "Operation cancelled" : cause instanceof Error ? cause.message : "Command failed";
|
|
383
|
+
error(json ? JSON.stringify({ error: {
|
|
384
|
+
code: cleanupFailed ? "CLEANUP_FAILED" : context.signal.aborted ? "CANCELLED" : "COMMAND_FAILED",
|
|
385
|
+
message
|
|
386
|
+
} }) : message);
|
|
574
387
|
return 1;
|
|
388
|
+
} finally {
|
|
389
|
+
process.removeListener("SIGINT", interrupt);
|
|
575
390
|
}
|
|
576
391
|
}
|
|
577
|
-
export {
|
|
392
|
+
export { disposeTypeScriptLoader, loadConfig, runCLI };
|
|
578
393
|
|
|
579
394
|
//# sourceMappingURL=index.js.map
|