@lotics/app-sdk 0.133.47 → 0.133.48

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.
package/AGENTS.md CHANGED
@@ -14,7 +14,7 @@ This file is the index. The **exact type** of anything is its shipped declaratio
14
14
 
15
15
  | Doc | Read it for |
16
16
  |---|---|
17
- | [docs/data_fetching.md](./docs/data_fetching.md) | The reads: `useQuery(alias, params, opts)` — its rows (`limit`), numbered pages (`page`), a keyset feed (`more`), its `total` or the total alone, with `total: { by }` a count per value of one column and `total: { where }` a count per named filter, from one scan — `useQueries` for reads known only at render, `queryAll` outside React, `exportQuery` for a file of them the server makes, `exportApp` for the workbook of a JSON app's List; every hook answers one `QueryState`. The ROW type (`RowOf` — the alias's projected columns and nothing else), runtime `sort`/`filter` keys, cell readers (`row.*`, `readSelect`, `readMembers`, `readLinks`, `readFiles`, `readLocked`/`readLockedBy`, `readCreatedAt`/`readUpdatedAt`), the SDK's own cache — **arrival revalidates** — **realtime push** and `answeredAt` (the server answering again what a screen drew), a write drawn on every read from the press, a count as its own full scan, and the search-as-you-type and record-picker patterns. |
17
+ | [docs/data_fetching.md](./docs/data_fetching.md) | The reads: `useQuery(alias, params, opts)` — its rows (`limit`), numbered pages (`page`), a keyset feed (`more`), its `total` or the total alone, only the columns it draws (`fields`), a push re-reading only the records it changed (`refresh: "changed"`), with `total: { by }` a count per value of one column and `total: { where }` a count per named filter, from one scan — `useQueries` for reads known only at render, `queryAll` outside React, `exportQuery` for a file of them the server makes, `exportApp` for the workbook of a JSON app's List; every hook answers one `QueryState`. The ROW type (`RowOf` — the alias's projected columns and nothing else), runtime `sort`/`filter` keys, cell readers (`row.*`, `readSelect`, `readMembers`, `readLinks`, `readFiles`, `readLocked`/`readLockedBy`, `readCreatedAt`/`readUpdatedAt`), the SDK's own cache — **arrival revalidates** — **realtime push** and `answeredAt` (the server answering again what a screen drew), a write drawn on every read from the press, a count as its own full scan, and the search-as-you-type and record-picker patterns. |
18
18
  | [docs/queries.md](./docs/queries.md) | **The query engine reference** — AST node kinds, per-field-type operators, filters/params/pruning, free-text search, combining tables, shaping (aggregates, date buckets, windows), runtime refinement bounds, limits and the efficiency playbook. |
19
19
  | [docs/mutations.md](./docs/mutations.md) | `useWorkflow` (the ONLY write path; `useWorkflows` for writes that are data), the `WorkflowResult` resolve-never-throw contract (`field_errors`), typed inputs, every write drawn on every read from the press — predicted from the workflow's own steps, taken back on a refusal, `pending` meanwhile — the re-read a successful write triggers over the tables its body names, diff-before-update, locked records, `useNewRecord`, read-after-write ordering (`writesSettled()`), `useRecording`, `useRecordings` over several aliases. |
20
20
  | [docs/workflows.md](./docs/workflows.md) | **The workflow-BODY reference** — the JS subset a body may use, opaque `fld_*`/`opt_*` keys, every step form, the accepted sugar, helpers, record-write surfaces, the traps and the verify loop. |
@@ -1608,8 +1608,23 @@ function notifyLocalWrite(reads) {
1608
1608
  if (aliases.length === 0) return;
1609
1609
  queriesChanged(aliases);
1610
1610
  }
1611
- function queriesChanged(aliases) {
1612
- for (const cb of refetchSubscribers) cb([...aliases]);
1611
+ function queriesChanged(aliases, changes) {
1612
+ for (const cb of refetchSubscribers) cb([...aliases], changes);
1613
+ }
1614
+ function readQueryChanges(raw) {
1615
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw)) return void 0;
1616
+ const changes = [];
1617
+ for (const [alias, tables] of Object.entries(raw)) {
1618
+ if (typeof tables !== "object" || tables === null || Array.isArray(tables)) return void 0;
1619
+ const read = [];
1620
+ for (const [tableId, ids] of Object.entries(tables)) {
1621
+ if (ids === null) read.push([tableId, null]);
1622
+ else if (Array.isArray(ids) && ids.every((id) => typeof id === "string")) read.push([tableId, ids]);
1623
+ else return void 0;
1624
+ }
1625
+ changes.push([alias, Object.fromEntries(read)]);
1626
+ }
1627
+ return Object.fromEntries(changes);
1613
1628
  }
1614
1629
  var pending = /* @__PURE__ */ new Map();
1615
1630
  var streaming = /* @__PURE__ */ new Map();
@@ -1634,7 +1649,10 @@ function ensureListener() {
1634
1649
  return;
1635
1650
  }
1636
1651
  if (msg.type === "queriesChanged" && Array.isArray(msg.aliases)) {
1637
- queriesChanged(msg.aliases.filter((a) => typeof a === "string"));
1652
+ queriesChanged(
1653
+ msg.aliases.filter((a) => typeof a === "string"),
1654
+ readQueryChanges(msg.changes)
1655
+ );
1638
1656
  return;
1639
1657
  }
1640
1658
  if (msg.type === "recordingChanged") {
package/dist/index.js CHANGED
@@ -62,7 +62,7 @@ import {
62
62
  subtractDecimal,
63
63
  sumDecimal,
64
64
  urlParam
65
- } from "./chunk-J2TOGQ4C.js";
65
+ } from "./chunk-NS3BIL73.js";
66
66
 
67
67
  // src/mount.tsx
68
68
  import { createRoot } from "react-dom/client";
@@ -571,10 +571,11 @@ function release(paint, slot) {
571
571
  paint.waiting.delete(slot);
572
572
  if (paint.waiting.size === 0) draw(paint);
573
573
  }
574
- function slotOf(key, fetcher, aliases) {
574
+ function slotOf(key, fetcher, aliases, patcher = null) {
575
575
  const held2 = slots.get(key);
576
576
  if (held2 !== void 0) {
577
577
  held2.fetcher = fetcher;
578
+ held2.patcher = patcher;
578
579
  held2.aliases = aliases;
579
580
  return held2;
580
581
  }
@@ -588,6 +589,7 @@ function slotOf(key, fetcher, aliases) {
588
589
  paint: null,
589
590
  stagings: [],
590
591
  fetcher,
592
+ patcher,
591
593
  aliases,
592
594
  mounts: /* @__PURE__ */ new Map(),
593
595
  listeners: /* @__PURE__ */ new Set(),
@@ -605,7 +607,7 @@ function tick() {
605
607
  clock += 1;
606
608
  return clock;
607
609
  }
608
- function ask(slot, fresh) {
610
+ function ask(slot, fresh, patch) {
609
611
  if (slot.inflight !== null) {
610
612
  if (fresh) slot.stale = true;
611
613
  return slot.inflight;
@@ -636,7 +638,7 @@ function ask(slot, fresh) {
636
638
  release(paint, slot);
637
639
  });
638
640
  };
639
- const inflight = slot.fetcher(askedAt, slot.answer).then(
641
+ const inflight = (patch ?? slot.fetcher)(askedAt, slot.answer).then(
640
642
  (answer) => settle2(() => {
641
643
  if (askedAt >= slot.askedAt) {
642
644
  slot.answer = answer;
@@ -663,17 +665,17 @@ function readNow(aliases) {
663
665
  function refetchReads(aliases) {
664
666
  for (const slot of readNow(aliases)) void ask(slot, true);
665
667
  }
666
- function askInOnePaint(read2) {
668
+ function askInOnePaint(read2, changes) {
667
669
  if (read2.length === 0) return;
668
670
  const paint = { waiting: new Set(read2), held: [], drawn: false, cap: setTimeout(() => draw(paint), PAINT_CAP_MS) };
669
671
  for (const slot of read2) {
670
672
  if (slot.paint !== null) release(slot.paint, slot);
671
673
  slot.paint = paint;
672
674
  }
673
- for (const slot of read2) void ask(slot, true);
675
+ for (const slot of read2) void ask(slot, true, changes === void 0 || slot.error !== null ? void 0 : slot.patcher?.(slot.answer, changes, slot.askedAt) ?? void 0);
674
676
  }
675
- function refetchPushed(aliases) {
676
- askInOnePaint(readNow(aliases));
677
+ function refetchPushed(aliases, changes) {
678
+ askInOnePaint(readNow(aliases), changes);
677
679
  }
678
680
  var listening = false;
679
681
  function listen() {
@@ -704,7 +706,7 @@ function useKey(key, fetcher, opts = {}) {
704
706
  const focus = opts.focus ?? true;
705
707
  const arrival = opts.arrival ?? true;
706
708
  const aliases = opts.aliases === void 0 ? NO_ALIASES : new Set(opts.aliases);
707
- const slot = key === null ? null : slotOf(key, fetcher, aliases);
709
+ const slot = key === null ? null : slotOf(key, fetcher, aliases, opts.patch ?? null);
708
710
  const mounted = useRef(null);
709
711
  if (mounted.current === null || mounted.current.key !== key) mounted.current = { key, at: clock };
710
712
  const mountedAt = mounted.current.at;
@@ -15234,7 +15236,8 @@ function readCriteria(read2) {
15234
15236
  params: { ...read2.params },
15235
15237
  ...read2.filter === void 0 ? {} : { filter: read2.filter },
15236
15238
  ...sort2 === void 0 ? {} : { sort: sort2 },
15237
- ...read2.aggregate === void 0 ? {} : { aggregate: read2.aggregate }
15239
+ ...read2.aggregate === void 0 ? {} : { aggregate: read2.aggregate },
15240
+ ...read2.fields === void 0 ? {} : { fields: [...read2.fields] }
15238
15241
  };
15239
15242
  }
15240
15243
 
@@ -15274,18 +15277,82 @@ function knownCount(alias, call) {
15274
15277
  if (counted instanceof Promise) leaveToTheRead(counted);
15275
15278
  return counted === null || counted instanceof Promise ? void 0 : counted;
15276
15279
  }
15277
- async function askRows(key, alias, askedAt, call, since = askedAt) {
15280
+ async function readRows(alias, call) {
15278
15281
  const mocked = getMockRows(alias, call);
15279
15282
  if (mocked !== null) return pageOf(await mocked, call);
15280
- const answer = await rpc("query", {
15283
+ return rpc("query", {
15281
15284
  alias,
15282
15285
  ...readCriteria(call),
15283
15286
  ...call.limit === void 0 ? {} : { limit: call.limit },
15284
15287
  ...call.keyset === true ? { keyset: true, ...call.cursor == null ? {} : { cursor: call.cursor } } : { offset: call.offset ?? 0 }
15285
15288
  });
15289
+ }
15290
+ async function askRows(key, alias, askedAt, call, since = askedAt) {
15291
+ const answer = await readRows(alias, call);
15286
15292
  noteAnswer(key, alias, askedAt, answer.rows, since);
15287
15293
  return answer;
15288
15294
  }
15295
+ function patchIds(held2, alias, fields, changes) {
15296
+ const tables = changes[alias];
15297
+ if (held2.refresh === void 0 || held2.truncated || tables === void 0) return null;
15298
+ if (typeof held2.refresh.by === "object" && fields !== void 0 && !fields.includes(held2.refresh.by.column)) return null;
15299
+ const ids = /* @__PURE__ */ new Set();
15300
+ const entries3 = Object.entries(tables);
15301
+ if (entries3.length === 0) return null;
15302
+ for (const [table, named] of entries3) {
15303
+ if (named === null || !held2.refresh.tables.includes(table)) return null;
15304
+ for (const id of named) ids.add(id);
15305
+ }
15306
+ return ids.size === 0 ? null : [...ids];
15307
+ }
15308
+ var idOf = (row2) => String(row2.__source_record_id);
15309
+ async function patchRows(key, alias, askedAt, { held: held2, since, ids }, call) {
15310
+ const { refresh } = held2;
15311
+ if (refresh === void 0) throw new Error(`A patch of "${alias}" needs the answer held to state \`refresh\`.`);
15312
+ const changed2 = new Set(ids);
15313
+ const idFilter = { node_type: "condition", type: "record_id", operator: "is_any_of", value: ids };
15314
+ const patched = (rows, reread) => {
15315
+ noteAnswer(key, alias, askedAt, reread, since);
15316
+ return { ...held2, rows };
15317
+ };
15318
+ if (refresh.by === "record") {
15319
+ const read2 = await readRows(alias, { ...call, filter: within(call.filter, idFilter) });
15320
+ const answered2 = new Map(read2.rows.map((row2) => [idOf(row2), row2]));
15321
+ const heldIds = new Set(held2.rows.map(idOf));
15322
+ const kept = held2.rows.flatMap((row2) => {
15323
+ if (!changed2.has(idOf(row2))) return [row2];
15324
+ const next = answered2.get(idOf(row2));
15325
+ return next === void 0 ? [] : [next];
15326
+ });
15327
+ return patched([...kept, ...read2.rows.filter((row2) => !heldIds.has(idOf(row2)))], read2.rows);
15328
+ }
15329
+ const { column } = refresh.by;
15330
+ const groupsOf2 = (row2) => readLinks(row2[column]).map((link2) => link2.id);
15331
+ const now = await readRows(alias, { params: call.params, filter: idFilter, fields: [column], offset: 0 });
15332
+ const groups = /* @__PURE__ */ new Set();
15333
+ let empty = false;
15334
+ for (const row2 of [...held2.rows.filter((one) => changed2.has(idOf(one))), ...now.rows]) {
15335
+ const named = groupsOf2(row2);
15336
+ if (named.length === 0) empty = true;
15337
+ for (const id of named) groups.add(id);
15338
+ }
15339
+ const inGroup = (row2) => {
15340
+ const named = groupsOf2(row2);
15341
+ return named.length === 0 ? empty : named.some((id) => groups.has(id));
15342
+ };
15343
+ const parts = [
15344
+ ...groups.size === 0 ? [] : [{ node_type: "condition", field_key: column, operator: "has_any_of", value: [...groups] }],
15345
+ ...empty ? [{ node_type: "condition", field_key: column, operator: "is_empty" }] : []
15346
+ ];
15347
+ const [only] = parts;
15348
+ if (only === void 0) return patched(held2.rows, []);
15349
+ if (held2.rows.filter(inGroup).length * 2 > held2.rows.length) return askRows(key, alias, askedAt, call);
15350
+ const again = await readRows(alias, { ...call, filter: within(call.filter, parts.length === 1 ? only : { node_type: "group", logic: "or", children: parts }) });
15351
+ if (again.truncated) return askRows(key, alias, askedAt, call);
15352
+ const at2 = held2.rows.findIndex(inGroup);
15353
+ const rest = held2.rows.filter((row2) => !inGroup(row2));
15354
+ return patched(at2 < 0 ? [...rest, ...again.rows] : [...rest.slice(0, at2), ...again.rows, ...rest.slice(at2)], again.rows);
15355
+ }
15289
15356
  async function askCount(key, alias, askedAt, call) {
15290
15357
  const mocked = mockCount(alias, call);
15291
15358
  if (mocked !== null) return mocked;
@@ -15320,24 +15387,31 @@ function useQuery(alias, params = {}, opts = {}) {
15320
15387
  const totalAsked = opts.total ?? opts.page !== void 0;
15321
15388
  const by = typeof totalAsked === "object" && "by" in totalAsked ? totalAsked.by : void 0;
15322
15389
  const where = typeof totalAsked === "object" && "where" in totalAsked ? totalAsked.where : void 0;
15323
- const call = JSON.stringify([params, filter2 ?? null, sort2 ?? null]);
15390
+ const fields = opts.fields;
15391
+ const call = JSON.stringify([params, filter2 ?? null, sort2 ?? null, fields ?? null]);
15324
15392
  const mocking = hasMockFlag();
15325
15393
  const [paging, setPaging] = useState3({ call, page: 0 });
15326
15394
  const held2 = opts.page === void 0 ? void 0 : opts.pageAt;
15327
15395
  const page = held2 !== void 0 ? Math.max(0, held2.at) : opts.page === void 0 || paging.call !== call ? 0 : paging.page;
15328
15396
  const turn2 = held2?.onChange;
15329
15397
  const setPage = useCallback5((next) => turn2 === void 0 ? setPaging({ call, page: Math.max(0, next) }) : turn2(Math.max(0, next)), [call, turn2]);
15330
- const rowsKey = !enabled || !wantsRows || opts.more !== void 0 ? null : JSON.stringify(["rows", alias, call, opts.limit ?? null, opts.page ?? null, page, ...apart]);
15398
+ const patches = opts.refresh === "changed" && opts.limit === void 0 && opts.page === void 0 && opts.more === void 0;
15399
+ const rowsKey = !enabled || !wantsRows || opts.more !== void 0 ? null : JSON.stringify(["rows", alias, call, opts.limit ?? null, opts.page ?? null, page, opts.refresh ?? null, ...apart]);
15400
+ const patchRowsRead = !patches ? void 0 : (held3, changes, since) => {
15401
+ const ids = held3 === void 0 ? null : patchIds(held3, alias, fields, changes);
15402
+ return held3 === void 0 || ids === null ? null : (askedAt) => patchRows(rowsKey ?? "", alias, askedAt, { held: held3, ids, since }, { params, filter: filter2, sort: sort2, ...fields === void 0 ? {} : { fields }, offset: 0 });
15403
+ };
15331
15404
  const rows = useKey(
15332
15405
  rowsKey,
15333
15406
  (askedAt) => askRows(rowsKey ?? "", alias, askedAt, {
15334
15407
  params,
15335
15408
  filter: filter2,
15336
15409
  sort: sort2,
15410
+ ...fields === void 0 ? {} : { fields },
15337
15411
  limit: opts.page ?? opts.limit,
15338
15412
  offset: opts.page === void 0 ? 0 : page * opts.page
15339
15413
  }),
15340
- { focus, aliases, known: mocking ? () => knownRows(alias, { params, filter: filter2, sort: sort2, limit: opts.page ?? opts.limit, offset: opts.page === void 0 ? 0 : page * opts.page }) : void 0 }
15414
+ { focus, aliases, patch: patchRowsRead, known: mocking ? () => knownRows(alias, { params, filter: filter2, sort: sort2, limit: opts.page ?? opts.limit, offset: opts.page === void 0 ? 0 : page * opts.page }) : void 0 }
15341
15415
  );
15342
15416
  const feedKey = !enabled || !wantsRows || opts.more === void 0 ? null : JSON.stringify(["feed", alias, call, opts.more, ...apart]);
15343
15417
  const feedSize = opts.more ?? 0;
@@ -15350,13 +15424,13 @@ function useQuery(alias, params = {}, opts = {}) {
15350
15424
  const last2 = current?.pages.at(-1);
15351
15425
  if (current !== void 0 && last2 !== void 0 && wants > current.pages.length && last2.next_cursor != null) {
15352
15426
  const since = current.pages[0]?.askedAt ?? askedAt;
15353
- const next = await askRows(key, alias, askedAt, { params, filter: filter2, sort: sort2, limit: feedSize, cursor: last2.next_cursor, keyset: true }, since);
15427
+ const next = await askRows(key, alias, askedAt, { params, filter: filter2, sort: sort2, ...fields === void 0 ? {} : { fields }, limit: feedSize, cursor: last2.next_cursor, keyset: true }, since);
15354
15428
  return { pages: [...current.pages, { ...next, askedAt }] };
15355
15429
  }
15356
15430
  const pages = [];
15357
15431
  let cursor = null;
15358
15432
  for (let at2 = 0; at2 < Math.min(wants, current?.pages.length ?? 1); at2 += 1) {
15359
- const next = await askRows(key, alias, askedAt, { params, filter: filter2, sort: sort2, limit: feedSize, cursor, keyset: true });
15433
+ const next = await askRows(key, alias, askedAt, { params, filter: filter2, sort: sort2, ...fields === void 0 ? {} : { fields }, limit: feedSize, cursor, keyset: true });
15360
15434
  pages.push({ ...next, askedAt });
15361
15435
  cursor = next.next_cursor ?? null;
15362
15436
  if (cursor === null) break;
@@ -15447,22 +15521,33 @@ async function askGroups(key, alias, askedAt, aggregate, call) {
15447
15521
  noteAnswer(key, alias, askedAt, []);
15448
15522
  return answer;
15449
15523
  }
15450
- async function askCall(key, call, askedAt) {
15524
+ async function askCall(key, call, askedAt, patch) {
15451
15525
  const params = call.params ?? {};
15452
15526
  const sort2 = statedSort(call.sort);
15453
15527
  const rows = call.rows === false ? null : settle(
15454
- call.aggregate !== void 0 ? askGroups(key, call.alias, askedAt, call.aggregate, { params, filter: call.filter, sort: sort2 }) : askRows(key, call.alias, askedAt, { params, filter: call.filter, sort: sort2 })
15528
+ patch !== void 0 ? patchRows(key, call.alias, askedAt, patch, { params, filter: call.filter, sort: sort2, ...call.fields === void 0 ? {} : { fields: call.fields }, offset: 0 }) : call.aggregate !== void 0 ? askGroups(key, call.alias, askedAt, call.aggregate, { params, filter: call.filter, sort: sort2 }) : askRows(key, call.alias, askedAt, { params, filter: call.filter, sort: sort2, ...call.fields === void 0 ? {} : { fields: call.fields } })
15455
15529
  );
15456
15530
  const count = call.total === true ? settle(askCount(key, call.alias, askedAt, { params, filter: call.filter })) : null;
15457
15531
  return { rows: rows === null ? null : await rows, count: count === null ? null : await count };
15458
15532
  }
15459
15533
  function useQueries(calls, opts = {}) {
15460
15534
  const enabled = opts.enabled ?? true;
15461
- const shape = JSON.stringify(calls.map((call) => [call.alias, call.params ?? {}, call.filter ?? null, statedSort(call.sort) ?? null, call.aggregate ?? null, call.total ?? false, call.rows ?? true]));
15535
+ const shape = JSON.stringify(calls.map((call) => [call.alias, call.params ?? {}, call.filter ?? null, statedSort(call.sort) ?? null, call.aggregate ?? null, call.total ?? false, call.rows ?? true, call.fields ?? null, call.refresh ?? null]));
15462
15536
  const key = !enabled || calls.length === 0 ? null : JSON.stringify(["calls", shape]);
15463
15537
  const answers = useKey(key, (askedAt) => Promise.all(calls.map((call) => askCall(key ?? "", call, askedAt))), {
15464
15538
  focus: opts.revalidateOnFocus ?? true,
15465
- aliases: calls.map((call) => call.alias)
15539
+ aliases: calls.map((call) => call.alias),
15540
+ // A call that opted in and can be patched is; the others of the key are asked whole in the same push.
15541
+ patch: (held2, changes, since) => {
15542
+ if (held2 === void 0) return null;
15543
+ const patched = calls.map((call, at2) => {
15544
+ const rows = held2[at2]?.rows?.answer;
15545
+ if (call.refresh !== "changed" || call.aggregate !== void 0 || call.rows === false || rows === void 0) return void 0;
15546
+ const ids = patchIds(rows, call.alias, call.fields, changes);
15547
+ return ids === null ? void 0 : { held: rows, since, ids };
15548
+ });
15549
+ return patched.every((one) => one === void 0) ? null : (askedAt) => Promise.all(calls.map((call, at2) => askCall(key ?? "", call, askedAt, patched[at2])));
15550
+ }
15466
15551
  });
15467
15552
  const version2 = useWrittenVersion();
15468
15553
  return useMemo3(
package/dist/queries.d.ts CHANGED
@@ -58,6 +58,15 @@ export interface QueryOptions<C extends string = string> {
58
58
  };
59
59
  /** `false` reads no rows: a total alone. Default `true`. */
60
60
  rows?: boolean;
61
+ /** The columns each row is read with, beside its address (`__source_record_id`, …): a screen drawing a few columns of a
62
+ * wide query names them, and `[]` reads which rows the set holds alone. Part of the read's key. Absent, every column. */
63
+ fields?: readonly C[];
64
+ /**
65
+ * `"changed"`: a realtime push re-reads only the rows it changed, where the server states the rows can be answered so
66
+ * (a row keeps its place, a new row lands last), instead of the whole read. Not with `limit`, `page` or `more`. Part of the
67
+ * read's key. Default: the whole read again.
68
+ */
69
+ refresh?: "changed";
61
70
  }
62
71
  export interface QueryState<R> {
63
72
  rows: R[];
@@ -130,6 +139,10 @@ export interface QueryCall {
130
139
  total?: boolean;
131
140
  /** `false` reads no rows: a total alone. Default `true`. */
132
141
  rows?: boolean;
142
+ /** The output columns each row holds, beside its address (`__source_record_id`, …); `[]` reads the rows' records alone. Absent, every column. */
143
+ fields?: readonly string[];
144
+ /** `"changed"`: a push re-reads only the rows it changed where the server states they can be answered so ([useQuery](./queries.ts)'s `refresh`). Part of the key. */
145
+ refresh?: "changed";
133
146
  }
134
147
  /**
135
148
  * Several declared queries read together, one state per call in the calls' order — for a surface whose
package/dist/router.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  setUrlParams,
7
7
  settleOpen,
8
8
  subscribeOpen
9
- } from "./chunk-J2TOGQ4C.js";
9
+ } from "./chunk-NS3BIL73.js";
10
10
 
11
11
  // src/router.tsx
12
12
  import { useEffect, useLayoutEffect, useRef } from "react";
package/dist/rpc.d.ts CHANGED
@@ -180,7 +180,7 @@ export declare function postHostNotification(message: HostNotification): void;
180
180
  * host owns the realtime socket because the frame holds no credentials; inert
181
181
  * standalone.
182
182
  */
183
- export declare function subscribeQueriesChanged(cb: (aliases: string[]) => void): () => void;
183
+ export declare function subscribeQueriesChanged(cb: (aliases: string[], changes: QueryChanges | undefined) => void): () => void;
184
184
  export declare function registerQueryAlias(alias: string): () => void;
185
185
  /**
186
186
  * Re-read after this app's own write — the realtime push is too slow for it.
@@ -189,8 +189,10 @@ export declare function registerQueryAlias(alias: string): () => void;
189
189
  * tables a workflow touched.
190
190
  */
191
191
  export declare function notifyLocalWrite(reads?: readonly string[]): void;
192
- /** What a host tells the app: the queries named are stale, and every mounted hook of one reads again. */
193
- export declare function queriesChanged(aliases: readonly string[]): void;
192
+ /** Per alias named, each changed table it reads: the ids of the records that changed, or null where unknown. */
193
+ export type QueryChanges = Readonly<Record<string, Readonly<Record<string, readonly string[] | null>>>>;
194
+ /** What a host tells the app: the queries named are stale, and every mounted hook of one reads again. `changes`, when the host names it, says which records. */
195
+ export declare function queriesChanged(aliases: readonly string[], changes?: QueryChanges): void;
194
196
  /**
195
197
  * Keeps the loading cover up until the returned release runs, for a page that has not yet drawn what its requests will
196
198
  * feed. Releasing the last hold starts the two-frame check; releasing again does nothing.
package/dist/store.d.ts CHANGED
@@ -1,5 +1,11 @@
1
+ import { type QueryChanges } from "./rpc.js";
1
2
  /** How a key is read: from when the request was sent and the answer it holds now (a feed grows from it). */
2
3
  export type Fetcher<T> = (askedAt: number, current: T | undefined) => Promise<T>;
4
+ /**
5
+ * How a key opted in to partial refresh answers a push: the fetcher that re-reads only what `changes` touched of the
6
+ * answer held (asked at `heldAskedAt`), or `null` where this push must be asked whole.
7
+ */
8
+ export type Patcher<T> = (held: T | undefined, changes: QueryChanges, heldAskedAt: number) => Fetcher<T> | null;
3
9
  /**
4
10
  * A focus or reconnect within this long of a key's last ask asks nothing: returns to the tab a minute apart are one
5
11
  * visit. A push asks at once whatever this says, so what this bounds is only what no push carries — a dead channel, a
@@ -13,8 +19,8 @@ export declare function refetchReads(aliases: readonly string[] | undefined): vo
13
19
  /** `refetchReads`, settled once every key a screen reads now holds an answer asked after this call — or its refusal. */
14
20
  export declare function readsAnswered(aliases: readonly string[]): Promise<void>;
15
21
  /** The host's push, naming the aliases whose tables moved: each key reading one asked again (`refetchReads`), in one
16
- * paint. */
17
- export declare function refetchPushed(aliases: readonly string[]): void;
22
+ * paint — a key that opted in to partial refresh re-reading only what `changes` names of it, where that applies. */
23
+ export declare function refetchPushed(aliases: readonly string[], changes?: QueryChanges): void;
18
24
  export interface Held<T> {
19
25
  /** The answer shown: each staged value over it, else the answer; the last key's while a new key is first asked. */
20
26
  data: T | undefined;
@@ -40,6 +46,8 @@ export interface KeyOptions<T> {
40
46
  arrival?: boolean;
41
47
  /** The query aliases the key reads. */
42
48
  aliases?: readonly string[];
49
+ /** Where a push names only the records it changed, the fetcher re-reading just those of the answer held. */
50
+ patch?: Patcher<T>;
43
51
  /** An answer known without asking — a design-time fixture's — shown from the first render. */
44
52
  known?: (askedAt: number) => T | undefined;
45
53
  }
@@ -22,7 +22,7 @@ untyped. It is written from the app's live bindings by `lotics app deploy` and
22
22
  | `useQuery(alias, params?, { page: n })` | one numbered page of `n` rows, `total`, `pageCount`, `setPage` | numbered, jumpable pages |
23
23
  | `useQuery(alias, params?, { more: n })` | accumulated `rows` + `loadMore` | infinite scroll / "load more" feeds |
24
24
  | `useQuery(alias, params?, { rows: false, total: true })` | `total` only, no rows (`total: { by: column }` or `total: { where: { name: filter } }` adds `counts`) | a facet chip, a queue badge, an "N awaiting approval" tile — the size of a set you are not listing |
25
- | `useQueries(calls, opts?)` | one state per `{ alias, params?, filter?, sort?, aggregate?, total?, rows? }`, in order — a `sort` orders that call's rows before the cap cuts them | reads that are DATA — a list known only at render, one read per item, or one count per stage (`rows: false, total: true`, each state's `.total`); the deploy's alias scan reads a list as dynamic, so every alias in it is still declared. With `aggregate` a call answers the groups of its filtered rows instead of the rows ([queries](./queries.md)) |
25
+ | `useQueries(calls, opts?)` | one state per `{ alias, params?, filter?, sort?, aggregate?, total?, rows?, fields? }`, in order — a `sort` orders that call's rows before the cap cuts them | reads that are DATA — a list known only at render, one read per item, or one count per stage (`rows: false, total: true`, each state's `.total`); the deploy's alias scan reads a list as dynamic, so every alias in it is still declared. With `aggregate` a call answers the groups of its filtered rows instead of the rows ([queries](./queries.md)) |
26
26
  | `queryAll(alias, params?, { filter, sort })` | a promise of every row | outside React, for a job that must hold the whole narrowed set in the browser (the ids an act runs on): it asks page after page until the server says the set ended, never stopping at the 10,000-row cap. The server's rows as stored — no write of this app is drawn over them |
27
27
  | `exportQuery(alias, { params, filter, sort, tabs?, report, file, labels? })` | a promise of an `ExportedFile`: `{ filename, mime_type, url, size, created_at }` | every row the narrowed set holds, made into one file by the server — no row reaches the browser. `tabs` (2 to 5, each `{ tab, label, filter?, sort?, totals? }`; `totals` is `{ query, params, via, columns }`, the read of a totals tab beside its rows, joined on the link column `via`, refused where that read lacks `via` or a column or a group links several rows; the groups naming one row, one per kind of row a totals tab adds, are added up) are each read as the export's own rows are — same query and params, under the tab's own filter and sort (absent, the declared order). `report` is `{ title, lines, readings }`; `file` is `{ kind: "workbook", language, sheet, columns }` (the report workbook, its head closing with the moment the server made it, each column `{ key, header, type }` an output column of the query — a `number` one on a number column, a `date` one on a date or datetime; with `tabs`, one sheet per tab named by its `label` in place of `sheet`). `labels`, by `select` output column, the words each option key prints as in the file — a cell no field of the query names (a union's literal column) arrives as its bare key; a cell its field's option names prints as that, a key the map lacks as itself, and a column no select of the query holds as it is. Past 20,000 rows, in any tab, it rejects, never cuts; each caller makes at most 60 exports a minute. The file has no `id` — it is a download, not a workspace file a workflow or a field takes: its `url` is signed for the caller for at most an hour, so download it with `downloadFileFromUrl(url, filename)` (`@lotics/ui/download`) when the promise resolves — a tab `openExternal` opens seconds after the click is a pop-up the browser blocks; the server deletes the file a day after it is made |
28
28
  | `exportApp(list, narrowing)` | a promise of an `ExportedFile`, as `exportQuery`'s | the workbook the server makes of a List of a JSON app that states `export: true`, named by its View id (a root List's key; `<page entity>.<key>` for a List on a page; a custom-code app makes its files with `exportQuery`), over the rows as `narrowing` states it (`tab`, `status`, `filters`, `search`, `overdue`, `waiting`, `period`, `window`, `sort`, `group`, `folder`, `row`; a `filters` entry `null` clears the chip the register opens on; `row` is the id of the row a List below a Record page hangs from, required there and refused elsewhere): the server reads the rows, the band's readings and the names under the caller's own access. Download it as `exportQuery`'s |
@@ -88,7 +88,7 @@ rows (below) — but a count over the whole set is `total`, not a length.
88
88
  ## Options
89
89
 
90
90
  `useQuery` takes these (`QueryOptions`); `useQueries` takes `enabled` and `revalidateOnFocus` for
91
- all its calls, and each call states its own `filter`, `sort`, `total` and `rows`:
91
+ all its calls, and each call states its own `filter`, `sort`, `total`, `rows` and `fields`:
92
92
 
93
93
  | Option | Type | Default | Effect |
94
94
  |---|---|---|---|
@@ -103,6 +103,8 @@ all its calls, and each call states its own `filter`, `sort`, `total` and `rows`
103
103
  | `more` | `number` | — | A keyset feed read `more` rows at a time: `loadMore`, `hasMore`, `loadingMore`. |
104
104
  | `total` | `boolean \| { by: column } \| { where: { name: filter } }` | `true` with `page`, else `false` | The whole set's count, its own request (`total`); with `by`, a count per value of that column, or with `where`, a count per named filter within `filter`, from the same scan (`counts`). |
105
105
  | `rows` | `boolean` | `true` | `false` reads no rows — a total alone. |
106
+ | `fields` | `column[]` | every column | The columns each row is read with, beside its addressing columns: a screen drawing three columns of a wide query names those three, and `[]` reads which rows the set holds and nothing of them. A name the query does not answer is refused. Not with `total` alone or `aggregate`. Part of the read's key. |
107
+ | `refresh` | `"changed"` | whole re-read | A realtime push re-reads only the records it changed, where the server states the rows can be answered so: a row keeps its place, a new row lands last. Any other change, a capped read (`limit`, `page`, `more`) or a read the server cut asks the whole read again. Part of the read's key; also a key of a `useQueries` call. |
106
108
 
107
109
  Runtime `sort`/`filter` are **bounded to the named query's output columns**, twice over. At
108
110
  compile time, `field_key` on a typed alias is the literal union of the columns the query projects —
@@ -170,6 +172,7 @@ write it as `{ node_type: "condition", type: "record_id", operator, value }`.
170
172
  changes only (a schema edit does not push), and a **standalone/public app has no host**, so
171
173
  those apps keep focus/reconnect freshness alone. Push is absent whenever the channel cannot
172
174
  connect, so never treat it as a replacement for pull.
175
+ A read with `refresh: "changed"` re-reads only the records a push names (rows that share a group with them, for a read the server partitions by a link) instead of the whole read.
173
176
  - **A `more` feed does not re-read on arrival** — the one exception. A warm feed re-mounted
174
177
  reads nothing, because re-reading it would reshuffle the feed under a reader scrolling it; a cold
175
178
  key still reads, and focus / reconnect / a realtime push / this app's own write still refresh.
@@ -385,8 +388,7 @@ Wire shapes per output column type:
385
388
 
386
389
  Row-level (non-grouped) queries additionally carry system columns: `__source_record_id` /
387
390
  `__source_table_id` / `__source_locked` (source addressing — pass `__source_record_id` to
388
- workflows), `__created_at` / `__updated_at` (record timestamps), and per-projection `__src_field_*`
389
- metadata. A grouped query collapses rows and answers each of these as `null`. Details:
391
+ workflows), and `__created_at` / `__updated_at` (record timestamps). A grouped query collapses rows and answers each of these as `null`. Details:
390
392
  [./queries.md](./queries.md).
391
393
 
392
394
  A row is typed from the alias's own projection (`AppQueryColumns` in `.lotics/app_queries.d.ts`),
package/docs/queries.md CHANGED
@@ -136,17 +136,17 @@ Delivery-layer enrichment (applied to the response, per request):
136
136
 
137
137
  Every row-level query carries auto-injected addressing columns alongside your output columns:
138
138
  `__source_record_id`, `__source_table_id`, `__source_locked` (decode with `readLocked`),
139
- `__created_at`, `__updated_at`, and per-projection `__src_field_<output>` metadata. You never
139
+ `__created_at` and `__updated_at`. You never
140
140
  declare these; output names starting with `__source_` / `__src_field_`, or equal to
141
141
  `__created_at` / `__updated_at`, are **reserved** and rejected. A `group` collapses rows and
142
142
  answers its addressing as `null` (grouped results can't be written through or matched by `record_id`); a `join`
143
143
  keeps the **left** side's addressing.
144
144
 
145
- A caller outside the app's organization — a public-app visitor, or a member of another
146
- organization — receives your output columns and the five addressing columns above, and nothing
147
- else: no `__src_field_*`, and `columns` carries each column's `name`, `type` and `nullable`
148
- only. Read what a row holds through your projection and the `read*` helpers, never through
149
- `__src_field_*`.
145
+ A row holds your output columns and the five addressing columns above, and nothing else; a member
146
+ of the app's organization also reads who may change a locked row (`readLockedBy`). For a caller
147
+ outside the app's organization — a public-app visitor, or a member of another organization —
148
+ `columns` carries each column's `name`, `type` and `nullable` only. Read what a row holds through
149
+ your projection and the `read*` helpers.
150
150
 
151
151
  `__created_at` / `__updated_at` arrive as ISO-8601 **instants** with an offset
152
152
  (`"2026-07-05T09:00:00.000Z"`), not a wall-clock — read them with `readCreatedAt(row)` /
@@ -248,8 +248,8 @@ right-side column nullable. Addressing (write-through, `record_id` filtering) fo
248
248
  column name *and* type (column j of every source must have the same name and type). Use
249
249
  `project` with `{ "literal": null }` fills (typed by the column's declared `type`) to align
250
250
  heterogeneous tables. Source addressing survives per column only when every arm agrees on the
251
- source table/field; per-row `__src_field_*` metadata still tracks which field each row's cell
252
- came from.
251
+ source table/field; a select column whose arms take different fields still answers each row's
252
+ options by name, read from the field that row's cell came from.
253
253
 
254
254
  A select column whose arms project different selects takes every arm's options: a filter value
255
255
  matches the arm whose select holds that key, and an option **name** stands for each arm's key
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lotics/app-sdk",
3
- "version": "0.133.47",
3
+ "version": "0.133.48",
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": {