@mak-98/xml-dirvi-app 0.11.0-beta.4 → 0.11.0-beta.6.1

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.
@@ -1,13 +1,18 @@
1
1
  import { z } from 'zod';
2
2
  import type { TreeNode, TreeNodeApi } from 'dirvi-lib';
3
3
  /**
4
- * A parser-assigned node identity within one XML document.
4
+ * A node key containing its UUID and display name.
5
5
  *
6
- * Position is an identity, not XML document order. XML sibling order is held
7
- * by the source TreeNode child sequence.
6
+ * This is not XML document order. XML sibling order is held by the source
7
+ * TreeNode child sequence.
8
+ *
9
+ * Changing the name changes the complete tree key.
8
10
  */
9
- export type Position = number;
10
- export declare const xmlIdSchema: z.ZodNumber;
11
+ export declare const xmlIdSchema: z.ZodString;
12
+ export type XmlId = z.infer<typeof xmlIdSchema>;
13
+ export declare function createXmlId(name: string, uuid: string): XmlId;
14
+ export declare function xmlIdName(id: XmlId): string;
15
+ export declare function xmlIdUuid(id: XmlId): string;
11
16
  export type XmlAttribute = Readonly<{
12
17
  readonly name: string;
13
18
  readonly value: string;
@@ -56,7 +61,7 @@ export type XmlProcessingInstructionValue = Readonly<{
56
61
  * Child ordering is deliberately not represented here.
57
62
  */
58
63
  export type XmlNodeValue = XmlDocumentValue | XmlDeclarationValue | XmlDoctypeValue | XmlElementValue | XmlTextValue | XmlCommentValue | XmlCdataValue | XmlProcessingInstructionValue;
59
- export type XmlTreeNode = TreeNode<Position, XmlNodeValue>;
64
+ export type XmlTreeNode = TreeNode<XmlId, XmlNodeValue>;
60
65
  export declare const XmlAttributeSchema: z.ZodObject<{
61
66
  name: z.ZodString;
62
67
  value: z.ZodString;
@@ -112,14 +117,14 @@ export declare const xmlValueSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
112
117
  target: z.ZodString;
113
118
  data: z.ZodString;
114
119
  }, z.core.$strip>], "kind">;
115
- export declare function createConstructors(xmlTreeNodeApi: TreeNodeApi<Position, XmlNodeValue>): {
116
- readonly document: (id: Position, children: Iterable<XmlTreeNode>) => XmlTreeNode | undefined;
117
- readonly declaration: (id: Position, version: string, encoding: string | null, standalone: "yes" | "no" | null) => XmlTreeNode;
118
- readonly doctype: (id: Position, name: string, publicId: string | null, systemId: string | null, internalSubset: string | null) => XmlTreeNode;
119
- readonly element: (id: Position, name: string, attributes: readonly XmlAttribute[], children: Iterable<XmlTreeNode>) => XmlTreeNode | undefined;
120
- readonly text: (id: Position, text: string) => XmlTreeNode;
121
- readonly comment: (id: Position, text: string) => XmlTreeNode;
122
- readonly cdata: (id: Position, text: string) => XmlTreeNode;
123
- readonly processingInstruction: (id: Position, target: string, data: string) => XmlTreeNode;
120
+ export declare function createConstructors(xmlTreeNodeApi: TreeNodeApi<XmlId, XmlNodeValue>): {
121
+ readonly document: (id: XmlId, children: Iterable<XmlTreeNode>) => XmlTreeNode | undefined;
122
+ readonly declaration: (id: XmlId, version: string, encoding: string | null, standalone: "yes" | "no" | null) => XmlTreeNode;
123
+ readonly doctype: (id: XmlId, name: string, publicId: string | null, systemId: string | null, internalSubset: string | null) => XmlTreeNode;
124
+ readonly element: (id: XmlId, name: string, attributes: readonly XmlAttribute[], children: Iterable<XmlTreeNode>) => XmlTreeNode | undefined;
125
+ readonly text: (id: XmlId, text: string) => XmlTreeNode;
126
+ readonly comment: (id: XmlId, text: string) => XmlTreeNode;
127
+ readonly cdata: (id: XmlId, text: string) => XmlTreeNode;
128
+ readonly processingInstruction: (id: XmlId, target: string, data: string) => XmlTreeNode;
124
129
  };
125
130
  //# 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;AAYxE;;;;;GAKG;AACH,MAAM,MAAM,QAAQ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,KAAK,QACH,MAAM,cACA,SAAS,YAAY,EAAE,YACzB,QAAQ,CAAC,WAAW,CAAC,KAC9B,WAAW,GAAG,SAAS;wBAYjB,KAAK,QAAQ,MAAM,KAAG,WAAW;2BAO9B,KAAK,QAAQ,MAAM,KAAG,WAAW;yBAOnC,KAAK,QAAQ,MAAM,KAAG,WAAW;yCAQrC,KAAK,UACD,MAAM,QACR,MAAM,KACX,WAAW;EAQjB"}
@@ -1,8 +1,33 @@
1
1
  import { z } from 'zod';
2
- export const xmlIdSchema = z
3
- .number()
4
- .int()
5
- .nonnegative();
2
+ // -----------------------------------------------------------------------------
3
+ // Position: Id extends SerializableKey
4
+ // -----------------------------------------------------------------------------
5
+ const uuidSchema = z.uuid();
6
+ /**
7
+ * A node key containing its UUID and display name.
8
+ *
9
+ * This is not XML document order. XML sibling order is held by the source
10
+ * TreeNode child sequence.
11
+ *
12
+ * Changing the name changes the complete tree key.
13
+ */
14
+ export const xmlIdSchema = z.string().refine((value) => {
15
+ const separator = value.indexOf(':');
16
+ return (separator > 0 &&
17
+ uuidSchema.safeParse(value.slice(0, separator)).success &&
18
+ value.slice(separator + 1).trim().length > 0);
19
+ }, {
20
+ message: 'Expected an XML node ID in the form <uuid>:<node-name>.',
21
+ });
22
+ export function createXmlId(name, uuid) {
23
+ return xmlIdSchema.parse(`${uuid}:${name}`);
24
+ }
25
+ export function xmlIdName(id) {
26
+ return id.slice(id.indexOf(':') + 1);
27
+ }
28
+ export function xmlIdUuid(id) {
29
+ return id.slice(0, id.indexOf(':'));
30
+ }
6
31
  // Schema ----------------------------------------------------------------------
7
32
  export const XmlAttributeSchema = z.object({
8
33
  name: z.string().min(1),
@@ -1,14 +1,14 @@
1
1
  import type { XmlNode } from '@rgrove/parse-xml';
2
2
  import type { TreeNodeApi } from 'dirvi-lib';
3
3
  import type { XmlNodeValue, XmlTreeNode } from '../domain/xml-tree.js';
4
- import type { Position } from '../domain/xml-tree.js';
4
+ import type { XmlId } from '../domain/xml-tree.js';
5
5
  /**
6
- * Allocates unique XML tree IDs while one parsed document is converted.
6
+ * Allocates an XML tree ID containing the node's name and a unique UUID.
7
7
  *
8
8
  * IDs identify nodes and cursor paths. They do not represent sibling order:
9
9
  * source child order is preserved by the TreeNode child sequence.
10
10
  */
11
- export type CreatePosition = () => Position;
11
+ export type CreateXmlId = (name: string) => XmlId;
12
12
  /**
13
13
  * Converts XML parser nodes into ordered Dirvi XML tree nodes.
14
14
  *
@@ -16,5 +16,5 @@ export type CreatePosition = () => Position;
16
16
  * mixed content such as text, elements, comments, and CDATA remains in its
17
17
  * source-document order.
18
18
  */
19
- export declare function getXmlEntries(treeNodeApi: TreeNodeApi<Position, XmlNodeValue>, xmlNodes: readonly XmlNode[], createPosition: CreatePosition): XmlTreeNode[];
19
+ export declare function getXmlEntries(treeNodeApi: TreeNodeApi<XmlId, XmlNodeValue>, xmlNodes: readonly XmlNode[], createXmlId: CreateXmlId): XmlTreeNode[];
20
20
  //# 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,WAAW,CAAC;AAE7C,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACZ,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,QAAQ,CAAC;AAE5C;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,WAAW,EAAE,WAAW,CAAC,QAAQ,EAAE,YAAY,CAAC,EAChD,QAAQ,EAAE,SAAS,OAAO,EAAE,EAC5B,cAAc,EAAE,cAAc,GAC7B,WAAW,EAAE,CAwEf"}
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,WAAW,CAAC;AAE7C,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACZ,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,KAAK,CAAC;AAElD;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,WAAW,EAAE,WAAW,CAAC,KAAK,EAAE,YAAY,CAAC,EAC7C,QAAQ,EAAE,SAAS,OAAO,EAAE,EAC5B,WAAW,EAAE,WAAW,GACvB,WAAW,EAAE,CAwEf"}
@@ -7,12 +7,12 @@ import { createConstructors } from '../domain/xml-tree.js';
7
7
  * mixed content such as text, elements, comments, and CDATA remains in its
8
8
  * source-document order.
9
9
  */
10
- export function getXmlEntries(treeNodeApi, xmlNodes, createPosition) {
10
+ export function getXmlEntries(treeNodeApi, xmlNodes, createXmlId) {
11
11
  return xmlNodes.map((xmlNode) => {
12
- const id = createPosition();
12
+ const id = createXmlId(getXmlNodeName(xmlNode));
13
13
  const constructors = createConstructors(treeNodeApi);
14
14
  if (xmlNode instanceof XmlElement) {
15
- const children = getXmlEntries(treeNodeApi, xmlNode.children, createPosition);
15
+ const children = getXmlEntries(treeNodeApi, xmlNode.children, createXmlId);
16
16
  const node = constructors.element(id, xmlNode.name, Object.entries(xmlNode.attributes).map(([name, value]) => ({
17
17
  name,
18
18
  value,
@@ -43,3 +43,28 @@ export function getXmlEntries(treeNodeApi, xmlNodes, createPosition) {
43
43
  throw new Error(`Unsupported XML node type "${xmlNode.type}".`);
44
44
  });
45
45
  }
46
+ /**
47
+ * Returns the XML name where one exists, otherwise a synthetic node label.
48
+ *
49
+ * Namespace prefixes are preserved, for example "svg:path".
50
+ */
51
+ function getXmlNodeName(xmlNode) {
52
+ if (xmlNode instanceof XmlElement ||
53
+ xmlNode instanceof XmlProcessingInstruction ||
54
+ xmlNode instanceof XmlDocumentType) {
55
+ return xmlNode.name;
56
+ }
57
+ if (xmlNode instanceof XmlText) {
58
+ return '#text';
59
+ }
60
+ if (xmlNode instanceof XmlCdata) {
61
+ return '#cdata';
62
+ }
63
+ if (xmlNode instanceof XmlComment) {
64
+ return '#comment';
65
+ }
66
+ if (xmlNode instanceof XmlDeclaration) {
67
+ return '#declaration';
68
+ }
69
+ throw new Error(`Unsupported XML node type "${xmlNode.type}".`);
70
+ }
@@ -1,10 +1,11 @@
1
1
  import type { TreeNodeApi } from 'dirvi-lib';
2
- import type { Position, XmlNodeValue, XmlTreeNode } from '../domain/xml-tree.js';
2
+ import type { XmlId, XmlNodeValue, XmlTreeNode } from '../domain/xml-tree.js';
3
+ export declare const createXmlId: (name: string) => XmlId;
3
4
  /**
4
5
  * Parses XML source into one Dirvi XML document tree.
5
6
  *
6
- * The synthetic document root always receives ID 0. Descendants receive
7
- * monotonically allocated IDs in parser encounter order.
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.
8
9
  */
9
- export declare function parseXmlDocument(treeNodeApi: TreeNodeApi<Position, XmlNodeValue>, source: string): XmlTreeNode;
10
+ export declare function parseXmlDocument(treeNodeApi: TreeNodeApi<XmlId, XmlNodeValue>, source: string): XmlTreeNode;
10
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":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,KAAK,EACV,QAAQ,EACR,YAAY,EACZ,WAAW,EACZ,MAAM,uBAAuB,CAAC;AAI/B;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,WAAW,CAAC,QAAQ,EAAE,YAAY,CAAC,EAChD,MAAM,EAAE,MAAM,GACb,WAAW,CAwBb"}
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 { createConstructors } from '../domain/xml-tree.js';
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
- * The synthetic document root always receives ID 0. Descendants receive
8
- * monotonically allocated IDs in parser encounter order.
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
12
  export function parseXmlDocument(treeNodeApi, source) {
11
13
  const document = parseXml(source);
12
- let nextPosition = 1;
13
- const root = createConstructors(treeNodeApi).document(0, getXmlEntries(treeNodeApi, 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
- * Position allocation is unique, so this would indicate a defect in the
21
- * XML-to-domain conversion rather than invalid user XML.
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
  }
@@ -1 +1 @@
1
- {"version":3,"file":"xml-dirvi-app.d.ts","sourceRoot":"","sources":["../src/xml-dirvi-app.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAQnD;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,EAAE,SAmC1B,CAAC"}
1
+ {"version":3,"file":"xml-dirvi-app.d.ts","sourceRoot":"","sources":["../src/xml-dirvi-app.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAQnD;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,EAAE,SAuC1B,CAAC"}
@@ -2,7 +2,7 @@ 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 { parseXmlDocument } from './infrastructure/parse-xml-document.js';
5
+ import { createXmlId, parseXmlDocument } from './infrastructure/parse-xml-document.js';
6
6
  /**
7
7
  * Creates applicator of `AppDefinition<Position, XmlValue>`.
8
8
  *
@@ -20,7 +20,7 @@ export const xmlAppPlugin = {
20
20
  const xmlAbsolutePath = resolve(input);
21
21
  const appDefinition = {
22
22
  displayName: `XML: ${input}`,
23
- rootId: 0,
23
+ rootId: createXmlId('document'),
24
24
  idSchema: xmlIdSchema,
25
25
  valueSchema: xmlValueSchema,
26
26
  createRoot: async (treeNodeApi) => {
@@ -31,6 +31,11 @@ export const xmlAppPlugin = {
31
31
  // TODO Later: load from the file
32
32
  throw new Error('Cannot load XML branches: parsed XML documents have no unloaded branches.');
33
33
  },
34
+ presentNode: (id, isBranch) => ({
35
+ // Split at the first colon only, preserving names such as "svg:path".
36
+ content: id.slice(id.indexOf(':') + 1),
37
+ highlight: isBranch ? 'branch' : 'leaf',
38
+ }),
34
39
  subscribeToResync: createXmlFileResyncSubscription(xmlAbsolutePath),
35
40
  createNavNodeApiOptions: {},
36
41
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mak-98/xml-dirvi-app",
3
- "version": "0.11.0-beta.4",
3
+ "version": "0.11.0-beta.6.1",
4
4
  "description": "XML file app for dirvi.",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "type": "module",
@@ -20,12 +20,12 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@rgrove/parse-xml": "^5.0.0",
23
- "dirvi-apis": "0.11.0-beta.4",
23
+ "dirvi-apis": "0.11.0-beta.6",
24
24
  "env-paths": "^4.0.0",
25
25
  "zod": "^4.4.3"
26
26
  },
27
27
  "devDependencies": {
28
- "dirvi-lib": "0.11.0-beta.4",
28
+ "dirvi-lib": "0.11.0-beta.6",
29
29
  "@types/node": "^22.0.0",
30
30
  "typescript": "^5.0.0"
31
31
  },