scripted-yaml 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +310 -2
- package/dist/builtins.d.ts +7 -0
- package/dist/checker.d.ts +41 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +2285 -0
- package/dist/document.d.ts +42 -0
- package/dist/expression.d.ts +47 -0
- package/dist/importers.d.ts +66 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +2132 -0
- package/dist/lazy-formula.d.ts +52 -0
- package/dist/node.d.ts +101 -0
- package/dist/patch.d.ts +26 -0
- package/dist/problem.d.ts +44 -0
- package/dist/reader.d.ts +30 -0
- package/dist/resolution.d.ts +53 -0
- package/dist/schema.d.ts +43 -0
- package/dist/scope.d.ts +72 -0
- package/dist/scripted-yaml.d.ts +30 -0
- package/dist/source.d.ts +42 -0
- package/dist/variables.d.ts +35 -0
- package/package.json +61 -4
- package/skills/scripted-yaml/SKILL.md +297 -0
- package/skills/scripted-yaml/examples/base.yml +16 -0
- package/skills/scripted-yaml/examples/fixed.yml +16 -0
- package/skills/scripted-yaml/examples/handbook.md +7 -0
- package/skills/scripted-yaml/examples/helpers.js +8 -0
- package/skills/scripted-yaml/examples/import.yml +9 -0
- package/skills/scripted-yaml/examples/mistakes.yml +13 -0
- package/skills/scripted-yaml/examples/patch.yml +25 -0
- package/skills/scripted-yaml/examples/pipeline.yml +25 -0
- package/skills/scripted-yaml/examples/settings.yml +2 -0
- package/skills/scripted-yaml/examples/shop.yml +55 -0
- package/skills/scripted-yaml/examples/team-wrong.yml +15 -0
- package/skills/scripted-yaml/examples/team.yml +21 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every node name of `feelin`'s syntax tree that this library relies on.
|
|
3
|
+
* `test/feelin-tree.test.ts` asserts that `feelin` still produces each of them.
|
|
4
|
+
*/
|
|
5
|
+
export declare const FeelNode: {
|
|
6
|
+
readonly VariableName: "VariableName";
|
|
7
|
+
readonly PathExpression: "PathExpression";
|
|
8
|
+
readonly FunctionInvocation: "FunctionInvocation";
|
|
9
|
+
readonly FilterExpression: "FilterExpression";
|
|
10
|
+
readonly ForExpression: "ForExpression";
|
|
11
|
+
readonly Type: "Type";
|
|
12
|
+
readonly Name: "Name";
|
|
13
|
+
readonly NamedParameter: "NamedParameter";
|
|
14
|
+
};
|
|
15
|
+
/** A name a formula reads: `prerequisites.local` is head `prerequisites`, path `[local]`. */
|
|
16
|
+
export declare class Ref {
|
|
17
|
+
readonly head: string;
|
|
18
|
+
readonly path: string[];
|
|
19
|
+
/** The name is called: `fileExists(...)`. */
|
|
20
|
+
readonly call: boolean;
|
|
21
|
+
/** The name is inside `[ ]`, where it may be a field of the item being filtered. */
|
|
22
|
+
readonly inFilter: boolean;
|
|
23
|
+
constructor(head: string, path: string[],
|
|
24
|
+
/** The name is called: `fileExists(...)`. */
|
|
25
|
+
call: boolean,
|
|
26
|
+
/** The name is inside `[ ]`, where it may be a field of the item being filtered. */
|
|
27
|
+
inFilter: boolean);
|
|
28
|
+
get name(): string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The names one formula reads, taken from the syntax tree `feelin` builds. Nothing is evaluated.
|
|
32
|
+
* A key is computed only when a formula reads it, so this tells which keys to compute first,
|
|
33
|
+
* and how deep into each one the formula goes.
|
|
34
|
+
*/
|
|
35
|
+
export declare class LazyFormula {
|
|
36
|
+
readonly source: string;
|
|
37
|
+
private static readonly cache;
|
|
38
|
+
readonly refs: Ref[];
|
|
39
|
+
/** Why `feelin` cannot read this formula. At most one. */
|
|
40
|
+
readonly errors: string[];
|
|
41
|
+
/** The names the formula makes itself: loop variables, function parameters, entries of `{ }`. They are not read from the file; nor is `item` inside `[ ]`. */
|
|
42
|
+
private readonly own;
|
|
43
|
+
static of(source: string): LazyFormula;
|
|
44
|
+
private constructor();
|
|
45
|
+
/** True when the text is one plain name, such as `test_command`. */
|
|
46
|
+
static isName(text: string): boolean;
|
|
47
|
+
private text;
|
|
48
|
+
/** Looks at one node of the tree. Returning false skips what is inside it. */
|
|
49
|
+
private enter;
|
|
50
|
+
/** True inside the `[ ]` of a filter, not in the list before it. */
|
|
51
|
+
private inFilter;
|
|
52
|
+
}
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { Expression } from './expression.js';
|
|
2
|
+
import type { Located } from './problem.js';
|
|
3
|
+
import type { Shape } from './schema.js';
|
|
4
|
+
/** A key as written, split at its last `!` into a name and a marker. */
|
|
5
|
+
export declare class Key {
|
|
6
|
+
readonly raw: string;
|
|
7
|
+
readonly name: string;
|
|
8
|
+
/** undefined: plain key. '': a formula. Anything else: the name of a marker. */
|
|
9
|
+
readonly marker: string | undefined;
|
|
10
|
+
constructor(raw: string);
|
|
11
|
+
get kind(): 'plain' | 'formula' | 'marked';
|
|
12
|
+
get keyword(): boolean;
|
|
13
|
+
}
|
|
14
|
+
/** The key of a function: `from_gear(wanted)` is the name `from_gear` and the parameter `wanted`. */
|
|
15
|
+
export declare class Signature {
|
|
16
|
+
readonly name: string;
|
|
17
|
+
/** undefined when the key has no brackets: the value is then a whole FEEL `function(…) …`. */
|
|
18
|
+
readonly parameters: string[] | undefined;
|
|
19
|
+
constructor(key: string);
|
|
20
|
+
/** The FEEL function definition for a body written without one. */
|
|
21
|
+
define(body: string): string;
|
|
22
|
+
}
|
|
23
|
+
/** A value in the file, with the place it was written. */
|
|
24
|
+
export declare abstract class Node implements Located {
|
|
25
|
+
readonly file: string;
|
|
26
|
+
readonly line: number;
|
|
27
|
+
readonly column: number;
|
|
28
|
+
/** The map or list that holds this node. */
|
|
29
|
+
parent?: Node;
|
|
30
|
+
/** The entry this node is the value of, when it sits in a map. */
|
|
31
|
+
entry?: Entry;
|
|
32
|
+
/** The formula or text template this node holds, set when the file is checked. */
|
|
33
|
+
expression?: Expression;
|
|
34
|
+
constructor(file: string, line: number, column: number);
|
|
35
|
+
/** Plain data, keys as written. */
|
|
36
|
+
abstract toData(): unknown;
|
|
37
|
+
/** A copy that shares nothing with this node. */
|
|
38
|
+
abstract clone(): Node;
|
|
39
|
+
path(): string;
|
|
40
|
+
within(ancestor: Node): boolean;
|
|
41
|
+
ancestors(): Node[];
|
|
42
|
+
}
|
|
43
|
+
export declare class ScalarNode extends Node {
|
|
44
|
+
readonly value: unknown;
|
|
45
|
+
/** The value as text, as written: `2` stays "2". */
|
|
46
|
+
readonly source: string;
|
|
47
|
+
constructor(file: string, line: number, column: number, value: unknown,
|
|
48
|
+
/** The value as text, as written: `2` stays "2". */
|
|
49
|
+
source: string);
|
|
50
|
+
toData(): unknown;
|
|
51
|
+
clone(): ScalarNode;
|
|
52
|
+
}
|
|
53
|
+
/** One `key: value` of a map. */
|
|
54
|
+
export declare class Entry implements Located {
|
|
55
|
+
readonly value: Node;
|
|
56
|
+
readonly map: MapNode;
|
|
57
|
+
readonly file: string;
|
|
58
|
+
readonly line: number;
|
|
59
|
+
readonly column: number;
|
|
60
|
+
readonly key: Key;
|
|
61
|
+
/** In a patch, the entry this one replaced: `base` in its formulas. */
|
|
62
|
+
base?: Entry;
|
|
63
|
+
/** What the marker function returned, once the file is loaded. */
|
|
64
|
+
marked?: {
|
|
65
|
+
value: unknown;
|
|
66
|
+
};
|
|
67
|
+
/** The formula as `feelin` gets it, when that is not the text written: a function whose parameters are in its key. */
|
|
68
|
+
formula?: string;
|
|
69
|
+
constructor(raw: string, value: Node, map: MapNode, file: string, line: number, column: number);
|
|
70
|
+
get name(): string;
|
|
71
|
+
path(): string;
|
|
72
|
+
}
|
|
73
|
+
export declare class MapNode extends Node {
|
|
74
|
+
readonly entries: Entry[];
|
|
75
|
+
/** The shape of the schema this map was checked against. */
|
|
76
|
+
shape?: Shape;
|
|
77
|
+
/** The entry with this name, whatever its marker. */
|
|
78
|
+
get(name: string): Entry | undefined;
|
|
79
|
+
/** Like `get`, and also a key that only a `$when` case adds. */
|
|
80
|
+
find(name: string): Entry | undefined;
|
|
81
|
+
/** The cases of this map's `$when`. */
|
|
82
|
+
cases(): MapNode[];
|
|
83
|
+
/** A plain value of this map, such as its `id`. */
|
|
84
|
+
scalar(name: string): unknown;
|
|
85
|
+
/** Adds an entry. `at` is its position; the end when omitted. */
|
|
86
|
+
set(raw: string, value: Node, from: Located, at?: number): Entry;
|
|
87
|
+
remove(entry: Entry): void;
|
|
88
|
+
toData(): Record<string, unknown>;
|
|
89
|
+
clone(): MapNode;
|
|
90
|
+
}
|
|
91
|
+
export declare class ListNode extends Node {
|
|
92
|
+
readonly items: Node[];
|
|
93
|
+
/** The field that names an item: `id`, unless a schema says otherwise. */
|
|
94
|
+
keyField: string;
|
|
95
|
+
add(item: Node, at?: number): void;
|
|
96
|
+
byId(id: string): MapNode | undefined;
|
|
97
|
+
/** How an item is named in a path: `.explore` by id, `[2]` by position. */
|
|
98
|
+
label(item: Node): string;
|
|
99
|
+
toData(): unknown[];
|
|
100
|
+
clone(): ListNode;
|
|
101
|
+
}
|
package/dist/patch.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { MapNode } from './node.js';
|
|
2
|
+
import type { Problems } from './problem.js';
|
|
3
|
+
/** Applies a file that starts with `$extends` to its base. The base tree is changed in place. */
|
|
4
|
+
export declare class Patch {
|
|
5
|
+
private readonly patch;
|
|
6
|
+
private readonly base;
|
|
7
|
+
private readonly problems;
|
|
8
|
+
/** Keys of the patch's top level that are merged into the base, not matched against it. */
|
|
9
|
+
private static readonly merged;
|
|
10
|
+
private static readonly replaced;
|
|
11
|
+
constructor(patch: MapNode, base: MapNode, problems: Problems);
|
|
12
|
+
apply(): void;
|
|
13
|
+
/** Puts an entry of the patch into a base map, in place of the one with its name when there is one. */
|
|
14
|
+
private put;
|
|
15
|
+
private merge;
|
|
16
|
+
/** Applies the changes written in one map of the patch to the node of the base they point at. */
|
|
17
|
+
private change;
|
|
18
|
+
private child;
|
|
19
|
+
private descend;
|
|
20
|
+
private replace;
|
|
21
|
+
private remove;
|
|
22
|
+
private insert;
|
|
23
|
+
/** A new item of a list: the fields written in the patch, and its name as the list's key field. */
|
|
24
|
+
private named;
|
|
25
|
+
private text;
|
|
26
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type Severity = 'error' | 'warning';
|
|
2
|
+
/** Anything in a file a problem can point at: a node or a key. */
|
|
3
|
+
export interface Located {
|
|
4
|
+
readonly file: string;
|
|
5
|
+
readonly line: number;
|
|
6
|
+
readonly column: number;
|
|
7
|
+
path(): string;
|
|
8
|
+
}
|
|
9
|
+
/** One thing wrong with a file: where it is, and what. */
|
|
10
|
+
export declare class Problem {
|
|
11
|
+
readonly file: string;
|
|
12
|
+
readonly line: number;
|
|
13
|
+
readonly column: number;
|
|
14
|
+
/** Path of the key, as written in the file. */
|
|
15
|
+
readonly key: string;
|
|
16
|
+
readonly message: string;
|
|
17
|
+
readonly severity: Severity;
|
|
18
|
+
constructor(file: string, line: number, column: number,
|
|
19
|
+
/** Path of the key, as written in the file. */
|
|
20
|
+
key: string, message: string, severity?: Severity);
|
|
21
|
+
toString(): string;
|
|
22
|
+
}
|
|
23
|
+
/** Collects the problems of one validation or one resolve. */
|
|
24
|
+
export declare class Problems {
|
|
25
|
+
readonly list: Problem[];
|
|
26
|
+
error(at: Located, message: string): void;
|
|
27
|
+
warning(at: Located, message: string): void;
|
|
28
|
+
add(at: Located, message: string, severity: Severity): void;
|
|
29
|
+
/** Puts the problems in reading order: file by file as first met, then by line. */
|
|
30
|
+
sort(): void;
|
|
31
|
+
get errors(): Problem[];
|
|
32
|
+
get failed(): boolean;
|
|
33
|
+
}
|
|
34
|
+
/** Base of the errors the library throws. It always carries the problems that caused it. */
|
|
35
|
+
export declare abstract class ScriptedYamlError extends Error {
|
|
36
|
+
readonly problems: Problem[];
|
|
37
|
+
constructor(problems: Problem[], options?: ErrorOptions);
|
|
38
|
+
}
|
|
39
|
+
/** Thrown by `parse` and `load` when a file has errors. */
|
|
40
|
+
export declare class ValidationFailed extends ScriptedYamlError {
|
|
41
|
+
}
|
|
42
|
+
/** Thrown by `resolve` when values are missing or a formula fails. */
|
|
43
|
+
export declare class ResolveFailed extends ScriptedYamlError {
|
|
44
|
+
}
|
package/dist/reader.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { MapNode } from './node.js';
|
|
2
|
+
import type { Problems } from './problem.js';
|
|
3
|
+
/** Turns what the application passed (text, or data already parsed) into the tree the library works on. */
|
|
4
|
+
export declare abstract class SourceReader {
|
|
5
|
+
protected readonly file: string;
|
|
6
|
+
protected readonly problems: Problems;
|
|
7
|
+
constructor(file: string, problems: Problems);
|
|
8
|
+
/** The root map, or undefined when the input cannot be used. Problems are collected. */
|
|
9
|
+
abstract read(): MapNode | undefined;
|
|
10
|
+
static for(input: unknown, file: string, problems: Problems): SourceReader;
|
|
11
|
+
protected notAMap(): undefined;
|
|
12
|
+
}
|
|
13
|
+
/** YAML text, read by the `yaml` package. Every node keeps its line. */
|
|
14
|
+
export declare class YamlTextReader extends SourceReader {
|
|
15
|
+
private readonly text;
|
|
16
|
+
private readonly lines;
|
|
17
|
+
private document;
|
|
18
|
+
constructor(text: string, file: string, problems: Problems);
|
|
19
|
+
read(): MapNode | undefined;
|
|
20
|
+
private report;
|
|
21
|
+
private at;
|
|
22
|
+
private convert;
|
|
23
|
+
}
|
|
24
|
+
/** Data that something else parsed, such as the front matter `mdq-cli` returns. There are no lines. */
|
|
25
|
+
export declare class DataReader extends SourceReader {
|
|
26
|
+
private readonly data;
|
|
27
|
+
constructor(data: unknown, file: string, problems: Problems);
|
|
28
|
+
read(): MapNode | undefined;
|
|
29
|
+
private convert;
|
|
30
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { Imported } from './importers.js';
|
|
2
|
+
import { Source } from './source.js';
|
|
3
|
+
/** One call of `resolve`: all variables in, all values out. Each formula is computed when first read, once. */
|
|
4
|
+
export declare class Resolution {
|
|
5
|
+
private readonly source;
|
|
6
|
+
private readonly imports;
|
|
7
|
+
private readonly input;
|
|
8
|
+
private readonly scope;
|
|
9
|
+
private readonly top;
|
|
10
|
+
private readonly vars;
|
|
11
|
+
/** The values of marker results that a formula read: their text, with "1" as true and "0" as false. */
|
|
12
|
+
private readonly read;
|
|
13
|
+
private readonly definitions;
|
|
14
|
+
private readonly defining;
|
|
15
|
+
private readonly guards;
|
|
16
|
+
private readonly documents;
|
|
17
|
+
/** Imported functions that returned a promise during the formula being computed. */
|
|
18
|
+
private readonly promised;
|
|
19
|
+
private readonly broken;
|
|
20
|
+
private readonly afterwards;
|
|
21
|
+
constructor(source: Source, imports: Map<string, Imported>, input: Record<string, unknown>);
|
|
22
|
+
/** The whole file as plain data: no formulas left, structure keywords applied. */
|
|
23
|
+
run(): Record<string, unknown>;
|
|
24
|
+
/** The file as a formula of another file sees it: a node with `$value` is that value. */
|
|
25
|
+
view(): unknown;
|
|
26
|
+
/** Computes one more formula at the top of the file, such as a path under `expect` in `$tests`. */
|
|
27
|
+
probe(source: string): unknown;
|
|
28
|
+
private output;
|
|
29
|
+
private viewOf;
|
|
30
|
+
private entryView;
|
|
31
|
+
/** A marker's result as a formula reads it: its toString(); "1" is true and "0" is false. Asked once. */
|
|
32
|
+
private markerValue;
|
|
33
|
+
private kept;
|
|
34
|
+
private flag;
|
|
35
|
+
/** The items of a list as they are in the result: `$each!` repeated, `$if!` and `$unless!` applied. */
|
|
36
|
+
private items;
|
|
37
|
+
/** The entries of a map after its `$when` cases: every case that matches applies, in order; `$else` when none did. */
|
|
38
|
+
private effective;
|
|
39
|
+
/** The rules of a schema, checked on one item. A marked field is seen as written: its function's result is not asked. */
|
|
40
|
+
private checkRules;
|
|
41
|
+
private compute;
|
|
42
|
+
/** Computes one formula. Any warning of `feelin` is an error, except reading a field of null. */
|
|
43
|
+
private evaluate;
|
|
44
|
+
/** Hands one formula to `feelin`, with a context that holds exactly what the formula reads. */
|
|
45
|
+
private feel;
|
|
46
|
+
private context;
|
|
47
|
+
/** A function of `$functions`, as the FEEL function `feelin` makes of it. Its warnings arrive later, when it is called. */
|
|
48
|
+
private definition;
|
|
49
|
+
/** An imported name. A function that is called is watched: it may not return a promise. */
|
|
50
|
+
private imported;
|
|
51
|
+
private problem;
|
|
52
|
+
private fail;
|
|
53
|
+
}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Formula } from './expression.js';
|
|
2
|
+
import { MapNode, type Node } from './node.js';
|
|
3
|
+
import type { Located, Problems } from './problem.js';
|
|
4
|
+
/** One word of a schema: `title`, `agents*`, `launch:Look`, `rules*:Rule`. */
|
|
5
|
+
export declare class Field {
|
|
6
|
+
readonly required: boolean;
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly many: boolean;
|
|
9
|
+
readonly type: string | undefined;
|
|
10
|
+
constructor(word: string, required: boolean);
|
|
11
|
+
}
|
|
12
|
+
/** A check across the fields of one item: `valid!` must be true, or `message` is shown. */
|
|
13
|
+
export declare class Rule {
|
|
14
|
+
readonly message: string;
|
|
15
|
+
readonly formula: Formula;
|
|
16
|
+
constructor(source: string, message: string);
|
|
17
|
+
}
|
|
18
|
+
/** The fields a map may have. */
|
|
19
|
+
export declare class Shape {
|
|
20
|
+
readonly name: string;
|
|
21
|
+
readonly fields: Map<string, Field>;
|
|
22
|
+
readonly rules: Rule[];
|
|
23
|
+
/** The field that names an item of this shape. */
|
|
24
|
+
readonly key: string;
|
|
25
|
+
/** Per field, the names the application supplies when it computes that field. */
|
|
26
|
+
readonly with: Record<string, string[]>;
|
|
27
|
+
constructor(name: string, data: Record<string, unknown>, at: Located, problems: Problems);
|
|
28
|
+
static words(list: unknown): string[];
|
|
29
|
+
private add;
|
|
30
|
+
private rule;
|
|
31
|
+
}
|
|
32
|
+
/** A `$schema`: which keys a file has. Short by design: everything is text unless marked. */
|
|
33
|
+
export declare class Schema {
|
|
34
|
+
readonly root: Shape;
|
|
35
|
+
private readonly shapes;
|
|
36
|
+
private readonly words;
|
|
37
|
+
constructor(node: Node, problems: Problems);
|
|
38
|
+
/** Checks a file against the schema and notes on each map the shape it has. */
|
|
39
|
+
check(root: MapNode, problems: Problems): void;
|
|
40
|
+
private fit;
|
|
41
|
+
private value;
|
|
42
|
+
private one;
|
|
43
|
+
}
|
package/dist/scope.d.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { Ref } from './lazy-formula.js';
|
|
2
|
+
import type { ImportSpec } from './importers.js';
|
|
3
|
+
import { type Entry, MapNode, type Node } from './node.js';
|
|
4
|
+
import { Source } from './source.js';
|
|
5
|
+
/** What a name in a formula stands for. */
|
|
6
|
+
export type Target = {
|
|
7
|
+
kind: 'unknown';
|
|
8
|
+
} | {
|
|
9
|
+
kind: 'builtin';
|
|
10
|
+
}
|
|
11
|
+
/** `vars`: the variables the application passes. */
|
|
12
|
+
| {
|
|
13
|
+
kind: 'vars';
|
|
14
|
+
}
|
|
15
|
+
/** The `$as` name of a `$each!` item. */
|
|
16
|
+
| {
|
|
17
|
+
kind: 'each';
|
|
18
|
+
owner: MapNode;
|
|
19
|
+
}
|
|
20
|
+
/** A name a schema says the application supplies (`with`). */
|
|
21
|
+
| {
|
|
22
|
+
kind: 'given';
|
|
23
|
+
}
|
|
24
|
+
/** `base` in a patch: the entry that was replaced. */
|
|
25
|
+
| {
|
|
26
|
+
kind: 'base';
|
|
27
|
+
entry: Entry;
|
|
28
|
+
} | {
|
|
29
|
+
kind: 'function';
|
|
30
|
+
entry: Entry;
|
|
31
|
+
} | {
|
|
32
|
+
kind: 'import';
|
|
33
|
+
spec: ImportSpec;
|
|
34
|
+
}
|
|
35
|
+
/** A key of the file. */
|
|
36
|
+
| {
|
|
37
|
+
kind: 'key';
|
|
38
|
+
entry: Entry;
|
|
39
|
+
};
|
|
40
|
+
/** How far a path such as `stages.explore.when` goes through the file before a value takes over. */
|
|
41
|
+
export declare class Reach {
|
|
42
|
+
entry: Entry | undefined;
|
|
43
|
+
node: Node;
|
|
44
|
+
readonly path: string[];
|
|
45
|
+
/** The path names that were followed through maps and lists of the file. */
|
|
46
|
+
readonly steps: string[];
|
|
47
|
+
/** The node reached after each step; the first is the value of the head key. */
|
|
48
|
+
readonly nodes: Node[];
|
|
49
|
+
/** A path name that is not a key of the map it was looked up in. */
|
|
50
|
+
missing?: {
|
|
51
|
+
name: string;
|
|
52
|
+
map: MapNode;
|
|
53
|
+
};
|
|
54
|
+
constructor(entry: Entry | undefined, node: Node, path: string[]);
|
|
55
|
+
/** The path names left for FEEL to follow inside the value. */
|
|
56
|
+
get rest(): string[];
|
|
57
|
+
}
|
|
58
|
+
/** Finds what a name means at a place in the file (SPEC 3.4). */
|
|
59
|
+
export declare class Scope {
|
|
60
|
+
private readonly source;
|
|
61
|
+
constructor(source: Source);
|
|
62
|
+
resolve(reader: Node, ref: Ref): Target;
|
|
63
|
+
/** Follows a path from a key through the maps and lists of the file. `find` picks a key of a map. */
|
|
64
|
+
walk(start: Entry, path: string[], find?: (map: MapNode, name: string) => Entry | undefined): Reach;
|
|
65
|
+
/** The names a formula at this place could have meant, for "did you mean". */
|
|
66
|
+
names(reader: Node): string[];
|
|
67
|
+
/** The name a `$each!` item gives each value: its `$as`, or `item`. */
|
|
68
|
+
static eachName(item: MapNode): string;
|
|
69
|
+
private callable;
|
|
70
|
+
/** The maps a bare name is looked up in: the one around the formula, each enclosing one, the root. */
|
|
71
|
+
private maps;
|
|
72
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Document, type Marker } from './document.js';
|
|
2
|
+
import { Problem } from './problem.js';
|
|
3
|
+
export interface ScriptedYamlOptions {
|
|
4
|
+
/**
|
|
5
|
+
* One function per marker name (`run!sh:` calls `sh`), or only the names where files are just checked.
|
|
6
|
+
* This is the only thing an application registers: functions come from each file's `$import`.
|
|
7
|
+
*/
|
|
8
|
+
markers?: Record<string, Marker> | string[];
|
|
9
|
+
}
|
|
10
|
+
export interface FileOptions {
|
|
11
|
+
/** The name of the file, for problems, and the place its `$dsl`, `$extends` and `$import` paths start from. */
|
|
12
|
+
file?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Validates and loads scripted-yaml files. It computes nothing: see `Document.resolve`. */
|
|
15
|
+
export declare class ScriptedYaml {
|
|
16
|
+
private readonly markers;
|
|
17
|
+
constructor(options?: ScriptedYamlOptions);
|
|
18
|
+
/** Checks a file and returns the problems. Runs nothing: no marker function, no formula, no import. */
|
|
19
|
+
validate(path: string): Promise<Problem[]>;
|
|
20
|
+
/** The same check for text that is not in a file (or data already parsed). `file` names it in the problems. */
|
|
21
|
+
validateText(input: unknown, options?: FileOptions): Promise<Problem[]>;
|
|
22
|
+
/** Reads a file, validates it, applies `$extends`, loads each `$import` and calls each marker's function. No formula is computed. */
|
|
23
|
+
load(path: string): Promise<Document>;
|
|
24
|
+
/** The same for text that is not in a file (or data already parsed). */
|
|
25
|
+
loadText(input: unknown, options?: FileOptions): Promise<Document>;
|
|
26
|
+
private check;
|
|
27
|
+
private readFile;
|
|
28
|
+
/** `chain` holds the files being loaded on the way here, to stop an import that comes back to itself. */
|
|
29
|
+
private open;
|
|
30
|
+
}
|
package/dist/source.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ImportSpec } from './importers.js';
|
|
2
|
+
import { type Entry, MapNode } from './node.js';
|
|
3
|
+
import type { Problems } from './problem.js';
|
|
4
|
+
import { Schema } from './schema.js';
|
|
5
|
+
import { Variables } from './variables.js';
|
|
6
|
+
/** One file as written: its tree after `$extends`, and what its top `$` keys say. Nothing is computed. */
|
|
7
|
+
export declare class Source {
|
|
8
|
+
readonly file: string;
|
|
9
|
+
readonly root: MapNode;
|
|
10
|
+
private readonly loader;
|
|
11
|
+
private readonly problems;
|
|
12
|
+
/** `$` keys that are words of the language at the top of a file, not data. */
|
|
13
|
+
static readonly rootKeywords: string[];
|
|
14
|
+
readonly variables: Variables;
|
|
15
|
+
/** `$functions`, by name. */
|
|
16
|
+
readonly functions: Map<string, Entry>;
|
|
17
|
+
readonly imports: ImportSpec[];
|
|
18
|
+
/** Every imported name, with the line of `$import` that brings it. */
|
|
19
|
+
readonly imported: Map<string, ImportSpec>;
|
|
20
|
+
schema?: Schema;
|
|
21
|
+
constructor(file: string, root: MapNode, loader: SourceLoader, problems: Problems);
|
|
22
|
+
/** The entries that are the file's data: everything but the top keywords. */
|
|
23
|
+
get data(): Entry[];
|
|
24
|
+
/** The `$tests` of the file, as plain data. */
|
|
25
|
+
get tests(): unknown[];
|
|
26
|
+
private readFunctions;
|
|
27
|
+
private readImports;
|
|
28
|
+
/** Reads the DSL file named by `$dsl`: the variables it makes known, and its tree for the schema. */
|
|
29
|
+
private readDsl;
|
|
30
|
+
}
|
|
31
|
+
/** Reads a file and the files it names with `$extends` and `$dsl`. */
|
|
32
|
+
export declare class SourceLoader {
|
|
33
|
+
private readonly problems;
|
|
34
|
+
constructor(problems: Problems);
|
|
35
|
+
/** The source for text or data. Undefined when it cannot be read at all; the problems say why. */
|
|
36
|
+
load(input: unknown, file: string): Source | undefined;
|
|
37
|
+
/** Where a path written in a file points: beside that file. */
|
|
38
|
+
absolute(file: string, path: string): string;
|
|
39
|
+
/** Reads the tree of a file that another file names. A problem is reported on the line that names it. */
|
|
40
|
+
read(from: Entry, path: string, chain?: string[]): MapNode | undefined;
|
|
41
|
+
private tree;
|
|
42
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type Node } from './node.js';
|
|
2
|
+
import type { Problems } from './problem.js';
|
|
3
|
+
/** One variable a file declares under `$vars`. */
|
|
4
|
+
export declare class Variable {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly optional: boolean;
|
|
7
|
+
readonly secret: boolean;
|
|
8
|
+
readonly host: boolean;
|
|
9
|
+
readonly type: string | undefined;
|
|
10
|
+
readonly about: string | undefined;
|
|
11
|
+
readonly default: unknown;
|
|
12
|
+
constructor(name: string, settings: Record<string, unknown>);
|
|
13
|
+
/** The application must pass it: it has no default and is not optional. */
|
|
14
|
+
get required(): boolean;
|
|
15
|
+
/** Why a value does not fit the declared type; undefined when it fits or the type is not one we know. */
|
|
16
|
+
mismatch(value: unknown): string | undefined;
|
|
17
|
+
}
|
|
18
|
+
/** The inputs of a file: what `$vars` declares, and the names a DSL makes known. */
|
|
19
|
+
export declare class Variables {
|
|
20
|
+
readonly declared: Map<string, Variable>;
|
|
21
|
+
private readonly patterns;
|
|
22
|
+
private readonly known;
|
|
23
|
+
/** Reads a `$vars` map. With `forChecking`, the names only become known: a DSL gives no value and asks for none. */
|
|
24
|
+
add(node: Node | undefined, problems: Problems, forChecking?: boolean): this;
|
|
25
|
+
/** True when `vars.NAME` is no typo: declared, matched by a pattern, or known from a DSL. */
|
|
26
|
+
knows(name: string): boolean;
|
|
27
|
+
/** The values formulas see: defaults filled in, empty text turned into null. */
|
|
28
|
+
values(input: Record<string, unknown>): {
|
|
29
|
+
values: Record<string, unknown>;
|
|
30
|
+
missing: string[];
|
|
31
|
+
mismatches: string[];
|
|
32
|
+
};
|
|
33
|
+
private declare;
|
|
34
|
+
private pattern;
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scripted-yaml",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "YAML files with marked formulas (FEEL): validate, parse, load, resolve.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/DavertMik/scripted-yaml.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/DavertMik/scripted-yaml#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/DavertMik/scripted-yaml/issues"
|
|
13
|
+
},
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./package.json": "./package.json"
|
|
23
|
+
},
|
|
24
|
+
"bin": {
|
|
25
|
+
"scripted-yaml": "./dist/cli.js"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"skills",
|
|
30
|
+
"README.md",
|
|
31
|
+
"LICENSE"
|
|
32
|
+
],
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=22"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"test": "bun test",
|
|
38
|
+
"typecheck": "tsc --noEmit",
|
|
39
|
+
"build": "rm -rf dist && bun build src/index.ts src/cli.ts --outdir dist --target node --packages external && tsc -p tsconfig.build.json",
|
|
40
|
+
"prepublishOnly": "bun run typecheck && bun test && bun run build"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"feelers": "^3.2.0",
|
|
44
|
+
"feelin": "^8.2.2",
|
|
45
|
+
"mdq-cli": "^0.1.4",
|
|
46
|
+
"yaml": "^2.8.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/bun": "latest",
|
|
50
|
+
"typescript": "^5.6.0"
|
|
51
|
+
},
|
|
52
|
+
"keywords": [
|
|
53
|
+
"yaml",
|
|
54
|
+
"feel",
|
|
55
|
+
"dmn",
|
|
56
|
+
"expressions",
|
|
57
|
+
"config",
|
|
58
|
+
"dsl",
|
|
59
|
+
"rules",
|
|
60
|
+
"pipeline",
|
|
61
|
+
"frontmatter"
|
|
62
|
+
]
|
|
63
|
+
}
|