Skip to content

Commit 3f7614e

Browse files
committed
Verifying types exported by the lite version
1 parent d560d3f commit 3f7614e

File tree

10 files changed

+372
-22
lines changed

10 files changed

+372
-22
lines changed

core/src/driver.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ import { Logger } from './internal/logger'
3333
import Session from './session'
3434
import { ServerInfo } from './result-summary'
3535
import { ENCRYPTION_ON, ENCRYPTION_OFF } from './internal/util'
36-
import { EncryptionLevel, LoggingConfig, TrustStrategy } from './types'
36+
import {
37+
EncryptionLevel,
38+
LoggingConfig,
39+
TrustStrategy,
40+
SessionMode
41+
} from './types'
3742
import { ServerAddress } from './internal/server-address'
3843

3944
const DEFAULT_MAX_CONNECTION_LIFETIME: number = 60 * 60 * 1000 // 1 hour
@@ -49,14 +54,14 @@ const DEFAULT_FETCH_SIZE: number = 1000
4954
* Should be used like this: `driver.session({ defaultAccessMode: neo4j.session.READ })`.
5055
* @type {string}
5156
*/
52-
const READ: string = ACCESS_MODE_READ
57+
const READ: SessionMode = ACCESS_MODE_READ
5358

5459
/**
5560
* Constant that represents write session access mode.
5661
* Should be used like this: `driver.session({ defaultAccessMode: neo4j.session.WRITE })`.
5762
* @type {string}
5863
*/
59-
const WRITE: string = ACCESS_MODE_WRITE
64+
const WRITE: SessionMode = ACCESS_MODE_WRITE
6065

6166
let idGenerator = 0
6267

@@ -227,7 +232,7 @@ class Driver {
227232
database = '',
228233
fetchSize
229234
}: {
230-
defaultAccessMode?: string
235+
defaultAccessMode?: SessionMode
231236
bookmarks?: string | string[]
232237
database?: string
233238
fetchSize?: number
@@ -274,7 +279,7 @@ class Driver {
274279
reactive,
275280
fetchSize
276281
}: {
277-
defaultAccessMode: string
282+
defaultAccessMode: SessionMode
278283
bookmarkOrBookmarks?: string | string[]
279284
database: string
280285
reactive: boolean

core/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ import ResultSummary, {
6767
} from './result-summary'
6868
import Result, { QueryResult, ResultObserver } from './result'
6969
import ConnectionProvider from './connection-provider'
70+
import Connection from './connection'
7071
import Transaction from './transaction'
7172
import Session, { TransactionConfig } from './session'
7273
import Driver, * as driver from './driver'
@@ -133,6 +134,7 @@ const forExport = {
133134
Transaction,
134135
Session,
135136
Driver,
137+
Connection,
136138
types,
137139
driver
138140
}
@@ -188,6 +190,7 @@ export {
188190
QueryResult,
189191
ResultObserver,
190192
ConnectionProvider,
193+
Connection,
191194
Transaction,
192195
Session,
193196
TransactionConfig,

core/src/internal/constants.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ const FETCH_ALL = -1
2121
const DEFAULT_POOL_ACQUISITION_TIMEOUT = 60 * 1000 // 60 seconds
2222
const DEFAULT_POOL_MAX_SIZE = 100
2323

24-
const ACCESS_MODE_READ: string = 'READ'
25-
const ACCESS_MODE_WRITE: string = 'WRITE'
24+
const ACCESS_MODE_READ: 'READ' = 'READ'
25+
const ACCESS_MODE_WRITE: 'WRITE' = 'WRITE'
2626

2727
const BOLT_PROTOCOL_V1: number = 1
2828
const BOLT_PROTOCOL_V2: number = 2

core/src/session.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { TransactionExecutor } from './internal/transaction-executor'
2727
import { Bookmark } from './internal/bookmark'
2828
import { TxConfig } from './internal/tx-config'
2929
import ConnectionProvider from './connection-provider'
30-
import { Query } from './types'
30+
import { Query, SessionMode } from './types'
3131
import Connection from './connection'
3232
import { NumberOrInteger } from './graph-types'
3333

@@ -47,7 +47,7 @@ interface TransactionConfig {
4747
* @access public
4848
*/
4949
class Session {
50-
private _mode: string
50+
private _mode: SessionMode
5151
private _database: string
5252
private _reactive: boolean
5353
private _fetchSize: number
@@ -80,9 +80,9 @@ class Session {
8080
reactive,
8181
fetchSize
8282
}: {
83-
mode: string
83+
mode: SessionMode
8484
connectionProvider: ConnectionProvider
85-
bookmark: Bookmark
85+
bookmark?: Bookmark
8686
database: string
8787
config: any
8888
reactive: boolean
@@ -106,7 +106,7 @@ class Session {
106106
})
107107
this._open = true
108108
this._hasTx = false
109-
this._lastBookmark = bookmark
109+
this._lastBookmark = bookmark || Bookmark.empty()
110110
this._transactionExecutor = _createTransactionExecutor(config)
111111
this._onComplete = this._onCompleteCallback.bind(this)
112112
}
@@ -233,7 +233,7 @@ class Session {
233233
return this._beginTransaction(this._mode, txConfig)
234234
}
235235

236-
_beginTransaction(accessMode: string, txConfig: TxConfig): Transaction {
236+
_beginTransaction(accessMode: SessionMode, txConfig: TxConfig): Transaction {
237237
if (!this._open) {
238238
throw newError('Cannot begin a transaction on a closed session.')
239239
}
@@ -333,7 +333,7 @@ class Session {
333333
}
334334

335335
_runTransaction<T>(
336-
accessMode: string,
336+
accessMode: SessionMode,
337337
transactionConfig: TxConfig,
338338
transactionWork: TransactionWork<T>
339339
): Promise<T> {
@@ -369,7 +369,7 @@ class Session {
369369
}
370370
}
371371

372-
_connectionHolderWithMode(mode: string): ConnectionHolder {
372+
_connectionHolderWithMode(mode: SessionMode): ConnectionHolder {
373373
if (mode === ACCESS_MODE_READ) {
374374
return this._readConnectionHolder
375375
} else if (mode === ACCESS_MODE_WRITE) {
@@ -391,7 +391,7 @@ class Session {
391391
/**
392392
* @protected
393393
*/
394-
static _validateSessionMode(rawMode?: string): string {
394+
static _validateSessionMode(rawMode?: SessionMode): SessionMode {
395395
const mode = rawMode || ACCESS_MODE_WRITE
396396
if (mode !== ACCESS_MODE_READ && mode !== ACCESS_MODE_WRITE) {
397397
throw newError('Illegal session mode ' + mode)

core/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export type LogLevel = 'error' | 'warn' | 'info' | 'debug'
2828

2929
export type LoggerFunction = (level: LogLevel, message: string) => unknown
3030

31+
export type SessionMode = 'READ' | 'WRITE'
32+
3133
export interface LoggingConfig {
3234
level?: LogLevel
3335
logger: LoggerFunction

neo4j-driver-lite/src/index.ts

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ import {
5353
ConnectionProvider,
5454
Driver,
5555
QueryResult,
56+
ResultObserver,
57+
Plan,
58+
ProfiledPlan,
59+
QueryStatistics,
60+
Notification,
61+
NotificationPosition,
62+
Session,
63+
Transaction,
64+
ServerInfo,
65+
Connection,
5666
driver as coreDriver,
5767
types as coreTypes
5868
} from 'neo4j-driver-core'
@@ -64,6 +74,8 @@ import {
6474
type AuthToken = coreTypes.AuthToken
6575
type Config = coreTypes.Config
6676
type TrustStrategy = coreTypes.TrustStrategy
77+
type EncryptionLevel = coreTypes.EncryptionLevel
78+
type SessionMode = coreTypes.SessionMode
6779
type Logger = internal.logger.Logger
6880
type ConfiguredCustomResolver = internal.resolver.ConfiguredCustomResolver
6981
type LogLevel = coreTypes.LogLevel
@@ -456,7 +468,31 @@ const forExport = {
456468
spatial,
457469
temporal,
458470
Driver,
459-
Result
471+
Result,
472+
Record,
473+
ResultSummary,
474+
Node,
475+
Relationship,
476+
UnboundRelationship,
477+
PathSegment,
478+
Path,
479+
Integer,
480+
Plan,
481+
ProfiledPlan,
482+
QueryStatistics,
483+
Notification,
484+
ServerInfo,
485+
Session,
486+
Transaction,
487+
Point,
488+
Duration,
489+
LocalTime,
490+
Time,
491+
Date,
492+
LocalDateTime,
493+
DateTime,
494+
ConnectionProvider,
495+
Connection
460496
}
461497

462498
export {
@@ -481,6 +517,37 @@ export {
481517
temporal,
482518
Driver,
483519
Result,
484-
QueryResult
520+
QueryResult,
521+
Record,
522+
ResultSummary,
523+
AuthToken,
524+
Config,
525+
EncryptionLevel,
526+
TrustStrategy,
527+
SessionMode,
528+
Node,
529+
Relationship,
530+
UnboundRelationship,
531+
PathSegment,
532+
Path,
533+
Integer,
534+
ResultObserver,
535+
Plan,
536+
ProfiledPlan,
537+
QueryStatistics,
538+
Notification,
539+
NotificationPosition,
540+
ServerInfo,
541+
Session,
542+
Transaction,
543+
Point,
544+
Duration,
545+
LocalTime,
546+
Time,
547+
Date,
548+
LocalDateTime,
549+
DateTime,
550+
ConnectionProvider,
551+
Connection
485552
}
486553
export default forExport

0 commit comments

Comments
 (0)