Skip to content

Commit 6359497

Browse files
authored
Remove Deprecated Transaction Functions (#1312)
1 parent e72e19f commit 6359497

File tree

21 files changed

+129
-410
lines changed

21 files changed

+129
-410
lines changed

packages/core/src/session.ts

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { validateQueryAndParameters } from './internal/util'
2222
import { FETCH_ALL, ACCESS_MODE_READ, ACCESS_MODE_WRITE, TELEMETRY_APIS } from './internal/constants'
2323
import { newError } from './error'
2424
import Result from './result'
25-
import Transaction, { NonAutoCommitApiTelemetryConfig, NonAutoCommitTelemetryApis } from './transaction'
25+
import { NonAutoCommitApiTelemetryConfig, NonAutoCommitTelemetryApis } from './transaction'
2626
import { ConnectionHolder } from './internal/connection-holder'
2727
import { TransactionExecutor } from './internal/transaction-executor'
2828
import { Bookmarks } from './internal/bookmarks'
@@ -40,7 +40,6 @@ import { Logger } from './internal/logger'
4040
import { cacheKey } from './internal/auth-util'
4141

4242
type ConnectionConsumer<T> = (connection: Connection) => Promise<T> | T
43-
type TransactionWork<T> = (tx: Transaction) => Promise<T> | T
4443
type ManagedTransactionWork<T> = (tx: ManagedTransaction) => Promise<T> | T
4544

4645
interface TransactionConfig {
@@ -392,67 +391,6 @@ class Session {
392391
return new Bookmarks([...bookmarks, ...this._configuredBookmarks])
393392
}
394393

395-
/**
396-
* Execute given unit of work in a {@link READ} transaction.
397-
*
398-
* Transaction will automatically be committed unless the given function throws or returns a rejected promise.
399-
* Some failures of the given function or the commit itself will be retried with exponential backoff with initial
400-
* delay of 1 second and maximum retry time of 30 seconds. Maximum retry time is configurable via driver config's
401-
* `maxTransactionRetryTime` property in milliseconds.
402-
*
403-
* @deprecated This method will be removed in version 6.0. Please, use {@link Session#executeRead} instead.
404-
*
405-
* @param {function(tx: Transaction): Promise} transactionWork - Callback that executes operations against
406-
* a given {@link Transaction}.
407-
* @param {TransactionConfig} [transactionConfig] - Configuration for all transactions started to execute the unit of work.
408-
* @return {Promise} Resolved promise as returned by the given function or rejected promise when given
409-
* function or commit fails.
410-
* @see {@link Session#executeRead}
411-
*/
412-
readTransaction<T>(
413-
transactionWork: TransactionWork<T>,
414-
transactionConfig?: TransactionConfig
415-
): Promise<T> {
416-
const config = new TxConfig(transactionConfig, this._log)
417-
return this._runTransaction(ACCESS_MODE_READ, config, transactionWork)
418-
}
419-
420-
/**
421-
* Execute given unit of work in a {@link WRITE} transaction.
422-
*
423-
* Transaction will automatically be committed unless the given function throws or returns a rejected promise.
424-
* Some failures of the given function or the commit itself will be retried with exponential backoff with initial
425-
* delay of 1 second and maximum retry time of 30 seconds. Maximum retry time is configurable via driver config's
426-
* `maxTransactionRetryTime` property in milliseconds.
427-
*
428-
* @deprecated This method will be removed in version 6.0. Please, use {@link Session#executeWrite} instead.
429-
*
430-
* @param {function(tx: Transaction): Promise} transactionWork - Callback that executes operations against
431-
* a given {@link Transaction}.
432-
* @param {TransactionConfig} [transactionConfig] - Configuration for all transactions started to execute the unit of work.
433-
* @return {Promise} Resolved promise as returned by the given function or rejected promise when given
434-
* function or commit fails.
435-
* @see {@link Session#executeWrite}
436-
*/
437-
writeTransaction<T>(
438-
transactionWork: TransactionWork<T>,
439-
transactionConfig?: TransactionConfig
440-
): Promise<T> {
441-
const config = new TxConfig(transactionConfig, this._log)
442-
return this._runTransaction(ACCESS_MODE_WRITE, config, transactionWork)
443-
}
444-
445-
_runTransaction<T>(
446-
accessMode: SessionMode,
447-
transactionConfig: TxConfig,
448-
transactionWork: TransactionWork<T>
449-
): Promise<T> {
450-
return this._transactionExecutor.execute(
451-
(apiTelemetryConfig?: NonAutoCommitApiTelemetryConfig) => this._beginTransaction(accessMode, transactionConfig, apiTelemetryConfig),
452-
transactionWork
453-
)
454-
}
455-
456394
/**
457395
* Execute given unit of work in a {@link READ} transaction.
458396
*

packages/core/src/transaction.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Transaction {
5959
private readonly _fetchSize: number
6060
private readonly _results: Result[]
6161
private readonly _impersonatedUser?: string
62-
private readonly _lowRecordWatermak: number
62+
private readonly _lowRecordWatermark: number
6363
private readonly _highRecordWatermark: number
6464
private _bookmarks: Bookmarks
6565
private readonly _activePromise: Promise<void>
@@ -119,7 +119,7 @@ class Transaction {
119119
this._onComplete = this._onCompleteCallback.bind(this)
120120
this._results = []
121121
this._impersonatedUser = impersonatedUser
122-
this._lowRecordWatermak = lowRecordWatermark
122+
this._lowRecordWatermark = lowRecordWatermark
123123
this._highRecordWatermark = highRecordWatermark
124124
this._bookmarks = Bookmarks.empty()
125125
this._notificationFilter = notificationFilter
@@ -210,7 +210,7 @@ class Transaction {
210210
reactive: this._reactive,
211211
fetchSize: this._fetchSize,
212212
highRecordWatermark: this._highRecordWatermark,
213-
lowRecordWatermark: this._lowRecordWatermak,
213+
lowRecordWatermark: this._lowRecordWatermark,
214214
preparationJob: this._activePromise
215215
})
216216
this._results.push(result)

packages/core/src/types.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,6 @@ export class Config {
331331
* * {@link Session#beginTransaction}
332332
* * {@link Session#executeRead}
333333
* * {@link Session#executeWrite}
334-
* * {@link Session#writeTransaction}
335-
* * {@link Session#readTransaction}
336334
* * The reactive counterparts of methods above.
337335
*
338336
* Metrics are only collected when enabled both in server and driver instances.

packages/core/test/session.test.ts

Lines changed: 26 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ describe('session', () => {
107107
const tx = session.beginTransaction()
108108

109109
// @ts-expect-error
110-
expect(tx._lowRecordWatermak).toEqual(300)
110+
expect(tx._lowRecordWatermark).toEqual(300)
111111
// @ts-expect-error
112112
expect(tx._highRecordWatermark).toEqual(700)
113113
})
@@ -119,77 +119,53 @@ describe('session', () => {
119119
const tx = session.beginTransaction()
120120

121121
// @ts-expect-error
122-
expect(tx._lowRecordWatermak).toEqual(Number.MAX_VALUE)
122+
expect(tx._lowRecordWatermark).toEqual(Number.MAX_VALUE)
123123
// @ts-expect-error
124124
expect(tx._highRecordWatermark).toEqual(Number.MAX_VALUE)
125125
})
126126

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

132-
await session.writeTransaction(tx => {
133-
// @ts-expect-error
134-
expect(tx._lowRecordWatermak).toEqual(300)
135-
// @ts-expect-error
136-
expect(tx._highRecordWatermark).toEqual(700)
137-
138-
status.functionCalled = true
139-
})
140-
141-
expect(status.functionCalled).toEqual(true)
131+
const tx = session.beginTransaction()
132+
// @ts-expect-error
133+
expect(tx._lowRecordWatermark).toEqual(300)
134+
// @ts-expect-error
135+
expect(tx._highRecordWatermark).toEqual(700)
142136
})
143137

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

149-
await session.writeTransaction(tx => {
150-
// @ts-expect-error
151-
expect(tx._lowRecordWatermak).toEqual(Number.MAX_VALUE)
152-
// @ts-expect-error
153-
expect(tx._highRecordWatermark).toEqual(Number.MAX_VALUE)
154-
155-
status.functionCalled = true
156-
})
157-
158-
expect(status.functionCalled).toEqual(true)
142+
const tx = session.beginTransaction()
143+
// @ts-expect-error
144+
expect(tx._lowRecordWatermark).toEqual(Number.MAX_VALUE)
145+
// @ts-expect-error
146+
expect(tx._highRecordWatermark).toEqual(Number.MAX_VALUE)
159147
})
160148

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

166-
await session.readTransaction(tx => {
167-
// @ts-expect-error
168-
expect(tx._lowRecordWatermak).toEqual(300)
169-
// @ts-expect-error
170-
expect(tx._highRecordWatermark).toEqual(700)
171-
172-
status.functionCalled = true
173-
})
174-
175-
expect(status.functionCalled).toEqual(true)
153+
const tx = session.beginTransaction()
154+
// @ts-expect-error
155+
expect(tx._lowRecordWatermark).toEqual(300)
156+
// @ts-expect-error
157+
expect(tx._highRecordWatermark).toEqual(700)
176158
})
177159

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

183-
await session.readTransaction(tx => {
184-
// @ts-expect-error
185-
expect(tx._lowRecordWatermak).toEqual(Number.MAX_VALUE)
186-
// @ts-expect-error
187-
expect(tx._highRecordWatermark).toEqual(Number.MAX_VALUE)
188-
189-
status.functionCalled = true
190-
})
191-
192-
expect(status.functionCalled).toEqual(true)
164+
const tx = session.beginTransaction()
165+
// @ts-expect-error
166+
expect(tx._lowRecordWatermark).toEqual(Number.MAX_VALUE)
167+
// @ts-expect-error
168+
expect(tx._highRecordWatermark).toEqual(Number.MAX_VALUE)
193169
})
194170

195171
it('close should be idempotent ', done => {

packages/neo4j-driver-deno/lib/core/session.ts

Lines changed: 1 addition & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/neo4j-driver-deno/lib/core/transaction.ts

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/neo4j-driver-deno/lib/core/types.ts

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/neo4j-driver-lite/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ readTxResultPromise
264264
```javascript
265265
// It is possible to execute write transactions that will benefit from automatic retries
266266
// on both single instance ('bolt' URI scheme) and Causal Cluster ('neo4j' URI scheme)
267-
var writeTxResultPromise = session.writeTransaction(async txc => {
267+
var writeTxResultPromise = session.executeWrite(async txc => {
268268
// used transaction will be committed automatically, no need for explicit commit/rollback
269269

270270
var result = await txc.run(

packages/neo4j-driver/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ neo4j.driver('neo4j://localhost', neo4j.auth.basic('neo4j', 'password'), {
276276
// It is possible to execute read transactions that will benefit from automatic
277277
// retries on both single instance ('bolt' URI scheme) and Causal Cluster
278278
// ('neo4j' URI scheme) and will get automatic load balancing in cluster deployments
279-
var readTxResultPromise = session.readTransaction(txc => {
279+
var readTxResultPromise = session.executeRead(txc => {
280280
// used transaction will be committed automatically, no need for explicit commit/rollback
281281

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

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

324324
var result = await txc.run(
@@ -344,7 +344,7 @@ writeTxResultPromise
344344

345345
```javascript
346346
rxSession
347-
.writeTransaction(txc =>
347+
.executeWrite(txc =>
348348
txc
349349
.run("MERGE (alice:Person {name: 'James'}) RETURN alice.name AS name")
350350
.records()

0 commit comments

Comments
 (0)