Skip to content

Remove circular dependencies #662

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 4 commits into from
Jan 15, 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
13 changes: 1 addition & 12 deletions src/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,17 +275,6 @@ class Driver {
})
}

/**
* @protected
*/
static _validateSessionMode (rawMode) {
const mode = rawMode || WRITE
if (mode !== ACCESS_MODE_READ && mode !== ACCESS_MODE_WRITE) {
throw newError('Illegal session mode ' + mode)
}
return mode
}

/**
* @private
*/
Expand All @@ -296,7 +285,7 @@ class Driver {
reactive,
fetchSize
}) {
const sessionMode = Driver._validateSessionMode(defaultAccessMode)
const sessionMode = Session._validateSessionMode(defaultAccessMode)
const connectionProvider = this._getOrCreateConnectionProvider()
const bookmark = bookmarkOrBookmarks
? new Bookmark(bookmarkOrBookmarks)
Expand Down
4 changes: 2 additions & 2 deletions src/internal/connectivity-verifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import ConnectionHolder from './connection-holder'
import { READ } from '../driver'
import { ACCESS_MODE_READ } from './constants'
import { ResultStreamObserver } from './bolt'

/**
Expand Down Expand Up @@ -49,7 +49,7 @@ export default class ConnectivityVerifier {
*/
function acquireAndReleaseDummyConnection (connectionProvider, database) {
const connectionHolder = new ConnectionHolder({
mode: READ,
mode: ACCESS_MODE_READ,
database,
connectionProvider
})
Expand Down
5 changes: 2 additions & 3 deletions src/internal/node/node-utf8.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* limitations under the License.
*/

import CombinedBuffer from '../buf/combined-buf'
import NodeBuffer from './node-buf'
import { newError } from '../../error'
import node from 'buffer'
Expand All @@ -30,9 +29,9 @@ function encode (str) {
}

function decode (buffer, length) {
if (buffer instanceof NodeBuffer) {
if (Object.prototype.hasOwnProperty.call(buffer, '_buffer')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there should be a decode function on NodeBuffer and CombinedBuffer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, It should be a method present in all the buffers versions, the issue is way it's done vary a bit between buffer types, I could not figure out a way to do it properly.

return decodeNodeBuffer(buffer, length)
} else if (buffer instanceof CombinedBuffer) {
} else if (Object.prototype.hasOwnProperty.call(buffer, '_buffers')) {
return decodeCombinedBuffer(buffer, length)
} else {
throw newError(`Don't know how to decode strings from '${buffer}'`)
Expand Down
9 changes: 6 additions & 3 deletions src/internal/packstream-v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,15 @@ import {
import { int, isInt } from '../integer'
import {
dateToEpochDay,
localDateTimeToEpochSecond,
localTimeToNanoOfDay
} from './temporal-util'

import {
epochDayToDate,
epochSecondAndNanoToLocalDateTime,
localDateTimeToEpochSecond,
localTimeToNanoOfDay,
nanoOfDayToLocalTime
} from './temporal-util'
} from './temporal-factory'

const POINT_2D = 0x58
const POINT_2D_STRUCT_SIZE = 3
Expand Down
137 changes: 137 additions & 0 deletions src/internal/temporal-factory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/**
* Copyright (c) 2002-2020 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Date, LocalDateTime, LocalTime } from '../temporal-types'
import { int } from '../integer'
import {
DAYS_0000_TO_1970,
DAYS_PER_400_YEAR_CYCLE,
NANOS_PER_HOUR,
NANOS_PER_MINUTE,
NANOS_PER_SECOND,
SECONDS_PER_DAY,
floorDiv,
floorMod
} from './temporal-util'

/**
* Converts given epoch day to a local date.
* @param {Integer|number|string} epochDay the epoch day to convert.
* @return {Date} the date representing the epoch day in years, months and days.
*/
export function epochDayToDate (epochDay) {
epochDay = int(epochDay)

let zeroDay = epochDay.add(DAYS_0000_TO_1970).subtract(60)
let adjust = int(0)
if (zeroDay.lessThan(0)) {
const adjustCycles = zeroDay
.add(1)
.div(DAYS_PER_400_YEAR_CYCLE)
.subtract(1)
adjust = adjustCycles.multiply(400)
zeroDay = zeroDay.add(adjustCycles.multiply(-DAYS_PER_400_YEAR_CYCLE))
}
let year = zeroDay
.multiply(400)
.add(591)
.div(DAYS_PER_400_YEAR_CYCLE)
let dayOfYearEst = zeroDay.subtract(
year
.multiply(365)
.add(year.div(4))
.subtract(year.div(100))
.add(year.div(400))
)
if (dayOfYearEst.lessThan(0)) {
year = year.subtract(1)
dayOfYearEst = zeroDay.subtract(
year
.multiply(365)
.add(year.div(4))
.subtract(year.div(100))
.add(year.div(400))
)
}
year = year.add(adjust)
const marchDayOfYear = dayOfYearEst

const marchMonth = marchDayOfYear
.multiply(5)
.add(2)
.div(153)
const month = marchMonth
.add(2)
.modulo(12)
.add(1)
const day = marchDayOfYear
.subtract(
marchMonth
.multiply(306)
.add(5)
.div(10)
)
.add(1)
year = year.add(marchMonth.div(10))

return new Date(year, month, day)
}

/**
* Converts nanoseconds of the day into local time.
* @param {Integer|number|string} nanoOfDay the nanoseconds of the day to convert.
* @return {LocalTime} the local time representing given nanoseconds of the day.
*/
export function nanoOfDayToLocalTime (nanoOfDay) {
nanoOfDay = int(nanoOfDay)

const hour = nanoOfDay.div(NANOS_PER_HOUR)
nanoOfDay = nanoOfDay.subtract(hour.multiply(NANOS_PER_HOUR))

const minute = nanoOfDay.div(NANOS_PER_MINUTE)
nanoOfDay = nanoOfDay.subtract(minute.multiply(NANOS_PER_MINUTE))

const second = nanoOfDay.div(NANOS_PER_SECOND)
const nanosecond = nanoOfDay.subtract(second.multiply(NANOS_PER_SECOND))

return new LocalTime(hour, minute, second, nanosecond)
}

/**
* Converts given epoch second and nanosecond adjustment into a local date time object.
* @param {Integer|number|string} epochSecond the epoch second to use.
* @param {Integer|number|string} nano the nanosecond to use.
* @return {LocalDateTime} the local date time representing given epoch second and nano.
*/
export function epochSecondAndNanoToLocalDateTime (epochSecond, nano) {
const epochDay = floorDiv(epochSecond, SECONDS_PER_DAY)
const secondsOfDay = floorMod(epochSecond, SECONDS_PER_DAY)
const nanoOfDay = secondsOfDay.multiply(NANOS_PER_SECOND).add(nano)

const localDate = epochDayToDate(epochDay)
const localTime = nanoOfDayToLocalTime(nanoOfDay)
return new LocalDateTime(
localDate.year,
localDate.month,
localDate.day,
localTime.hour,
localTime.minute,
localTime.second,
localTime.nanosecond
)
}
Loading