@ai-matrx/records 0.98.10 → 0.98.12
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 +12 -0
- package/dist/core/index.cjs +22 -7
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +22 -7
- package/dist/core/index.js.map +1 -1
- package/dist/first-page/index.cjs +7 -0
- package/dist/first-page/index.cjs.map +1 -1
- package/dist/first-page/index.d.cts +4 -0
- package/dist/first-page/index.d.ts +4 -0
- package/dist/first-page/index.js +7 -0
- package/dist/first-page/index.js.map +1 -1
- package/dist/index.cjs +22 -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 +22 -7
- package/dist/index.js.map +1 -1
- package/dist/react/index.cjs +22 -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 +22 -7
- package/dist/react/index.js.map +1 -1
- package/dist/views/index.cjs +41 -0
- package/dist/views/index.cjs.map +1 -1
- package/dist/views/index.d.cts +28 -1
- package/dist/views/index.d.ts +28 -1
- package/dist/views/index.js +41 -0
- package/dist/views/index.js.map +1 -1
- package/package.json +2 -2
package/dist/react/index.cjs
CHANGED
|
@@ -13775,20 +13775,29 @@ function tableRenderSchema(facts) {
|
|
|
13775
13775
|
function refuse4(code, message, hint) {
|
|
13776
13776
|
return { ok: false, error: { code, message, hint, ours: true } };
|
|
13777
13777
|
}
|
|
13778
|
-
function
|
|
13778
|
+
function displacedSource(envelope) {
|
|
13779
|
+
if (envelope.src) return { src: envelope.src };
|
|
13780
|
+
const by = envelope.actor === "agent" ? "an agent" : envelope.actor === "system" ? "the system" : envelope.actor ? "a person" : null;
|
|
13781
|
+
if (by === null) return {};
|
|
13782
|
+
const day = typeof envelope.at === "string" && envelope.at.length >= 10 ? ` on ${envelope.at.slice(0, 10)}` : "";
|
|
13783
|
+
return { src: { name: `Entered by ${by}${day}` } };
|
|
13784
|
+
}
|
|
13785
|
+
function alternatePatch(document, field_key, alternate_index, rank) {
|
|
13779
13786
|
const block = document._values ?? {};
|
|
13780
13787
|
const envelope = block[field_key];
|
|
13781
13788
|
const alternates = Array.isArray(envelope?.alternates) ? envelope.alternates : [];
|
|
13782
|
-
const
|
|
13789
|
+
const at = rank === void 0 ? alternate_index : alternates.findIndex((a) => a.rank === rank);
|
|
13790
|
+
alternate_index = at;
|
|
13791
|
+
const chosen = alternates[at];
|
|
13783
13792
|
if (!envelope || !chosen) return { ok: false, message: "That other value is no longer on this record." };
|
|
13784
13793
|
const kept = alternates.filter((_, i) => i !== alternate_index);
|
|
13785
13794
|
const current = document[field_key];
|
|
13786
13795
|
const next = [...kept];
|
|
13787
13796
|
if (current !== null && current !== void 0) {
|
|
13788
13797
|
const taken = new Set(kept.map((a) => a.rank));
|
|
13789
|
-
let
|
|
13790
|
-
while (taken.has(
|
|
13791
|
-
next.push({ value: current, ...envelope
|
|
13798
|
+
let rank2 = 1;
|
|
13799
|
+
while (taken.has(rank2)) rank2 += 1;
|
|
13800
|
+
next.push({ value: current, ...displacedSource(envelope), rank: rank2 });
|
|
13792
13801
|
}
|
|
13793
13802
|
const { ver: _ver, actor: _actor, at: _at, on_behalf_of: _on, absent: _absent, alternates: _alts, src: _src, ...rest } = envelope;
|
|
13794
13803
|
const changed = { ...rest, ...chosen.src ? { src: chosen.src } : {} };
|
|
@@ -13802,14 +13811,20 @@ function alternatePatch(document, field_key, alternate_index) {
|
|
|
13802
13811
|
}
|
|
13803
13812
|
};
|
|
13804
13813
|
}
|
|
13805
|
-
async function chooseAlternate(client, { record_id, field_key, alternate_index }) {
|
|
13814
|
+
async function chooseAlternate(client, { record_id, field_key, alternate_index, rank }) {
|
|
13806
13815
|
const read = await client.recordRead({ record_id, withVersion: true });
|
|
13807
13816
|
if (!read.ok) return read;
|
|
13817
|
+
if (Object.keys(read.data.hidden ?? {}).length > 0) {
|
|
13818
|
+
return refuse4("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.");
|
|
13819
|
+
}
|
|
13808
13820
|
const version = read.data.version;
|
|
13809
13821
|
if (version === null || version === void 0) {
|
|
13810
13822
|
return refuse4("stale_read", "Nothing was saved: this record's latest changes could not be checked.", "Reload, then try again.");
|
|
13811
13823
|
}
|
|
13812
|
-
const
|
|
13824
|
+
const raw = await client.recordAsOf({ record_id, recorded_at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
13825
|
+
if (!raw.ok) return raw;
|
|
13826
|
+
if (raw.data === null) return refuse4("not_found", "That record is no longer here.", "Reload, then look again.");
|
|
13827
|
+
const built = alternatePatch(raw.data, field_key, alternate_index, rank);
|
|
13813
13828
|
if (!built.ok) return refuse4("not_found", built.message, "Reload, then look again.");
|
|
13814
13829
|
return client.recordUpdate({ record_id, patch: built.patch, expectedVersion: version });
|
|
13815
13830
|
}
|