1 | /**
|
2 | * The top-level Diffusion API.
|
3 | *
|
4 | * Provides access to Session connections and global namespaces.
|
5 | */ /**
|
6 | * The version of this client library in the form major.minor.patch
|
7 | */
|
8 | export declare const version: string;
|
9 | /**
|
10 | * The build version of this client library
|
11 | */
|
12 | export declare const build: string;
|
13 | /**
|
14 | * Set the level of logging used by Diffusion. This will default to silent.
|
15 | * Log levels are strings that represent different degrees of information to
|
16 | * be logged. Available options are:
|
17 | *
|
18 | * * silent
|
19 | * * error
|
20 | * * warn
|
21 | * * info
|
22 | * * debug
|
23 | * * trace
|
24 | *
|
25 | * @param level the log level to use
|
26 | */
|
27 | export declare function log(level: LogLevel | keyof typeof LogLevel): void;
|
28 | /**
|
29 | * Connect to a specified Diffusion server. This will return a {@link
|
30 | * Result} that will complete succesfully if a session can be connected, or
|
31 | * fail if an error was encountered.
|
32 | *
|
33 | * If the result is succesful, the fulfilled handler will be called with a
|
34 | * {@link Session} instance. This session will be in a connected state and
|
35 | * may be used for subsequent API calls.
|
36 | *
|
37 | * If the result fails, the rejected handler will be called with an error
|
38 | * reason.
|
39 | *
|
40 | * **Example:**
|
41 | * ```
|
42 | * diffusion.connect('example.server.com').then(function(session) {
|
43 | * // Connected with a session
|
44 | * console.log('Connected!', session);
|
45 | * }, function(error) {
|
46 | * // Connection failed
|
47 | * console.log('Failed to connect', error);
|
48 | * });
|
49 | * ```
|
50 | *
|
51 | *
|
52 | * @param options the options to construct the session with.
|
53 | * @returns a {@link Result} for this operation
|
54 | */
|
55 | export declare function connect(options: Options): Result<Session>;
|
56 | /**
|
57 | * Escapes special characters in a string that is to be used within a topic
|
58 | * property or a session filter.
|
59 | * <P>
|
60 | * This is a convenience method which inserts an escape character '\' before
|
61 | * any of the special characters ' " or \.
|
62 | *
|
63 | * @param s the string to be escaped
|
64 | * @returns the string value with escape characters inserted as appropriate
|
65 | *
|
66 | * @since 6.1
|
67 | */
|
68 | export declare function escape(s: string): string;
|
69 | /**
|
70 | * Utility method which converts a string of the format required by the
|
71 | * {@link PropertyKeys.ROLES $Roles} session property into a mutable set of
|
72 | * strings.
|
73 | *
|
74 | * @param s the string with quoted roles separated by whitespace or
|
75 | * commas
|
76 | *
|
77 | * @return set of roles
|
78 | *
|
79 | * @since 6.2
|
80 | */
|
81 | export declare function stringToRoles(s: string): Set<string>;
|
82 | /**
|
83 | * Utility method which converts a set of authorisation roles to the string
|
84 | * format required by the {@link PropertyKeys.ROLES $Roles} session property.
|
85 | *
|
86 | * @param roles a set of roles
|
87 | * @return a string representing the supplied roles, formatted as
|
88 | * required by the {@link PropertyKeys.ROLES $Roles} session
|
89 | * property
|
90 | *
|
91 | * @since 6.2
|
92 | */
|
93 | export declare function rolesToString(roles: Set<string> | string[]): string;
|
94 | /**
|
95 | * Returns an update constraint factory.
|
96 | *
|
97 | * @function diffusion#updateConstraints
|
98 | * @return {diffusion.topicUpdate.UpdateConstraintFactory} update constraint
|
99 | * factory
|
100 | * @since 6.2
|
101 | */
|
102 | export declare function updateConstraints(): UpdateConstraintFactory;
|
103 | /**
|
104 | * Access to the datatypes namespace
|
105 | */
|
106 | export declare const datatypes: DataTypes;
|
107 | /**
|
108 | * Access to the selectors namespace
|
109 | */
|
110 | export declare const selectors: TopicSelectors;
|
111 | /**
|
112 | * Access to the topics namespace
|
113 | */
|
114 | export declare const topics: TopicsNamespace;
|
115 | /**
|
116 | * Access to the topicUpdate namespace
|
117 | */
|
118 | export declare const topicUpdate: TopicUpdateNamespace;
|
119 | /**
|
120 | * The ErrorReason enum
|
121 | */
|
122 | export declare const errors: {
|
123 | [key: string]: ErrorReasonType;
|
124 | };
|
125 | /**
|
126 | * Access to PropertyKeys
|
127 | */
|
128 | export declare const clients: ClientControlOptionsNamespace;
|
129 | /**
|
130 | * Access to the locks namespace
|
131 | */
|
132 | export declare const locks: SessionLockOptionsNamespace;
|
133 | /**
|
134 | * @module diffusion.errors
|
135 | */
|
136 | /**
|
137 | * An ErrorReport from the server.
|
138 | */
|
139 | export interface ErrorReport {
|
140 | /**
|
141 | * The error message
|
142 | */
|
143 | message: string;
|
144 | /**
|
145 | * The line at which the problem was found
|
146 | */
|
147 | line: number;
|
148 | /**
|
149 | * The column at which the problem was found
|
150 | */
|
151 | column: number;
|
152 | }
|
153 | /// <reference types="node" />
|
154 | /**
|
155 | * @module Session
|
156 | */
|
157 | export declare type TypedArray = Int8Array | Int16Array | Int32Array | Uint8Array | Uint8ClampedArray | Uint16Array | Uint32Array | Float32Array | Float64Array;
|
158 | export declare type ReconnectStrategy = (reconnect: () => void, abort: () => void) => void;
|
159 | /**
|
160 | * Provide Session configuration options.
|
161 | *
|
162 | * <h5>Connection:</h5>
|
163 | * There are several option values that can be configured to change how
|
164 | * Diffusion establishes a connection. These options are used to derive a
|
165 | * connection URL in the format: <code>{protocol}://{host}:{port}/{path}</code>.
|
166 | * The protocol used is determined by the chosen transports and whether secure
|
167 | * connections are enabled.
|
168 | *
|
169 | * <table>
|
170 | * <thead>
|
171 | * <tr>
|
172 | * <th>Option</th>
|
173 | * <th>Default value</th>
|
174 | * <th>Description</th>
|
175 | * </tr>
|
176 | * </thead>
|
177 | * <tbody>
|
178 | * <tr>
|
179 | * <td>host</td>
|
180 | * <td><code>localhost</code></td>
|
181 | * <td>The hostname to connect to.</td>
|
182 | * </tr>
|
183 | * <tr>
|
184 | * <td>port</td>
|
185 | * <td><code>80</code> or <code>443</code></td>
|
186 | * <td>The port to connect to. The default value is the default secure port if
|
187 | * secure connections are enabled, otherwise the default value is the default
|
188 | * insecure port.
|
189 | * <p>
|
190 | * In case the client is being run in a page served via <code>https</code>
|
191 | * (<code>http</code>), the default secure (insecure) port is the port of the
|
192 | * URI of the current page, otherwise the default secure (insecure) port is
|
193 | * <code>443</code> (<code>80</code>).
|
194 | * </tr>
|
195 | * <tr>
|
196 | * <td>path</td>
|
197 | * <td><code>/diffusion</code></td>
|
198 | * <td>The URL path to apply after the hostname/port. This allows additional context to be provided, such as might be
|
199 | * used by load balancers.</td>
|
200 | * </tr>
|
201 | * <tr>
|
202 | * <td>secure</td>
|
203 | * <td><code>true</code></td>
|
204 | * <td>Determines if secure transports will be used. If the port is not
|
205 | * explicitly specified this value defaults to <code>true</code>. If the port is
|
206 | * explicitly specified the default value is <code>true</code> only if the port is
|
207 | * equal to the default secure port, otherwise <code>false</code>.
|
208 | * <p>
|
209 | * In case the client is being run in a page served via <code>https</code>, the
|
210 | * default secure port is the port of the URI of the current page, otherwise the
|
211 | * default secure port is <code>443</code>.</td>
|
212 | * </tr>
|
213 | * </tbody>
|
214 | * </table>
|
215 | *
|
216 | * <h5>Reconnection:</h5>
|
217 | *
|
218 | * Reconnection is enabled by default. The <code>reconnect</code> key accepts several different option values.
|
219 | * <table>
|
220 | * <thead>
|
221 | * <tr>
|
222 | * <th>Option type</th>
|
223 | * <th>Default value</th>
|
224 | * <th>Description</th>
|
225 | * </tr>
|
226 | * </thead>
|
227 | * <tbody>
|
228 | * <tr>
|
229 | * <td><code>boolean</code></td>
|
230 | * <td><code>true</code></td>
|
231 | * <td>Enables or disables reconnection. If set to <code>true</code>, reconnection will be enabled using the default
|
232 | * timeout value and a periodic back-off strategy.</td>
|
233 | * </tr>
|
234 | * <tr>
|
235 | * <td><code>number</code></td>
|
236 | * <td><code>60000</code></td>
|
237 | * <td>Passing a number will enable reconnection with the default strategy and the reconnection timeout set to the
|
238 | * specified value. The reconnection timeout determines how long, in milliseconds, the client will remain in a
|
239 | * <code>disconnected</code> state before the client is closed.</td>
|
240 | * </tr>
|
241 | * <tr>
|
242 | * <td><code>function</code></td>
|
243 | * <td><pre>
|
244 | * function(reconnect, abort) {
|
245 | * setTimeout(reconnect, 5000);
|
246 | * }</pre></td>
|
247 | * <td>A strategy function that will be called when the client enters a <code>disconnected</code> state, and
|
248 | * subsequently if attempts to reconnect fail. Two arguments are provided, <code>reconnect</code> and <code>abort</code>
|
249 | * - these are functions to be called within the strategy. The <code>reconnect</code> argument will initiate a
|
250 | * reconnect attempt. <code>abort</code> may be called to abort reconnection, in which case the client will be closed.
|
251 | * </td>
|
252 | * </tr>
|
253 | * <tr>
|
254 | * <td><pre>
|
255 | * {
|
256 | * timeout : <number>,
|
257 | * strategy : <function>
|
258 | * }</pre></td>
|
259 | * <td><pre>
|
260 | * {
|
261 | * timeout : 60000,
|
262 | * strategy : function(reconnect, abort) {
|
263 | * setTimeout(reconnect, 5000);
|
264 | * }
|
265 | * }</pre></td>
|
266 | * <td>An object containing both the timeout and strategy options as specified above, allowing both to be set together.
|
267 | * </td>
|
268 | * </tr>
|
269 | * </tbody>
|
270 | * </table>
|
271 | *
|
272 | * <h5>Transports:</h5>
|
273 | * The <code>transports</code> property configures how the session should connect. It can be set to either a
|
274 | * <code>string</code>, or an <code>array</code> of strings to provide a transport cascading capability.
|
275 | * <table>
|
276 | * <thead>
|
277 | * <tr>
|
278 | * <th>Transport key</th>
|
279 | * <th>Description</th>
|
280 | * </tr>
|
281 | * </thead>
|
282 | * <tbody>
|
283 | * <tr>
|
284 | * <td><code>ws</code>, <code>WS</code>, <code>WEBSOCKET</code></td>
|
285 | * <td>The WebSocket transport. A single, long-lived WebSocket connection will be used to send and receive data.</td>
|
286 | * </tr>
|
287 | * <tr>
|
288 | * <td><code>xhr</code>, <code>XHR</code>, <code>HTTP_POLLING</code></td>
|
289 | * <td>An XHR-based polling transport. Data will be queued on the client and server, and sent in batches.</td>
|
290 | * </tr>
|
291 | * </tbody>
|
292 | * </table>
|
293 | * The client will use the transports in the order provided, for example:
|
294 | * <code>transports: ['WS', 'XHR']</code> indicates that the client will attempt to connect with the WebSocket
|
295 | * transport, and if the connection fails, the client will attempt to connect with the HTTP Polling transport. When no
|
296 | * <code>transports</code> value is provided the client will default to using the WebSocket transport. Any string values
|
297 | * that do not have an associated transport will be ignored.
|
298 | *
|
299 | * <h5>Properties:</h5>
|
300 | *
|
301 | * Supplied session properties will be provided to the server when a session
|
302 | * is created using this session factory. The supplied properties will be
|
303 | * validated during authentication and may be discarded or changed.
|
304 | *
|
305 | * The specified properties will be added to any existing properties set for
|
306 | * this session factory. If any of the keys have been previously declared
|
307 | * then they will be overwritten with the new values.
|
308 | *
|
309 | * For details of how session properties are used see {@link Session}.
|
310 | */
|
311 | export interface Options {
|
312 | /**
|
313 | * The hostname to connect to (default `'localhost'`)
|
314 | */
|
315 | host?: string;
|
316 | /**
|
317 | * The port to connect to (default `443`)
|
318 | */
|
319 | port?: number | string;
|
320 | /**
|
321 | * The request path used for connections (default `/diffusion`)
|
322 | */
|
323 | path?: string;
|
324 | /**
|
325 | * Whether to use secure connections.
|
326 | */
|
327 | secure?: boolean;
|
328 | /**
|
329 | * The principal name this session should connect with. Used for authentication.
|
330 | */
|
331 | principal?: string;
|
332 | /**
|
333 | * A password string to authenticate with, a buffer containing custom
|
334 | * credentials in binary format, a typed array, or a regular
|
335 | * array of octets.
|
336 | */
|
337 | credentials?: string | Buffer | TypedArray | number[];
|
338 | /**
|
339 | * Reconnection options. (default `true`)
|
340 | */
|
341 | reconnect?: boolean | number | ReconnectStrategy | {
|
342 | timeout: number;
|
343 | strategy: ReconnectStrategy;
|
344 | };
|
345 | /**
|
346 | * The transports to be used for connection establishment. (default `"WEBSOCKET"`)
|
347 | */
|
348 | transports?: string | string[];
|
349 | /**
|
350 | * The maximum size of messages that may be received from the server. (default `2147483647`)
|
351 | */
|
352 | maxMessageSize?: number;
|
353 | /**
|
354 | * An object of key-value pairs that define the user-defined session properties.
|
355 | *
|
356 | * For details of how session properties are used see {@link Session}.
|
357 | */
|
358 | properties?: {
|
359 | [key: string]: string;
|
360 | };
|
361 | /**
|
362 | * An optional HTTP/HTTPS proxy agent. (default `undefined`)
|
363 | *
|
364 | * If this is set, then the client will attempt to connect to the Diffusion
|
365 | * server via a proxy server.
|
366 | *
|
367 | * The proxy agent will be passed to the WebSocket constructor as the
|
368 | * `agent` option. See https://www.npmjs.com/package/https-proxy-agent for
|
369 | * an example of a proxy agent.
|
370 | *
|
371 | * This option is used for web socket connections and is intended for Node
|
372 | * based clients only. Browser based clients will automatically use the
|
373 | * browser's proxy settings.
|
374 | *
|
375 | * **Example:**
|
376 | * ```
|
377 | * const HttpsProxyAgent = require('https-proxy-agent');
|
378 | * const url = require('url');
|
379 | * const diffusion = require('diffusion');
|
380 | *
|
381 | * const agent = new HttpsProxyAgent(url.parse('https://proxy.example.com:80'));
|
382 | *
|
383 | * diffusion.connect({
|
384 | * host: 'https://diffusion.foo.com',
|
385 | * httpProxyAgent: agent
|
386 | * }).then((session) => {
|
387 | * // connected through proxy server
|
388 | * });
|
389 | * ```
|
390 | */
|
391 | httpProxyAgent?: any;
|
392 | }
|
393 | /**
|
394 | * Alias for the Options interface to keep compatibility with old TypeScript definitions
|
395 | */
|
396 | export declare type SessionOptions = Options;
|
397 | /**
|
398 | * @module Session
|
399 | */
|
400 | /**
|
401 | * A session ID
|
402 | */
|
403 | export interface SessionId {
|
404 | /**
|
405 | * Convert the session ID to a string
|
406 | *
|
407 | * @return a string representation of the session ID
|
408 | */
|
409 | toString(): string;
|
410 | }
|
411 | /**
|
412 | * Diffusion Session. Handles a connection to Diffusion and exposes API
|
413 | * features. Sessions can subscribe, add, remove and update topics, as well as
|
414 | * perform remote operations on the server.
|
415 | *
|
416 | * A session represents a single connection to a single Diffusion server. A
|
417 | * session begins connected and will remain so until until it is explicitly
|
418 | * closed via {@link Session.close} or there is a connection error.
|
419 | *
|
420 | * When a connected session loses its connection to the server, it will close if
|
421 | * {@link Options} `reconnect` is not enabled. If reconnect is enabled
|
422 | * then the session will enter a `disconnected` state. Once disconnected, any
|
423 | * API methods that involve the server will automatically fail. It is possible
|
424 | * for a session to lose messages while disconnected.
|
425 | *
|
426 | * The session will attempt to reconnect to the server on a regular basis. This
|
427 | * will continue until the server responds; at which point the session will
|
428 | * attempt to recover its previous connection.
|
429 | *
|
430 | * If the reconnection is successful the session will become connected again and
|
431 | * emit a `reconnect` event. Any prior subscriptions will continue to receive
|
432 | * data.
|
433 | *
|
434 | * If the server rejects the reconnection, the session will be closed.
|
435 | *
|
436 | * Sessions emit events to notify listeners of changes in state. Certain events
|
437 | * will provide arguments to any callback functions that have been registered.
|
438 | *
|
439 | * <H3>Session properties</H3>
|
440 | *
|
441 | * For each session, the server stores a set of session properties that describe
|
442 | * various attributes of the session.
|
443 | *
|
444 | * There are two types of session property. Fixed properties are assigned by the
|
445 | * server. User-defined properties are assigned by the application.
|
446 | *
|
447 | * Many operations use session filter expressions (see section Session Filters)
|
448 | * that use session properties to select sessions.
|
449 | *
|
450 | * A privileged client can monitor other sessions, including changes to their
|
451 | * session properties, using a {@link ClientControl.setSessionPropertiesListener
|
452 | * session properties listener}. When registering to receive session properties,
|
453 | * special key values of {@link PropertyKeys.ALL_FIXED_PROPERTIES
|
454 | * ALL_FIXED_PROPERTIES} and {@link PropertyKeys.ALL_USER_PROPERTIES
|
455 | * ALL_USER_PROPERTIES} can be used.
|
456 | *
|
457 | * Each property is identified by a key. Most properties have a single string
|
458 | * value. The exception is the $Roles fixed property which has a set of string
|
459 | * values.
|
460 | *
|
461 | * Fixed properties are identified by keys with a '$' prefix. The available
|
462 | * fixed session properties are:
|
463 | *
|
464 | * <table>
|
465 | * <tr>
|
466 | * <td><b>Key</b></td>
|
467 | * <td><b>Description</b></td>
|
468 | * <tr>
|
469 | * <tr>
|
470 | * <td>`$ClientIP`</td>
|
471 | * <td>The Internet address of the client in string format. See
|
472 | * {@link ClientLocation}.address.</td>
|
473 | * </tr>
|
474 | * <tr>
|
475 | * <td>`$ClientType`</td>
|
476 | * <td>The client type of the session. One of `ANDROID`, `C`, `DOTNET`, `IOS`,
|
477 | * `JAVA`, `JAVASCRIPT_BROWSER`, or `OTHER`. Equivalent to {@link
|
478 | * ClientSummary}.clientType.</td>
|
479 | * </tr>
|
480 | * <tr>
|
481 | * <td>`$Connector`</td>
|
482 | * <td>The configuration name of the server connector that the client connected
|
483 | * to. See {@link SessionDetails}.connector.</td>
|
484 | * </tr>
|
485 | * <tr>
|
486 | * <td>`$Country`</td>
|
487 | * <td>The country code for the country where the client's Internet address was
|
488 | * allocated (for example, `NZ` for New Zealand). If the country code could not
|
489 | * be determined, this will be a zero length string. See {@link
|
490 | * ClientLocation}.details.country.</td>
|
491 | * </tr>
|
492 | * <tr>
|
493 | * <td>`$Language`</td>
|
494 | * <td>The language code for the official language of the country where the
|
495 | * client's Internet address was allocated (for example, `en` for English). If
|
496 | * the language could not be determined or is not applicable, this will be a
|
497 | * zero length string. See {@link ClientLocation}.details.language.</td>
|
498 | * </tr>
|
499 | * <tr>
|
500 | * <td>`$Latitude`</td>
|
501 | * <td>The client's latitude, if available. This will be the string
|
502 | * representation of a floating point number and will be `NaN` if not
|
503 | * available. See {@link ClientLocation}.coordinates.latitude.</td>
|
504 | * </tr>
|
505 | * <tr>
|
506 | * <td>`$Longitude`</td>
|
507 | * <td>The client's longitude, if available. This will be the string
|
508 | * representation of a floating point number and will be `NaN` if not
|
509 | * available. See {@link ClientLocation}.coordinates.longitude.</td>
|
510 | * </tr>
|
511 | * <tr>
|
512 | * <td>`$Principal`</td>
|
513 | * <td>The security principal associated with the client session. Equivalent to
|
514 | * {@link ClientSummary}.principal</td>
|
515 | * </tr>
|
516 | * <tr>
|
517 | * <td>`$Roles`</td>
|
518 | * <td>Authorisation roles assigned to the session. This is a set of roles
|
519 | * represented as quoted strings (for example, `"role1","role2"`). The
|
520 | * utility method {@link stringToRoles} can be used to parse
|
521 | * the string value into a set of roles.</td>
|
522 | * </tr>
|
523 | * <tr>
|
524 | * <td>`$ServerName`</td>
|
525 | * <td>The name of the server to which the session is connected. See
|
526 | * {@link SessionDetails}.server.</td>
|
527 | * </tr>
|
528 | * <tr>
|
529 | * <td>`$SessionId`</td>
|
530 | * <td>The session identifier. Equivalent to {@link Session.sessionID}.</td>
|
531 | * </tr>
|
532 | * <tr>
|
533 | * <td>`$StartTime`</td>
|
534 | * <td>The session's start time in milliseconds since the epoch.</td>
|
535 | * </tr>
|
536 | * <tr>
|
537 | * <td>`$Transport`</td>
|
538 | * <td>The session transport type. One of `WEBSOCKET`,
|
539 | * `HTTP_LONG_POLL`, or `OTHER`. Equivalent to
|
540 | * {@link ClientSummary}.transportType.</td>
|
541 | * </tr>
|
542 | * </table>
|
543 | *
|
544 | * All user-defined property keys are non-empty strings and are case-sensitve.
|
545 | * The characters ' ', '\t', '\r', '\n', '"', ''', '(', ')' are not allowed.
|
546 | *
|
547 | * Session properties are initially associated with a session as follows:<br>
|
548 | *
|
549 | * 1. When a client starts a new session, it can optionally propose
|
550 | * user-defined session properties (see {@link Options}.properties).
|
551 | * Session properties proposed in this way must be accepted by the
|
552 | * authenticator. This safeguard prevents abuse by a rogue, unprivileged client.
|
553 | * 2. The server allocates all fixed property values.
|
554 | * 3. The new session is authenticated by registered authenticators. An
|
555 | * authenticator that accepts a session can veto or change the user-defined
|
556 | * session properties and add new user-defined session properties. The
|
557 | * authenticator can also change certain fixed properties.
|
558 | *
|
559 | * Once a session is established, its user-defined session properties can be
|
560 | * modified by clients with `VIEW_SESSION` and `MODIFY_SESSION`
|
561 | * permissions using {@link ClientControl.setSessionProperties}.
|
562 | * A privileged client can also modify its own session properties.
|
563 | *
|
564 | * If a session re-authenticates (see {@link Security.changePrincipal
|
565 | * changePrincipal}), the authenticator that allows the re-authentication can
|
566 | * modify the user-defined session properties and a subset of the fixed
|
567 | * properties as mentioned above.
|
568 | *
|
569 | * <H3>Session filters</H3>
|
570 | *
|
571 | * Session filters are query expressions for session properties. They can be
|
572 | * used to address a set of sessions based on their session properties. For
|
573 | * example, it is possible to send a message to all sessions that satisfy a
|
574 | * specified filter. Session filters are parsed and evaluated at the server.
|
575 | *
|
576 | * A session filter expression consists of either a single clause, or multiple
|
577 | * clauses connected by the binary operators `and` and `or`. The
|
578 | * `and` operator takes precedence over `or` but parentheses can be
|
579 | * used to override the precedence. For example:
|
580 | * * `Department is "Accounts"`
|
581 | * * `hasRoles ["operator" "trading desk"]`
|
582 | * * `Department is "Payroll" and Status is "Closed"}`
|
583 | * * `(Department is "Accounts" or Department is "Payroll") and Status is "Closed"}`
|
584 | *
|
585 | * The boolean <b>not</b> operator may be used to negate the following clause or
|
586 | * an expression within parentheses:
|
587 | * * `not Department is "Payroll"`
|
588 | * * `not (Department is "Payroll" or Department is "Accounts")`
|
589 | *
|
590 | * An equality clause has the form <em>key operator value</em> where
|
591 | * <em>key</em> is the name of a session property and <em>value</em> is the
|
592 | * property value. The supported operators are `is` or `eq`, both of
|
593 | * which mean "equals", and `ne` which means "does not equal". Values are
|
594 | * strings enclosed within single or double quotes. Special characters
|
595 | * (`"`, `'` or `\`) can be included within the value by
|
596 | * preceding with the escape character `\`. The utility method
|
597 | * {@link escape} can be used to insert escape characters into
|
598 | * a value.
|
599 | *
|
600 | * `hasRoles` is a special operator for querying the `$Roles`
|
601 | * session property. A `hasRoles` clause has the form <em>hasRoles
|
602 | * ["role1" "role2" ... "roleN"]</em>. The clause will match sessions that have
|
603 | * all the specified authorisation roles. Each role is a string enclosed within
|
604 | * either single or double quotes. Roles can be space or comma separated.
|
605 | *
|
606 | * The `all` operator matches all sessions.
|
607 | *
|
608 | * The `$Roles` session property can also be queried with an equality
|
609 | * clause, for example, `$Roles eq '"admin","client"'`, but the
|
610 | * `hasRoles` clause is usually more convenient. An equality clause will
|
611 | * match sessions that have exactly the listed roles. In contrast, a
|
612 | * `hasRoles` clause will match any sessions with the listed roles,
|
613 | * regardless of whether they have other roles. The equality clause requires the
|
614 | * value to be in the canonical form produced by the
|
615 | * {@link rolesToString} utility method.
|
616 | * Supported operators are as follows:
|
617 | *
|
618 | * Operator | Description
|
619 | * ---------------- | -----------
|
620 | * **is** or **eq** | equals
|
621 | * **ne** | not equals
|
622 | *
|
623 | * All operators are case insensitive.
|
624 | *
|
625 | * The following are examples of valid expressions:
|
626 | *
|
627 | * * `$Principal is "Alice"`
|
628 | * * `Department is "Accounts" and $Country ne "US"`
|
629 | * * `$Language EQ "en" and $Country NE "US"`
|
630 | * * `not (Department is "Accounts" or`
|
631 | * * `"Department is "Payroll") and $Country is "FR"`
|
632 | * * `Text is "xyz\"\\"`
|
633 | * * `hasRoles ["operator"]}`
|
634 | * * `$Transport is "wss" and hasRoles ["accountancy" "administrator"]`
|
635 | * * `hasRoles ["operator"] and not hasRoles ["administrator"]`
|
636 | *
|
637 | * **Example:**
|
638 | * ```
|
639 | * // Establish a session
|
640 | * diffusion.connect('diffusion.example.com').then(function(session) {
|
641 | * // Attach state listeners
|
642 | * session.on({
|
643 | * disconnect : function() {
|
644 | * console.log('Disconnected!');
|
645 | * },
|
646 | * reconnect : function() {
|
647 | * console.log('Phew, reconnected!');
|
648 | * },
|
649 | * error : function(error) {
|
650 | * console.log('Session error', error);
|
651 | * },
|
652 | * close : function(reason) {
|
653 | * console.log('Session closed', reason);
|
654 | * }
|
655 | * });
|
656 | *
|
657 | * // Do something with session...
|
658 | * });
|
659 | * ```
|
660 | *
|
661 | * <h2>Events</h2>
|
662 | *
|
663 | * <h3 id="event-disconnect"><code>disconnect</code></h3>
|
664 | *
|
665 | * Emitted when a connected session has lost connection to the server, and
|
666 | * {@link Options} `reconnect` is enabled. The provided reason will
|
667 | * contain the specific cause of the session disconnect.
|
668 | *
|
669 | * **Parameters:**
|
670 | *
|
671 | * `reason`: {@link CloseReason} - the cause of the session disconnect
|
672 | *
|
673 | * <h3 id="event-reconnect"><code>reconnect</code></h3>
|
674 | *
|
675 | * Emitted when a disconnected session has successfully reconnected.
|
676 | *
|
677 | * <h3 id="event-close"><code>close</code></h3>
|
678 | *
|
679 | * Emitted when a session is closed. This can occur because it was closed by the
|
680 | * user, closed by the server, failed to connect, or the session encountered an
|
681 | * error. The provided close reason will contain the specific cause of the
|
682 | * session close.
|
683 | *
|
684 | * **Parameters:**
|
685 | *
|
686 | * `reason`: {@link CloseReason} - the cause of the session close
|
687 | *
|
688 | * <h3 id="event-error"><code>error</code></h3>
|
689 | *
|
690 | * Emitted when a session error has occurred. A session error occurs when the
|
691 | * client cannot parse communication from the server. This occurs if a component
|
692 | * between the two - for example, a proxy or load balancer - alters the
|
693 | * communication.
|
694 | *
|
695 | * **Parameters:**
|
696 | *
|
697 | * `error`: any - the error that occurred
|
698 | */
|
699 | export interface Session extends Stream, Topics, Ping {
|
700 | /**
|
701 | * The unique id assigned to this session by the server.
|
702 | */
|
703 | readonly sessionID: string;
|
704 | /**
|
705 | * The connection options used to establish this session
|
706 | */
|
707 | readonly options: Options;
|
708 | /**
|
709 | * Exposes system authentication capabilities via a {@link Session.security}
|
710 | */
|
711 | readonly security: Security;
|
712 | /**
|
713 | * Exposes topic control capabilities via {@link Session.topics}
|
714 | */
|
715 | readonly topics: TopicControl;
|
716 | /**
|
717 | * Exposes topic update capabilities via {@link Session.topicUpdate}
|
718 | */
|
719 | readonly topicUpdate: TopicUpdate;
|
720 | /**
|
721 | * Exposes topic views capabilities via {@link Session.topicViews}
|
722 | */
|
723 | readonly topicViews: TopicViews;
|
724 | /**
|
725 | * Exposes time series capabilities via {@link Session.timeseries}
|
726 | */
|
727 | readonly timeseries: TimeSeries;
|
728 | /**
|
729 | * Exposes messaging capabilities via {@link Session.messages}
|
730 | */
|
731 | readonly messages: Messages;
|
732 | /**
|
733 | * Exposes topic notification capabilities via {@link Session.notifications}
|
734 | */
|
735 | readonly notifications: TopicNotifications;
|
736 | /**
|
737 | * Exposes client control capabilities via {@link ClientControl}
|
738 | */
|
739 | readonly clients: ClientControl;
|
740 | /**
|
741 | * Close this session's connection to the server.
|
742 | *
|
743 | * Calling this repeatedly will have no effect.
|
744 | *
|
745 | * @return this session
|
746 | */
|
747 | close(): Session;
|
748 | /**
|
749 | * Close this session's connection to the server and return a {@link Result}
|
750 | * that will completes when the session is closed.
|
751 | *
|
752 | * @return a {@link Result} that completes with the close reason returned
|
753 | * by the server. Only the {@link Result} of the first call to
|
754 | * `closeSession` is guaranteed to complete. The {@link Result}
|
755 | * will not resolve if the session is already closed.
|
756 | */
|
757 | closeSession(): Result<CloseReason>;
|
758 | /**
|
759 | * Indicates if this session is currently closed, or in the process of
|
760 | * closing.
|
761 | *
|
762 | * This will not return `true` if the session is disconnected
|
763 | * but attempting to reconnect.
|
764 | *
|
765 | * @return whether the session is currently closed.
|
766 | */
|
767 | isClosed(): boolean;
|
768 | /**
|
769 | * Indicates if this session is currently connected.
|
770 | *
|
771 | * This is orthogonal to {@link Session.isClosed}, as a session may
|
772 | * be disconnected and attempting to reconnect.
|
773 | *
|
774 | * @return whether the session is currently connected or not.
|
775 | */
|
776 | isConnected(): boolean;
|
777 | /**
|
778 | * Returns the principal name that this session is associated with.
|
779 | *
|
780 | * @return the principal for this session
|
781 | */
|
782 | getPrincipal(): string;
|
783 | /**
|
784 | * Attempt to acquire a {@link SessionLock session lock}.
|
785 | *
|
786 | * This method returns a Promise that will resolve normally if
|
787 | * the server assigns the requested lock to the session. Otherwise, the
|
788 | * Promise will fail with an error indicating why the lock could not
|
789 | * be acquired.
|
790 | *
|
791 | * @param lockName the name of the session lock
|
792 | * @param scope preferred scope, defaults to
|
793 | * `UNLOCK_ON_SESSION_LOSS` . The scope of a lock controls
|
794 | * when it will be released automatically. If a session
|
795 | * makes multiple requests for a lock using different
|
796 | * scopes, and the server assigns the lock to the session
|
797 | * fulfilling the requests, the lock will be given the
|
798 | * weakest scope (`UNLOCK_ON_SESSION_LOSS` ).
|
799 | * @return a Promise that resolves when a response is received
|
800 | * from the server.
|
801 | * <p>
|
802 | * If this session has successfully acquired the session
|
803 | * lock, or this session already owns the session lock, the
|
804 | * Promise will resolve normally with a SessionLock result.
|
805 | * <p>
|
806 | * If the Promise resolves with an error, this session does
|
807 | * not own the session lock.
|
808 | *
|
809 | * @since 6.2
|
810 | */
|
811 | lock(lockName: string, scope?: SessionLockScope): Result<SessionLock>;
|
812 | }
|
813 | /**
|
814 | * @module diffusion.clients
|
815 | */
|
816 | /**
|
817 | * Details relating to the network and geographic location of a client session.
|
818 | */
|
819 | export interface ClientLocation {
|
820 | /**
|
821 | * the IP address of the client
|
822 | */
|
823 | address: string;
|
824 | /**
|
825 | * the host name
|
826 | */
|
827 | hostname: string;
|
828 | /**
|
829 | * the resolved name
|
830 | */
|
831 | resolved: string;
|
832 | /**
|
833 | * the country details
|
834 | */
|
835 | details: {
|
836 | /**
|
837 | * the country code for the country where the IP address was allocated
|
838 | */
|
839 | country: string;
|
840 | /**
|
841 | * the country code for the official language of the country where the
|
842 | * IP address was allocated
|
843 | */
|
844 | language: string;
|
845 | };
|
846 | /**
|
847 | * the geographic coordinates of the client if this could be ascertained
|
848 | */
|
849 | coordinates?: {
|
850 | /**
|
851 | * the latitude
|
852 | */
|
853 | latitude: number;
|
854 | /**
|
855 | * the longitude
|
856 | */
|
857 | longitude: number;
|
858 | };
|
859 | /**
|
860 | * the address type
|
861 | */
|
862 | type: AddressType;
|
863 | }
|
864 | /**
|
865 | * Enum containing possible Address types.
|
866 | */
|
867 | export declare enum AddressType {
|
868 | /**
|
869 | * The address is a standard global internet address
|
870 | */
|
871 | GLOBAL = 1,
|
872 | /**
|
873 | * The address is a site local address. The address is part of the IP subset that is reserved for private networks.
|
874 | */
|
875 | LOCAL = 2,
|
876 | /**
|
877 | * The address is assigned to the server loopback interface
|
878 | */
|
879 | LOOPBACK = 3,
|
880 | /**
|
881 | * The address type is unknown
|
882 | */
|
883 | UNKNOWN = 4,
|
884 | }
|
885 | /**
|
886 | * @module diffusion.clients
|
887 | */
|
888 | /**
|
889 | * Lightweight summary of a client session.
|
890 | */
|
891 | export interface ClientSummary {
|
892 | /**
|
893 | * The name of the principal associated with the session
|
894 | */
|
895 | principal: string;
|
896 | /**
|
897 | * The type of the client
|
898 | */
|
899 | clientType: ClientType;
|
900 | /**
|
901 | * The transport type
|
902 | */
|
903 | transportType: TransportType;
|
904 | }
|
905 | /**
|
906 | * Enum containing possible client types.
|
907 | */
|
908 | export declare enum ClientType {
|
909 | /**
|
910 | * JavaScript client
|
911 | */
|
912 | JAVASCRIPT_BROWSER = 0,
|
913 | /**
|
914 | * Android client
|
915 | */
|
916 | ANDROID = 3,
|
917 | /**
|
918 | * iOS client
|
919 | */
|
920 | IOS = 4,
|
921 | /**
|
922 | * Java client
|
923 | */
|
924 | JAVA = 8,
|
925 | /**
|
926 | * .NET client
|
927 | */
|
928 | DOTNET = 9,
|
929 | /**
|
930 | * C
|
931 | */
|
932 | C = 10,
|
933 | /**
|
934 | * Client type is not known to the local session, possibly because the remote client is using a different version
|
935 | * of Diffusion
|
936 | */
|
937 | OTHER = 12,
|
938 | }
|
939 | /**
|
940 | * Enum containing possible Transport types.
|
941 | */
|
942 | export declare enum TransportType {
|
943 | /**
|
944 | * WebSocket protocol
|
945 | */
|
946 | WEBSOCKET = 0,
|
947 | /**
|
948 | * HTTP long polling transport
|
949 | */
|
950 | HTTP_LONG_POLL = 1,
|
951 | /**
|
952 | * HTTP long poll, via HTML iFrame elements
|
953 | */
|
954 | IFRAME_LONG_POLL = 2,
|
955 | /**
|
956 | * HTTP 1.1 chunked transfer via HTML iFrame elements
|
957 | */
|
958 | IFRAME_STREAMING = 3,
|
959 | /**
|
960 | * Diffusion protocol based on TCP sockets
|
961 | */
|
962 | DPT = 4,
|
963 | /**
|
964 | * Diffusion protocol based on HTTP 1.1 chunked transfer
|
965 | */
|
966 | HTTPC = 5,
|
967 | /**
|
968 | * Diffusion protocol based on HTTP 1.1 chunked transfer
|
969 | */
|
970 | HTTPC_DUPLEX = 6,
|
971 | /**
|
972 | * Transport type is not known to the local session, possible because the remote client is using a different version
|
973 | * of Diffusion
|
974 | */
|
975 | OTHER = 7,
|
976 | }
|
977 | /**
|
978 | * A type containing information about the reason for a session being closed
|
979 | */
|
980 | export interface CloseReason {
|
981 | /**
|
982 | * The close reason's id
|
983 | */
|
984 | id: number;
|
985 | /**
|
986 | * The close reason's description
|
987 | */
|
988 | message: string;
|
989 | }
|
990 | /**
|
991 | * Enum representing the reason that the session has been closed.
|
992 | *
|
993 | * **Example:**
|
994 | * ```
|
995 | * diffusion.connect({...}).then(function(session) {...}, function(err) {
|
996 | * switch(err) {
|
997 | * case diffusion.clients.CloseReason.CLOSED_BY_CLIENT:
|
998 | * // Do something
|
999 | * case diffusion.clients.CloseReason.ACCESS_DENIED:
|
1000 | * // Do something else
|
1001 | * ...
|
1002 | * }
|
1003 | * });
|
1004 | * ```
|
1005 | *
|
1006 | */ export declare const CloseReasonEnum: {
|
1007 | [key: string]: CloseReason;
|
1008 | };
|
1009 | /**
|
1010 | * @module diffusion.clients
|
1011 | */
|
1012 | /**
|
1013 | * A set of details relating to a client session.
|
1014 | */
|
1015 | export interface SessionDetails {
|
1016 | /**
|
1017 | * available detail types
|
1018 | */
|
1019 | available: DetailType[];
|
1020 | /**
|
1021 | * the configuration name of the server connector the client is connected to,
|
1022 | * or `undefined` if unavailable
|
1023 | */
|
1024 | connector?: string;
|
1025 | /**
|
1026 | * server name or `undefined` if unavailable
|
1027 | */
|
1028 | server?: string;
|
1029 | /**
|
1030 | * client location or `undefined` if unavailable
|
1031 | */
|
1032 | location?: ClientLocation;
|
1033 | /**
|
1034 | * client summary or `undefined` if unavailable
|
1035 | */
|
1036 | summary?: ClientSummary;
|
1037 | }
|
1038 | /**
|
1039 | * Enum containing possible Session Detail types.
|
1040 | */
|
1041 | export declare enum DetailType {
|
1042 | SUMMARY = 0,
|
1043 | LOCATION = 1,
|
1044 | CONNECTOR_NAME = 2,
|
1045 | SERVER_NAME = 3,
|
1046 | }
|
1047 | /// <reference types="node" />
|
1048 | /**
|
1049 | * @module diffusion.datatypes
|
1050 | */
|
1051 | /**
|
1052 | * Read-only interface for values that are internally represented as binary
|
1053 | * data.
|
1054 | *
|
1055 | * This interface provides access to copies of the binary data, making instances
|
1056 | * effectively immutable. Methods of derived interfaces and classes that relax
|
1057 | * this restriction and expose access to the internal data should be clearly
|
1058 | * documented.
|
1059 | *
|
1060 | * @since 5.7
|
1061 | */
|
1062 | export interface Bytes {
|
1063 | /**
|
1064 | * Get the number of bytes
|
1065 | *
|
1066 | * @return The length of the data in bytes
|
1067 | */
|
1068 | length(): number;
|
1069 | /**
|
1070 | * Get a copy of the buffer containing this value.
|
1071 | *
|
1072 | * @return This value in binary form
|
1073 | */
|
1074 | asBuffer(): Buffer;
|
1075 | /**
|
1076 | * Copy the binary data to a provided buffer.
|
1077 | *
|
1078 | * @param target the buffer to copy data to
|
1079 | * @param offset the position in the target buffer at which data will be copied
|
1080 | */
|
1081 | copyTo(target: Buffer, offset?: number): void;
|
1082 | }
|
1083 | /// <reference types="node" />
|
1084 | /**
|
1085 | * @module diffusion.datatypes
|
1086 | */
|
1087 | /**
|
1088 | * A data type is specified for a particular value type. It provides methods to
|
1089 | * convert values to and from binary. Diffusion provides several {@link DataType}
|
1090 | * implementations.
|
1091 | *
|
1092 | * A data type can optionally support incremental changes to values, represented
|
1093 | * by one or more types of <em>delta</em>. A delta is the difference between two
|
1094 | * values. For large or composite values that change in small steps, it is more
|
1095 | * efficient to transmit an initial value followed by a delta for each change
|
1096 | * than to transmit a complete value for each change. The data type provides an
|
1097 | * implementation of {@link DeltaType} for each type of delta it
|
1098 | * supports via {@link DataType.deltaType}.
|
1099 | *
|
1100 | * @since 5.7
|
1101 | *
|
1102 | * @param <ValueType> the value type of the data type
|
1103 | * @param <SourceType> the type(s) from which a value can be constructed
|
1104 | * @param <CBORType> the binary type containing the CBOR data
|
1105 | */
|
1106 | export interface DataType<ValueType, SourceType, CBORType> {
|
1107 | /**
|
1108 | * The external type identifier.
|
1109 | *
|
1110 | * @return the name of this datatype
|
1111 | */
|
1112 | name(): string;
|
1113 | /**
|
1114 | * Parse a value from binary.
|
1115 | *
|
1116 | * @param input the binary data
|
1117 | * @param offset the offset to start reading from the provided buffer (default = `0`)
|
1118 | * @param length the length of the data to read (default = `input.length`)
|
1119 | * @returns an instance of this data type value
|
1120 | * @throws an error if the data is invalid for this type
|
1121 | */
|
1122 | readValue(input: Buffer, offset?: number, length?: number): ValueType | null;
|
1123 | readValue(input: CBORType): ValueType | null;
|
1124 | /**
|
1125 | * Serialise a value to binary
|
1126 | *
|
1127 | * @param value the value to serialise
|
1128 | * @returns the serialised value as a buffer
|
1129 | * @throws an error if the value can not be serialised
|
1130 | */
|
1131 | writeValue(value: SourceType): Buffer;
|
1132 | /**
|
1133 | * Test whether this data type is compatible with `valueType`. Compatibility
|
1134 | * with a `valueType` means than any valid binary representation of a
|
1135 | * `value` can be {@link DataType.readAs read as} an
|
1136 | * instance of `valueType`.
|
1137 | *
|
1138 | * Every data type should be compatible with the following:
|
1139 | *
|
1140 | * * `Value Type` – the class corresponding to the data type's value
|
1141 | * type.
|
1142 | *
|
1143 | * For a data type with a value type of `X`, `readAs(X, buffer)` is
|
1144 | * equivalent to `readValue(buffer)`.
|
1145 | *
|
1146 | * @param valueType the type to check
|
1147 | * @return `true` if a binary representation created by this data
|
1148 | * type can read as an instance * of `valueType`
|
1149 | * @since 6.0
|
1150 | */
|
1151 | canReadAs(valueType: new (...args: any[]) => any): boolean;
|
1152 | /**
|
1153 | * Create a value of a compatible class from binary.
|
1154 | *
|
1155 | * @param valueType the type of the result
|
1156 | * @param buffer the binary data
|
1157 | * @param offset the offset to start reading from the provided buffer (default = `0`)
|
1158 | * @param length the length of the data to read (default = `input.length`)
|
1159 | * @return the value in the form of the specified type
|
1160 | * @throws an error if `valueType` is incompatible with this data
|
1161 | * type, or `buffer` does not * represent a valid value.
|
1162 | * @since 6.0
|
1163 | */
|
1164 | readAs(valueType: new (...args: any[]) => any, buffer: Buffer, offset?: number, length?: number): any | null;
|
1165 | readAs(valueType: new (...args: any[]) => any, buffer: CBORType): any | null;
|
1166 | /**
|
1167 | * Obtain a {@link DeltaType} by name or delta type.
|
1168 | *
|
1169 | * **Example:**
|
1170 | * ```
|
1171 | * // Get by name
|
1172 | * var deltas = datatype.deltaType("binary");
|
1173 | * ```
|
1174 | *
|
1175 | * **Example:**
|
1176 | * ```
|
1177 | * // Get by type
|
1178 | * var deltas = datatype.deltaType(delta);
|
1179 | * ```
|
1180 | *
|
1181 | * @param name the name, as returned by {@link DeltaType.name}
|
1182 | * @returns the delta type
|
1183 | */
|
1184 | deltaType(name?: string): DeltaType<ValueType, SourceType, CBORType>;
|
1185 | }
|
1186 | /**
|
1187 | * @module diffusion.datatypes
|
1188 | */
|
1189 | /**
|
1190 | * Diffusion datatype implementations.
|
1191 | *
|
1192 | * Datatypes are accessed via the `diffusion` singleton.
|
1193 | *
|
1194 | * **Example:**
|
1195 | * ```
|
1196 | * // Get the JSON datatype
|
1197 | * var json = diffusion.datatypes.json();
|
1198 | * ```
|
1199 | *
|
1200 | * **Example:**
|
1201 | * ```
|
1202 | * // Get a datatype via name
|
1203 | * var json = diffusion.datatypes.get('json');
|
1204 | * ```
|
1205 | * @namespace diffusion.datatypes
|
1206 | * @since 5.7
|
1207 | */
|
1208 | export interface DataTypes {
|
1209 | /**
|
1210 | * Get the binary data type
|
1211 | *
|
1212 | * @return the Binary data type
|
1213 | */
|
1214 | binary(): BinaryDataType;
|
1215 | /**
|
1216 | * Get the JSON data type
|
1217 | *
|
1218 | * @return the JSON data type
|
1219 | */
|
1220 | json(): JSONDataType;
|
1221 | /**
|
1222 | * Get the Int64 data type
|
1223 | *
|
1224 | * @return the Int64 data type
|
1225 | */
|
1226 | int64(): Int64DataType;
|
1227 | /**
|
1228 | * Get the string data type
|
1229 | *
|
1230 | * @return the String data type
|
1231 | */
|
1232 | string(): StringDataType;
|
1233 | /**
|
1234 | * Get the double data type
|
1235 | *
|
1236 | * @return the Double data type
|
1237 | */
|
1238 | double(): DoubleDataType;
|
1239 | /**
|
1240 | * Get the record V2 data type
|
1241 | *
|
1242 | * @return the RecordV2 data type
|
1243 | */
|
1244 | recordv2(): RecordV2DataType;
|
1245 | /**
|
1246 | * Get the timeseries data type
|
1247 | *
|
1248 | * @param valueType the value type of the timeseries data type
|
1249 | * @return a timeseries data type
|
1250 | */
|
1251 | timeseries<ValueType, SourceType>(valueType: DataType<ValueType, SourceType, any>): DataType<Event<ValueType>, Event<SourceType>, Bytes>;
|
1252 | /**
|
1253 | * Obtain a {@link DataType} implementation by type
|
1254 | * name, topic type, or value class
|
1255 | *
|
1256 | * @param name the type name as returned by {@link DataType.name}, the value
|
1257 | * or a topic type.
|
1258 | * @return the data type or `null` if no datatype was found
|
1259 | */
|
1260 | get(name: any): DataType<any, any, any> | null;
|
1261 | /**
|
1262 | * Obtain a {@link DataType} implementation by value class.
|
1263 | *
|
1264 | * For {@link DoubleDataType}, the associated value class is `Number`.
|
1265 | *
|
1266 | * @param valueClass the class
|
1267 | * @return the data type
|
1268 | * @throws an Error if there is no data type for provided class
|
1269 | */
|
1270 | getByClass(valueClass: new (...args: any[]) => any): DataType<any, any, any>;
|
1271 | }
|
1272 | /// <reference types="node" />
|
1273 | /**
|
1274 | * @module diffusion.datatypes
|
1275 | */
|
1276 | /**
|
1277 | * Optional extension provided by {@link DataType} implementations that support
|
1278 | * incremental changes to values.
|
1279 | *
|
1280 | * Each implementation specifies a `value` type and a `delta` type.
|
1281 | * Two values, oldValue and new Value, can be compared to produce a delta using
|
1282 | * {@link DeltaType.diff}. The delta can be separately applied to oldValue to
|
1283 | * create newValue using {@link DeltaType.apply}.
|
1284 | *
|
1285 | * <h5>Deferred parsing</h5>
|
1286 | * Implementations can choose not to fully validate values when they are read,
|
1287 | * but instead defer parsing until it is required. Consequently, all methods
|
1288 | * that accept values may throw an error.
|
1289 | *
|
1290 | * @param <ValueType> the value type of the data type
|
1291 | * @param <SourceType> the type(s) from which a value can be constructed
|
1292 | * @param <CBORType> the binary type containing the CBOR data
|
1293 | *
|
1294 | * @since 5.7
|
1295 | */
|
1296 | export interface DeltaType<ValueType, SourceType, CBORType> {
|
1297 | /**
|
1298 | * The name of this delta type
|
1299 | *
|
1300 | * @returns the name
|
1301 | */
|
1302 | name(): string;
|
1303 | /**
|
1304 | * Create a delta from two values.
|
1305 | *
|
1306 | * If there are many differences between oldValue and newValue, the result
|
1307 | * might require more bytes to transmit than the new value, or be
|
1308 | * computationally expensive to apply. In this case, it is better to discard
|
1309 | * oldValue and publish newValue in its place. This can be checked using
|
1310 | * {@link DeltaType.isValueCheaper}.
|
1311 | *
|
1312 | * The implementation can return the special constant {@link DeltaType.noChange}
|
1313 | * to indicate the old value and new value are equivalent and there is no change
|
1314 | * to publish.
|
1315 | *
|
1316 | * @param oldValue the old value
|
1317 | * @param newValue the new value
|
1318 | * @return the delta between values
|
1319 | */
|
1320 | diff(oldValue: SourceType, newValue: SourceType): BinaryDelta;
|
1321 | /**
|
1322 | * Apply a delta to a value.
|
1323 | *
|
1324 | * @param old the old value
|
1325 | * @param delta the delta to apply
|
1326 | * @return the new value generated applying the delta to the old value
|
1327 | * @throws an error if the value or delta is invalid
|
1328 | */
|
1329 | apply(oldValue: SourceType, delta: BinaryDelta): ValueType | null;
|
1330 | /**
|
1331 | * Parse a delta from binary.
|
1332 | *
|
1333 | * @param binary the binary data
|
1334 | * @param offset the offset from which to start reading from the buffer
|
1335 | * @param length the length of data to read from the buffer
|
1336 | * @return the delta
|
1337 | * @throws an error if the binary is invalid
|
1338 | */
|
1339 | readDelta(buffer: Buffer, offset?: number, length?: number): BinaryDelta;
|
1340 | /**
|
1341 | * Serialise a delta to binary.
|
1342 | *
|
1343 | * @param delta the delta to serialise
|
1344 | * @return the serialised form of the delta
|
1345 | * @throws an error if the delta cannot be serialised
|
1346 | */
|
1347 | writeDelta(delta: BinaryDelta): Buffer;
|
1348 | /**
|
1349 | * Constant returned by {@link DeltaType.diff} to
|
1350 | * indicate that both values are equivalent.
|
1351 | *
|
1352 | * @return unique object representing no change in value
|
1353 | */
|
1354 | noChange(): BinaryDelta;
|
1355 | /**
|
1356 | * Calculate if `value` is cheaper than the `delta`. The
|
1357 | * result is typically determined by the length of the serialised form, but may
|
1358 | * also consider the complexity of the delta.
|
1359 | *
|
1360 | * @param value the value to compare
|
1361 | * @param delta the delta to compare
|
1362 | * @return `true` if the value is considered cheaper than the delta
|
1363 | * @throws an error if the value or delta is invalid
|
1364 | */
|
1365 | isValueCheaper(value: SourceType, delta: BinaryDelta): boolean;
|
1366 | }
|
1367 | /**
|
1368 | * A type containing information about the reason that an error occured
|
1369 | */
|
1370 | export interface ErrorReasonType {
|
1371 | /**
|
1372 | * The error reason's id
|
1373 | */
|
1374 | id: number;
|
1375 | /**
|
1376 | * The error reason's description
|
1377 | */
|
1378 | reason: string;
|
1379 | }
|
1380 | /**
|
1381 | * Enum containing reason codes used to report error conditions.
|
1382 | * <p>
|
1383 | * Some common ErrorReason values are defined as global constants. More specific reasons may be defined by
|
1384 | * individual features.
|
1385 | *
|
1386 | * **Example:**
|
1387 | * ```
|
1388 | * // Handle an error from the server
|
1389 | * session.addStream('foo', diffusion.datatypes.string()).on('error', function(e) {
|
1390 | * if (e == diffusion.errors.ACCESS_DENIED) {
|
1391 | * // Handle authorisation error
|
1392 | * } else {
|
1393 | * // Log the problem
|
1394 | * console.log(e);
|
1395 | * }
|
1396 | * });
|
1397 | * ```
|
1398 | */ export declare const ErrorReason: {
|
1399 | [key: string]: ErrorReasonType;
|
1400 | };
|
1401 | /**
|
1402 | * @module diffusion.events
|
1403 | */
|
1404 | /**
|
1405 | * Provides a stream of topic values for a given fetch request.
|
1406 | *
|
1407 | * FetchStream inherits all functions defined on {@link Stream}.
|
1408 | *
|
1409 | * **Example:**
|
1410 | * ```
|
1411 | * // Handle all events from stream
|
1412 | * session.fetch("foo").on({
|
1413 | * open : function() {
|
1414 | * // Fetch stream has opened, values will be emitted after this event.
|
1415 | * },
|
1416 | * value : function(value, topicPath) {
|
1417 | * // Received topic value
|
1418 | * },
|
1419 | * error : function(err) {
|
1420 | * // Encountered an error
|
1421 | * },
|
1422 | * close : function() {
|
1423 | * // Fetch stream closed; no more values will be received
|
1424 | * }
|
1425 | * });
|
1426 | * ```
|
1427 | *
|
1428 | * <h2>Events</h2>
|
1429 | *
|
1430 | * <h3><code>open</code></h3>
|
1431 | *
|
1432 | * Emitted when the fetch stream is initially opened. This will only be fired once.
|
1433 | *
|
1434 | * <h3><code>value</code></h3>
|
1435 | *
|
1436 | * Emitted when a topic that is selected by the fetch request's topic selector
|
1437 | * has returned its value. By default, values are provided as
|
1438 | * `Buffer` instances. The topic path specifies which topic this
|
1439 | * value is for.
|
1440 | *
|
1441 | * **Parameters:**
|
1442 | *
|
1443 | * `value`: any - the new value of the topic
|
1444 | *
|
1445 | * `topicPath`: string - the path to the topic to which the value update applies
|
1446 | *
|
1447 | * <h3><code>close</code></h3>
|
1448 | * <h3><code>error</code></h3>
|
1449 | */ export interface FetchStream extends Stream {
|
1450 | }
|
1451 | /**
|
1452 | * @module diffusion.events
|
1453 | */
|
1454 | /**
|
1455 | * A reference to a registered handler.
|
1456 | *
|
1457 | * Such a handler reference is provided whenever a handler with a server side
|
1458 | * presence is registered.
|
1459 | */
|
1460 | export interface Registration {
|
1461 | /**
|
1462 | * Request that the handler is unregistered from the server.
|
1463 | *
|
1464 | * After the handler is unregistered, the handler's `onClose` method
|
1465 | * will be called.
|
1466 | *
|
1467 | * A handler can only be unregistered once. A given instance will return the
|
1468 | * same Result if this method is called more than once.
|
1469 | *
|
1470 | * @returns a {@link Result} that completes when a response is received from
|
1471 | * the server
|
1472 | */
|
1473 | close(): Result<void>;
|
1474 | }
|
1475 | /**
|
1476 | * @module diffusion.events
|
1477 | */
|
1478 | export declare type Callback<U> = (error: any) => U;
|
1479 | /**
|
1480 | * A Result represents a promise for the result of an async operation.
|
1481 | *
|
1482 | * It implements the full ES6 Promise specification and is in all respects equivalent to a Promise.
|
1483 | *
|
1484 | * Adapted from https://www.npmjs.com/package/@types/es6-promise
|
1485 | */
|
1486 | export declare type Result<R> = Promise<R>;
|
1487 | /**
|
1488 | * @module diffusion.events
|
1489 | *
|
1490 | * @brief A module containing event streams
|
1491 | *
|
1492 | * @preferred
|
1493 | */
|
1494 | /**
|
1495 | * A callback function type for {@link Stream}s
|
1496 | */
|
1497 | export declare type StreamCallback = (...args: any[]) => void;
|
1498 | /**
|
1499 | * A type mapping event names to callback functions
|
1500 | */
|
1501 | export interface CallbackMap {
|
1502 | [event: string]: StreamCallback;
|
1503 | }
|
1504 | /**
|
1505 | * A {@link Stream} provides a series of events that may be consumed by
|
1506 | * arbitrary listeners. The events emitted by a stream are defined by the
|
1507 | * operation that created the stream and can carry event-specific arguments.
|
1508 | *
|
1509 | * A stream is created in an open state, and may immediately emit events. When a
|
1510 | * Stream is closed it will emit a `close`. A closed stream will not
|
1511 | * emit any further events, and will remain closed permanently.
|
1512 | *
|
1513 | * It is possible for a stream to encounter an error. In this case, an `error` event will be emitted, and
|
1514 | * then the stream will be closed.
|
1515 | *
|
1516 | * This is a primitive class that is used to provide common event binding methods to other API components.
|
1517 | *
|
1518 | * @fires {@link error}
|
1519 | * @fires {@link close}
|
1520 | */
|
1521 | export interface Stream {
|
1522 | /**
|
1523 | * Register listeners against events.
|
1524 | *
|
1525 | * A single listener may be bound to an event by passing the event name and
|
1526 | * listener function.
|
1527 | *
|
1528 | * Multiple listeners may be bound by passing in a {@link CallbackMap},
|
1529 | * mapping event names to listener functions.
|
1530 | *
|
1531 | * **Example:**
|
1532 | * ```
|
1533 | * // Bind a single listener to the 'foo' event
|
1534 | * stream.on('foo', function(arg1, arg2) {
|
1535 | * console.log("Called for 'foo' event", arg1, arg2);
|
1536 | * });
|
1537 | * ```
|
1538 | *
|
1539 | * **Example:**
|
1540 | * ```
|
1541 | * // Bind multiple listeners
|
1542 | * stream.on({
|
1543 | * foo : function() { ... },
|
1544 | * bar : function() { ... },
|
1545 | * baz : function() { ... }
|
1546 | * });
|
1547 | * ```
|
1548 | *
|
1549 | * @param events the event name or {@link CallbackMap} mapping event names
|
1550 | * to listeners
|
1551 | * @param listener the listener to bind to the event, if passed as string.
|
1552 | * This argument is ignored if the first argument is a
|
1553 | * {@link CallbackMap}.
|
1554 | * @return this stream.
|
1555 | */
|
1556 | on(events: string | CallbackMap, listener?: StreamCallback): Stream;
|
1557 | /**
|
1558 | * Remove a listener from a specified event.
|
1559 | *
|
1560 | * **Example:**
|
1561 | * ```
|
1562 | * // Bind a single listener to the 'foo' event and then deregister it
|
1563 | * var listener = function() {};
|
1564 | * stream.on('foo', listener);
|
1565 | * stream.off('foo', listener);
|
1566 | * ```
|
1567 | *
|
1568 | * **Example:**
|
1569 | * ```
|
1570 | * // Bind a listener to the 'foo' event and deregister all listeners
|
1571 | * var listener = function() {};
|
1572 | * stream.on('foo', listener);
|
1573 | * stream.off('foo');
|
1574 | * ```
|
1575 | *
|
1576 | * @param event the event name to remove or {@link CallbackMap} mapping
|
1577 | * event names to listeners which will be removed
|
1578 | * @param listener the listener to remove. All listeners for the event are
|
1579 | * removed if this is not specified. This argument is
|
1580 | * ignored if the first argument is a {@link CallbackMap}.
|
1581 | * @return this stream.
|
1582 | */
|
1583 | off(events: string | CallbackMap, listener?: StreamCallback): Stream;
|
1584 | /**
|
1585 | * Close the stream. This will emit a 'close' event to any assigned listeners.
|
1586 | * No further events will be emitted.
|
1587 | */
|
1588 | close(): void;
|
1589 | }
|
1590 | /**
|
1591 | * Emitted when an error occurs in the {@link Stream} or in any of its listeners.
|
1592 | * No further events will be emitted after this.
|
1593 | *
|
1594 | * @param error the error that occurred
|
1595 | *
|
1596 | * @event
|
1597 | */
|
1598 | export declare type error = (err: Error) => void;
|
1599 | /**
|
1600 | * Emitted when the {@link Stream} has been closed through completion or the underlying session has been closed.
|
1601 | * No further events will be emitted after this.
|
1602 | *
|
1603 | * @param error the reason why the stream was closed
|
1604 | *
|
1605 | * @event
|
1606 | */
|
1607 | export declare type close = (reason?: string) => void;
|
1608 | /**
|
1609 | * @module diffusion.events
|
1610 | */
|
1611 | export interface SubscriptionEvent {
|
1612 | /**
|
1613 | * The topic to which the subscription applies
|
1614 | */
|
1615 | topic: string;
|
1616 | /**
|
1617 | * Instance that contains details about the topic
|
1618 | */
|
1619 | specification: TopicSpecification;
|
1620 | }
|
1621 | export interface UnsubscriptionEvent {
|
1622 | /**
|
1623 | * The topic to which the unsubscription applies
|
1624 | */
|
1625 | topic: string;
|
1626 | /**
|
1627 | * Instance that contains details about the topic
|
1628 | */
|
1629 | specification: TopicSpecification;
|
1630 | }
|
1631 | /**
|
1632 | * Provides a stream of topic events, specific to the topic selector that this ValueStream was created for, with
|
1633 | * topic values provided as instances of the associated {@link DataType}.
|
1634 | *
|
1635 | * ValueStream inherits all functions defined on {@link Stream}.
|
1636 | *
|
1637 | * **Example:**
|
1638 | * ```
|
1639 | * // Create a value stream for topic 'foo'
|
1640 | * session.addStream('foo', datatype).on('value', function(topic, specification, newValue, oldValue) {
|
1641 | * // Receive updates for the topic 'foo'
|
1642 | * });
|
1643 | *
|
1644 | * // Then subscribe to topic 'foo'
|
1645 | * session.select('foo');
|
1646 | * ```
|
1647 | *
|
1648 | * **Example:**
|
1649 | * ```
|
1650 | * // Attach multiple listeners for events
|
1651 | * session.addStream('foo', datatype).on({
|
1652 | * subscribe : function(topic, specification) {
|
1653 | * // Subscribed to a particular topic
|
1654 | * },
|
1655 | * unsubscribe : function(topic, specification, reason) {
|
1656 | * // Unsubscribed from a particular topic
|
1657 | * },
|
1658 | * value : function(topic, specification, newValue, oldValue) {
|
1659 | * // Value from a topic
|
1660 | * }
|
1661 | * });
|
1662 | * ```
|
1663 | *
|
1664 | * <h2>Events</h2>
|
1665 | *
|
1666 | * <h3 id="event-open"><code>open</code></h3>
|
1667 | *
|
1668 | * Emitted when the subscription is initially opened, passing a reference to the
|
1669 | * subscription itself. This will only be fired once.
|
1670 | *
|
1671 | * <h3 id="event-subscribe"><code>subscribe</code></h3>
|
1672 | *
|
1673 | * Emitted when a topic that is selected by this ValueStream's topic selector is
|
1674 | * subscribed to by this session. Once subscribed, <code>value</code> update
|
1675 | * events may be received for this topic. The specification is a {@link
|
1676 | * TopicSpecification} instance that contains details about the topic.
|
1677 | *
|
1678 | * **Parameters:**
|
1679 | *
|
1680 | * `topic`: string - The topic to which the subscription applies
|
1681 | *
|
1682 | * `specification`: {@link TopicSpecification} - Instance that contains details about the topic
|
1683 | *
|
1684 | * <h3 id="event-unsubscribe"><code>unsubscribe</code></h3>
|
1685 | *
|
1686 | * Emitted when a topic that was previously subscribed, has been unsubscribed.
|
1687 | * No further update events will be received from this topic until subscribed
|
1688 | * again. Unsubscriptions may occur due to the topic being removed, or through
|
1689 | * calling {@link Session.unsubscribe} - an object containing the reason is
|
1690 | * provided.
|
1691 | *
|
1692 | * **Parameters:**
|
1693 | *
|
1694 | * `topic`: string - The topic to which the unsubscription applies
|
1695 | *
|
1696 | * `specification`: {@link TopicSpecification} - Instance that contains details about the topic
|
1697 | *
|
1698 | * `reason`: {@link UnsubscribeReason} - the reason for the unsubscription
|
1699 | *
|
1700 | * <h3 id="event-value"><code>value</code></h3>
|
1701 | *
|
1702 | * Emitted when an update has been received for a topic's value. Values will be
|
1703 | * provided as instances appropriate for the associated {@link DataType} this
|
1704 | * subscription was created for. Both the previous value and the new value are
|
1705 | * provided.
|
1706 | *
|
1707 | * **Parameters:**
|
1708 | *
|
1709 | * `topic`: string - The topic to which the update applies
|
1710 | *
|
1711 | * `specification`: {@link TopicSpecification} - Instance that contains details about the topic
|
1712 | *
|
1713 | * `newValue`: any - the new value of the topic
|
1714 | *
|
1715 | * `oldValue`: any - the old value of the topic
|
1716 | *
|
1717 | * <h3><code>close</code></h3>
|
1718 | *
|
1719 | * Emitted when the subscription has been closed using {@link ValueStream.close}.
|
1720 | *
|
1721 | * <h3><code>error</code></h3>
|
1722 | *
|
1723 | * Emitted when the subscription request fails. No further events will be emitted after this.
|
1724 | *
|
1725 | * **Parameters:**
|
1726 | *
|
1727 | * `error`: {@link ErrorReason} - the error the subscription request failed with
|
1728 | */
|
1729 | export interface ValueStream extends Stream {
|
1730 | /**
|
1731 | * A static reference to the selector this Subscription was created for.
|
1732 | */
|
1733 | readonly selector: TopicSelector;
|
1734 | /**
|
1735 | * Close the stream. No further events will be emitted.
|
1736 | *
|
1737 | * This does not unsubscribe the topic. Other streams may still receive
|
1738 | * updates for the same topic selector. To unsubscribe, use {@link
|
1739 | * Session.unsubscribe}
|
1740 | */
|
1741 | close(): void;
|
1742 | }
|
1743 | /**
|
1744 | * @module diffusion.clients
|
1745 | */
|
1746 | export interface PropertyKeys {
|
1747 | ALL_FIXED_PROPERTIES: string[];
|
1748 | ALL_USER_PROPERTIES: string[];
|
1749 | ALL_PROPERTIES: string[];
|
1750 | SESSION_ID: string;
|
1751 | PRINCIPAL: string;
|
1752 | CONNECTOR: string;
|
1753 | TRANSPORT: string;
|
1754 | CLIENT_TYPE: string;
|
1755 | COUNTRY: string;
|
1756 | LANGUAGE: string;
|
1757 | SERVER_NAME: string;
|
1758 | CLIENT_IP: string;
|
1759 | LATITUDE: string;
|
1760 | LONGITUDE: string;
|
1761 | START_TIME: string;
|
1762 | ROLES: string;
|
1763 | }
|
1764 | /**
|
1765 | * @hidden
|
1766 | */
|
1767 | export interface ClientControlOptionsNamespace {
|
1768 | PropertyKeys: PropertyKeys;
|
1769 | ANONYMOUS: string;
|
1770 | ClientType: typeof ClientType;
|
1771 | TransportType: typeof TransportType;
|
1772 | AddressType: typeof AddressType;
|
1773 | DetailType: typeof DetailType;
|
1774 | CloseReason: typeof CloseReasonEnum;
|
1775 | }
|
1776 | export declare const ClientControlOptions: ClientControlOptionsNamespace;
|
1777 | /**
|
1778 | * @module Session.clients
|
1779 | */
|
1780 | export interface SessionProperties {
|
1781 | [key: string]: string | null;
|
1782 | }
|
1783 | /**
|
1784 | * Event types used within {@link SessionPropertiesListener.onSessionEvent}.
|
1785 | *
|
1786 | * **Example:**
|
1787 | * ```
|
1788 | * session.clients.setSessionPropertiesListener(props, {
|
1789 | * // ...
|
1790 | *
|
1791 | * onSessionEvent : function(sessionID, event, properties, previous) {
|
1792 | * switch (event) {
|
1793 | * case session.clients.SessionEventType.DISCONNECTED :
|
1794 | * console.log(sessionID + " has disconnected");
|
1795 | * break;
|
1796 | * case session.clients.SessionEventType.RECONNECTED :
|
1797 | * console.log(sessionID + " has reconnected");
|
1798 | * break;
|
1799 | * }
|
1800 | * }
|
1801 | *
|
1802 | * // ...
|
1803 | * });
|
1804 | * ```
|
1805 | */
|
1806 | export declare enum SessionEventType {
|
1807 | /**
|
1808 | * One or more relevant session properties have been updated.
|
1809 | */
|
1810 | UPDATED = 0,
|
1811 | /**
|
1812 | * A session has reconnected.
|
1813 | */
|
1814 | RECONNECTED = 1,
|
1815 | /**
|
1816 | * A session has failed over from one server to another in a cluster.
|
1817 | */
|
1818 | FAILED_OVER = 2,
|
1819 | /**
|
1820 | * A session has disconnected.
|
1821 | */
|
1822 | DISCONNECTED = 3,
|
1823 | }
|
1824 | /**
|
1825 | * Client control feature.
|
1826 | *
|
1827 | * Provides the ability for a client session to control other client sessions.
|
1828 | *
|
1829 | * **Example:**
|
1830 | * ```
|
1831 | * var clients = session.clients;
|
1832 | * ```
|
1833 | */
|
1834 | export interface ClientControl {
|
1835 | /**
|
1836 | * Event types used within
|
1837 | * {@link SessionPropertiesListener.onSessionEvent}
|
1838 | */ readonly SessionEventType: typeof SessionEventType;
|
1839 | /**
|
1840 | * Close a client session.
|
1841 | *
|
1842 | * **Example:**
|
1843 | * ```
|
1844 | * session.clients.close(otherSessionID).then(function() {
|
1845 | * // Other session has been closed
|
1846 | * }, function(err) {
|
1847 | * // There was an error when trying to close the other session
|
1848 | * });
|
1849 | * ```
|
1850 | *
|
1851 | * @param sessionId identifies the client session to close
|
1852 | * @return a {@link Result} for this operation.
|
1853 | */
|
1854 | close(sessionId: string | SessionId): Result<void>;
|
1855 | /**
|
1856 | * Subscribe one or more client sessions to topics.
|
1857 | *
|
1858 | * To subscribe a single known session, a session id may be provided;
|
1859 | * alternatively, a Session Filter may be used, in which case all sessions
|
1860 | * that satisfy the filter will be subscribed.
|
1861 | *
|
1862 | * The second argument of this function can be a string, a {@link
|
1863 | * TopicSelector}, or a non-empty of strings and {@link TopicSelector}s.
|
1864 | *
|
1865 | * **Example:**
|
1866 | * ```
|
1867 | * // Subscribe a single session via SessionID
|
1868 | * session.clients.subscribe(otherSessionID, ">foo").then(function() {
|
1869 | * // Subscribed 'otherSession' to topic "foo"
|
1870 | * }, function(err) {
|
1871 | * // Subscription failed
|
1872 | * console.log("Failed to subscribe session", err);
|
1873 | * });
|
1874 | * ```
|
1875 | *
|
1876 | * **Example:**
|
1877 | * ```
|
1878 | * // Subscribe multiple sesssions via a Session Filter
|
1879 | * session.clients.subscribe("$ClientType IS 'JAVA'", ">foo").then(function(selected) {
|
1880 | * console.log("Subscribed " + selected + " sessions to topic 'foo'");
|
1881 | * }, function(err) {
|
1882 | * // Subscription failed
|
1883 | * console.log("Failed to subscribe sessions", err);
|
1884 | * });
|
1885 | * ```
|
1886 | *
|
1887 | * @param session the Session ID or Session Filter
|
1888 | * @param selector the Topic Selector to subscribe to
|
1889 | * @return a {@link Result} for this operation. If
|
1890 | * subscribing with a session filter, the success callback
|
1891 | * will be given the number of sessions selected by the
|
1892 | * filter
|
1893 | */
|
1894 | subscribe(session: string | SessionId, selector: string | TopicSelector | Array<string | TopicSelector>): Result<number | void>;
|
1895 | /**
|
1896 | * Unsubscribe one or more client sessions from topics.
|
1897 | *
|
1898 | * To unsubscribe a single known session, a session id may be provided;
|
1899 | * alternatively, a Session Filter may be used, in which case all sessions
|
1900 | * that satisfy the filter will be unsubscribed.
|
1901 | *
|
1902 | * The second argument of this function can be a string, a {@link
|
1903 | * TopicSelector}, or a non-empty of strings and {@link TopicSelector}s.
|
1904 | *
|
1905 | * **Example:**
|
1906 | * ```
|
1907 | * // Unsubscribe a single session via SessionID
|
1908 | * session.clients.unsubscribe(otherSessionID, ">foo").then(function() {
|
1909 | * // Unsubscribed 'otherSession' from topic "foo"
|
1910 | * }, function(err) {
|
1911 | * // Unsubscription failed
|
1912 | * console.log("Failed to unsubscribe session", err);
|
1913 | * });
|
1914 | * ```
|
1915 | *
|
1916 | * **Example:**
|
1917 | * ```
|
1918 | * // Unsubscribe multiple sesssions via a Session Filter
|
1919 | * session.clients.unsubscribe("$ClientType IS 'JAVA'", ">foo").then(function(selected) {
|
1920 | * console.log("Unsubscribed " + selected + " sessions from topic 'foo'");
|
1921 | * }, function(err) {
|
1922 | * // Unsubscription failed
|
1923 | * console.log("Failed to unsubscribe sessions", err);
|
1924 | * });
|
1925 | * ```
|
1926 | *
|
1927 | * @param session the Session ID or Session Filter
|
1928 | * @param selector the Topic Selector to unsubscribe from
|
1929 | * @return a {@link Result} for this operation. If
|
1930 | * unsubscribing with a session filter, the success
|
1931 | * callback will be given the number of sessions selected
|
1932 | * by the filter
|
1933 | */
|
1934 | unsubscribe(session: string | SessionId, selector: string | TopicSelector | Array<string | TopicSelector>): Result<number | void>;
|
1935 | /**
|
1936 | * Query the server for property values of a specified client session.
|
1937 | *
|
1938 | * See {@link PropertyKeys} for a list of the available
|
1939 | * fixed property keys.
|
1940 | *
|
1941 | * To request all fixed properties {@link
|
1942 | * PropertyKeys.ALL_FIXED_PROPERTIES ALL_FIXED_PROPERTIES}
|
1943 | * may be included as the key.
|
1944 | *
|
1945 | * To request all user properties {@link
|
1946 | * PropertyKeys.ALL_USER_PROPERTIES ALL_USER_PROPERTIES}
|
1947 | * may be included as the key.
|
1948 | *
|
1949 | * **Example:**
|
1950 | * ```
|
1951 | * // Get values of all fixed properties for client whose session id is 'id'.
|
1952 | * session.clients.getSessionProperties(id, PropertyKeys.ALL_FIXED_PROPERTIES);
|
1953 | * ```
|
1954 | *
|
1955 | * **Example:**
|
1956 | * ```
|
1957 | * // Get values of the 'FOO' and 'BAR' properties for client whose session id is 'id'.
|
1958 | * session.clients.getSessionProperties(id, ['FOO', 'BAR']).then(function(properties) {
|
1959 | * console.log('Received properties for session', properties);
|
1960 | * }, function(err) {
|
1961 | * console.log('Unable to receive properties: ', err);
|
1962 | * });
|
1963 | * ```
|
1964 | *
|
1965 | * @param sessionID identifies the client session.
|
1966 | * @param properties specifies the keys of the property values required.
|
1967 | * @returns a {@link Result} for this operation
|
1968 | */
|
1969 | getSessionProperties(session: string | SessionId, properties?: string[]): Result<SessionProperties>;
|
1970 | /**
|
1971 | * Send a request to the server to change the user-defined session
|
1972 | * properties for a session.
|
1973 | *
|
1974 | * **Example:**
|
1975 | * ```
|
1976 | * // Add a new session property for client whose session id is 'id'.
|
1977 | * session.clients.setSessionProperties(id, { 'foo': 'bar' });
|
1978 | *
|
1979 | * // Remove a session property for client whose session id is 'id'.
|
1980 | * session.clients.setSessionProperties(id, { 'foo': null }).then(function(properties) {
|
1981 | * console.log('Properties changed ', properties);
|
1982 | * }, function(err) {
|
1983 | * console.log('Unable to change properties: ', err);
|
1984 | * });
|
1985 | * ```
|
1986 | *
|
1987 | * @param session identifies the client session
|
1988 | * @param properties the properties to change. Each entry in the map is a
|
1989 | * property name and the new value. If the value is
|
1990 | * `null` , any existing property with that
|
1991 | * name will be removed. Otherwise if the property name
|
1992 | * does not match any existing property, that entry will
|
1993 | * be added as a new property.
|
1994 | * @returns a {@link Result} for this operation. If the session properties
|
1995 | * were updated, the result type is a map of properties that
|
1996 | * changed with their previous values. If no properties were
|
1997 | * changed, the map will be empty. If any new properties were
|
1998 | * added, the values in the map will be `null` to indicate that
|
1999 | * they do not have an old value.
|
2000 | * <p>
|
2001 | * Otherwise, an error will be returned. Common reasons for
|
2002 | * failure include:
|
2003 | * <p>
|
2004 | * * {@link ErrorReason.ACCESS_DENIED} if the calling session
|
2005 | * does not have sufficient permission.
|
2006 | * * {@link ErrorReason.NO_SUCH_SESSION} if the calling session
|
2007 | * is closed before the response was delivered.
|
2008 | * * {@link ErrorReason.SESSION_CLOSED} if the calling session
|
2009 | * is closed.
|
2010 | *
|
2011 | */
|
2012 | setSessionProperties(session: string | SessionId, properties: SessionProperties | Map<string, string | null>): Result<SessionProperties>;
|
2013 | /**
|
2014 | * Send a request to the server to set all sessions that satisfy a session
|
2015 | * filter with the new user-defined session properties.
|
2016 | *
|
2017 | * **Example:**
|
2018 | * ```
|
2019 | * // Remove session property {job=employee}
|
2020 | * session.clients.setSessionPropertiesByFilter("job is 'employee'", { 'job': null }).then(function () {
|
2021 | * // All sessions satisfied the filter have updated their properties
|
2022 | * }, function (err) {
|
2023 | * console.log("Failed to update properties ", err);
|
2024 | * });
|
2025 | * ```
|
2026 | * @param filter session filter
|
2027 | * @param properties the properties to change. Each entry in the map is a
|
2028 | * property name and the new value. If the value is
|
2029 | * `null` , any existing property with that name will be
|
2030 | * removed. Otherwise if the property name does not match
|
2031 | * any existing property, that entry will be added as a
|
2032 | * new property.
|
2033 | *
|
2034 | * @returns a {@link Result} for this operation. The operation can fail,
|
2035 | * common reasons for failure include:
|
2036 | * <ul>
|
2037 | * <li> {@link ErrorReason.ACCESS_DENIED} if the calling session
|
2038 | * does not have sufficient permission.</li>
|
2039 | * <li> {@link ErrorReason.NO_SUCH_SESSION} if the calling
|
2040 | * session is closed before the response was delivered.
|
2041 | * <li> {@link ErrorReason.SESSION_CLOSED} if the calling
|
2042 | * session is closed.
|
2043 | * </ul>
|
2044 | */
|
2045 | setSessionPropertiesByFilter(filter: string, properties: SessionProperties | Map<string, string | null>): Result<void>;
|
2046 | /**
|
2047 | * Register a listener that will be notified when client sessions are
|
2048 | * opened, disconnected, reconnected, closed or when selected session
|
2049 | * property values are updated.
|
2050 | *
|
2051 | * When a listener is first set, it will be called with the required
|
2052 | * properties of all currently open client sessions. The amount of data
|
2053 | * transferred from the server is proportional to the number of connected
|
2054 | * clients and is potentially large. The amount of data can be reduced
|
2055 | * using the requiredProperties parameter.
|
2056 | *
|
2057 | * The requested property set controls the level of detail provided and
|
2058 | * whether the listener is called for updates to sessions. If no
|
2059 | * properties are requested then the listener is not called when session
|
2060 | * properties are updated.
|
2061 | *
|
2062 | * To request all fixed properties {@link
|
2063 | * PropertyKeys.ALL_FIXED_PROPERTIES ALL_FIXED_PROPERTIES}
|
2064 | * should be included as a key and any other fixed property keys would be
|
2065 | * ignored. To request all user properties {@link
|
2066 | * PropertyKeys.ALL_USER_PROPERTIES ALL_USER_PROPERTIES}
|
2067 | * should be included as a key and any other user property keys supplied
|
2068 | * would be ignored.
|
2069 | *
|
2070 | * **Example:**
|
2071 | * ```
|
2072 | * // Specify desired properties to listen to
|
2073 | * var props = diffusion.clients.PropertyKeys.ALL_FIXED_PROPERTIES;
|
2074 | *
|
2075 | * // Create the listener
|
2076 | * var listener = {
|
2077 | * onActive : function(deregister) {
|
2078 | * // Listener is active
|
2079 | * },
|
2080 | * onSessionOpen : function(sessionID, properties) {
|
2081 | * // A session has been opened
|
2082 | * },
|
2083 | * onSessionEvent : function(sessionID, event, properties, previous) {
|
2084 | * // A session's properties have changed (specified by 'event')
|
2085 | * },
|
2086 | * onSessionClose : function(sessionID, properties, reason) {
|
2087 | * // A session has closed
|
2088 | * },
|
2089 | * onClose : function() {
|
2090 | * // Listener is closed
|
2091 | * }
|
2092 | * }
|
2093 | * session.clients.setSessionPropertiesListener(props, listener).then(function() {
|
2094 | * // Registration was succesful
|
2095 | * }, function(err) {
|
2096 | * // There was an error registering the session listener
|
2097 | * });
|
2098 | * ```
|
2099 | *
|
2100 | * @param properties a set of required property keys.
|
2101 | * @param listener the listener to register
|
2102 | * @returns a {@link Result} for this operation.
|
2103 | */
|
2104 | setSessionPropertiesListener(properties: string[], listener: SessionPropertiesListener): Result<void>;
|
2105 | /**
|
2106 | * Changes the assigned roles of one or more sessions.
|
2107 | *
|
2108 | * Initially a session has a set of roles assigned during authentication.
|
2109 | * The set of assigned roles can be obtained from the session's `$Roles`
|
2110 | * {@link Session session} property.
|
2111 | *
|
2112 | * When a session's assigned roles change, its `$Roles` property changes
|
2113 | * accordingly. Changing the assigned roles can change the `READ_TOPIC`
|
2114 | * permissions granted to the session. The session's subscriptions will be
|
2115 | * updated accordingly.
|
2116 | *
|
2117 | * The same role must not occur in both `rolesToRemove` and
|
2118 | * `rolesToAdd` sets. Either set can be an empty set but not both.
|
2119 | *
|
2120 | * @param sessions either a {@link SessionId} that identifies a single
|
2121 | * client session, or a filter that identifies the set
|
2122 | * of client sessions for which the change will be
|
2123 | * applied
|
2124 | * @param rolesToRemove a set of roles to be removed from the session. If
|
2125 | * one or more roles from the list are not currently
|
2126 | * assigned, they are ignored.
|
2127 | * @param rolesToAdd a set of roles to be added to the session. If one or
|
2128 | * more roles from the list are already assigned, they
|
2129 | * are ignored.
|
2130 | * @return a Result that resolves when session roles have been changed.
|
2131 | * <p>
|
2132 | * If successful, the result resolves with an integer value which
|
2133 | * represents a number of sessions that have matched the filter and
|
2134 | * for which the specified role changes have been applied.
|
2135 | * <p>
|
2136 | * Otherwise, the Result fails with an Error. Common reasons for
|
2137 | * failure include:
|
2138 | * <ul>
|
2139 | * <li>the calling session does not have `MODIFY_SESSION` and
|
2140 | * `VIEW_SESSION` permission;
|
2141 | * <li>a `SessionId` was supplied and there is no session with
|
2142 | * the given `sessionId`;
|
2143 | * <li>a filter string was supplied that could not be parsed
|
2144 | * <li>the calling session is closed.
|
2145 | * </ul>
|
2146 | *
|
2147 | * @since 6.3
|
2148 | */
|
2149 | changeRoles(sessions: SessionId | string, rolesToRemove: string[] | Set<string>, rolesToAdd: string[] | Set<string>): Result<number>;
|
2150 | }
|
2151 | /**
|
2152 | * The Session Properties Listener interface for receiving session property
|
2153 | * events. This interface must be implemented by the user, to be registered via
|
2154 | * {@link ClientControl.setSessionPropertiesListener}.
|
2155 | *
|
2156 | * A session properties listener has a lifecycle that reflects the registration
|
2157 | * state on the server. This is expressed through the callback methods. Once
|
2158 | * {@link SessionPropertiesListener.onClose onClose} has been
|
2159 | * called, no further interactions will occur.
|
2160 | */
|
2161 | export interface SessionPropertiesListener {
|
2162 | /**
|
2163 | * Called when the listener has been registered at the server and is now
|
2164 | * active.
|
2165 | *
|
2166 | * @param deregister a function to call that will deregister and close this
|
2167 | * handler.
|
2168 | */
|
2169 | onActive(deregister: () => void): void;
|
2170 | /**
|
2171 | * Called when the listener is deregistered, or the session is closed.
|
2172 | */
|
2173 | onClose(): void;
|
2174 | /**
|
2175 | * Notification of a contextual error related to this handler. This is
|
2176 | * analogous to an unchecked exception being raised. Situations in which
|
2177 | * onError is called include the session being closed before the
|
2178 | * handler is registered, a communication timeout, or a problem with the
|
2179 | * provided parameters. No further calls will be made to this handler.
|
2180 | *
|
2181 | * @param error the error
|
2182 | *
|
2183 | * @since 5.9
|
2184 | */
|
2185 | onError(error: any): void;
|
2186 | /**
|
2187 | * Notification that a new client session has been opened.
|
2188 | *
|
2189 | * When the listener is registered, this will be called for all existing
|
2190 | * sessions. It will then be called for every client session that opens
|
2191 | * whilst the listener is registered.
|
2192 | *
|
2193 | * This will be called for client session regardless of requested session
|
2194 | * properties.
|
2195 | *
|
2196 | * @param session the session identifier
|
2197 | * @param properties the map of requested session property values.
|
2198 | */
|
2199 | onSessionOpen(session: SessionId, properties: SessionProperties): void;
|
2200 | /**
|
2201 | * Notification of a session event that can result in a change of properties.
|
2202 | *
|
2203 | * @param session the session identifier
|
2204 | * @param type the type of event
|
2205 | * @param properties the map of requested property values
|
2206 | * @param previous a map of previous values for keys that have changed.
|
2207 | * This will only contain changed values and not the
|
2208 | * whole required property set.
|
2209 | */
|
2210 | onSessionEvent(session: SessionId, type: SessionEventType, properties: SessionProperties, previous: SessionProperties): void;
|
2211 | /**
|
2212 | * Notification that a client session has closed.
|
2213 | *
|
2214 | * This will be called for every client that closes whilst the listener is
|
2215 | * registered, regardless of requested session properties.
|
2216 | *
|
2217 | * @param session the session identifier
|
2218 | * @param properties the map of requested property values
|
2219 | * @param reason the reason why the session was closed
|
2220 | */
|
2221 | onSessionClose(session: SessionId, properties: SessionProperties, reason: {}): void;
|
2222 | }
|
2223 | /// <reference types="node" />
|
2224 | /**
|
2225 | * @module Session.messages
|
2226 | */
|
2227 | /**
|
2228 | * The priority of the message. Higher priorities are delivered faster.
|
2229 | *
|
2230 | * @deprecated since 6.2
|
2231 | *
|
2232 | * This is only used within one-way messaging, which is deprecated
|
2233 | * from this release. This enum will be removed in a future
|
2234 | * release.
|
2235 | */
|
2236 | export declare enum Priority {
|
2237 | /**
|
2238 | * Indicates that messages should be delivered with normal priority.
|
2239 | */
|
2240 | NORMAL = 0,
|
2241 | /**
|
2242 | * Indicates that messages should be delivered with high priority.
|
2243 | */
|
2244 | HIGH = 1,
|
2245 | /**
|
2246 | * Indicates that messages should be delivered with low priority.
|
2247 | */
|
2248 | LOW = 2,
|
2249 | }
|
2250 | /**
|
2251 | * Messages Feature.
|
2252 | *
|
2253 | * This feature provides a client session with messaging capabilities. Each
|
2254 | * message is delivered to a request stream registered with the server.
|
2255 | * Additionally, the server and other clients can send messages to be received
|
2256 | * using this feature.
|
2257 | *
|
2258 | * Message requests are sent and received for a particular path. The message
|
2259 | * path provides a hierarchical context for the recipient.
|
2260 | *
|
2261 | * Message paths are distinct from topic paths. A topic with the path need not
|
2262 | * exist on the server; if a topic does exist, it is unaffected by messaging. An
|
2263 | * application can use the same path to associate messages with topics, or an
|
2264 | * arbitrary path can be chosen.
|
2265 | *
|
2266 | * A message request sent directly to another session is discarded if the
|
2267 | * receiving session is no longer connected or does not have a stream that
|
2268 | * matches the message path - an error is returned to the sending session in
|
2269 | * this case.
|
2270 | *
|
2271 | * Handlers for receiving messages are registered for a path. Each session may
|
2272 | * register at most one handler for a given path. When dispatching a message,
|
2273 | * the server will consider all registered handlers and select one registered
|
2274 | * for the most specific path. If multiple sessions have registered a handler
|
2275 | * for the same path, one will be chosen arbitrarily.
|
2276 | *
|
2277 | * When registering handlers to receive messages it is also possible to indicate
|
2278 | * that certain session properties (see {@link Session} for a full description
|
2279 | * of session properties), should be delivered with each message from a client
|
2280 | * session. The current values of the named properties for the originating
|
2281 | * session will be delivered with the message.
|
2282 | *
|
2283 | * Messages can also be sent using 'filters', (see {@link Session} for a full
|
2284 | * description of session filters), where the message is delivered to all
|
2285 | * sessions that satisfy a particular filter expression.
|
2286 | *
|
2287 | * Messages from other clients are received via {@link RequestStream streams}.
|
2288 | * Streams receive an {@link RequestStream.onClose onClose} callback when
|
2289 | * unregistered and an {@link RequestStream.onError onError} callback if the
|
2290 | * session is closed.
|
2291 | *
|
2292 | * <H3>Request-Response Messaging</H3>
|
2293 | *
|
2294 | * Typed request-response messaging allows applications to send requests (of
|
2295 | * type T) and receive responses (of type R) in the form of a {@link Result}.
|
2296 | * Using Messaging, applications send requests to paths using {@link
|
2297 | * Messages.sendRequest sendRequest}. In order to receive requests, applications
|
2298 | * must have a local request stream assigned to the specific path, using {@link
|
2299 | * Messages.setRequestStream setRequestStream}. When a request is received, the
|
2300 | * {@link RequestStream.onRequest onRequest} method on the stream is triggered,
|
2301 | * to which a response can be sent using the provided {@link
|
2302 | * Responder.respond respond} method call.
|
2303 | *
|
2304 | * <H3>One-way Messaging (deprecated)</H3>
|
2305 | *
|
2306 | * One-way messaging allows a client to send an untyped message to be sent to a
|
2307 | * path and be notified that the message has been delivered. No response is
|
2308 | * possible.
|
2309 | *
|
2310 | * A client can listen for one-way messages for a selection of paths by {@link
|
2311 | * listen adding} one or more {@link MessageStream} implementations. The mapping
|
2312 | * of selectors to message streams is maintained locally in the client process.
|
2313 | * Any number of message streams for inbound messages can be added on various
|
2314 | * selectors.
|
2315 | *
|
2316 | * <H3>Access control</H3>
|
2317 | *
|
2318 | * A client session needs {@link TopicPermission.SEND_TO_MESSAGE_HANDLER
|
2319 | * SEND_TO_MESSAGE_HANDLER} permission for the message paths to which it sends
|
2320 | * messages. If a client sends messages to a message path for which it does not
|
2321 | * have permission, the message is discarded by the server.
|
2322 | *
|
2323 | * <H3>Accessing the feature</H3>
|
2324 | *
|
2325 | * Obtain this feature from a {@link Session session} as follows:
|
2326 | *
|
2327 | * **Example:**
|
2328 | * ```
|
2329 | * // Get a reference to messaging feature
|
2330 | * var messages = session.messages;
|
2331 | * ```
|
2332 | */
|
2333 | export interface Messages {
|
2334 | /**
|
2335 | * The Priority enum
|
2336 | */ readonly Priority: typeof Priority;
|
2337 | /**
|
2338 | * Send an arbitrary message to either the server or another session, on a
|
2339 | * particular path.
|
2340 | *
|
2341 | * The path does not need to correspond to an existing topic; however the
|
2342 | * use of `/` as a hierarchical delimiter allows for other sessions to
|
2343 | * listen to messages from specific paths.
|
2344 | *
|
2345 | * The message content may be of any type that can be used for topic {@link
|
2346 | * TopicControl.update updates}. It is up to any receiving session to
|
2347 | * de-serialize it as appropriate.
|
2348 | *
|
2349 | * An optional argument may be provided to target a specific session or a
|
2350 | * collection of sessions that satisfy a given filter string. Messages sent
|
2351 | * will be received if that session has established a {@link MessageStream}
|
2352 | * for the same message path. The ability to send messages to specific
|
2353 | * sessions or via a filter is determined by permissions assigned to the
|
2354 | * sender.
|
2355 | *
|
2356 | * If no session ID or filter is given, the message will be sent to the
|
2357 | * server and dispatched to a control client that has registered a {@link
|
2358 | * MessageHandler} for the same, or higher, path. There is no guarantee that
|
2359 | * a MessageHandler will have been established for the path that the message
|
2360 | * is sent on.
|
2361 | *
|
2362 | * If no recipient is specified, a successful result will resolve with a
|
2363 | * single object containing the `path` that the message was sent to.
|
2364 | *
|
2365 | * If a session ID was used as the recipient, then the result will resolve
|
2366 | * with an object containing both `path` and `recipient` fields. The result
|
2367 | * will only resolve when the message has been successfully received by the
|
2368 | * intended recipient.
|
2369 | *
|
2370 | * If a session filter was used to send the message, then the result will
|
2371 | * contain `path`, `recipient`, `sent` and `errors` fields. The `sent` field
|
2372 | * specifies the number of sessions that the filter resolved and
|
2373 | * successfully sent the message to. The `errors` field contains an array of
|
2374 | * errors for any session that could not receive the message.
|
2375 | *
|
2376 | * **Example:**
|
2377 | * ```
|
2378 | * // Send a message to be received by the server and passed to a MessageHandler
|
2379 | * session.messages.send('foo', 123);
|
2380 | * ```
|
2381 | *
|
2382 | * **Example:**
|
2383 | * ```
|
2384 | * // Send a message to a specific session
|
2385 | * session.messages.send('bar', 'hello', sessionID);
|
2386 | * ```
|
2387 | *
|
2388 | * **Example:**
|
2389 | * ```
|
2390 | * // Send a message with a filter
|
2391 | * session.messages.send('baz', 'world', '$Principal is 'john'');
|
2392 | * ```
|
2393 | *
|
2394 | * @param path the message path
|
2395 | * @param message the message value
|
2396 | * @param options the optional message send options
|
2397 | * @param target the target recipient's session ID (as a string or
|
2398 | * ession ID object) or a session property filter string.
|
2399 | * @returns the {@link Result} of the send operation
|
2400 | *
|
2401 | * @deprecated since 6.2
|
2402 | *
|
2403 | * One-way messaging is deprecated in favor of request-response
|
2404 | * messaging. Use {@link Messages.sendRequest
|
2405 | * sendRequest} instead. This method will be removed in a future
|
2406 | * release.
|
2407 | */ send(path: string, message: any, options: SendOptions, target: string | SessionId): Result<MessageSendResult>;
|
2408 | send(path: string, message: any, target: string | SessionId): Result<MessageSendResult>;
|
2409 | /**
|
2410 | * Listen to a stream of messages sent to this Session for a particular
|
2411 | * path. Messages will be received as {@link Message
|
2412 | * message} instances.
|
2413 | *
|
2414 | * The message content is dependent on the sender. Correct parsing of the
|
2415 | * message content from a `Buffer` is up to the consuming session.
|
2416 | *
|
2417 | * Received messages do not indicate which session sent them; if sender
|
2418 | * information is required then this should be included within the message
|
2419 | * content.
|
2420 | *
|
2421 | * The first argument of this function can be a string, a {@link
|
2422 | * TopicSelector}, or a non-empty array of strings and {@link TopicSelector}s.
|
2423 | *
|
2424 | * **Example:**
|
2425 | * ```
|
2426 | * // Create with a default listener function
|
2427 | * session.messages.listen('foo', function(message) {
|
2428 | * // Do something with the message
|
2429 | * });
|
2430 | * ```
|
2431 | *
|
2432 | * **Example:**
|
2433 | * ```
|
2434 | * // Create a message stream and consume from it
|
2435 | * var stream = session.messages.listen('foo');
|
2436 | *
|
2437 | * stream.on('message', function(message) {
|
2438 | * // Do something with the message
|
2439 | * });
|
2440 | * ```
|
2441 | *
|
2442 | * @param path the message path or paths to listen to
|
2443 | * @param listener the default listener
|
2444 | * @returns a stream providing messages received on the specific path
|
2445 | *
|
2446 | * @deprecated since 6.2
|
2447 | *
|
2448 | * One-way messaging is deprecated in favor of request-response
|
2449 | * messaging. See {@link sendRequest} and
|
2450 | * {@link sendRequestToFilter}. This method
|
2451 | * will be removed in a future release.
|
2452 | */
|
2453 | listen(path: string | TopicSelector | Array<string | TopicSelector>, listener: (message: Message) => void): MessageStream;
|
2454 | /**
|
2455 | * Register a {@link MessageHandler MessageHandler} to
|
2456 | * receive messages that were sent from other sessions for a particular
|
2457 | * path but with no specified recipient. The handler must implement the
|
2458 | * {@link MessageHandler MessageHandler} interface.
|
2459 | *
|
2460 | * The provided handler will be passed messages received on the same path
|
2461 | * used for registration, or any lower branches. A session may only register
|
2462 | * a single handler for a given path at a time.
|
2463 | *
|
2464 | * The message content is dependent on the sender. Correct parsing of the
|
2465 | * message content from a `Buffer` is up to the consuming handler.
|
2466 | *
|
2467 | * Unlike {@link Messages.listen}, received messages provide the
|
2468 | * sender's SessionId.
|
2469 | *
|
2470 | * **Example:**
|
2471 | * ```
|
2472 | * // Create a message handler
|
2473 | * var handler = {
|
2474 | * onMessage : function(message) {
|
2475 | * console.log(message); // Log the received message
|
2476 | * },
|
2477 | * onActive : function(unregister) {
|
2478 | *
|
2479 | * },
|
2480 | * onClose : function() {
|
2481 | *
|
2482 | * }
|
2483 | * };
|
2484 | *
|
2485 | * // Register the handler
|
2486 | * session.messages.addHandler('foo/bar', handler).then(function() {
|
2487 | * // Registration happened successfully
|
2488 | * }, function(error) {
|
2489 | * // Registration failed
|
2490 | * });
|
2491 | * ```
|
2492 | *
|
2493 | *
|
2494 | * @param path the message path to handle
|
2495 | * @param handler the message handler
|
2496 | * @param keys message keys to register for this session
|
2497 | * @returns the registration {@link Result} that completes when the
|
2498 | * handler has been registered.
|
2499 | *
|
2500 | * @deprecated since 6.2
|
2501 | *
|
2502 | * One-way messaging is deprecated in favor of request-response
|
2503 | * messaging. See {@link sendRequest} and
|
2504 | * {@link sendRequestToFilter}. This method
|
2505 | * will be removed in a future release.
|
2506 | */ addHandler(path: string, handler: MessageHandler, keys?: string[]): Result<void>;
|
2507 | /**
|
2508 | * Register a request handler to handle requests from other client sessions
|
2509 | * on a path.
|
2510 | *
|
2511 | * **Example:**
|
2512 | * ```
|
2513 | * // Create a request handler that handles strings
|
2514 | * var handler = {
|
2515 | * onRequest: function(request, context, responder) {
|
2516 | * console.log(request); // Log the request
|
2517 | * responder.respond('something');
|
2518 | * },
|
2519 | * onError: function() {},
|
2520 | * onClose: function() {}
|
2521 | * };
|
2522 | *
|
2523 | * // Register the handler
|
2524 | * control.messages.addRequestHandler('test/topic', handler).then(function() {
|
2525 | * // Registration happened successfully
|
2526 | * }, function(error) {
|
2527 | * // Registration failed
|
2528 | * });
|
2529 | * ```
|
2530 | *
|
2531 | * @param path the request path to handle
|
2532 | * @param handler request handler to be registered at the server
|
2533 | * @param sessionProperties an optional array containing session properties
|
2534 | * that should be included with each request
|
2535 | * @param requestType an optional request data type
|
2536 | * @returns the registration {@link Result}
|
2537 | */
|
2538 | addRequestHandler(path: string, handler: RequestHandler, sessionProperties?: string[], requestType?: DataType<any, any, any>): Result<Registration>;
|
2539 | /**
|
2540 | * Send a request.
|
2541 | *
|
2542 | * A response is returned when the {Result} is complete.
|
2543 | *
|
2544 | * **Example:**
|
2545 | * ```
|
2546 | * // Send a string request to be received by the server and passed to a
|
2547 | * // {Session.messages.RequestHandler} registered on the supplied topic
|
2548 | * session.messages.sendRequest('test/topic', 'string request');
|
2549 | * ```
|
2550 | *
|
2551 | * **Example:**
|
2552 | * ```
|
2553 | * // Send a JSON request to be received by the server and passed to a
|
2554 | * // {Session.messages.RequestHandler} registered on the supplied topic
|
2555 | * session.messages.sendRequest('test/topic', diffusion.datatypes.json()
|
2556 | * .from({ 'foo': 'bar'}), diffusion.datatypes.json());
|
2557 | * ```
|
2558 | *
|
2559 | * **Example:**
|
2560 | * ```
|
2561 | * // Send an implicit JSON request to be received by the server and passed to a
|
2562 | * // {Session.messages.RequestHandler} registered on the supplied topic
|
2563 | * session.messages.sendRequest('test/topic', {
|
2564 | * dwarfs: ['sneezy', 'sleepy','dopey',
|
2565 | * 'doc', 'happy', 'bashful',
|
2566 | * 'grumpy']
|
2567 | * });
|
2568 | * ```
|
2569 | *
|
2570 | * @param path the path to send the request to
|
2571 | * @param request the request to send
|
2572 | * @param target the target recipient's session ID (as a string or Session ID object)
|
2573 | * @param requestType an optional request {@link DataType DataType}
|
2574 | * @param responseType an optional response {@link DataType DataType}
|
2575 | * @returns a {@link Result} containing the response
|
2576 | */
|
2577 | sendRequest(path: string, request: any, target: SessionId | string, requestType?: DataType<any, any, any> | string, responseType?: DataType<any, any, any> | string): Result<any>;
|
2578 | sendRequest(path: string, request: any, requestType?: DataType<any, any, any> | string, responseType?: DataType<any, any, any> | string): Result<any>;
|
2579 | /**
|
2580 | * Send a request to all sessions that satisfy a given session filter.
|
2581 | *
|
2582 | * **Example:**
|
2583 | * ```
|
2584 | * // Send a string request to be received by the server and passed to sessions matching the filter.
|
2585 | * session.messages.sendRequestToFilter('$Principal NE 'control'', 'test/topic', 'string request', {
|
2586 | * onResponse : function(sessionID, response) {
|
2587 | * console.log(response); // Log the response
|
2588 | * },
|
2589 | * onResponseError : function() {},
|
2590 | * onError : function() {},
|
2591 | * onClose : function() {}});
|
2592 | * ```
|
2593 | *
|
2594 | * **Example:**
|
2595 | * ```
|
2596 | * // Send a JSON request to be received by the server and passed to sessions matching the filter.
|
2597 | * session.messages.sendRequestToFilter('$Principal NE 'control'', 'test/topic',
|
2598 | * { dwarfs: ['sneezy', 'sleepy','dopey' ] },
|
2599 | * {
|
2600 | * onResponse : function(sessionID, response) {
|
2601 | * console.log(response.get()); // Log the response
|
2602 | * },
|
2603 | * onResponseError : function() {},
|
2604 | * onError : function() {},
|
2605 | * onClose : function() {}}, diffusion.datatypes.json(), diffusion.datatypes.json());
|
2606 | * ```
|
2607 | *
|
2608 | * @param filter the session filter expression
|
2609 | * @param path message path used by the recipient to select an appropriate handler
|
2610 | * @param request the request to send
|
2611 | * @param callback the handler to receive notification of responses
|
2612 | * (or errors) from sessions
|
2613 | * @param requestType] an optional request {@link DataType DataType}
|
2614 | * @param responseType an optional response {@link DataType DataType}
|
2615 | * @returns if the server successfully evaluated the filter, the
|
2616 | * result contains the number of sessions the request
|
2617 | * was sent to. Failure to send a request to a
|
2618 | * particular matching session is reported to the
|
2619 | * handler.
|
2620 | */
|
2621 | sendRequestToFilter(filter: string, path: string, request: any, callback: FilteredResponseHandler, reqType?: DataType<any, any, any>, respType?: DataType<any, any, any>): Result<number>;
|
2622 | /**
|
2623 | * Set a request stream to handle requests to a specified path.
|
2624 | *
|
2625 | * **Example:**
|
2626 | * ```
|
2627 | * // Set a request stream handler to handle string requests to 'test/topic'
|
2628 | * var handler = {
|
2629 | * onRequest: function (path, request, responder) {
|
2630 | * console.log(request);
|
2631 | * responder.respond('hello');
|
2632 | * },
|
2633 | * onError: function() {}
|
2634 | * };
|
2635 | *
|
2636 | * control.messages.setRequestStream('test/topic', handler,
|
2637 | * diffusion.datatypes.string(), diffusion.datatypes.string());
|
2638 | * ```
|
2639 | *
|
2640 | * @param path the path to receive request on
|
2641 | * @param stream the request stream to handle requests to this path
|
2642 | * @param requestType an optional request {@link DataType DataType}
|
2643 | * @param responseType an optional response {@link DataType DataType}
|
2644 | * @returns `undefined` if the request stream is the first stream
|
2645 | * to be set to the path, otherwise this method will
|
2646 | * return the previously set request stream.
|
2647 | */
|
2648 | setRequestStream(path: string, stream: RequestStream, reqType?: DataType<any, any, any>, resType?: DataType<any, any, any>): RequestStream | undefined;
|
2649 | /**
|
2650 | * Remove the request stream at a particular path.
|
2651 | *
|
2652 | * @param path the path at which to remove the request stream
|
2653 | * @returns the request stream that was removed from the path. If
|
2654 | * the path does not have a request stream assigned (or the
|
2655 | * path does not exist), `undefined` will be returned instead.
|
2656 | */
|
2657 | removeRequestStream(path: string): RequestStream | undefined;
|
2658 | }
|
2659 | /**
|
2660 | * A stream of messages sent to this session for a particular path.
|
2661 | *
|
2662 | * <h2>Events</h2>
|
2663 | *
|
2664 | * <h3><code>message</code></h3>
|
2665 | *
|
2666 | * Emitted when a message is received
|
2667 | *
|
2668 | * **Parameters:**
|
2669 | *
|
2670 | * `message`: {@link Message} - the incoming message
|
2671 | *
|
2672 | * <h3><code>close</code></h3>
|
2673 | *
|
2674 | * Emitted when the stream is closed
|
2675 | *
|
2676 | * <h3><code>error</code></h3>
|
2677 | *
|
2678 | * Emitted when an error occurred
|
2679 | *
|
2680 | * **Parameters:**
|
2681 | *
|
2682 | * `error`: any - the error
|
2683 | *
|
2684 | * @deprecated since 6.2
|
2685 | * <
|
2686 | * One-way messaging is deprecated in favor of request-response
|
2687 | * messaging. See {@link Messages.sendRequest sendRequest}
|
2688 | * and {@link Messages.sendRequestToFilter
|
2689 | * sendRequestToFilter}. This interface will be removed in a future
|
2690 | * release.
|
2691 | */ export interface MessageStream extends Stream {
|
2692 | }
|
2693 | /**
|
2694 | * The handler interface for receiving messages sent from sessions to the
|
2695 | * server. This interface must be implemented by the user, to be registered via
|
2696 | * {@link Messages.addHandler}.
|
2697 | *
|
2698 | * A message handler has a lifecycle that reflects the registration state on the
|
2699 | * server. This is expressed through the callback methods. Once {@link
|
2700 | * MessageHandler.onClose onClose} has been closed, no further interactions will
|
2701 | * occur.
|
2702 | *
|
2703 | * {@link SessionMessage Messages} received by a handler
|
2704 | * contain the identity of the original sender.
|
2705 | *
|
2706 | * @deprecated since 6.2
|
2707 | *
|
2708 | * One-way messaging is deprecated in favor of request-response
|
2709 | * messaging. See {@link Messages.sendRequest sendRequest}
|
2710 | * and {@link Messages.sendRequestToFilter
|
2711 | * sendRequestToFilter}. This interface will be removed in a future
|
2712 | * release.
|
2713 | */
|
2714 | export interface MessageHandler {
|
2715 | /**
|
2716 | * Handle a message that was sent by another session to the server, on a
|
2717 | * path that is a descendant of the path which this handler is registered
|
2718 | * for.
|
2719 | *
|
2720 | * @param {Session.messages.SessionMessage} message - The received message
|
2721 | * @function Session.messages.MessageHandler.onMessage
|
2722 | */ onMessage(message: SessionMessage): void;
|
2723 | /**
|
2724 | * Called when the handler has been registered at the server and is now
|
2725 | * active.
|
2726 | *
|
2727 | * @param unregister a function to call that will unregister and close this
|
2728 | * handler
|
2729 | */
|
2730 | onActive(unregister: () => void): void;
|
2731 | /**
|
2732 | * Called when the handler is unregistered, or the session is closed.
|
2733 | */
|
2734 | onClose(): void;
|
2735 | }
|
2736 | /**
|
2737 | * Interface which specifies a request stream to receive request notifications.
|
2738 | */
|
2739 | export interface RequestStream {
|
2740 | /**
|
2741 | * Called to indicate a request has been received.
|
2742 | *
|
2743 | * @param path the path the request was sent on
|
2744 | * @param request the request that was received
|
2745 | * @param responder the responder to dispatch a response back to the requester
|
2746 | */
|
2747 | onRequest(path: string, request: any, responder: Responder): void;
|
2748 | /**
|
2749 | * Notification of a contextual error related to this stream. This is
|
2750 | * analogous to an Error being thrown. Situations in which
|
2751 | * `onError` is called include being unable to parse the request
|
2752 | * with the data type the stream was registered with. No further calls will
|
2753 | * be made to this stream.
|
2754 | *
|
2755 | * @param error the error
|
2756 | */
|
2757 | onError(error: ErrorReasonType): void;
|
2758 | /**
|
2759 | * Called when the request stream is removed, or the session is closed.
|
2760 | */
|
2761 | onClose(): void;
|
2762 | }
|
2763 | /**
|
2764 | * Interface which specifies a request handler to receive request notifications.
|
2765 | *
|
2766 | * @class Session.messages.RequestHandler
|
2767 | */
|
2768 | export interface RequestHandler {
|
2769 | /**
|
2770 | * Called to indicate a request has been received.
|
2771 | *
|
2772 | * @param {Object} request - The request that was received
|
2773 | * @param {Session.messages.RequestContext} context - Context object that provides the session id
|
2774 | * (session that sent the request), path and session properties
|
2775 | * @param {Session.messages.Responder} responder - The responder to dispatch a response back to the requester
|
2776 | * @function Session.messages.RequestHandler.onRequest
|
2777 | */
|
2778 | onRequest(request: any, context: RequestContext, responder: Responder): void;
|
2779 | /**
|
2780 | * Notification of a contextual error related to this handler. This is
|
2781 | * analogous to an Error being thrown. Situations in which
|
2782 | * `onError` is called include the session being closed before the
|
2783 | * handler is registered, a communication timeout, or a problem with the
|
2784 | * provided parameters. No further calls will be made to this handler.
|
2785 | *
|
2786 | * @param error the error
|
2787 | */
|
2788 | onError(error: any): void;
|
2789 | /**
|
2790 | * Called when the request handler is unregistered, or the session is closed.
|
2791 | */
|
2792 | onClose(): void;
|
2793 | }
|
2794 | /**
|
2795 | * Interface which specifies a response handler for requests dispatched through
|
2796 | * a filter.
|
2797 | */
|
2798 | export interface FilteredResponseHandler {
|
2799 | /**
|
2800 | * Called to indicate a response has been received.
|
2801 | *
|
2802 | * @param sessionId session ID of the session that sent the response
|
2803 | * @param response response object
|
2804 | * @function Session.messages.FilteredResponseHandler.onResponse
|
2805 | */
|
2806 | onResponse(sessionId: SessionId, response: any): void;
|
2807 | /**
|
2808 | * Called when a response from a session results in an error.
|
2809 | *
|
2810 | * @param sessionId sessionID of the session in error
|
2811 | * @param errorReason the error reason
|
2812 | */
|
2813 | onResponseError(sessionId: SessionId, error: Error): void;
|
2814 | /**
|
2815 | * Notification of a contextual error related to this handler. This is
|
2816 | * analogous to an Error being thrown. Situations in which
|
2817 | * `onError` is called include the session being closed before the
|
2818 | * handler is registered, a communication timeout, or a problem with the
|
2819 | * provided parameters. No further calls will be made to this handler.
|
2820 | *
|
2821 | * @param error the error
|
2822 | */
|
2823 | onError(error: Error): void;
|
2824 | /**
|
2825 | * Called when the filtered response handler is unregistered, or the session
|
2826 | * is closed.
|
2827 | */
|
2828 | onClose(): void;
|
2829 | }
|
2830 | /**
|
2831 | * Responder interface to dispatch responses to requests.
|
2832 | */
|
2833 | export interface Responder {
|
2834 | /**
|
2835 | * Dispatch a response to a request.
|
2836 | *
|
2837 | * @param response the response to send
|
2838 | */
|
2839 | respond(response: any): void;
|
2840 | /**
|
2841 | * Reject a message
|
2842 | *
|
2843 | * @param message the message indicating the failure
|
2844 | */
|
2845 | reject(message: string): void;
|
2846 | }
|
2847 | /**
|
2848 | * A message request context
|
2849 | */
|
2850 | export interface RequestContext {
|
2851 | /**
|
2852 | * SessionId of the session that sent the request
|
2853 | */
|
2854 | sessionId: SessionId;
|
2855 | /**
|
2856 | * The message path of the request
|
2857 | */
|
2858 | path: string;
|
2859 | /**
|
2860 | * The session properties
|
2861 | */
|
2862 | properties: {
|
2863 | [key: string]: string;
|
2864 | };
|
2865 | }
|
2866 | /**
|
2867 | * A message that is received when a session {@link Messages.listen listens} to
|
2868 | * incoming messages.
|
2869 | *
|
2870 | * **Example:**
|
2871 | * ```
|
2872 | * // Read message content as a JSON DataType value
|
2873 | * var jsonObj = diffusion.datatypes.json().readValue(message.content).get();
|
2874 | * ```
|
2875 | *
|
2876 | * @deprecated since 6.2
|
2877 | *
|
2878 | * One-way messaging is deprecated in favor of request-response
|
2879 | * messaging. See {@link Messages.sendRequest sendRequest}
|
2880 | * and {@link Messages.sendRequestToFilter
|
2881 | * sendRequestToFilter}. This interface will be removed in a future
|
2882 | * release.
|
2883 | */
|
2884 | export interface Message {
|
2885 | /**
|
2886 | * The message path
|
2887 | */
|
2888 | readonly path: string;
|
2889 | /**
|
2890 | * The message payload
|
2891 | */
|
2892 | readonly content: Buffer;
|
2893 | /**
|
2894 | * The send options
|
2895 | */ readonly options: SendOptions;
|
2896 | }
|
2897 | /**
|
2898 | * A message received by the {@link MessageHandler}
|
2899 | *
|
2900 | * @deprecated since 6.2
|
2901 | *
|
2902 | * One-way messaging is deprecated in favor of request-response
|
2903 | * messaging. See {@link Messages.sendRequest sendRequest}
|
2904 | * and {@link Messages.sendRequestToFilter
|
2905 | * sendRequestToFilter}. This interface will be removed in a future
|
2906 | * release.
|
2907 | */
|
2908 | export interface SessionMessage {
|
2909 | /**
|
2910 | * The path that this message was sent on
|
2911 | */
|
2912 | readonly path: string;
|
2913 | /**
|
2914 | * The message's value as a binary buffer
|
2915 | */
|
2916 | readonly content: Buffer;
|
2917 | /**
|
2918 | * The session that sent this message
|
2919 | */
|
2920 | readonly session: string;
|
2921 | /**
|
2922 | * The options that were set when sending the message
|
2923 | */ readonly options: SendOptions;
|
2924 | /**
|
2925 | * The sender's session properties
|
2926 | */
|
2927 | properties?: {
|
2928 | [key: string]: string;
|
2929 | };
|
2930 | }
|
2931 | /**
|
2932 | * Options for sending messages
|
2933 | *
|
2934 | * @deprecated since 6.2
|
2935 | *
|
2936 | * This is only used within one-way messaging, which is deprecated
|
2937 | * from this release. This interface will be removed in a future
|
2938 | * release.
|
2939 | */
|
2940 | export interface SendOptions {
|
2941 | /**
|
2942 | * The message priority
|
2943 | */ priority?: Priority;
|
2944 | /**
|
2945 | * The message headers as an array of strings
|
2946 | */
|
2947 | headers?: string[];
|
2948 | }
|
2949 | /**
|
2950 | * @typedef {Object} Session.messages.MessageSendResult
|
2951 | * @property {String} path - topic path
|
2952 | * @property {String} recipient - session filter or SessionID of the recipient
|
2953 | * @property {Number} [sent] - the number of sessions the message has been sent to using a filter string
|
2954 | * @property {Array<ErrorReport>} [errors] - errors from sending to sessions using a filter string
|
2955 | *
|
2956 | * @deprecated since 6.2
|
2957 | * <p>
|
2958 | * One-way messaging is deprecated in favor of request-response
|
2959 | * messaging. See {@link Messages.sendRequest sendRequest}
|
2960 | * and {@link Messages.sendRequestToFilter
|
2961 | * sendRequestToFilter}. This interface will be removed in a future
|
2962 | * release.
|
2963 | */
|
2964 | export interface MessageSendResult {
|
2965 | /**
|
2966 | * The topic path as specified in the call to {@link Messages.send}
|
2967 | */
|
2968 | readonly path: string;
|
2969 | /**
|
2970 | * The recipient as specified in the call to {@link Messages.send}
|
2971 | */
|
2972 | readonly recipient?: string | SessionId;
|
2973 | /**
|
2974 | * If a filter was passed for the recipient, this contains the number of
|
2975 | * sessions the message has been sent to.
|
2976 | */
|
2977 | readonly sent?: number;
|
2978 | /**
|
2979 | * Any errors from sending to sessions using a filter string
|
2980 | */
|
2981 | readonly errors?: ErrorReport[];
|
2982 | }
|
2983 | /**
|
2984 | * Alias for the MessageSendResult interface to keep compatibility with old TypeScript definitions
|
2985 | */ export declare type SendResult = MessageSendResult;
|
2986 | /**
|
2987 | * @module Session
|
2988 | */
|
2989 | /**
|
2990 | * Ping feature
|
2991 | *
|
2992 | * The main purpose of a ping is to test, at a very basic level, the current
|
2993 | * network conditions that exist between the client session and the server
|
2994 | * it is connected to. The ping response includes the time taken to make a
|
2995 | * round-trip call to the server.
|
2996 | *
|
2997 | * There are no permission requirements associated with this feature.
|
2998 | */
|
2999 | export interface Ping {
|
3000 | /**
|
3001 | * Send a ping request to the server.
|
3002 | *
|
3003 | * **Example:**
|
3004 | * ```
|
3005 | * session.pingServer().then(function(pingDetails) {
|
3006 | * console.log("Round-trip call to server took: " + pingDetails.rtt + " milliseconds");
|
3007 | * });
|
3008 | * ```
|
3009 | *
|
3010 | * @return a result that completes when a response is received from the server.
|
3011 | */
|
3012 | pingServer(): Result<PingDetails>;
|
3013 | }
|
3014 | /**
|
3015 | * Details of a successful ping response
|
3016 | */
|
3017 | export interface PingDetails {
|
3018 | /**
|
3019 | * The timestamp when the ping was sent, represented as milliseconds since
|
3020 | * epoch
|
3021 | */
|
3022 | readonly timestamp: number;
|
3023 | /**
|
3024 | * The round-trip time in milliseconds from when the ping was sent to the
|
3025 | * time the response was received
|
3026 | */
|
3027 | readonly rtt: number;
|
3028 | }
|
3029 | /// <reference types="node" />
|
3030 | /**
|
3031 | * @module Session.security
|
3032 | *
|
3033 | * Access to the [[Security]] feature
|
3034 | * @preferred
|
3035 | */
|
3036 | /**
|
3037 | * Permissions that are applied globally
|
3038 | */
|
3039 | export declare enum GlobalPermission {
|
3040 | /**
|
3041 | * Add an authentication handler
|
3042 | */
|
3043 | AUTHENTICATE = "AUTHENTICATE",
|
3044 | /**
|
3045 | * List or listen to client sessions
|
3046 | */
|
3047 | VIEW_SESSION = "VIEW_SESSION",
|
3048 | /**
|
3049 | * Alter a client session
|
3050 | */
|
3051 | MODIFY_SESSION = "MODIFY_SESSION",
|
3052 | /**
|
3053 | * Required to register any server-side handler
|
3054 | */
|
3055 | REGISTER_HANDLER = "REGISTER_HANDLER",
|
3056 | /**
|
3057 | * View the server's runtime state
|
3058 | */
|
3059 | VIEW_SERVER = "VIEW_SERVER",
|
3060 | /**
|
3061 | * Change the server's runtime state
|
3062 | */
|
3063 | CONTROL_SERVER = "CONTROL_SERVER",
|
3064 | /**
|
3065 | * Read the security configuration
|
3066 | */
|
3067 | VIEW_SECURITY = "VIEW_SECURITY",
|
3068 | /**
|
3069 | * Change the security configuration
|
3070 | */
|
3071 | MODIFY_SECURITY = "MODIFY_SECURITY",
|
3072 | /**
|
3073 | * A permission that is unsupported by the session
|
3074 | */
|
3075 | UNKNOWN_GLOBAL_PERMISSION = "UNKNOWN_GLOBAL_PERMISSION",
|
3076 | /**
|
3077 | * List topic views
|
3078 | */
|
3079 | READ_TOPIC_VIEWS = "READ_TOPIC_VIEWS",
|
3080 | /**
|
3081 | * Modify topic views
|
3082 | */
|
3083 | MODIFY_TOPIC_VIEWS = "MODIFY_TOPIC_VIEWS",
|
3084 | }
|
3085 | /**
|
3086 | * Permissions that are applied on a topic path
|
3087 | */
|
3088 | export declare enum TopicPermission {
|
3089 | /**
|
3090 | * Required to receive information from a topic.
|
3091 | *
|
3092 | * If a session does not have read_topic permission for a topic, the topic
|
3093 | * will be excluded from the results of subscription or fetch operations for
|
3094 | * the session, and the topic's details cannot be retrieved by the session.
|
3095 | */
|
3096 | READ_TOPIC = "READ_TOPIC",
|
3097 | /**
|
3098 | * Update topics
|
3099 | */
|
3100 | UPDATE_TOPIC = "UPDATE_TOPIC",
|
3101 | /**
|
3102 | * Add or remove topics
|
3103 | */
|
3104 | MODIFY_TOPIC = "MODIFY_TOPIC",
|
3105 | /**
|
3106 | * Send a message to a handler registered with the server
|
3107 | */
|
3108 | SEND_TO_MESSAGE_HANDLER = "SEND_TO_MESSAGE_HANDLER",
|
3109 | /**
|
3110 | * Send a message another session
|
3111 | */
|
3112 | SEND_TO_SESSION = "SEND_TO_SESSION",
|
3113 | /**
|
3114 | * Use a topic selector that selects the topic path
|
3115 | *
|
3116 | * A session must have this permission for the path prefix of any topic selector
|
3117 | * used to subscribe or fetch.
|
3118 | *
|
3119 | * When the subscription or fetch request completes, the resulting topics
|
3120 | * are further filtered based on the `READ_TOPIC` permission.
|
3121 | *
|
3122 | * A session that has `READ_TOPIC` but not
|
3123 | * `SELECT_TOPIC` for a particular topic path cannot
|
3124 | * subscribe directly to topics belonging to the path. However, the session can
|
3125 | * be independently subscribed by a control session that has the
|
3126 | * `MODIFY_SESSION` global permission in addition to the
|
3127 | * appropriate `SELECT_TOPIC` permission.
|
3128 | */
|
3129 | SELECT_TOPIC = "SELECT_TOPIC",
|
3130 | /**
|
3131 | * Evaluate queries that return a non-current view of a time series topic.
|
3132 | *
|
3133 | * <p>
|
3134 | * The `READ_TOPIC` permission is required to evaluate any type of
|
3135 | * `Query` for a time series topic. This permission is additionally
|
3136 | * required for queries that potentially return a non-current view of all or
|
3137 | * part of a time series. Such queries include value range queries that
|
3138 | * specify an edit range, and all types of edit range query.
|
3139 | */
|
3140 | QUERY_OBSOLETE_TIME_SERIES_EVENTS = "QUERY_OBSOLETE_TIME_SERIES_EVENTS",
|
3141 | EDIT_TIME_SERIES_EVENTS = "EDIT_TIME_SERIES_EVENTS",
|
3142 | /**
|
3143 | * Submit edits to time series topic events which have an author which is
|
3144 | * the same as the principal of the calling session.
|
3145 | *
|
3146 | * <p>This permission is a more restrictive alternative to
|
3147 | * `EDIT_TIME_SERIES_EVENTS`.
|
3148 | *
|
3149 | * <p>
|
3150 | * The `UPDATE_TOPIC` permission is required to update a time series
|
3151 | * topic. This permission is additionally required to submit
|
3152 | * edits to a time series topic where the event
|
3153 | * author is the same as the principal of the calling session.
|
3154 | */
|
3155 | EDIT_OWN_TIME_SERIES_EVENTS = "EDIT_OWN_TIME_SERIES_EVENTS",
|
3156 | /**
|
3157 | * Acquire a session lock.
|
3158 | */
|
3159 | ACQUIRE_LOCK = "ACQUIRE_LOCK",
|
3160 | /**
|
3161 | * A permission that is unsupported by the session
|
3162 | */
|
3163 | UNKNOWN_TOPIC_PERMISSION = "UNKNOWN_TOPIC_PERMISSION",
|
3164 | }
|
3165 | /**
|
3166 | * The credentials that a session uses to authenticate itself
|
3167 | */
|
3168 | export declare type Credentials = string | Buffer | null | undefined;
|
3169 | /**
|
3170 | * Details for the permissions contained by a single role.
|
3171 | */
|
3172 | export interface Role {
|
3173 | /**
|
3174 | * The name of the role
|
3175 | */
|
3176 | readonly name: string;
|
3177 | /**
|
3178 | * The list of global permissions
|
3179 | */
|
3180 | readonly global: GlobalPermission[];
|
3181 | /**
|
3182 | * The list of default topic permissions
|
3183 | */
|
3184 | readonly default: TopicPermission[];
|
3185 | /**
|
3186 | * The map of topic paths to sets of Topic
|
3187 | * permissions
|
3188 | */
|
3189 | readonly topic: {
|
3190 | [key: string]: TopicPermission[];
|
3191 | };
|
3192 | /**
|
3193 | * Additional roles
|
3194 | */
|
3195 | readonly roles: string[];
|
3196 | /**
|
3197 | * If the role is locked this will contain the name of the principal that
|
3198 | * can update the role.
|
3199 | *
|
3200 | * @since 6.4
|
3201 | */
|
3202 | readonly lockingPrincipal?: string;
|
3203 | }
|
3204 | /**
|
3205 | * A snapshot of information from the security store
|
3206 | */
|
3207 | export interface SecurityConfiguration {
|
3208 | /**
|
3209 | * The list of default roles for named sessions
|
3210 | */
|
3211 | readonly named: string[];
|
3212 | /**
|
3213 | * The list of default roles for anonymous sessions
|
3214 | */
|
3215 | readonly anonymous: string[];
|
3216 | /**
|
3217 | * The list of all defined roles
|
3218 | */
|
3219 | readonly roles: Role[];
|
3220 | }
|
3221 | /**
|
3222 | * A principal in the system authentication store.
|
3223 | */
|
3224 | export interface SystemPrincipal {
|
3225 | /**
|
3226 | * The principal name
|
3227 | */
|
3228 | readonly name: string;
|
3229 | /**
|
3230 | * The principal's assigned roles
|
3231 | */
|
3232 | readonly roles: string[];
|
3233 | /**
|
3234 | * If the principal is locked this will contain the name of the principal that
|
3235 | * can update the role.
|
3236 | *
|
3237 | * @since 6.4
|
3238 | */
|
3239 | readonly lockingPrincipal?: string;
|
3240 | }
|
3241 | /**
|
3242 | * Action to be taken by the system authentication handler for connection
|
3243 | * attempts that do not provide a principal name and credentials.
|
3244 | */
|
3245 | export declare type AnonymousConnectionAction = 'deny' | 'allow' | 'abstain';
|
3246 | /**
|
3247 | * Configuration for anonymous connections
|
3248 | */
|
3249 | export interface SystemAuthenticationAnonymousConfiguration {
|
3250 | /**
|
3251 | * The action to take for anonymous connection attempts.
|
3252 | *
|
3253 | * May be one of:
|
3254 | *
|
3255 | * * `deny` - Deny anonymous connection attempts.
|
3256 | * * `allow` - Accept anonymous connection attempts.
|
3257 | * * `abstain` - Defer authentication for anonymous connection
|
3258 | * attempts to subsequent authentication handlers
|
3259 | *
|
3260 | */
|
3261 | readonly action: AnonymousConnectionAction;
|
3262 | /**
|
3263 | * The roles the system authentication handler will assign to
|
3264 | * anonymous sessions. Applicable only if anonymous connections are
|
3265 | * {@link AnonymousConnectionAction allowed}.
|
3266 | */
|
3267 | readonly roles: string[];
|
3268 | }
|
3269 | /**
|
3270 | * A snapshot of information from the system authentication store.
|
3271 | *
|
3272 | * @property {Object} anonymous The configuration used for anonymous connections.
|
3273 | * @property {String} anonymous.action The default action to apply to anonymous connections.
|
3274 | * <p>
|
3275 | * @property {String[]} anonymous.roles - The roles assigned to anonymous connections.
|
3276 | */
|
3277 | export interface SystemAuthenticationConfiguration {
|
3278 | /**
|
3279 | * The system principals stored on the server.
|
3280 | */
|
3281 | readonly principals: SystemPrincipal[];
|
3282 | /**
|
3283 | * The configuration that is applied for anonymous connections
|
3284 | */
|
3285 | readonly anonymous: SystemAuthenticationAnonymousConfiguration;
|
3286 | }
|
3287 | /**
|
3288 | * Additional information supplied to the server upon a successful authentication.
|
3289 | *
|
3290 | * @deprecated since 6.3
|
3291 | * <p>
|
3292 | * This interface is part of the deprecated {@link
|
3293 | * AuthenticationHandler} API. Use the new {@link Authenticator}
|
3294 | * API instead.
|
3295 | */
|
3296 | export interface AuthenticationResult {
|
3297 | /**
|
3298 | * Additional roles to be assigned to the authenticated session
|
3299 | */
|
3300 | readonly roles: string[];
|
3301 | /**
|
3302 | * Additional properties to be assigned to the authenticated session
|
3303 | */
|
3304 | readonly properties: SessionProperties;
|
3305 | }
|
3306 | /**
|
3307 | * Single-use callback provided to the {@link
|
3308 | * AuthenticationHandler.onAuthenticate onAuthenticate} call.
|
3309 | *
|
3310 | * The server calls the handlers for each authentication request. Each
|
3311 | * handler must respond {@link AuthenticationHandlerCallback.allow allow},
|
3312 | * {@link AuthenticationHandlerCallback.abstain abstain},
|
3313 | * or {@link AuthenticationHandlerCallback.deny deny}.
|
3314 | *
|
3315 | * The handler may provide additional information to the allow method with a user-supplied
|
3316 | * {@link AuthenticationResult} object.
|
3317 | *
|
3318 | * Authentication handlers are configured in precedence order.
|
3319 | * Authentication will succeed if a handler returns 'allow' and all higher
|
3320 | * precedence handlers (earlier in the order) return 'abstain'.
|
3321 | * Authentication will fail if a handler returns 'deny' and all higher
|
3322 | * precedence handlers return 'abstain'. If all authentication handlers
|
3323 | * return 'abstain', the request will be denied. Once the outcome is known,
|
3324 | * the server may choose not to call the remaining handlers.
|
3325 | *
|
3326 | * @deprecated since 6.3
|
3327 | * <p>
|
3328 | * This interface is part of the deprecated {@link
|
3329 | * AuthenticationHandler} API. Use the new {@link Authenticator}
|
3330 | * API instead.
|
3331 | */
|
3332 | export interface AuthenticationHandlerCallback {
|
3333 | /**
|
3334 | * Authentication passed - allow the authentication request
|
3335 | *
|
3336 | * **Example:**
|
3337 | * ```
|
3338 | * // Basic allow
|
3339 | * callback.allow();
|
3340 | *
|
3341 | * // Allow with AuthenticationResult
|
3342 | * callback.allow({
|
3343 | * roles : ['SOME_ROLE'],
|
3344 | * properties : {
|
3345 | * MyPropertyKey : 'MyPropertyValue'
|
3346 | * }
|
3347 | * });
|
3348 | * ```
|
3349 | *
|
3350 | * @param result optional roles/properties to assign to the authenticated session
|
3351 | */ allow(result?: AuthenticationResult): void;
|
3352 | /**
|
3353 | * Abstain from deciding on the authentication request
|
3354 | */
|
3355 | abstain(): void;
|
3356 | /**
|
3357 | * Authentication failed - deny the authentication request.
|
3358 | */
|
3359 | deny(): void;
|
3360 | }
|
3361 | /**
|
3362 | * Handler for session authentication events. Must be implemented by user.
|
3363 | *
|
3364 | * Authentication handlers implementing this interface can be registered with
|
3365 | * the server. The server calls the authentication handlers when a client
|
3366 | * application creates a session, or changes the principal associated with a
|
3367 | * session, allowing the handler to veto individual requests.
|
3368 | *
|
3369 | * Authentication handlers are configured in precedence order. Authentication
|
3370 | * will succeed if a handler returns {@link AuthenticationHandlerCallback.allow
|
3371 | * allow} and all higher precedence handlers (earlier in the order) return
|
3372 | * {@link AuthenticationHandlerCallback.abstain abstain}. Authentication will
|
3373 | * fail if a handler returns {@link AuthenticationHandlerCallback.deny deny} and
|
3374 | * all higher precedence handlers return 'abstain'. If all authentication
|
3375 | * handlers return 'abstain', the request will be denied. Once the outcome is
|
3376 | * known, the server may choose not to call the remaining handlers.
|
3377 | *
|
3378 | * The special variant of {@link AuthenticationHandlerCallback.allow allow}
|
3379 | * may be used by the handler to supply the server with additional information that is
|
3380 | * used to set up the session.
|
3381 | *
|
3382 | * @deprecated since 6.3
|
3383 | * <p>
|
3384 | * This interface is part of the deprecated {@link
|
3385 | * AuthenticationHandler} API. Use the new {@link Authenticator}
|
3386 | * API instead.
|
3387 | */
|
3388 | export interface AuthenticationHandler {
|
3389 | /**
|
3390 | * Request authentication.
|
3391 | *
|
3392 | * The server calls this to authenticate new sessions, and when a client
|
3393 | * requests the session principal is changed (e.g. using
|
3394 | * {@link Security.changePrincipal}.
|
3395 | *
|
3396 | * For each call to `onAuthenticate`, the authentication handler should
|
3397 | * respond by calling one of the methods of the provided `callback`.
|
3398 | * The handler may return immediately and process the authentication request
|
3399 | * asynchronously. The client session will be blocked until a callback
|
3400 | * method is called.
|
3401 | *
|
3402 | * @param principal the requested principal, or '' if none was supplied.
|
3403 | * @param credentials credentials authenticating the principal
|
3404 | * @param sessionDetails the information the server has about the client
|
3405 | * @param callback single use callback
|
3406 | */
|
3407 | onAuthenticate(principal: string, credentials: string | Buffer, sessionDetails: SessionDetails, callback: AuthenticationHandlerCallback): void;
|
3408 | /**
|
3409 | * Called when the handler has been successfully registered with the server.
|
3410 | *
|
3411 | * A session can register a single handler. If there is already a handler
|
3412 | * registered, the operation will fail and {@link
|
3413 | * AuthenticationHandler.onClose onClose} will be called.
|
3414 | *
|
3415 | * To deregister the handler, call the `deregister` function supplied.
|
3416 | *
|
3417 | * @param deregister a function that may be called to deregister this handler
|
3418 | */
|
3419 | onActive(deregister: () => void): void;
|
3420 | /**
|
3421 | * Called when the handler is closed. The handler will be closed if the
|
3422 | * session is closed, or if the handler is unregistered.
|
3423 | *
|
3424 | * Once closed, no further calls will be made for the handler.
|
3425 | */
|
3426 | onClose(): void;
|
3427 | /**
|
3428 | * Notification of a contextual error related to this handler. This is
|
3429 | * analogous to an unchecked exception being raised. Situations in which
|
3430 | * `onError` is called include the session being closed before the
|
3431 | * handler is registered, a communication timeout, or a problem with the
|
3432 | * provided parameters. No further calls will be made to this handler.
|
3433 | *
|
3434 | * @param error the error
|
3435 | */
|
3436 | onError(error: Error): void;
|
3437 | }
|
3438 | /**
|
3439 | * A builder that can be used to create scripts for use with
|
3440 | * {@link Security.updateSecurityStore updateSecurityStore}.
|
3441 | *
|
3442 | * Facilitates producing scripts that control the assignment of permissions to
|
3443 | * roles.
|
3444 | */
|
3445 | export interface SecurityScriptBuilder {
|
3446 | /**
|
3447 | * Create the script string.
|
3448 | *
|
3449 | * @return the script
|
3450 | */
|
3451 | build(): string;
|
3452 | /**
|
3453 | * Sets the roles to be assigned by default to all anonymous sessions.
|
3454 | *
|
3455 | * @param (roles?: string[]): SecurityScriptBuilder;the roles to be
|
3456 | * assigned. An empty array (the default), or no argument,
|
3457 | * will result in anonymous sessions being assigned no roles
|
3458 | * by default.
|
3459 | * @return the builder to allow chaining
|
3460 | */
|
3461 | setRolesForAnonymousSessions(roles?: string[]): SecurityScriptBuilder;
|
3462 | /**
|
3463 | * Sets the roles to be assigned by default to all sessions that authenticate with a principal.
|
3464 | *
|
3465 | * @param roles the roles to be assigned. Any empty array (the default), or
|
3466 | * no argument, will result in named sessions being assigned
|
3467 | * no roles by default.
|
3468 | *
|
3469 | * @return the builder to allow chaining
|
3470 | */
|
3471 | setRolesForNamedSessions(roles?: string[]): SecurityScriptBuilder;
|
3472 | /**
|
3473 | * Set the global permissions assigned to a particular role.
|
3474 | *
|
3475 | * @param role the role to set global permissions for.
|
3476 | * @param permissions the permissions to assign globally for a role,
|
3477 | * default `= []`.
|
3478 | *
|
3479 | * @return the builder to allow chaining
|
3480 | */
|
3481 | setGlobalPermissions(role: string, permissions?: string[]): SecurityScriptBuilder;
|
3482 | /**
|
3483 | * Set the default permissions that a particular role will have for topics.
|
3484 | *
|
3485 | * @param role the role to set topic permissions for.
|
3486 | * @param permissions the topic permissions to assign for the role,
|
3487 | * default `= []`.
|
3488 | *
|
3489 | * @return the builder to allow chaining
|
3490 | */
|
3491 | setDefaultTopicPermissions(role: string, permissions?: string[]): SecurityScriptBuilder;
|
3492 | /**
|
3493 | * Remove any previously assigned permissions from a particular topic for a
|
3494 | * given role.
|
3495 | *
|
3496 | * This is different from setting no permissions to a topic. By removing
|
3497 | * permissions set for a topic, permissions will be inherited from the
|
3498 | * nearest set of permissions that have been assigned higher in the topic
|
3499 | * path hierarchy or from the default topic permissions if no more specific
|
3500 | * permissions are found.
|
3501 | *
|
3502 | * @param role the role to remove topic permissions from.
|
3503 | * @param path the topic path to remove permissions from.
|
3504 | *
|
3505 | * @return the builder to allow chaining
|
3506 | */
|
3507 | removeTopicPermissions(role: string, path: string): SecurityScriptBuilder;
|
3508 | /**
|
3509 | * Sets specific topic permissions for a named role.
|
3510 | *
|
3511 | * When permissions are assigned to a role for a topic path they will apply
|
3512 | * to the topic and any topics below the specified path. Topic-scoped
|
3513 | * permissions are assigned to roles for specific topic paths. The
|
3514 | * permission assignment applies to all descendant topics, unless there is a
|
3515 | * more specific assignment.
|
3516 | *
|
3517 | * To evaluate whether a session has permission for a topic, the server
|
3518 | * starts at that topic and searches up the tree to find the nearest
|
3519 | * permissions assignment. The first assignment is the only one considered,
|
3520 | * even if the session has roles involved in assignments further up the
|
3521 | * hierarchy.
|
3522 | *
|
3523 | * @param role the role to assign permissions for.
|
3524 | * @param path the topic path to assign permissions.
|
3525 | * @param permissions the permissions to assign to the role for the
|
3526 | * specified path. Any empty array (the default) or no
|
3527 | * argument would specify that the role has no
|
3528 | * permissions at this path, which differs from there
|
3529 | * being no permissions assigned for that path (see
|
3530 | * {@link
|
3531 | * SecurityScriptBuilder.removeTopicPermissions}).
|
3532 | *
|
3533 | * @return the builder to allow chaining
|
3534 | */
|
3535 | setTopicPermissions(role: string, path: string, permissions?: string[]): SecurityScriptBuilder;
|
3536 | /**
|
3537 | * Specify a set of a roles that another role should inherit permissions from.
|
3538 | *
|
3539 | * @param role the role
|
3540 | * @param roles the set of roles to inherit from.
|
3541 | *
|
3542 | * @return the builder to allow chaining
|
3543 | */
|
3544 | setRoleIncludes(role: string, roles: string[]): SecurityScriptBuilder;
|
3545 | /**
|
3546 | * Restrict a role so it can only be edited by a specific principal.
|
3547 | *
|
3548 | * @param role the role
|
3549 | * @param lockingPrincipal the locking principal
|
3550 | *
|
3551 | * @return a new builder for scripts that also locks a role to a single
|
3552 | * principal that can edit it
|
3553 | *
|
3554 | * @since 6.4
|
3555 | */
|
3556 | setRoleLockedByPrincipal(role: string, lockingPrincipal: string): SecurityScriptBuilder;
|
3557 | }
|
3558 | /**
|
3559 | * A builder that can be used to create scripts for use with {@link
|
3560 | * Security.updateAuthenticationStore updateAuthenticationStore}.
|
3561 | *
|
3562 | * Facilitates producing scripts that contain the mapping of roles to specific
|
3563 | * principals/passwords.
|
3564 | */
|
3565 | export interface SystemAuthenticationScriptBuilder {
|
3566 | /**
|
3567 | * Create the script string.
|
3568 | *
|
3569 | * @return the script
|
3570 | */
|
3571 | build(): string;
|
3572 | /**
|
3573 | * Change a principal's assigned roles.
|
3574 | *
|
3575 | * @param principal the principal name.
|
3576 | * @param roles an array of roles
|
3577 | * @return a new builder containing the changed roles
|
3578 | */
|
3579 | assignRoles(principal: string, roles: string[]): SystemAuthenticationScriptBuilder;
|
3580 | /**
|
3581 | * Add a principal.
|
3582 | *
|
3583 | * If `lockingPrincipal` is defined, the new principal can only be edited
|
3584 | * by the principal defined in the lock.
|
3585 | *
|
3586 | * The script will fail if the principal is already defined at the server.
|
3587 | *
|
3588 | * @param principal the principal name
|
3589 | * @param password the principal's password
|
3590 | * @param roles the assigned roles for the principal, default `= []`
|
3591 | * @param lockingPrincipal the name of the principal that can edit this
|
3592 | * principal
|
3593 | * @return a new builder containing the new principal
|
3594 | */
|
3595 | addPrincipal(principal: string, password: string, roles?: string[], lockingPrincipal?: string): SystemAuthenticationScriptBuilder;
|
3596 | /**
|
3597 | * Set a principal's password.
|
3598 | *
|
3599 | * @param principal the principal name
|
3600 | * @param password the principal's password
|
3601 | * @return a new builder containing the changed password
|
3602 | */
|
3603 | setPassword(principal: string, password: string): SystemAuthenticationScriptBuilder;
|
3604 | /**
|
3605 | * Assert that a principal's password is `password`.
|
3606 | *
|
3607 | * This command doesn't update the store. It can be used in conjunction with
|
3608 | * {@link SystemAuthenticationScriptBuilder.setPassword setPassword} to
|
3609 | * create a script that updates a password only if the previous password is
|
3610 | * supplied.
|
3611 | *
|
3612 | * @param principal the principal name
|
3613 | * @param password the principal's password
|
3614 | * @return a new builder containing the verification command
|
3615 | */
|
3616 | verifyPassword(principal: string, password: string): SystemAuthenticationScriptBuilder;
|
3617 | /**
|
3618 | * Remove a principal.
|
3619 | *
|
3620 | * @param principal the principal name
|
3621 | * @return a new builder containing the remove command
|
3622 | */
|
3623 | removePrincipal(principal: string): SystemAuthenticationScriptBuilder;
|
3624 | /**
|
3625 | * Instruct the system authentication to allow anonymous connections.
|
3626 | *
|
3627 | * @param roles the roles to assign to anonymous sessions, default `= []`
|
3628 | * @return a new builder containing the allow anonymous connections
|
3629 | * command.
|
3630 | */
|
3631 | allowAnonymousConnections(roles?: string[]): SystemAuthenticationScriptBuilder;
|
3632 | /**
|
3633 | * Instruct the system authentication to deny anonymous connections.
|
3634 | *
|
3635 | * @return a new builder containing the deny anonymous connections command.
|
3636 | */
|
3637 | denyAnonymousConnections(): SystemAuthenticationScriptBuilder;
|
3638 | /**
|
3639 | * Instruct the system authentication handler to defer authentication
|
3640 | * decisions for anonymous connections to subsequent handlers.
|
3641 | *
|
3642 | * @return a new builder containing the abstain anonymous connections
|
3643 | * command.
|
3644 | */
|
3645 | abstainAnonymousConnections(): SystemAuthenticationScriptBuilder;
|
3646 | }
|
3647 | /**
|
3648 | * Single-use callback provided to the {@link Authenticator.authenticate
|
3649 | * authenticate} call.
|
3650 | */
|
3651 | export interface AuthenticatorCallback {
|
3652 | /**
|
3653 | * Authentication passed - allow the authentication request with
|
3654 | * modifications to the session properties.
|
3655 | *
|
3656 | * @param properties this can include all allowed user-defined session
|
3657 | * properties, as well as a subset of fixed session
|
3658 | * properties see {@link Authenticator.authenticate
|
3659 | * authenticate}.
|
3660 | * @throws an error if another method has already been
|
3661 | * invoked on this callback
|
3662 | */
|
3663 | allow(properties: SessionProperties): void;
|
3664 | /**
|
3665 | * Authentication passed - allow the authentication request with fixed
|
3666 | * properties as supplied but no user-defined properties.
|
3667 | *
|
3668 | * @throws an error if another method has already been
|
3669 | * invoked on this callback
|
3670 | */
|
3671 | allow(): void;
|
3672 | /**
|
3673 | * The authentication has neither passed nor failed.
|
3674 | *
|
3675 | * @throws an error if another method has already been
|
3676 | * invoked on this callback
|
3677 | */
|
3678 | abstain(): void;
|
3679 | /**
|
3680 | * Authentication failed - deny the authentication request.
|
3681 | *
|
3682 | * @throws an error if another method has already been
|
3683 | * invoked on this callback
|
3684 | */
|
3685 | deny(): void;
|
3686 | }
|
3687 | /**
|
3688 | * An authentication handler that processes authentication requests from the
|
3689 | * server.
|
3690 | *
|
3691 | * Instances can be registered with the server using the
|
3692 | * {@link Security.setAuthenticationHandler AuthenticationControl} feature.
|
3693 | *
|
3694 | * The server calls an authentication handler when a client application creates
|
3695 | * a session, or changes the principal associated with a session, allowing the
|
3696 | * handler to veto individual requests.
|
3697 | *
|
3698 | * Authentication handlers are configured in precedence order. Authentication
|
3699 | * will succeed if a handler responds by calling {@link
|
3700 | * AuthenticatorCallback.allow allow()} or {@link AuthenticatorCallback.allow
|
3701 | * allow(map)} and handlers with higher precedence respond by calling {@link
|
3702 | * AuthenticatorCallback.abstain abstain()}.
|
3703 | *
|
3704 | * Authentication will fail if a handler responds by calling {@link
|
3705 | * AuthenticatorCallback.deny deny()} and all higher precedence handlers respond
|
3706 | * by calling {@link AuthenticatorCallback.abstain abstain()}.
|
3707 | *
|
3708 | * If all authentication handlers respond by calling {@link
|
3709 | * AuthenticatorCallback.abstain abstain()}, the request will be denied. Once
|
3710 | * the outcome is known, the server may choose not to call any remaining
|
3711 | * authentication handlers.
|
3712 | *
|
3713 | * @since 6.3
|
3714 | */
|
3715 | export interface Authenticator {
|
3716 | /**
|
3717 | * Processes an authentication request.
|
3718 | *
|
3719 | * This method will be called to authenticate new sessions, and when a
|
3720 | * session requests that the session principal is changed (for example,
|
3721 | * using {@link Security.changePrincipal changePrincipal}).
|
3722 | *
|
3723 | * For each call to `authenticate`, the handler should respond by calling
|
3724 | * one of the methods of the provided {@link AuthenticatorCallback
|
3725 | * callback}. The handler may return immediately and process the
|
3726 | * authentication request asynchronously. The authentication will not
|
3727 | * proceed until a callback method is called.
|
3728 | *
|
3729 | * The content of the `sessionProperties` parameter depends upon
|
3730 | * whether the authentication handler is being called on initial
|
3731 | * authentication of a session or as a result of a session re-authenticating
|
3732 | * using {@link Security.changePrincipal changePrincipal}, as shown
|
3733 | * below:
|
3734 | *
|
3735 | * <table>
|
3736 | * <tr>
|
3737 | * <th></th>
|
3738 | * <th>Initial Authentication</th>
|
3739 | * <th>changePrincipal</th>
|
3740 | * </tr>
|
3741 | * <tr valign="top">
|
3742 | * <th><b>Fixed Properties</b></th>
|
3743 | * <td>
|
3744 | * A full set of fixed session properties as defined in {@link Session}.
|
3745 | * <p>
|
3746 | * <code>$Principal</code> will be the same as the supplied
|
3747 | * <code>principal</code>.
|
3748 | * <p>
|
3749 | * <code>$Roles</code> will contain the configured default roles for the
|
3750 | * principal.
|
3751 | * </td>
|
3752 | * <td>
|
3753 | * A full set of fixed session properties as defined in {@link Session}.
|
3754 | * <p>
|
3755 | * <code>$Principal</code> will be the principal from the previously
|
3756 | * authenticated session which may differ from the supplied
|
3757 | * <code>principal</code>.
|
3758 | * <p>
|
3759 | * <code>$Roles</code> will contain the configured default roles for the new
|
3760 | * principal.</td>
|
3761 | * </tr>
|
3762 | * <tr valign="top">
|
3763 | * <th><b>User-defined Properties</b></th>
|
3764 | * <td>None</td>
|
3765 | * <td>Existing user-defined properties</td>
|
3766 | * </tr>
|
3767 | * </table>
|
3768 | *
|
3769 | * On initial authentication the `proposedProperties` parameter will
|
3770 | * provide any user-defined properties that the client supplied when opening
|
3771 | * the client session, but on re-authentication it will be empty
|
3772 | *
|
3773 | * The handler can choose to call {@link AuthenticatorCallback.allow
|
3774 | * allow()} to accept the authentication request with default behavior or
|
3775 | * {@link AuthenticatorCallback.allow allow(map)} to accept the
|
3776 | * authentication request with modifications to the session properties.
|
3777 | * Alternatively it may call {@link AuthenticatorCallback.deny deny()} to
|
3778 | * deny the request or {@link AuthenticatorCallback.abstain abstain()} to
|
3779 | * abstain from authentication, in which case the request will be passed on
|
3780 | * to the next configured authentication handler.
|
3781 | *
|
3782 | * If the handler calls {@link AuthenticatorCallback.allow allow()} then the
|
3783 | * resulting session properties for the session will be as follows:
|
3784 | *
|
3785 | * <table border=1>
|
3786 | * <tr>
|
3787 | * <th></th>
|
3788 | * <th>Initial Authentication</th>
|
3789 | * <th>changePrincipal</th>
|
3790 | * </tr>
|
3791 | * <tr valign="top">
|
3792 | * <th><b>Fixed Properties</b></th>
|
3793 | * <td>As supplied plus those assigned by the server on connection.</td>
|
3794 | * <td>As supplied but with <code>$Principal</code> replaced by the supplied
|
3795 | * <code>principal</code>.</td>
|
3796 | * </tr>
|
3797 | * <tr valign="top">
|
3798 | * <th><b>User-defined Properties</b></th>
|
3799 | * <td>None</td>
|
3800 | * <td>None</td>
|
3801 | * </tr>
|
3802 | * </table>
|
3803 | *
|
3804 | * If the handler calls {@link AuthenticatorCallback.allow allow(map)} then the map
|
3805 | * may contain values for any fixed properties that can be changed/supplied
|
3806 | * (see below) and/or all user-defined properties to assign to the session.
|
3807 | * The user-defined properties may be those proposed by the client or they
|
3808 | * can be any set of user-defined properties that the handler chooses.
|
3809 | *
|
3810 | * <h3>Permitted fixed property adjustments</h3>
|
3811 | *
|
3812 | * An authentication handler can set values for any of the following fixed
|
3813 | * properties to {@link AuthenticatorCallback.allow allow(map)}:
|
3814 | *
|
3815 | * * {@link PropertyKeys.COUNTRY $Country}
|
3816 | * * {@link PropertyKeys.LANGUAGE $Language}
|
3817 | * * {@link PropertyKeys.LATITUDE $Latitude}
|
3818 | * * {@link PropertyKeys.LONGITUDE $Longitude}
|
3819 | * * {@link PropertyKeys.PRINCIPAL $Principal}
|
3820 | * * {@link PropertyKeys.ROLES $Roles}
|
3821 | *
|
3822 | * An authentication handler can only set values of these fixed properties.
|
3823 | * Other fixed properties provided by the handler will be ignored. If the
|
3824 | * handler does not set a fixed property, the value will be as supplied, or
|
3825 | * as assigned by the server.
|
3826 | *
|
3827 | * <h3>Handling the <code>$Roles</code> property</h3>
|
3828 | *
|
3829 | * The <code>$Roles</code> property is formatted as a quoted list of
|
3830 | * strings. To make the handling of this property value easier there are
|
3831 | * methods in the global `diffusion` namespace. Using these methods an
|
3832 | * authenticator can adjust roles as follows:
|
3833 | *
|
3834 | * ```
|
3835 | * const roles = diffusion.stringToRoles(
|
3836 | * sessionProperties.get(diffusion.clients.PropertyKeys.ROLES));
|
3837 | *
|
3838 | * ... changes roles are required ...
|
3839 | *
|
3840 | * sessionProperties.put(diffusion.clients.PropertyKeys.ROLES,
|
3841 | * diffusion.rolesToString(roles));
|
3842 | * callback.allow(sessionProperties);
|
3843 | * ```
|
3844 | *
|
3845 | * @param principal the name of the proposed principal, or
|
3846 | * {@link ClientControlOptions.ANONYMOUS ANONYMOUS}
|
3847 | * if none was supplied
|
3848 | * @param credentials authenticating the principal; for example, a password
|
3849 | * @param sessionProperties supplies the currently known session properties
|
3850 | * for the client. On initial authentication this
|
3851 | * will be the known fixed property values. If the
|
3852 | * session is re-authenticating using {@link
|
3853 | * Security.changePrincipal changePrincipal}, this
|
3854 | * will be the full set of fixed property values
|
3855 | * plus any user-defined properties from the
|
3856 | * existing session.
|
3857 | * @param proposedProperties provides any user-defined properties proposed
|
3858 | * by the client. The handler may choose to pass
|
3859 | * on these properties as they are, veto some
|
3860 | * properties, or add more properties before
|
3861 | * passing them to the result. The client can
|
3862 | * provide arbitrary keys and values. Supplied
|
3863 | * properties should be checked and
|
3864 | * filtered/constrained to ensure they do not
|
3865 | * affect the integrity of the application.
|
3866 | * Authentication handlers should not blindly pass
|
3867 | * proposed properties to {@link
|
3868 | * AuthenticatorCallback.allow allow}.
|
3869 | * @param callback single use callback
|
3870 | */
|
3871 | authenticate(principal: string, credentials: Credentials, sessionProperties: SessionProperties, proposedProperties: SessionProperties, callback: AuthenticatorCallback): void;
|
3872 | /**
|
3873 | * Notification that the authenticator was closed normally.
|
3874 | *
|
3875 | * No further calls to this authenticator will be made.
|
3876 | */
|
3877 | onClose(): void;
|
3878 | /**
|
3879 | * Notification of an error
|
3880 | *
|
3881 | * No further calls to this authenticator will be made.
|
3882 | *
|
3883 | * @param error the error that occurred
|
3884 | */
|
3885 | onError(error: any): void;
|
3886 | }
|
3887 | /**
|
3888 | * Security feature. Allows querying and modification of server-side
|
3889 | * security and authentication configuration.
|
3890 | *
|
3891 | * **Example:**
|
3892 | * ```
|
3893 | * // Get a reference to the security feature
|
3894 | * var security = session.security;
|
3895 | * ```
|
3896 | *
|
3897 | */
|
3898 | export interface Security {
|
3899 | /**
|
3900 | * The global permission enum
|
3901 | */ readonly GlobalPermission: typeof GlobalPermission;
|
3902 | /**
|
3903 | * The topic permission enum
|
3904 | */ readonly TopicPermission: typeof TopicPermission;
|
3905 | /**
|
3906 | * Get the principal that the session is currently authenticated as.
|
3907 | *
|
3908 | * @returns the session's principal
|
3909 | */
|
3910 | getPrincipal(): string;
|
3911 | /**
|
3912 | * Change the principal associated with this session.
|
3913 | *
|
3914 | * Allows a session to authenticate as a different principal. If the
|
3915 | * authentication fails, the current principal remains valid.
|
3916 | *
|
3917 | * @param principal the new principal to use.
|
3918 | * @param credentials credentials to authenticate the principal with.
|
3919 | * @returns a {@link Result}
|
3920 | *
|
3921 | * **Example:**
|
3922 | * ```
|
3923 | * session.security.changePrincipal('foo', 'password');
|
3924 | * ```
|
3925 | *
|
3926 | */
|
3927 | changePrincipal(principal: string, credentials: string): Result<void>;
|
3928 | /**
|
3929 | * Obtain the current contents of the server's security store.
|
3930 | *
|
3931 | * If the request is successful, the result will complete with a {@link SecurityConfiguration}.
|
3932 | *
|
3933 | * **Example:**
|
3934 | * ```
|
3935 | * session.security.getSecurityConfiguration().then(function(configuration) {
|
3936 | * console.log('Got security configuration', configuration);
|
3937 | * }, function(err) {
|
3938 | * console.log('Error getting security configuration', err);
|
3939 | * });
|
3940 | * ```
|
3941 | *
|
3942 | * @returns a {@link Result} that completes with the security configuration
|
3943 | *
|
3944 | */
|
3945 | getSecurityConfiguration(): Result<SecurityConfiguration>;
|
3946 | /**
|
3947 | * Obtain the current contents of the server's authentication store.
|
3948 | *
|
3949 | * If the request is successful, the success callback will be called with a
|
3950 | * {@link SystemAuthenticationConfiguration} object.
|
3951 | *
|
3952 | * **Example:**
|
3953 | * ```
|
3954 | * session.security.getSystemAuthenticationConfiguration().then(function(configuration) {
|
3955 | * // Display principals/roles
|
3956 | * configuration.principals.forEach(function(principal) {
|
3957 | * console.log(principal.name, principal.roles);
|
3958 | * });
|
3959 | *
|
3960 | * // Check the authentication action applied to anonymous connections
|
3961 | * console.log(configuration.anonymous.action);
|
3962 | *
|
3963 | * // Check the default roles assigned to anonymous connections
|
3964 | * console.log(configuration.anonymous.roles);
|
3965 | * }, function(err) {
|
3966 | * // Error retrieving configuration
|
3967 | * console.log(err);
|
3968 | * });
|
3969 | * ```
|
3970 | *
|
3971 | * @returns a {@link Result} that completes with the server's authentication store
|
3972 | *
|
3973 | */
|
3974 | getSystemAuthenticationConfiguration(): Result<SystemAuthenticationConfiguration>;
|
3975 | /**
|
3976 | * Send a command script to the server to update the security store. The
|
3977 | * script may be produced by the builder {@link SecurityScriptBuilder}.
|
3978 | *
|
3979 | * If the script is applied without error to the server, the operation
|
3980 | * result will complete successfully.
|
3981 | *
|
3982 | * If any command in the script fails, none of the changes will be applied,
|
3983 | * and the result will be failed with an error object.
|
3984 | *
|
3985 | * If the server is configured for topic replication then the changes will
|
3986 | * be replicated to all members of the cluster.
|
3987 | *
|
3988 | * **Example:**
|
3989 | * ```
|
3990 | * session.security.updateSecurityStore(script).then(function() {
|
3991 | * console.log('Security configuration updated');
|
3992 | * }, function(err) {
|
3993 | * console.log('Failed to update security configuration', err);
|
3994 | * });
|
3995 | * ```
|
3996 | *
|
3997 | * @param script the command script
|
3998 | * @returns a {@link Result}
|
3999 | */
|
4000 | updateSecurityStore(script: string): Result<void>;
|
4001 | /**
|
4002 | * Send a command script to the server to update the authentication store.
|
4003 | * The script may be produced by the builder {@link
|
4004 | * SystemAuthenticationScriptBuilder}.
|
4005 | *
|
4006 | * If the script is applied without error to the server, the operation
|
4007 | * result will complete successfully.
|
4008 | *
|
4009 | * If any command in the script fails, none of the changes will be applied,
|
4010 | * and the result will be failed with an error object.
|
4011 | *
|
4012 | * If the server is configured for topic replication then the changes will
|
4013 | * be replicated to all members of the cluster.
|
4014 | *
|
4015 | * **Example:**
|
4016 | * ```
|
4017 | * session.security.updateAuthenticationStore(script).then(function() {
|
4018 | * console.log('Authentication configuration updated');
|
4019 | * }, function(err) {
|
4020 | * console.log('Failed to update security configuration', err);
|
4021 | * });
|
4022 | * ```
|
4023 | *
|
4024 | * @param script the command script
|
4025 | * @returns a {@link Result}
|
4026 | */
|
4027 | updateAuthenticationStore(script: string): Result<void>;
|
4028 | /**
|
4029 | * Returns a {@link SecurityScriptBuilder} that can be used to modify the
|
4030 | * server's {@link SecurityConfiguration}.
|
4031 | *
|
4032 | * @return a script builder
|
4033 | */
|
4034 | securityScriptBuilder(): SecurityScriptBuilder;
|
4035 | /**
|
4036 | * Returns a {@link SystemAuthenticationScriptBuilder} that can be used to
|
4037 | * modify the server's {@link SystemAuthenticationConfiguration}.
|
4038 | *
|
4039 | * @return a script builder
|
4040 | */
|
4041 | authenticationScriptBuilder(): SystemAuthenticationScriptBuilder;
|
4042 | /**
|
4043 | * Register a handler for client authentication events.
|
4044 | *
|
4045 | * Each handler is registered under a particular `handlerName` . For
|
4046 | * registration to succeed, the server's security configuration must include
|
4047 | * a matching `<control-authentication-handler/>` entry for the name.
|
4048 | * Otherwise registration will fail, the handler will be closed immediately,
|
4049 | * and an error will be reported to the session error handler.
|
4050 | *
|
4051 | * Each control session can register a single handler for a `handlerName` .
|
4052 | * See {@link AuthenticationHandler.onActive onActive}.
|
4053 | *
|
4054 | * It is normal for several or all of the control sessions in a control
|
4055 | * group to set a handler for a given name. Registration will fail if a
|
4056 | * session in a different control group has registered a handler using the
|
4057 | * name.
|
4058 | *
|
4059 | * For each authentication event, the server will use its configuration to
|
4060 | * determine the handler priority order. The server can call authentication
|
4061 | * handlers in serial or parallel. The server can stop the authentication
|
4062 | * process as soon as it has an allow or deny response from a handler and
|
4063 | * all higher priority handlers have abstained.
|
4064 | *
|
4065 | * For a configured control authentication handler, the server will select a
|
4066 | * single handler from those registered for the `handlerName` . If
|
4067 | * no handlers are currently registered, the server will consult the next
|
4068 | * handler.
|
4069 | *
|
4070 | * **Example:**
|
4071 | * ```
|
4072 | * // Set a simple handler to handle pre-defined principals, otherwise defer to default handling
|
4073 | * session.security.setAuthenticationHandler('before-system-handler', [], {
|
4074 | * onAuthenticate : function(principal, credentials, details, callback) {
|
4075 | * if (principal === 'alice' && credentials === 'hello') {
|
4076 | * callback.allow();
|
4077 | * } else if (principal === 'bob') {
|
4078 | * callback.deny();
|
4079 | * } else {
|
4080 | * callback.abstain();
|
4081 | * }
|
4082 | * },
|
4083 | * onActive : function(deregister) { },
|
4084 | * onClose : function() { },
|
4085 | * onError : function() { }
|
4086 | * });
|
4087 | * ```
|
4088 | *
|
4089 | * **Example:**
|
4090 | * ```
|
4091 | * // Set a handler that allocates roles & properties to certain sessions
|
4092 | * session.security.setAuthenticationHandler('before-system-handler', [diffusion.clients.DetailType.SUMMARY], {
|
4093 | * onAuthenticate : function(principal, credentials, details, callback) {
|
4094 | *
|
4095 | * if (details.summary.clientType === diffusion.clients.ClientType.IOS &&
|
4096 | * details.summary.transportType === diffusion.clients.TransportType.WEBSOCKET) {
|
4097 | *
|
4098 | * // Session will be authenticated with the 'WS_IOS' role, and an assigned session property
|
4099 | * callback.allow({
|
4100 | * roles : ['WS_IOS'],
|
4101 | * properties : {
|
4102 | * PropertyName : 'PropertyValue'
|
4103 | * }
|
4104 | * });
|
4105 | * } else {
|
4106 | * callback.abstain();
|
4107 | * }
|
4108 | * },
|
4109 | * onActive : function(deregister) { },
|
4110 | * onClose : function() { },
|
4111 | * onError : function() { }
|
4112 | * });
|
4113 | * ```
|
4114 | *
|
4115 | * @param handlerName must match an entry in the server's security
|
4116 | * configuration for registration to succeed
|
4117 | * @param requestedDetails the session details that the server will supply,
|
4118 | * if available
|
4119 | * @param handler the authentication handler to set
|
4120 | * @returns a {@link Result}
|
4121 | *
|
4122 | *
|
4123 | * @deprecated since 6.3
|
4124 | * <p>
|
4125 | * This interface is part of the deprecated {@link
|
4126 | * AuthenticationHandler} API. Use the new {@link Authenticator}
|
4127 | * API instead.
|
4128 | */
|
4129 | setAuthenticationHandler(handlerName: string, requestedDetails: DetailType[], handler: AuthenticationHandler): Result<void>;
|
4130 | /**
|
4131 | * Register an authenticator for client authentication events.
|
4132 | *
|
4133 | * @param handlerName the handler name which must match an entry in the
|
4134 | * server's security configuration
|
4135 | * @param authenticator specifies the authentication handler
|
4136 | * @return a {@link Result} that completes when the authentication
|
4137 | * handler has been registered, returning a {@link Registration}
|
4138 | * which can be used to unregister the authentication handler.
|
4139 | * <p>
|
4140 | * Otherwise, the Result will resolve with an error. Common reasons
|
4141 | * for failure include:
|
4142 | * <ul>
|
4143 | * <li> the session is closed;
|
4144 | * <li> the session does not have `REGISTER_HANDLER` or `AUTHENTICATE`
|
4145 | * permission;
|
4146 | * <li> the server configuration does not contain a
|
4147 | * `control-authentication-handler` element with the given name.
|
4148 | * </ul>
|
4149 | *
|
4150 | * @since 6.3
|
4151 | */
|
4152 | setAuthenticator(handlerName: string, authenticator: Authenticator): Result<Registration>;
|
4153 | /**
|
4154 | * Query the global permissions assigned to the calling session.
|
4155 | *
|
4156 | * @return a {@link Result} which completes when the response is received
|
4157 | * from the server.
|
4158 | * <p>
|
4159 | * If the request was successful, the {@link Result} will
|
4160 | * complete successfully with a list of {@link GlobalPermission}.
|
4161 | *
|
4162 | * @since 6.3
|
4163 | */
|
4164 | getGlobalPermissions(): Result<GlobalPermission[]>;
|
4165 | /**
|
4166 | * Query the topic permissions assigned to the calling session on a given
|
4167 | * path.
|
4168 | *
|
4169 | * @param path the path to query for permissions
|
4170 | * @return a {@link Result} which completes when the response is received
|
4171 | * from the server.
|
4172 | * <p>
|
4173 | * If the request was successful, the {@link Result} will
|
4174 | * complete successfully with a list of {@link TopicPermission}.
|
4175 | *
|
4176 | * @since 6.3
|
4177 | */
|
4178 | getPathPermissions(path: string): Result<TopicPermission[]>;
|
4179 | }
|
4180 | /**
|
4181 | * @module diffusion.locks
|
4182 | *
|
4183 | * Provide access to {@link SessionLockScope}
|
4184 | *
|
4185 | * **Example:**
|
4186 | * ```
|
4187 | * // Get a reference to the security feature
|
4188 | * var locks = diffusion.locks;
|
4189 | * ```
|
4190 | */
|
4191 | /**
|
4192 | * Enum containing <code>scope</code> parameter of {@link Session.lock}
|
4193 | *
|
4194 | * **Example:**
|
4195 | * ```
|
4196 | * // Get the ALL_FIXED_PROPERTIES key
|
4197 | * var scope = diffusion.locks.SessionLockScope.UNLOCK_ON_SESSION_LOSS;
|
4198 | * ```
|
4199 | *
|
4200 | * @since 6.2
|
4201 | */
|
4202 | export declare enum SessionLockScope {
|
4203 | /**
|
4204 | * The lock will be released when the acquiring session is closed.
|
4205 | */
|
4206 | UNLOCK_ON_SESSION_LOSS = 0,
|
4207 | /**
|
4208 | * The lock will be released when the acquiring session loses its
|
4209 | * current connection to the server.
|
4210 | */
|
4211 | UNLOCK_ON_CONNECTION_LOSS = 1,
|
4212 | }
|
4213 | /**
|
4214 | * @hidden
|
4215 | */
|
4216 | export interface SessionLockOptionsNamespace {
|
4217 | SessionLockScope: typeof SessionLockScope;
|
4218 | }
|
4219 | export declare const SessionLockOptions: SessionLockOptionsNamespace;
|
4220 | /// <reference types="long" />
|
4221 | /**
|
4222 | * @module Session.lock
|
4223 | */
|
4224 | /**
|
4225 | * A session lock is a server-managed resource that can be used to
|
4226 | * coordinate exclusive access to shared resources across sessions. For
|
4227 | * example, to ensure a single session has the right to update a topic; to
|
4228 | * ensure at most one session responds to an event; or to select a single
|
4229 | * session to perform a housekeeping task. Session locks support general
|
4230 | * collaborative locking schemes. The application architect is responsible
|
4231 | * for designing a suitable locking scheme and for ensuring each application
|
4232 | * component follows the scheme appropriately.
|
4233 | *
|
4234 | * Session locks are identified by a lock name. Lock names are arbitrary and
|
4235 | * chosen at will to suit the application. Each lock is owned by at most one
|
4236 | * session. Locks are established on demand; there is no separate operation
|
4237 | * to create or destroy a lock.
|
4238 | *
|
4239 | * A session lock is acquired using the {@link Session.lock} method.
|
4240 | * If no other session owns the lock, the server will assign the lock to the
|
4241 | * calling session immediately. Otherwise, the server will record that the
|
4242 | * session is waiting to acquire the lock. A session can call `lock`
|
4243 | * more than once for a given session lock – if the lock is acquired,
|
4244 | * all calls will complete successfully with equal SessionLocks.
|
4245 | *
|
4246 | * If a session closes, the session locks it owns are automatically
|
4247 | * released. A session can also {@link SessionLock.unlock release a lock}.
|
4248 | * When a session lock is released and other sessions are waiting to acquire
|
4249 | * the lock, the server will arbitrarily select one of the waiting sessions
|
4250 | * and notify it that it has acquired the lock. All of the newly selected
|
4251 | * session's pending `lock` calls will complete normally. Other
|
4252 | * sessions will continue to wait.
|
4253 | *
|
4254 | * The {@link Session.lock} method takes an optional scope parameter that
|
4255 | * provides the further option of automatically releasing the lock when the
|
4256 | * session loses its connection to the server.
|
4257 | *
|
4258 | * <h3>Race conditions</h3>
|
4259 | *
|
4260 | * This session lock API has inherent race conditions. Even if an
|
4261 | * application is coded correctly to protect a shared resource using session
|
4262 | * locks, there may be a period where two or more sessions concurrently
|
4263 | * access the resource. The races arise for several reasons including
|
4264 | *
|
4265 | * * due to the <em>check-then-act</em> approach of polling
|
4266 | * {@link isOwned}, the lock can be lost after the check has succeeded but
|
4267 | * before the resource is accessed;
|
4268 | * * the server can detect a session is disconnected and assign the lock
|
4269 | * to another session before the original session has detected the
|
4270 | * disconnection.
|
4271 | *
|
4272 | * Despite this imprecision, session locks provide a useful way to
|
4273 | * coordinate session actions.
|
4274 | *
|
4275 | */
|
4276 | export interface SessionLock {
|
4277 | /**
|
4278 | * Get the name of the lock
|
4279 | * @return the name of the session lock
|
4280 | */
|
4281 | getName(): string;
|
4282 | /**
|
4283 | * A value that identifies the acquisition of the lock with the
|
4284 | * given {@link getName name}. SessionLocks that are acquired
|
4285 | * later are guaranteed to have bigger sequence values, allowing the
|
4286 | * sequence number to be used as a fencing token.
|
4287 | *
|
4288 | * @return a value that identifies the acquisition of this lock
|
4289 | */
|
4290 | getSequence(): Long;
|
4291 | /**
|
4292 | * Test whether the session lock is still owned.
|
4293 | *
|
4294 | * @return `true` if the session lock is still owned by the session
|
4295 | */
|
4296 | isOwned(): boolean;
|
4297 | /**
|
4298 | * The scope of the lock.
|
4299 | *
|
4300 | * The scope determines when the lock will be released automatically.
|
4301 | *
|
4302 | * If a session makes multiple
|
4303 | * {@link Session.lock requests for a lock}
|
4304 | * using different scopes, and the server assigns the lock to the session
|
4305 | * fulfilling the requests, the lock will be given the weakest scope
|
4306 | * (`UNLOCK_ON_CONNECTION_LOSS`). Consequently, an individual request can
|
4307 | * complete with a lock that has a different scope to that requested.
|
4308 | *
|
4309 | * @return the lock scope
|
4310 | *
|
4311 | * @see {@link Session.lock}
|
4312 | */
|
4313 | getScope(): SessionLockScope;
|
4314 | /**
|
4315 | * Release a session lock, if owned.
|
4316 | *
|
4317 | * @return a Promise that resolves when a response is received
|
4318 | * from the server.
|
4319 | * <p>
|
4320 | * On completion, this session will no longer own the named session
|
4321 | * lock. If Promise completes normally, a true value indicates this
|
4322 | * session previously owned the lock and a false value indicates
|
4323 | * it did not.
|
4324 | * <p>
|
4325 | * If the Promise resolves with an error, this session
|
4326 | * does not own the session lock.
|
4327 | *
|
4328 | * @see {@link Session.lock}
|
4329 | */
|
4330 | unlock(): Result<boolean>;
|
4331 | }
|
4332 | /**
|
4333 | * @module diffusion.timeseries
|
4334 | */
|
4335 | /**
|
4336 | * Time series event metadata.
|
4337 | */
|
4338 | export interface EventMetadata {
|
4339 | /**
|
4340 | * Sequence number identifying this event within its time series.
|
4341 | * Assigned by the server when the event is created.
|
4342 | *
|
4343 | * Sequence numbers are unique within a time series. Each event appended
|
4344 | * to a time series is assigned a sequence number that is is equal to
|
4345 | * the sequence number of the preceding event plus one.
|
4346 | */
|
4347 | readonly sequence: number;
|
4348 | /**
|
4349 | * Event timestamp. Assigned by the server when the event is created.
|
4350 | *
|
4351 | * Events do not have unique timestamps. Events with different sequence
|
4352 | * numbers may have the same timestamp.
|
4353 | *
|
4354 | * Subsequent events in a time series usually have timestamps that are
|
4355 | * greater or equal to the timestamps of earlier events, but this is not
|
4356 | * guaranteed due to changes to the time source used by the server.
|
4357 | *
|
4358 | * Timestamps represent the difference, measured in milliseconds, between
|
4359 | * the time the server added the event to the time series and midnight,
|
4360 | * January 1, 1970 UTC
|
4361 | */
|
4362 | readonly timestamp: number;
|
4363 | /**
|
4364 | * Server-authenticated identity of the session that created the event.
|
4365 | *
|
4366 | * If the session that created the event was not authenticated, the author
|
4367 | * will be an empty string.
|
4368 | */
|
4369 | readonly author: string;
|
4370 | /**
|
4371 | * Check if the EventMetadata is equal to another object
|
4372 | *
|
4373 | * @return `true` if the two objects are equal
|
4374 | */
|
4375 | equals(other: any): boolean;
|
4376 | }
|
4377 | /**
|
4378 | * An event in a time series.
|
4379 | *
|
4380 | * Two instances are {@link Event.equals equal} if and only if they have identical
|
4381 | * attributes. Typically, two Event instances that have the same sequence number will
|
4382 | * be equal, but this may not be true if the event has changed on the server –
|
4383 | * see <em>Changes to a time series made outside the API</em> in the
|
4384 | * {@link Session.timeseries TimeSeries} documentation.
|
4385 | */
|
4386 | export interface Event<V> extends EventMetadata {
|
4387 | /**
|
4388 | * The value associated with the event.
|
4389 | */
|
4390 | readonly value: V;
|
4391 | /**
|
4392 | * If this is an edit event, returns the metadata of the original event that this
|
4393 | * event replaces; otherwise returns this event.
|
4394 | *
|
4395 | * The result is always the metadata of an original event, never that of an edit event.
|
4396 | */
|
4397 | readonly originalEvent: EventMetadata;
|
4398 | /**
|
4399 | * Flag indicating whether this is an edit event.
|
4400 | *
|
4401 | * `x.isEditEvent` is equivalent to `x.originalEvent != x`.
|
4402 | */
|
4403 | readonly isEditEvent: boolean;
|
4404 | }
|
4405 | /// <reference types="long" />
|
4406 | /**
|
4407 | * @module Session.timeseries
|
4408 | */
|
4409 | /**
|
4410 | * Timeseries stream structure
|
4411 | */
|
4412 | export interface StreamStructure {
|
4413 | /**
|
4414 | * The id of the stream structure
|
4415 | */
|
4416 | readonly id: number;
|
4417 | /**
|
4418 | * The name of the stream structure
|
4419 | */
|
4420 | readonly name: string;
|
4421 | /**
|
4422 | * Convert object to string
|
4423 | *
|
4424 | * @return a string representation of the CloseClientRequest
|
4425 | */
|
4426 | toString(): string;
|
4427 | }
|
4428 | /**
|
4429 | * This feature allows a session to update and query time series topics.
|
4430 | *
|
4431 | * <h2>Time series topics</h2>
|
4432 | *
|
4433 | * A <em>time series</em> is a sequence of events. Each event contains a value
|
4434 | * and has server-assigned metadata comprised of a sequence number, timestamp,
|
4435 | * and author. Events in a time series are ordered by increasing sequence
|
4436 | * number. Sequence numbers have values between `0` and
|
4437 | * `Number.MAX_INTEGER` and are contiguous: an event with sequence number
|
4438 | * `n` will be followed by one with sequence number `n + 1` . Two
|
4439 | * events with the same sequence number will be equal – having the same
|
4440 | * timestamp, author, and value.
|
4441 | *
|
4442 | * A time series topic allows sessions to access a time series that is
|
4443 | * maintained by the server. A time series topic has an associated {@link
|
4444 | * DataType event data type}, such as `Binary` , `String` ,
|
4445 | * or `JSON` , that determines the type of value associated with each event.
|
4446 | *
|
4447 | * This feature provides a historic query API for time series topics, allowing a
|
4448 | * session to query arbitrary sub-sequences of a time series. The {@link
|
4449 | * Session.topics} and {@link Session.addStream} features complete the API,
|
4450 | * providing ways to create and subscribe to a time series topic.
|
4451 | *
|
4452 | * The API presents a time series as an append-only data structure of immutable
|
4453 | * events that is only changed by adding new events.
|
4454 | *
|
4455 | * <h3>Edit events</h3>
|
4456 | *
|
4457 | * Although a time series is append-only, an event can be overridden by
|
4458 | * appending an <em>edit event</em>. An edit event is a special type of event
|
4459 | * that overrides an earlier event in the time series (referred to as the
|
4460 | * <em>original event</em>) with a new value. When an edit event is added to a
|
4461 | * time series, the server retains both the original event and the edit event,
|
4462 | * allowing subscription and query results to reflect the edit.
|
4463 | *
|
4464 | * For example, suppose a time series has two events with the values `A`
|
4465 | * and `B` , and the first event has been overridden by a later edit event
|
4466 | * that provides a new value of `X` . The server has the following
|
4467 | * information about the time series.
|
4468 | *
|
4469 | * Sequence | Value | Type
|
4470 | * --------- | ------- | -------
|
4471 | * 0 | A | *original event*
|
4472 | * 1 | B | *original event*
|
4473 | * 2 | X | *edit of sequence 0*
|
4474 | *
|
4475 | * The current value of the event with sequence number 0 is `X` .
|
4476 | *
|
4477 | * If an original event has several edit events, the latest edit event (the one
|
4478 | * with the highest sequence number) determines its current value. Each edit
|
4479 | * event refers to an original event, never to another edit event.
|
4480 | *
|
4481 | * Extending the example by appending a further edit event to the time series:
|
4482 | *
|
4483 | * Sequence | Value | Type
|
4484 | * --------- | ------- | -------
|
4485 | * 3 | Y | *second edit of sequence 0*
|
4486 | *
|
4487 | * The current value of the event with sequence number 0 is now `Y` .
|
4488 | *
|
4489 | * <h3>Retained range</h3>
|
4490 | *
|
4491 | * A time series topic retains a range of the most recent events. When a new
|
4492 | * event is added to the time series, older events that fall outside of the
|
4493 | * range are discarded. By default, this range includes the ten most recent
|
4494 | * events. A different range can be configured by setting the
|
4495 | * {@link TopicSpecification.TIME_SERIES_RETAINED_RANGE
|
4496 | * TIME_SERIES_RETAINED_RANGE} property.
|
4497 | *
|
4498 | * <h2>Subscribing to a time series topic</h2>
|
4499 | *
|
4500 | * A session can {@link Session.select select} a time series topic and {@link
|
4501 | * Session.addStream add a value stream} to receive updates about events
|
4502 | * appended to the time series. Events are represented by {@link Event}
|
4503 | * instances. Each event has a value and {@link EventMetadata metadata}. An edit
|
4504 | * event has two sets of metadata – its own metadata and that of the
|
4505 | * original event that it replaces.
|
4506 | *
|
4507 | * <h3>Subscription range</h3>
|
4508 | *
|
4509 | * New subscribers are sent a range of events from the end of the time series.
|
4510 | * This is known as the <em>subscription range</em>. Configuring a subscription
|
4511 | * range is a convenient way to provide new subscribers with an appropriate
|
4512 | * subset of the latest events.
|
4513 | *
|
4514 | * The default subscription range depends on whether the topic is configured to
|
4515 | * publish delta streams. If delta streams are enabled, new subscribers are sent
|
4516 | * the latest event if one exists. If delta streams are disabled, new
|
4517 | * subscribers are sent no events. Delta streams are enabled by default and can
|
4518 | * be disabled by setting the {@link TopicSpecification.PUBLISH_VALUES_ONLY
|
4519 | * PUBLISH_VALUES_ONLY} property to `true`.
|
4520 | *
|
4521 | * A larger subscription range can be configured by setting the
|
4522 | * {@link TopicSpecification.TIME_SERIES_SUBSCRIPTION_RANGE
|
4523 | * TIME_SERIES_SUBSCRIPTION_RANGE} property. Regardless of the
|
4524 | * `TIME_SERIES_SUBSCRIPTION_RANGE` property, if delta streams are
|
4525 | * enabled, new subscribers will be sent at least the latest event if one
|
4526 | * exists.
|
4527 | *
|
4528 | * If the range of events is insufficient, the subscribing session can use a
|
4529 | * {@link TimeSeries.rangeQuery range query} to retrieve older events.
|
4530 | *
|
4531 | * When configuring a non-default subscription range for a time series topic,
|
4532 | * register value streams before subscribing to the topic. The session only
|
4533 | * maintains a local cache if the latest value received for a topic, not the
|
4534 | * full subscription range. If a value stream is added after a session has
|
4535 | * subscribed to a matching time series topic, the new stream will only be
|
4536 | * notified of the latest value.
|
4537 | *
|
4538 | * <h2>Updating a time series topic</h2>
|
4539 | *
|
4540 | * A session can use {@link TimeSeries.append append} to submit a value
|
4541 | * to be added to a time series. The server will add an event to the end of the
|
4542 | * time series based on the supplied value, with a new sequence number,
|
4543 | * timestamp, and the author set to the authenticated principal of the session.
|
4544 | *
|
4545 | * A session can use {@link TimeSeries.edit edit} to submit an edit to
|
4546 | * an original time series event, identified by its sequence number. The server
|
4547 | * will add an edit event to the end of the time series based on the supplied
|
4548 | * value, with a new sequence number, timestamp, and the author set to the
|
4549 | * authenticated principal of the session.
|
4550 | *
|
4551 | * <h2>Querying a time series topic</h2>
|
4552 | *
|
4553 | * A {@link RangeQuery} is a configured query that can be evaluated for a time
|
4554 | * series topic using {@link RangeQuery.selectFrom selectFrom(topicPath)}.
|
4555 | * Results are provided as streams of {@link Event Event} instances.
|
4556 | *
|
4557 | * {@link RangeQuery} is a builder for configuring a Query that selects a range
|
4558 | * of a time series. There are two types of range query that differ in how edits
|
4559 | * are processed – value range queries and edit range queries.
|
4560 | *
|
4561 | * <h3>Value range queries</h3>
|
4562 | *
|
4563 | * A value range query returns a merged view of part of a time series. This is
|
4564 | * the most common time series query and appropriate for most applications.
|
4565 | *
|
4566 | * The result of a value range query reflects the latest available edits and the
|
4567 | * {@link QueryResult query result} is ordered by the original event sequence
|
4568 | * number, presenting edit events instead of the original events they replace.
|
4569 | * Original events that have no edit events are included verbatim. Original
|
4570 | * events that have edit events are replaced by the latest edit event.
|
4571 | *
|
4572 | * A value range query of the example time series, with no range constraints so
|
4573 | * the entire time series is selected, returns two events:
|
4574 | *
|
4575 | * ```
|
4576 | * sequence=3, value=Y; original event sequence=0
|
4577 | * sequence=1, value=B
|
4578 | * ```
|
4579 | *
|
4580 | * The original value of the first event is not provided. It's apparent that the
|
4581 | * first event is an edit event because it provides the metadata of the original
|
4582 | * event it replaces.
|
4583 | *
|
4584 | * <h3>Edit range queries</h3>
|
4585 | *
|
4586 | * Applications with auditing and other administrative requirements can access
|
4587 | * original event values using an edit range query. An edit range query returns
|
4588 | * an unmerged view of a time series that can include both original events and
|
4589 | * the edit events that replace them. Edit range queries are rarely needed
|
4590 | * – value range queries satisfy most use cases.
|
4591 | *
|
4592 | * Edit range queries provide a detailed view of a time series. Because this is
|
4593 | * potentially sensitive information, an edit range query can only be performed
|
4594 | * by a session that has the `QUERY_OBSOLETE_TIME_SERIES_EVENTS`
|
4595 | * permission for the target topic.
|
4596 | *
|
4597 | * There are two sub-types of edit range query.
|
4598 | *
|
4599 | * A full audit trail of edit events can be obtained using an <em>all edits</em>
|
4600 | * edit range query. The result contains all original events selected by the
|
4601 | * query, together with all subsequent edit events that affect the original
|
4602 | * events. The query result stream provides events in time series order. An all
|
4603 | * edits query of the example time series, with no range constraints so the
|
4604 | * entire time series is selected, returns four events:
|
4605 | *
|
4606 | * ```
|
4607 | * sequence=0; value=A
|
4608 | * sequence=1; value=B
|
4609 | * sequence=2; value=X; original event sequence=0
|
4610 | * sequence=3; value=Y; original event sequence=0
|
4611 | * ```
|
4612 | *
|
4613 | * A <em>latest edits</em> edit range query returns a query result stream in
|
4614 | * time series order that contains all original events selected by the query,
|
4615 | * together with the latest edit events that affect the original events. A
|
4616 | * latest edits query of the example time series, with no range constraints so
|
4617 | * the entire time series is selected, returns three events:
|
4618 | *
|
4619 | * ```
|
4620 | * sequence=0; value=A
|
4621 | * sequence=1; value=B
|
4622 | * sequence=3; value=Y; original event sequence=0
|
4623 | * ```
|
4624 | *
|
4625 | * The initial range of events delivered for a subscription to a time series
|
4626 | * topic is derived from a <em>latest edits</em> edit range query. See
|
4627 | * <em>Subscription Range</em>.
|
4628 | *
|
4629 | * When evaluated for a time series that has no edit events, an edit range query
|
4630 | * will return the same results as a similarly configured value range query.
|
4631 | *
|
4632 | * <h2>Changes to a time series made outside the API</h2>
|
4633 | *
|
4634 | * The API presents a time series as an append-only data structure of immutable
|
4635 | * events that is only changed by adding new events. The API does not allow
|
4636 | * events to be deleted or edited.
|
4637 | *
|
4638 | * There are circumstances in which events can be removed from a time series by
|
4639 | * server operations outside the API. For example, a time series topic can be
|
4640 | * configured to discard or archive older events to save storage space; or the
|
4641 | * time series may be held in memory and lost if the server restarts. Subscribed
|
4642 | * sessions are not notified when events are removed in this way, but a session
|
4643 | * can infer the removal of events that are no longer included in query results.
|
4644 | * Similarly, an event's value can be changed on the server. For example, if an
|
4645 | * administrator changes its value to redact sensitive data. Again, subscribed
|
4646 | * sessions are not notified when events are modified, but a session can infer
|
4647 | * this has happened from query results.
|
4648 | *
|
4649 | * Whether such changes can happen for a particular time series topic depends on
|
4650 | * the topic specification, and the administrative actions that are allowed. To
|
4651 | * write a robust application, do not rely on two Event instances with the same
|
4652 | * sequence number but obtained though different API calls, being equal; nor
|
4653 | * that there are no sequence number gaps between events in query results.
|
4654 | *
|
4655 | * <h2>Access control</h2>
|
4656 | *
|
4657 | * The session must have the {@link TopicPermission.READ_TOPIC READ_TOPIC} topic
|
4658 | * permission for a topic to query a time series topic. The
|
4659 | * {@link TopicPermission.QUERY_OBSOLETE_TIME_SERIES_EVENTS
|
4660 | * QUERY_OBSOLETE_TIME_SERIES_EVENTS} topic permission is additionally required
|
4661 | * to evaluate an {@link RangeQuery.forEdits edit range} query, or a
|
4662 | * {@link RangeQuery.forValues value range query} with an
|
4663 | * {@link RangeQuery.editRange edit range}.
|
4664 | *
|
4665 | * The session must have the {@link TopicPermission.UPDATE_TOPIC UPDATE_TOPIC}
|
4666 | * topic permission for a topic to {@link TimeSeries.append append} a new event
|
4667 | * to a time series topic. The {@link TopicPermission.EDIT_TIME_SERIES_EVENTS
|
4668 | * EDIT_TIME_SERIES_EVENTS} topic permission is additionally required to {@link
|
4669 | * TimeSeries.edit submit an edit} to any time series event. The more
|
4670 | * restrictive {@link TopicPermission.EDIT_OWN_TIME_SERIES_EVENTS
|
4671 | * EDIT_OWN_TIME_SERIES_EVENTS} topic permission allows a session to submit
|
4672 | * edits to time series topic events that are authored by the principal of the
|
4673 | * calling session.
|
4674 | *
|
4675 | * @since 6.0
|
4676 | */
|
4677 | export interface TimeSeries {
|
4678 | /**
|
4679 | * Update a time series topic by appending a new value.
|
4680 | *
|
4681 | * The server will add an event to the end of the time series based on the
|
4682 | * supplied value, with a new sequence number, timestamp, and the author set
|
4683 | * to the authenticated principal of the session.
|
4684 | *
|
4685 | * @param topicPath the path of the time series topic to update
|
4686 | * @param value the event value
|
4687 | * @param valueType the type of the supplied value. This must match the value
|
4688 | * type of the {@link DataType} configured as the time
|
4689 | * series topic's {@link
|
4690 | * TopicSpecification.TIME_SERIES_EVENT_VALUE_TYPE event
|
4691 | * value type}. By default will be inferred from the
|
4692 | * provided value.
|
4693 | * @return a result that completes when a response is received from the
|
4694 | * server.
|
4695 | */
|
4696 | append(topicPath: string, value: any, valueType?: DataType<any, any, any>): Result<EventMetadata>;
|
4697 | /**
|
4698 | * Update a time series topic by appending a new value that overrides the
|
4699 | * value of an existing event.
|
4700 | *
|
4701 | * The existing event is identified by its sequence number and must be an
|
4702 | * original event.
|
4703 | *
|
4704 | * The server will add an edit event to the end of the time series based on
|
4705 | * the supplied value, with a new sequence number, timestamp, and the author
|
4706 | * set to the authenticated principal of the session.
|
4707 | *
|
4708 | * @param topicPath the path of the time series topic to update
|
4709 | * @param originalSequence the sequence number of the original event to edit
|
4710 | * @param value the event value
|
4711 | * @param valueType the type of the supplied value. This must match
|
4712 | * the value type of the {@link DataType}
|
4713 | * configured as the time series topic's {@link
|
4714 | * TopicSpecification.TIME_SERIES_EVENT_VALUE_TYPE
|
4715 | * event value type}. By default will be inferred
|
4716 | * from the provided value.
|
4717 | *
|
4718 | * @return a result that completes when a response is received from the server.
|
4719 | */
|
4720 | edit(topicPath: string, originalSequence: number | Long, value: any, valueType?: DataType<any, any, any>): Result<EventMetadata>;
|
4721 | /**
|
4722 | * Return a default range query that performs a value range query of an
|
4723 | * entire time series.
|
4724 | *
|
4725 | * Further queries with different parameters can be configured using the
|
4726 | * {@link RangeQuery} methods.
|
4727 | *
|
4728 | * The result provides {@link Bytes} values, making it
|
4729 | * compatible with any event data type supported by time series topics. A
|
4730 | * query with a more specific value type can be configured using {@link
|
4731 | * RangeQuery.as}.
|
4732 | *
|
4733 | * A RangeQuery equal to the one returned by this method can be created from
|
4734 | * an arbitrary RangeQuery as follows.
|
4735 | *
|
4736 | * ```
|
4737 | * defaults = anyRangeQuery.forValues()
|
4738 | * .fromStart()
|
4739 | * .untilLast(0)
|
4740 | * .limit(Number.MAX_INTEGER)
|
4741 | * .as(Buffer);
|
4742 | * ```
|
4743 | *
|
4744 | * @return a RangeQuery with default settings
|
4745 | */
|
4746 | rangeQuery(): RangeQuery;
|
4747 | }
|
4748 | /**
|
4749 | * Builder for queries that select a range of events from a time series.
|
4750 | *
|
4751 | * See {@link Session.timeseries} for an overview of the various types of range
|
4752 | * query:
|
4753 | *
|
4754 | * * value range queries,
|
4755 | * * latest edits edit range queries, and
|
4756 | * * all edits edit range queries.
|
4757 | *
|
4758 | * {@link TimeSeries.rangeQuery rangeQuery} returns a default
|
4759 | * RangeQuery. Further queries with different parameters can be configured
|
4760 | * using the methods of this interface. {@link RangeQuery} instances are
|
4761 | * immutable. Each method returns a copy of this query with a modified
|
4762 | * setting. Method calls can be chained together in a fluent manner to create a
|
4763 | * query. For example:
|
4764 | *
|
4765 | * ```
|
4766 | * var defaultQuery = session.timeseries.rangeQuery();
|
4767 | *
|
4768 | * // A value range query that selects up to 100 original events from the
|
4769 | * // start of a time series.
|
4770 | * first100 = defaultQuery.forValues().fromStart().next(100);
|
4771 | * ```
|
4772 | *
|
4773 | * <h2>Creating value range queries</h2>
|
4774 | *
|
4775 | * A value range query returns a merged view of part of a time series. This is
|
4776 | * the most common time series query and appropriate for most applications. A
|
4777 | * value range query begins with the {@link RangeQuery.forValues forValues}
|
4778 | * operator, followed by the <em>view range</em>. The view range determines the
|
4779 | * range of original events the time series that are of interest. See <em>Range
|
4780 | * expressions</em> below for the various ways to specify `RANGE` .
|
4781 | *
|
4782 | * The events returned by the query are constrained by an optional <em>edit
|
4783 | * range</em>, introduced by the {@link RangeQuery.editRange editRange}
|
4784 | * operator. An event will only be included in the result if it is in the edit
|
4785 | * range. Let's consider some examples to see how the view range and the edit
|
4786 | * range interact.
|
4787 | *
|
4788 | * <table>
|
4789 | * <tr>
|
4790 | * <th>Query</th>
|
4791 | * <th>Meaning</th>
|
4792 | * </tr>
|
4793 | * <tr>
|
4794 | * <td><code>rangeQuery().forValues();</code></td>
|
4795 | * <td>For each original event in the time series, either return the latest
|
4796 | * edit event or if it has no edit events, return the original event.</td>
|
4797 | * </tr>
|
4798 | * <tr>
|
4799 | * <td><code>rangeQuery().forValues().from(100).to(150);</code></td>
|
4800 | * <td>For each original event with a sequence number between 100 and 150
|
4801 | * (inclusive), either return the latest edit event or if it has no edit
|
4802 | * events, return the original event.</td>
|
4803 | * </tr>
|
4804 | * <tr>
|
4805 | * <td>
|
4806 | * <code>rangeQuery().forValues().from(100).to(150).editRange().from(400);</code>
|
4807 | * </td>
|
4808 | * <td>For each original event with a sequence number between 100 and 150
|
4809 | * (inclusive), return the latest edit event with a sequence number greater
|
4810 | * than or equal to 400.
|
4811 | * <p>
|
4812 | * The result of this query will not include any original events because
|
4813 | * there is no overlap between the view range and the edit range.</td>
|
4814 | * </tr>
|
4815 | * </table>
|
4816 | *
|
4817 | * Value range queries can be further refined using the {@link RangeQuery.limit
|
4818 | * limit()} and {@link RangeQuery.as as()} operators.
|
4819 | *
|
4820 | * <h2>Creating edit range queries</h2>
|
4821 | *
|
4822 | * An edit range query returns an unmerged view of a time series than can
|
4823 | * include both original events and the edit events that replace them. Edit
|
4824 | * range queries are rarely needed – value range queries satisfy most
|
4825 | * use cases.
|
4826 | *
|
4827 | * An edit range query begins with the {@link RangeQuery.forEdits forEdits}
|
4828 | * operator, followed by the <em>view range</em>. The view range determines the
|
4829 | * range of original events the time series that are of interest. The result
|
4830 | * will only contain original events that are in the view range, and edit events
|
4831 | * for original events in the view range. See <em>Range expressions</em> below
|
4832 | * for the various ways to specify `RANGE` .
|
4833 | *
|
4834 | * The events returned by the query are constrained by an optional <em>edit
|
4835 | * range</em>, introduced by the {@link RangeQuery.latestEdits latestEdits} or
|
4836 | * {@link RangeQuery.allEdits allEdits} operators. An event will only be
|
4837 | * included in the result if it is in the edit range. Let's consider some
|
4838 | * example edit range queries.
|
4839 | *
|
4840 | * <table>
|
4841 | * <tr>
|
4842 | * <th>Query</th>
|
4843 | * <th>Meaning</th>
|
4844 | * </tr>
|
4845 | * <tr>
|
4846 | * <td><code>rangeQuery().forEdits();</code></td>
|
4847 | * <td>Return all events in a time series.</td>
|
4848 | * </tr>
|
4849 | * <tr>
|
4850 | * <td><code>rangeQuery().forEdits().from(100).to(150);</code></td>
|
4851 | * <td>Return the original events with a sequence number between 100 and 150
|
4852 | * (inclusive) and all edit events in the time series that refer to the
|
4853 | * original events.</td>
|
4854 | * </tr>
|
4855 | * <tr>
|
4856 | * <td><code>rangeQuery().forEdits().from(100).to(150).latestEdits();</code></td>
|
4857 | * <td>Return the original events with a sequence number between 100 and 150
|
4858 | * (inclusive) and the latest edit events in the time series that refer to
|
4859 | * the original events.</td>
|
4860 | * </tr>
|
4861 | * <tr>
|
4862 | * <td>
|
4863 | * <code>rangeQuery().forEdits().from(100).to(150).allEdits().from(400);</code>
|
4864 | * </td>
|
4865 | * <td>For each original event with a sequence number between 100 and 150,
|
4866 | * (inclusive) return all edit events with a sequence number greater than or
|
4867 | * equal to 400.
|
4868 | * <p>
|
4869 | * The result of this query will not include any original events because
|
4870 | * there is no overlap between the view range and the edit range.</td>
|
4871 | * </tr>
|
4872 | * </table>
|
4873 | *
|
4874 | * Edit range queries can be further refined using the {@link RangeQuery.limit
|
4875 | * limit()} and {@link RangeQuery.as as()} operators.
|
4876 | *
|
4877 | * <h2>Range expressions</h2>
|
4878 | *
|
4879 | * Range expressions are used to specify the view and edit ranges in value
|
4880 | * range and edit range queries. Each range expression has an
|
4881 | * <em>anchor</em> that determines where to start, and a <em>span</em> that
|
4882 | * determines where the range ends. Both anchor and span are
|
4883 | * <em>inclusive</em> – if an anchor or span falls on an event, the
|
4884 | * event is included in the result.
|
4885 | *
|
4886 | * Both anchor and the span are optional. If the anchor is unspecified, the
|
4887 | * range begins at the start of the time series. If the span is unspecified,
|
4888 | * the range continues until the end of the time series.
|
4889 | *
|
4890 | * <h3>Anchors</h3>
|
4891 | *
|
4892 | *
|
4893 | * There are five ways to specify an anchor.
|
4894 | *
|
4895 | * <table>
|
4896 | * <tr>
|
4897 | * <th>Anchor</th>
|
4898 | * <th>Meaning</th>
|
4899 | * </tr>
|
4900 | * <tr>
|
4901 | * <td>{@link RangeQuery.from from(Number)}</td>
|
4902 | * <td>Sets the anchor at an absolute sequence number.</td>
|
4903 | * </tr>
|
4904 | * <tr>
|
4905 | * <td>{@link RangeQuery.from from(Date)}</td>
|
4906 | * <td>Sets the anchor at an absolute time.</td>
|
4907 | * </tr>
|
4908 | * <tr>
|
4909 | * <td>{@link RangeQuery.fromStart fromStart}</td>
|
4910 | * <td>Sets the anchor at the start of the time series.</td>
|
4911 | * </tr>
|
4912 | * <tr>
|
4913 | * <td>{@link RangeQuery.fromLast fromLast(Number)}</td>
|
4914 | * <td>Sets the anchor at a relative offset before the end of the time
|
4915 | * series. For value range queries, <code>count</code> is the number of original
|
4916 | * events. For edit range queries, <code>count</code> is the number of events of
|
4917 | * any type.</td>
|
4918 | * </tr>
|
4919 | * <tr>
|
4920 | * <td>{@link RangeQuery.fromLast fromLast(Date}<br/>
|
4921 | * {@link RangeQuery.fromLastMillis fromLastMillis}</td>
|
4922 | * <td>Sets the anchor at a relative time before the timestamp of the last
|
4923 | * event of the time series.</td>
|
4924 | * </tr>
|
4925 | * </table>
|
4926 | *
|
4927 | * An anchor point can be before the start or after the end of the time
|
4928 | * series.
|
4929 | *
|
4930 | * <h3>Spans</h3>
|
4931 | *
|
4932 | * There are nine ways to specify a span.
|
4933 | *
|
4934 | * <table>
|
4935 | * <tr>
|
4936 | * <th>Span</th>
|
4937 | * <th>Meaning</th>
|
4938 | * </tr>
|
4939 | * <tr>
|
4940 | * <td>{@link RangeQuery.to to(Number)}</td>
|
4941 | * <td>The range ends at an absolute sequence number. The <code>sequence</code>
|
4942 | * argument may be before or after the anchor.</td>
|
4943 | * </tr>
|
4944 | * <tr>
|
4945 | * <td>{@link RangeQuery.toStart toStart}</td>
|
4946 | * <td>The range ends at the start of the time series.</td>
|
4947 | * </tr>
|
4948 | * <tr>
|
4949 | * <td>{@link RangeQuery.to to(Date)}</td>
|
4950 | * <td>The range ends at an absolute time. The <code>date</code> argument may
|
4951 | * be before or after the anchor.</td>
|
4952 | * </tr>
|
4953 | * <tr>
|
4954 | * <td>{@link RangeQuery.next next(Number)}</td>
|
4955 | * <td>The range ends at an event that is a relative number of events after
|
4956 | * the anchor. For value range queries, <code>count</code> is the number of
|
4957 | * original events. For edit range queries, <code>count</code> is the number of
|
4958 | * events of any type.</td>
|
4959 | * </tr>
|
4960 | * <tr>
|
4961 | * <td>{@link RangeQuery.next next(Date)}<br/>
|
4962 | * {@link RangeQuery.nextMillis nextMillis}</td>
|
4963 | * <td>The range ends at an event that is a relative time after the
|
4964 | * anchor.</td>
|
4965 | * </tr>
|
4966 | * <tr>
|
4967 | * <td>{@link RangeQuery.previous previous(Number)}</td>
|
4968 | * <td>The range ends at an event that is a relative number of events before
|
4969 | * the anchor. For value range queries, <code>count</code> is the number of
|
4970 | * original events. For edit range queries, <code>count</code> is the number of
|
4971 | * events of any type.</td>
|
4972 | * </tr>
|
4973 | * <tr>
|
4974 | * <td>{@link RangeQuery.previous previous(Date)}<br/>
|
4975 | * {@link RangeQuery.previousMillis previousMillis}</td>
|
4976 | * <td>The range ends at an event that is a relative time before the
|
4977 | * anchor.</td>
|
4978 | * </tr>
|
4979 | * <tr>
|
4980 | * <td>{@link RangeQuery.untilLast untilLast(Number}</td>
|
4981 | * <td>The range ends at an event that is a relative number of events before
|
4982 | * the end of the time series. For value range queries, <code>count</code> is the
|
4983 | * number of original events. For edit range queries, <code>count</code> is the
|
4984 | * number of events of any type.</td>
|
4985 | * </tr>
|
4986 | * <tr>
|
4987 | * <td>{@link RangeQuery.untilLast untilLast(Date)}<br/>
|
4988 | * {@link RangeQuery.untilLastMillis untilLastMillis}</td>
|
4989 | * <td>The range ends at an event that is a relative time before the
|
4990 | * timestamp of the last event of the time series.</td>
|
4991 | * </tr>
|
4992 | * </table>
|
4993 | *
|
4994 | * A span can specify an end point that is before the start or after the end
|
4995 | * of the time series.
|
4996 | *
|
4997 | * If the span specifies an end point after the anchor, the range includes
|
4998 | * the first event at or following the anchor and ends at the last event at
|
4999 | * or preceding the end point. If the span specifies an end point before the
|
5000 | * anchor, the range includes the first event at or preceding the anchor and
|
5001 | * ends at the last event at or after the end point.
|
5002 | *
|
5003 | * <h2>Using the builder methods</h2>
|
5004 | *
|
5005 | * Although the natural order of operators in a query is as shown in the
|
5006 | * syntax diagrams above, RangeQuery builder methods – those that
|
5007 | * return another RangeQuery – can be applied in any order with the
|
5008 | * following exceptions:
|
5009 | *
|
5010 | * * {@link RangeQuery.editRange} only applies to value range queries, so cannot
|
5011 | * follow `forEdits()` without an intervening `forValues();`
|
5012 | * * {@link RangeQuery.latestEdits} and {@link RangeQuery.allEdits} only apply
|
5013 | * to edit range queries, so cannot follow `forValues()` without an
|
5014 | * intervening `forEdits()`.
|
5015 | *
|
5016 | * Each method overrides some configuration of the RangeQuery to which it is
|
5017 | * applied, as summarized in the following table.
|
5018 | *
|
5019 | * <table>
|
5020 | * <tr>
|
5021 | * <th>Builder method</th>
|
5022 | * <th>Operator type</th>
|
5023 | * <th>Overridden configuration</th>
|
5024 | * </tr>
|
5025 | * <tr>
|
5026 | * <td><code>forValues()</code></td>
|
5027 | * <td>Value range</td>
|
5028 | * <td>Overrides the existing query type to create a new value range query.
|
5029 | * Overrides the existing view range with a new view range that selects the
|
5030 | * entire time series. The existing edit range is copied unchanged.</td>
|
5031 | * </tr>
|
5032 | * <tr>
|
5033 | * <td><code>forEdits()</code></td>
|
5034 | * <td>Value range</td>
|
5035 | * <td>Overrides the existing query type to create a new edit range query
|
5036 | * that includes all edits. Overrides the existing view range with a new
|
5037 | * view range that selects the entire time series. The existing edit range
|
5038 | * is copied unchanged.</td>
|
5039 | * </tr>
|
5040 | * <tr>
|
5041 | * <td><code>editRange()</code>
|
5042 | * <td>Edit range</td></td>
|
5043 | * <td>Overrides the existing edit range with a new edit range that selects
|
5044 | * the entire time series. The existing view range is copied unchanged.<br/>
|
5045 | * Throws <code>IllegalStateException</code> if this is not a value range
|
5046 | * query.</td>
|
5047 | * </tr>
|
5048 | * <tr>
|
5049 | * <td><code>latestEdits()</code><br/>
|
5050 | * <code>allEdits()</code></td>
|
5051 | * <td>Edit range</td>
|
5052 | * <td>Overrides the existing edit range with a new edit range that selects
|
5053 | * the entire time series. The existing view range is copied unchanged.
|
5054 | * <br/>
|
5055 | * Throws <code>Error</code> if this is not an edit range query.</td>
|
5056 | * </tr>
|
5057 | * <tr>
|
5058 | * <td><code>from()</code><br/>
|
5059 | * <code>fromStart()</code><br/>
|
5060 | * <code>fromLast()</code></td>
|
5061 | * <td>Anchor</td>
|
5062 | * <td>Overrides the anchor of the current range.</td>
|
5063 | * </tr>
|
5064 | * <tr>
|
5065 | * <td><code>to()</code><br/>
|
5066 | * <code>toStart()</code><br/>
|
5067 | * <code>next()</code><br/>
|
5068 | * <code>previous()</code><br/>
|
5069 | * <code>untilLast()</code></td>
|
5070 | * <td>Span</td>
|
5071 | * <td>Overrides the span of the current range.</td>
|
5072 | * </tr>
|
5073 | * <tr>
|
5074 | * <td><code>limit()</code></td>
|
5075 | * <td>Limit</td>
|
5076 | * <td>Overrides the limit.</td>
|
5077 | * </tr>
|
5078 | * <tr>
|
5079 | * <td><code>as()</code></td>
|
5080 | * <td>Query value type</td>
|
5081 | * <td>Overrides the query value type.</td>
|
5082 | * </tr>
|
5083 | * </table>
|
5084 | *
|
5085 | * @see Session.timeseries.rangeQuery
|
5086 | */
|
5087 | export interface RangeQuery {
|
5088 | /**
|
5089 | * Return a copy of this RangeQuery configured to perform a value range
|
5090 | * query within the view range set to the entire time series.
|
5091 | *
|
5092 | * **Operator type:** value range
|
5093 | *
|
5094 | * @return a copy of this range query configured to perform a view range
|
5095 | * query within a new view range that selects the time time series.
|
5096 | */
|
5097 | forValues(): RangeQuery;
|
5098 | /**
|
5099 | * Return a copy of this RangeQuery configured to perform an edit range
|
5100 | * query within the view range set to the entire time series.
|
5101 | *
|
5102 | * **Operator type:** value range
|
5103 | *
|
5104 | * @return a copy of this range query configured to perform an edit range
|
5105 | * query with a new view range that selects the entire time series
|
5106 | */
|
5107 | forEdits(): RangeQuery;
|
5108 | /**
|
5109 | * Return a copy of this RangeQuery configured to perform a value range
|
5110 | * query with the edit range set to the entire time series.
|
5111 | *
|
5112 | * This operator can only be applied to value range queries. The default
|
5113 | * query returned by {@link TimeSeries.rangeQuery rangeQuery()} is a
|
5114 | * value range query. The {@link RangeQuery.forValues} operator can be used
|
5115 | * to create a value range query from an edit range query.
|
5116 | *
|
5117 | * **Operator type:** edit range
|
5118 | *
|
5119 | * @return a copy of this range query configured to perform a view range
|
5120 | * query with a new edit range that selects the entire time series
|
5121 | * @throws an {Error} if this is not a value range query
|
5122 | */
|
5123 | editRange(): RangeQuery;
|
5124 | /**
|
5125 | * Return a copy of this RangeQuery configured to perform an edit range
|
5126 | * query with the edit range that selects all edits in the entire time
|
5127 | * series.
|
5128 | *
|
5129 | * This operator can only be applied to edit range queries. The default
|
5130 | * query returned by {@link TimeSeries.rangeQuery rangeQuery()} is a
|
5131 | * value range query. The {@link RangeQuery.forEdits} operator can be used
|
5132 | * to create an edit range query form a value range query.
|
5133 | *
|
5134 | * **Operator type:** edit range
|
5135 | *
|
5136 | * @return a copy of this range query configured to perform an edit range
|
5137 | * query with a new edit range that selects all edits in the entire
|
5138 | * time series
|
5139 | * @throws an {Error} if this is not an edit range query
|
5140 | */
|
5141 | allEdits(): RangeQuery;
|
5142 | /**
|
5143 | * Return a copy of this RangeQuery configured to perform an edit range
|
5144 | * query with the edit range that selects latest edits in the entire
|
5145 | * time series.
|
5146 | *
|
5147 | * This operator can only be applied to edit range queries. The default
|
5148 | * query returned by {@link TimeSeries.rangeQuery rangeQuery()} is a
|
5149 | * value range query. The {@link RangeQuery.forEdits forEdits()} operator
|
5150 | * can be used to create an edit range query from a value range query.
|
5151 | *
|
5152 | * **Operator type:** edit range
|
5153 | *
|
5154 | * @return a copy of this range query configured to perform an edit range
|
5155 | * query with a new edit range that selects the latest edits in the
|
5156 | * entire time series
|
5157 | * @throws an {Error} if this is not an edit range query
|
5158 | */
|
5159 | latestEdits(): RangeQuery;
|
5160 | /**
|
5161 | * Return a copy of this RangeQuery with the anchor of the current range
|
5162 | * configured to be either an absolute sequence number, or a Date instance.
|
5163 | *
|
5164 | * **Operator type:** anchor
|
5165 | *
|
5166 | * @param sequence absolute sequence number or Date specifying the anchor of
|
5167 | * the returned range
|
5168 | * @return a copy of this range query with a new anchor
|
5169 | * @throws an {Error} if sequence is negative
|
5170 | */
|
5171 | from(sequence: number | Date): RangeQuery;
|
5172 | /**
|
5173 | * Return a copy of this RangeQuery with the anchor of the current range
|
5174 | * configured to be the start of the time series.
|
5175 | *
|
5176 | * There is a difference between <ode>fromStart(</code> and `from(0)`
|
5177 | * if the range also ends before the first event of the time series. For
|
5178 | * example, `fromStart().toStart()` is always empty, but
|
5179 | * `from(0).toStart()` includes the event with sequence number
|
5180 | * `0` .
|
5181 | *
|
5182 | * **Operator type:** anchor
|
5183 | *
|
5184 | * @return a copy of this range query with a new anchor
|
5185 | */
|
5186 | fromStart(): RangeQuery;
|
5187 | /**
|
5188 | * Return a copy of this RangeQuery with the anchor of the current range
|
5189 | * configured to be a relative offset before the end of the time series.
|
5190 | *
|
5191 | * **Operator type:** anchor
|
5192 | *
|
5193 | * @param count specifies the anchor as a number of events before the
|
5194 | * end of the time series. For value range queries, count is
|
5195 | * the number of original events. For edit range queries,
|
5196 | * count is the number of events of any type.
|
5197 | * @return a copy of this range query with a new anchor
|
5198 | * @throws an {Error} if count is negative
|
5199 | */
|
5200 | fromLast(count: number): RangeQuery;
|
5201 | /**
|
5202 | * Return a copy of this RangeQuery with the anchor of the current range
|
5203 | * configured to be a relative time from the timestamp of the last event
|
5204 | * in the time series.
|
5205 | *
|
5206 | * **Operator type:** anchor
|
5207 | *
|
5208 | * @param timeSpan specifies anchor as a number of milliseconds relative
|
5209 | * to the timestamp of the latest event in the time series
|
5210 | * @return a copy of this range query with a new anchor
|
5211 | * @throws an {Error} if timeSpan is negative
|
5212 | */
|
5213 | fromLastMillis(timeSpan: number): RangeQuery;
|
5214 | /**
|
5215 | * Return a copy of this RangeQuery with the span of the current range
|
5216 | * configured to end at an absolute sequence number or Date instance.
|
5217 | *
|
5218 | * **Operator type:** span
|
5219 | *
|
5220 | * @param sequence absolute sequence number or Date instance specifying the
|
5221 | * end of the returned range
|
5222 | * @return a copy of this range query with a new span
|
5223 | * @throws an {Error} if sequence is negative
|
5224 | */
|
5225 | to(sequence: number | Date): RangeQuery;
|
5226 | /**
|
5227 | * Return a copy of this RangeQuery with the span of the current range
|
5228 | * configured to end at the start of the time series.
|
5229 | *
|
5230 | * There is a difference between `toStart()` and `to(0)` if
|
5231 | * the range also starts before the first event of the time series. For
|
5232 | * example, `fromStart().toStart()` is always empty, but
|
5233 | * `fromStart().to(0)` includes the event with sequence number
|
5234 | * `0` .
|
5235 | *
|
5236 | * **Operator type:** span
|
5237 | *
|
5238 | * @return a copy of this range query with a new span
|
5239 | */
|
5240 | toStart(): RangeQuery;
|
5241 | /**
|
5242 | * Return a copy of this RangeQuery with the span of the current range
|
5243 | * configured to select a range of events following the anchor.
|
5244 | *
|
5245 | * **Operator type:** span
|
5246 | *
|
5247 | * @param count specifies the end of the range of events to select
|
5248 | * following the anchor. For value range queries, count is the
|
5249 | * number of original events. For edit range queries, count is
|
5250 | * the number of events of any type.
|
5251 | * @throws an {Error} if count is negative
|
5252 | * @return a copy of this range query with a new span
|
5253 | */
|
5254 | next(count: number): RangeQuery;
|
5255 | /**
|
5256 | * Return a copy of this RangeQuery with the span of the current range
|
5257 | * configured to select a temporal range of events following the anchor.
|
5258 | *
|
5259 | * **Operator type:** span
|
5260 | *
|
5261 | * @param timeSpan the time span in milliseconds of events following the
|
5262 | * anchor to select
|
5263 | * @return a copy of this range query with a new span
|
5264 | * @throws an {Error} if timeSpan is negative
|
5265 | */
|
5266 | nextMillis(timeSpan: number): RangeQuery;
|
5267 | /**
|
5268 | * Return a copy of this RangeQuery with the span of the current range
|
5269 | * configured to select a range of events preceding the anchor.
|
5270 | *
|
5271 | * **Operator type:** span
|
5272 | *
|
5273 | * @param count specifies the end of the range of events to select
|
5274 | * preceding the anchor. For value range queries, count is the
|
5275 | * number of original events. For edit range queries, count is
|
5276 | * the number of events of any type.
|
5277 | * @return a copy of this range query with a new span
|
5278 | * @throws an {Error} if count is negative
|
5279 | */
|
5280 | previous(count: number): RangeQuery;
|
5281 | /**
|
5282 | * Return a copy of this RangeQuery with the span of the current range
|
5283 | * configured to select a temporal range of events preceding the anchor.
|
5284 | *
|
5285 | * **Operator type:** span
|
5286 | *
|
5287 | * @param timeSpan the time span in milliseconds of events preceding the
|
5288 | * anchor to select
|
5289 | * @return a copy of this range query with a new span
|
5290 | * @throws an {Error} if timeSpan is negative
|
5291 | */
|
5292 | previousMillis(timeSpan: number): RangeQuery;
|
5293 | /**
|
5294 | * Return a copy of this RangeQuery with the span of the current range
|
5295 | * configured to end a number of events before the end of the time
|
5296 | * series.
|
5297 | *
|
5298 | * **Operator type:** span
|
5299 | *
|
5300 | * @param count specifies the end of the range of events to select as a
|
5301 | * number of events before the end of the time series. For
|
5302 | * value range queries, count is the number of original
|
5303 | * events. For edit range queries, count is the number of
|
5304 | * events of any type.
|
5305 | * @return a copy of this range query with a new span
|
5306 | * @throws an {Error} if count is negative
|
5307 | */
|
5308 | untilLast(count: number): RangeQuery;
|
5309 | /**
|
5310 | * Return a copy of this RangeQuery with the span of the current range
|
5311 | * configured to end at a relative time from the timestamp of the last
|
5312 | * event in the time series.
|
5313 | *
|
5314 | * **Operator type:** span
|
5315 | *
|
5316 | * @param timeSpan specifies the end of the range of events to select as
|
5317 | * a number of milliseconds relative to the timestamp of
|
5318 | * the latest event in the time series
|
5319 | * @return a copy of this range query with a new span
|
5320 | * @throws an {Error} if timeSpan is negative
|
5321 | */
|
5322 | untilLastMillis(timeSpan: number): RangeQuery;
|
5323 | /**
|
5324 | * Return a copy of this RangeQuery that returns at most count events.
|
5325 | *
|
5326 | * If the query would otherwise select more than count events, only the
|
5327 | * latest count values (those with the highest sequence numbers) are
|
5328 | * returned.
|
5329 | *
|
5330 | * This is most useful when a temporal span has been configured with
|
5331 | * {@link RangeQuery.nextMillis} or {@link RangeQuery.previousMillis},
|
5332 | * where the potential number of returned events is unknown.
|
5333 | *
|
5334 | * {@link QueryResult.isComplete isComplete()} can be used to determine
|
5335 | * whether a query has returned an incomplete result.
|
5336 | *
|
5337 | * **Operator type:** limit
|
5338 | *
|
5339 | * @param count the maximum number of events to return
|
5340 | * @return a copy of this range query with a new limit
|
5341 | * @throws an {Error} if count is negative
|
5342 | */
|
5343 | limit(count: number): RangeQuery;
|
5344 | /**
|
5345 | * Return a copy of this RangeQuery with a different query value type.
|
5346 | *
|
5347 | * A query can only be evaluated successfully against time series topics
|
5348 | * with a compatible event data type. If a query method is called for a
|
5349 | * time series topic with an incompatible event data type, the query
|
5350 | * will complete exceptionally.
|
5351 | *
|
5352 | * If the event data type of the time series topic is known,
|
5353 | * compatibility of a particular `valueClass` can be checked using
|
5354 | * {@link DataType.canReadAs canReadAs}. The
|
5355 | * {@link TimeSeries.rangeQuery default range query} has a query value
|
5356 | * type of {@link Bytes}, which is compatible with all time series value
|
5357 | * data types.
|
5358 | *
|
5359 | * **Operator type:** query value type
|
5360 | *
|
5361 | * @param valueClass the value class or data type to read event values as
|
5362 | * @return a copy of this range query with a new query value type
|
5363 | */
|
5364 | as(valueClass: DataType<any, any, any> | (new (...args: any[]) => any)): RangeQuery;
|
5365 | /**
|
5366 | * Evaluate this query for a time series topic.
|
5367 | *
|
5368 | * The session must have the `READ_TOPIC` topic permission for `topicPath`
|
5369 | * to evaluate a query. The `QUERY_OBSOLETE_TIME_SERIES_EVENTS` topic
|
5370 | * permission is also required if this is an {@link RangeQuery.forEdits edit
|
5371 | * range} query, or a {@link RangeQuery.forValues value range query} with an
|
5372 | * {@link RangeQuery.editRange edit range}.
|
5373 | *
|
5374 | * @param topicPath the path of the time series topic to query
|
5375 | *
|
5376 | * @return a result that completes when a response is
|
5377 | * received from the server.
|
5378 | * <p>
|
5379 | * If the query returned results, the result will
|
5380 | * complete successfully and provide an {@link QueryResult}.
|
5381 | * <p>
|
5382 | * Otherwise, the result will complete exceptionally
|
5383 | * with an {@link ErrorReason}.
|
5384 | */
|
5385 | selectFrom(topicPath: string): Result<QueryResult>;
|
5386 | }
|
5387 | /**
|
5388 | * Query result providing a {@link Stream} of events.
|
5389 | */
|
5390 | export interface QueryResult {
|
5391 | /**
|
5392 | * Returns the number of events selected by the query.
|
5393 | *
|
5394 | * This number may be greater than `stream().count()` due to a
|
5395 | * policy of the time series topic to limit the number of returned
|
5396 | * results, or the use of {@link RangeQuery.limit}.
|
5397 | */
|
5398 | readonly selectedCount: number;
|
5399 | /**
|
5400 | * The timeseries events returned
|
5401 | */
|
5402 | readonly events: Array<Event<any>>;
|
5403 | /**
|
5404 | * Returns whether this result includes all events selected by the
|
5405 | * query.
|
5406 | */
|
5407 | readonly isComplete: boolean;
|
5408 | /**
|
5409 | * Returns a description of the structure of the result stream.
|
5410 | */
|
5411 | readonly streamStructure: StreamStructure;
|
5412 | /**
|
5413 | * Merge this result with `other` , combining original events and
|
5414 | * edit events, to produce a new {@link QueryResult}.
|
5415 | *
|
5416 | * The following rules are applied to calculate the result:
|
5417 | *
|
5418 | * * If this result and `other` have an event with equal
|
5419 | * sequence numbers, the event from `other` is selected.
|
5420 | * * An edit event is selected in place of its original event.
|
5421 | * * If there are multiple edit events of an original edit, the one
|
5422 | * with the highest sequence is selected.
|
5423 | *
|
5424 | * The returned result implements {@link QueryResult.isComplete}
|
5425 | * to return true and {@link QueryResult.selectedCount} to
|
5426 | * return the count of events in the stream, regardless of whether this
|
5427 | * result is complete.
|
5428 | *
|
5429 | * @param other the other query result to merge
|
5430 | * @return the merged result
|
5431 | */
|
5432 | merge(other: QueryResult): QueryResult;
|
5433 | }
|
5434 | /**
|
5435 | * @module Session.topics
|
5436 | */
|
5437 | /**
|
5438 | * Topic control feature.
|
5439 | *
|
5440 | * Provides methods to change and update the topic tree stored on the server.
|
5441 | *
|
5442 | * **Example:**
|
5443 | * ```
|
5444 | * // Get a reference to topic control feature
|
5445 | * var topics = session.topics;
|
5446 | * ```
|
5447 | */
|
5448 | export interface TopicControl {
|
5449 | /**
|
5450 | * Add a topic to the server at a specific path. This returns a {@link Result}.
|
5451 | *
|
5452 | * The path should be a string. To express hierarchies, `/` can
|
5453 | * be used as a delimiter. This allows topics to be nested and grouped below
|
5454 | * each other. For example, `session.topics.add('foo/bar');`
|
5455 | * creates the topic `bar` . A topic is not created at `foo`
|
5456 | * by this method.
|
5457 | *
|
5458 | * Each topic has a particular {@link TopicType type}, which constrains the
|
5459 | * kind of values that the topic will allow. This type can either be
|
5460 | * explicitly provided, or included as part of a {@link TopicSpecification
|
5461 | * TopicSpecification}.
|
5462 | *
|
5463 | * <h5>Adding from topic type</h5>
|
5464 | *
|
5465 | * To directly specify the type of topic to create, provide a string path
|
5466 | * and a {@link TopicType}. Topics specified in this way
|
5467 | * are created with default topic properties, as described in {@link TopicSpecification}.
|
5468 | *
|
5469 | * <h5>Adding from topic specification</h5>
|
5470 | *
|
5471 | * {@link TopicSpecification TopicSpecifications} allows
|
5472 | * the creation of topics of a particular type, along with additional
|
5473 | * properties that determine how the topic operates. For instance, you may
|
5474 | * wish to specify that a topic will validate values before publishing, or
|
5475 | * that it will only publish values instead of deltas.
|
5476 | *
|
5477 | * <h5>Operation results</h5>
|
5478 | *
|
5479 | * If the topic was added, or a topic already exists with the same path and
|
5480 | * specification, the operation will succeed. If there is a problem with
|
5481 | * adding the topic then the result will be rejected with an error.
|
5482 | *
|
5483 | * If any sessions have already subscribed to the same path that a topic is
|
5484 | * created for, they will receive a `subscription` event once the topic is
|
5485 | * added, and a `value` event with the initial value (if supplied).
|
5486 | *
|
5487 | * If the session is closed when calling this method, the returned result
|
5488 | * will be rejected.
|
5489 | *
|
5490 | * <h5>Failure</h5>
|
5491 | *
|
5492 | * If the operation fails a {@link TopicAddFailReason} is
|
5493 | * provided. Adding a topic may fail because the session has insufficient
|
5494 | * permissions; a topic already exists at the specified path; or certain
|
5495 | * mandatory {@link TopicSpecification TopicSpecification}
|
5496 | * properties were missing
|
5497 | *
|
5498 | * **Example:**
|
5499 | * ```
|
5500 | * // Create a topic with a Topic Type
|
5501 | * session.topics.add('foo/binary', diffusion.topics.TopicType.BINARY);
|
5502 | * ```
|
5503 | *
|
5504 | * **Example:**
|
5505 | * ```
|
5506 | * // Create a topic with a TopicSpecification
|
5507 | * const TopicSpecification = diffusion.topics.TopicSpecification;
|
5508 | * var specification = new TopicSpecification(diffusion.topics.TopicType.JSON, {
|
5509 | * TopicSpecification.VALIDATE_VALUES : "true"
|
5510 | * });
|
5511 | *
|
5512 | * session.topics.add('foo/json', specification);
|
5513 | * ```
|
5514 | *
|
5515 | * **Example:**
|
5516 | * ```
|
5517 | * // Handle the add topic result
|
5518 | * session.topics.add('foo/bob', diffusion.topics.TopicType.JSON).then(function(result) {
|
5519 | * if (result.added) {
|
5520 | * console.log('Topic added');
|
5521 | * } else {
|
5522 | * console.log('A compatible topic already exists');
|
5523 | * }
|
5524 | * }, function(error) {
|
5525 | * console.log('Topic add failed: ', error);
|
5526 | * });
|
5527 | * ```
|
5528 | *
|
5529 | * @param topicPath the topic path to create.
|
5530 | * @param specification the topic type/specification
|
5531 | * @returns a {@link Result} for this operation
|
5532 | */
|
5533 | add(topicPath: string, specification: TopicType | TopicSpecification): Result<TopicAddResult>;
|
5534 | /**
|
5535 | * Remove one or more topics at the server.
|
5536 | *
|
5537 | * The topics to remove will depend upon the nature of the topic selector
|
5538 | * specified. If the selector does not have {@link TopicSelector descendant
|
5539 | * pattern qualifiers} (i.e. / or //), only those topics that exist at paths
|
5540 | * indicated by the selector will be removed and not their descendants. If a
|
5541 | * single / qualifier is specified, all descendants of the matching topic
|
5542 | * paths will be removed. If // is specified, all branches of the topic tree
|
5543 | * that match the selector (i.e topics at the selected paths and all
|
5544 | * descendants of the selected paths) will be removed.
|
5545 | *
|
5546 | * This function can take any number of arguments. Each argument can be a string
|
5547 | * or a {@link TopicSelector}. Alternatively, an array of strings and
|
5548 | * {@link TopicSelector}s can be passed as a single argument. At least one
|
5549 | * valid selector has to be specified.
|
5550 | *
|
5551 | * **Example:**
|
5552 | * ```
|
5553 | * // Remove the topic at 'foo/bar', leaving descendants
|
5554 | * session.topics.remove('>foo/bar');
|
5555 | * ```
|
5556 | *
|
5557 | * **Example:**
|
5558 | * ```
|
5559 | * // Remove the topic at 'foo/bar' and all descendants
|
5560 | * session.topics.remove('?foo/bar//');
|
5561 | * ```
|
5562 | *
|
5563 | * @param selector the selector specifying the topics to remove
|
5564 | * @returns a {@link Result} for this operation
|
5565 | */
|
5566 | remove(selector: Array<string | TopicSelector>): Result<void>;
|
5567 | remove(...selector: Array<string | TopicSelector>): Result<void>;
|
5568 | /**
|
5569 | * Register a deferred action to remove a branch of the topic tree when this
|
5570 | * session is closed.
|
5571 | *
|
5572 | * A removal action can be registered at any point in the topic tree, but
|
5573 | * can not be placed above or below existing registrations. An
|
5574 | * `error` event will be emitted if the server rejects the
|
5575 | * registration.
|
5576 | *
|
5577 | * When this session is closed, regardless of reason, this topic and all
|
5578 | * topics below it will be removed from the topic tree.
|
5579 | *
|
5580 | * Multiple sessions can request that the same branch be removed. If a branch
|
5581 | * has multiple registrations, then the marked topics will not be removed
|
5582 | * until all registered sessions have been closed.
|
5583 | *
|
5584 | * When registration is successful, the {@link Result} will
|
5585 | * call the success callback with an object representing the registration
|
5586 | * with the property function deregister that can be called at any point to
|
5587 | * remove this registered action. The deregistration function returns a new
|
5588 | * {@link Result}.
|
5589 | *
|
5590 | * If the session is closed when calling this method, the returned result
|
5591 | * will emit an `error` event.
|
5592 | *
|
5593 | * @deprecated since 6.1
|
5594 | *
|
5595 | * The preferred method for automatic removal of topics is
|
5596 | * the {@link TopicSpecification.REMOVAL REMOVAL} topic
|
5597 | * property. To achieve the equivalent of this method the
|
5598 | * property can be specified as:-
|
5599 | *
|
5600 | * ```
|
5601 | * when this session closes remove "?topicPath//"
|
5602 | * ```
|
5603 | *
|
5604 | * To achieve a dependency upon more than one session, a
|
5605 | * condition specifying a principal name or some other session
|
5606 | * property can be used.
|
5607 | *
|
5608 | * This method will be removed in a future release.
|
5609 | *
|
5610 | * **Example:**
|
5611 | * ```
|
5612 | * // Remove all topics under 'foo'
|
5613 | * session.topics.removeWithSession('foo').then(
|
5614 | * function(registration) {
|
5615 | * // Registration complete
|
5616 | *
|
5617 | * // Deregister this action
|
5618 | * registration.deregister().then(
|
5619 | * function() {
|
5620 | * // Deregistration complete
|
5621 | * },
|
5622 | * function(err) {
|
5623 | * // Failure while deregistering
|
5624 | * }
|
5625 | * );
|
5626 | * },
|
5627 | * function(err) {
|
5628 | * // Could not register
|
5629 | * }
|
5630 | * );
|
5631 | * ```
|
5632 | *
|
5633 | * @param topicPath the path of the topic tree to remove
|
5634 | * @returns registration {@link Result}.
|
5635 | */
|
5636 | removeWithSession(topicPath: string): Result<RemoveWithSessionResult>;
|
5637 | /**
|
5638 | * Update a topic on the server with a new supplied value. The returned
|
5639 | * {@link Result} will complete if the update is successfully applied, and
|
5640 | * any sessions subscribed to the same topic will be notified of the new
|
5641 | * topic value.
|
5642 | *
|
5643 | * If the session is closed when calling this method, the returned result
|
5644 | * will also emit an `error` event.
|
5645 | *
|
5646 | * <h5>Failure</h5>
|
5647 | *
|
5648 | * If the operation fails a {@link UpdateFailReason} is provided. The value
|
5649 | * provided must be compatible with the data type of the topic being
|
5650 | * updated, or the update will be rejected. Updates will also be rejected if
|
5651 | * the session has insufficient permissions, or the topic does not exist.
|
5652 | *
|
5653 | * Prefer {@link TopicControl.updateValue} when updating a `Double` or
|
5654 | * `Int64` topic. This method can infer the wrong data type when updating a
|
5655 | * `Double` topic with a value that does not have a fractional component.
|
5656 | *
|
5657 | * **Example:**
|
5658 | * ```
|
5659 | * // Update topic 'foo/bar' with string value.
|
5660 | * session.topics.update('foo/bar', 'baz');
|
5661 | * ```
|
5662 | *
|
5663 | * **Example:**
|
5664 | * ```
|
5665 | * // Update topic with JSON content
|
5666 | * var content = diffusion.datatypes.json().from({ "foo" : "bar" });
|
5667 | *
|
5668 | * session.topics.update('foo/bar', content);
|
5669 | * ```
|
5670 | *
|
5671 | * @param path the topic path to update
|
5672 | * @param value the value to update the topic with
|
5673 | * @returns a {@link Result} that completes with the topic path that has
|
5674 | * been updated.
|
5675 | *
|
5676 | * @deprecated since 6.2
|
5677 | * <p>
|
5678 | * This method is deprecated. Use {@link TopicUpdate.set}
|
5679 | * instead. This method will be removed in a future release.
|
5680 | */
|
5681 | update(path: string, value: any): Result<string>;
|
5682 | /**
|
5683 | * This method is similar to {@link TopicControl.update} but takes in a
|
5684 | * data type so that the updater can determine which data type to use when
|
5685 | * encoding the value.
|
5686 | *
|
5687 | * Note that if a double value is applied to an `Int64` topic, the
|
5688 | * fractional component is ignored. Updating a topic with a different value
|
5689 | * type can lead to an unexpected value getting applied to the topic.
|
5690 | *
|
5691 | * **Example:**
|
5692 | * ```
|
5693 | * session.topics.updateValue('foo', 123.45, diffusion.datatypes.double());
|
5694 | * ```
|
5695 | *
|
5696 | * @param path the topic path to update
|
5697 | * @param value the value to update the topic with
|
5698 | * @param datatype the data type to be used for encoding the value
|
5699 | * @returns a {@link Result} that completes with the topic path that has
|
5700 | * been updated.
|
5701 | *
|
5702 | * @deprecated since 6.2
|
5703 | * <p>
|
5704 | * This method is deprecated. Use {@link TopicUpdate.set}
|
5705 | * instead. This method will be removed in a future release.
|
5706 | */
|
5707 | updateValue(path: string, value: any, datatype: DataType<any, any, any>): Result<string>;
|
5708 | /**
|
5709 | * Register a handler to provide exclusive updates for a particular branch
|
5710 | * of the topic tree. Once successfully registered, the handler will be
|
5711 | * called with lifecycle callbacks. This grants this session sole access to
|
5712 | * publish updates to topics at or under the branch used for registration.
|
5713 | *
|
5714 | * If no other handlers have been registered for the topic path, the handler
|
5715 | * will enter the {@link TopicUpdateHandler.onActive active} state. This
|
5716 | * provides an {@link Updater updater} which can then be used to publish
|
5717 | * updates for topics at or below the registered topic path.
|
5718 | *
|
5719 | * If there is an existing handler for the topic path, the handler will be
|
5720 | * put into the {@link TopicUpdateHandler.onStandBy standby} state. This
|
5721 | * indicates that the handler is registered but does not have access to
|
5722 | * publish updates. Once all previously registered handlers are closed, this
|
5723 | * handler will transition to the {@link TopicUpdateHandler.onActive active}
|
5724 | * state.
|
5725 | *
|
5726 | * The handler will be closed if the session closes or `unregister` is
|
5727 | * called. This is a terminal state from which no further state transitions
|
5728 | * will occur. When a registered handler is closed, if there is another
|
5729 | * handler registered by a different session, this next handler will
|
5730 | * transition to an active state.
|
5731 | *
|
5732 | * Handlers cannot be registered above or below the topic path of any other
|
5733 | * registered handlers. Attempting to do so will close the handler.
|
5734 | *
|
5735 | * **Example:**
|
5736 | * ```
|
5737 | * session.topics.registerUpdateSource('foo/bar', {
|
5738 | * onRegister : function(topicPath, unregister) {
|
5739 | * // The handler has been registered
|
5740 | *
|
5741 | * // Unregister the handler
|
5742 | * unregister();
|
5743 | * },
|
5744 | * onActive : function(topicPath, updater) {
|
5745 | * // Now that we're active, we have sole write access for all topics under 'foo/bar'
|
5746 | * updater.update('foo/bar/baz', 123).then(function() {
|
5747 | * // Updates return a promise just like session.topics.update
|
5748 | * });
|
5749 | * },
|
5750 | * onStandby : function(topicPath) {
|
5751 | * // The updater is registered, but another updater currently holds the active state.
|
5752 | * },
|
5753 | * onClose : function(topicPath) {
|
5754 | * // The updater is closed
|
5755 | * }
|
5756 | * });
|
5757 | * ```
|
5758 | *
|
5759 | * **Example:**
|
5760 | * ```
|
5761 | * // 'client' is an anonymous session that has insufficient permission to register an update source
|
5762 | * client.topics.registerUpdateSource('foo/bar', {
|
5763 | * onRegister : function(topicPath, unregister) {
|
5764 | * },
|
5765 | * onActive : function(topicPath, updater) {
|
5766 | * },
|
5767 | * onStandby : function(topicPath) {
|
5768 | * },
|
5769 | * onClose : function(topicPath, error) {
|
5770 | * // The updater is closed because the error is diffusion.errors.ACCESS_DENIED
|
5771 | * }
|
5772 | * });
|
5773 | * ```
|
5774 | *
|
5775 | * @param path the topic path to register an update source for.
|
5776 | * @param updateHandler handler specifies the handler for the specified
|
5777 | * branch (unless overridden by a handler registered
|
5778 | * against a more specific branch)
|
5779 | * @returns a {@link Result} for this operation
|
5780 | *
|
5781 | * @deprecated since 6.2
|
5782 | * <p>
|
5783 | * This method is deprecated. Use {@link
|
5784 | * TopicUpdate.createUpdateStream} instead. This method will be
|
5785 | * removed in a future release.
|
5786 | */ registerUpdateSource(path: string, updateHandler: TopicUpdateHandler): Result<void>;
|
5787 | /**
|
5788 | * Register a {@link MissingTopicHandler} to handle requests for a branch of
|
5789 | * the topic tree.
|
5790 | *
|
5791 | * The provided handler is called when a client subscribes or fetches using
|
5792 | * a topic selector that matches no existing topics. This allows a control
|
5793 | * client to intercede when another session requests a topic that does not
|
5794 | * exist. The control client may {@link TopicControl.add create the
|
5795 | * topic}, perform some other action, or do nothing, before allowing the
|
5796 | * client operation to proceed by calling {@link
|
5797 | * MissingTopicNotification.proceed proceed()}. Alternatively, the control
|
5798 | * client can call {@link MissingTopicNotification.cancel cancel()} to
|
5799 | * discard the request.
|
5800 | *
|
5801 | * A control client can register multiple handlers, but may only register a
|
5802 | * single handler for a given topic path. See {@link
|
5803 | * MissingTopicHandler.onRegister}. A handler will only be called for topic
|
5804 | * selectors with a {@link TopicSelector.prefix path prefix} that starts
|
5805 | * with or is equal to `topicPath` . If the path prefix matches multiple
|
5806 | * handlers, the one registered for the most specific (longest) topic path
|
5807 | * will be called.
|
5808 | *
|
5809 | * If the session is closed or the handler could not be registered, the
|
5810 | * returned {@link Result} will call its failure callback, and the handler's
|
5811 | * {@link MissingTopicHandler.onClose} or {@link
|
5812 | * MissingTopicHandler.onError} method will be called.
|
5813 | *
|
5814 | * @param topicPath identifies a branch in the topic tree
|
5815 | * @param handler specifies the handler for the specified branch (unless
|
5816 | * overridden by a handler registered against a more
|
5817 | * specific branch)
|
5818 | *
|
5819 | * @returns a {@link Result} for this registration
|
5820 | */
|
5821 | addMissingTopicHandler(path: string, updateHandler: MissingTopicHandler): Result<void>;
|
5822 | }
|
5823 | /**
|
5824 | * Handler called when a client session subscribes or fetches using a topic
|
5825 | * selector that matches no topics. This interface must be implemented by the user.
|
5826 | * <P>
|
5827 | * Handler instances can be registered using
|
5828 | * {@link TopicControl.addMissingTopicHandler addMissingTopicHandler}.
|
5829 | *
|
5830 | * @class MissingTopicHandler
|
5831 | */
|
5832 | export interface MissingTopicHandler {
|
5833 | /**
|
5834 | * Called when a client session requests a topic that does not exist,
|
5835 | * and the topic path belongs to part of the topic tree for which this
|
5836 | * handler was registered.
|
5837 | *
|
5838 | * Missing topic notifications only occur when using the deprecated
|
5839 | * {@link Session.fetch} mechanism. The newer {@link Session.fetchRequest}
|
5840 | * mechanism does not generate missing topic notifications.
|
5841 | *
|
5842 | * The handler implementation should take the appropriate action (for
|
5843 | * example, create the topic), and then call
|
5844 | * {@link MissingTopicNotification.proceed proceed} on the supplied
|
5845 | * `notification` . This allows the client request to continue and
|
5846 | * successfully resolve against the topic if it was created.
|
5847 | *
|
5848 | * Alternatively, the handler can call {@link
|
5849 | * MissingTopicNotification.cancel cancel} to discard the request. A
|
5850 | * handler should always call `proceed` or `cancel` , otherwise resources
|
5851 | * will continue to be reserved on the server until the notification times
|
5852 | * out.
|
5853 | *
|
5854 | * @param notification the missing topic notification
|
5855 | */
|
5856 | onMissingTopic(notification: MissingTopicNotification): void;
|
5857 | /**
|
5858 | * Called when the handler has been successfully registered with the server.
|
5859 | *
|
5860 | * A session can register a single handler for a given branch of the topic
|
5861 | * tree. If there is already a handler registered for the topic path the
|
5862 | * operation will fail and {@link MissingTopicHandler.onClose onClose} will
|
5863 | * be called.
|
5864 | *
|
5865 | * To deregister the handler, call the `deregister` function
|
5866 | * supplied.
|
5867 | *
|
5868 | * @param path the registration path
|
5869 | * @param deregister a function that may be called to deregister this handler
|
5870 | */
|
5871 | onRegister(path: string, deregister: () => void): void;
|
5872 | /**
|
5873 | * Called when the handler is closed. The handler will be closed if the
|
5874 | * session is closed, or if the handler is unregistered.
|
5875 | *
|
5876 | * Once closed, no further calls will be made for the handler.
|
5877 | *
|
5878 | * @param path the registration path
|
5879 | */
|
5880 | onClose(path: string): void;
|
5881 | /**
|
5882 | * Notification of a contextual error related to this handler. This is
|
5883 | * analogous to an unchecked exception being raised. Situations in which
|
5884 | * `onError` is called include the session being closed before the
|
5885 | * handler is registered, a communication timeout, or a problem with the
|
5886 | * provided parameters. No further calls will be made to this handler.
|
5887 | *
|
5888 | * @param path the registration path
|
5889 | * @param error the error
|
5890 | */
|
5891 | onError(path: string, error: any): void;
|
5892 | }
|
5893 | /**
|
5894 | * Notification that a session has made a request using a selector that does
|
5895 | * not match any topics.
|
5896 | *
|
5897 | * Processing of the initial request will be halted until
|
5898 | * {@link MissingTopicNotification.proceed proceed} is called, at which point
|
5899 | * the selector will be resolved against the topic tree again.
|
5900 | *
|
5901 | * If after calling `proceed` the selector still does not
|
5902 | * match against any topics, no further notifications will be provided.
|
5903 | *
|
5904 | * Should {@link MissingTopicNotification.cancel cancel} be called, or the
|
5905 | * notification time out, the request will be discarded. The requesting
|
5906 | * session will not be notified that their request has been cancelled.
|
5907 | */
|
5908 | export interface MissingTopicNotification {
|
5909 | /**
|
5910 | * The common root topic path derived from the requested topic selector
|
5911 | */
|
5912 | path: string;
|
5913 | /**
|
5914 | * The topic selector that triggered this notification
|
5915 | */
|
5916 | selector: TopicSelector;
|
5917 | /**
|
5918 | * Session ID of the client session that triggered this notification
|
5919 | */
|
5920 | sessionID: SessionId;
|
5921 | /**
|
5922 | * Instruct the server to complete processing of the session request.
|
5923 | *
|
5924 | * This may be called after additional operations (such as adding
|
5925 | * topics) have been performed, to allow the requested selector to be
|
5926 | * resolved against the updated topic tree.
|
5927 | *
|
5928 | * For subscription requests, the topic selector will be added to the
|
5929 | * client's topic selections. This will cause the client session to
|
5930 | * become subscribed to topics that match the selector if they are added
|
5931 | * later.
|
5932 | */
|
5933 | proceed(): void;
|
5934 | /**
|
5935 | * Cancel the client request on the server.
|
5936 | *
|
5937 | * Calling this will prevent any further processing of the request. For
|
5938 | * subscription requests, the topic selector will be discarded. The
|
5939 | * client session will not become subscribed to topics that match the
|
5940 | * selector if they are added later.
|
5941 | *
|
5942 | * @deprecated since 6.4
|
5943 | * <p>
|
5944 | * This is only useful when using the deprecated {@link
|
5945 | * Topics.fetch} mechanism. It will be removed when that
|
5946 | * mechanism is removed.
|
5947 | */
|
5948 | cancel(): void;
|
5949 | }
|
5950 | /**
|
5951 | * The TopicUpdateHandler interface for exclusive updates. This interface must
|
5952 | * be implemented by the user, to be registered via {@link
|
5953 | * TopicControl.registerUpdateSource}.
|
5954 | *
|
5955 | * A topic update handler has a lifecycle that reflects the registration state
|
5956 | * on the server. This is expressed through the callback methods. Once {@link
|
5957 | * TopicUpdateHandler.onClose onClose} has been called, no further interactions
|
5958 | * will occur.
|
5959 | *
|
5960 | * When an update handler is registered it will be notified via the {@link
|
5961 | * TopicUpdateHandler.onRegister onRegister} callback. Once registered it may be
|
5962 | * in either a `active` state, where it can provide topic updates, or a
|
5963 | * `standby` state, where it is still registered but is not allowed to
|
5964 | * perform updates. The state may be switched in any order, depending on server
|
5965 | * policy.
|
5966 | *
|
5967 | * @class TopicUpdateHandler
|
5968 | *
|
5969 | * @deprecated since 6.2
|
5970 | *
|
5971 | * This class is deprecated. It is only used in conjunction with
|
5972 | * {@link TopicControl.registerUpdateSource}. Use {@link
|
5973 | * TopicUpdate.createUpdateStream} instead. This method will be
|
5974 | * removed in a future release.
|
5975 | */
|
5976 | export interface TopicUpdateHandler {
|
5977 | /**
|
5978 | * Called when the handler has been successfully registered with the server.
|
5979 | *
|
5980 | * A session can register a single handler for a given branch of the topic
|
5981 | * tree. If there is already a handler registered for the topic path the
|
5982 | * operation will fail and {@link TopicUpdateHandler.onClose onClose} will
|
5983 | * be called.
|
5984 | *
|
5985 | * To deregister the handler, call the `deregister` function supplied.
|
5986 | *
|
5987 | * @param path the path that the handler is registered for
|
5988 | * @param deregister a function that may be called to deregister this handler
|
5989 | */
|
5990 | onRegister(path: string, deregister: () => void): void;
|
5991 | /**
|
5992 | * State notification that this handler is now active for the specified
|
5993 | * topic path and is therefore in a valid state to send updates on topic at
|
5994 | * or below the registered topic path
|
5995 | *
|
5996 | * @param path the registration path
|
5997 | * @param updater an updater that can be used to update topics
|
5998 | */ onActive(path: string, updater: Updater): void;
|
5999 | /**
|
6000 | * State notification that this handler is not currently allowed to provide
|
6001 | * topic updates for the specified topic path. This indicates that another
|
6002 | * {@link TopicUpdateHandler} is currently active for the given topic path.
|
6003 | *
|
6004 | * Server policy will dictate when this handler is set as active.
|
6005 | *
|
6006 | * If this handler was previously in a `active` state, any {@link Updater}
|
6007 | * instances for this topic path will no longer be valid for use.
|
6008 | *
|
6009 | * @param path the registration path
|
6010 | */
|
6011 | onStandBy(path: string): void;
|
6012 | /**
|
6013 | * Called when the handler is closed. The handler will be closed if the
|
6014 | * session is closed, or if the handler is unregistered.
|
6015 | *
|
6016 | * Once closed, no further calls will be made for the handler.
|
6017 | *
|
6018 | * @param path the registration path
|
6019 | * @param errorReason an optional value representing the error; this can be
|
6020 | * one of the constants defined in {@link
|
6021 | * ErrorReason}, or a feature-specific reason. It
|
6022 | * is absent if the handler was closed because the
|
6023 | * session closed.
|
6024 | */
|
6025 | onClose(path: string, errorReason?: ErrorReasonType): void;
|
6026 | }
|
6027 | /**
|
6028 | * An updater provides methods to update a topic on the server with a new
|
6029 | * supplied value, like {@link TopicControl.update}, but within the context of
|
6030 | * an exclusive {@link TopicUpdateHandler} registration. If the update is
|
6031 | * successful it will call the result's success callback, and any sessions
|
6032 | * subscribed to the same topic will be notified of a topic update.
|
6033 | *
|
6034 | * An updater may only update topics at or below the registration path of the
|
6035 | * {@link TopicUpdateHandler} from which it was produced.
|
6036 | *
|
6037 | * The result will fail if the update was not successful. It is necessary for
|
6038 | * the topic to exist, and that the value type must be valid for the topic, for
|
6039 | * example a topic added with {@link TopicTypeEnum.INT64} cannot accept a string
|
6040 | * value. Updates will also fail if the {@link TopicUpdateHandler} this updater
|
6041 | * was created from is in a `standby` or `closed` state.
|
6042 | *
|
6043 | * **Example:**
|
6044 | * ```
|
6045 | * updater.update('foo/bar', 123).then(function() {
|
6046 | * // Update successful
|
6047 | * }, function(err) {
|
6048 | * // Update failed
|
6049 | * });
|
6050 | * ```
|
6051 | *
|
6052 | * @deprecated since 6.2
|
6053 | * <p>
|
6054 | * This class is deprecated. It is only used in conjunction with
|
6055 | * {@link TopicControl.registerUpdateSource}. Use {@link
|
6056 | * TopicUpdate.createUpdateStream} instead. This method will be
|
6057 | * removed in a future release.
|
6058 | */
|
6059 | export interface Updater {
|
6060 | /**
|
6061 | * Update a topic
|
6062 | *
|
6063 | * Prefer {@link updateValue} when updating a `Double` or `Int64` topic.
|
6064 | * This method can infer the wrong data type when updating a `Double` topic
|
6065 | * with a value that does not have a fractional component.
|
6066 | *
|
6067 | * @param path the topic to update
|
6068 | * @param value the value to update the topic with
|
6069 | * @return the {@link Result} that completes when the update succeeded
|
6070 | */
|
6071 | update(path: string, value: any): Result<void>;
|
6072 | /**
|
6073 | * Update a topic with a specified data type
|
6074 | *
|
6075 | * @param path the topic to update
|
6076 | * @param value the value to update the topic with
|
6077 | * @param datatype the data type to be used for encoding the value
|
6078 | * @return the {@link Result} that completes when the update suceeded
|
6079 | */
|
6080 | updateValue(path: string, value: any, datatype: DataType<any, any, any>): Result<void>;
|
6081 | }
|
6082 | /**
|
6083 | * A result returned when a request to add a topic completes
|
6084 | */
|
6085 | export interface TopicAddResult {
|
6086 | /**
|
6087 | * Whether the Topic was added or not
|
6088 | */
|
6089 | added: boolean;
|
6090 | /**
|
6091 | * The topic path that was used
|
6092 | */
|
6093 | topic: string;
|
6094 | }
|
6095 | /**
|
6096 | * A result that is returned from a {@link TopicControl.removeWithSession} request
|
6097 | */
|
6098 | export interface RemoveWithSessionResult {
|
6099 | /**
|
6100 | * A function to remove this registered action
|
6101 | *
|
6102 | * @return a result that resolves with the topic path that was removed
|
6103 | */
|
6104 | deregister(): Result<{
|
6105 | topic: string;
|
6106 | }>;
|
6107 | }
|
6108 | /**
|
6109 | * Alias for the TopicUpdateHandler interface to keep compatibility with old TypeScript definitions
|
6110 | */ export declare type UpdateSourceHandler = TopicUpdateHandler;
|
6111 | /**
|
6112 | * @module Session.notifications
|
6113 | */
|
6114 | /**
|
6115 | * The type of topic notification that has been received.
|
6116 | */
|
6117 | export declare enum TopicNotificationType {
|
6118 | /**
|
6119 | * The topic was added.
|
6120 | */
|
6121 | ADDED = 0,
|
6122 | /**
|
6123 | * The topic existed at the time of the selector registration.
|
6124 | */
|
6125 | SELECTED = 1,
|
6126 | /**
|
6127 | * The topic was removed.
|
6128 | */
|
6129 | REMOVED = 2,
|
6130 | /**
|
6131 | * The topic was deselected.
|
6132 | */
|
6133 | DESELECTED = 3,
|
6134 | }
|
6135 | /**
|
6136 | * Topic notifications feature.
|
6137 | *
|
6138 | * Allows a client session to receive notifications about changes to selected topics.
|
6139 | */
|
6140 | export interface TopicNotifications {
|
6141 | /**
|
6142 | * The topic notification type enum
|
6143 | */ TopicNotificationType: typeof TopicNotificationType;
|
6144 | /**
|
6145 | * Register a {@link TopicNotificationListener} to receive topic notifications.
|
6146 | *
|
6147 | * @param listener the listener to receive topic notifications
|
6148 | * @returns a {@link Result} for this operation
|
6149 | */
|
6150 | addListener(listener: TopicNotificationListener): Result<TopicNotificationRegistration>;
|
6151 | }
|
6152 | /**
|
6153 | * Listener for topic notifications.
|
6154 | */
|
6155 | export interface TopicNotificationListener {
|
6156 | /**
|
6157 | * Notification for an immediate descendant of a selected topic path. This
|
6158 | * notifies the presence or absence of a descendant topic that may
|
6159 | * subsequently be explicitly selected.
|
6160 | *
|
6161 | * @param path the path of the selected immediate descendant
|
6162 | * @param type the type of notification
|
6163 | */
|
6164 | onDescendantNotification(path: string, type: TopicNotificationType): void;
|
6165 | /**
|
6166 | * A notification for a selected topic.
|
6167 | *
|
6168 | * @param path the path of the selected topic
|
6169 | * @param specification the specification of the topic that this
|
6170 | * notification is for
|
6171 | * @param type the type of notification
|
6172 | */
|
6173 | onTopicNotification(path: string, specification: TopicSpecification, type: TopicNotificationType): void;
|
6174 | /**
|
6175 | * Called when the listener is closed. The listener will be closed if the
|
6176 | * session is closed, or if the listener is closed by the {@link
|
6177 | * TopicNotificationRegistration}
|
6178 | *
|
6179 | * Once closed, no further calls will be made to the listener.
|
6180 | */
|
6181 | onClose(): void;
|
6182 | /**
|
6183 | * Notification of a contextual error related to this listener. This is
|
6184 | * analogous to an Error being thrown. Situations in which
|
6185 | * `onError` is called include the session being closed before the
|
6186 | * listener is registered, a communication timeout, or a problem with the
|
6187 | * provided parameters. No further calls will be made to this listener.
|
6188 | *
|
6189 | * @param {Object} error - The error
|
6190 | *
|
6191 | * @function TopicNotificationListener#onError
|
6192 | */
|
6193 | onError(error: any): void;
|
6194 | }
|
6195 | /**
|
6196 | * The TopicNotificationRegistration represents the registration state of the
|
6197 | * associated listener on the server.
|
6198 | *
|
6199 | * The TopicNotificationRegistration provides operations to control which topic
|
6200 | * paths the listener will receive notifications for. It can also close the
|
6201 | * listener and remove it from the server.
|
6202 | */
|
6203 | export interface TopicNotificationRegistration {
|
6204 | /**
|
6205 | * Request to receive notifications for all topics matched by the provided
|
6206 | * topic selector.
|
6207 | *
|
6208 | * This function can take any number of arguments. Each argument can be a string
|
6209 | * or a {@link TopicSelector}. Alternatively, an array of strings and
|
6210 | * {@link TopicSelector}s can be passed as a single argument. At least one
|
6211 | * valid selector has to be specified.
|
6212 | *
|
6213 | * @param selector the selector to register
|
6214 | * @returns a {@link Result} for this operation
|
6215 | */
|
6216 | select(selector: Array<string | TopicSelector>): Result<void>;
|
6217 | select(...selector: Array<string | TopicSelector>): Result<void>;
|
6218 | /**
|
6219 | * Request to stop receiving notifications for all topics matched by the
|
6220 | * given selector.
|
6221 | *
|
6222 | * This function can take any number of arguments. Each argument can be a
|
6223 | * string or a {@link TopicSelector}. Alternatively, an array of strings and
|
6224 | * {@link TopicSelector}s can be passed as a single argument. At least one
|
6225 | * valid selector has to be specified.
|
6226 | *
|
6227 | * @param selector the selector to register
|
6228 | * @returns a {@link Result} for this operation
|
6229 | */
|
6230 | deselect(selector: Array<string | TopicSelector>): Result<void>;
|
6231 | deselect(...selector: Array<string | TopicSelector>): Result<void>;
|
6232 | /**
|
6233 | * Request that the listener is unregistered from the server.
|
6234 | * @function TopicNotificationRegistration#close
|
6235 | */
|
6236 | close(err?: any): void;
|
6237 | }
|
6238 | /**
|
6239 | * @module Session.topicUpdate
|
6240 | */
|
6241 | /**
|
6242 | * Options for creating a topic update stream or for setting a value using the
|
6243 | * topicUpdate feature.
|
6244 | */
|
6245 | export interface TopicUpdateOptions {
|
6246 | /**
|
6247 | * an optional constraint that must be satisfied for the topic to be
|
6248 | * updated.
|
6249 | */
|
6250 | constraint?: UpdateConstraint;
|
6251 | /**
|
6252 | * an optional specification of the topic. If this is specified and the
|
6253 | * topic does not exist at the `path` , one will be created using
|
6254 | * `specification` . If a topic does exist, its specification must match
|
6255 | * `specification` , otherwise the operation will fail with an `Error` .
|
6256 | */
|
6257 | specification?: TopicSpecification;
|
6258 | }
|
6259 | /**
|
6260 | * Result of {@link TopicUpdate.applyJsonPatch applyJsonPatch}. Check {@link
|
6261 | * JsonPatchResult.failedOperation failedOperation} to determine whether any of
|
6262 | * the operations failed.
|
6263 | *
|
6264 | * @since 6.4
|
6265 | */
|
6266 | export interface JsonPatchResult {
|
6267 | /**
|
6268 | * If present, this contains the index of the first operation which failed.
|
6269 | */
|
6270 | failedOperation?: number;
|
6271 | }
|
6272 | /**
|
6273 | * <a name="topic-update-feature"></a>
|
6274 | * This feature provides a client session with the ability to update topics.
|
6275 | *
|
6276 | * A session does not have to be subscribed to a topic to update it.
|
6277 | *
|
6278 | * Constraints can be applied to the setting of a value and creation of an
|
6279 | * update stream. Constraints describe a condition that must be satisfied for
|
6280 | * the operation to succeed. The constraints are evaluated on the server. The
|
6281 | * available constraints are: an active session lock, the current value of the
|
6282 | * topic being updated and a part of the current value of the topic being
|
6283 | * updated.
|
6284 | *
|
6285 | * When a topic of type {@link TopicTypeEnum.STRING STRING},
|
6286 | * {@link TopicTypeEnum.INT64 INT64} or
|
6287 | * {@link TopicTypeEnum.DOUBLE DOUBLE} is set to `null`
|
6288 | * or `undefined` , the topic will be updated to have no value. If a
|
6289 | * previous value was present subscribers will receive a notification that the
|
6290 | * new value is `undefined` . New subscribers will not receive a value
|
6291 | * notification. Attempting to set any other type of topic to `null`
|
6292 | * or `undefined` will cause an `Error` to be thrown.
|
6293 | *
|
6294 | * <H3>Access control</H3>
|
6295 | *
|
6296 | * To update any topic a session needs {@link TopicPermission.UPDATE_TOPIC
|
6297 | * update topic} permission covering the topic. To create any topic a session
|
6298 | * needs {@link TopicPermission.MODIFY_TOPIC modify topic} permission covering
|
6299 | * the topic. Requests that combine adding a topic and setting the value will
|
6300 | * require both permissions for either action to happen. An {@link UpdateStream}
|
6301 | * cannot be used to add a topic successfully but fail to set its value because
|
6302 | * the {@link TopicPermission.UPDATE_TOPIC update topic} is missing.
|
6303 | *
|
6304 | * <H3>Accessing the feature</H3>
|
6305 | *
|
6306 | * This feature may be obtained from a {@link Session session} as follows:
|
6307 | *
|
6308 | * ```
|
6309 | * var topicUpdate = session.topicUpdate;
|
6310 | * ```
|
6311 | *
|
6312 | * @since 6.2
|
6313 | */
|
6314 | export interface TopicUpdate {
|
6315 | /**
|
6316 | * Sets the topic to a specified value.
|
6317 | *
|
6318 | * `null` or `undefined` can only be passed to the
|
6319 | * `value` parameter when updating
|
6320 | * {@link TopicTypeEnum.STRING STRING},
|
6321 | * {@link TopicTypeEnum.INT64 INT64} or
|
6322 | * {@link TopicTypeEnum.DOUBLE DOUBLE} topics.
|
6323 | *
|
6324 | * When a topic of type {@link TopicTypeEnum.STRING STRING},
|
6325 | * {@link TopicTypeEnum.INT64 INT64} or
|
6326 | * {@link TopicTypeEnum.DOUBLE DOUBLE} is set
|
6327 | * to `null` or `undefined` , the topic will be updated
|
6328 | * to have no value. If a previous value was present subscribers will
|
6329 | * receive a notification that the new value is `undefined` . New
|
6330 | * subscribers will not receive a value notification.
|
6331 | *
|
6332 | * @param path the path of the topic
|
6333 | * @param dataType the type of the values
|
6334 | * @param value the value. String, int64, and double topics accept
|
6335 | * `null` or `undefined` , as described above.
|
6336 | * Using `null` or `undefined` with other
|
6337 | * topic types is an error and will throw an `Error` .
|
6338 | * @param options optional options object
|
6339 | * @return a Result that resolves when a response is received
|
6340 | * from the server.
|
6341 | * <p>
|
6342 | * If the task fails, the Result will resolve with an
|
6343 | * `Error` .
|
6344 | */
|
6345 | set(path: string, dataType: DataType<any, any, any>, value: any, options?: TopicUpdateOptions): Result<void>;
|
6346 | /**
|
6347 | * Creates an {@link UpdateStream update stream} to
|
6348 | * use for updating a specific topic.
|
6349 | *
|
6350 | * The type of the topic being updated must match the type derived from the
|
6351 | * `dataType` parameter.
|
6352 | *
|
6353 | * Update streams send a sequence of updates for a specific topic. They can
|
6354 | * result in more efficient use of the network as only the differences
|
6355 | * between the current value and the updated value are transmitted. They do
|
6356 | * not provide exclusive access to the topic. If exclusive access is
|
6357 | * required update streams should be used with {@link SessionLock session
|
6358 | * locks} as constraints.
|
6359 | *
|
6360 | * Streams are validated lazily when the first
|
6361 | * {@link UpdateStream.set set} or
|
6362 | * {@link UpdateStream.validate validate} operation is
|
6363 | * completed. Once validated a stream can be invalidated, after which it
|
6364 | * rejects future updates.
|
6365 | *
|
6366 | * @param path the path of the topic
|
6367 | * @param dataType the type of the values expected by the update stream
|
6368 | * @param options optional options object
|
6369 | * @return an update stream
|
6370 | */
|
6371 | createUpdateStream(path: string, dataType: DataType<any, any, any>, options?: TopicUpdateOptions): UpdateStream;
|
6372 | /**
|
6373 | * Applies a JSON Patch to a JSON topic.
|
6374 | *
|
6375 | * The `patch` argument should be formatted according to the JSON
|
6376 | * Patch standard (RFC 6902).
|
6377 | *
|
6378 | * Patches are a sequence of JSON Patch operations contained in an array.
|
6379 | * The following patch will insert a number at a specific key and then test
|
6380 | * that it was added:
|
6381 | *
|
6382 | * ```
|
6383 | * [{"op":"add", "path":"/price", "value" : 41},
|
6384 | * {"op":"test", "path":"/price", "value": 41}]
|
6385 | * ```
|
6386 | *
|
6387 | * The available operations are:
|
6388 | *
|
6389 | * * Add: `{ "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] }`
|
6390 | * * Remove: `{ "op": "remove", "path": "/a/b/c" }`
|
6391 | * * Replace: `{ "op": "replace", "path": "/a/b/c", "value": 43 }`
|
6392 | * * Move: `{ "op": "move", "from": "/a/b/c", "path": "/a/b/d" }`
|
6393 | * * Copy: `{ "op": "copy", "from": "/a/b/c", "path": "/a/b/e" }`
|
6394 | * * Test: `{ "op": "test", "path": "/a/b/c", "value": "foo" }`
|
6395 | *
|
6396 | * The test operation checks that the CBOR representation of the value of a
|
6397 | * topic is identical to value provided in the patch after converting it to
|
6398 | * CBOR. If the value is represented differently as CBOR, commonly due to
|
6399 | * different key ordering, then the patch will fail with an error. E.g the
|
6400 | * values `{"foo": "bar", "count": 43}` and `{"count": 43, "foo": "bar"}`
|
6401 | * are unequal despite semantic equality due to the differences in a byte
|
6402 | * for byte comparison.
|
6403 | *
|
6404 | * @param path the path of the topic to patch
|
6405 | * @param patch the JSON Patch
|
6406 | * @param constraint optional constraint that must be satisfied for the patch to
|
6407 | * be applied
|
6408 | * @return a {@link Result} that resolves when a response is received from
|
6409 | * the server.
|
6410 | * <p>
|
6411 | * If the task fails, the Result will reject with an error. Common reasons
|
6412 | * for failure include:
|
6413 | * <p>
|
6414 | * <ul>
|
6415 | * <li> the patch is not a valid JSON Patch;
|
6416 | * <li> applying the patch fails;
|
6417 | * <li> there is no topic bound to {@code path};
|
6418 | * <li> the patch cannot be applied to the topic, for example if the
|
6419 | * topic type is not {@link DataTypes.JSON}.
|
6420 | * <li> updates cannot be applied to the topic because an exclusive
|
6421 | * update source is registered for its path;
|
6422 | * <li> the topic is managed by a component (such as fan-out) that
|
6423 | * prohibits updates from the caller;
|
6424 | * <li> the cluster was repartitioning;
|
6425 | * <li> the calling session does not have the {@link
|
6426 | * TopicPermission.UPDATE_TOPIC UPDATE_TOPIC} permission for `path`;
|
6427 | * <li> the session is closed.
|
6428 | * </ul>
|
6429 | *
|
6430 | * @see <a href="https://tools.ietf.org/html/rfc6902">
|
6431 | * JavaScript Object Notation (JSON) Patch</a>
|
6432 | *
|
6433 | * @since 6.4
|
6434 | */
|
6435 | applyJsonPatch(path: string, patch: string | Array<{
|
6436 | [key: string]: any;
|
6437 | }>, constraint?: UpdateConstraint): Result<JsonPatchResult>;
|
6438 | }
|
6439 | /**
|
6440 | * @module Session.topicViews
|
6441 | */
|
6442 | /**
|
6443 | * Description of a topic view that has been created.
|
6444 | *
|
6445 | * @since 6.3
|
6446 | */
|
6447 | export interface TopicView {
|
6448 | /**
|
6449 | * The name of the topic view.
|
6450 | */
|
6451 | readonly name: string;
|
6452 | /**
|
6453 | * The specification of the topic view.
|
6454 | *
|
6455 | * See the <a href="./topicviews.html#view-specification">view
|
6456 | * specification</a> for the description of the DSL</a> for more
|
6457 | * information.
|
6458 | */
|
6459 | readonly specification: string;
|
6460 | /**
|
6461 | * The roles used by the view when evaluating permissions.
|
6462 | */
|
6463 | readonly roles: Set<string>;
|
6464 | }
|
6465 | /**
|
6466 | * <h3>Topic view feature.</h3>
|
6467 | *
|
6468 | * This feature provides a client session with the ability to manage topic
|
6469 | * views.
|
6470 | *
|
6471 | * A topic view maps one part of the server's topic tree to another. It
|
6472 | * dynamically creates a set of <em>reference topics</em> from a set of
|
6473 | * <em>source topics</em>, based on a declarative <em>topic view
|
6474 | * specification</em>. The capabilities of topic views range from simple
|
6475 | * mirroring of topics within the topic tree to advanced capabilities that
|
6476 | * include publication of partial values, expanding a single topic value into
|
6477 | * many topics and throttling the rate of publication.
|
6478 | *
|
6479 | * Each reference topic has a single source topic and has the same topic type as
|
6480 | * its source topic. Reference topics are read-only (they cannot be updated),
|
6481 | * nor can they be created or removed directly. Otherwise, they behave just like
|
6482 | * standard topics. A client session can subscribe to a reference topic, and can
|
6483 | * fetch the reference topic's current value if it has one.
|
6484 | *
|
6485 | * The source topics of a topic view are defined by a topic selector. One or
|
6486 | * more reference topics are created for each source topic, according to the
|
6487 | * topic view. If a source topic is removed, reference topics that are derived
|
6488 | * from it will automatically be removed. If a topic is added that matches the
|
6489 | * source topic selector of a topic view, corresponding reference topics will be
|
6490 | * created. Removing a topic view will remove all of its reference topics.
|
6491 | *
|
6492 | * <h3>Topic view specifications</h3>
|
6493 | *
|
6494 | * The following is a simple topic view specification that mirrors all topics
|
6495 | * below the path <code>a</code> to reference topics below the path
|
6496 | * <code>b</code>.
|
6497 | *
|
6498 | * <pre>
|
6499 | * map ?a// to b/<path(1)>
|
6500 | * </pre>
|
6501 | *
|
6502 | * A topic view with this specification will map a source topic at the path
|
6503 | * <code>a/x/y/z</code> to a reference topic at the path <code>b/x/y/z</code>.
|
6504 | * The specification is simple, so the reference topic will exactly mirror the
|
6505 | * source topic.
|
6506 | *
|
6507 | * A general topic view specification comprises several parts:
|
6508 | *
|
6509 | * <ul>
|
6510 | * <li>The <em>source topic</em> clause identifies the source topics.
|
6511 | * <li>The <em>path mapping</em> clause determines how reference topic paths are
|
6512 | * derived from the source topic paths, and when expanding to more than one
|
6513 | * reference topic, from where the values are obtained.
|
6514 | * <li>The optional <em>topic property mapping</em> clause determines how
|
6515 | * reference topic properties are derived from source topic properties.
|
6516 | * <li>The optional <em>value mapping</em> clause determines how reference topic
|
6517 | * values are derived from source topic or expanded values.
|
6518 | * <li>The optional <em>throttle</em> clause constrains the rate at which each
|
6519 | * reference topic is updated when its source topic is updated.
|
6520 | * </ul>
|
6521 | *
|
6522 | * <h4>Source topic clause</h4>
|
6523 | * The source topic clause begins with the <code>map</code> keyword and is followed
|
6524 | * by a topic selector. These topic selectors follow the same
|
6525 | * {@link TopicSelectors.parse parsing rules} as other topic selectors.
|
6526 | * When evaluating a topic view, topics in the topic tree that match the source
|
6527 | * topic selector are considered, with the following exceptions:
|
6528 | * <ul>
|
6529 | * <li>Topics created through the Publisher API;
|
6530 | * <li>{@link ROUTING ROUTING} topics.
|
6531 | * </ul>
|
6532 | *
|
6533 | * Both {@link SLAVE SLAVE} and reference topics are valid source
|
6534 | * topics. In particular, chaining of topic views is supported; that is, a
|
6535 | * reference topic created by one topic view can be the source topic of another
|
6536 | * topic view. Additionally, a reference topic can be the master topic of a
|
6537 | * slave topic, or the source topic of a routing topic subscription.
|
6538 | *
|
6539 | * <blockquote><em>Prefer topic views to slave topics which are now
|
6540 | * deprecated</em>. Individual topics can be mirrored by creating a slave topic,
|
6541 | * but maintaining slave topics for a branch of the topic tree quickly becomes
|
6542 | * tedious. A topic view will maintain such a branch automatically, and provides
|
6543 | * more sophisticated mapping options. </blockquote>
|
6544 | *
|
6545 | * <h4>Path mapping clause</h4>
|
6546 | * The paths of reference topics are derived from the source topic according to
|
6547 | * the topic view path mapping. The path mapping allows the source topic path
|
6548 | * and the value of the source topic to determine the path of the reference
|
6549 | * topic. In addition the path mapping can include <em>expand</em> directives
|
6550 | * which allow objects and arrays in JSON source topic values to be expanded to
|
6551 | * produce many reference topics.
|
6552 | *
|
6553 | * A path mapping clause begins with the <code>to</code> keyword and is followed by a
|
6554 | * path mapping template. A path mapping template is a topic path with embedded
|
6555 | * <em>directives</em>. Directives are evaluated when creating the topic
|
6556 | * reference and substituted into the topic path. Directives are delimited by
|
6557 | * angle brackets (<code><</code>,<code>></code>) and consist of the name of the
|
6558 | * directive and a list of parameters. The parameter list is comma-separated and
|
6559 | * surrounded by parentheses (<code>(</code>, <code>)</code>).
|
6560 | *
|
6561 | * The following path mapping directives are supported:
|
6562 | *
|
6563 | * <dl>
|
6564 | * <dt>Source path directives</dt>
|
6565 | * <dd>Source path directives extract a portion of the source path and are
|
6566 | * parameterized by the index of the start part of the source path and the
|
6567 | * number of parts to include. The number of parts parameter is optional – if it
|
6568 | * is missing, the selection extends to the end of the source path. The syntax
|
6569 | * is <code><path(<em>start</em>, <em>number</em>)></code>, or
|
6570 | * <code><path(<em>start</em>)></code> when the number of parts parameter
|
6571 | * is omitted.
|
6572 | *
|
6573 | * For example, given the source path <code>a/b/c/d</code>, the source path directive
|
6574 | * <code><path(1, 2)></code> is mapped to the reference topic path <code>b/c</code>, and
|
6575 | * the source path directive <code><path(2)></code> is mapped to the reference topic
|
6576 | * path <code>c/d</code>.</dd>
|
6577 | *
|
6578 | * <dt>Source value ("scalar") directives</dt>
|
6579 | * <dd>Source value directives are only applied to {@link JSON} source
|
6580 | * topics; if the path mapping contains a source value directive, non-JSON
|
6581 | * topics matching the source topic selector are ignored. Source value
|
6582 | * directives use the keyword <code>scalar</code> and are parameterized by a
|
6583 | * single <a href="https://tools.ietf.org/html/rfc6901"> JSON pointer</a> that
|
6584 | * extracts a scalar value from the source (or expanded) value. A scalar value
|
6585 | * is a string, a number, <code>true</code>, <code>false</code>, or
|
6586 | * <code>null</code>, that is, anything other than an array or a object. If the
|
6587 | * JSON pointer does not refer to a scalar value in the source (or expanded)
|
6588 | * value, no reference topic will be created. This includes cases where the JSON
|
6589 | * pointer refers to an array or an object), or when no part of the source value
|
6590 | * is selected.
|
6591 | *
|
6592 | * Deriving the reference topic paths from part of the source topic value
|
6593 | * effectively creates a secondary index on the value. For source value
|
6594 | * directives to work efficiently, the selected scalar values should be
|
6595 | * relatively stable. If an update to the source topic changes the selected
|
6596 | * scalar value, the corresponding reference topic will be removed and a new
|
6597 | * reference topic will be created.
|
6598 | *
|
6599 | * For example, given a source value of
|
6600 | *
|
6601 | * <pre>
|
6602 | * {
|
6603 | * "account" : "1234",
|
6604 | * "balance" : { "amount" : 12.57, "currency" : "USD" }
|
6605 | * }
|
6606 | * </pre>
|
6607 | *
|
6608 | * and the source value directive
|
6609 | * <code>currency/<scalar(/balance/currency)>/account/<scalar(/account)></code>, the
|
6610 | * reference topic path will be <code>currency/USD/account/1234</code>.
|
6611 | *
|
6612 | * If the extracted value is a string, it is copied literally to the reference
|
6613 | * topic path. A value that contains path separators (<code>/</code>) will create a
|
6614 | * reference topic path with more levels than the path mapping template.
|
6615 | *
|
6616 | * An extracted value of <code>null</code> will be copied to the reference topic path
|
6617 | * as the string <code>"null"</code>.</dd>
|
6618 | *
|
6619 | * <dt>Expand value directives</dt>
|
6620 | *
|
6621 | * <dd>Expand value directives are only applied to {@link JSON}
|
6622 | * source topics; if the path mapping contains an expand value directive,
|
6623 | * non-JSON topics matching the source topic selector are ignored.
|
6624 | * <p>
|
6625 | * Expand value directives use the keyword <code>expand</code> and are
|
6626 | * parameterized by one or two <a href="https://tools.ietf.org/html/rfc6901">
|
6627 | * JSON pointers</a>.
|
6628 | * <p>
|
6629 | * The first pointer indicates the element within the value to be expanded, and
|
6630 | * if omitted, the value is expanded from the root. Expansion of a source topic
|
6631 | * indicates that every direct child of the element pointed to by the expand
|
6632 | * pointer will be used to create a new reference topic (or provide input to
|
6633 | * later expand or scalar directives). For example <code><expand()></code> would
|
6634 | * expand every child item in the source value and <code><expand(/account)></code>
|
6635 | * would expand every child of the <code>account</code> value in the source value.
|
6636 | * The specified value could be an object, an array or even a scalar value, but
|
6637 | * a scalar value would expand to only a single new value.
|
6638 | * <p>
|
6639 | * The optional second parameter of the expand directive specifies a pointer to
|
6640 | * a scalar value within the expanded value which will be used to derive the
|
6641 | * path fragment of the reference topic path. If the second pointer is not
|
6642 | * specified or no scalar value is found for the pointer, the path fragment is
|
6643 | * taken from the key (if the child value is an object) or the index (if the
|
6644 | * child value is an array). Scalar child values will expand to a reference
|
6645 | * topic but will not add anything to the generated path. For example
|
6646 | * <code><expand(,/name)></code> would expand from the root of the source
|
6647 | * value and each child value path fragment would be obtained from the scalar
|
6648 | * value with the key <code>name</code>.
|
6649 | * <p>
|
6650 | * So if a source topic had a value of
|
6651 | *
|
6652 | * <pre>
|
6653 | * {
|
6654 | * "values": [1, 5, 7]
|
6655 | * }
|
6656 | * </pre>
|
6657 | *
|
6658 | * a path mapping of<br>
|
6659 | * <code>value<expand(/values)></code> would expand the value to the
|
6660 | * following reference topics:-
|
6661 | * <p>
|
6662 | * path <code>value0</code> with a value of <code>1</code><br>
|
6663 | * path <code>value1</code> with a value of <code>5</code><br>
|
6664 | * path <code>value2</code> with a value of <code>7</code><br>
|
6665 | * <p>
|
6666 | * Expand directives can be nested (i.e. there can be more than one expand
|
6667 | * directive in a path mapping). In this case a second expand directive will use
|
6668 | * the value from the previous expand as its source (root) value and not the
|
6669 | * value of the source topic. This also applies to scalar directives that
|
6670 | * follow an expand directive.
|
6671 | * <p>
|
6672 | * If expansion causes more than one mapping to the same topic path, only the
|
6673 | * first encountered will be created and updated.
|
6674 | * <p>
|
6675 | * Expanding source topic values effectively creates secondary indices on the
|
6676 | * value. For expanded value directives to work efficiently, the value selected
|
6677 | * for expansion should be relatively stable in terms of the children it
|
6678 | * contains. If an update to the source topic changes the children of the
|
6679 | * expanded value, then corresponding reference topics will be removed and
|
6680 | * created. Updates should generally be limited to changing values within the
|
6681 | * expanded values.</dd>
|
6682 | * </dl>
|
6683 | *
|
6684 | * <h4>Topic property mapping clause</h4>
|
6685 | * The {@link TopicSpecification topic specification} of a reference topic is
|
6686 | * derived from the topic specification of the source topics. A reference topic
|
6687 | * has the same topic type as its source topic.
|
6688 | *
|
6689 | * The topic properties of a reference topic are derived from the source topic.
|
6690 | * Some topic properties can be tuned using the optional topic property mapping
|
6691 | * clause. The following table describes the behavior for each topic property.
|
6692 | *
|
6693 | * <br>
|
6694 | *
|
6695 | * <table>
|
6696 | * <tr>
|
6697 | * <th style= "text-align:left;">Source topic property</th>
|
6698 | * <th>Reference topic specification default</th>
|
6699 | * <th>Can be set by topic property mapping?</th>
|
6700 | * <th>Notes</th>
|
6701 | * </tr>
|
6702 | * <tr>
|
6703 | * <th style="text-align:left;">
|
6704 | * {@link TopicSpecification.COMPRESSION COMPRESSION}</th>
|
6705 | * <td>Copied from source topic specification</td>
|
6706 | * <td>Yes</td>
|
6707 | * <td></td>
|
6708 | * </tr>
|
6709 | * <tr>
|
6710 | * <th style=
|
6711 | * "text-align:left;">{@link TopicSpecification.CONFLATION CONFLATION}</th>
|
6712 | * <td>Copied from source topic specification</td>
|
6713 | * <td>Yes</td>
|
6714 | * <td></td>
|
6715 | * </tr>
|
6716 | * <tr>
|
6717 | * <th style=
|
6718 | * "text-align:left;">{@link TopicSpecification.DONT_RETAIN_VALUE
|
6719 | * DONT_RETAIN_VALUE}</th>
|
6720 | * <td>Copied from source topic specification</td>
|
6721 | * <td>Yes</td>
|
6722 | * <td></td>
|
6723 | * </tr>
|
6724 | * <tr>
|
6725 | * <th style=
|
6726 | * "text-align:left;">{@link TopicSpecification.OWNER OWNER}</th>
|
6727 | * <td>Not set</td>
|
6728 | * <td>No</td>
|
6729 | * <td></td>
|
6730 | * </tr>
|
6731 | * <tr>
|
6732 | * <th style=
|
6733 | * "text-align:left;">{@link TopicSpecification.PERSISTENT PERSISTENT}</th>
|
6734 | * <td>Not set</td>
|
6735 | * <td>No</td>
|
6736 | * <td>Reference topics are not persisted. Topic views are persisted, so a
|
6737 | * reference topic will be recreated on server restart if its source is
|
6738 | * persistent.</td>
|
6739 | * </tr>
|
6740 | * <tr>
|
6741 | * <th style="text-align:left;">
|
6742 | * {@link TopicSpecification.PRIORITY PRIORITY}</th>
|
6743 | * <td>Copied from source topic specification</td>
|
6744 | * <td>Yes</td>
|
6745 | * <td></td>
|
6746 | * </tr>
|
6747 | * <tr>
|
6748 | * <th style=
|
6749 | * "text-align:left;">{@link TopicSpecification.PUBLISH_VALUES_ONLY PUBLISH_VALUES_ONLY}</th>
|
6750 | * <td>Copied from source topic specification</td>
|
6751 | * <td>Yes</td>
|
6752 | * <td></td>
|
6753 | * </tr>
|
6754 | * <tr>
|
6755 | * <th style=
|
6756 | * "text-align:left;">{@link TopicSpecification.REMOVAL REMOVAL}</th>
|
6757 | * <td>Not set</td>
|
6758 | * <td>No</td>
|
6759 | * <td>Reference topics cannot be removed directly.</td>
|
6760 | * </tr>
|
6761 | * <tr>
|
6762 | * <th style=
|
6763 | * "text-align:left;">{@link TopicSpecification.SCHEMA SCHEMA}
|
6764 | * </th>
|
6765 | * <td>Copied from source topic specification</td>
|
6766 | * <td>No</td>
|
6767 | * <td>A {@link RECORD_V2 RECORD_V2} reference topic has the same
|
6768 | * schema as its source topic.</td>
|
6769 | * </tr>
|
6770 | * <tr>
|
6771 | * <th style=
|
6772 | * "text-align:left;">{@link TopicSpecification.SLAVE_MASTER_TOPIC SLAVE_MASTER_TOPIC}</th>
|
6773 | * <td>Not set</td>
|
6774 | * <td>No</td>
|
6775 | * <td>If a reference topic has a slave topic as its source topic, it indirectly
|
6776 | * references the slave's master topic.</td>
|
6777 | * </tr>
|
6778 | * <tr>
|
6779 | * <th style=
|
6780 | * "text-align:left;">{@link TopicSpecification.TIDY_ON_UNSUBSCRIBE TIDY_ON_UNSUBSCRIBE}</th>
|
6781 | * <td>Copied from source topic specification</td>
|
6782 | * <td>Yes</td>
|
6783 | * <td></td>
|
6784 | * </tr>
|
6785 | * <tr>
|
6786 | * <th style="text-align:left;">
|
6787 | * {@link TopicSpecification.TIME_SERIES_EVENT_VALUE_TYPE TIME_SERIES_EVENT_VALUE_TYPE}</th>
|
6788 | * <td>Copied from source topic specification</td>
|
6789 | * <td>No</td>
|
6790 | * <td>A {@link TIME_SERIES TIME_SERIES} reference topic has the same
|
6791 | * value type as its source topic.</td>
|
6792 | * </tr>
|
6793 | * <tr>
|
6794 | * <th style="text-align:left;">
|
6795 | * {@link TopicSpecification.TIME_SERIES_RETAINED_RANGE TIME_SERIES_RETAINED_RANGE}</th>
|
6796 | * <td>Copied from source topic specification</td>
|
6797 | * <td>Yes, with restrictions</td>
|
6798 | * <td>A topic property mapping cannot increase the time series retained range
|
6799 | * by overriding the <code>TIME_SERIES_RETAINED_RANGE</code> property. The retained
|
6800 | * range of a reference time series topic will be constrained to be no greater
|
6801 | * than that of its source topic.</td>
|
6802 | * </tr>
|
6803 | * <tr>
|
6804 | * <th style="text-align:left;">
|
6805 | * {@link TopicSpecification.TIME_SERIES_SUBSCRIPTION_RANGE TIME_SERIES_SUBSCRIPTION_RANGE}</th>
|
6806 | * <td>Copied from source topic specification</td>
|
6807 | * <td>Yes</td>
|
6808 | * <td></td>
|
6809 | * </tr>
|
6810 | * <tr>
|
6811 | * <th style=
|
6812 | * "text-align:left;">
|
6813 | * {@link TopicSpecification.VALIDATE_VALUES VALIDATE_VALUES}</th>
|
6814 | * <td>Not set</td>
|
6815 | * <td>No</td>
|
6816 | * <td>A reference topic reflects updates to its source topic. It cannot reject
|
6817 | * updates.</td>
|
6818 | * </tr>
|
6819 | * </table>
|
6820 | *
|
6821 | * A topic property mapping clause begins with the keywords
|
6822 | * <code>with properties</code> and consists of a comma-separated list of topic
|
6823 | * property keys and values, each separated by a colon. For example, the
|
6824 | * following topic view specification maps all topics below the path
|
6825 | * <code>a</code> to reference topics below the path <code>b</code>, and
|
6826 | * disables both conflation and compression for the reference topics.
|
6827 | *
|
6828 | * <pre>
|
6829 | * map ?a// to b/<path(1)> with properties 'CONFLATION':'off', 'COMPRESSION':'false'
|
6830 | * </pre>
|
6831 | *
|
6832 | * <br>
|
6833 | *
|
6834 | * <h4>Topic value mapping</h4>
|
6835 | *
|
6836 | * By default, a reference topic's value is a copy of the source topic
|
6837 | * value, or part of the source value produced by an expand path
|
6838 | * mapping directive. For <code>JSON</code> source topics, the
|
6839 | * optional topic value mapping clause can be applied to extract part
|
6840 | * of the source value, or to further refine the value produced by the
|
6841 | * expand directive.
|
6842 | *
|
6843 | * A topic value mapping begins the keyword <code>as</code> and is
|
6844 | * followed by a value directive. A value directive is delimited by
|
6845 | * angle brackets (<code><</code>, <code>></code>), and consists
|
6846 | * of the <code>value</code> keywords and a single JSON pointer
|
6847 | * parameter. The JSON pointer selects the part of the source value to
|
6848 | * copy.
|
6849 | *
|
6850 | * For example, given a source value of
|
6851 | *
|
6852 | * <pre>
|
6853 | * {
|
6854 | * "account" : "1234",
|
6855 | * "balance" : { "amount" : 12.57, "currency" : "USD" }
|
6856 | * }
|
6857 | * </pre>
|
6858 | *
|
6859 | * and the value mapping clause <code>as <value(/balance)></code>, the
|
6860 | * reference topic value will be
|
6861 | *
|
6862 | * <pre>
|
6863 | * {
|
6864 | * "amount" : 12.57,
|
6865 | * "currency" : "USD"
|
6866 | * }
|
6867 | * </pre>
|
6868 | *
|
6869 | * Value mappings that follow expand directives apply to the expanded
|
6870 | * value and not the source topic value.
|
6871 | *
|
6872 | * Topic value mappings only alter the reference topic value; only the
|
6873 | * path mapping determines whether a reference topic should exist. If
|
6874 | * the topic value mapping's JSON pointer fails to select anything
|
6875 | * from the source topic value, the reference topic will have the JSON
|
6876 | * value <code>null</code>.
|
6877 | *
|
6878 | * Topic value mappings are often used with path value mappings to
|
6879 | * avoid repeating information in the path and the value. For example:
|
6880 | *
|
6881 | * <pre>
|
6882 | * map ?accounts// to balances/<scalar(/account)> as <value(/balance)>
|
6883 | * </pre>
|
6884 | *
|
6885 | * <br>
|
6886 | *
|
6887 | * <h4>Throttle clause</h4>
|
6888 | * The optional throttle clause can be used to constrain the rate at which a
|
6889 | * reference topic is updated when its source topic is updated. The primary
|
6890 | * application of a throttle clause is to restrict the number of updates sent to
|
6891 | * reference topic subscribers, reducing network utilization or the processing
|
6892 | * each subscriber must do. Throttling also restricts the rate at which client
|
6893 | * sessions can observe changes to reference topic values using the fetch API.
|
6894 | *
|
6895 | * The throttle clause has the form
|
6896 | * <code>throttle to <em>X</em> updates every <em>period</em></code>, where
|
6897 | * <em>X</em> is a positive integer, and <em>period</em> is a positive integer
|
6898 | * followed by a time unit which is one of <code>seconds</code>,
|
6899 | * <code>minutes</code>, or <code>hours</code>.
|
6900 | *
|
6901 | * For example, the following topic view specification maps all topics below the
|
6902 | * path <code>a</code> to reference topics below the path <code>b</code>, but
|
6903 | * updates the value of each reference topic at most twice every five seconds:
|
6904 | *
|
6905 | * <pre>
|
6906 | * map ?a// to b/<path(1)> throttle to 2 updates every 5 seconds
|
6907 | * </pre>
|
6908 | *
|
6909 | * To improve readability, the throttling clause allows <code>1 update</code> as
|
6910 | * an alternative to <code>1 updates</code>, and <code>every second</code> as an
|
6911 | * alternative to <code>every 1 seconds</code> (and so on, for other time
|
6912 | * units). For example, the following topic view specification maps all topics
|
6913 | * below the path <code>a</code> to reference topics below the path
|
6914 | * <code>b</code>, but updates the value of each reference topic at most once
|
6915 | * every hour:
|
6916 | *
|
6917 | * <pre>
|
6918 | * map ?a// to b/<path(1)> throttle to 1 update every minute
|
6919 | * </pre>
|
6920 | *
|
6921 | * The throttle clause is only applied when a source topic is updated more
|
6922 | * frequently than the configured rate. If a source topic is updated less
|
6923 | * frequently, updates are passed on unconstrained. If the rate is exceeded, a
|
6924 | * reference topic will not be updated again until the configured period has
|
6925 | * expired. At this time, the reference topic will be updated based on the
|
6926 | * source topic updates that happened in the interim, and a single value will be
|
6927 | * published. Thus, a throttle clause provides <em>topic-scoped conflation</em>.
|
6928 | *
|
6929 | * The throttle clause is ignored for time series topics because time series
|
6930 | * updates do not support efficient conflation. Updates to source time series
|
6931 | * topics are passed on immediately to the corresponding reference topics,
|
6932 | * regardless of any throttle clause.
|
6933 | *
|
6934 | * <h4>Escaping and quoting special characters</h4>
|
6935 | * Each part of a topic view expression has characters with special
|
6936 | * significance. Source topic clauses and path mapping clauses are delimited by
|
6937 | * white space. Directives in path and topic property mapping clauses are
|
6938 | * delimited by the <code><</code> and <code>></code> characters, and each directive
|
6939 | * parameter is terminated by <code>,</code> or <code>)</code>. Topic property mapping
|
6940 | * clauses are delimited by white space, and the <code>:</code> and <code>,</code>
|
6941 | * characters.
|
6942 | *
|
6943 | * Sometimes a topic view must refer to or generate topics with paths that
|
6944 | * containing special characters, or use a JSON pointer containing special
|
6945 | * characters. The escape sequence <code>\x</code> can be used to literally insert
|
6946 | * any character <code>x</code>, with a one exception: <code>\/</code> cannot be used in
|
6947 | * path fragments since the path delimiter <code>/</code> is always significant.
|
6948 | *
|
6949 | * Here is an example topic view expression containing escape sequences. It maps
|
6950 | * the topic path <code>a topic</code> a reference topic with the path
|
6951 | * <code>another topic</code>.
|
6952 | *
|
6953 | * <pre>
|
6954 | * map a\ topic to another\ topic
|
6955 | * </pre>
|
6956 | *
|
6957 | * Here is an example with a source value directive that uses the JSON pointer
|
6958 | * <code>/x()/y</code> to extract the target path from the source value. The
|
6959 | * <code>)</code> character in the JSON pointer must be escaped so it is not treated
|
6960 | * as the end of the parameter list.
|
6961 | *
|
6962 | * <pre>
|
6963 | * map ?a// to <scalar(/x(\)/y)>
|
6964 | * </pre>
|
6965 | *
|
6966 | * To insert <code>\</code>, the escape sequence <c>\\</c> must be used.
|
6967 | *
|
6968 | * There is no need to escape white space in JSON pointers directive parameters.
|
6969 | * However, white space is significant. For example, the following expressions
|
6970 | * have different topic value mapping clauses since the JSON pointer in the
|
6971 | * second expression is <code>/x </code>; that is, it has a trailing space:
|
6972 | *
|
6973 | * <pre>
|
6974 | * map a to b as <value(/x)>
|
6975 | * map a to b as <value(/x )>
|
6976 | * </pre>
|
6977 | *
|
6978 | * Instead of using escape sequences, white space characters can be included in
|
6979 | * source topic clauses and path mapping clauses using quotes. A clause is
|
6980 | * quoted by wrapping it in single quote (<code>'</code>) or double quote (<code>"</code>)
|
6981 | * characters. For example:
|
6982 | *
|
6983 | * <pre>
|
6984 | * map "a topic" to "another topic"
|
6985 | * </pre>
|
6986 | *
|
6987 | * Within a quoted clause, quotes of the same type must be escaped:
|
6988 | *
|
6989 | * <pre>
|
6990 | * map 'alice\'s topic' to 'bob\'s topic'
|
6991 | * </pre>
|
6992 | *
|
6993 | * For consistency, the values in topic property mapping clauses can be escaped
|
6994 | * or quoted. However, there is no need to do so because none of the valid
|
6995 | * values for the mappable properties contain special characters.
|
6996 | *
|
6997 | * <h3>Dealing with topic path conflicts</h3>
|
6998 | *
|
6999 | * Reference topics have a lower priority than normal topics created through the
|
7000 | * API, including replicas of normal topics created by topic replication or
|
7001 | * fan-out. A reference topic will only be created if no topic or reference
|
7002 | * topic is already bound to its derived topic path.
|
7003 | *
|
7004 | * Topic views have a precedence based on order of creation. If two topic views
|
7005 | * define mappings the same topic path, the earliest-created topic view will
|
7006 | * create a reference topic. If a topic view is updated, it retains its original
|
7007 | * precedence.
|
7008 | *
|
7009 | * <h3>Topic view persistence and replication</h3>
|
7010 | *
|
7011 | * Reference topics are neither replicated nor persisted. They are created and
|
7012 | * removed based on their source topics. However, topic views are replicated and
|
7013 | * persisted. A server that restarts will restore topic views during recovery.
|
7014 | * Each topic view will then create reference topics based on the source topics
|
7015 | * that have been recovered.
|
7016 | *
|
7017 | * The server records all changes to topic views in a persistent store. Topic
|
7018 | * views are restored if the server is started.
|
7019 | *
|
7020 | * If a server belongs to a cluster, topic views will be replicated to each
|
7021 | * server in the cluster. Topic views are evaluated locally within a server.
|
7022 | * Replicated topic views that select non-replicated source topics can create
|
7023 | * different reference topics on each server in the cluster.
|
7024 | *
|
7025 | * <h3>Access control</h3>
|
7026 | *
|
7027 | * <p>
|
7028 | * The following access control restrictions are applied:
|
7029 | *
|
7030 | * <ul>
|
7031 | * <li>To {@link listTopicViews list the topic views}, a session needs the
|
7032 | * {@link GlobalPermission.READ_TOPIC_VIEWS READ_TOPIC_VIEWS} global permission.
|
7033 | *
|
7034 | * <li>To {@link createTopicView create, replace}, or
|
7035 | * {@link removeTopicView remove} a topic view, a session needs the
|
7036 | * {@link GlobalPermission.MODIFY_TOPIC_VIEWS MODIFY_TOPIC_VIEWS} global
|
7037 | * permission and {@link TopicPermission.SELECT_TOPIC SELECT_TOPIC} permission
|
7038 | * for the path prefix of the source topic selector.
|
7039 | *
|
7040 | * <li>Each topic view records the principal and security roles of the session
|
7041 | * that created it as the <em>topic view security context</em>. When a topic
|
7042 | * view is evaluated, this security context is used to constrain the creation of
|
7043 | * reference topics. A reference topic will only be created if the security
|
7044 | * context has {@link TopicPermission.READ_TOPIC READ_TOPIC} permission for the
|
7045 | * source topic path, and {@link TopicPermission.MODIFY_TOPIC MODIFY_TOPIC}
|
7046 | * permission for the reference topic path. The topic view security context is
|
7047 | * copied from the creating session at the time the topic view is created or
|
7048 | * replaced, and is persisted with the topic view. The topic view security
|
7049 | * context is not updated if the roles associated with the session are changed.
|
7050 | *
|
7051 | * </ul>
|
7052 | *
|
7053 | * <h3>Accessing the feature</h3>
|
7054 | *
|
7055 | * This feature may be obtained from a {@link Session session} as follows:
|
7056 | *
|
7057 | * <pre>
|
7058 | * const topicViews = session.topicViews;
|
7059 | * </pre>
|
7060 | *
|
7061 | * @since 6.3
|
7062 | *
|
7063 | */
|
7064 | export interface TopicViews {
|
7065 | /**
|
7066 | * Create a new named topic view.
|
7067 | *
|
7068 | * If a view with the same name already exists the new view will update
|
7069 | * the existing view.
|
7070 | *
|
7071 | * @param name the name of the view
|
7072 | * @param specification the specification of the view using the DSL
|
7073 | * @return a Result that completes when a response is received
|
7074 | * from the server, returning the topic view created by the
|
7075 | * operation.
|
7076 | * <p>
|
7077 | * If the task fails, the Result will resolve with an error. Common reasons
|
7078 | * for failure, include:
|
7079 | * <ul>
|
7080 | * <li>the `specification` is invalid;
|
7081 | * <li>the cluster was repartitioning;
|
7082 | * <li>the calling session does not have MODIFY_TOPIC_VIEW
|
7083 | * permission or appropriate path prefix permissions;
|
7084 | * <li>the session is closed.
|
7085 | * </ul>
|
7086 | */
|
7087 | createTopicView(name: string, specification: string): Result<TopicView>;
|
7088 | /**
|
7089 | * List all the topic views that have been created.
|
7090 | *
|
7091 | * @return a Result that resolves when a response is received from the
|
7092 | * server, returning a list of views sorted by their creation
|
7093 | * order.
|
7094 | * <p>
|
7095 | * If the task fails, the Result will resolve with an Error. Common
|
7096 | * reasons for failure include:
|
7097 | * <ul>
|
7098 | * <li>the cluster was repartitioning;
|
7099 | * <li>the calling session does not have READ_TOPIC_VIEW permission
|
7100 | * or appropriate path prefix permissions;
|
7101 | * <li>the session is closed.
|
7102 | * </ul>
|
7103 | */
|
7104 | listTopicViews(): Result<TopicView[]>;
|
7105 | /**
|
7106 | * Remove a named topic view if it exists.
|
7107 | *
|
7108 | * If the named view does not exist the completable future will complete
|
7109 | * successfully.
|
7110 | *
|
7111 | * @param name the name of the view
|
7112 | * @return a Result that resolves when a response is received from the
|
7113 | * server.
|
7114 | * <p>
|
7115 | * If the task fails, the Result will resolve with an Error. Common
|
7116 | * reasons for failure include:
|
7117 | * <ul>
|
7118 | * <li>the cluster was repartitioning;
|
7119 | * <li>the calling session does not have MODIFY_TOPIC_VIEW
|
7120 | * permission or appropriate path prefix permissions;
|
7121 | * <li>the session is closed.
|
7122 | * </ul>
|
7123 | */
|
7124 | removeTopicView(name: string): Result<void>;
|
7125 | }
|
7126 | /**
|
7127 | * @module Session
|
7128 | */
|
7129 | export interface Topics {
|
7130 | /**
|
7131 | * Unsubscribe the client from a given topic selector.
|
7132 | *
|
7133 | * No more updates will be received from the server for any topics matched
|
7134 | * by the selector. If no topics exist that match the selector, the server
|
7135 | * will do nothing.
|
7136 | *
|
7137 | * Each topic that this session is unsubscribed from will cause an
|
7138 | * `unsubscribe` event. Any {@link ValueStream} objects produced from {@link
|
7139 | * Session.addStream} will remain open, and will continue to emit updates
|
7140 | * for topics that the session has not been unsubscribed from.
|
7141 | *
|
7142 | * The returned result will resolve normally when the session has been
|
7143 | * unsubscribed. It will resolve with an error if the session is unable to
|
7144 | * unsubscribe, for instance due to security constraints.
|
7145 | *
|
7146 | * This function can take any number of arguments. Each argument can be a
|
7147 | * string or a {@link TopicSelector}. Alternatively, an array of strings and
|
7148 | * {@link TopicSelector}s can be passed as a single argument. At least one
|
7149 | * valid selector has to be specified.
|
7150 | *
|
7151 | * **Example:**
|
7152 | * ```
|
7153 | * // Unsubscribe from a single topic
|
7154 | * session.unsubscribe('foo');
|
7155 | * ```
|
7156 | *
|
7157 | * **Example:**
|
7158 | * ```
|
7159 | * // Unsubscribe from multiple topics
|
7160 | * session.unsubscribe('?foo/.*');
|
7161 | * ```
|
7162 | *
|
7163 | * @param selector the topic selector to unsubscribe from.
|
7164 | * @returns a {@link Result} for this operation
|
7165 | */
|
7166 | unsubscribe(selector: Array<string | TopicSelector>): Result<void>;
|
7167 | unsubscribe(...selector: Array<string | TopicSelector>): Result<void>;
|
7168 | /**
|
7169 | * Fetch the current state of one or more topics.
|
7170 | *
|
7171 | * Fetching a topic will provide its current value without subscribing this
|
7172 | * client to that topic. The returned {@link FetchStream} will emit `value`
|
7173 | * events for each topic that is matched for which a fetch request can be
|
7174 | * satisfied. Once complete, the {@link FetchStream} will be closed.
|
7175 | *
|
7176 | * This function can take any number of arguments. Each argument can be a
|
7177 | * string or a {@link TopicSelector}. Alternatively, an array of strings and
|
7178 | * {@link TopicSelector}s can be passed as a single argument. At least one
|
7179 | * valid selector has to be specified.
|
7180 | *
|
7181 | * **Example:**
|
7182 | * ```
|
7183 | * // Fetch a topic's value
|
7184 | * session.fetch("foo").on('value', function(value, path) {
|
7185 | * console.log("Value for topic '" + path + "' is: " + value);
|
7186 | * });
|
7187 | * ```
|
7188 | *
|
7189 | * **Example:**
|
7190 | * ```
|
7191 | * // Fetch multiple topics, handling possible errors
|
7192 | * session.fetch("?foo/bar.*").on({
|
7193 | * value : function(value, path) { ... },
|
7194 | * error : function(error) { ... },
|
7195 | * close : function() { ... }
|
7196 | * });
|
7197 | * ```
|
7198 | *
|
7199 | * @param selector the topic selector to fetch
|
7200 | * @returns a {@link FetchStream} that will emit the fetched values.
|
7201 | *
|
7202 | * @deprecated since 6.2
|
7203 | * <p>
|
7204 | * Prefer the use of {@link fetchRequest} instead. Unlike
|
7205 | * this method fetchRequest supports additional query
|
7206 | * constraints, returns type-safe values, and optionally allows
|
7207 | * topic properties to be retrieved. This will be removed in a
|
7208 | * future release.
|
7209 | */
|
7210 | fetch(selector: Array<string | TopicSelector>): FetchStream;
|
7211 | fetch(...selector: Array<string | TopicSelector>): FetchStream;
|
7212 | /**
|
7213 | * Creates an unconfigured fetch request.
|
7214 | *
|
7215 | * The returned request can be invoked with
|
7216 | * {@link FetchRequest.fetch fetch}. The server will evaluate
|
7217 | * the query and return a fetch result that provides the paths and types of
|
7218 | * the matching topics which the session has permission to read.
|
7219 | *
|
7220 | * You will usually want to restrict the query to a subset of the topic
|
7221 | * tree, and to retrieve the topic values and/or properties. This is
|
7222 | * achieved by applying one or more of the fluent builder methods provided
|
7223 | * by {@link FetchRequest} to produce more refined requests.
|
7224 | *
|
7225 | * **Example:**
|
7226 | * ```
|
7227 | * // Create and send a fetch request. Then pass the results to a resultHandler
|
7228 | * session.fetchRequest()
|
7229 | * .withValues(diffusion.datatypes.StringDataType)
|
7230 | * .fetch("*A/B//")
|
7231 | * .then(resultHandler);
|
7232 | * ```
|
7233 | *
|
7234 | * @see diffusion.topics.FetchRequest
|
7235 | *
|
7236 | * @returns a new unconfigured fetch request
|
7237 | *
|
7238 | * @since 6.2
|
7239 | */
|
7240 | fetchRequest(): FetchRequest;
|
7241 | /**
|
7242 | * Subscribe the session to a topic selector in order to receive updates and
|
7243 | * subscription events.
|
7244 | *
|
7245 | * Subscription causes the server to establish a subscription for this
|
7246 | * session to any topic that matches the specified selector, including topics
|
7247 | * that are added after the initial call to {@link Session.select}.
|
7248 | *
|
7249 | * If the provided selector string does not begin with one of the prefixes
|
7250 | * defined by {@link TopicSelectors}, it will be treated as a direct topic
|
7251 | * path.
|
7252 | *
|
7253 | * This function can take any number of arguments. Each argument can be a string
|
7254 | * or a {@link TopicSelector}. Alternatively, an array of strings and
|
7255 | * {@link TopicSelector}s can be passed as a single argument. At least one
|
7256 | * valid selector has to be specified.
|
7257 | *
|
7258 | * The session will become subscribed to each existing topic
|
7259 | * matching the selector unless the session is already subscribed
|
7260 | * to the topic, or the session does not have {@link TopicPermissions.READ_TOPIC READ_TOPIC}
|
7261 | * permission for the topic path. For each topic to which the
|
7262 | * session becomes subscribed, a subscription notification and
|
7263 | * initial value (if any) will be delivered to registered value
|
7264 | * streams before the returned promise completes.
|
7265 | *
|
7266 | * The subscription request is also retained at the server and the
|
7267 | * session will be automatically subscribed to newly created
|
7268 | * topics that match the selector (unless a subsequent
|
7269 | * unsubscription cancels the request).
|
7270 | *
|
7271 | * **Example:**
|
7272 | * ```
|
7273 | * // Subscribe to a topic foo
|
7274 | * session.select("foo").then(function() {
|
7275 | * // Successfully subscribed
|
7276 | * }, function(err) {
|
7277 | * // There was an error with subscribing to topic "foo"
|
7278 | * });
|
7279 | * ```
|
7280 | *
|
7281 | * @param selector the topic selector to subscribe to.
|
7282 | * @returns a result that completes when this operation succeeds
|
7283 | */
|
7284 | select(selector: Array<string | TopicSelector>): Result<void>;
|
7285 | select(...selector: Array<string | TopicSelector>): Result<void>;
|
7286 | /**
|
7287 | * Create a {@link ValueStream} to receive updates from topics that match
|
7288 | * the provided topic selector.
|
7289 | *
|
7290 | * This method will not cause the server to send any topic updates unless
|
7291 | * already subscribed. This allows the registration of listeners prior to
|
7292 | * subscribing via {@link Session.select}, or to add/remove listeners
|
7293 | * independently of subscriptions on the server.
|
7294 | *
|
7295 | * The values as specific types, use the Streams will only receive values
|
7296 | * from topics for which the specified {@link DataTypes Data Type}
|
7297 | * is compatible.
|
7298 | *
|
7299 | * The first argument of this function can be a string, a {@link
|
7300 | * TopicSelector}, or a non-empty array of strings and {@link TopicSelector}s.
|
7301 | *
|
7302 | * **Example:**
|
7303 | * ```
|
7304 | * // Produce a value stream for receiving JSON values.
|
7305 | * var json = diffusion.datatypes.json();
|
7306 | *
|
7307 | * session.addStream(topic, json).on('value', function(topic, specification, newValue, oldValue) {
|
7308 | * console.log('New value ', newValue.get());
|
7309 | * });
|
7310 | * ```
|
7311 | *
|
7312 | * @param selector the topic selector to receive updates for
|
7313 | * @param datatype the data type to produce a stream for.
|
7314 | * @returns a new {@link ValueStream} for the provided data type
|
7315 | */
|
7316 | addStream(selector: string | TopicSelector | Array<string | TopicSelector>, dataType: DataType<any, any, any>): ValueStream;
|
7317 | /**
|
7318 | * This adds a value stream for a given {@link DataTypes Data
|
7319 | * Type} without a selector which will be a fallback stream to receive all
|
7320 | * events that do not have a stream registered.
|
7321 | *
|
7322 | * **Example:**
|
7323 | * ```
|
7324 | * // Produce a fallback value stream for receiving JSON values.
|
7325 | * var json = diffusion.datatypes.json();
|
7326 | *
|
7327 | * session.addFallbackStream(json).on('value', function(topic, specification, newValue, oldValue) {
|
7328 | * console.log('New value ', newValue.get());
|
7329 | * });
|
7330 | * ```
|
7331 | *
|
7332 | * @param datatype the data type to produce a stream for.
|
7333 | * @returns a fallback stream
|
7334 | */
|
7335 | addFallbackStream(dataType: DataType<any, any, any>): ValueStream;
|
7336 | }
|
7337 | /**
|
7338 | * @module diffusion.selectors
|
7339 | */
|
7340 | /**
|
7341 | * A {@link TopicSelector} is a value that identifies one or more topics.
|
7342 | */
|
7343 | export interface TopicSelector {
|
7344 | /**
|
7345 | * The type of this selector
|
7346 | */
|
7347 | readonly type: Type;
|
7348 | /**
|
7349 | * The maximum topic path prefix from this selector
|
7350 | */
|
7351 | readonly prefix: string;
|
7352 | /**
|
7353 | * The original expression of this selector
|
7354 | */
|
7355 | readonly expression: string;
|
7356 | /**
|
7357 | * Evaluate this selector against a topic path
|
7358 | *
|
7359 | * @param topicPath the topic path
|
7360 | * @returns if this selector selects the topic path
|
7361 | */
|
7362 | selects(topicPath: string): boolean;
|
7363 | /**
|
7364 | * Convert the topic selector to a string
|
7365 | *
|
7366 | * @return the original expression of the selector
|
7367 | */
|
7368 | toString(): string;
|
7369 | }
|
7370 | /**
|
7371 | * A Topic Selector Prefix
|
7372 | */
|
7373 | export declare enum Prefix {
|
7374 | /** Prefix used for {@link Type.PATH} expressions. */
|
7375 | PATH = ">",
|
7376 | /** Prefix used for {@link Type.SPLIT_PATH_PATTERN} expressions. */
|
7377 | SPLIT_PATH_PATTERN = "?",
|
7378 | /** Prefix used for {@link Type.FULL_PATH_PATTERN} expressions. */
|
7379 | FULL_PATH_PATTERN = "*",
|
7380 | /** Prefix used for {@link Type.SELECTOR_SET} expressions. */
|
7381 | SELECTOR_SET = "#",
|
7382 | }
|
7383 | /**
|
7384 | * Topic Selector type.
|
7385 | */
|
7386 | export declare enum Type {
|
7387 | /** A selector that selects a single topic. */
|
7388 | PATH = ">",
|
7389 | /** A selector that is a split-path pattern. */
|
7390 | SPLIT_PATH_PATTERN = "?",
|
7391 | /** A selector that is a full-path pattern. */
|
7392 | FULL_PATH_PATTERN = "*",
|
7393 | /** A composite of multiple selectors. */
|
7394 | SELECTOR_SET = "#",
|
7395 | }
|
7396 | /**
|
7397 | * Create {@link TopicSelector} instances for use with other API methods.
|
7398 | *
|
7399 | * Selectors are evaluated against topic paths. A topic path is a '/'
|
7400 | * separated string of parts, which map to the topic hierarchy. Each part is
|
7401 | * formed of one or more UTF characters, except '/'. Topic paths are absolute,
|
7402 | * and evaluated from the root of the current domain.
|
7403 | *
|
7404 | * **Example:**
|
7405 | * ```
|
7406 | * // Create a topic selector
|
7407 | * var selector = diffusion.selectors.parse('?foo/bar/.*');
|
7408 | * ```
|
7409 | */
|
7410 | export declare class TopicSelectors {
|
7411 | /**
|
7412 | * The Prefix enum
|
7413 | */ readonly Prefix: typeof Prefix;
|
7414 | /**
|
7415 | * The Type enum
|
7416 | */ readonly Type: typeof Type;
|
7417 | /**
|
7418 | * Parse an expression to create a selector.
|
7419 | *
|
7420 | * This function can take any number of arguments. Each argument can be a string
|
7421 | * or a {@link TopicSelector}. Alternatively, an array of strings and
|
7422 | * {@link TopicSelector}s can be passed as a single argument.
|
7423 | *
|
7424 | * The following types of expression are supported. The type is determined
|
7425 | * by the first character of the expression.
|
7426 | *
|
7427 | * <dl>
|
7428 | * <dt>Path
|
7429 | * <dd>Path expressions begin with the character <code>></code>. The remainder of
|
7430 | * the expression must be a valid topic path. A topic path is a '/'
|
7431 | * separated string of parts. Each part is formed of one or more UTF
|
7432 | * characters, except '/'.
|
7433 | *
|
7434 | * A {@link Type.PATH PATH} selector is returned that only
|
7435 | * selects the topic with the given path.
|
7436 | *
|
7437 | * <h4>Abbreviated Path Expressions</h4>
|
7438 | *
|
7439 | * In Diffusion 5.2, an alternative syntax for path expressions was added.
|
7440 | * An <em>abbreviated path expression</em> is any valid topic path (see
|
7441 | * above) that begins with a character other than one of <code>#</code>,
|
7442 | * <code>?</code>, <code>></code>, <code>*</code>, <code>$</code>,
|
7443 | * <code>%</code>, <code>&</code>, or <code><</code>.
|
7444 | * This syntax allows most topic paths to be used directly as selector
|
7445 | * expressions which appears more natural.
|
7446 | *
|
7447 | * This method converts abbreviated path expressions to standard path
|
7448 | * expressions by prepending the <code>></code> character. Thus <code>a/b</code> is
|
7449 | * interpreted as <code>>a/b</code>.
|
7450 | *
|
7451 | * <code>parse("a/b").expression</code> will return <code>">a/b"</code>.
|
7452 | *
|
7453 | * <dt>Split-path pattern
|
7454 | * <dd>Split-path pattern expressions begin with the character <code>?</code>.
|
7455 | * The remainder of the expression is split into a list of regular
|
7456 | * expressions using the <code>/</code> character as a separator.
|
7457 | *
|
7458 | * A {@link Type.SPLIT_PATH_PATTERN SPLIT_PATH_PATTERN}
|
7459 | * selector is returned that selects topics for which each regular
|
7460 | * expression matches each part of the topic path at the corresponding
|
7461 | * level.
|
7462 | *
|
7463 | * <dt>Full-path pattern
|
7464 | * <dd>Full-path pattern expressions begin with the character <code>*</code>. The
|
7465 | * remainder of the pattern is a regular expression.
|
7466 | *
|
7467 | * A {@link Type.FULL_PATH_PATTERN FULL_PATH_PATTERN} selector
|
7468 | * is returned that selects topics for which the regular expression matches
|
7469 | * the complete topic path.
|
7470 | *
|
7471 | * Full-path patterns provide a lot of expressive power but should be used
|
7472 | * sparingly since the server can evaluate split-path patterns more
|
7473 | * efficiently.
|
7474 | *
|
7475 | * Selector sets are the preferred way to combine expressions.
|
7476 | * <code>parse("a", "b")</code> is equivalent to the full-path expression "
|
7477 | * <code>*[a|b]</code>", but can be evaluated more efficiently by the
|
7478 | * server.
|
7479 | *
|
7480 | * <dt>Selector set
|
7481 | * <dd>Selector set expressions begin with the character <code>#</code>. The
|
7482 | * remainder of the expression is a list of contained selectors, formatted
|
7483 | * as described below.
|
7484 | *
|
7485 | * A {@link Type.SELECTOR_SET SELECTOR_SET} selector is
|
7486 | * returned that selects topics that match any of the contained selectors.
|
7487 | *
|
7488 | * The contained selectors are formatted as follows. First, any selector
|
7489 | * sets are expanded to produce a full list of non-selector set expressions.
|
7490 | * Then the selector expressions are concatenated, separated by the
|
7491 | * separator <code>////</code>. This separator has been chosen as it is not
|
7492 | * valid in a path, and is not a useful sequence in a pattern.
|
7493 | * </dl>
|
7494 | *
|
7495 | * <h2>Descendant pattern qualifiers</h2>
|
7496 | *
|
7497 | * Split-path and full-path pattern expressions can be further modified by
|
7498 | * appending `/` or `//`. These control the behaviour of the
|
7499 | * selector with respect to the descendants of the topics that match the
|
7500 | * pattern.
|
7501 | *
|
7502 | * <ul>
|
7503 | *
|
7504 | * <li>
|
7505 | * If the expression does not end with `/` or `//`, it selects
|
7506 | * only the topics that match the pattern.</li>
|
7507 | *
|
7508 | * <li>
|
7509 | * If the expression ends with `/`, it selects only the descendants of
|
7510 | * the matching topics, excluding the matching topics.</li>
|
7511 | *
|
7512 | * <li>
|
7513 | * If the expression ends with `//`, it selects the matching topics
|
7514 | * and all of their descendants.</li>
|
7515 | * </ul>
|
7516 | * </p>
|
7517 | *
|
7518 | * <h2>Regular expressions</h2>
|
7519 | *
|
7520 | * Any Java-style regular expression can be used in split-path and full-path
|
7521 | * patterns, with the following restrictions:
|
7522 | *
|
7523 | * * A regular expression may not be empty.
|
7524 | * * A regular expression used in split-path patterns may not contain the
|
7525 | * path separator `/`.
|
7526 | * * A regular expression used in full-path patterns may not contain the
|
7527 | * selector set separator `////`.
|
7528 | *
|
7529 | * Regular expressions that break any of these restrictions would never
|
7530 | * match a topic path, so they make no practical difference.
|
7531 | *
|
7532 | * <h2>Examples</h2>
|
7533 | *
|
7534 | * <h3>Path expressions</h3>
|
7535 | *
|
7536 | * Path | Matches `alpha/beta`? | Matches `alpha/beta/gamma`?
|
7537 | * ------------- | ---------------------- | ---------------------------
|
7538 | * `>alpha/beta` | yes | no
|
7539 | * `>alpha/beta/gamma` | no | yes
|
7540 | * `>beta` | no | no
|
7541 | * `>.*``/.*` | no | no
|
7542 | * `>/alpha/beta/` | yes | no
|
7543 | *
|
7544 | * <h3>Abbreviated path expressions</h3>
|
7545 | *
|
7546 | * Path | Matches `alpha/beta`? | Matches `alpha/beta/gamma`?
|
7547 | * ------------- | ---------------------- | ---------------------------
|
7548 | * `alpha/beta` | yes | no
|
7549 | * `alpha/beta/gamma` | no | yes
|
7550 | * `beta` | no | no
|
7551 | * `/alpha/beta/` | yes | no
|
7552 | *
|
7553 | * <h3>Split-path pattern expressions</h3>
|
7554 | *
|
7555 | * Path | Matches `alpha/beta`? | Matches `alpha/beta/gamma`?
|
7556 | * ------------- | ---------------------- | ---------------------------
|
7557 | * `?alpha/beta` | yes | no
|
7558 | * `?alpha/beta/gamma` | no | yes
|
7559 | * `?beta` | no | no
|
7560 | * `?.*` | no | no
|
7561 | * `?.*``/.*` | yes | no
|
7562 | * `?alpha/beta/` | no | yes
|
7563 | * `?alpha/beta//` | yes | yes
|
7564 | * `?alpha/.*``//` | yes | yes
|
7565 | *
|
7566 | * <h3>Full-path pattern expressions</h3>
|
7567 | *
|
7568 | * Path | Matches `alpha/beta`? | Matches `alpha/beta/gamma`?
|
7569 | * ------------- | ---------------------- | ---------------------------
|
7570 | * `*alpha/beta` | yes | no
|
7571 | * `*alpha/beta/gamma` | no | yes
|
7572 | * `*beta` | no | no
|
7573 | * `*.*beta` | yes | no
|
7574 | * `*.*` | yes | yes
|
7575 | * `*alpha/beta/` | no | yes
|
7576 | * `*alpha/beta//` | yes | yes
|
7577 | *
|
7578 | * **Example:**
|
7579 | * ```
|
7580 | * // Simple selector
|
7581 | * var selector = diffusion.selectors.parse(">a/b");
|
7582 | * ```
|
7583 | *
|
7584 | * **Example:**
|
7585 | * ```
|
7586 | * // Creating a selector set
|
7587 | * var selectorSet = diffusion.selectors.parse(">a", ">b");
|
7588 | * ```
|
7589 | *
|
7590 | * @param expression the pattern expression(s). At least one
|
7591 | * valid selector has to be specified.
|
7592 | * @param args additional pattern expressions
|
7593 | * @return the topic selector. If multiple expressions are provided,
|
7594 | * this will return a `SELECTOR_SET` that will match if
|
7595 | * any of the * provided `selectors` match.
|
7596 | */
|
7597 | parse(expression: string | TopicSelector | Array<string | TopicSelector>, ...args: Array<string | TopicSelector>): TopicSelector;
|
7598 | }
|
7599 | /**
|
7600 | * Provide access to
|
7601 | * {@link UpdateConstraint UpdateConstraint},
|
7602 | * {@link UpdateConstraintFactory UpdateConstraintFactory},
|
7603 | * {@link PartialJSON PartialJSON},
|
7604 | * {@link TopicCreationResult TopicCreationResult}, and
|
7605 | * {@link UpdateStream UpdateStream}.
|
7606 | *
|
7607 | * @module diffusion.topicUpdate
|
7608 | */
|
7609 | /**
|
7610 | * Result indicating whether the operation caused a topic to be created or if
|
7611 | * it already existed.
|
7612 | *
|
7613 | * @since 6.2
|
7614 | */
|
7615 | export declare enum TopicCreationResult {
|
7616 | /**
|
7617 | * A new topic was created.
|
7618 | */
|
7619 | CREATED = 1,
|
7620 | /**
|
7621 | * A topic with the same specification already exists.
|
7622 | */
|
7623 | EXISTS = 2,
|
7624 | }
|
7625 | export interface TopicUpdateNamespace {
|
7626 | TopicCreationResult: typeof TopicCreationResult;
|
7627 | }
|
7628 | export declare const TopicUpdateNamespace: TopicUpdateNamespace;
|
7629 | /**
|
7630 | * @module diffusion.topicUpdate
|
7631 | */
|
7632 | /**
|
7633 | * A constraint to be applied to an update operation or the creation of an
|
7634 | * update stream.
|
7635 | *
|
7636 | * Constraints describe a condition that must be satisfied for an operation to
|
7637 | * succeed. Constraints can be applied to the setting of a value or creation
|
7638 | * of an update stream. Constraints are only evaluated on the server.
|
7639 | *
|
7640 | * The constraints are evaluated using the:
|
7641 | *
|
7642 | * * active session locks
|
7643 | * * existence of the topic
|
7644 | * * current value of the topic
|
7645 | *
|
7646 | * The value of a topic can be described in several ways. The value can be
|
7647 | * described as an exact value, a partial value or an unset value.
|
7648 | *
|
7649 | * Constraints can be composed with one another. It is only possible to
|
7650 | * construct logical ANDs of constraints. Constraints can only be composed if
|
7651 | * the resulting constraint is satisfiable. Multiple session locks can be held
|
7652 | * but a topic can only have a single value. Constraints specifying multiple
|
7653 | * topic values cannot be constructed.
|
7654 | *
|
7655 | * Constraints can be created using a
|
7656 | * {@link UpdateConstraintFactory}, an
|
7657 | * instance of which can be obtained using
|
7658 | * {@link updateConstraints}.
|
7659 | * For example:
|
7660 | *
|
7661 | * ```
|
7662 | * const factory = diffusion.updateConstraints();
|
7663 | * const constraint = factory.locked(lock).and(factory.value(expectedValue));
|
7664 | * ```
|
7665 | *
|
7666 | * @since 6.2
|
7667 | */
|
7668 | export interface UpdateConstraint {
|
7669 | /**
|
7670 | * Returns a composed constraint that represents a logical AND of this
|
7671 | * constraint and another.
|
7672 | *
|
7673 | * If the composed constraint would be unsatisfiable, an `Error`
|
7674 | * is thrown.
|
7675 | *
|
7676 | * @param other a constraint that will be logically-ANDed with this constraint
|
7677 | * @return a composed constraint that represents a logical AND of this
|
7678 | * constraint and the `other` constraint
|
7679 | */
|
7680 | and(other: UpdateConstraint): UpdateConstraint;
|
7681 | }
|
7682 | /**
|
7683 | * A constraint requiring the current value of the
|
7684 | * {@link TopicTypeEnum.JSON JSON} topic to match the partially described value.
|
7685 | *
|
7686 | * The code:
|
7687 | *
|
7688 | * ```
|
7689 | * const factory = diffusion.updateConstraints();
|
7690 | * const constraint = factory.jsonValue().with('/id', idValue).without('/cancellation');
|
7691 | * ```
|
7692 | *
|
7693 | * creates a constraint for a JSON object with a specific ID value and no
|
7694 | * value for a 'cancellation' property.
|
7695 | *
|
7696 | * @since 6.2
|
7697 | */
|
7698 | export interface PartialJSON extends UpdateConstraint {
|
7699 | /**
|
7700 | * Require a value at a specific position in the JSON object.
|
7701 | *
|
7702 | * The `pointer` is a
|
7703 | * <a href="https://tools.ietf.org/html/rfc6901">JSON Pointer</a>
|
7704 | * syntax reference locating the `value` in the JSON object. If
|
7705 | * the `pointer` parameter cannot be parsed as a JSON pointer an
|
7706 | * `Error` is thrown.
|
7707 | *
|
7708 | * The function returns a new {@link PartialJSON PartialJSON}
|
7709 | * object. The original object remains unmodified.
|
7710 | *
|
7711 | * @param pointer the pointer expression
|
7712 | * @param dataType the optional type of the value
|
7713 | * @param value the value
|
7714 | * @return a new constraint
|
7715 | */
|
7716 | with(pointer: string, dataType: DataType<any, any, any>, value: any): PartialJSON;
|
7717 | /**
|
7718 | * Require a specific position in the JSON object to be empty.
|
7719 | *
|
7720 | * The `pointer` is a
|
7721 | * <a href="https://tools.ietf.org/html/rfc6901">JSON Pointer</a> syntax
|
7722 | * reference that should have no value in the JSON object. If the
|
7723 | * `pointer` parameter cannot be parsed as a JSON pointer an
|
7724 | * `Error` is thrown.
|
7725 | *
|
7726 | * The function returns a new {@link PartialJSON PartialJSON}
|
7727 | * object. The original object remains unmodified.
|
7728 | *
|
7729 | * @param pointer the pointer expression
|
7730 | * @return a new constraint
|
7731 | */
|
7732 | without(pointer: string): PartialJSON;
|
7733 | }
|
7734 | /**
|
7735 | * Factory for the constraint types.
|
7736 | *
|
7737 | * An instance can be obtained by calling
|
7738 | * {@link updateConstraints}.
|
7739 | *
|
7740 | * @since 6.2
|
7741 | */
|
7742 | export interface UpdateConstraintFactory {
|
7743 | /**
|
7744 | * Create a constraint requiring a lock to be held by the session.
|
7745 | *
|
7746 | * This can be used to coordinate operations between multiple
|
7747 | * sessions.
|
7748 | *
|
7749 | * @param lock the lock
|
7750 | * @return the constraint
|
7751 | */
|
7752 | locked(lock: SessionLock): UpdateConstraint;
|
7753 | /**
|
7754 | * Create a constraint requiring the current value of the topic to match
|
7755 | * the supplied value.
|
7756 | *
|
7757 | * If `dataType` is not specified, the data type is inferred
|
7758 | * from the `value` parameter.
|
7759 | *
|
7760 | * This method is useful when changing the value of a topic. This constraint
|
7761 | * is unsatisfied if no topic is present at the path, making it unsuitable
|
7762 | * for operations that try to add topics.
|
7763 | *
|
7764 | * When a {@link TopicTypeEnum.STRING string},
|
7765 | * {@link TopicTypeEnum.INT64 int64} or
|
7766 | * {@link TopicTypeEnum.DOUBLE double} topic is updated to a
|
7767 | * {@code null} value, the topic is set to have no value. Use the
|
7768 | * {@link noValue} constraint to check if the topic has no value.
|
7769 | *
|
7770 | * @param value the value
|
7771 | * @param dataType the optional type of the values
|
7772 | * @return the constraint
|
7773 | */
|
7774 | value(value: any, dataType?: DataType<any, any, any>): UpdateConstraint;
|
7775 | /**
|
7776 | * Create a constraint requiring the topic to have no value.
|
7777 | *
|
7778 | * This is useful when setting the first value of a topic. This
|
7779 | * constraint is unsatisfied if no topic is present at the path, making
|
7780 | * it unsuitable for operations that try to add topics.
|
7781 | *
|
7782 | * @return the constraint
|
7783 | */
|
7784 | noValue(): UpdateConstraint;
|
7785 | /**
|
7786 | * Create a constraint requiring the path to have no topic.
|
7787 | *
|
7788 | * This is useful when setting the first value of a topic being added using
|
7789 | * an {@link UpdateStream} without changing the value if the topic already
|
7790 | * exists. This constraint is unsatisfied if a topic is present at the path,
|
7791 | * making it unsuitable for operations that try to set topics without adding
|
7792 | * them.
|
7793 | *
|
7794 | * @return the constraint
|
7795 | */
|
7796 | noTopic(): UpdateConstraint;
|
7797 | /**
|
7798 | * Create a constraint that partially matches the current topic value.
|
7799 | *
|
7800 | * The topic must be a {@link TopicTypeEnum.JSON JSON} topic. The
|
7801 | * {@link PartialJSON} partially describes the
|
7802 | * structure of a {@link JSON} value.
|
7803 | *
|
7804 | * @return {diffusion.topicUpdate.PartialJSON} the constraint
|
7805 | */
|
7806 | jsonValue(): PartialJSON;
|
7807 | }
|
7808 | /**
|
7809 | * @module diffusion.topicUpdate
|
7810 | */
|
7811 | /**
|
7812 | * An update stream provides a method for updating a specific topic.
|
7813 | *
|
7814 | * An update stream is associated with a specific topic. The type of the topic
|
7815 | * must match the type of values passed to the update stream. It can be created
|
7816 | * with an optional {@link UpdateConstraint constraint}.
|
7817 | * The existence of the topic, its type and the constraint are validated lazily
|
7818 | * by the first {@link set} or {@link validate} operation. Subsequent operations
|
7819 | * issued before the first operation completes will be deferred until the
|
7820 | * completion of the first operation.
|
7821 | *
|
7822 | * An update stream can be used to send any number of updates. It sends a
|
7823 | * sequence of updates for a specific topic to the server. If supported by the
|
7824 | * data type, updates will be sent to the server as a stream of binary deltas.
|
7825 | * An update stream does not prevent other sessions from updating the topic. If
|
7826 | * exclusive access is required update streams should be used with
|
7827 | * {@link SessionLock session locks} as constraints.
|
7828 | *
|
7829 | * Once validated an update stream can be invalidated. An invalidated
|
7830 | * update stream rejects the operations applied to it. The update stream
|
7831 | * will be invalidated if:
|
7832 | *
|
7833 | * * the topic is removed
|
7834 | * * another update stream is created for the same topic
|
7835 | * * the topic is updated to a new value by anything other than the stream
|
7836 | * * the session does not have the
|
7837 | * {@link TopicPermission.UPDATE_TOPIC update permission}
|
7838 | * * an operation fails because of cluster repartitioning
|
7839 | *
|
7840 | * @since 6.2
|
7841 | */
|
7842 | export interface UpdateStream {
|
7843 | /**
|
7844 | * Sets the topic to a specified value.
|
7845 | *
|
7846 | * `null` or `undefined` can only be passed to the
|
7847 | * `value` parameter when updating {@link TopicTypeEnum.STRING string},
|
7848 | * {@link TopicTypeEnum.INT64 int64} or {@link TopicTypeEnum.DOUBLE double} topics.
|
7849 | * <p>
|
7850 | * When a topic of type {@link TopicTypeEnum.STRING string},
|
7851 | * {@link TopicTypeEnum.INT64 int64} or {@link TopicTypeEnum.DOUBLE double} is set
|
7852 | * to `null` or `undefined` , the topic will be updated
|
7853 | * to have no value. If a previous value was present subscribers will
|
7854 | * receive a notification that the new value is `undefined` . New
|
7855 | * subscribers will not receive a value notification.
|
7856 | *
|
7857 | * @param value the value. Update streams for string, int64, and double
|
7858 | * topics accept `null` or `undefined`, as described above.
|
7859 | * Using null with other topic types is an error and will
|
7860 | * result in an `Error` .
|
7861 | * @return a Result that completes when a response is received from the
|
7862 | * server.
|
7863 | * <p>
|
7864 | * If the task fails, the Result will resolve with an
|
7865 | * `Error` .
|
7866 | */
|
7867 | set(value: any): Result<void>;
|
7868 | /**
|
7869 | * Return the latest value of the topic set using this update stream.
|
7870 | *
|
7871 | * The returned value reflects the last value that has been set, before it
|
7872 | * is sent to the server.
|
7873 | *
|
7874 | * If the server rejects a set operation, the topic value will not change
|
7875 | * and this update stream will be invalidated.
|
7876 | *
|
7877 | * This method will throw an `Error` if called before the first
|
7878 | * call to {@link set}
|
7879 | *
|
7880 | * @return the cached value of the topic
|
7881 | */
|
7882 | get(): any;
|
7883 | /**
|
7884 | * Validates the update stream.
|
7885 | *
|
7886 | * Update streams are validated lazily when {@link set setting the value}.
|
7887 | * This method allows the stream to be validated before a value needs to be
|
7888 | * set.
|
7889 | *
|
7890 | * If the update stream has not been validated yet, calling this method
|
7891 | * checks the topic exists, the topic type is correct, the constraint is
|
7892 | * satisfied and the session has permission to update the topic. Once
|
7893 | * it has been validated calling this method checks the topic has not been
|
7894 | * removed, no other stream has been created for the topic, the value
|
7895 | * of the topic has not been changed by anything else and the session
|
7896 | * still has permission to update the topic. If validation fails, the Result
|
7897 | * will resolve with an `Error`.
|
7898 | *
|
7899 | * If this method fails all subsequent calls to {@link set} or
|
7900 | * {@link validate} will resolve with an `Error`.
|
7901 | *
|
7902 | * @return a Result that completes when a response is received from the server.
|
7903 | */
|
7904 | validate(): Result<TopicCreationResult>;
|
7905 | }
|
7906 | /**
|
7907 | * A parameterised query that can be used to search the topic tree.
|
7908 | *
|
7909 | * A new request can be created using the {@link Session.fetchRequest fetchRequest}
|
7910 | * method and modified to specify a range of topics and/or
|
7911 | * various levels of detail. The request can then be issued to the server
|
7912 | * using the {@link FetchRequest.fetch fetch} method
|
7913 | * supplying a topic selector which specifies the selection of topics.
|
7914 | * The results are returned via a {@link Result}.
|
7915 | *
|
7916 | * As a minimum, the path and type of each selected topic will be returned.
|
7917 | * It is also possible to request that the topic {@link withValues values}
|
7918 | * and/or {@link withProperties properties} are returned.
|
7919 | *
|
7920 | * If values are selected then the topic types selected are naturally
|
7921 | * constrained by the provided `dataType` argument. So if
|
7922 | * {@link DataTypes.string} is specified, only {@link TopicTypeEnum.STRING
|
7923 | * STRING} topics will be selected. However, if {@link DataTypes.json} is
|
7924 | * specified, all types compatible with {@link JSON} will be selected
|
7925 | * including {@link TopicTypeEnum.STRING STRING}, {@link TopicTypeEnum.INT64 INT64}
|
7926 | * and {@link TopicTypeEnum.DOUBLE DOUBLE}. See
|
7927 | * {@link DataType.canReadAs} for the class hierarchy of types.
|
7928 | *
|
7929 | * To select topic types when
|
7930 | * values are not required, or to further constrain the selection when
|
7931 | * values are required, it is also possible to specify exactly which
|
7932 | * {@link TopicTypeEnum topic types} to select.
|
7933 | *
|
7934 | * The topics selected by the topic selector can be further restricted by
|
7935 | * range. A range is defined by a start path and an end path, and contains
|
7936 | * all paths in-between in path order. Given a topic tree containing the
|
7937 | * topics:
|
7938 | *
|
7939 | * ```
|
7940 | * a, a/b, a/c, a/c/x, a/c/y, a/d, a/e, b, b/a/x, b/b/x, c
|
7941 | * ```
|
7942 | *
|
7943 | * The range from `a/c/y` to `b/a/x` includes the topics with paths:
|
7944 | *
|
7945 | * ```
|
7946 | * a/c/x, a/c/y, a/d, a/e, b, b/a/x
|
7947 | * ```
|
7948 | *
|
7949 | * The start point of a range can be specified using {@link from} or
|
7950 | * {@link after} and an end point using {@link to} or
|
7951 | * {@link before}. {@link from} and {@link to} include any
|
7952 | * topic with the specified path in the selection, whereas {@link after}
|
7953 | * and {@link before} are non-inclusive and useful for paging
|
7954 | * through a potentially large range of topics. If no start point is
|
7955 | * specified, the start point is assumed to be the first topic of the topic
|
7956 | * tree, ordered by path name. Similarly, if no end point is specified, the
|
7957 | * end point is the last topic of the topic tree.
|
7958 | *
|
7959 | * A limit on the number of results returned can be specified using
|
7960 | * {@link first}. This is advisable if the result set could
|
7961 | * potentially be large. The number of results returned is also limited by
|
7962 | * the session's maximum message size – see {@link maximumResultSize}. The
|
7963 | * result indicates whether the results have been limited via the
|
7964 | * {@link FetchResult.hasMore hasMore} method. If `hasMore()`
|
7965 | * returns `true`, further results can be retrieved by modifying the original
|
7966 | * query to request results {@link after} the last path received.
|
7967 | *
|
7968 | * By default, results are returned in path order, earliest path first,
|
7969 | * starting from the beginning of any range specified. It is also possible
|
7970 | * to request results from the end of the range indicated by specifying a
|
7971 | * limit to the number of results using {@link last}. This method
|
7972 | * complements {@link first}, returning up to the specified number of
|
7973 | * results from the end of the range, but in reverse path order. This is
|
7974 | * useful for paging backwards through a range of topics.
|
7975 | *
|
7976 | * It can be useful to explore an unknown topic tree in a breadth-first
|
7977 | * manner rather than the path order. This can be achieved using
|
7978 | * {@link limitDeepBranches}.
|
7979 | *
|
7980 | * {@link TopicTypeEnum.SLAVE Slave} topics are supported, in that if the slave
|
7981 | * topic itself is within the requested selector/range and it is currently
|
7982 | * linked to a topic that should be selected then a result will be returned
|
7983 | * for the slave topic with the type/value/properties of the source topic.
|
7984 | *
|
7985 | * {@link TopicTypeEnum.ROUTING Routing} topics are <b>not</b> supported, and if
|
7986 | * encountered will be ignored (i.e. treated as if they did not exist).
|
7987 | *
|
7988 | * FetchRequest instances are immutable and can be safely shared and reused.
|
7989 | *
|
7990 | * @since 6.2
|
7991 | */
|
7992 | export declare abstract class FetchRequest {
|
7993 | /**
|
7994 | * Specifies a logical start point within the topic tree.
|
7995 | *
|
7996 | * If specified, only results for topics with a path that is lexically equal
|
7997 | * to or 'after' the specified path will be returned.
|
7998 | *
|
7999 | * This is the inclusive equivalent of {@link after} and if used will
|
8000 | * override any previous {@link after} or {@link from}
|
8001 | * constraint.
|
8002 | *
|
8003 | * @param topicPath the topic path from which results are to be returned
|
8004 | *
|
8005 | * @return a new fetch request derived from this fetch request but
|
8006 | * selecting only topics from the specified path onwards
|
8007 | * (inclusive)
|
8008 | */
|
8009 | abstract from(topicPath: string): FetchRequest;
|
8010 | /**
|
8011 | * Specifies a logical start point within the topic tree.
|
8012 | *
|
8013 | * If specified, only results for topics with a path that is lexically
|
8014 | * 'after' the specified path will be returned.
|
8015 | *
|
8016 | * This is the non inclusive equivalent of {@link from} and if used
|
8017 | * will override any previous {@link from} or {@link after}
|
8018 | * constraint.
|
8019 | *
|
8020 | * @param topicPath the topic path after which results are to be returned
|
8021 | * @return a new fetch request derived from this fetch
|
8022 | * request but selecting only topics after the specified path (not
|
8023 | * inclusive)
|
8024 | */
|
8025 | abstract after(topicPath: string): FetchRequest;
|
8026 | /**
|
8027 | * Specifies a logical end point within the topic tree.
|
8028 | *
|
8029 | * If specified, only results for topics with a path that is lexically equal
|
8030 | * to or 'before' the specified path will be returned.
|
8031 | *
|
8032 | * This is the inclusive equivalent of {@link before} and if used
|
8033 | * will override any previous {@link before} or {@link to}
|
8034 | * constraint.
|
8035 | *
|
8036 | * @param topicPath the topic path to which results are to be returned
|
8037 | * @return a new fetch request derived from this fetch request but
|
8038 | * selecting only topics including and before the specified path
|
8039 | * (inclusive)
|
8040 | */
|
8041 | abstract to(topicPath: string): FetchRequest;
|
8042 | /**
|
8043 | * Specifies a logical end point within the topic tree.
|
8044 | *
|
8045 | * If specified, only results for topics with a path that is lexically
|
8046 | * 'before' the specified path will be returned.
|
8047 | *
|
8048 | * This is the non inclusive equivalent of {@link to} and if used
|
8049 | * will override any previous {@link to } or {@link before}
|
8050 | * constraint.
|
8051 | *
|
8052 | * @param topicPath the topic path before which results are to be
|
8053 | * returned
|
8054 | *
|
8055 | * @return a new fetch request derived from this fetch
|
8056 | * request but selecting only topics before the specified path (not
|
8057 | * inclusive)
|
8058 | */
|
8059 | abstract before(topicPath: string): FetchRequest;
|
8060 | /**
|
8061 | * Specifies that only topics of the specified topic types should be
|
8062 | * returned.
|
8063 | *
|
8064 | * If this is not specified, {@link getAllTypes all
|
8065 | * types} will be returned (unless constrained by {@link withValues}).
|
8066 | *
|
8067 | * This may be used instead to further constrain the results when using
|
8068 | * {@link withValues}. For example, you can specify
|
8069 | * {diffusion.datatypes.DataType.json} to {@link withValues} then specify
|
8070 | * {@link TopicTypeEnum.JSON JSON} here to ensure that only
|
8071 | * JSON topics are returned and not those topics that are logically value
|
8072 | * subtypes of JSON (e.g. {@link TopicTypeEnum.STRING STRING}).
|
8073 | *
|
8074 | * If {@link withValues} has been specified then the types specified here
|
8075 | * must be compatible with the value class specified.
|
8076 | *
|
8077 | * Neither {@link TopicTypeEnum.SLAVE SLAVE} nor {@link
|
8078 | * TopicTypeEnum.ROUTING ROUTING} may be specified as only target topic
|
8079 | * types may be selected.
|
8080 | *
|
8081 | * @param topicTypes topic types to be selected
|
8082 | *
|
8083 | * @return a new fetch request derived from this fetch request but
|
8084 | * specifying that only topics of the specified topic types should
|
8085 | * be returned.
|
8086 | *
|
8087 | * @throws an Error if invalid topic types are specified
|
8088 | */
|
8089 | abstract topicTypes(topicTypes: TopicType[]): FetchRequest;
|
8090 | /**
|
8091 | * Specifies that values should be returned for selected topics,
|
8092 | * constraining the selection to only those topics with a data type
|
8093 | * compatible with the specified {@link DataType
|
8094 | * DataType}.
|
8095 | *
|
8096 | * The specified value constrains the topic types. So, any topic types
|
8097 | * specified in a previous call to {@link topicTypes} that
|
8098 | * cannot be read as the specified class will be removed from the list
|
8099 | * of topic types.
|
8100 | *
|
8101 | * @param dataType the type of values. If no value is specified this will
|
8102 | * cancel any previous call (topic types will remain
|
8103 | * unchanged).
|
8104 | *
|
8105 | * @return a new fetch request derived from this fetch
|
8106 | * request but specifying that only topics compatible with the
|
8107 | * specified class should be returned with values.
|
8108 | *
|
8109 | * @throws an Error if the class is not compatible with any topic types.
|
8110 | */
|
8111 | abstract withValues(dataType: DataType<any, any, any>): FetchRequest;
|
8112 | /**
|
8113 | * Specifies that all properties associated with each topic's {@link
|
8114 | * TopicSpecification specification} should be returned.
|
8115 | *
|
8116 | * @return a new fetch request derived from this fetch request but
|
8117 | * specifying that topic specification properties should be
|
8118 | * returned.
|
8119 | */
|
8120 | abstract withProperties(): FetchRequest;
|
8121 | /**
|
8122 | * Specifies a maximum number of topic results to be returned from the start
|
8123 | * of the required range.
|
8124 | *
|
8125 | * If this is not specified, the number of results returned will only be
|
8126 | * limited by other constraints of the request.
|
8127 | *
|
8128 | * This should be used to retrieve results in manageable batches and prevent
|
8129 | * very large result sets.
|
8130 | *
|
8131 | * If there are potentially more results that would satisfy the other
|
8132 | * constraints then the fetch result will indicate so via the {@link
|
8133 | * FetchResult.hasMore hasMore} method.
|
8134 | *
|
8135 | * If the count is set to zero, no results will be returned. In this case,
|
8136 | * {@link FetchResult.hasMore hasMore} can be used to check the existence of
|
8137 | * any topics matching the criteria without retrieving topic details.
|
8138 | *
|
8139 | * Either this or {@link last} may be specified. This will therefore
|
8140 | * override any previous {@link last} or {@link first}
|
8141 | * constraint.
|
8142 | *
|
8143 | * @param count the non-negative maximum number of results to return from the
|
8144 | * start of the range
|
8145 | *
|
8146 | * @return a new fetch request derived from this fetch
|
8147 | * request but selecting only the number of topics specified from
|
8148 | * the start of the range
|
8149 | */
|
8150 | abstract first(count: number): FetchRequest;
|
8151 | /**
|
8152 | * Specifies a maximum number of topic results to be returned from the end
|
8153 | * of the required range.
|
8154 | *
|
8155 | * This is similar to {@link first} except that the specified number
|
8156 | * of results are returned from the end of the range. This is useful for
|
8157 | * paging backwards through a range of topics. Results are always returned
|
8158 | * in topic path order (not reverse order).
|
8159 | *
|
8160 | * Either this or {@link first} may be specified. This will therefore
|
8161 | * override any previous {@link first} or {@link last}
|
8162 | * constraint.
|
8163 | *
|
8164 | * @param count the non-negative maximum number of results to return from the
|
8165 | * end of the range
|
8166 | *
|
8167 | * @return a new fetch request derived from this fetch
|
8168 | * request but selecting only the number of topics specified from
|
8169 | * the end of the range
|
8170 | */
|
8171 | abstract last(count: number): FetchRequest;
|
8172 | /**
|
8173 | * Specifies the maximum data size of the result set.
|
8174 | * <p>
|
8175 | * This may be used to constrain the size of the result. If not specified
|
8176 | * then by default the maximum message size for the session (as specified by
|
8177 | * {@link Options.maxMessageSize} is used.
|
8178 | *
|
8179 | * @param maximumSize the maximum size of the result set in bytes.
|
8180 | * If a value greater than the session's maximum message
|
8181 | * size is specified, the maximum message size will be
|
8182 | * used.
|
8183 | *
|
8184 | * @return a new fetch request derived from this fetch
|
8185 | * request but constraining the size of the result to the specified
|
8186 | * maximum
|
8187 | */
|
8188 | abstract maximumResultSize(maximumSize: number): FetchRequest;
|
8189 | /**
|
8190 | * Specifies a limit on the number of results returned for each deep
|
8191 | * branch.
|
8192 | *
|
8193 | * A deep branch has a root path that has a number of parts equal to the
|
8194 | * `deepBranchDepth` parameter. The `deepBranchLimit`
|
8195 | * specifies the maximum number of results for each deep branch.
|
8196 | *
|
8197 | * This method is particularly useful for incrementally exploring a
|
8198 | * topic tree from the root, allowing a breadth-first search strategy.
|
8199 | *
|
8200 | * For example, given a topic tree containing the topics with the
|
8201 | * following paths:
|
8202 | *
|
8203 | * ```
|
8204 | * x/0
|
8205 | * x/x/1
|
8206 | * x/x/x/2
|
8207 | * y/y/y/y/3
|
8208 | * y/y/y/4
|
8209 | * z/5
|
8210 | * z/z/6
|
8211 | * ```
|
8212 | *
|
8213 | * Then
|
8214 | *
|
8215 | * ```
|
8216 | * session.fetchRequest().limitDeepBranches(1, 1).fetch("?.//");
|
8217 | * ```
|
8218 | *
|
8219 | * will return results with the paths `x/0`, `y/y/y/y/3`,
|
8220 | * and `z/5`. The application can then determine the roots of the
|
8221 | * tree are `x`, `y`, and `z`.
|
8222 | *
|
8223 | * The `deepBranchLimit` parameter can usefully be set to
|
8224 | * `0`. For example, given the same example topic tree,
|
8225 | *
|
8226 | * ```
|
8227 | * session.fetchRequest().limitDeepBranches(3, 0).fetch("?.//");
|
8228 | * ```
|
8229 | *
|
8230 | * will only return results having paths with fewer than three parts;
|
8231 | * namely `x/0`, and `z/5`.
|
8232 | *
|
8233 | * The fetch result does not indicate whether this option caused some
|
8234 | * results to be filtered from deep branches. It has no affect on the
|
8235 | * {@link FetchResult.hasMore hasMore()} result. If the result set
|
8236 | * contains `deepBranchLimit` results for a particular deep
|
8237 | * branch, some topics from that branch may have been filtered.
|
8238 | *
|
8239 | * @param deepBranchDepth the number of parts in the root path of a
|
8240 | * branch for it to be considered deep
|
8241 | * @param deepBranchLimit the maximum number of results to return for
|
8242 | * each deep branch
|
8243 | * @return a new fetch request derived from this fetch request but
|
8244 | * restricting the number of results for deep branches
|
8245 | * @since 6.4
|
8246 | */
|
8247 | abstract limitDeepBranches(deepBranchDepth: number, deepBranchLimit: number): FetchRequest;
|
8248 | /**
|
8249 | * Sends a fetch request to the server.
|
8250 | *
|
8251 | * Results are returned for all topics matching the selector that satisfy
|
8252 | * the request constraints within any range defined by {@link from}/{@link
|
8253 | * after} and/or {@link to}/{@link before}.
|
8254 | *
|
8255 | * This function can take any number of arguments. Each argument can be a string
|
8256 | * or a {@link TopicSelector}. Alternatively, an array of strings and
|
8257 | * {@link TopicSelector}s can be passed as a single argument. At least one
|
8258 | * valid selector has to be specified.
|
8259 | *
|
8260 | * @param topics specifies a topic selector which selects the topics to be
|
8261 | * fetched
|
8262 | *
|
8263 | * @return a Result that resolves with a {@link FetchResult
|
8264 | * FetchResult} when a response is received from the server with
|
8265 | * the results of the fetch operation.
|
8266 | * <p>
|
8267 | * If the task completes successfully, the FetchResult returned by
|
8268 | * the Result will be an object encapsulating all of the results.
|
8269 | * <p>
|
8270 | * Otherwise, the Result will resolve with an Error.
|
8271 | */
|
8272 | abstract fetch(topics: Array<TopicSelector | string>): Result<FetchResult<any>>;
|
8273 | abstract fetch(...topics: Array<TopicSelector | string>): Result<FetchResult<any>>;
|
8274 | /**
|
8275 | * Return a set of all topic types that can be fetched.
|
8276 | *
|
8277 | * @returns the topic types that can be fetched by a FetchRequest
|
8278 | */
|
8279 | static getAllTypes(): Set<TopicType>;
|
8280 | }
|
8281 | /**
|
8282 | * Encapsulates the results from a fetch operation issued to the server.
|
8283 | *
|
8284 | * A fetch operation is issued using a {@link FetchRequest
|
8285 | * fetch request} which will return a result of this type via a {@link Result}.
|
8286 | *
|
8287 | * @param V the result value type. This will be any type unless the request
|
8288 | * indicated that {@link FetchRequest.withValues
|
8289 | * values} are to be returned, in which case this will be the data
|
8290 | * type requested.
|
8291 | *
|
8292 | * @since 6.2
|
8293 | */
|
8294 | export interface FetchResult<V> {
|
8295 | /**
|
8296 | * Returns the results from the fetch operation.
|
8297 | *
|
8298 | * Results are always returned in path order.
|
8299 | *
|
8300 | * @return a list of {@link TopicResult TopicResult}s,
|
8301 | * each representing a result single topic selected by the fetch
|
8302 | * operation.
|
8303 | */
|
8304 | results(): Array<TopicResult<V>>;
|
8305 | /**
|
8306 | * Indicates whether the fetch could have returned more results if it had not
|
8307 | * been constrained by the {@link FetchRequest.first first}, {@link
|
8308 | * FetchRequest.last last} or {@link FetchRequest.maximumResultSize
|
8309 | * maximumResultSize}
|
8310 | * limits.
|
8311 | *
|
8312 | * @return `true` if more results could have been returned,
|
8313 | * otherwise false
|
8314 | */
|
8315 | hasMore(): boolean;
|
8316 | /**
|
8317 | * The number of elements in the fetch result.
|
8318 | *
|
8319 | * @return the size of the results list
|
8320 | * @since 6.3
|
8321 | */
|
8322 | size(): number;
|
8323 | /**
|
8324 | * Returns `true` if the result contains zero elements.
|
8325 | *
|
8326 | * @return true if result list is empty
|
8327 | * @since 6.3
|
8328 | */
|
8329 | isEmpty(): boolean;
|
8330 | }
|
8331 | /**
|
8332 | * Encapsulates the result of a {@link FetchRequest.fetch
|
8333 | * fetch} invocation for a single selected topic.
|
8334 | *
|
8335 | * @param V the result value type. This will be any type unless the request
|
8336 | * indicated that {@link FetchRequest.withValues values}
|
8337 | * are to be returned, in which case this will be the data type
|
8338 | * requested.
|
8339 | *
|
8340 | * @since 6.2
|
8341 | */
|
8342 | export interface TopicResult<V = any> {
|
8343 | /**
|
8344 | * Returns the topic path.
|
8345 | *
|
8346 | * @return the topic path
|
8347 | */
|
8348 | path(): string;
|
8349 | /**
|
8350 | * Returns the topic type.
|
8351 | *
|
8352 | * @return the topic type
|
8353 | */
|
8354 | type(): TopicType;
|
8355 | /**
|
8356 | * Returns the topic value.
|
8357 | *
|
8358 | * This will only return a value if the fetch request specified {@link
|
8359 | * FetchRequest.withValues withValues} and the topic actually had a value.
|
8360 | * For topics that have no value this will return undefined.
|
8361 | *
|
8362 | * @return the topic value or undefined if none available
|
8363 | */
|
8364 | value(): V;
|
8365 | /**
|
8366 | * Returns the topic specification.
|
8367 | *
|
8368 | * If the request specified {@link FetchRequest.withProperties
|
8369 | * withProperties}, the result reflect the topic's specification and can be
|
8370 | * used to create an identical topic. If the request did not specify {@link
|
8371 | * FetchRequest.withProperties withProperties}, the specification's property
|
8372 | * map will be empty.
|
8373 | *
|
8374 | * @return {TopicSpecification} the topic specification
|
8375 | */
|
8376 | specification(): TopicSpecification;
|
8377 | }
|
8378 | /**
|
8379 | * @module diffusion.topics
|
8380 | */
|
8381 | /**
|
8382 | * Topic specifications provide the information required to create a topic.
|
8383 | * Topics can be created from a topic specification using
|
8384 | * {@link TopicControl.add}.
|
8385 | *
|
8386 | * Topic specifications allow an application to introspect the type and
|
8387 | * capabilities of a topic. Topic specifications are provided to
|
8388 | * {@link ValueStream ValueStreams} and {@link TopicNotificationListener topic
|
8389 | * notification listeners}.
|
8390 | *
|
8391 | * A topic is specified in terms of its {@link TopicType type}
|
8392 | * and a map of optional property settings which can alter the default behavior
|
8393 | * of the topic.
|
8394 | *
|
8395 | * <h4>Topic Properties</h4>
|
8396 | *
|
8397 | * Depending on the topic type, some properties must be included in the
|
8398 | * specification when creating a topic and some properties have no effect. All
|
8399 | * topic specification property values must be supplied as strings.
|
8400 | *
|
8401 | * The required and optional properties for each topic type are set out in the following table.
|
8402 | *
|
8403 | * <table style="width: 100%">
|
8404 | * <tr>
|
8405 | * <th></th>
|
8406 | * <th>{@link TopicTypeEnum.STRING STRING}<br/>
|
8407 | * {@link TopicTypeEnum.JSON JSON}<br/>
|
8408 | * {@link TopicTypeEnum.BINARY BINARY}<br/>
|
8409 | * </th>
|
8410 | * <th>{@link TopicTypeEnum.DOUBLE DOUBLE}<br/>
|
8411 | * {@link TopicTypeEnum.INT64 INT64}</th>
|
8412 | * <th>{@link TopicTypeEnum.ROUTING ROUTING}<br/>
|
8413 | * <th>{@link TopicTypeEnum.SLAVE SLAVE}<br>deprecated</th>
|
8414 | * <th>{@link TopicTypeEnum.TIME_SERIES TIME_SERIES}</th>
|
8415 | * <th>{@link TopicTypeEnum.RECORD_V2 RECORD_V2}</th>
|
8416 | * </tr>
|
8417 | * <tr>
|
8418 | * <th>{@link TopicSpecification.COMPRESSION COMPRESSION}</th>
|
8419 | * <td>Optional</td>
|
8420 | * <td>-</td>
|
8421 | * <td>Optional</td>
|
8422 | * <td>Optional</td>
|
8423 | * <td>Optional</td>
|
8424 | * <td>Optional</td>
|
8425 | * </tr>
|
8426 | * <tr>
|
8427 | * <th>{@link TopicSpecification.CONFLATION CONFLATION}</th>
|
8428 | * <td>Optional</td>
|
8429 | * <td>Optional</td>
|
8430 | * <td>Optional</td>
|
8431 | * <td>Optional</td>
|
8432 | * <td>Optional</td>
|
8433 | * <td>Optional</td>
|
8434 | * </tr>
|
8435 | * <tr>
|
8436 | * <th>{@link TopicSpecification.DONT_RETAIN_VALUE DONT_RETAIN_VALUE}</th>
|
8437 | * <td>Optional</td>
|
8438 | * <td>Optional</td>
|
8439 | * <td>—</td>
|
8440 | * <td>—</td>
|
8441 | * <td>Optional</td>
|
8442 | * <td>Optional</td>
|
8443 | * </tr>
|
8444 | * <tr>
|
8445 | * <th>{@link TopicSpecification.PUBLISH_VALUES_ONLY PUBLISH_VALUES_ONLY}</th>
|
8446 | * <td>Optional</td>
|
8447 | * <td>—</td>
|
8448 | * <td>—</td>
|
8449 | * <td>—</td>
|
8450 | * <td>Optional</td>
|
8451 | * <td>Optional</td>
|
8452 | * </tr>
|
8453 | * <tr>
|
8454 | * <th>{@link TopicSpecification.SCHEMA SCHEMA}</th>
|
8455 | * <td>—</td>
|
8456 | * <td>—</td>
|
8457 | * <td>—</td>
|
8458 | * <td>—</td>
|
8459 | * <td>—</td>
|
8460 | * <td>Optional</td>
|
8461 | * </tr>
|
8462 | * <tr>
|
8463 | * <th>{@link TopicSpecification.SLAVE_MASTER_TOPIC SLAVE_MASTER_TOPIC} (deprecated)</th>
|
8464 | * <td>—</td>
|
8465 | * <td>—</td>
|
8466 | * <td>—</td>
|
8467 | * <td>Required</td>
|
8468 | * <td>—</td>
|
8469 | * <td>—</td>
|
8470 | * </tr>
|
8471 | * <tr>
|
8472 | * <th>{@link TopicSpecification.TIDY_ON_UNSUBSCRIBE TIDY_ON_UNSUBSCRIBE}</th>
|
8473 | * <td>Optional</td>
|
8474 | * <td>Optional</td>
|
8475 | * <td>Optional</td>
|
8476 | * <td>Optional</td>
|
8477 | * <td>Optional</td>
|
8478 | * <td>Optional</td>
|
8479 | * </tr>
|
8480 | * <tr>
|
8481 | * <th>{@link TopicSpecification.TIME_SERIES_EVENT_VALUE_TYPE TIME_SERIES_EVENT_VALUE_TYPE}</th>
|
8482 | * <td>—</td>
|
8483 | * <td>—</td>
|
8484 | * <td>—</td>
|
8485 | * <td>—</td>
|
8486 | * <td>Required</td>
|
8487 | * <td>—</td>
|
8488 | * </tr>
|
8489 | * <tr>
|
8490 | * <th>{@link TopicSpecification.TIME_SERIES_RETAINED_RANGE TIME_SERIES_RETAINED_RANGE}</th>
|
8491 | * <td>—</td>
|
8492 | * <td>—</td>
|
8493 | * <td>—</td>
|
8494 | * <td>—</td>
|
8495 | * <td>Optional</td>
|
8496 | * <td>—</td>
|
8497 | * </tr>
|
8498 | * <tr>
|
8499 | * <th>{@link TopicSpecification.TIME_SERIES_SUBSCRIPTION_RANGE TIME_SERIES_SUBSCRIPTION_RANGE}</th>
|
8500 | * <td>—</td>
|
8501 | * <td>—</td>
|
8502 | * <td>—</td>
|
8503 | * <td>—</td>
|
8504 | * <td>Optional</td>
|
8505 | * </tr>
|
8506 | * <tr>
|
8507 | * <th>{@link TopicSpecification.VALIDATE_VALUES VALIDATE_VALUES}</th>
|
8508 | * <td>Optional</td>
|
8509 | * <td>Optional</td>
|
8510 | * <td>—</td>
|
8511 | * <td>—</td>
|
8512 | * <td>Optional</td>
|
8513 | * <td>—</td>
|
8514 | * </tr>
|
8515 | * <tr>
|
8516 | * <th>{@link TopicSpecification.PERSISTENT PERSISTENT}</th>
|
8517 | * <td>Optional</td>
|
8518 | * <td>Optional</td>
|
8519 | * <td>—</td>
|
8520 | * <td>—</td>
|
8521 | * <td>Optional</td>
|
8522 | * <td>—</td>
|
8523 | * </tr>
|
8524 | * <tr>
|
8525 | * <th>{@link TopicSpecification.PRIORITY PRIORITY}</th>
|
8526 | * <td>Optional</td>
|
8527 | * <td>-</td>
|
8528 | * <td>Optional</td>
|
8529 | * <td>Optional</td>
|
8530 | * <td>Optional</td>
|
8531 | * <td>Optional</td>
|
8532 | * </tr>
|
8533 | * <tr>
|
8534 | * <th>{@link TopicSpecification.REMOVAL REMOVAL}</th>
|
8535 | * <td>Optional</td>
|
8536 | * <td>Optional</td>
|
8537 | * <td>—</td>
|
8538 | * <td>—</td>
|
8539 | * <td>Optional</td>
|
8540 | * <td>—</td>
|
8541 | * </tr>
|
8542 | * <tr>
|
8543 | * <th>{@link TopicSpecification.OWNER OWNER}</th>
|
8544 | * <td>Optional</td>
|
8545 | * <td>Optional</td>
|
8546 | * <td>—</td>
|
8547 | * <td>—</td>
|
8548 | * <td>Optional</td>
|
8549 | * <td>—</td>
|
8550 | * </tr>
|
8551 | * </table>
|
8552 | *
|
8553 | * `TIME_SERIES` topics have restricted values for the
|
8554 | * `CONFLATION` property. They are only allowed to have the values
|
8555 | * `off` or `unsubscribe`.
|
8556 | *
|
8557 | * `ROUTING` and `SLAVE` topics are references to other topics,
|
8558 | * and have no value of their own. Instead, they reflect the value of the
|
8559 | * appropriate source topic. Observed behavior depends on the values of the
|
8560 | * `DONT_RETAIN_VALUE`, `PUBLISH_VALUES_ONLY`, and
|
8561 | * `VALIDATE_VALUES` properties that are set on the source topic.
|
8562 | *
|
8563 | */
|
8564 | export declare class TopicSpecification {
|
8565 | /**
|
8566 | * Key of the topic property that specifies whether a topic should publish
|
8567 | * only values.
|
8568 | *
|
8569 | * By default, a topic that supports delta streams will publish the
|
8570 | * difference between two values (a delta) when doing so is more efficient
|
8571 | * than to publishing the complete new value. Subscribing sessions can use a
|
8572 | * {@link ValueStream} to automatically apply the delta to a
|
8573 | * local copy of the topic value to calculate the new value.
|
8574 | *
|
8575 | * Setting PUBLISH_VALUES_ONLY to `'true'` disables this behavior so that
|
8576 | * deltas are never published. Doing so is not recommended because it will
|
8577 | * result in more data being transmitted and less efficient use of network
|
8578 | * resources. Reasons to consider setting the value to 'true' include
|
8579 | * compatibility with older client libraries that do not support delta
|
8580 | * streams; to simplify applications that use topic streams and do not wish
|
8581 | * to deal with the complexities of delta processing (it would be better for
|
8582 | * such an application to use a {@link ValueStream}); and to disable
|
8583 | * delta streams to investigate their performance benefits.
|
8584 | *
|
8585 | */
|
8586 | static readonly PUBLISH_VALUES_ONLY: string;
|
8587 | /**
|
8588 | * Key of the topic property indicating whether a topic should validate
|
8589 | * inbound values.
|
8590 | *
|
8591 | * By default, the server does not validate received values before sending
|
8592 | * them on to client sessions. Invalid or corrupt values will be stored in
|
8593 | * the topic and passed on to sessions. If this property is set to `'true'`,
|
8594 | * the server will perform additional validation on values to check that
|
8595 | * they are valid instances of the data type, and if it is not then it will
|
8596 | * return an error to the updater and not update the topic.
|
8597 | *
|
8598 | * If this value is not set (or set to something other than `'true'`), no
|
8599 | * server validation of inbound values is performed. This is the recommended
|
8600 | * setting as there is a performance overhead to validation and values
|
8601 | * produced through the {@link DataTypes data type} API will not
|
8602 | * be invalid anyway.
|
8603 | */
|
8604 | static readonly VALIDATE_VALUES: string;
|
8605 | /**
|
8606 | * Key of the topic property that specifies the master topic path for a
|
8607 | * {@link TopicTypeEnum.SLAVE slave} topic.
|
8608 | *
|
8609 | * When creating a slave topic using a topic specification then this must be
|
8610 | * specified. For all other topic types it is ignored.
|
8611 | *
|
8612 | * @since 6.0
|
8613 | *
|
8614 | *
|
8615 | * @deprecated Since 6.4
|
8616 | * <p>
|
8617 | * Slave topics are deprecated. This property key will be
|
8618 | * removed in a future release.
|
8619 | */
|
8620 | static readonly SLAVE_MASTER_TOPIC: string;
|
8621 | /**
|
8622 | * Key of the topic property that specifies the 'tidy on unsubscribe' option
|
8623 | * for a topic.
|
8624 | *
|
8625 | * By default, if a session unsubscribes from a topic, it will receive any
|
8626 | * updates for that topic that were previously queued but not sent.
|
8627 | *
|
8628 | * If this property is set to `'true'`, when a session unsubscribes from the
|
8629 | * topic, any updates for the topic that are still queued for the session
|
8630 | * are removed. There is a performance overhead to using this option as the
|
8631 | * client queue must be scanned to find topic updates to remove, however it
|
8632 | * may prove useful for preventing unwanted data being sent to sessions.
|
8633 | *
|
8634 | * @since 6.0
|
8635 | */
|
8636 | static readonly TIDY_ON_UNSUBSCRIBE: string;
|
8637 | /**
|
8638 | * Key of the topic property that specifies the event data type for a time
|
8639 | * series topic.
|
8640 | *
|
8641 | * The value is the {@link DataType.name type name} of a
|
8642 | * data type.
|
8643 | *
|
8644 | * @since 6.0
|
8645 | */
|
8646 | static readonly TIME_SERIES_EVENT_VALUE_TYPE: string;
|
8647 | /**
|
8648 | * Key of the topic property that specifies the range of events retained by
|
8649 | * a time series topic.
|
8650 | *
|
8651 | * When a new event is added to the time series, older events that fall
|
8652 | * outside of the range are discarded.
|
8653 | *
|
8654 | * If the property is not specified, a time series topic will retain the ten
|
8655 | * most recent events.
|
8656 | *
|
8657 | * <h4>Time series range expressions</h4>
|
8658 | *
|
8659 | * The property value is a time series <em>range expression</em> string
|
8660 | * composed of one or more constraint clauses. Constraints are combined to
|
8661 | * provide a range of events from the end of the time series.
|
8662 | *
|
8663 | * <dl>
|
8664 | * <dt>limit constraint
|
8665 | * <dd>A limit constraint specifies the maximum number of events from the
|
8666 | * end of the time series.
|
8667 | * <dt>last clause
|
8668 | * <dd>A last constraint specifies the maximum duration of events from the
|
8669 | * end of the time series. The duration is expressed as an integer followed
|
8670 | * by one of the following time units. <br>
|
8671 | * <br>
|
8672 | * <code>MS</code> – milliseconds; <br>
|
8673 | * <code>S</code> – seconds; <br>
|
8674 | * <code>H</code> – hours.
|
8675 | * </dl>
|
8676 | *
|
8677 | * If a range expression contains multiple constraints, the constraint that
|
8678 | * selects the smallest range is used.
|
8679 | *
|
8680 | * Property value | Meaning
|
8681 | * --------------- | ---------
|
8682 | * `limit 5` | The five most recent events
|
8683 | * `last 10s` | All events that are no more than ten seconds older than the latest event
|
8684 | * `last 10s limit 5` | The five most recent events that are no more than ten seconds older than the latest event
|
8685 | *
|
8686 | * Range expressions are not case sensitive: `limit 5 last 10s` is
|
8687 | * equivalent to `LIMIT 5 LAST 10S`.
|
8688 | *
|
8689 | * @since 6.0
|
8690 | */
|
8691 | static readonly TIME_SERIES_RETAINED_RANGE: string;
|
8692 | /**
|
8693 | * Key of the topic property that specifies the range of time series topic
|
8694 | * events to send to new subscribers.
|
8695 | *
|
8696 | * The property value is a time series range expression, following the
|
8697 | * format used for {@link TopicSpecification.TIME_SERIES_RETAINED_RANGE
|
8698 | * TIME_SERIES_RETAINED_RANGE}.
|
8699 | *
|
8700 | * If the property is not specified, new subscribers will be sent the latest
|
8701 | * event if delta streams are enabled and no events if delta streams are
|
8702 | * disabled. See the description of <em>Subscription range</em> in the
|
8703 | * {@link TimeSeries time series feature} documentation.
|
8704 | *
|
8705 | * @since 6.0
|
8706 | */
|
8707 | static readonly TIME_SERIES_SUBSCRIPTION_RANGE: string;
|
8708 | /**
|
8709 | * Key of the topic property that specifies a schema which constrains topic
|
8710 | * values.
|
8711 | *
|
8712 | * This property is only used by {@link TopicTypeEnum.RECORD_V2
|
8713 | * RECORD_V2} topics. The value is converted to a Diffusion record schema
|
8714 | * using {@link RecordV2DataType.parseSchema}.
|
8715 | *
|
8716 | * @since 6.0
|
8717 | */
|
8718 | static readonly SCHEMA: string;
|
8719 | /**
|
8720 | * Key of the topic property that specifies a topic should not retain
|
8721 | * its last value. Setting this property to `'true'` allows the topic to behave
|
8722 | * like a stateless topic, while retaining other properties such as its data
|
8723 | * type.
|
8724 | *
|
8725 | * By default, a topic (other than a `SLAVE`, or `ROUTING` topic) will
|
8726 | * retain its latest value. The latest value will be sent to new
|
8727 | * subscribers. Setting this property to `'true'` disables this behavior. New
|
8728 | * subscribers will not be sent an initial value. No value will be returned
|
8729 | * for fetch operations that select the topic. This is useful for data
|
8730 | * streams where the values are only transiently valid.
|
8731 | *
|
8732 | * Setting DONT_RETAIN_VALUE to `'true'` disables delta streams, regardless of
|
8733 | * the {@link TopicSpecification.PUBLISH_VALUES_ONLY
|
8734 | * PUBLISH_VALUES_ONLY} value. If subsequent values are likely to be
|
8735 | * related, delta streams can provide a performance benefit. Consider not
|
8736 | * setting this property to benefit from delta streams, even if there is no
|
8737 | * other requirement to retain the last value.
|
8738 | *
|
8739 | * Setting this property affects the default subscription range of a time
|
8740 | * series topic. If set to `'true'`, the default subscription range will
|
8741 | * not provide an initial event to new subscribers. The default
|
8742 | * subscription range can be overridden with the {@link TopicSpecification.TIME_SERIES_SUBSCRIPTION_RANGE
|
8743 | * TIME_SERIES_SUBSCRIPTION_RANGE} property. Regardless of whether
|
8744 | * DONT_RETAIN_VALUE is set, a time series topic will continue to
|
8745 | * record events according to the {@link TopicSpecification.TIME_SERIES_RETAINED_RANGE
|
8746 | * TIME_SERIES_RETAINED_RANGE} property.
|
8747 | *
|
8748 | * @since 6.0
|
8749 | */
|
8750 | static readonly DONT_RETAIN_VALUE: string;
|
8751 | /**
|
8752 | * Key of the topic property that can be used to prevent a topic from being
|
8753 | * persisted when the server is configured to enable persistence.
|
8754 | *
|
8755 | * By default, a topic will be persisted if persistence is enabled at the
|
8756 | * server and the topic type supports persistence.
|
8757 | *
|
8758 | * Setting PERSISTENT to `'false'` will prevent the topic from being
|
8759 | * persisted.
|
8760 | *
|
8761 | * @since 6.1
|
8762 | */
|
8763 | static readonly PERSISTENT: string;
|
8764 | /**
|
8765 | * Key of the topic property that specifies a removal policy for automatic
|
8766 | * removal of the topic (and/or other topics).
|
8767 | *
|
8768 | * This property is specified as an expression which defines one or more
|
8769 | * conditions that are to be satisfied before automatic removal occurs.
|
8770 | *
|
8771 | * The expression takes the form:
|
8772 | *
|
8773 | * <code>
|
8774 | * when <i>conditions</i> [remove '<i>selector</i>']
|
8775 | * </code>
|
8776 | *
|
8777 | * At least one condition must be supplied. If more than one is supplied,
|
8778 | * they must be separated by logical operators (`and` or `or`).
|
8779 | * The natural evaluation order of the operators may be changed by
|
8780 | * surrounding with parentheses (e.g. (<i>condition</i> `and`
|
8781 | * <i>condition</i>)).
|
8782 | *
|
8783 | * The `remove` clause is optional. It provides a {@link TopicSelector}
|
8784 | * expression representing the topics to be removed. If a `remove` clause is
|
8785 | * specified, the topic with the removal policy will only be removed if its
|
8786 | * path matches the selector expression. The selector must be surrounded by
|
8787 | * either double or single quotes.
|
8788 | *
|
8789 | * The permissions that are applied at the time of removal are those defined
|
8790 | * by the roles of the principal that created the topic at the time of
|
8791 | * creation. The roles of that principal may therefore change before the
|
8792 | * removal with no effect, but if the permissions given to the roles change
|
8793 | * it may have an effect upon the final removal.
|
8794 | *
|
8795 | * Only one occurrence of each of the following condition types may be
|
8796 | * included within the expression:
|
8797 | * <table style="width: 100%">
|
8798 | * <tr>
|
8799 | * <th align="left">Condition Type</th>
|
8800 | * <th align="left">Format</th>
|
8801 | * <th align="left">Usage</th>
|
8802 | * </tr>
|
8803 | * <tr valign="top">
|
8804 | * <th align="left"><b>time after</b></th>
|
8805 | * <td><code>time after <i>absoluteTime</i></code></td>
|
8806 | * <td>Removal should occur after a specified absolute time. Absolute time
|
8807 | * may be specified as a number of milliseconds since the epoch (00:00:00 on
|
8808 | * 1 January 1970) <b>or</b> as a quoted date and time formatted in <a href=
|
8809 | * "https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#RFC_1123_DATE_TIME">RFC_1123
|
8810 | * date time format</a>. Either single or double quotes may be used.</td>
|
8811 | * </tr>
|
8812 | * <tr valign="top">
|
8813 | * <th align="left"><b>subscriptions less than</b></th>
|
8814 | * <td><code>subscriptions < <i>n</i> for <i>forPeriod</i> [after <i>afterPeriod</i>]</code></td>
|
8815 | * <td>Removal should occur when the topic has had less than the specified
|
8816 | * number (<i>n</i>) of subscriptions for a given period (<i>forPeriod</i>)
|
8817 | * of time. Optionally, an initial period (<i>afterPeriod</i>) may be
|
8818 | * specified by which to delay the initial checking of this condition. See
|
8819 | * below for period formats.</td>
|
8820 | * </tr>
|
8821 | * <tr valign="top">
|
8822 | * <th align="left"><b>no updates for</b></th>
|
8823 | * <td><code>no updates for <i>forPeriod</i> [after <i>afterPeriod</i>]</code></td>
|
8824 | * <td>Removal should occur when the topic has had no updates for a given
|
8825 | * period (<i>forPeriod</i>) of time. Optionally, an initial period
|
8826 | * (<i>afterPeriod</i>) may be specified by which to delay the initial
|
8827 | * checking of this condition. See below for period formats.</td>
|
8828 | * </tr>
|
8829 | * <tr valign="top">
|
8830 | * <th align="left"><b>no session has</b></th>
|
8831 | * <td><code>no session has <i>'criteria'</i> [for <i>forPeriod</i>] [after <i>afterPeriod</i>]</code></td>
|
8832 | * <td>Removal should occur when no sessions satisfy certain <i>criteria</i>.
|
8833 | * Optionally the criteria can be required to be satisfied for a period of time
|
8834 | * (<i>forPeriod</i>). Optionally, an initial period (<i>afterPeriod</i>) can
|
8835 | * be specified to delay the initial check of the criteria. Session selection
|
8836 | * criteria are specified as defined in {@link Session session filters} and
|
8837 | * must be surrounded by single or double quotes. See below for period formats.</td>
|
8838 | * </tr>
|
8839 | * <tr valign="top">
|
8840 | * <th></th>
|
8841 | * <td>`this session closes`</td>
|
8842 | * <td>This is a shorthand form of 'no session has' that may be used to
|
8843 | * indicate that the topic is to be removed when the session that created it
|
8844 | * closes.</td>
|
8845 | * </tr>
|
8846 | * </table>
|
8847 | *
|
8848 | * Time periods are specified as a number followed (with no intermediate
|
8849 | * space) by a single letter representing the time unit. The time unit may
|
8850 | * be 's' (seconds), 'm' (minutes), 'h' (hours) or 'd' (days). For example,
|
8851 | * 10 minutes would be specified as 10m.
|
8852 | *
|
8853 | * If quotes or backslashes (\) are required within quoted values such as
|
8854 | * selectors or session criteria then they may be escaped by preceding with
|
8855 | * \. The convenience method {@link escape} is provided to
|
8856 | * escape such characters in a value. The expression is validated only by
|
8857 | * the server and therefore if an invalid expression is specified it will be
|
8858 | * reported as an Error.
|
8859 | *
|
8860 | * **Examples:**
|
8861 | *
|
8862 | * ```
|
8863 | * when time after 1518780068112
|
8864 | * ```
|
8865 | *
|
8866 | * The topic will be removed when the date and time indicated by the
|
8867 | * specified number of milliseconds since the epoch has passed.
|
8868 | *
|
8869 | * ```
|
8870 | * when time after 'Tue, 3 Jun 2018 11:05:30 GMT'
|
8871 | * ```
|
8872 | *
|
8873 | * The topic will be removed when the specified date and time has passed.
|
8874 | *
|
8875 | * ```
|
8876 | * when time after 'Tue, 3 Jun 2018 11:05:30 GMT' remove '*alpha/beta//'
|
8877 | * ```
|
8878 | *
|
8879 | * The topic alpha/beta and all topics subordinate to it will be removed
|
8880 | * when the specified date and time has passed.
|
8881 | *
|
8882 | * ```
|
8883 | * when subscriptions < 1 for 20m
|
8884 | * ```
|
8885 | *
|
8886 | * The topic will be removed when it has had no subscriptions for a
|
8887 | * continuous period of 20 minutes.
|
8888 | *
|
8889 | * ```
|
8890 | * when subscriptions < 2 for 20m after 1h
|
8891 | * ```
|
8892 | *
|
8893 | * The topic will be removed when it has had less than 2 subscriptions for a
|
8894 | * continuous period of 20 minutes after one hour has passed since its
|
8895 | * creation.
|
8896 | *
|
8897 | * ```
|
8898 | * when no updates for 3h
|
8899 | * ```
|
8900 | *
|
8901 | * The topic will be removed when it has had no updates for a continuous
|
8902 | * period of 3 hours.
|
8903 | *
|
8904 | * ```
|
8905 | * when no updates for 15m after 1d
|
8906 | * ```
|
8907 | *
|
8908 | * The topic will be removed when it has had no updates for a continuous
|
8909 | * period of 15 minutes after one day has passed since its creation.
|
8910 | *
|
8911 | * ```
|
8912 | * when this session closes
|
8913 | * ```
|
8914 | *
|
8915 | * The topic will be removed when the session that created it closes.
|
8916 | *
|
8917 | * ```
|
8918 | * when no session has '$Principal is "Alice"'
|
8919 | * ```
|
8920 | *
|
8921 | * The topic will be removed when there is no session with the principal 'Alice'.
|
8922 | *
|
8923 | * ```
|
8924 | * when no session has '$Principal is "Alice"' for 10m
|
8925 | * ```
|
8926 | *
|
8927 | * The topic will be removed when there have been no sessions with the principal
|
8928 | * 'Alice' for a continuous period of 10 minutes.
|
8929 | *
|
8930 | * ```
|
8931 | * when no session has 'Department is "Accounts"' for 30m after 2h
|
8932 | * ```
|
8933 | *
|
8934 | * The topic will be removed when there have been no sessions from the Account
|
8935 | * department for a continuous period of 30 minutes after 2 hours have passed
|
8936 | * since its creation.
|
8937 | *
|
8938 | * ```
|
8939 | * when time after "Tue, 3 Jun 2018 11:05:30 GMT" and subscriptions < 1 for 30m
|
8940 | * ```
|
8941 | *
|
8942 | * The topic will be removed when the specified date and time has passed and
|
8943 | * the topic has had no subscriptions for a continuous period of 30 minutes
|
8944 | * after that time.
|
8945 | *
|
8946 | * ```
|
8947 | * when time after "Tue, 3 Jun 2018 11:05:30 GMT" and subscriptions < 2 for 10m after 1h
|
8948 | * ```
|
8949 | *
|
8950 | * The topic will be removed when the specified date and time has passed and
|
8951 | * the topic has had less than 2 subscriptions for a continuous period of 10
|
8952 | * minutes after that time plus one hour.
|
8953 | *
|
8954 | * ```
|
8955 | * when time after "Tue, 3 Jun 2018 11:05:30 GMT" or subscriptions < 2 for 10m after 1h
|
8956 | * ```
|
8957 | *
|
8958 | * The topic will be removed when the specified date and time has passed or
|
8959 | * the topic has had less than 2 subscriptions for a continuous period of 10
|
8960 | * minutes after one hour from its creation.
|
8961 | *
|
8962 | * ```
|
8963 | * when time after "Tue, 3 Jun 2018 11:05:30 GMT" and (subscriptions < 2 for 10m after 1h or no updates for 20m)
|
8964 | * ```
|
8965 | *
|
8966 | * The topic will be removed when the specified date and time has passed and
|
8967 | * either the topic has had less than 2 subscriptions for a continuous
|
8968 | * period of 10 minutes after that time plus one hour or it has had no
|
8969 | * updates for a continuous period of 20 minutes. Note that the parentheses
|
8970 | * are significant here as without them the topic would be removed if it had
|
8971 | * had no updates for 20 minutes regardless of the time and subscriptions
|
8972 | * clause.
|
8973 | *
|
8974 | * **Notes and restrictions on use**
|
8975 | *
|
8976 | * The `after` time periods refer to the period since the topic was
|
8977 | * created or restored from persistence store after a server is restarted.
|
8978 | * They are designed as a 'grace' period after the topic comes into
|
8979 | * existence before the related conditions starts to be evaluated. When not
|
8980 | * specified the conditions start to be evaluated as soon as the topic is
|
8981 | * created or restored.
|
8982 | *
|
8983 | * The server will evaluate conditions on a periodic basis (every few
|
8984 | * seconds) so the exact removal time will not be precise for low periodic
|
8985 | * granularity.
|
8986 | *
|
8987 | * The meaning of the `for` period on `no session has`
|
8988 | * conditions is subtly different from on other conditions. It does not
|
8989 | * guarantee that there has been no session satisfying the condition at some
|
8990 | * point between evaluations, only that when evaluated the given period of
|
8991 | * time has passed since it was last evaluated and found to have no matching
|
8992 | * sessions.
|
8993 | *
|
8994 | * Automatic topic removal is supported for both replicated topics and topics
|
8995 | * fanned out to secondary servers using the fan-out feature. A
|
8996 | * 'subscriptions less than' condition for such topics will be evaluated
|
8997 | * against the total number of subscriptions to the topic across the cluster
|
8998 | * and on all downstream secondary servers. A 'no session has' condition will
|
8999 | * consider all sessions hosted across a cluster and hosted by downstream
|
9000 | * secondary servers.
|
9001 | *
|
9002 | * @since 6.1
|
9003 | */
|
9004 | static readonly REMOVAL: string;
|
9005 | /**
|
9006 | * Key of the topic property that specifies the conflation policy of the
|
9007 | * topic. The policy specifies how the server manages queued topic updates.
|
9008 | * Conflation is applied individually to each session queue.
|
9009 | *
|
9010 | * Conflation is the process of merging or discarding topic updates queued
|
9011 | * for a session to reduce the server memory footprint and network data. The
|
9012 | * server will conflate sessions that have a large number of queued messages
|
9013 | * to meet configured queue size targets. The sessions with the largest
|
9014 | * queues are typically slow consumers or have been disconnected – both will
|
9015 | * benefit from conflation. This property allows conflation behavior to be
|
9016 | * tuned on a topic-by-topic basis.
|
9017 | *
|
9018 | * The supported policies are:
|
9019 | *
|
9020 | * * `off`
|
9021 | * * `conflate`
|
9022 | * * `unsubscribe`
|
9023 | * * `always`
|
9024 | *
|
9025 | * The default policy used when the property is not specified and the topic
|
9026 | * type is not time series is `conflate`. The default policy used when the
|
9027 | * property is not specified and the topic type is time series is `off`.
|
9028 | *
|
9029 | * The policy `off` disables conflation for the topic. This policy
|
9030 | * disables all conflation for the topic, so topic updates will never be
|
9031 | * merged or discarded.
|
9032 | *
|
9033 | * The policy `conflate` automatically conflates topic updates when
|
9034 | * back pressure is detected by the server.
|
9035 | *
|
9036 | * The policy `unsubscribe` automatically unsubscribes the topic when
|
9037 | * back pressure is detected by the server. The unsubscription is not
|
9038 | * persisted to the cluster. If a session fails over to a different server
|
9039 | * it will be resubscribed to the topic.
|
9040 | *
|
9041 | * The policy `always` automatically conflates topic updates as they
|
9042 | * are queued for the session. This is an eager policy that ensures only the
|
9043 | * latest update is queued for the topic, minimising the server memory and
|
9044 | * network bandwidth used by the session.
|
9045 | *
|
9046 | * The `conflate` and `unsubscribe` policies are applied when
|
9047 | * the server detects back pressure for a session. The server configuration
|
9048 | * places limits on the data queued for each session. If these limits are
|
9049 | * breached, the server will conflate the session queue to attempt to reduce
|
9050 | * its size. If the session queue still exceeds the limits after conflation,
|
9051 | * the session will be terminated.
|
9052 | *
|
9053 | * Conflation can be disabled on a session-by-session basis. If conflation is
|
9054 | * disabled for a session the policy will not be applied to topic updates
|
9055 | * queued for the session but will be for other sessions that have conflation
|
9056 | * enabled.
|
9057 | *
|
9058 | * The policies `conflate` and `always` are not supported for
|
9059 | * time series topics as they would cause missing events. Attempts to enable
|
9060 | * these policies with time series topics will cause the creation of the
|
9061 | * topic to fail, reporting that the specification is invalid.
|
9062 | *
|
9063 | * @since 6.2
|
9064 | */
|
9065 | static readonly CONFLATION: string;
|
9066 | /**
|
9067 | * Key of the topic property that allows the creator of a topic to extend
|
9068 | * READ_TOPIC, MODIFY_TOPIC, and UPDATE_TOPIC permissions to a specific
|
9069 | * principal, in addition to the permissions granted by the authorisation
|
9070 | * rules in the security store.
|
9071 | *
|
9072 | * A session that has authenticated using the principal can update and
|
9073 | * remove the topic, so the principal can be considered the topic owner. To
|
9074 | * fetch or subscribe to the topic, the principal must also be granted
|
9075 | * SELECT_TOPIC by the security store rules.
|
9076 | *
|
9077 | * This may be used in the following cases:
|
9078 | * 1) A session creates a topic and makes its own principal the owner.
|
9079 | * 2) A session creates a topic and makes another principal the owner.
|
9080 | *
|
9081 | * The format of the property value is:
|
9082 | *
|
9083 | * `$Principal is "<i>name</i>"`
|
9084 | *
|
9085 | * where <i>name</i> is the name of the principal. Single quotes may be used
|
9086 | * instead of double quotes and special characters can be escaped using
|
9087 | * {@link escape} if required.
|
9088 | *
|
9089 | * The purpose of this property is to allow a client to create topics on
|
9090 | * behalf of other users. This can be used in conjunction with the
|
9091 | * {@link REMOVAL} property so that such topics are removed when there are
|
9092 | * no longer any sessions for the named principal.
|
9093 | *
|
9094 | * **Example:**
|
9095 | * ```
|
9096 | * specification.withProperty(diffusion.topics.TopicSpecification.OWNER,
|
9097 | * "$Principal is 'myPrincipal'")
|
9098 | * .withProperty(diffusion.topics.TopicSpecification.REMOVAL,
|
9099 | * "when no session has '$Principal is \"myPrincipal\"' for 5s");
|
9100 | * ```
|
9101 | *
|
9102 | * @since 6.1
|
9103 | */
|
9104 | static readonly OWNER: string;
|
9105 | /**
|
9106 | * Key of the topic property that allows the compression policy to be set
|
9107 | * on a per-topic basis.
|
9108 | *
|
9109 | * Compression reduces the bandwidth required to broadcast topic updates to
|
9110 | * subscribed sessions, at the cost of increased server CPU.
|
9111 | *
|
9112 | * Changes to a topic's value are published to each subscribed session as a
|
9113 | * sequence of topic messages. A topic message can carry the latest value or
|
9114 | * the difference between the latest value and the previous value (a delta).
|
9115 | * The compression policy determines if and how published topic messages
|
9116 | * are compressed. Topic messages are not exposed through the client API;
|
9117 | * the client library handles decompression and decodes deltas
|
9118 | * automatically, passing reconstructed values to the application.
|
9119 | *
|
9120 | * The compression policy for a topic is specified by setting this property
|
9121 | * to one of several values:
|
9122 | *
|
9123 | * * `off`
|
9124 | * * `low`
|
9125 | * * `medium`
|
9126 | * * `high`
|
9127 | *
|
9128 | * The policies are listed in the order of increasing compression and
|
9129 | * increasing CPU cost. `off` disables compression completely for the
|
9130 | * topic and requires no additional CPU; `high` compresses the topic
|
9131 | * messages to the smallest number of bytes, but has the highest CPU cost.
|
9132 | * Generally some compression is beneficial, so the default value for this
|
9133 | * property is `low`.
|
9134 | *
|
9135 | * Prior to version 6.4, only two values were allowed: `true`
|
9136 | * (equivalent to `medium`, and the previous default policy) and
|
9137 | * `false` (equivalent to `off`). These values are still
|
9138 | * supported.
|
9139 | *
|
9140 | * This property is only one factor that determines whether a topic message
|
9141 | * will be compressed. Other factors include:
|
9142 | *
|
9143 | * * Compression must be enabled in the server configuration.
|
9144 | *
|
9145 | * * The client library must support the server's compression
|
9146 | * scheme. In this release, the server supports zlib
|
9147 | * compression, and also allows compression to be disabled on a
|
9148 | * per-connector basis. From 6.4, all client libraries are
|
9149 | * capable of zlib compression. A JavaScript client may or may
|
9150 | * not support zlib compression, depending on whether the zlib
|
9151 | * library can be loaded. The zlib library is packaged
|
9152 | * separately to reduce the download size of the core library.
|
9153 | *
|
9154 | * @since 6.2
|
9155 | */
|
9156 | static readonly COMPRESSION: string;
|
9157 | /**
|
9158 | * Key of the topic property that specifies the topic delivery priority.
|
9159 | *
|
9160 | * The supported delivery priorities are:
|
9161 | *
|
9162 | * * `low`
|
9163 | * * `default`
|
9164 | * * `high`
|
9165 | *
|
9166 | * The delivery priority affects the order of topic updates sent to a
|
9167 | * subscribed client session. When there are multiple topic updates for
|
9168 | * topics with different priorities in a session's outbound queue, updates
|
9169 | * for `high` priority topics will be delivered first, followed by
|
9170 | * updates for `default` priority topics, followed by updates for
|
9171 | * `low` priority topics. Topic subscription and unsubscription
|
9172 | * notifications are also delivered according to the topic delivery
|
9173 | * priority.
|
9174 | *
|
9175 | * Using different delivery priorities is most beneficial when there is a
|
9176 | * large backlog of queued updates to deliver to a client session. On
|
9177 | * lightly loaded systems, updates typically remain in the outbound queue
|
9178 | * for a few milliseconds and so there is a lower chance of topic updates
|
9179 | * being reordered based on their priority. The backlog will be larger if
|
9180 | * the topic update rate is higher; the server or the client are more
|
9181 | * heavily loaded; the client session becomes temporarily disconnected; or
|
9182 | * if there is poor network connectivity between the server and the client.
|
9183 | *
|
9184 | * Messages from the server to the client that are not topic updates, for
|
9185 | * example ping requests and responses, are queued with the
|
9186 | * `default` delivery priority.
|
9187 | *
|
9188 | * @since 6.4
|
9189 | */
|
9190 | static readonly PRIORITY: string;
|
9191 | /**
|
9192 | * The topic type.
|
9193 | */
|
9194 | type: TopicType;
|
9195 | /**
|
9196 | * A map of the topic properties.
|
9197 | */
|
9198 | properties: {
|
9199 | [key: string]: string;
|
9200 | };
|
9201 | /**
|
9202 | * Create a new TopicSpecification
|
9203 | *
|
9204 | * @param type the topic type for this specification.
|
9205 | * @param properties the properties to use for this specification.
|
9206 | * @since 5.9
|
9207 | *
|
9208 | * **Example:**
|
9209 | *
|
9210 | * Properties can be set when creating the specification by passing an object
|
9211 | * ```
|
9212 | * // Create specification for JSON topics which validate update values on the server
|
9213 | * const TopicSpecification = diffusion.topics.TopicSpecification;
|
9214 | *
|
9215 | * var specification = new TopicSpecification(diffusion.topics.TopicType.JSON, {
|
9216 | * "VALIDATE_VALUES" : "true"
|
9217 | * });
|
9218 | * ```
|
9219 | *
|
9220 | * **Example:** <caption>New specifications can be created with additional properties</caption>
|
9221 | * ```
|
9222 | * // Create specification for JSON topics which validate update values on the server
|
9223 | * const TopicSpecification = diffusion.topics.TopicSpecification;
|
9224 | *
|
9225 | * var specification = new TopicSpecification(diffusion.topics.TopicType.JSON)
|
9226 | * .withProperty(TopicSpecification.VALIDATE_VALUES, "true");
|
9227 | * ```
|
9228 | */
|
9229 | constructor(type: TopicType, properties?: {
|
9230 | [key: string]: string;
|
9231 | });
|
9232 | /**
|
9233 | * Returns a new TopicSpecification with the specified property set to the supplied value.
|
9234 | * @param key the new property key
|
9235 | * @param value the new property value
|
9236 | * @returns a new TopicSpecification with the specified property set.
|
9237 | */
|
9238 | withProperty(key: string, value: string): TopicSpecification;
|
9239 | }
|
9240 | /**
|
9241 | * A topic type
|
9242 | */
|
9243 | export declare class TopicType {
|
9244 | /**
|
9245 | * The topic type ID
|
9246 | */
|
9247 | readonly id: number;
|
9248 | /**
|
9249 | * A flag indicating whether the topic type is stateful
|
9250 | */
|
9251 | readonly stateful: boolean;
|
9252 | /**
|
9253 | * A flag indicating whether the topic type is functional
|
9254 | */
|
9255 | readonly functional: boolean;
|
9256 | /**
|
9257 | * Create a new TopicType instance
|
9258 | *
|
9259 | * @param id the topic type ID
|
9260 | * @param stateful a flag indicating whether the topic type is stateful
|
9261 | * @param functional a flag indicating whether the topic type is functional
|
9262 | */
|
9263 | constructor(id: number, stateful: boolean, functional: boolean);
|
9264 | }
|
9265 | /**
|
9266 | * Enum containing possible Topic Types.
|
9267 | *
|
9268 | * **Example:**
|
9269 | * ```
|
9270 | * // Get a topic type for adding topics
|
9271 | * var topicType = diffusion.topics.TopicType.JSON;
|
9272 | *
|
9273 | * session.topics.add("foo", topicType);
|
9274 | * ```
|
9275 | */ export declare const TopicTypeEnum: {
|
9276 | [key: string]: TopicType;
|
9277 | };
|
9278 | /**
|
9279 | * A type containing information about the reason for an unsubscription
|
9280 | */
|
9281 | export declare class UnsubscribeReason {
|
9282 | /**
|
9283 | * The unsubscribe reason's id
|
9284 | */
|
9285 | readonly id?: number;
|
9286 | /**
|
9287 | * The unsubscribe reason's description
|
9288 | */
|
9289 | readonly reason: string;
|
9290 | /**
|
9291 | * Create a `UnsubscribeReason`
|
9292 | *
|
9293 | * @param id the unsubscribe reason's id
|
9294 | * @param reason the unsubscribe reason's description
|
9295 | */
|
9296 | constructor(id: number | undefined, reason: string);
|
9297 | }
|
9298 | /**
|
9299 | * Enum containing reasons that an unsubscription occurred.
|
9300 | *
|
9301 | * **Example:**
|
9302 | * ```
|
9303 | * // Use UnsubscribeReason to validate unsubscription notifications
|
9304 | * session.addStream('>foo', diffusion.datatypes.string())
|
9305 | * .on('unsubscribe', function(topic, specification, reason) {
|
9306 | * switch (reason) {
|
9307 | * case diffusion.topics.UnsubscribeReason.REMOVED :
|
9308 | * // Do something if the topic was removed
|
9309 | * default :
|
9310 | * // Do something else if the client was explicitly unsubscribed
|
9311 | * }
|
9312 | * });
|
9313 | * ```
|
9314 | */ export declare const UnsubscribeReasonEnum: {
|
9315 | [key: string]: UnsubscribeReason;
|
9316 | };
|
9317 | /**
|
9318 | * A type containing information about the reason for failure of an update
|
9319 | */
|
9320 | export declare class UpdateFailReason {
|
9321 | /**
|
9322 | * The update fail reason's id
|
9323 | */
|
9324 | readonly id?: number;
|
9325 | /**
|
9326 | * The update fail reason's description
|
9327 | */
|
9328 | readonly reason: string;
|
9329 | /**
|
9330 | * Create a `UpdateFailReason`
|
9331 | *
|
9332 | * @param id the update fail reason's id
|
9333 | * @param reason the update fail reason's description
|
9334 | */
|
9335 | constructor(id: number | undefined, reason: string);
|
9336 | }
|
9337 | /**
|
9338 | * The reason that a topic could not be updated.
|
9339 | *
|
9340 | * **Example:**
|
9341 | * ```
|
9342 | * session.topics.update('foo', 'bar').then(function() { ... }, function(err) {
|
9343 | * switch (err) {
|
9344 | * case diffusion.topics.UpdateFailReason.MISSING_TOPIC:
|
9345 | * ...
|
9346 | * case diffusion.topics.UpdateFailReason.EXCLUSIVE_UPDATER_CONFLICT:
|
9347 | * ...
|
9348 | * }
|
9349 | * });
|
9350 | * ```
|
9351 | */ export declare const UpdateFailReasonEnum: {
|
9352 | [key: string]: UpdateFailReason;
|
9353 | };
|
9354 | /**
|
9355 | * A type containing information about the reason for failure of adding a topic
|
9356 | */
|
9357 | export declare class TopicAddFailReason {
|
9358 | /**
|
9359 | * The topic add failure reason's id
|
9360 | */
|
9361 | readonly id?: number;
|
9362 | /**
|
9363 | * The topic add failure reason's description
|
9364 | */
|
9365 | readonly reason: string;
|
9366 | /**
|
9367 | * Create a `TopicAddFailReason`
|
9368 | *
|
9369 | * @param id the topic add failure reason's id
|
9370 | * @param reason the topic add failure reason's description
|
9371 | */
|
9372 | constructor(id: number | undefined, reason: string);
|
9373 | }
|
9374 | /**
|
9375 | * The reason that a topic could not be added.
|
9376 | *
|
9377 | * **Example:**
|
9378 | * ```
|
9379 | * session.topics.add('foo').then(function() { ... }, function(err) {
|
9380 | * switch (err) {
|
9381 | * case diffusion.topics.TopicAddFailReason.EXISTS:
|
9382 | * ...
|
9383 | * case diffusion.topics.TopicAddFailReason.INVALID_PATH:
|
9384 | * ...
|
9385 | * }
|
9386 | * });
|
9387 | * ```
|
9388 | *
|
9389 | */ export declare const TopicAddFailReasonEnum: {
|
9390 | [key: string]: TopicAddFailReason;
|
9391 | };
|
9392 | export interface TopicsNamespace {
|
9393 | FetchRequest: typeof FetchRequest;
|
9394 | TopicType: typeof TopicTypeEnum;
|
9395 | TopicSpecification: typeof TopicSpecification;
|
9396 | UnsubscribeReason: typeof UnsubscribeReasonEnum;
|
9397 | UpdateFailReason: typeof UpdateFailReasonEnum;
|
9398 | TopicAddFailReason: typeof TopicAddFailReasonEnum;
|
9399 | }
|
9400 | export declare const topicsNamespace: TopicsNamespace;
|
9401 | /**
|
9402 | * @module diffusion
|
9403 | */
|
9404 | /**
|
9405 | * An enum for the available log levels
|
9406 | *
|
9407 | * Accessible through `diffusion.LogLevel`.
|
9408 | */
|
9409 | export declare enum LogLevel {
|
9410 | trace = "trace",
|
9411 | debug = "debug",
|
9412 | info = "info",
|
9413 | warn = "warn",
|
9414 | error = "error",
|
9415 | silent = "silent",
|
9416 | }
|
9417 | /// <reference types="node" />
|
9418 | /**
|
9419 | * @module diffusion.datatypes
|
9420 | */
|
9421 | /**
|
9422 | * Binary data type.
|
9423 | *
|
9424 | * Accessed via:
|
9425 | * `diffusion.datatypes.binary();`
|
9426 | *
|
9427 | * The implementation provides support for binary deltas.
|
9428 | *
|
9429 | * {@link Binary} values can be used to store and transmit arbitrary
|
9430 | * information. The responsibility for formatting and interpreting the
|
9431 | * information belongs solely to the application. Before using Binary for a
|
9432 | * topic, consider other data types such as {@link JSON JSON} or
|
9433 | * single value topic types; these may provide a simpler interface for
|
9434 | * your application.
|
9435 | *
|
9436 | * @since 5.7
|
9437 | */
|
9438 | export interface BinaryDataType extends DataType<Binary, Buffer | Binary, Binary> {
|
9439 | /**
|
9440 | * The Binary data type value class
|
9441 | */
|
9442 | Binary: new (value: Buffer) => Binary;
|
9443 | /**
|
9444 | * Returns a new {@link Binary} instance from a buffer.
|
9445 | *
|
9446 | * @param {Buffer} buffer - The binary data
|
9447 | * @return {diffusion.datatypes.Binary} a Binary data-type instance
|
9448 | *
|
9449 | * @function diffusion.datatypes.BinaryDataType#from
|
9450 | */
|
9451 | from(buffer: Buffer): Binary;
|
9452 | }
|
9453 | /**
|
9454 | * @module diffusion.datatypes
|
9455 | */
|
9456 | /**
|
9457 | * Delta that represents the difference between two binary values.
|
9458 | *
|
9459 | * @since 5.7
|
9460 | */
|
9461 | export interface BinaryDelta {
|
9462 | /**
|
9463 | * Whether this delta contains any changes.
|
9464 | *
|
9465 | * @returns if the delta contains changes
|
9466 | */
|
9467 | hasChanges(): boolean;
|
9468 | }
|
9469 | /// <reference types="node" />
|
9470 | /**
|
9471 | * @module diffusion.datatypes
|
9472 | */
|
9473 | /**
|
9474 | * A read-only binary value with support for binary deltas.
|
9475 | *
|
9476 | * Values are effectively immutable. Instances can be backed by
|
9477 | * {@link BinaryDataType.from user-supplied buffers}.
|
9478 | * Once a Binary has been constructed around a buffer, care must
|
9479 | * be taken not to modify the data in the buffer because doing
|
9480 | * so would violate immutability.
|
9481 | *
|
9482 | * @since 5.7
|
9483 | */
|
9484 | export interface Binary extends Bytes {
|
9485 | /**
|
9486 | * Get the value as a Buffer.
|
9487 | *
|
9488 | * @return the buffer value
|
9489 | */
|
9490 | get(): Buffer;
|
9491 | /**
|
9492 | * Compare this Binary value with an earlier version to create a delta.
|
9493 | *
|
9494 | * Convenient equivalent to:
|
9495 | * `diffusion.datatypes.binary().deltaSupport(type).diff(original, this);`
|
9496 | *
|
9497 | * Buffers may also be provided as the value to diff instead of a {@link
|
9498 | * Binary} instance.
|
9499 | *
|
9500 | * **Example:**
|
9501 | * ```
|
9502 | * var delta = binaryValue.diff(Buffer.from('Hello world'));
|
9503 | * ```
|
9504 | *
|
9505 | * @param original the value to diff against this
|
9506 | * @param type the type of delta to generate (default: `binary`);
|
9507 | * @return a delta representing the difference between this and the provided value
|
9508 | */
|
9509 | diff(original: Binary | Buffer, type?: string): BinaryDelta;
|
9510 | /**
|
9511 | * Apply a delta to this Binary value to create a new value.
|
9512 | *
|
9513 | * Convenient equivalent to:
|
9514 | * `diffusion.datatypes.binary().deltaSupport(delta).apply(this, delta);`
|
9515 | *
|
9516 | * @param delta the binary delta to apply to this value
|
9517 | * @return a new instance derived from applying the delta to this value
|
9518 | * @throws an error if the delta is invalid
|
9519 | */
|
9520 | apply(delta: BinaryDelta): Binary;
|
9521 | }
|
9522 | /**
|
9523 | * @module diffusion.datatypes
|
9524 | */
|
9525 | /**
|
9526 | * JSON data type.
|
9527 | *
|
9528 | * Accessed via:
|
9529 | * `diffusion.datatypes.json();`
|
9530 | *
|
9531 | * The JSON Data Type provides {@link JSON} values, which
|
9532 | * are a wrapper around native JSON objects.
|
9533 | *
|
9534 | * For efficiency, the JSON value is serialized in binary form following
|
9535 | * the CBOR specification.
|
9536 | *
|
9537 | * The implementation provides support for binary deltas.
|
9538 | *
|
9539 | * JSON instances defer parsing of underlying binary data until required. If the
|
9540 | * data is not valid, an Error may be thrown when {@link JSON.get} is called.
|
9541 | *
|
9542 | * @since 5.7
|
9543 | */
|
9544 | export interface JSONDataType extends DataType<JSON, any, JSON> {
|
9545 | /**
|
9546 | * The JSON data type value class
|
9547 | */
|
9548 | JSON: new (value: any) => JSON;
|
9549 | /**
|
9550 | * Returns a new {@link JSON} instance from a native JS object.
|
9551 | *
|
9552 | * Passing a string will produce a JSON instance encoding a single string
|
9553 | * token. To produce a JSON datatype instance from a JSON string, use {@link
|
9554 | * JSONDataType.fromJsonString} instead.
|
9555 | *
|
9556 | * This is useful in cases where providing the raw value may be ambiguous
|
9557 | * for SDK methods that infer the datatype from provided arguments, such as
|
9558 | * {@link Messages.sendRequest}.
|
9559 | *
|
9560 | * **Example:**
|
9561 | * ```
|
9562 | * // Value from object
|
9563 | * var value = jsondatatype.from({
|
9564 | * foo : "bar",
|
9565 | * baz : [1, 2, 3]
|
9566 | * });
|
9567 | * ```
|
9568 | *
|
9569 | * **Example:**
|
9570 | * ```
|
9571 | * // Datatype instance from string
|
9572 | * var value = jsondatatype.from("this is a simple string");
|
9573 | * ```
|
9574 | *
|
9575 | * @param object the object data
|
9576 | * @return a JSON data-type instance
|
9577 | */
|
9578 | from(object: any): JSON;
|
9579 | /**
|
9580 | * Returns a new {@link JSON} instance from a JSON
|
9581 | * string.
|
9582 | *
|
9583 | * Precision for numeric types is lost in the translation to the internal
|
9584 | * CBOR binary form and non-significant white space is not preserved.
|
9585 | *
|
9586 | * **Example:**
|
9587 | * ```
|
9588 | * // Datatype instance from a JSON string.
|
9589 | * var value = jsondatatype.fromJsonString("{\"foo\" : \"bar\"}");
|
9590 | *
|
9591 | * // The value contains the parsed object representation
|
9592 | * value.get(); // => { foo : "bar" }
|
9593 | * ```
|
9594 | *
|
9595 | * @param json the JSON string
|
9596 | * @return a JSON data-type instance
|
9597 | *
|
9598 | * @since 5.9
|
9599 | */
|
9600 | fromJsonString(json: string): JSON;
|
9601 | }
|
9602 | /**
|
9603 | * Alias for the JSONDataType interface to keep compatibility with old TypeScript definitions
|
9604 | */
|
9605 | export declare type JsonDataType = JSONDataType;
|
9606 | /**
|
9607 | * @module diffusion.datatypes
|
9608 | */
|
9609 | /**
|
9610 | * An unmodifiable map describing the changes to a JSON value.
|
9611 | *
|
9612 | * The {@link JSONDelta.inserted} method returns a
|
9613 | * {@link ChangeMap ChangeMap} describing the parts
|
9614 | * of the second JSON value not found in the first JSON value. Similarly,
|
9615 | * {@link JSONDelta.removed}
|
9616 | * returns a `ChangeMap` describing the parts of the first JSON value
|
9617 | * not found in the second JSON value.
|
9618 | *
|
9619 | * The map contains an entry for each change, as follows:
|
9620 | * * The key is a <a href= "https://tools.ietf.org/html/rfc6901">JSON
|
9621 | * Pointer</a> syntax reference locating the change in the complete value.
|
9622 | * Since a JSON value is a list of zero or more data items, the reference
|
9623 | * always begins with an array index. For example, the first part is
|
9624 | * identified by the JSON Pointer `/0`.
|
9625 | * * The value is part of the complete value. It is returned as a parsed
|
9626 | * value.
|
9627 | *
|
9628 | * An error will be thrown if an invalid JSON pointer expression is passed to
|
9629 | * {@link ChangeMap.get get},
|
9630 | * {@link ChangeMap.containsKey containsKey},
|
9631 | * {@link ChangeMap.descendants descendants}, or
|
9632 | * {@link ChangeMap.intersection intersection}. This only
|
9633 | * occurs if the expression does not start with `/` and is not empty.
|
9634 | */
|
9635 | export interface ChangeMap {
|
9636 | /**
|
9637 | * Retrieve a value from this change map, identified by a JSON Pointer.
|
9638 | *
|
9639 | * @param pointer the JSON Pointer expression
|
9640 | * @returns the change map value, if it exists, otherwise null
|
9641 | * @throws an error if pointer is an invalid JSON Pointer expression
|
9642 | */
|
9643 | get(pointer: string): any;
|
9644 | /**
|
9645 | * Determines if this change map contains an entry for a given JSON Pointer
|
9646 | *
|
9647 | * @param pointer the JSON Pointer expression
|
9648 | * @returns `true` if an entry exists, false if not
|
9649 | * @throws an error if pointer is an invalid JSON Pointer expression
|
9650 | */
|
9651 | containsKey(pointer: string): boolean;
|
9652 | /**
|
9653 | * Returns an array of map entries. Each entry is in the form of a key/value object pair.
|
9654 | *
|
9655 | * The key is a JSON Pointer expression, in string form. The value will be parsed from the
|
9656 | * underlying {@link JSON} object.
|
9657 | *
|
9658 | * @returns the entry array
|
9659 | *
|
9660 | * **Example:**
|
9661 | * ```
|
9662 | * changeMap.entrySet().forEach(function(entry) {
|
9663 | * console.log(entry.key, entry.value);
|
9664 | * });
|
9665 | * ```
|
9666 | */
|
9667 | entrySet(): Array<{
|
9668 | key: string;
|
9669 | value: string;
|
9670 | }>;
|
9671 | /**
|
9672 | * Returns a view of the portion of this map whose keys are descendants
|
9673 | * of `pointer`. If `pointer` is contained in this map, it
|
9674 | * will be included in the result.
|
9675 | *
|
9676 | * @param pointer the json pointer expression to derive descendants for
|
9677 | * @returns changemap of descendant changes
|
9678 | * @throws an error if pointer is an invalid JSON Pointer expression
|
9679 | */
|
9680 | descendants(pointer: string): ChangeMap;
|
9681 | /**
|
9682 | * Returns a view of the portion of this map whose keys are descendants
|
9683 | * or parents of `pointer`. If `pointer` is contained in
|
9684 | * this map, it will be included in the result.
|
9685 | *
|
9686 | * This method can be used to determine whether a structural
|
9687 | * delta affects a particular part of a JSON value. For example:
|
9688 | *
|
9689 | * ```
|
9690 | * if (structuralDelta.removed().intersection("/contact/address").length) {
|
9691 | * // The structural delta removes elements that affect '/contact/address'.
|
9692 | * }
|
9693 | * if (structuralDelta.inserted().intersection("/contact/address").length) {
|
9694 | * // The structural delta inserts elements that affect '/contact/address'.
|
9695 | * }
|
9696 | * ```
|
9697 | *
|
9698 | * @param pointer the json pointer expression to derive intersection for
|
9699 | * @returns changemap of intersection changes
|
9700 | * @throws an error if pointer is an invalid JSON Pointer expression
|
9701 | */
|
9702 | intersection(pointer: string): ChangeMap;
|
9703 | }
|
9704 | /**
|
9705 | * Structural delta type for {@link JSON}.
|
9706 | *
|
9707 | * A JSONDelta describes the differences between two JSON values. Unlike a
|
9708 | * {@link BinaryDelta binary delta}, a
|
9709 | * structural delta can be queried to determine its effect. The
|
9710 | * {@link JSONDelta.removed removed} and
|
9711 | * {@link JSONDelta.inserted inserted} methods provide full
|
9712 | * details of the differences between the two values.
|
9713 | * <p>
|
9714 | * An instance can be created from two JSON values using
|
9715 | * {@link JSON.jsonDiff}.
|
9716 | *
|
9717 | * @author Push Technology Limited
|
9718 | * @since 5.9
|
9719 | */
|
9720 | export interface JSONDelta {
|
9721 | /**
|
9722 | * Returns the parts of the first JSON value not found in the second JSON
|
9723 | * value.
|
9724 | *
|
9725 | * @return the removed parts. The JSON Pointer references used for the
|
9726 | * keys are relative to first JSON value.
|
9727 | */
|
9728 | removed(): ChangeMap;
|
9729 | /**
|
9730 | * Returns the parts of the second JSON value not found in the first JSON
|
9731 | * value.
|
9732 | *
|
9733 | * @return the removed parts. The JSON Pointer references used for
|
9734 | * the keys are relative to second JSON value.
|
9735 | */
|
9736 | inserted(): ChangeMap;
|
9737 | /**
|
9738 | * Returns whether the two JSON values used to create this instance are
|
9739 | * different.
|
9740 | *
|
9741 | * @return `true` if this delta has an effect
|
9742 | */
|
9743 | hasChanges(): boolean;
|
9744 | }
|
9745 | /**
|
9746 | * @module diffusion.datatypes
|
9747 | */
|
9748 | /**
|
9749 | * Immutable JSON data. The value is stored internally as a buffer.
|
9750 | *
|
9751 | * To create an instance from an object, obtain a {@link JSONDataType}
|
9752 | * implementation from `diffusion.datatypes.json()` and call {@link
|
9753 | * JSONDataType.from}.
|
9754 | *
|
9755 | * The encapsulated value can be accessed by calling {@link JSON.get}.
|
9756 | *
|
9757 | * <h4>CBOR representation</h4>
|
9758 | *
|
9759 | * Internally the value is stored and transmitted not as a JSON string, but in
|
9760 | * CBOR format to reduce memory and network overhead. CBOR (Concise Binary
|
9761 | * Object Representation) is a standardized format for binary representation of
|
9762 | * structured data defined by <a href= 'https://tools.ietf.org/html/rfc7049'>RFC
|
9763 | * 7049</a>. See <a href='http://www.cbor.io'>www.cbor.io</a>.
|
9764 | *
|
9765 | * Rather than working with JSON strings it is possible, and usually preferable,
|
9766 | * for applications to work directly with the underlying CBOR-format binary
|
9767 | * representation. This avoids creating intermediate JSON strings, and allows
|
9768 | * access to CBOR features such as the byte string data type.
|
9769 | *
|
9770 | * Each JSON value is represented as a single CBOR data item. CBOR supports
|
9771 | * composite data types just like JSON, so this data item can be an array or a
|
9772 | * map of other data items. The JSON `null` value is represented by the
|
9773 | * CBOR `null` value.
|
9774 | *
|
9775 | * A particular advantage of working directly with the CBOR-format data is that
|
9776 | * binary data can be written to the value as a data item using the CBOR byte
|
9777 | * string type. The data item will be stored as part of the JSON value in binary
|
9778 | * form and transmitted without further conversion.
|
9779 | *
|
9780 | * @since 5.7
|
9781 | */
|
9782 | export interface JSON extends Bytes {
|
9783 | /**
|
9784 | * Get this instance's value. Use this method to access the provided data when a
|
9785 | * {@link JSON} instance is received through the API.
|
9786 | *
|
9787 | * **Example:**
|
9788 | * ```
|
9789 | * session.addStream('foo', diffusion.datatypes.json())
|
9790 | * .on('value', function(path, spec, value) {
|
9791 | * // Get the actual value from the JSON instance
|
9792 | * const data = value.get();
|
9793 | * });
|
9794 | * ```
|
9795 | *
|
9796 | * @return the JSON value
|
9797 | */
|
9798 | get(): any;
|
9799 | /**
|
9800 | * Compare this JSON value with an earlier version to create a delta.
|
9801 | *
|
9802 | * Convenient equivalent to:
|
9803 | * `diffusion.datatypes.json().deltaType(type).diff(original, this);`
|
9804 | *
|
9805 | * Standard JSON objects may also be provided as the value to diff instead
|
9806 | * of a {@link JSON} instance.
|
9807 | *
|
9808 | * **Example:**
|
9809 | * ```
|
9810 | * const binaryDelta = jsonValue.diff({ foo : 'bar' });
|
9811 | * ```
|
9812 | *
|
9813 | * **Example:**
|
9814 | * ```
|
9815 | * const jsonDelta = jsonValue.diff({ foo : 'bar' }, 'json');
|
9816 | * ```
|
9817 | *
|
9818 | * @param original the value to diff against this
|
9819 | * @param type the type of delta to generate (default = 'binary')
|
9820 | * @return a delta representing the difference between this and the provided value
|
9821 | */
|
9822 | diff(original: any, type?: string): BinaryDelta | JSONDelta;
|
9823 | /**
|
9824 | * Compare this JSON value with an earlier version to create a structural
|
9825 | * {@link JSONDelta json delta}.
|
9826 | *
|
9827 | * Convenient equivalent to:
|
9828 | * `this.diff(original, 'json');`
|
9829 | *
|
9830 | * Standard JSON objects may also be provided as the value to diff instead
|
9831 | * of a {@link JSON} instance.
|
9832 | *
|
9833 | * **Example:**
|
9834 | * ```
|
9835 | * const delta = jsonValue.jsonDiff({ foo : 'bar' });
|
9836 | * ```
|
9837 | *
|
9838 | * @param original the value to diff against this
|
9839 | * @return a delta representing the difference between this and
|
9840 | * the provided value
|
9841 | */
|
9842 | jsonDiff(original: any): JSONDelta;
|
9843 | /**
|
9844 | * Apply a delta to this JSON value to create a new value.
|
9845 | *
|
9846 | * Convenient equivalent to:
|
9847 | * `diffusion.datatypes.JSON().deltaType(delta).apply(this, delta);`
|
9848 | *
|
9849 | * @param delta the binary delta to apply to this value
|
9850 | * @return a new instance derived from applying the delta to this value
|
9851 | * @throws an error if the delta is invalid
|
9852 | */
|
9853 | apply(delta: BinaryDelta): JSON;
|
9854 | }
|
9855 | /**
|
9856 | * Alias for the JSON interface to keep compatibility with old TypeScript definitions
|
9857 | */
|
9858 | export declare type Json = JSON;
|
9859 | /**
|
9860 | * @module diffusion.datatypes
|
9861 | */
|
9862 | /**
|
9863 | * Double data type.
|
9864 | *
|
9865 | * Accessed via:
|
9866 | * `diffusion.datatypes.double();`
|
9867 | *
|
9868 | * Provides a data type implementation which supports double float (native
|
9869 | * JavaScript Number) values. The double value is serialized in CBOR-format
|
9870 | * binary.
|
9871 | *
|
9872 | * This data type supports null double values.
|
9873 | *
|
9874 | * @since 6.0
|
9875 | */ export interface DoubleDataType extends DataType<Number, Number, Bytes> {
|
9876 | }
|
9877 | /// <reference types="node" />
|
9878 | /**
|
9879 | * @module diffusion.datatypes
|
9880 | */
|
9881 | export declare type Int64SourceType = string | number | Buffer | Int64;
|
9882 | /**
|
9883 | * Int64 data type.
|
9884 | *
|
9885 | * Accessed via:
|
9886 | * `diffusion.datatypes.int64();`
|
9887 | *
|
9888 | * Provides a data type implementation which supports {@link Int64 64-bit signed
|
9889 | * integer} values. The Int64 value is serialized in CBOR-format binary.
|
9890 | *
|
9891 | * This data type supports null Int64 values.
|
9892 | *
|
9893 | * @since 6.0
|
9894 | */
|
9895 | export interface Int64DataType extends DataType<Int64, Int64SourceType, Bytes> {
|
9896 | /**
|
9897 | * The Int64 data type value class
|
9898 | */
|
9899 | Int64: new (value: string | number | Buffer, radix?: number) => Int64;
|
9900 | }
|
9901 | /**
|
9902 | * @module diffusion.datatypes
|
9903 | */
|
9904 | /**
|
9905 | * Signed 64-bit integer. Provides a means to read integer values larger than
|
9906 | * supported natively by JavaScript.
|
9907 | *
|
9908 | * Used as the value type of the Int64 data type:
|
9909 | * ```
|
9910 | * var datatype = diffusion.datatypes.int64();
|
9911 | * var value = new datatype.Int64("12498352809328592352350908124");
|
9912 | * ```
|
9913 | *
|
9914 | * @since 6.0
|
9915 | */
|
9916 | export interface Int64 {
|
9917 | /**
|
9918 | * Read this value as a string.
|
9919 | *
|
9920 | * @param radix the radix to use. Defaults to base `10`.
|
9921 | * @return the string representation of the int64 value.
|
9922 | */
|
9923 | toString(radix?: number): string;
|
9924 | /**
|
9925 | * Read this value as a number. The validity of the returned number can only be guaranteed for values up to
|
9926 | * `Math.pow(2, 53) - 1` due to underlying platform limitations of JavaScript.
|
9927 | *
|
9928 | * @return the numerical value of this int64, as a 53-bit integer.
|
9929 | */
|
9930 | toNumber(): number;
|
9931 | }
|
9932 | /**
|
9933 | * @module diffusion.datatypes
|
9934 | */
|
9935 | export declare type StringSourceType = string | {
|
9936 | toString: () => string;
|
9937 | };
|
9938 | /**
|
9939 | * String data type.
|
9940 | *
|
9941 | * Accessed via:
|
9942 | * `diffusion.datatypes.string();`
|
9943 | *
|
9944 | * Provides a data type implementation which supports string values. The string value is serialized in CBOR-format
|
9945 | * binary.
|
9946 | *
|
9947 | * This data type supports null string instances.
|
9948 | *
|
9949 | * @since 6.0
|
9950 | */ export interface StringDataType extends DataType<String, StringSourceType, Bytes> {
|
9951 | }
|
9952 | /**
|
9953 | * @module diffusion.datatypes.RecordV2
|
9954 | */
|
9955 | /**
|
9956 | * This is a mutable data model of {@link RecordV2} data
|
9957 | * based upon a {@link Schema}.
|
9958 | *
|
9959 | * An initial version of such a model can be created from a schema using the
|
9960 | * {@link Schema.createMutableModel} method. A
|
9961 | * model created in this way will have all mandatory fields set to default
|
9962 | * values.
|
9963 | *
|
9964 | * The model may then be updated as required and then at any time a {@link
|
9965 | * RecordV2} object can be generated from the current state using the {@link
|
9966 | * MutableRecordModel.asValue asValue} method. The {@link RecordV2} object may
|
9967 | * then be used to update a topic.
|
9968 | *
|
9969 | * When values for integer or decimal type fields are supplied the values are
|
9970 | * validated and normalized. All number values will have any insignificant
|
9971 | * leading zeroes removed. A decimal value will also be rounded to its specified
|
9972 | * scale.
|
9973 | *
|
9974 | * All mutator methods return the model so that calls can be chained.
|
9975 | *
|
9976 | * @since 6.0
|
9977 | */
|
9978 | export interface MutableRecordModel extends RecordModel {
|
9979 | /**
|
9980 | * Set a field value.
|
9981 | *
|
9982 | * This allows an item to be addressed using a key of the form
|
9983 | * `recordName(recordIndex).fieldName(fieldIndex)`. Indexes may be omitted
|
9984 | * in which case `0` is assumed.
|
9985 | *
|
9986 | * **Example:**
|
9987 | * ```
|
9988 | * // Get field value with record & field names and indices
|
9989 | * var value = model.set("record", 0, "field", 0, "foo");
|
9990 | * ```
|
9991 | *
|
9992 | * @param recordName the name of the record
|
9993 | * @param recordIndex the index of the record
|
9994 | * @param fieldName the name of the field
|
9995 | * @param fieldIndex the index of the field
|
9996 | * @param value the value to be set
|
9997 | * @return this model
|
9998 | */
|
9999 | set(recordName: string, recordIndex: number, fieldName: string, fieldIndex: number, value: string): MutableRecordModel;
|
10000 | set(recordName: string, fieldName: string, value: string): MutableRecordModel;
|
10001 | set(recordName: string, value: string): MutableRecordModel;
|
10002 | /**
|
10003 | * Adds new values to the end of a variable length field list.
|
10004 | *
|
10005 | * This can only be used for a variable multiplicity field which can only be
|
10006 | * the last field in a record and therefore the field does not need to be
|
10007 | * named.
|
10008 | *
|
10009 | * If the record name and index are not supplied, this will add values to the last
|
10010 | * record in the model. If the model's schema does not specify a variable last field
|
10011 | * or record, an error will be thrown.
|
10012 | *
|
10013 | * @param recordName the name of the record
|
10014 | * @param recordIndex the index identifying the occurrence of the record
|
10015 | * @param values the values to add
|
10016 | * @return this model
|
10017 | */
|
10018 | add(recordName: string, recordIndex: number, ...values: string[]): MutableRecordModel;
|
10019 | add(recordName: string, ...values: string[]): MutableRecordModel;
|
10020 | /**
|
10021 | * Adds a new initialized record occurrence to the end of a variable
|
10022 | * multiplicity record list.
|
10023 | *
|
10024 | * As the only variable multiplicity record can be the last one there is no
|
10025 | * need to name the record. This method will add to the list of occurrences
|
10026 | * of the last defined record. The record will be initialized with default
|
10027 | * values appropriate to the schema definition and may then have individual
|
10028 | * field items set separately.
|
10029 | *
|
10030 | * @return this model
|
10031 | */
|
10032 | addRecord(): MutableRecordModel;
|
10033 | /**
|
10034 | * Removes the specified occurrence of a variable multiplicity record.
|
10035 | *
|
10036 | * A variable multiplicity record must be the last or only record within a
|
10037 | * schema and therefore the record name is not required.
|
10038 | *
|
10039 | * @param index the index of the record to remove
|
10040 | * @return this model
|
10041 | */
|
10042 | removeRecord(index: number): MutableRecordModel;
|
10043 | /**
|
10044 | * Removes the specified occurrence of a variable multiplicity field.
|
10045 | *
|
10046 | * A variable multiplicity field must be the last or only field within a
|
10047 | * record and therefore the field name is not required.
|
10048 | *
|
10049 | * @param recordName the name of the record
|
10050 | * @param recordIndex the record index
|
10051 | * @param fieldIndex the index of the field to remove
|
10052 | * @return this model
|
10053 | */
|
10054 | removeField(recordName: string, recordIndex: number, fieldIndex: number): MutableRecordModel;
|
10055 | }
|
10056 | /**
|
10057 | * @module diffusion.datatypes.RecordV2
|
10058 | */
|
10059 | /**
|
10060 | * Builds free format {@link RecordV2 RecordV2 value}.
|
10061 | *
|
10062 | * This type of builder may be used to generate free format {@link RecordV2}
|
10063 | * data which is not constrained by a {@link Schema}.
|
10064 | *
|
10065 | * A builder can be created using {@link RecordV2DataType.valueBuilder}.
|
10066 | *
|
10067 | * @since 6.0
|
10068 | */
|
10069 | export interface RecordV2Builder {
|
10070 | /**
|
10071 | * Adds one or more field values.
|
10072 | *
|
10073 | * If there is a current record, this adds the fields to the end of the
|
10074 | * current record.
|
10075 | *
|
10076 | * @param values field values
|
10077 | * @return this builder
|
10078 | */
|
10079 | addFields(fields: string[]): RecordV2Builder;
|
10080 | addFields(...fields: string[]): RecordV2Builder;
|
10081 | /**
|
10082 | * Adds a new record comprising the specified field values.
|
10083 | *
|
10084 | * @param fields the fields within the new record. If no fields are
|
10085 | * supplied, an empty record will be added.
|
10086 | * @return this builder
|
10087 | */
|
10088 | addRecord(fields: string[]): RecordV2Builder;
|
10089 | addRecord(...fields: string[]): RecordV2Builder;
|
10090 | /**
|
10091 | * Clears all current values from the builder allowing it to be reused to
|
10092 | * generate new data.
|
10093 | *
|
10094 | * @return this builder
|
10095 | */
|
10096 | clear(): void;
|
10097 | /**
|
10098 | * Builds a {@link RecordV2} object from the current
|
10099 | * builder state.
|
10100 | *
|
10101 | * @return a new {@link RecordV2} object
|
10102 | */
|
10103 | build(): RecordV2;
|
10104 | }
|
10105 | /**
|
10106 | * @module diffusion.datatypes.RecordV2
|
10107 | */
|
10108 | /**
|
10109 | * Record-based data type.
|
10110 | *
|
10111 | * This provides the ability to handle data in Diffusion proprietary 'record'
|
10112 | * format. This format allows string data to be organized into 'records' which
|
10113 | * in turn are made up of 'fields'. Each field is a string but may be handled as
|
10114 | * either an integer or a decimal field if required.
|
10115 | *
|
10116 | * The data can either be free format or constrained by a {@link Schema}.
|
10117 | *
|
10118 | * In free format mode, no schema is associated with the data and the data will
|
10119 | * contain zero or more records, each comprising zero or more fields. In this
|
10120 | * mode the meaning of each field is entirely up to the application and no
|
10121 | * validation will be performed by Diffusion, either in the client library, or
|
10122 | * at the server. To write free format records, a {@link RecordV2Builder} can be
|
10123 | * used to create a [RecordV2](recordv2.html) object. Such a builder may be
|
10124 | * created using the {@link RecordV2DataType.valueBuilder} method.
|
10125 | *
|
10126 | * When using a {@link Schema} then the permitted records and fields are defined
|
10127 | * by the schema. The schema names the records and the fields within them and
|
10128 | * provides a mechanism for direct access to the fields. The schema is also used
|
10129 | * to validate the data to ensure it complies with the schema definition.
|
10130 | *
|
10131 | * In schema mode, data can be created and updated using a {@link
|
10132 | * MutableRecordModel} which allows records and fields to be conveniently set
|
10133 | * and updated by name. A base model can be created from a schema using the
|
10134 | * {@link Schema.createMutableModel} method. The model can at any time be used
|
10135 | * to create a new [RecordV2](recordv2.html) object. A consumer of a
|
10136 | * [RecordV2](recordv2.html) value can read it as a {@link RecordModel} by
|
10137 | * simply using the {@link RecordV2.asModel} method to produce an immutable
|
10138 | * representation of the data. When creating the data using a {@link
|
10139 | * MutableRecordModel} then the model ensures that the data is valid and
|
10140 | * therefore there is no need for the server or the consuming client to validate
|
10141 | * the data.
|
10142 | *
|
10143 | * Schemas can be parsed from JSON strings or more simply using a {@link
|
10144 | * SchemaBuilder} obtained using the {@link RecordV2DataType.schemaBuilder}
|
10145 | * method. A schema can be bound to a [RecordV2](recordv2.html) data type
|
10146 | * instance using the method {@link RecordV2DataType.withSchema}. This method
|
10147 | * will return a new RecordV2DataType instance with the schema bound to it for
|
10148 | * validation.
|
10149 | *
|
10150 | * A [RecordV2](recordv2.html) object can only be validated within the context
|
10151 | * of a {@link Schema}. For this reason, if the {@link DataType#validate(Object)
|
10152 | * validate} method is called on a dataType that has no bound schema, it will
|
10153 | * always succeed.
|
10154 | *
|
10155 | * Accessed via:
|
10156 | * `diffusion.datatypes.recordv2();`
|
10157 | *
|
10158 | * @since 6.0
|
10159 | */
|
10160 | export interface RecordV2DataType extends DataType<RecordV2, RecordV2, RecordV2> {
|
10161 | /**
|
10162 | * The RecordV2 data type value class
|
10163 | */
|
10164 | RecordV2: new (...args: any[]) => RecordV2;
|
10165 | /**
|
10166 | * Bind a specific schema to a {@link RecordV2DataType}
|
10167 | * instance.
|
10168 | *
|
10169 | * @param schema schema to bind to the data type
|
10170 | * @return a {@link RecordV2DataType} bound to a
|
10171 | * specific schema
|
10172 | */
|
10173 | withSchema(schema: Schema): RecordV2DataType;
|
10174 | /**
|
10175 | * Parse a schema from a JSON string.
|
10176 | *
|
10177 | * @param json json string containing a schema definition
|
10178 | * @return the schema
|
10179 | */
|
10180 | parseSchema(json: string): Schema;
|
10181 | /**
|
10182 | * Creates a new {@link RecordV2Builder}.
|
10183 | *
|
10184 | * Such a builder may be used to generate a free format [RecordV2](recordv2.html)
|
10185 | * format value that is not constrained by a {@link Schema}.
|
10186 | *
|
10187 | * @return a new records builder
|
10188 | */
|
10189 | valueBuilder(): RecordV2Builder;
|
10190 | /**
|
10191 | * Creates a new schema builder.
|
10192 | *
|
10193 | * @return a new schema builder
|
10194 | */
|
10195 | schemaBuilder(): SchemaBuilder;
|
10196 | }
|
10197 | /**
|
10198 | * @module diffusion.datatypes.RecordV2
|
10199 | */
|
10200 | /**
|
10201 | * Represents a single change to a Record value.
|
10202 | */
|
10203 | export interface Change {
|
10204 | /**
|
10205 | * The name of the affected record
|
10206 | */
|
10207 | readonly recordName: string;
|
10208 | /**
|
10209 | * The index of the affected record
|
10210 | */
|
10211 | readonly recordIndex: number;
|
10212 | /**
|
10213 | * The name of the affected field
|
10214 | */
|
10215 | readonly fieldName: string;
|
10216 | /**
|
10217 | * The index of the affected field
|
10218 | */
|
10219 | readonly fieldIndex: number;
|
10220 | /**
|
10221 | * Returns the string key representation of the affected item in
|
10222 | * the form `recordName(recordIndex).fieldName(fieldIndex)`.
|
10223 | */
|
10224 | readonly key: string;
|
10225 | /**
|
10226 | * String denoting the type of change that this represents
|
10227 | */
|
10228 | readonly type: string;
|
10229 | }
|
10230 | /**
|
10231 | * {@link RecordV2} structural delta.
|
10232 | *
|
10233 | * A RecordV2Delta describes the differences between two {@link RecordV2}
|
10234 | * values. Unlike a {@link BinaryDelta binary delta}, a structural delta
|
10235 | * can be queried to determine its effect. The
|
10236 | * {@link RecordV2Delta.changes} method provides details of which values
|
10237 | * have changed.
|
10238 | *
|
10239 | * An instance can be created from two RecordV2 values using
|
10240 | * {@link RecordV2.diff}.
|
10241 | *
|
10242 | * RecordV2Deltas are useful for identifying small changes to complex RecordV2
|
10243 | * values. Here is an example of how to use this class to filter interesting
|
10244 | * changes from a value stream.
|
10245 | *
|
10246 | * **Example:**
|
10247 | * ```
|
10248 | * var datatype = diffusion.datatypes.recordv2();
|
10249 | *
|
10250 | * session.addStream("topic", datatype).on('value', (path, spec, newValue, oldValue) => {
|
10251 | * var schema = datatype.parseSchema(spec.properties.SCHEMA);
|
10252 | *
|
10253 | * newValue.diff(oldValue).changes(schema).forEach((change) => {
|
10254 | * if (change.fieldName === "address") {
|
10255 | * // Do something with the changed address
|
10256 | * console.log(newValue.getFields());
|
10257 | * }
|
10258 | * });
|
10259 | * });
|
10260 | * ```
|
10261 | *
|
10262 | * @author Push Technology Limited
|
10263 | * @since 6.0
|
10264 | * @see diffusion.datatypes.RecordV2.diff
|
10265 | */
|
10266 | export interface RecordV2Delta extends Bytes {
|
10267 | /**
|
10268 | * Returns a list of the changes represented by the delta with reference to
|
10269 | * a specified schema.
|
10270 | *
|
10271 | * The schema supplied must comply with the data format of the delta. No
|
10272 | * validation takes place, so if the schema does not match the data then the
|
10273 | * results may be unpredictable.
|
10274 | *
|
10275 | * @param schema the schema
|
10276 | * @return the list of changes
|
10277 | */
|
10278 | changes(schema: Schema): Change[];
|
10279 | }
|
10280 | /**
|
10281 | * @module diffusion.datatypes.RecordV2
|
10282 | */
|
10283 | /**
|
10284 | * {@link RecordV2} data model.
|
10285 | *
|
10286 | * A read only model can be created from any {@link RecordV2} object using the
|
10287 | * {@link RecordV2.asModel asModel} method. The model then provides direct
|
10288 | * access to the fields within the data. Fields may be accessed either by
|
10289 | * explicitly specifying the record and field occurrence or by specifying a key
|
10290 | * of the form:
|
10291 | *
|
10292 | * ```
|
10293 | * recordName(recordIndex).fieldName(fieldIndex)
|
10294 | * ```
|
10295 | *
|
10296 | * Indexes start from 0 and if omitted then 0 is assumed. The record name may
|
10297 | * also be omitted, in which case the first record definition is accessed. This
|
10298 | * form of addressing is useful when there is only one record definition.
|
10299 | *
|
10300 | * So valid keys are:
|
10301 | *
|
10302 | * Key | Description
|
10303 | * ---------------------------| --------------------
|
10304 | * `Address(4).AddressLine(3)`| The 4th `AddressLine` occurrence within the 5th `Address` record
|
10305 | * `Address.Name` | The first (or only) `Name` field within the first (or only) `Address` record
|
10306 | * `AddressLine(1)` | The 2nd `AddressLine` field within the first (or only) record
|
10307 | * `Name` | The first (or only) `Name` field within the first (or only) record
|
10308 | *
|
10309 | * The {@link RecordModel.recordCount} and
|
10310 | * {@link RecordModel.fieldCount} methods are useful for
|
10311 | * determining the actual number of occurrences of variable multiplicity items.
|
10312 | *
|
10313 | * @since 6.0
|
10314 | */
|
10315 | export interface RecordModel {
|
10316 | /**
|
10317 | * Get a field value.
|
10318 | *
|
10319 | * This allows an item to be addressed using a key of the form
|
10320 | * recordName(recordIndex).fieldName(fieldIndex). Indexes may be omitted in
|
10321 | * which case `0` is assumed.
|
10322 | *
|
10323 | * **Example:**
|
10324 | * ```
|
10325 | * // Get field value with record & field names and indices
|
10326 | * var value = model.get("record", 0, "field", 0);
|
10327 | * ```
|
10328 | *
|
10329 | * @param recordName the name of the record
|
10330 | * @param recordIndex the index of the record
|
10331 | * @param fieldName the name of the field
|
10332 | * @param fieldIndex the index of the field
|
10333 | * @return the field value
|
10334 | */
|
10335 | get(recordName: string, recordIndex: number, fieldName: string, fieldIndex?: number): string | null;
|
10336 | get(recordName: string, fieldName: string, fieldIndex?: number): string | null;
|
10337 | /**
|
10338 | * Creates an immutable {@link RecordV2} object
|
10339 | * generated from the model.
|
10340 | *
|
10341 | * @return a new immutable instance
|
10342 | */
|
10343 | asValue(): RecordV2;
|
10344 | /**
|
10345 | * Returns the actual number of occurrences of a named field within a
|
10346 | * specified record.
|
10347 | *
|
10348 | * For all but variable fields this simply returns the schema defined number
|
10349 | * of occurrences of the field.
|
10350 | *
|
10351 | * @param recordName the record name
|
10352 | * @param recordIndex the record index
|
10353 | * @param fieldName the field name
|
10354 | * @return the actual number of occurrences of the field
|
10355 | */
|
10356 | fieldCount(recordName: string, recordIndex?: number, fieldName?: string): number;
|
10357 | /**
|
10358 | * Returns the actual number of occurrences of a named record.
|
10359 | *
|
10360 | * If the record is not variable, this is the same as the defined number of
|
10361 | * occurrences in the schema
|
10362 | *
|
10363 | * @param recordName the record name
|
10364 | * @return the actual number of occurrences of the record
|
10365 | */
|
10366 | recordCount(recordName: string): number;
|
10367 | }
|
10368 | /**
|
10369 | * @module diffusion.datatypes.RecordV2
|
10370 | */
|
10371 | /**
|
10372 | * An immutable value representing a list of records.
|
10373 | *
|
10374 | * See {@link RecordV2DataType} for details
|
10375 | *
|
10376 | * @since 6.0
|
10377 | */
|
10378 | export interface RecordV2 extends Bytes {
|
10379 | /**
|
10380 | * Compare this value with an earlier version to calculate a structural
|
10381 | * delta.
|
10382 | *
|
10383 | * @param original the original value to compare with this value
|
10384 | * @return a structural delta representing the difference between
|
10385 | * the original and this value
|
10386 | */
|
10387 | diff(original: RecordV2): RecordV2Delta;
|
10388 | /**
|
10389 | * Parses the content into a model based upon a specified schema.
|
10390 | *
|
10391 | * This assumes that data is compatible with the schema and does not do any
|
10392 | * validation. There is no need to validate the data if this has been done
|
10393 | * on entry or at the server. However, if the data is invalid then issues
|
10394 | * may occur when attempting to access it.
|
10395 | *
|
10396 | * If it is not certain that the data is valid then the {@link
|
10397 | * asValidatedModel} method may be used instead.
|
10398 | *
|
10399 | * @param schema the schema to use for parsing the data
|
10400 | * @return an immutable model derived from the data content
|
10401 | */
|
10402 | asModel(schema: Schema): RecordModel;
|
10403 | /**
|
10404 | * Parses the content into a model based upon a specified schema.
|
10405 | *
|
10406 | * The data is validated against the schema
|
10407 | *
|
10408 | * @param schema the schema to use for parsing the data
|
10409 | * @return an immutable model derived from the data content
|
10410 | */
|
10411 | asValidatedModel(schema: Schema): RecordModel;
|
10412 | /**
|
10413 | * Returns the data content as an Array of Arrays of strings.
|
10414 | *
|
10415 | * **Example:**
|
10416 | * ```
|
10417 | * // Iterate across each record's fields
|
10418 | * value.asRecords().forEach((record) => {
|
10419 | * record.forEach((field) => {
|
10420 | * console.log("Field value: " + field);
|
10421 | * });
|
10422 | * });
|
10423 | * ```
|
10424 | *
|
10425 | * @return a new mutable list where each entry represents a record within the data
|
10426 | */
|
10427 | asRecords(): string[][];
|
10428 | /**
|
10429 | * Returns the data content as a list of fields.
|
10430 | *
|
10431 | * This disregards record boundaries. If there is more than one record, they
|
10432 | * are concatenated to produce a list of all of the fields.
|
10433 | *
|
10434 | * This method would normally only be used when it is known that there is
|
10435 | * only one record.
|
10436 | *
|
10437 | * @return a new mutable list of all the fields
|
10438 | */
|
10439 | asFields(): string[];
|
10440 | }
|
10441 | /**
|
10442 | * @module diffusion.datatypes.RecordV2
|
10443 | */
|
10444 | /**
|
10445 | * Used to build an immutable {@link Schema}.
|
10446 | *
|
10447 | * A schema defines the records and fields that may occur on record-based topic
|
10448 | * content.
|
10449 | *
|
10450 | * The schema must declare at least one record type and every record must have
|
10451 | * at least one field type declared.
|
10452 | *
|
10453 | * Every record type and field type has a 'multiplicity' which defines the
|
10454 | * number of times that the record or field may occur within the data.
|
10455 | * Multiplicity is specified as a 'minimum' and 'maximum' number of occurrences
|
10456 | * or where the minimum and maximum are the same (fixed multiplicity) then the
|
10457 | * multiplicity may be specified as a single 'occurs' value. If the minimum and
|
10458 | * maximum are different, this is referred to a 'variable' multiplicity. Only
|
10459 | * the last record declared or the last field within a record may have variable
|
10460 | * multiplicity. The maximum value may be declared as -1 to indicate that the
|
10461 | * record or field can have an unlimited number of occurrences.
|
10462 | *
|
10463 | * The builder is used to add a record definition followed by the fields within
|
10464 | * it. After all fields have been added to a record another may then be added,
|
10465 | * and so on, and then finally {@link SchemaBuilder.build build()} is called to create
|
10466 | * an immutable schema object.
|
10467 | *
|
10468 | * Every call returns the builder instance allowing calls to be chained, for
|
10469 | * example:
|
10470 | *
|
10471 | * ```
|
10472 | * const schema = builder.record('R1').string('S1').string('S2', 1, 5)
|
10473 | * .record('R2', 0, -1).decimal('D', 5).build();
|
10474 | * ```
|
10475 | *
|
10476 | * A builder is obtained using the {@link RecordV2DataType.schemaBuilder}
|
10477 | * method.
|
10478 | *
|
10479 | * @since 6.0
|
10480 | */
|
10481 | export interface SchemaBuilder {
|
10482 | /**
|
10483 | * Add a new record to the schema
|
10484 | *
|
10485 | * The record added must not have the same name as a previously added record.
|
10486 | *
|
10487 | * A record may not be added after a record that has variable multiplicity (min != max)
|
10488 | *
|
10489 | * A record may not be added directly after another record which has had no fields added.
|
10490 | *
|
10491 | * @param name record name. This must not the same as any record already added
|
10492 | * @param min=1 the minimum number of times the record should occur within the schema
|
10493 | * @param max=1 the maximum number of times the record should occur within the schema.
|
10494 | * May be either `-1` (indicating no upper limit) or a
|
10495 | * positive value that is not less than * `min`
|
10496 | */
|
10497 | record(name: string, min?: number, max?: number): SchemaBuilder;
|
10498 | /**
|
10499 | * Add a string field to the current record.
|
10500 | *
|
10501 | * A field may not be added after a field that has variable multiplicity (min != max)
|
10502 | *
|
10503 | * @param name field name. This must not the same as any field already added
|
10504 | * @param min=1 the minimum number of times the field should occur within the record
|
10505 | * @param max=1 the maximum number of times the field should occur within the record.
|
10506 | * May be either `-1` (indicating no upper limit) or a
|
10507 | * positive value that is not less than * `min`
|
10508 | *
|
10509 | */
|
10510 | string(name: string, min?: number, max?: number): SchemaBuilder;
|
10511 | /**
|
10512 | * Add an integer field to the current record.
|
10513 | *
|
10514 | * A field may not be added after a field that has variable multiplicity (min != max)
|
10515 | *
|
10516 | * @param name field name. This must not the same as any field already added
|
10517 | * @param min=1 the minimum number of times the field should occur within the record
|
10518 | * @param max=1 the maximum number of times the field should occur within the record.
|
10519 | * May be either `-1` (indicating no upper limit) or a
|
10520 | * positive value that is not less than * `min`
|
10521 | *
|
10522 | */
|
10523 | integer(name: string, min?: number, max?: number): SchemaBuilder;
|
10524 | /**
|
10525 | * Add a decimal field to the current record.
|
10526 | *
|
10527 | * A field may not be added after a field that has variable multiplicity (min != max)
|
10528 | *
|
10529 | * @param name field name. This must not the same as any field already added
|
10530 | * @param scale the scale of the field (number of decimal places). This must be strictly positive.
|
10531 | * @param min=1 the minimum number of times the field should occur within the record
|
10532 | * @param max=1 the maximum number of times the field should occur within the record.
|
10533 | * May be either `-1` (indicating no upper limit) or a
|
10534 | * positive value that is not less than * `min`
|
10535 | */
|
10536 | decimal(name: string, scale: number, min?: number, max?: number): SchemaBuilder;
|
10537 | /**
|
10538 | * Build an immutable Schema.
|
10539 | *
|
10540 | * At least one record with at least one field must have been added to the
|
10541 | * builder.
|
10542 | *
|
10543 | * @return a new immutable schema object representing the current state of
|
10544 | * the builder
|
10545 | */
|
10546 | build(): Schema;
|
10547 | }
|
10548 | /**
|
10549 | * @module diffusion.datatypes.RecordV2
|
10550 | */
|
10551 | /**
|
10552 | * A Node in the schema definition
|
10553 | */
|
10554 | export interface Node {
|
10555 | /**
|
10556 | * The node name
|
10557 | */
|
10558 | name: string;
|
10559 | /**
|
10560 | * The minimum number of occurrences of the node within its parent
|
10561 | */
|
10562 | min: number;
|
10563 | /**
|
10564 | * The maximum number of occurrences of the node within its parent
|
10565 | */
|
10566 | max: number;
|
10567 | /**
|
10568 | * Flag that indicates if the node has variable multiplicity, or has fixed
|
10569 | * multiplicity
|
10570 | */
|
10571 | isVariable: boolean;
|
10572 | }
|
10573 | export interface Field extends Node {
|
10574 | /**
|
10575 | * An optional scale definition for decimal field types
|
10576 | */
|
10577 | scale?: number;
|
10578 | }
|
10579 | export interface Record extends Node {
|
10580 | /**
|
10581 | * A list of the field definitions. There will be at least one
|
10582 | */
|
10583 | fields: Field[];
|
10584 | }
|
10585 | /**
|
10586 | * A {@link RecordV2} schema.
|
10587 | *
|
10588 | * A schema describes data content in terms of one or more record definitions. A
|
10589 | * record definition describes the layout of a record and comprises one or more
|
10590 | * field definitions.
|
10591 | *
|
10592 | * Within the data content there can be multiple occurrences of a record or
|
10593 | * field described by a single definition. The defined (or allowed, when
|
10594 | * describing variable numbers) number of occurrences of each definition is
|
10595 | * referred to as its 'multiplicity'. The multiplicity can be fixed (the item
|
10596 | * occurs a fixed number of times), or variable (the item occurs from a minimum
|
10597 | * number of times to a maximum number of times). If a variable field is used it
|
10598 | * must be the last in a record definition and if a variable record is used it
|
10599 | * must be the last in the schema definition.
|
10600 | *
|
10601 | * A field may be defined as of type 'string', 'integer' or 'decimal'. A decimal
|
10602 | * type has a further property of 'scale' which defines the number of digits to
|
10603 | * the right of the decimal point.
|
10604 | *
|
10605 | * A schema can be obtained from {@link RecordV2DataType.parseSchema} or from a
|
10606 | * {@link SchemaBuilder}
|
10607 | *
|
10608 | * @since 6.0
|
10609 | */
|
10610 | export interface Schema {
|
10611 | /**
|
10612 | * Returns an immutable, ordered list of record definitions.
|
10613 | *
|
10614 | * There will be at least one.
|
10615 | *
|
10616 | * @return a list of the record definitions in the schema
|
10617 | */
|
10618 | getRecords(): Record[];
|
10619 | /**
|
10620 | * Returns the schema in a JSON format
|
10621 | *
|
10622 | * @return schema in JSON format
|
10623 | */
|
10624 | asJSON(): any;
|
10625 | /**
|
10626 | * Create a mutable model based upon the schema.
|
10627 | *
|
10628 | * The model will be created with all mandatory record occurrences and all
|
10629 | * mandatory field occurrences initialized to default values.
|
10630 | *
|
10631 | * Such a model may be mutated and used to generate updated
|
10632 | * {@link RecordV2} occurrences for updating purposes.
|
10633 | *
|
10634 | * @return a new initialized model
|
10635 | */
|
10636 | createMutableModel(): MutableRecordModel;
|
10637 | }
|
10638 | export as namespace diffusion; |
\ | No newline at end of file |