@mak-98/xml-dirvi-app 0.11.0-beta.15.1 → 0.11.0-beta.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/domain/xml-doc.d.ts +73 -0
- package/dist/domain/xml-doc.d.ts.map +1 -0
- package/dist/domain/xml-doc.js +15 -0
- package/dist/domain/xml-tree.d.ts +64 -100
- package/dist/domain/xml-tree.d.ts.map +1 -1
- package/dist/domain/xml-tree.js +54 -86
- package/dist/infrastructure/create-xml-dom.d.ts +6 -0
- package/dist/infrastructure/create-xml-dom.d.ts.map +1 -0
- package/dist/infrastructure/create-xml-dom.js +163 -0
- package/dist/infrastructure/get-xml-entries.d.ts +5 -4
- package/dist/infrastructure/get-xml-entries.d.ts.map +1 -1
- package/dist/infrastructure/get-xml-entries.js +31 -101
- package/dist/services/xml-dom.d.ts +17 -0
- package/dist/services/xml-dom.d.ts.map +1 -0
- package/dist/services/xml-dom.js +1 -0
- package/dist/xml-dirvi-app.d.ts.map +1 -1
- package/dist/xml-dirvi-app.js +29 -7
- package/package.json +4 -3
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An XML document contains one root element and may also contain an XML
|
|
3
|
+
* declaration, a doctype, comments, and processing instructions. Elements
|
|
4
|
+
* have attributes and ordered children; their children may include elements,
|
|
5
|
+
* text, CDATA, comments, and processing instructions.
|
|
6
|
+
*
|
|
7
|
+
* These types model the document as a tree. Attributes belong to elements
|
|
8
|
+
* rather than appearing as child nodes. Text and CDATA remain distinct node
|
|
9
|
+
* kinds, and child order preserves mixed content.
|
|
10
|
+
*
|
|
11
|
+
* A document or element with `children` undefined has not had its children
|
|
12
|
+
* loaded. An empty array means its children have been loaded and it has none.
|
|
13
|
+
* These types describe the tree but do not enforce every XML validity rule.
|
|
14
|
+
*/
|
|
15
|
+
export type XmlNodePath = readonly number[];
|
|
16
|
+
/**
|
|
17
|
+
* Used by both XML attributes and elements.
|
|
18
|
+
*/
|
|
19
|
+
export type XmlName = {
|
|
20
|
+
qualifiedName: string;
|
|
21
|
+
localName: string;
|
|
22
|
+
prefix: string | null;
|
|
23
|
+
namespaceUri: string | null;
|
|
24
|
+
};
|
|
25
|
+
export type XmlDocument = {
|
|
26
|
+
kind: 'document';
|
|
27
|
+
children?: readonly XmlDocumentChild[];
|
|
28
|
+
};
|
|
29
|
+
export type XmlDeclaration = {
|
|
30
|
+
kind: 'declaration';
|
|
31
|
+
version: string;
|
|
32
|
+
encoding: string | null;
|
|
33
|
+
standalone: 'yes' | 'no' | null;
|
|
34
|
+
};
|
|
35
|
+
export type XmlDoctype = {
|
|
36
|
+
kind: 'doctype';
|
|
37
|
+
name: string;
|
|
38
|
+
publicId: string | null;
|
|
39
|
+
systemId: string | null;
|
|
40
|
+
internalSubset: string | null;
|
|
41
|
+
};
|
|
42
|
+
export type XmlAttribute = {
|
|
43
|
+
name: XmlName;
|
|
44
|
+
value: string;
|
|
45
|
+
};
|
|
46
|
+
export type XmlElement = {
|
|
47
|
+
kind: 'element';
|
|
48
|
+
name: XmlName;
|
|
49
|
+
attributes: readonly XmlAttribute[];
|
|
50
|
+
children?: readonly XmlElementChild[];
|
|
51
|
+
};
|
|
52
|
+
export type XmlText = {
|
|
53
|
+
kind: 'text';
|
|
54
|
+
text: string;
|
|
55
|
+
};
|
|
56
|
+
export type XmlCdata = {
|
|
57
|
+
kind: 'cdata';
|
|
58
|
+
text: string;
|
|
59
|
+
};
|
|
60
|
+
export type XmlComment = {
|
|
61
|
+
kind: 'comment';
|
|
62
|
+
text: string;
|
|
63
|
+
};
|
|
64
|
+
export type XmlProcessingInstruction = {
|
|
65
|
+
kind: 'processing-instruction';
|
|
66
|
+
target: string;
|
|
67
|
+
data: string;
|
|
68
|
+
};
|
|
69
|
+
export type XmlDocumentChild = XmlDeclaration | XmlDoctype | XmlElement | XmlText | XmlComment | XmlProcessingInstruction;
|
|
70
|
+
export type XmlElementChild = XmlElement | XmlText | XmlCdata | XmlComment | XmlProcessingInstruction;
|
|
71
|
+
export type XmlChildNode = XmlDocumentChild | XmlElementChild;
|
|
72
|
+
export type XmlNode = XmlDocument | XmlChildNode;
|
|
73
|
+
//# sourceMappingURL=xml-doc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xml-doc.d.ts","sourceRoot":"","sources":["../../src/domain/xml-doc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,MAAM,WAAW,GAAG,SAAS,MAAM,EAAE,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG;IACpB,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,CAAC,EAAE,SAAS,gBAAgB,EAAE,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,EAAE,KAAK,GAAG,IAAI,GAAG,IAAI,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B,CAAC;AAMF,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,SAAS,YAAY,EAAE,CAAC;IACpC,QAAQ,CAAC,EAAE,SAAS,eAAe,EAAE,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,EAAE,wBAAwB,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,gBAAgB,GACxB,cAAc,GACd,UAAU,GACV,UAAU,GACV,OAAO,GACP,UAAU,GACV,wBAAwB,CAAC;AAE7B,MAAM,MAAM,eAAe,GACvB,UAAU,GACV,OAAO,GACP,QAAQ,GACR,UAAU,GACV,wBAAwB,CAAC;AAE7B,MAAM,MAAM,YAAY,GAAG,gBAAgB,GAAG,eAAe,CAAC;AAC9D,MAAM,MAAM,OAAO,GAAG,WAAW,GAAG,YAAY,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An XML document contains one root element and may also contain an XML
|
|
3
|
+
* declaration, a doctype, comments, and processing instructions. Elements
|
|
4
|
+
* have attributes and ordered children; their children may include elements,
|
|
5
|
+
* text, CDATA, comments, and processing instructions.
|
|
6
|
+
*
|
|
7
|
+
* These types model the document as a tree. Attributes belong to elements
|
|
8
|
+
* rather than appearing as child nodes. Text and CDATA remain distinct node
|
|
9
|
+
* kinds, and child order preserves mixed content.
|
|
10
|
+
*
|
|
11
|
+
* A document or element with `children` undefined has not had its children
|
|
12
|
+
* loaded. An empty array means its children have been loaded and it has none.
|
|
13
|
+
* These types describe the tree but do not enforce every XML validity rule.
|
|
14
|
+
*/
|
|
15
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import type { TreeNode
|
|
2
|
+
import type { TreeNode } from 'dirvi-lib';
|
|
3
3
|
/**
|
|
4
4
|
* A node key containing its UUID and display name.
|
|
5
5
|
*
|
|
@@ -13,71 +13,55 @@ export type XmlId = z.infer<typeof xmlIdSchema>;
|
|
|
13
13
|
export declare function createXmlId(name: string, uuid: string): XmlId;
|
|
14
14
|
export declare function xmlIdName(id: XmlId): string;
|
|
15
15
|
export declare function xmlIdUuid(id: XmlId): string;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
readonly value: string;
|
|
19
|
-
}>;
|
|
20
|
-
export type XmlDocumentValue = Readonly<{
|
|
21
|
-
readonly kind: 'document';
|
|
22
|
-
}>;
|
|
23
|
-
export type XmlDeclarationValue = Readonly<{
|
|
24
|
-
readonly kind: 'declaration';
|
|
25
|
-
readonly version: string;
|
|
26
|
-
readonly encoding: string | null;
|
|
27
|
-
readonly standalone: 'yes' | 'no' | null;
|
|
28
|
-
}>;
|
|
29
|
-
export type XmlDoctypeValue = Readonly<{
|
|
30
|
-
readonly kind: 'doctype';
|
|
31
|
-
readonly name: string;
|
|
32
|
-
readonly publicId: string | null;
|
|
33
|
-
readonly systemId: string | null;
|
|
34
|
-
readonly internalSubset: string | null;
|
|
35
|
-
}>;
|
|
36
|
-
export type XmlElementValue = Readonly<{
|
|
37
|
-
readonly kind: 'element';
|
|
38
|
-
readonly name: string;
|
|
39
|
-
readonly attributes: readonly XmlAttribute[];
|
|
40
|
-
}>;
|
|
41
|
-
export type XmlTextValue = Readonly<{
|
|
42
|
-
readonly kind: 'text';
|
|
43
|
-
readonly text: string;
|
|
44
|
-
}>;
|
|
45
|
-
export type XmlCommentValue = Readonly<{
|
|
46
|
-
readonly kind: 'comment';
|
|
47
|
-
readonly text: string;
|
|
48
|
-
}>;
|
|
49
|
-
export type XmlCdataValue = Readonly<{
|
|
50
|
-
readonly kind: 'cdata';
|
|
51
|
-
readonly text: string;
|
|
52
|
-
}>;
|
|
53
|
-
export type XmlProcessingInstructionValue = Readonly<{
|
|
54
|
-
readonly kind: 'processing-instruction';
|
|
55
|
-
readonly target: string;
|
|
56
|
-
readonly data: string;
|
|
57
|
-
}>;
|
|
58
|
-
/**
|
|
59
|
-
* XML semantics carried by a generic tree node.
|
|
60
|
-
*
|
|
61
|
-
* Child ordering is deliberately not represented here.
|
|
62
|
-
*/
|
|
63
|
-
export type XmlNodeValue = XmlDocumentValue | XmlDeclarationValue | XmlDoctypeValue | XmlElementValue | XmlTextValue | XmlCommentValue | XmlCdataValue | XmlProcessingInstructionValue;
|
|
16
|
+
import type { XmlElementChild, XmlNode } from './xml-doc.js';
|
|
17
|
+
export type XmlNodeValue = XmlNode;
|
|
64
18
|
export type XmlTreeNode = TreeNode<XmlId, XmlNodeValue>;
|
|
65
|
-
export declare const
|
|
66
|
-
name: z.ZodString;
|
|
67
|
-
value: z.ZodString;
|
|
68
|
-
}, z.core.$strip>;
|
|
69
|
-
export declare const XmlDocumentValueSchema: z.ZodObject<{
|
|
19
|
+
export declare const xmlValueSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
70
20
|
kind: z.ZodLiteral<"document">;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
21
|
+
children: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
22
|
+
kind: z.ZodLiteral<"declaration">;
|
|
23
|
+
version: z.ZodString;
|
|
24
|
+
encoding: z.ZodNullable<z.ZodString>;
|
|
25
|
+
standalone: z.ZodNullable<z.ZodEnum<{
|
|
26
|
+
yes: "yes";
|
|
27
|
+
no: "no";
|
|
28
|
+
}>>;
|
|
29
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
30
|
+
kind: z.ZodLiteral<"doctype">;
|
|
76
31
|
name: z.ZodString;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
32
|
+
publicId: z.ZodNullable<z.ZodString>;
|
|
33
|
+
systemId: z.ZodNullable<z.ZodString>;
|
|
34
|
+
internalSubset: z.ZodNullable<z.ZodString>;
|
|
35
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
36
|
+
kind: z.ZodLiteral<"element">;
|
|
37
|
+
name: z.ZodObject<{
|
|
38
|
+
qualifiedName: z.ZodString;
|
|
39
|
+
localName: z.ZodString;
|
|
40
|
+
prefix: z.ZodNullable<z.ZodString>;
|
|
41
|
+
namespaceUri: z.ZodNullable<z.ZodString>;
|
|
42
|
+
}, z.core.$strip>;
|
|
43
|
+
attributes: z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
44
|
+
name: z.ZodObject<{
|
|
45
|
+
qualifiedName: z.ZodString;
|
|
46
|
+
localName: z.ZodString;
|
|
47
|
+
prefix: z.ZodNullable<z.ZodString>;
|
|
48
|
+
namespaceUri: z.ZodNullable<z.ZodString>;
|
|
49
|
+
}, z.core.$strip>;
|
|
50
|
+
value: z.ZodString;
|
|
51
|
+
}, z.core.$strip>>>;
|
|
52
|
+
children: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodType<XmlElementChild>>>>;
|
|
53
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
54
|
+
kind: z.ZodLiteral<"text">;
|
|
55
|
+
text: z.ZodString;
|
|
56
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
57
|
+
kind: z.ZodLiteral<"comment">;
|
|
58
|
+
text: z.ZodString;
|
|
59
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
60
|
+
kind: z.ZodLiteral<"processing-instruction">;
|
|
61
|
+
target: z.ZodString;
|
|
62
|
+
data: z.ZodString;
|
|
63
|
+
}, z.core.$strip>]>>>>;
|
|
64
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
81
65
|
kind: z.ZodLiteral<"declaration">;
|
|
82
66
|
version: z.ZodString;
|
|
83
67
|
encoding: z.ZodNullable<z.ZodString>;
|
|
@@ -85,62 +69,42 @@ export declare const XmlDeclarationValueSchema: z.ZodObject<{
|
|
|
85
69
|
yes: "yes";
|
|
86
70
|
no: "no";
|
|
87
71
|
}>>;
|
|
88
|
-
}, z.core.$strip
|
|
89
|
-
export declare const XmlDoctypeValueSchema: z.ZodObject<{
|
|
72
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
90
73
|
kind: z.ZodLiteral<"doctype">;
|
|
91
74
|
name: z.ZodString;
|
|
92
75
|
publicId: z.ZodNullable<z.ZodString>;
|
|
93
76
|
systemId: z.ZodNullable<z.ZodString>;
|
|
94
77
|
internalSubset: z.ZodNullable<z.ZodString>;
|
|
95
|
-
}, z.core.$strip>;
|
|
96
|
-
export declare const XmlTextValueSchema: z.ZodObject<{
|
|
97
|
-
kind: z.ZodLiteral<"text">;
|
|
98
|
-
text: z.ZodString;
|
|
99
|
-
}, z.core.$strip>;
|
|
100
|
-
export declare const XmlCommentValueSchema: z.ZodObject<{
|
|
101
|
-
kind: z.ZodLiteral<"comment">;
|
|
102
|
-
text: z.ZodString;
|
|
103
|
-
}, z.core.$strip>;
|
|
104
|
-
export declare const XmlCdataValueSchema: z.ZodObject<{
|
|
105
|
-
kind: z.ZodLiteral<"cdata">;
|
|
106
|
-
text: z.ZodString;
|
|
107
|
-
}, z.core.$strip>;
|
|
108
|
-
export declare const XmlProcessingInstructionValueSchema: z.ZodObject<{
|
|
109
|
-
kind: z.ZodLiteral<"processing-instruction">;
|
|
110
|
-
target: z.ZodString;
|
|
111
|
-
data: z.ZodString;
|
|
112
|
-
}, z.core.$strip>;
|
|
113
|
-
export declare const xmlValueSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
114
|
-
kind: z.ZodLiteral<"document">;
|
|
115
78
|
}, z.core.$strip>, z.ZodObject<{
|
|
116
79
|
kind: z.ZodLiteral<"element">;
|
|
117
|
-
name: z.
|
|
80
|
+
name: z.ZodObject<{
|
|
81
|
+
qualifiedName: z.ZodString;
|
|
82
|
+
localName: z.ZodString;
|
|
83
|
+
prefix: z.ZodNullable<z.ZodString>;
|
|
84
|
+
namespaceUri: z.ZodNullable<z.ZodString>;
|
|
85
|
+
}, z.core.$strip>;
|
|
118
86
|
attributes: z.ZodReadonly<z.ZodArray<z.ZodObject<{
|
|
119
|
-
name: z.
|
|
87
|
+
name: z.ZodObject<{
|
|
88
|
+
qualifiedName: z.ZodString;
|
|
89
|
+
localName: z.ZodString;
|
|
90
|
+
prefix: z.ZodNullable<z.ZodString>;
|
|
91
|
+
namespaceUri: z.ZodNullable<z.ZodString>;
|
|
92
|
+
}, z.core.$strip>;
|
|
120
93
|
value: z.ZodString;
|
|
121
94
|
}, z.core.$strip>>>;
|
|
95
|
+
children: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodType<XmlElementChild>>>>;
|
|
122
96
|
}, z.core.$strip>, z.ZodObject<{
|
|
123
97
|
kind: z.ZodLiteral<"text">;
|
|
124
98
|
text: z.ZodString;
|
|
125
99
|
}, z.core.$strip>, z.ZodObject<{
|
|
126
|
-
kind: z.ZodLiteral<"
|
|
100
|
+
kind: z.ZodLiteral<"cdata">;
|
|
127
101
|
text: z.ZodString;
|
|
128
102
|
}, z.core.$strip>, z.ZodObject<{
|
|
129
|
-
kind: z.ZodLiteral<"
|
|
103
|
+
kind: z.ZodLiteral<"comment">;
|
|
130
104
|
text: z.ZodString;
|
|
131
105
|
}, z.core.$strip>, z.ZodObject<{
|
|
132
106
|
kind: z.ZodLiteral<"processing-instruction">;
|
|
133
107
|
target: z.ZodString;
|
|
134
108
|
data: z.ZodString;
|
|
135
|
-
}, z.core.$strip>]
|
|
136
|
-
export declare function createConstructors(xmlTreeNodeApi: TreeMethods<XmlId, XmlNodeValue>): {
|
|
137
|
-
readonly document: (id: XmlId, children: Iterable<XmlTreeNode>) => XmlTreeNode | undefined;
|
|
138
|
-
readonly declaration: (id: XmlId, version: string, encoding: string | null, standalone: "yes" | "no" | null) => XmlTreeNode;
|
|
139
|
-
readonly doctype: (id: XmlId, name: string, publicId: string | null, systemId: string | null, internalSubset: string | null) => XmlTreeNode;
|
|
140
|
-
readonly element: (id: XmlId, name: string, attributes: readonly XmlAttribute[], children: Iterable<XmlTreeNode>) => XmlTreeNode | undefined;
|
|
141
|
-
readonly text: (id: XmlId, text: string) => XmlTreeNode;
|
|
142
|
-
readonly comment: (id: XmlId, text: string) => XmlTreeNode;
|
|
143
|
-
readonly cdata: (id: XmlId, text: string) => XmlTreeNode;
|
|
144
|
-
readonly processingInstruction: (id: XmlId, target: string, data: string) => XmlTreeNode;
|
|
145
|
-
};
|
|
109
|
+
}, z.core.$strip>]>;
|
|
146
110
|
//# sourceMappingURL=xml-tree.d.ts.map
|
|
@@ -1 +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,KAAK,EAAmB,QAAQ,EAAE,
|
|
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,KAAK,EAAmB,QAAQ,EAAE,MAAM,WAAW,CAAC;AAc3D;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,aAavB,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,WAAW,CAAC,CAAC;AAMhD,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,KAAK,CAE7D;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,KAAK,GAAG,MAAM,CAE3C;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,KAAK,GAAG,MAAM,CAE3C;AAKD,OAAO,KAAK,EAAc,eAAe,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEzE,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC;AACnC,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;AAqFxD,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBA7BT,CAAC,CAAC,gBAAgB,CAChC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CACtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAFe,CAAC,CAAC,gBAAgB,CAChC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC,CAAC,CACtD;;;;;;;;;;;;;;mBAoCiC,CAAC"}
|
package/dist/domain/xml-tree.js
CHANGED
|
@@ -28,113 +28,81 @@ export function xmlIdName(id) {
|
|
|
28
28
|
export function xmlIdUuid(id) {
|
|
29
29
|
return id.slice(0, id.indexOf(':'));
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
export const XmlDocumentValueSchema = z.object({
|
|
37
|
-
kind: z.literal('document'),
|
|
31
|
+
const xmlNameSchema = z.object({
|
|
32
|
+
qualifiedName: z.string(),
|
|
33
|
+
localName: z.string(),
|
|
34
|
+
prefix: z.string().nullable(),
|
|
35
|
+
namespaceUri: z.string().nullable(),
|
|
38
36
|
});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
attributes: z.array(XmlAttributeSchema).readonly(),
|
|
37
|
+
const xmlAttributeSchema = z.object({
|
|
38
|
+
name: xmlNameSchema,
|
|
39
|
+
value: z.string(),
|
|
43
40
|
});
|
|
44
|
-
|
|
41
|
+
const xmlDeclarationSchema = z.object({
|
|
45
42
|
kind: z.literal('declaration'),
|
|
46
43
|
version: z.string(),
|
|
47
44
|
encoding: z.string().nullable(),
|
|
48
45
|
standalone: z.enum(['yes', 'no']).nullable(),
|
|
49
46
|
});
|
|
50
|
-
|
|
47
|
+
const xmlDoctypeSchema = z.object({
|
|
51
48
|
kind: z.literal('doctype'),
|
|
52
49
|
name: z.string(),
|
|
53
50
|
publicId: z.string().nullable(),
|
|
54
51
|
systemId: z.string().nullable(),
|
|
55
52
|
internalSubset: z.string().nullable(),
|
|
56
53
|
});
|
|
57
|
-
|
|
54
|
+
const xmlTextSchema = z.object({
|
|
58
55
|
kind: z.literal('text'),
|
|
59
56
|
text: z.string(),
|
|
60
57
|
});
|
|
61
|
-
|
|
62
|
-
kind: z.literal('
|
|
58
|
+
const xmlCdataSchema = z.object({
|
|
59
|
+
kind: z.literal('cdata'),
|
|
63
60
|
text: z.string(),
|
|
64
61
|
});
|
|
65
|
-
|
|
66
|
-
kind: z.literal('
|
|
62
|
+
const xmlCommentSchema = z.object({
|
|
63
|
+
kind: z.literal('comment'),
|
|
67
64
|
text: z.string(),
|
|
68
65
|
});
|
|
69
|
-
|
|
66
|
+
const xmlProcessingInstructionSchema = z.object({
|
|
70
67
|
kind: z.literal('processing-instruction'),
|
|
71
|
-
target: z.string()
|
|
68
|
+
target: z.string(),
|
|
72
69
|
data: z.string(),
|
|
73
70
|
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
71
|
+
// Lazy because elements can contain other elements.
|
|
72
|
+
const xmlElementSchema = z.object({
|
|
73
|
+
kind: z.literal('element'),
|
|
74
|
+
name: xmlNameSchema,
|
|
75
|
+
attributes: z.array(xmlAttributeSchema).readonly(),
|
|
76
|
+
get children() {
|
|
77
|
+
return z.array(xmlElementChildSchema).readonly().exactOptional();
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
const xmlElementChildSchema = z.union([
|
|
81
|
+
xmlElementSchema,
|
|
82
|
+
xmlTextSchema,
|
|
83
|
+
xmlCdataSchema,
|
|
84
|
+
xmlCommentSchema,
|
|
85
|
+
xmlProcessingInstructionSchema,
|
|
86
|
+
]);
|
|
87
|
+
const xmlDocumentChildSchema = z.union([
|
|
88
|
+
xmlDeclarationSchema,
|
|
89
|
+
xmlDoctypeSchema,
|
|
90
|
+
xmlElementSchema,
|
|
91
|
+
xmlTextSchema,
|
|
92
|
+
xmlCommentSchema,
|
|
93
|
+
xmlProcessingInstructionSchema,
|
|
94
|
+
]);
|
|
95
|
+
const xmlDocumentSchema = z.object({
|
|
96
|
+
kind: z.literal('document'),
|
|
97
|
+
children: z.array(xmlDocumentChildSchema).readonly().exactOptional(),
|
|
98
|
+
});
|
|
99
|
+
export const xmlValueSchema = z.union([
|
|
100
|
+
xmlDocumentSchema,
|
|
101
|
+
xmlDeclarationSchema,
|
|
102
|
+
xmlDoctypeSchema,
|
|
103
|
+
xmlElementSchema,
|
|
104
|
+
xmlTextSchema,
|
|
105
|
+
xmlCdataSchema,
|
|
106
|
+
xmlCommentSchema,
|
|
107
|
+
xmlProcessingInstructionSchema,
|
|
81
108
|
]);
|
|
82
|
-
// -----------------------------------------------------------------------------
|
|
83
|
-
// XML domain constructors
|
|
84
|
-
// -----------------------------------------------------------------------------
|
|
85
|
-
export function createConstructors(xmlTreeNodeApi) {
|
|
86
|
-
return {
|
|
87
|
-
document(id, children) {
|
|
88
|
-
return xmlTreeNodeApi.createLoadedBranch(id, { kind: 'document' }, children);
|
|
89
|
-
},
|
|
90
|
-
declaration(id, version, encoding, standalone) {
|
|
91
|
-
return xmlTreeNodeApi.createLeaf(id, {
|
|
92
|
-
kind: 'declaration',
|
|
93
|
-
version,
|
|
94
|
-
encoding,
|
|
95
|
-
standalone,
|
|
96
|
-
});
|
|
97
|
-
},
|
|
98
|
-
doctype(id, name, publicId, systemId, internalSubset) {
|
|
99
|
-
return xmlTreeNodeApi.createLeaf(id, {
|
|
100
|
-
kind: 'doctype',
|
|
101
|
-
name,
|
|
102
|
-
publicId,
|
|
103
|
-
systemId,
|
|
104
|
-
internalSubset,
|
|
105
|
-
});
|
|
106
|
-
},
|
|
107
|
-
element(id, name, attributes, children) {
|
|
108
|
-
return xmlTreeNodeApi.createLoadedBranch(id, {
|
|
109
|
-
kind: 'element',
|
|
110
|
-
name,
|
|
111
|
-
attributes,
|
|
112
|
-
}, children);
|
|
113
|
-
},
|
|
114
|
-
text(id, text) {
|
|
115
|
-
return xmlTreeNodeApi.createLeaf(id, {
|
|
116
|
-
kind: 'text',
|
|
117
|
-
text,
|
|
118
|
-
});
|
|
119
|
-
},
|
|
120
|
-
comment(id, text) {
|
|
121
|
-
return xmlTreeNodeApi.createLeaf(id, {
|
|
122
|
-
kind: 'comment',
|
|
123
|
-
text,
|
|
124
|
-
});
|
|
125
|
-
},
|
|
126
|
-
cdata(id, text) {
|
|
127
|
-
return xmlTreeNodeApi.createLeaf(id, {
|
|
128
|
-
kind: 'cdata',
|
|
129
|
-
text,
|
|
130
|
-
});
|
|
131
|
-
},
|
|
132
|
-
processingInstruction(id, target, data) {
|
|
133
|
-
return xmlTreeNodeApi.createLeaf(id, {
|
|
134
|
-
kind: 'processing-instruction',
|
|
135
|
-
target,
|
|
136
|
-
data,
|
|
137
|
-
});
|
|
138
|
-
},
|
|
139
|
-
};
|
|
140
|
-
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-xml-dom.d.ts","sourceRoot":"","sources":["../../src/infrastructure/create-xml-dom.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AA+JrD;;GAEG;AACH,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,KAAG,MA6C7C,CAAC"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { DOMParser, Node, } from '@xmldom/xmldom';
|
|
2
|
+
/**
|
|
3
|
+
* Extract name for the domain type from xmldom.
|
|
4
|
+
* @param node
|
|
5
|
+
*/
|
|
6
|
+
const toXmlName = (node) => ({
|
|
7
|
+
qualifiedName: node.nodeName,
|
|
8
|
+
localName: node.localName ?? node.nodeName,
|
|
9
|
+
prefix: node.prefix || null,
|
|
10
|
+
namespaceUri: node.namespaceURI || null,
|
|
11
|
+
});
|
|
12
|
+
const getChildrenXmldomNode = (node) => {
|
|
13
|
+
const children = [];
|
|
14
|
+
for (let child = node.firstChild; child; child = child.nextSibling) {
|
|
15
|
+
children.push(child);
|
|
16
|
+
}
|
|
17
|
+
return children;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* xmldom uses a ProcessingInstruction node for the XML declaration.
|
|
21
|
+
* Map it to the domain's distinct XmlDeclaration type instead.
|
|
22
|
+
*/
|
|
23
|
+
const toXmlDeclaration = (node) => {
|
|
24
|
+
// xmldom represents the XML declaration as a processing instruction
|
|
25
|
+
// with target "xml". Our domain models it as a separate node kind with
|
|
26
|
+
// structured fields, so extract them from the instruction's data.
|
|
27
|
+
const fields = new Map();
|
|
28
|
+
// Match each field name and its quoted value. The closing quote (\2)
|
|
29
|
+
// must match the opening quote, allowing either single or double quotes.
|
|
30
|
+
for (const match of (node.data ?? '').matchAll(/(version|encoding|standalone)[\t\n\r ]*=[\t\n\r ]*(['"])(.*?)\2/g)) {
|
|
31
|
+
fields.set(match[1], match[3]);
|
|
32
|
+
}
|
|
33
|
+
const version = fields.get('version');
|
|
34
|
+
const standalone = fields.get('standalone');
|
|
35
|
+
if (!version ||
|
|
36
|
+
(standalone !== undefined && standalone !== 'yes' && standalone !== 'no')) {
|
|
37
|
+
throw new Error('Unsupported XML declaration');
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
kind: 'declaration',
|
|
41
|
+
version,
|
|
42
|
+
encoding: fields.get('encoding') ?? null,
|
|
43
|
+
standalone: standalone ?? null,
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Convert an xmldom doctype identifier to its unquoted domain value.
|
|
48
|
+
* An empty value represents an absent identifier.
|
|
49
|
+
*/
|
|
50
|
+
const unquoteDoctypeId = (value) => {
|
|
51
|
+
if (!value)
|
|
52
|
+
return null;
|
|
53
|
+
const quote = value[0];
|
|
54
|
+
if ((quote !== '"' && quote !== "'") || value[value.length - 1] !== quote) {
|
|
55
|
+
throw new Error(`Unexpected doctype identifier: ${value}`);
|
|
56
|
+
}
|
|
57
|
+
return value.slice(1, -1);
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Map an xmldom element and its attributes without loading its children.
|
|
61
|
+
*/
|
|
62
|
+
const toXmlElement = (node) => ({
|
|
63
|
+
kind: 'element',
|
|
64
|
+
name: toXmlName(node),
|
|
65
|
+
attributes: Array.from(node.attributes, (attribute) => ({
|
|
66
|
+
name: toXmlName(attribute),
|
|
67
|
+
value: attribute.value,
|
|
68
|
+
})),
|
|
69
|
+
});
|
|
70
|
+
const toXmlElementChild = (node) => {
|
|
71
|
+
switch (node.nodeType) {
|
|
72
|
+
case Node.ELEMENT_NODE:
|
|
73
|
+
return toXmlElement(node);
|
|
74
|
+
case Node.TEXT_NODE:
|
|
75
|
+
return { kind: 'text', text: node.nodeValue ?? '' };
|
|
76
|
+
case Node.CDATA_SECTION_NODE:
|
|
77
|
+
return { kind: 'cdata', text: node.nodeValue ?? '' };
|
|
78
|
+
case Node.COMMENT_NODE:
|
|
79
|
+
return { kind: 'comment', text: node.nodeValue ?? '' };
|
|
80
|
+
case Node.PROCESSING_INSTRUCTION_NODE: {
|
|
81
|
+
const instruction = node;
|
|
82
|
+
return {
|
|
83
|
+
kind: 'processing-instruction',
|
|
84
|
+
target: instruction.target,
|
|
85
|
+
data: instruction.data ?? '',
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
default:
|
|
89
|
+
throw new Error(`Unsupported XML element child type: ${node.nodeType}`);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const toXmlDocumentChild = (node) => {
|
|
93
|
+
switch (node.nodeType) {
|
|
94
|
+
case Node.ELEMENT_NODE:
|
|
95
|
+
return toXmlElement(node);
|
|
96
|
+
case Node.TEXT_NODE:
|
|
97
|
+
return { kind: 'text', text: node.nodeValue ?? '' };
|
|
98
|
+
case Node.COMMENT_NODE:
|
|
99
|
+
return { kind: 'comment', text: node.nodeValue ?? '' };
|
|
100
|
+
case Node.DOCUMENT_TYPE_NODE: {
|
|
101
|
+
const doctype = node;
|
|
102
|
+
return {
|
|
103
|
+
kind: 'doctype',
|
|
104
|
+
name: doctype.name,
|
|
105
|
+
publicId: unquoteDoctypeId(doctype.publicId),
|
|
106
|
+
systemId: unquoteDoctypeId(doctype.systemId),
|
|
107
|
+
internalSubset: doctype.internalSubset || null,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
case Node.PROCESSING_INSTRUCTION_NODE: {
|
|
111
|
+
const instruction = node;
|
|
112
|
+
// xmldom uses a ProcessingInstruction node for the XML declaration.
|
|
113
|
+
// Map it to the domain's distinct XmlDeclaration type instead.
|
|
114
|
+
if (instruction.target === 'xml') {
|
|
115
|
+
return toXmlDeclaration(instruction);
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
kind: 'processing-instruction',
|
|
119
|
+
target: instruction.target,
|
|
120
|
+
data: instruction.data ?? '',
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
default:
|
|
124
|
+
throw new Error(`Unsupported XML document child type: ${node.nodeType}`);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Creates the DOM service-level type.
|
|
129
|
+
*/
|
|
130
|
+
export const createXmlDom = (source) => {
|
|
131
|
+
const document = new DOMParser({
|
|
132
|
+
onError: (level, message) => {
|
|
133
|
+
if (level === 'error' || level === 'fatalError') {
|
|
134
|
+
throw new Error(message);
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
}).parseFromString(source, 'application/xml');
|
|
138
|
+
return {
|
|
139
|
+
getDocument: () => ({ kind: 'document' }),
|
|
140
|
+
getChildren: (path) => {
|
|
141
|
+
let node = document;
|
|
142
|
+
for (const index of path) {
|
|
143
|
+
if (node.nodeType !== Node.DOCUMENT_NODE &&
|
|
144
|
+
node.nodeType !== Node.ELEMENT_NODE) {
|
|
145
|
+
throw new Error(`XML path addresses a leaf: ${path.join(' / ')}`);
|
|
146
|
+
}
|
|
147
|
+
const child = getChildrenXmldomNode(node)[index];
|
|
148
|
+
if (!child) {
|
|
149
|
+
throw new Error(`XML path not found: ${path.join(' / ')}`);
|
|
150
|
+
}
|
|
151
|
+
node = child;
|
|
152
|
+
}
|
|
153
|
+
const children = getChildrenXmldomNode(node);
|
|
154
|
+
if (node.nodeType === Node.DOCUMENT_NODE) {
|
|
155
|
+
return children.map(toXmlDocumentChild);
|
|
156
|
+
}
|
|
157
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
158
|
+
return children.map(toXmlElementChild);
|
|
159
|
+
}
|
|
160
|
+
throw new Error(`XML path addresses a leaf: ${path.join(' / ')}`);
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { AppChild, AppRoot } from 'dirvi-apis';
|
|
2
|
+
import type { XmlDocument } from '../domain/xml-doc.js';
|
|
2
3
|
import type { XmlId, XmlNodeValue } from '../domain/xml-tree.js';
|
|
3
|
-
|
|
4
|
+
import { XmlDom } from '../services/xml-dom.js';
|
|
4
5
|
/**
|
|
5
|
-
* Returns direct children
|
|
6
|
-
* root; an empty path selects the document itself.
|
|
6
|
+
* Returns the direct children addressed by a dirvi path, in document order.
|
|
7
7
|
*/
|
|
8
|
-
export declare function getXmlEntries(filePath: string,
|
|
8
|
+
export declare function getXmlEntries(filePath: string, dom: XmlDom, path: readonly XmlId[]): readonly AppChild<XmlId, XmlNodeValue>[];
|
|
9
|
+
export declare function createXmlRoot(filePath: string, document: XmlDocument): AppRoot<XmlId, XmlNodeValue>;
|
|
9
10
|
//# sourceMappingURL=get-xml-entries.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-xml-entries.d.ts","sourceRoot":"","sources":["../../src/infrastructure/get-xml-entries.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-xml-entries.d.ts","sourceRoot":"","sources":["../../src/infrastructure/get-xml-entries.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,KAAK,EAAgB,WAAW,EAAe,MAAM,sBAAsB,CAAC;AACnF,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAEjE,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AA8DhD;;GAEG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,SAAS,KAAK,EAAE,GACrB,SAAS,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC,EAAE,CA0B1C;AAED,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,WAAW,GACpB,OAAO,CAAC,KAAK,EAAE,YAAY,CAAC,CAK9B"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import { parseXml, XmlCdata, XmlComment, XmlDeclaration, XmlDocumentType, XmlElement, XmlProcessingInstruction, XmlText, } from '@rgrove/parse-xml';
|
|
3
2
|
import { createXmlId } from '../domain/xml-tree.js';
|
|
4
3
|
// RFC 4122 URL namespace, used to derive deterministic version-5 UUIDs.
|
|
5
4
|
const uuidNamespace = Buffer.from('6ba7b8119dad11d180b400c04fd430c8', 'hex');
|
|
@@ -22,123 +21,54 @@ function nodeId(filePath, position, name) {
|
|
|
22
21
|
return createXmlId(name, uuid);
|
|
23
22
|
}
|
|
24
23
|
function nodeName(node) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
switch (node.kind) {
|
|
25
|
+
case 'element':
|
|
26
|
+
return node.name.qualifiedName;
|
|
27
|
+
case 'doctype':
|
|
28
|
+
return node.name;
|
|
29
|
+
case 'processing-instruction':
|
|
30
|
+
return node.target;
|
|
31
|
+
case 'declaration':
|
|
32
|
+
return '#declaration';
|
|
33
|
+
case 'text':
|
|
34
|
+
return '#text';
|
|
35
|
+
case 'cdata':
|
|
36
|
+
return '#cdata';
|
|
37
|
+
case 'comment':
|
|
38
|
+
return '#comment';
|
|
29
39
|
}
|
|
30
|
-
if (node instanceof XmlText)
|
|
31
|
-
return '#text';
|
|
32
|
-
if (node instanceof XmlCdata)
|
|
33
|
-
return '#cdata';
|
|
34
|
-
if (node instanceof XmlComment)
|
|
35
|
-
return '#comment';
|
|
36
|
-
if (node instanceof XmlDeclaration)
|
|
37
|
-
return '#declaration';
|
|
38
|
-
throw new Error(`Unsupported XML node type "${node.type}".`);
|
|
39
40
|
}
|
|
40
41
|
function describeChild(filePath, position, node) {
|
|
41
|
-
const id = nodeId(filePath, position, nodeName(node));
|
|
42
|
-
if (node instanceof XmlElement) {
|
|
43
|
-
return {
|
|
44
|
-
id,
|
|
45
|
-
kind: 'unloaded-branch',
|
|
46
|
-
value: {
|
|
47
|
-
kind: 'element',
|
|
48
|
-
name: node.name,
|
|
49
|
-
attributes: Object.entries(node.attributes).map(([name, value]) => ({
|
|
50
|
-
name,
|
|
51
|
-
value,
|
|
52
|
-
})),
|
|
53
|
-
},
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
if (node instanceof XmlText) {
|
|
57
|
-
return { id, kind: 'leaf', value: { kind: 'text', text: node.text } };
|
|
58
|
-
}
|
|
59
|
-
if (node instanceof XmlCdata) {
|
|
60
|
-
return { id, kind: 'leaf', value: { kind: 'cdata', text: node.text } };
|
|
61
|
-
}
|
|
62
|
-
if (node instanceof XmlComment) {
|
|
63
|
-
return {
|
|
64
|
-
id,
|
|
65
|
-
kind: 'leaf',
|
|
66
|
-
value: { kind: 'comment', text: node.content },
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
if (node instanceof XmlProcessingInstruction) {
|
|
70
|
-
return {
|
|
71
|
-
id,
|
|
72
|
-
kind: 'leaf',
|
|
73
|
-
value: {
|
|
74
|
-
kind: 'processing-instruction',
|
|
75
|
-
target: node.name,
|
|
76
|
-
data: node.content,
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
if (node instanceof XmlDeclaration) {
|
|
81
|
-
return {
|
|
82
|
-
id,
|
|
83
|
-
kind: 'leaf',
|
|
84
|
-
value: {
|
|
85
|
-
kind: 'declaration',
|
|
86
|
-
version: node.version,
|
|
87
|
-
encoding: node.encoding,
|
|
88
|
-
standalone: node.standalone,
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
if (node instanceof XmlDocumentType) {
|
|
93
|
-
return {
|
|
94
|
-
id,
|
|
95
|
-
kind: 'leaf',
|
|
96
|
-
value: {
|
|
97
|
-
kind: 'doctype',
|
|
98
|
-
name: node.name,
|
|
99
|
-
publicId: node.publicId,
|
|
100
|
-
systemId: node.systemId,
|
|
101
|
-
internalSubset: node.internalSubset,
|
|
102
|
-
},
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
throw new Error(`Unsupported XML node type "${node.type}".`);
|
|
106
|
-
}
|
|
107
|
-
export function createXmlRoot(filePath) {
|
|
108
42
|
return {
|
|
109
|
-
id: nodeId(filePath,
|
|
110
|
-
|
|
43
|
+
id: nodeId(filePath, position, nodeName(node)),
|
|
44
|
+
kind: node.kind === 'element' ? 'unloaded-branch' : 'leaf',
|
|
45
|
+
value: node,
|
|
111
46
|
};
|
|
112
47
|
}
|
|
113
48
|
/**
|
|
114
|
-
* Returns direct children
|
|
115
|
-
* root; an empty path selects the document itself.
|
|
49
|
+
* Returns the direct children addressed by a dirvi path, in document order.
|
|
116
50
|
*/
|
|
117
|
-
export function getXmlEntries(filePath,
|
|
118
|
-
const document = parseXml(source, {
|
|
119
|
-
preserveCdata: true,
|
|
120
|
-
preserveComments: true,
|
|
121
|
-
preserveDocumentType: true,
|
|
122
|
-
preserveXmlDeclaration: true,
|
|
123
|
-
});
|
|
124
|
-
let children = document.children;
|
|
51
|
+
export function getXmlEntries(filePath, dom, path) {
|
|
125
52
|
let position = [];
|
|
126
53
|
for (const segment of path) {
|
|
54
|
+
const children = dom.getChildren(position);
|
|
127
55
|
const index = children.findIndex((node, i) => nodeId(filePath, [...position, i], nodeName(node)) === segment);
|
|
128
56
|
if (index === -1) {
|
|
129
57
|
throw new Error(`XML path not found: ${path.join(' / ')}`);
|
|
130
58
|
}
|
|
131
59
|
const node = children[index];
|
|
132
|
-
if (!
|
|
60
|
+
if (!node || node.kind !== 'element') {
|
|
133
61
|
throw new Error(`XML path addresses a leaf: ${path.join(' / ')}`);
|
|
134
62
|
}
|
|
135
63
|
position = [...position, index];
|
|
136
|
-
children = node.children;
|
|
137
64
|
}
|
|
138
|
-
return
|
|
139
|
-
.
|
|
140
|
-
.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
65
|
+
return dom
|
|
66
|
+
.getChildren(position)
|
|
67
|
+
.map((node, index) => describeChild(filePath, [...position, index], node));
|
|
68
|
+
}
|
|
69
|
+
export function createXmlRoot(filePath, document) {
|
|
70
|
+
return {
|
|
71
|
+
id: nodeId(filePath, [], '#document'),
|
|
72
|
+
value: { kind: document.kind },
|
|
73
|
+
};
|
|
144
74
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { XmlDocument, XmlDocumentChild, XmlElementChild, XmlNodePath } from '../domain/xml-doc.js';
|
|
2
|
+
export type XmlDom = {
|
|
3
|
+
/**
|
|
4
|
+
* Loads the document and its direct children. Element descendants are not
|
|
5
|
+
* loaded: each direct child element has `children` undefined.
|
|
6
|
+
*/
|
|
7
|
+
getDocument: () => XmlDocument;
|
|
8
|
+
/**
|
|
9
|
+
* Loads the direct children of the document or an element.
|
|
10
|
+
* Child elements do not have their own children loaded.
|
|
11
|
+
*
|
|
12
|
+
* An empty path addresses the document. Each index selects a child in
|
|
13
|
+
* document order.
|
|
14
|
+
*/
|
|
15
|
+
getChildren: (path: XmlNodePath) => readonly (XmlDocumentChild | XmlElementChild)[];
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=xml-dom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"xml-dom.d.ts","sourceRoot":"","sources":["../../src/services/xml-dom.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExG,MAAM,MAAM,MAAM,GAAG;IACnB;;;OAGG;IACH,WAAW,EAAE,MAAM,WAAW,CAAC;IAE/B;;;;;;OAMG;IACH,WAAW,EAAE,CACX,IAAI,EAAE,WAAW,KACd,SAAS,CAAC,gBAAgB,GAAG,eAAe,CAAC,EAAE,CAAC;CACtD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xml-dirvi-app.d.ts","sourceRoot":"","sources":["../src/xml-dirvi-app.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"xml-dirvi-app.d.ts","sourceRoot":"","sources":["../src/xml-dirvi-app.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAiB,SAAS,EAAE,MAAM,YAAY,CAAC;AAS3D,eAAO,MAAM,YAAY,EAAE,SAsD1B,CAAC"}
|
package/dist/xml-dirvi-app.js
CHANGED
|
@@ -2,25 +2,47 @@ import { readFile } from 'node:fs/promises';
|
|
|
2
2
|
import { resolve } from 'node:path';
|
|
3
3
|
import { xmlIdSchema, xmlValueSchema } from './domain/xml-tree.js';
|
|
4
4
|
import { createXmlFileResyncSubscription } from './infrastructure/create-xml-file-resync.js';
|
|
5
|
-
import {
|
|
5
|
+
import { createXmlDom } from './infrastructure/create-xml-dom.js';
|
|
6
|
+
import { createXmlRoot, getXmlEntries } from './infrastructure/get-xml-entries.js';
|
|
6
7
|
export const xmlAppPlugin = {
|
|
7
8
|
createAppDefinitionApplicator: (input) => {
|
|
8
9
|
if (input === undefined) {
|
|
9
10
|
throw new Error('xml-dirvi-app: No file path to XML file given.');
|
|
10
11
|
}
|
|
11
12
|
const xmlAbsolutePath = resolve(input);
|
|
13
|
+
// Create dom async on first need, cache afterward
|
|
14
|
+
let dom;
|
|
15
|
+
let domPromise;
|
|
16
|
+
const getDom = async () => {
|
|
17
|
+
if (dom !== undefined) {
|
|
18
|
+
return dom;
|
|
19
|
+
}
|
|
20
|
+
if (domPromise === undefined) {
|
|
21
|
+
domPromise = readFile(xmlAbsolutePath, 'utf8')
|
|
22
|
+
.then((source) => {
|
|
23
|
+
dom = createXmlDom(source);
|
|
24
|
+
return dom;
|
|
25
|
+
})
|
|
26
|
+
.finally(() => {
|
|
27
|
+
domPromise = undefined;
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return domPromise;
|
|
31
|
+
};
|
|
12
32
|
const appDefinition = {
|
|
13
|
-
displayName: `XML: ${input}`,
|
|
14
33
|
semanticOrder: true,
|
|
15
34
|
idSchema: xmlIdSchema,
|
|
16
35
|
valueSchema: xmlValueSchema,
|
|
17
36
|
loadChildren: async (path) => {
|
|
18
|
-
const
|
|
19
|
-
return getXmlEntries(xmlAbsolutePath,
|
|
37
|
+
const dom = await getDom();
|
|
38
|
+
return getXmlEntries(xmlAbsolutePath, dom, path);
|
|
39
|
+
},
|
|
40
|
+
loadRoot: async () => {
|
|
41
|
+
const dom = await getDom();
|
|
42
|
+
return createXmlRoot(xmlAbsolutePath, dom.getDocument());
|
|
20
43
|
},
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
content: id.slice(id.indexOf(':') + 1),
|
|
44
|
+
presentNode: (_id, value, isBranch) => ({
|
|
45
|
+
content: value.kind,
|
|
24
46
|
highlight: isBranch ? 'branch' : 'leaf',
|
|
25
47
|
}),
|
|
26
48
|
subscribeToResync: createXmlFileResyncSubscription(xmlAbsolutePath),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mak-98/xml-dirvi-app",
|
|
3
|
-
"version": "0.11.0-beta.
|
|
3
|
+
"version": "0.11.0-beta.16",
|
|
4
4
|
"description": "XML file app for dirvi.",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"type": "module",
|
|
@@ -20,13 +20,14 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@rgrove/parse-xml": "^5.0.0",
|
|
23
|
-
"
|
|
23
|
+
"@xmldom/xmldom": "^0.9.12",
|
|
24
|
+
"dirvi-apis": "0.11.0-beta.16",
|
|
24
25
|
"env-paths": "^4.0.0",
|
|
25
26
|
"zod": "^4.4.3"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
|
-
"dirvi-lib": "0.11.0-beta.15",
|
|
29
29
|
"@types/node": "^22.0.0",
|
|
30
|
+
"dirvi-lib": "0.11.0-beta.16",
|
|
30
31
|
"typescript": "^5.0.0"
|
|
31
32
|
},
|
|
32
33
|
"scripts": {
|