browser-sqlite 1.0.0-rc.3 → 1.0.0-rc.5
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/NOTICE +56 -0
- package/README.md +112 -104
- package/dist/LICENSE +21 -0
- package/dist/NOTICE +56 -0
- package/dist/abandon.d.ts +77 -0
- package/dist/api.d.ts +426 -0
- package/dist/bulk.d.ts +57 -0
- package/dist/capabilities.d.ts +23 -0
- package/dist/client.d.ts +221 -0
- package/dist/credits.d.ts +31 -0
- package/dist/{esm/src/debug.d.ts → debug.d.ts} +21 -10
- package/dist/delete.d.ts +48 -0
- package/dist/epochs.d.ts +85 -0
- package/dist/errors.d.ts +76 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/inspect.d.ts +96 -0
- package/dist/locks.d.ts +172 -0
- package/dist/logger.d.ts +24 -0
- package/dist/pool.d.ts +191 -0
- package/dist/queries.d.ts +65 -0
- package/dist/scheduler.d.ts +145 -0
- package/dist/sqlite-codes.d.ts +154 -0
- package/dist/supervisor.d.ts +17 -0
- package/dist/transaction.d.ts +61 -0
- package/dist/types.d.ts +642 -0
- package/dist/utils.d.ts +156 -0
- package/dist/worker/cloneable.d.ts +25 -0
- package/dist/worker/probes.d.ts +26 -0
- package/dist/worker/sqlite-code.d.ts +9 -0
- package/dist/worker/statement-cache.d.ts +36 -0
- package/dist/worker/wa-sqlite-async.wasm +0 -0
- package/dist/worker/wa-sqlite-jspi.wasm +0 -0
- package/dist/worker/wa-sqlite.wasm +0 -0
- package/dist/worker/worker.js +11 -0
- package/dist/worker/worker.js.map +1 -0
- package/package.json +46 -22
- package/dist/esm/index.js +0 -424
- package/dist/esm/rslib.config.d.ts +0 -2
- package/dist/esm/rstest.config.d.ts +0 -2
- package/dist/esm/src/client.d.ts +0 -332
- package/dist/esm/src/index.d.ts +0 -1
- package/dist/esm/src/orchestrator.d.ts +0 -87
- package/dist/esm/src/types.d.ts +0 -83
- package/dist/esm/src/utils.d.ts +0 -6
- /package/dist/{esm/src → worker}/worker.d.ts +0 -0
package/dist/esm/src/client.d.ts
DELETED
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
import type { SQLiteVFS } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Configuration options for creating a SQLite client.
|
|
4
|
-
*/
|
|
5
|
-
export type CreateSQLiteClientOptions = {
|
|
6
|
-
/**
|
|
7
|
-
* Database file name within the OPFS origin private file system.
|
|
8
|
-
* Each unique name maps to a distinct SQLite database file.
|
|
9
|
-
* @defaultValue `"SQLite"` prefix + auto-incremented client index
|
|
10
|
-
*/
|
|
11
|
-
name?: string;
|
|
12
|
-
/**
|
|
13
|
-
* Number of Web Workers spawned in the pool at initialization.
|
|
14
|
-
* A larger pool allows more concurrent read operations but increases
|
|
15
|
-
* memory consumption and OPFS file handle usage.
|
|
16
|
-
* Must be `1` when using `AccessHandlePoolVFS` — any larger value throws at construction time.
|
|
17
|
-
* @defaultValue `2`
|
|
18
|
-
*/
|
|
19
|
-
poolSize?: number;
|
|
20
|
-
/**
|
|
21
|
-
* Virtual File System implementation used for SQLite storage.
|
|
22
|
-
* Controls whether data is stored in OPFS, IndexedDB, or memory.
|
|
23
|
-
* See the README VFS Selection guide for a comparison.
|
|
24
|
-
* @defaultValue `'OPFSPermutedVFS'`
|
|
25
|
-
*/
|
|
26
|
-
vfs?: SQLiteVFS;
|
|
27
|
-
/**
|
|
28
|
-
* SQLite PRAGMAs applied to each worker's database connection on open.
|
|
29
|
-
* Keys are PRAGMA names, values are their string representations.
|
|
30
|
-
* Example: `{ journal_mode: 'WAL', synchronous: 'NORMAL' }`.
|
|
31
|
-
* If omitted, no PRAGMAs are applied beyond SQLite defaults.
|
|
32
|
-
*/
|
|
33
|
-
pragmas?: Record<string, string>;
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Query execution options.
|
|
37
|
-
*/
|
|
38
|
-
type SQLiteQueryOptions<_T extends Record<string, unknown>> = {
|
|
39
|
-
id?: string;
|
|
40
|
-
chunkSize?: number;
|
|
41
|
-
signal?: AbortSignal;
|
|
42
|
-
debug?: string;
|
|
43
|
-
};
|
|
44
|
-
type SQLiteStreamOptions<T extends Record<string, unknown>> = SQLiteQueryOptions<T> & {
|
|
45
|
-
signal?: AbortSignal;
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Main SQLite database API.
|
|
49
|
-
*/
|
|
50
|
-
export type SQLiteDB = {
|
|
51
|
-
/**
|
|
52
|
-
* Executes a SELECT query and returns all matching rows as an array.
|
|
53
|
-
*
|
|
54
|
-
* Read queries are dispatched to any available worker in the pool,
|
|
55
|
-
* enabling concurrent execution across multiple readers.
|
|
56
|
-
*
|
|
57
|
-
* @param sql - SQL query string. Must be a SELECT (or equivalent read) statement.
|
|
58
|
-
* @param params - Positional parameters bound to `?` placeholders.
|
|
59
|
-
* @param options - Optional query options (`chunkSize`, `signal`, `id`).
|
|
60
|
-
* @returns Promise resolving to an array of typed rows (`T[]`). Returns `[]` for empty results.
|
|
61
|
-
*/
|
|
62
|
-
read: <T extends Record<string, unknown>>(sql: string, params?: any[], options?: SQLiteQueryOptions<T>) => Promise<T[]>;
|
|
63
|
-
/**
|
|
64
|
-
* Executes a DML or DDL statement (INSERT, UPDATE, DELETE, CREATE, DROP, etc.)
|
|
65
|
-
* and returns both any result rows and the number of affected rows.
|
|
66
|
-
*
|
|
67
|
-
* Write queries are serialized through a single dedicated writer worker.
|
|
68
|
-
* Concurrent writes queue behind each other — only one write executes at a time.
|
|
69
|
-
*
|
|
70
|
-
* @param sql - SQL statement. Any statement recognized as a write by `isWriteQuery`.
|
|
71
|
-
* @param params - Positional parameters bound to `?` placeholders.
|
|
72
|
-
* @param options - Optional query options (`chunkSize`, `signal`, `id`).
|
|
73
|
-
* @returns Promise resolving to `{ result: T[], affected: number }` where
|
|
74
|
-
* `affected` is the SQLite `changes()` count for the statement.
|
|
75
|
-
*/
|
|
76
|
-
write: <T extends Record<string, unknown>>(sql: string, params?: any[], options?: SQLiteQueryOptions<T>) => Promise<{
|
|
77
|
-
result: T[];
|
|
78
|
-
affected: number;
|
|
79
|
-
}>;
|
|
80
|
-
/**
|
|
81
|
-
* Executes a query and yields result rows in chunks via an async generator.
|
|
82
|
-
* Memory-efficient for large result sets — rows are not buffered in full.
|
|
83
|
-
*
|
|
84
|
-
* @remarks
|
|
85
|
-
* **Worker held for full generator lifetime.** A pool worker is acquired when
|
|
86
|
-
* the generator is created and released only when the generator is fully
|
|
87
|
-
* exhausted or the caller uses `break`. Failing to exhaust the generator
|
|
88
|
-
* starves the pool. Always use `for await...of` to completion or `break` to exit.
|
|
89
|
-
*
|
|
90
|
-
* @param sql - SQL query string.
|
|
91
|
-
* @param params - Positional parameters bound to `?` placeholders.
|
|
92
|
-
* @param options - Optional options including `chunkSize` (default `500`),
|
|
93
|
-
* `signal` (AbortSignal to cancel), and `id`.
|
|
94
|
-
* @returns AsyncGenerator yielding `T[]` chunks of at most `chunkSize` rows.
|
|
95
|
-
*/
|
|
96
|
-
stream: <T extends Record<string, unknown>>(sql: string, params?: any[], options?: SQLiteStreamOptions<T>) => AsyncGenerator<T[]>;
|
|
97
|
-
/**
|
|
98
|
-
* Executes a query and returns the first row, or `undefined` if no rows match.
|
|
99
|
-
* Internally uses `chunkSize: 1` and aborts after the first result chunk.
|
|
100
|
-
*
|
|
101
|
-
* @remarks
|
|
102
|
-
* Intended for SELECT queries. Using `one()` with a write statement (INSERT, UPDATE)
|
|
103
|
-
* routes to the write worker and still executes the DML — use `write()` for mutations.
|
|
104
|
-
*
|
|
105
|
-
* @param sql - SQL query string.
|
|
106
|
-
* @param params - Positional parameters bound to `?` placeholders.
|
|
107
|
-
* @param options - Optional query options (`id`). `chunkSize` and `signal` are managed internally.
|
|
108
|
-
* @returns Promise resolving to the first row as `T`, or `undefined` if no rows.
|
|
109
|
-
*/
|
|
110
|
-
one: <T extends Record<string, unknown>>(sql: string, params?: any[], options?: SQLiteQueryOptions<T>) => Promise<T | undefined>;
|
|
111
|
-
/**
|
|
112
|
-
* Executes a callback within a SQLite transaction, providing a scoped
|
|
113
|
-
* `TransactionDB` with `read`, `write`, `stream`, and `one` methods.
|
|
114
|
-
*
|
|
115
|
-
* The worker is held exclusively for the transaction's duration.
|
|
116
|
-
* On callback success: auto-commits if `autoCommit` is `true` (default).
|
|
117
|
-
* On callback error: rolls back automatically.
|
|
118
|
-
* The callback may call `db.commit()` or `db.rollback()` manually.
|
|
119
|
-
*
|
|
120
|
-
* @param callback - Async function receiving a `TransactionDB` instance.
|
|
121
|
-
* @param options - `readOnly` (default `false`) prevents write statements;
|
|
122
|
-
* `autoCommit` (default `true`) commits on callback success.
|
|
123
|
-
* @returns Promise resolving to the value returned by `callback`.
|
|
124
|
-
*/
|
|
125
|
-
transaction: <T = void>(callback: (db: any) => Promise<T>, options?: {
|
|
126
|
-
readOnly?: boolean;
|
|
127
|
-
autoCommit?: boolean;
|
|
128
|
-
}) => Promise<T>;
|
|
129
|
-
/**
|
|
130
|
-
* Creates a buffered bulk-insert utility that batches rows to stay within
|
|
131
|
-
* SQLite's variable limit (`SQLITE_MAX_VARS = 32766`).
|
|
132
|
-
*
|
|
133
|
-
* Call `enqueue()` for each row to insert, then `close()` to flush the
|
|
134
|
-
* remaining buffer and await completion.
|
|
135
|
-
*
|
|
136
|
-
* @param table - Target table name.
|
|
137
|
-
* @param keys - Column names for the INSERT statement.
|
|
138
|
-
* @returns Object with:
|
|
139
|
-
* - `enqueue(data)` — buffers a row, flushing automatically when the buffer fills.
|
|
140
|
-
* - `close()` — flushes remaining rows and resolves with total affected row count.
|
|
141
|
-
*/
|
|
142
|
-
bulkWrite: <KEYS extends string>(table: string, keys: KEYS[]) => {
|
|
143
|
-
enqueue: (data: Record<KEYS, any>) => void;
|
|
144
|
-
close: () => Promise<number>;
|
|
145
|
-
};
|
|
146
|
-
/**
|
|
147
|
-
* Schema-driven table replacement: drops the existing table, creates a new one
|
|
148
|
-
* from the provided schema, bulk-inserts all enqueued rows, then creates indexes.
|
|
149
|
-
*
|
|
150
|
-
* Useful for full-refresh ETL patterns where a table is rebuilt from scratch.
|
|
151
|
-
*
|
|
152
|
-
* @param table - Table name to drop and recreate.
|
|
153
|
-
* @param schema - Column definition map. Values are SQL type strings or
|
|
154
|
-
* objects with `{ type, required?, unique?, generated? }`.
|
|
155
|
-
* @param options - `indexes` array and `temp` flag for TEMPORARY tables.
|
|
156
|
-
* @returns Object with `enqueue(data)` and `close()` following the same
|
|
157
|
-
* contract as {@link SQLiteDB.bulkWrite}.
|
|
158
|
-
*/
|
|
159
|
-
output: <SCHEMA extends Record<string, any>>(table: string, schema: SCHEMA, options?: any) => {
|
|
160
|
-
enqueue: (data: any) => void;
|
|
161
|
-
close: () => Promise<number>;
|
|
162
|
-
};
|
|
163
|
-
/**
|
|
164
|
-
* Terminates all workers in the pool.
|
|
165
|
-
*
|
|
166
|
-
* @remarks
|
|
167
|
-
* **OPFS files are NOT deleted.** `close()` calls `worker.terminate()` on each
|
|
168
|
-
* pool worker — it does not remove any OPFS database files. Files created by
|
|
169
|
-
* browser-sqlite persist in the origin's private file system across page loads.
|
|
170
|
-
* To delete OPFS files, use the `navigator.storage.getDirectory()` API directly.
|
|
171
|
-
*/
|
|
172
|
-
close: () => void;
|
|
173
|
-
/**
|
|
174
|
-
* Internal diagnostic handle. Not part of the stable public API.
|
|
175
|
-
* Shape is subject to change without notice.
|
|
176
|
-
* @internal
|
|
177
|
-
*/
|
|
178
|
-
debug: unknown;
|
|
179
|
-
};
|
|
180
|
-
/**
|
|
181
|
-
* Creates a SQLite client backed by a pool of Web Workers, each running
|
|
182
|
-
* a wa-sqlite instance in a dedicated thread.
|
|
183
|
-
*
|
|
184
|
-
* @remarks
|
|
185
|
-
* **Browser requirements (COOP/COEP):** This function constructs a
|
|
186
|
-
* `SharedArrayBuffer` for cross-thread worker synchronization. Browsers
|
|
187
|
-
* require the page to be served with the following HTTP headers:
|
|
188
|
-
* ```
|
|
189
|
-
* Cross-Origin-Opener-Policy: same-origin
|
|
190
|
-
* Cross-Origin-Embedder-Policy: require-corp
|
|
191
|
-
* ```
|
|
192
|
-
* Without these headers, `new SharedArrayBuffer()` throws a `SecurityError`
|
|
193
|
-
* and the pool will never initialize.
|
|
194
|
-
*
|
|
195
|
-
* **Worker pool side effect:** Calling this function immediately spawns
|
|
196
|
-
* `poolSize` Web Worker threads and begins asynchronous database
|
|
197
|
-
* initialization. Workers become queryable once they emit a `ready` message.
|
|
198
|
-
*
|
|
199
|
-
* @param file - SQLite database file name within the OPFS origin.
|
|
200
|
-
* Each distinct name corresponds to a separate database file.
|
|
201
|
-
* @param clientOptions - Optional pool and VFS configuration.
|
|
202
|
-
* See {@link CreateSQLiteClientOptions} for field defaults.
|
|
203
|
-
* @returns A {@link SQLiteDB} object providing `read`, `write`, `stream`,
|
|
204
|
-
* `one`, `transaction`, `bulkWrite`, `output`, and `close` methods.
|
|
205
|
-
*
|
|
206
|
-
* @throws {Error} When `vfs` is `'AccessHandlePoolVFS'` and `poolSize` is
|
|
207
|
-
* greater than `1`. AccessHandlePoolVFS does not support concurrent access
|
|
208
|
-
* handles — set `poolSize: 1` explicitly when using this VFS.
|
|
209
|
-
*
|
|
210
|
-
* @example
|
|
211
|
-
* ```typescript
|
|
212
|
-
* import { createSQLiteClient } from 'browser-sqlite';
|
|
213
|
-
*
|
|
214
|
-
* const db = createSQLiteClient('myapp.sqlite', {
|
|
215
|
-
* poolSize: 3,
|
|
216
|
-
* vfs: 'OPFSPermutedVFS',
|
|
217
|
-
* pragmas: { journal_mode: 'WAL', synchronous: 'NORMAL' },
|
|
218
|
-
* });
|
|
219
|
-
*
|
|
220
|
-
* const users = await db.read<{ id: number; name: string }>(
|
|
221
|
-
* 'SELECT id, name FROM users WHERE active = ?',
|
|
222
|
-
* [1],
|
|
223
|
-
* );
|
|
224
|
-
* ```
|
|
225
|
-
*/
|
|
226
|
-
export declare const createSQLiteClient: (file: string, clientOptions?: CreateSQLiteClientOptions) => {
|
|
227
|
-
read: <T extends Record<string, unknown> = Record<string, unknown>>(sql: string, params?: unknown[], options?: SQLiteQueryOptions<T>) => Promise<T[]>;
|
|
228
|
-
write: <T extends Record<string, unknown> = Record<string, unknown>>(sql: string, params?: unknown[], options?: SQLiteQueryOptions<T>) => Promise<{
|
|
229
|
-
result: T[];
|
|
230
|
-
affected: number;
|
|
231
|
-
}>;
|
|
232
|
-
stream: <T extends Record<string, unknown> = Record<string, unknown>>(sql: string, params?: unknown[], options?: SQLiteQueryOptions<T>) => AsyncGenerator<T[], void, unknown>;
|
|
233
|
-
one: <T extends Record<string, unknown> = Record<string, unknown>>(sql: string, params?: unknown[], options?: Omit<SQLiteQueryOptions<T>, "chunkSize" | "signal">) => Promise<T | undefined>;
|
|
234
|
-
transaction: <T = void>(callback: (db: Pick<SQLiteDB, "one" | "read" | "write" | "stream"> & {
|
|
235
|
-
commit: () => Promise<void>;
|
|
236
|
-
rollback: () => Promise<void>;
|
|
237
|
-
}) => Promise<T>, options?: {
|
|
238
|
-
readOnly?: boolean;
|
|
239
|
-
autoCommit?: boolean;
|
|
240
|
-
}) => Promise<T>;
|
|
241
|
-
bulkWrite: <KEYS extends string>(table: string, keys: KEYS[]) => {
|
|
242
|
-
enqueue: (data: { [K in KEYS]: any; }) => void;
|
|
243
|
-
close: () => Promise<number>;
|
|
244
|
-
};
|
|
245
|
-
output: <SCHEMA extends Record<string, string | {
|
|
246
|
-
type: string;
|
|
247
|
-
generated?: string;
|
|
248
|
-
required?: boolean;
|
|
249
|
-
unique?: boolean;
|
|
250
|
-
}>>(table: string, schema: SCHEMA, options?: {
|
|
251
|
-
indexes?: (keyof SCHEMA | (keyof SCHEMA)[] | ({
|
|
252
|
-
unique?: boolean;
|
|
253
|
-
} & ({
|
|
254
|
-
column: keyof SCHEMA;
|
|
255
|
-
} | {
|
|
256
|
-
columns: (keyof SCHEMA)[];
|
|
257
|
-
})))[] | undefined;
|
|
258
|
-
temp?: boolean;
|
|
259
|
-
}) => {
|
|
260
|
-
enqueue: (data: { [K in keyof SCHEMA as SCHEMA[K] extends {
|
|
261
|
-
generated: string;
|
|
262
|
-
} ? never : K]: any; }) => void;
|
|
263
|
-
close: () => Promise<number>;
|
|
264
|
-
};
|
|
265
|
-
close: () => void;
|
|
266
|
-
debug: {
|
|
267
|
-
readonly file: string;
|
|
268
|
-
readonly vfs: SQLiteVFS;
|
|
269
|
-
readonly pragmas: Record<string, string>;
|
|
270
|
-
readonly name: string;
|
|
271
|
-
readonly queue: {
|
|
272
|
-
write: number;
|
|
273
|
-
read: number;
|
|
274
|
-
};
|
|
275
|
-
workers: {
|
|
276
|
-
index: number;
|
|
277
|
-
name: string;
|
|
278
|
-
creationTime: number;
|
|
279
|
-
initializationTime?: number;
|
|
280
|
-
requests: {
|
|
281
|
-
startTime: number;
|
|
282
|
-
acquireTime?: number;
|
|
283
|
-
releaseTime?: number;
|
|
284
|
-
affectedRows: number;
|
|
285
|
-
queries: {
|
|
286
|
-
sql: string;
|
|
287
|
-
params?: any[];
|
|
288
|
-
startTime: number;
|
|
289
|
-
firstRowTime?: number;
|
|
290
|
-
endTime?: number;
|
|
291
|
-
error?: any;
|
|
292
|
-
affectedRows: number;
|
|
293
|
-
}[];
|
|
294
|
-
currentQuery?: {
|
|
295
|
-
sql: string;
|
|
296
|
-
params?: any[];
|
|
297
|
-
startTime: number;
|
|
298
|
-
firstRowTime?: number;
|
|
299
|
-
endTime?: number;
|
|
300
|
-
error?: any;
|
|
301
|
-
affectedRows: number;
|
|
302
|
-
};
|
|
303
|
-
}[];
|
|
304
|
-
currentRequest?: {
|
|
305
|
-
startTime: number;
|
|
306
|
-
acquireTime?: number;
|
|
307
|
-
releaseTime?: number;
|
|
308
|
-
affectedRows: number;
|
|
309
|
-
queries: {
|
|
310
|
-
sql: string;
|
|
311
|
-
params?: any[];
|
|
312
|
-
startTime: number;
|
|
313
|
-
firstRowTime?: number;
|
|
314
|
-
endTime?: number;
|
|
315
|
-
error?: any;
|
|
316
|
-
affectedRows: number;
|
|
317
|
-
}[];
|
|
318
|
-
currentQuery?: {
|
|
319
|
-
sql: string;
|
|
320
|
-
params?: any[];
|
|
321
|
-
startTime: number;
|
|
322
|
-
firstRowTime?: number;
|
|
323
|
-
endTime?: number;
|
|
324
|
-
error?: any;
|
|
325
|
-
affectedRows: number;
|
|
326
|
-
};
|
|
327
|
-
};
|
|
328
|
-
readonly status: string;
|
|
329
|
-
}[];
|
|
330
|
-
};
|
|
331
|
-
};
|
|
332
|
-
export {};
|
package/dist/esm/src/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './client';
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Worker orchestrator for SQLite worker pool synchronization.
|
|
3
|
-
*
|
|
4
|
-
* Responsibilities:
|
|
5
|
-
* - Establish an initialization lock to serialize worker database initialization
|
|
6
|
-
* - Track worker status transitions throughout their lifecycle
|
|
7
|
-
*/
|
|
8
|
-
export declare const WorkerStatuses: {
|
|
9
|
-
readonly EMPTY: -3;
|
|
10
|
-
readonly NEW: -2;
|
|
11
|
-
readonly INITIALIZING: -1;
|
|
12
|
-
readonly INITIALIZED: 0;
|
|
13
|
-
readonly READY: 10;
|
|
14
|
-
readonly RESERVED: 49;
|
|
15
|
-
readonly RUNNING: 50;
|
|
16
|
-
readonly ABORTING: 99;
|
|
17
|
-
readonly DONE: 100;
|
|
18
|
-
};
|
|
19
|
-
export type WorkerStatus = (typeof WorkerStatuses)[keyof typeof WorkerStatuses];
|
|
20
|
-
/**
|
|
21
|
-
* Worker pool orchestrator using SharedArrayBuffer for cross-thread synchronization.
|
|
22
|
-
*
|
|
23
|
-
* Key features:
|
|
24
|
-
* - Serializes worker initialization via an atomic lock to prevent database conflicts
|
|
25
|
-
* - Tracks individual worker status using atomic operations for thread-safe state management
|
|
26
|
-
*
|
|
27
|
-
* @remarks
|
|
28
|
-
* **Worker lifecycle state machine (per slot):**
|
|
29
|
-
*
|
|
30
|
-
* ```
|
|
31
|
-
* EMPTY (-3) — slot allocated; Worker object not yet created by client.ts
|
|
32
|
-
* │
|
|
33
|
-
* NEW (-2) — Worker thread started; 'open' message not yet sent
|
|
34
|
-
* │
|
|
35
|
-
* INITIALIZING (-1) — 'open' message sent; worker calling orchestrator.lock()
|
|
36
|
-
* │ to serialize VFS + SQLite DB initialization across the pool
|
|
37
|
-
* INITIALIZED (0) — DB opened; orchestrator.unlock() called; about to post 'ready'
|
|
38
|
-
* │
|
|
39
|
-
* READY (10) — worker available for queries; pool is queryable from client.ts
|
|
40
|
-
* │
|
|
41
|
-
* RUNNING (50) — worker executing a query (set by worker.ts via Atomics)
|
|
42
|
-
* │
|
|
43
|
-
* ABORTING (99) — AbortSignal fired; worker.ts checks this flag in the step loop
|
|
44
|
-
* │ and exits early; transitions to DONE after the current step
|
|
45
|
-
* DONE (100) — query finished (normal or aborted); client calls releaseWorker()
|
|
46
|
-
* which sets status back to READY via setStatus()
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* Note: `RESERVED (49)` is defined but intentionally unused in v1.
|
|
50
|
-
* The `INITIALIZED (0)` state is transient — the worker moves to `READY` atomically
|
|
51
|
-
* inside the `finally` block of `open()` in `worker.ts`.
|
|
52
|
-
*/
|
|
53
|
-
export declare class WorkerOrchestrator {
|
|
54
|
-
readonly sharedArrayBuffer: SharedArrayBuffer;
|
|
55
|
-
private flags;
|
|
56
|
-
readonly size: number;
|
|
57
|
-
/**
|
|
58
|
-
* Creates a new orchestrator instance.
|
|
59
|
-
* @param init - Pool size (creates new SharedArrayBuffer) or existing SharedArrayBuffer
|
|
60
|
-
*/
|
|
61
|
-
constructor(init: number | SharedArrayBuffer);
|
|
62
|
-
/**
|
|
63
|
-
* Acquire initialization lock.
|
|
64
|
-
* Workers call this during startup to serialize database initialization.
|
|
65
|
-
* Uses busy-wait with Atomics.wait() for blocking.
|
|
66
|
-
*/
|
|
67
|
-
lock(): void;
|
|
68
|
-
/**
|
|
69
|
-
* Release initialization lock.
|
|
70
|
-
* Notifies one waiting worker that the lock is now available.
|
|
71
|
-
*/
|
|
72
|
-
unlock(): void;
|
|
73
|
-
/**
|
|
74
|
-
* Update worker status atomically.
|
|
75
|
-
* @param index - Worker index in the pool
|
|
76
|
-
* @param status - New status to set
|
|
77
|
-
* @param from - Optional: expected current status for conditional update (CAS)
|
|
78
|
-
* @returns true if status was successfully updated
|
|
79
|
-
*/
|
|
80
|
-
setStatus(index: number, status: WorkerStatus, from?: WorkerStatus): boolean;
|
|
81
|
-
/**
|
|
82
|
-
* Get current worker status.
|
|
83
|
-
* @param index - Worker index in the pool
|
|
84
|
-
* @returns Current worker status
|
|
85
|
-
*/
|
|
86
|
-
getStatus(index: number): WorkerStatus;
|
|
87
|
-
}
|
package/dist/esm/src/types.d.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
export type SQLiteClientCallData = {
|
|
2
|
-
type: 'open';
|
|
3
|
-
file: string;
|
|
4
|
-
workerIndex: number;
|
|
5
|
-
url?: string;
|
|
6
|
-
flag: SharedArrayBuffer;
|
|
7
|
-
} | {
|
|
8
|
-
type: 'sql';
|
|
9
|
-
sql: string;
|
|
10
|
-
params?: any[];
|
|
11
|
-
options?: {
|
|
12
|
-
debug?: boolean;
|
|
13
|
-
chunkSize?: number;
|
|
14
|
-
};
|
|
15
|
-
} | {
|
|
16
|
-
type: 'abort';
|
|
17
|
-
};
|
|
18
|
-
export type SQLiteCLientCallParams<K extends SQLiteClientCallData['type']> = Omit<Extract<SQLiteClientCallData, {
|
|
19
|
-
type: K;
|
|
20
|
-
}>, 'type'>;
|
|
21
|
-
export type SQLiteWorkerMessageData<_T = unknown> = {
|
|
22
|
-
callId: number;
|
|
23
|
-
terminate?: boolean;
|
|
24
|
-
} & (SQLWorkerResultData[keyof SQLWorkerResultData] | {
|
|
25
|
-
type: 'error';
|
|
26
|
-
message: string;
|
|
27
|
-
});
|
|
28
|
-
export type SQLWorkerResultData<T = unknown> = {
|
|
29
|
-
open: {
|
|
30
|
-
success: boolean;
|
|
31
|
-
};
|
|
32
|
-
sql: {
|
|
33
|
-
type: 'partial';
|
|
34
|
-
result: T[];
|
|
35
|
-
} | {
|
|
36
|
-
type: 'one';
|
|
37
|
-
sizes: number[];
|
|
38
|
-
};
|
|
39
|
-
abort: {
|
|
40
|
-
type: 'done';
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
export declare const SharedArrayTypes: {
|
|
44
|
-
INT: number;
|
|
45
|
-
STRING: number;
|
|
46
|
-
OBJECT: number;
|
|
47
|
-
};
|
|
48
|
-
type SQLOptions = {
|
|
49
|
-
chunkSize?: number;
|
|
50
|
-
};
|
|
51
|
-
export type ClientMessageData = {
|
|
52
|
-
type: 'open';
|
|
53
|
-
file: string;
|
|
54
|
-
flags: SharedArrayBuffer;
|
|
55
|
-
index: number;
|
|
56
|
-
vfs?: SQLiteVFS;
|
|
57
|
-
pragmas?: Record<string, string>;
|
|
58
|
-
} | {
|
|
59
|
-
type: 'query';
|
|
60
|
-
callId: number;
|
|
61
|
-
sql: string;
|
|
62
|
-
params: any[];
|
|
63
|
-
options?: SQLOptions;
|
|
64
|
-
};
|
|
65
|
-
export type WorkerMessageData = {
|
|
66
|
-
type: 'ready';
|
|
67
|
-
callId: number;
|
|
68
|
-
} | {
|
|
69
|
-
type: 'chunk';
|
|
70
|
-
callId: number;
|
|
71
|
-
data: any[];
|
|
72
|
-
} | {
|
|
73
|
-
type: 'done';
|
|
74
|
-
callId: number;
|
|
75
|
-
affected: number;
|
|
76
|
-
} | {
|
|
77
|
-
type: 'error';
|
|
78
|
-
callId: number;
|
|
79
|
-
message: string;
|
|
80
|
-
cause?: unknown;
|
|
81
|
-
};
|
|
82
|
-
export type SQLiteVFS = 'OPFSPermutedVFS' | 'OPFSAdaptiveVFS' | 'OPFSCoopSyncVFS' | 'AccessHandlePoolVFS' | 'IDBBatchAtomicVFS';
|
|
83
|
-
export {};
|
package/dist/esm/src/utils.d.ts
DELETED
|
File without changes
|