@inditextech/weave-store-azure-web-pubsub 5.2.0 → 5.2.2
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/client.d.ts +773 -65
- package/dist/client.js +892 -1124
- package/dist/client.stats.html +388 -33
- package/dist/server.d.ts +2177 -503
- package/dist/server.js +357 -460
- package/dist/server.stats.html +388 -33
- package/package.json +7 -7
package/dist/server.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { WebPubSubServiceClient } from "@azure/web-pubsub";
|
|
2
3
|
import { TokenCredential } from "@azure/identity";
|
|
3
4
|
import * as Y from "yjs";
|
|
@@ -5,36 +6,701 @@ import { Doc } from "yjs";
|
|
|
5
6
|
import { WebSocket } from "ws";
|
|
6
7
|
import { WeaveStore } from "@inditextech/weave-sdk";
|
|
7
8
|
import koa from "koa";
|
|
8
|
-
import Emittery from "emittery";
|
|
9
9
|
import ReconnectingWebSocket from "reconnecting-websocket";
|
|
10
|
-
import * as awarenessProtocol$1 from "y-protocols/awareness";
|
|
11
|
-
import * as awarenessProtocol from "y-protocols/awareness";
|
|
12
10
|
import { DeepPartial, WeaveStoreOptions } from "@inditextech/weave-types";
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import
|
|
11
|
+
import { SendOptions } from "send";
|
|
12
|
+
import { EventEmitter } from "events";
|
|
13
|
+
import * as http from "http";
|
|
14
|
+
import { ParsedQs } from "qs";
|
|
15
|
+
import { Options, Ranges, Result } from "range-parser";
|
|
16
16
|
import { RequestHandler } from "express";
|
|
17
|
+
//#region ../../node_modules/emittery/index.d.ts
|
|
18
|
+
/**
|
|
19
|
+
Emittery accepts strings, symbols, and numbers as event names.
|
|
20
|
+
|
|
21
|
+
Symbol event names are preferred given that they can be used to avoid name collisions when your classes are extended, especially for internal events.
|
|
22
|
+
*/
|
|
23
|
+
type EventName = PropertyKey;
|
|
24
|
+
// Helper type for turning the passed `EventData` type map into a list of string keys that don't require data alongside the event name when emitting. Uses the same trick that `Omit` does internally to filter keys by building a map of keys to keys we want to keep, and then accessing all the keys to return just the list of keys we want to keep.
|
|
25
|
+
type DatalessEventNames<EventData> = { [Key in keyof EventData]: EventData[Key] extends undefined ? Key : never; }[keyof EventData];
|
|
26
|
+
declare const listenerAdded: unique symbol;
|
|
27
|
+
declare const listenerRemoved: unique symbol;
|
|
28
|
+
type OmnipresentEventData = {
|
|
29
|
+
[listenerAdded]: ListenerChangedData;
|
|
30
|
+
[listenerRemoved]: ListenerChangedData;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
Emittery can collect and log debug information.
|
|
34
|
+
|
|
35
|
+
To enable this feature set the `DEBUG` environment variable to `emittery` or `*`. Additionally, you can set the static `isDebugEnabled` variable to true on the Emittery class, or `myEmitter.debug.enabled` on an instance of it for debugging a single instance.
|
|
36
|
+
|
|
37
|
+
See API for more information on how debugging works.
|
|
38
|
+
*/
|
|
39
|
+
type DebugLogger<EventData, Name extends keyof EventData> = (type: string, debugName: string, eventName?: Name, eventData?: EventData[Name]) => void;
|
|
40
|
+
/**
|
|
41
|
+
Configure debug options of an instance.
|
|
42
|
+
*/
|
|
43
|
+
type DebugOptions<EventData> = {
|
|
44
|
+
/**
|
|
45
|
+
Define a name for the instance of Emittery to use when outputting debug data.
|
|
46
|
+
|
|
47
|
+
@default undefined
|
|
48
|
+
|
|
49
|
+
@example
|
|
50
|
+
```
|
|
51
|
+
import Emittery from 'emittery';
|
|
52
|
+
|
|
53
|
+
Emittery.isDebugEnabled = true;
|
|
54
|
+
|
|
55
|
+
const emitter = new Emittery({debug: {name: 'myEmitter'}});
|
|
56
|
+
|
|
57
|
+
emitter.on('test', data => {
|
|
58
|
+
// …
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
emitter.emit('test');
|
|
62
|
+
//=> [16:43:20.417][emittery:subscribe][myEmitter] Event Name: test
|
|
63
|
+
// data: undefined
|
|
64
|
+
```
|
|
65
|
+
*/
|
|
66
|
+
readonly name: string;
|
|
67
|
+
/**
|
|
68
|
+
Toggle debug logging just for this instance.
|
|
69
|
+
|
|
70
|
+
@default false
|
|
71
|
+
|
|
72
|
+
@example
|
|
73
|
+
```
|
|
74
|
+
import Emittery from 'emittery';
|
|
75
|
+
|
|
76
|
+
const emitter1 = new Emittery({debug: {name: 'emitter1', enabled: true}});
|
|
77
|
+
const emitter2 = new Emittery({debug: {name: 'emitter2'}});
|
|
78
|
+
|
|
79
|
+
emitter1.on('test', data => {
|
|
80
|
+
// …
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
emitter2.on('test', data => {
|
|
84
|
+
// …
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
emitter1.emit('test');
|
|
88
|
+
//=> [16:43:20.417][emittery:subscribe][emitter1] Event Name: test
|
|
89
|
+
// data: undefined
|
|
90
|
+
|
|
91
|
+
emitter2.emit('test');
|
|
92
|
+
```
|
|
93
|
+
*/
|
|
94
|
+
readonly enabled?: boolean;
|
|
95
|
+
/**
|
|
96
|
+
Function that handles debug data.
|
|
97
|
+
|
|
98
|
+
@default
|
|
99
|
+
```
|
|
100
|
+
(type, debugName, eventName, eventData) => {
|
|
101
|
+
eventData = JSON.stringify(eventData);
|
|
102
|
+
|
|
103
|
+
if (typeof eventName === 'symbol' || typeof eventName === 'number') {
|
|
104
|
+
eventName = eventName.toString();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const currentTime = new Date();
|
|
108
|
+
const logTime = `${currentTime.getHours()}:${currentTime.getMinutes()}:${currentTime.getSeconds()}.${currentTime.getMilliseconds()}`;
|
|
109
|
+
console.log(`[${logTime}][emittery:${type}][${debugName}] Event Name: ${eventName}\n\tdata: ${eventData}`);
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
@example
|
|
114
|
+
```
|
|
115
|
+
import Emittery from 'emittery';
|
|
116
|
+
|
|
117
|
+
const myLogger = (type, debugName, eventName, eventData) => {
|
|
118
|
+
console.log(`[${type}]: ${eventName}`);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const emitter = new Emittery({
|
|
122
|
+
debug: {
|
|
123
|
+
name: 'myEmitter',
|
|
124
|
+
enabled: true,
|
|
125
|
+
logger: myLogger
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
emitter.on('test', data => {
|
|
130
|
+
// …
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
emitter.emit('test');
|
|
134
|
+
//=> [subscribe]: test
|
|
135
|
+
```
|
|
136
|
+
*/
|
|
137
|
+
readonly logger?: DebugLogger<EventData, keyof EventData>;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
Configuration options for Emittery.
|
|
141
|
+
*/
|
|
142
|
+
type Options$1<EventData> = {
|
|
143
|
+
readonly debug?: DebugOptions<EventData>;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
A promise returned from `emittery.once` with an extra `off` method to cancel your subscription.
|
|
147
|
+
*/
|
|
148
|
+
type EmitteryOncePromise<T> = {
|
|
149
|
+
off(): void;
|
|
150
|
+
} & Promise<T>;
|
|
151
|
+
/**
|
|
152
|
+
Removes an event subscription.
|
|
153
|
+
*/
|
|
154
|
+
type UnsubscribeFunction = () => void;
|
|
155
|
+
/**
|
|
156
|
+
The data provided as `eventData` when listening for `Emittery.listenerAdded` or `Emittery.listenerRemoved`.
|
|
157
|
+
*/
|
|
158
|
+
type ListenerChangedData = {
|
|
159
|
+
/**
|
|
160
|
+
The listener that was added or removed.
|
|
161
|
+
*/
|
|
162
|
+
listener: (eventData?: unknown) => (void | Promise<void>);
|
|
163
|
+
/**
|
|
164
|
+
The name of the event that was added or removed if `.on()` or `.off()` was used, or `undefined` if `.onAny()` or `.offAny()` was used.
|
|
165
|
+
*/
|
|
166
|
+
eventName?: EventName;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
Emittery is a strictly typed, fully async EventEmitter implementation. Event listeners can be registered with `on` or `once`, and events can be emitted with `emit`.
|
|
170
|
+
|
|
171
|
+
`Emittery` has a generic `EventData` type that can be provided by users to strongly type the list of events and the data passed to the listeners for those events. Pass an interface of {[eventName]: undefined | <eventArg>}, with all the event names as the keys and the values as the type of the argument passed to listeners if there is one, or `undefined` if there isn't.
|
|
172
|
+
|
|
173
|
+
@example
|
|
174
|
+
```
|
|
175
|
+
import Emittery from 'emittery';
|
|
176
|
+
|
|
177
|
+
const emitter = new Emittery<
|
|
178
|
+
// Pass `{[eventName: <string | symbol | number>]: undefined | <eventArg>}` as the first type argument for events that pass data to their listeners.
|
|
179
|
+
// A value of `undefined` in this map means the event listeners should expect no data, and a type other than `undefined` means the listeners will receive one argument of that type.
|
|
180
|
+
{
|
|
181
|
+
open: string,
|
|
182
|
+
close: undefined
|
|
183
|
+
}
|
|
184
|
+
>();
|
|
185
|
+
|
|
186
|
+
// Typechecks just fine because the data type for the `open` event is `string`.
|
|
187
|
+
emitter.emit('open', 'foo\n');
|
|
188
|
+
|
|
189
|
+
// Typechecks just fine because `close` is present but points to undefined in the event data type map.
|
|
190
|
+
emitter.emit('close');
|
|
191
|
+
|
|
192
|
+
// TS compilation error because `1` isn't assignable to `string`.
|
|
193
|
+
emitter.emit('open', 1);
|
|
194
|
+
|
|
195
|
+
// TS compilation error because `other` isn't defined in the event data type map.
|
|
196
|
+
emitter.emit('other');
|
|
197
|
+
```
|
|
198
|
+
*/
|
|
199
|
+
declare class Emittery<EventData = Record<EventName, any> // TODO: Use `unknown` instead of `any`.
|
|
200
|
+
, AllEventData = EventData & OmnipresentEventData, DatalessEvents = DatalessEventNames<EventData>> {
|
|
201
|
+
/**
|
|
202
|
+
Toggle debug mode for all instances.
|
|
203
|
+
|
|
204
|
+
Default: `true` if the `DEBUG` environment variable is set to `emittery` or `*`, otherwise `false`.
|
|
205
|
+
|
|
206
|
+
@example
|
|
207
|
+
```
|
|
208
|
+
import Emittery from 'emittery';
|
|
209
|
+
|
|
210
|
+
Emittery.isDebugEnabled = true;
|
|
211
|
+
|
|
212
|
+
const emitter1 = new Emittery({debug: {name: 'myEmitter1'}});
|
|
213
|
+
const emitter2 = new Emittery({debug: {name: 'myEmitter2'}});
|
|
214
|
+
|
|
215
|
+
emitter1.on('test', data => {
|
|
216
|
+
// …
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
emitter2.on('otherTest', data => {
|
|
220
|
+
// …
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
emitter1.emit('test');
|
|
224
|
+
//=> [16:43:20.417][emittery:subscribe][myEmitter1] Event Name: test
|
|
225
|
+
// data: undefined
|
|
226
|
+
|
|
227
|
+
emitter2.emit('otherTest');
|
|
228
|
+
//=> [16:43:20.417][emittery:subscribe][myEmitter2] Event Name: otherTest
|
|
229
|
+
// data: undefined
|
|
230
|
+
```
|
|
231
|
+
*/
|
|
232
|
+
static isDebugEnabled: boolean;
|
|
233
|
+
/**
|
|
234
|
+
Fires when an event listener was added.
|
|
235
|
+
|
|
236
|
+
An object with `listener` and `eventName` (if `on` or `off` was used) is provided as event data.
|
|
237
|
+
|
|
238
|
+
@example
|
|
239
|
+
```
|
|
240
|
+
import Emittery from 'emittery';
|
|
241
|
+
|
|
242
|
+
const emitter = new Emittery();
|
|
243
|
+
|
|
244
|
+
emitter.on(Emittery.listenerAdded, ({listener, eventName}) => {
|
|
245
|
+
console.log(listener);
|
|
246
|
+
//=> data => {}
|
|
247
|
+
|
|
248
|
+
console.log(eventName);
|
|
249
|
+
//=> '🦄'
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
emitter.on('🦄', data => {
|
|
253
|
+
// Handle data
|
|
254
|
+
});
|
|
255
|
+
```
|
|
256
|
+
*/
|
|
257
|
+
static readonly listenerAdded: typeof listenerAdded;
|
|
258
|
+
/**
|
|
259
|
+
Fires when an event listener was removed.
|
|
260
|
+
|
|
261
|
+
An object with `listener` and `eventName` (if `on` or `off` was used) is provided as event data.
|
|
262
|
+
|
|
263
|
+
@example
|
|
264
|
+
```
|
|
265
|
+
import Emittery from 'emittery';
|
|
266
|
+
|
|
267
|
+
const emitter = new Emittery();
|
|
268
|
+
|
|
269
|
+
const off = emitter.on('🦄', data => {
|
|
270
|
+
// Handle data
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
emitter.on(Emittery.listenerRemoved, ({listener, eventName}) => {
|
|
274
|
+
console.log(listener);
|
|
275
|
+
//=> data => {}
|
|
276
|
+
|
|
277
|
+
console.log(eventName);
|
|
278
|
+
//=> '🦄'
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
off();
|
|
282
|
+
```
|
|
283
|
+
*/
|
|
284
|
+
static readonly listenerRemoved: typeof listenerRemoved;
|
|
285
|
+
/**
|
|
286
|
+
In TypeScript, it returns a decorator which mixins `Emittery` as property `emitteryPropertyName` and `methodNames`, or all `Emittery` methods if `methodNames` is not defined, into the target class.
|
|
287
|
+
|
|
288
|
+
@example
|
|
289
|
+
```
|
|
290
|
+
import Emittery from 'emittery';
|
|
291
|
+
|
|
292
|
+
@Emittery.mixin('emittery')
|
|
293
|
+
class MyClass {}
|
|
294
|
+
|
|
295
|
+
const instance = new MyClass();
|
|
296
|
+
|
|
297
|
+
instance.emit('event');
|
|
298
|
+
```
|
|
299
|
+
*/
|
|
300
|
+
static mixin(emitteryPropertyName: string | symbol, methodNames?: readonly string[]): <T extends {
|
|
301
|
+
new (...arguments_: readonly any[]): any;
|
|
302
|
+
}>(klass: T) => T; // eslint-disable-line @typescript-eslint/prefer-function-type
|
|
303
|
+
/**
|
|
304
|
+
Debugging options for the current instance.
|
|
305
|
+
*/
|
|
306
|
+
debug: DebugOptions<EventData>;
|
|
307
|
+
/**
|
|
308
|
+
Create a new Emittery instance with the specified options.
|
|
309
|
+
|
|
310
|
+
@returns An instance of Emittery that you can use to listen for and emit events.
|
|
311
|
+
*/
|
|
312
|
+
constructor(options?: Options$1<EventData>);
|
|
313
|
+
/**
|
|
314
|
+
Subscribe to one or more events.
|
|
315
|
+
|
|
316
|
+
Using the same listener multiple times for the same event will result in only one method call per emitted event.
|
|
317
|
+
|
|
318
|
+
@returns An unsubscribe method.
|
|
319
|
+
|
|
320
|
+
@example
|
|
321
|
+
```
|
|
322
|
+
import Emittery from 'emittery';
|
|
323
|
+
|
|
324
|
+
const emitter = new Emittery();
|
|
325
|
+
|
|
326
|
+
emitter.on('🦄', data => {
|
|
327
|
+
console.log(data);
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
emitter.on(['🦄', '🐶'], data => {
|
|
331
|
+
console.log(data);
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
emitter.emit('🦄', '🌈'); // log => '🌈' x2
|
|
335
|
+
emitter.emit('🐶', '🍖'); // log => '🍖'
|
|
336
|
+
```
|
|
337
|
+
*/
|
|
338
|
+
on<Name extends keyof AllEventData>(eventName: Name | readonly Name[], listener: (eventData: AllEventData[Name]) => void | Promise<void>, options?: {
|
|
339
|
+
signal?: AbortSignal;
|
|
340
|
+
}): UnsubscribeFunction;
|
|
341
|
+
/**
|
|
342
|
+
Get an async iterator which buffers data each time an event is emitted.
|
|
343
|
+
|
|
344
|
+
Call `return()` on the iterator to remove the subscription.
|
|
345
|
+
|
|
346
|
+
@example
|
|
347
|
+
```
|
|
348
|
+
import Emittery from 'emittery';
|
|
349
|
+
|
|
350
|
+
const emitter = new Emittery();
|
|
351
|
+
const iterator = emitter.events('🦄');
|
|
352
|
+
|
|
353
|
+
emitter.emit('🦄', '🌈1'); // Buffered
|
|
354
|
+
emitter.emit('🦄', '🌈2'); // Buffered
|
|
355
|
+
|
|
356
|
+
iterator
|
|
357
|
+
.next()
|
|
358
|
+
.then(({value, done}) => {
|
|
359
|
+
// done === false
|
|
360
|
+
// value === '🌈1'
|
|
361
|
+
return iterator.next();
|
|
362
|
+
})
|
|
363
|
+
.then(({value, done}) => {
|
|
364
|
+
// done === false
|
|
365
|
+
// value === '🌈2'
|
|
366
|
+
// Revoke subscription
|
|
367
|
+
return iterator.return();
|
|
368
|
+
})
|
|
369
|
+
.then(({done}) => {
|
|
370
|
+
// done === true
|
|
371
|
+
});
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
In practice you would usually consume the events using the [for await](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of) statement. In that case, to revoke the subscription simply break the loop.
|
|
375
|
+
|
|
376
|
+
@example
|
|
377
|
+
```
|
|
378
|
+
import Emittery from 'emittery';
|
|
379
|
+
|
|
380
|
+
const emitter = new Emittery();
|
|
381
|
+
const iterator = emitter.events('🦄');
|
|
382
|
+
|
|
383
|
+
emitter.emit('🦄', '🌈1'); // Buffered
|
|
384
|
+
emitter.emit('🦄', '🌈2'); // Buffered
|
|
385
|
+
|
|
386
|
+
// In an async context.
|
|
387
|
+
for await (const data of iterator) {
|
|
388
|
+
if (data === '🌈2') {
|
|
389
|
+
break; // Revoke the subscription when we see the value `🌈2`.
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
It accepts multiple event names.
|
|
395
|
+
|
|
396
|
+
@example
|
|
397
|
+
```
|
|
398
|
+
import Emittery from 'emittery';
|
|
399
|
+
|
|
400
|
+
const emitter = new Emittery();
|
|
401
|
+
const iterator = emitter.events(['🦄', '🦊']);
|
|
402
|
+
|
|
403
|
+
emitter.emit('🦄', '🌈1'); // Buffered
|
|
404
|
+
emitter.emit('🦊', '🌈2'); // Buffered
|
|
405
|
+
|
|
406
|
+
iterator
|
|
407
|
+
.next()
|
|
408
|
+
.then(({value, done}) => {
|
|
409
|
+
// done === false
|
|
410
|
+
// value === '🌈1'
|
|
411
|
+
return iterator.next();
|
|
412
|
+
})
|
|
413
|
+
.then(({value, done}) => {
|
|
414
|
+
// done === false
|
|
415
|
+
// value === '🌈2'
|
|
416
|
+
// Revoke subscription
|
|
417
|
+
return iterator.return();
|
|
418
|
+
})
|
|
419
|
+
.then(({done}) => {
|
|
420
|
+
// done === true
|
|
421
|
+
});
|
|
422
|
+
```
|
|
423
|
+
*/
|
|
424
|
+
events<Name extends keyof EventData>(eventName: Name | readonly Name[]): AsyncIterableIterator<EventData[Name]>;
|
|
425
|
+
/**
|
|
426
|
+
Remove one or more event subscriptions.
|
|
427
|
+
|
|
428
|
+
@example
|
|
429
|
+
```
|
|
430
|
+
import Emittery from 'emittery';
|
|
431
|
+
|
|
432
|
+
const emitter = new Emittery();
|
|
433
|
+
|
|
434
|
+
const listener = data => {
|
|
435
|
+
console.log(data);
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
emitter.on(['🦄', '🐶', '🦊'], listener);
|
|
439
|
+
await emitter.emit('🦄', 'a');
|
|
440
|
+
await emitter.emit('🐶', 'b');
|
|
441
|
+
await emitter.emit('🦊', 'c');
|
|
442
|
+
emitter.off('🦄', listener);
|
|
443
|
+
emitter.off(['🐶', '🦊'], listener);
|
|
444
|
+
await emitter.emit('🦄', 'a'); // nothing happens
|
|
445
|
+
await emitter.emit('🐶', 'b'); // nothing happens
|
|
446
|
+
await emitter.emit('🦊', 'c'); // nothing happens
|
|
447
|
+
```
|
|
448
|
+
*/
|
|
449
|
+
off<Name extends keyof AllEventData>(eventName: Name | readonly Name[], listener: (eventData: AllEventData[Name]) => void | Promise<void>): void;
|
|
450
|
+
/**
|
|
451
|
+
Subscribe to one or more events only once. It will be unsubscribed after the first
|
|
452
|
+
event.
|
|
453
|
+
|
|
454
|
+
@returns The promise of event data when `eventName` is emitted. This promise is extended with an `off` method.
|
|
17
455
|
|
|
456
|
+
@example
|
|
457
|
+
```
|
|
458
|
+
import Emittery from 'emittery';
|
|
459
|
+
|
|
460
|
+
const emitter = new Emittery();
|
|
461
|
+
|
|
462
|
+
emitter.once('🦄').then(data => {
|
|
463
|
+
console.log(data);
|
|
464
|
+
//=> '🌈'
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
emitter.once(['🦄', '🐶']).then(data => {
|
|
468
|
+
console.log(data);
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
emitter.emit('🦄', '🌈'); // Logs `🌈` twice
|
|
472
|
+
emitter.emit('🐶', '🍖'); // Nothing happens
|
|
473
|
+
```
|
|
474
|
+
*/
|
|
475
|
+
once<Name extends keyof AllEventData>(eventName: Name | readonly Name[]): EmitteryOncePromise<AllEventData[Name]>;
|
|
476
|
+
/**
|
|
477
|
+
Trigger an event asynchronously, optionally with some data. Listeners are called in the order they were added, but executed concurrently.
|
|
478
|
+
|
|
479
|
+
@returns A promise that resolves when all the event listeners are done. *Done* meaning executed if synchronous or resolved when an async/promise-returning function. You usually wouldn't want to wait for this, but you could for example catch possible errors. If any of the listeners throw/reject, the returned promise will be rejected with the error, but the other listeners will not be affected.
|
|
480
|
+
*/
|
|
481
|
+
emit<Name extends DatalessEvents>(eventName: Name): Promise<void>;
|
|
482
|
+
emit<Name extends keyof EventData>(eventName: Name, eventData: EventData[Name]): Promise<void>;
|
|
483
|
+
/**
|
|
484
|
+
Same as `emit()`, but it waits for each listener to resolve before triggering the next one. This can be useful if your events depend on each other. Although ideally they should not. Prefer `emit()` whenever possible.
|
|
485
|
+
|
|
486
|
+
If any of the listeners throw/reject, the returned promise will be rejected with the error and the remaining listeners will *not* be called.
|
|
487
|
+
|
|
488
|
+
@returns A promise that resolves when all the event listeners are done.
|
|
489
|
+
*/
|
|
490
|
+
emitSerial<Name extends DatalessEvents>(eventName: Name): Promise<void>;
|
|
491
|
+
emitSerial<Name extends keyof EventData>(eventName: Name, eventData: EventData[Name]): Promise<void>;
|
|
492
|
+
/**
|
|
493
|
+
Subscribe to be notified about any event.
|
|
494
|
+
|
|
495
|
+
@returns A method to unsubscribe.
|
|
496
|
+
*/
|
|
497
|
+
onAny(listener: (eventName: keyof EventData, eventData: EventData[keyof EventData]) => void | Promise<void>, options?: {
|
|
498
|
+
signal?: AbortSignal;
|
|
499
|
+
}): UnsubscribeFunction;
|
|
500
|
+
/**
|
|
501
|
+
Get an async iterator which buffers a tuple of an event name and data each time an event is emitted.
|
|
502
|
+
|
|
503
|
+
Call `return()` on the iterator to remove the subscription.
|
|
504
|
+
|
|
505
|
+
In the same way as for `events`, you can subscribe by using the `for await` statement.
|
|
506
|
+
|
|
507
|
+
@example
|
|
508
|
+
```
|
|
509
|
+
import Emittery from 'emittery';
|
|
510
|
+
|
|
511
|
+
const emitter = new Emittery();
|
|
512
|
+
const iterator = emitter.anyEvent();
|
|
513
|
+
|
|
514
|
+
emitter.emit('🦄', '🌈1'); // Buffered
|
|
515
|
+
emitter.emit('🌟', '🌈2'); // Buffered
|
|
516
|
+
|
|
517
|
+
iterator.next()
|
|
518
|
+
.then(({value, done}) => {
|
|
519
|
+
// done is false
|
|
520
|
+
// value is ['🦄', '🌈1']
|
|
521
|
+
return iterator.next();
|
|
522
|
+
})
|
|
523
|
+
.then(({value, done}) => {
|
|
524
|
+
// done is false
|
|
525
|
+
// value is ['🌟', '🌈2']
|
|
526
|
+
// revoke subscription
|
|
527
|
+
return iterator.return();
|
|
528
|
+
})
|
|
529
|
+
.then(({done}) => {
|
|
530
|
+
// done is true
|
|
531
|
+
});
|
|
532
|
+
```
|
|
533
|
+
*/
|
|
534
|
+
anyEvent(): AsyncIterableIterator<[keyof EventData, EventData[keyof EventData]]>;
|
|
535
|
+
/**
|
|
536
|
+
Remove an `onAny` subscription.
|
|
537
|
+
*/
|
|
538
|
+
offAny(listener: (eventName: keyof EventData, eventData: EventData[keyof EventData]) => void | Promise<void>): void;
|
|
539
|
+
/**
|
|
540
|
+
Clear all event listeners on the instance.
|
|
541
|
+
|
|
542
|
+
If `eventName` is given, only the listeners for that event are cleared.
|
|
543
|
+
*/
|
|
544
|
+
clearListeners<Name extends keyof EventData>(eventName?: Name | readonly Name[]): void;
|
|
545
|
+
/**
|
|
546
|
+
The number of listeners for the `eventName` or all events if not specified.
|
|
547
|
+
*/
|
|
548
|
+
listenerCount<Name extends keyof EventData>(eventName?: Name | readonly Name[]): number;
|
|
549
|
+
/**
|
|
550
|
+
Bind the given `methodNames`, or all `Emittery` methods if `methodNames` is not defined, into the `target` object.
|
|
551
|
+
|
|
552
|
+
@example
|
|
553
|
+
```
|
|
554
|
+
import Emittery from 'emittery';
|
|
555
|
+
|
|
556
|
+
const object = {};
|
|
557
|
+
|
|
558
|
+
new Emittery().bindMethods(object);
|
|
559
|
+
|
|
560
|
+
object.emit('event');
|
|
561
|
+
```
|
|
562
|
+
*/
|
|
563
|
+
bindMethods(target: Record<string, unknown>, methodNames?: readonly string[]): void;
|
|
564
|
+
}
|
|
565
|
+
//#endregion
|
|
18
566
|
//#region src/constants.d.ts
|
|
19
567
|
declare const WEAVE_STORE_AZURE_WEB_PUBSUB = "store-azure-web-pubsub";
|
|
20
568
|
declare const WEAVE_STORE_AZURE_WEB_PUBSUB_CONNECTION_STATUS: {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
569
|
+
CONNECTING: string;
|
|
570
|
+
CONNECTED: string;
|
|
571
|
+
DISCONNECTED: string;
|
|
572
|
+
ERROR: string;
|
|
25
573
|
};
|
|
26
574
|
declare const WEAVE_STORE_HORIZONTAL_SYNC_HANDLER_CLIENT_TYPE: {
|
|
27
|
-
|
|
28
|
-
|
|
575
|
+
PUB: string;
|
|
576
|
+
SUB: string;
|
|
29
577
|
};
|
|
30
578
|
declare const WEAVE_STORE_AZURE_WEB_PUBSUB_DESTROY_ROOM_STATUS: {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
579
|
+
NOT_FOUND: string;
|
|
580
|
+
NOT_CONNECTED: string;
|
|
581
|
+
DESTROYED: string;
|
|
34
582
|
};
|
|
35
583
|
declare const WEAVE_STORE_AZURE_WEB_PUBSUB_SYNC_CLIENT_DEFAULT_OPTIONS: WeaveStoreAzureWebPubSubSyncClientOptions;
|
|
36
584
|
declare const WEAVE_STORE_AZURE_WEB_PUBSUB_SYNC_HOST_DEFAULT_OPTIONS: WeaveStoreAzureWebPubsubSyncHostOptions;
|
|
37
|
-
|
|
585
|
+
//#endregion
|
|
586
|
+
//#region ../../node_modules/lib0/observable.d.ts
|
|
587
|
+
/**
|
|
588
|
+
* Handles named events.
|
|
589
|
+
*
|
|
590
|
+
* @deprecated
|
|
591
|
+
* @template N
|
|
592
|
+
*/
|
|
593
|
+
declare class Observable<N> {
|
|
594
|
+
/**
|
|
595
|
+
* Some desc.
|
|
596
|
+
* @type {Map<N, any>}
|
|
597
|
+
*/
|
|
598
|
+
_observers: Map<N, any>;
|
|
599
|
+
/**
|
|
600
|
+
* @param {N} name
|
|
601
|
+
* @param {function} f
|
|
602
|
+
*/
|
|
603
|
+
on(name: N, f: Function): void;
|
|
604
|
+
/**
|
|
605
|
+
* @param {N} name
|
|
606
|
+
* @param {function} f
|
|
607
|
+
*/
|
|
608
|
+
once(name: N, f: Function): void;
|
|
609
|
+
/**
|
|
610
|
+
* @param {N} name
|
|
611
|
+
* @param {function} f
|
|
612
|
+
*/
|
|
613
|
+
off(name: N, f: Function): void;
|
|
614
|
+
/**
|
|
615
|
+
* Emit a named event. All registered event listeners that listen to the
|
|
616
|
+
* specified name will receive the event.
|
|
617
|
+
*
|
|
618
|
+
* @todo This should catch exceptions
|
|
619
|
+
*
|
|
620
|
+
* @param {N} name The event name.
|
|
621
|
+
* @param {Array<any>} args The arguments that are applied to the event listener.
|
|
622
|
+
*/
|
|
623
|
+
emit(name: N, args: Array<any>): void;
|
|
624
|
+
destroy(): void;
|
|
625
|
+
}
|
|
626
|
+
//#endregion
|
|
627
|
+
//#region ../../node_modules/y-protocols/awareness.d.ts
|
|
628
|
+
/**
|
|
629
|
+
* @typedef {Object} MetaClientState
|
|
630
|
+
* @property {number} MetaClientState.clock
|
|
631
|
+
* @property {number} MetaClientState.lastUpdated unix timestamp
|
|
632
|
+
*/
|
|
633
|
+
/**
|
|
634
|
+
* The Awareness class implements a simple shared state protocol that can be used for non-persistent data like awareness information
|
|
635
|
+
* (cursor, username, status, ..). Each client can update its own local state and listen to state changes of
|
|
636
|
+
* remote clients. Every client may set a state of a remote peer to `null` to mark the client as offline.
|
|
637
|
+
*
|
|
638
|
+
* Each client is identified by a unique client id (something we borrow from `doc.clientID`). A client can override
|
|
639
|
+
* its own state by propagating a message with an increasing timestamp (`clock`). If such a message is received, it is
|
|
640
|
+
* applied if the known state of that client is older than the new state (`clock < newClock`). If a client thinks that
|
|
641
|
+
* a remote client is offline, it may propagate a message with
|
|
642
|
+
* `{ clock: currentClientClock, state: null, client: remoteClient }`. If such a
|
|
643
|
+
* message is received, and the known clock of that client equals the received clock, it will override the state with `null`.
|
|
644
|
+
*
|
|
645
|
+
* Before a client disconnects, it should propagate a `null` state with an updated clock.
|
|
646
|
+
*
|
|
647
|
+
* Awareness states must be updated every 30 seconds. Otherwise the Awareness instance will delete the client state.
|
|
648
|
+
*
|
|
649
|
+
* @extends {Observable<string>}
|
|
650
|
+
*/
|
|
651
|
+
declare class Awareness extends Observable<string> {
|
|
652
|
+
/**
|
|
653
|
+
* @param {Y.Doc} doc
|
|
654
|
+
*/
|
|
655
|
+
constructor(doc: Y.Doc);
|
|
656
|
+
doc: Y.Doc;
|
|
657
|
+
/**
|
|
658
|
+
* @type {number}
|
|
659
|
+
*/
|
|
660
|
+
clientID: number;
|
|
661
|
+
/**
|
|
662
|
+
* Maps from client id to client state
|
|
663
|
+
* @type {Map<number, Object<string, any>>}
|
|
664
|
+
*/
|
|
665
|
+
states: Map<number, {
|
|
666
|
+
[x: string]: any;
|
|
667
|
+
}>;
|
|
668
|
+
/**
|
|
669
|
+
* @type {Map<number, MetaClientState>}
|
|
670
|
+
*/
|
|
671
|
+
meta: Map<number, MetaClientState>;
|
|
672
|
+
_checkInterval: any;
|
|
673
|
+
/**
|
|
674
|
+
* @return {Object<string,any>|null}
|
|
675
|
+
*/
|
|
676
|
+
getLocalState(): {
|
|
677
|
+
[x: string]: any;
|
|
678
|
+
} | null;
|
|
679
|
+
/**
|
|
680
|
+
* @param {Object<string,any>|null} state
|
|
681
|
+
*/
|
|
682
|
+
setLocalState(state: {
|
|
683
|
+
[x: string]: any;
|
|
684
|
+
} | null): void;
|
|
685
|
+
/**
|
|
686
|
+
* @param {string} field
|
|
687
|
+
* @param {any} value
|
|
688
|
+
*/
|
|
689
|
+
setLocalStateField(field: string, value: any): void;
|
|
690
|
+
/**
|
|
691
|
+
* @return {Map<number,Object<string,any>>}
|
|
692
|
+
*/
|
|
693
|
+
getStates(): Map<number, {
|
|
694
|
+
[x: string]: any;
|
|
695
|
+
}>;
|
|
696
|
+
}
|
|
697
|
+
type MetaClientState = {
|
|
698
|
+
clock: number;
|
|
699
|
+
/**
|
|
700
|
+
* unix timestamp
|
|
701
|
+
*/
|
|
702
|
+
lastUpdated: number;
|
|
703
|
+
};
|
|
38
704
|
//#endregion
|
|
39
705
|
//#region src/store-azure-web-pubsub.d.ts
|
|
40
706
|
declare class WeaveStoreAzureWebPubsub extends WeaveStore {
|
|
@@ -65,7 +731,6 @@ declare class WeaveStoreAzureWebPubsub extends WeaveStore {
|
|
|
65
731
|
handleAwarenessChange(emit?: boolean): void;
|
|
66
732
|
setAwarenessInfo<T>(field: string, value: T): void;
|
|
67
733
|
}
|
|
68
|
-
|
|
69
734
|
//#endregion
|
|
70
735
|
//#region src/client.d.ts
|
|
71
736
|
declare class WeaveStoreAzureWebPubSubSyncClient extends Emittery {
|
|
@@ -90,14 +755,14 @@ declare class WeaveStoreAzureWebPubSubSyncClient extends Emittery {
|
|
|
90
755
|
private _updateHandler;
|
|
91
756
|
private _awarenessUpdateHandler;
|
|
92
757
|
/**
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
758
|
+
* @param {string} url
|
|
759
|
+
* @param {string} topic
|
|
760
|
+
* @param {Doc} doc
|
|
761
|
+
* @param {number} [options.resyncInterval] Request server state every `resyncInterval` milliseconds.
|
|
762
|
+
* @param {number} [options.tokenProvider] token generator for negotiation.
|
|
763
|
+
*/
|
|
99
764
|
constructor(instance: WeaveStoreAzureWebPubsub, url: string, topic: string, doc: Doc, options?: DeepPartial<WeaveStoreAzureWebPubSubSyncClientOptions>);
|
|
100
|
-
get awareness():
|
|
765
|
+
get awareness(): Awareness;
|
|
101
766
|
get synced(): boolean;
|
|
102
767
|
set synced(state: boolean);
|
|
103
768
|
get ws(): ReconnectingWebSocket | null;
|
|
@@ -114,7 +779,43 @@ declare class WeaveStoreAzureWebPubSubSyncClient extends Emittery {
|
|
|
114
779
|
private destroyCheckHeartbeat;
|
|
115
780
|
connect(connectionUrlExtraParams?: Record<string, string>): Promise<void>;
|
|
116
781
|
}
|
|
117
|
-
|
|
782
|
+
//#endregion
|
|
783
|
+
//#region ../../node_modules/lib0/encoding.d.ts
|
|
784
|
+
/**
|
|
785
|
+
* A BinaryEncoder handles the encoding to an Uint8Array.
|
|
786
|
+
*/
|
|
787
|
+
declare class Encoder {
|
|
788
|
+
cpos: number;
|
|
789
|
+
cbuf: Uint8Array<ArrayBuffer>;
|
|
790
|
+
/**
|
|
791
|
+
* @type {Array<Uint8Array>}
|
|
792
|
+
*/
|
|
793
|
+
bufs: Array<Uint8Array>;
|
|
794
|
+
}
|
|
795
|
+
//#endregion
|
|
796
|
+
//#region ../../node_modules/lib0/decoding.d.ts
|
|
797
|
+
/**
|
|
798
|
+
* A Decoder handles the decoding of an Uint8Array.
|
|
799
|
+
* @template {ArrayBufferLike} [Buf=ArrayBufferLike]
|
|
800
|
+
*/
|
|
801
|
+
declare class Decoder<Buf extends ArrayBufferLike = ArrayBufferLike> {
|
|
802
|
+
/**
|
|
803
|
+
* @param {Uint8Array<Buf>} uint8Array Binary data to decode
|
|
804
|
+
*/
|
|
805
|
+
constructor(uint8Array: Uint8Array<Buf>);
|
|
806
|
+
/**
|
|
807
|
+
* Decoding target.
|
|
808
|
+
*
|
|
809
|
+
* @type {Uint8Array<Buf>}
|
|
810
|
+
*/
|
|
811
|
+
arr: Uint8Array<Buf>;
|
|
812
|
+
/**
|
|
813
|
+
* Current decoding position.
|
|
814
|
+
*
|
|
815
|
+
* @type {number}
|
|
816
|
+
*/
|
|
817
|
+
pos: number;
|
|
818
|
+
}
|
|
118
819
|
//#endregion
|
|
119
820
|
//#region src/types.d.ts
|
|
120
821
|
type WeaveStoreAzureWebPubsubConfig = {
|
|
@@ -139,9 +840,9 @@ type IndexedDbOptions = {
|
|
|
139
840
|
/** Enable IndexedDB offline persistence for faster initial load. Default: false. */
|
|
140
841
|
enabled: boolean;
|
|
141
842
|
/**
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
843
|
+
* IndexedDB database name. Defaults to the roomId when omitted.
|
|
844
|
+
* Override to namespace databases in multi-tenant applications.
|
|
845
|
+
*/
|
|
145
846
|
dbName?: string;
|
|
146
847
|
};
|
|
147
848
|
type WeaveStoreAzureWebPubsubOptions = {
|
|
@@ -214,12 +915,12 @@ type WeaveStoreAzureWebPubSubSyncClientConnectionStatus = (typeof WEAVE_STORE_AZ
|
|
|
214
915
|
declare enum MessageType {
|
|
215
916
|
System = "system",
|
|
216
917
|
JoinGroup = "joinGroup",
|
|
217
|
-
SendToGroup = "sendToGroup"
|
|
918
|
+
SendToGroup = "sendToGroup"
|
|
218
919
|
}
|
|
219
920
|
declare enum MessageDataType {
|
|
220
921
|
Init = "init",
|
|
221
922
|
Sync = "sync",
|
|
222
|
-
Awareness = "awareness"
|
|
923
|
+
Awareness = "awareness"
|
|
223
924
|
}
|
|
224
925
|
interface MessageData {
|
|
225
926
|
payloadId?: string;
|
|
@@ -259,810 +960,1793 @@ type WeaveStoreAzureWebPubsubSyncHostOptions = {
|
|
|
259
960
|
attemptsLimit: number;
|
|
260
961
|
};
|
|
261
962
|
};
|
|
262
|
-
|
|
963
|
+
//#endregion
|
|
964
|
+
//#region ../../node_modules/@types/express-serve-static-core/index.d.ts
|
|
965
|
+
declare global {
|
|
966
|
+
namespace Express {
|
|
967
|
+
// These open interfaces may be extended in an application-specific manner via declaration merging.
|
|
968
|
+
// See for example method-override.d.ts (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/method-override/index.d.ts)
|
|
969
|
+
interface Request {}
|
|
970
|
+
interface Response {}
|
|
971
|
+
interface Locals {}
|
|
972
|
+
interface Application {}
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
interface NextFunction {
|
|
976
|
+
(err?: any): void;
|
|
977
|
+
/**
|
|
978
|
+
* "Break-out" of a router by calling {next('router')};
|
|
979
|
+
* @see {https://expressjs.com/en/guide/using-middleware.html#middleware.router}
|
|
980
|
+
*/
|
|
981
|
+
(deferToNext: "router"): void;
|
|
982
|
+
/**
|
|
983
|
+
* "Break-out" of a route by calling {next('route')};
|
|
984
|
+
* @see {https://expressjs.com/en/guide/using-middleware.html#middleware.application}
|
|
985
|
+
*/
|
|
986
|
+
(deferToNext: "route"): void;
|
|
987
|
+
}
|
|
988
|
+
interface ParamsDictionary {
|
|
989
|
+
[key: string]: string | string[];
|
|
990
|
+
[key: number]: string;
|
|
991
|
+
}
|
|
992
|
+
interface ParamsFlatDictionary {
|
|
993
|
+
[key: string | number]: string;
|
|
994
|
+
}
|
|
995
|
+
interface Locals extends Express.Locals {}
|
|
996
|
+
interface RequestHandler$1<P = ParamsDictionary, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>> {
|
|
997
|
+
// tslint:disable-next-line callable-types (This is extended from and can't extend from a type alias in ts<2.2)
|
|
998
|
+
(req: Request<P, ResBody, ReqBody, ReqQuery, LocalsObj>, res: Response$1<ResBody, LocalsObj>, next: NextFunction): unknown;
|
|
999
|
+
}
|
|
1000
|
+
type ErrorRequestHandler<P = ParamsDictionary, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>> = (err: any, req: Request<P, ResBody, ReqBody, ReqQuery, LocalsObj>, res: Response$1<ResBody, LocalsObj>, next: NextFunction) => unknown;
|
|
1001
|
+
type PathParams = string | RegExp | Array<string | RegExp>;
|
|
1002
|
+
type RequestHandlerParams<P = ParamsDictionary, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>> = RequestHandler$1<P, ResBody, ReqBody, ReqQuery, LocalsObj> | ErrorRequestHandler<P, ResBody, ReqBody, ReqQuery, LocalsObj> | Array<RequestHandler$1<P> | ErrorRequestHandler<P>>;
|
|
1003
|
+
type RemoveTail<S extends string, Tail extends string> = S extends `${infer P}${Tail}` ? P : S;
|
|
1004
|
+
type GetRouteParameter<S extends string> = RemoveTail<RemoveTail<RemoveTail<S, `/${string}`>, `-${string}`>, `.${string}`>;
|
|
1005
|
+
// dprint-ignore
|
|
1006
|
+
type RouteParameters<Route extends string | RegExp> = Route extends string ? Route extends `${infer Required}{${infer Optional}}${infer Next}` ? ParseRouteParameters<Required> & Partial<ParseRouteParameters<Optional>> & RouteParameters<Next> : ParseRouteParameters<Route> : ParamsFlatDictionary;
|
|
1007
|
+
type ParseRouteParameters<Route extends string> = string extends Route ? ParamsDictionary : Route extends `${string}:${infer Rest}` ? (GetRouteParameter<Rest> extends never ? ParamsDictionary : { [P in GetRouteParameter<Rest>]: string; }) & (Rest extends `${GetRouteParameter<Rest>}${infer Next}` ? RouteParameters<Next> : unknown) : Route extends `${string}*${infer Rest}` ? (GetRouteParameter<Rest> extends never ? ParamsDictionary : { [P in GetRouteParameter<Rest>]: string[]; }) & (Rest extends `${GetRouteParameter<Rest>}${infer Next}` ? RouteParameters<Next> : unknown) : {};
|
|
1008
|
+
/* eslint-disable @definitelytyped/no-unnecessary-generics */
|
|
1009
|
+
interface IRouterMatcher<T, Method extends "all" | "get" | "post" | "put" | "delete" | "patch" | "options" | "head" | "query" = any> {
|
|
1010
|
+
<Route extends string | RegExp, P = RouteParameters<Route>, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>>(
|
|
1011
|
+
// (it's used as the default type parameter for P)
|
|
1012
|
+
path: Route,
|
|
1013
|
+
// (This generic is meant to be passed explicitly.)
|
|
1014
|
+
...handlers: Array<RequestHandler$1<P, ResBody, ReqBody, ReqQuery, LocalsObj>>): T;
|
|
1015
|
+
<Path extends string | RegExp, P = RouteParameters<Path>, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>>(
|
|
1016
|
+
// (it's used as the default type parameter for P)
|
|
1017
|
+
path: Path,
|
|
1018
|
+
// (This generic is meant to be passed explicitly.)
|
|
1019
|
+
...handlers: Array<RequestHandlerParams<P, ResBody, ReqBody, ReqQuery, LocalsObj>>): T;
|
|
1020
|
+
<P = ParamsDictionary, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>>(path: PathParams,
|
|
1021
|
+
// (This generic is meant to be passed explicitly.)
|
|
1022
|
+
...handlers: Array<RequestHandler$1<P, ResBody, ReqBody, ReqQuery, LocalsObj>>): T;
|
|
1023
|
+
<P = ParamsDictionary, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>>(path: PathParams,
|
|
1024
|
+
// (This generic is meant to be passed explicitly.)
|
|
1025
|
+
...handlers: Array<RequestHandlerParams<P, ResBody, ReqBody, ReqQuery, LocalsObj>>): T;
|
|
1026
|
+
(path: PathParams, subApplication: Application): T;
|
|
1027
|
+
}
|
|
1028
|
+
interface IRouterHandler<T, Route extends string | RegExp = string> {
|
|
1029
|
+
(...handlers: Array<RequestHandler$1<RouteParameters<Route>>>): T;
|
|
1030
|
+
(...handlers: Array<RequestHandlerParams<RouteParameters<Route>>>): T;
|
|
1031
|
+
<P = RouteParameters<Route>, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>>(
|
|
1032
|
+
// (This generic is meant to be passed explicitly.)
|
|
1033
|
+
// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
|
|
1034
|
+
...handlers: Array<RequestHandler$1<P, ResBody, ReqBody, ReqQuery, LocalsObj>>): T;
|
|
1035
|
+
<P = RouteParameters<Route>, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>>(
|
|
1036
|
+
// (This generic is meant to be passed explicitly.)
|
|
1037
|
+
// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
|
|
1038
|
+
...handlers: Array<RequestHandlerParams<P, ResBody, ReqBody, ReqQuery, LocalsObj>>): T;
|
|
1039
|
+
<P = ParamsDictionary, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>>(
|
|
1040
|
+
// (This generic is meant to be passed explicitly.)
|
|
1041
|
+
// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
|
|
1042
|
+
...handlers: Array<RequestHandler$1<P, ResBody, ReqBody, ReqQuery, LocalsObj>>): T;
|
|
1043
|
+
<P = ParamsDictionary, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>>(
|
|
1044
|
+
// (This generic is meant to be passed explicitly.)
|
|
1045
|
+
// eslint-disable-next-line @definitelytyped/no-unnecessary-generics
|
|
1046
|
+
...handlers: Array<RequestHandlerParams<P, ResBody, ReqBody, ReqQuery, LocalsObj>>): T;
|
|
1047
|
+
}
|
|
1048
|
+
/* eslint-enable @definitelytyped/no-unnecessary-generics */
|
|
1049
|
+
interface IRouter extends RequestHandler$1 {
|
|
1050
|
+
/**
|
|
1051
|
+
* Map the given param placeholder `name`(s) to the given callback(s).
|
|
1052
|
+
*
|
|
1053
|
+
* Parameter mapping is used to provide pre-conditions to routes
|
|
1054
|
+
* which use normalized placeholders. For example a _:user_id_ parameter
|
|
1055
|
+
* could automatically load a user's information from the database without
|
|
1056
|
+
* any additional code,
|
|
1057
|
+
*
|
|
1058
|
+
* The callback uses the samesignature as middleware, the only differencing
|
|
1059
|
+
* being that the value of the placeholder is passed, in this case the _id_
|
|
1060
|
+
* of the user. Once the `next()` function is invoked, just like middleware
|
|
1061
|
+
* it will continue on to execute the route, or subsequent parameter functions.
|
|
1062
|
+
*
|
|
1063
|
+
* app.param('user_id', function(req, res, next, id){
|
|
1064
|
+
* User.find(id, function(err, user){
|
|
1065
|
+
* if (err) {
|
|
1066
|
+
* next(err);
|
|
1067
|
+
* } else if (user) {
|
|
1068
|
+
* req.user = user;
|
|
1069
|
+
* next();
|
|
1070
|
+
* } else {
|
|
1071
|
+
* next(new Error('failed to load user'));
|
|
1072
|
+
* }
|
|
1073
|
+
* });
|
|
1074
|
+
* });
|
|
1075
|
+
*/
|
|
1076
|
+
param(name: string, handler: RequestParamHandler): this;
|
|
1077
|
+
/**
|
|
1078
|
+
* Special-cased "all" method, applying the given route `path`,
|
|
1079
|
+
* middleware, and callback to _every_ HTTP method.
|
|
1080
|
+
*/
|
|
1081
|
+
all: IRouterMatcher<this, "all">;
|
|
1082
|
+
get: IRouterMatcher<this, "get">;
|
|
1083
|
+
post: IRouterMatcher<this, "post">;
|
|
1084
|
+
put: IRouterMatcher<this, "put">;
|
|
1085
|
+
delete: IRouterMatcher<this, "delete">;
|
|
1086
|
+
patch: IRouterMatcher<this, "patch">;
|
|
1087
|
+
options: IRouterMatcher<this, "options">;
|
|
1088
|
+
head: IRouterMatcher<this, "head">;
|
|
1089
|
+
/**
|
|
1090
|
+
* Requires Node.js >=20.19.3 <21 || >=22.2.0
|
|
1091
|
+
* @see https://expressjs.com/en/5x/api/application/#appquery
|
|
1092
|
+
*/
|
|
1093
|
+
query?: IRouterMatcher<this, "query">;
|
|
1094
|
+
checkout: IRouterMatcher<this>;
|
|
1095
|
+
connect: IRouterMatcher<this>;
|
|
1096
|
+
copy: IRouterMatcher<this>;
|
|
1097
|
+
lock: IRouterMatcher<this>;
|
|
1098
|
+
merge: IRouterMatcher<this>;
|
|
1099
|
+
mkactivity: IRouterMatcher<this>;
|
|
1100
|
+
mkcol: IRouterMatcher<this>;
|
|
1101
|
+
move: IRouterMatcher<this>;
|
|
1102
|
+
"m-search": IRouterMatcher<this>;
|
|
1103
|
+
notify: IRouterMatcher<this>;
|
|
1104
|
+
propfind: IRouterMatcher<this>;
|
|
1105
|
+
proppatch: IRouterMatcher<this>;
|
|
1106
|
+
purge: IRouterMatcher<this>;
|
|
1107
|
+
report: IRouterMatcher<this>;
|
|
1108
|
+
search: IRouterMatcher<this>;
|
|
1109
|
+
subscribe: IRouterMatcher<this>;
|
|
1110
|
+
trace: IRouterMatcher<this>;
|
|
1111
|
+
unlock: IRouterMatcher<this>;
|
|
1112
|
+
unsubscribe: IRouterMatcher<this>;
|
|
1113
|
+
link: IRouterMatcher<this>;
|
|
1114
|
+
unlink: IRouterMatcher<this>;
|
|
1115
|
+
use: IRouterHandler<this> & IRouterMatcher<this>;
|
|
1116
|
+
route<T extends string | RegExp>(prefix: T): IRoute<T>;
|
|
1117
|
+
route(prefix: PathParams): IRoute;
|
|
1118
|
+
/**
|
|
1119
|
+
* Stack of configured routes
|
|
1120
|
+
*/
|
|
1121
|
+
stack: ILayer[];
|
|
1122
|
+
}
|
|
1123
|
+
interface ILayer {
|
|
1124
|
+
route?: IRoute;
|
|
1125
|
+
name: string | "<anonymous>";
|
|
1126
|
+
params?: Record<string, any>;
|
|
1127
|
+
keys: string[];
|
|
1128
|
+
path?: string;
|
|
1129
|
+
method: string;
|
|
1130
|
+
regexp: RegExp;
|
|
1131
|
+
handle: (req: Request, res: Response$1, next: NextFunction) => any;
|
|
1132
|
+
}
|
|
1133
|
+
interface IRoute<Route extends string | RegExp = string> {
|
|
1134
|
+
path: string;
|
|
1135
|
+
stack: ILayer[];
|
|
1136
|
+
all: IRouterHandler<this, Route>;
|
|
1137
|
+
get: IRouterHandler<this, Route>;
|
|
1138
|
+
post: IRouterHandler<this, Route>;
|
|
1139
|
+
put: IRouterHandler<this, Route>;
|
|
1140
|
+
delete: IRouterHandler<this, Route>;
|
|
1141
|
+
patch: IRouterHandler<this, Route>;
|
|
1142
|
+
options: IRouterHandler<this, Route>;
|
|
1143
|
+
head: IRouterHandler<this, Route>;
|
|
1144
|
+
checkout: IRouterHandler<this, Route>;
|
|
1145
|
+
copy: IRouterHandler<this, Route>;
|
|
1146
|
+
lock: IRouterHandler<this, Route>;
|
|
1147
|
+
merge: IRouterHandler<this, Route>;
|
|
1148
|
+
mkactivity: IRouterHandler<this, Route>;
|
|
1149
|
+
mkcol: IRouterHandler<this, Route>;
|
|
1150
|
+
move: IRouterHandler<this, Route>;
|
|
1151
|
+
"m-search": IRouterHandler<this, Route>;
|
|
1152
|
+
notify: IRouterHandler<this, Route>;
|
|
1153
|
+
purge: IRouterHandler<this, Route>;
|
|
1154
|
+
report: IRouterHandler<this, Route>;
|
|
1155
|
+
search: IRouterHandler<this, Route>;
|
|
1156
|
+
subscribe: IRouterHandler<this, Route>;
|
|
1157
|
+
trace: IRouterHandler<this, Route>;
|
|
1158
|
+
unlock: IRouterHandler<this, Route>;
|
|
1159
|
+
unsubscribe: IRouterHandler<this, Route>;
|
|
1160
|
+
}
|
|
1161
|
+
interface Router extends IRouter {}
|
|
1162
|
+
/**
|
|
1163
|
+
* Options passed down into `res.cookie`
|
|
1164
|
+
* @link https://expressjs.com/en/api.html#res.cookie
|
|
1165
|
+
*/
|
|
1166
|
+
interface CookieOptions {
|
|
1167
|
+
/** Convenient option for setting the expiry time relative to the current time in **milliseconds**. */
|
|
1168
|
+
maxAge?: number | undefined;
|
|
1169
|
+
/** Indicates if the cookie should be signed. */
|
|
1170
|
+
signed?: boolean | undefined;
|
|
1171
|
+
/** Expiry date of the cookie in GMT. If not specified (undefined), creates a session cookie. */
|
|
1172
|
+
expires?: Date | undefined;
|
|
1173
|
+
/** Flags the cookie to be accessible only by the web server. */
|
|
1174
|
+
httpOnly?: boolean | undefined;
|
|
1175
|
+
/** Path for the cookie. Defaults to “/”. */
|
|
1176
|
+
path?: string | undefined;
|
|
1177
|
+
/** Domain name for the cookie. Defaults to the domain name of the app. */
|
|
1178
|
+
domain?: string | undefined;
|
|
1179
|
+
/** Marks the cookie to be used with HTTPS only. */
|
|
1180
|
+
secure?: boolean | undefined;
|
|
1181
|
+
/** A synchronous function used for cookie value encoding. Defaults to encodeURIComponent. */
|
|
1182
|
+
encode?: ((val: string) => string) | undefined;
|
|
1183
|
+
/**
|
|
1184
|
+
* Value of the “SameSite” Set-Cookie attribute.
|
|
1185
|
+
* @link https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00#section-4.1.1.
|
|
1186
|
+
*/
|
|
1187
|
+
sameSite?: boolean | "lax" | "strict" | "none" | undefined;
|
|
1188
|
+
/**
|
|
1189
|
+
* Value of the “Priority” Set-Cookie attribute.
|
|
1190
|
+
* @link https://datatracker.ietf.org/doc/html/draft-west-cookie-priority-00#section-4.3
|
|
1191
|
+
*/
|
|
1192
|
+
priority?: "low" | "medium" | "high";
|
|
1193
|
+
/** Marks the cookie to use partioned storage. */
|
|
1194
|
+
partitioned?: boolean | undefined;
|
|
1195
|
+
}
|
|
1196
|
+
type Errback = (err?: Error) => void;
|
|
1197
|
+
/**
|
|
1198
|
+
* @param P For most requests, this should be `ParamsDictionary`, but if you're
|
|
1199
|
+
* using this in a route handler for a route that uses a `RegExp`, then `req.params`
|
|
1200
|
+
* will only contains strings, in which case you should use `ParamsFlatDictionary` instead.
|
|
1201
|
+
*
|
|
1202
|
+
* @example
|
|
1203
|
+
* app.get('/user/:id', (req, res) => res.send(req.params.id)); // implicitly `ParamsDictionary`, parameter is string
|
|
1204
|
+
* app.get('/user/*id', (req, res) => res.send(req.params.id)); // implicitly `ParamsDictionary`, parameter is string[]
|
|
1205
|
+
* app.get(/user\/(?<id>.*)/, (req, res) => res.send(req.params.id)); // implicitly `ParamsFlatDictionary`, parameter is string
|
|
1206
|
+
* app.get(/user\/(.*)/, (req, res) => res.send(req.params[0])); // implicitly `ParamsFlatDictionary`, parameter is string
|
|
1207
|
+
*/
|
|
1208
|
+
interface Request<P = ParamsDictionary, ResBody = any, ReqBody = any, ReqQuery = ParsedQs, LocalsObj extends Record<string, any> = Record<string, any>> extends http.IncomingMessage, Express.Request {
|
|
1209
|
+
/**
|
|
1210
|
+
* Return request header.
|
|
1211
|
+
*
|
|
1212
|
+
* The `Referrer` header field is special-cased,
|
|
1213
|
+
* both `Referrer` and `Referer` are interchangeable.
|
|
1214
|
+
*
|
|
1215
|
+
* Examples:
|
|
1216
|
+
*
|
|
1217
|
+
* req.get('Content-Type');
|
|
1218
|
+
* // => "text/plain"
|
|
1219
|
+
*
|
|
1220
|
+
* req.get('content-type');
|
|
1221
|
+
* // => "text/plain"
|
|
1222
|
+
*
|
|
1223
|
+
* req.get('Something');
|
|
1224
|
+
* // => undefined
|
|
1225
|
+
*
|
|
1226
|
+
* Aliased as `req.header()`.
|
|
1227
|
+
*/
|
|
1228
|
+
get(name: "set-cookie"): string[] | undefined;
|
|
1229
|
+
get(name: string): string | undefined;
|
|
1230
|
+
header(name: "set-cookie"): string[] | undefined;
|
|
1231
|
+
header(name: string): string | undefined;
|
|
1232
|
+
/**
|
|
1233
|
+
* Check if the given `type(s)` is acceptable, returning
|
|
1234
|
+
* the best match when true, otherwise `undefined`, in which
|
|
1235
|
+
* case you should respond with 406 "Not Acceptable".
|
|
1236
|
+
*
|
|
1237
|
+
* The `type` value may be a single mime type string
|
|
1238
|
+
* such as "application/json", the extension name
|
|
1239
|
+
* such as "json", a comma-delimted list such as "json, html, text/plain",
|
|
1240
|
+
* or an array `["json", "html", "text/plain"]`. When a list
|
|
1241
|
+
* or array is given the _best_ match, if any is returned.
|
|
1242
|
+
*
|
|
1243
|
+
* Examples:
|
|
1244
|
+
*
|
|
1245
|
+
* // Accept: text/html
|
|
1246
|
+
* req.accepts('html');
|
|
1247
|
+
* // => "html"
|
|
1248
|
+
*
|
|
1249
|
+
* // Accept: text/*, application/json
|
|
1250
|
+
* req.accepts('html');
|
|
1251
|
+
* // => "html"
|
|
1252
|
+
* req.accepts('text/html');
|
|
1253
|
+
* // => "text/html"
|
|
1254
|
+
* req.accepts('json, text');
|
|
1255
|
+
* // => "json"
|
|
1256
|
+
* req.accepts('application/json');
|
|
1257
|
+
* // => "application/json"
|
|
1258
|
+
*
|
|
1259
|
+
* // Accept: text/*, application/json
|
|
1260
|
+
* req.accepts('image/png');
|
|
1261
|
+
* req.accepts('png');
|
|
1262
|
+
* // => false
|
|
1263
|
+
*
|
|
1264
|
+
* // Accept: text/*;q=.5, application/json
|
|
1265
|
+
* req.accepts(['html', 'json']);
|
|
1266
|
+
* req.accepts('html, json');
|
|
1267
|
+
* // => "json"
|
|
1268
|
+
*/
|
|
1269
|
+
accepts(): string[];
|
|
1270
|
+
accepts(type: string): string | false;
|
|
1271
|
+
accepts(type: string[]): string | false;
|
|
1272
|
+
accepts(...type: string[]): string | false;
|
|
1273
|
+
/**
|
|
1274
|
+
* Returns the first accepted charset of the specified character sets,
|
|
1275
|
+
* based on the request's Accept-Charset HTTP header field.
|
|
1276
|
+
* If none of the specified charsets is accepted, returns false.
|
|
1277
|
+
*
|
|
1278
|
+
* For more information, or if you have issues or concerns, see accepts.
|
|
1279
|
+
*/
|
|
1280
|
+
acceptsCharsets(): string[];
|
|
1281
|
+
acceptsCharsets(charset: string): string | false;
|
|
1282
|
+
acceptsCharsets(charset: string[]): string | false;
|
|
1283
|
+
acceptsCharsets(...charset: string[]): string | false;
|
|
1284
|
+
/**
|
|
1285
|
+
* Returns the first accepted encoding of the specified encodings,
|
|
1286
|
+
* based on the request's Accept-Encoding HTTP header field.
|
|
1287
|
+
* If none of the specified encodings is accepted, returns false.
|
|
1288
|
+
*
|
|
1289
|
+
* For more information, or if you have issues or concerns, see accepts.
|
|
1290
|
+
*/
|
|
1291
|
+
acceptsEncodings(): string[];
|
|
1292
|
+
acceptsEncodings(encoding: string): string | false;
|
|
1293
|
+
acceptsEncodings(encoding: string[]): string | false;
|
|
1294
|
+
acceptsEncodings(...encoding: string[]): string | false;
|
|
1295
|
+
/**
|
|
1296
|
+
* Returns the first accepted language of the specified languages,
|
|
1297
|
+
* based on the request's Accept-Language HTTP header field.
|
|
1298
|
+
* If none of the specified languages is accepted, returns false.
|
|
1299
|
+
*
|
|
1300
|
+
* For more information, or if you have issues or concerns, see accepts.
|
|
1301
|
+
*/
|
|
1302
|
+
acceptsLanguages(): string[];
|
|
1303
|
+
acceptsLanguages(lang: string): string | false;
|
|
1304
|
+
acceptsLanguages(lang: string[]): string | false;
|
|
1305
|
+
acceptsLanguages(...lang: string[]): string | false;
|
|
1306
|
+
/**
|
|
1307
|
+
* Parse Range header field, capping to the given `size`.
|
|
1308
|
+
*
|
|
1309
|
+
* Unspecified ranges such as "0-" require knowledge of your resource length. In
|
|
1310
|
+
* the case of a byte range this is of course the total number of bytes.
|
|
1311
|
+
* If the Range header field is not given `undefined` is returned.
|
|
1312
|
+
* If the Range header field is given, return value is a result of range-parser.
|
|
1313
|
+
* See more ./types/range-parser/index.d.ts
|
|
1314
|
+
*
|
|
1315
|
+
* NOTE: remember that ranges are inclusive, so for example "Range: users=0-3"
|
|
1316
|
+
* should respond with 4 users when available, not 3.
|
|
1317
|
+
*/
|
|
1318
|
+
range(size: number, options?: Options): Ranges | Result | undefined;
|
|
1319
|
+
/**
|
|
1320
|
+
* Return an array of Accepted media types
|
|
1321
|
+
* ordered from highest quality to lowest.
|
|
1322
|
+
*/
|
|
1323
|
+
accepted: MediaType[];
|
|
1324
|
+
/**
|
|
1325
|
+
* Check if the incoming request contains the "Content-Type"
|
|
1326
|
+
* header field, and it contains the give mime `type`.
|
|
1327
|
+
*
|
|
1328
|
+
* Examples:
|
|
1329
|
+
*
|
|
1330
|
+
* // With Content-Type: text/html; charset=utf-8
|
|
1331
|
+
* req.is('html');
|
|
1332
|
+
* req.is('text/html');
|
|
1333
|
+
* req.is('text/*');
|
|
1334
|
+
* // => true
|
|
1335
|
+
*
|
|
1336
|
+
* // When Content-Type is application/json
|
|
1337
|
+
* req.is('json');
|
|
1338
|
+
* req.is('application/json');
|
|
1339
|
+
* req.is('application/*');
|
|
1340
|
+
* // => true
|
|
1341
|
+
*
|
|
1342
|
+
* req.is('html');
|
|
1343
|
+
* // => false
|
|
1344
|
+
*/
|
|
1345
|
+
is(type: string | string[]): string | false | null;
|
|
1346
|
+
/**
|
|
1347
|
+
* Return the protocol string "http" or "https"
|
|
1348
|
+
* when requested with TLS. When the "trust proxy"
|
|
1349
|
+
* setting is enabled the "X-Forwarded-Proto" header
|
|
1350
|
+
* field will be trusted. If you're running behind
|
|
1351
|
+
* a reverse proxy that supplies https for you this
|
|
1352
|
+
* may be enabled.
|
|
1353
|
+
*/
|
|
1354
|
+
readonly protocol: string;
|
|
1355
|
+
/**
|
|
1356
|
+
* Short-hand for:
|
|
1357
|
+
*
|
|
1358
|
+
* req.protocol == 'https'
|
|
1359
|
+
*/
|
|
1360
|
+
readonly secure: boolean;
|
|
1361
|
+
/**
|
|
1362
|
+
* Return the remote address, or when
|
|
1363
|
+
* "trust proxy" is `true` return
|
|
1364
|
+
* the upstream addr.
|
|
1365
|
+
*
|
|
1366
|
+
* Value may be undefined if the `req.socket` is destroyed
|
|
1367
|
+
* (for example, if the client disconnected).
|
|
1368
|
+
*/
|
|
1369
|
+
readonly ip: string | undefined;
|
|
1370
|
+
/**
|
|
1371
|
+
* When "trust proxy" is `true`, parse
|
|
1372
|
+
* the "X-Forwarded-For" ip address list.
|
|
1373
|
+
*
|
|
1374
|
+
* For example if the value were "client, proxy1, proxy2"
|
|
1375
|
+
* you would receive the array `["client", "proxy1", "proxy2"]`
|
|
1376
|
+
* where "proxy2" is the furthest down-stream.
|
|
1377
|
+
*/
|
|
1378
|
+
readonly ips: string[];
|
|
1379
|
+
/**
|
|
1380
|
+
* Return subdomains as an array.
|
|
1381
|
+
*
|
|
1382
|
+
* Subdomains are the dot-separated parts of the host before the main domain of
|
|
1383
|
+
* the app. By default, the domain of the app is assumed to be the last two
|
|
1384
|
+
* parts of the host. This can be changed by setting "subdomain offset".
|
|
1385
|
+
*
|
|
1386
|
+
* For example, if the domain is "tobi.ferrets.example.com":
|
|
1387
|
+
* If "subdomain offset" is not set, req.subdomains is `["ferrets", "tobi"]`.
|
|
1388
|
+
* If "subdomain offset" is 3, req.subdomains is `["tobi"]`.
|
|
1389
|
+
*/
|
|
1390
|
+
readonly subdomains: string[];
|
|
1391
|
+
/**
|
|
1392
|
+
* Short-hand for `url.parse(req.url).pathname`.
|
|
1393
|
+
*/
|
|
1394
|
+
readonly path: string;
|
|
1395
|
+
/**
|
|
1396
|
+
* Contains the hostname derived from the `Host` HTTP header.
|
|
1397
|
+
*/
|
|
1398
|
+
readonly hostname: string;
|
|
1399
|
+
/**
|
|
1400
|
+
* Contains the host derived from the `Host` HTTP header.
|
|
1401
|
+
*/
|
|
1402
|
+
readonly host: string;
|
|
1403
|
+
/**
|
|
1404
|
+
* Check if the request is fresh, aka
|
|
1405
|
+
* Last-Modified and/or the ETag
|
|
1406
|
+
* still match.
|
|
1407
|
+
*/
|
|
1408
|
+
readonly fresh: boolean;
|
|
1409
|
+
/**
|
|
1410
|
+
* Check if the request is stale, aka
|
|
1411
|
+
* "Last-Modified" and / or the "ETag" for the
|
|
1412
|
+
* resource has changed.
|
|
1413
|
+
*/
|
|
1414
|
+
readonly stale: boolean;
|
|
1415
|
+
/**
|
|
1416
|
+
* Check if the request was an _XMLHttpRequest_.
|
|
1417
|
+
*/
|
|
1418
|
+
readonly xhr: boolean;
|
|
1419
|
+
// body: { username: string; password: string; remember: boolean; title: string; };
|
|
1420
|
+
body: ReqBody;
|
|
1421
|
+
// cookies: { string; remember: boolean; };
|
|
1422
|
+
cookies: any;
|
|
1423
|
+
method: string;
|
|
1424
|
+
params: P;
|
|
1425
|
+
query: ReqQuery;
|
|
1426
|
+
route: any;
|
|
1427
|
+
signedCookies: any;
|
|
1428
|
+
originalUrl: string;
|
|
1429
|
+
url: string;
|
|
1430
|
+
baseUrl: string;
|
|
1431
|
+
app: Application;
|
|
1432
|
+
/**
|
|
1433
|
+
* After middleware.init executed, Request will contain res and next properties
|
|
1434
|
+
* See: express/lib/middleware/init.js
|
|
1435
|
+
*/
|
|
1436
|
+
res?: Response$1<ResBody, LocalsObj> | undefined;
|
|
1437
|
+
next?: NextFunction | undefined;
|
|
1438
|
+
}
|
|
1439
|
+
interface MediaType {
|
|
1440
|
+
value: string;
|
|
1441
|
+
quality: number;
|
|
1442
|
+
type: string;
|
|
1443
|
+
subtype: string;
|
|
1444
|
+
}
|
|
1445
|
+
type Send<ResBody = any, T = Response$1<ResBody>> = (body?: ResBody) => T;
|
|
1446
|
+
interface SendFileOptions extends SendOptions {
|
|
1447
|
+
/** Object containing HTTP headers to serve with the file. */
|
|
1448
|
+
headers?: Record<string, unknown>;
|
|
1449
|
+
}
|
|
1450
|
+
interface DownloadOptions extends SendOptions {
|
|
1451
|
+
/** Object containing HTTP headers to serve with the file. The header `Content-Disposition` will be overridden by the filename argument. */
|
|
1452
|
+
headers?: Record<string, unknown>;
|
|
1453
|
+
}
|
|
1454
|
+
interface Response$1<ResBody = any, LocalsObj extends Record<string, any> = Record<string, any>, StatusCode extends number = number> extends http.ServerResponse, Express.Response {
|
|
1455
|
+
/**
|
|
1456
|
+
* Set status `code`.
|
|
1457
|
+
*/
|
|
1458
|
+
status(code: StatusCode): this;
|
|
1459
|
+
/**
|
|
1460
|
+
* Set the response HTTP status code to `statusCode` and send its string representation as the response body.
|
|
1461
|
+
* @link http://expressjs.com/4x/api.html#res.sendStatus
|
|
1462
|
+
*
|
|
1463
|
+
* Examples:
|
|
1464
|
+
*
|
|
1465
|
+
* res.sendStatus(200); // equivalent to res.status(200).send('OK')
|
|
1466
|
+
* res.sendStatus(403); // equivalent to res.status(403).send('Forbidden')
|
|
1467
|
+
* res.sendStatus(404); // equivalent to res.status(404).send('Not Found')
|
|
1468
|
+
* res.sendStatus(500); // equivalent to res.status(500).send('Internal Server Error')
|
|
1469
|
+
*/
|
|
1470
|
+
sendStatus(code: StatusCode): this;
|
|
1471
|
+
/**
|
|
1472
|
+
* Set Link header field with the given `links`.
|
|
1473
|
+
*
|
|
1474
|
+
* Examples:
|
|
1475
|
+
*
|
|
1476
|
+
* res.links({
|
|
1477
|
+
* next: 'http://api.example.com/users?page=2',
|
|
1478
|
+
* last: 'http://api.example.com/users?page=5'
|
|
1479
|
+
* });
|
|
1480
|
+
*/
|
|
1481
|
+
links(links: any): this;
|
|
1482
|
+
/**
|
|
1483
|
+
* Send a response.
|
|
1484
|
+
*
|
|
1485
|
+
* Examples:
|
|
1486
|
+
*
|
|
1487
|
+
* res.send(new Buffer('wahoo'));
|
|
1488
|
+
* res.send({ some: 'json' });
|
|
1489
|
+
* res.send('<p>some html</p>');
|
|
1490
|
+
* res.status(404).send('Sorry, cant find that');
|
|
1491
|
+
*/
|
|
1492
|
+
send: Send<ResBody, this>;
|
|
1493
|
+
/**
|
|
1494
|
+
* Send JSON response.
|
|
1495
|
+
*
|
|
1496
|
+
* Examples:
|
|
1497
|
+
*
|
|
1498
|
+
* res.json(null);
|
|
1499
|
+
* res.json({ user: 'tj' });
|
|
1500
|
+
* res.status(500).json('oh noes!');
|
|
1501
|
+
* res.status(404).json('I dont have that');
|
|
1502
|
+
*/
|
|
1503
|
+
json: Send<ResBody, this>;
|
|
1504
|
+
/**
|
|
1505
|
+
* Send JSON response with JSONP callback support.
|
|
1506
|
+
*
|
|
1507
|
+
* Examples:
|
|
1508
|
+
*
|
|
1509
|
+
* res.jsonp(null);
|
|
1510
|
+
* res.jsonp({ user: 'tj' });
|
|
1511
|
+
* res.status(500).jsonp('oh noes!');
|
|
1512
|
+
* res.status(404).jsonp('I dont have that');
|
|
1513
|
+
*/
|
|
1514
|
+
jsonp: Send<ResBody, this>;
|
|
1515
|
+
/**
|
|
1516
|
+
* Transfer the file at the given `path`.
|
|
1517
|
+
*
|
|
1518
|
+
* Automatically sets the _Content-Type_ response header field.
|
|
1519
|
+
* The callback `fn(err)` is invoked when the transfer is complete
|
|
1520
|
+
* or when an error occurs. Be sure to check `res.headersSent`
|
|
1521
|
+
* if you wish to attempt responding, as the header and some data
|
|
1522
|
+
* may have already been transferred.
|
|
1523
|
+
*
|
|
1524
|
+
* Options:
|
|
1525
|
+
*
|
|
1526
|
+
* - `maxAge` defaulting to 0 (can be string converted by `ms`)
|
|
1527
|
+
* - `root` root directory for relative filenames
|
|
1528
|
+
* - `headers` object of headers to serve with file
|
|
1529
|
+
* - `dotfiles` serve dotfiles, defaulting to false; can be `"allow"` to send them
|
|
1530
|
+
*
|
|
1531
|
+
* Other options are passed along to `send`.
|
|
1532
|
+
*
|
|
1533
|
+
* Examples:
|
|
1534
|
+
*
|
|
1535
|
+
* The following example illustrates how `res.sendFile()` may
|
|
1536
|
+
* be used as an alternative for the `static()` middleware for
|
|
1537
|
+
* dynamic situations. The code backing `res.sendFile()` is actually
|
|
1538
|
+
* the same code, so HTTP cache support etc is identical.
|
|
1539
|
+
*
|
|
1540
|
+
* app.get('/user/:uid/photos/:file', function(req, res){
|
|
1541
|
+
* var uid = req.params.uid
|
|
1542
|
+
* , file = req.params.file;
|
|
1543
|
+
*
|
|
1544
|
+
* req.user.mayViewFilesFrom(uid, function(yes){
|
|
1545
|
+
* if (yes) {
|
|
1546
|
+
* res.sendFile('/uploads/' + uid + '/' + file);
|
|
1547
|
+
* } else {
|
|
1548
|
+
* res.send(403, 'Sorry! you cant see that.');
|
|
1549
|
+
* }
|
|
1550
|
+
* });
|
|
1551
|
+
* });
|
|
1552
|
+
*
|
|
1553
|
+
* @api public
|
|
1554
|
+
*/
|
|
1555
|
+
sendFile(path: string, fn?: Errback): void;
|
|
1556
|
+
sendFile(path: string, options: SendFileOptions, fn?: Errback): void;
|
|
1557
|
+
/**
|
|
1558
|
+
* Transfer the file at the given `path` as an attachment.
|
|
1559
|
+
*
|
|
1560
|
+
* Optionally providing an alternate attachment `filename`,
|
|
1561
|
+
* and optional callback `fn(err)`. The callback is invoked
|
|
1562
|
+
* when the data transfer is complete, or when an error has
|
|
1563
|
+
* ocurred. Be sure to check `res.headersSent` if you plan to respond.
|
|
1564
|
+
*
|
|
1565
|
+
* The optional options argument passes through to the underlying
|
|
1566
|
+
* res.sendFile() call, and takes the exact same parameters.
|
|
1567
|
+
*
|
|
1568
|
+
* This method uses `res.sendFile()`.
|
|
1569
|
+
*/
|
|
1570
|
+
download(path: string, fn?: Errback): void;
|
|
1571
|
+
download(path: string, filename: string, fn?: Errback): void;
|
|
1572
|
+
download(path: string, filename: string, options: DownloadOptions, fn?: Errback): void;
|
|
1573
|
+
/**
|
|
1574
|
+
* Set _Content-Type_ response header with `type` through `mime.lookup()`
|
|
1575
|
+
* when it does not contain "/", or set the Content-Type to `type` otherwise.
|
|
1576
|
+
*
|
|
1577
|
+
* Examples:
|
|
1578
|
+
*
|
|
1579
|
+
* res.type('.html');
|
|
1580
|
+
* res.type('html');
|
|
1581
|
+
* res.type('json');
|
|
1582
|
+
* res.type('application/json');
|
|
1583
|
+
* res.type('png');
|
|
1584
|
+
*/
|
|
1585
|
+
contentType(type: string): this;
|
|
1586
|
+
/**
|
|
1587
|
+
* Set _Content-Type_ response header with `type` through `mime.lookup()`
|
|
1588
|
+
* when it does not contain "/", or set the Content-Type to `type` otherwise.
|
|
1589
|
+
*
|
|
1590
|
+
* Examples:
|
|
1591
|
+
*
|
|
1592
|
+
* res.type('.html');
|
|
1593
|
+
* res.type('html');
|
|
1594
|
+
* res.type('json');
|
|
1595
|
+
* res.type('application/json');
|
|
1596
|
+
* res.type('png');
|
|
1597
|
+
*/
|
|
1598
|
+
type(type: string): this;
|
|
1599
|
+
/**
|
|
1600
|
+
* Respond to the Acceptable formats using an `obj`
|
|
1601
|
+
* of mime-type callbacks.
|
|
1602
|
+
*
|
|
1603
|
+
* This method uses `req.accepted`, an array of
|
|
1604
|
+
* acceptable types ordered by their quality values.
|
|
1605
|
+
* When "Accept" is not present the _first_ callback
|
|
1606
|
+
* is invoked, otherwise the first match is used. When
|
|
1607
|
+
* no match is performed the server responds with
|
|
1608
|
+
* 406 "Not Acceptable".
|
|
1609
|
+
*
|
|
1610
|
+
* Content-Type is set for you, however if you choose
|
|
1611
|
+
* you may alter this within the callback using `res.type()`
|
|
1612
|
+
* or `res.set('Content-Type', ...)`.
|
|
1613
|
+
*
|
|
1614
|
+
* res.format({
|
|
1615
|
+
* 'text/plain': function(){
|
|
1616
|
+
* res.send('hey');
|
|
1617
|
+
* },
|
|
1618
|
+
*
|
|
1619
|
+
* 'text/html': function(){
|
|
1620
|
+
* res.send('<p>hey</p>');
|
|
1621
|
+
* },
|
|
1622
|
+
*
|
|
1623
|
+
* 'appliation/json': function(){
|
|
1624
|
+
* res.send({ message: 'hey' });
|
|
1625
|
+
* }
|
|
1626
|
+
* });
|
|
1627
|
+
*
|
|
1628
|
+
* In addition to canonicalized MIME types you may
|
|
1629
|
+
* also use extnames mapped to these types:
|
|
1630
|
+
*
|
|
1631
|
+
* res.format({
|
|
1632
|
+
* text: function(){
|
|
1633
|
+
* res.send('hey');
|
|
1634
|
+
* },
|
|
1635
|
+
*
|
|
1636
|
+
* html: function(){
|
|
1637
|
+
* res.send('<p>hey</p>');
|
|
1638
|
+
* },
|
|
1639
|
+
*
|
|
1640
|
+
* json: function(){
|
|
1641
|
+
* res.send({ message: 'hey' });
|
|
1642
|
+
* }
|
|
1643
|
+
* });
|
|
1644
|
+
*
|
|
1645
|
+
* By default Express passes an `Error`
|
|
1646
|
+
* with a `.status` of 406 to `next(err)`
|
|
1647
|
+
* if a match is not made. If you provide
|
|
1648
|
+
* a `.default` callback it will be invoked
|
|
1649
|
+
* instead.
|
|
1650
|
+
*/
|
|
1651
|
+
format(obj: any): this;
|
|
1652
|
+
/**
|
|
1653
|
+
* Set _Content-Disposition_ header to _attachment_ with optional `filename`.
|
|
1654
|
+
*/
|
|
1655
|
+
attachment(filename?: string): this;
|
|
1656
|
+
/**
|
|
1657
|
+
* Set header `field` to `val`, or pass
|
|
1658
|
+
* an object of header fields.
|
|
1659
|
+
*
|
|
1660
|
+
* Examples:
|
|
1661
|
+
*
|
|
1662
|
+
* res.set('Foo', ['bar', 'baz']);
|
|
1663
|
+
* res.set('Accept', 'application/json');
|
|
1664
|
+
* res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
|
|
1665
|
+
*
|
|
1666
|
+
* Aliased as `res.header()`.
|
|
1667
|
+
*/
|
|
1668
|
+
set(field: any): this;
|
|
1669
|
+
set(field: string, value?: string | string[]): this;
|
|
1670
|
+
header(field: any): this;
|
|
1671
|
+
header(field: string, value?: string | string[]): this;
|
|
1672
|
+
// Property indicating if HTTP headers has been sent for the response.
|
|
1673
|
+
headersSent: boolean;
|
|
1674
|
+
/** Get value for header `field`. */
|
|
1675
|
+
get(field: string): string | undefined;
|
|
1676
|
+
/** Clear cookie `name`. */
|
|
1677
|
+
clearCookie(name: string, options?: CookieOptions): this;
|
|
1678
|
+
/**
|
|
1679
|
+
* Set cookie `name` to `val`, with the given `options`.
|
|
1680
|
+
*
|
|
1681
|
+
* Options:
|
|
1682
|
+
*
|
|
1683
|
+
* - `maxAge` max-age in milliseconds, converted to `expires`
|
|
1684
|
+
* - `signed` sign the cookie
|
|
1685
|
+
* - `path` defaults to "/"
|
|
1686
|
+
*
|
|
1687
|
+
* Examples:
|
|
1688
|
+
*
|
|
1689
|
+
* // "Remember Me" for 15 minutes
|
|
1690
|
+
* res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });
|
|
1691
|
+
*
|
|
1692
|
+
* // save as above
|
|
1693
|
+
* res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })
|
|
1694
|
+
*/
|
|
1695
|
+
cookie(name: string, val: string, options: CookieOptions): this;
|
|
1696
|
+
cookie(name: string, val: any, options: CookieOptions): this;
|
|
1697
|
+
cookie(name: string, val: any): this;
|
|
1698
|
+
/**
|
|
1699
|
+
* Set the location header to `url`.
|
|
1700
|
+
*
|
|
1701
|
+
* Examples:
|
|
1702
|
+
*
|
|
1703
|
+
* res.location('/foo/bar').;
|
|
1704
|
+
* res.location('http://example.com');
|
|
1705
|
+
* res.location('../login'); // /blog/post/1 -> /blog/login
|
|
1706
|
+
*
|
|
1707
|
+
* Mounting:
|
|
1708
|
+
*
|
|
1709
|
+
* When an application is mounted and `res.location()`
|
|
1710
|
+
* is given a path that does _not_ lead with "/" it becomes
|
|
1711
|
+
* relative to the mount-point. For example if the application
|
|
1712
|
+
* is mounted at "/blog", the following would become "/blog/login".
|
|
1713
|
+
*
|
|
1714
|
+
* res.location('login');
|
|
1715
|
+
*
|
|
1716
|
+
* While the leading slash would result in a location of "/login":
|
|
1717
|
+
*
|
|
1718
|
+
* res.location('/login');
|
|
1719
|
+
*/
|
|
1720
|
+
location(url: string): this;
|
|
1721
|
+
/**
|
|
1722
|
+
* Redirect to the given `url` with optional response `status`
|
|
1723
|
+
* defaulting to 302.
|
|
1724
|
+
*
|
|
1725
|
+
* The resulting `url` is determined by `res.location()`, so
|
|
1726
|
+
* it will play nicely with mounted apps, relative paths, etc.
|
|
1727
|
+
*
|
|
1728
|
+
* Examples:
|
|
1729
|
+
*
|
|
1730
|
+
* res.redirect('/foo/bar');
|
|
1731
|
+
* res.redirect('http://example.com');
|
|
1732
|
+
* res.redirect(301, 'http://example.com');
|
|
1733
|
+
* res.redirect('../login'); // /blog/post/1 -> /blog/login
|
|
1734
|
+
*/
|
|
1735
|
+
redirect(url: string): void;
|
|
1736
|
+
redirect(status: number, url: string): void;
|
|
1737
|
+
/**
|
|
1738
|
+
* Render `view` with the given `options` and optional callback `fn`.
|
|
1739
|
+
* When a callback function is given a response will _not_ be made
|
|
1740
|
+
* automatically, otherwise a response of _200_ and _text/html_ is given.
|
|
1741
|
+
*
|
|
1742
|
+
* Options:
|
|
1743
|
+
*
|
|
1744
|
+
* - `cache` boolean hinting to the engine it should cache
|
|
1745
|
+
* - `filename` filename of the view being rendered
|
|
1746
|
+
*/
|
|
1747
|
+
render(view: string, options?: object, callback?: (err: Error, html: string) => void): void;
|
|
1748
|
+
render(view: string, callback?: (err: Error, html: string) => void): void;
|
|
1749
|
+
locals: LocalsObj & Locals;
|
|
1750
|
+
charset: string;
|
|
1751
|
+
/**
|
|
1752
|
+
* Adds the field to the Vary response header, if it is not there already.
|
|
1753
|
+
* Examples:
|
|
1754
|
+
*
|
|
1755
|
+
* res.vary('User-Agent').render('docs');
|
|
1756
|
+
*/
|
|
1757
|
+
vary(field: string): this;
|
|
1758
|
+
app: Application;
|
|
1759
|
+
/**
|
|
1760
|
+
* Appends the specified value to the HTTP response header field.
|
|
1761
|
+
* If the header is not already set, it creates the header with the specified value.
|
|
1762
|
+
* The value parameter can be a string or an array.
|
|
1763
|
+
*
|
|
1764
|
+
* Note: calling res.set() after res.append() will reset the previously-set header value.
|
|
1765
|
+
*
|
|
1766
|
+
* @since 4.11.0
|
|
1767
|
+
*/
|
|
1768
|
+
append(field: string, value?: string[] | string): this;
|
|
1769
|
+
/**
|
|
1770
|
+
* After middleware.init executed, Response will contain req property
|
|
1771
|
+
* See: express/lib/middleware/init.js
|
|
1772
|
+
*/
|
|
1773
|
+
req: Request;
|
|
1774
|
+
}
|
|
1775
|
+
type RequestParamHandler = (req: Request, res: Response$1, next: NextFunction, value: any, name: string) => any;
|
|
1776
|
+
type ApplicationRequestHandler<T> = IRouterHandler<T> & IRouterMatcher<T> & ((...handlers: RequestHandlerParams[]) => T);
|
|
1777
|
+
interface Application<LocalsObj extends Record<string, any> = Record<string, any>> extends EventEmitter, IRouter, Express.Application {
|
|
1778
|
+
/**
|
|
1779
|
+
* Express instance itself is a request handler, which could be invoked without
|
|
1780
|
+
* third argument.
|
|
1781
|
+
*/
|
|
1782
|
+
(req: Request | http.IncomingMessage, res: Response$1 | http.ServerResponse): any;
|
|
1783
|
+
/**
|
|
1784
|
+
* Initialize the server.
|
|
1785
|
+
*
|
|
1786
|
+
* - setup default configuration
|
|
1787
|
+
* - setup default middleware
|
|
1788
|
+
* - setup route reflection methods
|
|
1789
|
+
*/
|
|
1790
|
+
init(): void;
|
|
1791
|
+
/**
|
|
1792
|
+
* Initialize application configuration.
|
|
1793
|
+
*/
|
|
1794
|
+
defaultConfiguration(): void;
|
|
1795
|
+
/**
|
|
1796
|
+
* Register the given template engine callback `fn`
|
|
1797
|
+
* as `ext`.
|
|
1798
|
+
*
|
|
1799
|
+
* By default will `require()` the engine based on the
|
|
1800
|
+
* file extension. For example if you try to render
|
|
1801
|
+
* a "foo.jade" file Express will invoke the following internally:
|
|
1802
|
+
*
|
|
1803
|
+
* app.engine('jade', require('jade').__express);
|
|
1804
|
+
*
|
|
1805
|
+
* For engines that do not provide `.__express` out of the box,
|
|
1806
|
+
* or if you wish to "map" a different extension to the template engine
|
|
1807
|
+
* you may use this method. For example mapping the EJS template engine to
|
|
1808
|
+
* ".html" files:
|
|
1809
|
+
*
|
|
1810
|
+
* app.engine('html', require('ejs').renderFile);
|
|
1811
|
+
*
|
|
1812
|
+
* In this case EJS provides a `.renderFile()` method with
|
|
1813
|
+
* the same signature that Express expects: `(path, options, callback)`,
|
|
1814
|
+
* though note that it aliases this method as `ejs.__express` internally
|
|
1815
|
+
* so if you're using ".ejs" extensions you dont need to do anything.
|
|
1816
|
+
*
|
|
1817
|
+
* Some template engines do not follow this convention, the
|
|
1818
|
+
* [Consolidate.js](https://github.com/visionmedia/consolidate.js)
|
|
1819
|
+
* library was created to map all of node's popular template
|
|
1820
|
+
* engines to follow this convention, thus allowing them to
|
|
1821
|
+
* work seamlessly within Express.
|
|
1822
|
+
*/
|
|
1823
|
+
engine(ext: string, fn: (path: string, options: object, callback: (e: any, rendered?: string) => void) => void): this;
|
|
1824
|
+
/**
|
|
1825
|
+
* Assign `setting` to `val`, or return `setting`'s value.
|
|
1826
|
+
*
|
|
1827
|
+
* app.set('foo', 'bar');
|
|
1828
|
+
* app.get('foo');
|
|
1829
|
+
* // => "bar"
|
|
1830
|
+
* app.set('foo', ['bar', 'baz']);
|
|
1831
|
+
* app.get('foo');
|
|
1832
|
+
* // => ["bar", "baz"]
|
|
1833
|
+
*
|
|
1834
|
+
* Mounted servers inherit their parent server's settings.
|
|
1835
|
+
*/
|
|
1836
|
+
set(setting: string, val: any): this;
|
|
1837
|
+
get: ((name: string) => any) & IRouterMatcher<this>;
|
|
1838
|
+
param(name: string | string[], handler: RequestParamHandler): this;
|
|
1839
|
+
/**
|
|
1840
|
+
* Return the app's absolute pathname
|
|
1841
|
+
* based on the parent(s) that have
|
|
1842
|
+
* mounted it.
|
|
1843
|
+
*
|
|
1844
|
+
* For example if the application was
|
|
1845
|
+
* mounted as "/admin", which itself
|
|
1846
|
+
* was mounted as "/blog" then the
|
|
1847
|
+
* return value would be "/blog/admin".
|
|
1848
|
+
*/
|
|
1849
|
+
path(): string;
|
|
1850
|
+
/**
|
|
1851
|
+
* Check if `setting` is enabled (truthy).
|
|
1852
|
+
*
|
|
1853
|
+
* app.enabled('foo')
|
|
1854
|
+
* // => false
|
|
1855
|
+
*
|
|
1856
|
+
* app.enable('foo')
|
|
1857
|
+
* app.enabled('foo')
|
|
1858
|
+
* // => true
|
|
1859
|
+
*/
|
|
1860
|
+
enabled(setting: string): boolean;
|
|
1861
|
+
/**
|
|
1862
|
+
* Check if `setting` is disabled.
|
|
1863
|
+
*
|
|
1864
|
+
* app.disabled('foo')
|
|
1865
|
+
* // => true
|
|
1866
|
+
*
|
|
1867
|
+
* app.enable('foo')
|
|
1868
|
+
* app.disabled('foo')
|
|
1869
|
+
* // => false
|
|
1870
|
+
*/
|
|
1871
|
+
disabled(setting: string): boolean;
|
|
1872
|
+
/** Enable `setting`. */
|
|
1873
|
+
enable(setting: string): this;
|
|
1874
|
+
/** Disable `setting`. */
|
|
1875
|
+
disable(setting: string): this;
|
|
1876
|
+
/**
|
|
1877
|
+
* Render the given view `name` name with `options`
|
|
1878
|
+
* and a callback accepting an error and the
|
|
1879
|
+
* rendered template string.
|
|
1880
|
+
*
|
|
1881
|
+
* Example:
|
|
1882
|
+
*
|
|
1883
|
+
* app.render('email', { name: 'Tobi' }, function(err, html){
|
|
1884
|
+
* // ...
|
|
1885
|
+
* })
|
|
1886
|
+
*/
|
|
1887
|
+
render(name: string, options?: object, callback?: (err: Error, html: string) => void): void;
|
|
1888
|
+
render(name: string, callback: (err: Error, html: string) => void): void;
|
|
1889
|
+
/**
|
|
1890
|
+
* Listen for connections.
|
|
1891
|
+
*
|
|
1892
|
+
* A node `http.Server` is returned, with this
|
|
1893
|
+
* application (which is a `Function`) as its
|
|
1894
|
+
* callback. If you wish to create both an HTTP
|
|
1895
|
+
* and HTTPS server you may do so with the "http"
|
|
1896
|
+
* and "https" modules as shown here:
|
|
1897
|
+
*
|
|
1898
|
+
* var http = require('http')
|
|
1899
|
+
* , https = require('https')
|
|
1900
|
+
* , express = require('express')
|
|
1901
|
+
* , app = express();
|
|
1902
|
+
*
|
|
1903
|
+
* http.createServer(app).listen(80);
|
|
1904
|
+
* https.createServer({ ... }, app).listen(443);
|
|
1905
|
+
*/
|
|
1906
|
+
listen(port: number, hostname: string, backlog: number, callback?: (error?: Error) => void): http.Server;
|
|
1907
|
+
listen(port: number, hostname: string, callback?: (error?: Error) => void): http.Server;
|
|
1908
|
+
listen(port: number, callback?: (error?: Error) => void): http.Server;
|
|
1909
|
+
listen(callback?: (error?: Error) => void): http.Server;
|
|
1910
|
+
listen(path: string, callback?: (error?: Error) => void): http.Server;
|
|
1911
|
+
listen(handle: any, listeningListener?: (error?: Error) => void): http.Server;
|
|
1912
|
+
router: Router;
|
|
1913
|
+
settings: any;
|
|
1914
|
+
resource: any;
|
|
1915
|
+
map: any;
|
|
1916
|
+
locals: LocalsObj & Locals;
|
|
1917
|
+
/**
|
|
1918
|
+
* The app.routes object houses all of the routes defined mapped by the
|
|
1919
|
+
* associated HTTP verb. This object may be used for introspection
|
|
1920
|
+
* capabilities, for example Express uses this internally not only for
|
|
1921
|
+
* routing but to provide default OPTIONS behaviour unless app.options()
|
|
1922
|
+
* is used. Your application or framework may also remove routes by
|
|
1923
|
+
* simply by removing them from this object.
|
|
1924
|
+
*/
|
|
1925
|
+
routes: any;
|
|
1926
|
+
/**
|
|
1927
|
+
* Used to get all registered routes in Express Application
|
|
1928
|
+
*/
|
|
1929
|
+
_router: any;
|
|
1930
|
+
use: ApplicationRequestHandler<this>;
|
|
1931
|
+
/**
|
|
1932
|
+
* The mount event is fired on a sub-app, when it is mounted on a parent app.
|
|
1933
|
+
* The parent app is passed to the callback function.
|
|
1934
|
+
*
|
|
1935
|
+
* NOTE:
|
|
1936
|
+
* Sub-apps will:
|
|
1937
|
+
* - Not inherit the value of settings that have a default value. You must set the value in the sub-app.
|
|
1938
|
+
* - Inherit the value of settings with no default value.
|
|
1939
|
+
*/
|
|
1940
|
+
on: (event: "mount", callback: (parent: Application) => void) => this;
|
|
1941
|
+
/**
|
|
1942
|
+
* The app.mountpath property contains one or more path patterns on which a sub-app was mounted.
|
|
1943
|
+
*/
|
|
1944
|
+
mountpath: string | string[];
|
|
1945
|
+
}
|
|
1946
|
+
interface Express extends Application {
|
|
1947
|
+
request: Request;
|
|
1948
|
+
response: Response$1;
|
|
1949
|
+
}
|
|
263
1950
|
//#endregion
|
|
264
1951
|
//#region src/server/event-handler/enum/mqtt-error-codes/mqtt-disconnect-reason-code.d.ts
|
|
265
1952
|
/**
|
|
266
|
-
* MQTT 5.0 Disconnect Reason Codes.
|
|
267
|
-
*/
|
|
1953
|
+
* MQTT 5.0 Disconnect Reason Codes.
|
|
1954
|
+
*/
|
|
268
1955
|
declare enum MqttDisconnectReasonCode {
|
|
269
1956
|
/**
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
1957
|
+
* 0x00 - Normal disconnection
|
|
1958
|
+
* Sent by: Client or Server
|
|
1959
|
+
* Description: Close the connection normally. Do not send the Will Message.
|
|
1960
|
+
*/
|
|
274
1961
|
NormalDisconnection = 0,
|
|
275
1962
|
/**
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
1963
|
+
* 0x04 - Disconnect with Will Message
|
|
1964
|
+
* Sent by: Client
|
|
1965
|
+
* Description: The Client wishes to disconnect but requires that the Server also publishes its Will Message.
|
|
1966
|
+
*/
|
|
280
1967
|
DisconnectWithWillMessage = 4,
|
|
281
1968
|
/**
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
1969
|
+
* 0x80 - Unspecified error
|
|
1970
|
+
* Sent by: Client or Server
|
|
1971
|
+
* Description: The Connection is closed but the sender either does not wish to reveal the reason, or none of the other Reason Codes apply.
|
|
1972
|
+
*/
|
|
286
1973
|
UnspecifiedError = 128,
|
|
287
1974
|
/**
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
1975
|
+
* 0x81 - Malformed Packet
|
|
1976
|
+
* Sent by: Client or Server
|
|
1977
|
+
* Description: The received packet does not conform to this specification.
|
|
1978
|
+
*/
|
|
292
1979
|
MalformedPacket = 129,
|
|
293
1980
|
/**
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
1981
|
+
* 0x82 - Protocol Error
|
|
1982
|
+
* Sent by: Client or Server
|
|
1983
|
+
* Description: An unexpected or out of order packet was received.
|
|
1984
|
+
*/
|
|
298
1985
|
ProtocolError = 130,
|
|
299
1986
|
/**
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
1987
|
+
* 0x83 - Implementation specific error
|
|
1988
|
+
* Sent by: Client or Server
|
|
1989
|
+
* Description: The packet received is valid but cannot be processed by this implementation.
|
|
1990
|
+
*/
|
|
304
1991
|
ImplementationSpecificError = 131,
|
|
305
1992
|
/**
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
1993
|
+
* 0x87 - Not authorized
|
|
1994
|
+
* Sent by: Server
|
|
1995
|
+
* Description: The request is not authorized.
|
|
1996
|
+
*/
|
|
310
1997
|
NotAuthorized = 135,
|
|
311
1998
|
/**
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
1999
|
+
* 0x89 - Server busy
|
|
2000
|
+
* Sent by: Server
|
|
2001
|
+
* Description: The Server is busy and cannot continue processing requests from this Client.
|
|
2002
|
+
*/
|
|
316
2003
|
ServerBusy = 137,
|
|
317
2004
|
/**
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
2005
|
+
* 0x8B - Server shutting down
|
|
2006
|
+
* Sent by: Server
|
|
2007
|
+
* Description: The Server is shutting down.
|
|
2008
|
+
*/
|
|
322
2009
|
ServerShuttingDown = 139,
|
|
323
2010
|
/**
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
2011
|
+
* 0x8D - Keep Alive timeout
|
|
2012
|
+
* Sent by: Server
|
|
2013
|
+
* Description: The Connection is closed because no packet has been received for 1.5 times the Keepalive time.
|
|
2014
|
+
*/
|
|
328
2015
|
KeepAliveTimeout = 141,
|
|
329
2016
|
/**
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
2017
|
+
* 0x8E - Session taken over
|
|
2018
|
+
* Sent by: Server
|
|
2019
|
+
* Description: Another Connection using the same ClientID has connected causing this Connection to be closed.
|
|
2020
|
+
*/
|
|
334
2021
|
SessionTakenOver = 142,
|
|
335
2022
|
/**
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
2023
|
+
* 0x8F - Topic Filter invalid
|
|
2024
|
+
* Sent by: Server
|
|
2025
|
+
* Description: The Topic Filter is correctly formed, but is not accepted by this Server.
|
|
2026
|
+
*/
|
|
340
2027
|
TopicFilterInvalid = 143,
|
|
341
2028
|
/**
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
2029
|
+
* 0x90 - Topic Name invalid
|
|
2030
|
+
* Sent by: Client or Server
|
|
2031
|
+
* Description: The Topic Name is correctly formed, but is not accepted by this Client or Server.
|
|
2032
|
+
*/
|
|
346
2033
|
TopicNameInvalid = 144,
|
|
347
2034
|
/**
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
2035
|
+
* 0x93 - Receive Maximum exceeded
|
|
2036
|
+
* Sent by: Client or Server
|
|
2037
|
+
* Description: The Client or Server has received more than Receive Maximum publication for which it has not sent PUBACK or PUBCOMP.
|
|
2038
|
+
*/
|
|
352
2039
|
ReceiveMaximumExceeded = 147,
|
|
353
2040
|
/**
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
2041
|
+
* 0x94 - Topic Alias invalid
|
|
2042
|
+
* Sent by: Client or Server
|
|
2043
|
+
* Description: The Client or Server has received a PUBLISH packet containing a Topic Alias which is greater than the Maximum Topic Alias it sent in the CONNECT or CONNACK packet.
|
|
2044
|
+
*/
|
|
358
2045
|
TopicAliasInvalid = 148,
|
|
359
2046
|
/**
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
2047
|
+
* 0x95 - Packet too large
|
|
2048
|
+
* Sent by: Client or Server
|
|
2049
|
+
* Description: The packet size is greater than Maximum Packet Size for this Client or Server.
|
|
2050
|
+
*/
|
|
364
2051
|
PacketTooLarge = 149,
|
|
365
2052
|
/**
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
2053
|
+
* 0x96 - Message rate too high
|
|
2054
|
+
* Sent by: Client or Server
|
|
2055
|
+
* Description: The received data rate is too high.
|
|
2056
|
+
*/
|
|
370
2057
|
MessageRateTooHigh = 150,
|
|
371
2058
|
/**
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
2059
|
+
* 0x97 - Quota exceeded
|
|
2060
|
+
* Sent by: Client or Server
|
|
2061
|
+
* Description: An implementation or administrative imposed limit has been exceeded.
|
|
2062
|
+
*/
|
|
376
2063
|
QuotaExceeded = 151,
|
|
377
2064
|
/**
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
2065
|
+
* 0x98 - Administrative action
|
|
2066
|
+
* Sent by: Client or Server
|
|
2067
|
+
* Description: The Connection is closed due to an administrative action.
|
|
2068
|
+
*/
|
|
382
2069
|
AdministrativeAction = 152,
|
|
383
2070
|
/**
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
2071
|
+
* 0x99 - Payload format invalid
|
|
2072
|
+
* Sent by: Client or Server
|
|
2073
|
+
* Description: The payload format does not match the one specified by the Payload Format Indicator.
|
|
2074
|
+
*/
|
|
388
2075
|
PayloadFormatInvalid = 153,
|
|
389
2076
|
/**
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
2077
|
+
* 0x9A - Retain not supported
|
|
2078
|
+
* Sent by: Server
|
|
2079
|
+
* Description: The Server does not support retained messages.
|
|
2080
|
+
*/
|
|
394
2081
|
RetainNotSupported = 154,
|
|
395
2082
|
/**
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
2083
|
+
* 0x9B - QoS not supported
|
|
2084
|
+
* Sent by: Server
|
|
2085
|
+
* Description: The Client specified a QoS greater than the QoS specified in a Maximum QoS in the CONNACK.
|
|
2086
|
+
*/
|
|
400
2087
|
QosNotSupported = 155,
|
|
401
2088
|
/**
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
2089
|
+
* 0x9C - Use another server
|
|
2090
|
+
* Sent by: Server
|
|
2091
|
+
* Description: The Client should temporarily change its Server.
|
|
2092
|
+
*/
|
|
406
2093
|
UseAnotherServer = 156,
|
|
407
2094
|
/**
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
2095
|
+
* 0x9D - Server moved
|
|
2096
|
+
* Sent by: Server
|
|
2097
|
+
* Description: The Server is moved and the Client should permanently change its server location.
|
|
2098
|
+
*/
|
|
412
2099
|
ServerMoved = 157,
|
|
413
2100
|
/**
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
2101
|
+
* 0x9E - Shared Subscriptions not supported
|
|
2102
|
+
* Sent by: Server
|
|
2103
|
+
* Description: The Server does not support Shared Subscriptions.
|
|
2104
|
+
*/
|
|
418
2105
|
SharedSubscriptionsNotSupported = 158,
|
|
419
2106
|
/**
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
2107
|
+
* 0x9F - Connection rate exceeded
|
|
2108
|
+
* Sent by: Server
|
|
2109
|
+
* Description: This connection is closed because the connection rate is too high.
|
|
2110
|
+
*/
|
|
424
2111
|
ConnectionRateExceeded = 159,
|
|
425
2112
|
/**
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
2113
|
+
* 0xA0 - Maximum connect time
|
|
2114
|
+
* Sent by: Server
|
|
2115
|
+
* Description: The maximum connection time authorized for this connection has been exceeded.
|
|
2116
|
+
*/
|
|
430
2117
|
MaximumConnectTime = 160,
|
|
431
2118
|
/**
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
2119
|
+
* 0xA1 - Subscription Identifiers not supported
|
|
2120
|
+
* Sent by: Server
|
|
2121
|
+
* Description: The Server does not support Subscription Identifiers; the subscription is not accepted.
|
|
2122
|
+
*/
|
|
436
2123
|
SubscriptionIdentifiersNotSupported = 161,
|
|
437
2124
|
/**
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
WildcardSubscriptionsNotSupported = 162
|
|
2125
|
+
* 0xA2 - Wildcard Subscriptions not supported
|
|
2126
|
+
* Sent by: Server
|
|
2127
|
+
* Description: The Server does not support Wildcard Subscriptions; the subscription is not accepted.
|
|
2128
|
+
*/
|
|
2129
|
+
WildcardSubscriptionsNotSupported = 162
|
|
443
2130
|
}
|
|
444
|
-
|
|
445
2131
|
//#endregion
|
|
446
2132
|
//#region src/server/event-handler/enum/mqtt-error-codes/mqtt-v311-connect-return-code.d.ts
|
|
447
2133
|
/**
|
|
448
|
-
* MQTT 3.1.1 Connect Return Codes.
|
|
449
|
-
*/
|
|
2134
|
+
* MQTT 3.1.1 Connect Return Codes.
|
|
2135
|
+
*/
|
|
450
2136
|
declare enum MqttV311ConnectReturnCode {
|
|
451
2137
|
/**
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
2138
|
+
* 0x01: Connection refused, unacceptable protocol version
|
|
2139
|
+
* The Server does not support the level of the MQTT protocol requested by the Client.
|
|
2140
|
+
*/
|
|
455
2141
|
UnacceptableProtocolVersion = 1,
|
|
456
2142
|
/**
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
2143
|
+
* 0x02: Connection refused, identifier rejected
|
|
2144
|
+
* The Client identifier is correct UTF-8 but not allowed by the Server.
|
|
2145
|
+
*/
|
|
460
2146
|
IdentifierRejected = 2,
|
|
461
2147
|
/**
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
2148
|
+
* 0x03: Connection refused, server unavailable
|
|
2149
|
+
* The Network Connection has been made but the MQTT service is unavailable.
|
|
2150
|
+
*/
|
|
465
2151
|
ServerUnavailable = 3,
|
|
466
2152
|
/**
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
2153
|
+
* 0x04: Connection refused, bad user name or password
|
|
2154
|
+
* The data in the user name or password is malformed.
|
|
2155
|
+
*/
|
|
470
2156
|
BadUsernameOrPassword = 4,
|
|
471
2157
|
/**
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
NotAuthorized = 5
|
|
2158
|
+
* 0x05: Connection refused, not authorized
|
|
2159
|
+
* The Client is not authorized to connect.
|
|
2160
|
+
*/
|
|
2161
|
+
NotAuthorized = 5
|
|
476
2162
|
}
|
|
477
|
-
|
|
478
2163
|
//#endregion
|
|
479
2164
|
//#region src/server/event-handler/enum/mqtt-error-codes/mqtt-v500-connect-reason-code.d.ts
|
|
480
2165
|
/**
|
|
481
|
-
* MQTT Connect Reason Codes
|
|
482
|
-
* These codes represent the reasons for the outcome of an MQTT CONNECT packet as per MQTT 5.0 specification.
|
|
483
|
-
*/
|
|
2166
|
+
* MQTT Connect Reason Codes
|
|
2167
|
+
* These codes represent the reasons for the outcome of an MQTT CONNECT packet as per MQTT 5.0 specification.
|
|
2168
|
+
*/
|
|
484
2169
|
declare enum MqttV500ConnectReasonCode {
|
|
485
2170
|
/**
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
2171
|
+
* 0x80 - Unspecified error
|
|
2172
|
+
* Description: The Server does not wish to reveal the reason for the failure, or none of the other Reason Codes apply.
|
|
2173
|
+
*/
|
|
489
2174
|
UnspecifiedError = 128,
|
|
490
2175
|
/**
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
2176
|
+
* 0x81 - Malformed Packet
|
|
2177
|
+
* Description: Data within the CONNECT packet could not be correctly parsed.
|
|
2178
|
+
*/
|
|
494
2179
|
MalformedPacket = 129,
|
|
495
2180
|
/**
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
2181
|
+
* 0x82 - Protocol Error
|
|
2182
|
+
* Description: Data in the CONNECT packet does not conform to this specification.
|
|
2183
|
+
*/
|
|
499
2184
|
ProtocolError = 130,
|
|
500
2185
|
/**
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
2186
|
+
* 0x83 - Implementation specific error
|
|
2187
|
+
* Description: The CONNECT is valid but is not accepted by this Server.
|
|
2188
|
+
*/
|
|
504
2189
|
ImplementationSpecificError = 131,
|
|
505
2190
|
/**
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
2191
|
+
* 0x84 - Unsupported Protocol Version
|
|
2192
|
+
* Description: The Server does not support the version of the MQTT protocol requested by the Client.
|
|
2193
|
+
*/
|
|
509
2194
|
UnsupportedProtocolVersion = 132,
|
|
510
2195
|
/**
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
2196
|
+
* 0x85 - Client Identifier not valid
|
|
2197
|
+
* Description: The Client Identifier is a valid string but is not allowed by the Server.
|
|
2198
|
+
*/
|
|
514
2199
|
ClientIdentifierNotValid = 133,
|
|
515
2200
|
/**
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
2201
|
+
* 0x86 - Bad User Name or Password
|
|
2202
|
+
* Description: The Server does not accept the User Name or Password specified by the Client.
|
|
2203
|
+
*/
|
|
519
2204
|
BadUserNameOrPassword = 134,
|
|
520
2205
|
/**
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
2206
|
+
* 0x87 - Not authorized
|
|
2207
|
+
* Description: The Client is not authorized to connect.
|
|
2208
|
+
*/
|
|
524
2209
|
NotAuthorized = 135,
|
|
525
2210
|
/**
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
2211
|
+
* 0x88 - Server unavailable
|
|
2212
|
+
* Description: The MQTT Server is not available.
|
|
2213
|
+
*/
|
|
529
2214
|
ServerUnavailable = 136,
|
|
530
2215
|
/**
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
2216
|
+
* 0x89 - Server busy
|
|
2217
|
+
* Description: The Server is busy. Try again later.
|
|
2218
|
+
*/
|
|
534
2219
|
ServerBusy = 137,
|
|
535
2220
|
/**
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
2221
|
+
* 0x8A - Banned
|
|
2222
|
+
* Description: This Client has been banned by administrative action. Contact the server administrator.
|
|
2223
|
+
*/
|
|
539
2224
|
Banned = 138,
|
|
540
2225
|
/**
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
2226
|
+
* 0x8C - Bad authentication method
|
|
2227
|
+
* Description: The authentication method is not supported or does not match the authentication method currently in use.
|
|
2228
|
+
*/
|
|
544
2229
|
BadAuthenticationMethod = 140,
|
|
545
2230
|
/**
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
2231
|
+
* 0x90 - Topic Name invalid
|
|
2232
|
+
* Description: The Will Topic Name is not malformed, but is not accepted by this Server.
|
|
2233
|
+
*/
|
|
549
2234
|
TopicNameInvalid = 144,
|
|
550
2235
|
/**
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
2236
|
+
* 0x95 - Packet too large
|
|
2237
|
+
* Description: The CONNECT packet exceeded the maximum permissible size.
|
|
2238
|
+
*/
|
|
554
2239
|
PacketTooLarge = 149,
|
|
555
2240
|
/**
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
2241
|
+
* 0x97 - Quota exceeded
|
|
2242
|
+
* Description: An implementation or administrative imposed limit has been exceeded.
|
|
2243
|
+
*/
|
|
559
2244
|
QuotaExceeded = 151,
|
|
560
2245
|
/**
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
2246
|
+
* 0x99 - Payload format invalid
|
|
2247
|
+
* Description: The Will Payload does not match the specified Payload Format Indicator.
|
|
2248
|
+
*/
|
|
564
2249
|
PayloadFormatInvalid = 153,
|
|
565
2250
|
/**
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
2251
|
+
* 0x9A - Retain not supported
|
|
2252
|
+
* Description: The Server does not support retained messages, and Will Retain was set to 1.
|
|
2253
|
+
*/
|
|
569
2254
|
RetainNotSupported = 154,
|
|
570
2255
|
/**
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
2256
|
+
* 0x9B - QoS not supported
|
|
2257
|
+
* Description: The Server does not support the QoS set in Will QoS.
|
|
2258
|
+
*/
|
|
574
2259
|
QosNotSupported = 155,
|
|
575
2260
|
/**
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
2261
|
+
* 0x9C - Use another server
|
|
2262
|
+
* Description: The Client should temporarily use another server.
|
|
2263
|
+
*/
|
|
579
2264
|
UseAnotherServer = 156,
|
|
580
2265
|
/**
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
2266
|
+
* 0x9D - Server moved
|
|
2267
|
+
* Description: The Client should permanently use another server.
|
|
2268
|
+
*/
|
|
584
2269
|
ServerMoved = 157,
|
|
585
2270
|
/**
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
ConnectionRateExceeded = 159
|
|
2271
|
+
* 0x9F - Connection rate exceeded
|
|
2272
|
+
* Description: The connection rate limit has been exceeded.
|
|
2273
|
+
*/
|
|
2274
|
+
ConnectionRateExceeded = 159
|
|
590
2275
|
}
|
|
591
|
-
|
|
592
2276
|
//#endregion
|
|
593
2277
|
//#region src/server/event-handler/cloud-events-protocols.d.ts
|
|
594
2278
|
/**
|
|
595
|
-
* Response of the connect event.
|
|
596
|
-
*/
|
|
2279
|
+
* Response of the connect event.
|
|
2280
|
+
*/
|
|
597
2281
|
interface ConnectResponse {
|
|
598
2282
|
/**
|
|
599
|
-
|
|
600
|
-
|
|
2283
|
+
* Set the groups the connection would like to join.
|
|
2284
|
+
*/
|
|
601
2285
|
groups?: string[];
|
|
602
2286
|
/**
|
|
603
|
-
|
|
604
|
-
|
|
2287
|
+
* Set the roles the connection belongs to.
|
|
2288
|
+
*/
|
|
605
2289
|
roles?: string[];
|
|
606
2290
|
/**
|
|
607
|
-
|
|
608
|
-
|
|
2291
|
+
* Set the userId for the connection.
|
|
2292
|
+
*/
|
|
609
2293
|
userId?: string;
|
|
610
2294
|
/**
|
|
611
|
-
|
|
612
|
-
|
|
2295
|
+
* Set the subprotocol for the connection to complete WebSocket handshake.
|
|
2296
|
+
*/
|
|
613
2297
|
subprotocol?: string;
|
|
614
2298
|
}
|
|
615
2299
|
/**
|
|
616
|
-
* Success respones of the connect event.
|
|
617
|
-
*/
|
|
2300
|
+
* Success respones of the connect event.
|
|
2301
|
+
*/
|
|
618
2302
|
interface MqttConnectResponse extends ConnectResponse {
|
|
619
2303
|
/**
|
|
620
|
-
|
|
621
|
-
|
|
2304
|
+
* The MQTT specific properties in a successful MQTT connection event response.
|
|
2305
|
+
*/
|
|
622
2306
|
mqtt?: MqttConnectResponseProperties;
|
|
623
2307
|
}
|
|
624
2308
|
/**
|
|
625
|
-
* Response of a failed connect event.
|
|
626
|
-
*/
|
|
2309
|
+
* Response of a failed connect event.
|
|
2310
|
+
*/
|
|
627
2311
|
interface ConnectErrorResponse {
|
|
628
2312
|
/**
|
|
629
|
-
|
|
630
|
-
|
|
2313
|
+
* The error code.
|
|
2314
|
+
*/
|
|
631
2315
|
code: 400 | 401 | 500;
|
|
632
2316
|
/**
|
|
633
|
-
|
|
634
|
-
|
|
2317
|
+
* The error detail.
|
|
2318
|
+
*/
|
|
635
2319
|
detail?: string;
|
|
636
2320
|
}
|
|
637
2321
|
/**
|
|
638
|
-
* Response of an MQTT connection failure.
|
|
639
|
-
*/
|
|
2322
|
+
* Response of an MQTT connection failure.
|
|
2323
|
+
*/
|
|
640
2324
|
interface MqttConnectErrorResponse {
|
|
641
2325
|
/**
|
|
642
|
-
|
|
643
|
-
|
|
2326
|
+
* The properties of the MQTT connection failure response.
|
|
2327
|
+
*/
|
|
644
2328
|
mqtt: MqttConnectErrorResponseProperties;
|
|
645
2329
|
}
|
|
646
2330
|
/**
|
|
647
|
-
* The properties of an MQTT connection failure response.
|
|
648
|
-
*/
|
|
2331
|
+
* The properties of an MQTT connection failure response.
|
|
2332
|
+
*/
|
|
649
2333
|
interface MqttConnectErrorResponseProperties {
|
|
650
2334
|
/**
|
|
651
|
-
|
|
652
|
-
|
|
2335
|
+
* The MQTT connect return code.
|
|
2336
|
+
*/
|
|
653
2337
|
code: MqttV311ConnectReturnCode | MqttV500ConnectReasonCode;
|
|
654
2338
|
/**
|
|
655
|
-
|
|
656
|
-
|
|
2339
|
+
* The reason string for the connection failure.
|
|
2340
|
+
*/
|
|
657
2341
|
reason?: string;
|
|
658
2342
|
/**
|
|
659
|
-
|
|
660
|
-
|
|
2343
|
+
* The user properties in the response.
|
|
2344
|
+
*/
|
|
661
2345
|
userProperties?: MqttUserProperty[];
|
|
662
2346
|
}
|
|
663
2347
|
/**
|
|
664
|
-
* The protocol of Web PubSub Client.
|
|
665
|
-
*/
|
|
2348
|
+
* The protocol of Web PubSub Client.
|
|
2349
|
+
*/
|
|
666
2350
|
type WebPubSubClientProtocol = "default" | "mqtt";
|
|
667
2351
|
/**
|
|
668
|
-
* The connection context representing the client WebSocket connection.
|
|
669
|
-
*/
|
|
2352
|
+
* The connection context representing the client WebSocket connection.
|
|
2353
|
+
*/
|
|
670
2354
|
interface ConnectionContext {
|
|
671
2355
|
/**
|
|
672
|
-
|
|
673
|
-
|
|
2356
|
+
* The unique identifier generated by the service of the network connection.
|
|
2357
|
+
*/
|
|
674
2358
|
signature: string;
|
|
675
2359
|
/**
|
|
676
|
-
|
|
677
|
-
|
|
2360
|
+
* The hub the connection belongs to.
|
|
2361
|
+
*/
|
|
678
2362
|
hub: string;
|
|
679
2363
|
/**
|
|
680
|
-
|
|
681
|
-
|
|
2364
|
+
* The Id of the connection.
|
|
2365
|
+
*/
|
|
682
2366
|
connectionId: string;
|
|
683
2367
|
/**
|
|
684
|
-
|
|
685
|
-
|
|
2368
|
+
* The event name of this CloudEvents request.
|
|
2369
|
+
*/
|
|
686
2370
|
eventName: string;
|
|
687
2371
|
/**
|
|
688
|
-
|
|
689
|
-
|
|
2372
|
+
* The origin this CloudEvents request comes from.
|
|
2373
|
+
*/
|
|
690
2374
|
origin: string;
|
|
691
2375
|
/**
|
|
692
|
-
|
|
693
|
-
|
|
2376
|
+
* The user id of the connection.
|
|
2377
|
+
*/
|
|
694
2378
|
userId?: string;
|
|
695
2379
|
/**
|
|
696
|
-
|
|
697
|
-
|
|
2380
|
+
* The subprotocol of this connection.
|
|
2381
|
+
*/
|
|
698
2382
|
subprotocol?: string;
|
|
699
2383
|
/**
|
|
700
|
-
|
|
701
|
-
|
|
2384
|
+
* Get the additional states for the connection, such states are perserved throughout the lifetime of the connection.
|
|
2385
|
+
*/
|
|
702
2386
|
states: Record<string, any>;
|
|
703
2387
|
/**
|
|
704
|
-
|
|
705
|
-
|
|
2388
|
+
* The type of client protocol.
|
|
2389
|
+
*/
|
|
706
2390
|
clientProtocol: WebPubSubClientProtocol;
|
|
707
2391
|
/**
|
|
708
|
-
|
|
709
|
-
|
|
2392
|
+
* The MQTT properties that the client WebSocket connection has when it connects (For MQTT connection only).
|
|
2393
|
+
*/
|
|
710
2394
|
mqtt?: MqttConnectionContextProperties;
|
|
711
2395
|
}
|
|
712
2396
|
/**
|
|
713
|
-
* The connection context properties representing the MQTT client WebSocket connection.
|
|
714
|
-
*/
|
|
2397
|
+
* The connection context properties representing the MQTT client WebSocket connection.
|
|
2398
|
+
*/
|
|
715
2399
|
interface MqttConnectionContextProperties {
|
|
716
2400
|
/**
|
|
717
|
-
|
|
718
|
-
|
|
2401
|
+
* The unique identifier generated by the service of the network connection.
|
|
2402
|
+
*/
|
|
719
2403
|
physicalConnectionId: string;
|
|
720
2404
|
/**
|
|
721
|
-
|
|
722
|
-
|
|
2405
|
+
* The unique identifier generated by the service of the MQTT session.
|
|
2406
|
+
*/
|
|
723
2407
|
sessionId?: string;
|
|
724
2408
|
}
|
|
725
2409
|
/**
|
|
726
|
-
* Request for the connect event.
|
|
727
|
-
*/
|
|
2410
|
+
* Request for the connect event.
|
|
2411
|
+
*/
|
|
728
2412
|
interface ConnectRequest {
|
|
729
2413
|
/**
|
|
730
|
-
|
|
731
|
-
|
|
2414
|
+
* The context of current CloudEvents request.
|
|
2415
|
+
*/
|
|
732
2416
|
context: ConnectionContext;
|
|
733
2417
|
/**
|
|
734
|
-
|
|
735
|
-
|
|
2418
|
+
* The claims that the client WebSocket connection has when it connects.
|
|
2419
|
+
*/
|
|
736
2420
|
claims?: Record<string, string[]>;
|
|
737
2421
|
/**
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
2422
|
+
* The query that the client WebSocket connection has when it connects.
|
|
2423
|
+
* @deprecated Please use queries instead.
|
|
2424
|
+
*/
|
|
741
2425
|
query?: Record<string, string[]>;
|
|
742
2426
|
/**
|
|
743
|
-
|
|
744
|
-
|
|
2427
|
+
* The queries that the client WebSocket connection has when it connects.
|
|
2428
|
+
*/
|
|
745
2429
|
queries?: Record<string, string[]>;
|
|
746
2430
|
/**
|
|
747
|
-
|
|
748
|
-
|
|
2431
|
+
* The headers that the client WebSocket connection has when it connects.
|
|
2432
|
+
*/
|
|
749
2433
|
headers?: Record<string, string[]>;
|
|
750
2434
|
/**
|
|
751
|
-
|
|
752
|
-
|
|
2435
|
+
* The subprotocols that the client WebSocket connection uses to do handshake.
|
|
2436
|
+
*/
|
|
753
2437
|
subprotocols?: string[];
|
|
754
2438
|
/**
|
|
755
|
-
|
|
756
|
-
|
|
2439
|
+
* The client certificate info that the client WebSocket connection uses to connect.
|
|
2440
|
+
*/
|
|
757
2441
|
clientCertificates?: Certificate[];
|
|
758
2442
|
}
|
|
759
2443
|
/**
|
|
760
|
-
* Request for the MQTT connect event.
|
|
761
|
-
*/
|
|
2444
|
+
* Request for the MQTT connect event.
|
|
2445
|
+
*/
|
|
762
2446
|
interface MqttConnectRequest extends ConnectRequest {
|
|
763
2447
|
/**
|
|
764
|
-
|
|
765
|
-
|
|
2448
|
+
* The MQTT specific properties in the MQTT connect event request.
|
|
2449
|
+
*/
|
|
766
2450
|
mqtt: MqttConnectProperties;
|
|
767
2451
|
}
|
|
768
2452
|
/**
|
|
769
|
-
* The properties of the MQTT CONNECT packet.
|
|
770
|
-
*/
|
|
2453
|
+
* The properties of the MQTT CONNECT packet.
|
|
2454
|
+
*/
|
|
771
2455
|
interface MqttConnectProperties {
|
|
772
2456
|
/**
|
|
773
|
-
|
|
774
|
-
|
|
2457
|
+
* MQTT protocol version.
|
|
2458
|
+
*/
|
|
775
2459
|
protocolVersion: number;
|
|
776
2460
|
/**
|
|
777
|
-
|
|
778
|
-
|
|
2461
|
+
* The username field in the MQTT CONNECT packet.
|
|
2462
|
+
*/
|
|
779
2463
|
username?: string;
|
|
780
2464
|
/**
|
|
781
|
-
|
|
782
|
-
|
|
2465
|
+
* The password field in the MQTT CONNECT packet.
|
|
2466
|
+
*/
|
|
783
2467
|
password?: string;
|
|
784
2468
|
/**
|
|
785
|
-
|
|
786
|
-
|
|
2469
|
+
* The user properties in the MQTT CONNECT packet.
|
|
2470
|
+
*/
|
|
787
2471
|
userProperties?: MqttUserProperty[];
|
|
788
2472
|
}
|
|
789
2473
|
/**
|
|
790
|
-
* The properties of a successful MQTT connection event response
|
|
791
|
-
*/
|
|
2474
|
+
* The properties of a successful MQTT connection event response
|
|
2475
|
+
*/
|
|
792
2476
|
interface MqttConnectResponseProperties {
|
|
793
2477
|
/**
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
2478
|
+
* Additional diagnostic or other information provided by upstream server
|
|
2479
|
+
* Now only MQTT 5.0 supports user properties
|
|
2480
|
+
*/
|
|
797
2481
|
userProperties?: MqttUserProperty[];
|
|
798
2482
|
}
|
|
799
2483
|
/**
|
|
800
|
-
* The properties of a user in MQTT.
|
|
801
|
-
*/
|
|
2484
|
+
* The properties of a user in MQTT.
|
|
2485
|
+
*/
|
|
802
2486
|
interface MqttUserProperty {
|
|
803
2487
|
/**
|
|
804
|
-
|
|
805
|
-
|
|
2488
|
+
* The name of the property.
|
|
2489
|
+
*/
|
|
806
2490
|
name: string;
|
|
807
2491
|
/**
|
|
808
|
-
|
|
809
|
-
|
|
2492
|
+
* The value of the property.
|
|
2493
|
+
*/
|
|
810
2494
|
value: string;
|
|
811
2495
|
}
|
|
812
2496
|
/**
|
|
813
|
-
* The client certificate.
|
|
814
|
-
*/
|
|
2497
|
+
* The client certificate.
|
|
2498
|
+
*/
|
|
815
2499
|
interface Certificate {
|
|
816
2500
|
/**
|
|
817
|
-
|
|
818
|
-
|
|
2501
|
+
* The thumbprint of the certificate.
|
|
2502
|
+
*/
|
|
819
2503
|
thumbprint: string;
|
|
820
2504
|
}
|
|
821
2505
|
/**
|
|
822
|
-
* Request for the connected event.
|
|
823
|
-
*/
|
|
2506
|
+
* Request for the connected event.
|
|
2507
|
+
*/
|
|
824
2508
|
interface ConnectedRequest {
|
|
825
2509
|
/**
|
|
826
|
-
|
|
827
|
-
|
|
2510
|
+
* The context of current CloudEvents request.
|
|
2511
|
+
*/
|
|
828
2512
|
context: ConnectionContext;
|
|
829
2513
|
}
|
|
830
2514
|
/**
|
|
831
|
-
* Request for the user event.
|
|
832
|
-
*/
|
|
2515
|
+
* Request for the user event.
|
|
2516
|
+
*/
|
|
833
2517
|
type UserEventRequest = {
|
|
834
2518
|
/**
|
|
835
|
-
|
|
836
|
-
|
|
2519
|
+
* The context of current CloudEvents request.
|
|
2520
|
+
*/
|
|
837
2521
|
context: ConnectionContext;
|
|
838
2522
|
/**
|
|
839
|
-
|
|
840
|
-
|
|
2523
|
+
* The content data.
|
|
2524
|
+
*/
|
|
841
2525
|
data: string;
|
|
842
2526
|
/**
|
|
843
|
-
|
|
844
|
-
|
|
2527
|
+
* The type of the data.
|
|
2528
|
+
*/
|
|
845
2529
|
dataType: "text";
|
|
846
2530
|
} | {
|
|
847
2531
|
/**
|
|
848
|
-
|
|
849
|
-
|
|
2532
|
+
* The context of current CloudEvents request.
|
|
2533
|
+
*/
|
|
850
2534
|
context: ConnectionContext;
|
|
851
2535
|
/**
|
|
852
|
-
|
|
853
|
-
|
|
2536
|
+
* The content data, when data type is `json`, the data is the result of JSON.parse, so the type of the data depends on user scenarios
|
|
2537
|
+
*/
|
|
854
2538
|
data: unknown;
|
|
855
2539
|
/**
|
|
856
|
-
|
|
857
|
-
|
|
2540
|
+
* The type of the data.
|
|
2541
|
+
*/
|
|
858
2542
|
dataType: "json";
|
|
859
2543
|
} | {
|
|
860
2544
|
/**
|
|
861
|
-
|
|
862
|
-
|
|
2545
|
+
* The context of current CloudEvents request.
|
|
2546
|
+
*/
|
|
863
2547
|
context: ConnectionContext;
|
|
864
2548
|
/**
|
|
865
|
-
|
|
866
|
-
|
|
2549
|
+
* The content data.
|
|
2550
|
+
*/
|
|
867
2551
|
data: ArrayBuffer;
|
|
868
2552
|
/**
|
|
869
|
-
|
|
870
|
-
|
|
2553
|
+
* The type of the data.
|
|
2554
|
+
*/
|
|
871
2555
|
dataType: "binary";
|
|
872
2556
|
};
|
|
873
2557
|
/**
|
|
874
|
-
* Request for the disconnected event.
|
|
875
|
-
*/
|
|
2558
|
+
* Request for the disconnected event.
|
|
2559
|
+
*/
|
|
876
2560
|
interface DisconnectedRequest {
|
|
877
2561
|
/**
|
|
878
|
-
|
|
879
|
-
|
|
2562
|
+
* The context of current CloudEvents request.
|
|
2563
|
+
*/
|
|
880
2564
|
context: ConnectionContext;
|
|
881
2565
|
/**
|
|
882
|
-
|
|
883
|
-
|
|
2566
|
+
* The reason that the connection disconnects.
|
|
2567
|
+
*/
|
|
884
2568
|
reason?: string;
|
|
885
2569
|
}
|
|
886
2570
|
/**
|
|
887
|
-
* Request for the disconnected event.
|
|
888
|
-
*/
|
|
2571
|
+
* Request for the disconnected event.
|
|
2572
|
+
*/
|
|
889
2573
|
interface MqttDisconnectedRequest extends DisconnectedRequest {
|
|
890
2574
|
/**
|
|
891
|
-
|
|
892
|
-
|
|
2575
|
+
* The MQTT specific properties in the MQTT disconnected event request.
|
|
2576
|
+
*/
|
|
893
2577
|
mqtt: MqttDisconnectedProperties;
|
|
894
2578
|
}
|
|
895
2579
|
/**
|
|
896
|
-
* The properties of an MQTT disconnected event.
|
|
897
|
-
*/
|
|
2580
|
+
* The properties of an MQTT disconnected event.
|
|
2581
|
+
*/
|
|
898
2582
|
interface MqttDisconnectedProperties {
|
|
899
2583
|
/**
|
|
900
|
-
|
|
901
|
-
|
|
2584
|
+
* The MQTT disconnect packet.
|
|
2585
|
+
*/
|
|
902
2586
|
disconnectPacket: MqttDisconnectPacket;
|
|
903
2587
|
/**
|
|
904
|
-
|
|
905
|
-
|
|
2588
|
+
* Whether the disconnection is initiated by the client.
|
|
2589
|
+
*/
|
|
906
2590
|
initiatedByClient: boolean;
|
|
907
2591
|
}
|
|
908
2592
|
/**
|
|
909
|
-
* The properties of the MQTT DISCONNECT packet.
|
|
910
|
-
*/
|
|
2593
|
+
* The properties of the MQTT DISCONNECT packet.
|
|
2594
|
+
*/
|
|
911
2595
|
interface MqttDisconnectPacket {
|
|
912
2596
|
/**
|
|
913
|
-
|
|
914
|
-
|
|
2597
|
+
* The MQTT disconnect return code.
|
|
2598
|
+
*/
|
|
915
2599
|
code: MqttDisconnectReasonCode;
|
|
916
2600
|
/**
|
|
917
|
-
|
|
918
|
-
|
|
2601
|
+
* The user properties in the MQTT disconnect packet.
|
|
2602
|
+
*/
|
|
919
2603
|
userProperties?: MqttUserProperty[];
|
|
920
2604
|
}
|
|
921
2605
|
/**
|
|
922
|
-
* The handler to set connect event response
|
|
923
|
-
*/
|
|
2606
|
+
* The handler to set connect event response
|
|
2607
|
+
*/
|
|
924
2608
|
interface ConnectResponseHandler {
|
|
925
2609
|
/**
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
2610
|
+
* Set the state of the connection
|
|
2611
|
+
* @param name - The name of the state
|
|
2612
|
+
* @param value - The value of the state
|
|
2613
|
+
*/
|
|
930
2614
|
setState(name: string, value: unknown): void;
|
|
931
2615
|
/**
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
2616
|
+
* Return success response to the service.
|
|
2617
|
+
* @param response - The response for the connect event.
|
|
2618
|
+
*/
|
|
935
2619
|
success(response?: ConnectResponse | MqttConnectResponse): void;
|
|
936
2620
|
/**
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
2621
|
+
* Return failed response and the service will reject the client WebSocket connection.
|
|
2622
|
+
* @param code - Code can be 400 user error, 401 unauthorized and 500 server error.
|
|
2623
|
+
* @param detail - The detail of the error.
|
|
2624
|
+
*/
|
|
941
2625
|
fail(code: 400 | 401 | 500, detail?: string): void;
|
|
942
2626
|
/**
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
2627
|
+
* Return failed response with MQTT response properties and the service will reject the client WebSocket connection.
|
|
2628
|
+
* @param response - The response for the connect event which contains either default WebPubSub or MQTT response properties.
|
|
2629
|
+
*/
|
|
946
2630
|
failWith(response: ConnectErrorResponse | MqttConnectErrorResponse): void;
|
|
947
2631
|
}
|
|
948
2632
|
/**
|
|
949
|
-
* The handler to set user event response
|
|
950
|
-
*/
|
|
2633
|
+
* The handler to set user event response
|
|
2634
|
+
*/
|
|
951
2635
|
interface UserEventResponseHandler {
|
|
952
2636
|
/**
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
2637
|
+
* Set the state of the connection
|
|
2638
|
+
* @param name - The name of the state
|
|
2639
|
+
* @param value - The value of the state
|
|
2640
|
+
*/
|
|
957
2641
|
setState(name: string, value: unknown): void;
|
|
958
2642
|
/**
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
2643
|
+
* Return success response with data to be delivered to the client WebSocket connection.
|
|
2644
|
+
* @param data - The payload data to be returned to the client. Stringify the message if it is a JSON object.
|
|
2645
|
+
* @param dataType - The type of the payload data.
|
|
2646
|
+
*/
|
|
963
2647
|
success(data?: string | ArrayBuffer, dataType?: "binary" | "text" | "json"): void;
|
|
964
2648
|
/**
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
2649
|
+
* Return failed response and the service will close the client WebSocket connection.
|
|
2650
|
+
* @param code - Code can be 400 user error, 401 unauthorized and 500 server error.
|
|
2651
|
+
* @param detail - The detail of the error.
|
|
2652
|
+
*/
|
|
969
2653
|
fail(code: 400 | 401 | 500, detail?: string): void;
|
|
970
2654
|
}
|
|
971
2655
|
/**
|
|
972
|
-
* The options for the CloudEvents handler.
|
|
973
|
-
*/
|
|
2656
|
+
* The options for the CloudEvents handler.
|
|
2657
|
+
*/
|
|
974
2658
|
interface WebPubSubEventHandlerOptions {
|
|
975
2659
|
/**
|
|
976
|
-
|
|
977
|
-
|
|
2660
|
+
* Custom serving path for the path of the CloudEvents handler.
|
|
2661
|
+
*/
|
|
978
2662
|
path?: string;
|
|
979
2663
|
/**
|
|
980
|
-
|
|
981
|
-
|
|
2664
|
+
* Handle 'connect' event, the service waits for the response to proceed.
|
|
2665
|
+
*/
|
|
982
2666
|
handleConnect?: (connectRequest: ConnectRequest, connectResponse: ConnectResponseHandler) => void;
|
|
983
2667
|
/**
|
|
984
|
-
|
|
985
|
-
|
|
2668
|
+
* Handle user events, the service waits for the response to proceed.
|
|
2669
|
+
*/
|
|
986
2670
|
handleUserEvent?: (userEventRequest: UserEventRequest, userEventResponse: UserEventResponseHandler) => void;
|
|
987
2671
|
/**
|
|
988
|
-
|
|
989
|
-
|
|
2672
|
+
* Event trigger for "connected" unblocking event. This is an unblocking event and the service does not wait for the response.
|
|
2673
|
+
*/
|
|
990
2674
|
onConnected?: (connectedRequest: ConnectedRequest) => void;
|
|
991
2675
|
/**
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
2676
|
+
*
|
|
2677
|
+
* Event triggers for "disconnected" unblocking event. This is an unblocking event and the service does not wait for the response.
|
|
2678
|
+
*/
|
|
995
2679
|
onDisconnected?: (disconnectedRequest: DisconnectedRequest) => void;
|
|
996
2680
|
/**
|
|
997
|
-
|
|
998
|
-
|
|
2681
|
+
* If not specified, by default allow all the endpoints, otherwise only allow specified endpoints
|
|
2682
|
+
*/
|
|
999
2683
|
allowedEndpoints?: string[];
|
|
1000
2684
|
/**
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
2685
|
+
* The Azure Web PubSub access key (or an array of [primary, secondary] keys to support key
|
|
2686
|
+
* rotation) used to verify the HMAC-SHA256 signature on every incoming CloudEvents POST.
|
|
2687
|
+
*
|
|
2688
|
+
* The Azure service signs each event as:
|
|
2689
|
+
* `sha256=Hex(HMAC-SHA256(accessKey, connectionId))`
|
|
2690
|
+
* and includes both the primary and secondary signatures in the `ce-signature` header.
|
|
2691
|
+
*
|
|
2692
|
+
* When set, requests whose `ce-signature` does not match are rejected with HTTP 401.
|
|
2693
|
+
* When omitted, signature verification is skipped and a warning is logged — use this only
|
|
2694
|
+
* when combined with network-level ingress restriction to Azure Web PubSub IP ranges.
|
|
2695
|
+
*
|
|
2696
|
+
* For managed identity / DefaultAzureCredential deployments that have no static key,
|
|
2697
|
+
* provide the service access key separately (e.g. from `WEAVE_AZURE_WEB_PUBSUB_KEY`).
|
|
2698
|
+
*/
|
|
1015
2699
|
accessKey?: string | string[];
|
|
1016
|
-
}
|
|
2700
|
+
}
|
|
2701
|
+
//#endregion
|
|
1017
2702
|
//#region src/server/event-handler/web-pubsub-event-handler.d.ts
|
|
1018
2703
|
/**
|
|
1019
|
-
* The handler to handle incoming CloudEvents messages
|
|
1020
|
-
*/
|
|
2704
|
+
* The handler to handle incoming CloudEvents messages
|
|
2705
|
+
*/
|
|
1021
2706
|
declare class WebPubSubEventHandler {
|
|
1022
|
-
private hub;
|
|
2707
|
+
private readonly hub;
|
|
1023
2708
|
/**
|
|
1024
|
-
|
|
1025
|
-
|
|
2709
|
+
* The path this CloudEvents handler listens to
|
|
2710
|
+
*/
|
|
1026
2711
|
readonly path: string;
|
|
1027
|
-
private _cloudEventsHandler;
|
|
1028
|
-
/**
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
2712
|
+
private readonly _cloudEventsHandler;
|
|
2713
|
+
/**
|
|
2714
|
+
* Creates an instance of a WebPubSubEventHandler for handling incoming CloudEvents messages.
|
|
2715
|
+
*
|
|
2716
|
+
* Example usage:
|
|
2717
|
+
* ```ts snippet:WebPubSubEventHandlerHandleMessages
|
|
2718
|
+
* import { WebPubSubEventHandler } from "@azure/web-pubsub-express";
|
|
2719
|
+
*
|
|
2720
|
+
* const endpoint = "https://xxxx.webpubsubdev.azure.com";
|
|
2721
|
+
* const handler = new WebPubSubEventHandler("chat", {
|
|
2722
|
+
* handleConnect: (req, res) => {
|
|
2723
|
+
* console.log(JSON.stringify(req));
|
|
2724
|
+
* return {};
|
|
2725
|
+
* },
|
|
2726
|
+
* onConnected: (req) => {
|
|
2727
|
+
* console.log(JSON.stringify(req));
|
|
2728
|
+
* },
|
|
2729
|
+
* handleUserEvent: (req, res) => {
|
|
2730
|
+
* console.log(JSON.stringify(req));
|
|
2731
|
+
* res.success("Hey " + req.data, req.dataType);
|
|
2732
|
+
* },
|
|
2733
|
+
* allowedEndpoints: [endpoint],
|
|
2734
|
+
* });
|
|
2735
|
+
* ```
|
|
2736
|
+
*
|
|
2737
|
+
* @param hub - The name of the hub to listen to
|
|
2738
|
+
* @param options - Options to configure the event handler
|
|
2739
|
+
*/
|
|
1055
2740
|
constructor(hub: string, options?: WebPubSubEventHandlerOptions);
|
|
1056
2741
|
/**
|
|
1057
|
-
|
|
1058
|
-
|
|
2742
|
+
* Get the middleware to process the CloudEvents requests for Koa.js
|
|
2743
|
+
*/
|
|
1059
2744
|
getKoaMiddleware(): (ctx: koa.Context, next: koa.Next) => Promise<void>;
|
|
1060
2745
|
/**
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
getExpressJsMiddleware():
|
|
2746
|
+
* Get the middleware to process the CloudEvents requests for Express.js
|
|
2747
|
+
*/
|
|
2748
|
+
getExpressJsMiddleware(): RequestHandler$1;
|
|
1064
2749
|
}
|
|
1065
|
-
|
|
1066
2750
|
//#endregion
|
|
1067
2751
|
//#region src/server/azure-web-pubsub-host.d.ts
|
|
1068
2752
|
declare class WeaveStoreAzureWebPubSubSyncHost {
|
|
@@ -1085,7 +2769,7 @@ declare class WeaveStoreAzureWebPubSubSyncHost {
|
|
|
1085
2769
|
private _updateHandler;
|
|
1086
2770
|
private _awarenessUpdateHandler;
|
|
1087
2771
|
constructor(server: WeaveAzureWebPubsubServer, syncHandler: WeaveAzureWebPubsubSyncHandler, client: WebPubSubServiceClient, topic: string, doc: Y.Doc, syncHostOptions?: DeepPartial<WeaveStoreAzureWebPubsubSyncHostOptions>);
|
|
1088
|
-
get awareness():
|
|
2772
|
+
get awareness(): Awareness | undefined;
|
|
1089
2773
|
sendInitAwarenessInfo(origin: string): void;
|
|
1090
2774
|
private setupHeartbeat;
|
|
1091
2775
|
createWebSocket(): Promise<void>;
|
|
@@ -1105,7 +2789,6 @@ declare class WeaveStoreAzureWebPubSubSyncHost {
|
|
|
1105
2789
|
private onAwareness;
|
|
1106
2790
|
private negotiate;
|
|
1107
2791
|
}
|
|
1108
|
-
|
|
1109
2792
|
//#endregion
|
|
1110
2793
|
//#region src/server/azure-web-pubsub-sync-handler.d.ts
|
|
1111
2794
|
declare class WeaveAzureWebPubsubSyncHandler extends WebPubSubEventHandler {
|
|
@@ -1135,7 +2818,6 @@ declare class WeaveAzureWebPubsubSyncHandler extends WebPubSubEventHandler {
|
|
|
1135
2818
|
clientTransportConnect(roomId: string): Promise<void>;
|
|
1136
2819
|
clientTransportDisconnect(roomId: string): void;
|
|
1137
2820
|
}
|
|
1138
|
-
|
|
1139
2821
|
//#endregion
|
|
1140
2822
|
//#region src/server/azure-web-pubsub-server.d.ts
|
|
1141
2823
|
type WeaveAzureWebPubsubServerParams = {
|
|
@@ -1151,14 +2833,7 @@ declare class WeaveAzureWebPubsubServer extends Emittery {
|
|
|
1151
2833
|
private syncHandler;
|
|
1152
2834
|
persistRoom: PersistRoom | undefined;
|
|
1153
2835
|
fetchRoom: FetchRoom | undefined;
|
|
1154
|
-
constructor({
|
|
1155
|
-
pubSubConfig,
|
|
1156
|
-
eventsHandlerConfig,
|
|
1157
|
-
initialState,
|
|
1158
|
-
persistRoom,
|
|
1159
|
-
fetchRoom,
|
|
1160
|
-
syncHostConfig
|
|
1161
|
-
}: WeaveAzureWebPubsubServerParams);
|
|
2836
|
+
constructor({ pubSubConfig, eventsHandlerConfig, initialState, persistRoom, fetchRoom, syncHostConfig }: WeaveAzureWebPubsubServerParams);
|
|
1162
2837
|
getKoaMiddleware(): koa.Middleware;
|
|
1163
2838
|
getExpressJsMiddleware(): RequestHandler;
|
|
1164
2839
|
getSyncHandler(): WeaveAzureWebPubsubSyncHandler;
|
|
@@ -1171,6 +2846,5 @@ declare class WeaveAzureWebPubsubServer extends Emittery {
|
|
|
1171
2846
|
clientTransportConnect(roomId: string): Promise<void>;
|
|
1172
2847
|
clientTransportDisconnect(roomId: string): void;
|
|
1173
2848
|
}
|
|
1174
|
-
|
|
1175
2849
|
//#endregion
|
|
1176
2850
|
export { Certificate, ConnectErrorResponse, ConnectRequest, ConnectResponse, ConnectResponseHandler, ConnectedRequest, ConnectionContext, DisconnectedRequest, FetchClient, FetchInitialState, FetchRoom, IndexedDbOptions, Message, MessageData, MessageDataType, MessageHandler, MessageType, MqttConnectErrorResponse, MqttConnectErrorResponseProperties, MqttConnectProperties, MqttConnectRequest, MqttConnectResponse, MqttConnectResponseProperties, MqttConnectionContextProperties, MqttDisconnectPacket, MqttDisconnectReasonCode, MqttDisconnectedProperties, MqttDisconnectedRequest, MqttUserProperty, MqttV311ConnectReturnCode, MqttV500ConnectReasonCode, PersistRoom, UserEventRequest, UserEventResponseHandler, WEAVE_STORE_AZURE_WEB_PUBSUB, WEAVE_STORE_AZURE_WEB_PUBSUB_CONNECTION_STATUS, WEAVE_STORE_AZURE_WEB_PUBSUB_DESTROY_ROOM_STATUS, WEAVE_STORE_AZURE_WEB_PUBSUB_SYNC_CLIENT_DEFAULT_OPTIONS, WEAVE_STORE_AZURE_WEB_PUBSUB_SYNC_HOST_DEFAULT_OPTIONS, WEAVE_STORE_HORIZONTAL_SYNC_HANDLER_CLIENT_TYPE, WeaveAzureWebPubsubServer, WeaveAzureWebPubsubSyncHandlerOptions, WeaveRoomData, WeaveStoreAzureWebPubSubSyncClientConnectionStatus, WeaveStoreAzureWebPubSubSyncClientConnectionStatusKeys, WeaveStoreAzureWebPubSubSyncClientOptions, WeaveStoreAzureWebPubSubSyncHost, WeaveStoreAzureWebPubSubSyncHostClientConnectOptions, WeaveStoreAzureWebPubsubConfig, WeaveStoreAzureWebPubsubEvents, WeaveStoreAzureWebPubsubOnConnectEvent, WeaveStoreAzureWebPubsubOnConnectedEvent, WeaveStoreAzureWebPubsubOnDisconnectedEvent, WeaveStoreAzureWebPubsubOnStoreFetchConnectionUrlEvent, WeaveStoreAzureWebPubsubOnWebsocketCloseEvent, WeaveStoreAzureWebPubsubOnWebsocketErrorEvent, WeaveStoreAzureWebPubsubOnWebsocketJoinGroupEvent, WeaveStoreAzureWebPubsubOnWebsocketMessageEvent, WeaveStoreAzureWebPubsubOnWebsocketOpenEvent, WeaveStoreAzureWebPubsubOnWebsocketReconnectEvent, WeaveStoreAzureWebPubsubOptions, WeaveStoreAzureWebPubsubSyncHandlerDestroyRoomStatus, WeaveStoreAzureWebPubsubSyncHandlerDestroyRoomStatusKeys, WeaveStoreAzureWebPubsubSyncHostOptions, WebPubSubClientProtocol, WebPubSubEventHandler, WebPubSubEventHandlerOptions };
|