Home Reference Source

lib6/connection-provider.js

  1. /**
  2. * Copyright (c) "Neo4j"
  3. * Neo4j Sweden AB [https://neo4j.com]
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* eslint-disable @typescript-eslint/promise-function-async */
  18. /**
  19. * Interface define a releasable resource shape
  20. *
  21. * @private
  22. * @interface
  23. */
  24. class Releasable {
  25. /**
  26. * @returns {Promise<void>}
  27. */
  28. release() {
  29. throw new Error('Not implemented');
  30. }
  31. }
  32. /**
  33. * Interface define a common way to acquire a connection
  34. *
  35. * @private
  36. */
  37. class ConnectionProvider {
  38. /**
  39. * This method acquires a connection against the specified database.
  40. *
  41. * Access mode and Bookmarks only applies to routing driver. Access mode only
  42. * differentiates the target server for the connection, where WRITE selects a
  43. * WRITER server, whereas READ selects a READ server. Bookmarks, when specified,
  44. * is only passed to the routing discovery procedure, for the system database to
  45. * synchronize on creation of databases and is never used in direct drivers.
  46. *
  47. * @param {object} param - object parameter
  48. * @property {string} param.accessMode - the access mode for the to-be-acquired connection
  49. * @property {string} param.database - the target database for the to-be-acquired connection
  50. * @property {Bookmarks} param.bookmarks - the bookmarks to send to routing discovery
  51. * @property {string} param.impersonatedUser - the impersonated user
  52. * @property {function (databaseName:string?)} param.onDatabaseNameResolved - Callback called when the database name get resolved
  53. * @returns {Promise<Connection>}
  54. */
  55. acquireConnection(param) {
  56. throw Error('Not implemented');
  57. }
  58. /**
  59. * This method checks whether the backend database supports multi database functionality
  60. * by checking protocol handshake result.
  61. *
  62. * @returns {Promise<boolean>}
  63. */
  64. supportsMultiDb() {
  65. throw Error('Not implemented');
  66. }
  67. /**
  68. * This method checks whether the backend database supports transaction config functionality
  69. * by checking protocol handshake result.
  70. *
  71. * @returns {Promise<boolean>}
  72. */
  73. supportsTransactionConfig() {
  74. throw Error('Not implemented');
  75. }
  76. /**
  77. * This method checks whether the backend database supports transaction config functionality
  78. * by checking protocol handshake result.
  79. *
  80. * @returns {Promise<boolean>}
  81. */
  82. supportsUserImpersonation() {
  83. throw Error('Not implemented');
  84. }
  85. /**
  86. * This method checks whether the driver session re-auth functionality
  87. * by checking protocol handshake result
  88. *
  89. * @returns {Promise<boolean>}
  90. */
  91. supportsSessionAuth() {
  92. throw Error('Not implemented');
  93. }
  94. /**
  95. * This method verifies the connectivity of the database by trying to acquire a connection
  96. * for each server available in the cluster.
  97. *
  98. * @param {object} param - object parameter
  99. * @property {string} param.database - the target database for the to-be-acquired connection
  100. * @property {string} param.accessMode - the access mode for the to-be-acquired connection
  101. *
  102. * @returns {Promise<ServerInfo>} promise resolved with server info or rejected with error.
  103. */
  104. verifyConnectivityAndGetServerInfo(param) {
  105. throw Error('Not implemented');
  106. }
  107. /**
  108. * This method verifies the authorization credentials work by trying to acquire a connection
  109. * to one of the servers with the given credentials.
  110. *
  111. * @param {object} param - object parameter
  112. * @property {AuthToken} param.auth - the target auth for the to-be-acquired connection
  113. * @property {string} param.database - the target database for the to-be-acquired connection
  114. * @property {string} param.accessMode - the access mode for the to-be-acquired connection
  115. *
  116. * @returns {Promise<boolean>} promise resolved with true if succeed, false if failed with
  117. * authentication issue and rejected with error if non-authentication error happens.
  118. */
  119. verifyAuthentication(param) {
  120. throw Error('Not implemented');
  121. }
  122. /**
  123. * Returns the protocol version negotiated via handshake.
  124. *
  125. * Note that this function call _always_ causes a round-trip to the server.
  126. *
  127. * @returns {Promise<number>} the protocol version negotiated via handshake.
  128. * @throws {Error} When protocol negotiation fails
  129. */
  130. getNegotiatedProtocolVersion() {
  131. throw Error('Not Implemented');
  132. }
  133. /**
  134. * Closes this connection provider along with its internals (connections, pools, etc.)
  135. *
  136. * @returns {Promise<void>}
  137. */
  138. close() {
  139. throw Error('Not implemented');
  140. }
  141. }
  142. export default ConnectionProvider;
  143. export { Releasable };