@ai-matrx/records 0.77.3 → 0.78.1

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 +15 -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 +94 -9
  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 +92 -7
  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 +4 -6
  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 +4 -6
  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 +92 -7
  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 +92 -7
  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 +3 -3
@@ -959,6 +959,7 @@ var STORE_DOORS = [
959
959
  { 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" },
960
960
  { 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" },
961
961
  { 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" },
962
+ { 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" },
962
963
  { 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" },
963
964
  { 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" },
964
965
  { name: "declared_conversation", args: "", returns: "uuid", security: "invoker" },
@@ -1539,6 +1540,7 @@ var STORE_DOORS = [
1539
1540
  { name: "table_list_everywhere", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
1540
1541
  { name: "table_list_everywhere", args: "p_organization_id uuid, p_include_app_tables boolean", returns: "jsonb", security: "invoker" },
1541
1542
  { name: "table_move", args: "p_table_id uuid, p_to_organization_id uuid, p_expected_version integer DEFAULT NULL::integer", returns: "jsonb", security: "definer" },
1543
+ { name: "table_page_bundle", args: "p_organization_id uuid, p_table_id uuid, p_view_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "invoker" },
1542
1544
  { 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" },
1543
1545
  { name: "table_record_ceiling", args: "", returns: "integer", security: "invoker" },
1544
1546
  { name: "table_record_ceiling", args: "p_organization_id uuid", returns: "integer", security: "invoker" },
@@ -2399,6 +2401,8 @@ function supabaseDataSource(client) {
2399
2401
  const supabase = client;
2400
2402
  const hasSchema = typeof supabase.schema === "function";
2401
2403
  const bound = {
2404
+ // PAGE-BUNDLE: the real adapter opens a table page with one `custom.table_page_bundle` call.
2405
+ opensInOneCall: true,
2402
2406
  rpc(fn, args, options) {
2403
2407
  if (!hasSchema) {
2404
2408
  return Promise.resolve(
@@ -2521,6 +2525,12 @@ function intersectIds(sets) {
2521
2525
 
2522
2526
  // src/core/client.ts
2523
2527
  var DEFAULT_SCHEMA = "custom";
2528
+ function canonicalArgs(value) {
2529
+ return JSON.stringify(
2530
+ value,
2531
+ (_key, held) => held && typeof held === "object" && !Array.isArray(held) ? Object.fromEntries(Object.keys(held).sort().map((k) => [k, held[k]])) : held
2532
+ );
2533
+ }
2524
2534
  var A_PERSONS_REFUSAL = /* @__PURE__ */ new Set([
2525
2535
  "refused_by_rule",
2526
2536
  "stale_write",
@@ -2549,7 +2559,83 @@ function createRecordsClient(given) {
2549
2559
  const schema = config.schema ?? DEFAULT_SCHEMA;
2550
2560
  const org = config.organizationId;
2551
2561
  const scream = sink(config);
2562
+ const BUNDLE_TTL_MS = 1e4;
2563
+ 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"]);
2564
+ const bundleParts = /* @__PURE__ */ new Map();
2565
+ const bundleFlights = /* @__PURE__ */ new Map();
2566
+ const bundleAsked = /* @__PURE__ */ new Map();
2567
+ let bundleKernel = null;
2568
+ const bundleKey = (door, args) => `${door}|${canonicalArgs(args)}`;
2569
+ function bundleTableOf(door, args) {
2570
+ const t = args["p_table_id"];
2571
+ if (door === "read_records_by_ids") {
2572
+ const ids = args["p_record_ids"];
2573
+ return typeof t === "string" && t === bundleKernel && Array.isArray(ids) && ids.length === 1 && typeof ids[0] === "string" ? ids[0] : null;
2574
+ }
2575
+ if (door === "my_levels") {
2576
+ const ids = args["p_ids"];
2577
+ return args["p_type"] === "record" && Array.isArray(ids) && ids.length === 1 && typeof ids[0] === "string" ? ids[0] : null;
2578
+ }
2579
+ return typeof t === "string" ? t : null;
2580
+ }
2581
+ async function fillBundle(tableId, viewId) {
2582
+ try {
2583
+ const response = await config.dataSource.rpc(
2584
+ "table_page_bundle",
2585
+ { p_organization_id: org, p_table_id: tableId, p_view_id: typeof viewId === "string" ? viewId : null },
2586
+ { schema }
2587
+ );
2588
+ const answer = response.data;
2589
+ if (response.error || !answer || !Array.isArray(answer.parts)) return;
2590
+ const now = Date.now();
2591
+ for (const part of answer.parts) {
2592
+ if (part.error !== void 0 || part.data === void 0) continue;
2593
+ if (part.door === "table_kernel_id" && typeof part.data === "string") bundleKernel = part.data;
2594
+ bundleParts.set(bundleKey(part.door, part.args), { data: part.data, at: now });
2595
+ }
2596
+ } catch {
2597
+ }
2598
+ }
2599
+ async function fromBundle(door, args) {
2600
+ if (!config.dataSource.opensInOneCall || !doorReady(config, "table_page_bundle")) return null;
2601
+ const tableId = bundleTableOf(door, args);
2602
+ if (tableId) {
2603
+ const asked = bundleAsked.get(tableId);
2604
+ const fresh = asked !== void 0 && Date.now() - asked < BUNDLE_TTL_MS;
2605
+ if (!fresh && BUNDLE_OPENERS.has(door)) {
2606
+ bundleAsked.set(tableId, Date.now());
2607
+ const flight2 = fillBundle(tableId, door === "grid_layout" ? args["p_view_id"] : null).finally(() => bundleFlights.delete(tableId));
2608
+ bundleFlights.set(tableId, flight2);
2609
+ }
2610
+ const flight = bundleFlights.get(tableId);
2611
+ if (flight) await flight;
2612
+ } else if (door === "table_kernel_id") {
2613
+ if (bundleKernel === null) {
2614
+ await new Promise((resolve) => setTimeout(resolve, 0));
2615
+ await Promise.all([...bundleFlights.values()]);
2616
+ }
2617
+ return bundleKernel === null ? null : { data: bundleKernel };
2618
+ } else {
2619
+ return null;
2620
+ }
2621
+ const key = bundleKey(door, args);
2622
+ const held = bundleParts.get(key);
2623
+ if (!held) return null;
2624
+ bundleParts.delete(key);
2625
+ return Date.now() - held.at < BUNDLE_TTL_MS ? { data: held.data } : null;
2626
+ }
2627
+ function bundleDrop(tableId) {
2628
+ if (tableId === null) {
2629
+ bundleParts.clear();
2630
+ bundleAsked.clear();
2631
+ return;
2632
+ }
2633
+ bundleAsked.delete(tableId);
2634
+ for (const key of [...bundleParts.keys()]) if (key.includes(tableId)) bundleParts.delete(key);
2635
+ }
2552
2636
  async function callDoor(door, args, where) {
2637
+ const bundled = await fromBundle(door, args);
2638
+ if (bundled) return ok(bundled.data);
2553
2639
  if (!doorReady(config, door)) {
2554
2640
  const refusal2 = doorAbsent(door);
2555
2641
  scream({ code: refusal2.code, message: refusal2.message, ...refusal2.hint ? { hint: refusal2.hint } : {}, where });
@@ -2564,7 +2650,10 @@ function createRecordsClient(given) {
2564
2650
  return ok(response.data);
2565
2651
  }
2566
2652
  function structureMoved(tableId, result) {
2567
- if (result.ok) announceTableStructureChanged(tableId);
2653
+ if (result.ok) {
2654
+ bundleDrop(tableId);
2655
+ announceTableStructureChanged(tableId);
2656
+ }
2568
2657
  return result;
2569
2658
  }
2570
2659
  async function owedDoor(door, args, where) {