@mak-98/xml-dirvi-app 0.11.0-beta.2 → 0.11.0-beta.20

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.
Files changed (32) hide show
  1. package/README.md +122 -0
  2. package/dist/domain/xml-doc.d.ts +73 -0
  3. package/dist/domain/xml-doc.d.ts.map +1 -0
  4. package/dist/domain/xml-doc.js +15 -0
  5. package/dist/domain/xml-tree.d.ts +83 -249
  6. package/dist/domain/xml-tree.d.ts.map +1 -1
  7. package/dist/domain/xml-tree.js +63 -96
  8. package/dist/index.d.ts +2 -2
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +2 -2
  11. package/dist/infrastructure/create-xml-dom.d.ts +6 -0
  12. package/dist/infrastructure/create-xml-dom.d.ts.map +1 -0
  13. package/dist/infrastructure/create-xml-dom.js +166 -0
  14. package/dist/infrastructure/create-xml-file-resync.d.ts +2 -0
  15. package/dist/infrastructure/create-xml-file-resync.d.ts.map +1 -0
  16. package/dist/infrastructure/create-xml-file-resync.js +68 -0
  17. package/dist/infrastructure/get-xml-entries.d.ts +1 -18
  18. package/dist/infrastructure/get-xml-entries.d.ts.map +1 -1
  19. package/dist/infrastructure/get-xml-entries.js +118 -44
  20. package/dist/infrastructure/load-node-xml-app-api.d.ts +1 -0
  21. package/dist/infrastructure/load-node-xml-app-api.d.ts.map +1 -1
  22. package/dist/infrastructure/load-node-xml-app-api.js +7 -3
  23. package/dist/infrastructure/parse-xml-document.d.ts +6 -4
  24. package/dist/infrastructure/parse-xml-document.d.ts.map +1 -1
  25. package/dist/infrastructure/parse-xml-document.js +9 -12
  26. package/dist/services/xml-dom.d.ts +16 -0
  27. package/dist/services/xml-dom.d.ts.map +1 -0
  28. package/dist/services/xml-dom.js +1 -0
  29. package/dist/xml-dirvi-app.d.ts +2 -5
  30. package/dist/xml-dirvi-app.d.ts.map +1 -1
  31. package/dist/xml-dirvi-app.js +53 -13
  32. package/package.json +4 -3
@@ -1,112 +1,79 @@
1
1
  import { z } from 'zod';
2
- import { createCursorApi, createCursorSchema, createFoldsApi, createNavNodeApi, createStateApi, createTreeNodeApi, } from 'dirvi-lib';
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),
2
+ const xmlNameSchema = z.object({
3
+ qualifiedName: z.string(),
4
+ localName: z.string(),
5
+ prefix: z.string().nullable(),
6
+ namespaceUri: z.string().nullable(),
7
+ });
8
+ const xmlAttributeSchema = z.object({
9
+ name: xmlNameSchema,
10
10
  value: z.string(),
11
11
  });
12
- export const XmlDocumentValueSchema = z.object({
13
- kind: z.literal('document'),
12
+ const xmlDeclarationSchema = z.object({
13
+ kind: z.literal('declaration'),
14
+ version: z.string(),
15
+ encoding: z.string().nullable(),
16
+ standalone: z.enum(['yes', 'no']).nullable(),
14
17
  });
15
- export const XmlElementValueSchema = z.object({
16
- kind: z.literal('element'),
17
- name: z.string().min(1),
18
- attributes: z.array(XmlAttributeSchema).readonly(),
18
+ const xmlDoctypeSchema = z.object({
19
+ kind: z.literal('doctype'),
20
+ name: z.string(),
21
+ publicId: z.string().nullable(),
22
+ systemId: z.string().nullable(),
23
+ internalSubset: z.string().nullable(),
19
24
  });
20
- // TODO: add declaration and doctype when schema is needed
21
- export const XmlTextValueSchema = z.object({
25
+ const xmlTextSchema = z.object({
22
26
  kind: z.literal('text'),
23
27
  text: z.string(),
24
28
  });
25
- export const XmlCommentValueSchema = z.object({
26
- kind: z.literal('comment'),
29
+ const xmlCdataSchema = z.object({
30
+ kind: z.literal('cdata'),
27
31
  text: z.string(),
28
32
  });
29
- export const XmlCdataValueSchema = z.object({
30
- kind: z.literal('cdata'),
33
+ const xmlCommentSchema = z.object({
34
+ kind: z.literal('comment'),
31
35
  text: z.string(),
32
36
  });
33
- export const XmlProcessingInstructionValueSchema = z.object({
37
+ const xmlProcessingInstructionSchema = z.object({
34
38
  kind: z.literal('processing-instruction'),
35
- target: z.string().min(1),
39
+ target: z.string(),
36
40
  data: z.string(),
37
41
  });
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
- });
42
+ // Lazy because elements can contain other elements.
43
+ const xmlElementSchema = z.object({
44
+ kind: z.literal('element'),
45
+ name: xmlNameSchema,
46
+ attributes: z.array(xmlAttributeSchema).readonly(),
47
+ get children() {
48
+ return z.array(xmlElementChildSchema).readonly().exactOptional();
102
49
  },
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);
50
+ });
51
+ const xmlElementChildSchema = z.union([
52
+ xmlElementSchema,
53
+ xmlTextSchema,
54
+ xmlCdataSchema,
55
+ xmlCommentSchema,
56
+ xmlProcessingInstructionSchema,
57
+ ]);
58
+ const xmlDocumentChildSchema = z.union([
59
+ xmlDeclarationSchema,
60
+ xmlDoctypeSchema,
61
+ xmlElementSchema,
62
+ xmlTextSchema,
63
+ xmlCommentSchema,
64
+ xmlProcessingInstructionSchema,
65
+ ]);
66
+ const xmlDocumentSchema = z.object({
67
+ kind: z.literal('document'),
68
+ children: z.array(xmlDocumentChildSchema).readonly().exactOptional(),
69
+ });
70
+ export const xmlValueSchema = z.union([
71
+ xmlDocumentSchema,
72
+ xmlDeclarationSchema,
73
+ xmlDoctypeSchema,
74
+ xmlElementSchema,
75
+ xmlTextSchema,
76
+ xmlCdataSchema,
77
+ xmlCommentSchema,
78
+ xmlProcessingInstructionSchema,
79
+ ]);
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { xmlAppPlugin as default } from './xml-dirvi-app.js';
2
- export { xmlAppPlugin } from './xml-dirvi-app.js';
1
+ export { xmlApp as default } from './xml-dirvi-app.js';
2
+ export { xmlApp } from './xml-dirvi-app.js';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export { xmlAppPlugin as default } from './xml-dirvi-app.js';
2
- export { xmlAppPlugin } from './xml-dirvi-app.js';
1
+ export { xmlApp as default } from './xml-dirvi-app.js';
2
+ export { xmlApp } from './xml-dirvi-app.js';
@@ -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":"AAkBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAiKrD;;GAEG;AACH,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,KAAG,MA4C7C,CAAC"}
@@ -0,0 +1,166 @@
1
+ import { DOMParser, Node, } from '@xmldom/xmldom';
2
+ const createXmlId = (node) => node;
3
+ /**
4
+ * Extract name for the domain type from xmldom.
5
+ * @param node
6
+ */
7
+ const toXmlName = (node) => ({
8
+ qualifiedName: node.nodeName,
9
+ localName: node.localName ?? node.nodeName,
10
+ prefix: node.prefix || null,
11
+ namespaceUri: node.namespaceURI || null,
12
+ });
13
+ const getChildrenXmldomNode = (node) => {
14
+ const children = [];
15
+ for (let child = node.firstChild; child; child = child.nextSibling) {
16
+ children.push(child);
17
+ }
18
+ return children;
19
+ };
20
+ /**
21
+ * xmldom uses a ProcessingInstruction node for the XML declaration.
22
+ * Map it to the domain's distinct XmlDeclaration type instead.
23
+ */
24
+ const toXmlDeclaration = (node) => {
25
+ // xmldom represents the XML declaration as a processing instruction
26
+ // with target "xml". Our domain models it as a separate node kind with
27
+ // structured fields, so extract them from the instruction's data.
28
+ const fields = new Map();
29
+ // Match each field name and its quoted value. The closing quote (\2)
30
+ // must match the opening quote, allowing either single or double quotes.
31
+ for (const match of (node.data ?? '').matchAll(/(version|encoding|standalone)[\t\n\r ]*=[\t\n\r ]*(['"])(.*?)\2/g)) {
32
+ fields.set(match[1], match[3]);
33
+ }
34
+ const version = fields.get('version');
35
+ const standalone = fields.get('standalone');
36
+ if (!version ||
37
+ (standalone !== undefined && standalone !== 'yes' && standalone !== 'no')) {
38
+ throw new Error('Unsupported XML declaration');
39
+ }
40
+ return {
41
+ kind: 'declaration',
42
+ version,
43
+ encoding: fields.get('encoding') ?? null,
44
+ standalone: standalone ?? null,
45
+ };
46
+ };
47
+ /**
48
+ * Convert an xmldom doctype identifier to its unquoted domain value.
49
+ * An empty value represents an absent identifier.
50
+ */
51
+ const unquoteDoctypeId = (value) => {
52
+ if (!value)
53
+ return null;
54
+ const quote = value[0];
55
+ if ((quote !== '"' && quote !== "'") || value[value.length - 1] !== quote) {
56
+ throw new Error(`Unexpected doctype identifier: ${value}`);
57
+ }
58
+ return value.slice(1, -1);
59
+ };
60
+ /**
61
+ * Map an xmldom element and its attributes without loading its children.
62
+ */
63
+ const toXmlElement = (node) => ({
64
+ kind: 'element',
65
+ name: toXmlName(node),
66
+ attributes: Array.from(node.attributes, (attribute) => ({
67
+ name: toXmlName(attribute),
68
+ value: attribute.value,
69
+ })),
70
+ });
71
+ const toXmlElementChild = (node) => {
72
+ switch (node.nodeType) {
73
+ case Node.ELEMENT_NODE:
74
+ return toXmlElement(node);
75
+ case Node.TEXT_NODE:
76
+ return { kind: 'text', text: node.nodeValue ?? '' };
77
+ case Node.CDATA_SECTION_NODE:
78
+ return { kind: 'cdata', text: node.nodeValue ?? '' };
79
+ case Node.COMMENT_NODE:
80
+ return { kind: 'comment', text: node.nodeValue ?? '' };
81
+ case Node.PROCESSING_INSTRUCTION_NODE: {
82
+ const instruction = node;
83
+ return {
84
+ kind: 'processing-instruction',
85
+ target: instruction.target,
86
+ data: instruction.data ?? '',
87
+ };
88
+ }
89
+ default:
90
+ throw new Error(`Unsupported XML element child type: ${node.nodeType}`);
91
+ }
92
+ };
93
+ const toXmlDocumentChild = (node) => {
94
+ switch (node.nodeType) {
95
+ case Node.ELEMENT_NODE:
96
+ return toXmlElement(node);
97
+ case Node.TEXT_NODE:
98
+ return { kind: 'text', text: node.nodeValue ?? '' };
99
+ case Node.COMMENT_NODE:
100
+ return { kind: 'comment', text: node.nodeValue ?? '' };
101
+ case Node.DOCUMENT_TYPE_NODE: {
102
+ const doctype = node;
103
+ return {
104
+ kind: 'doctype',
105
+ name: doctype.name,
106
+ publicId: unquoteDoctypeId(doctype.publicId),
107
+ systemId: unquoteDoctypeId(doctype.systemId),
108
+ internalSubset: doctype.internalSubset || null,
109
+ };
110
+ }
111
+ case Node.PROCESSING_INSTRUCTION_NODE: {
112
+ const instruction = node;
113
+ // xmldom uses a ProcessingInstruction node for the XML declaration.
114
+ // Map it to the domain's distinct XmlDeclaration type instead.
115
+ if (instruction.target === 'xml') {
116
+ return toXmlDeclaration(instruction);
117
+ }
118
+ return {
119
+ kind: 'processing-instruction',
120
+ target: instruction.target,
121
+ data: instruction.data ?? '',
122
+ };
123
+ }
124
+ default:
125
+ throw new Error(`Unsupported XML document child type: ${node.nodeType}`);
126
+ }
127
+ };
128
+ /**
129
+ * Creates the DOM service-level type.
130
+ */
131
+ export const createXmlDom = (source) => {
132
+ const document = new DOMParser({
133
+ onError: (level, message) => {
134
+ if (level === 'error' || level === 'fatalError') {
135
+ throw new Error(message);
136
+ }
137
+ },
138
+ }).parseFromString(source, 'application/xml');
139
+ return {
140
+ getDocument: () => ({
141
+ id: createXmlId(document),
142
+ value: { kind: 'document' },
143
+ }),
144
+ getChildren: (id) => {
145
+ const node = id === undefined ? document : id;
146
+ // Reject detached nodes and nodes from another document.
147
+ let current = node;
148
+ while (current && current !== document) {
149
+ current = current.parentNode;
150
+ }
151
+ if (current !== document) {
152
+ throw new Error('XML node does not belong to the current document');
153
+ }
154
+ if (node.nodeType !== Node.DOCUMENT_NODE &&
155
+ node.nodeType !== Node.ELEMENT_NODE) {
156
+ throw new Error('XML node is a leaf');
157
+ }
158
+ return getChildrenXmldomNode(node).map((child) => ({
159
+ id: createXmlId(child),
160
+ value: node.nodeType === Node.DOCUMENT_NODE
161
+ ? toXmlDocumentChild(child)
162
+ : toXmlElementChild(child),
163
+ }));
164
+ },
165
+ };
166
+ };
@@ -0,0 +1,2 @@
1
+ export declare function createXmlFileResyncSubscription(xmlAbsolutePath: string): (listener: () => void) => () => void;
2
+ //# sourceMappingURL=create-xml-file-resync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-xml-file-resync.d.ts","sourceRoot":"","sources":["../../src/infrastructure/create-xml-file-resync.ts"],"names":[],"mappings":"AAGA,wBAAgB,+BAA+B,CAC7C,eAAe,EAAE,MAAM,GACtB,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAiFtC"}
@@ -0,0 +1,68 @@
1
+ import { watch } from 'node:fs';
2
+ import { basename, dirname } from 'node:path';
3
+ export function createXmlFileResyncSubscription(xmlAbsolutePath) {
4
+ const listeners = new Set();
5
+ const parentDirectory = dirname(xmlAbsolutePath);
6
+ const fileName = basename(xmlAbsolutePath);
7
+ let watcher;
8
+ let notificationTimer;
9
+ function notifyListeners() {
10
+ for (const listener of listeners) {
11
+ listener();
12
+ }
13
+ }
14
+ function scheduleNotification() {
15
+ if (notificationTimer !== undefined) {
16
+ clearTimeout(notificationTimer);
17
+ }
18
+ notificationTimer = setTimeout(() => {
19
+ notificationTimer = undefined;
20
+ if (listeners.size > 0) {
21
+ notifyListeners();
22
+ }
23
+ }, 100);
24
+ }
25
+ function startWatcher() {
26
+ if (watcher !== undefined) {
27
+ return;
28
+ }
29
+ watcher = watch(parentDirectory, (_eventType, changedName) => {
30
+ /*
31
+ * A null filename means the platform could not identify the changed
32
+ * entry. Conservatively resync in that case.
33
+ */
34
+ if (changedName === null || changedName.toString() === fileName) {
35
+ scheduleNotification();
36
+ }
37
+ });
38
+ watcher.on('error', () => {
39
+ /*
40
+ * The next createRoot() call will report the filesystem or XML parsing
41
+ * failure through normal application error handling.
42
+ */
43
+ });
44
+ }
45
+ function stopWatcher() {
46
+ if (notificationTimer !== undefined) {
47
+ clearTimeout(notificationTimer);
48
+ notificationTimer = undefined;
49
+ }
50
+ watcher?.close();
51
+ watcher = undefined;
52
+ }
53
+ return (listener) => {
54
+ listeners.add(listener);
55
+ startWatcher();
56
+ let subscribed = true;
57
+ return () => {
58
+ if (!subscribed) {
59
+ return;
60
+ }
61
+ subscribed = false;
62
+ listeners.delete(listener);
63
+ if (listeners.size === 0) {
64
+ stopWatcher();
65
+ }
66
+ };
67
+ };
68
+ }
@@ -1,19 +1,2 @@
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[];
1
+ export {};
19
2
  //# 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":"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"}
1
+ {"version":3,"file":"get-xml-entries.d.ts","sourceRoot":"","sources":["../../src/infrastructure/get-xml-entries.ts"],"names":[],"mappings":""}
@@ -1,44 +1,118 @@
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
- }
1
+ export {};
2
+ // import { createHash } from 'node:crypto';
3
+ //
4
+ // import type { AppChild, AppRoot } from 'dirvi-apis';
5
+ //
6
+ // import type {
7
+ // XmlChildNode,
8
+ // XmlDocument,
9
+ // XmlNodePath,
10
+ // } from '../domain/xml-doc.js';
11
+ // import type { XmlId, XmlNodeValue } from '../domain/xml-tree.js';
12
+ // import { createXmlId } from '../domain/xml-tree.js';
13
+ // import { XmlDom } from '../services/xml-dom.js';
14
+ //
15
+ // // RFC 4122 URL namespace, used to derive deterministic version-5 UUIDs.
16
+ // const uuidNamespace = Buffer.from('6ba7b8119dad11d180b400c04fd430c8', 'hex');
17
+ //
18
+ // function nodeId(
19
+ // filePath: string,
20
+ // position: readonly number[],
21
+ // name: string,
22
+ // ): XmlId {
23
+ // const hash = createHash('sha1')
24
+ // .update(uuidNamespace)
25
+ // .update(JSON.stringify([filePath, position, name]), 'utf8')
26
+ // .digest();
27
+ //
28
+ // const bytes = Buffer.from(hash.subarray(0, 16));
29
+ // bytes[6] = (bytes[6]! & 0x0f) | 0x50; // UUID version 5
30
+ // bytes[8] = (bytes[8]! & 0x3f) | 0x80; // RFC variant
31
+ //
32
+ // const hex = bytes.toString('hex');
33
+ // const uuid = [
34
+ // hex.slice(0, 8),
35
+ // hex.slice(8, 12),
36
+ // hex.slice(12, 16),
37
+ // hex.slice(16, 20),
38
+ // hex.slice(20, 32),
39
+ // ].join('-');
40
+ //
41
+ // return createXmlId(name, uuid);
42
+ // }
43
+ //
44
+ // function nodeName(node: XmlChildNode): string {
45
+ // switch (node.kind) {
46
+ // case 'element':
47
+ // return node.name.qualifiedName;
48
+ // case 'doctype':
49
+ // return node.name;
50
+ // case 'processing-instruction':
51
+ // return node.target;
52
+ // case 'declaration':
53
+ // return '#declaration';
54
+ // case 'text':
55
+ // return '#text';
56
+ // case 'cdata':
57
+ // return '#cdata';
58
+ // case 'comment':
59
+ // return '#comment';
60
+ // }
61
+ // }
62
+ //
63
+ // function describeChild(
64
+ // filePath: string,
65
+ // position: XmlNodePath,
66
+ // node: XmlChildNode,
67
+ // ): AppChild<XmlId, XmlNodeValue> {
68
+ // return {
69
+ // id: nodeId(filePath, position, nodeName(node)),
70
+ // kind: node.kind === 'element' ? 'unloaded-branch' : 'leaf',
71
+ // value: node,
72
+ // };
73
+ // }
74
+ //
75
+ // /**
76
+ // * Returns the direct children addressed by a dirvi path, in document order.
77
+ // */
78
+ // export function getXmlEntries(
79
+ // filePath: string,
80
+ // dom: XmlDom,
81
+ // path: readonly XmlId[],
82
+ // ): readonly AppChild<XmlId, XmlNodeValue>[] {
83
+ // let position: XmlNodePath = [];
84
+ //
85
+ // for (const segment of path) {
86
+ // const children = dom.getChildren(position);
87
+ // const index = children.findIndex(
88
+ // (node, i) =>
89
+ // nodeId(filePath, [...position, i], nodeName(node)) === segment,
90
+ // );
91
+ //
92
+ // if (index === -1) {
93
+ // throw new Error(`XML path not found: ${path.join(' / ')}`);
94
+ // }
95
+ //
96
+ // const node = children[index];
97
+ //
98
+ // if (!node || node.kind !== 'element') {
99
+ // throw new Error(`XML path addresses a leaf: ${path.join(' / ')}`);
100
+ // }
101
+ //
102
+ // position = [...position, index];
103
+ // }
104
+ //
105
+ // return dom
106
+ // .getChildren(position)
107
+ // .map((node, index) => describeChild(filePath, [...position, index], node));
108
+ // }
109
+ //
110
+ // export function createXmlRoot(
111
+ // filePath: string,
112
+ // document: XmlDocument,
113
+ // ): AppRoot<XmlId, XmlNodeValue> {
114
+ // return {
115
+ // id: nodeId(filePath, [], '#document'),
116
+ // value: { kind: document.kind },
117
+ // };
118
+ // }
@@ -7,4 +7,5 @@ import { type Position, type XmlNodeValue } from '../domain/xml-tree.js';
7
7
  * XML domain tree and displayed through xmlNavApi's source-order navigation.
8
8
  */
9
9
  export declare function loadNodeXmlAppApi(filePath: string): AppApi<Position, XmlNodeValue, string>;
10
+ export declare function createXmlFileResyncSubscription(xmlAbsolutePath: string): (listener: () => void) => () => void;
10
11
  //# sourceMappingURL=load-node-xml-app-api.d.ts.map
@@ -1 +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"}
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;AAI/B;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,GACf,MAAM,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,CAAC,CA6CxC;AAED,wBAAgB,+BAA+B,CAC7C,eAAe,EAAE,MAAM,GACtB,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAiFtC"}