Skip to content

Commit 97f3840

Browse files
committed
Make newly created session return no bookmarks
1 parent c45a6b9 commit 97f3840

File tree

4 files changed

+27
-21
lines changed

4 files changed

+27
-21
lines changed

packages/core/src/internal/bookmark.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const EMPTY_BOOKMARK = new Bookmark(null)
7979
* @return {string[]} value converted to an array.
8080
*/
8181
function asStringArray(
82-
value?: string | string[] | Array<string> | null
82+
value?: string | (string | undefined)[] | Array<string | undefined> | null
8383
): string[] {
8484
if (!value) {
8585
return []

packages/core/src/session.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ class Session {
5555
private _writeConnectionHolder: ConnectionHolder
5656
private _open: boolean
5757
private _hasTx: boolean
58-
private _lastBookmark: Bookmark
58+
private _bookmarkIn: Bookmark
59+
private _bookmarkOut?: string
5960
private _transactionExecutor: TransactionExecutor
6061
private _impersonatedUser?: string
6162
private _onComplete: (meta: any) => void
@@ -117,7 +118,7 @@ class Session {
117118
this._open = true
118119
this._hasTx = false
119120
this._impersonatedUser = impersonatedUser
120-
this._lastBookmark = bookmark || Bookmark.empty()
121+
this._bookmarkIn = bookmark || Bookmark.empty()
121122
this._transactionExecutor = _createTransactionExecutor(config)
122123
this._onComplete = this._onCompleteCallback.bind(this)
123124
this._databaseNameResolved = this._database !== ''
@@ -150,7 +151,7 @@ class Session {
150151
return this._run(validatedQuery, params, connection => {
151152
this._assertSessionIsOpen()
152153
return (connection as Connection).protocol().run(validatedQuery, params, {
153-
bookmark: this._lastBookmark,
154+
bookmark: this._bookmarkIn,
154155
txConfig: autoCommitTxConfig,
155156
mode: this._mode,
156157
database: this._database,
@@ -271,7 +272,7 @@ class Session {
271272
reactive: this._reactive,
272273
fetchSize: this._fetchSize
273274
})
274-
tx._begin(this._lastBookmark, txConfig)
275+
tx._begin(this._bookmarkIn, txConfig)
275276
return tx
276277
}
277278

@@ -296,10 +297,10 @@ class Session {
296297
/**
297298
* Return the bookmark received following the last completed {@link Transaction}.
298299
*
299-
* @return {string[]} A reference to a previous transaction.
300+
* @return {string | undefined} A reference to a previous transaction if present.
300301
*/
301-
lastBookmark(): string[] {
302-
return this._lastBookmark.values()
302+
lastBookmark(): string | undefined {
303+
return this._bookmarkOut
303304
}
304305

305306
/**
@@ -360,7 +361,7 @@ class Session {
360361
/**
361362
* Sets the resolved database name in the session context.
362363
* @private
363-
* @param {string|undefined} database The resolved database name
364+
* @param {string | undefined} database The resolved database name
364365
* @returns {void}
365366
*/
366367
_onDatabaseNameResolved(database?: string): void {
@@ -376,12 +377,13 @@ class Session {
376377
/**
377378
* Update value of the last bookmark.
378379
* @private
379-
* @param {Bookmark} newBookmark - The new bookmark.
380+
* @param {string | undefined} newBookmark - The new bookmark.
380381
* @returns {void}
381382
*/
382-
_updateBookmark(newBookmark?: Bookmark): void {
383-
if (newBookmark && !newBookmark.isEmpty()) {
384-
this._lastBookmark = newBookmark
383+
_updateBookmark(newBookmark?: string): void {
384+
if (newBookmark !== undefined) {
385+
this._bookmarkIn = new Bookmark(newBookmark)
386+
this._bookmarkOut = newBookmark
385387
}
386388
}
387389

@@ -414,8 +416,8 @@ class Session {
414416
* @param {Object} meta Connection metadatada
415417
* @returns {void}
416418
*/
417-
_onCompleteCallback(meta: { bookmark: string | string[] }): void {
418-
this._updateBookmark(new Bookmark(meta.bookmark))
419+
_onCompleteCallback(meta: { bookmark: string }): void {
420+
this._updateBookmark(meta.bookmark)
419421
}
420422

421423
/**

packages/core/src/transaction.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Transaction {
4646
private _reactive: boolean
4747
private _state: any
4848
private _onClose: () => void
49-
private _onBookmark: (bookmark: Bookmark) => void
49+
private _onBookmark: (bookmark: string | undefined ) => void
5050
private _onConnection: () => void
5151
private _onError: (error: Error) => Promise<Connection | void>
5252
private _onComplete: (metadata: any) => void
@@ -58,7 +58,7 @@ class Transaction {
5858
* @constructor
5959
* @param {ConnectionHolder} connectionHolder - the connection holder to get connection from.
6060
* @param {function()} onClose - Function to be called when transaction is committed or rolled back.
61-
* @param {function(bookmark: Bookmark)} onBookmark callback invoked when new bookmark is produced.
61+
* @param {function(bookmark: string | undefined)} onBookmark callback invoked when new bookmark is produced.
6262
* * @param {function()} onConnection - Function to be called when a connection is obtained to ensure the conneciton
6363
* is not yet released.
6464
* @param {boolean} reactive whether this transaction generates reactive streams
@@ -76,7 +76,7 @@ class Transaction {
7676
}: {
7777
connectionHolder: ConnectionHolder
7878
onClose: () => void
79-
onBookmark: (bookmark: Bookmark) => void
79+
onBookmark: (bookmark: string | undefined) => void
8080
onConnection: () => void
8181
reactive: boolean
8282
fetchSize: number
@@ -226,8 +226,8 @@ class Transaction {
226226
* @param {object} meta The meta with bookmark
227227
* @returns {void}
228228
*/
229-
_onCompleteCallback(meta: { bookmark?: string | string[] }): void {
230-
this._onBookmark(new Bookmark(meta.bookmark))
229+
_onCompleteCallback(meta: { bookmark?: string }): void {
230+
this._onBookmark(meta.bookmark)
231231
}
232232
}
233233

packages/testkit-backend/src/request-handlers.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,11 @@ export function TransactionRollback (context, data, wire) {
288288
export function SessionLastBookmarks (context, data, wire) {
289289
const { sessionId } = data
290290
const session = context.getSession(sessionId)
291-
const bookmarks = session.lastBookmark()
291+
const bookmark = session.lastBookmark()
292+
const bookmarks = []
293+
if (bookmark !== undefined) {
294+
bookmarks.push(bookmark)
295+
}
292296
wire.writeResponse('Bookmarks', { bookmarks })
293297
}
294298

0 commit comments

Comments
 (0)