jsql-neo 3.4.8 → 3.5.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.
@@ -5,97 +5,115 @@ function safeJsonParse(str) {
5
5
  try { return JSON.parse(str); } catch { return str; }
6
6
  }
7
7
 
8
- const textEncoder = new TextEncoder();
9
-
10
- function utf8Len(s) {
11
- let len = 0;
12
- for (let i = 0; i < s.length; i++) {
13
- const c = s.charCodeAt(i);
14
- if (c < 0x80) len++;
15
- else if (c < 0x800) len += 2;
16
- else if (c < 0xD800 || c > 0xDFFF) len += 3;
17
- else { len += 4; i++; }
18
- }
19
- return len;
20
- }
21
-
22
- function writeUtf8(buf, off, s) {
23
- for (let i = 0; i < s.length; i++) {
24
- const c = s.charCodeAt(i);
25
- if (c < 0x80) { buf[off++] = c; }
26
- else if (c < 0x800) { buf[off++] = 0xC0 | (c >> 6); buf[off++] = 0x80 | (c & 0x3F); }
27
- else if (c < 0xD800 || c > 0xDFFF) { buf[off++] = 0xE0 | (c >> 12); buf[off++] = 0x80 | ((c >> 6) & 0x3F); buf[off++] = 0x80 | (c & 0x3F); }
28
- else { const cp = 0x10000 + ((c & 0x3FF) << 10) + (s.charCodeAt(++i) & 0x3FF); buf[off++] = 0xF0 | (cp >> 18); buf[off++] = 0x80 | ((cp >> 12) & 0x3F); buf[off++] = 0x80 | ((cp >> 6) & 0x3F); buf[off++] = 0x80 | (cp & 0x3F); }
29
- }
30
- return off;
31
- }
8
+ const INT_TAG = 1;
9
+ const FLOAT_TAG = 2;
10
+ const STR_TAG = 3;
11
+ const BOOL_TAG = 4;
32
12
 
33
13
  function encodeBatch(rows) {
34
14
  if (rows.length === 0) return new Uint8Array(0);
35
15
  const fieldNames = Object.keys(rows[0]);
36
16
  const nFields = fieldNames.length;
37
17
 
38
- // First pass: compute exact size, no allocations
39
- let size = 1;
40
- for (let fi = 0; fi < nFields; fi++) size += 1 + utf8Len(fieldNames[fi]);
41
- size += 4;
42
-
43
- for (let ri = 0; ri < rows.length; ri++) {
44
- const row = rows[ri];
45
- for (let fi = 0; fi < nFields; fi++) {
46
- const val = row[fieldNames[fi]];
47
- if (val === null || val === undefined) size += 1;
48
- else if (typeof val === 'number') size += 9;
49
- else if (typeof val === 'string') size += 1 + 4 + utf8Len(val);
50
- else size += 2;
51
- }
52
- }
53
-
54
- // Second pass: write directly to pre-allocated buffer
55
- const buf = new Uint8Array(size);
56
- const dv = new DataView(buf.buffer, 0, size);
18
+ // Estimate buffer: header ~100 + rows * 120 bytes/row
19
+ const est = 100 + rows.length * 120;
20
+ const buf = Buffer.allocUnsafe(est);
57
21
  let off = 0;
58
22
 
59
- buf[off++] = nFields;
23
+ off = buf.writeUInt8(nFields, off);
60
24
  for (let fi = 0; fi < nFields; fi++) {
61
25
  const s = fieldNames[fi];
62
- buf[off++] = utf8Len(s);
63
- off = writeUtf8(buf, off, s);
26
+ const nlen = Buffer.byteLength(s, 'utf8');
27
+ off = buf.writeUInt8(nlen, off);
28
+ off += buf.write(s, off, nlen, 'utf8');
64
29
  }
65
-
66
- dv.setUint32(off, rows.length, true);
67
- off += 4;
30
+ off = buf.writeUInt32LE(rows.length, off);
68
31
 
69
32
  for (let ri = 0; ri < rows.length; ri++) {
70
33
  const row = rows[ri];
71
- for (let fi = 0; fi < nFields; fi++) {
72
- const val = row[fieldNames[fi]];
73
- if (val === null || val === undefined) {
74
- buf[off++] = 0;
75
- } else if (typeof val === 'number') {
76
- if (Number.isInteger(val)) {
77
- buf[off++] = 1;
78
- dv.setBigInt64(off, BigInt(val), true);
79
- off += 8;
80
- } else {
81
- buf[off++] = 2;
82
- dv.setFloat64(off, val, true);
83
- off += 8;
84
- }
85
- } else if (typeof val === 'string') {
86
- buf[off++] = 3;
87
- const strLen = utf8Len(val);
88
- dv.setUint32(off, strLen, true);
89
- off += 4;
90
- off = writeUtf8(buf, off, val);
91
- } else {
92
- buf[off++] = 4;
93
- buf[off++] = val ? 1 : 0;
94
- }
34
+ let fi = 0;
35
+ if (nFields >= 1) {
36
+ const v = row[fieldNames[0]];
37
+ if (v === null || v === undefined) { off = buf.writeUInt8(0, off); }
38
+ else if (typeof v === 'number') {
39
+ if (Number.isInteger(v)) { off = buf.writeUInt8(INT_TAG, off); off = buf.writeBigInt64LE(BigInt(v), off); }
40
+ else { off = buf.writeUInt8(FLOAT_TAG, off); off = buf.writeDoubleLE(v, off); }
41
+ } else if (typeof v === 'string') {
42
+ off = buf.writeUInt8(STR_TAG, off);
43
+ const sl = Buffer.byteLength(v, 'utf8');
44
+ off = buf.writeUInt32LE(sl, off);
45
+ off += buf.write(v, off, sl, 'utf8');
46
+ } else { off = buf.writeUInt8(BOOL_TAG, off); off = buf.writeUInt8(v ? 1 : 0, off); }
47
+ }
48
+ if (nFields >= 2) {
49
+ const v = row[fieldNames[1]];
50
+ if (v === null || v === undefined) { off = buf.writeUInt8(0, off); }
51
+ else if (typeof v === 'number') {
52
+ if (Number.isInteger(v)) { off = buf.writeUInt8(INT_TAG, off); off = buf.writeBigInt64LE(BigInt(v), off); }
53
+ else { off = buf.writeUInt8(FLOAT_TAG, off); off = buf.writeDoubleLE(v, off); }
54
+ } else if (typeof v === 'string') {
55
+ off = buf.writeUInt8(STR_TAG, off);
56
+ const sl = Buffer.byteLength(v, 'utf8');
57
+ off = buf.writeUInt32LE(sl, off);
58
+ off += buf.write(v, off, sl, 'utf8');
59
+ } else { off = buf.writeUInt8(BOOL_TAG, off); off = buf.writeUInt8(v ? 1 : 0, off); }
60
+ }
61
+ if (nFields >= 3) {
62
+ const v = row[fieldNames[2]];
63
+ if (v === null || v === undefined) { off = buf.writeUInt8(0, off); }
64
+ else if (typeof v === 'number') {
65
+ if (Number.isInteger(v)) { off = buf.writeUInt8(INT_TAG, off); off = buf.writeBigInt64LE(BigInt(v), off); }
66
+ else { off = buf.writeUInt8(FLOAT_TAG, off); off = buf.writeDoubleLE(v, off); }
67
+ } else if (typeof v === 'string') {
68
+ off = buf.writeUInt8(STR_TAG, off);
69
+ const sl = Buffer.byteLength(v, 'utf8');
70
+ off = buf.writeUInt32LE(sl, off);
71
+ off += buf.write(v, off, sl, 'utf8');
72
+ } else { off = buf.writeUInt8(BOOL_TAG, off); off = buf.writeUInt8(v ? 1 : 0, off); }
73
+ }
74
+ if (nFields >= 4) {
75
+ const v = row[fieldNames[3]];
76
+ if (v === null || v === undefined) { off = buf.writeUInt8(0, off); }
77
+ else if (typeof v === 'number') {
78
+ if (Number.isInteger(v)) { off = buf.writeUInt8(INT_TAG, off); off = buf.writeBigInt64LE(BigInt(v), off); }
79
+ else { off = buf.writeUInt8(FLOAT_TAG, off); off = buf.writeDoubleLE(v, off); }
80
+ } else if (typeof v === 'string') {
81
+ off = buf.writeUInt8(STR_TAG, off);
82
+ const sl = Buffer.byteLength(v, 'utf8');
83
+ off = buf.writeUInt32LE(sl, off);
84
+ off += buf.write(v, off, sl, 'utf8');
85
+ } else { off = buf.writeUInt8(BOOL_TAG, off); off = buf.writeUInt8(v ? 1 : 0, off); }
86
+ }
87
+ if (nFields >= 5) {
88
+ const v = row[fieldNames[4]];
89
+ if (v === null || v === undefined) { off = buf.writeUInt8(0, off); }
90
+ else if (typeof v === 'number') {
91
+ if (Number.isInteger(v)) { off = buf.writeUInt8(INT_TAG, off); off = buf.writeBigInt64LE(BigInt(v), off); }
92
+ else { off = buf.writeUInt8(FLOAT_TAG, off); off = buf.writeDoubleLE(v, off); }
93
+ } else if (typeof v === 'string') {
94
+ off = buf.writeUInt8(STR_TAG, off);
95
+ const sl = Buffer.byteLength(v, 'utf8');
96
+ off = buf.writeUInt32LE(sl, off);
97
+ off += buf.write(v, off, sl, 'utf8');
98
+ } else { off = buf.writeUInt8(BOOL_TAG, off); off = buf.writeUInt8(v ? 1 : 0, off); }
99
+ }
100
+ // fallback for >5 fields
101
+ for (let fi = 5; fi < nFields; fi++) {
102
+ const v = row[fieldNames[fi]];
103
+ if (v === null || v === undefined) { off = buf.writeUInt8(0, off); }
104
+ else if (typeof v === 'number') {
105
+ if (Number.isInteger(v)) { off = buf.writeUInt8(INT_TAG, off); off = buf.writeBigInt64LE(BigInt(v), off); }
106
+ else { off = buf.writeUInt8(FLOAT_TAG, off); off = buf.writeDoubleLE(v, off); }
107
+ } else if (typeof v === 'string') {
108
+ off = buf.writeUInt8(STR_TAG, off);
109
+ const sl = Buffer.byteLength(v, 'utf8');
110
+ off = buf.writeUInt32LE(sl, off);
111
+ off += buf.write(v, off, sl, 'utf8');
112
+ } else { off = buf.writeUInt8(BOOL_TAG, off); off = buf.writeUInt8(v ? 1 : 0, off); }
95
113
  }
96
114
  }
97
115
 
98
- return buf;
116
+ return buf.subarray(0, off);
99
117
  }
100
118
 
101
119
  class JSQL {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jsql-neo",
3
- "version": "3.4.8",
3
+ "version": "3.5.0",
4
4
  "description": "JSQL-NEO — Rust-powered embedded database with WASM, REST API, B-Tree indexes, WAL, crash recovery",
5
5
  "main": "index.js",
6
6
  "files": [
@@ -1,357 +1,9 @@
1
1
  /* @ts-self-types="./jsql_neo_wasm.d.ts" */
2
+ import * as wasm from "./jsql_neo_wasm_bg.wasm";
3
+ import { __wbg_set_wasm } from "./jsql_neo_wasm_bg.js";
2
4
 
3
- /**
4
- * @param {string} table
5
- * @returns {string}
6
- */
7
- function jsql_count(table) {
8
- let deferred2_0;
9
- let deferred2_1;
10
- try {
11
- const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
12
- const len0 = WASM_VECTOR_LEN;
13
- const ret = wasm.jsql_count(ptr0, len0);
14
- deferred2_0 = ret[0];
15
- deferred2_1 = ret[1];
16
- return getStringFromWasm0(ret[0], ret[1]);
17
- } finally {
18
- wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
19
- }
20
- }
21
- exports.jsql_count = jsql_count;
22
-
23
- /**
24
- * @param {string} name
25
- * @param {string} schema_json
26
- * @returns {string}
27
- */
28
- function jsql_create_table(name, schema_json) {
29
- let deferred3_0;
30
- let deferred3_1;
31
- try {
32
- const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
33
- const len0 = WASM_VECTOR_LEN;
34
- const ptr1 = passStringToWasm0(schema_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
35
- const len1 = WASM_VECTOR_LEN;
36
- const ret = wasm.jsql_create_table(ptr0, len0, ptr1, len1);
37
- deferred3_0 = ret[0];
38
- deferred3_1 = ret[1];
39
- return getStringFromWasm0(ret[0], ret[1]);
40
- } finally {
41
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
42
- }
43
- }
44
- exports.jsql_create_table = jsql_create_table;
45
-
46
- /**
47
- * @param {string} name
48
- * @returns {string}
49
- */
50
- function jsql_drop_table(name) {
51
- let deferred2_0;
52
- let deferred2_1;
53
- try {
54
- const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
55
- const len0 = WASM_VECTOR_LEN;
56
- const ret = wasm.jsql_drop_table(ptr0, len0);
57
- deferred2_0 = ret[0];
58
- deferred2_1 = ret[1];
59
- return getStringFromWasm0(ret[0], ret[1]);
60
- } finally {
61
- wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
62
- }
63
- }
64
- exports.jsql_drop_table = jsql_drop_table;
65
-
66
- /**
67
- * @param {string} table
68
- * @param {string} filter_json
69
- * @param {number} limit
70
- * @param {number} offset
71
- * @returns {string}
72
- */
73
- function jsql_find(table, filter_json, limit, offset) {
74
- let deferred3_0;
75
- let deferred3_1;
76
- try {
77
- const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
78
- const len0 = WASM_VECTOR_LEN;
79
- const ptr1 = passStringToWasm0(filter_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
80
- const len1 = WASM_VECTOR_LEN;
81
- const ret = wasm.jsql_find(ptr0, len0, ptr1, len1, limit, offset);
82
- deferred3_0 = ret[0];
83
- deferred3_1 = ret[1];
84
- return getStringFromWasm0(ret[0], ret[1]);
85
- } finally {
86
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
87
- }
88
- }
89
- exports.jsql_find = jsql_find;
90
-
91
- /**
92
- * @param {string} table
93
- * @param {bigint} id
94
- * @returns {string}
95
- */
96
- function jsql_find_by_id(table, id) {
97
- let deferred2_0;
98
- let deferred2_1;
99
- try {
100
- const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
101
- const len0 = WASM_VECTOR_LEN;
102
- const ret = wasm.jsql_find_by_id(ptr0, len0, id);
103
- deferred2_0 = ret[0];
104
- deferred2_1 = ret[1];
105
- return getStringFromWasm0(ret[0], ret[1]);
106
- } finally {
107
- wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
108
- }
109
- }
110
- exports.jsql_find_by_id = jsql_find_by_id;
111
-
112
- /**
113
- * @param {string} table
114
- * @param {string} data_json
115
- * @returns {string}
116
- */
117
- function jsql_insert(table, data_json) {
118
- let deferred3_0;
119
- let deferred3_1;
120
- try {
121
- const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
122
- const len0 = WASM_VECTOR_LEN;
123
- const ptr1 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
124
- const len1 = WASM_VECTOR_LEN;
125
- const ret = wasm.jsql_insert(ptr0, len0, ptr1, len1);
126
- deferred3_0 = ret[0];
127
- deferred3_1 = ret[1];
128
- return getStringFromWasm0(ret[0], ret[1]);
129
- } finally {
130
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
131
- }
132
- }
133
- exports.jsql_insert = jsql_insert;
134
-
135
- /**
136
- * @param {string} table
137
- * @param {Uint8Array} data
138
- * @returns {string}
139
- */
140
- function jsql_insert_buf(table, data) {
141
- let deferred3_0;
142
- let deferred3_1;
143
- try {
144
- const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
145
- const len0 = WASM_VECTOR_LEN;
146
- const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
147
- const len1 = WASM_VECTOR_LEN;
148
- const ret = wasm.jsql_insert_buf(ptr0, len0, ptr1, len1);
149
- deferred3_0 = ret[0];
150
- deferred3_1 = ret[1];
151
- return getStringFromWasm0(ret[0], ret[1]);
152
- } finally {
153
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
154
- }
155
- }
156
- exports.jsql_insert_buf = jsql_insert_buf;
157
-
158
- /**
159
- * @param {string} table
160
- * @param {Uint8Array} data
161
- * @returns {string}
162
- */
163
- function jsql_insert_buf_count(table, data) {
164
- let deferred3_0;
165
- let deferred3_1;
166
- try {
167
- const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
168
- const len0 = WASM_VECTOR_LEN;
169
- const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
170
- const len1 = WASM_VECTOR_LEN;
171
- const ret = wasm.jsql_insert_buf_count(ptr0, len0, ptr1, len1);
172
- deferred3_0 = ret[0];
173
- deferred3_1 = ret[1];
174
- return getStringFromWasm0(ret[0], ret[1]);
175
- } finally {
176
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
177
- }
178
- }
179
- exports.jsql_insert_buf_count = jsql_insert_buf_count;
180
-
181
- /**
182
- * @param {string} table
183
- * @param {bigint} id
184
- * @returns {string}
185
- */
186
- function jsql_remove_by_id(table, id) {
187
- let deferred2_0;
188
- let deferred2_1;
189
- try {
190
- const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
191
- const len0 = WASM_VECTOR_LEN;
192
- const ret = wasm.jsql_remove_by_id(ptr0, len0, id);
193
- deferred2_0 = ret[0];
194
- deferred2_1 = ret[1];
195
- return getStringFromWasm0(ret[0], ret[1]);
196
- } finally {
197
- wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
198
- }
199
- }
200
- exports.jsql_remove_by_id = jsql_remove_by_id;
201
-
202
- /**
203
- * @param {string} table
204
- * @param {bigint} id
205
- * @param {string} data_json
206
- * @returns {string}
207
- */
208
- function jsql_update_by_id(table, id, data_json) {
209
- let deferred3_0;
210
- let deferred3_1;
211
- try {
212
- const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
213
- const len0 = WASM_VECTOR_LEN;
214
- const ptr1 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
215
- const len1 = WASM_VECTOR_LEN;
216
- const ret = wasm.jsql_update_by_id(ptr0, len0, id, ptr1, len1);
217
- deferred3_0 = ret[0];
218
- deferred3_1 = ret[1];
219
- return getStringFromWasm0(ret[0], ret[1]);
220
- } finally {
221
- wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
222
- }
223
- }
224
- exports.jsql_update_by_id = jsql_update_by_id;
225
- function __wbg_get_imports() {
226
- const import0 = {
227
- __proto__: null,
228
- __wbg___wbindgen_string_get_b0ca35b86a603356: function(arg0, arg1) {
229
- const obj = arg1;
230
- const ret = typeof(obj) === 'string' ? obj : undefined;
231
- var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
232
- var len1 = WASM_VECTOR_LEN;
233
- getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
234
- getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
235
- },
236
- __wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
237
- throw new Error(getStringFromWasm0(arg0, arg1));
238
- },
239
- __wbg_new_0_3da9e97f24fc69be: function() {
240
- const ret = new Date();
241
- return ret;
242
- },
243
- __wbg_toISOString_706fbe321055ee58: function(arg0) {
244
- const ret = arg0.toISOString();
245
- return ret;
246
- },
247
- __wbindgen_init_externref_table: function() {
248
- const table = wasm.__wbindgen_externrefs;
249
- const offset = table.grow(4);
250
- table.set(0, undefined);
251
- table.set(offset + 0, undefined);
252
- table.set(offset + 1, null);
253
- table.set(offset + 2, true);
254
- table.set(offset + 3, false);
255
- },
256
- };
257
- return {
258
- __proto__: null,
259
- "./jsql_neo_wasm_bg.js": import0,
260
- };
261
- }
262
-
263
- let cachedDataViewMemory0 = null;
264
- function getDataViewMemory0() {
265
- if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
266
- cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
267
- }
268
- return cachedDataViewMemory0;
269
- }
270
-
271
- function getStringFromWasm0(ptr, len) {
272
- return decodeText(ptr >>> 0, len);
273
- }
274
-
275
- let cachedUint8ArrayMemory0 = null;
276
- function getUint8ArrayMemory0() {
277
- if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
278
- cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
279
- }
280
- return cachedUint8ArrayMemory0;
281
- }
282
-
283
- function isLikeNone(x) {
284
- return x === undefined || x === null;
285
- }
286
-
287
- function passArray8ToWasm0(arg, malloc) {
288
- const ptr = malloc(arg.length * 1, 1) >>> 0;
289
- getUint8ArrayMemory0().set(arg, ptr / 1);
290
- WASM_VECTOR_LEN = arg.length;
291
- return ptr;
292
- }
293
-
294
- function passStringToWasm0(arg, malloc, realloc) {
295
- if (realloc === undefined) {
296
- const buf = cachedTextEncoder.encode(arg);
297
- const ptr = malloc(buf.length, 1) >>> 0;
298
- getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
299
- WASM_VECTOR_LEN = buf.length;
300
- return ptr;
301
- }
302
-
303
- let len = arg.length;
304
- let ptr = malloc(len, 1) >>> 0;
305
-
306
- const mem = getUint8ArrayMemory0();
307
-
308
- let offset = 0;
309
-
310
- for (; offset < len; offset++) {
311
- const code = arg.charCodeAt(offset);
312
- if (code > 0x7F) break;
313
- mem[ptr + offset] = code;
314
- }
315
- if (offset !== len) {
316
- if (offset !== 0) {
317
- arg = arg.slice(offset);
318
- }
319
- ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
320
- const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
321
- const ret = cachedTextEncoder.encodeInto(arg, view);
322
-
323
- offset += ret.written;
324
- ptr = realloc(ptr, len, offset, 1) >>> 0;
325
- }
326
-
327
- WASM_VECTOR_LEN = offset;
328
- return ptr;
329
- }
330
-
331
- let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
332
- cachedTextDecoder.decode();
333
- function decodeText(ptr, len) {
334
- return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
335
- }
336
-
337
- const cachedTextEncoder = new TextEncoder();
338
-
339
- if (!('encodeInto' in cachedTextEncoder)) {
340
- cachedTextEncoder.encodeInto = function (arg, view) {
341
- const buf = cachedTextEncoder.encode(arg);
342
- view.set(buf);
343
- return {
344
- read: arg.length,
345
- written: buf.length
346
- };
347
- };
348
- }
349
-
350
- let WASM_VECTOR_LEN = 0;
351
-
352
- const wasmPath = `${__dirname}/jsql_neo_wasm_bg.wasm`;
353
- const wasmBytes = require('fs').readFileSync(wasmPath);
354
- const wasmModule = new WebAssembly.Module(wasmBytes);
355
- let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
356
- let wasm = wasmInstance.exports;
5
+ __wbg_set_wasm(wasm);
357
6
  wasm.__wbindgen_start();
7
+ export {
8
+ jsql_count, jsql_create_table, jsql_drop_table, jsql_find, jsql_find_by_id, jsql_insert, jsql_insert_buf, jsql_insert_buf_count, jsql_remove_by_id, jsql_update_by_id
9
+ } from "./jsql_neo_wasm_bg.js";
@@ -0,0 +1,351 @@
1
+ /**
2
+ * @param {string} table
3
+ * @returns {string}
4
+ */
5
+ export function jsql_count(table) {
6
+ let deferred2_0;
7
+ let deferred2_1;
8
+ try {
9
+ const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
10
+ const len0 = WASM_VECTOR_LEN;
11
+ const ret = wasm.jsql_count(ptr0, len0);
12
+ deferred2_0 = ret[0];
13
+ deferred2_1 = ret[1];
14
+ return getStringFromWasm0(ret[0], ret[1]);
15
+ } finally {
16
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
17
+ }
18
+ }
19
+
20
+ /**
21
+ * @param {string} name
22
+ * @param {string} schema_json
23
+ * @returns {string}
24
+ */
25
+ export function jsql_create_table(name, schema_json) {
26
+ let deferred3_0;
27
+ let deferred3_1;
28
+ try {
29
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
30
+ const len0 = WASM_VECTOR_LEN;
31
+ const ptr1 = passStringToWasm0(schema_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
32
+ const len1 = WASM_VECTOR_LEN;
33
+ const ret = wasm.jsql_create_table(ptr0, len0, ptr1, len1);
34
+ deferred3_0 = ret[0];
35
+ deferred3_1 = ret[1];
36
+ return getStringFromWasm0(ret[0], ret[1]);
37
+ } finally {
38
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
39
+ }
40
+ }
41
+
42
+ /**
43
+ * @param {string} name
44
+ * @returns {string}
45
+ */
46
+ export function jsql_drop_table(name) {
47
+ let deferred2_0;
48
+ let deferred2_1;
49
+ try {
50
+ const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
51
+ const len0 = WASM_VECTOR_LEN;
52
+ const ret = wasm.jsql_drop_table(ptr0, len0);
53
+ deferred2_0 = ret[0];
54
+ deferred2_1 = ret[1];
55
+ return getStringFromWasm0(ret[0], ret[1]);
56
+ } finally {
57
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
58
+ }
59
+ }
60
+
61
+ /**
62
+ * @param {string} table
63
+ * @param {string} filter_json
64
+ * @param {number} limit
65
+ * @param {number} offset
66
+ * @returns {string}
67
+ */
68
+ export function jsql_find(table, filter_json, limit, offset) {
69
+ let deferred3_0;
70
+ let deferred3_1;
71
+ try {
72
+ const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
73
+ const len0 = WASM_VECTOR_LEN;
74
+ const ptr1 = passStringToWasm0(filter_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
75
+ const len1 = WASM_VECTOR_LEN;
76
+ const ret = wasm.jsql_find(ptr0, len0, ptr1, len1, limit, offset);
77
+ deferred3_0 = ret[0];
78
+ deferred3_1 = ret[1];
79
+ return getStringFromWasm0(ret[0], ret[1]);
80
+ } finally {
81
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
82
+ }
83
+ }
84
+
85
+ /**
86
+ * @param {string} table
87
+ * @param {bigint} id
88
+ * @returns {string}
89
+ */
90
+ export function jsql_find_by_id(table, id) {
91
+ let deferred2_0;
92
+ let deferred2_1;
93
+ try {
94
+ const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
95
+ const len0 = WASM_VECTOR_LEN;
96
+ const ret = wasm.jsql_find_by_id(ptr0, len0, id);
97
+ deferred2_0 = ret[0];
98
+ deferred2_1 = ret[1];
99
+ return getStringFromWasm0(ret[0], ret[1]);
100
+ } finally {
101
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
102
+ }
103
+ }
104
+
105
+ /**
106
+ * @param {string} table
107
+ * @param {string} data_json
108
+ * @returns {string}
109
+ */
110
+ export function jsql_insert(table, data_json) {
111
+ let deferred3_0;
112
+ let deferred3_1;
113
+ try {
114
+ const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
115
+ const len0 = WASM_VECTOR_LEN;
116
+ const ptr1 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
117
+ const len1 = WASM_VECTOR_LEN;
118
+ const ret = wasm.jsql_insert(ptr0, len0, ptr1, len1);
119
+ deferred3_0 = ret[0];
120
+ deferred3_1 = ret[1];
121
+ return getStringFromWasm0(ret[0], ret[1]);
122
+ } finally {
123
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
124
+ }
125
+ }
126
+
127
+ /**
128
+ * @param {string} table
129
+ * @param {Uint8Array} data
130
+ * @returns {string}
131
+ */
132
+ export function jsql_insert_buf(table, data) {
133
+ let deferred3_0;
134
+ let deferred3_1;
135
+ try {
136
+ const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
137
+ const len0 = WASM_VECTOR_LEN;
138
+ const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
139
+ const len1 = WASM_VECTOR_LEN;
140
+ const ret = wasm.jsql_insert_buf(ptr0, len0, ptr1, len1);
141
+ deferred3_0 = ret[0];
142
+ deferred3_1 = ret[1];
143
+ return getStringFromWasm0(ret[0], ret[1]);
144
+ } finally {
145
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
146
+ }
147
+ }
148
+
149
+ /**
150
+ * @param {string} table
151
+ * @param {Uint8Array} data
152
+ * @returns {string}
153
+ */
154
+ export function jsql_insert_buf_count(table, data) {
155
+ let deferred3_0;
156
+ let deferred3_1;
157
+ try {
158
+ const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
159
+ const len0 = WASM_VECTOR_LEN;
160
+ const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
161
+ const len1 = WASM_VECTOR_LEN;
162
+ const ret = wasm.jsql_insert_buf_count(ptr0, len0, ptr1, len1);
163
+ deferred3_0 = ret[0];
164
+ deferred3_1 = ret[1];
165
+ return getStringFromWasm0(ret[0], ret[1]);
166
+ } finally {
167
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
168
+ }
169
+ }
170
+
171
+ /**
172
+ * @param {string} table
173
+ * @param {bigint} id
174
+ * @returns {string}
175
+ */
176
+ export function jsql_remove_by_id(table, id) {
177
+ let deferred2_0;
178
+ let deferred2_1;
179
+ try {
180
+ const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
181
+ const len0 = WASM_VECTOR_LEN;
182
+ const ret = wasm.jsql_remove_by_id(ptr0, len0, id);
183
+ deferred2_0 = ret[0];
184
+ deferred2_1 = ret[1];
185
+ return getStringFromWasm0(ret[0], ret[1]);
186
+ } finally {
187
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
188
+ }
189
+ }
190
+
191
+ /**
192
+ * @param {string} table
193
+ * @param {bigint} id
194
+ * @param {string} data_json
195
+ * @returns {string}
196
+ */
197
+ export function jsql_update_by_id(table, id, data_json) {
198
+ let deferred3_0;
199
+ let deferred3_1;
200
+ try {
201
+ const ptr0 = passStringToWasm0(table, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
202
+ const len0 = WASM_VECTOR_LEN;
203
+ const ptr1 = passStringToWasm0(data_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
204
+ const len1 = WASM_VECTOR_LEN;
205
+ const ret = wasm.jsql_update_by_id(ptr0, len0, id, ptr1, len1);
206
+ deferred3_0 = ret[0];
207
+ deferred3_1 = ret[1];
208
+ return getStringFromWasm0(ret[0], ret[1]);
209
+ } finally {
210
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
211
+ }
212
+ }
213
+ export function __wbg___wbindgen_string_get_b0ca35b86a603356(arg0, arg1) {
214
+ const obj = arg1;
215
+ const ret = typeof(obj) === 'string' ? obj : undefined;
216
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
217
+ var len1 = WASM_VECTOR_LEN;
218
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
219
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
220
+ }
221
+ export function __wbg___wbindgen_throw_344f42d3211c4765(arg0, arg1) {
222
+ throw new Error(getStringFromWasm0(arg0, arg1));
223
+ }
224
+ export function __wbg_new_cc984128914cfc6f(arg0) {
225
+ const ret = new Date(arg0);
226
+ return ret;
227
+ }
228
+ export function __wbg_now_86c0d4ba3fa605b8() {
229
+ const ret = Date.now();
230
+ return ret;
231
+ }
232
+ export function __wbg_toISOString_706fbe321055ee58(arg0) {
233
+ const ret = arg0.toISOString();
234
+ return ret;
235
+ }
236
+ export function __wbindgen_cast_0000000000000001(arg0) {
237
+ // Cast intrinsic for `F64 -> Externref`.
238
+ const ret = arg0;
239
+ return ret;
240
+ }
241
+ export function __wbindgen_init_externref_table() {
242
+ const table = wasm.__wbindgen_externrefs;
243
+ const offset = table.grow(4);
244
+ table.set(0, undefined);
245
+ table.set(offset + 0, undefined);
246
+ table.set(offset + 1, null);
247
+ table.set(offset + 2, true);
248
+ table.set(offset + 3, false);
249
+ }
250
+ let cachedDataViewMemory0 = null;
251
+ function getDataViewMemory0() {
252
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
253
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
254
+ }
255
+ return cachedDataViewMemory0;
256
+ }
257
+
258
+ function getStringFromWasm0(ptr, len) {
259
+ return decodeText(ptr >>> 0, len);
260
+ }
261
+
262
+ let cachedUint8ArrayMemory0 = null;
263
+ function getUint8ArrayMemory0() {
264
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
265
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
266
+ }
267
+ return cachedUint8ArrayMemory0;
268
+ }
269
+
270
+ function isLikeNone(x) {
271
+ return x === undefined || x === null;
272
+ }
273
+
274
+ function passArray8ToWasm0(arg, malloc) {
275
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
276
+ getUint8ArrayMemory0().set(arg, ptr / 1);
277
+ WASM_VECTOR_LEN = arg.length;
278
+ return ptr;
279
+ }
280
+
281
+ function passStringToWasm0(arg, malloc, realloc) {
282
+ if (realloc === undefined) {
283
+ const buf = cachedTextEncoder.encode(arg);
284
+ const ptr = malloc(buf.length, 1) >>> 0;
285
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
286
+ WASM_VECTOR_LEN = buf.length;
287
+ return ptr;
288
+ }
289
+
290
+ let len = arg.length;
291
+ let ptr = malloc(len, 1) >>> 0;
292
+
293
+ const mem = getUint8ArrayMemory0();
294
+
295
+ let offset = 0;
296
+
297
+ for (; offset < len; offset++) {
298
+ const code = arg.charCodeAt(offset);
299
+ if (code > 0x7F) break;
300
+ mem[ptr + offset] = code;
301
+ }
302
+ if (offset !== len) {
303
+ if (offset !== 0) {
304
+ arg = arg.slice(offset);
305
+ }
306
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
307
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
308
+ const ret = cachedTextEncoder.encodeInto(arg, view);
309
+
310
+ offset += ret.written;
311
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
312
+ }
313
+
314
+ WASM_VECTOR_LEN = offset;
315
+ return ptr;
316
+ }
317
+
318
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
319
+ cachedTextDecoder.decode();
320
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
321
+ let numBytesDecoded = 0;
322
+ function decodeText(ptr, len) {
323
+ numBytesDecoded += len;
324
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
325
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
326
+ cachedTextDecoder.decode();
327
+ numBytesDecoded = len;
328
+ }
329
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
330
+ }
331
+
332
+ const cachedTextEncoder = new TextEncoder();
333
+
334
+ if (!('encodeInto' in cachedTextEncoder)) {
335
+ cachedTextEncoder.encodeInto = function (arg, view) {
336
+ const buf = cachedTextEncoder.encode(arg);
337
+ view.set(buf);
338
+ return {
339
+ read: arg.length,
340
+ written: buf.length
341
+ };
342
+ };
343
+ }
344
+
345
+ let WASM_VECTOR_LEN = 0;
346
+
347
+
348
+ let wasm;
349
+ export function __wbg_set_wasm(val) {
350
+ wasm = val;
351
+ }
Binary file
package/wasm/package.json CHANGED
@@ -1,12 +1,18 @@
1
1
  {
2
2
  "name": "jsql-neo-wasm",
3
+ "type": "module",
3
4
  "description": "JSQL Neo WASM bindings",
4
5
  "version": "0.1.0",
5
6
  "files": [
6
7
  "jsql_neo_wasm_bg.wasm",
7
8
  "jsql_neo_wasm.js",
9
+ "jsql_neo_wasm_bg.js",
8
10
  "jsql_neo_wasm.d.ts"
9
11
  ],
10
12
  "main": "jsql_neo_wasm.js",
11
- "types": "jsql_neo_wasm.d.ts"
13
+ "types": "jsql_neo_wasm.d.ts",
14
+ "sideEffects": [
15
+ "./jsql_neo_wasm.js",
16
+ "./snippets/*"
17
+ ]
12
18
  }