@ja-platform/parser-core 0.0.0-dev-20261105194022 → 0.0.0-dev-20261113191340
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/dist/@types/attributes/TextAttribute.d.ts +9 -2
- package/dist/@types/index.d.ts +1 -1
- package/dist/@types/nodes/Node.d.ts +2 -2
- package/dist/@types/parsed/ParsedArrayNode.d.ts +3 -4
- package/dist/@types/parsed/ParsedContentNode.d.ts +3 -2
- package/dist/@types/parsed/ParsedEitherNode.d.ts +3 -2
- package/dist/@types/parsed/ParsedNode.d.ts +7 -19
- package/dist/@types/parsed/ParsedRecordNode.d.ts +3 -2
- package/dist/@types/values/ParsedNodeValues.d.ts +3 -5
- package/dist/@types/values/ParsedProviderValue.d.ts +4 -0
- package/dist/@types/values/ParsedValue.d.ts +3 -12
- package/dist/@types/values/ValueProviderContext.d.ts +5 -0
- package/dist/attributes/TextAttribute.js +18 -0
- package/dist/attributes/TextAttribute.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/nodes/Node.js +4 -5
- package/dist/nodes/Node.js.map +1 -1
- package/dist/parsed/ParsedArrayNode.js +2 -6
- package/dist/parsed/ParsedArrayNode.js.map +1 -1
- package/dist/parsed/ParsedContentNode.js +4 -4
- package/dist/parsed/ParsedContentNode.js.map +1 -1
- package/dist/parsed/ParsedEitherNode.js +3 -3
- package/dist/parsed/ParsedEitherNode.js.map +1 -1
- package/dist/parsed/ParsedNode.js +37 -66
- package/dist/parsed/ParsedNode.js.map +1 -1
- package/dist/parsed/ParsedRecordNode.js +3 -3
- package/dist/parsed/ParsedRecordNode.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/values/ParsedNodeValues.js +17 -53
- package/dist/values/ParsedNodeValues.js.map +1 -1
- package/dist/values/ParsedProviderValue.js +5 -1
- package/dist/values/ParsedProviderValue.js.map +1 -1
- package/dist/values/ParsedValue.js +4 -25
- package/dist/values/ParsedValue.js.map +1 -1
- package/dist/values/ValueProviderContext.js +3 -0
- package/dist/values/ValueProviderContext.js.map +1 -0
- package/package.json +6 -6
- package/dist/@types/attributes/ContentTextAttribute.d.ts +0 -16
- package/dist/attributes/ContentTextAttribute.js +0 -29
- package/dist/attributes/ContentTextAttribute.js.map +0 -1
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ParsedNode = void 0;
|
|
4
|
+
const ParsedValue_1 = require("../values/ParsedValue");
|
|
4
5
|
const ParsedNodeValues_1 = require("../values/ParsedNodeValues");
|
|
5
6
|
const common_tree_1 = require("@journeyapps/common-tree");
|
|
6
7
|
const ParsedArrayNode_1 = require("./ParsedArrayNode");
|
|
7
8
|
const ParsedDiagnostic_1 = require("./ParsedDiagnostic");
|
|
8
|
-
const ParsedValue_1 = require("../values/ParsedValue");
|
|
9
9
|
class ParsedNode extends common_tree_1.TreeNode {
|
|
10
10
|
constructor(options) {
|
|
11
11
|
var _a;
|
|
12
12
|
const definition = options.definition;
|
|
13
13
|
super((_a = options.key) !== null && _a !== void 0 ? _a : definition.options.key);
|
|
14
|
-
this.parsedValues = new Map();
|
|
15
14
|
this.attributesByKey = new Map();
|
|
16
15
|
this.childrenByKey = new Map();
|
|
17
16
|
this.diagnostics = new ParsedDiagnostic_1.ParsedDiagnosticStore();
|
|
@@ -36,57 +35,50 @@ class ParsedNode extends common_tree_1.TreeNode {
|
|
|
36
35
|
const parent = (_a = this.getParent()) !== null && _a !== void 0 ? _a : this.parseParentNode;
|
|
37
36
|
return (_b = parent === null || parent === void 0 ? void 0 : parent.getRoot()) !== null && _b !== void 0 ? _b : this;
|
|
38
37
|
}
|
|
39
|
-
|
|
40
|
-
return this.
|
|
41
|
-
}
|
|
42
|
-
setValueProviders(providers) {
|
|
43
|
-
this.parsedValues.clear();
|
|
44
|
-
this.valueProviders = Object.freeze([...providers]);
|
|
45
|
-
this.childEntries().forEach((child) => child.setValueProviders(providers));
|
|
46
|
-
return this;
|
|
38
|
+
value(attributeKeys, provider) {
|
|
39
|
+
return this.createValues(attributeKeys, provider);
|
|
47
40
|
}
|
|
48
|
-
|
|
49
|
-
const attributes = this.collectAttributeValues(attributeKeys);
|
|
50
|
-
return new ParsedNodeValues_1.ParsedNodeValues(attributes.map(([, source]) => source), (currentValues) => Object.fromEntries(attributes.flatMap(([key], index) => currentValues[index] === undefined ? [] : [[key, currentValues[index]]])));
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Resolve this node's attributes and descendants through their value providers.
|
|
54
|
-
* Include declared defaults for absent children without creating parsed nodes.
|
|
55
|
-
*/
|
|
56
|
-
valueTree() {
|
|
57
|
-
const defaults = this.definition.nodes.flatMap(({ options, defaultValue }) => !this.childrenByKey.has(options.key) && defaultValue !== undefined ? [[options.key, defaultValue]] : []);
|
|
58
|
-
const attributes = this.collectAttributeValues(this.attributes().map((attribute) => attribute.getKey()));
|
|
59
|
-
const sources = [...attributes];
|
|
60
|
-
for (const [key, child] of this.childrenByKey) {
|
|
61
|
-
if (child instanceof ParsedArrayNode_1.ParsedArrayNode && child.inputPresent === false && child.definition.defaultValue == null) {
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
sources.push([key, child.valueTree()]);
|
|
65
|
-
}
|
|
66
|
-
return new ParsedNodeValues_1.ParsedNodeValues(sources.map(([, source]) => source), (currentValues) => Object.fromEntries([
|
|
67
|
-
...defaults,
|
|
68
|
-
...sources.flatMap(([key], index) => index < attributes.length && currentValues[index] === undefined ? [] : [[key, currentValues[index]]])
|
|
69
|
-
]));
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Collect retained attribute sources for a value container to own and release.
|
|
73
|
-
*/
|
|
74
|
-
collectAttributeValues(attributeKeys) {
|
|
75
|
-
if (!this.valueProviders) {
|
|
76
|
-
throw new Error(`No value providers have been configured for parsed node '${this.getKey()}'`);
|
|
77
|
-
}
|
|
41
|
+
createValues(attributeKeys, provider) {
|
|
78
42
|
const attributes = attributeKeys.map((key) => {
|
|
79
43
|
const attribute = this.attribute(key);
|
|
80
|
-
if (!attribute)
|
|
44
|
+
if (!attribute)
|
|
81
45
|
throw new Error(`Unknown parsed attribute '${key}' on node '${this.getKey()}'`);
|
|
82
|
-
}
|
|
83
46
|
return attribute;
|
|
84
47
|
});
|
|
85
48
|
const sources = [];
|
|
86
|
-
|
|
87
|
-
|
|
49
|
+
try {
|
|
50
|
+
for (const attribute of attributes) {
|
|
51
|
+
sources.push(new ParsedValue_1.ParsedValue(attribute, provider.providers));
|
|
52
|
+
}
|
|
53
|
+
return new ParsedNodeValues_1.ParsedNodeValues(sources, (values) => Object.fromEntries(attributes.flatMap((attribute, index) => {
|
|
54
|
+
if (values[index] === undefined)
|
|
55
|
+
return [];
|
|
56
|
+
return [[attribute.getKey(), values[index]]];
|
|
57
|
+
})));
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
sources.forEach((source) => source.dispose());
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/** Assemble this node's flat attribute set and its child trees. */
|
|
65
|
+
valueTree(provider) {
|
|
66
|
+
const defaults = this.definition.nodes.flatMap(({ options, defaultValue }) => !this.childrenByKey.has(options.key) && defaultValue !== undefined ? [[options.key, defaultValue]] : []);
|
|
67
|
+
const attributes = this.createValues(this.attributes().map((attribute) => attribute.getKey()), provider);
|
|
68
|
+
const children = [];
|
|
69
|
+
try {
|
|
70
|
+
for (const [key, child] of this.childrenByKey) {
|
|
71
|
+
if (child instanceof ParsedArrayNode_1.ParsedArrayNode && !child.inputPresent && child.definition.defaultValue == null)
|
|
72
|
+
continue;
|
|
73
|
+
children.push([key, child.valueTree(provider)]);
|
|
74
|
+
}
|
|
75
|
+
return new ParsedNodeValues_1.ParsedNodeValues([attributes, ...children.map(([, child]) => child)], ([values, ...childValues]) => (Object.assign(Object.assign(Object.assign({}, Object.fromEntries(defaults)), values), Object.fromEntries(children.map(([key], index) => [key, childValues[index]])))));
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
attributes.dispose();
|
|
79
|
+
children.forEach(([, child]) => child.dispose());
|
|
80
|
+
throw error;
|
|
88
81
|
}
|
|
89
|
-
return sources;
|
|
90
82
|
}
|
|
91
83
|
attribute(key) {
|
|
92
84
|
return this.attributesByKey.get(key);
|
|
@@ -168,9 +160,6 @@ class ParsedNode extends common_tree_1.TreeNode {
|
|
|
168
160
|
}
|
|
169
161
|
this.childrenByKey.set(key, child);
|
|
170
162
|
this.addParsedChild(child);
|
|
171
|
-
if (this.valueProviders) {
|
|
172
|
-
child.setValueProviders(this.valueProviders);
|
|
173
|
-
}
|
|
174
163
|
return this;
|
|
175
164
|
}
|
|
176
165
|
removeChild(key) {
|
|
@@ -180,8 +169,6 @@ class ParsedNode extends common_tree_1.TreeNode {
|
|
|
180
169
|
return this;
|
|
181
170
|
}
|
|
182
171
|
setAttribute(attribute) {
|
|
183
|
-
const previous = this.attributesByKey.get(attribute.definition.options.key);
|
|
184
|
-
this.parsedValues.delete(previous);
|
|
185
172
|
this.attributesByKey.set(attribute.definition.options.key, attribute);
|
|
186
173
|
this.addParsedAttribute(attribute);
|
|
187
174
|
return this;
|
|
@@ -208,22 +195,6 @@ class ParsedNode extends common_tree_1.TreeNode {
|
|
|
208
195
|
return [child];
|
|
209
196
|
});
|
|
210
197
|
}
|
|
211
|
-
getParsedValue(attribute) {
|
|
212
|
-
let value = this.parsedValues.get(attribute);
|
|
213
|
-
if (!value) {
|
|
214
|
-
value = new ParsedValue_1.ParsedValue(attribute, this.valueProviders);
|
|
215
|
-
this.parsedValues.set(attribute, value);
|
|
216
|
-
const deregister = value.registerListener({
|
|
217
|
-
disposed: () => {
|
|
218
|
-
deregister();
|
|
219
|
-
if (this.parsedValues.get(attribute) === value) {
|
|
220
|
-
this.parsedValues.delete(attribute);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
return value;
|
|
226
|
-
}
|
|
227
198
|
addParsedAttribute(attribute) {
|
|
228
199
|
const existing = this.getChild(attribute.getKey());
|
|
229
200
|
if (existing) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParsedNode.js","sourceRoot":"","sources":["../../src/parsed/ParsedNode.ts"],"names":[],"mappings":";;;AAAA,iEAAoF;AACpF,0DAAsE;AAKtE,uDAAoD;AAEpD,yDAAyG;AAkBzG,uDAAoD;AAsCpD,gBAAiG,SAAQ,sBAExG;IAYC,YAAY,OAA0B;;QACpC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACtC,KAAK,OAAC,OAAO,CAAC,GAAG,mCAAI,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAb9B,iBAAY,GAAG,IAAI,GAAG,EAAqC,CAAC;QACrE,oBAAe,GAAiC,IAAI,GAAG,EAAE,CAAC;QAC1D,kBAAa,GAA6B,IAAI,GAAG,EAAE,CAAC;QAM3C,gBAAW,GAAG,IAAI,wCAAqB,EAAE,CAAC;QAMzD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC;QAC1C,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IACpC,CAAC;IAED,IAAI,IAAI;;;QACN,aAAO,MAAA,MAAA,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,0CAAE,UAAU,EAAE,0CAAE,KAAK,EAAE,mCAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC;IACvF,CAAC;IAED,gBAAgB,CAAC,QAA+C;QAC9D,OAAO,KAAK,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAED,IAAI,QAAQ;QACV,OAAO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CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;CACF","sourcesContent":["import { ParsedNodeValues, ParsedNodeValuesLike } from '../values/ParsedNodeValues';\nimport { TreeNode, TreeNodeListener } from '@journeyapps/common-tree';\nimport { ParseEvent } from '../ParseEvent';\n\nimport type { NodeInput } from '../input/NodeInput';\nimport { Node } from '../nodes/Node';\nimport { ParsedArrayNode } from './ParsedArrayNode';\nimport { ParsedAttribute } from './ParsedAttribute';\nimport { ParsedDiagnostic, ParsedDiagnosticStore, ParsedValidationDiagnostic } from './ParsedDiagnostic';\nimport type { ValidationContext } from '@ja-platform/parser-expressions';\nimport {\n ParsedChild,\n ParsedChildNamesMarker,\n ParsedNodeAttribute,\n ParsedNodeAttributeShape,\n ParsedNodeAttributeName,\n ParsedNodeChild,\n ParsedNodeExpressionKey,\n ParsedNodeKnownChildKey,\n ParsedNodeValue,\n ParsedNodeValueRequest,\n ParsedNodeValueRequestKey,\n ParsedNodeRequiredAttributeName,\n ParsedNodeShape,\n ParsedNodeUntypedExpressionKey\n} from './ParsedNodeTypes';\nimport { ParsedValue } from '../values/ParsedValue';\nimport { AbstractValueProvider } from '../values/AbstractValueProvider';\n\nexport interface ParsedNodeOptions extends ParseEvent {\n definition: Node<any>;\n key?: string;\n}\n\nexport interface ParsedNodeValidationContext {\n scope: ValidationContext;\n}\n\nexport interface NodeValidationEvent<Shape extends ParsedNodeShape = ParsedNodeShape, Value = ParsedNodeValue<Shape>> {\n node: ParsedNode<Shape, Value>;\n context: NodeValidationContext;\n}\n\nexport interface NodeValidationContext {\n readonly scope: ValidationContext;\n report(diagnostic: ParsedValidationDiagnostic): void;\n}\n\nexport interface ParsedNodeListener<\n Shape extends ParsedNodeShape = ParsedNodeShape,\n Value = ParsedNodeValue<Shape>\n> extends TreeNodeListener {\n /**\n * Report diagnostics and introduce child scopes before validating expressions and descendants.\n * Hooks run in registration order during explicit validation, independently of parsing.\n */\n preValidation?(event: NodeValidationEvent<Shape, Value>): void;\n\n /**\n * Validate this node after its expressions and descendants using the resulting context.\n */\n postValidation?(event: NodeValidationEvent<Shape, Value>): void;\n}\n\nexport class ParsedNode<T extends ParsedNodeShape = ParsedNodeShape, Value = ParsedNodeValue<T>> extends TreeNode<\n ParsedNodeListener<any, any>\n> {\n private readonly parsedValues = new Map<ParsedAttribute, ParsedValue<any>>();\n private attributesByKey: Map<string, ParsedAttribute> = new Map();\n private childrenByKey: Map<string, ParsedChild> = new Map();\n private valueProviders?: readonly AbstractValueProvider[];\n public readonly definition: Node<any>;\n public readonly input?: NodeInput;\n public readonly parseParentNode?: ParsedNode;\n private parsedContent: any;\n private readonly diagnostics = new ParsedDiagnosticStore();\n private readonly reportError: (diagnostic: ParsedDiagnostic) => void;\n\n constructor(options: ParsedNodeOptions) {\n const definition = options.definition;\n super(options.key ?? definition.options.key);\n this.definition = definition;\n this.input = options.input;\n this.parseParentNode = options.parentNode;\n this.reportError = options.report;\n }\n\n get type(): string {\n return this.attribute('type')?.expression()?.value() ?? this.definition.options.name;\n }\n\n registerListener(listener: Partial<ParsedNodeListener<T, Value>>): () => void {\n return super.registerListener(listener);\n }\n\n get children(): ParsedNode[] {\n return this.nodes();\n }\n\n getRoot(): ParsedNode {\n const parent = this.getParent<ParsedNode>() ?? this.parseParentNode;\n return parent?.getRoot() ?? this;\n }\n\n get parsedValueProviders(): readonly AbstractValueProvider[] | undefined {\n return this.valueProviders;\n }\n\n setValueProviders(providers: readonly AbstractValueProvider[]): this {\n this.parsedValues.clear();\n this.valueProviders = Object.freeze([...providers]);\n this.childEntries().forEach((child) => child.setValueProviders(providers));\n return this;\n }\n\n value<const Keys extends readonly ParsedNodeValueRequestKey<T, Value>[]>(\n attributes: Keys\n ): ParsedNodeValuesLike<ParsedNodeValueRequest<T, Value, Keys>>;\n value<RequestedValue = any>(\n attributes: readonly ParsedNodeUntypedExpressionKey<T>[]\n ): ParsedNodeValuesLike<RequestedValue>;\n value(attributeKeys: readonly string[]): ParsedNodeValuesLike<any> {\n const attributes = this.collectAttributeValues(attributeKeys);\n return new ParsedNodeValues(\n attributes.map(([, source]) => source),\n (currentValues) =>\n Object.fromEntries(\n attributes.flatMap(([key], index) =>\n currentValues[index] === undefined ? [] : [[key, currentValues[index]]]\n )\n )\n );\n }\n\n /**\n * Resolve this node's attributes and descendants through their value providers.\n * Include declared defaults for absent children without creating parsed nodes.\n */\n valueTree(): ParsedNodeValuesLike<Value> {\n const defaults = this.definition.nodes.flatMap(({ options, defaultValue }) =>\n !this.childrenByKey.has(options.key) && defaultValue !== undefined ? [[options.key, defaultValue]] : []\n );\n const attributes = this.collectAttributeValues(this.attributes().map((attribute) => attribute.getKey()));\n const sources: Array<readonly [string, ParsedNodeValuesLike<unknown>]> = [...attributes];\n for (const [key, child] of this.childrenByKey) {\n if (child instanceof ParsedArrayNode && child.inputPresent === false && child.definition.defaultValue == null) {\n continue;\n }\n sources.push([key, child.valueTree()]);\n }\n return new ParsedNodeValues<Value>(\n sources.map(([, source]) => source),\n (currentValues) =>\n Object.fromEntries([\n ...defaults,\n ...sources.flatMap(([key], index) =>\n index < attributes.length && currentValues[index] === undefined ? [] : [[key, currentValues[index]]]\n )\n ]) as Value\n );\n }\n\n /**\n * Collect retained attribute sources for a value container to own and release.\n */\n protected collectAttributeValues(attributeKeys: readonly string[]): Array<readonly [string, ParsedValue<unknown>]> {\n if (!this.valueProviders) {\n throw new Error(`No value providers have been configured for parsed node '${this.getKey()}'`);\n }\n const attributes = attributeKeys.map((key) => {\n const attribute = this.attribute(key);\n if (!attribute) {\n throw new Error(`Unknown parsed attribute '${key}' on node '${this.getKey()}'`);\n }\n return attribute;\n });\n const sources: Array<readonly [string, ParsedValue<unknown>]> = [];\n for (const attribute of attributes) {\n sources.push([attribute.getKey(), this.getParsedValue(attribute).retain()]);\n }\n return sources;\n }\n\n attribute<Key extends Extract<ParsedNodeRequiredAttributeName<T>, ParsedNodeExpressionKey<T>>>(\n key: Key\n ): ParsedNodeAttribute<T, Key>;\n attribute<Key extends Exclude<ParsedNodeExpressionKey<T>, ParsedNodeRequiredAttributeName<T>>>(\n key: Key\n ): ParsedNodeAttribute<T, Key> | undefined;\n attribute<Attribute extends ParsedAttribute = ParsedAttribute>(key: string): Attribute | undefined;\n attribute(key: string): ParsedAttribute | undefined {\n return this.attributesByKey.get(key);\n }\n\n attrExpression<Key extends ParsedNodeExpressionKey<T>>(key: Key): ParsedNodeAttributeShape<T>[Key] | undefined;\n attrExpression<Value = any>(key: ParsedNodeUntypedExpressionKey<T>): Value | undefined;\n attrExpression(key: string): any {\n return this.attributesByKey.get(key)?.expression();\n }\n\n attributes(): ParsedAttribute[];\n attributes<const Names extends readonly ParsedNodeAttributeName<T>[]>(names: Names): ParsedAttribute[];\n attributes(names?: readonly string[]): ParsedAttribute[] {\n const attributes = Array.from(this.attributesByKey.values());\n if (!names || names.length === 0) {\n return attributes;\n }\n\n return attributes.filter((attribute) => names.includes(attribute.name));\n }\n\n content() {\n return this.parsedContent;\n }\n\n setContent(content: any): this {\n this.parsedContent = content;\n return this;\n }\n\n /**\n * Validate attribute expressions and descendants against the supplied scope.\n * Diagnostics are returned without changing parse errors or reading values.\n */\n validate({ scope }: ParsedNodeValidationContext): ParsedValidationDiagnostic[] {\n const diagnostics: ParsedValidationDiagnostic[] = [];\n const source = this.input?.source;\n const context: NodeValidationContext = {\n scope,\n report(diagnostic) {\n diagnostics.push(diagnostic.token ? diagnostic : { ...diagnostic, source: diagnostic.source ?? source });\n }\n };\n this.iterateListeners((listener) => listener.preValidation?.({ node: this, context }));\n diagnostics.push(\n ...this.attributes().flatMap(\n (attribute) =>\n attribute\n .expression()\n ?.validate(scope)\n .map((diagnostic) => ({ ...diagnostic, source: attribute.input?.source ?? source })) ?? []\n ),\n ...this.nodes().flatMap((child) => child.validate({ scope }))\n );\n this.iterateListeners((listener) => listener.postValidation?.({ node: this, context }));\n return diagnostics;\n }\n\n pushError({ message, source = this.input?.source, type }: ParsedDiagnostic): ParsedDiagnostic {\n const diagnostic = this.diagnostics.pushError({ message, source, type });\n this.reportError({ source, message, type });\n return diagnostic;\n }\n\n reportDiagnostic(diagnostic: ParsedDiagnostic) {\n this.reportError(diagnostic);\n }\n\n errors(options: { deep?: boolean } = {}): ParsedDiagnostic[] {\n if (!options.deep) {\n return this.diagnostics.errors();\n }\n\n return [\n ...this.diagnostics.errors(),\n ...this.attributes().flatMap((attribute) => attribute.errors()),\n ...this.childEntries().flatMap((child) => {\n if (child instanceof ParsedArrayNode) {\n return [...child.errors(), ...child.nodes().flatMap((node) => node.errors({ deep: true }))];\n }\n return child.errors({ deep: true });\n })\n ];\n }\n\n hasErrors(options: { deep?: boolean } = {}): boolean {\n return this.errors(options).length > 0;\n }\n\n child(key: string): ParsedChild | undefined {\n return this.childrenByKey.get(key);\n }\n\n setChild(key: string, child: ParsedChild): this {\n const existing = this.childrenByKey.get(key);\n if (existing && existing !== child) {\n existing.delete();\n }\n\n this.childrenByKey.set(key, child);\n\n this.addParsedChild(child);\n\n if (this.valueProviders) {\n child.setValueProviders(this.valueProviders);\n }\n\n return this;\n }\n\n removeChild(key: string): this {\n const child = this.childrenByKey.get(key);\n this.childrenByKey.delete(key);\n child?.delete();\n return this;\n }\n\n setAttribute(attribute: ParsedAttribute): this {\n const previous = this.attributesByKey.get(attribute.definition.options.key);\n this.parsedValues.delete(previous);\n this.attributesByKey.set(attribute.definition.options.key, attribute);\n this.addParsedAttribute(attribute);\n return this;\n }\n\n node<Key extends ParsedNodeKnownChildKey<T>>(key: Key): ParsedNodeChild<T, Key> | undefined;\n node<Child extends ParsedChild = ParsedChild>(\n key: T extends ParsedChildNamesMarker<any> ? never : string\n ): Child | undefined;\n node(key: string): ParsedChild | undefined {\n return this.child(key);\n }\n\n childEntries(): ParsedChild[] {\n return Array.from(this.childrenByKey.values());\n }\n\n nodes(): ParsedNode[] {\n return this.childEntries().flatMap((child) => {\n if (child instanceof ParsedArrayNode) {\n return this.flattenParsedArray(child);\n }\n return [child];\n });\n }\n\n private flattenParsedArray(arrayNode: ParsedArrayNode): ParsedNode[] {\n return arrayNode.nodes().flatMap((child) => {\n if (child instanceof ParsedArrayNode) {\n return this.flattenParsedArray(child);\n }\n return [child];\n });\n }\n\n private getParsedValue(attribute: ParsedAttribute): ParsedValue<any> {\n let value = this.parsedValues.get(attribute);\n if (!value) {\n value = new ParsedValue(attribute, this.valueProviders);\n this.parsedValues.set(attribute, value);\n const deregister = value.registerListener({\n disposed: () => {\n deregister();\n if (this.parsedValues.get(attribute) === value) {\n this.parsedValues.delete(attribute);\n }\n }\n });\n }\n return value;\n }\n\n private addParsedAttribute(attribute: ParsedAttribute) {\n const existing = this.getChild(attribute.getKey());\n if (existing) {\n existing.delete();\n }\n this.addChild(attribute);\n }\n\n private addParsedChild(child: ParsedChild) {\n const existing = this.getChild(child.getKey());\n if (existing) {\n existing.delete();\n }\n this.addChild(child);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ParsedNode.js","sourceRoot":"","sources":["../../src/parsed/ParsedNode.ts"],"names":[],"mappings":";;;AAAA,uDAAoD;AACpD,iEAA8D;AAG9D,0DAAsE;AAKtE,uDAAoD;AAEpD,yDAAyG;AAwDzG,gBAAiG,SAAQ,sBAExG;IAUC,YAAY,OAA0B;;QACpC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACtC,KAAK,OAAC,OAAO,CAAC,GAAG,mCAAI,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAXvC,oBAAe,GAAiC,IAAI,GAAG,EAAE,CAAC;QAC1D,kBAAa,GAA6B,IAAI,GAAG,EAAE,CAAC;QAK3C,gBAAW,GAAG,IAAI,wCAAqB,EAAE,CAAC;QAMzD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC;QAC1C,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC;IACpC,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C;QACnD,IAAI,QAAQ,EAAE,CAAC;YACb,QAAQ,CAAC,MAAM,EAAE,CAAC;QACpB,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC3B,CAAC;IAEO,cAAc,CAAC,KAAkB;QACvC,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;QAC/C,IAAI,QAAQ,EAAE,CAAC;YACb,QAAQ,CAAC,MAAM,EAAE,CAAC;QACpB,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;CACF","sourcesContent":["import { ParsedValue } from '../values/ParsedValue';\nimport { ParsedNodeValues } from '../values/ParsedNodeValues';\n\nimport type { ParsedNodeValuesLike } from '../values/ParsedNodeValues';\nimport { TreeNode, TreeNodeListener } from '@journeyapps/common-tree';\nimport { ParseEvent } from '../ParseEvent';\n\nimport type { NodeInput } from '../input/NodeInput';\nimport { Node } from '../nodes/Node';\nimport { ParsedArrayNode } from './ParsedArrayNode';\nimport { ParsedAttribute } from './ParsedAttribute';\nimport { ParsedDiagnostic, ParsedDiagnosticStore, ParsedValidationDiagnostic } from './ParsedDiagnostic';\nimport type { ValidationContext } from '@ja-platform/parser-expressions';\n\nimport {\n ParsedChild,\n ParsedChildNamesMarker,\n ParsedNodeAttribute,\n ParsedNodeAttributeShape,\n ParsedNodeAttributeName,\n ParsedNodeChild,\n ParsedNodeExpressionKey,\n ParsedNodeKnownChildKey,\n ParsedNodeValue,\n ParsedNodeValueRequest,\n ParsedNodeValueRequestKey,\n ParsedNodeRequiredAttributeName,\n ParsedNodeShape,\n ParsedNodeUntypedExpressionKey\n} from './ParsedNodeTypes';\nimport type { ValueProviderContext } from '../values/ValueProviderContext';\n\nexport interface ParsedNodeOptions extends ParseEvent {\n definition: Node<any>;\n key?: string;\n}\n\nexport interface ParsedNodeValidationContext {\n scope: ValidationContext;\n}\n\nexport interface NodeValidationEvent<Shape extends ParsedNodeShape = ParsedNodeShape, Value = ParsedNodeValue<Shape>> {\n node: ParsedNode<Shape, Value>;\n context: NodeValidationContext;\n}\n\nexport interface NodeValidationContext {\n readonly scope: ValidationContext;\n report(diagnostic: ParsedValidationDiagnostic): void;\n}\n\nexport interface ParsedNodeListener<\n Shape extends ParsedNodeShape = ParsedNodeShape,\n Value = ParsedNodeValue<Shape>\n> extends TreeNodeListener {\n /**\n * Report diagnostics and introduce child scopes before validating expressions and descendants.\n * Hooks run in registration order during explicit validation, independently of parsing.\n */\n preValidation?(event: NodeValidationEvent<Shape, Value>): void;\n\n /**\n * Validate this node after its expressions and descendants using the resulting context.\n */\n postValidation?(event: NodeValidationEvent<Shape, Value>): void;\n}\n\nexport class ParsedNode<T extends ParsedNodeShape = ParsedNodeShape, Value = ParsedNodeValue<T>> extends TreeNode<\n ParsedNodeListener<any, any>\n> {\n private attributesByKey: Map<string, ParsedAttribute> = new Map();\n private childrenByKey: Map<string, ParsedChild> = new Map();\n public readonly definition: Node<any>;\n public readonly input?: NodeInput;\n public readonly parseParentNode?: ParsedNode;\n private parsedContent: any;\n private readonly diagnostics = new ParsedDiagnosticStore();\n private readonly reportError: (diagnostic: ParsedDiagnostic) => void;\n\n constructor(options: ParsedNodeOptions) {\n const definition = options.definition;\n super(options.key ?? definition.options.key);\n this.definition = definition;\n this.input = options.input;\n this.parseParentNode = options.parentNode;\n this.reportError = options.report;\n }\n\n get type(): string {\n return this.attribute('type')?.expression()?.value() ?? this.definition.options.name;\n }\n\n registerListener(listener: Partial<ParsedNodeListener<T, Value>>): () => void {\n return super.registerListener(listener);\n }\n\n get children(): ParsedNode[] {\n return this.nodes();\n }\n\n getRoot(): ParsedNode {\n const parent = this.getParent<ParsedNode>() ?? this.parseParentNode;\n return parent?.getRoot() ?? this;\n }\n\n value<const Keys extends readonly ParsedNodeValueRequestKey<T, Value>[]>(\n attributes: Keys,\n provider: ValueProviderContext\n ): ParsedNodeValuesLike<ParsedNodeValueRequest<T, Value, Keys>>;\n value<RequestedValue = any>(\n attributes: readonly ParsedNodeUntypedExpressionKey<T>[],\n provider: ValueProviderContext\n ): ParsedNodeValuesLike<RequestedValue>;\n value(attributeKeys: readonly string[], provider: ValueProviderContext): ParsedNodeValuesLike<any> {\n return this.createValues(attributeKeys, provider);\n }\n\n protected createValues(attributeKeys: readonly string[], provider: ValueProviderContext): ParsedNodeValuesLike<any> {\n const attributes = attributeKeys.map((key) => {\n const attribute = this.attribute(key);\n if (!attribute) throw new Error(`Unknown parsed attribute '${key}' on node '${this.getKey()}'`);\n return attribute;\n });\n const sources: ParsedValue<unknown>[] = [];\n try {\n for (const attribute of attributes) {\n sources.push(new ParsedValue(attribute, provider.providers));\n }\n return new ParsedNodeValues(sources, (values) =>\n Object.fromEntries(\n attributes.flatMap((attribute, index) => {\n if (values[index] === undefined) return [];\n return [[attribute.getKey(), values[index]]];\n })\n )\n );\n } catch (error) {\n sources.forEach((source) => source.dispose());\n throw error;\n }\n }\n\n /** Assemble this node's flat attribute set and its child trees. */\n valueTree(provider: ValueProviderContext): ParsedNodeValuesLike<Value> {\n const defaults = this.definition.nodes.flatMap(({ options, defaultValue }) =>\n !this.childrenByKey.has(options.key) && defaultValue !== undefined ? [[options.key, defaultValue]] : []\n );\n const attributes = this.createValues(\n this.attributes().map((attribute) => attribute.getKey()),\n provider\n );\n const children: Array<readonly [string, ParsedNodeValuesLike<unknown>]> = [];\n try {\n for (const [key, child] of this.childrenByKey) {\n if (child instanceof ParsedArrayNode && !child.inputPresent && child.definition.defaultValue == null) continue;\n children.push([key, child.valueTree(provider)]);\n }\n return new ParsedNodeValues<Value>(\n [attributes, ...children.map(([, child]) => child)],\n ([values, ...childValues]) =>\n ({\n ...Object.fromEntries(defaults),\n ...(values as Record<string, unknown>),\n ...Object.fromEntries(children.map(([key], index) => [key, childValues[index]]))\n }) as Value\n );\n } catch (error) {\n attributes.dispose();\n children.forEach(([, child]) => child.dispose());\n throw error;\n }\n }\n\n attribute<Key extends Extract<ParsedNodeRequiredAttributeName<T>, ParsedNodeExpressionKey<T>>>(\n key: Key\n ): ParsedNodeAttribute<T, Key>;\n attribute<Key extends Exclude<ParsedNodeExpressionKey<T>, ParsedNodeRequiredAttributeName<T>>>(\n key: Key\n ): ParsedNodeAttribute<T, Key> | undefined;\n attribute<Attribute extends ParsedAttribute = ParsedAttribute>(key: string): Attribute | undefined;\n attribute(key: string): ParsedAttribute | undefined {\n return this.attributesByKey.get(key);\n }\n\n attrExpression<Key extends ParsedNodeExpressionKey<T>>(key: Key): ParsedNodeAttributeShape<T>[Key] | undefined;\n attrExpression<Value = any>(key: ParsedNodeUntypedExpressionKey<T>): Value | undefined;\n attrExpression(key: string): any {\n return this.attributesByKey.get(key)?.expression();\n }\n\n attributes(): ParsedAttribute[];\n attributes<const Names extends readonly ParsedNodeAttributeName<T>[]>(names: Names): ParsedAttribute[];\n attributes(names?: readonly string[]): ParsedAttribute[] {\n const attributes = Array.from(this.attributesByKey.values());\n if (!names || names.length === 0) {\n return attributes;\n }\n\n return attributes.filter((attribute) => names.includes(attribute.name));\n }\n\n content() {\n return this.parsedContent;\n }\n\n setContent(content: any): this {\n this.parsedContent = content;\n return this;\n }\n\n /**\n * Validate attribute expressions and descendants against the supplied scope.\n * Diagnostics are returned without changing parse errors or reading values.\n */\n validate({ scope }: ParsedNodeValidationContext): ParsedValidationDiagnostic[] {\n const diagnostics: ParsedValidationDiagnostic[] = [];\n const source = this.input?.source;\n const context: NodeValidationContext = {\n scope,\n report(diagnostic) {\n diagnostics.push(diagnostic.token ? diagnostic : { ...diagnostic, source: diagnostic.source ?? source });\n }\n };\n this.iterateListeners((listener) => listener.preValidation?.({ node: this, context }));\n diagnostics.push(\n ...this.attributes().flatMap(\n (attribute) =>\n attribute\n .expression()\n ?.validate(scope)\n .map((diagnostic) => ({ ...diagnostic, source: attribute.input?.source ?? source })) ?? []\n ),\n ...this.nodes().flatMap((child) => child.validate({ scope }))\n );\n this.iterateListeners((listener) => listener.postValidation?.({ node: this, context }));\n return diagnostics;\n }\n\n pushError({ message, source = this.input?.source, type }: ParsedDiagnostic): ParsedDiagnostic {\n const diagnostic = this.diagnostics.pushError({ message, source, type });\n this.reportError({ source, message, type });\n return diagnostic;\n }\n\n reportDiagnostic(diagnostic: ParsedDiagnostic) {\n this.reportError(diagnostic);\n }\n\n errors(options: { deep?: boolean } = {}): ParsedDiagnostic[] {\n if (!options.deep) {\n return this.diagnostics.errors();\n }\n\n return [\n ...this.diagnostics.errors(),\n ...this.attributes().flatMap((attribute) => attribute.errors()),\n ...this.childEntries().flatMap((child) => {\n if (child instanceof ParsedArrayNode) {\n return [...child.errors(), ...child.nodes().flatMap((node) => node.errors({ deep: true }))];\n }\n return child.errors({ deep: true });\n })\n ];\n }\n\n hasErrors(options: { deep?: boolean } = {}): boolean {\n return this.errors(options).length > 0;\n }\n\n child(key: string): ParsedChild | undefined {\n return this.childrenByKey.get(key);\n }\n\n setChild(key: string, child: ParsedChild): this {\n const existing = this.childrenByKey.get(key);\n if (existing && existing !== child) {\n existing.delete();\n }\n\n this.childrenByKey.set(key, child);\n\n this.addParsedChild(child);\n\n return this;\n }\n\n removeChild(key: string): this {\n const child = this.childrenByKey.get(key);\n this.childrenByKey.delete(key);\n child?.delete();\n return this;\n }\n\n setAttribute(attribute: ParsedAttribute): this {\n this.attributesByKey.set(attribute.definition.options.key, attribute);\n this.addParsedAttribute(attribute);\n return this;\n }\n\n node<Key extends ParsedNodeKnownChildKey<T>>(key: Key): ParsedNodeChild<T, Key> | undefined;\n node<Child extends ParsedChild = ParsedChild>(\n key: T extends ParsedChildNamesMarker<any> ? never : string\n ): Child | undefined;\n node(key: string): ParsedChild | undefined {\n return this.child(key);\n }\n\n childEntries(): ParsedChild[] {\n return Array.from(this.childrenByKey.values());\n }\n\n nodes(): ParsedNode[] {\n return this.childEntries().flatMap((child) => {\n if (child instanceof ParsedArrayNode) {\n return this.flattenParsedArray(child);\n }\n return [child];\n });\n }\n\n private flattenParsedArray(arrayNode: ParsedArrayNode): ParsedNode[] {\n return arrayNode.nodes().flatMap((child) => {\n if (child instanceof ParsedArrayNode) {\n return this.flattenParsedArray(child);\n }\n return [child];\n });\n }\n\n private addParsedAttribute(attribute: ParsedAttribute) {\n const existing = this.getChild(attribute.getKey());\n if (existing) {\n existing.delete();\n }\n this.addChild(attribute);\n }\n\n private addParsedChild(child: ParsedChild) {\n const existing = this.getChild(child.getKey());\n if (existing) {\n existing.delete();\n }\n this.addChild(child);\n }\n}\n"]}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ParsedRecordNode = void 0;
|
|
4
|
-
const ParsedNode_1 = require("./ParsedNode");
|
|
5
4
|
const ParsedNodeValues_1 = require("../values/ParsedNodeValues");
|
|
5
|
+
const ParsedNode_1 = require("./ParsedNode");
|
|
6
6
|
/** Only document keys become entries; the entry definition does not imply a default key. */
|
|
7
7
|
class ParsedRecordNode extends ParsedNode_1.ParsedNode {
|
|
8
|
-
valueTree() {
|
|
8
|
+
valueTree(provider) {
|
|
9
9
|
const entries = this.nodes();
|
|
10
|
-
return new ParsedNodeValues_1.ParsedNodeValues(entries.map((entry) => entry.valueTree()), (values) => Object.fromEntries(entries.map((entry, index) => [entry.getKey(), values[index]])));
|
|
10
|
+
return new ParsedNodeValues_1.ParsedNodeValues(entries.map((entry) => entry.valueTree(provider)), (values) => Object.fromEntries(entries.map((entry, index) => [entry.getKey(), values[index]])));
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
exports.ParsedRecordNode = ParsedRecordNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ParsedRecordNode.js","sourceRoot":"","sources":["../../src/parsed/ParsedRecordNode.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"ParsedRecordNode.js","sourceRoot":"","sources":["../../src/parsed/ParsedRecordNode.ts"],"names":[],"mappings":";;;AAAA,iEAAyF;AAEzF,6CAA0C;AAE1C,4FAA4F;AAC5F,sBAAyE,SAAQ,uBAGhF;IACC,SAAS,CAAC,QAA8B;QACtC,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;QAC7B,OAAO,IAAI,mCAAgB,CACzB,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,EACjD,CAAC,MAAM,EAAE,EAAE,CACT,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAA0B,CAC9G,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { ParsedNodeValues, type ParsedNodeValuesLike } from '../values/ParsedNodeValues';\nimport type { ValueProviderContext } from '../values/ValueProviderContext';\nimport { ParsedNode } from './ParsedNode';\n\n/** Only document keys become entries; the entry definition does not imply a default key. */\nexport class ParsedRecordNode<Entry extends ParsedNode<any, any>, Value> extends ParsedNode<\n Record<string, Entry>,\n Record<string, Value>\n> {\n valueTree(provider: ValueProviderContext): ParsedNodeValuesLike<Record<string, Value>> {\n const entries = this.nodes();\n return new ParsedNodeValues(\n entries.map((entry) => entry.valueTree(provider)),\n (values) =>\n Object.fromEntries(entries.map((entry, index) => [entry.getKey(), values[index]])) as Record<string, Value>\n );\n }\n}\n"]}
|