20
20
/* eslint-disable @typescript-eslint/promise-function-async */
21
21
22
22
import ResultSummary from './result-summary'
23
- import Record , { Dict } from './record'
23
+ import Record , { RecordShape } from './record'
24
24
import { Query , PeekableAsyncIterator } from './types'
25
25
import { observer , util , connectionHolder } from './internal'
26
26
import { newError , PROTOCOL_ERROR } from './error'
@@ -56,16 +56,16 @@ const DEFAULT_ON_KEYS = (keys: string[]): void => {}
56
56
* The query result is the combination of the {@link ResultSummary} and
57
57
* the array {@link Record[]} produced by the query
58
58
*/
59
- interface QueryResult < RecordShape extends Dict = Dict > {
60
- records : Array < Record < RecordShape > >
59
+ interface QueryResult < R extends RecordShape = RecordShape > {
60
+ records : Array < Record < R > >
61
61
summary : ResultSummary
62
62
}
63
63
64
64
/**
65
65
* Interface to observe updates on the Result which is being produced.
66
66
*
67
67
*/
68
- interface ResultObserver < RecordShape extends Dict = Dict > {
68
+ interface ResultObserver < R extends RecordShape = RecordShape > {
69
69
/**
70
70
* Receive the keys present on the record whenever this information is available
71
71
*
@@ -77,7 +77,7 @@ interface ResultObserver<RecordShape extends Dict =Dict> {
77
77
* Receive the each record present on the {@link @Result }
78
78
* @param {Record } record The {@link Record} produced
79
79
*/
80
- onNext ?: ( record : Record < RecordShape > ) => void
80
+ onNext ?: ( record : Record < R > ) => void
81
81
82
82
/**
83
83
* Called when the result is fully received
@@ -86,7 +86,7 @@ interface ResultObserver<RecordShape extends Dict =Dict> {
86
86
onCompleted ?: ( summary : ResultSummary ) => void
87
87
88
88
/**
89
- * Called when some error occurs during the result proccess or query execution
89
+ * Called when some error occurs during the result processing or query execution
90
90
* @param {Error } error The error ocurred
91
91
*/
92
92
onError ?: ( error : Error ) => void
@@ -111,7 +111,7 @@ interface QueuedResultObserver extends ResultObserver {
111
111
* Alternatively can be consumed lazily using {@link Result#subscribe} function.
112
112
* @access public
113
113
*/
114
- class Result < RecordShape extends Dict = Dict > implements Promise < QueryResult < RecordShape > > {
114
+ class Result < R extends RecordShape = RecordShape > implements Promise < QueryResult < R > > {
115
115
private readonly _stack : string | null
116
116
private readonly _streamObserverPromise : Promise < observer . ResultStreamObserver >
117
117
private _p : Promise < QueryResult > | null
@@ -212,12 +212,12 @@ class Result<RecordShape extends Dict = Dict> implements Promise<QueryResult<Rec
212
212
* @private
213
213
* @return {Promise } new Promise.
214
214
*/
215
- private _getOrCreatePromise ( ) : Promise < QueryResult < RecordShape > > {
215
+ private _getOrCreatePromise ( ) : Promise < QueryResult < R > > {
216
216
if ( this . _p == null ) {
217
217
this . _p = new Promise ( ( resolve , reject ) => {
218
- const records : Record [ ] = [ ]
218
+ const records : Array < Record < R > > = [ ]
219
219
const observer = {
220
- onNext : ( record : Record ) => {
220
+ onNext : ( record : Record < R > ) => {
221
221
records . push ( record )
222
222
} ,
223
223
onCompleted : ( summary : ResultSummary ) => {
@@ -240,9 +240,9 @@ class Result<RecordShape extends Dict = Dict> implements Promise<QueryResult<Rec
240
240
* *Should not be combined with {@link Result#subscribe} or ${@link Result#then} functions.*
241
241
*
242
242
* @public
243
- * @returns {PeekableAsyncIterator<Record<RecordShape >, ResultSummary> } The async iterator for the Results
243
+ * @returns {PeekableAsyncIterator<Record<R >, ResultSummary> } The async iterator for the Results
244
244
*/
245
- [ Symbol . asyncIterator ] ( ) : PeekableAsyncIterator < Record < RecordShape > , ResultSummary > {
245
+ [ Symbol . asyncIterator ] ( ) : PeekableAsyncIterator < Record < R > , ResultSummary > {
246
246
if ( ! this . isOpen ( ) ) {
247
247
const error = newError ( 'Result is already consumed' )
248
248
return {
@@ -345,9 +345,9 @@ class Result<RecordShape extends Dict = Dict> implements Promise<QueryResult<Rec
345
345
* @param {function(error: {message:string, code:string}) } onRejected - function to be called upon errors.
346
346
* @return {Promise } promise.
347
347
*/
348
- then < TResult1 = QueryResult < RecordShape > , TResult2 = never > (
348
+ then < TResult1 = QueryResult < R > , TResult2 = never > (
349
349
onFulfilled ?:
350
- | ( ( value : QueryResult < RecordShape > ) => TResult1 | PromiseLike < TResult1 > )
350
+ | ( ( value : QueryResult < R > ) => TResult1 | PromiseLike < TResult1 > )
351
351
| null ,
352
352
onRejected ?: ( ( reason : any ) => TResult2 | PromiseLike < TResult2 > ) | null
353
353
) : Promise < TResult1 | TResult2 > {
@@ -364,7 +364,7 @@ class Result<RecordShape extends Dict = Dict> implements Promise<QueryResult<Rec
364
364
*/
365
365
catch < TResult = never > (
366
366
onRejected ?: ( ( reason : any ) => TResult | PromiseLike < TResult > ) | null
367
- ) : Promise < QueryResult < RecordShape > | TResult > {
367
+ ) : Promise < QueryResult < R > | TResult > {
368
368
return this . _getOrCreatePromise ( ) . catch ( onRejected )
369
369
}
370
370
@@ -376,7 +376,7 @@ class Result<RecordShape extends Dict = Dict> implements Promise<QueryResult<Rec
376
376
* @return {Promise } promise.
377
377
*/
378
378
[ Symbol . toStringTag ] : string
379
- finally ( onfinally ?: ( ( ) => void ) | null ) : Promise < QueryResult < RecordShape > > {
379
+ finally ( onfinally ?: ( ( ) => void ) | null ) : Promise < QueryResult < R > > {
380
380
return this . _getOrCreatePromise ( ) . finally ( onfinally )
381
381
}
382
382
@@ -391,7 +391,7 @@ class Result<RecordShape extends Dict = Dict> implements Promise<QueryResult<Rec
391
391
* @param {function(error: {message:string, code:string}) } observer.onError - handle errors.
392
392
* @return {void }
393
393
*/
394
- subscribe ( observer : ResultObserver < RecordShape > ) : void {
394
+ subscribe ( observer : ResultObserver < R > ) : void {
395
395
this . _subscribe ( observer )
396
396
. catch ( ( ) => { } )
397
397
}
0 commit comments