@datarails-ai/dr-appspace-cli 0.12.75 → 0.12.77

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.
Files changed (2) hide show
  1. package/dist/cli.js +170 -36
  2. 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.75",
16
+ version: "0.12.77",
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-09T18:04:05.952Z";
60
+ var BUILD_TIME = "2026-11-09T20:17:25.971Z";
61
61
  function formatBuildTime(iso) {
62
62
  if (iso === "") return "";
63
63
  const d = new Date(iso);
@@ -2845,7 +2845,7 @@ function formatUtc(unix) {
2845
2845
  }
2846
2846
 
2847
2847
  // src/commands/appspace/compile.ts
2848
- import { mkdir as mkdir6, mkdtemp as mkdtemp3, readdir as readdir2, readFile as readFile10, rm as rm4, writeFile as writeFile7 } from "fs/promises";
2848
+ import { mkdir as mkdir6, mkdtemp as mkdtemp3, readdir as readdir3, readFile as readFile10, rm as rm4, writeFile as writeFile7 } from "fs/promises";
2849
2849
  import { tmpdir as tmpdir4 } from "os";
2850
2850
  import { basename, dirname as dirname7, isAbsolute, join as join15, resolve as resolve13, sep as sep4 } from "path";
2851
2851
 
@@ -17241,9 +17241,9 @@ function whereProblems(where2, table, pointer2, who, { platform = false, noColum
17241
17241
  const problems = [];
17242
17242
  const say = (key, message, code = "app_model_mismatch") => problems.push({ code, pointer: pointer2(key), message: `${who} ${message}` });
17243
17243
  for (const key of Object.keys(where2).sort()) {
17244
- const sep7 = key.indexOf("__");
17245
- const column = sep7 < 0 ? key : key.slice(0, sep7);
17246
- const op = sep7 < 0 ? "eq" : key.slice(sep7 + 2);
17244
+ const sep8 = key.indexOf("__");
17245
+ const column = sep8 < 0 ? key : key.slice(0, sep8);
17246
+ const op = sep8 < 0 ? "eq" : key.slice(sep8 + 2);
17247
17247
  const value = where2[key];
17248
17248
  if (!WHERE_OPS.includes(op)) {
17249
17249
  say(key, `filters with "${key}", and "${op}" is no operator a where knows: ${WHERE_OPS.join(", ")}`);
@@ -21521,6 +21521,37 @@ import { join as join6 } from "path";
21521
21521
  // src/commands/appspace/_folder.ts
21522
21522
  import { readFile as readFile3, readdir, stat, writeFile as writeFile2 } from "fs/promises";
21523
21523
  import { join as join5 } from "path";
21524
+
21525
+ // src/commands/appspace/_handlerNames.ts
21526
+ var MAX_HANDLER_NAME_LENGTH = 128;
21527
+ var UNSAFE_CHAR = /[\p{Cc}\p{Cs}\p{Cf}\p{Z}]/u;
21528
+ function handlerNameProblem(name) {
21529
+ if (name === "") return "the name is empty";
21530
+ if ([...name].length > MAX_HANDLER_NAME_LENGTH) {
21531
+ return `the name is longer than ${MAX_HANDLER_NAME_LENGTH} characters`;
21532
+ }
21533
+ if (name.includes("/") || name.includes("\\")) {
21534
+ return "the name contains a path separator ('/' or '\\')";
21535
+ }
21536
+ if (name === "." || name === "..") return "the name is '.' or '..'";
21537
+ if (UNSAFE_CHAR.test(name)) {
21538
+ return "the name contains whitespace, a control character or an invisible format character";
21539
+ }
21540
+ return null;
21541
+ }
21542
+ function handlerFileProblem(file) {
21543
+ const name = file.endsWith(".py") ? file.slice(0, -3) : file;
21544
+ const why = handlerNameProblem(name);
21545
+ if (why === null) return null;
21546
+ const cut3 = [...file].length > 80 ? `${[...file].slice(0, 80).join("")}...` : file;
21547
+ const shown2 = cut3.replace(
21548
+ /[\p{Cc}\p{Cs}\p{Cf}\p{Z}]/gu,
21549
+ (c) => c === " " ? " " : `\\u{${c.codePointAt(0).toString(16)}}`
21550
+ );
21551
+ return `handlers/${shown2}: ${why}. The handler name is the file name without ".py". Rename the file (for example with letters, digits, "_" and "-"), then run the command again. Nothing was sent.`;
21552
+ }
21553
+
21554
+ // src/commands/appspace/_folder.ts
21524
21555
  async function readIfPresent(path3) {
21525
21556
  try {
21526
21557
  return await readFile3(path3, "utf8");
@@ -21599,6 +21630,8 @@ async function readHandlers(handlersDir, state) {
21599
21630
  const handlers = {};
21600
21631
  for (const file of await readDirIfPresent(handlersDir)) {
21601
21632
  if (!file.endsWith(".py")) continue;
21633
+ const refused = handlerFileProblem(file);
21634
+ if (refused !== null) throw new Error(refused);
21602
21635
  const name = file.slice(0, -3);
21603
21636
  const method = recorded?.[name];
21604
21637
  handlers[name] = {
@@ -25053,11 +25086,23 @@ function registerGetCommand(parent) {
25053
25086
  }
25054
25087
 
25055
25088
  // src/commands/appspace/packageCheck.ts
25056
- import { cp, mkdir as mkdir5, mkdtemp as mkdtemp2, rm as rm3, writeFile as writeFile6 } from "fs/promises";
25089
+ import { cp, mkdir as mkdir5, mkdtemp as mkdtemp2, readdir as readdir2, rm as rm3, writeFile as writeFile6 } from "fs/promises";
25057
25090
  import { tmpdir as tmpdir3 } from "os";
25058
25091
  import { dirname as dirname4, join as join11, resolve as resolve5, sep as sep2 } from "path";
25059
25092
  var WHAT = "package";
25060
25093
  async function checkPackage(dir, files, contract, opts, online, pendingMetricKeys = []) {
25094
+ const badName = await handlerNameProblems(dir, files);
25095
+ if (badName.length > 0) {
25096
+ return {
25097
+ problems: badName.map((message) => ({
25098
+ code: "handler-name",
25099
+ pointer: "/",
25100
+ message,
25101
+ fix: "Rename the handler file, then run the check again."
25102
+ })),
25103
+ skipped: []
25104
+ };
25105
+ }
25061
25106
  if (!online) {
25062
25107
  return skip("no -s server to run the push's own checks against; the push is the first to run them");
25063
25108
  }
@@ -25098,6 +25143,24 @@ async function checkPackage(dir, files, contract, opts, online, pendingMetricKey
25098
25143
  await rm3(scratch, { recursive: true, force: true });
25099
25144
  }
25100
25145
  }
25146
+ async function handlerNameProblems(dir, files) {
25147
+ const names = /* @__PURE__ */ new Set();
25148
+ try {
25149
+ for (const file of await readdir2(join11(dir, "handlers"))) names.add(file);
25150
+ } catch {
25151
+ }
25152
+ for (const path3 of Object.keys(files)) {
25153
+ const match = /^handlers\/([^/]+)$/.exec(path3);
25154
+ if (match !== null) names.add(match[1]);
25155
+ }
25156
+ const out = [];
25157
+ for (const file of [...names].sort()) {
25158
+ if (!file.endsWith(".py")) continue;
25159
+ const problem6 = handlerFileProblem(file);
25160
+ if (problem6 !== null) out.push(problem6);
25161
+ }
25162
+ return out;
25163
+ }
25101
25164
  function setAsidePending(check5, pending) {
25102
25165
  if (pending.length === 0) return check5;
25103
25166
  const mentions3 = (message) => pending.some((key) => new RegExp(`metric_bindings\\.${key.replace(/[^a-z0-9_]/g, "")}(?![a-z0-9_])`).test(message));
@@ -34373,7 +34436,7 @@ async function landWithRetries(tryOnce, opts, sleep3 = (ms) => new Promise((done
34373
34436
  async function claimFolder(dir) {
34374
34437
  let names;
34375
34438
  try {
34376
- names = await readdir2(dir);
34439
+ names = await readdir3(dir);
34377
34440
  } catch {
34378
34441
  await mkdir6(dir, { recursive: true });
34379
34442
  names = [];
@@ -34872,8 +34935,8 @@ function registerLogsCommand(parent) {
34872
34935
 
34873
34936
  // src/commands/appspace/migrate.ts
34874
34937
  import { constants } from "fs";
34875
- import { access, lstat as lstat2, readFile as readFile11, rename as rename2, rm as rm5, writeFile as writeFile9 } from "fs/promises";
34876
- import { basename as basename2, dirname as dirname9, join as join17 } from "path";
34938
+ import { access, lstat as lstat2, readFile as readFile11, realpath, rename as rename2, rm as rm5, writeFile as writeFile9 } from "fs/promises";
34939
+ import { basename as basename2, dirname as dirname9, join as join17, sep as sep5 } from "path";
34877
34940
  var MIGRATE_ROUTE = "/apps/migrate-preview";
34878
34941
  var RUNTIMES_NOW = [1];
34879
34942
  var MigrateRefused = class extends Error {
@@ -35313,10 +35376,17 @@ async function runMigrate(dir, opts) {
35313
35376
  const written = [];
35314
35377
  let check5 = null;
35315
35378
  let warnings = [];
35379
+ const interrupt = watchSignals();
35316
35380
  try {
35317
- for (const step of plan) {
35318
- await replaceFile(join17(dir, step.path), step.text);
35319
- written.push(step.path);
35381
+ try {
35382
+ for (const step of plan) {
35383
+ interrupt.check();
35384
+ await replaceFile(join17(dir, step.path), step.text);
35385
+ written.push(step.path);
35386
+ }
35387
+ interrupt.check();
35388
+ } finally {
35389
+ interrupt.stop();
35320
35390
  }
35321
35391
  const compiled = await recordedDigests(dir);
35322
35392
  warnings = written.filter((path3) => Object.prototype.hasOwnProperty.call(compiled, path3)).map(
@@ -35335,20 +35405,30 @@ async function runMigrate(dir, opts) {
35335
35405
  } catch (err) {
35336
35406
  const restored = [];
35337
35407
  const lost = [];
35338
- for (const step of plan.filter((one) => written.includes(one.path)).reverse()) {
35339
- try {
35340
- await replaceFile(join17(dir, step.path), step.old);
35341
- restored.push(step.path);
35342
- } catch {
35343
- lost.push(step.path);
35408
+ const leftovers = err instanceof TemporaryLeft ? [err.temporary] : [];
35409
+ const hold = watchSignals();
35410
+ try {
35411
+ for (const step of plan.filter((one) => written.includes(one.path)).reverse()) {
35412
+ try {
35413
+ await replaceFile(join17(dir, step.path), step.old);
35414
+ restored.push(step.path);
35415
+ } catch (undo) {
35416
+ if (undo instanceof TemporaryLeft) leftovers.push(undo.temporary);
35417
+ lost.push(step.path);
35418
+ }
35344
35419
  }
35420
+ } finally {
35421
+ hold.stop();
35345
35422
  }
35423
+ const stop = err instanceof Interrupted ? err : hold.seen();
35346
35424
  const why = err instanceof Error ? err.message : String(err);
35347
- const said2 = `migrate --write failed (${why}). ` + (restored.length > 0 ? `Put back the old text of: ${restored.join(", ")}. ` : "") + (lost.length > 0 ? `Could NOT put back: ${lost.join(", ")}; these files hold the new text.` : "The folder is as it was.");
35425
+ const many = leftovers.length > 1;
35426
+ const left = `the temporary file${many ? "s" : ""} ${leftovers.join(", ")} ${many ? "are" : "is"} still there: remove ${many ? "them" : "it"} by hand.`;
35427
+ const said2 = (err instanceof Interrupted ? `migrate --write stopped by ${err.signal}. ` : `migrate --write failed (${why}). `) + (restored.length > 0 ? `Put back the old text of: ${restored.join(", ")}. ` : "") + (lost.length > 0 ? `Could NOT put back: ${lost.join(", ")}; these files hold the new text.` + (leftovers.length > 0 ? ` And ${left}` : "") : leftovers.length === 0 ? "The folder is as it was." : `The files are as they were, but ${left}`);
35348
35428
  if (opts.json === true) printJson({ ok: false, error: said2, restored, not_restored: lost });
35349
35429
  process.stderr.write(`${said2}
35350
35430
  `);
35351
- return 1;
35431
+ return stop !== void 0 ? stop.code : 1;
35352
35432
  }
35353
35433
  if (opts.json === true) {
35354
35434
  printJson({
@@ -35383,7 +35463,7 @@ ${written.map((p) => ` ${p}
35383
35463
  return 1;
35384
35464
  }
35385
35465
  }
35386
- var _io = { rename: rename2, writeFile: writeFile9 };
35466
+ var _io = { rename: rename2, writeFile: writeFile9, realpath, rm: rm5 };
35387
35467
  async function writable(dir, path3, sent) {
35388
35468
  const full = join17(dir, path3);
35389
35469
  const parts = path3.split("/");
@@ -35399,6 +35479,11 @@ async function writable(dir, path3, sent) {
35399
35479
  throw new MigrateRefused(`${folder}/ is not a plain folder (a link, or another kind); migrate writes only inside the app folder.`);
35400
35480
  }
35401
35481
  }
35482
+ const root = await _io.realpath(dir);
35483
+ const parent = await _io.realpath(dirname9(full));
35484
+ if (parent !== root && !parent.startsWith(root + sep5)) {
35485
+ throw new MigrateRefused(`${path3} is outside the app folder (a linked folder leads out); migrate writes only inside the app folder.`);
35486
+ }
35402
35487
  let info;
35403
35488
  try {
35404
35489
  info = await lstat2(full);
@@ -35424,16 +35509,65 @@ async function writable(dir, path3, sent) {
35424
35509
  }
35425
35510
  }
35426
35511
  var temporaries = 0;
35512
+ var TemporaryLeft = class extends Error {
35513
+ constructor(temporary, cause) {
35514
+ super(`${cause instanceof Error ? cause.message : String(cause)}; and the temporary file ${temporary} could not be removed`);
35515
+ this.temporary = temporary;
35516
+ }
35517
+ temporary;
35518
+ };
35519
+ var Interrupted = class extends Error {
35520
+ constructor(signal, code) {
35521
+ super(`stopped by ${signal}`);
35522
+ this.signal = signal;
35523
+ this.code = code;
35524
+ }
35525
+ signal;
35526
+ code;
35527
+ };
35528
+ var STOP_SIGNALS = [
35529
+ ["SIGINT", 130],
35530
+ ["SIGTERM", 143]
35531
+ ];
35532
+ function watchSignals() {
35533
+ let seen;
35534
+ const handlers = STOP_SIGNALS.map(([signal, code]) => {
35535
+ const handler = () => {
35536
+ seen ??= new Interrupted(signal, code);
35537
+ };
35538
+ process.on(signal, handler);
35539
+ return [signal, handler];
35540
+ });
35541
+ return {
35542
+ check: () => {
35543
+ if (seen !== void 0) throw seen;
35544
+ },
35545
+ seen: () => seen,
35546
+ stop: () => {
35547
+ for (const [signal, handler] of handlers) process.off(signal, handler);
35548
+ }
35549
+ };
35550
+ }
35551
+ async function dropTemporary(temporary, err) {
35552
+ try {
35553
+ await _io.rm(temporary, { force: true });
35554
+ } catch {
35555
+ throw new TemporaryLeft(temporary, err);
35556
+ }
35557
+ throw err;
35558
+ }
35427
35559
  async function replaceFile(full, text4) {
35428
35560
  temporaries += 1;
35429
35561
  const temporary = join17(dirname9(full), `.${basename2(full)}.migrate-${String(process.pid)}-${String(temporaries)}.tmp`);
35430
35562
  const mode = (await lstat2(full)).mode & 511;
35431
- await _io.writeFile(temporary, text4, { flag: "wx", mode });
35563
+ let ours = false;
35432
35564
  try {
35565
+ await _io.writeFile(temporary, text4, { flag: "wx", mode });
35566
+ ours = true;
35433
35567
  await _io.rename(temporary, full);
35434
35568
  } catch (err) {
35435
- await rm5(temporary, { force: true });
35436
- throw err;
35569
+ if (!ours && err.code === "EEXIST") throw err;
35570
+ return dropTemporary(temporary, err);
35437
35571
  }
35438
35572
  }
35439
35573
  function registerMigrateCommand(parent) {
@@ -35454,8 +35588,8 @@ import { readFile as readFile14 } from "fs/promises";
35454
35588
  import { join as join19, resolve as resolve16 } from "path";
35455
35589
 
35456
35590
  // src/commands/appspace/_files.ts
35457
- import { readFile as readFile12, realpath } from "fs/promises";
35458
- import { basename as basename3, extname, resolve as resolve14, sep as sep5 } from "path";
35591
+ import { readFile as readFile12, realpath as realpath2 } from "fs/promises";
35592
+ import { basename as basename3, extname, resolve as resolve14, sep as sep6 } from "path";
35459
35593
 
35460
35594
  // src/commands/appspace/_samplePdf.ts
35461
35595
  function pdfString(text4) {
@@ -35612,7 +35746,7 @@ function readFailure(path3, full, err) {
35612
35746
  if (code === void 0 || code === "ENOENT") return new Error(`no file at ${path3} (looked for ${full}).`);
35613
35747
  return new Error(`could not read ${path3} (${String(code)}).`);
35614
35748
  }
35615
- async function resolveFile(path3, base, { read = readFile12, confine = false, realpath: real = realpath } = {}) {
35749
+ async function resolveFile(path3, base, { read = readFile12, confine = false, realpath: real = realpath2 } = {}) {
35616
35750
  if (path3 === null) {
35617
35751
  return { bytes: sampleInvoiceBytes(), filename: SAMPLE_INVOICE.filename, mimeType: SAMPLE_INVOICE.mimeType };
35618
35752
  }
@@ -35625,7 +35759,7 @@ async function resolveFile(path3, base, { read = readFile12, confine = false, re
35625
35759
  } catch (err) {
35626
35760
  throw readFailure(path3, full, err);
35627
35761
  }
35628
- if (target !== root && !target.startsWith(root + sep5)) {
35762
+ if (target !== root && !target.startsWith(root + sep6)) {
35629
35763
  throw new Error(`${path3} leads outside the app folder (to ${target}); a fixture's file lives in the folder.`);
35630
35764
  }
35631
35765
  }
@@ -37756,10 +37890,10 @@ async function runUiSmoke(opts) {
37756
37890
  // src/commands/appspace/_screenshot.ts
37757
37891
  import { spawn } from "child_process";
37758
37892
  import { existsSync as existsSync3, statSync as statSync3 } from "fs";
37759
- import { mkdir as mkdir8, mkdtemp as mkdtemp4, readFile as readFile13, readdir as readdir3, rm as rm6, stat as stat2, writeFile as writeFile10 } from "fs/promises";
37893
+ import { mkdir as mkdir8, mkdtemp as mkdtemp4, readFile as readFile13, readdir as readdir4, rm as rm6, stat as stat2, writeFile as writeFile10 } from "fs/promises";
37760
37894
  import { createServer } from "http";
37761
37895
  import { tmpdir as tmpdir5 } from "os";
37762
- import { delimiter, extname as extname2, join as join18, relative as relative3, resolve as resolve15, sep as sep6 } from "path";
37896
+ import { delimiter, extname as extname2, join as join18, relative as relative3, resolve as resolve15, sep as sep7 } from "path";
37763
37897
 
37764
37898
  // ../tests/vendor/fixtures/widgets/kpi.json
37765
37899
  var kpi_default = {
@@ -38953,7 +39087,7 @@ function contentType(path3) {
38953
39087
  function inside(root, rel) {
38954
39088
  const base = resolve15(root);
38955
39089
  const full = resolve15(base, rel);
38956
- return full === base || !full.startsWith(base + sep6) ? null : full;
39090
+ return full === base || !full.startsWith(base + sep7) ? null : full;
38957
39091
  }
38958
39092
  var Shelf = class {
38959
39093
  constructor(source, fetchImpl = fetch) {
@@ -39472,14 +39606,14 @@ async function readLocalUi(dir) {
39472
39606
  const walk5 = async (folder) => {
39473
39607
  let names;
39474
39608
  try {
39475
- names = await readdir3(folder, { withFileTypes: true });
39609
+ names = await readdir4(folder, { withFileTypes: true });
39476
39610
  } catch {
39477
39611
  return;
39478
39612
  }
39479
39613
  for (const one of names) {
39480
39614
  const full = join18(folder, one.name);
39481
39615
  if (one.isDirectory()) await walk5(full);
39482
- else if (one.isFile()) out[relative3(root, full).split(sep6).join("/")] = await readFile13(full);
39616
+ else if (one.isFile()) out[relative3(root, full).split(sep7).join("/")] = await readFile13(full);
39483
39617
  }
39484
39618
  };
39485
39619
  await walk5(root);
@@ -42590,7 +42724,7 @@ function registerPublishCommands(parent) {
42590
42724
  }
42591
42725
 
42592
42726
  // src/commands/appspace/scaffold.ts
42593
- import { mkdir as mkdir9, readdir as readdir4, stat as stat3, writeFile as writeFile11 } from "fs/promises";
42727
+ import { mkdir as mkdir9, readdir as readdir5, stat as stat3, writeFile as writeFile11 } from "fs/promises";
42594
42728
  import { dirname as dirname10, join as join21 } from "path";
42595
42729
 
42596
42730
  // src/commands/appspace/starters.ts
@@ -42928,7 +43062,7 @@ async function checkTarget(dir, force) {
42928
43062
  if (force) return;
42929
43063
  let entries;
42930
43064
  try {
42931
- entries = await readdir4(dir);
43065
+ entries = await readdir5(dir);
42932
43066
  } catch (err) {
42933
43067
  if (err.code === "ENOENT") return;
42934
43068
  throw new Error(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datarails-ai/dr-appspace-cli",
3
- "version": "0.12.75",
3
+ "version": "0.12.77",
4
4
  "description": "Datarails App Space CLI — build, try, push and publish App Space apps",
5
5
  "type": "module",
6
6
  "engines": {