@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/dist/index.d.cts
CHANGED
|
@@ -410,15 +410,17 @@ interface ChooseAlternateArgs {
|
|
|
410
410
|
field_key: string;
|
|
411
411
|
/** Position in the field's `alternates` list as the record holds it. */
|
|
412
412
|
alternate_index: number;
|
|
413
|
+
/** When given, the alternate holding this rank is chosen instead — the list a screen drew may be ordered differently. */
|
|
414
|
+
rank?: number;
|
|
413
415
|
}
|
|
414
416
|
/** The patch that makes alternate `alternate_index` of `field_key` the value. Pure; exported for tests. */
|
|
415
|
-
declare function alternatePatch(document: RecordDocument, field_key: string, alternate_index: number): {
|
|
417
|
+
declare function alternatePatch(document: RecordDocument, field_key: string, alternate_index: number, rank?: number): {
|
|
416
418
|
ok: true;
|
|
417
419
|
patch: Record<string, unknown>;
|
|
418
420
|
} | {
|
|
419
421
|
ok: false;
|
|
420
422
|
message: string;
|
|
421
423
|
};
|
|
422
|
-
declare function chooseAlternate(client: Pick<RecordsClient, "recordRead" | "recordUpdate">, { record_id, field_key, alternate_index }: ChooseAlternateArgs): Promise<RecordsResult<number>>;
|
|
424
|
+
declare function chooseAlternate(client: Pick<RecordsClient, "recordRead" | "recordAsOf" | "recordUpdate">, { record_id, field_key, alternate_index, rank }: ChooseAlternateArgs): Promise<RecordsResult<number>>;
|
|
423
425
|
|
|
424
426
|
export { CaptureFileRef, CaptureOutcome, type CaptureQueue, type CaptureQueueCounts, type CaptureQueueOptions, type CaptureQueuePorts, type CaptureQueueStore, type CaptureSyncReport, type ChooseAlternateArgs, CoercibleField, Delivery, Freshness, type MergeField, MergeFieldModifier, type MergeFieldProvenance, type MergeFieldResolution, MergeFieldSemanticType, MergeFieldSource, type MergeFieldTransform, type MissingBehavior, OverridePolicy, type QueuedCapture, type QueuedCaptureFile, type QueuedCaptureState, REFUSALS_WORTH_REPEATING, RecordDocument, RecordsResult, type ResolutionTriple, Timestamp, type TypedDate, type TypedMatchScore, type TypedNumber, type TypedTime, Uuid, alternatePatch, autonumberJoin, autonumberPrefixOf, autonumberSearchOf, autonumberWords, chooseAlternate, filterWithAutonumber, indexedDbStore, isAutonumberField, isDecided, localeDateOrder, memoryStore, mintClientKey, openCaptureQueue, rankTypedMatches, readTypedDate, readTypedNumber, readTypedTime, twoDigitYear, typedDateText, typedMatchScore, typedTimeText };
|
package/dist/index.d.ts
CHANGED
|
@@ -410,15 +410,17 @@ interface ChooseAlternateArgs {
|
|
|
410
410
|
field_key: string;
|
|
411
411
|
/** Position in the field's `alternates` list as the record holds it. */
|
|
412
412
|
alternate_index: number;
|
|
413
|
+
/** When given, the alternate holding this rank is chosen instead — the list a screen drew may be ordered differently. */
|
|
414
|
+
rank?: number;
|
|
413
415
|
}
|
|
414
416
|
/** The patch that makes alternate `alternate_index` of `field_key` the value. Pure; exported for tests. */
|
|
415
|
-
declare function alternatePatch(document: RecordDocument, field_key: string, alternate_index: number): {
|
|
417
|
+
declare function alternatePatch(document: RecordDocument, field_key: string, alternate_index: number, rank?: number): {
|
|
416
418
|
ok: true;
|
|
417
419
|
patch: Record<string, unknown>;
|
|
418
420
|
} | {
|
|
419
421
|
ok: false;
|
|
420
422
|
message: string;
|
|
421
423
|
};
|
|
422
|
-
declare function chooseAlternate(client: Pick<RecordsClient, "recordRead" | "recordUpdate">, { record_id, field_key, alternate_index }: ChooseAlternateArgs): Promise<RecordsResult<number>>;
|
|
424
|
+
declare function chooseAlternate(client: Pick<RecordsClient, "recordRead" | "recordAsOf" | "recordUpdate">, { record_id, field_key, alternate_index, rank }: ChooseAlternateArgs): Promise<RecordsResult<number>>;
|
|
423
425
|
|
|
424
426
|
export { CaptureFileRef, CaptureOutcome, type CaptureQueue, type CaptureQueueCounts, type CaptureQueueOptions, type CaptureQueuePorts, type CaptureQueueStore, type CaptureSyncReport, type ChooseAlternateArgs, CoercibleField, Delivery, Freshness, type MergeField, MergeFieldModifier, type MergeFieldProvenance, type MergeFieldResolution, MergeFieldSemanticType, MergeFieldSource, type MergeFieldTransform, type MissingBehavior, OverridePolicy, type QueuedCapture, type QueuedCaptureFile, type QueuedCaptureState, REFUSALS_WORTH_REPEATING, RecordDocument, RecordsResult, type ResolutionTriple, Timestamp, type TypedDate, type TypedMatchScore, type TypedNumber, type TypedTime, Uuid, alternatePatch, autonumberJoin, autonumberPrefixOf, autonumberSearchOf, autonumberWords, chooseAlternate, filterWithAutonumber, indexedDbStore, isAutonumberField, isDecided, localeDateOrder, memoryStore, mintClientKey, openCaptureQueue, rankTypedMatches, readTypedDate, readTypedNumber, readTypedTime, twoDigitYear, typedDateText, typedMatchScore, typedTimeText };
|
package/dist/index.js
CHANGED
|
@@ -5114,20 +5114,22 @@ function tableRenderSchema(facts) {
|
|
|
5114
5114
|
function refuse(code, message, hint) {
|
|
5115
5115
|
return { ok: false, error: { code, message, hint, ours: true } };
|
|
5116
5116
|
}
|
|
5117
|
-
function alternatePatch(document, field_key, alternate_index) {
|
|
5117
|
+
function alternatePatch(document, field_key, alternate_index, rank) {
|
|
5118
5118
|
const block = document._values ?? {};
|
|
5119
5119
|
const envelope = block[field_key];
|
|
5120
5120
|
const alternates = Array.isArray(envelope?.alternates) ? envelope.alternates : [];
|
|
5121
|
-
const
|
|
5121
|
+
const at = rank === void 0 ? alternate_index : alternates.findIndex((a) => a.rank === rank);
|
|
5122
|
+
alternate_index = at;
|
|
5123
|
+
const chosen = alternates[at];
|
|
5122
5124
|
if (!envelope || !chosen) return { ok: false, message: "That other value is no longer on this record." };
|
|
5123
5125
|
const kept = alternates.filter((_, i) => i !== alternate_index);
|
|
5124
5126
|
const current = document[field_key];
|
|
5125
5127
|
const next = [...kept];
|
|
5126
5128
|
if (current !== null && current !== void 0) {
|
|
5127
5129
|
const taken = new Set(kept.map((a) => a.rank));
|
|
5128
|
-
let
|
|
5129
|
-
while (taken.has(
|
|
5130
|
-
next.push({ value: current, ...envelope.src ? { src: envelope.src } : {}, rank });
|
|
5130
|
+
let rank2 = 1;
|
|
5131
|
+
while (taken.has(rank2)) rank2 += 1;
|
|
5132
|
+
next.push({ value: current, ...envelope.src ? { src: envelope.src } : {}, rank: rank2 });
|
|
5131
5133
|
}
|
|
5132
5134
|
const { ver: _ver, actor: _actor, at: _at, on_behalf_of: _on, absent: _absent, alternates: _alts, src: _src, ...rest } = envelope;
|
|
5133
5135
|
const changed = { ...rest, ...chosen.src ? { src: chosen.src } : {} };
|
|
@@ -5141,14 +5143,20 @@ function alternatePatch(document, field_key, alternate_index) {
|
|
|
5141
5143
|
}
|
|
5142
5144
|
};
|
|
5143
5145
|
}
|
|
5144
|
-
async function chooseAlternate(client, { record_id, field_key, alternate_index }) {
|
|
5146
|
+
async function chooseAlternate(client, { record_id, field_key, alternate_index, rank }) {
|
|
5145
5147
|
const read = await client.recordRead({ record_id, withVersion: true });
|
|
5146
5148
|
if (!read.ok) return read;
|
|
5149
|
+
if (Object.keys(read.data.hidden ?? {}).length > 0) {
|
|
5150
|
+
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.");
|
|
5151
|
+
}
|
|
5147
5152
|
const version = read.data.version;
|
|
5148
5153
|
if (version === null || version === void 0) {
|
|
5149
5154
|
return refuse("stale_read", "Nothing was saved: this record's latest changes could not be checked.", "Reload, then try again.");
|
|
5150
5155
|
}
|
|
5151
|
-
const
|
|
5156
|
+
const raw = await client.recordAsOf({ record_id, recorded_at: (/* @__PURE__ */ new Date()).toISOString() });
|
|
5157
|
+
if (!raw.ok) return raw;
|
|
5158
|
+
if (raw.data === null) return refuse("not_found", "That record is no longer here.", "Reload, then look again.");
|
|
5159
|
+
const built = alternatePatch(raw.data, field_key, alternate_index, rank);
|
|
5152
5160
|
if (!built.ok) return refuse("not_found", built.message, "Reload, then look again.");
|
|
5153
5161
|
return client.recordUpdate({ record_id, patch: built.patch, expectedVersion: version });
|
|
5154
5162
|
}
|