Skip to content

Commit 32ec3b2

Browse files
authored
Add back (rx)session.lastBookmark methods (#853)
These method were added back deprecated for keeping the driver backward compatible.
1 parent 87a16a6 commit 32ec3b2

File tree

9 files changed

+161
-9
lines changed

9 files changed

+161
-9
lines changed

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 version 6.0. 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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ 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 bookmarks', (bookmarks, expectedBookmarks) => {
81+
// @ts-ignore
82+
const session = driver!.session({ bookmarks })
83+
84+
expect(session.lastBookmarks()).toEqual(expectedBookmarks.values())
85+
})
7386
})
7487

7588
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Driver extends CoreDriver {
6767
return new RxSession({
6868
session: this._newSession({
6969
defaultAccessMode,
70-
bookmarks,
70+
bookmarkOrBookmarks: bookmarks,
7171
database,
7272
impersonatedUser,
7373
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: 26 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,27 @@ 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(([bookmarks, expectedBookmarks]) => {
129+
it(`should create session using param bookmarks=${bookmarks}`, () => {
130+
driver = neo4j.driver(
131+
`neo4j+ssc://${sharedNeo4j.hostname}`,
132+
sharedNeo4j.authToken
133+
)
134+
135+
const session = driver.rxSession({ bookmarks })
136+
137+
expect(session.lastBookmarks()).toEqual(expectedBookmarks.values())
138+
})
139+
})
140+
})
117141
})
118142

119143
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/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)