monsqlize 2.0.6 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -5
- package/MIGRATION.md +127 -0
- package/README.md +194 -202
- package/SECURITY.md +21 -0
- package/changelogs/README.md +16 -4
- package/changelogs/v2.0.7.md +63 -0
- package/changelogs/v3.0.0.md +99 -0
- package/changelogs/v3.1.0-rc.0.md +23 -0
- package/changelogs/v3.1.0.md +24 -0
- package/dist/cjs/cli/data-task.cjs +380 -0
- package/dist/cjs/index.cjs +12261 -5497
- package/dist/cjs/transaction/Transaction.cjs +151 -19
- package/dist/cjs/transaction/TransactionManager.cjs +152 -20
- package/dist/esm/index.mjs +12265 -5500
- package/dist/types/collection.d.mts +92 -13
- package/dist/types/collection.d.ts +92 -13
- package/dist/types/data-tasks.d.mts +221 -0
- package/dist/types/data-tasks.d.ts +221 -0
- package/dist/types/index.d.mts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/lock.d.mts +7 -4
- package/dist/types/lock.d.ts +7 -4
- package/dist/types/model.d.mts +46 -14
- package/dist/types/model.d.ts +46 -14
- package/dist/types/monsqlize.d.mts +130 -16
- package/dist/types/monsqlize.d.ts +130 -16
- package/dist/types/runtime.d.mts +14 -1
- package/dist/types/runtime.d.ts +14 -1
- package/dist/types/saga.d.mts +11 -6
- package/dist/types/saga.d.ts +11 -6
- package/dist/types/sync.d.mts +47 -1
- package/dist/types/sync.d.ts +47 -1
- package/dist/types/transaction.d.mts +8 -0
- package/dist/types/transaction.d.ts +8 -0
- package/licenses/production-dependencies.json +11 -0
- package/package.json +45 -16
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// src/cli/data-task.ts
|
|
27
|
+
var import_promises = require("node:fs/promises");
|
|
28
|
+
var import_node_path = __toESM(require("node:path"));
|
|
29
|
+
var import_node_url = require("node:url");
|
|
30
|
+
|
|
31
|
+
// package.json
|
|
32
|
+
var package_default = {
|
|
33
|
+
name: "monsqlize",
|
|
34
|
+
version: "3.1.0",
|
|
35
|
+
description: "TypeScript production data runtime layer for MongoDB today, with cache, transactions, pools, models, sync, and observability",
|
|
36
|
+
type: "commonjs",
|
|
37
|
+
main: "./dist/cjs/index.cjs",
|
|
38
|
+
module: "./dist/esm/index.mjs",
|
|
39
|
+
types: "./dist/types/index.d.ts",
|
|
40
|
+
bin: {
|
|
41
|
+
monsqlize: "dist/cjs/cli/data-task.cjs"
|
|
42
|
+
},
|
|
43
|
+
exports: {
|
|
44
|
+
".": {
|
|
45
|
+
types: {
|
|
46
|
+
import: "./dist/types/index.d.mts",
|
|
47
|
+
require: "./dist/types/index.d.ts"
|
|
48
|
+
},
|
|
49
|
+
require: "./dist/cjs/index.cjs",
|
|
50
|
+
import: "./dist/esm/index.mjs"
|
|
51
|
+
},
|
|
52
|
+
"./package.json": "./package.json"
|
|
53
|
+
},
|
|
54
|
+
files: [
|
|
55
|
+
"dist/**/*.cjs",
|
|
56
|
+
"dist/**/*.mjs",
|
|
57
|
+
"dist/**/*.d.ts",
|
|
58
|
+
"dist/**/*.d.mts",
|
|
59
|
+
"changelogs/v3.1.0.md",
|
|
60
|
+
"changelogs/v3.1.0-rc.0.md",
|
|
61
|
+
"changelogs/v3.0.0.md",
|
|
62
|
+
"changelogs/v2.0.7.md",
|
|
63
|
+
"changelogs/v2.0.6.md",
|
|
64
|
+
"changelogs/v2.0.5.md",
|
|
65
|
+
"changelogs/v2.0.4.md",
|
|
66
|
+
"changelogs/v2.0.3.md",
|
|
67
|
+
"changelogs/v2.0.2.md",
|
|
68
|
+
"changelogs/v2.0.1.md",
|
|
69
|
+
"changelogs/v2.0.0.md",
|
|
70
|
+
"README.md",
|
|
71
|
+
"MIGRATION.md",
|
|
72
|
+
"SECURITY.md",
|
|
73
|
+
"LICENSE",
|
|
74
|
+
"licenses/production-dependencies.json",
|
|
75
|
+
"CHANGELOG.md"
|
|
76
|
+
],
|
|
77
|
+
keywords: [
|
|
78
|
+
"mongodb",
|
|
79
|
+
"database",
|
|
80
|
+
"data-runtime",
|
|
81
|
+
"database-runtime",
|
|
82
|
+
"cache",
|
|
83
|
+
"transaction",
|
|
84
|
+
"distributed",
|
|
85
|
+
"cache-invalidation",
|
|
86
|
+
"pagination",
|
|
87
|
+
"performance",
|
|
88
|
+
"mongodb-driver",
|
|
89
|
+
"nosql",
|
|
90
|
+
"typescript",
|
|
91
|
+
"query-builder",
|
|
92
|
+
"api"
|
|
93
|
+
],
|
|
94
|
+
author: "vext.js Team",
|
|
95
|
+
license: "Apache-2.0",
|
|
96
|
+
repository: {
|
|
97
|
+
type: "git",
|
|
98
|
+
url: "git+https://github.com/vextjs/monSQLize.git"
|
|
99
|
+
},
|
|
100
|
+
bugs: {
|
|
101
|
+
url: "https://github.com/vextjs/monSQLize/issues"
|
|
102
|
+
},
|
|
103
|
+
homepage: "https://vextjs.github.io/monSQLize/",
|
|
104
|
+
publishConfig: {
|
|
105
|
+
access: "public",
|
|
106
|
+
registry: "https://registry.npmjs.org/"
|
|
107
|
+
},
|
|
108
|
+
config: {
|
|
109
|
+
mongodbMemoryServer: {
|
|
110
|
+
downloadDir: ".cache/mongodb-memory-server/binaries",
|
|
111
|
+
preferGlobalPath: "false",
|
|
112
|
+
version: "7.0.37"
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
engines: {
|
|
116
|
+
node: ">=18.0.0"
|
|
117
|
+
},
|
|
118
|
+
scripts: {
|
|
119
|
+
"check:lint-contract": "node scripts/validation/check-lint-contract.cjs",
|
|
120
|
+
"check:coverage-policy": "node scripts/validation/check-coverage-policy.cjs",
|
|
121
|
+
"check:package-budgets": "node scripts/validation/check-package-budgets.cjs",
|
|
122
|
+
"check:production-licenses": "node scripts/validation/check-production-licenses.cjs",
|
|
123
|
+
"check:contributor-contract": "node scripts/validation/check-contributor-contract.cjs",
|
|
124
|
+
"check:dependency-policy": "node scripts/validation/check-dependency-policy.cjs",
|
|
125
|
+
"check:release-metadata": "node scripts/validation/check-release-metadata.cjs",
|
|
126
|
+
"check:doc-claims": "node scripts/validation/check-doc-claims.cjs",
|
|
127
|
+
"check:error-contract": "node scripts/validation/check-error-contract.cjs",
|
|
128
|
+
"check:current-version": "node scripts/validation/check-current-version-terminology.cjs",
|
|
129
|
+
"cleanup:derived": "node scripts/cleanup-derived-artifacts.cjs",
|
|
130
|
+
"cleanup:derived:apply": "node scripts/cleanup-derived-artifacts.cjs --apply --confirm=derived-artifacts",
|
|
131
|
+
"check:sizes": "node scripts/check-file-sizes.cjs",
|
|
132
|
+
"check:sizes:strict": "node scripts/check-file-sizes.cjs --strict",
|
|
133
|
+
build: "node scripts/build-p1.cjs",
|
|
134
|
+
"build:tests": "node scripts/compile-tests.cjs",
|
|
135
|
+
lint: "eslint . --ignore-pattern .generated/** --ignore-pattern dist/** --ignore-pattern .devcodex/**",
|
|
136
|
+
"lint:fix": "eslint . --fix --ignore-pattern .generated/** --ignore-pattern dist/** --ignore-pattern .devcodex/**",
|
|
137
|
+
"test:runtime": "npm run build && npm run build:tests && node --test .generated/test-dist/test/smoke/root-cjs.test.js .generated/test-dist/test/smoke/root-esm.test.js .generated/test-dist/test/smoke/pack-artifacts.test.js",
|
|
138
|
+
"test:compatibility": "npm run build && npm run build:tests && node --test .generated/test-dist/test/compatibility/exports/exports.test.js .generated/test-dist/test/compatibility/matrix.test.js",
|
|
139
|
+
"probe:server-matrix": "node scripts/validation/probe-memory-server-matrix.cjs",
|
|
140
|
+
"test:server-matrix": "node scripts/validation/run-memory-server-matrix.cjs",
|
|
141
|
+
"test:real-env:private": "node scripts/validation/run-private-real-env-checks.cjs",
|
|
142
|
+
"test:examples": "npm run build && tsc -p tsconfig.examples.json && node scripts/run-examples.cjs",
|
|
143
|
+
"test:performance": "npm run build && npm run build:tests && node .generated/test-dist/test/performance/baselines/function-cache.benchmark.js",
|
|
144
|
+
"test:unit": "npm run build && npm run build:tests && node test/run-tests.cjs unit",
|
|
145
|
+
"test:integration": "npm run build && npm run build:tests && node --test --test-concurrency=1 .generated/test-dist/test/integration/cache/cache.test.js .generated/test-dist/test/integration/cache/cache-behavior.test.js .generated/test-dist/test/integration/mongodb/connect.test.js .generated/test-dist/test/integration/mongodb/queries.test.js .generated/test-dist/test/integration/mongodb/management.test.js .generated/test-dist/test/integration/mongodb/writes-batch.test.js .generated/test-dist/test/integration/mongodb/find.test.js .generated/test-dist/test/integration/mongodb/find-one.test.js .generated/test-dist/test/integration/mongodb/find-page.test.js .generated/test-dist/test/integration/mongodb/aggregate.test.js .generated/test-dist/test/integration/mongodb/chaining.test.js .generated/test-dist/test/integration/mongodb/insert.test.js .generated/test-dist/test/integration/mongodb/update.test.js .generated/test-dist/test/integration/mongodb/delete.test.js .generated/test-dist/test/integration/mongodb/update-pipeline.test.js .generated/test-dist/test/integration/model/model-features.test.js .generated/test-dist/test/integration/transaction/transaction.test.js .generated/test-dist/test/integration/pool/pool.test.js .generated/test-dist/test/integration/pool/pool-behavior.test.js .generated/test-dist/test/integration/watch/watch-native.test.js .generated/test-dist/test/integration/runtime/runtime-core-regression.test.js .generated/test-dist/test/integration/sync/sync.test.js .generated/test-dist/test/integration/slow-query-log/slow-query-log.test.js .generated/test-dist/test/integration/model/model-crud-extended.test.js .generated/test-dist/test/integration/mongodb/management-complete.test.js .generated/test-dist/test/integration/runtime/runtime-methods-extended.test.js .generated/test-dist/test/integration/mongodb/find-page-advanced.test.js",
|
|
146
|
+
"test:data-tasks:integration": "npm run build && npm run build:tests && node test/run-tests.cjs data-tasks-integration",
|
|
147
|
+
"test:data-task-cli": "npm run build && npm run build:tests && node test/run-tests.cjs data-task-cli",
|
|
148
|
+
"test:pack-install": "npm run build && node scripts/pack-install-smoke.cjs",
|
|
149
|
+
"test:refactor-guard": "npm run build && npm run build:tests && node --test --test-concurrency=1 .generated/test-dist/test/compatibility/exports/exports.test.js .generated/test-dist/test/integration/model/model-features.test.js .generated/test-dist/test/integration/runtime/runtime-core-regression.test.js .generated/test-dist/test/integration/sync/sync.test.js",
|
|
150
|
+
"test:refactor-guard:cache": "npm run build && npm run build:tests && node --test .generated/test-dist/test/unit/cache/cache-refactor-guard.test.js",
|
|
151
|
+
"test:coverage": "node scripts/run-coverage.cjs",
|
|
152
|
+
"test:audit": "npm audit --omit=dev --registry=https://registry.npmjs.org/",
|
|
153
|
+
test: "npm run build && npm run build:tests && node test/run-tests.cjs",
|
|
154
|
+
"type-check": "npm run build && tsc -p tsconfig.json --noEmit && tsd --files test/types/root-import.test-d.ts --files test/types/cache-usage.test-d.ts --files test/types/model-usage.test-d.ts --files test/types/pool-usage.test-d.ts --files test/types/sync-usage.test-d.ts --files test/types/slow-query-log-usage.test-d.ts --files test/types/saga-usage.test-d.ts --files test/types/data-tasks-usage.test-d.ts",
|
|
155
|
+
"check:test-language": "node scripts/check-test-language.cjs",
|
|
156
|
+
"check:docs-examples": "node scripts/validation/check-doc-example-matrix.cjs",
|
|
157
|
+
"check:release-candidate": "node scripts/check-release-candidate.cjs",
|
|
158
|
+
"verify:fast": "npm run check:lint-contract && npm run lint && npm run check:contributor-contract && npm run check:dependency-policy && npm run check:release-metadata && npm run check:doc-claims && npm run check:error-contract && npm run check:current-version && npm run check:docs-examples && npm run type-check && npm run check:sizes:strict && npm run test:runtime && npm run check:package-budgets && npm run check:production-licenses && npm run test:compatibility && npm run test:refactor-guard && npm run test:refactor-guard:cache",
|
|
159
|
+
"verify:full": "npm run check:lint-contract && npm run lint && npm run check:doc-claims && npm run check:error-contract && npm run check:current-version && npm run check:docs-examples && npm run type-check && npm run check:sizes:strict && npm run test:examples && npm run test:server-matrix",
|
|
160
|
+
"verify:release": "npm run verify:full && npm run test:real-env:private",
|
|
161
|
+
verify: "npm run verify:full",
|
|
162
|
+
"release:preflight": "node scripts/release-preflight.cjs",
|
|
163
|
+
prepublishOnly: "npm run release:preflight",
|
|
164
|
+
"release:publish": "npm run release:preflight && npm publish --ignore-scripts"
|
|
165
|
+
},
|
|
166
|
+
devDependencies: {
|
|
167
|
+
"@eslint/js": "9.39.4",
|
|
168
|
+
"@types/node": "25.6.2",
|
|
169
|
+
"@types/semver": "7.7.1",
|
|
170
|
+
c8: "11.0.0",
|
|
171
|
+
chai: "6.2.2",
|
|
172
|
+
esbuild: "0.28.1",
|
|
173
|
+
eslint: "9.39.4",
|
|
174
|
+
"mongodb-memory-server": "10.4.3",
|
|
175
|
+
sinon: "22.0.0",
|
|
176
|
+
tsd: "0.33.0",
|
|
177
|
+
typescript: "5.9.3",
|
|
178
|
+
"typescript-eslint": "8.64.0"
|
|
179
|
+
},
|
|
180
|
+
dependencies: {
|
|
181
|
+
"async-lock": "1.4.1",
|
|
182
|
+
"cache-hub": "2.2.4",
|
|
183
|
+
ioredis: "5.11.1",
|
|
184
|
+
mongodb: "6.21.0",
|
|
185
|
+
"schema-dsl": "3.0.0",
|
|
186
|
+
ssh2: "1.17.0"
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// src/cli/data-task.ts
|
|
191
|
+
function usage() {
|
|
192
|
+
return [
|
|
193
|
+
"Usage:",
|
|
194
|
+
" monsqlize data-task preview --task <job.mjs> [--out <preview.json>] [--json]",
|
|
195
|
+
" monsqlize data-task apply --task <job.mjs> --approval <preview.json> [--out <result.json>] [--json]",
|
|
196
|
+
" monsqlize data-task preview-restore --task <job.mjs> --backup <manifest.json> [--out <preview.json>] [--json]",
|
|
197
|
+
" monsqlize data-task restore --task <job.mjs> --backup <manifest.json> --approval <preview.json> [--out <result.json>] [--json]",
|
|
198
|
+
" monsqlize --help | --version"
|
|
199
|
+
].join("\n");
|
|
200
|
+
}
|
|
201
|
+
function parseArgs(argv) {
|
|
202
|
+
const args = [...argv];
|
|
203
|
+
if (args[0] === "data-task") {
|
|
204
|
+
args.shift();
|
|
205
|
+
}
|
|
206
|
+
const parsed = {
|
|
207
|
+
json: false,
|
|
208
|
+
help: false,
|
|
209
|
+
version: false
|
|
210
|
+
};
|
|
211
|
+
if (args[0] === "--help" || args[0] === "-h") {
|
|
212
|
+
parsed.help = true;
|
|
213
|
+
args.shift();
|
|
214
|
+
} else if (args[0] === "--version" || args[0] === "-v") {
|
|
215
|
+
parsed.version = true;
|
|
216
|
+
args.shift();
|
|
217
|
+
} else {
|
|
218
|
+
parsed.action = args.shift();
|
|
219
|
+
}
|
|
220
|
+
while (args.length > 0) {
|
|
221
|
+
const arg = args.shift();
|
|
222
|
+
if (arg === "--task") {
|
|
223
|
+
parsed.taskFile = args.shift();
|
|
224
|
+
} else if (arg === "--json") {
|
|
225
|
+
parsed.json = true;
|
|
226
|
+
} else if (arg === "--approval") {
|
|
227
|
+
parsed.approvalFile = args.shift();
|
|
228
|
+
} else if (arg === "--backup") {
|
|
229
|
+
parsed.backupFile = args.shift();
|
|
230
|
+
} else if (arg === "--out") {
|
|
231
|
+
parsed.outFile = args.shift();
|
|
232
|
+
} else if (arg === "--help" || arg === "-h") {
|
|
233
|
+
parsed.help = true;
|
|
234
|
+
} else if (arg === "--version" || arg === "-v") {
|
|
235
|
+
parsed.version = true;
|
|
236
|
+
} else if (arg) {
|
|
237
|
+
throw new Error(`Unknown argument: ${arg}`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
return parsed;
|
|
241
|
+
}
|
|
242
|
+
function collectFailures(value, location = "result") {
|
|
243
|
+
if (!value || typeof value !== "object") return [];
|
|
244
|
+
const record = value;
|
|
245
|
+
const failures = [];
|
|
246
|
+
if (record.passed === false || record.status === "failed" || record.status === "partial") {
|
|
247
|
+
failures.push(`${location} reported failure.`);
|
|
248
|
+
}
|
|
249
|
+
if (Array.isArray(record.errors)) {
|
|
250
|
+
for (const error of record.errors) failures.push(`${location}: ${String(error)}`);
|
|
251
|
+
}
|
|
252
|
+
if (Array.isArray(record.results)) {
|
|
253
|
+
record.results.forEach((result, index) => failures.push(...collectFailures(result, `${location}.results[${index}]`)));
|
|
254
|
+
}
|
|
255
|
+
return [...new Set(failures)];
|
|
256
|
+
}
|
|
257
|
+
function unwrapDefault(value) {
|
|
258
|
+
return value && typeof value === "object" && "default" in value ? value.default : value;
|
|
259
|
+
}
|
|
260
|
+
function isDataTaskJob(value) {
|
|
261
|
+
return Boolean(value && typeof value === "object" && typeof value.name === "string" && typeof value.targetEnvironment === "string" && Array.isArray(value.collections));
|
|
262
|
+
}
|
|
263
|
+
function normalizeJobConfig(value) {
|
|
264
|
+
const exportedValue = unwrapDefault(value);
|
|
265
|
+
if (!isDataTaskJob(exportedValue)) throw new Error("Task file must directly export a DataTaskJob.");
|
|
266
|
+
return exportedValue;
|
|
267
|
+
}
|
|
268
|
+
async function loadTaskFile(file) {
|
|
269
|
+
const resolved = import_node_path.default.resolve(process.cwd(), file);
|
|
270
|
+
if (resolved.endsWith(".json")) {
|
|
271
|
+
return JSON.parse(await (0, import_promises.readFile)(resolved, "utf8"));
|
|
272
|
+
}
|
|
273
|
+
if (resolved.endsWith(".mjs")) {
|
|
274
|
+
return import((0, import_node_url.pathToFileURL)(resolved).href);
|
|
275
|
+
}
|
|
276
|
+
return require(resolved);
|
|
277
|
+
}
|
|
278
|
+
async function loadApproval(file) {
|
|
279
|
+
const parsed = JSON.parse(await (0, import_promises.readFile)(import_node_path.default.resolve(process.cwd(), file), "utf8"));
|
|
280
|
+
const approval = parsed && typeof parsed === "object" && "approval" in parsed ? parsed.approval : parsed;
|
|
281
|
+
if (!approval || approval.kind !== "apply" && approval.kind !== "restore") throw new Error("--approval must reference a preview result or approval object.");
|
|
282
|
+
return approval;
|
|
283
|
+
}
|
|
284
|
+
async function loadBackupRef(file) {
|
|
285
|
+
const resolved = import_node_path.default.resolve(process.cwd(), file);
|
|
286
|
+
const parsed = JSON.parse(await (0, import_promises.readFile)(resolved, "utf8"));
|
|
287
|
+
if (parsed.manifestPath && parsed.runId && parsed.checksum) return { runId: parsed.runId, checksum: parsed.checksum, manifestPath: import_node_path.default.resolve(import_node_path.default.dirname(resolved), parsed.manifestPath) };
|
|
288
|
+
if (typeof parsed.runId !== "string" || typeof parsed.checksum !== "string") throw new Error("--backup must reference a dataTasks manifest or backup ref.");
|
|
289
|
+
return { runId: parsed.runId, checksum: parsed.checksum, manifestPath: resolved };
|
|
290
|
+
}
|
|
291
|
+
function printHumanResult(action, result) {
|
|
292
|
+
if (!result || typeof result !== "object") {
|
|
293
|
+
console.log(String(result));
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
const record = result;
|
|
297
|
+
console.log(`monSQLize data-task ${action}: ${record.jobName ?? record.taskName ?? "task"}`);
|
|
298
|
+
if (record.passed !== void 0) {
|
|
299
|
+
console.log(`passed: ${String(record.passed)}`);
|
|
300
|
+
}
|
|
301
|
+
if (Array.isArray(record.errors) && record.errors.length > 0) {
|
|
302
|
+
console.log(`errors: ${record.errors.length}`);
|
|
303
|
+
for (const error of record.errors) {
|
|
304
|
+
console.log(`- ${String(error)}`);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (Array.isArray(record.warnings) && record.warnings.length > 0) {
|
|
308
|
+
console.log(`warnings: ${record.warnings.length}`);
|
|
309
|
+
for (const warning of record.warnings) {
|
|
310
|
+
console.log(`- ${String(warning)}`);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
if (Array.isArray(record.results)) {
|
|
314
|
+
console.log(`results: ${record.results.length}`);
|
|
315
|
+
}
|
|
316
|
+
if (Array.isArray(record.collections)) console.log(`collections: ${record.collections.length}`);
|
|
317
|
+
const failures = collectFailures(result).filter((failure) => !failure.startsWith("result:"));
|
|
318
|
+
if (failures.length > 0) {
|
|
319
|
+
console.log(`nested failures: ${failures.length}`);
|
|
320
|
+
for (const failure of failures) console.log(`- ${failure}`);
|
|
321
|
+
}
|
|
322
|
+
if (record.backup && typeof record.backup === "object") {
|
|
323
|
+
const backup = record.backup;
|
|
324
|
+
if (backup.manifestPath) console.log(`backup: ${String(backup.manifestPath)}`);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
async function outputResult(args, action, result) {
|
|
328
|
+
const serialized = `${JSON.stringify(result, null, 2)}
|
|
329
|
+
`;
|
|
330
|
+
if (args.outFile) await (0, import_promises.writeFile)(import_node_path.default.resolve(process.cwd(), args.outFile), serialized, "utf8");
|
|
331
|
+
if (args.json) console.log(serialized.trimEnd());
|
|
332
|
+
else printHumanResult(action, result);
|
|
333
|
+
if (collectFailures(result).length > 0) process.exitCode = 1;
|
|
334
|
+
}
|
|
335
|
+
async function runCli(argv, service) {
|
|
336
|
+
const args = parseArgs(argv);
|
|
337
|
+
if (args.version) {
|
|
338
|
+
console.log(package_default.version);
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
if (args.help || !args.action) {
|
|
342
|
+
console.log(usage());
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (!["preview", "apply", "preview-restore", "restore"].includes(args.action)) {
|
|
346
|
+
throw new Error(`Unknown data-task action: ${String(args.action)}`);
|
|
347
|
+
}
|
|
348
|
+
if (!args.taskFile) {
|
|
349
|
+
throw new Error("--task <file> is required.");
|
|
350
|
+
}
|
|
351
|
+
const loaded = await loadTaskFile(args.taskFile);
|
|
352
|
+
const job = normalizeJobConfig(loaded);
|
|
353
|
+
if (typeof job.source.collection === "function" || typeof job.target.collection === "function") {
|
|
354
|
+
throw new Error("CLI DataTaskJob source and target must be MonSQLizeOptions, not runtime instances.");
|
|
355
|
+
}
|
|
356
|
+
let result;
|
|
357
|
+
if (args.action === "preview") {
|
|
358
|
+
result = await service.preview(job);
|
|
359
|
+
} else if (args.action === "apply") {
|
|
360
|
+
if (!args.approvalFile) throw new Error("apply requires --approval <preview.json>.");
|
|
361
|
+
result = await service.apply(job, { approval: await loadApproval(args.approvalFile) });
|
|
362
|
+
} else {
|
|
363
|
+
if (!args.backupFile) throw new Error(`${args.action} requires --backup <manifest.json>.`);
|
|
364
|
+
const backup = await loadBackupRef(args.backupFile);
|
|
365
|
+
if (args.action === "preview-restore") {
|
|
366
|
+
result = await service.previewRestore(backup, { target: job.target });
|
|
367
|
+
} else {
|
|
368
|
+
if (!args.approvalFile) throw new Error("restore requires --approval <preview.json>.");
|
|
369
|
+
result = await service.restore(backup, { target: job.target, approval: await loadApproval(args.approvalFile) });
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
await outputResult(args, args.action, result);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// src/cli/data-task-bin.ts
|
|
376
|
+
var MonSQLize = require("../index.cjs");
|
|
377
|
+
runCli(process.argv.slice(2), MonSQLize.dataTasks).catch((error) => {
|
|
378
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
379
|
+
process.exitCode = 1;
|
|
380
|
+
});
|