@earnestjs/model 0.0.0-stage → 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/LICENSE +674 -0
- package/LICENSE.LESSER +165 -0
- package/README.md +298 -2
- package/dist/breadth.d.ts +125 -0
- package/dist/breadth.js +150 -0
- package/dist/declarations.d.ts +201 -0
- package/dist/declarations.js +482 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +7 -0
- package/dist/m.d.ts +10 -0
- package/dist/m.js +3 -0
- package/dist/model.d.ts +297 -0
- package/dist/model.js +262 -0
- package/dist/replay.d.ts +41 -0
- package/dist/replay.js +99 -0
- package/dist/runs.d.ts +41 -0
- package/dist/runs.js +325 -0
- package/dist/search.d.ts +130 -0
- package/dist/search.js +484 -0
- package/dist/values.d.ts +296 -0
- package/dist/values.js +695 -0
- package/package.json +51 -4
package/dist/values.d.ts
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A value as `earnest verify --json` prints it: a set, a sequence and a queue are arrays, a map
|
|
3
|
+
* is an array of `[key, value]` pairs, a record is an object, a lock is `true` when held or its
|
|
4
|
+
* holder, a timer and a request are the name of their stage, and a retry is its attempt count.
|
|
5
|
+
*/
|
|
6
|
+
export type Json = null | boolean | number | string | readonly Json[] | {
|
|
7
|
+
readonly [name: string]: Json;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Compares two texts by code point, the order of Rust's `str` and of the UTF-8 bytes, which is
|
|
11
|
+
* the order every set, map and record is kept in. JavaScript's own `<` compares UTF-16 code
|
|
12
|
+
* units, and so puts a character past U+FFFF before one from U+E000 to U+FFFF.
|
|
13
|
+
*/
|
|
14
|
+
export declare const compareText: (left: string, right: string) => number;
|
|
15
|
+
/** An object read by field name whose values are not yet known to fit any declaration. */
|
|
16
|
+
export type Row = Readonly<Record<string, unknown>>;
|
|
17
|
+
/**
|
|
18
|
+
* The base of every collection, lock, timer, request and retry value. Two values with the same
|
|
19
|
+
* content are the same object, so `===` compares them by content.
|
|
20
|
+
*/
|
|
21
|
+
export declare abstract class ModelValue {
|
|
22
|
+
/** Text that is equal for two values exactly when their content is equal. */
|
|
23
|
+
abstract readonly key: string;
|
|
24
|
+
/** The value in the form `earnest verify --json` prints. */
|
|
25
|
+
abstract toJSON(): Json;
|
|
26
|
+
}
|
|
27
|
+
/** Tells a record, which is a plain object, from every other value a model can hold. */
|
|
28
|
+
export declare const isRecord: (value: unknown) => value is Row;
|
|
29
|
+
/**
|
|
30
|
+
* Text that is equal for two model values exactly when their content is equal. A record's key
|
|
31
|
+
* does not depend on the order its fields were written in. Throws for anything a model can't
|
|
32
|
+
* hold, such as `undefined` or a function.
|
|
33
|
+
*/
|
|
34
|
+
export declare const keyOf: (value: unknown) => string;
|
|
35
|
+
/** Turns a model value into the form `earnest verify --json` prints. */
|
|
36
|
+
export declare const toJson: (value: unknown) => Json;
|
|
37
|
+
/**
|
|
38
|
+
* Makes a record, and every record inside it, read-only, and gives the same value back. Other
|
|
39
|
+
* values are already immutable.
|
|
40
|
+
*/
|
|
41
|
+
export declare const frozen: <T>(value: T) => T;
|
|
42
|
+
/** Tells a JSON array from every other JSON value. */
|
|
43
|
+
export declare const isJsonList: (json: Json) => json is readonly Json[];
|
|
44
|
+
/** Tells a JSON object from every other JSON value. */
|
|
45
|
+
export declare const isJsonObject: (json: Json) => json is {
|
|
46
|
+
readonly [name: string]: Json;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* The order set members and map keys are kept and printed in: `null`, then booleans, numbers,
|
|
50
|
+
* text in code point order (see `compareText`), records by their field names in that order, and
|
|
51
|
+
* collections item by item. Returns a negative number, zero or a
|
|
52
|
+
* positive number, as a sort comparator does.
|
|
53
|
+
*/
|
|
54
|
+
export declare const compareJson: (left: Json, right: Json) => number;
|
|
55
|
+
/**
|
|
56
|
+
* An immutable set. Members are compared by content and kept in the order of `compareJson`,
|
|
57
|
+
* whatever order they were added in. `has`, `isSubset`, `size`, `isEmpty`, `every` and `some`
|
|
58
|
+
* read the set; `add`, `delete`, `union`, `intersect`, `subtract` and `filter` give back another
|
|
59
|
+
* set and leave this one as it was.
|
|
60
|
+
*/
|
|
61
|
+
export declare class SetValue<T> extends ModelValue implements Iterable<T> {
|
|
62
|
+
#private;
|
|
63
|
+
readonly key: string;
|
|
64
|
+
private constructor();
|
|
65
|
+
/** The set of the given items; an item given twice is in the set once. */
|
|
66
|
+
static of<T>(items: Iterable<T>): SetValue<T>;
|
|
67
|
+
get size(): number;
|
|
68
|
+
get isEmpty(): boolean;
|
|
69
|
+
has(item: T): boolean;
|
|
70
|
+
add(item: T): SetValue<T>;
|
|
71
|
+
delete(item: T): SetValue<T>;
|
|
72
|
+
union(other: SetValue<T>): SetValue<T>;
|
|
73
|
+
intersect(other: SetValue<T>): SetValue<T>;
|
|
74
|
+
subtract(other: SetValue<T>): SetValue<T>;
|
|
75
|
+
isSubset(other: SetValue<T>): boolean;
|
|
76
|
+
every(test: (item: T) => boolean): boolean;
|
|
77
|
+
some(test: (item: T) => boolean): boolean;
|
|
78
|
+
filter(test: (item: T) => boolean): SetValue<T>;
|
|
79
|
+
[Symbol.iterator](): Iterator<T>;
|
|
80
|
+
toJSON(): Json;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* An immutable map. Keys are compared by content and kept in the order of `compareJson`.
|
|
84
|
+
* `get` gives `null` for a key the map does not have. `set` and `delete` give back another map
|
|
85
|
+
* and leave this one as it was. Iterating gives `[key, value]` pairs.
|
|
86
|
+
*/
|
|
87
|
+
export declare class MapValue<K, V> extends ModelValue implements Iterable<readonly [K, V]> {
|
|
88
|
+
#private;
|
|
89
|
+
readonly key: string;
|
|
90
|
+
private constructor();
|
|
91
|
+
/** The map of the given pairs; when a key is given twice, the later pair wins. */
|
|
92
|
+
static of<K, V>(entries: Iterable<readonly [K, V]>): MapValue<K, V>;
|
|
93
|
+
get size(): number;
|
|
94
|
+
get isEmpty(): boolean;
|
|
95
|
+
get keys(): SetValue<K>;
|
|
96
|
+
has(key: K): boolean;
|
|
97
|
+
get(key: K): V | null;
|
|
98
|
+
set(key: K, value: V): MapValue<K, V>;
|
|
99
|
+
delete(key: K): MapValue<K, V>;
|
|
100
|
+
[Symbol.iterator](): Iterator<readonly [K, V]>;
|
|
101
|
+
toJSON(): Json;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* An immutable sequence. `get`, `first` and `last` give `null` where there is no item. `push`
|
|
105
|
+
* adds at the end, `shift` drops the first item and `pop` drops the last; each gives back
|
|
106
|
+
* another sequence, and `shift` and `pop` on an empty sequence give the empty sequence. Pushing
|
|
107
|
+
* past the declared `max` is not an error here: the checker reports the state as out of range.
|
|
108
|
+
*/
|
|
109
|
+
export declare class SeqValue<T> extends ModelValue implements Iterable<T> {
|
|
110
|
+
#private;
|
|
111
|
+
readonly key: string;
|
|
112
|
+
private constructor();
|
|
113
|
+
/** The sequence of the given items, in the order given. */
|
|
114
|
+
static of<T>(items: Iterable<T>): SeqValue<T>;
|
|
115
|
+
get size(): number;
|
|
116
|
+
get isEmpty(): boolean;
|
|
117
|
+
get first(): T | null;
|
|
118
|
+
get last(): T | null;
|
|
119
|
+
get(position: number): T | null;
|
|
120
|
+
push(item: T): SeqValue<T>;
|
|
121
|
+
shift(): SeqValue<T>;
|
|
122
|
+
pop(): SeqValue<T>;
|
|
123
|
+
includes(item: T): boolean;
|
|
124
|
+
every(test: (item: T) => boolean): boolean;
|
|
125
|
+
some(test: (item: T) => boolean): boolean;
|
|
126
|
+
filter(test: (item: T) => boolean): SeqValue<T>;
|
|
127
|
+
[Symbol.iterator](): Iterator<T>;
|
|
128
|
+
toJSON(): Json;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* An immutable first-in, first-out queue with a capacity. `head` is the item `receive` would
|
|
132
|
+
* drop, or `null`. `send`, `receive` and `clear` give back another queue. Sending to a full
|
|
133
|
+
* queue is not an error here: the checker reports the state as out of range.
|
|
134
|
+
*/
|
|
135
|
+
export declare class QueueValue<T> extends ModelValue implements Iterable<T> {
|
|
136
|
+
#private;
|
|
137
|
+
readonly key: string;
|
|
138
|
+
private constructor();
|
|
139
|
+
/** The queue of the given capacity holding the given items, the first of them at the head. */
|
|
140
|
+
static of<T>(capacity: number, items: Iterable<T>): QueueValue<T>;
|
|
141
|
+
get size(): number;
|
|
142
|
+
get isEmpty(): boolean;
|
|
143
|
+
get capacity(): number;
|
|
144
|
+
get isFull(): boolean;
|
|
145
|
+
get head(): T | null;
|
|
146
|
+
send(item: T): QueueValue<T>;
|
|
147
|
+
receive(): QueueValue<T>;
|
|
148
|
+
includes(item: T): boolean;
|
|
149
|
+
clear(): QueueValue<T>;
|
|
150
|
+
every(test: (item: T) => boolean): boolean;
|
|
151
|
+
some(test: (item: T) => boolean): boolean;
|
|
152
|
+
[Symbol.iterator](): Iterator<T>;
|
|
153
|
+
toJSON(): Json;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* A lock with no owner: free or held. `acquire` and `release` give back another lock; acquiring
|
|
157
|
+
* a held lock gives a held lock, so guard with `isFree` in the action's `when`.
|
|
158
|
+
*/
|
|
159
|
+
export declare class LockValue extends ModelValue {
|
|
160
|
+
#private;
|
|
161
|
+
readonly key: string;
|
|
162
|
+
private constructor();
|
|
163
|
+
/** The held lock when `isHeld` is true, the free lock otherwise. */
|
|
164
|
+
static of(isHeld: boolean): LockValue;
|
|
165
|
+
get isFree(): boolean;
|
|
166
|
+
get isHeld(): boolean;
|
|
167
|
+
acquire(): LockValue;
|
|
168
|
+
release(): LockValue;
|
|
169
|
+
toJSON(): Json;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* A lock that remembers who holds it. `holder` is `null` when the lock is free. `acquire(owner)`
|
|
173
|
+
* and `release` give back another lock; acquiring a held lock hands it to the new owner, so
|
|
174
|
+
* guard with `isFree` in the action's `when`.
|
|
175
|
+
*/
|
|
176
|
+
export declare class OwnedLockValue<Owner> extends ModelValue {
|
|
177
|
+
#private;
|
|
178
|
+
readonly key: string;
|
|
179
|
+
private constructor();
|
|
180
|
+
/** The lock held by `holder`, or the free lock for `null`. */
|
|
181
|
+
static of<Owner>(holder: Owner | null): OwnedLockValue<Owner>;
|
|
182
|
+
get isFree(): boolean;
|
|
183
|
+
get isHeld(): boolean;
|
|
184
|
+
get holder(): Owner | null;
|
|
185
|
+
isHeldBy(owner: Owner): boolean;
|
|
186
|
+
acquire(owner: Owner): OwnedLockValue<Owner>;
|
|
187
|
+
release(): OwnedLockValue<Owner>;
|
|
188
|
+
toJSON(): Json;
|
|
189
|
+
}
|
|
190
|
+
/** The stages of a timer, in the order a declaration lists them. */
|
|
191
|
+
export declare const TIMER_STAGES: readonly TimerStage[];
|
|
192
|
+
/** The name of one stage of a timer. */
|
|
193
|
+
export type TimerStage = "idle" | "running" | "fired";
|
|
194
|
+
/**
|
|
195
|
+
* A timer: idle, running or fired. `start`, `fire`, `cancel` and `reset` give back another timer
|
|
196
|
+
* from any stage; `cancel` and `reset` both give the idle timer.
|
|
197
|
+
*/
|
|
198
|
+
export declare class TimerValue extends ModelValue {
|
|
199
|
+
#private;
|
|
200
|
+
readonly key: string;
|
|
201
|
+
private constructor();
|
|
202
|
+
/** The timer at the given stage. */
|
|
203
|
+
static at(stage: TimerStage): TimerValue;
|
|
204
|
+
get isIdle(): boolean;
|
|
205
|
+
get isRunning(): boolean;
|
|
206
|
+
get hasFired(): boolean;
|
|
207
|
+
start(): TimerValue;
|
|
208
|
+
fire(): TimerValue;
|
|
209
|
+
cancel(): TimerValue;
|
|
210
|
+
reset(): TimerValue;
|
|
211
|
+
toJSON(): Json;
|
|
212
|
+
}
|
|
213
|
+
/** The stages of an async request, in the order a declaration lists them. */
|
|
214
|
+
export declare const REQUEST_STAGES: readonly RequestStage[];
|
|
215
|
+
/** The name of one stage of an async request. */
|
|
216
|
+
export type RequestStage = "idle" | "pending" | "succeeded" | "failed";
|
|
217
|
+
/**
|
|
218
|
+
* An async request: idle, pending, succeeded or failed. `isSettled` is true once it succeeded or
|
|
219
|
+
* failed. `send`, `succeed`, `fail` and `reset` give back another request from any stage.
|
|
220
|
+
*/
|
|
221
|
+
export declare class RequestValue extends ModelValue {
|
|
222
|
+
#private;
|
|
223
|
+
readonly key: string;
|
|
224
|
+
private constructor();
|
|
225
|
+
/** The request at the given stage. */
|
|
226
|
+
static at(stage: RequestStage): RequestValue;
|
|
227
|
+
get isIdle(): boolean;
|
|
228
|
+
get isPending(): boolean;
|
|
229
|
+
get hasSucceeded(): boolean;
|
|
230
|
+
get hasFailed(): boolean;
|
|
231
|
+
get isSettled(): boolean;
|
|
232
|
+
send(): RequestValue;
|
|
233
|
+
succeed(): RequestValue;
|
|
234
|
+
fail(): RequestValue;
|
|
235
|
+
reset(): RequestValue;
|
|
236
|
+
toJSON(): Json;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* A count of attempts with a most. `canRetry` is true below the most and `isExhausted` at it.
|
|
240
|
+
* `again` counts one more attempt and `reset` goes back to zero; both give back another counter.
|
|
241
|
+
* Counting past the most is not an error here: the checker reports the state as out of range.
|
|
242
|
+
*/
|
|
243
|
+
export declare class RetryValue extends ModelValue {
|
|
244
|
+
#private;
|
|
245
|
+
readonly key: string;
|
|
246
|
+
private constructor();
|
|
247
|
+
/** The counter that allows `max` attempts and has counted `attempts` of them. */
|
|
248
|
+
static of(max: number, attempts: number): RetryValue;
|
|
249
|
+
get max(): number;
|
|
250
|
+
get attempts(): number;
|
|
251
|
+
get canRetry(): boolean;
|
|
252
|
+
get isExhausted(): boolean;
|
|
253
|
+
again(): RetryValue;
|
|
254
|
+
reset(): RetryValue;
|
|
255
|
+
toJSON(): Json;
|
|
256
|
+
}
|
|
257
|
+
/** Writes a set value: `m.setOf("a", "b")`. Members keep their literal types. */
|
|
258
|
+
export declare const setOf: <const T>(...items: readonly T[]) => SetValue<T>;
|
|
259
|
+
/** Writes a sequence value: `m.seqOf("a", "b")`. It is also how a queue's `.initial` is written. */
|
|
260
|
+
export declare const seqOf: <const T>(...items: readonly T[]) => SeqValue<T>;
|
|
261
|
+
/** Writes a map value from `[key, value]` pairs: `m.mapOf(["a", 1], ["b", 2])`. */
|
|
262
|
+
export declare const mapOf: <const K, const V>(...entries: readonly (readonly [K, V])[]) => MapValue<K, V>;
|
|
263
|
+
/** Thrown by `rem` for a divisor of zero; `explore` and `replay` report it as `earnest verify` does. */
|
|
264
|
+
export declare class RemainderFault extends Error {
|
|
265
|
+
constructor();
|
|
266
|
+
}
|
|
267
|
+
/** Thrown by `div` for a divisor of zero; `explore` and `replay` report it as `earnest verify` does. */
|
|
268
|
+
export declare class DivisionFault extends Error {
|
|
269
|
+
constructor();
|
|
270
|
+
}
|
|
271
|
+
/** Thrown by `some` for a `null`; `explore` and `replay` report it as a read of a null value. */
|
|
272
|
+
export declare class NullFault extends Error {
|
|
273
|
+
constructor();
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Writes the value inside an optional: `m.some(s.chosen).qty`. A `null` is a fault, as in
|
|
277
|
+
* `earnest verify`, because JavaScript would go on with `null` as a number. Use it where
|
|
278
|
+
* TypeScript would want a postfix `!`, which a model file may not have.
|
|
279
|
+
*/
|
|
280
|
+
export declare const some: <T>(value: T | null) => T;
|
|
281
|
+
/**
|
|
282
|
+
* Writes the remainder of `a` divided by `b`, JavaScript's `a % b`: `m.rem(7, 3)` is 1,
|
|
283
|
+
* `m.rem(-7, 2)` is -1 and `m.rem(7, -2)` is 1, with the sign of `a` as Rust's `%` has it. A
|
|
284
|
+
* zero result is 0, never -0. A `b` of zero is a fault, as in `earnest verify`, where JavaScript
|
|
285
|
+
* would go on with `NaN`, and so is a `NaN`. Use it where JavaScript would use `%`, which a model
|
|
286
|
+
* file may not.
|
|
287
|
+
*/
|
|
288
|
+
export declare const rem: (a: number, b: number) => number;
|
|
289
|
+
/**
|
|
290
|
+
* Writes the whole number of times `b` goes into `a`, `Math.trunc(a / b)`: `m.div(7, 2)` is 3,
|
|
291
|
+
* `m.div(-7, 2)` is -3 and `m.div(-7, -2)` is 3, as Rust's `/` on integers. It is exact for
|
|
292
|
+
* every safe integer, and a zero result is 0, never -0. A `b` of zero is a fault, as in
|
|
293
|
+
* `earnest verify` and as Rust panics, and so is a `NaN`. Use it where JavaScript would use
|
|
294
|
+
* `/`, which a model file may not, since it gives a fraction.
|
|
295
|
+
*/
|
|
296
|
+
export declare const div: (a: number, b: number) => number;
|