@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/core/index.js
CHANGED
|
@@ -5148,20 +5148,29 @@ function tableRenderSchema(facts) {
|
|
|
5148
5148
|
function refuse(code, message, hint) {
|
|
5149
5149
|
return { ok: false, error: { code, message, hint, ours: true } };
|
|
5150
5150
|
}
|
|
5151
|
-
function
|
|
5151
|
+
function displacedSource(envelope) {
|
|
5152
|
+
if (envelope.src) return { src: envelope.src };
|
|
5153
|
+
const by = envelope.actor === "agent" ? "an agent" : envelope.actor === "system" ? "the system" : envelope.actor ? "a person" : null;
|
|
5154
|
+
if (by === null) return {};
|
|
5155
|
+
const day = typeof envelope.at === "string" && envelope.at.length >= 10 ? ` on ${envelope.at.slice(0, 10)}` : "";
|
|
5156
|
+
return { src: { name: `Entered by ${by}${day}` } };
|
|
5157
|
+
}
|
|
5158
|
+
function alternatePatch(document, field_key, alternate_index, rank) {
|
|
5152
5159
|
const block = document._values ?? {};
|
|
5153
5160
|
const envelope = block[field_key];
|
|
5154
5161
|
const alternates = Array.isArray(envelope?.alternates) ? envelope.alternates : [];
|
|
5155
|
-
const
|
|
5162
|
+
const at = rank === void 0 ? alternate_index : alternates.findIndex((a) => a.rank === rank);
|
|
5163
|
+
alternate_index = at;
|
|
5164
|
+
const chosen = alternates[at];
|
|
5156
5165
|
if (!envelope || !chosen) return { ok: false, message: "That other value is no longer on this record." };
|
|
5157
5166
|
const kept = alternates.filter((_, i) => i !== alternate_index);
|
|
5158
5167
|
const current = document[field_key];
|
|
5159
5168
|
const next = [...kept];
|
|
5160
5169
|
if (current !== null && current !== void 0) {
|
|
5161
5170
|
const taken = new Set(kept.map((a) => a.rank));
|
|
5162
|
-
let
|
|
5163
|
-
while (taken.has(
|
|
5164
|
-
next.push({ value: current, ...envelope
|
|
5171
|
+
let rank2 = 1;
|
|
5172
|
+
while (taken.has(rank2)) rank2 += 1;
|
|
5173
|
+
next.push({ value: current, ...displacedSource(envelope), rank: rank2 });
|
|
5165
5174
|
}
|
|
5166
5175
|
const { ver: _ver, actor: _actor, at: _at, on_behalf_of: _on, absent: _absent, alternates: _alts, src: _src, ...rest } = envelope;
|
|
5167
5176
|
const changed = { ...rest, ...chosen.src ? { src: chosen.src } : {} };
|
|
@@ -5175,14 +5184,20 @@ function alternatePatch(document, field_key, alternate_index) {
|
|
|
5175
5184
|
}
|
|
5176
5185
|
};
|
|
5177
5186
|
}
|
|
5178
|
-
async function chooseAlternate(client, { record_id, field_key, alternate_index }) {
|
|
5187
|
+
async function chooseAlternate(client, { record_id, field_key, alternate_index, rank }) {
|
|
5179
5188
|
const read = await client.recordRead({ record_id, withVersion: true });
|
|
5180
5189
|
if (!read.ok) return read;
|
|
5190
|
+
if (Object.keys(read.data.hidden ?? {}).length > 0) {
|
|
5191
|
+
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.");
|
|
5192
|
+
}
|
|
5181
5193
|
const version = read.data.version;
|
|
5182
5194
|
if (version === null || version === void 0) {
|
|
5183
5195
|
return refuse("stale_read", "Nothing was saved: this record's latest changes could not be checked.", "Reload, then try again.");
|
|
5184
5196
|
}
|
|
5185
|
-
const
|
|
5197
|
+
const raw = await client.recordAsOf({ record_id, recorded_at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
5198
|
+
if (!raw.ok) return raw;
|
|
5199
|
+
if (raw.data === null) return refuse("not_found", "That record is no longer here.", "Reload, then look again.");
|
|
5200
|
+
const built = alternatePatch(raw.data, field_key, alternate_index, rank);
|
|
5186
5201
|
if (!built.ok) return refuse("not_found", built.message, "Reload, then look again.");
|
|
5187
5202
|
return client.recordUpdate({ record_id, patch: built.patch, expectedVersion: version });
|
|
5188
5203
|
}
|