1717 * limitations under the License.
1818 */
1919
20+ import NotificationFilter from './notification-filter'
21+
2022/**
2123 * @private
2224 */
@@ -56,7 +58,12 @@ export interface BoltAgent {
5658 languageDetails ?: string
5759}
5860
59- export interface Config {
61+ /**
62+ * The Neo4j Driver configuration.
63+ *
64+ * @interface
65+ */
66+ export class Config {
6067 encrypted ?: boolean | EncryptionLevel
6168 trust ?: TrustStrategy
6269 trustedCertificates ?: string [ ]
@@ -68,13 +75,220 @@ export interface Config {
6875 connectionAcquisitionTimeout ?: number
6976 connectionTimeout ?: number
7077 disableLosslessIntegers ?: boolean
78+ notificationFilter ?: NotificationFilter
7179 useBigInt ?: boolean
7280 logging ?: LoggingConfig
7381 resolver ?: ( address : string ) => string [ ] | Promise < string [ ] >
7482 userAgent ?: string
83+
84+ /**
85+ * @constructor
86+ * @private
87+ */
88+ protected constructor ( ) {
89+ /**
90+ * Encryption level
91+ *
92+ * @type {'ENCRYPTION_ON'|'ENCRYPTION_OFF'|undefined }
93+ */
94+ this . encrypted = undefined
95+
96+ /**
97+ * Trust strategy to use if encryption is enabled.
98+ *
99+ * There is no mode to disable trust other than disabling encryption altogether. The reason for
100+ * this is that if you don't know who you are talking to, it is easy for an
101+ * attacker to hijack your encrypted connection, rendering encryption pointless.
102+ *
103+ * TRUST_SYSTEM_CA_SIGNED_CERTIFICATES is the default choice. For NodeJS environments, this
104+ * means that you trust whatever certificates are in the default trusted certificate
105+ * store of the underlying system. For Browser environments, the trusted certificate
106+ * store is usually managed by the browser. Refer to your system or browser documentation
107+ * if you want to explicitly add a certificate as trusted.
108+ *
109+ * TRUST_CUSTOM_CA_SIGNED_CERTIFICATES is another option for trust verification -
110+ * whenever we establish an encrypted connection, we ensure the host is using
111+ * an encryption certificate that is in, or is signed by, a certificate given
112+ * as trusted through configuration. This option is only available for NodeJS environments.
113+ *
114+ * TRUST_ALL_CERTIFICATES means that you trust everything without any verifications
115+ * steps carried out. This option is only available for NodeJS environments and should not
116+ * be used on production systems.
117+ *
118+ * @type {'TRUST_SYSTEM_CA_SIGNED_CERTIFICATES'|'TRUST_CUSTOM_CA_SIGNED_CERTIFICATES'|'TRUST_ALL_CERTIFICATES'|undefined }
119+ */
120+ this . trust = undefined
121+
122+ /**
123+ * List of one or more paths to trusted encryption certificates.
124+ *
125+ * This only works in the NodeJS bundle,
126+ * and only matters if you use "TRUST_CUSTOM_CA_SIGNED_CERTIFICATES".
127+ *
128+ * The certificate files should be in regular X.509 PEM format.
129+ *
130+ * For instance, ['./trusted.pem']
131+ *
132+ * @type {?string[] }
133+ * @see {@link Config#trust }
134+ */
135+ this . trustedCertificates = [ ]
136+
137+ /**
138+ * The maximum total number of connections allowed to be managed by the connection pool, per host.
139+ *
140+ * This includes both in-use and idle connections.
141+ *
142+ * **Default**: ```100```
143+ *
144+ * @type {number|undefined }
145+ */
146+ this . maxConnectionPoolSize = 100
147+
148+ /**
149+ * The maximum allowed lifetime for a pooled connection in milliseconds.
150+ *
151+ * Pooled connections older than this
152+ * threshold will be closed and removed from the pool. Such discarding happens during connection acquisition
153+ * so that new session is never backed by an old connection. Setting this option to a low value will cause
154+ * a high connection churn and might result in a performance hit. It is recommended to set maximum lifetime
155+ * to a slightly smaller value than the one configured in network equipment (load balancer, proxy, firewall,
156+ * etc. can also limit maximum connection lifetime). No maximum lifetime limit is imposed by default. Zero
157+ * and negative values result in lifetime not being checked.
158+ *
159+ * **Default**: ```60 * 60 * 1000``` (1 hour)
160+ *
161+ * @type {number|undefined }
162+ */
163+ this . maxConnectionLifetime = 60 * 60 * 1000 // 1 hour
164+
165+ /**
166+ * The maximum amount of time to wait to acquire a connection from the pool (to either create a new
167+ * connection or borrow an existing one).
168+ *
169+ * **Default**: ```60000``` (1 minute)
170+ *
171+ * @type {number|undefined }
172+ */
173+ this . connectionAcquisitionTimeout = 60000 // 1 minute
174+
175+ /**
176+ * Specify the maximum time in milliseconds transactions are allowed to retry via
177+ * {@link Session#executeRead} and {@link Session#executeWrite} functions.
178+ *
179+ * These functions will retry the given unit of work on `ServiceUnavailable`, `SessionExpired` and transient
180+ * errors with exponential backoff using an initial delay of 1 second.
181+ *
182+ * **Default**: ```30000``` (30 seconds)
183+ *
184+ * @type {number|undefined }
185+ */
186+ this . maxTransactionRetryTime = 30000 // 30 seconds
187+
188+ /**
189+ * Specify socket connection timeout in milliseconds.
190+ *
191+ * Negative and zero values result in no timeout being applied.
192+ * Connection establishment will be then bound by the timeout configured
193+ * on the operating system level.
194+ *
195+ * **Default**: ```30000``` (30 seconds)
196+ *
197+ * @type {number|undefined }
198+ */
199+ this . connectionTimeout = 30000 // 30 seconds
200+
201+ /**
202+ * Make this driver always return native JavaScript numbers for integer values, instead of the
203+ * dedicated {@link Integer} class.
204+ *
205+ * Values that do not fit in native number bit range will be represented as `Number.NEGATIVE_INFINITY` or `Number.POSITIVE_INFINITY`.
206+ *
207+ * **Warning:** {@link ResultSummary} It is not always safe to enable this setting when JavaScript applications are not the only ones
208+ * interacting with the database. Stored numbers might in such case be not representable by native
209+ * `Number` type and thus the driver will return lossy values. This might also happen when data was
210+ * initially imported using neo4j import tool and contained numbers larger than
211+ * `Number.MAX_SAFE_INTEGER`. Driver will then return positive infinity, which is lossy.
212+ *
213+ * **Default**: ```false```
214+ *
215+ * Default value for this option is `false` because native JavaScript numbers might result
216+ * in loss of precision in the general case.
217+ *
218+ * @type {boolean|undefined }
219+ */
220+ this . disableLosslessIntegers = false
221+
222+ /**
223+ * Make this driver always return native Javascript `BigInt` for integer values,
224+ * instead of the dedicated {@link Integer} class or `Number`.
225+ *
226+ * **Warning:** `BigInt` doesn't implement the method `toJSON`. To serialize it as `json`,
227+ * it's needed to add a custom implementation of the `toJSON` on the
228+ * `BigInt.prototype`. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#use_within_json.
229+ *
230+ * **Default**: ```false``` (for backwards compatibility)
231+ *
232+ * @type {boolean|undefined }
233+ */
234+ this . useBigInt = false
235+
236+ /**
237+ * Specify the logging configuration for the driver. Object should have two properties `level` and `logger`.
238+ *
239+ * Property `level` represents the logging level which should be one of: 'error', 'warn', 'info' or 'debug'. This property is optional and
240+ * its default value is 'info'. Levels have priorities: 'error': 0, 'warn': 1, 'info': 2, 'debug': 3. Enabling a certain level also enables all
241+ * levels with lower priority. For example: 'error', 'warn' and 'info' will be logged when 'info' level is configured.
242+ *
243+ * Property `logger` represents the logging function which will be invoked for every log call with an acceptable level. The function should
244+ * take two string arguments `level` and `message`. The function should not execute any blocking or long-running operations
245+ * because it is often executed on a hot path.
246+ *
247+ * No logging is done by default. See `neo4j.logging` object that contains predefined logging implementations.
248+ *
249+ * @type {LoggingConfig|undefined }
250+ * @see {@link logging }
251+ */
252+ this . logging = undefined
253+
254+ /**
255+ * Specify a custom server address resolver function used by the routing driver to resolve the initial address used to create the driver.
256+ *
257+ * Such resolution happens:
258+ * * during the very first rediscovery when driver is created
259+ * * when all the known routers from the current routing table have failed and driver needs to fallback to the initial address
260+ *
261+ * In NodeJS environment driver defaults to performing a DNS resolution of the initial address using 'dns' module.
262+ * In browser environment driver uses the initial address as-is.
263+ * Value should be a function that takes a single string argument - the initial address. It should return an array of new addresses.
264+ * Address is a string of shape '<host>:<port>'. Provided function can return either a Promise resolved with an array of addresses
265+ * or array of addresses directly.
266+ *
267+ * @type {function(address: string) {} |undefined }
268+ */
269+ this . resolver = undefined
270+
271+ /**
272+ * Configure filter for Notification objects returned in {@Link ResultSummary#notifications}.
273+ *
274+ * See {@link SessionConfig#notificationFilter} for usage instructions.
275+ *
276+ * @type {NotificationFilter|undefined }
277+ */
278+ this . notificationFilter = undefined
279+
280+ /**
281+ * Optionally override the default user agent name.
282+ *
283+ * **Default**: ```'neo4j-javascript/<version>'```
284+ *
285+ * @type {string|undefined }
286+ */
287+ this . userAgent = undefined
288+ }
75289}
76290
77- export interface InternalConfig extends Config {
291+ export class InternalConfig extends Config {
78292 boltAgent ?: BoltAgent
79293}
80294
0 commit comments