speexjs 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/index.js +52 -2
- package/dist/cli/index.js.map +1 -1
- package/dist/{index-CMkhSDh7.d.ts → index-C4xilc_E.d.ts} +4 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2706 -2344
- package/dist/index.js.map +1 -1
- package/dist/server/auth/index.d.ts +2 -1
- package/dist/server/cache/index.d.ts +2 -1
- package/dist/server/controller/index.d.ts +2 -1
- package/dist/server/database/index.d.ts +14 -2
- package/dist/server/database/index.js +123 -15
- package/dist/server/database/index.js.map +1 -1
- package/dist/server/gate/index.d.ts +2 -1
- package/dist/server/index.d.ts +56 -3
- package/dist/server/index.js +1940 -1578
- package/dist/server/index.js.map +1 -1
- package/dist/server/middleware/index.d.ts +2 -1
- package/dist/server/middleware/index.js +32 -1
- package/dist/server/middleware/index.js.map +1 -1
- package/dist/server/router/index.d.ts +2 -1
- package/dist/server/router/index.js.map +1 -1
- package/package.json +143 -141
package/dist/server/index.js
CHANGED
|
@@ -10,6 +10,9 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
10
10
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
11
11
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
12
|
});
|
|
13
|
+
var __esm = (fn, res) => function __init() {
|
|
14
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
15
|
+
};
|
|
13
16
|
var __commonJS = (cb, mod) => function __require2() {
|
|
14
17
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
15
18
|
};
|
|
@@ -30,1697 +33,1868 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
33
|
mod
|
|
31
34
|
));
|
|
32
35
|
|
|
33
|
-
//
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
+
// src/server/http/status.ts
|
|
37
|
+
var HttpStatus;
|
|
38
|
+
var init_status = __esm({
|
|
39
|
+
"src/server/http/status.ts"() {
|
|
36
40
|
"use strict";
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
HttpStatus = {
|
|
42
|
+
OK: 200,
|
|
43
|
+
CREATED: 201,
|
|
44
|
+
ACCEPTED: 202,
|
|
45
|
+
NO_CONTENT: 204,
|
|
46
|
+
RESET_CONTENT: 205,
|
|
47
|
+
PARTIAL_CONTENT: 206,
|
|
48
|
+
MOVED_PERMANENTLY: 301,
|
|
49
|
+
FOUND: 302,
|
|
50
|
+
SEE_OTHER: 303,
|
|
51
|
+
NOT_MODIFIED: 304,
|
|
52
|
+
TEMPORARY_REDIRECT: 307,
|
|
53
|
+
PERMANENT_REDIRECT: 308,
|
|
54
|
+
BAD_REQUEST: 400,
|
|
55
|
+
UNAUTHORIZED: 401,
|
|
56
|
+
PAYMENT_REQUIRED: 402,
|
|
57
|
+
FORBIDDEN: 403,
|
|
58
|
+
NOT_FOUND: 404,
|
|
59
|
+
METHOD_NOT_ALLOWED: 405,
|
|
60
|
+
NOT_ACCEPTABLE: 406,
|
|
61
|
+
REQUEST_TIMEOUT: 408,
|
|
62
|
+
CONFLICT: 409,
|
|
63
|
+
GONE: 410,
|
|
64
|
+
LENGTH_REQUIRED: 411,
|
|
65
|
+
PRECONDITION_FAILED: 412,
|
|
66
|
+
PAYLOAD_TOO_LARGE: 413,
|
|
67
|
+
URI_TOO_LONG: 414,
|
|
68
|
+
UNSUPPORTED_MEDIA_TYPE: 415,
|
|
69
|
+
UNPROCESSABLE_ENTITY: 422,
|
|
70
|
+
TOO_MANY_REQUESTS: 429,
|
|
71
|
+
INTERNAL_SERVER_ERROR: 500,
|
|
72
|
+
NOT_IMPLEMENTED: 501,
|
|
73
|
+
BAD_GATEWAY: 502,
|
|
74
|
+
SERVICE_UNAVAILABLE: 503,
|
|
75
|
+
GATEWAY_TIMEOUT: 504,
|
|
76
|
+
HTTP_VERSION_NOT_SUPPORTED: 505
|
|
43
77
|
};
|
|
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
78
|
}
|
|
72
79
|
});
|
|
73
80
|
|
|
74
|
-
//
|
|
75
|
-
var
|
|
76
|
-
|
|
81
|
+
// src/server/http/headers.ts
|
|
82
|
+
var HeadersMap;
|
|
83
|
+
var init_headers = __esm({
|
|
84
|
+
"src/server/http/headers.ts"() {
|
|
77
85
|
"use strict";
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
host = sep + sep + host;
|
|
86
|
+
HeadersMap = class {
|
|
87
|
+
data;
|
|
88
|
+
constructor(initial) {
|
|
89
|
+
this.data = /* @__PURE__ */ new Map();
|
|
90
|
+
if (initial) {
|
|
91
|
+
for (const key of Object.keys(initial)) {
|
|
92
|
+
const value = initial[key];
|
|
93
|
+
if (value !== void 0) {
|
|
94
|
+
this.set(key, Array.isArray(value) ? value.join(", ") : value);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
91
98
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
99
|
+
get(name) {
|
|
100
|
+
const values = this.data.get(name.toLowerCase());
|
|
101
|
+
if (values !== void 0 && values.length > 0) {
|
|
102
|
+
return values[0];
|
|
103
|
+
}
|
|
104
|
+
return void 0;
|
|
95
105
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
106
|
+
getAll(name) {
|
|
107
|
+
const values = this.data.get(name.toLowerCase());
|
|
108
|
+
return values ?? [];
|
|
99
109
|
}
|
|
100
|
-
|
|
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;
|
|
110
|
+
set(name, value) {
|
|
111
|
+
this.data.set(name.toLowerCase(), [value]);
|
|
119
112
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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 = {};
|
|
113
|
+
append(name, value) {
|
|
114
|
+
const key = name.toLowerCase();
|
|
115
|
+
const existing = this.data.get(key);
|
|
116
|
+
if (existing !== void 0) {
|
|
117
|
+
existing.push(value);
|
|
118
|
+
} else {
|
|
119
|
+
this.data.set(key, [value]);
|
|
120
|
+
}
|
|
159
121
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
});
|
|
163
|
-
if (!opts.module_root) {
|
|
164
|
-
opts.module_root = exports.getRoot(exports.getFileName());
|
|
122
|
+
has(name) {
|
|
123
|
+
return this.data.has(name.toLowerCase());
|
|
165
124
|
}
|
|
166
|
-
|
|
167
|
-
|
|
125
|
+
delete(name) {
|
|
126
|
+
this.data.delete(name.toLowerCase());
|
|
168
127
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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;
|
|
128
|
+
*entries() {
|
|
129
|
+
for (const [key, values] of this.data) {
|
|
130
|
+
for (const value of values) {
|
|
131
|
+
yield [key, value];
|
|
188
132
|
}
|
|
189
133
|
}
|
|
190
134
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
-
}
|
|
135
|
+
*keys() {
|
|
136
|
+
for (const key of this.data.keys()) {
|
|
137
|
+
yield key;
|
|
215
138
|
}
|
|
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
139
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
if (dir === ".") {
|
|
231
|
-
dir = process.cwd();
|
|
140
|
+
*values() {
|
|
141
|
+
for (const [, values] of this.data) {
|
|
142
|
+
for (const value of values) {
|
|
143
|
+
yield value;
|
|
144
|
+
}
|
|
232
145
|
}
|
|
233
|
-
|
|
234
|
-
|
|
146
|
+
}
|
|
147
|
+
toJSON() {
|
|
148
|
+
const result = {};
|
|
149
|
+
for (const [key, values] of this.data) {
|
|
150
|
+
result[key] = values.length === 1 ? values[0] : values;
|
|
235
151
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
154
|
+
toNodeHeaders() {
|
|
155
|
+
const result = {};
|
|
156
|
+
for (const [key, values] of this.data) {
|
|
157
|
+
if (key === "set-cookie") {
|
|
158
|
+
result[key] = values;
|
|
159
|
+
} else {
|
|
160
|
+
result[key] = values.join(", ");
|
|
161
|
+
}
|
|
240
162
|
}
|
|
241
|
-
|
|
242
|
-
|
|
163
|
+
return result;
|
|
164
|
+
}
|
|
165
|
+
get size() {
|
|
166
|
+
return this.data.size;
|
|
167
|
+
}
|
|
168
|
+
[Symbol.iterator]() {
|
|
169
|
+
return this.entries();
|
|
243
170
|
}
|
|
244
171
|
};
|
|
245
172
|
}
|
|
246
173
|
});
|
|
247
174
|
|
|
248
|
-
//
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
175
|
+
// src/server/http/cookie.ts
|
|
176
|
+
function parseCookies(header) {
|
|
177
|
+
const result = {};
|
|
178
|
+
if (!header) return result;
|
|
179
|
+
const pairs = header.split(";");
|
|
180
|
+
for (const pair of pairs) {
|
|
181
|
+
const trimmed = pair.trim();
|
|
182
|
+
if (!trimmed) continue;
|
|
183
|
+
const eqIndex = trimmed.indexOf("=");
|
|
184
|
+
if (eqIndex === -1) {
|
|
185
|
+
result[trimmed] = "";
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const name = trimmed.slice(0, eqIndex).trim();
|
|
189
|
+
let value = trimmed.slice(eqIndex + 1).trim();
|
|
190
|
+
if (value.startsWith('"') && value.endsWith('"')) {
|
|
191
|
+
value = value.slice(1, -1);
|
|
192
|
+
}
|
|
193
|
+
if (name) {
|
|
194
|
+
result[decodeURIComponent(name)] = decodeURIComponent(value);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
199
|
+
function serializeCookieValue(name, value) {
|
|
200
|
+
return `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
|
|
201
|
+
}
|
|
202
|
+
function serializeCookie(name, value, options) {
|
|
203
|
+
const parts = [serializeCookieValue(name, value)];
|
|
204
|
+
if (options) {
|
|
205
|
+
if (options.maxAge !== void 0) {
|
|
206
|
+
parts.push(`Max-Age=${Math.floor(options.maxAge)}`);
|
|
207
|
+
}
|
|
208
|
+
if (options.expires !== void 0) {
|
|
209
|
+
parts.push(`Expires=${options.expires.toUTCString()}`);
|
|
210
|
+
}
|
|
211
|
+
if (options.path !== void 0) {
|
|
212
|
+
parts.push(`Path=${options.path}`);
|
|
213
|
+
} else {
|
|
214
|
+
parts.push("Path=/");
|
|
215
|
+
}
|
|
216
|
+
if (options.domain !== void 0) {
|
|
217
|
+
parts.push(`Domain=${options.domain}`);
|
|
218
|
+
}
|
|
219
|
+
if (options.secure) {
|
|
220
|
+
parts.push("Secure");
|
|
221
|
+
}
|
|
222
|
+
if (options.httpOnly) {
|
|
223
|
+
parts.push("HttpOnly");
|
|
224
|
+
}
|
|
225
|
+
if (options.sameSite !== void 0) {
|
|
226
|
+
parts.push(`SameSite=${options.sameSite}`);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return parts.join("; ");
|
|
230
|
+
}
|
|
231
|
+
function clearCookie(name, options) {
|
|
232
|
+
return serializeCookie(name, "", {
|
|
233
|
+
...options,
|
|
234
|
+
maxAge: 0,
|
|
235
|
+
expires: /* @__PURE__ */ new Date(0)
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
var init_cookie = __esm({
|
|
239
|
+
"src/server/http/cookie.ts"() {
|
|
240
|
+
"use strict";
|
|
308
241
|
}
|
|
309
242
|
});
|
|
310
243
|
|
|
311
|
-
//
|
|
312
|
-
|
|
313
|
-
|
|
244
|
+
// src/server/http/upload.ts
|
|
245
|
+
import { randomUUID } from "crypto";
|
|
246
|
+
import { writeFile, readFile, unlink, mkdir } from "fs/promises";
|
|
247
|
+
import { join, extname, basename, dirname } from "path";
|
|
248
|
+
import { tmpdir } from "os";
|
|
249
|
+
var IMAGE_MIME_TYPES, VIDEO_MIME_TYPES, SuperUploadedFile;
|
|
250
|
+
var init_upload = __esm({
|
|
251
|
+
"src/server/http/upload.ts"() {
|
|
314
252
|
"use strict";
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
});
|
|
253
|
+
IMAGE_MIME_TYPES = /* @__PURE__ */ new Set([
|
|
254
|
+
"image/jpeg",
|
|
255
|
+
"image/png",
|
|
256
|
+
"image/gif",
|
|
257
|
+
"image/webp",
|
|
258
|
+
"image/svg+xml",
|
|
259
|
+
"image/bmp",
|
|
260
|
+
"image/tiff",
|
|
261
|
+
"image/avif"
|
|
262
|
+
]);
|
|
263
|
+
VIDEO_MIME_TYPES = /* @__PURE__ */ new Set([
|
|
264
|
+
"video/mp4",
|
|
265
|
+
"video/mpeg",
|
|
266
|
+
"video/webm",
|
|
267
|
+
"video/ogg",
|
|
268
|
+
"video/quicktime",
|
|
269
|
+
"video/x-msvideo",
|
|
270
|
+
"video/x-matroska"
|
|
271
|
+
]);
|
|
272
|
+
SuperUploadedFile = class _SuperUploadedFile {
|
|
273
|
+
fieldName;
|
|
274
|
+
originalName;
|
|
275
|
+
mimeType;
|
|
276
|
+
size;
|
|
277
|
+
path;
|
|
278
|
+
extension;
|
|
279
|
+
buffer;
|
|
280
|
+
constructor(opts) {
|
|
281
|
+
this.fieldName = opts.fieldName;
|
|
282
|
+
this.originalName = opts.originalName;
|
|
283
|
+
this.mimeType = opts.mimeType;
|
|
284
|
+
this.size = opts.size;
|
|
285
|
+
this.path = opts.path;
|
|
286
|
+
this.extension = extname(opts.originalName).toLowerCase();
|
|
287
|
+
this.buffer = opts.buffer ?? null;
|
|
351
288
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
undo = rollbackTo;
|
|
360
|
-
} else {
|
|
361
|
-
before = begin;
|
|
362
|
-
after = commit;
|
|
363
|
-
undo = rollback;
|
|
289
|
+
async move(destination, filename) {
|
|
290
|
+
const destName = filename ?? basename(this.path);
|
|
291
|
+
const destPath = join(destination, destName);
|
|
292
|
+
await mkdir(dirname(destPath), { recursive: true });
|
|
293
|
+
const buf = await this.toBuffer();
|
|
294
|
+
await writeFile(destPath, buf);
|
|
295
|
+
return destPath;
|
|
364
296
|
}
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
297
|
+
async toBuffer() {
|
|
298
|
+
if (this.buffer !== null) return this.buffer;
|
|
299
|
+
this.buffer = await readFile(this.path);
|
|
300
|
+
return this.buffer;
|
|
301
|
+
}
|
|
302
|
+
toBase64() {
|
|
303
|
+
if (this.buffer === null) {
|
|
304
|
+
throw new Error(
|
|
305
|
+
"Buffer not loaded. Call toBuffer() first or read the file into memory."
|
|
306
|
+
);
|
|
370
307
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
308
|
+
return this.buffer.toString("base64");
|
|
309
|
+
}
|
|
310
|
+
isImage() {
|
|
311
|
+
return IMAGE_MIME_TYPES.has(this.mimeType);
|
|
312
|
+
}
|
|
313
|
+
isVideo() {
|
|
314
|
+
return VIDEO_MIME_TYPES.has(this.mimeType);
|
|
315
|
+
}
|
|
316
|
+
static async createFromBuffer(fieldName, originalName, mimeType, buffer, tempDir) {
|
|
317
|
+
const tmp = tempDir ?? tmpdir();
|
|
318
|
+
const fileName = `${randomUUID()}${extname(originalName)}`;
|
|
319
|
+
const filePath = join(tmp, fileName);
|
|
320
|
+
await writeFile(filePath, buffer);
|
|
321
|
+
return new _SuperUploadedFile({
|
|
322
|
+
fieldName,
|
|
323
|
+
originalName,
|
|
324
|
+
mimeType: mimeType || "application/octet-stream",
|
|
325
|
+
size: buffer.length,
|
|
326
|
+
path: filePath,
|
|
327
|
+
buffer
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
async cleanup() {
|
|
331
|
+
try {
|
|
332
|
+
await unlink(this.path);
|
|
333
|
+
} catch {
|
|
377
334
|
}
|
|
378
|
-
throw ex;
|
|
379
335
|
}
|
|
380
336
|
};
|
|
381
337
|
}
|
|
382
338
|
});
|
|
383
339
|
|
|
384
|
-
//
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
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
|
-
};
|
|
340
|
+
// src/server/http/request.ts
|
|
341
|
+
function parseQueryParams(searchParams) {
|
|
342
|
+
const result = {};
|
|
343
|
+
for (const key of searchParams.keys()) {
|
|
344
|
+
const values = searchParams.getAll(key);
|
|
345
|
+
result[key] = values.length === 1 ? values[0] : values;
|
|
458
346
|
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
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
|
-
};
|
|
347
|
+
return result;
|
|
348
|
+
}
|
|
349
|
+
function parseIp(req) {
|
|
350
|
+
const forwarded = req.headers["x-forwarded-for"];
|
|
351
|
+
if (forwarded !== void 0) {
|
|
352
|
+
const first = Array.isArray(forwarded) ? forwarded[0] : forwarded.split(",")[0];
|
|
353
|
+
if (first !== void 0) return first.trim();
|
|
474
354
|
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
355
|
+
const realIp = req.headers["x-real-ip"];
|
|
356
|
+
if (realIp !== void 0) {
|
|
357
|
+
return Array.isArray(realIp) ? realIp[0] : realIp;
|
|
358
|
+
}
|
|
359
|
+
const remote = req.socket.remoteAddress;
|
|
360
|
+
if (remote !== void 0) {
|
|
361
|
+
if (remote.startsWith("::ffff:")) return remote.slice(7);
|
|
362
|
+
return remote;
|
|
363
|
+
}
|
|
364
|
+
return "127.0.0.1";
|
|
365
|
+
}
|
|
366
|
+
function parseUrlEncoded(text) {
|
|
367
|
+
const result = {};
|
|
368
|
+
const pairs = text.split("&");
|
|
369
|
+
for (const pair of pairs) {
|
|
370
|
+
if (!pair) continue;
|
|
371
|
+
const eqIndex = pair.indexOf("=");
|
|
372
|
+
if (eqIndex === -1) {
|
|
373
|
+
result[decodeURIComponent(pair)] = "";
|
|
374
|
+
} else {
|
|
375
|
+
const key = decodeURIComponent(pair.slice(0, eqIndex));
|
|
376
|
+
const value = decodeURIComponent(pair.slice(eqIndex + 1));
|
|
377
|
+
result[key] = value;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return result;
|
|
381
|
+
}
|
|
382
|
+
function parseMultipartBody(body, boundary) {
|
|
383
|
+
const result = [];
|
|
384
|
+
const boundaryBuffer = Buffer.from(`--${boundary}`);
|
|
385
|
+
let start = 0;
|
|
386
|
+
let searchFrom = 0;
|
|
387
|
+
while (true) {
|
|
388
|
+
const boundaryIndex = body.indexOf(boundaryBuffer, searchFrom);
|
|
389
|
+
if (boundaryIndex === -1) break;
|
|
390
|
+
searchFrom = boundaryIndex + boundaryBuffer.length;
|
|
391
|
+
if (searchFrom < body.length && body[searchFrom] === 45 && body[searchFrom + 1] === 45) {
|
|
392
|
+
break;
|
|
393
|
+
}
|
|
394
|
+
if (searchFrom >= body.length) break;
|
|
395
|
+
if (body[searchFrom] === 13) searchFrom++;
|
|
396
|
+
if (body[searchFrom] === 10) searchFrom++;
|
|
397
|
+
start = searchFrom;
|
|
398
|
+
const nextBoundaryIndex = body.indexOf(boundaryBuffer, searchFrom);
|
|
399
|
+
if (nextBoundaryIndex === -1) break;
|
|
400
|
+
let partEnd = nextBoundaryIndex;
|
|
401
|
+
if (partEnd >= 2 && body[partEnd - 2] === 13 && body[partEnd - 1] === 10) {
|
|
402
|
+
partEnd -= 2;
|
|
403
|
+
}
|
|
404
|
+
const partData = body.slice(start, partEnd);
|
|
405
|
+
const headerEndIndex = partData.indexOf(Buffer.from("\r\n\r\n"));
|
|
406
|
+
if (headerEndIndex === -1) {
|
|
407
|
+
searchFrom = nextBoundaryIndex;
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
const headerSection = partData.slice(0, headerEndIndex).toString("utf-8");
|
|
411
|
+
const contentData = partData.slice(headerEndIndex + 4);
|
|
412
|
+
const disposition = parseDisposition(headerSection);
|
|
413
|
+
if (disposition === void 0) {
|
|
414
|
+
searchFrom = nextBoundaryIndex;
|
|
415
|
+
continue;
|
|
416
|
+
}
|
|
417
|
+
if (disposition.filename !== void 0) {
|
|
418
|
+
const contentType = parseContentType(headerSection);
|
|
419
|
+
result.push({
|
|
420
|
+
type: "file",
|
|
421
|
+
name: disposition.name,
|
|
422
|
+
filename: disposition.filename,
|
|
423
|
+
mimeType: contentType,
|
|
424
|
+
data: Buffer.from(contentData)
|
|
425
|
+
});
|
|
426
|
+
} else {
|
|
427
|
+
result.push({
|
|
428
|
+
type: "field",
|
|
429
|
+
name: disposition.name,
|
|
430
|
+
value: contentData.toString("utf-8").trim()
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
searchFrom = nextBoundaryIndex;
|
|
434
|
+
}
|
|
435
|
+
return result;
|
|
436
|
+
}
|
|
437
|
+
function parseDisposition(headerSection) {
|
|
438
|
+
const match = headerSection.match(
|
|
439
|
+
/content-disposition:\s*form-data;\s*(.+)/i
|
|
440
|
+
);
|
|
441
|
+
if (match === null) return void 0;
|
|
442
|
+
const params = match[1];
|
|
443
|
+
const nameMatch = params.match(/name="([^"]*)"/i);
|
|
444
|
+
const filenameMatch = params.match(/filename="([^"]*)"/i);
|
|
445
|
+
if (nameMatch === null) return void 0;
|
|
446
|
+
return {
|
|
447
|
+
name: nameMatch[1],
|
|
448
|
+
filename: filenameMatch?.[1]
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
function parseContentType(headerSection) {
|
|
452
|
+
const match = headerSection.match(/content-type:\s*([^\s;]+)/i);
|
|
453
|
+
return match?.[1] ?? "application/octet-stream";
|
|
454
|
+
}
|
|
455
|
+
var SuperRequest, ValidationError;
|
|
456
|
+
var init_request = __esm({
|
|
457
|
+
"src/server/http/request.ts"() {
|
|
480
458
|
"use strict";
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
459
|
+
init_headers();
|
|
460
|
+
init_cookie();
|
|
461
|
+
init_upload();
|
|
462
|
+
SuperRequest = class {
|
|
463
|
+
raw;
|
|
464
|
+
_headers;
|
|
465
|
+
_query;
|
|
466
|
+
_cookies = null;
|
|
467
|
+
_ip;
|
|
468
|
+
_params = {};
|
|
469
|
+
bodyCache = null;
|
|
470
|
+
_bodyReadPromise = null;
|
|
471
|
+
constructor(raw) {
|
|
472
|
+
this.raw = raw;
|
|
473
|
+
this._headers = new HeadersMap(
|
|
474
|
+
raw.headers
|
|
475
|
+
);
|
|
476
|
+
const parsedUrl = new URL(raw.url ?? "/", "http://localhost");
|
|
477
|
+
this._query = parseQueryParams(parsedUrl.searchParams);
|
|
478
|
+
this._ip = parseIp(raw);
|
|
479
|
+
this.path = parsedUrl.pathname;
|
|
480
|
+
this.url = raw.url ?? "/";
|
|
481
|
+
this.method = (raw.method ?? "GET").toUpperCase();
|
|
487
482
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
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");
|
|
483
|
+
method;
|
|
484
|
+
url;
|
|
485
|
+
path;
|
|
486
|
+
get headers() {
|
|
487
|
+
return this._headers;
|
|
501
488
|
}
|
|
502
|
-
|
|
503
|
-
|
|
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");
|
|
489
|
+
get query() {
|
|
490
|
+
return this._query;
|
|
530
491
|
}
|
|
531
|
-
|
|
532
|
-
|
|
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);
|
|
492
|
+
get params() {
|
|
493
|
+
return this._params;
|
|
563
494
|
}
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
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`);
|
|
495
|
+
set params(value) {
|
|
496
|
+
this._params = value;
|
|
497
|
+
}
|
|
498
|
+
get ip() {
|
|
499
|
+
return this._ip;
|
|
500
|
+
}
|
|
501
|
+
async ensureBody() {
|
|
502
|
+
if (this.bodyCache !== null) return this.bodyCache;
|
|
503
|
+
if (this._bodyReadPromise === null) {
|
|
504
|
+
this._bodyReadPromise = this.readBodyFromStream();
|
|
577
505
|
}
|
|
578
|
-
|
|
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`);
|
|
506
|
+
this.bodyCache = await this._bodyReadPromise;
|
|
507
|
+
return this.bodyCache;
|
|
584
508
|
}
|
|
585
|
-
|
|
586
|
-
|
|
509
|
+
async readBodyFromStream() {
|
|
510
|
+
const chunks = [];
|
|
511
|
+
const MAX_BODY_SIZE = 10 * 1024 * 1024;
|
|
512
|
+
let totalSize = 0;
|
|
513
|
+
for await (const chunk of this.raw) {
|
|
514
|
+
const buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
515
|
+
totalSize += buf.length;
|
|
516
|
+
if (totalSize > MAX_BODY_SIZE) {
|
|
517
|
+
throw new Error("Request body too large. Maximum size is 10MB.");
|
|
518
|
+
}
|
|
519
|
+
chunks.push(buf);
|
|
520
|
+
}
|
|
521
|
+
const raw = Buffer.concat(chunks);
|
|
522
|
+
const text = raw.toString("utf-8");
|
|
523
|
+
let json = void 0;
|
|
524
|
+
if (this.isContentType("application/json")) {
|
|
525
|
+
try {
|
|
526
|
+
json = JSON.parse(text);
|
|
527
|
+
} catch {
|
|
528
|
+
json = void 0;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
let formData = null;
|
|
532
|
+
let multipartParsed = null;
|
|
533
|
+
let files = null;
|
|
534
|
+
if (this.isContentType("application/x-www-form-urlencoded")) {
|
|
535
|
+
formData = parseUrlEncoded(text);
|
|
536
|
+
} else if (this.isContentType("multipart/form-data")) {
|
|
537
|
+
const boundary = this.getMultipartBoundary();
|
|
538
|
+
if (boundary !== void 0) {
|
|
539
|
+
multipartParsed = parseMultipartBody(raw, boundary);
|
|
540
|
+
formData = {};
|
|
541
|
+
files = {};
|
|
542
|
+
for (const part of multipartParsed) {
|
|
543
|
+
if (part.type === "field") {
|
|
544
|
+
formData[part.name] = part.value;
|
|
545
|
+
} else if (part.type === "file") {
|
|
546
|
+
const uploadedFile = await SuperUploadedFile.createFromBuffer(
|
|
547
|
+
part.name,
|
|
548
|
+
part.filename,
|
|
549
|
+
part.mimeType,
|
|
550
|
+
part.data
|
|
551
|
+
);
|
|
552
|
+
files[part.name] = uploadedFile;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
return {
|
|
558
|
+
raw,
|
|
559
|
+
text,
|
|
560
|
+
json,
|
|
561
|
+
parsed: json ?? text,
|
|
562
|
+
formData,
|
|
563
|
+
files,
|
|
564
|
+
multipartParsed
|
|
565
|
+
};
|
|
587
566
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
567
|
+
isContentType(expected) {
|
|
568
|
+
const ct = this._headers.get("content-type");
|
|
569
|
+
if (ct === void 0) return false;
|
|
570
|
+
return ct.toLowerCase().startsWith(expected);
|
|
591
571
|
}
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
572
|
+
getMultipartBoundary() {
|
|
573
|
+
const ct = this._headers.get("content-type");
|
|
574
|
+
if (ct === void 0) return void 0;
|
|
575
|
+
const match = ct.match(/boundary=(?:"([^"]+)"|([^;]+))/i);
|
|
576
|
+
if (match !== null) {
|
|
577
|
+
return match[1] ?? match[2];
|
|
578
|
+
}
|
|
579
|
+
return void 0;
|
|
595
580
|
}
|
|
596
|
-
|
|
597
|
-
|
|
581
|
+
async body() {
|
|
582
|
+
const cache = await this.ensureBody();
|
|
583
|
+
return cache.parsed;
|
|
598
584
|
}
|
|
599
|
-
|
|
600
|
-
|
|
585
|
+
async json() {
|
|
586
|
+
const cache = await this.ensureBody();
|
|
587
|
+
if (cache.json !== void 0) return cache.json;
|
|
588
|
+
throw new Error("Request body is not valid JSON");
|
|
601
589
|
}
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
590
|
+
async text() {
|
|
591
|
+
const cache = await this.ensureBody();
|
|
592
|
+
return cache.text;
|
|
593
|
+
}
|
|
594
|
+
async formData() {
|
|
595
|
+
const cache = await this.ensureBody();
|
|
596
|
+
if (cache.formData !== null) return cache.formData;
|
|
597
|
+
if (cache.multipartParsed !== null) {
|
|
598
|
+
const result = {};
|
|
599
|
+
for (const part of cache.multipartParsed) {
|
|
600
|
+
if (part.type === "field") {
|
|
601
|
+
result[part.name] = part.value;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
return result;
|
|
607
605
|
}
|
|
608
|
-
|
|
609
|
-
parameters = inferParameters(rows);
|
|
606
|
+
return {};
|
|
610
607
|
}
|
|
611
|
-
|
|
612
|
-
|
|
608
|
+
async file(name) {
|
|
609
|
+
const cache = await this.ensureBody();
|
|
610
|
+
if (cache.files !== null) {
|
|
611
|
+
return cache.files[name];
|
|
612
|
+
}
|
|
613
|
+
return void 0;
|
|
613
614
|
}
|
|
614
|
-
|
|
615
|
-
|
|
615
|
+
async files() {
|
|
616
|
+
const cache = await this.ensureBody();
|
|
617
|
+
return cache.files ?? {};
|
|
616
618
|
}
|
|
617
|
-
|
|
618
|
-
if (
|
|
619
|
-
|
|
619
|
+
cookie(name) {
|
|
620
|
+
if (this._cookies === null) {
|
|
621
|
+
const cookieHeader = this._headers.get("cookie");
|
|
622
|
+
this._cookies = cookieHeader !== void 0 ? parseCookies(cookieHeader) : {};
|
|
620
623
|
}
|
|
624
|
+
return this._cookies[name];
|
|
621
625
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
const
|
|
625
|
-
if (
|
|
626
|
-
|
|
626
|
+
async validate(schema) {
|
|
627
|
+
const data = await this.body();
|
|
628
|
+
const result = schema.validate(data);
|
|
629
|
+
if (!result.success) {
|
|
630
|
+
const messages = (result.errors ?? []).map((e) => {
|
|
631
|
+
const path3 = e.path ?? "";
|
|
632
|
+
return path3 ? `${path3}: ${e.message}` : e.message;
|
|
633
|
+
}).join("; ");
|
|
634
|
+
throw new ValidationError(messages, result.errors ?? []);
|
|
627
635
|
}
|
|
628
|
-
|
|
636
|
+
return result.data;
|
|
629
637
|
}
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
638
|
+
isAjax() {
|
|
639
|
+
const requestedWith = this._headers.get("x-requested-with");
|
|
640
|
+
return requestedWith?.toLowerCase() === "xmlhttprequest";
|
|
641
|
+
}
|
|
642
|
+
wantsJson() {
|
|
643
|
+
const accept = this._headers.get("accept");
|
|
644
|
+
if (accept !== void 0 && accept.includes("application/json")) {
|
|
645
|
+
return true;
|
|
635
646
|
}
|
|
647
|
+
return this.isAjax();
|
|
636
648
|
}
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
649
|
+
bearerToken() {
|
|
650
|
+
const auth = this._headers.get("authorization");
|
|
651
|
+
if (auth === void 0) return void 0;
|
|
652
|
+
const match = auth.match(/^Bearer\s+(.+)$/i);
|
|
653
|
+
return match?.[1];
|
|
654
|
+
}
|
|
655
|
+
get rawRequest() {
|
|
656
|
+
return this.raw;
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
ValidationError = class extends Error {
|
|
660
|
+
constructor(message, errors) {
|
|
661
|
+
super(message);
|
|
662
|
+
this.errors = errors;
|
|
663
|
+
this.name = "ValidationError";
|
|
664
|
+
}
|
|
665
|
+
errors;
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
});
|
|
669
|
+
|
|
670
|
+
// src/server/http/response.ts
|
|
671
|
+
import { createReadStream, stat } from "fs";
|
|
672
|
+
import { basename as basename2, extname as extname2, resolve } from "path";
|
|
673
|
+
import { promisify } from "util";
|
|
674
|
+
function joinPath(root, filePath) {
|
|
675
|
+
const normalizedRoot = root.replace(/\\/g, "/").replace(/\/$/, "");
|
|
676
|
+
const normalizedPath = filePath.replace(/\\/g, "/").replace(/^\//, "");
|
|
677
|
+
return `${normalizedRoot}/${normalizedPath}`;
|
|
678
|
+
}
|
|
679
|
+
var statAsync, MIME_TYPES, SuperResponse;
|
|
680
|
+
var init_response = __esm({
|
|
681
|
+
"src/server/http/response.ts"() {
|
|
682
|
+
"use strict";
|
|
683
|
+
init_cookie();
|
|
684
|
+
init_headers();
|
|
685
|
+
init_status();
|
|
686
|
+
statAsync = promisify(stat);
|
|
687
|
+
MIME_TYPES = {
|
|
688
|
+
".html": "text/html",
|
|
689
|
+
".css": "text/css",
|
|
690
|
+
".js": "application/javascript",
|
|
691
|
+
".mjs": "application/javascript",
|
|
692
|
+
".json": "application/json",
|
|
693
|
+
".png": "image/png",
|
|
694
|
+
".jpg": "image/jpeg",
|
|
695
|
+
".jpeg": "image/jpeg",
|
|
696
|
+
".gif": "image/gif",
|
|
697
|
+
".svg": "image/svg+xml",
|
|
698
|
+
".webp": "image/webp",
|
|
699
|
+
".ico": "image/x-icon",
|
|
700
|
+
".pdf": "application/pdf",
|
|
701
|
+
".txt": "text/plain",
|
|
702
|
+
".xml": "application/xml",
|
|
703
|
+
".zip": "application/zip",
|
|
704
|
+
".woff": "font/woff",
|
|
705
|
+
".woff2": "font/woff2",
|
|
706
|
+
".ttf": "font/ttf",
|
|
707
|
+
".eot": "application/vnd.ms-fontobject",
|
|
708
|
+
".mp4": "video/mp4",
|
|
709
|
+
".webm": "video/webm",
|
|
710
|
+
".mp3": "audio/mpeg",
|
|
711
|
+
".wav": "audio/wav"
|
|
712
|
+
};
|
|
713
|
+
SuperResponse = class {
|
|
714
|
+
raw;
|
|
715
|
+
_statusCode = HttpStatus.OK;
|
|
716
|
+
_headers = new HeadersMap();
|
|
717
|
+
_cookies = [];
|
|
718
|
+
_body = null;
|
|
719
|
+
_sent = false;
|
|
720
|
+
_contentTypeSet = false;
|
|
721
|
+
constructor(raw) {
|
|
722
|
+
this.raw = raw;
|
|
723
|
+
}
|
|
724
|
+
status(code) {
|
|
725
|
+
this._statusCode = code;
|
|
726
|
+
return this;
|
|
727
|
+
}
|
|
728
|
+
header(name, value) {
|
|
729
|
+
this._headers.set(name, value);
|
|
730
|
+
return this;
|
|
731
|
+
}
|
|
732
|
+
setHeader(name, value) {
|
|
733
|
+
return this.header(name, value);
|
|
734
|
+
}
|
|
735
|
+
getHeader(name) {
|
|
736
|
+
return this._headers.get(name);
|
|
737
|
+
}
|
|
738
|
+
removeHeader(name) {
|
|
739
|
+
this._headers.delete(name);
|
|
740
|
+
return this;
|
|
741
|
+
}
|
|
742
|
+
hasHeader(name) {
|
|
743
|
+
return this._headers.has(name);
|
|
744
|
+
}
|
|
745
|
+
type(contentType) {
|
|
746
|
+
this._headers.set("content-type", contentType);
|
|
747
|
+
this._contentTypeSet = true;
|
|
748
|
+
return this;
|
|
749
|
+
}
|
|
750
|
+
json(data, status) {
|
|
751
|
+
if (status !== void 0) this._statusCode = status;
|
|
752
|
+
const body = JSON.stringify(data);
|
|
753
|
+
return this.send(body, void 0, "application/json");
|
|
754
|
+
}
|
|
755
|
+
send(body, status, contentType) {
|
|
756
|
+
if (status !== void 0) this._statusCode = status;
|
|
757
|
+
this._body = body;
|
|
758
|
+
if (contentType !== void 0 && !this._contentTypeSet) {
|
|
759
|
+
this._headers.set("content-type", contentType);
|
|
654
760
|
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
761
|
+
return this;
|
|
762
|
+
}
|
|
763
|
+
html(html, status) {
|
|
764
|
+
return this.send(html, status, "text/html; charset=utf-8");
|
|
765
|
+
}
|
|
766
|
+
redirect(url2, status = HttpStatus.FOUND) {
|
|
767
|
+
if (url2.includes("\r") || url2.includes("\n")) {
|
|
768
|
+
throw new Error("Invalid redirect URL");
|
|
769
|
+
}
|
|
770
|
+
this._statusCode = status;
|
|
771
|
+
this._headers.set("location", url2);
|
|
772
|
+
this._body = null;
|
|
773
|
+
return this;
|
|
774
|
+
}
|
|
775
|
+
stream(stream, status) {
|
|
776
|
+
if (status !== void 0) this._statusCode = status;
|
|
777
|
+
this.flushHeaders();
|
|
778
|
+
this.raw.statusCode = this._statusCode;
|
|
779
|
+
stream.pipe(this.raw);
|
|
780
|
+
stream.on("end", () => {
|
|
781
|
+
this._sent = true;
|
|
782
|
+
});
|
|
783
|
+
stream.on("error", (_err) => {
|
|
784
|
+
if (!this._sent) {
|
|
785
|
+
this._sent = true;
|
|
786
|
+
this.raw.statusCode = HttpStatus.INTERNAL_SERVER_ERROR;
|
|
787
|
+
this.raw.end();
|
|
664
788
|
}
|
|
789
|
+
});
|
|
790
|
+
return this;
|
|
791
|
+
}
|
|
792
|
+
async file(filePath, options) {
|
|
793
|
+
const fullPath = options?.root ? joinPath(options.root, filePath) : filePath;
|
|
794
|
+
const resolved = resolve(fullPath);
|
|
795
|
+
const root = options?.root ? resolve(options.root) : null;
|
|
796
|
+
if (root !== null && !resolved.startsWith(root)) {
|
|
797
|
+
this._statusCode = HttpStatus.FORBIDDEN;
|
|
798
|
+
this._body = null;
|
|
799
|
+
return this;
|
|
665
800
|
}
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
801
|
+
try {
|
|
802
|
+
const stats = await statAsync(fullPath);
|
|
803
|
+
if (!stats.isFile()) {
|
|
804
|
+
this._statusCode = HttpStatus.NOT_FOUND;
|
|
805
|
+
this._body = null;
|
|
806
|
+
return this;
|
|
807
|
+
}
|
|
808
|
+
const ext = extname2(fullPath);
|
|
809
|
+
const mimeType = MIME_TYPES[ext] ?? "application/octet-stream";
|
|
810
|
+
this._headers.set("content-type", mimeType);
|
|
811
|
+
this._headers.set("content-length", String(stats.size));
|
|
812
|
+
if (options?.cacheControl !== false) {
|
|
813
|
+
const maxAge = options?.maxAge ?? 0;
|
|
814
|
+
this._headers.set("cache-control", `public, max-age=${maxAge}`);
|
|
815
|
+
}
|
|
816
|
+
if (options?.lastModified !== false) {
|
|
817
|
+
this._headers.set("last-modified", stats.mtime.toUTCString());
|
|
818
|
+
}
|
|
819
|
+
if (options?.headers !== void 0) {
|
|
820
|
+
for (const [key, value] of Object.entries(options.headers)) {
|
|
821
|
+
this._headers.set(key, value);
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
this.flushHeaders();
|
|
825
|
+
this.raw.statusCode = this._statusCode;
|
|
826
|
+
const readStream = createReadStream(fullPath);
|
|
827
|
+
readStream.pipe(this.raw);
|
|
828
|
+
readStream.on("end", () => {
|
|
829
|
+
this._sent = true;
|
|
830
|
+
});
|
|
831
|
+
readStream.on("error", () => {
|
|
832
|
+
if (!this._sent) {
|
|
833
|
+
this._sent = true;
|
|
834
|
+
this.raw.statusCode = HttpStatus.INTERNAL_SERVER_ERROR;
|
|
835
|
+
this.raw.end();
|
|
836
|
+
}
|
|
837
|
+
});
|
|
838
|
+
} catch {
|
|
839
|
+
this._statusCode = HttpStatus.NOT_FOUND;
|
|
840
|
+
this._body = null;
|
|
841
|
+
}
|
|
842
|
+
return this;
|
|
671
843
|
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
844
|
+
async download(filePath, filename) {
|
|
845
|
+
const downloadName = filename ?? basename2(filePath);
|
|
846
|
+
this._headers.set(
|
|
847
|
+
"content-disposition",
|
|
848
|
+
`attachment; filename="${downloadName}"`
|
|
849
|
+
);
|
|
850
|
+
await this.file(filePath);
|
|
851
|
+
return this;
|
|
675
852
|
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
853
|
+
attachment(filename) {
|
|
854
|
+
if (filename !== void 0) {
|
|
855
|
+
this._headers.set(
|
|
856
|
+
"content-disposition",
|
|
857
|
+
`attachment; filename="${filename}"`
|
|
858
|
+
);
|
|
859
|
+
} else {
|
|
860
|
+
this._headers.set("content-disposition", "attachment");
|
|
683
861
|
}
|
|
684
|
-
|
|
685
|
-
count += 1;
|
|
862
|
+
return this;
|
|
686
863
|
}
|
|
687
|
-
|
|
688
|
-
|
|
864
|
+
cookie(name, value, options) {
|
|
865
|
+
this._cookies.push(serializeCookie(name, value, options));
|
|
866
|
+
return this;
|
|
689
867
|
}
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
throw new TypeError("Expected function.length to be a positive integer");
|
|
868
|
+
clearCookie(name, options) {
|
|
869
|
+
this._cookies.push(clearCookie(name, options));
|
|
870
|
+
return this;
|
|
694
871
|
}
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
params.push(`$${i + 1}`);
|
|
872
|
+
get statusCode() {
|
|
873
|
+
return this._statusCode;
|
|
698
874
|
}
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
875
|
+
get headersSent() {
|
|
876
|
+
return this._sent;
|
|
877
|
+
}
|
|
878
|
+
get rawResponse() {
|
|
879
|
+
return this.raw;
|
|
880
|
+
}
|
|
881
|
+
async flush() {
|
|
882
|
+
if (this._sent) return;
|
|
883
|
+
this._sent = true;
|
|
884
|
+
this.flushHeaders();
|
|
885
|
+
this.raw.statusCode = this._statusCode;
|
|
886
|
+
if (this._body !== null) {
|
|
887
|
+
this.raw.end(this._body);
|
|
888
|
+
} else {
|
|
889
|
+
this.raw.end();
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
flushHeaders() {
|
|
893
|
+
if (this._cookies.length > 0) {
|
|
894
|
+
this.raw.setHeader("Set-Cookie", this._cookies);
|
|
895
|
+
}
|
|
896
|
+
for (const [name, value] of this._headers.entries()) {
|
|
897
|
+
if (name.toLowerCase() !== "set-cookie") {
|
|
898
|
+
this.raw.setHeader(name, value);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
};
|
|
707
903
|
}
|
|
708
904
|
});
|
|
709
905
|
|
|
710
|
-
//
|
|
711
|
-
|
|
712
|
-
|
|
906
|
+
// src/server/errors.ts
|
|
907
|
+
function registerExceptionHandler(exceptionType, handler) {
|
|
908
|
+
exceptionHandlers.set(exceptionType, handler);
|
|
909
|
+
}
|
|
910
|
+
function getDefaultErrorName(status) {
|
|
911
|
+
const names = {
|
|
912
|
+
400: "BAD_REQUEST",
|
|
913
|
+
401: "UNAUTHORIZED",
|
|
914
|
+
403: "FORBIDDEN",
|
|
915
|
+
404: "NOT_FOUND",
|
|
916
|
+
405: "METHOD_NOT_ALLOWED",
|
|
917
|
+
409: "CONFLICT",
|
|
918
|
+
422: "UNPROCESSABLE_ENTITY",
|
|
919
|
+
429: "TOO_MANY_REQUESTS",
|
|
920
|
+
500: "INTERNAL_SERVER_ERROR",
|
|
921
|
+
503: "SERVICE_UNAVAILABLE"
|
|
922
|
+
};
|
|
923
|
+
return names[status] ?? "UNKNOWN_ERROR";
|
|
924
|
+
}
|
|
925
|
+
function normalizeError(_err) {
|
|
926
|
+
const err = _err instanceof Error ? _err : new Error(String(_err));
|
|
927
|
+
if (err instanceof HttpException) {
|
|
928
|
+
const handler = exceptionHandlers.get(err.constructor);
|
|
929
|
+
if (handler !== void 0) {
|
|
930
|
+
const result = handler(err);
|
|
931
|
+
if (result instanceof Promise) {
|
|
932
|
+
return result;
|
|
933
|
+
}
|
|
934
|
+
return result;
|
|
935
|
+
}
|
|
936
|
+
return err;
|
|
937
|
+
}
|
|
938
|
+
if (process.env.NODE_ENV === "production") {
|
|
939
|
+
return new InternalServerErrorException();
|
|
940
|
+
}
|
|
941
|
+
return new InternalServerErrorException(err.message);
|
|
942
|
+
}
|
|
943
|
+
var HttpException, BadRequestException, UnauthorizedException, ForbiddenException, NotFoundException, MethodNotAllowedException, ConflictException, UnprocessableEntityException, TooManyRequestsException, InternalServerErrorException, ServiceUnavailableException, ValidationException, exceptionHandlers;
|
|
944
|
+
var init_errors = __esm({
|
|
945
|
+
"src/server/errors.ts"() {
|
|
713
946
|
"use strict";
|
|
714
|
-
|
|
947
|
+
HttpException = class extends Error {
|
|
948
|
+
status;
|
|
949
|
+
error;
|
|
950
|
+
constructor(message, status = 500, error) {
|
|
951
|
+
super(message);
|
|
952
|
+
this.name = "HttpException";
|
|
953
|
+
this.status = status;
|
|
954
|
+
this.error = error ?? getDefaultErrorName(status);
|
|
955
|
+
}
|
|
956
|
+
toJSON() {
|
|
957
|
+
return {
|
|
958
|
+
error: this.error,
|
|
959
|
+
message: this.message,
|
|
960
|
+
statusCode: this.status
|
|
961
|
+
};
|
|
962
|
+
}
|
|
715
963
|
};
|
|
716
|
-
|
|
717
|
-
|
|
964
|
+
BadRequestException = class extends HttpException {
|
|
965
|
+
constructor(message = "Bad Request") {
|
|
966
|
+
super(message, 400, "BAD_REQUEST");
|
|
967
|
+
}
|
|
718
968
|
};
|
|
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);
|
|
969
|
+
UnauthorizedException = class extends HttpException {
|
|
970
|
+
constructor(message = "Unauthorized") {
|
|
971
|
+
super(message, 401, "UNAUTHORIZED");
|
|
734
972
|
}
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
973
|
+
};
|
|
974
|
+
ForbiddenException = class extends HttpException {
|
|
975
|
+
constructor(message = "Forbidden") {
|
|
976
|
+
super(message, 403, "FORBIDDEN");
|
|
739
977
|
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
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;
|
|
978
|
+
};
|
|
979
|
+
NotFoundException = class extends HttpException {
|
|
980
|
+
constructor(message = "Not Found") {
|
|
981
|
+
super(message, 404, "NOT_FOUND");
|
|
766
982
|
}
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
983
|
+
};
|
|
984
|
+
MethodNotAllowedException = class extends HttpException {
|
|
985
|
+
constructor(message = "Method Not Allowed") {
|
|
986
|
+
super(message, 405, "METHOD_NOT_ALLOWED");
|
|
770
987
|
}
|
|
771
|
-
|
|
772
|
-
|
|
988
|
+
};
|
|
989
|
+
ConflictException = class extends HttpException {
|
|
990
|
+
constructor(message = "Conflict") {
|
|
991
|
+
super(message, 409, "CONFLICT");
|
|
773
992
|
}
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
993
|
+
};
|
|
994
|
+
UnprocessableEntityException = class extends HttpException {
|
|
995
|
+
constructor(message = "Unprocessable Entity") {
|
|
996
|
+
super(message, 422, "UNPROCESSABLE_ENTITY");
|
|
997
|
+
}
|
|
998
|
+
};
|
|
999
|
+
TooManyRequestsException = class extends HttpException {
|
|
1000
|
+
constructor(message = "Too Many Requests") {
|
|
1001
|
+
super(message, 429, "TOO_MANY_REQUESTS");
|
|
1002
|
+
}
|
|
1003
|
+
};
|
|
1004
|
+
InternalServerErrorException = class extends HttpException {
|
|
1005
|
+
constructor(message = "Internal Server Error") {
|
|
1006
|
+
super(message, 500, "INTERNAL_SERVER_ERROR");
|
|
1007
|
+
}
|
|
1008
|
+
};
|
|
1009
|
+
ServiceUnavailableException = class extends HttpException {
|
|
1010
|
+
constructor(message = "Service Unavailable") {
|
|
1011
|
+
super(message, 503, "SERVICE_UNAVAILABLE");
|
|
1012
|
+
}
|
|
1013
|
+
};
|
|
1014
|
+
ValidationException = class extends HttpException {
|
|
1015
|
+
errors;
|
|
1016
|
+
constructor(errors, message = "Validation Failed") {
|
|
1017
|
+
super(message, 422, "VALIDATION_ERROR");
|
|
1018
|
+
this.errors = errors;
|
|
1019
|
+
}
|
|
1020
|
+
toJSON() {
|
|
1021
|
+
return {
|
|
1022
|
+
error: this.error,
|
|
1023
|
+
message: this.message,
|
|
1024
|
+
statusCode: this.status,
|
|
1025
|
+
errors: this.errors
|
|
1026
|
+
};
|
|
1027
|
+
}
|
|
1028
|
+
};
|
|
1029
|
+
exceptionHandlers = /* @__PURE__ */ new Map();
|
|
795
1030
|
}
|
|
796
1031
|
});
|
|
797
1032
|
|
|
798
|
-
// node_modules/better-sqlite3/lib/
|
|
799
|
-
var
|
|
800
|
-
"node_modules/better-sqlite3/lib/
|
|
1033
|
+
// node_modules/better-sqlite3/lib/util.js
|
|
1034
|
+
var require_util = __commonJS({
|
|
1035
|
+
"node_modules/better-sqlite3/lib/util.js"(exports) {
|
|
801
1036
|
"use strict";
|
|
802
|
-
|
|
803
|
-
|
|
1037
|
+
exports.getBooleanOption = (options, key) => {
|
|
1038
|
+
let value = false;
|
|
1039
|
+
if (key in options && typeof (value = options[key]) !== "boolean") {
|
|
1040
|
+
throw new TypeError(`Expected the "${key}" option to be a boolean`);
|
|
1041
|
+
}
|
|
1042
|
+
return value;
|
|
1043
|
+
};
|
|
1044
|
+
exports.cppdb = /* @__PURE__ */ Symbol();
|
|
1045
|
+
exports.inspect = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
804
1046
|
}
|
|
805
1047
|
});
|
|
806
1048
|
|
|
807
|
-
//
|
|
808
|
-
var
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
singleton(name, factory) {
|
|
816
|
-
this.bindings.set(name, { factory, singleton: true });
|
|
817
|
-
return this;
|
|
818
|
-
}
|
|
819
|
-
instance(name, instance) {
|
|
820
|
-
this.bindings.set(name, {
|
|
821
|
-
factory: () => instance,
|
|
822
|
-
singleton: true,
|
|
823
|
-
instance
|
|
824
|
-
});
|
|
825
|
-
return this;
|
|
826
|
-
}
|
|
827
|
-
resolve(name) {
|
|
828
|
-
const binding = this.bindings.get(name);
|
|
829
|
-
if (binding === void 0) {
|
|
830
|
-
throw new Error(`Binding not found: ${name}`);
|
|
831
|
-
}
|
|
832
|
-
if (binding.singleton && binding.instance !== void 0) {
|
|
833
|
-
return binding.instance;
|
|
834
|
-
}
|
|
835
|
-
if (this.resolving.has(name)) {
|
|
836
|
-
throw new Error(
|
|
837
|
-
`Circular dependency detected: ${name} is already being resolved`
|
|
838
|
-
);
|
|
839
|
-
}
|
|
840
|
-
this.resolving.add(name);
|
|
841
|
-
try {
|
|
842
|
-
const instance = binding.factory();
|
|
843
|
-
if (binding.singleton) {
|
|
844
|
-
binding.instance = instance;
|
|
1049
|
+
// node_modules/better-sqlite3/lib/sqlite-error.js
|
|
1050
|
+
var require_sqlite_error = __commonJS({
|
|
1051
|
+
"node_modules/better-sqlite3/lib/sqlite-error.js"(exports, module) {
|
|
1052
|
+
"use strict";
|
|
1053
|
+
var descriptor = { value: "SqliteError", writable: true, enumerable: false, configurable: true };
|
|
1054
|
+
function SqliteError(message, code) {
|
|
1055
|
+
if (new.target !== SqliteError) {
|
|
1056
|
+
return new SqliteError(message, code);
|
|
845
1057
|
}
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
1058
|
+
if (typeof code !== "string") {
|
|
1059
|
+
throw new TypeError("Expected second argument to be a string");
|
|
1060
|
+
}
|
|
1061
|
+
Error.call(this, message);
|
|
1062
|
+
descriptor.value = "" + message;
|
|
1063
|
+
Object.defineProperty(this, "message", descriptor);
|
|
1064
|
+
Error.captureStackTrace(this, SqliteError);
|
|
1065
|
+
this.code = code;
|
|
849
1066
|
}
|
|
1067
|
+
Object.setPrototypeOf(SqliteError, Error);
|
|
1068
|
+
Object.setPrototypeOf(SqliteError.prototype, Error.prototype);
|
|
1069
|
+
Object.defineProperty(SqliteError.prototype, "name", descriptor);
|
|
1070
|
+
module.exports = SqliteError;
|
|
850
1071
|
}
|
|
851
|
-
|
|
852
|
-
return this.bindings.has(name);
|
|
853
|
-
}
|
|
854
|
-
remove(name) {
|
|
855
|
-
this.bindings.delete(name);
|
|
856
|
-
}
|
|
857
|
-
clear() {
|
|
858
|
-
this.bindings.clear();
|
|
859
|
-
this.resolving.clear();
|
|
860
|
-
}
|
|
861
|
-
getBindings() {
|
|
862
|
-
return new Map(this.bindings);
|
|
863
|
-
}
|
|
864
|
-
};
|
|
865
|
-
|
|
866
|
-
// src/server/http/status.ts
|
|
867
|
-
var HttpStatus = {
|
|
868
|
-
OK: 200,
|
|
869
|
-
CREATED: 201,
|
|
870
|
-
ACCEPTED: 202,
|
|
871
|
-
NO_CONTENT: 204,
|
|
872
|
-
RESET_CONTENT: 205,
|
|
873
|
-
PARTIAL_CONTENT: 206,
|
|
874
|
-
MOVED_PERMANENTLY: 301,
|
|
875
|
-
FOUND: 302,
|
|
876
|
-
SEE_OTHER: 303,
|
|
877
|
-
NOT_MODIFIED: 304,
|
|
878
|
-
TEMPORARY_REDIRECT: 307,
|
|
879
|
-
PERMANENT_REDIRECT: 308,
|
|
880
|
-
BAD_REQUEST: 400,
|
|
881
|
-
UNAUTHORIZED: 401,
|
|
882
|
-
PAYMENT_REQUIRED: 402,
|
|
883
|
-
FORBIDDEN: 403,
|
|
884
|
-
NOT_FOUND: 404,
|
|
885
|
-
METHOD_NOT_ALLOWED: 405,
|
|
886
|
-
NOT_ACCEPTABLE: 406,
|
|
887
|
-
REQUEST_TIMEOUT: 408,
|
|
888
|
-
CONFLICT: 409,
|
|
889
|
-
GONE: 410,
|
|
890
|
-
LENGTH_REQUIRED: 411,
|
|
891
|
-
PRECONDITION_FAILED: 412,
|
|
892
|
-
PAYLOAD_TOO_LARGE: 413,
|
|
893
|
-
URI_TOO_LONG: 414,
|
|
894
|
-
UNSUPPORTED_MEDIA_TYPE: 415,
|
|
895
|
-
UNPROCESSABLE_ENTITY: 422,
|
|
896
|
-
TOO_MANY_REQUESTS: 429,
|
|
897
|
-
INTERNAL_SERVER_ERROR: 500,
|
|
898
|
-
NOT_IMPLEMENTED: 501,
|
|
899
|
-
BAD_GATEWAY: 502,
|
|
900
|
-
SERVICE_UNAVAILABLE: 503,
|
|
901
|
-
GATEWAY_TIMEOUT: 504,
|
|
902
|
-
HTTP_VERSION_NOT_SUPPORTED: 505
|
|
903
|
-
};
|
|
904
|
-
|
|
905
|
-
// src/server/controller/index.ts
|
|
906
|
-
var controllerPrefixMap = /* @__PURE__ */ new WeakMap();
|
|
907
|
-
var controllerRoutesMap = /* @__PURE__ */ new WeakMap();
|
|
908
|
-
function createRouteDecorator(method) {
|
|
909
|
-
return (path3) => {
|
|
910
|
-
return (target, context) => {
|
|
911
|
-
const classTarget = context.static ? target : target.constructor;
|
|
912
|
-
const routes = controllerRoutesMap.get(classTarget) ?? [];
|
|
913
|
-
routes.push({ method, path: path3, handler: context.name });
|
|
914
|
-
controllerRoutesMap.set(classTarget, routes);
|
|
915
|
-
};
|
|
916
|
-
};
|
|
917
|
-
}
|
|
918
|
-
var get = createRouteDecorator("GET");
|
|
919
|
-
var post = createRouteDecorator("POST");
|
|
920
|
-
var put = createRouteDecorator("PUT");
|
|
921
|
-
var patch = createRouteDecorator("PATCH");
|
|
922
|
-
var del = createRouteDecorator("DELETE");
|
|
923
|
-
function getControllerPrefix(controllerClass) {
|
|
924
|
-
return controllerPrefixMap.get(controllerClass) ?? "";
|
|
925
|
-
}
|
|
926
|
-
function getControllerRoutes(controllerClass) {
|
|
927
|
-
return controllerRoutesMap.get(controllerClass) ?? [];
|
|
928
|
-
}
|
|
929
|
-
|
|
930
|
-
// src/server/engine/index.ts
|
|
931
|
-
import { createServer as createHttpServer } from "http";
|
|
1072
|
+
});
|
|
932
1073
|
|
|
933
|
-
//
|
|
934
|
-
var
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
this.set(key, Array.isArray(value) ? value.join(", ") : value);
|
|
943
|
-
}
|
|
1074
|
+
// node_modules/file-uri-to-path/index.js
|
|
1075
|
+
var require_file_uri_to_path = __commonJS({
|
|
1076
|
+
"node_modules/file-uri-to-path/index.js"(exports, module) {
|
|
1077
|
+
"use strict";
|
|
1078
|
+
var sep = __require("path").sep || "/";
|
|
1079
|
+
module.exports = fileUriToPath;
|
|
1080
|
+
function fileUriToPath(uri) {
|
|
1081
|
+
if ("string" != typeof uri || uri.length <= 7 || "file://" != uri.substring(0, 7)) {
|
|
1082
|
+
throw new TypeError("must pass in a file:// URI to convert to a file path");
|
|
944
1083
|
}
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
return void 0;
|
|
953
|
-
}
|
|
954
|
-
getAll(name) {
|
|
955
|
-
const values = this.data.get(name.toLowerCase());
|
|
956
|
-
return values ?? [];
|
|
957
|
-
}
|
|
958
|
-
set(name, value) {
|
|
959
|
-
this.data.set(name.toLowerCase(), [value]);
|
|
960
|
-
}
|
|
961
|
-
append(name, value) {
|
|
962
|
-
const key = name.toLowerCase();
|
|
963
|
-
const existing = this.data.get(key);
|
|
964
|
-
if (existing !== void 0) {
|
|
965
|
-
existing.push(value);
|
|
966
|
-
} else {
|
|
967
|
-
this.data.set(key, [value]);
|
|
968
|
-
}
|
|
969
|
-
}
|
|
970
|
-
has(name) {
|
|
971
|
-
return this.data.has(name.toLowerCase());
|
|
972
|
-
}
|
|
973
|
-
delete(name) {
|
|
974
|
-
this.data.delete(name.toLowerCase());
|
|
975
|
-
}
|
|
976
|
-
*entries() {
|
|
977
|
-
for (const [key, values] of this.data) {
|
|
978
|
-
for (const value of values) {
|
|
979
|
-
yield [key, value];
|
|
1084
|
+
var rest = decodeURI(uri.substring(7));
|
|
1085
|
+
var firstSlash = rest.indexOf("/");
|
|
1086
|
+
var host = rest.substring(0, firstSlash);
|
|
1087
|
+
var path3 = rest.substring(firstSlash + 1);
|
|
1088
|
+
if ("localhost" == host) host = "";
|
|
1089
|
+
if (host) {
|
|
1090
|
+
host = sep + sep + host;
|
|
980
1091
|
}
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
for (const key of this.data.keys()) {
|
|
985
|
-
yield key;
|
|
986
|
-
}
|
|
987
|
-
}
|
|
988
|
-
*values() {
|
|
989
|
-
for (const [, values] of this.data) {
|
|
990
|
-
for (const value of values) {
|
|
991
|
-
yield value;
|
|
1092
|
+
path3 = path3.replace(/^(.+)\|/, "$1:");
|
|
1093
|
+
if (sep == "\\") {
|
|
1094
|
+
path3 = path3.replace(/\//g, "\\");
|
|
992
1095
|
}
|
|
993
|
-
|
|
994
|
-
}
|
|
995
|
-
toJSON() {
|
|
996
|
-
const result = {};
|
|
997
|
-
for (const [key, values] of this.data) {
|
|
998
|
-
result[key] = values.length === 1 ? values[0] : values;
|
|
999
|
-
}
|
|
1000
|
-
return result;
|
|
1001
|
-
}
|
|
1002
|
-
toNodeHeaders() {
|
|
1003
|
-
const result = {};
|
|
1004
|
-
for (const [key, values] of this.data) {
|
|
1005
|
-
if (key === "set-cookie") {
|
|
1006
|
-
result[key] = values;
|
|
1096
|
+
if (/^.+\:/.test(path3)) {
|
|
1007
1097
|
} else {
|
|
1008
|
-
|
|
1098
|
+
path3 = sep + path3;
|
|
1009
1099
|
}
|
|
1010
|
-
|
|
1011
|
-
return result;
|
|
1012
|
-
}
|
|
1013
|
-
get size() {
|
|
1014
|
-
return this.data.size;
|
|
1015
|
-
}
|
|
1016
|
-
[Symbol.iterator]() {
|
|
1017
|
-
return this.entries();
|
|
1018
|
-
}
|
|
1019
|
-
};
|
|
1020
|
-
|
|
1021
|
-
// src/server/http/cookie.ts
|
|
1022
|
-
function parseCookies(header) {
|
|
1023
|
-
const result = {};
|
|
1024
|
-
if (!header) return result;
|
|
1025
|
-
const pairs = header.split(";");
|
|
1026
|
-
for (const pair of pairs) {
|
|
1027
|
-
const trimmed = pair.trim();
|
|
1028
|
-
if (!trimmed) continue;
|
|
1029
|
-
const eqIndex = trimmed.indexOf("=");
|
|
1030
|
-
if (eqIndex === -1) {
|
|
1031
|
-
result[trimmed] = "";
|
|
1032
|
-
continue;
|
|
1033
|
-
}
|
|
1034
|
-
const name = trimmed.slice(0, eqIndex).trim();
|
|
1035
|
-
let value = trimmed.slice(eqIndex + 1).trim();
|
|
1036
|
-
if (value.startsWith('"') && value.endsWith('"')) {
|
|
1037
|
-
value = value.slice(1, -1);
|
|
1038
|
-
}
|
|
1039
|
-
if (name) {
|
|
1040
|
-
result[decodeURIComponent(name)] = decodeURIComponent(value);
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
return result;
|
|
1044
|
-
}
|
|
1045
|
-
function serializeCookieValue(name, value) {
|
|
1046
|
-
return `${encodeURIComponent(name)}=${encodeURIComponent(value)}`;
|
|
1047
|
-
}
|
|
1048
|
-
function serializeCookie(name, value, options) {
|
|
1049
|
-
const parts = [serializeCookieValue(name, value)];
|
|
1050
|
-
if (options) {
|
|
1051
|
-
if (options.maxAge !== void 0) {
|
|
1052
|
-
parts.push(`Max-Age=${Math.floor(options.maxAge)}`);
|
|
1053
|
-
}
|
|
1054
|
-
if (options.expires !== void 0) {
|
|
1055
|
-
parts.push(`Expires=${options.expires.toUTCString()}`);
|
|
1056
|
-
}
|
|
1057
|
-
if (options.path !== void 0) {
|
|
1058
|
-
parts.push(`Path=${options.path}`);
|
|
1059
|
-
} else {
|
|
1060
|
-
parts.push("Path=/");
|
|
1061
|
-
}
|
|
1062
|
-
if (options.domain !== void 0) {
|
|
1063
|
-
parts.push(`Domain=${options.domain}`);
|
|
1064
|
-
}
|
|
1065
|
-
if (options.secure) {
|
|
1066
|
-
parts.push("Secure");
|
|
1067
|
-
}
|
|
1068
|
-
if (options.httpOnly) {
|
|
1069
|
-
parts.push("HttpOnly");
|
|
1070
|
-
}
|
|
1071
|
-
if (options.sameSite !== void 0) {
|
|
1072
|
-
parts.push(`SameSite=${options.sameSite}`);
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
return parts.join("; ");
|
|
1076
|
-
}
|
|
1077
|
-
function clearCookie(name, options) {
|
|
1078
|
-
return serializeCookie(name, "", {
|
|
1079
|
-
...options,
|
|
1080
|
-
maxAge: 0,
|
|
1081
|
-
expires: /* @__PURE__ */ new Date(0)
|
|
1082
|
-
});
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
// src/server/http/upload.ts
|
|
1086
|
-
import { randomUUID } from "crypto";
|
|
1087
|
-
import { writeFile, readFile, unlink, mkdir } from "fs/promises";
|
|
1088
|
-
import { join, extname, basename, dirname } from "path";
|
|
1089
|
-
import { tmpdir } from "os";
|
|
1090
|
-
var IMAGE_MIME_TYPES = /* @__PURE__ */ new Set([
|
|
1091
|
-
"image/jpeg",
|
|
1092
|
-
"image/png",
|
|
1093
|
-
"image/gif",
|
|
1094
|
-
"image/webp",
|
|
1095
|
-
"image/svg+xml",
|
|
1096
|
-
"image/bmp",
|
|
1097
|
-
"image/tiff",
|
|
1098
|
-
"image/avif"
|
|
1099
|
-
]);
|
|
1100
|
-
var VIDEO_MIME_TYPES = /* @__PURE__ */ new Set([
|
|
1101
|
-
"video/mp4",
|
|
1102
|
-
"video/mpeg",
|
|
1103
|
-
"video/webm",
|
|
1104
|
-
"video/ogg",
|
|
1105
|
-
"video/quicktime",
|
|
1106
|
-
"video/x-msvideo",
|
|
1107
|
-
"video/x-matroska"
|
|
1108
|
-
]);
|
|
1109
|
-
var SuperUploadedFile = class _SuperUploadedFile {
|
|
1110
|
-
fieldName;
|
|
1111
|
-
originalName;
|
|
1112
|
-
mimeType;
|
|
1113
|
-
size;
|
|
1114
|
-
path;
|
|
1115
|
-
extension;
|
|
1116
|
-
buffer;
|
|
1117
|
-
constructor(opts) {
|
|
1118
|
-
this.fieldName = opts.fieldName;
|
|
1119
|
-
this.originalName = opts.originalName;
|
|
1120
|
-
this.mimeType = opts.mimeType;
|
|
1121
|
-
this.size = opts.size;
|
|
1122
|
-
this.path = opts.path;
|
|
1123
|
-
this.extension = extname(opts.originalName).toLowerCase();
|
|
1124
|
-
this.buffer = opts.buffer ?? null;
|
|
1125
|
-
}
|
|
1126
|
-
async move(destination, filename) {
|
|
1127
|
-
const destName = filename ?? basename(this.path);
|
|
1128
|
-
const destPath = join(destination, destName);
|
|
1129
|
-
await mkdir(dirname(destPath), { recursive: true });
|
|
1130
|
-
const buf = await this.toBuffer();
|
|
1131
|
-
await writeFile(destPath, buf);
|
|
1132
|
-
return destPath;
|
|
1133
|
-
}
|
|
1134
|
-
async toBuffer() {
|
|
1135
|
-
if (this.buffer !== null) return this.buffer;
|
|
1136
|
-
this.buffer = await readFile(this.path);
|
|
1137
|
-
return this.buffer;
|
|
1138
|
-
}
|
|
1139
|
-
toBase64() {
|
|
1140
|
-
if (this.buffer === null) {
|
|
1141
|
-
throw new Error(
|
|
1142
|
-
"Buffer not loaded. Call toBuffer() first or read the file into memory."
|
|
1143
|
-
);
|
|
1144
|
-
}
|
|
1145
|
-
return this.buffer.toString("base64");
|
|
1146
|
-
}
|
|
1147
|
-
isImage() {
|
|
1148
|
-
return IMAGE_MIME_TYPES.has(this.mimeType);
|
|
1149
|
-
}
|
|
1150
|
-
isVideo() {
|
|
1151
|
-
return VIDEO_MIME_TYPES.has(this.mimeType);
|
|
1152
|
-
}
|
|
1153
|
-
static async createFromBuffer(fieldName, originalName, mimeType, buffer, tempDir) {
|
|
1154
|
-
const tmp = tempDir ?? tmpdir();
|
|
1155
|
-
const fileName = `${randomUUID()}${extname(originalName)}`;
|
|
1156
|
-
const filePath = join(tmp, fileName);
|
|
1157
|
-
await writeFile(filePath, buffer);
|
|
1158
|
-
return new _SuperUploadedFile({
|
|
1159
|
-
fieldName,
|
|
1160
|
-
originalName,
|
|
1161
|
-
mimeType: mimeType || "application/octet-stream",
|
|
1162
|
-
size: buffer.length,
|
|
1163
|
-
path: filePath,
|
|
1164
|
-
buffer
|
|
1165
|
-
});
|
|
1166
|
-
}
|
|
1167
|
-
async cleanup() {
|
|
1168
|
-
try {
|
|
1169
|
-
await unlink(this.path);
|
|
1170
|
-
} catch {
|
|
1100
|
+
return host + path3;
|
|
1171
1101
|
}
|
|
1172
1102
|
}
|
|
1173
|
-
};
|
|
1103
|
+
});
|
|
1174
1104
|
|
|
1175
|
-
//
|
|
1176
|
-
var
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
formData[part.name] = part.value;
|
|
1259
|
-
} else if (part.type === "file") {
|
|
1260
|
-
const uploadedFile = await SuperUploadedFile.createFromBuffer(
|
|
1261
|
-
part.name,
|
|
1262
|
-
part.filename,
|
|
1263
|
-
part.mimeType,
|
|
1264
|
-
part.data
|
|
1265
|
-
);
|
|
1266
|
-
files[part.name] = uploadedFile;
|
|
1105
|
+
// node_modules/bindings/bindings.js
|
|
1106
|
+
var require_bindings = __commonJS({
|
|
1107
|
+
"node_modules/bindings/bindings.js"(exports, module) {
|
|
1108
|
+
"use strict";
|
|
1109
|
+
var fs3 = __require("fs");
|
|
1110
|
+
var path3 = __require("path");
|
|
1111
|
+
var fileURLToPath = require_file_uri_to_path();
|
|
1112
|
+
var join5 = path3.join;
|
|
1113
|
+
var dirname4 = path3.dirname;
|
|
1114
|
+
var exists = fs3.accessSync && function(path4) {
|
|
1115
|
+
try {
|
|
1116
|
+
fs3.accessSync(path4);
|
|
1117
|
+
} catch (e) {
|
|
1118
|
+
return false;
|
|
1119
|
+
}
|
|
1120
|
+
return true;
|
|
1121
|
+
} || fs3.existsSync || path3.existsSync;
|
|
1122
|
+
var defaults = {
|
|
1123
|
+
arrow: process.env.NODE_BINDINGS_ARROW || " \u2192 ",
|
|
1124
|
+
compiled: process.env.NODE_BINDINGS_COMPILED_DIR || "compiled",
|
|
1125
|
+
platform: process.platform,
|
|
1126
|
+
arch: process.arch,
|
|
1127
|
+
nodePreGyp: "node-v" + process.versions.modules + "-" + process.platform + "-" + process.arch,
|
|
1128
|
+
version: process.versions.node,
|
|
1129
|
+
bindings: "bindings.node",
|
|
1130
|
+
try: [
|
|
1131
|
+
// node-gyp's linked version in the "build" dir
|
|
1132
|
+
["module_root", "build", "bindings"],
|
|
1133
|
+
// node-waf and gyp_addon (a.k.a node-gyp)
|
|
1134
|
+
["module_root", "build", "Debug", "bindings"],
|
|
1135
|
+
["module_root", "build", "Release", "bindings"],
|
|
1136
|
+
// Debug files, for development (legacy behavior, remove for node v0.9)
|
|
1137
|
+
["module_root", "out", "Debug", "bindings"],
|
|
1138
|
+
["module_root", "Debug", "bindings"],
|
|
1139
|
+
// Release files, but manually compiled (legacy behavior, remove for node v0.9)
|
|
1140
|
+
["module_root", "out", "Release", "bindings"],
|
|
1141
|
+
["module_root", "Release", "bindings"],
|
|
1142
|
+
// Legacy from node-waf, node <= 0.4.x
|
|
1143
|
+
["module_root", "build", "default", "bindings"],
|
|
1144
|
+
// Production "Release" buildtype binary (meh...)
|
|
1145
|
+
["module_root", "compiled", "version", "platform", "arch", "bindings"],
|
|
1146
|
+
// node-qbs builds
|
|
1147
|
+
["module_root", "addon-build", "release", "install-root", "bindings"],
|
|
1148
|
+
["module_root", "addon-build", "debug", "install-root", "bindings"],
|
|
1149
|
+
["module_root", "addon-build", "default", "install-root", "bindings"],
|
|
1150
|
+
// node-pre-gyp path ./lib/binding/{node_abi}-{platform}-{arch}
|
|
1151
|
+
["module_root", "lib", "binding", "nodePreGyp", "bindings"]
|
|
1152
|
+
]
|
|
1153
|
+
};
|
|
1154
|
+
function bindings(opts) {
|
|
1155
|
+
if (typeof opts == "string") {
|
|
1156
|
+
opts = { bindings: opts };
|
|
1157
|
+
} else if (!opts) {
|
|
1158
|
+
opts = {};
|
|
1159
|
+
}
|
|
1160
|
+
Object.keys(defaults).map(function(i2) {
|
|
1161
|
+
if (!(i2 in opts)) opts[i2] = defaults[i2];
|
|
1162
|
+
});
|
|
1163
|
+
if (!opts.module_root) {
|
|
1164
|
+
opts.module_root = exports.getRoot(exports.getFileName());
|
|
1165
|
+
}
|
|
1166
|
+
if (path3.extname(opts.bindings) != ".node") {
|
|
1167
|
+
opts.bindings += ".node";
|
|
1168
|
+
}
|
|
1169
|
+
var requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : __require;
|
|
1170
|
+
var tries = [], i = 0, l = opts.try.length, n, b, err;
|
|
1171
|
+
for (; i < l; i++) {
|
|
1172
|
+
n = join5.apply(
|
|
1173
|
+
null,
|
|
1174
|
+
opts.try[i].map(function(p) {
|
|
1175
|
+
return opts[p] || p;
|
|
1176
|
+
})
|
|
1177
|
+
);
|
|
1178
|
+
tries.push(n);
|
|
1179
|
+
try {
|
|
1180
|
+
b = opts.path ? requireFunc.resolve(n) : requireFunc(n);
|
|
1181
|
+
if (!opts.path) {
|
|
1182
|
+
b.path = n;
|
|
1183
|
+
}
|
|
1184
|
+
return b;
|
|
1185
|
+
} catch (e) {
|
|
1186
|
+
if (e.code !== "MODULE_NOT_FOUND" && e.code !== "QUALIFIED_PATH_RESOLUTION_FAILED" && !/not find/i.test(e.message)) {
|
|
1187
|
+
throw e;
|
|
1267
1188
|
}
|
|
1268
1189
|
}
|
|
1269
1190
|
}
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1191
|
+
err = new Error(
|
|
1192
|
+
"Could not locate the bindings file. Tried:\n" + tries.map(function(a) {
|
|
1193
|
+
return opts.arrow + a;
|
|
1194
|
+
}).join("\n")
|
|
1195
|
+
);
|
|
1196
|
+
err.tries = tries;
|
|
1197
|
+
throw err;
|
|
1198
|
+
}
|
|
1199
|
+
module.exports = exports = bindings;
|
|
1200
|
+
exports.getFileName = function getFileName(calling_file) {
|
|
1201
|
+
var origPST = Error.prepareStackTrace, origSTL = Error.stackTraceLimit, dummy = {}, fileName;
|
|
1202
|
+
Error.stackTraceLimit = 10;
|
|
1203
|
+
Error.prepareStackTrace = function(e, st) {
|
|
1204
|
+
for (var i = 0, l = st.length; i < l; i++) {
|
|
1205
|
+
fileName = st[i].getFileName();
|
|
1206
|
+
if (fileName !== __filename) {
|
|
1207
|
+
if (calling_file) {
|
|
1208
|
+
if (fileName !== calling_file) {
|
|
1209
|
+
return;
|
|
1210
|
+
}
|
|
1211
|
+
} else {
|
|
1212
|
+
return;
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
};
|
|
1217
|
+
Error.captureStackTrace(dummy);
|
|
1218
|
+
dummy.stack;
|
|
1219
|
+
Error.prepareStackTrace = origPST;
|
|
1220
|
+
Error.stackTraceLimit = origSTL;
|
|
1221
|
+
var fileSchema = "file://";
|
|
1222
|
+
if (fileName.indexOf(fileSchema) === 0) {
|
|
1223
|
+
fileName = fileURLToPath(fileName);
|
|
1224
|
+
}
|
|
1225
|
+
return fileName;
|
|
1226
|
+
};
|
|
1227
|
+
exports.getRoot = function getRoot(file) {
|
|
1228
|
+
var dir = dirname4(file), prev;
|
|
1229
|
+
while (true) {
|
|
1230
|
+
if (dir === ".") {
|
|
1231
|
+
dir = process.cwd();
|
|
1232
|
+
}
|
|
1233
|
+
if (exists(join5(dir, "package.json")) || exists(join5(dir, "node_modules"))) {
|
|
1234
|
+
return dir;
|
|
1235
|
+
}
|
|
1236
|
+
if (prev === dir) {
|
|
1237
|
+
throw new Error(
|
|
1238
|
+
'Could not find module root given file: "' + file + '". Do you have a `package.json` file? '
|
|
1239
|
+
);
|
|
1240
|
+
}
|
|
1241
|
+
prev = dir;
|
|
1242
|
+
dir = join5(dir, "..");
|
|
1243
|
+
}
|
|
1244
|
+
};
|
|
1245
|
+
}
|
|
1246
|
+
});
|
|
1247
|
+
|
|
1248
|
+
// node_modules/better-sqlite3/lib/methods/wrappers.js
|
|
1249
|
+
var require_wrappers = __commonJS({
|
|
1250
|
+
"node_modules/better-sqlite3/lib/methods/wrappers.js"(exports) {
|
|
1251
|
+
"use strict";
|
|
1252
|
+
var { cppdb } = require_util();
|
|
1253
|
+
exports.prepare = function prepare(sql) {
|
|
1254
|
+
return this[cppdb].prepare(sql, this, false);
|
|
1255
|
+
};
|
|
1256
|
+
exports.exec = function exec(sql) {
|
|
1257
|
+
this[cppdb].exec(sql);
|
|
1258
|
+
return this;
|
|
1259
|
+
};
|
|
1260
|
+
exports.close = function close() {
|
|
1261
|
+
this[cppdb].close();
|
|
1262
|
+
return this;
|
|
1263
|
+
};
|
|
1264
|
+
exports.loadExtension = function loadExtension(...args) {
|
|
1265
|
+
this[cppdb].loadExtension(...args);
|
|
1266
|
+
return this;
|
|
1267
|
+
};
|
|
1268
|
+
exports.defaultSafeIntegers = function defaultSafeIntegers(...args) {
|
|
1269
|
+
this[cppdb].defaultSafeIntegers(...args);
|
|
1270
|
+
return this;
|
|
1271
|
+
};
|
|
1272
|
+
exports.unsafeMode = function unsafeMode(...args) {
|
|
1273
|
+
this[cppdb].unsafeMode(...args);
|
|
1274
|
+
return this;
|
|
1275
|
+
};
|
|
1276
|
+
exports.getters = {
|
|
1277
|
+
name: {
|
|
1278
|
+
get: function name() {
|
|
1279
|
+
return this[cppdb].name;
|
|
1280
|
+
},
|
|
1281
|
+
enumerable: true
|
|
1282
|
+
},
|
|
1283
|
+
open: {
|
|
1284
|
+
get: function open() {
|
|
1285
|
+
return this[cppdb].open;
|
|
1286
|
+
},
|
|
1287
|
+
enumerable: true
|
|
1288
|
+
},
|
|
1289
|
+
inTransaction: {
|
|
1290
|
+
get: function inTransaction() {
|
|
1291
|
+
return this[cppdb].inTransaction;
|
|
1292
|
+
},
|
|
1293
|
+
enumerable: true
|
|
1294
|
+
},
|
|
1295
|
+
readonly: {
|
|
1296
|
+
get: function readonly() {
|
|
1297
|
+
return this[cppdb].readonly;
|
|
1298
|
+
},
|
|
1299
|
+
enumerable: true
|
|
1300
|
+
},
|
|
1301
|
+
memory: {
|
|
1302
|
+
get: function memory() {
|
|
1303
|
+
return this[cppdb].memory;
|
|
1304
|
+
},
|
|
1305
|
+
enumerable: true
|
|
1306
|
+
}
|
|
1307
|
+
};
|
|
1308
|
+
}
|
|
1309
|
+
});
|
|
1310
|
+
|
|
1311
|
+
// node_modules/better-sqlite3/lib/methods/transaction.js
|
|
1312
|
+
var require_transaction = __commonJS({
|
|
1313
|
+
"node_modules/better-sqlite3/lib/methods/transaction.js"(exports, module) {
|
|
1314
|
+
"use strict";
|
|
1315
|
+
var { cppdb } = require_util();
|
|
1316
|
+
var controllers = /* @__PURE__ */ new WeakMap();
|
|
1317
|
+
module.exports = function transaction(fn) {
|
|
1318
|
+
if (typeof fn !== "function") throw new TypeError("Expected first argument to be a function");
|
|
1319
|
+
const db = this[cppdb];
|
|
1320
|
+
const controller = getController(db, this);
|
|
1321
|
+
const { apply } = Function.prototype;
|
|
1322
|
+
const properties = {
|
|
1323
|
+
default: { value: wrapTransaction(apply, fn, db, controller.default) },
|
|
1324
|
+
deferred: { value: wrapTransaction(apply, fn, db, controller.deferred) },
|
|
1325
|
+
immediate: { value: wrapTransaction(apply, fn, db, controller.immediate) },
|
|
1326
|
+
exclusive: { value: wrapTransaction(apply, fn, db, controller.exclusive) },
|
|
1327
|
+
database: { value: this, enumerable: true }
|
|
1328
|
+
};
|
|
1329
|
+
Object.defineProperties(properties.default.value, properties);
|
|
1330
|
+
Object.defineProperties(properties.deferred.value, properties);
|
|
1331
|
+
Object.defineProperties(properties.immediate.value, properties);
|
|
1332
|
+
Object.defineProperties(properties.exclusive.value, properties);
|
|
1333
|
+
return properties.default.value;
|
|
1334
|
+
};
|
|
1335
|
+
var getController = (db, self) => {
|
|
1336
|
+
let controller = controllers.get(db);
|
|
1337
|
+
if (!controller) {
|
|
1338
|
+
const shared = {
|
|
1339
|
+
commit: db.prepare("COMMIT", self, false),
|
|
1340
|
+
rollback: db.prepare("ROLLBACK", self, false),
|
|
1341
|
+
savepoint: db.prepare("SAVEPOINT ` _bs3. `", self, false),
|
|
1342
|
+
release: db.prepare("RELEASE ` _bs3. `", self, false),
|
|
1343
|
+
rollbackTo: db.prepare("ROLLBACK TO ` _bs3. `", self, false)
|
|
1344
|
+
};
|
|
1345
|
+
controllers.set(db, controller = {
|
|
1346
|
+
default: Object.assign({ begin: db.prepare("BEGIN", self, false) }, shared),
|
|
1347
|
+
deferred: Object.assign({ begin: db.prepare("BEGIN DEFERRED", self, false) }, shared),
|
|
1348
|
+
immediate: Object.assign({ begin: db.prepare("BEGIN IMMEDIATE", self, false) }, shared),
|
|
1349
|
+
exclusive: Object.assign({ begin: db.prepare("BEGIN EXCLUSIVE", self, false) }, shared)
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
return controller;
|
|
1353
|
+
};
|
|
1354
|
+
var wrapTransaction = (apply, fn, db, { begin, commit, rollback, savepoint, release, rollbackTo }) => function sqliteTransaction() {
|
|
1355
|
+
let before, after, undo;
|
|
1356
|
+
if (db.inTransaction) {
|
|
1357
|
+
before = savepoint;
|
|
1358
|
+
after = release;
|
|
1359
|
+
undo = rollbackTo;
|
|
1360
|
+
} else {
|
|
1361
|
+
before = begin;
|
|
1362
|
+
after = commit;
|
|
1363
|
+
undo = rollback;
|
|
1364
|
+
}
|
|
1365
|
+
before.run();
|
|
1366
|
+
try {
|
|
1367
|
+
const result = apply.call(fn, this, arguments);
|
|
1368
|
+
if (result && typeof result.then === "function") {
|
|
1369
|
+
throw new TypeError("Transaction function cannot return a promise");
|
|
1370
|
+
}
|
|
1371
|
+
after.run();
|
|
1372
|
+
return result;
|
|
1373
|
+
} catch (ex) {
|
|
1374
|
+
if (db.inTransaction) {
|
|
1375
|
+
undo.run();
|
|
1376
|
+
if (undo !== rollback) after.run();
|
|
1377
|
+
}
|
|
1378
|
+
throw ex;
|
|
1379
|
+
}
|
|
1380
|
+
};
|
|
1381
|
+
}
|
|
1382
|
+
});
|
|
1383
|
+
|
|
1384
|
+
// node_modules/better-sqlite3/lib/methods/pragma.js
|
|
1385
|
+
var require_pragma = __commonJS({
|
|
1386
|
+
"node_modules/better-sqlite3/lib/methods/pragma.js"(exports, module) {
|
|
1387
|
+
"use strict";
|
|
1388
|
+
var { getBooleanOption, cppdb } = require_util();
|
|
1389
|
+
module.exports = function pragma(source, options) {
|
|
1390
|
+
if (options == null) options = {};
|
|
1391
|
+
if (typeof source !== "string") throw new TypeError("Expected first argument to be a string");
|
|
1392
|
+
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
1393
|
+
const simple = getBooleanOption(options, "simple");
|
|
1394
|
+
const stmt = this[cppdb].prepare(`PRAGMA ${source}`, this, true);
|
|
1395
|
+
return simple ? stmt.pluck().get() : stmt.all();
|
|
1396
|
+
};
|
|
1397
|
+
}
|
|
1398
|
+
});
|
|
1399
|
+
|
|
1400
|
+
// node_modules/better-sqlite3/lib/methods/backup.js
|
|
1401
|
+
var require_backup = __commonJS({
|
|
1402
|
+
"node_modules/better-sqlite3/lib/methods/backup.js"(exports, module) {
|
|
1403
|
+
"use strict";
|
|
1404
|
+
var fs3 = __require("fs");
|
|
1405
|
+
var path3 = __require("path");
|
|
1406
|
+
var { promisify: promisify2 } = __require("util");
|
|
1407
|
+
var { cppdb } = require_util();
|
|
1408
|
+
var fsAccess = promisify2(fs3.access);
|
|
1409
|
+
module.exports = async function backup(filename, options) {
|
|
1410
|
+
if (options == null) options = {};
|
|
1411
|
+
if (typeof filename !== "string") throw new TypeError("Expected first argument to be a string");
|
|
1412
|
+
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
1413
|
+
filename = filename.trim();
|
|
1414
|
+
const attachedName = "attached" in options ? options.attached : "main";
|
|
1415
|
+
const handler = "progress" in options ? options.progress : null;
|
|
1416
|
+
if (!filename) throw new TypeError("Backup filename cannot be an empty string");
|
|
1417
|
+
if (filename === ":memory:") throw new TypeError('Invalid backup filename ":memory:"');
|
|
1418
|
+
if (typeof attachedName !== "string") throw new TypeError('Expected the "attached" option to be a string');
|
|
1419
|
+
if (!attachedName) throw new TypeError('The "attached" option cannot be an empty string');
|
|
1420
|
+
if (handler != null && typeof handler !== "function") throw new TypeError('Expected the "progress" option to be a function');
|
|
1421
|
+
await fsAccess(path3.dirname(filename)).catch(() => {
|
|
1422
|
+
throw new TypeError("Cannot save backup because the directory does not exist");
|
|
1423
|
+
});
|
|
1424
|
+
const isNewFile = await fsAccess(filename).then(() => false, () => true);
|
|
1425
|
+
return runBackup(this[cppdb].backup(this, attachedName, filename, isNewFile), handler || null);
|
|
1426
|
+
};
|
|
1427
|
+
var runBackup = (backup, handler) => {
|
|
1428
|
+
let rate = 0;
|
|
1429
|
+
let useDefault = true;
|
|
1430
|
+
return new Promise((resolve4, reject) => {
|
|
1431
|
+
setImmediate(function step() {
|
|
1432
|
+
try {
|
|
1433
|
+
const progress = backup.transfer(rate);
|
|
1434
|
+
if (!progress.remainingPages) {
|
|
1435
|
+
backup.close();
|
|
1436
|
+
resolve4(progress);
|
|
1437
|
+
return;
|
|
1438
|
+
}
|
|
1439
|
+
if (useDefault) {
|
|
1440
|
+
useDefault = false;
|
|
1441
|
+
rate = 100;
|
|
1442
|
+
}
|
|
1443
|
+
if (handler) {
|
|
1444
|
+
const ret = handler(progress);
|
|
1445
|
+
if (ret !== void 0) {
|
|
1446
|
+
if (typeof ret === "number" && ret === ret) rate = Math.max(0, Math.min(2147483647, Math.round(ret)));
|
|
1447
|
+
else throw new TypeError("Expected progress callback to return a number or undefined");
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
setImmediate(step);
|
|
1451
|
+
} catch (err) {
|
|
1452
|
+
backup.close();
|
|
1453
|
+
reject(err);
|
|
1454
|
+
}
|
|
1455
|
+
});
|
|
1456
|
+
});
|
|
1457
|
+
};
|
|
1458
|
+
}
|
|
1459
|
+
});
|
|
1460
|
+
|
|
1461
|
+
// node_modules/better-sqlite3/lib/methods/serialize.js
|
|
1462
|
+
var require_serialize = __commonJS({
|
|
1463
|
+
"node_modules/better-sqlite3/lib/methods/serialize.js"(exports, module) {
|
|
1464
|
+
"use strict";
|
|
1465
|
+
var { cppdb } = require_util();
|
|
1466
|
+
module.exports = function serialize(options) {
|
|
1467
|
+
if (options == null) options = {};
|
|
1468
|
+
if (typeof options !== "object") throw new TypeError("Expected first argument to be an options object");
|
|
1469
|
+
const attachedName = "attached" in options ? options.attached : "main";
|
|
1470
|
+
if (typeof attachedName !== "string") throw new TypeError('Expected the "attached" option to be a string');
|
|
1471
|
+
if (!attachedName) throw new TypeError('The "attached" option cannot be an empty string');
|
|
1472
|
+
return this[cppdb].serialize(attachedName);
|
|
1473
|
+
};
|
|
1474
|
+
}
|
|
1475
|
+
});
|
|
1476
|
+
|
|
1477
|
+
// node_modules/better-sqlite3/lib/methods/function.js
|
|
1478
|
+
var require_function = __commonJS({
|
|
1479
|
+
"node_modules/better-sqlite3/lib/methods/function.js"(exports, module) {
|
|
1480
|
+
"use strict";
|
|
1481
|
+
var { getBooleanOption, cppdb } = require_util();
|
|
1482
|
+
module.exports = function defineFunction(name, options, fn) {
|
|
1483
|
+
if (options == null) options = {};
|
|
1484
|
+
if (typeof options === "function") {
|
|
1485
|
+
fn = options;
|
|
1486
|
+
options = {};
|
|
1487
|
+
}
|
|
1488
|
+
if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
|
|
1489
|
+
if (typeof fn !== "function") throw new TypeError("Expected last argument to be a function");
|
|
1490
|
+
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
1491
|
+
if (!name) throw new TypeError("User-defined function name cannot be an empty string");
|
|
1492
|
+
const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
|
|
1493
|
+
const deterministic = getBooleanOption(options, "deterministic");
|
|
1494
|
+
const directOnly = getBooleanOption(options, "directOnly");
|
|
1495
|
+
const varargs = getBooleanOption(options, "varargs");
|
|
1496
|
+
let argCount = -1;
|
|
1497
|
+
if (!varargs) {
|
|
1498
|
+
argCount = fn.length;
|
|
1499
|
+
if (!Number.isInteger(argCount) || argCount < 0) throw new TypeError("Expected function.length to be a positive integer");
|
|
1500
|
+
if (argCount > 100) throw new RangeError("User-defined functions cannot have more than 100 arguments");
|
|
1501
|
+
}
|
|
1502
|
+
this[cppdb].function(fn, name, argCount, safeIntegers, deterministic, directOnly);
|
|
1503
|
+
return this;
|
|
1504
|
+
};
|
|
1505
|
+
}
|
|
1506
|
+
});
|
|
1507
|
+
|
|
1508
|
+
// node_modules/better-sqlite3/lib/methods/aggregate.js
|
|
1509
|
+
var require_aggregate = __commonJS({
|
|
1510
|
+
"node_modules/better-sqlite3/lib/methods/aggregate.js"(exports, module) {
|
|
1511
|
+
"use strict";
|
|
1512
|
+
var { getBooleanOption, cppdb } = require_util();
|
|
1513
|
+
module.exports = function defineAggregate(name, options) {
|
|
1514
|
+
if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
|
|
1515
|
+
if (typeof options !== "object" || options === null) throw new TypeError("Expected second argument to be an options object");
|
|
1516
|
+
if (!name) throw new TypeError("User-defined function name cannot be an empty string");
|
|
1517
|
+
const start = "start" in options ? options.start : null;
|
|
1518
|
+
const step = getFunctionOption(options, "step", true);
|
|
1519
|
+
const inverse = getFunctionOption(options, "inverse", false);
|
|
1520
|
+
const result = getFunctionOption(options, "result", false);
|
|
1521
|
+
const safeIntegers = "safeIntegers" in options ? +getBooleanOption(options, "safeIntegers") : 2;
|
|
1522
|
+
const deterministic = getBooleanOption(options, "deterministic");
|
|
1523
|
+
const directOnly = getBooleanOption(options, "directOnly");
|
|
1524
|
+
const varargs = getBooleanOption(options, "varargs");
|
|
1525
|
+
let argCount = -1;
|
|
1526
|
+
if (!varargs) {
|
|
1527
|
+
argCount = Math.max(getLength(step), inverse ? getLength(inverse) : 0);
|
|
1528
|
+
if (argCount > 0) argCount -= 1;
|
|
1529
|
+
if (argCount > 100) throw new RangeError("User-defined functions cannot have more than 100 arguments");
|
|
1530
|
+
}
|
|
1531
|
+
this[cppdb].aggregate(start, step, inverse, result, name, argCount, safeIntegers, deterministic, directOnly);
|
|
1532
|
+
return this;
|
|
1533
|
+
};
|
|
1534
|
+
var getFunctionOption = (options, key, required) => {
|
|
1535
|
+
const value = key in options ? options[key] : null;
|
|
1536
|
+
if (typeof value === "function") return value;
|
|
1537
|
+
if (value != null) throw new TypeError(`Expected the "${key}" option to be a function`);
|
|
1538
|
+
if (required) throw new TypeError(`Missing required option "${key}"`);
|
|
1539
|
+
return null;
|
|
1540
|
+
};
|
|
1541
|
+
var getLength = ({ length }) => {
|
|
1542
|
+
if (Number.isInteger(length) && length >= 0) return length;
|
|
1543
|
+
throw new TypeError("Expected function.length to be a positive integer");
|
|
1544
|
+
};
|
|
1545
|
+
}
|
|
1546
|
+
});
|
|
1547
|
+
|
|
1548
|
+
// node_modules/better-sqlite3/lib/methods/table.js
|
|
1549
|
+
var require_table = __commonJS({
|
|
1550
|
+
"node_modules/better-sqlite3/lib/methods/table.js"(exports, module) {
|
|
1551
|
+
"use strict";
|
|
1552
|
+
var { cppdb } = require_util();
|
|
1553
|
+
module.exports = function defineTable(name, factory) {
|
|
1554
|
+
if (typeof name !== "string") throw new TypeError("Expected first argument to be a string");
|
|
1555
|
+
if (!name) throw new TypeError("Virtual table module name cannot be an empty string");
|
|
1556
|
+
let eponymous = false;
|
|
1557
|
+
if (typeof factory === "object" && factory !== null) {
|
|
1558
|
+
eponymous = true;
|
|
1559
|
+
factory = defer(parseTableDefinition(factory, "used", name));
|
|
1560
|
+
} else {
|
|
1561
|
+
if (typeof factory !== "function") throw new TypeError("Expected second argument to be a function or a table definition object");
|
|
1562
|
+
factory = wrapFactory(factory);
|
|
1563
|
+
}
|
|
1564
|
+
this[cppdb].table(factory, name, eponymous);
|
|
1565
|
+
return this;
|
|
1566
|
+
};
|
|
1567
|
+
function wrapFactory(factory) {
|
|
1568
|
+
return function virtualTableFactory(moduleName, databaseName, tableName, ...args) {
|
|
1569
|
+
const thisObject = {
|
|
1570
|
+
module: moduleName,
|
|
1571
|
+
database: databaseName,
|
|
1572
|
+
table: tableName
|
|
1573
|
+
};
|
|
1574
|
+
const def = apply.call(factory, thisObject, args);
|
|
1575
|
+
if (typeof def !== "object" || def === null) {
|
|
1576
|
+
throw new TypeError(`Virtual table module "${moduleName}" did not return a table definition object`);
|
|
1577
|
+
}
|
|
1578
|
+
return parseTableDefinition(def, "returned", moduleName);
|
|
1579
|
+
};
|
|
1580
|
+
}
|
|
1581
|
+
function parseTableDefinition(def, verb, moduleName) {
|
|
1582
|
+
if (!hasOwnProperty.call(def, "rows")) {
|
|
1583
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "rows" property`);
|
|
1584
|
+
}
|
|
1585
|
+
if (!hasOwnProperty.call(def, "columns")) {
|
|
1586
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition without a "columns" property`);
|
|
1587
|
+
}
|
|
1588
|
+
const rows = def.rows;
|
|
1589
|
+
if (typeof rows !== "function" || Object.getPrototypeOf(rows) !== GeneratorFunctionPrototype) {
|
|
1590
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "rows" property (should be a generator function)`);
|
|
1591
|
+
}
|
|
1592
|
+
let columns = def.columns;
|
|
1593
|
+
if (!Array.isArray(columns) || !(columns = [...columns]).every((x) => typeof x === "string")) {
|
|
1594
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "columns" property (should be an array of strings)`);
|
|
1595
|
+
}
|
|
1596
|
+
if (columns.length !== new Set(columns).size) {
|
|
1597
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate column names`);
|
|
1598
|
+
}
|
|
1599
|
+
if (!columns.length) {
|
|
1600
|
+
throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with zero columns`);
|
|
1601
|
+
}
|
|
1602
|
+
let parameters;
|
|
1603
|
+
if (hasOwnProperty.call(def, "parameters")) {
|
|
1604
|
+
parameters = def.parameters;
|
|
1605
|
+
if (!Array.isArray(parameters) || !(parameters = [...parameters]).every((x) => typeof x === "string")) {
|
|
1606
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "parameters" property (should be an array of strings)`);
|
|
1607
|
+
}
|
|
1608
|
+
} else {
|
|
1609
|
+
parameters = inferParameters(rows);
|
|
1610
|
+
}
|
|
1611
|
+
if (parameters.length !== new Set(parameters).size) {
|
|
1612
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with duplicate parameter names`);
|
|
1613
|
+
}
|
|
1614
|
+
if (parameters.length > 32) {
|
|
1615
|
+
throw new RangeError(`Virtual table module "${moduleName}" ${verb} a table definition with more than the maximum number of 32 parameters`);
|
|
1616
|
+
}
|
|
1617
|
+
for (const parameter of parameters) {
|
|
1618
|
+
if (columns.includes(parameter)) {
|
|
1619
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with column "${parameter}" which was ambiguously defined as both a column and parameter`);
|
|
1316
1620
|
}
|
|
1317
1621
|
}
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
const messages = (result.errors ?? []).map((e) => {
|
|
1345
|
-
const path3 = e.path ?? "";
|
|
1346
|
-
return path3 ? `${path3}: ${e.message}` : e.message;
|
|
1347
|
-
}).join("; ");
|
|
1348
|
-
throw new ValidationError(messages, result.errors ?? []);
|
|
1349
|
-
}
|
|
1350
|
-
return result.data;
|
|
1351
|
-
}
|
|
1352
|
-
isAjax() {
|
|
1353
|
-
const requestedWith = this._headers.get("x-requested-with");
|
|
1354
|
-
return requestedWith?.toLowerCase() === "xmlhttprequest";
|
|
1355
|
-
}
|
|
1356
|
-
wantsJson() {
|
|
1357
|
-
const accept = this._headers.get("accept");
|
|
1358
|
-
if (accept !== void 0 && accept.includes("application/json")) {
|
|
1359
|
-
return true;
|
|
1360
|
-
}
|
|
1361
|
-
return this.isAjax();
|
|
1362
|
-
}
|
|
1363
|
-
bearerToken() {
|
|
1364
|
-
const auth = this._headers.get("authorization");
|
|
1365
|
-
if (auth === void 0) return void 0;
|
|
1366
|
-
const match = auth.match(/^Bearer\s+(.+)$/i);
|
|
1367
|
-
return match?.[1];
|
|
1368
|
-
}
|
|
1369
|
-
get rawRequest() {
|
|
1370
|
-
return this.raw;
|
|
1371
|
-
}
|
|
1372
|
-
};
|
|
1373
|
-
var ValidationError = class extends Error {
|
|
1374
|
-
constructor(message, errors) {
|
|
1375
|
-
super(message);
|
|
1376
|
-
this.errors = errors;
|
|
1377
|
-
this.name = "ValidationError";
|
|
1378
|
-
}
|
|
1379
|
-
errors;
|
|
1380
|
-
};
|
|
1381
|
-
function parseQueryParams(searchParams) {
|
|
1382
|
-
const result = {};
|
|
1383
|
-
for (const key of searchParams.keys()) {
|
|
1384
|
-
const values = searchParams.getAll(key);
|
|
1385
|
-
result[key] = values.length === 1 ? values[0] : values;
|
|
1386
|
-
}
|
|
1387
|
-
return result;
|
|
1388
|
-
}
|
|
1389
|
-
function parseIp(req) {
|
|
1390
|
-
const forwarded = req.headers["x-forwarded-for"];
|
|
1391
|
-
if (forwarded !== void 0) {
|
|
1392
|
-
const first = Array.isArray(forwarded) ? forwarded[0] : forwarded.split(",")[0];
|
|
1393
|
-
if (first !== void 0) return first.trim();
|
|
1394
|
-
}
|
|
1395
|
-
const realIp = req.headers["x-real-ip"];
|
|
1396
|
-
if (realIp !== void 0) {
|
|
1397
|
-
return Array.isArray(realIp) ? realIp[0] : realIp;
|
|
1398
|
-
}
|
|
1399
|
-
const remote = req.socket.remoteAddress;
|
|
1400
|
-
if (remote !== void 0) {
|
|
1401
|
-
if (remote.startsWith("::ffff:")) return remote.slice(7);
|
|
1402
|
-
return remote;
|
|
1403
|
-
}
|
|
1404
|
-
return "127.0.0.1";
|
|
1405
|
-
}
|
|
1406
|
-
function parseUrlEncoded(text) {
|
|
1407
|
-
const result = {};
|
|
1408
|
-
const pairs = text.split("&");
|
|
1409
|
-
for (const pair of pairs) {
|
|
1410
|
-
if (!pair) continue;
|
|
1411
|
-
const eqIndex = pair.indexOf("=");
|
|
1412
|
-
if (eqIndex === -1) {
|
|
1413
|
-
result[decodeURIComponent(pair)] = "";
|
|
1414
|
-
} else {
|
|
1415
|
-
const key = decodeURIComponent(pair.slice(0, eqIndex));
|
|
1416
|
-
const value = decodeURIComponent(pair.slice(eqIndex + 1));
|
|
1417
|
-
result[key] = value;
|
|
1418
|
-
}
|
|
1419
|
-
}
|
|
1420
|
-
return result;
|
|
1421
|
-
}
|
|
1422
|
-
function parseMultipartBody(body, boundary) {
|
|
1423
|
-
const result = [];
|
|
1424
|
-
const boundaryBuffer = Buffer.from(`--${boundary}`);
|
|
1425
|
-
let start = 0;
|
|
1426
|
-
let searchFrom = 0;
|
|
1427
|
-
while (true) {
|
|
1428
|
-
const boundaryIndex = body.indexOf(boundaryBuffer, searchFrom);
|
|
1429
|
-
if (boundaryIndex === -1) break;
|
|
1430
|
-
searchFrom = boundaryIndex + boundaryBuffer.length;
|
|
1431
|
-
if (searchFrom < body.length && body[searchFrom] === 45 && body[searchFrom + 1] === 45) {
|
|
1432
|
-
break;
|
|
1433
|
-
}
|
|
1434
|
-
if (searchFrom >= body.length) break;
|
|
1435
|
-
if (body[searchFrom] === 13) searchFrom++;
|
|
1436
|
-
if (body[searchFrom] === 10) searchFrom++;
|
|
1437
|
-
start = searchFrom;
|
|
1438
|
-
const nextBoundaryIndex = body.indexOf(boundaryBuffer, searchFrom);
|
|
1439
|
-
if (nextBoundaryIndex === -1) break;
|
|
1440
|
-
let partEnd = nextBoundaryIndex;
|
|
1441
|
-
if (partEnd >= 2 && body[partEnd - 2] === 13 && body[partEnd - 1] === 10) {
|
|
1442
|
-
partEnd -= 2;
|
|
1622
|
+
let safeIntegers = 2;
|
|
1623
|
+
if (hasOwnProperty.call(def, "safeIntegers")) {
|
|
1624
|
+
const bool = def.safeIntegers;
|
|
1625
|
+
if (typeof bool !== "boolean") {
|
|
1626
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "safeIntegers" property (should be a boolean)`);
|
|
1627
|
+
}
|
|
1628
|
+
safeIntegers = +bool;
|
|
1629
|
+
}
|
|
1630
|
+
let directOnly = false;
|
|
1631
|
+
if (hasOwnProperty.call(def, "directOnly")) {
|
|
1632
|
+
directOnly = def.directOnly;
|
|
1633
|
+
if (typeof directOnly !== "boolean") {
|
|
1634
|
+
throw new TypeError(`Virtual table module "${moduleName}" ${verb} a table definition with an invalid "directOnly" property (should be a boolean)`);
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
const columnDefinitions = [
|
|
1638
|
+
...parameters.map(identifier).map((str) => `${str} HIDDEN`),
|
|
1639
|
+
...columns.map(identifier)
|
|
1640
|
+
];
|
|
1641
|
+
return [
|
|
1642
|
+
`CREATE TABLE x(${columnDefinitions.join(", ")});`,
|
|
1643
|
+
wrapGenerator(rows, new Map(columns.map((x, i) => [x, parameters.length + i])), moduleName),
|
|
1644
|
+
parameters,
|
|
1645
|
+
safeIntegers,
|
|
1646
|
+
directOnly
|
|
1647
|
+
];
|
|
1443
1648
|
}
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1649
|
+
function wrapGenerator(generator, columnMap, moduleName) {
|
|
1650
|
+
return function* virtualTable(...args) {
|
|
1651
|
+
const output = args.map((x) => Buffer.isBuffer(x) ? Buffer.from(x) : x);
|
|
1652
|
+
for (let i = 0; i < columnMap.size; ++i) {
|
|
1653
|
+
output.push(null);
|
|
1654
|
+
}
|
|
1655
|
+
for (const row of generator(...args)) {
|
|
1656
|
+
if (Array.isArray(row)) {
|
|
1657
|
+
extractRowArray(row, output, columnMap.size, moduleName);
|
|
1658
|
+
yield output;
|
|
1659
|
+
} else if (typeof row === "object" && row !== null) {
|
|
1660
|
+
extractRowObject(row, output, columnMap, moduleName);
|
|
1661
|
+
yield output;
|
|
1662
|
+
} else {
|
|
1663
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded something that isn't a valid row object`);
|
|
1664
|
+
}
|
|
1665
|
+
}
|
|
1666
|
+
};
|
|
1449
1667
|
}
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1668
|
+
function extractRowArray(row, output, columnCount, moduleName) {
|
|
1669
|
+
if (row.length !== columnCount) {
|
|
1670
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an incorrect number of columns`);
|
|
1671
|
+
}
|
|
1672
|
+
const offset = output.length - columnCount;
|
|
1673
|
+
for (let i = 0; i < columnCount; ++i) {
|
|
1674
|
+
output[i + offset] = row[i];
|
|
1675
|
+
}
|
|
1456
1676
|
}
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
value: contentData.toString("utf-8").trim()
|
|
1471
|
-
});
|
|
1677
|
+
function extractRowObject(row, output, columnMap, moduleName) {
|
|
1678
|
+
let count = 0;
|
|
1679
|
+
for (const key of Object.keys(row)) {
|
|
1680
|
+
const index = columnMap.get(key);
|
|
1681
|
+
if (index === void 0) {
|
|
1682
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with an undeclared column "${key}"`);
|
|
1683
|
+
}
|
|
1684
|
+
output[index] = row[key];
|
|
1685
|
+
count += 1;
|
|
1686
|
+
}
|
|
1687
|
+
if (count !== columnMap.size) {
|
|
1688
|
+
throw new TypeError(`Virtual table module "${moduleName}" yielded a row with missing columns`);
|
|
1689
|
+
}
|
|
1472
1690
|
}
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
}
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
const params = match[1];
|
|
1483
|
-
const nameMatch = params.match(/name="([^"]*)"/i);
|
|
1484
|
-
const filenameMatch = params.match(/filename="([^"]*)"/i);
|
|
1485
|
-
if (nameMatch === null) return void 0;
|
|
1486
|
-
return {
|
|
1487
|
-
name: nameMatch[1],
|
|
1488
|
-
filename: filenameMatch?.[1]
|
|
1489
|
-
};
|
|
1490
|
-
}
|
|
1491
|
-
function parseContentType(headerSection) {
|
|
1492
|
-
const match = headerSection.match(/content-type:\s*([^\s;]+)/i);
|
|
1493
|
-
return match?.[1] ?? "application/octet-stream";
|
|
1494
|
-
}
|
|
1495
|
-
|
|
1496
|
-
// src/server/http/response.ts
|
|
1497
|
-
import { createReadStream, stat } from "fs";
|
|
1498
|
-
import { basename as basename2, extname as extname2, resolve } from "path";
|
|
1499
|
-
import { promisify } from "util";
|
|
1500
|
-
var statAsync = promisify(stat);
|
|
1501
|
-
var MIME_TYPES = {
|
|
1502
|
-
".html": "text/html",
|
|
1503
|
-
".css": "text/css",
|
|
1504
|
-
".js": "application/javascript",
|
|
1505
|
-
".mjs": "application/javascript",
|
|
1506
|
-
".json": "application/json",
|
|
1507
|
-
".png": "image/png",
|
|
1508
|
-
".jpg": "image/jpeg",
|
|
1509
|
-
".jpeg": "image/jpeg",
|
|
1510
|
-
".gif": "image/gif",
|
|
1511
|
-
".svg": "image/svg+xml",
|
|
1512
|
-
".webp": "image/webp",
|
|
1513
|
-
".ico": "image/x-icon",
|
|
1514
|
-
".pdf": "application/pdf",
|
|
1515
|
-
".txt": "text/plain",
|
|
1516
|
-
".xml": "application/xml",
|
|
1517
|
-
".zip": "application/zip",
|
|
1518
|
-
".woff": "font/woff",
|
|
1519
|
-
".woff2": "font/woff2",
|
|
1520
|
-
".ttf": "font/ttf",
|
|
1521
|
-
".eot": "application/vnd.ms-fontobject",
|
|
1522
|
-
".mp4": "video/mp4",
|
|
1523
|
-
".webm": "video/webm",
|
|
1524
|
-
".mp3": "audio/mpeg",
|
|
1525
|
-
".wav": "audio/wav"
|
|
1526
|
-
};
|
|
1527
|
-
var SuperResponse = class {
|
|
1528
|
-
raw;
|
|
1529
|
-
_statusCode = HttpStatus.OK;
|
|
1530
|
-
_headers = new HeadersMap();
|
|
1531
|
-
_cookies = [];
|
|
1532
|
-
_body = null;
|
|
1533
|
-
_sent = false;
|
|
1534
|
-
_contentTypeSet = false;
|
|
1535
|
-
constructor(raw) {
|
|
1536
|
-
this.raw = raw;
|
|
1537
|
-
}
|
|
1538
|
-
status(code) {
|
|
1539
|
-
this._statusCode = code;
|
|
1540
|
-
return this;
|
|
1541
|
-
}
|
|
1542
|
-
header(name, value) {
|
|
1543
|
-
this._headers.set(name, value);
|
|
1544
|
-
return this;
|
|
1545
|
-
}
|
|
1546
|
-
setHeader(name, value) {
|
|
1547
|
-
return this.header(name, value);
|
|
1548
|
-
}
|
|
1549
|
-
getHeader(name) {
|
|
1550
|
-
return this._headers.get(name);
|
|
1551
|
-
}
|
|
1552
|
-
removeHeader(name) {
|
|
1553
|
-
this._headers.delete(name);
|
|
1554
|
-
return this;
|
|
1555
|
-
}
|
|
1556
|
-
hasHeader(name) {
|
|
1557
|
-
return this._headers.has(name);
|
|
1558
|
-
}
|
|
1559
|
-
type(contentType) {
|
|
1560
|
-
this._headers.set("content-type", contentType);
|
|
1561
|
-
this._contentTypeSet = true;
|
|
1562
|
-
return this;
|
|
1563
|
-
}
|
|
1564
|
-
json(data, status) {
|
|
1565
|
-
if (status !== void 0) this._statusCode = status;
|
|
1566
|
-
const body = JSON.stringify(data);
|
|
1567
|
-
return this.send(body, void 0, "application/json");
|
|
1568
|
-
}
|
|
1569
|
-
send(body, status, contentType) {
|
|
1570
|
-
if (status !== void 0) this._statusCode = status;
|
|
1571
|
-
this._body = body;
|
|
1572
|
-
if (contentType !== void 0 && !this._contentTypeSet) {
|
|
1573
|
-
this._headers.set("content-type", contentType);
|
|
1691
|
+
function inferParameters({ length }) {
|
|
1692
|
+
if (!Number.isInteger(length) || length < 0) {
|
|
1693
|
+
throw new TypeError("Expected function.length to be a positive integer");
|
|
1694
|
+
}
|
|
1695
|
+
const params = [];
|
|
1696
|
+
for (let i = 0; i < length; ++i) {
|
|
1697
|
+
params.push(`$${i + 1}`);
|
|
1698
|
+
}
|
|
1699
|
+
return params;
|
|
1574
1700
|
}
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1701
|
+
var { hasOwnProperty } = Object.prototype;
|
|
1702
|
+
var { apply } = Function.prototype;
|
|
1703
|
+
var GeneratorFunctionPrototype = Object.getPrototypeOf(function* () {
|
|
1704
|
+
});
|
|
1705
|
+
var identifier = (str) => `"${str.replace(/"/g, '""')}"`;
|
|
1706
|
+
var defer = (x) => () => x;
|
|
1579
1707
|
}
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1708
|
+
});
|
|
1709
|
+
|
|
1710
|
+
// node_modules/better-sqlite3/lib/methods/inspect.js
|
|
1711
|
+
var require_inspect = __commonJS({
|
|
1712
|
+
"node_modules/better-sqlite3/lib/methods/inspect.js"(exports, module) {
|
|
1713
|
+
"use strict";
|
|
1714
|
+
var DatabaseInspection = function Database() {
|
|
1715
|
+
};
|
|
1716
|
+
module.exports = function inspect(depth, opts) {
|
|
1717
|
+
return Object.assign(new DatabaseInspection(), this);
|
|
1718
|
+
};
|
|
1588
1719
|
}
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1720
|
+
});
|
|
1721
|
+
|
|
1722
|
+
// node_modules/better-sqlite3/lib/database.js
|
|
1723
|
+
var require_database = __commonJS({
|
|
1724
|
+
"node_modules/better-sqlite3/lib/database.js"(exports, module) {
|
|
1725
|
+
"use strict";
|
|
1726
|
+
var fs3 = __require("fs");
|
|
1727
|
+
var path3 = __require("path");
|
|
1728
|
+
var util = require_util();
|
|
1729
|
+
var SqliteError = require_sqlite_error();
|
|
1730
|
+
var DEFAULT_ADDON;
|
|
1731
|
+
function Database(filenameGiven, options) {
|
|
1732
|
+
if (new.target == null) {
|
|
1733
|
+
return new Database(filenameGiven, options);
|
|
1602
1734
|
}
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
const fullPath = options?.root ? joinPath(options.root, filePath) : filePath;
|
|
1608
|
-
const resolved = resolve(fullPath);
|
|
1609
|
-
const root = options?.root ? resolve(options.root) : null;
|
|
1610
|
-
if (root !== null && !resolved.startsWith(root)) {
|
|
1611
|
-
this._statusCode = HttpStatus.FORBIDDEN;
|
|
1612
|
-
this._body = null;
|
|
1613
|
-
return this;
|
|
1614
|
-
}
|
|
1615
|
-
try {
|
|
1616
|
-
const stats = await statAsync(fullPath);
|
|
1617
|
-
if (!stats.isFile()) {
|
|
1618
|
-
this._statusCode = HttpStatus.NOT_FOUND;
|
|
1619
|
-
this._body = null;
|
|
1620
|
-
return this;
|
|
1735
|
+
let buffer;
|
|
1736
|
+
if (Buffer.isBuffer(filenameGiven)) {
|
|
1737
|
+
buffer = filenameGiven;
|
|
1738
|
+
filenameGiven = ":memory:";
|
|
1621
1739
|
}
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
if (options
|
|
1627
|
-
|
|
1628
|
-
|
|
1740
|
+
if (filenameGiven == null) filenameGiven = "";
|
|
1741
|
+
if (options == null) options = {};
|
|
1742
|
+
if (typeof filenameGiven !== "string") throw new TypeError("Expected first argument to be a string");
|
|
1743
|
+
if (typeof options !== "object") throw new TypeError("Expected second argument to be an options object");
|
|
1744
|
+
if ("readOnly" in options) throw new TypeError('Misspelled option "readOnly" should be "readonly"');
|
|
1745
|
+
if ("memory" in options) throw new TypeError('Option "memory" was removed in v7.0.0 (use ":memory:" filename instead)');
|
|
1746
|
+
const filename = filenameGiven.trim();
|
|
1747
|
+
const anonymous = filename === "" || filename === ":memory:";
|
|
1748
|
+
const readonly = util.getBooleanOption(options, "readonly");
|
|
1749
|
+
const fileMustExist = util.getBooleanOption(options, "fileMustExist");
|
|
1750
|
+
const timeout = "timeout" in options ? options.timeout : 5e3;
|
|
1751
|
+
const verbose = "verbose" in options ? options.verbose : null;
|
|
1752
|
+
const nativeBinding = "nativeBinding" in options ? options.nativeBinding : null;
|
|
1753
|
+
if (readonly && anonymous && !buffer) throw new TypeError("In-memory/temporary databases cannot be readonly");
|
|
1754
|
+
if (!Number.isInteger(timeout) || timeout < 0) throw new TypeError('Expected the "timeout" option to be a positive integer');
|
|
1755
|
+
if (timeout > 2147483647) throw new RangeError('Option "timeout" cannot be greater than 2147483647');
|
|
1756
|
+
if (verbose != null && typeof verbose !== "function") throw new TypeError('Expected the "verbose" option to be a function');
|
|
1757
|
+
if (nativeBinding != null && typeof nativeBinding !== "string" && typeof nativeBinding !== "object") throw new TypeError('Expected the "nativeBinding" option to be a string or addon object');
|
|
1758
|
+
let addon;
|
|
1759
|
+
if (nativeBinding == null) {
|
|
1760
|
+
addon = DEFAULT_ADDON || (DEFAULT_ADDON = require_bindings()("better_sqlite3.node"));
|
|
1761
|
+
} else if (typeof nativeBinding === "string") {
|
|
1762
|
+
const requireFunc = typeof __non_webpack_require__ === "function" ? __non_webpack_require__ : __require;
|
|
1763
|
+
addon = requireFunc(path3.resolve(nativeBinding).replace(/(\.node)?$/, ".node"));
|
|
1764
|
+
} else {
|
|
1765
|
+
addon = nativeBinding;
|
|
1629
1766
|
}
|
|
1630
|
-
if (
|
|
1631
|
-
|
|
1767
|
+
if (!addon.isInitialized) {
|
|
1768
|
+
addon.setErrorConstructor(SqliteError);
|
|
1769
|
+
addon.isInitialized = true;
|
|
1632
1770
|
}
|
|
1633
|
-
if (
|
|
1634
|
-
|
|
1635
|
-
this._headers.set(key, value);
|
|
1636
|
-
}
|
|
1771
|
+
if (!anonymous && !filename.startsWith("file:") && !fs3.existsSync(path3.dirname(filename))) {
|
|
1772
|
+
throw new TypeError("Cannot open database because the directory does not exist");
|
|
1637
1773
|
}
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
readStream.pipe(this.raw);
|
|
1642
|
-
readStream.on("end", () => {
|
|
1643
|
-
this._sent = true;
|
|
1644
|
-
});
|
|
1645
|
-
readStream.on("error", () => {
|
|
1646
|
-
if (!this._sent) {
|
|
1647
|
-
this._sent = true;
|
|
1648
|
-
this.raw.statusCode = HttpStatus.INTERNAL_SERVER_ERROR;
|
|
1649
|
-
this.raw.end();
|
|
1650
|
-
}
|
|
1774
|
+
Object.defineProperties(this, {
|
|
1775
|
+
[util.cppdb]: { value: new addon.Database(filename, filenameGiven, anonymous, readonly, fileMustExist, timeout, verbose || null, buffer || null) },
|
|
1776
|
+
...wrappers.getters
|
|
1651
1777
|
});
|
|
1652
|
-
} catch {
|
|
1653
|
-
this._statusCode = HttpStatus.NOT_FOUND;
|
|
1654
|
-
this._body = null;
|
|
1655
1778
|
}
|
|
1656
|
-
|
|
1779
|
+
var wrappers = require_wrappers();
|
|
1780
|
+
Database.prototype.prepare = wrappers.prepare;
|
|
1781
|
+
Database.prototype.transaction = require_transaction();
|
|
1782
|
+
Database.prototype.pragma = require_pragma();
|
|
1783
|
+
Database.prototype.backup = require_backup();
|
|
1784
|
+
Database.prototype.serialize = require_serialize();
|
|
1785
|
+
Database.prototype.function = require_function();
|
|
1786
|
+
Database.prototype.aggregate = require_aggregate();
|
|
1787
|
+
Database.prototype.table = require_table();
|
|
1788
|
+
Database.prototype.loadExtension = wrappers.loadExtension;
|
|
1789
|
+
Database.prototype.exec = wrappers.exec;
|
|
1790
|
+
Database.prototype.close = wrappers.close;
|
|
1791
|
+
Database.prototype.defaultSafeIntegers = wrappers.defaultSafeIntegers;
|
|
1792
|
+
Database.prototype.unsafeMode = wrappers.unsafeMode;
|
|
1793
|
+
Database.prototype[util.inspect] = require_inspect();
|
|
1794
|
+
module.exports = Database;
|
|
1657
1795
|
}
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1796
|
+
});
|
|
1797
|
+
|
|
1798
|
+
// node_modules/better-sqlite3/lib/index.js
|
|
1799
|
+
var require_lib = __commonJS({
|
|
1800
|
+
"node_modules/better-sqlite3/lib/index.js"(exports, module) {
|
|
1801
|
+
"use strict";
|
|
1802
|
+
module.exports = require_database();
|
|
1803
|
+
module.exports.SqliteError = require_sqlite_error();
|
|
1666
1804
|
}
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
}
|
|
1805
|
+
});
|
|
1806
|
+
|
|
1807
|
+
// src/server/container/index.ts
|
|
1808
|
+
var Container = class {
|
|
1809
|
+
bindings = /* @__PURE__ */ new Map();
|
|
1810
|
+
resolving = /* @__PURE__ */ new Set();
|
|
1811
|
+
bind(name, factory) {
|
|
1812
|
+
this.bindings.set(name, { factory, singleton: false });
|
|
1676
1813
|
return this;
|
|
1677
1814
|
}
|
|
1678
|
-
|
|
1679
|
-
this.
|
|
1815
|
+
singleton(name, factory) {
|
|
1816
|
+
this.bindings.set(name, { factory, singleton: true });
|
|
1680
1817
|
return this;
|
|
1681
1818
|
}
|
|
1682
|
-
|
|
1683
|
-
this.
|
|
1819
|
+
instance(name, instance) {
|
|
1820
|
+
this.bindings.set(name, {
|
|
1821
|
+
factory: () => instance,
|
|
1822
|
+
singleton: true,
|
|
1823
|
+
instance
|
|
1824
|
+
});
|
|
1684
1825
|
return this;
|
|
1685
1826
|
}
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
return this._sent;
|
|
1691
|
-
}
|
|
1692
|
-
get rawResponse() {
|
|
1693
|
-
return this.raw;
|
|
1694
|
-
}
|
|
1695
|
-
async flush() {
|
|
1696
|
-
if (this._sent) return;
|
|
1697
|
-
this._sent = true;
|
|
1698
|
-
this.flushHeaders();
|
|
1699
|
-
this.raw.statusCode = this._statusCode;
|
|
1700
|
-
if (this._body !== null) {
|
|
1701
|
-
this.raw.end(this._body);
|
|
1702
|
-
} else {
|
|
1703
|
-
this.raw.end();
|
|
1827
|
+
resolve(name) {
|
|
1828
|
+
const binding = this.bindings.get(name);
|
|
1829
|
+
if (binding === void 0) {
|
|
1830
|
+
throw new Error(`Binding not found: ${name}`);
|
|
1704
1831
|
}
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1832
|
+
if (binding.singleton && binding.instance !== void 0) {
|
|
1833
|
+
return binding.instance;
|
|
1834
|
+
}
|
|
1835
|
+
if (this.resolving.has(name)) {
|
|
1836
|
+
throw new Error(
|
|
1837
|
+
`Circular dependency detected: ${name} is already being resolved`
|
|
1838
|
+
);
|
|
1709
1839
|
}
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1840
|
+
this.resolving.add(name);
|
|
1841
|
+
try {
|
|
1842
|
+
const instance = binding.factory();
|
|
1843
|
+
if (binding.singleton) {
|
|
1844
|
+
binding.instance = instance;
|
|
1713
1845
|
}
|
|
1846
|
+
return instance;
|
|
1847
|
+
} finally {
|
|
1848
|
+
this.resolving.delete(name);
|
|
1714
1849
|
}
|
|
1715
1850
|
}
|
|
1851
|
+
has(name) {
|
|
1852
|
+
return this.bindings.has(name);
|
|
1853
|
+
}
|
|
1854
|
+
remove(name) {
|
|
1855
|
+
this.bindings.delete(name);
|
|
1856
|
+
}
|
|
1857
|
+
clear() {
|
|
1858
|
+
this.bindings.clear();
|
|
1859
|
+
this.resolving.clear();
|
|
1860
|
+
}
|
|
1861
|
+
getBindings() {
|
|
1862
|
+
return new Map(this.bindings);
|
|
1863
|
+
}
|
|
1716
1864
|
};
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1865
|
+
|
|
1866
|
+
// src/server/controller/index.ts
|
|
1867
|
+
var controllerPrefixMap = /* @__PURE__ */ new WeakMap();
|
|
1868
|
+
var controllerRoutesMap = /* @__PURE__ */ new WeakMap();
|
|
1869
|
+
function createRouteDecorator(method) {
|
|
1870
|
+
return (path3) => {
|
|
1871
|
+
return (target, context) => {
|
|
1872
|
+
const classTarget = context.static ? target : target.constructor;
|
|
1873
|
+
const routes = controllerRoutesMap.get(classTarget) ?? [];
|
|
1874
|
+
routes.push({ method, path: path3, handler: context.name });
|
|
1875
|
+
controllerRoutesMap.set(classTarget, routes);
|
|
1876
|
+
};
|
|
1877
|
+
};
|
|
1878
|
+
}
|
|
1879
|
+
var get = createRouteDecorator("GET");
|
|
1880
|
+
var post = createRouteDecorator("POST");
|
|
1881
|
+
var put = createRouteDecorator("PUT");
|
|
1882
|
+
var patch = createRouteDecorator("PATCH");
|
|
1883
|
+
var del = createRouteDecorator("DELETE");
|
|
1884
|
+
function getControllerPrefix(controllerClass) {
|
|
1885
|
+
return controllerPrefixMap.get(controllerClass) ?? "";
|
|
1886
|
+
}
|
|
1887
|
+
function getControllerRoutes(controllerClass) {
|
|
1888
|
+
return controllerRoutesMap.get(controllerClass) ?? [];
|
|
1721
1889
|
}
|
|
1722
1890
|
|
|
1723
1891
|
// src/server/engine/index.ts
|
|
1892
|
+
init_request();
|
|
1893
|
+
init_response();
|
|
1894
|
+
init_errors();
|
|
1895
|
+
import { createServer as createHttpServer } from "http";
|
|
1896
|
+
import { createServer as createHttpsServer } from "https";
|
|
1897
|
+
import { readFileSync } from "fs";
|
|
1724
1898
|
var NodeEngine = class {
|
|
1725
1899
|
async createServer(handler) {
|
|
1726
1900
|
const server = createHttpServer(async (nodeReq, nodeRes) => {
|
|
@@ -1730,8 +1904,9 @@ var NodeEngine = class {
|
|
|
1730
1904
|
await handler(req, res);
|
|
1731
1905
|
} catch (_err) {
|
|
1732
1906
|
if (!res.headersSent) {
|
|
1733
|
-
const
|
|
1734
|
-
|
|
1907
|
+
const error = _err instanceof Error ? _err : new Error(String(_err));
|
|
1908
|
+
const httpError = normalizeError(error);
|
|
1909
|
+
res.status(httpError.status).json(httpError.toJSON());
|
|
1735
1910
|
await res.flush();
|
|
1736
1911
|
}
|
|
1737
1912
|
}
|
|
@@ -1766,7 +1941,11 @@ var NodeEngine = class {
|
|
|
1766
1941
|
}
|
|
1767
1942
|
};
|
|
1768
1943
|
|
|
1944
|
+
// src/server/index.ts
|
|
1945
|
+
init_status();
|
|
1946
|
+
|
|
1769
1947
|
// src/server/middleware/index.ts
|
|
1948
|
+
init_status();
|
|
1770
1949
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
1771
1950
|
import { createReadStream as createReadStream2, existsSync, statSync } from "fs";
|
|
1772
1951
|
import { extname as extname3, join as join2, resolve as resolve2 } from "path";
|
|
@@ -4347,10 +4526,15 @@ var Seeder = class {
|
|
|
4347
4526
|
|
|
4348
4527
|
// src/server/database/model.ts
|
|
4349
4528
|
var Model = class {
|
|
4529
|
+
/** Primary key */
|
|
4350
4530
|
id;
|
|
4351
4531
|
static table = "";
|
|
4352
4532
|
static connection = null;
|
|
4353
4533
|
static queryRunner = null;
|
|
4534
|
+
static relationDefs = /* @__PURE__ */ new Map();
|
|
4535
|
+
static eagerLoads = /* @__PURE__ */ new Map();
|
|
4536
|
+
/** @internal cache for loaded relations on instances */
|
|
4537
|
+
_relations = {};
|
|
4354
4538
|
static setConnection(conn) {
|
|
4355
4539
|
this.connection = conn;
|
|
4356
4540
|
this.queryRunner = conn;
|
|
@@ -4361,14 +4545,74 @@ var Model = class {
|
|
|
4361
4545
|
}
|
|
4362
4546
|
return new QueryBuilder(this.queryRunner, this.table);
|
|
4363
4547
|
}
|
|
4548
|
+
// ─── Relations Definition ──────────────────────────────────
|
|
4549
|
+
static hasOne(relatedModel, foreignKey, localKey) {
|
|
4550
|
+
const key = `hasOne:${relatedModel.table}`;
|
|
4551
|
+
this.relationDefs.set(key, {
|
|
4552
|
+
type: "hasOne",
|
|
4553
|
+
relatedModel,
|
|
4554
|
+
foreignKey: foreignKey ?? `${this.table}_id`,
|
|
4555
|
+
localKey: localKey ?? "id"
|
|
4556
|
+
});
|
|
4557
|
+
}
|
|
4558
|
+
static hasMany(relatedModel, foreignKey, localKey) {
|
|
4559
|
+
const key = `hasMany:${relatedModel.table}`;
|
|
4560
|
+
this.relationDefs.set(key, {
|
|
4561
|
+
type: "hasMany",
|
|
4562
|
+
relatedModel,
|
|
4563
|
+
foreignKey: foreignKey ?? `${this.table}_id`,
|
|
4564
|
+
localKey: localKey ?? "id"
|
|
4565
|
+
});
|
|
4566
|
+
}
|
|
4567
|
+
static belongsTo(relatedModel, foreignKey, ownerKey) {
|
|
4568
|
+
const key = `belongsTo:${relatedModel.table}`;
|
|
4569
|
+
this.relationDefs.set(key, {
|
|
4570
|
+
type: "belongsTo",
|
|
4571
|
+
relatedModel,
|
|
4572
|
+
foreignKey: foreignKey ?? `${relatedModel.table}_id`,
|
|
4573
|
+
localKey: ownerKey ?? "id"
|
|
4574
|
+
});
|
|
4575
|
+
}
|
|
4576
|
+
static belongsToMany(relatedModel, pivotTable, foreignPivotKey, relatedPivotKey) {
|
|
4577
|
+
const tables = [this.table, relatedModel.table].sort();
|
|
4578
|
+
const key = `belongsToMany:${relatedModel.table}`;
|
|
4579
|
+
this.relationDefs.set(key, {
|
|
4580
|
+
type: "belongsToMany",
|
|
4581
|
+
relatedModel,
|
|
4582
|
+
foreignKey: foreignPivotKey ?? `${this.table}_id`,
|
|
4583
|
+
localKey: relatedPivotKey ?? `${relatedModel.table}_id`,
|
|
4584
|
+
pivotTable: pivotTable ?? `${tables[0]}_${tables[1]}`
|
|
4585
|
+
});
|
|
4586
|
+
}
|
|
4587
|
+
static morphMany(relatedModel, morphName) {
|
|
4588
|
+
const key = `morphMany:${morphName}`;
|
|
4589
|
+
this.relationDefs.set(key, {
|
|
4590
|
+
type: "morphMany",
|
|
4591
|
+
relatedModel,
|
|
4592
|
+
foreignKey: `${morphName}_id`,
|
|
4593
|
+
localKey: "id",
|
|
4594
|
+
morphName
|
|
4595
|
+
});
|
|
4596
|
+
}
|
|
4597
|
+
// ─── Eager Loading ─────────────────────────────────────────
|
|
4598
|
+
static with(...relations) {
|
|
4599
|
+
for (const rel of relations) {
|
|
4600
|
+
this.eagerLoads.set(rel, true);
|
|
4601
|
+
}
|
|
4602
|
+
}
|
|
4603
|
+
// ─── Query Shortcuts ───────────────────────────────────────
|
|
4364
4604
|
static async all() {
|
|
4365
4605
|
const rows = await this.query().get();
|
|
4366
|
-
|
|
4606
|
+
const instances = rows.map((row) => this.hydrate(row));
|
|
4607
|
+
await this.loadRelations(instances);
|
|
4608
|
+
return instances;
|
|
4367
4609
|
}
|
|
4368
4610
|
static async find(id) {
|
|
4369
4611
|
const row = await this.query().find(id);
|
|
4370
4612
|
if (!row) return null;
|
|
4371
|
-
|
|
4613
|
+
const instance = this.hydrate(row);
|
|
4614
|
+
await this.loadRelations([instance]);
|
|
4615
|
+
return instance;
|
|
4372
4616
|
}
|
|
4373
4617
|
static async where(column, value) {
|
|
4374
4618
|
return this.query().where(column, value);
|
|
@@ -4395,6 +4639,7 @@ var Model = class {
|
|
|
4395
4639
|
}
|
|
4396
4640
|
return this.create({ ...attributes, ...values });
|
|
4397
4641
|
}
|
|
4642
|
+
// ─── Instance Methods ──────────────────────────────────────
|
|
4398
4643
|
async save() {
|
|
4399
4644
|
const ModelClass = this.constructor;
|
|
4400
4645
|
const id = this.id;
|
|
@@ -4412,22 +4657,64 @@ var Model = class {
|
|
|
4412
4657
|
await ModelClass.query().where("id", id).delete();
|
|
4413
4658
|
}
|
|
4414
4659
|
}
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
const
|
|
4419
|
-
|
|
4420
|
-
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4424
|
-
|
|
4425
|
-
|
|
4660
|
+
// ─── Relation Loader ───────────────────────────────────────
|
|
4661
|
+
static async loadRelations(instances) {
|
|
4662
|
+
if (instances.length === 0) return;
|
|
4663
|
+
for (const [key, def] of this.relationDefs) {
|
|
4664
|
+
const shouldLoad = this.eagerLoads.size === 0 || this.eagerLoads.has(key.split(":")[1] ?? key);
|
|
4665
|
+
if (!shouldLoad) continue;
|
|
4666
|
+
const localIds = instances.map((i) => i[def.localKey]).filter(Boolean);
|
|
4667
|
+
if (def.type === "belongsTo") {
|
|
4668
|
+
if (!def.relatedModel.queryRunner) def.relatedModel.setConnection(this.queryRunner);
|
|
4669
|
+
const related = await def.relatedModel.query().whereIn(def.localKey, localIds).get();
|
|
4670
|
+
for (const inst of instances) {
|
|
4671
|
+
inst._relations[key] = related.find((r) => r[def.localKey] === inst[def.foreignKey]) ?? null;
|
|
4672
|
+
}
|
|
4673
|
+
}
|
|
4674
|
+
if (def.type === "hasMany") {
|
|
4675
|
+
if (!def.relatedModel.queryRunner) def.relatedModel.setConnection(this.queryRunner);
|
|
4676
|
+
const related = await def.relatedModel.query().whereIn(def.foreignKey, localIds).get();
|
|
4677
|
+
for (const inst of instances) {
|
|
4678
|
+
inst._relations[key] = related.filter((r) => r[def.foreignKey] === inst[def.localKey]);
|
|
4679
|
+
}
|
|
4680
|
+
}
|
|
4681
|
+
if (def.type === "hasOne") {
|
|
4682
|
+
if (!def.relatedModel.queryRunner) def.relatedModel.setConnection(this.queryRunner);
|
|
4683
|
+
const related = await def.relatedModel.query().whereIn(def.foreignKey, localIds).get();
|
|
4684
|
+
for (const inst of instances) {
|
|
4685
|
+
inst._relations[key] = related.find((r) => r[def.foreignKey] === inst[def.localKey]) ?? null;
|
|
4686
|
+
}
|
|
4687
|
+
}
|
|
4688
|
+
if (def.type === "belongsToMany" && def.pivotTable) {
|
|
4689
|
+
if (!def.relatedModel.queryRunner) def.relatedModel.setConnection(this.queryRunner);
|
|
4690
|
+
const pivotQb = new QueryBuilder(this.queryRunner, def.pivotTable);
|
|
4691
|
+
const pivotRows = await pivotQb.whereIn(def.foreignKey, localIds).get();
|
|
4692
|
+
const relatedIds = pivotRows.map((r) => r[def.localKey]);
|
|
4693
|
+
if (relatedIds.length > 0) {
|
|
4694
|
+
const related = await def.relatedModel.query().whereIn("id", relatedIds).get();
|
|
4695
|
+
for (const inst of instances) {
|
|
4696
|
+
const pivots = pivotRows.filter((p) => p[def.foreignKey] === inst[def.localKey]);
|
|
4697
|
+
inst._relations[key] = pivots.map((p) => related.find((r) => r.id === p[def.localKey])).filter(Boolean);
|
|
4698
|
+
}
|
|
4699
|
+
} else {
|
|
4700
|
+
for (const inst of instances) {
|
|
4701
|
+
inst._relations[key] = [];
|
|
4702
|
+
}
|
|
4703
|
+
}
|
|
4704
|
+
}
|
|
4705
|
+
if (def.type === "morphMany" && def.morphName) {
|
|
4706
|
+
if (!def.relatedModel.queryRunner) def.relatedModel.setConnection(this.queryRunner);
|
|
4707
|
+
const related = await def.relatedModel.query().where(`${def.morphName}_type`, this.name).whereIn(`${def.morphName}_id`, localIds).get();
|
|
4708
|
+
for (const inst of instances) {
|
|
4709
|
+
inst._relations[key] = related.filter((r) => r[`${def.morphName}_id`] === inst[def.localKey]);
|
|
4710
|
+
}
|
|
4711
|
+
}
|
|
4712
|
+
}
|
|
4426
4713
|
}
|
|
4714
|
+
// ─── Internal Helpers ──────────────────────────────────────
|
|
4427
4715
|
static hydrate(data) {
|
|
4428
4716
|
const instance = new this();
|
|
4429
4717
|
for (const [key, value] of Object.entries(data)) {
|
|
4430
|
-
;
|
|
4431
4718
|
instance[key] = value;
|
|
4432
4719
|
}
|
|
4433
4720
|
return instance;
|
|
@@ -4447,7 +4734,7 @@ var Model = class {
|
|
|
4447
4734
|
"getData"
|
|
4448
4735
|
]);
|
|
4449
4736
|
for (const key of ownKeys) {
|
|
4450
|
-
if (typeof key === "string" && !classKeys.has(key) && key !== "constructor") {
|
|
4737
|
+
if (typeof key === "string" && !classKeys.has(key) && key !== "constructor" && !key.startsWith("_")) {
|
|
4451
4738
|
data[key] = instance[key];
|
|
4452
4739
|
}
|
|
4453
4740
|
}
|
|
@@ -4942,6 +5229,7 @@ function storage() {
|
|
|
4942
5229
|
}
|
|
4943
5230
|
|
|
4944
5231
|
// src/server/index.ts
|
|
5232
|
+
init_errors();
|
|
4945
5233
|
var SuperApp = class {
|
|
4946
5234
|
router;
|
|
4947
5235
|
container;
|
|
@@ -4950,6 +5238,10 @@ var SuperApp = class {
|
|
|
4950
5238
|
globalPipeline;
|
|
4951
5239
|
started = false;
|
|
4952
5240
|
serverPromise;
|
|
5241
|
+
onErrorHandler = null;
|
|
5242
|
+
onNotFoundHandler = null;
|
|
5243
|
+
shutdownHandlers = [];
|
|
5244
|
+
shuttingDown = false;
|
|
4953
5245
|
constructor(options = {}) {
|
|
4954
5246
|
this.container = options.container ?? new Container();
|
|
4955
5247
|
this.router = new Router();
|
|
@@ -5049,6 +5341,18 @@ var SuperApp = class {
|
|
|
5049
5341
|
view(_engine) {
|
|
5050
5342
|
return this;
|
|
5051
5343
|
}
|
|
5344
|
+
onError(handler) {
|
|
5345
|
+
this.onErrorHandler = handler;
|
|
5346
|
+
return this;
|
|
5347
|
+
}
|
|
5348
|
+
notFound(handler) {
|
|
5349
|
+
this.onNotFoundHandler = handler;
|
|
5350
|
+
return this;
|
|
5351
|
+
}
|
|
5352
|
+
onShutdown(handler) {
|
|
5353
|
+
this.shutdownHandlers.push(handler);
|
|
5354
|
+
return this;
|
|
5355
|
+
}
|
|
5052
5356
|
getServer() {
|
|
5053
5357
|
return this.serverInstance;
|
|
5054
5358
|
}
|
|
@@ -5073,8 +5377,29 @@ var SuperApp = class {
|
|
|
5073
5377
|
}
|
|
5074
5378
|
listen(port, callback) {
|
|
5075
5379
|
this.serverPromise = this.start(port).then(() => {
|
|
5380
|
+
const shutdown = async (signal) => {
|
|
5381
|
+
if (this.shuttingDown) return;
|
|
5382
|
+
this.shuttingDown = true;
|
|
5383
|
+
console.log(`
|
|
5384
|
+
\u26A0\uFE0F Received ${signal}. Starting graceful shutdown...`);
|
|
5385
|
+
for (const handler of this.shutdownHandlers) {
|
|
5386
|
+
try {
|
|
5387
|
+
await handler();
|
|
5388
|
+
} catch {
|
|
5389
|
+
}
|
|
5390
|
+
}
|
|
5391
|
+
await this.close();
|
|
5392
|
+
console.log("\u2713 Server shut down gracefully");
|
|
5393
|
+
process.exit(0);
|
|
5394
|
+
};
|
|
5395
|
+
process.on("SIGINT", () => shutdown("SIGINT"));
|
|
5396
|
+
process.on("SIGTERM", () => shutdown("SIGTERM"));
|
|
5397
|
+
if (process.stdin && process.stdin.isTTY) {
|
|
5398
|
+
process.stdin.on("end", () => shutdown("stdin end"));
|
|
5399
|
+
}
|
|
5076
5400
|
callback?.();
|
|
5077
5401
|
});
|
|
5402
|
+
return this;
|
|
5078
5403
|
}
|
|
5079
5404
|
async close() {
|
|
5080
5405
|
if (this.serverInstance !== void 0) {
|
|
@@ -5091,8 +5416,20 @@ var SuperApp = class {
|
|
|
5091
5416
|
async handleRequest(req, res) {
|
|
5092
5417
|
const resolvedRoute = this.router.resolve(req.method, req.path);
|
|
5093
5418
|
if (resolvedRoute === null) {
|
|
5419
|
+
if (this.onNotFoundHandler !== null) {
|
|
5420
|
+
const ctx2 = {
|
|
5421
|
+
request: req,
|
|
5422
|
+
response: res,
|
|
5423
|
+
params: {},
|
|
5424
|
+
query: req.query,
|
|
5425
|
+
container: this.container
|
|
5426
|
+
};
|
|
5427
|
+
await this.onNotFoundHandler(ctx2);
|
|
5428
|
+
if (!res.headersSent) await res.flush();
|
|
5429
|
+
return;
|
|
5430
|
+
}
|
|
5094
5431
|
res.status(HttpStatus.NOT_FOUND).json({
|
|
5095
|
-
error: "
|
|
5432
|
+
error: "NOT_FOUND",
|
|
5096
5433
|
message: `Route ${req.method} ${req.path} not found`
|
|
5097
5434
|
});
|
|
5098
5435
|
await res.flush();
|
|
@@ -5106,15 +5443,26 @@ var SuperApp = class {
|
|
|
5106
5443
|
query: req.query,
|
|
5107
5444
|
container: this.container
|
|
5108
5445
|
};
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
await
|
|
5446
|
+
try {
|
|
5447
|
+
await this.globalPipeline.run(ctx, async () => {
|
|
5448
|
+
const routePipeline = new MiddlewarePipeline();
|
|
5449
|
+
for (const mw of resolvedRoute.middleware) {
|
|
5450
|
+
routePipeline.use(mw);
|
|
5451
|
+
}
|
|
5452
|
+
await routePipeline.run(ctx, async () => {
|
|
5453
|
+
await resolvedRoute.handler(ctx);
|
|
5454
|
+
});
|
|
5116
5455
|
});
|
|
5117
|
-
})
|
|
5456
|
+
} catch (err) {
|
|
5457
|
+
if (this.onErrorHandler !== null) {
|
|
5458
|
+
await this.onErrorHandler(
|
|
5459
|
+
err instanceof Error ? err : new Error(String(err)),
|
|
5460
|
+
ctx
|
|
5461
|
+
);
|
|
5462
|
+
} else {
|
|
5463
|
+
throw err;
|
|
5464
|
+
}
|
|
5465
|
+
}
|
|
5118
5466
|
if (!res.headersSent) {
|
|
5119
5467
|
await res.flush();
|
|
5120
5468
|
}
|
|
@@ -5130,25 +5478,37 @@ function createControllerInstance(controller, ctx) {
|
|
|
5130
5478
|
return instance;
|
|
5131
5479
|
}
|
|
5132
5480
|
export {
|
|
5481
|
+
BadRequestException,
|
|
5133
5482
|
Cache,
|
|
5134
5483
|
ColumnDefinition,
|
|
5484
|
+
ConflictException,
|
|
5135
5485
|
DatabaseConnection,
|
|
5136
5486
|
Event,
|
|
5487
|
+
ForbiddenException,
|
|
5137
5488
|
ForeignKeyDefinition,
|
|
5489
|
+
HttpException,
|
|
5490
|
+
InternalServerErrorException,
|
|
5138
5491
|
LocalDisk,
|
|
5492
|
+
MethodNotAllowedException,
|
|
5139
5493
|
Migrator,
|
|
5140
5494
|
Model,
|
|
5141
5495
|
MysqlDialect,
|
|
5496
|
+
NotFoundException,
|
|
5142
5497
|
Pagination,
|
|
5143
5498
|
PostgresqlDialect,
|
|
5144
5499
|
QueryBuilder,
|
|
5145
5500
|
SchemaBuilder,
|
|
5146
5501
|
Seeder,
|
|
5502
|
+
ServiceUnavailableException,
|
|
5147
5503
|
SqliteDialect,
|
|
5148
5504
|
Storage,
|
|
5149
5505
|
SuperApp,
|
|
5150
5506
|
TableBlueprint,
|
|
5507
|
+
TooManyRequestsException,
|
|
5151
5508
|
URLBuilder,
|
|
5509
|
+
UnauthorizedException,
|
|
5510
|
+
UnprocessableEntityException,
|
|
5511
|
+
ValidationException,
|
|
5152
5512
|
cacheResponse,
|
|
5153
5513
|
createControllerInstance,
|
|
5154
5514
|
createDialect,
|
|
@@ -5156,6 +5516,8 @@ export {
|
|
|
5156
5516
|
createEvent,
|
|
5157
5517
|
createStorage,
|
|
5158
5518
|
event,
|
|
5519
|
+
normalizeError,
|
|
5520
|
+
registerExceptionHandler,
|
|
5159
5521
|
registerMacro,
|
|
5160
5522
|
responseMacros,
|
|
5161
5523
|
speexjs,
|