2020/* eslint-disable @typescript-eslint/promise-function-async */
2121
2222import ResultSummary from './result-summary'
23- import Record , { Dict } from './record'
23+ import Record , { RecordShape } from './record'
2424import { Query , PeekableAsyncIterator } from './types'
2525import { observer , util , connectionHolder } from './internal'
2626import { newError , PROTOCOL_ERROR } from './error'
@@ -56,16 +56,16 @@ const DEFAULT_ON_KEYS = (keys: string[]): void => {}
5656 * The query result is the combination of the {@link ResultSummary} and
5757 * the array {@link Record[]} produced by the query
5858 */
59- interface QueryResult < RecordShape extends Dict = Dict > {
60- records : Array < Record < RecordShape > >
59+ interface QueryResult < R extends RecordShape = RecordShape > {
60+ records : Array < Record < R > >
6161 summary : ResultSummary
6262}
6363
6464/**
6565 * Interface to observe updates on the Result which is being produced.
6666 *
6767 */
68- interface ResultObserver < RecordShape extends Dict = Dict > {
68+ interface ResultObserver < R extends RecordShape = RecordShape > {
6969 /**
7070 * Receive the keys present on the record whenever this information is available
7171 *
@@ -77,7 +77,7 @@ interface ResultObserver<RecordShape extends Dict =Dict> {
7777 * Receive the each record present on the {@link @Result }
7878 * @param {Record } record The {@link Record} produced
7979 */
80- onNext ?: ( record : Record < RecordShape > ) => void
80+ onNext ?: ( record : Record < R > ) => void
8181
8282 /**
8383 * Called when the result is fully received
@@ -86,7 +86,7 @@ interface ResultObserver<RecordShape extends Dict =Dict> {
8686 onCompleted ?: ( summary : ResultSummary ) => void
8787
8888 /**
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
9090 * @param {Error } error The error ocurred
9191 */
9292 onError ?: ( error : Error ) => void
@@ -111,7 +111,7 @@ interface QueuedResultObserver extends ResultObserver {
111111 * Alternatively can be consumed lazily using {@link Result#subscribe} function.
112112 * @access public
113113 */
114- class Result < RecordShape extends Dict = Dict > implements Promise < QueryResult < RecordShape > > {
114+ class Result < R extends RecordShape = RecordShape > implements Promise < QueryResult < R > > {
115115 private readonly _stack : string | null
116116 private readonly _streamObserverPromise : Promise < observer . ResultStreamObserver >
117117 private _p : Promise < QueryResult > | null
@@ -212,12 +212,12 @@ class Result<RecordShape extends Dict = Dict> implements Promise<QueryResult<Rec
212212 * @private
213213 * @return {Promise } new Promise.
214214 */
215- private _getOrCreatePromise ( ) : Promise < QueryResult < RecordShape > > {
215+ private _getOrCreatePromise ( ) : Promise < QueryResult < R > > {
216216 if ( this . _p == null ) {
217217 this . _p = new Promise ( ( resolve , reject ) => {
218- const records : Record [ ] = [ ]
218+ const records : Array < Record < R > > = [ ]
219219 const observer = {
220- onNext : ( record : Record ) => {
220+ onNext : ( record : Record < R > ) => {
221221 records . push ( record )
222222 } ,
223223 onCompleted : ( summary : ResultSummary ) => {
@@ -240,9 +240,9 @@ class Result<RecordShape extends Dict = Dict> implements Promise<QueryResult<Rec
240240 * *Should not be combined with {@link Result#subscribe} or ${@link Result#then} functions.*
241241 *
242242 * @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
244244 */
245- [ Symbol . asyncIterator ] ( ) : PeekableAsyncIterator < Record < RecordShape > , ResultSummary > {
245+ [ Symbol . asyncIterator ] ( ) : PeekableAsyncIterator < Record < R > , ResultSummary > {
246246 if ( ! this . isOpen ( ) ) {
247247 const error = newError ( 'Result is already consumed' )
248248 return {
@@ -345,9 +345,9 @@ class Result<RecordShape extends Dict = Dict> implements Promise<QueryResult<Rec
345345 * @param {function(error: {message:string, code:string}) } onRejected - function to be called upon errors.
346346 * @return {Promise } promise.
347347 */
348- then < TResult1 = QueryResult < RecordShape > , TResult2 = never > (
348+ then < TResult1 = QueryResult < R > , TResult2 = never > (
349349 onFulfilled ?:
350- | ( ( value : QueryResult < RecordShape > ) => TResult1 | PromiseLike < TResult1 > )
350+ | ( ( value : QueryResult < R > ) => TResult1 | PromiseLike < TResult1 > )
351351 | null ,
352352 onRejected ?: ( ( reason : any ) => TResult2 | PromiseLike < TResult2 > ) | null
353353 ) : Promise < TResult1 | TResult2 > {
@@ -364,7 +364,7 @@ class Result<RecordShape extends Dict = Dict> implements Promise<QueryResult<Rec
364364 */
365365 catch < TResult = never > (
366366 onRejected ?: ( ( reason : any ) => TResult | PromiseLike < TResult > ) | null
367- ) : Promise < QueryResult < RecordShape > | TResult > {
367+ ) : Promise < QueryResult < R > | TResult > {
368368 return this . _getOrCreatePromise ( ) . catch ( onRejected )
369369 }
370370
@@ -376,7 +376,7 @@ class Result<RecordShape extends Dict = Dict> implements Promise<QueryResult<Rec
376376 * @return {Promise } promise.
377377 */
378378 [ Symbol . toStringTag ] : string
379- finally ( onfinally ?: ( ( ) => void ) | null ) : Promise < QueryResult < RecordShape > > {
379+ finally ( onfinally ?: ( ( ) => void ) | null ) : Promise < QueryResult < R > > {
380380 return this . _getOrCreatePromise ( ) . finally ( onfinally )
381381 }
382382
@@ -391,7 +391,7 @@ class Result<RecordShape extends Dict = Dict> implements Promise<QueryResult<Rec
391391 * @param {function(error: {message:string, code:string}) } observer.onError - handle errors.
392392 * @return {void }
393393 */
394- subscribe ( observer : ResultObserver < RecordShape > ) : void {
394+ subscribe ( observer : ResultObserver < R > ) : void {
395395 this . _subscribe ( observer )
396396 . catch ( ( ) => { } )
397397 }
0 commit comments