Skip to content
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
64 changes: 1 addition & 63 deletions packages/core/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { validateQueryAndParameters } from './internal/util'
import { FETCH_ALL, ACCESS_MODE_READ, ACCESS_MODE_WRITE, TELEMETRY_APIS } from './internal/constants'
import { newError } from './error'
import Result from './result'
import Transaction, { NonAutoCommitApiTelemetryConfig, NonAutoCommitTelemetryApis } from './transaction'
import { NonAutoCommitApiTelemetryConfig, NonAutoCommitTelemetryApis } from './transaction'
import { ConnectionHolder } from './internal/connection-holder'
import { TransactionExecutor } from './internal/transaction-executor'
import { Bookmarks } from './internal/bookmarks'
Expand All @@ -40,7 +40,6 @@ import { Logger } from './internal/logger'
import { cacheKey } from './internal/auth-util'

type ConnectionConsumer<T> = (connection: Connection) => Promise<T> | T
type TransactionWork<T> = (tx: Transaction) => Promise<T> | T
type ManagedTransactionWork<T> = (tx: ManagedTransaction) => Promise<T> | T

interface TransactionConfig {
Expand Down Expand Up @@ -392,67 +391,6 @@ class Session {
return new Bookmarks([...bookmarks, ...this._configuredBookmarks])
}

/**
* Execute given unit of work in a {@link READ} transaction.
*
* Transaction will automatically be committed unless the given function throws or returns a rejected promise.
* Some failures of the given function or the commit itself will be retried with exponential backoff with initial
* delay of 1 second and maximum retry time of 30 seconds. Maximum retry time is configurable via driver config's
* `maxTransactionRetryTime` property in milliseconds.
*
* @deprecated This method will be removed in version 6.0. Please, use {@link Session#executeRead} instead.
*
* @param {function(tx: Transaction): Promise} transactionWork - Callback that executes operations against
* a given {@link Transaction}.
* @param {TransactionConfig} [transactionConfig] - Configuration for all transactions started to execute the unit of work.
* @return {Promise} Resolved promise as returned by the given function or rejected promise when given
* function or commit fails.
* @see {@link Session#executeRead}
*/
readTransaction<T>(
transactionWork: TransactionWork<T>,
transactionConfig?: TransactionConfig
): Promise<T> {
const config = new TxConfig(transactionConfig, this._log)
return this._runTransaction(ACCESS_MODE_READ, config, transactionWork)
}

/**
* Execute given unit of work in a {@link WRITE} transaction.
*
* Transaction will automatically be committed unless the given function throws or returns a rejected promise.
* Some failures of the given function or the commit itself will be retried with exponential backoff with initial
* delay of 1 second and maximum retry time of 30 seconds. Maximum retry time is configurable via driver config's
* `maxTransactionRetryTime` property in milliseconds.
*
* @deprecated This method will be removed in version 6.0. Please, use {@link Session#executeWrite} instead.
*
* @param {function(tx: Transaction): Promise} transactionWork - Callback that executes operations against
* a given {@link Transaction}.
* @param {TransactionConfig} [transactionConfig] - Configuration for all transactions started to execute the unit of work.
* @return {Promise} Resolved promise as returned by the given function or rejected promise when given
* function or commit fails.
* @see {@link Session#executeWrite}
*/
writeTransaction<T>(
transactionWork: TransactionWork<T>,
transactionConfig?: TransactionConfig
): Promise<T> {
const config = new TxConfig(transactionConfig, this._log)
return this._runTransaction(ACCESS_MODE_WRITE, config, transactionWork)
}

_runTransaction<T>(
accessMode: SessionMode,
transactionConfig: TxConfig,
transactionWork: TransactionWork<T>
): Promise<T> {
return this._transactionExecutor.execute(
(apiTelemetryConfig?: NonAutoCommitApiTelemetryConfig) => this._beginTransaction(accessMode, transactionConfig, apiTelemetryConfig),
transactionWork
)
}

/**
* Execute given unit of work in a {@link READ} transaction.
*
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Transaction {
private readonly _fetchSize: number
private readonly _results: Result[]
private readonly _impersonatedUser?: string
private readonly _lowRecordWatermak: number
private readonly _lowRecordWatermark: number
private readonly _highRecordWatermark: number
private _bookmarks: Bookmarks
private readonly _activePromise: Promise<void>
Expand Down Expand Up @@ -119,7 +119,7 @@ class Transaction {
this._onComplete = this._onCompleteCallback.bind(this)
this._results = []
this._impersonatedUser = impersonatedUser
this._lowRecordWatermak = lowRecordWatermark
this._lowRecordWatermark = lowRecordWatermark
this._highRecordWatermark = highRecordWatermark
this._bookmarks = Bookmarks.empty()
this._notificationFilter = notificationFilter
Expand Down Expand Up @@ -210,7 +210,7 @@ class Transaction {
reactive: this._reactive,
fetchSize: this._fetchSize,
highRecordWatermark: this._highRecordWatermark,
lowRecordWatermark: this._lowRecordWatermak,
lowRecordWatermark: this._lowRecordWatermark,
preparationJob: this._activePromise
})
this._results.push(result)
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,6 @@ export class Config {
* * {@link Session#beginTransaction}
* * {@link Session#executeRead}
* * {@link Session#executeWrite}
* * {@link Session#writeTransaction}
* * {@link Session#readTransaction}
* * The reactive counterparts of methods above.
*
* Metrics are only collected when enabled both in server and driver instances.
Expand Down
76 changes: 26 additions & 50 deletions packages/core/test/session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('session', () => {
const tx = session.beginTransaction()

// @ts-expect-error
expect(tx._lowRecordWatermak).toEqual(300)
expect(tx._lowRecordWatermark).toEqual(300)
// @ts-expect-error
expect(tx._highRecordWatermark).toEqual(700)
})
Expand All @@ -119,77 +119,53 @@ describe('session', () => {
const tx = session.beginTransaction()

// @ts-expect-error
expect(tx._lowRecordWatermak).toEqual(Number.MAX_VALUE)
expect(tx._lowRecordWatermark).toEqual(Number.MAX_VALUE)
// @ts-expect-error
expect(tx._highRecordWatermark).toEqual(Number.MAX_VALUE)
})

it('run should send watermarks to Transaction when fetchsize if defined (writeTransaction)', async () => {
it('run should send watermarks to Transaction when fetchsize if defined (executeWrite)', async () => {
const connection = mockBeginWithSuccess(newFakeConnection())
const session = newSessionWithConnection(connection, false, 1000)
const status = { functionCalled: false }

await session.writeTransaction(tx => {
// @ts-expect-error
expect(tx._lowRecordWatermak).toEqual(300)
// @ts-expect-error
expect(tx._highRecordWatermark).toEqual(700)

status.functionCalled = true
})

expect(status.functionCalled).toEqual(true)
const tx = session.beginTransaction()
// @ts-expect-error
expect(tx._lowRecordWatermark).toEqual(300)
// @ts-expect-error
expect(tx._highRecordWatermark).toEqual(700)
})

it('run should send watermarks to Transaction when fetchsize is fetch all (writeTransaction)', async () => {
it('run should send watermarks to Transaction when fetchsize is fetch all (executeWrite)', async () => {
const connection = mockBeginWithSuccess(newFakeConnection())
const session = newSessionWithConnection(connection, false, FETCH_ALL)
const status = { functionCalled: false }

await session.writeTransaction(tx => {
// @ts-expect-error
expect(tx._lowRecordWatermak).toEqual(Number.MAX_VALUE)
// @ts-expect-error
expect(tx._highRecordWatermark).toEqual(Number.MAX_VALUE)

status.functionCalled = true
})

expect(status.functionCalled).toEqual(true)
const tx = session.beginTransaction()
// @ts-expect-error
expect(tx._lowRecordWatermark).toEqual(Number.MAX_VALUE)
// @ts-expect-error
expect(tx._highRecordWatermark).toEqual(Number.MAX_VALUE)
})

it('run should send watermarks to Transaction when fetchsize if defined (readTransaction)', async () => {
it('run should send watermarks to Transaction when fetchsize if defined (executeRead)', async () => {
const connection = mockBeginWithSuccess(newFakeConnection())
const session = newSessionWithConnection(connection, false, 1000)
const status = { functionCalled: false }

await session.readTransaction(tx => {
// @ts-expect-error
expect(tx._lowRecordWatermak).toEqual(300)
// @ts-expect-error
expect(tx._highRecordWatermark).toEqual(700)

status.functionCalled = true
})

expect(status.functionCalled).toEqual(true)
const tx = session.beginTransaction()
// @ts-expect-error
expect(tx._lowRecordWatermark).toEqual(300)
// @ts-expect-error
expect(tx._highRecordWatermark).toEqual(700)
})

it('run should send watermarks to Transaction when fetchsize is fetch all (readTransaction)', async () => {
it('run should send watermarks to Transaction when fetchsize is fetch all (executeRead)', async () => {
const connection = mockBeginWithSuccess(newFakeConnection())
const session = newSessionWithConnection(connection, false, FETCH_ALL)
const status = { functionCalled: false }

await session.readTransaction(tx => {
// @ts-expect-error
expect(tx._lowRecordWatermak).toEqual(Number.MAX_VALUE)
// @ts-expect-error
expect(tx._highRecordWatermark).toEqual(Number.MAX_VALUE)

status.functionCalled = true
})

expect(status.functionCalled).toEqual(true)
const tx = session.beginTransaction()
// @ts-expect-error
expect(tx._lowRecordWatermark).toEqual(Number.MAX_VALUE)
// @ts-expect-error
expect(tx._highRecordWatermark).toEqual(Number.MAX_VALUE)
})

it('close should be idempotent ', done => {
Expand Down
64 changes: 1 addition & 63 deletions packages/neo4j-driver-deno/lib/core/session.ts

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

6 changes: 3 additions & 3 deletions packages/neo4j-driver-deno/lib/core/transaction.ts

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

2 changes: 0 additions & 2 deletions packages/neo4j-driver-deno/lib/core/types.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-lite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ readTxResultPromise
```javascript
// It is possible to execute write transactions that will benefit from automatic retries
// on both single instance ('bolt' URI scheme) and Causal Cluster ('neo4j' URI scheme)
var writeTxResultPromise = session.writeTransaction(async txc => {
var writeTxResultPromise = session.executeWrite(async txc => {
// used transaction will be committed automatically, no need for explicit commit/rollback

var result = await txc.run(
Expand Down
8 changes: 4 additions & 4 deletions packages/neo4j-driver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ neo4j.driver('neo4j://localhost', neo4j.auth.basic('neo4j', 'password'), {
// It is possible to execute read transactions that will benefit from automatic
// retries on both single instance ('bolt' URI scheme) and Causal Cluster
// ('neo4j' URI scheme) and will get automatic load balancing in cluster deployments
var readTxResultPromise = session.readTransaction(txc => {
var readTxResultPromise = session.executeRead(txc => {
// used transaction will be committed automatically, no need for explicit commit/rollback

var result = txc.run('MATCH (person:Person) RETURN person.name AS name')
Expand All @@ -300,7 +300,7 @@ readTxResultPromise

```javascript
rxSession
.readTransaction(txc =>
.executeRead(txc =>
txc
.run('MATCH (person:Person) RETURN person.name AS name')
.records()
Expand All @@ -318,7 +318,7 @@ rxSession
```javascript
// It is possible to execute write transactions that will benefit from automatic retries
// on both single instance ('bolt' URI scheme) and Causal Cluster ('neo4j' URI scheme)
var writeTxResultPromise = session.writeTransaction(async txc => {
var writeTxResultPromise = session.executeWrite(async txc => {
// used transaction will be committed automatically, no need for explicit commit/rollback

var result = await txc.run(
Expand All @@ -344,7 +344,7 @@ writeTxResultPromise

```javascript
rxSession
.writeTransaction(txc =>
.executeWrite(txc =>
txc
.run("MERGE (alice:Person {name: 'James'}) RETURN alice.name AS name")
.records()
Expand Down
Loading