@mark1russell7/coeval 0.3.3 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -5
- package/build/index.d.ts +330 -224
- package/build/index.d.ts.map +1 -1
- package/build/index.js +361 -91
- package/build/index.js.map +1 -1
- package/package.json +1 -1
- package/src/deref.ts +10 -6
- package/src/evaluate.ts +80 -4
- package/src/formula.ts +91 -19
- package/src/index.ts +3 -0
- package/src/parts.ts +42 -5
- package/src/static.ts +182 -48
- package/src/stdlib.ts +6 -2
- package/src/world.ts +39 -3
package/build/index.d.ts
CHANGED
|
@@ -247,6 +247,223 @@ export declare function thrown(error: unknown, who: string): Failed;
|
|
|
247
247
|
*/
|
|
248
248
|
export declare function describe(value: unknown): string;
|
|
249
249
|
//#endregion
|
|
250
|
+
//#region src/deref.d.ts
|
|
251
|
+
/**
|
|
252
|
+
* The brand of a host thing: an object of the host that answers the steps of a path itself. The brand is a
|
|
253
|
+
* global symbol, thus two copies of the kernel in one program know the things of each other.
|
|
254
|
+
*/
|
|
255
|
+
export declare const THING: unique symbol;
|
|
256
|
+
/**
|
|
257
|
+
* A host thing: an object that answers the steps of a path itself, for example a node of a live tree. It is the
|
|
258
|
+
* own entry of the ladder for the verb `deref`.
|
|
259
|
+
*/
|
|
260
|
+
interface HostThing {
|
|
261
|
+
readonly [THING]: true;
|
|
262
|
+
/** A short text for a reader, for example `node card`. */
|
|
263
|
+
readonly label: string;
|
|
264
|
+
/**
|
|
265
|
+
* This function answers one step.
|
|
266
|
+
*
|
|
267
|
+
* @param key - The key of the step.
|
|
268
|
+
* @returns What the step reaches, or `undefined` when it reaches nothing.
|
|
269
|
+
*/
|
|
270
|
+
deref(key: Key): Thing | undefined;
|
|
271
|
+
/**
|
|
272
|
+
* This function gives the thing as a value, when a reference ends on it.
|
|
273
|
+
*
|
|
274
|
+
* @returns The value.
|
|
275
|
+
*/
|
|
276
|
+
toJson(): unknown;
|
|
277
|
+
/**
|
|
278
|
+
* This optional function answers all the steps of a path that are keys, in one call. A store uses it to read a
|
|
279
|
+
* path without one call for each step.
|
|
280
|
+
*
|
|
281
|
+
* @param keys - The keys.
|
|
282
|
+
* @returns What the keys reach, or `undefined` when they reach nothing.
|
|
283
|
+
*/
|
|
284
|
+
resolve?(keys: readonly Key[]): {
|
|
285
|
+
readonly thing: Thing;
|
|
286
|
+
} | undefined;
|
|
287
|
+
}
|
|
288
|
+
/** Something that a path can reach: any value of the host, or a host thing. */
|
|
289
|
+
type Thing = unknown;
|
|
290
|
+
/**
|
|
291
|
+
* This function tells if a thing is a host thing.
|
|
292
|
+
*
|
|
293
|
+
* @param thing - The thing.
|
|
294
|
+
* @returns `true` for a host thing.
|
|
295
|
+
*/
|
|
296
|
+
export declare function isHostThing(thing: unknown): thing is HostThing;
|
|
297
|
+
/** The roots of a context. Each path starts with one of them. */
|
|
298
|
+
export declare const ROOTS: readonly ["self", "names", "world", "event", "caps"];
|
|
299
|
+
/** One root of a context. */
|
|
300
|
+
type Root = (typeof ROOTS)[number];
|
|
301
|
+
/**
|
|
302
|
+
* A capability: the name of a kind of effect, or its keys. A capability permits its kind and each kind under it.
|
|
303
|
+
* Keys are necessary when a key has a dot in it.
|
|
304
|
+
*/
|
|
305
|
+
type Cap = string | readonly Key[];
|
|
306
|
+
/**
|
|
307
|
+
* The context of a term: a record with five roots. A reference reaches outside its term only through them.
|
|
308
|
+
*
|
|
309
|
+
* - `self`: the node that the term is part of.
|
|
310
|
+
* - `names`: the values that the evaluators around the term bound.
|
|
311
|
+
* - `world`: the registry of kinds.
|
|
312
|
+
* - `event`: the event that started a run.
|
|
313
|
+
* - `caps`: the effects that the term can cause.
|
|
314
|
+
*/
|
|
315
|
+
interface Context {
|
|
316
|
+
readonly self: Thing;
|
|
317
|
+
readonly names: Readonly<Record<string, unknown>>;
|
|
318
|
+
readonly world: Thing;
|
|
319
|
+
readonly event: Thing;
|
|
320
|
+
readonly caps: readonly Cap[];
|
|
321
|
+
}
|
|
322
|
+
/** The code of a `deref` evaluator: it answers one step of a path on a document of its kind. */
|
|
323
|
+
type DerefCode = (doc: Envelope, key: Key) => Thing | undefined;
|
|
324
|
+
/**
|
|
325
|
+
* The result of a step document: what it reached, or the reason of a failure. A failure can give its code, for
|
|
326
|
+
* example `#REF!` for a position outside a space. The default code is `#N/A`.
|
|
327
|
+
*/
|
|
328
|
+
type WalkResult = {
|
|
329
|
+
readonly ok: true;
|
|
330
|
+
readonly thing: Thing;
|
|
331
|
+
} | {
|
|
332
|
+
readonly ok: false;
|
|
333
|
+
readonly reason: string;
|
|
334
|
+
readonly code?: ErrorCode;
|
|
335
|
+
};
|
|
336
|
+
/** The input of a walker: the code of a step document, for example `nearest`. */
|
|
337
|
+
interface WalkInput {
|
|
338
|
+
/** The value of the step document. */
|
|
339
|
+
readonly data: Json;
|
|
340
|
+
/** The thing that the path reached before this step. */
|
|
341
|
+
readonly here: Thing;
|
|
342
|
+
readonly context: Context;
|
|
343
|
+
/**
|
|
344
|
+
* This function answers one step on a thing, through the ladder.
|
|
345
|
+
*
|
|
346
|
+
* @param thing - The thing.
|
|
347
|
+
* @param key - The key.
|
|
348
|
+
* @returns What the step reaches, or `undefined`.
|
|
349
|
+
*/
|
|
350
|
+
deref(thing: Thing, key: Key): Thing | undefined;
|
|
351
|
+
}
|
|
352
|
+
/** A walker: the code of the verb `step` of a kind of step documents. */
|
|
353
|
+
type Walker = (input: WalkInput) => WalkResult;
|
|
354
|
+
/**
|
|
355
|
+
* What a resolution needs: the world, and the code of the `deref` evaluators and of the walkers.
|
|
356
|
+
*
|
|
357
|
+
* - `plain`: `true` when the values are data. Then a step does not ask the kind of an envelope, and a reference
|
|
358
|
+
* that a step reaches stays a value (no collapse).
|
|
359
|
+
* - `roots`: the roots that a path can start at. The default is each root.
|
|
360
|
+
* - `adopt`: the thing of each value that a path reaches. A host gives its own values a host thing with this
|
|
361
|
+
* function, for example a value whose fields read through signals. A host thing is not followed as a reference.
|
|
362
|
+
*/
|
|
363
|
+
interface Navigator {
|
|
364
|
+
readonly world: World;
|
|
365
|
+
readonly derefs?: Readonly<Record<string, DerefCode>>;
|
|
366
|
+
readonly walkers?: Readonly<Record<string, Walker>>;
|
|
367
|
+
readonly plain?: boolean;
|
|
368
|
+
readonly roots?: readonly Root[];
|
|
369
|
+
readonly adopt?: (value: unknown) => Thing;
|
|
370
|
+
}
|
|
371
|
+
/** The way that one hop of a path was answered. */
|
|
372
|
+
type HopBy = "root" | "own" | "kind" | "default" | "step" | "collapse";
|
|
373
|
+
/** One hop of a path: the step, what it reached, and who answered it. */
|
|
374
|
+
interface Hop {
|
|
375
|
+
readonly step: Json;
|
|
376
|
+
readonly thing: Thing;
|
|
377
|
+
readonly by: HopBy;
|
|
378
|
+
}
|
|
379
|
+
/** The codes that a resolution gives itself. A walker can give another code for its failure. */
|
|
380
|
+
type ResolveCode = "#REF!" | "#NAME?" | "#N/A" | "#CYCLE!" | "#STEP?";
|
|
381
|
+
/** The result of a resolution: what the path reached, with each hop, or an error with the hops before it. */
|
|
382
|
+
type Resolution = {
|
|
383
|
+
readonly ok: true;
|
|
384
|
+
readonly thing: Thing;
|
|
385
|
+
readonly hops: readonly Hop[];
|
|
386
|
+
} | {
|
|
387
|
+
readonly ok: false;
|
|
388
|
+
readonly code: ResolveCode | ErrorCode;
|
|
389
|
+
readonly reason: string;
|
|
390
|
+
readonly hops: readonly Hop[];
|
|
391
|
+
};
|
|
392
|
+
/** The options of a resolution. */
|
|
393
|
+
interface ResolveOptions {
|
|
394
|
+
/** `false`: do not record the hops. The default is `true`. */
|
|
395
|
+
readonly hops?: boolean;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* This function answers one step of a path on a thing, through the ladder of the verb `deref`. A host thing
|
|
399
|
+
* answers for itself (own). A document asks its own entry, then its kind. The default goes into the value: an own
|
|
400
|
+
* field of an object, or an item of a list.
|
|
401
|
+
*
|
|
402
|
+
* @param nav - The world and the code of the evaluators.
|
|
403
|
+
* @param thing - The thing that the path reached.
|
|
404
|
+
* @param key - The key of the step.
|
|
405
|
+
* @returns What the step reaches and the rung that answered, or `undefined` when it reaches nothing.
|
|
406
|
+
*/
|
|
407
|
+
export declare function derefStep(nav: Navigator, thing: Thing, key: Key): {
|
|
408
|
+
readonly thing: Thing;
|
|
409
|
+
readonly by: HopBy;
|
|
410
|
+
} | undefined;
|
|
411
|
+
/**
|
|
412
|
+
* This function tells if a thing is a reference document: an envelope of the type `ref` with a list for its path.
|
|
413
|
+
*
|
|
414
|
+
* @param thing - The thing.
|
|
415
|
+
* @returns `true` for a reference document.
|
|
416
|
+
*/
|
|
417
|
+
export declare function isRef(thing: unknown): thing is Envelope & {
|
|
418
|
+
readonly value: readonly Json[];
|
|
419
|
+
};
|
|
420
|
+
/**
|
|
421
|
+
* This function makes the thing of the root `world`: the entries of the world as JSON. An alias is a reference
|
|
422
|
+
* document in it, thus a walk through the world follows each alias (collapse). The thing of a world is made one
|
|
423
|
+
* time.
|
|
424
|
+
*
|
|
425
|
+
* @param world - The world.
|
|
426
|
+
* @returns The thing.
|
|
427
|
+
*/
|
|
428
|
+
export declare function worldThing(world: World): Json;
|
|
429
|
+
/**
|
|
430
|
+
* This function makes a context. The world comes from the navigator when the call gives none.
|
|
431
|
+
*
|
|
432
|
+
* @param parts - The roots to set.
|
|
433
|
+
* @returns The context.
|
|
434
|
+
*/
|
|
435
|
+
export declare function context(parts?: Partial<Context>): Context;
|
|
436
|
+
/**
|
|
437
|
+
* This function resolves a path from a context, and records each hop.
|
|
438
|
+
*
|
|
439
|
+
* 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
|
|
440
|
+
* of the verb `deref` on the thing that the path reached. A step document is evaluated by the walker of its kind,
|
|
441
|
+
* with the thing that the path reached. After each hop, a reference document is followed until the path reaches
|
|
442
|
+
* something else (collapse), except in a plain navigation.
|
|
443
|
+
*
|
|
444
|
+
* The codes of a failure:
|
|
445
|
+
*
|
|
446
|
+
* - `#REF!`: the path has no root, or a root that is not open here.
|
|
447
|
+
* - `#NAME?`: the root `names` has no such name.
|
|
448
|
+
* - `#N/A`: a step reaches nothing.
|
|
449
|
+
* - `#STEP?`: a step is not a key and not a step document.
|
|
450
|
+
* - `#CYCLE!`: the references form a cycle.
|
|
451
|
+
*
|
|
452
|
+
* @param nav - The world and the code of the evaluators.
|
|
453
|
+
* @param ctx - The context.
|
|
454
|
+
* @param path - The steps.
|
|
455
|
+
* @param options - `hops: false` does not record the hops.
|
|
456
|
+
* @returns What the path reached and each hop, or an error.
|
|
457
|
+
*/
|
|
458
|
+
export declare function resolve(nav: Navigator, ctx: Context, path: readonly unknown[], options?: ResolveOptions): Resolution;
|
|
459
|
+
/**
|
|
460
|
+
* This function gives the value of a thing: the value that a host thing gives, or else the thing itself.
|
|
461
|
+
*
|
|
462
|
+
* @param thing - The thing.
|
|
463
|
+
* @returns The value.
|
|
464
|
+
*/
|
|
465
|
+
export declare function valueOfThing(thing: Thing): unknown;
|
|
466
|
+
//#endregion
|
|
250
467
|
//#region src/world.d.ts
|
|
251
468
|
/** The two sides of evaluation. `derive` is pure. `run` causes effects in order. */
|
|
252
469
|
type Side = "derive" | "run";
|
|
@@ -261,16 +478,24 @@ type Side = "derive" | "run";
|
|
|
261
478
|
* - `record`: the value is a record. Each named field has its shape. A list of names makes each named field a
|
|
262
479
|
* part. The other fields have the shape `rest` (the default is data). `required` names the fields that must be.
|
|
263
480
|
* - `deep`: each envelope at any depth of the value is a part, and the rest is data.
|
|
481
|
+
* - `text`, `number` and `one`: the value is data of that type. `one` names the values that it permits.
|
|
482
|
+
*
|
|
483
|
+
* A `term` with `address: true` is an address: a reference there gives what its path reaches, not the value. A
|
|
484
|
+
* `term` with `kinds` permits only a part whose type starts with one of the paths. A `record` with `closed: true`
|
|
485
|
+
* permits only its named fields. A `list` with `distinct: true` permits no two equal items.
|
|
264
486
|
*/
|
|
265
487
|
type Shape = {
|
|
266
488
|
readonly shape: "none";
|
|
267
489
|
} | {
|
|
268
490
|
readonly shape: "term";
|
|
269
491
|
readonly of?: string;
|
|
492
|
+
readonly address?: boolean;
|
|
493
|
+
readonly kinds?: readonly (readonly Key[])[];
|
|
270
494
|
} | {
|
|
271
495
|
readonly shape: "list";
|
|
272
496
|
readonly of?: string;
|
|
273
497
|
readonly item?: Shape;
|
|
498
|
+
readonly distinct?: boolean;
|
|
274
499
|
} | {
|
|
275
500
|
readonly shape: "map";
|
|
276
501
|
readonly of?: string;
|
|
@@ -281,9 +506,20 @@ type Shape = {
|
|
|
281
506
|
readonly of?: string;
|
|
282
507
|
readonly required?: readonly string[];
|
|
283
508
|
readonly rest?: Shape;
|
|
509
|
+
readonly closed?: boolean;
|
|
284
510
|
} | {
|
|
285
511
|
readonly shape: "deep";
|
|
286
512
|
readonly of?: string;
|
|
513
|
+
} | {
|
|
514
|
+
readonly shape: "text";
|
|
515
|
+
} | {
|
|
516
|
+
readonly shape: "number";
|
|
517
|
+
readonly whole?: boolean;
|
|
518
|
+
readonly min?: number;
|
|
519
|
+
readonly max?: number;
|
|
520
|
+
} | {
|
|
521
|
+
readonly shape: "one";
|
|
522
|
+
readonly values: readonly Json[];
|
|
287
523
|
};
|
|
288
524
|
/** The former name of `Shape`. */
|
|
289
525
|
type PartsSpec = Shape;
|
|
@@ -319,6 +555,28 @@ interface ScopeRule {
|
|
|
319
555
|
/** `true`: a part sees only the names of the parts before it, as in a sequence. */
|
|
320
556
|
readonly sequential?: boolean;
|
|
321
557
|
}
|
|
558
|
+
/**
|
|
559
|
+
* A capability rule of a kind: what the kind gives some of its parts from the capabilities of its document. A rule
|
|
560
|
+
* only narrows. A part does not get a capability that its document does not have (CAP.NARROW).
|
|
561
|
+
*
|
|
562
|
+
* - `same`: the parts get the capabilities of the document. This is the default.
|
|
563
|
+
* - `mask`: the parts get no capabilities, as the part of `pure`.
|
|
564
|
+
* - `only`: the parts get only the effects that the capabilities of the document and the list `caps` both permit.
|
|
565
|
+
*
|
|
566
|
+
* `in` names the parts that the rule covers, as patterns of their paths in the value. The key `"*"` matches each
|
|
567
|
+
* key. A rule without `in` covers each part.
|
|
568
|
+
*/
|
|
569
|
+
type CapsRule = {
|
|
570
|
+
readonly rule: "same";
|
|
571
|
+
readonly in?: readonly (readonly Key[])[];
|
|
572
|
+
} | {
|
|
573
|
+
readonly rule: "mask";
|
|
574
|
+
readonly in?: readonly (readonly Key[])[];
|
|
575
|
+
} | {
|
|
576
|
+
readonly rule: "only";
|
|
577
|
+
readonly caps: readonly Cap[];
|
|
578
|
+
readonly in?: readonly (readonly Key[])[];
|
|
579
|
+
};
|
|
322
580
|
/** A kind gives the name of an evaluator for each verb, and the contract of its value. */
|
|
323
581
|
interface Kind {
|
|
324
582
|
readonly verbs: Readonly<Record<string, string>>;
|
|
@@ -326,6 +584,13 @@ interface Kind {
|
|
|
326
584
|
readonly parts?: Shape;
|
|
327
585
|
/** The names that the kind binds for its parts. */
|
|
328
586
|
readonly scope?: readonly ScopeRule[];
|
|
587
|
+
/**
|
|
588
|
+
* The capabilities that the kind gives its parts, as rules. A part that no rule covers gets the capabilities of
|
|
589
|
+
* the document. A part that several rules cover gets only what each rule permits. The static kit reads the rules,
|
|
590
|
+
* and the kernel narrows the context of each part by them. Thus an evaluator does not narrow the capabilities
|
|
591
|
+
* itself.
|
|
592
|
+
*/
|
|
593
|
+
readonly caps?: readonly CapsRule[];
|
|
329
594
|
/** The side of the kind. A kind of the run side causes effects. The default is `derive`. */
|
|
330
595
|
readonly side?: Side;
|
|
331
596
|
/**
|
|
@@ -507,219 +772,6 @@ export declare function kindNamed(world: World, name: TypeRef): Kind | undefined
|
|
|
507
772
|
*/
|
|
508
773
|
export declare function ask(world: World, doc: Header, verb: string, options?: AskOptions): Answer;
|
|
509
774
|
//#endregion
|
|
510
|
-
//#region src/deref.d.ts
|
|
511
|
-
/**
|
|
512
|
-
* The brand of a host thing: an object of the host that answers the steps of a path itself. The brand is a
|
|
513
|
-
* global symbol, thus two copies of the kernel in one program know the things of each other.
|
|
514
|
-
*/
|
|
515
|
-
export declare const THING: unique symbol;
|
|
516
|
-
/**
|
|
517
|
-
* A host thing: an object that answers the steps of a path itself, for example a node of a live tree. It is the
|
|
518
|
-
* own entry of the ladder for the verb `deref`.
|
|
519
|
-
*/
|
|
520
|
-
interface HostThing {
|
|
521
|
-
readonly [THING]: true;
|
|
522
|
-
/** A short text for a reader, for example `node card`. */
|
|
523
|
-
readonly label: string;
|
|
524
|
-
/**
|
|
525
|
-
* This function answers one step.
|
|
526
|
-
*
|
|
527
|
-
* @param key - The key of the step.
|
|
528
|
-
* @returns What the step reaches, or `undefined` when it reaches nothing.
|
|
529
|
-
*/
|
|
530
|
-
deref(key: Key): Thing | undefined;
|
|
531
|
-
/**
|
|
532
|
-
* This function gives the thing as a value, when a reference ends on it.
|
|
533
|
-
*
|
|
534
|
-
* @returns The value.
|
|
535
|
-
*/
|
|
536
|
-
toJson(): unknown;
|
|
537
|
-
/**
|
|
538
|
-
* This optional function answers all the steps of a path that are keys, in one call. A store uses it to read a
|
|
539
|
-
* path without one call for each step.
|
|
540
|
-
*
|
|
541
|
-
* @param keys - The keys.
|
|
542
|
-
* @returns What the keys reach, or `undefined` when they reach nothing.
|
|
543
|
-
*/
|
|
544
|
-
resolve?(keys: readonly Key[]): {
|
|
545
|
-
readonly thing: Thing;
|
|
546
|
-
} | undefined;
|
|
547
|
-
}
|
|
548
|
-
/** Something that a path can reach: any value of the host, or a host thing. */
|
|
549
|
-
type Thing = unknown;
|
|
550
|
-
/**
|
|
551
|
-
* This function tells if a thing is a host thing.
|
|
552
|
-
*
|
|
553
|
-
* @param thing - The thing.
|
|
554
|
-
* @returns `true` for a host thing.
|
|
555
|
-
*/
|
|
556
|
-
export declare function isHostThing(thing: unknown): thing is HostThing;
|
|
557
|
-
/** The roots of a context. Each path starts with one of them. */
|
|
558
|
-
export declare const ROOTS: readonly ["self", "names", "world", "event", "caps"];
|
|
559
|
-
/** One root of a context. */
|
|
560
|
-
type Root = (typeof ROOTS)[number];
|
|
561
|
-
/**
|
|
562
|
-
* A capability: the name of a kind of effect, or its keys. A capability permits its kind and each kind under it.
|
|
563
|
-
* Keys are necessary when a key has a dot in it.
|
|
564
|
-
*/
|
|
565
|
-
type Cap = string | readonly Key[];
|
|
566
|
-
/**
|
|
567
|
-
* The context of a term: a record with five roots. A reference reaches outside its term only through them.
|
|
568
|
-
*
|
|
569
|
-
* - `self`: the node that the term is part of.
|
|
570
|
-
* - `names`: the values that the evaluators around the term bound.
|
|
571
|
-
* - `world`: the registry of kinds.
|
|
572
|
-
* - `event`: the event that started a run.
|
|
573
|
-
* - `caps`: the effects that the term can cause.
|
|
574
|
-
*/
|
|
575
|
-
interface Context {
|
|
576
|
-
readonly self: Thing;
|
|
577
|
-
readonly names: Readonly<Record<string, unknown>>;
|
|
578
|
-
readonly world: Thing;
|
|
579
|
-
readonly event: Thing;
|
|
580
|
-
readonly caps: readonly Cap[];
|
|
581
|
-
}
|
|
582
|
-
/** The code of a `deref` evaluator: it answers one step of a path on a document of its kind. */
|
|
583
|
-
type DerefCode = (doc: Envelope, key: Key) => Thing | undefined;
|
|
584
|
-
/** The result of a step document: what it reached, or the reason of a failure. */
|
|
585
|
-
type WalkResult = {
|
|
586
|
-
readonly ok: true;
|
|
587
|
-
readonly thing: Thing;
|
|
588
|
-
} | {
|
|
589
|
-
readonly ok: false;
|
|
590
|
-
readonly reason: string;
|
|
591
|
-
};
|
|
592
|
-
/** The input of a walker: the code of a step document, for example `nearest`. */
|
|
593
|
-
interface WalkInput {
|
|
594
|
-
/** The value of the step document. */
|
|
595
|
-
readonly data: Json;
|
|
596
|
-
/** The thing that the path reached before this step. */
|
|
597
|
-
readonly here: Thing;
|
|
598
|
-
readonly context: Context;
|
|
599
|
-
/**
|
|
600
|
-
* This function answers one step on a thing, through the ladder.
|
|
601
|
-
*
|
|
602
|
-
* @param thing - The thing.
|
|
603
|
-
* @param key - The key.
|
|
604
|
-
* @returns What the step reaches, or `undefined`.
|
|
605
|
-
*/
|
|
606
|
-
deref(thing: Thing, key: Key): Thing | undefined;
|
|
607
|
-
}
|
|
608
|
-
/** A walker: the code of the verb `step` of a kind of step documents. */
|
|
609
|
-
type Walker = (input: WalkInput) => WalkResult;
|
|
610
|
-
/**
|
|
611
|
-
* What a resolution needs: the world, and the code of the `deref` evaluators and of the walkers.
|
|
612
|
-
*
|
|
613
|
-
* - `plain`: `true` when the values are data. Then a step does not ask the kind of an envelope, and a reference
|
|
614
|
-
* that a step reaches stays a value (no collapse).
|
|
615
|
-
* - `roots`: the roots that a path can start at. The default is each root.
|
|
616
|
-
* - `adopt`: the thing of each value that a path reaches. A host gives its own values a host thing with this
|
|
617
|
-
* function, for example a value whose fields read through signals. A host thing is not followed as a reference.
|
|
618
|
-
*/
|
|
619
|
-
interface Navigator {
|
|
620
|
-
readonly world: World;
|
|
621
|
-
readonly derefs?: Readonly<Record<string, DerefCode>>;
|
|
622
|
-
readonly walkers?: Readonly<Record<string, Walker>>;
|
|
623
|
-
readonly plain?: boolean;
|
|
624
|
-
readonly roots?: readonly Root[];
|
|
625
|
-
readonly adopt?: (value: unknown) => Thing;
|
|
626
|
-
}
|
|
627
|
-
/** The way that one hop of a path was answered. */
|
|
628
|
-
type HopBy = "root" | "own" | "kind" | "default" | "step" | "collapse";
|
|
629
|
-
/** One hop of a path: the step, what it reached, and who answered it. */
|
|
630
|
-
interface Hop {
|
|
631
|
-
readonly step: Json;
|
|
632
|
-
readonly thing: Thing;
|
|
633
|
-
readonly by: HopBy;
|
|
634
|
-
}
|
|
635
|
-
/** The codes of a failed resolution. */
|
|
636
|
-
type ResolveCode = "#REF!" | "#NAME?" | "#N/A" | "#CYCLE!" | "#STEP?";
|
|
637
|
-
/** The result of a resolution: what the path reached, with each hop, or an error with the hops before it. */
|
|
638
|
-
type Resolution = {
|
|
639
|
-
readonly ok: true;
|
|
640
|
-
readonly thing: Thing;
|
|
641
|
-
readonly hops: readonly Hop[];
|
|
642
|
-
} | {
|
|
643
|
-
readonly ok: false;
|
|
644
|
-
readonly code: ResolveCode;
|
|
645
|
-
readonly reason: string;
|
|
646
|
-
readonly hops: readonly Hop[];
|
|
647
|
-
};
|
|
648
|
-
/** The options of a resolution. */
|
|
649
|
-
interface ResolveOptions {
|
|
650
|
-
/** `false`: do not record the hops. The default is `true`. */
|
|
651
|
-
readonly hops?: boolean;
|
|
652
|
-
}
|
|
653
|
-
/**
|
|
654
|
-
* This function answers one step of a path on a thing, through the ladder of the verb `deref`. A host thing
|
|
655
|
-
* answers for itself (own). A document asks its own entry, then its kind. The default goes into the value: an own
|
|
656
|
-
* field of an object, or an item of a list.
|
|
657
|
-
*
|
|
658
|
-
* @param nav - The world and the code of the evaluators.
|
|
659
|
-
* @param thing - The thing that the path reached.
|
|
660
|
-
* @param key - The key of the step.
|
|
661
|
-
* @returns What the step reaches and the rung that answered, or `undefined` when it reaches nothing.
|
|
662
|
-
*/
|
|
663
|
-
export declare function derefStep(nav: Navigator, thing: Thing, key: Key): {
|
|
664
|
-
readonly thing: Thing;
|
|
665
|
-
readonly by: HopBy;
|
|
666
|
-
} | undefined;
|
|
667
|
-
/**
|
|
668
|
-
* This function tells if a thing is a reference document: an envelope of the type `ref` with a list for its path.
|
|
669
|
-
*
|
|
670
|
-
* @param thing - The thing.
|
|
671
|
-
* @returns `true` for a reference document.
|
|
672
|
-
*/
|
|
673
|
-
export declare function isRef(thing: unknown): thing is Envelope & {
|
|
674
|
-
readonly value: readonly Json[];
|
|
675
|
-
};
|
|
676
|
-
/**
|
|
677
|
-
* This function makes the thing of the root `world`: the entries of the world as JSON. An alias is a reference
|
|
678
|
-
* document in it, thus a walk through the world follows each alias (collapse). The thing of a world is made one
|
|
679
|
-
* time.
|
|
680
|
-
*
|
|
681
|
-
* @param world - The world.
|
|
682
|
-
* @returns The thing.
|
|
683
|
-
*/
|
|
684
|
-
export declare function worldThing(world: World): Json;
|
|
685
|
-
/**
|
|
686
|
-
* This function makes a context. The world comes from the navigator when the call gives none.
|
|
687
|
-
*
|
|
688
|
-
* @param parts - The roots to set.
|
|
689
|
-
* @returns The context.
|
|
690
|
-
*/
|
|
691
|
-
export declare function context(parts?: Partial<Context>): Context;
|
|
692
|
-
/**
|
|
693
|
-
* This function resolves a path from a context, and records each hop.
|
|
694
|
-
*
|
|
695
|
-
* 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
|
|
696
|
-
* of the verb `deref` on the thing that the path reached. A step document is evaluated by the walker of its kind,
|
|
697
|
-
* with the thing that the path reached. After each hop, a reference document is followed until the path reaches
|
|
698
|
-
* something else (collapse), except in a plain navigation.
|
|
699
|
-
*
|
|
700
|
-
* The codes of a failure:
|
|
701
|
-
*
|
|
702
|
-
* - `#REF!`: the path has no root, or a root that is not open here.
|
|
703
|
-
* - `#NAME?`: the root `names` has no such name.
|
|
704
|
-
* - `#N/A`: a step reaches nothing.
|
|
705
|
-
* - `#STEP?`: a step is not a key and not a step document.
|
|
706
|
-
* - `#CYCLE!`: the references form a cycle.
|
|
707
|
-
*
|
|
708
|
-
* @param nav - The world and the code of the evaluators.
|
|
709
|
-
* @param ctx - The context.
|
|
710
|
-
* @param path - The steps.
|
|
711
|
-
* @param options - `hops: false` does not record the hops.
|
|
712
|
-
* @returns What the path reached and each hop, or an error.
|
|
713
|
-
*/
|
|
714
|
-
export declare function resolve(nav: Navigator, ctx: Context, path: readonly unknown[], options?: ResolveOptions): Resolution;
|
|
715
|
-
/**
|
|
716
|
-
* This function gives the value of a thing: the value that a host thing gives, or else the thing itself.
|
|
717
|
-
*
|
|
718
|
-
* @param thing - The thing.
|
|
719
|
-
* @returns The value.
|
|
720
|
-
*/
|
|
721
|
-
export declare function valueOfThing(thing: Thing): unknown;
|
|
722
|
-
//#endregion
|
|
723
775
|
//#region src/classify.d.ts
|
|
724
776
|
/** A shape proposes a kind for each document that has all of its fields. */
|
|
725
777
|
interface Shape$1 {
|
|
@@ -765,6 +817,8 @@ interface PartSlot {
|
|
|
765
817
|
readonly key: string;
|
|
766
818
|
readonly item: Json;
|
|
767
819
|
readonly of?: string;
|
|
820
|
+
/** `true` when the position of the part declares an address: a reference there gives what its path reaches. */
|
|
821
|
+
readonly address?: true;
|
|
768
822
|
}
|
|
769
823
|
/** The value of a document, split into its parts, by the shape that its kind declares. */
|
|
770
824
|
type Split = {
|
|
@@ -841,6 +895,25 @@ export declare function permits(caps: readonly Cap[], kind: Cap): boolean;
|
|
|
841
895
|
* @returns The context of the part.
|
|
842
896
|
*/
|
|
843
897
|
export declare function narrow(parent: Context, next: Context): Context;
|
|
898
|
+
/**
|
|
899
|
+
* This function gives the capabilities that two lists both permit. An effect is permitted by the result when each
|
|
900
|
+
* list permits it. When the list `b` permits each capability of `a`, the result is the list `a` itself.
|
|
901
|
+
*
|
|
902
|
+
* @param a - The first list, for example the capabilities of a document.
|
|
903
|
+
* @param b - The second list, for example the list of a rule `only`.
|
|
904
|
+
* @returns The capabilities that both lists permit.
|
|
905
|
+
*/
|
|
906
|
+
export declare function intersectCaps(a: readonly Cap[], b: readonly Cap[]): readonly Cap[];
|
|
907
|
+
/**
|
|
908
|
+
* This function gives the capabilities that a kind gives one of its parts, by the capability rules of its contract.
|
|
909
|
+
* The kernel and the static kit both use it, thus a run and a check narrow the same way.
|
|
910
|
+
*
|
|
911
|
+
* @param rules - The capability rules of the kind (`Kind.caps`).
|
|
912
|
+
* @param path - The path of the part in the value of the document.
|
|
913
|
+
* @param caps - The capabilities of the document.
|
|
914
|
+
* @returns The capabilities of the part: the same list or a smaller one.
|
|
915
|
+
*/
|
|
916
|
+
export declare function partCaps(rules: readonly CapsRule[] | undefined, path: readonly Key[], caps: readonly Cap[]): readonly Cap[];
|
|
844
917
|
/**
|
|
845
918
|
* The steps of an evaluation that can wait. It yields a promise only when the host makes it wait. A runner takes the
|
|
846
919
|
* result of a part with `yield*`, thus a run goes on at once until an effect waits. A runner does not yield a
|
|
@@ -966,6 +1039,8 @@ interface CompileInput {
|
|
|
966
1039
|
* @returns The value with the items.
|
|
967
1040
|
*/
|
|
968
1041
|
fill(items: readonly unknown[]): unknown;
|
|
1042
|
+
/** `true` when the position of the document declares an address. A reference there gives the thing, not its value. */
|
|
1043
|
+
readonly address?: boolean;
|
|
969
1044
|
}
|
|
970
1045
|
/**
|
|
971
1046
|
* A sealed part. An evaluator can read the binding name of a part and evaluate it. It cannot read the value of the
|
|
@@ -1003,6 +1078,8 @@ interface EvalInput {
|
|
|
1003
1078
|
readonly context: Context;
|
|
1004
1079
|
/** The keys from the root document to this document. */
|
|
1005
1080
|
readonly place: readonly Key[];
|
|
1081
|
+
/** `true` when the position of the document declares an address. */
|
|
1082
|
+
readonly address?: boolean;
|
|
1006
1083
|
/**
|
|
1007
1084
|
* This function resolves a path from the context of the document.
|
|
1008
1085
|
*
|
|
@@ -1437,24 +1514,37 @@ interface DocVisit {
|
|
|
1437
1514
|
readonly place: readonly Key[];
|
|
1438
1515
|
/** The keys from the root JSON value to this document. A change at this path changes this document. */
|
|
1439
1516
|
readonly at: readonly Key[];
|
|
1517
|
+
/** The visit of the document that holds this document as a part. The root has none. */
|
|
1518
|
+
readonly parent?: DocVisit | undefined;
|
|
1519
|
+
/** The keys from the value of the parent to this document: the path of the part. The root has none. */
|
|
1520
|
+
readonly slot: readonly Key[];
|
|
1440
1521
|
/** The document. A bare value has the type that its position declares. */
|
|
1441
1522
|
readonly doc: Envelope;
|
|
1442
1523
|
/** `true` when the type came from the position and not from an envelope. */
|
|
1443
1524
|
readonly declared: boolean;
|
|
1444
1525
|
/** The kind of the document, when the world has it. */
|
|
1445
|
-
readonly kind?: Kind;
|
|
1526
|
+
readonly kind?: Kind | undefined;
|
|
1446
1527
|
/** The keys of the kind after each alias. */
|
|
1447
|
-
readonly typePath?: readonly Key[];
|
|
1528
|
+
readonly typePath?: readonly Key[] | undefined;
|
|
1448
1529
|
/** The number of documents around this document. The root has 0. */
|
|
1449
1530
|
readonly depth: number;
|
|
1450
1531
|
/** The names that the kinds around this document bind for it. */
|
|
1451
1532
|
readonly names: ReadonlySet<string>;
|
|
1452
1533
|
/** The names that a sequence around this document binds only for the parts after it. */
|
|
1453
1534
|
readonly later: ReadonlySet<string>;
|
|
1535
|
+
/** `true` when the position of the document declares an address: a reference there is not a read of a value. */
|
|
1536
|
+
readonly address?: true | undefined;
|
|
1537
|
+
/**
|
|
1538
|
+
* The capabilities of the document: the capabilities of the walk, narrowed by the capability rules of the kinds
|
|
1539
|
+
* around it (`Kind.caps`). A walk without capabilities gives none here.
|
|
1540
|
+
*/
|
|
1541
|
+
readonly caps?: readonly Cap[] | undefined;
|
|
1454
1542
|
}
|
|
1455
1543
|
/** A position that a walk cannot read as a document. */
|
|
1456
1544
|
interface WalkProblem {
|
|
1545
|
+
/** The keys from the root document to the document with the problem. */
|
|
1457
1546
|
readonly place: readonly Key[];
|
|
1547
|
+
/** The keys from the root JSON value to the value with the problem. */
|
|
1458
1548
|
readonly at: readonly Key[];
|
|
1459
1549
|
readonly code: "#PART?" | "#VALUE!";
|
|
1460
1550
|
readonly reason: string;
|
|
@@ -1465,6 +1555,8 @@ interface WalkOptions {
|
|
|
1465
1555
|
readonly declaredType?: string;
|
|
1466
1556
|
/** The names that the host binds at the root. */
|
|
1467
1557
|
readonly names?: readonly string[];
|
|
1558
|
+
/** The capabilities at the root. With them, each visit gets the capabilities of its document. */
|
|
1559
|
+
readonly caps?: readonly Cap[];
|
|
1468
1560
|
/**
|
|
1469
1561
|
* This function gets each position that is not a document.
|
|
1470
1562
|
*
|
|
@@ -1474,17 +1566,21 @@ interface WalkOptions {
|
|
|
1474
1566
|
}
|
|
1475
1567
|
/**
|
|
1476
1568
|
* This function visits each document of a document: the root and each part at each depth, by the contracts of the
|
|
1477
|
-
* kinds. A part of a kind that the world does not have is not visited.
|
|
1478
|
-
*
|
|
1569
|
+
* kinds. A part of a kind that the world does not have is not visited. With capabilities in the options, the walk
|
|
1570
|
+
* 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
|
|
1571
|
+
* depth, thus a deep document cannot overflow it. The time and the memory of a walk are linear in the size of the
|
|
1572
|
+
* document. A visit makes the keys of its place and of its path only when a reader asks for them.
|
|
1479
1573
|
*
|
|
1480
1574
|
* @param world - The world of the kinds.
|
|
1481
1575
|
* @param doc - The document, as JSON.
|
|
1482
1576
|
* @param visit - The function that gets each document. It gives `"skip"` to not visit the parts of a document.
|
|
1483
|
-
* @param options - The type of a bare root value, the names
|
|
1577
|
+
* @param options - The type of a bare root value, the names, the capabilities and a function for the problems.
|
|
1484
1578
|
*/
|
|
1485
1579
|
export declare function walk(world: World, doc: unknown, visit: (visit: DocVisit) => void | "skip", options?: WalkOptions): void;
|
|
1486
1580
|
/** One reference of a document. */
|
|
1487
1581
|
interface RefUse {
|
|
1582
|
+
/** The visit of the reference document: its parent, its depth and the names that it sees. */
|
|
1583
|
+
readonly visit: DocVisit;
|
|
1488
1584
|
/** The place of the reference document, through the parts. */
|
|
1489
1585
|
readonly place: readonly Key[];
|
|
1490
1586
|
/** The keys from the root JSON value to the reference document. */
|
|
@@ -1494,11 +1590,13 @@ interface RefUse {
|
|
|
1494
1590
|
readonly root: string;
|
|
1495
1591
|
/** `false` when a kind around the reference binds its first name. A reference to another root is free. */
|
|
1496
1592
|
readonly free: boolean;
|
|
1593
|
+
/** `true` when the reference is an address: its position declares it. An address does not read a value. */
|
|
1594
|
+
readonly address: boolean;
|
|
1497
1595
|
}
|
|
1498
1596
|
/**
|
|
1499
1597
|
* This function finds each reference of a document: each document of the type `ref` that a walk reaches. A
|
|
1500
1598
|
* reference to a name that a kind around it binds is not free. The others are what the document reads from
|
|
1501
|
-
* outside: its dependencies.
|
|
1599
|
+
* outside: its dependencies. When the kind `ref` has parts, the walk also finds the references in its step documents.
|
|
1502
1600
|
*
|
|
1503
1601
|
* @param world - The world of the kinds.
|
|
1504
1602
|
* @param doc - The document, as JSON.
|
|
@@ -1523,6 +1621,8 @@ interface Issue {
|
|
|
1523
1621
|
/** The keys from the root document to the document with the problem. */
|
|
1524
1622
|
readonly place: readonly Key[];
|
|
1525
1623
|
readonly reason: string;
|
|
1624
|
+
/** The keys from the root JSON value to the value with the problem. */
|
|
1625
|
+
readonly at?: readonly Key[];
|
|
1526
1626
|
}
|
|
1527
1627
|
/** The options of a check. */
|
|
1528
1628
|
interface CheckOptions {
|
|
@@ -1530,7 +1630,10 @@ interface CheckOptions {
|
|
|
1530
1630
|
readonly declaredType?: string;
|
|
1531
1631
|
/** The names that the host binds at the root. `"any"` does not check the names. The default is no names. */
|
|
1532
1632
|
readonly names?: readonly string[] | "any";
|
|
1533
|
-
/**
|
|
1633
|
+
/**
|
|
1634
|
+
* The capabilities at the root. Without them, the check does not check the effects. The check narrows them for
|
|
1635
|
+
* each part by the capability rules of the kinds, as a run does.
|
|
1636
|
+
*/
|
|
1534
1637
|
readonly caps?: readonly Cap[];
|
|
1535
1638
|
}
|
|
1536
1639
|
/**
|
|
@@ -1544,7 +1647,7 @@ interface CheckOptions {
|
|
|
1544
1647
|
* - `#DEPTH!`: too much nesting.
|
|
1545
1648
|
* - `#REF!` and `#STEP?`: a bad path.
|
|
1546
1649
|
* - `#NAME?`: a name that nothing binds.
|
|
1547
|
-
* - `#CAP!`: an effect that the capabilities do not permit.
|
|
1650
|
+
* - `#CAP!`: an effect that the capabilities of its document do not permit. A kind around the document can narrow them.
|
|
1548
1651
|
*
|
|
1549
1652
|
* @param machine - The world and the code of the evaluators.
|
|
1550
1653
|
* @param doc - The document, as JSON.
|
|
@@ -1561,8 +1664,8 @@ type OpFn = (...args: never[]) => unknown;
|
|
|
1561
1664
|
* example a default for an error.
|
|
1562
1665
|
*/
|
|
1563
1666
|
type LazyOp = (args: readonly (() => Result)[]) => Result;
|
|
1564
|
-
/** The code of an extension: it gives the value of the data of an extension document. */
|
|
1565
|
-
type ExtFn = (data: Json) => Result;
|
|
1667
|
+
/** The code of an extension: it gives the value of the data of an extension document, in the context of the document. */
|
|
1668
|
+
type ExtFn = (data: Json, context: Context) => Result;
|
|
1566
1669
|
/**
|
|
1567
1670
|
* The rules of one formula language: its operations, and the rules that differ between languages.
|
|
1568
1671
|
*
|
|
@@ -1577,6 +1680,8 @@ type ExtFn = (data: Json) => Result;
|
|
|
1577
1680
|
* - `omit`: the errors that leave a field out of a `record`, as an absent value.
|
|
1578
1681
|
* - `missing`: the values that a reference cannot give. Such a value gives `#N/A`.
|
|
1579
1682
|
* - `check`: a check of the value of an operation, for example "a number must be finite".
|
|
1683
|
+
* - `combine`: the error of two or more failed parts of an operation, a `record` or a `list`. With it, each part
|
|
1684
|
+
* evaluates, and one failed part gives its own error. Without it, the first error stops the evaluation.
|
|
1580
1685
|
*/
|
|
1581
1686
|
interface FormulaProfile {
|
|
1582
1687
|
readonly ops?: Readonly<Record<string, OpFn>> | ((name: string) => OpFn | undefined);
|
|
@@ -1588,6 +1693,7 @@ interface FormulaProfile {
|
|
|
1588
1693
|
readonly omit?: (error: EvalError) => boolean;
|
|
1589
1694
|
readonly missing?: (value: unknown) => boolean;
|
|
1590
1695
|
readonly check?: (value: unknown, op: string) => Result | undefined;
|
|
1696
|
+
readonly combine?: (errors: readonly EvalError[]) => EvalError;
|
|
1591
1697
|
}
|
|
1592
1698
|
/** The value of a name whose binding failed. A reference to the name gives the error. */
|
|
1593
1699
|
export declare class Held {
|
|
@@ -1637,5 +1743,5 @@ export declare function formulaEvaluators(profile?: FormulaProfile): Readonly<Re
|
|
|
1637
1743
|
*/
|
|
1638
1744
|
export declare function formulaMachine(profile?: FormulaProfile, more?: Partial<Machine>): Machine;
|
|
1639
1745
|
//#endregion
|
|
1640
|
-
export type { Alias, AllOptions, Answer, AskOptions, Cap, CheckOptions, Classification, Closure, Code, CompileInput, CompiledEvaluator, CompiledPart, CompiledRunner, Construct, Context, Part as ContextPart, DerefCode, DocVisit, Edge, Effect, Envelope, ErrorCode, EvalError, EvalFn, EvalInput, EvalOptions, Evaluator, ExtFn, Failed, FormulaProfile, Give, Header, Hop, HopBy, HostThing, Issue, Json, JsonRecord, KernelCode, Key, Kind, KindSource, LazyOp, Lookup, Machine, NamesSource, Namespace, Navigator, NearestOptions, OpFn, OrderProblem, Outcome, Part$1 as Part, PartInfo, Shape as PartShape, PartSlot, PartsSpec, Perform, Plan, PrepareOptions, RefUse, 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, TraceNode, TypeRef, Use, WalkInput, WalkOptions, WalkProblem, WalkResult, Walker, World, WorldEntry };
|
|
1746
|
+
export type { Alias, AllOptions, Answer, AskOptions, Cap, CapsRule, CheckOptions, Classification, Closure, Code, CompileInput, CompiledEvaluator, CompiledPart, CompiledRunner, Construct, Context, Part as ContextPart, DerefCode, DocVisit, Edge, Effect, Envelope, ErrorCode, EvalError, EvalFn, EvalInput, EvalOptions, Evaluator, ExtFn, Failed, FormulaProfile, Give, Header, Hop, HopBy, HostThing, Issue, Json, JsonRecord, KernelCode, Key, Kind, KindSource, LazyOp, Lookup, Machine, NamesSource, Namespace, Navigator, NearestOptions, OpFn, OrderProblem, Outcome, Part$1 as Part, PartInfo, Shape as PartShape, PartSlot, PartsSpec, Perform, Plan, PrepareOptions, RefUse, 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, TraceNode, TypeRef, Use, WalkInput, WalkOptions, WalkProblem, WalkResult, Walker, World, WorldEntry };
|
|
1641
1747
|
//# sourceMappingURL=index.d.ts.map
|