Skip to content

Commit ded7fde

Browse files
committed
Committing the source
1 parent a3bdcbb commit ded7fde

File tree

113 files changed

+21463
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+21463
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
import { newError } from '../../core/index.ts'
20+
// eslint-disable-next-line no-unused-vars
21+
import { ResultStreamObserver } from './stream-observers.js'
22+
23+
/**
24+
* @param {TxConfig} txConfig the auto-commit transaction configuration.
25+
* @param {function(error: string)} onProtocolError called when the txConfig is not empty.
26+
* @param {ResultStreamObserver} observer the response observer.
27+
*/
28+
function assertTxConfigIsEmpty (txConfig, onProtocolError = () => {}, observer) {
29+
if (txConfig && !txConfig.isEmpty()) {
30+
const error = newError(
31+
'Driver is connected to the database that does not support transaction configuration. ' +
32+
'Please upgrade to neo4j 3.5.0 or later in order to use this functionality'
33+
)
34+
35+
// unsupported API was used, consider this a fatal error for the current connection
36+
onProtocolError(error.message)
37+
observer.onError(error)
38+
throw error
39+
}
40+
}
41+
42+
/**
43+
* Asserts that the passed-in database name is empty.
44+
* @param {string} database
45+
* @param {fuction(err: String)} onProtocolError Called when it doesn't have database set
46+
*/
47+
function assertDatabaseIsEmpty (database, onProtocolError = () => {}, observer) {
48+
if (database) {
49+
const error = newError(
50+
'Driver is connected to the database that does not support multiple databases. ' +
51+
'Please upgrade to neo4j 4.0.0 or later in order to use this functionality'
52+
)
53+
54+
// unsupported API was used, consider this a fatal error for the current connection
55+
onProtocolError(error.message)
56+
observer.onError(error)
57+
throw error
58+
}
59+
}
60+
61+
/**
62+
* Asserts that the passed-in impersonated user is empty
63+
* @param {string} impersonatedUser
64+
* @param {function (err:Error)} onProtocolError Called when it does have impersonated user set
65+
* @param {any} observer
66+
*/
67+
function assertImpersonatedUserIsEmpty (impersonatedUser, onProtocolError = () => {}, observer) {
68+
if (impersonatedUser) {
69+
const error = newError(
70+
'Driver is connected to the database that does not support user impersonation. ' +
71+
'Please upgrade to neo4j 4.4.0 or later in order to use this functionality. ' +
72+
`Trying to impersonate ${impersonatedUser}.`
73+
)
74+
75+
// unsupported API was used, consider this a fatal error for the current connection
76+
onProtocolError(error.message)
77+
observer.onError(error)
78+
throw error
79+
}
80+
}
81+
82+
export { assertDatabaseIsEmpty, assertTxConfigIsEmpty, assertImpersonatedUserIsEmpty }

0 commit comments

Comments
 (0)