@cruba/crubal 0.1.0 → 0.2.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/README.md +30 -2
- package/dist/bin/crubal.js +70 -4
- package/dist/bin/crubal.js.map +1 -1
- package/dist/src/access.d.ts +126 -0
- package/dist/src/access.js +517 -0
- package/dist/src/access.js.map +1 -0
- package/dist/src/arrival.d.ts +55 -0
- package/dist/src/arrival.js +124 -0
- package/dist/src/arrival.js.map +1 -0
- package/dist/src/bundle.d.ts +66 -0
- package/dist/src/bundle.js +753 -0
- package/dist/src/bundle.js.map +1 -0
- package/dist/src/conditions.d.ts +7 -1
- package/dist/src/conditions.js +52 -11
- package/dist/src/conditions.js.map +1 -1
- package/dist/src/corpus.js +568 -34
- package/dist/src/corpus.js.map +1 -1
- package/dist/src/defs.d.ts +37 -2
- package/dist/src/defs.js +95 -14
- package/dist/src/defs.js.map +1 -1
- package/dist/src/dictionary.d.ts +15 -0
- package/dist/src/dictionary.js +72 -13
- package/dist/src/dictionary.js.map +1 -1
- package/dist/src/exchange.d.ts +202 -11
- package/dist/src/exchange.js +759 -45
- package/dist/src/exchange.js.map +1 -1
- package/dist/src/forms.d.ts +16 -0
- package/dist/src/forms.js +169 -0
- package/dist/src/forms.js.map +1 -0
- package/dist/src/index.d.ts +18 -6
- package/dist/src/index.js +17 -5
- package/dist/src/index.js.map +1 -1
- package/dist/src/lifecycle.d.ts +84 -0
- package/dist/src/lifecycle.js +415 -0
- package/dist/src/lifecycle.js.map +1 -0
- package/dist/src/log.d.ts +78 -0
- package/dist/src/log.js +506 -0
- package/dist/src/log.js.map +1 -0
- package/dist/src/migrate.d.ts +24 -1
- package/dist/src/migrate.js +104 -9
- package/dist/src/migrate.js.map +1 -1
- package/dist/src/model.d.ts +33 -1
- package/dist/src/model.js +158 -2
- package/dist/src/model.js.map +1 -1
- package/dist/src/packages.d.ts +44 -0
- package/dist/src/packages.js +137 -3
- package/dist/src/packages.js.map +1 -1
- package/dist/src/print-text.js +22 -0
- package/dist/src/print-text.js.map +1 -1
- package/dist/src/publish.d.ts +27 -0
- package/dist/src/publish.js +275 -0
- package/dist/src/publish.js.map +1 -0
- package/dist/src/read-text.d.ts +2 -0
- package/dist/src/read-text.js +72 -4
- package/dist/src/read-text.js.map +1 -1
- package/dist/src/records.d.ts +31 -0
- package/dist/src/records.js +72 -0
- package/dist/src/records.js.map +1 -0
- package/dist/src/review.d.ts +22 -0
- package/dist/src/review.js +198 -0
- package/dist/src/review.js.map +1 -0
- package/dist/src/rules.d.ts +34 -2
- package/dist/src/rules.js +147 -22
- package/dist/src/rules.js.map +1 -1
- package/dist/src/schedule.d.ts +24 -0
- package/dist/src/schedule.js +126 -0
- package/dist/src/schedule.js.map +1 -0
- package/dist/src/std-packages.d.ts +9 -0
- package/dist/src/std-packages.js +268 -0
- package/dist/src/std-packages.js.map +1 -0
- package/dist/src/store.d.ts +38 -7
- package/dist/src/store.js +166 -24
- package/dist/src/store.js.map +1 -1
- package/dist/src/tree.d.ts +3 -0
- package/dist/src/tree.js +36 -0
- package/dist/src/tree.js.map +1 -1
- package/dist/src/units-table.d.ts +1 -0
- package/dist/src/units-table.js +200 -0
- package/dist/src/units-table.js.map +1 -0
- package/dist/src/units.d.ts +42 -4
- package/dist/src/units.js +91 -30
- package/dist/src/units.js.map +1 -1
- package/dist/src/views.d.ts +108 -6
- package/dist/src/views.js +389 -64
- package/dist/src/views.js.map +1 -1
- package/package.json +5 -3
package/dist/src/exchange.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import type { Access } from "./access.ts";
|
|
2
|
+
import { type Arrival } from "./arrival.ts";
|
|
3
|
+
import type { Journal } from "./log.ts";
|
|
4
|
+
import type { Views } from "./views.ts";
|
|
1
5
|
import type { Dictionary } from "./defs.ts";
|
|
2
6
|
import type { Json, JsonObject, Record } from "./model.ts";
|
|
7
|
+
import { type RecordSet } from "./records.ts";
|
|
8
|
+
import { Engine, type Rule } from "./rules.ts";
|
|
3
9
|
import { type Contract, type Keys } from "./store.ts";
|
|
4
10
|
export type Role = {
|
|
5
11
|
name: string;
|
|
@@ -10,8 +16,8 @@ export type Role = {
|
|
|
10
16
|
line: number;
|
|
11
17
|
};
|
|
12
18
|
export declare function readRoles(source: string): Role[];
|
|
13
|
-
/** Check contracts against a dictionary (7.10). Throws the first problem. */
|
|
14
|
-
export declare function checkContracts(contracts: Contract[], dict: Dictionary, ownPrefix?: string): void;
|
|
19
|
+
/** Check contracts against a dictionary (7.10). Throws the first problem. `views` lets stream contracts be checked. */
|
|
20
|
+
export declare function checkContracts(contracts: Contract[], dict: Dictionary, ownPrefix?: string, views?: Set<string>): void;
|
|
15
21
|
export type RunResult = {
|
|
16
22
|
[k: string]: Json;
|
|
17
23
|
};
|
|
@@ -19,10 +25,82 @@ export declare class Exchange {
|
|
|
19
25
|
readonly dict: Dictionary;
|
|
20
26
|
readonly contracts: Map<string, Contract>;
|
|
21
27
|
readonly roles: Role[];
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
/** The records, shared with the Access that decides over them (chapter 14). */
|
|
29
|
+
records: RecordSet;
|
|
30
|
+
bindings: Map<string, string>;
|
|
31
|
+
/** Set to make the border consult access: `run` needs the caller's `run` item, gated access suggests. */
|
|
32
|
+
access?: Access;
|
|
33
|
+
/**
|
|
34
|
+
* How an arrival's new record is named (9.2a). A persistent store sets this to mint the next id of the
|
|
35
|
+
* owner (`P-2` after `P-1`), since an Exchange is built per run and its own counter would start again.
|
|
36
|
+
* Without it the memory border's `<L>-NEW<n>` stands.
|
|
37
|
+
*/
|
|
38
|
+
mint?: (level: string) => string;
|
|
39
|
+
/** Set to make every run a transaction (8.5): the border works on the journal's draft and commits each run. */
|
|
40
|
+
journal?: Journal;
|
|
41
|
+
/** Set to let stream contracts (12.6.2) carry the views' projection streams. */
|
|
42
|
+
views?: Views;
|
|
43
|
+
/** Per stream contract, the cursor each view's index has acknowledged, with the version it was for. */
|
|
44
|
+
private cursors;
|
|
45
|
+
/** The rules a run's step 6 applies (7.4): the package's, plus the facet shortcuts the engine adds. */
|
|
46
|
+
readonly engine: Engine;
|
|
47
|
+
/** Idempotency keys acted on (7.5); a store that outlives the instance seeds and keeps them. */
|
|
48
|
+
readonly sent: Set<string>;
|
|
49
|
+
/** Runs so far, which numbers the next run's log; a store continues the count across instances. */
|
|
50
|
+
runs: number;
|
|
51
|
+
/** Records minted by arrivals (9.2a), likewise. */
|
|
52
|
+
minted: number;
|
|
53
|
+
/** The versions a run uses (7.4 step 7, 8.5): the package's, set by a store; the contract's is added per run. */
|
|
54
|
+
versions: JsonObject;
|
|
55
|
+
/** The review queue the border writes to (a dead run, an answer naming no run); the journal's draft list. */
|
|
56
|
+
review: JsonObject[];
|
|
57
|
+
/** Observations this instance made (9.7); a store keeps every one in its state. */
|
|
58
|
+
observations: JsonObject[];
|
|
59
|
+
private observed;
|
|
60
|
+
/** The package's thresholds (11.1): instances to propose a version split, witnesses to confirm. */
|
|
61
|
+
thresholds: {
|
|
62
|
+
confirm?: number;
|
|
63
|
+
split?: number;
|
|
64
|
+
};
|
|
65
|
+
/** Review items already open in the store, for a border that loads them apart from the draft's list. */
|
|
66
|
+
knownReview: JsonObject[];
|
|
67
|
+
/** Mapped-out payloads kept beside the log, by run (docs/design/runs.md): a store keeps them in outtake. */
|
|
68
|
+
readonly outtake: Map<string, JsonObject>;
|
|
69
|
+
/** Runs the store knows beyond this instance's entries (a border over a store seeds them): run → contract and record. */
|
|
70
|
+
readonly runsKnown: Map<string, {
|
|
71
|
+
contract: string;
|
|
72
|
+
record: string;
|
|
73
|
+
}>;
|
|
74
|
+
/** Runs started and not yet acted or failed, by run: what a restarted host asks the adapter about. */
|
|
75
|
+
readonly started: Map<string, {
|
|
76
|
+
contract: string;
|
|
77
|
+
record: string;
|
|
78
|
+
key: string;
|
|
79
|
+
attempts: number;
|
|
80
|
+
cause?: string;
|
|
81
|
+
}>;
|
|
82
|
+
constructor(dict: Dictionary, contracts: Contract[], roles?: Role[], rules?: Rule[]);
|
|
83
|
+
/**
|
|
84
|
+
* Step 6 of a run (7.4): what came in runs through the rules (chapter 6). A `must` the write breaks
|
|
85
|
+
* refuses it and nothing changes; a hold takes the value out of the current values; a fill or derivation
|
|
86
|
+
* lands with `origin: derived` and the rule as its `via`. Returns the record to keep, or the refusal.
|
|
87
|
+
*/
|
|
88
|
+
private applyRules;
|
|
89
|
+
/** Run the ancestors' productions again after a write below them; the ids whose values changed. */
|
|
90
|
+
reproduceAncestors(id: string): string[];
|
|
91
|
+
/** Work on a journal's draft, so every run the border makes is one logged entry (8.5). */
|
|
92
|
+
useJournal(journal: Journal): void;
|
|
93
|
+
/** Log a run's transaction: what it changed on the draft, the run's own state, and any observations (8.5). */
|
|
94
|
+
private commit;
|
|
95
|
+
/** Step 1 of a run (7.4): the menu is the permission (14.6); `who` only narrows. */
|
|
96
|
+
private permitted;
|
|
97
|
+
/** The gated edge a caller's access comes through, if every granting edge is gated (14.7). */
|
|
98
|
+
private gate;
|
|
99
|
+
/**
|
|
100
|
+
* A contract that creates a record for a caller grants their edge on it (14.4): `mode: consume`, the
|
|
101
|
+
* contract's `relation`, under the owner's grant.
|
|
102
|
+
*/
|
|
103
|
+
private grantConsumer;
|
|
26
104
|
put(r: Record): void;
|
|
27
105
|
get(id: string): Record | undefined;
|
|
28
106
|
/** A record's values with everything above it read through (1.7). */
|
|
@@ -30,14 +108,127 @@ export declare class Exchange {
|
|
|
30
108
|
/** The value an address names from a record, with a level prefix reading that level. */
|
|
31
109
|
private read;
|
|
32
110
|
private nextLog;
|
|
33
|
-
/**
|
|
111
|
+
/**
|
|
112
|
+
* A send (or form) contract's run with no act between (the memory border, docs/design/runs.md): prepare,
|
|
113
|
+
* then acted, in two entries. A host puts its adapter between `prepare` and `acted` or `failed`.
|
|
114
|
+
*/
|
|
34
115
|
run(name: string, recordId: string, callerId?: string): RunResult;
|
|
116
|
+
/**
|
|
117
|
+
* Steps 1–3 of a send (7.4): permission, needs, map out; then the run is `started`, its idempotency key
|
|
118
|
+
* and the payload's hash logged, the payload itself kept beside the log. A key already started or acted
|
|
119
|
+
* is never sent again (7.5).
|
|
120
|
+
*/
|
|
121
|
+
prepare(name: string, recordId: string, callerId?: string, cause?: string): RunResult;
|
|
122
|
+
/** The act succeeded: the run is `acted` (docs/design/runs.md). */
|
|
123
|
+
acted(run: string, at?: string): RunResult;
|
|
124
|
+
/** How many attempts a contract allows (7.5 `retry: N every D`): one without it. */
|
|
125
|
+
private attemptsAllowed;
|
|
126
|
+
/**
|
|
127
|
+
* The act failed: a `failed` entry with the attempt; after the last attempt the contract allows, a
|
|
128
|
+
* review item `run:<contract>` opens, grouped by contract across records, and the run stays failed.
|
|
129
|
+
*/
|
|
130
|
+
failed(run: string, reason: string): RunResult;
|
|
131
|
+
/**
|
|
132
|
+
* A decision on a dead run (runs.md): `retry` releases its key and starts a new run from the record as it
|
|
133
|
+
* now is; `drop` closes the item. Either is a review write.
|
|
134
|
+
*/
|
|
135
|
+
decideRun(run: string, decision: "retry" | "drop", callerId?: string): RunResult;
|
|
136
|
+
/** Run the contract that reverses a run (7.5 `undo`): an ordinary send naming its cause. */
|
|
137
|
+
/** The contract and record of a run this instance or its store knows. */
|
|
138
|
+
runOf(run: string): {
|
|
139
|
+
contract: string;
|
|
140
|
+
record: string;
|
|
141
|
+
} | undefined;
|
|
142
|
+
undo(run: string, callerId?: string): RunResult;
|
|
35
143
|
private needsOf;
|
|
36
|
-
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
144
|
+
/**
|
|
145
|
+
* Steps 5–6 for a receive contract: map the answer back, compare with the record, and land it. Under a
|
|
146
|
+
* gated edge (14.7) the values land as suggestions for the edge's reviewer, whatever the contract says.
|
|
147
|
+
*/
|
|
148
|
+
receiveRun(name: string, recordId: string, body: string, callerId?: string, forRun?: string): RunResult;
|
|
149
|
+
/**
|
|
150
|
+
* An arrival through a contract (9.2a): the payload finds or makes its record; a new record made for a
|
|
151
|
+
* caller gets their consumer edge (14.4).
|
|
152
|
+
*/
|
|
153
|
+
arriveRun(name: string, body: string, level: string, callerId?: string, of?: string, within?: string): RunResult;
|
|
154
|
+
/** The arrival type, re-exported for callers that read `arrival`. */
|
|
155
|
+
static arrivalOf(r: RunResult): Arrival | undefined;
|
|
156
|
+
/**
|
|
157
|
+
* A stream contract's run (12.6.2): the entries of each view since the cursor, in order. Pushed (the
|
|
158
|
+
* stored cursor, acknowledged by the index) or pulled (the caller's cursor). A view above `public` goes
|
|
159
|
+
* only to a party holding `run` for the contract.
|
|
160
|
+
*/
|
|
161
|
+
streamRun(name: string, callerId?: string, cursor?: {
|
|
162
|
+
[view: string]: number;
|
|
163
|
+
}): RunResult;
|
|
164
|
+
private lastTick;
|
|
165
|
+
/**
|
|
166
|
+
* A scheduled contract's tick (7.11): the host offers its clock as `now`; every tick due since the last
|
|
167
|
+
* one runs (or only the latest, or none, by `missed`), each run keyed by the contract and the tick so a
|
|
168
|
+
* restarted host never runs a tick twice. A send contract with `for` runs over every record it selects;
|
|
169
|
+
* a stream contract pushes; any other runs once with no record.
|
|
170
|
+
*/
|
|
171
|
+
tick(name: string, now: string, callerId?: string): RunResult;
|
|
172
|
+
/** The index acknowledges what it holds: the store resumes from there (12.6.2). */
|
|
173
|
+
ack(name: string, cursor: {
|
|
174
|
+
[view: string]: number;
|
|
175
|
+
}): RunResult;
|
|
176
|
+
/** The classes a record wears, those of the records above it included (5.5). */
|
|
177
|
+
private wearsOf;
|
|
178
|
+
/**
|
|
179
|
+
* An offer (7.8): the records the contract's `for` selects, with only the facets it gives, each value with
|
|
180
|
+
* its source; the mode and terms ride along. A value the owner took under `reshare: no` never flows on.
|
|
181
|
+
* Who may see it is the host's decision from `to`.
|
|
182
|
+
*/
|
|
183
|
+
offer(name: string, owner: string, only?: string[]): Offer;
|
|
184
|
+
/**
|
|
185
|
+
* Offer and take (7.8): only what the offer gives and the take reads flows, by the offer's mode.
|
|
186
|
+
* `dump` copies once and never updates; `observed` stores a link and no value; `gathered` copies and
|
|
187
|
+
* takes the presenter's updates as intake, never over a value the consumer entered; `controlled` copies
|
|
188
|
+
* under the presenter's terms, which do override, expire and withdraw. The entry names the presenter's
|
|
189
|
+
* entry the values came from (8.5.1).
|
|
190
|
+
*/
|
|
191
|
+
take(takeName: string, offer: string | Offer, recordId: string, presenter: Record): RunResult;
|
|
192
|
+
/** A local offer contract as an offer object, for a take run against a presenter record at hand. */
|
|
193
|
+
private localOffer;
|
|
194
|
+
/** Taken values past their terms' `expires` (7.8) are removed, each record one entry; the ids changed. */
|
|
195
|
+
expire(now: string): string[];
|
|
40
196
|
}
|
|
197
|
+
/** An offer as one owner's host serves it to another (7.8): the border wrapper's content. */
|
|
198
|
+
export type Offer = {
|
|
199
|
+
contract: string;
|
|
200
|
+
owner: string;
|
|
201
|
+
to: string;
|
|
202
|
+
mode: string;
|
|
203
|
+
terms: {
|
|
204
|
+
[term: string]: string;
|
|
205
|
+
};
|
|
206
|
+
gives: string[];
|
|
207
|
+
records: Record[];
|
|
208
|
+
log?: JsonObject[]; /** The package version the records were written under (3.8, 10.1): `<owner>/<name> /<version>`. */
|
|
209
|
+
package?: string;
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* The version gate at a border (10.1): what a receiver does with data written under another version of a
|
|
213
|
+
* package it holds. Newer than ours: hold until we upgrade. Older: restamp through the recipes between.
|
|
214
|
+
* The same, or a package we don't hold, or no version on the wire: take as is.
|
|
215
|
+
*/
|
|
216
|
+
export declare function versionGate(theirs: string | undefined, installed: {
|
|
217
|
+
package: string;
|
|
218
|
+
version: string;
|
|
219
|
+
}[]): {
|
|
220
|
+
kind: "take";
|
|
221
|
+
} | {
|
|
222
|
+
kind: "hold";
|
|
223
|
+
package: string;
|
|
224
|
+
theirs: string;
|
|
225
|
+
ours: string;
|
|
226
|
+
} | {
|
|
227
|
+
kind: "restamp";
|
|
228
|
+
package: string;
|
|
229
|
+
theirs: string;
|
|
230
|
+
ours: string;
|
|
231
|
+
};
|
|
41
232
|
/** Verify a border wrapper from another owner: its log against the owner's key, and its values against the log. */
|
|
42
233
|
export declare function verifyBorder(w: {
|
|
43
234
|
records: Record[];
|