speexjs 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -60
- package/dist/cli/index.js +300 -91
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1048 -285
- package/dist/index.js.map +1 -1
- package/dist/rpc/index.d.ts +1 -1
- package/dist/schema/index.d.ts +36 -30
- package/dist/schema/index.js +12 -229
- package/dist/schema/index.js.map +1 -1
- package/dist/server/auth/index.d.ts +1 -0
- package/dist/server/auth/index.js +18 -12
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/database/index.d.ts +22 -2
- package/dist/server/database/index.js +993 -30
- package/dist/server/database/index.js.map +1 -1
- package/dist/server/http/index.js +19 -2
- package/dist/server/http/index.js.map +1 -1
- package/dist/server/index.d.ts +4 -3
- package/dist/server/index.js +1028 -48
- package/dist/server/index.js.map +1 -1
- package/dist/server/middleware/index.js +53 -33
- package/dist/server/middleware/index.js.map +1 -1
- package/dist/server/router/index.js +8 -6
- package/dist/server/router/index.js.map +1 -1
- package/dist/{types-CXH8hPei.d.ts → types-aW38f63o.d.ts} +1 -1
- package/package.json +8 -3
|
@@ -1,3 +1,809 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
+
}) : x)(function(x) {
|
|
10
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
11
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
|
+
});
|
|
13
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
14
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
30
|
+
mod
|
|
31
|
+
));
|
|
32
|
+
|
|
33
|
+
// node_modules/better-sqlite3/lib/util.js
|
|
34
|
+
var require_util = __commonJS({
|
|
35
|
+
"node_modules/better-sqlite3/lib/util.js"(exports) {
|
|
36
|
+
"use strict";
|
|
37
|
+
exports.getBooleanOption = (options, key) => {
|
|
38
|
+
let value = false;
|
|
39
|
+
if (key in options && typeof (value = options[key]) !== "boolean") {
|
|
40
|
+
throw new TypeError(`Expected the "${key}" option to be a boolean`);
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
};
|
|
44
|
+
exports.cppdb = /* @__PURE__ */ Symbol();
|
|
45
|
+
exports.inspect = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// node_modules/better-sqlite3/lib/sqlite-error.js
|
|
50
|
+
var require_sqlite_error = __commonJS({
|
|
51
|
+
"node_modules/better-sqlite3/lib/sqlite-error.js"(exports, module) {
|
|
52
|
+
"use strict";
|
|
53
|
+
var descriptor = { value: "SqliteError", writable: true, enumerable: false, configurable: true };
|
|
54
|
+
function SqliteError(message, code) {
|
|
55
|
+
if (new.target !== SqliteError) {
|
|
56
|
+
return new SqliteError(message, code);
|
|
57
|
+
}
|
|
58
|
+
if (typeof code !== "string") {
|
|
59
|
+
throw new TypeError("Expected second argument to be a string");
|
|
60
|
+
}
|
|
61
|
+
Error.call(this, message);
|
|
62
|
+
descriptor.value = "" + message;
|
|
63
|
+
Object.defineProperty(this, "message", descriptor);
|
|
64
|
+
Error.captureStackTrace(this, SqliteError);
|
|
65
|
+
this.code = code;
|
|
66
|
+
}
|
|
67
|
+
Object.setPrototypeOf(SqliteError, Error);
|
|
68
|
+
Object.setPrototypeOf(SqliteError.prototype, Error.prototype);
|
|
69
|
+
Object.defineProperty(SqliteError.prototype, "name", descriptor);
|
|
70
|
+
module.exports = SqliteError;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// node_modules/file-uri-to-path/index.js
|
|
75
|
+
var require_file_uri_to_path = __commonJS({
|
|
76
|
+
"node_modules/file-uri-to-path/index.js"(exports, module) {
|
|
77
|
+
"use strict";
|
|
78
|
+
var sep = __require("path").sep || "/";
|
|
79
|
+
module.exports = fileUriToPath;
|
|
80
|
+
function fileUriToPath(uri) {
|
|
81
|
+
if ("string" != typeof uri || uri.length <= 7 || "file://" != uri.substring(0, 7)) {
|
|
82
|
+
throw new TypeError("must pass in a file:// URI to convert to a file path");
|
|
83
|
+
}
|
|
84
|
+
var rest = decodeURI(uri.substring(7));
|
|
85
|
+
var firstSlash = rest.indexOf("/");
|
|
86
|
+
var host = rest.substring(0, firstSlash);
|
|
87
|
+
var path = rest.substring(firstSlash + 1);
|
|
88
|
+
if ("localhost" == host) host = "";
|
|
89
|
+
if (host) {
|
|
90
|
+
host = sep + sep + host;
|
|
91
|
+
}
|
|
92
|
+
path = path.replace(/^(.+)\|/, "$1:");
|
|
93
|
+
if (sep == "\\") {
|
|
94
|
+
path = path.replace(/\//g, "\\");
|
|
95
|
+
}
|
|
96
|
+
if (/^.+\:/.test(path)) {
|
|
97
|
+
} else {
|
|
98
|
+
path = sep + path;
|
|
99
|
+
}
|
|
100
|
+
return host + path;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// node_modules/bindings/bindings.js
|
|
106
|
+
var require_bindings = __commonJS({
|
|
107
|
+
"node_modules/bindings/bindings.js"(exports, module) {
|
|
108
|
+
"use strict";
|
|
109
|
+
var fs = __require("fs");
|
|
110
|
+
var path = __require("path");
|
|
111
|
+
var fileURLToPath = require_file_uri_to_path();
|
|
112
|
+
var join = path.join;
|
|
113
|
+
var dirname = path.dirname;
|
|
114
|
+
var exists = fs.accessSync && function(path2) {
|
|
115
|
+
try {
|
|
116
|
+
fs.accessSync(path2);
|
|
117
|
+
} catch (e) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
return true;
|
|
121
|
+
} || fs.existsSync || path.existsSync;
|
|
122
|
+
var defaults = {
|
|
123
|
+
arrow: process.env.NODE_BINDINGS_ARROW || " \u2192 ",
|
|
124
|
+
compiled: process.env.NODE_BINDINGS_COMPILED_DIR || "compiled",
|
|
125
|
+
platform: process.platform,
|
|
126
|
+
arch: process.arch,
|
|
127
|
+
nodePreGyp: "node-v" + process.versions.modules + "-" + process.platform + "-" + process.arch,
|
|
128
|
+
version: process.versions.node,
|
|
129
|
+
bindings: "bindings.node",
|
|
130
|
+
try: [
|
|
131
|
+
// node-gyp's linked version in the "build" dir
|
|
132
|
+
["module_root", "build", "bindings"],
|
|
133
|
+
// node-waf and gyp_addon (a.k.a node-gyp)
|
|
134
|
+
["module_root", "build", "Debug", "bindings"],
|
|
135
|
+
["module_root", "build", "Release", "bindings"],
|
|
136
|
+
// Debug files, for development (legacy behavior, remove for node v0.9)
|
|
137
|
+
["module_root", "out", "Debug", "bindings"],
|
|
138
|
+
["module_root", "Debug", "bindings"],
|
|
139
|
+
// Release files, but manually compiled (legacy behavior, remove for node v0.9)
|
|
140
|
+
["module_root", "out", "Release", "bindings"],
|
|
141
|
+
["module_root", "Release", "bindings"],
|
|
142
|
+
// Legacy from node-waf, node <= 0.4.x
|
|
143
|
+
["module_root", "build", "default", "bindings"],
|
|
144
|
+
// Production "Release" buildtype binary (meh...)
|
|
145
|
+
["module_root", "compiled", "version", "platform", "arch", "bindings"],
|
|
146
|
+
// node-qbs builds
|
|
147
|
+
["module_root", "addon-build", "release", "install-root", "bindings"],
|
|
148
|
+
["module_root", "addon-build", "debug", "install-root", "bindings"],
|
|
149
|
+
["module_root", "addon-build", "default", "install-root", "bindings"],
|
|
150
|
+
// node-pre-gyp path ./lib/binding/{node_abi}-{platform}-{arch}
|
|
151
|
+
["module_root", "lib", "binding", "nodePreGyp", "bindings"]
|
|
152
|
+
]
|
|
153
|
+
};
|
|
154
|
+
function bindings(opts) {
|
|
155
|
+
if (typeof opts == "string") {
|
|
156
|
+
opts = { bindings: opts };
|
|
157
|
+
} else if (!opts) {
|
|
158
|
+
opts = {};
|
|
159
|
+
}
|
|
160
|
+
Object.keys(defaults).map(function(i2) {
|
|
161
|
+
if (!(i2 in opts)) opts[i2] = defaults[i2];
|
|
162
|
+
});
|
|
163
|
+
if (!opts.module_root) {
|
|
164
|
+
opts.module_root = exports.getRoot(exports.getFileName());
|
|
165
|
+
}
|
|
166
|
+
if (path.extname(opts.bindings) != ".node") {
|
|
167
|
+
opts.bindings += ".node";
|
|
168
|
+
}
|
|
169
|
+
var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : __require;
|
|
170
|
+
var tries = [], i = 0, l = opts.try.length, n, b, err;
|
|
171
|
+
for (; i < l; i++) {
|
|
172
|
+
n = join.apply(
|
|
173
|
+
null,
|
|
174
|
+
opts.try[i].map(function(p) {
|
|
175
|
+
return opts[p] || p;
|
|
176
|
+
})
|
|
177
|
+
);
|
|
178
|
+
tries.push(n);
|
|
179
|
+
try {
|
|
180
|
+
b = opts.path ? requireFunc.resolve(n) : requireFunc(n);
|
|
181
|
+
if (!opts.path) {
|
|
182
|
+
b.path = n;
|
|
183
|
+
}
|
|
184
|
+
return b;
|
|
185
|
+
} catch (e) {
|
|
186
|
+
if (e.code !== "MODULE_NOT_FOUND" && e.code !== "QUALIFIED_PATH_RESOLUTION_FAILED" && !/not find/i.test(e.message)) {
|
|
187
|
+
throw e;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
err = new Error(
|
|
192
|
+
"Could not locate the bindings file. Tried:\n" + tries.map(function(a) {
|
|
193
|
+
return opts.arrow + a;
|
|
194
|
+
}).join("\n")
|
|
195
|
+
);
|
|
196
|
+
err.tries = tries;
|
|
197
|
+
throw err;
|
|
198
|
+
}
|
|
199
|
+
module.exports = exports = bindings;
|
|
200
|
+
exports.getFileName = function getFileName(calling_file) {
|
|
201
|
+
var origPST = Error.prepareStackTrace, origSTL = Error.stackTraceLimit, dummy = {}, fileName;
|
|
202
|
+
Error.stackTraceLimit = 10;
|
|
203
|
+
Error.prepareStackTrace = function(e, st) {
|
|
204
|
+
for (var i = 0, l = st.length; i < l; i++) {
|
|
205
|
+
fileName = st[i].getFileName();
|
|
206
|
+
if (fileName !== __filename) {
|
|
207
|
+
if (calling_file) {
|
|
208
|
+
if (fileName !== calling_file) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
} else {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
Error.captureStackTrace(dummy);
|
|
218
|
+
dummy.stack;
|
|
219
|
+
Error.prepareStackTrace = origPST;
|
|
220
|
+
Error.stackTraceLimit = origSTL;
|
|
221
|
+
var fileSchema = "file://";
|
|
222
|
+
if (fileName.indexOf(fileSchema) === 0) {
|
|
223
|
+
fileName = fileURLToPath(fileName);
|
|
224
|
+
}
|
|
225
|
+
return fileName;
|
|
226
|
+
};
|
|
227
|
+
exports.getRoot = function getRoot(file) {
|
|
228
|
+
var dir = dirname(file), prev;
|
|
229
|
+
while (true) {
|
|
230
|
+
if (dir === ".") {
|
|
231
|
+
dir = process.cwd();
|
|
232
|
+
}
|
|
233
|
+
if (exists(join(dir, "package.json")) || exists(join(dir, "node_modules"))) {
|
|
234
|
+
return dir;
|
|
235
|
+
}
|
|
236
|
+
if (prev === dir) {
|
|
237
|
+
throw new Error(
|
|
238
|
+
'Could not find module root given file: "' + file + '". Do you have a `package.json` file? '
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
prev = dir;
|
|
242
|
+
dir = join(dir, "..");
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
// node_modules/better-sqlite3/lib/methods/wrappers.js
|
|
249
|
+
var require_wrappers = __commonJS({
|
|
250
|
+
"node_modules/better-sqlite3/lib/methods/wrappers.js"(exports) {
|
|
251
|
+
"use strict";
|
|
252
|
+
var { cppdb } = require_util();
|
|
253
|
+
exports.prepare = function prepare(sql) {
|
|
254
|
+
return this[cppdb].prepare(sql, this, false);
|
|
255
|
+
};
|
|
256
|
+
exports.exec = function exec(sql) {
|
|
257
|
+
this[cppdb].exec(sql);
|
|
258
|
+
return this;
|
|
259
|
+
};
|
|
260
|
+
exports.close = function close() {
|
|
261
|
+
this[cppdb].close();
|
|
262
|
+
return this;
|
|
263
|
+
};
|
|
264
|
+
exports.loadExtension = function loadExtension(...args) {
|
|
265
|
+
this[cppdb].loadExtension(...args);
|
|
266
|
+
return this;
|
|
267
|
+
};
|
|
268
|
+
exports.defaultSafeIntegers = function defaultSafeIntegers(...args) {
|
|
269
|
+
this[cppdb].defaultSafeIntegers(...args);
|
|
270
|
+
return this;
|
|
271
|
+
};
|
|
272
|
+
exports.unsafeMode = function unsafeMode(...args) {
|
|
273
|
+
this[cppdb].unsafeMode(...args);
|
|
274
|
+
return this;
|
|
275
|
+
};
|
|
276
|
+
exports.getters = {
|
|
277
|
+
name: {
|
|
278
|
+
get: function name() {
|
|
279
|
+
return this[cppdb].name;
|
|
280
|
+
},
|
|
281
|
+
enumerable: true
|
|
282
|
+
},
|
|
283
|
+
open: {
|
|
284
|
+
get: function open() {
|
|
285
|
+
return this[cppdb].open;
|
|
286
|
+
},
|
|
287
|
+
enumerable: true
|
|
288
|
+
},
|
|
289
|
+
inTransaction: {
|
|
290
|
+
get: function inTransaction() {
|
|
291
|
+
return this[cppdb].inTransaction;
|
|
292
|
+
},
|
|
293
|
+
enumerable: true
|
|
294
|
+
},
|
|
295
|
+
readonly: {
|
|
296
|
+
get: function readonly() {
|
|
297
|
+
return this[cppdb].readonly;
|
|
298
|
+
},
|
|
299
|
+
enumerable: true
|
|
300
|
+
},
|
|
301
|
+
memory: {
|
|
302
|
+
get: function memory() {
|
|
303
|
+
return this[cppdb].memory;
|
|
304
|
+
},
|
|
305
|
+
enumerable: true
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
// node_modules/better-sqlite3/lib/methods/transaction.js
|
|
312
|
+
var require_transaction = __commonJS({
|
|
313
|
+
"node_modules/better-sqlite3/lib/methods/transaction.js"(exports, module) {
|
|
314
|
+
"use strict";
|
|
315
|
+
var { cppdb } = require_util();
|
|
316
|
+
var controllers = /* @__PURE__ */ new WeakMap();
|
|
317
|
+
module.exports = function transaction(fn) {
|
|
318
|
+
if (typeof fn !== "function") throw new TypeError("Expected first argument to be a function");
|
|
319
|
+
const db = this[cppdb];
|
|
320
|
+
const controller = getController(db, this);
|
|
321
|
+
const { apply } = Function.prototype;
|
|
322
|
+
const properties = {
|
|
323
|
+
default: { value: wrapTransaction(apply, fn, db, controller.default) },
|
|
324
|
+
deferred: { value: wrapTransaction(apply, fn, db, controller.deferred) },
|
|
325
|
+
immediate: { value: wrapTransaction(apply, fn, db, controller.immediate) },
|
|
326
|
+
exclusive: { value: wrapTransaction(apply, fn, db, controller.exclusive) },
|
|
327
|
+
database: { value: this, enumerable: true }
|
|
328
|
+
};
|
|
329
|
+
Object.defineProperties(properties.default.value, properties);
|
|
330
|
+
Object.defineProperties(properties.deferred.value, properties);
|
|
331
|
+
Object.defineProperties(properties.immediate.value, properties);
|
|
332
|
+
Object.defineProperties(properties.exclusive.value, properties);
|
|
333
|
+
return properties.default.value;
|
|
334
|
+
};
|
|
335
|
+
var getController = (db, self) => {
|
|
336
|
+
let controller = controllers.get(db);
|
|
337
|
+
if (!controller) {
|
|
338
|
+
const shared = {
|
|
339
|
+
commit: db.prepare("COMMIT", self, false),
|
|
340
|
+
rollback: db.prepare("ROLLBACK", self, false),
|
|
341
|
+
savepoint: db.prepare("SAVEPOINT ` _bs3. `", self, false),
|
|
342
|
+
release: db.prepare("RELEASE ` _bs3. `", self, false),
|
|
343
|
+
rollbackTo: db.prepare("ROLLBACK TO ` _bs3. `", self, false)
|
|
344
|
+
};
|
|
345
|
+
controllers.set(db, controller = {
|
|
346
|
+
default: Object.assign({ begin: db.prepare("BEGIN", self, false) }, shared),
|
|
347
|
+
deferred: Object.assign({ begin: db.prepare("BEGIN DEFERRED", self, false) }, shared),
|
|
348
|
+
immediate: Object.assign({ begin: db.prepare("BEGIN IMMEDIATE", self, false) }, shared),
|
|
349
|
+
exclusive: Object.assign({ begin: db.prepare("BEGIN EXCLUSIVE", self, false) }, shared)
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
return controller;
|
|
353
|
+
};
|
|
354
|
+
var wrapTransaction = (apply, fn, db, { begin, commit, rollback, savepoint, release, rollbackTo }) => function sqliteTransaction() {
|
|
355
|
+
let before, after, undo;
|
|
356
|
+
if (db.inTransaction) {
|
|
357
|
+
before = savepoint;
|
|
358
|
+
after = release;
|
|
359
|
+
undo = rollbackTo;
|
|
360
|
+
} else {
|
|
361
|
+
before = begin;
|
|
362
|
+
after = commit;
|
|
363
|
+
undo = rollback;
|
|
364
|
+
}
|
|
365
|
+
before.run();
|
|
366
|
+
try {
|
|
367
|
+
const result = apply.call(fn, this, arguments);
|
|
368
|
+
if (result && typeof result.then === "function") {
|
|
369
|
+
throw new TypeError("Transaction function cannot return a promise");
|
|
370
|
+
}
|
|
371
|
+
after.run();
|
|
372
|
+
return result;
|
|
373
|
+
} catch (ex) {
|
|
374
|
+
if (db.inTransaction) {
|
|
375
|
+
undo.run();
|
|
376
|
+
if (undo !== rollback) after.run();
|
|
377
|
+
}
|
|
378
|
+
throw ex;
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
// node_modules/better-sqlite3/lib/methods/pragma.js
|
|
385
|
+
var require_pragma = __commonJS({
|
|
386
|
+
"node_modules/better-sqlite3/lib/methods/pragma.js"(exports, module) {
|
|
387
|
+
"use strict";
|
|
388
|
+
var { getBooleanOption, cppdb } = require_util();
|
|
389
|
+
module.exports = function pragma(source, options) {
|
|
390
|
+
if (options == null) options = {};
|
|
391
|
+
if (typeof source !== "string") throw new TypeError("Expected first argument to be a string");
|
|
392
|
+
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
393
|
+
const simple = getBooleanOption(options, "simple");
|
|
394
|
+
const stmt = this[cppdb].prepare(`PRAGMA ${source}`, this, true);
|
|
395
|
+
return simple ? stmt.pluck().get() : stmt.all();
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
// node_modules/better-sqlite3/lib/methods/backup.js
|
|
401
|
+
var require_backup = __commonJS({
|
|
402
|
+
"node_modules/better-sqlite3/lib/methods/backup.js"(exports, module) {
|
|
403
|
+
"use strict";
|
|
404
|
+
var fs = __require("fs");
|
|
405
|
+
var path = __require("path");
|
|
406
|
+
var { promisify } = __require("util");
|
|
407
|
+
var { cppdb } = require_util();
|
|
408
|
+
var fsAccess = promisify(fs.access);
|
|
409
|
+
module.exports = async function backup(filename, options) {
|
|
410
|
+
if (options == null) options = {};
|
|
411
|
+
if (typeof filename !== "string") throw new TypeError("Expected first argument to be a string");
|
|
412
|
+
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
413
|
+
filename = filename.trim();
|
|
414
|
+
const attachedName = "attached" in options ? options.attached : "main";
|
|
415
|
+
const handler = "progress" in options ? options.progress : null;
|
|
416
|
+
if (!filename) throw new TypeError("Backup filename cannot be an empty string");
|
|
417
|
+
if (filename === ":memory:") throw new TypeError('Invalid backup filename ":memory:"');
|
|
418
|
+
if (typeof attachedName !== "string") throw new TypeError('Expected the "attached" option to be a string');
|
|
419
|
+
if (!attachedName) throw new TypeError('The "attached" option cannot be an empty string');
|
|
420
|
+
if (handler != null && typeof handler !== "function") throw new TypeError('Expected the "progress" option to be a function');
|
|
421
|
+
await fsAccess(path.dirname(filename)).catch(() => {
|
|
422
|
+
throw new TypeError("Cannot save backup because the directory does not exist");
|
|
423
|
+
});
|
|
424
|
+
const isNewFile = await fsAccess(filename).then(() => false, () => true);
|
|
425
|
+
return runBackup(this[cppdb].backup(this, attachedName, filename, isNewFile), handler || null);
|
|
426
|
+
};
|
|
427
|
+
var runBackup = (backup, handler) => {
|
|
428
|
+
let rate = 0;
|
|
429
|
+
let useDefault = true;
|
|
430
|
+
return new Promise((resolve, reject) => {
|
|
431
|
+
setImmediate(function step() {
|
|
432
|
+
try {
|
|
433
|
+
const progress = backup.transfer(rate);
|
|
434
|
+
if (!progress.remainingPages) {
|
|
435
|
+
backup.close();
|
|
436
|
+
resolve(progress);
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
if (useDefault) {
|
|
440
|
+
useDefault = false;
|
|
441
|
+
rate = 100;
|
|
442
|
+
}
|
|
443
|
+
if (handler) {
|
|
444
|
+
const ret = handler(progress);
|
|
445
|
+
if (ret !== void 0) {
|
|
446
|
+
if (typeof ret === "number" && ret === ret) rate = Math.max(0, Math.min(2147483647, Math.round(ret)));
|
|
447
|
+
else throw new TypeError("Expected progress callback to return a number or undefined");
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
setImmediate(step);
|
|
451
|
+
} catch (err) {
|
|
452
|
+
backup.close();
|
|
453
|
+
reject(err);
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
// node_modules/better-sqlite3/lib/methods/serialize.js
|
|
462
|
+
var require_serialize = __commonJS({
|
|
463
|
+
"node_modules/better-sqlite3/lib/methods/serialize.js"(exports, module) {
|
|
464
|
+
"use strict";
|
|
465
|
+
var { cppdb } = require_util();
|
|
466
|
+
module.exports = function serialize(options) {
|
|
467
|
+
if (options == null) options = {};
|
|
468
|
+
if (typeof options !== "object") throw new TypeError("Expected first argument to be an options object");
|
|
469
|
+
const attachedName = "attached" in options ? options.attached : "main";
|
|
470
|
+
if (typeof attachedName !== "string") throw new TypeError('Expected the "attached" option to be a string');
|
|
471
|
+
if (!attachedName) throw new TypeError('The "attached" option cannot be an empty string');
|
|
472
|
+
return this[cppdb].serialize(attachedName);
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
// node_modules/better-sqlite3/lib/methods/function.js
|
|
478
|
+
var require_function = __commonJS({
|
|
479
|
+
"node_modules/better-sqlite3/lib/methods/function.js"(exports, module) {
|
|
480
|
+
"use strict";
|
|
481
|
+
var { getBooleanOption, cppdb } = require_util();
|
|
482
|
+
module.exports = function defineFunction(name, options, fn) {
|
|
483
|
+
if (options == null) options = {};
|
|
484
|
+
if (typeof options === "function") {
|
|
485
|
+
fn = options;
|
|
486
|
+
options = {};
|
|
487
|
+
}
|
|
488
|
+
if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
|
|
489
|
+
if (typeof fn !== "function") throw new TypeError("Expected last argument to be a function");
|
|
490
|
+
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
491
|
+
if (!name) throw new TypeError("User-defined function name cannot be an empty string");
|
|
492
|
+
const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
|
|
493
|
+
const deterministic = getBooleanOption(options, "deterministic");
|
|
494
|
+
const directOnly = getBooleanOption(options, "directOnly");
|
|
495
|
+
const varargs = getBooleanOption(options, "varargs");
|
|
496
|
+
let argCount = -1;
|
|
497
|
+
if (!varargs) {
|
|
498
|
+
argCount = fn.length;
|
|
499
|
+
if (!Number.isInteger(argCount) || argCount < 0) throw new TypeError("Expected function.length to be a positive integer");
|
|
500
|
+
if (argCount > 100) throw new RangeError("User-defined functions cannot have more than 100 arguments");
|
|
501
|
+
}
|
|
502
|
+
this[cppdb].function(fn, name, argCount, safeIntegers, deterministic, directOnly);
|
|
503
|
+
return this;
|
|
504
|
+
};
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
// node_modules/better-sqlite3/lib/methods/aggregate.js
|
|
509
|
+
var require_aggregate = __commonJS({
|
|
510
|
+
"node_modules/better-sqlite3/lib/methods/aggregate.js"(exports, module) {
|
|
511
|
+
"use strict";
|
|
512
|
+
var { getBooleanOption, cppdb } = require_util();
|
|
513
|
+
module.exports = function defineAggregate(name, options) {
|
|
514
|
+
if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
|
|
515
|
+
if (typeof options !== "object" || options === null) throw new TypeError("Expected second argument to be an options object");
|
|
516
|
+
if (!name) throw new TypeError("User-defined function name cannot be an empty string");
|
|
517
|
+
const start = "start" in options ? options.start : null;
|
|
518
|
+
const step = getFunctionOption(options, "step", true);
|
|
519
|
+
const inverse = getFunctionOption(options, "inverse", false);
|
|
520
|
+
const result = getFunctionOption(options, "result", false);
|
|
521
|
+
const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
|
|
522
|
+
const deterministic = getBooleanOption(options, "deterministic");
|
|
523
|
+
const directOnly = getBooleanOption(options, "directOnly");
|
|
524
|
+
const varargs = getBooleanOption(options, "varargs");
|
|
525
|
+
let argCount = -1;
|
|
526
|
+
if (!varargs) {
|
|
527
|
+
argCount = Math.max(getLength(step), inverse ? getLength(inverse) : 0);
|
|
528
|
+
if (argCount > 0) argCount -= 1;
|
|
529
|
+
if (argCount > 100) throw new RangeError("User-defined functions cannot have more than 100 arguments");
|
|
530
|
+
}
|
|
531
|
+
this[cppdb].aggregate(start, step, inverse, result, name, argCount, safeIntegers, deterministic, directOnly);
|
|
532
|
+
return this;
|
|
533
|
+
};
|
|
534
|
+
var getFunctionOption = (options, key, required) => {
|
|
535
|
+
const value = key in options ? options[key] : null;
|
|
536
|
+
if (typeof value === "function") return value;
|
|
537
|
+
if (value != null) throw new TypeError(`Expected the "${key}" option to be a function`);
|
|
538
|
+
if (required) throw new TypeError(`Missing required option "${key}"`);
|
|
539
|
+
return null;
|
|
540
|
+
};
|
|
541
|
+
var getLength = ({ length }) => {
|
|
542
|
+
if (Number.isInteger(length) && length >= 0) return length;
|
|
543
|
+
throw new TypeError("Expected function.length to be a positive integer");
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
// node_modules/better-sqlite3/lib/methods/table.js
|
|
549
|
+
var require_table = __commonJS({
|
|
550
|
+
"node_modules/better-sqlite3/lib/methods/table.js"(exports, module) {
|
|
551
|
+
"use strict";
|
|
552
|
+
var { cppdb } = require_util();
|
|
553
|
+
module.exports = function defineTable(name, factory) {
|
|
554
|
+
if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
|
|
555
|
+
if (!name) throw new TypeError("Virtual table module name cannot be an empty string");
|
|
556
|
+
let eponymous = false;
|
|
557
|
+
if (typeof factory === "object" && factory !== null) {
|
|
558
|
+
eponymous = true;
|
|
559
|
+
factory = defer(parseTableDefinition(factory, "used", name));
|
|
560
|
+
} else {
|
|
561
|
+
if (typeof factory !== "function") throw new TypeError("Expected second argument to be a function or a table definition object");
|
|
562
|
+
factory = wrapFactory(factory);
|
|
563
|
+
}
|
|
564
|
+
this[cppdb].table(factory, name, eponymous);
|
|
565
|
+
return this;
|
|
566
|
+
};
|
|
567
|
+
function wrapFactory(factory) {
|
|
568
|
+
return function virtualTableFactory(moduleName, databaseName, tableName, ...args) {
|
|
569
|
+
const thisObject = {
|
|
570
|
+
module: moduleName,
|
|
571
|
+
database: databaseName,
|
|
572
|
+
table: tableName
|
|
573
|
+
};
|
|
574
|
+
const def = apply.call(factory, thisObject, args);
|
|
575
|
+
if (typeof def !== "object" || def === null) {
|
|
576
|
+
throw new TypeError(`Virtual table module "${moduleName}" did not return a table definition object`);
|
|
577
|
+
}
|
|
578
|
+
return parseTableDefinition(def, "returned", moduleName);
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
function parseTableDefinition(def, verb, moduleName) {
|
|
582
|
+
if (!hasOwnProperty.call(def, "rows")) {
|
|
583
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "rows" property`);
|
|
584
|
+
}
|
|
585
|
+
if (!hasOwnProperty.call(def, "columns")) {
|
|
586
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "columns" property`);
|
|
587
|
+
}
|
|
588
|
+
const rows = def.rows;
|
|
589
|
+
if (typeof rows !== "function" || Object.getPrototypeOf(rows) !== GeneratorFunctionPrototype) {
|
|
590
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "rows" property (should be a generator function)`);
|
|
591
|
+
}
|
|
592
|
+
let columns = def.columns;
|
|
593
|
+
if (!Array.isArray(columns) || !(columns = [...columns]).every((x) => typeof x === "string")) {
|
|
594
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "columns" property (should be an array of strings)`);
|
|
595
|
+
}
|
|
596
|
+
if (columns.length !== new Set(columns).size) {
|
|
597
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate column names`);
|
|
598
|
+
}
|
|
599
|
+
if (!columns.length) {
|
|
600
|
+
throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with zero columns`);
|
|
601
|
+
}
|
|
602
|
+
let parameters;
|
|
603
|
+
if (hasOwnProperty.call(def, "parameters")) {
|
|
604
|
+
parameters = def.parameters;
|
|
605
|
+
if (!Array.isArray(parameters) || !(parameters = [...parameters]).every((x) => typeof x === "string")) {
|
|
606
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "parameters" property (should be an array of strings)`);
|
|
607
|
+
}
|
|
608
|
+
} else {
|
|
609
|
+
parameters = inferParameters(rows);
|
|
610
|
+
}
|
|
611
|
+
if (parameters.length !== new Set(parameters).size) {
|
|
612
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate parameter names`);
|
|
613
|
+
}
|
|
614
|
+
if (parameters.length > 32) {
|
|
615
|
+
throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with more than the maximum number of 32 parameters`);
|
|
616
|
+
}
|
|
617
|
+
for (const parameter of parameters) {
|
|
618
|
+
if (columns.includes(parameter)) {
|
|
619
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with column "${parameter}" which was ambiguously defined as both a column and parameter`);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
let safeIntegers = 2;
|
|
623
|
+
if (hasOwnProperty.call(def, "safeIntegers")) {
|
|
624
|
+
const bool = def.safeIntegers;
|
|
625
|
+
if (typeof bool !== "boolean") {
|
|
626
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "safeIntegers" property (should be a boolean)`);
|
|
627
|
+
}
|
|
628
|
+
safeIntegers = +bool;
|
|
629
|
+
}
|
|
630
|
+
let directOnly = false;
|
|
631
|
+
if (hasOwnProperty.call(def, "directOnly")) {
|
|
632
|
+
directOnly = def.directOnly;
|
|
633
|
+
if (typeof directOnly !== "boolean") {
|
|
634
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "directOnly" property (should be a boolean)`);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
const columnDefinitions = [
|
|
638
|
+
...parameters.map(identifier).map((str) => `${str} HIDDEN`),
|
|
639
|
+
...columns.map(identifier)
|
|
640
|
+
];
|
|
641
|
+
return [
|
|
642
|
+
`CREATE TABLE x(${columnDefinitions.join(", ")});`,
|
|
643
|
+
wrapGenerator(rows, new Map(columns.map((x, i) => [x, parameters.length + i])), moduleName),
|
|
644
|
+
parameters,
|
|
645
|
+
safeIntegers,
|
|
646
|
+
directOnly
|
|
647
|
+
];
|
|
648
|
+
}
|
|
649
|
+
function wrapGenerator(generator, columnMap, moduleName) {
|
|
650
|
+
return function* virtualTable(...args) {
|
|
651
|
+
const output = args.map((x) => Buffer.isBuffer(x) ? Buffer.from(x) : x);
|
|
652
|
+
for (let i = 0; i < columnMap.size; ++i) {
|
|
653
|
+
output.push(null);
|
|
654
|
+
}
|
|
655
|
+
for (const row of generator(...args)) {
|
|
656
|
+
if (Array.isArray(row)) {
|
|
657
|
+
extractRowArray(row, output, columnMap.size, moduleName);
|
|
658
|
+
yield output;
|
|
659
|
+
} else if (typeof row === "object" && row !== null) {
|
|
660
|
+
extractRowObject(row, output, columnMap, moduleName);
|
|
661
|
+
yield output;
|
|
662
|
+
} else {
|
|
663
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded something that isn't a valid row object`);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
function extractRowArray(row, output, columnCount, moduleName) {
|
|
669
|
+
if (row.length !== columnCount) {
|
|
670
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an incorrect number of columns`);
|
|
671
|
+
}
|
|
672
|
+
const offset = output.length - columnCount;
|
|
673
|
+
for (let i = 0; i < columnCount; ++i) {
|
|
674
|
+
output[i + offset] = row[i];
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
function extractRowObject(row, output, columnMap, moduleName) {
|
|
678
|
+
let count = 0;
|
|
679
|
+
for (const key of Object.keys(row)) {
|
|
680
|
+
const index = columnMap.get(key);
|
|
681
|
+
if (index === void 0) {
|
|
682
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an undeclared column "${key}"`);
|
|
683
|
+
}
|
|
684
|
+
output[index] = row[key];
|
|
685
|
+
count += 1;
|
|
686
|
+
}
|
|
687
|
+
if (count !== columnMap.size) {
|
|
688
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with missing columns`);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
function inferParameters({ length }) {
|
|
692
|
+
if (!Number.isInteger(length) || length < 0) {
|
|
693
|
+
throw new TypeError("Expected function.length to be a positive integer");
|
|
694
|
+
}
|
|
695
|
+
const params = [];
|
|
696
|
+
for (let i = 0; i < length; ++i) {
|
|
697
|
+
params.push(`$${i + 1}`);
|
|
698
|
+
}
|
|
699
|
+
return params;
|
|
700
|
+
}
|
|
701
|
+
var { hasOwnProperty } = Object.prototype;
|
|
702
|
+
var { apply } = Function.prototype;
|
|
703
|
+
var GeneratorFunctionPrototype = Object.getPrototypeOf(function* () {
|
|
704
|
+
});
|
|
705
|
+
var identifier = (str) => `"${str.replace(/"/g, '""')}"`;
|
|
706
|
+
var defer = (x) => () => x;
|
|
707
|
+
}
|
|
708
|
+
});
|
|
709
|
+
|
|
710
|
+
// node_modules/better-sqlite3/lib/methods/inspect.js
|
|
711
|
+
var require_inspect = __commonJS({
|
|
712
|
+
"node_modules/better-sqlite3/lib/methods/inspect.js"(exports, module) {
|
|
713
|
+
"use strict";
|
|
714
|
+
var DatabaseInspection = function Database() {
|
|
715
|
+
};
|
|
716
|
+
module.exports = function inspect(depth, opts) {
|
|
717
|
+
return Object.assign(new DatabaseInspection(), this);
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
});
|
|
721
|
+
|
|
722
|
+
// node_modules/better-sqlite3/lib/database.js
|
|
723
|
+
var require_database = __commonJS({
|
|
724
|
+
"node_modules/better-sqlite3/lib/database.js"(exports, module) {
|
|
725
|
+
"use strict";
|
|
726
|
+
var fs = __require("fs");
|
|
727
|
+
var path = __require("path");
|
|
728
|
+
var util = require_util();
|
|
729
|
+
var SqliteError = require_sqlite_error();
|
|
730
|
+
var DEFAULT_ADDON;
|
|
731
|
+
function Database(filenameGiven, options) {
|
|
732
|
+
if (new.target == null) {
|
|
733
|
+
return new Database(filenameGiven, options);
|
|
734
|
+
}
|
|
735
|
+
let buffer;
|
|
736
|
+
if (Buffer.isBuffer(filenameGiven)) {
|
|
737
|
+
buffer = filenameGiven;
|
|
738
|
+
filenameGiven = ":memory:";
|
|
739
|
+
}
|
|
740
|
+
if (filenameGiven == null) filenameGiven = "";
|
|
741
|
+
if (options == null) options = {};
|
|
742
|
+
if (typeof filenameGiven !== "string") throw new TypeError("Expected first argument to be a string");
|
|
743
|
+
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
744
|
+
if ("readOnly" in options) throw new TypeError('Misspelled option "readOnly" should be "readonly"');
|
|
745
|
+
if ("memory" in options) throw new TypeError('Option "memory" was removed in v7.0.0 (use ":memory:" filename instead)');
|
|
746
|
+
const filename = filenameGiven.trim();
|
|
747
|
+
const anonymous = filename === "" || filename === ":memory:";
|
|
748
|
+
const readonly = util.getBooleanOption(options, "readonly");
|
|
749
|
+
const fileMustExist = util.getBooleanOption(options, "fileMustExist");
|
|
750
|
+
const timeout = "timeout" in options ? options.timeout : 5e3;
|
|
751
|
+
const verbose = "verbose" in options ? options.verbose : null;
|
|
752
|
+
const nativeBinding = "nativeBinding" in options ? options.nativeBinding : null;
|
|
753
|
+
if (readonly && anonymous && !buffer) throw new TypeError("In-memory/temporary databases cannot be readonly");
|
|
754
|
+
if (!Number.isInteger(timeout) || timeout < 0) throw new TypeError('Expected the "timeout" option to be a positive integer');
|
|
755
|
+
if (timeout > 2147483647) throw new RangeError('Option "timeout" cannot be greater than 2147483647');
|
|
756
|
+
if (verbose != null && typeof verbose !== "function") throw new TypeError('Expected the "verbose" option to be a function');
|
|
757
|
+
if (nativeBinding != null && typeof nativeBinding !== "string" && typeof nativeBinding !== "object") throw new TypeError('Expected the "nativeBinding" option to be a string or addon object');
|
|
758
|
+
let addon;
|
|
759
|
+
if (nativeBinding == null) {
|
|
760
|
+
addon = DEFAULT_ADDON || (DEFAULT_ADDON = require_bindings()("better_sqlite3.node"));
|
|
761
|
+
} else if (typeof nativeBinding === "string") {
|
|
762
|
+
const requireFunc = typeof __non_webpack_require__ === "function" ? __non_webpack_require__ : __require;
|
|
763
|
+
addon = requireFunc(path.resolve(nativeBinding).replace(/(\.node)?$/, ".node"));
|
|
764
|
+
} else {
|
|
765
|
+
addon = nativeBinding;
|
|
766
|
+
}
|
|
767
|
+
if (!addon.isInitialized) {
|
|
768
|
+
addon.setErrorConstructor(SqliteError);
|
|
769
|
+
addon.isInitialized = true;
|
|
770
|
+
}
|
|
771
|
+
if (!anonymous && !filename.startsWith("file:") && !fs.existsSync(path.dirname(filename))) {
|
|
772
|
+
throw new TypeError("Cannot open database because the directory does not exist");
|
|
773
|
+
}
|
|
774
|
+
Object.defineProperties(this, {
|
|
775
|
+
[util.cppdb]: { value: new addon.Database(filename, filenameGiven, anonymous, readonly, fileMustExist, timeout, verbose || null, buffer || null) },
|
|
776
|
+
...wrappers.getters
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
var wrappers = require_wrappers();
|
|
780
|
+
Database.prototype.prepare = wrappers.prepare;
|
|
781
|
+
Database.prototype.transaction = require_transaction();
|
|
782
|
+
Database.prototype.pragma = require_pragma();
|
|
783
|
+
Database.prototype.backup = require_backup();
|
|
784
|
+
Database.prototype.serialize = require_serialize();
|
|
785
|
+
Database.prototype.function = require_function();
|
|
786
|
+
Database.prototype.aggregate = require_aggregate();
|
|
787
|
+
Database.prototype.table = require_table();
|
|
788
|
+
Database.prototype.loadExtension = wrappers.loadExtension;
|
|
789
|
+
Database.prototype.exec = wrappers.exec;
|
|
790
|
+
Database.prototype.close = wrappers.close;
|
|
791
|
+
Database.prototype.defaultSafeIntegers = wrappers.defaultSafeIntegers;
|
|
792
|
+
Database.prototype.unsafeMode = wrappers.unsafeMode;
|
|
793
|
+
Database.prototype[util.inspect] = require_inspect();
|
|
794
|
+
module.exports = Database;
|
|
795
|
+
}
|
|
796
|
+
});
|
|
797
|
+
|
|
798
|
+
// node_modules/better-sqlite3/lib/index.js
|
|
799
|
+
var require_lib = __commonJS({
|
|
800
|
+
"node_modules/better-sqlite3/lib/index.js"(exports, module) {
|
|
801
|
+
"use strict";
|
|
802
|
+
module.exports = require_database();
|
|
803
|
+
module.exports.SqliteError = require_sqlite_error();
|
|
804
|
+
}
|
|
805
|
+
});
|
|
806
|
+
|
|
1
807
|
// src/server/database/connection.ts
|
|
2
808
|
import { randomUUID } from "crypto";
|
|
3
809
|
|
|
@@ -488,47 +1294,66 @@ async function createMysqlDriver(config) {
|
|
|
488
1294
|
"MySQL driver (mysql2) is not installed. Run: npm install mysql2"
|
|
489
1295
|
);
|
|
490
1296
|
}
|
|
491
|
-
let
|
|
1297
|
+
let pool = null;
|
|
492
1298
|
const dialect = new MysqlDialect();
|
|
493
1299
|
const driver = {
|
|
494
1300
|
async connect() {
|
|
495
|
-
|
|
1301
|
+
pool = mysqlPackage.createPool({
|
|
496
1302
|
host: config.host ?? "127.0.0.1",
|
|
497
1303
|
port: config.port ?? 3306,
|
|
498
1304
|
user: config.username,
|
|
499
1305
|
password: config.password,
|
|
500
1306
|
database: config.database,
|
|
501
|
-
charset: config.charset ?? "utf8mb4"
|
|
1307
|
+
charset: config.charset ?? "utf8mb4",
|
|
1308
|
+
waitForConnections: true,
|
|
1309
|
+
connectionLimit: 10,
|
|
1310
|
+
queueLimit: 0
|
|
502
1311
|
});
|
|
1312
|
+
const conn = await pool.getConnection();
|
|
1313
|
+
conn.release();
|
|
503
1314
|
},
|
|
504
1315
|
async disconnect() {
|
|
505
|
-
if (
|
|
506
|
-
await
|
|
507
|
-
|
|
1316
|
+
if (pool !== null) {
|
|
1317
|
+
await pool.end();
|
|
1318
|
+
pool = null;
|
|
508
1319
|
}
|
|
509
1320
|
},
|
|
510
1321
|
isConnected() {
|
|
511
|
-
return
|
|
1322
|
+
return pool !== null;
|
|
512
1323
|
},
|
|
513
1324
|
async raw(sql, bindings) {
|
|
514
|
-
if (
|
|
1325
|
+
if (pool === null) {
|
|
515
1326
|
throw new Error("Database not connected. Call connect() first.");
|
|
516
1327
|
}
|
|
517
|
-
const [rows, fields] = await
|
|
1328
|
+
const [rows, fields] = await pool.execute(sql, bindings ?? []);
|
|
518
1329
|
return { rows, fields };
|
|
519
1330
|
},
|
|
520
1331
|
async transaction(callback) {
|
|
521
|
-
if (
|
|
522
|
-
|
|
523
|
-
}
|
|
524
|
-
await connection.beginTransaction();
|
|
1332
|
+
if (pool === null) throw new Error("Database not connected.");
|
|
1333
|
+
const conn = await pool.getConnection();
|
|
525
1334
|
try {
|
|
526
|
-
|
|
527
|
-
|
|
1335
|
+
await conn.beginTransaction();
|
|
1336
|
+
const trxDriver = {
|
|
1337
|
+
...driver,
|
|
1338
|
+
async raw(sql, bindings) {
|
|
1339
|
+
const [rows, fields] = await conn.execute(sql, bindings ?? []);
|
|
1340
|
+
return { rows, fields };
|
|
1341
|
+
},
|
|
1342
|
+
getDialect() {
|
|
1343
|
+
return dialect;
|
|
1344
|
+
},
|
|
1345
|
+
getDriver() {
|
|
1346
|
+
return "mysql";
|
|
1347
|
+
}
|
|
1348
|
+
};
|
|
1349
|
+
const result = await callback(trxDriver);
|
|
1350
|
+
await conn.commit();
|
|
528
1351
|
return result;
|
|
529
1352
|
} catch (err) {
|
|
530
|
-
await
|
|
1353
|
+
await conn.rollback();
|
|
531
1354
|
throw err;
|
|
1355
|
+
} finally {
|
|
1356
|
+
conn.release();
|
|
532
1357
|
}
|
|
533
1358
|
},
|
|
534
1359
|
getDialect() {
|
|
@@ -621,7 +1446,7 @@ async function createPostgresqlDriver(config) {
|
|
|
621
1446
|
async function createSqliteDriver(config) {
|
|
622
1447
|
let sqlitePackage;
|
|
623
1448
|
try {
|
|
624
|
-
sqlitePackage = await
|
|
1449
|
+
sqlitePackage = await Promise.resolve().then(() => __toESM(require_lib(), 1));
|
|
625
1450
|
} catch {
|
|
626
1451
|
throw new Error(
|
|
627
1452
|
"SQLite driver (better-sqlite3) is not installed. Run: npm install better-sqlite3"
|
|
@@ -668,10 +1493,15 @@ async function createSqliteDriver(config) {
|
|
|
668
1493
|
if (db === null) {
|
|
669
1494
|
throw new Error("Database not connected. Call connect() first.");
|
|
670
1495
|
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
1496
|
+
db.exec("BEGIN");
|
|
1497
|
+
try {
|
|
1498
|
+
const result = await callback(driver);
|
|
1499
|
+
db.exec("COMMIT");
|
|
1500
|
+
return result;
|
|
1501
|
+
} catch (err) {
|
|
1502
|
+
db.exec("ROLLBACK");
|
|
1503
|
+
throw err;
|
|
1504
|
+
}
|
|
675
1505
|
},
|
|
676
1506
|
getDialect() {
|
|
677
1507
|
return dialect;
|
|
@@ -938,15 +1768,30 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
938
1768
|
async insert(data) {
|
|
939
1769
|
const { sql, bindings } = this.compileInsert(data);
|
|
940
1770
|
const driverType = this.connection.getDriver();
|
|
1771
|
+
const dialect = this.connection.getDialect();
|
|
941
1772
|
if (driverType === "postgresql") {
|
|
942
|
-
const dialect = this.connection.getDialect();
|
|
943
1773
|
const returningSQL = dialect.compileInsertReturning(sql, bindings);
|
|
944
1774
|
const result2 = await this.connection.raw(returningSQL, bindings);
|
|
945
1775
|
return result2.rows.length > 0 ? Number(result2.rows[0].id) ?? 0 : 0;
|
|
946
1776
|
}
|
|
947
1777
|
const result = await this.connection.raw(sql, bindings);
|
|
948
|
-
if (
|
|
949
|
-
|
|
1778
|
+
if (driverType === "mysql") {
|
|
1779
|
+
const header = result.rows;
|
|
1780
|
+
if (header && typeof header === "object" && "insertId" in header) {
|
|
1781
|
+
return Number(header.insertId) ?? 0;
|
|
1782
|
+
}
|
|
1783
|
+
if (Array.isArray(result.rows) && result.rows.length > 0) {
|
|
1784
|
+
const row = result.rows[0];
|
|
1785
|
+
return Number(row?.insertId ?? row?.id ?? 0);
|
|
1786
|
+
}
|
|
1787
|
+
return 0;
|
|
1788
|
+
}
|
|
1789
|
+
if (driverType === "sqlite") {
|
|
1790
|
+
const lastIdResult = await this.connection.raw("SELECT last_insert_rowid() as id");
|
|
1791
|
+
if (lastIdResult.rows.length > 0) {
|
|
1792
|
+
return Number(lastIdResult.rows[0].id) ?? 0;
|
|
1793
|
+
}
|
|
1794
|
+
return 0;
|
|
950
1795
|
}
|
|
951
1796
|
return 0;
|
|
952
1797
|
}
|
|
@@ -1055,7 +1900,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
1055
1900
|
const output = `SQL: ${sql}
|
|
1056
1901
|
Bindings: ${JSON.stringify(bindings)}`;
|
|
1057
1902
|
console.error(output);
|
|
1058
|
-
|
|
1903
|
+
return output;
|
|
1059
1904
|
}
|
|
1060
1905
|
compileJoins(dialect) {
|
|
1061
1906
|
if (this.joins.length === 0) return "";
|
|
@@ -1077,7 +1922,11 @@ Bindings: ${JSON.stringify(bindings)}`;
|
|
|
1077
1922
|
if (sql !== null) parts.push(sql);
|
|
1078
1923
|
}
|
|
1079
1924
|
if (parts.length === 0) return "";
|
|
1080
|
-
return parts.
|
|
1925
|
+
return parts.reduce((acc, part, i) => {
|
|
1926
|
+
if (i === 0) return part;
|
|
1927
|
+
const bool = wheres[i]?.boolean ?? "and";
|
|
1928
|
+
return `${acc} ${bool.toUpperCase()} ${part}`;
|
|
1929
|
+
}, "");
|
|
1081
1930
|
}
|
|
1082
1931
|
compileSingleWhere(w, dialect, bindings) {
|
|
1083
1932
|
const col = w.column ? dialect.wrapIdentifier(w.column) : "";
|
|
@@ -1126,15 +1975,18 @@ Bindings: ${JSON.stringify(bindings)}`;
|
|
|
1126
1975
|
}
|
|
1127
1976
|
}
|
|
1128
1977
|
compileNestedWhere(wheres, dialect, bindings) {
|
|
1978
|
+
if (wheres.length === 0) return "";
|
|
1129
1979
|
const parts = [];
|
|
1130
1980
|
for (const w of wheres) {
|
|
1131
1981
|
const sql = this.compileSingleWhere(w, dialect, bindings);
|
|
1132
|
-
if (sql !== null)
|
|
1133
|
-
parts.push(sql);
|
|
1134
|
-
}
|
|
1982
|
+
if (sql !== null) parts.push(sql);
|
|
1135
1983
|
}
|
|
1136
1984
|
if (parts.length === 0) return "";
|
|
1137
|
-
return parts.
|
|
1985
|
+
return parts.reduce((acc, part, i) => {
|
|
1986
|
+
if (i === 0) return part;
|
|
1987
|
+
const bool = wheres[i]?.boolean ?? "and";
|
|
1988
|
+
return `${acc} ${bool.toUpperCase()} ${part}`;
|
|
1989
|
+
}, "");
|
|
1138
1990
|
}
|
|
1139
1991
|
compileHavings(dialect, bindings) {
|
|
1140
1992
|
if (this.havings.length === 0) return "";
|
|
@@ -1958,11 +2810,122 @@ var Seeder = class {
|
|
|
1958
2810
|
throw new Error("Seeder.run() must be overridden by subclasses");
|
|
1959
2811
|
}
|
|
1960
2812
|
};
|
|
2813
|
+
|
|
2814
|
+
// src/server/database/model.ts
|
|
2815
|
+
var Model = class {
|
|
2816
|
+
id;
|
|
2817
|
+
static table = "";
|
|
2818
|
+
static connection = null;
|
|
2819
|
+
static queryRunner = null;
|
|
2820
|
+
static setConnection(conn) {
|
|
2821
|
+
this.connection = conn;
|
|
2822
|
+
this.queryRunner = conn;
|
|
2823
|
+
}
|
|
2824
|
+
static query() {
|
|
2825
|
+
if (!this.queryRunner) {
|
|
2826
|
+
throw new Error("Database connection not set. Call Model.setConnection() first.");
|
|
2827
|
+
}
|
|
2828
|
+
return new QueryBuilder(this.queryRunner, this.table);
|
|
2829
|
+
}
|
|
2830
|
+
static async all() {
|
|
2831
|
+
const rows = await this.query().get();
|
|
2832
|
+
return rows.map((row) => this.hydrate(row));
|
|
2833
|
+
}
|
|
2834
|
+
static async find(id) {
|
|
2835
|
+
const row = await this.query().find(id);
|
|
2836
|
+
if (!row) return null;
|
|
2837
|
+
return this.hydrate(row);
|
|
2838
|
+
}
|
|
2839
|
+
static async where(column, value) {
|
|
2840
|
+
return this.query().where(column, value);
|
|
2841
|
+
}
|
|
2842
|
+
static async create(data) {
|
|
2843
|
+
const id = await this.query().insert(data);
|
|
2844
|
+
return this.find(id);
|
|
2845
|
+
}
|
|
2846
|
+
static async updateOrCreate(attributes, values) {
|
|
2847
|
+
const qb = this.query();
|
|
2848
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
2849
|
+
qb.where(key, value);
|
|
2850
|
+
}
|
|
2851
|
+
const existing = await qb.first();
|
|
2852
|
+
if (existing) {
|
|
2853
|
+
const mergeValues = values ?? attributes;
|
|
2854
|
+
const id = existing.id;
|
|
2855
|
+
const updateQb = new QueryBuilder(this.queryRunner, this.table);
|
|
2856
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
2857
|
+
updateQb.where(key, value);
|
|
2858
|
+
}
|
|
2859
|
+
await updateQb.update(mergeValues);
|
|
2860
|
+
return this.find(id);
|
|
2861
|
+
}
|
|
2862
|
+
return this.create({ ...attributes, ...values });
|
|
2863
|
+
}
|
|
2864
|
+
async save() {
|
|
2865
|
+
const ModelClass = this.constructor;
|
|
2866
|
+
const id = this.id;
|
|
2867
|
+
if (id !== void 0 && id !== null) {
|
|
2868
|
+
await ModelClass.query().where("id", id).update(this.getData());
|
|
2869
|
+
} else {
|
|
2870
|
+
const newId = await ModelClass.query().insert(this.getData());
|
|
2871
|
+
this.id = newId;
|
|
2872
|
+
}
|
|
2873
|
+
}
|
|
2874
|
+
async delete() {
|
|
2875
|
+
const ModelClass = this.constructor;
|
|
2876
|
+
const id = this.id;
|
|
2877
|
+
if (id !== void 0 && id !== null) {
|
|
2878
|
+
await ModelClass.query().where("id", id).delete();
|
|
2879
|
+
}
|
|
2880
|
+
}
|
|
2881
|
+
static belongsTo(relatedModel, foreignKey, ownerKey) {
|
|
2882
|
+
const related = relatedModel.table;
|
|
2883
|
+
const fk = foreignKey ?? `${related}_id`;
|
|
2884
|
+
const ok = ownerKey ?? "id";
|
|
2885
|
+
return this.query().where(fk, ok);
|
|
2886
|
+
}
|
|
2887
|
+
static hasMany(relatedModel, foreignKey, localKey) {
|
|
2888
|
+
const related = relatedModel.table;
|
|
2889
|
+
const fk = foreignKey ?? `${this.table}_id`;
|
|
2890
|
+
const lk = localKey ?? "id";
|
|
2891
|
+
return this.query().join(related, fk, "=", lk);
|
|
2892
|
+
}
|
|
2893
|
+
static hydrate(data) {
|
|
2894
|
+
const instance = new this();
|
|
2895
|
+
for (const [key, value] of Object.entries(data)) {
|
|
2896
|
+
;
|
|
2897
|
+
instance[key] = value;
|
|
2898
|
+
}
|
|
2899
|
+
return instance;
|
|
2900
|
+
}
|
|
2901
|
+
getData() {
|
|
2902
|
+
const data = {};
|
|
2903
|
+
const instance = this;
|
|
2904
|
+
const prototype = Object.getPrototypeOf(this);
|
|
2905
|
+
const ownKeys = [
|
|
2906
|
+
...Object.getOwnPropertyNames(instance),
|
|
2907
|
+
...Object.keys(instance)
|
|
2908
|
+
];
|
|
2909
|
+
const classKeys = /* @__PURE__ */ new Set([
|
|
2910
|
+
...Object.getOwnPropertyNames(prototype),
|
|
2911
|
+
"save",
|
|
2912
|
+
"delete",
|
|
2913
|
+
"getData"
|
|
2914
|
+
]);
|
|
2915
|
+
for (const key of ownKeys) {
|
|
2916
|
+
if (typeof key === "string" && !classKeys.has(key) && key !== "constructor") {
|
|
2917
|
+
data[key] = instance[key];
|
|
2918
|
+
}
|
|
2919
|
+
}
|
|
2920
|
+
return data;
|
|
2921
|
+
}
|
|
2922
|
+
};
|
|
1961
2923
|
export {
|
|
1962
2924
|
ColumnDefinition,
|
|
1963
2925
|
DatabaseConnection,
|
|
1964
2926
|
ForeignKeyDefinition,
|
|
1965
2927
|
Migrator,
|
|
2928
|
+
Model,
|
|
1966
2929
|
MysqlDialect,
|
|
1967
2930
|
Pagination,
|
|
1968
2931
|
PostgresqlDialect,
|