Skip to content

Commit 7386e26

Browse files
Fix some TypeScript errors found with TypeScript 4.5 / Deno (#829)
* Fix TypeScript errors found by Deno with TypeScript 4.5 * Change some Node-specific types to generic ones * Fix Node 10 compatibility (address review comment)
1 parent bc6b388 commit 7386e26

File tree

6 files changed

+27
-21
lines changed

6 files changed

+27
-21
lines changed

packages/core/src/connection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
* @private
2323
*/
2424
class Connection {
25-
id: string
26-
databaseId: string
25+
id: string = ""
26+
databaseId: string = ""
2727
server: any
2828

2929
/**

packages/core/src/internal/connection-holder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class ConnectionHolder implements ConnectionHolderInterface {
194194
*/
195195
private _releaseConnection(): Promise<Connection | void> {
196196
this._connectionPromise = this._connectionPromise
197-
.then((connection?: Connection) => {
197+
.then((connection?: Connection|void) => {
198198
if (connection) {
199199
if (connection.isOpen()) {
200200
return connection

packages/core/src/internal/observers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,6 @@ export class FailedObserver implements ResultStreamObserver {
174174

175175
function apply<T>(thisArg: any, func?: (param: T) => void, param?: T): void {
176176
if (func) {
177-
func.bind(thisArg)(param)
177+
func.bind(thisArg)(param as any)
178178
}
179179
}

packages/core/src/internal/transaction-executor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ type TransactionCreator = () => Transaction
3030
type TransactionWork<T> = (tx: Transaction) => T | Promise<T>
3131
type Resolve<T> = (value: T | PromiseLike<T>) => void
3232
type Reject = (value: any) => void
33+
type Timeout = ReturnType<typeof setTimeout>
3334

3435
export class TransactionExecutor {
3536
private _maxRetryTimeMs: number
3637
private _initialRetryDelayMs: number
3738
private _multiplier: number
3839
private _jitterFactor: number
39-
private _inFlightTimeoutIds: NodeJS.Timeout[]
40+
private _inFlightTimeoutIds: Timeout[]
4041

4142
constructor(
4243
maxRetryTimeMs?: number | null,

packages/neo4j-driver-lite/src/index.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* limitations under the License.
1818
*/
1919
import VERSION from './version'
20+
import { logging } from './logging'
2021

2122
import {
2223
Neo4jError,
@@ -79,7 +80,6 @@ type EncryptionLevel = coreTypes.EncryptionLevel
7980
type SessionMode = coreTypes.SessionMode
8081
type Logger = internal.logger.Logger
8182
type ConfiguredCustomResolver = internal.resolver.ConfiguredCustomResolver
82-
type LogLevel = coreTypes.LogLevel
8383

8484
const { READ, WRITE } = coreDriver
8585

@@ -327,21 +327,6 @@ function driver (
327327

328328
const USER_AGENT: string = 'neo4j-javascript/' + VERSION
329329

330-
/**
331-
* Object containing predefined logging configurations. These are expected to be used as values of the driver config's `logging` property.
332-
* @property {function(level: ?string): object} console the function to create a logging config that prints all messages to `console.log` with
333-
* timestamp, level and message. It takes an optional `level` parameter which represents the maximum log level to be logged. Default value is 'info'.
334-
*/
335-
const logging = {
336-
console: (level: LogLevel) => {
337-
return {
338-
level: level,
339-
logger: (level: LogLevel, message: string) =>
340-
console.log(`${global.Date.now()} ${level.toUpperCase()} ${message}`)
341-
}
342-
}
343-
}
344-
345330
/**
346331
* Object containing constructors for all neo4j types.
347332
*/
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { types as coreTypes } from 'neo4j-driver-core'
2+
3+
type LogLevel = coreTypes.LogLevel
4+
5+
/**
6+
* Object containing predefined logging configurations. These are expected to be used as values of the driver config's `logging` property.
7+
* @property {function(level: ?string): object} console the function to create a logging config that prints all messages to `console.log` with
8+
* timestamp, level and message. It takes an optional `level` parameter which represents the maximum log level to be logged. Default value is 'info'.
9+
*/
10+
export const logging = {
11+
console: (level: LogLevel) => {
12+
return {
13+
level: level,
14+
logger: (level: LogLevel, message: string) =>
15+
console.log(`${Date.now()} ${level.toUpperCase()} ${message}`)
16+
// Note: This 'logging' object is in its own file so we can easily access the global Date object here without conflicting
17+
// with the Neo4j Date class, and without relying on 'globalThis' which isn't compatible with Node 10.
18+
}
19+
}
20+
}

0 commit comments

Comments
 (0)