xnl-core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,154 @@
1
+ type ValueLiteral = string | boolean | null | number;
2
+ type AttributeMap = Record<string, XnlNode>;
3
+ interface ExtendBody {
4
+ order: string[];
5
+ children: Record<string, ElementNode>;
6
+ }
7
+ type ElementNode = DataElementNode | TextElementNode;
8
+ type ElementNodeKind = 'DataElement' | 'TextElement';
9
+ interface DataElementNode {
10
+ kind: "DataElement";
11
+ tag: string;
12
+ id?: XnlWord;
13
+ metadata: AttributeMap;
14
+ attributes?: AttributeMap;
15
+ body?: XnlNode[];
16
+ extend?: ExtendBody;
17
+ }
18
+ interface XnlWord {
19
+ kind: "Word";
20
+ namespace: string[];
21
+ name: string;
22
+ }
23
+ interface TextElementNode {
24
+ kind: "TextElement";
25
+ tag: string;
26
+ id?: XnlWord;
27
+ metadata: AttributeMap;
28
+ attributes?: AttributeMap;
29
+ text?: string;
30
+ textMarker?: string;
31
+ }
32
+ interface CommentNode {
33
+ kind: "Comment";
34
+ value: string;
35
+ }
36
+ type ContainerNode = Array<XnlNode> | Object | ElementNode;
37
+ type XnlNode = ValueLiteral | XnlWord | ContainerNode | CommentNode;
38
+ declare function isWord(value: any): value is XnlWord;
39
+ declare function wordToString(word?: XnlWord | null): string | undefined;
40
+ type ParseWarningCode = "DUPLICATE_CHILD";
41
+ interface ParseWarning {
42
+ code: ParseWarningCode;
43
+ message: string;
44
+ parentName: string;
45
+ childName: string;
46
+ }
47
+ interface XnlDocument {
48
+ nodes: XnlNode[];
49
+ warnings?: ParseWarning[];
50
+ }
51
+ interface SingleNodeResult {
52
+ node: XnlNode;
53
+ warnings: ParseWarning[];
54
+ }
55
+ interface UniqueChildrenResult {
56
+ node: XnlNode;
57
+ warnings: ParseWarning[];
58
+ }
59
+
60
+ declare function parseXnl(input: string): XnlDocument;
61
+ declare function parseXnlSingleNode(input: string): SingleNodeResult;
62
+ declare function parseUniqueChildren(name: string, input: string, metadata?: AttributeMap, attributes?: AttributeMap): UniqueChildrenResult;
63
+
64
+ interface StringifyOptions {
65
+ pretty?: boolean;
66
+ indent?: number | string;
67
+ }
68
+ declare function stringify(value: XnlDocument | XnlNode, options?: StringifyOptions): string;
69
+
70
+ type PathItemType = "UniqueName" | "MetadataSelector" | "InstanceProperty" | "MapKey" | "ListIndex";
71
+ interface PathItem {
72
+ type: PathItemType;
73
+ value: string;
74
+ }
75
+ type XnlPath = PathItem[];
76
+ type MetadataSelectorMode = "identity" | "metadata";
77
+ interface ResolveOptions {
78
+ strict?: boolean;
79
+ metadataIdMode?: MetadataSelectorMode;
80
+ }
81
+ interface SetOptions extends ResolveOptions {
82
+ mode?: "insert" | "replace";
83
+ }
84
+ declare class XnlPathError extends Error {
85
+ }
86
+ declare function parsePath(input: string): XnlPath;
87
+ declare function resolvePath(target: XnlDocument | XnlNode, path: string | XnlPath, options?: ResolveOptions): any;
88
+ declare function setPathValue(target: XnlDocument | XnlNode, path: string | XnlPath, value: any, options?: SetOptions): any;
89
+ declare function deleteAtPath(target: XnlDocument | XnlNode, path: string | XnlPath, options?: ResolveOptions): any;
90
+
91
+ type MutationType = "TREE_ADD" | "TREE_DELETE" | "TREE_MOVE" | "TREE_UPDATE" | "TREE_MOVE_SAME_LEVEL" | "TREE_MOVE_CROSS_LEVEL" | "OBJECT_ADD" | "OBJECT_DELETE" | "OBJECT_UPDATE";
92
+ interface XnlMutation {
93
+ type: MutationType;
94
+ path: string | XnlPath;
95
+ pathBefore?: string | XnlPath;
96
+ valueBefore?: XnlNode;
97
+ valueAfter?: XnlNode;
98
+ metadata?: Record<string, unknown>;
99
+ targetUniqueName?: string;
100
+ parentUniqueNameBefore?: string;
101
+ parentUniqueNameAfter?: string;
102
+ }
103
+ type MetadataIdMode = "identity" | "metadata";
104
+ interface XnlMutationOptions {
105
+ metadataIdMode?: MetadataIdMode;
106
+ }
107
+ declare function applyMutations(root: XnlNode, mutations: XnlMutation[], opts?: XnlMutationOptions): XnlNode;
108
+ declare function diffNodes(oldNode: XnlNode, newNode: XnlNode, basePath?: string | XnlPath, opts?: XnlMutationOptions): XnlMutation[];
109
+
110
+ interface LoaderContext {
111
+ prototypes: Record<string, Record<string, DataElementNode>>;
112
+ }
113
+ declare function loadFromString(input: string): XnlDocument;
114
+ declare function resolveNode(ctx: LoaderContext, node: DataElementNode, scope: Record<string, Record<string, DataElementNode>>[]): DataElementNode;
115
+ declare function batchLoad(batches: DataElementNode[][]): {
116
+ resolved: DataElementNode[][];
117
+ exports: Record<string, Record<string, DataElementNode>>;
118
+ };
119
+
120
+ type XnlErrorCode = "UNEXPECTED_EOF" | "MISMATCHED_TAG" | "DUPLICATE_CHILD" | "INVALID_CONTENT" | "INVALID_LITERAL" | "UNEXPECTED_TOKEN";
121
+ declare class XnlParseError extends Error {
122
+ readonly code: XnlErrorCode;
123
+ readonly position: number;
124
+ readonly line: number;
125
+ readonly column: number;
126
+ constructor(code: XnlErrorCode, message: string, input: string, position: number);
127
+ }
128
+
129
+ declare function GetWordFullName(word: XnlWord): string;
130
+ declare function MakeWord(wordStr: string, namespace?: never[]): XnlWord;
131
+
132
+ declare const XNL: {
133
+ parseMany: typeof parseXnl;
134
+ parseSingle: typeof parseXnlSingleNode;
135
+ parseUnique: typeof parseUniqueChildren;
136
+ stringify: typeof stringify;
137
+ path: {
138
+ parse: typeof parsePath;
139
+ resolve: typeof resolvePath;
140
+ set: typeof setPathValue;
141
+ delete: typeof deleteAtPath;
142
+ };
143
+ mutation: {
144
+ apply: typeof applyMutations;
145
+ diff: typeof diffNodes;
146
+ };
147
+ loader: {
148
+ loadFromString: typeof loadFromString;
149
+ loadNode: typeof resolveNode;
150
+ batchLoad: typeof batchLoad;
151
+ };
152
+ };
153
+
154
+ export { type AttributeMap, type CommentNode, type DataElementNode, type ElementNode, type ElementNodeKind, type ExtendBody, GetWordFullName, MakeWord, type MetadataIdMode, type MutationType, type ParseWarning, type PathItem, type PathItemType, type SingleNodeResult, type TextElementNode, type UniqueChildrenResult, type ValueLiteral, XNL, type XnlDocument, type XnlErrorCode, type XnlMutation, type XnlMutationOptions, type XnlNode, XnlParseError, type XnlPath, XnlPathError, type XnlWord, applyMutations, batchLoad, deleteAtPath, diffNodes, isWord, loadFromString, resolveNode as loadNode, parsePath, parseUniqueChildren, parseXnl, parseXnlSingleNode, resolvePath, setPathValue, wordToString };