@ja-platform/parser-core 0.0.0-dev-20261022223751 → 0.0.0-dev-20261027014616
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -0
- package/dist/@types/attributes/BooleanAttribute.d.ts +4 -4
- package/dist/@types/attributes/ListAttribute.d.ts +4 -4
- package/dist/@types/attributes/NumberAttribute.d.ts +4 -4
- package/dist/@types/attributes/SetAttribute.d.ts +4 -4
- package/dist/@types/attributes/TextAttribute.d.ts +4 -2
- package/dist/@types/index.d.ts +4 -0
- package/dist/@types/input/NodeInput.d.ts +26 -0
- package/dist/@types/nodes/EitherNode.d.ts +32 -0
- package/dist/@types/nodes/Node.d.ts +4 -2
- package/dist/@types/nodes/NodeAlternatives.d.ts +5 -2
- package/dist/@types/nodes/RecordNode.d.ts +16 -0
- package/dist/@types/parsed/ParsedArrayNode.d.ts +5 -0
- package/dist/@types/parsed/ParsedEitherNode.d.ts +9 -0
- package/dist/@types/parsed/ParsedRecordNode.d.ts +6 -0
- package/dist/attributes/BooleanAttribute.js.map +1 -1
- package/dist/attributes/ListAttribute.js.map +1 -1
- package/dist/attributes/NumberAttribute.js.map +1 -1
- package/dist/attributes/SetAttribute.js.map +1 -1
- package/dist/attributes/TextAttribute.js.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/input/NodeInput.js +11 -0
- package/dist/input/NodeInput.js.map +1 -1
- package/dist/nodes/EitherNode.js +95 -0
- package/dist/nodes/EitherNode.js.map +1 -0
- package/dist/nodes/Node.js +17 -5
- package/dist/nodes/Node.js.map +1 -1
- package/dist/nodes/NodeAlternatives.js +9 -2
- package/dist/nodes/NodeAlternatives.js.map +1 -1
- package/dist/nodes/RecordNode.js +36 -0
- package/dist/nodes/RecordNode.js.map +1 -0
- package/dist/parsed/ParsedArrayNode.js +5 -1
- package/dist/parsed/ParsedArrayNode.js.map +1 -1
- package/dist/parsed/ParsedEitherNode.js +16 -0
- package/dist/parsed/ParsedEitherNode.js.map +1 -0
- package/dist/parsed/ParsedNode.js +3 -0
- package/dist/parsed/ParsedNode.js.map +1 -1
- package/dist/parsed/ParsedRecordNode.js +14 -0
- package/dist/parsed/ParsedRecordNode.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
package/README.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Parser core
|
|
2
|
+
|
|
3
|
+
`@ja-platform/parser-core` defines nodes, attributes, parsed trees, and value
|
|
4
|
+
providers. Document adapters supply the input, so a definition can read JSON or
|
|
5
|
+
XML without depending on either format.
|
|
6
|
+
|
|
7
|
+
For examples of definitions and the documents they read, see
|
|
8
|
+
[JSON document inputs](../document-json/README.md) and
|
|
9
|
+
[XML document inputs](../document-xml/README.md).
|
|
10
|
+
|
|
11
|
+
## Resolving values
|
|
12
|
+
|
|
13
|
+
Parsing creates a tree of parsed nodes and expressions. Value providers tell that
|
|
14
|
+
tree how to resolve values. For a document containing constants and defaults:
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import {
|
|
18
|
+
Node,
|
|
19
|
+
NumberAttribute,
|
|
20
|
+
ConstantExpressionValueProvider,
|
|
21
|
+
ParserDefaultValueProvider
|
|
22
|
+
} from '@ja-platform/parser-core';
|
|
23
|
+
import { JSONNodeInput } from '@ja-platform/parser-document-json';
|
|
24
|
+
|
|
25
|
+
const config = new Node({ name: 'config' });
|
|
26
|
+
config.addAttribute(new NumberAttribute({ name: 'delay', defaultValue: 500 }));
|
|
27
|
+
|
|
28
|
+
const parsed = config.parseTree({
|
|
29
|
+
input: JSONNodeInput.parse('{"delay":250}'),
|
|
30
|
+
report: (diagnostic) => console.warn(diagnostic)
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const providers = [new ParserDefaultValueProvider(), new ConstantExpressionValueProvider()];
|
|
34
|
+
parsed.setValueProviders(providers);
|
|
35
|
+
|
|
36
|
+
const values = parsed.valueTree();
|
|
37
|
+
console.log(values.current); // { delay: 250 }
|
|
38
|
+
|
|
39
|
+
// Release the value subscription and the providers when finished.
|
|
40
|
+
values.dispose();
|
|
41
|
+
providers.forEach((provider) => provider.dispose());
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The constant provider supplies the explicit `250`. With `{}` as the input, the
|
|
45
|
+
default provider supplies `500`. The same provider setup works for a tree parsed
|
|
46
|
+
from XML; it operates on the parsed expressions, not the source format.
|
|
47
|
+
|
|
48
|
+
For dynamic expressions, the host supplies providers that resolve references or
|
|
49
|
+
evaluate code. Keep that setup separate from document parsing so the same
|
|
50
|
+
definitions and inputs can be used in different hosts.
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { Attribute, AttributeOptions, AttributeGenerics } from './Attribute';
|
|
2
2
|
import { EvaluatedExpression, ConstantExpression, ShorthandExpression } from '@ja-platform/parser-expressions';
|
|
3
3
|
export type CombinedBooleanExpression = EvaluatedExpression | ConstantExpression<boolean> | ShorthandExpression;
|
|
4
|
-
export interface BooleanAttributeGenerics extends AttributeGenerics {
|
|
5
|
-
Options:
|
|
4
|
+
export interface BooleanAttributeGenerics<Options extends AttributeOptions<boolean, boolean> = AttributeOptions<boolean, boolean>> extends AttributeGenerics {
|
|
5
|
+
Options: Options;
|
|
6
6
|
Value: CombinedBooleanExpression | null;
|
|
7
7
|
NormalizedValue: boolean;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* For dealing with boolean attribute types such as `show-if` and `hide-if`
|
|
11
11
|
*/
|
|
12
|
-
export declare class BooleanAttribute extends Attribute<BooleanAttributeGenerics
|
|
12
|
+
export declare class BooleanAttribute<Options extends AttributeOptions<boolean, boolean> = AttributeOptions<boolean, boolean>> extends Attribute<BooleanAttributeGenerics<Options>> {
|
|
13
13
|
static TYPE: string;
|
|
14
14
|
static isInstanceOf(attr: Attribute): attr is BooleanAttribute;
|
|
15
|
-
constructor(options:
|
|
15
|
+
constructor(options: Options);
|
|
16
16
|
serialize(): any;
|
|
17
17
|
}
|
|
@@ -5,14 +5,14 @@ export interface ListAttributeOptions extends AttributeOptions<string[]> {
|
|
|
5
5
|
options: string[];
|
|
6
6
|
delimiter?: string;
|
|
7
7
|
}
|
|
8
|
-
export interface ListAttributeGenerics extends AttributeGenerics {
|
|
8
|
+
export interface ListAttributeGenerics<Options extends ListAttributeOptions = ListAttributeOptions> extends AttributeGenerics {
|
|
9
9
|
Value: CombinedListExpression | null;
|
|
10
|
-
Options:
|
|
10
|
+
Options: Options;
|
|
11
11
|
}
|
|
12
|
-
export declare class ListAttribute extends Attribute<ListAttributeGenerics
|
|
12
|
+
export declare class ListAttribute<Options extends ListAttributeOptions = ListAttributeOptions> extends Attribute<ListAttributeGenerics<Options>> {
|
|
13
13
|
static TYPE: string;
|
|
14
14
|
delimiter: string;
|
|
15
|
-
constructor(options:
|
|
15
|
+
constructor(options: Options);
|
|
16
16
|
static isInstanceOf(attr: Attribute): attr is ListAttribute;
|
|
17
17
|
static toList(value: any, delimiter?: string): any[];
|
|
18
18
|
serialize(): any;
|
|
@@ -10,15 +10,15 @@ export interface NumberAttributeRange {
|
|
|
10
10
|
export interface NumberAttributeOptions extends AttributeOptions<number, number> {
|
|
11
11
|
range?: NumberAttributeRange;
|
|
12
12
|
}
|
|
13
|
-
export interface NumberAttributeGenerics extends AttributeGenerics {
|
|
14
|
-
Options:
|
|
13
|
+
export interface NumberAttributeGenerics<Options extends NumberAttributeOptions = NumberAttributeOptions> extends AttributeGenerics {
|
|
14
|
+
Options: Options;
|
|
15
15
|
Value: CombinedNumberExpression | null;
|
|
16
16
|
NormalizedValue: number;
|
|
17
17
|
}
|
|
18
|
-
export declare class NumberAttribute extends Attribute<NumberAttributeGenerics
|
|
18
|
+
export declare class NumberAttribute<Options extends NumberAttributeOptions = NumberAttributeOptions> extends Attribute<NumberAttributeGenerics<Options>> {
|
|
19
19
|
static TYPE: string;
|
|
20
20
|
static isInstanceOf(attr: Attribute): attr is NumberAttribute;
|
|
21
|
-
constructor(options:
|
|
21
|
+
constructor(options: Options);
|
|
22
22
|
protected getParsedValue(event: AttributeParseEvent): NumberAttributeGenerics['Value'];
|
|
23
23
|
setParent(parent: Node<any>): void;
|
|
24
24
|
serialize(): any;
|
|
@@ -4,13 +4,13 @@ export type CombinedSetExpression = EvaluatedExpression | ConstantExpression;
|
|
|
4
4
|
export interface SetAttributeOptions extends AttributeOptions<string> {
|
|
5
5
|
options: string[];
|
|
6
6
|
}
|
|
7
|
-
export interface SetAttributeGenerics extends AttributeGenerics {
|
|
7
|
+
export interface SetAttributeGenerics<Options extends SetAttributeOptions = SetAttributeOptions> extends AttributeGenerics {
|
|
8
8
|
Value: CombinedSetExpression | null;
|
|
9
|
-
Options:
|
|
9
|
+
Options: Options;
|
|
10
10
|
}
|
|
11
|
-
export declare class SetAttribute extends Attribute<SetAttributeGenerics
|
|
11
|
+
export declare class SetAttribute<Options extends SetAttributeOptions = SetAttributeOptions> extends Attribute<SetAttributeGenerics<Options>> {
|
|
12
12
|
static TYPE: string;
|
|
13
|
-
constructor(options:
|
|
13
|
+
constructor(options: Options);
|
|
14
14
|
static isInstanceOf(attr: Attribute): attr is SetAttribute;
|
|
15
15
|
serialize(): any;
|
|
16
16
|
}
|
|
@@ -8,9 +8,11 @@ export interface TextAttributeGenerics<Value = string> extends AttributeGenerics
|
|
|
8
8
|
Options: TextAttributeOptions<Value>;
|
|
9
9
|
NormalizedValue: Value;
|
|
10
10
|
}
|
|
11
|
-
export declare class TextAttribute<T extends TextAttributeGenerics<unknown> = TextAttributeGenerics> extends Attribute<T
|
|
11
|
+
export declare class TextAttribute<T extends TextAttributeGenerics<unknown> = TextAttributeGenerics, Options extends T['Options'] = T['Options']> extends Attribute<T & {
|
|
12
|
+
Options: Options;
|
|
13
|
+
}> {
|
|
12
14
|
static TYPE: string;
|
|
13
|
-
constructor(options:
|
|
15
|
+
constructor(options: Options);
|
|
14
16
|
static isInstanceOf(attr: Attribute): attr is TextAttribute<TextAttributeGenerics<unknown>>;
|
|
15
17
|
protected getParsedValue(event: AttributeParseEvent): CombinedTextExpression | null;
|
|
16
18
|
protected validateInput(event: AttributeParseEvent, expression: CombinedTextExpression): void;
|
package/dist/@types/index.d.ts
CHANGED
|
@@ -19,6 +19,10 @@ export * from './entities/CommonEntity';
|
|
|
19
19
|
export * from './nodes/Node';
|
|
20
20
|
export * from './nodes/ContentNode';
|
|
21
21
|
export * from './nodes/NodeAlternatives';
|
|
22
|
+
export * from './nodes/RecordNode';
|
|
23
|
+
export * from './nodes/EitherNode';
|
|
24
|
+
export * from './parsed/ParsedEitherNode';
|
|
25
|
+
export * from './parsed/ParsedRecordNode';
|
|
22
26
|
export * from './parsed/ParsedArrayNode';
|
|
23
27
|
export * from './parsed/ParsedAttribute';
|
|
24
28
|
export * from './parsed/ParsedContentNode';
|
|
@@ -1,9 +1,35 @@
|
|
|
1
1
|
import type { AttributeInput } from './AttributeInput';
|
|
2
|
+
import type { ParsedDiagnostic } from '../parsed/ParsedDiagnostic';
|
|
2
3
|
import type { SourceReference } from '../source/SourceReference';
|
|
4
|
+
export interface NodeInputSelector {
|
|
5
|
+
name: string;
|
|
6
|
+
key: string;
|
|
7
|
+
isMultiple?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface NodeInputSelection {
|
|
10
|
+
inputs: NodeInput[];
|
|
11
|
+
present: boolean;
|
|
12
|
+
source?: SourceReference;
|
|
13
|
+
diagnostics: ParsedDiagnostic[];
|
|
14
|
+
}
|
|
15
|
+
export declare enum NodeInputKind {
|
|
16
|
+
STRING = "string",
|
|
17
|
+
NUMBER = "number",
|
|
18
|
+
BOOLEAN = "boolean",
|
|
19
|
+
NULL = "null",
|
|
20
|
+
OBJECT = "object",
|
|
21
|
+
ARRAY = "array",
|
|
22
|
+
ELEMENT = "element"
|
|
23
|
+
}
|
|
3
24
|
export interface NodeInput {
|
|
25
|
+
readonly kind: NodeInputKind;
|
|
4
26
|
readonly name: string;
|
|
5
27
|
readonly source?: SourceReference;
|
|
6
28
|
attribute(name: string): AttributeInput | undefined;
|
|
7
29
|
content(): AttributeInput | undefined;
|
|
8
30
|
children(): Iterable<NodeInput>;
|
|
31
|
+
/** Select named entries, reporting inputs that cannot represent a record. */
|
|
32
|
+
recordEntries(): NodeInputSelection;
|
|
33
|
+
/** Select declared children in document order, retaining explicit empty collections. */
|
|
34
|
+
selectChildren(selectors: readonly NodeInputSelector[], attributeNames?: readonly string[]): NodeInputSelection;
|
|
9
35
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type NodeInput, type NodeInputSelection } from '../input/NodeInput';
|
|
2
|
+
import { ParsedEitherNode } from '../parsed/ParsedEitherNode';
|
|
3
|
+
import { ParsedNode } from '../parsed/ParsedNode';
|
|
4
|
+
import type { ParsedChild } from '../parsed/ParsedNodeTypes';
|
|
5
|
+
import { Node, type NodeGenerics, type NodeOptions, type ParseTreeOptions } from './Node';
|
|
6
|
+
export interface EitherNodeOptions extends NodeOptions {
|
|
7
|
+
alternatives: readonly [Node<any>, Node<any>, ...Node<any>[]];
|
|
8
|
+
}
|
|
9
|
+
interface EitherParseTreeOptions extends ParseTreeOptions {
|
|
10
|
+
alternativeInputs?: NodeInput[];
|
|
11
|
+
}
|
|
12
|
+
/** Select by input shape before parsing, so unsuccessful branches have no side effects. */
|
|
13
|
+
export declare class EitherNode<Value = unknown> extends Node<NodeGenerics<{
|
|
14
|
+
value?: ParsedChild;
|
|
15
|
+
}, ParsedEitherNode<Value>, Value | undefined>> {
|
|
16
|
+
constructor(options: EitherNodeOptions);
|
|
17
|
+
protected createParsedNode(options: ParseTreeOptions): ParsedEitherNode<Value>;
|
|
18
|
+
parse(options: EitherParseTreeOptions): ParsedEitherNode<Value> | null;
|
|
19
|
+
protected parseChildren({ parsed, options }: {
|
|
20
|
+
parsed: ParsedEitherNode<Value>;
|
|
21
|
+
options: EitherParseTreeOptions;
|
|
22
|
+
}): void;
|
|
23
|
+
parseChildrenInto({ parent, inputs, options, selection }: {
|
|
24
|
+
parent: ParsedNode;
|
|
25
|
+
inputs: NodeInput[];
|
|
26
|
+
options: ParseTreeOptions;
|
|
27
|
+
selection?: NodeInputSelection;
|
|
28
|
+
}): void;
|
|
29
|
+
private matches;
|
|
30
|
+
private parseSelection;
|
|
31
|
+
}
|
|
32
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ParseEvent } from '../ParseEvent';
|
|
2
|
-
import type { NodeInput } from '../input/NodeInput';
|
|
2
|
+
import type { NodeInput, NodeInputSelector, NodeInputSelection } from '../input/NodeInput';
|
|
3
3
|
import { Attribute } from '../attributes/Attribute';
|
|
4
4
|
import { ContentTextAttribute } from '../attributes/ContentTextAttribute';
|
|
5
5
|
import { CommonEntity, CommonEntityGenerics, CommonEntityOptions } from '../entities/CommonEntity';
|
|
@@ -106,10 +106,12 @@ export declare class Node<G extends NodeGenerics<any> = NodeGenerics<any>> exten
|
|
|
106
106
|
parsed: ParsedNode<G['Shape'], G['Value']>;
|
|
107
107
|
options: ParseTreeOptions;
|
|
108
108
|
}): void;
|
|
109
|
-
|
|
109
|
+
get inputSelectors(): readonly NodeInputSelector[];
|
|
110
|
+
parseChildrenInto({ parent, inputs, options, selection }: {
|
|
110
111
|
parent: ParsedNode;
|
|
111
112
|
inputs: NodeInput[];
|
|
112
113
|
options: ParseTreeOptions;
|
|
114
|
+
selection?: NodeInputSelection;
|
|
113
115
|
}): void;
|
|
114
116
|
parseInput({ parent, options, input, key }: {
|
|
115
117
|
parent: ParsedNode;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ParsedNode } from '../parsed/ParsedNode';
|
|
2
2
|
import { ParsedNodeShape } from '../parsed/ParsedNodeTypes';
|
|
3
3
|
import { ParseTreeOptions, Node, NodeGenerics, NodeOptions } from './Node';
|
|
4
|
-
import type { NodeInput } from '../input/NodeInput';
|
|
4
|
+
import type { NodeInput, NodeInputSelector, NodeInputSelection } from '../input/NodeInput';
|
|
5
5
|
export interface NodeAlternativesOptions extends Omit<NodeOptions, 'name'> {
|
|
6
6
|
key: string;
|
|
7
7
|
alternatives: Node<any>[];
|
|
@@ -10,12 +10,15 @@ export interface NodeAlternativesOptions extends Omit<NodeOptions, 'name'> {
|
|
|
10
10
|
export declare class NodeAlternatives<Shape extends ParsedNodeShape = ParsedNodeShape> extends Node<NodeGenerics<Shape>> {
|
|
11
11
|
private readonly exclusiveValue;
|
|
12
12
|
private readonly alternatives;
|
|
13
|
+
private readonly selectors;
|
|
13
14
|
constructor(options: NodeAlternativesOptions);
|
|
14
15
|
get exclusive(): boolean;
|
|
15
|
-
|
|
16
|
+
get inputSelectors(): readonly NodeInputSelector[];
|
|
17
|
+
parseChildrenInto({ parent, inputs, options, selection }: {
|
|
16
18
|
parent: ParsedNode;
|
|
17
19
|
inputs: NodeInput[];
|
|
18
20
|
options: ParseTreeOptions;
|
|
21
|
+
selection?: NodeInputSelection;
|
|
19
22
|
}): void;
|
|
20
23
|
private parseAlternativeInput;
|
|
21
24
|
private getMatchingAlternatives;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ParsedNode } from '../parsed/ParsedNode';
|
|
2
|
+
import { ParsedRecordNode } from '../parsed/ParsedRecordNode';
|
|
3
|
+
import { Node, type NodeGenerics, type NodeOptions, type ParseTreeOptions } from './Node';
|
|
4
|
+
type RecordShape<Entry extends Node<any>> = Record<string, ReturnType<Entry['parseTree']>>;
|
|
5
|
+
/** Parse named entries using one shared definition, retaining each entry's source. */
|
|
6
|
+
export declare class RecordNode<Entry extends Node<any>, Value = Entry extends Node<infer G> ? G['Value'] : never> extends Node<NodeGenerics<RecordShape<Entry>, ParsedRecordNode<ReturnType<Entry['parseTree']>, Value>, Record<string, Value>>> {
|
|
7
|
+
constructor(options: NodeOptions & {
|
|
8
|
+
entry: Entry;
|
|
9
|
+
});
|
|
10
|
+
protected createParsedNode(options: ParseTreeOptions): ParsedRecordNode<ReturnType<Entry['parseTree']>, Value>;
|
|
11
|
+
protected parseChildren({ parsed, options }: {
|
|
12
|
+
parsed: ParsedNode<RecordShape<Entry>, Record<string, Value>>;
|
|
13
|
+
options: ParseTreeOptions;
|
|
14
|
+
}): void;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ParsedNodeValuesLike } from '../values/ParsedNodeValues';
|
|
2
2
|
import { ParsedExpressionValue } from './ParsedNodeTypes';
|
|
3
3
|
import { TreeNode } from '@journeyapps/common-tree';
|
|
4
|
+
import type { SourceReference } from '../source/SourceReference';
|
|
4
5
|
import { Node } from '../nodes/Node';
|
|
5
6
|
import { AbstractValueProvider } from '../values/AbstractValueProvider';
|
|
6
7
|
import { ParsedDiagnostic } from './ParsedDiagnostic';
|
|
@@ -8,10 +9,14 @@ import { ParsedNode } from './ParsedNode';
|
|
|
8
9
|
export interface ParsedArrayNodeOptions {
|
|
9
10
|
definition: Node<any>;
|
|
10
11
|
key: string;
|
|
12
|
+
inputPresent?: boolean;
|
|
13
|
+
source?: SourceReference;
|
|
11
14
|
}
|
|
12
15
|
export type ParsedArrayNodeChild = ParsedNode<any, any> | ParsedArrayNode<any>;
|
|
13
16
|
export declare class ParsedArrayNode<Child extends ParsedArrayNodeChild = ParsedNode<any, any>> extends TreeNode {
|
|
14
17
|
readonly definition: Node<any>;
|
|
18
|
+
readonly inputPresent?: boolean;
|
|
19
|
+
readonly source?: SourceReference;
|
|
15
20
|
private readonly diagnostics;
|
|
16
21
|
constructor(options: ParsedArrayNodeOptions);
|
|
17
22
|
nodes(): Child[];
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ParsedNode } from './ParsedNode';
|
|
2
|
+
import type { ParsedChild } from './ParsedNodeTypes';
|
|
3
|
+
import { type ParsedNodeValuesLike } from '../values/ParsedNodeValues';
|
|
4
|
+
/** Preserve the selected branch's value without adding an object to the output. */
|
|
5
|
+
export declare class ParsedEitherNode<Value> extends ParsedNode<{
|
|
6
|
+
value?: ParsedChild;
|
|
7
|
+
}, Value | undefined> {
|
|
8
|
+
valueTree(): ParsedNodeValuesLike<Value | undefined>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ParsedNode } from './ParsedNode';
|
|
2
|
+
import { type ParsedNodeValuesLike } from '../values/ParsedNodeValues';
|
|
3
|
+
/** Only document keys become entries; the entry definition does not imply a default key. */
|
|
4
|
+
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
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BooleanAttribute.js","sourceRoot":"","sources":["../../src/attributes/BooleanAttribute.ts"],"names":[],"mappings":";;;AAAA,mDAAgD;AAChD,2CAA6E;AAC7E,wEASyC;AACzC,wEAA8D;
|
|
1
|
+
{"version":3,"file":"BooleanAttribute.js","sourceRoot":"","sources":["../../src/attributes/BooleanAttribute.ts"],"names":[],"mappings":";;;AAAA,mDAAgD;AAChD,2CAA6E;AAC7E,wEASyC;AACzC,wEAA8D;AAY9D;;GAEG;AACH,sBAEE,SAAQ,qBAA4C;IAGpD,MAAM,CAAC,YAAY,CAAC,IAAe;QACjC,OAAO,IAAI,CAAC,IAAI,KAAK,gBAAgB,CAAC,IAAI,CAAC;IAC7C,CAAC;IAED,YAAY,OAAgB;;QAC1B,MAAM,SAAS,SAAG,OAAO,CAAC,SAAS,mCAAI,IAAI,6BAAa,EAAE,CAAC;QAC3D,KAAK,CAAC,gBAAgB,CAAC,IAAI,kCACtB,OAAO,KACV,SAAS,EACT,MAAM,QACJ,OAAO,CAAC,MAAM,mCACd,IAAI,mCAAc,CAA4B;gBAC5C,IAAI,6CAAwB,EAAE;gBAC9B,IAAI,8CAAyB,EAAE;gBAC/B,IAAI,8CAAyB,EAAE;gBAC/B,IAAI,6CAAwB,OAAC,OAAO,CAAC,SAAS,mCAAI,gCAAW,CAAC;aAC/D,CAAC,EACJ,YAAY,QAAE,OAAO,CAAC,YAAY,mCAAI,IAAI,IAC1C,CAAC;IACL,CAAC;IAED,SAAS;QACP,uCACK,KAAK,CAAC,SAAS,EAAE,KACpB,IAAI,EAAE,SAAS,IACf;IACJ,CAAC;CACF;;AA7BQ,qBAAI,GAAG,mBAAmB,CAAC","sourcesContent":["import { ConditionType } from './ConditionType';\nimport { Attribute, AttributeOptions, AttributeGenerics } from './Attribute';\nimport {\n EvaluatedExpression,\n ConstantExpression,\n ShorthandExpression,\n CombinedParser,\n FunctionExpressionParser,\n EvaluatedExpressionParser,\n ConstantExpressionParser,\n ShorthandExpressionParser\n} from '@ja-platform/parser-expressions';\nimport { booleanType } from '@ja-platform/parser-type-system';\n\nexport type CombinedBooleanExpression = EvaluatedExpression | ConstantExpression<boolean> | ShorthandExpression;\n\nexport interface BooleanAttributeGenerics<\n Options extends AttributeOptions<boolean, boolean> = AttributeOptions<boolean, boolean>\n> extends AttributeGenerics {\n Options: Options;\n Value: CombinedBooleanExpression | null;\n NormalizedValue: boolean;\n}\n\n/**\n * For dealing with boolean attribute types such as `show-if` and `hide-if`\n */\nexport class BooleanAttribute<\n Options extends AttributeOptions<boolean, boolean> = AttributeOptions<boolean, boolean>\n> extends Attribute<BooleanAttributeGenerics<Options>> {\n static TYPE = 'boolean-attribute';\n\n static isInstanceOf(attr: Attribute): attr is BooleanAttribute {\n return attr.type === BooleanAttribute.TYPE;\n }\n\n constructor(options: Options) {\n const valueType = options.valueType ?? new ConditionType();\n super(BooleanAttribute.TYPE, {\n ...options,\n valueType,\n syntax:\n options.syntax ??\n new CombinedParser<CombinedBooleanExpression>([\n new FunctionExpressionParser(),\n new EvaluatedExpressionParser(),\n new ShorthandExpressionParser(),\n new ConstantExpressionParser(options.valueType ?? booleanType)\n ]),\n configurable: options.configurable ?? true\n });\n }\n\n serialize(): any {\n return {\n ...super.serialize(),\n type: 'boolean'\n };\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ListAttribute.js","sourceRoot":"","sources":["../../src/attributes/ListAttribute.ts"],"names":[],"mappings":";;;AACA,2CAA6E;
|
|
1
|
+
{"version":3,"file":"ListAttribute.js","sourceRoot":"","sources":["../../src/attributes/ListAttribute.ts"],"names":[],"mappings":";;;AACA,2CAA6E;AAgB7E,mBAAwF,SAAQ,qBAE/F;IAGC,YAAY,OAAgB;;QAC1B,KAAK,CAAC,aAAa,CAAC,IAAI,kCACnB,OAAO,KACV,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE,EAC9B,YAAY,QAAE,OAAO,CAAC,YAAY,mCAAI,IAAI,IAC1C,CAAC;QACH,IAAI,CAAC,SAAS,SAAG,OAAO,CAAC,SAAS,mCAAI,GAAG,CAAC;IAC5C,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,IAAe;QACjC,OAAO,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,IAAI,CAAC;IAC1C,CAAC;IAED,MAAM,CAAC,MAAM,CAAC,KAAU,EAAE,SAAS,GAAG,GAAG;QACvC,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,OAAO,IAAI,CAAC;QACd,CAAC;aAAM,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAChC,OAAO,KAAK,CAAC;QACf,CAAC;aAAM,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,YAAY,MAAM,EAAE,CAAC;YAChE,OAAO,GAAG,KAAK,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACrC,CAAC;aAAM,CAAC;YACN,6DAA6D;YAC7D,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,SAAS;QACP,uCACK,KAAK,CAAC,SAAS,EAAE,KACpB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,IAC7B;IACJ,CAAC;CACF;;AAlCQ,kBAAI,GAAG,gBAAgB,CAAC","sourcesContent":["import type { EvaluatedExpression, ConstantExpression } from '@ja-platform/parser-expressions';\nimport { Attribute, AttributeGenerics, AttributeOptions } from './Attribute';\n\nexport type CombinedListExpression = EvaluatedExpression | ConstantExpression;\n\nexport interface ListAttributeOptions extends AttributeOptions<string[]> {\n options: string[];\n delimiter?: string;\n}\n\nexport interface ListAttributeGenerics<\n Options extends ListAttributeOptions = ListAttributeOptions\n> extends AttributeGenerics {\n Value: CombinedListExpression | null;\n Options: Options;\n}\n\nexport class ListAttribute<Options extends ListAttributeOptions = ListAttributeOptions> extends Attribute<\n ListAttributeGenerics<Options>\n> {\n static TYPE = 'list-attribute';\n delimiter: string;\n constructor(options: Options) {\n super(ListAttribute.TYPE, {\n ...options,\n options: options.options || [],\n configurable: options.configurable ?? true\n });\n this.delimiter = options.delimiter ?? ',';\n }\n\n static isInstanceOf(attr: Attribute): attr is ListAttribute {\n return attr.type === ListAttribute.TYPE;\n }\n\n static toList(value: any, delimiter = ','): any[] {\n if (value == null) {\n return null;\n } else if (Array.isArray(value)) {\n return value;\n } else if (typeof value === 'string' || value instanceof String) {\n return `${value}`.split(delimiter);\n } else {\n // Value might be an object, which will be resolved elsewhere\n return value;\n }\n }\n serialize(): any {\n return {\n ...super.serialize(),\n type: 'list',\n options: this.options.options\n };\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NumberAttribute.js","sourceRoot":"","sources":["../../src/attributes/NumberAttribute.ts"],"names":[],"mappings":";;;AACA,wEAA0F;AAC1F,wEAA6D;AAC7D,2CAA6E;
|
|
1
|
+
{"version":3,"file":"NumberAttribute.js","sourceRoot":"","sources":["../../src/attributes/NumberAttribute.ts"],"names":[],"mappings":";;;AACA,wEAA0F;AAC1F,wEAA6D;AAC7D,2CAA6E;AAsB7E,qBAA8F,SAAQ,qBAErG;IAGC,MAAM,CAAC,YAAY,CAAC,IAAe;QACjC,OAAO,IAAI,CAAC,IAAI,KAAK,eAAe,CAAC,IAAI,CAAC;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C;oCACb,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;oCAC3B,OAAO,EAAE,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,eAAe,IAAI,KAAK,UAAU,CAAC,GAAG,EAAE,oCAAoC,GAAG,KAAK,GAAG,IAAI;iCAC9H,CAAC,CAAC;4BACL,CAAC;wBACH,CAAC;oBACH,CAAC;iBACF,CAAC,CAAC;YACL,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IACD,SAAS;QACP,uCACK,KAAK,CAAC,SAAS,EAAE,KACpB,IAAI,EAAE,QAAQ,IACd;IACJ,CAAC;CACF;;AApDQ,oBAAI,GAAG,kBAAkB,CAAC","sourcesContent":["import { AttributeParseEvent } from '../AttributeParseEvent';\nimport { EvaluatedExpression, ConstantExpression } from '@ja-platform/parser-expressions';\nimport { numberType } from '@ja-platform/parser-type-system';\nimport { Attribute, AttributeGenerics, AttributeOptions } from './Attribute';\nimport type { Node } from '../nodes/Node';\n\nexport type CombinedNumberExpression = EvaluatedExpression | ConstantExpression<number>;\n\nexport interface NumberAttributeRange {\n min?: number;\n max?: number;\n}\n\nexport interface NumberAttributeOptions extends AttributeOptions<number, number> {\n range?: NumberAttributeRange;\n}\n\nexport interface NumberAttributeGenerics<\n Options extends NumberAttributeOptions = NumberAttributeOptions\n> extends AttributeGenerics {\n Options: Options;\n Value: CombinedNumberExpression | null;\n NormalizedValue: number;\n}\n\nexport class NumberAttribute<Options extends NumberAttributeOptions = NumberAttributeOptions> extends Attribute<\n NumberAttributeGenerics<Options>\n> {\n static TYPE = 'number-attribute';\n\n static isInstanceOf(attr: Attribute): attr is NumberAttribute {\n return attr.type === NumberAttribute.TYPE;\n }\n\n constructor(options: Options) {\n super(NumberAttribute.TYPE, {\n ...options,\n valueType: options.valueType ?? numberType,\n configurable: options.configurable ?? true\n });\n }\n\n protected getParsedValue(event: AttributeParseEvent): NumberAttributeGenerics['Value'] {\n const value = event.input.value;\n if (value.trim() === '') {\n return null;\n }\n return super.getParsedValue(event);\n }\n\n setParent(parent: Node<any>) {\n super.setParent(parent);\n parent.registerListener({\n postParse: ({ parsed }) => {\n parsed.registerListener({\n postValidation: ({ context }) => {\n const expression = parsed.attrExpression(this.options.key);\n const { name, range } = this.options;\n if (expression instanceof ConstantExpression && range) {\n const value = expression.value();\n const min = range.min ?? Number.NEGATIVE_INFINITY;\n const max = range.max ?? Number.POSITIVE_INFINITY;\n if (value < min || value > max) {\n context.report({\n token: expression.tokens[0],\n message: `${parsed.definition.name}: Attribute ${name}=\"${expression.raw()}\" is outside of allowable range [${min}, ${max}].`\n });\n }\n }\n }\n });\n }\n });\n }\n serialize(): any {\n return {\n ...super.serialize(),\n type: 'number'\n };\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SetAttribute.js","sourceRoot":"","sources":["../../src/attributes/SetAttribute.ts"],"names":[],"mappings":";;;AACA,2CAA6E;
|
|
1
|
+
{"version":3,"file":"SetAttribute.js","sourceRoot":"","sources":["../../src/attributes/SetAttribute.ts"],"names":[],"mappings":";;;AACA,2CAA6E;AAe7E,kBAAqF,SAAQ,qBAE5F;IAEC,YAAY,OAAgB;;QAC1B,KAAK,CAAC,YAAY,CAAC,IAAI,kCAClB,OAAO,KACV,YAAY,QAAE,OAAO,CAAC,YAAY,mCAAI,IAAI,EAC1C,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE,IAC9B,CAAC;IACL,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,IAAe;QACjC,OAAO,IAAI,CAAC,IAAI,KAAK,YAAY,CAAC,IAAI,CAAC;IACzC,CAAC;IAED,SAAS;QACP,uCACK,KAAK,CAAC,SAAS,EAAE,KACpB,IAAI,EAAE,KAAK,EACX,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,IAC7B;IACJ,CAAC;CACF;;AApBQ,iBAAI,GAAG,eAAe,CAAC","sourcesContent":["import type { EvaluatedExpression, ConstantExpression } from '@ja-platform/parser-expressions';\nimport { Attribute, AttributeGenerics, AttributeOptions } from './Attribute';\n\nexport type CombinedSetExpression = EvaluatedExpression | ConstantExpression;\n\nexport interface SetAttributeOptions extends AttributeOptions<string> {\n options: string[];\n}\n\nexport interface SetAttributeGenerics<\n Options extends SetAttributeOptions = SetAttributeOptions\n> extends AttributeGenerics {\n Value: CombinedSetExpression | null;\n Options: Options;\n}\n\nexport class SetAttribute<Options extends SetAttributeOptions = SetAttributeOptions> extends Attribute<\n SetAttributeGenerics<Options>\n> {\n static TYPE = 'set-attribute';\n constructor(options: Options) {\n super(SetAttribute.TYPE, {\n ...options,\n configurable: options.configurable ?? true,\n options: options.options || []\n });\n }\n\n static isInstanceOf(attr: Attribute): attr is SetAttribute {\n return attr.type === SetAttribute.TYPE;\n }\n\n serialize(): any {\n return {\n ...super.serialize(),\n type: 'set',\n options: this.options.options\n };\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextAttribute.js","sourceRoot":"","sources":["../../src/attributes/TextAttribute.ts"],"names":[],"mappings":";;;AAAA,4DAAiE;AAEjE,2CAA6E;AAC7E,wEAOyC;AACzC,wEAA2D;AAY3D,
|
|
1
|
+
{"version":3,"file":"TextAttribute.js","sourceRoot":"","sources":["../../src/attributes/TextAttribute.ts"],"names":[],"mappings":";;;AAAA,4DAAiE;AAEjE,2CAA6E;AAC7E,wEAOyC;AACzC,wEAA2D;AAY3D,mBAGE,SAAQ,qBAAmC;IAG3C,YAAY,OAAgB;;QAC1B,KAAK,CAAC,aAAa,CAAC,IAAI,kCACnB,OAAO,KACV,SAAS,QAAE,OAAO,CAAC,SAAS,mCAAI,6BAAQ,EACxC,MAAM,QACJ,OAAO,CAAC,MAAM,mCACd,IAAI,mCAAc,CAAyB;gBACzC,IAAI,6CAAwB,EAAE;gBAC9B,IAAI,8CAAyB,EAAE;gBAC/B,IAAI,iDAA4B,EAAE;aACnC,CAAC,EACJ,YAAY,QAAE,OAAO,CAAC,YAAY,mCAAI,IAAI,IAC1C,CAAC;IACL,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,IAAe;QACjC,OAAO,IAAI,CAAC,IAAI,KAAK,aAAa,CAAC,IAAI,CAAC;IAC1C,CAAC;IAES,cAAc,CAAC,KAA0B;QACjD,MAAM,UAAU,GAAG,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;QAC/C,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QACtC,OAAO,UAAU,CAAC;IACpB,CAAC;IAES,aAAa,CAAC,KAA0B,EAAE,UAAkC;;;QACpF,MAAA,MAAA,KAAK,CAAC,OAAO,0CAAE,kBAAkB,mDAAG;YAClC,SAAS,EAAE,IAAI;YACf,UAAU;YACV,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM;YAC1B,QAAQ,QAAE,KAAK,CAAC,KAAK,CAAC,QAAQ,mCAAI,uCAAsB,CAAC,SAAS;SACnE,CAAC,CAAC;IACL,CAAC;IAED,SAAS;QACP,uCACK,KAAK,CAAC,SAAS,EAAE,KACpB,IAAI,EAAE,MAAM,IACZ;IACJ,CAAC;CACF;;AA1CQ,kBAAI,GAAG,gBAAgB,CAAC","sourcesContent":["import { AttributeInputLocation } from '../input/AttributeInput';\nimport { AttributeParseEvent } from '../AttributeParseEvent';\nimport { Attribute, AttributeGenerics, AttributeOptions } from './Attribute';\nimport {\n FormatStringExpression,\n CombinedParser,\n FunctionExpressionParser,\n EvaluatedExpressionParser,\n FormatStringExpressionParser,\n EvaluatedExpression\n} from '@ja-platform/parser-expressions';\nimport { textType } from '@ja-platform/parser-type-system';\n\nexport type CombinedTextExpression = FormatStringExpression | EvaluatedExpression;\n\nexport type TextAttributeOptions<Value = string> = AttributeOptions<Value, Value>;\n\nexport interface TextAttributeGenerics<Value = string> extends AttributeGenerics {\n Value: CombinedTextExpression | null;\n Options: TextAttributeOptions<Value>;\n NormalizedValue: Value;\n}\n\nexport class TextAttribute<\n T extends TextAttributeGenerics<unknown> = TextAttributeGenerics,\n Options extends T['Options'] = T['Options']\n> extends Attribute<T & { Options: Options }> {\n static TYPE = 'text-attribute';\n\n constructor(options: Options) {\n super(TextAttribute.TYPE, {\n ...options,\n valueType: options.valueType ?? textType,\n syntax:\n options.syntax ??\n new CombinedParser<CombinedTextExpression>([\n new FunctionExpressionParser(),\n new EvaluatedExpressionParser(),\n new FormatStringExpressionParser()\n ]),\n configurable: options.configurable ?? true\n });\n }\n\n static isInstanceOf(attr: Attribute): attr is TextAttribute<TextAttributeGenerics<unknown>> {\n return attr.type === TextAttribute.TYPE;\n }\n\n protected getParsedValue(event: AttributeParseEvent): CombinedTextExpression | null {\n const expression = super.getParsedValue(event);\n this.validateInput(event, expression);\n return expression;\n }\n\n protected validateInput(event: AttributeParseEvent, expression: CombinedTextExpression): void {\n event.context?.validateExpression?.({\n attribute: this,\n expression,\n source: event.input.source,\n location: event.input.location ?? AttributeInputLocation.ATTRIBUTE\n });\n }\n\n serialize(): any {\n return {\n ...super.serialize(),\n type: 'text'\n };\n }\n}\n"]}
|
package/dist/index.js
CHANGED
|
@@ -35,6 +35,10 @@ __exportStar(require("./entities/CommonEntity"), exports);
|
|
|
35
35
|
__exportStar(require("./nodes/Node"), exports);
|
|
36
36
|
__exportStar(require("./nodes/ContentNode"), exports);
|
|
37
37
|
__exportStar(require("./nodes/NodeAlternatives"), exports);
|
|
38
|
+
__exportStar(require("./nodes/RecordNode"), exports);
|
|
39
|
+
__exportStar(require("./nodes/EitherNode"), exports);
|
|
40
|
+
__exportStar(require("./parsed/ParsedEitherNode"), exports);
|
|
41
|
+
__exportStar(require("./parsed/ParsedRecordNode"), exports);
|
|
38
42
|
__exportStar(require("./parsed/ParsedArrayNode"), exports);
|
|
39
43
|
__exportStar(require("./parsed/ParsedAttribute"), exports);
|
|
40
44
|
__exportStar(require("./parsed/ParsedContentNode"), exports);
|
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,oEAAkD;AAClD,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,2DAAyC;AACzC,2DAAyC;AACzC,6DAA2C;AAC3C,4DAA0C;AAC1C,sDAAoC;AACpC,2DAAyC;AACzC,iEAA+C;AAC/C,2EAAyD;AACzD,sEAAoD;AACpD,4DAA0C;AAC1C,+DAA6C;AAC7C,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/ContentTextAttribute';\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 './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/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,oEAAkD;AAClD,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,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/ContentTextAttribute';\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/ParsedValue';\nexport * from './utils/types/valueOf';\n\nexport * from './source/SourceReference';\nexport * from './input/AttributeInput';\nexport * from './input/NodeInput';\nexport * from './input/AttributeParseContext';\n"]}
|
package/dist/input/NodeInput.js
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.NodeInputKind = void 0;
|
|
4
|
+
var NodeInputKind;
|
|
5
|
+
(function (NodeInputKind) {
|
|
6
|
+
NodeInputKind["STRING"] = "string";
|
|
7
|
+
NodeInputKind["NUMBER"] = "number";
|
|
8
|
+
NodeInputKind["BOOLEAN"] = "boolean";
|
|
9
|
+
NodeInputKind["NULL"] = "null";
|
|
10
|
+
NodeInputKind["OBJECT"] = "object";
|
|
11
|
+
NodeInputKind["ARRAY"] = "array";
|
|
12
|
+
NodeInputKind["ELEMENT"] = "element";
|
|
13
|
+
})(NodeInputKind || (exports.NodeInputKind = NodeInputKind = {}));
|
|
3
14
|
//# sourceMappingURL=NodeInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NodeInput.js","sourceRoot":"","sources":["../../src/input/NodeInput.ts"],"names":[],"mappings":"","sourcesContent":["import type { AttributeInput } from './AttributeInput';\nimport type { SourceReference } from '../source/SourceReference';\n\nexport interface NodeInput {\n readonly name: string;\n readonly source?: SourceReference;\n attribute(name: string): AttributeInput | undefined;\n content(): AttributeInput | undefined;\n children(): Iterable<NodeInput>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"NodeInput.js","sourceRoot":"","sources":["../../src/input/NodeInput.ts"],"names":[],"mappings":";;;AAiBA,IAAY,aAQX;AARD,WAAY,aAAa;IACvB,kCAAiB,CAAA;IACjB,kCAAiB,CAAA;IACjB,oCAAmB,CAAA;IACnB,8BAAa,CAAA;IACb,kCAAiB,CAAA;IACjB,gCAAe,CAAA;IACf,oCAAmB,CAAA;AACrB,CAAC,EARW,aAAa,aAAb,aAAa,GAAb,aAAa,QAQxB","sourcesContent":["import type { AttributeInput } from './AttributeInput';\nimport type { ParsedDiagnostic } from '../parsed/ParsedDiagnostic';\nimport type { SourceReference } from '../source/SourceReference';\n\nexport interface NodeInputSelector {\n name: string;\n key: string;\n isMultiple?: boolean;\n}\n\nexport interface NodeInputSelection {\n inputs: NodeInput[];\n present: boolean;\n source?: SourceReference;\n diagnostics: ParsedDiagnostic[];\n}\n\nexport enum NodeInputKind {\n STRING = 'string',\n NUMBER = 'number',\n BOOLEAN = 'boolean',\n NULL = 'null',\n OBJECT = 'object',\n ARRAY = 'array',\n ELEMENT = 'element'\n}\n\nexport interface NodeInput {\n readonly kind: NodeInputKind;\n readonly name: string;\n readonly source?: SourceReference;\n attribute(name: string): AttributeInput | undefined;\n content(): AttributeInput | undefined;\n children(): Iterable<NodeInput>;\n /** Select named entries, reporting inputs that cannot represent a record. */\n recordEntries(): NodeInputSelection;\n /** Select declared children in document order, retaining explicit empty collections. */\n selectChildren(selectors: readonly NodeInputSelector[], attributeNames?: readonly string[]): NodeInputSelection;\n}\n"]}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.EitherNode = void 0;
|
|
15
|
+
const NodeInput_1 = require("../input/NodeInput");
|
|
16
|
+
const ParsedArrayNode_1 = require("../parsed/ParsedArrayNode");
|
|
17
|
+
const ParsedEitherNode_1 = require("../parsed/ParsedEitherNode");
|
|
18
|
+
const ContentNode_1 = require("./ContentNode");
|
|
19
|
+
const Node_1 = require("./Node");
|
|
20
|
+
/** Select by input shape before parsing, so unsuccessful branches have no side effects. */
|
|
21
|
+
class EitherNode extends Node_1.Node {
|
|
22
|
+
constructor(options) {
|
|
23
|
+
super(options);
|
|
24
|
+
options.alternatives.forEach((alternative) => this.addNode(alternative));
|
|
25
|
+
}
|
|
26
|
+
createParsedNode(options) {
|
|
27
|
+
return new ParsedEitherNode_1.ParsedEitherNode(Object.assign({ definition: this }, options));
|
|
28
|
+
}
|
|
29
|
+
parse(options) {
|
|
30
|
+
return super.parse(options);
|
|
31
|
+
}
|
|
32
|
+
parseChildren({ parsed, options }) {
|
|
33
|
+
this.fireListeners((listener) => { var _a; return (_a = listener.preChildrenParse) === null || _a === void 0 ? void 0 : _a.call(listener, Object.assign(Object.assign({}, options), { parsedNode: parsed })); });
|
|
34
|
+
if (!options.input)
|
|
35
|
+
return;
|
|
36
|
+
const { alternativeInputs } = options, branchOptions = __rest(options, ["alternativeInputs"]);
|
|
37
|
+
this.parseSelection(parsed, branchOptions, alternativeInputs !== null && alternativeInputs !== void 0 ? alternativeInputs : [options.input]);
|
|
38
|
+
}
|
|
39
|
+
parseChildrenInto({ parent, inputs, options, selection }) {
|
|
40
|
+
const matching = inputs.filter((input) => input.name === this.name);
|
|
41
|
+
if (matching.length <= 1) {
|
|
42
|
+
super.parseChildrenInto({ parent, inputs, options, selection });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const parsed = this.parse(Object.assign(Object.assign({}, options), { input: matching[0], alternativeInputs: matching, parentNode: parent, parentEvent: options, key: this.options.key }));
|
|
46
|
+
if (parsed)
|
|
47
|
+
parent.setChild(this.options.key, parsed);
|
|
48
|
+
}
|
|
49
|
+
matches(definition, input, repeated) {
|
|
50
|
+
var _a;
|
|
51
|
+
if (definition.options.isMultiple)
|
|
52
|
+
return repeated || input.kind === NodeInput_1.NodeInputKind.ARRAY;
|
|
53
|
+
if (repeated)
|
|
54
|
+
return false;
|
|
55
|
+
if (definition instanceof EitherNode) {
|
|
56
|
+
return definition.nodes.some((branch) => definition.matches(branch, input, false));
|
|
57
|
+
}
|
|
58
|
+
if (input.kind === NodeInput_1.NodeInputKind.ELEMENT)
|
|
59
|
+
return true;
|
|
60
|
+
if (definition instanceof ContentNode_1.ContentNode) {
|
|
61
|
+
return definition.options.valueType.is((_a = input.content()) === null || _a === void 0 ? void 0 : _a.value);
|
|
62
|
+
}
|
|
63
|
+
return input.kind === NodeInput_1.NodeInputKind.OBJECT;
|
|
64
|
+
}
|
|
65
|
+
parseSelection(parsed, options, inputs) {
|
|
66
|
+
const input = inputs[0];
|
|
67
|
+
const matches = this.nodes.filter((definition) => this.matches(definition, input, inputs.length > 1));
|
|
68
|
+
if (matches.length !== 1) {
|
|
69
|
+
parsed.pushError({
|
|
70
|
+
source: input.source,
|
|
71
|
+
message: matches.length === 0
|
|
72
|
+
? `No alternative matches '${input.name}' (${input.kind})`
|
|
73
|
+
: `Multiple alternatives match '${input.name}' (${input.kind})`
|
|
74
|
+
});
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const definition = matches[0];
|
|
78
|
+
if (definition.options.isMultiple) {
|
|
79
|
+
const entries = input.kind === NodeInput_1.NodeInputKind.ARRAY ? Array.from(input.children()) : inputs;
|
|
80
|
+
const array = new ParsedArrayNode_1.ParsedArrayNode({ definition, key: 'value', inputPresent: true, source: input.source });
|
|
81
|
+
entries.forEach((entry, index) => {
|
|
82
|
+
const child = definition.parseInput({ parent: parsed, options, input: entry, key: String(index) });
|
|
83
|
+
if (child)
|
|
84
|
+
array.addChild(child);
|
|
85
|
+
});
|
|
86
|
+
parsed.setChild('value', array);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const child = definition.parseInput({ parent: parsed, options, input, key: 'value' });
|
|
90
|
+
if (child)
|
|
91
|
+
parsed.setChild('value', child);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
exports.EitherNode = EitherNode;
|
|
95
|
+
//# sourceMappingURL=EitherNode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EitherNode.js","sourceRoot":"","sources":["../../src/nodes/EitherNode.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,kDAA4F;AAC5F,+DAA4D;AAC5D,iEAA8D;AAG9D,+CAA4C;AAC5C,iCAA0F;AAU1F,2FAA2F;AAC3F,gBAAyC,SAAQ,WAEhD;IACC,YAAY,OAA0B;QACpC,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IAC3E,CAAC;IAES,gBAAgB,CAAC,OAAyB;QAClD,OAAO,IAAI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E,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;QACtF,IAAI,KAAK;YAAE,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAC7C,CAAC;CACF","sourcesContent":["import { NodeInputKind, type NodeInput, type NodeInputSelection } from '../input/NodeInput';\nimport { ParsedArrayNode } from '../parsed/ParsedArrayNode';\nimport { ParsedEitherNode } from '../parsed/ParsedEitherNode';\nimport { ParsedNode } from '../parsed/ParsedNode';\nimport type { ParsedChild } from '../parsed/ParsedNodeTypes';\nimport { ContentNode } from './ContentNode';\nimport { Node, type NodeGenerics, type NodeOptions, type ParseTreeOptions } from './Node';\n\nexport interface EitherNodeOptions extends NodeOptions {\n alternatives: readonly [Node<any>, Node<any>, ...Node<any>[]];\n}\n\ninterface EitherParseTreeOptions extends ParseTreeOptions {\n alternativeInputs?: NodeInput[];\n}\n\n/** Select by input shape before parsing, so unsuccessful branches have no side effects. */\nexport class EitherNode<Value = unknown> extends Node<\n NodeGenerics<{ value?: ParsedChild }, ParsedEitherNode<Value>, Value | undefined>\n> {\n constructor(options: EitherNodeOptions) {\n super(options);\n options.alternatives.forEach((alternative) => this.addNode(alternative));\n }\n\n protected createParsedNode(options: ParseTreeOptions): ParsedEitherNode<Value> {\n return new ParsedEitherNode({ definition: this, ...options });\n }\n\n parse(options: EitherParseTreeOptions): ParsedEitherNode<Value> | null {\n return super.parse(options);\n }\n\n protected parseChildren({\n parsed,\n options\n }: {\n parsed: ParsedEitherNode<Value>;\n options: EitherParseTreeOptions;\n }): void {\n this.fireListeners((listener) => listener.preChildrenParse?.({ ...options, parsedNode: parsed }));\n if (!options.input) return;\n const { alternativeInputs, ...branchOptions } = options;\n this.parseSelection(parsed, branchOptions, alternativeInputs ?? [options.input]);\n }\n\n parseChildrenInto({\n parent,\n inputs,\n options,\n selection\n }: {\n parent: ParsedNode;\n inputs: NodeInput[];\n options: ParseTreeOptions;\n selection?: NodeInputSelection;\n }): void {\n const matching = inputs.filter((input) => input.name === this.name);\n if (matching.length <= 1) {\n super.parseChildrenInto({ parent, inputs, options, selection });\n return;\n }\n const parsed = this.parse({\n ...options,\n input: matching[0],\n alternativeInputs: matching,\n parentNode: parent,\n parentEvent: options,\n key: this.options.key\n });\n if (parsed) parent.setChild(this.options.key, parsed);\n }\n\n private matches(definition: Node<any>, input: NodeInput, repeated: boolean): boolean {\n if (definition.options.isMultiple) return repeated || input.kind === NodeInputKind.ARRAY;\n if (repeated) return false;\n if (definition instanceof EitherNode) {\n return definition.nodes.some((branch) => definition.matches(branch, input, false));\n }\n if (input.kind === NodeInputKind.ELEMENT) return true;\n if (definition instanceof ContentNode) {\n return definition.options.valueType.is(input.content()?.value);\n }\n return input.kind === NodeInputKind.OBJECT;\n }\n\n private parseSelection(parsed: ParsedEitherNode<Value>, options: ParseTreeOptions, inputs: NodeInput[]): void {\n const input = inputs[0];\n const matches = this.nodes.filter((definition) => this.matches(definition, input, inputs.length > 1));\n if (matches.length !== 1) {\n parsed.pushError({\n source: input.source,\n message:\n matches.length === 0\n ? `No alternative matches '${input.name}' (${input.kind})`\n : `Multiple alternatives match '${input.name}' (${input.kind})`\n });\n return;\n }\n const definition = matches[0];\n if (definition.options.isMultiple) {\n const entries = input.kind === NodeInputKind.ARRAY ? Array.from(input.children()) : inputs;\n const array = new ParsedArrayNode({ definition, key: 'value', inputPresent: true, source: input.source });\n entries.forEach((entry, index) => {\n const child = definition.parseInput({ parent: parsed, options, input: entry, key: String(index) });\n if (child) array.addChild(child);\n });\n parsed.setChild('value', array);\n return;\n }\n const child = definition.parseInput({ parent: parsed, options, input, key: 'value' });\n if (child) parsed.setChild('value', child);\n }\n}\n"]}
|