@mark1russell7/coeval 0.6.3 → 0.7.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
@@ -162,7 +162,7 @@ export declare function docEquals(a: unknown, b: unknown): boolean;
162
162
  //#endregion
163
163
  //#region src/errors.d.ts
164
164
  /** The codes that the kernel gives. */
165
- type KernelCode = "#KIND?" | "#NOEVAL" | "#PART?" | "#NAME?" | "#REF!" | "#N/A" | "#CYCLE!" | "#STEP?" | "#VALUE!" | "#NUM!" | "#ARGS" | "#CAP!" | "#CALC!" | "#DEPTH!" | "#ABORT" | "#REPLAY!";
165
+ type KernelCode = "#KIND?" | "#NOEVAL" | "#PART?" | "#NAME?" | "#REF!" | "#N/A" | "#CYCLE!" | "#STEP?" | "#VALUE!" | "#NUM!" | "#ARGS" | "#CAP!" | "#CALC!" | "#DEPTH!" | "#ABORT" | "#REPLAY!" | "#TYPE!";
166
166
  /** The code of an error value. A language can add its own codes. Each code starts with `#`. */
167
167
  type ErrorCode = KernelCode | `#${string}`;
168
168
  /**
@@ -414,8 +414,10 @@ interface ResolveOptions {
414
414
  }
415
415
  /**
416
416
  * This function answers one step of a path on a thing, through the ladder of the verb `deref`. A host thing
417
- * answers for itself (own). A document asks its own entry, then its kind. The default goes into the value: an own
418
- * field of an object, or an item of a list.
417
+ * answers for itself (own). A document asks its own entry, then its kind, then the default of the world
418
+ * (VERB.LADDER). A rung answers only with a `deref` that the navigator has. When no rung answers, the step goes into
419
+ * the value: an own field of an object, or an item of a list. A value without a type is data, thus the step goes
420
+ * into it at once.
419
421
  *
420
422
  * @param nav - The world and the code of the evaluators.
421
423
  * @param thing - The thing that the path reached.
@@ -455,9 +457,9 @@ export declare function context(parts?: Partial<Context>): Context;
455
457
  * This function resolves a path from a context, and records each hop.
456
458
  *
457
459
  * The first step is a root of the context. Each later step is a key or a step document. A key goes up the ladder
458
- * of the verb `deref` on the thing that the path reached. A step document is evaluated by the walker of its kind,
459
- * with the thing that the path reached. After each hop, a reference document is followed until the path reaches
460
- * something else (collapse), except in a plain navigation.
460
+ * of the verb `deref` on the thing that the path reached. A step document is evaluated by the walker that the
461
+ * ladder of the verb `step` gives, with the thing that the path reached. After each hop, a reference document is
462
+ * followed until the path reaches something else (collapse), except in a plain navigation.
461
463
  *
462
464
  * The codes of a failure:
463
465
  *
@@ -482,6 +484,162 @@ export declare function resolve(nav: Navigator, ctx: Context, path: readonly unk
482
484
  */
483
485
  export declare function valueOfThing(thing: Thing): unknown;
484
486
  //#endregion
487
+ //#region src/types.d.ts
488
+ /**
489
+ * A value type: a set of values that a result can have, as a JSON term.
490
+ *
491
+ * - A text names a base type: `unknown`, `never`, a domain of the kernel (`null`, `bool`, `number`, `text`), or a
492
+ * domain of a language.
493
+ * - `list`: a list whose items have the type.
494
+ * - `record`: a plain record with the named fields. `optional` names the fields that can be absent. A `closed`
495
+ * record has no other fields. The other fields of an open record can hold each value.
496
+ * - `fn`: a function with the types of its parameters, and the type of its result (`to`).
497
+ * - `union`: a value of one of the types. An empty union holds no value.
498
+ * - `one`: one of the JSON values of the list.
499
+ *
500
+ * A term that is not in this list reads as `unknown` (TYPE.UNKNOWN). Thus a later version can add a term.
501
+ */
502
+ type ValueType = string | {
503
+ readonly list: ValueType;
504
+ } | {
505
+ readonly record: Readonly<Record<string, ValueType>>;
506
+ readonly optional?: readonly string[];
507
+ readonly closed?: boolean;
508
+ } | {
509
+ readonly fn: readonly ValueType[];
510
+ readonly to: ValueType;
511
+ } | {
512
+ readonly union: readonly ValueType[];
513
+ } | {
514
+ readonly one: readonly Json[];
515
+ };
516
+ /**
517
+ * A value domain: a base type of a language, with its membership test. A machine holds its domains by their names
518
+ * (`Machine.domains`). A value is a member of a domain only when the test of the domain and the test of each parent
519
+ * accept it (TYPE.MEMBER).
520
+ *
521
+ * A path does not follow a member of a domain as a reference (DEREF.COLLAPSE). Thus the test `is` must refuse each
522
+ * reference document.
523
+ */
524
+ interface Domain {
525
+ /**
526
+ * This function tells if a value is a member of the domain. It must be pure. A test that throws gives `false`.
527
+ *
528
+ * @param value - The value.
529
+ * @returns `true` for a member.
530
+ */
531
+ readonly is: (value: unknown) => boolean;
532
+ /** The names of the parents: the base types that hold each member of the domain. A base type fits each parent. */
533
+ readonly under?: readonly string[];
534
+ /** One sentence that tells what the domain holds. */
535
+ readonly summary?: string;
536
+ /**
537
+ * The value type of each step into a member, by its key, for example the field `x` of a point (TYPE.STEPS). The
538
+ * check of a path reads the steps of the domain first, then the steps of each parent. The language keeps them true:
539
+ * a step with the key into a member reaches a member of the type. A key without a type gives `unknown`.
540
+ */
541
+ readonly steps?: Readonly<Record<string, ValueType>>;
542
+ }
543
+ /** A problem of a value type: the keys from the root of the term to the problem, and the reason. */
544
+ interface TypeIssue {
545
+ readonly at: readonly Key[];
546
+ readonly reason: string;
547
+ }
548
+ /**
549
+ * The domains of the kernel. `unknown` and `never` are not domains: they are the top and the bottom of the types.
550
+ * A machine that does not name one of these domains gets it from this table.
551
+ */
552
+ export declare const STD_DOMAINS: Readonly<Record<string, Domain>>;
553
+ /**
554
+ * This function tells if a value is a member of a value type (TYPE.MEMBER). It is the membership test that a cast
555
+ * at run time uses.
556
+ *
557
+ * - Each value is a member of `unknown`, and no value is a member of `never`.
558
+ * - A value is a member of a domain when the test `is` of the domain and of each parent accepts it.
559
+ * - A list, a record, a union and `one` test their values at each depth.
560
+ * - A function type tests only that the value is a function. Its parameters need a test at each call.
561
+ *
562
+ * The function does not throw. A term that is not a value type, or a base type without a domain, holds each value.
563
+ *
564
+ * @param value - The value.
565
+ * @param type - The value type.
566
+ * @param domains - The domains of the machine. A domain of the kernel that the table does not name comes from `STD_DOMAINS`.
567
+ * @returns `true` when the value is a member of the type.
568
+ */
569
+ export declare function member(value: unknown, type: ValueType, domains?: Readonly<Record<string, Domain>>): boolean;
570
+ /**
571
+ * This function tells if each value of the type `found` can be where the type `expected` must be (TYPE.FITS). Each
572
+ * check of a type uses it.
573
+ *
574
+ * - `unknown` fits each type, and each type fits `unknown` (TYPE.UNKNOWN). This is the gradual top.
575
+ * - `never` fits each type. Only `never`, an empty union and an empty `one` fit `never`.
576
+ * - A union fits when each of its types fits. A type fits a union when it fits one of its types.
577
+ * - `one` fits when each of its values is a member of `expected`.
578
+ * - A base type fits itself and each parent of its domain, through each level (TYPE.DOMAIN).
579
+ * - A list fits a list when its items fit.
580
+ * - A record fits a record with fewer fields. A field that `expected` needs is not optional in `found`, and each field
581
+ * fits. Only a closed record fits a closed record. An open record without an optional field fits only when that
582
+ * field is `unknown`.
583
+ * - A function fits when it has the same or fewer parameters, each expected parameter fits its parameter, and its
584
+ * result fits.
585
+ *
586
+ * The relation is sound: a member of `found` is a member of `expected` when no `unknown` is in the types. It is not
587
+ * complete. For example, `bool` does not fit `{ "one": [true, false] }`. The function does not throw.
588
+ *
589
+ * @param found - The type that a part has.
590
+ * @param expected - The type that the position needs.
591
+ * @param domains - The domains of the machine. A domain of the kernel that the table does not name comes from `STD_DOMAINS`.
592
+ * @returns `true` when `found` fits `expected`.
593
+ */
594
+ export declare function fits(found: ValueType, expected: ValueType, domains?: Readonly<Record<string, Domain>>): boolean;
595
+ /**
596
+ * This function gives the join of two value types (TYPE.JOIN): a type that holds each member of both types. The check
597
+ * of a type uses it for the branches of an `if` and for the items of a list.
598
+ *
599
+ * - `unknown` with each type gives `unknown`, and `never` with a type gives that type.
600
+ * - When one type fits the other by the strict form of `fits`, the join is the wider type. The strict form reads
601
+ * `unknown` only as the top.
602
+ * - Two lists give a list of the join of their items.
603
+ * - Two records give a record of the join of their common fields. A field of one closed record is optional in the
604
+ * join of two closed records. The join of an open record leaves out the fields that only one record has.
605
+ * - Each other pair gives a union. The union puts the values of `one` together and leaves out each member that fits
606
+ * another member.
607
+ *
608
+ * The join is sound: a member of `a` or of `b` is a member of the join. It is not always the least such type. The
609
+ * function does not throw.
610
+ *
611
+ * @param a - The first type.
612
+ * @param b - The second type.
613
+ * @param domains - The domains of the machine. A domain of the kernel that the table does not name comes from `STD_DOMAINS`.
614
+ * @returns The join.
615
+ */
616
+ export declare function join(a: ValueType, b: ValueType, domains?: Readonly<Record<string, Domain>>): ValueType;
617
+ /**
618
+ * This function gives the text of a value type (TYPE.TEXT), for the reason of an issue. The function does not throw.
619
+ *
620
+ * - A base type gives its name.
621
+ * - `list<T>` is a list, `{a: T, b?: U}` is a closed record, and `{a: T, ...}` is an open record.
622
+ * - `(T, U) => V` is a function, and `T | U` is a union.
623
+ * - `one` gives its values as JSON, and an empty union gives `never`.
624
+ * - A term that is not a value type gives `unknown`.
625
+ *
626
+ * The text shows at most 8 values of `one`, and it cuts a long value.
627
+ *
628
+ * @param type - The value type.
629
+ * @returns The text.
630
+ */
631
+ export declare function typeText(type: ValueType): string;
632
+ /**
633
+ * This function lists the problems of a value type (TYPE.ISSUES). A problem is a term that is not a value type, a
634
+ * base type without a domain, or a term that is too deep. `fits` and `member` read each such term as `unknown`.
635
+ * Thus a check that reads a type from a contract can report it first.
636
+ *
637
+ * @param type - The value type, as JSON.
638
+ * @param domains - The domains of the machine. A domain of the kernel that the table does not name comes from `STD_DOMAINS`.
639
+ * @returns The problems. A term comes before its parts, and the parts keep their order.
640
+ */
641
+ export declare function typeIssues(type: unknown, domains?: Readonly<Record<string, Domain>>): readonly TypeIssue[];
642
+ //#endregion
485
643
  //#region src/world.d.ts
486
644
  /** The two sides of evaluation. `derive` is pure. `run` causes effects in order. */
487
645
  type Side = "derive" | "run";
@@ -501,6 +659,9 @@ type Side = "derive" | "run";
501
659
  * A `term` with `address: true` is an address: a reference there gives what its path reaches, not the value. A
502
660
  * `term` with `kinds` permits only a part whose type starts with one of the paths. A `record` with `closed: true`
503
661
  * permits only its named fields. A `list` with `distinct: true` permits no two equal items.
662
+ *
663
+ * `expect` is the value type that a part must have, as `of` is its type (TYPE.CHECK). A shape with parts gives it to
664
+ * each part that `of` covers. Only a check of types reads it, and it describes the verb `eval`.
504
665
  */
505
666
  type Shape = {
506
667
  readonly shape: "none";
@@ -509,15 +670,18 @@ type Shape = {
509
670
  readonly of?: string;
510
671
  readonly address?: boolean;
511
672
  readonly kinds?: readonly (readonly Key[])[];
673
+ readonly expect?: ValueType;
512
674
  } | {
513
675
  readonly shape: "list";
514
676
  readonly of?: string;
515
677
  readonly item?: Shape;
516
678
  readonly distinct?: boolean;
679
+ readonly expect?: ValueType;
517
680
  } | {
518
681
  readonly shape: "map";
519
682
  readonly of?: string;
520
683
  readonly item?: Shape;
684
+ readonly expect?: ValueType;
521
685
  } | {
522
686
  readonly shape: "record";
523
687
  readonly fields: readonly string[] | Readonly<Record<string, Shape>>;
@@ -525,9 +689,11 @@ type Shape = {
525
689
  readonly required?: readonly string[];
526
690
  readonly rest?: Shape;
527
691
  readonly closed?: boolean;
692
+ readonly expect?: ValueType;
528
693
  } | {
529
694
  readonly shape: "deep";
530
695
  readonly of?: string;
696
+ readonly expect?: ValueType;
531
697
  } | {
532
698
  readonly shape: "text";
533
699
  } | {
@@ -595,8 +761,44 @@ type CapsRule = {
595
761
  readonly caps: readonly Cap[];
596
762
  readonly in?: readonly (readonly Key[])[];
597
763
  };
598
- /** A kind gives the name of an evaluator for each verb, and the contract of its value. */
599
- interface Kind {
764
+ /**
765
+ * A lazy rule of a kind names the parts that an evaluation can skip and still give a value. An example is the
766
+ * branches of `if`. The static facts mark each read under such a part (D24).
767
+ *
768
+ * `in` names the parts, as patterns of their paths in the value. The key `"*"` matches each key. A rule without `in`
769
+ * covers each part. With `after: n`, the rule covers only the parts after the first `n` parts that its patterns
770
+ * match. Thus `{ after: 1 }` makes each part lazy except the first part, as in `and`.
771
+ */
772
+ interface LazyRule {
773
+ readonly in?: readonly (readonly Key[])[];
774
+ readonly after?: number;
775
+ }
776
+ /**
777
+ * The static facts that a kind declares for its code (D24). The contract of a kind holds them, and the hook `facts`
778
+ * of a machine can give them for a name under a fallback kind. The facts describe the code of `eval`, and of `step`
779
+ * for a step document.
780
+ *
781
+ * - `pure`: `true` when the code of the kind causes no effect. Its result depends only on its data, the results
782
+ * of its parts and what its paths reach. A kind that reads the context in another way does not declare it,
783
+ * because the static facts do not see that read.
784
+ * - `volatile`: `true` when its result can change while each read gives the same thing, for example a clock.
785
+ * - `lazy`: the parts that an evaluation can skip and still give a value.
786
+ */
787
+ interface KindFacts {
788
+ readonly pure?: boolean;
789
+ readonly volatile?: boolean;
790
+ readonly lazy?: readonly LazyRule[];
791
+ }
792
+ /**
793
+ * A kind gives the name of an evaluator for each verb, and the contract of its value. The contract serves each verb.
794
+ * For each verb, the kernel splits the parts and narrows their capabilities by it, and `check` reads its scope rules.
795
+ * `side` and `effects` tell what the verb `eval` does (VERB.CONTRACT).
796
+ */
797
+ interface Kind extends KindFacts {
798
+ /**
799
+ * The evaluator names, by verb. `eval` evaluates a document, `deref` answers a step on it, and `step` names the
800
+ * walker of a step document. A language adds its own verbs, for example `view` or `format`.
801
+ */
600
802
  readonly verbs: Readonly<Record<string, string>>;
601
803
  /** Where the parts of the value are. The default is `none`. */
602
804
  readonly parts?: Shape;
@@ -609,13 +811,20 @@ interface Kind {
609
811
  * itself.
610
812
  */
611
813
  readonly caps?: readonly CapsRule[];
612
- /** The side of the kind. A kind of the run side causes effects. The default is `derive`. */
814
+ /** The side of the verb `eval` of the kind. A kind of the run side causes effects. The default is `derive`. */
613
815
  readonly side?: Side;
614
816
  /**
615
- * The effects that a document of this kind can cause. It is a list of the kinds of the effects. The text
616
- * `"type"` means that the kind of the effect is the type of the document itself, as for a call.
817
+ * The effects that the verb `eval` of a document of this kind can cause. It is a list of the kinds of the effects.
818
+ * The text `"type"` means that the kind of the effect is the type of the document itself, as for a call. For a
819
+ * procedure entry, the list holds the latent effects of the procedure, and `checkLatent` compares them with its body
820
+ * (CAP.LATENT).
617
821
  */
618
822
  readonly effects?: "type" | readonly string[];
823
+ /**
824
+ * The value type of the result of the verb `eval`, when it is fixed (TYPE.SYNTH). A check of types gives it to each
825
+ * document of the kind, in the place of the type that the rule of the evaluator synthesizes.
826
+ */
827
+ readonly result?: ValueType;
619
828
  /** One sentence that tells what the kind is. */
620
829
  readonly summary?: string;
621
830
  }
@@ -637,6 +846,10 @@ type WorldEntry = Kind | Namespace | Alias;
637
846
  */
638
847
  interface World {
639
848
  readonly kinds: Readonly<Record<string, WorldEntry>>;
849
+ /**
850
+ * The default evaluator of each verb: the last rung of the ladder (LADDER.DEFAULT). It serves each verb, also
851
+ * `deref` and `step`. Without a default of `deref`, a step goes into the value of a document (VERB.LADDER).
852
+ */
640
853
  readonly defaults: Readonly<Record<string, string>>;
641
854
  readonly fallback?: Kind;
642
855
  }
@@ -759,36 +972,476 @@ interface AskOptions {
759
972
  readonly declaredType?: string;
760
973
  }
761
974
  /**
762
- * This function finds the kind that a type names, and follows each alias. It gives `undefined` for an unknown
763
- * type.
975
+ * This function finds the kind that a type names, and follows each alias. It gives `undefined` for an unknown
976
+ * type.
977
+ *
978
+ * @param world - The world.
979
+ * @param type - The reference to the type.
980
+ * @returns The kind, or `undefined`.
981
+ */
982
+ export declare function kindOf(world: World, type: TypeRef): Kind | undefined;
983
+ /**
984
+ * This function finds a kind by a text type. It is the same as `kindOf` for a one-key reference.
985
+ *
986
+ * @param world - The world.
987
+ * @param name - The text of the type.
988
+ * @returns The kind, or `undefined`.
989
+ */
990
+ export declare function kindNamed(world: World, name: TypeRef): Kind | undefined;
991
+ /**
992
+ * This function asks a document a question, and gives the evaluator that answers it.
993
+ *
994
+ * The question visits the rungs in order: the own entry of the envelope, then its kind, then the default of the
995
+ * world. The type comes from the envelope, or else from the type that the position declares. The type is a
996
+ * reference into the world. The ladder does not guess a type from the shape of a value. Each verb has this ladder:
997
+ * `eval`, `deref`, `step` and each verb of a language (VERB.LADDER).
998
+ *
999
+ * @param world - The kinds and the defaults.
1000
+ * @param doc - The header of the document: an envelope, or `{}` for a bare value.
1001
+ * @param verb - The verb of the question, for example `eval` or `view`.
1002
+ * @param options - The type that the position declares.
1003
+ * @returns The answer, with the record of each rung that the question visited.
1004
+ */
1005
+ export declare function ask(world: World, doc: Header, verb: string, options?: AskOptions): Answer;
1006
+ //#endregion
1007
+ //#region src/parts.d.ts
1008
+ /** One part of a value: its place in the value, the JSON of the part, and the type that its position declares. */
1009
+ interface PartSlot {
1010
+ /** The keys from the value of the document to the part. */
1011
+ readonly path: readonly Key[];
1012
+ /** The path as one text, with a dot between the keys, for example `bind.x`. A part of a list has its index. */
1013
+ readonly key: string;
1014
+ readonly item: Json;
1015
+ readonly of?: string;
1016
+ /** `true` when the position of the part declares an address: a reference there gives what its path reaches. */
1017
+ readonly address?: true;
1018
+ /** The value type that the shape declares for the part (`expect`). Only a check of types reads it. */
1019
+ readonly expect?: ValueType;
1020
+ }
1021
+ /** The value of a document, split into its parts, by the shape that its kind declares. */
1022
+ type Split = {
1023
+ readonly ok: true;
1024
+ /** The parts, in the order of the value. */
1025
+ readonly parts: readonly PartSlot[];
1026
+ /** The value without the parts: a field that holds a part is not in it, and a list of parts gives `null`. */
1027
+ readonly data: Json;
1028
+ /**
1029
+ * This function gives the value with a handle in the place of each part.
1030
+ *
1031
+ * @param handles - One handle for each part, in the order of `parts`.
1032
+ * @returns The value with the handles.
1033
+ */
1034
+ fill<P>(handles: readonly P[]): unknown;
1035
+ } | {
1036
+ readonly ok: false;
1037
+ readonly reason: string;
1038
+ readonly at: readonly Key[];
1039
+ };
1040
+ /**
1041
+ * This function splits a value into its parts, by the shape that its kind declares. The evaluator, the view and
1042
+ * the static kit use the same split, thus each one sees the same parts.
1043
+ *
1044
+ * @param shape - The shape of the value. The default is data.
1045
+ * @param value - The value of the document.
1046
+ * @returns The parts and a way to fill their places, or the reason why the value does not have the shape.
1047
+ */
1048
+ export declare function splitParts(shape: Shape | undefined, value: Json): Split;
1049
+ /**
1050
+ * The kind and the parts of one document: what `partsOf` gives. `ok` is `false` only when the value is not a
1051
+ * document: it has no envelope, and its position declares no type. A value without the shape of its kind gives a
1052
+ * failed `split`.
1053
+ */
1054
+ type DocParts = {
1055
+ readonly ok: true;
1056
+ /** The document. A bare value gets the type that its position declares. */
1057
+ readonly doc: Envelope;
1058
+ /** `true` when the type came from the position and not from an envelope. */
1059
+ readonly declared: boolean;
1060
+ /** The kind, or `undefined` when the world has no kind for the type. Then the value is data. */
1061
+ readonly kind: Kind | undefined;
1062
+ /** The keys of the kind after each alias, or `undefined` without a kind. */
1063
+ readonly typePath: readonly Key[] | undefined;
1064
+ /**
1065
+ * The split of the value by the shape of the kind. The reason of a failed split is the reason of the `#VALUE!`
1066
+ * of an evaluation: it names the kind. Its `at` gives the keys from the value to the problem.
1067
+ */
1068
+ readonly split: Split;
1069
+ } | {
1070
+ readonly ok: false;
1071
+ readonly code: "#PART?";
1072
+ readonly reason: string;
1073
+ };
1074
+ /**
1075
+ * This function reads one document by the contracts of the world. It finds the kind of the type. A bare value gets
1076
+ * the type that its position declares. Then the function splits the value by the shape of the kind. The plan, the
1077
+ * reference interpreter and the static kit read each document with this function. Thus they see the same parts.
1078
+ *
1079
+ * @param world - The world of the kinds.
1080
+ * @param value - The document, or a bare value.
1081
+ * @param declaredType - The type that the position of a bare value declares.
1082
+ * @returns The document, its kind and its parts, or the reason why the value is not a document.
1083
+ */
1084
+ export declare function partsOf(world: World, value: unknown, declaredType?: string): DocParts;
1085
+ /**
1086
+ * This function tells if the path of a part matches a pattern of a scope rule. The key `"*"` of a pattern matches
1087
+ * each key.
1088
+ *
1089
+ * @param path - The path of the part.
1090
+ * @param pattern - The pattern.
1091
+ * @returns `true` when the path matches.
1092
+ */
1093
+ export declare function pathMatches(path: readonly Key[], pattern: readonly Key[]): boolean;
1094
+ //#endregion
1095
+ //#region src/static.d.ts
1096
+ /** One document that a walk visits. */
1097
+ interface DocVisit {
1098
+ /** The keys from the root document to this document, through the parts. It is the place of an error. */
1099
+ readonly place: readonly Key[];
1100
+ /** The keys from the root JSON value to this document. A change at this path changes this document. */
1101
+ readonly at: readonly Key[];
1102
+ /** The visit of the document that holds this document as a part. The root has none. */
1103
+ readonly parent?: DocVisit | undefined;
1104
+ /** The keys from the value of the parent to this document: the path of the part. The root has none. */
1105
+ readonly slot: readonly Key[];
1106
+ /** The document. A bare value has the type that its position declares. */
1107
+ readonly doc: Envelope;
1108
+ /** `true` when the type came from the position and not from an envelope. */
1109
+ readonly declared: boolean;
1110
+ /** The kind of the document, when the world has it. */
1111
+ readonly kind?: Kind | undefined;
1112
+ /** The keys of the kind after each alias. */
1113
+ readonly typePath?: readonly Key[] | undefined;
1114
+ /** The number of documents around this document. The root has 0. */
1115
+ readonly depth: number;
1116
+ /** The names that the kinds around this document bind for it. */
1117
+ readonly names: ReadonlySet<string>;
1118
+ /** The names that a sequence around this document binds only for the parts after it. */
1119
+ readonly later: ReadonlySet<string>;
1120
+ /** `true` when the position of the document declares an address: a reference there is not a read of a value. */
1121
+ readonly address?: true | undefined;
1122
+ /**
1123
+ * The capabilities of the document: the capabilities of the walk, narrowed by the capability rules of the kinds
1124
+ * around it (`Kind.caps`). A walk without capabilities gives none here.
1125
+ */
1126
+ readonly caps?: readonly Cap[] | undefined;
1127
+ }
1128
+ /** A position that a walk cannot read as a document. */
1129
+ interface WalkProblem {
1130
+ /** The keys from the root document to the document with the problem. */
1131
+ readonly place: readonly Key[];
1132
+ /** The keys from the root JSON value to the value with the problem. */
1133
+ readonly at: readonly Key[];
1134
+ readonly code: "#PART?" | "#VALUE!";
1135
+ readonly reason: string;
1136
+ }
1137
+ /** The options of a walk. */
1138
+ interface WalkOptions {
1139
+ /** The type of a bare root value. */
1140
+ readonly declaredType?: string;
1141
+ /** The names that the host binds at the root. */
1142
+ readonly names?: readonly string[];
1143
+ /** The capabilities at the root. With them, each visit gets the capabilities of its document. */
1144
+ readonly caps?: readonly Cap[];
1145
+ /**
1146
+ * This function gets each position that is not a document.
1147
+ *
1148
+ * @param problem - The position and the reason.
1149
+ */
1150
+ readonly problem?: (problem: WalkProblem) => void;
1151
+ }
1152
+ /**
1153
+ * This function visits each document of a document: the root and each part at each depth, by the contracts of the
1154
+ * kinds. A part of a kind that the world does not have is not visited. With capabilities in the options, the walk
1155
+ * narrows them for each part by the rules of its kind, as a run does. The walk uses no stack of the host for the
1156
+ * depth, thus a deep document cannot overflow it. The time and the memory of a walk are linear in the size of the
1157
+ * document. A visit makes the keys of its place and of its path only when a reader asks for them.
1158
+ *
1159
+ * @param world - The world of the kinds.
1160
+ * @param doc - The document, as JSON.
1161
+ * @param visit - The function that gets each document. It gives `"skip"` to not visit the parts of a document.
1162
+ * @param options - The type of a bare root value, the names, the capabilities and a function for the problems.
1163
+ */
1164
+ export declare function walk(world: World, doc: unknown, visit: (visit: DocVisit) => void | "skip", options?: WalkOptions): void;
1165
+ /** One reference of a document. */
1166
+ interface RefUse {
1167
+ /** The visit of the reference document: its parent, its depth and the names that it sees. */
1168
+ readonly visit: DocVisit;
1169
+ /** The place of the reference document, through the parts. */
1170
+ readonly place: readonly Key[];
1171
+ /** The keys from the root JSON value to the reference document. */
1172
+ readonly at: readonly Key[];
1173
+ /** The path of the reference: its root and its steps. */
1174
+ readonly path: readonly Json[];
1175
+ readonly root: string;
1176
+ /** `false` when a kind around the reference binds its first name. A reference to another root is free. */
1177
+ readonly free: boolean;
1178
+ /** `true` when the reference is an address: its position declares it. An address does not read a value. */
1179
+ readonly address: boolean;
1180
+ }
1181
+ /**
1182
+ * This function finds each reference of a document: each document of the type `ref` that a walk reaches. A
1183
+ * reference to a name that a kind around it binds is not free. The others are what the document reads from
1184
+ * outside: its dependencies. When the kind `ref` has parts, the walk also finds the references in its step documents.
1185
+ *
1186
+ * @param world - The world of the kinds.
1187
+ * @param doc - The document, as JSON.
1188
+ * @param options - The type of a bare root value. The names of the host do not change the result.
1189
+ * @returns The references, in the order of the document.
1190
+ */
1191
+ export declare function refsOf(world: World, doc: unknown, options?: WalkOptions): readonly RefUse[];
1192
+ /**
1193
+ * This function changes the free references of a document. The document is not changed: the function gives a new
1194
+ * document that shares each part without a change.
1195
+ *
1196
+ * @param world - The world of the kinds.
1197
+ * @param doc - The document, as JSON.
1198
+ * @param change - The function that gives the new document of a reference, or `undefined` to keep it.
1199
+ * @param options - The type of a bare root value, and the names that the host binds at the root.
1200
+ * @returns The new document.
1201
+ */
1202
+ export declare function mapRefs(world: World, doc: unknown, change: (use: RefUse) => unknown, options?: WalkOptions): unknown;
1203
+ /** A problem that a check finds before a document runs. */
1204
+ interface Issue {
1205
+ readonly code: ErrorCode;
1206
+ /** The keys from the root document to the document with the problem. */
1207
+ readonly place: readonly Key[];
1208
+ readonly reason: string;
1209
+ /** The keys from the root JSON value to the value with the problem. */
1210
+ readonly at?: readonly Key[];
1211
+ /** The type that the position needs, for a type issue (`#TYPE!`). */
1212
+ readonly expected?: ValueType;
1213
+ /** The type that the check found, for a type issue (`#TYPE!`). */
1214
+ readonly found?: ValueType;
1215
+ }
1216
+ /** The options of a check. */
1217
+ interface CheckOptions {
1218
+ /** The type of a bare root value. */
1219
+ readonly declaredType?: string;
1220
+ /** The names that the host binds at the root. `"any"` does not check the names. The default is no names. */
1221
+ readonly names?: readonly string[] | "any";
1222
+ /**
1223
+ * The capabilities at the root. Without them, the check does not check the effects. The check narrows them for
1224
+ * each part by the capability rules of the kinds, as a run does.
1225
+ */
1226
+ readonly caps?: readonly Cap[];
1227
+ /**
1228
+ * The verb that goes up the ladder at each document, as in `prepare`. The default is `eval`. `#NOEVAL` and the hook
1229
+ * `known` follow this verb. The contract declares the effects and the value types of `eval` only, thus only `eval`
1230
+ * checks them (VERB.CHECK). The type rule of an evaluator serves each verb.
1231
+ */
1232
+ readonly verb?: string;
1233
+ /**
1234
+ * With `true`, the check also checks the value types (TYPE.CHECK). It reads the type rules of the evaluators, the
1235
+ * signatures of the operations and the value types of the contracts. A type issue has the code `#TYPE!`. The
1236
+ * default is `false`, thus a host opts in.
1237
+ */
1238
+ readonly types?: boolean;
1239
+ /** The type that the root document must have, for the check of the value types. */
1240
+ readonly expect?: ValueType;
1241
+ /**
1242
+ * With `true`, the check also finds the problems of a run (RUN.CAN-WAIT). A runner under a parent without a runner
1243
+ * gives `#CALC!` when an effect of its runners can reach the host. The parent cannot pass that wait through.
1244
+ * A runner without such an effect does not wait, and the run drives it (RUN.DRIVE-NESTED). A kind that declares
1245
+ * effects and has no runner gives `#CALC!` too, because in a run only a runner can wait for the host. The default is
1246
+ * `false`.
1247
+ */
1248
+ readonly run?: boolean;
1249
+ /**
1250
+ * The value types of the roots and of the names of the host, for the check of the value types (TYPE.ROOTS). A
1251
+ * reference then gets the type that its path reaches. Only a check with `types: true` reads them.
1252
+ */
1253
+ readonly rootTypes?: RootTypes;
1254
+ }
1255
+ /** The result of `typeCheck`. */
1256
+ interface Typing {
1257
+ /** The type of the root document. It is `unknown` when the root has an issue. */
1258
+ readonly type: ValueType;
1259
+ /** Each issue of the check. The type issues come after the other issues. */
1260
+ readonly issues: readonly Issue[];
1261
+ /** The type of each document, in the order of the document. */
1262
+ readonly places: readonly Typed[];
1263
+ }
1264
+ /**
1265
+ * This function checks a document before an evaluation, by the contracts of its kinds. It finds the problems
1266
+ * that an evaluation finds when it reaches them:
1267
+ *
1268
+ * - `#KIND?`: a kind that the world does not have.
1269
+ * - `#NOEVAL`: no evaluator.
1270
+ * - `#VALUE!`: a value without the shape of its kind.
1271
+ * - `#PART?`: a value without a type.
1272
+ * - `#DEPTH!`: too much nesting.
1273
+ * - `#REF!` and `#STEP?`: a bad path.
1274
+ * - `#NAME?`: a name that nothing binds. With the hook `known` of the machine, also a name that the language does not
1275
+ * have, for example an operation.
1276
+ * - `#CAP!`: an effect that the capabilities of its document do not permit. A kind around the document can narrow them.
1277
+ * The hook `permits` of the machine decides, as in a run (CAP.PERMITS).
1278
+ * - `#CALC!`: with the option `run`, a runner under a parent without a runner, when an effect of its runners can reach
1279
+ * the host. Also a kind that declares effects and has no runner (RUN.CAN-WAIT). The issue has the place and the
1280
+ * reason of the run.
1281
+ * - `#TYPE!`: with the option `types`, a part whose type does not fit the type that its position needs (TYPE.CHECK).
1282
+ * A run does not always fail there, thus a type issue is a static finding, not an error of a run.
1283
+ *
1284
+ * The check asks the ladder for the verb of the options, `eval` by default (VERB.CHECK). The shapes, the paths and the
1285
+ * names follow the contracts, thus they are the same for each verb. Only `eval` checks the declared effects.
1286
+ *
1287
+ * @param machine - The world and the code of the evaluators.
1288
+ * @param doc - The document, as JSON.
1289
+ * @param options - The type of a bare root value, the names of the host, the capabilities, the verb, the types and the run.
1290
+ * @returns The problems, in the order of the document. The type issues come after the other issues.
1291
+ */
1292
+ export declare function check(machine: Machine, doc: unknown, options?: CheckOptions): readonly Issue[];
1293
+ /**
1294
+ * This function checks a document, and it also checks the value types (TYPE.CHECK, D25). It finds each issue of
1295
+ * `check`. Then it synthesizes the type of each document from the types of its parts. It also checks each part
1296
+ * against the type that its position needs. The type rule of the parent, the signature of an operation or the shape
1297
+ * of the contract gives that type. A part with an issue gets the type `unknown`, thus one
1298
+ * problem does not give a chain of issues.
1299
+ *
1300
+ * A type issue has the code `#TYPE!`, the type that the position needs (`expected`) and the type that the check found
1301
+ * (`found`). It is a static finding: the evaluation of the document does not change.
1302
+ *
1303
+ * The option `rootTypes` gives the types of the roots and of the names of the host (TYPE.ROOTS). A reference then gets
1304
+ * the type that its path reaches, and a field that a closed record does not have is a type issue (TYPE.CLOSED).
1305
+ *
1306
+ * @param machine - The world and the code of the evaluators, with their type rules.
1307
+ * @param doc - The document, as JSON.
1308
+ * @param options - The options of `check`, the type that the root must have and the types of the roots.
1309
+ * @returns The type of the root, each issue, and the type of each document.
1310
+ */
1311
+ export declare function typeCheck(machine: Machine, doc: unknown, options?: CheckOptions): Typing;
1312
+ //#endregion
1313
+ //#region src/typing.d.ts
1314
+ /** What a type rule gets for one document. */
1315
+ interface TypeInput {
1316
+ /** The keys of the kind of the document, after each alias. */
1317
+ readonly typePath: readonly Key[];
1318
+ /** The document. A bare value has the type that its position declares. */
1319
+ readonly doc: Envelope;
1320
+ /** The type that the position of the document needs. It is `unknown` when the position needs no type. */
1321
+ readonly expected: ValueType;
1322
+ /** The paths of the parts in the value, in the order of the value. */
1323
+ readonly paths: readonly (readonly Key[])[];
1324
+ /** `true` when the position declares an address. A reference there gives a thing, not a value. */
1325
+ readonly address: boolean;
1326
+ readonly machine: Machine;
1327
+ /**
1328
+ * This function gives the type of a part that the check typed before. It gives `unknown` for a part that the check
1329
+ * did not type yet, and for a part with an issue.
1330
+ *
1331
+ * @param path - The path of the part in the value.
1332
+ * @returns The type of the part.
1333
+ */
1334
+ typeOf(path: readonly Key[]): ValueType;
1335
+ /**
1336
+ * This function gives the type of a name: the type that a kind around the document binds. Without such a kind, it
1337
+ * gives the type from the option `rootTypes` of the host.
1338
+ *
1339
+ * @param name - The name.
1340
+ * @returns The type, or `undefined` when neither a kind around the document nor the host gives the name a type.
1341
+ */
1342
+ nameType(name: string): ValueType | undefined;
1343
+ /**
1344
+ * This function gives the type of a root of the context at the document (TYPE.ROOTS). The host gives the types of
1345
+ * `self`, `world` and `event` in the option `rootTypes`. A rule can give other types to its parts. The root `caps`
1346
+ * always has the type `CAPS_TYPE`. A rule reads the type of a name with `nameType`, thus the root `names` gives
1347
+ * `unknown`.
1348
+ *
1349
+ * @param root - The root.
1350
+ * @returns The type. It is `unknown` for a root without a type.
1351
+ */
1352
+ rootType(root: string): ValueType;
1353
+ /**
1354
+ * This function examines a value type of a contract with `typeIssues`, one time in a check. The first problem of a
1355
+ * type becomes an issue at the document. A term with a problem reads as `unknown`.
1356
+ *
1357
+ * @param type - The value type of the contract.
1358
+ * @param what - What the type is, for the reason, for example "the result of ops.add".
1359
+ * @returns The type.
1360
+ */
1361
+ contract(type: unknown, what: string): ValueType;
1362
+ }
1363
+ /** What a type rule tells for one part: the type that the part must have, and the types of the names of the part. */
1364
+ interface PartType {
1365
+ /** The type that the part must have. */
1366
+ readonly expect?: ValueType;
1367
+ /** What the part is, for the reason of an issue, for example "argument 2 of ops.add". */
1368
+ readonly what?: string;
1369
+ /** The types of the names that the scope rules of the kind bind for the part. Each other name of the rules gets `unknown`. */
1370
+ readonly names?: Readonly<Record<string, ValueType>>;
1371
+ /**
1372
+ * The types of the roots that the evaluator changes for the part, for example `self` for the attributes of a node.
1373
+ * Each other root keeps its type. The parts of an evaluator without a rule get `unknown` for each of these roots.
1374
+ */
1375
+ readonly roots?: Omit<RootTypes, "names">;
1376
+ }
1377
+ /**
1378
+ * The value types of the roots of a context, for a check of types (TYPE.ROOTS). The host gives them in the option
1379
+ * `rootTypes` of `check` and `typeCheck`. A root without a type has the type `unknown`. The root `caps` always has the
1380
+ * type `CAPS_TYPE`, because the kernel narrows it.
764
1381
  *
765
- * @param world - The world.
766
- * @param type - The reference to the type.
767
- * @returns The kind, or `undefined`.
1382
+ * The host keeps the types true: each root of the context holds a member of its type. A host thing, or a machine
1383
+ * with `adopt`, keeps each step true too. The context binds each name of `names`, thus the option `names` of `check`
1384
+ * lists it too.
768
1385
  */
769
- export declare function kindOf(world: World, type: TypeRef): Kind | undefined;
1386
+ interface RootTypes {
1387
+ /** The type of each name that the host binds. A name of the host without a type here has the type `unknown`. */
1388
+ readonly names?: Readonly<Record<string, ValueType>>;
1389
+ /** The type of `self`: the node or the position that the document is part of. */
1390
+ readonly self?: ValueType;
1391
+ /** The type of `world`, for example the schema of a store. The context then gives the world. */
1392
+ readonly world?: ValueType;
1393
+ /** The type of `event`: the event that started a run. */
1394
+ readonly event?: ValueType;
1395
+ }
770
1396
  /**
771
- * This function finds a kind by a text type. It is the same as `kindOf` for a one-key reference.
772
- *
773
- * @param world - The world.
774
- * @param name - The text of the type.
775
- * @returns The kind, or `undefined`.
1397
+ * The value type of the root `caps`: a list of capabilities. A capability is a text, or a list of keys. The kernel
1398
+ * narrows the capabilities for each part, thus the host does not give this type.
776
1399
  */
777
- export declare function kindNamed(world: World, name: TypeRef): Kind | undefined;
1400
+ export declare const CAPS_TYPE: ValueType;
1401
+ /** A problem that a type rule finds. Its place is a part of the document, or the document itself. */
1402
+ interface TypeProblem {
1403
+ /** The path of the part in the value. Without it, the problem is at the document. */
1404
+ readonly path?: readonly Key[];
1405
+ readonly reason: string;
1406
+ readonly expected?: ValueType;
1407
+ readonly found?: ValueType;
1408
+ }
778
1409
  /**
779
- * This function asks a document a question, and gives the evaluator that answers it.
780
- *
781
- * The question visits the rungs in order: the own entry of the envelope, then its kind, then the default of the
782
- * world. The type comes from the envelope, or else from the type that the position declares. The type is a
783
- * reference into the world. The ladder does not guess a type from the shape of a value.
784
- *
785
- * @param world - The kinds and the defaults.
786
- * @param doc - The header of the document: an envelope, or `{}` for a bare value.
787
- * @param verb - The verb of the question, for example `eval` or `view`.
788
- * @param options - The type that the position declares.
789
- * @returns The answer, with the record of each rung that the question visited.
1410
+ * The type rule of an evaluator: what a check of types knows about the values that the evaluator gives. An evaluator
1411
+ * object holds its rule in its field `type`. Thus the rule follows the evaluator that the ladder gives a document
1412
+ * (TYPE.RULE).
790
1413
  */
791
- export declare function ask(world: World, doc: Header, verb: string, options?: AskOptions): Answer;
1414
+ interface TypeRule {
1415
+ /**
1416
+ * This function tells the type that a part must have, and the types of the names for the part. The check asks it
1417
+ * before it types the part. The parts that give the names of a rule `keysAt` come first.
1418
+ *
1419
+ * @param input - The document, the type that its position needs, and the types of the parts before.
1420
+ * @param path - The path of the part in the value.
1421
+ * @returns The type of the part and the types of its names.
1422
+ */
1423
+ readonly part?: (input: TypeInput, path: readonly Key[]) => PartType;
1424
+ /**
1425
+ * This function synthesizes the type of the document from the types of its parts. It must be sound: each value that
1426
+ * the evaluator gives is a member of the type.
1427
+ *
1428
+ * @param input - The document, the type that its position needs, and the types of its parts.
1429
+ * @param report - The function that gets each problem that the rule finds.
1430
+ * @returns The type of the document.
1431
+ */
1432
+ readonly synth: (input: TypeInput, report: (problem: TypeProblem) => void) => ValueType;
1433
+ }
1434
+ /** The type of one document of a check of types. */
1435
+ interface Typed {
1436
+ /** The keys from the root document to the document. */
1437
+ readonly place: readonly Key[];
1438
+ /** The keys from the root JSON value to the document. */
1439
+ readonly at: readonly Key[];
1440
+ /** The type that the check synthesized. A document with an issue has the type `unknown`. */
1441
+ readonly type: ValueType;
1442
+ /** The type that the position of the document needs, when it needs one. */
1443
+ readonly expected?: ValueType;
1444
+ }
792
1445
  //#endregion
793
1446
  //#region src/evaluate.d.ts
794
1447
  /**
@@ -882,6 +1535,33 @@ interface Effect {
882
1535
  */
883
1536
  readonly outcome?: Result;
884
1537
  }
1538
+ /**
1539
+ * One read of an evaluation: a path that code resolved, and what the path reached (READS.RECORD, D26). A schedule
1540
+ * keeps the list of the reads of an evaluation. `verifyReads` resolves each free read again in a new context, and it
1541
+ * tells if the old result stays valid.
1542
+ */
1543
+ interface Read {
1544
+ /** The path that the code resolved: its root, and its steps with the value of each step document. */
1545
+ readonly path: readonly unknown[];
1546
+ /**
1547
+ * What the path reached: the thing, or the error of the resolution. A host thing stays a thing. An exception of the
1548
+ * host gives its error value.
1549
+ */
1550
+ readonly reached: Result;
1551
+ /**
1552
+ * `true` when the read reads the context of the evaluation (READS.FREE). A read of a name that a kind binds, for
1553
+ * example a name of `let`, is not free. A read of a `self` that a kind sets is not free either, for example a node
1554
+ * of a tree. A path without a root is not free. `verifyReads` resolves only the free reads again.
1555
+ */
1556
+ readonly free: boolean;
1557
+ /**
1558
+ * `true` when the kernel adds the read, because a value keeps a root of the context for later (READS.KEPT). Such a
1559
+ * read has the whole root as its path.
1560
+ */
1561
+ readonly kept?: true;
1562
+ /** The hops of the resolution, only when the code asked for them. `verifyReads` then compares each hop too. */
1563
+ readonly hops?: readonly Hop[];
1564
+ }
885
1565
  /**
886
1566
  * The host side of a run: it does one effect, and gives its result. A throw or a rejection is an error value, and a
887
1567
  * `Failure` gives its own error value. In an evaluation, this function is a mock: it answers at once, and a promise
@@ -932,7 +1612,7 @@ interface Runtime {
932
1612
  * This function causes an effect from an evaluator. In a run, an evaluator cannot cause an effect: the host does
933
1613
  * each effect, thus only a runner can wait for it.
934
1614
  *
935
- * @param ctx - The context of the document.
1615
+ * @param ctx - The context of the document. It gives only the capabilities that the document has (CAP.NARROW-CODE).
936
1616
  * @param kind - The kind of the effect.
937
1617
  * @param payload - The data of the effect.
938
1618
  * @param place - The place of the document.
@@ -943,7 +1623,7 @@ interface Runtime {
943
1623
  * This function causes an effect from a runner. In a run, the host does it, and the steps wait when the host
944
1624
  * waits.
945
1625
  *
946
- * @param ctx - The context of the document.
1626
+ * @param ctx - The context of the document. It gives only the capabilities that the document has (CAP.NARROW-CODE).
947
1627
  * @param kind - The kind of the effect.
948
1628
  * @param payload - The data of the effect.
949
1629
  * @param place - The place of the document.
@@ -958,6 +1638,12 @@ interface Runtime {
958
1638
  * @returns The steps that give each result, in the order of the list.
959
1639
  */
960
1640
  all(list: readonly (() => Steps)[], options?: AllOptions): Generator<Promise<unknown>, readonly Result[], unknown>;
1641
+ /**
1642
+ * This optional function tells the runtime that a value keeps the context for later, for example a closure of
1643
+ * `fn`. A later use of the value reads that context, and no evaluation records these reads. Thus the list of reads
1644
+ * gets a read of each root of the context (READS.KEPT).
1645
+ */
1646
+ keepsContext?(): void;
961
1647
  }
962
1648
  /**
963
1649
  * The options of a drive of parts at the same time.
@@ -970,9 +1656,16 @@ interface AllOptions {
970
1656
  readonly concurrency?: number;
971
1657
  readonly failFast?: boolean;
972
1658
  }
973
- /** Compiled code: the evaluation of a document in a context. */
1659
+ /**
1660
+ * Compiled code: the evaluation of a document in a context. The code gives each part a context that it makes from
1661
+ * its own context with a spread. The part then keeps only the capabilities of the document (CAP.NARROW-CODE). A
1662
+ * context that the code makes without a spread gives the part no capabilities.
1663
+ */
974
1664
  type Code = (ctx: Context, rt: Runtime) => Result;
975
- /** Compiled code that can wait: the run of a document in a context. */
1665
+ /**
1666
+ * Compiled code that can wait: the run of a document in a context. Its parts keep only the capabilities of the
1667
+ * document, as for `Code`.
1668
+ */
976
1669
  type RunCode = (ctx: Context, rt: Runtime) => Steps;
977
1670
  /** A compiled part: its place in its parent, its binding name, and its code. It has no field with its value. */
978
1671
  interface CompiledPart {
@@ -1144,6 +1837,11 @@ interface CompiledEvaluator {
1144
1837
  * @returns The code that evaluates the document.
1145
1838
  */
1146
1839
  readonly compile: (input: CompileInput) => Code;
1840
+ /**
1841
+ * The type rule of the evaluator: the value types that a check of types gives its documents and their parts
1842
+ * (TYPE.RULE). Only a check reads it. An evaluator without a rule gives `unknown`.
1843
+ */
1844
+ readonly type?: TypeRule;
1147
1845
  }
1148
1846
  /** An evaluator: a function of its input, or a compiler. */
1149
1847
  type Evaluator = EvalFn | CompiledEvaluator;
@@ -1168,8 +1866,11 @@ type Runner = RunFn | CompiledRunner;
1168
1866
  * A machine: a world of kinds, and the code of each evaluator name, of each `deref` and of each walker.
1169
1867
  *
1170
1868
  * - `maxDepth`: the deepest nesting of documents. The default is 1000.
1171
- * - `permits`: the rule of the host for an effect. The default is the function `permits` on the capabilities.
1869
+ * - `permits`: the rule of the host for an effect. The default is the function `permits` on the capabilities. A run,
1870
+ * `check` and `effectsOf` ask it (CAP.PERMITS). In a check, its context has only the capabilities and the world.
1172
1871
  * - `known`: the names that the evaluators know, for `check`. Without it, `check` does not check such names.
1872
+ * - `domains`: the value domains of the language, by the name of their base type (D22).
1873
+ * - `facts`: the static facts of the names that a fallback kind covers, for `factsOf` (D24).
1173
1874
  */
1174
1875
  interface Machine extends Navigator {
1175
1876
  readonly evaluators: Readonly<Record<string, Evaluator>>;
@@ -1183,10 +1884,26 @@ interface Machine extends Navigator {
1183
1884
  * `check` asks it for each document with an evaluator. The function must be pure.
1184
1885
  *
1185
1886
  * @param path - The keys of the kind of the document, after each alias.
1186
- * @param evaluator - The name of the evaluator that the ladder gives the document.
1887
+ * @param evaluator - The name of the evaluator that the ladder of the verb of the check gives the document.
1187
1888
  * @returns `true` when the evaluator knows the name, or else the reason of the `#NAME?` that a run gives.
1188
1889
  */
1189
1890
  readonly known?: (path: readonly Key[], evaluator: string) => true | string;
1891
+ /**
1892
+ * The value domains of the language, by the name of their base type, for example a color or a unit of length. A
1893
+ * check reads them through `fits` and `member`. A domain of the kernel that the table does not name comes from
1894
+ * `STD_DOMAINS`.
1895
+ */
1896
+ readonly domains?: Readonly<Record<string, Domain>>;
1897
+ /**
1898
+ * This function gives the static facts of the code of a name, for `factsOf` (D24). An example is the operation
1899
+ * `["ops", "now"]` of a formula language: a fallback kind names it, and only the language knows that it is volatile.
1900
+ * Each field of the answer wins over the same field of the contract of the kind. The function must be pure.
1901
+ *
1902
+ * @param path - The keys of the kind of the document, after each alias.
1903
+ * @param code - The name of the evaluator of the document, or of the walker of a step document.
1904
+ * @returns The facts, or `undefined` for the facts of the contract.
1905
+ */
1906
+ readonly facts?: (path: readonly Key[], code: string) => KindFacts | undefined;
1190
1907
  }
1191
1908
  /** One evaluation in a trace. The children are the evaluations of its parts, in the order that they started. */
1192
1909
  interface TraceNode {
@@ -1197,7 +1914,7 @@ interface TraceNode {
1197
1914
  readonly doc: Envelope;
1198
1915
  /** `true` when the type came from the container and not from an envelope. */
1199
1916
  readonly declared: boolean;
1200
- /** The answer of the ladder to the verb `eval`. */
1917
+ /** The answer of the ladder to the verb of the plan, `eval` by default. */
1201
1918
  readonly answer: Answer;
1202
1919
  readonly side: Side;
1203
1920
  /** The names that the document could read when its evaluation started. */
@@ -1239,8 +1956,18 @@ interface RunOptions {
1239
1956
  readonly perform?: Perform;
1240
1957
  /** The type of a bare root value. */
1241
1958
  readonly declaredType?: string;
1959
+ /**
1960
+ * The verb of `run`, for example `format`. The default is `eval` (VERB.PREPARE). A plan keeps the verb of its
1961
+ * `prepare`, thus `plan.run` does not read this option.
1962
+ */
1963
+ readonly verb?: string;
1242
1964
  /** A signal of the host. When it aborts, the run stops with `#ABORT`. */
1243
1965
  readonly signal?: StopSignal;
1966
+ /**
1967
+ * A list that gets each read, in the order of the resolutions (READS.RECORD). Under `all`, the order of the host
1968
+ * decides the order of the reads of the items.
1969
+ */
1970
+ readonly reads?: Read[];
1244
1971
  }
1245
1972
  /** The options of an evaluation of a plan. */
1246
1973
  interface EvalOptions {
@@ -1251,13 +1978,22 @@ interface EvalOptions {
1251
1978
  * Without it, an effect gives its payload (RUN.EVAL).
1252
1979
  */
1253
1980
  readonly perform?: Perform;
1981
+ /**
1982
+ * A list that gets each read, in the order of the resolutions (READS.RECORD). Without it, the plan records no read,
1983
+ * and each resolution costs one more test.
1984
+ */
1985
+ readonly reads?: Read[];
1254
1986
  }
1255
1987
  /** The options of `evaluate`. */
1256
1988
  interface EvaluateOptions {
1257
1989
  /** The type of a bare root value. */
1258
1990
  readonly declaredType?: string;
1991
+ /** The verb that goes up the ladder at each document, for example `format`. The default is `eval` (VERB.PREPARE). */
1992
+ readonly verb?: string;
1259
1993
  /** The mock of the host (RUN.MOCK). Without it, an effect gives its payload (RUN.EVAL). */
1260
1994
  readonly perform?: Perform;
1995
+ /** A list that gets each read, in the order of the resolutions (READS.RECORD). */
1996
+ readonly reads?: Read[];
1261
1997
  }
1262
1998
  /** The options of a compilation. */
1263
1999
  interface PrepareOptions {
@@ -1265,6 +2001,11 @@ interface PrepareOptions {
1265
2001
  readonly declaredType?: string;
1266
2002
  /** `true`: each evaluation records a trace. The default is `false`. */
1267
2003
  readonly trace?: boolean;
2004
+ /**
2005
+ * The verb that goes up the ladder at each document, for example `format`. Each part evaluates with the same verb.
2006
+ * The default is `eval` (VERB.PREPARE).
2007
+ */
2008
+ readonly verb?: string;
1268
2009
  }
1269
2010
  /** A compiled document. It evaluates many times, and it does the work of the ladder one time. */
1270
2011
  interface Plan {
@@ -1278,7 +2019,7 @@ interface Plan {
1278
2019
  * effect at once (RUN.MOCK).
1279
2020
  *
1280
2021
  * @param context - The names and the capabilities at the root.
1281
- * @param options - A list that gets the effects, and the mock of the host.
2022
+ * @param options - A list that gets the effects, the mock of the host and a list that gets the reads.
1282
2023
  * @returns The result.
1283
2024
  */
1284
2025
  evaluate(context?: Context, options?: EvalOptions): Result;
@@ -1286,7 +2027,7 @@ interface Plan {
1286
2027
  * This function runs the document: the host does each effect, and the run waits when the host waits.
1287
2028
  *
1288
2029
  * @param context - The names and the capabilities at the root.
1289
- * @param options - The host code that does the effects, and a signal to stop the run.
2030
+ * @param options - The host code that does the effects, a signal to stop the run and a list that gets the reads.
1290
2031
  * @returns The result, when the run ends.
1291
2032
  */
1292
2033
  run(context?: Context, options?: RunOptions): Promise<Result>;
@@ -1295,9 +2036,13 @@ interface Plan {
1295
2036
  * This function compiles a document into a plan. The ladder, the kinds and the parts are known after it. A plan
1296
2037
  * evaluates many times. A document that does not compile gives a plan that fails with the reason, when it evaluates.
1297
2038
  *
2039
+ * The verb of the options goes up the ladder at each document, and each part evaluates with the same verb. The
2040
+ * default verb is `eval`. A plan of another verb, for example `format`, evaluates, runs and traces as a plan of
2041
+ * `eval` does (VERB.PREPARE).
2042
+ *
1298
2043
  * @param machine - The world and the code of the evaluators.
1299
2044
  * @param doc - The document, as JSON.
1300
- * @param options - The type of a bare root value, and a trace.
2045
+ * @param options - The type of a bare root value, a trace and the verb.
1301
2046
  * @returns The plan.
1302
2047
  */
1303
2048
  export declare function prepare(machine: Machine, doc: unknown, options?: PrepareOptions): Plan;
@@ -1313,15 +2058,17 @@ export declare function planner(machine: Machine, options?: PrepareOptions): (do
1313
2058
  /**
1314
2059
  * This function evaluates a document, and records each evaluation in a trace.
1315
2060
  *
1316
- * The verb `eval` goes up the ladder for each document. The kind of the document tells where its parts are. The
1317
- * evaluator gets each part sealed: it can evaluate the part, and it cannot read its value. A failure gives an error
1318
- * value, and the function does not throw. An effect is recorded in its order, and the host does not do it. A mock
1319
- * can answer each effect at once (RUN.MOCK).
2061
+ * The verb of the options goes up the ladder for each document. The default verb is `eval`. The kind of the document
2062
+ * tells where its parts are. The evaluator gets each part sealed: it can evaluate the part, and it cannot read its
2063
+ * value.
2064
+ *
2065
+ * A failure gives an error value, and the function does not throw. An effect is recorded in its order, and the host
2066
+ * does not do it. A mock can answer each effect at once (RUN.MOCK).
1320
2067
  *
1321
2068
  * @param machine - The world and the code of the evaluators.
1322
2069
  * @param doc - The document, as JSON.
1323
2070
  * @param context - The names and the capabilities at the root.
1324
- * @param options - The type of a bare root value, or the options: that type and the mock of the host.
2071
+ * @param options - The type of a bare root value, or the options: that type, the mock of the host, the verb and a list for the reads.
1325
2072
  * @returns The result, the trace and the effects in their order.
1326
2073
  */
1327
2074
  export declare function evaluate(machine: Machine, doc: unknown, context?: Context, options?: string | EvaluateOptions): Run;
@@ -1333,7 +2080,7 @@ export declare function evaluate(machine: Machine, doc: unknown, context?: Conte
1333
2080
  * @param machine - The world, the evaluators and the runners.
1334
2081
  * @param doc - The document, as JSON.
1335
2082
  * @param context - The names and the capabilities at the root.
1336
- * @param options - The host code that does the effects, the type of a bare root value, and a signal.
2083
+ * @param options - The host code that does the effects, the type of a bare root value, a signal, the verb and a list for the reads.
1337
2084
  * @returns The result, the trace and the effects in their order, when the run ends.
1338
2085
  */
1339
2086
  export declare function run(machine: Machine, doc: unknown, context?: Context, options?: RunOptions): Promise<Run>;
@@ -1401,6 +2148,28 @@ export declare class MergeError extends Error {
1401
2148
  */
1402
2149
  constructor(conflicts: readonly MergeConflict[]);
1403
2150
  }
2151
+ /** What `extendDomain` adds to a domain: more parents, and the types of more steps. */
2152
+ interface DomainExtension {
2153
+ /** The names of the parents to add. A member of the domain then also passes the test of each new parent. */
2154
+ readonly under?: readonly string[];
2155
+ /** The types of the steps to add. A step with the key of an earlier step replaces its type. */
2156
+ readonly steps?: Readonly<Record<string, ValueType>>;
2157
+ }
2158
+ /**
2159
+ * This function makes a part of a merge that adds parents or steps to a domain of an earlier part (TYPE.PARENTS). An
2160
+ * example is a domain of another language. The part reads the domain from the merge before it (`prev`). It gives a
2161
+ * copy with the same test and summary, and it names `["domains", name]` in `replaces` (D17). A domain of the kernel
2162
+ * that the earlier parts do not name comes from `STD_DOMAINS`.
2163
+ *
2164
+ * A new parent adds its test to the domain (TYPE.MEMBER). Thus `fits` stays sound, but a value that fails the test of
2165
+ * the parent is no longer a member. The language that adds the parent keeps the signatures of the other language
2166
+ * true. A name without a domain gives an empty part, and `typeIssues` reports each use of that name.
2167
+ *
2168
+ * @param name - The name of the domain.
2169
+ * @param more - The parents and the steps to add.
2170
+ * @returns The part, as a function of the merge before it.
2171
+ */
2172
+ export declare function extendDomain(name: string, more: DomainExtension): (prev: Machine) => MachinePart;
1404
2173
  /**
1405
2174
  * This function merges worlds into one world, in the order of the parts. It does not change a part.
1406
2175
  *
@@ -1423,9 +2192,11 @@ export declare function mergeWorlds(...parts: readonly (WorldPart | ((prev: Worl
1423
2192
  *
1424
2193
  * - The worlds merge with the rules of `mergeWorlds`. The paths of their conflicts start with `"world"`.
1425
2194
  * - The tables `evaluators`, `runners`, `derefs` and `walkers` merge name by name. A function is equal only to itself.
2195
+ * - The table `domains` merges name by name. Two domains with the same test, parents and summary give one domain (D22).
1426
2196
  * - The evaluator and the runner of a name are its code. A replacement of the name replaces both.
1427
2197
  * - A runner hides the evaluator of its name. Thus one part must give both, or the merge gives a conflict.
1428
2198
  * - The hooks `known` compose in the order of the parts. A hook does not answer for a name that a later part replaces.
2199
+ * The hooks `facts` compose the same way, and the first answer that is not `undefined` wins.
1429
2200
  * - Each other field, for example `permits`, `adopt`, `roots`, `plain` or `maxDepth`, is one value. Two different
1430
2201
  * values are a conflict. An absent field has no value.
1431
2202
  *
@@ -1457,7 +2228,7 @@ export declare function restrictWorld(world: World, paths: readonly MergePath[])
1457
2228
  *
1458
2229
  * - A path that starts with `"world"` removes an entry of the world, with the rules of `restrictWorld`.
1459
2230
  * - `["evaluators", name]` or `["runners", name]` removes the code of the name: its evaluator and its runner.
1460
- * - `["derefs", name]` and `["walkers", name]` remove one entry of their tables.
2231
+ * - `["derefs", name]`, `["walkers", name]` and `["domains", name]` remove one entry of their tables.
1461
2232
  *
1462
2233
  * A path that names no entry changes nothing. The function does not change the machine. An own entry names an
1463
2234
  * evaluator directly, thus only a machine without the code of a name refuses each document that names it.
@@ -1504,92 +2275,6 @@ export declare function classify(shapes: readonly Shape$1[], value: Json): Class
1504
2275
  */
1505
2276
  export declare function tag(value: Json, kind: string): Envelope;
1506
2277
  //#endregion
1507
- //#region src/parts.d.ts
1508
- /** One part of a value: its place in the value, the JSON of the part, and the type that its position declares. */
1509
- interface PartSlot {
1510
- /** The keys from the value of the document to the part. */
1511
- readonly path: readonly Key[];
1512
- /** The path as one text, with a dot between the keys, for example `bind.x`. A part of a list has its index. */
1513
- readonly key: string;
1514
- readonly item: Json;
1515
- readonly of?: string;
1516
- /** `true` when the position of the part declares an address: a reference there gives what its path reaches. */
1517
- readonly address?: true;
1518
- }
1519
- /** The value of a document, split into its parts, by the shape that its kind declares. */
1520
- type Split = {
1521
- readonly ok: true;
1522
- /** The parts, in the order of the value. */
1523
- readonly parts: readonly PartSlot[];
1524
- /** The value without the parts: a field that holds a part is not in it, and a list of parts gives `null`. */
1525
- readonly data: Json;
1526
- /**
1527
- * This function gives the value with a handle in the place of each part.
1528
- *
1529
- * @param handles - One handle for each part, in the order of `parts`.
1530
- * @returns The value with the handles.
1531
- */
1532
- fill<P>(handles: readonly P[]): unknown;
1533
- } | {
1534
- readonly ok: false;
1535
- readonly reason: string;
1536
- readonly at: readonly Key[];
1537
- };
1538
- /**
1539
- * This function splits a value into its parts, by the shape that its kind declares. The evaluator, the view and
1540
- * the static kit use the same split, thus each one sees the same parts.
1541
- *
1542
- * @param shape - The shape of the value. The default is data.
1543
- * @param value - The value of the document.
1544
- * @returns The parts and a way to fill their places, or the reason why the value does not have the shape.
1545
- */
1546
- export declare function splitParts(shape: Shape | undefined, value: Json): Split;
1547
- /**
1548
- * The kind and the parts of one document: what `partsOf` gives. `ok` is `false` only when the value is not a
1549
- * document: it has no envelope, and its position declares no type. A value without the shape of its kind gives a
1550
- * failed `split`.
1551
- */
1552
- type DocParts = {
1553
- readonly ok: true;
1554
- /** The document. A bare value gets the type that its position declares. */
1555
- readonly doc: Envelope;
1556
- /** `true` when the type came from the position and not from an envelope. */
1557
- readonly declared: boolean;
1558
- /** The kind, or `undefined` when the world has no kind for the type. Then the value is data. */
1559
- readonly kind: Kind | undefined;
1560
- /** The keys of the kind after each alias, or `undefined` without a kind. */
1561
- readonly typePath: readonly Key[] | undefined;
1562
- /**
1563
- * The split of the value by the shape of the kind. The reason of a failed split is the reason of the `#VALUE!`
1564
- * of an evaluation: it names the kind. Its `at` gives the keys from the value to the problem.
1565
- */
1566
- readonly split: Split;
1567
- } | {
1568
- readonly ok: false;
1569
- readonly code: "#PART?";
1570
- readonly reason: string;
1571
- };
1572
- /**
1573
- * This function reads one document by the contracts of the world. It finds the kind of the type. A bare value gets
1574
- * the type that its position declares. Then the function splits the value by the shape of the kind. The plan, the
1575
- * reference interpreter and the static kit read each document with this function. Thus they see the same parts.
1576
- *
1577
- * @param world - The world of the kinds.
1578
- * @param value - The document, or a bare value.
1579
- * @param declaredType - The type that the position of a bare value declares.
1580
- * @returns The document, its kind and its parts, or the reason why the value is not a document.
1581
- */
1582
- export declare function partsOf(world: World, value: unknown, declaredType?: string): DocParts;
1583
- /**
1584
- * This function tells if the path of a part matches a pattern of a scope rule. The key `"*"` of a pattern matches
1585
- * each key.
1586
- *
1587
- * @param path - The path of the part.
1588
- * @param pattern - The pattern.
1589
- * @returns `true` when the path matches.
1590
- */
1591
- export declare function pathMatches(path: readonly Key[], pattern: readonly Key[]): boolean;
1592
- //#endregion
1593
2278
  //#region src/stdlib.d.ts
1594
2279
  /**
1595
2280
  * The world of the examples: small kinds for numbers, lists, conditions, names, sequences and effects.
@@ -1627,7 +2312,7 @@ export declare const STD_WALKERS: Readonly<Record<string, Walker>>;
1627
2312
  * order. In a run, an effect ends before the next step starts.
1628
2313
  */
1629
2314
  export declare const STD_RUNNERS: Readonly<Record<string, Runner>>;
1630
- /** The machine of the examples: the standard world, its evaluators, its runners and its walkers. */
2315
+ /** The machine of the examples: the standard world, its evaluators, its runners, its walkers and the domains of the kernel. */
1631
2316
  export declare const STD_MACHINE: Machine;
1632
2317
  /** The capabilities of the examples at the root: the two effects of the standard world. */
1633
2318
  export declare const STD_CAPS: readonly string[];
@@ -1733,155 +2418,144 @@ interface Construct {
1733
2418
  /** Six constructs that show the range of the context. */
1734
2419
  export declare const CONSTRUCTS: readonly Construct[];
1735
2420
  //#endregion
1736
- //#region src/static.d.ts
1737
- /** One document that a walk visits. */
1738
- interface DocVisit {
1739
- /** The keys from the root document to this document, through the parts. It is the place of an error. */
1740
- readonly place: readonly Key[];
1741
- /** The keys from the root JSON value to this document. A change at this path changes this document. */
1742
- readonly at: readonly Key[];
1743
- /** The visit of the document that holds this document as a part. The root has none. */
1744
- readonly parent?: DocVisit | undefined;
1745
- /** The keys from the value of the parent to this document: the path of the part. The root has none. */
1746
- readonly slot: readonly Key[];
1747
- /** The document. A bare value has the type that its position declares. */
1748
- readonly doc: Envelope;
1749
- /** `true` when the type came from the position and not from an envelope. */
1750
- readonly declared: boolean;
1751
- /** The kind of the document, when the world has it. */
1752
- readonly kind?: Kind | undefined;
1753
- /** The keys of the kind after each alias. */
1754
- readonly typePath?: readonly Key[] | undefined;
1755
- /** The number of documents around this document. The root has 0. */
1756
- readonly depth: number;
1757
- /** The names that the kinds around this document bind for it. */
1758
- readonly names: ReadonlySet<string>;
1759
- /** The names that a sequence around this document binds only for the parts after it. */
1760
- readonly later: ReadonlySet<string>;
1761
- /** `true` when the position of the document declares an address: a reference there is not a read of a value. */
1762
- readonly address?: true | undefined;
1763
- /**
1764
- * The capabilities of the document: the capabilities of the walk, narrowed by the capability rules of the kinds
1765
- * around it (`Kind.caps`). A walk without capabilities gives none here.
1766
- */
1767
- readonly caps?: readonly Cap[] | undefined;
1768
- }
1769
- /** A position that a walk cannot read as a document. */
1770
- interface WalkProblem {
1771
- /** The keys from the root document to the document with the problem. */
1772
- readonly place: readonly Key[];
1773
- /** The keys from the root JSON value to the value with the problem. */
1774
- readonly at: readonly Key[];
1775
- readonly code: "#PART?" | "#VALUE!";
1776
- readonly reason: string;
1777
- }
1778
- /** The options of a walk. */
1779
- interface WalkOptions {
1780
- /** The type of a bare root value. */
1781
- readonly declaredType?: string;
1782
- /** The names that the host binds at the root. */
1783
- readonly names?: readonly string[];
1784
- /** The capabilities at the root. With them, each visit gets the capabilities of its document. */
1785
- readonly caps?: readonly Cap[];
1786
- /**
1787
- * This function gets each position that is not a document.
1788
- *
1789
- * @param problem - The position and the reason.
1790
- */
1791
- readonly problem?: (problem: WalkProblem) => void;
1792
- }
2421
+ //#region src/facts.d.ts
1793
2422
  /**
1794
- * This function visits each document of a document: the root and each part at each depth, by the contracts of the
1795
- * kinds. A part of a kind that the world does not have is not visited. With capabilities in the options, the walk
1796
- * narrows them for each part by the rules of its kind, as a run does. The walk uses no stack of the host for the
1797
- * depth, thus a deep document cannot overflow it. The time and the memory of a walk are linear in the size of the
1798
- * document. A visit makes the keys of its place and of its path only when a reader asks for them.
1799
- *
1800
- * @param world - The world of the kinds.
1801
- * @param doc - The document, as JSON.
1802
- * @param visit - The function that gets each document. It gives `"skip"` to not visit the parts of a document.
1803
- * @param options - The type of a bare root value, the names, the capabilities and a function for the problems.
2423
+ * One read of a document: a free reference, with its marks (FACTS.READS). A plan resolves the path of the reference
2424
+ * when it evaluates the reference. The static read covers each path that the plan resolves there (FACTS.SOUND).
1804
2425
  */
1805
- export declare function walk(world: World, doc: unknown, visit: (visit: DocVisit) => void | "skip", options?: WalkOptions): void;
1806
- /** One reference of a document. */
1807
- interface RefUse {
1808
- /** The visit of the reference document: its parent, its depth and the names that it sees. */
1809
- readonly visit: DocVisit;
1810
- /** The place of the reference document, through the parts. */
2426
+ interface StaticRead {
2427
+ /** The root of the path. */
2428
+ readonly root: Root;
2429
+ /** The keys after the root, up to the first step that is not a key. */
2430
+ readonly keys: readonly Key[];
2431
+ /**
2432
+ * `true` when each step after the root is a key. Then the plan resolves this path and no other. A step document,
2433
+ * for example `nearest`, makes it `false`: the plan resolves a path that starts with the keys.
2434
+ */
2435
+ readonly exact: boolean;
2436
+ /** `true` when only a lazy part reaches the reference. An evaluation can then give a value without this read (FACTS.LAZY). */
2437
+ readonly lazy: boolean;
2438
+ /** `true` when the position of the reference declares an address. The read gives what the path reaches, not its value. */
2439
+ readonly address: boolean;
2440
+ /** The path of the reference: its root and its steps. */
2441
+ readonly path: readonly Json[];
2442
+ /** The keys from the root document to the reference document, through the parts. */
1811
2443
  readonly place: readonly Key[];
1812
2444
  /** The keys from the root JSON value to the reference document. */
1813
2445
  readonly at: readonly Key[];
1814
- /** The path of the reference: its root and its steps. */
1815
- readonly path: readonly Json[];
1816
- readonly root: string;
1817
- /** `false` when a kind around the reference binds its first name. A reference to another root is free. */
1818
- readonly free: boolean;
1819
- /** `true` when the reference is an address: its position declares it. An address does not read a value. */
1820
- readonly address: boolean;
2446
+ }
2447
+ /** The static facts of one document (D24). They depend only on the document and the machine, not on a context. */
2448
+ interface DocFacts {
2449
+ /** The free references, in the order of the document (FACTS.READS). A reference to a name that a kind binds is not here. */
2450
+ readonly reads: readonly StaticRead[];
2451
+ /** `"run"` when one kind of the document is on the run side (FACTS.SIDE). */
2452
+ readonly side: Side;
2453
+ /** The kinds of the effects that the contracts declare, as texts with dots, each one time (FACTS.EFFECTS). */
2454
+ readonly effects: readonly string[];
2455
+ /**
2456
+ * `true` when each kind of the document declares `pure`, and the document has no effect and is not volatile. Then
2457
+ * its result depends only on what its reads give (FACTS.PURE).
2458
+ */
2459
+ readonly pure: boolean;
2460
+ /** `true` when the result can change while each read gives the same thing, for example with a clock (FACTS.VOLATILE). */
2461
+ readonly volatile: boolean;
2462
+ /** The number of documents in the document: a hint of the cost of an evaluation. */
2463
+ readonly size: number;
2464
+ }
2465
+ /** The options of `factsOf`. */
2466
+ interface FactsOptions {
2467
+ /** The type of a bare root value. */
2468
+ readonly declaredType?: string;
2469
+ /**
2470
+ * The verb whose evaluators the facts describe, as in `prepare`. The default is `eval`. The contract of a kind
2471
+ * describes the code of `eval` only. For another verb, only the hook `facts` describes the code (FACTS.VERB).
2472
+ */
2473
+ readonly verb?: string;
2474
+ /**
2475
+ * This function tells if a read reaches a volatile value of the host, for example a function that reads a clock.
2476
+ * A read that it marks makes the document volatile (FACTS.VOLATILE).
2477
+ *
2478
+ * @param read - The read.
2479
+ * @returns `true` when the read reaches a volatile value.
2480
+ */
2481
+ readonly volatile?: (read: StaticRead) => boolean;
1821
2482
  }
1822
2483
  /**
1823
- * This function finds each reference of a document: each document of the type `ref` that a walk reaches. A
1824
- * reference to a name that a kind around it binds is not free. The others are what the document reads from
1825
- * outside: its dependencies. When the kind `ref` has parts, the walk also finds the references in its step documents.
2484
+ * This function gives the static facts of a document, for a schedule (R4 P2, D24). It walks the document one time,
2485
+ * by the contracts of its kinds:
1826
2486
  *
1827
- * @param world - The world of the kinds.
1828
- * @param doc - The document, as JSON.
1829
- * @param options - The type of a bare root value. The names of the host do not change the result.
1830
- * @returns The references, in the order of the document.
1831
- */
1832
- export declare function refsOf(world: World, doc: unknown, options?: WalkOptions): readonly RefUse[];
1833
- /**
1834
- * This function changes the free references of a document. The document is not changed: the function gives a new
1835
- * document that shares each part without a change.
2487
+ * - `reads`: each free reference, with the root and the keys of its path. A read under a lazy part has the mark
2488
+ * `lazy`, for example a read in a branch of `if`. A read after a step document has `exact: false`.
2489
+ * - `side` and `effects`: from the contract of each kind.
2490
+ * - `pure`: each kind declares `pure`, and the document has no effect and is not volatile.
2491
+ * - `volatile`: a kind, an operation or a step document declares `volatile`, or the host marks a read.
1836
2492
  *
1837
- * @param world - The world of the kinds.
2493
+ * The hook `facts` of the machine answers for a name that a fallback kind covers, for example an operation. Its
2494
+ * answer wins over the contract of the kind. The contract of a kind does not describe the evaluator of an own
2495
+ * entry. Thus a document with an own entry for another evaluator is not pure, and each of its parts is lazy. The
2496
+ * hook can still answer for that evaluator.
2497
+ *
2498
+ * The option `verb` names the verb whose code the facts describe (FACTS.VERB). A contract describes the code of
2499
+ * `eval`, thus the rule of an own entry applies to each document for another verb. The side and the effects come
2500
+ * from the contracts for each verb.
2501
+ *
2502
+ * A read is one resolution of its path. A reference that the resolution reaches and follows is a part of that read
2503
+ * (DEREF.COLLAPSE), not a separate read. The facts depend only on the document and the machine. Thus a host computes
2504
+ * them again only after an edit of the document or of the machine.
2505
+ *
2506
+ * @param machine - The world, the code and the hook `facts`.
1838
2507
  * @param doc - The document, as JSON.
1839
- * @param change - The function that gives the new document of a reference, or `undefined` to keep it.
1840
- * @param options - The type of a bare root value, and the names that the host binds at the root.
1841
- * @returns The new document.
2508
+ * @param options - The type of a bare root value, the verb and the volatile reads of the host.
2509
+ * @returns The facts.
1842
2510
  */
1843
- export declare function mapRefs(world: World, doc: unknown, change: (use: RefUse) => unknown, options?: WalkOptions): unknown;
1844
- /** A problem that a check finds before a document runs. */
1845
- interface Issue {
1846
- readonly code: ErrorCode;
1847
- /** The keys from the root document to the document with the problem. */
1848
- readonly place: readonly Key[];
1849
- readonly reason: string;
1850
- /** The keys from the root JSON value to the value with the problem. */
1851
- readonly at?: readonly Key[];
1852
- }
1853
- /** The options of a check. */
1854
- interface CheckOptions {
2511
+ export declare function factsOf(machine: Machine, doc: unknown, options?: FactsOptions): DocFacts;
2512
+ //#endregion
2513
+ //#region src/effects.d.ts
2514
+ /** The options of `effectsOf`. */
2515
+ interface EffectsOptions {
1855
2516
  /** The type of a bare root value. */
1856
2517
  readonly declaredType?: string;
1857
- /** The names that the host binds at the root. `"any"` does not check the names. The default is no names. */
1858
- readonly names?: readonly string[] | "any";
1859
2518
  /**
1860
- * The capabilities at the root. Without them, the check does not check the effects. The check narrows them for
1861
- * each part by the capability rules of the kinds, as a run does.
2519
+ * The capabilities at the root. With them, the result keeps only the effects that the rule of the machine permits at
2520
+ * their documents, as a run does (CAP.PERMITS). Without them, the root has each capability, and only the capability
2521
+ * rules of the kinds remove an effect.
1862
2522
  */
1863
2523
  readonly caps?: readonly Cap[];
1864
2524
  }
1865
2525
  /**
1866
- * This function checks a document before an evaluation, by the contracts of its kinds. It finds the problems
1867
- * that an evaluation finds when it reaches them:
2526
+ * This function gives the effects of a document that can reach the host (CAP.EFFECTS-OF, R2 P3). The result is the
2527
+ * effects that the contract of each kind declares, without the effects that the capability rules around them remove.
2528
+ * A rule `mask` removes each effect of its parts, and a rule `only` removes each effect outside its list.
1868
2529
  *
1869
- * - `#KIND?`: a kind that the world does not have.
1870
- * - `#NOEVAL`: no evaluator.
1871
- * - `#VALUE!`: a value without the shape of its kind.
1872
- * - `#PART?`: a value without a type.
1873
- * - `#DEPTH!`: too much nesting.
1874
- * - `#REF!` and `#STEP?`: a bad path.
1875
- * - `#NAME?`: a name that nothing binds. With the hook `known` of the machine, also a name that the language does not
1876
- * have, for example an operation.
1877
- * - `#CAP!`: an effect that the capabilities of its document do not permit. A kind around the document can narrow them.
2530
+ * Without capabilities in the options, the result is the least authority of the document. A host that grants these
2531
+ * kinds as capabilities grants each effect that a run of the document can give it. With capabilities, the result keeps
2532
+ * only the effects that the rule of the machine permits at their documents.
1878
2533
  *
1879
- * @param machine - The world and the code of the evaluators.
2534
+ * The result covers each effect that an evaluation or a run gives the host (CAP.EFFECTS-SOUND). A procedure value keeps
2535
+ * the capabilities of the document that made it, thus the effects of its body count at the body (CAP.LATENT). The
2536
+ * contract describes the code of its kind. The code of an own entry for another evaluator is outside the result.
2537
+ *
2538
+ * @param machine - The world and its contracts, and the hook `permits`.
1880
2539
  * @param doc - The document, as JSON.
1881
- * @param options - The type of a bare root value, the names of the host and the capabilities.
1882
- * @returns The problems, in the order of the document.
2540
+ * @param options - The type of a bare root value and the capabilities at the root.
2541
+ * @returns The kinds of the effects, as texts with dots, each one time, in the order of the document.
1883
2542
  */
1884
- export declare function check(machine: Machine, doc: unknown, options?: CheckOptions): readonly Issue[];
2543
+ export declare function effectsOf(machine: Machine, doc: unknown, options?: EffectsOptions): readonly string[];
2544
+ /**
2545
+ * This function compares the latent effects that a procedure declares with the body of the procedure (CAP.LATENT). A
2546
+ * procedure entry is a kind whose code evaluates the document of a procedure. Its field `effects` declares the latent
2547
+ * effects: the effects that a call of the procedure can cause. `check` tests each call against this declaration.
2548
+ *
2549
+ * The function gives a `#CAP!` for each effect of the body that can reach the host and that the declaration does not
2550
+ * permit. An effect that a kind in the body masks fails in the body, thus it is not a latent effect.
2551
+ *
2552
+ * @param machine - The world and its contracts.
2553
+ * @param declared - The latent effects that the procedure declares, for example the field `effects` of its kind.
2554
+ * @param body - The document of the procedure, as JSON.
2555
+ * @param options - The type of a bare root value.
2556
+ * @returns The issues, in the order of the body.
2557
+ */
2558
+ export declare function checkLatent(machine: Machine, declared: readonly Cap[], body: unknown, options?: Omit<EffectsOptions, "caps">): readonly Issue[];
1885
2559
  //#endregion
1886
2560
  //#region src/formula.d.ts
1887
2561
  /** An operation of a formula language: a function of the values of its arguments. */
@@ -1909,6 +2583,14 @@ type ExtFn = (data: Json, context: Context) => Result;
1909
2583
  * - `check`: a check of the value of an operation, for example "a number must be finite".
1910
2584
  * - `combine`: the error of two or more failed parts of an operation, a `record` or a `list`. With it, each part
1911
2585
  * evaluates, and one failed part gives its own error. Without it, the first error stops the evaluation.
2586
+ * - `pure`: the pure operations, for `factsOf` (D24). `true` names each operation that is not volatile. The default
2587
+ * names no operation.
2588
+ * - `volatile`: the operations whose results can change while their arguments stay the same, for example a clock.
2589
+ * - `sigs`: the signatures of the operations, by their name, for a check of types (TYPE.SIGNATURE). A list gives
2590
+ * overloads. An operation without a signature takes and gives `unknown` (TYPE.GRADUAL).
2591
+ *
2592
+ * A check of types trusts the signatures. Each operation must give a member of the result of each signature that
2593
+ * its arguments match. The hook `check` must keep each result in that type.
1912
2594
  */
1913
2595
  interface FormulaProfile {
1914
2596
  readonly ops?: Readonly<Record<string, OpFn>> | ((name: string) => OpFn | undefined);
@@ -1921,6 +2603,22 @@ interface FormulaProfile {
1921
2603
  readonly missing?: (value: unknown) => boolean;
1922
2604
  readonly check?: (value: unknown, op: string) => Result | undefined;
1923
2605
  readonly combine?: (errors: readonly EvalError[]) => EvalError;
2606
+ readonly pure?: true | readonly string[];
2607
+ readonly volatile?: readonly string[];
2608
+ readonly sigs?: Readonly<Record<string, Signature | readonly Signature[]>> | ((name: string) => Signature | readonly Signature[] | undefined);
2609
+ }
2610
+ /**
2611
+ * The signature of an operation: the value types of its parameters and of its result (TYPE.SIGNATURE). A parameter of
2612
+ * the type `unknown` at the end of `params` is optional. A later version can add a key, for example the type that a
2613
+ * true result proves.
2614
+ */
2615
+ interface Signature {
2616
+ /** The types of the parameters, in order. */
2617
+ readonly params: readonly ValueType[];
2618
+ /** The type of each argument after the parameters. Without it, the operation takes no more arguments. */
2619
+ readonly rest?: ValueType;
2620
+ /** The type of the result. */
2621
+ readonly to: ValueType;
1924
2622
  }
1925
2623
  /** The value of a name whose binding failed. A reference to the name gives the error. */
1926
2624
  export declare class Held {
@@ -1954,7 +2652,7 @@ export declare function jsTruthy(value: unknown): boolean;
1954
2652
  export declare function formulaKinds(): Readonly<Record<string, WorldEntry>>;
1955
2653
  /**
1956
2654
  * This function makes the evaluators of the formula kit for one language. Each evaluator compiles its document
1957
- * one time into code.
2655
+ * one time into code. Each evaluator also holds its type rule, for a check of types (TYPE.SYNTH).
1958
2656
  *
1959
2657
  * @param profile - The operations and the rules of the language.
1960
2658
  * @returns The evaluators, by their name.
@@ -1971,16 +2669,31 @@ export declare function formulaEvaluators(profile?: FormulaProfile): Readonly<Re
1971
2669
  * @returns The hook: `true`, or the reason of the `#NAME?` that the evaluator gives in a run.
1972
2670
  */
1973
2671
  export declare function formulaKnown(profile?: FormulaProfile): (path: readonly Key[], evaluator: string) => true | string;
2672
+ /**
2673
+ * This function makes the hook `facts` of the formula kit for one profile (FACTS.PROFILE, D24). It answers for the
2674
+ * operations and the extensions, because one fallback kind covers each of them.
2675
+ *
2676
+ * - An operation of `lazy` has a lazy rule for each argument.
2677
+ * - An operation is pure when the profile names it in `pure`, or when `pure` is `true`. A volatile operation is not pure.
2678
+ * - A standard extension is pure. An extension of the profile gets the context, thus it is not pure.
2679
+ *
2680
+ * @param profile - The operations, the extensions and their facts.
2681
+ * @returns The hook: the facts of a name, or `undefined` for the facts of the contract.
2682
+ */
2683
+ export declare function formulaFacts(profile?: FormulaProfile): (path: readonly Key[], code: string) => KindFacts | undefined;
1974
2684
  /**
1975
2685
  * This function makes a machine for a formula language. It merges the kit and the parts that the language adds with
1976
2686
  * `mergeMachines`. Thus a kind `ops.*` or a namespace `ops` of the language extends the namespace of the kit, and
1977
2687
  * the fallback of the kit stays. The hook `known` of the kit comes from the profile (`formulaKnown`). A hook `known`
1978
- * of the language answers after it.
2688
+ * of the language answers after it. The hook `facts` of the kit comes from the profile too (`formulaFacts`).
1979
2689
  *
1980
2690
  * A kind or an evaluator of the language that differs from the entry of the kit with its name is a conflict. The
1981
2691
  * language names the path in `replaces` to replace the entry, for example `["world", "kinds", "ref"]` or
1982
2692
  * `["evaluators", "formula.op"]`. Then the hook of the kit does not answer for a replaced evaluator.
1983
2693
  *
2694
+ * The kit gives the domains of the kernel (`STD_DOMAINS`). Thus a domain of the language with the name `number` is a
2695
+ * conflict. The language names `["domains", "number"]` in `replaces` to replace it.
2696
+ *
1984
2697
  * @param profile - The operations and the rules of the language.
1985
2698
  * @param more - The parts of a machine that the language adds, with the paths of the entries that it replaces.
1986
2699
  * @returns The machine.
@@ -2007,16 +2720,24 @@ interface ReferenceOptions {
2007
2720
  readonly effects?: Effect[];
2008
2721
  /** The mock of the host (RUN.MOCK). It answers each effect at once. Without it, an effect gives its payload. */
2009
2722
  readonly perform?: Perform;
2723
+ /**
2724
+ * The verb that goes up the ladder at each document, as in `prepare`. The default is `eval`. The reference reads
2725
+ * each verb by the same rules (VERB.AGREE).
2726
+ */
2727
+ readonly verb?: string;
2010
2728
  }
2011
2729
  /**
2012
2730
  * This function evaluates a document by the rules, without a compilation. It is the reference of the plans: a plan,
2013
2731
  * a traced plan and the second tier of a language must give its results. It covers evaluations, not runs: an effect
2014
2732
  * gives the answer of the mock or its payload, and a part that waits gives `#CALC!`.
2015
2733
  *
2734
+ * The verb of the options goes up the ladder at each document, as in `prepare`. Each verb has the same rules: the
2735
+ * ladder, the contract of the kind and the sealed parts (VERB.AGREE).
2736
+ *
2016
2737
  * @param machine - The world and the code of the evaluators.
2017
2738
  * @param doc - The document.
2018
2739
  * @param context - The names and the capabilities at the root.
2019
- * @param options - The type of a bare root value, the definitions of compiled code, a list for the effects and a mock.
2740
+ * @param options - The type of a bare root value, the definitions of compiled code, a list for the effects, a mock and the verb.
2020
2741
  * @returns The result.
2021
2742
  */
2022
2743
  export declare function reference(machine: Machine, doc: unknown, context?: Context, options?: ReferenceOptions): Result;
@@ -2054,11 +2775,19 @@ interface TierResult {
2054
2775
  interface TierInput {
2055
2776
  /** The mock of the host, when `agree` has one (AGREE.MOCK). The tier answers each effect with it. */
2056
2777
  readonly perform?: Perform;
2778
+ /** The verb of `agree`, when its options name one (VERB.AGREE). A tier that does not serve the verb fails. */
2779
+ readonly verb?: string;
2057
2780
  }
2058
2781
  /** The options of `agree`. */
2059
2782
  interface AgreeOptions {
2060
2783
  /** The type of a bare root value. */
2061
2784
  readonly declaredType?: string;
2785
+ /**
2786
+ * The verb of each tier, as in `prepare`. The default is `eval`. The plan, the reference, the traced evaluation and a
2787
+ * second evaluation each ask the ladder for this verb (VERB.AGREE). The second tier of a language gets it in its
2788
+ * input.
2789
+ */
2790
+ readonly verb?: string;
2062
2791
  /** The definitional code of the compiled evaluators of the machine, for the reference. */
2063
2792
  readonly definitions?: Definitions;
2064
2793
  /** The tiers to compare with the plan. The default is the reference, the traced evaluation and a second evaluation. */
@@ -2068,7 +2797,7 @@ interface AgreeOptions {
2068
2797
  *
2069
2798
  * @param doc - The document.
2070
2799
  * @param context - The context.
2071
- * @param input - The mock of the host, when `agree` has one.
2800
+ * @param input - The mock of the host and the verb, when `agree` has them.
2072
2801
  * @returns The result, or the result with the effects.
2073
2802
  */
2074
2803
  readonly other?: (doc: unknown, context: Context, input: TierInput) => Result | TierResult;
@@ -2144,6 +2873,110 @@ export declare function sameValue(a: unknown, b: unknown, equal?: (a: unknown, b
2144
2873
  */
2145
2874
  export declare function agree(machine: Machine, doc: unknown, context?: Context, options?: AgreeOptions): Agreement;
2146
2875
  //#endregion
2876
+ //#region src/conform.d.ts
2877
+ /**
2878
+ * An obligation that `conforms` checks. `C1` to `C8` are the obligations of host code in `docs/SEMANTICS.md`. `local`
2879
+ * and `agree` are two premises of the simulation of the plan (SIM-PLAN).
2880
+ *
2881
+ * - `C1`: each context that the code gives a part, or an effect, has only the capabilities of its document.
2882
+ * - `C2`: the code causes only the effects that the contract of the kind declares.
2883
+ * - `C3`: each eager part evaluates when the result is a value, and a lazy part evaluates only when its result counts.
2884
+ * - `C4`: the code of a pure kind causes no effect, and it reads the context only through `resolve`.
2885
+ * - `C5`: the code reads its parts only through their handles, not through the JSON of the document.
2886
+ * - `C6`: only a runner waits, and a runner passes each wait of its parts and its effects through.
2887
+ * - `C7`: the code binds for a part each name that the scope rules give the part, and no other name.
2888
+ * - `C8`: compiled code gives the result of code that compiles again at the time of the evaluation.
2889
+ * - `local`: the code keeps no state from one call to the next.
2890
+ * - `agree`: compiled code gives the result of its definition for the reference interpreter.
2891
+ */
2892
+ type Obligation = "C1" | "C2" | "C3" | "C4" | "C5" | "C6" | "C7" | "C8" | "local" | "agree";
2893
+ /** The probe of a finding: the document, the result of each probe part, the capabilities and the handler. */
2894
+ interface ConformProbe {
2895
+ /** The text of the type of the document. */
2896
+ readonly type: string;
2897
+ /** The document. A probe document takes the place of each part. */
2898
+ readonly doc: Envelope;
2899
+ /** The result of each probe part, by the key of the part. */
2900
+ readonly results: Readonly<Record<string, Result>>;
2901
+ /** The keys of the probe parts that wait for the host before they give their result. Only a run has them. */
2902
+ readonly waits: readonly string[];
2903
+ /** The capabilities of the context of the document. */
2904
+ readonly caps: readonly Cap[];
2905
+ /** `true` in a run, in which the host does each effect and a part can wait. */
2906
+ readonly running: boolean;
2907
+ }
2908
+ /** One obligation that the code breaks, with the reason and the first probe that shows it. */
2909
+ interface Finding {
2910
+ readonly obligation: Obligation;
2911
+ /** One or two sentences that tell what the code did. */
2912
+ readonly reason: string;
2913
+ readonly probe: ConformProbe;
2914
+ }
2915
+ /** The options of `conforms`. */
2916
+ interface ConformOptions {
2917
+ /**
2918
+ * The verb that the evaluator serves. The default is `eval`. The facts of a contract (`effects`, `pure` and `lazy`)
2919
+ * describe only `eval`, thus `conforms` checks C2, C3 and C4 only for `eval` (D23).
2920
+ */
2921
+ readonly verb?: string;
2922
+ /**
2923
+ * The types of the probe documents. The default is each kind of the world whose verb names the evaluator. A fallback
2924
+ * kind gives the key `probe`, for example `["ops", "probe"]`. The contract of the kind of each type applies.
2925
+ */
2926
+ readonly types?: readonly TypeRef[];
2927
+ /**
2928
+ * More values of probe documents, by the text of their type. A probe document takes the place of each part of such a
2929
+ * value. Use them for data that the code needs, for example the key of `write`.
2930
+ */
2931
+ readonly values?: Readonly<Record<string, readonly Json[]>>;
2932
+ /**
2933
+ * The results that a probe part can give. The default holds numbers, truth values, a text, `null`, a list, a
2934
+ * record, a function and two errors.
2935
+ */
2936
+ readonly results?: readonly Result[];
2937
+ /**
2938
+ * The definitional code of the compiled evaluators and runners, as for `reference`. A standard evaluator gets its
2939
+ * definition from `STD_DEFINITIONS`.
2940
+ */
2941
+ readonly definitions?: Definitions;
2942
+ /** The capabilities of half of the probes. The other half has none. The default is the declared effects and `probe`. */
2943
+ readonly caps?: readonly Cap[];
2944
+ /** The names of the context of each probe. */
2945
+ readonly names?: Readonly<Record<string, unknown>>;
2946
+ /** The seed of the random results. The same seed gives the same probes. The default is 1. */
2947
+ readonly seed?: number;
2948
+ /** The count of probes with random results for each probe document. The default is 12. */
2949
+ readonly runs?: number;
2950
+ /** The mock of the host (RUN.MOCK). It answers each effect at once. Without it, an effect gives its payload. */
2951
+ readonly perform?: Perform;
2952
+ /**
2953
+ * This function compares two values that the rules of `sameValue` do not know, as in `agree`.
2954
+ *
2955
+ * @param a - The first value.
2956
+ * @param b - The second value.
2957
+ * @returns `true` or `false`, or `undefined` for the rules of `sameValue`.
2958
+ */
2959
+ readonly equal?: (a: unknown, b: unknown) => boolean | undefined;
2960
+ }
2961
+ /**
2962
+ * This function examines one evaluator or runner of a machine against the obligations of host code (K92, D36). It
2963
+ * starts the code directly, without the kernel, with probe parts and a probe runtime. It generates probe documents from
2964
+ * the contract of each kind that names the code, and it gives the probe parts chosen and random results.
2965
+ *
2966
+ * The checks follow the obligations C1 to C8 of `docs/SEMANTICS.md`. Two more checks follow the premises of the
2967
+ * simulation of the plan. The check `local` finds state that stays from one call to the next. The check `agree` compares
2968
+ * compiled code with its definition. The
2969
+ * finding of an obligation names the first probe that breaks it. An empty list means that each probe conforms.
2970
+ *
2971
+ * @param machine - The machine with the code and the world of the kinds.
2972
+ * @param name - The name of the evaluator or of the runner. A runner wins over an evaluator of the same name.
2973
+ * @param options - The verb, the types and the values of the probe documents, and the results of the probe parts. Also
2974
+ * the definitions, the capabilities, the names, the seed, the mock and the rule of equality.
2975
+ * @returns The first finding of each obligation that the code breaks, in the order of the obligations.
2976
+ * @throws {Error} The machine has no code with the name, or no kind names it and the options give no types.
2977
+ */
2978
+ export declare function conforms(machine: Machine, name: string, options?: ConformOptions): readonly Finding[];
2979
+ //#endregion
2147
2980
  //#region src/same.d.ts
2148
2981
  /**
2149
2982
  * This function tells if two results are the same for an early cutoff (RESULT.SAME). A schedule uses it to stop the
@@ -2167,6 +3000,422 @@ export declare function agree(machine: Machine, doc: unknown, context?: Context,
2167
3000
  */
2168
3001
  export declare function sameResult(a: Result<unknown>, b: Result<unknown>, equal?: (a: unknown, b: unknown) => boolean | undefined): boolean;
2169
3002
  //#endregion
3003
+ //#region src/reads.d.ts
3004
+ /** The answer of `verifyReads`: the old result stays valid, or the first read that reaches another thing. */
3005
+ type ReadsCheck = {
3006
+ readonly same: true;
3007
+ } | {
3008
+ readonly same: false;
3009
+ /** The index of the first changed read in the list. */
3010
+ readonly index: number;
3011
+ /** The first changed read, as the evaluation recorded it. */
3012
+ readonly read: Read;
3013
+ /** What the path of that read reaches in the new context. */
3014
+ readonly now: Result;
3015
+ };
3016
+ /** The options of `verifyReads`. */
3017
+ interface VerifyOptions {
3018
+ /**
3019
+ * The rule of the host for two things, as in `sameResult`. It answers first, and `undefined` gives the rules of
3020
+ * `sameResult`. An example is a rule for a host thing that keeps a version.
3021
+ *
3022
+ * @param a - The thing of the recorded read.
3023
+ * @param b - The thing in the new context.
3024
+ * @returns `true` when the two things are the same, or `undefined` for the rules of `sameResult`.
3025
+ */
3026
+ readonly equal?: (a: unknown, b: unknown) => boolean | undefined;
3027
+ }
3028
+ /**
3029
+ * This function tells if an old result stays valid in a new context (READS.VERIFY, D26). It resolves the path of
3030
+ * each free read again, in the order of the list, and it compares what the path reaches with `sameResult`. It stops at
3031
+ * the first read that reaches another thing, and it gives that read (READS.CHANGED).
3032
+ *
3033
+ * - A read that is not free reads a binding that a kind made from earlier reads, for example a name of `let`. The
3034
+ * function does not resolve it again.
3035
+ * - A thing compares as in `sameResult`. Thus a host thing or a date is the same only as itself. A host gives a new
3036
+ * object for a new state, or the option `equal`.
3037
+ * - A longer path through a name that holds a `Held` in the new context is a changed read. A reference of the formula
3038
+ * kit gives the error of that binding, and the resolution of the path does not show it.
3039
+ * - The answer is sound only for a pure document (FACTS.PURE). A document with an effect, a volatile operation or an
3040
+ * extension of a profile can read outside `resolve`. The schedule asks `factsOf` first.
3041
+ *
3042
+ * The values of the context must not change in place, as PLAN.CACHE says for the documents. A value that changed in
3043
+ * place is the same object, thus the function cannot see the change.
3044
+ *
3045
+ * @param target - The machine of the evaluation, or its plan.
3046
+ * @param reads - The reads of the evaluation, from the option `reads`.
3047
+ * @param context - The new context.
3048
+ * @param options - The rule of the host for two things.
3049
+ * @returns `{ same: true }` when each free read reaches the same thing, or else the first changed read.
3050
+ */
3051
+ export declare function verifyReads(target: Machine | Plan, reads: readonly Read[], context: Context, options?: VerifyOptions): ReadsCheck;
3052
+ //#endregion
3053
+ //#region src/durable.d.ts
3054
+ /** The two epochs of a host (DURABLE.EPOCHS). Each epoch counts the changes of its level. */
3055
+ interface Epochs {
3056
+ /** The count of the changes of the structure: a new machine, or an edit of a document. */
3057
+ readonly structure: number;
3058
+ /** The count of the changes of the data. A change of the structure is also a change of the data. */
3059
+ readonly data: number;
3060
+ }
3061
+ /** The work of a durable cache since its start. A schedule reads it as a measure, not as a rule (R4). */
3062
+ interface DurableCounts {
3063
+ /** The compilations: the calls of `prepare`. */
3064
+ readonly compiles: number;
3065
+ /** The calls of `factsOf`. */
3066
+ readonly facts: number;
3067
+ /** The evaluations of a plan. */
3068
+ readonly evaluations: number;
3069
+ /** The calls of `verifyReads`. */
3070
+ readonly verifications: number;
3071
+ /** The results that stayed without an evaluation. */
3072
+ readonly reuses: number;
3073
+ }
3074
+ /** The options of `durable`. */
3075
+ interface DurableOptions {
3076
+ /** The type of a bare root value, for each plan and each fact. */
3077
+ readonly declaredType?: string;
3078
+ /** The verb of each plan and each fact. The default is `eval` (VERB.PREPARE). */
3079
+ readonly verb?: string;
3080
+ /** The volatile reads of the host, as in `factsOf`. A document with such a read is not pure, thus it evaluates again after each change of data. */
3081
+ readonly volatile?: FactsOptions["volatile"];
3082
+ /** The rule of the host for two things, as in `verifyReads`. */
3083
+ readonly equal?: VerifyOptions["equal"];
3084
+ }
3085
+ /**
3086
+ * A cache of plans, facts and results with two levels of durability (D30). A host or a schedule tells the cache each
3087
+ * change of the structure and each change of the data.
3088
+ */
3089
+ interface Durable {
3090
+ /** The machine of the current structure epoch. */
3091
+ readonly machine: Machine;
3092
+ /** The current epochs. A schedule builds again what depends on the whole structure when `structure` changes, for example a graph of the nodes. */
3093
+ readonly epochs: Epochs;
3094
+ /** The work since the start. */
3095
+ readonly counts: DurableCounts;
3096
+ /**
3097
+ * This function gives the plan of a document. A document object compiles one time for a machine (DURABLE.STRUCTURE).
3098
+ * A change of data compiles nothing (DURABLE.DATA).
3099
+ *
3100
+ * @param doc - The document, as JSON.
3101
+ * @returns The plan.
3102
+ */
3103
+ plan(doc: unknown): Plan;
3104
+ /**
3105
+ * This function gives the static facts of a document. A document object computes its facts one time for a machine.
3106
+ *
3107
+ * @param doc - The document, as JSON.
3108
+ * @returns The facts.
3109
+ */
3110
+ facts(doc: unknown): DocFacts;
3111
+ /**
3112
+ * This function gives the result of the document of a node (DURABLE.REUSE). The key names the node, and in one data
3113
+ * epoch the context of a key gives the same data.
3114
+ *
3115
+ * - In the data epoch of its result, a key with the same plan gives that result again.
3116
+ * - After a change of data, a pure document verifies its reads, and it keeps its result when each read is the same.
3117
+ * - Each other document evaluates again.
3118
+ *
3119
+ * @param key - The name of the node in the host, for example the name of a cell.
3120
+ * @param doc - The document of the node.
3121
+ * @param context - The context of the node.
3122
+ * @returns The result.
3123
+ */
3124
+ evaluate(key: unknown, doc: unknown, context: Context): Result;
3125
+ /** This function tells the cache that the data changed: a context gives a new value (DURABLE.EPOCHS). */
3126
+ changeData(): void;
3127
+ /**
3128
+ * This function tells the cache that the structure changed (DURABLE.EPOCHS). An edit of a document gives a new
3129
+ * document object, and only that object compiles. A new machine drops each plan, each fact and each result.
3130
+ *
3131
+ * @param machine - The new machine, or `undefined` for an edit of a document.
3132
+ */
3133
+ changeStructure(machine?: Machine): void;
3134
+ /**
3135
+ * This function drops the result of a node, for example a node that the host removed.
3136
+ *
3137
+ * @param key - The name of the node.
3138
+ */
3139
+ forget(key: unknown): void;
3140
+ }
3141
+ /**
3142
+ * This function makes a cache with two levels of durability for a host or a schedule (R4 P7, D30). The structure is
3143
+ * the machine and the documents. The data is each value that a context gives: the names, `self`, `event`, the
3144
+ * capabilities and the world of the host.
3145
+ *
3146
+ * - A plan and the facts depend only on the structure. A document object compiles one time for a machine, thus a
3147
+ * change of data compiles nothing (DURABLE.DATA).
3148
+ * - A result depends on the data too. It stays in its data epoch. After a change of data, a pure document verifies
3149
+ * its reads with `verifyReads`, and each other document evaluates again.
3150
+ * - An edit gives a new document object, thus only that document compiles. A new machine drops each plan, each fact
3151
+ * and each result (DURABLE.STRUCTURE).
3152
+ *
3153
+ * The host keeps two promises. In one data epoch, the context of a key gives the same data. The values of a
3154
+ * context and the documents do not change in place, as PLAN.CACHE and `verifyReads` say.
3155
+ *
3156
+ * @param machine - The machine of the first structure epoch.
3157
+ * @param options - The type of a bare root value, the verb, the volatile reads and the rule of the host for two things.
3158
+ * @returns The cache.
3159
+ */
3160
+ export declare function durable(machine: Machine, options?: DurableOptions): Durable;
3161
+ //#endregion
3162
+ //#region src/schedule.d.ts
3163
+ /** One edge of a graph of nodes: a static read of a node from the document of another node (SCHED.EDGES). */
3164
+ interface NodeEdge {
3165
+ /**
3166
+ * The node that the read reaches: the first key after the root `world`. It is `undefined` when the read can reach
3167
+ * each node, for example the path `["world"]`, or a step document right after the root.
3168
+ */
3169
+ readonly to: string | undefined;
3170
+ /** The keys after the node, up to the first step document: the field of the node that the read reaches (SCHED.GRAIN). */
3171
+ readonly field: readonly Key[];
3172
+ /** `true` when only a lazy part reaches the read. An evaluation can then give a value without it (FACTS.LAZY). */
3173
+ readonly lazy: boolean;
3174
+ /** The static read of `factsOf`, with its path, its place and its mark `exact`. */
3175
+ readonly read: StaticRead;
3176
+ }
3177
+ /** One node of a schedule, with what the static facts tell about it (SCHED.GRAPH). */
3178
+ interface NodeInfo {
3179
+ /** The name of the node: its key under the root `world`. */
3180
+ readonly id: string;
3181
+ /** The document of the node. */
3182
+ readonly doc: unknown;
3183
+ /** The static facts of the document. */
3184
+ readonly facts: DocFacts;
3185
+ /** The side of the node, from the facts. A node on the run side is a sink: no node reads it (SCHED.SIDE). */
3186
+ readonly side: Side;
3187
+ /** The edges to the nodes that the document can read, in the order of its reads. */
3188
+ readonly edges: readonly NodeEdge[];
3189
+ }
3190
+ /** The options of `schedule`: the options of `durable`, and the context of the host. */
3191
+ interface ScheduleOptions extends DurableOptions {
3192
+ /** The context of the host: the names, `self`, `event` and the capabilities. The schedule sets the root `world` to the nodes. */
3193
+ readonly context?: Context;
3194
+ }
3195
+ /** The work of a schedule since its start: the work of its `durable` cache, and the demands ahead of a node. */
3196
+ interface ScheduleCounts extends DurableCounts {
3197
+ /**
3198
+ * The demands that a demand of the host made before its own node (SCHED.LONG-CHAIN). Each node that the eager edges
3199
+ * reach, and that has no value in the data epoch, adds one.
3200
+ */
3201
+ readonly ahead: number;
3202
+ }
3203
+ /** The options of a run of a node. */
3204
+ interface NodeRunOptions {
3205
+ /** The event that starts the run, at the root `event`. The default is the event of the context of the host. */
3206
+ readonly event?: Thing;
3207
+ /** The host code that does each effect, as in `run`. */
3208
+ readonly perform?: Perform;
3209
+ /** A signal that stops the run. */
3210
+ readonly signal?: StopSignal;
3211
+ }
3212
+ /**
3213
+ * The demand schedule of a graph of named nodes (D31). The host tells it each change of a node, of the machine and of
3214
+ * its data. The schedule evaluates a node only when a host or another node reads it.
3215
+ */
3216
+ interface Schedule {
3217
+ /** The epochs of the schedule (DURABLE.EPOCHS). A schedule builds again what depends on the structure when `structure` changes. */
3218
+ readonly epochs: Epochs;
3219
+ /** The work of the schedule since its start: the compilations, the evaluations, the verifications, the reuses and the demands ahead. */
3220
+ readonly counts: ScheduleCounts;
3221
+ /** The context of each node in the current data epoch: the context of the host, with the nodes at the root `world`. */
3222
+ readonly context: Context;
3223
+ /**
3224
+ * This function gives each node with its facts, its side and its edges (SCHED.GRAPH). The map stays the same object
3225
+ * in one structure epoch, thus a schedule can keep what it computes from it, for example an order.
3226
+ *
3227
+ * @returns The nodes, by name.
3228
+ */
3229
+ graph(): ReadonlyMap<string, NodeInfo>;
3230
+ /**
3231
+ * This function gives the value of a node on demand (SCHED.DEMAND). A read of `world` in the document demands that
3232
+ * node first. Each node evaluates at most one time in a data epoch.
3233
+ *
3234
+ * - First, the schedule demands each node that the eager edges reach, deepest first (SCHED.LONG-CHAIN).
3235
+ * - After a change, a pure node verifies its reads, and it keeps its result when each read is the same (SCHED.STALE).
3236
+ * - Each node of a cycle gives `#CYCLE!`, in each order of demands (SCHED.CYCLE).
3237
+ * - A node on the run side gives `#REF!`, because the schedule does not evaluate it (SCHED.SIDE).
3238
+ *
3239
+ * @param id - The name of the node.
3240
+ * @returns The result, or `#N/A` for a node that the schedule does not have.
3241
+ */
3242
+ read(id: string): Result;
3243
+ /**
3244
+ * This function adds a node, or gives a node a new document. It is a change of the structure. Only a new document
3245
+ * object compiles (DURABLE.STRUCTURE).
3246
+ *
3247
+ * @param id - The name of the node.
3248
+ * @param doc - The document of the node. It must not change in place after this call.
3249
+ */
3250
+ set(id: string, doc: unknown): void;
3251
+ /**
3252
+ * This function removes a node. It is a change of the structure, and a read of the node then gives `#N/A`.
3253
+ *
3254
+ * @param id - The name of the node.
3255
+ * @returns `true` when the schedule had the node.
3256
+ */
3257
+ remove(id: string): boolean;
3258
+ /**
3259
+ * This function tells the schedule that the data of the host changed (DURABLE.EPOCHS). The values of a context do
3260
+ * not change in place, thus new data comes in a new context, or through a host thing.
3261
+ *
3262
+ * @param context - The new context of the host, or `undefined` to keep the context.
3263
+ */
3264
+ changeData(context?: Context): void;
3265
+ /**
3266
+ * This function gives the schedule a new machine. It drops each plan, each fact and each result.
3267
+ *
3268
+ * @param machine - The new machine.
3269
+ */
3270
+ changeMachine(machine: Machine): void;
3271
+ /**
3272
+ * This function starts a run of the document of a node, and the host does each effect (SCHED.RUN). Only the host
3273
+ * starts a run, for example at an event. A change of data does not start or repeat a run (L3).
3274
+ *
3275
+ * @param id - The name of the node.
3276
+ * @param options - The event, the host code that does the effects, and a signal to stop the run.
3277
+ * @returns The result, when the run ends.
3278
+ */
3279
+ run(id: string, options?: NodeRunOptions): Promise<Result>;
3280
+ }
3281
+ /**
3282
+ * This function gives the edges of a node from the static facts of its document (SCHED.EDGES). Each read of the root
3283
+ * `world` is an edge to the node of its first key. The keys after that key are the field of the edge (SCHED.GRAIN).
3284
+ * A read of another root reads the data of the host, thus it is not an edge.
3285
+ *
3286
+ * A reference in the value of a node can lead a read to a third node (DEREF.COLLAPSE). The edges do not show such a
3287
+ * read, but the reads of an evaluation do (S1d).
3288
+ *
3289
+ * @param facts - The static facts of the document of the node.
3290
+ * @returns The edges, in the order of the reads.
3291
+ */
3292
+ export declare function edgesOf(facts: DocFacts): readonly NodeEdge[];
3293
+ /**
3294
+ * This function makes the demand schedule of a graph of named nodes (S1, R4, D31). A host gives each node a name and
3295
+ * a document. The root `world` of each node reaches the other nodes by name. The context of the host gives the other
3296
+ * roots.
3297
+ *
3298
+ * - `graph()` gives the facts, the side and the edges of each node, from `factsOf` and `edgesOf`.
3299
+ * - `read(id)` evaluates a node on demand, through `durable`. A pure node verifies its reads after a change, and a
3300
+ * read of a node demands that node again. Thus only a node with a changed read evaluates again: the red-green
3301
+ * algorithm of rustc.
3302
+ * - A node is on a cycle when its demand reaches itself through the reads of the evaluations. Each node of such a
3303
+ * strongly connected component gives `#CYCLE!`, whatever its document does with the error. The schedule finds the
3304
+ * components with the algorithm of Tarjan over the demands. Thus each order of demands gives the same values.
3305
+ * - A demand of the host, or of a run, first demands each node that the eager edges reach, deepest first. Thus each
3306
+ * read of such a node finds a value, and a chain of 100000 nodes does not overflow the stack (SCHED.LONG-CHAIN).
3307
+ * Each such demand starts with no node in evaluation, thus the order of demands keeps the values of D31.
3308
+ * - A node on the run side is a sink. Only `run` evaluates it, and only the host uses `run`.
3309
+ *
3310
+ * The host keeps the promises of `durable`. The documents and the values of a context do not change in place.
3311
+ *
3312
+ * @param machine - The machine of the first structure epoch.
3313
+ * @param options - The options of `durable`, and the context of the host.
3314
+ * @returns The schedule.
3315
+ */
3316
+ export declare function schedule(machine: Machine, options?: ScheduleOptions): Schedule;
3317
+ //#endregion
3318
+ //#region src/graph.d.ts
3319
+ /** One edge of a graph of nodes: a read of a node by another node. `NodeEdge` of a schedule is such an edge. */
3320
+ interface GraphEdge<Id> {
3321
+ /** The node that the read reaches. It is `undefined` when the read can reach each node (GRAPH.UNKNOWN). */
3322
+ readonly to: Id | undefined;
3323
+ /** `true` when only a lazy part reaches the read. An evaluation can then give a value without it (FACTS.LAZY). */
3324
+ readonly lazy: boolean;
3325
+ }
3326
+ /** One node of a graph, with its edges. `NodeInfo` of a schedule is such a node. */
3327
+ interface GraphNode<Id> {
3328
+ /** The edges to the nodes that the node reads. */
3329
+ readonly edges: readonly GraphEdge<Id>[];
3330
+ /** The side of the node. A node on the run side is a sink: no edge reaches it (SCHED.SIDE). The default is `derive`. */
3331
+ readonly side?: Side;
3332
+ }
3333
+ /**
3334
+ * A graph of nodes, by name. The order of the map is the order of the nodes in each answer. The function `graph` of
3335
+ * a schedule gives such a graph. An edge to a name that is not in the map, or to a sink, is not an edge of the
3336
+ * analysis.
3337
+ */
3338
+ type NodeGraph<Id> = ReadonlyMap<Id, GraphNode<Id>>;
3339
+ /** The options of an analysis. */
3340
+ interface GraphOptions {
3341
+ /**
3342
+ * `true`: the analysis keeps only the eager edges with a target node. Such a read occurs in each evaluation in
3343
+ * which each document around it gives a value (FACTS.LAZY). The default keeps each edge.
3344
+ */
3345
+ readonly eager?: boolean;
3346
+ }
3347
+ /** One static cycle of a graph (GRAPH.CYCLE). */
3348
+ interface GraphCycle<Id> {
3349
+ /** The nodes of the cycle, in the order of the graph. */
3350
+ readonly nodes: readonly Id[];
3351
+ /**
3352
+ * `true` when the eager edges with a target close the cycle. `false` when the cycle needs a lazy edge or an edge
3353
+ * without a target. The value of each node still comes from the demand (D31).
3354
+ */
3355
+ readonly certain: boolean;
3356
+ }
3357
+ /**
3358
+ * This function gives the strongly connected components of a graph of nodes (GRAPH.SCC), with the algorithm of
3359
+ * Tarjan. It keeps its own stack, thus a chain of 100000 nodes does not overflow the stack of the host.
3360
+ *
3361
+ * - Each component comes after each component that it reads: the deepest component comes first.
3362
+ * - A node that is on no cycle is a component of one node.
3363
+ * - The nodes of a component are in the order of the graph.
3364
+ *
3365
+ * @param graph - The nodes, each with its edges.
3366
+ * @param options - The option `eager` keeps only the eager edges with a target node.
3367
+ * @returns The components, deepest first.
3368
+ */
3369
+ export declare function components<Id>(graph: NodeGraph<Id>, options?: GraphOptions): readonly (readonly Id[])[];
3370
+ /**
3371
+ * This function gives the height of each node: the order of a push schedule (GRAPH.ORDER). A schedule that evaluates
3372
+ * the nodes from the lowest height up evaluates each node after each node that it reads, except on a cycle.
3373
+ *
3374
+ * - A node that reads no node outside its component has the height 0.
3375
+ * - Each other node is one higher than the highest node that it reads outside its component.
3376
+ * - The nodes of one component have one height.
3377
+ * - An edge without a target reads each node that is not a sink (GRAPH.UNKNOWN).
3378
+ *
3379
+ * @param graph - The nodes, each with its edges.
3380
+ * @param options - The option `eager` keeps only the eager edges with a target node.
3381
+ * @returns The height of each node, in the order of the graph.
3382
+ */
3383
+ export declare function heights<Id>(graph: NodeGraph<Id>, options?: GraphOptions): ReadonlyMap<Id, number>;
3384
+ /**
3385
+ * This function puts the nodes in layers by their heights, in linear time (GRAPH.LAYERS). The first layer has the
3386
+ * height 0. Two nodes of one layer read each other only inside one component. Thus a push schedule can evaluate the
3387
+ * components of one layer at the same time.
3388
+ *
3389
+ * @param graph - The nodes, each with its edges.
3390
+ * @param options - The option `eager` keeps only the eager edges with a target node.
3391
+ * @returns The layers, from the height 0 up. Each layer keeps the order of the graph.
3392
+ */
3393
+ export declare function nodeLayers<Id>(graph: NodeGraph<Id>, options?: GraphOptions): readonly (readonly Id[])[];
3394
+ /**
3395
+ * This function gives the nodes that a set of observed nodes needs (GRAPH.NECESSARY). These are the observed nodes,
3396
+ * and each node with a path of edges from them. A push schedule evaluates only these nodes. An observed name that is
3397
+ * not a node of the graph adds nothing.
3398
+ *
3399
+ * @param graph - The nodes, each with its edges.
3400
+ * @param observed - The nodes that the host shows or reads.
3401
+ * @param options - The option `eager` keeps only the eager edges with a target node.
3402
+ * @returns The necessary nodes, in the order of the graph.
3403
+ */
3404
+ export declare function necessary<Id>(graph: NodeGraph<Id>, observed: Iterable<Id>, options?: GraphOptions): ReadonlySet<Id>;
3405
+ /**
3406
+ * This function gives the static cycles of a graph (GRAPH.CYCLE): each component with two or more nodes, and each
3407
+ * node with an edge to itself. A cycle of the eager edges with a target is certain, and `check` or a host can report
3408
+ * it before a run. Another cycle is possible: an evaluation can skip a lazy read.
3409
+ *
3410
+ * - A component of all the edges that is also a component of the eager edges is one certain cycle.
3411
+ * - Each other component of all the edges is one possible cycle, and each certain cycle in it comes after it.
3412
+ * - A read can still fail before it occurs. Thus the demand of D31, not a static cycle, gives the value of each node.
3413
+ *
3414
+ * @param graph - The nodes, each with its edges.
3415
+ * @returns The cycles, deepest first.
3416
+ */
3417
+ export declare function cycles<Id>(graph: NodeGraph<Id>): readonly GraphCycle<Id>[];
3418
+ //#endregion
2170
3419
  //#region src/replay.d.ts
2171
3420
  /** One effect of a log: its address, its request and its outcome. */
2172
3421
  interface ReplayEntry {
@@ -2314,5 +3563,53 @@ export declare function typesOf(world: World): readonly (readonly Key[])[];
2314
3563
  */
2315
3564
  export declare function generate(world: World, options: GenerateOptions): unknown;
2316
3565
  //#endregion
2317
- export type { AgreeOptions, Agreement, Alias, AllOptions, Answer, AskOptions, Cap, CapsRule, CheckOptions, Classification, Closure, Code, CompileInput, CompiledEvaluator, CompiledPart, CompiledRunner, Construct, Context, Part as ContextPart, Definitions, DerefCode, DocParts, DocVisit, Edge, Effect, Envelope, ErrorCode, EvalError, EvalFn, EvalInput, EvalOptions, EvaluateOptions, Evaluator, ExtFn, Failed, FormulaProfile, GenerateOptions, Give, Header, Hop, HopBy, HostThing, Issue, Journal, Json, JsonRecord, KernelCode, Key, Kind, KindSource, LazyOp, Lookup, Machine, MachinePart, MergeConflict, MergePath, NamesSource, Namespace, Navigator, NearestOptions, OpFn, OrderProblem, Outcome, Part$1 as Part, PartInfo, Shape as PartShape, PartSlot, PartsSpec, Perform, Plan, PrepareOptions, Random, Recorder, RefUse, ReferenceOptions, ReplayEntry, ReplayLog, ReplayOptions, ReplaySettle, Resolution, ResolveCode, ResolveOptions, Result, Root, Run, RunCode, RunFn, RunInput, RunOptions, RunPart, Rung, Runner, Runtime, ScopeRule, Shape$1 as Shape, Side, Split, Step, StepSpec, Steps, StopSignal, Stored, Thing, Tier, TierInput, TierResult, TraceNode, TypeRef, Use, WalkInput, WalkOptions, WalkProblem, WalkResult, Walker, World, WorldEntry, WorldPart };
3566
+ //#region src/providers.d.ts
3567
+ /** The type that a provider reads, and the problems of the reading. Each problem tells what the type does not test. */
3568
+ interface TypeReading {
3569
+ readonly type: ValueType;
3570
+ readonly issues: readonly TypeIssue[];
3571
+ }
3572
+ /**
3573
+ * This function makes a value type from a JSON Schema (TYPE.SCHEMA). A host uses it for the type of a root, for
3574
+ * example the schema of a store for `world`. It reads this subset:
3575
+ *
3576
+ * - `type`: `null`, `boolean`, `number`, `integer` (as `number`), `string`, `object` and `array`, or a list of them.
3577
+ * - `properties`, `required` and `additionalProperties` give a record. `false` closes it, and a property that is not
3578
+ * in `required` is optional.
3579
+ * - `items` gives a list. `enum` and `const` give `one`. `anyOf` and `oneOf` give a union.
3580
+ *
3581
+ * The type holds each value that the schema accepts. Each keyword that the function does not read tests nothing, as
3582
+ * `unknown`, and the issues name it. Examples are `minimum`, `pattern` and `allOf`. A schema with `$ref` or `nullable`
3583
+ * reads as `unknown`, because these keywords can permit more values. A schema with more than one of `type`, `anyOf`
3584
+ * and `oneOf` gives the type of the first, and an issue for each other. The function does not throw.
3585
+ *
3586
+ * @param schema - The schema, as JSON.
3587
+ * @returns The type, and the problems of the reading with their keys in the schema.
3588
+ */
3589
+ export declare function typeFromSchema(schema: unknown): TypeReading;
3590
+ /** The options of `typeFromSamples`. */
3591
+ interface SampleOptions {
3592
+ /** `true`: the samples show each field, thus each record type is closed. The default is `false`. */
3593
+ readonly closed?: boolean;
3594
+ }
3595
+ /**
3596
+ * This function infers a value type from sample values (TYPE.SAMPLES), as a type provider of F# does. A host uses it
3597
+ * for the type of a root, for example from some events.
3598
+ *
3599
+ * - `null`, a truth value, a number and a text give their base types, not their values.
3600
+ * - The items of each list join into one type of items.
3601
+ * - All records join into one record with each key of the samples. A key that a record does not have is optional.
3602
+ * - Values of different forms give a union, as `join` gives. No samples give `never`.
3603
+ * - A value without a type of the kernel, for example a function, gives `unknown`.
3604
+ *
3605
+ * Each sample is a member of the type. A record is open, because samples do not show that a field cannot exist. With
3606
+ * `closed: true`, each record is closed, and a reference to a field that no sample has gives `#TYPE!`.
3607
+ *
3608
+ * @param values - The sample values.
3609
+ * @param options - `closed: true` closes each record type.
3610
+ * @returns The type.
3611
+ */
3612
+ export declare function typeFromSamples(values: readonly unknown[], options?: SampleOptions): ValueType;
3613
+ //#endregion
3614
+ export type { AgreeOptions, Agreement, Alias, AllOptions, Answer, AskOptions, Cap, CapsRule, CheckOptions, Classification, Closure, Code, CompileInput, CompiledEvaluator, CompiledPart, CompiledRunner, ConformOptions, ConformProbe, Construct, Context, Part as ContextPart, Definitions, DerefCode, DocFacts, DocParts, DocVisit, Domain, 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, Part$1 as Part, PartInfo, Shape as PartShape, PartSlot, PartType, PartsSpec, Perform, Plan, 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, Thing, Tier, TierInput, TierResult, TraceNode, TypeInput, TypeIssue, TypeProblem, TypeReading, TypeRef, TypeRule, Typed, Typing, Use, ValueType, VerifyOptions, WalkInput, WalkOptions, WalkProblem, WalkResult, Walker, World, WorldEntry, WorldPart };
2318
3615
  //# sourceMappingURL=index.d.ts.map