@plurnk/plurnk-mimetypes-application-xml 2.0.3 → 2.0.5

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 CHANGED
@@ -11,8 +11,8 @@ npm i @plurnk/plurnk-mimetypes-application-xml
11
11
  ## what it does
12
12
 
13
13
  - `extractRaw(content)` emits the root element and its immediate children: enough shape to recognize RSS, SOAP or a Maven pom without every leaf ({§xml-shape}).
14
- - `deepJson(content)` is the DOM as nested objects ({§mimetype-channel-architecture}); `xpath` runs against the real DOM and every match selects its exact lexical source ({§xml-lexical-spans}, {§xml-text-nodes}).
15
- - A recoverable xmldom report is counted, not fatal; content that is not a document projects nothing and stays text-searchable ({§xml-recovery}).
14
+ - `deepJson(content)` is the DOM as nested objects ({§mimetype-channel-architecture}); `xpath` runs against the real DOM and every match selects its exact lexical source ({§xml-shape}).
15
+ - A recoverable xmldom report is counted, not fatal; content that is not a document projects nothing and stays text-searchable ({§xml-shape}).
16
16
 
17
17
  ## license
18
18
 
package/SPEC.md CHANGED
@@ -1,38 +1,13 @@
1
1
  # XML handler
2
2
 
3
- §xml-shape Symbols are the document's shape, not its leaves: the root element is a
4
- `module` symbol and each immediate child element is a `field` symbol named by its
5
- `id` attribute, else its `name` attribute, else its tag name, with the root's tag
6
- name as `container` ({§mimetype-symbol-container}). Every symbol spans its complete
7
- element. Empty input or content that is not a document has no symbols.
8
-
9
- §xml-recovery xmldom's recoverable `error` reports, such as an entity declared only
10
- in the internal DTD subset, each count as one parse issue and the channels project
11
- the recovered DOM. Content that is not a document (xmldom `fatalError`: a template,
12
- a truncated file) counts as one issue, has no symbols and a `null` `deepJson`, and
13
- refuses XPath and JSONPath with `QueryParseFailureError`; regex and glob run
14
- unaffected ({§mimetype-parse-issues}). Empty input reports no issue. Only a defect
15
- outside xmldom's own `ParseError` fails a derivation.
16
-
17
- §xml-lexical-spans XPath runs over the real DOM (XPath 1.0 through `xpath`) and
18
- JSONPath over the DOM projection; every node match selects its exact lexical source
19
- through the concrete syntax tree: an element without surrounding whitespace, an
20
- attribute as `name = 'value'` as written, text with its entity, character-reference
21
- and CDATA markup, a comment or processing instruction whole. A computed scalar is
22
- locator-only; a malformed expression is `InvalidExpressionError` ({§mimetype-query}).
23
-
24
- §xml-text-nodes XPath sees the XPath 1.0 logical text model: a CDATA section is
25
- text, adjacent text coalesces into one node, an empty text node does not exist,
26
- and the document node carries neither whitespace text nor the XML declaration
27
- while other processing instructions remain. `matched` is the logical string; the
28
- region is the lexical source ({§xml-lexical-spans}).
3
+ ## §xml-shape XML shape, recovery, lexical spans, and logical text nodes
29
4
 
30
5
  | Surface | Contract |
31
6
  |---|---|
32
- | `validate` | Framework default; recovery is advisory ({§xml-recovery}). |
33
- | `extractRaw` | Root and immediate children ({§xml-shape}). |
34
- | `deepJson` | The DOM as nested `{ type, attrs, children }` objects through the framework's `projectDomToJson`, each with its source coordinates; a text-only element collapses to `text`, mixed content keeps `#text` siblings, comments and instructions are omitted ({§mimetype-channel-architecture}). |
35
- | `parseIssues` | Recovery sites ({§xml-recovery}). |
36
- | JSONPath / XPath | Lexical source spans ({§xml-lexical-spans}, {§xml-text-nodes}). |
7
+ | `validate` | Framework default no-op; recovery is advisory ({§mimetype-channel-selection}). Only a defect outside xmldom's `ParseError` fails derivation. |
8
+ | `parseIssues` | Each recoverable xmldom `error` (such as an entity declared only in the internal DTD subset) counts as 1 issue and channels project the recovered DOM. Content that is not a document (xmldom `fatalError`: template or truncated file) counts as 1 issue, yields `[]` symbols and `null` `deepJson`, and refuses XPath/JSONPath with `QueryParseFailureError` (regex/glob unaffected). Empty input reports 0 issues and `[]` symbols. |
9
+ | `extractRaw` | Document shape: root element is a `module` symbol and each immediate child element is a `field` symbol named by `id`, else `name`, else tag name, with the root's tag name as `container` ({§mimetype-symbol}), each spanning its complete element. |
10
+ | `deepJson` | DOM as nested `{ type, attrs, children }` objects via `projectDomToJson` with source coordinates; text-only elements collapse to `text`, mixed content keeps `#text` siblings, and comments/processing instructions are omitted ({§mimetype-channel-architecture}). |
11
+ | JSONPath / XPath | XPath 1.0 runs over the real DOM and JSONPath over `deepJson`. Every node match selects its exact lexical source via the concrete syntax tree: elements without surrounding whitespace, attributes as their lexical value inside the quotes (`old` in `id = 'old'`), text with entity/character-reference/CDATA markup, and comments or processing instructions whole. XPath sees the XPath 1.0 logical text model (CDATA is text, adjacent text coalesces, empty text nodes do not exist, document node drops whitespace text and the XML declaration while keeping other processing instructions); `matched` is the logical string while the region is lexical source. Computed scalars are locator-only; malformed expressions throw `InvalidExpressionError` ({§mimetype-query}). |
37
12
 
38
- Raw source remains unchanged. Binary input is decoded as UTF-8.
13
+ Raw source remains unchanged; binary input is decoded as UTF-8.
@@ -1 +1 @@
1
- {"version":3,"file":"ApplicationXml.d.ts","sourceRoot":"","sources":["../src/ApplicationXml.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EAMd,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAc,MAAM,0BAA0B,CAAC;AAQjH,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,WAAW;IAC1C,UAAU,CAAC,OAAO,EAAE,cAAc,GAAG,UAAU,EAAE,CAoBzD;IAEQ,QAAQ,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAKlD;IAGQ,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAIpD;IAEc,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CA2B3H;CACJ"}
1
+ {"version":3,"file":"ApplicationXml.d.ts","sourceRoot":"","sources":["../src/ApplicationXml.ts"],"names":[],"mappings":"AACA,OAAO,EACH,WAAW,EAMd,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,EAAc,MAAM,0BAA0B,CAAC;AAQjH,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,WAAW;IAC1C,UAAU,CAAC,OAAO,EAAE,cAAc,GAAG,UAAU,EAAE,CAoBzD;IAEQ,QAAQ,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAKlD;IAGQ,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM,CAIpD;IAEc,KAAK,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CA2B3H;CACJ"}
@@ -1,3 +1,4 @@
1
+ // {§xml-shape}
1
2
  import { BaseHandler, InvalidExpressionError, QueryParseFailureError, queryJsonpathObject, projectDomToJson, serializeXpathNode, } from "@plurnk/plurnk-mimetypes";
2
3
  import { ParseError } from "@xmldom/xmldom";
3
4
  import * as xpath from "xpath";
@@ -38,7 +39,7 @@ export default class ApplicationXml extends BaseHandler {
38
39
  const source = XmlSource.parse(text);
39
40
  return source === null ? null : projectDomToJson(source.document, (node) => source.region(node)).value;
40
41
  }
41
- // {§mimetype-parse-issues} — xmldom's recoverable reports, or one for content that is not a document.
42
+ // {§mimetype-channel-selection} — xmldom's recoverable reports, or one for content that is not a document.
42
43
  parseIssues(content) {
43
44
  const text = textOf(content);
44
45
  if (text.length === 0)
@@ -1 +1 @@
1
- {"version":3,"file":"ApplicationXml.js","sourceRoot":"","sources":["../src/ApplicationXml.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,WAAW,EACX,sBAAsB,EACtB,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,EAChB,kBAAkB,GACrB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,UAAU,EAAsC,MAAM,gBAAgB,CAAC;AAChF,OAAO,KAAK,KAAK,MAAM,OAAO,CAA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,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;QACnI,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;YAC9B,oHAAoH;YACpH,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAA0B,CAAC,CAAC;YACzD,OAAO;gBACH,OAAO,EAAE,kBAAkB,CAAC,IAAI,CAAC;gBACjC,QAAQ,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,OAAO,GAAG,IAAI,GAAG,CAAC,KAAK,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,OAAO;gBAChF,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;aACzD,CAAC;QACN,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAED,SAAS,MAAM,CAAC,OAAuB;IACnC,OAAO,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,WAAW,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAC5F,CAAC;AAED,SAAS,IAAI,CAAC,MAAkB;IAC5B,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,WAAW,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC;AACxH,CAAC","sourcesContent":["// {§xml-shape}\nimport {\n BaseHandler,\n InvalidExpressionError,\n QueryParseFailureError,\n queryJsonpathObject,\n projectDomToJson,\n serializeXpathNode,\n} from \"@plurnk/plurnk-mimetypes\";\nimport type { HandlerContent, MimeSymbol, QueryDialect, QueryMatch, TextRegion } from \"@plurnk/plurnk-mimetypes\";\nimport { ParseError, type Element, type Node as XmlNode } from \"@xmldom/xmldom\";\nimport * as xpath from \"xpath\";\nimport XmlSource from \"./XmlSource.ts\";\n\n// A node whose type is ELEMENT_NODE is an element: the DOM's own contract.\nconst isElementNode = (node: XmlNode): node is Element => node.nodeType === 1;\n\nexport default class ApplicationXml extends BaseHandler {\n override extractRaw(content: HandlerContent): MimeSymbol[] {\n const text = textOf(content);\n if (text.length === 0) return [];\n const source = XmlSource.parse(text);\n if (source === null) return [];\n const root = source.document.documentElement;\n if (root === null) return [];\n const symbols: MimeSymbol[] = [];\n const append = (element: Element, name: string, kind: MimeSymbol[\"kind\"], container?: string): void => {\n const region = source.region(element);\n if (region === undefined) return;\n symbols.push({ name, kind, ...span(region), ...(container === undefined ? {} : { container }) });\n };\n append(root, root.tagName, \"module\");\n for (let child = root.firstChild; child !== null; child = child.nextSibling) {\n if (!isElementNode(child)) continue;\n const element = child;\n append(element, element.getAttribute(\"id\") || element.getAttribute(\"name\") || element.tagName, \"field\", root.tagName);\n }\n return symbols;\n }\n\n override deepJson(content: HandlerContent): unknown {\n const text = textOf(content);\n if (text.length === 0) return null;\n const source = XmlSource.parse(text);\n return source === null ? null : projectDomToJson(source.document, (node) => source.region(node)).value;\n }\n\n // {§mimetype-channel-selection} — xmldom's recoverable reports, or one for content that is not a document.\n override parseIssues(content: HandlerContent): number {\n const text = textOf(content);\n if (text.length === 0) return 0;\n return XmlSource.parse(text)?.issues ?? 1;\n }\n\n override async query(content: HandlerContent, dialect: QueryDialect, pattern: string, flags?: string): Promise<QueryMatch[]> {\n if (dialect !== \"xpath\" && dialect !== \"jsonpath\") return super.query(content, dialect, pattern, flags);\n let source: XmlSource;\n try { source = new XmlSource(textOf(content)); }\n catch (cause) {\n if (!(cause instanceof ParseError)) throw cause;\n throw new QueryParseFailureError({ mimetype: this.mimetype, cause });\n }\n if (dialect === \"jsonpath\") {\n const { value, regions } = projectDomToJson(source.document, (node) => source.region(node));\n return queryJsonpathObject(value, pattern, (pointer) => regions.get(pointer));\n }\n let result: xpath.SelectReturnType;\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- xpath types its nodes by the browser's DOM; the parsed document walks the same tree\n try { result = xpath.select(pattern, source.document as unknown as Node); }\n catch (cause) { throw new InvalidExpressionError({ dialect, expression: pattern, cause }); }\n // oxlint-disable-next-line typescript/no-base-to-string -- a scalar XPath value is a string, number or boolean; a node renders by its own toString\n if (!Array.isArray(result)) return result === null || result === undefined ? [] : [{ matched: String(result), matching: pattern }];\n return result.map((node, index) => {\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- an xpath result node is a node of the parsed tree\n const region = source.region(node as unknown as XmlNode);\n return {\n matched: serializeXpathNode(node),\n matching: result.length > 1 ? \"(\" + pattern + \")[\" + (index + 1) + \"]\" : pattern,\n ...(region === undefined ? {} : { regions: [region] }),\n };\n });\n }\n}\n\nfunction textOf(content: HandlerContent): string {\n return typeof content === \"string\" ? content : new TextDecoder(\"utf-8\").decode(content);\n}\n\nfunction span(region: TextRegion): { line: number; endLine: number; column: number; endColumn: number } {\n return { line: region.startLine, column: region.startColumn, endLine: region.endLine, endColumn: region.endColumn };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"XmlSource.d.ts","sourceRoot":"","sources":["../src/XmlSource.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,KAAK,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAmB,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAI5E,MAAM,CAAC,OAAO,OAAO,SAAS;;IAC1B,QAAQ,CAAC,QAAQ,oCAAC;IAGlB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAMxB,YAAY,OAAO,EAAE,MAAM,EAwC1B;IAID,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAM9C;IAED,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,UAAU,GAAG,SAAS,CA2BzC;CACJ"}
1
+ {"version":3,"file":"XmlSource.d.ts","sourceRoot":"","sources":["../src/XmlSource.ts"],"names":[],"mappings":"AACA,OAAO,EAAyB,KAAK,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAmB,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAI5E,MAAM,CAAC,OAAO,OAAO,SAAS;;IAC1B,QAAQ,CAAC,QAAQ,oCAAC;IAGlB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAMxB,YAAY,OAAO,EAAE,MAAM,EAwC1B;IAID,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,CAM9C;IAED,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,UAAU,GAAG,SAAS,CAgCzC;CACJ"}
package/dist/XmlSource.js CHANGED
@@ -5,7 +5,7 @@ import { TextCoordinates } from "@plurnk/plurnk-mimetypes";
5
5
  // source extents. DOM serialization cannot recover lexical quotes or entities.
6
6
  export default class XmlSource {
7
7
  document;
8
- // {§mimetype-parse-issues} — xmldom keeps building past an `error` report (an entity declared
8
+ // {§mimetype-channel-selection} — xmldom keeps building past an `error` report (an entity declared
9
9
  // only in the internal DTD subset, which it does not process); each one is a recovery site.
10
10
  issues;
11
11
  #tree;
@@ -58,7 +58,7 @@ export default class XmlSource {
58
58
  }
59
59
  }
60
60
  }
61
- // {§mimetype-parse-issues} — content that is not a document (a template, a truncated file) has
61
+ // {§mimetype-channel-selection} — content that is not a document (a template, a truncated file) has
62
62
  // no source: null, never a throw. Anything but xmldom's ParseError is a defect and keeps its identity.
63
63
  static parse(content) {
64
64
  try {
@@ -91,9 +91,16 @@ export default class XmlSource {
91
91
  return undefined;
92
92
  syntax = syntax.parent;
93
93
  }
94
- const from = syntax.from;
94
+ let from = syntax.from;
95
95
  let to = syntax.to;
96
- if (node.nodeType === 3) {
96
+ if (node.nodeType === 2) {
97
+ const value = syntax.getChild("AttributeValue");
98
+ if (value === null || value.to - value.from < 2)
99
+ return undefined;
100
+ from = value.from + 1;
101
+ to = value.to - 1;
102
+ }
103
+ else if (node.nodeType === 3) {
97
104
  while (syntax.nextSibling !== null && syntax.nextSibling.from === to && text(syntax.nextSibling.name)) {
98
105
  syntax = syntax.nextSibling;
99
106
  to = syntax.to;
@@ -1 +1 @@
1
- {"version":3,"file":"XmlSource.js","sourceRoot":"","sources":["../src/XmlSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAa,MAAM,gBAAgB,CAAC;AAClE,OAAO,EAAE,eAAe,EAAmB,MAAM,0BAA0B,CAAC;AAE5E,8EAA8E;AAC9E,+EAA+E;AAC/E,MAAM,CAAC,OAAO,OAAO,SAAS;IACjB,QAAQ,CAAC;IAClB,8FAA8F;IAC9F,4FAA4F;IACnF,MAAM,CAAS;IACf,KAAK,CAAC;IACN,YAAY,CAAkB;IAC9B,WAAW,CAAW;IACtB,OAAO,CAAS;IAEzB,YAAY,OAAe;QACvB,IAAI,MAAM,GAAG,CAAC,CAAC;QACf,iGAAiG;QACjG,IAAI,CAAC,QAAQ,GAAG,IAAI,SAAS,CAAC,EAAE,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;gBAC/C,IAAI,KAAK,KAAK,OAAO;oBAAE,MAAM,IAAI,CAAC,CAAC;YACvC,CAAC,EAAE,CAAC,CAAC,eAAe,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAC1C,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACnC,IAAI,CAAC,YAAY,GAAG,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;QACjD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;QAC9B,wEAAwE;QACxE,mFAAmF;QAC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ordinates, type TextRegion } from \"@plurnk/plurnk-mimetypes\";\n\n// {§mimetype-query} — XPath owns node identity; the concrete syntax tree owns\n// source extents. DOM serialization cannot recover lexical quotes or entities.\nexport default class XmlSource {\n readonly document;\n // {§mimetype-channel-selection} — xmldom keeps building past an `error` report (an entity declared\n // only in the internal DTD subset, which it does not process); each one is a recovery site.\n readonly issues: number;\n readonly #tree;\n readonly #coordinates: TextCoordinates;\n readonly #lineStarts: number[];\n readonly #length: number;\n\n constructor(content: string) {\n let issues = 0;\n // A `fatalError` still throws xmldom's ParseError: no document exists ({@link XmlSource.parse}).\n this.document = new DOMParser({ onError: (level) => {\n if (level === \"error\") issues += 1;\n } }).parseFromString(content, \"text/xml\");\n this.issues = issues;\n this.#tree = parser.parse(content);\n this.#coordinates = new TextCoordinates(content);\n this.#length = content.length;\n // xmldom's XML line normalization; its columns count UTF-16 code units.\n // Convert its locator back to original offsets before applying Plurnk coordinates.\n this.#lineStarts = [0, ...[...content.matchAll(/\\r[\\n\\u0085]|[\\r\\n\\u0085\\u2028\\u2029]/g)].map((match) => match.index + match[0].length)];\n // XPath 1.0 §5.7 has logical text nodes, not separate CDATA nodes.\n const pending: Node[] = [this.document];\n while (pending.length > 0) {\n const parent = pending.pop()!;\n for (let child = parent.firstChild; child !== null;) {\n const next = child.nextSibling;\n if (child.nodeType === 4) {\n const text = this.document.createTextNode(child.nodeValue ?? \"\");\n text.lineNumber = child.lineNumber;\n text.columnNumber = child.columnNumber;\n parent.replaceChild(text, child);\n } else if (child.nodeType === 1) pending.push(child);\n child = next;\n }\n }\n this.document.normalize();\n pending.push(this.document);\n while (pending.length > 0) {\n const parent = pending.pop()!;\n for (let child = parent.firstChild; child !== null;) {\n const next = child.nextSibling;\n if ((child.nodeType === 3 && (parent === this.document || child.nodeValue === \"\"))\n || (child.nodeType === 7 && child.nodeName === \"xml\")) parent.removeChild(child);\n else if (child.nodeType === 1) pending.push(child);\n child = next;\n }\n }\n }\n\n // {§mimetype-channel-selection} — content that is not a document (a template, a truncated file) has\n // no source: null, never a throw. Anything but xmldom's ParseError is a defect and keeps its identity.\n static parse(content: string): XmlSource | null {\n try { return new XmlSource(content); }\n catch (cause) {\n if (cause instanceof ParseError) return null;\n throw cause;\n }\n }\n\n region(node: Node): TextRegion | undefined {\n if (node.nodeType === 9) return this.#coordinates.regionFromOffsets(0, this.#length) ?? undefined;\n const { lineNumber, columnNumber } = node;\n const start = lineNumber === undefined ? undefined : this.#lineStarts[lineNumber - 1];\n if (start === undefined || columnNumber === undefined) return undefined;\n const offset = start + columnNumber - 1;\n const kind = node.nodeType === 1 ? \"Element\"\n : node.nodeType === 2 ? \"Attribute\"\n : node.nodeType === 4 ? \"Cdata\"\n : node.nodeType === 7 ? \"ProcessingInst\"\n : node.nodeType === 8 ? \"Comment\"\n : node.nodeType === 10 ? \"DoctypeDecl\" : undefined;\n let syntax = this.#tree.resolveInner(offset, 1);\n const text = (name: string): boolean => name === \"Text\" || name === \"EntityReference\" || name === \"CharacterReference\" || name === \"Cdata\";\n while (kind === undefined ? node.nodeType !== 3 || !text(syntax.name) : syntax.name !== kind) {\n if (syntax.parent === null) return undefined;\n syntax = syntax.parent;\n }\n let from = syntax.from;\n let to = syntax.to;\n if (node.nodeType === 2) {\n const value = syntax.getChild(\"AttributeValue\");\n if (value === null || value.to - value.from < 2) return undefined;\n from = value.from + 1;\n to = value.to - 1;\n } else if (node.nodeType === 3) {\n while (syntax.nextSibling !== null && syntax.nextSibling.from === to && text(syntax.nextSibling.name)) {\n syntax = syntax.nextSibling;\n to = syntax.to;\n }\n }\n return this.#coordinates.regionFromOffsets(from, to) ?? undefined;\n }\n}\n"]}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["export { default as ApplicationXml } from \"./ApplicationXml.ts\";\nexport { default } from \"./ApplicationXml.ts\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plurnk/plurnk-mimetypes-application-xml",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "description": "application/xml and text/xml mimetype handler for plurnk-service. DOM-tree extraction via @xmldom/xmldom; xpath via the xpath package; framework structural projections.",
5
5
  "keywords": [
6
6
  "plurnk",
@@ -48,7 +48,7 @@
48
48
  ],
49
49
  "scripts": {
50
50
  "test:lint": "tsc --noEmit",
51
- "test:unit": "node --conditions=plurnk-dev --test ${PLURNK_TEST_CONCURRENCY:+--test-concurrency=$PLURNK_TEST_CONCURRENCY} 'src/**/*.test.ts'",
51
+ "test:unit": "node --conditions=plurnk-dev --experimental-test-coverage --test-coverage-include-all '--test-coverage-include=src/**' --test ${PLURNK_TEST_CONCURRENCY:+--test-concurrency=$PLURNK_TEST_CONCURRENCY} 'src/**/*.test.ts'",
52
52
  "test": "npm run test:lint && npm run test:unit",
53
53
  "build:clean": "rm -rf dist",
54
54
  "build:dist": "tsc -p tsconfig.build.json",
@@ -59,19 +59,19 @@
59
59
  "dependencies": {
60
60
  "@lezer/xml": "^1.0.6",
61
61
  "@xmldom/xmldom": "^0.9.10",
62
- "xpath": "^0.0.35"
62
+ "xpath": "^0.0.36"
63
63
  },
64
64
  "peerDependencies": {
65
65
  "@plurnk/plurnk-mimetypes": "^3.0.0"
66
66
  },
67
67
  "homepage": "https://github.com/plurnk/plurnk-service/tree/main/plurnk-mimetypes-application-xml#readme",
68
68
  "bugs": {
69
- "url": "https://repo.possumtech.com/plurnk/plurnk-service/issues"
69
+ "url": "https://github.com/plurnk/plurnk-service/issues"
70
70
  },
71
71
  "repository": {
72
72
  "type": "git",
73
73
  "url": "git+https://github.com/plurnk/plurnk-service.git",
74
74
  "directory": "plurnk-mimetypes-application-xml"
75
75
  },
76
- "gitHead": "d2647f7ec0d352b276714f22a93267aac04634b3"
76
+ "gitHead": "49f92d9351021ae0729d69e72ab9b1b95e3a974b"
77
77
  }