@ai-matrx/records 0.92.1 → 0.93.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 (103) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/README.md +4 -4
  3. package/dist/{client-Dzd8gtAo.d.ts → client-DsPuWFp0.d.ts} +8 -8
  4. package/dist/{client-Cn3odIIB.d.cts → client-EyD3rS0T.d.cts} +8 -8
  5. package/dist/core/index.cjs +101 -32
  6. package/dist/core/index.cjs.map +1 -1
  7. package/dist/core/index.d.cts +16 -15
  8. package/dist/core/index.d.ts +16 -15
  9. package/dist/core/index.js +101 -32
  10. package/dist/core/index.js.map +1 -1
  11. package/dist/data/index.cjs +46 -24
  12. package/dist/data/index.cjs.map +1 -1
  13. package/dist/data/index.d.cts +11 -11
  14. package/dist/data/index.d.ts +11 -11
  15. package/dist/data/index.js +46 -24
  16. package/dist/data/index.js.map +1 -1
  17. package/dist/{declareTable-CrL6AZKB.d.cts → declareTable-Bkk_Ewib.d.cts} +4 -4
  18. package/dist/{declareTable-ZRW5EsTQ.d.ts → declareTable-kL5qZoTe.d.ts} +4 -4
  19. package/dist/entity/index.cjs +43 -29
  20. package/dist/entity/index.cjs.map +1 -1
  21. package/dist/entity/index.d.cts +7 -6
  22. package/dist/entity/index.d.ts +7 -6
  23. package/dist/entity/index.js +43 -29
  24. package/dist/entity/index.js.map +1 -1
  25. package/dist/entity/react.cjs +43 -29
  26. package/dist/entity/react.cjs.map +1 -1
  27. package/dist/entity/react.js +43 -29
  28. package/dist/entity/react.js.map +1 -1
  29. package/dist/{field-CCY1rG9l.d.cts → field-6rwt4ejZ.d.cts} +1 -1
  30. package/dist/{field-enufS5ry.d.ts → field-B-WaVZnS.d.ts} +1 -1
  31. package/dist/forms/index.d.cts +3 -3
  32. package/dist/forms/index.d.ts +3 -3
  33. package/dist/index.cjs +92 -25
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +13 -33
  36. package/dist/index.d.ts +13 -33
  37. package/dist/index.js +92 -25
  38. package/dist/index.js.map +1 -1
  39. package/dist/memory/index.d.cts +7 -7
  40. package/dist/memory/index.d.ts +7 -7
  41. package/dist/objectOrganization-BII_K3Gm.d.ts +45 -0
  42. package/dist/objectOrganization-DfjDQtDb.d.cts +45 -0
  43. package/dist/{port-C54ykAOv.d.ts → port--acgmxh5.d.ts} +5 -2
  44. package/dist/{port-Drioh9al.d.cts → port-Cx76dq-X.d.cts} +5 -2
  45. package/dist/{portal-DRdmZ-xv.d.cts → portal-9sRr6cpG.d.cts} +1 -1
  46. package/dist/{portal-or_f7BkT.d.ts → portal-BDAqsGkg.d.ts} +1 -1
  47. package/dist/{ports-s0D2jvqn.d.cts → ports-9BQ3zo2y.d.cts} +108 -2
  48. package/dist/{ports-BeOgjwYl.d.ts → ports-DYWE1ENo.d.ts} +108 -2
  49. package/dist/react/index.cjs +101 -32
  50. package/dist/react/index.cjs.map +1 -1
  51. package/dist/react/index.d.cts +1463 -1363
  52. package/dist/react/index.d.ts +1463 -1363
  53. package/dist/react/index.js +101 -32
  54. package/dist/react/index.js.map +1 -1
  55. package/dist/realtime/index.cjs +43 -13
  56. package/dist/realtime/index.cjs.map +1 -1
  57. package/dist/realtime/index.d.cts +9 -3
  58. package/dist/realtime/index.d.ts +9 -3
  59. package/dist/realtime/index.js +43 -13
  60. package/dist/realtime/index.js.map +1 -1
  61. package/dist/{record-BwCf9wKW.d.cts → record-DmmeuUrC.d.cts} +1 -1
  62. package/dist/{record-BwCf9wKW.d.ts → record-DmmeuUrC.d.ts} +1 -1
  63. package/dist/{relation-eLMgv_dV.d.ts → relation-Op1M67le.d.ts} +2 -2
  64. package/dist/{relation-8vAWCa67.d.cts → relation-qrb2NbHf.d.cts} +2 -2
  65. package/dist/{rule-wHI5B0Ka.d.cts → rule-CeHg1sy1.d.cts} +1 -1
  66. package/dist/{rule-D9yNiorf.d.ts → rule-tN2lxvJ1.d.ts} +1 -1
  67. package/dist/search/index.d.cts +1 -1
  68. package/dist/search/index.d.ts +1 -1
  69. package/dist/setup/index.cjs +117 -42
  70. package/dist/setup/index.cjs.map +1 -1
  71. package/dist/setup/index.d.cts +25 -11
  72. package/dist/setup/index.d.ts +25 -11
  73. package/dist/setup/index.js +117 -42
  74. package/dist/setup/index.js.map +1 -1
  75. package/dist/{subscription-CdoI-UaB.d.cts → subscription-Drbxn-9Z.d.cts} +3 -3
  76. package/dist/{subscription-BynsG1K6.d.ts → subscription-hdTaRrfK.d.ts} +3 -3
  77. package/dist/{table-kind-i3lZJa3f.d.ts → table-kind-BZkvzBgc.d.ts} +4 -29
  78. package/dist/{table-kind-DzctQ7dO.d.cts → table-kind-C-hZxDN7.d.cts} +4 -29
  79. package/dist/templates/index.d.cts +10 -10
  80. package/dist/templates/index.d.ts +10 -10
  81. package/dist/typed-table/index.cjs +46 -24
  82. package/dist/typed-table/index.cjs.map +1 -1
  83. package/dist/typed-table/index.d.cts +10 -10
  84. package/dist/typed-table/index.d.ts +10 -10
  85. package/dist/typed-table/index.js +46 -24
  86. package/dist/typed-table/index.js.map +1 -1
  87. package/dist/{types-BvL_oKFl.d.ts → types-BauAeFW8.d.ts} +2 -2
  88. package/dist/{types-DAFP6XFe.d.cts → types-CBmUdBT0.d.cts} +2 -2
  89. package/dist/{types-BKYEeFt4.d.cts → types-Dek9owBe.d.cts} +2 -2
  90. package/dist/{types-D8qdG3Lg.d.cts → types-DsgXrESm.d.cts} +2 -2
  91. package/dist/{types-cpKY7Pjb.d.ts → types-HVgWcZDY.d.ts} +2 -2
  92. package/dist/{types-DYzXhD7j.d.ts → types-hrw-Eff1.d.ts} +2 -2
  93. package/dist/use-cases/index.d.cts +5 -5
  94. package/dist/use-cases/index.d.ts +5 -5
  95. package/dist/{validate-DfNMxjmU.d.cts → validate-B_iUeyh2.d.cts} +1 -1
  96. package/dist/{validate-DbvAParj.d.ts → validate-w-HGGTf-.d.ts} +1 -1
  97. package/dist/views/index.cjs +438 -0
  98. package/dist/views/index.cjs.map +1 -0
  99. package/dist/views/index.d.cts +401 -0
  100. package/dist/views/index.d.ts +401 -0
  101. package/dist/views/index.js +415 -0
  102. package/dist/views/index.js.map +1 -0
  103. package/package.json +12 -2
@@ -509,40 +509,59 @@ function sourceArchivedOf(value) {
509
509
  import { globalSlot as globalSlot2 } from "@ai-matrx/kit/global-slot";
510
510
  var REMEMBER_MS = 3e4;
511
511
  var REMEMBER_MAX = 500;
512
- var ours = globalSlot2("ai-matrx.records.op-ledger", () => /* @__PURE__ */ new Map());
513
- function trim(now) {
514
- for (const [id, at] of ours) {
515
- if (now - at <= REMEMBER_MS) break;
516
- ours.delete(id);
517
- }
518
- while (ours.size > REMEMBER_MAX) {
519
- const oldest = ours.keys().next();
520
- if (oldest.done === true) break;
521
- ours.delete(oldest.value);
512
+ function ledgerOver(ours) {
513
+ function trim(now) {
514
+ for (const [id, at] of ours) {
515
+ if (now - at <= REMEMBER_MS) break;
516
+ ours.delete(id);
517
+ }
518
+ while (ours.size > REMEMBER_MAX) {
519
+ const oldest = ours.keys().next();
520
+ if (oldest.done === true) break;
521
+ ours.delete(oldest.value);
522
+ }
522
523
  }
524
+ return {
525
+ mint() {
526
+ const id = crypto.randomUUID();
527
+ const now = Date.now();
528
+ ours.set(id, now);
529
+ trim(now);
530
+ return id;
531
+ },
532
+ isOwn(opId) {
533
+ if (!opId) return false;
534
+ const at = ours.get(opId);
535
+ if (at === void 0) return false;
536
+ if (Date.now() - at > REMEMBER_MS) {
537
+ ours.delete(opId);
538
+ return false;
539
+ }
540
+ return true;
541
+ },
542
+ clear() {
543
+ ours.clear();
544
+ },
545
+ get size() {
546
+ return ours.size;
547
+ }
548
+ };
523
549
  }
550
+ function createOpLedger() {
551
+ return ledgerOver(/* @__PURE__ */ new Map());
552
+ }
553
+ var defaultOpLedger = ledgerOver(globalSlot2("ai-matrx.records.op-ledger", () => /* @__PURE__ */ new Map()));
524
554
  function mintOpId() {
525
- const id = crypto.randomUUID();
526
- const now = Date.now();
527
- ours.set(id, now);
528
- trim(now);
529
- return id;
555
+ return defaultOpLedger.mint();
530
556
  }
531
557
  function isOwnOp(opId) {
532
- if (!opId) return false;
533
- const at = ours.get(opId);
534
- if (at === void 0) return false;
535
- if (Date.now() - at > REMEMBER_MS) {
536
- ours.delete(opId);
537
- return false;
538
- }
539
- return true;
558
+ return defaultOpLedger.isOwn(opId);
540
559
  }
541
560
  function forgetAllOps() {
542
- ours.clear();
561
+ defaultOpLedger.clear();
543
562
  }
544
563
  function rememberedOpCount() {
545
- return ours.size;
564
+ return defaultOpLedger.size;
546
565
  }
547
566
 
548
567
  // src/choice.ts
@@ -4208,6 +4227,8 @@ function createRecordsClient(given) {
4208
4227
  const config = { ...given, dataSource: asRecordsDataSource(given.dataSource) };
4209
4228
  const schema = config.schema ?? DEFAULT_SCHEMA;
4210
4229
  const org = config.organizationId;
4230
+ const ledger = config.opLedger ?? defaultOpLedger;
4231
+ const mintOp = () => ledger.mint();
4211
4232
  const scream = sink(config);
4212
4233
  const BUNDLE_TTL_MS = 1e4;
4213
4234
  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"]);
@@ -4594,14 +4615,14 @@ function createRecordsClient(given) {
4594
4615
  async recordWrite({ table_id, data }) {
4595
4616
  const result = await callDoor(
4596
4617
  DOORS.recordWrite,
4597
- { p_organization_id: org, p_table_id: table_id, p_data: { ...data, _op_id: mintOpId() } },
4618
+ { p_organization_id: org, p_table_id: table_id, p_data: { ...data, _op_id: mintOp() } },
4598
4619
  "recordWrite"
4599
4620
  );
4600
4621
  if (result.ok && typeof result.data === "string") announceRecordChanged(result.data);
4601
4622
  return result;
4602
4623
  },
4603
4624
  async recordWriteMany({ table_id, rows, ids }) {
4604
- const opId = mintOpId();
4625
+ const opId = mintOp();
4605
4626
  return callDoor(
4606
4627
  DOORS.recordWriteMany,
4607
4628
  {
@@ -4614,7 +4635,7 @@ function createRecordsClient(given) {
4614
4635
  );
4615
4636
  },
4616
4637
  async recordChangeMany({ table_id, changes }) {
4617
- const opId = mintOpId();
4638
+ const opId = mintOp();
4618
4639
  const result = await callDoor(
4619
4640
  DOORS.recordChangeMany,
4620
4641
  {
@@ -4637,7 +4658,7 @@ function createRecordsClient(given) {
4637
4658
  return result;
4638
4659
  },
4639
4660
  async recordWriteGraph({ table_id, parent, children, edges }) {
4640
- const opId = mintOpId();
4661
+ const opId = mintOp();
4641
4662
  return callDoor(
4642
4663
  DOORS.recordWriteGraph,
4643
4664
  {
@@ -4661,7 +4682,7 @@ function createRecordsClient(given) {
4661
4682
  {
4662
4683
  p_organization_id: org,
4663
4684
  p_record_id: record_id,
4664
- p_patch: { ...patch, _op_id: mintOpId() },
4685
+ p_patch: { ...patch, _op_id: mintOp() },
4665
4686
  ...expectedVersion === void 0 ? {} : { p_expected_version: expectedVersion }
4666
4687
  },
4667
4688
  "recordUpdate"
@@ -4675,7 +4696,7 @@ function createRecordsClient(given) {
4675
4696
  {
4676
4697
  p_organization_id: org,
4677
4698
  p_record_id: record_id,
4678
- p_patch: { ...patch, _op_id: mintOpId() },
4699
+ p_patch: { ...patch, _op_id: mintOp() },
4679
4700
  p_add: add,
4680
4701
  ...expectedVersion === void 0 ? {} : { p_expected_version: expectedVersion }
4681
4702
  },
@@ -5700,7 +5721,7 @@ function createRecordsClient(given) {
5700
5721
  p_table_id: table_id,
5701
5722
  p_key: keys,
5702
5723
  // The op id rides the envelope, as `recordWrite` / `recordUpdate` send it; each door takes it off.
5703
- p_data: { ...data, _op_id: mintOpId() },
5724
+ p_data: { ...data, _op_id: mintOp() },
5704
5725
  ...expectedVersion === void 0 ? {} : { p_expected_version: expectedVersion }
5705
5726
  },
5706
5727
  "recordUpsert"
@@ -12103,6 +12124,48 @@ function openCaptureQueue(opts) {
12103
12124
  return queue;
12104
12125
  }
12105
12126
 
12127
+ // src/objectOrganization.ts
12128
+ var WHERE_ID_OPENS_DOOR = "where_id_opens";
12129
+ function doorIsAbsent(error) {
12130
+ if (error.code === "PGRST202" || error.code === "42883") return true;
12131
+ return /could not find the function/i.test(error.message ?? "");
12132
+ }
12133
+ var DOOR_ABSENT_WHY = "custom.where_id_opens is missing from this database, so this page cannot tell which organization the record lives in and holds instead of guessing. Remedy: the chair applies migrations/campaign/openbyid_one_address_opens_any_id.sql and openbyid_the_resolver_can_be_reached.sql.";
12134
+ async function resolveObjectOrganization(dataSource, id) {
12135
+ let answered;
12136
+ try {
12137
+ answered = await dataSource.rpc(WHERE_ID_OPENS_DOOR, { p_id: id }, { schema: "custom" });
12138
+ } catch (thrown) {
12139
+ return { state: "unavailable", why: thrown instanceof Error ? thrown.message : "The record store did not answer." };
12140
+ }
12141
+ return readObjectOrganizationAnswer(answered, id);
12142
+ }
12143
+ function readObjectOrganizationAnswer(answered, id) {
12144
+ if (answered.error) {
12145
+ if (doorIsAbsent(answered.error)) {
12146
+ console.warn(`[@ai-matrx/records] ${DOOR_ABSENT_WHY}`);
12147
+ return { state: "unavailable", why: DOOR_ABSENT_WHY };
12148
+ }
12149
+ return { state: "unavailable", why: answered.error.message ?? "The record store refused to say where this is." };
12150
+ }
12151
+ const row = answered.data;
12152
+ if (row === null || row === void 0) return { state: "not-given" };
12153
+ if (typeof row !== "object" || typeof row.organization_id !== "string" || typeof row.kind !== "string") {
12154
+ return { state: "unavailable", why: "The record store answered something this page cannot read." };
12155
+ }
12156
+ return {
12157
+ state: "found",
12158
+ organizationId: row.organization_id,
12159
+ kind: row.kind,
12160
+ path: typeof row.path === "string" ? row.path : null,
12161
+ live: row.live !== false,
12162
+ resolvedId: typeof row.resolved_id === "string" ? row.resolved_id : id
12163
+ };
12164
+ }
12165
+ function whereIdOpensPort(dataSource) {
12166
+ return { organizationOf: (id) => resolveObjectOrganization(dataSource, id) };
12167
+ }
12168
+
12106
12169
  // src/record-scope.ts
12107
12170
  function scopeChip(scope) {
12108
12171
  return scope.title ? `About: ${scope.title}` : "About: this record";
@@ -12576,6 +12639,7 @@ export {
12576
12639
  TO_CUSTOM_FIELDS,
12577
12640
  VALUE_ALTERNATE_KEYS,
12578
12641
  VALUE_ENVELOPE_KEYS,
12642
+ WHERE_ID_OPENS_DOOR,
12579
12643
  actionRefusals,
12580
12644
  addressFromText,
12581
12645
  addressMapUrl,
@@ -12608,8 +12672,10 @@ export {
12608
12672
  confidentialRefusal,
12609
12673
  confidentialRequest,
12610
12674
  confidentialState,
12675
+ createOpLedger,
12611
12676
  decideTypedChoice,
12612
12677
  declareDrillDefinition,
12678
+ defaultOpLedger,
12613
12679
  defineTypedTable,
12614
12680
  drillAnswerOf,
12615
12681
  drillFindingKnob,
@@ -12695,6 +12761,7 @@ export {
12695
12761
  publicFormPath,
12696
12762
  rankTypedMatches,
12697
12763
  ratingMaxOf,
12764
+ readObjectOrganizationAnswer,
12698
12765
  readTypedDate,
12699
12766
  readTypedDuration,
12700
12767
  readTypedNumber,
@@ -12712,6 +12779,7 @@ export {
12712
12779
  rememberedOpCount,
12713
12780
  removeAppRow,
12714
12781
  removedChoicesInUse,
12782
+ resolveObjectOrganization,
12715
12783
  richTextPlain,
12716
12784
  rowFromDocument,
12717
12785
  ruleThatRefuses,
@@ -12776,6 +12844,7 @@ export {
12776
12844
  useTables,
12777
12845
  useTypedTable,
12778
12846
  valueConverts,
12847
+ whereIdOpensPort,
12779
12848
  withCallersClock,
12780
12849
  withRowCounts,
12781
12850
  withTablePlacement,