@bjoernboss/mws 1.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/LICENSE.txt +29 -0
- package/README.md +301 -0
- package/dist/base.d.ts +198 -0
- package/dist/base.js +73 -0
- package/dist/builder.d.ts +58 -0
- package/dist/builder.js +146 -0
- package/dist/cache.d.ts +66 -0
- package/dist/cache.js +708 -0
- package/dist/client.d.ts +228 -0
- package/dist/client.js +1646 -0
- package/dist/handler.d.ts +119 -0
- package/dist/handler.js +542 -0
- package/dist/helper.d.ts +33 -0
- package/dist/helper.js +363 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +12 -0
- package/dist/log.d.ts +52 -0
- package/dist/log.js +288 -0
- package/dist/server.d.ts +66 -0
- package/dist/server.js +257 -0
- package/package.json +46 -0
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import * as libLog from "./log.js";
|
|
2
|
+
import * as libBuilder from "./builder.js";
|
|
3
|
+
import * as libCache from "./cache.js";
|
|
4
|
+
import * as libBase from "./base.js";
|
|
5
|
+
import * as libStream from "stream";
|
|
6
|
+
import * as libUrl from "url";
|
|
7
|
+
import * as libWs from "ws";
|
|
8
|
+
import * as libHttp from "http";
|
|
9
|
+
declare class ClientContext {
|
|
10
|
+
dropLogTag: () => void;
|
|
11
|
+
path: string;
|
|
12
|
+
translationCount: number;
|
|
13
|
+
busyCount: number;
|
|
14
|
+
headerPatchCount: number;
|
|
15
|
+
htmlPatchCount: number;
|
|
16
|
+
constructor(path: string, translationCount: number, busyCount: number, headerPatchCount: number, htmlPatchCount: number);
|
|
17
|
+
}
|
|
18
|
+
declare class ClientBase extends libLog.Logger {
|
|
19
|
+
private _config;
|
|
20
|
+
protected _path: string;
|
|
21
|
+
protected _translation: Record<string, string | null>[];
|
|
22
|
+
protected constructor(url: libUrl.URL, kind: string, config: BurntClientConfig);
|
|
23
|
+
protected constructor(client: ClientBase, kind: string, config: BurntClientConfig);
|
|
24
|
+
readonly url: libUrl.URL;
|
|
25
|
+
get path(): string;
|
|
26
|
+
get config(): BurntClientConfig;
|
|
27
|
+
isSubPathOf(base: string): boolean;
|
|
28
|
+
isInsideOf(base: string): boolean;
|
|
29
|
+
makePath(path: string): string;
|
|
30
|
+
}
|
|
31
|
+
export type HeaderPatch = (status: libBase.StatusType, headers: Record<string, string>) => void;
|
|
32
|
+
export type HtmlPatch = (page: libBuilder.HtmlPage, status: libBase.StatusType, headers: Record<string, string>) => Promise<void>;
|
|
33
|
+
export declare class ClientRequest extends ClientBase {
|
|
34
|
+
private _headerPatcher;
|
|
35
|
+
private _htmlPatcher;
|
|
36
|
+
private _state;
|
|
37
|
+
private _throughput;
|
|
38
|
+
private _native;
|
|
39
|
+
private _request;
|
|
40
|
+
private _cache;
|
|
41
|
+
private constructor();
|
|
42
|
+
private constructQuickResponse;
|
|
43
|
+
private failThroughput;
|
|
44
|
+
private updateThroughput;
|
|
45
|
+
private wrapSocketWriter;
|
|
46
|
+
private killNativeConnection;
|
|
47
|
+
private markAsBroken;
|
|
48
|
+
private badClientUsage;
|
|
49
|
+
private closeHeader;
|
|
50
|
+
private sendFullResponse;
|
|
51
|
+
private sendClientSetupHeader;
|
|
52
|
+
private sendClientWrite;
|
|
53
|
+
private sendClientData;
|
|
54
|
+
private receiveClientData;
|
|
55
|
+
_pushTranslation(map: Record<string, string | null>, identity: string): ClientContext | null;
|
|
56
|
+
_restoreSnapshot(snapshot: ClientContext): void;
|
|
57
|
+
static fromRequest(protocol: string, request: libHttp.IncomingMessage, response: libHttp.ServerResponse, options?: {
|
|
58
|
+
config?: BurntClientConfig | ClientConfig;
|
|
59
|
+
cache?: libCache.CacheHost | libCache.CacheConfig | libCache.BurntCacheConfig;
|
|
60
|
+
}): ClientRequest;
|
|
61
|
+
static fromUpgrade(protocol: string, request: libHttp.IncomingMessage, socket: libStream.Duplex, head: Buffer, options?: {
|
|
62
|
+
config?: BurntClientConfig | ClientConfig;
|
|
63
|
+
cache?: libCache.CacheHost | libCache.CacheConfig | libCache.BurntCacheConfig;
|
|
64
|
+
wss?: libWs.WebSocketServer;
|
|
65
|
+
}): ClientRequest;
|
|
66
|
+
finalizeConnection(): Promise<void>;
|
|
67
|
+
killConnection(reason: string): void;
|
|
68
|
+
get cache(): libCache.CacheHost;
|
|
69
|
+
get unhandled(): boolean;
|
|
70
|
+
get claimed(): boolean;
|
|
71
|
+
get responded(): Promise<void>;
|
|
72
|
+
get completed(): Promise<void>;
|
|
73
|
+
get headers(): libHttp.IncomingHttpHeaders;
|
|
74
|
+
get method(): string;
|
|
75
|
+
get isHead(): boolean;
|
|
76
|
+
getMediaType(): string;
|
|
77
|
+
getMediaTypeCharset(defEncoding: string): string;
|
|
78
|
+
requireMediaType(types: libBase.MediaType[] | libBase.MediaType, options?: {
|
|
79
|
+
noneIsFirst?: boolean;
|
|
80
|
+
headers?: Record<string, string>;
|
|
81
|
+
}): libBase.MediaType | null;
|
|
82
|
+
requireMethod(methods: string[] | string, options?: {
|
|
83
|
+
headExplicit?: boolean;
|
|
84
|
+
headers?: Record<string, string>;
|
|
85
|
+
}): string | null;
|
|
86
|
+
busyCheck(cb: () => boolean): void;
|
|
87
|
+
patchHeaders(cb: HeaderPatch): void;
|
|
88
|
+
patchHtmlPage(cb: HtmlPatch): void;
|
|
89
|
+
respondInternalError(reason: string, options?: {
|
|
90
|
+
headers?: Record<string, string>;
|
|
91
|
+
}): void;
|
|
92
|
+
respondForbidden(reason: string, options?: {
|
|
93
|
+
headers?: Record<string, string>;
|
|
94
|
+
}): void;
|
|
95
|
+
respond(content: string | Buffer | null, options?: {
|
|
96
|
+
media?: libBase.MediaType;
|
|
97
|
+
status?: libBase.StatusType;
|
|
98
|
+
headers?: Record<string, string>;
|
|
99
|
+
lightResponse?: boolean;
|
|
100
|
+
}): void;
|
|
101
|
+
respondOk(options?: {
|
|
102
|
+
message?: string;
|
|
103
|
+
headers?: Record<string, string>;
|
|
104
|
+
}): void;
|
|
105
|
+
respondCreated(target: string, options?: {
|
|
106
|
+
headers?: Record<string, string>;
|
|
107
|
+
}): void;
|
|
108
|
+
respondNotModified(options?: {
|
|
109
|
+
etag?: string;
|
|
110
|
+
lastModified?: string;
|
|
111
|
+
headers?: Record<string, string>;
|
|
112
|
+
}): void;
|
|
113
|
+
respondPreconditionFailed(reason: string, options?: {
|
|
114
|
+
etag?: string;
|
|
115
|
+
lastModified?: string;
|
|
116
|
+
headers?: Record<string, string>;
|
|
117
|
+
}): void;
|
|
118
|
+
respondBadRequest(reason: string, options?: {
|
|
119
|
+
headers?: Record<string, string>;
|
|
120
|
+
}): void;
|
|
121
|
+
respondRangeIssue(range: string, size: number, options?: {
|
|
122
|
+
headers?: Record<string, string>;
|
|
123
|
+
}): void;
|
|
124
|
+
respondConflict(conflict: string, options?: {
|
|
125
|
+
headers?: Record<string, string>;
|
|
126
|
+
}): void;
|
|
127
|
+
respondNotFound(options?: {
|
|
128
|
+
headers?: Record<string, string>;
|
|
129
|
+
}): void;
|
|
130
|
+
respondUnsupported(used: string, allowed: string, options?: {
|
|
131
|
+
headers?: Record<string, string>;
|
|
132
|
+
}): void;
|
|
133
|
+
respondMethodNotAllowed(method: string, allowed: string, options?: {
|
|
134
|
+
headers?: Record<string, string>;
|
|
135
|
+
}): void;
|
|
136
|
+
respondRequestTimeout(reason: string, options?: {
|
|
137
|
+
headers?: Record<string, string>;
|
|
138
|
+
}): void;
|
|
139
|
+
respondContentTooLarge(allowed: number, atLeastProvided: number, options?: {
|
|
140
|
+
headers?: Record<string, string>;
|
|
141
|
+
}): void;
|
|
142
|
+
respondUpdateRequired(upgrade: string, options?: {
|
|
143
|
+
headers?: Record<string, string>;
|
|
144
|
+
}): void;
|
|
145
|
+
respondSeeOther(target: string, options?: {
|
|
146
|
+
headers?: Record<string, string>;
|
|
147
|
+
}): void;
|
|
148
|
+
respondTemporaryRedirect(target: string, options?: {
|
|
149
|
+
headers?: Record<string, string>;
|
|
150
|
+
}): void;
|
|
151
|
+
respondPermanentRedirect(target: string, options?: {
|
|
152
|
+
headers?: Record<string, string>;
|
|
153
|
+
}): void;
|
|
154
|
+
respondHtml(page: libBuilder.HtmlPage, options?: {
|
|
155
|
+
status?: libBase.StatusType;
|
|
156
|
+
headers?: Record<string, string>;
|
|
157
|
+
}): Promise<void>;
|
|
158
|
+
respondData(options?: {
|
|
159
|
+
status?: libBase.StatusType;
|
|
160
|
+
media?: libBase.MediaType;
|
|
161
|
+
contentSize?: number;
|
|
162
|
+
dynamicEncode?: boolean;
|
|
163
|
+
headers?: Record<string, string>;
|
|
164
|
+
}): libStream.Writable;
|
|
165
|
+
tryRespondFile(filePath: string, options?: {
|
|
166
|
+
encoded?: string;
|
|
167
|
+
media?: libBase.MediaType;
|
|
168
|
+
headers?: Record<string, string>;
|
|
169
|
+
checkFreshness?: boolean;
|
|
170
|
+
}): Promise<boolean>;
|
|
171
|
+
receiveToFile(path: string, maxLength: number | null): Promise<void>;
|
|
172
|
+
receiveData(maxLength: number | null): libStream.Readable;
|
|
173
|
+
receiveAllBuffer(maxLength: number | null): Promise<Buffer>;
|
|
174
|
+
receiveAllText(encoding: string, maxLength: number | null): Promise<string>;
|
|
175
|
+
acceptWebSocket(): Promise<ClientSocket | null>;
|
|
176
|
+
}
|
|
177
|
+
export declare class ClientSocket extends ClientBase {
|
|
178
|
+
private _ws;
|
|
179
|
+
private _alive;
|
|
180
|
+
private _closing;
|
|
181
|
+
private _emitter;
|
|
182
|
+
private _extension;
|
|
183
|
+
private constructor();
|
|
184
|
+
private checkIsAlive;
|
|
185
|
+
private selfIsAlive;
|
|
186
|
+
private handleClosing;
|
|
187
|
+
static _fromRequest(ws: libWs.WebSocket, source: ClientRequest): ClientSocket;
|
|
188
|
+
send(data: string | Buffer): void;
|
|
189
|
+
close(): Promise<void>;
|
|
190
|
+
on<K extends keyof ClientSocketEvents>(event: K, listener: ClientSocketEvents[K]): ClientSocket;
|
|
191
|
+
off<K extends keyof ClientSocketEvents>(event: K, listener: ClientSocketEvents[K]): ClientSocket;
|
|
192
|
+
once<K extends keyof ClientSocketEvents>(event: K, listener: ClientSocketEvents[K]): ClientSocket;
|
|
193
|
+
private emitEventSync;
|
|
194
|
+
}
|
|
195
|
+
type ClientSocketEvents = {
|
|
196
|
+
'data': (data: Buffer) => void;
|
|
197
|
+
'close': () => void;
|
|
198
|
+
};
|
|
199
|
+
export interface ClientConfig {
|
|
200
|
+
serverName?: string;
|
|
201
|
+
commonHeaders?: Record<string, string>;
|
|
202
|
+
webSocketTimeout?: number;
|
|
203
|
+
webSocketAliveTimeout?: number;
|
|
204
|
+
killGraceTimeout?: number;
|
|
205
|
+
fileCacheControl?: string;
|
|
206
|
+
immutableCacheControl?: string;
|
|
207
|
+
responseCacheControl?: string;
|
|
208
|
+
throughputGrace?: number;
|
|
209
|
+
throughputThreshold?: number;
|
|
210
|
+
throughputWindow?: number;
|
|
211
|
+
}
|
|
212
|
+
export declare class BurntClientConfig {
|
|
213
|
+
readonly serverName: string;
|
|
214
|
+
readonly commonHeaders: Record<string, string>;
|
|
215
|
+
readonly webSocketTimeout: number;
|
|
216
|
+
readonly webSocketAliveTimeout: number;
|
|
217
|
+
readonly killGraceTimeout: number;
|
|
218
|
+
readonly fileCacheControl: string;
|
|
219
|
+
readonly immutableCacheControl: string;
|
|
220
|
+
readonly responseCacheControl: string;
|
|
221
|
+
readonly throughputGrace: number;
|
|
222
|
+
readonly throughputThreshold: number;
|
|
223
|
+
readonly throughputWindow: number;
|
|
224
|
+
constructor(config?: ClientConfig);
|
|
225
|
+
static from(config?: ClientConfig | BurntClientConfig): BurntClientConfig;
|
|
226
|
+
}
|
|
227
|
+
export {};
|
|
228
|
+
//# sourceMappingURL=client.d.ts.map
|