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

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 +111 -10
  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.70",
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-06T08:12:14.679Z";
61
61
  function formatBuildTime(iso) {
62
62
  if (iso === "") return "";
63
63
  const d = new Date(iso);
@@ -21581,6 +21581,72 @@ async function readHandlers(handlersDir, state) {
21581
21581
  }
21582
21582
  return handlers;
21583
21583
  }
21584
+ var PYTHON_KEYWORDS = /* @__PURE__ */ new Set([
21585
+ "False",
21586
+ "None",
21587
+ "True",
21588
+ "and",
21589
+ "as",
21590
+ "assert",
21591
+ "async",
21592
+ "await",
21593
+ "break",
21594
+ "class",
21595
+ "continue",
21596
+ "def",
21597
+ "del",
21598
+ "elif",
21599
+ "else",
21600
+ "except",
21601
+ "finally",
21602
+ "for",
21603
+ "from",
21604
+ "global",
21605
+ "if",
21606
+ "import",
21607
+ "in",
21608
+ "is",
21609
+ "lambda",
21610
+ "nonlocal",
21611
+ "not",
21612
+ "or",
21613
+ "pass",
21614
+ "raise",
21615
+ "return",
21616
+ "try",
21617
+ "while",
21618
+ "with",
21619
+ "yield"
21620
+ ]);
21621
+ function libNameProblem(name) {
21622
+ if (name.length > 64) return "is longer than 64 characters";
21623
+ if (!/^[a-z_][a-z0-9_]*$/.test(name)) return "must match [a-z_][a-z0-9_]*";
21624
+ if (name.startsWith("__")) return 'must not start with "__"';
21625
+ if (name === "lib") return 'must not be "lib"';
21626
+ if (PYTHON_KEYWORDS.has(name)) return "is a Python keyword";
21627
+ return null;
21628
+ }
21629
+ async function readLib(libDir) {
21630
+ const lib = {};
21631
+ for (const file of (await readDirIfPresent(libDir)).sort()) {
21632
+ if (!file.endsWith(".py")) continue;
21633
+ const full = join5(libDir, file);
21634
+ try {
21635
+ if (!(await stat(full)).isFile()) continue;
21636
+ } catch {
21637
+ continue;
21638
+ }
21639
+ const name = file.slice(0, -3);
21640
+ const problem6 = libNameProblem(name);
21641
+ if (problem6 !== null) {
21642
+ process.stderr.write(`warning: lib/${file} was not sent: the module name "${name}" ${problem6}.
21643
+ `);
21644
+ continue;
21645
+ }
21646
+ lib[name] = await readFile3(full, "utf8");
21647
+ }
21648
+ return lib;
21649
+ }
21584
21650
  async function recordRevision(dir, revision, stage2, handlers, identity = {}) {
21585
21651
  const statePath = join5(dir, ".appspace.json");
21586
21652
  const state = { ...await readState(dir) };
@@ -21895,6 +21961,7 @@ async function runLiveness(dir, appId, whole, client, only) {
21895
21961
  `${handler.file} is not in this folder, so no handler was run`
21896
21962
  );
21897
21963
  }
21964
+ const lib = await readLib(join7(dir, "lib"));
21898
21965
  const groups = pagesToLoad(whole, only);
21899
21966
  const merged = {};
21900
21967
  const violations = /* @__PURE__ */ new Map();
@@ -21932,7 +21999,7 @@ async function runLiveness(dir, appId, whole, client, only) {
21932
21999
  `/apps/${encodeURIComponent(appId)}/dry-run`,
21933
22000
  {
21934
22001
  method: "POST",
21935
- body: { code, payload }
22002
+ body: { code, payload, ...Object.keys(lib).length > 0 ? { lib } : {} }
21936
22003
  }
21937
22004
  );
21938
22005
  } catch (err) {
@@ -24370,6 +24437,7 @@ async function pushBody(dir, opts) {
24370
24437
  const modelRaw = await readIfPresent(join8(dir, "data_model.json"));
24371
24438
  const handlers = await readHandlers(join8(dir, "handlers"), state);
24372
24439
  const uiFiles = await readUiTree(join8(dir, "ui"));
24440
+ const lib = await readLib(join8(dir, "lib"));
24373
24441
  for (const line2 of chartsWithoutEcharts(uiFiles)) process.stderr.write(`warning: ${line2}
24374
24442
  `);
24375
24443
  const ui = bundleUi(uiFiles);
@@ -24385,6 +24453,7 @@ async function pushBody(dir, opts) {
24385
24453
  if (ui?.field === "frontend_bundle_gz") {
24386
24454
  body["frontend_bundle_gz"] = ui.files;
24387
24455
  }
24456
+ if (Object.keys(lib).length > 0) body["lib"] = lib;
24388
24457
  const connectTables = manifest["connect_tables"];
24389
24458
  if (typeof connectTables === "object" && connectTables !== null && !Array.isArray(connectTables)) {
24390
24459
  if (Object.keys(connectTables).length > 0) body["connect_tables"] = connectTables;
@@ -24532,7 +24601,7 @@ async function pushFolder(dir, opts) {
24532
24601
  }
24533
24602
 
24534
24603
  // src/commands/appspace/get.ts
24535
- import { mkdtemp, mkdir as mkdir4, readFile as readFile9, rm as rm2, writeFile as writeFile5 } from "fs/promises";
24604
+ import { lstat, mkdtemp, mkdir as mkdir4, readFile as readFile9, rm as rm2, writeFile as writeFile5 } from "fs/promises";
24536
24605
  import { tmpdir as tmpdir2 } from "os";
24537
24606
  import { dirname as dirname3, join as join10 } from "path";
24538
24607
 
@@ -24642,14 +24711,14 @@ function requireBundlePath(name) {
24642
24711
  return name;
24643
24712
  }
24644
24713
  async function unpushedInputs(dir, pkg) {
24714
+ const out = await unpushedLib(dir, pkg);
24645
24715
  let inputs = [];
24646
24716
  try {
24647
24717
  const parsed2 = JSON.parse(await readFile9(reportPath(dir), "utf8"));
24648
24718
  if (Array.isArray(parsed2.inputs)) inputs = parsed2.inputs.map(String);
24649
24719
  } catch {
24650
- return [];
24720
+ return out;
24651
24721
  }
24652
- const out = [];
24653
24722
  for (const path3 of inputs.sort()) {
24654
24723
  let remote;
24655
24724
  if (path3.startsWith("handlers/") && path3.endsWith(".py")) {
@@ -24664,6 +24733,18 @@ async function unpushedInputs(dir, pkg) {
24664
24733
  }
24665
24734
  return out;
24666
24735
  }
24736
+ async function unpushedLib(dir, pkg) {
24737
+ const remote = pkg.lib;
24738
+ if (typeof remote !== "object" || remote === null || Array.isArray(remote)) return [];
24739
+ const out = [];
24740
+ const libDir = join10(dir, "lib");
24741
+ for (const file of (await readDirIfPresent(libDir)).sort()) {
24742
+ if (!file.endsWith(".py")) continue;
24743
+ const local = await readIfPresent(join10(libDir, file));
24744
+ if (local !== void 0 && local !== remote[file.slice(0, -".py".length)]) out.push(`lib/${file}`);
24745
+ }
24746
+ return out;
24747
+ }
24667
24748
  async function writePackage(dir, appId, pkg) {
24668
24749
  await mkdir4(dir, { recursive: true });
24669
24750
  await Promise.all([
@@ -24697,6 +24778,24 @@ async function writePackage(dir, appId, pkg) {
24697
24778
  }
24698
24779
  }
24699
24780
  }
24781
+ if (typeof pkg.lib === "object" && pkg.lib !== null && !Array.isArray(pkg.lib)) {
24782
+ const libDir = join10(dir, "lib");
24783
+ const linked = await lstat(libDir).then((st) => st.isSymbolicLink(), () => false);
24784
+ if (linked) throw new Error(`refusing to write lib modules: ${libDir} is a symbolic link.`);
24785
+ for (const name of Object.keys(pkg.lib)) {
24786
+ const problem6 = libNameProblem(name);
24787
+ if (problem6 !== null) {
24788
+ throw new Error(`refusing to write a lib module named ${JSON.stringify(name)}: it ${problem6}.`);
24789
+ }
24790
+ }
24791
+ for (const file of await readDirIfPresent(libDir)) {
24792
+ if (file.endsWith(".py")) await rm2(join10(libDir, file), { force: true });
24793
+ }
24794
+ for (const [name, code] of Object.entries(pkg.lib)) {
24795
+ await mkdir4(libDir, { recursive: true });
24796
+ await writeFile5(join10(libDir, `${name}.py`), code);
24797
+ }
24798
+ }
24700
24799
  const ui = Object.entries(pkg.frontend_bundle ?? {});
24701
24800
  if (ui.length > 0) {
24702
24801
  await mkdir4(join10(dir, "ui"), { recursive: true });
@@ -24860,7 +24959,7 @@ async function runGet(appId, opts) {
24860
24959
  if (unpushed.length > 0) {
24861
24960
  const them = unpushed.length === 1 ? "it" : "them";
24862
24961
  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.
24962
+ `${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
24963
  `
24865
24964
  );
24866
24965
  return 1;
@@ -34126,7 +34225,7 @@ function ontoLiveBackoff(attempt, random = Math.random) {
34126
34225
  return Math.floor(random() * ceiling);
34127
34226
  }
34128
34227
  var ONTO_LIVE_MARK = ".onto-live";
34129
- var ONTO_LIVE_OWNED = ["contract.json", "manifest.json", "data_model.json", "handlers", "ui", "transforms", ".appspace.json", ".appspace"];
34228
+ var ONTO_LIVE_OWNED = ["contract.json", "manifest.json", "data_model.json", "handlers", "lib", "ui", "transforms", ".appspace.json", ".appspace"];
34130
34229
  async function runShipOntoLive(dir, opts) {
34131
34230
  const appId = opts.appId;
34132
34231
  const refuse2 = (why) => {
@@ -40623,6 +40722,7 @@ async function loadFixtures(dir, explicit) {
40623
40722
  }
40624
40723
  async function runHandlerCases(cases, dir, appId, client, roleOf = () => void 0) {
40625
40724
  const code = /* @__PURE__ */ new Map();
40725
+ const lib = await readLib(join18(dir, "lib"));
40626
40726
  const outcomes = [];
40627
40727
  for (const kase of cases) {
40628
40728
  requirePlainName("handler", kase.handler, "read");
@@ -40682,7 +40782,7 @@ async function runHandlerCases(cases, dir, appId, client, roleOf = () => void 0)
40682
40782
  try {
40683
40783
  res = await client.request(`/apps/${encodeURIComponent(appId)}/dry-run`, {
40684
40784
  method: "POST",
40685
- body: { code: source, payload },
40785
+ body: { code: source, payload, ...Object.keys(lib).length > 0 ? { lib } : {} },
40686
40786
  ...asRole === void 0 ? {} : { headers: { [PREVIEW_ROLE_HEADER]: asRole } }
40687
40787
  });
40688
40788
  } catch (err) {
@@ -41739,6 +41839,7 @@ function registerTryCommand(parent) {
41739
41839
  `no handlers/${handler}.py in ${opts.dir} \u2014 is this an app folder?`
41740
41840
  );
41741
41841
  });
41842
+ const lib = await readLib(join19(opts.dir, "lib"));
41742
41843
  let payload = await readPayloadOption(opts.payload ?? "{}");
41743
41844
  const files = parseFileSpecs(opts.file ?? []);
41744
41845
  const withFiles = payloadForFiles(payload, files);
@@ -41779,7 +41880,7 @@ function registerTryCommand(parent) {
41779
41880
  const fileFields = attached.length === 0 ? {} : { files: attached };
41780
41881
  const res = await client.request(`/apps/${encodeURIComponent(appId)}/dry-run`, {
41781
41882
  method: "POST",
41782
- body: { code, payload },
41883
+ body: { code, payload, ...Object.keys(lib).length > 0 ? { lib } : {} },
41783
41884
  ...asRole === void 0 ? {} : { headers: { [PREVIEW_ROLE_HEADER]: asRole } }
41784
41885
  });
41785
41886
  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.70",
4
4
  "description": "Datarails App Space CLI — build, try, push and publish App Space apps",
5
5
  "type": "module",
6
6
  "engines": {