@kodexa-ai/document-wasm-ts 8.0.0-develop-20665016781 → 8.0.0-develop-20666055921
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/KddbDocument.d.ts +0 -9
- package/dist/KddbDocument.d.ts.map +1 -1
- package/dist/KddbDocument.js +0 -19
- package/dist/KddbDocument.js.map +1 -1
- package/dist/kodexa-shared-worker.js +594 -0
- package/dist/kodexa-shared-worker.js.map +7 -0
- package/dist/kodexa-worker.js +80 -21
- package/dist/kodexa-worker.js.map +3 -3
- package/dist/kodexa.wasm +0 -0
- package/dist/worker/KodexaSharedWorker.d.ts +267 -0
- package/dist/worker/KodexaSharedWorker.d.ts.map +1 -0
- package/dist/worker/KodexaSharedWorker.js +475 -0
- package/dist/worker/KodexaSharedWorker.js.map +1 -0
- package/dist/worker/KodexaWorker.d.ts +110 -0
- package/dist/worker/KodexaWorker.d.ts.map +1 -1
- package/dist/worker/KodexaWorker.js +163 -0
- package/dist/worker/KodexaWorker.js.map +1 -1
- package/dist/worker/KodexaWorkerDocument.d.ts +183 -0
- package/dist/worker/KodexaWorkerDocument.d.ts.map +1 -1
- package/dist/worker/KodexaWorkerDocument.js +458 -0
- package/dist/worker/KodexaWorkerDocument.js.map +1 -1
- package/dist/worker/KodexaWorkerNode.d.ts +22 -0
- package/dist/worker/KodexaWorkerNode.d.ts.map +1 -1
- package/dist/worker/KodexaWorkerNode.js +64 -3
- package/dist/worker/KodexaWorkerNode.js.map +1 -1
- package/dist/worker/index.d.ts +23 -6
- package/dist/worker/index.d.ts.map +1 -1
- package/dist/worker/index.js +21 -5
- package/dist/worker/index.js.map +1 -1
- package/dist/worker/kodexa-shared-worker.d.ts +20 -0
- package/dist/worker/kodexa-shared-worker.d.ts.map +1 -0
- package/dist/worker/kodexa-shared-worker.js +460 -0
- package/dist/worker/kodexa-shared-worker.js.map +1 -0
- package/dist/worker/kodexa-worker.js +110 -22
- package/dist/worker/kodexa-worker.js.map +1 -1
- package/dist/worker/types.d.ts +76 -1
- package/dist/worker/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KodexaSharedWorker - Main Thread Proxy for SharedWorker WASM
|
|
3
|
+
*
|
|
4
|
+
* This class manages a SharedWorker that runs the Go WASM module.
|
|
5
|
+
* Multiple tabs/windows can share the same worker instance, enabling
|
|
6
|
+
* shared document state and cross-tab event synchronization.
|
|
7
|
+
*
|
|
8
|
+
* API is compatible with KodexaWorker - same methods, same return types.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const kodexa = new KodexaSharedWorker();
|
|
13
|
+
* await kodexa.init();
|
|
14
|
+
*
|
|
15
|
+
* const doc = await kodexa.createDocument();
|
|
16
|
+
* const root = await doc.getRoot();
|
|
17
|
+
*
|
|
18
|
+
* await doc.dispose();
|
|
19
|
+
* kodexa.disconnect();
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
import { KodexaWorkerDocument } from './KodexaWorkerDocument';
|
|
23
|
+
/**
|
|
24
|
+
* Main thread proxy for Kodexa SharedWorker.
|
|
25
|
+
*
|
|
26
|
+
* Creates and manages a connection to a SharedWorker that runs the Go WASM module.
|
|
27
|
+
* Multiple KodexaSharedWorker instances in different tabs will share the same
|
|
28
|
+
* underlying SharedWorker process.
|
|
29
|
+
*/
|
|
30
|
+
export class KodexaSharedWorker {
|
|
31
|
+
/**
|
|
32
|
+
* Create a new KodexaSharedWorker instance.
|
|
33
|
+
*
|
|
34
|
+
* @param options Configuration options
|
|
35
|
+
*/
|
|
36
|
+
constructor(options = {}) {
|
|
37
|
+
this.pending = new Map();
|
|
38
|
+
this.nextId = 0;
|
|
39
|
+
this.disconnected = false;
|
|
40
|
+
this.eventListeners = new Set();
|
|
41
|
+
this.portId = null;
|
|
42
|
+
this.config = {
|
|
43
|
+
wasmBaseUrl: options.wasmBaseUrl,
|
|
44
|
+
logLevel: options.logLevel,
|
|
45
|
+
};
|
|
46
|
+
this.dispatchDomEvents = options.dispatchDomEvents !== false;
|
|
47
|
+
// Determine worker URL
|
|
48
|
+
let workerUrl;
|
|
49
|
+
if (options.workerUrl) {
|
|
50
|
+
workerUrl = options.workerUrl;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
// Default: use shared worker from same directory as this module
|
|
54
|
+
workerUrl = new URL('./kodexa-shared-worker.js', import.meta.url);
|
|
55
|
+
}
|
|
56
|
+
const workerName = options.name || 'kodexa';
|
|
57
|
+
this.worker = new SharedWorker(workerUrl, { type: 'module', name: workerName });
|
|
58
|
+
this.port = this.worker.port;
|
|
59
|
+
// Set up ready promise
|
|
60
|
+
this.ready = new Promise((resolve, reject) => {
|
|
61
|
+
this.readyResolve = resolve;
|
|
62
|
+
this.readyReject = reject;
|
|
63
|
+
});
|
|
64
|
+
// Handle messages from worker
|
|
65
|
+
this.port.onmessage = this.handleMessage.bind(this);
|
|
66
|
+
this.port.onmessageerror = this.handleError.bind(this);
|
|
67
|
+
// Start the port
|
|
68
|
+
this.port.start();
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Handle messages from the worker.
|
|
72
|
+
*/
|
|
73
|
+
handleMessage(event) {
|
|
74
|
+
const data = event.data;
|
|
75
|
+
// Handle connected message (assigns port ID)
|
|
76
|
+
if ('type' in data && data.type === 'connected') {
|
|
77
|
+
const msg = data;
|
|
78
|
+
this.portId = msg.portId;
|
|
79
|
+
console.log(`[KodexaSharedWorker] Connected with port ID: ${this.portId}`);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// Handle ready message
|
|
83
|
+
if ('type' in data && data.type === 'ready') {
|
|
84
|
+
const msg = data;
|
|
85
|
+
if (msg.portId) {
|
|
86
|
+
this.portId = msg.portId;
|
|
87
|
+
}
|
|
88
|
+
this.readyResolve();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
// Handle error message during initialization
|
|
92
|
+
if ('type' in data && data.type === 'error') {
|
|
93
|
+
this.readyReject(new Error(data.error));
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
// Handle forwarded WASM events
|
|
97
|
+
if ('type' in data && data.type === 'wasmEvent') {
|
|
98
|
+
this.handleWasmEvent(data);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
// Handle RPC response
|
|
102
|
+
if ('id' in data) {
|
|
103
|
+
const response = data;
|
|
104
|
+
const handler = this.pending.get(response.id);
|
|
105
|
+
if (handler) {
|
|
106
|
+
this.pending.delete(response.id);
|
|
107
|
+
if (response.success) {
|
|
108
|
+
handler.resolve(response.result);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
handler.reject(new Error(response.error || 'Unknown worker error'));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Handle WASM events forwarded from the worker.
|
|
118
|
+
*/
|
|
119
|
+
handleWasmEvent(message) {
|
|
120
|
+
const { eventType, detail } = message;
|
|
121
|
+
// Notify all registered listeners
|
|
122
|
+
for (const listener of this.eventListeners) {
|
|
123
|
+
try {
|
|
124
|
+
listener(eventType, detail);
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
console.error('[KodexaSharedWorker] Event listener error:', error);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// Optionally dispatch as DOM event for backwards compatibility
|
|
131
|
+
if (this.dispatchDomEvents && typeof document !== 'undefined') {
|
|
132
|
+
const customEvent = new CustomEvent(eventType, { detail });
|
|
133
|
+
document.dispatchEvent(customEvent);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Handle worker errors.
|
|
138
|
+
*/
|
|
139
|
+
handleError(event) {
|
|
140
|
+
console.error('[KodexaSharedWorker] Worker message error:', event);
|
|
141
|
+
this.readyReject(new Error('Worker message error'));
|
|
142
|
+
// Reject all pending requests
|
|
143
|
+
for (const [id, handler] of this.pending) {
|
|
144
|
+
handler.reject(new Error('Worker connection error'));
|
|
145
|
+
this.pending.delete(id);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Initialize the worker and load WASM.
|
|
150
|
+
* Must be called before any other methods.
|
|
151
|
+
*/
|
|
152
|
+
async init() {
|
|
153
|
+
if (this.disconnected) {
|
|
154
|
+
throw new Error('Worker has been disconnected');
|
|
155
|
+
}
|
|
156
|
+
// Send init message to worker
|
|
157
|
+
this.port.postMessage({
|
|
158
|
+
type: 'init',
|
|
159
|
+
config: this.config,
|
|
160
|
+
});
|
|
161
|
+
// Wait for ready signal
|
|
162
|
+
await this.ready;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Get the port ID assigned by the SharedWorker.
|
|
166
|
+
*/
|
|
167
|
+
getPortId() {
|
|
168
|
+
return this.portId;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Call a Go WASM function in the worker.
|
|
172
|
+
*
|
|
173
|
+
* @param method Function name (e.g., 'createDocument', 'documentGetRoot')
|
|
174
|
+
* @param args Arguments to pass to the function
|
|
175
|
+
* @returns Promise that resolves with the function result
|
|
176
|
+
*/
|
|
177
|
+
async call(method, ...args) {
|
|
178
|
+
if (this.disconnected) {
|
|
179
|
+
throw new Error('Worker has been disconnected');
|
|
180
|
+
}
|
|
181
|
+
// Wait for initialization
|
|
182
|
+
await this.ready;
|
|
183
|
+
// Generate unique request ID (namespaced with port ID to avoid collisions)
|
|
184
|
+
const id = `${this.portId || 'unknown'}_${++this.nextId}`;
|
|
185
|
+
// Create promise for response
|
|
186
|
+
return new Promise((resolve, reject) => {
|
|
187
|
+
this.pending.set(id, {
|
|
188
|
+
resolve: resolve,
|
|
189
|
+
reject,
|
|
190
|
+
});
|
|
191
|
+
// Send request to worker
|
|
192
|
+
const request = {
|
|
193
|
+
id,
|
|
194
|
+
type: 'call',
|
|
195
|
+
method,
|
|
196
|
+
args,
|
|
197
|
+
portId: this.portId || '',
|
|
198
|
+
};
|
|
199
|
+
this.port.postMessage(request);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Create a new empty document.
|
|
204
|
+
*/
|
|
205
|
+
async createDocument() {
|
|
206
|
+
const docRef = await this.call('createDocument');
|
|
207
|
+
return new KodexaWorkerDocument(this, docRef);
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Create a document from text content.
|
|
211
|
+
*
|
|
212
|
+
* @param text Text content for the document
|
|
213
|
+
*/
|
|
214
|
+
async fromText(text) {
|
|
215
|
+
const docRef = await this.call('createDocumentFromText', text);
|
|
216
|
+
return new KodexaWorkerDocument(this, docRef);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Create a document from JSON.
|
|
220
|
+
*
|
|
221
|
+
* @param json JSON string representing the document
|
|
222
|
+
*/
|
|
223
|
+
async fromJson(json) {
|
|
224
|
+
const docRef = await this.call('createDocumentFromJson', json);
|
|
225
|
+
return new KodexaWorkerDocument(this, docRef);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Create a document from KDDB bytes.
|
|
229
|
+
*
|
|
230
|
+
* @param bytes KDDB file contents as Uint8Array
|
|
231
|
+
*/
|
|
232
|
+
async fromKddb(bytes) {
|
|
233
|
+
// Use the loadDocument function which handles migration
|
|
234
|
+
const docRef = await this.call('loadDocument', bytes);
|
|
235
|
+
if (docRef === 0) {
|
|
236
|
+
throw new Error('Failed to load KDDB document');
|
|
237
|
+
}
|
|
238
|
+
return new KodexaWorkerDocument(this, docRef);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Create a document from KDDB bytes (raw, no migration).
|
|
242
|
+
*
|
|
243
|
+
* @param bytes KDDB file contents as Uint8Array
|
|
244
|
+
*/
|
|
245
|
+
async fromKddbBytes(bytes) {
|
|
246
|
+
const docRef = await this.call('createDocumentFromKddbBytes', bytes);
|
|
247
|
+
return new KodexaWorkerDocument(this, docRef);
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Get library version information.
|
|
251
|
+
*/
|
|
252
|
+
async getLibraryVersion() {
|
|
253
|
+
return this.call('getLibraryVersion');
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Get build information.
|
|
257
|
+
*/
|
|
258
|
+
async getBuildInfo() {
|
|
259
|
+
return this.call('getBuildInfo');
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Cleanup all resources in the worker.
|
|
263
|
+
*/
|
|
264
|
+
async cleanup() {
|
|
265
|
+
await this.call('cleanup');
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Get active handle count (for debugging).
|
|
269
|
+
*/
|
|
270
|
+
async getActiveHandles() {
|
|
271
|
+
return this.call('getActiveHandles');
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Set the log level for Go WASM logging.
|
|
275
|
+
*
|
|
276
|
+
* @param level Log level ('debug', 'info', 'warn', 'error')
|
|
277
|
+
*/
|
|
278
|
+
async setLogLevel(level) {
|
|
279
|
+
return this.call('kodexa_setLogLevel', level);
|
|
280
|
+
}
|
|
281
|
+
// ============================================================================
|
|
282
|
+
// Event Subscription API
|
|
283
|
+
// ============================================================================
|
|
284
|
+
/**
|
|
285
|
+
* Subscribe to WASM events forwarded from the worker.
|
|
286
|
+
* These events include data change events, validation events, etc.
|
|
287
|
+
*
|
|
288
|
+
* @param callback Function to call when an event is received
|
|
289
|
+
* @returns Unsubscribe function
|
|
290
|
+
*/
|
|
291
|
+
onWasmEvent(callback) {
|
|
292
|
+
this.eventListeners.add(callback);
|
|
293
|
+
return () => {
|
|
294
|
+
this.eventListeners.delete(callback);
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Remove a WASM event listener.
|
|
299
|
+
*
|
|
300
|
+
* @param callback The callback to remove
|
|
301
|
+
*/
|
|
302
|
+
offWasmEvent(callback) {
|
|
303
|
+
this.eventListeners.delete(callback);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Enable or disable automatic DOM event dispatching.
|
|
307
|
+
*
|
|
308
|
+
* @param enabled Whether to dispatch DOM events
|
|
309
|
+
*/
|
|
310
|
+
setDispatchDomEvents(enabled) {
|
|
311
|
+
this.dispatchDomEvents = enabled;
|
|
312
|
+
}
|
|
313
|
+
// ============================================================================
|
|
314
|
+
// Document Subscription (SharedWorker-specific)
|
|
315
|
+
// ============================================================================
|
|
316
|
+
/**
|
|
317
|
+
* Subscribe to events for a specific document.
|
|
318
|
+
* This tells the SharedWorker to forward events for this document to this port.
|
|
319
|
+
*
|
|
320
|
+
* @param docRef Document reference
|
|
321
|
+
* @param pattern Event pattern to subscribe to (e.g., '*' for all events)
|
|
322
|
+
*/
|
|
323
|
+
async subscribeToDocument(docRef, pattern = '*') {
|
|
324
|
+
if (!this.portId) {
|
|
325
|
+
throw new Error('Not connected to SharedWorker');
|
|
326
|
+
}
|
|
327
|
+
this.port.postMessage({
|
|
328
|
+
type: 'subscribe',
|
|
329
|
+
portId: this.portId,
|
|
330
|
+
docRef,
|
|
331
|
+
pattern,
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Unsubscribe from events for a specific document.
|
|
336
|
+
*
|
|
337
|
+
* @param docRef Document reference
|
|
338
|
+
*/
|
|
339
|
+
async unsubscribeFromDocument(docRef) {
|
|
340
|
+
if (!this.portId) {
|
|
341
|
+
throw new Error('Not connected to SharedWorker');
|
|
342
|
+
}
|
|
343
|
+
this.port.postMessage({
|
|
344
|
+
type: 'unsubscribe',
|
|
345
|
+
portId: this.portId,
|
|
346
|
+
docRef,
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
// ============================================================================
|
|
350
|
+
// WASM Service Management (via Worker)
|
|
351
|
+
// ============================================================================
|
|
352
|
+
/**
|
|
353
|
+
* Initialize the recalculation service in the worker.
|
|
354
|
+
*
|
|
355
|
+
* @param docRef Document reference
|
|
356
|
+
* @param taxonomiesJson JSON string of taxonomies map
|
|
357
|
+
*/
|
|
358
|
+
async initializeRecalculationService(docRef, taxonomiesJson) {
|
|
359
|
+
return this.call('initializeRecalculationService', docRef, taxonomiesJson);
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Subscribe to WASM events for a document.
|
|
363
|
+
*
|
|
364
|
+
* @param docRef Document reference
|
|
365
|
+
* @param pattern Event pattern to subscribe to
|
|
366
|
+
*/
|
|
367
|
+
async subscribe(docRef, pattern) {
|
|
368
|
+
return this.call('subscribe', docRef, pattern);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Unsubscribe from WASM events for a document.
|
|
372
|
+
*
|
|
373
|
+
* @param docRef Document reference
|
|
374
|
+
* @param pattern Event pattern to unsubscribe from
|
|
375
|
+
*/
|
|
376
|
+
async unsubscribe(docRef, pattern) {
|
|
377
|
+
return this.call('unsubscribe', docRef, pattern);
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Free the recalculation service for a document.
|
|
381
|
+
*
|
|
382
|
+
* @param docRef Document reference
|
|
383
|
+
*/
|
|
384
|
+
async freeRecalculationService(docRef) {
|
|
385
|
+
return this.call('freeRecalculationService', docRef);
|
|
386
|
+
}
|
|
387
|
+
// ============================================================================
|
|
388
|
+
// Extraction Engine (via Worker)
|
|
389
|
+
// ============================================================================
|
|
390
|
+
/**
|
|
391
|
+
* Create an extraction engine for a document.
|
|
392
|
+
*
|
|
393
|
+
* @param docRef Document reference
|
|
394
|
+
* @param taxonomiesJson JSON string of taxonomies array
|
|
395
|
+
* @returns Engine reference (0 on error)
|
|
396
|
+
*/
|
|
397
|
+
async createExtractionEngine(docRef, taxonomiesJson) {
|
|
398
|
+
return this.call('createExtractionEngine', docRef, taxonomiesJson);
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Run extraction and save results to the document.
|
|
402
|
+
*
|
|
403
|
+
* @param engineRef Extraction engine reference
|
|
404
|
+
* @returns Count of data objects extracted (-1 on error)
|
|
405
|
+
*/
|
|
406
|
+
async processAndSaveExtraction(engineRef) {
|
|
407
|
+
return this.call('processAndSaveExtraction', engineRef);
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Get content exceptions from the extraction.
|
|
411
|
+
*
|
|
412
|
+
* @param engineRef Extraction engine reference
|
|
413
|
+
* @returns JSON array of content exceptions
|
|
414
|
+
*/
|
|
415
|
+
async getExtractionContentExceptions(engineRef) {
|
|
416
|
+
return this.call('getExtractionContentExceptions', engineRef);
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Get document taxon validations from the extraction.
|
|
420
|
+
*
|
|
421
|
+
* @param engineRef Extraction engine reference
|
|
422
|
+
* @returns JSON array of validations
|
|
423
|
+
*/
|
|
424
|
+
async getExtractionValidations(engineRef) {
|
|
425
|
+
return this.call('getExtractionValidations', engineRef);
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Free an extraction engine and release its resources.
|
|
429
|
+
*
|
|
430
|
+
* @param engineRef Extraction engine reference
|
|
431
|
+
*/
|
|
432
|
+
async freeExtractionEngine(engineRef) {
|
|
433
|
+
await this.call('freeExtractionEngine', engineRef);
|
|
434
|
+
}
|
|
435
|
+
// ============================================================================
|
|
436
|
+
// Lifecycle
|
|
437
|
+
// ============================================================================
|
|
438
|
+
/**
|
|
439
|
+
* Disconnect from the SharedWorker.
|
|
440
|
+
* This closes the port but doesn't terminate the worker (other tabs may still use it).
|
|
441
|
+
*/
|
|
442
|
+
disconnect() {
|
|
443
|
+
if (this.disconnected) {
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
this.disconnected = true;
|
|
447
|
+
this.port.close();
|
|
448
|
+
// Clear all event listeners
|
|
449
|
+
this.eventListeners.clear();
|
|
450
|
+
// Reject all pending requests
|
|
451
|
+
for (const [id, handler] of this.pending) {
|
|
452
|
+
handler.reject(new Error('Worker disconnected'));
|
|
453
|
+
this.pending.delete(id);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
/**
|
|
457
|
+
* Alias for disconnect() for API compatibility with KodexaWorker.
|
|
458
|
+
*/
|
|
459
|
+
terminate() {
|
|
460
|
+
this.disconnect();
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Check if the worker has been disconnected.
|
|
464
|
+
*/
|
|
465
|
+
isDisconnected() {
|
|
466
|
+
return this.disconnected;
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Alias for isDisconnected() for API compatibility with KodexaWorker.
|
|
470
|
+
*/
|
|
471
|
+
isTerminated() {
|
|
472
|
+
return this.disconnected;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
//# sourceMappingURL=KodexaSharedWorker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KodexaSharedWorker.js","sourceRoot":"","sources":["../../src/worker/KodexaSharedWorker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAYH,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AA8B9D;;;;;;GAMG;AACH,MAAM,OAAO,kBAAkB;IAc7B;;;;OAIG;IACH,YAAY,UAAqC,EAAE;QAb3C,YAAO,GAAG,IAAI,GAAG,EAA0B,CAAC;QAC5C,WAAM,GAAG,CAAC,CAAC;QACX,iBAAY,GAAG,KAAK,CAAC;QAGrB,mBAAc,GAAG,IAAI,GAAG,EAAqB,CAAC;QAC9C,WAAM,GAAkB,IAAI,CAAC;QAQnC,IAAI,CAAC,MAAM,GAAG;YACZ,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,QAAQ,EAAE,OAAO,CAAC,QAAQ;SAC3B,CAAC;QACF,IAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,KAAK,KAAK,CAAC;QAE7D,uBAAuB;QACvB,IAAI,SAAuB,CAAC;QAC5B,IAAI,OAAO,CAAC,S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|
|
19
19
|
*/
|
|
20
20
|
import type { WorkerConfig } from './types';
|
|
21
21
|
import { KodexaWorkerDocument } from './KodexaWorkerDocument';
|
|
22
|
+
/**
|
|
23
|
+
* Callback for WASM events forwarded from the worker.
|
|
24
|
+
*/
|
|
25
|
+
export type WasmEventCallback = (eventType: string, detail: unknown) => void;
|
|
22
26
|
/**
|
|
23
27
|
* Options for creating a KodexaWorker instance.
|
|
24
28
|
*/
|
|
@@ -28,6 +32,11 @@ export interface KodexaWorkerOptions extends WorkerConfig {
|
|
|
28
32
|
* If not provided, uses the bundled worker from the package.
|
|
29
33
|
*/
|
|
30
34
|
workerUrl?: string | URL;
|
|
35
|
+
/**
|
|
36
|
+
* Whether to dispatch forwarded WASM events as DOM CustomEvents on document.
|
|
37
|
+
* Defaults to true for backwards compatibility with main-thread WASM code.
|
|
38
|
+
*/
|
|
39
|
+
dispatchDomEvents?: boolean;
|
|
31
40
|
}
|
|
32
41
|
/**
|
|
33
42
|
* Main thread proxy for Kodexa Web Worker.
|
|
@@ -44,6 +53,8 @@ export declare class KodexaWorker {
|
|
|
44
53
|
private nextId;
|
|
45
54
|
private terminated;
|
|
46
55
|
private config;
|
|
56
|
+
private dispatchDomEvents;
|
|
57
|
+
private eventListeners;
|
|
47
58
|
/**
|
|
48
59
|
* Create a new KodexaWorker instance.
|
|
49
60
|
*
|
|
@@ -54,6 +65,10 @@ export declare class KodexaWorker {
|
|
|
54
65
|
* Handle messages from the worker.
|
|
55
66
|
*/
|
|
56
67
|
private handleMessage;
|
|
68
|
+
/**
|
|
69
|
+
* Handle WASM events forwarded from the worker.
|
|
70
|
+
*/
|
|
71
|
+
private handleWasmEvent;
|
|
57
72
|
/**
|
|
58
73
|
* Handle worker errors.
|
|
59
74
|
*/
|
|
@@ -121,6 +136,101 @@ export declare class KodexaWorker {
|
|
|
121
136
|
* @param level Log level ('debug', 'info', 'warn', 'error')
|
|
122
137
|
*/
|
|
123
138
|
setLogLevel(level: 'debug' | 'info' | 'warn' | 'error'): Promise<string>;
|
|
139
|
+
/**
|
|
140
|
+
* Subscribe to WASM events forwarded from the worker.
|
|
141
|
+
* These events include data change events, validation events, etc.
|
|
142
|
+
*
|
|
143
|
+
* @param callback Function to call when an event is received
|
|
144
|
+
* @returns Unsubscribe function
|
|
145
|
+
*
|
|
146
|
+
* @example
|
|
147
|
+
* ```typescript
|
|
148
|
+
* const unsubscribe = worker.onWasmEvent((eventType, detail) => {
|
|
149
|
+
* if (eventType === 'kodexaDataChange') {
|
|
150
|
+
* console.log('Data changed:', detail);
|
|
151
|
+
* }
|
|
152
|
+
* });
|
|
153
|
+
* // Later: unsubscribe();
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
onWasmEvent(callback: WasmEventCallback): () => void;
|
|
157
|
+
/**
|
|
158
|
+
* Remove a WASM event listener.
|
|
159
|
+
*
|
|
160
|
+
* @param callback The callback to remove
|
|
161
|
+
*/
|
|
162
|
+
offWasmEvent(callback: WasmEventCallback): void;
|
|
163
|
+
/**
|
|
164
|
+
* Enable or disable automatic DOM event dispatching.
|
|
165
|
+
* When enabled, forwarded WASM events are also dispatched as
|
|
166
|
+
* CustomEvents on the document for backwards compatibility.
|
|
167
|
+
*
|
|
168
|
+
* @param enabled Whether to dispatch DOM events
|
|
169
|
+
*/
|
|
170
|
+
setDispatchDomEvents(enabled: boolean): void;
|
|
171
|
+
/**
|
|
172
|
+
* Initialize the recalculation service in the worker.
|
|
173
|
+
* This must be called after loading a document to enable formula recalculation.
|
|
174
|
+
*
|
|
175
|
+
* @param docRef Document reference
|
|
176
|
+
* @param taxonomiesJson JSON string of taxonomies map
|
|
177
|
+
*/
|
|
178
|
+
initializeRecalculationService(docRef: number, taxonomiesJson: string): Promise<unknown>;
|
|
179
|
+
/**
|
|
180
|
+
* Subscribe to WASM events for a document.
|
|
181
|
+
*
|
|
182
|
+
* @param docRef Document reference
|
|
183
|
+
* @param pattern Event pattern to subscribe to
|
|
184
|
+
*/
|
|
185
|
+
subscribe(docRef: number, pattern: string): Promise<unknown>;
|
|
186
|
+
/**
|
|
187
|
+
* Unsubscribe from WASM events for a document.
|
|
188
|
+
*
|
|
189
|
+
* @param docRef Document reference
|
|
190
|
+
* @param pattern Event pattern to unsubscribe from
|
|
191
|
+
*/
|
|
192
|
+
unsubscribe(docRef: number, pattern: string): Promise<unknown>;
|
|
193
|
+
/**
|
|
194
|
+
* Free the recalculation service for a document.
|
|
195
|
+
*
|
|
196
|
+
* @param docRef Document reference
|
|
197
|
+
*/
|
|
198
|
+
freeRecalculationService(docRef: number): Promise<unknown>;
|
|
199
|
+
/**
|
|
200
|
+
* Create an extraction engine for a document.
|
|
201
|
+
*
|
|
202
|
+
* @param docRef Document reference
|
|
203
|
+
* @param taxonomiesJson JSON string of taxonomies array
|
|
204
|
+
* @returns Engine reference (0 on error)
|
|
205
|
+
*/
|
|
206
|
+
createExtractionEngine(docRef: number, taxonomiesJson: string): Promise<number>;
|
|
207
|
+
/**
|
|
208
|
+
* Run extraction and save results to the document.
|
|
209
|
+
*
|
|
210
|
+
* @param engineRef Extraction engine reference
|
|
211
|
+
* @returns Count of data objects extracted (-1 on error)
|
|
212
|
+
*/
|
|
213
|
+
processAndSaveExtraction(engineRef: number): Promise<number>;
|
|
214
|
+
/**
|
|
215
|
+
* Get content exceptions from the extraction.
|
|
216
|
+
*
|
|
217
|
+
* @param engineRef Extraction engine reference
|
|
218
|
+
* @returns JSON array of content exceptions
|
|
219
|
+
*/
|
|
220
|
+
getExtractionContentExceptions(engineRef: number): Promise<string>;
|
|
221
|
+
/**
|
|
222
|
+
* Get document taxon validations from the extraction.
|
|
223
|
+
*
|
|
224
|
+
* @param engineRef Extraction engine reference
|
|
225
|
+
* @returns JSON array of validations
|
|
226
|
+
*/
|
|
227
|
+
getExtractionValidations(engineRef: number): Promise<string>;
|
|
228
|
+
/**
|
|
229
|
+
* Free an extraction engine and release its resources.
|
|
230
|
+
*
|
|
231
|
+
* @param engineRef Extraction engine reference
|
|
232
|
+
*/
|
|
233
|
+
freeExtractionEngine(engineRef: number): Promise<void>;
|
|
124
234
|
/**
|
|
125
235
|
* Terminate the worker.
|
|
126
236
|
* After calling this, the worker cannot be used.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KodexaWorker.d.ts","sourceRoot":"","sources":["../../src/worker/KodexaWorker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAIV,YAAY,
|
|
1
|
+
{"version":3,"file":"KodexaWorker.d.ts","sourceRoot":"","sources":["../../src/worker/KodexaWorker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAIV,YAAY,EAGb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;AAE7E;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,YAAY;IACvD;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;IAEzB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;GAKG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,WAAW,CAA0B;IAC7C,OAAO,CAAC,OAAO,CAAqC;IACpD,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,iBAAiB,CAAU;IACnC,OAAO,CAAC,cAAc,CAAgC;IAEtD;;;;OAIG;gBACS,OAAO,GAAE,mBAAwB;IA8B7C;;OAEG;IACH,OAAO,CAAC,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