Skip to content

Commit 82c435a

Browse files
committed
Move connection holdes and constants to core
1 parent 109b227 commit 82c435a

File tree

9 files changed

+393
-282
lines changed

9 files changed

+393
-282
lines changed

core/src/connection.ts

Lines changed: 23 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717
* limitations under the License.
1818
*/
1919

20-
import { newError } from './error'
21-
2220
/**
2321
* Interface which defines the raw connection with the database
2422
* @private
2523
*/
26-
interface Connection {
24+
class Connection {
2725
id: string
2826
databaseId: string
2927
server: any
@@ -41,89 +39,61 @@ interface Connection {
4139
/**
4240
* @returns {boolean} whether this connection is in a working condition
4341
*/
44-
isOpen(): boolean
42+
isOpen (): boolean {
43+
return false
44+
}
4545

4646
/**
4747
* @todo be removed and internalize the methods
4848
* @returns {any} the underlying bolt protocol assigned to this connection
4949
*/
50-
protocol(): any
50+
protocol (): any {
51+
throw Error('Not implemented')
52+
}
5153

5254
/**
5355
* Connect to the target address, negotiate Bolt protocol and send initialization message.
5456
* @param {string} userAgent the user agent for this driver.
5557
* @param {Object} authToken the object containing auth information.
5658
* @return {Promise<Connection>} promise resolved with the current connection if connection is successful. Rejected promise otherwise.
5759
*/
58-
connect(userAgent: string, authToken: any): Promise<Connection>
60+
connect (userAgent: string, authToken: any): Promise<Connection> {
61+
throw Error('Not implemented')
62+
}
5963

6064
/**
6165
* Write a message to the network channel.
6266
* @param {RequestMessage} message the message to write.
6367
* @param {ResultStreamObserver} observer the response observer.
6468
* @param {boolean} flush `true` if flush should happen after the message is written to the buffer.
6569
*/
66-
write(message: any, observer: any, flush: boolean): void
70+
write (message: any, observer: any, flush: boolean): void {
71+
throw Error('Not implemented')
72+
}
73+
6774
/**
6875
* Send a RESET-message to the database. Message is immediately flushed to the network.
6976
* @return {Promise<void>} promise resolved when SUCCESS-message response arrives, or failed when other response messages arrives.
7077
*/
71-
resetAndFlush(): Promise<void>
78+
resetAndFlush (): Promise<void> {
79+
throw Error('Not implemented')
80+
}
7281

7382
/**
7483
* Call close on the channel.
7584
* @returns {Promise<void>} - A promise that will be resolved when the connection is closed.
7685
*
7786
*/
78-
close(): Promise<void>
79-
}
80-
81-
/**
82-
* @private
83-
*/
84-
interface ConnectionHolder {
85-
mode(): string | undefined
86-
database(): string | undefined
87-
initializeConnection(): boolean
88-
getConnection(): Promise<Connection>
89-
releaseConnection(): Promise<Connection | void>
90-
close(): Promise<Connection | void>
91-
}
92-
93-
class EmptyConnectionHolder implements ConnectionHolder {
94-
mode(): undefined {
95-
return undefined
87+
close (): Promise<void> {
88+
throw Error('Not implemented')
9689
}
9790

98-
database(): undefined {
99-
return undefined
100-
}
101-
102-
initializeConnection() {
103-
// nothing to initialize
104-
return true
105-
}
106-
107-
getConnection(): Promise<Connection> {
108-
return Promise.reject(
109-
newError('This connection holder does not serve connections')
110-
)
111-
}
112-
113-
releaseConnection(): Promise<void> {
114-
return Promise.resolve()
115-
}
116-
117-
close(): Promise<void> {
91+
/**
92+
* Called to release the connection
93+
*/
94+
_release (): Promise<void> {
11895
return Promise.resolve()
11996
}
12097
}
12198

122-
/**
123-
* Connection holder that does not manage any connections.
124-
* @type {ConnectionHolder}
125-
*/
126-
const EMPTY_CONNECTION_HOLDER = new EmptyConnectionHolder()
127-
12899
export default Connection
129-
export { ConnectionHolder, EMPTY_CONNECTION_HOLDER }

0 commit comments

Comments
 (0)