@mak-98/xml-dirvi-app 0.0.0-stage → 0.11.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/dist/domain/xml-tree.d.ts +146 -0
- package/dist/domain/xml-tree.d.ts.map +1 -0
- package/dist/domain/xml-tree.js +140 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/infrastructure/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 +9 -0
- package/dist/infrastructure/get-xml-entries.d.ts.map +1 -0
- package/dist/infrastructure/get-xml-entries.js +134 -0
- package/dist/infrastructure/load-node-xml-app-api.d.ts +11 -0
- package/dist/infrastructure/load-node-xml-app-api.d.ts.map +1 -0
- package/dist/infrastructure/load-node-xml-app-api.js +114 -0
- package/dist/infrastructure/load-node-xml-document.d.ts +6 -0
- package/dist/infrastructure/load-node-xml-document.d.ts.map +1 -0
- package/dist/infrastructure/load-node-xml-document.js +9 -0
- package/dist/infrastructure/parse-xml-document.d.ts +11 -0
- package/dist/infrastructure/parse-xml-document.d.ts.map +1 -0
- package/dist/infrastructure/parse-xml-document.js +23 -0
- package/dist/xml-dirvi-app.d.ts +3 -0
- package/dist/xml-dirvi-app.d.ts.map +1 -0
- package/dist/xml-dirvi-app.js +30 -0
- package/package.json +34 -3
- package/README.md +0 -3
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { parseXmlDocument } from './parse-xml-document.js';
|
|
3
|
+
/**
|
|
4
|
+
* Reads one UTF-8 XML file and parses it into the XML domain tree.
|
|
5
|
+
*/
|
|
6
|
+
export async function loadNodeXmlDocument(filePath) {
|
|
7
|
+
const source = await readFile(filePath, 'utf8');
|
|
8
|
+
return parseXmlDocument(source);
|
|
9
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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;
|
|
4
|
+
/**
|
|
5
|
+
* Parses XML source into one Dirvi XML document tree.
|
|
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.
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseXmlDocument(treeNodeApi: TreeMethods<XmlId, XmlNodeValue>, source: string): XmlTreeNode;
|
|
11
|
+
//# sourceMappingURL=parse-xml-document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-xml-document.d.ts","sourceRoot":"","sources":["../../src/infrastructure/parse-xml-document.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { parseXml } from '@rgrove/parse-xml';
|
|
3
|
+
import { createConstructors, xmlIdSchema } from '../domain/xml-tree.js';
|
|
4
|
+
import { getXmlEntries } from './get-xml-entries.js';
|
|
5
|
+
export const createXmlId = (name) => xmlIdSchema.parse(`${randomUUID()}:${name}`);
|
|
6
|
+
/**
|
|
7
|
+
* Parses XML source into one Dirvi XML document tree.
|
|
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.
|
|
11
|
+
*/
|
|
12
|
+
export function parseXmlDocument(treeNodeApi, source) {
|
|
13
|
+
const document = parseXml(source);
|
|
14
|
+
const root = createConstructors(treeNodeApi).document(createXmlId('#document'), getXmlEntries(treeNodeApi, document.children, createXmlId));
|
|
15
|
+
if (root === undefined) {
|
|
16
|
+
/*
|
|
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.
|
|
19
|
+
*/
|
|
20
|
+
throw new Error('Cannot create XML document: duplicate child IDs.');
|
|
21
|
+
}
|
|
22
|
+
return root;
|
|
23
|
+
}
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { readFile } from 'node:fs/promises';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import { xmlIdSchema, xmlValueSchema } from './domain/xml-tree.js';
|
|
4
|
+
import { createXmlFileResyncSubscription } from './infrastructure/create-xml-file-resync.js';
|
|
5
|
+
import { createXmlRoot, getXmlEntries, } from './infrastructure/get-xml-entries.js';
|
|
6
|
+
export const xmlAppPlugin = {
|
|
7
|
+
createAppDefinitionApplicator: (input) => {
|
|
8
|
+
if (input === undefined) {
|
|
9
|
+
throw new Error('xml-dirvi-app: No file path to XML file given.');
|
|
10
|
+
}
|
|
11
|
+
const xmlAbsolutePath = resolve(input);
|
|
12
|
+
const appDefinition = {
|
|
13
|
+
displayName: `XML: ${input}`,
|
|
14
|
+
semanticOrder: true,
|
|
15
|
+
idSchema: xmlIdSchema,
|
|
16
|
+
valueSchema: xmlValueSchema,
|
|
17
|
+
loadChildren: async (path) => {
|
|
18
|
+
const source = await readFile(xmlAbsolutePath, 'utf8');
|
|
19
|
+
return getXmlEntries(xmlAbsolutePath, source, path);
|
|
20
|
+
},
|
|
21
|
+
loadRoot: async () => createXmlRoot(xmlAbsolutePath),
|
|
22
|
+
presentNode: (id, isBranch) => ({
|
|
23
|
+
content: id.slice(id.indexOf(':') + 1),
|
|
24
|
+
highlight: isBranch ? 'branch' : 'leaf',
|
|
25
|
+
}),
|
|
26
|
+
subscribeToResync: createXmlFileResyncSubscription(xmlAbsolutePath),
|
|
27
|
+
};
|
|
28
|
+
return (appDefinitionConsumer) => appDefinitionConsumer(appDefinition);
|
|
29
|
+
},
|
|
30
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,37 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mak-98/xml-dirvi-app",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.11.0-beta.13",
|
|
4
|
+
"description": "XML file app for dirvi.",
|
|
5
|
+
"license": "GPL-3.0-or-later",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=22"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@rgrove/parse-xml": "^5.0.0",
|
|
23
|
+
"dirvi-apis": "0.11.0-beta.13",
|
|
24
|
+
"env-paths": "^4.0.0",
|
|
25
|
+
"zod": "^4.4.3"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"dirvi-lib": "0.11.0-beta.13",
|
|
29
|
+
"@types/node": "^22.0.0",
|
|
30
|
+
"typescript": "^5.0.0"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc",
|
|
34
|
+
"typecheck": "tsc --noEmit",
|
|
35
|
+
"format": "prettier src --write"
|
|
36
|
+
}
|
|
6
37
|
}
|
package/README.md
DELETED