@kevisual/router 0.0.33 → 0.0.35
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/router-browser.d.ts +24 -3
- package/dist/router-browser.js +80 -81
- package/dist/router-sign.d.ts +2 -2
- package/dist/router-sign.js +13711 -28503
- package/dist/router-simple.d.ts +18 -1
- package/dist/router-simple.js +24 -3
- package/dist/router.d.ts +24 -3
- package/dist/router.js +266 -156
- package/package.json +8 -8
- package/src/route.ts +29 -41
- package/src/router-simple.ts +28 -3
- package/src/test/listen-ip.ts +18 -0
package/dist/router.js
CHANGED
|
@@ -119,21 +119,30 @@ try {
|
|
|
119
119
|
/** A special constant with type `never` */
|
|
120
120
|
function $constructor(name, initializer, params) {
|
|
121
121
|
function init(inst, def) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
122
|
+
if (!inst._zod) {
|
|
123
|
+
Object.defineProperty(inst, "_zod", {
|
|
124
|
+
value: {
|
|
125
|
+
def,
|
|
126
|
+
constr: _,
|
|
127
|
+
traits: new Set(),
|
|
128
|
+
},
|
|
129
|
+
enumerable: false,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
if (inst._zod.traits.has(name)) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
128
135
|
inst._zod.traits.add(name);
|
|
129
136
|
initializer(inst, def);
|
|
130
137
|
// support prototype modifications
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
138
|
+
const proto = _.prototype;
|
|
139
|
+
const keys = Object.keys(proto);
|
|
140
|
+
for (let i = 0; i < keys.length; i++) {
|
|
141
|
+
const k = keys[i];
|
|
142
|
+
if (!(k in inst)) {
|
|
143
|
+
inst[k] = proto[k].bind(inst);
|
|
144
|
+
}
|
|
134
145
|
}
|
|
135
|
-
inst._zod.constr = _;
|
|
136
|
-
inst._zod.def = def;
|
|
137
146
|
}
|
|
138
147
|
// doesn't work if Parent has a constructor with arguments
|
|
139
148
|
const Parent = params?.Parent ?? Object;
|
|
@@ -268,6 +277,14 @@ function mergeDefs(...defs) {
|
|
|
268
277
|
function esc(str) {
|
|
269
278
|
return JSON.stringify(str);
|
|
270
279
|
}
|
|
280
|
+
function slugify(input) {
|
|
281
|
+
return input
|
|
282
|
+
.toLowerCase()
|
|
283
|
+
.trim()
|
|
284
|
+
.replace(/[^\w\s-]/g, "")
|
|
285
|
+
.replace(/[\s_-]+/g, "-")
|
|
286
|
+
.replace(/^-+|-+$/g, "");
|
|
287
|
+
}
|
|
271
288
|
const captureStackTrace = ("captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => { });
|
|
272
289
|
function isObject$1(data) {
|
|
273
290
|
return typeof data === "object" && data !== null && !Array.isArray(data);
|
|
@@ -293,6 +310,8 @@ function isPlainObject(o) {
|
|
|
293
310
|
const ctor = o.constructor;
|
|
294
311
|
if (ctor === undefined)
|
|
295
312
|
return true;
|
|
313
|
+
if (typeof ctor !== "function")
|
|
314
|
+
return true;
|
|
296
315
|
// modified prototype
|
|
297
316
|
const prot = ctor.prototype;
|
|
298
317
|
if (isObject$1(prot) === false)
|
|
@@ -756,9 +775,6 @@ const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?:
|
|
|
756
775
|
// https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
|
|
757
776
|
const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
|
|
758
777
|
const base64url = /^[A-Za-z0-9_-]*$/;
|
|
759
|
-
// based on https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address
|
|
760
|
-
// export const hostname: RegExp = /^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;
|
|
761
|
-
const hostname = /^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/;
|
|
762
778
|
// https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces)
|
|
763
779
|
const e164 = /^\+(?:[0-9]){6,14}[0-9]$/;
|
|
764
780
|
// const dateSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
|
|
@@ -1249,7 +1265,7 @@ class Doc {
|
|
|
1249
1265
|
const version = {
|
|
1250
1266
|
major: 4,
|
|
1251
1267
|
minor: 1,
|
|
1252
|
-
patch:
|
|
1268
|
+
patch: 13,
|
|
1253
1269
|
};
|
|
1254
1270
|
|
|
1255
1271
|
const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
|
|
@@ -1452,7 +1468,7 @@ const $ZodURL = /*@__PURE__*/ $constructor("$ZodURL", (inst, def) => {
|
|
|
1452
1468
|
code: "invalid_format",
|
|
1453
1469
|
format: "url",
|
|
1454
1470
|
note: "Invalid hostname",
|
|
1455
|
-
pattern: hostname.source,
|
|
1471
|
+
pattern: def.hostname.source,
|
|
1456
1472
|
input: payload.value,
|
|
1457
1473
|
inst,
|
|
1458
1474
|
continue: !def.abort,
|
|
@@ -1542,18 +1558,12 @@ const $ZodISODuration = /*@__PURE__*/ $constructor("$ZodISODuration", (inst, def
|
|
|
1542
1558
|
const $ZodIPv4 = /*@__PURE__*/ $constructor("$ZodIPv4", (inst, def) => {
|
|
1543
1559
|
def.pattern ?? (def.pattern = ipv4);
|
|
1544
1560
|
$ZodStringFormat.init(inst, def);
|
|
1545
|
-
inst._zod.
|
|
1546
|
-
const bag = inst._zod.bag;
|
|
1547
|
-
bag.format = `ipv4`;
|
|
1548
|
-
});
|
|
1561
|
+
inst._zod.bag.format = `ipv4`;
|
|
1549
1562
|
});
|
|
1550
1563
|
const $ZodIPv6 = /*@__PURE__*/ $constructor("$ZodIPv6", (inst, def) => {
|
|
1551
1564
|
def.pattern ?? (def.pattern = ipv6);
|
|
1552
1565
|
$ZodStringFormat.init(inst, def);
|
|
1553
|
-
inst._zod.
|
|
1554
|
-
const bag = inst._zod.bag;
|
|
1555
|
-
bag.format = `ipv6`;
|
|
1556
|
-
});
|
|
1566
|
+
inst._zod.bag.format = `ipv6`;
|
|
1557
1567
|
inst._zod.check = (payload) => {
|
|
1558
1568
|
try {
|
|
1559
1569
|
// @ts-ignore
|
|
@@ -1623,9 +1633,7 @@ function isValidBase64(data) {
|
|
|
1623
1633
|
const $ZodBase64 = /*@__PURE__*/ $constructor("$ZodBase64", (inst, def) => {
|
|
1624
1634
|
def.pattern ?? (def.pattern = base64);
|
|
1625
1635
|
$ZodStringFormat.init(inst, def);
|
|
1626
|
-
inst._zod.
|
|
1627
|
-
inst._zod.bag.contentEncoding = "base64";
|
|
1628
|
-
});
|
|
1636
|
+
inst._zod.bag.contentEncoding = "base64";
|
|
1629
1637
|
inst._zod.check = (payload) => {
|
|
1630
1638
|
if (isValidBase64(payload.value))
|
|
1631
1639
|
return;
|
|
@@ -1649,9 +1657,7 @@ function isValidBase64URL(data) {
|
|
|
1649
1657
|
const $ZodBase64URL = /*@__PURE__*/ $constructor("$ZodBase64URL", (inst, def) => {
|
|
1650
1658
|
def.pattern ?? (def.pattern = base64url);
|
|
1651
1659
|
$ZodStringFormat.init(inst, def);
|
|
1652
|
-
inst._zod.
|
|
1653
|
-
inst._zod.bag.contentEncoding = "base64url";
|
|
1654
|
-
});
|
|
1660
|
+
inst._zod.bag.contentEncoding = "base64url";
|
|
1655
1661
|
inst._zod.check = (payload) => {
|
|
1656
1662
|
if (isValidBase64URL(payload.value))
|
|
1657
1663
|
return;
|
|
@@ -1735,9 +1741,9 @@ const $ZodNumber = /*@__PURE__*/ $constructor("$ZodNumber", (inst, def) => {
|
|
|
1735
1741
|
return payload;
|
|
1736
1742
|
};
|
|
1737
1743
|
});
|
|
1738
|
-
const $ZodNumberFormat = /*@__PURE__*/ $constructor("$
|
|
1744
|
+
const $ZodNumberFormat = /*@__PURE__*/ $constructor("$ZodNumberFormat", (inst, def) => {
|
|
1739
1745
|
$ZodCheckNumberFormat.init(inst, def);
|
|
1740
|
-
$ZodNumber.init(inst, def); // no format
|
|
1746
|
+
$ZodNumber.init(inst, def); // no format checks
|
|
1741
1747
|
});
|
|
1742
1748
|
const $ZodBoolean = /*@__PURE__*/ $constructor("$ZodBoolean", (inst, def) => {
|
|
1743
1749
|
$ZodType.init(inst, def);
|
|
@@ -1855,7 +1861,7 @@ function handleCatchall(proms, input, payload, ctx, def, inst) {
|
|
|
1855
1861
|
const keySet = def.keySet;
|
|
1856
1862
|
const _catchall = def.catchall._zod;
|
|
1857
1863
|
const t = _catchall.def.type;
|
|
1858
|
-
for (const key
|
|
1864
|
+
for (const key in input) {
|
|
1859
1865
|
if (keySet.has(key))
|
|
1860
1866
|
continue;
|
|
1861
1867
|
if (t === "never") {
|
|
@@ -2409,8 +2415,8 @@ const $ZodReadonly = /*@__PURE__*/ $constructor("$ZodReadonly", (inst, def) => {
|
|
|
2409
2415
|
$ZodType.init(inst, def);
|
|
2410
2416
|
defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
|
|
2411
2417
|
defineLazy(inst._zod, "values", () => def.innerType._zod.values);
|
|
2412
|
-
defineLazy(inst._zod, "optin", () => def.innerType
|
|
2413
|
-
defineLazy(inst._zod, "optout", () => def.innerType
|
|
2418
|
+
defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
|
|
2419
|
+
defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
|
|
2414
2420
|
inst._zod.parse = (payload, ctx) => {
|
|
2415
2421
|
if (ctx.direction === "backward") {
|
|
2416
2422
|
return def.innerType._zod.run(payload, ctx);
|
|
@@ -2458,6 +2464,7 @@ function handleRefineResult(result, payload, input, inst) {
|
|
|
2458
2464
|
}
|
|
2459
2465
|
}
|
|
2460
2466
|
|
|
2467
|
+
var _a;
|
|
2461
2468
|
class $ZodRegistry {
|
|
2462
2469
|
constructor() {
|
|
2463
2470
|
this._map = new WeakMap();
|
|
@@ -2507,7 +2514,8 @@ class $ZodRegistry {
|
|
|
2507
2514
|
function registry() {
|
|
2508
2515
|
return new $ZodRegistry();
|
|
2509
2516
|
}
|
|
2510
|
-
|
|
2517
|
+
(_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
|
|
2518
|
+
const globalRegistry = globalThis.__zod_globalRegistry;
|
|
2511
2519
|
|
|
2512
2520
|
function _string(Class, params) {
|
|
2513
2521
|
return new Class({
|
|
@@ -2919,6 +2927,10 @@ function _toLowerCase() {
|
|
|
2919
2927
|
function _toUpperCase() {
|
|
2920
2928
|
return _overwrite((input) => input.toUpperCase());
|
|
2921
2929
|
}
|
|
2930
|
+
// slugify
|
|
2931
|
+
function _slugify() {
|
|
2932
|
+
return _overwrite((input) => slugify(input));
|
|
2933
|
+
}
|
|
2922
2934
|
function _array(Class, element, params) {
|
|
2923
2935
|
return new Class({
|
|
2924
2936
|
type: "array",
|
|
@@ -3162,6 +3174,7 @@ const _ZodString = /*@__PURE__*/ $constructor("_ZodString", (inst, def) => {
|
|
|
3162
3174
|
inst.normalize = (...args) => inst.check(_normalize(...args));
|
|
3163
3175
|
inst.toLowerCase = () => inst.check(_toLowerCase());
|
|
3164
3176
|
inst.toUpperCase = () => inst.check(_toUpperCase());
|
|
3177
|
+
inst.slugify = () => inst.check(_slugify());
|
|
3165
3178
|
});
|
|
3166
3179
|
const ZodString = /*@__PURE__*/ $constructor("ZodString", (inst, def) => {
|
|
3167
3180
|
$ZodString.init(inst, def);
|
|
@@ -4821,7 +4834,6 @@ class Route {
|
|
|
4821
4834
|
*/
|
|
4822
4835
|
key;
|
|
4823
4836
|
id;
|
|
4824
|
-
share = false;
|
|
4825
4837
|
run;
|
|
4826
4838
|
nextRoute; // route to run after this route
|
|
4827
4839
|
description;
|
|
@@ -5298,9 +5310,7 @@ class QueryRouter {
|
|
|
5298
5310
|
ctx.query = { ...ctx.query, ...query, ...payload };
|
|
5299
5311
|
ctx.state = { ...ctx?.state };
|
|
5300
5312
|
ctx.throw = this.throw;
|
|
5301
|
-
|
|
5302
|
-
// TODO: 是否需要queryRouter,函数内部处理router路由执行,这应该是避免去内部去包含的功能过
|
|
5303
|
-
ctx.queryRouter = this;
|
|
5313
|
+
ctx.app = this;
|
|
5304
5314
|
ctx.call = this.call.bind(this);
|
|
5305
5315
|
ctx.queryRoute = this.queryRoute.bind(this);
|
|
5306
5316
|
ctx.index = 0;
|
|
@@ -5321,7 +5331,11 @@ class QueryRouter {
|
|
|
5321
5331
|
async call(message, ctx) {
|
|
5322
5332
|
let path = message.path;
|
|
5323
5333
|
let key = message.key;
|
|
5324
|
-
|
|
5334
|
+
// 优先 path + key
|
|
5335
|
+
if (path) {
|
|
5336
|
+
return await this.parse({ ...message, path, key }, { ...this.context, ...ctx });
|
|
5337
|
+
}
|
|
5338
|
+
else if (message.id) {
|
|
5325
5339
|
const route = this.routes.find((r) => r.id === message.id);
|
|
5326
5340
|
if (route) {
|
|
5327
5341
|
path = route.path;
|
|
@@ -5332,9 +5346,6 @@ class QueryRouter {
|
|
|
5332
5346
|
}
|
|
5333
5347
|
return await this.parse({ ...message, path, key }, { ...this.context, ...ctx });
|
|
5334
5348
|
}
|
|
5335
|
-
else if (path) {
|
|
5336
|
-
return await this.parse({ ...message, path, key }, { ...this.context, ...ctx });
|
|
5337
|
-
}
|
|
5338
5349
|
else {
|
|
5339
5350
|
return { code: 404, body: null, message: 'Not found path' };
|
|
5340
5351
|
}
|
|
@@ -5343,10 +5354,25 @@ class QueryRouter {
|
|
|
5343
5354
|
* 请求 result 的数据
|
|
5344
5355
|
* @param message
|
|
5345
5356
|
* @param ctx
|
|
5357
|
+
* @deprecated use run or call instead
|
|
5346
5358
|
* @returns
|
|
5347
5359
|
*/
|
|
5348
5360
|
async queryRoute(message, ctx) {
|
|
5349
|
-
const res = await this.
|
|
5361
|
+
const res = await this.call(message, { ...this.context, ...ctx });
|
|
5362
|
+
return {
|
|
5363
|
+
code: res.code,
|
|
5364
|
+
data: res.body,
|
|
5365
|
+
message: res.message,
|
|
5366
|
+
};
|
|
5367
|
+
}
|
|
5368
|
+
/**
|
|
5369
|
+
* Router Run获取数据
|
|
5370
|
+
* @param message
|
|
5371
|
+
* @param ctx
|
|
5372
|
+
* @returns
|
|
5373
|
+
*/
|
|
5374
|
+
async run(message, ctx) {
|
|
5375
|
+
const res = await this.call(message, { ...this.context, ...ctx });
|
|
5350
5376
|
return {
|
|
5351
5377
|
code: res.code,
|
|
5352
5378
|
data: res.body,
|
|
@@ -5373,18 +5399,7 @@ class QueryRouter {
|
|
|
5373
5399
|
return async (msg, handleContext) => {
|
|
5374
5400
|
try {
|
|
5375
5401
|
const context = { ...ctx, ...handleContext };
|
|
5376
|
-
|
|
5377
|
-
const route = router.routes.find((r) => r.id === msg.id);
|
|
5378
|
-
if (route) {
|
|
5379
|
-
msg.path = route.path;
|
|
5380
|
-
msg.key = route.key;
|
|
5381
|
-
}
|
|
5382
|
-
else {
|
|
5383
|
-
return { code: 404, message: 'Not found route' };
|
|
5384
|
-
}
|
|
5385
|
-
}
|
|
5386
|
-
// @ts-ignore
|
|
5387
|
-
const res = await router.parse(msg, context);
|
|
5402
|
+
const res = await router.call(msg, context);
|
|
5388
5403
|
if (wrapperFn) {
|
|
5389
5404
|
res.data = res.body;
|
|
5390
5405
|
return wrapperFn(res, context);
|
|
@@ -5496,37 +5511,21 @@ class QueryRouterServer extends QueryRouter {
|
|
|
5496
5511
|
return new Route('', '', { description });
|
|
5497
5512
|
}
|
|
5498
5513
|
/**
|
|
5499
|
-
*
|
|
5514
|
+
* 调用了handle
|
|
5500
5515
|
* @param param0
|
|
5501
5516
|
* @returns
|
|
5502
5517
|
*/
|
|
5503
|
-
async run({ path, key, payload }) {
|
|
5518
|
+
async run({ path, key, payload }, ctx) {
|
|
5504
5519
|
const handle = this.handle;
|
|
5505
|
-
|
|
5506
|
-
const
|
|
5507
|
-
|
|
5508
|
-
message: error,
|
|
5509
|
-
};
|
|
5510
|
-
return r;
|
|
5511
|
-
};
|
|
5512
|
-
try {
|
|
5513
|
-
const end = handle({ path, key, ...payload });
|
|
5514
|
-
return end;
|
|
5515
|
-
}
|
|
5516
|
-
catch (e) {
|
|
5517
|
-
if (e.code && typeof e.code === 'number') {
|
|
5518
|
-
return {
|
|
5519
|
-
code: e.code,
|
|
5520
|
-
message: e.message,
|
|
5521
|
-
};
|
|
5522
|
-
}
|
|
5523
|
-
else {
|
|
5524
|
-
return resultError('Router Server error');
|
|
5525
|
-
}
|
|
5520
|
+
if (handle) {
|
|
5521
|
+
const result = await this.call({ path, key, payload }, ctx);
|
|
5522
|
+
return handle(result);
|
|
5526
5523
|
}
|
|
5524
|
+
return super.run({ path, key, payload }, ctx);
|
|
5527
5525
|
}
|
|
5528
5526
|
}
|
|
5529
|
-
|
|
5527
|
+
class Mini extends QueryRouterServer {
|
|
5528
|
+
}
|
|
5530
5529
|
|
|
5531
5530
|
class Connect {
|
|
5532
5531
|
path;
|
|
@@ -5705,8 +5704,14 @@ function requireDist () {
|
|
|
5705
5704
|
if (hasRequiredDist) return dist;
|
|
5706
5705
|
hasRequiredDist = 1;
|
|
5707
5706
|
Object.defineProperty(dist, "__esModule", { value: true });
|
|
5708
|
-
dist.
|
|
5709
|
-
dist.
|
|
5707
|
+
dist.parseCookie = parseCookie;
|
|
5708
|
+
dist.parse = parseCookie;
|
|
5709
|
+
dist.stringifyCookie = stringifyCookie;
|
|
5710
|
+
dist.stringifySetCookie = stringifySetCookie;
|
|
5711
|
+
dist.serialize = stringifySetCookie;
|
|
5712
|
+
dist.parseSetCookie = parseSetCookie;
|
|
5713
|
+
dist.stringifySetCookie = stringifySetCookie;
|
|
5714
|
+
dist.serialize = stringifySetCookie;
|
|
5710
5715
|
/**
|
|
5711
5716
|
* RegExp to match cookie-name in RFC 6265 sec 4.1.1
|
|
5712
5717
|
* This refers out to the obsoleted definition of token in RFC 2616 sec 2.2
|
|
@@ -5767,6 +5772,10 @@ function requireDist () {
|
|
|
5767
5772
|
* ; defined in RFC 5234 appendix B.1
|
|
5768
5773
|
*/
|
|
5769
5774
|
const pathValueRegExp = /^[\u0020-\u003A\u003D-\u007E]*$/;
|
|
5775
|
+
/**
|
|
5776
|
+
* RegExp to match max-age-value in RFC 6265 sec 5.6.2
|
|
5777
|
+
*/
|
|
5778
|
+
const maxAgeRegExp = /^-?\d+$/;
|
|
5770
5779
|
const __toString = Object.prototype.toString;
|
|
5771
5780
|
const NullObject = /* @__PURE__ */ (() => {
|
|
5772
5781
|
const C = function () { };
|
|
@@ -5774,12 +5783,12 @@ function requireDist () {
|
|
|
5774
5783
|
return C;
|
|
5775
5784
|
})();
|
|
5776
5785
|
/**
|
|
5777
|
-
* Parse a
|
|
5786
|
+
* Parse a `Cookie` header.
|
|
5778
5787
|
*
|
|
5779
5788
|
* Parse the given cookie header string into an object
|
|
5780
5789
|
* The object has the various cookies as keys(names) => values
|
|
5781
5790
|
*/
|
|
5782
|
-
function
|
|
5791
|
+
function parseCookie(str, options) {
|
|
5783
5792
|
const obj = new NullObject();
|
|
5784
5793
|
const len = str.length;
|
|
5785
5794
|
// RFC 6265 sec 4.1.1, RFC 2616 2.2 defines a cookie name consists of one char minimum, plus '='.
|
|
@@ -5788,104 +5797,95 @@ function requireDist () {
|
|
|
5788
5797
|
const dec = options?.decode || decode;
|
|
5789
5798
|
let index = 0;
|
|
5790
5799
|
do {
|
|
5791
|
-
const eqIdx = str
|
|
5800
|
+
const eqIdx = eqIndex(str, index, len);
|
|
5792
5801
|
if (eqIdx === -1)
|
|
5793
5802
|
break; // No more cookie pairs.
|
|
5794
|
-
const
|
|
5795
|
-
const endIdx = colonIdx === -1 ? len : colonIdx;
|
|
5803
|
+
const endIdx = endIndex(str, index, len);
|
|
5796
5804
|
if (eqIdx > endIdx) {
|
|
5797
5805
|
// backtrack on prior semicolon
|
|
5798
5806
|
index = str.lastIndexOf(";", eqIdx - 1) + 1;
|
|
5799
5807
|
continue;
|
|
5800
5808
|
}
|
|
5801
|
-
const
|
|
5802
|
-
const keyEndIdx = endIndex(str, eqIdx, keyStartIdx);
|
|
5803
|
-
const key = str.slice(keyStartIdx, keyEndIdx);
|
|
5809
|
+
const key = valueSlice(str, index, eqIdx);
|
|
5804
5810
|
// only assign once
|
|
5805
5811
|
if (obj[key] === undefined) {
|
|
5806
|
-
|
|
5807
|
-
let valEndIdx = endIndex(str, endIdx, valStartIdx);
|
|
5808
|
-
const value = dec(str.slice(valStartIdx, valEndIdx));
|
|
5809
|
-
obj[key] = value;
|
|
5812
|
+
obj[key] = dec(valueSlice(str, eqIdx + 1, endIdx));
|
|
5810
5813
|
}
|
|
5811
5814
|
index = endIdx + 1;
|
|
5812
5815
|
} while (index < len);
|
|
5813
5816
|
return obj;
|
|
5814
5817
|
}
|
|
5815
|
-
function startIndex(str, index, max) {
|
|
5816
|
-
do {
|
|
5817
|
-
const code = str.charCodeAt(index);
|
|
5818
|
-
if (code !== 0x20 /* */ && code !== 0x09 /* \t */)
|
|
5819
|
-
return index;
|
|
5820
|
-
} while (++index < max);
|
|
5821
|
-
return max;
|
|
5822
|
-
}
|
|
5823
|
-
function endIndex(str, index, min) {
|
|
5824
|
-
while (index > min) {
|
|
5825
|
-
const code = str.charCodeAt(--index);
|
|
5826
|
-
if (code !== 0x20 /* */ && code !== 0x09 /* \t */)
|
|
5827
|
-
return index + 1;
|
|
5828
|
-
}
|
|
5829
|
-
return min;
|
|
5830
|
-
}
|
|
5831
5818
|
/**
|
|
5832
|
-
*
|
|
5833
|
-
*
|
|
5834
|
-
* Serialize a name value pair into a cookie string suitable for
|
|
5835
|
-
* http headers. An optional options object specifies cookie parameters.
|
|
5836
|
-
*
|
|
5837
|
-
* serialize('foo', 'bar', { httpOnly: true })
|
|
5838
|
-
* => "foo=bar; httpOnly"
|
|
5819
|
+
* Stringifies an object into an HTTP `Cookie` header.
|
|
5839
5820
|
*/
|
|
5840
|
-
function
|
|
5821
|
+
function stringifyCookie(cookie, options) {
|
|
5841
5822
|
const enc = options?.encode || encodeURIComponent;
|
|
5842
|
-
|
|
5843
|
-
|
|
5823
|
+
const cookieStrings = [];
|
|
5824
|
+
for (const name of Object.keys(cookie)) {
|
|
5825
|
+
const val = cookie[name];
|
|
5826
|
+
if (val === undefined)
|
|
5827
|
+
continue;
|
|
5828
|
+
if (!cookieNameRegExp.test(name)) {
|
|
5829
|
+
throw new TypeError(`cookie name is invalid: ${name}`);
|
|
5830
|
+
}
|
|
5831
|
+
const value = enc(val);
|
|
5832
|
+
if (!cookieValueRegExp.test(value)) {
|
|
5833
|
+
throw new TypeError(`cookie val is invalid: ${val}`);
|
|
5834
|
+
}
|
|
5835
|
+
cookieStrings.push(`${name}=${value}`);
|
|
5844
5836
|
}
|
|
5845
|
-
|
|
5837
|
+
return cookieStrings.join("; ");
|
|
5838
|
+
}
|
|
5839
|
+
function stringifySetCookie(_name, _val, _opts) {
|
|
5840
|
+
const cookie = typeof _name === "object"
|
|
5841
|
+
? _name
|
|
5842
|
+
: { ..._opts, name: _name, value: String(_val) };
|
|
5843
|
+
const options = typeof _val === "object" ? _val : _opts;
|
|
5844
|
+
const enc = options?.encode || encodeURIComponent;
|
|
5845
|
+
if (!cookieNameRegExp.test(cookie.name)) {
|
|
5846
|
+
throw new TypeError(`argument name is invalid: ${cookie.name}`);
|
|
5847
|
+
}
|
|
5848
|
+
const value = cookie.value ? enc(cookie.value) : "";
|
|
5846
5849
|
if (!cookieValueRegExp.test(value)) {
|
|
5847
|
-
throw new TypeError(`argument val is invalid: ${
|
|
5850
|
+
throw new TypeError(`argument val is invalid: ${cookie.value}`);
|
|
5848
5851
|
}
|
|
5849
|
-
let str = name + "=" + value;
|
|
5850
|
-
if (
|
|
5851
|
-
|
|
5852
|
-
|
|
5853
|
-
if (!Number.isInteger(options.maxAge)) {
|
|
5854
|
-
throw new TypeError(`option maxAge is invalid: ${options.maxAge}`);
|
|
5852
|
+
let str = cookie.name + "=" + value;
|
|
5853
|
+
if (cookie.maxAge !== undefined) {
|
|
5854
|
+
if (!Number.isInteger(cookie.maxAge)) {
|
|
5855
|
+
throw new TypeError(`option maxAge is invalid: ${cookie.maxAge}`);
|
|
5855
5856
|
}
|
|
5856
|
-
str += "; Max-Age=" +
|
|
5857
|
+
str += "; Max-Age=" + cookie.maxAge;
|
|
5857
5858
|
}
|
|
5858
|
-
if (
|
|
5859
|
-
if (!domainValueRegExp.test(
|
|
5860
|
-
throw new TypeError(`option domain is invalid: ${
|
|
5859
|
+
if (cookie.domain) {
|
|
5860
|
+
if (!domainValueRegExp.test(cookie.domain)) {
|
|
5861
|
+
throw new TypeError(`option domain is invalid: ${cookie.domain}`);
|
|
5861
5862
|
}
|
|
5862
|
-
str += "; Domain=" +
|
|
5863
|
+
str += "; Domain=" + cookie.domain;
|
|
5863
5864
|
}
|
|
5864
|
-
if (
|
|
5865
|
-
if (!pathValueRegExp.test(
|
|
5866
|
-
throw new TypeError(`option path is invalid: ${
|
|
5865
|
+
if (cookie.path) {
|
|
5866
|
+
if (!pathValueRegExp.test(cookie.path)) {
|
|
5867
|
+
throw new TypeError(`option path is invalid: ${cookie.path}`);
|
|
5867
5868
|
}
|
|
5868
|
-
str += "; Path=" +
|
|
5869
|
+
str += "; Path=" + cookie.path;
|
|
5869
5870
|
}
|
|
5870
|
-
if (
|
|
5871
|
-
if (!isDate(
|
|
5872
|
-
|
|
5873
|
-
throw new TypeError(`option expires is invalid: ${options.expires}`);
|
|
5871
|
+
if (cookie.expires) {
|
|
5872
|
+
if (!isDate(cookie.expires) || !Number.isFinite(cookie.expires.valueOf())) {
|
|
5873
|
+
throw new TypeError(`option expires is invalid: ${cookie.expires}`);
|
|
5874
5874
|
}
|
|
5875
|
-
str += "; Expires=" +
|
|
5875
|
+
str += "; Expires=" + cookie.expires.toUTCString();
|
|
5876
5876
|
}
|
|
5877
|
-
if (
|
|
5877
|
+
if (cookie.httpOnly) {
|
|
5878
5878
|
str += "; HttpOnly";
|
|
5879
5879
|
}
|
|
5880
|
-
if (
|
|
5880
|
+
if (cookie.secure) {
|
|
5881
5881
|
str += "; Secure";
|
|
5882
5882
|
}
|
|
5883
|
-
if (
|
|
5883
|
+
if (cookie.partitioned) {
|
|
5884
5884
|
str += "; Partitioned";
|
|
5885
5885
|
}
|
|
5886
|
-
if (
|
|
5887
|
-
const priority = typeof
|
|
5888
|
-
?
|
|
5886
|
+
if (cookie.priority) {
|
|
5887
|
+
const priority = typeof cookie.priority === "string"
|
|
5888
|
+
? cookie.priority.toLowerCase()
|
|
5889
5889
|
: undefined;
|
|
5890
5890
|
switch (priority) {
|
|
5891
5891
|
case "low":
|
|
@@ -5898,13 +5898,13 @@ function requireDist () {
|
|
|
5898
5898
|
str += "; Priority=High";
|
|
5899
5899
|
break;
|
|
5900
5900
|
default:
|
|
5901
|
-
throw new TypeError(`option priority is invalid: ${
|
|
5901
|
+
throw new TypeError(`option priority is invalid: ${cookie.priority}`);
|
|
5902
5902
|
}
|
|
5903
5903
|
}
|
|
5904
|
-
if (
|
|
5905
|
-
const sameSite = typeof
|
|
5906
|
-
?
|
|
5907
|
-
:
|
|
5904
|
+
if (cookie.sameSite) {
|
|
5905
|
+
const sameSite = typeof cookie.sameSite === "string"
|
|
5906
|
+
? cookie.sameSite.toLowerCase()
|
|
5907
|
+
: cookie.sameSite;
|
|
5908
5908
|
switch (sameSite) {
|
|
5909
5909
|
case true:
|
|
5910
5910
|
case "strict":
|
|
@@ -5917,11 +5917,121 @@ function requireDist () {
|
|
|
5917
5917
|
str += "; SameSite=None";
|
|
5918
5918
|
break;
|
|
5919
5919
|
default:
|
|
5920
|
-
throw new TypeError(`option sameSite is invalid: ${
|
|
5920
|
+
throw new TypeError(`option sameSite is invalid: ${cookie.sameSite}`);
|
|
5921
5921
|
}
|
|
5922
5922
|
}
|
|
5923
5923
|
return str;
|
|
5924
5924
|
}
|
|
5925
|
+
/**
|
|
5926
|
+
* Deserialize a `Set-Cookie` header into an object.
|
|
5927
|
+
*
|
|
5928
|
+
* deserialize('foo=bar; httpOnly')
|
|
5929
|
+
* => { name: 'foo', value: 'bar', httpOnly: true }
|
|
5930
|
+
*/
|
|
5931
|
+
function parseSetCookie(str, options) {
|
|
5932
|
+
const dec = options?.decode || decode;
|
|
5933
|
+
const len = str.length;
|
|
5934
|
+
const endIdx = endIndex(str, 0, len);
|
|
5935
|
+
const eqIdx = eqIndex(str, 0, endIdx);
|
|
5936
|
+
const setCookie = eqIdx === -1
|
|
5937
|
+
? { name: "", value: dec(valueSlice(str, 0, endIdx)) }
|
|
5938
|
+
: {
|
|
5939
|
+
name: valueSlice(str, 0, eqIdx),
|
|
5940
|
+
value: dec(valueSlice(str, eqIdx + 1, endIdx)),
|
|
5941
|
+
};
|
|
5942
|
+
let index = endIdx + 1;
|
|
5943
|
+
while (index < len) {
|
|
5944
|
+
const endIdx = endIndex(str, index, len);
|
|
5945
|
+
const eqIdx = eqIndex(str, index, endIdx);
|
|
5946
|
+
const attr = eqIdx === -1
|
|
5947
|
+
? valueSlice(str, index, endIdx)
|
|
5948
|
+
: valueSlice(str, index, eqIdx);
|
|
5949
|
+
const val = eqIdx === -1 ? undefined : valueSlice(str, eqIdx + 1, endIdx);
|
|
5950
|
+
switch (attr.toLowerCase()) {
|
|
5951
|
+
case "httponly":
|
|
5952
|
+
setCookie.httpOnly = true;
|
|
5953
|
+
break;
|
|
5954
|
+
case "secure":
|
|
5955
|
+
setCookie.secure = true;
|
|
5956
|
+
break;
|
|
5957
|
+
case "partitioned":
|
|
5958
|
+
setCookie.partitioned = true;
|
|
5959
|
+
break;
|
|
5960
|
+
case "domain":
|
|
5961
|
+
setCookie.domain = val;
|
|
5962
|
+
break;
|
|
5963
|
+
case "path":
|
|
5964
|
+
setCookie.path = val;
|
|
5965
|
+
break;
|
|
5966
|
+
case "max-age":
|
|
5967
|
+
if (val && maxAgeRegExp.test(val))
|
|
5968
|
+
setCookie.maxAge = Number(val);
|
|
5969
|
+
break;
|
|
5970
|
+
case "expires":
|
|
5971
|
+
if (!val)
|
|
5972
|
+
break;
|
|
5973
|
+
const date = new Date(val);
|
|
5974
|
+
if (Number.isFinite(date.valueOf()))
|
|
5975
|
+
setCookie.expires = date;
|
|
5976
|
+
break;
|
|
5977
|
+
case "priority":
|
|
5978
|
+
if (!val)
|
|
5979
|
+
break;
|
|
5980
|
+
const priority = val.toLowerCase();
|
|
5981
|
+
if (priority === "low" ||
|
|
5982
|
+
priority === "medium" ||
|
|
5983
|
+
priority === "high") {
|
|
5984
|
+
setCookie.priority = priority;
|
|
5985
|
+
}
|
|
5986
|
+
break;
|
|
5987
|
+
case "samesite":
|
|
5988
|
+
if (!val)
|
|
5989
|
+
break;
|
|
5990
|
+
const sameSite = val.toLowerCase();
|
|
5991
|
+
if (sameSite === "lax" ||
|
|
5992
|
+
sameSite === "strict" ||
|
|
5993
|
+
sameSite === "none") {
|
|
5994
|
+
setCookie.sameSite = sameSite;
|
|
5995
|
+
}
|
|
5996
|
+
break;
|
|
5997
|
+
}
|
|
5998
|
+
index = endIdx + 1;
|
|
5999
|
+
}
|
|
6000
|
+
return setCookie;
|
|
6001
|
+
}
|
|
6002
|
+
/**
|
|
6003
|
+
* Find the `;` character between `min` and `len` in str.
|
|
6004
|
+
*/
|
|
6005
|
+
function endIndex(str, min, len) {
|
|
6006
|
+
const index = str.indexOf(";", min);
|
|
6007
|
+
return index === -1 ? len : index;
|
|
6008
|
+
}
|
|
6009
|
+
/**
|
|
6010
|
+
* Find the `=` character between `min` and `max` in str.
|
|
6011
|
+
*/
|
|
6012
|
+
function eqIndex(str, min, max) {
|
|
6013
|
+
const index = str.indexOf("=", min);
|
|
6014
|
+
return index < max ? index : -1;
|
|
6015
|
+
}
|
|
6016
|
+
/**
|
|
6017
|
+
* Slice out a value between startPod to max.
|
|
6018
|
+
*/
|
|
6019
|
+
function valueSlice(str, min, max) {
|
|
6020
|
+
let start = min;
|
|
6021
|
+
let end = max;
|
|
6022
|
+
do {
|
|
6023
|
+
const code = str.charCodeAt(start);
|
|
6024
|
+
if (code !== 0x20 /* */ && code !== 0x09 /* \t */)
|
|
6025
|
+
break;
|
|
6026
|
+
} while (++start < end);
|
|
6027
|
+
while (end > start) {
|
|
6028
|
+
const code = str.charCodeAt(end - 1);
|
|
6029
|
+
if (code !== 0x20 /* */ && code !== 0x09 /* \t */)
|
|
6030
|
+
break;
|
|
6031
|
+
end--;
|
|
6032
|
+
}
|
|
6033
|
+
return str.slice(start, end);
|
|
6034
|
+
}
|
|
5925
6035
|
/**
|
|
5926
6036
|
* URL-decode string value. Optimized to skip native call when no %.
|
|
5927
6037
|
*/
|
|
@@ -5945,7 +6055,7 @@ function requireDist () {
|
|
|
5945
6055
|
return dist;
|
|
5946
6056
|
}
|
|
5947
6057
|
|
|
5948
|
-
var distExports = requireDist();
|
|
6058
|
+
var distExports = /*@__PURE__*/ requireDist();
|
|
5949
6059
|
|
|
5950
6060
|
// 实现函数
|
|
5951
6061
|
function createHandleCtx(req, res) {
|