@ai-matrx/records 0.92.2 → 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.
- package/CHANGELOG.md +37 -0
- package/dist/{client-Dzd8gtAo.d.ts → client-DsPuWFp0.d.ts} +8 -8
- package/dist/{client-Cn3odIIB.d.cts → client-EyD3rS0T.d.cts} +8 -8
- package/dist/core/index.cjs +101 -32
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.cts +16 -15
- package/dist/core/index.d.ts +16 -15
- package/dist/core/index.js +101 -32
- package/dist/core/index.js.map +1 -1
- package/dist/data/index.cjs +46 -24
- package/dist/data/index.cjs.map +1 -1
- package/dist/data/index.d.cts +11 -11
- package/dist/data/index.d.ts +11 -11
- package/dist/data/index.js +46 -24
- package/dist/data/index.js.map +1 -1
- package/dist/{declareTable-CrL6AZKB.d.cts → declareTable-Bkk_Ewib.d.cts} +4 -4
- package/dist/{declareTable-ZRW5EsTQ.d.ts → declareTable-kL5qZoTe.d.ts} +4 -4
- package/dist/entity/index.cjs +43 -29
- package/dist/entity/index.cjs.map +1 -1
- package/dist/entity/index.d.cts +7 -6
- package/dist/entity/index.d.ts +7 -6
- package/dist/entity/index.js +43 -29
- package/dist/entity/index.js.map +1 -1
- package/dist/entity/react.cjs +43 -29
- package/dist/entity/react.cjs.map +1 -1
- package/dist/entity/react.js +43 -29
- package/dist/entity/react.js.map +1 -1
- package/dist/{field-CCY1rG9l.d.cts → field-6rwt4ejZ.d.cts} +1 -1
- package/dist/{field-enufS5ry.d.ts → field-B-WaVZnS.d.ts} +1 -1
- package/dist/forms/index.d.cts +3 -3
- package/dist/forms/index.d.ts +3 -3
- package/dist/index.cjs +92 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -33
- package/dist/index.d.ts +13 -33
- package/dist/index.js +92 -25
- package/dist/index.js.map +1 -1
- package/dist/memory/index.d.cts +7 -7
- package/dist/memory/index.d.ts +7 -7
- package/dist/objectOrganization-BII_K3Gm.d.ts +45 -0
- package/dist/objectOrganization-DfjDQtDb.d.cts +45 -0
- package/dist/{port-C54ykAOv.d.ts → port--acgmxh5.d.ts} +5 -2
- package/dist/{port-Drioh9al.d.cts → port-Cx76dq-X.d.cts} +5 -2
- package/dist/{portal-DRdmZ-xv.d.cts → portal-9sRr6cpG.d.cts} +1 -1
- package/dist/{portal-or_f7BkT.d.ts → portal-BDAqsGkg.d.ts} +1 -1
- package/dist/{ports-s0D2jvqn.d.cts → ports-9BQ3zo2y.d.cts} +108 -2
- package/dist/{ports-BeOgjwYl.d.ts → ports-DYWE1ENo.d.ts} +108 -2
- package/dist/react/index.cjs +101 -32
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +1463 -1363
- package/dist/react/index.d.ts +1463 -1363
- package/dist/react/index.js +101 -32
- package/dist/react/index.js.map +1 -1
- package/dist/realtime/index.cjs +43 -13
- package/dist/realtime/index.cjs.map +1 -1
- package/dist/realtime/index.d.cts +9 -3
- package/dist/realtime/index.d.ts +9 -3
- package/dist/realtime/index.js +43 -13
- package/dist/realtime/index.js.map +1 -1
- package/dist/{record-BwCf9wKW.d.cts → record-DmmeuUrC.d.cts} +1 -1
- package/dist/{record-BwCf9wKW.d.ts → record-DmmeuUrC.d.ts} +1 -1
- package/dist/{relation-eLMgv_dV.d.ts → relation-Op1M67le.d.ts} +2 -2
- package/dist/{relation-8vAWCa67.d.cts → relation-qrb2NbHf.d.cts} +2 -2
- package/dist/{rule-wHI5B0Ka.d.cts → rule-CeHg1sy1.d.cts} +1 -1
- package/dist/{rule-D9yNiorf.d.ts → rule-tN2lxvJ1.d.ts} +1 -1
- package/dist/search/index.d.cts +1 -1
- package/dist/search/index.d.ts +1 -1
- package/dist/setup/index.cjs +117 -42
- package/dist/setup/index.cjs.map +1 -1
- package/dist/setup/index.d.cts +25 -11
- package/dist/setup/index.d.ts +25 -11
- package/dist/setup/index.js +117 -42
- package/dist/setup/index.js.map +1 -1
- package/dist/{subscription-CdoI-UaB.d.cts → subscription-Drbxn-9Z.d.cts} +3 -3
- package/dist/{subscription-BynsG1K6.d.ts → subscription-hdTaRrfK.d.ts} +3 -3
- package/dist/{table-kind-i3lZJa3f.d.ts → table-kind-BZkvzBgc.d.ts} +4 -29
- package/dist/{table-kind-DzctQ7dO.d.cts → table-kind-C-hZxDN7.d.cts} +4 -29
- package/dist/templates/index.d.cts +10 -10
- package/dist/templates/index.d.ts +10 -10
- package/dist/typed-table/index.cjs +46 -24
- package/dist/typed-table/index.cjs.map +1 -1
- package/dist/typed-table/index.d.cts +10 -10
- package/dist/typed-table/index.d.ts +10 -10
- package/dist/typed-table/index.js +46 -24
- package/dist/typed-table/index.js.map +1 -1
- package/dist/{types-BvL_oKFl.d.ts → types-BauAeFW8.d.ts} +2 -2
- package/dist/{types-DAFP6XFe.d.cts → types-CBmUdBT0.d.cts} +2 -2
- package/dist/{types-BKYEeFt4.d.cts → types-Dek9owBe.d.cts} +2 -2
- package/dist/{types-D8qdG3Lg.d.cts → types-DsgXrESm.d.cts} +2 -2
- package/dist/{types-cpKY7Pjb.d.ts → types-HVgWcZDY.d.ts} +2 -2
- package/dist/{types-DYzXhD7j.d.ts → types-hrw-Eff1.d.ts} +2 -2
- package/dist/use-cases/index.d.cts +5 -5
- package/dist/use-cases/index.d.ts +5 -5
- package/dist/{validate-DfNMxjmU.d.cts → validate-B_iUeyh2.d.cts} +1 -1
- package/dist/{validate-DbvAParj.d.ts → validate-w-HGGTf-.d.ts} +1 -1
- package/dist/views/index.cjs +438 -0
- package/dist/views/index.cjs.map +1 -0
- package/dist/views/index.d.cts +401 -0
- package/dist/views/index.d.ts +401 -0
- package/dist/views/index.js +415 -0
- package/dist/views/index.js.map +1 -0
- package/package.json +13 -3
package/dist/entity/react.cjs
CHANGED
|
@@ -399,34 +399,47 @@ var import_realtime = require("@ai-matrx/realtime");
|
|
|
399
399
|
var import_global_slot = require("@ai-matrx/kit/global-slot");
|
|
400
400
|
var REMEMBER_MS = 3e4;
|
|
401
401
|
var REMEMBER_MAX = 500;
|
|
402
|
-
|
|
403
|
-
function trim(now) {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
402
|
+
function ledgerOver(ours) {
|
|
403
|
+
function trim(now) {
|
|
404
|
+
for (const [id, at] of ours) {
|
|
405
|
+
if (now - at <= REMEMBER_MS) break;
|
|
406
|
+
ours.delete(id);
|
|
407
|
+
}
|
|
408
|
+
while (ours.size > REMEMBER_MAX) {
|
|
409
|
+
const oldest = ours.keys().next();
|
|
410
|
+
if (oldest.done === true) break;
|
|
411
|
+
ours.delete(oldest.value);
|
|
412
|
+
}
|
|
412
413
|
}
|
|
414
|
+
return {
|
|
415
|
+
mint() {
|
|
416
|
+
const id = crypto.randomUUID();
|
|
417
|
+
const now = Date.now();
|
|
418
|
+
ours.set(id, now);
|
|
419
|
+
trim(now);
|
|
420
|
+
return id;
|
|
421
|
+
},
|
|
422
|
+
isOwn(opId) {
|
|
423
|
+
if (!opId) return false;
|
|
424
|
+
const at = ours.get(opId);
|
|
425
|
+
if (at === void 0) return false;
|
|
426
|
+
if (Date.now() - at > REMEMBER_MS) {
|
|
427
|
+
ours.delete(opId);
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
return true;
|
|
431
|
+
},
|
|
432
|
+
clear() {
|
|
433
|
+
ours.clear();
|
|
434
|
+
},
|
|
435
|
+
get size() {
|
|
436
|
+
return ours.size;
|
|
437
|
+
}
|
|
438
|
+
};
|
|
413
439
|
}
|
|
414
|
-
|
|
415
|
-
const id = crypto.randomUUID();
|
|
416
|
-
const now = Date.now();
|
|
417
|
-
ours.set(id, now);
|
|
418
|
-
trim(now);
|
|
419
|
-
return id;
|
|
420
|
-
}
|
|
440
|
+
var defaultOpLedger = ledgerOver((0, import_global_slot.globalSlot)("ai-matrx.records.op-ledger", () => /* @__PURE__ */ new Map()));
|
|
421
441
|
function isOwnOp(opId) {
|
|
422
|
-
|
|
423
|
-
const at = ours.get(opId);
|
|
424
|
-
if (at === void 0) return false;
|
|
425
|
-
if (Date.now() - at > REMEMBER_MS) {
|
|
426
|
-
ours.delete(opId);
|
|
427
|
-
return false;
|
|
428
|
-
}
|
|
429
|
-
return true;
|
|
442
|
+
return defaultOpLedger.isOwn(opId);
|
|
430
443
|
}
|
|
431
444
|
|
|
432
445
|
// src/entity/core/realtime.ts
|
|
@@ -689,6 +702,7 @@ function toWireValues(values) {
|
|
|
689
702
|
}
|
|
690
703
|
function createEntityDataPort(options) {
|
|
691
704
|
const client = options.client ?? createEntityClient({ dataSource: options.dataSource });
|
|
705
|
+
const ledger = options.opLedger ?? defaultOpLedger;
|
|
692
706
|
const activeOrganization = () => (options.activeOrganizationId ? options.activeOrganizationId() : options.organization) ?? null;
|
|
693
707
|
const gets = /* @__PURE__ */ new Map();
|
|
694
708
|
const aliases = options.aliases;
|
|
@@ -879,27 +893,27 @@ function createEntityDataPort(options) {
|
|
|
879
893
|
"Pick an organization, then add the row again. Nothing was saved."
|
|
880
894
|
);
|
|
881
895
|
}
|
|
882
|
-
const answer = await client.insert({ token: binding.token, organizationId, rows: [toWireValues(values)], opId:
|
|
896
|
+
const answer = await client.insert({ token: binding.token, organizationId, rows: [toWireValues(values)], opId: ledger.mint() });
|
|
883
897
|
return readBack(alias, answer, "The new row");
|
|
884
898
|
},
|
|
885
899
|
async update(alias, id, patch, baseVersion) {
|
|
886
900
|
const binding = bindingOf(alias);
|
|
887
901
|
if (!binding) return noSuchAlias(alias);
|
|
888
902
|
if (!(0, import_uuid.isUuidShape)(id)) return refusal("invalid_argument", `"${String(id)}" is not a row id.`);
|
|
889
|
-
const answer = await client.update({ token: binding.token, id, baseVersion, patch: toWireValues(patch), opId:
|
|
903
|
+
const answer = await client.update({ token: binding.token, id, baseVersion, patch: toWireValues(patch), opId: ledger.mint() });
|
|
890
904
|
return readBack(alias, answer, "The change");
|
|
891
905
|
},
|
|
892
906
|
async archive(alias, id) {
|
|
893
907
|
const binding = bindingOf(alias);
|
|
894
908
|
if (!binding) return noSuchAlias(alias);
|
|
895
909
|
if (!(0, import_uuid.isUuidShape)(id)) return refusal("invalid_argument", `"${String(id)}" is not a row id.`);
|
|
896
|
-
return done(await client.archive({ token: binding.token, ids: [id], opId:
|
|
910
|
+
return done(await client.archive({ token: binding.token, ids: [id], opId: ledger.mint() }));
|
|
897
911
|
},
|
|
898
912
|
async restore(alias, id) {
|
|
899
913
|
const binding = bindingOf(alias);
|
|
900
914
|
if (!binding) return noSuchAlias(alias);
|
|
901
915
|
if (!(0, import_uuid.isUuidShape)(id)) return refusal("invalid_argument", `"${String(id)}" is not a row id.`);
|
|
902
|
-
return done(await client.unarchive({ token: binding.token, ids: [id], opId:
|
|
916
|
+
return done(await client.unarchive({ token: binding.token, ids: [id], opId: ledger.mint() }));
|
|
903
917
|
},
|
|
904
918
|
subscribe(event, listener) {
|
|
905
919
|
const alias = event.startsWith("rows:") ? event.slice(5) : null;
|