@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
@@ -28,6 +28,32 @@ function takePrimedTablePageBundle(organizationId, tableId, viewId) {
28
28
  return Date.now() - held.at < PRIMED_TTL_MS ? held.answer : null;
29
29
  }
30
30
 
31
+ // src/core/recordChanges.ts
32
+ var listeners = /* @__PURE__ */ new Set();
33
+ function announceRecordChanged(recordId) {
34
+ for (const listener of [...listeners]) {
35
+ try {
36
+ listener(recordId);
37
+ } catch (thrown) {
38
+ console.error("[@ai-matrx/records] a record-change listener threw", thrown);
39
+ }
40
+ }
41
+ }
42
+ function onRecordChanged(listener) {
43
+ listeners.add(listener);
44
+ return () => listeners.delete(listener);
45
+ }
46
+ var tableListeners = /* @__PURE__ */ new Set();
47
+ function announceTableStructureChanged(tableId) {
48
+ for (const listener of [...tableListeners]) {
49
+ try {
50
+ listener(tableId);
51
+ } catch (thrown) {
52
+ console.error("[@ai-matrx/records] a table-structure listener threw", thrown);
53
+ }
54
+ }
55
+ }
56
+
31
57
  // src/archive.ts
32
58
  var ARCHIVE_LANES = ["mine", "org"];
33
59
  var DEFAULT_ARCHIVE_LANE = "org";
@@ -1365,21 +1391,25 @@ var STORE_DOORS = [
1365
1391
  { 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" },
1366
1392
  { 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" },
1367
1393
  { 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" },
1394
+ { name: "form_knobs", args: "p_organization_id uuid", returns: "jsonb", security: "definer" },
1368
1395
  { name: "form_look_options", args: "p_organization_id uuid, p_presentation jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "definer" },
1369
1396
  { name: "form_notify", args: "p_organization_id uuid, p_form_id uuid, p_record_id uuid, p_submission_id uuid", returns: "uuid", security: "invoker" },
1370
1397
  { 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" },
1371
1398
  { 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" },
1372
1399
  { 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" },
1373
1400
  { 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" },
1401
+ { name: "form_public_options", args: "p_form_id uuid", returns: "jsonb", security: "definer" },
1374
1402
  { name: "form_public_route", args: "p_form_id uuid, p_values jsonb", returns: "jsonb", security: "definer" },
1375
1403
  { name: "form_redirect_domains", args: "p_organization_id uuid", returns: "text[]", security: "invoker" },
1376
1404
  { name: "form_redirect_refusal", args: "p_organization_id uuid, p_url text", returns: "text", security: "invoker" },
1405
+ { 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" },
1377
1406
  { name: "form_restore", args: "p_organization_id uuid, p_form_id uuid", returns: "jsonb", security: "definer" },
1378
1407
  { name: "form_results", args: "p_organization_id uuid, p_form_id uuid", returns: "jsonb", security: "definer" },
1379
1408
  { name: "form_slug", args: "p_organization_id uuid, p_title text, p_form_id uuid DEFAULT NULL::uuid", returns: "text", security: "invoker" },
1380
1409
  { 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" },
1381
1410
  { name: "form_theme_options", args: "", returns: "jsonb", security: "invoker" },
1382
1411
  { name: "form_visit", args: "p_form_id uuid, p_visit text, p_event text, p_field text DEFAULT NULL::text", returns: "text", security: "definer" },
1412
+ { name: "form_visit_admit", args: "p_form_id uuid, p_bucket text", returns: "boolean", security: "definer" },
1383
1413
  { 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" },
1384
1414
  { 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" },
1385
1415
  { name: "formula_compile_sql", args: "p_organization_id uuid, p_expr jsonb, p_values_sql text", returns: "text", security: "invoker" },
@@ -1647,6 +1677,7 @@ var STORE_DOORS = [
1647
1677
  { name: "record_filter_sql", args: "p_organization_id uuid, p_table_id uuid, p_filter jsonb", returns: "text", security: "invoker" },
1648
1678
  { 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" },
1649
1679
  { 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" },
1680
+ { name: "record_page_bundle", args: "p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "invoker" },
1650
1681
  { name: "record_platform_keys", args: "", returns: "text[]", security: "invoker" },
1651
1682
  { 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" },
1652
1683
  { name: "record_reparent", args: "p_organization_id uuid, p_record_id uuid, p_parent_id uuid", returns: "void", security: "definer" },
@@ -2057,6 +2088,7 @@ var ENTITY_TOKENS = [
2057
2088
  "access_shadow_log",
2058
2089
  "account_addon",
2059
2090
  "account_closure",
2091
+ "account_facts",
2060
2092
  "acquisition_block",
2061
2093
  "activity",
2062
2094
  "admin_audit_log",
@@ -2347,6 +2379,7 @@ var ENTITY_TOKENS = [
2347
2379
  "deprecated_relation",
2348
2380
  "derive_run",
2349
2381
  "dev_login_audit",
2382
+ "device_handoff",
2350
2383
  "dict_entry",
2351
2384
  "dict_provider_publication",
2352
2385
  "dict_setting",
@@ -2382,12 +2415,15 @@ var ENTITY_TOKENS = [
2382
2415
  "esign_envelope",
2383
2416
  "esign_envelope_certificate",
2384
2417
  "esign_envelope_document",
2418
+ "esign_envelope_draft",
2385
2419
  "esign_envelope_event",
2386
2420
  "esign_envelope_external_ref",
2387
2421
  "esign_envelope_signer",
2388
2422
  "esign_provider",
2389
2423
  "esign_provider_binding",
2424
+ "esign_saved_signature",
2390
2425
  "esign_signing_key",
2426
+ "esign_template",
2391
2427
  "execution_event_cursor",
2392
2428
  "extension_auth_code",
2393
2429
  "external_link",
@@ -3014,6 +3050,7 @@ var ENTITY_TOKENS = [
3014
3050
  "tool_binding",
3015
3051
  "tool_bundle",
3016
3052
  "tool_call",
3053
+ "tool_call_facts",
3017
3054
  "tool_definition_version",
3018
3055
  "tool_executor",
3019
3056
  "tool_surface_defaults",
@@ -3048,6 +3085,7 @@ var ENTITY_TOKENS = [
3048
3085
  "uploads_inflight",
3049
3086
  "user",
3050
3087
  "user_achievement",
3088
+ "user_acquisition_facts",
3051
3089
  "user_active_context",
3052
3090
  "user_analysis_preference",
3053
3091
  "user_email_preference",
@@ -3518,6 +3556,7 @@ var DOORS = {
3518
3556
  formPreviewRoute: "form_preview_route",
3519
3557
  /** TYPEFORM-DUP: views, starts, completions, drop-off and answers per question. */
3520
3558
  formResults: "form_results",
3559
+ formKnobs: "form_knobs",
3521
3560
  formLookOptions: "form_look_options",
3522
3561
  // PRODUCTS row 14 — "let clients book a 30-minute consult". A booking page IS an
3523
3562
  // `anon_form`, so it is opened and closed by `anonPublish` like any other; this is
@@ -3969,32 +4008,6 @@ var DRILL_DOORS = {
3969
4008
  rows: "drill_rows"
3970
4009
  };
3971
4010
 
3972
- // src/core/recordChanges.ts
3973
- var listeners = /* @__PURE__ */ new Set();
3974
- function announceRecordChanged(recordId) {
3975
- for (const listener of [...listeners]) {
3976
- try {
3977
- listener(recordId);
3978
- } catch (thrown) {
3979
- console.error("[@ai-matrx/records] a record-change listener threw", thrown);
3980
- }
3981
- }
3982
- }
3983
- function onRecordChanged(listener) {
3984
- listeners.add(listener);
3985
- return () => listeners.delete(listener);
3986
- }
3987
- var tableListeners = /* @__PURE__ */ new Set();
3988
- function announceTableStructureChanged(tableId) {
3989
- for (const listener of [...tableListeners]) {
3990
- try {
3991
- listener(tableId);
3992
- } catch (thrown) {
3993
- console.error("[@ai-matrx/records] a table-structure listener threw", thrown);
3994
- }
3995
- }
3996
- }
3997
-
3998
4011
  // src/core/query.ts
3999
4012
  var DEFAULT_PAGE_SIZE = 50;
4000
4013
  function planQuery(query) {
@@ -4114,8 +4127,68 @@ function createRecordsClient(given) {
4114
4127
  } catch {
4115
4128
  }
4116
4129
  }
4130
+ const RECORD_OPENERS = /* @__PURE__ */ new Set(["read_record", "record_row_controls", "record_history", "comment_thread", "computed_provenance"]);
4131
+ const recordFlights = /* @__PURE__ */ new Map();
4132
+ const recordAsked = /* @__PURE__ */ new Map();
4133
+ let recordChangesHeard = false;
4134
+ function bundleRecordOf(door, args) {
4135
+ if (RECORD_OPENERS.has(door)) return typeof args["p_record_id"] === "string" ? args["p_record_id"] : null;
4136
+ const ids = args["p_ids"];
4137
+ const one = Array.isArray(ids) && ids.length === 1 && typeof ids[0] === "string" ? ids[0] : null;
4138
+ if (door === "record_headers") return one;
4139
+ if (door === "my_levels" && args["p_type"] === "record") return one;
4140
+ return null;
4141
+ }
4142
+ async function fillRecordBundle(recordId) {
4143
+ if (!recordChangesHeard) {
4144
+ recordChangesHeard = true;
4145
+ onRecordChanged((changed) => {
4146
+ recordAsked.delete(changed);
4147
+ for (const key of [...bundleParts.keys()]) if (key.includes(changed)) bundleParts.delete(key);
4148
+ });
4149
+ }
4150
+ try {
4151
+ const usable = (r) => r !== null && !r.error && r.data !== null && typeof r.data === "object" && Array.isArray(r.data.parts);
4152
+ const primedAnswer = takePrimedTablePageBundle(org, `record:${recordId}`, null);
4153
+ let response = primedAnswer ? await primedAnswer : null;
4154
+ if (!usable(response)) {
4155
+ response = await config.dataSource.rpc("record_page_bundle", { p_organization_id: org, p_record_id: recordId }, { schema });
4156
+ }
4157
+ if (!usable(response)) return;
4158
+ const now = Date.now();
4159
+ for (const part of response.data.parts) {
4160
+ if (part.error !== void 0 || part.data === void 0) continue;
4161
+ bundleParts.set(bundleKey(part.door, part.args), { data: part.data, at: now });
4162
+ }
4163
+ } catch {
4164
+ }
4165
+ }
4166
+ async function fromRecordBundle(door, args) {
4167
+ if (!doorReady(config, "record_page_bundle")) return void 0;
4168
+ const recordId = bundleRecordOf(door, args);
4169
+ if (!recordId) return void 0;
4170
+ const opener = RECORD_OPENERS.has(door);
4171
+ if (!opener && !recordFlights.has(recordId) && !recordAsked.has(recordId)) return void 0;
4172
+ const asked = recordAsked.get(recordId);
4173
+ const fresh = asked !== void 0 && Date.now() - asked < BUNDLE_TTL_MS;
4174
+ if (!fresh && opener) {
4175
+ recordAsked.set(recordId, Date.now());
4176
+ const flight2 = fillRecordBundle(recordId).finally(() => recordFlights.delete(recordId));
4177
+ recordFlights.set(recordId, flight2);
4178
+ }
4179
+ const flight = recordFlights.get(recordId);
4180
+ if (flight) await flight;
4181
+ const key = bundleKey(door, args);
4182
+ const held = bundleParts.get(key);
4183
+ if (!held) return opener ? null : void 0;
4184
+ bundleParts.delete(key);
4185
+ return Date.now() - held.at < BUNDLE_TTL_MS ? { data: held.data } : null;
4186
+ }
4117
4187
  async function fromBundle(door, args) {
4118
- if (!config.dataSource.opensInOneCall || !doorReady(config, "table_page_bundle")) return null;
4188
+ if (!config.dataSource.opensInOneCall) return null;
4189
+ const fromRecord = await fromRecordBundle(door, args);
4190
+ if (fromRecord !== void 0) return fromRecord;
4191
+ if (!doorReady(config, "table_page_bundle")) return null;
4119
4192
  const tableId = bundleTableOf(door, args);
4120
4193
  if (tableId) {
4121
4194
  const asked = bundleAsked.get(tableId);
@@ -5560,6 +5633,13 @@ function createRecordsClient(given) {
5560
5633
  "formResults"
5561
5634
  );
5562
5635
  },
5636
+ async formKnobs() {
5637
+ return callDoor(
5638
+ DOORS.formKnobs,
5639
+ { p_organization_id: org },
5640
+ "formKnobs"
5641
+ );
5642
+ },
5563
5643
  async formLookOptions(args) {
5564
5644
  return callDoor(
5565
5645
  DOORS.formLookOptions,