@based/type-gen 0.0.3 → 0.0.4

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.
Files changed (57) hide show
  1. package/dist/index.d.ts +7 -3
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +31 -77
  4. package/dist/index.js.map +1 -1
  5. package/dist/updateTypesPath.d.ts +15 -0
  6. package/dist/updateTypesPath.d.ts.map +1 -0
  7. package/dist/updateTypesPath.js +88 -0
  8. package/dist/updateTypesPath.js.map +1 -0
  9. package/package.json +1 -1
  10. package/src/index.ts +51 -101
  11. package/src/updateTypesPath.ts +109 -0
  12. package/test/types.ts +17 -9
  13. package/dist/auth.d.ts +0 -16
  14. package/dist/auth.d.ts.map +0 -1
  15. package/dist/auth.js +0 -3
  16. package/dist/auth.js.map +0 -1
  17. package/dist/channel.d.ts +0 -6
  18. package/dist/channel.d.ts.map +0 -1
  19. package/dist/channel.js +0 -7
  20. package/dist/channel.js.map +0 -1
  21. package/dist/client.d.ts +0 -18
  22. package/dist/client.d.ts.map +0 -1
  23. package/dist/client.js +0 -7
  24. package/dist/client.js.map +0 -1
  25. package/dist/context.d.ts +0 -100
  26. package/dist/context.d.ts.map +0 -1
  27. package/dist/context.js +0 -39
  28. package/dist/context.js.map +0 -1
  29. package/dist/fromAst.d.ts +0 -4
  30. package/dist/fromAst.d.ts.map +0 -1
  31. package/dist/fromAst.js +0 -34
  32. package/dist/fromAst.js.map +0 -1
  33. package/dist/function.d.ts +0 -1
  34. package/dist/function.d.ts.map +0 -1
  35. package/dist/function.js +0 -1
  36. package/dist/function.js.map +0 -1
  37. package/dist/functions.d.ts +0 -181
  38. package/dist/functions.d.ts.map +0 -1
  39. package/dist/functions.js +0 -29
  40. package/dist/functions.js.map +0 -1
  41. package/dist/geo.d.ts +0 -36
  42. package/dist/geo.d.ts.map +0 -1
  43. package/dist/geo.js +0 -3
  44. package/dist/geo.js.map +0 -1
  45. package/dist/parseAst.d.ts +0 -4
  46. package/dist/parseAst.d.ts.map +0 -1
  47. package/dist/parseAst.js +0 -34
  48. package/dist/parseAst.js.map +0 -1
  49. package/dist/query.d.ts +0 -7
  50. package/dist/query.d.ts.map +0 -1
  51. package/dist/query.js +0 -7
  52. package/dist/query.js.map +0 -1
  53. package/dist/stream.d.ts +0 -40
  54. package/dist/stream.d.ts.map +0 -1
  55. package/dist/stream.js +0 -63
  56. package/dist/stream.js.map +0 -1
  57. package/dist/uws.d.ts +0 -469
package/dist/stream.d.ts DELETED
@@ -1,40 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- /// <reference types="node" />
4
- /// <reference types="node" />
5
- import { Duplex, Readable } from 'stream';
6
- import util from 'node:util';
7
- export declare class BasedDataStream extends Duplex {
8
- size: number;
9
- receivedBytes: number;
10
- progessTimer: NodeJS.Timeout;
11
- constructor(size: number);
12
- _read(): void;
13
- _write(chunk: any, encoding: any, callback: any): void;
14
- _final(): void;
15
- [util.inspect.custom](): string;
16
- }
17
- export type StreamFunctionContents<F = Buffer | ArrayBuffer | string> = {
18
- contents: F;
19
- payload?: any;
20
- mimeType?: string;
21
- fileName?: string;
22
- };
23
- export type StreamFunctionStream = {
24
- contents: Readable | Duplex;
25
- payload?: any;
26
- size: number;
27
- mimeType?: string;
28
- fileName?: string;
29
- extension?: string;
30
- } | {
31
- contents: BasedDataStream;
32
- payload?: any;
33
- size?: number;
34
- mimeType?: string;
35
- fileName?: string;
36
- extension?: string;
37
- };
38
- export type StreamFunctionOpts = StreamFunctionContents | StreamFunctionStream;
39
- export declare const isStreamFunctionOpts: (opts: StreamFunctionContents | StreamFunctionStream) => opts is StreamFunctionStream;
40
- //# sourceMappingURL=stream.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":";;;;AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AACzC,OAAO,IAAI,M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var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isStreamFunctionOpts = exports.BasedDataStream = void 0;
7
- const stream_1 = require("stream");
8
- const node_util_1 = __importDefault(require("node:util"));
9
- // prob want to move this to based functions
10
- class BasedDataStream extends stream_1.Duplex {
11
- constructor(size) {
12
- super();
13
- this.size = 0;
14
- this.receivedBytes = 0;
15
- this.size = size;
16
- this.emit('progress', 0);
17
- }
18
- _read() { }
19
- _write(chunk, encoding, callback) {
20
- this.receivedBytes += chunk.byteLength;
21
- if (this.size && this.size > 20000) {
22
- if (!this.progessTimer) {
23
- this.progessTimer = setTimeout(() => {
24
- const progress = this.receivedBytes / this.size;
25
- this.emit('progress', progress);
26
- this.progessTimer = null;
27
- }, 200);
28
- }
29
- }
30
- this.push(Buffer.from(chunk, encoding));
31
- callback();
32
- }
33
- _final() {
34
- if (!this.size) {
35
- this.size = this.receivedBytes;
36
- }
37
- this.receivedBytes = this.size;
38
- if (this.progessTimer) {
39
- clearTimeout(this.progessTimer);
40
- this.progessTimer = null;
41
- }
42
- this.emit('progress', 1);
43
- this.push(null);
44
- }
45
- [node_util_1.default.inspect.custom]() {
46
- if (this.size) {
47
- const rb = this.receivedBytes < 1000
48
- ? Math.round(this.receivedBytes / 1024) + 'kb'
49
- : Math.round(this.receivedBytes / 1024 / 1024) + 'mb';
50
- return `[BasedStream ${~~((this.receivedBytes / this.size) *
51
- 100)}% ${rb}]`;
52
- }
53
- else {
54
- return `[BasedStream]`;
55
- }
56
- }
57
- }
58
- exports.BasedDataStream = BasedDataStream;
59
- const isStreamFunctionOpts = (opts) => {
60
- return opts.contents instanceof stream_1.Duplex || opts.contents instanceof stream_1.Readable;
61
- };
62
- exports.isStreamFunctionOpts = isStreamFunctionOpts;
63
- //# sourceMappingURL=stream.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stream.js","sourceRoot":"","sources":["../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AAA;YAC/B,IAAI,CAAC,YAAY,GAAG,IAAI,CAAA;SACzB;QACD,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAA;QACxB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACjB,CAAC;IAED,CAAC,mBAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QACnB,IAAI,IAAI,CAAC,IAAI,EAAE;YACb,MAAM,EAAE,GACN,IAAI,CAAC,aAAa,GAAG,IAAI;gBACvB,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,GAAG,IAAI;gBAC9C,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,IAAI,CAAC,GAAG,IAAI,CAAA;YAEzD,OAAO,gBAAgB,CAAC,CAAC,CACvB,CAAC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC;gBAChC,GAAG,CACJ,KAAK,EAAE,GAAG,CAAA;SACZ;aAAM;YACL,OAAO,eAAe,CAAA;SACvB;IACH,CAAC;CACF;AAxDD,0CAwDC;AA8BM,MAAM,oBAAoB,GAAG,CAClC,IAAmD,EACrB,EAAE;IAChC,OAAO,IAAI,CAAC,QAAQ,YAAY,eAAM,IAAI,IAAI,CAAC,QAAQ,YAAY,iBAAQ,CAAA;AAC7E,CAAC,CAAA;AAJY,QAAA,oBAAoB,wBAIhC"}
package/dist/uws.d.ts DELETED
@@ -1,469 +0,0 @@
1
- /*
2
- * Authored by Alex Hultman, 2018-2021.
3
- * Intellectual property of third-party.
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- * Unless required by applicable law or agreed to in writing, software
9
- * distributed under the License is distributed on an "AS IS" BASIS,
10
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- * See the License for the specific language governing permissions and
12
- * limitations under the License.
13
- */
14
-
15
- /** Native type representing a raw uSockets struct us_listen_socket_t.
16
- * Careful with this one, it is entirely unchecked and native so invalid usage will blow up.
17
- */
18
- export interface us_listen_socket {}
19
-
20
- /** Native type representing a raw uSockets struct us_socket_t.
21
- * Careful with this one, it is entirely unchecked and native so invalid usage will blow up.
22
- */
23
- export interface us_socket {}
24
-
25
- /** Native type representing a raw uSockets struct us_socket_context_t.
26
- * Used while upgrading a WebSocket manually. */
27
- export interface us_socket_context_t {}
28
-
29
- /** Recognized string types, things C++ can read and understand as strings.
30
- * "String" does not have to mean "text", it can also be "binary".
31
- *
32
- * Ironically, JavaScript strings are the least performant of all options, to pass or receive to/from C++.
33
- * This because we expect UTF-8, which is packed in 8-byte chars. JavaScript strings are UTF-16 internally meaning extra copies and reinterpretation are required.
34
- *
35
- * That's why all events pass data by ArrayBuffer and not JavaScript strings, as they allow zero-copy data passing.
36
- *
37
- * You can always do Buffer.from(arrayBuffer).toString(), but keeping things binary and as ArrayBuffer is preferred.
38
- */
39
- export type RecognizedString =
40
- | string
41
- | ArrayBuffer
42
- | Uint8Array
43
- | Int8Array
44
- | Uint16Array
45
- | Int16Array
46
- | Uint32Array
47
- | Int32Array
48
- | Float32Array
49
- | Float64Array
50
-
51
- /** A WebSocket connection that is valid from open to close event.
52
- * Read more about this in the user manual.
53
- */
54
- export interface WebSocket<UserData> {
55
- /** Sends a message. Returns 1 for success, 2 for dropped due to backpressure limit, and 0 for built up backpressure that will drain over time. You can check backpressure before or after sending by calling getBufferedAmount().
56
- *
57
- * Make sure you properly understand the concept of backpressure. Check the backpressure example file.
58
- */
59
- send(
60
- message: RecognizedString,
61
- isBinary?: boolean,
62
- compress?: boolean
63
- ): number
64
-
65
- /** Returns the bytes buffered in backpressure. This is similar to the bufferedAmount property in the browser counterpart.
66
- * Check backpressure example.
67
- */
68
- getBufferedAmount(): number
69
-
70
- /** Gracefully closes this WebSocket. Immediately calls the close handler.
71
- * A WebSocket close message is sent with code and shortMessage.
72
- */
73
- end(code?: number, shortMessage?: RecognizedString): void
74
-
75
- /** Forcefully closes this WebSocket. Immediately calls the close handler.
76
- * No WebSocket close message is sent.
77
- */
78
- close(): void
79
-
80
- /** Sends a ping control message. Returns sendStatus similar to WebSocket.send (regarding backpressure). This helper function correlates to WebSocket::send(message, uWS::OpCode::PING, ...) in C++. */
81
- ping(message?: RecognizedString): number
82
-
83
- /** Subscribe to a topic. */
84
- subscribe(topic: RecognizedString): boolean
85
-
86
- /** Unsubscribe from a topic. Returns true on success, if the WebSocket was subscribed. */
87
- unsubscribe(topic: RecognizedString): boolean
88
-
89
- /** Returns whether this websocket is subscribed to topic. */
90
- isSubscribed(topic: RecognizedString): boolean
91
-
92
- /** Returns a list of topics this websocket is subscribed to. */
93
- getTopics(): string[]
94
-
95
- /** Publish a message under topic. Backpressure is managed according to maxBackpressure, closeOnBackpressureLimit settings.
96
- * Order is guaranteed since v20.
97
- */
98
- publish(
99
- topic: RecognizedString,
100
- message: RecognizedString,
101
- isBinary?: boolean,
102
- compress?: boolean
103
- ): boolean
104
-
105
- /** See HttpResponse.cork. Takes a function in which the socket is corked (packing many sends into one single syscall/SSL block) */
106
- cork(cb: () => void): WebSocket<UserData>
107
-
108
- /** Returns the remote IP address. Note that the returned IP is binary, not text.
109
- *
110
- * IPv4 is 4 byte long and can be converted to text by printing every byte as a digit between 0 and 255.
111
- * IPv6 is 16 byte long and can be converted to text in similar ways, but you typically print digits in HEX.
112
- *
113
- * See getRemoteAddressAsText() for a text version.
114
- */
115
- getRemoteAddress(): ArrayBuffer
116
-
117
- /** Returns the remote IP address as text. See RecognizedString. */
118
- getRemoteAddressAsText(): ArrayBuffer
119
-
120
- /** Returns the UserData object. */
121
- getUserData(): UserData
122
- }
123
-
124
- /** An HttpResponse is valid until either onAborted callback or any of the .end/.tryEnd calls succeed. You may attach user data to this object. */
125
- export interface HttpResponse {
126
- /** Writes the HTTP status message such as "200 OK".
127
- * This has to be called first in any response, otherwise
128
- * it will be called automatically with "200 OK".
129
- *
130
- * If you want to send custom headers in a WebSocket
131
- * upgrade response, you have to call writeStatus with
132
- * "101 Switching Protocols" before you call writeHeader,
133
- * otherwise your first call to writeHeader will call
134
- * writeStatus with "200 OK" and the upgrade will fail.
135
- *
136
- * As you can imagine, we format outgoing responses in a linear
137
- * buffer, not in a hash table. You can read about this in
138
- * the user manual under "corking".
139
- */
140
-
141
- /** Pause http body streaming (throttle) */
142
- pause(): void
143
-
144
- /** Resume http body streaming (unthrottle) */
145
- resume(): void
146
-
147
- writeStatus(status: RecognizedString): HttpResponse
148
- /** Writes key and value to HTTP response.
149
- * See writeStatus and corking.
150
- */
151
- writeHeader(key: RecognizedString, value: RecognizedString): HttpResponse
152
- /** Enters or continues chunked encoding mode. Writes part of the response. End with zero length write. Returns true if no backpressure was added. */
153
- write(chunk: RecognizedString): boolean
154
- /** Ends this response by copying the contents of body. */
155
- end(body?: RecognizedString, closeConnection?: boolean): HttpResponse
156
- /** Ends this response, or tries to, by streaming appropriately sized chunks of body. Use in conjunction with onWritable. Returns tuple [ok, hasResponded]. */
157
- tryEnd(
158
- fullBodyOrChunk: RecognizedString,
159
- totalSize: number
160
- ): [boolean, boolean]
161
-
162
- /** Immediately force closes the connection. Any onAborted callback will run. */
163
- close(): HttpResponse
164
-
165
- /** Returns the global byte write offset for this response. Use with onWritable. */
166
- getWriteOffset(): number
167
-
168
- /** Registers a handler for writable events. Continue failed write attempts in here.
169
- * You MUST return true for success, false for failure.
170
- * Writing nothing is always success, so by default you must return true.
171
- */
172
- onWritable(handler: (offset: number) => boolean): HttpResponse
173
-
174
- /** Every HttpResponse MUST have an attached abort handler IF you do not respond
175
- * to it immediately inside of the callback. Returning from an Http request handler
176
- * without attaching (by calling onAborted) an abort handler is ill-use and will terminate.
177
- * When this event emits, the response has been aborted and may not be used. */
178
- onAborted(handler: () => void): HttpResponse
179
-
180
- /** Handler for reading data from POST and such requests. You MUST copy the data of chunk if isLast is not true. We Neuter ArrayBuffers on return, making it zero length. */
181
- onData(handler: (chunk: ArrayBuffer, isLast: boolean) => void): HttpResponse
182
-
183
- /** Returns the remote IP address in binary format (4 or 16 bytes). */
184
- getRemoteAddress(): ArrayBuffer
185
-
186
- /** Returns the remote IP address as text. */
187
- getRemoteAddressAsText(): ArrayBuffer
188
-
189
- /** Returns the remote IP address in binary format (4 or 16 bytes), as reported by the PROXY Protocol v2 compatible proxy. */
190
- getProxiedRemoteAddress(): ArrayBuffer
191
-
192
- /** Returns the remote IP address as text, as reported by the PROXY Protocol v2 compatible proxy. */
193
- getProxiedRemoteAddressAsText(): ArrayBuffer
194
-
195
- /** Corking a response is a performance improvement in both CPU and network, as you ready the IO system for writing multiple chunks at once.
196
- * By default, you're corked in the immediately executing top portion of the route handler. In all other cases, such as when returning from
197
- * await, or when being called back from an async database request or anything that isn't directly executing in the route handler, you'll want
198
- * to cork before calling writeStatus, writeHeader or just write. Corking takes a callback in which you execute the writeHeader, writeStatus and
199
- * such calls, in one atomic IO operation. This is important, not only for TCP but definitely for TLS where each write would otherwise result
200
- * in one TLS block being sent off, each with one send syscall.
201
- *
202
- * Example usage:
203
- *
204
- * res.cork(() => {
205
- * res.writeStatus("200 OK").writeHeader("Some", "Value").write("Hello world!");
206
- * });
207
- */
208
- cork(cb: () => void): HttpResponse
209
-
210
- /** Upgrades a HttpResponse to a WebSocket. See UpgradeAsync, UpgradeSync example files. */
211
- upgrade<UserData>(
212
- userData: UserData,
213
- secWebSocketKey: RecognizedString,
214
- secWebSocketProtocol: RecognizedString,
215
- secWebSocketExtensions: RecognizedString,
216
- context: us_socket_context_t
217
- ): void
218
-
219
- /** Arbitrary user data may be attached to this object */
220
- [key: string]: any
221
- }
222
-
223
- /** An HttpRequest is stack allocated and only accessible during the callback invocation. */
224
- export interface HttpRequest {
225
- /** Returns the lowercased header value or empty string. */
226
- getHeader(lowerCaseKey: RecognizedString): string
227
- /** Returns the parsed parameter at index. Corresponds to route. */
228
- getParameter(index: number): string
229
- /** Returns the URL including initial /slash */
230
- getUrl(): string
231
- /** Returns the lowercased HTTP method, useful for "any" routes. */
232
- getMethod(): string
233
- /** Returns the HTTP method as-is. */
234
- getCaseSensitiveMethod(): string
235
- /** Returns the raw querystring (the part of URL after ? sign) or empty string. */
236
- getQuery(): string
237
- /** Returns a decoded query parameter value or empty string. */
238
- getQuery(key: string): string
239
- /** Loops over all headers. */
240
- forEach(cb: (key: string, value: string) => void): void
241
- /** Setting yield to true is to say that this route handler did not handle the route, causing the router to continue looking for a matching route handler, or fail. */
242
- setYield(y: boolean): HttpRequest
243
- }
244
-
245
- /** A structure holding settings and handlers for a WebSocket URL route handler. */
246
- export interface WebSocketBehavior<UserData> {
247
- /** Maximum length of received message. If a client tries to send you a message larger than this, the connection is immediately closed. Defaults to 16 * 1024. */
248
- maxPayloadLength?: number
249
- /** Whether or not we should automatically close the socket when a message is dropped due to backpressure. Defaults to false. */
250
- closeOnBackpressureLimit?: number
251
- /** Maximum number of minutes a WebSocket may be connected before being closed by the server. 0 disables the feature. */
252
- maxLifetime?: number
253
- /** Maximum amount of seconds that may pass without sending or getting a message. Connection is closed if this timeout passes. Resolution (granularity) for timeouts are typically 4 seconds, rounded to closest.
254
- * Disable by using 0. Defaults to 120.
255
- */
256
- idleTimeout?: number
257
- /** What permessage-deflate compression to use. uWS.DISABLED, uWS.SHARED_COMPRESSOR or any of the uWS.DEDICATED_COMPRESSOR_xxxKB. Defaults to uWS.DISABLED. */
258
- compression?: CompressOptions
259
- /** Maximum length of allowed backpressure per socket when publishing or sending messages. Slow receivers with too high backpressure will be skipped until they catch up or timeout. Defaults to 64 * 1024. */
260
- maxBackpressure?: number
261
- /** Whether or not we should automatically send pings to uphold a stable connection given whatever idleTimeout. */
262
- sendPingsAutomatically?: boolean
263
- /** Upgrade handler used to intercept HTTP upgrade requests and potentially upgrade to WebSocket.
264
- * See UpgradeAsync and UpgradeSync example files.
265
- */
266
- upgrade?: (
267
- res: HttpResponse,
268
- req: HttpRequest,
269
- context: us_socket_context_t
270
- ) => void
271
- /** Handler for new WebSocket connection. WebSocket is valid from open to close, no errors. */
272
- open?: (ws: WebSocket<UserData>) => void
273
- /** Handler for a WebSocket message. Messages are given as ArrayBuffer no matter if they are binary or not. Given ArrayBuffer is valid during the lifetime of this callback (until first await or return) and will be neutered. */
274
- message?: (
275
- ws: WebSocket<UserData>,
276
- message: ArrayBuffer,
277
- isBinary: boolean
278
- ) => void
279
- /** Handler for when WebSocket backpressure drains. Check ws.getBufferedAmount(). Use this to guide / drive your backpressure throttling. */
280
- drain?: (ws: WebSocket<UserData>) => void
281
- /** Handler for close event, no matter if error, timeout or graceful close. You may not use WebSocket after this event. Do not send on this WebSocket from within here, it is closed. */
282
- close?: (ws: WebSocket<UserData>, code: number, message: ArrayBuffer) => void
283
- /** Handler for received ping control message. You do not need to handle this, pong messages are automatically sent as per the standard. */
284
- ping?: (ws: WebSocket<UserData>, message: ArrayBuffer) => void
285
- /** Handler for received pong control message. */
286
- pong?: (ws: WebSocket<UserData>, message: ArrayBuffer) => void
287
- /** Handler for subscription changes. */
288
- subscription?: (
289
- ws: WebSocket<UserData>,
290
- topic: ArrayBuffer,
291
- newCount: number,
292
- oldCount: number
293
- ) => void
294
- }
295
-
296
- /** Options used when constructing an app. Especially for SSLApp.
297
- * These are options passed directly to uSockets, C layer.
298
- */
299
- export interface AppOptions {
300
- key_file_name?: RecognizedString
301
- cert_file_name?: RecognizedString
302
- ca_file_name?: RecognizedString
303
- passphrase?: RecognizedString
304
- dh_params_file_name?: RecognizedString
305
- ssl_ciphers?: RecognizedString
306
- /** This translates to SSL_MODE_RELEASE_BUFFERS */
307
- ssl_prefer_low_memory_usage?: boolean
308
- }
309
-
310
- export enum ListenOptions {
311
- LIBUS_LISTEN_DEFAULT = 0,
312
- LIBUS_LISTEN_EXCLUSIVE_PORT = 1,
313
- }
314
-
315
- /** TemplatedApp is either an SSL or non-SSL app. See App for more info, read user manual. */
316
- export interface TemplatedApp {
317
- /** Listens to hostname & port. Callback hands either false or a listen socket. */
318
- listen(
319
- host: RecognizedString,
320
- port: number,
321
- cb: (listenSocket: us_listen_socket) => void
322
- ): TemplatedApp
323
- /** Listens to port. Callback hands either false or a listen socket. */
324
- listen(port: number, cb: (listenSocket: any) => void): TemplatedApp
325
- /** Listens to port and sets Listen Options. Callback hands either false or a listen socket. */
326
- listen(
327
- port: number,
328
- options: ListenOptions,
329
- cb: (listenSocket: us_listen_socket | false) => void
330
- ): TemplatedApp
331
- /** Registers an HTTP GET handler matching specified URL pattern. */
332
- get(
333
- pattern: RecognizedString,
334
- handler: (res: HttpResponse, req: HttpRequest) => void
335
- ): TemplatedApp
336
- /** Registers an HTTP POST handler matching specified URL pattern. */
337
- post(
338
- pattern: RecognizedString,
339
- handler: (res: HttpResponse, req: HttpRequest) => void
340
- ): TemplatedApp
341
- /** Registers an HTTP OPTIONS handler matching specified URL pattern. */
342
- options(
343
- pattern: RecognizedString,
344
- handler: (res: HttpResponse, req: HttpRequest) => void
345
- ): TemplatedApp
346
- /** Registers an HTTP DELETE handler matching specified URL pattern. */
347
- del(
348
- pattern: RecognizedString,
349
- handler: (res: HttpResponse, req: HttpRequest) => void
350
- ): TemplatedApp
351
- /** Registers an HTTP PATCH handler matching specified URL pattern. */
352
- patch(
353
- pattern: RecognizedString,
354
- handler: (res: HttpResponse, req: HttpRequest) => void
355
- ): TemplatedApp
356
- /** Registers an HTTP PUT handler matching specified URL pattern. */
357
- put(
358
- pattern: RecognizedString,
359
- handler: (res: HttpResponse, req: HttpRequest) => void
360
- ): TemplatedApp
361
- /** Registers an HTTP HEAD handler matching specified URL pattern. */
362
- head(
363
- pattern: RecognizedString,
364
- handler: (res: HttpResponse, req: HttpRequest) => void
365
- ): TemplatedApp
366
- /** Registers an HTTP CONNECT handler matching specified URL pattern. */
367
- connect(
368
- pattern: RecognizedString,
369
- handler: (res: HttpResponse, req: HttpRequest) => void
370
- ): TemplatedApp
371
- /** Registers an HTTP TRACE handler matching specified URL pattern. */
372
- trace(
373
- pattern: RecognizedString,
374
- handler: (res: HttpResponse, req: HttpRequest) => void
375
- ): TemplatedApp
376
- /** Registers an HTTP handler matching specified URL pattern on any HTTP method. */
377
- any(
378
- pattern: RecognizedString,
379
- handler: (res: HttpResponse, req: HttpRequest) => void
380
- ): TemplatedApp
381
- /** Registers a handler matching specified URL pattern where WebSocket upgrade requests are caught. */
382
- ws<UserData>(
383
- pattern: RecognizedString,
384
- behavior: WebSocketBehavior<UserData>
385
- ): TemplatedApp
386
- /** Publishes a message under topic, for all WebSockets under this app. See WebSocket.publish. */
387
- publish(
388
- topic: RecognizedString,
389
- message: RecognizedString,
390
- isBinary?: boolean,
391
- compress?: boolean
392
- ): boolean
393
- /** Returns number of subscribers for this topic. */
394
- numSubscribers(topic: RecognizedString): number
395
- /** Adds a server name. */
396
- addServerName(hostname: string, options: AppOptions): TemplatedApp
397
- /** Removes a server name. */
398
- removeServerName(hostname: string): TemplatedApp
399
- /** Registers a synchronous callback on missing server names. See /examples/ServerName.js. */
400
- missingServerName(cb: (hostname: string) => void): TemplatedApp
401
- }
402
-
403
- /** Constructs a non-SSL app. An app is your starting point where you attach behavior to URL routes.
404
- * This is also where you listen and run your app, set any SSL options (in case of SSLApp) and the like.
405
- */
406
- export function App(options?: AppOptions): TemplatedApp
407
-
408
- /** Constructs an SSL app. See App. */
409
- export function SSLApp(options: AppOptions): TemplatedApp
410
-
411
- /** Closes a uSockets listen socket. */
412
- export function us_listen_socket_close(listenSocket: us_listen_socket): void
413
-
414
- /** Gets local port of socket (or listenSocket) or -1. */
415
- export function us_socket_local_port(socket: us_socket): number
416
-
417
- export interface MultipartField {
418
- data: ArrayBuffer
419
- name: string
420
- type?: string
421
- filename?: string
422
- }
423
-
424
- /** Takes a POSTed body and contentType, and returns an array of parts if the request is a multipart request */
425
- export function getParts(
426
- body: RecognizedString,
427
- contentType: RecognizedString
428
- ): MultipartField[] | undefined
429
-
430
- /** WebSocket compression options. Combine any compressor with any decompressor using bitwise OR. */
431
- export type CompressOptions = number
432
- /** No compression (always a good idea if you operate using an efficient binary protocol) */
433
- export var DISABLED: CompressOptions
434
- /** Zero memory overhead compression. */
435
- export var SHARED_COMPRESSOR: CompressOptions
436
- /** Zero memory overhead decompression. */
437
- export var SHARED_DECOMPRESSOR: CompressOptions
438
- /** Sliding dedicated compress window, requires 3KB of memory per socket */
439
- export var DEDICATED_COMPRESSOR_3KB: CompressOptions
440
- /** Sliding dedicated compress window, requires 4KB of memory per socket */
441
- export var DEDICATED_COMPRESSOR_4KB: CompressOptions
442
- /** Sliding dedicated compress window, requires 8KB of memory per socket */
443
- export var DEDICATED_COMPRESSOR_8KB: CompressOptions
444
- /** Sliding dedicated compress window, requires 16KB of memory per socket */
445
- export var DEDICATED_COMPRESSOR_16KB: CompressOptions
446
- /** Sliding dedicated compress window, requires 32KB of memory per socket */
447
- export var DEDICATED_COMPRESSOR_32KB: CompressOptions
448
- /** Sliding dedicated compress window, requires 64KB of memory per socket */
449
- export var DEDICATED_COMPRESSOR_64KB: CompressOptions
450
- /** Sliding dedicated compress window, requires 128KB of memory per socket */
451
- export var DEDICATED_COMPRESSOR_128KB: CompressOptions
452
- /** Sliding dedicated compress window, requires 256KB of memory per socket */
453
- export var DEDICATED_COMPRESSOR_256KB: CompressOptions
454
- /** Sliding dedicated decompress window, requires 32KB of memory per socket (plus about 23KB) */
455
- export var DEDICATED_DECOMPRESSOR_32KB: CompressOptions
456
- /** Sliding dedicated decompress window, requires 16KB of memory per socket (plus about 23KB) */
457
- export var DEDICATED_DECOMPRESSOR_16KB: CompressOptions
458
- /** Sliding dedicated decompress window, requires 8KB of memory per socket (plus about 23KB) */
459
- export var DEDICATED_DECOMPRESSOR_8KB: CompressOptions
460
- /** Sliding dedicated decompress window, requires 4KB of memory per socket (plus about 23KB) */
461
- export var DEDICATED_DECOMPRESSOR_4KB: CompressOptions
462
- /** Sliding dedicated decompress window, requires 2KB of memory per socket (plus about 23KB) */
463
- export var DEDICATED_DECOMPRESSOR_2KB: CompressOptions
464
- /** Sliding dedicated decompress window, requires 1KB of memory per socket (plus about 23KB) */
465
- export var DEDICATED_DECOMPRESSOR_1KB: CompressOptions
466
- /** Sliding dedicated decompress window, requires 512B of memory per socket (plus about 23KB) */
467
- export var DEDICATED_DECOMPRESSOR_512B: CompressOptions
468
- /** Sliding dedicated decompress window, requires 32KB of memory per socket (plus about 23KB) */
469
- export var DEDICATED_DECOMPRESSOR: CompressOptions