@ai-matrx/records 0.80.2 → 0.80.7

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 +29 -0
  2. package/README.md +19 -0
  3. package/dist/app-table/index.cjs +100 -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 +100 -23
  8. package/dist/app-table/index.js.map +1 -1
  9. package/dist/{client-DKKRZKNw.d.ts → client-D1LTezMZ.d.ts} +10 -5
  10. package/dist/{client-BfNJEpar.d.cts → client-DLIKeBWF.d.cts} +10 -5
  11. package/dist/core/index.cjs +115 -31
  12. package/dist/core/index.cjs.map +1 -1
  13. package/dist/core/index.d.cts +22 -12
  14. package/dist/core/index.d.ts +22 -12
  15. package/dist/core/index.js +115 -31
  16. package/dist/core/index.js.map +1 -1
  17. package/dist/data/index.cjs +100 -23
  18. package/dist/data/index.cjs.map +1 -1
  19. package/dist/data/index.d.cts +7 -7
  20. package/dist/data/index.d.ts +7 -7
  21. package/dist/data/index.js +100 -23
  22. package/dist/data/index.js.map +1 -1
  23. package/dist/{declareTable-CzLMdOSy.d.cts → declareTable-02uao-5n.d.cts} +4 -4
  24. package/dist/{declareTable-Cg522Sk0.d.ts → declareTable-C5FlIS0z.d.ts} +4 -4
  25. package/dist/{field-DJAvDExi.d.ts → field-BIJiFPc0.d.ts} +1 -1
  26. package/dist/{field-DCXU6k9i.d.cts → field-snQG2jMq.d.cts} +1 -1
  27. package/dist/index.cjs +12 -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 +12 -0
  32. package/dist/index.js.map +1 -1
  33. package/dist/memory/index.cjs +5 -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 +5 -0
  38. package/dist/memory/index.js.map +1 -1
  39. package/dist/{ports-Kpc-RihV.d.ts → ports-Y5gLbCXe.d.ts} +1 -1
  40. package/dist/{ports-DaHUjVg7.d.cts → ports-y1QNfM80.d.cts} +1 -1
  41. package/dist/react/index.cjs +107 -27
  42. package/dist/react/index.cjs.map +1 -1
  43. package/dist/react/index.d.cts +31 -1
  44. package/dist/react/index.d.ts +31 -1
  45. package/dist/react/index.js +107 -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-DCaOJbhA.d.cts → record-1yDCn169.d.cts} +26 -1
  50. package/dist/{record-DCaOJbhA.d.ts → record-1yDCn169.d.ts} +26 -1
  51. package/dist/{subscription-C_hNjbaR.d.cts → subscription-B_WaT-kr.d.cts} +1 -1
  52. package/dist/{subscription-B9znK2dw.d.ts → subscription-CUok1vAm.d.ts} +1 -1
  53. package/dist/{table-kind-B9RBUmSb.d.ts → table-kind-COmkYYkc.d.ts} +3 -3
  54. package/dist/{table-kind-DXktQGzR.d.cts → table-kind-LodkBhCZ.d.cts} +3 -3
  55. package/dist/templates/index.cjs +70 -6
  56. package/dist/templates/index.cjs.map +1 -1
  57. package/dist/templates/index.d.cts +26 -10
  58. package/dist/templates/index.d.ts +26 -10
  59. package/dist/templates/index.js +70 -6
  60. package/dist/templates/index.js.map +1 -1
  61. package/dist/{types-DuyBN2im.d.cts → types-BJGTxu3Y.d.cts} +2 -2
  62. package/dist/{types-b-VGi15H.d.ts → types-C5-AaPa6.d.ts} +2 -2
  63. package/dist/{types-CHEFgCu1.d.ts → types-CU_Tn2Np.d.ts} +2 -2
  64. package/dist/{types-CD2HoaZt.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-CubFFxpu.d.cts → validate-CE6qpJIb.d.cts} +1 -1
  70. package/dist/{validate-BEfYwBpA.d.ts → validate-Rz9djP6H.d.ts} +1 -1
  71. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { P as PgError, A as Actor, U as Uuid } from './record-DCaOJbhA.js';
1
+ import { P as PgError, A as Actor, U as Uuid } from './record-1yDCn169.js';
2
2
 
3
3
  /**
4
4
  * The data seam: a structural subset of `SupabaseClient`. The package never
@@ -1,4 +1,4 @@
1
- import { P as PgError, A as Actor, U as Uuid } from './record-DCaOJbhA.cjs';
1
+ import { P as PgError, A as Actor, U as Uuid } from './record-1yDCn169.cjs';
2
2
 
3
3
  /**
4
4
  * The data seam: a structural subset of `SupabaseClient`. The package never
@@ -310,6 +310,32 @@ function takePrimedTablePageBundle(organizationId, tableId, viewId) {
310
310
  return Date.now() - held.at < PRIMED_TTL_MS ? held.answer : null;
311
311
  }
312
312
 
313
+ // src/core/recordChanges.ts
314
+ var listeners = /* @__PURE__ */ new Set();
315
+ function announceRecordChanged(recordId) {
316
+ for (const listener of [...listeners]) {
317
+ try {
318
+ listener(recordId);
319
+ } catch (thrown) {
320
+ console.error("[@ai-matrx/records] a record-change listener threw", thrown);
321
+ }
322
+ }
323
+ }
324
+ function onRecordChanged(listener) {
325
+ listeners.add(listener);
326
+ return () => listeners.delete(listener);
327
+ }
328
+ var tableListeners = /* @__PURE__ */ new Set();
329
+ function announceTableStructureChanged(tableId) {
330
+ for (const listener of [...tableListeners]) {
331
+ try {
332
+ listener(tableId);
333
+ } catch (thrown) {
334
+ console.error("[@ai-matrx/records] a table-structure listener threw", thrown);
335
+ }
336
+ }
337
+ }
338
+
313
339
  // src/archive.ts
314
340
  var ARCHIVE_LANES = ["mine", "org"];
315
341
  var DEFAULT_ARCHIVE_LANE = "org";
@@ -1647,21 +1673,25 @@ var STORE_DOORS = [
1647
1673
  { name: "form_declare", args: "p_organization_id uuid, p_table_id uuid, p_title text, p_questions jsonb, p_presentation jsonb DEFAULT '{}'::jsonb, p_submission_cap integer DEFAULT NULL::integer, p_quarantine_rule_id uuid DEFAULT NULL::uuid, p_notify_rule_id uuid DEFAULT NULL::uuid, p_form_id uuid DEFAULT NULL::uuid, p_slug text DEFAULT NULL::text", returns: "uuid", security: "definer" },
1648
1674
  { name: "form_draft_read", args: "p_form_id uuid, p_secret text", returns: "TABLE(answers jsonb, saved_at timestamp with time zone, expires_at timestamp with time zone, state text, message text)", security: "definer" },
1649
1675
  { name: "form_draft_save", args: "p_form_id uuid, p_answers jsonb, p_secret text DEFAULT NULL::text, p_bucket text DEFAULT NULL::text, p_origin text DEFAULT NULL::text", returns: "TABLE(draft_secret text, saved_at timestamp with time zone, expires_at timestamp with time zone, state text, message text)", security: "definer" },
1676
+ { name: "form_knobs", args: "p_organization_id uuid", returns: "jsonb", security: "definer" },
1650
1677
  { name: "form_look_options", args: "p_organization_id uuid, p_presentation jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "definer" },
1651
1678
  { name: "form_notify", args: "p_organization_id uuid, p_form_id uuid, p_record_id uuid, p_submission_id uuid", returns: "uuid", security: "invoker" },
1652
1679
  { name: "form_preview_asks", args: "p_organization_id uuid, p_table_id uuid, p_questions jsonb, p_values jsonb", returns: "TABLE(field_key text, asked boolean, decided boolean, said text)", security: "definer" },
1653
1680
  { name: "form_preview_route", args: "p_organization_id uuid, p_table_id uuid, p_questions jsonb, p_endings jsonb, p_values jsonb", returns: "jsonb", security: "definer" },
1654
1681
  { name: "form_public", args: "p_form_id uuid", returns: "TABLE(form_id uuid, organization_id uuid, table_id uuid, title text, presentation jsonb, fields jsonb, honeypot_key text, state text, message text)", security: "definer" },
1655
1682
  { name: "form_public_asks", args: "p_form_id uuid, p_values jsonb, p_secret text DEFAULT NULL::text, p_origin text DEFAULT NULL::text", returns: "TABLE(field_key text, asked boolean, decided boolean, said text)", security: "definer" },
1683
+ { name: "form_public_options", args: "p_form_id uuid", returns: "jsonb", security: "definer" },
1656
1684
  { name: "form_public_route", args: "p_form_id uuid, p_values jsonb", returns: "jsonb", security: "definer" },
1657
1685
  { name: "form_redirect_domains", args: "p_organization_id uuid", returns: "text[]", security: "invoker" },
1658
1686
  { name: "form_redirect_refusal", args: "p_organization_id uuid, p_url text", returns: "text", security: "invoker" },
1687
+ { name: "form_respondent_copy", args: "p_organization_id uuid, p_form_id uuid, p_record_id uuid, p_submission_id uuid", returns: "jsonb", security: "definer" },
1659
1688
  { name: "form_restore", args: "p_organization_id uuid, p_form_id uuid", returns: "jsonb", security: "definer" },
1660
1689
  { name: "form_results", args: "p_organization_id uuid, p_form_id uuid", returns: "jsonb", security: "definer" },
1661
1690
  { name: "form_slug", args: "p_organization_id uuid, p_title text, p_form_id uuid DEFAULT NULL::uuid", returns: "text", security: "invoker" },
1662
1691
  { name: "form_submit", args: "p_form_id uuid, p_origin text, p_payload jsonb, p_bucket text, p_honeypot text DEFAULT NULL::text, p_client_key text DEFAULT NULL::text", returns: "TABLE(submission_id uuid, record_id uuid, state text, message text)", security: "definer" },
1663
1692
  { name: "form_theme_options", args: "", returns: "jsonb", security: "invoker" },
1664
1693
  { name: "form_visit", args: "p_form_id uuid, p_visit text, p_event text, p_field text DEFAULT NULL::text", returns: "text", security: "definer" },
1694
+ { name: "form_visit_admit", args: "p_form_id uuid, p_bucket text", returns: "boolean", security: "definer" },
1665
1695
  { name: "forms", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "TABLE(form_id uuid, table_id uuid, title text, slug text, published_at timestamp with time zone, closed_at timestamp with time zone, submission_cap integer, responses bigint, in_table bigint, held bigint, rejected bigint, state text, quarantine_rule_id uuid, notify_rule_id uuid, presentation jsonb)", security: "definer" },
1666
1696
  { name: "forms_archived", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid, p_limit integer DEFAULT 100", returns: "TABLE(form_id uuid, table_id uuid, table_name text, kind text, title text, slug text, archived_at timestamp with time zone, archived_by uuid, table_archived boolean, can_restore boolean)", security: "definer" },
1667
1697
  { name: "formula_compile_sql", args: "p_organization_id uuid, p_expr jsonb, p_values_sql text", returns: "text", security: "invoker" },
@@ -1929,6 +1959,7 @@ var STORE_DOORS = [
1929
1959
  { name: "record_filter_sql", args: "p_organization_id uuid, p_table_id uuid, p_filter jsonb", returns: "text", security: "invoker" },
1930
1960
  { 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" },
1931
1961
  { 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" },
1962
+ { name: "record_page_bundle", args: "p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "invoker" },
1932
1963
  { name: "record_platform_keys", args: "", returns: "text[]", security: "invoker" },
1933
1964
  { 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" },
1934
1965
  { name: "record_reparent", args: "p_organization_id uuid, p_record_id uuid, p_parent_id uuid", returns: "void", security: "definer" },
@@ -2339,6 +2370,7 @@ var ENTITY_TOKENS = [
2339
2370
  "access_shadow_log",
2340
2371
  "account_addon",
2341
2372
  "account_closure",
2373
+ "account_facts",
2342
2374
  "acquisition_block",
2343
2375
  "activity",
2344
2376
  "admin_audit_log",
@@ -2629,6 +2661,7 @@ var ENTITY_TOKENS = [
2629
2661
  "deprecated_relation",
2630
2662
  "derive_run",
2631
2663
  "dev_login_audit",
2664
+ "device_handoff",
2632
2665
  "dict_entry",
2633
2666
  "dict_provider_publication",
2634
2667
  "dict_setting",
@@ -2664,12 +2697,15 @@ var ENTITY_TOKENS = [
2664
2697
  "esign_envelope",
2665
2698
  "esign_envelope_certificate",
2666
2699
  "esign_envelope_document",
2700
+ "esign_envelope_draft",
2667
2701
  "esign_envelope_event",
2668
2702
  "esign_envelope_external_ref",
2669
2703
  "esign_envelope_signer",
2670
2704
  "esign_provider",
2671
2705
  "esign_provider_binding",
2706
+ "esign_saved_signature",
2672
2707
  "esign_signing_key",
2708
+ "esign_template",
2673
2709
  "execution_event_cursor",
2674
2710
  "extension_auth_code",
2675
2711
  "external_link",
@@ -3296,6 +3332,7 @@ var ENTITY_TOKENS = [
3296
3332
  "tool_binding",
3297
3333
  "tool_bundle",
3298
3334
  "tool_call",
3335
+ "tool_call_facts",
3299
3336
  "tool_definition_version",
3300
3337
  "tool_executor",
3301
3338
  "tool_surface_defaults",
@@ -3330,6 +3367,7 @@ var ENTITY_TOKENS = [
3330
3367
  "uploads_inflight",
3331
3368
  "user",
3332
3369
  "user_achievement",
3370
+ "user_acquisition_facts",
3333
3371
  "user_active_context",
3334
3372
  "user_analysis_preference",
3335
3373
  "user_email_preference",
@@ -3800,6 +3838,7 @@ var DOORS = {
3800
3838
  formPreviewRoute: "form_preview_route",
3801
3839
  /** TYPEFORM-DUP: views, starts, completions, drop-off and answers per question. */
3802
3840
  formResults: "form_results",
3841
+ formKnobs: "form_knobs",
3803
3842
  formLookOptions: "form_look_options",
3804
3843
  // PRODUCTS row 14 — "let clients book a 30-minute consult". A booking page IS an
3805
3844
  // `anon_form`, so it is opened and closed by `anonPublish` like any other; this is
@@ -4251,32 +4290,6 @@ var DRILL_DOORS = {
4251
4290
  rows: "drill_rows"
4252
4291
  };
4253
4292
 
4254
- // src/core/recordChanges.ts
4255
- var listeners = /* @__PURE__ */ new Set();
4256
- function announceRecordChanged(recordId) {
4257
- for (const listener of [...listeners]) {
4258
- try {
4259
- listener(recordId);
4260
- } catch (thrown) {
4261
- console.error("[@ai-matrx/records] a record-change listener threw", thrown);
4262
- }
4263
- }
4264
- }
4265
- function onRecordChanged(listener) {
4266
- listeners.add(listener);
4267
- return () => listeners.delete(listener);
4268
- }
4269
- var tableListeners = /* @__PURE__ */ new Set();
4270
- function announceTableStructureChanged(tableId) {
4271
- for (const listener of [...tableListeners]) {
4272
- try {
4273
- listener(tableId);
4274
- } catch (thrown) {
4275
- console.error("[@ai-matrx/records] a table-structure listener threw", thrown);
4276
- }
4277
- }
4278
- }
4279
-
4280
4293
  // src/core/query.ts
4281
4294
  var DEFAULT_PAGE_SIZE = 50;
4282
4295
  function planQuery(query) {
@@ -4396,8 +4409,68 @@ function createRecordsClient(given) {
4396
4409
  } catch {
4397
4410
  }
4398
4411
  }
4412
+ const RECORD_OPENERS = /* @__PURE__ */ new Set(["read_record", "record_row_controls", "record_history", "comment_thread", "computed_provenance"]);
4413
+ const recordFlights = /* @__PURE__ */ new Map();
4414
+ const recordAsked = /* @__PURE__ */ new Map();
4415
+ let recordChangesHeard = false;
4416
+ function bundleRecordOf(door, args) {
4417
+ if (RECORD_OPENERS.has(door)) return typeof args["p_record_id"] === "string" ? args["p_record_id"] : null;
4418
+ const ids = args["p_ids"];
4419
+ const one = Array.isArray(ids) && ids.length === 1 && typeof ids[0] === "string" ? ids[0] : null;
4420
+ if (door === "record_headers") return one;
4421
+ if (door === "my_levels" && args["p_type"] === "record") return one;
4422
+ return null;
4423
+ }
4424
+ async function fillRecordBundle(recordId) {
4425
+ if (!recordChangesHeard) {
4426
+ recordChangesHeard = true;
4427
+ onRecordChanged((changed) => {
4428
+ recordAsked.delete(changed);
4429
+ for (const key of [...bundleParts.keys()]) if (key.includes(changed)) bundleParts.delete(key);
4430
+ });
4431
+ }
4432
+ try {
4433
+ const usable = (r) => r !== null && !r.error && r.data !== null && typeof r.data === "object" && Array.isArray(r.data.parts);
4434
+ const primedAnswer = takePrimedTablePageBundle(org, `record:${recordId}`, null);
4435
+ let response = primedAnswer ? await primedAnswer : null;
4436
+ if (!usable(response)) {
4437
+ response = await config.dataSource.rpc("record_page_bundle", { p_organization_id: org, p_record_id: recordId }, { schema });
4438
+ }
4439
+ if (!usable(response)) return;
4440
+ const now = Date.now();
4441
+ for (const part of response.data.parts) {
4442
+ if (part.error !== void 0 || part.data === void 0) continue;
4443
+ bundleParts.set(bundleKey(part.door, part.args), { data: part.data, at: now });
4444
+ }
4445
+ } catch {
4446
+ }
4447
+ }
4448
+ async function fromRecordBundle(door, args) {
4449
+ if (!doorReady(config, "record_page_bundle")) return void 0;
4450
+ const recordId = bundleRecordOf(door, args);
4451
+ if (!recordId) return void 0;
4452
+ const opener = RECORD_OPENERS.has(door);
4453
+ if (!opener && !recordFlights.has(recordId) && !recordAsked.has(recordId)) return void 0;
4454
+ const asked = recordAsked.get(recordId);
4455
+ const fresh = asked !== void 0 && Date.now() - asked < BUNDLE_TTL_MS;
4456
+ if (!fresh && opener) {
4457
+ recordAsked.set(recordId, Date.now());
4458
+ const flight2 = fillRecordBundle(recordId).finally(() => recordFlights.delete(recordId));
4459
+ recordFlights.set(recordId, flight2);
4460
+ }
4461
+ const flight = recordFlights.get(recordId);
4462
+ if (flight) await flight;
4463
+ const key = bundleKey(door, args);
4464
+ const held = bundleParts.get(key);
4465
+ if (!held) return opener ? null : void 0;
4466
+ bundleParts.delete(key);
4467
+ return Date.now() - held.at < BUNDLE_TTL_MS ? { data: held.data } : null;
4468
+ }
4399
4469
  async function fromBundle(door, args) {
4400
- if (!config.dataSource.opensInOneCall || !doorReady(config, "table_page_bundle")) return null;
4470
+ if (!config.dataSource.opensInOneCall) return null;
4471
+ const fromRecord = await fromRecordBundle(door, args);
4472
+ if (fromRecord !== void 0) return fromRecord;
4473
+ if (!doorReady(config, "table_page_bundle")) return null;
4401
4474
  const tableId = bundleTableOf(door, args);
4402
4475
  if (tableId) {
4403
4476
  const asked = bundleAsked.get(tableId);
@@ -5842,6 +5915,13 @@ function createRecordsClient(given) {
5842
5915
  "formResults"
5843
5916
  );
5844
5917
  },
5918
+ async formKnobs() {
5919
+ return callDoor(
5920
+ DOORS.formKnobs,
5921
+ { p_organization_id: org },
5922
+ "formKnobs"
5923
+ );
5924
+ },
5845
5925
  async formLookOptions(args) {
5846
5926
  return callDoor(
5847
5927
  DOORS.formLookOptions,