@lotics/app-sdk 0.128.5 → 0.128.6

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.
@@ -281,11 +281,13 @@ var MEMBER_ID_PATTERN = new RegExp(`^[${ID_ALPHABET}]{${ID_LENGTH},}$`);
281
281
  var CPU_PROFILE_ID_PATTERN = new RegExp(`^cpf_[${ID_ALPHABET}]{${ID_LENGTH}}$`);
282
282
 
283
283
  // ../shared/src/table_field_keys.ts
284
- var nanoid2 = customAlphabet(ID_ALPHABET, 6);
284
+ var KEY_LENGTH = 6;
285
+ var nanoid2 = customAlphabet(ID_ALPHABET, KEY_LENGTH);
285
286
  var FIELD_KEY_PREFIX = "fld_";
286
287
  function isFieldKey(value) {
287
288
  return value.startsWith(FIELD_KEY_PREFIX);
288
289
  }
290
+ var GENERATED_OPTION_KEY_PATTERN = new RegExp(`^opt_[${ID_ALPHABET}]{${KEY_LENGTH}}$`);
289
291
 
290
292
  // ../shared/src/schemas/read_row.ts
291
293
  var RECORD_ID_COLUMN = "__source_record_id";
package/dist/index.js CHANGED
@@ -51,7 +51,7 @@ import {
51
51
  subtractDecimal,
52
52
  sumDecimal,
53
53
  urlParam
54
- } from "./chunk-ZMNW4WF6.js";
54
+ } from "./chunk-GYTOFOC2.js";
55
55
 
56
56
  // src/mount.tsx
57
57
  import { createRoot } from "react-dom/client";
@@ -9421,20 +9421,23 @@ function resolveForeachFrame(ctx, name, at2) {
9421
9421
  }
9422
9422
  function evaluateRead(source, path, coerce, ctx) {
9423
9423
  const root = source.from === "value" ? evaluateExpression(source.expr, ctx) : resolveReadRoot(source, ctx);
9424
- return root instanceof Promise ? readAfter(root, source, path, coerce, ctx) : walkPath(path, coerce, ctx, readRecordAnchor(source, path, ctx.anchor_context), 0, root, null, void 0, void 0);
9424
+ return root instanceof Promise ? readAfter(root, source, path, coerce, ctx) : walkPath(path, coerce, ctx, readRecordAnchor(source, path, ctx.anchor_context), 0, root, null, void 0, void 0, NO_OWNERS);
9425
9425
  }
9426
9426
  async function readAfter(root, source, path, coerce, ctx) {
9427
9427
  const value = await root;
9428
- return walkPath(path, coerce, ctx, readRecordAnchor(source, path, ctx.anchor_context), 0, value, null, void 0, void 0);
9428
+ return walkPath(path, coerce, ctx, readRecordAnchor(source, path, ctx.anchor_context), 0, value, null, void 0, void 0, NO_OWNERS);
9429
9429
  }
9430
9430
  function knownTables(tables) {
9431
9431
  return { current: tables, hold: (tableId) => tables.get(tableId) ?? null };
9432
9432
  }
9433
- function walkPath(path, coerce, ctx, anchor, from, start, startTable, startField, startTerminal, startCarried) {
9433
+ var NO_OWNERS = { prev: null, terminal: null };
9434
+ function walkPath(path, coerce, ctx, anchor, from, start, startTable, startField, startTerminal, startOwners, startCarried) {
9434
9435
  let current = start;
9435
9436
  let table = startTable;
9436
9437
  let prevField = startField;
9437
9438
  let terminalField = startTerminal;
9439
+ let prevOwner = startOwners.prev;
9440
+ let terminalOwner = startOwners.terminal;
9438
9441
  for (let i = from; i < path.length; i++) {
9439
9442
  const segment = path[i];
9440
9443
  const isLast = i === path.length - 1;
@@ -9443,23 +9446,25 @@ function walkPath(path, coerce, ctx, anchor, from, start, startTable, startField
9443
9446
  const carried = asked === void 0 ? carriedTable(current, ctx) : asked;
9444
9447
  if (carried instanceof Promise) {
9445
9448
  return carried.then(
9446
- (settled) => walkPath(path, coerce, ctx, anchor, i, current, table, prevField, terminalField, settled)
9449
+ (settled) => walkPath(path, coerce, ctx, anchor, i, current, table, prevField, terminalField, { prev: prevOwner, terminal: terminalOwner }, settled)
9447
9450
  );
9448
9451
  }
9449
9452
  if (carried?.at === "self") table = carried.table;
9450
9453
  const field = (segment.at === "field" || segment.at === "key") && table ? findField(table, segment.key) : void 0;
9451
9454
  if (isLast) {
9452
9455
  terminalField = field ?? (segment.at === "key" && (segment.key === "next_value" || segment.key === "prev_value") ? prevField : void 0);
9456
+ terminalOwner = field === void 0 ? prevOwner : table;
9453
9457
  }
9454
9458
  const walked = walkSegment(current, segment, ctx);
9455
9459
  if (walked instanceof Promise) {
9456
- return walkPending({ path, coerce, ctx, anchor, table, carried, field, terminal_field: terminalField }, i, walked);
9460
+ return walkPending({ path, coerce, ctx, anchor, table, carried, field, terminal_field: terminalField, owners: { prev: prevOwner, terminal: terminalOwner } }, i, walked);
9457
9461
  }
9458
9462
  if (walked === void 0 || walked === null) return walked;
9459
9463
  const next = tableAfter(segment, table, carried, ctx);
9460
9464
  if (next instanceof Promise) {
9461
- return next.then((advanced) => walkPath(path, coerce, ctx, anchor, i + 1, walked, advanced, field, terminalField));
9465
+ return next.then((advanced) => walkPath(path, coerce, ctx, anchor, i + 1, walked, advanced, field, terminalField, { prev: table, terminal: terminalOwner }));
9462
9466
  }
9467
+ prevOwner = table;
9463
9468
  table = next;
9464
9469
  prevField = field;
9465
9470
  current = walked;
@@ -9468,7 +9473,7 @@ function walkPath(path, coerce, ctx, anchor, from, start, startTable, startField
9468
9473
  current = unwrapScalarField(current);
9469
9474
  }
9470
9475
  if (coerce.mode === "display" && terminalField) {
9471
- return coerceFieldDisplay(current, terminalField, ctx);
9476
+ return coerceFieldDisplay(current, terminalField, terminalOwner, ctx);
9472
9477
  }
9473
9478
  if (coerce.mode === "alias") return coerceOptionAliases(current, coerce.of, ctx);
9474
9479
  return current;
@@ -9490,9 +9495,10 @@ function coerceOptionAliases(value, of, ctx) {
9490
9495
  const options = optionsBehind(of, heldTable(of.table_id, ctx), ctx, 0);
9491
9496
  return options instanceof Promise ? options.then((held2) => aliasesOf(value, of, held2, ctx)) : aliasesOf(value, of, options, ctx);
9492
9497
  }
9493
- function optionsBehind(of, held2, ctx, hops) {
9494
- if (held2 instanceof Promise) return held2.then((table) => optionsBehind(of, table, ctx, hops));
9498
+ function optionsBehind(of, held2, ctx, hops, unheld = "refuse") {
9499
+ if (held2 instanceof Promise) return held2.then((table) => optionsBehind(of, table, ctx, hops, unheld));
9495
9500
  if (held2 === null) {
9501
+ if (unheld === "unknown") return void 0;
9496
9502
  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 } });
9497
9503
  }
9498
9504
  const field = findField(held2, of.field_key);
@@ -9502,7 +9508,7 @@ function optionsBehind(of, held2, ctx, hops) {
9502
9508
  const through = findField(held2, field.source_field_key);
9503
9509
  if (through?.type !== "select_record_link") return void 0;
9504
9510
  const next = { table_id: through.table_id, field_key: field.lookup_field_key };
9505
- return optionsBehind(next, heldTable(next.table_id, ctx), ctx, hops + 1);
9511
+ return optionsBehind(next, heldTable(next.table_id, ctx), ctx, hops + 1, unheld);
9506
9512
  }
9507
9513
  function aliasesOf(value, of, options, ctx) {
9508
9514
  if (options === void 0) {
@@ -9515,11 +9521,11 @@ function aliasesOf(value, of, options, ctx) {
9515
9521
  return aliased;
9516
9522
  }
9517
9523
  async function walkPending(read2, at2, walked) {
9518
- const { path, coerce, ctx, anchor, carried, field, terminal_field: terminalField } = read2;
9524
+ const { path, coerce, ctx, anchor, carried, field, terminal_field: terminalField, owners } = read2;
9519
9525
  const current = await walked;
9520
9526
  if (current === void 0 || current === null) return current;
9521
9527
  const table = await tableAfter(path[at2], read2.table, carried, ctx);
9522
- return walkPath(path, coerce, ctx, anchor, at2 + 1, current, table, field, terminalField);
9528
+ return walkPath(path, coerce, ctx, anchor, at2 + 1, current, table, field, terminalField, { prev: read2.table, terminal: owners.terminal });
9523
9529
  }
9524
9530
  function tableAfter(segment, table, carried, ctx) {
9525
9531
  return carried?.at === "data" && isKeyNamed(segment, "data") ? carried.table : advanceTable(segment, table, ctx);
@@ -9550,7 +9556,7 @@ function isPlainObject(value) {
9550
9556
  function isKeyNamed(segment, key) {
9551
9557
  return (segment.at === "key" || segment.at === "field") && segment.key === key;
9552
9558
  }
9553
- async function coerceFieldDisplay(value, field, ctx) {
9559
+ async function coerceFieldDisplay(value, field, owner, ctx) {
9554
9560
  if (value === null || value === void 0) return value;
9555
9561
  switch (field.type) {
9556
9562
  case "select":
@@ -9563,13 +9569,19 @@ async function coerceFieldDisplay(value, field, ctx) {
9563
9569
  case "select_member":
9564
9570
  return coerceMemberDisplay(value, ctx);
9565
9571
  case "lookup":
9566
- return field.lookup_field_options ? coerceOptionKeysDeep(value, field.lookup_field_options, ctx) : value;
9572
+ if (field.lookup_field_type !== "select") return value;
9573
+ const behind = owner === null ? void 0 : await optionsBehind({ table_id: owner.id, field_key: field.key }, owner, ctx, 0, "unknown");
9574
+ const options = behind ?? field.lookup_field_options;
9575
+ return options ? coerceOptionKeysDeep(value, options, ctx) : value;
9567
9576
  default:
9568
9577
  return value;
9569
9578
  }
9570
9579
  }
9580
+ function optionNames(options) {
9581
+ return new Map(options.flatMap((o) => o.alias === void 0 ? [[o.key, o.name]] : [[o.key, o.name], [o.alias, o.name]]));
9582
+ }
9571
9583
  function coerceSelectDisplay(value, options, ctx) {
9572
- const optionMap = new Map(options.map((o) => [o.key, o.name]));
9584
+ const optionMap = optionNames(options);
9573
9585
  const resolve = (key) => {
9574
9586
  if (typeof key !== "string") return "";
9575
9587
  return optionMap.get(key) ?? key;
@@ -9582,7 +9594,7 @@ function coerceSelectDisplay(value, options, ctx) {
9582
9594
  }
9583
9595
  function coerceOptionKeysDeep(value, options, ctx) {
9584
9596
  assertCheap(ctx.evaluation_budget, value);
9585
- const optionMap = new Map(options.map((o) => [o.key, o.name]));
9597
+ const optionMap = optionNames(options);
9586
9598
  const resolve = (v) => {
9587
9599
  if (Array.isArray(v)) {
9588
9600
  const resolved = v.map(resolve);
@@ -10458,6 +10470,7 @@ async function predictWorkflowEffects(input) {
10458
10470
  step_outputs: {},
10459
10471
  runtime: clientRuntime(input),
10460
10472
  helpers,
10473
+ body_spelling: "key",
10461
10474
  record_cache: cache,
10462
10475
  fetch_record: fetchRecord,
10463
10476
  tables: knownTables(input.tables),
@@ -13436,14 +13449,14 @@ function referencedFieldKeys(expression, fields) {
13436
13449
  }
13437
13450
 
13438
13451
  // ../shared/src/formula.ts
13439
- function optionNames(options) {
13452
+ function optionNames2(options) {
13440
13453
  return Object.fromEntries(options.map((option) => [option.key, option.name]));
13441
13454
  }
13442
13455
  function optionNamesOf(fields) {
13443
13456
  return Object.fromEntries(
13444
13457
  fields.flatMap((field) => {
13445
13458
  const options = effectiveSelectOptions(field);
13446
- return options === null ? [] : [[field.key, optionNames(options)]];
13459
+ return options === null ? [] : [[field.key, optionNames2(options)]];
13447
13460
  })
13448
13461
  );
13449
13462
  }
package/dist/router.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  isEmbedded,
3
3
  postHostNotification,
4
4
  setUrlParams
5
- } from "./chunk-ZMNW4WF6.js";
5
+ } from "./chunk-GYTOFOC2.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.128.5",
3
+ "version": "0.128.6",
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": {