@mak-98/xml-dirvi-app 0.11.0-beta.15.2 → 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.
@@ -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, TreeMethods } from 'dirvi-lib';
2
+ import type { TreeNode } from 'dirvi-lib';
3
3
  /**
4
4
  * A node key containing its UUID and display name.
5
5
  *
@@ -13,105 +13,54 @@ 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
- export type XmlAttribute = Readonly<{
17
- readonly name: string;
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 XmlAttributeSchema: z.ZodObject<{
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
- }, z.core.$strip>;
72
- export declare const XmlElementValueSchema: z.ZodObject<{
73
- kind: z.ZodLiteral<"element">;
74
- name: z.ZodString;
75
- attributes: z.ZodReadonly<z.ZodArray<z.ZodObject<{
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
- value: z.ZodString;
78
- }, z.core.$strip>>>;
79
- }, z.core.$strip>;
80
- export declare const XmlDeclarationValueSchema: z.ZodObject<{
81
- kind: z.ZodLiteral<"declaration">;
82
- version: z.ZodString;
83
- encoding: z.ZodNullable<z.ZodString>;
84
- standalone: z.ZodNullable<z.ZodEnum<{
85
- yes: "yes";
86
- no: "no";
87
- }>>;
88
- }, z.core.$strip>;
89
- export declare const XmlDoctypeValueSchema: z.ZodObject<{
90
- kind: z.ZodLiteral<"doctype">;
91
- name: z.ZodString;
92
- publicId: z.ZodNullable<z.ZodString>;
93
- systemId: z.ZodNullable<z.ZodString>;
94
- 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">;
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>]>>>>;
115
64
  }, z.core.$strip>, z.ZodObject<{
116
65
  kind: z.ZodLiteral<"declaration">;
117
66
  version: z.ZodString;
@@ -128,33 +77,34 @@ export declare const xmlValueSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
128
77
  internalSubset: z.ZodNullable<z.ZodString>;
129
78
  }, z.core.$strip>, z.ZodObject<{
130
79
  kind: z.ZodLiteral<"element">;
131
- name: z.ZodString;
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>;
132
86
  attributes: z.ZodReadonly<z.ZodArray<z.ZodObject<{
133
- name: z.ZodString;
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>;
134
93
  value: z.ZodString;
135
94
  }, z.core.$strip>>>;
95
+ children: z.ZodExactOptional<z.ZodReadonly<z.ZodArray<z.ZodType<XmlElementChild>>>>;
136
96
  }, z.core.$strip>, z.ZodObject<{
137
97
  kind: z.ZodLiteral<"text">;
138
98
  text: z.ZodString;
139
99
  }, z.core.$strip>, z.ZodObject<{
140
- kind: z.ZodLiteral<"comment">;
100
+ kind: z.ZodLiteral<"cdata">;
141
101
  text: z.ZodString;
142
102
  }, z.core.$strip>, z.ZodObject<{
143
- kind: z.ZodLiteral<"cdata">;
103
+ kind: z.ZodLiteral<"comment">;
144
104
  text: z.ZodString;
145
105
  }, z.core.$strip>, z.ZodObject<{
146
106
  kind: z.ZodLiteral<"processing-instruction">;
147
107
  target: z.ZodString;
148
108
  data: z.ZodString;
149
- }, z.core.$strip>], "kind">;
150
- export declare function createConstructors(xmlTreeNodeApi: TreeMethods<XmlId, XmlNodeValue>): {
151
- readonly document: (id: XmlId, children: Iterable<XmlTreeNode>) => XmlTreeNode | undefined;
152
- readonly declaration: (id: XmlId, version: string, encoding: string | null, standalone: "yes" | "no" | null) => XmlTreeNode;
153
- readonly doctype: (id: XmlId, name: string, publicId: string | null, systemId: string | null, internalSubset: string | null) => XmlTreeNode;
154
- readonly element: (id: XmlId, name: string, attributes: readonly XmlAttribute[], children: Iterable<XmlTreeNode>) => XmlTreeNode | undefined;
155
- readonly text: (id: XmlId, text: string) => XmlTreeNode;
156
- readonly comment: (id: XmlId, text: string) => XmlTreeNode;
157
- readonly cdata: (id: XmlId, text: string) => XmlTreeNode;
158
- readonly processingInstruction: (id: XmlId, target: string, data: string) => XmlTreeNode;
159
- };
109
+ }, z.core.$strip>]>;
160
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,WAAW,EAAE,MAAM,WAAW,CAAC;AAcxE;;;;;;;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;AAQD,MAAM,MAAM,YAAY,GAAG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,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"}
@@ -28,115 +28,81 @@ export function xmlIdName(id) {
28
28
  export function xmlIdUuid(id) {
29
29
  return id.slice(0, id.indexOf(':'));
30
30
  }
31
- // Schema ----------------------------------------------------------------------
32
- export const XmlAttributeSchema = z.object({
33
- name: z.string().min(1),
34
- value: z.string(),
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
- export const XmlElementValueSchema = z.object({
40
- kind: z.literal('element'),
41
- name: z.string().min(1),
42
- attributes: z.array(XmlAttributeSchema).readonly(),
37
+ const xmlAttributeSchema = z.object({
38
+ name: xmlNameSchema,
39
+ value: z.string(),
43
40
  });
44
- export const XmlDeclarationValueSchema = z.object({
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
- export const XmlDoctypeValueSchema = z.object({
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
- export const XmlTextValueSchema = z.object({
54
+ const xmlTextSchema = z.object({
58
55
  kind: z.literal('text'),
59
56
  text: z.string(),
60
57
  });
61
- export const XmlCommentValueSchema = z.object({
62
- kind: z.literal('comment'),
58
+ const xmlCdataSchema = z.object({
59
+ kind: z.literal('cdata'),
63
60
  text: z.string(),
64
61
  });
65
- export const XmlCdataValueSchema = z.object({
66
- kind: z.literal('cdata'),
62
+ const xmlCommentSchema = z.object({
63
+ kind: z.literal('comment'),
67
64
  text: z.string(),
68
65
  });
69
- export const XmlProcessingInstructionValueSchema = z.object({
66
+ const xmlProcessingInstructionSchema = z.object({
70
67
  kind: z.literal('processing-instruction'),
71
- target: z.string().min(1),
68
+ target: z.string(),
72
69
  data: z.string(),
73
70
  });
74
- export const xmlValueSchema = z.discriminatedUnion('kind', [
75
- XmlDocumentValueSchema,
76
- XmlDeclarationValueSchema,
77
- XmlDoctypeValueSchema,
78
- XmlElementValueSchema,
79
- XmlTextValueSchema,
80
- XmlCommentValueSchema,
81
- XmlCdataValueSchema,
82
- XmlProcessingInstructionValueSchema,
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,
83
108
  ]);
84
- // -----------------------------------------------------------------------------
85
- // XML domain constructors
86
- // -----------------------------------------------------------------------------
87
- export function createConstructors(xmlTreeNodeApi) {
88
- return {
89
- document(id, children) {
90
- return xmlTreeNodeApi.createLoadedBranch(id, { kind: 'document' }, children);
91
- },
92
- declaration(id, version, encoding, standalone) {
93
- return xmlTreeNodeApi.createLeaf(id, {
94
- kind: 'declaration',
95
- version,
96
- encoding,
97
- standalone,
98
- });
99
- },
100
- doctype(id, name, publicId, systemId, internalSubset) {
101
- return xmlTreeNodeApi.createLeaf(id, {
102
- kind: 'doctype',
103
- name,
104
- publicId,
105
- systemId,
106
- internalSubset,
107
- });
108
- },
109
- element(id, name, attributes, children) {
110
- return xmlTreeNodeApi.createLoadedBranch(id, {
111
- kind: 'element',
112
- name,
113
- attributes,
114
- }, children);
115
- },
116
- text(id, text) {
117
- return xmlTreeNodeApi.createLeaf(id, {
118
- kind: 'text',
119
- text,
120
- });
121
- },
122
- comment(id, text) {
123
- return xmlTreeNodeApi.createLeaf(id, {
124
- kind: 'comment',
125
- text,
126
- });
127
- },
128
- cdata(id, text) {
129
- return xmlTreeNodeApi.createLeaf(id, {
130
- kind: 'cdata',
131
- text,
132
- });
133
- },
134
- processingInstruction(id, target, data) {
135
- return xmlTreeNodeApi.createLeaf(id, {
136
- kind: 'processing-instruction',
137
- target,
138
- data,
139
- });
140
- },
141
- };
142
- }
@@ -0,0 +1,6 @@
1
+ import type { XmlDom } from '../services/xml-dom.js';
2
+ /**
3
+ * Creates the DOM service-level type.
4
+ */
5
+ export declare const createXmlDom: (source: string) => XmlDom;
6
+ //# sourceMappingURL=create-xml-dom.d.ts.map
@@ -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
- export declare function createXmlRoot(filePath: string): AppRoot<XmlId, XmlNodeValue>;
4
+ import { XmlDom } from '../services/xml-dom.js';
4
5
  /**
5
- * Returns direct children in parser order. Paths are relative to the document
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, source: string, path: readonly XmlId[]): readonly AppChild<XmlId, XmlNodeValue>[];
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":"AAaA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAoIjE,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,EAAE,YAAY,CAAC,CAK5E;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,KAAK,EAAE,GACrB,SAAS,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC,EAAE,CA2C1C"}
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,126 +21,54 @@ function nodeId(filePath, position, name) {
22
21
  return createXmlId(name, uuid);
23
22
  }
24
23
  function nodeName(node) {
25
- if (node instanceof XmlElement ||
26
- node instanceof XmlProcessingInstruction ||
27
- node instanceof XmlDocumentType) {
28
- return node.name;
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 XmlCdata)
31
- return '#cdata';
32
- if (node instanceof XmlText)
33
- return '#text';
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: node.attributes['xml:space'] === 'preserve'
46
- ? 'leaf'
47
- : 'unloaded-branch',
48
- value: {
49
- kind: 'element',
50
- name: node.name,
51
- attributes: Object.entries(node.attributes).map(([name, value]) => ({
52
- name,
53
- value,
54
- })),
55
- },
56
- };
57
- }
58
- if (node instanceof XmlCdata) {
59
- return { id, kind: 'leaf', value: { kind: 'cdata', text: node.text } };
60
- }
61
- if (node instanceof XmlText) {
62
- return { id, kind: 'leaf', value: { kind: 'text', text: node.text } };
63
- }
64
- if (node instanceof XmlComment) {
65
- return {
66
- id,
67
- kind: 'leaf',
68
- value: { kind: 'comment', text: node.content },
69
- };
70
- }
71
- if (node instanceof XmlProcessingInstruction) {
72
- return {
73
- id,
74
- kind: 'leaf',
75
- value: {
76
- kind: 'processing-instruction',
77
- target: node.name,
78
- data: node.content,
79
- },
80
- };
81
- }
82
- if (node instanceof XmlDeclaration) {
83
- return {
84
- id,
85
- kind: 'leaf',
86
- value: {
87
- kind: 'declaration',
88
- version: node.version,
89
- encoding: node.encoding,
90
- standalone: node.standalone,
91
- },
92
- };
93
- }
94
- if (node instanceof XmlDocumentType) {
95
- return {
96
- id,
97
- kind: 'leaf',
98
- value: {
99
- kind: 'doctype',
100
- name: node.name,
101
- publicId: node.publicId,
102
- systemId: node.systemId,
103
- internalSubset: node.internalSubset,
104
- },
105
- };
106
- }
107
- throw new Error(`Unsupported XML node type "${node.type}".`);
108
- }
109
- export function createXmlRoot(filePath) {
110
42
  return {
111
- id: nodeId(filePath, [], '#document'),
112
- value: { kind: 'document' },
43
+ id: nodeId(filePath, position, nodeName(node)),
44
+ kind: node.kind === 'element' ? 'unloaded-branch' : 'leaf',
45
+ value: node,
113
46
  };
114
47
  }
115
48
  /**
116
- * Returns direct children in parser order. Paths are relative to the document
117
- * root; an empty path selects the document itself.
49
+ * Returns the direct children addressed by a dirvi path, in document order.
118
50
  */
119
- export function getXmlEntries(filePath, source, path) {
120
- const document = parseXml(source, {
121
- preserveCdata: true,
122
- preserveComments: true,
123
- preserveDocumentType: true,
124
- preserveXmlDeclaration: true,
125
- });
126
- let children = document.children;
51
+ export function getXmlEntries(filePath, dom, path) {
127
52
  let position = [];
128
53
  for (const segment of path) {
54
+ const children = dom.getChildren(position);
129
55
  const index = children.findIndex((node, i) => nodeId(filePath, [...position, i], nodeName(node)) === segment);
130
56
  if (index === -1) {
131
57
  throw new Error(`XML path not found: ${path.join(' / ')}`);
132
58
  }
133
59
  const node = children[index];
134
- if (!(node instanceof XmlElement)) {
60
+ if (!node || node.kind !== 'element') {
135
61
  throw new Error(`XML path addresses a leaf: ${path.join(' / ')}`);
136
62
  }
137
63
  position = [...position, index];
138
- children = node.children;
139
64
  }
140
- return children
141
- .map((node, index) => ({ node, index }))
142
- .filter(({ node }) => !(node instanceof XmlText &&
143
- !(node instanceof XmlCdata) &&
144
- !node.preserveWhitespace &&
145
- /^[\t\n\r ]*$/.test(node.text)))
146
- .map(({ node, index }) => describeChild(filePath, [...position, index], node));
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
+ };
147
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;AAU3D,eAAO,MAAM,YAAY,EAAE,SA8B1B,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"}
@@ -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 { createXmlRoot, getXmlEntries, } from './infrastructure/get-xml-entries.js';
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 source = await readFile(xmlAbsolutePath, 'utf8');
19
- return getXmlEntries(xmlAbsolutePath, source, path);
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
- loadRoot: async () => createXmlRoot(xmlAbsolutePath),
22
- presentNode: (id, isBranch) => ({
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.15.2",
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
- "dirvi-apis": "0.11.0-beta.15",
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": {