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.
@@ -0,0 +1,42 @@
1
+ import type { Imported } from './importers.js';
2
+ import { type Problems } from './problem.js';
3
+ import type { Source } from './source.js';
4
+ import type { Variable } from './variables.js';
5
+ /** The application's function for one marker. It receives the value as written; what it returns becomes the value. */
6
+ export type Marker = (source: any) => unknown;
7
+ /** The result of one test of `$tests`. */
8
+ export declare class TestResult {
9
+ readonly about: string;
10
+ /** One line per expectation that did not hold. Empty when the test passed. */
11
+ readonly failures: string[];
12
+ constructor(about: string,
13
+ /** One line per expectation that did not hold. Empty when the test passed. */
14
+ failures: string[]);
15
+ get passed(): boolean;
16
+ }
17
+ /** A loaded file: its data with formulas kept as formulas, and the way to compute them. */
18
+ export declare class Document {
19
+ readonly file: string;
20
+ private readonly source;
21
+ private readonly imports;
22
+ /**
23
+ * The file as data, markers removed from the key names. A `key!:` is a `Formula`, text with `{{ }}`
24
+ * is a `Text`, a `key!name:` is what the marker function returned.
25
+ */
26
+ readonly data: any;
27
+ constructor(file: string, source: Source, imports: Map<string, Imported>, markers: Record<string, Marker | undefined>, problems: Problems);
28
+ /** The variables the file declares under `$vars`. */
29
+ get variables(): Variable[];
30
+ /**
31
+ * All variables in, all values out: the whole file as plain data, every formula computed,
32
+ * `$if` / `$unless` / `$each` / `$when` applied. Throws `ResolveFailed`.
33
+ */
34
+ resolve(options?: {
35
+ vars?: Record<string, unknown>;
36
+ }): Promise<any>;
37
+ /** Runs the file's `$tests`: each resolves the file with its `vars` and compares the paths under `expect`. */
38
+ test(): Promise<TestResult[]>;
39
+ /** The file as a formula of another file reads it, when it is imported with `$import`. */
40
+ view(vars: Record<string, unknown>): unknown;
41
+ private mark;
42
+ }
@@ -0,0 +1,47 @@
1
+ import { LazyFormula } from './lazy-formula.js';
2
+ /** Something in a file that is computed later: a formula, or text with `{{ }}`. */
3
+ export declare abstract class Expression {
4
+ /** The formula or the text, as written in the file. */
5
+ readonly source: string;
6
+ /** The names it reads, as written: `vars.URL`, `prerequisites.staging`. Filled when the file is checked. */
7
+ reads: string[];
8
+ constructor(
9
+ /** The formula or the text, as written in the file. */
10
+ source: string);
11
+ /** Why it cannot be used. Empty when it is fine. */
12
+ abstract get errors(): string[];
13
+ /** Each FEEL formula it holds, as the names it reads. */
14
+ abstract get formulas(): LazyFormula[];
15
+ toString(): string;
16
+ toJSON(): {
17
+ source: string;
18
+ reads: string[];
19
+ };
20
+ }
21
+ /** The value of a `key!:`. One FEEL expression. */
22
+ export declare class Formula extends Expression {
23
+ get errors(): string[];
24
+ get formulas(): LazyFormula[];
25
+ }
26
+ /** One `{{ }}` of a text: where it starts and ends, and its formula. */
27
+ export declare class TextBlock {
28
+ readonly from: number;
29
+ readonly to: number;
30
+ readonly formula: LazyFormula;
31
+ constructor(from: number, to: number, formula: LazyFormula);
32
+ }
33
+ /** Plain text with `{{ }}` in it. `feelers` finds the blocks; each block is one FEEL formula. */
34
+ export declare class Text extends Expression {
35
+ readonly blocks: TextBlock[];
36
+ private readonly problems;
37
+ constructor(source: string);
38
+ /** True when a string holds `{{`, so it has to be read as a template. */
39
+ static in(value: unknown): value is string;
40
+ get errors(): string[];
41
+ get formulas(): LazyFormula[];
42
+ /** The text with each block replaced by the value `compute` gives for it. */
43
+ render(compute: (block: TextBlock) => unknown): string;
44
+ private static show;
45
+ private fail;
46
+ private collect;
47
+ }
@@ -0,0 +1,66 @@
1
+ import type { Document } from './document.js';
2
+ import type { Entry } from './node.js';
3
+ /** One line of `$import`: a path and the names taken from it. */
4
+ export declare class ImportSpec {
5
+ /** The path as written in the file. */
6
+ readonly path: string;
7
+ readonly absolute: string;
8
+ /** What is written beside the path: a list of names, or one name. */
9
+ readonly wanted: unknown;
10
+ readonly entry: Entry;
11
+ constructor(
12
+ /** The path as written in the file. */
13
+ path: string, absolute: string,
14
+ /** What is written beside the path: a list of names, or one name. */
15
+ wanted: unknown, entry: Entry);
16
+ }
17
+ /** A name a file imported, and what it stands for. */
18
+ export declare class Imported {
19
+ readonly name: string;
20
+ /** A function, data, or (for a scripted-yaml file) the loaded document. */
21
+ readonly value: unknown;
22
+ readonly document: boolean;
23
+ constructor(name: string,
24
+ /** A function, data, or (for a scripted-yaml file) the loaded document. */
25
+ value: unknown, document?: boolean);
26
+ }
27
+ /** An import that cannot be done. The message is shown on the line of the import. */
28
+ export declare class ImportFailed extends Error {
29
+ }
30
+ /** What an importer may ask of the library: to load another scripted-yaml file. */
31
+ export interface ImportHost {
32
+ document(absolute: string): Promise<Document>;
33
+ }
34
+ /** Brings names from another file into a formula. One importer per kind of file, chosen by extension. */
35
+ export declare abstract class Importer {
36
+ private static readonly all;
37
+ /** The extensions this importer reads, with the dot. */
38
+ abstract readonly extensions: string[];
39
+ /** The names a spec brings in, read from the file's text alone. Throws ImportFailed when the spec is wrong. */
40
+ abstract names(spec: ImportSpec): string[];
41
+ /** Opens the file and returns what each name stands for. Throws ImportFailed. */
42
+ abstract load(spec: ImportSpec, host: ImportHost): Promise<Imported[]>;
43
+ static for(path: string): Importer | undefined;
44
+ static get supported(): string[];
45
+ /** A path that does not exist is a problem; where there is no disk, so is every path. */
46
+ exists(spec: ImportSpec): boolean;
47
+ protected oneName(spec: ImportSpec): string[];
48
+ }
49
+ /** `.ts` and `.js`: each listed name is an export of the module. */
50
+ export declare class ModuleImporter extends Importer {
51
+ readonly extensions: string[];
52
+ names(spec: ImportSpec): string[];
53
+ load(spec: ImportSpec): Promise<Imported[]>;
54
+ }
55
+ /** `.yml` and `.yaml`: one name for the file's data. The file is loaded as a scripted-yaml file. */
56
+ export declare class YamlImporter extends Importer {
57
+ readonly extensions: string[];
58
+ names(spec: ImportSpec): string[];
59
+ load(spec: ImportSpec, host: ImportHost): Promise<Imported[]>;
60
+ }
61
+ /** `.md`: one name, a function from an `mdq-cli` selector to the Markdown it picks. */
62
+ export declare class MarkdownImporter extends Importer {
63
+ readonly extensions: string[];
64
+ names(spec: ImportSpec): string[];
65
+ load(spec: ImportSpec): Promise<Imported[]>;
66
+ }
@@ -0,0 +1,5 @@
1
+ export { Document, type Marker, TestResult } from './document.js';
2
+ export { Expression, Formula, Text } from './expression.js';
3
+ export { Problem, ResolveFailed, ScriptedYamlError, type Severity, ValidationFailed } from './problem.js';
4
+ export { type FileOptions, ScriptedYaml, type ScriptedYamlOptions } from './scripted-yaml.js';
5
+ export { Variable } from './variables.js';