@datarails-ai/dr-appspace-cli 0.12.91 → 0.12.92
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/dist/cli.js +113 -6
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -13,7 +13,7 @@ import { fileURLToPath as fileURLToPath6 } from "url";
|
|
|
13
13
|
// package.json
|
|
14
14
|
var package_default = {
|
|
15
15
|
name: "@datarails-ai/dr-appspace-cli",
|
|
16
|
-
version: "0.12.
|
|
16
|
+
version: "0.12.92",
|
|
17
17
|
description: "Datarails App Space CLI \u2014 build, try, push and publish App Space apps",
|
|
18
18
|
type: "module",
|
|
19
19
|
engines: {
|
|
@@ -57,7 +57,7 @@ var package_default = {
|
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
// src/buildInfo.ts
|
|
60
|
-
var BUILD_TIME = "2026-11-
|
|
60
|
+
var BUILD_TIME = "2026-11-16T16:22:02.840Z";
|
|
61
61
|
function formatBuildTime(iso) {
|
|
62
62
|
if (iso === "") return "";
|
|
63
63
|
const d = new Date(iso);
|
|
@@ -38251,6 +38251,96 @@ function manifestText(raw, merge, before) {
|
|
|
38251
38251
|
);
|
|
38252
38252
|
}
|
|
38253
38253
|
}
|
|
38254
|
+
function drWords(manifest) {
|
|
38255
|
+
const caps = manifest["capabilities"];
|
|
38256
|
+
const dr = isObj5(caps) ? caps["dr"] : void 0;
|
|
38257
|
+
return Array.isArray(dr) ? dr.filter((w) => typeof w === "string") : [];
|
|
38258
|
+
}
|
|
38259
|
+
var CONTRACT_PLACES = ["app", "backend"];
|
|
38260
|
+
function mergeContract(raw, words) {
|
|
38261
|
+
const same5 = { text: raw, added: [], skipped: [] };
|
|
38262
|
+
if (words.length === 0) return same5;
|
|
38263
|
+
const byHand = "add dr to app.capabilities and backend.capabilities by hand";
|
|
38264
|
+
let doc;
|
|
38265
|
+
try {
|
|
38266
|
+
doc = JSON.parse(raw);
|
|
38267
|
+
} catch {
|
|
38268
|
+
return { ...same5, skipped: [`contract.json is not valid JSON; ${byHand}`] };
|
|
38269
|
+
}
|
|
38270
|
+
if (!isObj5(doc)) return { ...same5, skipped: [`contract.json is not an object; ${byHand}`] };
|
|
38271
|
+
if (isObj5(doc["app"]) && doc["app"]["kind"] === "dashboard") {
|
|
38272
|
+
return { ...same5, skipped: ["contract.json is a dashboard contract: the dashboard kit does not take a dr grant, so migrate leaves it as it is"] };
|
|
38273
|
+
}
|
|
38274
|
+
const added = [];
|
|
38275
|
+
const skipped = [];
|
|
38276
|
+
const edits = [];
|
|
38277
|
+
try {
|
|
38278
|
+
const style = styleOf(raw);
|
|
38279
|
+
const root = containerOf(raw, skipSpace(raw, 0));
|
|
38280
|
+
const expected = JSON.parse(raw);
|
|
38281
|
+
for (const place of CONTRACT_PLACES) {
|
|
38282
|
+
const holder = doc[place];
|
|
38283
|
+
if (holder === void 0 && place === "backend") continue;
|
|
38284
|
+
if (!isObj5(holder)) {
|
|
38285
|
+
skipped.push(`contract.json ${place}: it is not an object; ${byHand}`);
|
|
38286
|
+
continue;
|
|
38287
|
+
}
|
|
38288
|
+
const caps = holder["capabilities"];
|
|
38289
|
+
if (caps !== void 0 && !isObj5(caps)) {
|
|
38290
|
+
skipped.push(`contract.json ${place}.capabilities: it is not an object; ${byHand}`);
|
|
38291
|
+
continue;
|
|
38292
|
+
}
|
|
38293
|
+
const dr = isObj5(caps) ? caps["dr"] : void 0;
|
|
38294
|
+
if (dr !== void 0 && !Array.isArray(dr)) {
|
|
38295
|
+
skipped.push(`contract.json ${place}.capabilities.dr: it is not a list; ${byHand}`);
|
|
38296
|
+
continue;
|
|
38297
|
+
}
|
|
38298
|
+
const missing = words.filter((w) => !(dr ?? []).includes(w));
|
|
38299
|
+
if (missing.length === 0) continue;
|
|
38300
|
+
const holderSpan = memberOf(root, place);
|
|
38301
|
+
const holderBox = containerOf(raw, holderSpan.start);
|
|
38302
|
+
const capsSpan = memberOf(holderBox, "capabilities");
|
|
38303
|
+
if (capsSpan === void 0) {
|
|
38304
|
+
const multiline = raw.slice(holderBox.open, holderBox.close).includes("\n");
|
|
38305
|
+
edits.push(insertion(raw, holderBox, [`"capabilities": ${rendered({ dr: missing }, 2, style, multiline)}`], 1, style));
|
|
38306
|
+
} else {
|
|
38307
|
+
const capsBox = containerOf(raw, capsSpan.start);
|
|
38308
|
+
const drSpan = memberOf(capsBox, "dr");
|
|
38309
|
+
if (drSpan === void 0) {
|
|
38310
|
+
const multiline = raw.slice(capsBox.open, capsBox.close).includes("\n");
|
|
38311
|
+
edits.push(insertion(raw, capsBox, [`"dr": ${rendered(missing, 3, style, multiline)}`], 2, style));
|
|
38312
|
+
} else {
|
|
38313
|
+
edits.push(insertion(raw, containerOf(raw, drSpan.start), missing.map((w) => JSON.stringify(w)), 3, style));
|
|
38314
|
+
}
|
|
38315
|
+
}
|
|
38316
|
+
const target = expected[place];
|
|
38317
|
+
const held = isObj5(target["capabilities"]) ? target["capabilities"] : {};
|
|
38318
|
+
target["capabilities"] = { ...held, dr: [...Array.isArray(held["dr"]) ? held["dr"] : [], ...missing] };
|
|
38319
|
+
for (const word of missing) added.push(`contract.json ${place}.capabilities.dr: ${word}`);
|
|
38320
|
+
}
|
|
38321
|
+
if (edits.length === 0) return { ...same5, skipped };
|
|
38322
|
+
let out = raw;
|
|
38323
|
+
for (const edit of [...edits].sort((a, b) => b.at - a.at)) {
|
|
38324
|
+
out = out.slice(0, edit.at) + edit.text + out.slice(edit.at);
|
|
38325
|
+
}
|
|
38326
|
+
if (canonical6(JSON.parse(out)) !== canonical6(expected)) throw new NotJson();
|
|
38327
|
+
return { text: out, added, skipped };
|
|
38328
|
+
} catch (err) {
|
|
38329
|
+
if (!(err instanceof NotJson) && !(err instanceof SyntaxError)) throw err;
|
|
38330
|
+
return { ...same5, skipped: [`migrate could not edit contract.json in its own layout; ${byHand}`] };
|
|
38331
|
+
}
|
|
38332
|
+
}
|
|
38333
|
+
var CONTRACT_POINT = "contract";
|
|
38334
|
+
function contractPoints(merge) {
|
|
38335
|
+
const words = [...new Set(merge.added.map((a) => a.slice(a.lastIndexOf(": ") + 2)))];
|
|
38336
|
+
const places = [...new Set(merge.added.map((a) => a.slice(14, a.indexOf(".", 14))))];
|
|
38337
|
+
return [
|
|
38338
|
+
...merge.added.length === 0 ? [] : [
|
|
38339
|
+
`--write adds dr (${words.join(", ")}) to ${places.map((p) => `${p}.capabilities`).join(" and ")} in contract.json, so the next compile keeps the grant`
|
|
38340
|
+
],
|
|
38341
|
+
...merge.skipped
|
|
38342
|
+
];
|
|
38343
|
+
}
|
|
38254
38344
|
function previewOf(body) {
|
|
38255
38345
|
if (!isObj5(body) || typeof body["diff"] !== "string" || !Array.isArray(body["files"]) || !Array.isArray(body["points"]) || !isObj5(body["manifest"])) {
|
|
38256
38346
|
throw new MigrateRefused("the server answered, but not with a migrate preview.");
|
|
@@ -38315,6 +38405,7 @@ async function runMigrate(dir, opts) {
|
|
|
38315
38405
|
if (canonical6(JSON.parse(manifestSent)) !== canonical6(manifest)) {
|
|
38316
38406
|
throw new MigrateRefused("manifest.json changed while migrate read it. Run migrate again.");
|
|
38317
38407
|
}
|
|
38408
|
+
const contractSent = await readIfPresent(join19(dir, "contract.json"));
|
|
38318
38409
|
const handlers = await readHandlers(join19(dir, "handlers"), await readState(dir));
|
|
38319
38410
|
const lib = await readLib(join19(dir, "lib"));
|
|
38320
38411
|
const sent = {};
|
|
@@ -38332,11 +38423,19 @@ async function runMigrate(dir, opts) {
|
|
|
38332
38423
|
} finally {
|
|
38333
38424
|
client.cleanup();
|
|
38334
38425
|
}
|
|
38426
|
+
const merge = mergeManifest(JSON.parse(manifestSent), preview.manifest);
|
|
38427
|
+
const contractMerge = contractSent === void 0 ? void 0 : mergeContract(contractSent, [.../* @__PURE__ */ new Set([...drWords(merge.manifest), ...drWords(preview.manifest)])]);
|
|
38335
38428
|
if (opts.write !== true) {
|
|
38336
|
-
|
|
38429
|
+
const extra = contractMerge === void 0 ? [] : contractPoints(contractMerge);
|
|
38430
|
+
const shown3 = {
|
|
38431
|
+
...preview,
|
|
38432
|
+
points: [...preview.points, ...extra.map((text4) => ({ kind: CONTRACT_POINT, file: "contract.json", line: null, text: text4 }))],
|
|
38433
|
+
counts: extra.length === 0 ? preview.counts : { ...preview.counts, [CONTRACT_POINT]: extra.length }
|
|
38434
|
+
};
|
|
38435
|
+
if (opts.json === true) printJson({ ...shown3, written: [] });
|
|
38337
38436
|
else {
|
|
38338
|
-
process.stdout.write(renderPreview(
|
|
38339
|
-
if (preview.diff !== "" || Object.keys(preview.manifest).length > 0) {
|
|
38437
|
+
process.stdout.write(renderPreview(shown3));
|
|
38438
|
+
if (preview.diff !== "" || Object.keys(preview.manifest).length > 0 || extra.length > 0) {
|
|
38340
38439
|
process.stdout.write("Dry run: nothing was written. Run again with --write to apply the diff and the manifest additions.\n");
|
|
38341
38440
|
}
|
|
38342
38441
|
}
|
|
@@ -38347,7 +38446,6 @@ async function runMigrate(dir, opts) {
|
|
|
38347
38446
|
if (manifestNow !== manifestSent) {
|
|
38348
38447
|
throw new MigrateRefused("manifest.json changed since migrate read it. Run migrate again.");
|
|
38349
38448
|
}
|
|
38350
|
-
const merge = mergeManifest(JSON.parse(manifestSent), preview.manifest);
|
|
38351
38449
|
const plan = [];
|
|
38352
38450
|
for (const [path3, text4] of Object.entries(files)) {
|
|
38353
38451
|
if (text4 !== sent[path3]) plan.push({ path: path3, old: sent[path3], text: text4 });
|
|
@@ -38359,6 +38457,9 @@ async function runMigrate(dir, opts) {
|
|
|
38359
38457
|
text: manifestText(manifestSent, merge, JSON.parse(manifestSent))
|
|
38360
38458
|
});
|
|
38361
38459
|
}
|
|
38460
|
+
if (contractMerge !== void 0 && contractMerge.added.length > 0) {
|
|
38461
|
+
plan.push({ path: "contract.json", old: contractSent, text: contractMerge.text });
|
|
38462
|
+
}
|
|
38362
38463
|
for (const step of plan) await writable(dir, step.path, step.old);
|
|
38363
38464
|
const written = [];
|
|
38364
38465
|
let check5 = null;
|
|
@@ -38423,6 +38524,8 @@ async function runMigrate(dir, opts) {
|
|
|
38423
38524
|
written,
|
|
38424
38525
|
manifest_added: merge.added,
|
|
38425
38526
|
manifest_skipped: merge.skipped,
|
|
38527
|
+
contract_added: contractMerge?.added ?? [],
|
|
38528
|
+
contract_skipped: contractMerge?.skipped ?? [],
|
|
38426
38529
|
warnings,
|
|
38427
38530
|
check: check5
|
|
38428
38531
|
});
|
|
@@ -38434,8 +38537,12 @@ ${written.map((p) => ` ${p}
|
|
|
38434
38537
|
`).join("")}`
|
|
38435
38538
|
);
|
|
38436
38539
|
for (const line2 of merge.added) process.stdout.write(` added ${line2}
|
|
38540
|
+
`);
|
|
38541
|
+
for (const line2 of contractMerge?.added ?? []) process.stdout.write(` added ${line2}
|
|
38437
38542
|
`);
|
|
38438
38543
|
for (const line2 of merge.skipped) process.stderr.write(`warning: manifest.json ${line2}
|
|
38544
|
+
`);
|
|
38545
|
+
for (const line2 of contractMerge?.skipped ?? []) process.stderr.write(`warning: ${line2}
|
|
38439
38546
|
`);
|
|
38440
38547
|
for (const line2 of warnings) process.stderr.write(`warning: ${line2}
|
|
38441
38548
|
`);
|