premiere distribution de la page web
This commit is contained in:
62
server/node_modules/better-sqlite3/lib/binding.js
generated
vendored
Normal file
62
server/node_modules/better-sqlite3/lib/binding.js
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
'use strict';
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const PREBUILD_PLATFORMS = ['linux', 'darwin', 'win32'];
|
||||
const PREBUILD_ARCHS = ['x64', 'arm64'];
|
||||
let DEFAULT_ADDON;
|
||||
|
||||
function getBinding(nativeBinding) {
|
||||
// If a path was provided, load the binding from the filesystem.
|
||||
if (typeof nativeBinding === 'string') {
|
||||
// See <https://webpack.js.org/api/module-variables/#__non_webpack_require__-webpack-specific>
|
||||
const requireFunc = typeof __non_webpack_require__ === 'function' ? __non_webpack_require__ : require;
|
||||
return requireFunc(path.resolve(nativeBinding).replace(/(\.node)?$/, '.node'));
|
||||
}
|
||||
|
||||
// If an object was provided, use it as the binding directly.
|
||||
if (typeof nativeBinding === 'object' && nativeBinding !== null) {
|
||||
return nativeBinding;
|
||||
}
|
||||
|
||||
// If we're using the default binding and it already exists, just return it.
|
||||
if (DEFAULT_ADDON) {
|
||||
return DEFAULT_ADDON;
|
||||
}
|
||||
|
||||
// Otherwise, try to find the binding as a prebuilt binary.
|
||||
let filename = getPrebuildPath();
|
||||
if (filename) {
|
||||
return DEFAULT_ADDON = require(filename);
|
||||
}
|
||||
|
||||
// If no prebuilt binary was found, try the default node-gyp locations.
|
||||
filename = path.join(__dirname, '..', 'build', 'Debug', 'better_sqlite3.node');
|
||||
if (!fs.existsSync(filename)) {
|
||||
filename = path.join(__dirname, '..', 'build', 'Release', 'better_sqlite3.node');
|
||||
}
|
||||
return DEFAULT_ADDON = require(filename);
|
||||
}
|
||||
|
||||
function getPrebuildPath() {
|
||||
if (PREBUILD_PLATFORMS.includes(process.platform) && PREBUILD_ARCHS.includes(process.arch)) {
|
||||
const target = `${isLinuxMusl() ? 'linuxmusl' : process.platform}-${process.arch}`;
|
||||
const filename = path.join(__dirname, '..', 'prebuilds', `${target}.node`);
|
||||
if (fs.existsSync(filename)) {
|
||||
return filename;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function isLinuxMusl() {
|
||||
return process.platform === 'linux' && !process.report.getReport().header.glibcVersionRuntime;
|
||||
}
|
||||
|
||||
exports.getBinding = getBinding;
|
||||
exports.getPrebuildPath = getPrebuildPath;
|
||||
|
||||
// This script is executed directly by binding.gyp to detect prebuilt binaries.
|
||||
if (require.main === module) {
|
||||
process.stdout.write(getPrebuildPath() ? '1' : '0');
|
||||
}
|
||||
3
server/node_modules/better-sqlite3/lib/darwin-arm64.js
generated
vendored
Normal file
3
server/node_modules/better-sqlite3/lib/darwin-arm64.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
module.exports = require('./database')(() => require('../prebuilds/darwin-arm64.node'), false);
|
||||
module.exports.SqliteError = require('./sqlite-error');
|
||||
3
server/node_modules/better-sqlite3/lib/darwin-x64.js
generated
vendored
Normal file
3
server/node_modules/better-sqlite3/lib/darwin-x64.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
module.exports = require('./database')(() => require('../prebuilds/darwin-x64.node'), false);
|
||||
module.exports.SqliteError = require('./sqlite-error');
|
||||
109
server/node_modules/better-sqlite3/lib/database.js
generated
vendored
Normal file
109
server/node_modules/better-sqlite3/lib/database.js
generated
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
'use strict';
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const util = require('./util');
|
||||
const SqliteError = require('./sqlite-error');
|
||||
|
||||
module.exports = function createDatabase(getAddon, allowNativeBinding) {
|
||||
function Database(filenameGiven, options) {
|
||||
if (new.target == null) {
|
||||
return new Database(filenameGiven, options);
|
||||
}
|
||||
|
||||
// Apply defaults
|
||||
let buffer;
|
||||
if (Buffer.isBuffer(filenameGiven)) {
|
||||
buffer = filenameGiven;
|
||||
filenameGiven = ':memory:';
|
||||
}
|
||||
if (filenameGiven == null) filenameGiven = '';
|
||||
if (options == null) options = {};
|
||||
|
||||
// Validate arguments
|
||||
if (typeof filenameGiven !== 'string') throw new TypeError('Expected first argument to be a string');
|
||||
if (typeof options !== 'object') throw new TypeError('Expected second argument to be an options object');
|
||||
if ('readOnly' in options) throw new TypeError('Misspelled option "readOnly" should be "readonly"');
|
||||
if ('memory' in options) throw new TypeError('Option "memory" was removed in v7.0.0 (use ":memory:" filename instead)');
|
||||
|
||||
// Interpret options
|
||||
const filename = filenameGiven.trim();
|
||||
const anonymous = filename === '' || filename === ':memory:';
|
||||
const readonly = util.getBooleanOption(options, 'readonly');
|
||||
const fileMustExist = util.getBooleanOption(options, 'fileMustExist');
|
||||
const timeout = 'timeout' in options ? options.timeout : 5000;
|
||||
const verbose = 'verbose' in options ? options.verbose : null;
|
||||
const nativeBinding = 'nativeBinding' in options ? options.nativeBinding : null;
|
||||
|
||||
// Validate interpreted options
|
||||
if (readonly && anonymous && !buffer) throw new TypeError('In-memory/temporary databases cannot be readonly');
|
||||
if (!Number.isInteger(timeout) || timeout < 0) throw new TypeError('Expected the "timeout" option to be a positive integer');
|
||||
if (timeout > 0x7fffffff) throw new RangeError('Option "timeout" cannot be greater than 2147483647');
|
||||
if (verbose != null && typeof verbose !== 'function') throw new TypeError('Expected the "verbose" option to be a function');
|
||||
if (!allowNativeBinding && 'nativeBinding' in options) throw new TypeError('The "nativeBinding" option is only supported by the default better-sqlite3 entrypoint');
|
||||
if (allowNativeBinding && nativeBinding != null && typeof nativeBinding !== 'string' && typeof nativeBinding !== 'object') throw new TypeError('Expected the "nativeBinding" option to be a string or addon object');
|
||||
|
||||
// Load the native addon
|
||||
const addon = getAddon(nativeBinding);
|
||||
if (!addon.isInitialized) {
|
||||
addon.initialize(SqliteError, arrayFactory, arrayAppender, rowFactory, recordFactory);
|
||||
addon.isInitialized = true;
|
||||
}
|
||||
|
||||
// Make sure the specified directory exists
|
||||
if (!anonymous && !filename.startsWith('file:') && !fs.existsSync(path.dirname(filename))) {
|
||||
throw new TypeError('Cannot open database because the directory does not exist');
|
||||
}
|
||||
|
||||
Object.defineProperties(this, {
|
||||
[util.cppdb]: { value: new addon.Database(filename, filenameGiven, anonymous, readonly, fileMustExist, timeout, verbose || null, buffer || null) },
|
||||
...wrappers.getters,
|
||||
});
|
||||
}
|
||||
|
||||
const wrappers = require('./methods/wrappers');
|
||||
Database.prototype.prepare = wrappers.prepare;
|
||||
Database.prototype.transaction = require('./methods/transaction');
|
||||
Database.prototype.pragma = require('./methods/pragma');
|
||||
Database.prototype.explain = require('./methods/explain');
|
||||
Database.prototype.backup = require('./methods/backup');
|
||||
Database.prototype.serialize = require('./methods/serialize');
|
||||
Database.prototype.function = require('./methods/function');
|
||||
Database.prototype.aggregate = require('./methods/aggregate');
|
||||
Database.prototype.table = require('./methods/table');
|
||||
Database.prototype.loadExtension = wrappers.loadExtension;
|
||||
Database.prototype.exec = wrappers.exec;
|
||||
Database.prototype.close = wrappers.close;
|
||||
Database.prototype.defaultSafeIntegers = wrappers.defaultSafeIntegers;
|
||||
Database.prototype.unsafeMode = wrappers.unsafeMode;
|
||||
Database.prototype[util.inspect] = require('./methods/inspect');
|
||||
|
||||
return Database;
|
||||
};
|
||||
|
||||
function arrayFactory(...values) {
|
||||
return values;
|
||||
}
|
||||
|
||||
function arrayAppender(array, ...values) {
|
||||
const offset = array.length;
|
||||
for (let i = 0; i < values.length; ++i) {
|
||||
array[offset + i] = values[i];
|
||||
}
|
||||
}
|
||||
|
||||
function rowFactory(...keys) {
|
||||
if (!keys.includes('__proto__')) {
|
||||
const parameters = keys.map((_, index) => `v${index}`).join(',');
|
||||
const properties = keys.map((key, index) => `${JSON.stringify(key)}:v${index}`).join(',');
|
||||
return Function(`return (${parameters}) => ({${properties}})`)();
|
||||
}
|
||||
return (...values) => {
|
||||
const row = {};
|
||||
for (let i = 0; i < keys.length; ++i) row[keys[i]] = values[i];
|
||||
return row;
|
||||
};
|
||||
}
|
||||
|
||||
function recordFactory(value) {
|
||||
return { value, done: false };
|
||||
}
|
||||
3
server/node_modules/better-sqlite3/lib/index.js
generated
vendored
Normal file
3
server/node_modules/better-sqlite3/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
module.exports = require('./database')(require('./binding').getBinding, true);
|
||||
module.exports.SqliteError = require('./sqlite-error');
|
||||
3
server/node_modules/better-sqlite3/lib/linux-arm64.js
generated
vendored
Normal file
3
server/node_modules/better-sqlite3/lib/linux-arm64.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
module.exports = require('./database')(() => require('../prebuilds/linux-arm64.node'), false);
|
||||
module.exports.SqliteError = require('./sqlite-error');
|
||||
3
server/node_modules/better-sqlite3/lib/linux-x64.js
generated
vendored
Normal file
3
server/node_modules/better-sqlite3/lib/linux-x64.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
module.exports = require('./database')(() => require('../prebuilds/linux-x64.node'), false);
|
||||
module.exports.SqliteError = require('./sqlite-error');
|
||||
4
server/node_modules/better-sqlite3/lib/linuxmusl-arm64.js
generated
vendored
Normal file
4
server/node_modules/better-sqlite3/lib/linuxmusl-arm64.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
'use strict';
|
||||
const Database = require('./database')(() => require('../prebuilds/linuxmusl-arm64.node'), false);
|
||||
Database.SqliteError = require('./sqlite-error');
|
||||
module.exports = Database;
|
||||
4
server/node_modules/better-sqlite3/lib/linuxmusl-x64.js
generated
vendored
Normal file
4
server/node_modules/better-sqlite3/lib/linuxmusl-x64.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
'use strict';
|
||||
const Database = require('./database')(() => require('../prebuilds/linuxmusl-x64.node'), false);
|
||||
Database.SqliteError = require('./sqlite-error');
|
||||
module.exports = Database;
|
||||
43
server/node_modules/better-sqlite3/lib/methods/aggregate.js
generated
vendored
Normal file
43
server/node_modules/better-sqlite3/lib/methods/aggregate.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
'use strict';
|
||||
const { getBooleanOption, cppdb } = require('../util');
|
||||
|
||||
module.exports = function defineAggregate(name, options) {
|
||||
// Validate arguments
|
||||
if (typeof name !== 'string') throw new TypeError('Expected first argument to be a string');
|
||||
if (typeof options !== 'object' || options === null) throw new TypeError('Expected second argument to be an options object');
|
||||
if (!name) throw new TypeError('User-defined function name cannot be an empty string');
|
||||
|
||||
// Interpret options
|
||||
const start = 'start' in options ? options.start : null;
|
||||
const step = getFunctionOption(options, 'step', true);
|
||||
const inverse = getFunctionOption(options, 'inverse', false);
|
||||
const result = getFunctionOption(options, 'result', false);
|
||||
const safeIntegers = 'safeIntegers' in options ? +getBooleanOption(options, 'safeIntegers') : 2;
|
||||
const deterministic = getBooleanOption(options, 'deterministic');
|
||||
const directOnly = getBooleanOption(options, 'directOnly');
|
||||
const varargs = getBooleanOption(options, 'varargs');
|
||||
let argCount = -1;
|
||||
|
||||
// Determine argument count
|
||||
if (!varargs) {
|
||||
argCount = Math.max(getLength(step), inverse ? getLength(inverse) : 0);
|
||||
if (argCount > 0) argCount -= 1;
|
||||
if (argCount > 100) throw new RangeError('User-defined functions cannot have more than 100 arguments');
|
||||
}
|
||||
|
||||
this[cppdb].aggregate(start, step, inverse, result, name, argCount, safeIntegers, deterministic, directOnly);
|
||||
return this;
|
||||
};
|
||||
|
||||
const getFunctionOption = (options, key, required) => {
|
||||
const value = key in options ? options[key] : null;
|
||||
if (typeof value === 'function') return value;
|
||||
if (value != null) throw new TypeError(`Expected the "${key}" option to be a function`);
|
||||
if (required) throw new TypeError(`Missing required option "${key}"`);
|
||||
return null;
|
||||
};
|
||||
|
||||
const getLength = ({ length }) => {
|
||||
if (Number.isInteger(length) && length >= 0) return length;
|
||||
throw new TypeError('Expected function.length to be a positive integer');
|
||||
};
|
||||
67
server/node_modules/better-sqlite3/lib/methods/backup.js
generated
vendored
Normal file
67
server/node_modules/better-sqlite3/lib/methods/backup.js
generated
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
'use strict';
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { promisify } = require('util');
|
||||
const { cppdb } = require('../util');
|
||||
const fsAccess = promisify(fs.access);
|
||||
|
||||
module.exports = async function backup(filename, options) {
|
||||
if (options == null) options = {};
|
||||
|
||||
// Validate arguments
|
||||
if (typeof filename !== 'string') throw new TypeError('Expected first argument to be a string');
|
||||
if (typeof options !== 'object') throw new TypeError('Expected second argument to be an options object');
|
||||
|
||||
// Interpret options
|
||||
filename = filename.trim();
|
||||
const attachedName = 'attached' in options ? options.attached : 'main';
|
||||
const handler = 'progress' in options ? options.progress : null;
|
||||
|
||||
// Validate interpreted options
|
||||
if (!filename) throw new TypeError('Backup filename cannot be an empty string');
|
||||
if (filename === ':memory:') throw new TypeError('Invalid backup filename ":memory:"');
|
||||
if (typeof attachedName !== 'string') throw new TypeError('Expected the "attached" option to be a string');
|
||||
if (!attachedName) throw new TypeError('The "attached" option cannot be an empty string');
|
||||
if (handler != null && typeof handler !== 'function') throw new TypeError('Expected the "progress" option to be a function');
|
||||
|
||||
// Make sure the specified directory exists
|
||||
await fsAccess(path.dirname(filename)).catch(() => {
|
||||
throw new TypeError('Cannot save backup because the directory does not exist');
|
||||
});
|
||||
|
||||
const isNewFile = await fsAccess(filename).then(() => false, () => true);
|
||||
return runBackup(this[cppdb].backup(this, attachedName, filename, isNewFile), handler || null);
|
||||
};
|
||||
|
||||
const runBackup = (backup, handler) => {
|
||||
let rate = 0;
|
||||
let useDefault = true;
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
setImmediate(function step() {
|
||||
try {
|
||||
const progress = backup.transfer(rate);
|
||||
if (!progress.remainingPages) {
|
||||
backup.close();
|
||||
resolve(progress);
|
||||
return;
|
||||
}
|
||||
if (useDefault) {
|
||||
useDefault = false;
|
||||
rate = 100;
|
||||
}
|
||||
if (handler) {
|
||||
const ret = handler(progress);
|
||||
if (ret !== undefined) {
|
||||
if (typeof ret === 'number' && ret === ret) rate = Math.max(0, Math.min(0x7fffffff, Math.round(ret)));
|
||||
else throw new TypeError('Expected progress callback to return a number or undefined');
|
||||
}
|
||||
}
|
||||
setImmediate(step);
|
||||
} catch (err) {
|
||||
backup.close();
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
9
server/node_modules/better-sqlite3/lib/methods/explain.js
generated
vendored
Normal file
9
server/node_modules/better-sqlite3/lib/methods/explain.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
'use strict';
|
||||
const { cppdb } = require('../util');
|
||||
|
||||
module.exports = function explain(source) {
|
||||
if (typeof source !== 'string') throw new TypeError('Expected first argument to be a string');
|
||||
|
||||
const stmt = this[cppdb].prepare(`EXPLAIN ${source}`, this, false, true);
|
||||
return stmt.all();
|
||||
};
|
||||
31
server/node_modules/better-sqlite3/lib/methods/function.js
generated
vendored
Normal file
31
server/node_modules/better-sqlite3/lib/methods/function.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
'use strict';
|
||||
const { getBooleanOption, cppdb } = require('../util');
|
||||
|
||||
module.exports = function defineFunction(name, options, fn) {
|
||||
// Apply defaults
|
||||
if (options == null) options = {};
|
||||
if (typeof options === 'function') { fn = options; options = {}; }
|
||||
|
||||
// Validate arguments
|
||||
if (typeof name !== 'string') throw new TypeError('Expected first argument to be a string');
|
||||
if (typeof fn !== 'function') throw new TypeError('Expected last argument to be a function');
|
||||
if (typeof options !== 'object') throw new TypeError('Expected second argument to be an options object');
|
||||
if (!name) throw new TypeError('User-defined function name cannot be an empty string');
|
||||
|
||||
// Interpret options
|
||||
const safeIntegers = 'safeIntegers' in options ? +getBooleanOption(options, 'safeIntegers') : 2;
|
||||
const deterministic = getBooleanOption(options, 'deterministic');
|
||||
const directOnly = getBooleanOption(options, 'directOnly');
|
||||
const varargs = getBooleanOption(options, 'varargs');
|
||||
let argCount = -1;
|
||||
|
||||
// Determine argument count
|
||||
if (!varargs) {
|
||||
argCount = fn.length;
|
||||
if (!Number.isInteger(argCount) || argCount < 0) throw new TypeError('Expected function.length to be a positive integer');
|
||||
if (argCount > 100) throw new RangeError('User-defined functions cannot have more than 100 arguments');
|
||||
}
|
||||
|
||||
this[cppdb].function(fn, name, argCount, safeIntegers, deterministic, directOnly);
|
||||
return this;
|
||||
};
|
||||
7
server/node_modules/better-sqlite3/lib/methods/inspect.js
generated
vendored
Normal file
7
server/node_modules/better-sqlite3/lib/methods/inspect.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
'use strict';
|
||||
const DatabaseInspection = function Database() {};
|
||||
|
||||
module.exports = function inspect(depth, opts) {
|
||||
return Object.assign(new DatabaseInspection(), this);
|
||||
};
|
||||
|
||||
12
server/node_modules/better-sqlite3/lib/methods/pragma.js
generated
vendored
Normal file
12
server/node_modules/better-sqlite3/lib/methods/pragma.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
const { getBooleanOption, cppdb } = require('../util');
|
||||
|
||||
module.exports = function pragma(source, options) {
|
||||
if (options == null) options = {};
|
||||
if (typeof source !== 'string') throw new TypeError('Expected first argument to be a string');
|
||||
if (typeof options !== 'object') throw new TypeError('Expected second argument to be an options object');
|
||||
const simple = getBooleanOption(options, 'simple');
|
||||
|
||||
const stmt = this[cppdb].prepare(`PRAGMA ${source}`, this, true, false);
|
||||
return simple ? stmt.pluck().get() : stmt.all();
|
||||
};
|
||||
16
server/node_modules/better-sqlite3/lib/methods/serialize.js
generated
vendored
Normal file
16
server/node_modules/better-sqlite3/lib/methods/serialize.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
'use strict';
|
||||
const { cppdb } = require('../util');
|
||||
|
||||
module.exports = function serialize(options) {
|
||||
if (options == null) options = {};
|
||||
|
||||
// Validate arguments
|
||||
if (typeof options !== 'object') throw new TypeError('Expected first argument to be an options object');
|
||||
|
||||
// Interpret and validate options
|
||||
const attachedName = 'attached' in options ? options.attached : 'main';
|
||||
if (typeof attachedName !== 'string') throw new TypeError('Expected the "attached" option to be a string');
|
||||
if (!attachedName) throw new TypeError('The "attached" option cannot be an empty string');
|
||||
|
||||
return this[cppdb].serialize(attachedName);
|
||||
};
|
||||
195
server/node_modules/better-sqlite3/lib/methods/table.js
generated
vendored
Normal file
195
server/node_modules/better-sqlite3/lib/methods/table.js
generated
vendored
Normal file
@@ -0,0 +1,195 @@
|
||||
'use strict';
|
||||
const { cppdb } = require('../util');
|
||||
|
||||
module.exports = function defineTable(name, factory) {
|
||||
// Validate arguments
|
||||
if (typeof name !== 'string') throw new TypeError('Expected first argument to be a string');
|
||||
if (!name) throw new TypeError('Virtual table module name cannot be an empty string');
|
||||
|
||||
// Determine whether the module is eponymous-only or not
|
||||
let eponymous = false;
|
||||
if (typeof factory === 'object' && factory !== null) {
|
||||
eponymous = true;
|
||||
factory = defer(parseTableDefinition(factory, 'used', name));
|
||||
} else {
|
||||
if (typeof factory !== 'function') throw new TypeError('Expected second argument to be a function or a table definition object');
|
||||
factory = wrapFactory(factory);
|
||||
}
|
||||
|
||||
this[cppdb].table(factory, name, eponymous);
|
||||
return this;
|
||||
};
|
||||
|
||||
function wrapFactory(factory) {
|
||||
return function virtualTableFactory(moduleName, databaseName, tableName, ...args) {
|
||||
const thisObject = {
|
||||
module: moduleName,
|
||||
database: databaseName,
|
||||
table: tableName,
|
||||
};
|
||||
|
||||
// Generate a new table definition by invoking the factory
|
||||
const def = apply.call(factory, thisObject, args);
|
||||
if (typeof def !== 'object' || def === null) {
|
||||
throw new TypeError(`Virtual table module "${moduleName}" did not return a table definition object`);
|
||||
}
|
||||
|
||||
return parseTableDefinition(def, 'returned', moduleName);
|
||||
};
|
||||
}
|
||||
|
||||
function parseTableDefinition(def, verb, moduleName) {
|
||||
// Validate required properties
|
||||
if (!hasOwnProperty.call(def, 'rows')) {
|
||||
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "rows" property`);
|
||||
}
|
||||
if (!hasOwnProperty.call(def, 'columns')) {
|
||||
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "columns" property`);
|
||||
}
|
||||
|
||||
// Validate "rows" property
|
||||
const rows = def.rows;
|
||||
if (typeof rows !== 'function' || Object.getPrototypeOf(rows) !== GeneratorFunctionPrototype) {
|
||||
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "rows" property (should be a generator function)`);
|
||||
}
|
||||
|
||||
// Validate "columns" property
|
||||
let columns = def.columns;
|
||||
if (!Array.isArray(columns) || !isStringArray(columns = [...columns])) {
|
||||
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "columns" property (should be an array of strings)`);
|
||||
}
|
||||
if (columns.length !== new Set(columns).size) {
|
||||
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate column names`);
|
||||
}
|
||||
if (!columns.length) {
|
||||
throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with zero columns`);
|
||||
}
|
||||
|
||||
// Validate "parameters" property
|
||||
let parameters;
|
||||
if (hasOwnProperty.call(def, 'parameters')) {
|
||||
parameters = def.parameters;
|
||||
if (!Array.isArray(parameters) || !isStringArray(parameters = [...parameters])) {
|
||||
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "parameters" property (should be an array of strings)`);
|
||||
}
|
||||
} else {
|
||||
parameters = inferParameters(rows);
|
||||
}
|
||||
if (parameters.length !== new Set(parameters).size) {
|
||||
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate parameter names`);
|
||||
}
|
||||
if (parameters.length > 32) {
|
||||
throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with more than the maximum number of 32 parameters`);
|
||||
}
|
||||
for (const parameter of parameters) {
|
||||
if (columns.includes(parameter)) {
|
||||
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with column "${parameter}" which was ambiguously defined as both a column and parameter`);
|
||||
}
|
||||
}
|
||||
|
||||
// Validate "safeIntegers" option
|
||||
let safeIntegers = 2;
|
||||
if (hasOwnProperty.call(def, 'safeIntegers')) {
|
||||
const bool = def.safeIntegers;
|
||||
if (typeof bool !== 'boolean') {
|
||||
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "safeIntegers" property (should be a boolean)`);
|
||||
}
|
||||
safeIntegers = +bool;
|
||||
}
|
||||
|
||||
// Validate "directOnly" option
|
||||
let directOnly = false;
|
||||
if (hasOwnProperty.call(def, 'directOnly')) {
|
||||
directOnly = def.directOnly;
|
||||
if (typeof directOnly !== 'boolean') {
|
||||
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "directOnly" property (should be a boolean)`);
|
||||
}
|
||||
}
|
||||
|
||||
// Generate SQL for the virtual table definition
|
||||
const columnDefinitions = [
|
||||
...parameters.map(identifier).map(str => `${str} HIDDEN`),
|
||||
...columns.map(identifier),
|
||||
];
|
||||
return [
|
||||
`CREATE TABLE x(${columnDefinitions.join(', ')});`,
|
||||
wrapGenerator(rows, new Map(columns.map((x, i) => [x, parameters.length + i])), moduleName),
|
||||
parameters,
|
||||
safeIntegers,
|
||||
directOnly,
|
||||
];
|
||||
}
|
||||
|
||||
function wrapGenerator(generator, columnMap, moduleName) {
|
||||
return function* virtualTable(...args) {
|
||||
/*
|
||||
We must defensively clone any buffers in the arguments, because
|
||||
otherwise the generator could mutate one of them, which would cause
|
||||
us to return incorrect values for hidden columns, potentially
|
||||
corrupting the database.
|
||||
*/
|
||||
const output = args.map(x => Buffer.isBuffer(x) ? Buffer.from(x) : x);
|
||||
for (let i = 0; i < columnMap.size; ++i) {
|
||||
output.push(null); // Fill with nulls to prevent gaps in array (v8 optimization)
|
||||
}
|
||||
for (const row of generator(...args)) {
|
||||
if (Array.isArray(row)) {
|
||||
extractRowArray(row, output, columnMap.size, moduleName);
|
||||
yield output;
|
||||
} else if (typeof row === 'object' && row !== null) {
|
||||
extractRowObject(row, output, columnMap, moduleName);
|
||||
yield output;
|
||||
} else {
|
||||
throw new TypeError(`Virtual table module "${moduleName}" yielded something that isn't a valid row object`);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function extractRowArray(row, output, columnCount, moduleName) {
|
||||
if (row.length !== columnCount) {
|
||||
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an incorrect number of columns`);
|
||||
}
|
||||
const offset = output.length - columnCount;
|
||||
for (let i = 0; i < columnCount; ++i) {
|
||||
output[i + offset] = row[i];
|
||||
}
|
||||
}
|
||||
|
||||
function extractRowObject(row, output, columnMap, moduleName) {
|
||||
let count = 0;
|
||||
for (const key of Object.keys(row)) {
|
||||
const index = columnMap.get(key);
|
||||
if (index === undefined) {
|
||||
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an undeclared column "${key}"`);
|
||||
}
|
||||
output[index] = row[key];
|
||||
count += 1;
|
||||
}
|
||||
if (count !== columnMap.size) {
|
||||
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with missing columns`);
|
||||
}
|
||||
}
|
||||
|
||||
function inferParameters({ length }) {
|
||||
if (!Number.isInteger(length) || length < 0) {
|
||||
throw new TypeError('Expected function.length to be a positive integer');
|
||||
}
|
||||
const params = [];
|
||||
for (let i = 0; i < length; ++i) {
|
||||
params.push(`$${i + 1}`);
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
const { hasOwnProperty } = Object.prototype;
|
||||
const { apply } = Function.prototype;
|
||||
const GeneratorFunctionPrototype = Object.getPrototypeOf(function*(){});
|
||||
const identifier = str => `"${str.replace(/"/g, '""')}"`;
|
||||
const defer = x => () => x;
|
||||
const isStringArray = (arr) => {
|
||||
for (let i = 0; i < arr.length; ++i) {
|
||||
if (typeof arr[i] !== 'string') return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
78
server/node_modules/better-sqlite3/lib/methods/transaction.js
generated
vendored
Normal file
78
server/node_modules/better-sqlite3/lib/methods/transaction.js
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
'use strict';
|
||||
const { cppdb } = require('../util');
|
||||
const controllers = new WeakMap();
|
||||
|
||||
module.exports = function transaction(fn) {
|
||||
if (typeof fn !== 'function') throw new TypeError('Expected first argument to be a function');
|
||||
|
||||
const db = this[cppdb];
|
||||
const controller = getController(db, this);
|
||||
const { apply } = Function.prototype;
|
||||
|
||||
// Each version of the transaction function has these same properties
|
||||
const properties = {
|
||||
default: { value: wrapTransaction(apply, fn, db, controller.default) },
|
||||
deferred: { value: wrapTransaction(apply, fn, db, controller.deferred) },
|
||||
immediate: { value: wrapTransaction(apply, fn, db, controller.immediate) },
|
||||
exclusive: { value: wrapTransaction(apply, fn, db, controller.exclusive) },
|
||||
database: { value: this, enumerable: true },
|
||||
};
|
||||
|
||||
Object.defineProperties(properties.default.value, properties);
|
||||
Object.defineProperties(properties.deferred.value, properties);
|
||||
Object.defineProperties(properties.immediate.value, properties);
|
||||
Object.defineProperties(properties.exclusive.value, properties);
|
||||
|
||||
// Return the default version of the transaction function
|
||||
return properties.default.value;
|
||||
};
|
||||
|
||||
// Return the database's cached transaction controller, or create a new one
|
||||
const getController = (db, self) => {
|
||||
let controller = controllers.get(db);
|
||||
if (!controller) {
|
||||
const shared = {
|
||||
commit: db.prepare('COMMIT', self, false, false),
|
||||
rollback: db.prepare('ROLLBACK', self, false, false),
|
||||
savepoint: db.prepare('SAVEPOINT `\t_bs3.\t`', self, false, false),
|
||||
release: db.prepare('RELEASE `\t_bs3.\t`', self, false, false),
|
||||
rollbackTo: db.prepare('ROLLBACK TO `\t_bs3.\t`', self, false, false),
|
||||
};
|
||||
controllers.set(db, controller = {
|
||||
default: Object.assign({ begin: db.prepare('BEGIN', self, false, false) }, shared),
|
||||
deferred: Object.assign({ begin: db.prepare('BEGIN DEFERRED', self, false, false) }, shared),
|
||||
immediate: Object.assign({ begin: db.prepare('BEGIN IMMEDIATE', self, false, false) }, shared),
|
||||
exclusive: Object.assign({ begin: db.prepare('BEGIN EXCLUSIVE', self, false, false) }, shared),
|
||||
});
|
||||
}
|
||||
return controller;
|
||||
};
|
||||
|
||||
// Return a new transaction function by wrapping the given function
|
||||
const wrapTransaction = (apply, fn, db, { begin, commit, rollback, savepoint, release, rollbackTo }) => function sqliteTransaction() {
|
||||
let before, after, undo;
|
||||
if (db.inTransaction) {
|
||||
before = savepoint;
|
||||
after = release;
|
||||
undo = rollbackTo;
|
||||
} else {
|
||||
before = begin;
|
||||
after = commit;
|
||||
undo = rollback;
|
||||
}
|
||||
before.run();
|
||||
try {
|
||||
const result = apply.call(fn, this, arguments);
|
||||
if (result && typeof result.then === 'function') {
|
||||
throw new TypeError('Transaction function cannot return a promise');
|
||||
}
|
||||
after.run();
|
||||
return result;
|
||||
} catch (ex) {
|
||||
if (db.inTransaction) {
|
||||
undo.run();
|
||||
if (undo !== rollback) after.run();
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
};
|
||||
54
server/node_modules/better-sqlite3/lib/methods/wrappers.js
generated
vendored
Normal file
54
server/node_modules/better-sqlite3/lib/methods/wrappers.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
'use strict';
|
||||
const { cppdb } = require('../util');
|
||||
|
||||
exports.prepare = function prepare(sql) {
|
||||
return this[cppdb].prepare(sql, this, false, false);
|
||||
};
|
||||
|
||||
exports.exec = function exec(sql) {
|
||||
this[cppdb].exec(sql);
|
||||
return this;
|
||||
};
|
||||
|
||||
exports.close = function close() {
|
||||
this[cppdb].close();
|
||||
return this;
|
||||
};
|
||||
|
||||
exports.loadExtension = function loadExtension(...args) {
|
||||
this[cppdb].loadExtension(...args);
|
||||
return this;
|
||||
};
|
||||
|
||||
exports.defaultSafeIntegers = function defaultSafeIntegers(...args) {
|
||||
this[cppdb].defaultSafeIntegers(...args);
|
||||
return this;
|
||||
};
|
||||
|
||||
exports.unsafeMode = function unsafeMode(...args) {
|
||||
this[cppdb].unsafeMode(...args);
|
||||
return this;
|
||||
};
|
||||
|
||||
exports.getters = {
|
||||
name: {
|
||||
get: function name() { return this[cppdb].name; },
|
||||
enumerable: true,
|
||||
},
|
||||
open: {
|
||||
get: function open() { return this[cppdb].open; },
|
||||
enumerable: true,
|
||||
},
|
||||
inTransaction: {
|
||||
get: function inTransaction() { return this[cppdb].inTransaction; },
|
||||
enumerable: true,
|
||||
},
|
||||
readonly: {
|
||||
get: function readonly() { return this[cppdb].readonly; },
|
||||
enumerable: true,
|
||||
},
|
||||
memory: {
|
||||
get: function memory() { return this[cppdb].memory; },
|
||||
enumerable: true,
|
||||
},
|
||||
};
|
||||
25
server/node_modules/better-sqlite3/lib/sqlite-error.js
generated
vendored
Normal file
25
server/node_modules/better-sqlite3/lib/sqlite-error.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
class SqliteError extends Error {
|
||||
constructor(message, code) {
|
||||
if (typeof code !== 'string') {
|
||||
throw new TypeError('Expected second argument to be a string');
|
||||
}
|
||||
|
||||
super('' + message);
|
||||
this.code = code;
|
||||
|
||||
if (typeof Error.captureStackTrace === 'function') {
|
||||
Error.captureStackTrace(this, SqliteError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Object.defineProperty(SqliteError.prototype, 'name', {
|
||||
value: 'SqliteError',
|
||||
writable: true,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
});
|
||||
|
||||
module.exports = SqliteError;
|
||||
12
server/node_modules/better-sqlite3/lib/util.js
generated
vendored
Normal file
12
server/node_modules/better-sqlite3/lib/util.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
exports.getBooleanOption = (options, key) => {
|
||||
let value = false;
|
||||
if (key in options && typeof (value = options[key]) !== 'boolean') {
|
||||
throw new TypeError(`Expected the "${key}" option to be a boolean`);
|
||||
}
|
||||
return value;
|
||||
};
|
||||
|
||||
exports.cppdb = Symbol();
|
||||
exports.inspect = Symbol.for('nodejs.util.inspect.custom');
|
||||
3
server/node_modules/better-sqlite3/lib/win32-arm64.js
generated
vendored
Normal file
3
server/node_modules/better-sqlite3/lib/win32-arm64.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
module.exports = require('./database')(() => require('../prebuilds/win32-arm64.node'), false);
|
||||
module.exports.SqliteError = require('./sqlite-error');
|
||||
3
server/node_modules/better-sqlite3/lib/win32-x64.js
generated
vendored
Normal file
3
server/node_modules/better-sqlite3/lib/win32-x64.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
module.exports = require('./database')(() => require('../prebuilds/win32-x64.node'), false);
|
||||
module.exports.SqliteError = require('./sqlite-error');
|
||||
Reference in New Issue
Block a user