@mak-98/xml-dirvi-app 0.0.0-stage → 0.11.0-beta.2
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/LICENSE +674 -0
- package/dist/domain/xml-tree.d.ts +271 -0
- package/dist/domain/xml-tree.d.ts.map +1 -0
- package/dist/domain/xml-tree.js +112 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/infrastructure/get-xml-entries.d.ts +19 -0
- package/dist/infrastructure/get-xml-entries.d.ts.map +1 -0
- package/dist/infrastructure/get-xml-entries.js +44 -0
- package/dist/infrastructure/load-node-xml-app-api.d.ts +10 -0
- package/dist/infrastructure/load-node-xml-app-api.d.ts.map +1 -0
- package/dist/infrastructure/load-node-xml-app-api.js +110 -0
- package/dist/infrastructure/load-node-xml-document.d.ts +6 -0
- package/dist/infrastructure/load-node-xml-document.d.ts.map +1 -0
- package/dist/infrastructure/load-node-xml-document.js +9 -0
- package/dist/infrastructure/parse-xml-document.d.ts +9 -0
- package/dist/infrastructure/parse-xml-document.d.ts.map +1 -0
- package/dist/infrastructure/parse-xml-document.js +26 -0
- package/dist/xml-dirvi-app.d.ts +6 -0
- package/dist/xml-dirvi-app.d.ts.map +1 -0
- package/dist/xml-dirvi-app.js +15 -0
- package/package.json +34 -3
- package/README.md +0 -3
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { State, TreeNodeModel } from 'dirvi-lib';
|
|
3
|
+
import type { Cursor, Folds, NavNode, TreeNode } from 'dirvi-lib';
|
|
4
|
+
/**
|
|
5
|
+
* A parser-assigned node identity within one XML document.
|
|
6
|
+
*
|
|
7
|
+
* Position is an identity, not XML document order. XML sibling order is held
|
|
8
|
+
* by the source TreeNode child sequence.
|
|
9
|
+
*/
|
|
10
|
+
export type Position = number;
|
|
11
|
+
export declare const XmlNodeIdSchema: z.ZodNumber;
|
|
12
|
+
export type XmlAttribute = Readonly<{
|
|
13
|
+
readonly name: string;
|
|
14
|
+
readonly value: string;
|
|
15
|
+
}>;
|
|
16
|
+
export type XmlDocumentValue = Readonly<{
|
|
17
|
+
readonly kind: 'document';
|
|
18
|
+
}>;
|
|
19
|
+
export type XmlDeclarationValue = Readonly<{
|
|
20
|
+
readonly kind: 'declaration';
|
|
21
|
+
readonly version: string;
|
|
22
|
+
readonly encoding: string | null;
|
|
23
|
+
readonly standalone: 'yes' | 'no' | null;
|
|
24
|
+
}>;
|
|
25
|
+
export type XmlDoctypeValue = Readonly<{
|
|
26
|
+
readonly kind: 'doctype';
|
|
27
|
+
readonly name: string;
|
|
28
|
+
readonly publicId: string | null;
|
|
29
|
+
readonly systemId: string | null;
|
|
30
|
+
readonly internalSubset: string | null;
|
|
31
|
+
}>;
|
|
32
|
+
export type XmlElementValue = Readonly<{
|
|
33
|
+
readonly kind: 'element';
|
|
34
|
+
readonly name: string;
|
|
35
|
+
readonly attributes: readonly XmlAttribute[];
|
|
36
|
+
}>;
|
|
37
|
+
export type XmlTextValue = Readonly<{
|
|
38
|
+
readonly kind: 'text';
|
|
39
|
+
readonly text: string;
|
|
40
|
+
}>;
|
|
41
|
+
export type XmlCommentValue = Readonly<{
|
|
42
|
+
readonly kind: 'comment';
|
|
43
|
+
readonly text: string;
|
|
44
|
+
}>;
|
|
45
|
+
export type XmlCdataValue = Readonly<{
|
|
46
|
+
readonly kind: 'cdata';
|
|
47
|
+
readonly text: string;
|
|
48
|
+
}>;
|
|
49
|
+
export type XmlProcessingInstructionValue = Readonly<{
|
|
50
|
+
readonly kind: 'processing-instruction';
|
|
51
|
+
readonly target: string;
|
|
52
|
+
readonly data: string;
|
|
53
|
+
}>;
|
|
54
|
+
/**
|
|
55
|
+
* XML semantics carried by a generic tree node.
|
|
56
|
+
*
|
|
57
|
+
* Child ordering is deliberately not represented here.
|
|
58
|
+
*/
|
|
59
|
+
export type XmlNodeValue = XmlDocumentValue | XmlDeclarationValue | XmlDoctypeValue | XmlElementValue | XmlTextValue | XmlCommentValue | XmlCdataValue | XmlProcessingInstructionValue;
|
|
60
|
+
export declare const XmlAttributeSchema: z.ZodObject<{
|
|
61
|
+
name: z.ZodString;
|
|
62
|
+
value: z.ZodString;
|
|
63
|
+
}, z.core.$strip>;
|
|
64
|
+
export declare const XmlDocumentValueSchema: z.ZodObject<{
|
|
65
|
+
kind: z.ZodLiteral<"document">;
|
|
66
|
+
}, z.core.$strip>;
|
|
67
|
+
export declare const XmlElementValueSchema: z.ZodObject<{
|
|
68
|
+
kind: z.ZodLiteral<"element">;
|
|
69
|
+
name: z.ZodString;
|
|
70
|
+
attributes: z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
71
|
+
name: z.ZodString;
|
|
72
|
+
value: z.ZodString;
|
|
73
|
+
}, z.core.$strip>>>;
|
|
74
|
+
}, z.core.$strip>;
|
|
75
|
+
export declare const XmlTextValueSchema: z.ZodObject<{
|
|
76
|
+
kind: z.ZodLiteral<"text">;
|
|
77
|
+
text: z.ZodString;
|
|
78
|
+
}, z.core.$strip>;
|
|
79
|
+
export declare const XmlCommentValueSchema: z.ZodObject<{
|
|
80
|
+
kind: z.ZodLiteral<"comment">;
|
|
81
|
+
text: z.ZodString;
|
|
82
|
+
}, z.core.$strip>;
|
|
83
|
+
export declare const XmlCdataValueSchema: z.ZodObject<{
|
|
84
|
+
kind: z.ZodLiteral<"cdata">;
|
|
85
|
+
text: z.ZodString;
|
|
86
|
+
}, z.core.$strip>;
|
|
87
|
+
export declare const XmlProcessingInstructionValueSchema: z.ZodObject<{
|
|
88
|
+
kind: z.ZodLiteral<"processing-instruction">;
|
|
89
|
+
target: z.ZodString;
|
|
90
|
+
data: z.ZodString;
|
|
91
|
+
}, z.core.$strip>;
|
|
92
|
+
export declare const XmlNodeValueSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
93
|
+
kind: z.ZodLiteral<"document">;
|
|
94
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
95
|
+
kind: z.ZodLiteral<"element">;
|
|
96
|
+
name: z.ZodString;
|
|
97
|
+
attributes: z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
98
|
+
name: z.ZodString;
|
|
99
|
+
value: z.ZodString;
|
|
100
|
+
}, z.core.$strip>>>;
|
|
101
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
102
|
+
kind: z.ZodLiteral<"text">;
|
|
103
|
+
text: z.ZodString;
|
|
104
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
105
|
+
kind: z.ZodLiteral<"comment">;
|
|
106
|
+
text: z.ZodString;
|
|
107
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
108
|
+
kind: z.ZodLiteral<"cdata">;
|
|
109
|
+
text: z.ZodString;
|
|
110
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
111
|
+
kind: z.ZodLiteral<"processing-instruction">;
|
|
112
|
+
target: z.ZodString;
|
|
113
|
+
data: z.ZodString;
|
|
114
|
+
}, z.core.$strip>], "kind">;
|
|
115
|
+
/**
|
|
116
|
+
* An opaque tree whose IDs are parser-assigned positions and whose values
|
|
117
|
+
* describe XML node semantics.
|
|
118
|
+
*/
|
|
119
|
+
export type XmlTreeNode = TreeNode<Position, XmlNodeValue>;
|
|
120
|
+
export declare const xmlTreeNodeApi: Readonly<{
|
|
121
|
+
createLeaf(id: number, value: XmlNodeValue): TreeNode<number, XmlNodeValue>;
|
|
122
|
+
createUnloadedBranch(id: number, value: XmlNodeValue): TreeNode<number, XmlNodeValue>;
|
|
123
|
+
createLoadedBranch(id: number, value: XmlNodeValue, children: Iterable<TreeNode<number, XmlNodeValue>>): TreeNode<number, XmlNodeValue> | undefined;
|
|
124
|
+
id(node: TreeNode<number, XmlNodeValue>): number;
|
|
125
|
+
value(node: TreeNode<number, XmlNodeValue>): XmlNodeValue;
|
|
126
|
+
kind(node: TreeNode<number, XmlNodeValue>): import("dirvi-lib").TreeNodeKind;
|
|
127
|
+
matchByKind<Result>(node: TreeNode<number, XmlNodeValue>, handlers: Readonly<{
|
|
128
|
+
leaf: (node: Readonly<{
|
|
129
|
+
id: number;
|
|
130
|
+
value: XmlNodeValue;
|
|
131
|
+
}>) => Result;
|
|
132
|
+
unloadedBranch: (node: Readonly<{
|
|
133
|
+
id: number;
|
|
134
|
+
value: XmlNodeValue;
|
|
135
|
+
}>) => Result;
|
|
136
|
+
loadedBranch: (node: Readonly<{
|
|
137
|
+
id: number;
|
|
138
|
+
value: XmlNodeValue;
|
|
139
|
+
children: Iterable<TreeNode<number, XmlNodeValue>>;
|
|
140
|
+
}>) => Result;
|
|
141
|
+
}>): Result;
|
|
142
|
+
getLoadedChildren(node: TreeNode<number, XmlNodeValue>): Iterable<TreeNode<number, XmlNodeValue>> | undefined;
|
|
143
|
+
findChildById(node: TreeNode<number, XmlNodeValue>, id: number): TreeNode<number, XmlNodeValue> | undefined;
|
|
144
|
+
withValue(node: TreeNode<number, XmlNodeValue>, value: XmlNodeValue): TreeNode<number, XmlNodeValue>;
|
|
145
|
+
toLeaf(node: TreeNode<number, XmlNodeValue>): TreeNode<number, XmlNodeValue>;
|
|
146
|
+
toUnloadedBranch(node: TreeNode<number, XmlNodeValue>): TreeNode<number, XmlNodeValue>;
|
|
147
|
+
withLoadedChildren(node: TreeNode<number, XmlNodeValue>, children: Iterable<TreeNode<number, XmlNodeValue>>): TreeNode<number, XmlNodeValue> | undefined;
|
|
148
|
+
findAtPath(root: TreeNode<number, XmlNodeValue>, path: readonly number[]): TreeNode<number, XmlNodeValue> | undefined;
|
|
149
|
+
selectAtPath<Result>(root: TreeNode<number, XmlNodeValue>, path: readonly number[], selector: (node: TreeNode<number, XmlNodeValue>) => Result): Result | undefined;
|
|
150
|
+
updateAtPath(root: TreeNode<number, XmlNodeValue>, path: readonly number[], update: (node: TreeNode<number, XmlNodeValue>) => TreeNode<number, XmlNodeValue> | undefined): TreeNode<number, XmlNodeValue> | undefined;
|
|
151
|
+
toModel(node: TreeNode<number, XmlNodeValue>): TreeNodeModel<number, XmlNodeValue>;
|
|
152
|
+
fromModel(model: TreeNodeModel<number, XmlNodeValue>): TreeNode<number, XmlNodeValue> | undefined;
|
|
153
|
+
}>;
|
|
154
|
+
export declare const XmlTreeNode: {
|
|
155
|
+
readonly document: (id: Position, children: Iterable<XmlTreeNode>) => XmlTreeNode | undefined;
|
|
156
|
+
readonly declaration: (id: Position, version: string, encoding: string | null, standalone: "yes" | "no" | null) => XmlTreeNode;
|
|
157
|
+
readonly doctype: (id: Position, name: string, publicId: string | null, systemId: string | null, internalSubset: string | null) => XmlTreeNode;
|
|
158
|
+
readonly element: (id: Position, name: string, attributes: readonly XmlAttribute[], children: Iterable<XmlTreeNode>) => XmlTreeNode | undefined;
|
|
159
|
+
readonly text: (id: Position, text: string) => XmlTreeNode;
|
|
160
|
+
readonly comment: (id: Position, text: string) => XmlTreeNode;
|
|
161
|
+
readonly cdata: (id: Position, text: string) => XmlTreeNode;
|
|
162
|
+
readonly processingInstruction: (id: Position, target: string, data: string) => XmlTreeNode;
|
|
163
|
+
};
|
|
164
|
+
export type XmlFolds = Folds<Position>;
|
|
165
|
+
export declare const xmlFoldsApi: Readonly<{
|
|
166
|
+
create(rootId: number, initialPrimaryInfo: Readonly<{
|
|
167
|
+
name: string;
|
|
168
|
+
description: string | null;
|
|
169
|
+
}>): Folds<number>;
|
|
170
|
+
getIndexByName(folds: Folds<number>, name: string): import("dirvi-lib").FoldIndex | undefined;
|
|
171
|
+
getInfoAtIndex(folds: Folds<number>, index: import("dirvi-lib").FoldIndex): Readonly<{
|
|
172
|
+
name: string;
|
|
173
|
+
description: string | null;
|
|
174
|
+
}> | undefined;
|
|
175
|
+
isActiveAtIndex(folds: Folds<number>, index: import("dirvi-lib").FoldIndex): boolean | undefined;
|
|
176
|
+
hasAtIndex(folds: Folds<number>, index: import("dirvi-lib").FoldIndex): boolean;
|
|
177
|
+
indexes(folds: Folds<number>): Iterable<import("dirvi-lib").FoldIndex>;
|
|
178
|
+
setAtIndex(folds: Folds<number>, index: import("dirvi-lib").FoldIndex, foldData: Readonly<{
|
|
179
|
+
name: string;
|
|
180
|
+
description: string | null;
|
|
181
|
+
active: boolean;
|
|
182
|
+
tree: Readonly<{
|
|
183
|
+
id: number;
|
|
184
|
+
hiddenEntryIds: readonly number[];
|
|
185
|
+
children: readonly Readonly</*elided*/ any>[];
|
|
186
|
+
}>;
|
|
187
|
+
}>): Folds<number> | undefined;
|
|
188
|
+
setAdditionalFoldAtIndex(folds: Folds<number>, index: import("dirvi-lib").FoldIndex, rootId: number, info: Readonly<{
|
|
189
|
+
name: string;
|
|
190
|
+
description: string | null;
|
|
191
|
+
}>): Folds<number> | undefined;
|
|
192
|
+
removeAdditionalFoldAtIndex(folds: Folds<number>, index: import("dirvi-lib").FoldIndex): Folds<number> | undefined;
|
|
193
|
+
updateInfoAtIndex(folds: Folds<number>, index: import("dirvi-lib").FoldIndex, update: Readonly<{
|
|
194
|
+
name?: string;
|
|
195
|
+
description?: string | null;
|
|
196
|
+
}>): Folds<number> | undefined;
|
|
197
|
+
activateAtIndex(folds: Folds<number>, index: import("dirvi-lib").FoldIndex): Folds<number> | undefined;
|
|
198
|
+
deactivateAtIndex(folds: Folds<number>, index: import("dirvi-lib").FoldIndex): Folds<number> | undefined;
|
|
199
|
+
toggleActiveAtIndex(folds: Folds<number>, index: import("dirvi-lib").FoldIndex): Folds<number> | undefined;
|
|
200
|
+
isEntryHiddenInFoldAtPath(folds: Folds<number>, index: import("dirvi-lib").FoldIndex, path: readonly number[], entryId: number): boolean;
|
|
201
|
+
isEntryHiddenAtPath(folds: Folds<number>, path: readonly number[], entryId: number): boolean;
|
|
202
|
+
hiddenEntryIdsAtPath(folds: Folds<number>, index: import("dirvi-lib").FoldIndex, path: readonly number[]): Iterable<number> | undefined;
|
|
203
|
+
hideEntryAtPath(folds: Folds<number>, index: import("dirvi-lib").FoldIndex, path: readonly number[], entryId: number): Folds<number> | undefined;
|
|
204
|
+
showEntryAtPath(folds: Folds<number>, index: import("dirvi-lib").FoldIndex, path: readonly number[], entryId: number): Folds<number> | undefined;
|
|
205
|
+
showAllHiddenEntriesAtPath(folds: Folds<number>, index: import("dirvi-lib").FoldIndex, path: readonly number[]): Folds<number> | undefined;
|
|
206
|
+
toModel(folds: Folds<number>): Readonly<{
|
|
207
|
+
slots: readonly [Readonly<{
|
|
208
|
+
name: string;
|
|
209
|
+
description: string | null;
|
|
210
|
+
active: boolean;
|
|
211
|
+
tree: Readonly<{
|
|
212
|
+
id: number;
|
|
213
|
+
hiddenEntryIds: readonly number[];
|
|
214
|
+
children: readonly Readonly</*elided*/ any>[];
|
|
215
|
+
}>;
|
|
216
|
+
}>, ...(Readonly<{
|
|
217
|
+
name: string;
|
|
218
|
+
description: string | null;
|
|
219
|
+
active: boolean;
|
|
220
|
+
tree: Readonly<{
|
|
221
|
+
id: number;
|
|
222
|
+
hiddenEntryIds: readonly number[];
|
|
223
|
+
children: readonly Readonly</*elided*/ any>[];
|
|
224
|
+
}>;
|
|
225
|
+
}> | null)[]];
|
|
226
|
+
}>;
|
|
227
|
+
fromModel(model: Readonly<{
|
|
228
|
+
slots: readonly [Readonly<{
|
|
229
|
+
name: string;
|
|
230
|
+
description: string | null;
|
|
231
|
+
active: boolean;
|
|
232
|
+
tree: Readonly<{
|
|
233
|
+
id: number;
|
|
234
|
+
hiddenEntryIds: readonly number[];
|
|
235
|
+
children: readonly Readonly</*elided*/ any>[];
|
|
236
|
+
}>;
|
|
237
|
+
}>, ...(Readonly<{
|
|
238
|
+
name: string;
|
|
239
|
+
description: string | null;
|
|
240
|
+
active: boolean;
|
|
241
|
+
tree: Readonly<{
|
|
242
|
+
id: number;
|
|
243
|
+
hiddenEntryIds: readonly number[];
|
|
244
|
+
children: readonly Readonly</*elided*/ any>[];
|
|
245
|
+
}>;
|
|
246
|
+
}> | null)[]];
|
|
247
|
+
}>): Folds<number> | undefined;
|
|
248
|
+
}>;
|
|
249
|
+
export declare const xmlCursorSchema: z.ZodType<XmlCursor>;
|
|
250
|
+
export type XmlCursor = Cursor<Position>;
|
|
251
|
+
export declare const xmlCursorApi: import("dirvi-lib").CursorApi<number>;
|
|
252
|
+
export type XmlNavNode = NavNode<Position>;
|
|
253
|
+
export declare const xmlNavApi: import("dirvi-lib").NavNodeApi<number, XmlNodeValue>;
|
|
254
|
+
export type XmlState = State<Position, XmlNodeValue>;
|
|
255
|
+
export declare const xmlStateApi: Readonly<{
|
|
256
|
+
getNodeAtCursor(state: Readonly<{
|
|
257
|
+
root: TreeNode<number, XmlNodeValue>;
|
|
258
|
+
folds: Folds<number>;
|
|
259
|
+
cursor: Cursor<number>;
|
|
260
|
+
}>): TreeNode<number, XmlNodeValue> | undefined;
|
|
261
|
+
resync(oldState: Readonly<{
|
|
262
|
+
root: TreeNode<number, XmlNodeValue>;
|
|
263
|
+
folds: Folds<number>;
|
|
264
|
+
cursor: Cursor<number>;
|
|
265
|
+
}>, loadBranches: (path: readonly number[]) => Promise<readonly TreeNode<number, XmlNodeValue>[]>): Promise<Readonly<{
|
|
266
|
+
root: TreeNode<number, XmlNodeValue>;
|
|
267
|
+
folds: Folds<number>;
|
|
268
|
+
cursor: Cursor<number>;
|
|
269
|
+
}>>;
|
|
270
|
+
}>;
|
|
271
|
+
//# sourceMappingURL=xml-tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xml-tree.d.ts","sourceRoot":"","sources":["../../src/domain/xml-tree.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAK0B,KAAK,EAAc,aAAa,EAChE,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EACV,MAAM,EACN,KAAK,EACL,OAAO,EAEP,QAAQ,EACT,MAAM,WAAW,CAAC;AAYnB;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC;AAE9B,eAAO,MAAM,eAAe,aAGkB,CAAC;AAY/C,MAAM,MAAM,YAAY,GAAG,QAAQ,C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ib';
|
|
3
|
+
export const XmlNodeIdSchema = z
|
|
4
|
+
.number()
|
|
5
|
+
.int()
|
|
6
|
+
.nonnegative();
|
|
7
|
+
// Schema ----------------------------------------------------------------------
|
|
8
|
+
export const XmlAttributeSchema = z.object({
|
|
9
|
+
name: z.string().min(1),
|
|
10
|
+
value: z.string(),
|
|
11
|
+
});
|
|
12
|
+
export const XmlDocumentValueSchema = z.object({
|
|
13
|
+
kind: z.literal('document'),
|
|
14
|
+
});
|
|
15
|
+
export const XmlElementValueSchema = z.object({
|
|
16
|
+
kind: z.literal('element'),
|
|
17
|
+
name: z.string().min(1),
|
|
18
|
+
attributes: z.array(XmlAttributeSchema).readonly(),
|
|
19
|
+
});
|
|
20
|
+
// TODO: add declaration and doctype when schema is needed
|
|
21
|
+
export const XmlTextValueSchema = z.object({
|
|
22
|
+
kind: z.literal('text'),
|
|
23
|
+
text: z.string(),
|
|
24
|
+
});
|
|
25
|
+
export const XmlCommentValueSchema = z.object({
|
|
26
|
+
kind: z.literal('comment'),
|
|
27
|
+
text: z.string(),
|
|
28
|
+
});
|
|
29
|
+
export const XmlCdataValueSchema = z.object({
|
|
30
|
+
kind: z.literal('cdata'),
|
|
31
|
+
text: z.string(),
|
|
32
|
+
});
|
|
33
|
+
export const XmlProcessingInstructionValueSchema = z.object({
|
|
34
|
+
kind: z.literal('processing-instruction'),
|
|
35
|
+
target: z.string().min(1),
|
|
36
|
+
data: z.string(),
|
|
37
|
+
});
|
|
38
|
+
export const XmlNodeValueSchema = z.discriminatedUnion('kind', [
|
|
39
|
+
XmlDocumentValueSchema,
|
|
40
|
+
XmlElementValueSchema,
|
|
41
|
+
XmlTextValueSchema,
|
|
42
|
+
XmlCommentValueSchema,
|
|
43
|
+
XmlCdataValueSchema,
|
|
44
|
+
XmlProcessingInstructionValueSchema,
|
|
45
|
+
]);
|
|
46
|
+
export const xmlTreeNodeApi = createTreeNodeApi();
|
|
47
|
+
// -----------------------------------------------------------------------------
|
|
48
|
+
// XML domain constructors
|
|
49
|
+
// -----------------------------------------------------------------------------
|
|
50
|
+
export const XmlTreeNode = {
|
|
51
|
+
document(id, children) {
|
|
52
|
+
return xmlTreeNodeApi.createLoadedBranch(id, { kind: 'document' }, children);
|
|
53
|
+
},
|
|
54
|
+
declaration(id, version, encoding, standalone) {
|
|
55
|
+
return xmlTreeNodeApi.createLeaf(id, {
|
|
56
|
+
kind: 'declaration',
|
|
57
|
+
version,
|
|
58
|
+
encoding,
|
|
59
|
+
standalone,
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
doctype(id, name, publicId, systemId, internalSubset) {
|
|
63
|
+
return xmlTreeNodeApi.createLeaf(id, {
|
|
64
|
+
kind: 'doctype',
|
|
65
|
+
name,
|
|
66
|
+
publicId,
|
|
67
|
+
systemId,
|
|
68
|
+
internalSubset,
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
element(id, name, attributes, children) {
|
|
72
|
+
return xmlTreeNodeApi.createLoadedBranch(id, {
|
|
73
|
+
kind: 'element',
|
|
74
|
+
name,
|
|
75
|
+
attributes,
|
|
76
|
+
}, children);
|
|
77
|
+
},
|
|
78
|
+
text(id, text) {
|
|
79
|
+
return xmlTreeNodeApi.createLeaf(id, {
|
|
80
|
+
kind: 'text',
|
|
81
|
+
text,
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
comment(id, text) {
|
|
85
|
+
return xmlTreeNodeApi.createLeaf(id, {
|
|
86
|
+
kind: 'comment',
|
|
87
|
+
text,
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
cdata(id, text) {
|
|
91
|
+
return xmlTreeNodeApi.createLeaf(id, {
|
|
92
|
+
kind: 'cdata',
|
|
93
|
+
text,
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
processingInstruction(id, target, data) {
|
|
97
|
+
return xmlTreeNodeApi.createLeaf(id, {
|
|
98
|
+
kind: 'processing-instruction',
|
|
99
|
+
target,
|
|
100
|
+
data,
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
const xmlFoldTreeNodeApi = createTreeNodeApi();
|
|
105
|
+
export const xmlFoldsApi = createFoldsApi(xmlFoldTreeNodeApi);
|
|
106
|
+
// -----------------------------------------------------------------------------
|
|
107
|
+
// XmlCursor
|
|
108
|
+
// -----------------------------------------------------------------------------
|
|
109
|
+
export const xmlCursorSchema = createCursorSchema(XmlNodeIdSchema);
|
|
110
|
+
export const xmlCursorApi = createCursorApi();
|
|
111
|
+
export const xmlNavApi = createNavNodeApi(xmlTreeNodeApi, xmlFoldsApi, xmlCursorApi, {});
|
|
112
|
+
export const xmlStateApi = createStateApi(xmlTreeNodeApi, xmlCursorApi);
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,IAAI,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { XmlNode } from '@rgrove/parse-xml';
|
|
2
|
+
import type { XmlTreeNode } from '../domain/xml-tree.js';
|
|
3
|
+
import { type Position } from '../domain/xml-tree.js';
|
|
4
|
+
/**
|
|
5
|
+
* Allocates unique XML tree IDs while one parsed document is converted.
|
|
6
|
+
*
|
|
7
|
+
* IDs identify nodes and cursor paths. They do not represent sibling order:
|
|
8
|
+
* source child order is preserved by the TreeNode child sequence.
|
|
9
|
+
*/
|
|
10
|
+
export type CreatePosition = () => Position;
|
|
11
|
+
/**
|
|
12
|
+
* Converts XML parser nodes into ordered Dirvi XML tree nodes.
|
|
13
|
+
*
|
|
14
|
+
* The returned array preserves parser child order exactly. In particular,
|
|
15
|
+
* mixed content such as text, elements, comments, and CDATA remains in its
|
|
16
|
+
* source-document order.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getXmlEntries(xmlNodes: readonly XmlNode[], createPosition: CreatePosition): XmlTreeNode[];
|
|
19
|
+
//# sourceMappingURL=get-xml-entries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-xml-entries.d.ts","sourceRoot":"","sources":["../../src/infrastructure/get-xml-entries.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EACL,KAAK,QAAQ,EAEd,MAAM,uBAAuB,CAAC;AAE/B;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,QAAQ,CAAC;AAE5C;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,SAAS,OAAO,EAAE,EAC5B,cAAc,EAAE,cAAc,GAC7B,WAAW,EAAE,CAmEf"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { XmlCdata, XmlComment, XmlDeclaration, XmlDocumentType, XmlElement, XmlProcessingInstruction, XmlText, } from '@rgrove/parse-xml';
|
|
2
|
+
import { XmlTreeNode as XmlTreeNodeDomain, } from '../domain/xml-tree.js';
|
|
3
|
+
/**
|
|
4
|
+
* Converts XML parser nodes into ordered Dirvi XML tree nodes.
|
|
5
|
+
*
|
|
6
|
+
* The returned array preserves parser child order exactly. In particular,
|
|
7
|
+
* mixed content such as text, elements, comments, and CDATA remains in its
|
|
8
|
+
* source-document order.
|
|
9
|
+
*/
|
|
10
|
+
export function getXmlEntries(xmlNodes, createPosition) {
|
|
11
|
+
return xmlNodes.map((xmlNode) => {
|
|
12
|
+
const id = createPosition();
|
|
13
|
+
if (xmlNode instanceof XmlElement) {
|
|
14
|
+
const children = getXmlEntries(xmlNode.children, createPosition);
|
|
15
|
+
const node = XmlTreeNodeDomain.element(id, xmlNode.name, Object.entries(xmlNode.attributes).map(([name, value]) => ({
|
|
16
|
+
name,
|
|
17
|
+
value,
|
|
18
|
+
})), children);
|
|
19
|
+
if (node === undefined) {
|
|
20
|
+
throw new Error(`Cannot create XML element "${xmlNode.name}": duplicate child IDs.`);
|
|
21
|
+
}
|
|
22
|
+
return node;
|
|
23
|
+
}
|
|
24
|
+
if (xmlNode instanceof XmlText) {
|
|
25
|
+
return XmlTreeNodeDomain.text(id, xmlNode.text);
|
|
26
|
+
}
|
|
27
|
+
if (xmlNode instanceof XmlCdata) {
|
|
28
|
+
return XmlTreeNodeDomain.cdata(id, xmlNode.text);
|
|
29
|
+
}
|
|
30
|
+
if (xmlNode instanceof XmlComment) {
|
|
31
|
+
return XmlTreeNodeDomain.comment(id, xmlNode.content);
|
|
32
|
+
}
|
|
33
|
+
if (xmlNode instanceof XmlProcessingInstruction) {
|
|
34
|
+
return XmlTreeNodeDomain.processingInstruction(id, xmlNode.name, xmlNode.content);
|
|
35
|
+
}
|
|
36
|
+
if (xmlNode instanceof XmlDeclaration) {
|
|
37
|
+
return XmlTreeNodeDomain.declaration(id, xmlNode.version, xmlNode.encoding, xmlNode.standalone);
|
|
38
|
+
}
|
|
39
|
+
if (xmlNode instanceof XmlDocumentType) {
|
|
40
|
+
return XmlTreeNodeDomain.doctype(id, xmlNode.name, xmlNode.publicId, xmlNode.systemId, xmlNode.internalSubset);
|
|
41
|
+
}
|
|
42
|
+
throw new Error(`Unsupported XML node type "${xmlNode.type}".`);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AppApi } from 'dirvi-apis';
|
|
2
|
+
import { type Position, type XmlNodeValue } from '../domain/xml-tree.js';
|
|
3
|
+
/**
|
|
4
|
+
* Creates the AppApi for one XML document.
|
|
5
|
+
*
|
|
6
|
+
* XML is parsed eagerly as one complete tree. Child order is retained by the
|
|
7
|
+
* XML domain tree and displayed through xmlNavApi's source-order navigation.
|
|
8
|
+
*/
|
|
9
|
+
export declare function loadNodeXmlAppApi(filePath: string): AppApi<Position, XmlNodeValue, string>;
|
|
10
|
+
//# sourceMappingURL=load-node-xml-app-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-node-xml-app-api.d.ts","sourceRoot":"","sources":["../../src/infrastructure/load-node-xml-app-api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAGzC,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,YAAY,EAGlB,MAAM,uBAAuB,CAAC;AAG/B;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,GACf,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,CAAC,CA0CxC"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { watch } from 'node:fs';
|
|
2
|
+
import { basename, dirname, resolve } from 'node:path';
|
|
3
|
+
import { createAppStateApis } from 'dirvi-lib';
|
|
4
|
+
import { xmlFoldsApi, xmlNavApi, } from '../domain/xml-tree.js';
|
|
5
|
+
import { loadNodeXmlDocument } from './load-node-xml-document.js';
|
|
6
|
+
/**
|
|
7
|
+
* Creates the AppApi for one XML document.
|
|
8
|
+
*
|
|
9
|
+
* XML is parsed eagerly as one complete tree. Child order is retained by the
|
|
10
|
+
* XML domain tree and displayed through xmlNavApi's source-order navigation.
|
|
11
|
+
*/
|
|
12
|
+
export function loadNodeXmlAppApi(filePath) {
|
|
13
|
+
const xmlAbsolutePath = resolve(filePath);
|
|
14
|
+
const apis = createAppStateApis();
|
|
15
|
+
return {
|
|
16
|
+
name: basename(xmlAbsolutePath),
|
|
17
|
+
/*
|
|
18
|
+
* parseXmlDocument() reserves position 0 for the synthetic document root.
|
|
19
|
+
*/
|
|
20
|
+
rootId: 0,
|
|
21
|
+
createRoot: () => loadNodeXmlDocument(xmlAbsolutePath),
|
|
22
|
+
/*
|
|
23
|
+
* XML documents are parsed completely when their root is created. No XML
|
|
24
|
+
* branch is represented as an unloaded branch.
|
|
25
|
+
*/
|
|
26
|
+
async loadBranches() {
|
|
27
|
+
throw new Error('Cannot load XML branches: parsed XML documents have no unloaded branches.');
|
|
28
|
+
},
|
|
29
|
+
/*
|
|
30
|
+
* Watch the parent directory rather than the file directly. Editors often
|
|
31
|
+
* save atomically by replacing the document file with a renamed temporary
|
|
32
|
+
* file, which can invalidate a direct file watcher.
|
|
33
|
+
*/
|
|
34
|
+
subscribeToResync: createXmlFileResyncSubscription(xmlAbsolutePath),
|
|
35
|
+
/*
|
|
36
|
+
* The absolute filename identifies this app instance. View persistence is
|
|
37
|
+
* intentionally not wired yet.
|
|
38
|
+
*/
|
|
39
|
+
// viewKey: xmlAbsolutePath,
|
|
40
|
+
foldsApi: xmlFoldsApi,
|
|
41
|
+
navNodeApi: xmlNavApi,
|
|
42
|
+
...apis,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function createXmlFileResyncSubscription(xmlAbsolutePath) {
|
|
46
|
+
const listeners = new Set();
|
|
47
|
+
const parentDirectory = dirname(xmlAbsolutePath);
|
|
48
|
+
const fileName = basename(xmlAbsolutePath);
|
|
49
|
+
let watcher;
|
|
50
|
+
let notificationTimer;
|
|
51
|
+
function notifyListeners() {
|
|
52
|
+
for (const listener of listeners) {
|
|
53
|
+
listener();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function scheduleNotification() {
|
|
57
|
+
if (notificationTimer !== undefined) {
|
|
58
|
+
clearTimeout(notificationTimer);
|
|
59
|
+
}
|
|
60
|
+
notificationTimer = setTimeout(() => {
|
|
61
|
+
notificationTimer = undefined;
|
|
62
|
+
if (listeners.size > 0) {
|
|
63
|
+
notifyListeners();
|
|
64
|
+
}
|
|
65
|
+
}, 100);
|
|
66
|
+
}
|
|
67
|
+
function startWatcher() {
|
|
68
|
+
if (watcher !== undefined) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
watcher = watch(parentDirectory, (_eventType, changedName) => {
|
|
72
|
+
/*
|
|
73
|
+
* A null filename means the platform could not identify the changed
|
|
74
|
+
* entry. Conservatively resync in that case.
|
|
75
|
+
*/
|
|
76
|
+
if (changedName === null || changedName.toString() === fileName) {
|
|
77
|
+
scheduleNotification();
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
watcher.on('error', () => {
|
|
81
|
+
/*
|
|
82
|
+
* The next createRoot() call will report the filesystem or XML parsing
|
|
83
|
+
* failure through normal application error handling.
|
|
84
|
+
*/
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function stopWatcher() {
|
|
88
|
+
if (notificationTimer !== undefined) {
|
|
89
|
+
clearTimeout(notificationTimer);
|
|
90
|
+
notificationTimer = undefined;
|
|
91
|
+
}
|
|
92
|
+
watcher?.close();
|
|
93
|
+
watcher = undefined;
|
|
94
|
+
}
|
|
95
|
+
return (listener) => {
|
|
96
|
+
listeners.add(listener);
|
|
97
|
+
startWatcher();
|
|
98
|
+
let subscribed = true;
|
|
99
|
+
return () => {
|
|
100
|
+
if (!subscribed) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
subscribed = false;
|
|
104
|
+
listeners.delete(listener);
|
|
105
|
+
if (listeners.size === 0) {
|
|
106
|
+
stopWatcher();
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { XmlTreeNode } from '../domain/xml-tree.js';
|
|
2
|
+
/**
|
|
3
|
+
* Reads one UTF-8 XML file and parses it into the XML domain tree.
|
|
4
|
+
*/
|
|
5
|
+
export declare function loadNodeXmlDocument(filePath: string): Promise<XmlTreeNode>;
|
|
6
|
+
//# sourceMappingURL=load-node-xml-document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-node-xml-document.d.ts","sourceRoot":"","sources":["../../src/infrastructure/load-node-xml-document.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGzD;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,WAAW,CAAC,CAItB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { parseXmlDocument } from './parse-xml-document.js';
|
|
3
|
+
/**
|
|
4
|
+
* Reads one UTF-8 XML file and parses it into the XML domain tree.
|
|
5
|
+
*/
|
|
6
|
+
export async function loadNodeXmlDocument(filePath) {
|
|
7
|
+
const source = await readFile(filePath, 'utf8');
|
|
8
|
+
return parseXmlDocument(source);
|
|
9
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { XmlTreeNode } from '../domain/xml-tree.js';
|
|
2
|
+
/**
|
|
3
|
+
* Parses XML source into one Dirvi XML document tree.
|
|
4
|
+
*
|
|
5
|
+
* The synthetic document root always receives ID 0. Descendants receive
|
|
6
|
+
* monotonically allocated IDs in parser encounter order.
|
|
7
|
+
*/
|
|
8
|
+
export declare function parseXmlDocument(source: string): XmlTreeNode;
|
|
9
|
+
//# sourceMappingURL=parse-xml-document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-xml-document.d.ts","sourceRoot":"","sources":["../../src/infrastructure/parse-xml-document.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAIzD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAwB5D"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { parseXml } from '@rgrove/parse-xml';
|
|
2
|
+
import { XmlTreeNode as XmlTreeNodeDomain } from '../domain/xml-tree.js';
|
|
3
|
+
import { getXmlEntries } from './get-xml-entries.js';
|
|
4
|
+
/**
|
|
5
|
+
* Parses XML source into one Dirvi XML document tree.
|
|
6
|
+
*
|
|
7
|
+
* The synthetic document root always receives ID 0. Descendants receive
|
|
8
|
+
* monotonically allocated IDs in parser encounter order.
|
|
9
|
+
*/
|
|
10
|
+
export function parseXmlDocument(source) {
|
|
11
|
+
const document = parseXml(source);
|
|
12
|
+
let nextPosition = 1;
|
|
13
|
+
const root = XmlTreeNodeDomain.document(0, getXmlEntries(document.children, () => {
|
|
14
|
+
const position = nextPosition;
|
|
15
|
+
nextPosition += 1;
|
|
16
|
+
return position;
|
|
17
|
+
}));
|
|
18
|
+
if (root === undefined) {
|
|
19
|
+
/*
|
|
20
|
+
* Position allocation is unique, so this would indicate a defect in the
|
|
21
|
+
* XML-to-domain conversion rather than invalid user XML.
|
|
22
|
+
*/
|
|
23
|
+
throw new Error('Cannot create XML document: duplicate child IDs.');
|
|
24
|
+
}
|
|
25
|
+
return root;
|
|
26
|
+
}
|