@mark1russell7/coeval 0.20.1 → 0.22.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
@@ -251,6 +251,235 @@ export declare function thrown(error: unknown, who: string): Failed;
251
251
  * @returns The text.
252
252
  */
253
253
  export declare function describe(value: unknown): string;
254
+ /**
255
+ * A value type: a set of values that a result can have, as a JSON term.
256
+ *
257
+ * - A text names a base type: `unknown`, `never`, a domain of the kernel (`null`, `undefined`, `bool`, `number`,
258
+ * `text`), or a domain of a language.
259
+ * - `list`: a list whose items have the type.
260
+ * - `record`: a plain record with the named fields. `optional` names the fields that can be absent. A `closed`
261
+ * record has no other fields. The other fields of an open record can hold each value.
262
+ * - `fn`: a function with the types of its parameters, and the type of its result (`to`).
263
+ * - `union`: a value of one of the types. An empty union holds no value.
264
+ * - `one`: one of the JSON values of the list.
265
+ *
266
+ * A term that is not in this list reads as `unknown` (TYPE.UNKNOWN). Thus a later version can add a term.
267
+ */
268
+ type ValueType = string | {
269
+ readonly list: ValueType;
270
+ } | {
271
+ readonly record: Readonly<Record<string, ValueType>>;
272
+ readonly optional?: readonly string[];
273
+ readonly closed?: boolean;
274
+ } | {
275
+ readonly fn: readonly ValueType[];
276
+ readonly to: ValueType;
277
+ } | {
278
+ readonly union: readonly ValueType[];
279
+ } | {
280
+ readonly one: readonly Json[];
281
+ };
282
+ /**
283
+ * A value domain: a base type of a language, with its membership test. A machine holds its domains by their names
284
+ * (`Machine.domains`). A value is a member of a domain only when the test of the domain and the test of each parent
285
+ * accept it (TYPE.MEMBER).
286
+ *
287
+ * A path does not follow a member of a domain as a reference (DEREF.COLLAPSE). Thus the test `is` must refuse each
288
+ * reference document.
289
+ */
290
+ interface Domain {
291
+ /**
292
+ * This function tells if a value is a member of the domain. It must be pure. A test that throws gives `false`.
293
+ *
294
+ * @param value - The value.
295
+ * @returns `true` for a member.
296
+ */
297
+ readonly is: (value: unknown) => boolean;
298
+ /** The names of the parents: the base types that hold each member of the domain. A base type fits each parent. */
299
+ readonly under?: readonly string[];
300
+ /** One sentence that tells what the domain holds. */
301
+ readonly summary?: string;
302
+ /**
303
+ * The value type of each step into a member, by its key, for example the field `x` of a point (TYPE.STEPS). The
304
+ * check of a path reads the steps of the domain first, then the steps of each parent. The language keeps them true:
305
+ * a step with the key into a member reaches a member of the type. A key without a type gives `unknown`.
306
+ */
307
+ readonly steps?: Readonly<Record<string, ValueType>>;
308
+ /**
309
+ * The codec of the members: it writes a member as JSON and reads it again (D40). A document holds a member as the
310
+ * standard extension `ext.domain`. A domain without a codec has no such document.
311
+ */
312
+ readonly codec?: DomainCodec;
313
+ /**
314
+ * The full list of the members of the domain, when the domain holds few values, for example `true` and `false` of
315
+ * `bool` (TYPE.FITS-FINITE). `fits` reads it: a base type with a list fits a type that holds each member of the list.
316
+ * The language keeps the list complete: each member of the domain is in the list. A value that fails a test of the
317
+ * domain does not count. The check reads a list of at most 64 values.
318
+ */
319
+ readonly values?: readonly unknown[];
320
+ /**
321
+ * Some members of the domain for the tests of `conforms`, for example `0` and `-1` of `number` (D99). The checks
322
+ * `truth` and `cover` add the samples of each domain to the palette. A sample that fails a test of a type does not
323
+ * count. The list is not a full list of the members, thus `fits` does not read it.
324
+ */
325
+ readonly samples?: readonly unknown[];
326
+ /**
327
+ * The covers of the domain (TYPE.FITS-COVER, D85). A cover is a list of domains under this domain, and its domains
328
+ * together hold each member of this domain. An example is a domain of negative numbers and a domain of the other
329
+ * numbers as a cover of `number`. `fits` reads it: a base type fits a union when each domain of a cover fits it.
330
+ *
331
+ * A split of a record also narrows a field of the domain to each domain of a cover (D90).
332
+ * The language keeps each cover true, and `fits` trusts it, as it trusts `values`. A cover that is empty, or that
333
+ * names this domain or a name that is not under it, does not count. `conforms` tests each cover from samples (D94).
334
+ */
335
+ readonly covers?: readonly (readonly string[])[];
336
+ }
337
+ /**
338
+ * The codec of a domain: it writes a member of the domain as JSON, and it reads the JSON again (D40). Both functions
339
+ * must be pure. `decode(encode(v))` must equal `v` by `sameValue` (EXT.ROUNDTRIP). The codec must give one JSON
340
+ * value for each member, thus the same value has the same document in each language (D12).
341
+ */
342
+ interface DomainCodec {
343
+ /**
344
+ * This function writes a member of the domain as JSON.
345
+ *
346
+ * @param value - A member of the domain.
347
+ * @returns The JSON of the member.
348
+ */
349
+ readonly encode: (value: unknown) => Json;
350
+ /**
351
+ * This function reads the JSON of a member again. It throws for JSON that does not write a member.
352
+ *
353
+ * @param data - The JSON that `encode` gave.
354
+ * @returns The member.
355
+ */
356
+ readonly decode: (data: Json) => unknown;
357
+ }
358
+ /** A problem of a value type: the keys from the root of the term to the problem, and the reason. */
359
+ interface TypeIssue {
360
+ readonly at: readonly Key[];
361
+ readonly reason: string;
362
+ }
363
+ /**
364
+ * The domains of the kernel. `unknown` and `never` are not domains: they are the top and the bottom of the types.
365
+ * A machine that does not name one of these domains gets it from this table.
366
+ */
367
+ export declare const STD_DOMAINS: Readonly<Record<string, Domain>>;
368
+ /**
369
+ * This function tells if a value is a member of a value type (TYPE.MEMBER). It is the membership test that a cast
370
+ * at run time uses.
371
+ *
372
+ * - Each value is a member of `unknown`, and no value is a member of `never`.
373
+ * - A value is a member of a domain when the test `is` of the domain and of each parent accepts it.
374
+ * - A list, a record, a union and `one` test their values at each depth.
375
+ * - A function type tests only that the value is a function. Its parameters need a test at each call.
376
+ *
377
+ * The function does not throw. A term that is not a value type, or a base type without a domain, holds each value.
378
+ *
379
+ * @param value - The value.
380
+ * @param type - The value type.
381
+ * @param domains - The domains of the machine. A domain of the kernel that the table does not name comes from `STD_DOMAINS`.
382
+ * @returns `true` when the value is a member of the type.
383
+ */
384
+ export declare function member(value: unknown, type: ValueType, domains?: Readonly<Record<string, Domain>>): boolean;
385
+ /**
386
+ * This function tells if each value of the type `found` can be where the type `expected` must be (TYPE.FITS). Each
387
+ * check of a type uses it.
388
+ *
389
+ * - `unknown` fits each type, and each type fits `unknown` (TYPE.UNKNOWN). This is the gradual top.
390
+ * - `never` fits each type. Only `never`, an empty union and an empty `one` fit `never`.
391
+ * - A union fits when each of its types fits. A type fits a union when it fits one of its types.
392
+ * - `one` fits when each of its values is a member of `expected`.
393
+ * - A base type fits itself and each parent of its domain, through each level (TYPE.DOMAIN).
394
+ * - A list fits a list when its items fit.
395
+ * - A record fits a record with fewer fields. A field that `expected` needs is not optional in `found`, and each field
396
+ * fits. Only a closed record fits a closed record. An open record without an optional field fits only when that
397
+ * field is `unknown`.
398
+ * - A function fits when it has the same or fewer parameters, each expected parameter fits its parameter, and its
399
+ * result fits.
400
+ * - The finite rule comes after these rules (TYPE.FITS-FINITE). A type with at most 64 members fits when each member
401
+ * is a member of `expected`. Thus `bool` fits `{ "one": [true, false] }`.
402
+ * - A base type has few members when its domain or a parent declares `values`, as `null`, `undefined` and `bool` do.
403
+ * A union, a `one`, a closed record of such types and a list of `never` also have few members.
404
+ * - The cover rule comes next (TYPE.FITS-COVER, D85). A base type fits a union or a `one` when each domain of a cover
405
+ * fits. The cover is in `covers` of a domain of its line. Each domain of a cover is under the covered
406
+ * domain. Thus a cover of `number` by `neg` and `nonneg` gives `number` a fit against `neg | nonneg`.
407
+ * - The split rule comes last (D84). An open record, or a closed record with more than 64 members, splits a field with
408
+ * few members over a union. A closed record also splits over a `one`. Each record of the split narrows the field to
409
+ * one member, and each record must fit.
410
+ * Thus `{ "record": { "a": "bool" } }` fits a union of a record for each value of `a`.
411
+ * - A split also narrows a field of a record in a field, by its path (TYPE.FITS-PATH, D89). The fields of the record
412
+ * split first, then the paths of each next depth, in the order of the keys. A path goes into a record without a
413
+ * finite list. Thus `{a: {x: bool}}` fits the union of `{a: {x: true}}` and `{a: {x: false}}`.
414
+ * - A type split comes after each value split (TYPE.FITS-SPLIT-TYPE, D90). A field of a base type with a valid cover in
415
+ * its line splits into the domains of a cover. A field of a union without a finite list splits into its
416
+ * members. A case that does not fit splits again at its path, by the same rules. A base type there uses only the
417
+ * covers of its own domain. Thus `{a: number}` fits `{a: neg} | {a: nonneg}` when `neg` and `nonneg` cover `number`.
418
+ * - A field with more than one valid cover tries each cover until one fits (TYPE.FITS-SPLIT-COVERS, D102). The order
419
+ * is the order of the line, then the order of the covers of each domain.
420
+ *
421
+ * The relation is sound: a member of `found` is a member of `expected` when no `unknown` is in the types
422
+ * (TYPE.FITS-SOUND). The finite rule trusts `values`, and the cover rule trusts `covers`. Thus a list without a member
423
+ * or a false cover makes the relation unsound for that domain.
424
+ *
425
+ * The relation is not complete. A split builds at most 64 records, with each split inside its work at each depth. The
426
+ * failed tries of covers take from these 64 records too. A domain without `values` gets no finite rule, and
427
+ * neither does a type with more than 64 members that is not a record. The cover rule tests at most 64 domains of
428
+ * covers. The function does not throw.
429
+ *
430
+ * @param found - The type that a part has.
431
+ * @param expected - The type that the position needs.
432
+ * @param domains - The domains of the machine. A domain of the kernel that the table does not name comes from `STD_DOMAINS`.
433
+ * @returns `true` when `found` fits `expected`.
434
+ */
435
+ export declare function fits(found: ValueType, expected: ValueType, domains?: Readonly<Record<string, Domain>>): boolean;
436
+ /**
437
+ * This function gives the join of two value types (TYPE.JOIN): a type that holds each member of both types. The check
438
+ * of a type uses it for the branches of an `if` and for the items of a list.
439
+ *
440
+ * - `unknown` with each type gives `unknown`, and `never` with a type gives that type.
441
+ * - When one type fits the other by the strict form of `fits`, the join is the wider type. The strict form reads
442
+ * `unknown` only as the top.
443
+ * - Two lists give a list of the join of their items.
444
+ * - Two records give a record of the join of their common fields. A field of one closed record is optional in the
445
+ * join of two closed records. The join of an open record leaves out the fields that only one record has.
446
+ * - Each other pair gives a union. The union puts the values of `one` together and leaves out each member that fits
447
+ * another member.
448
+ *
449
+ * 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
450
+ * function does not throw.
451
+ *
452
+ * @param a - The first type.
453
+ * @param b - The second type.
454
+ * @param domains - The domains of the machine. A domain of the kernel that the table does not name comes from `STD_DOMAINS`.
455
+ * @returns The join.
456
+ */
457
+ export declare function join(a: ValueType, b: ValueType, domains?: Readonly<Record<string, Domain>>): ValueType;
458
+ /**
459
+ * This function gives the text of a value type (TYPE.TEXT), for the reason of an issue. The function does not throw.
460
+ *
461
+ * - A base type gives its name.
462
+ * - `list<T>` is a list, `{a: T, b?: U}` is a closed record, and `{a: T, ...}` is an open record.
463
+ * - `(T, U) => V` is a function, and `T | U` is a union.
464
+ * - `one` gives its values as JSON, and an empty union gives `never`.
465
+ * - A term that is not a value type gives `unknown`.
466
+ *
467
+ * The text shows at most 8 values of `one`, and it cuts a long value.
468
+ *
469
+ * @param type - The value type.
470
+ * @returns The text.
471
+ */
472
+ export declare function typeText(type: ValueType): string;
473
+ /**
474
+ * This function lists the problems of a value type (TYPE.ISSUES). A problem is a term that is not a value type, a
475
+ * base type without a domain, or a term that is too deep. `fits` and `member` read each such term as `unknown`.
476
+ * Thus a check that reads a type from a contract can report it first.
477
+ *
478
+ * @param type - The value type, as JSON.
479
+ * @param domains - The domains of the machine. A domain of the kernel that the table does not name comes from `STD_DOMAINS`.
480
+ * @returns The problems. A term comes before its parts, and the parts keep their order.
481
+ */
482
+ export declare function typeIssues(type: unknown, domains?: Readonly<Record<string, Domain>>): readonly TypeIssue[];
254
483
  /**
255
484
  * The brand of a host thing: an object of the host that answers the steps of a path itself. The brand is a
256
485
  * global symbol, thus two copies of the kernel in one program know the things of each other.
@@ -415,8 +644,36 @@ interface WalkInput {
415
644
  */
416
645
  readonly visit?: (key: Key, thing: Thing) => void;
417
646
  }
418
- /** A walker: the code of the verb `step` of a kind of step documents. */
419
- type Walker = (input: WalkInput) => WalkResult;
647
+ /** The input of the type rule of a walker: the data of the step document, and the type of the thing before the step. */
648
+ interface WalkTypeInput {
649
+ /** The value of the step document. A step document with parts has no type rule, thus this value holds no part. */
650
+ readonly data: Json;
651
+ /** The type of the thing that the path reached before this step. */
652
+ readonly here: ValueType;
653
+ }
654
+ /**
655
+ * A walker: the code of the verb `step` of a kind of step documents. A plain function is a walker.
656
+ *
657
+ * A walker can hold a type rule in its field `type` (TYPE.WALKER, D121). The rule gives the type of each thing that
658
+ * the walker reaches from a thing of the type `here`. It must be sound, as the rule of an evaluator. A walker
659
+ * without a rule reaches the type `unknown`. A host gives the rule with `Object.assign(walker, { type })`.
660
+ */
661
+ interface Walker {
662
+ /**
663
+ * This function answers the step document on the thing that the path reached.
664
+ *
665
+ * @param input - The data of the step document, the thing before the step and the ladder.
666
+ * @returns What the step reached, or the reason of a failure.
667
+ */
668
+ (input: WalkInput): WalkResult;
669
+ /**
670
+ * This optional function gives the type of what the walker reaches.
671
+ *
672
+ * @param input - The data of the step document and the type before the step.
673
+ * @returns The type of each thing that the walker reaches.
674
+ */
675
+ readonly type?: (input: WalkTypeInput) => ValueType;
676
+ }
420
677
  /**
421
678
  * What a resolution needs: the world, and the code of the `deref` evaluators and of the walkers.
422
679
  *
@@ -532,235 +789,6 @@ export declare function resolve(nav: Navigator, ctx: Context, path: readonly unk
532
789
  * @returns The value.
533
790
  */
534
791
  export declare function valueOfThing(thing: Thing): unknown;
535
- /**
536
- * A value type: a set of values that a result can have, as a JSON term.
537
- *
538
- * - A text names a base type: `unknown`, `never`, a domain of the kernel (`null`, `undefined`, `bool`, `number`,
539
- * `text`), or a domain of a language.
540
- * - `list`: a list whose items have the type.
541
- * - `record`: a plain record with the named fields. `optional` names the fields that can be absent. A `closed`
542
- * record has no other fields. The other fields of an open record can hold each value.
543
- * - `fn`: a function with the types of its parameters, and the type of its result (`to`).
544
- * - `union`: a value of one of the types. An empty union holds no value.
545
- * - `one`: one of the JSON values of the list.
546
- *
547
- * A term that is not in this list reads as `unknown` (TYPE.UNKNOWN). Thus a later version can add a term.
548
- */
549
- type ValueType = string | {
550
- readonly list: ValueType;
551
- } | {
552
- readonly record: Readonly<Record<string, ValueType>>;
553
- readonly optional?: readonly string[];
554
- readonly closed?: boolean;
555
- } | {
556
- readonly fn: readonly ValueType[];
557
- readonly to: ValueType;
558
- } | {
559
- readonly union: readonly ValueType[];
560
- } | {
561
- readonly one: readonly Json[];
562
- };
563
- /**
564
- * A value domain: a base type of a language, with its membership test. A machine holds its domains by their names
565
- * (`Machine.domains`). A value is a member of a domain only when the test of the domain and the test of each parent
566
- * accept it (TYPE.MEMBER).
567
- *
568
- * A path does not follow a member of a domain as a reference (DEREF.COLLAPSE). Thus the test `is` must refuse each
569
- * reference document.
570
- */
571
- interface Domain {
572
- /**
573
- * This function tells if a value is a member of the domain. It must be pure. A test that throws gives `false`.
574
- *
575
- * @param value - The value.
576
- * @returns `true` for a member.
577
- */
578
- readonly is: (value: unknown) => boolean;
579
- /** The names of the parents: the base types that hold each member of the domain. A base type fits each parent. */
580
- readonly under?: readonly string[];
581
- /** One sentence that tells what the domain holds. */
582
- readonly summary?: string;
583
- /**
584
- * The value type of each step into a member, by its key, for example the field `x` of a point (TYPE.STEPS). The
585
- * check of a path reads the steps of the domain first, then the steps of each parent. The language keeps them true:
586
- * a step with the key into a member reaches a member of the type. A key without a type gives `unknown`.
587
- */
588
- readonly steps?: Readonly<Record<string, ValueType>>;
589
- /**
590
- * The codec of the members: it writes a member as JSON and reads it again (D40). A document holds a member as the
591
- * standard extension `ext.domain`. A domain without a codec has no such document.
592
- */
593
- readonly codec?: DomainCodec;
594
- /**
595
- * The full list of the members of the domain, when the domain holds few values, for example `true` and `false` of
596
- * `bool` (TYPE.FITS-FINITE). `fits` reads it: a base type with a list fits a type that holds each member of the list.
597
- * The language keeps the list complete: each member of the domain is in the list. A value that fails a test of the
598
- * domain does not count. The check reads a list of at most 64 values.
599
- */
600
- readonly values?: readonly unknown[];
601
- /**
602
- * Some members of the domain for the tests of `conforms`, for example `0` and `-1` of `number` (D99). The checks
603
- * `truth` and `cover` add the samples of each domain to the palette. A sample that fails a test of a type does not
604
- * count. The list is not a full list of the members, thus `fits` does not read it.
605
- */
606
- readonly samples?: readonly unknown[];
607
- /**
608
- * The covers of the domain (TYPE.FITS-COVER, D85). A cover is a list of domains under this domain, and its domains
609
- * together hold each member of this domain. An example is a domain of negative numbers and a domain of the other
610
- * numbers as a cover of `number`. `fits` reads it: a base type fits a union when each domain of a cover fits it.
611
- *
612
- * A split of a record also narrows a field of the domain to each domain of a cover (D90).
613
- * The language keeps each cover true, and `fits` trusts it, as it trusts `values`. A cover that is empty, or that
614
- * names this domain or a name that is not under it, does not count. `conforms` tests each cover from samples (D94).
615
- */
616
- readonly covers?: readonly (readonly string[])[];
617
- }
618
- /**
619
- * The codec of a domain: it writes a member of the domain as JSON, and it reads the JSON again (D40). Both functions
620
- * must be pure. `decode(encode(v))` must equal `v` by `sameValue` (EXT.ROUNDTRIP). The codec must give one JSON
621
- * value for each member, thus the same value has the same document in each language (D12).
622
- */
623
- interface DomainCodec {
624
- /**
625
- * This function writes a member of the domain as JSON.
626
- *
627
- * @param value - A member of the domain.
628
- * @returns The JSON of the member.
629
- */
630
- readonly encode: (value: unknown) => Json;
631
- /**
632
- * This function reads the JSON of a member again. It throws for JSON that does not write a member.
633
- *
634
- * @param data - The JSON that `encode` gave.
635
- * @returns The member.
636
- */
637
- readonly decode: (data: Json) => unknown;
638
- }
639
- /** A problem of a value type: the keys from the root of the term to the problem, and the reason. */
640
- interface TypeIssue {
641
- readonly at: readonly Key[];
642
- readonly reason: string;
643
- }
644
- /**
645
- * The domains of the kernel. `unknown` and `never` are not domains: they are the top and the bottom of the types.
646
- * A machine that does not name one of these domains gets it from this table.
647
- */
648
- export declare const STD_DOMAINS: Readonly<Record<string, Domain>>;
649
- /**
650
- * This function tells if a value is a member of a value type (TYPE.MEMBER). It is the membership test that a cast
651
- * at run time uses.
652
- *
653
- * - Each value is a member of `unknown`, and no value is a member of `never`.
654
- * - A value is a member of a domain when the test `is` of the domain and of each parent accepts it.
655
- * - A list, a record, a union and `one` test their values at each depth.
656
- * - A function type tests only that the value is a function. Its parameters need a test at each call.
657
- *
658
- * The function does not throw. A term that is not a value type, or a base type without a domain, holds each value.
659
- *
660
- * @param value - The value.
661
- * @param type - The value type.
662
- * @param domains - The domains of the machine. A domain of the kernel that the table does not name comes from `STD_DOMAINS`.
663
- * @returns `true` when the value is a member of the type.
664
- */
665
- export declare function member(value: unknown, type: ValueType, domains?: Readonly<Record<string, Domain>>): boolean;
666
- /**
667
- * This function tells if each value of the type `found` can be where the type `expected` must be (TYPE.FITS). Each
668
- * check of a type uses it.
669
- *
670
- * - `unknown` fits each type, and each type fits `unknown` (TYPE.UNKNOWN). This is the gradual top.
671
- * - `never` fits each type. Only `never`, an empty union and an empty `one` fit `never`.
672
- * - A union fits when each of its types fits. A type fits a union when it fits one of its types.
673
- * - `one` fits when each of its values is a member of `expected`.
674
- * - A base type fits itself and each parent of its domain, through each level (TYPE.DOMAIN).
675
- * - A list fits a list when its items fit.
676
- * - A record fits a record with fewer fields. A field that `expected` needs is not optional in `found`, and each field
677
- * fits. Only a closed record fits a closed record. An open record without an optional field fits only when that
678
- * field is `unknown`.
679
- * - A function fits when it has the same or fewer parameters, each expected parameter fits its parameter, and its
680
- * result fits.
681
- * - The finite rule comes after these rules (TYPE.FITS-FINITE). A type with at most 64 members fits when each member
682
- * is a member of `expected`. Thus `bool` fits `{ "one": [true, false] }`.
683
- * - A base type has few members when its domain or a parent declares `values`, as `null`, `undefined` and `bool` do.
684
- * A union, a `one`, a closed record of such types and a list of `never` also have few members.
685
- * - The cover rule comes next (TYPE.FITS-COVER, D85). A base type fits a union or a `one` when each domain of a cover
686
- * fits. The cover is in `covers` of a domain of its line. Each domain of a cover is under the covered
687
- * domain. Thus a cover of `number` by `neg` and `nonneg` gives `number` a fit against `neg | nonneg`.
688
- * - The split rule comes last (D84). An open record, or a closed record with more than 64 members, splits a field with
689
- * few members over a union. A closed record also splits over a `one`. Each record of the split narrows the field to
690
- * one member, and each record must fit.
691
- * Thus `{ "record": { "a": "bool" } }` fits a union of a record for each value of `a`.
692
- * - A split also narrows a field of a record in a field, by its path (TYPE.FITS-PATH, D89). The fields of the record
693
- * split first, then the paths of each next depth, in the order of the keys. A path goes into a record without a
694
- * finite list. Thus `{a: {x: bool}}` fits the union of `{a: {x: true}}` and `{a: {x: false}}`.
695
- * - A type split comes after each value split (TYPE.FITS-SPLIT-TYPE, D90). A field of a base type with a valid cover in
696
- * its line splits into the domains of a cover. A field of a union without a finite list splits into its
697
- * members. A case that does not fit splits again at its path, by the same rules. A base type there uses only the
698
- * covers of its own domain. Thus `{a: number}` fits `{a: neg} | {a: nonneg}` when `neg` and `nonneg` cover `number`.
699
- * - A field with more than one valid cover tries each cover until one fits (TYPE.FITS-SPLIT-COVERS, D102). The order
700
- * is the order of the line, then the order of the covers of each domain.
701
- *
702
- * The relation is sound: a member of `found` is a member of `expected` when no `unknown` is in the types
703
- * (TYPE.FITS-SOUND). The finite rule trusts `values`, and the cover rule trusts `covers`. Thus a list without a member
704
- * or a false cover makes the relation unsound for that domain.
705
- *
706
- * The relation is not complete. A split builds at most 64 records, with each split inside its work at each depth. The
707
- * failed tries of covers take from these 64 records too. A domain without `values` gets no finite rule, and
708
- * neither does a type with more than 64 members that is not a record. The cover rule tests at most 64 domains of
709
- * covers. The function does not throw.
710
- *
711
- * @param found - The type that a part has.
712
- * @param expected - The type that the position needs.
713
- * @param domains - The domains of the machine. A domain of the kernel that the table does not name comes from `STD_DOMAINS`.
714
- * @returns `true` when `found` fits `expected`.
715
- */
716
- export declare function fits(found: ValueType, expected: ValueType, domains?: Readonly<Record<string, Domain>>): boolean;
717
- /**
718
- * This function gives the join of two value types (TYPE.JOIN): a type that holds each member of both types. The check
719
- * of a type uses it for the branches of an `if` and for the items of a list.
720
- *
721
- * - `unknown` with each type gives `unknown`, and `never` with a type gives that type.
722
- * - When one type fits the other by the strict form of `fits`, the join is the wider type. The strict form reads
723
- * `unknown` only as the top.
724
- * - Two lists give a list of the join of their items.
725
- * - Two records give a record of the join of their common fields. A field of one closed record is optional in the
726
- * join of two closed records. The join of an open record leaves out the fields that only one record has.
727
- * - Each other pair gives a union. The union puts the values of `one` together and leaves out each member that fits
728
- * another member.
729
- *
730
- * 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
731
- * function does not throw.
732
- *
733
- * @param a - The first type.
734
- * @param b - The second type.
735
- * @param domains - The domains of the machine. A domain of the kernel that the table does not name comes from `STD_DOMAINS`.
736
- * @returns The join.
737
- */
738
- export declare function join(a: ValueType, b: ValueType, domains?: Readonly<Record<string, Domain>>): ValueType;
739
- /**
740
- * This function gives the text of a value type (TYPE.TEXT), for the reason of an issue. The function does not throw.
741
- *
742
- * - A base type gives its name.
743
- * - `list<T>` is a list, `{a: T, b?: U}` is a closed record, and `{a: T, ...}` is an open record.
744
- * - `(T, U) => V` is a function, and `T | U` is a union.
745
- * - `one` gives its values as JSON, and an empty union gives `never`.
746
- * - A term that is not a value type gives `unknown`.
747
- *
748
- * The text shows at most 8 values of `one`, and it cuts a long value.
749
- *
750
- * @param type - The value type.
751
- * @returns The text.
752
- */
753
- export declare function typeText(type: ValueType): string;
754
- /**
755
- * This function lists the problems of a value type (TYPE.ISSUES). A problem is a term that is not a value type, a
756
- * base type without a domain, or a term that is too deep. `fits` and `member` read each such term as `unknown`.
757
- * Thus a check that reads a type from a contract can report it first.
758
- *
759
- * @param type - The value type, as JSON.
760
- * @param domains - The domains of the machine. A domain of the kernel that the table does not name comes from `STD_DOMAINS`.
761
- * @returns The problems. A term comes before its parts, and the parts keep their order.
762
- */
763
- export declare function typeIssues(type: unknown, domains?: Readonly<Record<string, Domain>>): readonly TypeIssue[];
764
792
  /** The two sides of evaluation. `derive` is pure. `run` causes effects in order. */
765
793
  type Side = "derive" | "run";
766
794
  /**
@@ -905,12 +933,20 @@ interface LazyRule {
905
933
  * - `lazy`: the parts that an evaluation can skip and still give a value.
906
934
  * - `reads`: the roots that the code of the kind resolves as a whole, with the path of one root. The static facts
907
935
  * give a read of each root at each document of the kind (D44). The tree node reads `self` this way.
936
+ * - `effects`: the effects that the code of `eval` can cause, in the form of the field `effects` of a kind (D27). In
937
+ * the answer of the hook `facts`, it gives the effects of the code of a name. The contract of a kind does not
938
+ * describe an own entry for another evaluator, thus only the hook can give its effects (CAP.OWN-EFFECTS, D118).
939
+ * - `drives`: the parts that the code of a runner evaluates itself, without a wait, in the form of the lazy rules. A
940
+ * step under such a part cannot wait for the host. The check of a run then refuses a part that can wait there
941
+ * (RUN.DRIVES, D119). Without `drives`, the check assumes that the runner passes each wait of its parts through.
908
942
  */
909
943
  interface KindFacts {
910
944
  readonly pure?: boolean;
911
945
  readonly volatile?: boolean;
912
946
  readonly lazy?: readonly LazyRule[];
913
947
  readonly reads?: readonly Root[];
948
+ readonly effects?: "type" | readonly string[];
949
+ readonly drives?: readonly LazyRule[];
914
950
  }
915
951
  /**
916
952
  * The declaration of one attribute of the nodes of a kind (D42). The last two rungs of the ladder of an attribute
@@ -924,6 +960,8 @@ interface KindFacts {
924
960
  * - `default`: the term that gives the value when no rung before it answers and the declaration has no fold.
925
961
  * - `circular`: a cycle of this attribute gives its fixed point, not `#CYCLE!` (TREE.CIRCULAR, D113). Only a cycle
926
962
  * whose attributes each declare `circular` gives a fixed point.
963
+ * - `collect`: the value of a node without an answer of the first four rungs and without a fold. The node combines
964
+ * the contributions of each node of its subtree (TREE.COLLECT, D122).
927
965
  */
928
966
  interface AttributeDeclaration {
929
967
  readonly copy?: boolean;
@@ -933,7 +971,35 @@ interface AttributeDeclaration {
933
971
  };
934
972
  readonly default?: Json;
935
973
  readonly circular?: CircularDeclaration;
974
+ readonly collect?: CollectDeclaration;
936
975
  }
976
+ /**
977
+ * The declaration `collect` of an attribute (TREE.COLLECT, D122). The node of the attribute visits each node of its
978
+ * subtree. It visits the node itself first. Then it visits the nodes in its list `children`, in the order of the list.
979
+ *
980
+ * - `{ unit, combine }`: the collection starts with the term `unit`. The term `combine` then adds the contribution
981
+ * of each node, with the names `acc` and `item`. A node contributes when its kind has an equation for the
982
+ * attribute in `tree.contributes`.
983
+ * - `"names"`: the registry of binding names. Its value is a record from the header name of each node to its node
984
+ * (TREE.NAMED). Two nodes with one name give `#VALUE!` at the read of the registry.
985
+ */
986
+ type CollectDeclaration = {
987
+ readonly unit: Json;
988
+ readonly combine: Json;
989
+ } | "names";
990
+ /** A declaration `collect` that the kit can use, or the reason of a bad declaration (D122). */
991
+ type CollectRule = {
992
+ readonly ok: true;
993
+ readonly names: true;
994
+ } | {
995
+ readonly ok: true;
996
+ readonly names: false;
997
+ readonly unit: Json;
998
+ readonly combine: Json;
999
+ } | {
1000
+ readonly ok: false;
1001
+ readonly reason: string;
1002
+ };
937
1003
  /**
938
1004
  * The declaration `circular` of an attribute (TREE.CIRCULAR, D113). The attribute that a cycle reaches first leads it.
939
1005
  * The leader evaluates again until no value of the cycle changes.
@@ -965,6 +1031,14 @@ type CircularRule = {
965
1031
  * @returns The start value and the limit, or the reason when the declaration has no correct form.
966
1032
  */
967
1033
  export declare function circularOf(declared: unknown): CircularRule;
1034
+ /**
1035
+ * This function reads the declaration `collect` of an attribute (D122). The tree kit, the reference, `check` and the
1036
+ * graph of attribute instances read it with this one function.
1037
+ *
1038
+ * @param declared - The value of the field `collect`.
1039
+ * @returns The rule of the collection, or the reason when the declaration has no correct form.
1040
+ */
1041
+ export declare function collectOf(declared: unknown): CollectRule;
968
1042
  /**
969
1043
  * The tree contract of a kind (D42): the equations of the attributes of its nodes. Each equation is a document that
970
1044
  * evaluates with the node as `self` and without capabilities. A bare equation gets the type `of` of the parts of the
@@ -974,12 +1048,70 @@ export declare function circularOf(declared: unknown): CircularRule;
974
1048
  * - `down`: the attributes of each child of the node. `self` is this node. An equation sees the names `child`,
975
1049
  * `index` and `prev` (TREE.DOWN).
976
1050
  * - `attributes`: the declarations of the attributes of the node, for the rungs `copy` and `default`.
1051
+ * - `contributes`: the contribution of the node to each collection of an attribute (TREE.COLLECT, D122). An
1052
+ * equation sees no names.
1053
+ * - `at`: the attributes with parameters of the node (TREE.AT, D124). Only the step `tree.at` reads them, and the
1054
+ * equation sees each parameter as a name.
977
1055
  */
978
1056
  interface TreeContract {
979
1057
  readonly equations?: Readonly<Record<string, Json>>;
980
1058
  readonly down?: Readonly<Record<string, Json>>;
981
1059
  readonly attributes?: Readonly<Record<string, AttributeDeclaration>>;
1060
+ readonly contributes?: Readonly<Record<string, Json>>;
1061
+ readonly at?: Readonly<Record<string, AtEquation>>;
1062
+ }
1063
+ /**
1064
+ * An attribute with parameters (TREE.AT, D124), as `paramAttr` in Kiama. The step `tree.at` gives the arguments. The
1065
+ * equation evaluates with the node as `self`, and it sees each parameter as a name, for example `names.width`.
1066
+ */
1067
+ interface AtEquation {
1068
+ /** The names of the parameters. The step gives an argument for each of them, and no other argument. */
1069
+ readonly params: readonly string[];
1070
+ readonly equation: Json;
982
1071
  }
1072
+ /** An entry of `tree.at` that the kit can use, or the reason of a bad entry (D124). */
1073
+ type AtRule = {
1074
+ readonly ok: true;
1075
+ readonly params: readonly string[];
1076
+ readonly equation: Json;
1077
+ } | {
1078
+ readonly ok: false;
1079
+ readonly reason: string;
1080
+ };
1081
+ /**
1082
+ * This function reads an entry of the table `tree.at` (D124). The tree kit, the reference, `check` and the graph of
1083
+ * attribute instances read it with this one function.
1084
+ *
1085
+ * @param declared - The entry.
1086
+ * @returns The rule, or the reason when the entry has no correct form.
1087
+ */
1088
+ export declare function atRuleOf(declared: unknown): AtRule;
1089
+ /** The arguments of a step `tree.at` (D124): the names of the equation and their key, or the reason of bad arguments. */
1090
+ type AtArgs = {
1091
+ readonly ok: true;
1092
+ readonly names: Readonly<Record<string, Json>>;
1093
+ readonly key: string;
1094
+ } | {
1095
+ readonly ok: false;
1096
+ readonly reason: string;
1097
+ };
1098
+ /**
1099
+ * This function examines the arguments of a step `tree.at` (D124). The step gives an argument for each parameter, and
1100
+ * no other argument. Each argument is JSON data. The key is the text of `argsKey`, thus two equal arguments give one key.
1101
+ *
1102
+ * @param params - The parameters of the attribute.
1103
+ * @param args - The field `args` of the step.
1104
+ * @returns The names of the equation and the key, or the reason.
1105
+ */
1106
+ export declare function atArgsOf(params: readonly string[], args: unknown): AtArgs;
1107
+ /**
1108
+ * This function gives the key of a JSON value (D124). The fields of a record are in the order of their names. Two
1109
+ * values have the same key only when they are equal by DOC.EQUALS, thus `-0` and `0` have different keys.
1110
+ *
1111
+ * @param value - The value.
1112
+ * @returns The JSON text, or `undefined` for a value that is not JSON data: a number that is not finite, a host value or a cycle.
1113
+ */
1114
+ export declare function argsKey(value: unknown): string | undefined;
983
1115
  /**
984
1116
  * This function gives the type of a bare equation of a kind (D42). It is the type `of` of the shape of its parts, or
985
1117
  * else the type `of` of the shape `rest` of a record. The plan, the reference and `check` read it with this one function.
@@ -3082,6 +3214,10 @@ interface AttributeAnswer {
3082
3214
  * A new plan gives new arrays. Thus a host keeps its cells by the identity of `place` and by `attribute`.
3083
3215
  * A host that keeps its cells by the keys of `place` can give the answer of another node or a stale answer.
3084
3216
  *
3217
+ * An attribute with parameters gets one cell for each key of its arguments (TREE.AT-CELL, D124). Its `place` is a
3218
+ * second array with the same keys, one for each key of a node. Its `attribute` is the JSON text of the name and the
3219
+ * arguments, for example `["height",{"width":200}]`.
3220
+ *
3085
3221
  * The function gives the answer of `compute`, or a kept answer. A host with signals gives a computed signal: a change
3086
3222
  * of its store then makes only the attributes that read the store compute again. Each demand gives a new `compute`, and
3087
3223
  * a cell that computes again uses the last one.
@@ -3286,7 +3422,9 @@ interface EffectsOptions {
3286
3422
  *
3287
3423
  * The result covers each effect that an evaluation or a run gives the host (CAP.EFFECTS-SOUND). A procedure value keeps
3288
3424
  * the capabilities of the document that made it, thus the effects of its body count at the body (CAP.LATENT). The
3289
- * contract describes the code of its kind. The code of an own entry for another evaluator is outside the result.
3425
+ * contract describes the code of its kind. The contract does not describe the code of an own entry for another
3426
+ * evaluator. The answer of the hook `facts` for that code gives its effects (CAP.OWN-EFFECTS, D118). Without an
3427
+ * answer, its effects are outside the result.
3290
3428
  *
3291
3429
  * @param machine - The world and its contracts, and the hook `permits`.
3292
3430
  * @param doc - The document, as JSON.
@@ -4632,6 +4770,8 @@ interface AttributeVertex {
4632
4770
  readonly type: string;
4633
4771
  /** `true` when the kind of the node declares the attribute `circular` (TREE.CIRCULAR-CHECK). Else the field is absent. */
4634
4772
  readonly circular?: true;
4773
+ /** The arguments of an instance of an attribute with parameters (TREE.AT-CHECK). Else the field is absent. */
4774
+ readonly args?: Readonly<Record<string, Json>>;
4635
4775
  }
4636
4776
  /** One read of an attribute by the code of another attribute (D107). */
4637
4777
  interface AttributeEdge {
@@ -4957,11 +5097,14 @@ interface TypeReading {
4957
5097
  * - `properties`, `required` and `additionalProperties` give a record. `false` closes it, and a property that is not
4958
5098
  * in `required` is optional.
4959
5099
  * - `items` gives a list. `enum` and `const` give `one`. `anyOf` and `oneOf` give a union.
5100
+ * - `$ref` reads a definition in `$defs` or `definitions` of the same schema (TYPE.SCHEMA-REF). Another reference, a
5101
+ * missing definition and a reference in a cycle read as `unknown`.
5102
+ * - `allOf` and the other keywords of a schema give the meet of their types (TYPE.SCHEMA-ALLOF). Records merge their
5103
+ * fields, and a closed part keeps the merge closed.
4960
5104
  *
4961
5105
  * The type holds each value that the schema accepts. Each keyword that the function does not read tests nothing, as
4962
- * `unknown`, and the issues name it. Examples are `minimum`, `pattern` and `allOf`. A schema with `$ref` or `nullable`
4963
- * reads as `unknown`, because these keywords can permit more values. A schema with more than one of `type`, `anyOf`
4964
- * and `oneOf` gives the type of the first, and an issue for each other. The function does not throw.
5106
+ * `unknown`, and the issues name it. Examples are `minimum` and `pattern`. A schema with `nullable` or `$dynamicRef`
5107
+ * reads as `unknown`, because these keywords can permit more values. The function does not throw.
4965
5108
  *
4966
5109
  * @param schema - The schema, as JSON.
4967
5110
  * @returns The type, and the problems of the reading with their keys in the schema.
@@ -4990,5 +5133,5 @@ interface SampleOptions {
4990
5133
  * @returns The type.
4991
5134
  */
4992
5135
  export declare function typeFromSamples(values: readonly unknown[], options?: SampleOptions): ValueType;
4993
- export type { AgreeOptions, AgreeRunOptions, AgreeScheduleOptions, Agreement, Alias, AllOptions, Answer, AskOptions, AttributeAnswer, AttributeCell, AttributeCycle, AttributeDeclaration, AttributeEdge, AttributeGraph, AttributeGraphOptions, AttributeRung, AttributeTrace, AttributeVertex, Cap, CapsRule, CheckOptions, CircularDeclaration, CircularRule, Classification, Closure, Code, CompileInput, CompiledEvaluator, CompiledPart, CompiledRunner, ConformOptions, ConformProbe, Construct, Context, Part as ContextPart, Declared, Definitions, DerefCode, DocFacts, DocParts, DocVisit, Domain, DomainCodec, DomainExtension, Durable, DurableCounts, DurableOptions, Edge, Effect, EffectsOptions, Envelope, Epochs, ErrorCode, EvalError, EvalFn, EvalInput, EvalOptions, EvaluateOptions, Evaluator, ExtFn, FactsOptions, Failed, Finding, FormulaProfile, GenerateOptions, Give, GraphCycle, GraphEdge, GraphNode, GraphOptions, Header, Hop, HopBy, HostThing, Issue, Journal, Json, JsonRecord, KernelCode, Key, Kind, KindFacts, KindSource, LazyOp, LazyRule, Lookup, Machine, MachinePart, MergeConflict, MergePath, NamesSource, Namespace, Navigator, NearestOptions, NodeEdge, NodeGraph, NodeInfo, NodeRunOptions, Obligation, OpFn, OrderProblem, Outcome, ParseResult, Part$1 as Part, PartInfo, Shape as PartShape, PartSlot, PartType, PartsSpec, Perform, Plan, PlanRunOptions, PrepareOptions, PrintOptions, Random, Read, ReadPrints, ReadsCheck, Recorder, RefUse, ReferenceOptions, ReferenceRunOptions, ReplayCausePartsJson, ReplayEntry, ReplayEntryJson, ReplayErrorJson, ReplayExceptionJson, ReplayLog, ReplayLogJson, ReplayOptions, ReplayPartJson, ReplayPartsJson, ReplayResultJson, ReplaySettle, Resolution, ResolveCode, ResolveOptions, Result, Root, RootTypes, Run, RunCode, RunFn, RunInput, RunOptions, RunPart, Rung, Runner, Runtime, SampleOptions, Schedule, ScheduleAgreement, ScheduleAgreementCounts, ScheduleCounts, ScheduleEngine, ScheduleEngineFactory, ScheduleEngineStart, ScheduleOptions, ScopeRule, Shape$1 as Shape, Side, Signature, Split, StaticRead, Step, StepKey, StepLadder, StepNeed, StepReason, StepRefusal, StepSpec, StepWalk, Steps, StopSignal, Stored, SyntaxAssoc, SyntaxCalls, SyntaxEnvelopes, SyntaxFixity, SyntaxForm, SyntaxFormArgs, SyntaxHeader, SyntaxIssue, SyntaxLiterals, SyntaxOperator, SyntaxProfile, SyntaxRefPattern, SyntaxRefs, Thing, Tier, TierInput, TierResult, TraceNode, TreeContract, TreeOptions, TypeInput, TypeIssue, TypeProblem, TypeReading, TypeRef, TypeRule, Typed, Typing, Use, ValueType, VerbEffects, VerifyOptions, WalkInput, WalkOptions, WalkProblem, WalkResult, Walker, World, WorldEntry, WorldIssue, WorldOptions, WorldPart };
5136
+ export type { AgreeOptions, AgreeRunOptions, AgreeScheduleOptions, Agreement, Alias, AllOptions, Answer, AskOptions, AtArgs, AtEquation, AtRule, AttributeAnswer, AttributeCell, AttributeCycle, AttributeDeclaration, AttributeEdge, AttributeGraph, AttributeGraphOptions, AttributeRung, AttributeTrace, AttributeVertex, Cap, CapsRule, CheckOptions, CircularDeclaration, CircularRule, Classification, Closure, Code, CollectDeclaration, CollectRule, CompileInput, CompiledEvaluator, CompiledPart, CompiledRunner, ConformOptions, ConformProbe, Construct, Context, Part as ContextPart, Declared, Definitions, DerefCode, DocFacts, DocParts, DocVisit, Domain, DomainCodec, DomainExtension, Durable, DurableCounts, DurableOptions, Edge, Effect, EffectsOptions, Envelope, Epochs, ErrorCode, EvalError, EvalFn, EvalInput, EvalOptions, EvaluateOptions, Evaluator, ExtFn, FactsOptions, Failed, Finding, FormulaProfile, GenerateOptions, Give, GraphCycle, GraphEdge, GraphNode, GraphOptions, Header, Hop, HopBy, HostThing, Issue, Journal, Json, JsonRecord, KernelCode, Key, Kind, KindFacts, KindSource, LazyOp, LazyRule, Lookup, Machine, MachinePart, MergeConflict, MergePath, NamesSource, Namespace, Navigator, NearestOptions, NodeEdge, NodeGraph, NodeInfo, NodeRunOptions, Obligation, OpFn, OrderProblem, Outcome, ParseResult, Part$1 as Part, PartInfo, Shape as PartShape, PartSlot, PartType, PartsSpec, Perform, Plan, PlanRunOptions, PrepareOptions, PrintOptions, Random, Read, ReadPrints, ReadsCheck, Recorder, RefUse, ReferenceOptions, ReferenceRunOptions, ReplayCausePartsJson, ReplayEntry, ReplayEntryJson, ReplayErrorJson, ReplayExceptionJson, ReplayLog, ReplayLogJson, ReplayOptions, ReplayPartJson, ReplayPartsJson, ReplayResultJson, ReplaySettle, Resolution, ResolveCode, ResolveOptions, Result, Root, RootTypes, Run, RunCode, RunFn, RunInput, RunOptions, RunPart, Rung, Runner, Runtime, SampleOptions, Schedule, ScheduleAgreement, ScheduleAgreementCounts, ScheduleCounts, ScheduleEngine, ScheduleEngineFactory, ScheduleEngineStart, ScheduleOptions, ScopeRule, Shape$1 as Shape, Side, Signature, Split, StaticRead, Step, StepKey, StepLadder, StepNeed, StepReason, StepRefusal, StepSpec, StepWalk, Steps, StopSignal, Stored, SyntaxAssoc, SyntaxCalls, SyntaxEnvelopes, SyntaxFixity, SyntaxForm, SyntaxFormArgs, SyntaxHeader, SyntaxIssue, SyntaxLiterals, SyntaxOperator, SyntaxProfile, SyntaxRefPattern, SyntaxRefs, Thing, Tier, TierInput, TierResult, TraceNode, TreeContract, TreeOptions, TypeInput, TypeIssue, TypeProblem, TypeReading, TypeRef, TypeRule, Typed, Typing, Use, ValueType, VerbEffects, VerifyOptions, WalkInput, WalkOptions, WalkProblem, WalkResult, WalkTypeInput, Walker, World, WorldEntry, WorldIssue, WorldOptions, WorldPart };
4994
5137
  //# sourceMappingURL=index.d.ts.map