@datarails-ai/dr-appspace-cli 0.12.69 → 0.12.71

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 +129 -18
  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.69",
16
+ version: "0.12.71",
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-05T11:53:43.742Z";
60
+ var BUILD_TIME = "2026-11-08T16:13:27.404Z";
61
61
  function formatBuildTime(iso) {
62
62
  if (iso === "") return "";
63
63
  const d = new Date(iso);
@@ -12622,6 +12622,7 @@ var CLOAK_REVEAL_MS = 3e3;
12622
12622
  var CLOAK = `<style data-dr-cloak>main[data-dr-app]{visibility:hidden;animation:dr-reveal 0s linear ${CLOAK_REVEAL_MS}ms forwards}html[data-dr-app-runtime] main[data-dr-app]{visibility:visible;animation:none}main[data-dr-app]:has(>[data-dr-portal]){visibility:visible;animation:none}@keyframes dr-reveal{to{visibility:visible}}</style><noscript><style>main[data-dr-app]{visibility:visible;animation:none}</style></noscript>`;
12623
12623
  var DEFAULT_VERSION = "0.1.0";
12624
12624
  var DEFAULT_API_VERSION = "appspace/v1";
12625
+ var RUNTIME_VERSION = 1;
12625
12626
  var ROLES = ["list", "inbox", "save", "remove", "submit", "decide", "summary", "history", "custom"];
12626
12627
  var ROLE_SET = new Set(ROLES);
12627
12628
  var REQUIRED_KEYS = {
@@ -17485,7 +17486,8 @@ function manifestOf(contract, app, handlers, names, model, served = [], readers
17485
17486
  // empty one too, so the verifier says "blank" and the round trip holds;
17486
17487
  // a contract that states none writes the manifest it always did.
17487
17488
  ...typeof app.description === "string" ? { description: app.description } : {},
17488
- version: app.version ?? DEFAULT_VERSION
17489
+ version: app.version ?? DEFAULT_VERSION,
17490
+ runtime: RUNTIME_VERSION
17489
17491
  };
17490
17492
  if (named5(app.nav_label)) manifest.nav = { label: app.nav_label };
17491
17493
  manifest.routes = routesOf2(app, contract.pages ?? []);
@@ -21581,6 +21583,72 @@ async function readHandlers(handlersDir, state) {
21581
21583
  }
21582
21584
  return handlers;
21583
21585
  }
21586
+ var PYTHON_KEYWORDS = /* @__PURE__ */ new Set([
21587
+ "False",
21588
+ "None",
21589
+ "True",
21590
+ "and",
21591
+ "as",
21592
+ "assert",
21593
+ "async",
21594
+ "await",
21595
+ "break",
21596
+ "class",
21597
+ "continue",
21598
+ "def",
21599
+ "del",
21600
+ "elif",
21601
+ "else",
21602
+ "except",
21603
+ "finally",
21604
+ "for",
21605
+ "from",
21606
+ "global",
21607
+ "if",
21608
+ "import",
21609
+ "in",
21610
+ "is",
21611
+ "lambda",
21612
+ "nonlocal",
21613
+ "not",
21614
+ "or",
21615
+ "pass",
21616
+ "raise",
21617
+ "return",
21618
+ "try",
21619
+ "while",
21620
+ "with",
21621
+ "yield"
21622
+ ]);
21623
+ function libNameProblem(name) {
21624
+ if (name.length > 64) return "is longer than 64 characters";
21625
+ if (!/^[a-z_][a-z0-9_]*$/.test(name)) return "must match [a-z_][a-z0-9_]*";
21626
+ if (name.startsWith("__")) return 'must not start with "__"';
21627
+ if (name === "lib") return 'must not be "lib"';
21628
+ if (PYTHON_KEYWORDS.has(name)) return "is a Python keyword";
21629
+ return null;
21630
+ }
21631
+ async function readLib(libDir) {
21632
+ const lib = {};
21633
+ for (const file of (await readDirIfPresent(libDir)).sort()) {
21634
+ if (!file.endsWith(".py")) continue;
21635
+ const full = join5(libDir, file);
21636
+ try {
21637
+ if (!(await stat(full)).isFile()) continue;
21638
+ } catch {
21639
+ continue;
21640
+ }
21641
+ const name = file.slice(0, -3);
21642
+ const problem6 = libNameProblem(name);
21643
+ if (problem6 !== null) {
21644
+ process.stderr.write(`warning: lib/${file} was not sent: the module name "${name}" ${problem6}.
21645
+ `);
21646
+ continue;
21647
+ }
21648
+ lib[name] = await readFile3(full, "utf8");
21649
+ }
21650
+ return lib;
21651
+ }
21584
21652
  async function recordRevision(dir, revision, stage2, handlers, identity = {}) {
21585
21653
  const statePath = join5(dir, ".appspace.json");
21586
21654
  const state = { ...await readState(dir) };
@@ -21895,6 +21963,7 @@ async function runLiveness(dir, appId, whole, client, only) {
21895
21963
  `${handler.file} is not in this folder, so no handler was run`
21896
21964
  );
21897
21965
  }
21966
+ const lib = await readLib(join7(dir, "lib"));
21898
21967
  const groups = pagesToLoad(whole, only);
21899
21968
  const merged = {};
21900
21969
  const violations = /* @__PURE__ */ new Map();
@@ -21932,7 +22001,7 @@ async function runLiveness(dir, appId, whole, client, only) {
21932
22001
  `/apps/${encodeURIComponent(appId)}/dry-run`,
21933
22002
  {
21934
22003
  method: "POST",
21935
- body: { code, payload }
22004
+ body: { code, payload, ...Object.keys(lib).length > 0 ? { lib } : {} }
21936
22005
  }
21937
22006
  );
21938
22007
  } catch (err) {
@@ -24370,6 +24439,7 @@ async function pushBody(dir, opts) {
24370
24439
  const modelRaw = await readIfPresent(join8(dir, "data_model.json"));
24371
24440
  const handlers = await readHandlers(join8(dir, "handlers"), state);
24372
24441
  const uiFiles = await readUiTree(join8(dir, "ui"));
24442
+ const lib = await readLib(join8(dir, "lib"));
24373
24443
  for (const line2 of chartsWithoutEcharts(uiFiles)) process.stderr.write(`warning: ${line2}
24374
24444
  `);
24375
24445
  const ui = bundleUi(uiFiles);
@@ -24385,6 +24455,7 @@ async function pushBody(dir, opts) {
24385
24455
  if (ui?.field === "frontend_bundle_gz") {
24386
24456
  body["frontend_bundle_gz"] = ui.files;
24387
24457
  }
24458
+ if (Object.keys(lib).length > 0) body["lib"] = lib;
24388
24459
  const connectTables = manifest["connect_tables"];
24389
24460
  if (typeof connectTables === "object" && connectTables !== null && !Array.isArray(connectTables)) {
24390
24461
  if (Object.keys(connectTables).length > 0) body["connect_tables"] = connectTables;
@@ -24532,7 +24603,7 @@ async function pushFolder(dir, opts) {
24532
24603
  }
24533
24604
 
24534
24605
  // src/commands/appspace/get.ts
24535
- import { mkdtemp, mkdir as mkdir4, readFile as readFile9, rm as rm2, writeFile as writeFile5 } from "fs/promises";
24606
+ import { lstat, mkdtemp, mkdir as mkdir4, readFile as readFile9, rm as rm2, writeFile as writeFile5 } from "fs/promises";
24536
24607
  import { tmpdir as tmpdir2 } from "os";
24537
24608
  import { dirname as dirname3, join as join10 } from "path";
24538
24609
 
@@ -24627,6 +24698,10 @@ async function recordAsInput(dir, path3) {
24627
24698
  }
24628
24699
 
24629
24700
  // src/commands/appspace/get.ts
24701
+ function headline(appId, pkg) {
24702
+ const runtime = pkg.runtime === void 0 ? "" : `, runtime ${pkg.runtime}`;
24703
+ return `${appId} (${pkg.stage}, revision ${pkg.revision}${runtime})`;
24704
+ }
24630
24705
  function requirePlainName(kind, name, verb = "write") {
24631
24706
  if (name === "" || name === "." || name === ".." || /[\\/]/.test(name)) {
24632
24707
  throw new Error(
@@ -24642,14 +24717,14 @@ function requireBundlePath(name) {
24642
24717
  return name;
24643
24718
  }
24644
24719
  async function unpushedInputs(dir, pkg) {
24720
+ const out = await unpushedLib(dir, pkg);
24645
24721
  let inputs = [];
24646
24722
  try {
24647
24723
  const parsed2 = JSON.parse(await readFile9(reportPath(dir), "utf8"));
24648
24724
  if (Array.isArray(parsed2.inputs)) inputs = parsed2.inputs.map(String);
24649
24725
  } catch {
24650
- return [];
24726
+ return out;
24651
24727
  }
24652
- const out = [];
24653
24728
  for (const path3 of inputs.sort()) {
24654
24729
  let remote;
24655
24730
  if (path3.startsWith("handlers/") && path3.endsWith(".py")) {
@@ -24664,6 +24739,18 @@ async function unpushedInputs(dir, pkg) {
24664
24739
  }
24665
24740
  return out;
24666
24741
  }
24742
+ async function unpushedLib(dir, pkg) {
24743
+ const remote = pkg.lib;
24744
+ if (typeof remote !== "object" || remote === null || Array.isArray(remote)) return [];
24745
+ const out = [];
24746
+ const libDir = join10(dir, "lib");
24747
+ for (const file of (await readDirIfPresent(libDir)).sort()) {
24748
+ if (!file.endsWith(".py")) continue;
24749
+ const local = await readIfPresent(join10(libDir, file));
24750
+ if (local !== void 0 && local !== remote[file.slice(0, -".py".length)]) out.push(`lib/${file}`);
24751
+ }
24752
+ return out;
24753
+ }
24667
24754
  async function writePackage(dir, appId, pkg) {
24668
24755
  await mkdir4(dir, { recursive: true });
24669
24756
  await Promise.all([
@@ -24697,6 +24784,24 @@ async function writePackage(dir, appId, pkg) {
24697
24784
  }
24698
24785
  }
24699
24786
  }
24787
+ if (typeof pkg.lib === "object" && pkg.lib !== null && !Array.isArray(pkg.lib)) {
24788
+ const libDir = join10(dir, "lib");
24789
+ const linked = await lstat(libDir).then((st) => st.isSymbolicLink(), () => false);
24790
+ if (linked) throw new Error(`refusing to write lib modules: ${libDir} is a symbolic link.`);
24791
+ for (const name of Object.keys(pkg.lib)) {
24792
+ const problem6 = libNameProblem(name);
24793
+ if (problem6 !== null) {
24794
+ throw new Error(`refusing to write a lib module named ${JSON.stringify(name)}: it ${problem6}.`);
24795
+ }
24796
+ }
24797
+ for (const file of await readDirIfPresent(libDir)) {
24798
+ if (file.endsWith(".py")) await rm2(join10(libDir, file), { force: true });
24799
+ }
24800
+ for (const [name, code] of Object.entries(pkg.lib)) {
24801
+ await mkdir4(libDir, { recursive: true });
24802
+ await writeFile5(join10(libDir, `${name}.py`), code);
24803
+ }
24804
+ }
24700
24805
  const ui = Object.entries(pkg.frontend_bundle ?? {});
24701
24806
  if (ui.length > 0) {
24702
24807
  await mkdir4(join10(dir, "ui"), { recursive: true });
@@ -24860,7 +24965,7 @@ async function runGet(appId, opts) {
24860
24965
  if (unpushed.length > 0) {
24861
24966
  const them = unpushed.length === 1 ? "it" : "them";
24862
24967
  process.stderr.write(
24863
- `${dir} holds ${unpushed.join(", ")}, which the compile record lists as yours and the pushed package does not hold as written: get replaces handlers/ and ui/, and would lose ${them}. Push first (app-space push), or pass --force to discard your copy. Nothing was written.
24968
+ `${dir} holds ${unpushed.join(", ")}, which are yours and which the pushed package does not hold as written: get replaces handlers/, ui/ and the modules in lib/, and would lose ${them}. Push first (app-space push), or pass --force to discard your copy. Nothing was written.
24864
24969
  `
24865
24970
  );
24866
24971
  return 1;
@@ -24870,10 +24975,10 @@ async function runGet(appId, opts) {
24870
24975
  const restored = await restoreOwnedFiles(dir, contract, { force: opts.force === true });
24871
24976
  await recordPulled(dir, contract);
24872
24977
  if (opts.json === true) {
24873
- printJson({ id: appId, dir, revision: pkg.revision, stage: pkg.stage, contract, owned: restored.wrote, kept: restored.kept });
24978
+ printJson({ id: appId, dir, revision: pkg.revision, stage: pkg.stage, runtime: pkg.runtime, contract, owned: restored.wrote, kept: restored.kept });
24874
24979
  return 0;
24875
24980
  }
24876
- process.stdout.write(`${appId} (${pkg.stage}, revision ${pkg.revision})
24981
+ process.stdout.write(`${headline(appId, pkg)}
24877
24982
  `);
24878
24983
  process.stdout.write(`${dir}
24879
24984
  `);
@@ -25437,10 +25542,10 @@ var RUNTIME_LIBRARIES = [
25437
25542
  }
25438
25543
  ];
25439
25544
  var MIN_DASHBOARD_RUNTIME = "1.13.0";
25440
- var RUNTIME_VERSION = /^vendor\/dr-app-runtime@(\d+\.\d+\.\d+)\/runtime\.js$/;
25545
+ var RUNTIME_VERSION2 = /^vendor\/dr-app-runtime@(\d+\.\d+\.\d+)\/runtime\.js$/;
25441
25546
  function runtimeBelowMinimum(page) {
25442
25547
  const { elements } = parseHtml(page.text);
25443
- return elements.filter((el) => el.tag === "script" && el.attrs.src !== void 0).map((el) => RUNTIME_VERSION.exec(resolveFromPlatformRoot(page.path, el.attrs.src) ?? "")?.[1]).filter((version) => version !== void 0 && compareVersions(version, MIN_DASHBOARD_RUNTIME) < 0);
25548
+ return elements.filter((el) => el.tag === "script" && el.attrs.src !== void 0).map((el) => RUNTIME_VERSION2.exec(resolveFromPlatformRoot(page.path, el.attrs.src) ?? "")?.[1]).filter((version) => version !== void 0 && compareVersions(version, MIN_DASHBOARD_RUNTIME) < 0);
25444
25549
  }
25445
25550
  function compareVersions(a, b) {
25446
25551
  const left = a.split(".").map(Number);
@@ -33592,7 +33697,7 @@ async function loadContract(dir, opts) {
33592
33697
  }
33593
33698
  const app = assembled.contract["app"];
33594
33699
  record2.name = typeof app["name"] === "string" ? app["name"] : null;
33595
- const headline = resolveExpectations(opts.expect, assembled.contract, assembled.widgetIds);
33700
+ const headline2 = resolveExpectations(opts.expect, assembled.contract, assembled.widgetIds);
33596
33701
  const overlay = {};
33597
33702
  for (const [path3, text4] of Object.entries(assembled.transforms)) {
33598
33703
  if (!insideFolder(dir, path3)) throw new Error(`refusing to write the transform ${JSON.stringify(path3)} outside ${dir}.`);
@@ -33616,7 +33721,7 @@ async function loadContract(dir, opts) {
33616
33721
  `).join("")
33617
33722
  );
33618
33723
  }
33619
- return { contract: assembled.contract, assemble: record2, headline, overlay };
33724
+ return { contract: assembled.contract, assemble: record2, headline: headline2, overlay };
33620
33725
  }
33621
33726
  function pageDrafts(named13) {
33622
33727
  const doc = named13.doc;
@@ -34126,7 +34231,7 @@ function ontoLiveBackoff(attempt, random = Math.random) {
34126
34231
  return Math.floor(random() * ceiling);
34127
34232
  }
34128
34233
  var ONTO_LIVE_MARK = ".onto-live";
34129
- var ONTO_LIVE_OWNED = ["contract.json", "manifest.json", "data_model.json", "handlers", "ui", "transforms", ".appspace.json", ".appspace"];
34234
+ var ONTO_LIVE_OWNED = ["contract.json", "manifest.json", "data_model.json", "handlers", "lib", "ui", "transforms", ".appspace.json", ".appspace"];
34130
34235
  async function runShipOntoLive(dir, opts) {
34131
34236
  const appId = opts.appId;
34132
34237
  const refuse2 = (why) => {
@@ -34626,6 +34731,10 @@ function registerEjectCommand(parent) {
34626
34731
  }
34627
34732
 
34628
34733
  // src/commands/appspace/list.ts
34734
+ function formatListLine(a) {
34735
+ const runtime = a.runtime === void 0 ? "-" : `r${a.runtime}`;
34736
+ return `${a.stage.padEnd(9)} ${runtime.padEnd(4)} ${a.id.padEnd(24)} ${a.name}`;
34737
+ }
34629
34738
  function registerListCommand(parent) {
34630
34739
  withJsonOption(
34631
34740
  withServerOptions(
@@ -34648,7 +34757,7 @@ function registerListCommand(parent) {
34648
34757
  return;
34649
34758
  }
34650
34759
  for (const a of apps) {
34651
- process.stdout.write(`${a.stage.padEnd(9)} ${a.id.padEnd(24)} ${a.name}
34760
+ process.stdout.write(`${formatListLine(a)}
34652
34761
  `);
34653
34762
  }
34654
34763
  } finally {
@@ -40623,6 +40732,7 @@ async function loadFixtures(dir, explicit) {
40623
40732
  }
40624
40733
  async function runHandlerCases(cases, dir, appId, client, roleOf = () => void 0) {
40625
40734
  const code = /* @__PURE__ */ new Map();
40735
+ const lib = await readLib(join18(dir, "lib"));
40626
40736
  const outcomes = [];
40627
40737
  for (const kase of cases) {
40628
40738
  requirePlainName("handler", kase.handler, "read");
@@ -40682,7 +40792,7 @@ async function runHandlerCases(cases, dir, appId, client, roleOf = () => void 0)
40682
40792
  try {
40683
40793
  res = await client.request(`/apps/${encodeURIComponent(appId)}/dry-run`, {
40684
40794
  method: "POST",
40685
- body: { code: source, payload },
40795
+ body: { code: source, payload, ...Object.keys(lib).length > 0 ? { lib } : {} },
40686
40796
  ...asRole === void 0 ? {} : { headers: { [PREVIEW_ROLE_HEADER]: asRole } }
40687
40797
  });
40688
40798
  } catch (err) {
@@ -41739,6 +41849,7 @@ function registerTryCommand(parent) {
41739
41849
  `no handlers/${handler}.py in ${opts.dir} \u2014 is this an app folder?`
41740
41850
  );
41741
41851
  });
41852
+ const lib = await readLib(join19(opts.dir, "lib"));
41742
41853
  let payload = await readPayloadOption(opts.payload ?? "{}");
41743
41854
  const files = parseFileSpecs(opts.file ?? []);
41744
41855
  const withFiles = payloadForFiles(payload, files);
@@ -41779,7 +41890,7 @@ function registerTryCommand(parent) {
41779
41890
  const fileFields = attached.length === 0 ? {} : { files: attached };
41780
41891
  const res = await client.request(`/apps/${encodeURIComponent(appId)}/dry-run`, {
41781
41892
  method: "POST",
41782
- body: { code, payload },
41893
+ body: { code, payload, ...Object.keys(lib).length > 0 ? { lib } : {} },
41783
41894
  ...asRole === void 0 ? {} : { headers: { [PREVIEW_ROLE_HEADER]: asRole } }
41784
41895
  });
41785
41896
  if (opts.json === true) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datarails-ai/dr-appspace-cli",
3
- "version": "0.12.69",
3
+ "version": "0.12.71",
4
4
  "description": "Datarails App Space CLI — build, try, push and publish App Space apps",
5
5
  "type": "module",
6
6
  "engines": {