Skip to content

Fix some TypeScript errors found with TypeScript 4.5 / Deno #829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* @private
*/
class Connection {
id: string
databaseId: string
id: string = ""
databaseId: string = ""
server: any

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/internal/connection-holder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class ConnectionHolder implements ConnectionHolderInterface {
*/
private _releaseConnection(): Promise<Connection | void> {
this._connectionPromise = this._connectionPromise
.then((connection?: Connection) => {
.then((connection?: Connection|void) => {
if (connection) {
if (connection.isOpen()) {
return connection
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/internal/observers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,6 @@ export class FailedObserver implements ResultStreamObserver {

function apply<T>(thisArg: any, func?: (param: T) => void, param?: T): void {
if (func) {
func.bind(thisArg)(param)
func.bind(thisArg)(param as any)
}
}
3 changes: 2 additions & 1 deletion packages/core/src/internal/transaction-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ type TransactionCreator = () => Transaction
type TransactionWork<T> = (tx: Transaction) => T | Promise<T>
type Resolve<T> = (value: T | PromiseLike<T>) => void
type Reject = (value: any) => void
type Timeout = ReturnType<typeof setTimeout>

export class TransactionExecutor {
private _maxRetryTimeMs: number
private _initialRetryDelayMs: number
private _multiplier: number
private _jitterFactor: number
private _inFlightTimeoutIds: NodeJS.Timeout[]
private _inFlightTimeoutIds: Timeout[]

constructor(
maxRetryTimeMs?: number | null,
Expand Down
17 changes: 1 addition & 16 deletions packages/neo4j-driver-lite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* limitations under the License.
*/
import VERSION from './version'
import { logging } from './logging'

import {
Neo4jError,
Expand Down Expand Up @@ -79,7 +80,6 @@ type EncryptionLevel = coreTypes.EncryptionLevel
type SessionMode = coreTypes.SessionMode
type Logger = internal.logger.Logger
type ConfiguredCustomResolver = internal.resolver.ConfiguredCustomResolver
type LogLevel = coreTypes.LogLevel

const { READ, WRITE } = coreDriver

Expand Down Expand Up @@ -327,21 +327,6 @@ function driver (

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

/**
* Object containing predefined logging configurations. These are expected to be used as values of the driver config's `logging` property.
* @property {function(level: ?string): object} console the function to create a logging config that prints all messages to `console.log` with
* timestamp, level and message. It takes an optional `level` parameter which represents the maximum log level to be logged. Default value is 'info'.
*/
const logging = {
console: (level: LogLevel) => {
return {
level: level,
logger: (level: LogLevel, message: string) =>
console.log(`${global.Date.now()} ${level.toUpperCase()} ${message}`)
}
}
}

/**
* Object containing constructors for all neo4j types.
*/
Expand Down
20 changes: 20 additions & 0 deletions packages/neo4j-driver-lite/src/logging.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { types as coreTypes } from 'neo4j-driver-core'

type LogLevel = coreTypes.LogLevel

/**
* Object containing predefined logging configurations. These are expected to be used as values of the driver config's `logging` property.
* @property {function(level: ?string): object} console the function to create a logging config that prints all messages to `console.log` with
* timestamp, level and message. It takes an optional `level` parameter which represents the maximum log level to be logged. Default value is 'info'.
*/
export const logging = {
console: (level: LogLevel) => {
return {
level: level,
logger: (level: LogLevel, message: string) =>
console.log(`${Date.now()} ${level.toUpperCase()} ${message}`)
// Note: This 'logging' object is in its own file so we can easily access the global Date object here without conflicting
// with the Neo4j Date class, and without relying on 'globalThis' which isn't compatible with Node 10.
}
}
}