jsql-neo 5.3.0 → 5.4.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.
@@ -1,12 +1,45 @@
1
- let wasm;
2
-
3
1
  /* @ts-self-types="./jsql_neo_wasm.d.ts" */
4
2
 
3
+ /**
4
+ * @returns {string}
5
+ */
6
+ export function jsql_begin_tx() {
7
+ let deferred1_0;
8
+ let deferred1_1;
9
+ try {
10
+ const ret = wasm.jsql_begin_tx();
11
+ deferred1_0 = ret[0];
12
+ deferred1_1 = ret[1];
13
+ return getStringFromWasm0(ret[0], ret[1]);
14
+ } finally {
15
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
16
+ }
17
+ }
18
+
19
+ /**
20
+ * @param {string} tx_id
21
+ * @returns {string}
22
+ */
23
+ export function jsql_commit_tx(tx_id) {
24
+ let deferred2_0;
25
+ let deferred2_1;
26
+ try {
27
+ const ptr0 = passStringToWasm0(tx_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
28
+ const len0 = WASM_VECTOR_LEN;
29
+ const ret = wasm.jsql_commit_tx(ptr0, len0);
30
+ deferred2_0 = ret[0];
31
+ deferred2_1 = ret[1];
32
+ return getStringFromWasm0(ret[0], ret[1]);
33
+ } finally {
34
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
35
+ }
36
+ }
37
+
5
38
  /**
6
39
  * @param {string} table
7
40
  * @returns {string}
8
41
  */
9
- function jsql_count(table) {
42
+ export function jsql_count(table) {
10
43
  let deferred2_0;
11
44
  let deferred2_1;
12
45
  try {
@@ -26,7 +59,7 @@ function jsql_count(table) {
26
59
  * @param {string} schema_json
27
60
  * @returns {string}
28
61
  */
29
- function jsql_create_table(name, schema_json) {
62
+ export function jsql_create_table(name, schema_json) {
30
63
  let deferred3_0;
31
64
  let deferred3_1;
32
65
  try {
@@ -47,7 +80,7 @@ function jsql_create_table(name, schema_json) {
47
80
  * @param {string} name
48
81
  * @returns {string}
49
82
  */
50
- function jsql_drop_table(name) {
83
+ export function jsql_drop_table(name) {
51
84
  let deferred2_0;
52
85
  let deferred2_1;
53
86
  try {
@@ -69,7 +102,7 @@ function jsql_drop_table(name) {
69
102
  * @param {number} offset
70
103
  * @returns {string}
71
104
  */
72
- function jsql_find(table, filter_json, limit, offset) {
105
+ export function jsql_find(table, filter_json, limit, offset) {
73
106
  let deferred3_0;
74
107
  let deferred3_1;
75
108
  try {
@@ -91,7 +124,7 @@ function jsql_find(table, filter_json, limit, offset) {
91
124
  * @param {bigint} id
92
125
  * @returns {string}
93
126
  */
94
- function jsql_find_by_id(table, id) {
127
+ export function jsql_find_by_id(table, id) {
95
128
  let deferred2_0;
96
129
  let deferred2_1;
97
130
  try {
@@ -111,7 +144,7 @@ function jsql_find_by_id(table, id) {
111
144
  * @param {string} ids_json
112
145
  * @returns {string}
113
146
  */
114
- function jsql_find_by_ids(table, ids_json) {
147
+ export function jsql_find_by_ids(table, ids_json) {
115
148
  let deferred3_0;
116
149
  let deferred3_1;
117
150
  try {
@@ -133,7 +166,7 @@ function jsql_find_by_ids(table, ids_json) {
133
166
  * @param {string} data_json
134
167
  * @returns {string}
135
168
  */
136
- function jsql_insert(table, data_json) {
169
+ export function jsql_insert(table, data_json) {
137
170
  let deferred3_0;
138
171
  let deferred3_1;
139
172
  try {
@@ -155,7 +188,7 @@ function jsql_insert(table, data_json) {
155
188
  * @param {Uint8Array} data
156
189
  * @returns {string}
157
190
  */
158
- function jsql_insert_buf(table, data) {
191
+ export function jsql_insert_buf(table, data) {
159
192
  let deferred3_0;
160
193
  let deferred3_1;
161
194
  try {
@@ -177,7 +210,7 @@ function jsql_insert_buf(table, data) {
177
210
  * @param {Uint8Array} data
178
211
  * @returns {string}
179
212
  */
180
- function jsql_insert_buf_count(table, data) {
213
+ export function jsql_insert_buf_count(table, data) {
181
214
  let deferred3_0;
182
215
  let deferred3_1;
183
216
  try {
@@ -199,7 +232,7 @@ function jsql_insert_buf_count(table, data) {
199
232
  * @param {string} json
200
233
  * @returns {string}
201
234
  */
202
- function jsql_insert_json(table, json) {
235
+ export function jsql_insert_json(table, json) {
203
236
  let deferred3_0;
204
237
  let deferred3_1;
205
238
  try {
@@ -221,7 +254,7 @@ function jsql_insert_json(table, json) {
221
254
  * @param {bigint} id
222
255
  * @returns {string}
223
256
  */
224
- function jsql_remove_by_id(table, id) {
257
+ export function jsql_remove_by_id(table, id) {
225
258
  let deferred2_0;
226
259
  let deferred2_1;
227
260
  try {
@@ -241,7 +274,7 @@ function jsql_remove_by_id(table, id) {
241
274
  * @param {string} ids_json
242
275
  * @returns {string}
243
276
  */
244
- function jsql_remove_by_ids(table, ids_json) {
277
+ export function jsql_remove_by_ids(table, ids_json) {
245
278
  let deferred3_0;
246
279
  let deferred3_1;
247
280
  try {
@@ -258,17 +291,36 @@ function jsql_remove_by_ids(table, ids_json) {
258
291
  }
259
292
  }
260
293
 
261
- function jsql_reset() {
294
+ export function jsql_reset() {
262
295
  wasm.jsql_reset();
263
296
  }
264
297
 
298
+ /**
299
+ * @param {string} tx_id
300
+ * @returns {string}
301
+ */
302
+ export function jsql_rollback_tx(tx_id) {
303
+ let deferred2_0;
304
+ let deferred2_1;
305
+ try {
306
+ const ptr0 = passStringToWasm0(tx_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
307
+ const len0 = WASM_VECTOR_LEN;
308
+ const ret = wasm.jsql_rollback_tx(ptr0, len0);
309
+ deferred2_0 = ret[0];
310
+ deferred2_1 = ret[1];
311
+ return getStringFromWasm0(ret[0], ret[1]);
312
+ } finally {
313
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
314
+ }
315
+ }
316
+
265
317
  /**
266
318
  * @param {string} table
267
319
  * @param {bigint} id
268
320
  * @param {string} data_json
269
321
  * @returns {string}
270
322
  */
271
- function jsql_update_by_id(table, id, data_json) {
323
+ export function jsql_update_by_id(table, id, data_json) {
272
324
  let deferred3_0;
273
325
  let deferred3_1;
274
326
  try {
@@ -290,7 +342,7 @@ function jsql_update_by_id(table, id, data_json) {
290
342
  * @param {string} batch_json
291
343
  * @returns {string}
292
344
  */
293
- function jsql_update_by_ids(table, batch_json) {
345
+ export function jsql_update_by_ids(table, batch_json) {
294
346
  let deferred3_0;
295
347
  let deferred3_1;
296
348
  try {
@@ -423,7 +475,15 @@ function passStringToWasm0(arg, malloc, realloc) {
423
475
 
424
476
  let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
425
477
  cachedTextDecoder.decode();
478
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
479
+ let numBytesDecoded = 0;
426
480
  function decodeText(ptr, len) {
481
+ numBytesDecoded += len;
482
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
483
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
484
+ cachedTextDecoder.decode();
485
+ numBytesDecoded = len;
486
+ }
427
487
  return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
428
488
  }
429
489
 
@@ -442,21 +502,96 @@ if (!('encodeInto' in cachedTextEncoder)) {
442
502
 
443
503
  let WASM_VECTOR_LEN = 0;
444
504
 
505
+ let wasmModule, wasmInstance, wasm;
506
+ function __wbg_finalize_init(instance, module) {
507
+ wasmInstance = instance;
508
+ wasm = instance.exports;
509
+ wasmModule = module;
510
+ cachedDataViewMemory0 = null;
511
+ cachedUint8ArrayMemory0 = null;
512
+ wasm.__wbindgen_start();
513
+ return wasm;
514
+ }
515
+
516
+ async function __wbg_load(module, imports) {
517
+ if (typeof Response === 'function' && module instanceof Response) {
518
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
519
+ try {
520
+ return await WebAssembly.instantiateStreaming(module, imports);
521
+ } catch (e) {
522
+ const validResponse = module.ok && expectedResponseType(module.type);
523
+
524
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
525
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
526
+
527
+ } else { throw e; }
528
+ }
529
+ }
530
+
531
+ const bytes = await module.arrayBuffer();
532
+ return await WebAssembly.instantiate(bytes, imports);
533
+ } else {
534
+ const instance = await WebAssembly.instantiate(module, imports);
535
+
536
+ if (instance instanceof WebAssembly.Instance) {
537
+ return { instance, module };
538
+ } else {
539
+ return instance;
540
+ }
541
+ }
542
+
543
+ function expectedResponseType(type) {
544
+ switch (type) {
545
+ case 'basic': case 'cors': case 'default': return true;
546
+ }
547
+ return false;
548
+ }
549
+ }
550
+
551
+ function initSync(module) {
552
+ if (wasm !== undefined) return wasm;
553
+
554
+
555
+ if (module !== undefined) {
556
+ if (Object.getPrototypeOf(module) === Object.prototype) {
557
+ ({module} = module)
558
+ } else {
559
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
560
+ }
561
+ }
562
+
563
+ const imports = __wbg_get_imports();
564
+ if (!(module instanceof WebAssembly.Module)) {
565
+ module = new WebAssembly.Module(module);
566
+ }
567
+ const instance = new WebAssembly.Instance(module, imports);
568
+ return __wbg_finalize_init(instance, module);
569
+ }
570
+
571
+ async function __wbg_init(module_or_path) {
572
+ if (wasm !== undefined) return wasm;
573
+
574
+
575
+ if (module_or_path !== undefined) {
576
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
577
+ ({module_or_path} = module_or_path)
578
+ } else {
579
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
580
+ }
581
+ }
582
+
583
+ if (module_or_path === undefined) {
584
+ module_or_path = new URL('jsql_neo_wasm_bg.wasm', import.meta.url);
585
+ }
586
+ const imports = __wbg_get_imports();
587
+
588
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
589
+ module_or_path = fetch(module_or_path);
590
+ }
445
591
 
592
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
446
593
 
447
- export async function init(input) {
448
- cachedDataViewMemory0 = null;
449
- cachedUint8ArrayMemory0 = null;
450
- let bytes;
451
- if (input instanceof Uint8Array) bytes = input;
452
- else if (input instanceof ArrayBuffer) bytes = new Uint8Array(input);
453
- else if (input instanceof Response) bytes = new Uint8Array(await input.arrayBuffer());
454
- else if (input instanceof WebAssembly.Module) { wasm = new WebAssembly.Instance(input, __wbg_get_imports()).exports; wasm.__wbindgen_start(); return wasm; }
455
- else bytes = new Uint8Array(await (await fetch(input || new URL('./jsql_neo_wasm_bg.wasm', import.meta.url))).arrayBuffer());
456
- const result = await WebAssembly.instantiate(bytes, __wbg_get_imports());
457
- wasm = result.instance.exports;
458
- wasm.__wbindgen_start();
459
- return wasm;
594
+ return __wbg_finalize_init(instance, module);
460
595
  }
461
596
 
462
- export { jsql_count, jsql_create_table, jsql_drop_table, jsql_find, jsql_find_by_id, jsql_find_by_ids, jsql_insert, jsql_insert_buf, jsql_insert_buf_count, jsql_insert_json, jsql_remove_by_id, jsql_remove_by_ids, jsql_reset, jsql_update_by_id, jsql_update_by_ids, __wbg_get_imports };
597
+ export { initSync, __wbg_init as default };
@@ -1,6 +1,10 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
 
4
+ export function jsql_begin_tx(): string;
5
+
6
+ export function jsql_commit_tx(tx_id: string): string;
7
+
4
8
  export function jsql_count(table: string): string;
5
9
 
6
10
  export function jsql_create_table(name: string, schema_json: string): string;
@@ -27,6 +31,8 @@ export function jsql_remove_by_ids(table: string, ids_json: string): string;
27
31
 
28
32
  export function jsql_reset(): void;
29
33
 
34
+ export function jsql_rollback_tx(tx_id: string): string;
35
+
30
36
  export function jsql_update_by_id(table: string, id: bigint, data_json: string): string;
31
37
 
32
38
  export function jsql_update_by_ids(table: string, batch_json: string): string;
@@ -1,5 +1,42 @@
1
1
  /* @ts-self-types="./jsql_neo_wasm.d.ts" */
2
2
 
3
+ /**
4
+ * @returns {string}
5
+ */
6
+ function jsql_begin_tx() {
7
+ let deferred1_0;
8
+ let deferred1_1;
9
+ try {
10
+ const ret = wasm.jsql_begin_tx();
11
+ deferred1_0 = ret[0];
12
+ deferred1_1 = ret[1];
13
+ return getStringFromWasm0(ret[0], ret[1]);
14
+ } finally {
15
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
16
+ }
17
+ }
18
+ exports.jsql_begin_tx = jsql_begin_tx;
19
+
20
+ /**
21
+ * @param {string} tx_id
22
+ * @returns {string}
23
+ */
24
+ function jsql_commit_tx(tx_id) {
25
+ let deferred2_0;
26
+ let deferred2_1;
27
+ try {
28
+ const ptr0 = passStringToWasm0(tx_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
29
+ const len0 = WASM_VECTOR_LEN;
30
+ const ret = wasm.jsql_commit_tx(ptr0, len0);
31
+ deferred2_0 = ret[0];
32
+ deferred2_1 = ret[1];
33
+ return getStringFromWasm0(ret[0], ret[1]);
34
+ } finally {
35
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
36
+ }
37
+ }
38
+ exports.jsql_commit_tx = jsql_commit_tx;
39
+
3
40
  /**
4
41
  * @param {string} table
5
42
  * @returns {string}
@@ -273,6 +310,26 @@ function jsql_reset() {
273
310
  }
274
311
  exports.jsql_reset = jsql_reset;
275
312
 
313
+ /**
314
+ * @param {string} tx_id
315
+ * @returns {string}
316
+ */
317
+ function jsql_rollback_tx(tx_id) {
318
+ let deferred2_0;
319
+ let deferred2_1;
320
+ try {
321
+ const ptr0 = passStringToWasm0(tx_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
322
+ const len0 = WASM_VECTOR_LEN;
323
+ const ret = wasm.jsql_rollback_tx(ptr0, len0);
324
+ deferred2_0 = ret[0];
325
+ deferred2_1 = ret[1];
326
+ return getStringFromWasm0(ret[0], ret[1]);
327
+ } finally {
328
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
329
+ }
330
+ }
331
+ exports.jsql_rollback_tx = jsql_rollback_tx;
332
+
276
333
  /**
277
334
  * @param {string} table
278
335
  * @param {bigint} id
Binary file
@@ -1,6 +1,8 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
+ export const jsql_begin_tx: () => [number, number];
5
+ export const jsql_commit_tx: (a: number, b: number) => [number, number];
4
6
  export const jsql_count: (a: number, b: number) => [number, number];
5
7
  export const jsql_create_table: (a: number, b: number, c: number, d: number) => [number, number];
6
8
  export const jsql_drop_table: (a: number, b: number) => [number, number];
@@ -13,6 +15,7 @@ export const jsql_insert_buf_count: (a: number, b: number, c: number, d: number)
13
15
  export const jsql_insert_json: (a: number, b: number, c: number, d: number) => [number, number];
14
16
  export const jsql_remove_by_id: (a: number, b: number, c: bigint) => [number, number];
15
17
  export const jsql_remove_by_ids: (a: number, b: number, c: number, d: number) => [number, number];
18
+ export const jsql_rollback_tx: (a: number, b: number) => [number, number];
16
19
  export const jsql_update_by_id: (a: number, b: number, c: bigint, d: number, e: number) => [number, number];
17
20
  export const jsql_update_by_ids: (a: number, b: number, c: number, d: number) => [number, number];
18
21
  export const jsql_reset: () => void;
package/wasm/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsql-neo-wasm",
3
- "version": "0.1.0",
3
+ "version": "5.4.0",
4
4
  "files": [
5
5
  "jsql_neo_wasm_bg.wasm",
6
6
  "jsql_neo_wasm.js",
@@ -1,122 +0,0 @@
1
- const { Worker, MessageChannel, receiveMessageOnPort } = require('worker_threads');
2
- const path = require('path');
3
- const os = require('os');
4
- const zlib = require('zlib');
5
-
6
- const POOL_SIZE = Math.max(2, Math.min(os.cpus().length - 1, 8));
7
-
8
- let pool = null;
9
-
10
- class SyncCompressionPool {
11
- constructor(size) {
12
- this.size = size;
13
- this.workers = [];
14
- this.ports = [];
15
- this.nextId = 1;
16
- const wp = path.join(__dirname, 'compress_worker.js');
17
-
18
- for (let i = 0; i < size; i++) {
19
- const { port1, port2 } = new MessageChannel();
20
- const worker = new Worker(wp);
21
- worker.postMessage({ type: 'init', port: port2 }, [port2]);
22
- worker.unref();
23
- this.workers.push({ worker, port: port1 });
24
- this.ports.push(port1);
25
- }
26
- }
27
-
28
- _getIdle() {
29
- for (const p of this.ports) {
30
- if (!p._busy) return p;
31
- }
32
- return null;
33
- }
34
-
35
- _copyBuffer(data) {
36
- const src = Buffer.isBuffer(data) ? data : Buffer.from(data);
37
- const ab = new ArrayBuffer(src.length);
38
- const dst = Buffer.from(ab);
39
- src.copy(dst);
40
- return dst;
41
- }
42
-
43
- _sendMsg(port, msg, data) {
44
- const copy = this._copyBuffer(data);
45
- port._busy = true;
46
- port.postMessage({ ...msg, data: copy.buffer, level: msg.level || 1 }, [copy.buffer]);
47
- }
48
-
49
- _waitResult(port) {
50
- let r = null;
51
- while (!r) { r = receiveMessageOnPort(port); }
52
- port._busy = false;
53
- if (r.message.error) throw new Error(r.message.error);
54
- return r.message;
55
- }
56
-
57
- compressSync(data, level = 1) {
58
- const port = this._getIdle();
59
- if (!port) {
60
- return { result: zlib.gzipSync(Buffer.isBuffer(data) ? data : Buffer.from(data), { level }).buffer };
61
- }
62
- const id = this.nextId++;
63
- this._sendMsg(port, { type: 'compress', id, level }, data);
64
- return this._waitResult(port);
65
- }
66
-
67
- decompressSync(data) {
68
- const port = this._getIdle();
69
- if (!port) {
70
- return { result: zlib.gunzipSync(Buffer.isBuffer(data) ? data : Buffer.from(data)).buffer };
71
- }
72
- const id = this.nextId++;
73
- this._sendMsg(port, { type: 'decompress', id }, data);
74
- return this._waitResult(port);
75
- }
76
-
77
- compressBatchSync(blocks, level = 1) {
78
- const n = blocks.length;
79
- const results = new Array(n);
80
- let submitted = 0;
81
- let completed = 0;
82
-
83
- const trySubmit = () => {
84
- while (submitted < n) {
85
- const port = this._getIdle();
86
- if (!port) break;
87
- const idx = submitted++;
88
- port._idx = idx;
89
- port._busy = true;
90
- const copy = this._copyBuffer(blocks[idx]);
91
- port.postMessage({ type: 'compress', id: this.nextId++, data: copy.buffer, level }, [copy.buffer]);
92
- }
93
- };
94
-
95
- trySubmit();
96
- while (completed < n) {
97
- for (const port of this.ports) {
98
- if (!port._busy) continue;
99
- const msg = receiveMessageOnPort(port);
100
- if (msg) {
101
- results[port._idx] = msg.message;
102
- port._busy = false;
103
- completed++;
104
- trySubmit();
105
- }
106
- }
107
- }
108
- return results;
109
- }
110
-
111
- terminate() {
112
- for (const { worker } of this.workers) worker.terminate();
113
- pool = null;
114
- }
115
- }
116
-
117
- function getPool() {
118
- if (!pool) pool = new SyncCompressionPool(POOL_SIZE);
119
- return pool;
120
- }
121
-
122
- module.exports = { getPool, SyncCompressionPool };
@@ -1,32 +0,0 @@
1
- const { parentPort } = require('worker_threads');
2
- const zlib = require('zlib');
3
-
4
- let commPort = null;
5
-
6
- parentPort.on('message', (msg) => {
7
- if (msg.type === 'init' && msg.port) {
8
- commPort = msg.port;
9
- commPort.on('message', (task) => {
10
- try {
11
- if (task.type === 'compress') {
12
- const buf = Buffer.from(task.data);
13
- const result = zlib.gzipSync(buf, { level: task.level || 1 });
14
- const ab = new ArrayBuffer(result.length);
15
- const view = new Uint8Array(ab);
16
- for (let i = 0; i < result.length; i++) view[i] = result[i];
17
- commPort.postMessage({ id: task.id, result: ab, len: result.length }, [ab]);
18
- } else if (task.type === 'decompress') {
19
- const buf = Buffer.from(task.data);
20
- const result = zlib.gunzipSync(buf);
21
- const ab = new ArrayBuffer(result.length);
22
- const view = new Uint8Array(ab);
23
- for (let i = 0; i < result.length; i++) view[i] = result[i];
24
- commPort.postMessage({ id: task.id, result: ab, len: result.length }, [ab]);
25
- }
26
- } catch (e) {
27
- commPort.postMessage({ id: task.id, error: e.message });
28
- }
29
- });
30
- commPort.unref();
31
- }
32
- });