@livestore/wa-sqlite 1.0.1-dev.0 → 1.0.1-dev.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livestore/wa-sqlite",
3
- "version": "1.0.1-dev.0",
3
+ "version": "1.0.1-dev.10",
4
4
  "type": "module",
5
5
  "main": "src/sqlite-api.js",
6
6
  "types": "src/types/index.d.ts",
package/src/sqlite-api.js CHANGED
@@ -237,6 +237,31 @@ export function Factory(Module) {
237
237
  };
238
238
  })();
239
239
 
240
+ sqlite3.deserialize = (function() {
241
+ const fname = 'sqlite3_deserialize';
242
+ const f = Module.cwrap(fname, ...decl('nnnnnn:n'));
243
+ return function(db, schema, data, szDb, szBuf, flags) {
244
+ verifyDatabase(db);
245
+ const ptr = Module._sqlite3_malloc(szDb);
246
+ Module.HEAPU8.subarray(ptr).set(data);
247
+ const result = f(db, schema, ptr, szDb, szBuf, flags);
248
+ return result;
249
+ };
250
+ })();
251
+
252
+ sqlite3.serialize = (function() {
253
+ const fname = 'sqlite3_serialize';
254
+ const f = Module.cwrap(fname, ...decl('nsnn:n'));
255
+ return function(db, schema, piSize, flags) {
256
+ verifyDatabase(db);
257
+ // TODO alloc + free memory for result?
258
+ const address = f(db, schema, piSize, flags);
259
+ const result = Module.HEAPU8.subarray(address, address + piSize);
260
+
261
+ return result;
262
+ };
263
+ })();
264
+
240
265
  sqlite3.clear_bindings = (function() {
241
266
  const fname = 'sqlite3_clear_bindings';
242
267
  const f = Module.cwrap(fname, ...decl('n:n'));
@@ -1,6 +1,6 @@
1
- declare namespace Asyncify {
2
- function handleAsync(f: () => Promise<any>);
3
- }
1
+ // declare namespace Asyncify {
2
+ // function handleAsync(f: () => Promise<any>);
3
+ // }
4
4
 
5
5
  declare function UTF8ToString(ptr: number): string;
6
6
  declare function lengthBytesUTF8(s: string): number;
@@ -33,7 +33,7 @@ type SQLiteCompatibleType = number|string|Uint8Array|Array<number>|bigint|null;
33
33
  * @see https://sqlite.org/vfs.html
34
34
  * @see https://sqlite.org/c3ref/io_methods.html
35
35
  */
36
- declare interface SQLiteVFS {
36
+ interface SQLiteVFS {
37
37
  /** Maximum length of a file path in UTF-8 bytes (default 64) */
38
38
  mxPathName?: number;
39
39
 
@@ -151,14 +151,14 @@ declare interface SQLitePrepareOptions {
151
151
  *
152
152
  * ```javascript
153
153
  * // Import an ES6 module factory function from one of the
154
- * // package builds, either 'wa-sqlite.mjs' (synchronous) or
155
- * // 'wa-sqlite-async.mjs' (asynchronous). You should only
154
+ * // package builds, either '@livestore/wa-sqlite.mjs' (synchronous) or
155
+ * // '@livestore/wa-sqlite-async.mjs' (asynchronous). You should only
156
156
  * // use the asynchronous build if you plan to use an
157
157
  * // asynchronous VFS or module.
158
- * import SQLiteESMFactory from 'wa-sqlite/dist/wa-sqlite.mjs';
158
+ * import SQLiteESMFactory from '@livestore/wa-sqlite/dist/wa-sqlite.mjs';
159
159
  *
160
160
  * // Import the Javascript API wrappers.
161
- * import * as SQLite from 'wa-sqlite';
161
+ * import * as SQLite from '@livestore/wa-sqlite';
162
162
  *
163
163
  * // Use an async function to simplify Promise handling.
164
164
  * (async function() {
@@ -178,7 +178,7 @@ declare interface SQLitePrepareOptions {
178
178
  *
179
179
  * @see https://sqlite.org/c3ref/funclist.html
180
180
  */
181
- declare interface SQLiteAPI {
181
+ interface SQLiteAPI {
182
182
  /**
183
183
  * Bind a collection of values to a statement
184
184
  *
@@ -330,6 +330,41 @@ declare interface SQLiteAPI {
330
330
  */
331
331
  changes(db): number;
332
332
 
333
+ /**
334
+ * https://www.sqlite.org/c3ref/deserialize.html
335
+ * int sqlite3_deserialize(
336
+ * sqlite3 *db, The database connection
337
+ * const char *zSchema, Which DB to reopen with the deserialization
338
+ * unsigned char *pData, The serialized database content
339
+ * sqlite3_int64 szDb, Number bytes in the deserialization
340
+ * sqlite3_int64 szBuf, Total size of buffer pData[]
341
+ * unsigned mFlags Zero or more SQLITE_DESERIALIZE_* flags
342
+ * );
343
+ */
344
+ deserialize(
345
+ db: number,
346
+ zSchema: string,
347
+ pData: Uint8Array,
348
+ szDb: number,
349
+ szBuf: number,
350
+ mFlags: number
351
+ ): number;
352
+
353
+ /**
354
+ * unsigned char *sqlite3_serialize(
355
+ * sqlite3 *db, The database connection
356
+ * const char *zSchema, Which DB to serialize. ex: "main", "temp", ...
357
+ * sqlite3_int64 *piSize, Write size of the DB here, if not NULL
358
+ * unsigned int mFlags Zero or more SQLITE_SERIALIZE_* flags
359
+ * );
360
+ */
361
+ serialize(
362
+ db: number,
363
+ zSchema: string,
364
+ piSize: number,
365
+ mFlags: number
366
+ ): Uint8Array;
367
+
333
368
  /**
334
369
  * Reset all bindings on a prepared statement.
335
370
  * @see https://www.sqlite.org/c3ref/clear_bindings.html
@@ -576,7 +611,7 @@ declare interface SQLiteAPI {
576
611
  zFilename: string,
577
612
  iFlags?: number,
578
613
  zVfs?: string
579
- ): Promise<number>;
614
+ ): number;
580
615
 
581
616
  /**
582
617
  * Specify callback to be invoked between long-running queries
@@ -596,9 +631,9 @@ declare interface SQLiteAPI {
596
631
  * Reset a prepared statement object
597
632
  * @see https://www.sqlite.org/c3ref/reset.html
598
633
  * @param stmt prepared statement pointer
599
- * @returns Promise-wrapped `SQLITE_OK` (rejects on error)
634
+ * @returns `SQLITE_OK` (rejects on error)
600
635
  */
601
- reset(stmt: number): Promise<number>;
636
+ reset(stmt: number): number;
602
637
 
603
638
  /**
604
639
  * Convenience function to call `result_*` based of the type of `value`
@@ -725,7 +760,7 @@ declare interface SQLiteAPI {
725
760
  * @param options
726
761
  */
727
762
  // statements(db: number, sql: string, options?: SQLitePrepareOptions): AsyncIterable<number>;
728
- statements(db: number, sql: string, options?: SQLitePrepareOptions): Iterable<number>;
763
+ statements(db: number, sql: string, options?: SQLitePrepareOptions): ReadonlyArray<number>;
729
764
 
730
765
  /**
731
766
  * Evaluate an SQL statement
@@ -822,8 +857,13 @@ declare interface SQLiteAPI {
822
857
  vfs_register(vfs: SQLiteVFS, makeDefault?: boolean): number;
823
858
  }
824
859
 
860
+ declare module '@livestore/wa-sqlite' {
861
+ export type SQLiteAPI_ = SQLiteAPI;
862
+ export type SQLiteVFS_ = SQLiteVFS;
863
+ }
864
+
825
865
  /** @ignore */
826
- declare module 'wa-sqlite/src/sqlite-constants.js' {
866
+ declare module '@livestore/wa-sqlite/src/sqlite-constants.js' {
827
867
  export const SQLITE_OK: 0;
828
868
  export const SQLITE_ERROR: 1;
829
869
  export const SQLITE_INTERNAL: 2;
@@ -1058,8 +1098,8 @@ declare module 'wa-sqlite/src/sqlite-constants.js' {
1058
1098
  export const SQLITE_PREPARE_NO_VTAB: 0x04;
1059
1099
  }
1060
1100
 
1061
- declare module 'wa-sqlite' {
1062
- export * from 'wa-sqlite/src/sqlite-constants.js';
1101
+ declare module '@livestore/wa-sqlite' {
1102
+ export * from '@livestore/wa-sqlite/src/sqlite-constants.js';
1063
1103
 
1064
1104
  /**
1065
1105
  * @ignore
@@ -1078,22 +1118,23 @@ declare module 'wa-sqlite' {
1078
1118
  }
1079
1119
 
1080
1120
  /** @ignore */
1081
- declare module 'wa-sqlite/dist/wa-sqlite.mjs' {
1121
+ declare module '@livestore/wa-sqlite/dist/wa-sqlite.mjs' {
1082
1122
  function ModuleFactory(config?: object): Promise<any>;
1083
1123
  export = ModuleFactory;
1084
1124
  }
1085
1125
 
1086
1126
  /** @ignore */
1087
- declare module 'wa-sqlite/dist/wa-sqlite-async.mjs' {
1127
+ declare module '@livestore/wa-sqlite/dist/wa-sqlite-async.mjs' {
1088
1128
  function ModuleFactory(config?: object): Promise<any>;
1089
1129
  export = ModuleFactory;
1090
1130
  }
1091
1131
 
1092
1132
  /** @ignore */
1093
- declare module 'wa-sqlite/src/VFS.js' {
1094
- export * from 'wa-sqlite/src/sqlite-constants.js';
1133
+ declare module '@livestore/wa-sqlite/src/VFS.js' {
1134
+ export * from '@livestore/wa-sqlite/src/sqlite-constants.js';
1095
1135
 
1096
1136
  export class Base {
1137
+ name: string;
1097
1138
  mxPathName: number;
1098
1139
  /**
1099
1140
  * @param {number} fileId
@@ -1205,9 +1246,16 @@ declare module 'wa-sqlite/src/VFS.js' {
1205
1246
  }
1206
1247
  }
1207
1248
 
1249
+ declare module '@livestore/wa-sqlite/src/examples/AccessHandlePoolVFS.js' {
1250
+ import * as VFS from "@livestore/wa-sqlite/src/VFS.js";
1251
+ export class AccessHandlePoolVFS extends VFS.Base {
1252
+ constructor(name: string, module: any)
1253
+ }
1254
+ }
1255
+
1208
1256
  /** @ignore */
1209
- declare module 'wa-sqlite/src/examples/IndexedDbVFS.js' {
1210
- import * as VFS from "wa-sqlite/src/VFS.js";
1257
+ declare module '@livestore/wa-sqlite/src/examples/IndexedDbVFS.js' {
1258
+ import * as VFS from "@livestore/wa-sqlite/src/VFS.js";
1211
1259
  export class IndexedDbVFS extends VFS.Base {
1212
1260
  /**
1213
1261
  * @param {string} idbName Name of IndexedDB database.
@@ -1260,8 +1308,8 @@ declare module 'wa-sqlite/src/examples/IndexedDbVFS.js' {
1260
1308
  }
1261
1309
 
1262
1310
  /** @ignore */
1263
- declare module 'wa-sqlite/src/examples/MemoryVFS.js' {
1264
- import * as VFS from "wa-sqlite/src/VFS.js";
1311
+ declare module '@livestore/wa-sqlite/src/examples/MemoryVFS.js' {
1312
+ import * as VFS from "@livestore/wa-sqlite/src/VFS.js";
1265
1313
  /** @ignore */
1266
1314
  export class MemoryVFS extends VFS.Base {
1267
1315
  name: string;
@@ -1271,14 +1319,14 @@ declare module 'wa-sqlite/src/examples/MemoryVFS.js' {
1271
1319
  }
1272
1320
 
1273
1321
  /** @ignore */
1274
- declare module 'wa-sqlite/src/examples/MemoryAsyncVFS.js' {
1275
- import { MemoryVFS } from "wa-sqlite/src/examples/MemoryVFS.js";
1322
+ declare module '@livestore/wa-sqlite/src/examples/MemoryAsyncVFS.js' {
1323
+ import { MemoryVFS } from "@livestore/wa-sqlite/src/examples/MemoryVFS.js";
1276
1324
  export class MemoryAsyncVFS extends MemoryVFS {
1277
1325
  }
1278
1326
  }
1279
1327
 
1280
1328
  /** @ignore */
1281
- declare module 'wa-sqlite/src/examples/tag.js' {
1329
+ declare module '@livestore/wa-sqlite/src/examples/tag.js' {
1282
1330
  /**
1283
1331
  * @ignore
1284
1332
  * Template tag builder. This function creates a tag with an API and