@mark1russell7/coeval 0.14.0 → 0.16.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/build/index.d.ts CHANGED
@@ -302,6 +302,17 @@ interface HostThing {
302
302
  resolve?(keys: readonly Key[]): {
303
303
  readonly thing: Thing;
304
304
  } | undefined;
305
+ /**
306
+ * This optional function answers one step only when the host has its value without new work (SCHED.CLOSURE). A
307
+ * kept read of a closure uses it, because the evaluation did not ask for that read. A schedule gives the value of
308
+ * a node that has its result in the data epoch. A throw gives the error of the step.
309
+ *
310
+ * @param key - The key of the step.
311
+ * @returns What the step reaches, or `undefined` when the host does not know it yet. Then the kept read ends at the thing.
312
+ */
313
+ known?(key: Key): {
314
+ readonly thing: Thing;
315
+ } | undefined;
305
316
  }
306
317
  /** Something that a path can reach: any value of the host, or a host thing. */
307
318
  type Thing = unknown;
@@ -366,6 +377,14 @@ interface WalkInput {
366
377
  * @returns What the step reaches, or `undefined`.
367
378
  */
368
379
  deref(thing: Thing, key: Key): Thing | undefined;
380
+ /**
381
+ * This optional function records one hop inside the walk (HOP.EACH-STEP). The resolution gives it only when it
382
+ * records hops. The hop of the whole walk comes after these hops, as before.
383
+ *
384
+ * @param key - The key that the walk followed.
385
+ * @param thing - The thing that the key reached.
386
+ */
387
+ readonly visit?: (key: Key, thing: Thing) => void;
369
388
  }
370
389
  /** A walker: the code of the verb `step` of a kind of step documents. */
371
390
  type Walker = (input: WalkInput) => WalkResult;
@@ -1501,6 +1520,103 @@ interface Typed {
1501
1520
  readonly expected?: ValueType;
1502
1521
  }
1503
1522
  //#endregion
1523
+ //#region src/facts.d.ts
1524
+ /**
1525
+ * One read of a document: a free reference, with its marks (FACTS.READS). A plan resolves the path of the reference
1526
+ * when it evaluates the reference. The static read covers each path that the plan resolves there (FACTS.SOUND). A
1527
+ * root that a kind declares in `reads` is a read too, with the path of the root alone.
1528
+ */
1529
+ interface StaticRead {
1530
+ /** The root of the path. */
1531
+ readonly root: Root;
1532
+ /** The keys after the root, up to the first step that is not a key. */
1533
+ readonly keys: readonly Key[];
1534
+ /**
1535
+ * `true` when each step after the root is a key. Then the plan resolves this path and no other. A step document,
1536
+ * for example `nearest`, makes it `false`: the plan resolves a path that starts with the keys.
1537
+ */
1538
+ readonly exact: boolean;
1539
+ /** `true` when only a lazy part reaches the reference. An evaluation can then give a value without this read (FACTS.LAZY). */
1540
+ readonly lazy: boolean;
1541
+ /** `true` when the position of the reference declares an address. The read gives what the path reaches, not its value. */
1542
+ readonly address: boolean;
1543
+ /** The path of the reference: its root and its steps. */
1544
+ readonly path: readonly Json[];
1545
+ /** The keys from the root document to the reference document, through the parts. */
1546
+ readonly place: readonly Key[];
1547
+ /** The keys from the root JSON value to the reference document. */
1548
+ readonly at: readonly Key[];
1549
+ }
1550
+ /** The static facts of one document (D24). They depend only on the document and the machine, not on a context. */
1551
+ interface DocFacts {
1552
+ /**
1553
+ * The free references, in the order of the document (FACTS.READS). A reference to a name that a kind binds is not
1554
+ * here. The roots that a kind declares in `reads` are here too, each one at the place of its document.
1555
+ */
1556
+ readonly reads: readonly StaticRead[];
1557
+ /** `"run"` when one kind of the document is on the run side (FACTS.SIDE). */
1558
+ readonly side: Side;
1559
+ /** The kinds of the effects that the contracts declare, as texts with dots, each one time (FACTS.EFFECTS). */
1560
+ readonly effects: readonly string[];
1561
+ /**
1562
+ * `true` when each kind of the document declares `pure`, and the document has no effect and is not volatile. Then
1563
+ * its result depends only on what its reads give (FACTS.PURE).
1564
+ */
1565
+ readonly pure: boolean;
1566
+ /** `true` when the result can change while each read gives the same thing, for example with a clock (FACTS.VOLATILE). */
1567
+ readonly volatile: boolean;
1568
+ /** The number of documents in the document: a hint of the cost of an evaluation. */
1569
+ readonly size: number;
1570
+ }
1571
+ /** The options of `factsOf`. */
1572
+ interface FactsOptions {
1573
+ /** The type of a bare root value. */
1574
+ readonly declaredType?: string;
1575
+ /**
1576
+ * The verb whose evaluators the facts describe, as in `prepare`. The default is `eval`. The contract of a kind
1577
+ * describes the code of `eval` only. For another verb, only the hook `facts` describes the code (FACTS.VERB).
1578
+ */
1579
+ readonly verb?: string;
1580
+ /**
1581
+ * This function tells if a read reaches a volatile value of the host, for example a function that reads a clock.
1582
+ * A read that it marks makes the document volatile (FACTS.VOLATILE).
1583
+ *
1584
+ * @param read - The read.
1585
+ * @returns `true` when the read reaches a volatile value.
1586
+ */
1587
+ readonly volatile?: (read: StaticRead) => boolean;
1588
+ }
1589
+ /**
1590
+ * This function gives the static facts of a document, for a schedule (R4 P2, D24). It walks the document one time,
1591
+ * by the contracts of its kinds:
1592
+ *
1593
+ * - `reads`: each free reference, with the root and the keys of its path. A read under a lazy part has the mark
1594
+ * `lazy`, for example a read in a branch of `if`. A read after a step document has `exact: false`. A kind that
1595
+ * declares `reads` adds a read of each of its roots at each document of the kind.
1596
+ * - `side` and `effects`: from the contract of each kind.
1597
+ * - `pure`: each kind declares `pure`, and the document has no effect and is not volatile.
1598
+ * - `volatile`: a kind, an operation or a step document declares `volatile`, or the host marks a read.
1599
+ *
1600
+ * The hook `facts` of the machine answers for a name that a fallback kind covers, for example an operation. Its
1601
+ * answer wins over the contract of the kind. The contract of a kind does not describe the evaluator of an own
1602
+ * entry. Thus a document with an own entry for another evaluator is not pure, and each of its parts is lazy. The
1603
+ * hook can still answer for that evaluator.
1604
+ *
1605
+ * The option `verb` names the verb whose code the facts describe (FACTS.VERB). A contract describes the code of
1606
+ * `eval`, thus the rule of an own entry applies to each document for another verb. The side and the effects come
1607
+ * from the contracts for each verb.
1608
+ *
1609
+ * A read is one resolution of its path. A reference that the resolution reaches and follows is a part of that read
1610
+ * (DEREF.COLLAPSE), not a separate read. The facts depend only on the document and the machine. Thus a host computes
1611
+ * them again only after an edit of the document or of the machine.
1612
+ *
1613
+ * @param machine - The world, the code and the hook `facts`.
1614
+ * @param doc - The document, as JSON.
1615
+ * @param options - The type of a bare root value, the verb and the volatile reads of the host.
1616
+ * @returns The facts.
1617
+ */
1618
+ export declare function factsOf(machine: Machine, doc: unknown, options?: FactsOptions): DocFacts;
1619
+ //#endregion
1504
1620
  //#region src/evaluate.d.ts
1505
1621
  /**
1506
1622
  * This function makes a context with names and capabilities. The other roots are empty, and an evaluation sets
@@ -1614,8 +1730,8 @@ interface Read {
1614
1730
  */
1615
1731
  readonly free: boolean;
1616
1732
  /**
1617
- * `true` when the kernel adds the read, because a value keeps a root of the context for later (READS.KEPT). Such a
1618
- * read has the whole root as its path.
1733
+ * `true` when the kernel adds the read, because a value keeps the context for later (READS.KEPT). Such a read has
1734
+ * a whole root as its path, or a path that a closure can read (READS.CLOSURE).
1619
1735
  */
1620
1736
  readonly kept?: true;
1621
1737
  /** The hops of the resolution, only when the code asked for them. `verifyReads` then compares each hop too. */
@@ -1700,9 +1816,13 @@ interface Runtime {
1700
1816
  /**
1701
1817
  * This optional function tells the runtime that a value keeps the context for later, for example a closure of
1702
1818
  * `fn`. A later use of the value reads that context, and no evaluation records these reads. Thus the list of reads
1703
- * gets a read of each root of the context (READS.KEPT).
1819
+ * gets a kept read of each path that the value can read (READS.CLOSURE). Without the static reads, the list gets a
1820
+ * read of each root of the context (READS.KEPT).
1821
+ *
1822
+ * @param context - The context that the value keeps.
1823
+ * @param reads - This function gives the static reads of the value, or `undefined` when they are not known.
1704
1824
  */
1705
- keepsContext?(): void;
1825
+ keepsContext?(context?: Context, reads?: () => readonly StaticRead[] | undefined): void;
1706
1826
  }
1707
1827
  /**
1708
1828
  * The options of a drive of parts at the same time.
@@ -2077,6 +2197,17 @@ interface PrepareOptions {
2077
2197
  * evaluates one time, when the plan compiles. Its result is one frozen value for each evaluation (PLAN.FOLD).
2078
2198
  */
2079
2199
  readonly fold?: boolean;
2200
+ /**
2201
+ * The values that the host declares fixed for each evaluation of the plan (PLAN.FIXED, D60). The field `names` gives
2202
+ * a value for each fixed name. A path from a fixed name then resolves one time, when the plan compiles, and a pure
2203
+ * part that reads only fixed names folds. Only a deeply frozen value of plain data fixes its name.
2204
+ *
2205
+ * Each folded part compares the value of its names with one own-key test and `Object.is`. A different value gives
2206
+ * the code without the fold. A plan without folds ignores this option.
2207
+ */
2208
+ readonly fixed?: {
2209
+ readonly names?: Readonly<Record<string, unknown>>;
2210
+ };
2080
2211
  }
2081
2212
  /** A compiled document. It evaluates many times, and it does the work of the ladder one time. */
2082
2213
  interface Plan {
@@ -2463,6 +2594,15 @@ interface AttributeTrace {
2463
2594
  * @returns The record, or `undefined` for a thing that is not a node or an attribute that no demand reached.
2464
2595
  */
2465
2596
  export declare function attributeTrace(node: Thing, attribute: string): AttributeTrace | undefined;
2597
+ /**
2598
+ * This function gives the place of a node of the decorated tree: the keys from the root document to the document of
2599
+ * the node (HOP.PLACE). A view puts each hop of a resolution on its node with it. The node keeps its place already,
2600
+ * thus the function adds no record.
2601
+ *
2602
+ * @param thing - A thing, for example the thing of a hop.
2603
+ * @returns The keys of the place, or `undefined` for a thing that is not a node of the decorated tree.
2604
+ */
2605
+ export declare function placeOf(thing: Thing): readonly Key[] | undefined;
2466
2606
  /** The options of a walker `nearest`. */
2467
2607
  interface NearestOptions {
2468
2608
  /**
@@ -2475,13 +2615,18 @@ interface NearestOptions {
2475
2615
  readonly matches?: (node: Thing, wanted: Json | undefined) => boolean;
2476
2616
  /** The most hops of one walk. The default is 256. */
2477
2617
  readonly maxHops?: number;
2618
+ /**
2619
+ * `true`: the walk records one hop for each node on the way before the node that it reaches (HOP.EACH-STEP). Each
2620
+ * such hop has the followed key as its step. The default is `false`: one hop for the whole walk.
2621
+ */
2622
+ readonly eachStep?: boolean;
2478
2623
  }
2479
2624
  /**
2480
2625
  * This function makes a walker `nearest`. The walker follows a key (the default is `parent`) until the node that it
2481
2626
  * reaches has the wanted type. With `self: true`, the node where the walk starts is the first candidate. A node
2482
- * without that key ends the walk with an error.
2627
+ * without that key ends the walk with an error. With `eachStep`, a resolution with hops gets a hop for each node on the way.
2483
2628
  *
2484
- * @param options - The test of a type and the most hops.
2629
+ * @param options - The test of a type, the most hops and the record of each step.
2485
2630
  * @returns The walker.
2486
2631
  */
2487
2632
  export declare function nearestWalker(options?: NearestOptions): Walker;
@@ -2598,103 +2743,6 @@ interface Construct {
2598
2743
  /** Six constructs that show the range of the context. */
2599
2744
  export declare const CONSTRUCTS: readonly Construct[];
2600
2745
  //#endregion
2601
- //#region src/facts.d.ts
2602
- /**
2603
- * One read of a document: a free reference, with its marks (FACTS.READS). A plan resolves the path of the reference
2604
- * when it evaluates the reference. The static read covers each path that the plan resolves there (FACTS.SOUND). A
2605
- * root that a kind declares in `reads` is a read too, with the path of the root alone.
2606
- */
2607
- interface StaticRead {
2608
- /** The root of the path. */
2609
- readonly root: Root;
2610
- /** The keys after the root, up to the first step that is not a key. */
2611
- readonly keys: readonly Key[];
2612
- /**
2613
- * `true` when each step after the root is a key. Then the plan resolves this path and no other. A step document,
2614
- * for example `nearest`, makes it `false`: the plan resolves a path that starts with the keys.
2615
- */
2616
- readonly exact: boolean;
2617
- /** `true` when only a lazy part reaches the reference. An evaluation can then give a value without this read (FACTS.LAZY). */
2618
- readonly lazy: boolean;
2619
- /** `true` when the position of the reference declares an address. The read gives what the path reaches, not its value. */
2620
- readonly address: boolean;
2621
- /** The path of the reference: its root and its steps. */
2622
- readonly path: readonly Json[];
2623
- /** The keys from the root document to the reference document, through the parts. */
2624
- readonly place: readonly Key[];
2625
- /** The keys from the root JSON value to the reference document. */
2626
- readonly at: readonly Key[];
2627
- }
2628
- /** The static facts of one document (D24). They depend only on the document and the machine, not on a context. */
2629
- interface DocFacts {
2630
- /**
2631
- * The free references, in the order of the document (FACTS.READS). A reference to a name that a kind binds is not
2632
- * here. The roots that a kind declares in `reads` are here too, each one at the place of its document.
2633
- */
2634
- readonly reads: readonly StaticRead[];
2635
- /** `"run"` when one kind of the document is on the run side (FACTS.SIDE). */
2636
- readonly side: Side;
2637
- /** The kinds of the effects that the contracts declare, as texts with dots, each one time (FACTS.EFFECTS). */
2638
- readonly effects: readonly string[];
2639
- /**
2640
- * `true` when each kind of the document declares `pure`, and the document has no effect and is not volatile. Then
2641
- * its result depends only on what its reads give (FACTS.PURE).
2642
- */
2643
- readonly pure: boolean;
2644
- /** `true` when the result can change while each read gives the same thing, for example with a clock (FACTS.VOLATILE). */
2645
- readonly volatile: boolean;
2646
- /** The number of documents in the document: a hint of the cost of an evaluation. */
2647
- readonly size: number;
2648
- }
2649
- /** The options of `factsOf`. */
2650
- interface FactsOptions {
2651
- /** The type of a bare root value. */
2652
- readonly declaredType?: string;
2653
- /**
2654
- * The verb whose evaluators the facts describe, as in `prepare`. The default is `eval`. The contract of a kind
2655
- * describes the code of `eval` only. For another verb, only the hook `facts` describes the code (FACTS.VERB).
2656
- */
2657
- readonly verb?: string;
2658
- /**
2659
- * This function tells if a read reaches a volatile value of the host, for example a function that reads a clock.
2660
- * A read that it marks makes the document volatile (FACTS.VOLATILE).
2661
- *
2662
- * @param read - The read.
2663
- * @returns `true` when the read reaches a volatile value.
2664
- */
2665
- readonly volatile?: (read: StaticRead) => boolean;
2666
- }
2667
- /**
2668
- * This function gives the static facts of a document, for a schedule (R4 P2, D24). It walks the document one time,
2669
- * by the contracts of its kinds:
2670
- *
2671
- * - `reads`: each free reference, with the root and the keys of its path. A read under a lazy part has the mark
2672
- * `lazy`, for example a read in a branch of `if`. A read after a step document has `exact: false`. A kind that
2673
- * declares `reads` adds a read of each of its roots at each document of the kind.
2674
- * - `side` and `effects`: from the contract of each kind.
2675
- * - `pure`: each kind declares `pure`, and the document has no effect and is not volatile.
2676
- * - `volatile`: a kind, an operation or a step document declares `volatile`, or the host marks a read.
2677
- *
2678
- * The hook `facts` of the machine answers for a name that a fallback kind covers, for example an operation. Its
2679
- * answer wins over the contract of the kind. The contract of a kind does not describe the evaluator of an own
2680
- * entry. Thus a document with an own entry for another evaluator is not pure, and each of its parts is lazy. The
2681
- * hook can still answer for that evaluator.
2682
- *
2683
- * The option `verb` names the verb whose code the facts describe (FACTS.VERB). A contract describes the code of
2684
- * `eval`, thus the rule of an own entry applies to each document for another verb. The side and the effects come
2685
- * from the contracts for each verb.
2686
- *
2687
- * A read is one resolution of its path. A reference that the resolution reaches and follows is a part of that read
2688
- * (DEREF.COLLAPSE), not a separate read. The facts depend only on the document and the machine. Thus a host computes
2689
- * them again only after an edit of the document or of the machine.
2690
- *
2691
- * @param machine - The world, the code and the hook `facts`.
2692
- * @param doc - The document, as JSON.
2693
- * @param options - The type of a bare root value, the verb and the volatile reads of the host.
2694
- * @returns The facts.
2695
- */
2696
- export declare function factsOf(machine: Machine, doc: unknown, options?: FactsOptions): DocFacts;
2697
- //#endregion
2698
2746
  //#region src/effects.d.ts
2699
2747
  /** The options of `effectsOf`. */
2700
2748
  interface EffectsOptions {
@@ -3116,10 +3164,20 @@ interface ReferenceOptions {
3116
3164
  */
3117
3165
  readonly verb?: string;
3118
3166
  }
3167
+ /** The options of a run of the reference: the options of an evaluation, with the host and a signal (REF.RUN). */
3168
+ interface ReferenceRunOptions extends ReferenceOptions {
3169
+ /**
3170
+ * The host code that does each effect of a runner. A promise from it makes the run wait. Without it, an effect gives
3171
+ * its payload. A journal on the function sets the order of the waits of each `all` (RUN.REPLAY).
3172
+ */
3173
+ readonly perform?: Perform;
3174
+ /** A signal of the host. When it aborts, the run stops with `#ABORT` (RUN.ABORT). */
3175
+ readonly signal?: StopSignal;
3176
+ }
3119
3177
  /**
3120
3178
  * This function evaluates a document by the rules, without a compilation. It is the reference of the plans: a plan,
3121
- * a traced plan and the second tier of a language must give its results. It covers evaluations, not runs: an effect
3122
- * gives the answer of the mock or its payload, and a part that waits gives `#CALC!`.
3179
+ * a traced plan and the second tier of a language must give its results. In an evaluation, an effect gives the answer
3180
+ * of the mock or its payload, and a part that waits gives `#CALC!`. `referenceRun` reads the rules of a run.
3123
3181
  *
3124
3182
  * The verb of the options goes up the ladder at each document, as in `prepare`. Each verb has the same rules: the
3125
3183
  * ladder, the contract of the kind and the sealed parts (VERB.AGREE).
@@ -3131,6 +3189,22 @@ interface ReferenceOptions {
3131
3189
  * @returns The result.
3132
3190
  */
3133
3191
  export declare function reference(machine: Machine, doc: unknown, context?: Context, options?: ReferenceOptions): Result;
3192
+ /**
3193
+ * This function starts a run of a document by the rules, without a compilation (REF.RUN). The host does each effect of a runner,
3194
+ * and a step waits when the host waits (RUN.SEQ). `all` settles the waits in the order of the host, or in the order
3195
+ * of the journal of a replay (RUN.REPLAY). An effect of an evaluator gives `#CALC!` (RUN.NEEDS-RUNNER). A signal that
3196
+ * aborts stops the run with `#ABORT` (RUN.ABORT).
3197
+ *
3198
+ * The part of the run before the first wait happens at once, in the call (RUN.EAGER). `agreeRun` compares the run of
3199
+ * a plan with this run.
3200
+ *
3201
+ * @param machine - The world, the evaluators and the runners.
3202
+ * @param doc - The document.
3203
+ * @param context - The names and the capabilities at the root.
3204
+ * @param options - The options of `reference`, the host and a signal.
3205
+ * @returns The result, when the run ends.
3206
+ */
3207
+ export declare function referenceRun(machine: Machine, doc: unknown, context?: Context, options?: ReferenceRunOptions): Promise<Result>;
3134
3208
  /**
3135
3209
  * The definitions of the reference for the evaluators of the standard machine that need their own reading. The
3136
3210
  * reference uses them for the standard evaluators, also without the option `definitions`. It holds `tree.node`.
@@ -3155,9 +3229,11 @@ export declare function formulaDefinitions(profile?: FormulaProfile): Definition
3155
3229
  * - `again`: a second evaluation of the same plan.
3156
3230
  * - `folds`: a second plan with the other choice of folds (PLAN.FOLD). It has no folds when the plan has them, and
3157
3231
  * it has folds when the option `observe` stops the folds of the plan.
3232
+ * - `fixed`: a plan that declares each name of plain data fixed (PLAN.FIXED). It evaluates with a frozen copy of
3233
+ * each such name, and then with the context of `agree`. `agreeRun` does not have this tier.
3158
3234
  * - `other`: the second tier of a language, from the option `other`.
3159
3235
  */
3160
- type Tier = "reference" | "traced" | "again" | "folds" | "other";
3236
+ type Tier = "reference" | "traced" | "again" | "folds" | "fixed" | "other";
3161
3237
  /** What a second tier gives: its result, and its effects when it records them. */
3162
3238
  interface TierResult {
3163
3239
  readonly result: Result;
@@ -3183,8 +3259,8 @@ interface AgreeOptions {
3183
3259
  /** The definitional code of the compiled evaluators of the machine, for the reference. */
3184
3260
  readonly definitions?: Definitions;
3185
3261
  /**
3186
- * The tiers to compare with the plan. The default is the reference, the traced evaluation, a second evaluation and
3187
- * the plan with the other choice of folds.
3262
+ * The tiers to compare with the plan. The default is the reference, the traced evaluation, a second evaluation, the
3263
+ * plan with the other choice of folds and the plan with fixed names.
3188
3264
  */
3189
3265
  readonly tiers?: readonly Exclude<Tier, "other">[];
3190
3266
  /**
@@ -3268,6 +3344,29 @@ export declare function sameValue(a: unknown, b: unknown, equal?: (a: unknown, b
3268
3344
  * @returns The result of the plan, or the first tier that disagrees and the reason.
3269
3345
  */
3270
3346
  export declare function agree(machine: Machine, doc: unknown, context?: Context, options?: AgreeOptions): Agreement;
3347
+ /** The options of `agreeRun`: the options of `agree` without the second tier of a language. */
3348
+ interface AgreeRunOptions extends Omit<AgreeOptions, "other" | "perform"> {
3349
+ /**
3350
+ * The host of the run of the plan (RUN.AGREES). A recorder wraps it, and each other tier replays the log of that run.
3351
+ * Thus the host does each effect one time. Without it, an effect gives its payload.
3352
+ */
3353
+ readonly perform?: Perform;
3354
+ }
3355
+ /**
3356
+ * This function compares the run of a document in a plan with its run in other tiers (RUN.AGREES). First the plan
3357
+ * starts the run with a recorder around the host. Then each tier replays the log of that run. These tiers are the
3358
+ * reference run, the traced run, a second run of the plan and the plan with the other choice of folds.
3359
+ *
3360
+ * The rules of `agree` compare the results and the effects, with their addresses and outcomes. A tier must also
3361
+ * settle the waits of each `all` in the order of the plan, thus a replay keeps the order of the waits.
3362
+ *
3363
+ * @param machine - The world, the evaluators and the runners.
3364
+ * @param doc - The document.
3365
+ * @param context - The names and the capabilities at the root.
3366
+ * @param options - The tiers, the definitions for the reference, the rules of the comparison and the host.
3367
+ * @returns The result of the plan, or the first tier that disagrees and the reason.
3368
+ */
3369
+ export declare function agreeRun(machine: Machine, doc: unknown, context?: Context, options?: AgreeRunOptions): Promise<Agreement>;
3271
3370
  //#endregion
3272
3371
  //#region src/conform.d.ts
3273
3372
  /**
@@ -3712,6 +3811,269 @@ export declare function edgesOf(facts: DocFacts): readonly NodeEdge[];
3712
3811
  */
3713
3812
  export declare function schedule(machine: Machine, options?: ScheduleOptions): Schedule;
3714
3813
  //#endregion
3814
+ //#region src/generate.d.ts
3815
+ /** A source of random numbers with a seed. The same seed gives the same numbers. */
3816
+ interface Random {
3817
+ /** This function gives a number from 0 up to 1, without 1. */
3818
+ next(): number;
3819
+ /** This function gives a whole number from 0 up to `below`, without `below`. */
3820
+ int(below: number): number;
3821
+ /** This function gives `true` with the chance `p`. */
3822
+ chance(p: number): boolean;
3823
+ /** This function gives one item of a list that is not empty. */
3824
+ pick<T>(items: readonly T[]): T;
3825
+ }
3826
+ /**
3827
+ * This function makes a source of random numbers with a seed (the algorithm mulberry32). It needs no package.
3828
+ *
3829
+ * @param seed - The seed: a whole number.
3830
+ * @returns The source.
3831
+ */
3832
+ export declare function random(seed: number): Random;
3833
+ /** The options of `generate`. */
3834
+ interface GenerateOptions {
3835
+ /** The seed. The same seed and the same options give the same document. */
3836
+ readonly seed: number;
3837
+ /** The types that a document can have. The default is `typesOf(world)`. A namespace with a fallback needs its keys here. */
3838
+ readonly types?: readonly (readonly Key[])[];
3839
+ /** The type of a bare root value. */
3840
+ readonly declaredType?: string;
3841
+ /** The names that the host binds at the root. */
3842
+ readonly names?: readonly string[];
3843
+ /** The deepest nesting of documents. The default is 4. */
3844
+ readonly maxDepth?: number;
3845
+ /** The most documents in one document. The default is 24. */
3846
+ readonly maxSize?: number;
3847
+ /** The chance of a malformed choice at each document. The default is 0.05. */
3848
+ readonly malformed?: number;
3849
+ /**
3850
+ * This function gives the data of a document of a type without parts, for example a number for the kind `number`.
3851
+ *
3852
+ * @param type - The keys of the type.
3853
+ * @param random - The source of random numbers.
3854
+ * @returns The data, or `undefined` for a random JSON value.
3855
+ */
3856
+ readonly data?: (type: readonly Key[], random: Random) => Json | undefined;
3857
+ /**
3858
+ * This function gives the types to prefer for a part, for example a function for the field `fn` of `call`.
3859
+ *
3860
+ * @param type - The keys of the type of the parent.
3861
+ * @param path - The path of the part in the value of the parent.
3862
+ * @returns The types, or `undefined` for no preference.
3863
+ */
3864
+ readonly hints?: (type: readonly Key[], path: readonly Key[]) => readonly (readonly Key[])[] | undefined;
3865
+ /** The evaluator names for own entries. The default is none. */
3866
+ readonly own?: readonly string[];
3867
+ /** The keys for the steps of a path after its root and its name. */
3868
+ readonly keys?: readonly Key[];
3869
+ /** The roots that a path can start at. The default is each root. */
3870
+ readonly roots?: readonly Root[];
3871
+ /** The most steps of a path after its root and its name. The default is 2. */
3872
+ readonly steps?: number;
3873
+ }
3874
+ /**
3875
+ * This function lists the types of a world: each kind and each alias, also in a namespace. A namespace with a
3876
+ * fallback gives no types, because each key names a kind.
3877
+ *
3878
+ * @param world - The world.
3879
+ * @returns The keys of each type.
3880
+ */
3881
+ export declare function typesOf(world: World): readonly (readonly Key[])[];
3882
+ /**
3883
+ * This function builds a random document for a world from the contracts of its kinds. It reads the shapes of the
3884
+ * parts, the declared types, the permitted kinds and the names that the scope rules bind. Some choices are malformed
3885
+ * on purpose, for example an unknown kind or an unknown name under a namespace with a fallback. Other examples are a
3886
+ * value without its shape, a bare value without a type and a name that nothing binds. The depth and the size have
3887
+ * limits.
3888
+ *
3889
+ * @param world - The world.
3890
+ * @param options - The seed, the types, the limits and the data of the leaves.
3891
+ * @returns The document, as JSON.
3892
+ */
3893
+ export declare function generate(world: World, options: GenerateOptions): unknown;
3894
+ //#endregion
3895
+ //#region src/meaning.d.ts
3896
+ /**
3897
+ * The smallest interface of the engine of a host that `agreeSchedule` examines (SCHED.AGREES). The demand schedule of
3898
+ * `schedule` has this interface.
3899
+ */
3900
+ interface ScheduleEngine {
3901
+ /**
3902
+ * This function adds a node, or gives a node a new document. The harness also gives the same document object again:
3903
+ * a change of the structure without an edit.
3904
+ *
3905
+ * @param id - The name of the node.
3906
+ * @param doc - The document of the node. It does not change in place.
3907
+ */
3908
+ set(id: string, doc: unknown): void;
3909
+ /**
3910
+ * This function removes a node. A later read of the node by another node gives the error of a missing step.
3911
+ *
3912
+ * @param id - The name of the node.
3913
+ */
3914
+ remove(id: string): unknown;
3915
+ /**
3916
+ * This function gives the engine the new context of the host. The values of a context do not change in place. The
3917
+ * same context object again is a change of data that changes no value.
3918
+ *
3919
+ * @param context - The context of the host, without the root `world`.
3920
+ */
3921
+ changeData(context: Context): void;
3922
+ /**
3923
+ * This function gives the engine a new machine. The harness gives no new machine to an engine without this function.
3924
+ *
3925
+ * @param machine - The new machine.
3926
+ */
3927
+ changeMachine?(machine: Machine): void;
3928
+ /**
3929
+ * This function demands a node and gives its answer.
3930
+ *
3931
+ * @param id - The name of the node. The engine has the node.
3932
+ * @returns The result of the node.
3933
+ */
3934
+ read(id: string): Result;
3935
+ }
3936
+ /** What a new engine gets beside its machine: the context of the host, and the type of a bare root value. */
3937
+ interface ScheduleEngineStart {
3938
+ /** The first context of the host, without the root `world`. */
3939
+ readonly context: Context;
3940
+ /** The type of a bare root value, when the options of the harness name one. */
3941
+ readonly declaredType?: string;
3942
+ }
3943
+ /**
3944
+ * This function makes a new engine with no nodes. The harness makes one engine for each run. The function `schedule`
3945
+ * has this form.
3946
+ */
3947
+ type ScheduleEngineFactory = (machine: Machine, start: ScheduleEngineStart) => ScheduleEngine;
3948
+ /**
3949
+ * The options of `agreeSchedule`. The defaults fit `STD_MACHINE`. A host with another machine also gives `generate`,
3950
+ * `value` and `wire`, and it sets `runs` to `false` when its world has no kind `log`.
3951
+ */
3952
+ interface AgreeScheduleOptions {
3953
+ /** The machines. The first machine starts each run, and the command of a new machine takes the next one. The default is `STD_MACHINE` and a copy. */
3954
+ readonly machines?: readonly Machine[];
3955
+ /** The type of a bare root value, for each engine, each plan and each fact. */
3956
+ readonly declaredType?: string;
3957
+ /** The options of the document generator. Each generated path from `names` to a node changes into a path from `world`. */
3958
+ readonly generate?: Omit<GenerateOptions, "seed" | "names">;
3959
+ /**
3960
+ * This function gives a small value document.
3961
+ *
3962
+ * @param rng - The source of random numbers.
3963
+ * @returns The document.
3964
+ */
3965
+ readonly value?: (rng: Random) => unknown;
3966
+ /**
3967
+ * This function gives a document that reads one or two nodes, for dense graphs with many cycles.
3968
+ *
3969
+ * @param rng - The source of random numbers.
3970
+ * @param node - This function gives a reference to a random node.
3971
+ * @returns The document.
3972
+ */
3973
+ readonly wire?: (rng: Random, node: () => Json) => unknown;
3974
+ /** The share of the nodes that `wire` gives. The default is 0.2. */
3975
+ readonly wired?: number;
3976
+ /** `true`: one generated document in ten goes into the kind `log`, thus the node is on the run side. The default is `true`. */
3977
+ readonly runs?: boolean;
3978
+ /** The names of the nodes. The default is five names. */
3979
+ readonly nodes?: readonly string[];
3980
+ /** The names that the context of the host binds at the root `names`. The default is `a`, `b`, `x` and `n`. */
3981
+ readonly names?: readonly string[];
3982
+ /** The values that a change of data gives a name of the host. The default has equal values, host values and a `Held` error. */
3983
+ readonly values?: readonly unknown[];
3984
+ /** The contexts of the host at the start of the runs, one after the other. */
3985
+ readonly contexts?: readonly Context[];
3986
+ /** The number of runs. The default is 100. */
3987
+ readonly count?: number;
3988
+ /** The number of commands in one run. The default is 30. */
3989
+ readonly steps?: number;
3990
+ /** The seed of the first run, and one more for each later run. The default is 9000011. */
3991
+ readonly seed?: number;
3992
+ /**
3993
+ * This function compares two values that the rules of `sameResult` do not know. It answers first. Without an answer,
3994
+ * two closures of `fn` are the same when they have the same parameters.
3995
+ *
3996
+ * @param a - The value of the engine, or of the first evaluation from scratch.
3997
+ * @param b - The value from scratch.
3998
+ * @returns `true` or `false`, or `undefined` for the other rules.
3999
+ */
4000
+ readonly equal?: (a: unknown, b: unknown) => boolean | undefined;
4001
+ }
4002
+ /** What the harness reached: the commands, the reads, and the kinds of answers that it compared. */
4003
+ interface ScheduleAgreementCounts {
4004
+ /** The reads of a node. */
4005
+ readonly reads: number;
4006
+ /** The reads with one answer from scratch, which the harness compared. */
4007
+ readonly compared: number;
4008
+ /** The reads whose answer from scratch is new at each evaluation. The harness does not compare them. */
4009
+ readonly unrepeatable: number;
4010
+ /** The compared answers that are a value. */
4011
+ readonly values: number;
4012
+ /** The compared answers that are the `#CYCLE!` of the node. */
4013
+ readonly cycles: number;
4014
+ /** The compared answers that are the `#REF!` of a node on the run side. */
4015
+ readonly runs: number;
4016
+ /** The changes of data with new names of the host. */
4017
+ readonly data: number;
4018
+ /** The changes of data that change no value. */
4019
+ readonly empty: number;
4020
+ /** The new documents of a node. */
4021
+ readonly edits: number;
4022
+ /** The new nodes. */
4023
+ readonly additions: number;
4024
+ /** The removed nodes. */
4025
+ readonly removes: number;
4026
+ /** The changes of the structure with the same document object. */
4027
+ readonly same: number;
4028
+ /** The new machines. */
4029
+ readonly machines: number;
4030
+ }
4031
+ /** The outcome of `agreeSchedule`: what the harness reached, or the first disagreement. */
4032
+ type ScheduleAgreement = {
4033
+ readonly ok: true;
4034
+ readonly counts: ScheduleAgreementCounts;
4035
+ } | {
4036
+ readonly ok: false;
4037
+ /** The seed of the run. */
4038
+ readonly seed: number;
4039
+ /** The index of the command in the run. */
4040
+ readonly step: number;
4041
+ /** The node of the read. */
4042
+ readonly node: string;
4043
+ /** The answer of the engine. */
4044
+ readonly engine: Result;
4045
+ /** The answer of the evaluation from scratch. */
4046
+ readonly scratch: Result;
4047
+ /** The documents of the nodes at the read. */
4048
+ readonly docs: ReadonlyMap<string, unknown>;
4049
+ /** The context of the host at the read. */
4050
+ readonly context: Context;
4051
+ /** The machine at the read. */
4052
+ readonly machine: Machine;
4053
+ /** One sentence that tells the difference. */
4054
+ readonly reason: string;
4055
+ /** What the harness reached up to the read. */
4056
+ readonly counts: ScheduleAgreementCounts;
4057
+ };
4058
+ /**
4059
+ * This function examines an engine of a host against an evaluation from scratch (SCHED.AGREES, R4 P4, D58). Each run
4060
+ * makes a new engine and a random graph of named nodes from the document generator. Then it gives random commands:
4061
+ * edits, new nodes, removed nodes, the same document again, new machines and changes of data.
4062
+ *
4063
+ * - Each read command evaluates the whole graph from scratch two times, with the meaning of D31.
4064
+ * - It then demands each node in a random order, or one node, and compares each answer with `sameResult`.
4065
+ * - A read whose answer from scratch differs between the two evaluations is not compared.
4066
+ * - Two errors agree when they have the same code, reason and place. Thus an engine gives the `#CYCLE!` and the
4067
+ * `#REF!` of D31.
4068
+ *
4069
+ * The same seed and the same options give the same commands, thus a disagreement occurs again.
4070
+ *
4071
+ * @param engine - This function makes a new engine for each run, for example `schedule`.
4072
+ * @param options - The machines, the generator, the contexts, the number of runs and the rule for host values.
4073
+ * @returns What the harness reached, or the first read whose answer differs from the answer from scratch.
4074
+ */
4075
+ export declare function agreeSchedule(engine: ScheduleEngineFactory, options?: AgreeScheduleOptions): ScheduleAgreement;
4076
+ //#endregion
3715
4077
  //#region src/graph.d.ts
3716
4078
  /** One edge of a graph of nodes: a read of a node by another node. `NodeEdge` of a schedule is such an edge. */
3717
4079
  interface GraphEdge<Id> {
@@ -3879,87 +4241,6 @@ export declare function recorder(perform?: Perform): Recorder;
3879
4241
  */
3880
4242
  export declare function replayer(log: ReplayLog, options?: ReplayOptions): Perform;
3881
4243
  //#endregion
3882
- //#region src/generate.d.ts
3883
- /** A source of random numbers with a seed. The same seed gives the same numbers. */
3884
- interface Random {
3885
- /** This function gives a number from 0 up to 1, without 1. */
3886
- next(): number;
3887
- /** This function gives a whole number from 0 up to `below`, without `below`. */
3888
- int(below: number): number;
3889
- /** This function gives `true` with the chance `p`. */
3890
- chance(p: number): boolean;
3891
- /** This function gives one item of a list that is not empty. */
3892
- pick<T>(items: readonly T[]): T;
3893
- }
3894
- /**
3895
- * This function makes a source of random numbers with a seed (the algorithm mulberry32). It needs no package.
3896
- *
3897
- * @param seed - The seed: a whole number.
3898
- * @returns The source.
3899
- */
3900
- export declare function random(seed: number): Random;
3901
- /** The options of `generate`. */
3902
- interface GenerateOptions {
3903
- /** The seed. The same seed and the same options give the same document. */
3904
- readonly seed: number;
3905
- /** The types that a document can have. The default is `typesOf(world)`. A namespace with a fallback needs its keys here. */
3906
- readonly types?: readonly (readonly Key[])[];
3907
- /** The type of a bare root value. */
3908
- readonly declaredType?: string;
3909
- /** The names that the host binds at the root. */
3910
- readonly names?: readonly string[];
3911
- /** The deepest nesting of documents. The default is 4. */
3912
- readonly maxDepth?: number;
3913
- /** The most documents in one document. The default is 24. */
3914
- readonly maxSize?: number;
3915
- /** The chance of a malformed choice at each document. The default is 0.05. */
3916
- readonly malformed?: number;
3917
- /**
3918
- * This function gives the data of a document of a type without parts, for example a number for the kind `number`.
3919
- *
3920
- * @param type - The keys of the type.
3921
- * @param random - The source of random numbers.
3922
- * @returns The data, or `undefined` for a random JSON value.
3923
- */
3924
- readonly data?: (type: readonly Key[], random: Random) => Json | undefined;
3925
- /**
3926
- * This function gives the types to prefer for a part, for example a function for the field `fn` of `call`.
3927
- *
3928
- * @param type - The keys of the type of the parent.
3929
- * @param path - The path of the part in the value of the parent.
3930
- * @returns The types, or `undefined` for no preference.
3931
- */
3932
- readonly hints?: (type: readonly Key[], path: readonly Key[]) => readonly (readonly Key[])[] | undefined;
3933
- /** The evaluator names for own entries. The default is none. */
3934
- readonly own?: readonly string[];
3935
- /** The keys for the steps of a path after its root and its name. */
3936
- readonly keys?: readonly Key[];
3937
- /** The roots that a path can start at. The default is each root. */
3938
- readonly roots?: readonly Root[];
3939
- /** The most steps of a path after its root and its name. The default is 2. */
3940
- readonly steps?: number;
3941
- }
3942
- /**
3943
- * This function lists the types of a world: each kind and each alias, also in a namespace. A namespace with a
3944
- * fallback gives no types, because each key names a kind.
3945
- *
3946
- * @param world - The world.
3947
- * @returns The keys of each type.
3948
- */
3949
- export declare function typesOf(world: World): readonly (readonly Key[])[];
3950
- /**
3951
- * This function builds a random document for a world from the contracts of its kinds. It reads the shapes of the
3952
- * parts, the declared types, the permitted kinds and the names that the scope rules bind. Some choices are malformed
3953
- * on purpose, for example an unknown kind or an unknown name under a namespace with a fallback. Other examples are a
3954
- * value without its shape, a bare value without a type and a name that nothing binds. The depth and the size have
3955
- * limits.
3956
- *
3957
- * @param world - The world.
3958
- * @param options - The seed, the types, the limits and the data of the leaves.
3959
- * @returns The document, as JSON.
3960
- */
3961
- export declare function generate(world: World, options: GenerateOptions): unknown;
3962
- //#endregion
3963
4244
  //#region src/providers.d.ts
3964
4245
  /** The type that a provider reads, and the problems of the reading. Each problem tells what the type does not test. */
3965
4246
  interface TypeReading {
@@ -4008,5 +4289,5 @@ interface SampleOptions {
4008
4289
  */
4009
4290
  export declare function typeFromSamples(values: readonly unknown[], options?: SampleOptions): ValueType;
4010
4291
  //#endregion
4011
- export type { AgreeOptions, Agreement, Alias, AllOptions, Answer, AskOptions, AttributeDeclaration, AttributeRung, AttributeTrace, Cap, CapsRule, CheckOptions, Classification, Closure, Code, CompileInput, CompiledEvaluator, CompiledPart, CompiledRunner, ConformOptions, ConformProbe, Construct, Context, Part as ContextPart, Definitions, DerefCode, DocFacts, DocParts, DocVisit, Domain, DomainCodec, DomainExtension, Durable, DurableCounts, DurableOptions, Edge, Effect, EffectsOptions, Envelope, Epochs, ErrorCode, EvalError, EvalFn, EvalInput, EvalOptions, EvaluateOptions, Evaluator, ExtFn, FactsOptions, Failed, Finding, FormulaProfile, GenerateOptions, Give, GraphCycle, GraphEdge, GraphNode, GraphOptions, Header, Hop, HopBy, HostThing, Issue, Journal, Json, JsonRecord, KernelCode, Key, Kind, KindFacts, KindSource, LazyOp, LazyRule, Lookup, Machine, MachinePart, MergeConflict, MergePath, NamesSource, Namespace, Navigator, NearestOptions, NodeEdge, NodeGraph, NodeInfo, NodeRunOptions, Obligation, OpFn, OrderProblem, Outcome, ParseResult, Part$1 as Part, PartInfo, Shape as PartShape, PartSlot, PartType, PartsSpec, Perform, Plan, PlanRunOptions, PrepareOptions, Random, Read, ReadsCheck, Recorder, RefUse, ReferenceOptions, ReplayEntry, ReplayLog, ReplayOptions, ReplaySettle, Resolution, ResolveCode, ResolveOptions, Result, Root, RootTypes, Run, RunCode, RunFn, RunInput, RunOptions, RunPart, Rung, Runner, Runtime, SampleOptions, Schedule, ScheduleCounts, ScheduleOptions, ScopeRule, Shape$1 as Shape, Side, Signature, Split, StaticRead, Step, StepSpec, Steps, StopSignal, Stored, SyntaxAssoc, SyntaxCalls, SyntaxFixity, SyntaxForm, SyntaxIssue, SyntaxLiterals, SyntaxOperator, SyntaxProfile, SyntaxRefPattern, SyntaxRefs, Thing, Tier, TierInput, TierResult, TraceNode, TreeContract, TypeInput, TypeIssue, TypeProblem, TypeReading, TypeRef, TypeRule, Typed, Typing, Use, ValueType, VerbEffects, VerifyOptions, WalkInput, WalkOptions, WalkProblem, WalkResult, Walker, World, WorldEntry, WorldIssue, WorldPart };
4292
+ export type { AgreeOptions, AgreeRunOptions, AgreeScheduleOptions, Agreement, Alias, AllOptions, Answer, AskOptions, AttributeDeclaration, AttributeRung, AttributeTrace, Cap, CapsRule, CheckOptions, Classification, Closure, Code, CompileInput, CompiledEvaluator, CompiledPart, CompiledRunner, ConformOptions, ConformProbe, Construct, Context, Part as ContextPart, Definitions, DerefCode, DocFacts, DocParts, DocVisit, Domain, DomainCodec, DomainExtension, Durable, DurableCounts, DurableOptions, Edge, Effect, EffectsOptions, Envelope, Epochs, ErrorCode, EvalError, EvalFn, EvalInput, EvalOptions, EvaluateOptions, Evaluator, ExtFn, FactsOptions, Failed, Finding, FormulaProfile, GenerateOptions, Give, GraphCycle, GraphEdge, GraphNode, GraphOptions, Header, Hop, HopBy, HostThing, Issue, Journal, Json, JsonRecord, KernelCode, Key, Kind, KindFacts, KindSource, LazyOp, LazyRule, Lookup, Machine, MachinePart, MergeConflict, MergePath, NamesSource, Namespace, Navigator, NearestOptions, NodeEdge, NodeGraph, NodeInfo, NodeRunOptions, Obligation, OpFn, OrderProblem, Outcome, ParseResult, Part$1 as Part, PartInfo, Shape as PartShape, PartSlot, PartType, PartsSpec, Perform, Plan, PlanRunOptions, PrepareOptions, Random, Read, ReadsCheck, Recorder, RefUse, ReferenceOptions, ReferenceRunOptions, ReplayEntry, ReplayLog, ReplayOptions, ReplaySettle, Resolution, ResolveCode, ResolveOptions, Result, Root, RootTypes, Run, RunCode, RunFn, RunInput, RunOptions, RunPart, Rung, Runner, Runtime, SampleOptions, Schedule, ScheduleAgreement, ScheduleAgreementCounts, ScheduleCounts, ScheduleEngine, ScheduleEngineFactory, ScheduleEngineStart, ScheduleOptions, ScopeRule, Shape$1 as Shape, Side, Signature, Split, StaticRead, Step, StepSpec, Steps, StopSignal, Stored, SyntaxAssoc, SyntaxCalls, SyntaxFixity, SyntaxForm, SyntaxIssue, SyntaxLiterals, SyntaxOperator, SyntaxProfile, SyntaxRefPattern, SyntaxRefs, Thing, Tier, TierInput, TierResult, TraceNode, TreeContract, TypeInput, TypeIssue, TypeProblem, TypeReading, TypeRef, TypeRule, Typed, Typing, Use, ValueType, VerbEffects, VerifyOptions, WalkInput, WalkOptions, WalkProblem, WalkResult, Walker, World, WorldEntry, WorldIssue, WorldPart };
4012
4293
  //# sourceMappingURL=index.d.ts.map