routup 3.0.0-alpha.2 → 3.0.0-alpha.3

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.mjs CHANGED
@@ -77,6 +77,64 @@ function isError(input) {
77
77
  }, input);
78
78
  }
79
79
 
80
+ function isRequestCacheable(req, modifiedTime) {
81
+ const modifiedSince = req.headers[HeaderName.IF_MODIFIED_SINCE];
82
+ if (!modifiedSince) {
83
+ return false;
84
+ }
85
+ modifiedTime = typeof modifiedTime === 'string' ? new Date(modifiedTime) : modifiedTime;
86
+ return new Date(modifiedSince) >= modifiedTime;
87
+ }
88
+
89
+ const envSymbol = Symbol.for('ReqEnv');
90
+ function setRequestEnv(req, key, value) {
91
+ if (envSymbol in req) {
92
+ if (typeof key === 'object') {
93
+ if (value) {
94
+ req[envSymbol] = merge(req[envSymbol], key);
95
+ } else {
96
+ req[envSymbol] = key;
97
+ }
98
+ } else {
99
+ req[envSymbol][key] = value;
100
+ }
101
+ return;
102
+ }
103
+ if (typeof key === 'object') {
104
+ req[envSymbol] = key;
105
+ return;
106
+ }
107
+ req[envSymbol] = {
108
+ [key]: value
109
+ };
110
+ }
111
+ function useRequestEnv(req, key) {
112
+ if (envSymbol in req) {
113
+ if (typeof key === 'string') {
114
+ return req[envSymbol][key];
115
+ }
116
+ return req[envSymbol];
117
+ }
118
+ if (typeof key === 'string') {
119
+ return undefined;
120
+ }
121
+ return {};
122
+ }
123
+ function unsetRequestEnv(req, key) {
124
+ if (envSymbol in req) {
125
+ if (hasOwnProperty(req[envSymbol], key)) {
126
+ delete req[envSymbol][key];
127
+ }
128
+ }
129
+ }
130
+
131
+ function getRequestHeader(req, name) {
132
+ return req.headers[name];
133
+ }
134
+ function setRequestHeader(req, name, value) {
135
+ req.headers[name] = value;
136
+ }
137
+
80
138
  /*
81
139
  Set-Cookie header field-values are sometimes comma joined in one string. This splits them without choking on commas
82
140
  that are within a single set-cookie field-value, such as in the Expires portion.
@@ -362,160 +420,6 @@ function isWebResponse(input) {
362
420
  return typeof Response !== 'undefined' && input instanceof Response;
363
421
  }
364
422
 
365
- const BodySymbol = Symbol.for('ReqBody');
366
- function useRequestBody(req, key) {
367
- let body;
368
- /* istanbul ignore next */ if ('body' in req) {
369
- body = req.body;
370
- }
371
- if (BodySymbol in req) {
372
- if (body) {
373
- body = merge({}, req[BodySymbol], body);
374
- } else {
375
- body = req[BodySymbol];
376
- }
377
- }
378
- if (body) {
379
- if (typeof key === 'string') {
380
- return body[key];
381
- }
382
- return body;
383
- }
384
- return typeof key === 'string' ? undefined : {};
385
- }
386
- function hasRequestBody(req) {
387
- return 'body' in req || BodySymbol in req;
388
- }
389
- function setRequestBody(req, key, value) {
390
- if (isObject(key)) {
391
- req[BodySymbol] = key;
392
- return;
393
- }
394
- req[BodySymbol] = {
395
- [key]: value
396
- };
397
- }
398
- function extendRequestBody(req, key, value) {
399
- if (hasRequestBody(req)) {
400
- const body = useRequestBody(req);
401
- // body can not be merged :/
402
- if (!isObject(body)) {
403
- return;
404
- }
405
- if (isObject(key)) {
406
- req[BodySymbol] = merge({}, key, body);
407
- } else {
408
- body[key] = value;
409
- req[BodySymbol] = body;
410
- }
411
- return;
412
- }
413
- if (isObject(key)) {
414
- setRequestBody(req, key);
415
- return;
416
- }
417
- setRequestBody(req, key, value);
418
- }
419
-
420
- function isRequestCacheable(req, modifiedTime) {
421
- const modifiedSince = req.headers[HeaderName.IF_MODIFIED_SINCE];
422
- if (!modifiedSince) {
423
- return false;
424
- }
425
- modifiedTime = typeof modifiedTime === 'string' ? new Date(modifiedTime) : modifiedTime;
426
- return new Date(modifiedSince) >= modifiedTime;
427
- }
428
-
429
- const CookieSymbol = Symbol.for('ReqCookie');
430
- function useRequestCookies(req) {
431
- if (CookieSymbol in req) {
432
- return req[CookieSymbol];
433
- }
434
- return {};
435
- }
436
- function hasRequestCookies(req) {
437
- return CookieSymbol in req && isObject(req[CookieSymbol]);
438
- }
439
- function useRequestCookie(req, name) {
440
- return useRequestCookies(req)[name];
441
- }
442
- function setRequestCookies(req, key, value) {
443
- if (isObject(key)) {
444
- req[CookieSymbol] = key;
445
- return;
446
- }
447
- req[CookieSymbol] = {
448
- [key]: value
449
- };
450
- }
451
- function extendRequestCookies(req, key, value) {
452
- if (hasRequestCookies(req)) {
453
- const cookies = useRequestCookies(req);
454
- if (isObject(key)) {
455
- req[CookieSymbol] = merge({}, key, cookies);
456
- } else {
457
- cookies[key] = value;
458
- req[CookieSymbol] = cookies;
459
- }
460
- req[CookieSymbol] = merge(req[CookieSymbol], cookies);
461
- return;
462
- }
463
- if (isObject(key)) {
464
- setRequestCookies(req, key);
465
- return;
466
- }
467
- setRequestCookies(req, key, value);
468
- }
469
-
470
- const envSymbol = Symbol.for('ReqEnv');
471
- function setRequestEnv(req, key, value) {
472
- if (envSymbol in req) {
473
- if (typeof key === 'object') {
474
- if (value) {
475
- req[envSymbol] = merge(req[envSymbol], key);
476
- } else {
477
- req[envSymbol] = key;
478
- }
479
- } else {
480
- req[envSymbol][key] = value;
481
- }
482
- return;
483
- }
484
- if (typeof key === 'object') {
485
- req[envSymbol] = key;
486
- return;
487
- }
488
- req[envSymbol] = {
489
- [key]: value
490
- };
491
- }
492
- function useRequestEnv(req, key) {
493
- if (envSymbol in req) {
494
- if (typeof key === 'string') {
495
- return req[envSymbol][key];
496
- }
497
- return req[envSymbol];
498
- }
499
- if (typeof key === 'string') {
500
- return undefined;
501
- }
502
- return {};
503
- }
504
- function unsetRequestEnv(req, key) {
505
- if (envSymbol in req) {
506
- if (hasOwnProperty(req[envSymbol], key)) {
507
- delete req[envSymbol][key];
508
- }
509
- }
510
- }
511
-
512
- function getRequestHeader(req, name) {
513
- return req.headers[name];
514
- }
515
- function setRequestHeader(req, name, value) {
516
- req.headers[name] = value;
517
- }
518
-
519
423
  const NegotiatorSymbol = Symbol.for('ReqNegotiator');
520
424
  function useRequestNegotiator(req) {
521
425
  if (NegotiatorSymbol in req) {
@@ -773,52 +677,6 @@ function getRequestProtocol(req, options) {
773
677
  return index !== -1 ? header.substring(0, index).trim() : header.trim();
774
678
  }
775
679
 
776
- const QuerySymbol = Symbol.for('ReqQuery');
777
- function useRequestQuery(req, key) {
778
- /* istanbul ignore if */ if ('query' in req) {
779
- if (typeof key === 'string') {
780
- return req.query[key];
781
- }
782
- return req.query;
783
- }
784
- if (QuerySymbol in req) {
785
- if (typeof key === 'string') {
786
- return req[QuerySymbol][key];
787
- }
788
- return req[QuerySymbol];
789
- }
790
- return typeof key === 'string' ? undefined : {};
791
- }
792
- function hasRequestQuery(req) {
793
- return QuerySymbol in req && isObject(req[QuerySymbol]) || 'query' in req && isObject(req.query);
794
- }
795
- function setRequestQuery(req, key, value) {
796
- if (isObject(key)) {
797
- req[QuerySymbol] = key;
798
- return;
799
- }
800
- req[QuerySymbol] = {
801
- [key]: value
802
- };
803
- }
804
- function extendRequestQuery(req, key, value) {
805
- if (hasRequestQuery(req)) {
806
- const query = useRequestQuery(req);
807
- if (isObject(key)) {
808
- req[QuerySymbol] = merge({}, key, query);
809
- } else {
810
- query[key] = value;
811
- req[QuerySymbol] = query;
812
- }
813
- return;
814
- }
815
- if (isObject(key)) {
816
- setRequestQuery(req, key);
817
- return;
818
- }
819
- setRequestQuery(req, key, value);
820
- }
821
-
822
680
  function createRequest(context) {
823
681
  let readable;
824
682
  if (context.body) {
@@ -2092,5 +1950,5 @@ class Router {
2092
1950
  }
2093
1951
  }
2094
1952
 
2095
- export { ErrorProxy, HandlerType, HeaderName, Layer, MethodName, PathMatcher, Router, appendResponseHeader, appendResponseHeaderDirective, buildDispatcherMeta, cloneDispatcherMeta, cloneDispatcherMetaParams, coreHandler, createError, createNodeDispatcher, createRawDispatcher, createRequest, createResponse, createWebDispatcher, dispatchNodeRequest, dispatchRawRequest, dispatchWebRequest, errorHandler, extendRequestBody, extendRequestCookies, extendRequestQuery, getRequestAcceptableCharset, getRequestAcceptableCharsets, getRequestAcceptableContentType, getRequestAcceptableContentTypes, getRequestAcceptableEncoding, getRequestAcceptableEncodings, getRequestAcceptableLanguage, getRequestAcceptableLanguages, getRequestHeader, getRequestHostName, getRequestIP, getRequestProtocol, hasRequestBody, hasRequestCookies, hasRequestQuery, isError, isHandler, isLayerInstance, isPath, isPlugin, isRequestCacheable, isResponseGone, isRouterInstance, matchRequestContentType, mergeDispatcherMetaParams, send, sendAccepted, sendCreated, sendFile, sendFormat, sendRedirect, sendStream, sendWebBlob, sendWebResponse, setRequestBody, setRequestCookies, setRequestEnv, setRequestHeader, setRequestMountPath, setRequestParam, setRequestParams, setRequestQuery, setRequestRouterPath, setResponseCacheHeaders, setResponseContentTypeByFileName, setResponseHeaderAttachment, setResponseHeaderContentType, unsetRequestEnv, useRequestBody, useRequestCookie, useRequestCookies, useRequestEnv, useRequestMountPath, useRequestNegotiator, useRequestParam, useRequestParams, useRequestPath, useRequestQuery, useRequestRouterPath };
1953
+ export { ErrorProxy, HandlerType, HeaderName, Layer, MethodName, PathMatcher, Router, appendResponseHeader, appendResponseHeaderDirective, buildDispatcherMeta, cloneDispatcherMeta, cloneDispatcherMetaParams, coreHandler, createError, createNodeDispatcher, createRawDispatcher, createRequest, createResponse, createWebDispatcher, dispatchNodeRequest, dispatchRawRequest, dispatchWebRequest, errorHandler, getRequestAcceptableCharset, getRequestAcceptableCharsets, getRequestAcceptableContentType, getRequestAcceptableContentTypes, getRequestAcceptableEncoding, getRequestAcceptableEncodings, getRequestAcceptableLanguage, getRequestAcceptableLanguages, getRequestHeader, getRequestHostName, getRequestIP, getRequestProtocol, isError, isHandler, isLayerInstance, isPath, isPlugin, isRequestCacheable, isResponseGone, isRouterInstance, matchRequestContentType, mergeDispatcherMetaParams, send, sendAccepted, sendCreated, sendFile, sendFormat, sendRedirect, sendStream, sendWebBlob, sendWebResponse, setRequestEnv, setRequestHeader, setRequestMountPath, setRequestParam, setRequestParams, setRequestRouterPath, setResponseCacheHeaders, setResponseContentTypeByFileName, setResponseHeaderAttachment, setResponseHeaderContentType, unsetRequestEnv, useRequestEnv, useRequestMountPath, useRequestNegotiator, useRequestParam, useRequestParams, useRequestPath, useRequestRouterPath };
2096
1954
  //# sourceMappingURL=index.mjs.map