@deepseek-ai/cordis-plugin-include 1.1.0 → 1.2.0-alpha.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 +9 -3
- package/lib/index.js +410 -167
- package/lib/types/index.d.ts +47 -9
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/patch.d.ts +21 -20
- package/lib/types/patch.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/index.ts +279 -61
- package/src/patch.ts +148 -135
package/lib/types/index.d.ts
CHANGED
|
@@ -1,18 +1,51 @@
|
|
|
1
|
-
import { type EntryChange, EntryTree, EntryGroup } from '@deepseek-ai/cordis-plugin-loader';
|
|
1
|
+
import { type EntryChange, EntryTree, EntryGroup, type SourceLocation } from '@deepseek-ai/cordis-plugin-loader';
|
|
2
2
|
import { Context, Service } from '@deepseek-ai/cordis';
|
|
3
|
-
import * as yaml from 'js-yaml';
|
|
4
3
|
import { type PatchOptions } from './patch.ts';
|
|
5
4
|
/** Shared patch semantics used by config dumps and mounting. */
|
|
6
5
|
export { applyPatches as applyEntryPatches } from './patch.ts';
|
|
7
|
-
/** Serialized entry patch options. */
|
|
8
|
-
export type { PatchOptions } from './patch.ts';
|
|
9
|
-
/**
|
|
10
|
-
export
|
|
6
|
+
/** Serialized entry patch options and the composed result of applying them. */
|
|
7
|
+
export type { PatchOptions, PatchResult } from './patch.ts';
|
|
8
|
+
/** Options for {@link stringifyEntryYaml}. */
|
|
9
|
+
export interface EntryYamlStringifyOptions {
|
|
10
|
+
/** Column at which long scalars are folded; `-1` disables folding. Defaults to 80. */
|
|
11
|
+
lineWidth?: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Parse text in Include's YAML dialect: YAML 1.2 under the core schema, plus `!!js`. A `!!js` scalar becomes a
|
|
15
|
+
* child-owned JavaScript expression node that stays literal until its owning Loader entry evaluates it. Include
|
|
16
|
+
* reads its own file with the same options.
|
|
17
|
+
* @param content - YAML source text.
|
|
18
|
+
* @returns the parsed value, or `undefined` for an empty document.
|
|
19
|
+
* @throws the first parse error, or the first warning such as an unknown tag; {@link entryYamlErrorPosition} reads its location.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseEntryYaml(content: string): unknown;
|
|
22
|
+
/**
|
|
23
|
+
* Serialize a value in Include's YAML dialect. JavaScript expression nodes are written as `!!js` scalars. The output
|
|
24
|
+
* never contains anchors or aliases: repeated object references are written out in full, and no option changes this.
|
|
25
|
+
* @param value - entry list, patch list, or entry fragment to serialize.
|
|
26
|
+
* @param options - output formatting.
|
|
27
|
+
* @returns YAML text ending with a newline.
|
|
28
|
+
*/
|
|
29
|
+
export declare function stringifyEntryYaml(value: unknown, options?: EntryYamlStringifyOptions): string;
|
|
30
|
+
/**
|
|
31
|
+
* Locate a parse error thrown by {@link parseEntryYaml}.
|
|
32
|
+
* @param error - any caught value; only a parse error thrown by {@link parseEntryYaml} yields a position.
|
|
33
|
+
* @returns the one-based line and column of the error, or `undefined` when the error carries no source location.
|
|
34
|
+
*/
|
|
35
|
+
export declare function entryYamlErrorPosition(error: unknown): {
|
|
36
|
+
line: number;
|
|
37
|
+
column: number;
|
|
38
|
+
} | undefined;
|
|
11
39
|
type ConfigStage = 'read' | 'parse' | 'validate';
|
|
40
|
+
export interface ConfigIssue {
|
|
41
|
+
message: string;
|
|
42
|
+
location: SourceLocation;
|
|
43
|
+
}
|
|
12
44
|
export declare class ConfigFileError extends Error {
|
|
13
45
|
stage: ConfigStage;
|
|
46
|
+
issues: ConfigIssue[];
|
|
14
47
|
name: string;
|
|
15
|
-
constructor(stage: ConfigStage, path: string, cause: unknown);
|
|
48
|
+
constructor(stage: ConfigStage, path: string, cause: unknown, issues?: ConfigIssue[]);
|
|
16
49
|
}
|
|
17
50
|
export declare namespace Include {
|
|
18
51
|
interface Config {
|
|
@@ -32,6 +65,8 @@ export declare class Include extends EntryTree {
|
|
|
32
65
|
private cache?;
|
|
33
66
|
/** Tree-side changes that have not reached the file yet. */
|
|
34
67
|
private journal;
|
|
68
|
+
/** Where the entries of the applied tree come from. */
|
|
69
|
+
private index?;
|
|
35
70
|
/** Ids we assigned to entries the file leaves anonymous. */
|
|
36
71
|
private anonymous;
|
|
37
72
|
private dirtyRead;
|
|
@@ -67,11 +102,14 @@ export declare class Include extends EntryTree {
|
|
|
67
102
|
*/
|
|
68
103
|
private _writeText;
|
|
69
104
|
private dump;
|
|
105
|
+
getLocation(id: string, path: PropertyKey[]): SourceLocation | undefined;
|
|
106
|
+
private _locate;
|
|
70
107
|
/**
|
|
71
108
|
* Entries the file leaves anonymous get an id here, before the loader sees
|
|
72
109
|
* them. One that looks exactly like an entry we named on the previous read
|
|
73
|
-
* keeps that id,
|
|
74
|
-
*
|
|
110
|
+
* keeps that id, unless it is already explicitly owned, so editing a
|
|
111
|
+
* neighbor does not restart it; anything else gets a fresh id. Assigned
|
|
112
|
+
* ids stay in memory until the next write.
|
|
75
113
|
*/
|
|
76
114
|
private _assignIds;
|
|
77
115
|
private _scheduleApply;
|
package/lib/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAqB,SAAS,EAAE,UAAU,EAAY,MAAM,mCAAmC,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAqB,SAAS,EAAE,UAAU,EAAY,KAAK,cAAc,EAAE,MAAM,mCAAmC,CAAA;AAC7I,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAYtD,OAAO,EAA6D,KAAK,YAAY,EAAgB,MAAM,YAAY,CAAA;AACvH,gEAAgE;AAChE,OAAO,EAAE,YAAY,IAAI,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAC9D,+EAA+E;AAC/E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string) =>
|
|
|
18
18
|
/** Runtime changes are routed back to an inserted entry by its id, so every insert needs one. */
|
|
19
19
|
export declare function ensureInsertIds(patches: PatchOptions[] | undefined, used: (id: string) => boolean): void;
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
21
|
+
* Who supplies an entry, or one key of it, in the patched tree: the file, a
|
|
22
|
+
* patch that overrides that key, or the patch the entry is written in.
|
|
23
23
|
*/
|
|
24
|
-
export
|
|
25
|
-
/**
|
|
26
|
-
* Who owns an entry, or one key of it, in the patched tree: the file, a patch
|
|
27
|
-
* that overrides that key (the last one wins), or the patch that inserted the
|
|
28
|
-
* whole entry.
|
|
29
|
-
*/
|
|
30
|
-
export type EntryOwner = EntryOwner.File | EntryOwner.Patch | EntryOwner.Insert;
|
|
24
|
+
export type EntryOwner = EntryOwner.File | EntryOwner.Patch | EntryOwner.Embedded;
|
|
31
25
|
export declare namespace EntryOwner {
|
|
32
26
|
interface File {
|
|
33
27
|
type: 'file';
|
|
@@ -37,28 +31,35 @@ export declare namespace EntryOwner {
|
|
|
37
31
|
/** Index into the patch list. */
|
|
38
32
|
index: number;
|
|
39
33
|
}
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
/** An entry written in `patches[index][key]`. */
|
|
35
|
+
interface Embedded {
|
|
36
|
+
type: 'embedded';
|
|
42
37
|
/** Index into the patch list. */
|
|
43
38
|
index: number;
|
|
44
|
-
|
|
45
|
-
list: EntryOptions[];
|
|
46
|
-
options: EntryOptions;
|
|
47
|
-
/** The group the entry is inserted into (`null` for the root). */
|
|
48
|
-
parent: string | null;
|
|
39
|
+
key: 'insert' | 'config';
|
|
49
40
|
}
|
|
50
41
|
}
|
|
42
|
+
/** Where every entry and key of a patched tree comes from. */
|
|
51
43
|
export declare class PatchIndex {
|
|
52
|
-
|
|
44
|
+
private owners;
|
|
53
45
|
private keys;
|
|
54
|
-
|
|
55
|
-
constructor(patches: PatchOptions[]);
|
|
46
|
+
constructor(owners: Map<string, EntryOwner.File | EntryOwner.Embedded>, keys: Map<string, Map<string, number>>);
|
|
56
47
|
/** Owner of the entry as a whole. */
|
|
57
|
-
entry(id: string | null): EntryOwner;
|
|
48
|
+
entry(id: string | null): EntryOwner.File | EntryOwner.Embedded;
|
|
58
49
|
/** Owner of one key of an entry. */
|
|
59
50
|
key(id: string, key: string): EntryOwner;
|
|
60
51
|
fileOwned(id: string, key: string | null): boolean;
|
|
61
52
|
}
|
|
53
|
+
export interface PatchResult {
|
|
54
|
+
data: EntryOptions[];
|
|
55
|
+
index: PatchIndex;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Overlay `patches` onto a fresh clone of `data`. Entry lists from patches
|
|
59
|
+
* are cloned too, so the tree owns every entry it mounts. The index is built
|
|
60
|
+
* in the same pass, so a patch that does not apply owns nothing.
|
|
61
|
+
*/
|
|
62
|
+
export declare function applyPatches(data: EntryOptions[], patches: PatchOptions[] | undefined, warn?: Warn): PatchResult;
|
|
62
63
|
/**
|
|
63
64
|
* Route a journal to its owners: file-owned changes are applied to `data`,
|
|
64
65
|
* patch-owned ones to `patches`. Both are mutated in place, so pass clones.
|
package/lib/types/patch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch.d.ts","sourceRoot":"","sources":["../../src/patch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAErE,OAAO,EAAiC,KAAK,OAAO,EAAS,MAAM,cAAc,CAAA;AAEjF,MAAM,WAAW,YAAY;IAC3B,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,MAAM,CAAC,EAAE,YAAY,EAAE,CAAA;IACvB,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,GAAG,CAAA;IACZ,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;IACtB,QAAQ,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;IACzB,MAAM,CAAC,EA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CAGzC;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,YAAY,EAAE,CAAA;IACpB,KAAK,EAAE,UAAU,CAAA;CAClB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,SAAS,EAAE,IAAI,GAAE,IAAe,GAAG,WAAW,CA6E1H;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,IAAI,EAAE,IAAI,WAqFvG"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseek-ai/cordis-plugin-include",
|
|
3
3
|
"description": "Include files in cordis configurations",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.2.0-alpha.1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"author": "Shigma <shigma10826@gmail.com>",
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@deepseek-ai/cordis-plugin-loader": "~1.
|
|
34
|
-
"@deepseek-ai/cordis": "~4.
|
|
33
|
+
"@deepseek-ai/cordis-plugin-loader": "~1.2.0-alpha.1",
|
|
34
|
+
"@deepseek-ai/cordis": "~4.2.0-alpha.1"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@deepseek-ai/cosmokit": "~1.
|
|
38
|
-
"
|
|
37
|
+
"@deepseek-ai/cosmokit": "~1.10.0-alpha.1",
|
|
38
|
+
"yaml": "^2.9.0"
|
|
39
39
|
}
|
|
40
40
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,29 +1,88 @@
|
|
|
1
|
-
import { type EntryChange, type EntryOptions, EntryTree, EntryGroup, isJsExpr } from '@deepseek-ai/cordis-plugin-loader'
|
|
1
|
+
import { type EntryChange, type EntryOptions, EntryTree, EntryGroup, isJsExpr, type SourceLocation } from '@deepseek-ai/cordis-plugin-loader'
|
|
2
2
|
import { Context, Service } from '@deepseek-ai/cordis'
|
|
3
3
|
import { deepEqual } from '@deepseek-ai/cosmokit'
|
|
4
4
|
import { basename, dirname, extname, join } from 'node:path'
|
|
5
5
|
import { access, constants, readFile, rename, rm, writeFile } from 'node:fs/promises'
|
|
6
6
|
import { setTimeout as sleep } from 'node:timers/promises'
|
|
7
7
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
8
|
-
import
|
|
8
|
+
import {
|
|
9
|
+
isAlias, isMap, isNode, isScalar, isSeq, LineCounter, parseDocument, Scalar, stringify, visit, YAMLError, YAMLParseError,
|
|
10
|
+
type Alias, type Document, type Range, type ScalarTag, type SchemaOptions,
|
|
11
|
+
} from 'yaml'
|
|
12
|
+
import { stringifyString } from 'yaml/util'
|
|
9
13
|
import { applyJournal, flatten, type Journal, merge, reconcile, record } from './journal.ts'
|
|
10
|
-
import { applyPatches, ensureIds, ensureInsertIds, PatchIndex, type PatchOptions, routeJournal } from './patch.ts'
|
|
14
|
+
import { applyPatches, ensureIds, ensureInsertIds, type PatchIndex, type PatchOptions, routeJournal } from './patch.ts'
|
|
11
15
|
/** Shared patch semantics used by config dumps and mounting. */
|
|
12
16
|
export { applyPatches as applyEntryPatches } from './patch.ts'
|
|
13
|
-
/** Serialized entry patch options. */
|
|
14
|
-
export type { PatchOptions } from './patch.ts'
|
|
17
|
+
/** Serialized entry patch options and the composed result of applying them. */
|
|
18
|
+
export type { PatchOptions, PatchResult } from './patch.ts'
|
|
19
|
+
|
|
20
|
+
// A Windows drive-letter path, e.g. `C:\app\cordis.yml` or `C:/app/cordis.yml`.
|
|
21
|
+
const driveLetter = /^[A-Za-z]:[\\/]/
|
|
22
|
+
|
|
23
|
+
const JsExpr: ScalarTag = {
|
|
24
|
+
tag: 'tag:yaml.org,2002:js',
|
|
25
|
+
identify: isJsExpr,
|
|
26
|
+
resolve: (source) => ({ __jsExpr: source }),
|
|
27
|
+
// quoted like any other string
|
|
28
|
+
stringify: (item, ctx, onComment, onChompKeep) => {
|
|
29
|
+
const scalar = new Scalar((item.value as any).__jsExpr)
|
|
30
|
+
return stringifyString(Object.assign(scalar, { type: item.type }), ctx, onComment, onChompKeep)
|
|
31
|
+
},
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const yamlOptions: SchemaOptions = {
|
|
35
|
+
schema: 'core',
|
|
36
|
+
customTags: [JsExpr],
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Options for {@link stringifyEntryYaml}. */
|
|
40
|
+
export interface EntryYamlStringifyOptions {
|
|
41
|
+
/** Column at which long scalars are folded; `-1` disables folding. Defaults to 80. */
|
|
42
|
+
lineWidth?: number
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Parse text in Include's YAML dialect: YAML 1.2 under the core schema, plus `!!js`. A `!!js` scalar becomes a
|
|
47
|
+
* child-owned JavaScript expression node that stays literal until its owning Loader entry evaluates it. Include
|
|
48
|
+
* reads its own file with the same options.
|
|
49
|
+
* @param content - YAML source text.
|
|
50
|
+
* @returns the parsed value, or `undefined` for an empty document.
|
|
51
|
+
* @throws the first parse error, or the first warning such as an unknown tag; {@link entryYamlErrorPosition} reads its location.
|
|
52
|
+
*/
|
|
53
|
+
export function parseEntryYaml(content: string): unknown {
|
|
54
|
+
const lines = new LineCounter()
|
|
55
|
+
const document = parseDocument(content, { ...yamlOptions, lineCounter: lines })
|
|
56
|
+
const [error] = [...document.errors, ...document.warnings, ...unresolvedAliases(document)]
|
|
57
|
+
if (error) {
|
|
58
|
+
// Alias errors carry offsets only; the parser's own errors already carry line positions.
|
|
59
|
+
error.linePos ??= [lines.linePos(error.pos[0]), lines.linePos(error.pos[1])]
|
|
60
|
+
throw error
|
|
61
|
+
}
|
|
62
|
+
return document.contents === null ? undefined : document.toJS()
|
|
63
|
+
}
|
|
15
64
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Serialize a value in Include's YAML dialect. JavaScript expression nodes are written as `!!js` scalars. The output
|
|
67
|
+
* never contains anchors or aliases: repeated object references are written out in full, and no option changes this.
|
|
68
|
+
* @param value - entry list, patch list, or entry fragment to serialize.
|
|
69
|
+
* @param options - output formatting.
|
|
70
|
+
* @returns YAML text ending with a newline.
|
|
71
|
+
*/
|
|
72
|
+
export function stringifyEntryYaml(value: unknown, options: EntryYamlStringifyOptions = {}): string {
|
|
73
|
+
return stringify(value, { ...yamlOptions, singleQuote: true, aliasDuplicateObjects: false, lineWidth: options.lineWidth ?? 80 })
|
|
74
|
+
}
|
|
23
75
|
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Locate a parse error thrown by {@link parseEntryYaml}.
|
|
78
|
+
* @param error - any caught value; only a parse error thrown by {@link parseEntryYaml} yields a position.
|
|
79
|
+
* @returns the one-based line and column of the error, or `undefined` when the error carries no source location.
|
|
80
|
+
*/
|
|
81
|
+
export function entryYamlErrorPosition(error: unknown): { line: number; column: number } | undefined {
|
|
82
|
+
if (!(error instanceof YAMLError) || !error.linePos) return undefined
|
|
83
|
+
const [{ line, col }] = error.linePos
|
|
84
|
+
return { line, column: col }
|
|
85
|
+
}
|
|
27
86
|
|
|
28
87
|
const types: Record<string, string> = {
|
|
29
88
|
'.json': 'application/json',
|
|
@@ -33,16 +92,65 @@ const types: Record<string, string> = {
|
|
|
33
92
|
|
|
34
93
|
type ConfigStage = 'read' | 'parse' | 'validate'
|
|
35
94
|
|
|
95
|
+
/** JSON is parsed as YAML too, for node ranges and line positions. */
|
|
96
|
+
interface Syntax {
|
|
97
|
+
document: Document
|
|
98
|
+
lines: LineCounter
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function parseSyntax(content: string): Syntax {
|
|
102
|
+
const lines = new LineCounter()
|
|
103
|
+
const document = parseDocument(content, { ...yamlOptions, prettyErrors: false, lineCounter: lines })
|
|
104
|
+
return { document, lines }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The parser accepts an alias without a preceding anchor, which only fails in
|
|
109
|
+
* `toJS()` with an unlocated `ReferenceError`. Nodes are visited in document
|
|
110
|
+
* order, so an anchor is known exactly when it precedes the alias.
|
|
111
|
+
*/
|
|
112
|
+
function unresolvedAliases(document: Document) {
|
|
113
|
+
const anchors = new Set<string>()
|
|
114
|
+
const unresolved: Alias[] = []
|
|
115
|
+
visit(document, (_, node) => {
|
|
116
|
+
if (isAlias(node)) {
|
|
117
|
+
if (!anchors.has(node.source)) unresolved.push(node)
|
|
118
|
+
} else if (isNode(node) && node.anchor) {
|
|
119
|
+
anchors.add(node.anchor)
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
// every anchor is known once the scan ends
|
|
123
|
+
return unresolved.map((node) => {
|
|
124
|
+
const [start, end] = node.range!
|
|
125
|
+
const message = anchors.has(node.source)
|
|
126
|
+
? `Alias *${node.source} must follow its anchor`
|
|
127
|
+
: `Unresolved alias: *${node.source}`
|
|
128
|
+
return new YAMLParseError([start, end], 'BAD_ALIAS', message)
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
|
|
36
132
|
interface Snapshot {
|
|
37
133
|
content: string
|
|
38
134
|
data: EntryOptions[]
|
|
135
|
+
/** Parsed on first use. */
|
|
136
|
+
syntax?: Syntax
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// e.g. `at position 17 (line 2 column 16)`
|
|
140
|
+
const jsonPosition = /\s+at position (\d+)(?: \(line \d+ column \d+\))?$/
|
|
141
|
+
|
|
142
|
+
export interface ConfigIssue {
|
|
143
|
+
message: string
|
|
144
|
+
location: SourceLocation
|
|
39
145
|
}
|
|
40
146
|
|
|
41
147
|
export class ConfigFileError extends Error {
|
|
42
148
|
name = 'ConfigFileError'
|
|
43
149
|
|
|
44
|
-
constructor(public stage: ConfigStage, path: string, cause: unknown) {
|
|
45
|
-
super(`failed to ${stage} config file ${path}`, {
|
|
150
|
+
constructor(public stage: ConfigStage, path: string, cause: unknown, public issues: ConfigIssue[] = []) {
|
|
151
|
+
super([`failed to ${stage} config file ${path}`, ...issues.map(({ message, location }) => {
|
|
152
|
+
return ` - ${message} (at ${location.filename}:${location.line}:${location.column})`
|
|
153
|
+
})].join('\n'), { cause })
|
|
46
154
|
}
|
|
47
155
|
}
|
|
48
156
|
|
|
@@ -83,6 +191,50 @@ export namespace Include {
|
|
|
83
191
|
}
|
|
84
192
|
}
|
|
85
193
|
|
|
194
|
+
/** Index path of an entry in a nested entry list. */
|
|
195
|
+
function findEntry(entries: EntryOptions[], id: string): PropertyKey[] | undefined {
|
|
196
|
+
for (const [index, options] of entries.entries()) {
|
|
197
|
+
if (options.id === id) return [index]
|
|
198
|
+
if (!options.group || !Array.isArray(options.config)) continue
|
|
199
|
+
const path = findEntry(options.config, id)
|
|
200
|
+
if (path) return [index, 'config', ...path]
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function findInvalidEntries(entries: unknown[], prefix: PropertyKey[] = []): PropertyKey[][] {
|
|
205
|
+
return entries.flatMap((options: any, index) => {
|
|
206
|
+
if (!options || typeof options !== 'object' || Array.isArray(options)) return [[...prefix, index]]
|
|
207
|
+
if (!options.group || !Array.isArray(options.config)) return []
|
|
208
|
+
return findInvalidEntries(options.config, [...prefix, index, 'config'])
|
|
209
|
+
})
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Range of the node at `path`, or of its deepest ancestor. A collection is
|
|
214
|
+
* represented by the key that holds it.
|
|
215
|
+
*/
|
|
216
|
+
function seek(document: Document, path: PropertyKey[]): Range | null | undefined {
|
|
217
|
+
let node: unknown = document.contents
|
|
218
|
+
let anchor = isNode(node) ? node.range : undefined
|
|
219
|
+
for (const key of path) {
|
|
220
|
+
if (isAlias(node)) node = node.resolve(document)
|
|
221
|
+
if (isMap(node)) {
|
|
222
|
+
const pair = node.items.find(pair => String(isScalar(pair.key) ? pair.key.value : pair.key) === String(key))
|
|
223
|
+
if (!pair) break
|
|
224
|
+
node = pair.value
|
|
225
|
+
if (isNode(pair.key)) anchor = pair.key.range
|
|
226
|
+
} else if (isSeq(node)) {
|
|
227
|
+
const item = node.items[key as number]
|
|
228
|
+
if (!isNode(item)) break
|
|
229
|
+
node = item
|
|
230
|
+
anchor = item.range
|
|
231
|
+
} else {
|
|
232
|
+
break
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return isScalar(node) ? node.range : anchor
|
|
236
|
+
}
|
|
237
|
+
|
|
86
238
|
export class Include extends EntryTree {
|
|
87
239
|
static inject = ['loader']
|
|
88
240
|
|
|
@@ -96,6 +248,8 @@ export class Include extends EntryTree {
|
|
|
96
248
|
private cache?: Snapshot
|
|
97
249
|
/** Tree-side changes that have not reached the file yet. */
|
|
98
250
|
private journal: Journal = new Map()
|
|
251
|
+
/** Where the entries of the applied tree come from. */
|
|
252
|
+
private index?: PatchIndex
|
|
99
253
|
/** Ids we assigned to entries the file leaves anonymous. */
|
|
100
254
|
private anonymous = new Map<string, Anonymous>()
|
|
101
255
|
|
|
@@ -114,7 +268,11 @@ export class Include extends EntryTree {
|
|
|
114
268
|
constructor(ctx: Context, public config: Include.Config) {
|
|
115
269
|
super(ctx)
|
|
116
270
|
this.enableLogs = config.enableLogs ?? ctx.fiber.entry?.parent.tree.enableLogs ?? false
|
|
117
|
-
|
|
271
|
+
// On Windows, a drive-letter path is converted with `pathToFileURL`.
|
|
272
|
+
// `new URL()` would read its `C:` as a URL scheme, which `fileURLToPath` rejects.
|
|
273
|
+
this.filename = fileURLToPath(process.platform === 'win32' && driveLetter.test(this.config.path)
|
|
274
|
+
? pathToFileURL(this.config.path)
|
|
275
|
+
: new URL(this.config.path, this.ctx.baseUrl))
|
|
118
276
|
const ext = extname(this.filename)
|
|
119
277
|
if (!types[ext]) {
|
|
120
278
|
throw new Error(`extension "${ext}" not supported`)
|
|
@@ -133,7 +291,7 @@ export class Include extends EntryTree {
|
|
|
133
291
|
}
|
|
134
292
|
|
|
135
293
|
private warn = (format: string, ...args: any[]) => {
|
|
136
|
-
this.ctx.root.logger?.('loader').warn(format, ...args)
|
|
294
|
+
this.ctx[Context.root].logger?.('loader').warn(format, ...args)
|
|
137
295
|
}
|
|
138
296
|
|
|
139
297
|
async* [Service.init]() {
|
|
@@ -253,30 +411,59 @@ export class Include extends EntryTree {
|
|
|
253
411
|
if (content === this.cache?.content) return
|
|
254
412
|
|
|
255
413
|
let data: any
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
414
|
+
let syntax: Syntax | undefined
|
|
415
|
+
if (this.type === 'application/yaml') {
|
|
416
|
+
syntax = parseSyntax(content)
|
|
417
|
+
const { document, lines } = syntax
|
|
418
|
+
// unknown tags are only warnings to the parser, but leave the data incomplete
|
|
419
|
+
const errors: YAMLError[] = [...document.errors, ...document.warnings, ...unresolvedAliases(document)]
|
|
420
|
+
if (errors.length) {
|
|
421
|
+
const issues = errors.map(error => ({ message: error.message, location: this._locate(lines, error.pos[0]) }))
|
|
422
|
+
throw new ConfigFileError('parse', this.filename, undefined, issues)
|
|
423
|
+
}
|
|
424
|
+
data = document.toJS()
|
|
425
|
+
} else {
|
|
426
|
+
try {
|
|
427
|
+
data = JSON.parse(content)
|
|
428
|
+
} catch (error) {
|
|
429
|
+
const match = error instanceof SyntaxError && error.message.match(jsonPosition)
|
|
430
|
+
if (!match) throw new ConfigFileError('parse', this.filename, error)
|
|
431
|
+
const message = error.message.slice(0, match.index)
|
|
432
|
+
const location = this._locate(parseSyntax(content).lines, +match[1])
|
|
433
|
+
throw new ConfigFileError('parse', this.filename, undefined, [{ message, location }])
|
|
434
|
+
}
|
|
262
435
|
}
|
|
263
436
|
// An empty or truncated file (routine mid-edit) parses to `undefined`, so
|
|
264
437
|
// every non-array shape is rejected here as one "invalid file" signal.
|
|
265
438
|
if (!Array.isArray(data)) {
|
|
266
|
-
|
|
439
|
+
const message = 'config file must be a top-level array'
|
|
440
|
+
const { document, lines } = syntax ?? parseSyntax(content)
|
|
441
|
+
const range = document.contents?.range
|
|
442
|
+
if (!range) throw new ConfigFileError('validate', this.filename, new TypeError(message))
|
|
443
|
+
throw new ConfigFileError('validate', this.filename, undefined, [{ message, location: this._locate(lines, range[0]) }])
|
|
444
|
+
}
|
|
445
|
+
// ids, patches and the journal all assume an entry is an object
|
|
446
|
+
const invalid = findInvalidEntries(data)
|
|
447
|
+
if (invalid.length) {
|
|
448
|
+
const { document, lines } = syntax ?? parseSyntax(content)
|
|
449
|
+
const issues = invalid.map((path) => {
|
|
450
|
+
const range = seek(document, path)
|
|
451
|
+
return { message: 'entry must be an object', location: this._locate(lines, range?.[0] ?? 0) }
|
|
452
|
+
})
|
|
453
|
+
throw new ConfigFileError('validate', this.filename, undefined, issues)
|
|
267
454
|
}
|
|
268
455
|
|
|
269
456
|
this._assignIds(data)
|
|
270
457
|
|
|
271
458
|
if (this.cache) {
|
|
272
|
-
const index =
|
|
459
|
+
const { index } = applyPatches(data, this.config.patches)
|
|
273
460
|
const conflicts = reconcile(this.journal, flatten(this.cache.data), flatten(data), (id, key) => index.fileOwned(id, key))
|
|
274
461
|
for (const { id, reason } of conflicts) {
|
|
275
462
|
this.ctx.logger.error('config conflict in %C: entry %C %s; file wins', this.filename, id, reason)
|
|
276
463
|
}
|
|
277
464
|
}
|
|
278
465
|
|
|
279
|
-
this.cache = { content, data }
|
|
466
|
+
this.cache = { content, data, syntax }
|
|
280
467
|
this._scheduleApply()
|
|
281
468
|
// the file changed while tree-side changes were pending: write the merge
|
|
282
469
|
if (this.journal.size) this.dirtyWrite = true
|
|
@@ -394,60 +581,91 @@ export class Include extends EntryTree {
|
|
|
394
581
|
|
|
395
582
|
private dump(data: EntryOptions[]) {
|
|
396
583
|
return this.type === 'application/yaml'
|
|
397
|
-
?
|
|
584
|
+
? stringify(data, { ...yamlOptions, singleQuote: true })
|
|
398
585
|
: JSON.stringify(data, null, 2)
|
|
399
586
|
}
|
|
400
587
|
|
|
588
|
+
getLocation(id: string, path: PropertyKey[]): SourceLocation | undefined {
|
|
589
|
+
if (!this.cache || !this.index) return
|
|
590
|
+
// values changed at runtime are not written anywhere yet
|
|
591
|
+
const record = this.journal.get(id)
|
|
592
|
+
if (record?.kind === 'remove') return
|
|
593
|
+
if (path.length && record && String(path[0]) in record.changes) return
|
|
594
|
+
|
|
595
|
+
const owner = path.length ? this.index.key(id, String(path[0])) : this.index.entry(id)
|
|
596
|
+
if (owner.type === 'patch') {
|
|
597
|
+
return this.ctx.fiber.entry?.getLocation(['config', 'patches', owner.index, ...path])
|
|
598
|
+
} else if (owner.type === 'embedded') {
|
|
599
|
+
const prefix = findEntry(this.config.patches![owner.index][owner.key], id)
|
|
600
|
+
if (!prefix) return
|
|
601
|
+
return this.ctx.fiber.entry?.getLocation(['config', 'patches', owner.index, owner.key, ...prefix, ...path])
|
|
602
|
+
}
|
|
603
|
+
const prefix = findEntry(this.cache.data, id)
|
|
604
|
+
if (!prefix) return
|
|
605
|
+
const { document, lines } = this.cache.syntax ??= parseSyntax(this.cache.content)
|
|
606
|
+
const range = seek(document, [...prefix, ...path])
|
|
607
|
+
if (range) return this._locate(lines, range[0])
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
private _locate(lines: LineCounter, offset: number): SourceLocation {
|
|
611
|
+
const { line, col } = lines.linePos(offset)
|
|
612
|
+
return { filename: this.filename, line, column: col }
|
|
613
|
+
}
|
|
614
|
+
|
|
401
615
|
/**
|
|
402
616
|
* Entries the file leaves anonymous get an id here, before the loader sees
|
|
403
617
|
* them. One that looks exactly like an entry we named on the previous read
|
|
404
|
-
* keeps that id,
|
|
405
|
-
*
|
|
618
|
+
* keeps that id, unless it is already explicitly owned, so editing a
|
|
619
|
+
* neighbor does not restart it; anything else gets a fresh id. Assigned
|
|
620
|
+
* ids stay in memory until the next write.
|
|
406
621
|
*/
|
|
407
622
|
private _assignIds(data: EntryOptions[]) {
|
|
408
623
|
const used = new Set<string>()
|
|
409
|
-
const
|
|
410
|
-
const walk = (entries: EntryOptions[], parent: string | null) => {
|
|
624
|
+
const collect = (entries: EntryOptions[]) => {
|
|
411
625
|
for (const options of entries) {
|
|
412
|
-
if (options.id)
|
|
413
|
-
|
|
414
|
-
} else {
|
|
415
|
-
pending.push({ options, parent })
|
|
416
|
-
}
|
|
417
|
-
if (options.group && Array.isArray(options.config)) {
|
|
418
|
-
walk(options.config, options.id ?? null)
|
|
419
|
-
}
|
|
626
|
+
if (options.id) used.add(options.id)
|
|
627
|
+
if (options.group && Array.isArray(options.config)) collect(options.config)
|
|
420
628
|
}
|
|
421
629
|
}
|
|
422
|
-
|
|
630
|
+
collect(data)
|
|
631
|
+
for (const patch of this.config.patches ?? []) {
|
|
632
|
+
if (patch.insert) collect(patch.insert)
|
|
633
|
+
}
|
|
423
634
|
|
|
424
635
|
const previous = this.anonymous
|
|
425
636
|
this.anonymous = new Map()
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
637
|
+
const assign = (entries: EntryOptions[], parent: string | null) => {
|
|
638
|
+
for (const options of entries) {
|
|
639
|
+
if (!options.id) {
|
|
640
|
+
let id: string | undefined
|
|
641
|
+
for (const [candidate, info] of previous) {
|
|
642
|
+
if (info.parent !== parent || used.has(candidate) || !deepEqual(info.options, options)) continue
|
|
643
|
+
id = candidate
|
|
644
|
+
previous.delete(candidate)
|
|
645
|
+
break
|
|
646
|
+
}
|
|
647
|
+
if (!id) {
|
|
648
|
+
do {
|
|
649
|
+
id = Math.random().toString(16).slice(2, 10)
|
|
650
|
+
} while (used.has(id) || this.store[id])
|
|
651
|
+
}
|
|
652
|
+
used.add(id)
|
|
653
|
+
this.anonymous.set(id, { parent, options: structuredClone(options) })
|
|
654
|
+
const rest = { ...options }
|
|
655
|
+
for (const key of Object.keys(options)) delete options[key]
|
|
656
|
+
Object.assign(options, { id }, rest)
|
|
657
|
+
}
|
|
658
|
+
if (options.group && Array.isArray(options.config)) assign(options.config, options.id)
|
|
438
659
|
}
|
|
439
|
-
used.add(id)
|
|
440
|
-
this.anonymous.set(id, { parent, options: structuredClone(options) })
|
|
441
|
-
const rest = { ...options }
|
|
442
|
-
for (const key of Object.keys(options)) delete options[key]
|
|
443
|
-
Object.assign(options, { id }, rest)
|
|
444
660
|
}
|
|
661
|
+
assign(data, null)
|
|
445
662
|
}
|
|
446
663
|
|
|
447
664
|
private _scheduleApply() {
|
|
448
665
|
if (this._disposed || !this.cache) return
|
|
449
|
-
const
|
|
450
|
-
this.
|
|
666
|
+
const { data, index } = applyPatches(this.cache.data, this.config.patches, this.warn)
|
|
667
|
+
this.index = index
|
|
668
|
+
this._pendingTree = applyJournal(data, this.journal, undefined, this.warn)
|
|
451
669
|
this._applyTask ??= (async () => {
|
|
452
670
|
try {
|
|
453
671
|
while (this._pendingTree) {
|