@soundworks/core 4.0.0-alpha.21 → 4.0.0-alpha.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/CHANGELOG.md +14 -3
  2. package/package.json +15 -15
  3. package/src/client/Client.js +233 -188
  4. package/src/client/Socket.js +84 -247
  5. package/src/client/index.js +6 -0
  6. package/src/common/constants.js +0 -1
  7. package/src/common/logger.js +15 -0
  8. package/src/common/sockets-utils.js +0 -63
  9. package/src/common/version.js +2 -0
  10. package/src/server/Plugin.js +22 -10
  11. package/src/server/Server.js +37 -36
  12. package/src/server/Socket.js +126 -250
  13. package/src/server/Sockets.js +103 -127
  14. package/src/server/audit-network-latency.worker.js +4 -3
  15. package/src/server/index.js +6 -0
  16. package/types/client/Client.d.ts +41 -8
  17. package/types/client/Client.d.ts.map +1 -1
  18. package/types/client/Context.d.ts +40 -14
  19. package/types/client/Context.d.ts.map +1 -1
  20. package/types/client/Plugin.d.ts +42 -41
  21. package/types/client/Plugin.d.ts.map +1 -1
  22. package/types/client/PluginManager.d.ts +26 -11
  23. package/types/client/PluginManager.d.ts.map +1 -1
  24. package/types/client/SharedState.d.ts +1 -1
  25. package/types/client/SharedState.d.ts.map +1 -1
  26. package/types/client/SharedStateCollection.d.ts +41 -0
  27. package/types/client/SharedStateCollection.d.ts.map +1 -0
  28. package/types/client/Socket.d.ts +41 -30
  29. package/types/client/Socket.d.ts.map +1 -1
  30. package/types/client/StateManager.d.ts +1 -1
  31. package/types/client/StateManager.d.ts.map +1 -1
  32. package/types/client/index.d.ts +0 -8
  33. package/types/common/BasePlugin.d.ts +24 -19
  34. package/types/common/BasePlugin.d.ts.map +1 -1
  35. package/types/common/BasePluginManager.d.ts +17 -5
  36. package/types/common/BasePluginManager.d.ts.map +1 -1
  37. package/types/common/BaseSharedState.d.ts +100 -29
  38. package/types/common/BaseSharedState.d.ts.map +1 -1
  39. package/types/common/BaseSharedStateCollection.d.ts +183 -0
  40. package/types/common/BaseSharedStateCollection.d.ts.map +1 -0
  41. package/types/common/BaseStateManager.d.ts +83 -18
  42. package/types/common/BaseStateManager.d.ts.map +1 -1
  43. package/types/common/BatchedTransport.d.ts +21 -0
  44. package/types/common/BatchedTransport.d.ts.map +1 -0
  45. package/types/common/ParameterBag.d.ts +61 -40
  46. package/types/common/ParameterBag.d.ts.map +1 -1
  47. package/types/common/PromiseStore.d.ts +11 -0
  48. package/types/common/PromiseStore.d.ts.map +1 -0
  49. package/types/common/SharedStatePrivate.d.ts +4 -3
  50. package/types/common/SharedStatePrivate.d.ts.map +1 -1
  51. package/types/common/constants.d.ts +10 -1
  52. package/types/common/constants.d.ts.map +1 -1
  53. package/types/common/logger.d.ts +1 -1
  54. package/types/common/sockets-utils.d.ts.map +1 -1
  55. package/types/common/version.d.ts +3 -0
  56. package/types/common/version.d.ts.map +1 -0
  57. package/types/server/Client.d.ts +5 -0
  58. package/types/server/Client.d.ts.map +1 -1
  59. package/types/server/Context.d.ts +162 -22
  60. package/types/server/Context.d.ts.map +1 -1
  61. package/types/server/ContextManager.d.ts +4 -4
  62. package/types/server/ContextManager.d.ts.map +1 -1
  63. package/types/server/Plugin.d.ts +56 -55
  64. package/types/server/Plugin.d.ts.map +1 -1
  65. package/types/server/PluginManager.d.ts +26 -6
  66. package/types/server/PluginManager.d.ts.map +1 -1
  67. package/types/server/Server.d.ts +207 -70
  68. package/types/server/Server.d.ts.map +1 -1
  69. package/types/server/SharedState.d.ts +1 -1
  70. package/types/server/SharedState.d.ts.map +1 -1
  71. package/types/server/SharedStateCollection.d.ts +41 -0
  72. package/types/server/SharedStateCollection.d.ts.map +1 -0
  73. package/types/server/Socket.d.ts +93 -57
  74. package/types/server/Socket.d.ts.map +1 -1
  75. package/types/server/Sockets.d.ts +32 -25
  76. package/types/server/Sockets.d.ts.map +1 -1
  77. package/types/server/StateManager.d.ts +242 -27
  78. package/types/server/StateManager.d.ts.map +1 -1
  79. package/types/server/audit-network-latency.worker.d.ts +2 -1
  80. package/types/server/audit-schema.d.ts +8 -8
  81. package/types/server/crypto.d.ts +3 -0
  82. package/types/server/crypto.d.ts.map +1 -0
  83. package/types/server/index.d.ts +0 -4
  84. package/types/common/promise-store.d.ts +0 -4
  85. package/types/common/promise-store.d.ts.map +0 -1
  86. package/types/common/utils.d.ts +0 -5
  87. package/types/common/utils.d.ts.map +0 -1
@@ -1,100 +1,155 @@
1
1
  export default Server;
2
2
  /**
3
- * Server side entry point for a `soundworks` application.
3
+ * Configuration object for the server.
4
+ */
5
+ export type ServerConfig = any;
6
+ /**
7
+ * The `Server` class is the main entry point for the server-side of a soundworks
8
+ * application.
4
9
  *
5
- * This object hosts configuration informations, as well as methods to
6
- * initialize and start the application. It is also responsible for creating
7
- * the static file (http) server as well as the socket server.
10
+ * The `Server` instance allows to access soundworks components such as {@link server.StateManager},
11
+ * {@link server.PluginManager},{@link server.Socket} or {@link server.ContextManager}.
12
+ * Its is also responsible for handling the initialization lifecycles of the different
13
+ * soundworks components.
8
14
  *
9
- * @memberof server
10
- *
11
- * @param {server.ServerConfig} config
12
- * @example
15
+ * ```
13
16
  * import { Server } from '@soundworks/core/server';
17
+ *
14
18
  * const server = new Server({
15
19
  * app: {
16
20
  * name: 'my-example-app',
17
- * clients: { myClient: { target: 'node' } },
21
+ * clients: {
22
+ * player: { target: 'browser', default: true },
23
+ * controller: { target: 'browser' },
24
+ * thing: { target: 'node' }
25
+ * },
18
26
  * },
19
27
  * env: {
20
- * port: 8888,
28
+ * port: 8000,
21
29
  * },
22
30
  * });
23
- * await server.init();
31
+ *
24
32
  * await server.start();
33
+ * ```
34
+ *
35
+ * According to the clients definitions provided in `config.app.clients`, the
36
+ * server will automatically create a dedicated route for each browser client role.
37
+ * For example, given the config object of the example above that defines two
38
+ * different client roles for browser targets (i.e. `player` and `controller`):
39
+ *
40
+ * ```
41
+ * config.app.clients = {
42
+ * player: { target: 'browser', default: true },
43
+ * controller: { target: 'browser' },
44
+ * }
45
+ * ```
46
+ *
47
+ * The server will listen to the following URLs:
48
+ * - `http://127.0.0.1:8000/` for the `player` role, which is defined as the default client.
49
+ * - `http://127.0.0.1:8000/controller` for the `controller` role.
50
+ *
51
+ * @memberof server
25
52
  */
26
53
  declare class Server {
27
- constructor(config: any);
28
54
  /**
29
- * Configuration informations.
30
- * Defaults to:
31
- * ```
55
+ * @param {server.ServerConfig} config - Configuration object for the server.
56
+ * @throws
57
+ * - If `config.app.clients` is empty.
58
+ * - If a `node` client is defined but `config.env.serverAddress` is not defined.
59
+ * - if `config.env.useHttps` is `true` and `config.env.httpsInfos` is not `null`
60
+ * (which generates self signed certificated), `config.env.httpsInfos.cert` and
61
+ * `config.env.httpsInfos.key` should point to valid cert files.
62
+ */
63
+ constructor(config: server.ServerConfig);
64
+ /**
65
+ * @description Given config object merged with the following defaults:
66
+ * @example
32
67
  * {
33
68
  * env: {
34
69
  * type: 'development',
35
70
  * port: 8000,
36
- * subfolder: '',
71
+ * serverAddress: null,
72
+ * subpath: '',
73
+ * websockets: {
74
+ * path: 'socket',
75
+ * pingInterval: 5000,
76
+ * },
37
77
  * useHttps: false,
38
78
  * httpsInfos: null,
79
+ * crossOriginIsolated: true,
80
+ * verbose: true,
39
81
  * },
40
82
  * app: {
41
83
  * name: 'soundworks',
42
84
  * clients: {},
43
- * },
85
+ * }
44
86
  * }
45
- * ```
46
87
  */
47
88
  config: any;
89
+ version: string;
48
90
  /**
49
- * Router. Internally use polka.
50
- * (cf. {@link https://github.com/lukeed/polka})
91
+ * Instance of the express router.
92
+ *
93
+ * The router can be used to open new route, for example to expose a directory
94
+ * of static assets (in default soundworks applications only the `public` is exposed).
95
+ *
96
+ * @see {@link https://github.com/expressjs/express}
97
+ * @example
98
+ * import { Server } from '@soundworks/core/server.js';
99
+ * import express from 'express';
100
+ *
101
+ * // create the soundworks server instance
102
+ * const server = new Server(config);
103
+ *
104
+ * // expose assets located in the `soundfiles` directory on the network
105
+ * server.router.use('/soundfiles', express.static('soundfiles')));
51
106
  */
52
107
  router: any;
53
108
  /**
54
- * Http(s) server instance. The node `http` or `https` module instance
55
- * (cf. {@link https://nodejs.org/api/http.html})
109
+ * Raw Node.js `http` or `https` instance
110
+ *
111
+ * @see {@link https://nodejs.org/api/http.html}
112
+ * @see {@link https://nodejs.org/api/https.html}
56
113
  */
57
114
  httpServer: any;
58
115
  /**
59
- * Key / value storage with Promise based Map API
60
- * basically a wrapper around kvey (cf. {@link https://github.com/lukechilds/keyv})
61
- * @private
62
- */
63
- private db;
64
- /**
65
- * The {@link server.Sockets} instance. A small wrapper around
66
- * [`ws`](https://github.com/websockets/ws) server.
116
+ * Instance of the {@link server.Sockets} class.
117
+ *
67
118
  * @see {@link server.Sockets}
68
119
  * @type {server.Sockets}
69
120
  */
70
121
  sockets: server.Sockets;
71
122
  /**
72
- * The {@link server.PluginManager} instance.
123
+ * Instance of the {@link server.PluginManager} class.
124
+ *
73
125
  * @see {@link server.PluginManager}
74
126
  * @type {server.PluginManager}
75
127
  */
76
128
  pluginManager: server.PluginManager;
77
129
  /**
78
- * The {@link server.StateManager} instance.
130
+ * Instance of the {@link server.StateManager} class.
131
+ *
79
132
  * @see {@link server.StateManager}
80
133
  * @type {server.StateManager}
81
134
  */
82
135
  stateManager: server.StateManager;
83
136
  /**
84
- * The {@link server.ContextManager} instance.
137
+ * Instance of the {@link server.ContextManager} class.
85
138
  *
139
+ * @see {@link server.ContextManager}
140
+ * @type {server.ContextManager}
86
141
  */
87
- contextManager: ContextManager;
142
+ contextManager: server.ContextManager;
88
143
  /**
89
- * If https is required, will contain informations about the certificates
90
- * (self-signed, validity dates, etc.)
144
+ * If `https` is required, hold informations about the certificates, e.g. if
145
+ * self-signed, the dates of validity of the certificates, etc.
91
146
  */
92
147
  httpsInfos: {
93
148
  selfSigned: boolean;
94
- CN: any;
95
- altNames: any;
96
- validFrom: any;
97
- validTo: any;
149
+ CN: string;
150
+ altNames: string[];
151
+ validFrom: string;
152
+ validTo: string;
98
153
  isValid: boolean;
99
154
  daysRemaining: number;
100
155
  } | {
@@ -115,28 +170,55 @@ declare class Server {
115
170
  daysRemaining?: undefined;
116
171
  };
117
172
  /**
118
- * Current status of the server ['idle', 'inited', 'started']
173
+ * Status of the server, 'idle', 'inited', 'started' or 'errored'.
174
+ *
175
+ * @type {string}
119
176
  */
120
177
  status: string;
178
+ /**
179
+ * Simple key / value database with Promise based Map API store on filesystem,
180
+ * basically a tiny wrapper around the `kvey` package.
181
+ *
182
+ * @private
183
+ * @see {@link https://github.com/lukechilds/keyv}
184
+ */
185
+ private db;
121
186
  /** @private */
122
- private _applicationTemplateConfig;
187
+ private _applicationTemplateOptions;
123
188
  /** @private */
124
189
  private _onStatusChangeCallbacks;
125
190
  /** @private */
191
+ private _onClientConnectCallbacks;
192
+ /** @private */
193
+ private _onClientDisconnectCallbacks;
194
+ /** @private */
126
195
  private _auditState;
196
+ /** @private */
197
+ private _pendingConnectionTokens;
198
+ /** @private */
199
+ private _trustedClients;
127
200
  /**
128
- * Method to be called before `start` in the initialization lifecycle of the
129
- * soundworks server. Note that if `init()`` is not explicitely called, `start()`
130
- * will call it implicitely.
201
+ * Id of the server, a constant set to -1
202
+ * @type {Number}
203
+ * @readonly
204
+ */
205
+ readonly get id(): number;
206
+ /**
207
+ * The `init` method is part of the initialization lifecycle of the `soundworks`
208
+ * server. Most of the time, the `init` method will be implicitly called by the
209
+ * {@link server.Server#start} method.
210
+ *
211
+ * In some situations you might want to call this method manually, in such cases
212
+ * the method should be called before the {@link server.Server#start} method.
131
213
  *
132
214
  * What it does:
133
215
  * - create the audit state
134
216
  * - prepapre http(s) server and routing according to the informations
135
217
  * declared in `config.app.clients`
136
- * - starts all registered plugins
218
+ * - initialize all registered plugins
137
219
  *
138
- * After `await server.init()`, you can safely use the StateManager, as well
139
- * as any registered Plugins.
220
+ * After `await server.init()` is fulfilled, the {@link server.Server#stateManager}
221
+ * and all registered plugins can be safely used.
140
222
  *
141
223
  * @example
142
224
  * const server = new Server(config);
@@ -148,22 +230,41 @@ declare class Server {
148
230
  */
149
231
  init(): Promise<void>;
150
232
  /**
151
- * Method to be called when `init` step is done in the initialization
152
- * lifecycle of the soundworks server. If `server.init()` has not been called
153
- * explicitely, `server.start()` will call it automatically.
233
+ * The `start` method is part of the initialization lifecycle of the `soundworks`
234
+ * server. The `start` method will implicitly call the {@link server.Server#init}
235
+ * method if it has not been called manually.
154
236
  *
155
237
  * What it does:
156
- * - starts all registered contexts (context are automatically registered
157
- * when instantiated)
158
- * - start the web socket server
159
- * - launch the HTTP server on given port
238
+ * - implicitely call {@link server.Server#init} if not done manually
239
+ * - launch the HTTP and WebSocket servers
240
+ * - start all created contexts. To this end, you will have to call `server.init`
241
+ * manually and instantiate the contexts between `server.init()` and `server.start()`
242
+ *
243
+ * After `await server.start()` the server is ready to accept incoming connections
160
244
  *
161
- * After `await server.start()` the server is ready to accept incoming connexions
245
+ * @example
246
+ * import { Server } from '@soundworks/core/server.js'
247
+ *
248
+ * const server = new Server(config);
249
+ * await server.start();
162
250
  */
163
251
  start(): Promise<any>;
164
252
  /**
165
- * Stop the server, close all existing WebSocket connections.
166
- * Mainly usefull for test.
253
+ * Stops all started contexts, plugins, close all the socket connections and
254
+ * the http(s) server.
255
+ *
256
+ * In most situations, you might not need to call this method. However, it can
257
+ * be usefull for unit testing or similar situations where you want to create
258
+ * and delete several servers in the same process.
259
+ *
260
+ * @example
261
+ * import { Server } from '@soundworks/core/server.js'
262
+ *
263
+ * const server = new Server(config);
264
+ * await server.start();
265
+ *
266
+ * await new Promise(resolve => setTimeout(resolve, 1000));
267
+ * await server.stop();
167
268
  */
168
269
  stop(): Promise<void>;
169
270
  /**
@@ -171,6 +272,8 @@ declare class Server {
171
272
  * @private
172
273
  */
173
274
  private _openClientRoute;
275
+ onClientConnect(callback: any): () => boolean;
276
+ onClientDisconnect(callback: any): () => boolean;
174
277
  /**
175
278
  * Socket connection callback.
176
279
  * @private
@@ -189,8 +292,8 @@ declare class Server {
189
292
  /** @private */
190
293
  private _dispatchStatus;
191
294
  /**
192
- * Configure the server to work out-of-the box with the soundworks-template
193
- * directory tree structure.
295
+ * Configure the server to work _out-of-the-box_ within the soundworks application
296
+ * template provided by `@soundworks/create.
194
297
  *
195
298
  * - uses [template-literal](https://www.npmjs.com/package/template-literal) package
196
299
  * as html templateEngine
@@ -202,22 +305,56 @@ declare class Server {
202
305
  * Also expose two public directory:
203
306
  * - the `public` directory which is exposed behind the root path
204
307
  * - the `./.build/public` directory which is exposed behind the `build` path
308
+ *
309
+ * _Note: except in very rare cases (so rare that they are quite difficult to imagine),
310
+ * you should rely on these defaults._
205
311
  */
206
- setDefaultTemplateConfig(): void;
312
+ useDefaultApplicationTemplate(): void;
207
313
  /**
208
- * Define your own template path, template engine, and clientConfig function.
209
- * This method is for very advanced use-cases and only be used if you know what
210
- * you are doing. As such its behavior could probably be improved a lot...
211
- *
212
- * If you end up using this, please contact me to explain your use-case :)
314
+ * Define custom template path, template engine, and clientConfig function.
315
+ * This method is proposed for very advanced use-cases and should very probably
316
+ * be improved. If you consider using this for some reason, please get in touch
317
+ * first to explain your use-case :)
213
318
  */
214
- setCustomTemplateConfig(options: any): void;
319
+ setCustomApplicationTemplateOptions(options: any): void;
215
320
  /**
216
- * Get the global audit state of the application.
321
+ * Attach and retrieve the global audit state of the application.
322
+ *
323
+ * The audit state is a {@link server.SharedState} instance that keeps track of
324
+ * global informations about the application such as, the number of connected
325
+ * clients, network latency estimation, etc.
217
326
  *
327
+ * The audit state is created by the server on start up.
328
+ *
329
+ * @returns {Promise<server.SharedState>}
218
330
  * @throws Will throw if called before `server.init()`
331
+ * @see {@link server.SharedState}
332
+ * @example
333
+ * const auditState = await server.getAuditState();
334
+ * auditState.onUpdate(() => console.log(auditState.getValues()), true);
335
+ */
336
+ getAuditState(): Promise<server.SharedState>;
337
+ /** @private */
338
+ private isProtected;
339
+ /** @private */
340
+ private isValidConnectionToken;
341
+ /**
342
+ * Check if the given client is trusted, i.e. config.env.type == 'production'
343
+ * and the client is protected behind a password.
344
+ *
345
+ * @param {server.Client} client - Client to be tested
346
+ * @returns {Boolean}
347
+ */
348
+ isTrustedClient(client: server.Client): boolean;
349
+ /**
350
+ * Check if the token from a client is trusted, i.e. config.env.type == 'production'
351
+ * and the client is protected behind a password.
352
+ *
353
+ * @param {Number} clientId - Id of the client
354
+ * @param {Number} clientIp - Ip of the client
355
+ * @param {String} token - Token to be tested
356
+ * @returns {Boolean}
219
357
  */
220
- getAuditState(): Promise<any>;
358
+ isTrustedToken(clientId: number, clientIp: number, token: string): boolean;
221
359
  }
222
- import ContextManager from "./ContextManager.js";
223
360
  //# sourceMappingURL=Server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Server.d.ts","sourceRoot":"","sources":["../../src/server/Server.js"],"names":[],"mappings":";AA2EA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH;IACE,yBA2IC;IAvIC;;;;;;;;;;;;;;;;;;OAkBG;IACH,YAA+C;IAuC/C;;;OAGG;IACH,YAAuB;IAIvB;;;OAGG;IACH,gBAAsB;IAEtB;;;;OAIG;IACH,WAAyC;IAEzC;;;;;OAKG;IACH,wBAA4B;IAE5B;;;;OAIG;IACH,oCAA4C;IAE5C;;;;OAIG;IACH,kCAAsC;IAEtC;;;OAGG;IACH,+BAA8C;IAE9C;;;OAGG;IACH;;;;;;;;;;;;;;;;;;;;;;;;MAAsB;IAEtB;;OAEG;IACH,eAAoB;IAEpB,eAAe;IACf,mCAIC;IAED,eAAe;IACf,iCAAyC;IACzC,eAAe;IACf,oBAAuB;IASzB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,sBAwMC;IAED;;;;;;;;;;;;OAYG;IACH,sBAoFC;IAGD;;;OAGG;IACH,sBAgBC;IAED;;;OAGG;IACH,yBAgEC;IAED;;;OAGG;IACH,4BAmEC;IAED;;;;;;;OAOG;IACH,2BAmBC;IAED,6CAIC;IAED,eAAe;IACf,wBAgBC;IAED;;;;;;;;;;;;;;OAcG;IACH,iCAsBC;IAED;;;;;;OAMG;IACH,4CAEC;IAED;;;;OAIG;IACH,8BAMC;CACF"}
1
+ {"version":3,"file":"Server.d.ts","sourceRoot":"","sources":["../../src/server/Server.js"],"names":[],"mappings":";;;;;AAuGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH;IACE;;;;;;;;OAQG;IACH,yCAoLC;IA/KC;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,YAA+C;IAuC/C,gBAAsB;IAEtB;;;;;;;;;;;;;;;;OAgBG;IAGH,YAAuB;IAIvB;;;;;OAKG;IACH,gBAAsB;IAEtB;;;;;OAKG;IACH,wBAA4B;IAE5B;;;;;OAKG;IACH,oCAA4C;IAE5C;;;;;OAKG;IACH,kCAAsC;IAEtC;;;;;OAKG;IACH,sCAA8C;IAE9C;;;OAGG;IACH;;;;;;;;;;;;;;;;;;;;;;;;MAAsB;IAEtB;;;;OAIG;IACH,QAFU,MAAM,CAEI;IAEpB;;;;;;OAMG;IACH,WAAyC;IAEzC,eAAe;IACf,oCAIC;IAED,eAAe;IACf,iCAAyC;IACzC,eAAe;IACf,kCAA0C;IAC1C,eAAe;IACf,qCAA6C;IAC7C,eAAe;IACf,oBAAuB;IACvB,eAAe;IACf,iCAAyC;IACzC,eAAe;IACf,wBAAgC;IASlC;;;;OAIG;IACH,0BAEC;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,sBAgPC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,sBAwFC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,sBAgBC;IAED;;;OAGG;IACH,yBA2EC;IAED,8CAIC;IAED,iDAIC;IAED;;;OAGG;IACH,4BAkHC;IAED;;;;;;;OAOG;IACH,2BAmBC;IAED,6CAIC;IAED,eAAe;IACf,wBAgBC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,sCAkDC;IAED;;;;;OAKG;IACH,wDAEC;IAED;;;;;;;;;;;;;;;OAeG;IACH,iBAPa,2BAA2B,CAavC;IAED,eAAe;IACf,oBAMC;IAED,eAAe;IACf,+BAkBC;IAED;;;;;;OAMG;IACH,gDAMC;IAED;;;;;;;;OAQG;IAEH,2EAkBC;CACF"}
@@ -82,5 +82,5 @@ export namespace server {
82
82
  */
83
83
  declare class SharedState extends BaseSharedState {
84
84
  }
85
- import BaseSharedState from "../common/BaseSharedState.js";
85
+ import BaseSharedState from '../common/BaseSharedState.js';
86
86
  //# sourceMappingURL=SharedState.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"SharedState.d.ts","sourceRoot":"","sources":["../../src/server/SharedState.js"],"names":[],"mappings":";;;;;;;AAIA;;;;;;;;GAQG;AAEH;;;;GAIG;AAGH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH;CAA4C"}
1
+ {"version":3,"file":"SharedState.d.ts","sourceRoot":"","sources":["../../src/server/SharedState.js"],"names":[],"mappings":";;;;;;;AAIA;;;;;;;;GAQG;AAEH;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH;CAA4C;4BAjFhB,8BAA8B"}
@@ -0,0 +1,41 @@
1
+ export default SharedStateCollection;
2
+ export namespace server {
3
+ /**
4
+ * ~onUpdateCallback
5
+ */
6
+ type SharedStateCollection = (state: server.SharedState, newValues: any, oldValues: any, context?: Mixed) => any;
7
+ }
8
+ /**
9
+ * @callback server.SharedStateCollection~onUpdateCallback
10
+ * @param {server.SharedState} state - State that triggered the update.
11
+ * @param {Object} newValues - Key / value pairs of the updates that have been
12
+ * applied to the state.
13
+ * @param {Object} oldValues - Key / value pairs of the updated params before
14
+ * the updates has been applied to the state.
15
+ * @param {Mixed} [context=null] - Optionnal context object that has been passed
16
+ * with the values updates in the `set` call.
17
+ */
18
+ /**
19
+ * The `SharedStateCollection` interface represent a collection of all states
20
+ * created from a given schema name on the network.
21
+ *
22
+ * It can optionnaly exclude the states created by the current node.
23
+ *
24
+ * See {@link server.StateManager#getCollection} for factory method API
25
+ *
26
+ * ```
27
+ * const collection = await server.stateManager.getCollection('my-schema');
28
+ * const allValues = collection.getValues();
29
+ * collection.onUpdate((state, newValues, oldValues, context) => {
30
+ * // do something
31
+ * });
32
+ * ```
33
+ * @memberof server
34
+ * @extends BaseSharedStateCollection
35
+ * @inheritdoc
36
+ * @hideconstructor
37
+ */
38
+ declare class SharedStateCollection extends BaseSharedStateCollection {
39
+ }
40
+ import BaseSharedStateCollection from '../common/BaseSharedStateCollection.js';
41
+ //# sourceMappingURL=SharedStateCollection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SharedStateCollection.d.ts","sourceRoot":"","sources":["../../src/server/SharedStateCollection.js"],"names":[],"mappings":";;;;;;;AAIA;;;;;;;;;GASG;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AACH;CAAgE;sCAnC1B,wCAAwC"}