@kodexa-ai/document-wasm-ts 8.0.0-20484695702

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.
Files changed (39) hide show
  1. package/README.md +563 -0
  2. package/dist/ContentNode.d.ts +207 -0
  3. package/dist/ContentNode.d.ts.map +1 -0
  4. package/dist/ContentNode.js +633 -0
  5. package/dist/ContentNode.js.map +1 -0
  6. package/dist/ExtractionEngine.d.ts +65 -0
  7. package/dist/ExtractionEngine.d.ts.map +1 -0
  8. package/dist/ExtractionEngine.js +115 -0
  9. package/dist/ExtractionEngine.js.map +1 -0
  10. package/dist/KddbDocument.d.ts +193 -0
  11. package/dist/KddbDocument.d.ts.map +1 -0
  12. package/dist/KddbDocument.js +575 -0
  13. package/dist/KddbDocument.js.map +1 -0
  14. package/dist/index.d.ts +54 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +96 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/sqljs-bridge.bundle.js +330 -0
  19. package/dist/wasm/browser-bridge.d.ts +44 -0
  20. package/dist/wasm/browser-bridge.d.ts.map +1 -0
  21. package/dist/wasm/browser-bridge.js +104 -0
  22. package/dist/wasm/browser-bridge.js.map +1 -0
  23. package/dist/wasm/loader.d.ts +57 -0
  24. package/dist/wasm/loader.d.ts.map +1 -0
  25. package/dist/wasm/loader.js +193 -0
  26. package/dist/wasm/loader.js.map +1 -0
  27. package/dist/wasm/sqljs-bridge.d.ts +40 -0
  28. package/dist/wasm/sqljs-bridge.d.ts.map +1 -0
  29. package/dist/wasm/sqljs-bridge.js +98 -0
  30. package/dist/wasm/sqljs-bridge.js.map +1 -0
  31. package/dist/wasm/sqljs-core.d.ts +92 -0
  32. package/dist/wasm/sqljs-core.d.ts.map +1 -0
  33. package/dist/wasm/sqljs-core.js +372 -0
  34. package/dist/wasm/sqljs-core.js.map +1 -0
  35. package/dist/wasm/types.d.ts +179 -0
  36. package/dist/wasm/types.d.ts.map +1 -0
  37. package/dist/wasm/types.js +9 -0
  38. package/dist/wasm/types.js.map +1 -0
  39. package/package.json +62 -0
package/dist/index.js ADDED
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Kodexa Document Library - TypeScript WASM Wrapper
3
+ *
4
+ * High-performance TypeScript wrapper for the Kodexa Go library using WebAssembly.
5
+ * Provides document processing capabilities for both Node.js and browser environments.
6
+ */
7
+ // Main classes
8
+ export { KddbDocument } from './KddbDocument';
9
+ export { ContentNode } from './ContentNode';
10
+ export { ExtractionEngine } from './ExtractionEngine';
11
+ // WASM utilities
12
+ export { initWasm, isWasmLoaded, cleanupWasm, setLogLevel } from './wasm/loader';
13
+ // Convenience functions
14
+ export class Kodexa {
15
+ /**
16
+ * Initialize the WASM module
17
+ * Call this before using any other functions
18
+ */
19
+ static async init() {
20
+ const { initWasm } = await import('./wasm/loader');
21
+ return initWasm();
22
+ }
23
+ /**
24
+ * Create a new empty document
25
+ */
26
+ static async createDocument() {
27
+ const { KddbDocument } = await import('./KddbDocument');
28
+ return KddbDocument.create();
29
+ }
30
+ /**
31
+ * Create a document from text
32
+ */
33
+ static async fromText(text) {
34
+ const { KddbDocument } = await import('./KddbDocument');
35
+ return KddbDocument.fromText(text);
36
+ }
37
+ /**
38
+ * Create a document from JSON
39
+ */
40
+ static async fromJson(json) {
41
+ const { KddbDocument } = await import('./KddbDocument');
42
+ return KddbDocument.fromJson(json);
43
+ }
44
+ /**
45
+ * Create a document from KDDB blob
46
+ */
47
+ static async fromBlob(blob) {
48
+ const { KddbDocument } = await import('./KddbDocument');
49
+ return KddbDocument.fromBlob(blob);
50
+ }
51
+ /**
52
+ * Check if WASM module is loaded
53
+ */
54
+ static isLoaded() {
55
+ try {
56
+ const { isWasmLoaded } = require('./wasm/loader');
57
+ return isWasmLoaded();
58
+ }
59
+ catch {
60
+ return false;
61
+ }
62
+ }
63
+ /**
64
+ * Cleanup WASM resources
65
+ */
66
+ static cleanup() {
67
+ try {
68
+ const { cleanupWasm } = require('./wasm/loader');
69
+ cleanupWasm();
70
+ }
71
+ catch (e) {
72
+ console.warn('Error during cleanup:', e);
73
+ }
74
+ }
75
+ /**
76
+ * Set the log level for Go WASM logging.
77
+ * Valid levels: "debug", "info", "warn", "error"
78
+ * Default is "warn" (set during initialization).
79
+ *
80
+ * Can be called anytime after init().
81
+ * To set before init(), use: window.KODEXA_LOG_LEVEL = "debug"
82
+ */
83
+ static setLogLevel(level) {
84
+ try {
85
+ const { setLogLevel } = require('./wasm/loader');
86
+ return setLogLevel(level);
87
+ }
88
+ catch (e) {
89
+ console.warn('Error setting log level:', e);
90
+ return false;
91
+ }
92
+ }
93
+ }
94
+ // Default export
95
+ export default Kodexa;
96
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAe;AACf,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD,iBAAiB;AACjB,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAqBjF,wBAAwB;AACxB,MAAM,OAAO,MAAM;IACjB;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,IAAI;QACf,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,CAAC;QACnD,OAAO,QAAQ,EAAE,CAAC;IACpB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,cAAc;QACzB,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC,CAAC;QACxD,OAAO,YAAY,CAAC,MAAM,EAAE,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAA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AC,CAAC;QAC5B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,OAAO,CAAC,IAAI,CAAC,0BAA0B,EAAE,CAAC,CAAC,CAAC;YAC5C,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;CACF;AAED,iBAAiB;AACjB,eAAe,MAAM,CAAC"}
@@ -0,0 +1,330 @@
1
+ "use strict";
2
+ var KodexaBridge = (() => {
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/wasm/browser-bridge.ts
22
+ var browser_bridge_exports = {};
23
+ __export(browser_bridge_exports, {
24
+ cleanupSqlJs: () => cleanupSqlJs,
25
+ getDatabase: () => getDatabase2,
26
+ initialize: () => initialize,
27
+ isInitialized: () => isInitialized,
28
+ loadDocument: () => loadDocument
29
+ });
30
+
31
+ // src/wasm/sqljs-core.ts
32
+ var databases = /* @__PURE__ */ new Map();
33
+ var nextHandle = 1;
34
+ var sqlInstance = null;
35
+ function uint8ArrayToBase64(bytes) {
36
+ if (bytes.length < 32768) {
37
+ let binary2 = "";
38
+ for (let i = 0; i < bytes.length; i++) {
39
+ binary2 += String.fromCharCode(bytes[i]);
40
+ }
41
+ return btoa(binary2);
42
+ }
43
+ const chunkSize = 32768;
44
+ let binary = "";
45
+ for (let i = 0; i < bytes.length; i += chunkSize) {
46
+ const chunk = bytes.subarray(i, Math.min(i + chunkSize, bytes.length));
47
+ binary += String.fromCharCode.apply(null, Array.from(chunk));
48
+ }
49
+ return btoa(binary);
50
+ }
51
+ function processRowForJson(obj) {
52
+ const result = {};
53
+ for (const key in obj) {
54
+ const value = obj[key];
55
+ if (value instanceof Uint8Array) {
56
+ try {
57
+ const base64 = uint8ArrayToBase64(value);
58
+ result[key] = "base64:" + base64;
59
+ } catch (err) {
60
+ console.error(`[sql.js] Failed to convert BLOB column '${key}' (${value.length} bytes):`, err);
61
+ result[key] = null;
62
+ }
63
+ } else {
64
+ result[key] = value;
65
+ }
66
+ }
67
+ return result;
68
+ }
69
+ function createDatabaseOp() {
70
+ if (!sqlInstance) {
71
+ console.error("[sql.js] Not initialized");
72
+ return 0;
73
+ }
74
+ try {
75
+ const db = new sqlInstance.Database();
76
+ const handle = nextHandle++;
77
+ databases.set(handle, db);
78
+ console.log(`[sql.js] Created database with handle ${handle}`);
79
+ return handle;
80
+ } catch (error) {
81
+ console.error("[sql.js] Failed to create database:", error);
82
+ return 0;
83
+ }
84
+ }
85
+ function execOp(handle, sql) {
86
+ const db = databases.get(handle);
87
+ if (!db) {
88
+ console.error(`[sql.js] Invalid database handle: ${handle}`);
89
+ return 0;
90
+ }
91
+ try {
92
+ db.run(sql);
93
+ return 1;
94
+ } catch (error) {
95
+ console.error("[sql.js] Exec failed:", error);
96
+ return 0;
97
+ }
98
+ }
99
+ function queryOp(handle, sql, paramsJson) {
100
+ const db = databases.get(handle);
101
+ if (!db) {
102
+ console.error(`[sql.js] Invalid database handle: ${handle}`);
103
+ return "[]";
104
+ }
105
+ try {
106
+ let params = [];
107
+ if (paramsJson && paramsJson !== "[]" && paramsJson !== "null") {
108
+ params = JSON.parse(paramsJson);
109
+ }
110
+ const stmt = db.prepare(sql);
111
+ if (params.length > 0) {
112
+ stmt.bind(params);
113
+ }
114
+ const results = [];
115
+ while (stmt.step()) {
116
+ results.push(processRowForJson(stmt.getAsObject()));
117
+ }
118
+ stmt.free();
119
+ return JSON.stringify(results);
120
+ } catch (error) {
121
+ console.error("[sql.js] Query failed:", sql, error);
122
+ return "[]";
123
+ }
124
+ }
125
+ function insertOp(handle, sql, paramsJson) {
126
+ const db = databases.get(handle);
127
+ if (!db) {
128
+ console.error(`[sql.js] Invalid database handle: ${handle}`);
129
+ return 0;
130
+ }
131
+ try {
132
+ let params = [];
133
+ if (paramsJson && paramsJson !== "[]" && paramsJson !== "null") {
134
+ params = JSON.parse(paramsJson);
135
+ }
136
+ if (params.length > 0) {
137
+ db.run(sql, params);
138
+ } else {
139
+ db.run(sql);
140
+ }
141
+ const result = db.exec("SELECT last_insert_rowid() as id");
142
+ if (result.length > 0 && result[0].values.length > 0) {
143
+ return result[0].values[0][0];
144
+ }
145
+ return 0;
146
+ } catch (error) {
147
+ console.error("[sql.js] Insert failed:", sql, error);
148
+ return 0;
149
+ }
150
+ }
151
+ function execParamsOp(handle, sql, paramsJson) {
152
+ const db = databases.get(handle);
153
+ if (!db) {
154
+ console.error(`[sql.js] Invalid database handle: ${handle}`);
155
+ return -1;
156
+ }
157
+ try {
158
+ let params = [];
159
+ if (paramsJson && paramsJson !== "[]" && paramsJson !== "null") {
160
+ params = JSON.parse(paramsJson);
161
+ }
162
+ if (params.length > 0) {
163
+ db.run(sql, params);
164
+ } else {
165
+ db.run(sql);
166
+ }
167
+ const result = db.exec("SELECT changes() as count");
168
+ if (result.length > 0 && result[0].values.length > 0) {
169
+ return result[0].values[0][0];
170
+ }
171
+ return 0;
172
+ } catch (error) {
173
+ console.error("[sql.js] ExecParams failed:", sql, error);
174
+ return -1;
175
+ }
176
+ }
177
+ function exportOp(handle) {
178
+ const db = databases.get(handle);
179
+ if (!db) {
180
+ console.error(`[sql.js] Invalid database handle: ${handle}`);
181
+ return "";
182
+ }
183
+ try {
184
+ const data = db.export();
185
+ return uint8ArrayToBase64(data);
186
+ } catch (error) {
187
+ console.error("[sql.js] Export failed:", error);
188
+ return "";
189
+ }
190
+ }
191
+ function importOp(base64Data) {
192
+ if (!sqlInstance) {
193
+ console.error("[sql.js] Not initialized");
194
+ return 0;
195
+ }
196
+ try {
197
+ const binary = atob(base64Data);
198
+ const data = new Uint8Array(binary.length);
199
+ for (let i = 0; i < binary.length; i++) {
200
+ data[i] = binary.charCodeAt(i);
201
+ }
202
+ const db = new sqlInstance.Database(data);
203
+ const handle = nextHandle++;
204
+ databases.set(handle, db);
205
+ console.log(`[sql.js] Imported database with handle ${handle}`);
206
+ return handle;
207
+ } catch (error) {
208
+ console.error("[sql.js] Import failed:", error);
209
+ return 0;
210
+ }
211
+ }
212
+ function loadDirectOp(bytes) {
213
+ if (!sqlInstance) {
214
+ console.error("[sql.js] Not initialized");
215
+ return 0;
216
+ }
217
+ try {
218
+ const db = new sqlInstance.Database(bytes);
219
+ const handle = nextHandle++;
220
+ databases.set(handle, db);
221
+ return handle;
222
+ } catch (error) {
223
+ console.error("[sql.js] Failed to load database directly:", error);
224
+ return 0;
225
+ }
226
+ }
227
+ function closeOp(handle) {
228
+ const db = databases.get(handle);
229
+ if (db) {
230
+ try {
231
+ db.close();
232
+ } catch (error) {
233
+ console.error("[sql.js] Close failed:", error);
234
+ }
235
+ databases.delete(handle);
236
+ console.log(`[sql.js] Closed database with handle ${handle}`);
237
+ }
238
+ }
239
+ function getErrorOp(_handle) {
240
+ return "";
241
+ }
242
+ function cleanupOp() {
243
+ for (const [_handle, db] of databases) {
244
+ try {
245
+ db.close();
246
+ } catch (_e) {
247
+ }
248
+ }
249
+ databases.clear();
250
+ nextHandle = 1;
251
+ console.log("[sql.js] Cleaned up all databases");
252
+ }
253
+ function setSqlInstance(SQL2) {
254
+ sqlInstance = SQL2;
255
+ }
256
+ function exposeBridgeFunctions() {
257
+ const g = globalThis;
258
+ g.sqljsCreateDatabase = createDatabaseOp;
259
+ g.sqljsExec = execOp;
260
+ g.sqljsQuery = queryOp;
261
+ g.sqljsInsert = insertOp;
262
+ g.sqljsExecParams = execParamsOp;
263
+ g.sqljsExport = exportOp;
264
+ g.sqljsImport = importOp;
265
+ g.sqljsClose = closeOp;
266
+ g.sqljsGetError = getErrorOp;
267
+ g.sqljsLoadDirect = loadDirectOp;
268
+ g.sqljsDatabases = databases;
269
+ console.log("[sql.js] Bridge functions exposed to globalThis");
270
+ }
271
+ function getDatabase(handle) {
272
+ return databases.get(handle);
273
+ }
274
+
275
+ // src/wasm/browser-bridge.ts
276
+ var SQL = null;
277
+ var initialized = false;
278
+ var initPromise = null;
279
+ async function initialize(wasmUrl) {
280
+ if (initialized) {
281
+ return;
282
+ }
283
+ if (initPromise) {
284
+ return initPromise;
285
+ }
286
+ initPromise = (async () => {
287
+ try {
288
+ if (typeof initSqlJs === "undefined") {
289
+ throw new Error("sql.js not loaded. Include sql-wasm.js before this script.");
290
+ }
291
+ const config = {};
292
+ if (wasmUrl) {
293
+ config.locateFile = () => wasmUrl;
294
+ } else {
295
+ config.locateFile = (file) => `https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.11.0/${file}`;
296
+ }
297
+ SQL = await initSqlJs(config);
298
+ setSqlInstance(SQL);
299
+ initialized = true;
300
+ exposeBridgeFunctions();
301
+ const g = globalThis;
302
+ g.loadDocument = loadDocument;
303
+ console.log("[sql.js] Browser bridge initialized successfully");
304
+ } catch (error) {
305
+ console.error("[sql.js] Initialization failed:", error);
306
+ throw error;
307
+ }
308
+ })();
309
+ return initPromise;
310
+ }
311
+ function isInitialized() {
312
+ return initialized;
313
+ }
314
+ function loadDocument(bytes) {
315
+ const g = globalThis;
316
+ const handle = loadDirectOp(bytes);
317
+ if (handle === 0) {
318
+ console.error("[sql.js] Failed to load database");
319
+ return 0;
320
+ }
321
+ return g.createDocumentFromHandle(handle);
322
+ }
323
+ function cleanupSqlJs() {
324
+ cleanupOp();
325
+ }
326
+ function getDatabase2(handle) {
327
+ return getDatabase(handle);
328
+ }
329
+ return __toCommonJS(browser_bridge_exports);
330
+ })();
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Browser-specific sql.js Bridge for Go WASM
3
+ *
4
+ * This is a standalone bridge that expects sql.js to be loaded globally from CDN.
5
+ * It exposes functions to globalThis so that Go WASM code can call them via syscall/js.
6
+ *
7
+ * For npm package usage, see sqljs-bridge.ts instead.
8
+ *
9
+ * Usage in HTML:
10
+ * <script src="https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.11.0/sql-wasm.js"></script>
11
+ * <script src="dist/sqljs-bridge.bundle.js"></script>
12
+ * <script>
13
+ * KodexaBridge.initialize().then(() => {
14
+ * // Load Go WASM here
15
+ * });
16
+ * </script>
17
+ *
18
+ * CRITICAL: This must be initialized BEFORE Go WASM is loaded.
19
+ */
20
+ /**
21
+ * Initialize sql.js WASM
22
+ * Must be called before any database operations
23
+ */
24
+ export declare function initialize(wasmUrl?: string): Promise<void>;
25
+ /**
26
+ * Check if sql.js is initialized
27
+ */
28
+ export declare function isInitialized(): boolean;
29
+ /**
30
+ * Load document: loads bytes directly into sql.js and passes handle to Go.
31
+ * Go handles migration if needed. This avoids the bytes round-trip for ALL documents.
32
+ * @param bytes Raw KDDB file bytes (Uint8Array)
33
+ * @returns Document reference or 0 on error
34
+ */
35
+ export declare function loadDocument(bytes: Uint8Array): number;
36
+ /**
37
+ * Cleanup all databases and reset state
38
+ */
39
+ export declare function cleanupSqlJs(): void;
40
+ /**
41
+ * Get a database by handle (for debugging from console)
42
+ */
43
+ export declare function getDatabase(handle: number): any;
44
+ //# sourceMappingURL=browser-bridge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-bridge.d.ts","sourceRoot":"","sources":["../../src/wasm/browser-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAoBH;;;GAGG;AACH,wBAAsB,UAAU,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA8ChE;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAYtD;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,IAAI,CAEnC;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAE/C"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Browser-specific sql.js Bridge for Go WASM
3
+ *
4
+ * This is a standalone bridge that expects sql.js to be loaded globally from CDN.
5
+ * It exposes functions to globalThis so that Go WASM code can call them via syscall/js.
6
+ *
7
+ * For npm package usage, see sqljs-bridge.ts instead.
8
+ *
9
+ * Usage in HTML:
10
+ * <script src="https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.11.0/sql-wasm.js"></script>
11
+ * <script src="dist/sqljs-bridge.bundle.js"></script>
12
+ * <script>
13
+ * KodexaBridge.initialize().then(() => {
14
+ * // Load Go WASM here
15
+ * });
16
+ * </script>
17
+ *
18
+ * CRITICAL: This must be initialized BEFORE Go WASM is loaded.
19
+ */
20
+ import { setSqlInstance, exposeBridgeFunctions, cleanupOp, getDatabase as getDatabaseCore, loadDirectOp, } from './sqljs-core';
21
+ // sql.js static instance
22
+ let SQL = null;
23
+ // Track initialization state
24
+ let initialized = false;
25
+ let initPromise = null;
26
+ /**
27
+ * Initialize sql.js WASM
28
+ * Must be called before any database operations
29
+ */
30
+ export async function initialize(wasmUrl) {
31
+ if (initialized) {
32
+ return;
33
+ }
34
+ if (initPromise) {
35
+ return initPromise;
36
+ }
37
+ initPromise = (async () => {
38
+ try {
39
+ // Check that sql.js is loaded globally
40
+ if (typeof initSqlJs === 'undefined') {
41
+ throw new Error('sql.js not loaded. Include sql-wasm.js before this script.');
42
+ }
43
+ // Configure sql.js WASM location
44
+ const config = {};
45
+ if (wasmUrl) {
46
+ config.locateFile = () => wasmUrl;
47
+ }
48
+ else {
49
+ // Use CDN for WASM file
50
+ config.locateFile = (file) => `https://cdnjs.cloudflare.com/ajax/libs/sql.js/1.11.0/${file}`;
51
+ }
52
+ SQL = await initSqlJs(config);
53
+ setSqlInstance(SQL);
54
+ initialized = true;
55
+ // Auto-expose bridge functions for browser usage
56
+ exposeBridgeFunctions();
57
+ // Expose additional browser-specific functions
58
+ const g = globalThis;
59
+ g.loadDocument = loadDocument;
60
+ console.log('[sql.js] Browser bridge initialized successfully');
61
+ }
62
+ catch (error) {
63
+ console.error('[sql.js] Initialization failed:', error);
64
+ throw error;
65
+ }
66
+ })();
67
+ return initPromise;
68
+ }
69
+ /**
70
+ * Check if sql.js is initialized
71
+ */
72
+ export function isInitialized() {
73
+ return initialized;
74
+ }
75
+ /**
76
+ * Load document: loads bytes directly into sql.js and passes handle to Go.
77
+ * Go handles migration if needed. This avoids the bytes round-trip for ALL documents.
78
+ * @param bytes Raw KDDB file bytes (Uint8Array)
79
+ * @returns Document reference or 0 on error
80
+ */
81
+ export function loadDocument(bytes) {
82
+ const g = globalThis;
83
+ // Load directly into sql.js (fast - no bytes round-trip through Go)
84
+ const handle = loadDirectOp(bytes);
85
+ if (handle === 0) {
86
+ console.error('[sql.js] Failed to load database');
87
+ return 0;
88
+ }
89
+ // Pass handle to Go - it will detect and migrate if needed
90
+ return g.createDocumentFromHandle(handle);
91
+ }
92
+ /**
93
+ * Cleanup all databases and reset state
94
+ */
95
+ export function cleanupSqlJs() {
96
+ cleanupOp();
97
+ }
98
+ /**
99
+ * Get a database by handle (for debugging from console)
100
+ */
101
+ export function getDatabase(handle) {
102
+ return getDatabaseCore(handle);
103
+ }
104
+ //# sourceMappingURL=browser-bridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-bridge.js","sourceRoot":"","sources":["../../src/wasm/browser-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EACL,cAAc,EACd,qBAAqB,EACrB,SAAS,EACT,WAAW,IAAI,eAAe,EAC9B,YAAY,GACb,MAAM,cAAc,CAAC;AAKtB,yBA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ACH,CAAC,CAAC,EAAE,CAAC;IAEL,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,KAAiB;IAC5C,MAAM,CAAC,GAAG,UAAiB,CAAC;IAE5B,oEAAoE;IACpE,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;IACnC,IAAI,MAAM,KAAK,CAAC,EAAE,CAAC;QACjB,OAAO,CAAC,KAAK,CAAC,kCAAkC,CAAC,CAAC;QAClD,OAAO,CAAC,CAAC;IACX,CAAC;IAED,2DAA2D;IAC3D,OAAO,CAAC,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAC;AAC5C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY;IAC1B,SAAS,EAAE,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAC,MAAc;IACxC,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * WebAssembly loader for Kodexa Go library
3
+ *
4
+ * NOTE: Go WASM with syscall/js uses a different model than typical WASM.
5
+ * Functions are registered on globalThis and accept/return JS values directly.
6
+ * No pointer-based memory management is needed for strings.
7
+ *
8
+ * IMPORTANT: sql.js is initialized BEFORE Go WASM to provide SQLite support.
9
+ */
10
+ import { GoWasmInstance } from './types';
11
+ /**
12
+ * WASM helper for Go-based WASM modules
13
+ *
14
+ * With Go's syscall/js, strings are passed directly between JS and Go.
15
+ * This helper provides utilities for JSON serialization and result parsing.
16
+ */
17
+ export declare class WasmHelper {
18
+ constructor(_instance: GoWasmInstance);
19
+ /**
20
+ * Parse JSON string returned from Go
21
+ */
22
+ parseJsonResult(jsonStr: string): any;
23
+ /**
24
+ * Create JSON string for Go functions
25
+ */
26
+ toJson(obj: any): string;
27
+ }
28
+ /**
29
+ * Get the loaded WASM instance
30
+ */
31
+ export declare function getWasmInstance(): Promise<GoWasmInstance>;
32
+ /**
33
+ * Get WASM helper for the current instance
34
+ */
35
+ export declare function getWasmHelper(): Promise<WasmHelper>;
36
+ /**
37
+ * Check if WASM is loaded
38
+ */
39
+ export declare function isWasmLoaded(): boolean;
40
+ /**
41
+ * Initialize WASM (call this before using any Go functions)
42
+ */
43
+ export declare function initWasm(): Promise<void>;
44
+ /**
45
+ * Cleanup WASM resources
46
+ */
47
+ export declare function cleanupWasm(): void;
48
+ /**
49
+ * Set the log level for Go WASM logging.
50
+ * Valid levels: "debug", "info", "warn", "error"
51
+ * Default is "warn" (set during initialization).
52
+ *
53
+ * Can be called anytime after WASM is loaded.
54
+ * To set before loading, use: window.KODEXA_LOG_LEVEL = "debug"
55
+ */
56
+ export declare function setLogLevel(level: 'debug' | 'info' | 'warn' | 'error'): boolean;
57
+ //# sourceMappingURL=loader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/wasm/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAQzC;;;;;GAKG;AACH,qBAAa,UAAU;gBACT,SAAS,EAAE,cAAc;IAIrC;;OAEG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG;IAUrC;;OAEG;IACH,MAAM,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM;CAGzB;AA0FD;;GAEG;AACH,wBAAsB,eAAe,IAAI,OAAO,CAAC,cAAc,CAAC,CAW/D;AAED;;GAEG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,UAAU,CAAC,CAGzD;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,OAAO,CAEtC;AAED;;GAEG;AACH,wBAAsB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAO9C;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAclC;AAED;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,CAO/E"}