Skip to content

Commit 1d6f5c5

Browse files
committed
Add back (rx)session.lastBookmark methods and bookmark params to driver.(rx)session methods.
These method were added back deprecated for keeping the driver backward compatible.
1 parent 87a16a6 commit 1d6f5c5

File tree

11 files changed

+215
-10
lines changed

11 files changed

+215
-10
lines changed

packages/core/src/driver.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ class Driver {
247247
* @public
248248
* @param {Object} param - The object parameter
249249
* @param {string} param.defaultAccessMode=WRITE - The access mode of this session, allowed values are {@link READ} and {@link WRITE}.
250+
* @param {string|string[]} param.bookmark - *Deprecated!* Use `bookmarks` instead.
250251
* @param {string|string[]} param.bookmarks - The initial reference or references to some previous
251252
* transactions. Value is optional and absence indicates that that the bookmarks do not exist or are unknown.
252253
* @param {number} param.fetchSize - The record fetch size of each batch of this session.
@@ -257,20 +258,22 @@ class Driver {
257258
*/
258259
session({
259260
defaultAccessMode = WRITE,
261+
bookmark,
260262
bookmarks: bookmarkOrBookmarks,
261263
database = '',
262264
impersonatedUser,
263265
fetchSize
264266
}: {
265267
defaultAccessMode?: SessionMode
268+
bookmark?: string | string[]
266269
bookmarks?: string | string[]
267270
database?: string
268271
impersonatedUser?: string
269272
fetchSize?: number
270273
} = {}): Session {
271274
return this._newSession({
272275
defaultAccessMode,
273-
bookmarkOrBookmarks,
276+
bookmarkOrBookmarks: bookmarkOrBookmarks || bookmark,
274277
database,
275278
reactive: false,
276279
impersonatedUser,

packages/core/src/session.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,17 @@ class Session {
304304
this._hasTx = false
305305
}
306306

307+
/**
308+
* Return the bookmarks received following the last completed {@link Transaction}.
309+
*
310+
* @deprecated This method will be removed in 6.0 version. Please, use {@link Session#lastBookmarks} instead.
311+
*
312+
* @return {string[]} A reference to a previous transaction.
313+
*/
314+
lastBookmark(): string[] {
315+
return this.lastBookmarks()
316+
}
317+
307318
/**
308319
* Return the bookmarks received following the last completed {@link Transaction}.
309320
*

packages/core/test/driver.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,44 @@ describe('Driver', () => {
7070
expect(session).not.toBeUndefined()
7171
expect(createSession).toHaveBeenCalledWith(expectedSessionParams())
7272
})
73+
74+
it.each([
75+
[undefined, Bookmarks.empty()],
76+
[null, Bookmarks.empty()],
77+
['bookmark', new Bookmarks('bookmark')],
78+
[['bookmark'], new Bookmarks(['bookmark'])],
79+
[['bookmark1', 'bookmark2'], new Bookmarks(['bookmark1', 'bookmark2'])],
80+
])('should create session using param bookmark', (bookmark, expectedBookmarks) => {
81+
// @ts-ignore
82+
const session = driver!.session({ bookmark })
83+
84+
expect(session.lastBookmarks()).toEqual(expectedBookmarks.values())
85+
})
86+
87+
it.each([
88+
[undefined, Bookmarks.empty()],
89+
[null, Bookmarks.empty()],
90+
['bookmark', new Bookmarks('bookmark')],
91+
[['bookmark'], new Bookmarks(['bookmark'])],
92+
[['bookmark1', 'bookmark2'], new Bookmarks(['bookmark1', 'bookmark2'])],
93+
])('should create session using param bookmarks', (bookmarks, expectedBookmarks) => {
94+
// @ts-ignore
95+
const session = driver!.session({ bookmarks })
96+
97+
expect(session.lastBookmarks()).toEqual(expectedBookmarks.values())
98+
})
99+
100+
it.each([
101+
[undefined, undefined, Bookmarks.empty()],
102+
[undefined, 'bookmark', new Bookmarks('bookmark')],
103+
['bookmark', undefined, new Bookmarks('bookmark')],
104+
['bookmark', 'bookmark2', new Bookmarks('bookmark')]
105+
])('should bookmarks should take precedence to bookmark', (bookmarks, bookmark, expectedBookmarks) => {
106+
// @ts-ignore
107+
const session = driver!.session({ bookmarks, bookmark })
108+
109+
expect(session.lastBookmarks()).toEqual(expectedBookmarks.values())
110+
})
73111
})
74112

75113
it.each([

packages/core/test/session.test.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* limitations under the License.
1818
*/
1919
import { ConnectionProvider, Session, Connection } from '../src'
20+
import { bookmarks } from '../src/internal'
2021
import { ACCESS_MODE_READ, FETCH_ALL } from '../src/internal/constants'
2122
import FakeConnection from './utils/connection.fake'
2223

@@ -202,9 +203,39 @@ describe('session', () => {
202203
done()
203204
})
204205
}, 70000)
206+
207+
describe('.lastBookmark()', () => {
208+
it.each([
209+
[bookmarks.Bookmarks.empty()],
210+
[new bookmarks.Bookmarks('bookmark1')],
211+
[new bookmarks.Bookmarks(['bookmark1', 'bookmark2'])]
212+
])('should return the bookmark informed in the object creation', (bookmarks) => {
213+
const session = newSessionWithConnection(newFakeConnection(), false, 1000, bookmarks)
214+
215+
expect(session.lastBookmark()).toEqual(bookmarks.values())
216+
})
217+
})
218+
219+
describe('.lastBookmark()', () => {
220+
it.each([
221+
[bookmarks.Bookmarks.empty()],
222+
[new bookmarks.Bookmarks('bookmark1')],
223+
[new bookmarks.Bookmarks(['bookmark1', 'bookmark2'])]
224+
])('should return the bookmark informed in the object creation', (bookmarks) => {
225+
const session = newSessionWithConnection(newFakeConnection(), false, 1000, bookmarks)
226+
227+
expect(session.lastBookmarks()).toEqual(bookmarks.values())
228+
})
229+
})
205230
})
206231

207-
function newSessionWithConnection(connection: Connection, beginTx: boolean = true, fetchSize: number = 1000): Session {
232+
function newSessionWithConnection(
233+
connection: Connection,
234+
beginTx: boolean = true,
235+
fetchSize: number = 1000,
236+
lastBookmarks: bookmarks.Bookmarks = bookmarks.Bookmarks.empty()
237+
): Session {
238+
208239
const connectionProvider = new ConnectionProvider()
209240
connectionProvider.acquireConnection = () => Promise.resolve(connection)
210241
connectionProvider.close = () => Promise.resolve()
@@ -215,7 +246,8 @@ function newSessionWithConnection(connection: Connection, beginTx: boolean = tru
215246
database: "",
216247
fetchSize,
217248
config: {},
218-
reactive: false
249+
reactive: false,
250+
bookmarks: lastBookmarks
219251
})
220252

221253
if (beginTx) {

packages/neo4j-driver/src/driver.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Driver extends CoreDriver {
5151
* @public
5252
* @param {Object} param
5353
* @param {string} param.defaultAccessMode=WRITE - The access mode of this session, allowed values are {@link READ} and {@link WRITE}.
54+
* @param {string|string[]} param.bookmark - *Deprecated!* Use `bookmarks` instead.
5455
* @param {string|string[]} param.bookmarks - The initial reference or references to some previous transactions. Value is optional and
5556
* absence indicates that the bookmarks do not exist or are unknown.
5657
* @param {string} param.database - The database this session will operate on.
@@ -59,6 +60,7 @@ class Driver extends CoreDriver {
5960
*/
6061
rxSession ({
6162
defaultAccessMode = WRITE,
63+
bookmark,
6264
bookmarks,
6365
database = '',
6466
fetchSize,
@@ -67,7 +69,7 @@ class Driver extends CoreDriver {
6769
return new RxSession({
6870
session: this._newSession({
6971
defaultAccessMode,
70-
bookmarks,
72+
bookmarkOrBookmarks: bookmarks || bookmark,
7173
database,
7274
impersonatedUser,
7375
reactive: true,

packages/neo4j-driver/src/session-rx.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,23 @@ export default class RxSession {
121121
})
122122
}
123123

124+
/**
125+
* Returns the bookmarks received following the last successfully completed query, which is executed
126+
* either in an {@link RxTransaction} obtained from this session instance or directly through one of
127+
* the {@link RxSession#run} method of this session instance.
128+
*
129+
* If no bookmarks were received or if this transaction was rolled back, the bookmarks value will not be
130+
* changed.
131+
*
132+
* @deprecated This method will be removed in 6.0 version. Please, use {@link RxSession#lastBookmarks} instead.
133+
*
134+
* @public
135+
* @returns {string[]}
136+
*/
137+
lastBookmark () {
138+
return this.lastBookmarks()
139+
}
140+
124141
/**
125142
* Returns the bookmarks received following the last successfully completed query, which is executed
126143
* either in an {@link RxTransaction} obtained from this session instance or directly through one of
@@ -130,7 +147,7 @@ export default class RxSession {
130147
* changed.
131148
*
132149
* @public
133-
* @returns {string}
150+
* @returns {string[]}
134151
*/
135152
lastBookmarks () {
136153
return this._session.lastBookmarks()

packages/neo4j-driver/test/driver.test.js

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ import {
2424
DEFAULT_ACQUISITION_TIMEOUT,
2525
DEFAULT_MAX_SIZE
2626
} from '../../bolt-connection/lib/pool/pool-config'
27-
import { ServerVersion, VERSION_4_0_0 } from '../src/internal/server-version'
2827
import testUtils from './internal/test-utils'
29-
import { json } from 'neo4j-driver-core'
28+
import { json, internal } from 'neo4j-driver-core'
29+
30+
const {
31+
bookmarks: { Bookmarks }
32+
} = internal
3033

3134
// As long as driver creation doesn't touch the network it's fine to run
3235
// this as a unit test.
@@ -114,6 +117,49 @@ describe('#unit driver', () => {
114117
})
115118
).toThrow()
116119
})
120+
121+
describe('.rxSession()', () => {
122+
;[
123+
[undefined, Bookmarks.empty()],
124+
[null, Bookmarks.empty()],
125+
['bookmark', new Bookmarks('bookmark')],
126+
[['bookmark'], new Bookmarks(['bookmark'])],
127+
[['bookmark1', 'bookmark2'], new Bookmarks(['bookmark1', 'bookmark2'])]
128+
].forEach(([bookmark, expectedBookmarks]) => {
129+
it(`should create session using param bookmark=${bookmark}`, () => {
130+
const session = driver.rxSession({ bookmark })
131+
132+
expect(session.lastBookmarks()).toEqual(expectedBookmarks.values())
133+
})
134+
})
135+
136+
;[
137+
[undefined, Bookmarks.empty()],
138+
[null, Bookmarks.empty()],
139+
['bookmark', new Bookmarks('bookmark')],
140+
[['bookmark'], new Bookmarks(['bookmark'])],
141+
[['bookmark1', 'bookmark2'], new Bookmarks(['bookmark1', 'bookmark2'])]
142+
].forEach(([bookmarks, expectedBookmarks]) => {
143+
it(`should create session using param bookmarks=${bookmarks}`, () => {
144+
const session = driver.rxSession({ bookmarks })
145+
146+
expect(session.lastBookmarks()).toEqual(expectedBookmarks.values())
147+
})
148+
})
149+
150+
;[
151+
[undefined, undefined, Bookmarks.empty()],
152+
[undefined, 'bookmark', new Bookmarks('bookmark')],
153+
['bookmark', undefined, new Bookmarks('bookmark')],
154+
['bookmark', 'bookmark2', new Bookmarks('bookmark')]
155+
].forEach(([bookmarks, bookmark, expectedBookmarks]) => {
156+
it(`should have correct precedence between bookmarks=${bookmarks} and bookmark${bookmark} `, () => {
157+
const session = driver.rxSession({ bookmarks, bookmark })
158+
159+
expect(session.lastBookmarks()).toEqual(expectedBookmarks.values())
160+
})
161+
})
162+
})
117163
})
118164

119165
describe('#integration driver', () => {

packages/neo4j-driver/test/rx/session.test.js

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,18 @@
2020
import { Notification, throwError } from 'rxjs'
2121
import { map, materialize, toArray, concat } from 'rxjs/operators'
2222
import neo4j from '../../src'
23+
import RxSession from '../../src/session-rx'
2324
import sharedNeo4j from '../internal/shared-neo4j'
24-
import { newError, error } from 'neo4j-driver-core'
25+
import {
26+
newError,
27+
error,
28+
internal,
29+
Session,
30+
ConnectionProvider
31+
} from 'neo4j-driver-core'
2532

2633
const { SERVICE_UNAVAILABLE, SESSION_EXPIRED } = error
34+
const { bookmarks } = internal
2735

2836
describe('#integration rx-session', () => {
2937
let driver
@@ -274,3 +282,48 @@ describe('#integration rx-session', () => {
274282
}
275283
}
276284
})
285+
286+
describe('#unit rx-session', () => {
287+
describe('lastBookmark', () => {
288+
;[
289+
bookmarks.Bookmarks.empty(),
290+
new bookmarks.Bookmarks('bookmark1'),
291+
new bookmarks.Bookmarks(['bookmark1', 'bookmark2'])
292+
].forEach(bookmarks => {
293+
it(`should return ${bookmarks}`, () => {
294+
const session = newSession(bookmarks)
295+
expect(session.lastBookmark()).toBe(bookmarks.values())
296+
})
297+
})
298+
})
299+
300+
describe('lastBookmarks', () => {
301+
;[
302+
bookmarks.Bookmarks.empty(),
303+
new bookmarks.Bookmarks('bookmark1'),
304+
new bookmarks.Bookmarks(['bookmark1', 'bookmark2'])
305+
].forEach(bookmarks => {
306+
it(`should return ${bookmarks}`, () => {
307+
const session = newSession(bookmarks)
308+
expect(session.lastBookmarks()).toBe(bookmarks.values())
309+
})
310+
})
311+
})
312+
313+
function newSession (lastBookmarks = bookmarks.Bookmarks.empty()) {
314+
const connectionProvider = new ConnectionProvider()
315+
connectionProvider.acquireConnection = () => Promise.resolve(null)
316+
connectionProvider.close = () => Promise.resolve()
317+
318+
const session = new Session({
319+
mode: 'READ',
320+
connectionProvider,
321+
database: '',
322+
config: {},
323+
reactive: true,
324+
bookmarks: lastBookmarks
325+
})
326+
327+
return new RxSession({ session })
328+
}
329+
})

packages/neo4j-driver/test/types/session-rx.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ const txConfig7: TransactionConfig = {
7474
}
7575

7676
const tx1: Observable<RxTransaction> = rxSession.beginTransaction()
77-
const bookmarks: null | string = <null>rxSession.lastBookmarks()
77+
const bookmarks: string[] = rxSession.lastBookmarks()
78+
const bookmark: string[] = rxSession.lastBookmark()
7879

7980
const observable1: Observable<number> = rxSession.readTransaction(
8081
(tx: RxTransaction) => {

packages/neo4j-driver/types/driver.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ declare interface Driver extends CoreDriver {
4343
fetchSize
4444
}?: {
4545
defaultAccessMode?: SessionMode
46+
bookmark?: string | string[]
4647
bookmarks?: string | string[]
4748
fetchSize?: number
4849
database?: string

packages/neo4j-driver/types/session-rx.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ declare interface RxSession {
3333

3434
beginTransaction(config?: TransactionConfig): Observable<RxTransaction>
3535

36-
lastBookmarks(): string | null
36+
lastBookmarks(): string[]
37+
lastBookmark(): string[]
3738

3839
readTransaction<T>(
3940
work: RxTransactionWork<T>,

0 commit comments

Comments
 (0)