@kevisual/router 0.0.38 → 0.0.40
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 +3 -3
- package/dist/router-browser.js +2 -5
- package/dist/router-sign.js +1 -3
- package/dist/router-simple.d.ts +2 -2
- package/dist/router.d.ts +98 -4
- package/dist/router.js +243 -369
- package/package.json +6 -8
- package/src/result/error.ts +2 -5
- package/src/server/cookie.ts +543 -0
- package/src/server/server.ts +1 -1
package/dist/router-browser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import * as
|
|
2
|
+
import * as node_querystring from 'node:querystring';
|
|
3
3
|
import { IncomingMessage } from 'node:http';
|
|
4
4
|
import { RouteOpts as RouteOpts$1, QueryRouterServer as QueryRouterServer$1, RouteMiddleware as RouteMiddleware$1, Run as Run$1 } from '@kevisual/router';
|
|
5
5
|
import { Query, DataOpts, Result } from '@kevisual/query/query';
|
|
@@ -406,7 +406,7 @@ declare class CustomError extends Error {
|
|
|
406
406
|
* @param err
|
|
407
407
|
* @returns
|
|
408
408
|
*/
|
|
409
|
-
static isError(
|
|
409
|
+
static isError(error: unknown): error is CustomError;
|
|
410
410
|
parse(e?: CustomError): {
|
|
411
411
|
code: number;
|
|
412
412
|
data: any;
|
|
@@ -416,7 +416,7 @@ declare class CustomError extends Error {
|
|
|
416
416
|
}
|
|
417
417
|
|
|
418
418
|
declare const parseBody: <T = Record<string, any>>(req: IncomingMessage) => Promise<T>;
|
|
419
|
-
declare const parseSearch: (req: IncomingMessage) =>
|
|
419
|
+
declare const parseSearch: (req: IncomingMessage) => node_querystring.ParsedUrlQuery;
|
|
420
420
|
/**
|
|
421
421
|
* 把url当个key 的 value 的字符串转成json
|
|
422
422
|
* @param value
|
package/dist/router-browser.js
CHANGED
|
@@ -56,11 +56,8 @@ class CustomError extends Error {
|
|
|
56
56
|
* @param err
|
|
57
57
|
* @returns
|
|
58
58
|
*/
|
|
59
|
-
static isError(
|
|
60
|
-
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
return false;
|
|
59
|
+
static isError(error) {
|
|
60
|
+
return error instanceof CustomError || (typeof error === 'object' && error !== null && 'code' in error);
|
|
64
61
|
}
|
|
65
62
|
parse(e) {
|
|
66
63
|
if (e) {
|
package/dist/router-sign.js
CHANGED
|
@@ -3272,9 +3272,7 @@ class LocalBitStringValueBlock extends HexBlock(LocalConstructedValueBlock) {
|
|
|
3272
3272
|
return new ArrayBuffer(this.valueHexView.byteLength + 1);
|
|
3273
3273
|
}
|
|
3274
3274
|
if (!this.valueHexView.byteLength) {
|
|
3275
|
-
|
|
3276
|
-
empty[0] = 0;
|
|
3277
|
-
return empty.buffer;
|
|
3275
|
+
return EMPTY_BUFFER;
|
|
3278
3276
|
}
|
|
3279
3277
|
const retView = new Uint8Array(this.valueHexView.length + 1);
|
|
3280
3278
|
retView[0] = this.unusedBits;
|
package/dist/router-simple.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as node_querystring from 'node:querystring';
|
|
2
2
|
import { Key } from 'path-to-regexp';
|
|
3
3
|
import { IncomingMessage, ServerResponse, Server } from 'node:http';
|
|
4
4
|
import { ListenOptions } from 'node:net';
|
|
@@ -25,7 +25,7 @@ declare class SimpleRouter {
|
|
|
25
25
|
exclude?: string[];
|
|
26
26
|
});
|
|
27
27
|
getBody(req: Req): Promise<Record<string, any>>;
|
|
28
|
-
getSearch(req: Req):
|
|
28
|
+
getSearch(req: Req): node_querystring.ParsedUrlQuery;
|
|
29
29
|
parseSearchValue: (value?: string, opts?: {
|
|
30
30
|
decode?: boolean;
|
|
31
31
|
}) => any;
|
package/dist/router.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import http, { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
2
|
import https from 'node:https';
|
|
3
3
|
import http2 from 'node:http2';
|
|
4
|
-
import * as cookie from 'cookie';
|
|
5
4
|
import { z } from 'zod';
|
|
6
5
|
import { WebSocketServer, WebSocket } from 'ws';
|
|
7
6
|
import { IncomingMessage as IncomingMessage$1, ServerResponse as ServerResponse$1 } from 'http';
|
|
@@ -383,8 +382,103 @@ declare class QueryConnect {
|
|
|
383
382
|
}[];
|
|
384
383
|
}
|
|
385
384
|
|
|
385
|
+
interface StringifyOptions {
|
|
386
|
+
/**
|
|
387
|
+
* Specifies a function that will be used to encode a [cookie-value](https://datatracker.ietf.org/doc/html/rfc6265#section-4.1.1).
|
|
388
|
+
* Since value of a cookie has a limited character set (and must be a simple string), this function can be used to encode
|
|
389
|
+
* a value into a string suited for a cookie's value, and should mirror `decode` when parsing.
|
|
390
|
+
*
|
|
391
|
+
* @default encodeURIComponent
|
|
392
|
+
*/
|
|
393
|
+
encode?: (str: string) => string;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Set-Cookie object.
|
|
397
|
+
*/
|
|
398
|
+
interface SetCookie {
|
|
399
|
+
/**
|
|
400
|
+
* Specifies the name of the cookie.
|
|
401
|
+
*/
|
|
402
|
+
name: string;
|
|
403
|
+
/**
|
|
404
|
+
* Specifies the string to be the value for the cookie.
|
|
405
|
+
*/
|
|
406
|
+
value: string | undefined;
|
|
407
|
+
/**
|
|
408
|
+
* Specifies the `number` (in seconds) to be the value for the [`Max-Age` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.2).
|
|
409
|
+
*
|
|
410
|
+
* The [cookie storage model specification](https://tools.ietf.org/html/rfc6265#section-5.3) states that if both `expires` and
|
|
411
|
+
* `maxAge` are set, then `maxAge` takes precedence, but it is possible not all clients by obey this,
|
|
412
|
+
* so if both are set, they should point to the same date and time.
|
|
413
|
+
*/
|
|
414
|
+
maxAge?: number;
|
|
415
|
+
/**
|
|
416
|
+
* Specifies the `Date` object to be the value for the [`Expires` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.1).
|
|
417
|
+
* When no expiration is set, clients consider this a "non-persistent cookie" and delete it when the current session is over.
|
|
418
|
+
*
|
|
419
|
+
* The [cookie storage model specification](https://tools.ietf.org/html/rfc6265#section-5.3) states that if both `expires` and
|
|
420
|
+
* `maxAge` are set, then `maxAge` takes precedence, but it is possible not all clients by obey this,
|
|
421
|
+
* so if both are set, they should point to the same date and time.
|
|
422
|
+
*/
|
|
423
|
+
expires?: Date;
|
|
424
|
+
/**
|
|
425
|
+
* Specifies the value for the [`Domain` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.3).
|
|
426
|
+
* When no domain is set, clients consider the cookie to apply to the current domain only.
|
|
427
|
+
*/
|
|
428
|
+
domain?: string;
|
|
429
|
+
/**
|
|
430
|
+
* Specifies the value for the [`Path` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.4).
|
|
431
|
+
* When no path is set, the path is considered the ["default path"](https://tools.ietf.org/html/rfc6265#section-5.1.4).
|
|
432
|
+
*/
|
|
433
|
+
path?: string;
|
|
434
|
+
/**
|
|
435
|
+
* Enables the [`HttpOnly` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.6).
|
|
436
|
+
* When enabled, clients will not allow client-side JavaScript to see the cookie in `document.cookie`.
|
|
437
|
+
*/
|
|
438
|
+
httpOnly?: boolean;
|
|
439
|
+
/**
|
|
440
|
+
* Enables the [`Secure` `Set-Cookie` attribute](https://tools.ietf.org/html/rfc6265#section-5.2.5).
|
|
441
|
+
* When enabled, clients will only send the cookie back if the browser has an HTTPS connection.
|
|
442
|
+
*/
|
|
443
|
+
secure?: boolean;
|
|
444
|
+
/**
|
|
445
|
+
* Enables the [`Partitioned` `Set-Cookie` attribute](https://tools.ietf.org/html/draft-cutler-httpbis-partitioned-cookies/).
|
|
446
|
+
* When enabled, clients will only send the cookie back when the current domain _and_ top-level domain matches.
|
|
447
|
+
*
|
|
448
|
+
* This is an attribute that has not yet been fully standardized, and may change in the future.
|
|
449
|
+
* This also means clients may ignore this attribute until they understand it. More information
|
|
450
|
+
* about can be found in [the proposal](https://github.com/privacycg/CHIPS).
|
|
451
|
+
*/
|
|
452
|
+
partitioned?: boolean;
|
|
453
|
+
/**
|
|
454
|
+
* Specifies the value for the [`Priority` `Set-Cookie` attribute](https://tools.ietf.org/html/draft-west-cookie-priority-00#section-4.1).
|
|
455
|
+
*
|
|
456
|
+
* - `'low'` will set the `Priority` attribute to `Low`.
|
|
457
|
+
* - `'medium'` will set the `Priority` attribute to `Medium`, the default priority when not set.
|
|
458
|
+
* - `'high'` will set the `Priority` attribute to `High`.
|
|
459
|
+
*
|
|
460
|
+
* More information about priority levels can be found in [the specification](https://tools.ietf.org/html/draft-west-cookie-priority-00#section-4.1).
|
|
461
|
+
*/
|
|
462
|
+
priority?: "low" | "medium" | "high";
|
|
463
|
+
/**
|
|
464
|
+
* Specifies the value for the [`SameSite` `Set-Cookie` attribute](https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-09#section-5.4.7).
|
|
465
|
+
*
|
|
466
|
+
* - `true` will set the `SameSite` attribute to `Strict` for strict same site enforcement.
|
|
467
|
+
* - `'lax'` will set the `SameSite` attribute to `Lax` for lax same site enforcement.
|
|
468
|
+
* - `'none'` will set the `SameSite` attribute to `None` for an explicit cross-site cookie.
|
|
469
|
+
* - `'strict'` will set the `SameSite` attribute to `Strict` for strict same site enforcement.
|
|
470
|
+
*
|
|
471
|
+
* More information about enforcement levels can be found in [the specification](https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-09#section-5.4.7).
|
|
472
|
+
*/
|
|
473
|
+
sameSite?: boolean | "lax" | "strict" | "none";
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Backward compatibility serialize options.
|
|
477
|
+
*/
|
|
478
|
+
type SerializeOptions = StringifyOptions & Omit<SetCookie, "name" | "value">;
|
|
479
|
+
|
|
386
480
|
type Listener = (...args: any[]) => void;
|
|
387
|
-
type CookieFn = (name: string, value: string, options?:
|
|
481
|
+
type CookieFn = (name: string, value: string, options?: SerializeOptions, end?: boolean) => void;
|
|
388
482
|
type HandleCtx = {
|
|
389
483
|
req: IncomingMessage & {
|
|
390
484
|
cookies: Record<string, string>;
|
|
@@ -437,7 +531,7 @@ declare class Server {
|
|
|
437
531
|
listen(path: string, listeningListener?: () => void): void;
|
|
438
532
|
listen(handle: any, backlog?: number, listeningListener?: () => void): void;
|
|
439
533
|
listen(handle: any, listeningListener?: () => void): void;
|
|
440
|
-
createServer(): http.Server<typeof IncomingMessage, typeof ServerResponse> |
|
|
534
|
+
createServer(): http.Server<typeof IncomingMessage, typeof ServerResponse> | http2.Http2SecureServer<typeof IncomingMessage, typeof ServerResponse, typeof http2.Http2ServerRequest, typeof http2.Http2ServerResponse>;
|
|
441
535
|
setHandle(handle?: any): void;
|
|
442
536
|
/**
|
|
443
537
|
* get callback
|
|
@@ -491,7 +585,7 @@ declare class CustomError extends Error {
|
|
|
491
585
|
* @param err
|
|
492
586
|
* @returns
|
|
493
587
|
*/
|
|
494
|
-
static isError(
|
|
588
|
+
static isError(error: unknown): error is CustomError;
|
|
495
589
|
parse(e?: CustomError): {
|
|
496
590
|
code: number;
|
|
497
591
|
data: any;
|