@@ -1255,6 +1255,131 @@ declare class OpfsDatabase extends Database {
12551255 ) : Promise < number > ;
12561256}
12571257
1258+ declare class OpfsSAHPoolDatabase extends OpfsDatabase {
1259+ constructor ( filename : string ) ;
1260+ }
1261+
1262+ type SAHPoolUtil = {
1263+ OpfsSAHPoolDb : typeof OpfsSAHPoolDatabase ;
1264+
1265+ /**
1266+ * Adds `numEntries` entries to the current pool.
1267+ *
1268+ * This change is persistent across sessions so should not be called
1269+ * automatically at each app startup (but see `reserveMinimumCapacity()`). Its
1270+ * returned Promise resolves to the new capacity. Because this operation is
1271+ * necessarily asynchronous, the C-level VFS API cannot call this on its own
1272+ * as needed.
1273+ */
1274+ addCapacity : ( numEntries : number ) => Promise < number > ;
1275+
1276+ /**
1277+ * Synchronously reads the contents of the given file into a `Uint8Array` and
1278+ * returns it.
1279+ *
1280+ * This will throw if the given name is not currently in active use or on I/O
1281+ * error. Note that the given name is not visible directly in OPFS (or, if it
1282+ * is, it's not from this VFS). The reason for that is that this VFS manages
1283+ * name-to-file mappings in a roundabout way in order to maintain its list of
1284+ * SAHs.
1285+ */
1286+ exportFile : ( filename : string ) => Promise < Uint8Array > ;
1287+
1288+ /**
1289+ * Returns the number of files currently contained in the SAH pool.
1290+ *
1291+ * The default capacity is only large enough for one or two databases and
1292+ * their associated temp files.
1293+ */
1294+ getCapacity : ( ) => number ;
1295+
1296+ /**
1297+ * Returns the number of files from the pool currently allocated to VFS slots.
1298+ *
1299+ * This is not the same as the files being "opened".
1300+ */
1301+ getFileCount : ( ) => number ;
1302+
1303+ /**
1304+ * Returns an array of the names of the files currently allocated to VFS
1305+ * slots.
1306+ *
1307+ * This list is the same length as `getFileCount()`.
1308+ */
1309+ getFilenames : ( ) => string [ ] ;
1310+
1311+ /**
1312+ * Imports the contents of an SQLite database, provided as a byte array or
1313+ * ArrayBuffer, under the given name, overwriting any existing content.
1314+ *
1315+ * Throws if the pool has no available file slots, on I/O error, or if the
1316+ * input does not appear to be a database. In the latter case, only a cursory
1317+ * examination is made.
1318+ *
1319+ * Note that this routine is only for importing database files, not arbitrary
1320+ * files, the reason being that this VFS will automatically clean up any
1321+ * non-database files so importing them is pointless.
1322+ *
1323+ * On a write error, the handle is removed from the pool and made available
1324+ * for re-use.
1325+ *
1326+ * On success, the number of bytes written is returned.
1327+ */
1328+ importDb : ( name : string , data : Uint8Array | ArrayBuffer ) => Promise < number > ;
1329+
1330+ /**
1331+ * Removes up to `numEntries` entries from the pool, with the caveat that it
1332+ * can only remove currently-unused entries.
1333+ *
1334+ * It returns a Promise which resolves to the number of entries actually
1335+ * removed.
1336+ */
1337+ reduceCapacity : ( numEntries : number ) => Promise < number > ;
1338+
1339+ /**
1340+ * Unregisters the VFS and removes its directory from OPFS (which means all
1341+ * client content is destroyed). After calling this, the VFS may no longer be
1342+ * used and there is currently no way to re-add it aside from reloading the
1343+ * current JavaScript context.
1344+ *
1345+ * Results are undefined if a database is currently in use with this VFS.
1346+ *
1347+ * The returned Promise resolves to true if it performed the removal and false
1348+ * if the VFS was not installed.
1349+ *
1350+ * If the VFS has a multi-level directory, e.g. "/foo/bar/baz", only the
1351+ * bottom-most directory is removed because this VFS cannot know for certain
1352+ * whether the higher-level directories contain data which should be removed.
1353+ */
1354+ removeVfs : ( ) => Promise < boolean > ;
1355+
1356+ /**
1357+ * If the current capacity is less than `minCapacity`, the capacity is
1358+ * increased to `minCapacity`, else this returns with no side effects.
1359+ *
1360+ * The resulting Promise resolves to the new capacity.
1361+ */
1362+ reserveMinimumCapacity : ( minCapacity : number ) => Promise < number > ;
1363+
1364+ /**
1365+ * If a virtual file exists with the given name, disassociates it from the
1366+ * pool and returns true, else returns false without side effects. Results are
1367+ * undefined if the file is currently in active use. Recall that names need to
1368+ * use absolute paths (starting with a slash).
1369+ */
1370+ unlink : ( filename : string ) => boolean ;
1371+
1372+ /** The SQLite VFS name under which this pool's VFS is registered. */
1373+ vfsName : string ;
1374+
1375+ /**
1376+ * Clears all client-defined state of all SAHs and makes all of them available
1377+ * for re-use by the pool. Results are undefined if any such handles are
1378+ * currently in use, e.g. by an sqlite3 db.
1379+ */
1380+ wipeFiles : ( ) => Promise < void > ;
1381+ } ;
1382+
12581383/** Exception class for reporting WASM-side allocation errors. */
12591384declare class WasmAllocError extends Error {
12601385 constructor ( message : string ) ;
@@ -1752,6 +1877,65 @@ declare type Sqlite3Static = {
17521877 */
17531878 initWorker1API ( ) : void ;
17541879
1880+ installOpfsSAHPoolVfs ( opts : {
1881+ /**
1882+ * If truthy (default=false) contents and filename mapping are removed from
1883+ * each SAH it is acquired during initalization of the VFS, leaving the
1884+ * VFS's storage in a pristine state. Use this only for databases which need
1885+ * not survive a page reload.
1886+ */
1887+ clearOnInit ?: boolean ;
1888+
1889+ /**
1890+ * (default=6) Specifies the default capacity of the VFS.
1891+ *
1892+ * This should not be set unduly high because the VFS has to open (and keep
1893+ * open) a file for each entry in the pool. This setting only has an effect
1894+ * when the pool is initially empty. It does not have any effect if a pool
1895+ * already exists. Note that this number needs to be at least twice the
1896+ * number of expected database files (to account for journal files) and may
1897+ * need to be even higher than three times the number of databases plus one,
1898+ * depending on the value of the `TEMP_STORE` pragma and how the databases
1899+ * are used.
1900+ */
1901+ initialCapacity ?: number ;
1902+
1903+ /**
1904+ * (default="."+options.name) Specifies the OPFS directory name in which to
1905+ * store metadata for the VFS.
1906+ *
1907+ * Only one instance of this VFS can use the same directory concurrently.
1908+ * Using a different directory name for each application enables different
1909+ * engines in the same HTTP origin to co-exist, but their data are invisible
1910+ * to each other. Changing this name will effectively orphan any databases
1911+ * stored under previous names. This option may contain multiple path
1912+ * elements, e.g. "/foo/bar/baz", and they are created automatically. In
1913+ * practice there should be no driving need to change this.
1914+ *
1915+ * **ACHTUNG:** all files in this directory are assumed to be managed by the
1916+ * VFS. Do not place other files in this directory, as they may be deleted
1917+ * or otherwise modified by the VFS.
1918+ */
1919+ directory ?: string ;
1920+
1921+ /**
1922+ * (default="opfs-sahpool") sets the name to register this VFS under.
1923+ *
1924+ * Normally this should not be changed, but it is possible to register this
1925+ * VFS under multiple names so long as each has its own separate directory
1926+ * to work from. The storage for each is invisible to all others. The name
1927+ * must be a string compatible with `sqlite3_vfs_register()` and friends and
1928+ * suitable for use in URI-style database file names.
1929+ *
1930+ * **ACHTUNG:** if a custom name is provided, a custom directory must also
1931+ * be provided if any other instance is registered with the default
1932+ * directory. No two instances may use the same directory. If no directory
1933+ * is explicitly provided then a directory name is synthesized from the name
1934+ * option.
1935+ */
1936+ name ?: string ;
1937+ } ) : Promise < SAHPoolUtil > ;
1938+
17551939 WasmAllocError : WasmAllocError ;
17561940
17571941 SQLite3Error : SQLite3Error ;
@@ -7368,6 +7552,44 @@ declare type CAPI = {
73687552 dataLen ?: number ,
73697553 ) => void ;
73707554
7555+ /**
7556+ * Clears all kvvfs-owned state and returns the number of records it deleted
7557+ * (one record per database page).
7558+ */
7559+ sqlite3_js_kvvfs_clear : ( which ?: string ) => void ;
7560+
7561+ /** Returns an estimate of how many bytes of storage are used by kvvfs. */
7562+ sqlite3_js_kvvfs_size : ( which ?: string ) => number ;
7563+
7564+ /**
7565+ * If the current environment supports the POSIX file APIs, this routine
7566+ * creates (or overwrites) the given file using those APIs. This is primarily
7567+ * intended for use in Emscripten-based builds where the POSIX APIs are
7568+ * transparently proxied by an in-memory virtual filesystem. It may behave
7569+ * differently in other environments.
7570+ *
7571+ * The first argument must be either a JS string or WASM C-string holding the
7572+ * filename. Note that this routine does not create intermediary directories
7573+ * if the filename has a directory part.
7574+ *
7575+ * The 2nd argument may either a valid WASM memory pointer, an ArrayBuffer, or
7576+ * a Uint8Array. The 3rd must be the length, in bytes, of the data array to
7577+ * copy. If the 2nd argument is an ArrayBuffer or Uint8Array and the 3rd is
7578+ * not a positive integer then the 3rd defaults to the array's byteLength
7579+ * value.
7580+ *
7581+ * Results are undefined if data is a WASM pointer and dataLen is exceeds
7582+ * data's bounds.
7583+ *
7584+ * Throws if any arguments are invalid or if creating or writing to the file
7585+ * fails.
7586+ */
7587+ sqlite3_js_posix_create_file : (
7588+ filename : string | WasmPointer ,
7589+ data : Uint8Array | ArrayBuffer | WasmPointer ,
7590+ dataLen ?: number ,
7591+ ) => void ;
7592+
73717593 /**
73727594 * Given a `sqlite3_value*`, this function attempts to convert it to an
73737595 * equivalent JS value with as much fidelity as feasible and return it.
@@ -7444,10 +7666,11 @@ declare type CAPI = {
74447666 SQLITE_RECURSIVE : 33 ;
74457667 SQLITE_STATIC : 0 ;
74467668 SQLITE_TRANSIENT : - 1 ;
7447- SQLITE_WASM_DEALLOC : WasmPointer ;
7669+ SQLITE_WASM_DEALLOC : 1 ;
74487670 SQLITE_CHANGESETSTART_INVERT : 2 ;
74497671 SQLITE_CHANGESETAPPLY_NOSAVEPOINT : 1 ;
74507672 SQLITE_CHANGESETAPPLY_INVERT : 2 ;
7673+ SQLITE_CHANGESETAPPLY_IGNORENOOP : 4 ;
74517674 SQLITE_CHANGESET_DATA : 1 ;
74527675 SQLITE_CHANGESET_NOTFOUND : 2 ;
74537676 SQLITE_CHANGESET_CONFLICT : 3 ;
@@ -7507,6 +7730,8 @@ declare type CAPI = {
75077730 SQLITE_DBCONFIG_ENABLE_VIEW : 1015 ;
75087731 SQLITE_DBCONFIG_LEGACY_FILE_FORMAT : 1016 ;
75097732 SQLITE_DBCONFIG_TRUSTED_SCHEMA : 1017 ;
7733+ SQLITE_DBCONFIG_STMT_SCANSTATUS : 1018 ;
7734+ SQLITE_DBCONFIG_REVERSE_SCANORDER : 1019 ;
75107735 SQLITE_DBCONFIG_MAX : 1019 ;
75117736 SQLITE_DBSTATUS_LOOKASIDE_USED : 0 ;
75127737 SQLITE_DBSTATUS_CACHE_USED : 1 ;
@@ -7567,6 +7792,7 @@ declare type CAPI = {
75677792 SQLITE_FCNTL_CKPT_START : 39 ;
75687793 SQLITE_FCNTL_EXTERNAL_READER : 40 ;
75697794 SQLITE_FCNTL_CKSM_FILE : 41 ;
7795+ SQLITE_FCNTL_RESET_CACHE : 42 ;
75707796 SQLITE_LOCK_NONE : 0 ;
75717797 SQLITE_LOCK_SHARED : 1 ;
75727798 SQLITE_LOCK_RESERVED : 2 ;
@@ -7799,6 +8025,7 @@ declare type CAPI = {
77998025 SQLITE_VTAB_CONSTRAINT_SUPPORT : 1 ;
78008026 SQLITE_VTAB_INNOCUOUS : 2 ;
78018027 SQLITE_VTAB_DIRECTONLY : 3 ;
8028+ SQLITE_VTAB_USES_ALL_SCHEMAS : 4 ;
78028029 SQLITE_ROLLBACK : 1 ;
78038030 SQLITE_FAIL : 3 ;
78048031 SQLITE_REPLACE : 5 ;
0 commit comments