@ai-matrx/records 0.98.10 → 0.98.11
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 +6 -0
- package/dist/core/index.cjs +15 -7
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +15 -7
- package/dist/core/index.js.map +1 -1
- package/dist/index.cjs +15 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +15 -7
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +15 -7
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +4 -2
- package/dist/react/index.d.ts +4 -2
- package/dist/react/index.js +15 -7
- package/dist/react/index.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog — @ai-matrx/records
|
|
2
2
|
|
|
3
|
+
## 0.98.11
|
|
4
|
+
|
|
5
|
+
Automatic changed-only republish (docs/metadata drift since the last tag — see
|
|
6
|
+
`git diff npm/records/v0.98.10..npm/records/v0.98.11 -- apps/shared/records`).
|
|
7
|
+
No source changes intended and no consumer action required.
|
|
8
|
+
|
|
3
9
|
## 0.98.10
|
|
4
10
|
|
|
5
11
|
Automatic changed-only republish (docs/metadata drift since the last tag — see
|
package/dist/core/index.cjs
CHANGED
|
@@ -5480,20 +5480,22 @@ function tableRenderSchema(facts) {
|
|
|
5480
5480
|
function refuse(code, message, hint) {
|
|
5481
5481
|
return { ok: false, error: { code, message, hint, ours: true } };
|
|
5482
5482
|
}
|
|
5483
|
-
function alternatePatch(document, field_key, alternate_index) {
|
|
5483
|
+
function alternatePatch(document, field_key, alternate_index, rank) {
|
|
5484
5484
|
const block = document._values ?? {};
|
|
5485
5485
|
const envelope = block[field_key];
|
|
5486
5486
|
const alternates = Array.isArray(envelope?.alternates) ? envelope.alternates : [];
|
|
5487
|
-
const
|
|
5487
|
+
const at = rank === void 0 ? alternate_index : alternates.findIndex((a) => a.rank === rank);
|
|
5488
|
+
alternate_index = at;
|
|
5489
|
+
const chosen = alternates[at];
|
|
5488
5490
|
if (!envelope || !chosen) return { ok: false, message: "That other value is no longer on this record." };
|
|
5489
5491
|
const kept = alternates.filter((_, i) => i !== alternate_index);
|
|
5490
5492
|
const current = document[field_key];
|
|
5491
5493
|
const next = [...kept];
|
|
5492
5494
|
if (current !== null && current !== void 0) {
|
|
5493
5495
|
const taken = new Set(kept.map((a) => a.rank));
|
|
5494
|
-
let
|
|
5495
|
-
while (taken.has(
|
|
5496
|
-
next.push({ value: current, ...envelope.src ? { src: envelope.src } : {}, rank });
|
|
5496
|
+
let rank2 = 1;
|
|
5497
|
+
while (taken.has(rank2)) rank2 += 1;
|
|
5498
|
+
next.push({ value: current, ...envelope.src ? { src: envelope.src } : {}, rank: rank2 });
|
|
5497
5499
|
}
|
|
5498
5500
|
const { ver: _ver, actor: _actor, at: _at, on_behalf_of: _on, absent: _absent, alternates: _alts, src: _src, ...rest } = envelope;
|
|
5499
5501
|
const changed = { ...rest, ...chosen.src ? { src: chosen.src } : {} };
|
|
@@ -5507,14 +5509,20 @@ function alternatePatch(document, field_key, alternate_index) {
|
|
|
5507
5509
|
}
|
|
5508
5510
|
};
|
|
5509
5511
|
}
|
|
5510
|
-
async function chooseAlternate(client, { record_id, field_key, alternate_index }) {
|
|
5512
|
+
async function chooseAlternate(client, { record_id, field_key, alternate_index, rank }) {
|
|
5511
5513
|
const read = await client.recordRead({ record_id, withVersion: true });
|
|
5512
5514
|
if (!read.ok) return read;
|
|
5515
|
+
if (Object.keys(read.data.hidden ?? {}).length > 0) {
|
|
5516
|
+
return refuse("refused_by_rule", "Some fields here are hidden from you, so this choice can't be saved safely.", "Ask someone who can see every field.");
|
|
5517
|
+
}
|
|
5513
5518
|
const version = read.data.version;
|
|
5514
5519
|
if (version === null || version === void 0) {
|
|
5515
5520
|
return refuse("stale_read", "Nothing was saved: this record's latest changes could not be checked.", "Reload, then try again.");
|
|
5516
5521
|
}
|
|
5517
|
-
const
|
|
5522
|
+
const raw = await client.recordAsOf({ record_id, recorded_at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
5523
|
+
if (!raw.ok) return raw;
|
|
5524
|
+
if (raw.data === null) return refuse("not_found", "That record is no longer here.", "Reload, then look again.");
|
|
5525
|
+
const built = alternatePatch(raw.data, field_key, alternate_index, rank);
|
|
5518
5526
|
if (!built.ok) return refuse("not_found", built.message, "Reload, then look again.");
|
|
5519
5527
|
return client.recordUpdate({ record_id, patch: built.patch, expectedVersion: version });
|
|
5520
5528
|
}
|