@arkstack/common 0.16.3 → 0.16.4
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/dist--I3ELzrl.js
DELETED
|
@@ -1,3581 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
import "node:crypto";
|
|
3
|
-
import { createJiti } from "jiti";
|
|
4
|
-
import "@arkstack/contract";
|
|
5
|
-
import { isAbsolute, join, resolve } from "node:path";
|
|
6
|
-
import { pathToFileURL } from "node:url";
|
|
7
|
-
import { readdir, stat } from "node:fs/promises";
|
|
8
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
9
|
-
//#region \0rolldown/runtime.js
|
|
10
|
-
var __create = Object.create;
|
|
11
|
-
var __defProp = Object.defineProperty;
|
|
12
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
-
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
17
|
-
var __copyProps = (to, from, except, desc) => {
|
|
18
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
19
|
-
key = keys[i];
|
|
20
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
21
|
-
get: ((k) => from[k]).bind(null, key),
|
|
22
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
return to;
|
|
26
|
-
};
|
|
27
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
-
value: mod,
|
|
29
|
-
enumerable: true
|
|
30
|
-
}) : target, mod));
|
|
31
|
-
//#endregion
|
|
32
|
-
//#region ../../node_modules/.pnpm/clear-router@2.9.0_@h3ravel+support@2.2.1_@types+node@25.6.2__express@5.2.1_h3@2.0.1-rc_b9d44c4015b9a26737430ad34be3397f/node_modules/clear-router/dist/ClearRequest.mjs
|
|
33
|
-
var ClearRequest = class {
|
|
34
|
-
/**
|
|
35
|
-
* @param body - Parsed request body
|
|
36
|
-
*/
|
|
37
|
-
body;
|
|
38
|
-
/**
|
|
39
|
-
* @param query - Parsed query parameters
|
|
40
|
-
*/
|
|
41
|
-
query;
|
|
42
|
-
/**
|
|
43
|
-
* @param params - Parsed route parameters
|
|
44
|
-
*/
|
|
45
|
-
params;
|
|
46
|
-
route;
|
|
47
|
-
constructor(init) {
|
|
48
|
-
Object.assign(this, init);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
//#endregion
|
|
52
|
-
//#region ../../node_modules/.pnpm/clear-router@2.9.0_@h3ravel+support@2.2.1_@types+node@25.6.2__express@5.2.1_h3@2.0.1-rc_b9d44c4015b9a26737430ad34be3397f/node_modules/clear-router/dist/Route.mjs
|
|
53
|
-
/**
|
|
54
|
-
* Parse the placeholder parameters declared in a domain/host pattern such as
|
|
55
|
-
* `{account}.example.com`. Mirrors the path parameter syntax (supporting the
|
|
56
|
-
* optional `{name?}` form) so domain parameters feel consistent with path ones.
|
|
57
|
-
*
|
|
58
|
-
* @param pattern
|
|
59
|
-
* @returns
|
|
60
|
-
*/
|
|
61
|
-
const parseDomainParameters = (pattern) => {
|
|
62
|
-
if (!pattern) return [];
|
|
63
|
-
const parameters = [];
|
|
64
|
-
const seen = /* @__PURE__ */ new Set();
|
|
65
|
-
const matcher = /\{([^{}]+)\}/g;
|
|
66
|
-
let match;
|
|
67
|
-
while ((match = matcher.exec(pattern)) !== null) {
|
|
68
|
-
const raw = match[1].trim();
|
|
69
|
-
const optional = raw.endsWith("?");
|
|
70
|
-
const [name, field] = (optional ? raw.slice(0, -1) : raw).split(":", 2).map((part) => part.trim());
|
|
71
|
-
if (!name || seen.has(name)) continue;
|
|
72
|
-
seen.add(name);
|
|
73
|
-
parameters.push({
|
|
74
|
-
name,
|
|
75
|
-
field: field || void 0,
|
|
76
|
-
optional
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
return parameters;
|
|
80
|
-
};
|
|
81
|
-
/**
|
|
82
|
-
* @class clear-router Route
|
|
83
|
-
* @description A route describes a single enpoint on clear-router
|
|
84
|
-
* @author 3m1n3nc3
|
|
85
|
-
* @repository https://github.com/arkstack-hq/clear-router
|
|
86
|
-
*/
|
|
87
|
-
var Route = class Route {
|
|
88
|
-
ctx;
|
|
89
|
-
body = {};
|
|
90
|
-
query = {};
|
|
91
|
-
params = {};
|
|
92
|
-
clearRequest;
|
|
93
|
-
methods;
|
|
94
|
-
path;
|
|
95
|
-
registrationPaths;
|
|
96
|
-
parameters;
|
|
97
|
-
routeName;
|
|
98
|
-
handler;
|
|
99
|
-
middlewares;
|
|
100
|
-
controllerName;
|
|
101
|
-
actionName;
|
|
102
|
-
handlerType;
|
|
103
|
-
middlewareCount;
|
|
104
|
-
domainPattern;
|
|
105
|
-
domainParameters;
|
|
106
|
-
constraints = {};
|
|
107
|
-
constructor(methods, path, handler, middlewares = [], options = {}) {
|
|
108
|
-
this.methods = methods;
|
|
109
|
-
this.path = path;
|
|
110
|
-
this.registrationPaths = options.registrationPaths || [path];
|
|
111
|
-
this.parameters = options.parameters || [];
|
|
112
|
-
this.handler = handler;
|
|
113
|
-
this.middlewares = middlewares;
|
|
114
|
-
this.handlerType = Array.isArray(handler) ? "controller" : "function";
|
|
115
|
-
this.middlewareCount = middlewares.length;
|
|
116
|
-
this.controllerName = Array.isArray(handler) ? handler[0]?.name : void 0;
|
|
117
|
-
this.actionName = Array.isArray(handler) ? handler[1] : typeof handler === "function" ? handler.constructor.name ?? handler.name : void 0;
|
|
118
|
-
this.domainPattern = options.domain;
|
|
119
|
-
this.domainParameters = parseDomainParameters(options.domain);
|
|
120
|
-
this.onName = options.onName;
|
|
121
|
-
this.normalizeMiddleware = options.normalizeMiddleware;
|
|
122
|
-
}
|
|
123
|
-
onName;
|
|
124
|
-
normalizeMiddleware;
|
|
125
|
-
static currentResolvers;
|
|
126
|
-
/**
|
|
127
|
-
* Wire the resolvers used by the static `current*` accessors. Called once by
|
|
128
|
-
* `CoreRouter` so `Route.current()` reflects the active request.
|
|
129
|
-
*
|
|
130
|
-
* @internal
|
|
131
|
-
* @param resolvers
|
|
132
|
-
*/
|
|
133
|
-
static bindCurrentResolvers(resolvers) {
|
|
134
|
-
Route.currentResolvers = resolvers;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Get the route currently being dispatched, if any.
|
|
138
|
-
*
|
|
139
|
-
* @returns
|
|
140
|
-
*/
|
|
141
|
-
static current() {
|
|
142
|
-
return Route.currentResolvers?.current();
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Get the name of the route currently being dispatched.
|
|
146
|
-
*
|
|
147
|
-
* @returns
|
|
148
|
-
*/
|
|
149
|
-
static currentRouteName() {
|
|
150
|
-
return Route.currentResolvers?.currentRouteName() ?? "";
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Get the action (controller@method or `Closure`) of the route currently
|
|
154
|
-
* being dispatched.
|
|
155
|
-
*
|
|
156
|
-
* @returns
|
|
157
|
-
*/
|
|
158
|
-
static currentRouteAction() {
|
|
159
|
-
return Route.currentResolvers?.currentRouteAction() ?? "";
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* The route action expressed as `Controller@method` for controller routes or
|
|
163
|
-
* `Closure` for callback routes.
|
|
164
|
-
*/
|
|
165
|
-
get action() {
|
|
166
|
-
if (this.handlerType === "controller") {
|
|
167
|
-
const method = String(this.actionName ?? "");
|
|
168
|
-
return this.controllerName ? `${this.controllerName}@${method}` : method;
|
|
169
|
-
}
|
|
170
|
-
return "Closure";
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Set the route name
|
|
174
|
-
*
|
|
175
|
-
* @param name
|
|
176
|
-
* @returns
|
|
177
|
-
*/
|
|
178
|
-
name(name) {
|
|
179
|
-
const previousName = this.routeName;
|
|
180
|
-
this.routeName = name;
|
|
181
|
-
this.onName?.(name, this, previousName);
|
|
182
|
-
return this;
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Constrain the route to a host pattern such as `{account}.example.com`.
|
|
186
|
-
* Any `{placeholder}` segments are exposed as route parameters once matched.
|
|
187
|
-
*
|
|
188
|
-
* @param pattern
|
|
189
|
-
* @returns
|
|
190
|
-
*/
|
|
191
|
-
domain(pattern) {
|
|
192
|
-
this.domainPattern = pattern;
|
|
193
|
-
this.domainParameters = parseDomainParameters(pattern);
|
|
194
|
-
return this;
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Constrain one or more route parameters with a regular expression. Accepts
|
|
198
|
-
* either `where(name, pattern)` or `where({ name: pattern, ... })`.
|
|
199
|
-
*
|
|
200
|
-
* @param name
|
|
201
|
-
* @param pattern
|
|
202
|
-
* @returns
|
|
203
|
-
*/
|
|
204
|
-
where(name, pattern) {
|
|
205
|
-
if (typeof name === "object") Object.assign(this.constraints, name);
|
|
206
|
-
else if (typeof pattern !== "undefined") this.constraints[name] = pattern;
|
|
207
|
-
return this;
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Constrain the given parameters to numeric values.
|
|
211
|
-
*
|
|
212
|
-
* @param names
|
|
213
|
-
* @returns
|
|
214
|
-
*/
|
|
215
|
-
whereNumber(...names) {
|
|
216
|
-
return this.applyConstraint(names, "[0-9]+");
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Constrain the given parameters to alphabetic values.
|
|
220
|
-
*
|
|
221
|
-
* @param names
|
|
222
|
-
* @returns
|
|
223
|
-
*/
|
|
224
|
-
whereAlpha(...names) {
|
|
225
|
-
return this.applyConstraint(names, "[a-zA-Z]+");
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Constrain the given parameters to alphanumeric values.
|
|
229
|
-
*
|
|
230
|
-
* @param names
|
|
231
|
-
* @returns
|
|
232
|
-
*/
|
|
233
|
-
whereAlphaNumeric(...names) {
|
|
234
|
-
return this.applyConstraint(names, "[a-zA-Z0-9]+");
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Constrain the given parameters to UUID values.
|
|
238
|
-
*
|
|
239
|
-
* @param names
|
|
240
|
-
* @returns
|
|
241
|
-
*/
|
|
242
|
-
whereUuid(...names) {
|
|
243
|
-
return this.applyConstraint(names, "[\\da-fA-F]{8}-[\\da-fA-F]{4}-[\\da-fA-F]{4}-[\\da-fA-F]{4}-[\\da-fA-F]{12}");
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Constrain the given parameters to ULID values.
|
|
247
|
-
*
|
|
248
|
-
* @param names
|
|
249
|
-
* @returns
|
|
250
|
-
*/
|
|
251
|
-
whereUlid(...names) {
|
|
252
|
-
return this.applyConstraint(names, "[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}");
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Constrain a parameter to one of the given values.
|
|
256
|
-
*
|
|
257
|
-
* @param name
|
|
258
|
-
* @param values
|
|
259
|
-
* @returns
|
|
260
|
-
*/
|
|
261
|
-
whereIn(name, values) {
|
|
262
|
-
const escaped = values.map((value) => String(value).replace(/[.*+?^${}()|[\]\\]/g, (match) => `\\${match}`));
|
|
263
|
-
this.constraints[name] = escaped.join("|");
|
|
264
|
-
return this;
|
|
265
|
-
}
|
|
266
|
-
applyConstraint(names, pattern) {
|
|
267
|
-
for (const name of names) this.constraints[name] = pattern;
|
|
268
|
-
return this;
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* Register one or more middleware that will be executed before the route.
|
|
272
|
-
*
|
|
273
|
-
* @param middlewares
|
|
274
|
-
* @returns
|
|
275
|
-
*/
|
|
276
|
-
middleware(middlewares) {
|
|
277
|
-
const normalized = (Array.isArray(middlewares) ? middlewares : [middlewares]).map((middleware) => this.normalizeMiddleware?.(middleware) ?? middleware);
|
|
278
|
-
this.middlewares.push(...normalized);
|
|
279
|
-
this.middlewareCount = this.middlewares.length;
|
|
280
|
-
return this;
|
|
281
|
-
}
|
|
282
|
-
/**
|
|
283
|
-
* Resolve the route's domain pattern into a concrete host using the given
|
|
284
|
-
* parameters.
|
|
285
|
-
*
|
|
286
|
-
* @param params
|
|
287
|
-
* @returns
|
|
288
|
-
*/
|
|
289
|
-
resolveDomainHost(params) {
|
|
290
|
-
return this.domainPattern.replace(/\{([^{}]+)\}/g, (_, raw) => {
|
|
291
|
-
const optional = raw.endsWith("?");
|
|
292
|
-
const name = (optional ? raw.slice(0, -1) : raw).split(":", 2)[0].trim();
|
|
293
|
-
const value = params[name];
|
|
294
|
-
if (typeof value === "undefined" || value === null || value === "") {
|
|
295
|
-
if (optional) return "";
|
|
296
|
-
throw new Error(`Missing required route domain parameter: ${name}`);
|
|
297
|
-
}
|
|
298
|
-
return encodeURIComponent(String(value));
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
/**
|
|
302
|
-
* Get the path generated and accessible by this route
|
|
303
|
-
*
|
|
304
|
-
* @param params
|
|
305
|
-
* @returns
|
|
306
|
-
*/
|
|
307
|
-
toPath(params = {}) {
|
|
308
|
-
const resolved = this.path.replace(/\/?\{([^{}]+)\}/g, (segment, raw) => {
|
|
309
|
-
const optional = raw.endsWith("?");
|
|
310
|
-
const [rawName, rawField] = (optional ? raw.slice(0, -1) : raw).split(":", 2);
|
|
311
|
-
const name = rawName.trim();
|
|
312
|
-
const field = rawField?.trim();
|
|
313
|
-
const value = params[name];
|
|
314
|
-
const resolved = field && value && typeof value === "object" ? value[field] : value;
|
|
315
|
-
if (typeof resolved === "undefined" || resolved === null || resolved === "") {
|
|
316
|
-
if (optional) return "";
|
|
317
|
-
throw new Error(`Missing required route parameter: ${name}`);
|
|
318
|
-
}
|
|
319
|
-
return `${segment.startsWith("/") ? "/" : ""}${encodeURIComponent(String(resolved))}`;
|
|
320
|
-
}) || "/";
|
|
321
|
-
if (!this.domainPattern) return resolved;
|
|
322
|
-
return `//${this.resolveDomainHost(params)}${resolved}`;
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
//#endregion
|
|
326
|
-
//#region ../../node_modules/.pnpm/clear-router@2.9.0_@h3ravel+support@2.2.1_@types+node@25.6.2__express@5.2.1_h3@2.0.1-rc_b9d44c4015b9a26737430ad34be3397f/node_modules/clear-router/dist/core/helpers.mjs
|
|
327
|
-
const wrap = (value) => {
|
|
328
|
-
if (value === null || value === void 0) return [];
|
|
329
|
-
return Array.isArray(value) ? value : [value];
|
|
330
|
-
};
|
|
331
|
-
/**
|
|
332
|
-
*
|
|
333
|
-
* Dynamically imports a file at the given path with full TypeScript support,
|
|
334
|
-
* including `tsconfig.json` path aliases.
|
|
335
|
-
*
|
|
336
|
-
* @param filePath - The path to the file to import.
|
|
337
|
-
* @returns The imported module typed as `T`.
|
|
338
|
-
*
|
|
339
|
-
* @example
|
|
340
|
-
* const config = await importFile<AppConfig>('./config/app.ts')
|
|
341
|
-
*/
|
|
342
|
-
const importFile = async (filePath, userOptions, resolveOptions) => {
|
|
343
|
-
const resolvedPath = resolve(filePath);
|
|
344
|
-
return await createJiti(pathToFileURL(resolvedPath).href, {
|
|
345
|
-
...userOptions,
|
|
346
|
-
interopDefault: false,
|
|
347
|
-
tsconfigPaths: true
|
|
348
|
-
}).import(resolvedPath, resolveOptions);
|
|
349
|
-
};
|
|
350
|
-
//#endregion
|
|
351
|
-
//#region ../../node_modules/.pnpm/clear-router@2.9.0_@h3ravel+support@2.2.1_@types+node@25.6.2__express@5.2.1_h3@2.0.1-rc_b9d44c4015b9a26737430ad34be3397f/node_modules/clear-router/dist/RouteGroup.mjs
|
|
352
|
-
/**
|
|
353
|
-
* @class clear-router RouteGroup
|
|
354
|
-
* @description A route group describes a collection of routes on clear-router
|
|
355
|
-
* @author 3m1n3nc3
|
|
356
|
-
* @repository https://github.com/arkstack-hq/clear-router
|
|
357
|
-
*/
|
|
358
|
-
var RouteGroup = class {
|
|
359
|
-
checks = [];
|
|
360
|
-
conditions = [];
|
|
361
|
-
registration;
|
|
362
|
-
routes = /* @__PURE__ */ new Set();
|
|
363
|
-
unfilteredSources = /* @__PURE__ */ new Set();
|
|
364
|
-
constructor(options) {
|
|
365
|
-
this.options = options;
|
|
366
|
-
this.registration = this.register();
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* Returning a falsy value will stop route group registration
|
|
370
|
-
*
|
|
371
|
-
* @param condition
|
|
372
|
-
* @returns
|
|
373
|
-
*/
|
|
374
|
-
when(condition) {
|
|
375
|
-
this.conditions.push(condition);
|
|
376
|
-
const unfilteredSources = Array.from(this.unfilteredSources);
|
|
377
|
-
if (unfilteredSources.length) this.checks.push(this.registration.then(async () => {
|
|
378
|
-
for (const source of unfilteredSources) if (!await condition(source)) {
|
|
379
|
-
this.rollback();
|
|
380
|
-
break;
|
|
381
|
-
}
|
|
382
|
-
}));
|
|
383
|
-
return this;
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* Register one or more middleware that will be executed before every route in the group.
|
|
387
|
-
*
|
|
388
|
-
* @param middlewares
|
|
389
|
-
* @returns
|
|
390
|
-
*/
|
|
391
|
-
middleware(middlewares) {
|
|
392
|
-
this.checks.push(this.registration.then(() => {
|
|
393
|
-
for (const route of this.routes) route.middleware(middlewares);
|
|
394
|
-
}));
|
|
395
|
-
return this;
|
|
396
|
-
}
|
|
397
|
-
/**
|
|
398
|
-
* Attaches callbacks for the resolution and/or rejection of the RouteGroup.
|
|
399
|
-
*
|
|
400
|
-
* @param onfulfilled
|
|
401
|
-
* @param onrejected
|
|
402
|
-
* @returns
|
|
403
|
-
*/
|
|
404
|
-
then(onfulfilled, onrejected) {
|
|
405
|
-
return Promise.all([this.registration, ...this.checks]).then(() => void 0).then(onfulfilled, onrejected);
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* Register the routes
|
|
409
|
-
*/
|
|
410
|
-
async register() {
|
|
411
|
-
const current = this.options.context.getStore();
|
|
412
|
-
const previousPrefix = current?.prefix ?? this.options.defaultPrefix;
|
|
413
|
-
const previousMiddlewares = current?.groupMiddlewares ?? this.options.defaultMiddlewares;
|
|
414
|
-
const fullPrefix = [previousPrefix, this.options.prefix].filter(Boolean).join("/");
|
|
415
|
-
const nextContext = {
|
|
416
|
-
prefix: this.options.normalizePath(fullPrefix),
|
|
417
|
-
groupMiddlewares: [...previousMiddlewares, ...this.options.middlewares || []],
|
|
418
|
-
domain: this.options.domain ?? current?.domain,
|
|
419
|
-
routeCollectors: [...current?.routeCollectors ?? [], this.routes]
|
|
420
|
-
};
|
|
421
|
-
await this.options.context.run(nextContext, async () => {
|
|
422
|
-
for (const entry of Array.isArray(this.options.source) ? this.options.source : [this.options.source]) {
|
|
423
|
-
if (typeof entry === "function") {
|
|
424
|
-
if (!this.conditions.length) this.unfilteredSources.add(entry);
|
|
425
|
-
else if (!await this.accepts(entry)) continue;
|
|
426
|
-
await Promise.resolve(entry());
|
|
427
|
-
continue;
|
|
428
|
-
}
|
|
429
|
-
const resolved = await this.resolveFiles(entry);
|
|
430
|
-
if (!resolved.directory && !await this.accepts(entry)) continue;
|
|
431
|
-
for (const file of resolved.files) {
|
|
432
|
-
if (resolved.directory && !await this.accepts(file)) continue;
|
|
433
|
-
await importFile(file);
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
});
|
|
437
|
-
}
|
|
438
|
-
/**
|
|
439
|
-
* Rollback the route registration
|
|
440
|
-
*/
|
|
441
|
-
rollback() {
|
|
442
|
-
for (const route of this.routes) this.options.removeRoute(route);
|
|
443
|
-
}
|
|
444
|
-
/**
|
|
445
|
-
* Check whether a callback or path should be registered.
|
|
446
|
-
*
|
|
447
|
-
* @param source
|
|
448
|
-
* @returns
|
|
449
|
-
*/
|
|
450
|
-
async accepts(source) {
|
|
451
|
-
for (const condition of this.conditions) if (!await condition(source)) return false;
|
|
452
|
-
return true;
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
|
-
* Resolve files from the group path
|
|
456
|
-
*
|
|
457
|
-
* @param source
|
|
458
|
-
* @returns
|
|
459
|
-
*/
|
|
460
|
-
async resolveFiles(source) {
|
|
461
|
-
const resolved = isAbsolute(source) ? source : resolve(process.cwd(), source);
|
|
462
|
-
let sourceStat;
|
|
463
|
-
try {
|
|
464
|
-
sourceStat = await stat(resolved);
|
|
465
|
-
} catch {
|
|
466
|
-
throw new Error(`Route group source not found: ${source}`);
|
|
467
|
-
}
|
|
468
|
-
if (sourceStat.isFile()) return {
|
|
469
|
-
directory: false,
|
|
470
|
-
files: [resolved]
|
|
471
|
-
};
|
|
472
|
-
if (!sourceStat.isDirectory()) throw new Error(`Route group source must be a file or directory: ${source}`);
|
|
473
|
-
return {
|
|
474
|
-
directory: true,
|
|
475
|
-
files: await this.readDirectory(resolved)
|
|
476
|
-
};
|
|
477
|
-
}
|
|
478
|
-
/**
|
|
479
|
-
* Read all the files in the configured directory
|
|
480
|
-
*
|
|
481
|
-
* @param directory
|
|
482
|
-
* @returns
|
|
483
|
-
*/
|
|
484
|
-
async readDirectory(directory) {
|
|
485
|
-
const entries = await readdir(directory, { withFileTypes: true });
|
|
486
|
-
const files = [];
|
|
487
|
-
for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
488
|
-
const path = join(directory, entry.name);
|
|
489
|
-
if (entry.isDirectory()) files.push(...await this.readDirectory(path));
|
|
490
|
-
else if (entry.isFile() && /\.(?:[cm]?[jt]s)$/.test(entry.name) && !entry.name.endsWith(".d.ts")) files.push(path);
|
|
491
|
-
}
|
|
492
|
-
return files;
|
|
493
|
-
}
|
|
494
|
-
};
|
|
495
|
-
//#endregion
|
|
496
|
-
//#region ../../node_modules/.pnpm/clear-router@2.9.0_@h3ravel+support@2.2.1_@types+node@25.6.2__express@5.2.1_h3@2.0.1-rc_b9d44c4015b9a26737430ad34be3397f/node_modules/clear-router/dist/RouteRegistrar.mjs
|
|
497
|
-
/**
|
|
498
|
-
* @class clear-router RouteRegistrar
|
|
499
|
-
* @description Fluent builder returned by `Router.domain()` that lets routes be
|
|
500
|
-
* grouped under a shared host pattern (and optionally a prefix/middlewares),
|
|
501
|
-
* mirroring Laravel's route attribute registrar.
|
|
502
|
-
* @author 3m1n3nc3
|
|
503
|
-
* @repository https://github.com/arkstack-hq/clear-router
|
|
504
|
-
*/
|
|
505
|
-
var RouteRegistrar = class {
|
|
506
|
-
attributes;
|
|
507
|
-
constructor(makeGroup, attributes = {}) {
|
|
508
|
-
this.makeGroup = makeGroup;
|
|
509
|
-
this.attributes = {
|
|
510
|
-
domain: attributes.domain,
|
|
511
|
-
prefix: attributes.prefix ?? "",
|
|
512
|
-
middlewares: attributes.middlewares ?? []
|
|
513
|
-
};
|
|
514
|
-
}
|
|
515
|
-
/**
|
|
516
|
-
* Constrain the grouped routes to a host pattern such as `{account}.example.com`.
|
|
517
|
-
*
|
|
518
|
-
* @param pattern
|
|
519
|
-
* @returns
|
|
520
|
-
*/
|
|
521
|
-
domain(pattern) {
|
|
522
|
-
this.attributes.domain = pattern;
|
|
523
|
-
return this;
|
|
524
|
-
}
|
|
525
|
-
/**
|
|
526
|
-
* Prepend a path prefix to the grouped routes.
|
|
527
|
-
*
|
|
528
|
-
* @param prefix
|
|
529
|
-
* @returns
|
|
530
|
-
*/
|
|
531
|
-
prefix(prefix) {
|
|
532
|
-
this.attributes.prefix = prefix;
|
|
533
|
-
return this;
|
|
534
|
-
}
|
|
535
|
-
/**
|
|
536
|
-
* Register one or more middleware shared by the grouped routes.
|
|
537
|
-
*
|
|
538
|
-
* @param middlewares
|
|
539
|
-
* @returns
|
|
540
|
-
*/
|
|
541
|
-
middleware(middlewares) {
|
|
542
|
-
this.attributes.middlewares = [...this.attributes.middlewares, ...Array.isArray(middlewares) ? middlewares : [middlewares]];
|
|
543
|
-
return this;
|
|
544
|
-
}
|
|
545
|
-
group(prefixOrSource, sourceOrMiddlewares, middlewares) {
|
|
546
|
-
let prefix = this.attributes.prefix;
|
|
547
|
-
let source;
|
|
548
|
-
let extraMiddlewares;
|
|
549
|
-
if (typeof prefixOrSource === "string") {
|
|
550
|
-
prefix = prefixOrSource;
|
|
551
|
-
source = sourceOrMiddlewares;
|
|
552
|
-
extraMiddlewares = middlewares;
|
|
553
|
-
} else {
|
|
554
|
-
source = prefixOrSource;
|
|
555
|
-
extraMiddlewares = sourceOrMiddlewares;
|
|
556
|
-
}
|
|
557
|
-
return this.makeGroup(prefix, source, [...this.attributes.middlewares, ...extraMiddlewares ?? []], { domain: this.attributes.domain });
|
|
558
|
-
}
|
|
559
|
-
};
|
|
560
|
-
//#endregion
|
|
561
|
-
//#region ../../node_modules/.pnpm/clear-router@2.9.0_@h3ravel+support@2.2.1_@types+node@25.6.2__express@5.2.1_h3@2.0.1-rc_b9d44c4015b9a26737430ad34be3397f/node_modules/clear-router/dist/core/Request.mjs
|
|
562
|
-
var Request = class extends ClearRequest {
|
|
563
|
-
original;
|
|
564
|
-
method = "GET";
|
|
565
|
-
path = "/";
|
|
566
|
-
url = "/";
|
|
567
|
-
headers = {};
|
|
568
|
-
constructor(init) {
|
|
569
|
-
super(init);
|
|
570
|
-
Object.assign(this, init);
|
|
571
|
-
}
|
|
572
|
-
getBody() {
|
|
573
|
-
return this.body ?? {};
|
|
574
|
-
}
|
|
575
|
-
header(name) {
|
|
576
|
-
if (typeof this.headers.get === "function") return this.headers.get(name) || "";
|
|
577
|
-
const headers = this.headers;
|
|
578
|
-
const value = headers[name] ?? headers[name.toLowerCase()];
|
|
579
|
-
return Array.isArray(value) ? String(value[0] ?? "") : String(value ?? "");
|
|
580
|
-
}
|
|
581
|
-
param(name) {
|
|
582
|
-
return this.params?.[name];
|
|
583
|
-
}
|
|
584
|
-
input(name) {
|
|
585
|
-
return this.body?.[name] ?? this.query?.[name] ?? this.params?.[name];
|
|
586
|
-
}
|
|
587
|
-
is(method) {
|
|
588
|
-
return this.method.toLowerCase() === String(method).toLowerCase();
|
|
589
|
-
}
|
|
590
|
-
};
|
|
591
|
-
//#endregion
|
|
592
|
-
//#region ../../node_modules/.pnpm/clear-router@2.9.0_@h3ravel+support@2.2.1_@types+node@25.6.2__express@5.2.1_h3@2.0.1-rc_b9d44c4015b9a26737430ad34be3397f/node_modules/clear-router/dist/core/Response.mjs
|
|
593
|
-
var Response = class {
|
|
594
|
-
body;
|
|
595
|
-
headers = new Headers();
|
|
596
|
-
sent = false;
|
|
597
|
-
statusCode = 200;
|
|
598
|
-
statusText = "OK";
|
|
599
|
-
constructor(init) {
|
|
600
|
-
const { status: _, ...rest } = init ?? {};
|
|
601
|
-
Object.assign(this, rest);
|
|
602
|
-
if (init?.headers && !(init.headers instanceof Headers)) this.headers = new Headers(init.headers);
|
|
603
|
-
if (init?.status && typeof init.status === "number") this.statusCode = init?.status;
|
|
604
|
-
}
|
|
605
|
-
status(code) {
|
|
606
|
-
this.statusCode = code;
|
|
607
|
-
return this;
|
|
608
|
-
}
|
|
609
|
-
setStatusText(text) {
|
|
610
|
-
this.statusText = text;
|
|
611
|
-
return this;
|
|
612
|
-
}
|
|
613
|
-
code(code) {
|
|
614
|
-
return this.status(code);
|
|
615
|
-
}
|
|
616
|
-
setHeader(name, value) {
|
|
617
|
-
this.headers.set(name, value);
|
|
618
|
-
return this;
|
|
619
|
-
}
|
|
620
|
-
header(name, value) {
|
|
621
|
-
return this.setHeader(name, value);
|
|
622
|
-
}
|
|
623
|
-
set(name, value) {
|
|
624
|
-
return this.setHeader(name, value);
|
|
625
|
-
}
|
|
626
|
-
type(contentType) {
|
|
627
|
-
return this.setHeader("Content-Type", contentType);
|
|
628
|
-
}
|
|
629
|
-
send(body) {
|
|
630
|
-
this.body = body;
|
|
631
|
-
this.sent = true;
|
|
632
|
-
return this;
|
|
633
|
-
}
|
|
634
|
-
json(body) {
|
|
635
|
-
return this.type("application/json; charset=utf-8").send(body);
|
|
636
|
-
}
|
|
637
|
-
html(body) {
|
|
638
|
-
return this.type("text/html; charset=utf-8").send(body);
|
|
639
|
-
}
|
|
640
|
-
text(body) {
|
|
641
|
-
return this.type("text/plain; charset=utf-8").send(body);
|
|
642
|
-
}
|
|
643
|
-
noContent() {
|
|
644
|
-
return this.status(204).send(null);
|
|
645
|
-
}
|
|
646
|
-
};
|
|
647
|
-
//#endregion
|
|
648
|
-
//#region ../../node_modules/.pnpm/clear-router@2.9.0_@h3ravel+support@2.2.1_@types+node@25.6.2__express@5.2.1_h3@2.0.1-rc_b9d44c4015b9a26737430ad34be3397f/node_modules/clear-router/dist/core/bindings.mjs
|
|
649
|
-
const metadataKey = Symbol.for("clear-router:binding-metadata");
|
|
650
|
-
const bindings = /* @__PURE__ */ new WeakMap();
|
|
651
|
-
var Container = class {
|
|
652
|
-
static registry = /* @__PURE__ */ new Map();
|
|
653
|
-
static bind(token, value) {
|
|
654
|
-
this.registry.set(token, value);
|
|
655
|
-
}
|
|
656
|
-
static unbind(token) {
|
|
657
|
-
this.registry.delete(token);
|
|
658
|
-
}
|
|
659
|
-
static clear() {
|
|
660
|
-
this.registry.clear();
|
|
661
|
-
}
|
|
662
|
-
static has(token) {
|
|
663
|
-
return this.registry.has(token) || Boolean(this.findEquivalentToken(token));
|
|
664
|
-
}
|
|
665
|
-
static bindings() {
|
|
666
|
-
return Object.fromEntries(this.registry.entries());
|
|
667
|
-
}
|
|
668
|
-
static async resolve(token, ctx, autoDiscover = false) {
|
|
669
|
-
if (token === Request) return ctx.clearRequest;
|
|
670
|
-
if (token === Response) return ctx.clearResponse;
|
|
671
|
-
const binding = this.getBinding(token);
|
|
672
|
-
if (binding) return this.resolveBinding(binding, ctx, autoDiscover);
|
|
673
|
-
if (autoDiscover && typeof token === "function") return new token();
|
|
674
|
-
}
|
|
675
|
-
static getBinding(token) {
|
|
676
|
-
if (this.registry.has(token)) return this.registry.get(token);
|
|
677
|
-
const equivalent = this.findEquivalentToken(token);
|
|
678
|
-
return equivalent ? this.registry.get(equivalent) : void 0;
|
|
679
|
-
}
|
|
680
|
-
static findEquivalentToken(token) {
|
|
681
|
-
const name = token.name;
|
|
682
|
-
if (!name) return;
|
|
683
|
-
const tokenParent = Object.getPrototypeOf(token);
|
|
684
|
-
const tokenProps = this.getComparableStaticProps(token);
|
|
685
|
-
for (const registered of this.registry.keys()) {
|
|
686
|
-
if (registered === token) continue;
|
|
687
|
-
if (registered.name !== name) continue;
|
|
688
|
-
const registeredParent = Object.getPrototypeOf(registered);
|
|
689
|
-
if (tokenParent && registeredParent && tokenParent.name !== registeredParent.name) continue;
|
|
690
|
-
const registeredProps = this.getComparableStaticProps(registered);
|
|
691
|
-
if (!this.staticPropsMatch(token, registered, tokenProps, registeredProps)) continue;
|
|
692
|
-
return registered;
|
|
693
|
-
}
|
|
694
|
-
}
|
|
695
|
-
static getComparableStaticProps(token) {
|
|
696
|
-
return Object.getOwnPropertyNames(token).filter((prop) => {
|
|
697
|
-
return ![
|
|
698
|
-
"length",
|
|
699
|
-
"name",
|
|
700
|
-
"prototype",
|
|
701
|
-
"arguments",
|
|
702
|
-
"caller"
|
|
703
|
-
].includes(prop);
|
|
704
|
-
});
|
|
705
|
-
}
|
|
706
|
-
static staticPropsMatch(token, registered, tokenProps, registeredProps) {
|
|
707
|
-
if (tokenProps.length !== registeredProps.length) return false;
|
|
708
|
-
for (const prop of tokenProps) {
|
|
709
|
-
if (!registeredProps.includes(prop)) return false;
|
|
710
|
-
if (Reflect.get(token, prop) !== Reflect.get(registered, prop)) return false;
|
|
711
|
-
}
|
|
712
|
-
return true;
|
|
713
|
-
}
|
|
714
|
-
static async resolveBinding(binding, ctx, autoDiscover) {
|
|
715
|
-
if (!binding) return void 0;
|
|
716
|
-
if (typeof binding !== "function") return binding;
|
|
717
|
-
if (isClass(binding)) return new binding();
|
|
718
|
-
const resolved = await binding(ctx);
|
|
719
|
-
if (typeof resolved === "function" && autoDiscover && isClass(resolved)) return new resolved();
|
|
720
|
-
return resolved;
|
|
721
|
-
}
|
|
722
|
-
};
|
|
723
|
-
function getStandardMetadata(metadata, propertyKey) {
|
|
724
|
-
const store = metadata && metadata[metadataKey];
|
|
725
|
-
if (!store) return void 0;
|
|
726
|
-
return propertyKey ? store[propertyKey] : void 0;
|
|
727
|
-
}
|
|
728
|
-
function getBindingMetadataFromTargets(targets) {
|
|
729
|
-
for (const { target, propertyKey } of targets) {
|
|
730
|
-
if (!target) continue;
|
|
731
|
-
const metadata = getBindingMetadata(target, propertyKey);
|
|
732
|
-
if (metadata) return metadata;
|
|
733
|
-
const standardMetadata = getStandardMetadata(target[Symbol.metadata], propertyKey);
|
|
734
|
-
if (standardMetadata) return standardMetadata;
|
|
735
|
-
}
|
|
736
|
-
}
|
|
737
|
-
function getBindingMetadata(target, propertyKey) {
|
|
738
|
-
if (propertyKey) return bindings.get(target)?.get(propertyKey);
|
|
739
|
-
return bindings.get(target)?.get("__route_handler__");
|
|
740
|
-
}
|
|
741
|
-
function getDesignParamTypes(target, propertyKey) {
|
|
742
|
-
return Reflect.getMetadata?.("design:paramtypes", target, propertyKey) ?? [];
|
|
743
|
-
}
|
|
744
|
-
function isClass(value) {
|
|
745
|
-
return typeof value === "function" && /^class\s/.test(Function.prototype.toString.call(value));
|
|
746
|
-
}
|
|
747
|
-
//#endregion
|
|
748
|
-
//#region ../../node_modules/.pnpm/clear-router@2.9.0_@h3ravel+support@2.2.1_@types+node@25.6.2__express@5.2.1_h3@2.0.1-rc_b9d44c4015b9a26737430ad34be3397f/node_modules/clear-router/dist/ResourceRouteSelection.mjs
|
|
749
|
-
var ResourceRouteSelection = class {
|
|
750
|
-
constructor(routes) {
|
|
751
|
-
this.routes = routes;
|
|
752
|
-
}
|
|
753
|
-
/**
|
|
754
|
-
* Register one or more middleware that will be executed before the route.
|
|
755
|
-
*
|
|
756
|
-
* @param middlewares
|
|
757
|
-
* @returns
|
|
758
|
-
*/
|
|
759
|
-
middleware(middlewares) {
|
|
760
|
-
for (const route of this.routes) route.middleware(middlewares);
|
|
761
|
-
return this;
|
|
762
|
-
}
|
|
763
|
-
all() {
|
|
764
|
-
return this.routes;
|
|
765
|
-
}
|
|
766
|
-
first() {
|
|
767
|
-
return this.routes[0];
|
|
768
|
-
}
|
|
769
|
-
};
|
|
770
|
-
//#endregion
|
|
771
|
-
//#region ../../node_modules/.pnpm/clear-router@2.9.0_@h3ravel+support@2.2.1_@types+node@25.6.2__express@5.2.1_h3@2.0.1-rc_b9d44c4015b9a26737430ad34be3397f/node_modules/clear-router/dist/ResourceRoutes.mjs
|
|
772
|
-
/**
|
|
773
|
-
* @class clear-router ResourceRoutes
|
|
774
|
-
* @description A ResourceRoutes creates a collection of resourceful routes in a single call
|
|
775
|
-
* @author 3m1n3nc3
|
|
776
|
-
* @repository https://github.com/arkstack-hq/clear-router
|
|
777
|
-
*/
|
|
778
|
-
var ResourceRoutes = class ResourceRoutes {
|
|
779
|
-
static actions = {
|
|
780
|
-
index: {
|
|
781
|
-
method: "get",
|
|
782
|
-
path: "/"
|
|
783
|
-
},
|
|
784
|
-
show: {
|
|
785
|
-
method: "get",
|
|
786
|
-
path: "/:{param}"
|
|
787
|
-
},
|
|
788
|
-
create: {
|
|
789
|
-
method: "post",
|
|
790
|
-
path: "/"
|
|
791
|
-
},
|
|
792
|
-
update: {
|
|
793
|
-
method: "put",
|
|
794
|
-
path: "/:{param}"
|
|
795
|
-
},
|
|
796
|
-
destroy: {
|
|
797
|
-
method: "delete",
|
|
798
|
-
path: "/:{param}"
|
|
799
|
-
}
|
|
800
|
-
};
|
|
801
|
-
routes = {};
|
|
802
|
-
options;
|
|
803
|
-
chainedMiddlewares = [];
|
|
804
|
-
constructor(basePath, controller, paramName, options, registerRoute, removeRoute) {
|
|
805
|
-
this.basePath = basePath;
|
|
806
|
-
this.controller = controller;
|
|
807
|
-
this.paramName = paramName;
|
|
808
|
-
this.registerRoute = registerRoute;
|
|
809
|
-
this.removeRoute = removeRoute;
|
|
810
|
-
this.options = options ?? {};
|
|
811
|
-
}
|
|
812
|
-
register() {
|
|
813
|
-
this.clear();
|
|
814
|
-
const preController = typeof this.controller === "function" ? new this.controller() : this.controller;
|
|
815
|
-
for (const action of this.selectedActions()) {
|
|
816
|
-
if (typeof preController[action] !== "function") continue;
|
|
817
|
-
const definition = this.definitionFor(action);
|
|
818
|
-
const route = this.registerRoute({
|
|
819
|
-
action,
|
|
820
|
-
method: definition.method,
|
|
821
|
-
path: `${this.basePath}${definition.path}`,
|
|
822
|
-
handler: [this.controller, action],
|
|
823
|
-
middlewares: this.resolveActionMiddlewares(action),
|
|
824
|
-
name: `${this.nameFor(definition.path)}.${action.toLowerCase()}`
|
|
825
|
-
});
|
|
826
|
-
this.routes[action] = route;
|
|
827
|
-
}
|
|
828
|
-
for (const middlewares of this.chainedMiddlewares) this.middleware(middlewares, false);
|
|
829
|
-
return this;
|
|
830
|
-
}
|
|
831
|
-
/**
|
|
832
|
-
* Only register routes for the provided actions.
|
|
833
|
-
*
|
|
834
|
-
* @param action
|
|
835
|
-
* @param actions
|
|
836
|
-
* @returns
|
|
837
|
-
*/
|
|
838
|
-
only(action, ...actions) {
|
|
839
|
-
this.options.only = Array.from(new Set(wrap(action).concat(actions)));
|
|
840
|
-
return this.register();
|
|
841
|
-
}
|
|
842
|
-
/**
|
|
843
|
-
* Register all resource routes except the provided actions.
|
|
844
|
-
*
|
|
845
|
-
* @param action
|
|
846
|
-
* @param actions
|
|
847
|
-
* @returns
|
|
848
|
-
*/
|
|
849
|
-
except(action, ...actions) {
|
|
850
|
-
this.options.except = Array.from(new Set(wrap(action).concat(actions)));
|
|
851
|
-
return this.register();
|
|
852
|
-
}
|
|
853
|
-
/**
|
|
854
|
-
* Register one or more middleware that will be executed before the route.
|
|
855
|
-
*
|
|
856
|
-
* @param middlewares
|
|
857
|
-
* @param remember
|
|
858
|
-
* @returns
|
|
859
|
-
*/
|
|
860
|
-
middleware(middlewares, remember = true) {
|
|
861
|
-
if (remember) this.chainedMiddlewares.push(middlewares);
|
|
862
|
-
for (const route of Object.values(this.routes)) route?.middleware(middlewares);
|
|
863
|
-
return this;
|
|
864
|
-
}
|
|
865
|
-
action(action) {
|
|
866
|
-
return this.routes[action];
|
|
867
|
-
}
|
|
868
|
-
index() {
|
|
869
|
-
return this.routes.index;
|
|
870
|
-
}
|
|
871
|
-
show() {
|
|
872
|
-
return this.routes.show;
|
|
873
|
-
}
|
|
874
|
-
create() {
|
|
875
|
-
return this.routes.create;
|
|
876
|
-
}
|
|
877
|
-
update() {
|
|
878
|
-
return this.routes.update;
|
|
879
|
-
}
|
|
880
|
-
destroy() {
|
|
881
|
-
return this.routes.destroy;
|
|
882
|
-
}
|
|
883
|
-
get() {
|
|
884
|
-
return this.byMethod("get");
|
|
885
|
-
}
|
|
886
|
-
post() {
|
|
887
|
-
return this.byMethod("post");
|
|
888
|
-
}
|
|
889
|
-
put() {
|
|
890
|
-
return this.byMethod("put");
|
|
891
|
-
}
|
|
892
|
-
delete() {
|
|
893
|
-
return this.byMethod("delete");
|
|
894
|
-
}
|
|
895
|
-
selectedActions() {
|
|
896
|
-
const actions = this.options.only?.length ? this.options.only : Object.keys(ResourceRoutes.actions);
|
|
897
|
-
const except = new Set(this.options.except ?? []);
|
|
898
|
-
return actions.filter((action) => !except.has(action));
|
|
899
|
-
}
|
|
900
|
-
definitionFor(action) {
|
|
901
|
-
const definition = ResourceRoutes.actions[action];
|
|
902
|
-
return {
|
|
903
|
-
method: definition.method,
|
|
904
|
-
path: definition.path.replace("{param}", this.paramName)
|
|
905
|
-
};
|
|
906
|
-
}
|
|
907
|
-
resolveActionMiddlewares(action) {
|
|
908
|
-
const middlewares = this.isActionMiddlewareMap(this.options.middlewares) ? this.options.middlewares[action] : this.options.middlewares;
|
|
909
|
-
return Array.isArray(middlewares) ? middlewares : middlewares ? [middlewares] : void 0;
|
|
910
|
-
}
|
|
911
|
-
isActionMiddlewareMap(middlewares) {
|
|
912
|
-
if (!middlewares || Array.isArray(middlewares) || typeof middlewares !== "object") return false;
|
|
913
|
-
return Object.keys(ResourceRoutes.actions).some((action) => action in middlewares);
|
|
914
|
-
}
|
|
915
|
-
nameFor(path) {
|
|
916
|
-
return `${this.basePath}${path}`.replace(/\/:[^/]+|\/\{[^}]+\}/g, "").replace(/\{(\w+):[^}]+\}/g, "$1").replace(/\/|:|[{}]/g, ".").replace(/\.{2,}/g, ".").replace(/^\.|\.$/g, "");
|
|
917
|
-
}
|
|
918
|
-
byMethod(method) {
|
|
919
|
-
return new ResourceRouteSelection(Object.values(this.routes).filter((route) => Boolean(route?.methods.includes(method))));
|
|
920
|
-
}
|
|
921
|
-
clear() {
|
|
922
|
-
for (const route of Object.values(this.routes)) if (route) this.removeRoute(route);
|
|
923
|
-
for (const key of Object.keys(this.routes)) delete this.routes[key];
|
|
924
|
-
}
|
|
925
|
-
};
|
|
926
|
-
//#endregion
|
|
927
|
-
//#region ../../node_modules/.pnpm/clear-router@2.9.0_@h3ravel+support@2.2.1_@types+node@25.6.2__express@5.2.1_h3@2.0.1-rc_b9d44c4015b9a26737430ad34be3397f/node_modules/clear-router/dist/core/CoreRouter.mjs
|
|
928
|
-
/**
|
|
929
|
-
* @class clear-router CoreRouter
|
|
930
|
-
* @description Core routing logic for clear-router, shared between all supported adapters (Express.js, H3, etc.)
|
|
931
|
-
* @author 3m1n3nc3
|
|
932
|
-
* @repository https://github.com/arkstack-hq/clear-router
|
|
933
|
-
*/
|
|
934
|
-
var CoreRouter = class {
|
|
935
|
-
static routerStateNamespace = "clear-router:core";
|
|
936
|
-
static stateStoreKey = Symbol.for("clear-router:router-state");
|
|
937
|
-
static stateBoundKey = Symbol.for("clear-router:router-state-bound");
|
|
938
|
-
static defaultConfigKey = Symbol.for("clear-router:default-config");
|
|
939
|
-
static pluginStoreKey = Symbol.for("clear-router:plugins");
|
|
940
|
-
static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
|
|
941
|
-
static pluginHttpCtxResolversKey = Symbol.for("clear-router:plugin-http-ctx");
|
|
942
|
-
static pluginArgumentResolversKey = Symbol.for("clear-router:plugin-argument-resolvers");
|
|
943
|
-
static requestProvider;
|
|
944
|
-
static responseProvider;
|
|
945
|
-
static domainMatcherCache = /* @__PURE__ */ new Map();
|
|
946
|
-
static constraintRegexCache = /* @__PURE__ */ new Map();
|
|
947
|
-
static routePatterns = /* @__PURE__ */ new Map();
|
|
948
|
-
static config = {
|
|
949
|
-
inferParamName: false,
|
|
950
|
-
methodOverride: {
|
|
951
|
-
enabled: true,
|
|
952
|
-
bodyKeys: ["_method"],
|
|
953
|
-
headerKeys: ["x-http-method"]
|
|
954
|
-
},
|
|
955
|
-
container: {
|
|
956
|
-
enabled: false,
|
|
957
|
-
autoDiscover: false
|
|
958
|
-
}
|
|
959
|
-
};
|
|
960
|
-
static groupContext = new AsyncLocalStorage();
|
|
961
|
-
static pluginRequestContext = new AsyncLocalStorage();
|
|
962
|
-
static routes = /* @__PURE__ */ new Set([]);
|
|
963
|
-
static routesByPathMethod = /* @__PURE__ */ new Map();
|
|
964
|
-
static routesByMethod = /* @__PURE__ */ new Map();
|
|
965
|
-
static routesByName = /* @__PURE__ */ new Map();
|
|
966
|
-
static prefix = "";
|
|
967
|
-
static groupMiddlewares = [];
|
|
968
|
-
static globalMiddlewares = [];
|
|
969
|
-
/**
|
|
970
|
-
* Resolve middlewares before assigning to adapter
|
|
971
|
-
*
|
|
972
|
-
* @param middleware
|
|
973
|
-
* @returns
|
|
974
|
-
*/
|
|
975
|
-
static resolveMiddleware(middleware) {
|
|
976
|
-
if (!middleware || typeof middleware === "function" && !isClass(middleware)) return middleware;
|
|
977
|
-
const instance = isClass(middleware) ? new middleware() : middleware;
|
|
978
|
-
if (instance && typeof instance.handle === "function") return instance.handle.bind(instance);
|
|
979
|
-
return middleware;
|
|
980
|
-
}
|
|
981
|
-
static resolveMiddlewares(middlewares = []) {
|
|
982
|
-
return middlewares.map((middleware) => this.resolveMiddleware(middleware));
|
|
983
|
-
}
|
|
984
|
-
static routeSpecificity(route) {
|
|
985
|
-
const path = route.registrationPaths.slice().sort((left, right) => right.length - left.length)[0] ?? route.path;
|
|
986
|
-
const segments = this.normalizePath(path).split("/").filter(Boolean);
|
|
987
|
-
return [
|
|
988
|
-
segments.filter((segment) => !segment.startsWith(":")).length,
|
|
989
|
-
segments.length,
|
|
990
|
-
path.length
|
|
991
|
-
];
|
|
992
|
-
}
|
|
993
|
-
static orderedRoutes() {
|
|
994
|
-
return Array.from(this.routes).sort((left, right) => {
|
|
995
|
-
const leftScore = this.routeSpecificity(left);
|
|
996
|
-
const rightScore = this.routeSpecificity(right);
|
|
997
|
-
for (let index = 0; index < leftScore.length; index++) {
|
|
998
|
-
const difference = rightScore[index] - leftScore[index];
|
|
999
|
-
if (difference !== 0) return difference;
|
|
1000
|
-
}
|
|
1001
|
-
return 0;
|
|
1002
|
-
});
|
|
1003
|
-
}
|
|
1004
|
-
static removeRouteMethod(route, method, path) {
|
|
1005
|
-
route.methods = route.methods.filter((existingMethod) => existingMethod !== method);
|
|
1006
|
-
this.routesByPathMethod.delete(`${method.toUpperCase()} ${path}`);
|
|
1007
|
-
const methodKey = method.toUpperCase();
|
|
1008
|
-
this.routesByMethod.set(methodKey, (this.routesByMethod.get(methodKey) ?? []).filter((existingRoute) => existingRoute !== route));
|
|
1009
|
-
if (!route.methods.some((existingMethod) => existingMethod !== "options")) {
|
|
1010
|
-
this.routes.delete(route);
|
|
1011
|
-
if (route.routeName && this.routesByName.get(route.routeName) === route) this.routesByName.delete(route.routeName);
|
|
1012
|
-
}
|
|
1013
|
-
}
|
|
1014
|
-
static removeRoute(route) {
|
|
1015
|
-
this.routes.delete(route);
|
|
1016
|
-
if (route.routeName && this.routesByName.get(route.routeName) === route) this.routesByName.delete(route.routeName);
|
|
1017
|
-
for (const method of route.methods) {
|
|
1018
|
-
const methodKey = method.toUpperCase();
|
|
1019
|
-
this.routesByPathMethod.delete(`${methodKey} ${route.path}`);
|
|
1020
|
-
this.routesByMethod.set(methodKey, (this.routesByMethod.get(methodKey) ?? []).filter((existingRoute) => existingRoute !== route));
|
|
1021
|
-
}
|
|
1022
|
-
}
|
|
1023
|
-
/**
|
|
1024
|
-
* Resets the router to it's default state
|
|
1025
|
-
*/
|
|
1026
|
-
static reset() {
|
|
1027
|
-
this.routes.clear();
|
|
1028
|
-
this.prefix = "";
|
|
1029
|
-
this.groupMiddlewares = [];
|
|
1030
|
-
this.globalMiddlewares = [];
|
|
1031
|
-
this.routesByPathMethod.clear();
|
|
1032
|
-
this.routesByMethod.clear();
|
|
1033
|
-
this.routesByName.clear();
|
|
1034
|
-
this.routePatterns.clear();
|
|
1035
|
-
return this;
|
|
1036
|
-
}
|
|
1037
|
-
static createBaseConfig() {
|
|
1038
|
-
return {
|
|
1039
|
-
inferParamName: false,
|
|
1040
|
-
methodOverride: {
|
|
1041
|
-
enabled: true,
|
|
1042
|
-
bodyKeys: ["_method"],
|
|
1043
|
-
headerKeys: ["x-http-method"]
|
|
1044
|
-
},
|
|
1045
|
-
container: {
|
|
1046
|
-
enabled: false,
|
|
1047
|
-
autoDiscover: false
|
|
1048
|
-
}
|
|
1049
|
-
};
|
|
1050
|
-
}
|
|
1051
|
-
static mergeConfig(target, source) {
|
|
1052
|
-
if (!source) return target;
|
|
1053
|
-
if (source.methodOverride) target.methodOverride = {
|
|
1054
|
-
...target.methodOverride || {},
|
|
1055
|
-
...source.methodOverride
|
|
1056
|
-
};
|
|
1057
|
-
if (source.container) target.container = {
|
|
1058
|
-
...target.container || {},
|
|
1059
|
-
...source.container
|
|
1060
|
-
};
|
|
1061
|
-
return target;
|
|
1062
|
-
}
|
|
1063
|
-
static getDefaultConfig() {
|
|
1064
|
-
const g = globalThis;
|
|
1065
|
-
if (!g[this.defaultConfigKey]) g[this.defaultConfigKey] = this.createBaseConfig();
|
|
1066
|
-
return {
|
|
1067
|
-
inferParamName: g[this.defaultConfigKey].inferParamName,
|
|
1068
|
-
methodOverride: { ...g[this.defaultConfigKey].methodOverride },
|
|
1069
|
-
container: { ...g[this.defaultConfigKey].container }
|
|
1070
|
-
};
|
|
1071
|
-
}
|
|
1072
|
-
static resolveStateNamespace() {
|
|
1073
|
-
return String(this.routerStateNamespace || this.name || "clear-router:core");
|
|
1074
|
-
}
|
|
1075
|
-
static getStateStore() {
|
|
1076
|
-
const g = globalThis;
|
|
1077
|
-
if (!g[this.stateStoreKey]) g[this.stateStoreKey] = Object.create(null);
|
|
1078
|
-
return g[this.stateStoreKey];
|
|
1079
|
-
}
|
|
1080
|
-
static getPluginStore() {
|
|
1081
|
-
const g = globalThis;
|
|
1082
|
-
if (!g[this.pluginStoreKey]) g[this.pluginStoreKey] = /* @__PURE__ */ new Set();
|
|
1083
|
-
return g[this.pluginStoreKey];
|
|
1084
|
-
}
|
|
1085
|
-
static getPluginPendingStore() {
|
|
1086
|
-
const g = globalThis;
|
|
1087
|
-
if (!g[this.pluginPendingKey]) g[this.pluginPendingKey] = /* @__PURE__ */ new Set();
|
|
1088
|
-
return g[this.pluginPendingKey];
|
|
1089
|
-
}
|
|
1090
|
-
static getPluginArgumentResolvers() {
|
|
1091
|
-
const g = globalThis;
|
|
1092
|
-
if (!g[this.pluginArgumentResolversKey]) g[this.pluginArgumentResolversKey] = /* @__PURE__ */ new Set();
|
|
1093
|
-
return g[this.pluginArgumentResolversKey];
|
|
1094
|
-
}
|
|
1095
|
-
static getPluginHttpCtxResolvers() {
|
|
1096
|
-
const g = globalThis;
|
|
1097
|
-
if (!g[this.pluginHttpCtxResolversKey]) g[this.pluginHttpCtxResolversKey] = /* @__PURE__ */ new Set();
|
|
1098
|
-
return g[this.pluginHttpCtxResolversKey];
|
|
1099
|
-
}
|
|
1100
|
-
static createDefaultState() {
|
|
1101
|
-
return {
|
|
1102
|
-
config: this.getDefaultConfig(),
|
|
1103
|
-
groupContext: new AsyncLocalStorage(),
|
|
1104
|
-
routes: /* @__PURE__ */ new Set([]),
|
|
1105
|
-
routesByPathMethod: /* @__PURE__ */ new Map(),
|
|
1106
|
-
routesByMethod: /* @__PURE__ */ new Map(),
|
|
1107
|
-
routesByName: /* @__PURE__ */ new Map(),
|
|
1108
|
-
prefix: "",
|
|
1109
|
-
groupMiddlewares: [],
|
|
1110
|
-
globalMiddlewares: []
|
|
1111
|
-
};
|
|
1112
|
-
}
|
|
1113
|
-
static bindStateAccessors() {
|
|
1114
|
-
if (Object.prototype.hasOwnProperty.call(this, this.stateBoundKey)) return;
|
|
1115
|
-
const namespace = this.resolveStateNamespace();
|
|
1116
|
-
const store = this.getStateStore();
|
|
1117
|
-
if (!store[namespace]) store[namespace] = this.createDefaultState();
|
|
1118
|
-
for (const key of [
|
|
1119
|
-
"config",
|
|
1120
|
-
"groupContext",
|
|
1121
|
-
"routes",
|
|
1122
|
-
"routesByPathMethod",
|
|
1123
|
-
"routesByMethod",
|
|
1124
|
-
"routesByName",
|
|
1125
|
-
"prefix",
|
|
1126
|
-
"groupMiddlewares",
|
|
1127
|
-
"globalMiddlewares"
|
|
1128
|
-
]) Object.defineProperty(this, key, {
|
|
1129
|
-
get() {
|
|
1130
|
-
const ns = this.resolveStateNamespace();
|
|
1131
|
-
const registry = this.getStateStore();
|
|
1132
|
-
if (!registry[ns]) registry[ns] = this.createDefaultState();
|
|
1133
|
-
return registry[ns][key];
|
|
1134
|
-
},
|
|
1135
|
-
set(value) {
|
|
1136
|
-
const ns = this.resolveStateNamespace();
|
|
1137
|
-
const registry = this.getStateStore();
|
|
1138
|
-
if (!registry[ns]) registry[ns] = this.createDefaultState();
|
|
1139
|
-
registry[ns][key] = value;
|
|
1140
|
-
},
|
|
1141
|
-
configurable: true,
|
|
1142
|
-
enumerable: true
|
|
1143
|
-
});
|
|
1144
|
-
Object.defineProperty(this, this.stateBoundKey, {
|
|
1145
|
-
value: true,
|
|
1146
|
-
configurable: false,
|
|
1147
|
-
enumerable: false,
|
|
1148
|
-
writable: false
|
|
1149
|
-
});
|
|
1150
|
-
}
|
|
1151
|
-
static createDefaultOptionsHandler() {
|
|
1152
|
-
return (ctx) => {
|
|
1153
|
-
const allow = "GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD";
|
|
1154
|
-
if (ctx?.header && ctx?.status && ctx?.body) {
|
|
1155
|
-
ctx.header("Allow", allow);
|
|
1156
|
-
ctx.status(204);
|
|
1157
|
-
return ctx.body(null);
|
|
1158
|
-
}
|
|
1159
|
-
if (ctx?.res?.headers?.set) {
|
|
1160
|
-
ctx.res.headers.set("Allow", allow);
|
|
1161
|
-
ctx.res.status = 204;
|
|
1162
|
-
return;
|
|
1163
|
-
}
|
|
1164
|
-
if (ctx?.res?.set) {
|
|
1165
|
-
ctx.res.set("Allow", allow);
|
|
1166
|
-
ctx.res.sendStatus(204);
|
|
1167
|
-
return;
|
|
1168
|
-
}
|
|
1169
|
-
if (ctx?.reply?.header) {
|
|
1170
|
-
ctx.reply.header("Allow", allow);
|
|
1171
|
-
ctx.reply.code(204).send();
|
|
1172
|
-
return;
|
|
1173
|
-
}
|
|
1174
|
-
if (ctx?.set && "status" in ctx) {
|
|
1175
|
-
ctx.set("Allow", allow);
|
|
1176
|
-
ctx.status = 204;
|
|
1177
|
-
ctx.body = null;
|
|
1178
|
-
}
|
|
1179
|
-
};
|
|
1180
|
-
}
|
|
1181
|
-
/**
|
|
1182
|
-
* Default configuration used for everytime the router is reset
|
|
1183
|
-
*
|
|
1184
|
-
* @param options
|
|
1185
|
-
*/
|
|
1186
|
-
static configureDefaults(options) {
|
|
1187
|
-
const g = globalThis;
|
|
1188
|
-
const defaults = this.mergeConfig(g[this.defaultConfigKey] || this.createBaseConfig(), options);
|
|
1189
|
-
g[this.defaultConfigKey] = defaults;
|
|
1190
|
-
const store = this.getStateStore();
|
|
1191
|
-
for (const state of Object.values(store)) state.config = this.mergeConfig(state.config || this.createBaseConfig(), options);
|
|
1192
|
-
}
|
|
1193
|
-
/**
|
|
1194
|
-
* Use a registered plugin
|
|
1195
|
-
*
|
|
1196
|
-
* @param this
|
|
1197
|
-
* @param plugin
|
|
1198
|
-
* @param options
|
|
1199
|
-
* @returns
|
|
1200
|
-
*/
|
|
1201
|
-
static async use(plugin, options) {
|
|
1202
|
-
const name = typeof plugin === "function" ? plugin.name : plugin.name;
|
|
1203
|
-
const store = this.getPluginStore();
|
|
1204
|
-
if (name && store.has(name)) return;
|
|
1205
|
-
if (name) store.add(name);
|
|
1206
|
-
const setup = async () => {
|
|
1207
|
-
const ctx = {
|
|
1208
|
-
container: Container,
|
|
1209
|
-
bind: this.createPluginBind(),
|
|
1210
|
-
resolveArguments: (resolver) => {
|
|
1211
|
-
this.getPluginArgumentResolvers().add(resolver);
|
|
1212
|
-
},
|
|
1213
|
-
useHttpContext: (resolver) => {
|
|
1214
|
-
this.getPluginHttpCtxResolvers().add(resolver);
|
|
1215
|
-
},
|
|
1216
|
-
bindings: Container.bindings(),
|
|
1217
|
-
configure: this.configure.bind(this),
|
|
1218
|
-
configureDefaults: this.configureDefaults.bind(this),
|
|
1219
|
-
get request() {
|
|
1220
|
-
return this.getRequest();
|
|
1221
|
-
},
|
|
1222
|
-
get response() {
|
|
1223
|
-
return this.getResponse();
|
|
1224
|
-
},
|
|
1225
|
-
getRequest: () => this.getCurrentPluginRequestContext()?.request,
|
|
1226
|
-
getResponse: () => this.getCurrentPluginRequestContext()?.response,
|
|
1227
|
-
options
|
|
1228
|
-
};
|
|
1229
|
-
if (typeof plugin === "function") await plugin(ctx);
|
|
1230
|
-
else await plugin.setup(ctx);
|
|
1231
|
-
};
|
|
1232
|
-
const pending = this.getPluginPendingStore();
|
|
1233
|
-
const promise = setup();
|
|
1234
|
-
pending.add(promise);
|
|
1235
|
-
try {
|
|
1236
|
-
await promise;
|
|
1237
|
-
} catch (error) {
|
|
1238
|
-
if (name) store.delete(name);
|
|
1239
|
-
throw error;
|
|
1240
|
-
} finally {
|
|
1241
|
-
pending.delete(promise);
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
static async pluginsReady() {
|
|
1245
|
-
const pending = Array.from(this.getPluginPendingStore());
|
|
1246
|
-
if (!pending.length) return;
|
|
1247
|
-
await Promise.all(pending);
|
|
1248
|
-
}
|
|
1249
|
-
static getCurrentPluginRequestContext() {
|
|
1250
|
-
return this.pluginRequestContext.getStore();
|
|
1251
|
-
}
|
|
1252
|
-
static createPluginRequestContext(ctx) {
|
|
1253
|
-
const request = ctx.clearRequest;
|
|
1254
|
-
const response = ctx.clearResponse;
|
|
1255
|
-
return {
|
|
1256
|
-
...ctx,
|
|
1257
|
-
ctx,
|
|
1258
|
-
request,
|
|
1259
|
-
response,
|
|
1260
|
-
getBindings: () => Container.bindings()
|
|
1261
|
-
};
|
|
1262
|
-
}
|
|
1263
|
-
static createPluginBind() {
|
|
1264
|
-
const bind = (token, value) => {
|
|
1265
|
-
if (typeof value === "function" && !isClass(value)) {
|
|
1266
|
-
const factory = value;
|
|
1267
|
-
Container.bind(token, (ctx) => factory(this.createPluginRequestContext(ctx)));
|
|
1268
|
-
return;
|
|
1269
|
-
}
|
|
1270
|
-
Container.bind(token, value);
|
|
1271
|
-
};
|
|
1272
|
-
return bind;
|
|
1273
|
-
}
|
|
1274
|
-
static async resolvePluginArguments(ctx, routeContext) {
|
|
1275
|
-
const resolvers = Array.from(this.getPluginArgumentResolvers());
|
|
1276
|
-
if (!resolvers.length) return void 0;
|
|
1277
|
-
const pluginContext = {
|
|
1278
|
-
...this.createPluginRequestContext(ctx),
|
|
1279
|
-
...routeContext
|
|
1280
|
-
};
|
|
1281
|
-
for (const resolver of resolvers) {
|
|
1282
|
-
const args = await resolver(pluginContext);
|
|
1283
|
-
if (Array.isArray(args)) return args;
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
static async resolvePluginHttpCtx(ctx) {
|
|
1287
|
-
const resolvers = Array.from(this.getPluginHttpCtxResolvers());
|
|
1288
|
-
if (!resolvers.length) return void 0;
|
|
1289
|
-
const pluginContext = this.createPluginRequestContext(ctx);
|
|
1290
|
-
for (const resolver of resolvers) await resolver(pluginContext);
|
|
1291
|
-
}
|
|
1292
|
-
static ensureState() {
|
|
1293
|
-
this.bindStateAccessors();
|
|
1294
|
-
if (!this.config) this.config = { methodOverride: {
|
|
1295
|
-
enabled: true,
|
|
1296
|
-
bodyKeys: ["_method"],
|
|
1297
|
-
headerKeys: ["x-http-method"]
|
|
1298
|
-
} };
|
|
1299
|
-
if (!this.groupContext) this.groupContext = new AsyncLocalStorage();
|
|
1300
|
-
if (!this.routes || Array.isArray(this.routes)) this.routes = new Set(this.routes ?? []);
|
|
1301
|
-
if (!this.routesByPathMethod) this.routesByPathMethod = /* @__PURE__ */ new Map();
|
|
1302
|
-
if (!this.routesByMethod) this.routesByMethod = /* @__PURE__ */ new Map();
|
|
1303
|
-
if (!this.routesByName) this.routesByName = /* @__PURE__ */ new Map();
|
|
1304
|
-
if (typeof this.prefix !== "string") this.prefix = "";
|
|
1305
|
-
if (!Array.isArray(this.groupMiddlewares)) this.groupMiddlewares = [];
|
|
1306
|
-
if (!Array.isArray(this.globalMiddlewares)) this.globalMiddlewares = [];
|
|
1307
|
-
}
|
|
1308
|
-
/**
|
|
1309
|
-
* Normalizes a path by ensuring it starts with a single slash and does not have trailing
|
|
1310
|
-
* slashes, while preserving dynamic segments and parameters.
|
|
1311
|
-
*
|
|
1312
|
-
* @param path The path to normalize.
|
|
1313
|
-
* @returns The normalized path.
|
|
1314
|
-
*/
|
|
1315
|
-
static normalizePath(path) {
|
|
1316
|
-
return "/" + path.split("/").filter(Boolean).join("/");
|
|
1317
|
-
}
|
|
1318
|
-
static parseRouteParameters(path) {
|
|
1319
|
-
const parameters = [];
|
|
1320
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1321
|
-
const pattern = /\{([^{}]+)\}/g;
|
|
1322
|
-
let match;
|
|
1323
|
-
while ((match = pattern.exec(path)) !== null) {
|
|
1324
|
-
const raw = match[1].trim();
|
|
1325
|
-
const optional = raw.endsWith("?");
|
|
1326
|
-
const [name, field] = (optional ? raw.slice(0, -1) : raw).split(":", 2).map((part) => part.trim());
|
|
1327
|
-
if (!name || seen.has(name)) continue;
|
|
1328
|
-
seen.add(name);
|
|
1329
|
-
parameters.push({
|
|
1330
|
-
name,
|
|
1331
|
-
field: field || void 0,
|
|
1332
|
-
optional
|
|
1333
|
-
});
|
|
1334
|
-
}
|
|
1335
|
-
return parameters;
|
|
1336
|
-
}
|
|
1337
|
-
static expandRoutePath(path) {
|
|
1338
|
-
let paths = [""];
|
|
1339
|
-
const segments = this.normalizePath(path).split("/").filter(Boolean);
|
|
1340
|
-
for (const segment of segments) {
|
|
1341
|
-
const match = segment.match(/^\{([^{}]+)\}$/);
|
|
1342
|
-
if (!match) {
|
|
1343
|
-
paths = paths.map((current) => `${current}/${segment}`);
|
|
1344
|
-
continue;
|
|
1345
|
-
}
|
|
1346
|
-
const raw = match[1].trim();
|
|
1347
|
-
const optional = raw.endsWith("?");
|
|
1348
|
-
const [rawName] = (optional ? raw.slice(0, -1) : raw).split(":", 2);
|
|
1349
|
-
const name = rawName.trim();
|
|
1350
|
-
if (!name) continue;
|
|
1351
|
-
const parameterSegment = `/:${name}`;
|
|
1352
|
-
paths = optional ? paths.flatMap((current) => [current, `${current}${parameterSegment}`]) : paths.map((current) => `${current}${parameterSegment}`);
|
|
1353
|
-
}
|
|
1354
|
-
return paths.map((path) => path || "/");
|
|
1355
|
-
}
|
|
1356
|
-
static routeRegistrationPaths(path) {
|
|
1357
|
-
return this.expandRoutePath(path);
|
|
1358
|
-
}
|
|
1359
|
-
/**
|
|
1360
|
-
* Compile a host pattern such as `{account}.example.com` into a matcher and
|
|
1361
|
-
* the ordered list of placeholder names it captures. Results are memoized.
|
|
1362
|
-
*
|
|
1363
|
-
* @param pattern
|
|
1364
|
-
* @returns
|
|
1365
|
-
*/
|
|
1366
|
-
static compileDomain(pattern) {
|
|
1367
|
-
const cached = this.domainMatcherCache.get(pattern);
|
|
1368
|
-
if (cached) return cached;
|
|
1369
|
-
const cleanPattern = pattern.split(":", 1)[0].trim();
|
|
1370
|
-
const escape = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, (match) => `\\${match}`);
|
|
1371
|
-
const placeholder = /\{([^{}]+)\}/g;
|
|
1372
|
-
const params = [];
|
|
1373
|
-
let source = "^";
|
|
1374
|
-
let lastIndex = 0;
|
|
1375
|
-
let match;
|
|
1376
|
-
while ((match = placeholder.exec(cleanPattern)) !== null) {
|
|
1377
|
-
source += escape(cleanPattern.slice(lastIndex, match.index));
|
|
1378
|
-
const raw = match[1].trim();
|
|
1379
|
-
const optional = raw.endsWith("?");
|
|
1380
|
-
const name = (optional ? raw.slice(0, -1) : raw).split(":", 1)[0].trim();
|
|
1381
|
-
params.push(name);
|
|
1382
|
-
source += optional ? "([^.]*)" : "([^.]+)";
|
|
1383
|
-
lastIndex = match.index + match[0].length;
|
|
1384
|
-
}
|
|
1385
|
-
source += escape(cleanPattern.slice(lastIndex));
|
|
1386
|
-
source += "$";
|
|
1387
|
-
const compiled = {
|
|
1388
|
-
regex: new RegExp(source, "i"),
|
|
1389
|
-
params
|
|
1390
|
-
};
|
|
1391
|
-
this.domainMatcherCache.set(pattern, compiled);
|
|
1392
|
-
return compiled;
|
|
1393
|
-
}
|
|
1394
|
-
/**
|
|
1395
|
-
* Match a host against a domain pattern, returning the captured parameters or
|
|
1396
|
-
* `null` when the host does not match.
|
|
1397
|
-
*
|
|
1398
|
-
* @param pattern
|
|
1399
|
-
* @param host
|
|
1400
|
-
* @returns
|
|
1401
|
-
*/
|
|
1402
|
-
static matchDomain(pattern, host) {
|
|
1403
|
-
if (!pattern) return null;
|
|
1404
|
-
const cleanHost = String(host ?? "").split(":", 1)[0].trim().toLowerCase();
|
|
1405
|
-
const { regex, params } = this.compileDomain(pattern);
|
|
1406
|
-
const match = regex.exec(cleanHost);
|
|
1407
|
-
if (!match) return null;
|
|
1408
|
-
const result = {};
|
|
1409
|
-
params.forEach((name, index) => {
|
|
1410
|
-
const value = match[index + 1];
|
|
1411
|
-
if (typeof value !== "undefined") result[name] = decodeURIComponent(value);
|
|
1412
|
-
});
|
|
1413
|
-
return result;
|
|
1414
|
-
}
|
|
1415
|
-
/**
|
|
1416
|
-
* Best-effort extraction of the request host across every supported adapter
|
|
1417
|
-
* context shape (Express/Fastify plain headers, H3 `Headers`, Hono accessor,
|
|
1418
|
-
* Koa context).
|
|
1419
|
-
*
|
|
1420
|
-
* @param ctx
|
|
1421
|
-
* @returns
|
|
1422
|
-
*/
|
|
1423
|
-
static extractHost(ctx) {
|
|
1424
|
-
const headers = ctx?.req?.headers ?? ctx?.headers;
|
|
1425
|
-
let host;
|
|
1426
|
-
if (headers) host = typeof headers.get === "function" ? headers.get("host") ?? headers.get(":authority") : headers.host ?? headers[":authority"];
|
|
1427
|
-
if (!host && typeof ctx?.req?.header === "function") host = ctx.req.header("host");
|
|
1428
|
-
if (!host && typeof ctx?.host === "string") host = ctx.host;
|
|
1429
|
-
if (Array.isArray(host)) host = host[0];
|
|
1430
|
-
return String(host ?? "").split(",", 1)[0].trim();
|
|
1431
|
-
}
|
|
1432
|
-
/**
|
|
1433
|
-
* Resolve the domain parameters for a route given the active request context.
|
|
1434
|
-
* Returns `null` when the route is not domain-constrained, `false` when it is
|
|
1435
|
-
* but the host does not match, or the captured parameters on a match.
|
|
1436
|
-
*
|
|
1437
|
-
* @param route
|
|
1438
|
-
* @param ctx
|
|
1439
|
-
* @returns
|
|
1440
|
-
*/
|
|
1441
|
-
static matchRouteDomain(route, ctx) {
|
|
1442
|
-
if (!route.domainPattern) return null;
|
|
1443
|
-
return this.matchDomain(route.domainPattern, this.extractHost(ctx)) ?? false;
|
|
1444
|
-
}
|
|
1445
|
-
/**
|
|
1446
|
-
* Register a global pattern applied to every route parameter sharing the
|
|
1447
|
-
* given name (equivalent to Laravel's `Route::pattern`).
|
|
1448
|
-
*
|
|
1449
|
-
* @param name
|
|
1450
|
-
* @param pattern
|
|
1451
|
-
*/
|
|
1452
|
-
static pattern(name, pattern) {
|
|
1453
|
-
this.ensureState();
|
|
1454
|
-
this.routePatterns.set(name, pattern);
|
|
1455
|
-
}
|
|
1456
|
-
/**
|
|
1457
|
-
* Register multiple global parameter patterns at once.
|
|
1458
|
-
*
|
|
1459
|
-
* @param patterns
|
|
1460
|
-
*/
|
|
1461
|
-
static patterns(patterns) {
|
|
1462
|
-
for (const [name, pattern] of Object.entries(patterns)) this.pattern(name, pattern);
|
|
1463
|
-
}
|
|
1464
|
-
/**
|
|
1465
|
-
* Merge the global parameter patterns with the route's own constraints. Route
|
|
1466
|
-
* level constraints take precedence over global patterns.
|
|
1467
|
-
*
|
|
1468
|
-
* @param route
|
|
1469
|
-
* @returns
|
|
1470
|
-
*/
|
|
1471
|
-
static resolveConstraints(route) {
|
|
1472
|
-
if (!this.routePatterns.size && !Object.keys(route.constraints).length) return route.constraints;
|
|
1473
|
-
return {
|
|
1474
|
-
...Object.fromEntries(this.routePatterns),
|
|
1475
|
-
...route.constraints
|
|
1476
|
-
};
|
|
1477
|
-
}
|
|
1478
|
-
/**
|
|
1479
|
-
* Compile a constraint pattern into a fully-anchored regular expression.
|
|
1480
|
-
*
|
|
1481
|
-
* @param pattern
|
|
1482
|
-
* @returns
|
|
1483
|
-
*/
|
|
1484
|
-
static toConstraintRegex(pattern) {
|
|
1485
|
-
if (pattern instanceof RegExp) return new RegExp(`^(?:${pattern.source})$`, pattern.flags.replace("g", ""));
|
|
1486
|
-
const cached = this.constraintRegexCache.get(pattern);
|
|
1487
|
-
if (cached) return cached;
|
|
1488
|
-
const regex = new RegExp(`^(?:${pattern})$`);
|
|
1489
|
-
this.constraintRegexCache.set(pattern, regex);
|
|
1490
|
-
return regex;
|
|
1491
|
-
}
|
|
1492
|
-
/**
|
|
1493
|
-
* Determine whether the resolved parameters satisfy the route's constraints.
|
|
1494
|
-
* Absent parameters (e.g. optional ones) are ignored.
|
|
1495
|
-
*
|
|
1496
|
-
* @param route
|
|
1497
|
-
* @param params
|
|
1498
|
-
* @returns
|
|
1499
|
-
*/
|
|
1500
|
-
static satisfiesConstraints(route, params) {
|
|
1501
|
-
const constraints = this.resolveConstraints(route);
|
|
1502
|
-
for (const name of Object.keys(constraints)) {
|
|
1503
|
-
const value = params[name];
|
|
1504
|
-
if (typeof value === "undefined" || value === null) continue;
|
|
1505
|
-
const values = Array.isArray(value) ? value : [value];
|
|
1506
|
-
const regex = this.toConstraintRegex(constraints[name]);
|
|
1507
|
-
if (!values.every((entry) => regex.test(String(entry)))) return false;
|
|
1508
|
-
}
|
|
1509
|
-
return true;
|
|
1510
|
-
}
|
|
1511
|
-
/**
|
|
1512
|
-
* Determine which of a route's parameters are allowed to span multiple path
|
|
1513
|
-
* segments (i.e. their constraint matches an encoded forward slash). These are
|
|
1514
|
-
* registered with the adapter's catch-all syntax.
|
|
1515
|
-
*
|
|
1516
|
-
* @param route
|
|
1517
|
-
* @returns
|
|
1518
|
-
*/
|
|
1519
|
-
static wildcardParameters(route) {
|
|
1520
|
-
const wildcards = /* @__PURE__ */ new Set();
|
|
1521
|
-
const constraints = this.resolveConstraints(route);
|
|
1522
|
-
const declared = new Set(route.parameters.map((parameter) => parameter.name));
|
|
1523
|
-
for (const name of Object.keys(constraints)) {
|
|
1524
|
-
if (!declared.has(name)) continue;
|
|
1525
|
-
if (this.toConstraintRegex(constraints[name]).test("a/b")) wildcards.add(name);
|
|
1526
|
-
}
|
|
1527
|
-
return wildcards;
|
|
1528
|
-
}
|
|
1529
|
-
/**
|
|
1530
|
-
* Render a single wildcard (slash-spanning) parameter for the underlying
|
|
1531
|
-
* router's registration path. Overridden per adapter; the base form keeps the
|
|
1532
|
-
* plain `:name` placeholder.
|
|
1533
|
-
*
|
|
1534
|
-
* @param name
|
|
1535
|
-
* @returns
|
|
1536
|
-
*/
|
|
1537
|
-
static formatWildcardParam(name) {
|
|
1538
|
-
return `:${name}`;
|
|
1539
|
-
}
|
|
1540
|
-
/**
|
|
1541
|
-
* Rewrite a route's registration paths so any wildcard parameters use the
|
|
1542
|
-
* adapter's catch-all syntax. Non-wildcard routes are returned unchanged.
|
|
1543
|
-
*
|
|
1544
|
-
* @param route
|
|
1545
|
-
* @returns
|
|
1546
|
-
*/
|
|
1547
|
-
static resolveRegistrationPaths(route) {
|
|
1548
|
-
const wildcards = this.wildcardParameters(route);
|
|
1549
|
-
if (!wildcards.size) return route.registrationPaths;
|
|
1550
|
-
return route.registrationPaths.map((path) => path.split("/").map((segment) => {
|
|
1551
|
-
const name = segment.startsWith(":") ? segment.slice(1) : "";
|
|
1552
|
-
return name && wildcards.has(name) ? this.formatWildcardParam(name) : segment;
|
|
1553
|
-
}).join("/"));
|
|
1554
|
-
}
|
|
1555
|
-
/**
|
|
1556
|
-
* Resolve the final parameters for a dispatched route, applying domain
|
|
1557
|
-
* matching and constraint validation. Returns the merged parameters, or
|
|
1558
|
-
* `false` when the route should not handle the request (host mismatch or a
|
|
1559
|
-
* constraint failure) so the adapter can fall through.
|
|
1560
|
-
*
|
|
1561
|
-
* @param route
|
|
1562
|
-
* @param ctx
|
|
1563
|
-
* @param baseParams
|
|
1564
|
-
* @returns
|
|
1565
|
-
*/
|
|
1566
|
-
static matchRoute(route, ctx, baseParams = {}) {
|
|
1567
|
-
const params = { ...baseParams ?? {} };
|
|
1568
|
-
if (route.domainPattern) {
|
|
1569
|
-
const domainParams = this.matchDomain(route.domainPattern, this.extractHost(ctx));
|
|
1570
|
-
if (!domainParams) return false;
|
|
1571
|
-
Object.assign(params, domainParams);
|
|
1572
|
-
}
|
|
1573
|
-
this.normalizeWildcardParams(route, params);
|
|
1574
|
-
if (!this.satisfiesConstraints(route, params)) return false;
|
|
1575
|
-
return params;
|
|
1576
|
-
}
|
|
1577
|
-
/**
|
|
1578
|
-
* Normalize wildcard (slash-spanning) parameters into a single string keyed by
|
|
1579
|
-
* the declared parameter name, smoothing over the differing shapes adapters
|
|
1580
|
-
* return (Express yields an array of segments, Fastify keys it under `*`).
|
|
1581
|
-
*
|
|
1582
|
-
* @param route
|
|
1583
|
-
* @param params
|
|
1584
|
-
*/
|
|
1585
|
-
static normalizeWildcardParams(route, params) {
|
|
1586
|
-
const wildcards = this.wildcardParameters(route);
|
|
1587
|
-
if (!wildcards.size) return;
|
|
1588
|
-
for (const name of wildcards) {
|
|
1589
|
-
let value = params[name];
|
|
1590
|
-
if (typeof value === "undefined" && typeof params["*"] !== "undefined") {
|
|
1591
|
-
value = params["*"];
|
|
1592
|
-
delete params["*"];
|
|
1593
|
-
}
|
|
1594
|
-
if (Array.isArray(value)) value = value.join("/");
|
|
1595
|
-
if (typeof value !== "undefined") params[name] = value;
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
/**
|
|
1599
|
-
* Get the route currently being dispatched, if any.
|
|
1600
|
-
*
|
|
1601
|
-
* @returns
|
|
1602
|
-
*/
|
|
1603
|
-
static current() {
|
|
1604
|
-
const store = this.pluginRequestContext.getStore();
|
|
1605
|
-
return store?.request?.route ?? store?.ctx?.clearRequest?.route;
|
|
1606
|
-
}
|
|
1607
|
-
/**
|
|
1608
|
-
* Get the name of the route currently being dispatched.
|
|
1609
|
-
*
|
|
1610
|
-
* @returns
|
|
1611
|
-
*/
|
|
1612
|
-
static currentRouteName() {
|
|
1613
|
-
return this.current()?.routeName ?? "";
|
|
1614
|
-
}
|
|
1615
|
-
/**
|
|
1616
|
-
* Get the action (`Controller@method` or `Closure`) of the route currently
|
|
1617
|
-
* being dispatched.
|
|
1618
|
-
*
|
|
1619
|
-
* @returns
|
|
1620
|
-
*/
|
|
1621
|
-
static currentRouteAction() {
|
|
1622
|
-
return this.current()?.action ?? "";
|
|
1623
|
-
}
|
|
1624
|
-
/**
|
|
1625
|
-
* Configures the router with the given options, such as method override settings.
|
|
1626
|
-
*
|
|
1627
|
-
* @param this
|
|
1628
|
-
* @param options
|
|
1629
|
-
* @returns
|
|
1630
|
-
*/
|
|
1631
|
-
static configure(options) {
|
|
1632
|
-
this.ensureState();
|
|
1633
|
-
this.config = this.mergeConfig(this.getDefaultConfig(), this.config);
|
|
1634
|
-
const container = options?.container;
|
|
1635
|
-
if (container) {
|
|
1636
|
-
if (typeof container.enabled === "boolean") this.config.container.enabled = container.enabled;
|
|
1637
|
-
if (typeof container.autoDiscover === "boolean") this.config.container.autoDiscover = container.autoDiscover;
|
|
1638
|
-
}
|
|
1639
|
-
if (options?.inferParamName) this.config.inferParamName = options?.inferParamName;
|
|
1640
|
-
const override = options?.methodOverride;
|
|
1641
|
-
if (override) {
|
|
1642
|
-
if (typeof override.enabled === "boolean") this.config.methodOverride.enabled = override.enabled;
|
|
1643
|
-
const bodyKeys = override.bodyKeys;
|
|
1644
|
-
if (typeof bodyKeys !== "undefined") this.config.methodOverride.bodyKeys = (Array.isArray(bodyKeys) ? bodyKeys : [bodyKeys]).map((e) => String(e).trim()).filter(Boolean);
|
|
1645
|
-
const headerKeys = override.headerKeys;
|
|
1646
|
-
if (typeof headerKeys !== "undefined") this.config.methodOverride.headerKeys = (Array.isArray(headerKeys) ? headerKeys : [headerKeys]).map((e) => String(e).trim().toLowerCase()).filter(Boolean);
|
|
1647
|
-
}
|
|
1648
|
-
}
|
|
1649
|
-
static resolveMethodOverride(method, headers, body) {
|
|
1650
|
-
this.ensureState();
|
|
1651
|
-
if (!this.config.methodOverride?.enabled || method.toLowerCase() !== "post") return null;
|
|
1652
|
-
let override;
|
|
1653
|
-
const headerValueFor = (key) => {
|
|
1654
|
-
if (typeof headers.get === "function") return headers.get(key);
|
|
1655
|
-
const value = headers?.[key];
|
|
1656
|
-
return Array.isArray(value) ? value[0] : value;
|
|
1657
|
-
};
|
|
1658
|
-
for (const key of this.config.methodOverride?.headerKeys || []) {
|
|
1659
|
-
const value = headerValueFor(key);
|
|
1660
|
-
if (value) {
|
|
1661
|
-
override = value;
|
|
1662
|
-
break;
|
|
1663
|
-
}
|
|
1664
|
-
}
|
|
1665
|
-
if (!override && body && typeof body === "object") for (const key of this.config.methodOverride?.bodyKeys || []) {
|
|
1666
|
-
const value = body[key];
|
|
1667
|
-
if (typeof value !== "undefined" && value !== null && value !== "") {
|
|
1668
|
-
override = value;
|
|
1669
|
-
break;
|
|
1670
|
-
}
|
|
1671
|
-
}
|
|
1672
|
-
const normalized = String(override || "").trim().toLowerCase();
|
|
1673
|
-
if (!normalized) return null;
|
|
1674
|
-
if ([
|
|
1675
|
-
"put",
|
|
1676
|
-
"patch",
|
|
1677
|
-
"delete",
|
|
1678
|
-
"post"
|
|
1679
|
-
].includes(normalized)) return normalized;
|
|
1680
|
-
return null;
|
|
1681
|
-
}
|
|
1682
|
-
/**
|
|
1683
|
-
* Adds a new route to the router.
|
|
1684
|
-
*
|
|
1685
|
-
* @param this
|
|
1686
|
-
* @param methods
|
|
1687
|
-
* @param path
|
|
1688
|
-
* @param handler
|
|
1689
|
-
* @param middlewares
|
|
1690
|
-
*/
|
|
1691
|
-
static add(methods, path, handler, middlewares) {
|
|
1692
|
-
this.ensureState();
|
|
1693
|
-
const context = this.groupContext.getStore();
|
|
1694
|
-
const activePrefix = context?.prefix ?? this.prefix;
|
|
1695
|
-
const activeGroupMiddlewares = context?.groupMiddlewares ?? this.groupMiddlewares;
|
|
1696
|
-
const activeDomain = context?.domain;
|
|
1697
|
-
methods = Array.isArray(methods) ? methods : [methods];
|
|
1698
|
-
middlewares = middlewares ? Array.isArray(middlewares) ? middlewares : [middlewares] : void 0;
|
|
1699
|
-
const fullPath = this.normalizePath(`${activePrefix}/${path}`);
|
|
1700
|
-
const registrationPaths = this.routeRegistrationPaths(fullPath);
|
|
1701
|
-
const parameters = this.parseRouteParameters(fullPath);
|
|
1702
|
-
for (const method of methods) {
|
|
1703
|
-
const existing = this.routesByPathMethod.get(`${method.toUpperCase()} ${fullPath}`);
|
|
1704
|
-
if (existing) this.removeRouteMethod(existing, method, fullPath);
|
|
1705
|
-
}
|
|
1706
|
-
const route = new Route(methods.includes("options") ? methods : methods.concat("options"), fullPath, handler, this.resolveMiddlewares([
|
|
1707
|
-
...this.globalMiddlewares,
|
|
1708
|
-
...activeGroupMiddlewares,
|
|
1709
|
-
...middlewares || []
|
|
1710
|
-
]), {
|
|
1711
|
-
registrationPaths,
|
|
1712
|
-
parameters,
|
|
1713
|
-
domain: activeDomain,
|
|
1714
|
-
onName: (name, route, previousName) => {
|
|
1715
|
-
if (previousName && this.routesByName.get(previousName) === route) this.routesByName.delete(previousName);
|
|
1716
|
-
this.routesByName.set(name, route);
|
|
1717
|
-
},
|
|
1718
|
-
normalizeMiddleware: (middleware) => this.resolveMiddleware(middleware)
|
|
1719
|
-
});
|
|
1720
|
-
if (!methods.includes("options") && !this.routesByPathMethod.get(`OPTIONS ${fullPath}`)) this.options(path, this.createDefaultOptionsHandler());
|
|
1721
|
-
this.routes.add(route);
|
|
1722
|
-
for (const collector of context?.routeCollectors ?? []) collector.add(route);
|
|
1723
|
-
for (const method of methods.map((m) => m.toUpperCase())) {
|
|
1724
|
-
this.routesByPathMethod.set(`${method} ${fullPath}`, route);
|
|
1725
|
-
if (!this.routesByMethod.has(method)) this.routesByMethod.set(method, []);
|
|
1726
|
-
this.routesByMethod.get(method)?.push(route);
|
|
1727
|
-
}
|
|
1728
|
-
return route;
|
|
1729
|
-
}
|
|
1730
|
-
/**
|
|
1731
|
-
* Define a resourceful API controller with standard CRUD routes.
|
|
1732
|
-
*
|
|
1733
|
-
* @param this
|
|
1734
|
-
* @param basePath
|
|
1735
|
-
* @param controller
|
|
1736
|
-
* @param options
|
|
1737
|
-
*/
|
|
1738
|
-
static apiResource(basePath, controller, options) {
|
|
1739
|
-
let paramName = "id";
|
|
1740
|
-
if (!!this.config.inferParamName && this.hasPackageInstalled("@h3ravel/support")) {
|
|
1741
|
-
const { str } = createRequire(import.meta.url)("@h3ravel/support");
|
|
1742
|
-
paramName = str(basePath).singular().afterLast("/").toString();
|
|
1743
|
-
}
|
|
1744
|
-
return new ResourceRoutes(basePath, controller, paramName, options, ({ method, path, handler, middlewares, name }) => {
|
|
1745
|
-
return this.add(method, path, handler, middlewares).name(name);
|
|
1746
|
-
}, (route) => this.removeRoute(route)).register();
|
|
1747
|
-
}
|
|
1748
|
-
/**
|
|
1749
|
-
* Adds a new GET route to the router.
|
|
1750
|
-
*
|
|
1751
|
-
* @param this The router instance.
|
|
1752
|
-
* @param path The path for the GET route.
|
|
1753
|
-
* @param handler The handler function for the GET route.
|
|
1754
|
-
* @param middlewares Optional middlewares to apply to the GET route.
|
|
1755
|
-
*/
|
|
1756
|
-
static get(path, handler, middlewares) {
|
|
1757
|
-
return this.add("get", path, handler, middlewares);
|
|
1758
|
-
}
|
|
1759
|
-
/**
|
|
1760
|
-
* Adds a new POST route to the router.
|
|
1761
|
-
*
|
|
1762
|
-
* @param this
|
|
1763
|
-
* @param path
|
|
1764
|
-
* @param handler
|
|
1765
|
-
* @param middlewares
|
|
1766
|
-
*/
|
|
1767
|
-
static post(path, handler, middlewares) {
|
|
1768
|
-
return this.add("post", path, handler, middlewares);
|
|
1769
|
-
}
|
|
1770
|
-
/**
|
|
1771
|
-
* Adds a new PUT route to the router.
|
|
1772
|
-
*
|
|
1773
|
-
* @param this
|
|
1774
|
-
* @param path
|
|
1775
|
-
* @param handler
|
|
1776
|
-
* @param middlewares
|
|
1777
|
-
*/
|
|
1778
|
-
static put(path, handler, middlewares) {
|
|
1779
|
-
return this.add("put", path, handler, middlewares);
|
|
1780
|
-
}
|
|
1781
|
-
/**
|
|
1782
|
-
* Adds a new DELETE route to the router.
|
|
1783
|
-
*
|
|
1784
|
-
* @param this
|
|
1785
|
-
* @param path
|
|
1786
|
-
* @param handler
|
|
1787
|
-
* @param middlewares
|
|
1788
|
-
*/
|
|
1789
|
-
static delete(path, handler, middlewares) {
|
|
1790
|
-
return this.add("delete", path, handler, middlewares);
|
|
1791
|
-
}
|
|
1792
|
-
/**
|
|
1793
|
-
* Adds a new PATCH route to the router.
|
|
1794
|
-
*
|
|
1795
|
-
* @param this
|
|
1796
|
-
* @param path
|
|
1797
|
-
* @param handler
|
|
1798
|
-
* @param middlewares
|
|
1799
|
-
*/
|
|
1800
|
-
static patch(path, handler, middlewares) {
|
|
1801
|
-
return this.add("patch", path, handler, middlewares);
|
|
1802
|
-
}
|
|
1803
|
-
/**
|
|
1804
|
-
* Adds a new OPTIONS route to the router.
|
|
1805
|
-
*
|
|
1806
|
-
* @param this
|
|
1807
|
-
* @param path
|
|
1808
|
-
* @param handler
|
|
1809
|
-
* @param middlewares
|
|
1810
|
-
*/
|
|
1811
|
-
static options(path, handler, middlewares) {
|
|
1812
|
-
return this.add("options", path, handler, middlewares);
|
|
1813
|
-
}
|
|
1814
|
-
/**
|
|
1815
|
-
* Adds a new HEAD route to the router.
|
|
1816
|
-
*
|
|
1817
|
-
* @param this
|
|
1818
|
-
* @param path
|
|
1819
|
-
* @param handler
|
|
1820
|
-
* @param middlewares
|
|
1821
|
-
*/
|
|
1822
|
-
static head(path, handler, middlewares) {
|
|
1823
|
-
return this.add("head", path, handler, middlewares);
|
|
1824
|
-
}
|
|
1825
|
-
/**
|
|
1826
|
-
* Defines a group of routes with a common prefix.
|
|
1827
|
-
*
|
|
1828
|
-
* @param this
|
|
1829
|
-
* @param prefix
|
|
1830
|
-
* @param callback
|
|
1831
|
-
* @param middlewares
|
|
1832
|
-
*/
|
|
1833
|
-
static group(prefix, source, middlewares) {
|
|
1834
|
-
return this.makeGroup(prefix, source, middlewares);
|
|
1835
|
-
}
|
|
1836
|
-
/**
|
|
1837
|
-
* Build a route group, optionally constrained to a host pattern. Shared by
|
|
1838
|
-
* `group` and the `domain` registrar.
|
|
1839
|
-
*
|
|
1840
|
-
* @param prefix
|
|
1841
|
-
* @param source
|
|
1842
|
-
* @param middlewares
|
|
1843
|
-
* @param extra
|
|
1844
|
-
*/
|
|
1845
|
-
static makeGroup(prefix, source, middlewares, extra) {
|
|
1846
|
-
this.ensureState();
|
|
1847
|
-
return new RouteGroup({
|
|
1848
|
-
prefix,
|
|
1849
|
-
source,
|
|
1850
|
-
middlewares,
|
|
1851
|
-
domain: extra?.domain,
|
|
1852
|
-
context: this.groupContext,
|
|
1853
|
-
defaultPrefix: this.prefix,
|
|
1854
|
-
defaultMiddlewares: this.groupMiddlewares,
|
|
1855
|
-
normalizePath: (path) => this.normalizePath(path),
|
|
1856
|
-
removeRoute: (route) => this.removeRoute(route)
|
|
1857
|
-
});
|
|
1858
|
-
}
|
|
1859
|
-
/**
|
|
1860
|
-
* Begin a route registration constrained to a host pattern such as
|
|
1861
|
-
* `{account}.example.com`. Returns a registrar whose `.group()` registers the
|
|
1862
|
-
* routes under that domain (matched parameters become route parameters).
|
|
1863
|
-
*
|
|
1864
|
-
* @param pattern
|
|
1865
|
-
* @returns
|
|
1866
|
-
*/
|
|
1867
|
-
static domain(pattern) {
|
|
1868
|
-
this.ensureState();
|
|
1869
|
-
return new RouteRegistrar((prefix, source, middlewares, extra) => this.makeGroup(prefix, source, middlewares, extra), { domain: pattern });
|
|
1870
|
-
}
|
|
1871
|
-
/**
|
|
1872
|
-
* Adds global middlewares to the router, which will be applied to all routes.
|
|
1873
|
-
*
|
|
1874
|
-
* @param this
|
|
1875
|
-
* @param middlewares
|
|
1876
|
-
* @param callback
|
|
1877
|
-
*/
|
|
1878
|
-
static middleware(middlewares, callback) {
|
|
1879
|
-
this.ensureState();
|
|
1880
|
-
const prevMiddlewares = this.globalMiddlewares;
|
|
1881
|
-
this.globalMiddlewares = [...prevMiddlewares, ...middlewares || []];
|
|
1882
|
-
callback();
|
|
1883
|
-
this.globalMiddlewares = prevMiddlewares;
|
|
1884
|
-
}
|
|
1885
|
-
static allRoutes(type) {
|
|
1886
|
-
this.ensureState();
|
|
1887
|
-
if (type === "method") return Object.fromEntries(this.routesByMethod.entries());
|
|
1888
|
-
if (type === "path") return Object.fromEntries(this.routesByPathMethod.entries());
|
|
1889
|
-
if (type === "name") return Object.fromEntries(this.routesByName.entries());
|
|
1890
|
-
return Array.from(this.routes).filter((e) => e.methods.length > 1 || e.methods[0] !== "options");
|
|
1891
|
-
}
|
|
1892
|
-
static route(name) {
|
|
1893
|
-
this.ensureState();
|
|
1894
|
-
return this.routesByName.get(name);
|
|
1895
|
-
}
|
|
1896
|
-
static url(name, params) {
|
|
1897
|
-
return this.route(name)?.toPath(params);
|
|
1898
|
-
}
|
|
1899
|
-
/**
|
|
1900
|
-
* Provide a class that will overide the base Request instance
|
|
1901
|
-
*
|
|
1902
|
-
* @param provider
|
|
1903
|
-
*/
|
|
1904
|
-
static setRequestProvider(provider) {
|
|
1905
|
-
this.requestProvider = provider;
|
|
1906
|
-
}
|
|
1907
|
-
/**
|
|
1908
|
-
* Provide a class that will overide the base Response instance
|
|
1909
|
-
*
|
|
1910
|
-
* @param provider
|
|
1911
|
-
*/
|
|
1912
|
-
static setResponseProvider(provider) {
|
|
1913
|
-
this.responseProvider = provider;
|
|
1914
|
-
}
|
|
1915
|
-
static hasPackageInstalled(name) {
|
|
1916
|
-
try {
|
|
1917
|
-
createRequire(import.meta.url).resolve(name, { paths: [process.cwd()] });
|
|
1918
|
-
return true;
|
|
1919
|
-
} catch {
|
|
1920
|
-
return false;
|
|
1921
|
-
}
|
|
1922
|
-
}
|
|
1923
|
-
static initializeInstance(provider, args) {
|
|
1924
|
-
const isRequest = [
|
|
1925
|
-
"CoreRequest",
|
|
1926
|
-
"Request",
|
|
1927
|
-
"ClearRequest"
|
|
1928
|
-
].includes(provider.name);
|
|
1929
|
-
const isResponse = [
|
|
1930
|
-
"CoreResponse",
|
|
1931
|
-
"Response",
|
|
1932
|
-
"ClearResponse"
|
|
1933
|
-
].includes(provider.name);
|
|
1934
|
-
if (isRequest && this.requestProvider) return new this.requestProvider(args);
|
|
1935
|
-
else if (isResponse && this.responseProvider) return new this.responseProvider(args);
|
|
1936
|
-
return new provider(args);
|
|
1937
|
-
}
|
|
1938
|
-
static resolveHandler(route) {
|
|
1939
|
-
let handlerFunction;
|
|
1940
|
-
let instance = null;
|
|
1941
|
-
let bindingTarget;
|
|
1942
|
-
let bindingMethod;
|
|
1943
|
-
let bindingHandler;
|
|
1944
|
-
let bindingMetadata;
|
|
1945
|
-
if (typeof route.handler === "function") {
|
|
1946
|
-
handlerFunction = route.handler.bind(route);
|
|
1947
|
-
bindingTarget = route.handler;
|
|
1948
|
-
bindingHandler = route.handler;
|
|
1949
|
-
} else if (Array.isArray(route.handler) && route.handler.length === 2) {
|
|
1950
|
-
const [ControllerType, method] = route.handler;
|
|
1951
|
-
if (["function", "object"].includes(typeof ControllerType) && typeof ControllerType[method] === "function") {
|
|
1952
|
-
instance = ControllerType;
|
|
1953
|
-
handlerFunction = ControllerType[method].bind(ControllerType);
|
|
1954
|
-
bindingTarget = ControllerType;
|
|
1955
|
-
bindingMethod = method;
|
|
1956
|
-
bindingHandler = ControllerType[method];
|
|
1957
|
-
bindingMetadata = ControllerType[Symbol.metadata];
|
|
1958
|
-
} else if (typeof ControllerType === "function") {
|
|
1959
|
-
instance = new ControllerType();
|
|
1960
|
-
if (typeof instance[method] === "function") {
|
|
1961
|
-
handlerFunction = instance[method].bind(instance);
|
|
1962
|
-
bindingTarget = ControllerType.prototype;
|
|
1963
|
-
bindingMethod = method;
|
|
1964
|
-
bindingHandler = instance[method];
|
|
1965
|
-
bindingMetadata = ControllerType[Symbol.metadata];
|
|
1966
|
-
} else throw new Error(`Method "${method}" not found in controller instance "${ControllerType.name}"`);
|
|
1967
|
-
} else throw new Error(`Invalid controller type for route: ${route.path}`);
|
|
1968
|
-
} else throw new Error(`Invalid handler format for route: ${route.path}`);
|
|
1969
|
-
return {
|
|
1970
|
-
handlerFunction,
|
|
1971
|
-
instance,
|
|
1972
|
-
bindingTarget,
|
|
1973
|
-
bindingMethod,
|
|
1974
|
-
bindingHandler,
|
|
1975
|
-
bindingMetadata
|
|
1976
|
-
};
|
|
1977
|
-
}
|
|
1978
|
-
static async callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata) {
|
|
1979
|
-
return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
|
|
1980
|
-
await this.pluginsReady();
|
|
1981
|
-
await this.resolvePluginHttpCtx(ctx);
|
|
1982
|
-
if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
|
|
1983
|
-
const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
|
|
1984
|
-
const metadata = getBindingMetadataFromTargets([
|
|
1985
|
-
{
|
|
1986
|
-
target: bindingTarget,
|
|
1987
|
-
propertyKey: bindingMethod
|
|
1988
|
-
},
|
|
1989
|
-
{ target: bindingHandler },
|
|
1990
|
-
{
|
|
1991
|
-
target: bindingTarget,
|
|
1992
|
-
propertyKey: "__class__"
|
|
1993
|
-
}
|
|
1994
|
-
]) ?? getStandardMetadata(bindingMetadata, bindingMethod) ?? getStandardMetadata(bindingMetadata, "__class__");
|
|
1995
|
-
const tokens = metadata?.tokens?.length ? metadata.tokens : designTokens;
|
|
1996
|
-
const pluginArgs = await this.resolvePluginArguments(ctx, {
|
|
1997
|
-
target: bindingTarget,
|
|
1998
|
-
method: bindingMethod,
|
|
1999
|
-
handler: bindingHandler,
|
|
2000
|
-
metadata: bindingMetadata,
|
|
2001
|
-
tokens,
|
|
2002
|
-
designTokens
|
|
2003
|
-
});
|
|
2004
|
-
if (pluginArgs?.length) return handlerFunction(...pluginArgs);
|
|
2005
|
-
if (!metadata || !tokens.length) return handlerFunction(ctx, ctx.clearRequest);
|
|
2006
|
-
const args = [];
|
|
2007
|
-
for (const token of tokens) {
|
|
2008
|
-
const resolved = await Container.resolve(token, ctx, Boolean(this.config.container?.autoDiscover));
|
|
2009
|
-
if (typeof resolved === "undefined") return handlerFunction(ctx, ctx.clearRequest);
|
|
2010
|
-
args.push(resolved);
|
|
2011
|
-
}
|
|
2012
|
-
return handlerFunction(...args);
|
|
2013
|
-
});
|
|
2014
|
-
}
|
|
2015
|
-
static bindRequestToInstance(ctx, instance, route, payload) {
|
|
2016
|
-
const clearRequest = ctx.clearRequest instanceof Request ? ctx.clearRequest : this.initializeInstance(Request, {
|
|
2017
|
-
ctx,
|
|
2018
|
-
route,
|
|
2019
|
-
body: payload.body,
|
|
2020
|
-
query: payload.query,
|
|
2021
|
-
params: payload.params,
|
|
2022
|
-
method: String(payload.method || ctx.req?.method || ctx.method || "GET").toUpperCase(),
|
|
2023
|
-
path: String(ctx.path || ctx.req?.path || ctx.req?.url || route.path),
|
|
2024
|
-
url: String(ctx.url || ctx.req?.url || ctx.req?.originalUrl || route.path),
|
|
2025
|
-
headers: ctx.req?.headers || ctx.headers || {},
|
|
2026
|
-
original: ctx.req || ctx.request || ctx
|
|
2027
|
-
});
|
|
2028
|
-
clearRequest.ctx = ctx;
|
|
2029
|
-
clearRequest.route = route;
|
|
2030
|
-
clearRequest.body = payload.body;
|
|
2031
|
-
clearRequest.query = payload.query;
|
|
2032
|
-
clearRequest.params = payload.params;
|
|
2033
|
-
ctx.clearRequest = clearRequest;
|
|
2034
|
-
Container.bind(Request, ctx.clearRequest);
|
|
2035
|
-
if (!(ctx.clearResponse instanceof Response)) {
|
|
2036
|
-
ctx.clearResponse = this.initializeInstance(Response, ctx.response ?? ctx.reply ?? ctx.res);
|
|
2037
|
-
Container.bind(Response, ctx.clearResponse);
|
|
2038
|
-
}
|
|
2039
|
-
if (!instance) return;
|
|
2040
|
-
instance.ctx = ctx;
|
|
2041
|
-
instance.body = payload.body;
|
|
2042
|
-
instance.query = payload.query;
|
|
2043
|
-
instance.params = payload.params;
|
|
2044
|
-
instance.clearRequest = clearRequest;
|
|
2045
|
-
}
|
|
2046
|
-
};
|
|
2047
|
-
/**
|
|
2048
|
-
* Expose the active request's route through the `Route` facade (`Route.current()`,
|
|
2049
|
-
* `Route.currentRouteName()`, `Route.currentRouteAction()`) by delegating to the
|
|
2050
|
-
* shared router request context.
|
|
2051
|
-
*/
|
|
2052
|
-
Route.bindCurrentResolvers({
|
|
2053
|
-
current: () => CoreRouter.current(),
|
|
2054
|
-
currentRouteName: () => CoreRouter.currentRouteName(),
|
|
2055
|
-
currentRouteAction: () => CoreRouter.currentRouteAction()
|
|
2056
|
-
});
|
|
2057
|
-
//#endregion
|
|
2058
|
-
//#region ../../node_modules/.pnpm/dayjs@1.11.20/node_modules/dayjs/plugin/customParseFormat.js
|
|
2059
|
-
var require_customParseFormat = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2060
|
-
(function(e, t) {
|
|
2061
|
-
"object" == typeof exports && "undefined" != typeof module ? module.exports = t() : "function" == typeof define && define.amd ? define(t) : (e = "undefined" != typeof globalThis ? globalThis : e || self).dayjs_plugin_customParseFormat = t();
|
|
2062
|
-
})(exports, (function() {
|
|
2063
|
-
"use strict";
|
|
2064
|
-
var e = {
|
|
2065
|
-
LTS: "h:mm:ss A",
|
|
2066
|
-
LT: "h:mm A",
|
|
2067
|
-
L: "MM/DD/YYYY",
|
|
2068
|
-
LL: "MMMM D, YYYY",
|
|
2069
|
-
LLL: "MMMM D, YYYY h:mm A",
|
|
2070
|
-
LLLL: "dddd, MMMM D, YYYY h:mm A"
|
|
2071
|
-
}, t = /(\[[^[]*\])|([-_:/.,()\s]+)|(A|a|Q|YYYY|YY?|ww?|MM?M?M?|Do|DD?|hh?|HH?|mm?|ss?|S{1,3}|z|ZZ?)/g, n = /\d/, r = /\d\d/, i = /\d\d?/, o = /\d*[^-_:/,()\s\d]+/, s = {}, a = function(e) {
|
|
2072
|
-
return (e = +e) + (e > 68 ? 1900 : 2e3);
|
|
2073
|
-
};
|
|
2074
|
-
var f = function(e) {
|
|
2075
|
-
return function(t) {
|
|
2076
|
-
this[e] = +t;
|
|
2077
|
-
};
|
|
2078
|
-
}, h = [/[+-]\d\d:?(\d\d)?|Z/, function(e) {
|
|
2079
|
-
(this.zone || (this.zone = {})).offset = function(e) {
|
|
2080
|
-
if (!e) return 0;
|
|
2081
|
-
if ("Z" === e) return 0;
|
|
2082
|
-
var t = e.match(/([+-]|\d\d)/g), n = 60 * t[1] + (+t[2] || 0);
|
|
2083
|
-
return 0 === n ? 0 : "+" === t[0] ? -n : n;
|
|
2084
|
-
}(e);
|
|
2085
|
-
}], u = function(e) {
|
|
2086
|
-
var t = s[e];
|
|
2087
|
-
return t && (t.indexOf ? t : t.s.concat(t.f));
|
|
2088
|
-
}, d = function(e, t) {
|
|
2089
|
-
var n, r = s.meridiem;
|
|
2090
|
-
if (r) {
|
|
2091
|
-
for (var i = 1; i <= 24; i += 1) if (e.indexOf(r(i, 0, t)) > -1) {
|
|
2092
|
-
n = i > 12;
|
|
2093
|
-
break;
|
|
2094
|
-
}
|
|
2095
|
-
} else n = e === (t ? "pm" : "PM");
|
|
2096
|
-
return n;
|
|
2097
|
-
}, c = {
|
|
2098
|
-
A: [o, function(e) {
|
|
2099
|
-
this.afternoon = d(e, !1);
|
|
2100
|
-
}],
|
|
2101
|
-
a: [o, function(e) {
|
|
2102
|
-
this.afternoon = d(e, !0);
|
|
2103
|
-
}],
|
|
2104
|
-
Q: [n, function(e) {
|
|
2105
|
-
this.month = 3 * (e - 1) + 1;
|
|
2106
|
-
}],
|
|
2107
|
-
S: [n, function(e) {
|
|
2108
|
-
this.milliseconds = 100 * +e;
|
|
2109
|
-
}],
|
|
2110
|
-
SS: [r, function(e) {
|
|
2111
|
-
this.milliseconds = 10 * +e;
|
|
2112
|
-
}],
|
|
2113
|
-
SSS: [/\d{3}/, function(e) {
|
|
2114
|
-
this.milliseconds = +e;
|
|
2115
|
-
}],
|
|
2116
|
-
s: [i, f("seconds")],
|
|
2117
|
-
ss: [i, f("seconds")],
|
|
2118
|
-
m: [i, f("minutes")],
|
|
2119
|
-
mm: [i, f("minutes")],
|
|
2120
|
-
H: [i, f("hours")],
|
|
2121
|
-
h: [i, f("hours")],
|
|
2122
|
-
HH: [i, f("hours")],
|
|
2123
|
-
hh: [i, f("hours")],
|
|
2124
|
-
D: [i, f("day")],
|
|
2125
|
-
DD: [r, f("day")],
|
|
2126
|
-
Do: [o, function(e) {
|
|
2127
|
-
var t = s.ordinal, n = e.match(/\d+/);
|
|
2128
|
-
if (this.day = n[0], t) for (var r = 1; r <= 31; r += 1) t(r).replace(/\[|\]/g, "") === e && (this.day = r);
|
|
2129
|
-
}],
|
|
2130
|
-
w: [i, f("week")],
|
|
2131
|
-
ww: [r, f("week")],
|
|
2132
|
-
M: [i, f("month")],
|
|
2133
|
-
MM: [r, f("month")],
|
|
2134
|
-
MMM: [o, function(e) {
|
|
2135
|
-
var t = u("months"), n = (u("monthsShort") || t.map((function(e) {
|
|
2136
|
-
return e.slice(0, 3);
|
|
2137
|
-
}))).indexOf(e) + 1;
|
|
2138
|
-
if (n < 1) throw new Error();
|
|
2139
|
-
this.month = n % 12 || n;
|
|
2140
|
-
}],
|
|
2141
|
-
MMMM: [o, function(e) {
|
|
2142
|
-
var t = u("months").indexOf(e) + 1;
|
|
2143
|
-
if (t < 1) throw new Error();
|
|
2144
|
-
this.month = t % 12 || t;
|
|
2145
|
-
}],
|
|
2146
|
-
Y: [/[+-]?\d+/, f("year")],
|
|
2147
|
-
YY: [r, function(e) {
|
|
2148
|
-
this.year = a(e);
|
|
2149
|
-
}],
|
|
2150
|
-
YYYY: [/\d{4}/, f("year")],
|
|
2151
|
-
Z: h,
|
|
2152
|
-
ZZ: h
|
|
2153
|
-
};
|
|
2154
|
-
function l(n) {
|
|
2155
|
-
var r = n, i = s && s.formats;
|
|
2156
|
-
for (var o = (n = r.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g, (function(t, n, r) {
|
|
2157
|
-
var o = r && r.toUpperCase();
|
|
2158
|
-
return n || i[r] || e[r] || i[o].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g, (function(e, t, n) {
|
|
2159
|
-
return t || n.slice(1);
|
|
2160
|
-
}));
|
|
2161
|
-
}))).match(t), a = o.length, f = 0; f < a; f += 1) {
|
|
2162
|
-
var h = o[f], u = c[h], d = u && u[0], l = u && u[1];
|
|
2163
|
-
o[f] = l ? {
|
|
2164
|
-
regex: d,
|
|
2165
|
-
parser: l
|
|
2166
|
-
} : h.replace(/^\[|\]$/g, "");
|
|
2167
|
-
}
|
|
2168
|
-
return function(e) {
|
|
2169
|
-
for (var t = {}, n = 0, r = 0; n < a; n += 1) {
|
|
2170
|
-
var i = o[n];
|
|
2171
|
-
if ("string" == typeof i) r += i.length;
|
|
2172
|
-
else {
|
|
2173
|
-
var s = i.regex, f = i.parser, h = e.slice(r), u = s.exec(h)[0];
|
|
2174
|
-
f.call(t, u), e = e.replace(u, "");
|
|
2175
|
-
}
|
|
2176
|
-
}
|
|
2177
|
-
return function(e) {
|
|
2178
|
-
var t = e.afternoon;
|
|
2179
|
-
if (void 0 !== t) {
|
|
2180
|
-
var n = e.hours;
|
|
2181
|
-
t ? n < 12 && (e.hours += 12) : 12 === n && (e.hours = 0), delete e.afternoon;
|
|
2182
|
-
}
|
|
2183
|
-
}(t), t;
|
|
2184
|
-
};
|
|
2185
|
-
}
|
|
2186
|
-
return function(e, t, n) {
|
|
2187
|
-
n.p.customParseFormat = !0, e && e.parseTwoDigitYear && (a = e.parseTwoDigitYear);
|
|
2188
|
-
var r = t.prototype, i = r.parse;
|
|
2189
|
-
r.parse = function(e) {
|
|
2190
|
-
var t = e.date, r = e.utc, o = e.args;
|
|
2191
|
-
this.$u = r;
|
|
2192
|
-
var a = o[1];
|
|
2193
|
-
if ("string" == typeof a) {
|
|
2194
|
-
var f = !0 === o[2], h = !0 === o[3], u = f || h, d = o[2];
|
|
2195
|
-
h && (d = o[2]), s = this.$locale(), !f && d && (s = n.Ls[d]), this.$d = function(e, t, n, r) {
|
|
2196
|
-
try {
|
|
2197
|
-
if (["x", "X"].indexOf(t) > -1) return /* @__PURE__ */ new Date(("X" === t ? 1e3 : 1) * e);
|
|
2198
|
-
var i = l(t)(e), o = i.year, s = i.month, a = i.day, f = i.hours, h = i.minutes, u = i.seconds, d = i.milliseconds, c = i.zone, m = i.week, M = /* @__PURE__ */ new Date(), Y = a || (o || s ? 1 : M.getDate()), p = o || M.getFullYear(), v = 0;
|
|
2199
|
-
o && !s || (v = s > 0 ? s - 1 : M.getMonth());
|
|
2200
|
-
var D, w = f || 0, g = h || 0, y = u || 0, L = d || 0;
|
|
2201
|
-
return c ? new Date(Date.UTC(p, v, Y, w, g, y, L + 60 * c.offset * 1e3)) : n ? new Date(Date.UTC(p, v, Y, w, g, y, L)) : (D = new Date(p, v, Y, w, g, y, L), m && (D = r(D).week(m).toDate()), D);
|
|
2202
|
-
} catch (e) {
|
|
2203
|
-
return /* @__PURE__ */ new Date("");
|
|
2204
|
-
}
|
|
2205
|
-
}(t, a, r, n), this.init(), d && !0 !== d && (this.$L = this.locale(d).$L), u && t != this.format(a) && (this.$d = /* @__PURE__ */ new Date("")), s = {};
|
|
2206
|
-
} else if (a instanceof Array) for (var c = a.length, m = 1; m <= c; m += 1) {
|
|
2207
|
-
o[1] = a[m - 1];
|
|
2208
|
-
var M = n.apply(this, o);
|
|
2209
|
-
if (M.isValid()) {
|
|
2210
|
-
this.$d = M.$d, this.$L = M.$L, this.init();
|
|
2211
|
-
break;
|
|
2212
|
-
}
|
|
2213
|
-
m === c && (this.$d = /* @__PURE__ */ new Date(""));
|
|
2214
|
-
}
|
|
2215
|
-
else i.call(this, e);
|
|
2216
|
-
};
|
|
2217
|
-
};
|
|
2218
|
-
}));
|
|
2219
|
-
}));
|
|
2220
|
-
//#endregion
|
|
2221
|
-
//#region ../../node_modules/.pnpm/dayjs@1.11.20/node_modules/dayjs/dayjs.min.js
|
|
2222
|
-
var require_dayjs_min = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2223
|
-
(function(t, e) {
|
|
2224
|
-
"object" == typeof exports && "undefined" != typeof module ? module.exports = e() : "function" == typeof define && define.amd ? define(e) : (t = "undefined" != typeof globalThis ? globalThis : t || self).dayjs = e();
|
|
2225
|
-
})(exports, (function() {
|
|
2226
|
-
"use strict";
|
|
2227
|
-
var t = 1e3, e = 6e4, n = 36e5, r = "millisecond", i = "second", s = "minute", u = "hour", a = "day", o = "week", c = "month", f = "quarter", h = "year", d = "date", l = "Invalid Date", $ = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, y = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, M = {
|
|
2228
|
-
name: "en",
|
|
2229
|
-
weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),
|
|
2230
|
-
months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"),
|
|
2231
|
-
ordinal: function(t) {
|
|
2232
|
-
var e = [
|
|
2233
|
-
"th",
|
|
2234
|
-
"st",
|
|
2235
|
-
"nd",
|
|
2236
|
-
"rd"
|
|
2237
|
-
], n = t % 100;
|
|
2238
|
-
return "[" + t + (e[(n - 20) % 10] || e[n] || e[0]) + "]";
|
|
2239
|
-
}
|
|
2240
|
-
}, m = function(t, e, n) {
|
|
2241
|
-
var r = String(t);
|
|
2242
|
-
return !r || r.length >= e ? t : "" + Array(e + 1 - r.length).join(n) + t;
|
|
2243
|
-
}, v = {
|
|
2244
|
-
s: m,
|
|
2245
|
-
z: function(t) {
|
|
2246
|
-
var e = -t.utcOffset(), n = Math.abs(e), r = Math.floor(n / 60), i = n % 60;
|
|
2247
|
-
return (e <= 0 ? "+" : "-") + m(r, 2, "0") + ":" + m(i, 2, "0");
|
|
2248
|
-
},
|
|
2249
|
-
m: function t(e, n) {
|
|
2250
|
-
if (e.date() < n.date()) return -t(n, e);
|
|
2251
|
-
var r = 12 * (n.year() - e.year()) + (n.month() - e.month()), i = e.clone().add(r, c), s = n - i < 0, u = e.clone().add(r + (s ? -1 : 1), c);
|
|
2252
|
-
return +(-(r + (n - i) / (s ? i - u : u - i)) || 0);
|
|
2253
|
-
},
|
|
2254
|
-
a: function(t) {
|
|
2255
|
-
return t < 0 ? Math.ceil(t) || 0 : Math.floor(t);
|
|
2256
|
-
},
|
|
2257
|
-
p: function(t) {
|
|
2258
|
-
return {
|
|
2259
|
-
M: c,
|
|
2260
|
-
y: h,
|
|
2261
|
-
w: o,
|
|
2262
|
-
d: a,
|
|
2263
|
-
D: d,
|
|
2264
|
-
h: u,
|
|
2265
|
-
m: s,
|
|
2266
|
-
s: i,
|
|
2267
|
-
ms: r,
|
|
2268
|
-
Q: f
|
|
2269
|
-
}[t] || String(t || "").toLowerCase().replace(/s$/, "");
|
|
2270
|
-
},
|
|
2271
|
-
u: function(t) {
|
|
2272
|
-
return void 0 === t;
|
|
2273
|
-
}
|
|
2274
|
-
}, g = "en", D = {};
|
|
2275
|
-
D[g] = M;
|
|
2276
|
-
var p = "$isDayjsObject", S = function(t) {
|
|
2277
|
-
return t instanceof _ || !(!t || !t[p]);
|
|
2278
|
-
}, w = function t(e, n, r) {
|
|
2279
|
-
var i;
|
|
2280
|
-
if (!e) return g;
|
|
2281
|
-
if ("string" == typeof e) {
|
|
2282
|
-
var s = e.toLowerCase();
|
|
2283
|
-
D[s] && (i = s), n && (D[s] = n, i = s);
|
|
2284
|
-
var u = e.split("-");
|
|
2285
|
-
if (!i && u.length > 1) return t(u[0]);
|
|
2286
|
-
} else {
|
|
2287
|
-
var a = e.name;
|
|
2288
|
-
D[a] = e, i = a;
|
|
2289
|
-
}
|
|
2290
|
-
return !r && i && (g = i), i || !r && g;
|
|
2291
|
-
}, O = function(t, e) {
|
|
2292
|
-
if (S(t)) return t.clone();
|
|
2293
|
-
var n = "object" == typeof e ? e : {};
|
|
2294
|
-
return n.date = t, n.args = arguments, new _(n);
|
|
2295
|
-
}, b = v;
|
|
2296
|
-
b.l = w, b.i = S, b.w = function(t, e) {
|
|
2297
|
-
return O(t, {
|
|
2298
|
-
locale: e.$L,
|
|
2299
|
-
utc: e.$u,
|
|
2300
|
-
x: e.$x,
|
|
2301
|
-
$offset: e.$offset
|
|
2302
|
-
});
|
|
2303
|
-
};
|
|
2304
|
-
var _ = function() {
|
|
2305
|
-
function M(t) {
|
|
2306
|
-
this.$L = w(t.locale, null, !0), this.parse(t), this.$x = this.$x || t.x || {}, this[p] = !0;
|
|
2307
|
-
}
|
|
2308
|
-
var m = M.prototype;
|
|
2309
|
-
return m.parse = function(t) {
|
|
2310
|
-
this.$d = function(t) {
|
|
2311
|
-
var e = t.date, n = t.utc;
|
|
2312
|
-
if (null === e) return /* @__PURE__ */ new Date(NaN);
|
|
2313
|
-
if (b.u(e)) return /* @__PURE__ */ new Date();
|
|
2314
|
-
if (e instanceof Date) return new Date(e);
|
|
2315
|
-
if ("string" == typeof e && !/Z$/i.test(e)) {
|
|
2316
|
-
var r = e.match($);
|
|
2317
|
-
if (r) {
|
|
2318
|
-
var i = r[2] - 1 || 0, s = (r[7] || "0").substring(0, 3);
|
|
2319
|
-
return n ? new Date(Date.UTC(r[1], i, r[3] || 1, r[4] || 0, r[5] || 0, r[6] || 0, s)) : new Date(r[1], i, r[3] || 1, r[4] || 0, r[5] || 0, r[6] || 0, s);
|
|
2320
|
-
}
|
|
2321
|
-
}
|
|
2322
|
-
return new Date(e);
|
|
2323
|
-
}(t), this.init();
|
|
2324
|
-
}, m.init = function() {
|
|
2325
|
-
var t = this.$d;
|
|
2326
|
-
this.$y = t.getFullYear(), this.$M = t.getMonth(), this.$D = t.getDate(), this.$W = t.getDay(), this.$H = t.getHours(), this.$m = t.getMinutes(), this.$s = t.getSeconds(), this.$ms = t.getMilliseconds();
|
|
2327
|
-
}, m.$utils = function() {
|
|
2328
|
-
return b;
|
|
2329
|
-
}, m.isValid = function() {
|
|
2330
|
-
return !(this.$d.toString() === l);
|
|
2331
|
-
}, m.isSame = function(t, e) {
|
|
2332
|
-
var n = O(t);
|
|
2333
|
-
return this.startOf(e) <= n && n <= this.endOf(e);
|
|
2334
|
-
}, m.isAfter = function(t, e) {
|
|
2335
|
-
return O(t) < this.startOf(e);
|
|
2336
|
-
}, m.isBefore = function(t, e) {
|
|
2337
|
-
return this.endOf(e) < O(t);
|
|
2338
|
-
}, m.$g = function(t, e, n) {
|
|
2339
|
-
return b.u(t) ? this[e] : this.set(n, t);
|
|
2340
|
-
}, m.unix = function() {
|
|
2341
|
-
return Math.floor(this.valueOf() / 1e3);
|
|
2342
|
-
}, m.valueOf = function() {
|
|
2343
|
-
return this.$d.getTime();
|
|
2344
|
-
}, m.startOf = function(t, e) {
|
|
2345
|
-
var n = this, r = !!b.u(e) || e, f = b.p(t), l = function(t, e) {
|
|
2346
|
-
var i = b.w(n.$u ? Date.UTC(n.$y, e, t) : new Date(n.$y, e, t), n);
|
|
2347
|
-
return r ? i : i.endOf(a);
|
|
2348
|
-
}, $ = function(t, e) {
|
|
2349
|
-
return b.w(n.toDate()[t].apply(n.toDate("s"), (r ? [
|
|
2350
|
-
0,
|
|
2351
|
-
0,
|
|
2352
|
-
0,
|
|
2353
|
-
0
|
|
2354
|
-
] : [
|
|
2355
|
-
23,
|
|
2356
|
-
59,
|
|
2357
|
-
59,
|
|
2358
|
-
999
|
|
2359
|
-
]).slice(e)), n);
|
|
2360
|
-
}, y = this.$W, M = this.$M, m = this.$D, v = "set" + (this.$u ? "UTC" : "");
|
|
2361
|
-
switch (f) {
|
|
2362
|
-
case h: return r ? l(1, 0) : l(31, 11);
|
|
2363
|
-
case c: return r ? l(1, M) : l(0, M + 1);
|
|
2364
|
-
case o:
|
|
2365
|
-
var g = this.$locale().weekStart || 0, D = (y < g ? y + 7 : y) - g;
|
|
2366
|
-
return l(r ? m - D : m + (6 - D), M);
|
|
2367
|
-
case a:
|
|
2368
|
-
case d: return $(v + "Hours", 0);
|
|
2369
|
-
case u: return $(v + "Minutes", 1);
|
|
2370
|
-
case s: return $(v + "Seconds", 2);
|
|
2371
|
-
case i: return $(v + "Milliseconds", 3);
|
|
2372
|
-
default: return this.clone();
|
|
2373
|
-
}
|
|
2374
|
-
}, m.endOf = function(t) {
|
|
2375
|
-
return this.startOf(t, !1);
|
|
2376
|
-
}, m.$set = function(t, e) {
|
|
2377
|
-
var n, o = b.p(t), f = "set" + (this.$u ? "UTC" : ""), l = (n = {}, n[a] = f + "Date", n[d] = f + "Date", n[c] = f + "Month", n[h] = f + "FullYear", n[u] = f + "Hours", n[s] = f + "Minutes", n[i] = f + "Seconds", n[r] = f + "Milliseconds", n)[o], $ = o === a ? this.$D + (e - this.$W) : e;
|
|
2378
|
-
if (o === c || o === h) {
|
|
2379
|
-
var y = this.clone().set(d, 1);
|
|
2380
|
-
y.$d[l]($), y.init(), this.$d = y.set(d, Math.min(this.$D, y.daysInMonth())).$d;
|
|
2381
|
-
} else l && this.$d[l]($);
|
|
2382
|
-
return this.init(), this;
|
|
2383
|
-
}, m.set = function(t, e) {
|
|
2384
|
-
return this.clone().$set(t, e);
|
|
2385
|
-
}, m.get = function(t) {
|
|
2386
|
-
return this[b.p(t)]();
|
|
2387
|
-
}, m.add = function(r, f) {
|
|
2388
|
-
var d, l = this;
|
|
2389
|
-
r = Number(r);
|
|
2390
|
-
var $ = b.p(f), y = function(t) {
|
|
2391
|
-
var e = O(l);
|
|
2392
|
-
return b.w(e.date(e.date() + Math.round(t * r)), l);
|
|
2393
|
-
};
|
|
2394
|
-
if ($ === c) return this.set(c, this.$M + r);
|
|
2395
|
-
if ($ === h) return this.set(h, this.$y + r);
|
|
2396
|
-
if ($ === a) return y(1);
|
|
2397
|
-
if ($ === o) return y(7);
|
|
2398
|
-
var M = (d = {}, d[s] = e, d[u] = n, d[i] = t, d)[$] || 1, m = this.$d.getTime() + r * M;
|
|
2399
|
-
return b.w(m, this);
|
|
2400
|
-
}, m.subtract = function(t, e) {
|
|
2401
|
-
return this.add(-1 * t, e);
|
|
2402
|
-
}, m.format = function(t) {
|
|
2403
|
-
var e = this, n = this.$locale();
|
|
2404
|
-
if (!this.isValid()) return n.invalidDate || l;
|
|
2405
|
-
var r = t || "YYYY-MM-DDTHH:mm:ssZ", i = b.z(this), s = this.$H, u = this.$m, a = this.$M, o = n.weekdays, c = n.months, f = n.meridiem, h = function(t, n, i, s) {
|
|
2406
|
-
return t && (t[n] || t(e, r)) || i[n].slice(0, s);
|
|
2407
|
-
}, d = function(t) {
|
|
2408
|
-
return b.s(s % 12 || 12, t, "0");
|
|
2409
|
-
}, $ = f || function(t, e, n) {
|
|
2410
|
-
var r = t < 12 ? "AM" : "PM";
|
|
2411
|
-
return n ? r.toLowerCase() : r;
|
|
2412
|
-
};
|
|
2413
|
-
return r.replace(y, (function(t, r) {
|
|
2414
|
-
return r || function(t) {
|
|
2415
|
-
switch (t) {
|
|
2416
|
-
case "YY": return String(e.$y).slice(-2);
|
|
2417
|
-
case "YYYY": return b.s(e.$y, 4, "0");
|
|
2418
|
-
case "M": return a + 1;
|
|
2419
|
-
case "MM": return b.s(a + 1, 2, "0");
|
|
2420
|
-
case "MMM": return h(n.monthsShort, a, c, 3);
|
|
2421
|
-
case "MMMM": return h(c, a);
|
|
2422
|
-
case "D": return e.$D;
|
|
2423
|
-
case "DD": return b.s(e.$D, 2, "0");
|
|
2424
|
-
case "d": return String(e.$W);
|
|
2425
|
-
case "dd": return h(n.weekdaysMin, e.$W, o, 2);
|
|
2426
|
-
case "ddd": return h(n.weekdaysShort, e.$W, o, 3);
|
|
2427
|
-
case "dddd": return o[e.$W];
|
|
2428
|
-
case "H": return String(s);
|
|
2429
|
-
case "HH": return b.s(s, 2, "0");
|
|
2430
|
-
case "h": return d(1);
|
|
2431
|
-
case "hh": return d(2);
|
|
2432
|
-
case "a": return $(s, u, !0);
|
|
2433
|
-
case "A": return $(s, u, !1);
|
|
2434
|
-
case "m": return String(u);
|
|
2435
|
-
case "mm": return b.s(u, 2, "0");
|
|
2436
|
-
case "s": return String(e.$s);
|
|
2437
|
-
case "ss": return b.s(e.$s, 2, "0");
|
|
2438
|
-
case "SSS": return b.s(e.$ms, 3, "0");
|
|
2439
|
-
case "Z": return i;
|
|
2440
|
-
}
|
|
2441
|
-
return null;
|
|
2442
|
-
}(t) || i.replace(":", "");
|
|
2443
|
-
}));
|
|
2444
|
-
}, m.utcOffset = function() {
|
|
2445
|
-
return 15 * -Math.round(this.$d.getTimezoneOffset() / 15);
|
|
2446
|
-
}, m.diff = function(r, d, l) {
|
|
2447
|
-
var $, y = this, M = b.p(d), m = O(r), v = (m.utcOffset() - this.utcOffset()) * e, g = this - m, D = function() {
|
|
2448
|
-
return b.m(y, m);
|
|
2449
|
-
};
|
|
2450
|
-
switch (M) {
|
|
2451
|
-
case h:
|
|
2452
|
-
$ = D() / 12;
|
|
2453
|
-
break;
|
|
2454
|
-
case c:
|
|
2455
|
-
$ = D();
|
|
2456
|
-
break;
|
|
2457
|
-
case f:
|
|
2458
|
-
$ = D() / 3;
|
|
2459
|
-
break;
|
|
2460
|
-
case o:
|
|
2461
|
-
$ = (g - v) / 6048e5;
|
|
2462
|
-
break;
|
|
2463
|
-
case a:
|
|
2464
|
-
$ = (g - v) / 864e5;
|
|
2465
|
-
break;
|
|
2466
|
-
case u:
|
|
2467
|
-
$ = g / n;
|
|
2468
|
-
break;
|
|
2469
|
-
case s:
|
|
2470
|
-
$ = g / e;
|
|
2471
|
-
break;
|
|
2472
|
-
case i:
|
|
2473
|
-
$ = g / t;
|
|
2474
|
-
break;
|
|
2475
|
-
default: $ = g;
|
|
2476
|
-
}
|
|
2477
|
-
return l ? $ : b.a($);
|
|
2478
|
-
}, m.daysInMonth = function() {
|
|
2479
|
-
return this.endOf(c).$D;
|
|
2480
|
-
}, m.$locale = function() {
|
|
2481
|
-
return D[this.$L];
|
|
2482
|
-
}, m.locale = function(t, e) {
|
|
2483
|
-
if (!t) return this.$L;
|
|
2484
|
-
var n = this.clone(), r = w(t, e, !0);
|
|
2485
|
-
return r && (n.$L = r), n;
|
|
2486
|
-
}, m.clone = function() {
|
|
2487
|
-
return b.w(this.$d, this);
|
|
2488
|
-
}, m.toDate = function() {
|
|
2489
|
-
return new Date(this.valueOf());
|
|
2490
|
-
}, m.toJSON = function() {
|
|
2491
|
-
return this.isValid() ? this.toISOString() : null;
|
|
2492
|
-
}, m.toISOString = function() {
|
|
2493
|
-
return this.$d.toISOString();
|
|
2494
|
-
}, m.toString = function() {
|
|
2495
|
-
return this.$d.toUTCString();
|
|
2496
|
-
}, M;
|
|
2497
|
-
}(), k = _.prototype;
|
|
2498
|
-
return O.prototype = k, [
|
|
2499
|
-
["$ms", r],
|
|
2500
|
-
["$s", i],
|
|
2501
|
-
["$m", s],
|
|
2502
|
-
["$H", u],
|
|
2503
|
-
["$W", a],
|
|
2504
|
-
["$M", c],
|
|
2505
|
-
["$y", h],
|
|
2506
|
-
["$D", d]
|
|
2507
|
-
].forEach((function(t) {
|
|
2508
|
-
k[t[1]] = function(e) {
|
|
2509
|
-
return this.$g(e, t[0], t[1]);
|
|
2510
|
-
};
|
|
2511
|
-
})), O.extend = function(t, e) {
|
|
2512
|
-
return t.$i || (t(e, _, O), t.$i = !0), O;
|
|
2513
|
-
}, O.locale = w, O.isDayjs = S, O.unix = function(t) {
|
|
2514
|
-
return O(1e3 * t);
|
|
2515
|
-
}, O.en = D[g], O.Ls = D, O.p = {}, O;
|
|
2516
|
-
}));
|
|
2517
|
-
}));
|
|
2518
|
-
//#endregion
|
|
2519
|
-
//#region ../../node_modules/.pnpm/kanun@1.2.0/node_modules/kanun/dist/index.js
|
|
2520
|
-
var import_customParseFormat = /* @__PURE__ */ __toESM(require_customParseFormat(), 1);
|
|
2521
|
-
var import_dayjs_min = /* @__PURE__ */ __toESM(require_dayjs_min(), 1);
|
|
2522
|
-
new AsyncLocalStorage();
|
|
2523
|
-
var locales_default = {
|
|
2524
|
-
en: {
|
|
2525
|
-
accepted: "The :attribute must be accepted.",
|
|
2526
|
-
accepted_if: "The :attribute must be accepted when :other is :value.",
|
|
2527
|
-
after: "The :attribute must be a date after :date.",
|
|
2528
|
-
after_or_equal: "The :attribute must be a date after or equal to :date.",
|
|
2529
|
-
alpha: "The :attribute must only contain letters.",
|
|
2530
|
-
alpha_dash: "The :attribute must only contain at least one letter or one number, and optionally dashes and underscores.",
|
|
2531
|
-
alpha_num: "The :attribute must only contain letters and numbers.",
|
|
2532
|
-
array: "The :attribute must be an array.",
|
|
2533
|
-
array_unique: "The :attribute must be an array with unique values.",
|
|
2534
|
-
before: "The :attribute must be a date before :date.",
|
|
2535
|
-
before_or_equal: "The :attribute must be a date before or equal to :date.",
|
|
2536
|
-
between: {
|
|
2537
|
-
number: "The :attribute must be between :min and :max.",
|
|
2538
|
-
string: "The :attribute must be between :min and :max characters.",
|
|
2539
|
-
array: "The :attribute must have between :min and :max items.",
|
|
2540
|
-
object: "The :attribute must have between :min and :max items."
|
|
2541
|
-
},
|
|
2542
|
-
boolean: "The :attribute field must be true or false.",
|
|
2543
|
-
confirmed: "The :attribute confirmation does not match.",
|
|
2544
|
-
date: "The :attribute is not a valid date.",
|
|
2545
|
-
datetime: "The :attribute must be a valid date matching the format :format.",
|
|
2546
|
-
date_equals: "The :attribute must be a date equal to :date.",
|
|
2547
|
-
declined: "The :attribute must be declined.",
|
|
2548
|
-
declined_if: "The :attribute must be declined when :other is :value.",
|
|
2549
|
-
different: "The :attribute and :other must be different.",
|
|
2550
|
-
distinct: "The :attribute field has a duplicate value.",
|
|
2551
|
-
digits: "The :attribute must be :digits digits.",
|
|
2552
|
-
digits_between: "The :attribute must be between :min and :max digits.",
|
|
2553
|
-
email: "The :attribute must be a valid email address.",
|
|
2554
|
-
ends_with: "The :attribute must end with one of the following: :values.",
|
|
2555
|
-
filled: "The :attribute field must have a value.",
|
|
2556
|
-
exists: "The selected :attribute is invalid.",
|
|
2557
|
-
gt: {
|
|
2558
|
-
number: "The :attribute must be greater than :value.",
|
|
2559
|
-
string: "The :attribute must be greater than :value characters.",
|
|
2560
|
-
array: "The :attribute must have more than :value items.",
|
|
2561
|
-
object: "The :attribute must have more than :value items."
|
|
2562
|
-
},
|
|
2563
|
-
gte: {
|
|
2564
|
-
number: "The :attribute must be greater than or equal :value.",
|
|
2565
|
-
string: "The :attribute must be greater than or equal :value characters.",
|
|
2566
|
-
array: "The :attribute must have :value items or more.",
|
|
2567
|
-
object: "The :attribute must have :value items or more."
|
|
2568
|
-
},
|
|
2569
|
-
hex: "The :attribute must be a valid hexadecimal color.",
|
|
2570
|
-
in: "The :attribute must be one of the following :values.",
|
|
2571
|
-
includes: "The :attribute must include one of the following values: :values.",
|
|
2572
|
-
integer: "The :attribute must be an integer.",
|
|
2573
|
-
ip: "The :attribute must be a valid IP address.",
|
|
2574
|
-
ipv4: "The :attribute must be a valid IPv4 address.",
|
|
2575
|
-
ipv6: "The :attribute must be a valid IPv6 address.",
|
|
2576
|
-
json: "The :attribute must be a valid JSON string.",
|
|
2577
|
-
lt: {
|
|
2578
|
-
number: "The :attribute must be less than :value.",
|
|
2579
|
-
string: "The :attribute must be less than :value characters.",
|
|
2580
|
-
array: "The :attribute must have less than :value items.",
|
|
2581
|
-
object: "The :attribute must have less than :value items."
|
|
2582
|
-
},
|
|
2583
|
-
lte: {
|
|
2584
|
-
number: "The :attribute must be less than or equal :value.",
|
|
2585
|
-
string: "The :attribute must be less than or equal :value characters.",
|
|
2586
|
-
array: "The :attribute must have :value items or less.",
|
|
2587
|
-
object: "The :attribute must have :value items or less."
|
|
2588
|
-
},
|
|
2589
|
-
max: {
|
|
2590
|
-
number: "The :attribute must not be greater than :max.",
|
|
2591
|
-
string: "The :attribute must not be greater than :max characters.",
|
|
2592
|
-
array: "The :attribute must not have more than :max items.",
|
|
2593
|
-
object: "The :attribute must not have more than :max items."
|
|
2594
|
-
},
|
|
2595
|
-
min: {
|
|
2596
|
-
number: "The :attribute must be at least :min.",
|
|
2597
|
-
string: "The :attribute must be at least :min characters.",
|
|
2598
|
-
array: "The :attribute must have at least :min items.",
|
|
2599
|
-
object: "The :attribute must have at least :min items."
|
|
2600
|
-
},
|
|
2601
|
-
mac_address: "The :attribute must be a valid MAC address.",
|
|
2602
|
-
not_in: "The selected :attribute is invalid.",
|
|
2603
|
-
not_regex: "The :attribute format is invalid.",
|
|
2604
|
-
not_includes: "The :attribute must not include any of the following values: :values.",
|
|
2605
|
-
numeric: "The :attribute must be a number.",
|
|
2606
|
-
object: "The :attribute must be an object.",
|
|
2607
|
-
password: {
|
|
2608
|
-
letter: "The :attribute must contain at least one letter.",
|
|
2609
|
-
letters: "The :attribute must contain at least :amount letters.",
|
|
2610
|
-
lower_case: "The :attribute must contain at least one lowercase letter.",
|
|
2611
|
-
lower_cases: "The :attribute must contain at least :amount lowercase letters.",
|
|
2612
|
-
number: "The :attribute must contain at least one number.",
|
|
2613
|
-
numbers: "The :attribute must contain at least :amount numbers.",
|
|
2614
|
-
symbol: "The :attribute must contain at least one symbol.",
|
|
2615
|
-
symbols: "The :attribute must contain at least :amount symbols.",
|
|
2616
|
-
upper_case: "The :attribute must contain at least one uppercase letter.",
|
|
2617
|
-
upper_cases: "The :attribute must contain at least :amount uppercase letters."
|
|
2618
|
-
},
|
|
2619
|
-
present: "The :attribute field must be present.",
|
|
2620
|
-
presentsame: "The :attribute field must be present.",
|
|
2621
|
-
prohibited: "The :attribute field is prohibited.",
|
|
2622
|
-
prohibited_unless: "The :attribute field is prohibited unless :other is in :values.",
|
|
2623
|
-
prohibits: "The :attribute field prohibits :values from being present.",
|
|
2624
|
-
regex: "The :attribute format is invalid.",
|
|
2625
|
-
required: "The :attribute field is required.",
|
|
2626
|
-
required_if: "The :attribute field is required when :other is :value.",
|
|
2627
|
-
required_unless: "The :attribute field is required unless :other is in :values.",
|
|
2628
|
-
required_with: "The :attribute field is required when :values is present.",
|
|
2629
|
-
required_with_all: "The :attribute field is required when :values are present.",
|
|
2630
|
-
required_without: "The :attribute field is required when :values is not present.",
|
|
2631
|
-
required_without_all: "The :attribute field is required when none of :values are present.",
|
|
2632
|
-
starts_with: "The :attribute must start with one of the following: :values.",
|
|
2633
|
-
same: "The :attribute and :other must match.",
|
|
2634
|
-
size: {
|
|
2635
|
-
number: "The :attribute must be :size.",
|
|
2636
|
-
string: "The :attribute must be :size characters.",
|
|
2637
|
-
array: "The :attribute must contain :size items.",
|
|
2638
|
-
object: "The :attribute must contain :size items."
|
|
2639
|
-
},
|
|
2640
|
-
string: "The :attribute must be a string.",
|
|
2641
|
-
timezone: "The :attribute must be a valid timezone.",
|
|
2642
|
-
unique: "The :attribute has already been taken.",
|
|
2643
|
-
url: "The :attribute must have a valid URL format.",
|
|
2644
|
-
multiple_of: "The :attribute must be a multiple of :value."
|
|
2645
|
-
},
|
|
2646
|
-
ar: {
|
|
2647
|
-
accepted: "يجب قبول الحقل :attribute",
|
|
2648
|
-
accepted_if: "الحقل :attribute مقبول في حال ما إذا كان :other يساوي :value.",
|
|
2649
|
-
after: "يجب على الحقل :attribute أن يكون تاريخا لاحقا للتاريخ :date.",
|
|
2650
|
-
after_or_equal: "الحقل :attribute يجب أن يكون تاريخاً لاحقاً أو مطابقاً للتاريخ :date.",
|
|
2651
|
-
alpha: "يجب أن لا يحتوي الحقل :attribute سوى على حروف",
|
|
2652
|
-
alpha_dash: "يجب أن يحتوي الحقل :attribute على حرف واحد أو رقم واحد على الأقل، بالإضافة إلى شرطات وشرطات سفلية بشكل اختياري",
|
|
2653
|
-
alpha_num: "يجب أن يحتوي :attribute على حروف وأرقام فقط",
|
|
2654
|
-
array: "يجب أن يكون الحقل :attribute ًمصفوفة",
|
|
2655
|
-
before: "يجب على الحقل :attribute أن يكون تاريخا سابقا للتاريخ :date.",
|
|
2656
|
-
before_or_equal: "الحقل :attribute يجب أن يكون تاريخا سابقا أو مطابقا للتاريخ :date",
|
|
2657
|
-
between: {
|
|
2658
|
-
number: "يجب أن تكون قيمة :attribute بين :min و :max.",
|
|
2659
|
-
string: "يجب أن يكون عدد حروف النّص :attribute بين :min و :max",
|
|
2660
|
-
array: "يجب أن يحتوي :attribute على عدد من العناصر بين :min و :max",
|
|
2661
|
-
object: "يجب أن يحتوي :attribute على عدد من العناصر بين :min و :max"
|
|
2662
|
-
},
|
|
2663
|
-
boolean: "يجب أن تكون قيمة الحقل :attribute إما true أو false",
|
|
2664
|
-
confirmed: "حقل التأكيد غير مُطابق للحقل :attribute",
|
|
2665
|
-
date: "الحقل :attribute ليس تاريخًا صحيحًا",
|
|
2666
|
-
datetime: "الحقل :attribute يجب أن يكون تاريخًا صالحًا يطابق الصيغة :format.",
|
|
2667
|
-
date_equals: "لا يساوي الحقل :attribute مع :date.",
|
|
2668
|
-
declined: "يجب رفض الحقل :attribute",
|
|
2669
|
-
declined_if: "الحقل :attribute مرفوض في حال ما إذا كان :other يساوي :value.",
|
|
2670
|
-
different: "يجب أن يكون الحقلان :attribute و :other مُختلفان",
|
|
2671
|
-
digits: "يجب أن يحتوي الحقل :attribute على :digits رقمًا/أرقام",
|
|
2672
|
-
digits_between: "يجب أن يحتوي الحقل :attribute بين :min و :max رقمًا/أرقام",
|
|
2673
|
-
email: "يجب أن يكون :attribute عنوان بريد إلكتروني صحيح البُنية",
|
|
2674
|
-
ends_with: "حقل :attribute يجب ان ينتهي بأحد القيم التالية :value.",
|
|
2675
|
-
exists: "الحقل :attribute غير موجود",
|
|
2676
|
-
gt: {
|
|
2677
|
-
number: "حقل :attribute يجب ان يكون اكبر من :value.",
|
|
2678
|
-
string: "حقل :attribute يجب ان يكون اكبر من :value حروفٍ/حرفًا.",
|
|
2679
|
-
array: "حقل :attribute يجب ان يحتوي علي اكثر من :value عناصر/عنصر.",
|
|
2680
|
-
object: "حقل :attribute يجب ان يحتوي علي اكثر من :value عناصر/عنصر."
|
|
2681
|
-
},
|
|
2682
|
-
gte: {
|
|
2683
|
-
number: "حقل :attribute يجب ان يكون اكبر من او يساوي :value.",
|
|
2684
|
-
string: "حقل :attribute يجب ان يكون اكبر من او يساوي :value حروفٍ/حرفًا.",
|
|
2685
|
-
array: "حقل :attribute يجب ان يحتوي علي :value عناصر/عنصر او اكثر.",
|
|
2686
|
-
object: "حقل :attribute يجب ان يحتوي علي :value عناصر/عنصر او اكثر."
|
|
2687
|
-
},
|
|
2688
|
-
hex: "الحقل :attribute يجب أن يكون لونًا سداسيًا صالحًا.",
|
|
2689
|
-
in: "الحقل :attribute غير صالح",
|
|
2690
|
-
includes: "الحقل :attribute يجب أن يحتوي على أحد القيم التالية: :values.",
|
|
2691
|
-
integer: "يجب أن يكون الحقل :attribute عددًا صحيحًا",
|
|
2692
|
-
json: "يجب أن يكون الحقل :attribute نصا من نوع JSON.",
|
|
2693
|
-
lt: {
|
|
2694
|
-
number: "حقل :attribute يجب ان يكون اقل من :value.",
|
|
2695
|
-
string: "حقل :attribute يجب ان يكون اقل من :value حروفٍ/حرفًا.",
|
|
2696
|
-
array: "حقل :attribute يجب ان يحتوي علي اقل من :value عناصر/عنصر.",
|
|
2697
|
-
object: "حقل :attribute يجب ان يحتوي علي اقل من :value عناصر/عنصر."
|
|
2698
|
-
},
|
|
2699
|
-
lte: {
|
|
2700
|
-
number: "حقل :attribute يجب ان يكون اقل من او يساوي :value.",
|
|
2701
|
-
string: "حقل :attribute يجب ان يكون اقل من او يساوي :value حروفٍ/حرفًا.",
|
|
2702
|
-
array: "حقل :attribute يجب ان يحتوي علي اكثر من :value عناصر/عنصر.",
|
|
2703
|
-
object: "حقل :attribute يجب ان يحتوي علي اكثر من :value عناصر/عنصر."
|
|
2704
|
-
},
|
|
2705
|
-
max: {
|
|
2706
|
-
number: "يجب أن تكون قيمة الحقل :attribute مساوية أو أصغر لـ :max.",
|
|
2707
|
-
string: "يجب أن لا يتجاوز طول نص :attribute :max حروفٍ/حرفًا",
|
|
2708
|
-
array: "يجب أن لا يحتوي الحقل :attribute على أكثر من :max عناصر/عنصر.",
|
|
2709
|
-
object: "يجب أن لا يحتوي الحقل :attribute على أكثر من :max عناصر/عنصر."
|
|
2710
|
-
},
|
|
2711
|
-
min: {
|
|
2712
|
-
number: "يجب أن تكون قيمة الحقل :attribute مساوية أو أكبر لـ :min.",
|
|
2713
|
-
string: "يجب أن يكون طول نص :attribute على الأقل :min حروفٍ/حرفًا",
|
|
2714
|
-
array: "يجب أن يحتوي الحقل :attribute على الأقل على :min عُنصرًا/عناصر",
|
|
2715
|
-
object: "يجب أن يحتوي الحقل :attribute على الأقل على :min عُنصرًا/عناصر"
|
|
2716
|
-
},
|
|
2717
|
-
not_in: "الحقل :attribute غير صالح",
|
|
2718
|
-
not_regex: "الحقل :attribute نوعه غير صالح",
|
|
2719
|
-
not_includes: "الحقل :attribute يجب ألا يحتوي على أي من القيم التالية: :values.",
|
|
2720
|
-
numeric: "يجب على الحقل :attribute أن يكون رقمًا",
|
|
2721
|
-
object: "الحقل :attribute يجب ان يكون من نوع object.",
|
|
2722
|
-
password: {
|
|
2723
|
-
letter: "يجب ان يشمل حقل :attribute على حرف واحد على الاقل.",
|
|
2724
|
-
letters: "يجب ان يشمل حقل :attribute على عدد :amount حروف على الاقل.",
|
|
2725
|
-
lower_case: "يجب ان يشمل حقل :attribute على حرف واحد من صيغة صغيرة على الاقل.",
|
|
2726
|
-
lower_cases: "يجب ان يشمل حقل :attribute على عدد :amount حروف صغيرة على الاقل.",
|
|
2727
|
-
number: "يجب ان يشمل حقل :attribute على رقم واحد على الاقل.",
|
|
2728
|
-
numbers: "يجب ان يشمل حقل :attribute على عدد :amount من الارقام على الاقل.",
|
|
2729
|
-
symbol: "يجب ان يشمل حقل :attribute على رمز واحد على الاقل.",
|
|
2730
|
-
symbols: "يجب ان يشمل حقل :attribute على عدد :amount رموز على الاقل.",
|
|
2731
|
-
upper_case: "يجب ان يشمل حقل :attribute على حرف كبير واحد على الاقل.",
|
|
2732
|
-
upper_cases: "يجب ان يشمل حقل :attribute على عدد :amount حروف كبيرة على الاقل."
|
|
2733
|
-
},
|
|
2734
|
-
present: "يجب تقديم الحقل :attribute",
|
|
2735
|
-
regex: "صيغة الحقل :attribute .غير صحيحة",
|
|
2736
|
-
required: "الحقل :attribute مطلوب.",
|
|
2737
|
-
required_if: "الحقل :attribute مطلوب في حال ما إذا كان :other يساوي :value.",
|
|
2738
|
-
required_unless: "الحقل :attribute مطلوب في حال ما لم يكن :other يساوي :values.",
|
|
2739
|
-
required_with: "الحقل :attribute اجباري إذا توفّر :values.",
|
|
2740
|
-
required_with_all: "الحقل :attribute اجباري إذا توفّر :values.",
|
|
2741
|
-
required_without: "الحقل :attribute اجباري إذا لم يتوفّر :values.",
|
|
2742
|
-
required_without_all: "الحقل :attribute اجباري إذا لم يتوفّر :values.",
|
|
2743
|
-
starts_with: "الحقل :attribute يجب ان يبدأ بأحد القيم التالية: :values.",
|
|
2744
|
-
same: "يجب أن يتطابق الحقل :attribute مع :other",
|
|
2745
|
-
size: {
|
|
2746
|
-
number: "يجب أن تكون قيمة الحقل :attribute مساوية لـ :size",
|
|
2747
|
-
string: "يجب أن يحتوي النص :attribute على :size حروفٍ/حرفًا بالظبط",
|
|
2748
|
-
array: "يجب أن يحتوي الحقل :attribute على :size عنصرٍ/عناصر بالظبط",
|
|
2749
|
-
object: "يجب أن يحتوي الحقل :attribute على :size عنصرٍ/عناصر بالظبط"
|
|
2750
|
-
},
|
|
2751
|
-
string: "يجب أن يكون الحقل :attribute نصآ.",
|
|
2752
|
-
unique: "الحقل :attribute مستخدم بالفعل.",
|
|
2753
|
-
url: "صيغة الرابط :attribute غير صحيحة"
|
|
2754
|
-
}
|
|
2755
|
-
};
|
|
2756
|
-
/**
|
|
2757
|
-
* Determine if a value is an object. Arrays and null are not considered objects.
|
|
2758
|
-
*
|
|
2759
|
-
* @param value
|
|
2760
|
-
* @returns
|
|
2761
|
-
*/
|
|
2762
|
-
function isObject(value) {
|
|
2763
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2764
|
-
}
|
|
2765
|
-
/**
|
|
2766
|
-
* Deeply merge two objects.
|
|
2767
|
-
* The source object will overwrite the target object when there is a conflict.
|
|
2768
|
-
* Arrays and non-object values will be overwritten, not merged.
|
|
2769
|
-
*
|
|
2770
|
-
* @param target
|
|
2771
|
-
* @param source
|
|
2772
|
-
* @returns
|
|
2773
|
-
*/
|
|
2774
|
-
function mergeDeep(target, source) {
|
|
2775
|
-
const output = Object.assign({}, target);
|
|
2776
|
-
if (!isObject(target) || !isObject(source)) return output;
|
|
2777
|
-
for (const key in source) if (isObject(source[key])) if (!target[key]) Object.assign(output, { [key]: source[key] });
|
|
2778
|
-
else output[key] = mergeDeep(target[key], source[key]);
|
|
2779
|
-
else Object.assign(output, { [key]: source[key] });
|
|
2780
|
-
return output;
|
|
2781
|
-
}
|
|
2782
|
-
(class {
|
|
2783
|
-
/**
|
|
2784
|
-
* Default lang to be used, when lang is not specified
|
|
2785
|
-
*/
|
|
2786
|
-
static defaultLang = "en";
|
|
2787
|
-
/**
|
|
2788
|
-
* Determines the locale to be used when tu current one is not available
|
|
2789
|
-
*/
|
|
2790
|
-
static fallbackLang = "en";
|
|
2791
|
-
/**
|
|
2792
|
-
* The existing langs that are supported by the library
|
|
2793
|
-
*/
|
|
2794
|
-
static existingLangs = ["en"];
|
|
2795
|
-
/**
|
|
2796
|
-
* Store the translations passed by the user
|
|
2797
|
-
*/
|
|
2798
|
-
static translations = {};
|
|
2799
|
-
/**
|
|
2800
|
-
* Store translations contributed by plugins.
|
|
2801
|
-
*/
|
|
2802
|
-
static translationExtensions = {};
|
|
2803
|
-
/**
|
|
2804
|
-
* Stores the messages that are already loaded
|
|
2805
|
-
*/
|
|
2806
|
-
static messages = {};
|
|
2807
|
-
/**
|
|
2808
|
-
* Stores the default messages
|
|
2809
|
-
*/
|
|
2810
|
-
static defaultMessages = {};
|
|
2811
|
-
/**
|
|
2812
|
-
* Stores the fallback messages
|
|
2813
|
-
*/
|
|
2814
|
-
static fallbackMessages = locales_default.en;
|
|
2815
|
-
/**
|
|
2816
|
-
* Get messages for lang
|
|
2817
|
-
*
|
|
2818
|
-
* @param lang
|
|
2819
|
-
* @returns
|
|
2820
|
-
*/
|
|
2821
|
-
static get(lang) {
|
|
2822
|
-
lang ??= this.defaultLang;
|
|
2823
|
-
this.load(lang);
|
|
2824
|
-
return this.messages[lang];
|
|
2825
|
-
}
|
|
2826
|
-
/**
|
|
2827
|
-
* Set the translation object passed by the user
|
|
2828
|
-
*
|
|
2829
|
-
* @param translations
|
|
2830
|
-
*/
|
|
2831
|
-
static setTranslationObject(translations) {
|
|
2832
|
-
this.translations = translations;
|
|
2833
|
-
this.existingLangs = Array.from(/* @__PURE__ */ new Set([...this.existingLangs, ...Object.keys(translations)]));
|
|
2834
|
-
this.resetLoadedMessages();
|
|
2835
|
-
this.setDefaultLang(this.defaultLang);
|
|
2836
|
-
}
|
|
2837
|
-
/**
|
|
2838
|
-
* Merge additional translations into the global catalog.
|
|
2839
|
-
*/
|
|
2840
|
-
static extendTranslationObject(translations) {
|
|
2841
|
-
this.translationExtensions = mergeDeep(this.translationExtensions, translations);
|
|
2842
|
-
this.existingLangs = Array.from(/* @__PURE__ */ new Set([...this.existingLangs, ...Object.keys(translations)]));
|
|
2843
|
-
this.resetLoadedMessages();
|
|
2844
|
-
this.setDefaultLang(this.defaultLang);
|
|
2845
|
-
}
|
|
2846
|
-
/**
|
|
2847
|
-
* Set the default lang that should be used. And assign the default messages
|
|
2848
|
-
*
|
|
2849
|
-
* @param lang
|
|
2850
|
-
*/
|
|
2851
|
-
static setDefaultLang(lang) {
|
|
2852
|
-
this.defaultLang = lang;
|
|
2853
|
-
this.load(lang);
|
|
2854
|
-
}
|
|
2855
|
-
/**
|
|
2856
|
-
* Set the fallback lang to be used. And assign the fallback messages
|
|
2857
|
-
*
|
|
2858
|
-
* @param lang
|
|
2859
|
-
*/
|
|
2860
|
-
static setFallbackLang(lang) {
|
|
2861
|
-
this.fallbackLang = lang;
|
|
2862
|
-
this.fallbackMessages = locales_default.en;
|
|
2863
|
-
if (Object.prototype.hasOwnProperty.call(locales_default, lang)) this.fallbackMessages = mergeDeep(this.fallbackMessages, locales_default[lang]);
|
|
2864
|
-
if (Object.prototype.hasOwnProperty.call(this.translationExtensions, lang)) this.fallbackMessages = mergeDeep(this.fallbackMessages, this.translationExtensions[lang]);
|
|
2865
|
-
if (Object.prototype.hasOwnProperty.call(this.translations, lang)) this.fallbackMessages = mergeDeep(this.fallbackMessages, this.translations[lang]);
|
|
2866
|
-
}
|
|
2867
|
-
/**
|
|
2868
|
-
* Get the default language
|
|
2869
|
-
*
|
|
2870
|
-
* @returns
|
|
2871
|
-
*/
|
|
2872
|
-
static getDefaultLang() {
|
|
2873
|
-
return this.defaultLang;
|
|
2874
|
-
}
|
|
2875
|
-
/**
|
|
2876
|
-
* Load the messages based on the specified language
|
|
2877
|
-
*
|
|
2878
|
-
* @param lang
|
|
2879
|
-
* @returns
|
|
2880
|
-
*/
|
|
2881
|
-
static load(lang) {
|
|
2882
|
-
if (this.messages[lang]) return;
|
|
2883
|
-
if (Object.prototype.hasOwnProperty.call(locales_default, lang)) this.messages[lang] = mergeDeep(this.fallbackMessages, locales_default[lang]);
|
|
2884
|
-
else this.messages[lang] = mergeDeep({}, this.fallbackMessages);
|
|
2885
|
-
if (Object.prototype.hasOwnProperty.call(this.translationExtensions, lang)) this.messages[lang] = mergeDeep(this.messages[lang], this.translationExtensions[lang]);
|
|
2886
|
-
if (Object.prototype.hasOwnProperty.call(this.translations, lang)) this.messages[lang] = mergeDeep(this.messages[lang], this.translations[lang]);
|
|
2887
|
-
}
|
|
2888
|
-
static resetLoadedMessages() {
|
|
2889
|
-
this.messages = {};
|
|
2890
|
-
this.fallbackMessages = locales_default.en;
|
|
2891
|
-
}
|
|
2892
|
-
});
|
|
2893
|
-
import_dayjs_min.default.extend(import_customParseFormat.default);
|
|
2894
|
-
//#endregion
|
|
2895
|
-
//#region ../http/dist/redirect-BPQIvVtB.js
|
|
2896
|
-
const unwrapRequestSource = (source) => {
|
|
2897
|
-
if (source.original) return unwrapRequestSource(source.original);
|
|
2898
|
-
if (source.headers) return source;
|
|
2899
|
-
if (source.req) return source.req;
|
|
2900
|
-
if (source.request) return source.request;
|
|
2901
|
-
return source;
|
|
2902
|
-
};
|
|
2903
|
-
const makeHeaders = (headers) => {
|
|
2904
|
-
return new Headers(normalizeHeaders(headers));
|
|
2905
|
-
};
|
|
2906
|
-
const normalizeHeaders = (headers) => {
|
|
2907
|
-
const normalized = {};
|
|
2908
|
-
if (!headers) return normalized;
|
|
2909
|
-
if (isHeaders(headers)) {
|
|
2910
|
-
headers.forEach((value, key) => {
|
|
2911
|
-
normalized[key.toLowerCase()] = value;
|
|
2912
|
-
});
|
|
2913
|
-
return normalized;
|
|
2914
|
-
}
|
|
2915
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
2916
|
-
const normalizedValue = normalizeHeaderValue(value);
|
|
2917
|
-
if (typeof normalizedValue === "string") normalized[key.toLowerCase()] = normalizedValue;
|
|
2918
|
-
}
|
|
2919
|
-
return normalized;
|
|
2920
|
-
};
|
|
2921
|
-
const normalizeHeaderValue = (value) => {
|
|
2922
|
-
if (Array.isArray(value)) return value.join(", ");
|
|
2923
|
-
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
2924
|
-
return value ?? void 0;
|
|
2925
|
-
};
|
|
2926
|
-
const isHeaders = (value) => typeof Headers !== "undefined" && value instanceof Headers;
|
|
2927
|
-
const isRecord = (value) => {
|
|
2928
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
2929
|
-
};
|
|
2930
|
-
/**
|
|
2931
|
-
* Represents an HTTP request, providing a consistent interface for accessing request data.
|
|
2932
|
-
*
|
|
2933
|
-
* @author 3m1n3nc3
|
|
2934
|
-
*/
|
|
2935
|
-
var Request$1 = class Request$1 extends Request {
|
|
2936
|
-
headers;
|
|
2937
|
-
ip;
|
|
2938
|
-
source;
|
|
2939
|
-
currentUser;
|
|
2940
|
-
currentAuth;
|
|
2941
|
-
currentAuthUser;
|
|
2942
|
-
currentAuthToken;
|
|
2943
|
-
get user() {
|
|
2944
|
-
return this.getSourceRequest()?.user ?? this.currentUser;
|
|
2945
|
-
}
|
|
2946
|
-
set user(user) {
|
|
2947
|
-
this.currentUser = user;
|
|
2948
|
-
}
|
|
2949
|
-
get auth() {
|
|
2950
|
-
return this.getSourceRequest()?.auth ?? this.currentAuth;
|
|
2951
|
-
}
|
|
2952
|
-
set auth(auth) {
|
|
2953
|
-
this.currentAuth = auth;
|
|
2954
|
-
}
|
|
2955
|
-
get authUser() {
|
|
2956
|
-
return this.getSourceRequest()?.authUser ?? this.currentAuthUser;
|
|
2957
|
-
}
|
|
2958
|
-
set authUser(user) {
|
|
2959
|
-
this.currentAuthUser = user;
|
|
2960
|
-
}
|
|
2961
|
-
get authToken() {
|
|
2962
|
-
return this.getSourceRequest()?.authToken ?? this.currentAuthToken;
|
|
2963
|
-
}
|
|
2964
|
-
set authToken(token) {
|
|
2965
|
-
this.currentAuthToken = token;
|
|
2966
|
-
}
|
|
2967
|
-
constructor(options = {}) {
|
|
2968
|
-
super(options);
|
|
2969
|
-
const source = options.source ?? options.original;
|
|
2970
|
-
const sourceRequest = isRecord(source) ? source : void 0;
|
|
2971
|
-
this.headers = normalizeHeaders(options.headers);
|
|
2972
|
-
if (this.method) this.method = options.method;
|
|
2973
|
-
if (this.url) this.url = options.url;
|
|
2974
|
-
if (this.path) this.path = options.path;
|
|
2975
|
-
this.ip = options.ip ?? sourceRequest?.ip ?? null;
|
|
2976
|
-
this.user = options.user ?? sourceRequest?.user;
|
|
2977
|
-
this.auth = options.auth ?? sourceRequest?.auth;
|
|
2978
|
-
this.authUser = options.authUser ?? sourceRequest?.authUser;
|
|
2979
|
-
this.authToken = options.authToken ?? sourceRequest?.authToken;
|
|
2980
|
-
this.source = source;
|
|
2981
|
-
globalThis.request = (key) => key ? this.input(key) : this;
|
|
2982
|
-
}
|
|
2983
|
-
static from(source) {
|
|
2984
|
-
if (!source) return;
|
|
2985
|
-
if (source instanceof Request$1) return source;
|
|
2986
|
-
const request = unwrapRequestSource(source);
|
|
2987
|
-
return new Request$1({
|
|
2988
|
-
headers: request.headers,
|
|
2989
|
-
method: request.method,
|
|
2990
|
-
url: request.originalUrl ?? request.url,
|
|
2991
|
-
path: request.path,
|
|
2992
|
-
ip: request.ip ?? null,
|
|
2993
|
-
user: request.user,
|
|
2994
|
-
auth: request.auth,
|
|
2995
|
-
authUser: request.authUser,
|
|
2996
|
-
authToken: request.authToken,
|
|
2997
|
-
source: request
|
|
2998
|
-
});
|
|
2999
|
-
}
|
|
3000
|
-
header(name) {
|
|
3001
|
-
return this.headers[name.toLowerCase()];
|
|
3002
|
-
}
|
|
3003
|
-
bearerToken() {
|
|
3004
|
-
const authorization = this.header("authorization");
|
|
3005
|
-
if (!authorization?.startsWith("Bearer ")) return null;
|
|
3006
|
-
return authorization.substring(7);
|
|
3007
|
-
}
|
|
3008
|
-
setUser(user) {
|
|
3009
|
-
this.user = user;
|
|
3010
|
-
if (isRecord(this.source)) this.source.user = user;
|
|
3011
|
-
return this;
|
|
3012
|
-
}
|
|
3013
|
-
setAuthentication(auth, user, token) {
|
|
3014
|
-
this.auth = auth;
|
|
3015
|
-
this.authUser = user;
|
|
3016
|
-
this.authToken = token;
|
|
3017
|
-
this.setUser(user);
|
|
3018
|
-
if (isRecord(this.source)) {
|
|
3019
|
-
this.source.auth = auth;
|
|
3020
|
-
this.source.authUser = user;
|
|
3021
|
-
this.source.authToken = token;
|
|
3022
|
-
}
|
|
3023
|
-
return this;
|
|
3024
|
-
}
|
|
3025
|
-
syncFromSource() {
|
|
3026
|
-
if (!isRecord(this.source)) return this;
|
|
3027
|
-
const source = this.source;
|
|
3028
|
-
this.user = source.user ?? this.user;
|
|
3029
|
-
this.auth = source.auth ?? this.auth;
|
|
3030
|
-
this.authUser = source.authUser ?? this.authUser;
|
|
3031
|
-
this.authToken = source.authToken ?? this.authToken;
|
|
3032
|
-
return this;
|
|
3033
|
-
}
|
|
3034
|
-
getSourceRequest() {
|
|
3035
|
-
return isRecord(this.source) ? this.source : void 0;
|
|
3036
|
-
}
|
|
3037
|
-
clearAuthentication() {
|
|
3038
|
-
this.auth = void 0;
|
|
3039
|
-
this.authUser = void 0;
|
|
3040
|
-
this.authToken = void 0;
|
|
3041
|
-
this.user = void 0;
|
|
3042
|
-
if (isRecord(this.source)) {
|
|
3043
|
-
this.source.auth = void 0;
|
|
3044
|
-
this.source.authUser = void 0;
|
|
3045
|
-
this.source.authToken = void 0;
|
|
3046
|
-
this.source.user = void 0;
|
|
3047
|
-
}
|
|
3048
|
-
return this;
|
|
3049
|
-
}
|
|
3050
|
-
};
|
|
3051
|
-
/**
|
|
3052
|
-
* Represents an HTTP response, providing a consistent interface for accessing response data.
|
|
3053
|
-
*
|
|
3054
|
-
* @author 3m1n3nc3
|
|
3055
|
-
*/
|
|
3056
|
-
var Response$1 = class Response$1 extends Response {
|
|
3057
|
-
body;
|
|
3058
|
-
source;
|
|
3059
|
-
constructor(options = {}) {
|
|
3060
|
-
super({
|
|
3061
|
-
body: options.body,
|
|
3062
|
-
headers: makeHeaders(options.headers),
|
|
3063
|
-
statusCode: options.statusCode ?? 200
|
|
3064
|
-
});
|
|
3065
|
-
this.body = options.body ?? {};
|
|
3066
|
-
this.source = options.source;
|
|
3067
|
-
globalThis.response = () => this;
|
|
3068
|
-
}
|
|
3069
|
-
static from(source) {
|
|
3070
|
-
if (!source) return;
|
|
3071
|
-
if (source instanceof Response$1) return source;
|
|
3072
|
-
return new Response$1({
|
|
3073
|
-
statusCode: typeof source.status === "number" ? source.status : source.statusCode,
|
|
3074
|
-
headers: source.headers,
|
|
3075
|
-
source
|
|
3076
|
-
});
|
|
3077
|
-
}
|
|
3078
|
-
status(code) {
|
|
3079
|
-
this.statusCode = code;
|
|
3080
|
-
if (isRecord(this.source)) if (typeof this.source.status === "function") this.source.status(code);
|
|
3081
|
-
else this.source.statusCode = code;
|
|
3082
|
-
return this;
|
|
3083
|
-
}
|
|
3084
|
-
header(name, value) {
|
|
3085
|
-
this.headers.set(name.toLowerCase(), value);
|
|
3086
|
-
if (isRecord(this.source) && typeof this.source.setHeader === "function") this.source.setHeader(name, value);
|
|
3087
|
-
return this;
|
|
3088
|
-
}
|
|
3089
|
-
getHeaders() {
|
|
3090
|
-
return normalizeHeaders(this.headers);
|
|
3091
|
-
}
|
|
3092
|
-
json(body) {
|
|
3093
|
-
this.body = body;
|
|
3094
|
-
if (isRecord(this.source) && typeof this.source.json === "function") return this.source.json(body);
|
|
3095
|
-
return body;
|
|
3096
|
-
}
|
|
3097
|
-
send(body) {
|
|
3098
|
-
this.body = body;
|
|
3099
|
-
if (isRecord(this.source) && typeof this.source.send === "function") return this.source.send(body);
|
|
3100
|
-
return body;
|
|
3101
|
-
}
|
|
3102
|
-
};
|
|
3103
|
-
var FlashBag = class {
|
|
3104
|
-
bag = {};
|
|
3105
|
-
sweepKeys = /* @__PURE__ */ new Set();
|
|
3106
|
-
constructor(items) {
|
|
3107
|
-
this.bag = { ...items || {} };
|
|
3108
|
-
this.sweepKeys = new Set(Object.keys(this.bag));
|
|
3109
|
-
}
|
|
3110
|
-
put(key, value) {
|
|
3111
|
-
this.bag[key] = value;
|
|
3112
|
-
this.sweepKeys.delete(key);
|
|
3113
|
-
return this;
|
|
3114
|
-
}
|
|
3115
|
-
set(key, value) {
|
|
3116
|
-
return this.put(key, value);
|
|
3117
|
-
}
|
|
3118
|
-
get(key, defaultValue) {
|
|
3119
|
-
return key in this.bag ? this.bag[key] : defaultValue;
|
|
3120
|
-
}
|
|
3121
|
-
has(key) {
|
|
3122
|
-
if (Array.isArray(key)) return key.every((item) => this.has(item));
|
|
3123
|
-
if (key) return key in this.bag;
|
|
3124
|
-
return this.any();
|
|
3125
|
-
}
|
|
3126
|
-
any() {
|
|
3127
|
-
return Object.keys(this.bag).length > 0;
|
|
3128
|
-
}
|
|
3129
|
-
isEmpty() {
|
|
3130
|
-
return !this.any();
|
|
3131
|
-
}
|
|
3132
|
-
isNotEmpty() {
|
|
3133
|
-
return this.any();
|
|
3134
|
-
}
|
|
3135
|
-
keys() {
|
|
3136
|
-
return Object.keys(this.bag);
|
|
3137
|
-
}
|
|
3138
|
-
all() {
|
|
3139
|
-
return { ...this.bag };
|
|
3140
|
-
}
|
|
3141
|
-
clear(key) {
|
|
3142
|
-
if (Array.isArray(key)) {
|
|
3143
|
-
for (const item of key) {
|
|
3144
|
-
delete this.bag[item];
|
|
3145
|
-
this.sweepKeys.delete(item);
|
|
3146
|
-
}
|
|
3147
|
-
return this;
|
|
3148
|
-
}
|
|
3149
|
-
if (key) {
|
|
3150
|
-
delete this.bag[key];
|
|
3151
|
-
this.sweepKeys.delete(key);
|
|
3152
|
-
return this;
|
|
3153
|
-
}
|
|
3154
|
-
this.bag = {};
|
|
3155
|
-
this.sweepKeys.clear();
|
|
3156
|
-
return this;
|
|
3157
|
-
}
|
|
3158
|
-
forget(key) {
|
|
3159
|
-
return this.clear(key);
|
|
3160
|
-
}
|
|
3161
|
-
markForSweep(keys = this.keys()) {
|
|
3162
|
-
this.sweepKeys = new Set(keys);
|
|
3163
|
-
return this;
|
|
3164
|
-
}
|
|
3165
|
-
sweep() {
|
|
3166
|
-
for (const key of this.sweepKeys) delete this.bag[key];
|
|
3167
|
-
this.sweepKeys = new Set(Object.keys(this.bag));
|
|
3168
|
-
return this;
|
|
3169
|
-
}
|
|
3170
|
-
toJSON() {
|
|
3171
|
-
return this.all();
|
|
3172
|
-
}
|
|
3173
|
-
};
|
|
3174
|
-
const asMessageRecord = (value) => {
|
|
3175
|
-
if (!isRecord(value)) return;
|
|
3176
|
-
return value;
|
|
3177
|
-
};
|
|
3178
|
-
const callRecordMethod = (source, method) => {
|
|
3179
|
-
if (typeof source[method] !== "function") return;
|
|
3180
|
-
return asMessageRecord(source[method]());
|
|
3181
|
-
};
|
|
3182
|
-
const resolveMessageRecord = (source) => {
|
|
3183
|
-
if (!isRecord(source)) return;
|
|
3184
|
-
if (typeof source.getMessageBag === "function") {
|
|
3185
|
-
const bag = source.getMessageBag();
|
|
3186
|
-
if (bag && bag !== source) {
|
|
3187
|
-
const messages = resolveMessageRecord(bag);
|
|
3188
|
-
if (messages) return messages;
|
|
3189
|
-
}
|
|
3190
|
-
}
|
|
3191
|
-
if (typeof source.errors === "function") {
|
|
3192
|
-
const errors = source.errors();
|
|
3193
|
-
const messages = resolveMessageRecord(errors) || asMessageRecord(errors);
|
|
3194
|
-
if (messages) return messages;
|
|
3195
|
-
}
|
|
3196
|
-
return callRecordMethod(source, "getMessages") || callRecordMethod(source, "messagesRaw") || callRecordMethod(source, "toArray") || resolveMessageRecord(source.errors) || asMessageRecord(source.errors);
|
|
3197
|
-
};
|
|
3198
|
-
const getValidationIssueField = (issue) => {
|
|
3199
|
-
if (typeof issue.field === "string") return issue.field;
|
|
3200
|
-
if (typeof issue.attribute === "string") return issue.attribute;
|
|
3201
|
-
if (typeof issue.key === "string") return issue.key;
|
|
3202
|
-
if (typeof issue.path === "string") return issue.path;
|
|
3203
|
-
if (Array.isArray(issue.path)) return issue.path.join(".") || "_";
|
|
3204
|
-
return "_";
|
|
3205
|
-
};
|
|
3206
|
-
const toMessages = (value) => {
|
|
3207
|
-
if (Array.isArray(value)) return value.flatMap((item) => toMessages(item));
|
|
3208
|
-
if (value instanceof Error) return [value.message];
|
|
3209
|
-
if (isRecord(value) && typeof value.message === "string") return [value.message];
|
|
3210
|
-
if (value === null || typeof value === "undefined") return [];
|
|
3211
|
-
return [String(value)];
|
|
3212
|
-
};
|
|
3213
|
-
var ErrorBag = class ErrorBag extends FlashBag {
|
|
3214
|
-
constructor(errors) {
|
|
3215
|
-
super();
|
|
3216
|
-
if (errors) {
|
|
3217
|
-
this.merge(errors);
|
|
3218
|
-
this.markForSweep();
|
|
3219
|
-
}
|
|
3220
|
-
}
|
|
3221
|
-
add(field, message) {
|
|
3222
|
-
const key = field || "_";
|
|
3223
|
-
const messages = toMessages(message);
|
|
3224
|
-
if (!messages.length) return this;
|
|
3225
|
-
this.put(key, [...this.bag[key] || [], ...messages]);
|
|
3226
|
-
return this;
|
|
3227
|
-
}
|
|
3228
|
-
addIf(condition, field, message) {
|
|
3229
|
-
if (condition) this.add(field, message);
|
|
3230
|
-
return this;
|
|
3231
|
-
}
|
|
3232
|
-
merge(errors) {
|
|
3233
|
-
const incoming = resolveMessageRecord(errors) || (isRecord(errors) ? errors : void 0);
|
|
3234
|
-
if (!incoming) return this.validation(errors);
|
|
3235
|
-
for (const [field, messages] of Object.entries(incoming)) this.add(field, messages);
|
|
3236
|
-
return this;
|
|
3237
|
-
}
|
|
3238
|
-
validation(error) {
|
|
3239
|
-
if (!error) return this;
|
|
3240
|
-
if (error instanceof ErrorBag) return this.merge(error);
|
|
3241
|
-
const messages = resolveMessageRecord(error);
|
|
3242
|
-
if (messages) return this.merge(messages);
|
|
3243
|
-
if (Array.isArray(error)) {
|
|
3244
|
-
for (const item of error) if (isRecord(item) && "message" in item) this.add(getValidationIssueField(item), item.message);
|
|
3245
|
-
else this.add("_", item);
|
|
3246
|
-
return this;
|
|
3247
|
-
}
|
|
3248
|
-
if (isRecord(error)) {
|
|
3249
|
-
if (typeof error.errors === "function") return this.validation(error.errors());
|
|
3250
|
-
if (error.errors) return this.validation(error.errors);
|
|
3251
|
-
if (Array.isArray(error.issues)) return this.validation(error.issues);
|
|
3252
|
-
if ("message" in error) return this.add(getValidationIssueField(error), error.message);
|
|
3253
|
-
return this.merge(error);
|
|
3254
|
-
}
|
|
3255
|
-
if (error instanceof Error) return this.add("_", error.message);
|
|
3256
|
-
return this.add("_", error);
|
|
3257
|
-
}
|
|
3258
|
-
keys() {
|
|
3259
|
-
return Object.keys(this.bag);
|
|
3260
|
-
}
|
|
3261
|
-
get(field = "_") {
|
|
3262
|
-
return [...this.bag[field] || []];
|
|
3263
|
-
}
|
|
3264
|
-
first(field) {
|
|
3265
|
-
if (field) return this.bag[field]?.[0] || "";
|
|
3266
|
-
return this.all()[0] || "";
|
|
3267
|
-
}
|
|
3268
|
-
has(field) {
|
|
3269
|
-
if (Array.isArray(field)) return field.every((key) => this.has(key));
|
|
3270
|
-
if (field) return (this.bag[field]?.length || 0) > 0;
|
|
3271
|
-
return this.any();
|
|
3272
|
-
}
|
|
3273
|
-
hasAny(fields) {
|
|
3274
|
-
return (Array.isArray(fields) ? fields : [fields]).some((key) => this.has(key));
|
|
3275
|
-
}
|
|
3276
|
-
missing(fields) {
|
|
3277
|
-
return (Array.isArray(fields) ? fields : [fields]).every((key) => !this.has(key));
|
|
3278
|
-
}
|
|
3279
|
-
any() {
|
|
3280
|
-
return Object.values(this.bag).some((messages) => messages.length > 0);
|
|
3281
|
-
}
|
|
3282
|
-
isEmpty() {
|
|
3283
|
-
return !this.any();
|
|
3284
|
-
}
|
|
3285
|
-
isNotEmpty() {
|
|
3286
|
-
return this.any();
|
|
3287
|
-
}
|
|
3288
|
-
count() {
|
|
3289
|
-
return Object.values(this.bag).reduce((total, messages) => total + messages.length, 0);
|
|
3290
|
-
}
|
|
3291
|
-
all() {
|
|
3292
|
-
return Object.values(this.bag).flat();
|
|
3293
|
-
}
|
|
3294
|
-
unique() {
|
|
3295
|
-
return [...new Set(this.all())];
|
|
3296
|
-
}
|
|
3297
|
-
clear(field) {
|
|
3298
|
-
super.clear(field);
|
|
3299
|
-
return this;
|
|
3300
|
-
}
|
|
3301
|
-
forget(field) {
|
|
3302
|
-
return this.clear(field);
|
|
3303
|
-
}
|
|
3304
|
-
messagesRaw() {
|
|
3305
|
-
return this.toJSON();
|
|
3306
|
-
}
|
|
3307
|
-
getMessages() {
|
|
3308
|
-
return this.messagesRaw();
|
|
3309
|
-
}
|
|
3310
|
-
getMessageBag() {
|
|
3311
|
-
return this;
|
|
3312
|
-
}
|
|
3313
|
-
toArray() {
|
|
3314
|
-
return this.toJSON();
|
|
3315
|
-
}
|
|
3316
|
-
toJSON() {
|
|
3317
|
-
return Object.entries(this.bag).reduce((errors, [field, messages]) => {
|
|
3318
|
-
errors[field] = [...messages];
|
|
3319
|
-
return errors;
|
|
3320
|
-
}, {});
|
|
3321
|
-
}
|
|
3322
|
-
};
|
|
3323
|
-
var Session = class Session {
|
|
3324
|
-
errors;
|
|
3325
|
-
flashBag;
|
|
3326
|
-
id;
|
|
3327
|
-
data;
|
|
3328
|
-
persistent;
|
|
3329
|
-
saveQueue = Promise.resolve();
|
|
3330
|
-
constructor(initial, persistent) {
|
|
3331
|
-
const current = initial instanceof Session ? initial : void 0;
|
|
3332
|
-
const state = current ? current.snapshot() : initial && ("data" in initial || "errors" in initial || "flash" in initial) ? initial : { data: initial };
|
|
3333
|
-
this.id = persistent?.id ?? current?.id;
|
|
3334
|
-
this.persistent = persistent ?? current?.persistent;
|
|
3335
|
-
this.saveQueue = current?.saveQueue ?? this.saveQueue;
|
|
3336
|
-
this.data = current ? current.data : { ...state.data || {} };
|
|
3337
|
-
this.errors = current ? current.errors : state.errors instanceof ErrorBag ? state.errors : new ErrorBag(state.errors);
|
|
3338
|
-
this.flashBag = current ? current.flashBag : state.flash instanceof FlashBag ? state.flash : new FlashBag(state.flash);
|
|
3339
|
-
const helper = ((key) => key ? this.get(key) : this);
|
|
3340
|
-
Object.assign(helper, {
|
|
3341
|
-
get: this.get.bind(this),
|
|
3342
|
-
put: this.put.bind(this),
|
|
3343
|
-
set: this.set.bind(this),
|
|
3344
|
-
has: this.has.bind(this),
|
|
3345
|
-
forget: this.forget.bind(this),
|
|
3346
|
-
clear: this.clear.bind(this),
|
|
3347
|
-
all: this.all.bind(this),
|
|
3348
|
-
flash: this.flash.bind(this),
|
|
3349
|
-
getFlash: this.getFlash.bind(this),
|
|
3350
|
-
hasErrors: this.hasErrors.bind(this),
|
|
3351
|
-
clearErrors: this.clearErrors.bind(this),
|
|
3352
|
-
errors: this.errors,
|
|
3353
|
-
flashBag: this.flashBag
|
|
3354
|
-
});
|
|
3355
|
-
globalThis.session = helper;
|
|
3356
|
-
}
|
|
3357
|
-
snapshot() {
|
|
3358
|
-
return {
|
|
3359
|
-
data: this.all(),
|
|
3360
|
-
errors: this.errors.toJSON(),
|
|
3361
|
-
flash: this.flashBag.toJSON()
|
|
3362
|
-
};
|
|
3363
|
-
}
|
|
3364
|
-
queuePersist() {
|
|
3365
|
-
this.save();
|
|
3366
|
-
}
|
|
3367
|
-
async save() {
|
|
3368
|
-
const payload = this.snapshot();
|
|
3369
|
-
const previous = this.saveQueue.catch(() => void 0);
|
|
3370
|
-
this.saveQueue = previous.then(async () => {
|
|
3371
|
-
await this.persistent?.save(payload);
|
|
3372
|
-
});
|
|
3373
|
-
await this.saveQueue;
|
|
3374
|
-
return this;
|
|
3375
|
-
}
|
|
3376
|
-
async destroy() {
|
|
3377
|
-
this.data = {};
|
|
3378
|
-
this.errors.clear();
|
|
3379
|
-
this.flashBag.clear();
|
|
3380
|
-
await this.persistent?.destroy?.();
|
|
3381
|
-
return this;
|
|
3382
|
-
}
|
|
3383
|
-
/**
|
|
3384
|
-
* Get an item from the session bag
|
|
3385
|
-
*
|
|
3386
|
-
* @param key
|
|
3387
|
-
* @param defaultValue
|
|
3388
|
-
* @returns
|
|
3389
|
-
*/
|
|
3390
|
-
get(key, defaultValue) {
|
|
3391
|
-
return key in this.data ? this.data[key] : defaultValue;
|
|
3392
|
-
}
|
|
3393
|
-
/**
|
|
3394
|
-
* Add an item to the session bag
|
|
3395
|
-
*
|
|
3396
|
-
* @param key
|
|
3397
|
-
* @param defaultValue
|
|
3398
|
-
* @returns
|
|
3399
|
-
*/
|
|
3400
|
-
put(key, value) {
|
|
3401
|
-
this.data[key] = value;
|
|
3402
|
-
this.queuePersist();
|
|
3403
|
-
return this;
|
|
3404
|
-
}
|
|
3405
|
-
/**
|
|
3406
|
-
* Add an item to the session bag
|
|
3407
|
-
*
|
|
3408
|
-
* @param key
|
|
3409
|
-
* @param defaultValue
|
|
3410
|
-
* @returns
|
|
3411
|
-
*/
|
|
3412
|
-
set(key, value) {
|
|
3413
|
-
return this.put(key, value);
|
|
3414
|
-
}
|
|
3415
|
-
/**
|
|
3416
|
-
* Check if an item exist in the session bag
|
|
3417
|
-
*
|
|
3418
|
-
* @param key
|
|
3419
|
-
* @returns
|
|
3420
|
-
*/
|
|
3421
|
-
has(key) {
|
|
3422
|
-
return key in this.data;
|
|
3423
|
-
}
|
|
3424
|
-
/**
|
|
3425
|
-
* Remove an item from the session bag
|
|
3426
|
-
*
|
|
3427
|
-
* @param key
|
|
3428
|
-
* @returns
|
|
3429
|
-
*/
|
|
3430
|
-
forget(key) {
|
|
3431
|
-
delete this.data[key];
|
|
3432
|
-
this.queuePersist();
|
|
3433
|
-
return this;
|
|
3434
|
-
}
|
|
3435
|
-
/**
|
|
3436
|
-
* Clear the session bag
|
|
3437
|
-
*
|
|
3438
|
-
* @returns
|
|
3439
|
-
*/
|
|
3440
|
-
clear() {
|
|
3441
|
-
this.data = {};
|
|
3442
|
-
this.errors.clear();
|
|
3443
|
-
this.flashBag.clear();
|
|
3444
|
-
this.queuePersist();
|
|
3445
|
-
return this;
|
|
3446
|
-
}
|
|
3447
|
-
/**
|
|
3448
|
-
* Get all items in the session bag
|
|
3449
|
-
*
|
|
3450
|
-
* @returns
|
|
3451
|
-
*/
|
|
3452
|
-
all() {
|
|
3453
|
-
return { ...this.data };
|
|
3454
|
-
}
|
|
3455
|
-
/**
|
|
3456
|
-
* Add a flash item for the next request
|
|
3457
|
-
*
|
|
3458
|
-
* @param key
|
|
3459
|
-
* @param value
|
|
3460
|
-
* @returns
|
|
3461
|
-
*/
|
|
3462
|
-
flash(key, value) {
|
|
3463
|
-
this.flashBag.put(key, value);
|
|
3464
|
-
this.queuePersist();
|
|
3465
|
-
return this;
|
|
3466
|
-
}
|
|
3467
|
-
/**
|
|
3468
|
-
* Get a flash item
|
|
3469
|
-
*
|
|
3470
|
-
* @param key
|
|
3471
|
-
* @param defaultValue
|
|
3472
|
-
* @returns
|
|
3473
|
-
*/
|
|
3474
|
-
getFlash(key, defaultValue) {
|
|
3475
|
-
return this.flashBag.get(key, defaultValue);
|
|
3476
|
-
}
|
|
3477
|
-
/**
|
|
3478
|
-
* Sweep flashed data that was loaded for this request
|
|
3479
|
-
*
|
|
3480
|
-
* @returns
|
|
3481
|
-
*/
|
|
3482
|
-
async sweepFlash() {
|
|
3483
|
-
this.errors.sweep();
|
|
3484
|
-
this.flashBag.sweep();
|
|
3485
|
-
await this.save();
|
|
3486
|
-
return this;
|
|
3487
|
-
}
|
|
3488
|
-
/**
|
|
3489
|
-
* Add an error to the session error bag
|
|
3490
|
-
*
|
|
3491
|
-
* @param field
|
|
3492
|
-
* @param message
|
|
3493
|
-
* @returns
|
|
3494
|
-
*/
|
|
3495
|
-
addError(field, message) {
|
|
3496
|
-
this.errors.add(field, message);
|
|
3497
|
-
this.queuePersist();
|
|
3498
|
-
return this;
|
|
3499
|
-
}
|
|
3500
|
-
/**
|
|
3501
|
-
* Add multiple errors to the session error bag
|
|
3502
|
-
*
|
|
3503
|
-
* @param errors
|
|
3504
|
-
* @returns
|
|
3505
|
-
*/
|
|
3506
|
-
addErrors(errors) {
|
|
3507
|
-
this.errors.merge(errors);
|
|
3508
|
-
this.queuePersist();
|
|
3509
|
-
return this;
|
|
3510
|
-
}
|
|
3511
|
-
/**
|
|
3512
|
-
* Add a validation error to the session error bag
|
|
3513
|
-
*
|
|
3514
|
-
* @param error
|
|
3515
|
-
* @returns
|
|
3516
|
-
*/
|
|
3517
|
-
addValidationErrors(error) {
|
|
3518
|
-
this.errors.validation(error);
|
|
3519
|
-
this.queuePersist();
|
|
3520
|
-
return this;
|
|
3521
|
-
}
|
|
3522
|
-
/**
|
|
3523
|
-
* Check if the session error bag has any errors
|
|
3524
|
-
*
|
|
3525
|
-
* @param field
|
|
3526
|
-
* @returns
|
|
3527
|
-
*/
|
|
3528
|
-
hasErrors(field) {
|
|
3529
|
-
return this.errors.has(field);
|
|
3530
|
-
}
|
|
3531
|
-
/**
|
|
3532
|
-
* Clear all errors in the session error bag
|
|
3533
|
-
*
|
|
3534
|
-
* @param field
|
|
3535
|
-
* @returns
|
|
3536
|
-
*/
|
|
3537
|
-
clearErrors(field) {
|
|
3538
|
-
this.errors.clear(field);
|
|
3539
|
-
this.queuePersist();
|
|
3540
|
-
return this;
|
|
3541
|
-
}
|
|
3542
|
-
/**
|
|
3543
|
-
* Parse session for views
|
|
3544
|
-
*
|
|
3545
|
-
* @returns
|
|
3546
|
-
*/
|
|
3547
|
-
forView() {
|
|
3548
|
-
return {
|
|
3549
|
-
...this.all(),
|
|
3550
|
-
errors: this.errors,
|
|
3551
|
-
flash: this.flashBag
|
|
3552
|
-
};
|
|
3553
|
-
}
|
|
3554
|
-
/**
|
|
3555
|
-
* Return session as json
|
|
3556
|
-
*
|
|
3557
|
-
* @returns
|
|
3558
|
-
*/
|
|
3559
|
-
toJSON() {
|
|
3560
|
-
return {
|
|
3561
|
-
...this.all(),
|
|
3562
|
-
errors: this.errors.toJSON(),
|
|
3563
|
-
flash: this.flashBag.toJSON()
|
|
3564
|
-
};
|
|
3565
|
-
}
|
|
3566
|
-
};
|
|
3567
|
-
const byteLength = (value) => Buffer.byteLength(value, "utf8");
|
|
3568
|
-
const serializeValue = (value) => {
|
|
3569
|
-
if (value === null || typeof value === "undefined") return "N;";
|
|
3570
|
-
if (typeof value === "boolean") return `b:${value ? 1 : 0};`;
|
|
3571
|
-
if (typeof value === "number") return Number.isInteger(value) ? `i:${value};` : `d:${value};`;
|
|
3572
|
-
if (typeof value === "string") return `s:${byteLength(value)}:"${value}";`;
|
|
3573
|
-
if (Array.isArray(value)) return serializeEntries(value.map((item, index) => [index, item]));
|
|
3574
|
-
if (typeof value === "object") return serializeEntries(Object.entries(value));
|
|
3575
|
-
return serializeValue(String(value));
|
|
3576
|
-
};
|
|
3577
|
-
const serializeEntries = (entries) => {
|
|
3578
|
-
return `a:${entries.length}:{${entries.map(([key, value]) => serializeValue(key) + serializeValue(value)).join("")}}`;
|
|
3579
|
-
};
|
|
3580
|
-
//#endregion
|
|
3581
|
-
export { Request$1 as Request, Response$1 as Response, Session };
|