@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
@@ -1,7 +1,7 @@
1
- import { R as RecordsClient } from './client-Cn3odIIB.cjs';
2
- import { F as FieldTypeWord, N as NewFieldDeclaration } from './field-CCY1rG9l.cjs';
3
- import { U as Uuid, a as RecordsError } from './record-BwCf9wKW.cjs';
4
- import { F as FieldDrift } from './table-kind-DzctQ7dO.cjs';
1
+ import { R as RecordsClient } from './client-EyD3rS0T.cjs';
2
+ import { F as FieldTypeWord, N as NewFieldDeclaration } from './field-6rwt4ejZ.cjs';
3
+ import { U as Uuid, a as RecordsError } from './record-DmmeuUrC.cjs';
4
+ import { F as FieldDrift } from './table-kind-C-hZxDN7.cjs';
5
5
 
6
6
  /** One Field a person asked for, in the words a person uses (FLD-1 / FLD-11). */
7
7
  interface NewFieldSpec {
@@ -1,7 +1,7 @@
1
- import { R as RecordsClient } from './client-Dzd8gtAo.js';
2
- import { F as FieldTypeWord, N as NewFieldDeclaration } from './field-enufS5ry.js';
3
- import { U as Uuid, a as RecordsError } from './record-BwCf9wKW.js';
4
- import { F as FieldDrift } from './table-kind-i3lZJa3f.js';
1
+ import { R as RecordsClient } from './client-DsPuWFp0.js';
2
+ import { F as FieldTypeWord, N as NewFieldDeclaration } from './field-B-WaVZnS.js';
3
+ import { U as Uuid, a as RecordsError } from './record-DmmeuUrC.js';
4
+ import { F as FieldDrift } from './table-kind-BZkvzBgc.js';
5
5
 
6
6
  /** One Field a person asked for, in the words a person uses (FLD-1 / FLD-11). */
7
7
  interface NewFieldSpec {
@@ -469,34 +469,47 @@ var import_realtime = require("@ai-matrx/realtime");
469
469
  var import_global_slot = require("@ai-matrx/kit/global-slot");
470
470
  var REMEMBER_MS = 3e4;
471
471
  var REMEMBER_MAX = 500;
472
- var ours = (0, import_global_slot.globalSlot)("ai-matrx.records.op-ledger", () => /* @__PURE__ */ new Map());
473
- function trim(now) {
474
- for (const [id, at] of ours) {
475
- if (now - at <= REMEMBER_MS) break;
476
- ours.delete(id);
477
- }
478
- while (ours.size > REMEMBER_MAX) {
479
- const oldest = ours.keys().next();
480
- if (oldest.done === true) break;
481
- ours.delete(oldest.value);
472
+ function ledgerOver(ours) {
473
+ function trim(now) {
474
+ for (const [id, at] of ours) {
475
+ if (now - at <= REMEMBER_MS) break;
476
+ ours.delete(id);
477
+ }
478
+ while (ours.size > REMEMBER_MAX) {
479
+ const oldest = ours.keys().next();
480
+ if (oldest.done === true) break;
481
+ ours.delete(oldest.value);
482
+ }
482
483
  }
484
+ return {
485
+ mint() {
486
+ const id = crypto.randomUUID();
487
+ const now = Date.now();
488
+ ours.set(id, now);
489
+ trim(now);
490
+ return id;
491
+ },
492
+ isOwn(opId) {
493
+ if (!opId) return false;
494
+ const at = ours.get(opId);
495
+ if (at === void 0) return false;
496
+ if (Date.now() - at > REMEMBER_MS) {
497
+ ours.delete(opId);
498
+ return false;
499
+ }
500
+ return true;
501
+ },
502
+ clear() {
503
+ ours.clear();
504
+ },
505
+ get size() {
506
+ return ours.size;
507
+ }
508
+ };
483
509
  }
484
- function mintOpId() {
485
- const id = crypto.randomUUID();
486
- const now = Date.now();
487
- ours.set(id, now);
488
- trim(now);
489
- return id;
490
- }
510
+ var defaultOpLedger = ledgerOver((0, import_global_slot.globalSlot)("ai-matrx.records.op-ledger", () => /* @__PURE__ */ new Map()));
491
511
  function isOwnOp(opId) {
492
- if (!opId) return false;
493
- const at = ours.get(opId);
494
- if (at === void 0) return false;
495
- if (Date.now() - at > REMEMBER_MS) {
496
- ours.delete(opId);
497
- return false;
498
- }
499
- return true;
512
+ return defaultOpLedger.isOwn(opId);
500
513
  }
501
514
 
502
515
  // src/entity/core/realtime.ts
@@ -719,6 +732,7 @@ function toWireValues(values) {
719
732
  }
720
733
  function createEntityDataPort(options) {
721
734
  const client = options.client ?? createEntityClient({ dataSource: options.dataSource });
735
+ const ledger = options.opLedger ?? defaultOpLedger;
722
736
  const activeOrganization = () => (options.activeOrganizationId ? options.activeOrganizationId() : options.organization) ?? null;
723
737
  const gets = /* @__PURE__ */ new Map();
724
738
  const aliases = options.aliases;
@@ -909,27 +923,27 @@ function createEntityDataPort(options) {
909
923
  "Pick an organization, then add the row again. Nothing was saved."
910
924
  );
911
925
  }
912
- const answer = await client.insert({ token: binding.token, organizationId, rows: [toWireValues(values)], opId: mintOpId() });
926
+ const answer = await client.insert({ token: binding.token, organizationId, rows: [toWireValues(values)], opId: ledger.mint() });
913
927
  return readBack(alias, answer, "The new row");
914
928
  },
915
929
  async update(alias, id, patch, baseVersion) {
916
930
  const binding = bindingOf(alias);
917
931
  if (!binding) return noSuchAlias(alias);
918
932
  if (!(0, import_uuid.isUuidShape)(id)) return refusal("invalid_argument", `"${String(id)}" is not a row id.`);
919
- const answer = await client.update({ token: binding.token, id, baseVersion, patch: toWireValues(patch), opId: mintOpId() });
933
+ const answer = await client.update({ token: binding.token, id, baseVersion, patch: toWireValues(patch), opId: ledger.mint() });
920
934
  return readBack(alias, answer, "The change");
921
935
  },
922
936
  async archive(alias, id) {
923
937
  const binding = bindingOf(alias);
924
938
  if (!binding) return noSuchAlias(alias);
925
939
  if (!(0, import_uuid.isUuidShape)(id)) return refusal("invalid_argument", `"${String(id)}" is not a row id.`);
926
- return done(await client.archive({ token: binding.token, ids: [id], opId: mintOpId() }));
940
+ return done(await client.archive({ token: binding.token, ids: [id], opId: ledger.mint() }));
927
941
  },
928
942
  async restore(alias, id) {
929
943
  const binding = bindingOf(alias);
930
944
  if (!binding) return noSuchAlias(alias);
931
945
  if (!(0, import_uuid.isUuidShape)(id)) return refusal("invalid_argument", `"${String(id)}" is not a row id.`);
932
- return done(await client.unarchive({ token: binding.token, ids: [id], opId: mintOpId() }));
946
+ return done(await client.unarchive({ token: binding.token, ids: [id], opId: ledger.mint() }));
933
947
  },
934
948
  subscribe(event, listener) {
935
949
  const alias = event.startsWith("rows:") ? event.slice(5) : null;