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
package/dist/index.js
CHANGED
|
@@ -1,61 +1,810 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
string_regex: "Format tidak sesuai dengan pola yang diharapkan",
|
|
24
|
-
string_includes: 'Teks harus mengandung "{substring}"',
|
|
25
|
-
string_starts_with: 'Teks harus diawali dengan "{prefix}"',
|
|
26
|
-
string_ends_with: 'Teks harus diakhiri dengan "{suffix}"',
|
|
27
|
-
number_min: "Nilai minimal {min}",
|
|
28
|
-
number_max: "Nilai maksimal {max}",
|
|
29
|
-
number_int: "Nilai harus bilangan bulat",
|
|
30
|
-
number_positive: "Nilai harus positif",
|
|
31
|
-
number_negative: "Nilai harus negatif",
|
|
32
|
-
number_finite: "Nilai harus terbatas (finite)",
|
|
33
|
-
number_safe: "Nilai harus dalam batas safe integer",
|
|
34
|
-
array_min: "Panjang array minimal {min}",
|
|
35
|
-
array_max: "Panjang array maksimal {max}",
|
|
36
|
-
array_length: "Panjang array harus tepat {length}",
|
|
37
|
-
array_nonempty: "Array tidak boleh kosong",
|
|
38
|
-
array_unique: "Semua elemen array harus unik",
|
|
39
|
-
object_strict: 'Key "{key}" tidak dikenal',
|
|
40
|
-
enum_invalid: "Nilai harus salah satu dari: {values}",
|
|
41
|
-
tuple_length: "Tuple harus memiliki tepat {length} elemen",
|
|
42
|
-
union_fail: "Nilai tidak cocok dengan skema apapun",
|
|
43
|
-
intersection_fail: "Nilai tidak cocok dengan interseksi skema",
|
|
44
|
-
literal_fail: "Nilai harus tepat {expected}",
|
|
45
|
-
refine_fail: "{message}",
|
|
46
|
-
date_invalid: "Tanggal tidak valid",
|
|
47
|
-
date_not_date: "Nilai harus berupa tanggal yang valid",
|
|
48
|
-
indonesia_nik: "NIK harus 16 digit dan memenuhi format yang valid",
|
|
49
|
-
indonesia_npwp: "NPWP tidak valid",
|
|
50
|
-
indonesia_phone: "Nomor telepon Indonesia tidak valid",
|
|
51
|
-
indonesia_alamat: "Alamat tidak valid (minimal 10 karakter, harus mengandung unsur jalan/RT/RW)",
|
|
52
|
-
indonesia_kodepos: "Kode pos harus 5 digit angka",
|
|
53
|
-
indonesia_rekening: "Nomor rekening harus 10-16 digit angka",
|
|
54
|
-
coerce_number_fail: "Nilai tidak dapat dikonversi menjadi angka",
|
|
55
|
-
coerce_date_fail: "Nilai tidak dapat dikonversi menjadi tanggal",
|
|
56
|
-
map_not_map: "Nilai harus berupa Map",
|
|
57
|
-
set_not_set: "Nilai harus berupa Set"
|
|
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;
|
|
58
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 path3 = rest.substring(firstSlash + 1);
|
|
88
|
+
if ("localhost" == host) host = "";
|
|
89
|
+
if (host) {
|
|
90
|
+
host = sep + sep + host;
|
|
91
|
+
}
|
|
92
|
+
path3 = path3.replace(/^(.+)\|/, "$1:");
|
|
93
|
+
if (sep == "\\") {
|
|
94
|
+
path3 = path3.replace(/\//g, "\\");
|
|
95
|
+
}
|
|
96
|
+
if (/^.+\:/.test(path3)) {
|
|
97
|
+
} else {
|
|
98
|
+
path3 = sep + path3;
|
|
99
|
+
}
|
|
100
|
+
return host + path3;
|
|
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 fs3 = __require("fs");
|
|
110
|
+
var path3 = __require("path");
|
|
111
|
+
var fileURLToPath = require_file_uri_to_path();
|
|
112
|
+
var join5 = path3.join;
|
|
113
|
+
var dirname4 = path3.dirname;
|
|
114
|
+
var exists = fs3.accessSync && function(path4) {
|
|
115
|
+
try {
|
|
116
|
+
fs3.accessSync(path4);
|
|
117
|
+
} catch (e) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
return true;
|
|
121
|
+
} || fs3.existsSync || path3.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 (path3.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 = join5.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 = dirname4(file), prev;
|
|
229
|
+
while (true) {
|
|
230
|
+
if (dir === ".") {
|
|
231
|
+
dir = process.cwd();
|
|
232
|
+
}
|
|
233
|
+
if (exists(join5(dir, "package.json")) || exists(join5(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 = join5(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 fs3 = __require("fs");
|
|
405
|
+
var path3 = __require("path");
|
|
406
|
+
var { promisify: promisify2 } = __require("util");
|
|
407
|
+
var { cppdb } = require_util();
|
|
408
|
+
var fsAccess = promisify2(fs3.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(path3.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((resolve4, reject) => {
|
|
431
|
+
setImmediate(function step() {
|
|
432
|
+
try {
|
|
433
|
+
const progress = backup.transfer(rate);
|
|
434
|
+
if (!progress.remainingPages) {
|
|
435
|
+
backup.close();
|
|
436
|
+
resolve4(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 fs3 = __require("fs");
|
|
727
|
+
var path3 = __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(path3.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:") && !fs3.existsSync(path3.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
|
+
|
|
807
|
+
// src/schema/messages.ts
|
|
59
808
|
var EN = {
|
|
60
809
|
required: "Value is required",
|
|
61
810
|
type_string: "Expected a string",
|
|
@@ -101,18 +850,12 @@ var EN = {
|
|
|
101
850
|
refine_fail: "{message}",
|
|
102
851
|
date_invalid: "Invalid date",
|
|
103
852
|
date_not_date: "Value must be a valid date",
|
|
104
|
-
indonesia_nik: "NIK must be 16 digits with valid format",
|
|
105
|
-
indonesia_npwp: "Invalid NPWP format",
|
|
106
|
-
indonesia_phone: "Invalid Indonesian phone number",
|
|
107
|
-
indonesia_alamat: "Invalid address (min 10 characters, must contain street/RT/RW elements)",
|
|
108
|
-
indonesia_kodepos: "Postal code must be 5 digits",
|
|
109
|
-
indonesia_rekening: "Bank account number must be 10-16 digits",
|
|
110
853
|
coerce_number_fail: "Value cannot be coerced to a number",
|
|
111
854
|
coerce_date_fail: "Value cannot be coerced to a date",
|
|
112
855
|
map_not_map: "Expected a Map",
|
|
113
856
|
set_not_set: "Expected a Set"
|
|
114
857
|
};
|
|
115
|
-
var store = { ...
|
|
858
|
+
var store = { ...EN };
|
|
116
859
|
function msg(key, params) {
|
|
117
860
|
let template = store[key];
|
|
118
861
|
if (!template) return key;
|
|
@@ -123,9 +866,8 @@ function msg(key, params) {
|
|
|
123
866
|
}
|
|
124
867
|
return template;
|
|
125
868
|
}
|
|
126
|
-
function setLocale(
|
|
127
|
-
|
|
128
|
-
const source = locale === "id" ? ID : EN;
|
|
869
|
+
function setLocale(_locale) {
|
|
870
|
+
const source = EN;
|
|
129
871
|
for (const key in source) {
|
|
130
872
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
131
873
|
store[key] = source[key];
|
|
@@ -133,7 +875,7 @@ function setLocale(locale) {
|
|
|
133
875
|
}
|
|
134
876
|
}
|
|
135
877
|
function getLocale() {
|
|
136
|
-
return
|
|
878
|
+
return "en";
|
|
137
879
|
}
|
|
138
880
|
|
|
139
881
|
// src/schema/types.ts
|
|
@@ -183,7 +925,7 @@ var Schema = class {
|
|
|
183
925
|
transform(fn) {
|
|
184
926
|
return new TransformSchema(this, fn);
|
|
185
927
|
}
|
|
186
|
-
/** @internal used by
|
|
928
|
+
/** @internal used by schema.enum() etc */
|
|
187
929
|
get _internal() {
|
|
188
930
|
return this;
|
|
189
931
|
}
|
|
@@ -561,9 +1303,9 @@ var ObjectSchema = class _ObjectSchema extends Schema {
|
|
|
561
1303
|
const result = {};
|
|
562
1304
|
for (const key in this.shape) {
|
|
563
1305
|
if (Object.prototype.hasOwnProperty.call(this.shape, key)) {
|
|
564
|
-
const
|
|
1306
|
+
const schema2 = this.shape[key];
|
|
565
1307
|
try {
|
|
566
|
-
result[key] =
|
|
1308
|
+
result[key] = schema2._parse(obj[key]);
|
|
567
1309
|
} catch (e) {
|
|
568
1310
|
if (e instanceof SchemaError) {
|
|
569
1311
|
throw new SchemaError(e.message, {
|
|
@@ -706,9 +1448,9 @@ var UnionSchema = class extends Schema {
|
|
|
706
1448
|
schemas;
|
|
707
1449
|
_parse(value) {
|
|
708
1450
|
const errors = [];
|
|
709
|
-
for (const
|
|
1451
|
+
for (const schema2 of this.schemas) {
|
|
710
1452
|
try {
|
|
711
|
-
return
|
|
1453
|
+
return schema2._parse(value);
|
|
712
1454
|
} catch (e) {
|
|
713
1455
|
errors.push(e instanceof SchemaError ? e.message : String(e));
|
|
714
1456
|
}
|
|
@@ -826,136 +1568,6 @@ var UnknownSchema = class extends Schema {
|
|
|
826
1568
|
}
|
|
827
1569
|
};
|
|
828
1570
|
|
|
829
|
-
// src/schema/indonesia.ts
|
|
830
|
-
function isNIK(value) {
|
|
831
|
-
const digits = value.replace(/\D/g, "");
|
|
832
|
-
if (digits.length !== 16) return false;
|
|
833
|
-
const rawDay = Number.parseInt(digits.slice(6, 8), 10);
|
|
834
|
-
const month = Number.parseInt(digits.slice(8, 10), 10);
|
|
835
|
-
const year = Number.parseInt(digits.slice(10, 12), 10);
|
|
836
|
-
if (rawDay < 1 || rawDay > 71) return false;
|
|
837
|
-
if (month < 1 || month > 12) return false;
|
|
838
|
-
let day = rawDay;
|
|
839
|
-
if (day >= 41) day -= 40;
|
|
840
|
-
const fullYear = year < 70 ? 2e3 + year : 1900 + year;
|
|
841
|
-
const date = new Date(fullYear, month - 1, day);
|
|
842
|
-
return date.getFullYear() === fullYear && date.getMonth() === month - 1 && date.getDate() === day;
|
|
843
|
-
}
|
|
844
|
-
function isNPWP(value) {
|
|
845
|
-
const digits = value.replace(/\D/g, "");
|
|
846
|
-
if (digits.length !== 15 && digits.length !== 16) return false;
|
|
847
|
-
const nums = [];
|
|
848
|
-
for (let i = 0; i < digits.length; i++) {
|
|
849
|
-
nums.push(Number.parseInt(digits[i], 10));
|
|
850
|
-
}
|
|
851
|
-
const checkDigit = nums[nums.length - 1];
|
|
852
|
-
let sum = 0;
|
|
853
|
-
for (let i = 0; i < nums.length - 1; i++) {
|
|
854
|
-
sum += nums[i] * [3, 7, 1][i % 3];
|
|
855
|
-
}
|
|
856
|
-
const computed2 = (11 - sum % 11) % 10;
|
|
857
|
-
return computed2 === checkDigit;
|
|
858
|
-
}
|
|
859
|
-
var INDONESIAN_PREFIXES = [
|
|
860
|
-
[11, 19],
|
|
861
|
-
[21, 29],
|
|
862
|
-
[51, 59],
|
|
863
|
-
[77, 79],
|
|
864
|
-
[95, 99]
|
|
865
|
-
];
|
|
866
|
-
function isValidIndonesianPrefix(prefix) {
|
|
867
|
-
for (const [min, max] of INDONESIAN_PREFIXES) {
|
|
868
|
-
if (prefix >= min && prefix <= max) return true;
|
|
869
|
-
}
|
|
870
|
-
return false;
|
|
871
|
-
}
|
|
872
|
-
function isPhone(value, country = "id") {
|
|
873
|
-
const digits = value.replace(/\D/g, "");
|
|
874
|
-
if (country === "any") {
|
|
875
|
-
return digits.length >= 10 && digits.length <= 15;
|
|
876
|
-
}
|
|
877
|
-
if (digits.length < 10) return false;
|
|
878
|
-
let normalized;
|
|
879
|
-
if (digits.startsWith("62")) {
|
|
880
|
-
normalized = digits.slice(2);
|
|
881
|
-
} else if (digits.startsWith("0")) {
|
|
882
|
-
normalized = digits.slice(1);
|
|
883
|
-
} else {
|
|
884
|
-
normalized = digits;
|
|
885
|
-
}
|
|
886
|
-
if (normalized.length < 10 || normalized.length > 13) return false;
|
|
887
|
-
if (!normalized.startsWith("8")) return false;
|
|
888
|
-
const prefix = Number.parseInt(normalized.slice(1, 3), 10);
|
|
889
|
-
return isValidIndonesianPrefix(prefix);
|
|
890
|
-
}
|
|
891
|
-
var NIKSchema = class extends Schema {
|
|
892
|
-
_parse(value) {
|
|
893
|
-
if (typeof value !== "string") throw new SchemaError(msg("type_string"));
|
|
894
|
-
if (!isNIK(value)) throw new SchemaError(msg("indonesia_nik"));
|
|
895
|
-
return value;
|
|
896
|
-
}
|
|
897
|
-
};
|
|
898
|
-
var NPWPSchema = class extends Schema {
|
|
899
|
-
_parse(value) {
|
|
900
|
-
if (typeof value !== "string") throw new SchemaError(msg("type_string"));
|
|
901
|
-
if (!isNPWP(value)) throw new SchemaError(msg("indonesia_npwp"));
|
|
902
|
-
return value;
|
|
903
|
-
}
|
|
904
|
-
};
|
|
905
|
-
var PhoneSchema = class extends Schema {
|
|
906
|
-
_parse(value) {
|
|
907
|
-
if (typeof value !== "string") throw new SchemaError(msg("type_string"));
|
|
908
|
-
if (!isPhone(value, "id")) throw new SchemaError(msg("indonesia_phone"));
|
|
909
|
-
return value;
|
|
910
|
-
}
|
|
911
|
-
};
|
|
912
|
-
var ALAMAT_KEYWORDS = [
|
|
913
|
-
/^jl[.\s]/i,
|
|
914
|
-
/^jalan\s/i,
|
|
915
|
-
/^gg[.\s]/i,
|
|
916
|
-
/^gang\s/i,
|
|
917
|
-
/rt\s*\d/i,
|
|
918
|
-
/rw\s*\d/i,
|
|
919
|
-
/dsn/i,
|
|
920
|
-
/dusun/i,
|
|
921
|
-
/kec/i,
|
|
922
|
-
/kelurahan/i,
|
|
923
|
-
/desa/i,
|
|
924
|
-
/perum/i,
|
|
925
|
-
/komplek/i
|
|
926
|
-
];
|
|
927
|
-
var AlamatSchema = class extends Schema {
|
|
928
|
-
_parse(value) {
|
|
929
|
-
if (typeof value !== "string") throw new SchemaError(msg("type_string"));
|
|
930
|
-
if (value.length < 10) throw new SchemaError(msg("indonesia_alamat"));
|
|
931
|
-
let hasKeyword = false;
|
|
932
|
-
for (const pattern of ALAMAT_KEYWORDS) {
|
|
933
|
-
if (pattern.test(value)) {
|
|
934
|
-
hasKeyword = true;
|
|
935
|
-
break;
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
if (!hasKeyword) throw new SchemaError(msg("indonesia_alamat"));
|
|
939
|
-
return value;
|
|
940
|
-
}
|
|
941
|
-
};
|
|
942
|
-
var KodeposSchema = class extends Schema {
|
|
943
|
-
_parse(value) {
|
|
944
|
-
if (typeof value !== "string") throw new SchemaError(msg("type_string"));
|
|
945
|
-
const digits = value.replace(/\s/g, "");
|
|
946
|
-
if (!/^\d{5}$/.test(digits)) throw new SchemaError(msg("indonesia_kodepos"));
|
|
947
|
-
return digits;
|
|
948
|
-
}
|
|
949
|
-
};
|
|
950
|
-
var RekeningSchema = class extends Schema {
|
|
951
|
-
_parse(value) {
|
|
952
|
-
if (typeof value !== "string") throw new SchemaError(msg("type_string"));
|
|
953
|
-
const digits = value.replace(/\s/g, "");
|
|
954
|
-
if (!/^\d{10,16}$/.test(digits)) throw new SchemaError(msg("indonesia_rekening"));
|
|
955
|
-
return digits;
|
|
956
|
-
}
|
|
957
|
-
};
|
|
958
|
-
|
|
959
1571
|
// src/schema/transform.ts
|
|
960
1572
|
var CoerceStringSchema = class extends Schema {
|
|
961
1573
|
_parse(value) {
|
|
@@ -1016,7 +1628,7 @@ var StandaloneTransformSchema = class extends Schema {
|
|
|
1016
1628
|
};
|
|
1017
1629
|
|
|
1018
1630
|
// src/schema/index.ts
|
|
1019
|
-
var
|
|
1631
|
+
var schema = {
|
|
1020
1632
|
string() {
|
|
1021
1633
|
return new StringSchema();
|
|
1022
1634
|
},
|
|
@@ -1080,25 +1692,6 @@ var s = {
|
|
|
1080
1692
|
unknown() {
|
|
1081
1693
|
return new UnknownSchema();
|
|
1082
1694
|
},
|
|
1083
|
-
// ─── Indonesia ──────────────────────────────────────────
|
|
1084
|
-
nik() {
|
|
1085
|
-
return new NIKSchema();
|
|
1086
|
-
},
|
|
1087
|
-
npwp() {
|
|
1088
|
-
return new NPWPSchema();
|
|
1089
|
-
},
|
|
1090
|
-
phone() {
|
|
1091
|
-
return new PhoneSchema();
|
|
1092
|
-
},
|
|
1093
|
-
alamat() {
|
|
1094
|
-
return new AlamatSchema();
|
|
1095
|
-
},
|
|
1096
|
-
kodepos() {
|
|
1097
|
-
return new KodeposSchema();
|
|
1098
|
-
},
|
|
1099
|
-
rekening() {
|
|
1100
|
-
return new RekeningSchema();
|
|
1101
|
-
},
|
|
1102
1695
|
// ─── Coerce ─────────────────────────────────────────────
|
|
1103
1696
|
coerce: {
|
|
1104
1697
|
string() {
|
|
@@ -1119,6 +1712,7 @@ var s = {
|
|
|
1119
1712
|
return new StandaloneTransformSchema(fn);
|
|
1120
1713
|
}
|
|
1121
1714
|
};
|
|
1715
|
+
var s = schema;
|
|
1122
1716
|
|
|
1123
1717
|
// src/server/container/index.ts
|
|
1124
1718
|
var Container = class {
|
|
@@ -1538,8 +2132,15 @@ var SuperRequest = class {
|
|
|
1538
2132
|
}
|
|
1539
2133
|
async readBodyFromStream() {
|
|
1540
2134
|
const chunks = [];
|
|
2135
|
+
const MAX_BODY_SIZE = 10 * 1024 * 1024;
|
|
2136
|
+
let totalSize = 0;
|
|
1541
2137
|
for await (const chunk of this.raw) {
|
|
1542
|
-
|
|
2138
|
+
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
2139
|
+
totalSize += buf.length;
|
|
2140
|
+
if (totalSize > MAX_BODY_SIZE) {
|
|
2141
|
+
throw new Error("Request body too large. Maximum size is 10MB.");
|
|
2142
|
+
}
|
|
2143
|
+
chunks.push(buf);
|
|
1543
2144
|
}
|
|
1544
2145
|
const raw = Buffer.concat(chunks);
|
|
1545
2146
|
const text2 = raw.toString("utf-8");
|
|
@@ -1646,9 +2247,9 @@ var SuperRequest = class {
|
|
|
1646
2247
|
}
|
|
1647
2248
|
return this._cookies[name];
|
|
1648
2249
|
}
|
|
1649
|
-
async validate(
|
|
2250
|
+
async validate(schema2) {
|
|
1650
2251
|
const data = await this.body();
|
|
1651
|
-
const result =
|
|
2252
|
+
const result = schema2.validate(data);
|
|
1652
2253
|
if (!result.success) {
|
|
1653
2254
|
const messages = (result.errors ?? []).map((e) => {
|
|
1654
2255
|
const path3 = e.path ?? "";
|
|
@@ -1804,7 +2405,7 @@ function parseContentType(headerSection) {
|
|
|
1804
2405
|
|
|
1805
2406
|
// src/server/http/response.ts
|
|
1806
2407
|
import { createReadStream, stat } from "fs";
|
|
1807
|
-
import { basename as basename2, extname as extname2 } from "path";
|
|
2408
|
+
import { basename as basename2, extname as extname2, resolve } from "path";
|
|
1808
2409
|
import { promisify } from "util";
|
|
1809
2410
|
var statAsync = promisify(stat);
|
|
1810
2411
|
var MIME_TYPES = {
|
|
@@ -1887,6 +2488,9 @@ var SuperResponse = class {
|
|
|
1887
2488
|
return this.send(html, status, "text/html; charset=utf-8");
|
|
1888
2489
|
}
|
|
1889
2490
|
redirect(url2, status = HttpStatus.FOUND) {
|
|
2491
|
+
if (url2.includes("\r") || url2.includes("\n")) {
|
|
2492
|
+
throw new Error("Invalid redirect URL");
|
|
2493
|
+
}
|
|
1890
2494
|
this._statusCode = status;
|
|
1891
2495
|
this._headers.set("location", url2);
|
|
1892
2496
|
this._body = null;
|
|
@@ -1911,6 +2515,13 @@ var SuperResponse = class {
|
|
|
1911
2515
|
}
|
|
1912
2516
|
async file(filePath, options) {
|
|
1913
2517
|
const fullPath = options?.root ? joinPath(options.root, filePath) : filePath;
|
|
2518
|
+
const resolved = resolve(fullPath);
|
|
2519
|
+
const root = options?.root ? resolve(options.root) : null;
|
|
2520
|
+
if (root !== null && !resolved.startsWith(root)) {
|
|
2521
|
+
this._statusCode = HttpStatus.FORBIDDEN;
|
|
2522
|
+
this._body = null;
|
|
2523
|
+
return this;
|
|
2524
|
+
}
|
|
1914
2525
|
try {
|
|
1915
2526
|
const stats = await statAsync(fullPath);
|
|
1916
2527
|
if (!stats.isFile()) {
|
|
@@ -2041,12 +2652,12 @@ var NodeEngine = class {
|
|
|
2041
2652
|
return {
|
|
2042
2653
|
raw: server,
|
|
2043
2654
|
close: () => {
|
|
2044
|
-
return new Promise((
|
|
2655
|
+
return new Promise((resolve4, reject) => {
|
|
2045
2656
|
server.close((err) => {
|
|
2046
2657
|
if (err !== void 0 && err !== null) {
|
|
2047
2658
|
reject(err);
|
|
2048
2659
|
} else {
|
|
2049
|
-
|
|
2660
|
+
resolve4();
|
|
2050
2661
|
}
|
|
2051
2662
|
});
|
|
2052
2663
|
});
|
|
@@ -2068,8 +2679,8 @@ var NodeEngine = class {
|
|
|
2068
2679
|
// src/server/middleware/index.ts
|
|
2069
2680
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
2070
2681
|
import { createReadStream as createReadStream2, existsSync, statSync } from "fs";
|
|
2071
|
-
import { extname as extname3, join as join2 } from "path";
|
|
2072
|
-
import {
|
|
2682
|
+
import { extname as extname3, join as join2, resolve as resolve2 } from "path";
|
|
2683
|
+
import { gzipSync } from "zlib";
|
|
2073
2684
|
function staticFiles(root, options) {
|
|
2074
2685
|
const opts = {
|
|
2075
2686
|
maxAge: 0,
|
|
@@ -2108,6 +2719,11 @@ function staticFiles(root, options) {
|
|
|
2108
2719
|
}
|
|
2109
2720
|
}
|
|
2110
2721
|
let fullPath = join2(root, filePath);
|
|
2722
|
+
const resolvedRoot = resolve2(root);
|
|
2723
|
+
const resolvedPath = resolve2(fullPath);
|
|
2724
|
+
if (!resolvedPath.startsWith(resolvedRoot)) {
|
|
2725
|
+
return next();
|
|
2726
|
+
}
|
|
2111
2727
|
if (!existsSync(fullPath)) {
|
|
2112
2728
|
let found = false;
|
|
2113
2729
|
for (const ext2 of opts.extensions) {
|
|
@@ -2139,8 +2755,8 @@ function staticFiles(root, options) {
|
|
|
2139
2755
|
const readStream = createReadStream2(fullPath);
|
|
2140
2756
|
readStream.pipe(response.rawResponse);
|
|
2141
2757
|
response.rawResponse.statusCode = HttpStatus.OK;
|
|
2142
|
-
return new Promise((
|
|
2143
|
-
readStream.on("end", () =>
|
|
2758
|
+
return new Promise((resolve4, reject) => {
|
|
2759
|
+
readStream.on("end", () => resolve4());
|
|
2144
2760
|
readStream.on("error", (err) => reject(err));
|
|
2145
2761
|
});
|
|
2146
2762
|
};
|
|
@@ -2397,12 +3013,6 @@ function singularize(word) {
|
|
|
2397
3013
|
if (lastChar === "S") return word.slice(0, -1);
|
|
2398
3014
|
return word;
|
|
2399
3015
|
}
|
|
2400
|
-
function createControllerInstance(controller, ctx) {
|
|
2401
|
-
const instance = new controller();
|
|
2402
|
-
instance.__ctx = ctx;
|
|
2403
|
-
instance.__container = ctx.container;
|
|
2404
|
-
return instance;
|
|
2405
|
-
}
|
|
2406
3016
|
|
|
2407
3017
|
// src/server/cache/index.ts
|
|
2408
3018
|
import * as crypto from "crypto";
|
|
@@ -3128,47 +3738,66 @@ async function createMysqlDriver(config) {
|
|
|
3128
3738
|
"MySQL driver (mysql2) is not installed. Run: npm install mysql2"
|
|
3129
3739
|
);
|
|
3130
3740
|
}
|
|
3131
|
-
let
|
|
3741
|
+
let pool = null;
|
|
3132
3742
|
const dialect = new MysqlDialect();
|
|
3133
3743
|
const driver = {
|
|
3134
3744
|
async connect() {
|
|
3135
|
-
|
|
3745
|
+
pool = mysqlPackage.createPool({
|
|
3136
3746
|
host: config.host ?? "127.0.0.1",
|
|
3137
3747
|
port: config.port ?? 3306,
|
|
3138
3748
|
user: config.username,
|
|
3139
3749
|
password: config.password,
|
|
3140
3750
|
database: config.database,
|
|
3141
|
-
charset: config.charset ?? "utf8mb4"
|
|
3751
|
+
charset: config.charset ?? "utf8mb4",
|
|
3752
|
+
waitForConnections: true,
|
|
3753
|
+
connectionLimit: 10,
|
|
3754
|
+
queueLimit: 0
|
|
3142
3755
|
});
|
|
3756
|
+
const conn = await pool.getConnection();
|
|
3757
|
+
conn.release();
|
|
3143
3758
|
},
|
|
3144
3759
|
async disconnect() {
|
|
3145
|
-
if (
|
|
3146
|
-
await
|
|
3147
|
-
|
|
3760
|
+
if (pool !== null) {
|
|
3761
|
+
await pool.end();
|
|
3762
|
+
pool = null;
|
|
3148
3763
|
}
|
|
3149
3764
|
},
|
|
3150
3765
|
isConnected() {
|
|
3151
|
-
return
|
|
3766
|
+
return pool !== null;
|
|
3152
3767
|
},
|
|
3153
3768
|
async raw(sql, bindings) {
|
|
3154
|
-
if (
|
|
3769
|
+
if (pool === null) {
|
|
3155
3770
|
throw new Error("Database not connected. Call connect() first.");
|
|
3156
3771
|
}
|
|
3157
|
-
const [rows, fields] = await
|
|
3772
|
+
const [rows, fields] = await pool.execute(sql, bindings ?? []);
|
|
3158
3773
|
return { rows, fields };
|
|
3159
3774
|
},
|
|
3160
3775
|
async transaction(callback) {
|
|
3161
|
-
if (
|
|
3162
|
-
|
|
3163
|
-
}
|
|
3164
|
-
await connection.beginTransaction();
|
|
3776
|
+
if (pool === null) throw new Error("Database not connected.");
|
|
3777
|
+
const conn = await pool.getConnection();
|
|
3165
3778
|
try {
|
|
3166
|
-
|
|
3167
|
-
|
|
3779
|
+
await conn.beginTransaction();
|
|
3780
|
+
const trxDriver = {
|
|
3781
|
+
...driver,
|
|
3782
|
+
async raw(sql, bindings) {
|
|
3783
|
+
const [rows, fields] = await conn.execute(sql, bindings ?? []);
|
|
3784
|
+
return { rows, fields };
|
|
3785
|
+
},
|
|
3786
|
+
getDialect() {
|
|
3787
|
+
return dialect;
|
|
3788
|
+
},
|
|
3789
|
+
getDriver() {
|
|
3790
|
+
return "mysql";
|
|
3791
|
+
}
|
|
3792
|
+
};
|
|
3793
|
+
const result = await callback(trxDriver);
|
|
3794
|
+
await conn.commit();
|
|
3168
3795
|
return result;
|
|
3169
3796
|
} catch (err) {
|
|
3170
|
-
await
|
|
3797
|
+
await conn.rollback();
|
|
3171
3798
|
throw err;
|
|
3799
|
+
} finally {
|
|
3800
|
+
conn.release();
|
|
3172
3801
|
}
|
|
3173
3802
|
},
|
|
3174
3803
|
getDialect() {
|
|
@@ -3261,7 +3890,7 @@ async function createPostgresqlDriver(config) {
|
|
|
3261
3890
|
async function createSqliteDriver(config) {
|
|
3262
3891
|
let sqlitePackage;
|
|
3263
3892
|
try {
|
|
3264
|
-
sqlitePackage = await
|
|
3893
|
+
sqlitePackage = await Promise.resolve().then(() => __toESM(require_lib(), 1));
|
|
3265
3894
|
} catch {
|
|
3266
3895
|
throw new Error(
|
|
3267
3896
|
"SQLite driver (better-sqlite3) is not installed. Run: npm install better-sqlite3"
|
|
@@ -3308,10 +3937,15 @@ async function createSqliteDriver(config) {
|
|
|
3308
3937
|
if (db === null) {
|
|
3309
3938
|
throw new Error("Database not connected. Call connect() first.");
|
|
3310
3939
|
}
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3940
|
+
db.exec("BEGIN");
|
|
3941
|
+
try {
|
|
3942
|
+
const result = await callback(driver);
|
|
3943
|
+
db.exec("COMMIT");
|
|
3944
|
+
return result;
|
|
3945
|
+
} catch (err) {
|
|
3946
|
+
db.exec("ROLLBACK");
|
|
3947
|
+
throw err;
|
|
3948
|
+
}
|
|
3315
3949
|
},
|
|
3316
3950
|
getDialect() {
|
|
3317
3951
|
return dialect;
|
|
@@ -3578,15 +4212,30 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
3578
4212
|
async insert(data) {
|
|
3579
4213
|
const { sql, bindings } = this.compileInsert(data);
|
|
3580
4214
|
const driverType = this.connection.getDriver();
|
|
4215
|
+
const dialect = this.connection.getDialect();
|
|
3581
4216
|
if (driverType === "postgresql") {
|
|
3582
|
-
const dialect = this.connection.getDialect();
|
|
3583
4217
|
const returningSQL = dialect.compileInsertReturning(sql, bindings);
|
|
3584
4218
|
const result2 = await this.connection.raw(returningSQL, bindings);
|
|
3585
4219
|
return result2.rows.length > 0 ? Number(result2.rows[0].id) ?? 0 : 0;
|
|
3586
4220
|
}
|
|
3587
4221
|
const result = await this.connection.raw(sql, bindings);
|
|
3588
|
-
if (
|
|
3589
|
-
|
|
4222
|
+
if (driverType === "mysql") {
|
|
4223
|
+
const header = result.rows;
|
|
4224
|
+
if (header && typeof header === "object" && "insertId" in header) {
|
|
4225
|
+
return Number(header.insertId) ?? 0;
|
|
4226
|
+
}
|
|
4227
|
+
if (Array.isArray(result.rows) && result.rows.length > 0) {
|
|
4228
|
+
const row = result.rows[0];
|
|
4229
|
+
return Number(row?.insertId ?? row?.id ?? 0);
|
|
4230
|
+
}
|
|
4231
|
+
return 0;
|
|
4232
|
+
}
|
|
4233
|
+
if (driverType === "sqlite") {
|
|
4234
|
+
const lastIdResult = await this.connection.raw("SELECT last_insert_rowid() as id");
|
|
4235
|
+
if (lastIdResult.rows.length > 0) {
|
|
4236
|
+
return Number(lastIdResult.rows[0].id) ?? 0;
|
|
4237
|
+
}
|
|
4238
|
+
return 0;
|
|
3590
4239
|
}
|
|
3591
4240
|
return 0;
|
|
3592
4241
|
}
|
|
@@ -3695,7 +4344,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
3695
4344
|
const output = `SQL: ${sql}
|
|
3696
4345
|
Bindings: ${JSON.stringify(bindings)}`;
|
|
3697
4346
|
console.error(output);
|
|
3698
|
-
|
|
4347
|
+
return output;
|
|
3699
4348
|
}
|
|
3700
4349
|
compileJoins(dialect) {
|
|
3701
4350
|
if (this.joins.length === 0) return "";
|
|
@@ -3717,7 +4366,11 @@ Bindings: ${JSON.stringify(bindings)}`;
|
|
|
3717
4366
|
if (sql !== null) parts.push(sql);
|
|
3718
4367
|
}
|
|
3719
4368
|
if (parts.length === 0) return "";
|
|
3720
|
-
return parts.
|
|
4369
|
+
return parts.reduce((acc, part, i) => {
|
|
4370
|
+
if (i === 0) return part;
|
|
4371
|
+
const bool = wheres[i]?.boolean ?? "and";
|
|
4372
|
+
return `${acc} ${bool.toUpperCase()} ${part}`;
|
|
4373
|
+
}, "");
|
|
3721
4374
|
}
|
|
3722
4375
|
compileSingleWhere(w, dialect, bindings) {
|
|
3723
4376
|
const col = w.column ? dialect.wrapIdentifier(w.column) : "";
|
|
@@ -3766,15 +4419,18 @@ Bindings: ${JSON.stringify(bindings)}`;
|
|
|
3766
4419
|
}
|
|
3767
4420
|
}
|
|
3768
4421
|
compileNestedWhere(wheres, dialect, bindings) {
|
|
4422
|
+
if (wheres.length === 0) return "";
|
|
3769
4423
|
const parts = [];
|
|
3770
4424
|
for (const w of wheres) {
|
|
3771
4425
|
const sql = this.compileSingleWhere(w, dialect, bindings);
|
|
3772
|
-
if (sql !== null)
|
|
3773
|
-
parts.push(sql);
|
|
3774
|
-
}
|
|
4426
|
+
if (sql !== null) parts.push(sql);
|
|
3775
4427
|
}
|
|
3776
4428
|
if (parts.length === 0) return "";
|
|
3777
|
-
return parts.
|
|
4429
|
+
return parts.reduce((acc, part, i) => {
|
|
4430
|
+
if (i === 0) return part;
|
|
4431
|
+
const bool = wheres[i]?.boolean ?? "and";
|
|
4432
|
+
return `${acc} ${bool.toUpperCase()} ${part}`;
|
|
4433
|
+
}, "");
|
|
3778
4434
|
}
|
|
3779
4435
|
compileHavings(dialect, bindings) {
|
|
3780
4436
|
if (this.havings.length === 0) return "";
|
|
@@ -4363,11 +5019,11 @@ var Migrator = class {
|
|
|
4363
5019
|
return;
|
|
4364
5020
|
}
|
|
4365
5021
|
const nextBatch = await this.getNextBatchNumber();
|
|
4366
|
-
const
|
|
5022
|
+
const schema2 = new SchemaBuilder(this.connection);
|
|
4367
5023
|
for (const migration of pending) {
|
|
4368
5024
|
console.log(`Migrating: ${migration.name}`);
|
|
4369
5025
|
try {
|
|
4370
|
-
await migration.up(
|
|
5026
|
+
await migration.up(schema2);
|
|
4371
5027
|
await this.recordMigration(migration.name, nextBatch);
|
|
4372
5028
|
console.log(`Migrated: ${migration.name}`);
|
|
4373
5029
|
} catch (err) {
|
|
@@ -4384,13 +5040,13 @@ var Migrator = class {
|
|
|
4384
5040
|
return;
|
|
4385
5041
|
}
|
|
4386
5042
|
const lastBatchMigrations = await this.getMigrationsByBatch(lastBatch);
|
|
4387
|
-
const
|
|
5043
|
+
const schema2 = new SchemaBuilder(this.connection);
|
|
4388
5044
|
for (const migration of lastBatchMigrations.reverse()) {
|
|
4389
5045
|
const def = this.migrations.find((m) => m.name === migration.name);
|
|
4390
5046
|
if (def) {
|
|
4391
5047
|
console.log(`Rolling back: ${migration.name}`);
|
|
4392
5048
|
try {
|
|
4393
|
-
await def.down(
|
|
5049
|
+
await def.down(schema2);
|
|
4394
5050
|
await this.removeMigration(migration.name);
|
|
4395
5051
|
console.log(`Rolled back: ${migration.name}`);
|
|
4396
5052
|
} catch (err) {
|
|
@@ -4403,13 +5059,13 @@ var Migrator = class {
|
|
|
4403
5059
|
async reset() {
|
|
4404
5060
|
await this.ensureMigrationTable();
|
|
4405
5061
|
const allRan = await this.getRanMigrations();
|
|
4406
|
-
const
|
|
5062
|
+
const schema2 = new SchemaBuilder(this.connection);
|
|
4407
5063
|
for (const migration of allRan.reverse()) {
|
|
4408
5064
|
const def = this.migrations.find((m) => m.name === migration.name);
|
|
4409
5065
|
if (def) {
|
|
4410
5066
|
console.log(`Resetting: ${migration.name}`);
|
|
4411
5067
|
try {
|
|
4412
|
-
await def.down(
|
|
5068
|
+
await def.down(schema2);
|
|
4413
5069
|
await this.removeMigration(migration.name);
|
|
4414
5070
|
console.log(`Reset: ${migration.name}`);
|
|
4415
5071
|
} catch (err) {
|
|
@@ -4599,6 +5255,116 @@ var Seeder = class {
|
|
|
4599
5255
|
}
|
|
4600
5256
|
};
|
|
4601
5257
|
|
|
5258
|
+
// src/server/database/model.ts
|
|
5259
|
+
var Model = class {
|
|
5260
|
+
id;
|
|
5261
|
+
static table = "";
|
|
5262
|
+
static connection = null;
|
|
5263
|
+
static queryRunner = null;
|
|
5264
|
+
static setConnection(conn) {
|
|
5265
|
+
this.connection = conn;
|
|
5266
|
+
this.queryRunner = conn;
|
|
5267
|
+
}
|
|
5268
|
+
static query() {
|
|
5269
|
+
if (!this.queryRunner) {
|
|
5270
|
+
throw new Error("Database connection not set. Call Model.setConnection() first.");
|
|
5271
|
+
}
|
|
5272
|
+
return new QueryBuilder(this.queryRunner, this.table);
|
|
5273
|
+
}
|
|
5274
|
+
static async all() {
|
|
5275
|
+
const rows = await this.query().get();
|
|
5276
|
+
return rows.map((row) => this.hydrate(row));
|
|
5277
|
+
}
|
|
5278
|
+
static async find(id) {
|
|
5279
|
+
const row = await this.query().find(id);
|
|
5280
|
+
if (!row) return null;
|
|
5281
|
+
return this.hydrate(row);
|
|
5282
|
+
}
|
|
5283
|
+
static async where(column, value) {
|
|
5284
|
+
return this.query().where(column, value);
|
|
5285
|
+
}
|
|
5286
|
+
static async create(data) {
|
|
5287
|
+
const id = await this.query().insert(data);
|
|
5288
|
+
return this.find(id);
|
|
5289
|
+
}
|
|
5290
|
+
static async updateOrCreate(attributes, values) {
|
|
5291
|
+
const qb = this.query();
|
|
5292
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
5293
|
+
qb.where(key, value);
|
|
5294
|
+
}
|
|
5295
|
+
const existing = await qb.first();
|
|
5296
|
+
if (existing) {
|
|
5297
|
+
const mergeValues = values ?? attributes;
|
|
5298
|
+
const id = existing.id;
|
|
5299
|
+
const updateQb = new QueryBuilder(this.queryRunner, this.table);
|
|
5300
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
5301
|
+
updateQb.where(key, value);
|
|
5302
|
+
}
|
|
5303
|
+
await updateQb.update(mergeValues);
|
|
5304
|
+
return this.find(id);
|
|
5305
|
+
}
|
|
5306
|
+
return this.create({ ...attributes, ...values });
|
|
5307
|
+
}
|
|
5308
|
+
async save() {
|
|
5309
|
+
const ModelClass = this.constructor;
|
|
5310
|
+
const id = this.id;
|
|
5311
|
+
if (id !== void 0 && id !== null) {
|
|
5312
|
+
await ModelClass.query().where("id", id).update(this.getData());
|
|
5313
|
+
} else {
|
|
5314
|
+
const newId = await ModelClass.query().insert(this.getData());
|
|
5315
|
+
this.id = newId;
|
|
5316
|
+
}
|
|
5317
|
+
}
|
|
5318
|
+
async delete() {
|
|
5319
|
+
const ModelClass = this.constructor;
|
|
5320
|
+
const id = this.id;
|
|
5321
|
+
if (id !== void 0 && id !== null) {
|
|
5322
|
+
await ModelClass.query().where("id", id).delete();
|
|
5323
|
+
}
|
|
5324
|
+
}
|
|
5325
|
+
static belongsTo(relatedModel, foreignKey, ownerKey) {
|
|
5326
|
+
const related = relatedModel.table;
|
|
5327
|
+
const fk = foreignKey ?? `${related}_id`;
|
|
5328
|
+
const ok = ownerKey ?? "id";
|
|
5329
|
+
return this.query().where(fk, ok);
|
|
5330
|
+
}
|
|
5331
|
+
static hasMany(relatedModel, foreignKey, localKey) {
|
|
5332
|
+
const related = relatedModel.table;
|
|
5333
|
+
const fk = foreignKey ?? `${this.table}_id`;
|
|
5334
|
+
const lk = localKey ?? "id";
|
|
5335
|
+
return this.query().join(related, fk, "=", lk);
|
|
5336
|
+
}
|
|
5337
|
+
static hydrate(data) {
|
|
5338
|
+
const instance = new this();
|
|
5339
|
+
for (const [key, value] of Object.entries(data)) {
|
|
5340
|
+
;
|
|
5341
|
+
instance[key] = value;
|
|
5342
|
+
}
|
|
5343
|
+
return instance;
|
|
5344
|
+
}
|
|
5345
|
+
getData() {
|
|
5346
|
+
const data = {};
|
|
5347
|
+
const instance = this;
|
|
5348
|
+
const prototype = Object.getPrototypeOf(this);
|
|
5349
|
+
const ownKeys = [
|
|
5350
|
+
...Object.getOwnPropertyNames(instance),
|
|
5351
|
+
...Object.keys(instance)
|
|
5352
|
+
];
|
|
5353
|
+
const classKeys = /* @__PURE__ */ new Set([
|
|
5354
|
+
...Object.getOwnPropertyNames(prototype),
|
|
5355
|
+
"save",
|
|
5356
|
+
"delete",
|
|
5357
|
+
"getData"
|
|
5358
|
+
]);
|
|
5359
|
+
for (const key of ownKeys) {
|
|
5360
|
+
if (typeof key === "string" && !classKeys.has(key) && key !== "constructor") {
|
|
5361
|
+
data[key] = instance[key];
|
|
5362
|
+
}
|
|
5363
|
+
}
|
|
5364
|
+
return data;
|
|
5365
|
+
}
|
|
5366
|
+
};
|
|
5367
|
+
|
|
4602
5368
|
// src/server/events/index.ts
|
|
4603
5369
|
import { EventEmitter } from "events";
|
|
4604
5370
|
var Event = class {
|
|
@@ -5161,7 +5927,7 @@ var SuperApp = class {
|
|
|
5161
5927
|
[route.method],
|
|
5162
5928
|
handlerPath,
|
|
5163
5929
|
async (ctx) => {
|
|
5164
|
-
const instance =
|
|
5930
|
+
const instance = createControllerInstance(ctrl, ctx);
|
|
5165
5931
|
const handlerFn = instance[handlerName];
|
|
5166
5932
|
if (typeof handlerFn === "function") {
|
|
5167
5933
|
await handlerFn.call(instance, ctx);
|
|
@@ -5208,10 +5974,10 @@ var SuperApp = class {
|
|
|
5208
5974
|
);
|
|
5209
5975
|
const listenPort = port ?? 3e3;
|
|
5210
5976
|
const listenHost = host ?? "0.0.0.0";
|
|
5211
|
-
return new Promise((
|
|
5977
|
+
return new Promise((resolve4) => {
|
|
5212
5978
|
const raw = this.serverInstance.raw;
|
|
5213
5979
|
raw.listen(listenPort, listenHost, () => {
|
|
5214
|
-
|
|
5980
|
+
resolve4();
|
|
5215
5981
|
});
|
|
5216
5982
|
});
|
|
5217
5983
|
}
|
|
@@ -5267,7 +6033,7 @@ var SuperApp = class {
|
|
|
5267
6033
|
function speexjs(options) {
|
|
5268
6034
|
return new SuperApp(options);
|
|
5269
6035
|
}
|
|
5270
|
-
function
|
|
6036
|
+
function createControllerInstance(controller, ctx) {
|
|
5271
6037
|
const instance = new controller();
|
|
5272
6038
|
instance.__ctx = ctx;
|
|
5273
6039
|
instance.__container = ctx.container;
|
|
@@ -6299,7 +7065,6 @@ function createClient(options) {
|
|
|
6299
7065
|
return new RpcClient(options);
|
|
6300
7066
|
}
|
|
6301
7067
|
export {
|
|
6302
|
-
AlamatSchema,
|
|
6303
7068
|
AnySchema,
|
|
6304
7069
|
ArraySchema,
|
|
6305
7070
|
BigIntSchema,
|
|
@@ -6320,24 +7085,20 @@ export {
|
|
|
6320
7085
|
ForeignKeyDefinition,
|
|
6321
7086
|
Fragment,
|
|
6322
7087
|
IntersectionSchema,
|
|
6323
|
-
KodeposSchema,
|
|
6324
7088
|
LiteralSchema,
|
|
6325
7089
|
LocalDisk,
|
|
6326
7090
|
MapSchema,
|
|
6327
7091
|
Migrator,
|
|
7092
|
+
Model,
|
|
6328
7093
|
MysqlDialect,
|
|
6329
|
-
NIKSchema,
|
|
6330
|
-
NPWPSchema,
|
|
6331
7094
|
NaNSchema,
|
|
6332
7095
|
NullSchema,
|
|
6333
7096
|
NumberSchema,
|
|
6334
7097
|
ObjectSchema,
|
|
6335
7098
|
Pagination,
|
|
6336
|
-
PhoneSchema,
|
|
6337
7099
|
PostgresqlDialect,
|
|
6338
7100
|
QueryBuilder,
|
|
6339
7101
|
RecordSchema,
|
|
6340
|
-
RekeningSchema,
|
|
6341
7102
|
RpcClient,
|
|
6342
7103
|
RpcClientError,
|
|
6343
7104
|
RpcError,
|
|
@@ -6365,6 +7126,7 @@ export {
|
|
|
6365
7126
|
computed,
|
|
6366
7127
|
createClient,
|
|
6367
7128
|
createComponent,
|
|
7129
|
+
createControllerInstance,
|
|
6368
7130
|
createDialect,
|
|
6369
7131
|
createDriver,
|
|
6370
7132
|
createElement,
|
|
@@ -6390,6 +7152,7 @@ export {
|
|
|
6390
7152
|
responseMacros,
|
|
6391
7153
|
rpc,
|
|
6392
7154
|
s,
|
|
7155
|
+
schema,
|
|
6393
7156
|
setLocale,
|
|
6394
7157
|
signal,
|
|
6395
7158
|
speexjs,
|