@affiant/core 0.1.0-alpha.0
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/LICENSE +202 -0
- package/README.md +354 -0
- package/dist/context.d.ts +136 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +30 -0
- package/dist/context.js.map +1 -0
- package/dist/docket/entry.d.ts +421 -0
- package/dist/docket/entry.d.ts.map +1 -0
- package/dist/docket/entry.js +155 -0
- package/dist/docket/entry.js.map +1 -0
- package/dist/docket/expiry.d.ts +82 -0
- package/dist/docket/expiry.d.ts.map +1 -0
- package/dist/docket/expiry.js +106 -0
- package/dist/docket/expiry.js.map +1 -0
- package/dist/docket/memory.d.ts +163 -0
- package/dist/docket/memory.d.ts.map +1 -0
- package/dist/docket/memory.js +528 -0
- package/dist/docket/memory.js.map +1 -0
- package/dist/docket/store.d.ts +387 -0
- package/dist/docket/store.d.ts.map +1 -0
- package/dist/docket/store.js +51 -0
- package/dist/docket/store.js.map +1 -0
- package/dist/errors.d.ts +153 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +164 -0
- package/dist/errors.js.map +1 -0
- package/dist/gate/coverage.d.ts +152 -0
- package/dist/gate/coverage.d.ts.map +1 -0
- package/dist/gate/coverage.js +114 -0
- package/dist/gate/coverage.js.map +1 -0
- package/dist/gate/decide.d.ts +207 -0
- package/dist/gate/decide.d.ts.map +1 -0
- package/dist/gate/decide.js +559 -0
- package/dist/gate/decide.js.map +1 -0
- package/dist/gate/gate.d.ts +212 -0
- package/dist/gate/gate.d.ts.map +1 -0
- package/dist/gate/gate.js +175 -0
- package/dist/gate/gate.js.map +1 -0
- package/dist/gate/pipeline.d.ts +285 -0
- package/dist/gate/pipeline.d.ts.map +1 -0
- package/dist/gate/pipeline.js +515 -0
- package/dist/gate/pipeline.js.map +1 -0
- package/dist/gate/policy.d.ts +272 -0
- package/dist/gate/policy.d.ts.map +1 -0
- package/dist/gate/policy.js +396 -0
- package/dist/gate/policy.js.map +1 -0
- package/dist/gate/wrap.d.ts +107 -0
- package/dist/gate/wrap.d.ts.map +1 -0
- package/dist/gate/wrap.js +164 -0
- package/dist/gate/wrap.js.map +1 -0
- package/dist/index.d.ts +95 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +111 -0
- package/dist/index.js.map +1 -0
- package/dist/model/affidavit.d.ts +354 -0
- package/dist/model/affidavit.d.ts.map +1 -0
- package/dist/model/affidavit.js +417 -0
- package/dist/model/affidavit.js.map +1 -0
- package/dist/model/amendments.d.ts +160 -0
- package/dist/model/amendments.d.ts.map +1 -0
- package/dist/model/amendments.js +183 -0
- package/dist/model/amendments.js.map +1 -0
- package/dist/model/canonical.d.ts +311 -0
- package/dist/model/canonical.d.ts.map +1 -0
- package/dist/model/canonical.js +665 -0
- package/dist/model/canonical.js.map +1 -0
- package/dist/model/money.d.ts +127 -0
- package/dist/model/money.d.ts.map +1 -0
- package/dist/model/money.js +177 -0
- package/dist/model/money.js.map +1 -0
- package/dist/model/provenance.d.ts +315 -0
- package/dist/model/provenance.d.ts.map +1 -0
- package/dist/model/provenance.js +223 -0
- package/dist/model/provenance.js.map +1 -0
- package/dist/ports.d.ts +269 -0
- package/dist/ports.d.ts.map +1 -0
- package/dist/ports.js +34 -0
- package/dist/ports.js.map +1 -0
- package/dist/store-memory.d.ts +21 -0
- package/dist/store-memory.d.ts.map +1 -0
- package/dist/store-memory.js +20 -0
- package/dist/store-memory.js.map +1 -0
- package/dist/telemetry-keys.d.ts +65 -0
- package/dist/telemetry-keys.d.ts.map +1 -0
- package/dist/telemetry-keys.js +72 -0
- package/dist/telemetry-keys.js.map +1 -0
- package/dist/telemetry.d.ts +77 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +43 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/testing.d.ts +574 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +1291 -0
- package/dist/testing.js.map +1 -0
- package/package.json +75 -0
- package/telemetry-keys.json +92 -0
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Affidavit: the sworn evidence record for one proposed write, its fields, the
|
|
3
|
+
* three confidence numbers, and the mapping to and from the wire shape.
|
|
4
|
+
*
|
|
5
|
+
* **Rules served: AF-1** (`fields[]` carries only the proposed fields; unknown
|
|
6
|
+
* provenance is present and tagged `Empty`, a field the operation does not propose
|
|
7
|
+
* is absent), **AF-2** (three confidence numbers, `aggregateConfidence` the
|
|
8
|
+
* *minimum* over proposed fields with `Empty` counting as `0`), **AF-3**
|
|
9
|
+
* (`entityId` non-null ⇔ update; an update carries a `previousValue` key on every
|
|
10
|
+
* proposed field, `null` where the field had no stored value), **SR-2** (money is a
|
|
11
|
+
* decimal string plus an ISO 4217 code — the shape only; the validator is pull
|
|
12
|
+
* request C3).
|
|
13
|
+
*
|
|
14
|
+
* Why AF-2 is a minimum and not a mean: a mean that first discards every `Empty`
|
|
15
|
+
* field lets a mostly-empty Affidavit report high confidence, which is the exact
|
|
16
|
+
* hole once provenance authorises writes. The shipped .NET projection computes a
|
|
17
|
+
* mean over non-`Empty` fields; the parity manifest names it.
|
|
18
|
+
*
|
|
19
|
+
* Nothing here reads a clock or a database. `createdAt` is passed in and
|
|
20
|
+
* `previousValue` comes from the host's projection port.
|
|
21
|
+
*
|
|
22
|
+
* @packageDocumentation
|
|
23
|
+
*/
|
|
24
|
+
import type { Affidavit as WireAffidavit, EvidenceCardRequest as WireEvidenceCardRequest, FieldPresentation, JsonValue } from "@affiant/contract";
|
|
25
|
+
import type { Operation } from "../ports.js";
|
|
26
|
+
import { type ProvenanceChain } from "./provenance.js";
|
|
27
|
+
/**
|
|
28
|
+
* Any value that survives a round trip through JSON, re-exported from
|
|
29
|
+
* `@affiant/contract` so the gate and the wire agree on one definition of what a
|
|
30
|
+
* field value may be. `null` is a value; `undefined` is not.
|
|
31
|
+
*/
|
|
32
|
+
export type { JsonValue };
|
|
33
|
+
/**
|
|
34
|
+
* Whether `value` is a {@link JsonValue}: no `undefined`, no function, no symbol, no
|
|
35
|
+
* `NaN` or infinity, no cycle.
|
|
36
|
+
*
|
|
37
|
+
* Checked deeply, because a field value is carried onto a record a person is asked
|
|
38
|
+
* to swear to and later hashed into a canonical form (SR-1); a value that
|
|
39
|
+
* serialises to something different from what the reviewer saw is the failure mode
|
|
40
|
+
* this closes.
|
|
41
|
+
*/
|
|
42
|
+
export declare function isJsonValue(value: unknown): value is JsonValue;
|
|
43
|
+
/**
|
|
44
|
+
* Money is one definition, and it lives in `./money.ts` — the SR-2 module, which
|
|
45
|
+
* owns the {@link Money} shape, the decimal-string and ISO 4217 validators, and the
|
|
46
|
+
* scale check a host declares. Re-exported here because an Affidavit is where a
|
|
47
|
+
* caller meets a monetary field, and because the export path `@affiant/core` offers
|
|
48
|
+
* should not depend on which pull request wrote which half.
|
|
49
|
+
*
|
|
50
|
+
* Note that `isMoney` **validates**: it is `false` for `{ amount: "1e3" }` and for
|
|
51
|
+
* `{ currency: "usd" }`, not only for a missing property. A shape-only guard on a
|
|
52
|
+
* public surface would answer "yes, money" for values SR-2 refuses, which is the
|
|
53
|
+
* wrong answer to give a host that is about to swear to one.
|
|
54
|
+
*/
|
|
55
|
+
export { isMoney } from "./money.js";
|
|
56
|
+
export type { Money } from "./money.js";
|
|
57
|
+
/** How a reviewer surface should render a field. Same set as the wire's. */
|
|
58
|
+
export type AffidavitFieldKind = "text" | "number" | "date" | "enum";
|
|
59
|
+
/** Every {@link AffidavitFieldKind}. */
|
|
60
|
+
export declare const AFFIDAVIT_FIELD_KINDS: readonly ["text", "number", "date", "enum"];
|
|
61
|
+
/**
|
|
62
|
+
* One sworn field: the proposed value, the value it replaces, and the whole
|
|
63
|
+
* provenance chain behind it.
|
|
64
|
+
*
|
|
65
|
+
* `previousValue` is `null` on a create and on an update field that had no stored
|
|
66
|
+
* value; the two are distinguished by the Affidavit's `operationType`, not by the
|
|
67
|
+
* field (AF-3).
|
|
68
|
+
*/
|
|
69
|
+
export interface AffidavitField {
|
|
70
|
+
/** The field's name on the target entity. The key amendments use. */
|
|
71
|
+
readonly name: string;
|
|
72
|
+
/** Rendering hint for a reviewer surface. */
|
|
73
|
+
readonly kind: AffidavitFieldKind;
|
|
74
|
+
/** The proposed value. */
|
|
75
|
+
readonly value: JsonValue;
|
|
76
|
+
/** The value being replaced, or `null` (AF-3). */
|
|
77
|
+
readonly previousValue: JsonValue | null;
|
|
78
|
+
/** Where the value came from, and everything it displaced. */
|
|
79
|
+
readonly provenance: ProvenanceChain;
|
|
80
|
+
/** Whether the target entity requires the field. */
|
|
81
|
+
readonly isMandatory: boolean;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The sworn evidence record for one proposed write.
|
|
85
|
+
*
|
|
86
|
+
* `operationType` is the protocol's own two-valued vocabulary rather than the
|
|
87
|
+
* host's operation name, because AF-3 is a rule about the *shape* — an update names
|
|
88
|
+
* the entity it updates and swears to what it replaces — and "create-only" has to
|
|
89
|
+
* be a predicate a policy can test without knowing the host's verbs. The host's own
|
|
90
|
+
* verb travels beside the record, never on it, and the v0.1 wire has no slot for
|
|
91
|
+
* it at all — a card carries the shape, and the host keeps its own vocabulary.
|
|
92
|
+
*/
|
|
93
|
+
export interface Affidavit {
|
|
94
|
+
/**
|
|
95
|
+
* The protocol version this record conforms to (SR-4).
|
|
96
|
+
*
|
|
97
|
+
* **On the record, not only on the wire.** `schemas/0.1.0/affidavit.schema.json`
|
|
98
|
+
* requires `protocolVersion` on an Affidavit, and SR-1 takes the canonical form
|
|
99
|
+
* over the Affidavit *as the schema defines it* — so a runtime model that carried
|
|
100
|
+
* it only on the way out would hash a document the protocol does not have. It
|
|
101
|
+
* did, until this version: `toWire` stamped the version and the canonical form
|
|
102
|
+
* over the model omitted it, so the bytes a Docket row's `canonicalHash` was
|
|
103
|
+
* taken over were not the bytes of the record the same row put on a card. Every
|
|
104
|
+
* canonical byte vector in the conformance suite carries the property; the model
|
|
105
|
+
* now carries it too, and the two paths produce identical bytes for one record.
|
|
106
|
+
*
|
|
107
|
+
* Set from `PROTOCOL_VERSION` when a record is built, kept as it arrived when one
|
|
108
|
+
* is read off the wire (a newer minor is accepted and is not rewritten to this
|
|
109
|
+
* version — re-emitting a record under a tag it did not arrive under would be
|
|
110
|
+
* forging its provenance), and carried unchanged through an amendment.
|
|
111
|
+
*/
|
|
112
|
+
readonly protocolVersion: string;
|
|
113
|
+
/** `create` when nothing exists yet; `update` when an entity is being changed. */
|
|
114
|
+
readonly operationType: "create" | "update";
|
|
115
|
+
/** The kind of domain entity being written, named by the host. */
|
|
116
|
+
readonly entityType: string;
|
|
117
|
+
/** The entity being written; `null` on a create, non-null on an update (AF-3). */
|
|
118
|
+
readonly entityId: string | null;
|
|
119
|
+
/** The sworn fields, in the order the operation proposed them. */
|
|
120
|
+
readonly fields: readonly AffidavitField[];
|
|
121
|
+
/** Minimum confidence over every proposed field, `Empty` counting as `0` (AF-2). */
|
|
122
|
+
readonly aggregateConfidence: number;
|
|
123
|
+
/**
|
|
124
|
+
* Minimum confidence over the non-`Empty` proposed fields, or `null` when there
|
|
125
|
+
* are none (AF-2). `null` rather than `0`: "there is nothing populated to be
|
|
126
|
+
* confident about" is a different statement from "the populated fields are
|
|
127
|
+
* worthless", and a card showing `0` would say the second.
|
|
128
|
+
*/
|
|
129
|
+
readonly populatedConfidence: number | null;
|
|
130
|
+
/** How many proposed fields are tagged `Empty` (AF-2). */
|
|
131
|
+
readonly emptyFieldCount: number;
|
|
132
|
+
/** The conversation turn the proposal was made on, or `null`. */
|
|
133
|
+
readonly conversationTurn: number | null;
|
|
134
|
+
/** When the Affidavit was built, as an ISO 8601 instant. */
|
|
135
|
+
readonly createdAt: string;
|
|
136
|
+
}
|
|
137
|
+
/** The three numbers AF-2 requires a card to show. */
|
|
138
|
+
export interface ConfidenceNumbers {
|
|
139
|
+
/** Minimum over every proposed field, `Empty` counting as `0`. */
|
|
140
|
+
readonly aggregateConfidence: number;
|
|
141
|
+
/** Minimum over the non-`Empty` proposed fields; `null` when there are none. */
|
|
142
|
+
readonly populatedConfidence: number | null;
|
|
143
|
+
/** How many proposed fields are tagged `Empty`. */
|
|
144
|
+
readonly emptyFieldCount: number;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The three confidence numbers over `fields` (AF-2).
|
|
148
|
+
*
|
|
149
|
+
* - `aggregateConfidence` is the **minimum** over every proposed field, with an
|
|
150
|
+
* `Empty` field counting as `0` whatever its tag says — so it is `0` exactly when
|
|
151
|
+
* some proposed field has unknown provenance.
|
|
152
|
+
* - `populatedConfidence` is the minimum over the non-`Empty` fields, and **`null`**
|
|
153
|
+
* when there are none. `null` rather than `0`: "there is nothing populated to be
|
|
154
|
+
* confident about" is a different statement from "the populated fields are
|
|
155
|
+
* worthless", and a card that showed `0` would say the second.
|
|
156
|
+
* - `emptyFieldCount` counts the `Empty` fields.
|
|
157
|
+
*
|
|
158
|
+
* An Affidavit with no fields at all reports `0`, `null`, `0`. It has nothing to
|
|
159
|
+
* swear to, and the substance gate refuses it before it is ever filed (GT-3).
|
|
160
|
+
*
|
|
161
|
+
* Neither the protocol nor this package defines a threshold on any of the three.
|
|
162
|
+
*/
|
|
163
|
+
export declare function computeConfidence(fields: readonly AffidavitField[]): ConfidenceNumbers;
|
|
164
|
+
/**
|
|
165
|
+
* One field as a caller offers it to {@link buildAffidavit}.
|
|
166
|
+
*
|
|
167
|
+
* `provenance` is optional and its absence is the whole of AF-1's first half: a
|
|
168
|
+
* proposed field whose provenance nobody knows is **present** on the Affidavit with
|
|
169
|
+
* an `Empty` tag at confidence `0`, never quietly omitted.
|
|
170
|
+
*
|
|
171
|
+
* `previousValue` is optional in the type and **required at runtime on an update**
|
|
172
|
+
* (AF-3): the key must be there, holding `null` where the field had no stored
|
|
173
|
+
* value. Optional-in-the-type is what lets a create omit it; the runtime check is
|
|
174
|
+
* what stops an update from forgetting it.
|
|
175
|
+
*/
|
|
176
|
+
export interface AffidavitFieldInput {
|
|
177
|
+
/** The field's name. Must be one the operation proposes. */
|
|
178
|
+
readonly name: string;
|
|
179
|
+
/** Rendering hint for a reviewer surface. */
|
|
180
|
+
readonly kind: AffidavitFieldKind;
|
|
181
|
+
/** The proposed value. */
|
|
182
|
+
readonly value: JsonValue;
|
|
183
|
+
/** The stored value being replaced; `null` where there was none. */
|
|
184
|
+
readonly previousValue?: JsonValue | null;
|
|
185
|
+
/** Where the value came from. Absent means unknown, which becomes an `Empty` tag. */
|
|
186
|
+
readonly provenance?: ProvenanceChain;
|
|
187
|
+
/** Whether the target entity requires the field. */
|
|
188
|
+
readonly isMandatory: boolean;
|
|
189
|
+
}
|
|
190
|
+
/** What {@link buildAffidavit} needs that the operation and the fields do not carry. */
|
|
191
|
+
export interface AffidavitMeta {
|
|
192
|
+
/** When the Affidavit is built, as an ISO 8601 instant. Passed in; nothing here reads a clock. */
|
|
193
|
+
readonly createdAt: string;
|
|
194
|
+
/** The conversation turn the proposal was made on. Defaults to `null`. */
|
|
195
|
+
readonly conversationTurn?: number | null;
|
|
196
|
+
/**
|
|
197
|
+
* The protocol version the record conforms to (SR-4). Defaults to
|
|
198
|
+
* `PROTOCOL_VERSION`, which is what a host building a fresh proposal wants.
|
|
199
|
+
*
|
|
200
|
+
* It is here for one caller: {@link fromWire}, which must keep the version a
|
|
201
|
+
* record arrived under rather than restamp it with this package's own.
|
|
202
|
+
*/
|
|
203
|
+
readonly protocolVersion?: string;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Build an Affidavit for `op` from `fields`, enforcing AF-1 and AF-3 and computing
|
|
207
|
+
* the three numbers (AF-2).
|
|
208
|
+
*
|
|
209
|
+
* **AF-1.** `op.fields` is the authority on what is proposed, and the field list
|
|
210
|
+
* must cover it exactly. A field the operation does not propose is a `RangeError`
|
|
211
|
+
* rather than a silently `Empty`-tagged row (that is the "absent, never
|
|
212
|
+
* `Empty`-tagged" half of the rule, made unfakeable); a proposed field with no
|
|
213
|
+
* entry is also a `RangeError`, because the way to say "proposed, provenance
|
|
214
|
+
* unknown" is to pass the field with no `provenance` and get an `Empty` tag.
|
|
215
|
+
*
|
|
216
|
+
* **AF-3.** `op.kind` and `op.entityId` must agree — an update names its entity, a
|
|
217
|
+
* create names none — and on an update every field must carry the `previousValue`
|
|
218
|
+
* key, holding `null` where the entity had no stored value. On a create every
|
|
219
|
+
* `previousValue` is `null`.
|
|
220
|
+
*
|
|
221
|
+
* @throws RangeError on any AF-1 or AF-3 violation, naming the field.
|
|
222
|
+
*/
|
|
223
|
+
export declare function buildAffidavit(op: Operation, fields: readonly AffidavitFieldInput[], meta: AffidavitMeta): Affidavit;
|
|
224
|
+
/** The Affidavit's own properties minus the three numbers — what a caller supplies. */
|
|
225
|
+
type AffidavitCore = Omit<Affidavit, "aggregateConfidence" | "populatedConfidence" | "emptyFieldCount" | "fields">;
|
|
226
|
+
/**
|
|
227
|
+
* Assemble an Affidavit from its parts with the three numbers computed over
|
|
228
|
+
* `fields` (AF-2, and AF-4 when the fields have been amended).
|
|
229
|
+
*
|
|
230
|
+
* Exported because the amendment path needs exactly this: same identity, same
|
|
231
|
+
* order, recomputed numbers.
|
|
232
|
+
*/
|
|
233
|
+
export declare function withConfidence(core: AffidavitCore, fields: readonly AffidavitField[]): Affidavit;
|
|
234
|
+
/**
|
|
235
|
+
* The presentation the card envelope carries beside a sworn record, which the
|
|
236
|
+
* Affidavit itself does not own.
|
|
237
|
+
*
|
|
238
|
+
* All four are the host's presentation of the proposal rather than its sworn
|
|
239
|
+
* substance: the sentences a reviewer should read, whether a person must confirm
|
|
240
|
+
* (which is the policy chain's verdict, not a property of the evidence), the
|
|
241
|
+
* per-field rendering hints a surface builds its inputs from, and the host's own
|
|
242
|
+
* verb for the operation.
|
|
243
|
+
*
|
|
244
|
+
* They live on the envelope and not on the record because the canonical form a
|
|
245
|
+
* host's execution grant binds to is defined over the Affidavit and its accepted
|
|
246
|
+
* amendments and nothing else (SR-1). A closed value set, a regular expression an
|
|
247
|
+
* input is masked with, and a sentence a reviewer should read are none of those
|
|
248
|
+
* things: swearing to them would put a rendering decision inside a hash a grant is
|
|
249
|
+
* checked against, so that restyling an input invalidates a grant minted over
|
|
250
|
+
* evidence that did not change. It would also invite the misreading that the gate
|
|
251
|
+
* enforces them — it does not. A value outside `allowedValues`, or not matching
|
|
252
|
+
* `pattern`, is still recorded; a host that wants such a value refused enforces
|
|
253
|
+
* that in its own policy.
|
|
254
|
+
*/
|
|
255
|
+
export interface WireCarry {
|
|
256
|
+
/** Sentences a reviewer should see beside the record. Empty when there are none. */
|
|
257
|
+
readonly warnings: readonly string[];
|
|
258
|
+
/** Whether a person must confirm this write before it commits. */
|
|
259
|
+
readonly requiresConfirmation: boolean;
|
|
260
|
+
/**
|
|
261
|
+
* How a reviewer surface should render each field's input: one entry per field
|
|
262
|
+
* the host has a hint for, naming a field the Affidavit carries. Empty when the
|
|
263
|
+
* host declared none.
|
|
264
|
+
*/
|
|
265
|
+
readonly presentation: readonly FieldPresentation[];
|
|
266
|
+
/**
|
|
267
|
+
* The host's own verb for the operation, or `null` when it named none.
|
|
268
|
+
*
|
|
269
|
+
* `Affidavit.operationType` is the protocol's two-valued shape, so that a rule
|
|
270
|
+
* about shape stays a predicate a policy can test without knowing any host's
|
|
271
|
+
* vocabulary. The host's word for the same act travels **beside** it, here, where
|
|
272
|
+
* a reviewer surface can show it and no hash is taken over it.
|
|
273
|
+
*/
|
|
274
|
+
readonly hostOperation: string | null;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Lift the {@link WireCarry} off a card envelope, so a round trip can put it back.
|
|
278
|
+
*
|
|
279
|
+
* The two optional slots come back as empty arrays rather than `undefined`: a
|
|
280
|
+
* caller reading them wants something to iterate, and `toWire`'s companion,
|
|
281
|
+
* {@link presentationToWire}, turns an empty one back into an omitted property.
|
|
282
|
+
*/
|
|
283
|
+
export declare function wireCarryOf(card: WireEvidenceCardRequest): WireCarry;
|
|
284
|
+
/**
|
|
285
|
+
* The card envelope's three optional presentation slots as the wire spells them:
|
|
286
|
+
* **absent** when there is nothing to say, never `null`.
|
|
287
|
+
*
|
|
288
|
+
* Nothing swears to any of them, so a producer with nothing to say says nothing —
|
|
289
|
+
* the distinction the schemas draw between a value that is sometimes missing
|
|
290
|
+
* (spelled `null`) and a property that is meaningful only sometimes (spelled by its
|
|
291
|
+
* absence).
|
|
292
|
+
*/
|
|
293
|
+
export declare function presentationToWire(carry: WireCarry): {
|
|
294
|
+
presentation?: readonly FieldPresentation[];
|
|
295
|
+
warnings?: readonly string[];
|
|
296
|
+
hostOperation?: string;
|
|
297
|
+
};
|
|
298
|
+
/** What {@link fromWire} must be told, because a wire Affidavit does not carry it. */
|
|
299
|
+
export interface FromWireStamp {
|
|
300
|
+
/**
|
|
301
|
+
* The instant to stamp on the Affidavit. A tag carries its own `at` on the wire
|
|
302
|
+
* from v0.1, so this is the record's `createdAt` and the fallback for a tag that
|
|
303
|
+
* somehow arrived without one.
|
|
304
|
+
*/
|
|
305
|
+
readonly at: string;
|
|
306
|
+
/** The conversation turn the proposal was made on. Defaults to the wire's own, else `null`. */
|
|
307
|
+
readonly conversationTurn?: number | null;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Read a wire Affidavit into the core model.
|
|
311
|
+
*
|
|
312
|
+
* **A payload from another protocol version is refused, never guessed at.** The
|
|
313
|
+
* `0.0.1-seed` shape the shipped .NET framework still sends is a different
|
|
314
|
+
* document — the host's verb where the shape belongs, one confidence number rather
|
|
315
|
+
* than three, the warnings and the confirmation flag on the record, the
|
|
316
|
+
* presentation on each field — and reading it as though it were this one would
|
|
317
|
+
* produce a record that swore to things nobody said. SR-4 puts the version on the
|
|
318
|
+
* envelope precisely so a consumer can tell: a differing **major** is refused, and
|
|
319
|
+
* so is an older minor whose shape this version does not describe. A newer minor is
|
|
320
|
+
* accepted, because a minor only adds.
|
|
321
|
+
*
|
|
322
|
+
* Two mappings are worth stating. **The operation shape is derived, not trusted:**
|
|
323
|
+
* `entityId === null` is a create and anything else is an update (AF-3), so a
|
|
324
|
+
* record whose `operationType` disagrees with its own `entityId` still lands on the
|
|
325
|
+
* right side of the rule. **A grade is carried, never raised:** a binding read off
|
|
326
|
+
* the wire is recorded as it arrived, and whether a tag may be relied on is PV-4's
|
|
327
|
+
* call, not the reader's.
|
|
328
|
+
*
|
|
329
|
+
* @throws RangeError if the payload names another protocol version, if a field
|
|
330
|
+
* value is not a JSON value, or if the wire shape violates AF-1 or AF-3.
|
|
331
|
+
*/
|
|
332
|
+
export declare function fromWire(wire: WireAffidavit, stamp: FromWireStamp): Affidavit;
|
|
333
|
+
/**
|
|
334
|
+
* Write a core Affidavit back out in the wire shape.
|
|
335
|
+
*
|
|
336
|
+
* Everything on the wire record is the record: the operation's **shape** rather
|
|
337
|
+
* than the host's verb (AF-3), the three confidence numbers (AF-2), the version
|
|
338
|
+
* the envelope conforms to (SR-4), and each field's value, previous value and
|
|
339
|
+
* whole provenance chain. The presentation a surface needs goes on the card
|
|
340
|
+
* envelope instead — see {@link WireCarry}.
|
|
341
|
+
*
|
|
342
|
+
* `aggregateConfidence` is **the computed value** (AF-2). An implementation that
|
|
343
|
+
* wrote back whatever number it was handed would let a mean computed elsewhere
|
|
344
|
+
* travel under a name the rule defines as a minimum.
|
|
345
|
+
*
|
|
346
|
+
* `protocolVersion` is **the record's own** (SR-4), no longer stamped here. It used
|
|
347
|
+
* to be invented on the way out, which made the wire document and the runtime model
|
|
348
|
+
* two different records — the wire one carrying a property the model did not have —
|
|
349
|
+
* and SR-1's canonical form is over the record as the schema defines it, so the two
|
|
350
|
+
* hashed differently. The parameter is kept for a caller re-emitting a record under
|
|
351
|
+
* an explicit version, and defaults to the version the record carries.
|
|
352
|
+
*/
|
|
353
|
+
export declare function toWire(affidavit: Affidavit, protocolVersion?: string): WireAffidavit;
|
|
354
|
+
//# sourceMappingURL=affidavit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"affidavit.d.ts","sourceRoot":"","sources":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