@soundworks/core 4.0.0-alpha.7 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/CHANGELOG.md +102 -0
  2. package/README.md +16 -50
  3. package/package.json +26 -44
  4. package/src/client/Client.js +306 -256
  5. package/src/client/{Context.js → ClientContext.js} +63 -54
  6. package/src/client/ClientContextManager.js +115 -0
  7. package/src/client/{Plugin.js → ClientPlugin.js} +23 -19
  8. package/src/client/{PluginManager.js → ClientPluginManager.js} +43 -40
  9. package/src/client/ClientSocket.js +270 -0
  10. package/src/client/{StateManager.js → ClientStateManager.js} +13 -13
  11. package/src/client/index.js +36 -39
  12. package/src/common/BasePlugin.js +63 -58
  13. package/src/common/BasePluginManager.js +191 -142
  14. package/src/common/BaseStateManager.js +636 -143
  15. package/src/common/BatchedTransport.js +73 -0
  16. package/src/common/ParameterBag.js +90 -93
  17. package/src/common/PromiseStore.js +54 -0
  18. package/src/common/SharedState.js +821 -0
  19. package/src/common/SharedStateCollection.js +492 -0
  20. package/src/common/constants.js +14 -2
  21. package/src/common/logger.js +64 -68
  22. package/src/common/shared-state-types.js +82 -0
  23. package/src/common/sockets-utils.js +0 -64
  24. package/src/common/version.js +2 -0
  25. package/src/server/Server.js +559 -821
  26. package/src/server/ServerClient.js +74 -0
  27. package/src/server/{Context.js → ServerContext.js} +96 -77
  28. package/src/server/{ContextManager.js → ServerContextManager.js} +107 -87
  29. package/src/server/{Plugin.js → ServerPlugin.js} +30 -32
  30. package/src/server/ServerPluginManager.js +177 -0
  31. package/src/server/ServerSocket.js +256 -0
  32. package/src/server/ServerSockets.js +150 -0
  33. package/src/server/ServerStateManager.js +706 -0
  34. package/src/server/SharedStatePrivate.js +277 -0
  35. package/src/server/audit-network-latency.worker.js +19 -4
  36. package/src/server/{audit-schema.js → audit-state-class-description.js} +3 -2
  37. package/src/server/create-http-server.js +127 -0
  38. package/src/server/crypto.js +8 -7
  39. package/src/server/index.js +60 -17
  40. package/types/client/Client.d.ts +95 -70
  41. package/types/client/{Context.d.ts → ClientContext.d.ts} +59 -34
  42. package/types/client/{ContextManager.d.ts → ClientContextManager.d.ts} +19 -22
  43. package/types/client/ClientPlugin.d.ts +51 -0
  44. package/types/client/ClientPluginManager.d.ts +112 -0
  45. package/types/client/ClientSocket.d.ts +76 -0
  46. package/types/client/{StateManager.d.ts → ClientStateManager.d.ts} +18 -21
  47. package/types/client/index.d.ts +33 -6
  48. package/types/common/BasePlugin.d.ts +64 -53
  49. package/types/common/BasePluginManager.d.ts +84 -39
  50. package/types/common/BaseStateManager.d.ts +227 -49
  51. package/types/common/BatchedTransport.d.ts +17 -0
  52. package/types/common/ParameterBag.d.ts +73 -76
  53. package/types/common/PromiseStore.d.ts +11 -0
  54. package/types/common/SharedState.d.ts +291 -0
  55. package/types/common/SharedStateCollection.d.ts +311 -0
  56. package/types/common/constants.d.ts +10 -3
  57. package/types/common/logger.d.ts +8 -6
  58. package/types/common/shared-state-types.d.ts +95 -0
  59. package/types/common/sockets-utils.d.ts +0 -5
  60. package/types/common/version.d.ts +2 -0
  61. package/types/server/Server.d.ts +215 -136
  62. package/types/server/ServerClient.d.ts +45 -0
  63. package/types/server/ServerContext.d.ts +209 -0
  64. package/types/server/ServerContextManager.d.ts +75 -0
  65. package/types/server/ServerPlugin.d.ts +57 -0
  66. package/types/server/ServerPluginManager.d.ts +115 -0
  67. package/types/server/ServerSocket.d.ts +69 -0
  68. package/types/server/ServerSockets.d.ts +42 -0
  69. package/types/server/ServerStateManager.d.ts +284 -0
  70. package/types/server/SharedStatePrivate.d.ts +23 -0
  71. package/types/server/audit-network-latency.worker.d.ts +2 -2
  72. package/types/server/{audit-schema.d.ts → audit-state-class-description.d.ts} +8 -9
  73. package/types/server/create-http-server.d.ts +5 -0
  74. package/types/server/crypto.d.ts +4 -0
  75. package/types/server/index.d.ts +51 -3
  76. package/.eslintrc +0 -15
  77. package/.github/workflows/gh-pages.yml +0 -31
  78. package/.github/workflows/unit-tests.yml +0 -18
  79. package/src/client/ContextManager.js +0 -111
  80. package/src/client/SharedState.js +0 -84
  81. package/src/client/SharedStateCollection.js +0 -35
  82. package/src/client/Socket.js +0 -402
  83. package/src/common/BaseSharedState.js +0 -517
  84. package/src/common/BaseSharedStateCollection.js +0 -179
  85. package/src/common/SharedStatePrivate.js +0 -192
  86. package/src/common/promise-store.js +0 -25
  87. package/src/server/Client.js +0 -55
  88. package/src/server/PluginManager.js +0 -170
  89. package/src/server/SharedState.js +0 -85
  90. package/src/server/SharedStateCollection.js +0 -36
  91. package/src/server/Socket.js +0 -396
  92. package/src/server/Sockets.js +0 -224
  93. package/src/server/StateManager.js +0 -620
  94. package/tsconfig.json +0 -21
  95. package/types/client/Client.d.ts.map +0 -1
  96. package/types/client/Context.d.ts.map +0 -1
  97. package/types/client/ContextManager.d.ts.map +0 -1
  98. package/types/client/Plugin.d.ts +0 -53
  99. package/types/client/Plugin.d.ts.map +0 -1
  100. package/types/client/PluginManager.d.ts +0 -96
  101. package/types/client/PluginManager.d.ts.map +0 -1
  102. package/types/client/SharedState.d.ts +0 -85
  103. package/types/client/SharedState.d.ts.map +0 -1
  104. package/types/client/Socket.d.ts +0 -138
  105. package/types/client/Socket.d.ts.map +0 -1
  106. package/types/client/StateManager.d.ts.map +0 -1
  107. package/types/client/index.d.ts.map +0 -1
  108. package/types/common/BasePlugin.d.ts.map +0 -1
  109. package/types/common/BasePluginManager.d.ts.map +0 -1
  110. package/types/common/BaseSharedState.d.ts +0 -173
  111. package/types/common/BaseSharedState.d.ts.map +0 -1
  112. package/types/common/BaseStateManager.d.ts.map +0 -1
  113. package/types/common/ParameterBag.d.ts.map +0 -1
  114. package/types/common/SharedStatePrivate.d.ts +0 -20
  115. package/types/common/SharedStatePrivate.d.ts.map +0 -1
  116. package/types/common/constants.d.ts.map +0 -1
  117. package/types/common/logger.d.ts.map +0 -1
  118. package/types/common/promise-store.d.ts +0 -4
  119. package/types/common/promise-store.d.ts.map +0 -1
  120. package/types/common/sockets-utils.d.ts.map +0 -1
  121. package/types/common/utils.d.ts +0 -5
  122. package/types/common/utils.d.ts.map +0 -1
  123. package/types/server/Client.d.ts +0 -40
  124. package/types/server/Client.d.ts.map +0 -1
  125. package/types/server/Context.d.ts +0 -59
  126. package/types/server/Context.d.ts.map +0 -1
  127. package/types/server/ContextManager.d.ts +0 -69
  128. package/types/server/ContextManager.d.ts.map +0 -1
  129. package/types/server/Plugin.d.ts +0 -70
  130. package/types/server/Plugin.d.ts.map +0 -1
  131. package/types/server/PluginManager.d.ts +0 -91
  132. package/types/server/PluginManager.d.ts.map +0 -1
  133. package/types/server/Server.d.ts.map +0 -1
  134. package/types/server/SharedState.d.ts +0 -86
  135. package/types/server/SharedState.d.ts.map +0 -1
  136. package/types/server/Socket.d.ts +0 -128
  137. package/types/server/Socket.d.ts.map +0 -1
  138. package/types/server/Sockets.d.ts +0 -73
  139. package/types/server/Sockets.d.ts.map +0 -1
  140. package/types/server/StateManager.d.ts +0 -190
  141. package/types/server/StateManager.d.ts.map +0 -1
  142. package/types/server/audit-network-latency.worker.d.ts.map +0 -1
  143. package/types/server/audit-schema.d.ts.map +0 -1
  144. package/types/server/index.d.ts.map +0 -1
@@ -0,0 +1,291 @@
1
+ export const kSharedStatePromiseStore: unique symbol;
2
+ export default SharedState;
3
+ /**
4
+ * Callback executed when updates are applied on a {@link SharedState}.
5
+ */
6
+ export type sharedStateOnUpdateCallback = (newValues: any, oldValues: any) => any;
7
+ /**
8
+ * Delete the registered {@link sharedStateOnUpdateCallback}.
9
+ */
10
+ export type sharedStateDeleteOnUpdateCallback = () => any;
11
+ /**
12
+ * Callback executed when updates are applied on a {@link SharedState}.
13
+ *
14
+ * @callback sharedStateOnUpdateCallback
15
+ * @param {Object} newValues - Key / value pairs of the updates that have been
16
+ * applied to the state.
17
+ * @param {Object} oldValues - Key / value pairs of the updated params before
18
+ * the updates has been applied to the state.
19
+ */
20
+ /**
21
+ * Delete the registered {@link sharedStateOnUpdateCallback}.
22
+ *
23
+ * @callback sharedStateDeleteOnUpdateCallback
24
+ */
25
+ /**
26
+ * The `SharedState` is one of the most important and versatile abstraction provided
27
+ * by `soundworks`. It represents a set of parameters that are synchronized across
28
+ * every nodes of the application (clients and server) that declared some interest
29
+ * to the shared state.
30
+ *
31
+ * A `SharedState` instance is created according to a shared state class definition
32
+ * which is composed of a {@link SharedStateClassName} and of a {@link SharedStateClassDescription}
33
+ * registered in the {@link ServerStateManager}. Any number of `SharedState`s
34
+ * can be created from a single class definition.
35
+ *
36
+ * A shared state can be created both by the clients or by the server, in which case
37
+ * it is generally considered as a global state of the application. Similarly any
38
+ * node of the application (clients or server) can declare interest and "attach" to
39
+ * a state created by another node. All node attached to a state can modify its values
40
+ * and/or react to the modifications applied by other nodes.
41
+ *
42
+ * Tutorial: {@link https://soundworks.dev/guide/state-manager.html}
43
+ *
44
+ * ```
45
+ * // server-side
46
+ * import { Server } from '@soundworks/server/index.js';
47
+ *
48
+ * const server = new Server(config);
49
+ * // define a shared state class
50
+ * server.stateManager.defineClass('some-global-state', {
51
+ * myRandom: {
52
+ * type: 'float',
53
+ * default: 0,
54
+ * }
55
+ * });
56
+ *
57
+ * await server.start();
58
+ *
59
+ * // create a global state server-side
60
+ * const globalState = await server.stateManager.create('some-global-state');
61
+ * // listen and react to the changes made by the clients
62
+ * globalState.onUpdate(updates => console.log(updates));
63
+ * ```
64
+ *
65
+ * ```
66
+ * // client-side
67
+ * import { Client } from '@soundworks/client.index.js';
68
+ *
69
+ * const client = new Client(config);
70
+ * await client.start();
71
+ *
72
+ * // attach to the global state created by the server
73
+ * const globalState = await client.stateManager.attach('some-global-state');
74
+ *
75
+ * // update the value of a `myRandom` parameter every seconds
76
+ * setInterval(() => {
77
+ * globalState.set({ myRandom: Math.random() });
78
+ * }, 1000);
79
+ * ```
80
+ */
81
+ declare class SharedState {
82
+ constructor({ stateId, instanceId, className, classDescription, isOwner, manager, initValues, filter, }: {
83
+ stateId: any;
84
+ instanceId: any;
85
+ className: any;
86
+ classDescription: any;
87
+ isOwner: any;
88
+ manager: any;
89
+ initValues: any;
90
+ filter: any;
91
+ });
92
+ /**
93
+ * Id of the state
94
+ * @type {Number}
95
+ */
96
+ get id(): number;
97
+ /**
98
+ * Name of the underlying {@link SharedState} class.
99
+ * @type {String}
100
+ */
101
+ get className(): string;
102
+ /**
103
+ * @deprecated Use {@link SharedState#className} instead.
104
+ */
105
+ get schemaName(): string;
106
+ /**
107
+ * Indicates if the node is the owner of the state, i.e. if it created the state.
108
+ * @type {Boolean}
109
+ */
110
+ get isOwner(): boolean;
111
+ /**
112
+ * Return the underlying {@link SharedStateClassDescription} or the
113
+ * {@link SharedStateParameterDescription} if `paramName` is given.
114
+ *
115
+ * @param {string} [paramName=null] - If defined, returns the parameter
116
+ * description of the given parameter name rather than the full class description.
117
+ * @return {SharedStateClassDescription|SharedStateParameterDescription}
118
+ * @throws Throws if `paramName` is not null and does not exists.
119
+ * @example
120
+ * const classDescription = state.getDescription();
121
+ * const paramDescription = state.getDescription('my-param');
122
+ */
123
+ getDescription(paramName?: string): SharedStateClassDescription | SharedStateParameterDescription;
124
+ /**
125
+ * @deprecated Use {@link SharedState#getDescription} instead.
126
+ */
127
+ getSchema(paramName?: any): any;
128
+ /**
129
+ * Update the values of the state.
130
+ *
131
+ * The returned `Promise` resolves on an object that contains the applied updates,
132
+ * and resolves after all the `onUpdate` callbacks have resolved themselves
133
+ *
134
+ * @overload
135
+ * @param {object} updates - Key / value pairs of updates to apply to the state.
136
+ * @returns {Promise<Object>} - Promise to the (coerced) updates.
137
+ */
138
+ set(updates: object): Promise<any>;
139
+ /**
140
+ * Update the values of the state.
141
+ *
142
+ * The returned `Promise` resolves on an object that contains the applied updates,
143
+ * and resolves after all the `onUpdate` callbacks have resolved themselves
144
+ *
145
+ * @overload
146
+ * @param {SharedStateParameterName} name - Name of the parameter.
147
+ * @param {*} value - Value of the parameter.
148
+ * @returns {Promise<Object>} - Promise to the (coerced) updates.
149
+ */
150
+ set(name: SharedStateParameterName, value: any): Promise<any>;
151
+ /**
152
+ * Get the value of a parameter of the state.
153
+ *
154
+ * Be aware that in case of 'any' type, the returned value is deeply copied.
155
+ * While this prevents from pollution of the state by mutating the reference,
156
+ * this can also lead to performance issues when the parameter contains large
157
+ * data. In such cases you should use the {@link SharedState#getUnsafe} method
158
+ * and make sure to treat the returned object as readonly.
159
+ *
160
+ * @param {SharedStateParameterName} name - Name of the param.
161
+ * @return {any}
162
+ * @throws Throws if `name` does not exists.
163
+ * @example
164
+ * const value = state.get('paramName');
165
+ */
166
+ get(name: SharedStateParameterName): any;
167
+ /**
168
+ * Get an unsafe reference to the value of a parameter of the state.
169
+ *
170
+ * Similar to `get` but returns a reference to the underlying value in case of
171
+ * `any` type. Can be useful if the underlying value is large (e.g. sensors
172
+ * recordings, etc.) and deep cloning expensive. Be aware that if changes are
173
+ * made on the returned object, the state of your application will become
174
+ * inconsistent.
175
+ *
176
+ * @param {SharedStateParameterName} name - Name of the param.
177
+ * @return {any}
178
+ * @throws Throws if `name` does not exists.
179
+ * @example
180
+ * const value = state.getUnsafe('paramName');
181
+ */
182
+ getUnsafe(name: SharedStateParameterName): any;
183
+ /**
184
+ * Get all the key / value pairs of the state.
185
+ *
186
+ * If a parameter is of `any` type, a deep copy is made.
187
+ *
188
+ * @return {object}
189
+ * @example
190
+ * const values = state.getValues();
191
+ */
192
+ getValues(): object;
193
+ /**
194
+ * Get all the key / value pairs of the state.
195
+ *
196
+ * Similar to `getValues` but returns a reference to the underlying value in
197
+ * case of `any` type. Can be useful if the underlying value is big (e.g.
198
+ * sensors recordings, etc.) and deep cloning expensive. Be aware that if
199
+ * changes are made on the returned object, the state of your application will
200
+ * become inconsistent.
201
+ *
202
+ * @return {object}
203
+ * @example
204
+ * const values = state.getValues();
205
+ */
206
+ getValuesUnsafe(): object;
207
+ /**
208
+ * Get the values with which the state has been created. May defer from the
209
+ * default values declared in the class description.
210
+ *
211
+ * @return {object}
212
+ * @example
213
+ * const initValues = state.getInitValues();
214
+ */
215
+ getInitValues(): object;
216
+ /**
217
+ * Get the default values as declared in the class description.
218
+ *
219
+ * @return {object}
220
+ * @example
221
+ * const defaults = state.getDefaults();
222
+ */
223
+ getDefaults(): object;
224
+ /**
225
+ * Detach from the state. If the client is the creator of the state, the state
226
+ * is deleted and all attached nodes get notified.
227
+ *
228
+ * @example
229
+ * const state = await client.state.attach('globals');
230
+ * // later
231
+ * await state.detach();
232
+ */
233
+ detach(): Promise<any>;
234
+ /**
235
+ * Delete the state. Only the creator/owner of the state can use this method.
236
+ *
237
+ * All nodes attached to the state will be detached, triggering any registered
238
+ * `onDetach` callbacks. The creator of the state will also have its own `onDelete`
239
+ * callback triggered. The local `onDetach` and `onDelete` callbacks will be
240
+ * executed *before* the returned Promise resolves
241
+ *
242
+ * @throws Throws if the method is called by a node which is not the owner of
243
+ * the state.
244
+ * @example
245
+ * const state = await client.stateManager.create('my-class-name');
246
+ * // later
247
+ * await state.delete();
248
+ */
249
+ delete(): Promise<any>;
250
+ /**
251
+ * Subscribe to state updates.
252
+ *
253
+ * @param {sharedStateOnUpdateCallback} callback
254
+ * Callback to execute when an update is applied on the state.
255
+ * @param {Boolean} [executeListener=false] - Execute the callback immediately
256
+ * with current state values. Note that `oldValues` will be set to `{}`.
257
+ * @returns {sharedStateDeleteOnUpdateCallback}
258
+ * @example
259
+ * const unsubscribe = state.onUpdate(async (newValues, oldValues) => {
260
+ * for (let [key, value] of Object.entries(newValues)) {
261
+ * switch (key) {
262
+ * // do something
263
+ * }
264
+ * }
265
+ * });
266
+ *
267
+ * // later
268
+ * unsubscribe();
269
+ */
270
+ onUpdate(listener: any, executeListener?: boolean): sharedStateDeleteOnUpdateCallback;
271
+ /**
272
+ * Register a function to execute when detaching from the state. The function
273
+ * will be executed before the `detach` promise resolves.
274
+ *
275
+ * @param {Function} callback - Callback to execute when detaching from the state.
276
+ * Whether the client as called `detach`, or the state has been deleted by its
277
+ * creator.
278
+ */
279
+ onDetach(callback: Function): () => boolean;
280
+ /**
281
+ * Register a function to execute when the state is deleted. Only called if the
282
+ * node was the creator of the state. Is called after `onDetach` and executed
283
+ * before the `delete` Promise resolves.
284
+ *
285
+ * @param {Function} callback - Callback to execute when the state is deleted.
286
+ */
287
+ onDelete(callback: Function): () => boolean;
288
+ /** @private */
289
+ private [kSharedStatePromiseStore];
290
+ #private;
291
+ }
@@ -0,0 +1,311 @@
1
+ /**
2
+ * Callback to execute when an update is triggered on one of the shared states
3
+ * of the collection.
4
+ *
5
+ * @callback sharedStateCollectionOnUpdateCallback
6
+ * @param {SharedState} state - The shared state instance that triggered the update.
7
+ * @param {Object} newValues - Key / value pairs of the updates that have been
8
+ * applied to the state.
9
+ * @param {Object} oldValues - Key / value pairs of the updated params before
10
+ * the updates has been applied to the state.
11
+ */
12
+ /**
13
+ * Delete the registered {@link sharedStateCollectionOnUpdateCallback} when executed.
14
+ *
15
+ * @callback sharedStateCollectionDeleteOnUpdateCallback
16
+ */
17
+ /**
18
+ * Callback to execute when an new shared state is added to the collection
19
+ *
20
+ * @callback sharedStateCollectionOnAttachCallback
21
+ * @param {SharedState} state - The newly shared state instance added to the collection.
22
+ */
23
+ /**
24
+ * Delete the registered {@link sharedStateCollectionOnAttachCallback} when executed.
25
+ *
26
+ * @callback sharedStateCollectionDeleteOnAttachCallback
27
+ */
28
+ /**
29
+ * Callback to execute when an shared state is removed from the collection, i.e.
30
+ * has been deleted by its owner.
31
+ *
32
+ * @callback sharedStateCollectionOnDetachCallback
33
+ * @param {SharedState} state - The shared state instance removed from the collection.
34
+ */
35
+ /**
36
+ * Delete the registered {@link sharedStateCollectionOnDetachCallback} when executed.
37
+ *
38
+ * @callback sharedStateCollectionDeleteOnDetachCallback
39
+ */
40
+ /**
41
+ * Callback to execute when any state of the collection is attached, removed, or updated.
42
+ *
43
+ * @callback sharedStateCollectionOnChangeCallback
44
+ */
45
+ /**
46
+ * Delete the registered {@link sharedStateCollectionOnChangeCallback}.
47
+ *
48
+ * @callback sharedStateCollectionDeleteOnChangeCallback
49
+ */
50
+ export const kSharedStateCollectionInit: unique symbol;
51
+ export default SharedStateCollection;
52
+ /**
53
+ * Callback to execute when an update is triggered on one of the shared states
54
+ * of the collection.
55
+ */
56
+ export type sharedStateCollectionOnUpdateCallback = (state: SharedState, newValues: any, oldValues: any) => any;
57
+ /**
58
+ * Delete the registered {@link sharedStateCollectionOnUpdateCallback} when executed.
59
+ */
60
+ export type sharedStateCollectionDeleteOnUpdateCallback = () => any;
61
+ /**
62
+ * Callback to execute when an new shared state is added to the collection
63
+ */
64
+ export type sharedStateCollectionOnAttachCallback = (state: SharedState) => any;
65
+ /**
66
+ * Delete the registered {@link sharedStateCollectionOnAttachCallback} when executed.
67
+ */
68
+ export type sharedStateCollectionDeleteOnAttachCallback = () => any;
69
+ /**
70
+ * Callback to execute when an shared state is removed from the collection, i.e.
71
+ * has been deleted by its owner.
72
+ */
73
+ export type sharedStateCollectionOnDetachCallback = (state: SharedState) => any;
74
+ /**
75
+ * Delete the registered {@link sharedStateCollectionOnDetachCallback} when executed.
76
+ */
77
+ export type sharedStateCollectionDeleteOnDetachCallback = () => any;
78
+ /**
79
+ * Callback to execute when any state of the collection is attached, removed, or updated.
80
+ */
81
+ export type sharedStateCollectionOnChangeCallback = () => any;
82
+ /**
83
+ * Delete the registered {@link sharedStateCollectionOnChangeCallback}.
84
+ */
85
+ export type sharedStateCollectionDeleteOnChangeCallback = () => any;
86
+ /**
87
+ * The `SharedStateCollection` interface represent a collection of all states
88
+ * created from a given class name on the network.
89
+ *
90
+ * It can optionally exclude the states created by the current node.
91
+ *
92
+ * See {@link ClientStateManager#getCollection} and
93
+ * {@link ServerStateManager#getCollection} for factory methods API
94
+ *
95
+ * ```
96
+ * const collection = await client.stateManager.getCollection('my-class');
97
+ * const allValues = collection.getValues();
98
+ * collection.onUpdate((state, newValues, oldValues) => {
99
+ * // do something
100
+ * });
101
+ * ```
102
+ * @hideconstructor
103
+ */
104
+ declare class SharedStateCollection {
105
+ constructor(stateManager: any, className: any, filter?: any, options?: {});
106
+ /**
107
+ * Size of the collection, alias `size`
108
+ * @type {number}
109
+ * @readonly
110
+ */
111
+ readonly get length(): number;
112
+ /**
113
+ * Size of the collection, , alias `length`
114
+ * @type {number}
115
+ */
116
+ get size(): number;
117
+ /**
118
+ * Name of the class from which the collection has been created.
119
+ * @type {String}
120
+ */
121
+ get className(): string;
122
+ /**
123
+ * @deprecated Use {@link SharedStateCollection#className} instead.
124
+ */
125
+ get schemaName(): string;
126
+ /**
127
+ * @deprecated Use {@link SharedStateCollection#getDescription} instead.
128
+ */
129
+ getSchema(paramName?: any): any;
130
+ /**
131
+ * Return the underlying {@link SharedStateClassDescription} or the
132
+ * {@link SharedStateParameterDescription} if `paramName` is given.
133
+ *
134
+ * @param {string} [paramName=null] - If defined, returns the parameter
135
+ * description of the given parameter name rather than the full class description.
136
+ * @return {SharedStateClassDescription|SharedStateParameterDescription}
137
+ * @throws Throws if `paramName` is not null and does not exists.
138
+ * @example
139
+ * const classDescription = collection.getDescription();
140
+ * const paramDescription = collection.getDescription('my-param');
141
+ */
142
+ getDescription(paramName?: string): SharedStateClassDescription | SharedStateParameterDescription;
143
+ /**
144
+ * Get the default values as declared in the class description.
145
+ *
146
+ * @return {object}
147
+ * @example
148
+ * const defaults = state.getDefaults();
149
+ */
150
+ getDefaults(): object;
151
+ /**
152
+ * Return the current values of all the states in the collection.
153
+ * @return {Object[]}
154
+ */
155
+ getValues(): any[];
156
+ /**
157
+ * Return the current values of all the states in the collection.
158
+ *
159
+ * Similar to `getValues` but returns a reference to the underlying value in
160
+ * case of `any` type. May be useful if the underlying value is big (e.g.
161
+ * sensors recordings, etc.) and deep cloning expensive. Be aware that if
162
+ * changes are made on the returned object, the state of your application will
163
+ * become inconsistent.
164
+ *
165
+ * @return {Object[]}
166
+ */
167
+ getValuesUnsafe(): any[];
168
+ /**
169
+ * Return the current param value of all the states in the collection.
170
+ *
171
+ * @param {String} name - Name of the parameter
172
+ * @return {any[]}
173
+ */
174
+ get(name: string): any[];
175
+ /**
176
+ * Similar to `get` but returns a reference to the underlying value in case of
177
+ * `any` type. May be useful if the underlying value is big (e.g. sensors
178
+ * recordings, etc.) and deep cloning expensive. Be aware that if changes are
179
+ * made on the returned object, the state of your application will become
180
+ * inconsistent.
181
+ *
182
+ * @param {String} name - Name of the parameter
183
+ * @return {any[]}
184
+ */
185
+ getUnsafe(name: string): any[];
186
+ /**
187
+ * Update all states of the collection with given values.
188
+ *
189
+ * The returned `Promise` resolves on a list of objects that contains the applied updates,
190
+ * and resolves after all the `onUpdate` callbacks have resolved themselves
191
+ *
192
+ * @overload
193
+ * @param {object} updates - key / value pairs of updates to apply to the collection.
194
+ * @returns {Promise<Array<Object>>} - Promise to the list of (coerced) updates.
195
+ */
196
+ set(updates: object): Promise<Array<any>>;
197
+ /**
198
+ * Update all states of the collection with given values.
199
+ *
200
+ * The returned `Promise` resolves on a list of objects that contains the applied updates,
201
+ * and resolves after all the `onUpdate` callbacks have resolved themselves
202
+ *
203
+ * @overload
204
+ * @param {SharedStateParameterName} name - Name of the parameter.
205
+ * @param {*} value - Value of the parameter.
206
+ * @returns {Promise<Array<Object>>} - Promise to the list of (coerced) updates.
207
+ */
208
+ set(name: SharedStateParameterName, value: any): Promise<Array<any>>;
209
+ /**
210
+ * Register a function to execute when any shared state of the collection is updated.
211
+ *
212
+ * @param {sharedStateCollectionOnUpdateCallback}
213
+ * callback - Callback to execute when an update is applied on a state.
214
+ * @param {Boolean} [executeListener=false] - Execute the callback immediately
215
+ * with current state values. Note that `oldValues` will be set to `{}`.
216
+ * @returns {sharedStateCollectionDeleteOnUpdateCallback} - Function that delete
217
+ * the registered listener when executed.
218
+ */
219
+ onUpdate(callback: sharedStateCollectionOnUpdateCallback, executeListener?: boolean): sharedStateCollectionDeleteOnUpdateCallback;
220
+ /**
221
+ * Register a function to execute when a shared state is attached to the collection,
222
+ * i.e. when a node creates a new state from same {@link SharedState} class.
223
+ *
224
+ * @param {sharedStateCollectionOnAttachCallback} callback - callback to execute
225
+ * when a state is added to the collection.
226
+ * @param {boolean} executeListener - execute the callback with the states
227
+ * already present in the collection.
228
+ * @returns {sharedStateCollectionDeleteOnAttachCallback} - Function that delete
229
+ * the registered listener when executed.
230
+ */
231
+ onAttach(callback: sharedStateCollectionOnAttachCallback, executeListener?: boolean): sharedStateCollectionDeleteOnAttachCallback;
232
+ /**
233
+ * Register a function to execute when a shared state is removed from the collection,
234
+ * i.e. when it is deleted by its owner.
235
+ *
236
+ * @param {sharedStateCollectionOnDetachCallback} callback - callback to execute
237
+ * when a state is removed from the collection.
238
+ * @returns {sharedStateCollectionDeleteOnDetachCallback} - Function that delete
239
+ * the registered listener when executed.
240
+ */
241
+ onDetach(callback: sharedStateCollectionOnDetachCallback): sharedStateCollectionDeleteOnDetachCallback;
242
+ /**
243
+ * Register a function to execute when any state of the collection is either attached,
244
+ * removed, or updated.
245
+ *
246
+ * @param {sharedStateCollectionOnChangeCallback} callback - callback to execute
247
+ * when any state of the collection is either attached, updated, or detached.
248
+ * @returns {sharedStateCollectionDeleteOnChangeCallback} - Function that delete
249
+ * the registered listener when executed.
250
+ * @example
251
+ * const collection = await client.stateManager.getCollection('player');
252
+ * collection.onChange(() => renderApp(), true);
253
+ */
254
+ onChange(callback: sharedStateCollectionOnChangeCallback, executeListener?: boolean): sharedStateCollectionDeleteOnChangeCallback;
255
+ /**
256
+ * Detach from the collection, i.e. detach all underlying shared states.
257
+ * @type {number}
258
+ */
259
+ detach(): Promise<void>;
260
+ /**
261
+ * Execute the given function once for each states of the collection (see `Array.forEach`).
262
+ *
263
+ * @param {Function} func - A function to execute for each element in the array.
264
+ * Its return value is discarded.
265
+ */
266
+ forEach(func: Function): void;
267
+ /**
268
+ * Creates a new array populated with the results of calling a provided function
269
+ * on every state of the collection (see `Array.map`).
270
+ *
271
+ * @param {Function} func - A function to execute for each element in the array.
272
+ * Its return value is added as a single element in the new array.
273
+ */
274
+ map(func: Function): any[];
275
+ /**
276
+ * Creates a shallow copy of a portion of the collection, filtered down to just
277
+ * the estates that pass the test implemented by the provided function (see `Array.filter`).
278
+ *
279
+ * @param {Function} func - A function to execute for each element in the array.
280
+ * It should return a truthy to keep the element in the resulting array, and a
281
+ * falsy value otherwise.
282
+ */
283
+ filter(func: Function): any[];
284
+ /**
285
+ * Sort the elements of the collection in place (see `Array.sort`).
286
+ *
287
+ * @param {Function} func - Function that defines the sort order.
288
+ */
289
+ sort(func: Function): void;
290
+ /**
291
+ * Returns the first element of the collection that satisfies the provided testing
292
+ * function. If no values satisfy the testing function, undefined is returned.
293
+ *
294
+ * @param {Function} func - Function to execute for each element in the array.
295
+ * It should return a truthy value to indicate a matching element has been found.
296
+ * @return {}
297
+ */
298
+ find(func: Function): any;
299
+ /** @private */
300
+ private [kSharedStateCollectionInit];
301
+ /**
302
+ * Iterable API, e.g. for use in `for .. of` loops
303
+ */
304
+ [Symbol.iterator](): {
305
+ next: () => {
306
+ value: any;
307
+ done: boolean;
308
+ };
309
+ };
310
+ #private;
311
+ }
@@ -1,4 +1,8 @@
1
1
  export const SERVER_ID: -1;
2
+ export const PING_INTERVAL: number;
3
+ export const PING_MESSAGE: "h:ping";
4
+ export const PONG_MESSAGE: "h:pong";
5
+ export const BATCHED_TRANSPORT_CHANNEL: "b:t";
2
6
  export const CREATE_REQUEST: "s:c:req";
3
7
  export const CREATE_RESPONSE: "s:c:res";
4
8
  export const CREATE_ERROR: "s:c:err";
@@ -14,13 +18,17 @@ export const DETACH_RESPONSE: "s:dt:res";
14
18
  export const DETACH_ERROR: "s:dt:err";
15
19
  export const OBSERVE_REQUEST: "s:o:req";
16
20
  export const OBSERVE_RESPONSE: "s:o:res";
21
+ export const OBSERVE_ERROR: "s:o:err";
17
22
  export const OBSERVE_NOTIFICATION: "s:o:not";
18
23
  export const UNOBSERVE_NOTIFICATION: "s:uo:not";
19
24
  export const UPDATE_REQUEST: "s:u:req";
20
25
  export const UPDATE_RESPONSE: "s:u:res";
21
26
  export const UPDATE_ABORT: "s:u:ab";
22
27
  export const UPDATE_NOTIFICATION: "s:u:not";
23
- export const DELETE_SCHEMA: "s:d:s";
28
+ export const DELETE_SHARED_STATE_CLASS: "s:d:s";
29
+ export const GET_CLASS_DESCRIPTION_REQUEST: "s:s:req";
30
+ export const GET_CLASS_DESCRIPTION_RESPONSE: "s:s:res";
31
+ export const GET_CLASS_DESCRIPTION_ERROR: "s:s:err";
24
32
  export const CONTEXT_ENTER_REQUEST: "c:en:req";
25
33
  export const CONTEXT_ENTER_RESPONSE: "c:en:res";
26
34
  export const CONTEXT_ENTER_ERROR: "c:en:err";
@@ -30,6 +38,5 @@ export const CONTEXT_EXIT_ERROR: "c:ex:err";
30
38
  export const CLIENT_HANDSHAKE_REQUEST: "cl:h:req";
31
39
  export const CLIENT_HANDSHAKE_RESPONSE: "cl:h:res";
32
40
  export const CLIENT_HANDSHAKE_ERROR: "cl:h:err";
33
- export const AUDIT_STATE_NAME: "s:c:audit";
41
+ export const AUDIT_STATE_NAME: "p:s:audit";
34
42
  export const PRIVATE_STATES: string[];
35
- //# sourceMappingURL=constants.d.ts.map
@@ -1,16 +1,18 @@
1
1
  export default logger;
2
2
  declare namespace logger {
3
- const verbose: boolean;
3
+ let verbose: boolean;
4
4
  function configure(verbose: any): void;
5
5
  function title(msg: any): void;
6
- function clientConfigAndRouting(routes: any, config: any): void;
6
+ function log(msg: any): void;
7
+ function warn(msg: any): void;
8
+ function error(msg: any): void;
7
9
  function ip(protocol: any, address: any, port: any): void;
8
10
  function pluginStart(name: any): void;
9
11
  function pluginStarted(name: any): void;
10
12
  function pluginReady(name: any): void;
11
13
  function pluginErrored(name: any): void;
12
- function log(msg: any): void;
13
- function warn(msg: any): void;
14
- function error(msg: any): void;
14
+ function warnVersionDiscrepancies(clientRole: any, clientVersion: any, serverVersion: any): void;
15
+ function deprecated(oldAPI: any, newAPI: any, lastSupportedVersion: any): void;
16
+ function removed(oldAPI: any, hint: any, lastSupportedVersion: any): never;
17
+ function httpsCertsInfos(httpsCertsInfos: any): void;
15
18
  }
16
- //# sourceMappingURL=logger.d.ts.map