-
Notifications
You must be signed in to change notification settings - Fork 151
Introduce GqlStatusObject
support as notifications to ResultSummary
#1194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bigmontz
merged 43 commits into
neo4j:5.0
from
bigmontz:5.x/feature/gqlobject-in-summary
Jun 20, 2024
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
8d2ee88
Implement filtering GqlStatusObject in Bot layer
bigmontz a80c303
Sync deno
bigmontz 28917a8
Add Bolt 5.5 to handshake
bigmontz 6d3ed0f
Implement filtering in core and exposing it throug api
bigmontz 24f6225
Fix docs
bigmontz 951a6c8
Sync deno
bigmontz c00c24b
Extract Notification to their own file
bigmontz b1dc8d6
GqlStatusObject construction using native gql objects
bigmontz 3fd4e0c
Sync deno
bigmontz 2ee427e
Small fix
bigmontz 4760c86
Polyfilling and exposing GqlStatusCode
bigmontz 1db6c6e
Create gqlStatusObjects from statuses or notifications
bigmontz 9923c00
Sync deno
bigmontz 8ff2064
Polyfill notifications
bigmontz b18b345
Adjust descriptions and polifylled messages order
bigmontz e0e5608
Build notifications from metadata
bigmontz a342a84
Tests and fixes around stream status
bigmontz 433eb46
Testkit support + bug fixing
bigmontz eec6885
sync deno
bigmontz e47831f
Ordering gqlStatus
bigmontz 678b12e
sync deno
bigmontz 6de5a0c
Add default values
bigmontz 47ca007
Add test for default values
bigmontz 4caeca6
Implement new defaults and nullability
bigmontz e43d31e
Update packages/core/src/driver.ts
bigmontz 01b4020
Small fixes and sync deno
bigmontz 6fcea24
Adjust diagnostic record naming to avoid clashes
bigmontz a14dfac
fix test
bigmontz 3ef928d
Diagnostic record should only have null values when returned by the
bigmontz 23ecd0e
sync deno
bigmontz bedf5bb
Apply suggestions from code review
bigmontz 638a990
Update packages/core/test/notification.test.ts
bigmontz ada9fb2
address comments in the PR
bigmontz f9b117e
sync deno
bigmontz f7e4244
Ajust test
bigmontz 4e15f2d
update gqlstatus docs
bigmontz fa1fe22
sync deno
bigmontz b5984b3
Adjust diagnostic record serialization
bigmontz 7da3f78
Adjust status_description for warn and info
bigmontz 3d34596
Better type support for DiagnosticRecord
bigmontz c880682
More unit tests
bigmontz ac12a3f
Apply suggestions from code review
bigmontz 0dce222
Sync deno
bigmontz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
189 changes: 189 additions & 0 deletions
189
packages/bolt-connection/src/bolt/bolt-protocol-v5x5.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
/** | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [https://neo4j.com] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import BoltProtocolV5x4 from './bolt-protocol-v5x4' | ||
|
||
import transformersFactories from './bolt-protocol-v5x5.transformer' | ||
import Transformer from './transformer' | ||
import RequestMessage from './request-message' | ||
import { LoginObserver, ResultStreamObserver } from './stream-observers' | ||
|
||
import { internal } from 'neo4j-driver-core' | ||
|
||
const { | ||
constants: { BOLT_PROTOCOL_V5_5, FETCH_ALL } | ||
} = internal | ||
|
||
const DEFAULT_DIAGNOSTIC_RECORD = Object.freeze({ | ||
OPERATION: '', | ||
OPERATION_CODE: '0', | ||
CURRENT_SCHEMA: '/' | ||
}) | ||
|
||
export default class BoltProtocol extends BoltProtocolV5x4 { | ||
get version () { | ||
return BOLT_PROTOCOL_V5_5 | ||
} | ||
|
||
get transformer () { | ||
if (this._transformer === undefined) { | ||
this._transformer = new Transformer(Object.values(transformersFactories).map(create => create(this._config, this._log))) | ||
} | ||
return this._transformer | ||
} | ||
|
||
/** | ||
* Initialize a connection with the server | ||
* | ||
* @param {Object} args The params | ||
* @param {string} args.userAgent The user agent | ||
* @param {any} args.authToken The auth token | ||
* @param {NotificationFilter} args.notificationFilter The notification filters. | ||
* @param {function(error)} args.onError On error callback | ||
* @param {function(onComplete)} args.onComplete On complete callback | ||
* @returns {LoginObserver} The Login observer | ||
*/ | ||
initialize ({ userAgent, boltAgent, authToken, notificationFilter, onError, onComplete } = {}) { | ||
const state = {} | ||
const observer = new LoginObserver({ | ||
onError: error => this._onLoginError(error, onError), | ||
onCompleted: metadata => { | ||
state.metadata = metadata | ||
return this._onLoginCompleted(metadata) | ||
} | ||
}) | ||
|
||
this.write( | ||
RequestMessage.hello5x5(userAgent, boltAgent, notificationFilter, this._serversideRouting), | ||
observer, | ||
false | ||
) | ||
|
||
return this.logon({ | ||
authToken, | ||
onComplete: metadata => onComplete({ ...metadata, ...state.metadata }), | ||
onError, | ||
flush: true | ||
}) | ||
} | ||
|
||
beginTransaction ({ | ||
bookmarks, | ||
txConfig, | ||
database, | ||
mode, | ||
impersonatedUser, | ||
notificationFilter, | ||
beforeError, | ||
afterError, | ||
beforeComplete, | ||
afterComplete | ||
} = {}) { | ||
const observer = new ResultStreamObserver({ | ||
server: this._server, | ||
beforeError, | ||
afterError, | ||
beforeComplete, | ||
afterComplete | ||
}) | ||
observer.prepareToHandleSingleResponse() | ||
|
||
this.write( | ||
RequestMessage.begin5x5({ bookmarks, txConfig, database, mode, impersonatedUser, notificationFilter }), | ||
observer, | ||
true | ||
) | ||
|
||
return observer | ||
} | ||
|
||
run ( | ||
query, | ||
parameters, | ||
{ | ||
bookmarks, | ||
txConfig, | ||
database, | ||
mode, | ||
impersonatedUser, | ||
notificationFilter, | ||
beforeKeys, | ||
afterKeys, | ||
beforeError, | ||
afterError, | ||
beforeComplete, | ||
afterComplete, | ||
flush = true, | ||
reactive = false, | ||
fetchSize = FETCH_ALL, | ||
highRecordWatermark = Number.MAX_VALUE, | ||
lowRecordWatermark = Number.MAX_VALUE | ||
} = {} | ||
) { | ||
const observer = new ResultStreamObserver({ | ||
server: this._server, | ||
reactive, | ||
fetchSize, | ||
moreFunction: this._requestMore.bind(this), | ||
discardFunction: this._requestDiscard.bind(this), | ||
beforeKeys, | ||
afterKeys, | ||
beforeError, | ||
afterError, | ||
beforeComplete, | ||
afterComplete, | ||
highRecordWatermark, | ||
lowRecordWatermark, | ||
enrichMetadata: BoltProtocol._enrichMetadata | ||
}) | ||
|
||
const flushRun = reactive | ||
this.write( | ||
RequestMessage.runWithMetadata5x5(query, parameters, { | ||
bookmarks, | ||
txConfig, | ||
database, | ||
mode, | ||
impersonatedUser, | ||
notificationFilter | ||
}), | ||
observer, | ||
flushRun && flush | ||
) | ||
|
||
if (!reactive) { | ||
this.write(RequestMessage.pull({ n: fetchSize }), observer, flush) | ||
} | ||
|
||
return observer | ||
} | ||
|
||
/** | ||
* | ||
* @param {object} metadata | ||
* @returns {object} | ||
*/ | ||
static _enrichMetadata (metadata) { | ||
if (Array.isArray(metadata.statuses)) { | ||
metadata.statuses = metadata.statuses.map(status => ({ | ||
...status, | ||
diagnostic_record: status.diagnostic_record !== null ? { ...DEFAULT_DIAGNOSTIC_RECORD, ...status.diagnostic_record } : null | ||
})) | ||
} | ||
|
||
return metadata | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
packages/bolt-connection/src/bolt/bolt-protocol-v5x5.transformer.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* Copyright (c) "Neo4j" | ||
* Neo4j Sweden AB [https://neo4j.com] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import v5x3 from './bolt-protocol-v5x3.transformer' | ||
|
||
export default { | ||
...v5x3 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.