11/* eslint-disable no-throw-literal */
22/* eslint-disable @typescript-eslint/require-await */
33import type { Jsonify } from "type-fest" ;
4- import type { GadgetRecord , RecordShape } from "./GadgetRecord.js" ;
4+ import type { GadgetRecord , GadgetRecord_ , RecordShape } from "./GadgetRecord.js" ;
55import type { InternalModelManager } from "./InternalModelManager.js" ;
66import type { AnyModelManager } from "./ModelManager.js" ;
77import { GadgetClientError , GadgetOperationError } from "./support.js" ;
@@ -13,17 +13,20 @@ type PaginationConfig = {
1313} ;
1414
1515/** Represents a list of objects returned from the API. Facilitates iterating and paginating. */
16- export class GadgetRecordList < Shape extends RecordShape > extends Array < GadgetRecord < Shape > > {
16+ export class GadgetRecordList <
17+ Shape extends RecordShape ,
18+ RecordType extends GadgetRecord_ < Shape > = GadgetRecord < any >
19+ > extends Array < RecordType > {
1720 modelManager ! : AnyModelManager | InternalModelManager < Shape > ;
1821 pagination ! : PaginationConfig ;
1922
2023 /** Internal method used to create a list. Should not be used by applications. */
21- static boot < Shape extends RecordShape > (
24+ static boot < Shape extends RecordShape , RecordType extends GadgetRecord_ < Shape > = GadgetRecord < any > > (
2225 modelManager : AnyModelManager | InternalModelManager < Shape > ,
23- records : GadgetRecord < Shape > [ ] ,
26+ records : RecordType [ ] ,
2427 pagination : PaginationConfig
2528 ) {
26- const list = new GadgetRecordList < Shape > ( ) ;
29+ const list = new GadgetRecordList < Shape , RecordType > ( ) ;
2730 list . push ( ...records ) ;
2831 list . modelManager = modelManager ;
2932 list . pagination = pagination ;
@@ -71,7 +74,7 @@ export class GadgetRecordList<Shape extends RecordShape> extends Array<GadgetRec
7174 ...options ,
7275 after : this . pagination . pageInfo . endCursor ,
7376 first : first || last ,
74- } ) as Promise < GadgetRecordList < Shape > > ;
77+ } ) as Promise < GadgetRecordList < Shape , RecordType > > ;
7578 return await nextPage ;
7679 }
7780
@@ -86,7 +89,7 @@ export class GadgetRecordList<Shape extends RecordShape> extends Array<GadgetRec
8689 ...options ,
8790 before : this . pagination . pageInfo . startCursor ,
8891 last : last || first ,
89- } ) as Promise < GadgetRecordList < Shape > > ;
92+ } ) as Promise < GadgetRecordList < Shape , RecordType > > ;
9093 return await prevPage ;
9194 }
9295}
0 commit comments