Skip to content

Commit 580d33d

Browse files
authored
Merge pull request #523 from zhenlineo/4.0-api-doc
Improving js driver API doc
2 parents 272a049 + 5fc9c43 commit 580d33d

File tree

6 files changed

+97
-68
lines changed

6 files changed

+97
-68
lines changed

esdoc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"enable": true
3737
},
3838
"brand": {
39-
"title": "Neo4j Bolt Driver 2.0 for JavaScript",
39+
"title": "Neo4j Bolt Driver 4.0 for JavaScript",
4040
"repository": "https://github.com/neo4j/neo4j-javascript-driver"
4141
}
4242
}

src/driver.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class Driver {
102102
* @public
103103
* @param {Object} param - The object parameter
104104
* @param {string} param.database - The target database to verify connectivity for.
105-
* @returns {Promise} promise resolved with server info or rejected with error.
105+
* @returns {Promise<void>} promise resolved with server info or rejected with error.
106106
*/
107107
verifyConnectivity ({ database = '' } = {}) {
108108
const connectionProvider = this._getOrCreateConnectionProvider()
@@ -200,6 +200,7 @@ class Driver {
200200
* Close all open sessions and other associated resources. You should
201201
* make sure to use this when you are done with this driver instance.
202202
* @public
203+
* @return {Promise<void>} promise resolved when the driver is closed.
203204
*/
204205
close () {
205206
this._log.info(`Driver ${this._id} closing`)

src/error.js

+19
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ const SESSION_EXPIRED = 'SessionExpired'
3838
*/
3939
const PROTOCOL_ERROR = 'ProtocolError'
4040

41+
/**
42+
* Create a new error from a message and error code
43+
* @param message the error message
44+
* @param code the error code
45+
* @return {Neo4jError} an {@link Neo4jError}
46+
* @private
47+
*/
4148
function newError (message, code = 'N/A') {
4249
// TODO: Idea is that we can check the code here and throw sub-classes
4350
// of Neo4jError as appropriate
@@ -55,8 +62,20 @@ class Neo4jError extends Error {
5562
*/
5663
constructor (message, code = 'N/A') {
5764
super(message)
65+
/**
66+
* The error message
67+
* @type {string}
68+
*/
5869
this.message = message
70+
/**
71+
* Optional error code. Will be populated when error originates in the database.
72+
* @type {string}
73+
*/
5974
this.code = code
75+
/**
76+
* The name of the error.
77+
* @type {string}
78+
*/
6079
this.name = 'Neo4jError'
6180
}
6281
}

src/index.js

+65-65
Original file line numberDiff line numberDiff line change
@@ -56,70 +56,6 @@ import {
5656
} from './temporal-types'
5757
import ServerAddress from './internal/server-address'
5858

59-
/**
60-
* @property {function(username: string, password: string, realm: ?string)} basic the function to create a
61-
* basic authentication token.
62-
* @property {function(base64EncodedTicket: string)} kerberos the function to create a Kerberos authentication token.
63-
* Accepts a single string argument - base64 encoded Kerberos ticket.
64-
* @property {function(principal: string, credentials: string, realm: string, scheme: string, parameters: ?object)} custom
65-
* the function to create a custom authentication token.
66-
*/
67-
const auth = {
68-
basic: (username, password, realm = undefined) => {
69-
if (realm) {
70-
return {
71-
scheme: 'basic',
72-
principal: username,
73-
credentials: password,
74-
realm: realm
75-
}
76-
} else {
77-
return { scheme: 'basic', principal: username, credentials: password }
78-
}
79-
},
80-
kerberos: base64EncodedTicket => {
81-
return {
82-
scheme: 'kerberos',
83-
principal: '', // This empty string is required for backwards compatibility.
84-
credentials: base64EncodedTicket
85-
}
86-
},
87-
custom: (principal, credentials, realm, scheme, parameters = undefined) => {
88-
if (parameters) {
89-
return {
90-
scheme: scheme,
91-
principal: principal,
92-
credentials: credentials,
93-
realm: realm,
94-
parameters: parameters
95-
}
96-
} else {
97-
return {
98-
scheme: scheme,
99-
principal: principal,
100-
credentials: credentials,
101-
realm: realm
102-
}
103-
}
104-
}
105-
}
106-
const USER_AGENT = 'neo4j-javascript/' + VERSION
107-
108-
/**
109-
* Object containing predefined logging configurations. These are expected to be used as values of the driver config's `logging` property.
110-
* @property {function(level: ?string): object} console the function to create a logging config that prints all messages to `console.log` with
111-
* timestamp, level and message. It takes an optional `level` parameter which represents the maximum log level to be logged. Default value is 'info'.
112-
*/
113-
const logging = {
114-
console: level => {
115-
return {
116-
level: level,
117-
logger: (level, message) =>
118-
console.log(`${global.Date.now()} ${level.toUpperCase()} ${message}`)
119-
}
120-
}
121-
}
122-
12359
/**
12460
* Construct a new Neo4j Driver. This is your main entry point for this
12561
* library.
@@ -234,7 +170,7 @@ const logging = {
234170
* },
235171
* }
236172
*
237-
* @param {string} url The URL for the Neo4j database, for instance "bolt://localhost"
173+
* @param {string} url The URL for the Neo4j database, for instance "neo4j://localhost" and/or "bolt://localhost"
238174
* @param {Map<string,string>} authToken Authentication credentials. See {@link auth} for helpers.
239175
* @param {Object} config Configuration object. See the configuration section above for details.
240176
* @returns {Driver}
@@ -267,6 +203,70 @@ function driver (url, authToken, config = {}) {
267203
}
268204
}
269205

206+
/**
207+
* @property {function(username: string, password: string, realm: ?string)} basic the function to create a
208+
* basic authentication token.
209+
* @property {function(base64EncodedTicket: string)} kerberos the function to create a Kerberos authentication token.
210+
* Accepts a single string argument - base64 encoded Kerberos ticket.
211+
* @property {function(principal: string, credentials: string, realm: string, scheme: string, parameters: ?object)} custom
212+
* the function to create a custom authentication token.
213+
*/
214+
const auth = {
215+
basic: (username, password, realm = undefined) => {
216+
if (realm) {
217+
return {
218+
scheme: 'basic',
219+
principal: username,
220+
credentials: password,
221+
realm: realm
222+
}
223+
} else {
224+
return { scheme: 'basic', principal: username, credentials: password }
225+
}
226+
},
227+
kerberos: base64EncodedTicket => {
228+
return {
229+
scheme: 'kerberos',
230+
principal: '', // This empty string is required for backwards compatibility.
231+
credentials: base64EncodedTicket
232+
}
233+
},
234+
custom: (principal, credentials, realm, scheme, parameters = undefined) => {
235+
if (parameters) {
236+
return {
237+
scheme: scheme,
238+
principal: principal,
239+
credentials: credentials,
240+
realm: realm,
241+
parameters: parameters
242+
}
243+
} else {
244+
return {
245+
scheme: scheme,
246+
principal: principal,
247+
credentials: credentials,
248+
realm: realm
249+
}
250+
}
251+
}
252+
}
253+
const USER_AGENT = 'neo4j-javascript/' + VERSION
254+
255+
/**
256+
* Object containing predefined logging configurations. These are expected to be used as values of the driver config's `logging` property.
257+
* @property {function(level: ?string): object} console the function to create a logging config that prints all messages to `console.log` with
258+
* timestamp, level and message. It takes an optional `level` parameter which represents the maximum log level to be logged. Default value is 'info'.
259+
*/
260+
const logging = {
261+
console: level => {
262+
return {
263+
level: level,
264+
logger: (level, message) =>
265+
console.log(`${global.Date.now()} ${level.toUpperCase()} ${message}`)
266+
}
267+
}
268+
}
269+
270270
/**
271271
* Object containing constructors for all neo4j types.
272272
*/

src/result-summary.js

+10
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,19 @@ class ResultSummary {
5454
*/
5555
this.counters = new QueryStatistics(metadata.stats || {})
5656
// for backwards compatibility, remove in future version
57+
/**
58+
* Use {@link ResultSummary.counters} instead.
59+
* @type {QueryStatistics}
60+
* @deprecated
61+
*/
5762
this.updateStatistics = this.counters
5863

5964
/**
6065
* This describes how the database will execute the query.
6166
* Query plan for the executed query if available, otherwise undefined.
6267
* Will only be populated for queries that start with "EXPLAIN".
6368
* @type {Plan}
69+
* @public
6470
*/
6571
this.plan =
6672
metadata.plan || metadata.profile
@@ -329,6 +335,10 @@ function valueOrDefault (key, values, defaultValue = 0) {
329335
}
330336
}
331337

338+
/**
339+
* The constants for query types
340+
* @type {{SCHEMA_WRITE: string, WRITE_ONLY: string, READ_ONLY: string, READ_WRITE: string}}
341+
*/
332342
const queryType = {
333343
READ_ONLY: 'r',
334344
READ_WRITE: 'rw',

test/rx/nested-statements.test.js

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import neo4j from '../../src'
3131
import { ServerVersion, VERSION_4_0_0 } from '../../src/internal/server-version'
3232
import RxSession from '../../src/session-rx'
3333
import sharedNeo4j from '../internal/shared-neo4j'
34-
import { newError } from '../../src/error'
3534

3635
describe('#integration-rx transaction', () => {
3736
let driver

0 commit comments

Comments
 (0)