@ai-matrx/records 0.80.4 → 0.80.8

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 (71) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +19 -0
  3. package/dist/app-table/index.cjs +88 -23
  4. package/dist/app-table/index.cjs.map +1 -1
  5. package/dist/app-table/index.d.cts +7 -7
  6. package/dist/app-table/index.d.ts +7 -7
  7. package/dist/app-table/index.js +88 -23
  8. package/dist/app-table/index.js.map +1 -1
  9. package/dist/{client-CB_Klj1P.d.ts → client-D1LTezMZ.d.ts} +5 -5
  10. package/dist/{client-D0yGEof4.d.cts → client-DLIKeBWF.d.cts} +5 -5
  11. package/dist/core/index.cjs +97 -31
  12. package/dist/core/index.cjs.map +1 -1
  13. package/dist/core/index.d.cts +21 -12
  14. package/dist/core/index.d.ts +21 -12
  15. package/dist/core/index.js +97 -31
  16. package/dist/core/index.js.map +1 -1
  17. package/dist/data/index.cjs +88 -23
  18. package/dist/data/index.cjs.map +1 -1
  19. package/dist/data/index.d.cts +6 -6
  20. package/dist/data/index.d.ts +6 -6
  21. package/dist/data/index.js +88 -23
  22. package/dist/data/index.js.map +1 -1
  23. package/dist/{declareTable-l7ktxN6p.d.cts → declareTable-02uao-5n.d.cts} +4 -4
  24. package/dist/{declareTable-DoYVueVF.d.ts → declareTable-C5FlIS0z.d.ts} +4 -4
  25. package/dist/{field-6UtYgFeu.d.ts → field-BIJiFPc0.d.ts} +1 -1
  26. package/dist/{field-DpJR_5Pe.d.cts → field-snQG2jMq.d.cts} +1 -1
  27. package/dist/index.cjs +2 -0
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +7 -7
  30. package/dist/index.d.ts +7 -7
  31. package/dist/index.js +2 -0
  32. package/dist/index.js.map +1 -1
  33. package/dist/memory/index.cjs +1 -0
  34. package/dist/memory/index.cjs.map +1 -1
  35. package/dist/memory/index.d.cts +6 -6
  36. package/dist/memory/index.d.ts +6 -6
  37. package/dist/memory/index.js +1 -0
  38. package/dist/memory/index.js.map +1 -1
  39. package/dist/{ports-CiEYhwi5.d.ts → ports-Y5gLbCXe.d.ts} +1 -1
  40. package/dist/{ports-CE7umTp-.d.cts → ports-y1QNfM80.d.cts} +1 -1
  41. package/dist/react/index.cjs +89 -27
  42. package/dist/react/index.cjs.map +1 -1
  43. package/dist/react/index.d.cts +6 -1
  44. package/dist/react/index.d.ts +6 -1
  45. package/dist/react/index.js +89 -27
  46. package/dist/react/index.js.map +1 -1
  47. package/dist/realtime/index.d.cts +2 -2
  48. package/dist/realtime/index.d.ts +2 -2
  49. package/dist/{record-CvqV8wyO.d.cts → record-1yDCn169.d.cts} +6 -1
  50. package/dist/{record-CvqV8wyO.d.ts → record-1yDCn169.d.ts} +6 -1
  51. package/dist/{subscription-CC0kgkwa.d.cts → subscription-B_WaT-kr.d.cts} +1 -1
  52. package/dist/{subscription-DjkuDMcX.d.ts → subscription-CUok1vAm.d.ts} +1 -1
  53. package/dist/{table-kind-FMYq3nCr.d.ts → table-kind-COmkYYkc.d.ts} +3 -3
  54. package/dist/{table-kind-DHpMEOHd.d.cts → table-kind-LodkBhCZ.d.cts} +3 -3
  55. package/dist/templates/index.cjs +3 -2
  56. package/dist/templates/index.cjs.map +1 -1
  57. package/dist/templates/index.d.cts +9 -9
  58. package/dist/templates/index.d.ts +9 -9
  59. package/dist/templates/index.js +3 -2
  60. package/dist/templates/index.js.map +1 -1
  61. package/dist/{types-DuceX7js.d.cts → types-BJGTxu3Y.d.cts} +2 -2
  62. package/dist/{types-BbCZJh1C.d.ts → types-C5-AaPa6.d.ts} +2 -2
  63. package/dist/{types-B4LF3sFx.d.ts → types-CU_Tn2Np.d.ts} +2 -2
  64. package/dist/{types-Flsf_KU5.d.cts → types-yBZLtxrZ.d.cts} +2 -2
  65. package/dist/use-cases/index.cjs.map +1 -1
  66. package/dist/use-cases/index.d.cts +5 -5
  67. package/dist/use-cases/index.d.ts +5 -5
  68. package/dist/use-cases/index.js.map +1 -1
  69. package/dist/{validate-EvZGkD96.d.cts → validate-CE6qpJIb.d.cts} +1 -1
  70. package/dist/{validate-DyVwSD74.d.ts → validate-Rz9djP6H.d.ts} +1 -1
  71. package/package.json +1 -1
@@ -1,9 +1,9 @@
1
- import { bK as EntityRefWithWords } from '../table-kind-DHpMEOHd.cjs';
2
- import { U as Uuid, h as RecordsResult, n as RecordPageSort, m as ReadRow } from '../record-CvqV8wyO.cjs';
3
- import { R as RecordsClient } from '../client-D0yGEof4.cjs';
4
- import { b as Field } from '../field-DpJR_5Pe.cjs';
5
- import { u as RuleExpression } from '../subscription-CC0kgkwa.cjs';
6
- import '../ports-CE7umTp-.cjs';
1
+ import { bK as EntityRefWithWords } from '../table-kind-LodkBhCZ.cjs';
2
+ import { U as Uuid, h as RecordsResult, n as RecordPageSort, m as ReadRow } from '../record-1yDCn169.cjs';
3
+ import { R as RecordsClient } from '../client-DLIKeBWF.cjs';
4
+ import { b as Field } from '../field-snQG2jMq.cjs';
5
+ import { u as RuleExpression } from '../subscription-B_WaT-kr.cjs';
6
+ import '../ports-y1QNfM80.cjs';
7
7
 
8
8
  /** §0. A link to any thing: `{token, id, label}`. A custom row's token is `record`. Every link reads as `EntityRef[]`. */
9
9
  type EntityRef = EntityRefWithWords;
@@ -1,9 +1,9 @@
1
- import { bK as EntityRefWithWords } from '../table-kind-FMYq3nCr.js';
2
- import { U as Uuid, h as RecordsResult, n as RecordPageSort, m as ReadRow } from '../record-CvqV8wyO.js';
3
- import { R as RecordsClient } from '../client-CB_Klj1P.js';
4
- import { b as Field } from '../field-6UtYgFeu.js';
5
- import { u as RuleExpression } from '../subscription-DjkuDMcX.js';
6
- import '../ports-CiEYhwi5.js';
1
+ import { bK as EntityRefWithWords } from '../table-kind-COmkYYkc.js';
2
+ import { U as Uuid, h as RecordsResult, n as RecordPageSort, m as ReadRow } from '../record-1yDCn169.js';
3
+ import { R as RecordsClient } from '../client-D1LTezMZ.js';
4
+ import { b as Field } from '../field-BIJiFPc0.js';
5
+ import { u as RuleExpression } from '../subscription-CUok1vAm.js';
6
+ import '../ports-Y5gLbCXe.js';
7
7
 
8
8
  /** §0. A link to any thing: `{token, id, label}`. A custom row's token is `record`. Every link reads as `EntityRef[]`. */
9
9
  type EntityRef = EntityRefWithWords;
@@ -194,6 +194,32 @@ function takePrimedTablePageBundle(organizationId, tableId, viewId) {
194
194
  return Date.now() - held.at < PRIMED_TTL_MS ? held.answer : null;
195
195
  }
196
196
 
197
+ // src/core/recordChanges.ts
198
+ var listeners = /* @__PURE__ */ new Set();
199
+ function announceRecordChanged(recordId) {
200
+ for (const listener of [...listeners]) {
201
+ try {
202
+ listener(recordId);
203
+ } catch (thrown) {
204
+ console.error("[@ai-matrx/records] a record-change listener threw", thrown);
205
+ }
206
+ }
207
+ }
208
+ function onRecordChanged(listener) {
209
+ listeners.add(listener);
210
+ return () => listeners.delete(listener);
211
+ }
212
+ var tableListeners = /* @__PURE__ */ new Set();
213
+ function announceTableStructureChanged(tableId) {
214
+ for (const listener of [...tableListeners]) {
215
+ try {
216
+ listener(tableId);
217
+ } catch (thrown) {
218
+ console.error("[@ai-matrx/records] a table-structure listener threw", thrown);
219
+ }
220
+ }
221
+ }
222
+
197
223
  // src/archive.ts
198
224
  var DEFAULT_ARCHIVE_LANE = "org";
199
225
 
@@ -1349,6 +1375,7 @@ var STORE_DOORS = [
1349
1375
  { name: "record_filter_sql", args: "p_organization_id uuid, p_table_id uuid, p_filter jsonb", returns: "text", security: "invoker" },
1350
1376
  { name: "record_headers", args: "p_organization_id uuid, p_ids uuid[]", returns: "TABLE(id uuid, table_id uuid, created_at timestamp with time zone, updated_at timestamp with time zone, version integer, deleted_at timestamp with time zone, mine boolean, created_by uuid)", security: "definer" },
1351
1377
  { name: "record_history", args: "p_organization_id uuid, p_record_id uuid, p_limit integer DEFAULT 200, p_offset integer DEFAULT 0", returns: "TABLE(version integer, occurred_at timestamp with time zone, operation text, operation_label text, actor jsonb, changes jsonb, migration_id uuid, undoable boolean)", security: "definer" },
1378
+ { name: "record_page_bundle", args: "p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "invoker" },
1352
1379
  { name: "record_platform_keys", args: "", returns: "text[]", security: "invoker" },
1353
1380
  { name: "record_relation_edges", args: "p_organization_id uuid, p_id uuid, p_table_id uuid, p_data_class text, p_data jsonb, p_deleted_at timestamp with time zone", returns: "TABLE(target_id uuid, edge_role text, field_id uuid, ord integer)", security: "invoker" },
1354
1381
  { name: "record_reparent", args: "p_organization_id uuid, p_record_id uuid, p_parent_id uuid", returns: "void", security: "definer" },
@@ -2446,28 +2473,6 @@ var DRILL_DOORS = {
2446
2473
  rows: "drill_rows"
2447
2474
  };
2448
2475
 
2449
- // src/core/recordChanges.ts
2450
- var listeners = /* @__PURE__ */ new Set();
2451
- function announceRecordChanged(recordId) {
2452
- for (const listener of [...listeners]) {
2453
- try {
2454
- listener(recordId);
2455
- } catch (thrown) {
2456
- console.error("[@ai-matrx/records] a record-change listener threw", thrown);
2457
- }
2458
- }
2459
- }
2460
- var tableListeners = /* @__PURE__ */ new Set();
2461
- function announceTableStructureChanged(tableId) {
2462
- for (const listener of [...tableListeners]) {
2463
- try {
2464
- listener(tableId);
2465
- } catch (thrown) {
2466
- console.error("[@ai-matrx/records] a table-structure listener threw", thrown);
2467
- }
2468
- }
2469
- }
2470
-
2471
2476
  // src/core/query.ts
2472
2477
  var DEFAULT_PAGE_SIZE = 50;
2473
2478
  function planQuery(query) {
@@ -2587,8 +2592,68 @@ function createRecordsClient(given) {
2587
2592
  } catch {
2588
2593
  }
2589
2594
  }
2595
+ const RECORD_OPENERS = /* @__PURE__ */ new Set(["read_record", "record_row_controls", "record_history", "comment_thread", "computed_provenance"]);
2596
+ const recordFlights = /* @__PURE__ */ new Map();
2597
+ const recordAsked = /* @__PURE__ */ new Map();
2598
+ let recordChangesHeard = false;
2599
+ function bundleRecordOf(door, args) {
2600
+ if (RECORD_OPENERS.has(door)) return typeof args["p_record_id"] === "string" ? args["p_record_id"] : null;
2601
+ const ids = args["p_ids"];
2602
+ const one = Array.isArray(ids) && ids.length === 1 && typeof ids[0] === "string" ? ids[0] : null;
2603
+ if (door === "record_headers") return one;
2604
+ if (door === "my_levels" && args["p_type"] === "record") return one;
2605
+ return null;
2606
+ }
2607
+ async function fillRecordBundle(recordId) {
2608
+ if (!recordChangesHeard) {
2609
+ recordChangesHeard = true;
2610
+ onRecordChanged((changed) => {
2611
+ recordAsked.delete(changed);
2612
+ for (const key of [...bundleParts.keys()]) if (key.includes(changed)) bundleParts.delete(key);
2613
+ });
2614
+ }
2615
+ try {
2616
+ const usable = (r) => r !== null && !r.error && r.data !== null && typeof r.data === "object" && Array.isArray(r.data.parts);
2617
+ const primedAnswer = takePrimedTablePageBundle(org, `record:${recordId}`, null);
2618
+ let response = primedAnswer ? await primedAnswer : null;
2619
+ if (!usable(response)) {
2620
+ response = await config.dataSource.rpc("record_page_bundle", { p_organization_id: org, p_record_id: recordId }, { schema });
2621
+ }
2622
+ if (!usable(response)) return;
2623
+ const now = Date.now();
2624
+ for (const part of response.data.parts) {
2625
+ if (part.error !== void 0 || part.data === void 0) continue;
2626
+ bundleParts.set(bundleKey(part.door, part.args), { data: part.data, at: now });
2627
+ }
2628
+ } catch {
2629
+ }
2630
+ }
2631
+ async function fromRecordBundle(door, args) {
2632
+ if (!doorReady(config, "record_page_bundle")) return void 0;
2633
+ const recordId = bundleRecordOf(door, args);
2634
+ if (!recordId) return void 0;
2635
+ const opener = RECORD_OPENERS.has(door);
2636
+ if (!opener && !recordFlights.has(recordId) && !recordAsked.has(recordId)) return void 0;
2637
+ const asked = recordAsked.get(recordId);
2638
+ const fresh = asked !== void 0 && Date.now() - asked < BUNDLE_TTL_MS;
2639
+ if (!fresh && opener) {
2640
+ recordAsked.set(recordId, Date.now());
2641
+ const flight2 = fillRecordBundle(recordId).finally(() => recordFlights.delete(recordId));
2642
+ recordFlights.set(recordId, flight2);
2643
+ }
2644
+ const flight = recordFlights.get(recordId);
2645
+ if (flight) await flight;
2646
+ const key = bundleKey(door, args);
2647
+ const held = bundleParts.get(key);
2648
+ if (!held) return opener ? null : void 0;
2649
+ bundleParts.delete(key);
2650
+ return Date.now() - held.at < BUNDLE_TTL_MS ? { data: held.data } : null;
2651
+ }
2590
2652
  async function fromBundle(door, args) {
2591
- if (!config.dataSource.opensInOneCall || !doorReady(config, "table_page_bundle")) return null;
2653
+ if (!config.dataSource.opensInOneCall) return null;
2654
+ const fromRecord = await fromRecordBundle(door, args);
2655
+ if (fromRecord !== void 0) return fromRecord;
2656
+ if (!doorReady(config, "table_page_bundle")) return null;
2592
2657
  const tableId = bundleTableOf(door, args);
2593
2658
  if (tableId) {
2594
2659
  const asked = bundleAsked.get(tableId);