From e44e2fe070484e06d384a31ef2699c3a2d5d474e Mon Sep 17 00:00:00 2001 From: RaindropsSys Date: Thu, 13 Jun 2024 15:46:03 +0200 Subject: GitHub migration --- updater/main.js | 201 ++ updater/menu/16x16@2x.png | Bin 0 -> 4883 bytes updater/package-lock.json | 3664 ++++++++++++++++++++ updater/package.json | 13 + updater/sql/.idea/.gitignore | 8 + .../.idea/inspectionProfiles/Project_Default.xml | 13 + .../.idea/inspectionProfiles/profiles_settings.xml | 6 + updater/sql/.idea/misc.xml | 4 + updater/sql/.idea/modules.xml | 8 + updater/sql/.idea/pgsql.iml | 8 + updater/sql/doall.sh | 15 + updater/sql/mac/LICENSE | 25 + updater/sql/mac/README.md | 249 ++ updater/sql/mac/binding.gyp | 58 + updater/sql/mac/deps/common-sqlite.gypi | 60 + updater/sql/mac/deps/extract.js | 10 + .../sql/mac/deps/sqlite-autoconf-3440200.tar.gz | Bin 0 -> 3204841 bytes updater/sql/mac/deps/sqlite3.gyp | 121 + updater/sql/mac/lib/sqlite3-binding.js | 1 + updater/sql/mac/lib/sqlite3.d.ts | 205 ++ updater/sql/mac/lib/sqlite3.js | 207 ++ updater/sql/mac/lib/trace.js | 38 + updater/sql/mac/package.json | 89 + updater/sql/mac/src/async.h | 76 + updater/sql/mac/src/backup.cc | 418 +++ updater/sql/mac/src/backup.h | 209 ++ updater/sql/mac/src/database.cc | 751 ++++ updater/sql/mac/src/database.h | 188 + updater/sql/mac/src/gcc-preinclude.h | 30 + updater/sql/mac/src/macros.h | 207 ++ updater/sql/mac/src/node_sqlite3.cc | 128 + updater/sql/mac/src/statement.cc | 939 +++++ updater/sql/mac/src/statement.h | 244 ++ updater/sql/mac/src/threading.h | 10 + updater/sql/main.py | 206 ++ updater/sql/win/LICENSE | 25 + updater/sql/win/README.md | 249 ++ updater/sql/win/binding.gyp | 58 + updater/sql/win/deps/common-sqlite.gypi | 60 + updater/sql/win/deps/extract.js | 10 + .../sql/win/deps/sqlite-autoconf-3440200.tar.gz | Bin 0 -> 3204841 bytes updater/sql/win/deps/sqlite3.gyp | 121 + updater/sql/win/lib/sqlite3-binding.js | 1 + updater/sql/win/lib/sqlite3.d.ts | 205 ++ updater/sql/win/lib/sqlite3.js | 207 ++ updater/sql/win/lib/trace.js | 38 + updater/sql/win/package.json | 89 + updater/sql/win/src/async.h | 76 + updater/sql/win/src/backup.cc | 418 +++ updater/sql/win/src/backup.h | 209 ++ updater/sql/win/src/database.cc | 751 ++++ updater/sql/win/src/database.h | 188 + updater/sql/win/src/gcc-preinclude.h | 30 + updater/sql/win/src/macros.h | 207 ++ updater/sql/win/src/node_sqlite3.cc | 128 + updater/sql/win/src/statement.cc | 939 +++++ updater/sql/win/src/statement.h | 244 ++ updater/sql/win/src/threading.h | 10 + updater/tray/16x16Template@2x.png | Bin 0 -> 2556 bytes 59 files changed, 12672 insertions(+) create mode 100755 updater/main.js create mode 100755 updater/menu/16x16@2x.png create mode 100755 updater/package-lock.json create mode 100755 updater/package.json create mode 100755 updater/sql/.idea/.gitignore create mode 100755 updater/sql/.idea/inspectionProfiles/Project_Default.xml create mode 100755 updater/sql/.idea/inspectionProfiles/profiles_settings.xml create mode 100755 updater/sql/.idea/misc.xml create mode 100755 updater/sql/.idea/modules.xml create mode 100755 updater/sql/.idea/pgsql.iml create mode 100755 updater/sql/doall.sh create mode 100755 updater/sql/mac/LICENSE create mode 100755 updater/sql/mac/README.md create mode 100755 updater/sql/mac/binding.gyp create mode 100755 updater/sql/mac/deps/common-sqlite.gypi create mode 100755 updater/sql/mac/deps/extract.js create mode 100755 updater/sql/mac/deps/sqlite-autoconf-3440200.tar.gz create mode 100755 updater/sql/mac/deps/sqlite3.gyp create mode 100755 updater/sql/mac/lib/sqlite3-binding.js create mode 100755 updater/sql/mac/lib/sqlite3.d.ts create mode 100755 updater/sql/mac/lib/sqlite3.js create mode 100755 updater/sql/mac/lib/trace.js create mode 100755 updater/sql/mac/package.json create mode 100755 updater/sql/mac/src/async.h create mode 100755 updater/sql/mac/src/backup.cc create mode 100755 updater/sql/mac/src/backup.h create mode 100755 updater/sql/mac/src/database.cc create mode 100755 updater/sql/mac/src/database.h create mode 100755 updater/sql/mac/src/gcc-preinclude.h create mode 100755 updater/sql/mac/src/macros.h create mode 100755 updater/sql/mac/src/node_sqlite3.cc create mode 100755 updater/sql/mac/src/statement.cc create mode 100755 updater/sql/mac/src/statement.h create mode 100755 updater/sql/mac/src/threading.h create mode 100755 updater/sql/main.py create mode 100755 updater/sql/win/LICENSE create mode 100755 updater/sql/win/README.md create mode 100755 updater/sql/win/binding.gyp create mode 100755 updater/sql/win/deps/common-sqlite.gypi create mode 100755 updater/sql/win/deps/extract.js create mode 100755 updater/sql/win/deps/sqlite-autoconf-3440200.tar.gz create mode 100755 updater/sql/win/deps/sqlite3.gyp create mode 100755 updater/sql/win/lib/sqlite3-binding.js create mode 100755 updater/sql/win/lib/sqlite3.d.ts create mode 100755 updater/sql/win/lib/sqlite3.js create mode 100755 updater/sql/win/lib/trace.js create mode 100755 updater/sql/win/package.json create mode 100755 updater/sql/win/src/async.h create mode 100755 updater/sql/win/src/backup.cc create mode 100755 updater/sql/win/src/backup.h create mode 100755 updater/sql/win/src/database.cc create mode 100755 updater/sql/win/src/database.h create mode 100755 updater/sql/win/src/gcc-preinclude.h create mode 100755 updater/sql/win/src/macros.h create mode 100755 updater/sql/win/src/node_sqlite3.cc create mode 100755 updater/sql/win/src/statement.cc create mode 100755 updater/sql/win/src/statement.h create mode 100755 updater/sql/win/src/threading.h create mode 100755 updater/tray/16x16Template@2x.png (limited to 'updater') diff --git a/updater/main.js b/updater/main.js new file mode 100755 index 0000000..d70bd51 --- /dev/null +++ b/updater/main.js @@ -0,0 +1,201 @@ +// noinspection JSCheckFunctionSignatures + +require('os').setPriority(19); + +const { app, Tray, Menu, shell } = require('electron'); +const fs = require('fs'); +const libprisbeam = require('libprisbeam'); +const execCb = require('child_process').exec; + +let tray = null; + +app.whenReady().then(() => { + const config = app.getPath("userData"); + if (!fs.existsSync(config + "/database.txt")) fs.writeFileSync(config + "/database.txt", "# Insert the full path to your Prisbeam database below:\n\n# Insert your Derpibooru username below:\n\n# (if you have not registered for Prisbeam Cloud, please contact Equestria.dev)"); + if (!fs.existsSync(config + "/last.txt")) fs.writeFileSync(config + "/last.txt", "0"); + + if (process.platform === "darwin") app.dock.hide(); + tray = new Tray(__dirname + "/tray/16x16Template@2x.png"); + tray.setToolTip("Prisbeam Updater"); + + let update = null; + + async function startUpdate() { + try { + let databasePath = fs.readFileSync(config + "/database.txt").toString().trim().split("\n").filter(i => !i.startsWith("#") && i.trim() !== "")[0]; + let userName = fs.readFileSync(config + "/database.txt").toString().trim().split("\n").filter(i => !i.startsWith("#") && i.trim() !== "")[1]; + + if (fs.existsSync(config + "/temp")) fs.rmSync(config + "/temp", { recursive: true }); + fs.mkdirSync(config + "/temp"); + + update = [ + { + title: "Preparing update..." + }, + { + title: "Downloading update data..." + } + ]; + updateTray(); + + await new Promise((res) => { + let p = execCb("curl \"https://cdn.equestria.dev/prisbeam/users/" + userName + ".db\" -o \"" + config + "/temp/preprocessed.db\"", () => { + res(); + }); + + let percent = 0; + let data = (d) => { + let lines = d.trim().split("\n"); + let line = lines[lines.length - 1]; + + let lineProcessed = line.replace(/^(\d+) (\d|.)+M .*$/gm, "$1").trim(); + if (lineProcessed !== line && !isNaN(parseInt(lineProcessed))) { + percent = lineProcessed; + } + + update = [ + { + title: "Preparing update..." + }, + { + title: "Downloading update data..." + (percent > 0 ? " (" + Math.round(percent / 2) + "%)" : "") + } + ]; + if (percent > 0) updateTray(); + }; + + p.stdout.on('data', data); + p.stderr.on('data', data); + }); + + await new Promise((res) => { + let p = execCb("curl \"https://cdn.equestria.dev/prisbeam/common/tags.db\" -o \"" + config + "/temp/tags.db\"", () => { + res(); + }); + + let percent = 0; + let data = (d) => { + let lines = d.trim().split("\n"); + let line = lines[lines.length - 1]; + + let lineProcessed = line.replace(/^(\d+) (\d|.)+M .*$/gm, "$1").trim(); + if (lineProcessed !== line && !isNaN(parseInt(lineProcessed))) { + percent = lineProcessed; + } + + update = [ + { + title: "Preparing update..." + }, + { + title: "Downloading update data..." + (percent > 0 ? " (" + (50 + Math.round(percent / 2)) + "%)" : "") + } + ]; + if (percent > 0) updateTray(); + }; + + p.stdout.on('data', data); + p.stderr.on('data', data); + }); + + fs.writeFileSync(databasePath + "/updater.pbmk", process.pid.toString()); + + let database = new libprisbeam.Prisbeam({ + database: databasePath, + cachePath: config + "/temp", + sqlitePath: process.platform === "darwin" ? "../../../sql/mac" : "../../../sql/win", + readOnly: false, + sensitiveImageProtocol: true, + verbose: false + }); + await database.initialize(true); + + let updater = new libprisbeam.PrisbeamUpdater(database); + await updater.updateFromPreprocessed(config + "/temp/preprocessed.db", config + "/temp/tags.db", (status) => { + update = status; + updateTray(); + }); + + fs.unlinkSync(databasePath + "/updater.pbmk"); + if (fs.existsSync(config + "/temp")) fs.rmSync(config + "/temp", { recursive: true }); + + fs.copyFileSync(databasePath + "/current.pbdb", databasePath + "/updated.pbdb"); + + update = null; + fs.writeFileSync(config + "/last.txt", new Date().getTime().toString()); + updateTray(); + } catch (e) { + console.error(e); + update = null; + } + } + + function updateTray() { + let template = [ + { label: "Prisbeam Updater", type: 'normal', enabled: false, icon: __dirname + "/menu/16x16@2x.png" }, + + { type: 'separator' }, + ]; + + let databasePath = fs.readFileSync(config + "/database.txt").toString().trim().split("\n").filter(i => !i.startsWith("#") && i.trim() !== "")[0]; + let lastUpdate = parseInt(fs.readFileSync(config + "/last.txt").toString()); + + if (databasePath && fs.existsSync(databasePath) && fs.existsSync(databasePath + "/current.pbdb")) { + if (update) { + template.push(...[ + ...update.filter(i => i).map(i => { + return { label: i['title'], enabled: false } + }), + + { type: 'separator' }, + + { label: "Open Prisbeam", enabled: false }, + ]); + } else { + template.push(...[ + { label: "Last Database Update:", type: 'normal', enabled: false }, + { label: lastUpdate > 0 ? new Date(lastUpdate).toLocaleString("en-CA", { day: "2-digit", month: "2-digit", year: "numeric", hour: "2-digit", minute: "2-digit", hour12: false }) : "Never", type: 'normal', enabled: false }, + + { type: 'separator' }, + + { label: "Update Database Now", click: () => { + startUpdate(); + } }, + + { type: 'separator' }, + + { label: "Open Prisbeam", enabled: false, }, + ]); + } + } else { + template.push(...[ + { label: "Updater Not Configured", type: 'normal', enabled: false }, + + { type: 'separator' }, + + { label: "Change Database Path", click: () => { + shell.openPath(config + "/database.txt"); + } }, + + { type: 'separator' }, + + { label: "Open Prisbeam", enabled: false }, + ]); + } + + template.push({ label: "Quit", role: "quit" }); + + tray.setContextMenu(Menu.buildFromTemplate(template)); + } + + updateTray(); + setInterval(() => { + if (update) return; + let lastUpdate = parseInt(fs.readFileSync(config + "/last.txt").toString()); + let difference = new Date().getTime() - lastUpdate; + + if (difference > 86400000) { + startUpdate(); + } + }, 60000); +}) diff --git a/updater/menu/16x16@2x.png b/updater/menu/16x16@2x.png new file mode 100755 index 0000000..c02929f Binary files /dev/null and b/updater/menu/16x16@2x.png differ diff --git a/updater/package-lock.json b/updater/package-lock.json new file mode 100755 index 0000000..7c56c02 --- /dev/null +++ b/updater/package-lock.json @@ -0,0 +1,3664 @@ +{ + "name": "updater", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "version": "1.0.0", + "dependencies": { + "libprisbeam": "git+https://source.equestria.dev/equestria.dev/libprisbeam.git/", + "sqlite3": "^5.1.7" + }, + "devDependencies": { + "electron": "^29.1.6", + "electron-packager": "^17.1.2", + "electron-rebuild": "^3.2.9" + } + }, + "node_modules/@electron/asar": { + "version": "3.2.9", + "resolved": "https://registry.npmjs.org/@electron/asar/-/asar-3.2.9.tgz", + "integrity": "sha512-Vu2P3X2gcZ3MY9W7yH72X9+AMXwUQZEJBrsPIbX0JsdllLtoh62/Q8Wg370/DawIEVKOyfD6KtTLo645ezqxUA==", + "dev": true, + "dependencies": { + "commander": "^5.0.0", + "glob": "^7.1.6", + "minimatch": "^3.0.4" + }, + "bin": { + "asar": "bin/asar.js" + }, + "engines": { + "node": ">=10.12.0" + } + }, + "node_modules/@electron/get": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@electron/get/-/get-2.0.3.tgz", + "integrity": "sha512-Qkzpg2s9GnVV2I2BjRksUi43U5e6+zaQMcjoJy0C+C5oxaKl+fmckGDQFtRpZpZV0NQekuZZ+tGz7EA9TVnQtQ==", + "dev": true, + "dependencies": { + "debug": "^4.1.1", + "env-paths": "^2.2.0", + "fs-extra": "^8.1.0", + "got": "^11.8.5", + "progress": "^2.0.3", + "semver": "^6.2.0", + "sumchecker": "^3.0.1" + }, + "engines": { + "node": ">=12" + }, + "optionalDependencies": { + "global-agent": "^3.0.0" + } + }, + "node_modules/@electron/get/node_modules/semver": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + } + }, + "node_modules/@electron/notarize": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/@electron/notarize/-/notarize-1.2.4.tgz", + "integrity": "sha512-W5GQhJEosFNafewnS28d3bpQ37/s91CDWqxVchHfmv2dQSTWpOzNlUVQwYzC1ay5bChRV/A9BTL68yj0Pa+TSg==", + "dev": true, + "dependencies": { + "debug": "^4.1.1", + "fs-extra": "^9.0.1" + }, + "engines": { + "node": ">= 10.0.0" + } + }, + "node_modules/@electron/notarize/node_modules/fs-extra": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz", + "integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==", + "dev": true, + "dependencies": { + "at-least-node": "^1.0.0", + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@electron/notarize/node_modules/jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dev": true, + "dependencies": { + "universalify": "^2.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, + "node_modules/@electron/notarize/node_modules/universalify": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", + "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", + "dev": true, + "engines": { + "node": ">= 10.0.0" + } + }, + "node_modules/@electron/osx-sign": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@electron/osx-sign/-/osx-sign-1.1.0.tgz", + "integrity": "sha512-9xxNAyTu2YEAfn2TOQXC5fcTZ9hxVT/zAgWOONpOvxivv5rU97RldGbJrxz+OBKXGAiQRJUYOY07mJI++S/iYw==", + "dev": true, + "dependencies": { + "compare-version": "^0.1.2", + "debug": "^4.3.4", + "fs-extra": "^10.0.0", + "isbinaryfile": "^4.0.8", + "minimist": "^1.2.6", + "plist": "^3.0.5" + }, + "bin": { + "electron-osx-flat": "bin/electron-osx-flat.js", + "electron-osx-sign": "bin/electron-osx-sign.js" + }, + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/@electron/osx-sign/node_modules/fs-extra": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", + "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@electron/osx-sign/node_modules/jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dev": true, + "dependencies": { + "universalify": "^2.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, + "node_modules/@electron/osx-sign/node_modules/universalify": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", + "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", + "dev": true, + "engines": { + "node": ">= 10.0.0" + } + }, + "node_modules/@electron/universal": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/@electron/universal/-/universal-1.5.1.tgz", + "integrity": "sha512-kbgXxyEauPJiQQUNG2VgUeyfQNFk6hBF11ISN2PNI6agUgPl55pv4eQmaqHzTAzchBvqZ2tQuRVaPStGf0mxGw==", + "dev": true, + "dependencies": { + "@electron/asar": "^3.2.1", + "@malept/cross-spawn-promise": "^1.1.0", + "debug": "^4.3.1", + "dir-compare": "^3.0.0", + "fs-extra": "^9.0.1", + "minimatch": "^3.0.4", + "plist": "^3.0.4" + }, + "engines": { + "node": ">=8.6" + } + }, + "node_modules/@electron/universal/node_modules/fs-extra": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz", + "integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==", + "dev": true, + "dependencies": { + "at-least-node": "^1.0.0", + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@electron/universal/node_modules/jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dev": true, + "dependencies": { + "universalify": "^2.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, + "node_modules/@electron/universal/node_modules/universalify": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", + "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", + "dev": true, + "engines": { + "node": ">= 10.0.0" + } + }, + "node_modules/@gar/promisify": { + "version": "1.1.3", + "devOptional": true, + "license": "MIT" + }, + "node_modules/@malept/cross-spawn-promise": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@malept/cross-spawn-promise/-/cross-spawn-promise-1.1.1.tgz", + "integrity": "sha512-RTBGWL5FWQcg9orDOCcp4LvItNzUPcyEU9bwaeJX0rJ1IQxzucC48Y0/sQLp/g6t99IQgAlGIaesJS+gTn7tVQ==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/malept" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/subscription/pkg/npm-.malept-cross-spawn-promise?utm_medium=referral&utm_source=npm_fund" + } + ], + "dependencies": { + "cross-spawn": "^7.0.1" + }, + "engines": { + "node": ">= 10" + } + }, + "node_modules/@npmcli/fs": { + "version": "1.1.1", + "license": "ISC", + "optional": true, + "dependencies": { + "@gar/promisify": "^1.0.1", + "semver": "^7.3.5" + } + }, + "node_modules/@npmcli/move-file": { + "version": "1.1.2", + "license": "MIT", + "optional": true, + "dependencies": { + "mkdirp": "^1.0.4", + "rimraf": "^3.0.2" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@sindresorhus/is": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz", + "integrity": "sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sindresorhus/is?sponsor=1" + } + }, + "node_modules/@szmarczak/http-timer": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-4.0.6.tgz", + "integrity": "sha512-4BAffykYOgO+5nzBWYwE3W90sBgLJoUPRWWcL8wlyiM8IB8ipJz3UMJ9KXQd1RKQXpKp8Tutn80HZtWsu2u76w==", + "dev": true, + "dependencies": { + "defer-to-connect": "^2.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@tootallnate/once": { + "version": "1.1.2", + "license": "MIT", + "optional": true, + "engines": { + "node": ">= 6" + } + }, + "node_modules/@types/cacheable-request": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.3.tgz", + "integrity": "sha512-IQ3EbTzGxIigb1I3qPZc1rWJnH0BmSKv5QYTalEwweFvyBDLSAe24zP0le/hyi7ecGfZVlIVAg4BZqb8WBwKqw==", + "dev": true, + "dependencies": { + "@types/http-cache-semantics": "*", + "@types/keyv": "^3.1.4", + "@types/node": "*", + "@types/responselike": "^1.0.0" + } + }, + "node_modules/@types/http-cache-semantics": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.4.tgz", + "integrity": "sha512-1m0bIFVc7eJWyve9S0RnuRgcQqF/Xd5QsUZAZeQFr1Q3/p9JWoQQEqmVy+DPTNpGXwhgIetAoYF8JSc33q29QA==", + "dev": true + }, + "node_modules/@types/keyv": { + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/@types/keyv/-/keyv-3.1.4.tgz", + "integrity": "sha512-BQ5aZNSCpj7D6K2ksrRCTmKRLEpnPvWDiLPfoGyhZ++8YtiK9d/3DBKPJgry359X/P1PfruyYwvnvwFjuEiEIg==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/node": { + "version": "20.12.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.7.tgz", + "integrity": "sha512-wq0cICSkRLVaf3UGLMGItu/PtdY7oaXaI/RVU+xliKVOtRna3PRY57ZDfztpDL0n11vfymMUnXv8QwYCO7L1wg==", + "dev": true, + "dependencies": { + "undici-types": "~5.26.4" + } + }, + "node_modules/@types/responselike": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.3.tgz", + "integrity": "sha512-H/+L+UkTV33uf49PH5pCAUBVPNj2nDBXTN+qS1dOwyyg24l3CcicicCA7ca+HMvJBZcFgl5r8e+RR6elsb4Lyw==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/yauzl": { + "version": "2.10.3", + "resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.10.3.tgz", + "integrity": "sha512-oJoftv0LSuaDZE3Le4DbKX+KS9G36NzOeSap90UIK0yMA/NhKJhqlSGtNDORNRaIbQfzjXDrQa0ytJ6mNRGz/Q==", + "dev": true, + "optional": true, + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@xmldom/xmldom": { + "version": "0.8.10", + "resolved": "https://registry.npmjs.org/@xmldom/xmldom/-/xmldom-0.8.10.tgz", + "integrity": "sha512-2WALfTl4xo2SkGCYRt6rDTFfk9R1czmBvUQy12gK2KuRKIpWEhcbbzy8EZXtz/jkRqHX8bFEc6FC1HjX4TUWYw==", + "dev": true, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/abbrev": { + "version": "1.1.1", + "devOptional": true, + "license": "ISC" + }, + "node_modules/agent-base": { + "version": "6.0.2", + "devOptional": true, + "license": "MIT", + "dependencies": { + "debug": "4" + }, + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/agentkeepalive": { + "version": "4.5.0", + "devOptional": true, + "license": "MIT", + "dependencies": { + "humanize-ms": "^1.2.1" + }, + "engines": { + "node": ">= 8.0.0" + } + }, + "node_modules/aggregate-error": { + "version": "3.1.0", + "devOptional": true, + "license": "MIT", + "dependencies": { + "clean-stack": "^2.0.0", + "indent-string": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/ansi-regex": { + "version": "5.0.1", + "devOptional": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/aproba": { + "version": "2.0.0", + "devOptional": true, + "license": "ISC" + }, + "node_modules/are-we-there-yet": { + "version": "3.0.1", + "devOptional": true, + "license": "ISC", + "dependencies": { + "delegates": "^1.0.0", + "readable-stream": "^3.6.0" + }, + "engines": { + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" + } + }, + "node_modules/at-least-node": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz", + "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==", + "dev": true, + "engines": { + "node": ">= 4.0.0" + } + }, + "node_modules/author-regex": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/author-regex/-/author-regex-1.0.0.tgz", + "integrity": "sha512-KbWgR8wOYRAPekEmMXrYYdc7BRyhn2Ftk7KWfMUnQ43hFdojWEFRxhhRUm3/OFEdPa1r0KAvTTg9YQK57xTe0g==", + "dev": true, + "engines": { + "node": ">=0.8" + } + }, + "node_modules/balanced-match": { + "version": "1.0.2", + "devOptional": true, + "license": "MIT" + }, + "node_modules/base64-js": { + "version": "1.5.1", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/bindings": { + "version": "1.5.0", + "license": "MIT", + "dependencies": { + "file-uri-to-path": "1.0.0" + } + }, + "node_modules/bl": { + "version": "4.1.0", + "license": "MIT", + "dependencies": { + "buffer": "^5.5.0", + "inherits": "^2.0.4", + "readable-stream": "^3.4.0" + } + }, + "node_modules/bluebird": { + "version": "3.7.2", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", + "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==", + "dev": true + }, + "node_modules/boolean": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/boolean/-/boolean-3.2.0.tgz", + "integrity": "sha512-d0II/GO9uf9lfUHH2BQsjxzRJZBdsjgsBiW4BvhWk/3qoKwQFjIDVN19PfX8F2D/r9PCMTtLWjYVCFrpeYUzsw==", + "dev": true, + "optional": true + }, + "node_modules/brace-expansion": { + "version": "1.1.11", + "devOptional": true, + "license": "MIT", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/buffer": { + "version": "5.7.1", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT", + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.1.13" + } + }, + "node_modules/buffer-crc32": { + "version": "0.2.13", + "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", + "integrity": "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==", + "dev": true, + "engines": { + "node": "*" + } + }, + "node_modules/buffer-equal": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/buffer-equal/-/buffer-equal-1.0.1.tgz", + "integrity": "sha512-QoV3ptgEaQpvVwbXdSO39iqPQTCxSF7A5U99AxbHYqUdCizL/lH2Z0A2y6nbZucxMEOtNyZfG2s6gsVugGpKkg==", + "dev": true, + "engines": { + "node": ">=0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/cacache": { + "version": "15.3.0", + "license": "ISC", + "optional": true, + "dependencies": { + "@npmcli/fs": "^1.0.0", + "@npmcli/move-file": "^1.0.1", + "chownr": "^2.0.0", + "fs-minipass": "^2.0.0", + "glob": "^7.1.4", + "infer-owner": "^1.0.4", + "lru-cache": "^6.0.0", + "minipass": "^3.1.1", + "minipass-collect": "^1.0.2", + "minipass-flush": "^1.0.5", + "minipass-pipeline": "^1.2.2", + "mkdirp": "^1.0.3", + "p-map": "^4.0.0", + "promise-inflight": "^1.0.1", + "rimraf": "^3.0.2", + "ssri": "^8.0.1", + "tar": "^6.0.2", + "unique-filename": "^1.1.1" + }, + "engines": { + "node": ">= 10" + } + }, + "node_modules/cacheable-lookup": { + "version": "5.0.4", + "resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-5.0.4.tgz", + "integrity": "sha512-2/kNscPhpcxrOigMZzbiWF7dz8ilhb/nIHU3EyZiXWXpeq/au8qJ8VhdftMkty3n7Gj6HIGalQG8oiBNB3AJgA==", + "dev": true, + "engines": { + "node": ">=10.6.0" + } + }, + "node_modules/cacheable-request": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-7.0.4.tgz", + "integrity": "sha512-v+p6ongsrp0yTGbJXjgxPow2+DL93DASP4kXCDKb8/bwRtt9OEF3whggkkDkGNzgcWy2XaF4a8nZglC7uElscg==", + "dev": true, + "dependencies": { + "clone-response": "^1.0.2", + "get-stream": "^5.1.0", + "http-cache-semantics": "^4.0.0", + "keyv": "^4.0.0", + "lowercase-keys": "^2.0.0", + "normalize-url": "^6.0.1", + "responselike": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/chownr": { + "version": "2.0.0", + "license": "ISC", + "engines": { + "node": ">=10" + } + }, + "node_modules/clean-stack": { + "version": "2.2.0", + "devOptional": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/cli-cursor": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", + "integrity": "sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==", + "dev": true, + "dependencies": { + "restore-cursor": "^3.1.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/cli-spinners": { + "version": "2.9.2", + "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.2.tgz", + "integrity": "sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==", + "dev": true, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/cliui": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", + "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", + "dev": true, + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.1", + "wrap-ansi": "^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/clone": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz", + "integrity": "sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg==", + "dev": true, + "engines": { + "node": ">=0.8" + } + }, + "node_modules/clone-response": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.3.tgz", + "integrity": "sha512-ROoL94jJH2dUVML2Y/5PEDNaSHgeOdSDicUyS7izcF63G6sTc/FTjLub4b8Il9S8S0beOfYt0TaA5qvFK+w0wA==", + "dev": true, + "dependencies": { + "mimic-response": "^1.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/clone-response/node_modules/mimic-response": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz", + "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "node_modules/color-support": { + "version": "1.1.3", + "devOptional": true, + "license": "ISC", + "bin": { + "color-support": "bin.js" + } + }, + "node_modules/commander": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-5.1.0.tgz", + "integrity": "sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg==", + "dev": true, + "engines": { + "node": ">= 6" + } + }, + "node_modules/compare-version": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/compare-version/-/compare-version-0.1.2.tgz", + "integrity": "sha512-pJDh5/4wrEnXX/VWRZvruAGHkzKdr46z11OlTPN+VrATlWWhSKewNCJ1futCO5C7eJB3nPMFZA1LeYtcFboZ2A==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/concat-map": { + "version": "0.0.1", + "devOptional": true, + "license": "MIT" + }, + "node_modules/console-control-strings": { + "version": "1.1.0", + "devOptional": true, + "license": "ISC" + }, + "node_modules/cross-spawn": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "dev": true, + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/cross-spawn-windows-exe": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/cross-spawn-windows-exe/-/cross-spawn-windows-exe-1.2.0.tgz", + "integrity": "sha512-mkLtJJcYbDCxEG7Js6eUnUNndWjyUZwJ3H7bErmmtOYU/Zb99DyUkpamuIZE0b3bhmJyZ7D90uS6f+CGxRRjOw==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/malept" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/subscription/pkg/npm-cross-spawn-windows-exe?utm_medium=referral&utm_source=npm_fund" + } + ], + "dependencies": { + "@malept/cross-spawn-promise": "^1.1.0", + "is-wsl": "^2.2.0", + "which": "^2.0.2" + }, + "engines": { + "node": ">= 10" + } + }, + "node_modules/debug": { + "version": "4.3.4", + "devOptional": true, + "license": "MIT", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/decompress-response": { + "version": "6.0.0", + "license": "MIT", + "dependencies": { + "mimic-response": "^3.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/deep-extend": { + "version": "0.6.0", + "license": "MIT", + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/defaults": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/defaults/-/defaults-1.0.4.tgz", + "integrity": "sha512-eFuaLoy/Rxalv2kr+lqMlUnrDWV+3j4pljOIJgLIhI058IQfWJ7vXhyEIHu+HtC738klGALYxOKDO0bQP3tg8A==", + "dev": true, + "dependencies": { + "clone": "^1.0.2" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/defer-to-connect": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-2.0.1.tgz", + "integrity": "sha512-4tvttepXG1VaYGrRibk5EwJd1t4udunSOVMdLSAL6mId1ix438oPwPZMALY41FCijukO1L0twNcGsdzS7dHgDg==", + "dev": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/define-data-property": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", + "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", + "dev": true, + "optional": true, + "dependencies": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "gopd": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/define-properties": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.1.tgz", + "integrity": "sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==", + "dev": true, + "optional": true, + "dependencies": { + "define-data-property": "^1.0.1", + "has-property-descriptors": "^1.0.0", + "object-keys": "^1.1.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/delegates": { + "version": "1.0.0", + "devOptional": true, + "license": "MIT" + }, + "node_modules/detect-libc": { + "version": "2.0.3", + "license": "Apache-2.0", + "engines": { + "node": ">=8" + } + }, + "node_modules/detect-node": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/detect-node/-/detect-node-2.1.0.tgz", + "integrity": "sha512-T0NIuQpnTvFDATNuHN5roPwSBG83rFsuO+MXXH9/3N1eFbn4wcPjttvjMLEPWJ0RGUYgQE7cGgS3tNxbqCGM7g==", + "dev": true, + "optional": true + }, + "node_modules/dir-compare": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/dir-compare/-/dir-compare-3.3.0.tgz", + "integrity": "sha512-J7/et3WlGUCxjdnD3HAAzQ6nsnc0WL6DD7WcwJb7c39iH1+AWfg+9OqzJNaI6PkBwBvm1mhZNL9iY/nRiZXlPg==", + "dev": true, + "dependencies": { + "buffer-equal": "^1.0.0", + "minimatch": "^3.0.4" + } + }, + "node_modules/electron": { + "version": "29.3.0", + "resolved": "https://registry.npmjs.org/electron/-/electron-29.3.0.tgz", + "integrity": "sha512-ZxFKm0/v48GSoBuO3DdnMlCYXefEUKUHLMsKxyXY4nZGgzbBKpF/X8haZa2paNj23CLfsCKBOtfc2vsEQiOOsA==", + "dev": true, + "hasInstallScript": true, + "dependencies": { + "@electron/get": "^2.0.0", + "@types/node": "^20.9.0", + "extract-zip": "^2.0.1" + }, + "bin": { + "electron": "cli.js" + }, + "engines": { + "node": ">= 12.20.55" + } + }, + "node_modules/electron-packager": { + "version": "17.1.2", + "resolved": "https://registry.npmjs.org/electron-packager/-/electron-packager-17.1.2.tgz", + "integrity": "sha512-XofXdikjYI7MVBcnXeoOvRR+yFFFHOLs3J7PF5KYQweigtgLshcH4W660PsvHr4lYZ03JBpLyEcUB8DzHZ+BNw==", + "deprecated": "Please use @electron/packager moving forward. There is no API change, just a package name change", + "dev": true, + "dependencies": { + "@electron/asar": "^3.2.1", + "@electron/get": "^2.0.0", + "@electron/notarize": "^1.2.3", + "@electron/osx-sign": "^1.0.5", + "@electron/universal": "^1.3.2", + "cross-spawn-windows-exe": "^1.2.0", + "debug": "^4.0.1", + "extract-zip": "^2.0.0", + "filenamify": "^4.1.0", + "fs-extra": "^11.1.0", + "galactus": "^1.0.0", + "get-package-info": "^1.0.0", + "junk": "^3.1.0", + "parse-author": "^2.0.0", + "plist": "^3.0.0", + "rcedit": "^3.0.1", + "resolve": "^1.1.6", + "semver": "^7.1.3", + "yargs-parser": "^21.1.1" + }, + "bin": { + "electron-packager": "bin/electron-packager.js" + }, + "engines": { + "node": ">= 14.17.5" + }, + "funding": { + "url": "https://github.com/electron/electron-packager?sponsor=1" + } + }, + "node_modules/electron-packager/node_modules/fs-extra": { + "version": "11.2.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", + "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=14.14" + } + }, + "node_modules/electron-packager/node_modules/jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dev": true, + "dependencies": { + "universalify": "^2.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, + "node_modules/electron-packager/node_modules/universalify": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", + "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", + "dev": true, + "engines": { + "node": ">= 10.0.0" + } + }, + "node_modules/electron-rebuild": { + "version": "3.2.9", + "resolved": "https://registry.npmjs.org/electron-rebuild/-/electron-rebuild-3.2.9.tgz", + "integrity": "sha512-FkEZNFViUem3P0RLYbZkUjC8LUFIK+wKq09GHoOITSJjfDAVQv964hwaNseTTWt58sITQX3/5fHNYcTefqaCWw==", + "deprecated": "Please use @electron/rebuild moving forward. There is no API change, just a package name change", + "dev": true, + "dependencies": { + "@malept/cross-spawn-promise": "^2.0.0", + "chalk": "^4.0.0", + "debug": "^4.1.1", + "detect-libc": "^2.0.1", + "fs-extra": "^10.0.0", + "got": "^11.7.0", + "lzma-native": "^8.0.5", + "node-abi": "^3.0.0", + "node-api-version": "^0.1.4", + "node-gyp": "^9.0.0", + "ora": "^5.1.0", + "semver": "^7.3.5", + "tar": "^6.0.5", + "yargs": "^17.0.1" + }, + "bin": { + "electron-rebuild": "lib/src/cli.js" + }, + "engines": { + "node": ">=12.13.0" + } + }, + "node_modules/electron-rebuild/node_modules/@malept/cross-spawn-promise": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@malept/cross-spawn-promise/-/cross-spawn-promise-2.0.0.tgz", + "integrity": "sha512-1DpKU0Z5ThltBwjNySMC14g0CkbyhCaz9FkhxqNsZI6uAPJXFS8cMXlBKo26FJ8ZuW6S9GCMcR9IO5k2X5/9Fg==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/malept" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/subscription/pkg/npm-.malept-cross-spawn-promise?utm_medium=referral&utm_source=npm_fund" + } + ], + "dependencies": { + "cross-spawn": "^7.0.1" + }, + "engines": { + "node": ">= 12.13.0" + } + }, + "node_modules/electron-rebuild/node_modules/@npmcli/fs": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/@npmcli/fs/-/fs-2.1.2.tgz", + "integrity": "sha512-yOJKRvohFOaLqipNtwYB9WugyZKhC/DZC4VYPmpaCzDBrA8YpK3qHZ8/HGscMnE4GqbkLNuVcCnxkeQEdGt6LQ==", + "dev": true, + "dependencies": { + "@gar/promisify": "^1.1.3", + "semver": "^7.3.5" + }, + "engines": { + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" + } + }, + "node_modules/electron-rebuild/node_modules/@npmcli/move-file": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@npmcli/move-file/-/move-file-2.0.1.tgz", + "integrity": "sha512-mJd2Z5TjYWq/ttPLLGqArdtnC74J6bOzg4rMDnN+p1xTacZ2yPRCk2y0oSWQtygLR9YVQXgOcONrwtnk3JupxQ==", + "deprecated": "This functionality has been moved to @npmcli/fs", + "dev": true, + "dependencies": { + "mkdirp": "^1.0.4", + "rimraf": "^3.0.2" + }, + "engines": { + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" + } + }, + "node_modules/electron-rebuild/node_modules/@tootallnate/once": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz", + "integrity": "sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A==", + "dev": true, + "engines": { + "node": ">= 10" + } + }, + "node_modules/electron-rebuild/node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/electron-rebuild/node_modules/cacache": { + "version": "16.1.3", + "resolved": "https://registry.npmjs.org/cacache/-/cacache-16.1.3.tgz", + "integrity": "sha512-/+Emcj9DAXxX4cwlLmRI9c166RuL3w30zp4R7Joiv2cQTtTtA+jeuCAjH3ZlGnYS3tKENSrKhAzVVP9GVyzeYQ==", + "dev": true, + "dependencies": { + "@npmcli/fs": "^2.1.0", + "@npmcli/move-file": "^2.0.0", + "chownr": "^2.0.0", + "fs-minipass": "^2.1.0", + "glob": "^8.0.1", + "infer-owner": "^1.0.4", + "lru-cache": "^7.7.1", + "minipass": "^3.1.6", + "minipass-collect": "^1.0.2", + "minipass-flush": "^1.0.5", + "minipass-pipeline": "^1.2.4", + "mkdirp": "^1.0.4", + "p-map": "^4.0.0", + "promise-inflight": "^1.0.1", + "rimraf": "^3.0.2", + "ssri": "^9.0.0", + "tar": "^6.1.11", + "unique-filename": "^2.0.0" + }, + "engines": { + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" + } + }, + "node_modules/electron-rebuild/node_modules/cacache/node_modules/glob": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", + "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", + "dev": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^5.0.1", + "once": "^1.3.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/electron-rebuild/node_modules/fs-extra": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", + "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/electron-rebuild/node_modules/http-proxy-agent": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-5.0.0.tgz", + "integrity": "sha512-n2hY8YdoRE1i7r6M0w9DIw5GgZN0G25P8zLCRQ8rjXtTU3vsNFBI/vWK/UIeE6g5MUUz6avwAPXmL6Fy9D/90w==", + "dev": true, + "dependencies": { + "@tootallnate/once": "2", + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/electron-rebuild/node_modules/jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dev": true, + "dependencies": { + "universalify": "^2.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, + "node_modules/electron-rebuild/node_modules/lru-cache": { + "version": "7.18.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz", + "integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==", + "dev": true, + "engines": { + "node": ">=12" + } + }, + "node_modules/electron-rebuild/node_modules/make-fetch-happen": { + "version": "10.2.1", + "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-10.2.1.tgz", + "integrity": "sha512-NgOPbRiaQM10DYXvN3/hhGVI2M5MtITFryzBGxHM5p4wnFxsVCbxkrBrDsk+EZ5OB4jEOT7AjDxtdF+KVEFT7w==", + "dev": true, + "dependencies": { + "agentkeepalive": "^4.2.1", + "cacache": "^16.1.0", + "http-cache-semantics": "^4.1.0", + "http-proxy-agent": "^5.0.0", + "https-proxy-agent": "^5.0.0", + "is-lambda": "^1.0.1", + "lru-cache": "^7.7.1", + "minipass": "^3.1.6", + "minipass-collect": "^1.0.2", + "minipass-fetch": "^2.0.3", + "minipass-flush": "^1.0.5", + "minipass-pipeline": "^1.2.4", + "negotiator": "^0.6.3", + "promise-retry": "^2.0.1", + "socks-proxy-agent": "^7.0.0", + "ssri": "^9.0.0" + }, + "engines": { + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" + } + }, + "node_modules/electron-rebuild/node_modules/minimatch": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", + "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/electron-rebuild/node_modules/minipass-fetch": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/minipass-fetch/-/minipass-fetch-2.1.2.tgz", + "integrity": "sha512-LT49Zi2/WMROHYoqGgdlQIZh8mLPZmOrN2NdJjMXxYe4nkN6FUyuPuOAOedNJDrx0IRGg9+4guZewtp8hE6TxA==", + "dev": true, + "dependencies": { + "minipass": "^3.1.6", + "minipass-sized": "^1.0.3", + "minizlib": "^2.1.2" + }, + "engines": { + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" + }, + "optionalDependencies": { + "encoding": "^0.1.13" + } + }, + "node_modules/electron-rebuild/node_modules/node-gyp": { + "version": "9.4.1", + "resolved": "https://registry.npmjs.org/node-gyp/-/node-gyp-9.4.1.tgz", + "integrity": "sha512-OQkWKbjQKbGkMf/xqI1jjy3oCTgMKJac58G2+bjZb3fza6gW2YrCSdMQYaoTb70crvE//Gngr4f0AgVHmqHvBQ==", + "dev": true, + "dependencies": { + "env-paths": "^2.2.0", + "exponential-backoff": "^3.1.1", + "glob": "^7.1.4", + "graceful-fs": "^4.2.6", + "make-fetch-happen": "^10.0.3", + "nopt": "^6.0.0", + "npmlog": "^6.0.0", + "rimraf": "^3.0.2", + "semver": "^7.3.5", + "tar": "^6.1.2", + "which": "^2.0.2" + }, + "bin": { + "node-gyp": "bin/node-gyp.js" + }, + "engines": { + "node": "^12.13 || ^14.13 || >=16" + } + }, + "node_modules/electron-rebuild/node_modules/nopt": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-6.0.0.tgz", + "integrity": "sha512-ZwLpbTgdhuZUnZzjd7nb1ZV+4DoiC6/sfiVKok72ym/4Tlf+DFdlHYmT2JPmcNNWV6Pi3SDf1kT+A4r9RTuT9g==", + "dev": true, + "dependencies": { + "abbrev": "^1.0.0" + }, + "bin": { + "nopt": "bin/nopt.js" + }, + "engines": { + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" + } + }, + "node_modules/electron-rebuild/node_modules/socks-proxy-agent": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-7.0.0.tgz", + "integrity": "sha512-Fgl0YPZ902wEsAyiQ+idGd1A7rSFx/ayC1CQVMw5P+EQx2V0SgpGtf6OKFhVjPflPUl9YMmEOnmfjCdMUsygww==", + "dev": true, + "dependencies": { + "agent-base": "^6.0.2", + "debug": "^4.3.3", + "socks": "^2.6.2" + }, + "engines": { + "node": ">= 10" + } + }, + "node_modules/electron-rebuild/node_modules/ssri": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/ssri/-/ssri-9.0.1.tgz", + "integrity": "sha512-o57Wcn66jMQvfHG1FlYbWeZWW/dHZhJXjpIcTfXldXEk5nz5lStPo3mK0OJQfGR3RbZUlbISexbljkJzuEj/8Q==", + "dev": true, + "dependencies": { + "minipass": "^3.1.1" + }, + "engines": { + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" + } + }, + "node_modules/electron-rebuild/node_modules/unique-filename": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/unique-filename/-/unique-filename-2.0.1.tgz", + "integrity": "sha512-ODWHtkkdx3IAR+veKxFV+VBkUMcN+FaqzUUd7IZzt+0zhDZFPFxhlqwPF3YQvMHx1TD0tdgYl+kuPnJ8E6ql7A==", + "dev": true, + "dependencies": { + "unique-slug": "^3.0.0" + }, + "engines": { + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" + } + }, + "node_modules/electron-rebuild/node_modules/unique-slug": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/unique-slug/-/unique-slug-3.0.0.tgz", + "integrity": "sha512-8EyMynh679x/0gqE9fT9oilG+qEt+ibFyqjuVTsZn1+CMxH+XLlpvr2UZx4nVcCwTpx81nICr2JQFkM+HPLq4w==", + "dev": true, + "dependencies": { + "imurmurhash": "^0.1.4" + }, + "engines": { + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" + } + }, + "node_modules/electron-rebuild/node_modules/universalify": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", + "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", + "dev": true, + "engines": { + "node": ">= 10.0.0" + } + }, + "node_modules/emoji-regex": { + "version": "8.0.0", + "devOptional": true, + "license": "MIT" + }, + "node_modules/encoding": { + "version": "0.1.13", + "license": "MIT", + "optional": true, + "dependencies": { + "iconv-lite": "^0.6.2" + } + }, + "node_modules/end-of-stream": { + "version": "1.4.4", + "license": "MIT", + "dependencies": { + "once": "^1.4.0" + } + }, + "node_modules/env-paths": { + "version": "2.2.1", + "devOptional": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, + "node_modules/err-code": { + "version": "2.0.3", + "devOptional": true, + "license": "MIT" + }, + "node_modules/error-ex": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", + "integrity": "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==", + "dev": true, + "dependencies": { + "is-arrayish": "^0.2.1" + } + }, + "node_modules/es-define-property": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", + "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", + "dev": true, + "optional": true, + "dependencies": { + "get-intrinsic": "^1.2.4" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "dev": true, + "optional": true, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es6-error": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/es6-error/-/es6-error-4.1.1.tgz", + "integrity": "sha512-Um/+FxMr9CISWh0bi5Zv0iOD+4cFh5qLeks1qhAopKVAJw3drgKbKySikp7wGhDL0HPeaja0P5ULZrxLkniUVg==", + "dev": true, + "optional": true + }, + "node_modules/escalade": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.2.tgz", + "integrity": "sha512-ErCHMCae19vR8vQGe50xIsVomy19rg6gFu3+r3jkEO46suLMWBksvVyoGgQV+jOfl84ZSOSlmv6Gxa89PmTGmA==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true, + "optional": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/expand-template": { + "version": "2.0.3", + "license": "(MIT OR WTFPL)", + "engines": { + "node": ">=6" + } + }, + "node_modules/exponential-backoff": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/exponential-backoff/-/exponential-backoff-3.1.1.tgz", + "integrity": "sha512-dX7e/LHVJ6W3DE1MHWi9S1EYzDESENfLrYohG2G++ovZrYOkm4Knwa0mc1cn84xJOR4KEU0WSchhLbd0UklbHw==", + "dev": true + }, + "node_modules/extract-zip": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-2.0.1.tgz", + "integrity": "sha512-GDhU9ntwuKyGXdZBUgTIe+vXnWj0fppUEtMDL0+idd5Sta8TGpHssn/eusA9mrPr9qNDym6SxAYZjNvCn/9RBg==", + "dev": true, + "dependencies": { + "debug": "^4.1.1", + "get-stream": "^5.1.0", + "yauzl": "^2.10.0" + }, + "bin": { + "extract-zip": "cli.js" + }, + "engines": { + "node": ">= 10.17.0" + }, + "optionalDependencies": { + "@types/yauzl": "^2.9.1" + } + }, + "node_modules/fd-slicer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz", + "integrity": "sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g==", + "dev": true, + "dependencies": { + "pend": "~1.2.0" + } + }, + "node_modules/file-uri-to-path": { + "version": "1.0.0", + "license": "MIT" + }, + "node_modules/filename-reserved-regex": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/filename-reserved-regex/-/filename-reserved-regex-2.0.0.tgz", + "integrity": "sha512-lc1bnsSr4L4Bdif8Xb/qrtokGbq5zlsms/CYH8PP+WtCkGNF65DPiQY8vG3SakEdRn8Dlnm+gW/qWKKjS5sZzQ==", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/filenamify": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/filenamify/-/filenamify-4.3.0.tgz", + "integrity": "sha512-hcFKyUG57yWGAzu1CMt/dPzYZuv+jAJUT85bL8mrXvNe6hWj6yEHEc4EdcgiA6Z3oi1/9wXJdZPXF2dZNgwgOg==", + "dev": true, + "dependencies": { + "filename-reserved-regex": "^2.0.0", + "strip-outer": "^1.0.1", + "trim-repeated": "^1.0.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/find-up": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", + "integrity": "sha512-NWzkk0jSJtTt08+FBFMvXoeZnOJD+jTtsRmBYbAIzJdX6l7dLgR7CTubCM5/eDdPUBvLCeVasP1brfVR/9/EZQ==", + "dev": true, + "dependencies": { + "locate-path": "^2.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/flora-colossus": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/flora-colossus/-/flora-colossus-2.0.0.tgz", + "integrity": "sha512-dz4HxH6pOvbUzZpZ/yXhafjbR2I8cenK5xL0KtBFb7U2ADsR+OwXifnxZjij/pZWF775uSCMzWVd+jDik2H2IA==", + "dev": true, + "dependencies": { + "debug": "^4.3.4", + "fs-extra": "^10.1.0" + }, + "engines": { + "node": ">= 12" + } + }, + "node_modules/flora-colossus/node_modules/fs-extra": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", + "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/flora-colossus/node_modules/jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dev": true, + "dependencies": { + "universalify": "^2.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, + "node_modules/flora-colossus/node_modules/universalify": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", + "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", + "dev": true, + "engines": { + "node": ">= 10.0.0" + } + }, + "node_modules/fs-constants": { + "version": "1.0.0", + "license": "MIT" + }, + "node_modules/fs-extra": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", + "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + }, + "engines": { + "node": ">=6 <7 || >=8" + } + }, + "node_modules/fs-minipass": { + "version": "2.1.0", + "license": "ISC", + "dependencies": { + "minipass": "^3.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/fs.realpath": { + "version": "1.0.0", + "devOptional": true, + "license": "ISC" + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/galactus": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/galactus/-/galactus-1.0.0.tgz", + "integrity": "sha512-R1fam6D4CyKQGNlvJne4dkNF+PvUUl7TAJInvTGa9fti9qAv95quQz29GXapA4d8Ec266mJJxFVh82M4GIIGDQ==", + "dev": true, + "dependencies": { + "debug": "^4.3.4", + "flora-colossus": "^2.0.0", + "fs-extra": "^10.1.0" + }, + "engines": { + "node": ">= 12" + } + }, + "node_modules/galactus/node_modules/fs-extra": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", + "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/galactus/node_modules/jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "dev": true, + "dependencies": { + "universalify": "^2.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, + "node_modules/galactus/node_modules/universalify": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", + "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", + "dev": true, + "engines": { + "node": ">= 10.0.0" + } + }, + "node_modules/gauge": { + "version": "4.0.4", + "devOptional": true, + "license": "ISC", + "dependencies": { + "aproba": "^1.0.3 || ^2.0.0", + "color-support": "^1.1.3", + "console-control-strings": "^1.1.0", + "has-unicode": "^2.0.1", + "signal-exit": "^3.0.7", + "string-width": "^4.2.3", + "strip-ansi": "^6.0.1", + "wide-align": "^1.1.5" + }, + "engines": { + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" + } + }, + "node_modules/get-caller-file": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", + "dev": true, + "engines": { + "node": "6.* || 8.* || >= 10.*" + } + }, + "node_modules/get-intrinsic": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", + "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", + "dev": true, + "optional": true, + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "has-proto": "^1.0.1", + "has-symbols": "^1.0.3", + "hasown": "^2.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-package-info": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/get-package-info/-/get-package-info-1.0.0.tgz", + "integrity": "sha512-SCbprXGAPdIhKAXiG+Mk6yeoFH61JlYunqdFQFHDtLjJlDjFf6x07dsS8acO+xWt52jpdVo49AlVDnUVK1sDNw==", + "dev": true, + "dependencies": { + "bluebird": "^3.1.1", + "debug": "^2.2.0", + "lodash.get": "^4.0.0", + "read-pkg-up": "^2.0.0" + }, + "engines": { + "node": ">= 4.0" + } + }, + "node_modules/get-package-info/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/get-package-info/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "dev": true + }, + "node_modules/get-stream": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz", + "integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==", + "dev": true, + "dependencies": { + "pump": "^3.0.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/github-from-package": { + "version": "0.0.0", + "license": "MIT" + }, + "node_modules/glob": { + "version": "7.2.3", + "devOptional": true, + "license": "ISC", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/global-agent": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/global-agent/-/global-agent-3.0.0.tgz", + "integrity": "sha512-PT6XReJ+D07JvGoxQMkT6qji/jVNfX/h364XHZOWeRzy64sSFr+xJ5OX7LI3b4MPQzdL4H8Y8M0xzPpsVMwA8Q==", + "dev": true, + "optional": true, + "dependencies": { + "boolean": "^3.0.1", + "es6-error": "^4.1.1", + "matcher": "^3.0.0", + "roarr": "^2.15.3", + "semver": "^7.3.2", + "serialize-error": "^7.0.1" + }, + "engines": { + "node": ">=10.0" + } + }, + "node_modules/globalthis": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/globalthis/-/globalthis-1.0.3.tgz", + "integrity": "sha512-sFdI5LyBiNTHjRd7cGPWapiHWMOXKyuBNX/cWJ3NfzrZQVa8GI/8cofCl74AOVqq9W5kNmguTIzJ/1s2gyI9wA==", + "dev": true, + "optional": true, + "dependencies": { + "define-properties": "^1.1.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/gopd": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", + "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", + "dev": true, + "optional": true, + "dependencies": { + "get-intrinsic": "^1.1.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/got": { + "version": "11.8.6", + "resolved": "https://registry.npmjs.org/got/-/got-11.8.6.tgz", + "integrity": "sha512-6tfZ91bOr7bOXnK7PRDCGBLa1H4U080YHNaAQ2KsMGlLEzRbk44nsZF2E1IeRc3vtJHPVbKCYgdFbaGO2ljd8g==", + "dev": true, + "dependencies": { + "@sindresorhus/is": "^4.0.0", + "@szmarczak/http-timer": "^4.0.5", + "@types/cacheable-request": "^6.0.1", + "@types/responselike": "^1.0.0", + "cacheable-lookup": "^5.0.3", + "cacheable-request": "^7.0.2", + "decompress-response": "^6.0.0", + "http2-wrapper": "^1.0.0-beta.5.2", + "lowercase-keys": "^2.0.0", + "p-cancelable": "^2.0.0", + "responselike": "^2.0.0" + }, + "engines": { + "node": ">=10.19.0" + }, + "funding": { + "url": "https://github.com/sindresorhus/got?sponsor=1" + } + }, + "node_modules/graceful-fs": { + "version": "4.2.11", + "devOptional": true, + "license": "ISC" + }, + "node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/has-property-descriptors": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", + "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", + "dev": true, + "optional": true, + "dependencies": { + "es-define-property": "^1.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-proto": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz", + "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==", + "dev": true, + "optional": true, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "dev": true, + "optional": true, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-unicode": { + "version": "2.0.1", + "devOptional": true, + "license": "ISC" + }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "dev": true, + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/hosted-git-info": { + "version": "2.8.9", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", + "integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==", + "dev": true + }, + "node_modules/http-cache-semantics": { + "version": "4.1.1", + "devOptional": true, + "license": "BSD-2-Clause" + }, + "node_modules/http-proxy-agent": { + "version": "4.0.1", + "license": "MIT", + "optional": true, + "dependencies": { + "@tootallnate/once": "1", + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/http2-wrapper": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/http2-wrapper/-/http2-wrapper-1.0.3.tgz", + "integrity": "sha512-V+23sDMr12Wnz7iTcDeJr3O6AIxlnvT/bmaAAAP/Xda35C90p9599p0F1eHR/N1KILWSoWVAiOMFjBBXaXSMxg==", + "dev": true, + "dependencies": { + "quick-lru": "^5.1.1", + "resolve-alpn": "^1.0.0" + }, + "engines": { + "node": ">=10.19.0" + } + }, + "node_modules/https-proxy-agent": { + "version": "5.0.1", + "devOptional": true, + "license": "MIT", + "dependencies": { + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/humanize-ms": { + "version": "1.2.1", + "devOptional": true, + "license": "MIT", + "dependencies": { + "ms": "^2.0.0" + } + }, + "node_modules/iconv-lite": { + "version": "0.6.3", + "license": "MIT", + "optional": true, + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/ieee754": { + "version": "1.2.1", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "BSD-3-Clause" + }, + "node_modules/imurmurhash": { + "version": "0.1.4", + "devOptional": true, + "license": "MIT", + "engines": { + "node": ">=0.8.19" + } + }, + "node_modules/indent-string": { + "version": "4.0.0", + "devOptional": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/infer-owner": { + "version": "1.0.4", + "devOptional": true, + "license": "ISC" + }, + "node_modules/inflight": { + "version": "1.0.6", + "devOptional": true, + "license": "ISC", + "dependencies": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "license": "ISC" + }, + "node_modules/ini": { + "version": "1.3.8", + "license": "ISC" + }, + "node_modules/ip-address": { + "version": "9.0.5", + "devOptional": true, + "license": "MIT", + "dependencies": { + "jsbn": "1.1.0", + "sprintf-js": "^1.1.3" + }, + "engines": { + "node": ">= 12" + } + }, + "node_modules/is-arrayish": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", + "integrity": "sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==", + "dev": true + }, + "node_modules/is-core-module": { + "version": "2.13.1", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.13.1.tgz", + "integrity": "sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==", + "dev": true, + "dependencies": { + "hasown": "^2.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-docker": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz", + "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==", + "dev": true, + "bin": { + "is-docker": "cli.js" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "devOptional": true, + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/is-interactive": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-interactive/-/is-interactive-1.0.0.tgz", + "integrity": "sha512-2HvIEKRoqS62guEC+qBjpvRubdX910WCMuJTZ+I9yvqKU2/12eSL549HMwtabb4oupdj2sMP50k+XJfB/8JE6w==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/is-lambda": { + "version": "1.0.1", + "devOptional": true, + "license": "MIT" + }, + "node_modules/is-unicode-supported": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz", + "integrity": "sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/is-wsl": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", + "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", + "dev": true, + "dependencies": { + "is-docker": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/isbinaryfile": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/isbinaryfile/-/isbinaryfile-4.0.10.tgz", + "integrity": "sha512-iHrqe5shvBUcFbmZq9zOQHBoeOhZJu6RQGrDpBgenUm/Am+F3JM2MgQj+rK3Z601fzrL5gLZWtAPH2OBaSVcyw==", + "dev": true, + "engines": { + "node": ">= 8.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/gjtorikian/" + } + }, + "node_modules/isexe": { + "version": "2.0.0", + "devOptional": true, + "license": "ISC" + }, + "node_modules/jsbn": { + "version": "1.1.0", + "devOptional": true, + "license": "MIT" + }, + "node_modules/json-buffer": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", + "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==", + "dev": true + }, + "node_modules/json-stringify-safe": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", + "integrity": "sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==", + "dev": true, + "optional": true + }, + "node_modules/jsonfile": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", + "integrity": "sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==", + "dev": true, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, + "node_modules/junk": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/junk/-/junk-3.1.0.tgz", + "integrity": "sha512-pBxcB3LFc8QVgdggvZWyeys+hnrNWg4OcZIU/1X59k5jQdLBlCsYGRQaz234SqoRLTCgMH00fY0xRJH+F9METQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/keyv": { + "version": "4.5.4", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", + "integrity": "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==", + "dev": true, + "dependencies": { + "json-buffer": "3.0.1" + } + }, + "node_modules/libprisbeam": { + "version": "2.3.3", + "resolved": "git+https://source.equestria.dev/equestria.dev/libprisbeam.git/#9e6e5d276fa83b5424c69be2691ad94c0ccebd03", + "hasInstallScript": true + }, + "node_modules/load-json-file": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz", + "integrity": "sha512-3p6ZOGNbiX4CdvEd1VcE6yi78UrGNpjHO33noGwHCnT/o2fyllJDepsm8+mFFv/DvtwFHht5HIHSyOy5a+ChVQ==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.1.2", + "parse-json": "^2.2.0", + "pify": "^2.0.0", + "strip-bom": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/locate-path": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", + "integrity": "sha512-NCI2kiDkyR7VeEKm27Kda/iQHyKJe1Bu0FlTbYp3CqJu+9IFe9bLyAjMxf5ZDDbEg+iMPzB5zYyUTSm8wVTKmA==", + "dev": true, + "dependencies": { + "p-locate": "^2.0.0", + "path-exists": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/lodash.get": { + "version": "4.4.2", + "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz", + "integrity": "sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==", + "dev": true + }, + "node_modules/log-symbols": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", + "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==", + "dev": true, + "dependencies": { + "chalk": "^4.1.0", + "is-unicode-supported": "^0.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/lowercase-keys": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz", + "integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/lru-cache": { + "version": "6.0.0", + "license": "ISC", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/lzma-native": { + "version": "8.0.6", + "resolved": "https://registry.npmjs.org/lzma-native/-/lzma-native-8.0.6.tgz", + "integrity": "sha512-09xfg67mkL2Lz20PrrDeNYZxzeW7ADtpYFbwSQh9U8+76RIzx5QsJBMy8qikv3hbUPfpy6hqwxt6FcGK81g9AA==", + "dev": true, + "hasInstallScript": true, + "dependencies": { + "node-addon-api": "^3.1.0", + "node-gyp-build": "^4.2.1", + "readable-stream": "^3.6.0" + }, + "bin": { + "lzmajs": "bin/lzmajs" + }, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/lzma-native/node_modules/node-addon-api": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.2.1.tgz", + "integrity": "sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A==", + "dev": true + }, + "node_modules/make-fetch-happen": { + "version": "9.1.0", + "license": "ISC", + "optional": true, + "dependencies": { + "agentkeepalive": "^4.1.3", + "cacache": "^15.2.0", + "http-cache-semantics": "^4.1.0", + "http-proxy-agent": "^4.0.1", + "https-proxy-agent": "^5.0.0", + "is-lambda": "^1.0.1", + "lru-cache": "^6.0.0", + "minipass": "^3.1.3", + "minipass-collect": "^1.0.2", + "minipass-fetch": "^1.3.2", + "minipass-flush": "^1.0.5", + "minipass-pipeline": "^1.2.4", + "negotiator": "^0.6.2", + "promise-retry": "^2.0.1", + "socks-proxy-agent": "^6.0.0", + "ssri": "^8.0.0" + }, + "engines": { + "node": ">= 10" + } + }, + "node_modules/matcher": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/matcher/-/matcher-3.0.0.tgz", + "integrity": "sha512-OkeDaAZ/bQCxeFAozM55PKcKU0yJMPGifLwV4Qgjitu+5MoAfSQN4lsLJeXZ1b8w0x+/Emda6MZgXS1jvsapng==", + "dev": true, + "optional": true, + "dependencies": { + "escape-string-regexp": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/mimic-fn": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", + "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/mimic-response": { + "version": "3.1.0", + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/minimatch": { + "version": "3.1.2", + "devOptional": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/minimist": { + "version": "1.2.8", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/minipass": { + "version": "3.3.6", + "license": "ISC", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/minipass-collect": { + "version": "1.0.2", + "devOptional": true, + "license": "ISC", + "dependencies": { + "minipass": "^3.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/minipass-fetch": { + "version": "1.4.1", + "license": "MIT", + "optional": true, + "dependencies": { + "minipass": "^3.1.0", + "minipass-sized": "^1.0.3", + "minizlib": "^2.0.0" + }, + "engines": { + "node": ">=8" + }, + "optionalDependencies": { + "encoding": "^0.1.12" + } + }, + "node_modules/minipass-flush": { + "version": "1.0.5", + "devOptional": true, + "license": "ISC", + "dependencies": { + "minipass": "^3.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/minipass-pipeline": { + "version": "1.2.4", + "devOptional": true, + "license": "ISC", + "dependencies": { + "minipass": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/minipass-sized": { + "version": "1.0.3", + "devOptional": true, + "license": "ISC", + "dependencies": { + "minipass": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/minizlib": { + "version": "2.1.2", + "license": "MIT", + "dependencies": { + "minipass": "^3.0.0", + "yallist": "^4.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/mkdirp": { + "version": "1.0.4", + "license": "MIT", + "bin": { + "mkdirp": "bin/cmd.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/mkdirp-classic": { + "version": "0.5.3", + "license": "MIT" + }, + "node_modules/ms": { + "version": "2.1.2", + "devOptional": true, + "license": "MIT" + }, + "node_modules/napi-build-utils": { + "version": "1.0.2", + "license": "MIT" + }, + "node_modules/negotiator": { + "version": "0.6.3", + "devOptional": true, + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/node-abi": { + "version": "3.57.0", + "license": "MIT", + "dependencies": { + "semver": "^7.3.5" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/node-addon-api": { + "version": "7.1.0", + "license": "MIT", + "engines": { + "node": "^16 || ^18 || >= 20" + } + }, + "node_modules/node-api-version": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/node-api-version/-/node-api-version-0.1.4.tgz", + "integrity": "sha512-KGXihXdUChwJAOHO53bv9/vXcLmdUsZ6jIptbvYvkpKfth+r7jw44JkVxQFA3kX5nQjzjmGu1uAu/xNNLNlI5g==", + "dev": true, + "dependencies": { + "semver": "^7.3.5" + } + }, + "node_modules/node-gyp": { + "version": "8.4.1", + "license": "MIT", + "optional": true, + "dependencies": { + "env-paths": "^2.2.0", + "glob": "^7.1.4", + "graceful-fs": "^4.2.6", + "make-fetch-happen": "^9.1.0", + "nopt": "^5.0.0", + "npmlog": "^6.0.0", + "rimraf": "^3.0.2", + "semver": "^7.3.5", + "tar": "^6.1.2", + "which": "^2.0.2" + }, + "bin": { + "node-gyp": "bin/node-gyp.js" + }, + "engines": { + "node": ">= 10.12.0" + } + }, + "node_modules/node-gyp-build": { + "version": "4.8.0", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.0.tgz", + "integrity": "sha512-u6fs2AEUljNho3EYTJNBfImO5QTo/J/1Etd+NVdCj7qWKUSN/bSLkZwhDv7I+w/MSC6qJ4cknepkAYykDdK8og==", + "dev": true, + "bin": { + "node-gyp-build": "bin.js", + "node-gyp-build-optional": "optional.js", + "node-gyp-build-test": "build-test.js" + } + }, + "node_modules/nopt": { + "version": "5.0.0", + "license": "ISC", + "optional": true, + "dependencies": { + "abbrev": "1" + }, + "bin": { + "nopt": "bin/nopt.js" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/normalize-package-data": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", + "integrity": "sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==", + "dev": true, + "dependencies": { + "hosted-git-info": "^2.1.4", + "resolve": "^1.10.0", + "semver": "2 || 3 || 4 || 5", + "validate-npm-package-license": "^3.0.1" + } + }, + "node_modules/normalize-package-data/node_modules/semver": { + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", + "dev": true, + "bin": { + "semver": "bin/semver" + } + }, + "node_modules/normalize-url": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz", + "integrity": "sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/npmlog": { + "version": "6.0.2", + "devOptional": true, + "license": "ISC", + "dependencies": { + "are-we-there-yet": "^3.0.0", + "console-control-strings": "^1.1.0", + "gauge": "^4.0.3", + "set-blocking": "^2.0.0" + }, + "engines": { + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" + } + }, + "node_modules/object-keys": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", + "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", + "dev": true, + "optional": true, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/once": { + "version": "1.4.0", + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/onetime": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", + "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", + "dev": true, + "dependencies": { + "mimic-fn": "^2.1.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/ora": { + "version": "5.4.1", + "resolved": "https://registry.npmjs.org/ora/-/ora-5.4.1.tgz", + "integrity": "sha512-5b6Y85tPxZZ7QytO+BQzysW31HJku27cRIlkbAXaNx+BdcVi+LlRFmVXzeF6a7JCwJpyw5c4b+YSVImQIrBpuQ==", + "dev": true, + "dependencies": { + "bl": "^4.1.0", + "chalk": "^4.1.0", + "cli-cursor": "^3.1.0", + "cli-spinners": "^2.5.0", + "is-interactive": "^1.0.0", + "is-unicode-supported": "^0.1.0", + "log-symbols": "^4.1.0", + "strip-ansi": "^6.0.0", + "wcwidth": "^1.0.1" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-cancelable": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.1.1.tgz", + "integrity": "sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/p-limit": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", + "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==", + "dev": true, + "dependencies": { + "p-try": "^1.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/p-locate": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", + "integrity": "sha512-nQja7m7gSKuewoVRen45CtVfODR3crN3goVQ0DDZ9N3yHxgpkuBhZqsaiotSQRrADUrne346peY7kT3TSACykg==", + "dev": true, + "dependencies": { + "p-limit": "^1.1.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/p-map": { + "version": "4.0.0", + "devOptional": true, + "license": "MIT", + "dependencies": { + "aggregate-error": "^3.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/p-try": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz", + "integrity": "sha512-U1etNYuMJoIz3ZXSrrySFjsXQTWOx2/jdi86L+2pRvph/qMKL6sbcCYdH23fqsbm8TH2Gn0OybpT4eSFlCVHww==", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/parse-author": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/parse-author/-/parse-author-2.0.0.tgz", + "integrity": "sha512-yx5DfvkN8JsHL2xk2Os9oTia467qnvRgey4ahSm2X8epehBLx/gWLcy5KI+Y36ful5DzGbCS6RazqZGgy1gHNw==", + "dev": true, + "dependencies": { + "author-regex": "^1.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/parse-json": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-2.2.0.tgz", + "integrity": "sha512-QR/GGaKCkhwk1ePQNYDRKYZ3mwU9ypsKhB0XyFnLQdomyEqk3e8wpW3V5Jp88zbxK4n5ST1nqo+g9juTpownhQ==", + "dev": true, + "dependencies": { + "error-ex": "^1.2.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/path-exists": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", + "integrity": "sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/path-is-absolute": { + "version": "1.0.1", + "devOptional": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/path-parse": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", + "dev": true + }, + "node_modules/path-type": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-2.0.0.tgz", + "integrity": "sha512-dUnb5dXUf+kzhC/W/F4e5/SkluXIFf5VUHolW1Eg1irn1hGWjPGdsRcvYJ1nD6lhk8Ir7VM0bHJKsYTx8Jx9OQ==", + "dev": true, + "dependencies": { + "pify": "^2.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/pend": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", + "integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==", + "dev": true + }, + "node_modules/pify": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/pify/-/pify-2.3.0.tgz", + "integrity": "sha512-udgsAY+fTnvv7kI7aaxbqwWNb0AHiB0qBO89PZKPkoTmGOgdbrHDKD+0B2X4uTfJ/FT1R09r9gTsjUjNJotuog==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/plist": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/plist/-/plist-3.1.0.tgz", + "integrity": "sha512-uysumyrvkUX0rX/dEVqt8gC3sTBzd4zoWfLeS29nb53imdaXVvLINYXTI2GNqzaMuvacNx4uJQ8+b3zXR0pkgQ==", + "dev": true, + "dependencies": { + "@xmldom/xmldom": "^0.8.8", + "base64-js": "^1.5.1", + "xmlbuilder": "^15.1.1" + }, + "engines": { + "node": ">=10.4.0" + } + }, + "node_modules/prebuild-install": { + "version": "7.1.2", + "license": "MIT", + "dependencies": { + "detect-libc": "^2.0.0", + "expand-template": "^2.0.3", + "github-from-package": "0.0.0", + "minimist": "^1.2.3", + "mkdirp-classic": "^0.5.3", + "napi-build-utils": "^1.0.1", + "node-abi": "^3.3.0", + "pump": "^3.0.0", + "rc": "^1.2.7", + "simple-get": "^4.0.0", + "tar-fs": "^2.0.0", + "tunnel-agent": "^0.6.0" + }, + "bin": { + "prebuild-install": "bin.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/progress": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", + "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", + "dev": true, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/promise-inflight": { + "version": "1.0.1", + "devOptional": true, + "license": "ISC" + }, + "node_modules/promise-retry": { + "version": "2.0.1", + "devOptional": true, + "license": "MIT", + "dependencies": { + "err-code": "^2.0.2", + "retry": "^0.12.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/pump": { + "version": "3.0.0", + "license": "MIT", + "dependencies": { + "end-of-stream": "^1.1.0", + "once": "^1.3.1" + } + }, + "node_modules/quick-lru": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-5.1.1.tgz", + "integrity": "sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/rc": { + "version": "1.2.8", + "license": "(BSD-2-Clause OR MIT OR Apache-2.0)", + "dependencies": { + "deep-extend": "^0.6.0", + "ini": "~1.3.0", + "minimist": "^1.2.0", + "strip-json-comments": "~2.0.1" + }, + "bin": { + "rc": "cli.js" + } + }, + "node_modules/rcedit": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/rcedit/-/rcedit-3.1.0.tgz", + "integrity": "sha512-WRlRdY1qZbu1L11DklT07KuHfRk42l0NFFJdaExELEu4fEQ982bP5Z6OWGPj/wLLIuKRQDCxZJGAwoFsxhZhNA==", + "dev": true, + "dependencies": { + "cross-spawn-windows-exe": "^1.1.0" + }, + "engines": { + "node": ">= 10.0.0" + } + }, + "node_modules/read-pkg": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-2.0.0.tgz", + "integrity": "sha512-eFIBOPW7FGjzBuk3hdXEuNSiTZS/xEMlH49HxMyzb0hyPfu4EhVjT2DH32K1hSSmVq4sebAWnZuuY5auISUTGA==", + "dev": true, + "dependencies": { + "load-json-file": "^2.0.0", + "normalize-package-data": "^2.3.2", + "path-type": "^2.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/read-pkg-up": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-2.0.0.tgz", + "integrity": "sha512-1orxQfbWGUiTn9XsPlChs6rLie/AV9jwZTGmu2NZw/CUDJQchXJFYE0Fq5j7+n558T1JhDWLdhyd1Zj+wLY//w==", + "dev": true, + "dependencies": { + "find-up": "^2.0.0", + "read-pkg": "^2.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/readable-stream": { + "version": "3.6.2", + "license": "MIT", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/require-directory": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/resolve": { + "version": "1.22.8", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", + "integrity": "sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==", + "dev": true, + "dependencies": { + "is-core-module": "^2.13.0", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + }, + "bin": { + "resolve": "bin/resolve" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/resolve-alpn": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/resolve-alpn/-/resolve-alpn-1.2.1.tgz", + "integrity": "sha512-0a1F4l73/ZFZOakJnQ3FvkJ2+gSTQWz/r2KE5OdDY0TxPm5h4GkqkWWfM47T7HsbnOtcJVEF4epCVy6u7Q3K+g==", + "dev": true + }, + "node_modules/responselike": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/responselike/-/responselike-2.0.1.tgz", + "integrity": "sha512-4gl03wn3hj1HP3yzgdI7d3lCkF95F21Pz4BPGvKHinyQzALR5CapwC8yIi0Rh58DEMQ/SguC03wFj2k0M/mHhw==", + "dev": true, + "dependencies": { + "lowercase-keys": "^2.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/restore-cursor": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-3.1.0.tgz", + "integrity": "sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA==", + "dev": true, + "dependencies": { + "onetime": "^5.1.0", + "signal-exit": "^3.0.2" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/retry": { + "version": "0.12.0", + "devOptional": true, + "license": "MIT", + "engines": { + "node": ">= 4" + } + }, + "node_modules/rimraf": { + "version": "3.0.2", + "devOptional": true, + "license": "ISC", + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/roarr": { + "version": "2.15.4", + "resolved": "https://registry.npmjs.org/roarr/-/roarr-2.15.4.tgz", + "integrity": "sha512-CHhPh+UNHD2GTXNYhPWLnU8ONHdI+5DI+4EYIAOaiD63rHeYlZvyh8P+in5999TTSFgUYuKUAjzRI4mdh/p+2A==", + "dev": true, + "optional": true, + "dependencies": { + "boolean": "^3.0.1", + "detect-node": "^2.0.4", + "globalthis": "^1.0.1", + "json-stringify-safe": "^5.0.1", + "semver-compare": "^1.0.0", + "sprintf-js": "^1.1.2" + }, + "engines": { + "node": ">=8.0" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "license": "MIT", + "optional": true + }, + "node_modules/semver": { + "version": "7.6.0", + "license": "ISC", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/semver-compare": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/semver-compare/-/semver-compare-1.0.0.tgz", + "integrity": "sha512-YM3/ITh2MJ5MtzaM429anh+x2jiLVjqILF4m4oyQB18W7Ggea7BfqdH/wGMK7dDiMghv/6WG7znWMwUDzJiXow==", + "dev": true, + "optional": true + }, + "node_modules/serialize-error": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/serialize-error/-/serialize-error-7.0.1.tgz", + "integrity": "sha512-8I8TjW5KMOKsZQTvoxjuSIa7foAwPWGOts+6o7sgjz41/qMD9VQHEDxi6PBvK2l0MXUmqZyNpUK+T2tQaaElvw==", + "dev": true, + "optional": true, + "dependencies": { + "type-fest": "^0.13.1" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/set-blocking": { + "version": "2.0.0", + "devOptional": true, + "license": "ISC" + }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/signal-exit": { + "version": "3.0.7", + "devOptional": true, + "license": "ISC" + }, + "node_modules/simple-concat": { + "version": "1.0.1", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" + }, + "node_modules/simple-get": { + "version": "4.0.1", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT", + "dependencies": { + "decompress-response": "^6.0.0", + "once": "^1.3.1", + "simple-concat": "^1.0.0" + } + }, + "node_modules/smart-buffer": { + "version": "4.2.0", + "devOptional": true, + "license": "MIT", + "engines": { + "node": ">= 6.0.0", + "npm": ">= 3.0.0" + } + }, + "node_modules/socks": { + "version": "2.8.1", + "devOptional": true, + "license": "MIT", + "dependencies": { + "ip-address": "^9.0.5", + "smart-buffer": "^4.2.0" + }, + "engines": { + "node": ">= 10.0.0", + "npm": ">= 3.0.0" + } + }, + "node_modules/socks-proxy-agent": { + "version": "6.2.1", + "license": "MIT", + "optional": true, + "dependencies": { + "agent-base": "^6.0.2", + "debug": "^4.3.3", + "socks": "^2.6.2" + }, + "engines": { + "node": ">= 10" + } + }, + "node_modules/spdx-correct": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.2.0.tgz", + "integrity": "sha512-kN9dJbvnySHULIluDHy32WHRUu3Og7B9sbY7tsFLctQkIqnMh3hErYgdMjTYuqmcXX+lK5T1lnUt3G7zNswmZA==", + "dev": true, + "dependencies": { + "spdx-expression-parse": "^3.0.0", + "spdx-license-ids": "^3.0.0" + } + }, + "node_modules/spdx-exceptions": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.5.0.tgz", + "integrity": "sha512-PiU42r+xO4UbUS1buo3LPJkjlO7430Xn5SVAhdpzzsPHsjbYVflnnFdATgabnLude+Cqu25p6N+g2lw/PFsa4w==", + "dev": true + }, + "node_modules/spdx-expression-parse": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.1.tgz", + "integrity": "sha512-cbqHunsQWnJNE6KhVSMsMeH5H/L9EpymbzqTQ3uLwNCLZ1Q481oWaofqH7nO6V07xlXwY6PhQdQ2IedWx/ZK4Q==", + "dev": true, + "dependencies": { + "spdx-exceptions": "^2.1.0", + "spdx-license-ids": "^3.0.0" + } + }, + "node_modules/spdx-license-ids": { + "version": "3.0.17", + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.17.tgz", + "integrity": "sha512-sh8PWc/ftMqAAdFiBu6Fy6JUOYjqDJBJvIhpfDMyHrr0Rbp5liZqd4TjtQ/RgfLjKFZb+LMx5hpml5qOWy0qvg==", + "dev": true + }, + "node_modules/sprintf-js": { + "version": "1.1.3", + "devOptional": true, + "license": "BSD-3-Clause" + }, + "node_modules/sqlite3": { + "version": "5.1.7", + "hasInstallScript": true, + "license": "BSD-3-Clause", + "dependencies": { + "bindings": "^1.5.0", + "node-addon-api": "^7.0.0", + "prebuild-install": "^7.1.1", + "tar": "^6.1.11" + }, + "optionalDependencies": { + "node-gyp": "8.x" + }, + "peerDependencies": { + "node-gyp": "8.x" + }, + "peerDependenciesMeta": { + "node-gyp": { + "optional": true + } + } + }, + "node_modules/ssri": { + "version": "8.0.1", + "license": "ISC", + "optional": true, + "dependencies": { + "minipass": "^3.1.1" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/string_decoder": { + "version": "1.3.0", + "license": "MIT", + "dependencies": { + "safe-buffer": "~5.2.0" + } + }, + "node_modules/string-width": { + "version": "4.2.3", + "devOptional": true, + "license": "MIT", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-ansi": { + "version": "6.0.1", + "devOptional": true, + "license": "MIT", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-bom": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", + "integrity": "sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/strip-json-comments": { + "version": "2.0.1", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/strip-outer": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/strip-outer/-/strip-outer-1.0.1.tgz", + "integrity": "sha512-k55yxKHwaXnpYGsOzg4Vl8+tDrWylxDEpknGjhTiZB8dFRU5rTo9CAzeycivxV3s+zlTKwrs6WxMxR95n26kwg==", + "dev": true, + "dependencies": { + "escape-string-regexp": "^1.0.2" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/strip-outer/node_modules/escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", + "dev": true, + "engines": { + "node": ">=0.8.0" + } + }, + "node_modules/sumchecker": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/sumchecker/-/sumchecker-3.0.1.tgz", + "integrity": "sha512-MvjXzkz/BOfyVDkG0oFOtBxHX2u3gKbMHIF/dXblZsgD3BWOFLmHovIpZY7BykJdAjcqRCBi1WYBNdEC9yI7vg==", + "dev": true, + "dependencies": { + "debug": "^4.1.0" + }, + "engines": { + "node": ">= 8.0" + } + }, + "node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/supports-preserve-symlinks-flag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", + "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", + "dev": true, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/tar": { + "version": "6.2.1", + "license": "ISC", + "dependencies": { + "chownr": "^2.0.0", + "fs-minipass": "^2.0.0", + "minipass": "^5.0.0", + "minizlib": "^2.1.1", + "mkdirp": "^1.0.3", + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/tar-fs": { + "version": "2.1.1", + "license": "MIT", + "dependencies": { + "chownr": "^1.1.1", + "mkdirp-classic": "^0.5.2", + "pump": "^3.0.0", + "tar-stream": "^2.1.4" + } + }, + "node_modules/tar-fs/node_modules/chownr": { + "version": "1.1.4", + "license": "ISC" + }, + "node_modules/tar-stream": { + "version": "2.2.0", + "license": "MIT", + "dependencies": { + "bl": "^4.0.3", + "end-of-stream": "^1.4.1", + "fs-constants": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^3.1.1" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/tar/node_modules/minipass": { + "version": "5.0.0", + "license": "ISC", + "engines": { + "node": ">=8" + } + }, + "node_modules/trim-repeated": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/trim-repeated/-/trim-repeated-1.0.0.tgz", + "integrity": "sha512-pkonvlKk8/ZuR0D5tLW8ljt5I8kmxp2XKymhepUeOdCEfKpZaktSArkLHZt76OB1ZvO9bssUsDty4SWhLvZpLg==", + "dev": true, + "dependencies": { + "escape-string-regexp": "^1.0.2" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/trim-repeated/node_modules/escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", + "dev": true, + "engines": { + "node": ">=0.8.0" + } + }, + "node_modules/tunnel-agent": { + "version": "0.6.0", + "license": "Apache-2.0", + "dependencies": { + "safe-buffer": "^5.0.1" + }, + "engines": { + "node": "*" + } + }, + "node_modules/type-fest": { + "version": "0.13.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.13.1.tgz", + "integrity": "sha512-34R7HTnG0XIJcBSn5XhDd7nNFPRcXYRZrBB2O2jdKqYODldSzBAqzsWoZYYvduky73toYS/ESqxPvkDf/F0XMg==", + "dev": true, + "optional": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true + }, + "node_modules/unique-filename": { + "version": "1.1.1", + "license": "ISC", + "optional": true, + "dependencies": { + "unique-slug": "^2.0.0" + } + }, + "node_modules/unique-slug": { + "version": "2.0.2", + "license": "ISC", + "optional": true, + "dependencies": { + "imurmurhash": "^0.1.4" + } + }, + "node_modules/universalify": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", + "dev": true, + "engines": { + "node": ">= 4.0.0" + } + }, + "node_modules/util-deprecate": { + "version": "1.0.2", + "license": "MIT" + }, + "node_modules/validate-npm-package-license": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", + "integrity": "sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==", + "dev": true, + "dependencies": { + "spdx-correct": "^3.0.0", + "spdx-expression-parse": "^3.0.0" + } + }, + "node_modules/wcwidth": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/wcwidth/-/wcwidth-1.0.1.tgz", + "integrity": "sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg==", + "dev": true, + "dependencies": { + "defaults": "^1.0.3" + } + }, + "node_modules/which": { + "version": "2.0.2", + "devOptional": true, + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/wide-align": { + "version": "1.1.5", + "devOptional": true, + "license": "ISC", + "dependencies": { + "string-width": "^1.0.2 || 2 || 3 || 4" + } + }, + "node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "license": "ISC" + }, + "node_modules/xmlbuilder": { + "version": "15.1.1", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-15.1.1.tgz", + "integrity": "sha512-yMqGBqtXyeN1e3TGYvgNgDVZ3j84W4cwkOXQswghol6APgZWaff9lnbvN7MHYJOiXsvGPXtjTYJEiC9J2wv9Eg==", + "dev": true, + "engines": { + "node": ">=8.0" + } + }, + "node_modules/y18n": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", + "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", + "dev": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/yallist": { + "version": "4.0.0", + "license": "ISC" + }, + "node_modules/yargs": { + "version": "17.7.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", + "dev": true, + "dependencies": { + "cliui": "^8.0.1", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.3", + "y18n": "^5.0.5", + "yargs-parser": "^21.1.1" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/yargs-parser": { + "version": "21.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", + "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", + "dev": true, + "engines": { + "node": ">=12" + } + }, + "node_modules/yauzl": { + "version": "2.10.0", + "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz", + "integrity": "sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g==", + "dev": true, + "dependencies": { + "buffer-crc32": "~0.2.3", + "fd-slicer": "~1.1.0" + } + } + } +} diff --git a/updater/package.json b/updater/package.json new file mode 100755 index 0000000..622f637 --- /dev/null +++ b/updater/package.json @@ -0,0 +1,13 @@ +{ + "main": "main.js", + "version": "1.0.0", + "dependencies": { + "libprisbeam": "git+https://source.equestria.dev/equestria.dev/libprisbeam.git/", + "sqlite3": "^5.1.7" + }, + "devDependencies": { + "electron": "^29.1.6", + "electron-packager": "^17.1.2", + "electron-rebuild": "^3.2.9" + } +} diff --git a/updater/sql/.idea/.gitignore b/updater/sql/.idea/.gitignore new file mode 100755 index 0000000..13566b8 --- /dev/null +++ b/updater/sql/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/updater/sql/.idea/inspectionProfiles/Project_Default.xml b/updater/sql/.idea/inspectionProfiles/Project_Default.xml new file mode 100755 index 0000000..8252e57 --- /dev/null +++ b/updater/sql/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,13 @@ + + + + \ No newline at end of file diff --git a/updater/sql/.idea/inspectionProfiles/profiles_settings.xml b/updater/sql/.idea/inspectionProfiles/profiles_settings.xml new file mode 100755 index 0000000..105ce2d --- /dev/null +++ b/updater/sql/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/updater/sql/.idea/misc.xml b/updater/sql/.idea/misc.xml new file mode 100755 index 0000000..a971a2c --- /dev/null +++ b/updater/sql/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/updater/sql/.idea/modules.xml b/updater/sql/.idea/modules.xml new file mode 100755 index 0000000..dfb35d4 --- /dev/null +++ b/updater/sql/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/updater/sql/.idea/pgsql.iml b/updater/sql/.idea/pgsql.iml new file mode 100755 index 0000000..d0876a7 --- /dev/null +++ b/updater/sql/.idea/pgsql.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/updater/sql/doall.sh b/updater/sql/doall.sh new file mode 100755 index 0000000..89594f8 --- /dev/null +++ b/updater/sql/doall.sh @@ -0,0 +1,15 @@ +#!/bin/bash +PATH=/opt/homebrew/Cellar/postgresql@16/16.2_1/bin:$PATH +brew services start postgresql@16 +rm -f $HOME/.db.pgdump +wget $1 -O $HOME/.db.pgdump +dropdb --if-exists derpibooru +#sudo -u postgres dropdb --if-exists derpibooru +createdb derpibooru +#sudo -u postgres createdb derpibooru +pg_restore -v -O -d derpibooru $HOME/.db.pgdump +#sudo -u postgres pg_restore -v -O -d derpibooru $HOME/.db.pgdump +python3 main.py +#sudo -u postgres bash -c "cd $PATH && python3 main.py" +brew services stop postgresql@16 +rm -f $HOME/.db.pgdump diff --git a/updater/sql/mac/LICENSE b/updater/sql/mac/LICENSE new file mode 100755 index 0000000..6c4ce40 --- /dev/null +++ b/updater/sql/mac/LICENSE @@ -0,0 +1,25 @@ +Copyright (c) MapBox +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. +- Neither the name "MapBox" nor the names of its contributors may be + used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/updater/sql/mac/README.md b/updater/sql/mac/README.md new file mode 100755 index 0000000..ffc1f04 --- /dev/null +++ b/updater/sql/mac/README.md @@ -0,0 +1,249 @@ +# ⚙️ node-sqlite3 + +Asynchronous, non-blocking [SQLite3](https://sqlite.org/) bindings for [Node.js](http://nodejs.org/). + +[![Latest release](https://img.shields.io/github/release/TryGhost/node-sqlite3.svg)](https://www.npmjs.com/package/sqlite3) +![Build Status](https://github.com/TryGhost/node-sqlite3/workflows/CI/badge.svg?branch=master) +[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmapbox%2Fnode-sqlite3.svg?type=shield)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmapbox%2Fnode-sqlite3?ref=badge_shield) +[![N-API v3 Badge](https://img.shields.io/badge/N--API-v3-green.svg)](https://nodejs.org/dist/latest/docs/api/n-api.html#n_api_n_api) +[![N-API v6 Badge](https://img.shields.io/badge/N--API-v6-green.svg)](https://nodejs.org/dist/latest/docs/api/n-api.html#n_api_n_api) + +# Features + + - Straightforward query and parameter binding interface + - Full Buffer/Blob support + - Extensive [debugging support](https://github.com/tryghost/node-sqlite3/wiki/Debugging) + - [Query serialization](https://github.com/tryghost/node-sqlite3/wiki/Control-Flow) API + - [Extension support](https://github.com/TryGhost/node-sqlite3/wiki/API#databaseloadextensionpath-callback), including bundled support for the [json1 extension](https://www.sqlite.org/json1.html) + - Big test suite + - Written in modern C++ and tested for memory leaks + - Bundles SQLite v3.44.2, or you can build using a local SQLite + +# Installing + +You can use [`npm`](https://github.com/npm/cli) or [`yarn`](https://github.com/yarnpkg/yarn) to install `sqlite3`: + +* (recommended) Latest published package: +```bash +npm install sqlite3 +# or +yarn add sqlite3 +``` +* GitHub's `master` branch: `npm install https://github.com/tryghost/node-sqlite3/tarball/master` + +### Prebuilt binaries + +`sqlite3` v5+ was rewritten to use [Node-API](https://nodejs.org/api/n-api.html) so prebuilt binaries do not need to be built for specific Node versions. `sqlite3` currently builds for both Node-API v3 and v6. Check the [Node-API version matrix](https://nodejs.org/api/n-api.html#node-api-version-matrix) to ensure your Node version supports one of these. The prebuilt binaries should be supported on Node v10+. + +The module uses [`prebuild-install`](https://github.com/prebuild/prebuild-install) to download the prebuilt binary for your platform, if it exists. These binaries are hosted on GitHub Releases for `sqlite3` versions above 5.0.2, and they are hosted on S3 otherwise. The following targets are currently provided: + +* `darwin-arm64` +* `darwin-x64` +* `linux-arm64` +* `linux-x64` +* `linuxmusl-arm64` +* `linuxmusl-x64` +* `win32-ia32` +* `win32-x64` + +Unfortunately, [prebuild](https://github.com/prebuild/prebuild/issues/174) cannot differentiate between `armv6` and `armv7`, and instead uses `arm` as the `{arch}`. Until that is fixed, you will still need to install `sqlite3` from [source](#source-install). + +Support for other platforms and architectures may be added in the future if CI supports building on them. + +If your environment isn't supported, it'll use `node-gyp` to build SQLite, but you will need to install a C++ compiler and linker. + +### Other ways to install + +It is also possible to make your own build of `sqlite3` from its source instead of its npm package ([See below.](#source-install)). + +The `sqlite3` module also works with [node-webkit](https://github.com/rogerwang/node-webkit) if node-webkit contains a supported version of Node.js engine. [(See below.)](#building-for-node-webkit) + +SQLite's [SQLCipher extension](https://github.com/sqlcipher/sqlcipher) is also supported. [(See below.)](#building-for-sqlcipher) + +# API + +See the [API documentation](https://github.com/TryGhost/node-sqlite3/wiki/API) in the wiki. + +# Usage + +**Note:** the module must be [installed](#installing) before use. + +``` js +const sqlite3 = require('sqlite3').verbose(); +const db = new sqlite3.Database(':memory:'); + +db.serialize(() => { + db.run("CREATE TABLE lorem (info TEXT)"); + + const stmt = db.prepare("INSERT INTO lorem VALUES (?)"); + for (let i = 0; i < 10; i++) { + stmt.run("Ipsum " + i); + } + stmt.finalize(); + + db.each("SELECT rowid AS id, info FROM lorem", (err, row) => { + console.log(row.id + ": " + row.info); + }); +}); + +db.close(); +``` + +## Source install + +To skip searching for pre-compiled binaries, and force a build from source, use + +```bash +npm install --build-from-source +``` + +The sqlite3 module depends only on libsqlite3. However, by default, an internal/bundled copy of sqlite will be built and statically linked, so an externally installed sqlite3 is not required. + +If you wish to install against an external sqlite then you need to pass the `--sqlite` argument to `npm` wrapper: + +```bash +npm install --build-from-source --sqlite=/usr/local +``` + +If building against an external sqlite3 make sure to have the development headers available. Mac OS X ships with these by default. If you don't have them installed, install the `-dev` package with your package manager, e.g. `apt-get install libsqlite3-dev` for Debian/Ubuntu. Make sure that you have at least `libsqlite3` >= 3.6. + +Note, if building against homebrew-installed sqlite on OS X you can do: + +```bash +npm install --build-from-source --sqlite=/usr/local/opt/sqlite/ +``` + +## Custom file header (magic) + +The default sqlite file header is "SQLite format 3". You can specify a different magic, though this will make standard tools and libraries unable to work with your files. + +```bash +npm install --build-from-source --sqlite_magic="MyCustomMagic15" +``` + +Note that the magic *must* be exactly 15 characters long (16 bytes including null terminator). + +## Building for node-webkit + +Because of ABI differences, `sqlite3` must be built in a custom to be used with [node-webkit](https://github.com/rogerwang/node-webkit). + +To build `sqlite3` for node-webkit: + +1. Install [`nw-gyp`](https://github.com/rogerwang/nw-gyp) globally: `npm install nw-gyp -g` *(unless already installed)* + +2. Build the module with the custom flags of `--runtime`, `--target_arch`, and `--target`: + +```bash +NODE_WEBKIT_VERSION="0.8.6" # see latest version at https://github.com/rogerwang/node-webkit#downloads +npm install sqlite3 --build-from-source --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION) +``` + +You can also run this command from within a `sqlite3` checkout: + +```bash +npm install --build-from-source --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION) +``` + +Remember the following: + +* You must provide the right `--target_arch` flag. `ia32` is needed to target 32bit node-webkit builds, while `x64` will target 64bit node-webkit builds (if available for your platform). + +* After the `sqlite3` package is built for node-webkit it cannot run in the vanilla Node.js (and vice versa). + * For example, `npm test` of the node-webkit's package would fail. + +Visit the “[Using Node modules](https://github.com/rogerwang/node-webkit/wiki/Using-Node-modules)” article in the node-webkit's wiki for more details. + +## Building for SQLCipher + +For instructions on building SQLCipher, see [Building SQLCipher for Node.js](https://coolaj86.com/articles/building-sqlcipher-for-node-js-on-raspberry-pi-2/). Alternatively, you can install it with your local package manager. + +To run against SQLCipher, you need to compile `sqlite3` from source by passing build options like: + +```bash +npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=/usr/ + +node -e 'require("sqlite3")' +``` + +If your SQLCipher is installed in a custom location (if you compiled and installed it yourself), you'll need to set some environment variables: + +### On OS X with Homebrew + +Set the location where `brew` installed it: + +```bash +export LDFLAGS="-L`brew --prefix`/opt/sqlcipher/lib" +export CPPFLAGS="-I`brew --prefix`/opt/sqlcipher/include/sqlcipher" +npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix` + +node -e 'require("sqlite3")' +``` + +### On most Linuxes (including Raspberry Pi) + +Set the location where `make` installed it: + +```bash +export LDFLAGS="-L/usr/local/lib" +export CPPFLAGS="-I/usr/local/include -I/usr/local/include/sqlcipher" +export CXXFLAGS="$CPPFLAGS" +npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=/usr/local --verbose + +node -e 'require("sqlite3")' +``` + +### Custom builds and Electron + +Running `sqlite3` through [electron-rebuild](https://github.com/electron/electron-rebuild) does not preserve the SQLCipher extension, so some additional flags are needed to make this build Electron compatible. Your `npm install sqlite3 --build-from-source` command needs these additional flags (be sure to replace the target version with the current Electron version you are working with): + +```bash +--runtime=electron --target=18.2.1 --dist-url=https://electronjs.org/headers +``` + +In the case of MacOS with Homebrew, the command should look like the following: + +```bash +npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix` --runtime=electron --target=18.2.1 --dist-url=https://electronjs.org/headers +``` + +# Testing + +```bash +npm test +``` + +# Contributors + +* [Daniel Lockyer](https://github.com/daniellockyer) +* [Konstantin Käfer](https://github.com/kkaefer) +* [Dane Springmeyer](https://github.com/springmeyer) +* [Will White](https://github.com/willwhite) +* [Orlando Vazquez](https://github.com/orlandov) +* [Artem Kustikov](https://github.com/artiz) +* [Eric Fredricksen](https://github.com/grumdrig) +* [John Wright](https://github.com/mrjjwright) +* [Ryan Dahl](https://github.com/ry) +* [Tom MacWright](https://github.com/tmcw) +* [Carter Thaxton](https://github.com/carter-thaxton) +* [Audrius Kažukauskas](https://github.com/audriusk) +* [Johannes Schauer](https://github.com/pyneo) +* [Mithgol](https://github.com/Mithgol) +* [Kewde](https://github.com/kewde) + +# Acknowledgments + +Thanks to [Orlando Vazquez](https://github.com/orlandov), +[Eric Fredricksen](https://github.com/grumdrig) and +[Ryan Dahl](https://github.com/ry) for their SQLite bindings for node, and to mraleph on Freenode's #v8 for answering questions. + +This module was originally created by [Mapbox](https://mapbox.com/) & is now maintained by [Ghost](https://ghost.org). + +# Changelog + +We use [GitHub releases](https://github.com/TryGhost/node-sqlite3/releases) for notes on the latest versions. See [CHANGELOG.md](https://github.com/TryGhost/node-sqlite3/blob/b05f4594cf8b0de64743561fcd2cfe6f4571754d/CHANGELOG.md) in git history for details on older versions. + +# License + +`node-sqlite3` is [BSD licensed](https://github.com/tryghost/node-sqlite3/raw/master/LICENSE). + +[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmapbox%2Fnode-sqlite3.svg?type=large)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmapbox%2Fnode-sqlite3?ref=badge_large) diff --git a/updater/sql/mac/binding.gyp b/updater/sql/mac/binding.gyp new file mode 100755 index 0000000..a8fccd0 --- /dev/null +++ b/updater/sql/mac/binding.gyp @@ -0,0 +1,58 @@ +{ + "includes": [ "deps/common-sqlite.gypi" ], + "variables": { + "sqlite%":"internal", + "sqlite_libname%":"sqlite3", + "module_name": "node_sqlite3", + }, + "targets": [ + { + "target_name": "<(module_name)", + "cflags!": [ "-fno-exceptions" ], + "cflags_cc!": [ "-fno-exceptions" ], + "xcode_settings": { "GCC_ENABLE_CPP_EXCEPTIONS": "YES", + "CLANG_CXX_LIBRARY": "libc++", + "MACOSX_DEPLOYMENT_TARGET": "10.7", + }, + "msvs_settings": { + "VCCLCompilerTool": { "ExceptionHandling": 1 }, + }, + "include_dirs": [ + " + +import events = require("events"); + +export const OPEN_READONLY: number; +export const OPEN_READWRITE: number; +export const OPEN_CREATE: number; +export const OPEN_FULLMUTEX: number; +export const OPEN_SHAREDCACHE: number; +export const OPEN_PRIVATECACHE: number; +export const OPEN_URI: number; + +export const VERSION: string; +export const SOURCE_ID: string; +export const VERSION_NUMBER: number; + +export const OK: number; +export const ERROR: number; +export const INTERNAL: number; +export const PERM: number; +export const ABORT: number; +export const BUSY: number; +export const LOCKED: number; +export const NOMEM: number; +export const READONLY: number; +export const INTERRUPT: number +export const IOERR: number; +export const CORRUPT: number +export const NOTFOUND: number; +export const FULL: number; +export const CANTOPEN: number; +export const PROTOCOL: number; +export const EMPTY: number; +export const SCHEMA: number; +export const TOOBIG: number +export const CONSTRAINT: number +export const MISMATCH: number; +export const MISUSE: number; +export const NOLFS: number; +export const AUTH: number +export const FORMAT: number; +export const RANGE: number +export const NOTADB: number; + +export const LIMIT_LENGTH: number; +export const LIMIT_SQL_LENGTH: number; +export const LIMIT_COLUMN: number; +export const LIMIT_EXPR_DEPTH: number; +export const LIMIT_COMPOUND_SELECT: number; +export const LIMIT_VDBE_OP: number; +export const LIMIT_FUNCTION_ARG: number; +export const LIMIT_ATTACHED: number; +export const LIMIT_LIKE_PATTERN_LENGTH: number; +export const LIMIT_VARIABLE_NUMBER: number; +export const LIMIT_TRIGGER_DEPTH: number; +export const LIMIT_WORKER_THREADS: number; + +export const cached: { + Database(filename: string, callback?: (this: Database, err: Error | null) => void): Database; + Database(filename: string, mode?: number, callback?: (this: Database, err: Error | null) => void): Database; +}; + +export interface RunResult extends Statement { + lastID: number; + changes: number; +} + +export class Statement extends events.EventEmitter { + bind(callback?: (err: Error | null) => void): this; + bind(...params: any[]): this; + + reset(callback?: (err: null) => void): this; + + finalize(callback?: (err: Error) => void): Database; + + run(callback?: (err: Error | null) => void): this; + run(params: any, callback?: (this: RunResult, err: Error | null) => void): this; + run(...params: any[]): this; + + get(callback?: (err: Error | null, row?: T) => void): this; + get(params: any, callback?: (this: RunResult, err: Error | null, row?: T) => void): this; + get(...params: any[]): this; + + all(callback?: (err: Error | null, rows: T[]) => void): this; + all(params: any, callback?: (this: RunResult, err: Error | null, rows: T[]) => void): this; + all(...params: any[]): this; + + each(callback?: (err: Error | null, row: T) => void, complete?: (err: Error | null, count: number) => void): this; + each(params: any, callback?: (this: RunResult, err: Error | null, row: T) => void, complete?: (err: Error | null, count: number) => void): this; + each(...params: any[]): this; +} + +export class Database extends events.EventEmitter { + constructor(filename: string, callback?: (err: Error | null) => void); + constructor(filename: string, mode?: number, callback?: (err: Error | null) => void); + + close(callback?: (err: Error | null) => void): void; + + run(sql: string, callback?: (this: RunResult, err: Error | null) => void): this; + run(sql: string, params: any, callback?: (this: RunResult, err: Error | null) => void): this; + run(sql: string, ...params: any[]): this; + + get(sql: string, callback?: (this: Statement, err: Error | null, row: T) => void): this; + get(sql: string, params: any, callback?: (this: Statement, err: Error | null, row: T) => void): this; + get(sql: string, ...params: any[]): this; + + all(sql: string, callback?: (this: Statement, err: Error | null, rows: T[]) => void): this; + all(sql: string, params: any, callback?: (this: Statement, err: Error | null, rows: T[]) => void): this; + all(sql: string, ...params: any[]): this; + + each(sql: string, callback?: (this: Statement, err: Error | null, row: T) => void, complete?: (err: Error | null, count: number) => void): this; + each(sql: string, params: any, callback?: (this: Statement, err: Error | null, row: T) => void, complete?: (err: Error | null, count: number) => void): this; + each(sql: string, ...params: any[]): this; + + exec(sql: string, callback?: (this: Statement, err: Error | null) => void): this; + + prepare(sql: string, callback?: (this: Statement, err: Error | null) => void): Statement; + prepare(sql: string, params: any, callback?: (this: Statement, err: Error | null) => void): Statement; + prepare(sql: string, ...params: any[]): Statement; + + serialize(callback?: () => void): void; + parallelize(callback?: () => void): void; + + on(event: "trace", listener: (sql: string) => void): this; + on(event: "profile", listener: (sql: string, time: number) => void): this; + on(event: "change", listener: (type: string, database: string, table: string, rowid: number) => void): this; + on(event: "error", listener: (err: Error) => void): this; + on(event: "open" | "close", listener: () => void): this; + on(event: string, listener: (...args: any[]) => void): this; + + configure(option: "busyTimeout", value: number): void; + configure(option: "limit", id: number, value: number): void; + + loadExtension(filename: string, callback?: (err: Error | null) => void): this; + + wait(callback?: (param: null) => void): this; + + interrupt(): void; +} + +export function verbose(): sqlite3; + +export interface sqlite3 { + OPEN_READONLY: number; + OPEN_READWRITE: number; + OPEN_CREATE: number; + OPEN_FULLMUTEX: number; + OPEN_SHAREDCACHE: number; + OPEN_PRIVATECACHE: number; + OPEN_URI: number; + + VERSION: string; + SOURCE_ID: string; + VERSION_NUMBER: number; + + OK: number; + ERROR: number; + INTERNAL: number; + PERM: number; + ABORT: number; + BUSY: number; + LOCKED: number; + NOMEM: number; + READONLY: number; + INTERRUPT: number + IOERR: number; + CORRUPT: number + NOTFOUND: number; + FULL: number; + CANTOPEN: number; + PROTOCOL: number; + EMPTY: number; + SCHEMA: number; + TOOBIG: number + CONSTRAINT: number + MISMATCH: number; + MISUSE: number; + NOLFS: number; + AUTH: number + FORMAT: number; + RANGE: number + NOTADB: number; + + LIMIT_LENGTH: number; + LIMIT_SQL_LENGTH: number; + LIMIT_COLUMN: number; + LIMIT_EXPR_DEPTH: number; + LIMIT_COMPOUND_SELECT: number; + LIMIT_VDBE_OP: number; + LIMIT_FUNCTION_ARG: number; + LIMIT_ATTACHED: number; + LIMIT_LIKE_PATTERN_LENGTH: number; + LIMIT_VARIABLE_NUMBER: number; + LIMIT_TRIGGER_DEPTH: number; + LIMIT_WORKER_THREADS: number; + + cached: typeof cached; + RunResult: RunResult; + Statement: typeof Statement; + Database: typeof Database; + verbose(): this; +} \ No newline at end of file diff --git a/updater/sql/mac/lib/sqlite3.js b/updater/sql/mac/lib/sqlite3.js new file mode 100755 index 0000000..430a2b8 --- /dev/null +++ b/updater/sql/mac/lib/sqlite3.js @@ -0,0 +1,207 @@ +const path = require('path'); +const sqlite3 = require('./sqlite3-binding.js'); +const EventEmitter = require('events').EventEmitter; +module.exports = exports = sqlite3; + +function normalizeMethod (fn) { + return function (sql) { + let errBack; + const args = Array.prototype.slice.call(arguments, 1); + + if (typeof args[args.length - 1] === 'function') { + const callback = args[args.length - 1]; + errBack = function(err) { + if (err) { + callback(err); + } + }; + } + const statement = new Statement(this, sql, errBack); + return fn.call(this, statement, args); + }; +} + +function inherits(target, source) { + for (const k in source.prototype) + target.prototype[k] = source.prototype[k]; +} + +sqlite3.cached = { + Database: function(file, a, b) { + if (file === '' || file === ':memory:') { + // Don't cache special databases. + return new Database(file, a, b); + } + + let db; + file = path.resolve(file); + + if (!sqlite3.cached.objects[file]) { + db = sqlite3.cached.objects[file] = new Database(file, a, b); + } + else { + // Make sure the callback is called. + db = sqlite3.cached.objects[file]; + const callback = (typeof a === 'number') ? b : a; + if (typeof callback === 'function') { + function cb() { callback.call(db, null); } + if (db.open) process.nextTick(cb); + else db.once('open', cb); + } + } + + return db; + }, + objects: {} +}; + + +const Database = sqlite3.Database; +const Statement = sqlite3.Statement; +const Backup = sqlite3.Backup; + +inherits(Database, EventEmitter); +inherits(Statement, EventEmitter); +inherits(Backup, EventEmitter); + +// Database#prepare(sql, [bind1, bind2, ...], [callback]) +Database.prototype.prepare = normalizeMethod(function(statement, params) { + return params.length + ? statement.bind.apply(statement, params) + : statement; +}); + +// Database#run(sql, [bind1, bind2, ...], [callback]) +Database.prototype.run = normalizeMethod(function(statement, params) { + statement.run.apply(statement, params).finalize(); + return this; +}); + +// Database#get(sql, [bind1, bind2, ...], [callback]) +Database.prototype.get = normalizeMethod(function(statement, params) { + statement.get.apply(statement, params).finalize(); + return this; +}); + +// Database#all(sql, [bind1, bind2, ...], [callback]) +Database.prototype.all = normalizeMethod(function(statement, params) { + statement.all.apply(statement, params).finalize(); + return this; +}); + +// Database#each(sql, [bind1, bind2, ...], [callback], [complete]) +Database.prototype.each = normalizeMethod(function(statement, params) { + statement.each.apply(statement, params).finalize(); + return this; +}); + +Database.prototype.map = normalizeMethod(function(statement, params) { + statement.map.apply(statement, params).finalize(); + return this; +}); + +// Database#backup(filename, [callback]) +// Database#backup(filename, destName, sourceName, filenameIsDest, [callback]) +Database.prototype.backup = function() { + let backup; + if (arguments.length <= 2) { + // By default, we write the main database out to the main database of the named file. + // This is the most likely use of the backup api. + backup = new Backup(this, arguments[0], 'main', 'main', true, arguments[1]); + } else { + // Otherwise, give the user full control over the sqlite3_backup_init arguments. + backup = new Backup(this, arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]); + } + // Per the sqlite docs, exclude the following errors as non-fatal by default. + backup.retryErrors = [sqlite3.BUSY, sqlite3.LOCKED]; + return backup; +}; + +Statement.prototype.map = function() { + const params = Array.prototype.slice.call(arguments); + const callback = params.pop(); + params.push(function(err, rows) { + if (err) return callback(err); + const result = {}; + if (rows.length) { + const keys = Object.keys(rows[0]); + const key = keys[0]; + if (keys.length > 2) { + // Value is an object + for (let i = 0; i < rows.length; i++) { + result[rows[i][key]] = rows[i]; + } + } else { + const value = keys[1]; + // Value is a plain value + for (let i = 0; i < rows.length; i++) { + result[rows[i][key]] = rows[i][value]; + } + } + } + callback(err, result); + }); + return this.all.apply(this, params); +}; + +let isVerbose = false; + +const supportedEvents = [ 'trace', 'profile', 'change' ]; + +Database.prototype.addListener = Database.prototype.on = function(type) { + const val = EventEmitter.prototype.addListener.apply(this, arguments); + if (supportedEvents.indexOf(type) >= 0) { + this.configure(type, true); + } + return val; +}; + +Database.prototype.removeListener = function(type) { + const val = EventEmitter.prototype.removeListener.apply(this, arguments); + if (supportedEvents.indexOf(type) >= 0 && !this._events[type]) { + this.configure(type, false); + } + return val; +}; + +Database.prototype.removeAllListeners = function(type) { + const val = EventEmitter.prototype.removeAllListeners.apply(this, arguments); + if (supportedEvents.indexOf(type) >= 0) { + this.configure(type, false); + } + return val; +}; + +// Save the stack trace over EIO callbacks. +sqlite3.verbose = function() { + if (!isVerbose) { + const trace = require('./trace'); + [ + 'prepare', + 'get', + 'run', + 'all', + 'each', + 'map', + 'close', + 'exec' + ].forEach(function (name) { + trace.extendTrace(Database.prototype, name); + }); + [ + 'bind', + 'get', + 'run', + 'all', + 'each', + 'map', + 'reset', + 'finalize', + ].forEach(function (name) { + trace.extendTrace(Statement.prototype, name); + }); + isVerbose = true; + } + + return sqlite3; +}; diff --git a/updater/sql/mac/lib/trace.js b/updater/sql/mac/lib/trace.js new file mode 100755 index 0000000..1d84cb0 --- /dev/null +++ b/updater/sql/mac/lib/trace.js @@ -0,0 +1,38 @@ +// Inspired by https://github.com/tlrobinson/long-stack-traces +const util = require('util'); + +function extendTrace(object, property, pos) { + const old = object[property]; + object[property] = function() { + const error = new Error(); + const name = object.constructor.name + '#' + property + '(' + + Array.prototype.slice.call(arguments).map(function(el) { + return util.inspect(el, false, 0); + }).join(', ') + ')'; + + if (typeof pos === 'undefined') pos = -1; + if (pos < 0) pos += arguments.length; + const cb = arguments[pos]; + if (typeof arguments[pos] === 'function') { + arguments[pos] = function replacement() { + const err = arguments[0]; + if (err && err.stack && !err.__augmented) { + err.stack = filter(err).join('\n'); + err.stack += '\n--> in ' + name; + err.stack += '\n' + filter(error).slice(1).join('\n'); + err.__augmented = true; + } + return cb.apply(this, arguments); + }; + } + return old.apply(this, arguments); + }; +} +exports.extendTrace = extendTrace; + + +function filter(error) { + return error.stack.split('\n').filter(function(line) { + return line.indexOf(__filename) < 0; + }); +} diff --git a/updater/sql/mac/package.json b/updater/sql/mac/package.json new file mode 100755 index 0000000..a6626c0 --- /dev/null +++ b/updater/sql/mac/package.json @@ -0,0 +1,89 @@ +{ + "name": "sqlite3-mac", + "description": "Asynchronous, non-blocking SQLite3 bindings", + "version": "5.1.7", + "homepage": "https://github.com/TryGhost/node-sqlite3", + "author": { + "name": "Mapbox", + "url": "https://mapbox.com/" + }, + "binary": { + "napi_versions": [ + 3, + 6 + ] + }, + "contributors": [ + "Daniel Lockyer ", + "Konstantin Käfer ", + "Dane Springmeyer ", + "Will White ", + "Orlando Vazquez ", + "Artem Kustikov ", + "Eric Fredricksen ", + "John Wright ", + "Ryan Dahl ", + "Tom MacWright ", + "Carter Thaxton ", + "Audrius Kažukauskas ", + "Johannes Schauer ", + "Nathan Rajlich ", + "AJ ONeal ", + "Mithgol", + "Ben Noordhuis " + ], + "files": [ + "binding.gyp", + "deps/", + "lib/*.js", + "lib/*.d.ts", + "src/" + ], + "repository": { + "type": "git", + "url": "https://github.com/TryGhost/node-sqlite3.git" + }, + "dependencies": { + "bindings": "^1.5.0", + "node-addon-api": "^7.0.0", + "prebuild-install": "^7.1.1", + "tar": "^6.1.11" + }, + "devDependencies": { + "eslint": "8.56.0", + "mocha": "10.2.0", + "prebuild": "12.1.0" + }, + "peerDependencies": { + "node-gyp": "8.x" + }, + "peerDependenciesMeta": { + "node-gyp": { + "optional": true + } + }, + "optionalDependencies": { + "node-gyp": "8.x" + }, + "scripts": { + "install": "prebuild-install -r napi || node-gyp rebuild", + "prebuild": "prebuild --runtime napi --all --verbose", + "rebuild": "node-gyp rebuild", + "upload": "prebuild --verbose --prerelease", + "test": "node test/support/createdb.js && mocha -R spec --timeout 480000" + }, + "license": "BSD-3-Clause", + "keywords": [ + "sql", + "sqlite", + "sqlite3", + "database" + ], + "main": "./lib/sqlite3", + "types": "./lib/sqlite3.d.ts", + "renovate": { + "extends": [ + "@tryghost:base" + ] + } +} diff --git a/updater/sql/mac/src/async.h b/updater/sql/mac/src/async.h new file mode 100755 index 0000000..f36e4cb --- /dev/null +++ b/updater/sql/mac/src/async.h @@ -0,0 +1,76 @@ +#ifndef NODE_SQLITE3_SRC_ASYNC_H +#define NODE_SQLITE3_SRC_ASYNC_H + +#include +#include + +#include "threading.h" + +// Generic uv_async handler. +template class Async { + typedef void (*Callback)(Parent* parent, Item* item); + +protected: + uv_async_t watcher; + NODE_SQLITE3_MUTEX_t + std::vector data; + Callback callback; +public: + Parent* parent; + +public: + Async(Parent* parent_, Callback cb_) + : callback(cb_), parent(parent_) { + watcher.data = this; + NODE_SQLITE3_MUTEX_INIT + uv_loop_t *loop; + napi_get_uv_event_loop(parent_->Env(), &loop); + uv_async_init(loop, &watcher, reinterpret_cast(listener)); + } + + static void listener(uv_async_t* handle) { + auto* async = static_cast(handle->data); + std::vector rows; + NODE_SQLITE3_MUTEX_LOCK(&async->mutex) + rows.swap(async->data); + NODE_SQLITE3_MUTEX_UNLOCK(&async->mutex) + for(auto row : rows) + async->callback(async->parent, row); + } + + static void close(uv_handle_t* handle) { + assert(handle != NULL); + assert(handle->data != NULL); + auto* async = static_cast(handle->data); + delete async; + } + + void finish() { + // Need to call the listener again to ensure all items have been + // processed. Is this a bug in uv_async? Feels like uv_close + // should handle that. + listener(&watcher); + uv_close((uv_handle_t*)&watcher, close); + } + + void add(Item* item) { + NODE_SQLITE3_MUTEX_LOCK(&mutex); + data.emplace_back(item); + NODE_SQLITE3_MUTEX_UNLOCK(&mutex) + } + + void send() { + uv_async_send(&watcher); + } + + void send(Item* item) { + add(item); + send(); + } + + ~Async() { + NODE_SQLITE3_MUTEX_DESTROY + } +}; + +#endif diff --git a/updater/sql/mac/src/backup.cc b/updater/sql/mac/src/backup.cc new file mode 100755 index 0000000..0f971f5 --- /dev/null +++ b/updater/sql/mac/src/backup.cc @@ -0,0 +1,418 @@ +#include +#include +#include "macros.h" +#include "database.h" +#include "backup.h" + +using namespace node_sqlite3; + +Napi::Object Backup::Init(Napi::Env env, Napi::Object exports) { + Napi::HandleScope scope(env); + + // declare napi_default_method here as it is only available in Node v14.12.0+ + auto napi_default_method = static_cast(napi_writable | napi_configurable); + + auto t = DefineClass(env, "Backup", { + InstanceMethod("step", &Backup::Step, napi_default_method), + InstanceMethod("finish", &Backup::Finish, napi_default_method), + InstanceAccessor("idle", &Backup::IdleGetter, nullptr), + InstanceAccessor("completed", &Backup::CompletedGetter, nullptr), + InstanceAccessor("failed", &Backup::FailedGetter, nullptr), + InstanceAccessor("remaining", &Backup::RemainingGetter, nullptr), + InstanceAccessor("pageCount", &Backup::PageCountGetter, nullptr), + InstanceAccessor("retryErrors", &Backup::RetryErrorGetter, &Backup::RetryErrorSetter), + }); + + exports.Set("Backup", t); + return exports; +} + +void Backup::Process() { + if (finished && !queue.empty()) { + return CleanQueue(); + } + + while (inited && !locked && !queue.empty()) { + auto call = std::move(queue.front()); + queue.pop(); + + call->callback(call->baton); + } +} + +void Backup::Schedule(Work_Callback callback, Baton* baton) { + if (finished) { + queue.emplace(new Call(callback, baton)); + CleanQueue(); + } + else if (!inited || locked || !queue.empty()) { + queue.emplace(new Call(callback, baton)); + } + else { + callback(baton); + } +} + +template void Backup::Error(T* baton) { + auto env = baton->backup->Env(); + Napi::HandleScope scope(env); + + Backup* backup = baton->backup; + // Fail hard on logic errors. + assert(backup->status != 0); + EXCEPTION(Napi::String::New(env, backup->message), backup->status, exception); + + Napi::Function cb = baton->callback.Value(); + + if (!cb.IsEmpty() && cb.IsFunction()) { + Napi::Value argv[] = { exception }; + TRY_CATCH_CALL(backup->Value(), cb, 1, argv); + } + else { + Napi::Value argv[] = { Napi::String::New(env, "error"), exception }; + EMIT_EVENT(backup->Value(), 2, argv); + } +} + +void Backup::CleanQueue() { + auto env = this->Env(); + Napi::HandleScope scope(env); + + if (inited && !queue.empty()) { + // This backup has already been initialized and is now finished. + // Fire error for all remaining items in the queue. + EXCEPTION(Napi::String::New(env, "Backup is already finished"), SQLITE_MISUSE, exception); + Napi::Value argv[] = { exception }; + bool called = false; + + // Clear out the queue so that this object can get GC'ed. + while (!queue.empty()) { + auto call = std::move(queue.front()); + queue.pop(); + + std::unique_ptr baton(call->baton); + Napi::Function cb = baton->callback.Value(); + + if (inited && !cb.IsEmpty() && + cb.IsFunction()) { + TRY_CATCH_CALL(Value(), cb, 1, argv); + called = true; + } + } + + // When we couldn't call a callback function, emit an error on the + // Backup object. + if (!called) { + Napi::Value info[] = { Napi::String::New(env, "error"), exception }; + EMIT_EVENT(Value(), 2, info); + } + } + else while (!queue.empty()) { + // Just delete all items in the queue; we already fired an event when + // initializing the backup failed. + auto call = std::move(queue.front()); + queue.pop(); + + // We don't call the actual callback, so we have to make sure that + // the baton gets destroyed. + delete call->baton; + } +} + +Backup::Backup(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { + auto env = info.Env(); + if (!info.IsConstructCall()) { + Napi::TypeError::New(env, "Use the new operator to create new Backup objects").ThrowAsJavaScriptException(); + return; + } + + auto length = info.Length(); + + if (length <= 0 || !Database::HasInstance(info[0])) { + Napi::TypeError::New(env, "Database object expected").ThrowAsJavaScriptException(); + return; + } + else if (length <= 1 || !info[1].IsString()) { + Napi::TypeError::New(env, "Filename expected").ThrowAsJavaScriptException(); + return; + } + else if (length <= 2 || !info[2].IsString()) { + Napi::TypeError::New(env, "Source database name expected").ThrowAsJavaScriptException(); + return; + } + else if (length <= 3 || !info[3].IsString()) { + Napi::TypeError::New(env, "Destination database name expected").ThrowAsJavaScriptException(); + return; + } + else if (length <= 4 || !info[4].IsBoolean()) { + Napi::TypeError::New(env, "Direction flag expected").ThrowAsJavaScriptException(); + return; + } + else if (length > 5 && !info[5].IsUndefined() && !info[5].IsFunction()) { + Napi::TypeError::New(env, "Callback expected").ThrowAsJavaScriptException(); + return; + } + + this->db = Napi::ObjectWrap::Unwrap(info[0].As()); + this->db->Ref(); + + auto filename = info[1].As(); + auto sourceName = info[2].As(); + auto destName = info[3].As(); + auto filenameIsDest = info[4].As(); + + info.This().As().DefineProperty(Napi::PropertyDescriptor::Value("filename", filename)); + info.This().As().DefineProperty(Napi::PropertyDescriptor::Value("sourceName", sourceName)); + info.This().As().DefineProperty(Napi::PropertyDescriptor::Value("destName", destName)); + info.This().As().DefineProperty(Napi::PropertyDescriptor::Value("filenameIsDest", filenameIsDest)); + + auto* baton = new InitializeBaton(this->db, info[5].As(), this); + baton->filename = filename.Utf8Value(); + baton->sourceName = sourceName.Utf8Value(); + baton->destName = destName.Utf8Value(); + baton->filenameIsDest = filenameIsDest.Value(); + + this->db->Schedule(Work_BeginInitialize, baton); +} + +void Backup::Work_BeginInitialize(Database::Baton* baton) { + assert(baton->db->open); + baton->db->pending++; + auto env = baton->db->Env(); + CREATE_WORK("sqlite3.Backup.Initialize", Work_Initialize, Work_AfterInitialize); +} + +void Backup::Work_Initialize(napi_env e, void* data) { + BACKUP_INIT(InitializeBaton); + + // In case stepping fails, we use a mutex to make sure we get the associated + // error message. + auto* mtx = sqlite3_db_mutex(baton->db->_handle); + sqlite3_mutex_enter(mtx); + + backup->status = sqlite3_open(baton->filename.c_str(), &backup->_otherDb); + + if (backup->status == SQLITE_OK) { + backup->_handle = sqlite3_backup_init( + baton->filenameIsDest ? backup->_otherDb : backup->db->_handle, + baton->destName.c_str(), + baton->filenameIsDest ? backup->db->_handle : backup->_otherDb, + baton->sourceName.c_str()); + } + backup->_destDb = baton->filenameIsDest ? backup->_otherDb : backup->db->_handle; + + if (backup->status != SQLITE_OK) { + backup->message = std::string(sqlite3_errmsg(backup->_destDb)); + sqlite3_close(backup->_otherDb); + backup->_otherDb = NULL; + backup->_destDb = NULL; + } + + sqlite3_mutex_leave(mtx); +} + +void Backup::Work_AfterInitialize(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + auto* backup = baton->backup; + + auto env = backup->Env(); + Napi::HandleScope scope(env); + + if (backup->status != SQLITE_OK) { + Error(baton.get()); + backup->FinishAll(); + } + else { + backup->inited = true; + Napi::Function cb = baton->callback.Value(); + if (!cb.IsEmpty() && cb.IsFunction()) { + Napi::Value argv[] = { env.Null() }; + TRY_CATCH_CALL(backup->Value(), cb, 1, argv); + } + } + BACKUP_END(); +} + +Napi::Value Backup::Step(const Napi::CallbackInfo& info) { + auto* backup = this; + auto env = backup->Env(); + + REQUIRE_ARGUMENT_INTEGER(0, pages); + OPTIONAL_ARGUMENT_FUNCTION(1, callback); + + auto* baton = new StepBaton(backup, callback, pages); + backup->GetRetryErrors(baton->retryErrorsSet); + backup->Schedule(Work_BeginStep, baton); + return info.This(); +} + +void Backup::Work_BeginStep(Baton* baton) { + BACKUP_BEGIN(Step); +} + +void Backup::Work_Step(napi_env e, void* data) { + BACKUP_INIT(StepBaton); + if (backup->_handle) { + backup->status = sqlite3_backup_step(backup->_handle, baton->pages); + backup->remaining = sqlite3_backup_remaining(backup->_handle); + backup->pageCount = sqlite3_backup_pagecount(backup->_handle); + } + if (backup->status != SQLITE_OK) { + // Text of message is a little awkward to get, since the error is not associated + // with a db connection. +#if SQLITE_VERSION_NUMBER >= 3007015 + // sqlite3_errstr is a relatively new method + backup->message = std::string(sqlite3_errstr(backup->status)); +#else + backup->message = "Sqlite error"; +#endif + if (baton->retryErrorsSet.size() > 0) { + if (baton->retryErrorsSet.find(backup->status) == baton->retryErrorsSet.end()) { + backup->FinishSqlite(); + } + } + } +} + +void Backup::Work_AfterStep(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + auto* backup = baton->backup; + + auto env = backup->Env(); + Napi::HandleScope scope(env); + + if (backup->status == SQLITE_DONE) { + backup->completed = true; + } else if (!backup->_handle) { + backup->failed = true; + } + + if (backup->status != SQLITE_OK && backup->status != SQLITE_DONE) { + Error(baton.get()); + } + else { + // Fire callbacks. + Napi::Function cb = baton->callback.Value(); + if (!cb.IsEmpty() && cb.IsFunction()) { + Napi::Value argv[] = { env.Null(), Napi::Boolean::New(env, backup->status == SQLITE_DONE) }; + TRY_CATCH_CALL(backup->Value(), cb, 2, argv); + } + } + + BACKUP_END(); +} + +Napi::Value Backup::Finish(const Napi::CallbackInfo& info) { + auto* backup = this; + auto env = backup->Env(); + + OPTIONAL_ARGUMENT_FUNCTION(0, callback); + + auto* baton = new Baton(backup, callback); + backup->Schedule(Work_BeginFinish, baton); + return info.This(); +} + +void Backup::Work_BeginFinish(Baton* baton) { + BACKUP_BEGIN(Finish); +} + +void Backup::Work_Finish(napi_env e, void* data) { + BACKUP_INIT(Baton); + backup->FinishSqlite(); +} + +void Backup::Work_AfterFinish(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + auto* backup = baton->backup; + + auto env = backup->Env(); + Napi::HandleScope scope(env); + + backup->FinishAll(); + + // Fire callback in case there was one. + Napi::Function cb = baton->callback.Value(); + if (!cb.IsEmpty() && cb.IsFunction()) { + TRY_CATCH_CALL(backup->Value(), cb, 0, NULL); + } + + BACKUP_END(); +} + +void Backup::FinishAll() { + assert(!finished); + if (!completed && !failed) { + failed = true; + } + finished = true; + CleanQueue(); + FinishSqlite(); + db->Unref(); +} + +void Backup::FinishSqlite() { + if (_handle) { + sqlite3_backup_finish(_handle); + _handle = NULL; + } + if (_otherDb) { + sqlite3_close(_otherDb); + _otherDb = NULL; + } + _destDb = NULL; +} + +Napi::Value Backup::IdleGetter(const Napi::CallbackInfo& info) { + auto* backup = this; + bool idle = backup->inited && !backup->locked && backup->queue.empty(); + return Napi::Boolean::New(this->Env(), idle); +} + +Napi::Value Backup::CompletedGetter(const Napi::CallbackInfo& info) { + auto* backup = this; + return Napi::Boolean::New(this->Env(), backup->completed); +} + +Napi::Value Backup::FailedGetter(const Napi::CallbackInfo& info) { + auto* backup = this; + return Napi::Boolean::New(this->Env(), backup->failed); +} + +Napi::Value Backup::RemainingGetter(const Napi::CallbackInfo& info) { + auto* backup = this; + return Napi::Number::New(this->Env(), backup->remaining); +} + +Napi::Value Backup::PageCountGetter(const Napi::CallbackInfo& info) { + auto* backup = this; + return Napi::Number::New(this->Env(), backup->pageCount); +} + +Napi::Value Backup::RetryErrorGetter(const Napi::CallbackInfo& info) { + auto* backup = this; + return backup->retryErrors.Value(); +} + +void Backup::RetryErrorSetter(const Napi::CallbackInfo& info, const Napi::Value& value) { + auto* backup = this; + auto env = backup->Env(); + if (!value.IsArray()) { + Napi::Error::New(env, "retryErrors must be an array").ThrowAsJavaScriptException(); + return; + } + Napi::Array array = value.As(); + backup->retryErrors.Reset(array, 1); +} + +void Backup::GetRetryErrors(std::set& retryErrorsSet) { + retryErrorsSet.clear(); + Napi::Array array = retryErrors.Value(); + auto length = array.Length(); + for (size_t i = 0; i < length; i++) { + Napi::Value code = (array).Get(static_cast(i)); + if (code.IsNumber()) { + retryErrorsSet.insert(code.As().Int32Value()); + } + } +} diff --git a/updater/sql/mac/src/backup.h b/updater/sql/mac/src/backup.h new file mode 100755 index 0000000..b894aca --- /dev/null +++ b/updater/sql/mac/src/backup.h @@ -0,0 +1,209 @@ +#ifndef NODE_SQLITE3_SRC_BACKUP_H +#define NODE_SQLITE3_SRC_BACKUP_H + +#include "database.h" + +#include +#include +#include + +#include +#include + +using namespace Napi; + +namespace node_sqlite3 { + +/** + * + * A class for managing an sqlite3_backup object. For consistency + * with other node-sqlite3 classes, it maintains an internal queue + * of calls. + * + * Intended usage from node: + * + * var db = new sqlite3.Database('live.db'); + * var backup = db.backup('backup.db'); + * ... + * // in event loop, move backup forward when we have time. + * if (backup.idle) { backup.step(NPAGES); } + * if (backup.completed) { ... success ... } + * if (backup.failed) { ... sadness ... } + * // do other work in event loop - fine to modify live.db + * ... + * + * Here is how sqlite's backup api is exposed: + * + * - `sqlite3_backup_init`: This is implemented as + * `db.backup(filename, [callback])` or + * `db.backup(filename, destDbName, sourceDbName, filenameIsDest, [callback])`. + * - `sqlite3_backup_step`: `backup.step(pages, [callback])`. + * - `sqlite3_backup_finish`: `backup.finish([callback])`. + * - `sqlite3_backup_remaining`: `backup.remaining`. + * - `sqlite3_backup_pagecount`: `backup.pageCount`. + * + * There are the following read-only properties: + * + * - `backup.completed` is set to `true` when the backup + * succeeeds. + * - `backup.failed` is set to `true` when the backup + * has a fatal error. + * - `backup.idle` is set to `true` when no operation + * is currently in progress or queued for the backup. + * - `backup.remaining` is an integer with the remaining + * number of pages after the last call to `backup.step` + * (-1 if `step` not yet called). + * - `backup.pageCount` is an integer with the total number + * of pages measured during the last call to `backup.step` + * (-1 if `step` not yet called). + * + * There is the following writable property: + * + * - `backup.retryErrors`: an array of sqlite3 error codes + * that are treated as non-fatal - meaning, if they occur, + * backup.failed is not set, and the backup may continue. + * By default, this is `[sqlite3.BUSY, sqlite3.LOCKED]`. + * + * The `db.backup(filename, [callback])` shorthand is sufficient + * for making a backup of a database opened by node-sqlite3. If + * using attached or temporary databases, or moving data in the + * opposite direction, the more complete (but daunting) + * `db.backup(filename, destDbName, sourceDbName, filenameIsDest, [callback])` + * signature is provided. + * + * A backup will finish automatically when it succeeds or a fatal + * error occurs, meaning it is not necessary to call `db.finish()`. + * By default, SQLITE_LOCKED and SQLITE_BUSY errors are not + * treated as failures, and the backup will continue if they + * occur. The set of errors that are tolerated can be controlled + * by setting `backup.retryErrors`. To disable automatic + * finishing and stick strictly to sqlite's raw api, set + * `backup.retryErrors` to `[]`. In that case, it is necessary + * to call `backup.finish()`. + * + * In the same way as node-sqlite3 databases and statements, + * backup methods can be called safely without callbacks, due + * to an internal call queue. So for example this naive code + * will correctly back up a db, if there are no errors: + * + * var backup = db.backup('backup.db'); + * backup.step(-1); + * backup.finish(); + * + */ +class Backup : public Napi::ObjectWrap { +public: + static Napi::Object Init(Napi::Env env, Napi::Object exports); + + struct Baton { + napi_async_work request = NULL; + Backup* backup; + Napi::FunctionReference callback; + + Baton(Backup* backup_, Napi::Function cb_) : backup(backup_) { + backup->Ref(); + callback.Reset(cb_, 1); + } + virtual ~Baton() { + if (request) napi_delete_async_work(backup->Env(), request); + backup->Unref(); + callback.Reset(); + } + }; + + struct InitializeBaton : Database::Baton { + Backup* backup; + std::string filename; + std::string sourceName; + std::string destName; + bool filenameIsDest; + InitializeBaton(Database* db_, Napi::Function cb_, Backup* backup_) : + Baton(db_, cb_), backup(backup_), filenameIsDest(true) { + backup->Ref(); + } + virtual ~InitializeBaton() override { + backup->Unref(); + if (!db->IsOpen() && db->IsLocked()) { + // The database handle was closed before the backup could be opened. + backup->FinishAll(); + } + } + }; + + struct StepBaton : Baton { + int pages; + std::set retryErrorsSet; + StepBaton(Backup* backup_, Napi::Function cb_, int pages_) : + Baton(backup_, cb_), pages(pages_) {} + virtual ~StepBaton() override = default; + }; + + typedef void (*Work_Callback)(Baton* baton); + + struct Call { + Call(Work_Callback cb_, Baton* baton_) : callback(cb_), baton(baton_) {}; + Work_Callback callback; + Baton* baton; + }; + + Backup(const Napi::CallbackInfo& info); + + ~Backup() { + if (!finished) { + FinishAll(); + } + retryErrors.Reset(); + } + + WORK_DEFINITION(Step) + WORK_DEFINITION(Finish) + + Napi::Value IdleGetter(const Napi::CallbackInfo& info); + Napi::Value CompletedGetter(const Napi::CallbackInfo& info); + Napi::Value FailedGetter(const Napi::CallbackInfo& info); + Napi::Value PageCountGetter(const Napi::CallbackInfo& info); + Napi::Value RemainingGetter(const Napi::CallbackInfo& info); + Napi::Value FatalErrorGetter(const Napi::CallbackInfo& info); + Napi::Value RetryErrorGetter(const Napi::CallbackInfo& info); + + void FatalErrorSetter(const Napi::CallbackInfo& info, const Napi::Value& value); + void RetryErrorSetter(const Napi::CallbackInfo& info, const Napi::Value& value); + +protected: + static void Work_BeginInitialize(Database::Baton* baton); + static void Work_Initialize(napi_env env, void* data); + static void Work_AfterInitialize(napi_env env, napi_status status, void* data); + + void Schedule(Work_Callback callback, Baton* baton); + void Process(); + void CleanQueue(); + template static void Error(T* baton); + + void FinishAll(); + void FinishSqlite(); + void GetRetryErrors(std::set& retryErrorsSet); + + Database* db; + + sqlite3_backup* _handle = NULL; + sqlite3* _otherDb = NULL; + sqlite3* _destDb = NULL; + + bool inited = false; + bool locked = true; + bool completed = false; + bool failed = false; + int remaining = -1; + int pageCount = -1; + bool finished = false; + + int status; + std::string message; + std::queue> queue; + + Napi::Reference retryErrors; +}; + +} + +#endif diff --git a/updater/sql/mac/src/database.cc b/updater/sql/mac/src/database.cc new file mode 100755 index 0000000..d495ce9 --- /dev/null +++ b/updater/sql/mac/src/database.cc @@ -0,0 +1,751 @@ +#include +#include + +#include "macros.h" +#include "database.h" +#include "statement.h" + +using namespace node_sqlite3; + +#if NAPI_VERSION < 6 +Napi::FunctionReference Database::constructor; +#endif + +Napi::Object Database::Init(Napi::Env env, Napi::Object exports) { + Napi::HandleScope scope(env); + // declare napi_default_method here as it is only available in Node v14.12.0+ + auto napi_default_method = static_cast(napi_writable | napi_configurable); + + auto t = DefineClass(env, "Database", { + InstanceMethod("close", &Database::Close, napi_default_method), + InstanceMethod("exec", &Database::Exec, napi_default_method), + InstanceMethod("wait", &Database::Wait, napi_default_method), + InstanceMethod("loadExtension", &Database::LoadExtension, napi_default_method), + InstanceMethod("serialize", &Database::Serialize, napi_default_method), + InstanceMethod("parallelize", &Database::Parallelize, napi_default_method), + InstanceMethod("configure", &Database::Configure, napi_default_method), + InstanceMethod("interrupt", &Database::Interrupt, napi_default_method), + InstanceAccessor("open", &Database::Open, nullptr) + }); + +#if NAPI_VERSION < 6 + constructor = Napi::Persistent(t); + constructor.SuppressDestruct(); +#else + Napi::FunctionReference* constructor = new Napi::FunctionReference(); + *constructor = Napi::Persistent(t); + env.SetInstanceData(constructor); +#endif + + exports.Set("Database", t); + return exports; +} + +void Database::Process() { + auto env = this->Env(); + Napi::HandleScope scope(env); + + if (!open && locked && !queue.empty()) { + EXCEPTION(Napi::String::New(env, "Database handle is closed"), SQLITE_MISUSE, exception); + Napi::Value argv[] = { exception }; + bool called = false; + + // Call all callbacks with the error object. + while (!queue.empty()) { + auto call = std::unique_ptr(queue.front()); + queue.pop(); + auto baton = std::unique_ptr(call->baton); + Napi::Function cb = baton->callback.Value(); + if (IS_FUNCTION(cb)) { + TRY_CATCH_CALL(this->Value(), cb, 1, argv); + called = true; + } + } + + // When we couldn't call a callback function, emit an error on the + // Database object. + if (!called) { + Napi::Value info[] = { Napi::String::New(env, "error"), exception }; + EMIT_EVENT(Value(), 2, info); + } + return; + } + + while (open && (!locked || pending == 0) && !queue.empty()) { + Call *c = queue.front(); + + if (c->exclusive && pending > 0) { + break; + } + + queue.pop(); + std::unique_ptr call(c); + locked = call->exclusive; + call->callback(call->baton); + + if (locked) break; + } +} + +void Database::Schedule(Work_Callback callback, Baton* baton, bool exclusive) { + auto env = this->Env(); + Napi::HandleScope scope(env); + + if (!open && locked) { + EXCEPTION(Napi::String::New(env, "Database is closed"), SQLITE_MISUSE, exception); + Napi::Function cb = baton->callback.Value(); + // We don't call the actual callback, so we have to make sure that + // the baton gets destroyed. + delete baton; + if (IS_FUNCTION(cb)) { + Napi::Value argv[] = { exception }; + TRY_CATCH_CALL(Value(), cb, 1, argv); + } + else { + Napi::Value argv[] = { Napi::String::New(env, "error"), exception }; + EMIT_EVENT(Value(), 2, argv); + } + return; + } + + if (!open || ((locked || exclusive || serialize) && pending > 0)) { + queue.emplace(new Call(callback, baton, exclusive || serialize)); + } + else { + locked = exclusive; + callback(baton); + } +} + +Database::Database(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { + auto env = info.Env(); + + if (info.Length() <= 0 || !info[0].IsString()) { + Napi::TypeError::New(env, "String expected").ThrowAsJavaScriptException(); + return; + } + auto filename = info[0].As().Utf8Value(); + + unsigned int pos = 1; + + int mode; + if (info.Length() >= pos && info[pos].IsNumber() && OtherIsInt(info[pos].As())) { + mode = info[pos++].As().Int32Value(); + } + else { + mode = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX; + } + + Napi::Function callback; + if (info.Length() >= pos && info[pos].IsFunction()) { + callback = info[pos++].As(); + } + + info.This().As().DefineProperty(Napi::PropertyDescriptor::Value("filename", info[0].As(), napi_default)); + info.This().As().DefineProperty(Napi::PropertyDescriptor::Value("mode", Napi::Number::New(env, mode), napi_default)); + + // Start opening the database. + auto* baton = new OpenBaton(this, callback, filename.c_str(), mode); + Work_BeginOpen(baton); +} + +void Database::Work_BeginOpen(Baton* baton) { + auto env = baton->db->Env(); + CREATE_WORK("sqlite3.Database.Open", Work_Open, Work_AfterOpen); +} + +void Database::Work_Open(napi_env e, void* data) { + auto* baton = static_cast(data); + auto* db = baton->db; + + baton->status = sqlite3_open_v2( + baton->filename.c_str(), + &db->_handle, + baton->mode, + NULL + ); + + if (baton->status != SQLITE_OK) { + baton->message = std::string(sqlite3_errmsg(db->_handle)); + sqlite3_close(db->_handle); + db->_handle = NULL; + } + else { + // Set default database handle values. + sqlite3_busy_timeout(db->_handle, 1000); + } +} + +void Database::Work_AfterOpen(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + + auto* db = baton->db; + + auto env = db->Env(); + Napi::HandleScope scope(env); + + Napi::Value argv[1]; + if (baton->status != SQLITE_OK) { + EXCEPTION(Napi::String::New(env, baton->message.c_str()), baton->status, exception); + argv[0] = exception; + } + else { + db->open = true; + argv[0] = env.Null(); + } + + Napi::Function cb = baton->callback.Value(); + + if (IS_FUNCTION(cb)) { + TRY_CATCH_CALL(db->Value(), cb, 1, argv); + } + else if (!db->open) { + Napi::Value info[] = { Napi::String::New(env, "error"), argv[0] }; + EMIT_EVENT(db->Value(), 2, info); + } + + if (db->open) { + Napi::Value info[] = { Napi::String::New(env, "open") }; + EMIT_EVENT(db->Value(), 1, info); + db->Process(); + } +} + +Napi::Value Database::Open(const Napi::CallbackInfo& info) { + auto env = this->Env(); + auto* db = this; + return Napi::Boolean::New(env, db->open); +} + +Napi::Value Database::Close(const Napi::CallbackInfo& info) { + auto env = info.Env(); + auto* db = this; + OPTIONAL_ARGUMENT_FUNCTION(0, callback); + + auto* baton = new Baton(db, callback); + db->Schedule(Work_BeginClose, baton, true); + + return info.This(); +} + +void Database::Work_BeginClose(Baton* baton) { + assert(baton->db->locked); + assert(baton->db->open); + assert(baton->db->_handle); + assert(baton->db->pending == 0); + + baton->db->pending++; + baton->db->RemoveCallbacks(); + baton->db->closing = true; + + auto env = baton->db->Env(); + CREATE_WORK("sqlite3.Database.Close", Work_Close, Work_AfterClose); +} + +void Database::Work_Close(napi_env e, void* data) { + auto* baton = static_cast(data); + auto* db = baton->db; + + baton->status = sqlite3_close(db->_handle); + + if (baton->status != SQLITE_OK) { + baton->message = std::string(sqlite3_errmsg(db->_handle)); + } + else { + db->_handle = NULL; + } +} + +void Database::Work_AfterClose(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + + auto* db = baton->db; + + auto env = db->Env(); + Napi::HandleScope scope(env); + + db->pending--; + db->closing = false; + + Napi::Value argv[1]; + if (baton->status != SQLITE_OK) { + EXCEPTION(Napi::String::New(env, baton->message.c_str()), baton->status, exception); + argv[0] = exception; + } + else { + db->open = false; + // Leave db->locked to indicate that this db object has reached + // the end of its life. + argv[0] = env.Null(); + } + + Napi::Function cb = baton->callback.Value(); + + // Fire callbacks. + if (IS_FUNCTION(cb)) { + TRY_CATCH_CALL(db->Value(), cb, 1, argv); + } + else if (db->open) { + Napi::Value info[] = { Napi::String::New(env, "error"), argv[0] }; + EMIT_EVENT(db->Value(), 2, info); + } + + if (!db->open) { + Napi::Value info[] = { Napi::String::New(env, "close") }; + EMIT_EVENT(db->Value(), 1, info); + db->Process(); + } +} + +Napi::Value Database::Serialize(const Napi::CallbackInfo& info) { + auto env = this->Env(); + auto* db = this; + OPTIONAL_ARGUMENT_FUNCTION(0, callback); + + bool before = db->serialize; + db->serialize = true; + + if (!callback.IsEmpty() && callback.IsFunction()) { + TRY_CATCH_CALL(info.This(), callback, 0, NULL, info.This()); + db->serialize = before; + } + + db->Process(); + + return info.This(); +} + +Napi::Value Database::Parallelize(const Napi::CallbackInfo& info) { + auto env = this->Env(); + auto* db = this; + OPTIONAL_ARGUMENT_FUNCTION(0, callback); + + auto before = db->serialize; + db->serialize = false; + + if (!callback.IsEmpty() && callback.IsFunction()) { + TRY_CATCH_CALL(info.This(), callback, 0, NULL, info.This()); + db->serialize = before; + } + + db->Process(); + + return info.This(); +} + +Napi::Value Database::Configure(const Napi::CallbackInfo& info) { + auto env = this->Env(); + auto* db = this; + + REQUIRE_ARGUMENTS(2); + + Napi::Function handle; + if (info[0].StrictEquals( Napi::String::New(env, "trace"))) { + auto* baton = new Baton(db, handle); + db->Schedule(RegisterTraceCallback, baton); + } + else if (info[0].StrictEquals( Napi::String::New(env, "profile"))) { + auto* baton = new Baton(db, handle); + db->Schedule(RegisterProfileCallback, baton); + } + else if (info[0].StrictEquals( Napi::String::New(env, "busyTimeout"))) { + if (!info[1].IsNumber()) { + Napi::TypeError::New(env, "Value must be an integer").ThrowAsJavaScriptException(); + return env.Null(); + } + auto* baton = new Baton(db, handle); + baton->status = info[1].As().Int32Value(); + db->Schedule(SetBusyTimeout, baton); + } + else if (info[0].StrictEquals( Napi::String::New(env, "limit"))) { + REQUIRE_ARGUMENTS(3); + if (!info[1].IsNumber()) { + Napi::TypeError::New(env, "limit id must be an integer").ThrowAsJavaScriptException(); + return env.Null(); + } + if (!info[2].IsNumber()) { + Napi::TypeError::New(env, "limit value must be an integer").ThrowAsJavaScriptException(); + return env.Null(); + } + int id = info[1].As().Int32Value(); + int value = info[2].As().Int32Value(); + Baton* baton = new LimitBaton(db, handle, id, value); + db->Schedule(SetLimit, baton); + } + else if (info[0].StrictEquals(Napi::String::New(env, "change"))) { + auto* baton = new Baton(db, handle); + db->Schedule(RegisterUpdateCallback, baton); + } + else { + Napi::TypeError::New(env, (StringConcat( +#if V8_MAJOR_VERSION > 6 + info.GetIsolate(), +#endif + info[0].As(), + Napi::String::New(env, " is not a valid configuration option") + )).Utf8Value().c_str()).ThrowAsJavaScriptException(); + return env.Null(); + } + + db->Process(); + + return info.This(); +} + +Napi::Value Database::Interrupt(const Napi::CallbackInfo& info) { + auto env = this->Env(); + auto* db = this; + + if (!db->open) { + Napi::Error::New(env, "Database is not open").ThrowAsJavaScriptException(); + return env.Null(); + } + + if (db->closing) { + Napi::Error::New(env, "Database is closing").ThrowAsJavaScriptException(); + return env.Null(); + } + + sqlite3_interrupt(db->_handle); + return info.This(); +} + +void Database::SetBusyTimeout(Baton* b) { + auto baton = std::unique_ptr(b); + + assert(baton->db->open); + assert(baton->db->_handle); + + // Abuse the status field for passing the timeout. + sqlite3_busy_timeout(baton->db->_handle, baton->status); +} + +void Database::SetLimit(Baton* b) { + std::unique_ptr baton(static_cast(b)); + + assert(baton->db->open); + assert(baton->db->_handle); + + sqlite3_limit(baton->db->_handle, baton->id, baton->value); +} + +void Database::RegisterTraceCallback(Baton* b) { + auto baton = std::unique_ptr(b); + assert(baton->db->open); + assert(baton->db->_handle); + auto* db = baton->db; + + if (db->debug_trace == NULL) { + // Add it. + db->debug_trace = new AsyncTrace(db, TraceCallback); + sqlite3_trace(db->_handle, TraceCallback, db); + } + else { + // Remove it. + sqlite3_trace(db->_handle, NULL, NULL); + db->debug_trace->finish(); + db->debug_trace = NULL; + } +} + +void Database::TraceCallback(void* db, const char* sql) { + // Note: This function is called in the thread pool. + // Note: Some queries, such as "EXPLAIN" queries, are not sent through this. + static_cast(db)->debug_trace->send(new std::string(sql)); +} + +void Database::TraceCallback(Database* db, std::string* s) { + std::unique_ptr sql(s); + // Note: This function is called in the main V8 thread. + auto env = db->Env(); + Napi::HandleScope scope(env); + + Napi::Value argv[] = { + Napi::String::New(env, "trace"), + Napi::String::New(env, sql->c_str()) + }; + EMIT_EVENT(db->Value(), 2, argv); +} + +void Database::RegisterProfileCallback(Baton* b) { + auto baton = std::unique_ptr(b); + assert(baton->db->open); + assert(baton->db->_handle); + auto* db = baton->db; + + if (db->debug_profile == NULL) { + // Add it. + db->debug_profile = new AsyncProfile(db, ProfileCallback); + sqlite3_profile(db->_handle, ProfileCallback, db); + } + else { + // Remove it. + sqlite3_profile(db->_handle, NULL, NULL); + db->debug_profile->finish(); + db->debug_profile = NULL; + } +} + +void Database::ProfileCallback(void* db, const char* sql, sqlite3_uint64 nsecs) { + // Note: This function is called in the thread pool. + // Note: Some queries, such as "EXPLAIN" queries, are not sent through this. + auto* info = new ProfileInfo(); + info->sql = std::string(sql); + info->nsecs = nsecs; + static_cast(db)->debug_profile->send(info); +} + +void Database::ProfileCallback(Database *db, ProfileInfo* i) { + auto info = std::unique_ptr(i); + auto env = db->Env(); + Napi::HandleScope scope(env); + + Napi::Value argv[] = { + Napi::String::New(env, "profile"), + Napi::String::New(env, info->sql.c_str()), + Napi::Number::New(env, (double)info->nsecs / 1000000.0) + }; + EMIT_EVENT(db->Value(), 3, argv); +} + +void Database::RegisterUpdateCallback(Baton* b) { + auto baton = std::unique_ptr(b); + assert(baton->db->open); + assert(baton->db->_handle); + auto* db = baton->db; + + if (db->update_event == NULL) { + // Add it. + db->update_event = new AsyncUpdate(db, UpdateCallback); + sqlite3_update_hook(db->_handle, UpdateCallback, db); + } + else { + // Remove it. + sqlite3_update_hook(db->_handle, NULL, NULL); + db->update_event->finish(); + db->update_event = NULL; + } +} + +void Database::UpdateCallback(void* db, int type, const char* database, + const char* table, sqlite3_int64 rowid) { + // Note: This function is called in the thread pool. + // Note: Some queries, such as "EXPLAIN" queries, are not sent through this. + auto* info = new UpdateInfo(); + info->type = type; + info->database = std::string(database); + info->table = std::string(table); + info->rowid = rowid; + static_cast(db)->update_event->send(info); +} + +void Database::UpdateCallback(Database *db, UpdateInfo* i) { + auto info = std::unique_ptr(i); + auto env = db->Env(); + Napi::HandleScope scope(env); + + Napi::Value argv[] = { + Napi::String::New(env, "change"), + Napi::String::New(env, sqlite_authorizer_string(info->type)), + Napi::String::New(env, info->database.c_str()), + Napi::String::New(env, info->table.c_str()), + Napi::Number::New(env, info->rowid), + }; + EMIT_EVENT(db->Value(), 5, argv); +} + +Napi::Value Database::Exec(const Napi::CallbackInfo& info) { + auto env = this->Env(); + auto* db = this; + + REQUIRE_ARGUMENT_STRING(0, sql); + OPTIONAL_ARGUMENT_FUNCTION(1, callback); + + Baton* baton = new ExecBaton(db, callback, sql.c_str()); + db->Schedule(Work_BeginExec, baton, true); + + return info.This(); +} + +void Database::Work_BeginExec(Baton* baton) { + assert(baton->db->locked); + assert(baton->db->open); + assert(baton->db->_handle); + assert(baton->db->pending == 0); + baton->db->pending++; + + auto env = baton->db->Env(); + CREATE_WORK("sqlite3.Database.Exec", Work_Exec, Work_AfterExec); +} + +void Database::Work_Exec(napi_env e, void* data) { + auto* baton = static_cast(data); + + char* message = NULL; + baton->status = sqlite3_exec( + baton->db->_handle, + baton->sql.c_str(), + NULL, + NULL, + &message + ); + + if (baton->status != SQLITE_OK && message != NULL) { + baton->message = std::string(message); + sqlite3_free(message); + } +} + +void Database::Work_AfterExec(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + + auto* db = baton->db; + db->pending--; + + auto env = db->Env(); + Napi::HandleScope scope(env); + + Napi::Function cb = baton->callback.Value(); + + if (baton->status != SQLITE_OK) { + EXCEPTION(Napi::String::New(env, baton->message.c_str()), baton->status, exception); + + if (IS_FUNCTION(cb)) { + Napi::Value argv[] = { exception }; + TRY_CATCH_CALL(db->Value(), cb, 1, argv); + } + else { + Napi::Value info[] = { Napi::String::New(env, "error"), exception }; + EMIT_EVENT(db->Value(), 2, info); + } + } + else if (IS_FUNCTION(cb)) { + Napi::Value argv[] = { env.Null() }; + TRY_CATCH_CALL(db->Value(), cb, 1, argv); + } + + db->Process(); +} + +Napi::Value Database::Wait(const Napi::CallbackInfo& info) { + auto env = info.Env(); + auto* db = this; + + OPTIONAL_ARGUMENT_FUNCTION(0, callback); + + auto* baton = new Baton(db, callback); + db->Schedule(Work_Wait, baton, true); + + return info.This(); +} + +void Database::Work_Wait(Baton* b) { + auto baton = std::unique_ptr(b); + + auto env = baton->db->Env(); + Napi::HandleScope scope(env); + + assert(baton->db->locked); + assert(baton->db->open); + assert(baton->db->_handle); + assert(baton->db->pending == 0); + + Napi::Function cb = baton->callback.Value(); + if (IS_FUNCTION(cb)) { + Napi::Value argv[] = { env.Null() }; + TRY_CATCH_CALL(baton->db->Value(), cb, 1, argv); + } + + baton->db->Process(); +} + +Napi::Value Database::LoadExtension(const Napi::CallbackInfo& info) { + auto env = this->Env(); + auto* db = this; + + REQUIRE_ARGUMENT_STRING(0, filename); + OPTIONAL_ARGUMENT_FUNCTION(1, callback); + + Baton* baton = new LoadExtensionBaton(db, callback, filename.c_str()); + db->Schedule(Work_BeginLoadExtension, baton, true); + + return info.This(); +} + +void Database::Work_BeginLoadExtension(Baton* baton) { + assert(baton->db->locked); + assert(baton->db->open); + assert(baton->db->_handle); + assert(baton->db->pending == 0); + baton->db->pending++; + + auto env = baton->db->Env(); + CREATE_WORK("sqlite3.Database.LoadExtension", Work_LoadExtension, Work_AfterLoadExtension); +} + +void Database::Work_LoadExtension(napi_env e, void* data) { + auto* baton = static_cast(data); + + sqlite3_enable_load_extension(baton->db->_handle, 1); + + char* message = NULL; + baton->status = sqlite3_load_extension( + baton->db->_handle, + baton->filename.c_str(), + 0, + &message + ); + + sqlite3_enable_load_extension(baton->db->_handle, 0); + + if (baton->status != SQLITE_OK && message != NULL) { + baton->message = std::string(message); + sqlite3_free(message); + } +} + +void Database::Work_AfterLoadExtension(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + + auto* db = baton->db; + db->pending--; + + auto env = db->Env(); + Napi::HandleScope scope(env); + + Napi::Function cb = baton->callback.Value(); + + if (baton->status != SQLITE_OK) { + EXCEPTION(Napi::String::New(env, baton->message.c_str()), baton->status, exception); + + if (IS_FUNCTION(cb)) { + Napi::Value argv[] = { exception }; + TRY_CATCH_CALL(db->Value(), cb, 1, argv); + } + else { + Napi::Value info[] = { Napi::String::New(env, "error"), exception }; + EMIT_EVENT(db->Value(), 2, info); + } + } + else if (IS_FUNCTION(cb)) { + Napi::Value argv[] = { env.Null() }; + TRY_CATCH_CALL(db->Value(), cb, 1, argv); + } + + db->Process(); +} + +void Database::RemoveCallbacks() { + if (debug_trace) { + debug_trace->finish(); + debug_trace = NULL; + } + if (debug_profile) { + debug_profile->finish(); + debug_profile = NULL; + } + if (update_event) { + update_event->finish(); + update_event = NULL; + } +} diff --git a/updater/sql/mac/src/database.h b/updater/sql/mac/src/database.h new file mode 100755 index 0000000..8ffd300 --- /dev/null +++ b/updater/sql/mac/src/database.h @@ -0,0 +1,188 @@ + +#ifndef NODE_SQLITE3_SRC_DATABASE_H +#define NODE_SQLITE3_SRC_DATABASE_H + + +#include +#include +#include + +#include +#include + +#include "async.h" + +using namespace Napi; + +namespace node_sqlite3 { + +class Database; + + +class Database : public Napi::ObjectWrap { +public: +#if NAPI_VERSION < 6 + static Napi::FunctionReference constructor; +#endif + static Napi::Object Init(Napi::Env env, Napi::Object exports); + + static inline bool HasInstance(Napi::Value val) { + auto env = val.Env(); + Napi::HandleScope scope(env); + if (!val.IsObject()) return false; + auto obj = val.As(); +#if NAPI_VERSION < 6 + return obj.InstanceOf(constructor.Value()); +#else + auto constructor = + env.GetInstanceData(); + return obj.InstanceOf(constructor->Value()); +#endif + } + + struct Baton { + napi_async_work request = NULL; + Database* db; + Napi::FunctionReference callback; + int status; + std::string message; + + Baton(Database* db_, Napi::Function cb_) : + db(db_), status(SQLITE_OK) { + db->Ref(); + if (!cb_.IsUndefined() && cb_.IsFunction()) { + callback.Reset(cb_, 1); + } + } + virtual ~Baton() { + if (request) napi_delete_async_work(db->Env(), request); + db->Unref(); + callback.Reset(); + } + }; + + struct OpenBaton : Baton { + std::string filename; + int mode; + OpenBaton(Database* db_, Napi::Function cb_, const char* filename_, int mode_) : + Baton(db_, cb_), filename(filename_), mode(mode_) {} + virtual ~OpenBaton() override = default; + }; + + struct ExecBaton : Baton { + std::string sql; + ExecBaton(Database* db_, Napi::Function cb_, const char* sql_) : + Baton(db_, cb_), sql(sql_) {} + virtual ~ExecBaton() override = default; + }; + + struct LoadExtensionBaton : Baton { + std::string filename; + LoadExtensionBaton(Database* db_, Napi::Function cb_, const char* filename_) : + Baton(db_, cb_), filename(filename_) {} + virtual ~LoadExtensionBaton() override = default; + }; + + struct LimitBaton : Baton { + int id; + int value; + LimitBaton(Database* db_, Napi::Function cb_, int id_, int value_) : + Baton(db_, cb_), id(id_), value(value_) {} + virtual ~LimitBaton() override = default; + }; + + typedef void (*Work_Callback)(Baton* baton); + + struct Call { + Call(Work_Callback cb_, Baton* baton_, bool exclusive_ = false) : + callback(cb_), exclusive(exclusive_), baton(baton_) {}; + Work_Callback callback; + bool exclusive; + Baton* baton; + }; + + struct ProfileInfo { + std::string sql; + sqlite3_int64 nsecs; + }; + + struct UpdateInfo { + int type; + std::string database; + std::string table; + sqlite3_int64 rowid; + }; + + bool IsOpen() { return open; } + bool IsLocked() { return locked; } + + typedef Async AsyncTrace; + typedef Async AsyncProfile; + typedef Async AsyncUpdate; + + friend class Statement; + friend class Backup; + + Database(const Napi::CallbackInfo& info); + + ~Database() { + RemoveCallbacks(); + sqlite3_close(_handle); + _handle = NULL; + open = false; + } + +protected: + WORK_DEFINITION(Open); + WORK_DEFINITION(Exec); + WORK_DEFINITION(Close); + WORK_DEFINITION(LoadExtension); + + void Schedule(Work_Callback callback, Baton* baton, bool exclusive = false); + void Process(); + + Napi::Value Wait(const Napi::CallbackInfo& info); + static void Work_Wait(Baton* baton); + + Napi::Value Serialize(const Napi::CallbackInfo& info); + Napi::Value Parallelize(const Napi::CallbackInfo& info); + Napi::Value Configure(const Napi::CallbackInfo& info); + Napi::Value Interrupt(const Napi::CallbackInfo& info); + + static void SetBusyTimeout(Baton* baton); + static void SetLimit(Baton* baton); + + static void RegisterTraceCallback(Baton* baton); + static void TraceCallback(void* db, const char* sql); + static void TraceCallback(Database* db, std::string* sql); + + static void RegisterProfileCallback(Baton* baton); + static void ProfileCallback(void* db, const char* sql, sqlite3_uint64 nsecs); + static void ProfileCallback(Database* db, ProfileInfo* info); + + static void RegisterUpdateCallback(Baton* baton); + static void UpdateCallback(void* db, int type, const char* database, const char* table, sqlite3_int64 rowid); + static void UpdateCallback(Database* db, UpdateInfo* info); + + void RemoveCallbacks(); + +protected: + sqlite3* _handle = NULL; + + bool open = false; + bool closing = false; + bool locked = false; + unsigned int pending = 0; + + bool serialize = false; + + std::queue queue; + + AsyncTrace* debug_trace = NULL; + AsyncProfile* debug_profile = NULL; + AsyncUpdate* update_event = NULL; +}; + +} + +#endif diff --git a/updater/sql/mac/src/gcc-preinclude.h b/updater/sql/mac/src/gcc-preinclude.h new file mode 100755 index 0000000..7a52a4d --- /dev/null +++ b/updater/sql/mac/src/gcc-preinclude.h @@ -0,0 +1,30 @@ +// http://web.archive.org/web/20140401031018/http://rjpower9000.wordpress.com:80/2012/04/09/fun-with-shared-libraries-version-glibc_2-14-not-found/ + +#if defined(__linux__) + +#define _GNU_SOURCE +#include +#undef _GNU_SOURCE + +#if defined(__USE_GNU) + +#if defined(__x86_64__) +__asm__(".symver memcpy,memcpy@GLIBC_2.2.5"); +__asm__(".symver exp,exp@GLIBC_2.2.5"); +__asm__(".symver log,log@GLIBC_2.2.5"); +__asm__(".symver log2,log2@GLIBC_2.2.5"); +__asm__(".symver pow,pow@GLIBC_2.2.5"); +__asm__(".symver fcntl64,fcntl@GLIBC_2.2.5"); +#endif + +#if defined(__aarch64__) || defined(_M_ARM64) +__asm__(".symver memcpy,memcpy@GLIBC_2.17"); +__asm__(".symver exp,exp@GLIBC_2.17"); +__asm__(".symver log,log@GLIBC_2.17"); +__asm__(".symver log2,log2@GLIBC_2.17"); +__asm__(".symver pow,pow@GLIBC_2.17"); +__asm__(".symver fcntl64,fcntl@GLIBC_2.17"); +#endif + +#endif +#endif diff --git a/updater/sql/mac/src/macros.h b/updater/sql/mac/src/macros.h new file mode 100755 index 0000000..3bcde83 --- /dev/null +++ b/updater/sql/mac/src/macros.h @@ -0,0 +1,207 @@ +#ifndef NODE_SQLITE3_SRC_MACROS_H +#define NODE_SQLITE3_SRC_MACROS_H + +const char* sqlite_code_string(int code); +const char* sqlite_authorizer_string(int type); +#include + +// TODO: better way to work around StringConcat? +#include +inline Napi::String StringConcat(Napi::Value str1, Napi::Value str2) { + return Napi::String::New(str1.Env(), str1.As().Utf8Value() + + str2.As().Utf8Value() ); +} + +// A Napi substitute IsInt32() +inline bool OtherIsInt(Napi::Number source) { + double orig_val = source.DoubleValue(); + double int_val = static_cast(source.Int32Value()); + if (orig_val == int_val) { + return true; + } else { + return false; + } +} + +#define IS_FUNCTION(cb) \ + !cb.IsUndefined() && cb.IsFunction() + +#define REQUIRE_ARGUMENTS(n) \ + if (info.Length() < (n)) { \ + Napi::TypeError::New(env, "Expected " #n "arguments").ThrowAsJavaScriptException(); \ + return env.Null(); \ + } + + +#define REQUIRE_ARGUMENT_EXTERNAL(i, var) \ + if (info.Length() <= (i) || !info[i].IsExternal()) { \ + Napi::TypeError::New(env, "Argument " #i " invalid").ThrowAsJavaScriptException(); \ + return env.Null(); \ + } \ + Napi::External var = info[i].As(); + + +#define REQUIRE_ARGUMENT_FUNCTION(i, var) \ + if (info.Length() <= (i) || !info[i].IsFunction()) { \ + Napi::TypeError::New(env, "Argument " #i " must be a function").ThrowAsJavaScriptException(); \ + return env.Null(); \ + } \ + Napi::Function var = info[i].As(); + + +#define REQUIRE_ARGUMENT_STRING(i, var) \ + if (info.Length() <= (i) || !info[i].IsString()) { \ + Napi::TypeError::New(env, "Argument " #i " must be a string").ThrowAsJavaScriptException(); \ + return env.Null(); \ + } \ + std::string var = info[i].As(); + +#define REQUIRE_ARGUMENT_INTEGER(i, var) \ + if (info.Length() <= (i) || !info[i].IsNumber()) { \ + Napi::TypeError::New(env, "Argument " #i " must be an integer").ThrowAsJavaScriptException(); \ + return env.Null(); \ + } \ + int var(info[i].As().Int32Value()); + +#define OPTIONAL_ARGUMENT_FUNCTION(i, var) \ + Napi::Function var; \ + if (info.Length() > i && !info[i].IsUndefined()) { \ + if (!info[i].IsFunction()) { \ + Napi::TypeError::New(env, "Argument " #i " must be a function").ThrowAsJavaScriptException(); \ + return env.Null(); \ + } \ + var = info[i].As(); \ + } + + +#define OPTIONAL_ARGUMENT_INTEGER(i, var, default) \ + int var; \ + if (info.Length() <= (i)) { \ + var = (default); \ + } \ + else if (info[i].IsNumber()) { \ + if (OtherIsInt(info[i].As())) { \ + var = info[i].As().Int32Value(); \ + } \ + } \ + else { \ + Napi::TypeError::New(env, "Argument " #i " must be an integer").ThrowAsJavaScriptException(); \ + return env.Null(); \ + } + + +#define DEFINE_CONSTANT_INTEGER(target, constant, name) \ + Napi::PropertyDescriptor::Value(#name, Napi::Number::New(env, constant), \ + static_cast(napi_enumerable | napi_configurable)), + +#define DEFINE_CONSTANT_STRING(target, constant, name) \ + Napi::PropertyDescriptor::Value(#name, Napi::String::New(env, constant), \ + static_cast(napi_enumerable | napi_configurable)), + +#define EXCEPTION(msg, errno, name) \ + Napi::Value name = Napi::Error::New(env, \ + StringConcat( \ + StringConcat( \ + Napi::String::New(env, sqlite_code_string(errno)), \ + Napi::String::New(env, ": ") \ + ), \ + (msg) \ + ).Utf8Value() \ + ).Value(); \ + Napi::Object name ##_obj = name.As(); \ + (name ##_obj).Set( Napi::String::New(env, "errno"), Napi::Number::New(env, errno)); \ + (name ##_obj).Set( Napi::String::New(env, "code"), \ + Napi::String::New(env, sqlite_code_string(errno))); + + +#define EMIT_EVENT(obj, argc, argv) \ + TRY_CATCH_CALL((obj), \ + (obj).Get("emit").As(),\ + argc, argv \ + ); + +// The Mac OS compiler complains when argv is NULL unless we +// first assign it to a locally defined variable. +#define TRY_CATCH_CALL(context, callback, argc, argv, ...) \ + Napi::Value* passed_argv = argv;\ + std::vector args;\ + if ((argc != 0) && (passed_argv != NULL)) {\ + args.assign(passed_argv, passed_argv + argc);\ + }\ + Napi::Value res = (callback).Call(Napi::Value(context), args); \ + if (res.IsEmpty()) return __VA_ARGS__; + +#define WORK_DEFINITION(name) \ + Napi::Value name(const Napi::CallbackInfo& info); \ + static void Work_Begin##name(Baton* baton); \ + static void Work_##name(napi_env env, void* data); \ + static void Work_After##name(napi_env env, napi_status status, void* data); + +#ifdef DEBUG + #define ASSERT_STATUS() assert(status == 0); +#else + #define ASSERT_STATUS() (void)status; +#endif + +#define CREATE_WORK(name, workerFn, afterFn) \ + int status = napi_create_async_work(env, NULL, Napi::String::New(env, name),\ + workerFn, afterFn, baton, &baton->request); \ + \ + ASSERT_STATUS(); \ + napi_queue_async_work(env, baton->request); + +#define STATEMENT_BEGIN(type) \ + assert(baton); \ + assert(baton->stmt); \ + assert(!baton->stmt->locked); \ + assert(!baton->stmt->finalized); \ + assert(baton->stmt->prepared); \ + baton->stmt->locked = true; \ + baton->stmt->db->pending++; \ + auto env = baton->stmt->Env(); \ + CREATE_WORK("sqlite3.Statement."#type, Work_##type, Work_After##type); + +#define STATEMENT_INIT(type) \ + type* baton = static_cast(data); \ + Statement* stmt = baton->stmt; + +#define STATEMENT_MUTEX(name) \ + if (!stmt->db->_handle) { \ + stmt->status = SQLITE_MISUSE; \ + stmt->message = "Database handle is closed"; \ + return; \ + } \ + sqlite3_mutex* name = sqlite3_db_mutex(stmt->db->_handle); + +#define STATEMENT_END() \ + assert(stmt->locked); \ + assert(stmt->db->pending); \ + stmt->locked = false; \ + stmt->db->pending--; \ + stmt->Process(); \ + stmt->db->Process(); + +#define BACKUP_BEGIN(type) \ + assert(baton); \ + assert(baton->backup); \ + assert(!baton->backup->locked); \ + assert(!baton->backup->finished); \ + assert(baton->backup->inited); \ + baton->backup->locked = true; \ + baton->backup->db->pending++; \ + auto env = baton->backup->Env(); \ + CREATE_WORK("sqlite3.Backup."#type, Work_##type, Work_After##type); + +#define BACKUP_INIT(type) \ + type* baton = static_cast(data); \ + Backup* backup = baton->backup; + +#define BACKUP_END() \ + assert(backup->locked); \ + assert(backup->db->pending); \ + backup->locked = false; \ + backup->db->pending--; \ + backup->Process(); \ + backup->db->Process(); + +#endif \ No newline at end of file diff --git a/updater/sql/mac/src/node_sqlite3.cc b/updater/sql/mac/src/node_sqlite3.cc new file mode 100755 index 0000000..6f47a68 --- /dev/null +++ b/updater/sql/mac/src/node_sqlite3.cc @@ -0,0 +1,128 @@ +#include +#include +#include +#include +#include + +#include "macros.h" +#include "database.h" +#include "statement.h" +#include "backup.h" + +using namespace node_sqlite3; + +namespace { + +Napi::Object RegisterModule(Napi::Env env, Napi::Object exports) { + Napi::HandleScope scope(env); + + Database::Init(env, exports); + Statement::Init(env, exports); + Backup::Init(env, exports); + + exports.DefineProperties({ + DEFINE_CONSTANT_INTEGER(exports, SQLITE_OPEN_READONLY, OPEN_READONLY) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_OPEN_READWRITE, OPEN_READWRITE) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_OPEN_CREATE, OPEN_CREATE) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_OPEN_FULLMUTEX, OPEN_FULLMUTEX) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_OPEN_URI, OPEN_URI) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_OPEN_SHAREDCACHE, OPEN_SHAREDCACHE) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_OPEN_PRIVATECACHE, OPEN_PRIVATECACHE) + DEFINE_CONSTANT_STRING(exports, SQLITE_VERSION, VERSION) +#ifdef SQLITE_SOURCE_ID + DEFINE_CONSTANT_STRING(exports, SQLITE_SOURCE_ID, SOURCE_ID) +#endif + DEFINE_CONSTANT_INTEGER(exports, SQLITE_VERSION_NUMBER, VERSION_NUMBER) + + DEFINE_CONSTANT_INTEGER(exports, SQLITE_OK, OK) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_ERROR, ERROR) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_INTERNAL, INTERNAL) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_PERM, PERM) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_ABORT, ABORT) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_BUSY, BUSY) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LOCKED, LOCKED) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_NOMEM, NOMEM) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_READONLY, READONLY) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_INTERRUPT, INTERRUPT) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_IOERR, IOERR) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_CORRUPT, CORRUPT) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_NOTFOUND, NOTFOUND) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_FULL, FULL) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_CANTOPEN, CANTOPEN) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_PROTOCOL, PROTOCOL) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_EMPTY, EMPTY) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_SCHEMA, SCHEMA) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_TOOBIG, TOOBIG) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_CONSTRAINT, CONSTRAINT) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_MISMATCH, MISMATCH) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_MISUSE, MISUSE) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_NOLFS, NOLFS) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_AUTH, AUTH) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_FORMAT, FORMAT) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_RANGE, RANGE) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_NOTADB, NOTADB) + + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_LENGTH, LIMIT_LENGTH) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_SQL_LENGTH, LIMIT_SQL_LENGTH) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_COLUMN, LIMIT_COLUMN) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_EXPR_DEPTH, LIMIT_EXPR_DEPTH) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_COMPOUND_SELECT, LIMIT_COMPOUND_SELECT) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_VDBE_OP, LIMIT_VDBE_OP) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_FUNCTION_ARG, LIMIT_FUNCTION_ARG) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_ATTACHED, LIMIT_ATTACHED) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_LIKE_PATTERN_LENGTH, LIMIT_LIKE_PATTERN_LENGTH) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_VARIABLE_NUMBER, LIMIT_VARIABLE_NUMBER) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_TRIGGER_DEPTH, LIMIT_TRIGGER_DEPTH) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_WORKER_THREADS, LIMIT_WORKER_THREADS) + }); + + return exports; +} + +} + +const char* sqlite_code_string(int code) { + switch (code) { + case SQLITE_OK: return "SQLITE_OK"; + case SQLITE_ERROR: return "SQLITE_ERROR"; + case SQLITE_INTERNAL: return "SQLITE_INTERNAL"; + case SQLITE_PERM: return "SQLITE_PERM"; + case SQLITE_ABORT: return "SQLITE_ABORT"; + case SQLITE_BUSY: return "SQLITE_BUSY"; + case SQLITE_LOCKED: return "SQLITE_LOCKED"; + case SQLITE_NOMEM: return "SQLITE_NOMEM"; + case SQLITE_READONLY: return "SQLITE_READONLY"; + case SQLITE_INTERRUPT: return "SQLITE_INTERRUPT"; + case SQLITE_IOERR: return "SQLITE_IOERR"; + case SQLITE_CORRUPT: return "SQLITE_CORRUPT"; + case SQLITE_NOTFOUND: return "SQLITE_NOTFOUND"; + case SQLITE_FULL: return "SQLITE_FULL"; + case SQLITE_CANTOPEN: return "SQLITE_CANTOPEN"; + case SQLITE_PROTOCOL: return "SQLITE_PROTOCOL"; + case SQLITE_EMPTY: return "SQLITE_EMPTY"; + case SQLITE_SCHEMA: return "SQLITE_SCHEMA"; + case SQLITE_TOOBIG: return "SQLITE_TOOBIG"; + case SQLITE_CONSTRAINT: return "SQLITE_CONSTRAINT"; + case SQLITE_MISMATCH: return "SQLITE_MISMATCH"; + case SQLITE_MISUSE: return "SQLITE_MISUSE"; + case SQLITE_NOLFS: return "SQLITE_NOLFS"; + case SQLITE_AUTH: return "SQLITE_AUTH"; + case SQLITE_FORMAT: return "SQLITE_FORMAT"; + case SQLITE_RANGE: return "SQLITE_RANGE"; + case SQLITE_NOTADB: return "SQLITE_NOTADB"; + case SQLITE_ROW: return "SQLITE_ROW"; + case SQLITE_DONE: return "SQLITE_DONE"; + default: return "UNKNOWN"; + } +} + +const char* sqlite_authorizer_string(int type) { + switch (type) { + case SQLITE_INSERT: return "insert"; + case SQLITE_UPDATE: return "update"; + case SQLITE_DELETE: return "delete"; + default: return ""; + } +} + +NODE_API_MODULE(node_sqlite3, RegisterModule) diff --git a/updater/sql/mac/src/statement.cc b/updater/sql/mac/src/statement.cc new file mode 100755 index 0000000..fc49b90 --- /dev/null +++ b/updater/sql/mac/src/statement.cc @@ -0,0 +1,939 @@ +#include +#include +#include + +#include "macros.h" +#include "database.h" +#include "statement.h" + +using namespace node_sqlite3; + +Napi::Object Statement::Init(Napi::Env env, Napi::Object exports) { + Napi::HandleScope scope(env); + + // declare napi_default_method here as it is only available in Node v14.12.0+ + auto napi_default_method = static_cast(napi_writable | napi_configurable); + + auto t = DefineClass(env, "Statement", { + InstanceMethod("bind", &Statement::Bind, napi_default_method), + InstanceMethod("get", &Statement::Get, napi_default_method), + InstanceMethod("run", &Statement::Run, napi_default_method), + InstanceMethod("all", &Statement::All, napi_default_method), + InstanceMethod("each", &Statement::Each, napi_default_method), + InstanceMethod("reset", &Statement::Reset, napi_default_method), + InstanceMethod("finalize", &Statement::Finalize_, napi_default_method), + }); + + exports.Set("Statement", t); + return exports; +} + +// A Napi InstanceOf for Javascript Objects "Date" and "RegExp" +bool OtherInstanceOf(Napi::Object source, const char* object_type) { + if (strncmp(object_type, "Date", 4) == 0) { + return source.InstanceOf(source.Env().Global().Get("Date").As()); + } else if (strncmp(object_type, "RegExp", 6) == 0) { + return source.InstanceOf(source.Env().Global().Get("RegExp").As()); + } + + return false; +} + +void Statement::Process() { + if (finalized && !queue.empty()) { + return CleanQueue(); + } + + while (prepared && !locked && !queue.empty()) { + auto call = std::unique_ptr(queue.front()); + queue.pop(); + + call->callback(call->baton); + } +} + +void Statement::Schedule(Work_Callback callback, Baton* baton) { + if (finalized) { + queue.emplace(new Call(callback, baton)); + CleanQueue(); + } + else if (!prepared || locked) { + queue.emplace(new Call(callback, baton)); + } + else { + callback(baton); + } +} + +template void Statement::Error(T* baton) { + Statement* stmt = baton->stmt; + + auto env = stmt->Env(); + Napi::HandleScope scope(env); + + // Fail hard on logic errors. + assert(stmt->status != 0); + EXCEPTION(Napi::String::New(env, stmt->message.c_str()), stmt->status, exception); + + Napi::Function cb = baton->callback.Value(); + + if (IS_FUNCTION(cb)) { + Napi::Value argv[] = { exception }; + TRY_CATCH_CALL(stmt->Value(), cb, 1, argv); + } + else { + Napi::Value argv[] = { Napi::String::New(env, "error"), exception }; + EMIT_EVENT(stmt->Value(), 2, argv); + } +} + +// { Database db, String sql, Array params, Function callback } +Statement::Statement(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { + auto env = info.Env(); + int length = info.Length(); + + if (length <= 0 || !Database::HasInstance(info[0])) { + Napi::TypeError::New(env, "Database object expected").ThrowAsJavaScriptException(); + return; + } + else if (length <= 1 || !info[1].IsString()) { + Napi::TypeError::New(env, "SQL query expected").ThrowAsJavaScriptException(); + return; + } + else if (length > 2 && !info[2].IsUndefined() && !info[2].IsFunction()) { + Napi::TypeError::New(env, "Callback expected").ThrowAsJavaScriptException(); + return; + } + + this->db = Napi::ObjectWrap::Unwrap(info[0].As()); + this->db->Ref(); + + auto sql = info[1].As(); + + info.This().As().DefineProperty(Napi::PropertyDescriptor::Value("sql", sql, napi_default)); + + + Statement* stmt = this; + + auto* baton = new PrepareBaton(this->db, info[2].As(), stmt); + baton->sql = std::string(sql.As().Utf8Value().c_str()); + this->db->Schedule(Work_BeginPrepare, baton); +} + +void Statement::Work_BeginPrepare(Database::Baton* baton) { + assert(baton->db->open); + baton->db->pending++; + + auto env = baton->db->Env(); + CREATE_WORK("sqlite3.Statement.Prepare", Work_Prepare, Work_AfterPrepare); +} + +void Statement::Work_Prepare(napi_env e, void* data) { + STATEMENT_INIT(PrepareBaton); + + // In case preparing fails, we use a mutex to make sure we get the associated + // error message. + STATEMENT_MUTEX(mtx); + sqlite3_mutex_enter(mtx); + + stmt->status = sqlite3_prepare_v2( + baton->db->_handle, + baton->sql.c_str(), + baton->sql.size(), + &stmt->_handle, + NULL + ); + + if (stmt->status != SQLITE_OK) { + stmt->message = std::string(sqlite3_errmsg(baton->db->_handle)); + stmt->_handle = NULL; + } + + sqlite3_mutex_leave(mtx); +} + +void Statement::Work_AfterPrepare(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + auto* stmt = baton->stmt; + + auto env = stmt->Env(); + Napi::HandleScope scope(env); + + if (stmt->status != SQLITE_OK) { + Error(baton.get()); + stmt->Finalize_(); + } + else { + stmt->prepared = true; + if (!baton->callback.IsEmpty() && baton->callback.Value().IsFunction()) { + Napi::Function cb = baton->callback.Value(); + Napi::Value argv[] = { env.Null() }; + TRY_CATCH_CALL(stmt->Value(), cb, 1, argv); + } + } + + STATEMENT_END(); +} + +template std::unique_ptr + Statement::BindParameter(const Napi::Value source, T pos) { + if (source.IsString()) { + std::string val = source.As().Utf8Value(); + return std::make_unique(pos, val.length(), val.c_str()); + } + else if (OtherInstanceOf(source.As(), "RegExp")) { + std::string val = source.ToString().Utf8Value(); + return std::make_unique(pos, val.length(), val.c_str()); + } + else if (source.IsNumber()) { + if (OtherIsInt(source.As())) { + return std::make_unique(pos, source.As().Int32Value()); + } else { + return std::make_unique(pos, source.As().DoubleValue()); + } + } + else if (source.IsBoolean()) { + return std::make_unique(pos, source.As().Value() ? 1 : 0); + } + else if (source.IsNull()) { + return std::make_unique(pos); + } + else if (source.IsBuffer()) { + Napi::Buffer buffer = source.As>(); + return std::make_unique(pos, buffer.Length(), buffer.Data()); + } + else if (OtherInstanceOf(source.As(), "Date")) { + return std::make_unique(pos, source.ToNumber().DoubleValue()); + } + else if (source.IsObject()) { + auto napiVal = Napi::String::New(source.Env(), "[object Object]"); + // Check whether toString returned a value that is not undefined. + if(napiVal.Type() == 0) { + return NULL; + } + + std::string val = napiVal.Utf8Value(); + return std::make_unique(pos, val.length(), val.c_str()); + } + else { + return NULL; + } +} + +template T* Statement::Bind(const Napi::CallbackInfo& info, int start, int last) { + auto env = info.Env(); + Napi::HandleScope scope(env); + + if (last < 0) last = info.Length(); + Napi::Function callback; + if (last > start && info[last - 1].IsFunction()) { + callback = info[last - 1].As(); + last--; + } + + auto *baton = new T(this, callback); + + if (start < last) { + if (info[start].IsArray()) { + auto array = info[start].As(); + int length = array.Length(); + // Note: bind parameters start with 1. + for (int i = 0, pos = 1; i < length; i++, pos++) { + baton->parameters.emplace_back(BindParameter((array).Get(i), i + 1)); + } + } + else if (!info[start].IsObject() || OtherInstanceOf(info[start].As(), "RegExp") + || OtherInstanceOf(info[start].As(), "Date") || info[start].IsBuffer()) { + // Parameters directly in array. + // Note: bind parameters start with 1. + for (int i = start, pos = 1; i < last; i++, pos++) { + baton->parameters.emplace_back(BindParameter(info[i], pos)); + } + } + else if (info[start].IsObject()) { + auto object = info[start].As(); + auto array = object.GetPropertyNames(); + int length = array.Length(); + for (int i = 0; i < length; i++) { + Napi::Value name = (array).Get(i); + Napi::Number num = name.ToNumber(); + + if (num.Int32Value() == num.DoubleValue()) { + baton->parameters.emplace_back( + BindParameter((object).Get(name), num.Int32Value())); + } + else { + baton->parameters.emplace_back(BindParameter((object).Get(name), + name.As().Utf8Value().c_str())); + } + } + } + else { + return NULL; + } + } + + return baton; +} + +bool Statement::Bind(const Parameters & parameters) { + if (parameters.empty()) { + return true; + } + + sqlite3_reset(_handle); + sqlite3_clear_bindings(_handle); + + for (auto& field : parameters) { + if (field == NULL) + continue; + + unsigned int pos; + if (field->index > 0) { + pos = field->index; + } + else { + pos = sqlite3_bind_parameter_index(_handle, field->name.c_str()); + } + + switch (field->type) { + case SQLITE_INTEGER: { + status = sqlite3_bind_int(_handle, pos, + (static_cast(field.get()))->value); + } break; + case SQLITE_FLOAT: { + status = sqlite3_bind_double(_handle, pos, + (static_cast(field.get()))->value); + } break; + case SQLITE_TEXT: { + status = sqlite3_bind_text(_handle, pos, + (static_cast(field.get()))->value.c_str(), + (static_cast(field.get()))->value.size(), SQLITE_TRANSIENT); + } break; + case SQLITE_BLOB: { + status = sqlite3_bind_blob(_handle, pos, + (static_cast(field.get()))->value, + (static_cast(field.get()))->length, SQLITE_TRANSIENT); + } break; + case SQLITE_NULL: { + status = sqlite3_bind_null(_handle, pos); + } break; + } + + if (status != SQLITE_OK) { + message = std::string(sqlite3_errmsg(db->_handle)); + return false; + } + } + + return true; +} + +Napi::Value Statement::Bind(const Napi::CallbackInfo& info) { + auto env = info.Env(); + Statement* stmt = this; + + auto baton = stmt->Bind(info); + if (baton == NULL) { + Napi::TypeError::New(env, "Data type is not supported").ThrowAsJavaScriptException(); + return env.Null(); + } + else { + stmt->Schedule(Work_BeginBind, baton); + return info.This(); + } +} + +void Statement::Work_BeginBind(Baton* baton) { + STATEMENT_BEGIN(Bind); +} + +void Statement::Work_Bind(napi_env e, void* data) { + STATEMENT_INIT(Baton); + + STATEMENT_MUTEX(mtx); + sqlite3_mutex_enter(mtx); + stmt->Bind(baton->parameters); + sqlite3_mutex_leave(mtx); +} + +void Statement::Work_AfterBind(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + auto* stmt = baton->stmt; + + auto env = stmt->Env(); + Napi::HandleScope scope(env); + + if (stmt->status != SQLITE_OK) { + Error(baton.get()); + } + else { + // Fire callbacks. + Napi::Function cb = baton->callback.Value(); + if (IS_FUNCTION(cb)) { + Napi::Value argv[] = { env.Null() }; + TRY_CATCH_CALL(stmt->Value(), cb, 1, argv); + } + } + + STATEMENT_END(); +} + + + +Napi::Value Statement::Get(const Napi::CallbackInfo& info) { + auto env = info.Env(); + Statement* stmt = this; + + Baton* baton = stmt->Bind(info); + if (baton == NULL) { + Napi::Error::New(env, "Data type is not supported").ThrowAsJavaScriptException(); + return env.Null(); + } + else { + stmt->Schedule(Work_BeginGet, baton); + return info.This(); + } +} + +void Statement::Work_BeginGet(Baton* baton) { + STATEMENT_BEGIN(Get); +} + +void Statement::Work_Get(napi_env e, void* data) { + STATEMENT_INIT(RowBaton); + + if (stmt->status != SQLITE_DONE || baton->parameters.size()) { + STATEMENT_MUTEX(mtx); + sqlite3_mutex_enter(mtx); + + if (stmt->Bind(baton->parameters)) { + stmt->status = sqlite3_step(stmt->_handle); + + if (!(stmt->status == SQLITE_ROW || stmt->status == SQLITE_DONE)) { + stmt->message = std::string(sqlite3_errmsg(stmt->db->_handle)); + } + } + + sqlite3_mutex_leave(mtx); + + if (stmt->status == SQLITE_ROW) { + // Acquire one result row before returning. + GetRow(&baton->row, stmt->_handle); + } + } +} + +void Statement::Work_AfterGet(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + auto* stmt = baton->stmt; + + auto env = stmt->Env(); + Napi::HandleScope scope(env); + + if (stmt->status != SQLITE_ROW && stmt->status != SQLITE_DONE) { + Error(baton.get()); + } + else { + // Fire callbacks. + Napi::Function cb = baton->callback.Value(); + if (IS_FUNCTION(cb)) { + if (stmt->status == SQLITE_ROW) { + // Create the result array from the data we acquired. + Napi::Value argv[] = { env.Null(), RowToJS(env, &baton->row) }; + TRY_CATCH_CALL(stmt->Value(), cb, 2, argv); + } + else { + Napi::Value argv[] = { env.Null() }; + TRY_CATCH_CALL(stmt->Value(), cb, 1, argv); + } + } + } + + STATEMENT_END(); +} + +Napi::Value Statement::Run(const Napi::CallbackInfo& info) { + auto env = info.Env(); + Statement* stmt = this; + + Baton* baton = stmt->Bind(info); + if (baton == NULL) { + Napi::Error::New(env, "Data type is not supported").ThrowAsJavaScriptException(); + return env.Null(); + } + else { + stmt->Schedule(Work_BeginRun, baton); + return info.This(); + } +} + +void Statement::Work_BeginRun(Baton* baton) { + STATEMENT_BEGIN(Run); +} + +void Statement::Work_Run(napi_env e, void* data) { + STATEMENT_INIT(RunBaton); + + STATEMENT_MUTEX(mtx); + sqlite3_mutex_enter(mtx); + + // Make sure that we also reset when there are no parameters. + if (!baton->parameters.size()) { + sqlite3_reset(stmt->_handle); + } + + if (stmt->Bind(baton->parameters)) { + stmt->status = sqlite3_step(stmt->_handle); + + if (!(stmt->status == SQLITE_ROW || stmt->status == SQLITE_DONE)) { + stmt->message = std::string(sqlite3_errmsg(stmt->db->_handle)); + } + else { + baton->inserted_id = sqlite3_last_insert_rowid(stmt->db->_handle); + baton->changes = sqlite3_changes(stmt->db->_handle); + } + } + + sqlite3_mutex_leave(mtx); +} + +void Statement::Work_AfterRun(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + auto* stmt = baton->stmt; + + auto env = stmt->Env(); + Napi::HandleScope scope(env); + + if (stmt->status != SQLITE_ROW && stmt->status != SQLITE_DONE) { + Error(baton.get()); + } + else { + // Fire callbacks. + Napi::Function cb = baton->callback.Value(); + if (IS_FUNCTION(cb)) { + (stmt->Value()).Set(Napi::String::New(env, "lastID"), Napi::Number::New(env, baton->inserted_id)); + (stmt->Value()).Set( Napi::String::New(env, "changes"), Napi::Number::New(env, baton->changes)); + + Napi::Value argv[] = { env.Null() }; + TRY_CATCH_CALL(stmt->Value(), cb, 1, argv); + } + } + + STATEMENT_END(); +} + +Napi::Value Statement::All(const Napi::CallbackInfo& info) { + auto env = info.Env(); + Statement* stmt = this; + + Baton* baton = stmt->Bind(info); + if (baton == NULL) { + Napi::Error::New(env, "Data type is not supported").ThrowAsJavaScriptException(); + return env.Null(); + } + else { + stmt->Schedule(Work_BeginAll, baton); + return info.This(); + } +} + +void Statement::Work_BeginAll(Baton* baton) { + STATEMENT_BEGIN(All); +} + +void Statement::Work_All(napi_env e, void* data) { + STATEMENT_INIT(RowsBaton); + + STATEMENT_MUTEX(mtx); + sqlite3_mutex_enter(mtx); + + // Make sure that we also reset when there are no parameters. + if (!baton->parameters.size()) { + sqlite3_reset(stmt->_handle); + } + + if (stmt->Bind(baton->parameters)) { + while ((stmt->status = sqlite3_step(stmt->_handle)) == SQLITE_ROW) { + auto row = std::make_unique(); + GetRow(row.get(), stmt->_handle); + baton->rows.emplace_back(std::move(row)); + } + + if (stmt->status != SQLITE_DONE) { + stmt->message = std::string(sqlite3_errmsg(stmt->db->_handle)); + } + } + + sqlite3_mutex_leave(mtx); +} + +void Statement::Work_AfterAll(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + auto* stmt = baton->stmt; + + auto env = stmt->Env(); + Napi::HandleScope scope(env); + + if (stmt->status != SQLITE_DONE) { + Error(baton.get()); + } + else { + // Fire callbacks. + Napi::Function cb = baton->callback.Value(); + if (IS_FUNCTION(cb)) { + if (baton->rows.size()) { + // Create the result array from the data we acquired. + Napi::Array result(Napi::Array::New(env, baton->rows.size())); + auto it = static_cast(baton->rows.begin()); + decltype(it) end = baton->rows.end(); + for (int i = 0; it < end; ++it, i++) { + (result).Set(i, RowToJS(env, it->get())); + } + + Napi::Value argv[] = { env.Null(), result }; + TRY_CATCH_CALL(stmt->Value(), cb, 2, argv); + } + else { + // There were no result rows. + Napi::Value argv[] = { + env.Null(), + Napi::Array::New(env, 0) + }; + TRY_CATCH_CALL(stmt->Value(), cb, 2, argv); + } + } + } + + STATEMENT_END(); +} + +Napi::Value Statement::Each(const Napi::CallbackInfo& info) { + auto env = info.Env(); + Statement* stmt = this; + + int last = info.Length(); + + Napi::Function completed; + if (last >= 2 && info[last - 1].IsFunction() && info[last - 2].IsFunction()) { + completed = info[--last].As(); + } + + auto baton = stmt->Bind(info, 0, last); + if (baton == NULL) { + Napi::Error::New(env, "Data type is not supported").ThrowAsJavaScriptException(); + return env.Null(); + } + else { + baton->completed.Reset(completed, 1); + stmt->Schedule(Work_BeginEach, baton); + return info.This(); + } +} + +void Statement::Work_BeginEach(Baton* baton) { + // Only create the Async object when we're actually going into + // the event loop. This prevents dangling events. + auto* each_baton = static_cast(baton); + each_baton->async = new Async(each_baton->stmt, reinterpret_cast(AsyncEach)); + each_baton->async->item_cb.Reset(each_baton->callback.Value(), 1); + each_baton->async->completed_cb.Reset(each_baton->completed.Value(), 1); + + STATEMENT_BEGIN(Each); +} + +void Statement::Work_Each(napi_env e, void* data) { + STATEMENT_INIT(EachBaton); + + auto* async = baton->async; + + STATEMENT_MUTEX(mtx); + + // Make sure that we also reset when there are no parameters. + if (!baton->parameters.size()) { + sqlite3_reset(stmt->_handle); + } + + if (stmt->Bind(baton->parameters)) { + while (true) { + sqlite3_mutex_enter(mtx); + stmt->status = sqlite3_step(stmt->_handle); + if (stmt->status == SQLITE_ROW) { + sqlite3_mutex_leave(mtx); + auto row = std::make_unique(); + GetRow(row.get(), stmt->_handle); + NODE_SQLITE3_MUTEX_LOCK(&async->mutex) + async->data.emplace_back(std::move(row)); + NODE_SQLITE3_MUTEX_UNLOCK(&async->mutex) + + uv_async_send(&async->watcher); + } + else { + if (stmt->status != SQLITE_DONE) { + stmt->message = std::string(sqlite3_errmsg(stmt->db->_handle)); + } + sqlite3_mutex_leave(mtx); + break; + } + } + } + + async->completed = true; + uv_async_send(&async->watcher); +} + +void Statement::CloseCallback(uv_handle_t* handle) { + assert(handle != NULL); + assert(handle->data != NULL); + auto* async = static_cast(handle->data); + delete async; +} + +void Statement::AsyncEach(uv_async_t* handle) { + auto* async = static_cast(handle->data); + + auto env = async->stmt->Env(); + Napi::HandleScope scope(env); + + while (true) { + // Get the contents out of the data cache for us to process in the JS callback. + Rows rows; + NODE_SQLITE3_MUTEX_LOCK(&async->mutex) + rows.swap(async->data); + NODE_SQLITE3_MUTEX_UNLOCK(&async->mutex) + + if (rows.empty()) { + break; + } + + Napi::Function cb = async->item_cb.Value(); + if (IS_FUNCTION(cb)) { + Napi::Value argv[2]; + argv[0] = env.Null(); + + for(auto& row : rows) { + argv[1] = RowToJS(env,row.get()); + async->retrieved++; + TRY_CATCH_CALL(async->stmt->Value(), cb, 2, argv); + } + } + } + + Napi::Function cb = async->completed_cb.Value(); + if (async->completed) { + if (!cb.IsEmpty() && + cb.IsFunction()) { + Napi::Value argv[] = { + env.Null(), + Napi::Number::New(env, async->retrieved) + }; + TRY_CATCH_CALL(async->stmt->Value(), cb, 2, argv); + } + uv_close(reinterpret_cast(handle), CloseCallback); + } +} + +void Statement::Work_AfterEach(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + auto* stmt = baton->stmt; + + auto env = stmt->Env(); + Napi::HandleScope scope(env); + + if (stmt->status != SQLITE_DONE) { + Error(baton.get()); + } + + STATEMENT_END(); +} + +Napi::Value Statement::Reset(const Napi::CallbackInfo& info) { + auto env = info.Env(); + Statement* stmt = this; + + OPTIONAL_ARGUMENT_FUNCTION(0, callback); + + auto* baton = new Baton(stmt, callback); + stmt->Schedule(Work_BeginReset, baton); + + return info.This(); +} + +void Statement::Work_BeginReset(Baton* baton) { + STATEMENT_BEGIN(Reset); +} + +void Statement::Work_Reset(napi_env e, void* data) { + STATEMENT_INIT(Baton); + + sqlite3_reset(stmt->_handle); + stmt->status = SQLITE_OK; +} + +void Statement::Work_AfterReset(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + auto* stmt = baton->stmt; + + auto env = stmt->Env(); + Napi::HandleScope scope(env); + + // Fire callbacks. + Napi::Function cb = baton->callback.Value(); + if (IS_FUNCTION(cb)) { + Napi::Value argv[] = { env.Null() }; + TRY_CATCH_CALL(stmt->Value(), cb, 1, argv); + } + + STATEMENT_END(); +} + +Napi::Value Statement::RowToJS(Napi::Env env, Row* row) { + Napi::EscapableHandleScope scope(env); + + auto result = Napi::Object::New(env); + + for (auto& field : *row) { + + Napi::Value value; + + switch (field->type) { + case SQLITE_INTEGER: { + value = Napi::Number::New(env, (static_cast(field.get()))->value); + } break; + case SQLITE_FLOAT: { + value = Napi::Number::New(env, (static_cast(field.get()))->value); + } break; + case SQLITE_TEXT: { + value = Napi::String::New(env, (static_cast(field.get()))->value.c_str(), + (static_cast(field.get()))->value.size()); + } break; + case SQLITE_BLOB: { + value = Napi::Buffer::Copy(env, (static_cast(field.get()))->value, + (static_cast(field.get()))->length); + } break; + case SQLITE_NULL: { + value = env.Null(); + } break; + } + + result.Set(field->name, value); + } + + return scope.Escape(result); +} + +void Statement::GetRow(Row* row, sqlite3_stmt* stmt) { + int cols = sqlite3_column_count(stmt); + + for (int i = 0; i < cols; i++) { + int type = sqlite3_column_type(stmt, i); + const char* name = sqlite3_column_name(stmt, i); + if (name == NULL) { + assert(false); + } + + switch (type) { + case SQLITE_INTEGER: { + row->emplace_back(std::make_unique(name, sqlite3_column_int64(stmt, i))); + } break; + case SQLITE_FLOAT: { + row->emplace_back(std::make_unique(name, sqlite3_column_double(stmt, i))); + } break; + case SQLITE_TEXT: { + const char* text = (const char*)sqlite3_column_text(stmt, i); + int length = sqlite3_column_bytes(stmt, i); + row->emplace_back(std::make_unique(name, length, text)); + } break; + case SQLITE_BLOB: { + const void* blob = sqlite3_column_blob(stmt, i); + int length = sqlite3_column_bytes(stmt, i); + row->emplace_back(std::make_unique(name, length, blob)); + } break; + case SQLITE_NULL: { + row->emplace_back(std::make_unique(name)); + } break; + default: + assert(false); + } + } +} + +Napi::Value Statement::Finalize_(const Napi::CallbackInfo& info) { + auto env = info.Env(); + Statement* stmt = this; + OPTIONAL_ARGUMENT_FUNCTION(0, callback); + + auto *baton = new Baton(stmt, callback); + stmt->Schedule(Finalize_, baton); + + return stmt->db->Value(); +} + +void Statement::Finalize_(Baton* b) { + auto baton = std::unique_ptr(b); + auto env = baton->stmt->Env(); + Napi::HandleScope scope(env); + + baton->stmt->Finalize_(); + + // Fire callback in case there was one. + Napi::Function cb = baton->callback.Value(); + if (IS_FUNCTION(cb)) { + TRY_CATCH_CALL(baton->stmt->Value(), cb, 0, NULL); + } +} + +void Statement::Finalize_() { + assert(!finalized); + finalized = true; + CleanQueue(); + // Finalize returns the status code of the last operation. We already fired + // error events in case those failed. + sqlite3_finalize(_handle); + _handle = NULL; + db->Unref(); +} + +void Statement::CleanQueue() { + auto env = this->Env(); + Napi::HandleScope scope(env); + + if (prepared && !queue.empty()) { + // This statement has already been prepared and is now finalized. + // Fire error for all remaining items in the queue. + EXCEPTION(Napi::String::New(env, "Statement is already finalized"), SQLITE_MISUSE, exception); + Napi::Value argv[] = { exception }; + bool called = false; + + // Clear out the queue so that this object can get GC'ed. + while (!queue.empty()) { + auto call = std::unique_ptr(queue.front()); + queue.pop(); + + auto baton = std::unique_ptr(call->baton); + Napi::Function cb = baton->callback.Value(); + + if (prepared && !cb.IsEmpty() && + cb.IsFunction()) { + TRY_CATCH_CALL(Value(), cb, 1, argv); + called = true; + } + } + + // When we couldn't call a callback function, emit an error on the + // Statement object. + if (!called) { + Napi::Value info[] = { Napi::String::New(env, "error"), exception }; + EMIT_EVENT(Value(), 2, info); + } + } + else while (!queue.empty()) { + // Just delete all items in the queue; we already fired an event when + // preparing the statement failed. + auto call = std::unique_ptr(queue.front()); + queue.pop(); + // We don't call the actual callback, so we have to make sure that + // the baton gets destroyed. + delete call->baton; + } +} diff --git a/updater/sql/mac/src/statement.h b/updater/sql/mac/src/statement.h new file mode 100755 index 0000000..c522c0f --- /dev/null +++ b/updater/sql/mac/src/statement.h @@ -0,0 +1,244 @@ +#ifndef NODE_SQLITE3_SRC_STATEMENT_H +#define NODE_SQLITE3_SRC_STATEMENT_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "database.h" +#include "threading.h" + +using namespace Napi; + +namespace node_sqlite3 { + +namespace Values { + struct Field { + inline Field(unsigned short _index, unsigned short _type = SQLITE_NULL) : + type(_type), index(_index) {} + inline Field(const char* _name, unsigned short _type = SQLITE_NULL) : + type(_type), index(0), name(_name) {} + + unsigned short type; + unsigned short index; + std::string name; + + virtual ~Field() = default; + }; + + struct Integer : Field { + template inline Integer(T _name, int64_t val) : + Field(_name, SQLITE_INTEGER), value(val) {} + int64_t value; + virtual ~Integer() override = default; + }; + + struct Float : Field { + template inline Float(T _name, double val) : + Field(_name, SQLITE_FLOAT), value(val) {} + double value; + virtual ~Float() override = default; + }; + + struct Text : Field { + template inline Text(T _name, size_t len, const char* val) : + Field(_name, SQLITE_TEXT), value(val, len) {} + std::string value; + virtual ~Text() override = default; + }; + + struct Blob : Field { + template inline Blob(T _name, size_t len, const void* val) : + Field(_name, SQLITE_BLOB), length(len) { + value = new char[len]; + assert(value != nullptr); + memcpy(value, val, len); + } + inline virtual ~Blob() override { + delete[] value; + } + int length; + char* value; + }; + + typedef Field Null; +} + +typedef std::vector > Row; +typedef std::vector > Rows; +typedef Row Parameters; + + + +class Statement : public Napi::ObjectWrap { +public: + static Napi::Object Init(Napi::Env env, Napi::Object exports); + static Napi::Value New(const Napi::CallbackInfo& info); + + struct Baton { + napi_async_work request = NULL; + Statement* stmt; + Napi::FunctionReference callback; + Parameters parameters; + + Baton(Statement* stmt_, Napi::Function cb_) : stmt(stmt_) { + stmt->Ref(); + callback.Reset(cb_, 1); + } + virtual ~Baton() { + parameters.clear(); + if (request) napi_delete_async_work(stmt->Env(), request); + stmt->Unref(); + callback.Reset(); + } + }; + + struct RowBaton : Baton { + RowBaton(Statement* stmt_, Napi::Function cb_) : + Baton(stmt_, cb_) {} + Row row; + virtual ~RowBaton() override = default; + }; + + struct RunBaton : Baton { + RunBaton(Statement* stmt_, Napi::Function cb_) : + Baton(stmt_, cb_), inserted_id(0), changes(0) {} + sqlite3_int64 inserted_id; + int changes; + virtual ~RunBaton() override = default; + }; + + struct RowsBaton : Baton { + RowsBaton(Statement* stmt_, Napi::Function cb_) : + Baton(stmt_, cb_) {} + Rows rows; + virtual ~RowsBaton() override = default; + }; + + struct Async; + + struct EachBaton : Baton { + Napi::FunctionReference completed; + Async* async; // Isn't deleted when the baton is deleted. + + EachBaton(Statement* stmt_, Napi::Function cb_) : + Baton(stmt_, cb_) {} + virtual ~EachBaton() override { + completed.Reset(); + } + }; + + struct PrepareBaton : Database::Baton { + Statement* stmt; + std::string sql; + PrepareBaton(Database* db_, Napi::Function cb_, Statement* stmt_) : + Baton(db_, cb_), stmt(stmt_) { + stmt->Ref(); + } + virtual ~PrepareBaton() override { + stmt->Unref(); + if (!db->IsOpen() && db->IsLocked()) { + // The database handle was closed before the statement could be + // prepared. + stmt->Finalize_(); + } + } + }; + + typedef void (*Work_Callback)(Baton* baton); + + struct Call { + Call(Work_Callback cb_, Baton* baton_) : callback(cb_), baton(baton_) {}; + Work_Callback callback; + Baton* baton; + }; + + struct Async { + uv_async_t watcher; + Statement* stmt; + Rows data; + NODE_SQLITE3_MUTEX_t; + bool completed; + int retrieved; + + // Store the callbacks here because we don't have + // access to the baton in the async callback. + Napi::FunctionReference item_cb; + Napi::FunctionReference completed_cb; + + Async(Statement* st, uv_async_cb async_cb) : + stmt(st), completed(false), retrieved(0) { + watcher.data = this; + NODE_SQLITE3_MUTEX_INIT + stmt->Ref(); + uv_loop_t *loop; + napi_get_uv_event_loop(stmt->Env(), &loop); + uv_async_init(loop, &watcher, async_cb); + } + + ~Async() { + stmt->Unref(); + item_cb.Reset(); + completed_cb.Reset(); + NODE_SQLITE3_MUTEX_DESTROY + } + }; + + Statement(const Napi::CallbackInfo& info); + + ~Statement() { + if (!finalized) Finalize_(); + } + + WORK_DEFINITION(Bind) + WORK_DEFINITION(Get) + WORK_DEFINITION(Run) + WORK_DEFINITION(All) + WORK_DEFINITION(Each) + WORK_DEFINITION(Reset) + + Napi::Value Finalize_(const Napi::CallbackInfo& info); + +protected: + static void Work_BeginPrepare(Database::Baton* baton); + static void Work_Prepare(napi_env env, void* data); + static void Work_AfterPrepare(napi_env env, napi_status status, void* data); + + static void AsyncEach(uv_async_t* handle); + static void CloseCallback(uv_handle_t* handle); + + static void Finalize_(Baton* baton); + void Finalize_(); + + template inline std::unique_ptr BindParameter(const Napi::Value source, T pos); + template T* Bind(const Napi::CallbackInfo& info, int start = 0, int end = -1); + bool Bind(const Parameters ¶meters); + + static void GetRow(Row* row, sqlite3_stmt* stmt); + static Napi::Value RowToJS(Napi::Env env, Row* row); + void Schedule(Work_Callback callback, Baton* baton); + void Process(); + void CleanQueue(); + template static void Error(T* baton); + +protected: + Database* db; + + sqlite3_stmt* _handle = NULL; + int status = SQLITE_OK; + bool prepared = false; + bool locked = true; + bool finalized = false; + + std::queue queue; + std::string message; +}; + +} + +#endif diff --git a/updater/sql/mac/src/threading.h b/updater/sql/mac/src/threading.h new file mode 100755 index 0000000..7c7139b --- /dev/null +++ b/updater/sql/mac/src/threading.h @@ -0,0 +1,10 @@ +#ifndef NODE_SQLITE3_SRC_THREADING_H +#define NODE_SQLITE3_SRC_THREADING_H + +#define NODE_SQLITE3_MUTEX_t uv_mutex_t mutex; +#define NODE_SQLITE3_MUTEX_INIT uv_mutex_init(&mutex); +#define NODE_SQLITE3_MUTEX_LOCK(m) uv_mutex_lock(m); +#define NODE_SQLITE3_MUTEX_UNLOCK(m) uv_mutex_unlock(m); +#define NODE_SQLITE3_MUTEX_DESTROY uv_mutex_destroy(&mutex); + +#endif // NODE_SQLITE3_SRC_THREADING_H diff --git a/updater/sql/main.py b/updater/sql/main.py new file mode 100755 index 0000000..f4e3a01 --- /dev/null +++ b/updater/sql/main.py @@ -0,0 +1,206 @@ +import base64 +import json +import sqlite3 +import os + +import psycopg2 + +registered = [ + "RaindropsSys", +] + +def dict_factory(cursor, row): + d = {} + for idx, col in enumerate(cursor.description): + d[col[0]] = row[idx] + return d + + +print("Initializing database...") + +conn = psycopg2.connect(database="derpibooru") +db = conn.cursor() + +print("Creating taggings index...") +db.execute(""" +CREATE INDEX IF NOT EXISTS taggings_index ON image_taggings (image_id) INCLUDE (tag_id) +""") + +print("Creating tags index...") +db.execute(""" +CREATE INDEX IF NOT EXISTS tags_index ON tags (id) INCLUDE (name) +""") + +print("Opening tags database...") + +os.system("rm -rf /app/prisbeam") +os.system("rm -rf /prisbeam") +os.system("mkdir -p /prisbeam") +os.system("mkdir -p /prisbeam/common") +os.system("mkdir -p /prisbeam/users") + +if os.path.exists(f"/prisbeam/common/tags.db"): + os.remove(f"/prisbeam/common/tags.db") +db2 = sqlite3.connect(f"/prisbeam/common/tags.db") +db2.execute("CREATE TABLE tags (json LONGTEXT)") +db2.execute("CREATE TABLE aliases (json LONGTEXT)") +db2.execute("CREATE TABLE implications (json LONGTEXT)") + +print("Building list of tags... Step 1/3") +db.execute(""" +SELECT * +FROM tags +""") +data = list(map(lambda x: dict_factory(db, x), db.fetchall())) +for tag in data: + tag['id'] = int('10' + str(tag['id'])) + db2.execute("INSERT INTO tags VALUES ('" + base64.b64encode(bytes(json.dumps(tag), 'utf-8')).decode('utf-8') + "')") + +print("Building list of tags... Step 2/3") +db.execute(""" +SELECT * +FROM tag_aliases +""") +data = list(map(lambda x: dict_factory(db, x), db.fetchall())) +for tag in data: + tag['tag_id'] = int('10' + str(tag['tag_id'])) + tag['target_tag_id'] = int('10' + str(tag['target_tag_id'])) + db2.execute("INSERT INTO aliases VALUES ('" + base64.b64encode(bytes(json.dumps(tag), 'utf-8')).decode('utf-8') + "')") + +print("Building list of tags... Step 3/3") +db.execute(""" +SELECT * +FROM tag_implications +""") +data = list(map(lambda x: dict_factory(db, x), db.fetchall())) +for tag in data: + tag['tag_id'] = int('10' + str(tag['tag_id'])) + tag['target_tag_id'] = int('10' + str(tag['target_tag_id'])) + db2.execute("INSERT INTO implications VALUES ('" + base64.b64encode(bytes(json.dumps(tag), 'utf-8')).decode('utf-8') + "')") + +print("Saving...") +db2.commit() +db2.close() + +print("Gathering user list...") +db.execute(""" +SELECT * +FROM public.users +""") + +users = list(filter(lambda x: x['name'] in registered, map(lambda x: dict_factory(db, x), db.fetchall()))) + +for user in users: + print(f"{user['name']}: Initialising database..."); + + if os.path.exists(f"/prisbeam/users/{user['name']}.db"): + os.remove(f"/prisbeam/users/{user['name']}.db") + + db2 = sqlite3.connect(f"/prisbeam/users/{user['name']}.db") + db2.execute("CREATE TABLE images (json LONGTEXT)") + + print(f"{user['name']}: Fetching data...") + + db.execute(f""" + SELECT * + FROM image_faves + JOIN image_intensities ON image_faves.image_id = image_intensities.image_id + JOIN images ON image_faves.image_id = images.id + JOIN users ON images.user_id = users.id + WHERE image_faves.user_id = {user['id']} + """) + data = list(map(lambda x: dict_factory(db, x), db.fetchall())) + + i = 0 + l = len(data) + + for image in data: + print(f"{user['name']}: Processing image #{image['image_id']} ({round((i / l) * 100)}%)") + + db.execute(f""" + SELECT tags.id, tags.name + FROM image_taggings + JOIN tags ON image_taggings.tag_id = tags.id + WHERE image_taggings.image_id = {image['image_id']} + """) + tags = list(map(lambda x: dict_factory(db, x), db.fetchall())) + + db.execute(f""" + SELECT source + FROM image_sources + WHERE image_sources.image_id = {image['image_id']} + """) + sources = list(map(lambda x: dict_factory(db, x), db.fetchall())) + + dic = { + 'wilson_score': 0, + 'spoilered': False, + 'representations': { + 'full': f"{image['version_path']}full.{image['image_format']}", + 'large': f"{image['version_path']}large.{image['image_format']}", + 'medium': f"{image['version_path']}medium.{image['image_format']}", + 'small': f"{image['version_path']}small.{image['image_format']}", + 'tall': f"{image['version_path']}tall.{image['image_format']}", + 'thumb': f"{image['version_path']}thumb.{image['image_format']}", + 'thumb_small': f"{image['version_path']}thumb_small.{image['image_format']}", + 'thumb_tiny': f"{image['version_path']}thumb_tiny.{image['image_format']}", + }, + 'faves': 0, + 'aspect_ratio': image['image_aspect_ratio'], + 'duration': 0, + 'thumbnails_generated': True, + 'tags': list(map(lambda x: x['name'], tags)), + 'created_at': image['created_at'].isoformat(), + 'tag_count': 0, + 'downvotes': image['downvotes'], + 'id': int('10' + str(image['image_id'])), + 'source_id': image['image_id'], + 'source': 'https://derpibooru.org/images/%s', + 'source_name': 'Derpibooru', + 'name': image['image_name'], + 'width': image['image_width'], + 'intensities': { + 'ne': image['ne_intensity'], + 'nw': image['nw_intensity'], + 'se': image['se_intensity'], + 'sw': image['sw_intensity'] + }, + 'orig_sha512_hash': image['image_orig_sha512_hash'], + 'deletion_reason': None, + 'processed': True, + 'animated': None, + 'height': image['image_height'], + 'description': '', + 'sha512_hash': image['image_sha512_hash'], + 'source_urls': list(map(lambda x: x['source'], sources)) if len(list(map(lambda x: x['source'], sources))) else [], + 'upvotes': image['upvotes'], + 'source_url': list(map(lambda x: x['source'], sources))[0] if len(list(map(lambda x: x['source'], sources))) else '', + 'uploader_id': image['user_id'], + 'score': image['score'], + 'uploader': image['name'], + 'first_seen_at': image['created_at'].isoformat(), + 'mime_type': image['image_mime_type'], + 'duplicate_of': None, + 'size': image['image_size'], + 'comment_count': image['comment_count'], + 'view_url': f"{image['version_path'][:-1].replace('/img/', '/img/view/')}.{image['image_format']}", + 'hidden_from_users': False, + 'updated_at': image['updated_at'].isoformat(), + 'tag_ids': list(map(lambda x: int('10' + str(x['id'])), tags)), + 'format': image['image_format'], + } + + db2.execute("INSERT INTO images VALUES ('" + base64.b64encode(bytes(json.dumps(dic), 'utf-8')).decode('utf-8') + "')") + i += 1 + + print(f"{user['name']}: Saving...") + + db2.commit() + db2.close() + print(f"{user['name']}: Finished.") + +db.close() +print("Moving...") +os.system("cp -rv /prisbeam/* /app/prisbeam") +os.system("rm -rf /prisbeam") +print("Done!") diff --git a/updater/sql/win/LICENSE b/updater/sql/win/LICENSE new file mode 100755 index 0000000..6c4ce40 --- /dev/null +++ b/updater/sql/win/LICENSE @@ -0,0 +1,25 @@ +Copyright (c) MapBox +All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +- Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +- Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimer in the documentation and/or + other materials provided with the distribution. +- Neither the name "MapBox" nor the names of its contributors may be + used to endorse or promote products derived from this software without + specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/updater/sql/win/README.md b/updater/sql/win/README.md new file mode 100755 index 0000000..ffc1f04 --- /dev/null +++ b/updater/sql/win/README.md @@ -0,0 +1,249 @@ +# ⚙️ node-sqlite3 + +Asynchronous, non-blocking [SQLite3](https://sqlite.org/) bindings for [Node.js](http://nodejs.org/). + +[![Latest release](https://img.shields.io/github/release/TryGhost/node-sqlite3.svg)](https://www.npmjs.com/package/sqlite3) +![Build Status](https://github.com/TryGhost/node-sqlite3/workflows/CI/badge.svg?branch=master) +[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmapbox%2Fnode-sqlite3.svg?type=shield)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmapbox%2Fnode-sqlite3?ref=badge_shield) +[![N-API v3 Badge](https://img.shields.io/badge/N--API-v3-green.svg)](https://nodejs.org/dist/latest/docs/api/n-api.html#n_api_n_api) +[![N-API v6 Badge](https://img.shields.io/badge/N--API-v6-green.svg)](https://nodejs.org/dist/latest/docs/api/n-api.html#n_api_n_api) + +# Features + + - Straightforward query and parameter binding interface + - Full Buffer/Blob support + - Extensive [debugging support](https://github.com/tryghost/node-sqlite3/wiki/Debugging) + - [Query serialization](https://github.com/tryghost/node-sqlite3/wiki/Control-Flow) API + - [Extension support](https://github.com/TryGhost/node-sqlite3/wiki/API#databaseloadextensionpath-callback), including bundled support for the [json1 extension](https://www.sqlite.org/json1.html) + - Big test suite + - Written in modern C++ and tested for memory leaks + - Bundles SQLite v3.44.2, or you can build using a local SQLite + +# Installing + +You can use [`npm`](https://github.com/npm/cli) or [`yarn`](https://github.com/yarnpkg/yarn) to install `sqlite3`: + +* (recommended) Latest published package: +```bash +npm install sqlite3 +# or +yarn add sqlite3 +``` +* GitHub's `master` branch: `npm install https://github.com/tryghost/node-sqlite3/tarball/master` + +### Prebuilt binaries + +`sqlite3` v5+ was rewritten to use [Node-API](https://nodejs.org/api/n-api.html) so prebuilt binaries do not need to be built for specific Node versions. `sqlite3` currently builds for both Node-API v3 and v6. Check the [Node-API version matrix](https://nodejs.org/api/n-api.html#node-api-version-matrix) to ensure your Node version supports one of these. The prebuilt binaries should be supported on Node v10+. + +The module uses [`prebuild-install`](https://github.com/prebuild/prebuild-install) to download the prebuilt binary for your platform, if it exists. These binaries are hosted on GitHub Releases for `sqlite3` versions above 5.0.2, and they are hosted on S3 otherwise. The following targets are currently provided: + +* `darwin-arm64` +* `darwin-x64` +* `linux-arm64` +* `linux-x64` +* `linuxmusl-arm64` +* `linuxmusl-x64` +* `win32-ia32` +* `win32-x64` + +Unfortunately, [prebuild](https://github.com/prebuild/prebuild/issues/174) cannot differentiate between `armv6` and `armv7`, and instead uses `arm` as the `{arch}`. Until that is fixed, you will still need to install `sqlite3` from [source](#source-install). + +Support for other platforms and architectures may be added in the future if CI supports building on them. + +If your environment isn't supported, it'll use `node-gyp` to build SQLite, but you will need to install a C++ compiler and linker. + +### Other ways to install + +It is also possible to make your own build of `sqlite3` from its source instead of its npm package ([See below.](#source-install)). + +The `sqlite3` module also works with [node-webkit](https://github.com/rogerwang/node-webkit) if node-webkit contains a supported version of Node.js engine. [(See below.)](#building-for-node-webkit) + +SQLite's [SQLCipher extension](https://github.com/sqlcipher/sqlcipher) is also supported. [(See below.)](#building-for-sqlcipher) + +# API + +See the [API documentation](https://github.com/TryGhost/node-sqlite3/wiki/API) in the wiki. + +# Usage + +**Note:** the module must be [installed](#installing) before use. + +``` js +const sqlite3 = require('sqlite3').verbose(); +const db = new sqlite3.Database(':memory:'); + +db.serialize(() => { + db.run("CREATE TABLE lorem (info TEXT)"); + + const stmt = db.prepare("INSERT INTO lorem VALUES (?)"); + for (let i = 0; i < 10; i++) { + stmt.run("Ipsum " + i); + } + stmt.finalize(); + + db.each("SELECT rowid AS id, info FROM lorem", (err, row) => { + console.log(row.id + ": " + row.info); + }); +}); + +db.close(); +``` + +## Source install + +To skip searching for pre-compiled binaries, and force a build from source, use + +```bash +npm install --build-from-source +``` + +The sqlite3 module depends only on libsqlite3. However, by default, an internal/bundled copy of sqlite will be built and statically linked, so an externally installed sqlite3 is not required. + +If you wish to install against an external sqlite then you need to pass the `--sqlite` argument to `npm` wrapper: + +```bash +npm install --build-from-source --sqlite=/usr/local +``` + +If building against an external sqlite3 make sure to have the development headers available. Mac OS X ships with these by default. If you don't have them installed, install the `-dev` package with your package manager, e.g. `apt-get install libsqlite3-dev` for Debian/Ubuntu. Make sure that you have at least `libsqlite3` >= 3.6. + +Note, if building against homebrew-installed sqlite on OS X you can do: + +```bash +npm install --build-from-source --sqlite=/usr/local/opt/sqlite/ +``` + +## Custom file header (magic) + +The default sqlite file header is "SQLite format 3". You can specify a different magic, though this will make standard tools and libraries unable to work with your files. + +```bash +npm install --build-from-source --sqlite_magic="MyCustomMagic15" +``` + +Note that the magic *must* be exactly 15 characters long (16 bytes including null terminator). + +## Building for node-webkit + +Because of ABI differences, `sqlite3` must be built in a custom to be used with [node-webkit](https://github.com/rogerwang/node-webkit). + +To build `sqlite3` for node-webkit: + +1. Install [`nw-gyp`](https://github.com/rogerwang/nw-gyp) globally: `npm install nw-gyp -g` *(unless already installed)* + +2. Build the module with the custom flags of `--runtime`, `--target_arch`, and `--target`: + +```bash +NODE_WEBKIT_VERSION="0.8.6" # see latest version at https://github.com/rogerwang/node-webkit#downloads +npm install sqlite3 --build-from-source --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION) +``` + +You can also run this command from within a `sqlite3` checkout: + +```bash +npm install --build-from-source --runtime=node-webkit --target_arch=ia32 --target=$(NODE_WEBKIT_VERSION) +``` + +Remember the following: + +* You must provide the right `--target_arch` flag. `ia32` is needed to target 32bit node-webkit builds, while `x64` will target 64bit node-webkit builds (if available for your platform). + +* After the `sqlite3` package is built for node-webkit it cannot run in the vanilla Node.js (and vice versa). + * For example, `npm test` of the node-webkit's package would fail. + +Visit the “[Using Node modules](https://github.com/rogerwang/node-webkit/wiki/Using-Node-modules)” article in the node-webkit's wiki for more details. + +## Building for SQLCipher + +For instructions on building SQLCipher, see [Building SQLCipher for Node.js](https://coolaj86.com/articles/building-sqlcipher-for-node-js-on-raspberry-pi-2/). Alternatively, you can install it with your local package manager. + +To run against SQLCipher, you need to compile `sqlite3` from source by passing build options like: + +```bash +npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=/usr/ + +node -e 'require("sqlite3")' +``` + +If your SQLCipher is installed in a custom location (if you compiled and installed it yourself), you'll need to set some environment variables: + +### On OS X with Homebrew + +Set the location where `brew` installed it: + +```bash +export LDFLAGS="-L`brew --prefix`/opt/sqlcipher/lib" +export CPPFLAGS="-I`brew --prefix`/opt/sqlcipher/include/sqlcipher" +npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix` + +node -e 'require("sqlite3")' +``` + +### On most Linuxes (including Raspberry Pi) + +Set the location where `make` installed it: + +```bash +export LDFLAGS="-L/usr/local/lib" +export CPPFLAGS="-I/usr/local/include -I/usr/local/include/sqlcipher" +export CXXFLAGS="$CPPFLAGS" +npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=/usr/local --verbose + +node -e 'require("sqlite3")' +``` + +### Custom builds and Electron + +Running `sqlite3` through [electron-rebuild](https://github.com/electron/electron-rebuild) does not preserve the SQLCipher extension, so some additional flags are needed to make this build Electron compatible. Your `npm install sqlite3 --build-from-source` command needs these additional flags (be sure to replace the target version with the current Electron version you are working with): + +```bash +--runtime=electron --target=18.2.1 --dist-url=https://electronjs.org/headers +``` + +In the case of MacOS with Homebrew, the command should look like the following: + +```bash +npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix` --runtime=electron --target=18.2.1 --dist-url=https://electronjs.org/headers +``` + +# Testing + +```bash +npm test +``` + +# Contributors + +* [Daniel Lockyer](https://github.com/daniellockyer) +* [Konstantin Käfer](https://github.com/kkaefer) +* [Dane Springmeyer](https://github.com/springmeyer) +* [Will White](https://github.com/willwhite) +* [Orlando Vazquez](https://github.com/orlandov) +* [Artem Kustikov](https://github.com/artiz) +* [Eric Fredricksen](https://github.com/grumdrig) +* [John Wright](https://github.com/mrjjwright) +* [Ryan Dahl](https://github.com/ry) +* [Tom MacWright](https://github.com/tmcw) +* [Carter Thaxton](https://github.com/carter-thaxton) +* [Audrius Kažukauskas](https://github.com/audriusk) +* [Johannes Schauer](https://github.com/pyneo) +* [Mithgol](https://github.com/Mithgol) +* [Kewde](https://github.com/kewde) + +# Acknowledgments + +Thanks to [Orlando Vazquez](https://github.com/orlandov), +[Eric Fredricksen](https://github.com/grumdrig) and +[Ryan Dahl](https://github.com/ry) for their SQLite bindings for node, and to mraleph on Freenode's #v8 for answering questions. + +This module was originally created by [Mapbox](https://mapbox.com/) & is now maintained by [Ghost](https://ghost.org). + +# Changelog + +We use [GitHub releases](https://github.com/TryGhost/node-sqlite3/releases) for notes on the latest versions. See [CHANGELOG.md](https://github.com/TryGhost/node-sqlite3/blob/b05f4594cf8b0de64743561fcd2cfe6f4571754d/CHANGELOG.md) in git history for details on older versions. + +# License + +`node-sqlite3` is [BSD licensed](https://github.com/tryghost/node-sqlite3/raw/master/LICENSE). + +[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmapbox%2Fnode-sqlite3.svg?type=large)](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Fmapbox%2Fnode-sqlite3?ref=badge_large) diff --git a/updater/sql/win/binding.gyp b/updater/sql/win/binding.gyp new file mode 100755 index 0000000..a8fccd0 --- /dev/null +++ b/updater/sql/win/binding.gyp @@ -0,0 +1,58 @@ +{ + "includes": [ "deps/common-sqlite.gypi" ], + "variables": { + "sqlite%":"internal", + "sqlite_libname%":"sqlite3", + "module_name": "node_sqlite3", + }, + "targets": [ + { + "target_name": "<(module_name)", + "cflags!": [ "-fno-exceptions" ], + "cflags_cc!": [ "-fno-exceptions" ], + "xcode_settings": { "GCC_ENABLE_CPP_EXCEPTIONS": "YES", + "CLANG_CXX_LIBRARY": "libc++", + "MACOSX_DEPLOYMENT_TARGET": "10.7", + }, + "msvs_settings": { + "VCCLCompilerTool": { "ExceptionHandling": 1 }, + }, + "include_dirs": [ + " + +import events = require("events"); + +export const OPEN_READONLY: number; +export const OPEN_READWRITE: number; +export const OPEN_CREATE: number; +export const OPEN_FULLMUTEX: number; +export const OPEN_SHAREDCACHE: number; +export const OPEN_PRIVATECACHE: number; +export const OPEN_URI: number; + +export const VERSION: string; +export const SOURCE_ID: string; +export const VERSION_NUMBER: number; + +export const OK: number; +export const ERROR: number; +export const INTERNAL: number; +export const PERM: number; +export const ABORT: number; +export const BUSY: number; +export const LOCKED: number; +export const NOMEM: number; +export const READONLY: number; +export const INTERRUPT: number +export const IOERR: number; +export const CORRUPT: number +export const NOTFOUND: number; +export const FULL: number; +export const CANTOPEN: number; +export const PROTOCOL: number; +export const EMPTY: number; +export const SCHEMA: number; +export const TOOBIG: number +export const CONSTRAINT: number +export const MISMATCH: number; +export const MISUSE: number; +export const NOLFS: number; +export const AUTH: number +export const FORMAT: number; +export const RANGE: number +export const NOTADB: number; + +export const LIMIT_LENGTH: number; +export const LIMIT_SQL_LENGTH: number; +export const LIMIT_COLUMN: number; +export const LIMIT_EXPR_DEPTH: number; +export const LIMIT_COMPOUND_SELECT: number; +export const LIMIT_VDBE_OP: number; +export const LIMIT_FUNCTION_ARG: number; +export const LIMIT_ATTACHED: number; +export const LIMIT_LIKE_PATTERN_LENGTH: number; +export const LIMIT_VARIABLE_NUMBER: number; +export const LIMIT_TRIGGER_DEPTH: number; +export const LIMIT_WORKER_THREADS: number; + +export const cached: { + Database(filename: string, callback?: (this: Database, err: Error | null) => void): Database; + Database(filename: string, mode?: number, callback?: (this: Database, err: Error | null) => void): Database; +}; + +export interface RunResult extends Statement { + lastID: number; + changes: number; +} + +export class Statement extends events.EventEmitter { + bind(callback?: (err: Error | null) => void): this; + bind(...params: any[]): this; + + reset(callback?: (err: null) => void): this; + + finalize(callback?: (err: Error) => void): Database; + + run(callback?: (err: Error | null) => void): this; + run(params: any, callback?: (this: RunResult, err: Error | null) => void): this; + run(...params: any[]): this; + + get(callback?: (err: Error | null, row?: T) => void): this; + get(params: any, callback?: (this: RunResult, err: Error | null, row?: T) => void): this; + get(...params: any[]): this; + + all(callback?: (err: Error | null, rows: T[]) => void): this; + all(params: any, callback?: (this: RunResult, err: Error | null, rows: T[]) => void): this; + all(...params: any[]): this; + + each(callback?: (err: Error | null, row: T) => void, complete?: (err: Error | null, count: number) => void): this; + each(params: any, callback?: (this: RunResult, err: Error | null, row: T) => void, complete?: (err: Error | null, count: number) => void): this; + each(...params: any[]): this; +} + +export class Database extends events.EventEmitter { + constructor(filename: string, callback?: (err: Error | null) => void); + constructor(filename: string, mode?: number, callback?: (err: Error | null) => void); + + close(callback?: (err: Error | null) => void): void; + + run(sql: string, callback?: (this: RunResult, err: Error | null) => void): this; + run(sql: string, params: any, callback?: (this: RunResult, err: Error | null) => void): this; + run(sql: string, ...params: any[]): this; + + get(sql: string, callback?: (this: Statement, err: Error | null, row: T) => void): this; + get(sql: string, params: any, callback?: (this: Statement, err: Error | null, row: T) => void): this; + get(sql: string, ...params: any[]): this; + + all(sql: string, callback?: (this: Statement, err: Error | null, rows: T[]) => void): this; + all(sql: string, params: any, callback?: (this: Statement, err: Error | null, rows: T[]) => void): this; + all(sql: string, ...params: any[]): this; + + each(sql: string, callback?: (this: Statement, err: Error | null, row: T) => void, complete?: (err: Error | null, count: number) => void): this; + each(sql: string, params: any, callback?: (this: Statement, err: Error | null, row: T) => void, complete?: (err: Error | null, count: number) => void): this; + each(sql: string, ...params: any[]): this; + + exec(sql: string, callback?: (this: Statement, err: Error | null) => void): this; + + prepare(sql: string, callback?: (this: Statement, err: Error | null) => void): Statement; + prepare(sql: string, params: any, callback?: (this: Statement, err: Error | null) => void): Statement; + prepare(sql: string, ...params: any[]): Statement; + + serialize(callback?: () => void): void; + parallelize(callback?: () => void): void; + + on(event: "trace", listener: (sql: string) => void): this; + on(event: "profile", listener: (sql: string, time: number) => void): this; + on(event: "change", listener: (type: string, database: string, table: string, rowid: number) => void): this; + on(event: "error", listener: (err: Error) => void): this; + on(event: "open" | "close", listener: () => void): this; + on(event: string, listener: (...args: any[]) => void): this; + + configure(option: "busyTimeout", value: number): void; + configure(option: "limit", id: number, value: number): void; + + loadExtension(filename: string, callback?: (err: Error | null) => void): this; + + wait(callback?: (param: null) => void): this; + + interrupt(): void; +} + +export function verbose(): sqlite3; + +export interface sqlite3 { + OPEN_READONLY: number; + OPEN_READWRITE: number; + OPEN_CREATE: number; + OPEN_FULLMUTEX: number; + OPEN_SHAREDCACHE: number; + OPEN_PRIVATECACHE: number; + OPEN_URI: number; + + VERSION: string; + SOURCE_ID: string; + VERSION_NUMBER: number; + + OK: number; + ERROR: number; + INTERNAL: number; + PERM: number; + ABORT: number; + BUSY: number; + LOCKED: number; + NOMEM: number; + READONLY: number; + INTERRUPT: number + IOERR: number; + CORRUPT: number + NOTFOUND: number; + FULL: number; + CANTOPEN: number; + PROTOCOL: number; + EMPTY: number; + SCHEMA: number; + TOOBIG: number + CONSTRAINT: number + MISMATCH: number; + MISUSE: number; + NOLFS: number; + AUTH: number + FORMAT: number; + RANGE: number + NOTADB: number; + + LIMIT_LENGTH: number; + LIMIT_SQL_LENGTH: number; + LIMIT_COLUMN: number; + LIMIT_EXPR_DEPTH: number; + LIMIT_COMPOUND_SELECT: number; + LIMIT_VDBE_OP: number; + LIMIT_FUNCTION_ARG: number; + LIMIT_ATTACHED: number; + LIMIT_LIKE_PATTERN_LENGTH: number; + LIMIT_VARIABLE_NUMBER: number; + LIMIT_TRIGGER_DEPTH: number; + LIMIT_WORKER_THREADS: number; + + cached: typeof cached; + RunResult: RunResult; + Statement: typeof Statement; + Database: typeof Database; + verbose(): this; +} \ No newline at end of file diff --git a/updater/sql/win/lib/sqlite3.js b/updater/sql/win/lib/sqlite3.js new file mode 100755 index 0000000..430a2b8 --- /dev/null +++ b/updater/sql/win/lib/sqlite3.js @@ -0,0 +1,207 @@ +const path = require('path'); +const sqlite3 = require('./sqlite3-binding.js'); +const EventEmitter = require('events').EventEmitter; +module.exports = exports = sqlite3; + +function normalizeMethod (fn) { + return function (sql) { + let errBack; + const args = Array.prototype.slice.call(arguments, 1); + + if (typeof args[args.length - 1] === 'function') { + const callback = args[args.length - 1]; + errBack = function(err) { + if (err) { + callback(err); + } + }; + } + const statement = new Statement(this, sql, errBack); + return fn.call(this, statement, args); + }; +} + +function inherits(target, source) { + for (const k in source.prototype) + target.prototype[k] = source.prototype[k]; +} + +sqlite3.cached = { + Database: function(file, a, b) { + if (file === '' || file === ':memory:') { + // Don't cache special databases. + return new Database(file, a, b); + } + + let db; + file = path.resolve(file); + + if (!sqlite3.cached.objects[file]) { + db = sqlite3.cached.objects[file] = new Database(file, a, b); + } + else { + // Make sure the callback is called. + db = sqlite3.cached.objects[file]; + const callback = (typeof a === 'number') ? b : a; + if (typeof callback === 'function') { + function cb() { callback.call(db, null); } + if (db.open) process.nextTick(cb); + else db.once('open', cb); + } + } + + return db; + }, + objects: {} +}; + + +const Database = sqlite3.Database; +const Statement = sqlite3.Statement; +const Backup = sqlite3.Backup; + +inherits(Database, EventEmitter); +inherits(Statement, EventEmitter); +inherits(Backup, EventEmitter); + +// Database#prepare(sql, [bind1, bind2, ...], [callback]) +Database.prototype.prepare = normalizeMethod(function(statement, params) { + return params.length + ? statement.bind.apply(statement, params) + : statement; +}); + +// Database#run(sql, [bind1, bind2, ...], [callback]) +Database.prototype.run = normalizeMethod(function(statement, params) { + statement.run.apply(statement, params).finalize(); + return this; +}); + +// Database#get(sql, [bind1, bind2, ...], [callback]) +Database.prototype.get = normalizeMethod(function(statement, params) { + statement.get.apply(statement, params).finalize(); + return this; +}); + +// Database#all(sql, [bind1, bind2, ...], [callback]) +Database.prototype.all = normalizeMethod(function(statement, params) { + statement.all.apply(statement, params).finalize(); + return this; +}); + +// Database#each(sql, [bind1, bind2, ...], [callback], [complete]) +Database.prototype.each = normalizeMethod(function(statement, params) { + statement.each.apply(statement, params).finalize(); + return this; +}); + +Database.prototype.map = normalizeMethod(function(statement, params) { + statement.map.apply(statement, params).finalize(); + return this; +}); + +// Database#backup(filename, [callback]) +// Database#backup(filename, destName, sourceName, filenameIsDest, [callback]) +Database.prototype.backup = function() { + let backup; + if (arguments.length <= 2) { + // By default, we write the main database out to the main database of the named file. + // This is the most likely use of the backup api. + backup = new Backup(this, arguments[0], 'main', 'main', true, arguments[1]); + } else { + // Otherwise, give the user full control over the sqlite3_backup_init arguments. + backup = new Backup(this, arguments[0], arguments[1], arguments[2], arguments[3], arguments[4]); + } + // Per the sqlite docs, exclude the following errors as non-fatal by default. + backup.retryErrors = [sqlite3.BUSY, sqlite3.LOCKED]; + return backup; +}; + +Statement.prototype.map = function() { + const params = Array.prototype.slice.call(arguments); + const callback = params.pop(); + params.push(function(err, rows) { + if (err) return callback(err); + const result = {}; + if (rows.length) { + const keys = Object.keys(rows[0]); + const key = keys[0]; + if (keys.length > 2) { + // Value is an object + for (let i = 0; i < rows.length; i++) { + result[rows[i][key]] = rows[i]; + } + } else { + const value = keys[1]; + // Value is a plain value + for (let i = 0; i < rows.length; i++) { + result[rows[i][key]] = rows[i][value]; + } + } + } + callback(err, result); + }); + return this.all.apply(this, params); +}; + +let isVerbose = false; + +const supportedEvents = [ 'trace', 'profile', 'change' ]; + +Database.prototype.addListener = Database.prototype.on = function(type) { + const val = EventEmitter.prototype.addListener.apply(this, arguments); + if (supportedEvents.indexOf(type) >= 0) { + this.configure(type, true); + } + return val; +}; + +Database.prototype.removeListener = function(type) { + const val = EventEmitter.prototype.removeListener.apply(this, arguments); + if (supportedEvents.indexOf(type) >= 0 && !this._events[type]) { + this.configure(type, false); + } + return val; +}; + +Database.prototype.removeAllListeners = function(type) { + const val = EventEmitter.prototype.removeAllListeners.apply(this, arguments); + if (supportedEvents.indexOf(type) >= 0) { + this.configure(type, false); + } + return val; +}; + +// Save the stack trace over EIO callbacks. +sqlite3.verbose = function() { + if (!isVerbose) { + const trace = require('./trace'); + [ + 'prepare', + 'get', + 'run', + 'all', + 'each', + 'map', + 'close', + 'exec' + ].forEach(function (name) { + trace.extendTrace(Database.prototype, name); + }); + [ + 'bind', + 'get', + 'run', + 'all', + 'each', + 'map', + 'reset', + 'finalize', + ].forEach(function (name) { + trace.extendTrace(Statement.prototype, name); + }); + isVerbose = true; + } + + return sqlite3; +}; diff --git a/updater/sql/win/lib/trace.js b/updater/sql/win/lib/trace.js new file mode 100755 index 0000000..1d84cb0 --- /dev/null +++ b/updater/sql/win/lib/trace.js @@ -0,0 +1,38 @@ +// Inspired by https://github.com/tlrobinson/long-stack-traces +const util = require('util'); + +function extendTrace(object, property, pos) { + const old = object[property]; + object[property] = function() { + const error = new Error(); + const name = object.constructor.name + '#' + property + '(' + + Array.prototype.slice.call(arguments).map(function(el) { + return util.inspect(el, false, 0); + }).join(', ') + ')'; + + if (typeof pos === 'undefined') pos = -1; + if (pos < 0) pos += arguments.length; + const cb = arguments[pos]; + if (typeof arguments[pos] === 'function') { + arguments[pos] = function replacement() { + const err = arguments[0]; + if (err && err.stack && !err.__augmented) { + err.stack = filter(err).join('\n'); + err.stack += '\n--> in ' + name; + err.stack += '\n' + filter(error).slice(1).join('\n'); + err.__augmented = true; + } + return cb.apply(this, arguments); + }; + } + return old.apply(this, arguments); + }; +} +exports.extendTrace = extendTrace; + + +function filter(error) { + return error.stack.split('\n').filter(function(line) { + return line.indexOf(__filename) < 0; + }); +} diff --git a/updater/sql/win/package.json b/updater/sql/win/package.json new file mode 100755 index 0000000..b6496ad --- /dev/null +++ b/updater/sql/win/package.json @@ -0,0 +1,89 @@ +{ + "name": "sqlite3-win", + "description": "Asynchronous, non-blocking SQLite3 bindings", + "version": "5.1.7", + "homepage": "https://github.com/TryGhost/node-sqlite3", + "author": { + "name": "Mapbox", + "url": "https://mapbox.com/" + }, + "binary": { + "napi_versions": [ + 3, + 6 + ] + }, + "contributors": [ + "Daniel Lockyer ", + "Konstantin Käfer ", + "Dane Springmeyer ", + "Will White ", + "Orlando Vazquez ", + "Artem Kustikov ", + "Eric Fredricksen ", + "John Wright ", + "Ryan Dahl ", + "Tom MacWright ", + "Carter Thaxton ", + "Audrius Kažukauskas ", + "Johannes Schauer ", + "Nathan Rajlich ", + "AJ ONeal ", + "Mithgol", + "Ben Noordhuis " + ], + "files": [ + "binding.gyp", + "deps/", + "lib/*.js", + "lib/*.d.ts", + "src/" + ], + "repository": { + "type": "git", + "url": "https://github.com/TryGhost/node-sqlite3.git" + }, + "dependencies": { + "bindings": "^1.5.0", + "node-addon-api": "^7.0.0", + "prebuild-install": "^7.1.1", + "tar": "^6.1.11" + }, + "devDependencies": { + "eslint": "8.56.0", + "mocha": "10.2.0", + "prebuild": "12.1.0" + }, + "peerDependencies": { + "node-gyp": "8.x" + }, + "peerDependenciesMeta": { + "node-gyp": { + "optional": true + } + }, + "optionalDependencies": { + "node-gyp": "8.x" + }, + "scripts": { + "install": "prebuild-install -r napi || node-gyp rebuild", + "prebuild": "prebuild --runtime napi --all --verbose", + "rebuild": "node-gyp rebuild", + "upload": "prebuild --verbose --prerelease", + "test": "node test/support/createdb.js && mocha -R spec --timeout 480000" + }, + "license": "BSD-3-Clause", + "keywords": [ + "sql", + "sqlite", + "sqlite3", + "database" + ], + "main": "./lib/sqlite3", + "types": "./lib/sqlite3.d.ts", + "renovate": { + "extends": [ + "@tryghost:base" + ] + } +} diff --git a/updater/sql/win/src/async.h b/updater/sql/win/src/async.h new file mode 100755 index 0000000..f36e4cb --- /dev/null +++ b/updater/sql/win/src/async.h @@ -0,0 +1,76 @@ +#ifndef NODE_SQLITE3_SRC_ASYNC_H +#define NODE_SQLITE3_SRC_ASYNC_H + +#include +#include + +#include "threading.h" + +// Generic uv_async handler. +template class Async { + typedef void (*Callback)(Parent* parent, Item* item); + +protected: + uv_async_t watcher; + NODE_SQLITE3_MUTEX_t + std::vector data; + Callback callback; +public: + Parent* parent; + +public: + Async(Parent* parent_, Callback cb_) + : callback(cb_), parent(parent_) { + watcher.data = this; + NODE_SQLITE3_MUTEX_INIT + uv_loop_t *loop; + napi_get_uv_event_loop(parent_->Env(), &loop); + uv_async_init(loop, &watcher, reinterpret_cast(listener)); + } + + static void listener(uv_async_t* handle) { + auto* async = static_cast(handle->data); + std::vector rows; + NODE_SQLITE3_MUTEX_LOCK(&async->mutex) + rows.swap(async->data); + NODE_SQLITE3_MUTEX_UNLOCK(&async->mutex) + for(auto row : rows) + async->callback(async->parent, row); + } + + static void close(uv_handle_t* handle) { + assert(handle != NULL); + assert(handle->data != NULL); + auto* async = static_cast(handle->data); + delete async; + } + + void finish() { + // Need to call the listener again to ensure all items have been + // processed. Is this a bug in uv_async? Feels like uv_close + // should handle that. + listener(&watcher); + uv_close((uv_handle_t*)&watcher, close); + } + + void add(Item* item) { + NODE_SQLITE3_MUTEX_LOCK(&mutex); + data.emplace_back(item); + NODE_SQLITE3_MUTEX_UNLOCK(&mutex) + } + + void send() { + uv_async_send(&watcher); + } + + void send(Item* item) { + add(item); + send(); + } + + ~Async() { + NODE_SQLITE3_MUTEX_DESTROY + } +}; + +#endif diff --git a/updater/sql/win/src/backup.cc b/updater/sql/win/src/backup.cc new file mode 100755 index 0000000..0f971f5 --- /dev/null +++ b/updater/sql/win/src/backup.cc @@ -0,0 +1,418 @@ +#include +#include +#include "macros.h" +#include "database.h" +#include "backup.h" + +using namespace node_sqlite3; + +Napi::Object Backup::Init(Napi::Env env, Napi::Object exports) { + Napi::HandleScope scope(env); + + // declare napi_default_method here as it is only available in Node v14.12.0+ + auto napi_default_method = static_cast(napi_writable | napi_configurable); + + auto t = DefineClass(env, "Backup", { + InstanceMethod("step", &Backup::Step, napi_default_method), + InstanceMethod("finish", &Backup::Finish, napi_default_method), + InstanceAccessor("idle", &Backup::IdleGetter, nullptr), + InstanceAccessor("completed", &Backup::CompletedGetter, nullptr), + InstanceAccessor("failed", &Backup::FailedGetter, nullptr), + InstanceAccessor("remaining", &Backup::RemainingGetter, nullptr), + InstanceAccessor("pageCount", &Backup::PageCountGetter, nullptr), + InstanceAccessor("retryErrors", &Backup::RetryErrorGetter, &Backup::RetryErrorSetter), + }); + + exports.Set("Backup", t); + return exports; +} + +void Backup::Process() { + if (finished && !queue.empty()) { + return CleanQueue(); + } + + while (inited && !locked && !queue.empty()) { + auto call = std::move(queue.front()); + queue.pop(); + + call->callback(call->baton); + } +} + +void Backup::Schedule(Work_Callback callback, Baton* baton) { + if (finished) { + queue.emplace(new Call(callback, baton)); + CleanQueue(); + } + else if (!inited || locked || !queue.empty()) { + queue.emplace(new Call(callback, baton)); + } + else { + callback(baton); + } +} + +template void Backup::Error(T* baton) { + auto env = baton->backup->Env(); + Napi::HandleScope scope(env); + + Backup* backup = baton->backup; + // Fail hard on logic errors. + assert(backup->status != 0); + EXCEPTION(Napi::String::New(env, backup->message), backup->status, exception); + + Napi::Function cb = baton->callback.Value(); + + if (!cb.IsEmpty() && cb.IsFunction()) { + Napi::Value argv[] = { exception }; + TRY_CATCH_CALL(backup->Value(), cb, 1, argv); + } + else { + Napi::Value argv[] = { Napi::String::New(env, "error"), exception }; + EMIT_EVENT(backup->Value(), 2, argv); + } +} + +void Backup::CleanQueue() { + auto env = this->Env(); + Napi::HandleScope scope(env); + + if (inited && !queue.empty()) { + // This backup has already been initialized and is now finished. + // Fire error for all remaining items in the queue. + EXCEPTION(Napi::String::New(env, "Backup is already finished"), SQLITE_MISUSE, exception); + Napi::Value argv[] = { exception }; + bool called = false; + + // Clear out the queue so that this object can get GC'ed. + while (!queue.empty()) { + auto call = std::move(queue.front()); + queue.pop(); + + std::unique_ptr baton(call->baton); + Napi::Function cb = baton->callback.Value(); + + if (inited && !cb.IsEmpty() && + cb.IsFunction()) { + TRY_CATCH_CALL(Value(), cb, 1, argv); + called = true; + } + } + + // When we couldn't call a callback function, emit an error on the + // Backup object. + if (!called) { + Napi::Value info[] = { Napi::String::New(env, "error"), exception }; + EMIT_EVENT(Value(), 2, info); + } + } + else while (!queue.empty()) { + // Just delete all items in the queue; we already fired an event when + // initializing the backup failed. + auto call = std::move(queue.front()); + queue.pop(); + + // We don't call the actual callback, so we have to make sure that + // the baton gets destroyed. + delete call->baton; + } +} + +Backup::Backup(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { + auto env = info.Env(); + if (!info.IsConstructCall()) { + Napi::TypeError::New(env, "Use the new operator to create new Backup objects").ThrowAsJavaScriptException(); + return; + } + + auto length = info.Length(); + + if (length <= 0 || !Database::HasInstance(info[0])) { + Napi::TypeError::New(env, "Database object expected").ThrowAsJavaScriptException(); + return; + } + else if (length <= 1 || !info[1].IsString()) { + Napi::TypeError::New(env, "Filename expected").ThrowAsJavaScriptException(); + return; + } + else if (length <= 2 || !info[2].IsString()) { + Napi::TypeError::New(env, "Source database name expected").ThrowAsJavaScriptException(); + return; + } + else if (length <= 3 || !info[3].IsString()) { + Napi::TypeError::New(env, "Destination database name expected").ThrowAsJavaScriptException(); + return; + } + else if (length <= 4 || !info[4].IsBoolean()) { + Napi::TypeError::New(env, "Direction flag expected").ThrowAsJavaScriptException(); + return; + } + else if (length > 5 && !info[5].IsUndefined() && !info[5].IsFunction()) { + Napi::TypeError::New(env, "Callback expected").ThrowAsJavaScriptException(); + return; + } + + this->db = Napi::ObjectWrap::Unwrap(info[0].As()); + this->db->Ref(); + + auto filename = info[1].As(); + auto sourceName = info[2].As(); + auto destName = info[3].As(); + auto filenameIsDest = info[4].As(); + + info.This().As().DefineProperty(Napi::PropertyDescriptor::Value("filename", filename)); + info.This().As().DefineProperty(Napi::PropertyDescriptor::Value("sourceName", sourceName)); + info.This().As().DefineProperty(Napi::PropertyDescriptor::Value("destName", destName)); + info.This().As().DefineProperty(Napi::PropertyDescriptor::Value("filenameIsDest", filenameIsDest)); + + auto* baton = new InitializeBaton(this->db, info[5].As(), this); + baton->filename = filename.Utf8Value(); + baton->sourceName = sourceName.Utf8Value(); + baton->destName = destName.Utf8Value(); + baton->filenameIsDest = filenameIsDest.Value(); + + this->db->Schedule(Work_BeginInitialize, baton); +} + +void Backup::Work_BeginInitialize(Database::Baton* baton) { + assert(baton->db->open); + baton->db->pending++; + auto env = baton->db->Env(); + CREATE_WORK("sqlite3.Backup.Initialize", Work_Initialize, Work_AfterInitialize); +} + +void Backup::Work_Initialize(napi_env e, void* data) { + BACKUP_INIT(InitializeBaton); + + // In case stepping fails, we use a mutex to make sure we get the associated + // error message. + auto* mtx = sqlite3_db_mutex(baton->db->_handle); + sqlite3_mutex_enter(mtx); + + backup->status = sqlite3_open(baton->filename.c_str(), &backup->_otherDb); + + if (backup->status == SQLITE_OK) { + backup->_handle = sqlite3_backup_init( + baton->filenameIsDest ? backup->_otherDb : backup->db->_handle, + baton->destName.c_str(), + baton->filenameIsDest ? backup->db->_handle : backup->_otherDb, + baton->sourceName.c_str()); + } + backup->_destDb = baton->filenameIsDest ? backup->_otherDb : backup->db->_handle; + + if (backup->status != SQLITE_OK) { + backup->message = std::string(sqlite3_errmsg(backup->_destDb)); + sqlite3_close(backup->_otherDb); + backup->_otherDb = NULL; + backup->_destDb = NULL; + } + + sqlite3_mutex_leave(mtx); +} + +void Backup::Work_AfterInitialize(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + auto* backup = baton->backup; + + auto env = backup->Env(); + Napi::HandleScope scope(env); + + if (backup->status != SQLITE_OK) { + Error(baton.get()); + backup->FinishAll(); + } + else { + backup->inited = true; + Napi::Function cb = baton->callback.Value(); + if (!cb.IsEmpty() && cb.IsFunction()) { + Napi::Value argv[] = { env.Null() }; + TRY_CATCH_CALL(backup->Value(), cb, 1, argv); + } + } + BACKUP_END(); +} + +Napi::Value Backup::Step(const Napi::CallbackInfo& info) { + auto* backup = this; + auto env = backup->Env(); + + REQUIRE_ARGUMENT_INTEGER(0, pages); + OPTIONAL_ARGUMENT_FUNCTION(1, callback); + + auto* baton = new StepBaton(backup, callback, pages); + backup->GetRetryErrors(baton->retryErrorsSet); + backup->Schedule(Work_BeginStep, baton); + return info.This(); +} + +void Backup::Work_BeginStep(Baton* baton) { + BACKUP_BEGIN(Step); +} + +void Backup::Work_Step(napi_env e, void* data) { + BACKUP_INIT(StepBaton); + if (backup->_handle) { + backup->status = sqlite3_backup_step(backup->_handle, baton->pages); + backup->remaining = sqlite3_backup_remaining(backup->_handle); + backup->pageCount = sqlite3_backup_pagecount(backup->_handle); + } + if (backup->status != SQLITE_OK) { + // Text of message is a little awkward to get, since the error is not associated + // with a db connection. +#if SQLITE_VERSION_NUMBER >= 3007015 + // sqlite3_errstr is a relatively new method + backup->message = std::string(sqlite3_errstr(backup->status)); +#else + backup->message = "Sqlite error"; +#endif + if (baton->retryErrorsSet.size() > 0) { + if (baton->retryErrorsSet.find(backup->status) == baton->retryErrorsSet.end()) { + backup->FinishSqlite(); + } + } + } +} + +void Backup::Work_AfterStep(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + auto* backup = baton->backup; + + auto env = backup->Env(); + Napi::HandleScope scope(env); + + if (backup->status == SQLITE_DONE) { + backup->completed = true; + } else if (!backup->_handle) { + backup->failed = true; + } + + if (backup->status != SQLITE_OK && backup->status != SQLITE_DONE) { + Error(baton.get()); + } + else { + // Fire callbacks. + Napi::Function cb = baton->callback.Value(); + if (!cb.IsEmpty() && cb.IsFunction()) { + Napi::Value argv[] = { env.Null(), Napi::Boolean::New(env, backup->status == SQLITE_DONE) }; + TRY_CATCH_CALL(backup->Value(), cb, 2, argv); + } + } + + BACKUP_END(); +} + +Napi::Value Backup::Finish(const Napi::CallbackInfo& info) { + auto* backup = this; + auto env = backup->Env(); + + OPTIONAL_ARGUMENT_FUNCTION(0, callback); + + auto* baton = new Baton(backup, callback); + backup->Schedule(Work_BeginFinish, baton); + return info.This(); +} + +void Backup::Work_BeginFinish(Baton* baton) { + BACKUP_BEGIN(Finish); +} + +void Backup::Work_Finish(napi_env e, void* data) { + BACKUP_INIT(Baton); + backup->FinishSqlite(); +} + +void Backup::Work_AfterFinish(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + auto* backup = baton->backup; + + auto env = backup->Env(); + Napi::HandleScope scope(env); + + backup->FinishAll(); + + // Fire callback in case there was one. + Napi::Function cb = baton->callback.Value(); + if (!cb.IsEmpty() && cb.IsFunction()) { + TRY_CATCH_CALL(backup->Value(), cb, 0, NULL); + } + + BACKUP_END(); +} + +void Backup::FinishAll() { + assert(!finished); + if (!completed && !failed) { + failed = true; + } + finished = true; + CleanQueue(); + FinishSqlite(); + db->Unref(); +} + +void Backup::FinishSqlite() { + if (_handle) { + sqlite3_backup_finish(_handle); + _handle = NULL; + } + if (_otherDb) { + sqlite3_close(_otherDb); + _otherDb = NULL; + } + _destDb = NULL; +} + +Napi::Value Backup::IdleGetter(const Napi::CallbackInfo& info) { + auto* backup = this; + bool idle = backup->inited && !backup->locked && backup->queue.empty(); + return Napi::Boolean::New(this->Env(), idle); +} + +Napi::Value Backup::CompletedGetter(const Napi::CallbackInfo& info) { + auto* backup = this; + return Napi::Boolean::New(this->Env(), backup->completed); +} + +Napi::Value Backup::FailedGetter(const Napi::CallbackInfo& info) { + auto* backup = this; + return Napi::Boolean::New(this->Env(), backup->failed); +} + +Napi::Value Backup::RemainingGetter(const Napi::CallbackInfo& info) { + auto* backup = this; + return Napi::Number::New(this->Env(), backup->remaining); +} + +Napi::Value Backup::PageCountGetter(const Napi::CallbackInfo& info) { + auto* backup = this; + return Napi::Number::New(this->Env(), backup->pageCount); +} + +Napi::Value Backup::RetryErrorGetter(const Napi::CallbackInfo& info) { + auto* backup = this; + return backup->retryErrors.Value(); +} + +void Backup::RetryErrorSetter(const Napi::CallbackInfo& info, const Napi::Value& value) { + auto* backup = this; + auto env = backup->Env(); + if (!value.IsArray()) { + Napi::Error::New(env, "retryErrors must be an array").ThrowAsJavaScriptException(); + return; + } + Napi::Array array = value.As(); + backup->retryErrors.Reset(array, 1); +} + +void Backup::GetRetryErrors(std::set& retryErrorsSet) { + retryErrorsSet.clear(); + Napi::Array array = retryErrors.Value(); + auto length = array.Length(); + for (size_t i = 0; i < length; i++) { + Napi::Value code = (array).Get(static_cast(i)); + if (code.IsNumber()) { + retryErrorsSet.insert(code.As().Int32Value()); + } + } +} diff --git a/updater/sql/win/src/backup.h b/updater/sql/win/src/backup.h new file mode 100755 index 0000000..b894aca --- /dev/null +++ b/updater/sql/win/src/backup.h @@ -0,0 +1,209 @@ +#ifndef NODE_SQLITE3_SRC_BACKUP_H +#define NODE_SQLITE3_SRC_BACKUP_H + +#include "database.h" + +#include +#include +#include + +#include +#include + +using namespace Napi; + +namespace node_sqlite3 { + +/** + * + * A class for managing an sqlite3_backup object. For consistency + * with other node-sqlite3 classes, it maintains an internal queue + * of calls. + * + * Intended usage from node: + * + * var db = new sqlite3.Database('live.db'); + * var backup = db.backup('backup.db'); + * ... + * // in event loop, move backup forward when we have time. + * if (backup.idle) { backup.step(NPAGES); } + * if (backup.completed) { ... success ... } + * if (backup.failed) { ... sadness ... } + * // do other work in event loop - fine to modify live.db + * ... + * + * Here is how sqlite's backup api is exposed: + * + * - `sqlite3_backup_init`: This is implemented as + * `db.backup(filename, [callback])` or + * `db.backup(filename, destDbName, sourceDbName, filenameIsDest, [callback])`. + * - `sqlite3_backup_step`: `backup.step(pages, [callback])`. + * - `sqlite3_backup_finish`: `backup.finish([callback])`. + * - `sqlite3_backup_remaining`: `backup.remaining`. + * - `sqlite3_backup_pagecount`: `backup.pageCount`. + * + * There are the following read-only properties: + * + * - `backup.completed` is set to `true` when the backup + * succeeeds. + * - `backup.failed` is set to `true` when the backup + * has a fatal error. + * - `backup.idle` is set to `true` when no operation + * is currently in progress or queued for the backup. + * - `backup.remaining` is an integer with the remaining + * number of pages after the last call to `backup.step` + * (-1 if `step` not yet called). + * - `backup.pageCount` is an integer with the total number + * of pages measured during the last call to `backup.step` + * (-1 if `step` not yet called). + * + * There is the following writable property: + * + * - `backup.retryErrors`: an array of sqlite3 error codes + * that are treated as non-fatal - meaning, if they occur, + * backup.failed is not set, and the backup may continue. + * By default, this is `[sqlite3.BUSY, sqlite3.LOCKED]`. + * + * The `db.backup(filename, [callback])` shorthand is sufficient + * for making a backup of a database opened by node-sqlite3. If + * using attached or temporary databases, or moving data in the + * opposite direction, the more complete (but daunting) + * `db.backup(filename, destDbName, sourceDbName, filenameIsDest, [callback])` + * signature is provided. + * + * A backup will finish automatically when it succeeds or a fatal + * error occurs, meaning it is not necessary to call `db.finish()`. + * By default, SQLITE_LOCKED and SQLITE_BUSY errors are not + * treated as failures, and the backup will continue if they + * occur. The set of errors that are tolerated can be controlled + * by setting `backup.retryErrors`. To disable automatic + * finishing and stick strictly to sqlite's raw api, set + * `backup.retryErrors` to `[]`. In that case, it is necessary + * to call `backup.finish()`. + * + * In the same way as node-sqlite3 databases and statements, + * backup methods can be called safely without callbacks, due + * to an internal call queue. So for example this naive code + * will correctly back up a db, if there are no errors: + * + * var backup = db.backup('backup.db'); + * backup.step(-1); + * backup.finish(); + * + */ +class Backup : public Napi::ObjectWrap { +public: + static Napi::Object Init(Napi::Env env, Napi::Object exports); + + struct Baton { + napi_async_work request = NULL; + Backup* backup; + Napi::FunctionReference callback; + + Baton(Backup* backup_, Napi::Function cb_) : backup(backup_) { + backup->Ref(); + callback.Reset(cb_, 1); + } + virtual ~Baton() { + if (request) napi_delete_async_work(backup->Env(), request); + backup->Unref(); + callback.Reset(); + } + }; + + struct InitializeBaton : Database::Baton { + Backup* backup; + std::string filename; + std::string sourceName; + std::string destName; + bool filenameIsDest; + InitializeBaton(Database* db_, Napi::Function cb_, Backup* backup_) : + Baton(db_, cb_), backup(backup_), filenameIsDest(true) { + backup->Ref(); + } + virtual ~InitializeBaton() override { + backup->Unref(); + if (!db->IsOpen() && db->IsLocked()) { + // The database handle was closed before the backup could be opened. + backup->FinishAll(); + } + } + }; + + struct StepBaton : Baton { + int pages; + std::set retryErrorsSet; + StepBaton(Backup* backup_, Napi::Function cb_, int pages_) : + Baton(backup_, cb_), pages(pages_) {} + virtual ~StepBaton() override = default; + }; + + typedef void (*Work_Callback)(Baton* baton); + + struct Call { + Call(Work_Callback cb_, Baton* baton_) : callback(cb_), baton(baton_) {}; + Work_Callback callback; + Baton* baton; + }; + + Backup(const Napi::CallbackInfo& info); + + ~Backup() { + if (!finished) { + FinishAll(); + } + retryErrors.Reset(); + } + + WORK_DEFINITION(Step) + WORK_DEFINITION(Finish) + + Napi::Value IdleGetter(const Napi::CallbackInfo& info); + Napi::Value CompletedGetter(const Napi::CallbackInfo& info); + Napi::Value FailedGetter(const Napi::CallbackInfo& info); + Napi::Value PageCountGetter(const Napi::CallbackInfo& info); + Napi::Value RemainingGetter(const Napi::CallbackInfo& info); + Napi::Value FatalErrorGetter(const Napi::CallbackInfo& info); + Napi::Value RetryErrorGetter(const Napi::CallbackInfo& info); + + void FatalErrorSetter(const Napi::CallbackInfo& info, const Napi::Value& value); + void RetryErrorSetter(const Napi::CallbackInfo& info, const Napi::Value& value); + +protected: + static void Work_BeginInitialize(Database::Baton* baton); + static void Work_Initialize(napi_env env, void* data); + static void Work_AfterInitialize(napi_env env, napi_status status, void* data); + + void Schedule(Work_Callback callback, Baton* baton); + void Process(); + void CleanQueue(); + template static void Error(T* baton); + + void FinishAll(); + void FinishSqlite(); + void GetRetryErrors(std::set& retryErrorsSet); + + Database* db; + + sqlite3_backup* _handle = NULL; + sqlite3* _otherDb = NULL; + sqlite3* _destDb = NULL; + + bool inited = false; + bool locked = true; + bool completed = false; + bool failed = false; + int remaining = -1; + int pageCount = -1; + bool finished = false; + + int status; + std::string message; + std::queue> queue; + + Napi::Reference retryErrors; +}; + +} + +#endif diff --git a/updater/sql/win/src/database.cc b/updater/sql/win/src/database.cc new file mode 100755 index 0000000..d495ce9 --- /dev/null +++ b/updater/sql/win/src/database.cc @@ -0,0 +1,751 @@ +#include +#include + +#include "macros.h" +#include "database.h" +#include "statement.h" + +using namespace node_sqlite3; + +#if NAPI_VERSION < 6 +Napi::FunctionReference Database::constructor; +#endif + +Napi::Object Database::Init(Napi::Env env, Napi::Object exports) { + Napi::HandleScope scope(env); + // declare napi_default_method here as it is only available in Node v14.12.0+ + auto napi_default_method = static_cast(napi_writable | napi_configurable); + + auto t = DefineClass(env, "Database", { + InstanceMethod("close", &Database::Close, napi_default_method), + InstanceMethod("exec", &Database::Exec, napi_default_method), + InstanceMethod("wait", &Database::Wait, napi_default_method), + InstanceMethod("loadExtension", &Database::LoadExtension, napi_default_method), + InstanceMethod("serialize", &Database::Serialize, napi_default_method), + InstanceMethod("parallelize", &Database::Parallelize, napi_default_method), + InstanceMethod("configure", &Database::Configure, napi_default_method), + InstanceMethod("interrupt", &Database::Interrupt, napi_default_method), + InstanceAccessor("open", &Database::Open, nullptr) + }); + +#if NAPI_VERSION < 6 + constructor = Napi::Persistent(t); + constructor.SuppressDestruct(); +#else + Napi::FunctionReference* constructor = new Napi::FunctionReference(); + *constructor = Napi::Persistent(t); + env.SetInstanceData(constructor); +#endif + + exports.Set("Database", t); + return exports; +} + +void Database::Process() { + auto env = this->Env(); + Napi::HandleScope scope(env); + + if (!open && locked && !queue.empty()) { + EXCEPTION(Napi::String::New(env, "Database handle is closed"), SQLITE_MISUSE, exception); + Napi::Value argv[] = { exception }; + bool called = false; + + // Call all callbacks with the error object. + while (!queue.empty()) { + auto call = std::unique_ptr(queue.front()); + queue.pop(); + auto baton = std::unique_ptr(call->baton); + Napi::Function cb = baton->callback.Value(); + if (IS_FUNCTION(cb)) { + TRY_CATCH_CALL(this->Value(), cb, 1, argv); + called = true; + } + } + + // When we couldn't call a callback function, emit an error on the + // Database object. + if (!called) { + Napi::Value info[] = { Napi::String::New(env, "error"), exception }; + EMIT_EVENT(Value(), 2, info); + } + return; + } + + while (open && (!locked || pending == 0) && !queue.empty()) { + Call *c = queue.front(); + + if (c->exclusive && pending > 0) { + break; + } + + queue.pop(); + std::unique_ptr call(c); + locked = call->exclusive; + call->callback(call->baton); + + if (locked) break; + } +} + +void Database::Schedule(Work_Callback callback, Baton* baton, bool exclusive) { + auto env = this->Env(); + Napi::HandleScope scope(env); + + if (!open && locked) { + EXCEPTION(Napi::String::New(env, "Database is closed"), SQLITE_MISUSE, exception); + Napi::Function cb = baton->callback.Value(); + // We don't call the actual callback, so we have to make sure that + // the baton gets destroyed. + delete baton; + if (IS_FUNCTION(cb)) { + Napi::Value argv[] = { exception }; + TRY_CATCH_CALL(Value(), cb, 1, argv); + } + else { + Napi::Value argv[] = { Napi::String::New(env, "error"), exception }; + EMIT_EVENT(Value(), 2, argv); + } + return; + } + + if (!open || ((locked || exclusive || serialize) && pending > 0)) { + queue.emplace(new Call(callback, baton, exclusive || serialize)); + } + else { + locked = exclusive; + callback(baton); + } +} + +Database::Database(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { + auto env = info.Env(); + + if (info.Length() <= 0 || !info[0].IsString()) { + Napi::TypeError::New(env, "String expected").ThrowAsJavaScriptException(); + return; + } + auto filename = info[0].As().Utf8Value(); + + unsigned int pos = 1; + + int mode; + if (info.Length() >= pos && info[pos].IsNumber() && OtherIsInt(info[pos].As())) { + mode = info[pos++].As().Int32Value(); + } + else { + mode = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX; + } + + Napi::Function callback; + if (info.Length() >= pos && info[pos].IsFunction()) { + callback = info[pos++].As(); + } + + info.This().As().DefineProperty(Napi::PropertyDescriptor::Value("filename", info[0].As(), napi_default)); + info.This().As().DefineProperty(Napi::PropertyDescriptor::Value("mode", Napi::Number::New(env, mode), napi_default)); + + // Start opening the database. + auto* baton = new OpenBaton(this, callback, filename.c_str(), mode); + Work_BeginOpen(baton); +} + +void Database::Work_BeginOpen(Baton* baton) { + auto env = baton->db->Env(); + CREATE_WORK("sqlite3.Database.Open", Work_Open, Work_AfterOpen); +} + +void Database::Work_Open(napi_env e, void* data) { + auto* baton = static_cast(data); + auto* db = baton->db; + + baton->status = sqlite3_open_v2( + baton->filename.c_str(), + &db->_handle, + baton->mode, + NULL + ); + + if (baton->status != SQLITE_OK) { + baton->message = std::string(sqlite3_errmsg(db->_handle)); + sqlite3_close(db->_handle); + db->_handle = NULL; + } + else { + // Set default database handle values. + sqlite3_busy_timeout(db->_handle, 1000); + } +} + +void Database::Work_AfterOpen(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + + auto* db = baton->db; + + auto env = db->Env(); + Napi::HandleScope scope(env); + + Napi::Value argv[1]; + if (baton->status != SQLITE_OK) { + EXCEPTION(Napi::String::New(env, baton->message.c_str()), baton->status, exception); + argv[0] = exception; + } + else { + db->open = true; + argv[0] = env.Null(); + } + + Napi::Function cb = baton->callback.Value(); + + if (IS_FUNCTION(cb)) { + TRY_CATCH_CALL(db->Value(), cb, 1, argv); + } + else if (!db->open) { + Napi::Value info[] = { Napi::String::New(env, "error"), argv[0] }; + EMIT_EVENT(db->Value(), 2, info); + } + + if (db->open) { + Napi::Value info[] = { Napi::String::New(env, "open") }; + EMIT_EVENT(db->Value(), 1, info); + db->Process(); + } +} + +Napi::Value Database::Open(const Napi::CallbackInfo& info) { + auto env = this->Env(); + auto* db = this; + return Napi::Boolean::New(env, db->open); +} + +Napi::Value Database::Close(const Napi::CallbackInfo& info) { + auto env = info.Env(); + auto* db = this; + OPTIONAL_ARGUMENT_FUNCTION(0, callback); + + auto* baton = new Baton(db, callback); + db->Schedule(Work_BeginClose, baton, true); + + return info.This(); +} + +void Database::Work_BeginClose(Baton* baton) { + assert(baton->db->locked); + assert(baton->db->open); + assert(baton->db->_handle); + assert(baton->db->pending == 0); + + baton->db->pending++; + baton->db->RemoveCallbacks(); + baton->db->closing = true; + + auto env = baton->db->Env(); + CREATE_WORK("sqlite3.Database.Close", Work_Close, Work_AfterClose); +} + +void Database::Work_Close(napi_env e, void* data) { + auto* baton = static_cast(data); + auto* db = baton->db; + + baton->status = sqlite3_close(db->_handle); + + if (baton->status != SQLITE_OK) { + baton->message = std::string(sqlite3_errmsg(db->_handle)); + } + else { + db->_handle = NULL; + } +} + +void Database::Work_AfterClose(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + + auto* db = baton->db; + + auto env = db->Env(); + Napi::HandleScope scope(env); + + db->pending--; + db->closing = false; + + Napi::Value argv[1]; + if (baton->status != SQLITE_OK) { + EXCEPTION(Napi::String::New(env, baton->message.c_str()), baton->status, exception); + argv[0] = exception; + } + else { + db->open = false; + // Leave db->locked to indicate that this db object has reached + // the end of its life. + argv[0] = env.Null(); + } + + Napi::Function cb = baton->callback.Value(); + + // Fire callbacks. + if (IS_FUNCTION(cb)) { + TRY_CATCH_CALL(db->Value(), cb, 1, argv); + } + else if (db->open) { + Napi::Value info[] = { Napi::String::New(env, "error"), argv[0] }; + EMIT_EVENT(db->Value(), 2, info); + } + + if (!db->open) { + Napi::Value info[] = { Napi::String::New(env, "close") }; + EMIT_EVENT(db->Value(), 1, info); + db->Process(); + } +} + +Napi::Value Database::Serialize(const Napi::CallbackInfo& info) { + auto env = this->Env(); + auto* db = this; + OPTIONAL_ARGUMENT_FUNCTION(0, callback); + + bool before = db->serialize; + db->serialize = true; + + if (!callback.IsEmpty() && callback.IsFunction()) { + TRY_CATCH_CALL(info.This(), callback, 0, NULL, info.This()); + db->serialize = before; + } + + db->Process(); + + return info.This(); +} + +Napi::Value Database::Parallelize(const Napi::CallbackInfo& info) { + auto env = this->Env(); + auto* db = this; + OPTIONAL_ARGUMENT_FUNCTION(0, callback); + + auto before = db->serialize; + db->serialize = false; + + if (!callback.IsEmpty() && callback.IsFunction()) { + TRY_CATCH_CALL(info.This(), callback, 0, NULL, info.This()); + db->serialize = before; + } + + db->Process(); + + return info.This(); +} + +Napi::Value Database::Configure(const Napi::CallbackInfo& info) { + auto env = this->Env(); + auto* db = this; + + REQUIRE_ARGUMENTS(2); + + Napi::Function handle; + if (info[0].StrictEquals( Napi::String::New(env, "trace"))) { + auto* baton = new Baton(db, handle); + db->Schedule(RegisterTraceCallback, baton); + } + else if (info[0].StrictEquals( Napi::String::New(env, "profile"))) { + auto* baton = new Baton(db, handle); + db->Schedule(RegisterProfileCallback, baton); + } + else if (info[0].StrictEquals( Napi::String::New(env, "busyTimeout"))) { + if (!info[1].IsNumber()) { + Napi::TypeError::New(env, "Value must be an integer").ThrowAsJavaScriptException(); + return env.Null(); + } + auto* baton = new Baton(db, handle); + baton->status = info[1].As().Int32Value(); + db->Schedule(SetBusyTimeout, baton); + } + else if (info[0].StrictEquals( Napi::String::New(env, "limit"))) { + REQUIRE_ARGUMENTS(3); + if (!info[1].IsNumber()) { + Napi::TypeError::New(env, "limit id must be an integer").ThrowAsJavaScriptException(); + return env.Null(); + } + if (!info[2].IsNumber()) { + Napi::TypeError::New(env, "limit value must be an integer").ThrowAsJavaScriptException(); + return env.Null(); + } + int id = info[1].As().Int32Value(); + int value = info[2].As().Int32Value(); + Baton* baton = new LimitBaton(db, handle, id, value); + db->Schedule(SetLimit, baton); + } + else if (info[0].StrictEquals(Napi::String::New(env, "change"))) { + auto* baton = new Baton(db, handle); + db->Schedule(RegisterUpdateCallback, baton); + } + else { + Napi::TypeError::New(env, (StringConcat( +#if V8_MAJOR_VERSION > 6 + info.GetIsolate(), +#endif + info[0].As(), + Napi::String::New(env, " is not a valid configuration option") + )).Utf8Value().c_str()).ThrowAsJavaScriptException(); + return env.Null(); + } + + db->Process(); + + return info.This(); +} + +Napi::Value Database::Interrupt(const Napi::CallbackInfo& info) { + auto env = this->Env(); + auto* db = this; + + if (!db->open) { + Napi::Error::New(env, "Database is not open").ThrowAsJavaScriptException(); + return env.Null(); + } + + if (db->closing) { + Napi::Error::New(env, "Database is closing").ThrowAsJavaScriptException(); + return env.Null(); + } + + sqlite3_interrupt(db->_handle); + return info.This(); +} + +void Database::SetBusyTimeout(Baton* b) { + auto baton = std::unique_ptr(b); + + assert(baton->db->open); + assert(baton->db->_handle); + + // Abuse the status field for passing the timeout. + sqlite3_busy_timeout(baton->db->_handle, baton->status); +} + +void Database::SetLimit(Baton* b) { + std::unique_ptr baton(static_cast(b)); + + assert(baton->db->open); + assert(baton->db->_handle); + + sqlite3_limit(baton->db->_handle, baton->id, baton->value); +} + +void Database::RegisterTraceCallback(Baton* b) { + auto baton = std::unique_ptr(b); + assert(baton->db->open); + assert(baton->db->_handle); + auto* db = baton->db; + + if (db->debug_trace == NULL) { + // Add it. + db->debug_trace = new AsyncTrace(db, TraceCallback); + sqlite3_trace(db->_handle, TraceCallback, db); + } + else { + // Remove it. + sqlite3_trace(db->_handle, NULL, NULL); + db->debug_trace->finish(); + db->debug_trace = NULL; + } +} + +void Database::TraceCallback(void* db, const char* sql) { + // Note: This function is called in the thread pool. + // Note: Some queries, such as "EXPLAIN" queries, are not sent through this. + static_cast(db)->debug_trace->send(new std::string(sql)); +} + +void Database::TraceCallback(Database* db, std::string* s) { + std::unique_ptr sql(s); + // Note: This function is called in the main V8 thread. + auto env = db->Env(); + Napi::HandleScope scope(env); + + Napi::Value argv[] = { + Napi::String::New(env, "trace"), + Napi::String::New(env, sql->c_str()) + }; + EMIT_EVENT(db->Value(), 2, argv); +} + +void Database::RegisterProfileCallback(Baton* b) { + auto baton = std::unique_ptr(b); + assert(baton->db->open); + assert(baton->db->_handle); + auto* db = baton->db; + + if (db->debug_profile == NULL) { + // Add it. + db->debug_profile = new AsyncProfile(db, ProfileCallback); + sqlite3_profile(db->_handle, ProfileCallback, db); + } + else { + // Remove it. + sqlite3_profile(db->_handle, NULL, NULL); + db->debug_profile->finish(); + db->debug_profile = NULL; + } +} + +void Database::ProfileCallback(void* db, const char* sql, sqlite3_uint64 nsecs) { + // Note: This function is called in the thread pool. + // Note: Some queries, such as "EXPLAIN" queries, are not sent through this. + auto* info = new ProfileInfo(); + info->sql = std::string(sql); + info->nsecs = nsecs; + static_cast(db)->debug_profile->send(info); +} + +void Database::ProfileCallback(Database *db, ProfileInfo* i) { + auto info = std::unique_ptr(i); + auto env = db->Env(); + Napi::HandleScope scope(env); + + Napi::Value argv[] = { + Napi::String::New(env, "profile"), + Napi::String::New(env, info->sql.c_str()), + Napi::Number::New(env, (double)info->nsecs / 1000000.0) + }; + EMIT_EVENT(db->Value(), 3, argv); +} + +void Database::RegisterUpdateCallback(Baton* b) { + auto baton = std::unique_ptr(b); + assert(baton->db->open); + assert(baton->db->_handle); + auto* db = baton->db; + + if (db->update_event == NULL) { + // Add it. + db->update_event = new AsyncUpdate(db, UpdateCallback); + sqlite3_update_hook(db->_handle, UpdateCallback, db); + } + else { + // Remove it. + sqlite3_update_hook(db->_handle, NULL, NULL); + db->update_event->finish(); + db->update_event = NULL; + } +} + +void Database::UpdateCallback(void* db, int type, const char* database, + const char* table, sqlite3_int64 rowid) { + // Note: This function is called in the thread pool. + // Note: Some queries, such as "EXPLAIN" queries, are not sent through this. + auto* info = new UpdateInfo(); + info->type = type; + info->database = std::string(database); + info->table = std::string(table); + info->rowid = rowid; + static_cast(db)->update_event->send(info); +} + +void Database::UpdateCallback(Database *db, UpdateInfo* i) { + auto info = std::unique_ptr(i); + auto env = db->Env(); + Napi::HandleScope scope(env); + + Napi::Value argv[] = { + Napi::String::New(env, "change"), + Napi::String::New(env, sqlite_authorizer_string(info->type)), + Napi::String::New(env, info->database.c_str()), + Napi::String::New(env, info->table.c_str()), + Napi::Number::New(env, info->rowid), + }; + EMIT_EVENT(db->Value(), 5, argv); +} + +Napi::Value Database::Exec(const Napi::CallbackInfo& info) { + auto env = this->Env(); + auto* db = this; + + REQUIRE_ARGUMENT_STRING(0, sql); + OPTIONAL_ARGUMENT_FUNCTION(1, callback); + + Baton* baton = new ExecBaton(db, callback, sql.c_str()); + db->Schedule(Work_BeginExec, baton, true); + + return info.This(); +} + +void Database::Work_BeginExec(Baton* baton) { + assert(baton->db->locked); + assert(baton->db->open); + assert(baton->db->_handle); + assert(baton->db->pending == 0); + baton->db->pending++; + + auto env = baton->db->Env(); + CREATE_WORK("sqlite3.Database.Exec", Work_Exec, Work_AfterExec); +} + +void Database::Work_Exec(napi_env e, void* data) { + auto* baton = static_cast(data); + + char* message = NULL; + baton->status = sqlite3_exec( + baton->db->_handle, + baton->sql.c_str(), + NULL, + NULL, + &message + ); + + if (baton->status != SQLITE_OK && message != NULL) { + baton->message = std::string(message); + sqlite3_free(message); + } +} + +void Database::Work_AfterExec(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + + auto* db = baton->db; + db->pending--; + + auto env = db->Env(); + Napi::HandleScope scope(env); + + Napi::Function cb = baton->callback.Value(); + + if (baton->status != SQLITE_OK) { + EXCEPTION(Napi::String::New(env, baton->message.c_str()), baton->status, exception); + + if (IS_FUNCTION(cb)) { + Napi::Value argv[] = { exception }; + TRY_CATCH_CALL(db->Value(), cb, 1, argv); + } + else { + Napi::Value info[] = { Napi::String::New(env, "error"), exception }; + EMIT_EVENT(db->Value(), 2, info); + } + } + else if (IS_FUNCTION(cb)) { + Napi::Value argv[] = { env.Null() }; + TRY_CATCH_CALL(db->Value(), cb, 1, argv); + } + + db->Process(); +} + +Napi::Value Database::Wait(const Napi::CallbackInfo& info) { + auto env = info.Env(); + auto* db = this; + + OPTIONAL_ARGUMENT_FUNCTION(0, callback); + + auto* baton = new Baton(db, callback); + db->Schedule(Work_Wait, baton, true); + + return info.This(); +} + +void Database::Work_Wait(Baton* b) { + auto baton = std::unique_ptr(b); + + auto env = baton->db->Env(); + Napi::HandleScope scope(env); + + assert(baton->db->locked); + assert(baton->db->open); + assert(baton->db->_handle); + assert(baton->db->pending == 0); + + Napi::Function cb = baton->callback.Value(); + if (IS_FUNCTION(cb)) { + Napi::Value argv[] = { env.Null() }; + TRY_CATCH_CALL(baton->db->Value(), cb, 1, argv); + } + + baton->db->Process(); +} + +Napi::Value Database::LoadExtension(const Napi::CallbackInfo& info) { + auto env = this->Env(); + auto* db = this; + + REQUIRE_ARGUMENT_STRING(0, filename); + OPTIONAL_ARGUMENT_FUNCTION(1, callback); + + Baton* baton = new LoadExtensionBaton(db, callback, filename.c_str()); + db->Schedule(Work_BeginLoadExtension, baton, true); + + return info.This(); +} + +void Database::Work_BeginLoadExtension(Baton* baton) { + assert(baton->db->locked); + assert(baton->db->open); + assert(baton->db->_handle); + assert(baton->db->pending == 0); + baton->db->pending++; + + auto env = baton->db->Env(); + CREATE_WORK("sqlite3.Database.LoadExtension", Work_LoadExtension, Work_AfterLoadExtension); +} + +void Database::Work_LoadExtension(napi_env e, void* data) { + auto* baton = static_cast(data); + + sqlite3_enable_load_extension(baton->db->_handle, 1); + + char* message = NULL; + baton->status = sqlite3_load_extension( + baton->db->_handle, + baton->filename.c_str(), + 0, + &message + ); + + sqlite3_enable_load_extension(baton->db->_handle, 0); + + if (baton->status != SQLITE_OK && message != NULL) { + baton->message = std::string(message); + sqlite3_free(message); + } +} + +void Database::Work_AfterLoadExtension(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + + auto* db = baton->db; + db->pending--; + + auto env = db->Env(); + Napi::HandleScope scope(env); + + Napi::Function cb = baton->callback.Value(); + + if (baton->status != SQLITE_OK) { + EXCEPTION(Napi::String::New(env, baton->message.c_str()), baton->status, exception); + + if (IS_FUNCTION(cb)) { + Napi::Value argv[] = { exception }; + TRY_CATCH_CALL(db->Value(), cb, 1, argv); + } + else { + Napi::Value info[] = { Napi::String::New(env, "error"), exception }; + EMIT_EVENT(db->Value(), 2, info); + } + } + else if (IS_FUNCTION(cb)) { + Napi::Value argv[] = { env.Null() }; + TRY_CATCH_CALL(db->Value(), cb, 1, argv); + } + + db->Process(); +} + +void Database::RemoveCallbacks() { + if (debug_trace) { + debug_trace->finish(); + debug_trace = NULL; + } + if (debug_profile) { + debug_profile->finish(); + debug_profile = NULL; + } + if (update_event) { + update_event->finish(); + update_event = NULL; + } +} diff --git a/updater/sql/win/src/database.h b/updater/sql/win/src/database.h new file mode 100755 index 0000000..8ffd300 --- /dev/null +++ b/updater/sql/win/src/database.h @@ -0,0 +1,188 @@ + +#ifndef NODE_SQLITE3_SRC_DATABASE_H +#define NODE_SQLITE3_SRC_DATABASE_H + + +#include +#include +#include + +#include +#include + +#include "async.h" + +using namespace Napi; + +namespace node_sqlite3 { + +class Database; + + +class Database : public Napi::ObjectWrap { +public: +#if NAPI_VERSION < 6 + static Napi::FunctionReference constructor; +#endif + static Napi::Object Init(Napi::Env env, Napi::Object exports); + + static inline bool HasInstance(Napi::Value val) { + auto env = val.Env(); + Napi::HandleScope scope(env); + if (!val.IsObject()) return false; + auto obj = val.As(); +#if NAPI_VERSION < 6 + return obj.InstanceOf(constructor.Value()); +#else + auto constructor = + env.GetInstanceData(); + return obj.InstanceOf(constructor->Value()); +#endif + } + + struct Baton { + napi_async_work request = NULL; + Database* db; + Napi::FunctionReference callback; + int status; + std::string message; + + Baton(Database* db_, Napi::Function cb_) : + db(db_), status(SQLITE_OK) { + db->Ref(); + if (!cb_.IsUndefined() && cb_.IsFunction()) { + callback.Reset(cb_, 1); + } + } + virtual ~Baton() { + if (request) napi_delete_async_work(db->Env(), request); + db->Unref(); + callback.Reset(); + } + }; + + struct OpenBaton : Baton { + std::string filename; + int mode; + OpenBaton(Database* db_, Napi::Function cb_, const char* filename_, int mode_) : + Baton(db_, cb_), filename(filename_), mode(mode_) {} + virtual ~OpenBaton() override = default; + }; + + struct ExecBaton : Baton { + std::string sql; + ExecBaton(Database* db_, Napi::Function cb_, const char* sql_) : + Baton(db_, cb_), sql(sql_) {} + virtual ~ExecBaton() override = default; + }; + + struct LoadExtensionBaton : Baton { + std::string filename; + LoadExtensionBaton(Database* db_, Napi::Function cb_, const char* filename_) : + Baton(db_, cb_), filename(filename_) {} + virtual ~LoadExtensionBaton() override = default; + }; + + struct LimitBaton : Baton { + int id; + int value; + LimitBaton(Database* db_, Napi::Function cb_, int id_, int value_) : + Baton(db_, cb_), id(id_), value(value_) {} + virtual ~LimitBaton() override = default; + }; + + typedef void (*Work_Callback)(Baton* baton); + + struct Call { + Call(Work_Callback cb_, Baton* baton_, bool exclusive_ = false) : + callback(cb_), exclusive(exclusive_), baton(baton_) {}; + Work_Callback callback; + bool exclusive; + Baton* baton; + }; + + struct ProfileInfo { + std::string sql; + sqlite3_int64 nsecs; + }; + + struct UpdateInfo { + int type; + std::string database; + std::string table; + sqlite3_int64 rowid; + }; + + bool IsOpen() { return open; } + bool IsLocked() { return locked; } + + typedef Async AsyncTrace; + typedef Async AsyncProfile; + typedef Async AsyncUpdate; + + friend class Statement; + friend class Backup; + + Database(const Napi::CallbackInfo& info); + + ~Database() { + RemoveCallbacks(); + sqlite3_close(_handle); + _handle = NULL; + open = false; + } + +protected: + WORK_DEFINITION(Open); + WORK_DEFINITION(Exec); + WORK_DEFINITION(Close); + WORK_DEFINITION(LoadExtension); + + void Schedule(Work_Callback callback, Baton* baton, bool exclusive = false); + void Process(); + + Napi::Value Wait(const Napi::CallbackInfo& info); + static void Work_Wait(Baton* baton); + + Napi::Value Serialize(const Napi::CallbackInfo& info); + Napi::Value Parallelize(const Napi::CallbackInfo& info); + Napi::Value Configure(const Napi::CallbackInfo& info); + Napi::Value Interrupt(const Napi::CallbackInfo& info); + + static void SetBusyTimeout(Baton* baton); + static void SetLimit(Baton* baton); + + static void RegisterTraceCallback(Baton* baton); + static void TraceCallback(void* db, const char* sql); + static void TraceCallback(Database* db, std::string* sql); + + static void RegisterProfileCallback(Baton* baton); + static void ProfileCallback(void* db, const char* sql, sqlite3_uint64 nsecs); + static void ProfileCallback(Database* db, ProfileInfo* info); + + static void RegisterUpdateCallback(Baton* baton); + static void UpdateCallback(void* db, int type, const char* database, const char* table, sqlite3_int64 rowid); + static void UpdateCallback(Database* db, UpdateInfo* info); + + void RemoveCallbacks(); + +protected: + sqlite3* _handle = NULL; + + bool open = false; + bool closing = false; + bool locked = false; + unsigned int pending = 0; + + bool serialize = false; + + std::queue queue; + + AsyncTrace* debug_trace = NULL; + AsyncProfile* debug_profile = NULL; + AsyncUpdate* update_event = NULL; +}; + +} + +#endif diff --git a/updater/sql/win/src/gcc-preinclude.h b/updater/sql/win/src/gcc-preinclude.h new file mode 100755 index 0000000..7a52a4d --- /dev/null +++ b/updater/sql/win/src/gcc-preinclude.h @@ -0,0 +1,30 @@ +// http://web.archive.org/web/20140401031018/http://rjpower9000.wordpress.com:80/2012/04/09/fun-with-shared-libraries-version-glibc_2-14-not-found/ + +#if defined(__linux__) + +#define _GNU_SOURCE +#include +#undef _GNU_SOURCE + +#if defined(__USE_GNU) + +#if defined(__x86_64__) +__asm__(".symver memcpy,memcpy@GLIBC_2.2.5"); +__asm__(".symver exp,exp@GLIBC_2.2.5"); +__asm__(".symver log,log@GLIBC_2.2.5"); +__asm__(".symver log2,log2@GLIBC_2.2.5"); +__asm__(".symver pow,pow@GLIBC_2.2.5"); +__asm__(".symver fcntl64,fcntl@GLIBC_2.2.5"); +#endif + +#if defined(__aarch64__) || defined(_M_ARM64) +__asm__(".symver memcpy,memcpy@GLIBC_2.17"); +__asm__(".symver exp,exp@GLIBC_2.17"); +__asm__(".symver log,log@GLIBC_2.17"); +__asm__(".symver log2,log2@GLIBC_2.17"); +__asm__(".symver pow,pow@GLIBC_2.17"); +__asm__(".symver fcntl64,fcntl@GLIBC_2.17"); +#endif + +#endif +#endif diff --git a/updater/sql/win/src/macros.h b/updater/sql/win/src/macros.h new file mode 100755 index 0000000..3bcde83 --- /dev/null +++ b/updater/sql/win/src/macros.h @@ -0,0 +1,207 @@ +#ifndef NODE_SQLITE3_SRC_MACROS_H +#define NODE_SQLITE3_SRC_MACROS_H + +const char* sqlite_code_string(int code); +const char* sqlite_authorizer_string(int type); +#include + +// TODO: better way to work around StringConcat? +#include +inline Napi::String StringConcat(Napi::Value str1, Napi::Value str2) { + return Napi::String::New(str1.Env(), str1.As().Utf8Value() + + str2.As().Utf8Value() ); +} + +// A Napi substitute IsInt32() +inline bool OtherIsInt(Napi::Number source) { + double orig_val = source.DoubleValue(); + double int_val = static_cast(source.Int32Value()); + if (orig_val == int_val) { + return true; + } else { + return false; + } +} + +#define IS_FUNCTION(cb) \ + !cb.IsUndefined() && cb.IsFunction() + +#define REQUIRE_ARGUMENTS(n) \ + if (info.Length() < (n)) { \ + Napi::TypeError::New(env, "Expected " #n "arguments").ThrowAsJavaScriptException(); \ + return env.Null(); \ + } + + +#define REQUIRE_ARGUMENT_EXTERNAL(i, var) \ + if (info.Length() <= (i) || !info[i].IsExternal()) { \ + Napi::TypeError::New(env, "Argument " #i " invalid").ThrowAsJavaScriptException(); \ + return env.Null(); \ + } \ + Napi::External var = info[i].As(); + + +#define REQUIRE_ARGUMENT_FUNCTION(i, var) \ + if (info.Length() <= (i) || !info[i].IsFunction()) { \ + Napi::TypeError::New(env, "Argument " #i " must be a function").ThrowAsJavaScriptException(); \ + return env.Null(); \ + } \ + Napi::Function var = info[i].As(); + + +#define REQUIRE_ARGUMENT_STRING(i, var) \ + if (info.Length() <= (i) || !info[i].IsString()) { \ + Napi::TypeError::New(env, "Argument " #i " must be a string").ThrowAsJavaScriptException(); \ + return env.Null(); \ + } \ + std::string var = info[i].As(); + +#define REQUIRE_ARGUMENT_INTEGER(i, var) \ + if (info.Length() <= (i) || !info[i].IsNumber()) { \ + Napi::TypeError::New(env, "Argument " #i " must be an integer").ThrowAsJavaScriptException(); \ + return env.Null(); \ + } \ + int var(info[i].As().Int32Value()); + +#define OPTIONAL_ARGUMENT_FUNCTION(i, var) \ + Napi::Function var; \ + if (info.Length() > i && !info[i].IsUndefined()) { \ + if (!info[i].IsFunction()) { \ + Napi::TypeError::New(env, "Argument " #i " must be a function").ThrowAsJavaScriptException(); \ + return env.Null(); \ + } \ + var = info[i].As(); \ + } + + +#define OPTIONAL_ARGUMENT_INTEGER(i, var, default) \ + int var; \ + if (info.Length() <= (i)) { \ + var = (default); \ + } \ + else if (info[i].IsNumber()) { \ + if (OtherIsInt(info[i].As())) { \ + var = info[i].As().Int32Value(); \ + } \ + } \ + else { \ + Napi::TypeError::New(env, "Argument " #i " must be an integer").ThrowAsJavaScriptException(); \ + return env.Null(); \ + } + + +#define DEFINE_CONSTANT_INTEGER(target, constant, name) \ + Napi::PropertyDescriptor::Value(#name, Napi::Number::New(env, constant), \ + static_cast(napi_enumerable | napi_configurable)), + +#define DEFINE_CONSTANT_STRING(target, constant, name) \ + Napi::PropertyDescriptor::Value(#name, Napi::String::New(env, constant), \ + static_cast(napi_enumerable | napi_configurable)), + +#define EXCEPTION(msg, errno, name) \ + Napi::Value name = Napi::Error::New(env, \ + StringConcat( \ + StringConcat( \ + Napi::String::New(env, sqlite_code_string(errno)), \ + Napi::String::New(env, ": ") \ + ), \ + (msg) \ + ).Utf8Value() \ + ).Value(); \ + Napi::Object name ##_obj = name.As(); \ + (name ##_obj).Set( Napi::String::New(env, "errno"), Napi::Number::New(env, errno)); \ + (name ##_obj).Set( Napi::String::New(env, "code"), \ + Napi::String::New(env, sqlite_code_string(errno))); + + +#define EMIT_EVENT(obj, argc, argv) \ + TRY_CATCH_CALL((obj), \ + (obj).Get("emit").As(),\ + argc, argv \ + ); + +// The Mac OS compiler complains when argv is NULL unless we +// first assign it to a locally defined variable. +#define TRY_CATCH_CALL(context, callback, argc, argv, ...) \ + Napi::Value* passed_argv = argv;\ + std::vector args;\ + if ((argc != 0) && (passed_argv != NULL)) {\ + args.assign(passed_argv, passed_argv + argc);\ + }\ + Napi::Value res = (callback).Call(Napi::Value(context), args); \ + if (res.IsEmpty()) return __VA_ARGS__; + +#define WORK_DEFINITION(name) \ + Napi::Value name(const Napi::CallbackInfo& info); \ + static void Work_Begin##name(Baton* baton); \ + static void Work_##name(napi_env env, void* data); \ + static void Work_After##name(napi_env env, napi_status status, void* data); + +#ifdef DEBUG + #define ASSERT_STATUS() assert(status == 0); +#else + #define ASSERT_STATUS() (void)status; +#endif + +#define CREATE_WORK(name, workerFn, afterFn) \ + int status = napi_create_async_work(env, NULL, Napi::String::New(env, name),\ + workerFn, afterFn, baton, &baton->request); \ + \ + ASSERT_STATUS(); \ + napi_queue_async_work(env, baton->request); + +#define STATEMENT_BEGIN(type) \ + assert(baton); \ + assert(baton->stmt); \ + assert(!baton->stmt->locked); \ + assert(!baton->stmt->finalized); \ + assert(baton->stmt->prepared); \ + baton->stmt->locked = true; \ + baton->stmt->db->pending++; \ + auto env = baton->stmt->Env(); \ + CREATE_WORK("sqlite3.Statement."#type, Work_##type, Work_After##type); + +#define STATEMENT_INIT(type) \ + type* baton = static_cast(data); \ + Statement* stmt = baton->stmt; + +#define STATEMENT_MUTEX(name) \ + if (!stmt->db->_handle) { \ + stmt->status = SQLITE_MISUSE; \ + stmt->message = "Database handle is closed"; \ + return; \ + } \ + sqlite3_mutex* name = sqlite3_db_mutex(stmt->db->_handle); + +#define STATEMENT_END() \ + assert(stmt->locked); \ + assert(stmt->db->pending); \ + stmt->locked = false; \ + stmt->db->pending--; \ + stmt->Process(); \ + stmt->db->Process(); + +#define BACKUP_BEGIN(type) \ + assert(baton); \ + assert(baton->backup); \ + assert(!baton->backup->locked); \ + assert(!baton->backup->finished); \ + assert(baton->backup->inited); \ + baton->backup->locked = true; \ + baton->backup->db->pending++; \ + auto env = baton->backup->Env(); \ + CREATE_WORK("sqlite3.Backup."#type, Work_##type, Work_After##type); + +#define BACKUP_INIT(type) \ + type* baton = static_cast(data); \ + Backup* backup = baton->backup; + +#define BACKUP_END() \ + assert(backup->locked); \ + assert(backup->db->pending); \ + backup->locked = false; \ + backup->db->pending--; \ + backup->Process(); \ + backup->db->Process(); + +#endif \ No newline at end of file diff --git a/updater/sql/win/src/node_sqlite3.cc b/updater/sql/win/src/node_sqlite3.cc new file mode 100755 index 0000000..6f47a68 --- /dev/null +++ b/updater/sql/win/src/node_sqlite3.cc @@ -0,0 +1,128 @@ +#include +#include +#include +#include +#include + +#include "macros.h" +#include "database.h" +#include "statement.h" +#include "backup.h" + +using namespace node_sqlite3; + +namespace { + +Napi::Object RegisterModule(Napi::Env env, Napi::Object exports) { + Napi::HandleScope scope(env); + + Database::Init(env, exports); + Statement::Init(env, exports); + Backup::Init(env, exports); + + exports.DefineProperties({ + DEFINE_CONSTANT_INTEGER(exports, SQLITE_OPEN_READONLY, OPEN_READONLY) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_OPEN_READWRITE, OPEN_READWRITE) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_OPEN_CREATE, OPEN_CREATE) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_OPEN_FULLMUTEX, OPEN_FULLMUTEX) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_OPEN_URI, OPEN_URI) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_OPEN_SHAREDCACHE, OPEN_SHAREDCACHE) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_OPEN_PRIVATECACHE, OPEN_PRIVATECACHE) + DEFINE_CONSTANT_STRING(exports, SQLITE_VERSION, VERSION) +#ifdef SQLITE_SOURCE_ID + DEFINE_CONSTANT_STRING(exports, SQLITE_SOURCE_ID, SOURCE_ID) +#endif + DEFINE_CONSTANT_INTEGER(exports, SQLITE_VERSION_NUMBER, VERSION_NUMBER) + + DEFINE_CONSTANT_INTEGER(exports, SQLITE_OK, OK) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_ERROR, ERROR) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_INTERNAL, INTERNAL) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_PERM, PERM) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_ABORT, ABORT) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_BUSY, BUSY) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LOCKED, LOCKED) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_NOMEM, NOMEM) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_READONLY, READONLY) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_INTERRUPT, INTERRUPT) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_IOERR, IOERR) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_CORRUPT, CORRUPT) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_NOTFOUND, NOTFOUND) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_FULL, FULL) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_CANTOPEN, CANTOPEN) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_PROTOCOL, PROTOCOL) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_EMPTY, EMPTY) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_SCHEMA, SCHEMA) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_TOOBIG, TOOBIG) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_CONSTRAINT, CONSTRAINT) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_MISMATCH, MISMATCH) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_MISUSE, MISUSE) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_NOLFS, NOLFS) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_AUTH, AUTH) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_FORMAT, FORMAT) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_RANGE, RANGE) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_NOTADB, NOTADB) + + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_LENGTH, LIMIT_LENGTH) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_SQL_LENGTH, LIMIT_SQL_LENGTH) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_COLUMN, LIMIT_COLUMN) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_EXPR_DEPTH, LIMIT_EXPR_DEPTH) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_COMPOUND_SELECT, LIMIT_COMPOUND_SELECT) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_VDBE_OP, LIMIT_VDBE_OP) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_FUNCTION_ARG, LIMIT_FUNCTION_ARG) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_ATTACHED, LIMIT_ATTACHED) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_LIKE_PATTERN_LENGTH, LIMIT_LIKE_PATTERN_LENGTH) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_VARIABLE_NUMBER, LIMIT_VARIABLE_NUMBER) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_TRIGGER_DEPTH, LIMIT_TRIGGER_DEPTH) + DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_WORKER_THREADS, LIMIT_WORKER_THREADS) + }); + + return exports; +} + +} + +const char* sqlite_code_string(int code) { + switch (code) { + case SQLITE_OK: return "SQLITE_OK"; + case SQLITE_ERROR: return "SQLITE_ERROR"; + case SQLITE_INTERNAL: return "SQLITE_INTERNAL"; + case SQLITE_PERM: return "SQLITE_PERM"; + case SQLITE_ABORT: return "SQLITE_ABORT"; + case SQLITE_BUSY: return "SQLITE_BUSY"; + case SQLITE_LOCKED: return "SQLITE_LOCKED"; + case SQLITE_NOMEM: return "SQLITE_NOMEM"; + case SQLITE_READONLY: return "SQLITE_READONLY"; + case SQLITE_INTERRUPT: return "SQLITE_INTERRUPT"; + case SQLITE_IOERR: return "SQLITE_IOERR"; + case SQLITE_CORRUPT: return "SQLITE_CORRUPT"; + case SQLITE_NOTFOUND: return "SQLITE_NOTFOUND"; + case SQLITE_FULL: return "SQLITE_FULL"; + case SQLITE_CANTOPEN: return "SQLITE_CANTOPEN"; + case SQLITE_PROTOCOL: return "SQLITE_PROTOCOL"; + case SQLITE_EMPTY: return "SQLITE_EMPTY"; + case SQLITE_SCHEMA: return "SQLITE_SCHEMA"; + case SQLITE_TOOBIG: return "SQLITE_TOOBIG"; + case SQLITE_CONSTRAINT: return "SQLITE_CONSTRAINT"; + case SQLITE_MISMATCH: return "SQLITE_MISMATCH"; + case SQLITE_MISUSE: return "SQLITE_MISUSE"; + case SQLITE_NOLFS: return "SQLITE_NOLFS"; + case SQLITE_AUTH: return "SQLITE_AUTH"; + case SQLITE_FORMAT: return "SQLITE_FORMAT"; + case SQLITE_RANGE: return "SQLITE_RANGE"; + case SQLITE_NOTADB: return "SQLITE_NOTADB"; + case SQLITE_ROW: return "SQLITE_ROW"; + case SQLITE_DONE: return "SQLITE_DONE"; + default: return "UNKNOWN"; + } +} + +const char* sqlite_authorizer_string(int type) { + switch (type) { + case SQLITE_INSERT: return "insert"; + case SQLITE_UPDATE: return "update"; + case SQLITE_DELETE: return "delete"; + default: return ""; + } +} + +NODE_API_MODULE(node_sqlite3, RegisterModule) diff --git a/updater/sql/win/src/statement.cc b/updater/sql/win/src/statement.cc new file mode 100755 index 0000000..fc49b90 --- /dev/null +++ b/updater/sql/win/src/statement.cc @@ -0,0 +1,939 @@ +#include +#include +#include + +#include "macros.h" +#include "database.h" +#include "statement.h" + +using namespace node_sqlite3; + +Napi::Object Statement::Init(Napi::Env env, Napi::Object exports) { + Napi::HandleScope scope(env); + + // declare napi_default_method here as it is only available in Node v14.12.0+ + auto napi_default_method = static_cast(napi_writable | napi_configurable); + + auto t = DefineClass(env, "Statement", { + InstanceMethod("bind", &Statement::Bind, napi_default_method), + InstanceMethod("get", &Statement::Get, napi_default_method), + InstanceMethod("run", &Statement::Run, napi_default_method), + InstanceMethod("all", &Statement::All, napi_default_method), + InstanceMethod("each", &Statement::Each, napi_default_method), + InstanceMethod("reset", &Statement::Reset, napi_default_method), + InstanceMethod("finalize", &Statement::Finalize_, napi_default_method), + }); + + exports.Set("Statement", t); + return exports; +} + +// A Napi InstanceOf for Javascript Objects "Date" and "RegExp" +bool OtherInstanceOf(Napi::Object source, const char* object_type) { + if (strncmp(object_type, "Date", 4) == 0) { + return source.InstanceOf(source.Env().Global().Get("Date").As()); + } else if (strncmp(object_type, "RegExp", 6) == 0) { + return source.InstanceOf(source.Env().Global().Get("RegExp").As()); + } + + return false; +} + +void Statement::Process() { + if (finalized && !queue.empty()) { + return CleanQueue(); + } + + while (prepared && !locked && !queue.empty()) { + auto call = std::unique_ptr(queue.front()); + queue.pop(); + + call->callback(call->baton); + } +} + +void Statement::Schedule(Work_Callback callback, Baton* baton) { + if (finalized) { + queue.emplace(new Call(callback, baton)); + CleanQueue(); + } + else if (!prepared || locked) { + queue.emplace(new Call(callback, baton)); + } + else { + callback(baton); + } +} + +template void Statement::Error(T* baton) { + Statement* stmt = baton->stmt; + + auto env = stmt->Env(); + Napi::HandleScope scope(env); + + // Fail hard on logic errors. + assert(stmt->status != 0); + EXCEPTION(Napi::String::New(env, stmt->message.c_str()), stmt->status, exception); + + Napi::Function cb = baton->callback.Value(); + + if (IS_FUNCTION(cb)) { + Napi::Value argv[] = { exception }; + TRY_CATCH_CALL(stmt->Value(), cb, 1, argv); + } + else { + Napi::Value argv[] = { Napi::String::New(env, "error"), exception }; + EMIT_EVENT(stmt->Value(), 2, argv); + } +} + +// { Database db, String sql, Array params, Function callback } +Statement::Statement(const Napi::CallbackInfo& info) : Napi::ObjectWrap(info) { + auto env = info.Env(); + int length = info.Length(); + + if (length <= 0 || !Database::HasInstance(info[0])) { + Napi::TypeError::New(env, "Database object expected").ThrowAsJavaScriptException(); + return; + } + else if (length <= 1 || !info[1].IsString()) { + Napi::TypeError::New(env, "SQL query expected").ThrowAsJavaScriptException(); + return; + } + else if (length > 2 && !info[2].IsUndefined() && !info[2].IsFunction()) { + Napi::TypeError::New(env, "Callback expected").ThrowAsJavaScriptException(); + return; + } + + this->db = Napi::ObjectWrap::Unwrap(info[0].As()); + this->db->Ref(); + + auto sql = info[1].As(); + + info.This().As().DefineProperty(Napi::PropertyDescriptor::Value("sql", sql, napi_default)); + + + Statement* stmt = this; + + auto* baton = new PrepareBaton(this->db, info[2].As(), stmt); + baton->sql = std::string(sql.As().Utf8Value().c_str()); + this->db->Schedule(Work_BeginPrepare, baton); +} + +void Statement::Work_BeginPrepare(Database::Baton* baton) { + assert(baton->db->open); + baton->db->pending++; + + auto env = baton->db->Env(); + CREATE_WORK("sqlite3.Statement.Prepare", Work_Prepare, Work_AfterPrepare); +} + +void Statement::Work_Prepare(napi_env e, void* data) { + STATEMENT_INIT(PrepareBaton); + + // In case preparing fails, we use a mutex to make sure we get the associated + // error message. + STATEMENT_MUTEX(mtx); + sqlite3_mutex_enter(mtx); + + stmt->status = sqlite3_prepare_v2( + baton->db->_handle, + baton->sql.c_str(), + baton->sql.size(), + &stmt->_handle, + NULL + ); + + if (stmt->status != SQLITE_OK) { + stmt->message = std::string(sqlite3_errmsg(baton->db->_handle)); + stmt->_handle = NULL; + } + + sqlite3_mutex_leave(mtx); +} + +void Statement::Work_AfterPrepare(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + auto* stmt = baton->stmt; + + auto env = stmt->Env(); + Napi::HandleScope scope(env); + + if (stmt->status != SQLITE_OK) { + Error(baton.get()); + stmt->Finalize_(); + } + else { + stmt->prepared = true; + if (!baton->callback.IsEmpty() && baton->callback.Value().IsFunction()) { + Napi::Function cb = baton->callback.Value(); + Napi::Value argv[] = { env.Null() }; + TRY_CATCH_CALL(stmt->Value(), cb, 1, argv); + } + } + + STATEMENT_END(); +} + +template std::unique_ptr + Statement::BindParameter(const Napi::Value source, T pos) { + if (source.IsString()) { + std::string val = source.As().Utf8Value(); + return std::make_unique(pos, val.length(), val.c_str()); + } + else if (OtherInstanceOf(source.As(), "RegExp")) { + std::string val = source.ToString().Utf8Value(); + return std::make_unique(pos, val.length(), val.c_str()); + } + else if (source.IsNumber()) { + if (OtherIsInt(source.As())) { + return std::make_unique(pos, source.As().Int32Value()); + } else { + return std::make_unique(pos, source.As().DoubleValue()); + } + } + else if (source.IsBoolean()) { + return std::make_unique(pos, source.As().Value() ? 1 : 0); + } + else if (source.IsNull()) { + return std::make_unique(pos); + } + else if (source.IsBuffer()) { + Napi::Buffer buffer = source.As>(); + return std::make_unique(pos, buffer.Length(), buffer.Data()); + } + else if (OtherInstanceOf(source.As(), "Date")) { + return std::make_unique(pos, source.ToNumber().DoubleValue()); + } + else if (source.IsObject()) { + auto napiVal = Napi::String::New(source.Env(), "[object Object]"); + // Check whether toString returned a value that is not undefined. + if(napiVal.Type() == 0) { + return NULL; + } + + std::string val = napiVal.Utf8Value(); + return std::make_unique(pos, val.length(), val.c_str()); + } + else { + return NULL; + } +} + +template T* Statement::Bind(const Napi::CallbackInfo& info, int start, int last) { + auto env = info.Env(); + Napi::HandleScope scope(env); + + if (last < 0) last = info.Length(); + Napi::Function callback; + if (last > start && info[last - 1].IsFunction()) { + callback = info[last - 1].As(); + last--; + } + + auto *baton = new T(this, callback); + + if (start < last) { + if (info[start].IsArray()) { + auto array = info[start].As(); + int length = array.Length(); + // Note: bind parameters start with 1. + for (int i = 0, pos = 1; i < length; i++, pos++) { + baton->parameters.emplace_back(BindParameter((array).Get(i), i + 1)); + } + } + else if (!info[start].IsObject() || OtherInstanceOf(info[start].As(), "RegExp") + || OtherInstanceOf(info[start].As(), "Date") || info[start].IsBuffer()) { + // Parameters directly in array. + // Note: bind parameters start with 1. + for (int i = start, pos = 1; i < last; i++, pos++) { + baton->parameters.emplace_back(BindParameter(info[i], pos)); + } + } + else if (info[start].IsObject()) { + auto object = info[start].As(); + auto array = object.GetPropertyNames(); + int length = array.Length(); + for (int i = 0; i < length; i++) { + Napi::Value name = (array).Get(i); + Napi::Number num = name.ToNumber(); + + if (num.Int32Value() == num.DoubleValue()) { + baton->parameters.emplace_back( + BindParameter((object).Get(name), num.Int32Value())); + } + else { + baton->parameters.emplace_back(BindParameter((object).Get(name), + name.As().Utf8Value().c_str())); + } + } + } + else { + return NULL; + } + } + + return baton; +} + +bool Statement::Bind(const Parameters & parameters) { + if (parameters.empty()) { + return true; + } + + sqlite3_reset(_handle); + sqlite3_clear_bindings(_handle); + + for (auto& field : parameters) { + if (field == NULL) + continue; + + unsigned int pos; + if (field->index > 0) { + pos = field->index; + } + else { + pos = sqlite3_bind_parameter_index(_handle, field->name.c_str()); + } + + switch (field->type) { + case SQLITE_INTEGER: { + status = sqlite3_bind_int(_handle, pos, + (static_cast(field.get()))->value); + } break; + case SQLITE_FLOAT: { + status = sqlite3_bind_double(_handle, pos, + (static_cast(field.get()))->value); + } break; + case SQLITE_TEXT: { + status = sqlite3_bind_text(_handle, pos, + (static_cast(field.get()))->value.c_str(), + (static_cast(field.get()))->value.size(), SQLITE_TRANSIENT); + } break; + case SQLITE_BLOB: { + status = sqlite3_bind_blob(_handle, pos, + (static_cast(field.get()))->value, + (static_cast(field.get()))->length, SQLITE_TRANSIENT); + } break; + case SQLITE_NULL: { + status = sqlite3_bind_null(_handle, pos); + } break; + } + + if (status != SQLITE_OK) { + message = std::string(sqlite3_errmsg(db->_handle)); + return false; + } + } + + return true; +} + +Napi::Value Statement::Bind(const Napi::CallbackInfo& info) { + auto env = info.Env(); + Statement* stmt = this; + + auto baton = stmt->Bind(info); + if (baton == NULL) { + Napi::TypeError::New(env, "Data type is not supported").ThrowAsJavaScriptException(); + return env.Null(); + } + else { + stmt->Schedule(Work_BeginBind, baton); + return info.This(); + } +} + +void Statement::Work_BeginBind(Baton* baton) { + STATEMENT_BEGIN(Bind); +} + +void Statement::Work_Bind(napi_env e, void* data) { + STATEMENT_INIT(Baton); + + STATEMENT_MUTEX(mtx); + sqlite3_mutex_enter(mtx); + stmt->Bind(baton->parameters); + sqlite3_mutex_leave(mtx); +} + +void Statement::Work_AfterBind(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + auto* stmt = baton->stmt; + + auto env = stmt->Env(); + Napi::HandleScope scope(env); + + if (stmt->status != SQLITE_OK) { + Error(baton.get()); + } + else { + // Fire callbacks. + Napi::Function cb = baton->callback.Value(); + if (IS_FUNCTION(cb)) { + Napi::Value argv[] = { env.Null() }; + TRY_CATCH_CALL(stmt->Value(), cb, 1, argv); + } + } + + STATEMENT_END(); +} + + + +Napi::Value Statement::Get(const Napi::CallbackInfo& info) { + auto env = info.Env(); + Statement* stmt = this; + + Baton* baton = stmt->Bind(info); + if (baton == NULL) { + Napi::Error::New(env, "Data type is not supported").ThrowAsJavaScriptException(); + return env.Null(); + } + else { + stmt->Schedule(Work_BeginGet, baton); + return info.This(); + } +} + +void Statement::Work_BeginGet(Baton* baton) { + STATEMENT_BEGIN(Get); +} + +void Statement::Work_Get(napi_env e, void* data) { + STATEMENT_INIT(RowBaton); + + if (stmt->status != SQLITE_DONE || baton->parameters.size()) { + STATEMENT_MUTEX(mtx); + sqlite3_mutex_enter(mtx); + + if (stmt->Bind(baton->parameters)) { + stmt->status = sqlite3_step(stmt->_handle); + + if (!(stmt->status == SQLITE_ROW || stmt->status == SQLITE_DONE)) { + stmt->message = std::string(sqlite3_errmsg(stmt->db->_handle)); + } + } + + sqlite3_mutex_leave(mtx); + + if (stmt->status == SQLITE_ROW) { + // Acquire one result row before returning. + GetRow(&baton->row, stmt->_handle); + } + } +} + +void Statement::Work_AfterGet(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + auto* stmt = baton->stmt; + + auto env = stmt->Env(); + Napi::HandleScope scope(env); + + if (stmt->status != SQLITE_ROW && stmt->status != SQLITE_DONE) { + Error(baton.get()); + } + else { + // Fire callbacks. + Napi::Function cb = baton->callback.Value(); + if (IS_FUNCTION(cb)) { + if (stmt->status == SQLITE_ROW) { + // Create the result array from the data we acquired. + Napi::Value argv[] = { env.Null(), RowToJS(env, &baton->row) }; + TRY_CATCH_CALL(stmt->Value(), cb, 2, argv); + } + else { + Napi::Value argv[] = { env.Null() }; + TRY_CATCH_CALL(stmt->Value(), cb, 1, argv); + } + } + } + + STATEMENT_END(); +} + +Napi::Value Statement::Run(const Napi::CallbackInfo& info) { + auto env = info.Env(); + Statement* stmt = this; + + Baton* baton = stmt->Bind(info); + if (baton == NULL) { + Napi::Error::New(env, "Data type is not supported").ThrowAsJavaScriptException(); + return env.Null(); + } + else { + stmt->Schedule(Work_BeginRun, baton); + return info.This(); + } +} + +void Statement::Work_BeginRun(Baton* baton) { + STATEMENT_BEGIN(Run); +} + +void Statement::Work_Run(napi_env e, void* data) { + STATEMENT_INIT(RunBaton); + + STATEMENT_MUTEX(mtx); + sqlite3_mutex_enter(mtx); + + // Make sure that we also reset when there are no parameters. + if (!baton->parameters.size()) { + sqlite3_reset(stmt->_handle); + } + + if (stmt->Bind(baton->parameters)) { + stmt->status = sqlite3_step(stmt->_handle); + + if (!(stmt->status == SQLITE_ROW || stmt->status == SQLITE_DONE)) { + stmt->message = std::string(sqlite3_errmsg(stmt->db->_handle)); + } + else { + baton->inserted_id = sqlite3_last_insert_rowid(stmt->db->_handle); + baton->changes = sqlite3_changes(stmt->db->_handle); + } + } + + sqlite3_mutex_leave(mtx); +} + +void Statement::Work_AfterRun(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + auto* stmt = baton->stmt; + + auto env = stmt->Env(); + Napi::HandleScope scope(env); + + if (stmt->status != SQLITE_ROW && stmt->status != SQLITE_DONE) { + Error(baton.get()); + } + else { + // Fire callbacks. + Napi::Function cb = baton->callback.Value(); + if (IS_FUNCTION(cb)) { + (stmt->Value()).Set(Napi::String::New(env, "lastID"), Napi::Number::New(env, baton->inserted_id)); + (stmt->Value()).Set( Napi::String::New(env, "changes"), Napi::Number::New(env, baton->changes)); + + Napi::Value argv[] = { env.Null() }; + TRY_CATCH_CALL(stmt->Value(), cb, 1, argv); + } + } + + STATEMENT_END(); +} + +Napi::Value Statement::All(const Napi::CallbackInfo& info) { + auto env = info.Env(); + Statement* stmt = this; + + Baton* baton = stmt->Bind(info); + if (baton == NULL) { + Napi::Error::New(env, "Data type is not supported").ThrowAsJavaScriptException(); + return env.Null(); + } + else { + stmt->Schedule(Work_BeginAll, baton); + return info.This(); + } +} + +void Statement::Work_BeginAll(Baton* baton) { + STATEMENT_BEGIN(All); +} + +void Statement::Work_All(napi_env e, void* data) { + STATEMENT_INIT(RowsBaton); + + STATEMENT_MUTEX(mtx); + sqlite3_mutex_enter(mtx); + + // Make sure that we also reset when there are no parameters. + if (!baton->parameters.size()) { + sqlite3_reset(stmt->_handle); + } + + if (stmt->Bind(baton->parameters)) { + while ((stmt->status = sqlite3_step(stmt->_handle)) == SQLITE_ROW) { + auto row = std::make_unique(); + GetRow(row.get(), stmt->_handle); + baton->rows.emplace_back(std::move(row)); + } + + if (stmt->status != SQLITE_DONE) { + stmt->message = std::string(sqlite3_errmsg(stmt->db->_handle)); + } + } + + sqlite3_mutex_leave(mtx); +} + +void Statement::Work_AfterAll(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + auto* stmt = baton->stmt; + + auto env = stmt->Env(); + Napi::HandleScope scope(env); + + if (stmt->status != SQLITE_DONE) { + Error(baton.get()); + } + else { + // Fire callbacks. + Napi::Function cb = baton->callback.Value(); + if (IS_FUNCTION(cb)) { + if (baton->rows.size()) { + // Create the result array from the data we acquired. + Napi::Array result(Napi::Array::New(env, baton->rows.size())); + auto it = static_cast(baton->rows.begin()); + decltype(it) end = baton->rows.end(); + for (int i = 0; it < end; ++it, i++) { + (result).Set(i, RowToJS(env, it->get())); + } + + Napi::Value argv[] = { env.Null(), result }; + TRY_CATCH_CALL(stmt->Value(), cb, 2, argv); + } + else { + // There were no result rows. + Napi::Value argv[] = { + env.Null(), + Napi::Array::New(env, 0) + }; + TRY_CATCH_CALL(stmt->Value(), cb, 2, argv); + } + } + } + + STATEMENT_END(); +} + +Napi::Value Statement::Each(const Napi::CallbackInfo& info) { + auto env = info.Env(); + Statement* stmt = this; + + int last = info.Length(); + + Napi::Function completed; + if (last >= 2 && info[last - 1].IsFunction() && info[last - 2].IsFunction()) { + completed = info[--last].As(); + } + + auto baton = stmt->Bind(info, 0, last); + if (baton == NULL) { + Napi::Error::New(env, "Data type is not supported").ThrowAsJavaScriptException(); + return env.Null(); + } + else { + baton->completed.Reset(completed, 1); + stmt->Schedule(Work_BeginEach, baton); + return info.This(); + } +} + +void Statement::Work_BeginEach(Baton* baton) { + // Only create the Async object when we're actually going into + // the event loop. This prevents dangling events. + auto* each_baton = static_cast(baton); + each_baton->async = new Async(each_baton->stmt, reinterpret_cast(AsyncEach)); + each_baton->async->item_cb.Reset(each_baton->callback.Value(), 1); + each_baton->async->completed_cb.Reset(each_baton->completed.Value(), 1); + + STATEMENT_BEGIN(Each); +} + +void Statement::Work_Each(napi_env e, void* data) { + STATEMENT_INIT(EachBaton); + + auto* async = baton->async; + + STATEMENT_MUTEX(mtx); + + // Make sure that we also reset when there are no parameters. + if (!baton->parameters.size()) { + sqlite3_reset(stmt->_handle); + } + + if (stmt->Bind(baton->parameters)) { + while (true) { + sqlite3_mutex_enter(mtx); + stmt->status = sqlite3_step(stmt->_handle); + if (stmt->status == SQLITE_ROW) { + sqlite3_mutex_leave(mtx); + auto row = std::make_unique(); + GetRow(row.get(), stmt->_handle); + NODE_SQLITE3_MUTEX_LOCK(&async->mutex) + async->data.emplace_back(std::move(row)); + NODE_SQLITE3_MUTEX_UNLOCK(&async->mutex) + + uv_async_send(&async->watcher); + } + else { + if (stmt->status != SQLITE_DONE) { + stmt->message = std::string(sqlite3_errmsg(stmt->db->_handle)); + } + sqlite3_mutex_leave(mtx); + break; + } + } + } + + async->completed = true; + uv_async_send(&async->watcher); +} + +void Statement::CloseCallback(uv_handle_t* handle) { + assert(handle != NULL); + assert(handle->data != NULL); + auto* async = static_cast(handle->data); + delete async; +} + +void Statement::AsyncEach(uv_async_t* handle) { + auto* async = static_cast(handle->data); + + auto env = async->stmt->Env(); + Napi::HandleScope scope(env); + + while (true) { + // Get the contents out of the data cache for us to process in the JS callback. + Rows rows; + NODE_SQLITE3_MUTEX_LOCK(&async->mutex) + rows.swap(async->data); + NODE_SQLITE3_MUTEX_UNLOCK(&async->mutex) + + if (rows.empty()) { + break; + } + + Napi::Function cb = async->item_cb.Value(); + if (IS_FUNCTION(cb)) { + Napi::Value argv[2]; + argv[0] = env.Null(); + + for(auto& row : rows) { + argv[1] = RowToJS(env,row.get()); + async->retrieved++; + TRY_CATCH_CALL(async->stmt->Value(), cb, 2, argv); + } + } + } + + Napi::Function cb = async->completed_cb.Value(); + if (async->completed) { + if (!cb.IsEmpty() && + cb.IsFunction()) { + Napi::Value argv[] = { + env.Null(), + Napi::Number::New(env, async->retrieved) + }; + TRY_CATCH_CALL(async->stmt->Value(), cb, 2, argv); + } + uv_close(reinterpret_cast(handle), CloseCallback); + } +} + +void Statement::Work_AfterEach(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + auto* stmt = baton->stmt; + + auto env = stmt->Env(); + Napi::HandleScope scope(env); + + if (stmt->status != SQLITE_DONE) { + Error(baton.get()); + } + + STATEMENT_END(); +} + +Napi::Value Statement::Reset(const Napi::CallbackInfo& info) { + auto env = info.Env(); + Statement* stmt = this; + + OPTIONAL_ARGUMENT_FUNCTION(0, callback); + + auto* baton = new Baton(stmt, callback); + stmt->Schedule(Work_BeginReset, baton); + + return info.This(); +} + +void Statement::Work_BeginReset(Baton* baton) { + STATEMENT_BEGIN(Reset); +} + +void Statement::Work_Reset(napi_env e, void* data) { + STATEMENT_INIT(Baton); + + sqlite3_reset(stmt->_handle); + stmt->status = SQLITE_OK; +} + +void Statement::Work_AfterReset(napi_env e, napi_status status, void* data) { + std::unique_ptr baton(static_cast(data)); + auto* stmt = baton->stmt; + + auto env = stmt->Env(); + Napi::HandleScope scope(env); + + // Fire callbacks. + Napi::Function cb = baton->callback.Value(); + if (IS_FUNCTION(cb)) { + Napi::Value argv[] = { env.Null() }; + TRY_CATCH_CALL(stmt->Value(), cb, 1, argv); + } + + STATEMENT_END(); +} + +Napi::Value Statement::RowToJS(Napi::Env env, Row* row) { + Napi::EscapableHandleScope scope(env); + + auto result = Napi::Object::New(env); + + for (auto& field : *row) { + + Napi::Value value; + + switch (field->type) { + case SQLITE_INTEGER: { + value = Napi::Number::New(env, (static_cast(field.get()))->value); + } break; + case SQLITE_FLOAT: { + value = Napi::Number::New(env, (static_cast(field.get()))->value); + } break; + case SQLITE_TEXT: { + value = Napi::String::New(env, (static_cast(field.get()))->value.c_str(), + (static_cast(field.get()))->value.size()); + } break; + case SQLITE_BLOB: { + value = Napi::Buffer::Copy(env, (static_cast(field.get()))->value, + (static_cast(field.get()))->length); + } break; + case SQLITE_NULL: { + value = env.Null(); + } break; + } + + result.Set(field->name, value); + } + + return scope.Escape(result); +} + +void Statement::GetRow(Row* row, sqlite3_stmt* stmt) { + int cols = sqlite3_column_count(stmt); + + for (int i = 0; i < cols; i++) { + int type = sqlite3_column_type(stmt, i); + const char* name = sqlite3_column_name(stmt, i); + if (name == NULL) { + assert(false); + } + + switch (type) { + case SQLITE_INTEGER: { + row->emplace_back(std::make_unique(name, sqlite3_column_int64(stmt, i))); + } break; + case SQLITE_FLOAT: { + row->emplace_back(std::make_unique(name, sqlite3_column_double(stmt, i))); + } break; + case SQLITE_TEXT: { + const char* text = (const char*)sqlite3_column_text(stmt, i); + int length = sqlite3_column_bytes(stmt, i); + row->emplace_back(std::make_unique(name, length, text)); + } break; + case SQLITE_BLOB: { + const void* blob = sqlite3_column_blob(stmt, i); + int length = sqlite3_column_bytes(stmt, i); + row->emplace_back(std::make_unique(name, length, blob)); + } break; + case SQLITE_NULL: { + row->emplace_back(std::make_unique(name)); + } break; + default: + assert(false); + } + } +} + +Napi::Value Statement::Finalize_(const Napi::CallbackInfo& info) { + auto env = info.Env(); + Statement* stmt = this; + OPTIONAL_ARGUMENT_FUNCTION(0, callback); + + auto *baton = new Baton(stmt, callback); + stmt->Schedule(Finalize_, baton); + + return stmt->db->Value(); +} + +void Statement::Finalize_(Baton* b) { + auto baton = std::unique_ptr(b); + auto env = baton->stmt->Env(); + Napi::HandleScope scope(env); + + baton->stmt->Finalize_(); + + // Fire callback in case there was one. + Napi::Function cb = baton->callback.Value(); + if (IS_FUNCTION(cb)) { + TRY_CATCH_CALL(baton->stmt->Value(), cb, 0, NULL); + } +} + +void Statement::Finalize_() { + assert(!finalized); + finalized = true; + CleanQueue(); + // Finalize returns the status code of the last operation. We already fired + // error events in case those failed. + sqlite3_finalize(_handle); + _handle = NULL; + db->Unref(); +} + +void Statement::CleanQueue() { + auto env = this->Env(); + Napi::HandleScope scope(env); + + if (prepared && !queue.empty()) { + // This statement has already been prepared and is now finalized. + // Fire error for all remaining items in the queue. + EXCEPTION(Napi::String::New(env, "Statement is already finalized"), SQLITE_MISUSE, exception); + Napi::Value argv[] = { exception }; + bool called = false; + + // Clear out the queue so that this object can get GC'ed. + while (!queue.empty()) { + auto call = std::unique_ptr(queue.front()); + queue.pop(); + + auto baton = std::unique_ptr(call->baton); + Napi::Function cb = baton->callback.Value(); + + if (prepared && !cb.IsEmpty() && + cb.IsFunction()) { + TRY_CATCH_CALL(Value(), cb, 1, argv); + called = true; + } + } + + // When we couldn't call a callback function, emit an error on the + // Statement object. + if (!called) { + Napi::Value info[] = { Napi::String::New(env, "error"), exception }; + EMIT_EVENT(Value(), 2, info); + } + } + else while (!queue.empty()) { + // Just delete all items in the queue; we already fired an event when + // preparing the statement failed. + auto call = std::unique_ptr(queue.front()); + queue.pop(); + // We don't call the actual callback, so we have to make sure that + // the baton gets destroyed. + delete call->baton; + } +} diff --git a/updater/sql/win/src/statement.h b/updater/sql/win/src/statement.h new file mode 100755 index 0000000..c522c0f --- /dev/null +++ b/updater/sql/win/src/statement.h @@ -0,0 +1,244 @@ +#ifndef NODE_SQLITE3_SRC_STATEMENT_H +#define NODE_SQLITE3_SRC_STATEMENT_H + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "database.h" +#include "threading.h" + +using namespace Napi; + +namespace node_sqlite3 { + +namespace Values { + struct Field { + inline Field(unsigned short _index, unsigned short _type = SQLITE_NULL) : + type(_type), index(_index) {} + inline Field(const char* _name, unsigned short _type = SQLITE_NULL) : + type(_type), index(0), name(_name) {} + + unsigned short type; + unsigned short index; + std::string name; + + virtual ~Field() = default; + }; + + struct Integer : Field { + template inline Integer(T _name, int64_t val) : + Field(_name, SQLITE_INTEGER), value(val) {} + int64_t value; + virtual ~Integer() override = default; + }; + + struct Float : Field { + template inline Float(T _name, double val) : + Field(_name, SQLITE_FLOAT), value(val) {} + double value; + virtual ~Float() override = default; + }; + + struct Text : Field { + template inline Text(T _name, size_t len, const char* val) : + Field(_name, SQLITE_TEXT), value(val, len) {} + std::string value; + virtual ~Text() override = default; + }; + + struct Blob : Field { + template inline Blob(T _name, size_t len, const void* val) : + Field(_name, SQLITE_BLOB), length(len) { + value = new char[len]; + assert(value != nullptr); + memcpy(value, val, len); + } + inline virtual ~Blob() override { + delete[] value; + } + int length; + char* value; + }; + + typedef Field Null; +} + +typedef std::vector > Row; +typedef std::vector > Rows; +typedef Row Parameters; + + + +class Statement : public Napi::ObjectWrap { +public: + static Napi::Object Init(Napi::Env env, Napi::Object exports); + static Napi::Value New(const Napi::CallbackInfo& info); + + struct Baton { + napi_async_work request = NULL; + Statement* stmt; + Napi::FunctionReference callback; + Parameters parameters; + + Baton(Statement* stmt_, Napi::Function cb_) : stmt(stmt_) { + stmt->Ref(); + callback.Reset(cb_, 1); + } + virtual ~Baton() { + parameters.clear(); + if (request) napi_delete_async_work(stmt->Env(), request); + stmt->Unref(); + callback.Reset(); + } + }; + + struct RowBaton : Baton { + RowBaton(Statement* stmt_, Napi::Function cb_) : + Baton(stmt_, cb_) {} + Row row; + virtual ~RowBaton() override = default; + }; + + struct RunBaton : Baton { + RunBaton(Statement* stmt_, Napi::Function cb_) : + Baton(stmt_, cb_), inserted_id(0), changes(0) {} + sqlite3_int64 inserted_id; + int changes; + virtual ~RunBaton() override = default; + }; + + struct RowsBaton : Baton { + RowsBaton(Statement* stmt_, Napi::Function cb_) : + Baton(stmt_, cb_) {} + Rows rows; + virtual ~RowsBaton() override = default; + }; + + struct Async; + + struct EachBaton : Baton { + Napi::FunctionReference completed; + Async* async; // Isn't deleted when the baton is deleted. + + EachBaton(Statement* stmt_, Napi::Function cb_) : + Baton(stmt_, cb_) {} + virtual ~EachBaton() override { + completed.Reset(); + } + }; + + struct PrepareBaton : Database::Baton { + Statement* stmt; + std::string sql; + PrepareBaton(Database* db_, Napi::Function cb_, Statement* stmt_) : + Baton(db_, cb_), stmt(stmt_) { + stmt->Ref(); + } + virtual ~PrepareBaton() override { + stmt->Unref(); + if (!db->IsOpen() && db->IsLocked()) { + // The database handle was closed before the statement could be + // prepared. + stmt->Finalize_(); + } + } + }; + + typedef void (*Work_Callback)(Baton* baton); + + struct Call { + Call(Work_Callback cb_, Baton* baton_) : callback(cb_), baton(baton_) {}; + Work_Callback callback; + Baton* baton; + }; + + struct Async { + uv_async_t watcher; + Statement* stmt; + Rows data; + NODE_SQLITE3_MUTEX_t; + bool completed; + int retrieved; + + // Store the callbacks here because we don't have + // access to the baton in the async callback. + Napi::FunctionReference item_cb; + Napi::FunctionReference completed_cb; + + Async(Statement* st, uv_async_cb async_cb) : + stmt(st), completed(false), retrieved(0) { + watcher.data = this; + NODE_SQLITE3_MUTEX_INIT + stmt->Ref(); + uv_loop_t *loop; + napi_get_uv_event_loop(stmt->Env(), &loop); + uv_async_init(loop, &watcher, async_cb); + } + + ~Async() { + stmt->Unref(); + item_cb.Reset(); + completed_cb.Reset(); + NODE_SQLITE3_MUTEX_DESTROY + } + }; + + Statement(const Napi::CallbackInfo& info); + + ~Statement() { + if (!finalized) Finalize_(); + } + + WORK_DEFINITION(Bind) + WORK_DEFINITION(Get) + WORK_DEFINITION(Run) + WORK_DEFINITION(All) + WORK_DEFINITION(Each) + WORK_DEFINITION(Reset) + + Napi::Value Finalize_(const Napi::CallbackInfo& info); + +protected: + static void Work_BeginPrepare(Database::Baton* baton); + static void Work_Prepare(napi_env env, void* data); + static void Work_AfterPrepare(napi_env env, napi_status status, void* data); + + static void AsyncEach(uv_async_t* handle); + static void CloseCallback(uv_handle_t* handle); + + static void Finalize_(Baton* baton); + void Finalize_(); + + template inline std::unique_ptr BindParameter(const Napi::Value source, T pos); + template T* Bind(const Napi::CallbackInfo& info, int start = 0, int end = -1); + bool Bind(const Parameters ¶meters); + + static void GetRow(Row* row, sqlite3_stmt* stmt); + static Napi::Value RowToJS(Napi::Env env, Row* row); + void Schedule(Work_Callback callback, Baton* baton); + void Process(); + void CleanQueue(); + template static void Error(T* baton); + +protected: + Database* db; + + sqlite3_stmt* _handle = NULL; + int status = SQLITE_OK; + bool prepared = false; + bool locked = true; + bool finalized = false; + + std::queue queue; + std::string message; +}; + +} + +#endif diff --git a/updater/sql/win/src/threading.h b/updater/sql/win/src/threading.h new file mode 100755 index 0000000..7c7139b --- /dev/null +++ b/updater/sql/win/src/threading.h @@ -0,0 +1,10 @@ +#ifndef NODE_SQLITE3_SRC_THREADING_H +#define NODE_SQLITE3_SRC_THREADING_H + +#define NODE_SQLITE3_MUTEX_t uv_mutex_t mutex; +#define NODE_SQLITE3_MUTEX_INIT uv_mutex_init(&mutex); +#define NODE_SQLITE3_MUTEX_LOCK(m) uv_mutex_lock(m); +#define NODE_SQLITE3_MUTEX_UNLOCK(m) uv_mutex_unlock(m); +#define NODE_SQLITE3_MUTEX_DESTROY uv_mutex_destroy(&mutex); + +#endif // NODE_SQLITE3_SRC_THREADING_H diff --git a/updater/tray/16x16Template@2x.png b/updater/tray/16x16Template@2x.png new file mode 100755 index 0000000..3136296 Binary files /dev/null and b/updater/tray/16x16Template@2x.png differ -- cgit