@kodexa-ai/document-wasm-ts 8.0.0-develop-20663153063 → 8.0.0-develop-20664344428
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/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/kodexa-worker.js +401 -0
- package/dist/kodexa-worker.js.map +7 -0
- package/dist/kodexa.wasm +0 -0
- package/dist/worker/KodexaWorker.d.ts +134 -0
- package/dist/worker/KodexaWorker.d.ts.map +1 -0
- package/dist/worker/KodexaWorker.js +252 -0
- package/dist/worker/KodexaWorker.js.map +1 -0
- package/dist/worker/KodexaWorkerDocument.d.ts +192 -0
- package/dist/worker/KodexaWorkerDocument.d.ts.map +1 -0
- package/dist/worker/KodexaWorkerDocument.js +370 -0
- package/dist/worker/KodexaWorkerDocument.js.map +1 -0
- package/dist/worker/KodexaWorkerNode.d.ts +276 -0
- package/dist/worker/KodexaWorkerNode.d.ts.map +1 -0
- package/dist/worker/KodexaWorkerNode.js +517 -0
- package/dist/worker/KodexaWorkerNode.js.map +1 -0
- package/dist/worker/index.d.ts +29 -0
- package/dist/worker/index.d.ts.map +1 -0
- package/dist/worker/index.js +28 -0
- package/dist/worker/index.js.map +1 -0
- package/dist/worker/kodexa-worker.d.ts +15 -0
- package/dist/worker/kodexa-worker.d.ts.map +1 -0
- package/dist/worker/kodexa-worker.js +203 -0
- package/dist/worker/kodexa-worker.js.map +1 -0
- package/dist/worker/types.d.ts +80 -0
- package/dist/worker/types.d.ts.map +1 -0
- package/dist/worker/types.js +8 -0
- package/dist/worker/types.js.map +1 -0
- package/package.json +16 -3
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kodexa Web Worker Entry Point
|
|
3
|
+
*
|
|
4
|
+
* This worker owns the Go WASM instance and exposes an RPC-style API
|
|
5
|
+
* via postMessage. All heavy document processing happens here,
|
|
6
|
+
* keeping the main thread responsive.
|
|
7
|
+
*
|
|
8
|
+
* Initialization order (critical):
|
|
9
|
+
* 1. sql.js WASM loaded and bridge exposed to globalThis
|
|
10
|
+
* 2. wasm_exec.js loaded (defines globalThis.Go)
|
|
11
|
+
* 3. kodexa.wasm instantiated and Go runtime started
|
|
12
|
+
* 4. Worker signals 'ready' to main thread
|
|
13
|
+
*/
|
|
14
|
+
import { setSqlInstance, exposeBridgeFunctions, loadDirectOp } from '../wasm/sqljs-core';
|
|
15
|
+
// Worker state
|
|
16
|
+
let initialized = false;
|
|
17
|
+
let initPromise = null;
|
|
18
|
+
let config = {};
|
|
19
|
+
/**
|
|
20
|
+
* Initialize sql.js in the worker context.
|
|
21
|
+
* Uses dynamic import from ESM CDN for browser workers.
|
|
22
|
+
*/
|
|
23
|
+
async function initializeSqlJs() {
|
|
24
|
+
// For browser workers, we need to load sql.js from a CDN that supports ESM
|
|
25
|
+
// We use the esm.sh CDN which provides ESM versions of npm packages
|
|
26
|
+
const sqlJsUrl = 'https://esm.sh/sql.js@1.11.0';
|
|
27
|
+
// Dynamic import from CDN
|
|
28
|
+
const sqlJsModule = await import(/* webpackIgnore: true */ sqlJsUrl);
|
|
29
|
+
const initSqlJs = sqlJsModule.default;
|
|
30
|
+
// Configure sql.js WASM location
|
|
31
|
+
const sqlConfig = {};
|
|
32
|
+
sqlConfig.locateFile = () => 'https://sql.js.org/dist/sql-wasm.wasm';
|
|
33
|
+
const SQL = await initSqlJs(sqlConfig);
|
|
34
|
+
setSqlInstance(SQL);
|
|
35
|
+
exposeBridgeFunctions();
|
|
36
|
+
// Expose loadDocument function
|
|
37
|
+
self.loadDocument = (bytes) => {
|
|
38
|
+
const handle = loadDirectOp(bytes);
|
|
39
|
+
if (handle === 0) {
|
|
40
|
+
console.error('[worker] Failed to load database');
|
|
41
|
+
return 0;
|
|
42
|
+
}
|
|
43
|
+
return self.createDocumentFromHandle(handle);
|
|
44
|
+
};
|
|
45
|
+
console.log('[worker] sql.js initialized');
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Load wasm_exec.js in the worker context.
|
|
49
|
+
* We use fetch + eval since workers don't have document.createElement.
|
|
50
|
+
*/
|
|
51
|
+
async function loadWasmExec() {
|
|
52
|
+
if (self.Go) {
|
|
53
|
+
return; // Already loaded
|
|
54
|
+
}
|
|
55
|
+
const baseUrl = config.wasmBaseUrl || self.location.origin;
|
|
56
|
+
const wasmExecUrl = `${baseUrl}/wasm_exec.js`;
|
|
57
|
+
try {
|
|
58
|
+
const response = await fetch(wasmExecUrl);
|
|
59
|
+
if (!response.ok) {
|
|
60
|
+
throw new Error(`Failed to fetch wasm_exec.js: ${response.statusText}`);
|
|
61
|
+
}
|
|
62
|
+
const code = await response.text();
|
|
63
|
+
// eslint-disable-next-line no-eval
|
|
64
|
+
eval(code);
|
|
65
|
+
console.log('[worker] wasm_exec.js loaded');
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
throw new Error(`Failed to load wasm_exec.js: ${error}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Load and instantiate the Go WASM module.
|
|
73
|
+
*/
|
|
74
|
+
async function loadGoWasm() {
|
|
75
|
+
const baseUrl = config.wasmBaseUrl || self.location.origin;
|
|
76
|
+
const wasmUrl = `${baseUrl}/kodexa.wasm`;
|
|
77
|
+
const response = await fetch(wasmUrl);
|
|
78
|
+
if (!response.ok) {
|
|
79
|
+
throw new Error(`Failed to fetch kodexa.wasm: ${response.statusText}`);
|
|
80
|
+
}
|
|
81
|
+
const wasmBytes = await response.arrayBuffer();
|
|
82
|
+
// Create Go runtime and instantiate WASM
|
|
83
|
+
const go = new self.Go();
|
|
84
|
+
const result = await WebAssembly.instantiate(wasmBytes, go.importObject);
|
|
85
|
+
// Start the Go program (registers functions on globalThis)
|
|
86
|
+
go.run(result.instance);
|
|
87
|
+
// Configure log level
|
|
88
|
+
const logLevel = config.logLevel || 'warn';
|
|
89
|
+
if (self.kodexa_setLogLevel) {
|
|
90
|
+
self.kodexa_setLogLevel(logLevel);
|
|
91
|
+
}
|
|
92
|
+
console.log('[worker] Go WASM loaded');
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Initialize the worker with all WASM components.
|
|
96
|
+
*/
|
|
97
|
+
async function initialize(workerConfig) {
|
|
98
|
+
if (initialized) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (initPromise) {
|
|
102
|
+
return initPromise;
|
|
103
|
+
}
|
|
104
|
+
config = workerConfig || {};
|
|
105
|
+
initPromise = (async () => {
|
|
106
|
+
try {
|
|
107
|
+
// Step 1: Initialize sql.js (MUST be first)
|
|
108
|
+
await initializeSqlJs();
|
|
109
|
+
// Step 2: Load wasm_exec.js
|
|
110
|
+
await loadWasmExec();
|
|
111
|
+
// Step 3: Load Go WASM
|
|
112
|
+
await loadGoWasm();
|
|
113
|
+
initialized = true;
|
|
114
|
+
console.log('[worker] Kodexa WASM fully initialized');
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
console.error('[worker] Initialization failed:', error);
|
|
118
|
+
throw error;
|
|
119
|
+
}
|
|
120
|
+
})();
|
|
121
|
+
return initPromise;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Handle RPC call from main thread.
|
|
125
|
+
*/
|
|
126
|
+
function handleCall(request) {
|
|
127
|
+
const { id, method, args } = request;
|
|
128
|
+
try {
|
|
129
|
+
const fn = self[method];
|
|
130
|
+
if (typeof fn !== 'function') {
|
|
131
|
+
return {
|
|
132
|
+
id,
|
|
133
|
+
success: false,
|
|
134
|
+
error: `Function '${method}' not found on globalThis`,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
const result = fn(...(args || []));
|
|
138
|
+
return { id, success: true, result };
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
return {
|
|
142
|
+
id,
|
|
143
|
+
success: false,
|
|
144
|
+
error: error instanceof Error ? error.message : String(error),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Main message handler.
|
|
150
|
+
*/
|
|
151
|
+
self.onmessage = async (event) => {
|
|
152
|
+
const data = event.data;
|
|
153
|
+
// Handle init message
|
|
154
|
+
if ('type' in data && data.type === 'init') {
|
|
155
|
+
try {
|
|
156
|
+
await initialize(data.config);
|
|
157
|
+
const readyMessage = { type: 'ready' };
|
|
158
|
+
self.postMessage(readyMessage);
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
const errorMessage = {
|
|
162
|
+
type: 'error',
|
|
163
|
+
error: error instanceof Error ? error.message : String(error),
|
|
164
|
+
};
|
|
165
|
+
self.postMessage(errorMessage);
|
|
166
|
+
}
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
// Handle RPC call
|
|
170
|
+
if ('type' in data && data.type === 'call') {
|
|
171
|
+
// Ensure initialized
|
|
172
|
+
if (!initialized) {
|
|
173
|
+
const response = {
|
|
174
|
+
id: data.id,
|
|
175
|
+
success: false,
|
|
176
|
+
error: 'Worker not initialized. Send init message first.',
|
|
177
|
+
};
|
|
178
|
+
self.postMessage(response);
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
const response = handleCall(data);
|
|
182
|
+
self.postMessage(response);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
// Auto-initialize on load if config is in URL params
|
|
186
|
+
// This allows the worker to be used without explicit init message
|
|
187
|
+
const urlParams = new URLSearchParams(self.location.search);
|
|
188
|
+
const autoInit = urlParams.get('autoInit');
|
|
189
|
+
if (autoInit === 'true') {
|
|
190
|
+
const wasmBaseUrl = urlParams.get('wasmBaseUrl') || undefined;
|
|
191
|
+
const logLevel = urlParams.get('logLevel') || undefined;
|
|
192
|
+
initialize({ wasmBaseUrl, logLevel }).then(() => {
|
|
193
|
+
const readyMessage = { type: 'ready' };
|
|
194
|
+
self.postMessage(readyMessage);
|
|
195
|
+
}).catch((error) => {
|
|
196
|
+
const errorMessage = {
|
|
197
|
+
type: 'error',
|
|
198
|
+
error: error instanceof Error ? error.message : String(error),
|
|
199
|
+
};
|
|
200
|
+
self.postMessage(errorMessage);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=kodexa-worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kodexa-worker.js","sourceRoot":"","sources":["../../src/worker/kodexa-worker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIzF,eAAe;AACf,IAAI,WAAW,GAAG,KAAK,CAAC;AACxB,IAAI,WAAW,GAAyB,IAAI,CAAC;AAC7C,IAAI,MAAM,GAAiB,EAAE,CAAC;AAE9B;;;GAGG;AACH,KAAK,UAAU,eAAe;IAC5B,2EAA2E;IAC3E,oEAAoE;IACpE,MAAM,QAAQ,GAAG,8BAA8B,CAAC;IAEhD,0BAA0B;IAC1B,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,yBAAyB,CAAC,QAAQ,CAAC,CAAC;IACrE,MAAM,SAAS,GAAG,WAAW,CAAC,OAAO,CAAC;IAEtC,iCAAiC;IACjC,MAAM,SAAS,GAA8C,EAAE,CAAC;IAChE,SAAS,CAAC,UAAU,GAAG,GAAG,EAAE,CAAC,uCAAuC,CAAC;IAErE,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,SAAS,CAAC,CAAC;IACvC,cAAc,CAAC,GAAG,CAAC,CAAC;IACpB,qBAAqB,EAAE,CAAC;IAExB,+BAA+B;IAC9B,IAAY,CAAC,YAAY,GAAG,CAAC,KAAiB,EAAU,EAAE;QACzD,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;QACnC,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;YACjB,OAAO,CAAC,KAAK,CAAC,kCAA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,IAAI,CAAC,GAAG,EAAE;QAC9C,MAAM,YAAY,GAAuB,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;QAC3D,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;QACjB,MAAM,YAAY,GAAuB;YACvC,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;SAC9D,CAAC;QACF,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message protocol types for Kodexa Web Worker communication.
|
|
3
|
+
*
|
|
4
|
+
* The worker owns the WASM instance and exposes an RPC-style API via postMessage.
|
|
5
|
+
* All Go WASM functions are called by name with arguments serialized as JSON.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Request message sent from main thread to worker.
|
|
9
|
+
*/
|
|
10
|
+
export interface WorkerRequest {
|
|
11
|
+
/** Unique request ID for response matching */
|
|
12
|
+
id: string;
|
|
13
|
+
/** Request type */
|
|
14
|
+
type: 'call';
|
|
15
|
+
/** Go WASM function name to call (e.g., 'documentGetRoot', 'nodeGetChildren') */
|
|
16
|
+
method: string;
|
|
17
|
+
/** Arguments to pass to the function (must be JSON-serializable) */
|
|
18
|
+
args: unknown[];
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Response message sent from worker to main thread.
|
|
22
|
+
*/
|
|
23
|
+
export interface WorkerResponse {
|
|
24
|
+
/** Matches the request ID */
|
|
25
|
+
id: string;
|
|
26
|
+
/** Whether the call succeeded */
|
|
27
|
+
success: boolean;
|
|
28
|
+
/** Return value from the Go function (typically JSON string or number) */
|
|
29
|
+
result?: unknown;
|
|
30
|
+
/** Error message if the call failed */
|
|
31
|
+
error?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Message sent when worker has finished initializing WASM.
|
|
35
|
+
*/
|
|
36
|
+
export interface WorkerReadyMessage {
|
|
37
|
+
type: 'ready';
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Message sent if worker initialization fails.
|
|
41
|
+
*/
|
|
42
|
+
export interface WorkerErrorMessage {
|
|
43
|
+
type: 'error';
|
|
44
|
+
error: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* All possible messages from worker to main thread.
|
|
48
|
+
*/
|
|
49
|
+
export type WorkerOutboundMessage = WorkerResponse | WorkerReadyMessage | WorkerErrorMessage;
|
|
50
|
+
/**
|
|
51
|
+
* Configuration for initializing the worker.
|
|
52
|
+
*/
|
|
53
|
+
export interface WorkerConfig {
|
|
54
|
+
/** Base URL for WASM files (kodexa.wasm, wasm_exec.js). Defaults to same origin. */
|
|
55
|
+
wasmBaseUrl?: string;
|
|
56
|
+
/** Log level for the Go WASM module */
|
|
57
|
+
logLevel?: 'debug' | 'info' | 'warn' | 'error';
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Pending request tracker for the main thread proxy.
|
|
61
|
+
*/
|
|
62
|
+
export interface PendingRequest {
|
|
63
|
+
resolve: (value: unknown) => void;
|
|
64
|
+
reject: (error: Error) => void;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Content node data returned from Go WASM.
|
|
68
|
+
* This mirrors the ContentNodeData interface from the main library.
|
|
69
|
+
*/
|
|
70
|
+
export interface WorkerNodeData {
|
|
71
|
+
nodeRef: number;
|
|
72
|
+
id: number;
|
|
73
|
+
parentId?: number;
|
|
74
|
+
type: string;
|
|
75
|
+
content: string;
|
|
76
|
+
index?: number;
|
|
77
|
+
virtual?: boolean;
|
|
78
|
+
confidence?: number;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=types.d.ts.map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AE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message protocol types for Kodexa Web Worker communication.
|
|
3
|
+
*
|
|
4
|
+
* The worker owns the WASM instance and exposes an RPC-style API via postMessage.
|
|
5
|
+
* All Go WASM functions are called by name with arguments serialized as JSON.
|
|
6
|
+
*/
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/worker/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
package/package.json
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kodexa-ai/document-wasm-ts",
|
|
3
|
-
"version": "8.0.0-develop-
|
|
3
|
+
"version": "8.0.0-develop-20664344428",
|
|
4
4
|
"description": "TypeScript WASM wrapper for high-performance Kodexa Document processing using Go backend",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./worker": {
|
|
14
|
+
"types": "./dist/worker/index.d.ts",
|
|
15
|
+
"import": "./dist/worker/index.js",
|
|
16
|
+
"require": "./dist/worker/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
7
19
|
"repository": {
|
|
8
20
|
"type": "git",
|
|
9
21
|
"url": "git+https://github.com/kodexa/platform.git",
|
|
@@ -16,10 +28,11 @@
|
|
|
16
28
|
"test": "jest",
|
|
17
29
|
"clean": "node scripts/clean-dist.js",
|
|
18
30
|
"build:ts": "tsc && npm run build:browser-bridge",
|
|
19
|
-
"build": "
|
|
31
|
+
"build:worker": "node scripts/build-worker.js",
|
|
32
|
+
"build": "npm run clean && npm run build:ts && npm run build:worker",
|
|
20
33
|
"build:browser-bridge": "esbuild src/wasm/browser-bridge.ts --bundle --format=iife --global-name=KodexaBridge --outfile=dist/sqljs-bridge.bundle.js",
|
|
21
34
|
"build:wasm": "cd ../go && make wasm wasm-support",
|
|
22
|
-
"build:all": "npm run clean && npm run build:wasm && npm run build:ts",
|
|
35
|
+
"build:all": "npm run clean && npm run build:wasm && npm run build:ts && npm run build:worker",
|
|
23
36
|
"prepublishOnly": "npm run build"
|
|
24
37
|
},
|
|
25
38
|
"files": [
|