@datarails-ai/dr-appspace-cli 0.12.76 → 0.12.78

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 +110 -12
  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.76",
16
+ version: "0.12.78",
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-09T19:41:45.642Z";
60
+ var BUILD_TIME = "2026-11-10T10:24:32.742Z";
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
 
@@ -10753,7 +10753,7 @@ function compile(contract, { kit, extra = {} } = {}) {
10753
10753
  for (const page of pages) {
10754
10754
  files[page.path] = pageFile(page, { contract: composed, pages, kit, problems });
10755
10755
  }
10756
- return { files, problems: problems.sort(byProblem2), warnings: narrativeOrderWarnings(composed, applied) };
10756
+ return { files, problems: problems.sort(byProblem2), warnings: [...narrativeOrderWarnings(composed, applied), ...undeclaredTableWarnings(composed)] };
10757
10757
  }
10758
10758
  var RUNTIME_RENDERER2 = "runtime";
10759
10759
  function dashboardHandler(composed, handlerName, extra = {}) {
@@ -10882,6 +10882,8 @@ function manifestFile(contract, handlerName) {
10882
10882
  handlers: { [handlerName]: { entrypoint: handlerPath(contract, handlerName), http: handlerHttp(contract, handlerName) } },
10883
10883
  capabilities: isPlainObject6(app.capabilities) ? app.capabilities : { ...DEFAULT_CAPABILITIES }
10884
10884
  };
10885
+ const { tables } = readTables(contract);
10886
+ if (tables.length > 0) manifest.sources = { tables };
10885
10887
  return `${JSON.stringify(manifest, null, 2)}
10886
10888
  `;
10887
10889
  }
@@ -11348,7 +11350,7 @@ function compileDashboard(contract, { kit = null, extra = {}, uiKit, charts, fmt
11348
11350
  files[handlerPath(composed, handlerName)] = handler.text;
11349
11351
  const shelf2 = { runtime: DASHBOARD_RUNTIME, widgets: DASHBOARD_WIDGETS, bar: DASHBOARD_BAR, assistant, markdown, uiKit, charts, fmt, appComponents, appControls };
11350
11352
  for (const page of whole.pages) files[page.path] = pageHtml(whole, page, elements, tree, shelf2);
11351
- return { files, problems, contract: whole, order: order2, warnings: [...warnings, ...narrativeOrderWarnings(composed, applied)] };
11353
+ return { files, problems, contract: whole, order: order2, warnings: [...warnings, ...narrativeOrderWarnings(composed, applied), ...undeclaredTableWarnings(composed)] };
11352
11354
  }
11353
11355
  function isRefusal(problem6) {
11354
11356
  return problem6.lossy !== false;
@@ -12917,6 +12919,37 @@ function sourcesOf(contract) {
12917
12919
  function readsMetric(read) {
12918
12920
  return isPlainObject8(read) && (read.metric_id !== void 0 && read.metric_id !== null || read.metric !== void 0 && read.metric !== null);
12919
12921
  }
12922
+ function readTables(contract) {
12923
+ const tables = [];
12924
+ const aliased = [];
12925
+ const walk5 = (node, pointer2) => {
12926
+ if (Array.isArray(node)) {
12927
+ node.forEach((one, index) => walk5(one, `${pointer2}/${index}`));
12928
+ return;
12929
+ }
12930
+ if (!isPlainObject8(node)) return;
12931
+ if ((Object.hasOwn(node, "table_id") || Object.hasOwn(node, "table_alias")) && !readsMetric(node)) {
12932
+ const id = tableIdOf(node.table_id);
12933
+ if (id !== null && !tables.includes(id)) tables.push(id);
12934
+ if (id === null && named5(node.table_alias)) aliased.push(pointer2);
12935
+ return;
12936
+ }
12937
+ for (const key of Object.keys(node).sort(natural3)) walk5(node[key], `${pointer2}/${escapePointer3(key)}`);
12938
+ };
12939
+ walk5(contract?.data, "/data");
12940
+ return { tables, aliased };
12941
+ }
12942
+ function tableIdOf(value) {
12943
+ const id = typeof value === "number" ? value : typeof value === "string" && /^\d+$/.test(value.trim()) ? Number(value.trim()) : NaN;
12944
+ return Number.isSafeInteger(id) && id > 0 ? id : null;
12945
+ }
12946
+ function undeclaredTableWarnings(contract) {
12947
+ return readTables(contract).aliased.map((pointer2) => ({
12948
+ code: "table_not_declared",
12949
+ pointer: pointer2,
12950
+ message: `${pointer2} reads its table by table_alias alone, so the manifest cannot list it in sources.tables and sharing this app will not offer a grantee access to it; add the table's numeric table_id beside the alias`
12951
+ }));
12952
+ }
12920
12953
  var FINANCEOS_SCOPES = {
12921
12954
  commands: {
12922
12955
  "status:read": ["status", "whoami"],
@@ -14694,7 +14727,7 @@ function compileApp(contract, { kit = null, runtime = RUNTIME, extra = {} } = {}
14694
14727
  }
14695
14728
  if (typeof extra["seed.json"] === "string") files["seed.json"] = extra["seed.json"];
14696
14729
  files["tests.json"] = typeof extra["tests.json"] === "string" ? extra["tests.json"] : json(testsOf(handlers, names, sources, served, model));
14697
- return { files, problems, contract: whole, order: order2, warnings };
14730
+ return { files, problems, contract: whole, order: order2, warnings: [...warnings, ...undeclaredTableWarnings(contract)] };
14698
14731
  }
14699
14732
  function refreshPins(contract, compiled, files) {
14700
14733
  if (!Array.isArray(contract.pins)) return contract;
@@ -17535,6 +17568,8 @@ function manifestOf(contract, app, handlers, names, model, served = [], readers
17535
17568
  }
17536
17569
  manifest.handlers = Object.fromEntries(Object.keys(manifest.handlers).sort(natural3).map((name) => [name, manifest.handlers[name]]));
17537
17570
  manifest.capabilities = isPlainObject8(app.capabilities) && Object.keys(app.capabilities).length > 0 ? app.capabilities : { data: ["rw"] };
17571
+ const { tables } = readTables(contract);
17572
+ if (tables.length > 0) manifest.sources = { tables };
17538
17573
  return manifest;
17539
17574
  }
17540
17575
  function routesOf2(app, pages) {
@@ -21521,6 +21556,37 @@ import { join as join6 } from "path";
21521
21556
  // src/commands/appspace/_folder.ts
21522
21557
  import { readFile as readFile3, readdir, stat, writeFile as writeFile2 } from "fs/promises";
21523
21558
  import { join as join5 } from "path";
21559
+
21560
+ // src/commands/appspace/_handlerNames.ts
21561
+ var MAX_HANDLER_NAME_LENGTH = 128;
21562
+ var UNSAFE_CHAR = /[\p{Cc}\p{Cs}\p{Cf}\p{Z}]/u;
21563
+ function handlerNameProblem(name) {
21564
+ if (name === "") return "the name is empty";
21565
+ if ([...name].length > MAX_HANDLER_NAME_LENGTH) {
21566
+ return `the name is longer than ${MAX_HANDLER_NAME_LENGTH} characters`;
21567
+ }
21568
+ if (name.includes("/") || name.includes("\\")) {
21569
+ return "the name contains a path separator ('/' or '\\')";
21570
+ }
21571
+ if (name === "." || name === "..") return "the name is '.' or '..'";
21572
+ if (UNSAFE_CHAR.test(name)) {
21573
+ return "the name contains whitespace, a control character or an invisible format character";
21574
+ }
21575
+ return null;
21576
+ }
21577
+ function handlerFileProblem(file) {
21578
+ const name = file.endsWith(".py") ? file.slice(0, -3) : file;
21579
+ const why = handlerNameProblem(name);
21580
+ if (why === null) return null;
21581
+ const cut3 = [...file].length > 80 ? `${[...file].slice(0, 80).join("")}...` : file;
21582
+ const shown2 = cut3.replace(
21583
+ /[\p{Cc}\p{Cs}\p{Cf}\p{Z}]/gu,
21584
+ (c) => c === " " ? " " : `\\u{${c.codePointAt(0).toString(16)}}`
21585
+ );
21586
+ 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.`;
21587
+ }
21588
+
21589
+ // src/commands/appspace/_folder.ts
21524
21590
  async function readIfPresent(path3) {
21525
21591
  try {
21526
21592
  return await readFile3(path3, "utf8");
@@ -21599,6 +21665,8 @@ async function readHandlers(handlersDir, state) {
21599
21665
  const handlers = {};
21600
21666
  for (const file of await readDirIfPresent(handlersDir)) {
21601
21667
  if (!file.endsWith(".py")) continue;
21668
+ const refused = handlerFileProblem(file);
21669
+ if (refused !== null) throw new Error(refused);
21602
21670
  const name = file.slice(0, -3);
21603
21671
  const method = recorded?.[name];
21604
21672
  handlers[name] = {
@@ -25053,11 +25121,23 @@ function registerGetCommand(parent) {
25053
25121
  }
25054
25122
 
25055
25123
  // src/commands/appspace/packageCheck.ts
25056
- import { cp, mkdir as mkdir5, mkdtemp as mkdtemp2, rm as rm3, writeFile as writeFile6 } from "fs/promises";
25124
+ import { cp, mkdir as mkdir5, mkdtemp as mkdtemp2, readdir as readdir2, rm as rm3, writeFile as writeFile6 } from "fs/promises";
25057
25125
  import { tmpdir as tmpdir3 } from "os";
25058
25126
  import { dirname as dirname4, join as join11, resolve as resolve5, sep as sep2 } from "path";
25059
25127
  var WHAT = "package";
25060
25128
  async function checkPackage(dir, files, contract, opts, online, pendingMetricKeys = []) {
25129
+ const badName = await handlerNameProblems(dir, files);
25130
+ if (badName.length > 0) {
25131
+ return {
25132
+ problems: badName.map((message) => ({
25133
+ code: "handler-name",
25134
+ pointer: "/",
25135
+ message,
25136
+ fix: "Rename the handler file, then run the check again."
25137
+ })),
25138
+ skipped: []
25139
+ };
25140
+ }
25061
25141
  if (!online) {
25062
25142
  return skip("no -s server to run the push's own checks against; the push is the first to run them");
25063
25143
  }
@@ -25098,6 +25178,24 @@ async function checkPackage(dir, files, contract, opts, online, pendingMetricKey
25098
25178
  await rm3(scratch, { recursive: true, force: true });
25099
25179
  }
25100
25180
  }
25181
+ async function handlerNameProblems(dir, files) {
25182
+ const names = /* @__PURE__ */ new Set();
25183
+ try {
25184
+ for (const file of await readdir2(join11(dir, "handlers"))) names.add(file);
25185
+ } catch {
25186
+ }
25187
+ for (const path3 of Object.keys(files)) {
25188
+ const match = /^handlers\/([^/]+)$/.exec(path3);
25189
+ if (match !== null) names.add(match[1]);
25190
+ }
25191
+ const out = [];
25192
+ for (const file of [...names].sort()) {
25193
+ if (!file.endsWith(".py")) continue;
25194
+ const problem6 = handlerFileProblem(file);
25195
+ if (problem6 !== null) out.push(problem6);
25196
+ }
25197
+ return out;
25198
+ }
25101
25199
  function setAsidePending(check5, pending) {
25102
25200
  if (pending.length === 0) return check5;
25103
25201
  const mentions3 = (message) => pending.some((key) => new RegExp(`metric_bindings\\.${key.replace(/[^a-z0-9_]/g, "")}(?![a-z0-9_])`).test(message));
@@ -34373,7 +34471,7 @@ async function landWithRetries(tryOnce, opts, sleep3 = (ms) => new Promise((done
34373
34471
  async function claimFolder(dir) {
34374
34472
  let names;
34375
34473
  try {
34376
- names = await readdir2(dir);
34474
+ names = await readdir3(dir);
34377
34475
  } catch {
34378
34476
  await mkdir6(dir, { recursive: true });
34379
34477
  names = [];
@@ -37827,7 +37925,7 @@ async function runUiSmoke(opts) {
37827
37925
  // src/commands/appspace/_screenshot.ts
37828
37926
  import { spawn } from "child_process";
37829
37927
  import { existsSync as existsSync3, statSync as statSync3 } from "fs";
37830
- 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";
37928
+ 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";
37831
37929
  import { createServer } from "http";
37832
37930
  import { tmpdir as tmpdir5 } from "os";
37833
37931
  import { delimiter, extname as extname2, join as join18, relative as relative3, resolve as resolve15, sep as sep7 } from "path";
@@ -39543,7 +39641,7 @@ async function readLocalUi(dir) {
39543
39641
  const walk5 = async (folder) => {
39544
39642
  let names;
39545
39643
  try {
39546
- names = await readdir3(folder, { withFileTypes: true });
39644
+ names = await readdir4(folder, { withFileTypes: true });
39547
39645
  } catch {
39548
39646
  return;
39549
39647
  }
@@ -42661,7 +42759,7 @@ function registerPublishCommands(parent) {
42661
42759
  }
42662
42760
 
42663
42761
  // src/commands/appspace/scaffold.ts
42664
- import { mkdir as mkdir9, readdir as readdir4, stat as stat3, writeFile as writeFile11 } from "fs/promises";
42762
+ import { mkdir as mkdir9, readdir as readdir5, stat as stat3, writeFile as writeFile11 } from "fs/promises";
42665
42763
  import { dirname as dirname10, join as join21 } from "path";
42666
42764
 
42667
42765
  // src/commands/appspace/starters.ts
@@ -42999,7 +43097,7 @@ async function checkTarget(dir, force) {
42999
43097
  if (force) return;
43000
43098
  let entries;
43001
43099
  try {
43002
- entries = await readdir4(dir);
43100
+ entries = await readdir5(dir);
43003
43101
  } catch (err) {
43004
43102
  if (err.code === "ENOENT") return;
43005
43103
  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.76",
3
+ "version": "0.12.78",
4
4
  "description": "Datarails App Space CLI — build, try, push and publish App Space apps",
5
5
  "type": "module",
6
6
  "engines": {