@lotics/app-sdk 0.127.10 → 0.127.12

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.
@@ -273,6 +273,9 @@ var TABLE_ID_PATTERN = new RegExp(
273
273
  `^tbl_[${ID_ALPHABET}]+$|^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`,
274
274
  "i"
275
275
  );
276
+ function isTableId(value) {
277
+ return TABLE_ID_PATTERN.test(value);
278
+ }
276
279
  var PREFIXED_ID_PATTERN = new RegExp(`^[a-z]{3}_[${ID_ALPHABET}]{${ID_LENGTH}}$`);
277
280
  var MEMBER_ID_PATTERN = new RegExp(`^[${ID_ALPHABET}]{${ID_LENGTH},}$`);
278
281
  var CPU_PROFILE_ID_PATTERN = new RegExp(`^cpf_[${ID_ALPHABET}]{${ID_LENGTH}}$`);
@@ -2066,6 +2069,7 @@ export {
2066
2069
  keepAccentsForm,
2067
2070
  searchWords,
2068
2071
  customAlphabet,
2072
+ isTableId,
2069
2073
  isFieldKey,
2070
2074
  COMPARE_KEYS,
2071
2075
  isRecordBound,
package/dist/index.js CHANGED
@@ -25,6 +25,7 @@ import {
25
25
  isEmbedded,
26
26
  isFieldKey,
27
27
  isRecordBound,
28
+ isTableId,
28
29
  keepAccentsForm,
29
30
  moduloDecimal,
30
31
  multiplyDecimal,
@@ -51,7 +52,7 @@ import {
51
52
  subtractDecimal,
52
53
  sumDecimal,
53
54
  urlParam
54
- } from "./chunk-JSL3NPE2.js";
55
+ } from "./chunk-7OXMZ332.js";
55
56
 
56
57
  // src/mount.tsx
57
58
  import { createRoot } from "react-dom/client";
@@ -9163,7 +9164,7 @@ function evaluateLambda(params, body, ctx, items) {
9163
9164
  }
9164
9165
  function evalAnchorContext(ctx) {
9165
9166
  return {
9166
- tables: ctx.tables,
9167
+ tables: ctx.tables.current,
9167
9168
  steps_by_id: ctx.steps_by_id,
9168
9169
  // The whole stack, so a read anchors to the loop it NAMES rather than to
9169
9170
  // whichever is innermost — the anchor half of the same nesting bug.
@@ -9294,7 +9295,10 @@ async function readAfter(root, source, path, coerce, ctx) {
9294
9295
  const value = await root;
9295
9296
  return walkPath(path, coerce, ctx, readRecordAnchor(source, path, ctx.anchor_context), 0, value, null, void 0, void 0);
9296
9297
  }
9297
- function walkPath(path, coerce, ctx, anchor, from, start, startTable, startField, startTerminal) {
9298
+ function knownTables(tables) {
9299
+ return { current: tables, hold: (tableId) => tables.get(tableId) ?? null };
9300
+ }
9301
+ function walkPath(path, coerce, ctx, anchor, from, start, startTable, startField, startTerminal, startCarried) {
9298
9302
  let current = start;
9299
9303
  let table = startTable;
9300
9304
  let prevField = startField;
@@ -9303,7 +9307,13 @@ function walkPath(path, coerce, ctx, anchor, from, start, startTable, startField
9303
9307
  const segment = path[i];
9304
9308
  const isLast = i === path.length - 1;
9305
9309
  if (anchor && i === anchor.envelopeLen) table ??= anchor.table;
9306
- const carried = carriedTable(current, ctx);
9310
+ const asked = i === from ? startCarried : void 0;
9311
+ const carried = asked === void 0 ? carriedTable(current, ctx) : asked;
9312
+ if (carried instanceof Promise) {
9313
+ return carried.then(
9314
+ (settled) => walkPath(path, coerce, ctx, anchor, i, current, table, prevField, terminalField, settled)
9315
+ );
9316
+ }
9307
9317
  if (carried?.at === "self") table = carried.table;
9308
9318
  const field = (segment.at === "field" || segment.at === "key") && table ? findField(table, segment.key) : void 0;
9309
9319
  if (isLast) {
@@ -9313,10 +9323,14 @@ function walkPath(path, coerce, ctx, anchor, from, start, startTable, startField
9313
9323
  if (walked instanceof Promise) {
9314
9324
  return walkPending({ path, coerce, ctx, anchor, table, carried, field, terminal_field: terminalField }, i, walked);
9315
9325
  }
9316
- table = tableAfter(segment, table, carried, ctx);
9326
+ if (walked === void 0 || walked === null) return walked;
9327
+ const next = tableAfter(segment, table, carried, ctx);
9328
+ if (next instanceof Promise) {
9329
+ return next.then((advanced) => walkPath(path, coerce, ctx, anchor, i + 1, walked, advanced, field, terminalField));
9330
+ }
9331
+ table = next;
9317
9332
  prevField = field;
9318
9333
  current = walked;
9319
- if (current === void 0 || current === null) return current;
9320
9334
  }
9321
9335
  if (terminalField && isScalarWrappedField(terminalField)) {
9322
9336
  current = unwrapScalarField(current);
@@ -9341,8 +9355,11 @@ function optionAliases(value, field) {
9341
9355
  return resolve(value);
9342
9356
  }
9343
9357
  function coerceOptionAliases(value, of, ctx) {
9344
- const table = ctx.tables.get(of.table_id);
9345
- if (table === void 0) {
9358
+ const held2 = heldTable(of.table_id, ctx);
9359
+ return held2 instanceof Promise ? held2.then((table) => aliasesOf(value, of, table, ctx)) : aliasesOf(value, of, held2, ctx);
9360
+ }
9361
+ function aliasesOf(value, of, table, ctx) {
9362
+ if (table === null) {
9346
9363
  throw new WorkflowEvalError(`Reading "${of.field_key}" as its alias reads table ${of.table_id}, which this run does not hold.`, { kind: "unknown_table", extra: { table_id: of.table_id } });
9347
9364
  }
9348
9365
  const field = findField(table, of.field_key);
@@ -9360,12 +9377,11 @@ async function walkPending(read2, at2, walked) {
9360
9377
  const { path, coerce, ctx, anchor, carried, field, terminal_field: terminalField } = read2;
9361
9378
  const current = await walked;
9362
9379
  if (current === void 0 || current === null) return current;
9363
- const table = tableAfter(path[at2], read2.table, carried, ctx);
9380
+ const table = await tableAfter(path[at2], read2.table, carried, ctx);
9364
9381
  return walkPath(path, coerce, ctx, anchor, at2 + 1, current, table, field, terminalField);
9365
9382
  }
9366
9383
  function tableAfter(segment, table, carried, ctx) {
9367
- const advanced = advanceTable(segment, table, ctx);
9368
- return carried?.at === "data" && isKeyNamed(segment, "data") ? carried.table : advanced;
9384
+ return carried?.at === "data" && isKeyNamed(segment, "data") ? carried.table : advanceTable(segment, table, ctx);
9369
9385
  }
9370
9386
  function isScalarWrappedField(field) {
9371
9387
  if (field.type === "formula") return field.formula.options !== void 0;
@@ -9377,9 +9393,15 @@ function unwrapScalarField(value) {
9377
9393
  }
9378
9394
  function carriedTable(value, ctx) {
9379
9395
  if (!isPlainObject(value) || !("table_id" in value) || typeof value.table_id !== "string") return null;
9380
- const table = ctx.tables.get(value.table_id);
9381
- if (!table) return null;
9382
- return { table, at: isPlainObject(value.data) ? "data" : "self" };
9396
+ const at2 = isPlainObject(value.data) ? "data" : "self";
9397
+ const table = heldTable(value.table_id, ctx);
9398
+ if (table instanceof Promise) return table.then((loaded2) => loaded2 === null ? null : { table: loaded2, at: at2 });
9399
+ return table === null ? null : { table, at: at2 };
9400
+ }
9401
+ function heldTable(tableId, ctx) {
9402
+ const held2 = ctx.tables.current.get(tableId);
9403
+ if (held2 !== void 0) return held2;
9404
+ return isTableId(tableId) ? ctx.tables.hold(tableId) : null;
9383
9405
  }
9384
9406
  function isPlainObject(value) {
9385
9407
  return typeof value === "object" && value !== null && !Array.isArray(value);
@@ -9450,8 +9472,9 @@ async function coerceRecordLinkDisplay(value, field, ctx) {
9450
9472
  }
9451
9473
  if (!Array.isArray(value)) return value;
9452
9474
  assertCheap(ctx.evaluation_budget, value);
9453
- const target = ctx.tables.get(field.table_id);
9454
- if (target === void 0) {
9475
+ const held2 = heldTable(field.table_id, ctx);
9476
+ const target = held2 instanceof Promise ? await held2 : held2;
9477
+ if (target === null) {
9455
9478
  throw new WorkflowEvalError(`Showing "${field.key}" reads rows of table ${field.table_id}, which this run does not hold.`, { kind: "unknown_table", extra: { table_id: field.table_id } });
9456
9479
  }
9457
9480
  const rows = await fetchRecordsBounded(
@@ -9467,7 +9490,7 @@ function advanceTable(segment, currentTable, ctx) {
9467
9490
  if (segment.at === "linked" && currentTable) {
9468
9491
  const linkField = findField(currentTable, segment.via);
9469
9492
  if (linkField?.type === "select_record_link") {
9470
- return ctx.tables.get(linkField.table_id) ?? null;
9493
+ return heldTable(linkField.table_id, ctx);
9471
9494
  }
9472
9495
  }
9473
9496
  return null;
@@ -10294,7 +10317,7 @@ async function predictWorkflowEffects(input) {
10294
10317
  helpers,
10295
10318
  record_cache: cache,
10296
10319
  fetch_record: fetchRecord,
10297
- tables: input.tables,
10320
+ tables: knownTables(input.tables),
10298
10321
  trigger_table: null,
10299
10322
  member_lookup: async () => unread("member display"),
10300
10323
  lexical_bindings: [{}],
package/dist/router.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  isEmbedded,
3
3
  postHostNotification,
4
4
  setUrlParams
5
- } from "./chunk-JSL3NPE2.js";
5
+ } from "./chunk-7OXMZ332.js";
6
6
 
7
7
  // src/router.tsx
8
8
  import { useEffect } from "react";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lotics/app-sdk",
3
- "version": "0.127.10",
3
+ "version": "0.127.12",
4
4
  "description": "The SDK a Lotics custom-code app reads and writes through — typed hooks over the host bridge, cell readers, mount() and AppRouter",
5
5
  "type": "module",
6
6
  "exports": {