@powersync/web 1.38.6 → 1.39.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.
- package/dist/index.umd.js +259 -51
- package/dist/index.umd.js.map +1 -1
- package/dist/worker/SharedSyncImplementation.umd.js +11 -3
- package/dist/worker/SharedSyncImplementation.umd.js.map +1 -1
- package/dist/worker/WASQLiteDB.umd.js +78 -54
- package/dist/worker/WASQLiteDB.umd.js.map +1 -1
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-833585.umd.js +1400 -0
- package/dist/worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-833585.umd.js.map +1 -0
- package/lib/package.json +2 -2
- package/lib/src/db/adapters/wa-sqlite/RawSqliteConnection.d.ts +0 -1
- package/lib/src/db/adapters/wa-sqlite/RawSqliteConnection.js +4 -9
- package/lib/src/db/adapters/wa-sqlite/RawSqliteConnection.js.map +1 -1
- package/lib/src/db/adapters/wa-sqlite/vfs.d.ts +20 -30
- package/lib/src/db/adapters/wa-sqlite/vfs.js +57 -39
- package/lib/src/db/adapters/wa-sqlite/vfs.js.map +1 -1
- package/lib/src/worker/db/MultiDatabaseServer.js +5 -3
- package/lib/src/worker/db/MultiDatabaseServer.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/db/adapters/wa-sqlite/RawSqliteConnection.ts +5 -11
- package/src/db/adapters/wa-sqlite/vfs.ts +67 -54
- package/src/worker/db/MultiDatabaseServer.ts +5 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker/node_modules_pnpm_journeyapps_wa-sqlite_1_7_0_node_modules_journeyapps_wa-sqlite_src_examples-833585.umd.js","mappings":";;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AC/sBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;;;;;AC7NA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sources":["webpack://sdk_web/../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/FacadeVFS.js","webpack://sdk_web/../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/VFS.js","webpack://sdk_web/../../node_modules/.pnpm/@journeyapps+wa-sqlite@1.7.0/node_modules/@journeyapps/wa-sqlite/src/examples/MemoryVFS.js"],"sourcesContent":["// Copyright 2024 Roy T. Hashimoto. All Rights Reserved.\nimport * as VFS from './VFS.js';\n\nconst AsyncFunction = Object.getPrototypeOf(async function(){}).constructor;\n\n// Milliseconds since Julian epoch as a BigInt.\n// https://github.com/sqlite/sqlite/blob/e57527c14f7b7cfa6e32eeab5c549d50c4fa3674/src/os_unix.c#L6872-L6882\nconst UNIX_EPOCH = 24405875n * 8640000n;\n\n// Convenience base class for a JavaScript VFS.\n// The raw xOpen, xRead, etc. function signatures receive only C primitives\n// which aren't easy to work with. This class provides corresponding calls\n// like jOpen, jRead, etc., which receive JavaScript-friendlier arguments\n// such as string, Uint8Array, and DataView.\nexport class FacadeVFS extends VFS.Base {\n /**\n * @param {string} name \n * @param {object} module \n */\n constructor(name, module) {\n super(name, module);\n }\n\n /**\n * Override to indicate which methods are asynchronous.\n * @param {string} methodName \n * @returns {boolean}\n */\n hasAsyncMethod(methodName) {\n // The input argument is a string like \"xOpen\", so convert to \"jOpen\".\n // Then check if the method exists and is async.\n const jMethodName = `j${methodName.slice(1)}`;\n return this[jMethodName] instanceof AsyncFunction;\n }\n \n /**\n * Return the filename for a file id for use by mixins.\n * @param {number} pFile \n * @returns {string}\n */\n getFilename(pFile) {\n throw new Error('unimplemented');\n }\n\n /**\n * @param {string?} filename \n * @param {number} pFile \n * @param {number} flags \n * @param {DataView} pOutFlags \n * @returns {number|Promise<number>}\n */\n jOpen(filename, pFile, flags, pOutFlags) {\n return VFS.SQLITE_CANTOPEN;\n }\n\n /**\n * @param {string} filename \n * @param {number} syncDir \n * @returns {number|Promise<number>}\n */\n jDelete(filename, syncDir) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {string} filename \n * @param {number} flags \n * @param {DataView} pResOut \n * @returns {number|Promise<number>}\n */\n jAccess(filename, flags, pResOut) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {string} filename \n * @param {Uint8Array} zOut \n * @returns {number|Promise<number>}\n */\n jFullPathname(filename, zOut) {\n // Copy the filename to the output buffer.\n const { read, written } = new TextEncoder().encodeInto(filename, zOut);\n if (read < filename.length) return VFS.SQLITE_IOERR;\n if (written >= zOut.length) return VFS.SQLITE_IOERR;\n zOut[written] = 0;\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {Uint8Array} zBuf \n * @returns {number|Promise<number>}\n */\n jGetLastError(zBuf) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @returns {number|Promise<number>}\n */\n jClose(pFile) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {Uint8Array} pData \n * @param {number} iOffset \n * @returns {number|Promise<number>}\n */\n jRead(pFile, pData, iOffset) {\n pData.fill(0);\n return VFS.SQLITE_IOERR_SHORT_READ;\n }\n\n /**\n * @param {number} pFile \n * @param {Uint8Array} pData \n * @param {number} iOffset \n * @returns {number|Promise<number>}\n */\n jWrite(pFile, pData, iOffset) {\n return VFS.SQLITE_IOERR_WRITE;\n }\n\n /**\n * @param {number} pFile \n * @param {number} size \n * @returns {number|Promise<number>}\n */\n jTruncate(pFile, size) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {number} flags \n * @returns {number|Promise<number>}\n */\n jSync(pFile, flags) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {DataView} pSize\n * @returns {number|Promise<number>}\n */\n jFileSize(pFile, pSize) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {number} lockType \n * @returns {number|Promise<number>}\n */\n jLock(pFile, lockType) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {number} lockType \n * @returns {number|Promise<number>}\n */\n jUnlock(pFile, lockType) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {DataView} pResOut \n * @returns {number|Promise<number>}\n */\n jCheckReservedLock(pFile, pResOut) {\n pResOut.setInt32(0, 0, true);\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile\n * @param {number} op\n * @param {DataView} pArg\n * @returns {number|Promise<number>}\n */\n jFileControl(pFile, op, pArg) {\n return VFS.SQLITE_NOTFOUND;\n }\n\n /**\n * @param {number} pFile\n * @returns {number|Promise<number>}\n */\n jSectorSize(pFile) {\n return super.xSectorSize(pFile);\n }\n\n /**\n * @param {number} pFile\n * @returns {number|Promise<number>}\n */\n jDeviceCharacteristics(pFile) {\n return 0;\n }\n\n /**\n * @param {number} pVfs \n * @param {number} zName \n * @param {number} pFile \n * @param {number} flags \n * @param {number} pOutFlags \n * @returns {number|Promise<number>}\n */\n xOpen(pVfs, zName, pFile, flags, pOutFlags) {\n const filename = this.#decodeFilename(zName, flags);\n const pOutFlagsView = this.#makeTypedDataView('Int32', pOutFlags);\n this['log']?.('jOpen', filename, pFile, '0x' + flags.toString(16));\n return this.jOpen(filename, pFile, flags, pOutFlagsView);\n }\n\n /**\n * @param {number} pVfs \n * @param {number} nByte \n * @param {number} pCharOut\n * @returns {number|Promise<number>}\n */\n xRandomness(pVfs, nByte, pCharOut) {\n const randomArray = new Uint8Array(nByte);\n crypto.getRandomValues(randomArray);\n // Copy randomArray to the WebAssembly memory\n const buffer = pCharOut; // Pointer to memory in WebAssembly\n this._module.HEAPU8.set(randomArray, buffer); // Copy randomArray into memory starting at buffer\n return nByte;\n }\n\n /**\n * Gets the current time as milliseconds since Unix epoch\n * @param {number} pVfs pointer to the VFS\n * @param {number} pTime pointer to write the time value\n * @returns {number} SQLite error code\n */\n xCurrentTimeInt64(pVfs, pTime) {\n // Create a DataView to write the current time\n const timeView = this.#makeTypedDataView('BigInt64', pTime);\n \n const currentTime = BigInt(Date.now());\n // Convert the current time to milliseconds since Unix epoch\n const value = UNIX_EPOCH + currentTime;\n \n // Write the time value to the pointer location\n timeView.setBigInt64(0, value, true);\n \n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pVfs \n * @param {number} zName \n * @param {number} syncDir \n * @returns {number|Promise<number>}\n */\n xDelete(pVfs, zName, syncDir) {\n const filename = this._module.UTF8ToString(zName);\n this['log']?.('jDelete', filename, syncDir);\n return this.jDelete(filename, syncDir);\n }\n\n /**\n * @param {number} pVfs \n * @param {number} zName \n * @param {number} flags \n * @param {number} pResOut \n * @returns {number|Promise<number>}\n */\n xAccess(pVfs, zName, flags, pResOut) {\n const filename = this._module.UTF8ToString(zName);\n const pResOutView = this.#makeTypedDataView('Int32', pResOut);\n this['log']?.('jAccess', filename, flags);\n return this.jAccess(filename, flags, pResOutView);\n }\n\n /**\n * @param {number} pVfs \n * @param {number} zName \n * @param {number} nOut \n * @param {number} zOut \n * @returns {number|Promise<number>}\n */\n xFullPathname(pVfs, zName, nOut, zOut) {\n const filename = this._module.UTF8ToString(zName);\n const zOutArray = this._module.HEAPU8.subarray(zOut, zOut + nOut);\n this['log']?.('jFullPathname', filename, nOut);\n return this.jFullPathname(filename, zOutArray);\n }\n\n /**\n * @param {number} pVfs \n * @param {number} nBuf \n * @param {number} zBuf \n * @returns {number|Promise<number>}\n */\n xGetLastError(pVfs, nBuf, zBuf) {\n const zBufArray = this._module.HEAPU8.subarray(zBuf, zBuf + nBuf);\n this['log']?.('jGetLastError', nBuf);\n return this.jGetLastError(zBufArray);\n }\n\n /**\n * @param {number} pFile \n * @returns {number|Promise<number>}\n */\n xClose(pFile) {\n this['log']?.('jClose', pFile);\n return this.jClose(pFile);\n }\n\n /**\n * @param {number} pFile \n * @param {number} pData \n * @param {number} iAmt \n * @param {number} iOffsetLo \n * @param {number} iOffsetHi \n * @returns {number|Promise<number>}\n */\n xRead(pFile, pData, iAmt, iOffsetLo, iOffsetHi) {\n const pDataArray = this.#makeDataArray(pData, iAmt);\n const iOffset = delegalize(iOffsetLo, iOffsetHi);\n this['log']?.('jRead', pFile, iAmt, iOffset);\n return this.jRead(pFile, pDataArray, iOffset);\n }\n\n /**\n * @param {number} pFile \n * @param {number} pData \n * @param {number} iAmt \n * @param {number} iOffsetLo \n * @param {number} iOffsetHi \n * @returns {number|Promise<number>}\n */\n xWrite(pFile, pData, iAmt, iOffsetLo, iOffsetHi) {\n const pDataArray = this.#makeDataArray(pData, iAmt);\n const iOffset = delegalize(iOffsetLo, iOffsetHi);\n this['log']?.('jWrite', pFile, pDataArray, iOffset);\n return this.jWrite(pFile, pDataArray, iOffset);\n }\n\n /**\n * @param {number} pFile \n * @param {number} sizeLo \n * @param {number} sizeHi \n * @returns {number|Promise<number>}\n */\n xTruncate(pFile, sizeLo, sizeHi) {\n const size = delegalize(sizeLo, sizeHi);\n this['log']?.('jTruncate', pFile, size);\n return this.jTruncate(pFile, size);\n }\n\n /**\n * @param {number} pFile \n * @param {number} flags \n * @returns {number|Promise<number>}\n */\n xSync(pFile, flags) {\n this['log']?.('jSync', pFile, flags);\n return this.jSync(pFile, flags);\n }\n\n /**\n * \n * @param {number} pFile \n * @param {number} pSize \n * @returns {number|Promise<number>}\n */\n xFileSize(pFile, pSize) {\n const pSizeView = this.#makeTypedDataView('BigInt64', pSize);\n this['log']?.('jFileSize', pFile);\n return this.jFileSize(pFile, pSizeView);\n }\n\n /**\n * @param {number} pFile \n * @param {number} lockType \n * @returns {number|Promise<number>}\n */\n xLock(pFile, lockType) {\n this['log']?.('jLock', pFile, lockType);\n return this.jLock(pFile, lockType);\n }\n\n /**\n * @param {number} pFile \n * @param {number} lockType \n * @returns {number|Promise<number>}\n */\n xUnlock(pFile, lockType) {\n this['log']?.('jUnlock', pFile, lockType);\n return this.jUnlock(pFile, lockType);\n } \n\n /**\n * @param {number} pFile \n * @param {number} pResOut \n * @returns {number|Promise<number>}\n */\n xCheckReservedLock(pFile, pResOut) {\n const pResOutView = this.#makeTypedDataView('Int32', pResOut);\n this['log']?.('jCheckReservedLock', pFile);\n return this.jCheckReservedLock(pFile, pResOutView);\n }\n\n /**\n * @param {number} pFile \n * @param {number} op \n * @param {number} pArg \n * @returns {number|Promise<number>}\n */\n xFileControl(pFile, op, pArg) {\n const pArgView = new DataView(\n this._module.HEAPU8.buffer,\n this._module.HEAPU8.byteOffset + pArg);\n this['log']?.('jFileControl', pFile, op, pArgView);\n return this.jFileControl(pFile, op, pArgView);\n }\n\n /**\n * @param {number} pFile \n * @returns {number|Promise<number>}\n */\n xSectorSize(pFile) {\n this['log']?.('jSectorSize', pFile);\n return this.jSectorSize(pFile);\n }\n\n /**\n * @param {number} pFile \n * @returns {number|Promise<number>}\n */\n xDeviceCharacteristics(pFile) {\n this['log']?.('jDeviceCharacteristics', pFile);\n return this.jDeviceCharacteristics(pFile);\n }\n\n /**\n * Wrapped DataView for pointer arguments.\n * Pointers to a single value are passed using a DataView-like class.\n * This wrapper class prevents use of incorrect type or endianness, and\n * reacquires the underlying buffer when the WebAssembly memory is resized.\n * @param {'Int32'|'BigInt64'} type \n * @param {number} byteOffset \n * @returns {DataView}\n */\n #makeTypedDataView(type, byteOffset) {\n // @ts-ignore\n return new DataViewProxy(this._module, byteOffset, type);\n }\n\n /**\n * Wrapped Uint8Array for buffer arguments.\n * Memory blocks are passed as a Uint8Array-like class. This wrapper\n * class reacquires the underlying buffer when the WebAssembly memory\n * is resized.\n * @param {number} byteOffset \n * @param {number} byteLength \n * @returns {Uint8Array}\n */\n #makeDataArray(byteOffset, byteLength) {\n // @ts-ignore\n return new Uint8ArrayProxy(this._module, byteOffset, byteLength);\n }\n\n #decodeFilename(zName, flags) {\n if (flags & VFS.SQLITE_OPEN_URI) {\n // The first null-terminated string is the URI path. Subsequent\n // strings are query parameter keys and values.\n // https://www.sqlite.org/c3ref/open.html#urifilenamesinsqlite3open\n let pName = zName;\n let state = 1;\n const charCodes = [];\n while (state) {\n const charCode = this._module.HEAPU8[pName++];\n if (charCode) {\n charCodes.push(charCode);\n } else {\n if (!this._module.HEAPU8[pName]) state = null;\n switch (state) {\n case 1: // path\n charCodes.push('?'.charCodeAt(0));\n state = 2;\n break;\n case 2: // key\n charCodes.push('='.charCodeAt(0));\n state = 3;\n break;\n case 3: // value\n charCodes.push('&'.charCodeAt(0));\n state = 2;\n break;\n }\n }\n }\n return new TextDecoder().decode(new Uint8Array(charCodes));\n }\n return zName ? this._module.UTF8ToString(zName) : null;\n }\n}\n\n// Emscripten \"legalizes\" 64-bit integer arguments by passing them as\n// two 32-bit signed integers.\nfunction delegalize(lo32, hi32) {\n return (hi32 * 0x100000000) + lo32 + (lo32 < 0 ? 2**32 : 0);\n}\n\n// This class provides a Uint8Array-like interface for a WebAssembly memory\n// buffer. It is used to access memory blocks passed as arguments to\n// xRead, xWrite, etc. The class reacquires the underlying buffer when the\n// WebAssembly memory is resized, which can happen when the memory is\n// detached and resized by the WebAssembly module.\n//\n// Note that although this class implements the same methods as Uint8Array,\n// it is not a real Uint8Array and passing it to functions that expect\n// a Uint8Array may not work. Use subarray() to get a real Uint8Array\n// if needed.\nclass Uint8ArrayProxy {\n #module;\n\n #_array = new Uint8Array()\n get #array() {\n if (this.#_array.buffer.byteLength === 0) {\n // WebAssembly memory resize detached the buffer so re-create the\n // array with the new buffer.\n this.#_array = this.#module.HEAPU8.subarray(\n this.byteOffset,\n this.byteOffset + this.byteLength);\n }\n return this.#_array;\n }\n\n /**\n * @param {*} module\n * @param {number} byteOffset \n * @param {number} byteLength \n */\n constructor(module, byteOffset, byteLength) {\n this.#module = module;\n this.byteOffset = byteOffset;\n this.length = this.byteLength = byteLength;\n }\n\n get buffer() {\n return this.#array.buffer;\n }\n\n at(index) {\n return this.#array.at(index);\n }\n copyWithin(target, start, end) {\n this.#array.copyWithin(target, start, end);\n }\n entries() {\n return this.#array.entries();\n }\n every(predicate) {\n return this.#array.every(predicate);\n }\n fill(value, start, end) {\n this.#array.fill(value, start, end);\n }\n filter(predicate) {\n return this.#array.filter(predicate);\n }\n find(predicate) {\n return this.#array.find(predicate);\n }\n findIndex(predicate) {\n return this.#array.findIndex(predicate);\n }\n findLast(predicate) {\n return this.#array.findLast(predicate);\n }\n findLastIndex(predicate) {\n return this.#array.findLastIndex(predicate);\n }\n forEach(callback) {\n this.#array.forEach(callback);\n }\n includes(value, start) {\n return this.#array.includes(value, start);\n }\n indexOf(value, start) {\n return this.#array.indexOf(value, start);\n }\n join(separator) {\n return this.#array.join(separator);\n }\n keys() {\n return this.#array.keys();\n }\n lastIndexOf(value, start) {\n return this.#array.lastIndexOf(value, start);\n }\n map(callback) {\n return this.#array.map(callback);\n }\n reduce(callback, initialValue) {\n return this.#array.reduce(callback, initialValue);\n }\n reduceRight(callback, initialValue) {\n return this.#array.reduceRight(callback, initialValue);\n }\n reverse() {\n this.#array.reverse();\n }\n set(array, offset) {\n this.#array.set(array, offset);\n }\n slice(start, end) {\n return this.#array.slice(start, end);\n }\n some(predicate) {\n return this.#array.some(predicate);\n }\n sort(compareFn) {\n this.#array.sort(compareFn);\n }\n subarray(begin, end) {\n return this.#array.subarray(begin, end);\n }\n toLocaleString(locales, options) {\n // @ts-ignore\n return this.#array.toLocaleString(locales, options);\n }\n toReversed() {\n return this.#array.toReversed();\n }\n toSorted(compareFn) {\n return this.#array.toSorted(compareFn);\n }\n toString() {\n return this.#array.toString();\n }\n values() {\n return this.#array.values();\n }\n with(index, value) {\n return this.#array.with(index, value);\n }\n [Symbol.iterator]() {\n return this.#array[Symbol.iterator]();\n }\n}\n\n// This class provides a DataView-like interface for a WebAssembly memory\n// buffer, restricted to either Int32 or BigInt64 types. It also reacquires\n// the underlying buffer when the WebAssembly memory is resized, which can\n// happen when the memory is detached and resized by the WebAssembly module.\nclass DataViewProxy {\n #module;\n #type;\n\n #_view = new DataView(new ArrayBuffer(0));\n get #view() {\n if (this.#_view.buffer.byteLength === 0) {\n // WebAssembly memory resize detached the buffer so re-create the\n // view with the new buffer.\n this.#_view = new DataView(\n this.#module.HEAPU8.buffer,\n this.#module.HEAPU8.byteOffset + this.byteOffset);\n }\n return this.#_view;\n }\n\n /**\n * @param {*} module\n * @param {number} byteOffset \n * @param {'Int32'|'BigInt64'} type\n */\n constructor(module, byteOffset, type) {\n this.#module = module;\n this.byteOffset = byteOffset;\n this.#type = type;\n }\n\n get buffer() {\n return this.#view.buffer;\n }\n get byteLength() {\n return this.#type === 'Int32' ? 4 : 8;\n }\n\n getInt32(byteOffset, littleEndian) {\n if (this.#type !== 'Int32') {\n throw new Error('invalid type');\n }\n if (!littleEndian) throw new Error('must be little endian');\n return this.#view.getInt32(byteOffset, littleEndian);\n }\n setInt32(byteOffset, value, littleEndian) {\n if (this.#type !== 'Int32') {\n throw new Error('invalid type');\n }\n if (!littleEndian) throw new Error('must be little endian');\n this.#view.setInt32(byteOffset, value, littleEndian);\n }\n getBigInt64(byteOffset, littleEndian) {\n if (this.#type !== 'BigInt64') {\n throw new Error('invalid type');\n }\n if (!littleEndian) throw new Error('must be little endian');\n return this.#view.getBigInt64(byteOffset, littleEndian);\n }\n setBigInt64(byteOffset, value, littleEndian) {\n if (this.#type !== 'BigInt64') {\n throw new Error('invalid type');\n }\n if (!littleEndian) throw new Error('must be little endian');\n this.#view.setBigInt64(byteOffset, value, littleEndian);\n }\n}","// Copyright 2024 Roy T. Hashimoto. All Rights Reserved.\nimport * as VFS from './sqlite-constants.js';\nexport * from './sqlite-constants.js';\n\nconst DEFAULT_SECTOR_SIZE = 512;\n\n// Base class for a VFS.\nexport class Base {\n name;\n mxPathname = 64;\n _module;\n\n /**\n * @param {string} name \n * @param {object} module \n */\n constructor(name, module) {\n this.name = name;\n this._module = module;\n }\n\n /**\n * @returns {void|Promise<void>} \n */\n close() {\n }\n\n /**\n * @returns {boolean|Promise<boolean>}\n */\n isReady() {\n return true;\n }\n\n /**\n * Overload in subclasses to indicate which methods are asynchronous.\n * @param {string} methodName \n * @returns {boolean}\n */\n hasAsyncMethod(methodName) {\n return false;\n }\n\n /**\n * @param {number} pVfs \n * @param {number} zName \n * @param {number} pFile \n * @param {number} flags \n * @param {number} pOutFlags \n * @returns {number|Promise<number>}\n */\n xOpen(pVfs, zName, pFile, flags, pOutFlags) {\n return VFS.SQLITE_CANTOPEN;\n }\n\n /**\n * @param {number} pVfs \n * @param {number} zName \n * @param {number} syncDir \n * @returns {number|Promise<number>}\n */\n xDelete(pVfs, zName, syncDir) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pVfs \n * @param {number} zName \n * @param {number} flags \n * @param {number} pResOut \n * @returns {number|Promise<number>}\n */\n xAccess(pVfs, zName, flags, pResOut) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pVfs \n * @param {number} zName \n * @param {number} nOut \n * @param {number} zOut \n * @returns {number|Promise<number>}\n */\n xFullPathname(pVfs, zName, nOut, zOut) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pVfs \n * @param {number} nBuf \n * @param {number} zBuf \n * @returns {number|Promise<number>}\n */\n xGetLastError(pVfs, nBuf, zBuf) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @returns {number|Promise<number>}\n */\n xClose(pFile) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {number} pData \n * @param {number} iAmt \n * @param {number} iOffsetLo \n * @param {number} iOffsetHi \n * @returns {number|Promise<number>}\n */\n xRead(pFile, pData, iAmt, iOffsetLo, iOffsetHi) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {number} pData \n * @param {number} iAmt \n * @param {number} iOffsetLo \n * @param {number} iOffsetHi \n * @returns {number|Promise<number>}\n */\n xWrite(pFile, pData, iAmt, iOffsetLo, iOffsetHi) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {number} sizeLo \n * @param {number} sizeHi \n * @returns {number|Promise<number>}\n */\n xTruncate(pFile, sizeLo, sizeHi) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {number} flags \n * @returns {number|Promise<number>}\n */\n xSync(pFile, flags) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * \n * @param {number} pFile \n * @param {number} pSize \n * @returns {number|Promise<number>}\n */\n xFileSize(pFile, pSize) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {number} lockType \n * @returns {number|Promise<number>}\n */\n xLock(pFile, lockType) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {number} lockType \n * @returns {number|Promise<number>}\n */\n xUnlock(pFile, lockType) {\n return VFS.SQLITE_OK;\n } \n\n /**\n * @param {number} pFile \n * @param {number} pResOut \n * @returns {number|Promise<number>}\n */\n xCheckReservedLock(pFile, pResOut) {\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} pFile \n * @param {number} op \n * @param {number} pArg \n * @returns {number|Promise<number>}\n */\n xFileControl(pFile, op, pArg) {\n return VFS.SQLITE_NOTFOUND;\n }\n\n /**\n * @param {number} pFile \n * @returns {number|Promise<number>}\n */\n xSectorSize(pFile) {\n return DEFAULT_SECTOR_SIZE;\n }\n\n /**\n * @param {number} pFile \n * @returns {number|Promise<number>}\n */\n xDeviceCharacteristics(pFile) {\n return 0;\n }\n}\n\nexport const FILE_TYPE_MASK = [\n VFS.SQLITE_OPEN_MAIN_DB,\n VFS.SQLITE_OPEN_MAIN_JOURNAL,\n VFS.SQLITE_OPEN_TEMP_DB,\n VFS.SQLITE_OPEN_TEMP_JOURNAL,\n VFS.SQLITE_OPEN_TRANSIENT_DB,\n VFS.SQLITE_OPEN_SUBJOURNAL,\n VFS.SQLITE_OPEN_SUPER_JOURNAL,\n VFS.SQLITE_OPEN_WAL\n].reduce((mask, element) => mask | element);","// Copyright 2024 Roy T. Hashimoto. All Rights Reserved.\nimport { FacadeVFS } from '../FacadeVFS.js';\nimport * as VFS from '../VFS.js';\n\n// Sample in-memory filesystem.\nexport class MemoryVFS extends FacadeVFS {\n // Map of existing files, keyed by filename.\n mapNameToFile = new Map();\n\n // Map of open files, keyed by id (sqlite3_file pointer).\n mapIdToFile = new Map();\n\n static async create(name, module) {\n const vfs = new MemoryVFS(name, module);\n await vfs.isReady();\n return vfs;\n }\n\n constructor(name, module) {\n super(name, module);\n }\n\n close() {\n for (const fileId of this.mapIdToFile.keys()) {\n this.jClose(fileId);\n }\n }\n\n /**\n * @param {string?} filename \n * @param {number} fileId \n * @param {number} flags \n * @param {DataView} pOutFlags \n * @returns {number|Promise<number>}\n */\n jOpen(filename, fileId, flags, pOutFlags) {\n const url = new URL(filename || Math.random().toString(36).slice(2), 'file://');\n const pathname = url.pathname;\n\n let file = this.mapNameToFile.get(pathname);\n if (!file) {\n if (flags & VFS.SQLITE_OPEN_CREATE) {\n // Create a new file object.\n file = {\n pathname,\n flags,\n size: 0,\n data: new ArrayBuffer(0)\n };\n this.mapNameToFile.set(pathname, file);\n } else {\n return VFS.SQLITE_CANTOPEN;\n }\n }\n\n // Put the file in the opened files map.\n this.mapIdToFile.set(fileId, file);\n pOutFlags.setInt32(0, flags, true);\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} fileId \n * @returns {number|Promise<number>}\n */\n jClose(fileId) {\n const file = this.mapIdToFile.get(fileId);\n this.mapIdToFile.delete(fileId);\n\n if (file.flags & VFS.SQLITE_OPEN_DELETEONCLOSE) {\n this.mapNameToFile.delete(file.pathname);\n }\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} fileId \n * @param {Uint8Array} pData \n * @param {number} iOffset\n * @returns {number|Promise<number>}\n */\n jRead(fileId, pData, iOffset) {\n const file = this.mapIdToFile.get(fileId);\n\n // Clip the requested read to the file boundary.\n const bgn = Math.min(iOffset, file.size);\n const end = Math.min(iOffset + pData.byteLength, file.size);\n const nBytes = end - bgn;\n\n if (nBytes) {\n pData.set(new Uint8Array(file.data, bgn, nBytes));\n }\n\n if (nBytes < pData.byteLength) {\n // Zero unused area of read buffer.\n pData.fill(0, nBytes);\n return VFS.SQLITE_IOERR_SHORT_READ;\n }\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} fileId \n * @param {Uint8Array} pData \n * @param {number} iOffset\n * @returns {number|Promise<number>}\n */\n jWrite(fileId, pData, iOffset) {\n const file = this.mapIdToFile.get(fileId);\n if (iOffset + pData.byteLength > file.data.byteLength) {\n // Resize the ArrayBuffer to hold more data.\n const newSize = Math.max(iOffset + pData.byteLength, 2 * file.data.byteLength);\n const data = new ArrayBuffer(newSize);\n new Uint8Array(data).set(new Uint8Array(file.data, 0, file.size));\n file.data = data;\n }\n\n // Copy data.\n new Uint8Array(file.data, iOffset, pData.byteLength).set(pData.subarray());\n file.size = Math.max(file.size, iOffset + pData.byteLength);\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} fileId \n * @param {number} iSize \n * @returns {number|Promise<number>}\n */\n jTruncate(fileId, iSize) {\n const file = this.mapIdToFile.get(fileId);\n\n // For simplicity we don't make the ArrayBuffer smaller.\n file.size = Math.min(file.size, iSize);\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {number} fileId \n * @param {DataView} pSize64 \n * @returns {number|Promise<number>}\n */\n jFileSize(fileId, pSize64) {\n const file = this.mapIdToFile.get(fileId);\n\n pSize64.setBigInt64(0, BigInt(file.size), true);\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {string} name \n * @param {number} syncDir \n * @returns {number|Promise<number>}\n */\n jDelete(name, syncDir) {\n const url = new URL(name, 'file://');\n const pathname = url.pathname;\n\n this.mapNameToFile.delete(pathname);\n return VFS.SQLITE_OK;\n }\n\n /**\n * @param {string} name \n * @param {number} flags \n * @param {DataView} pResOut \n * @returns {number|Promise<number>}\n */\n jAccess(name, flags, pResOut) {\n const url = new URL(name, 'file://');\n const pathname = url.pathname;\n\n const file = this.mapNameToFile.get(pathname);\n pResOut.setInt32(0, file ? 1 : 0, true);\n return VFS.SQLITE_OK;\n }\n}\n"],"names":[],"sourceRoot":""}
|
package/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powersync/web",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.39.0",
|
|
4
4
|
"description": "PowerSync Web SDK",
|
|
5
5
|
"main": "lib/src/index.js",
|
|
6
6
|
"module": "lib/src/index.js",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"license": "Apache-2.0",
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"@journeyapps/wa-sqlite": "catalog:",
|
|
70
|
-
"@powersync/common": "workspace:^1.57.
|
|
70
|
+
"@powersync/common": "workspace:^1.57.2"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
73
|
"@powersync/common": "workspace:*",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Factory as WaSqliteFactory, SQLITE_ROW } from '@journeyapps/wa-sqlite';
|
|
2
|
-
import {
|
|
2
|
+
import { loadModuleAndVfs } from './vfs.js';
|
|
3
3
|
/**
|
|
4
4
|
* A small wrapper around WA-sqlite to help with opening databases and running statements by preparing them internally.
|
|
5
5
|
*
|
|
@@ -13,10 +13,8 @@ export class RawSqliteConnection {
|
|
|
13
13
|
* The `sqlite3*` connection pointer.
|
|
14
14
|
*/
|
|
15
15
|
db = 0;
|
|
16
|
-
_moduleFactory;
|
|
17
16
|
constructor(options) {
|
|
18
17
|
this.options = options;
|
|
19
|
-
this._moduleFactory = DEFAULT_MODULE_FACTORIES[this.options.vfs];
|
|
20
18
|
}
|
|
21
19
|
get isOpen() {
|
|
22
20
|
return this.db != 0;
|
|
@@ -26,17 +24,14 @@ export class RawSqliteConnection {
|
|
|
26
24
|
this.db = await api.open_v2(this.options.dbFilename, this.options.isReadOnly ? 1 /* SQLITE_OPEN_READONLY */ : 6 /* SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE */);
|
|
27
25
|
await this.executeRaw(`PRAGMA temp_store = ${this.options.temporaryStorage};`);
|
|
28
26
|
if (this.options.encryptionKey) {
|
|
29
|
-
const escapedKey = this.options.encryptionKey.
|
|
30
|
-
await this.executeRaw(`PRAGMA key = '${escapedKey}'
|
|
27
|
+
const escapedKey = this.options.encryptionKey.replaceAll("'", "''");
|
|
28
|
+
await this.executeRaw(`PRAGMA key = '${escapedKey}';`);
|
|
31
29
|
}
|
|
32
30
|
await this.executeRaw(`PRAGMA cache_size = -${this.options.cacheSizeKb};`);
|
|
33
31
|
await this.executeRaw(`SELECT powersync_update_hooks('install');`);
|
|
34
32
|
}
|
|
35
33
|
async openSQLiteAPI() {
|
|
36
|
-
const { module, vfs } = await this.
|
|
37
|
-
dbFileName: this.options.dbFilename,
|
|
38
|
-
encryptionKey: this.options.encryptionKey
|
|
39
|
-
});
|
|
34
|
+
const { module, vfs } = await loadModuleAndVfs(this.options);
|
|
40
35
|
const sqlite3 = WaSqliteFactory(module);
|
|
41
36
|
sqlite3.vfs_register(vfs, true);
|
|
42
37
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RawSqliteConnection.js","sourceRoot":"","sources":["../../../../../src/db/adapters/wa-sqlite/RawSqliteConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEhF,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"RawSqliteConnection.js","sourceRoot":"","sources":["../../../../../src/db/adapters/wa-sqlite/RawSqliteConnection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEhF,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAe5C;;;;;GAKG;AACH,MAAM,OAAO,mBAAmB;IAOT;IANb,UAAU,GAAqB,IAAI,CAAC;IAC5C;;OAEG;IACK,EAAE,GAAW,CAAC,CAAC;IAEvB,YAAqB,OAA2C;QAA3C,YAAO,GAAP,OAAO,CAAoC;IAAG,CAAC;IAEpE,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,UAAU,GAAG,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;QAC3D,IAAI,CAAC,EAAE,GAAG,MAAM,GAAG,CAAC,OAAO,CACzB,IAAI,CAAC,OAAO,CAAC,UAAU,EACvB,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC,CAAC,CAAC,gDAAgD,CAC5G,CAAC;QACF,MAAM,IAAI,CAAC,UAAU,CAAC,uBAAuB,IAAI,CAAC,OAAO,CAAC,gBAAgB,GAA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AAE,KAAK,EAAE,GAAG,EAAE,EAAE;YACjC,IAAI,OAAO,CAAC,IAAI,SAAS,EAAE,CAAC;gBAC1B,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YACzB,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAChB,IAAI,QAAQ,EAAE,CAAC;YACb,GAAG,CAAC,eAAe,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACtC,CAAC;QAED,MAAM,IAAI,GAAG,EAAE,CAAC;QAChB,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,UAAU,EAAE,CAAC;YAC7C,IAAI,cAAc,EAAE,CAAC;gBACnB,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBAC1B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACjB,CAAC;QACH,CAAC;QAED,YAAY,KAAK,GAAG,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QACxC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC1C,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type * as SQLite from '@journeyapps/wa-sqlite';
|
|
2
|
+
import { ResolvedWASQLiteOpenFactoryOptions } from './WASQLiteOpenFactory.js';
|
|
2
3
|
/**
|
|
3
4
|
* List of currently tested virtual filesystems
|
|
4
5
|
*/
|
|
@@ -6,16 +7,26 @@ export declare enum WASQLiteVFS {
|
|
|
6
7
|
IDBBatchAtomicVFS = "IDBBatchAtomicVFS",
|
|
7
8
|
OPFSCoopSyncVFS = "OPFSCoopSyncVFS",
|
|
8
9
|
AccessHandlePoolVFS = "AccessHandlePoolVFS",
|
|
9
|
-
OPFSWriteAheadVFS = "OPFSWriteAheadVFS"
|
|
10
|
+
OPFSWriteAheadVFS = "OPFSWriteAheadVFS",
|
|
11
|
+
/**
|
|
12
|
+
* A virtual file system storing data in-memory only, without persistence.
|
|
13
|
+
*
|
|
14
|
+
* This file system can be used in three configurations:
|
|
15
|
+
*
|
|
16
|
+
* 1. In shared workers (the default when available): All tabs share the same in-memory database, which is cleared
|
|
17
|
+
* once the last tab is closed.
|
|
18
|
+
* 2. In dedicated workers (used when `enableMultiTabs` is disabled). Each tab has its own in-memory database cleared
|
|
19
|
+
* when the tab is closed. Queries are offloaded to a dedicated worker.
|
|
20
|
+
* 3. In the context of the tab itself (used when both `enableMultiTabs` and `useWebWorker` are disabled). The per-tab
|
|
21
|
+
* database is hosted in the tab itself, and queries run synchronously. This is _a lot_ faster than any other
|
|
22
|
+
* single-threadedVFS, but can block JavaScript for computationally-intensive queries.
|
|
23
|
+
*
|
|
24
|
+
* This VFS primarily intended for development, but it also useful for online-first deployments not syncing large
|
|
25
|
+
* amounts of data, as it is quicker to start up.
|
|
26
|
+
*/
|
|
27
|
+
InMemoryVfs = "InMemoryVFS"
|
|
10
28
|
}
|
|
11
29
|
export declare function vfsRequiresDedicatedWorkers(vfs: WASQLiteVFS): vfs is WASQLiteVFS.OPFSCoopSyncVFS | WASQLiteVFS.AccessHandlePoolVFS | WASQLiteVFS.OPFSWriteAheadVFS;
|
|
12
|
-
/**
|
|
13
|
-
* @internal
|
|
14
|
-
*/
|
|
15
|
-
export type WASQLiteModuleFactoryOptions = {
|
|
16
|
-
dbFileName: string;
|
|
17
|
-
encryptionKey?: string;
|
|
18
|
-
};
|
|
19
30
|
/**
|
|
20
31
|
* @internal
|
|
21
32
|
*/
|
|
@@ -23,28 +34,7 @@ export type SQLiteModule = Parameters<typeof SQLite.Factory>[0];
|
|
|
23
34
|
/**
|
|
24
35
|
* @internal
|
|
25
36
|
*/
|
|
26
|
-
export
|
|
37
|
+
export declare function loadModuleAndVfs({ vfs, dbFilename, encryptionKey }: ResolvedWASQLiteOpenFactoryOptions): Promise<{
|
|
27
38
|
module: SQLiteModule;
|
|
28
39
|
vfs: SQLiteVFS;
|
|
29
40
|
}>;
|
|
30
|
-
/**
|
|
31
|
-
* @internal
|
|
32
|
-
*/
|
|
33
|
-
export declare const DEFAULT_MODULE_FACTORIES: {
|
|
34
|
-
IDBBatchAtomicVFS: (options: WASQLiteModuleFactoryOptions) => Promise<{
|
|
35
|
-
module: any;
|
|
36
|
-
vfs: any;
|
|
37
|
-
}>;
|
|
38
|
-
AccessHandlePoolVFS: (options: WASQLiteModuleFactoryOptions) => Promise<{
|
|
39
|
-
module: any;
|
|
40
|
-
vfs: any;
|
|
41
|
-
}>;
|
|
42
|
-
OPFSCoopSyncVFS: (options: WASQLiteModuleFactoryOptions) => Promise<{
|
|
43
|
-
module: any;
|
|
44
|
-
vfs: any;
|
|
45
|
-
}>;
|
|
46
|
-
OPFSWriteAheadVFS: (options: WASQLiteModuleFactoryOptions) => Promise<{
|
|
47
|
-
module: any;
|
|
48
|
-
vfs: any;
|
|
49
|
-
}>;
|
|
50
|
-
};
|
|
@@ -7,9 +7,26 @@ export var WASQLiteVFS;
|
|
|
7
7
|
WASQLiteVFS["OPFSCoopSyncVFS"] = "OPFSCoopSyncVFS";
|
|
8
8
|
WASQLiteVFS["AccessHandlePoolVFS"] = "AccessHandlePoolVFS";
|
|
9
9
|
WASQLiteVFS["OPFSWriteAheadVFS"] = "OPFSWriteAheadVFS";
|
|
10
|
+
/**
|
|
11
|
+
* A virtual file system storing data in-memory only, without persistence.
|
|
12
|
+
*
|
|
13
|
+
* This file system can be used in three configurations:
|
|
14
|
+
*
|
|
15
|
+
* 1. In shared workers (the default when available): All tabs share the same in-memory database, which is cleared
|
|
16
|
+
* once the last tab is closed.
|
|
17
|
+
* 2. In dedicated workers (used when `enableMultiTabs` is disabled). Each tab has its own in-memory database cleared
|
|
18
|
+
* when the tab is closed. Queries are offloaded to a dedicated worker.
|
|
19
|
+
* 3. In the context of the tab itself (used when both `enableMultiTabs` and `useWebWorker` are disabled). The per-tab
|
|
20
|
+
* database is hosted in the tab itself, and queries run synchronously. This is _a lot_ faster than any other
|
|
21
|
+
* single-threadedVFS, but can block JavaScript for computationally-intensive queries.
|
|
22
|
+
*
|
|
23
|
+
* This VFS primarily intended for development, but it also useful for online-first deployments not syncing large
|
|
24
|
+
* amounts of data, as it is quicker to start up.
|
|
25
|
+
*/
|
|
26
|
+
WASQLiteVFS["InMemoryVfs"] = "InMemoryVFS";
|
|
10
27
|
})(WASQLiteVFS || (WASQLiteVFS = {}));
|
|
11
28
|
export function vfsRequiresDedicatedWorkers(vfs) {
|
|
12
|
-
return vfs != WASQLiteVFS.IDBBatchAtomicVFS;
|
|
29
|
+
return vfs != WASQLiteVFS.IDBBatchAtomicVFS && vfs != WASQLiteVFS.InMemoryVfs;
|
|
13
30
|
}
|
|
14
31
|
async function asyncModuleFactory(encryptionKey) {
|
|
15
32
|
if (encryptionKey) {
|
|
@@ -34,44 +51,45 @@ async function syncModuleFactory(encryptionKey) {
|
|
|
34
51
|
/**
|
|
35
52
|
* @internal
|
|
36
53
|
*/
|
|
37
|
-
export
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
54
|
+
export async function loadModuleAndVfs({ vfs, dbFilename, encryptionKey }) {
|
|
55
|
+
let moduleFactory = syncModuleFactory;
|
|
56
|
+
let resolveVfs;
|
|
57
|
+
switch (vfs) {
|
|
58
|
+
case WASQLiteVFS.IDBBatchAtomicVFS: {
|
|
59
|
+
moduleFactory = asyncModuleFactory;
|
|
60
|
+
const { IDBBatchAtomicVFS } = await import('@journeyapps/wa-sqlite/src/examples/IDBBatchAtomicVFS.js');
|
|
61
|
+
resolveVfs = (module) => {
|
|
62
|
+
// @ts-expect-error The types for this static method are missing upstream
|
|
63
|
+
return IDBBatchAtomicVFS.create(dbFilename, module, { lockPolicy: 'exclusive' });
|
|
64
|
+
};
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case WASQLiteVFS.AccessHandlePoolVFS: {
|
|
68
|
+
// @ts-expect-error The types for this import are missing upstream
|
|
69
|
+
const { AccessHandlePoolVFS } = await import('@journeyapps/wa-sqlite/src/examples/AccessHandlePoolVFS.js');
|
|
70
|
+
resolveVfs = (module) => AccessHandlePoolVFS.create(dbFilename, module);
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
case WASQLiteVFS.OPFSCoopSyncVFS: {
|
|
74
|
+
// @ts-expect-error The types for this import are missing upstream
|
|
75
|
+
const { OPFSCoopSyncVFS } = await import('@journeyapps/wa-sqlite/src/examples/OPFSCoopSyncVFS.js');
|
|
76
|
+
resolveVfs = (module) => OPFSCoopSyncVFS.create(dbFilename, module);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
case WASQLiteVFS.OPFSWriteAheadVFS: {
|
|
80
|
+
// @ts-expect-error The types for this import are missing upstream
|
|
81
|
+
const { OPFSWriteAheadVFS } = await import('@journeyapps/wa-sqlite/src/examples/OPFSWriteAheadVFS.js');
|
|
82
|
+
resolveVfs = (module) => OPFSWriteAheadVFS.create(dbFilename, module, {});
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
case WASQLiteVFS.InMemoryVfs: {
|
|
86
|
+
const { MemoryVFS } = await import('@journeyapps/wa-sqlite/src/examples/MemoryVFS.js');
|
|
43
87
|
// @ts-expect-error The types for this static method are missing upstream
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
[WASQLiteVFS.AccessHandlePoolVFS]: async (options) => {
|
|
48
|
-
const module = await syncModuleFactory(options.encryptionKey);
|
|
49
|
-
// @ts-expect-error The types for this static method are missing upstream
|
|
50
|
-
const { AccessHandlePoolVFS } = await import('@journeyapps/wa-sqlite/src/examples/AccessHandlePoolVFS.js');
|
|
51
|
-
return {
|
|
52
|
-
module,
|
|
53
|
-
vfs: await AccessHandlePoolVFS.create(options.dbFileName, module)
|
|
54
|
-
};
|
|
55
|
-
},
|
|
56
|
-
[WASQLiteVFS.OPFSCoopSyncVFS]: async (options) => {
|
|
57
|
-
const module = await syncModuleFactory(options.encryptionKey);
|
|
58
|
-
// @ts-expect-error The types for this static method are missing upstream
|
|
59
|
-
const { OPFSCoopSyncVFS } = await import('@journeyapps/wa-sqlite/src/examples/OPFSCoopSyncVFS.js');
|
|
60
|
-
const vfs = await OPFSCoopSyncVFS.create(options.dbFileName, module);
|
|
61
|
-
return {
|
|
62
|
-
module,
|
|
63
|
-
vfs
|
|
64
|
-
};
|
|
65
|
-
},
|
|
66
|
-
[WASQLiteVFS.OPFSWriteAheadVFS]: async (options) => {
|
|
67
|
-
const module = await syncModuleFactory(options.encryptionKey);
|
|
68
|
-
// @ts-expect-error The types for this static method are missing upstream
|
|
69
|
-
const { OPFSWriteAheadVFS } = await import('@journeyapps/wa-sqlite/src/examples/OPFSWriteAheadVFS.js');
|
|
70
|
-
const vfs = await OPFSWriteAheadVFS.create(options.dbFileName, module, {});
|
|
71
|
-
return {
|
|
72
|
-
module,
|
|
73
|
-
vfs
|
|
74
|
-
};
|
|
88
|
+
resolveVfs = (module) => MemoryVFS.create(dbFilename, module);
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
75
91
|
}
|
|
76
|
-
|
|
92
|
+
const module = await moduleFactory(encryptionKey);
|
|
93
|
+
return { module, vfs: await resolveVfs(module) };
|
|
94
|
+
}
|
|
77
95
|
//# sourceMappingURL=vfs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vfs.js","sourceRoot":"","sources":["../../../../../src/db/adapters/wa-sqlite/vfs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":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AAM,EAAE,EAAE,CAAC,CAAC;YAC1E,MAAM;QACR,CAAC;QACD,KAAK,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC;YAC7B,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,kDAAkD,CAAC,CAAC;YACvF,yEAAyE;YACzE,UAAU,GAAG,CAAC,MAAM,EAAE,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;YAC9D,MAAM;QACR,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,aAAa,CAAC,CAAC;IAClD,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;AACnD,CAAC"}
|
|
@@ -3,6 +3,7 @@ import { DatabaseServer } from '../../db/adapters/wa-sqlite/DatabaseServer.js';
|
|
|
3
3
|
import { getNavigatorLocks } from '../../shared/navigator.js';
|
|
4
4
|
import { RawSqliteConnection } from '../../db/adapters/wa-sqlite/RawSqliteConnection.js';
|
|
5
5
|
import { ConcurrentSqliteConnection } from '../../db/adapters/wa-sqlite/ConcurrentConnection.js';
|
|
6
|
+
import { WASQLiteVFS } from '../../db/adapters/wa-sqlite/vfs.js';
|
|
6
7
|
const OPEN_DB_LOCK = 'open-wasqlite-db';
|
|
7
8
|
/**
|
|
8
9
|
* Shared state to manage multiple database connections hosted by a worker.
|
|
@@ -46,13 +47,14 @@ export class MultiDatabaseServer {
|
|
|
46
47
|
}
|
|
47
48
|
async databaseOpenAttempt(options) {
|
|
48
49
|
return getNavigatorLocks().request(OPEN_DB_LOCK, async () => {
|
|
49
|
-
const { dbFilename } = options;
|
|
50
|
+
const { dbFilename, isReadOnly, vfs } = options;
|
|
50
51
|
let server = this.activeDatabases.get(dbFilename);
|
|
51
52
|
if (server == null) {
|
|
52
53
|
// We don't need navigator locks for shared workers because all queries run in this shared worker exclusively.
|
|
53
54
|
// For read-only connections, we use a VFS that supports concurrent reads (so a single lock on the connection is
|
|
54
|
-
// fine).
|
|
55
|
-
|
|
55
|
+
// fine). In-memory databases either run in a shared worker or aren't shared across tabs at all, so the internal
|
|
56
|
+
// lock is enough.
|
|
57
|
+
const needsNavigatorLocks = !(isSharedWorker || isReadOnly || vfs == WASQLiteVFS.InMemoryVfs);
|
|
56
58
|
const connection = new RawSqliteConnection(options);
|
|
57
59
|
const withSafeConcurrency = new ConcurrentSqliteConnection(connection, needsNavigatorLocks);
|
|
58
60
|
// Initializing the RawSqliteConnection will run some pragmas that might write to the database file, so we want
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiDatabaseServer.js","sourceRoot":"","sources":["../../../../src/worker/db/MultiDatabaseServer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAwB,cAAc,EAAE,MAAM,+CAA+C,CAAC;AAKrG,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,oDAAoD,CAAC;AACzF,OAAO,EAAE,0BAA0B,EAAE,MAAM,qDAAqD,CAAC;
|
|
1
|
+
{"version":3,"file":"MultiDatabaseServer.js","sourceRoot":"","sources":["../../../../src/worker/db/MultiDatabaseServer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAwB,cAAc,EAAE,MAAM,+CAA+C,CAAC;AAKrG,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,oDAAoD,CAAC;AACzF,OAAO,EAAE,0BAA0B,EAAE,MAAM,qDAAqD,CAAC;AACjG,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AAEjE,MAAM,YAAY,GAAG,kBAAkB,CAAC;AAExC;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAGT;IAFb,eAA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