-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiagnostics.ts
More file actions
73 lines (68 loc) · 2.34 KB
/
Copy pathdiagnostics.ts
File metadata and controls
73 lines (68 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* Operator-facing inspection helpers for the v19 application API.
*/
import { resolveReceiptProvenance } from './src/application/ReceiptProvenanceRegistry.ts';
import WarpError from './src/domain/errors/WarpError.ts';
import type ReadIdentity from './src/domain/services/optic/ReadIdentity.ts';
import type { Receipt } from './src/domain/api/Receipt.ts';
export type ReceiptSubstrateInspection =
| {
readonly operation: 'write';
readonly patchSha: string | undefined;
}
| {
readonly operation: 'read';
readonly identity: ReadIdentity | undefined;
}
| {
readonly operation: 'join';
readonly patchShas: readonly string[];
};
export type ReceiptInspection = {
readonly operation: Receipt['operation'];
readonly outcome: Receipt['outcome'];
readonly lane: string;
readonly writer: string;
readonly reason: string | undefined;
readonly evidence: 'present' | 'absent';
readonly objectIds: readonly string[];
readonly substrate: ReceiptSubstrateInspection;
};
export function inspectReceipt(receipt: Receipt): ReceiptInspection {
const provenance = resolveReceiptProvenance(receipt);
if (provenance.operation !== receipt.operation) {
throw new WarpError(
'Receipt provenance operation does not match the receipt',
'E_RECEIPT_PROVENANCE_MISMATCH'
);
}
return Object.freeze({
operation: receipt.operation,
outcome: receipt.outcome,
lane: receipt.operation === 'write' ? receipt.lane : receipt.timeline,
writer: receipt.writer,
reason: receipt.reason,
evidence: receipt.evidence === undefined ? 'absent' : 'present',
objectIds: Object.freeze(receiptObjectIds(provenance)),
substrate: provenance,
});
}
function receiptObjectIds(provenance: ReceiptSubstrateInspection): string[] {
if (provenance.operation === 'write') {
return provenance.patchSha === undefined ? [] : [provenance.patchSha];
}
if (provenance.operation === 'join') {
return [...provenance.patchShas];
}
if (provenance.identity === undefined) {
return [];
}
return [
...new Set([
provenance.identity.checkpointSha,
...provenance.identity.checkpointFrontier.map((entry) => entry.patchSha),
...provenance.identity.checkpointIndexShards.map((shard) => shard.oid),
...provenance.identity.tailWitnesses.map((witness) => witness.sha),
]),
];
}