@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.d.cts
CHANGED
|
@@ -16258,16 +16258,18 @@ interface ChooseAlternateArgs {
|
|
|
16258
16258
|
field_key: string;
|
|
16259
16259
|
/** Position in the field's `alternates` list as the record holds it. */
|
|
16260
16260
|
alternate_index: number;
|
|
16261
|
+
/** When given, the alternate holding this rank is chosen instead — the list a screen drew may be ordered differently. */
|
|
16262
|
+
rank?: number;
|
|
16261
16263
|
}
|
|
16262
16264
|
/** The patch that makes alternate `alternate_index` of `field_key` the value. Pure; exported for tests. */
|
|
16263
|
-
declare function alternatePatch(document: RecordDocument, field_key: string, alternate_index: number): {
|
|
16265
|
+
declare function alternatePatch(document: RecordDocument, field_key: string, alternate_index: number, rank?: number): {
|
|
16264
16266
|
ok: true;
|
|
16265
16267
|
patch: Record<string, unknown>;
|
|
16266
16268
|
} | {
|
|
16267
16269
|
ok: false;
|
|
16268
16270
|
message: string;
|
|
16269
16271
|
};
|
|
16270
|
-
declare function chooseAlternate(client: Pick<RecordsClient, "recordRead" | "recordUpdate">, { record_id, field_key, alternate_index }: ChooseAlternateArgs): Promise<RecordsResult<number>>;
|
|
16272
|
+
declare function chooseAlternate(client: Pick<RecordsClient, "recordRead" | "recordAsOf" | "recordUpdate">, { record_id, field_key, alternate_index, rank }: ChooseAlternateArgs): Promise<RecordsResult<number>>;
|
|
16271
16273
|
|
|
16272
16274
|
interface RecordsProviderProps {
|
|
16273
16275
|
config: RecordsConfig;
|
package/dist/react/index.d.ts
CHANGED
|
@@ -16258,16 +16258,18 @@ interface ChooseAlternateArgs {
|
|
|
16258
16258
|
field_key: string;
|
|
16259
16259
|
/** Position in the field's `alternates` list as the record holds it. */
|
|
16260
16260
|
alternate_index: number;
|
|
16261
|
+
/** When given, the alternate holding this rank is chosen instead — the list a screen drew may be ordered differently. */
|
|
16262
|
+
rank?: number;
|
|
16261
16263
|
}
|
|
16262
16264
|
/** The patch that makes alternate `alternate_index` of `field_key` the value. Pure; exported for tests. */
|
|
16263
|
-
declare function alternatePatch(document: RecordDocument, field_key: string, alternate_index: number): {
|
|
16265
|
+
declare function alternatePatch(document: RecordDocument, field_key: string, alternate_index: number, rank?: number): {
|
|
16264
16266
|
ok: true;
|
|
16265
16267
|
patch: Record<string, unknown>;
|
|
16266
16268
|
} | {
|
|
16267
16269
|
ok: false;
|
|
16268
16270
|
message: string;
|
|
16269
16271
|
};
|
|
16270
|
-
declare function chooseAlternate(client: Pick<RecordsClient, "recordRead" | "recordUpdate">, { record_id, field_key, alternate_index }: ChooseAlternateArgs): Promise<RecordsResult<number>>;
|
|
16272
|
+
declare function chooseAlternate(client: Pick<RecordsClient, "recordRead" | "recordAsOf" | "recordUpdate">, { record_id, field_key, alternate_index, rank }: ChooseAlternateArgs): Promise<RecordsResult<number>>;
|
|
16271
16273
|
|
|
16272
16274
|
interface RecordsProviderProps {
|
|
16273
16275
|
config: RecordsConfig;
|
package/dist/react/index.js
CHANGED
|
@@ -13456,20 +13456,29 @@ function tableRenderSchema(facts) {
|
|
|
13456
13456
|
function refuse4(code, message, hint) {
|
|
13457
13457
|
return { ok: false, error: { code, message, hint, ours: true } };
|
|
13458
13458
|
}
|
|
13459
|
-
function
|
|
13459
|
+
function displacedSource(envelope) {
|
|
13460
|
+
if (envelope.src) return { src: envelope.src };
|
|
13461
|
+
const by = envelope.actor === "agent" ? "an agent" : envelope.actor === "system" ? "the system" : envelope.actor ? "a person" : null;
|
|
13462
|
+
if (by === null) return {};
|
|
13463
|
+
const day = typeof envelope.at === "string" && envelope.at.length >= 10 ? ` on ${envelope.at.slice(0, 10)}` : "";
|
|
13464
|
+
return { src: { name: `Entered by ${by}${day}` } };
|
|
13465
|
+
}
|
|
13466
|
+
function alternatePatch(document, field_key, alternate_index, rank) {
|
|
13460
13467
|
const block = document._values ?? {};
|
|
13461
13468
|
const envelope = block[field_key];
|
|
13462
13469
|
const alternates = Array.isArray(envelope?.alternates) ? envelope.alternates : [];
|
|
13463
|
-
const
|
|
13470
|
+
const at = rank === void 0 ? alternate_index : alternates.findIndex((a) => a.rank === rank);
|
|
13471
|
+
alternate_index = at;
|
|
13472
|
+
const chosen = alternates[at];
|
|
13464
13473
|
if (!envelope || !chosen) return { ok: false, message: "That other value is no longer on this record." };
|
|
13465
13474
|
const kept = alternates.filter((_, i) => i !== alternate_index);
|
|
13466
13475
|
const current = document[field_key];
|
|
13467
13476
|
const next = [...kept];
|
|
13468
13477
|
if (current !== null && current !== void 0) {
|
|
13469
13478
|
const taken = new Set(kept.map((a) => a.rank));
|
|
13470
|
-
let
|
|
13471
|
-
while (taken.has(
|
|
13472
|
-
next.push({ value: current, ...envelope
|
|
13479
|
+
let rank2 = 1;
|
|
13480
|
+
while (taken.has(rank2)) rank2 += 1;
|
|
13481
|
+
next.push({ value: current, ...displacedSource(envelope), rank: rank2 });
|
|
13473
13482
|
}
|
|
13474
13483
|
const { ver: _ver, actor: _actor, at: _at, on_behalf_of: _on, absent: _absent, alternates: _alts, src: _src, ...rest } = envelope;
|
|
13475
13484
|
const changed = { ...rest, ...chosen.src ? { src: chosen.src } : {} };
|
|
@@ -13483,14 +13492,20 @@ function alternatePatch(document, field_key, alternate_index) {
|
|
|
13483
13492
|
}
|
|
13484
13493
|
};
|
|
13485
13494
|
}
|
|
13486
|
-
async function chooseAlternate(client, { record_id, field_key, alternate_index }) {
|
|
13495
|
+
async function chooseAlternate(client, { record_id, field_key, alternate_index, rank }) {
|
|
13487
13496
|
const read = await client.recordRead({ record_id, withVersion: true });
|
|
13488
13497
|
if (!read.ok) return read;
|
|
13498
|
+
if (Object.keys(read.data.hidden ?? {}).length > 0) {
|
|
13499
|
+
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.");
|
|
13500
|
+
}
|
|
13489
13501
|
const version = read.data.version;
|
|
13490
13502
|
if (version === null || version === void 0) {
|
|
13491
13503
|
return refuse4("stale_read", "Nothing was saved: this record's latest changes could not be checked.", "Reload, then try again.");
|
|
13492
13504
|
}
|
|
13493
|
-
const
|
|
13505
|
+
const raw = await client.recordAsOf({ record_id, recorded_at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
13506
|
+
if (!raw.ok) return raw;
|
|
13507
|
+
if (raw.data === null) return refuse4("not_found", "That record is no longer here.", "Reload, then look again.");
|
|
13508
|
+
const built = alternatePatch(raw.data, field_key, alternate_index, rank);
|
|
13494
13509
|
if (!built.ok) return refuse4("not_found", built.message, "Reload, then look again.");
|
|
13495
13510
|
return client.recordUpdate({ record_id, patch: built.patch, expectedVersion: version });
|
|
13496
13511
|
}
|