routup 3.2.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.
@@ -1,7 +1,7 @@
1
- import type { ParseOptions, TokensToRegexpOptions } from 'path-to-regexp';
2
- export type PathMatcherOptions = TokensToRegexpOptions & ParseOptions;
1
+ import type { ParseOptions, PathToRegexpOptions } from 'path-to-regexp';
2
+ export type PathMatcherOptions = PathToRegexpOptions & ParseOptions;
3
3
  export type PathMatcherExecResult = {
4
4
  path: string;
5
5
  params: Record<string, any>;
6
6
  };
7
- export type Path = string | RegExp;
7
+ export type Path = string;
@@ -1,6 +1,6 @@
1
1
  import type { Request } from '../types';
2
- export declare function setRequestEnv(req: Request, key: string, value: unknown): void;
3
- export declare function setRequestEnv(req: Request, record: Record<string, any>, append?: boolean): void;
2
+ export declare function setRequestEnv(req: Request, key: string | symbol, value: unknown): void;
3
+ export declare function setRequestEnv(req: Request, record: Record<string | symbol, any>, append?: boolean): void;
4
4
  export declare function useRequestEnv(req: Request): Record<string, any>;
5
- export declare function useRequestEnv(req: Request, key: string): unknown | undefined;
6
- export declare function unsetRequestEnv(req: Request, key: string): void;
5
+ export declare function useRequestEnv(req: Request, key: PropertyKey): unknown | undefined;
6
+ export declare function unsetRequestEnv(req: Request, key: PropertyKey): void;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import type { IncomingMessage } from 'node:http';
3
2
  export declare function getRequestAcceptableEncodings(req: IncomingMessage): string[];
4
3
  export declare function getRequestAcceptableEncoding(req: IncomingMessage, input: string | string[]): string | undefined;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import type { IncomingHttpHeaders } from 'node:http';
3
2
  import type { Request } from '../types';
4
3
  export declare function getRequestHeader<K extends keyof IncomingHttpHeaders>(req: Request, name: K): IncomingHttpHeaders[K];
@@ -0,0 +1,2 @@
1
+ import type { Request } from '../types';
2
+ export declare function isRequestHTTP2(req: Request): boolean;
@@ -7,6 +7,7 @@ export * from './header-accept-encoding';
7
7
  export * from './header-accept-language';
8
8
  export * from './header-content-type';
9
9
  export * from './hostname';
10
+ export * from './http2';
10
11
  export * from './ip';
11
12
  export * from './mount-path';
12
13
  export * from './negotiator';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import type { IncomingMessage } from 'node:http';
3
2
  import type { RequestCreateContext } from './types';
4
3
  export declare function createRequest(context: RequestCreateContext): IncomingMessage;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import type { IncomingMessage } from 'node:http';
3
2
  import type { NodeReadableStream, WebReadableStream } from '../types';
4
3
  export type RequestBody = null | Iterable<any> | AsyncIterable<any> | NodeReadableStream | WebReadableStream;
@@ -0,0 +1,3 @@
1
+ import type { Response } from '../../types';
2
+ import { EventStream } from './module';
3
+ export declare function createEventStream(response: Response): EventStream;
@@ -0,0 +1,2 @@
1
+ export * from './factory';
2
+ export * from './module';
@@ -0,0 +1,17 @@
1
+ import { PassThrough } from 'readable-stream';
2
+ import type { Response } from '../../types';
3
+ import type { EventStreamListener, EventStreamMessage } from './types';
4
+ export declare class EventStream {
5
+ protected response: Response;
6
+ protected passThrough: PassThrough;
7
+ protected flushed: boolean;
8
+ protected eventHandlers: Record<string, EventStreamListener[]>;
9
+ constructor(response: Response);
10
+ protected open(): void;
11
+ write(message: EventStreamMessage): void;
12
+ write(message: string): void;
13
+ end(): void;
14
+ on(event: 'close', listener: EventStreamListener): void;
15
+ on(event: 'error', listener: EventStreamListener): void;
16
+ protected emit(event: string, ...args: any[]): void;
17
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#event_stream_format
3
+ */
4
+ export type EventStreamMessage = {
5
+ /**
6
+ * The event ID to set the EventSource object's last event ID value.
7
+ */
8
+ id?: string;
9
+ /**
10
+ * The reconnection time.
11
+ * If the connection to the server is lost, the browser will wait for the specified time before attempting to reconnect.
12
+ * This must be an integer, specifying the reconnection time in milliseconds.
13
+ */
14
+ retry?: number;
15
+ /**
16
+ * The data field for the message.
17
+ */
18
+ data: string;
19
+ /**
20
+ * A string identifying the type of event described.
21
+ */
22
+ event?: string;
23
+ };
24
+ export type EventStreamListener<T = any> = (err: Error | null, data: T) => void | Promise<void>;
@@ -0,0 +1,2 @@
1
+ import type { EventStreamMessage } from './types';
2
+ export declare function serializeEventStreamMessage(message: EventStreamMessage): string;
@@ -1,2 +1,3 @@
1
1
  import type { Response } from '../types';
2
2
  export declare function isResponseGone(res: Response): any;
3
+ export declare function setResponseGone(res: Response, value: boolean): void;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import type { OutgoingHttpHeader } from 'node:http';
3
2
  import type { Response } from '../types';
4
3
  export declare function appendResponseHeader(res: Response, name: string, value: OutgoingHttpHeader): void;
@@ -1,4 +1,5 @@
1
1
  export * from './cache';
2
+ export * from './event-stream';
2
3
  export * from './gone';
3
4
  export * from './header';
4
5
  export * from './header-attachment';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import type { ServerResponse } from 'node:http';
3
2
  export interface Response extends ServerResponse {
4
3
  }
package/dist/types.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import type { Readable as NodeReadable } from 'node:stream';
4
2
  import type { Readable } from 'readable-stream';
5
3
  import type { ReadableStream } from 'stream/web';
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { Buffer } from 'buffer';
4
2
  import { type Stats } from 'node:fs';
5
3
  import type { EtagOptions } from './type';
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  export type EtagOptions = {
3
2
  /**
4
3
  * Create a weak ETag?
@@ -1 +1,3 @@
1
1
  export declare function isObject(item: unknown): item is Record<string, any>;
2
+ export declare function setProperty(record: Record<PropertyKey, any>, property: PropertyKey, value: any): void;
3
+ export declare function getProperty<T = any>(req: Record<PropertyKey, any>, property: PropertyKey): T;
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import type { ReadableStream as WebReadableStream } from 'stream/web';
4
2
  import type { Readable as NodeReadable } from 'node:stream';
5
3
  import type { Readable } from 'readable-stream';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "routup",
3
- "version": "3.2.0",
3
+ "version": "4.0.0",
4
4
  "description": "Routup is a minimalistic http based routing framework.",
5
5
  "exports": {
6
6
  "./package.json": "./package.json",
@@ -52,35 +52,35 @@
52
52
  "dependencies": {
53
53
  "@ebec/http": "^2.3.0",
54
54
  "buffer": "^6.0.3",
55
- "mime-explorer": "^1.0.0",
55
+ "mime-explorer": "^1.1.0",
56
56
  "negotiator": "^0.6.3",
57
- "path-to-regexp": "^6.2.1",
57
+ "path-to-regexp": "^7.0.0",
58
58
  "proxy-addr": "^2.0.7",
59
- "readable-stream": "^4.4.2",
60
- "smob": "^1.4.1",
59
+ "readable-stream": "^4.5.2",
60
+ "smob": "^1.5.0",
61
61
  "uncrypto": "^0.1.3"
62
62
  },
63
63
  "devDependencies": {
64
- "@rollup/plugin-commonjs": "^25.0.7",
64
+ "@rollup/plugin-commonjs": "^26.0.1",
65
65
  "@rollup/plugin-node-resolve": "^15.2.3",
66
- "@swc/core": "^1.3.96",
67
- "@swc/jest": "^0.2.29",
68
- "@tada5hi/commitlint-config": "^1.1.3",
69
- "@tada5hi/eslint-config-typescript": "^1.2.6",
70
- "@tada5hi/semantic-release": "^0.3.0",
71
- "@tada5hi/tsconfig": "^0.5.0",
72
- "@types/jest": "^29.5.7",
73
- "@types/negotiator": "^0.6.2",
74
- "@types/node": "^20.8.10",
75
- "@types/proxy-addr": "^2.0.2",
76
- "@types/readable-stream": "^4.0.4",
77
- "@types/supertest": "^2.0.15",
66
+ "@swc/core": "^1.6.5",
67
+ "@swc/jest": "^0.2.36",
68
+ "@tada5hi/commitlint-config": "^1.2.1",
69
+ "@tada5hi/eslint-config-typescript": "^1.2.11",
70
+ "@tada5hi/semantic-release": "^0.3.1",
71
+ "@tada5hi/tsconfig": "^0.5.1",
72
+ "@types/jest": "^29.5.12",
73
+ "@types/negotiator": "^0.6.3",
74
+ "@types/node": "^20.12.2",
75
+ "@types/proxy-addr": "^2.0.3",
76
+ "@types/readable-stream": "^4.0.14",
77
+ "@types/supertest": "^6.0.2",
78
78
  "cross-env": "^7.0.3",
79
79
  "jest": "^29.7.0",
80
- "rimraf": "^5.0.5",
81
- "rollup": "^4.3.0",
82
- "semantic-release": "^22.0.7",
83
- "supertest": "^6.3.3",
84
- "typescript": "5.2.2"
80
+ "rimraf": "^5.0.7",
81
+ "rollup": "^4.18.0",
82
+ "semantic-release": "^22.0.12",
83
+ "supertest": "^7.0.0",
84
+ "typescript": "5.5.2"
85
85
  }
86
86
  }