routup 3.3.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/node/module.d.ts +0 -1
- package/dist/handler/module.d.ts +1 -1
- package/dist/index.cjs +89 -103
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +89 -103
- package/dist/index.mjs.map +1 -1
- package/dist/path/type.d.ts +3 -3
- package/dist/request/helpers/env.d.ts +4 -4
- package/dist/request/helpers/header-accept-encoding.d.ts +0 -1
- package/dist/request/helpers/header.d.ts +0 -1
- package/dist/request/module.d.ts +0 -1
- package/dist/request/types.d.ts +0 -1
- package/dist/response/helpers/header.d.ts +0 -1
- package/dist/response/types.d.ts +0 -1
- package/dist/types.d.ts +0 -2
- package/dist/utils/etag/module.d.ts +0 -2
- package/dist/utils/etag/type.d.ts +0 -1
- package/dist/utils/object.d.ts +2 -0
- package/dist/utils/stream.d.ts +0 -2
- package/package.json +11 -11
package/dist/handler/module.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export declare class Handler implements Dispatcher {
|
|
|
12
12
|
protected _method: MethodName | undefined;
|
|
13
13
|
constructor(handler: HandlerConfig);
|
|
14
14
|
get type(): "error" | "core";
|
|
15
|
-
get path():
|
|
15
|
+
get path(): string | undefined;
|
|
16
16
|
get method(): MethodName | undefined;
|
|
17
17
|
dispatch(event: DispatchEvent): Promise<void>;
|
|
18
18
|
matchPath(path: string): boolean;
|
package/dist/index.cjs
CHANGED
|
@@ -64,55 +64,6 @@ function isRequestCacheable(req, modifiedTime) {
|
|
|
64
64
|
return new Date(modifiedSince) >= modifiedTime;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
const envSymbol = Symbol.for('ReqEnv');
|
|
68
|
-
function setRequestEnv(req, key, value) {
|
|
69
|
-
if (envSymbol in req) {
|
|
70
|
-
if (typeof key === 'object') {
|
|
71
|
-
if (value) {
|
|
72
|
-
req[envSymbol] = smob.merge(req[envSymbol], key);
|
|
73
|
-
} else {
|
|
74
|
-
req[envSymbol] = key;
|
|
75
|
-
}
|
|
76
|
-
} else {
|
|
77
|
-
req[envSymbol][key] = value;
|
|
78
|
-
}
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (typeof key === 'object') {
|
|
82
|
-
req[envSymbol] = key;
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
req[envSymbol] = {
|
|
86
|
-
[key]: value
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
function useRequestEnv(req, key) {
|
|
90
|
-
if (envSymbol in req) {
|
|
91
|
-
if (typeof key === 'string') {
|
|
92
|
-
return req[envSymbol][key];
|
|
93
|
-
}
|
|
94
|
-
return req[envSymbol];
|
|
95
|
-
}
|
|
96
|
-
if (typeof key === 'string') {
|
|
97
|
-
return undefined;
|
|
98
|
-
}
|
|
99
|
-
return {};
|
|
100
|
-
}
|
|
101
|
-
function unsetRequestEnv(req, key) {
|
|
102
|
-
if (envSymbol in req) {
|
|
103
|
-
if (smob.hasOwnProperty(req[envSymbol], key)) {
|
|
104
|
-
delete req[envSymbol][key];
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function getRequestHeader(req, name) {
|
|
110
|
-
return req.headers[name];
|
|
111
|
-
}
|
|
112
|
-
function setRequestHeader(req, name, value) {
|
|
113
|
-
req.headers[name] = value;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
67
|
/*
|
|
117
68
|
Set-Cookie header field-values are sometimes comma joined in one string. This splits them without choking on commas
|
|
118
69
|
that are within a single set-cookie field-value, such as in the Expires portion.
|
|
@@ -188,6 +139,12 @@ function setRequestHeader(req, name, value) {
|
|
|
188
139
|
function isObject(item) {
|
|
189
140
|
return !!item && typeof item === 'object' && !Array.isArray(item);
|
|
190
141
|
}
|
|
142
|
+
function setProperty(record, property, value) {
|
|
143
|
+
record[property] = value;
|
|
144
|
+
}
|
|
145
|
+
function getProperty(req, property) {
|
|
146
|
+
return req[property];
|
|
147
|
+
}
|
|
191
148
|
|
|
192
149
|
/**
|
|
193
150
|
* Determine if object is a Stats object.
|
|
@@ -324,7 +281,7 @@ function basename(input, extension) {
|
|
|
324
281
|
if (!lastSegment) {
|
|
325
282
|
return input;
|
|
326
283
|
}
|
|
327
|
-
return
|
|
284
|
+
return lastSegment;
|
|
328
285
|
}
|
|
329
286
|
|
|
330
287
|
function isPromise(p) {
|
|
@@ -380,12 +337,66 @@ function isWebResponse(input) {
|
|
|
380
337
|
return typeof Response !== 'undefined' && input instanceof Response;
|
|
381
338
|
}
|
|
382
339
|
|
|
383
|
-
const
|
|
340
|
+
const symbol$4 = Symbol.for('ReqEnv');
|
|
341
|
+
function setRequestEnv(req, key, value) {
|
|
342
|
+
const propertyValue = getProperty(req, symbol$4);
|
|
343
|
+
if (propertyValue) {
|
|
344
|
+
if (typeof key === 'object') {
|
|
345
|
+
if (value) {
|
|
346
|
+
setProperty(req, symbol$4, smob.merge(propertyValue, key));
|
|
347
|
+
} else {
|
|
348
|
+
setProperty(req, symbol$4, key);
|
|
349
|
+
}
|
|
350
|
+
} else {
|
|
351
|
+
propertyValue[key] = value;
|
|
352
|
+
setProperty(req, symbol$4, propertyValue);
|
|
353
|
+
}
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
if (typeof key === 'object') {
|
|
357
|
+
setProperty(req, symbol$4, key);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
setProperty(req, symbol$4, {
|
|
361
|
+
[key]: value
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
function useRequestEnv(req, key) {
|
|
365
|
+
const propertyValue = getProperty(req, symbol$4);
|
|
366
|
+
if (propertyValue) {
|
|
367
|
+
if (typeof key !== 'undefined') {
|
|
368
|
+
return propertyValue[key];
|
|
369
|
+
}
|
|
370
|
+
return propertyValue;
|
|
371
|
+
}
|
|
372
|
+
if (typeof key !== 'undefined') {
|
|
373
|
+
return undefined;
|
|
374
|
+
}
|
|
375
|
+
return {};
|
|
376
|
+
}
|
|
377
|
+
function unsetRequestEnv(req, key) {
|
|
378
|
+
const propertyValue = getProperty(req, symbol$4);
|
|
379
|
+
if (smob.hasOwnProperty(propertyValue, key)) {
|
|
380
|
+
delete propertyValue[key];
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function getRequestHeader(req, name) {
|
|
385
|
+
return req.headers[name];
|
|
386
|
+
}
|
|
387
|
+
function setRequestHeader(req, name, value) {
|
|
388
|
+
req.headers[name] = value;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
const symbol$3 = Symbol.for('ReqNegotiator');
|
|
384
392
|
function useRequestNegotiator(req) {
|
|
385
|
-
|
|
386
|
-
|
|
393
|
+
let value = getProperty(req, symbol$3);
|
|
394
|
+
if (value) {
|
|
395
|
+
return value;
|
|
387
396
|
}
|
|
388
|
-
|
|
397
|
+
value = new Negotiator(req);
|
|
398
|
+
setProperty(req, symbol$3, value);
|
|
399
|
+
return value;
|
|
389
400
|
}
|
|
390
401
|
|
|
391
402
|
function getRequestAcceptableContentTypes(req) {
|
|
@@ -513,13 +524,10 @@ function findRouterOption(key, path) {
|
|
|
513
524
|
|
|
514
525
|
const routerSymbol = Symbol.for('ReqRouterID');
|
|
515
526
|
function setRequestRouterPath(req, path) {
|
|
516
|
-
req
|
|
527
|
+
setProperty(req, routerSymbol, path);
|
|
517
528
|
}
|
|
518
529
|
function useRequestRouterPath(req) {
|
|
519
|
-
|
|
520
|
-
return req[routerSymbol];
|
|
521
|
-
}
|
|
522
|
-
return undefined;
|
|
530
|
+
return getProperty(req, routerSymbol);
|
|
523
531
|
}
|
|
524
532
|
|
|
525
533
|
function getRequestHostName(req, options) {
|
|
@@ -564,32 +572,23 @@ function getRequestIP(req, options) {
|
|
|
564
572
|
return addrs[addrs.length - 1];
|
|
565
573
|
}
|
|
566
574
|
|
|
567
|
-
const
|
|
575
|
+
const symbol$2 = Symbol.for('ReqMountPath');
|
|
568
576
|
function useRequestMountPath(req) {
|
|
569
|
-
|
|
570
|
-
return req[ReqMountPathSymbol];
|
|
571
|
-
}
|
|
572
|
-
return '/';
|
|
577
|
+
return getProperty(req, symbol$2) || '/';
|
|
573
578
|
}
|
|
574
579
|
function setRequestMountPath(req, basePath) {
|
|
575
|
-
req
|
|
580
|
+
setProperty(req, symbol$2, basePath);
|
|
576
581
|
}
|
|
577
582
|
|
|
578
|
-
const
|
|
583
|
+
const symbol$1 = Symbol.for('ReqParams');
|
|
579
584
|
function useRequestParams(req) {
|
|
580
|
-
|
|
581
|
-
return req.params;
|
|
582
|
-
}
|
|
583
|
-
if (ParamsSymbol in req) {
|
|
584
|
-
return req[ParamsSymbol];
|
|
585
|
-
}
|
|
586
|
-
return {};
|
|
585
|
+
return getProperty(req, symbol$1) || getProperty(req, 'params') || {};
|
|
587
586
|
}
|
|
588
587
|
function useRequestParam(req, key) {
|
|
589
588
|
return useRequestParams(req)[key];
|
|
590
589
|
}
|
|
591
590
|
function setRequestParams(req, data) {
|
|
592
|
-
req
|
|
591
|
+
setProperty(req, symbol$1, data);
|
|
593
592
|
}
|
|
594
593
|
function setRequestParam(req, key, value) {
|
|
595
594
|
const params = useRequestParams(req);
|
|
@@ -599,18 +598,16 @@ function setRequestParam(req, key, value) {
|
|
|
599
598
|
|
|
600
599
|
const PathSymbol = Symbol.for('ReqPath');
|
|
601
600
|
function useRequestPath(req) {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
if (PathSymbol in req) {
|
|
606
|
-
return req[PathSymbol];
|
|
601
|
+
const path = getProperty(req, 'path') || getProperty(req, PathSymbol);
|
|
602
|
+
if (path) {
|
|
603
|
+
return path;
|
|
607
604
|
}
|
|
608
605
|
if (typeof req.url === 'undefined') {
|
|
609
606
|
return '/';
|
|
610
607
|
}
|
|
611
608
|
const parsed = new URL(req.url, 'http://localhost/');
|
|
612
|
-
req
|
|
613
|
-
return
|
|
609
|
+
setProperty(req, PathSymbol, parsed.pathname);
|
|
610
|
+
return parsed.pathname;
|
|
614
611
|
}
|
|
615
612
|
|
|
616
613
|
function getRequestProtocol(req, options) {
|
|
@@ -757,18 +754,15 @@ function setResponseCacheHeaders(res, options) {
|
|
|
757
754
|
res.setHeader('cache-control', cacheControls.join(', '));
|
|
758
755
|
}
|
|
759
756
|
|
|
760
|
-
const
|
|
757
|
+
const symbol = Symbol.for('ResGone');
|
|
761
758
|
function isResponseGone(res) {
|
|
762
759
|
if (res.headersSent || res.writableEnded) {
|
|
763
760
|
return true;
|
|
764
761
|
}
|
|
765
|
-
|
|
766
|
-
return res[GoneSymbol];
|
|
767
|
-
}
|
|
768
|
-
return false;
|
|
762
|
+
return getProperty(res, symbol) ?? false;
|
|
769
763
|
}
|
|
770
764
|
function setResponseGone(res, value) {
|
|
771
|
-
res
|
|
765
|
+
setProperty(res, symbol, value);
|
|
772
766
|
}
|
|
773
767
|
|
|
774
768
|
function serializeEventStreamMessage(message) {
|
|
@@ -1730,12 +1724,14 @@ class PathMatcher {
|
|
|
1730
1724
|
this.regexpKeys = [];
|
|
1731
1725
|
this.path = path;
|
|
1732
1726
|
this.regexpOptions = options || {};
|
|
1733
|
-
|
|
1727
|
+
const regexp = pathToRegexp.pathToRegexp(path, options);
|
|
1728
|
+
this.regexp = regexp;
|
|
1729
|
+
this.regexpKeys = regexp.keys;
|
|
1734
1730
|
}
|
|
1735
1731
|
}
|
|
1736
1732
|
|
|
1737
1733
|
function isPath(input) {
|
|
1738
|
-
return typeof input === 'string'
|
|
1734
|
+
return typeof input === 'string';
|
|
1739
1735
|
}
|
|
1740
1736
|
|
|
1741
1737
|
class Handler {
|
|
@@ -1928,15 +1924,9 @@ class Router {
|
|
|
1928
1924
|
this.pathMatcher = undefined;
|
|
1929
1925
|
return;
|
|
1930
1926
|
}
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
});
|
|
1935
|
-
} else {
|
|
1936
|
-
this.pathMatcher = new PathMatcher(value, {
|
|
1937
|
-
end: false
|
|
1938
|
-
});
|
|
1939
|
-
}
|
|
1927
|
+
this.pathMatcher = new PathMatcher(withLeadingSlash(withoutTrailingSlash(`${value}`)), {
|
|
1928
|
+
end: false
|
|
1929
|
+
});
|
|
1940
1930
|
}
|
|
1941
1931
|
// --------------------------------------------------
|
|
1942
1932
|
async executePipelineStep(context) {
|
|
@@ -2158,11 +2148,7 @@ class Router {
|
|
|
2158
2148
|
for(let i = 0; i < input.length; i++){
|
|
2159
2149
|
const item = input[i];
|
|
2160
2150
|
if (isPath(item)) {
|
|
2161
|
-
|
|
2162
|
-
path = withLeadingSlash(item);
|
|
2163
|
-
} else {
|
|
2164
|
-
path = item;
|
|
2165
|
-
}
|
|
2151
|
+
path = withLeadingSlash(item);
|
|
2166
2152
|
continue;
|
|
2167
2153
|
}
|
|
2168
2154
|
if (isRouterInstance(item)) {
|