@ja-platform/parser-core 0.0.0-dev-20261112183707 → 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.
@@ -40,3 +40,4 @@ export * from './source/SourceReference';
40
40
  export * from './input/AttributeInput';
41
41
  export * from './input/NodeInput';
42
42
  export * from './input/AttributeParseContext';
43
+ export * from './values/ValueProviderContext';
@@ -1,9 +1,9 @@
1
- import { ParsedNodeValuesLike } from '../values/ParsedNodeValues';
1
+ import { type ParsedNodeValuesLike } from '../values/ParsedNodeValues';
2
+ import type { ValueProviderContext } from '../values/ValueProviderContext';
2
3
  import { ParsedExpressionValue } from './ParsedNodeTypes';
3
4
  import { TreeNode } from '@journeyapps/common-tree';
4
5
  import type { SourceReference } from '../source/SourceReference';
5
6
  import { Node } from '../nodes/Node';
6
- import { AbstractValueProvider } from '../values/AbstractValueProvider';
7
7
  import { ParsedDiagnostic } from './ParsedDiagnostic';
8
8
  import { ParsedNode } from './ParsedNode';
9
9
  export interface ParsedArrayNodeOptions {
@@ -23,9 +23,8 @@ export declare class ParsedArrayNode<Child extends ParsedArrayNodeChild = Parsed
23
23
  /**
24
24
  * Resolve repeated children in order, preserving nested arrays.
25
25
  */
26
- valueTree(): ParsedNodeValuesLike<ParsedExpressionValue<Child>[]>;
26
+ valueTree(provider: ValueProviderContext): ParsedNodeValuesLike<ParsedExpressionValue<Child>[]>;
27
27
  at(index: number): Child | undefined;
28
- setValueProviders(providers: readonly AbstractValueProvider[]): this;
29
28
  pushError({ message, source, type }: ParsedDiagnostic): ParsedDiagnostic;
30
29
  errors(): ParsedDiagnostic[];
31
30
  hasErrors(): boolean;
@@ -1,6 +1,7 @@
1
+ import { type ParsedNodeValuesLike } from '../values/ParsedNodeValues';
2
+ import type { ValueProviderContext } from '../values/ValueProviderContext';
1
3
  import { ParsedNode } from './ParsedNode';
2
4
  import { ParsedNodeShapeValue } from './ParsedNodeTypes';
3
- import { ParsedNodeValuesLike } from '../values/ParsedNodeValues';
4
5
  export type ParsedContentNodeShape<Expression extends ParsedNodeShapeValue> = {
5
6
  content?: Expression;
6
7
  };
@@ -9,5 +10,5 @@ export type ParsedContentNodeShape<Expression extends ParsedNodeShapeValue> = {
9
10
  */
10
11
  export declare class ParsedContentNode<Expression extends ParsedNodeShapeValue, Value> extends ParsedNode<ParsedContentNodeShape<Expression>, Value | undefined> {
11
12
  content(): Expression | undefined;
12
- valueTree(): ParsedNodeValuesLike<Value | undefined>;
13
+ valueTree(provider: ValueProviderContext): ParsedNodeValuesLike<Value | undefined>;
13
14
  }
@@ -1,9 +1,10 @@
1
+ import { type ParsedNodeValuesLike } from '../values/ParsedNodeValues';
2
+ import type { ValueProviderContext } from '../values/ValueProviderContext';
1
3
  import { ParsedNode } from './ParsedNode';
2
4
  import type { ParsedChild } from './ParsedNodeTypes';
3
- import { type ParsedNodeValuesLike } from '../values/ParsedNodeValues';
4
5
  /** Preserve the selected branch's value without adding an object to the output. */
5
6
  export declare class ParsedEitherNode<Value> extends ParsedNode<{
6
7
  value?: ParsedChild;
7
8
  }, Value | undefined> {
8
- valueTree(): ParsedNodeValuesLike<Value | undefined>;
9
+ valueTree(provider: ValueProviderContext): ParsedNodeValuesLike<Value | undefined>;
9
10
  }
@@ -1,4 +1,4 @@
1
- import { ParsedNodeValuesLike } from '../values/ParsedNodeValues';
1
+ import type { ParsedNodeValuesLike } from '../values/ParsedNodeValues';
2
2
  import { TreeNode, TreeNodeListener } from '@journeyapps/common-tree';
3
3
  import { ParseEvent } from '../ParseEvent';
4
4
  import type { NodeInput } from '../input/NodeInput';
@@ -7,8 +7,7 @@ import { ParsedAttribute } from './ParsedAttribute';
7
7
  import { ParsedDiagnostic, ParsedValidationDiagnostic } from './ParsedDiagnostic';
8
8
  import type { ValidationContext } from '@ja-platform/parser-expressions';
9
9
  import { ParsedChild, ParsedChildNamesMarker, ParsedNodeAttribute, ParsedNodeAttributeShape, ParsedNodeAttributeName, ParsedNodeChild, ParsedNodeExpressionKey, ParsedNodeKnownChildKey, ParsedNodeValue, ParsedNodeValueRequest, ParsedNodeValueRequestKey, ParsedNodeRequiredAttributeName, ParsedNodeShape, ParsedNodeUntypedExpressionKey } from './ParsedNodeTypes';
10
- import { ParsedValue } from '../values/ParsedValue';
11
- import { AbstractValueProvider } from '../values/AbstractValueProvider';
10
+ import type { ValueProviderContext } from '../values/ValueProviderContext';
12
11
  export interface ParsedNodeOptions extends ParseEvent {
13
12
  definition: Node<any>;
14
13
  key?: string;
@@ -36,10 +35,8 @@ export interface ParsedNodeListener<Shape extends ParsedNodeShape = ParsedNodeSh
36
35
  postValidation?(event: NodeValidationEvent<Shape, Value>): void;
37
36
  }
38
37
  export declare class ParsedNode<T extends ParsedNodeShape = ParsedNodeShape, Value = ParsedNodeValue<T>> extends TreeNode<ParsedNodeListener<any, any>> {
39
- private readonly parsedValues;
40
38
  private attributesByKey;
41
39
  private childrenByKey;
42
- private valueProviders?;
43
40
  readonly definition: Node<any>;
44
41
  readonly input?: NodeInput;
45
42
  readonly parseParentNode?: ParsedNode;
@@ -51,19 +48,11 @@ export declare class ParsedNode<T extends ParsedNodeShape = ParsedNodeShape, Val
51
48
  registerListener(listener: Partial<ParsedNodeListener<T, Value>>): () => void;
52
49
  get children(): ParsedNode[];
53
50
  getRoot(): ParsedNode;
54
- get parsedValueProviders(): readonly AbstractValueProvider[] | undefined;
55
- setValueProviders(providers: readonly AbstractValueProvider[]): this;
56
- value<const Keys extends readonly ParsedNodeValueRequestKey<T, Value>[]>(attributes: Keys): ParsedNodeValuesLike<ParsedNodeValueRequest<T, Value, Keys>>;
57
- value<RequestedValue = any>(attributes: readonly ParsedNodeUntypedExpressionKey<T>[]): ParsedNodeValuesLike<RequestedValue>;
58
- /**
59
- * Resolve this node's attributes and descendants through their value providers.
60
- * Include declared defaults for absent children without creating parsed nodes.
61
- */
62
- valueTree(): ParsedNodeValuesLike<Value>;
63
- /**
64
- * Collect retained attribute sources for a value container to own and release.
65
- */
66
- protected collectAttributeValues(attributeKeys: readonly string[]): Array<readonly [string, ParsedValue<unknown>]>;
51
+ value<const Keys extends readonly ParsedNodeValueRequestKey<T, Value>[]>(attributes: Keys, provider: ValueProviderContext): ParsedNodeValuesLike<ParsedNodeValueRequest<T, Value, Keys>>;
52
+ value<RequestedValue = any>(attributes: readonly ParsedNodeUntypedExpressionKey<T>[], provider: ValueProviderContext): ParsedNodeValuesLike<RequestedValue>;
53
+ protected createValues(attributeKeys: readonly string[], provider: ValueProviderContext): ParsedNodeValuesLike<any>;
54
+ /** Assemble this node's flat attribute set and its child trees. */
55
+ valueTree(provider: ValueProviderContext): ParsedNodeValuesLike<Value>;
67
56
  attribute<Key extends Extract<ParsedNodeRequiredAttributeName<T>, ParsedNodeExpressionKey<T>>>(key: Key): ParsedNodeAttribute<T, Key>;
68
57
  attribute<Key extends Exclude<ParsedNodeExpressionKey<T>, ParsedNodeRequiredAttributeName<T>>>(key: Key): ParsedNodeAttribute<T, Key> | undefined;
69
58
  attribute<Attribute extends ParsedAttribute = ParsedAttribute>(key: string): Attribute | undefined;
@@ -95,7 +84,6 @@ export declare class ParsedNode<T extends ParsedNodeShape = ParsedNodeShape, Val
95
84
  childEntries(): ParsedChild[];
96
85
  nodes(): ParsedNode[];
97
86
  private flattenParsedArray;
98
- private getParsedValue;
99
87
  private addParsedAttribute;
100
88
  private addParsedChild;
101
89
  }
@@ -1,6 +1,7 @@
1
- import { ParsedNode } from './ParsedNode';
2
1
  import { type ParsedNodeValuesLike } from '../values/ParsedNodeValues';
2
+ import type { ValueProviderContext } from '../values/ValueProviderContext';
3
+ import { ParsedNode } from './ParsedNode';
3
4
  /** Only document keys become entries; the entry definition does not imply a default key. */
4
5
  export declare class ParsedRecordNode<Entry extends ParsedNode<any, any>, Value> extends ParsedNode<Record<string, Entry>, Record<string, Value>> {
5
- valueTree(): ParsedNodeValuesLike<Record<string, Value>>;
6
+ valueTree(provider: ValueProviderContext): ParsedNodeValuesLike<Record<string, Value>>;
6
7
  }
@@ -1,16 +1,14 @@
1
1
  import { BaseObserver } from '@journeyapps/common-utils';
2
2
  export interface ParsedNodeValuesListener<T> {
3
- changed?: (value: T) => void;
4
- disposed?: () => void;
3
+ changed?(value: T): void;
4
+ disposed?(): void;
5
5
  }
6
6
  export interface ParsedNodeValuesLike<T> {
7
7
  readonly current: T;
8
8
  registerListener(listener: Partial<ParsedNodeValuesListener<T>>): () => void;
9
9
  dispose(): void;
10
10
  }
11
- /**
12
- * Combine attribute or descendant values into one disposable value.
13
- */
11
+ /** Owns attribute or descendant evaluations and their combined current value. */
14
12
  export declare class ParsedNodeValues<T> extends BaseObserver<ParsedNodeValuesListener<T>> implements ParsedNodeValuesLike<T> {
15
13
  private readonly sources;
16
14
  private readonly compose;
@@ -1,6 +1,6 @@
1
1
  import { BaseObserver } from '@journeyapps/common-utils';
2
2
  import type { AbstractValueProvider } from './AbstractValueProvider';
3
- import { ParsedAttribute } from '../parsed/ParsedAttribute';
3
+ import type { ParsedAttribute } from '../parsed/ParsedAttribute';
4
4
  import { ParsedProviderValue } from './ParsedProviderValue';
5
5
  export interface ParsedValueListener<T> {
6
6
  changed?: (value: T) => void;
@@ -13,26 +13,17 @@ export interface ParsedValueLike<T> {
13
13
  }
14
14
  /**
15
15
  * Creates contributions from providers ordered from lowest to highest priority.
16
- * Subscribes to every contribution and caches the last active value.
16
+ * Subscribes to every contribution and keeps the current winning value.
17
17
  */
18
18
  export declare class ParsedValue<T> extends BaseObserver<ParsedValueListener<T | undefined>> {
19
19
  private readonly attribute;
20
20
  current: T | undefined;
21
21
  readonly providerValues: readonly ParsedProviderValue<unknown>[];
22
- private retainCount;
23
- private released;
22
+ private disposed;
24
23
  private readonly deregister;
25
24
  private selected?;
26
25
  constructor(attribute: ParsedAttribute, providers: readonly AbstractValueProvider[]);
27
26
  get activeValue(): ParsedProviderValue<unknown> | undefined;
28
- /**
29
- * Keep this resolved value and its contributions alive for another consumer.
30
- */
31
- retain(): this;
32
- /**
33
- * Dispose contributions when the last consumer releases this value.
34
- */
35
- release(): void;
36
27
  dispose(): void;
37
28
  private refresh;
38
29
  }
@@ -0,0 +1,5 @@
1
+ import type { AbstractValueProvider } from './AbstractValueProvider';
2
+ /** Supplies the provider order for independently owned parsed-node evaluations. */
3
+ export interface ValueProviderContext {
4
+ readonly providers: readonly AbstractValueProvider[];
5
+ }
package/dist/index.js CHANGED
@@ -56,4 +56,5 @@ __exportStar(require("./source/SourceReference"), exports);
56
56
  __exportStar(require("./input/AttributeInput"), exports);
57
57
  __exportStar(require("./input/NodeInput"), exports);
58
58
  __exportStar(require("./input/AttributeParseContext"), exports);
59
+ __exportStar(require("./values/ValueProviderContext"), exports);
59
60
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC,+CAA6B;AAC7B,6DAA2C;AAC3C,yDAAuC;AACvC,gEAA8C;AAC9C,wEAAsD;AACtD,qEAAmD;AACnD,mEAAiD;AACjD,iEAA+C;AAC/C,6DAA2C;AAC3C,+DAA6C;AAC7C,6DAA2C;AAC3C,4DAA0C;AAC1C,kEAAgD;AAChD,6DAA2C;AAC3C,4DAA0C;AAC1C,0DAAwC;AACxC,+CAA6B;AAC7B,sDAAoC;AACpC,2DAAyC;AACzC,qDAAmC;AACnC,qDAAmC;AACnC,4DAA0C;AAC1C,4DAA0C;AAC1C,2DAAyC;AACzC,2DAAyC;AACzC,6DAA2C;AAC3C,4DAA0C;AAC1C,sDAAoC;AACpC,2DAAyC;AACzC,iEAA+C;AAC/C,2EAAyD;AACzD,sEAAoD;AACpD,4DAA0C;AAC1C,+DAA6C;AAC7C,qEAAmD;AACnD,uDAAqC;AACrC,wDAAsC;AAEtC,2DAAyC;AACzC,yDAAuC;AACvC,oDAAkC;AAClC,gEAA8C","sourcesContent":["export * from './AttributeParseEvent';\nexport * from './ParseEvent';\nexport * from './attributes/ConditionType';\nexport * from './attributes/Attribute';\nexport * from './attributes/BooleanAttribute';\nexport * from './attributes/ConstantBooleanAttribute';\nexport * from './attributes/ConstantTextAttribute';\nexport * from './attributes/ExpressionAttribute';\nexport * from './attributes/FunctionAttribute';\nexport * from './attributes/ListAttribute';\nexport * from './attributes/NumberAttribute';\nexport * from './attributes/PathAttribute';\nexport * from './attributes/SetAttribute';\nexport * from './attributes/TextArrayAttribute';\nexport * from './attributes/TextAttribute';\nexport * from './entities/AbstractEntity';\nexport * from './entities/CommonEntity';\nexport * from './nodes/Node';\nexport * from './nodes/ContentNode';\nexport * from './nodes/NodeAlternatives';\nexport * from './nodes/RecordNode';\nexport * from './nodes/EitherNode';\nexport * from './parsed/ParsedEitherNode';\nexport * from './parsed/ParsedRecordNode';\nexport * from './parsed/ParsedArrayNode';\nexport * from './parsed/ParsedAttribute';\nexport * from './parsed/ParsedContentNode';\nexport * from './parsed/ParsedDiagnostic';\nexport * from './parsed/ParsedNode';\nexport * from './parsed/ParsedNodeTypes';\nexport * from './values/AbstractValueProvider';\nexport * from './values/ConstantExpressionValueProvider';\nexport * from './values/ParserDefaultValueProvider';\nexport * from './values/ParsedNodeValues';\nexport * from './values/ParsedProviderValue';\nexport * from './values/MappedParsedProviderValue';\nexport * from './values/ParsedValue';\nexport * from './utils/types/valueOf';\n\nexport * from './source/SourceReference';\nexport * from './input/AttributeInput';\nexport * from './input/NodeInput';\nexport * from './input/AttributeParseContext';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC,+CAA6B;AAC7B,6DAA2C;AAC3C,yDAAuC;AACvC,gEAA8C;AAC9C,wEAAsD;AACtD,qEAAmD;AACnD,mEAAiD;AACjD,iEAA+C;AAC/C,6DAA2C;AAC3C,+DAA6C;AAC7C,6DAA2C;AAC3C,4DAA0C;AAC1C,kEAAgD;AAChD,6DAA2C;AAC3C,4DAA0C;AAC1C,0DAAwC;AACxC,+CAA6B;AAC7B,sDAAoC;AACpC,2DAAyC;AACzC,qDAAmC;AACnC,qDAAmC;AACnC,4DAA0C;AAC1C,4DAA0C;AAC1C,2DAAyC;AACzC,2DAAyC;AACzC,6DAA2C;AAC3C,4DAA0C;AAC1C,sDAAoC;AACpC,2DAAyC;AACzC,iEAA+C;AAC/C,2EAAyD;AACzD,sEAAoD;AACpD,4DAA0C;AAC1C,+DAA6C;AAC7C,qEAAmD;AACnD,uDAAqC;AACrC,wDAAsC;AAEtC,2DAAyC;AACzC,yDAAuC;AACvC,oDAAkC;AAClC,gEAA8C;AAE9C,gEAA8C","sourcesContent":["export * from './AttributeParseEvent';\nexport * from './ParseEvent';\nexport * from './attributes/ConditionType';\nexport * from './attributes/Attribute';\nexport * from './attributes/BooleanAttribute';\nexport * from './attributes/ConstantBooleanAttribute';\nexport * from './attributes/ConstantTextAttribute';\nexport * from './attributes/ExpressionAttribute';\nexport * from './attributes/FunctionAttribute';\nexport * from './attributes/ListAttribute';\nexport * from './attributes/NumberAttribute';\nexport * from './attributes/PathAttribute';\nexport * from './attributes/SetAttribute';\nexport * from './attributes/TextArrayAttribute';\nexport * from './attributes/TextAttribute';\nexport * from './entities/AbstractEntity';\nexport * from './entities/CommonEntity';\nexport * from './nodes/Node';\nexport * from './nodes/ContentNode';\nexport * from './nodes/NodeAlternatives';\nexport * from './nodes/RecordNode';\nexport * from './nodes/EitherNode';\nexport * from './parsed/ParsedEitherNode';\nexport * from './parsed/ParsedRecordNode';\nexport * from './parsed/ParsedArrayNode';\nexport * from './parsed/ParsedAttribute';\nexport * from './parsed/ParsedContentNode';\nexport * from './parsed/ParsedDiagnostic';\nexport * from './parsed/ParsedNode';\nexport * from './parsed/ParsedNodeTypes';\nexport * from './values/AbstractValueProvider';\nexport * from './values/ConstantExpressionValueProvider';\nexport * from './values/ParserDefaultValueProvider';\nexport * from './values/ParsedNodeValues';\nexport * from './values/ParsedProviderValue';\nexport * from './values/MappedParsedProviderValue';\nexport * from './values/ParsedValue';\nexport * from './utils/types/valueOf';\n\nexport * from './source/SourceReference';\nexport * from './input/AttributeInput';\nexport * from './input/NodeInput';\nexport * from './input/AttributeParseContext';\n\nexport * from './values/ValueProviderContext';\n"]}
@@ -18,18 +18,14 @@ class ParsedArrayNode extends common_tree_1.TreeNode {
18
18
  /**
19
19
  * Resolve repeated children in order, preserving nested arrays.
20
20
  */
21
- valueTree() {
22
- return new ParsedNodeValues_1.ParsedNodeValues(this.nodes().map((child) => child.valueTree()), (values) => { var _a; return [
21
+ valueTree(provider) {
22
+ return new ParsedNodeValues_1.ParsedNodeValues(this.nodes().map((child) => child.valueTree(provider)), (values) => { var _a; return [
23
23
  ...(values.length === 0 && !this.inputPresent ? ((_a = this.definition.defaultValue) !== null && _a !== void 0 ? _a : []) : values)
24
24
  ]; });
25
25
  }
26
26
  at(index) {
27
27
  return this.nodes()[index];
28
28
  }
29
- setValueProviders(providers) {
30
- this.nodes().forEach((child) => child.setValueProviders(providers));
31
- return this;
32
- }
33
29
  pushError({ message, source, type }) {
34
30
  var _a;
35
31
  const diagnostic = this.diagnostics.pushError({ message, source, type });
@@ -1 +1 @@
1
- {"version":3,"file":"ParsedArrayNode.js","sourceRoot":"","sources":["../../src/parsed/ParsedArrayNode.ts"],"names":[],"mappings":";;;AAAA,iEAAoF;AAEpF,0DAAoD;AAKpD,yDAA6E;AAY7E,qBAAwF,SAAQ,sBAAQ;IAMtG,YAAY,OAA+B;QACzC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAHJ,gBAAW,GAAG,IAAI,wCAAqB,EAAE,CAAC;QAIzD,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC/B,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,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C;IACtC,CAAC;IAED,GAAG,CAAI,EAAqC;QAC1C,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC9B,CAAC;CACF","sourcesContent":["import { ParsedNodeValues, ParsedNodeValuesLike } from '../values/ParsedNodeValues';\nimport { ParsedExpressionValue } from './ParsedNodeTypes';\nimport { TreeNode } from '@journeyapps/common-tree';\n\nimport type { SourceReference } from '../source/SourceReference';\nimport { Node } from '../nodes/Node';\nimport { AbstractValueProvider } from '../values/AbstractValueProvider';\nimport { ParsedDiagnostic, ParsedDiagnosticStore } from './ParsedDiagnostic';\nimport { ParsedNode } from './ParsedNode';\n\nexport interface ParsedArrayNodeOptions {\n definition: Node<any>;\n key: string;\n inputPresent?: boolean;\n source?: SourceReference;\n}\n\nexport type ParsedArrayNodeChild = ParsedNode<any, any> | ParsedArrayNode<any>;\n\nexport class ParsedArrayNode<Child extends ParsedArrayNodeChild = ParsedNode<any, any>> extends TreeNode {\n public readonly definition: Node<any>;\n readonly inputPresent?: boolean;\n readonly source?: SourceReference;\n private readonly diagnostics = new ParsedDiagnosticStore();\n\n constructor(options: ParsedArrayNodeOptions) {\n super(options.key);\n this.definition = options.definition;\n this.inputPresent = options.inputPresent;\n this.source = options.source;\n }\n\n nodes(): Child[] {\n return this.getNodes<Child>();\n }\n\n /**\n * Resolve repeated children in order, preserving nested arrays.\n */\n valueTree(): ParsedNodeValuesLike<ParsedExpressionValue<Child>[]> {\n return new ParsedNodeValues(\n this.nodes().map((child) => child.valueTree()),\n (values) =>\n [\n ...(values.length === 0 && !this.inputPresent ? (this.definition.defaultValue ?? []) : values)\n ] as ParsedExpressionValue<Child>[]\n );\n }\n\n at(index: number): Child | undefined {\n return this.nodes()[index];\n }\n\n setValueProviders(providers: readonly AbstractValueProvider[]): this {\n this.nodes().forEach((child) => child.setValueProviders(providers));\n return this;\n }\n\n pushError({ message, source, type }: ParsedDiagnostic): ParsedDiagnostic {\n const diagnostic = this.diagnostics.pushError({ message, source, type });\n if (source) {\n this.getParent<ParsedNode>()?.reportDiagnostic({ source, message, type });\n }\n return diagnostic;\n }\n\n errors(): ParsedDiagnostic[] {\n return this.diagnostics.errors();\n }\n\n hasErrors(): boolean {\n return this.diagnostics.hasErrors();\n }\n\n map<T>(cb: (node: Child, index: number) => T): T[] {\n return this.nodes().map(cb);\n }\n}\n"]}
1
+ {"version":3,"file":"ParsedArrayNode.js","sourceRoot":"","sources":["../../src/parsed/ParsedArrayNode.ts"],"names":[],"mappings":";;;AAAA,iEAAyF;AAGzF,0DAAoD;AAIpD,yDAA6E;AAY7E,qBAAwF,SAAQ,sBAAQ;IAMtG,YAAY,OAA+B;QACzC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAHJ,gBAAW,GAAG,IAAI,wCAAqB,EAAE,CAAC;QAIzD,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;QACzC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC/B,CAAC;IAED,KAAK;QACH,OAAO,IAAI,CAAC,QAAQ,EAAS,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,QAA8B;QACtC,OAAO,IAAI,mCAAgB,CACzB,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,EACtD,CAAC,MAAM,EAAE,EAAE,kBACT;YACE,GAAG,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,OAAC,IAAI,CAAC,UAAU,CAAC,YAAY,mCAAI,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;SAC7D,GAAA,CACtC,CAAC;IACJ,CAAC;IAED,EAAE,CAAC,KAAa;QACd,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;IAED,SAAS,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAoB;;QACnD,MAAM,UAAU,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;QACzE,IAAI,MAAM,EAAE,CAAC;YACX,MAAA,IAAI,CAAC,SAAS,EAAc,0CAAE,gBAAgB,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;QAC5E,CAAC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC;IAED,MAAM;QACJ,OAAO,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;IACnC,CAAC;IAED,SAAS;QACP,OAAO,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC;IACtC,CAAC;IAED,GAAG,CAAI,EAAqC;QAC1C,OAAO,IAAI,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC9B,CAAC;CACF","sourcesContent":["import { ParsedNodeValues, type ParsedNodeValuesLike } from '../values/ParsedNodeValues';\nimport type { ValueProviderContext } from '../values/ValueProviderContext';\nimport { ParsedExpressionValue } from './ParsedNodeTypes';\nimport { TreeNode } from '@journeyapps/common-tree';\n\nimport type { SourceReference } from '../source/SourceReference';\nimport { Node } from '../nodes/Node';\nimport { ParsedDiagnostic, ParsedDiagnosticStore } from './ParsedDiagnostic';\nimport { ParsedNode } from './ParsedNode';\n\nexport interface ParsedArrayNodeOptions {\n definition: Node<any>;\n key: string;\n inputPresent?: boolean;\n source?: SourceReference;\n}\n\nexport type ParsedArrayNodeChild = ParsedNode<any, any> | ParsedArrayNode<any>;\n\nexport class ParsedArrayNode<Child extends ParsedArrayNodeChild = ParsedNode<any, any>> extends TreeNode {\n public readonly definition: Node<any>;\n readonly inputPresent?: boolean;\n readonly source?: SourceReference;\n private readonly diagnostics = new ParsedDiagnosticStore();\n\n constructor(options: ParsedArrayNodeOptions) {\n super(options.key);\n this.definition = options.definition;\n this.inputPresent = options.inputPresent;\n this.source = options.source;\n }\n\n nodes(): Child[] {\n return this.getNodes<Child>();\n }\n\n /**\n * Resolve repeated children in order, preserving nested arrays.\n */\n valueTree(provider: ValueProviderContext): ParsedNodeValuesLike<ParsedExpressionValue<Child>[]> {\n return new ParsedNodeValues(\n this.nodes().map((child) => child.valueTree(provider)),\n (values) =>\n [\n ...(values.length === 0 && !this.inputPresent ? (this.definition.defaultValue ?? []) : values)\n ] as ParsedExpressionValue<Child>[]\n );\n }\n\n at(index: number): Child | undefined {\n return this.nodes()[index];\n }\n\n pushError({ message, source, type }: ParsedDiagnostic): ParsedDiagnostic {\n const diagnostic = this.diagnostics.pushError({ message, source, type });\n if (source) {\n this.getParent<ParsedNode>()?.reportDiagnostic({ source, message, type });\n }\n return diagnostic;\n }\n\n errors(): ParsedDiagnostic[] {\n return this.diagnostics.errors();\n }\n\n hasErrors(): boolean {\n return this.diagnostics.hasErrors();\n }\n\n map<T>(cb: (node: Child, index: number) => T): T[] {\n return this.nodes().map(cb);\n }\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ParsedContentNode = void 0;
4
- const ParsedNode_1 = require("./ParsedNode");
5
4
  const ParsedNodeValues_1 = require("../values/ParsedNodeValues");
5
+ const ParsedNode_1 = require("./ParsedNode");
6
6
  /**
7
7
  * A node whose element content resolves to the codec's value rather than an object.
8
8
  */
@@ -10,9 +10,9 @@ class ParsedContentNode extends ParsedNode_1.ParsedNode {
10
10
  content() {
11
11
  return super.content();
12
12
  }
13
- valueTree() {
14
- const [[, source]] = this.collectAttributeValues(['content']);
15
- return new ParsedNodeValues_1.ParsedNodeValues([source], ([value]) => value);
13
+ valueTree(provider) {
14
+ const source = this.createValues(['content'], provider);
15
+ return new ParsedNodeValues_1.ParsedNodeValues([source], ([value]) => value.content);
16
16
  }
17
17
  }
18
18
  exports.ParsedContentNode = ParsedContentNode;
@@ -1 +1 @@
1
- {"version":3,"file":"ParsedContentNode.js","sourceRoot":"","sources":["../../src/parsed/ParsedContentNode.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAE1C,iEAAoF;AAMpF;;GAEG;AACH,uBAA+E,SAAQ,uBAGtF;IACC,OAAO;QACL,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;IAED,SAAS;QACP,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,sBAAsB,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;QAC9D,OAAO,IAAI,mCAAgB,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,KAA0B,CAAC,CAAC;IACjF,CAAC;CACF","sourcesContent":["import { ParsedNode } from './ParsedNode';\nimport { ParsedNodeShapeValue } from './ParsedNodeTypes';\nimport { ParsedNodeValues, ParsedNodeValuesLike } from '../values/ParsedNodeValues';\n\nexport type ParsedContentNodeShape<Expression extends ParsedNodeShapeValue> = {\n content?: Expression;\n};\n\n/**\n * A node whose element content resolves to the codec's value rather than an object.\n */\nexport class ParsedContentNode<Expression extends ParsedNodeShapeValue, Value> extends ParsedNode<\n ParsedContentNodeShape<Expression>,\n Value | undefined\n> {\n content(): Expression | undefined {\n return super.content();\n }\n\n valueTree(): ParsedNodeValuesLike<Value | undefined> {\n const [[, source]] = this.collectAttributeValues(['content']);\n return new ParsedNodeValues([source], ([value]) => value as Value | undefined);\n }\n}\n"]}
1
+ {"version":3,"file":"ParsedContentNode.js","sourceRoot":"","sources":["../../src/parsed/ParsedContentNode.ts"],"names":[],"mappings":";;;AAAA,iEAAyF;AAEzF,6CAA0C;AAO1C;;GAEG;AACH,uBAA+E,SAAQ,uBAGtF;IACC,OAAO;QACL,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;IAED,SAAS,CAAC,QAA8B;QACtC,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,CAAC;QACxD,OAAO,IAAI,mCAAgB,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,CAAE,KAA6B,CAAC,OAAO,CAAC,CAAC;IAC7F,CAAC;CACF","sourcesContent":["import { ParsedNodeValues, type ParsedNodeValuesLike } from '../values/ParsedNodeValues';\nimport type { ValueProviderContext } from '../values/ValueProviderContext';\nimport { ParsedNode } from './ParsedNode';\nimport { ParsedNodeShapeValue } from './ParsedNodeTypes';\n\nexport type ParsedContentNodeShape<Expression extends ParsedNodeShapeValue> = {\n content?: Expression;\n};\n\n/**\n * A node whose element content resolves to the codec's value rather than an object.\n */\nexport class ParsedContentNode<Expression extends ParsedNodeShapeValue, Value> extends ParsedNode<\n ParsedContentNodeShape<Expression>,\n Value | undefined\n> {\n content(): Expression | undefined {\n return super.content();\n }\n\n valueTree(provider: ValueProviderContext): ParsedNodeValuesLike<Value | undefined> {\n const source = this.createValues(['content'], provider);\n return new ParsedNodeValues([source], ([value]) => (value as { content?: Value }).content);\n }\n}\n"]}
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ParsedEitherNode = void 0;
4
- const ParsedNode_1 = require("./ParsedNode");
5
4
  const ParsedNodeValues_1 = require("../values/ParsedNodeValues");
5
+ const ParsedNode_1 = require("./ParsedNode");
6
6
  /** Preserve the selected branch's value without adding an object to the output. */
7
7
  class ParsedEitherNode extends ParsedNode_1.ParsedNode {
8
- valueTree() {
8
+ valueTree(provider) {
9
9
  const selected = this.child('value');
10
10
  if (!selected)
11
11
  return new ParsedNodeValues_1.ParsedNodeValues([], () => undefined);
12
- return selected.valueTree();
12
+ return selected.valueTree(provider);
13
13
  }
14
14
  }
15
15
  exports.ParsedEitherNode = ParsedEitherNode;
@@ -1 +1 @@
1
- {"version":3,"file":"ParsedEitherNode.js","sourceRoot":"","sources":["../../src/parsed/ParsedEitherNode.ts"],"names":[],"mappings":";;;AAAA,6CAA0C;AAE1C,iEAAyF;AAEzF,mFAAmF;AACnF,sBAAqC,SAAQ,uBAAsD;IACjG,SAAS;QACP,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACrC,IAAI,CAAC,QAAQ;YAAE,OAAO,IAAI,mCAAgB,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAChE,OAAO,QAAQ,CAAC,SAAS,EAAiC,CAAC;IAC7D,CAAC;CACF","sourcesContent":["import { ParsedNode } from './ParsedNode';\nimport type { ParsedChild } from './ParsedNodeTypes';\nimport { ParsedNodeValues, type ParsedNodeValuesLike } from '../values/ParsedNodeValues';\n\n/** Preserve the selected branch's value without adding an object to the output. */\nexport class ParsedEitherNode<Value> extends ParsedNode<{ value?: ParsedChild }, Value | undefined> {\n valueTree(): ParsedNodeValuesLike<Value | undefined> {\n const selected = this.child('value');\n if (!selected) return new ParsedNodeValues([], () => undefined);\n return selected.valueTree() as ParsedNodeValuesLike<Value>;\n }\n}\n"]}
1
+ {"version":3,"file":"ParsedEitherNode.js","sourceRoot":"","sources":["../../src/parsed/ParsedEitherNode.ts"],"names":[],"mappings":";;;AAAA,iEAAyF;AAEzF,6CAA0C;AAG1C,mFAAmF;AACnF,sBAAqC,SAAQ,uBAAsD;IACjG,SAAS,CAAC,QAA8B;QACtC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACrC,IAAI,CAAC,QAAQ;YAAE,OAAO,IAAI,mCAAgB,CAAC,EAAE,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAChE,OAAO,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAgC,CAAC;IACrE,CAAC;CACF","sourcesContent":["import { ParsedNodeValues, type ParsedNodeValuesLike } from '../values/ParsedNodeValues';\nimport type { ValueProviderContext } from '../values/ValueProviderContext';\nimport { ParsedNode } from './ParsedNode';\nimport type { ParsedChild } from './ParsedNodeTypes';\n\n/** Preserve the selected branch's value without adding an object to the output. */\nexport class ParsedEitherNode<Value> extends ParsedNode<{ value?: ParsedChild }, Value | undefined> {\n valueTree(provider: ValueProviderContext): ParsedNodeValuesLike<Value | undefined> {\n const selected = this.child('value');\n if (!selected) return new ParsedNodeValues([], () => undefined);\n return selected.valueTree(provider) as ParsedNodeValuesLike<Value>;\n }\n}\n"]}
@@ -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
- get parsedValueProviders() {
40
- return this.valueProviders;
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
- value(attributeKeys) {
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
- for (const attribute of attributes) {
87
- sources.push([attribute.getKey(), this.getParsedValue(attribute).retain()]);
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,OA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AAQ,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 { 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,GA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CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;YACzC,IAAI,KAAK,YAAY,iCAAe,EAAE,CAAC;gBACrC,OAAO,IAAI,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;YACxC,CAAC;YACD,OAAO,CAAC,KAAK,CAAC,CAAC;QACjB,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,kBAAkB,CAAC,SAA0B;QACnD,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC,CAAC;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,6CAA0C;AAC1C,iEAAyF;AAEzF,4FAA4F;AAC5F,sBAAyE,SAAQ,uBAGhF;IACC,SAAS;QACP,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,EAAE,CAAC,EACzC,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 { ParsedNode } from './ParsedNode';\nimport { ParsedNodeValues, type ParsedNodeValuesLike } from '../values/ParsedNodeValues';\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(): ParsedNodeValuesLike<Record<string, Value>> {\n const entries = this.nodes();\n return new ParsedNodeValues(\n entries.map((entry) => entry.valueTree()),\n (values) =>\n Object.fromEntries(entries.map((entry, index) => [entry.getKey(), values[index]])) as Record<string, Value>\n );\n }\n}\n"]}
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"]}