1 | ;
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
6 |
|
7 | Object.defineProperty(exports, "__esModule", {
|
8 | value: true
|
9 | });
|
10 | exports.driver = driver;
|
11 | Object.defineProperty(exports, "int", {
|
12 | enumerable: true,
|
13 | get: function get() {
|
14 | return _integer["int"];
|
15 | }
|
16 | });
|
17 | Object.defineProperty(exports, "isInt", {
|
18 | enumerable: true,
|
19 | get: function get() {
|
20 | return _integer.isInt;
|
21 | }
|
22 | });
|
23 | Object.defineProperty(exports, "Neo4jError", {
|
24 | enumerable: true,
|
25 | get: function get() {
|
26 | return _error.Neo4jError;
|
27 | }
|
28 | });
|
29 | Object.defineProperty(exports, "isPoint", {
|
30 | enumerable: true,
|
31 | get: function get() {
|
32 | return _spatialTypes.isPoint;
|
33 | }
|
34 | });
|
35 | Object.defineProperty(exports, "isDate", {
|
36 | enumerable: true,
|
37 | get: function get() {
|
38 | return _temporalTypes.isDate;
|
39 | }
|
40 | });
|
41 | Object.defineProperty(exports, "isDateTime", {
|
42 | enumerable: true,
|
43 | get: function get() {
|
44 | return _temporalTypes.isDateTime;
|
45 | }
|
46 | });
|
47 | Object.defineProperty(exports, "isDuration", {
|
48 | enumerable: true,
|
49 | get: function get() {
|
50 | return _temporalTypes.isDuration;
|
51 | }
|
52 | });
|
53 | Object.defineProperty(exports, "isLocalDateTime", {
|
54 | enumerable: true,
|
55 | get: function get() {
|
56 | return _temporalTypes.isLocalDateTime;
|
57 | }
|
58 | });
|
59 | Object.defineProperty(exports, "isLocalTime", {
|
60 | enumerable: true,
|
61 | get: function get() {
|
62 | return _temporalTypes.isLocalTime;
|
63 | }
|
64 | });
|
65 | Object.defineProperty(exports, "isTime", {
|
66 | enumerable: true,
|
67 | get: function get() {
|
68 | return _temporalTypes.isTime;
|
69 | }
|
70 | });
|
71 | exports["default"] = exports.temporal = exports.spatial = exports.error = exports.session = exports.types = exports.logging = exports.auth = exports.integer = void 0;
|
72 |
|
73 | var _integer = _interopRequireWildcard(require("./integer"));
|
74 |
|
75 | var _graphTypes = require("./graph-types");
|
76 |
|
77 | var _error = require("./error");
|
78 |
|
79 | var _result = _interopRequireDefault(require("./result"));
|
80 |
|
81 | var _resultSummary = _interopRequireDefault(require("./result-summary"));
|
82 |
|
83 | var _record = _interopRequireDefault(require("./record"));
|
84 |
|
85 | var _driver = require("./driver");
|
86 |
|
87 | var _routingDriver = _interopRequireDefault(require("./routing-driver"));
|
88 |
|
89 | var _version = _interopRequireDefault(require("./version"));
|
90 |
|
91 | var _util = require("./internal/util");
|
92 |
|
93 | var _urlUtil = _interopRequireDefault(require("./internal/url-util"));
|
94 |
|
95 | var _spatialTypes = require("./spatial-types");
|
96 |
|
97 | var _temporalTypes = require("./temporal-types");
|
98 |
|
99 | var _serverAddress = _interopRequireDefault(require("./internal/server-address"));
|
100 |
|
101 | /**
|
102 | * Copyright (c) 2002-2019 "Neo4j,"
|
103 | * Neo4j Sweden AB [http://neo4j.com]
|
104 | *
|
105 | * This file is part of Neo4j.
|
106 | *
|
107 | * Licensed under the Apache License, Version 2.0 (the "License");
|
108 | * you may not use this file except in compliance with the License.
|
109 | * You may obtain a copy of the License at
|
110 | *
|
111 | * http://www.apache.org/licenses/LICENSE-2.0
|
112 | *
|
113 | * Unless required by applicable law or agreed to in writing, software
|
114 | * distributed under the License is distributed on an "AS IS" BASIS,
|
115 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
116 | * See the License for the specific language governing permissions and
|
117 | * limitations under the License.
|
118 | */
|
119 |
|
120 | /**
|
121 | * @property {function(username: string, password: string, realm: ?string)} basic the function to create a
|
122 | * basic authentication token.
|
123 | * @property {function(base64EncodedTicket: string)} kerberos the function to create a Kerberos authentication token.
|
124 | * Accepts a single string argument - base64 encoded Kerberos ticket.
|
125 | * @property {function(principal: string, credentials: string, realm: string, scheme: string, parameters: ?object)} custom
|
126 | * the function to create a custom authentication token.
|
127 | */
|
128 | var auth = {
|
129 | basic: function basic(username, password) {
|
130 | var realm = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : undefined;
|
131 |
|
132 | if (realm) {
|
133 | return {
|
134 | scheme: 'basic',
|
135 | principal: username,
|
136 | credentials: password,
|
137 | realm: realm
|
138 | };
|
139 | } else {
|
140 | return {
|
141 | scheme: 'basic',
|
142 | principal: username,
|
143 | credentials: password
|
144 | };
|
145 | }
|
146 | },
|
147 | kerberos: function kerberos(base64EncodedTicket) {
|
148 | return {
|
149 | scheme: 'kerberos',
|
150 | principal: '',
|
151 | // This empty string is required for backwards compatibility.
|
152 | credentials: base64EncodedTicket
|
153 | };
|
154 | },
|
155 | custom: function custom(principal, credentials, realm, scheme) {
|
156 | var parameters = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : undefined;
|
157 |
|
158 | if (parameters) {
|
159 | return {
|
160 | scheme: scheme,
|
161 | principal: principal,
|
162 | credentials: credentials,
|
163 | realm: realm,
|
164 | parameters: parameters
|
165 | };
|
166 | } else {
|
167 | return {
|
168 | scheme: scheme,
|
169 | principal: principal,
|
170 | credentials: credentials,
|
171 | realm: realm
|
172 | };
|
173 | }
|
174 | }
|
175 | };
|
176 | exports.auth = auth;
|
177 | var USER_AGENT = 'neo4j-javascript/' + _version["default"];
|
178 | /**
|
179 | * Object containing predefined logging configurations. These are expected to be used as values of the driver config's `logging` property.
|
180 | * @property {function(level: ?string): object} console the function to create a logging config that prints all messages to `console.log` with
|
181 | * timestamp, level and message. It takes an optional `level` parameter which represents the maximum log level to be logged. Default value is 'info'.
|
182 | */
|
183 |
|
184 | var logging = {
|
185 | console: function (_console) {
|
186 | function console(_x) {
|
187 | return _console.apply(this, arguments);
|
188 | }
|
189 |
|
190 | console.toString = function () {
|
191 | return _console.toString();
|
192 | };
|
193 |
|
194 | return console;
|
195 | }(function (level) {
|
196 | return {
|
197 | level: level,
|
198 | logger: function logger(level, message) {
|
199 | return console.log("".concat(global.Date.now(), " ").concat(level.toUpperCase(), " ").concat(message));
|
200 | }
|
201 | };
|
202 | })
|
203 | /**
|
204 | * Construct a new Neo4j Driver. This is your main entry point for this
|
205 | * library.
|
206 | *
|
207 | * ## Configuration
|
208 | *
|
209 | * This function optionally takes a configuration argument. Available configuration
|
210 | * options are as follows:
|
211 | *
|
212 | * {
|
213 | * // Encryption level: ENCRYPTION_ON or ENCRYPTION_OFF.
|
214 | * encrypted: ENCRYPTION_ON|ENCRYPTION_OFF
|
215 | *
|
216 | * // Trust strategy to use if encryption is enabled. There is no mode to disable
|
217 | * // trust other than disabling encryption altogether. The reason for
|
218 | * // this is that if you don't know who you are talking to, it is easy for an
|
219 | * // attacker to hijack your encrypted connection, rendering encryption pointless.
|
220 | * //
|
221 | * // TRUST_SYSTEM_CA_SIGNED_CERTIFICATES is the default choice. For NodeJS environments, this
|
222 | * // means that you trust whatever certificates are in the default trusted certificate
|
223 | * // store of the underlying system. For Browser environments, the trusted certificate
|
224 | * // store is usually managed by the browser. Refer to your system or browser documentation
|
225 | * // if you want to explicitly add a certificate as trusted.
|
226 | * //
|
227 | * // TRUST_CUSTOM_CA_SIGNED_CERTIFICATES is another option for trust verification -
|
228 | * // whenever we establish an encrypted connection, we ensure the host is using
|
229 | * // an encryption certificate that is in, or is signed by, a certificate given
|
230 | * // as trusted through configuration. This option is only available for NodeJS environments.
|
231 | * //
|
232 | * // TRUST_ALL_CERTIFICATES means that you trust everything without any verifications
|
233 | * // steps carried out. This option is only available for NodeJS environments and should not
|
234 | * // be used on production systems.
|
235 | * trust: "TRUST_SYSTEM_CA_SIGNED_CERTIFICATES" | "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES" |
|
236 | * "TRUST_ALL_CERTIFICATES",
|
237 | *
|
238 | * // List of one or more paths to trusted encryption certificates. This only
|
239 | * // works in the NodeJS bundle, and only matters if you use "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES".
|
240 | * // The certificate files should be in regular X.509 PEM format.
|
241 | * // For instance, ['./trusted.pem']
|
242 | * trustedCertificates: [],
|
243 | *
|
244 | * // The maximum total number of connections allowed to be managed by the connection pool, per host.
|
245 | * // This includes both in-use and idle connections. No maximum connection pool size is imposed
|
246 | * // by default.
|
247 | * maxConnectionPoolSize: 100,
|
248 | *
|
249 | * // The maximum allowed lifetime for a pooled connection in milliseconds. Pooled connections older than this
|
250 | * // threshold will be closed and removed from the pool. Such discarding happens during connection acquisition
|
251 | * // so that new session is never backed by an old connection. Setting this option to a low value will cause
|
252 | * // a high connection churn and might result in a performance hit. It is recommended to set maximum lifetime
|
253 | * // to a slightly smaller value than the one configured in network equipment (load balancer, proxy, firewall,
|
254 | * // etc. can also limit maximum connection lifetime). No maximum lifetime limit is imposed by default. Zero
|
255 | * // and negative values result in lifetime not being checked.
|
256 | * maxConnectionLifetime: 60 * 60 * 1000, // 1 hour
|
257 | *
|
258 | * // The maximum amount of time to wait to acquire a connection from the pool (to either create a new
|
259 | * // connection or borrow an existing one.
|
260 | * connectionAcquisitionTimeout: 60000, // 1 minute
|
261 | *
|
262 | * // Specify the maximum time in milliseconds transactions are allowed to retry via
|
263 | * // `Session#readTransaction()` and `Session#writeTransaction()` functions.
|
264 | * // These functions will retry the given unit of work on `ServiceUnavailable`, `SessionExpired` and transient
|
265 | * // errors with exponential backoff using initial delay of 1 second.
|
266 | * // Default value is 30000 which is 30 seconds.
|
267 | * maxTransactionRetryTime: 30000, // 30 seconds
|
268 | *
|
269 | * // Specify socket connection timeout in milliseconds. Numeric values are expected. Negative and zero values
|
270 | * // result in no timeout being applied. Connection establishment will be then bound by the timeout configured
|
271 | * // on the operating system level. Default value is 30000, which is 30 seconds.
|
272 | * connectionTimeout: 30000, // 30 seconds
|
273 | *
|
274 | * // Make this driver always return native JavaScript numbers for integer values, instead of the
|
275 | * // dedicated {@link Integer} class. Values that do not fit in native number bit range will be represented as
|
276 | * // `Number.NEGATIVE_INFINITY` or `Number.POSITIVE_INFINITY`.
|
277 | * // **Warning:** ResultSummary It is not always safe to enable this setting when JavaScript applications are not the only ones
|
278 | * // interacting with the database. Stored numbers might in such case be not representable by native
|
279 | * // {@link Number} type and thus driver will return lossy values. This might also happen when data was
|
280 | * // initially imported using neo4j import tool and contained numbers larger than
|
281 | * // `Number.MAX_SAFE_INTEGER`. Driver will then return positive infinity, which is lossy.
|
282 | * // Default value for this option is `false` because native JavaScript numbers might result
|
283 | * // in loss of precision in the general case.
|
284 | * disableLosslessIntegers: false,
|
285 | *
|
286 | * // Specify the logging configuration for the driver. Object should have two properties `level` and `logger`.
|
287 | * //
|
288 | * // Property `level` represents the logging level which should be one of: 'error', 'warn', 'info' or 'debug'. This property is optional and
|
289 | * // its default value is 'info'. Levels have priorities: 'error': 0, 'warn': 1, 'info': 2, 'debug': 3. Enabling a certain level also enables all
|
290 | * // levels with lower priority. For example: 'error', 'warn' and 'info' will be logged when 'info' level is configured.
|
291 | * //
|
292 | * // Property `logger` represents the logging function which will be invoked for every log call with an acceptable level. The function should
|
293 | * // take two string arguments `level` and `message`. The function should not execute any blocking or long-running operations
|
294 | * // because it is often executed on a hot path.
|
295 | * //
|
296 | * // No logging is done by default. See `neo4j.logging` object that contains predefined logging implementations.
|
297 | * logging: {
|
298 | * level: 'info',
|
299 | * logger: (level, message) => console.log(level + ' ' + message)
|
300 | * },
|
301 | *
|
302 | * // Specify a custom server address resolver function used by the routing driver to resolve the initial address used to create the driver.
|
303 | * // Such resolution happens:
|
304 | * // * during the very first rediscovery when driver is created
|
305 | * // * when all the known routers from the current routing table have failed and driver needs to fallback to the initial address
|
306 | * //
|
307 | * // In NodeJS environment driver defaults to performing a DNS resolution of the initial address using 'dns' module.
|
308 | * // In browser environment driver uses the initial address as-is.
|
309 | * // Value should be a function that takes a single string argument - the initial address. It should return an array of new addresses.
|
310 | * // Address is a string of shape '<host>:<port>'. Provided function can return either a Promise resolved with an array of addresses
|
311 | * // or array of addresses directly.
|
312 | * resolver: function(address) {
|
313 | * return ['127.0.0.1:8888', 'fallback.db.com:7687'];
|
314 | * },
|
315 | * }
|
316 | *
|
317 | * @param {string} url The URL for the Neo4j database, for instance "bolt://localhost"
|
318 | * @param {Map<string,string>} authToken Authentication credentials. See {@link auth} for helpers.
|
319 | * @param {Object} config Configuration object. See the configuration section above for details.
|
320 | * @returns {Driver}
|
321 | */
|
322 |
|
323 | };
|
324 | exports.logging = logging;
|
325 |
|
326 | function driver(url, authToken) {
|
327 | var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
328 | (0, _util.assertString)(url, 'Bolt URL');
|
329 |
|
330 | var parsedUrl = _urlUtil["default"].parseDatabaseUrl(url);
|
331 |
|
332 | if (parsedUrl.scheme === 'neo4j') {
|
333 | return new _routingDriver["default"](_serverAddress["default"].fromUrl(parsedUrl.hostAndPort), parsedUrl.query, USER_AGENT, authToken, config);
|
334 | } else if (parsedUrl.scheme === 'bolt') {
|
335 | if (!(0, _util.isEmptyObjectOrNull)(parsedUrl.query)) {
|
336 | throw new Error("Parameters are not supported with scheme 'bolt'. Given URL: '".concat(url, "'"));
|
337 | }
|
338 |
|
339 | return new _driver.Driver(_serverAddress["default"].fromUrl(parsedUrl.hostAndPort), USER_AGENT, authToken, config);
|
340 | } else {
|
341 | throw new Error("Unknown scheme: ".concat(parsedUrl.scheme));
|
342 | }
|
343 | }
|
344 | /**
|
345 | * Object containing constructors for all neo4j types.
|
346 | */
|
347 |
|
348 |
|
349 | var types = {
|
350 | Node: _graphTypes.Node,
|
351 | Relationship: _graphTypes.Relationship,
|
352 | UnboundRelationship: _graphTypes.UnboundRelationship,
|
353 | PathSegment: _graphTypes.PathSegment,
|
354 | Path: _graphTypes.Path,
|
355 | Result: _result["default"],
|
356 | ResultSummary: _resultSummary["default"],
|
357 | Record: _record["default"],
|
358 | Point: _spatialTypes.Point,
|
359 | Date: _temporalTypes.Date,
|
360 | DateTime: _temporalTypes.DateTime,
|
361 | Duration: _temporalTypes.Duration,
|
362 | LocalDateTime: _temporalTypes.LocalDateTime,
|
363 | LocalTime: _temporalTypes.LocalTime,
|
364 | Time: _temporalTypes.Time,
|
365 | Integer: _integer["default"]
|
366 | /**
|
367 | * Object containing string constants representing session access modes.
|
368 | */
|
369 |
|
370 | };
|
371 | exports.types = types;
|
372 | var session = {
|
373 | READ: _driver.READ,
|
374 | WRITE: _driver.WRITE
|
375 | /**
|
376 | * Object containing string constants representing predefined {@link Neo4jError} codes.
|
377 | */
|
378 |
|
379 | };
|
380 | exports.session = session;
|
381 | var error = {
|
382 | SERVICE_UNAVAILABLE: _error.SERVICE_UNAVAILABLE,
|
383 | SESSION_EXPIRED: _error.SESSION_EXPIRED,
|
384 | PROTOCOL_ERROR: _error.PROTOCOL_ERROR
|
385 | /**
|
386 | * Object containing functions to work with {@link Integer} objects.
|
387 | */
|
388 |
|
389 | };
|
390 | exports.error = error;
|
391 | var integer = {
|
392 | toNumber: _integer.toNumber,
|
393 | toString: _integer.toString,
|
394 | inSafeRange: _integer.inSafeRange
|
395 | /**
|
396 | * Object containing functions to work with spatial types, like {@link Point}.
|
397 | */
|
398 |
|
399 | };
|
400 | exports.integer = integer;
|
401 | var spatial = {
|
402 | isPoint: _spatialTypes.isPoint
|
403 | /**
|
404 | * Object containing functions to work with temporal types, like {@link Time} or {@link Duration}.
|
405 | */
|
406 |
|
407 | };
|
408 | exports.spatial = spatial;
|
409 | var temporal = {
|
410 | isDuration: _temporalTypes.isDuration,
|
411 | isLocalTime: _temporalTypes.isLocalTime,
|
412 | isTime: _temporalTypes.isTime,
|
413 | isDate: _temporalTypes.isDate,
|
414 | isLocalDateTime: _temporalTypes.isLocalDateTime,
|
415 | isDateTime: _temporalTypes.isDateTime
|
416 | /**
|
417 | * @private
|
418 | */
|
419 |
|
420 | };
|
421 | exports.temporal = temporal;
|
422 | var forExport = {
|
423 | driver: driver,
|
424 | "int": _integer["int"],
|
425 | isInt: _integer.isInt,
|
426 | isPoint: _spatialTypes.isPoint,
|
427 | isDuration: _temporalTypes.isDuration,
|
428 | isLocalTime: _temporalTypes.isLocalTime,
|
429 | isTime: _temporalTypes.isTime,
|
430 | isDate: _temporalTypes.isDate,
|
431 | isLocalDateTime: _temporalTypes.isLocalDateTime,
|
432 | isDateTime: _temporalTypes.isDateTime,
|
433 | integer: integer,
|
434 | Neo4jError: _error.Neo4jError,
|
435 | auth: auth,
|
436 | logging: logging,
|
437 | types: types,
|
438 | session: session,
|
439 | error: error,
|
440 | spatial: spatial,
|
441 | temporal: temporal
|
442 | };
|
443 | var _default = forExport;
|
444 | exports["default"] = _default; |
\ | No newline at end of file |