@mak-98/xml-dirvi-app 0.11.0-beta.2 → 0.11.0-beta.24
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/README.md +122 -0
- 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 +83 -249
- package/dist/domain/xml-tree.d.ts.map +1 -1
- package/dist/domain/xml-tree.js +63 -96
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- 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 +166 -0
- package/dist/infrastructure/create-xml-file-resync.d.ts +2 -0
- package/dist/infrastructure/create-xml-file-resync.d.ts.map +1 -0
- package/dist/infrastructure/create-xml-file-resync.js +68 -0
- package/dist/infrastructure/get-xml-entries.d.ts +1 -18
- package/dist/infrastructure/get-xml-entries.d.ts.map +1 -1
- package/dist/infrastructure/get-xml-entries.js +118 -44
- package/dist/infrastructure/load-node-xml-app-api.d.ts +1 -0
- package/dist/infrastructure/load-node-xml-app-api.d.ts.map +1 -1
- package/dist/infrastructure/load-node-xml-app-api.js +7 -3
- package/dist/infrastructure/parse-xml-document.d.ts +6 -4
- package/dist/infrastructure/parse-xml-document.d.ts.map +1 -1
- package/dist/infrastructure/parse-xml-document.js +9 -12
- package/dist/services/xml-dom.d.ts +16 -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 +2 -5
- package/dist/xml-dirvi-app.d.ts.map +1 -1
- package/dist/xml-dirvi-app.js +53 -13
- package/package.json +4 -3
|
@@ -2,7 +2,8 @@ import { watch } from 'node:fs';
|
|
|
2
2
|
import { basename, dirname, resolve } from 'node:path';
|
|
3
3
|
import { createAppStateApis } from 'dirvi-lib';
|
|
4
4
|
import { xmlFoldsApi, xmlNavApi, } from '../domain/xml-tree.js';
|
|
5
|
-
import {
|
|
5
|
+
import { readFile } from 'node:fs/promises';
|
|
6
|
+
import { parseXmlDocument } from './parse-xml-document.js';
|
|
6
7
|
/**
|
|
7
8
|
* Creates the AppApi for one XML document.
|
|
8
9
|
*
|
|
@@ -18,7 +19,10 @@ export function loadNodeXmlAppApi(filePath) {
|
|
|
18
19
|
* parseXmlDocument() reserves position 0 for the synthetic document root.
|
|
19
20
|
*/
|
|
20
21
|
rootId: 0,
|
|
21
|
-
createRoot: () =>
|
|
22
|
+
createRoot: async () => {
|
|
23
|
+
const source = await readFile(xmlAbsolutePath, 'utf8');
|
|
24
|
+
return parseXmlDocument(source);
|
|
25
|
+
},
|
|
22
26
|
/*
|
|
23
27
|
* XML documents are parsed completely when their root is created. No XML
|
|
24
28
|
* branch is represented as an unloaded branch.
|
|
@@ -42,7 +46,7 @@ export function loadNodeXmlAppApi(filePath) {
|
|
|
42
46
|
...apis,
|
|
43
47
|
};
|
|
44
48
|
}
|
|
45
|
-
function createXmlFileResyncSubscription(xmlAbsolutePath) {
|
|
49
|
+
export function createXmlFileResyncSubscription(xmlAbsolutePath) {
|
|
46
50
|
const listeners = new Set();
|
|
47
51
|
const parentDirectory = dirname(xmlAbsolutePath);
|
|
48
52
|
const fileName = basename(xmlAbsolutePath);
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TreeMethods } from 'dirvi-lib';
|
|
2
|
+
import type { XmlId, XmlNodeValue, XmlTreeNode } from '../domain/xml-tree.js';
|
|
3
|
+
export declare const createXmlId: (name: string) => XmlId;
|
|
2
4
|
/**
|
|
3
5
|
* Parses XML source into one Dirvi XML document tree.
|
|
4
6
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
+
* Each node receives an ID containing a fresh UUID and its node name.
|
|
8
|
+
* Source child order is preserved by the TreeNode child sequence.
|
|
7
9
|
*/
|
|
8
|
-
export declare function parseXmlDocument(source: string): XmlTreeNode;
|
|
10
|
+
export declare function parseXmlDocument(treeNodeApi: TreeMethods<XmlId, XmlNodeValue>, source: string): XmlTreeNode;
|
|
9
11
|
//# sourceMappingURL=parse-xml-document.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-xml-document.d.ts","sourceRoot":"","sources":["../../src/infrastructure/parse-xml-document.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parse-xml-document.d.ts","sourceRoot":"","sources":["../../src/infrastructure/parse-xml-document.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAI9E,eAAO,MAAM,WAAW,GAAI,MAAM,MAAM,KAAG,KACG,CAAC;AAE/C;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,WAAW,CAAC,KAAK,EAAE,YAAY,CAAC,EAC7C,MAAM,EAAE,MAAM,GACb,WAAW,CAiBb"}
|
|
@@ -1,24 +1,21 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
1
2
|
import { parseXml } from '@rgrove/parse-xml';
|
|
2
|
-
import {
|
|
3
|
+
import { createConstructors, xmlIdSchema } from '../domain/xml-tree.js';
|
|
3
4
|
import { getXmlEntries } from './get-xml-entries.js';
|
|
5
|
+
export const createXmlId = (name) => xmlIdSchema.parse(`${randomUUID()}:${name}`);
|
|
4
6
|
/**
|
|
5
7
|
* Parses XML source into one Dirvi XML document tree.
|
|
6
8
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
+
* Each node receives an ID containing a fresh UUID and its node name.
|
|
10
|
+
* Source child order is preserved by the TreeNode child sequence.
|
|
9
11
|
*/
|
|
10
|
-
export function parseXmlDocument(source) {
|
|
12
|
+
export function parseXmlDocument(treeNodeApi, source) {
|
|
11
13
|
const document = parseXml(source);
|
|
12
|
-
|
|
13
|
-
const root = XmlTreeNodeDomain.document(0, getXmlEntries(document.children, () => {
|
|
14
|
-
const position = nextPosition;
|
|
15
|
-
nextPosition += 1;
|
|
16
|
-
return position;
|
|
17
|
-
}));
|
|
14
|
+
const root = createConstructors(treeNodeApi).document(createXmlId('#document'), getXmlEntries(treeNodeApi, document.children, createXmlId));
|
|
18
15
|
if (root === undefined) {
|
|
19
16
|
/*
|
|
20
|
-
*
|
|
21
|
-
* XML-to-domain conversion
|
|
17
|
+
* Each node receives a fresh UUID, so duplicate child IDs would indicate
|
|
18
|
+
* an ID collision or a defect in XML-to-domain conversion.
|
|
22
19
|
*/
|
|
23
20
|
throw new Error('Cannot create XML document: duplicate child IDs.');
|
|
24
21
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { XmlDocument, XmlDocumentChild, XmlElementChild } from '../domain/xml-doc.js';
|
|
2
|
+
import { XmlId } from '../domain/xml-tree.js';
|
|
3
|
+
export type XmlDomEntry<Value> = {
|
|
4
|
+
id: XmlId;
|
|
5
|
+
value: Value;
|
|
6
|
+
};
|
|
7
|
+
export type XmlDom = {
|
|
8
|
+
/** Returns the document and its ID. */
|
|
9
|
+
getDocument: () => XmlDomEntry<XmlDocument>;
|
|
10
|
+
/**
|
|
11
|
+
* Loads direct children in document order.
|
|
12
|
+
* Omitting the ID addresses the document.
|
|
13
|
+
*/
|
|
14
|
+
getChildren: (id?: XmlId) => readonly XmlDomEntry<XmlDocumentChild | XmlElementChild>[];
|
|
15
|
+
};
|
|
16
|
+
//# 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,EACV,WAAW,EACX,gBAAgB,EAChB,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE9C,MAAM,MAAM,WAAW,CAAC,KAAK,IAAI;IAC/B,EAAE,EAAE,KAAK,CAAC;IACV,KAAK,EAAE,KAAK,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG;IACnB,uCAAuC;IACvC,WAAW,EAAE,MAAM,WAAW,CAAC,WAAW,CAAC,CAAC;IAE5C;;;OAGG;IACH,WAAW,EAAE,CACX,EAAE,CAAC,EAAE,KAAK,KACP,SAAS,WAAW,CAAC,gBAAgB,GAAG,eAAe,CAAC,EAAE,CAAC;CACjE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/xml-dirvi-app.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
* A dirvi app that exposes a POSIX filesystem as a navigable tree.
|
|
4
|
-
*/
|
|
5
|
-
export declare const xmlAppPlugin: AppPlugin;
|
|
1
|
+
import type { CreateAppDefinitionApplicator } from 'treevim';
|
|
2
|
+
export declare const app: CreateAppDefinitionApplicator;
|
|
6
3
|
//# sourceMappingURL=xml-dirvi-app.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"xml-dirvi-app.d.ts","sourceRoot":"","sources":["../src/xml-dirvi-app.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"xml-dirvi-app.d.ts","sourceRoot":"","sources":["../src/xml-dirvi-app.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAGV,6BAA6B,EAE9B,MAAM,SAAS,CAAC;AAQjB,eAAO,MAAM,GAAG,EAAE,6BA8DjB,CAAC"}
|
package/dist/xml-dirvi-app.js
CHANGED
|
@@ -1,15 +1,55 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { xmlValueSchema } from './domain/xml-tree.js';
|
|
4
|
+
import { createXmlFileResyncSubscription } from './infrastructure/create-xml-file-resync.js';
|
|
5
|
+
import { createXmlDom } from './infrastructure/create-xml-dom.js';
|
|
6
|
+
export const app = (input) => {
|
|
7
|
+
if (input === undefined) {
|
|
8
|
+
throw new Error('xml-dirvi-app: No file path to XML file given.');
|
|
9
|
+
}
|
|
10
|
+
const xmlAbsolutePath = resolve(input);
|
|
11
|
+
// TODO: Make the `xmldom` nodes the IDs.
|
|
12
|
+
// Create dom async on first need, cache afterward
|
|
13
|
+
let dom;
|
|
14
|
+
let domPromise;
|
|
15
|
+
const getDom = async () => {
|
|
16
|
+
if (dom !== undefined) {
|
|
17
|
+
return dom;
|
|
9
18
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
19
|
+
if (domPromise === undefined) {
|
|
20
|
+
domPromise = readFile(xmlAbsolutePath, 'utf8')
|
|
21
|
+
.then((source) => {
|
|
22
|
+
dom = createXmlDom(source);
|
|
23
|
+
return dom;
|
|
24
|
+
})
|
|
25
|
+
.finally(() => {
|
|
26
|
+
domPromise = undefined;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return domPromise;
|
|
30
|
+
};
|
|
31
|
+
const appDefinition = {
|
|
32
|
+
semanticOrder: true,
|
|
33
|
+
valueSchema: xmlValueSchema,
|
|
34
|
+
loadChildren: async (path) => {
|
|
35
|
+
const dom = await getDom();
|
|
36
|
+
return dom.getChildren(path.at(-1)).map(({ id, value }) => ({
|
|
37
|
+
id,
|
|
38
|
+
kind: value.kind === 'element' ? 'unloaded-branch' : 'leaf',
|
|
39
|
+
value,
|
|
40
|
+
}));
|
|
41
|
+
},
|
|
42
|
+
loadRoot: async () => {
|
|
43
|
+
const dom = await getDom();
|
|
44
|
+
return dom.getDocument();
|
|
45
|
+
},
|
|
46
|
+
presentNode: (_id, value, nodeKind) => [
|
|
47
|
+
{
|
|
48
|
+
content: value.kind,
|
|
49
|
+
hlToken: nodeKind,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
subscribeToResync: createXmlFileResyncSubscription(xmlAbsolutePath),
|
|
53
|
+
};
|
|
54
|
+
return (appDefinitionConsumer) => appDefinitionConsumer(appDefinition);
|
|
15
55
|
};
|
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.24",
|
|
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
|
-
"
|
|
24
|
-
"dirvi-lib": "0.11.0-beta.1",
|
|
23
|
+
"@xmldom/xmldom": "^0.9.12",
|
|
25
24
|
"env-paths": "^4.0.0",
|
|
26
25
|
"zod": "^4.4.3"
|
|
27
26
|
},
|
|
28
27
|
"devDependencies": {
|
|
28
|
+
"treevim": "0.1.0-beta.2",
|
|
29
29
|
"@types/node": "^22.0.0",
|
|
30
|
+
"dirvi-lib": "0.11.0-beta.24",
|
|
30
31
|
"typescript": "^5.0.0"
|
|
31
32
|
},
|
|
32
33
|
"scripts": {
|