@ai-matrx/records 0.77.3 → 0.78.0

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 (70) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/app-table/index.cjs +90 -1
  3. package/dist/app-table/index.cjs.map +1 -1
  4. package/dist/app-table/index.d.cts +7 -7
  5. package/dist/app-table/index.d.ts +7 -7
  6. package/dist/app-table/index.js +90 -1
  7. package/dist/app-table/index.js.map +1 -1
  8. package/dist/{client-DZ3UcU4_.d.cts → client-BExNR0TK.d.cts} +5 -5
  9. package/dist/{client-ZIxyAOdh.d.ts → client-Byn_UthM.d.ts} +5 -5
  10. package/dist/core/index.cjs +90 -1
  11. package/dist/core/index.cjs.map +1 -1
  12. package/dist/core/index.d.cts +11 -11
  13. package/dist/core/index.d.ts +11 -11
  14. package/dist/core/index.js +90 -1
  15. package/dist/core/index.js.map +1 -1
  16. package/dist/data/index.cjs +90 -1
  17. package/dist/data/index.cjs.map +1 -1
  18. package/dist/data/index.d.cts +6 -6
  19. package/dist/data/index.d.ts +6 -6
  20. package/dist/data/index.js +90 -1
  21. package/dist/data/index.js.map +1 -1
  22. package/dist/{declareTable-BYZdFrt5.d.cts → declareTable-CgrEusy8.d.cts} +4 -4
  23. package/dist/{declareTable-DGSJMqGx.d.ts → declareTable-DWOh53eK.d.ts} +4 -4
  24. package/dist/{field-D7I9yck6.d.ts → field-B2bvpqcE.d.ts} +1 -1
  25. package/dist/{field-BTW7h7Wh.d.cts → field-t9aefszx.d.cts} +1 -1
  26. package/dist/index.cjs +2 -0
  27. package/dist/index.cjs.map +1 -1
  28. package/dist/index.d.cts +7 -7
  29. package/dist/index.d.ts +7 -7
  30. package/dist/index.js +2 -0
  31. package/dist/index.js.map +1 -1
  32. package/dist/memory/index.cjs +2 -0
  33. package/dist/memory/index.cjs.map +1 -1
  34. package/dist/memory/index.d.cts +6 -6
  35. package/dist/memory/index.d.ts +6 -6
  36. package/dist/memory/index.js +2 -0
  37. package/dist/memory/index.js.map +1 -1
  38. package/dist/{ports-CaYEF1dG.d.ts → ports-Ch4Ym0tj.d.ts} +7 -1
  39. package/dist/{ports-PpvsH1cQ.d.cts → ports-Cjl-IjFa.d.cts} +7 -1
  40. package/dist/react/index.cjs +90 -1
  41. package/dist/react/index.cjs.map +1 -1
  42. package/dist/react/index.d.cts +16 -0
  43. package/dist/react/index.d.ts +16 -0
  44. package/dist/react/index.js +90 -1
  45. package/dist/react/index.js.map +1 -1
  46. package/dist/realtime/index.d.cts +2 -2
  47. package/dist/realtime/index.d.ts +2 -2
  48. package/dist/{record-B7iwye2k.d.cts → record-Ba1F1CNS.d.cts} +10 -0
  49. package/dist/{record-B7iwye2k.d.ts → record-Ba1F1CNS.d.ts} +10 -0
  50. package/dist/{subscription-BWaRPLyo.d.ts → subscription-CccP6N93.d.ts} +1 -1
  51. package/dist/{subscription-Br30ZwIt.d.cts → subscription-DGCrwwSR.d.cts} +1 -1
  52. package/dist/{table-kind-Da21ZLdJ.d.ts → table-kind-BMWi8G37.d.ts} +3 -3
  53. package/dist/{table-kind-HAQ6WNxZ.d.cts → table-kind-BoelIMjr.d.cts} +3 -3
  54. package/dist/templates/index.cjs +2 -0
  55. package/dist/templates/index.cjs.map +1 -1
  56. package/dist/templates/index.d.cts +9 -9
  57. package/dist/templates/index.d.ts +9 -9
  58. package/dist/templates/index.js +2 -0
  59. package/dist/templates/index.js.map +1 -1
  60. package/dist/{types-DrJLOqVi.d.ts → types-CiHdoATO.d.ts} +2 -2
  61. package/dist/{types-DWZ5_3by.d.ts → types-CtyMwJvy.d.ts} +2 -2
  62. package/dist/{types-DYoWzHwJ.d.cts → types-D-Mhiodh.d.cts} +2 -2
  63. package/dist/{types-LvxsZ6Zv.d.cts → types-euaQwxnB.d.cts} +2 -2
  64. package/dist/use-cases/index.cjs.map +1 -1
  65. package/dist/use-cases/index.d.cts +5 -5
  66. package/dist/use-cases/index.d.ts +5 -5
  67. package/dist/use-cases/index.js.map +1 -1
  68. package/dist/{validate-j0WQoC3C.d.ts → validate-B-p3YPgA.d.ts} +1 -1
  69. package/dist/{validate-CRdXE73G.d.cts → validate-COvMcv8z.d.cts} +1 -1
  70. package/package.json +2 -2
@@ -1,9 +1,9 @@
1
- import { bK as EntityRefWithWords } from '../table-kind-HAQ6WNxZ.cjs';
2
- import { U as Uuid, h as RecordsResult, n as RecordPageSort, m as ReadRow } from '../record-B7iwye2k.cjs';
3
- import { R as RecordsClient } from '../client-DZ3UcU4_.cjs';
4
- import { b as Field } from '../field-BTW7h7Wh.cjs';
5
- import { u as RuleExpression } from '../subscription-Br30ZwIt.cjs';
6
- import '../ports-PpvsH1cQ.cjs';
1
+ import { bK as EntityRefWithWords } from '../table-kind-BoelIMjr.cjs';
2
+ import { U as Uuid, h as RecordsResult, n as RecordPageSort, m as ReadRow } from '../record-Ba1F1CNS.cjs';
3
+ import { R as RecordsClient } from '../client-BExNR0TK.cjs';
4
+ import { b as Field } from '../field-t9aefszx.cjs';
5
+ import { u as RuleExpression } from '../subscription-DGCrwwSR.cjs';
6
+ import '../ports-Cjl-IjFa.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-Da21ZLdJ.js';
2
- import { U as Uuid, h as RecordsResult, n as RecordPageSort, m as ReadRow } from '../record-B7iwye2k.js';
3
- import { R as RecordsClient } from '../client-ZIxyAOdh.js';
4
- import { b as Field } from '../field-D7I9yck6.js';
5
- import { u as RuleExpression } from '../subscription-BWaRPLyo.js';
6
- import '../ports-CaYEF1dG.js';
1
+ import { bK as EntityRefWithWords } from '../table-kind-BMWi8G37.js';
2
+ import { U as Uuid, h as RecordsResult, n as RecordPageSort, m as ReadRow } from '../record-Ba1F1CNS.js';
3
+ import { R as RecordsClient } from '../client-Byn_UthM.js';
4
+ import { b as Field } from '../field-B2bvpqcE.js';
5
+ import { u as RuleExpression } from '../subscription-CccP6N93.js';
6
+ import '../ports-Ch4Ym0tj.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;
@@ -915,6 +915,7 @@ var STORE_DOORS = [
915
915
  { name: "data_home", args: "p_organization_id uuid DEFAULT NULL::uuid, p_search text DEFAULT NULL::text, p_include_app_tables boolean DEFAULT false", returns: "jsonb", security: "definer" },
916
916
  { name: "data_home_changed_by", args: "p_asks jsonb", returns: "TABLE(organization_id uuid, id uuid, at timestamp with time zone, who text)", security: "definer" },
917
917
  { name: "data_home_items", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "TABLE(kind text, organization_id uuid, organization_name text, item_id uuid, table_id uuid, table_name text, item_row jsonb)", security: "definer" },
918
+ { name: "data_home_slim", args: "p_organization_id uuid DEFAULT NULL::uuid, p_search text DEFAULT NULL::text, p_include_app_tables boolean DEFAULT false", returns: "jsonb", security: "invoker" },
918
919
  { name: "data_home_tables", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "TABLE(table_id uuid, table_name text, organization_id uuid, organization_name text, member boolean, visibility text, updated_at timestamp with time zone, mine boolean, shared_with_me boolean, kept_by_the_app boolean, kind text, team boolean, system boolean, created_by uuid)", security: "definer" },
919
920
  { name: "data_home_tables", args: "p_organization_id uuid, p_include_app_tables boolean", returns: "TABLE(table_id uuid, table_name text, organization_id uuid, organization_name text, member boolean, visibility text, updated_at timestamp with time zone, mine boolean, shared_with_me boolean, kept_by_the_app boolean, kind text, team boolean, system boolean, created_by uuid)", security: "invoker" },
920
921
  { name: "declared_conversation", args: "", returns: "uuid", security: "invoker" },
@@ -1495,6 +1496,7 @@ var STORE_DOORS = [
1495
1496
  { name: "table_list_everywhere", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
1496
1497
  { name: "table_list_everywhere", args: "p_organization_id uuid, p_include_app_tables boolean", returns: "jsonb", security: "invoker" },
1497
1498
  { name: "table_move", args: "p_table_id uuid, p_to_organization_id uuid, p_expected_version integer DEFAULT NULL::integer", returns: "jsonb", security: "definer" },
1499
+ { name: "table_page_bundle", args: "p_organization_id uuid, p_table_id uuid, p_view_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "invoker" },
1498
1500
  { name: "table_placement", args: "p_organization_id uuid, p_table_id uuid, p_data jsonb, p_is_kernel boolean DEFAULT false", returns: "jsonb", security: "invoker" },
1499
1501
  { name: "table_record_ceiling", args: "", returns: "integer", security: "invoker" },
1500
1502
  { name: "table_record_ceiling", args: "p_organization_id uuid", returns: "integer", security: "invoker" },
@@ -2355,6 +2357,8 @@ function supabaseDataSource(client) {
2355
2357
  const supabase = client;
2356
2358
  const hasSchema = typeof supabase.schema === "function";
2357
2359
  const bound = {
2360
+ // PAGE-BUNDLE: the real adapter opens a table page with one `custom.table_page_bundle` call.
2361
+ opensInOneCall: true,
2358
2362
  rpc(fn, args, options) {
2359
2363
  if (!hasSchema) {
2360
2364
  return Promise.resolve(
@@ -2477,6 +2481,12 @@ function intersectIds(sets) {
2477
2481
 
2478
2482
  // src/core/client.ts
2479
2483
  var DEFAULT_SCHEMA = "custom";
2484
+ function canonicalArgs(value) {
2485
+ return JSON.stringify(
2486
+ value,
2487
+ (_key, held) => held && typeof held === "object" && !Array.isArray(held) ? Object.fromEntries(Object.keys(held).sort().map((k) => [k, held[k]])) : held
2488
+ );
2489
+ }
2480
2490
  var A_PERSONS_REFUSAL = /* @__PURE__ */ new Set([
2481
2491
  "refused_by_rule",
2482
2492
  "stale_write",
@@ -2505,7 +2515,83 @@ function createRecordsClient(given) {
2505
2515
  const schema = config.schema ?? DEFAULT_SCHEMA;
2506
2516
  const org = config.organizationId;
2507
2517
  const scream = sink(config);
2518
+ const BUNDLE_TTL_MS = 1e4;
2519
+ const BUNDLE_OPENERS = /* @__PURE__ */ new Set(["applicable_fields", "views", "view_look_read", "table_decorations", "row_actions", "reverse_columns", "record_change_actions", "grid_layout", "io_imports"]);
2520
+ const bundleParts = /* @__PURE__ */ new Map();
2521
+ const bundleFlights = /* @__PURE__ */ new Map();
2522
+ const bundleAsked = /* @__PURE__ */ new Map();
2523
+ let bundleKernel = null;
2524
+ const bundleKey = (door, args) => `${door}|${canonicalArgs(args)}`;
2525
+ function bundleTableOf(door, args) {
2526
+ const t = args["p_table_id"];
2527
+ if (door === "read_records_by_ids") {
2528
+ const ids = args["p_record_ids"];
2529
+ return typeof t === "string" && t === bundleKernel && Array.isArray(ids) && ids.length === 1 && typeof ids[0] === "string" ? ids[0] : null;
2530
+ }
2531
+ if (door === "my_levels") {
2532
+ const ids = args["p_ids"];
2533
+ return args["p_type"] === "record" && Array.isArray(ids) && ids.length === 1 && typeof ids[0] === "string" ? ids[0] : null;
2534
+ }
2535
+ return typeof t === "string" ? t : null;
2536
+ }
2537
+ async function fillBundle(tableId, viewId) {
2538
+ try {
2539
+ const response = await config.dataSource.rpc(
2540
+ "table_page_bundle",
2541
+ { p_organization_id: org, p_table_id: tableId, p_view_id: typeof viewId === "string" ? viewId : null },
2542
+ { schema }
2543
+ );
2544
+ const answer = response.data;
2545
+ if (response.error || !answer || !Array.isArray(answer.parts)) return;
2546
+ const now = Date.now();
2547
+ for (const part of answer.parts) {
2548
+ if (part.error !== void 0 || part.data === void 0) continue;
2549
+ if (part.door === "table_kernel_id" && typeof part.data === "string") bundleKernel = part.data;
2550
+ bundleParts.set(bundleKey(part.door, part.args), { data: part.data, at: now });
2551
+ }
2552
+ } catch {
2553
+ }
2554
+ }
2555
+ async function fromBundle(door, args) {
2556
+ if (!config.dataSource.opensInOneCall || !doorReady(config, "table_page_bundle")) return null;
2557
+ const tableId = bundleTableOf(door, args);
2558
+ if (tableId) {
2559
+ const asked = bundleAsked.get(tableId);
2560
+ const fresh = asked !== void 0 && Date.now() - asked < BUNDLE_TTL_MS;
2561
+ if (!fresh && BUNDLE_OPENERS.has(door)) {
2562
+ bundleAsked.set(tableId, Date.now());
2563
+ const flight2 = fillBundle(tableId, door === "grid_layout" ? args["p_view_id"] : null).finally(() => bundleFlights.delete(tableId));
2564
+ bundleFlights.set(tableId, flight2);
2565
+ }
2566
+ const flight = bundleFlights.get(tableId);
2567
+ if (flight) await flight;
2568
+ } else if (door === "table_kernel_id") {
2569
+ if (bundleKernel === null) {
2570
+ await new Promise((resolve) => setTimeout(resolve, 0));
2571
+ await Promise.all([...bundleFlights.values()]);
2572
+ }
2573
+ return bundleKernel === null ? null : { data: bundleKernel };
2574
+ } else {
2575
+ return null;
2576
+ }
2577
+ const key = bundleKey(door, args);
2578
+ const held = bundleParts.get(key);
2579
+ if (!held) return null;
2580
+ bundleParts.delete(key);
2581
+ return Date.now() - held.at < BUNDLE_TTL_MS ? { data: held.data } : null;
2582
+ }
2583
+ function bundleDrop(tableId) {
2584
+ if (tableId === null) {
2585
+ bundleParts.clear();
2586
+ bundleAsked.clear();
2587
+ return;
2588
+ }
2589
+ bundleAsked.delete(tableId);
2590
+ for (const key of [...bundleParts.keys()]) if (key.includes(tableId)) bundleParts.delete(key);
2591
+ }
2508
2592
  async function callDoor(door, args, where) {
2593
+ const bundled = await fromBundle(door, args);
2594
+ if (bundled) return ok(bundled.data);
2509
2595
  if (!doorReady(config, door)) {
2510
2596
  const refusal2 = doorAbsent(door);
2511
2597
  scream({ code: refusal2.code, message: refusal2.message, ...refusal2.hint ? { hint: refusal2.hint } : {}, where });
@@ -2520,7 +2606,10 @@ function createRecordsClient(given) {
2520
2606
  return ok(response.data);
2521
2607
  }
2522
2608
  function structureMoved(tableId, result) {
2523
- if (result.ok) announceTableStructureChanged(tableId);
2609
+ if (result.ok) {
2610
+ bundleDrop(tableId);
2611
+ announceTableStructureChanged(tableId);
2612
+ }
2524
2613
  return result;
2525
2614
  }
2526
2615
  async function owedDoor(door, args, where) {