@hot-updater/cloudflare 0.25.9 → 0.25.10
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/index.d.cts +3 -3
- package/package.json +6 -6
- package/worker/dist/README.md +1 -1
- package/worker/dist/index.js +111 -91
- package/worker/dist/index.js.map +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _hot_updater_plugin_core0 from "@hot-updater/plugin-core";
|
|
2
2
|
|
|
3
3
|
//#region src/d1Database.d.ts
|
|
4
4
|
interface D1DatabaseConfig {
|
|
@@ -6,7 +6,7 @@ interface D1DatabaseConfig {
|
|
|
6
6
|
accountId: string;
|
|
7
7
|
cloudflareApiToken: string;
|
|
8
8
|
}
|
|
9
|
-
declare const d1Database: (config: D1DatabaseConfig, hooks?:
|
|
9
|
+
declare const d1Database: (config: D1DatabaseConfig, hooks?: _hot_updater_plugin_core0.DatabasePluginHooks) => (() => _hot_updater_plugin_core0.DatabasePlugin);
|
|
10
10
|
//#endregion
|
|
11
11
|
//#region src/r2Storage.d.ts
|
|
12
12
|
interface R2StorageConfig {
|
|
@@ -41,6 +41,6 @@ interface R2StorageConfig {
|
|
|
41
41
|
* })
|
|
42
42
|
* ```
|
|
43
43
|
*/
|
|
44
|
-
declare const r2Storage: (config: R2StorageConfig, hooks?:
|
|
44
|
+
declare const r2Storage: (config: R2StorageConfig, hooks?: _hot_updater_plugin_core0.StoragePluginHooks) => () => _hot_updater_plugin_core0.StoragePlugin;
|
|
45
45
|
//#endregion
|
|
46
46
|
export { D1DatabaseConfig, R2StorageConfig, d1Database, r2Storage };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hot-updater/cloudflare",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.25.
|
|
4
|
+
"version": "0.25.10",
|
|
5
5
|
"description": "React Native OTA solution for self-hosted",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"cloudflare": "4.2.0",
|
|
44
|
-
"@hot-updater/
|
|
45
|
-
"@hot-updater/
|
|
46
|
-
"@hot-updater/
|
|
47
|
-
"@hot-updater/
|
|
44
|
+
"@hot-updater/cli-tools": "0.25.10",
|
|
45
|
+
"@hot-updater/core": "0.25.10",
|
|
46
|
+
"@hot-updater/plugin-core": "0.25.10",
|
|
47
|
+
"@hot-updater/js": "0.25.10"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@cloudflare/vitest-pool-workers": "^0.8.70",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"vitest": "2.1.8",
|
|
63
63
|
"wrangler": "^4.5.0",
|
|
64
64
|
"xdg-app-paths": "^8.3.0",
|
|
65
|
-
"@hot-updater/test-utils": "0.25.
|
|
65
|
+
"@hot-updater/test-utils": "0.25.10"
|
|
66
66
|
},
|
|
67
67
|
"scripts": {
|
|
68
68
|
"build": "tsdown && pnpm build:worker",
|
package/worker/dist/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
This folder contains the built output assets for the worker "hot-updater" generated at 2026-02-
|
|
1
|
+
This folder contains the built output assets for the worker "hot-updater" generated at 2026-02-19T00:58:25.738Z.
|
package/worker/dist/index.js
CHANGED
|
@@ -906,6 +906,26 @@ var process_default = _process;
|
|
|
906
906
|
globalThis.process = process_default;
|
|
907
907
|
|
|
908
908
|
// ../../packages/core/dist/index.js
|
|
909
|
+
import path from "path";
|
|
910
|
+
var HOT_UPDATE_DIR_NAME = ".hot-updater";
|
|
911
|
+
var HOT_UPDATE_OUTPUT_DIR_NAME = "output";
|
|
912
|
+
var HOT_UPDATE_LOG_DIR_NAME = "log";
|
|
913
|
+
var HotUpdateDirUtil = {
|
|
914
|
+
dirName: HOT_UPDATE_DIR_NAME,
|
|
915
|
+
outputDirName: HOT_UPDATE_OUTPUT_DIR_NAME,
|
|
916
|
+
logDirName: HOT_UPDATE_LOG_DIR_NAME,
|
|
917
|
+
outputGitignorePath: `${HOT_UPDATE_DIR_NAME}/${HOT_UPDATE_OUTPUT_DIR_NAME}`,
|
|
918
|
+
logGitignorePath: `${HOT_UPDATE_DIR_NAME}/${HOT_UPDATE_LOG_DIR_NAME}`,
|
|
919
|
+
getDirPath: /* @__PURE__ */ __name(({ cwd: cwd2 }) => {
|
|
920
|
+
return path.join(cwd2, HOT_UPDATE_DIR_NAME);
|
|
921
|
+
}, "getDirPath"),
|
|
922
|
+
getDefaultOutputPath: /* @__PURE__ */ __name(({ cwd: cwd2 }) => {
|
|
923
|
+
return path.join(cwd2, HOT_UPDATE_DIR_NAME, HOT_UPDATE_OUTPUT_DIR_NAME);
|
|
924
|
+
}, "getDefaultOutputPath"),
|
|
925
|
+
getLogDirPath: /* @__PURE__ */ __name(({ cwd: cwd2 }) => {
|
|
926
|
+
return path.join(cwd2, HOT_UPDATE_DIR_NAME, HOT_UPDATE_LOG_DIR_NAME);
|
|
927
|
+
}, "getLogDirPath")
|
|
928
|
+
};
|
|
909
929
|
var NIL_UUID = "00000000-0000-0000-0000-000000000000";
|
|
910
930
|
|
|
911
931
|
// ../js/dist/index.js
|
|
@@ -3330,8 +3350,8 @@ var SignJWT = class {
|
|
|
3330
3350
|
return sig.sign(key, options);
|
|
3331
3351
|
}
|
|
3332
3352
|
};
|
|
3333
|
-
var verifyJwtToken = /* @__PURE__ */ __name(async ({ path, token, jwtSecret }) => {
|
|
3334
|
-
const key =
|
|
3353
|
+
var verifyJwtToken = /* @__PURE__ */ __name(async ({ path: path2, token, jwtSecret }) => {
|
|
3354
|
+
const key = path2.replace(/^\/+/, "");
|
|
3335
3355
|
if (!token) return {
|
|
3336
3356
|
valid: false,
|
|
3337
3357
|
error: "Missing token"
|
|
@@ -3370,9 +3390,9 @@ var getFileResponse = /* @__PURE__ */ __name(async ({ key, handler }) => {
|
|
|
3370
3390
|
responseBody: object.body
|
|
3371
3391
|
};
|
|
3372
3392
|
}, "getFileResponse");
|
|
3373
|
-
var verifyJwtSignedUrl = /* @__PURE__ */ __name(async ({ path, token, jwtSecret, handler }) => {
|
|
3393
|
+
var verifyJwtSignedUrl = /* @__PURE__ */ __name(async ({ path: path2, token, jwtSecret, handler }) => {
|
|
3374
3394
|
const result = await verifyJwtToken({
|
|
3375
|
-
path,
|
|
3395
|
+
path: path2,
|
|
3376
3396
|
token,
|
|
3377
3397
|
jwtSecret
|
|
3378
3398
|
});
|
|
@@ -3482,26 +3502,26 @@ var handleParsingNestedValues = /* @__PURE__ */ __name((form, key, value) => {
|
|
|
3482
3502
|
}, "handleParsingNestedValues");
|
|
3483
3503
|
|
|
3484
3504
|
// ../../node_modules/.pnpm/hono@4.6.3/node_modules/hono/dist/utils/url.js
|
|
3485
|
-
var splitPath = /* @__PURE__ */ __name((
|
|
3486
|
-
const paths =
|
|
3505
|
+
var splitPath = /* @__PURE__ */ __name((path2) => {
|
|
3506
|
+
const paths = path2.split("/");
|
|
3487
3507
|
if (paths[0] === "") {
|
|
3488
3508
|
paths.shift();
|
|
3489
3509
|
}
|
|
3490
3510
|
return paths;
|
|
3491
3511
|
}, "splitPath");
|
|
3492
3512
|
var splitRoutingPath = /* @__PURE__ */ __name((routePath) => {
|
|
3493
|
-
const { groups, path } = extractGroupsFromPath(routePath);
|
|
3494
|
-
const paths = splitPath(
|
|
3513
|
+
const { groups, path: path2 } = extractGroupsFromPath(routePath);
|
|
3514
|
+
const paths = splitPath(path2);
|
|
3495
3515
|
return replaceGroupMarks(paths, groups);
|
|
3496
3516
|
}, "splitRoutingPath");
|
|
3497
|
-
var extractGroupsFromPath = /* @__PURE__ */ __name((
|
|
3517
|
+
var extractGroupsFromPath = /* @__PURE__ */ __name((path2) => {
|
|
3498
3518
|
const groups = [];
|
|
3499
|
-
|
|
3519
|
+
path2 = path2.replace(/\{[^}]+\}/g, (match, index) => {
|
|
3500
3520
|
const mark = `@${index}`;
|
|
3501
3521
|
groups.push([mark, match]);
|
|
3502
3522
|
return mark;
|
|
3503
3523
|
});
|
|
3504
|
-
return { groups, path };
|
|
3524
|
+
return { groups, path: path2 };
|
|
3505
3525
|
}, "extractGroupsFromPath");
|
|
3506
3526
|
var replaceGroupMarks = /* @__PURE__ */ __name((paths, groups) => {
|
|
3507
3527
|
for (let i = groups.length - 1; i >= 0; i--) {
|
|
@@ -3554,8 +3574,8 @@ var getPath = /* @__PURE__ */ __name((request) => {
|
|
|
3554
3574
|
const charCode = url.charCodeAt(i);
|
|
3555
3575
|
if (charCode === 37) {
|
|
3556
3576
|
const queryIndex = url.indexOf("?", i);
|
|
3557
|
-
const
|
|
3558
|
-
return tryDecodeURI(
|
|
3577
|
+
const path2 = url.slice(start, queryIndex === -1 ? void 0 : queryIndex);
|
|
3578
|
+
return tryDecodeURI(path2.includes("%25") ? path2.replace(/%25/g, "%2525") : path2);
|
|
3559
3579
|
} else if (charCode === 63) {
|
|
3560
3580
|
break;
|
|
3561
3581
|
}
|
|
@@ -3569,30 +3589,30 @@ var getPathNoStrict = /* @__PURE__ */ __name((request) => {
|
|
|
3569
3589
|
var mergePath = /* @__PURE__ */ __name((...paths) => {
|
|
3570
3590
|
let p = "";
|
|
3571
3591
|
let endsWithSlash = false;
|
|
3572
|
-
for (let
|
|
3592
|
+
for (let path2 of paths) {
|
|
3573
3593
|
if (p[p.length - 1] === "/") {
|
|
3574
3594
|
p = p.slice(0, -1);
|
|
3575
3595
|
endsWithSlash = true;
|
|
3576
3596
|
}
|
|
3577
|
-
if (
|
|
3578
|
-
|
|
3597
|
+
if (path2[0] !== "/") {
|
|
3598
|
+
path2 = `/${path2}`;
|
|
3579
3599
|
}
|
|
3580
|
-
if (
|
|
3600
|
+
if (path2 === "/" && endsWithSlash) {
|
|
3581
3601
|
p = `${p}/`;
|
|
3582
|
-
} else if (
|
|
3583
|
-
p = `${p}${
|
|
3602
|
+
} else if (path2 !== "/") {
|
|
3603
|
+
p = `${p}${path2}`;
|
|
3584
3604
|
}
|
|
3585
|
-
if (
|
|
3605
|
+
if (path2 === "/" && p === "") {
|
|
3586
3606
|
p = "/";
|
|
3587
3607
|
}
|
|
3588
3608
|
}
|
|
3589
3609
|
return p;
|
|
3590
3610
|
}, "mergePath");
|
|
3591
|
-
var checkOptionalParameter = /* @__PURE__ */ __name((
|
|
3592
|
-
if (!
|
|
3611
|
+
var checkOptionalParameter = /* @__PURE__ */ __name((path2) => {
|
|
3612
|
+
if (!path2.match(/\:.+\?$/)) {
|
|
3593
3613
|
return null;
|
|
3594
3614
|
}
|
|
3595
|
-
const segments =
|
|
3615
|
+
const segments = path2.split("/");
|
|
3596
3616
|
const results = [];
|
|
3597
3617
|
let basePath = "";
|
|
3598
3618
|
segments.forEach((segment) => {
|
|
@@ -3705,9 +3725,9 @@ var HonoRequest = class {
|
|
|
3705
3725
|
routeIndex = 0;
|
|
3706
3726
|
path;
|
|
3707
3727
|
bodyCache = {};
|
|
3708
|
-
constructor(request,
|
|
3728
|
+
constructor(request, path2 = "/", matchResult = [[]]) {
|
|
3709
3729
|
this.raw = request;
|
|
3710
|
-
this.path =
|
|
3730
|
+
this.path = path2;
|
|
3711
3731
|
this.#matchResult = matchResult;
|
|
3712
3732
|
this.#validatedData = {};
|
|
3713
3733
|
}
|
|
@@ -4199,8 +4219,8 @@ var Hono = class {
|
|
|
4199
4219
|
return this;
|
|
4200
4220
|
};
|
|
4201
4221
|
});
|
|
4202
|
-
this.on = (method,
|
|
4203
|
-
for (const p of [
|
|
4222
|
+
this.on = (method, path2, ...handlers) => {
|
|
4223
|
+
for (const p of [path2].flat()) {
|
|
4204
4224
|
this.#path = p;
|
|
4205
4225
|
for (const m of [method].flat()) {
|
|
4206
4226
|
handlers.map((handler) => {
|
|
@@ -4237,8 +4257,8 @@ var Hono = class {
|
|
|
4237
4257
|
}
|
|
4238
4258
|
notFoundHandler = notFoundHandler;
|
|
4239
4259
|
errorHandler = errorHandler;
|
|
4240
|
-
route(
|
|
4241
|
-
const subApp = this.basePath(
|
|
4260
|
+
route(path2, app2) {
|
|
4261
|
+
const subApp = this.basePath(path2);
|
|
4242
4262
|
app2.routes.map((r) => {
|
|
4243
4263
|
let handler;
|
|
4244
4264
|
if (app2.errorHandler === errorHandler) {
|
|
@@ -4251,9 +4271,9 @@ var Hono = class {
|
|
|
4251
4271
|
});
|
|
4252
4272
|
return this;
|
|
4253
4273
|
}
|
|
4254
|
-
basePath(
|
|
4274
|
+
basePath(path2) {
|
|
4255
4275
|
const subApp = this.clone();
|
|
4256
|
-
subApp._basePath = mergePath(this._basePath,
|
|
4276
|
+
subApp._basePath = mergePath(this._basePath, path2);
|
|
4257
4277
|
return subApp;
|
|
4258
4278
|
}
|
|
4259
4279
|
onError = /* @__PURE__ */ __name((handler) => {
|
|
@@ -4264,7 +4284,7 @@ var Hono = class {
|
|
|
4264
4284
|
this.notFoundHandler = handler;
|
|
4265
4285
|
return this;
|
|
4266
4286
|
}, "notFound");
|
|
4267
|
-
mount(
|
|
4287
|
+
mount(path2, applicationHandler, options) {
|
|
4268
4288
|
let replaceRequest;
|
|
4269
4289
|
let optionHandler;
|
|
4270
4290
|
if (options) {
|
|
@@ -4287,7 +4307,7 @@ var Hono = class {
|
|
|
4287
4307
|
return [c.env, executionContext];
|
|
4288
4308
|
};
|
|
4289
4309
|
replaceRequest ||= (() => {
|
|
4290
|
-
const mergedPath = mergePath(this._basePath,
|
|
4310
|
+
const mergedPath = mergePath(this._basePath, path2);
|
|
4291
4311
|
const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
|
|
4292
4312
|
return (request) => {
|
|
4293
4313
|
const url = new URL(request.url);
|
|
@@ -4302,18 +4322,18 @@ var Hono = class {
|
|
|
4302
4322
|
}
|
|
4303
4323
|
await next();
|
|
4304
4324
|
}, "handler");
|
|
4305
|
-
this.addRoute(METHOD_NAME_ALL, mergePath(
|
|
4325
|
+
this.addRoute(METHOD_NAME_ALL, mergePath(path2, "*"), handler);
|
|
4306
4326
|
return this;
|
|
4307
4327
|
}
|
|
4308
|
-
addRoute(method,
|
|
4328
|
+
addRoute(method, path2, handler) {
|
|
4309
4329
|
method = method.toUpperCase();
|
|
4310
|
-
|
|
4311
|
-
const r = { path, method, handler };
|
|
4312
|
-
this.router.add(method,
|
|
4330
|
+
path2 = mergePath(this._basePath, path2);
|
|
4331
|
+
const r = { path: path2, method, handler };
|
|
4332
|
+
this.router.add(method, path2, [handler, r]);
|
|
4313
4333
|
this.routes.push(r);
|
|
4314
4334
|
}
|
|
4315
|
-
matchRoute(method,
|
|
4316
|
-
return this.router.match(method,
|
|
4335
|
+
matchRoute(method, path2) {
|
|
4336
|
+
return this.router.match(method, path2);
|
|
4317
4337
|
}
|
|
4318
4338
|
handleError(err, c) {
|
|
4319
4339
|
if (err instanceof Error) {
|
|
@@ -4325,10 +4345,10 @@ var Hono = class {
|
|
|
4325
4345
|
if (method === "HEAD") {
|
|
4326
4346
|
return (async () => new Response(null, await this.dispatch(request, executionCtx, env2, "GET")))();
|
|
4327
4347
|
}
|
|
4328
|
-
const
|
|
4329
|
-
const matchResult = this.matchRoute(method,
|
|
4348
|
+
const path2 = this.getPath(request, { env: env2 });
|
|
4349
|
+
const matchResult = this.matchRoute(method, path2);
|
|
4330
4350
|
const c = new Context(request, {
|
|
4331
|
-
path,
|
|
4351
|
+
path: path2,
|
|
4332
4352
|
matchResult,
|
|
4333
4353
|
env: env2,
|
|
4334
4354
|
executionCtx,
|
|
@@ -4373,8 +4393,8 @@ var Hono = class {
|
|
|
4373
4393
|
return this.fetch(input, Env, executionCtx);
|
|
4374
4394
|
}
|
|
4375
4395
|
input = input.toString();
|
|
4376
|
-
const
|
|
4377
|
-
const req = new Request(
|
|
4396
|
+
const path2 = /^https?:\/\//.test(input) ? input : `http://localhost${mergePath("/", input)}`;
|
|
4397
|
+
const req = new Request(path2, requestInit);
|
|
4378
4398
|
return this.fetch(req, Env, executionCtx);
|
|
4379
4399
|
}, "request");
|
|
4380
4400
|
fire = /* @__PURE__ */ __name(() => {
|
|
@@ -4500,12 +4520,12 @@ var Trie = class {
|
|
|
4500
4520
|
}
|
|
4501
4521
|
context = { varIndex: 0 };
|
|
4502
4522
|
root = new Node();
|
|
4503
|
-
insert(
|
|
4523
|
+
insert(path2, index, pathErrorCheckOnly) {
|
|
4504
4524
|
const paramAssoc = [];
|
|
4505
4525
|
const groups = [];
|
|
4506
4526
|
for (let i = 0; ; ) {
|
|
4507
4527
|
let replaced = false;
|
|
4508
|
-
|
|
4528
|
+
path2 = path2.replace(/\{[^}]+\}/g, (m) => {
|
|
4509
4529
|
const mark = `@\\${i}`;
|
|
4510
4530
|
groups[i] = [mark, m];
|
|
4511
4531
|
i++;
|
|
@@ -4516,7 +4536,7 @@ var Trie = class {
|
|
|
4516
4536
|
break;
|
|
4517
4537
|
}
|
|
4518
4538
|
}
|
|
4519
|
-
const tokens =
|
|
4539
|
+
const tokens = path2.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
|
|
4520
4540
|
for (let i = groups.length - 1; i >= 0; i--) {
|
|
4521
4541
|
const [mark] = groups[i];
|
|
4522
4542
|
for (let j = tokens.length - 1; j >= 0; j--) {
|
|
@@ -4556,9 +4576,9 @@ var Trie = class {
|
|
|
4556
4576
|
var emptyParam = [];
|
|
4557
4577
|
var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
|
|
4558
4578
|
var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
4559
|
-
function buildWildcardRegExp(
|
|
4560
|
-
return wildcardRegExpCache[
|
|
4561
|
-
|
|
4579
|
+
function buildWildcardRegExp(path2) {
|
|
4580
|
+
return wildcardRegExpCache[path2] ??= new RegExp(
|
|
4581
|
+
path2 === "*" ? "" : `^${path2.replace(
|
|
4562
4582
|
/\/\*$|([.\\+*[^\]$()])/g,
|
|
4563
4583
|
(_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)"
|
|
4564
4584
|
)}$`
|
|
@@ -4582,17 +4602,17 @@ function buildMatcherFromPreprocessedRoutes(routes) {
|
|
|
4582
4602
|
);
|
|
4583
4603
|
const staticMap = /* @__PURE__ */ Object.create(null);
|
|
4584
4604
|
for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) {
|
|
4585
|
-
const [pathErrorCheckOnly,
|
|
4605
|
+
const [pathErrorCheckOnly, path2, handlers] = routesWithStaticPathFlag[i];
|
|
4586
4606
|
if (pathErrorCheckOnly) {
|
|
4587
|
-
staticMap[
|
|
4607
|
+
staticMap[path2] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
|
|
4588
4608
|
} else {
|
|
4589
4609
|
j++;
|
|
4590
4610
|
}
|
|
4591
4611
|
let paramAssoc;
|
|
4592
4612
|
try {
|
|
4593
|
-
paramAssoc = trie.insert(
|
|
4613
|
+
paramAssoc = trie.insert(path2, j, pathErrorCheckOnly);
|
|
4594
4614
|
} catch (e) {
|
|
4595
|
-
throw e === PATH_ERROR ? new UnsupportedPathError(
|
|
4615
|
+
throw e === PATH_ERROR ? new UnsupportedPathError(path2) : e;
|
|
4596
4616
|
}
|
|
4597
4617
|
if (pathErrorCheckOnly) {
|
|
4598
4618
|
continue;
|
|
@@ -4627,12 +4647,12 @@ function buildMatcherFromPreprocessedRoutes(routes) {
|
|
|
4627
4647
|
return [regexp, handlerMap, staticMap];
|
|
4628
4648
|
}
|
|
4629
4649
|
__name(buildMatcherFromPreprocessedRoutes, "buildMatcherFromPreprocessedRoutes");
|
|
4630
|
-
function findMiddleware(middleware,
|
|
4650
|
+
function findMiddleware(middleware, path2) {
|
|
4631
4651
|
if (!middleware) {
|
|
4632
4652
|
return void 0;
|
|
4633
4653
|
}
|
|
4634
4654
|
for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) {
|
|
4635
|
-
if (buildWildcardRegExp(k).test(
|
|
4655
|
+
if (buildWildcardRegExp(k).test(path2)) {
|
|
4636
4656
|
return [...middleware[k]];
|
|
4637
4657
|
}
|
|
4638
4658
|
}
|
|
@@ -4650,7 +4670,7 @@ var RegExpRouter = class {
|
|
|
4650
4670
|
this.middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
4651
4671
|
this.routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
|
|
4652
4672
|
}
|
|
4653
|
-
add(method,
|
|
4673
|
+
add(method, path2, handler) {
|
|
4654
4674
|
const { middleware, routes } = this;
|
|
4655
4675
|
if (!middleware || !routes) {
|
|
4656
4676
|
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
@@ -4664,18 +4684,18 @@ var RegExpRouter = class {
|
|
|
4664
4684
|
});
|
|
4665
4685
|
});
|
|
4666
4686
|
}
|
|
4667
|
-
if (
|
|
4668
|
-
|
|
4687
|
+
if (path2 === "/*") {
|
|
4688
|
+
path2 = "*";
|
|
4669
4689
|
}
|
|
4670
|
-
const paramCount = (
|
|
4671
|
-
if (/\*$/.test(
|
|
4672
|
-
const re = buildWildcardRegExp(
|
|
4690
|
+
const paramCount = (path2.match(/\/:/g) || []).length;
|
|
4691
|
+
if (/\*$/.test(path2)) {
|
|
4692
|
+
const re = buildWildcardRegExp(path2);
|
|
4673
4693
|
if (method === METHOD_NAME_ALL) {
|
|
4674
4694
|
Object.keys(middleware).forEach((m) => {
|
|
4675
|
-
middleware[m][
|
|
4695
|
+
middleware[m][path2] ||= findMiddleware(middleware[m], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || [];
|
|
4676
4696
|
});
|
|
4677
4697
|
} else {
|
|
4678
|
-
middleware[method][
|
|
4698
|
+
middleware[method][path2] ||= findMiddleware(middleware[method], path2) || findMiddleware(middleware[METHOD_NAME_ALL], path2) || [];
|
|
4679
4699
|
}
|
|
4680
4700
|
Object.keys(middleware).forEach((m) => {
|
|
4681
4701
|
if (method === METHOD_NAME_ALL || method === m) {
|
|
@@ -4693,36 +4713,36 @@ var RegExpRouter = class {
|
|
|
4693
4713
|
});
|
|
4694
4714
|
return;
|
|
4695
4715
|
}
|
|
4696
|
-
const paths = checkOptionalParameter(
|
|
4716
|
+
const paths = checkOptionalParameter(path2) || [path2];
|
|
4697
4717
|
for (let i = 0, len = paths.length; i < len; i++) {
|
|
4698
|
-
const
|
|
4718
|
+
const path22 = paths[i];
|
|
4699
4719
|
Object.keys(routes).forEach((m) => {
|
|
4700
4720
|
if (method === METHOD_NAME_ALL || method === m) {
|
|
4701
|
-
routes[m][
|
|
4702
|
-
...findMiddleware(middleware[m],
|
|
4721
|
+
routes[m][path22] ||= [
|
|
4722
|
+
...findMiddleware(middleware[m], path22) || findMiddleware(middleware[METHOD_NAME_ALL], path22) || []
|
|
4703
4723
|
];
|
|
4704
|
-
routes[m][
|
|
4724
|
+
routes[m][path22].push([handler, paramCount - len + i + 1]);
|
|
4705
4725
|
}
|
|
4706
4726
|
});
|
|
4707
4727
|
}
|
|
4708
4728
|
}
|
|
4709
|
-
match(method,
|
|
4729
|
+
match(method, path2) {
|
|
4710
4730
|
clearWildcardRegExpCache();
|
|
4711
4731
|
const matchers = this.buildAllMatchers();
|
|
4712
|
-
this.match = (method2,
|
|
4732
|
+
this.match = (method2, path22) => {
|
|
4713
4733
|
const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
|
|
4714
|
-
const staticMatch = matcher[2][
|
|
4734
|
+
const staticMatch = matcher[2][path22];
|
|
4715
4735
|
if (staticMatch) {
|
|
4716
4736
|
return staticMatch;
|
|
4717
4737
|
}
|
|
4718
|
-
const match =
|
|
4738
|
+
const match = path22.match(matcher[0]);
|
|
4719
4739
|
if (!match) {
|
|
4720
4740
|
return [[], emptyParam];
|
|
4721
4741
|
}
|
|
4722
4742
|
const index = match.indexOf("", 1);
|
|
4723
4743
|
return [matcher[1][index], match];
|
|
4724
4744
|
};
|
|
4725
|
-
return this.match(method,
|
|
4745
|
+
return this.match(method, path2);
|
|
4726
4746
|
}
|
|
4727
4747
|
buildAllMatchers() {
|
|
4728
4748
|
const matchers = /* @__PURE__ */ Object.create(null);
|
|
@@ -4736,13 +4756,13 @@ var RegExpRouter = class {
|
|
|
4736
4756
|
const routes = [];
|
|
4737
4757
|
let hasOwnRoute = method === METHOD_NAME_ALL;
|
|
4738
4758
|
[this.middleware, this.routes].forEach((r) => {
|
|
4739
|
-
const ownRoute = r[method] ? Object.keys(r[method]).map((
|
|
4759
|
+
const ownRoute = r[method] ? Object.keys(r[method]).map((path2) => [path2, r[method][path2]]) : [];
|
|
4740
4760
|
if (ownRoute.length !== 0) {
|
|
4741
4761
|
hasOwnRoute ||= true;
|
|
4742
4762
|
routes.push(...ownRoute);
|
|
4743
4763
|
} else if (method !== METHOD_NAME_ALL) {
|
|
4744
4764
|
routes.push(
|
|
4745
|
-
...Object.keys(r[METHOD_NAME_ALL]).map((
|
|
4765
|
+
...Object.keys(r[METHOD_NAME_ALL]).map((path2) => [path2, r[METHOD_NAME_ALL][path2]])
|
|
4746
4766
|
);
|
|
4747
4767
|
}
|
|
4748
4768
|
});
|
|
@@ -4765,13 +4785,13 @@ var SmartRouter = class {
|
|
|
4765
4785
|
constructor(init) {
|
|
4766
4786
|
Object.assign(this, init);
|
|
4767
4787
|
}
|
|
4768
|
-
add(method,
|
|
4788
|
+
add(method, path2, handler) {
|
|
4769
4789
|
if (!this.routes) {
|
|
4770
4790
|
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
|
4771
4791
|
}
|
|
4772
|
-
this.routes.push([method,
|
|
4792
|
+
this.routes.push([method, path2, handler]);
|
|
4773
4793
|
}
|
|
4774
|
-
match(method,
|
|
4794
|
+
match(method, path2) {
|
|
4775
4795
|
if (!this.routes) {
|
|
4776
4796
|
throw new Error("Fatal error");
|
|
4777
4797
|
}
|
|
@@ -4785,7 +4805,7 @@ var SmartRouter = class {
|
|
|
4785
4805
|
routes.forEach((args) => {
|
|
4786
4806
|
router.add(...args);
|
|
4787
4807
|
});
|
|
4788
|
-
res = router.match(method,
|
|
4808
|
+
res = router.match(method, path2);
|
|
4789
4809
|
} catch (e) {
|
|
4790
4810
|
if (e instanceof UnsupportedPathError) {
|
|
4791
4811
|
continue;
|
|
@@ -4833,11 +4853,11 @@ var Node2 = class {
|
|
|
4833
4853
|
}
|
|
4834
4854
|
this.patterns = [];
|
|
4835
4855
|
}
|
|
4836
|
-
insert(method,
|
|
4837
|
-
this.name = `${method} ${
|
|
4856
|
+
insert(method, path2, handler) {
|
|
4857
|
+
this.name = `${method} ${path2}`;
|
|
4838
4858
|
this.order = ++this.order;
|
|
4839
4859
|
let curNode = this;
|
|
4840
|
-
const parts = splitRoutingPath(
|
|
4860
|
+
const parts = splitRoutingPath(path2);
|
|
4841
4861
|
const possibleKeys = [];
|
|
4842
4862
|
for (let i = 0, len = parts.length; i < len; i++) {
|
|
4843
4863
|
const p = parts[i];
|
|
@@ -4889,12 +4909,12 @@ var Node2 = class {
|
|
|
4889
4909
|
}
|
|
4890
4910
|
return handlerSets;
|
|
4891
4911
|
}
|
|
4892
|
-
search(method,
|
|
4912
|
+
search(method, path2) {
|
|
4893
4913
|
const handlerSets = [];
|
|
4894
4914
|
this.params = /* @__PURE__ */ Object.create(null);
|
|
4895
4915
|
const curNode = this;
|
|
4896
4916
|
let curNodes = [curNode];
|
|
4897
|
-
const parts = splitPath(
|
|
4917
|
+
const parts = splitPath(path2);
|
|
4898
4918
|
for (let i = 0, len = parts.length; i < len; i++) {
|
|
4899
4919
|
const part = parts[i];
|
|
4900
4920
|
const isLast = i === len - 1;
|
|
@@ -4972,18 +4992,18 @@ var TrieRouter = class {
|
|
|
4972
4992
|
constructor() {
|
|
4973
4993
|
this.node = new Node2();
|
|
4974
4994
|
}
|
|
4975
|
-
add(method,
|
|
4976
|
-
const results = checkOptionalParameter(
|
|
4995
|
+
add(method, path2, handler) {
|
|
4996
|
+
const results = checkOptionalParameter(path2);
|
|
4977
4997
|
if (results) {
|
|
4978
4998
|
for (const p of results) {
|
|
4979
4999
|
this.node.insert(method, p, handler);
|
|
4980
5000
|
}
|
|
4981
5001
|
return;
|
|
4982
5002
|
}
|
|
4983
|
-
this.node.insert(method,
|
|
5003
|
+
this.node.insert(method, path2, handler);
|
|
4984
5004
|
}
|
|
4985
|
-
match(method,
|
|
4986
|
-
return this.node.search(method,
|
|
5005
|
+
match(method, path2) {
|
|
5006
|
+
return this.node.search(method, path2);
|
|
4987
5007
|
}
|
|
4988
5008
|
};
|
|
4989
5009
|
|