@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,10 +1,10 @@
1
- import { N as NewFieldSpec } from '../declareTable-BYZdFrt5.cjs';
2
- import { U as Uuid, h as RecordsResult, n as RecordPageSort } from '../record-B7iwye2k.cjs';
3
- import { R as RecordsClient } from '../client-DZ3UcU4_.cjs';
4
- import { F as FieldDrift, T as TableArchiveProgress } from '../table-kind-HAQ6WNxZ.cjs';
5
- import '../field-BTW7h7Wh.cjs';
6
- import '../subscription-Br30ZwIt.cjs';
7
- import '../ports-PpvsH1cQ.cjs';
1
+ import { N as NewFieldSpec } from '../declareTable-CgrEusy8.cjs';
2
+ import { U as Uuid, h as RecordsResult, n as RecordPageSort } from '../record-Ba1F1CNS.cjs';
3
+ import { R as RecordsClient } from '../client-BExNR0TK.cjs';
4
+ import { F as FieldDrift, T as TableArchiveProgress } from '../table-kind-BoelIMjr.cjs';
5
+ import '../field-t9aefszx.cjs';
6
+ import '../subscription-DGCrwwSR.cjs';
7
+ import '../ports-Cjl-IjFa.cjs';
8
8
 
9
9
  /** Where a declared field's value goes in the graduated table. */
10
10
  declare const TO_CUSTOM_FIELDS: "custom_fields";
@@ -1,10 +1,10 @@
1
- import { N as NewFieldSpec } from '../declareTable-DGSJMqGx.js';
2
- import { U as Uuid, h as RecordsResult, n as RecordPageSort } from '../record-B7iwye2k.js';
3
- import { R as RecordsClient } from '../client-ZIxyAOdh.js';
4
- import { F as FieldDrift, T as TableArchiveProgress } from '../table-kind-Da21ZLdJ.js';
5
- import '../field-D7I9yck6.js';
6
- import '../subscription-BWaRPLyo.js';
7
- import '../ports-CaYEF1dG.js';
1
+ import { N as NewFieldSpec } from '../declareTable-DWOh53eK.js';
2
+ import { U as Uuid, h as RecordsResult, n as RecordPageSort } from '../record-Ba1F1CNS.js';
3
+ import { R as RecordsClient } from '../client-Byn_UthM.js';
4
+ import { F as FieldDrift, T as TableArchiveProgress } from '../table-kind-BMWi8G37.js';
5
+ import '../field-B2bvpqcE.js';
6
+ import '../subscription-CccP6N93.js';
7
+ import '../ports-Ch4Ym0tj.js';
8
8
 
9
9
  /** Where a declared field's value goes in the graduated table. */
10
10
  declare const TO_CUSTOM_FIELDS: "custom_fields";
@@ -1074,6 +1074,7 @@ var STORE_DOORS = [
1074
1074
  { 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" },
1075
1075
  { 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" },
1076
1076
  { 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" },
1077
+ { 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" },
1077
1078
  { 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" },
1078
1079
  { 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" },
1079
1080
  { name: "declared_conversation", args: "", returns: "uuid", security: "invoker" },
@@ -1654,6 +1655,7 @@ var STORE_DOORS = [
1654
1655
  { name: "table_list_everywhere", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
1655
1656
  { name: "table_list_everywhere", args: "p_organization_id uuid, p_include_app_tables boolean", returns: "jsonb", security: "invoker" },
1656
1657
  { name: "table_move", args: "p_table_id uuid, p_to_organization_id uuid, p_expected_version integer DEFAULT NULL::integer", returns: "jsonb", security: "definer" },
1658
+ { name: "table_page_bundle", args: "p_organization_id uuid, p_table_id uuid, p_view_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "invoker" },
1657
1659
  { 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" },
1658
1660
  { name: "table_record_ceiling", args: "", returns: "integer", security: "invoker" },
1659
1661
  { name: "table_record_ceiling", args: "p_organization_id uuid", returns: "integer", security: "invoker" },
@@ -2514,6 +2516,8 @@ function supabaseDataSource(client) {
2514
2516
  const supabase = client;
2515
2517
  const hasSchema = typeof supabase.schema === "function";
2516
2518
  const bound = {
2519
+ // PAGE-BUNDLE: the real adapter opens a table page with one `custom.table_page_bundle` call.
2520
+ opensInOneCall: true,
2517
2521
  rpc(fn, args, options) {
2518
2522
  if (!hasSchema) {
2519
2523
  return Promise.resolve(
@@ -2636,6 +2640,12 @@ function intersectIds(sets) {
2636
2640
 
2637
2641
  // src/core/client.ts
2638
2642
  var DEFAULT_SCHEMA = "custom";
2643
+ function canonicalArgs(value) {
2644
+ return JSON.stringify(
2645
+ value,
2646
+ (_key, held) => held && typeof held === "object" && !Array.isArray(held) ? Object.fromEntries(Object.keys(held).sort().map((k) => [k, held[k]])) : held
2647
+ );
2648
+ }
2639
2649
  var A_PERSONS_REFUSAL = /* @__PURE__ */ new Set([
2640
2650
  "refused_by_rule",
2641
2651
  "stale_write",
@@ -2664,7 +2674,83 @@ function createRecordsClient(given) {
2664
2674
  const schema = config.schema ?? DEFAULT_SCHEMA;
2665
2675
  const org = config.organizationId;
2666
2676
  const scream = sink(config);
2677
+ const BUNDLE_TTL_MS = 1e4;
2678
+ 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"]);
2679
+ const bundleParts = /* @__PURE__ */ new Map();
2680
+ const bundleFlights = /* @__PURE__ */ new Map();
2681
+ const bundleAsked = /* @__PURE__ */ new Map();
2682
+ let bundleKernel = null;
2683
+ const bundleKey = (door, args) => `${door}|${canonicalArgs(args)}`;
2684
+ function bundleTableOf(door, args) {
2685
+ const t = args["p_table_id"];
2686
+ if (door === "read_records_by_ids") {
2687
+ const ids = args["p_record_ids"];
2688
+ return typeof t === "string" && t === bundleKernel && Array.isArray(ids) && ids.length === 1 && typeof ids[0] === "string" ? ids[0] : null;
2689
+ }
2690
+ if (door === "my_levels") {
2691
+ const ids = args["p_ids"];
2692
+ return args["p_type"] === "record" && Array.isArray(ids) && ids.length === 1 && typeof ids[0] === "string" ? ids[0] : null;
2693
+ }
2694
+ return typeof t === "string" ? t : null;
2695
+ }
2696
+ async function fillBundle(tableId, viewId) {
2697
+ try {
2698
+ const response = await config.dataSource.rpc(
2699
+ "table_page_bundle",
2700
+ { p_organization_id: org, p_table_id: tableId, p_view_id: typeof viewId === "string" ? viewId : null },
2701
+ { schema }
2702
+ );
2703
+ const answer = response.data;
2704
+ if (response.error || !answer || !Array.isArray(answer.parts)) return;
2705
+ const now = Date.now();
2706
+ for (const part of answer.parts) {
2707
+ if (part.error !== void 0 || part.data === void 0) continue;
2708
+ if (part.door === "table_kernel_id" && typeof part.data === "string") bundleKernel = part.data;
2709
+ bundleParts.set(bundleKey(part.door, part.args), { data: part.data, at: now });
2710
+ }
2711
+ } catch {
2712
+ }
2713
+ }
2714
+ async function fromBundle(door, args) {
2715
+ if (!config.dataSource.opensInOneCall || !doorReady(config, "table_page_bundle")) return null;
2716
+ const tableId = bundleTableOf(door, args);
2717
+ if (tableId) {
2718
+ const asked = bundleAsked.get(tableId);
2719
+ const fresh = asked !== void 0 && Date.now() - asked < BUNDLE_TTL_MS;
2720
+ if (!fresh && BUNDLE_OPENERS.has(door)) {
2721
+ bundleAsked.set(tableId, Date.now());
2722
+ const flight2 = fillBundle(tableId, door === "grid_layout" ? args["p_view_id"] : null).finally(() => bundleFlights.delete(tableId));
2723
+ bundleFlights.set(tableId, flight2);
2724
+ }
2725
+ const flight = bundleFlights.get(tableId);
2726
+ if (flight) await flight;
2727
+ } else if (door === "table_kernel_id") {
2728
+ if (bundleKernel === null) {
2729
+ await new Promise((resolve) => setTimeout(resolve, 0));
2730
+ await Promise.all([...bundleFlights.values()]);
2731
+ }
2732
+ return bundleKernel === null ? null : { data: bundleKernel };
2733
+ } else {
2734
+ return null;
2735
+ }
2736
+ const key = bundleKey(door, args);
2737
+ const held = bundleParts.get(key);
2738
+ if (!held) return null;
2739
+ bundleParts.delete(key);
2740
+ return Date.now() - held.at < BUNDLE_TTL_MS ? { data: held.data } : null;
2741
+ }
2742
+ function bundleDrop(tableId) {
2743
+ if (tableId === null) {
2744
+ bundleParts.clear();
2745
+ bundleAsked.clear();
2746
+ return;
2747
+ }
2748
+ bundleAsked.delete(tableId);
2749
+ for (const key of [...bundleParts.keys()]) if (key.includes(tableId)) bundleParts.delete(key);
2750
+ }
2667
2751
  async function callDoor(door, args, where) {
2752
+ const bundled = await fromBundle(door, args);
2753
+ if (bundled) return ok(bundled.data);
2668
2754
  if (!doorReady(config, door)) {
2669
2755
  const refusal2 = doorAbsent(door);
2670
2756
  scream({ code: refusal2.code, message: refusal2.message, ...refusal2.hint ? { hint: refusal2.hint } : {}, where });
@@ -2679,7 +2765,10 @@ function createRecordsClient(given) {
2679
2765
  return ok(response.data);
2680
2766
  }
2681
2767
  function structureMoved(tableId, result) {
2682
- if (result.ok) announceTableStructureChanged(tableId);
2768
+ if (result.ok) {
2769
+ bundleDrop(tableId);
2770
+ announceTableStructureChanged(tableId);
2771
+ }
2683
2772
  return result;
2684
2773
  }
2685
2774
  async function owedDoor(door, args, where) {