UNPKG

6.58 kBJavaScriptView Raw
1"use strict";
2/**
3 * @module diffusion
4 */
5Object.defineProperty(exports, "__esModule", { value: true });
6var InternalSessionFactory = require("client/internal-session-factory");
7var datatypes_1 = require("data/datatypes");
8var DiffusionGlobals = require("diffusion/diffusion-globals");
9var session_impl_1 = require("session/session-impl");
10var update_constraint_factory_1 = require("topic-update/update-constraint-factory");
11var logger = require("util/logger");
12var error_reason_1 = require("./errors/error-reason");
13var client_control_options_1 = require("./features/client-control-options");
14var session_lock_options_1 = require("./features/session-lock-options");
15var topic_selectors_1 = require("./selectors/topic-selectors");
16var topic_update_1 = require("./topic-update/topic-update");
17var topics_1 = require("./topics/topics");
18logger.setLevel('warn');
19/**
20 * The top-level Diffusion API.
21 *
22 * Provides access to Session connections and global namespaces.
23 */ // export namespace diffusion {
24/**
25 * The version of this client library in the form major.minor.patch
26 */
27exports.version = '6.4.5';
28/**
29 * The build version of this client library
30 */
31exports.build = '5#71287';
32/**
33 * Set the level of logging used by Diffusion. This will default to silent.
34 * Log levels are strings that represent different degrees of information to
35 * be logged. Available options are:
36 *
37 * * silent
38 * * error
39 * * warn
40 * * info
41 * * debug
42 * * trace
43 *
44 * @param level the log level to use
45 */
46function log(level) {
47 // keyof typeof works only because LogLevel maps the keys onto themselves
48 logger.setLevel(level);
49}
50exports.log = log;
51/**
52 * Connect to a specified Diffusion server. This will return a {@link
53 * Result} that will complete succesfully if a session can be connected, or
54 * fail if an error was encountered.
55 *
56 * If the result is succesful, the fulfilled handler will be called with a
57 * {@link Session} instance. This session will be in a connected state and
58 * may be used for subsequent API calls.
59 *
60 * If the result fails, the rejected handler will be called with an error
61 * reason.
62 *
63 * **Example:**
64 * ```
65 * diffusion.connect('example.server.com').then(function(session) {
66 * // Connected with a session
67 * console.log('Connected!', session);
68 * }, function(error) {
69 * // Connection failed
70 * console.log('Failed to connect', error);
71 * });
72 * ```
73 *
74 *
75 * @param options the options to construct the session with.
76 * @returns a {@link Result} for this operation
77 */
78function connect(options) {
79 return session_impl_1.SessionImpl.create(InternalSessionFactory.create, options);
80}
81exports.connect = connect;
82/**
83 * Escapes special characters in a string that is to be used within a topic
84 * property or a session filter.
85 * <P>
86 * This is a convenience method which inserts an escape character '\' before
87 * any of the special characters ' " or \.
88 *
89 * @param s the string to be escaped
90 * @returns the string value with escape characters inserted as appropriate
91 *
92 * @since 6.1
93 */
94function escape(s) {
95 return DiffusionGlobals.escape(s);
96}
97exports.escape = escape;
98/**
99 * Utility method which converts a string of the format required by the
100 * {@link PropertyKeys.ROLES $Roles} session property into a mutable set of
101 * strings.
102 *
103 * @param s the string with quoted roles separated by whitespace or
104 * commas
105 *
106 * @return set of roles
107 *
108 * @since 6.2
109 */
110function stringToRoles(s) {
111 return DiffusionGlobals.stringToRoles(s);
112}
113exports.stringToRoles = stringToRoles;
114/**
115 * Utility method which converts a set of authorisation roles to the string
116 * format required by the {@link PropertyKeys.ROLES $Roles} session property.
117 *
118 * @param roles a set of roles
119 * @return a string representing the supplied roles, formatted as
120 * required by the {@link PropertyKeys.ROLES $Roles} session
121 * property
122 *
123 * @since 6.2
124 */
125function rolesToString(roles) {
126 return DiffusionGlobals.rolesToString(roles);
127}
128exports.rolesToString = rolesToString;
129/**
130 * Returns an update constraint factory.
131 *
132 * @function diffusion#updateConstraints
133 * @return {diffusion.topicUpdate.UpdateConstraintFactory} update constraint
134 * factory
135 * @since 6.2
136 */
137function updateConstraints() {
138 return update_constraint_factory_1.updateConstraintFactory;
139}
140exports.updateConstraints = updateConstraints;
141/**
142 * Access to the datatypes namespace
143 */
144exports.datatypes = datatypes_1.DataTypes;
145/**
146 * Access to the selectors namespace
147 */
148exports.selectors = new topic_selectors_1.TopicSelectors();
149/**
150 * Access to the topics namespace
151 */
152exports.topics = topics_1.topicsNamespace;
153/**
154 * Access to the topicUpdate namespace
155 */
156exports.topicUpdate = topic_update_1.TopicUpdateNamespace;
157/**
158 * The ErrorReason enum
159 */
160exports.errors = error_reason_1.ErrorReason;
161/**
162 * Access to PropertyKeys
163 */
164exports.clients = client_control_options_1.ClientControlOptions;
165/**
166 * Access to the locks namespace
167 */
168exports.locks = session_lock_options_1.SessionLockOptions;
169var client_location_1 = require("./client/client-location");
170exports.AddressType = client_location_1.AddressType;
171var client_summary_1 = require("./client/client-summary");
172exports.ClientType = client_summary_1.ClientType;
173exports.TransportType = client_summary_1.TransportType;
174var close_reason_1 = require("./client/close-reason");
175exports.CloseReasonEnum = close_reason_1.CloseReasonEnum;
176var session_details_1 = require("./client/session-details");
177exports.DetailType = session_details_1.DetailType;
178var client_control_1 = require("./features/client-control");
179exports.SessionEventType = client_control_1.SessionEventType;
180var messages_1 = require("./features/messages");
181exports.Priority = messages_1.Priority;
182var security_1 = require("./features/security");
183exports.GlobalPermission = security_1.GlobalPermission;
184exports.TopicPermission = security_1.TopicPermission;
185var session_lock_options_2 = require("./features/session-lock-options");
186exports.SessionLockScope = session_lock_options_2.SessionLockScope;
187var topic_notifications_1 = require("./features/topic-notifications");
188exports.TopicNotificationType = topic_notifications_1.TopicNotificationType;
189var topic_selector_1 = require("./selectors/topic-selector");
190exports.Prefix = topic_selector_1.Prefix;
191exports.Type = topic_selector_1.Type;
192var topic_update_2 = require("./topic-update/topic-update");
193exports.TopicCreationResult = topic_update_2.TopicCreationResult;
194var logger_1 = require("./util/logger");
195exports.LogLevel = logger_1.LogLevel;