@docx4j/jsonix 3.2.0 → 3.3.0

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/jsonix.mjs CHANGED
@@ -1,6 +1,8 @@
1
- // ES-module entry point (package.json "exports" -> "import").
2
- // The runtime stays a single CommonJS bundle (jsonix.js); this wrapper gives ESM consumers and
3
- // bundlers a static named export, which the UMD footer of jsonix.js cannot provide.
4
- import cjs from './jsonix.js';
5
- export const Jsonix = cjs.Jsonix;
6
- export default cjs;
1
+ // ES-module entry for browsers and browser bundlers (package.json "exports" -> "default" -> "import").
2
+ // No Node dependency is reachable from this file: the browser supplies DOMParser, XMLSerializer and
3
+ // XMLHttpRequest. Node and Node bundlers take jsonix.node.mjs through the "node" condition instead.
4
+ // (jsonix-CR-005 section 7.1)
5
+ import factory from './jsonix-factory.js';
6
+ const { Jsonix } = factory();
7
+ export { Jsonix };
8
+ export default { Jsonix };
@@ -0,0 +1,35 @@
1
+ // ES-module entry for Node and Node bundlers (package.json "exports" -> "node" -> "import").
2
+ // The DOM dependency is a static import, which every bundler resolves, instead of the UMD footer's
3
+ // runtime resolution that a bundle cannot perform. (jsonix-CR-005 section 7.1)
4
+ import { createRequire } from 'node:module';
5
+ import fs from 'node:fs';
6
+ import xmldom from '@xmldom/xmldom';
7
+ import factory from './jsonix-factory.js';
8
+
9
+ // xmlhttprequest is a CommonJS package that requires Node built-ins (url, http, https, child_process)
10
+ // at load time, which an ES-module bundle cannot carry: esbuild emits "Dynamic require of 'url' is not
11
+ // supported". It is needed only by Unmarshaller.unmarshalURL and Jsonix.DOM.load, so it is resolved
12
+ // lazily, at first use, with a real require that bundlers leave alone. Parsing never touches it.
13
+ // import.meta.url is empty when a bundler emits CommonJS from this file (it applies the "import"
14
+ // condition to any `import` statement, whatever the output format); resolve from the working
15
+ // directory then.
16
+ const nodeRequire = (() => {
17
+ try {
18
+ return createRequire(import.meta.url);
19
+ } catch (e) {
20
+ return createRequire(process.cwd() + '/');
21
+ }
22
+ })();
23
+ const xmlhttprequest = {
24
+ get XMLHttpRequest() {
25
+ try {
26
+ return nodeRequire('xmlhttprequest').XMLHttpRequest;
27
+ } catch (e) {
28
+ throw new Error('Jsonix: unmarshalURL / Jsonix.DOM.load need the xmlhttprequest package, which could not be loaded: ' + e.message);
29
+ }
30
+ },
31
+ };
32
+
33
+ const { Jsonix } = factory(xmldom, xmlhttprequest, fs);
34
+ export { Jsonix };
35
+ export default { Jsonix };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docx4j/jsonix",
3
- "version": "3.2.0",
3
+ "version": "3.3.0",
4
4
  "description": "Jsonix (JSON interfaces for XML) is a JavaScript library which allows converting between XML and JSON structures.",
5
5
  "keywords": [
6
6
  "json",
@@ -24,12 +24,7 @@
24
24
  "bugs": {
25
25
  "url": "https://github.com/plutext/jsonix/issues"
26
26
  },
27
- "licenses": [
28
- {
29
- "type": "(Apache-2.0 AND BSD-2-Clause)",
30
- "url": "https://github.com/plutext/jsonix/raw/master/LICENSE"
31
- }
32
- ],
27
+ "license": "(Apache-2.0 AND BSD-2-Clause)",
33
28
  "author": {
34
29
  "name": "Alexey Valikov",
35
30
  "url": "http://github.com/highsource"
@@ -52,29 +47,37 @@
52
47
  "module": "jsonix.mjs",
53
48
  "repository": {
54
49
  "type": "git",
55
- "url": "https://github.com/plutext/jsonix.git"
50
+ "url": "git+https://github.com/plutext/jsonix.git"
56
51
  },
57
52
  "types": "./types/main.d.ts",
58
53
  "exports": {
59
54
  ".": {
60
55
  "types": "./types/main.d.ts",
61
- "import": "./jsonix.mjs",
62
- "require": "./jsonix.js"
56
+ "node": {
57
+ "import": "./jsonix.node.mjs",
58
+ "require": "./jsonix.js"
59
+ },
60
+ "default": {
61
+ "import": "./jsonix.mjs",
62
+ "require": "./jsonix.js"
63
+ }
63
64
  },
64
65
  "./jsonix.js": "./jsonix.js",
66
+ "./jsonix-factory.js": "./jsonix-factory.js",
65
67
  "./package.json": "./package.json"
66
68
  },
67
69
  "scripts": {
68
70
  "test": "nodeunit tests/tests.js",
69
71
  "typecheck": "tsc -p tests/typescript/tsconfig.json && tsc -p tests/typescript/tsconfig.node16.json",
70
- "test:esm": "node tests/typescript/esm-smoke.mjs"
72
+ "test:esm": "node tests/typescript/esm-smoke.mjs",
73
+ "test:bundle": "node tests/bundle/bundle-test.mjs"
71
74
  },
72
75
  "dependencies": {
73
76
  "@xmldom/xmldom": "^0.9.7",
74
- "amdefine": "^1.0.1",
75
77
  "xmlhttprequest": "^1.8.0"
76
78
  },
77
79
  "devDependencies": {
80
+ "esbuild": "~0.28.2",
78
81
  "node-static": "^0.7.11",
79
82
  "nodeunit": "^0.11.3",
80
83
  "typescript": "~5.6.3"
@@ -24,12 +24,7 @@
24
24
  "bugs": {
25
25
  "url": "https://github.com/plutext/jsonix/issues"
26
26
  },
27
- "licenses": [
28
- {
29
- "type": "BSD-3-Clause",
30
- "url": "https://github.com/plutext/jsonix/raw/master/LICENSE"
31
- }
32
- ],
27
+ "license": "(Apache-2.0 AND BSD-2-Clause)",
33
28
  "author": {
34
29
  "name": "Alexey Valikov",
35
30
  "url": "http://github.com/highsource"
@@ -47,7 +42,7 @@
47
42
  "main": "jsonix.js",
48
43
  "repository": {
49
44
  "type": "git",
50
- "url": "https://github.com/plutext/jsonix.git"
45
+ "url": "git+https://github.com/plutext/jsonix.git"
51
46
  },
52
47
  "scripts": {
53
48
  "test": "nodeunit tests/tests.js"
package/types/main.d.ts CHANGED
@@ -52,6 +52,54 @@ export namespace Jsonix {
52
52
  }
53
53
  }
54
54
 
55
+ /**
56
+ * DOM access as the runtime does it: @xmldom/xmldom and xmlhttprequest when injected (Node),
57
+ * the browser's DOMParser / XMLSerializer / XMLHttpRequest otherwise (jsonix-CR-003 part 1).
58
+ */
59
+ /**
60
+ * A DOM implementation a consumer can supply with `DOM.use`: any object exposing the W3C
61
+ * constructors, for example the `@xmldom/xmldom` module. Missing members fall through to the
62
+ * next option (injected xmldom, then browser globals).
63
+ */
64
+ export interface DomImplementation {
65
+ DOMParser?: new (options?: unknown) => { parseFromString(text: string, mimeType: string): Document };
66
+ XMLSerializer?: new () => { serializeToString(node: Node): string };
67
+ DOMImplementation?: new () => { createDocument(...args: unknown[]): Document };
68
+ }
69
+
70
+ export namespace DOM {
71
+ /**
72
+ * Supplies the DOM implementation to use, consulted before the xmldom injected into the
73
+ * runtime and before browser globals; `null` clears it (jsonix-CR-005). For workers, sandboxes
74
+ * and bundles the runtime cannot detect.
75
+ */
76
+ function use(implementation: DomImplementation | null): void;
77
+ /** The implementation in effect: the one given to `use`, else the injected xmldom, else `null` (browser globals will be tried). */
78
+ function getImplementation(): DomImplementation | null;
79
+ /** XML 1.0 section 2.11 line-ending normalisation: CR LF and bare CR become LF (jsonix-CR-004). */
80
+ function normalizeLineEndings10(text: string): string;
81
+ /** XML 1.1 section 2.11: additionally CR NEL, NEL (U+0085) and LINE SEPARATOR (U+2028) become LF. */
82
+ function normalizeLineEndings11(text: string): string;
83
+ /** True when the text starts with an XML declaration whose version is 1.1. `parse` uses it to pick the normalisation. */
84
+ function isXml11(text: string): boolean;
85
+ /** True when a DOM implementation (supplied, injected xmldom, or the browser's) is available. */
86
+ function isDomImplementationAvailable(): boolean;
87
+ /** A new, empty XML document. Takes no arguments; the runtime ignores any that are passed. */
88
+ function createDocument(): Document;
89
+ /** Serialises a node to XML text; throws if no serializer is available. */
90
+ function serialize(node: Node): string;
91
+ /**
92
+ * Parses XML text into a document; throws on malformed input. Line endings are normalised per the
93
+ * document's XML version (1.0 unless the declaration says 1.1), so raw U+0085 and U+2028 survive in
94
+ * XML 1.0 text (jsonix-CR-004).
95
+ */
96
+ function parse(text: string): Document;
97
+ /** Loads and parses the URL through the runtime's XMLHttpRequest transport (see Unmarshaller.unmarshalURL). */
98
+ function load(url: string, callback: (doc: Document) => void, options?: UnmarshalOptions): void;
99
+ /** Whether the xlink namespace work-around for older Chrome builds is needed in this environment. */
100
+ function isXlinkFixRequired(): boolean;
101
+ }
102
+
55
103
  /**
56
104
  * An element: what an unmarshaller returns, what a marshaller accepts, and the value of an
57
105
  * elementRef property. Generated declarations alias this per global element, for example
@@ -168,6 +216,13 @@ export namespace Jsonix {
168
216
  */
169
217
  constructor(mappings: M[], options?: ContextOptions);
170
218
 
219
+ /**
220
+ * The namespace-to-prefix table this context marshals with, copied from
221
+ * `options.namespacePrefixes` at construction. Read-only: derive a per-document table rather
222
+ * than mutating the shared context.
223
+ */
224
+ readonly namespacePrefixes: { readonly [namespaceURI: string]: string };
225
+
171
226
  createUnmarshaller(): Unmarshaller<RootElementOf<M>>;
172
227
  createMarshaller(): Marshaller;
173
228