Skip to content

Fix inconsistent typing of duration properties #1265

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

Open
wants to merge 5 commits into
base: 6.x
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,8 @@ exports[`#unit BoltProtocolV1 .packable() should pack types introduced afterward
{
"days": 1,
"months": 1,
"nanoseconds": Integer {
"high": 0,
"low": 1,
},
"seconds": Integer {
"high": 0,
"low": 1,
},
"nanoseconds": 1,
"seconds": 1,
}
`;

Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/integer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,13 @@ const inSafeRange = Integer.inSafeRange
*/
const toNumber = Integer.toNumber

/**
* Converts a variable to a BigInt
* @access public
* @param {Mixed} value - The variable to convert
* @return {BigInt} - the variable as a BigInt
*/
const toBigInt = Integer.valueOf
/**
* Converts the integer to a string representation
* @access public
Expand All @@ -1109,6 +1116,6 @@ const toNumber = Integer.toNumber
*/
const toString = Integer.toString

export { int, isInt, inSafeRange, toNumber, toString }
export { int, isInt, inSafeRange, toNumber, toBigInt, toString }

export default Integer
2 changes: 1 addition & 1 deletion packages/core/src/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class Result<R extends RecordShape = RecordShape> implements Promise<QueryResult
/**
* Provides a async iterator over the records in the result.
*
* *Should not be combined with {@link Result#subscribe} or ${@link Result#then} functions.*
* *Should not be combined with {@link Result#subscribe} or {@link Result#then} functions.*
*
* @public
* @returns {PeekableAsyncIterator<Record<R>, ResultSummary>} The async iterator for the Results
Expand Down
10 changes: 9 additions & 1 deletion packages/core/src/temporal-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
assertValidDate
} from './internal/util'
import { newError } from './error'
import Integer, { int, toNumber } from './integer'
import Integer, { int, toNumber, isInt } from './integer'

const IDENTIFIER_PROPERTY_ATTRIBUTES = {
value: true,
Expand Down Expand Up @@ -79,6 +79,14 @@ export class Duration<T extends NumberOrInteger = Integer> {
* @type {NumberOrInteger}
*/
this.nanoseconds = util.normalizeNanosecondsForDuration(nanoseconds) as T
if (typeof this.months === 'number' && isInt(this.nanoseconds) && isInt(this.seconds)) {
this.seconds = this.seconds.toNumber() as T
this.nanoseconds = this.nanoseconds.toNumber() as T
}
if (typeof this.months === 'bigint' && isInt(this.nanoseconds) && isInt(this.seconds)) {
this.seconds = this.seconds.toBigInt() as T
this.nanoseconds = this.nanoseconds.toBigInt() as T
}
Object.freeze(this)
}

Expand Down
6 changes: 3 additions & 3 deletions packages/core/test/__snapshots__/json.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ exports[`json .stringify should handle DateTime in list 1`] = `"[{"year":2024,"m

exports[`json .stringify should handle DateTime in object 1`] = `"{"key":{"year":2024,"month":6,"day":13,"hour":10,"minute":0,"second":30,"nanosecond":134,"timeZoneOffsetSeconds":-3600,"timeZoneId":"Europe/Berlin"}}"`;

exports[`json .stringify should handle Duration 1`] = `"{"months":10,"days":2,"seconds":{"low":35,"high":0},"nanoseconds":{"low":100,"high":0}}"`;
exports[`json .stringify should handle Duration 1`] = `"{"months":10,"days":2,"seconds":35,"nanoseconds":100}"`;

exports[`json .stringify should handle Duration in list 1`] = `"[{"months":10,"days":2,"seconds":{"low":35,"high":0},"nanoseconds":{"low":100,"high":0}}]"`;
exports[`json .stringify should handle Duration in list 1`] = `"[{"months":10,"days":2,"seconds":35,"nanoseconds":100}]"`;

exports[`json .stringify should handle Duration in object 1`] = `"{"key":{"months":10,"days":2,"seconds":{"low":35,"high":0},"nanoseconds":{"low":100,"high":0}}}"`;
exports[`json .stringify should handle Duration in object 1`] = `"{"key":{"months":10,"days":2,"seconds":35,"nanoseconds":100}}"`;

exports[`json .stringify should handle Integer 1`] = `"{"low":5,"high":0}"`;

Expand Down
9 changes: 8 additions & 1 deletion packages/neo4j-driver-deno/lib/core/integer.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/neo4j-driver-deno/lib/core/result.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion packages/neo4j-driver-deno/lib/core/temporal-types.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/neo4j-driver/test/examples.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1101,8 +1101,8 @@ describe('#integration examples', () => {
expect(neo4j.isDuration(durationField)).toEqual(true)
expect(durationField.months.toInt()).toEqual(duration.months)
expect(durationField.days.toInt()).toEqual(duration.days)
expect(durationField.seconds).toEqual(duration.seconds)
expect(durationField.nanoseconds).toEqual(duration.nanoseconds)
expect(durationField.seconds.toInt()).toEqual(duration.seconds)
expect(durationField.nanoseconds.toInt()).toEqual(duration.nanoseconds)
} finally {
await session.close()
}
Expand Down
12 changes: 11 additions & 1 deletion packages/testkit-backend/src/skipped-tests/rx.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import { skip, ifEquals } from './skip.js'
import { skip, ifEquals, ifStartsWith } from './skip.js'

const skippedTests = [
skip(
'Throws after run insted of the first next because of the backend implementation',
ifEquals('stub.disconnects.test_disconnects.TestDisconnects.test_disconnect_on_tx_begin')
),
skip(
'Reactive driver does not send DISCARD on consume if records stream has been subscribed to',
ifStartsWith('stub.summary.test_summary.TestSummaryPlanDiscard'),
ifStartsWith('stub.summary.test_summary.TestSummaryCountersDiscard'),
ifStartsWith('stub.summary.test_summary.TestSummaryBasicInfoDiscard'),
ifStartsWith('stub.summary.test_summary.TestSummaryGqlStatusObjects4x4Discard'),
ifStartsWith('stub.summary.test_summary.TestSummaryGqlStatusObjects5x6Discard'),
ifStartsWith('stub.summary.test_summary.TestSummaryNotifications4x4Discard'),
ifStartsWith('stub.summary.test_summary.TestSummaryNotifications5x6Discard')
)
]

Expand Down