jsql-neo 5.3.1 → 5.4.1
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/LICENSE +0 -0
- package/README.md +240 -33
- package/bin/jsql +0 -0
- package/bin/jsql-server +0 -0
- package/bin/jsql-server-control.js +0 -0
- package/index.d.ts +0 -0
- package/index.js +0 -0
- package/lib/btree.js +0 -0
- package/lib/cache.js +0 -0
- package/lib/client.js +0 -0
- package/lib/database.js +0 -0
- package/lib/date-types.js +0 -0
- package/lib/errors.js +0 -0
- package/lib/jsql_format.js +0 -0
- package/lib/migrate.js +0 -0
- package/lib/mod.js +0 -0
- package/lib/mongo_server.js +1 -1
- package/lib/multiserver.js +0 -0
- package/lib/mysql_compat.js +0 -0
- package/lib/mysql_server.js +0 -0
- package/lib/native_client.js +182 -23
- package/lib/nedb_compat.js +0 -0
- package/lib/pg_server.js +0 -0
- package/lib/plugin.js +0 -0
- package/lib/query.js +0 -0
- package/lib/redis_server.js +0 -0
- package/lib/sql.js +0 -0
- package/lib/sqlite_compat.js +0 -0
- package/lib/sqlite_worker.js +5 -1
- package/lib/table.js +0 -0
- package/lib/tui.js +0 -0
- package/lib/wasm.js +0 -0
- package/lib/wasm_client.js +200 -23
- package/lib/web_ui.js +1 -1
- package/nativesrc/jsql-neo-core/Cargo.lock +0 -0
- package/nativesrc/jsql-neo-core/Cargo.toml +1 -1
- package/nativesrc/jsql-neo-core/src/engine/hybrid.rs +0 -0
- package/nativesrc/jsql-neo-core/src/engine/memory.rs +0 -0
- package/nativesrc/jsql-neo-core/src/engine/mod.rs +0 -0
- package/nativesrc/jsql-neo-core/src/engine/table.rs +0 -0
- package/nativesrc/jsql-neo-core/src/lib.rs +0 -0
- package/nativesrc/jsql-neo-core/src/storage/mod.rs +0 -0
- package/nativesrc/jsql-neo-core/src/storage/persistent.rs +0 -0
- package/nativesrc/jsql-neo-core/src/storage/wal.rs +0 -0
- package/nativesrc/jsql-neo-core/src/types.rs +0 -0
- package/nativesrc/jsql-neo-native/Cargo.lock +0 -0
- package/nativesrc/jsql-neo-native/Cargo.toml +1 -1
- package/nativesrc/jsql-neo-native/build.rs +0 -0
- package/nativesrc/jsql-neo-native/jsql-neo-native.node +0 -0
- package/nativesrc/jsql-neo-native/package.json +0 -0
- package/nativesrc/jsql-neo-native/src/lib.rs +0 -0
- package/nativesrc/jsql-neo-wasm/Cargo.lock +2 -2
- package/nativesrc/jsql-neo-wasm/Cargo.toml +1 -1
- package/nativesrc/jsql-neo-wasm/src/lib.rs +24 -0
- package/package.json +3 -3
- package/postinstall.js +146 -25
- package/test/btree.test.js +0 -0
- package/test/coverage.js +0 -0
- package/test/join.test.js +110 -0
- package/test/native.test.js +159 -0
- package/test/regress-5.1.0.js +0 -0
- package/test/smoke.js +0 -0
- package/test/wasm.test.js +111 -0
- package/wasm/browser.d.ts +81 -80
- package/wasm/browser.mjs +407 -242
- package/wasm/browser_bg.mjs +166 -31
- package/wasm/jsql_neo_wasm.d.ts +6 -0
- package/wasm/jsql_neo_wasm.js +57 -0
- package/wasm/jsql_neo_wasm_bg.wasm +0 -0
- package/wasm/jsql_neo_wasm_bg.wasm.d.ts +3 -0
- package/wasm/package.json +1 -1
- package/bin/jsql-neo-server +0 -0
- package/lib/compress_pool.js +0 -122
- package/lib/compress_worker.js +0 -32
- package/wasm/jsql_neo_wasm_bg.js +0 -373
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* WASM (.wasm) regression tests
|
|
3
|
+
* node test/wasm.test.js
|
|
4
|
+
* Covers: JSQL CRUD + flat row shape, shorthand schemas, pk-aware by-id CRUD,
|
|
5
|
+
* non-auto pk insert backfill, and beginTransaction / rollback / commit.
|
|
6
|
+
*/
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const ROOT = path.join(__dirname, '..');
|
|
9
|
+
|
|
10
|
+
let passed = 0, failed = 0;
|
|
11
|
+
function ok(name, cond, extra) {
|
|
12
|
+
if (cond) { passed++; console.log('[OK]', name); }
|
|
13
|
+
else { failed++; console.log('[FAIL]', name, extra !== undefined ? JSON.stringify(extra) : ''); }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
(async () => {
|
|
17
|
+
const { JSQL } = require(path.join(ROOT, 'lib', 'wasm_client'));
|
|
18
|
+
|
|
19
|
+
/* ---------- basic CRUD + flat row shape ---------- */
|
|
20
|
+
{
|
|
21
|
+
const db = new JSQL({ modules: false });
|
|
22
|
+
await db.start();
|
|
23
|
+
await db.createTable('users', { id: 'integer primary key auto_increment', name: 'string', age: 'integer' });
|
|
24
|
+
const ids = await db.insert('users', [{ name: 'Alice', age: 30 }, { name: 'Bob', age: 25 }]);
|
|
25
|
+
ok('wasm batch insert returns ids', Array.isArray(ids) && ids.length === 2, ids);
|
|
26
|
+
|
|
27
|
+
const row = await db.findById('users', 1);
|
|
28
|
+
ok('wasm findById flat row', row && row.id === 1 && row.name === 'Alice' && !('fields' in row), row);
|
|
29
|
+
|
|
30
|
+
const rows = await db.find('users', {});
|
|
31
|
+
ok('wasm find returns flat rows', rows.length === 2 && rows[1].name === 'Bob', rows);
|
|
32
|
+
ok('wasm filter match', (await db.find('users', { age: 25 })).length === 1);
|
|
33
|
+
ok('wasm count', (await db.count('users')) === 2);
|
|
34
|
+
|
|
35
|
+
await db.updateById('users', 1, { age: 31 });
|
|
36
|
+
ok('wasm updateById applied', (await db.findById('users', 1)).age === 31, await db.findById('users', 1));
|
|
37
|
+
|
|
38
|
+
await db.updateByIds('users', [[2, { age: 99 }]]);
|
|
39
|
+
ok('wasm updateByIds applied', (await db.findById('users', 2)).age === 99, await db.findById('users', 2));
|
|
40
|
+
|
|
41
|
+
ok('wasm findByIds', (await db.findByIds('users', [1, 2])).length === 2);
|
|
42
|
+
|
|
43
|
+
await db.removeById('users', 1);
|
|
44
|
+
ok('wasm removeById applied', (await db.count('users')) === 1, await db.count('users'));
|
|
45
|
+
|
|
46
|
+
await db.removeByIds('users', [2]);
|
|
47
|
+
ok('wasm removeByIds applied', (await db.count('users')) === 0, await db.count('users'));
|
|
48
|
+
await db.stop();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* ---------- non-auto pk: id resolution by pk value ---------- */
|
|
52
|
+
{
|
|
53
|
+
const db = new JSQL({ modules: false });
|
|
54
|
+
await db.start();
|
|
55
|
+
await db.createTable('config', { key: { type: 'string', primaryKey: true }, value: 'string' });
|
|
56
|
+
const ids = await db.insert('config', [{ key: 'a', value: '1' }, { key: 'b', value: '2' }]);
|
|
57
|
+
ok('wasm non-auto pk insert returns pk values', JSON.stringify(ids) === JSON.stringify(['a', 'b']), ids);
|
|
58
|
+
|
|
59
|
+
const a = await db.findById('config', 'a');
|
|
60
|
+
ok('wasm findById resolves string pk', a && a.value === '1' && !('fields' in a), a);
|
|
61
|
+
ok('wasm findById pk miss returns null', (await db.findById('config', 'nope')) === null);
|
|
62
|
+
|
|
63
|
+
await db.updateById('config', 'b', { value: '22' });
|
|
64
|
+
ok('wasm updateById resolves string pk', (await db.findById('config', 'b')).value === '22', await db.findById('config', 'b'));
|
|
65
|
+
|
|
66
|
+
await db.removeById('config', 'a');
|
|
67
|
+
ok('wasm removeById resolves string pk', (await db.count('config')) === 1, await db.count('config'));
|
|
68
|
+
|
|
69
|
+
await db.removeByIds('config', ['b']);
|
|
70
|
+
ok('wasm removeByIds resolves string pk', (await db.count('config')) === 0, await db.count('config'));
|
|
71
|
+
await db.stop();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/* ---------- shorthand schema ---------- */
|
|
75
|
+
{
|
|
76
|
+
const db = new JSQL({ modules: false });
|
|
77
|
+
await db.start();
|
|
78
|
+
await db.createTable('t2', { name: 'string unique', n: 'number', ok: 'boolean' });
|
|
79
|
+
await db.insert('t2', { name: 'x', n: 1.5, ok: true });
|
|
80
|
+
const r2 = (await db.find('t2', {}))[0];
|
|
81
|
+
ok('wasm shorthand schema fields', r2.name === 'x' && r2.n === 1.5 && r2.ok === true, r2);
|
|
82
|
+
|
|
83
|
+
await db.createTable('cfg', 'key string primary key, value string');
|
|
84
|
+
const cfgIds = await db.insert('cfg', { key: 'a', value: '1' });
|
|
85
|
+
ok('wasm full shorthand string schema', cfgIds[0] === 'a' && (await db.findById('cfg', 'a')).value === '1', cfgIds);
|
|
86
|
+
await db.stop();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/* ---------- transactions ---------- */
|
|
90
|
+
{
|
|
91
|
+
const db = new JSQL({ modules: false });
|
|
92
|
+
await db.start();
|
|
93
|
+
await db.createTable('tx', { id: 'integer primary key auto_increment', name: 'string' });
|
|
94
|
+
await db.insert('tx', { name: 'n1' });
|
|
95
|
+
await db.beginTransaction();
|
|
96
|
+
await db.insert('tx', { name: 'n2' });
|
|
97
|
+
await db.rollback();
|
|
98
|
+
ok('wasm rollback reverts insert', (await db.count('tx')) === 1, await db.count('tx'));
|
|
99
|
+
await db.beginTransaction();
|
|
100
|
+
await db.insert('tx', { name: 'n3' });
|
|
101
|
+
await db.commit();
|
|
102
|
+
ok('wasm commit keeps insert', (await db.count('tx')) === 2, await db.count('tx'));
|
|
103
|
+
await db.stop();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
console.log(`\n${passed} passed, ${failed} failed`);
|
|
107
|
+
process.exit(failed ? 1 : 0);
|
|
108
|
+
})().catch(e => {
|
|
109
|
+
console.error('[FATAL]', e.stack.split('\n').slice(0, 3).join('\n'));
|
|
110
|
+
process.exit(1);
|
|
111
|
+
});
|
package/wasm/browser.d.ts
CHANGED
|
@@ -1,88 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
4
3
|
|
|
5
|
-
export
|
|
6
|
-
| 'string' | 'integer' | 'float' | 'boolean' | 'date' | 'datetime' | 'timestamp'
|
|
7
|
-
| 'object' | 'array' | 'any';
|
|
8
|
-
|
|
9
|
-
export interface FieldDef {
|
|
10
|
-
type: FieldType;
|
|
11
|
-
primaryKey?: boolean;
|
|
12
|
-
autoIncrement?: boolean;
|
|
13
|
-
unique?: boolean;
|
|
14
|
-
required?: boolean;
|
|
15
|
-
length?: number;
|
|
16
|
-
default?: unknown;
|
|
17
|
-
computed?: boolean;
|
|
18
|
-
}
|
|
4
|
+
export function jsql_begin_tx(): string;
|
|
19
5
|
|
|
20
|
-
export
|
|
6
|
+
export function jsql_commit_tx(tx_id: string): string;
|
|
21
7
|
|
|
22
|
-
export
|
|
23
|
-
id: number | string;
|
|
24
|
-
fields?: Record<string, unknown>;
|
|
25
|
-
created_at?: string;
|
|
26
|
-
updated_at?: string;
|
|
27
|
-
[key: string]: unknown;
|
|
28
|
-
}
|
|
8
|
+
export function jsql_count(table: string): string;
|
|
29
9
|
|
|
30
|
-
export
|
|
31
|
-
limit?: number;
|
|
32
|
-
offset?: number;
|
|
33
|
-
}
|
|
10
|
+
export function jsql_create_table(name: string, schema_json: string): string;
|
|
34
11
|
|
|
35
|
-
export
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
pageSize?: number;
|
|
51
|
-
}
|
|
12
|
+
export function jsql_drop_table(name: string): string;
|
|
13
|
+
|
|
14
|
+
export function jsql_find(table: string, filter_json: string, limit: number, offset: number): string;
|
|
15
|
+
|
|
16
|
+
export function jsql_find_by_id(table: string, id: bigint): string;
|
|
17
|
+
|
|
18
|
+
export function jsql_find_by_ids(table: string, ids_json: string): string;
|
|
19
|
+
|
|
20
|
+
export function jsql_insert(table: string, data_json: string): string;
|
|
21
|
+
|
|
22
|
+
export function jsql_insert_buf(table: string, data: Uint8Array): string;
|
|
23
|
+
|
|
24
|
+
export function jsql_insert_buf_count(table: string, data: Uint8Array): string;
|
|
25
|
+
|
|
26
|
+
export function jsql_insert_json(table: string, json: string): string;
|
|
52
27
|
|
|
53
|
-
export
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
28
|
+
export function jsql_remove_by_id(table: string, id: bigint): string;
|
|
29
|
+
|
|
30
|
+
export function jsql_remove_by_ids(table: string, ids_json: string): string;
|
|
31
|
+
|
|
32
|
+
export function jsql_reset(): void;
|
|
33
|
+
|
|
34
|
+
export function jsql_rollback_tx(tx_id: string): string;
|
|
35
|
+
|
|
36
|
+
export function jsql_update_by_id(table: string, id: bigint, data_json: string): string;
|
|
37
|
+
|
|
38
|
+
export function jsql_update_by_ids(table: string, batch_json: string): string;
|
|
39
|
+
|
|
40
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
41
|
+
|
|
42
|
+
export interface InitOutput {
|
|
43
|
+
readonly memory: WebAssembly.Memory;
|
|
44
|
+
readonly jsql_begin_tx: () => [number, number];
|
|
45
|
+
readonly jsql_commit_tx: (a: number, b: number) => [number, number];
|
|
46
|
+
readonly jsql_count: (a: number, b: number) => [number, number];
|
|
47
|
+
readonly jsql_create_table: (a: number, b: number, c: number, d: number) => [number, number];
|
|
48
|
+
readonly jsql_drop_table: (a: number, b: number) => [number, number];
|
|
49
|
+
readonly jsql_find: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number];
|
|
50
|
+
readonly jsql_find_by_id: (a: number, b: number, c: bigint) => [number, number];
|
|
51
|
+
readonly jsql_find_by_ids: (a: number, b: number, c: number, d: number) => [number, number];
|
|
52
|
+
readonly jsql_insert: (a: number, b: number, c: number, d: number) => [number, number];
|
|
53
|
+
readonly jsql_insert_buf: (a: number, b: number, c: number, d: number) => [number, number];
|
|
54
|
+
readonly jsql_insert_buf_count: (a: number, b: number, c: number, d: number) => [number, number];
|
|
55
|
+
readonly jsql_insert_json: (a: number, b: number, c: number, d: number) => [number, number];
|
|
56
|
+
readonly jsql_remove_by_id: (a: number, b: number, c: bigint) => [number, number];
|
|
57
|
+
readonly jsql_remove_by_ids: (a: number, b: number, c: number, d: number) => [number, number];
|
|
58
|
+
readonly jsql_rollback_tx: (a: number, b: number) => [number, number];
|
|
59
|
+
readonly jsql_update_by_id: (a: number, b: number, c: bigint, d: number, e: number) => [number, number];
|
|
60
|
+
readonly jsql_update_by_ids: (a: number, b: number, c: number, d: number) => [number, number];
|
|
61
|
+
readonly jsql_reset: () => void;
|
|
62
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
63
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
64
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
65
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
66
|
+
readonly __wbindgen_start: () => void;
|
|
86
67
|
}
|
|
87
68
|
|
|
88
|
-
export
|
|
69
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
73
|
+
* a precompiled `WebAssembly.Module`.
|
|
74
|
+
*
|
|
75
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
76
|
+
*
|
|
77
|
+
* @returns {InitOutput}
|
|
78
|
+
*/
|
|
79
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
83
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
84
|
+
*
|
|
85
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
86
|
+
*
|
|
87
|
+
* @returns {Promise<InitOutput>}
|
|
88
|
+
*/
|
|
89
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|