@hpcc-js/wasm-expat 1.8.0 → 1.10.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hpcc-js/wasm-expat",
3
- "version": "1.8.0",
3
+ "version": "1.10.0",
4
4
  "description": "hpcc-js - WASM expat",
5
5
  "type": "module",
6
6
  "exports": {
@@ -26,7 +26,7 @@
26
26
  "build-dev": "run-p gen-types bundle-dev",
27
27
  "build": "run-p gen-types bundle",
28
28
  "lint-skypack": "npx -y @skypack/package-check",
29
- "lint-eslint": "eslint src/**/*.ts tests/**/*.ts",
29
+ "lint-eslint": "eslint \"src/**/*.ts\" \"tests/**/*.ts\"",
30
30
  "lint": "run-p lint-eslint",
31
31
  "test-browser": "vitest run --project browser",
32
32
  "test-node": "vitest run --project node",
@@ -36,7 +36,8 @@
36
36
  "update-major": "npx -y npm-check-updates -u"
37
37
  },
38
38
  "devDependencies": {
39
- "@hpcc-js/esbuild-plugins": "1.5.2"
39
+ "@hpcc-js/esbuild-plugins": "1.7.0",
40
+ "@hpcc-js/wasm-util": "1.0.0"
40
41
  },
41
42
  "keywords": [
42
43
  "graphviz",
@@ -54,5 +55,5 @@
54
55
  },
55
56
  "homepage": "https://hpcc-systems.github.io/hpcc-js-wasm/",
56
57
  "license": "Apache-2.0",
57
- "gitHead": "bd1b2a90ecccc79105da683bd2cfbc69296b693e"
58
+ "gitHead": "6799e024fc9186c4a4f87294862142f00628e597"
58
59
  }
package/src/expat.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  // @ts-expect-error importing from a wasm file is resolved via a custom esbuild plugin
2
- import load, { reset } from "../../../build/packages/expat/src-cpp/expatlib/expatlib.wasm";
2
+ import load, { reset } from "../../../build/packages/expat/expatlib.wasm";
3
+ import type { MainModule, map_string_string } from "../../../build/packages/expat/expatlib.js";
4
+ import { MainModuleEx } from "@hpcc-js/wasm-util";
3
5
 
4
6
  export type Attributes = { [key: string]: string };
5
7
  export interface IParser {
@@ -8,18 +10,20 @@ export interface IParser {
8
10
  characterData(content: string): void;
9
11
  }
10
12
 
11
- function parseAttrs(attrs: string): Attributes {
13
+ function parseAttrs(attrs: map_string_string): Attributes {
12
14
  const retVal: Attributes = {};
13
- const keys = attrs;
14
- const sep = `${String.fromCharCode(1)}`;
15
- const sep2 = `${sep}${sep}`;
16
- keys.split(sep2).filter((key: string) => !!key).forEach((key: string) => {
17
- const parts = key.split(sep);
18
- retVal[parts[0]] = parts[1];
19
- });
15
+ const keys = attrs.keys();
16
+ const size = keys.size();
17
+ for (let i = 0; i < size; ++i) {
18
+ const key = keys.get(i);
19
+ const value = attrs.get(key!);
20
+ retVal[key!] = value!;
21
+ }
20
22
  return retVal;
21
23
  }
22
24
 
25
+ let g_expat: Promise<Expat>;
26
+
23
27
  /**
24
28
  * Expat XML parser WASM library, provides a simplified wrapper around the Expat XML Parser library.
25
29
  *
@@ -46,9 +50,10 @@ function parseAttrs(attrs: string): Attributes {
46
50
  * ```
47
51
 
48
52
  */
49
- export class Expat {
53
+ export class Expat extends MainModuleEx<MainModule> {
50
54
 
51
- private constructor(protected _module: any) {
55
+ private constructor(_module: MainModule) {
56
+ super(_module);
52
57
  }
53
58
 
54
59
  /**
@@ -61,9 +66,10 @@ export class Expat {
61
66
  * @returns A promise to an instance of the Expat class.
62
67
  */
63
68
  static load(): Promise<Expat> {
64
- return load().then((module: any) => {
65
- return new Expat(module);
66
- });
69
+ if (!g_expat) {
70
+ g_expat = (load() as Promise<MainModule>).then((module) => new Expat(module));
71
+ }
72
+ return g_expat;
67
73
  }
68
74
 
69
75
  /**
@@ -78,7 +84,7 @@ export class Expat {
78
84
  * @returns The Expat c++ version
79
85
  */
80
86
  version(): string {
81
- return this._module.CExpat.prototype.version();
87
+ return this._module.version();
82
88
  }
83
89
 
84
90
  /**
@@ -93,21 +99,11 @@ export class Expat {
93
99
  * @returns `true`|`false` if the XML parse succeeds.
94
100
  */
95
101
  parse(xml: string, callback: IParser): boolean {
96
- const parser = new this._module.CExpatJS();
97
- parser.startElement = function () {
98
- callback.startElement(this.tag(), parseAttrs(this.attrs()));
99
- };
100
- parser.endElement = function () {
101
- callback.endElement(this.tag());
102
- };
103
- parser.characterData = function () {
104
- callback.characterData(this.content());
105
- };
106
- parser.create();
107
- const retVal = parser.parse(xml);
108
- parser.destroy();
109
- this._module.destroy(parser);
110
- return retVal;
102
+ return this._module.parse(xml, {
103
+ startElement: (tag: string, attrs: map_string_string) => callback.startElement(tag, parseAttrs(attrs)),
104
+ endElement: (tag: string) => callback.endElement(tag),
105
+ characterData: (content: string) => callback.characterData(content)
106
+ });
111
107
  }
112
108
  }
113
109
 
@@ -1,3 +1,3 @@
1
1
  export declare const PKG_NAME = "@hpcc-js/wasm-expat";
2
- export declare const PKG_VERSION = "1.6.1";
3
- export declare const BUILD_VERSION = "3.12.0";
2
+ export declare const PKG_VERSION = "1.8.0";
3
+ export declare const BUILD_VERSION = "4.0.0";
package/types/expat.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import type { MainModule } from "../../../build/packages/expat/expatlib.js";
2
+ import { MainModuleEx } from "@hpcc-js/wasm-util";
1
3
  export type Attributes = {
2
4
  [key: string]: string;
3
5
  };
@@ -32,8 +34,7 @@ export interface IParser {
32
34
  * ```
33
35
 
34
36
  */
35
- export declare class Expat {
36
- protected _module: any;
37
+ export declare class Expat extends MainModuleEx<MainModule> {
37
38
  private constructor();
38
39
  /**
39
40
  * Compiles and instantiates the raw wasm.