@@ -19,24 +19,29 @@ const logger = createLogger('RequestsRegistry');
1919/**
2020 * Creates request record schema
2121 *
22- * @param {z.ZodType } querySchema Custom request query schema
23- * @param {z.ZodType } offerOptionsSchema
22+ * @template {CustomRequestQuery}
23+ * @template {CustomOfferOptions}
24+ * @param {z.ZodType<CustomRequestQuery> } querySchema Custom request query schema
25+ * @param {z.ZodType<CustomOfferOptions> } offerOptionsSchema
2426 * @returns {z.ZodType } Request record schema
2527 */
2628export const createRequestRecordSchema = <
27- TQuery extends z . ZodTypeAny ,
28- TOfferOptions extends z . ZodTypeAny ,
29+ CustomRequestQuery extends GenericQuery ,
30+ CustomOfferOptions extends GenericOfferOptions ,
2931> (
30- querySchema : TQuery ,
31- offerOptionsSchema : TOfferOptions ,
32+ querySchema : z . ZodType < CustomRequestQuery > ,
33+ offerOptionsSchema : z . ZodType < CustomOfferOptions > ,
3234) =>
3335 z
3436 . object ( {
3537 /** Raw request data */
36- data : createRequestDataSchema < TQuery > ( querySchema ) ,
38+ data : createRequestDataSchema < CustomRequestQuery > ( querySchema ) ,
3739 /** Offers associated with a request*/
3840 offers : z . array (
39- createOfferDataSchema < TQuery , TOfferOptions > ( querySchema , offerOptionsSchema ) ,
41+ createOfferDataSchema < CustomRequestQuery , CustomOfferOptions > (
42+ querySchema ,
43+ offerOptionsSchema ,
44+ ) ,
4045 ) ,
4146 /** Request cancelation flag */
4247 cancelled : z . boolean ( ) . default ( false ) ,
@@ -84,11 +89,7 @@ export type RequestsRegistryOptions<
8489export type RequestRecord <
8590 CustomRequestQuery extends GenericQuery ,
8691 CustomOfferOptions extends GenericOfferOptions ,
87- > = z . infer <
88- ReturnType <
89- typeof createRequestRecordSchema < z . ZodType < CustomRequestQuery > , z . ZodType < CustomOfferOptions > >
90- >
91- > ;
92+ > = z . infer < ReturnType < typeof createRequestRecordSchema < CustomRequestQuery , CustomOfferOptions > > > ;
9293
9394/**
9495 * Request manager events interface
@@ -260,10 +261,10 @@ export class RequestsRegistry<
260261
261262 for ( let requestRecord of rawRecords ) {
262263 try {
263- requestRecord = createRequestRecordSchema <
264- z . ZodType < CustomRequestQuery > ,
265- z . ZodType < CustomOfferOptions >
266- > ( this . client . querySchema , this . client . offerOptionsSchema ) . parse ( requestRecord ) ;
264+ requestRecord = createRequestRecordSchema < CustomRequestQuery , CustomOfferOptions > (
265+ this . client . querySchema ,
266+ this . client . offerOptionsSchema ,
267+ ) . parse ( requestRecord ) ;
267268
268269 // `record.data` marked as optional because of Zod generics issue
269270 this . requests . set (
@@ -379,13 +380,11 @@ export class RequestsRegistry<
379380 throw new Error ( 'Client not connected to the coordination server yet' ) ;
380381 }
381382
382- request = createRequestDataSchema < z . ZodType < CustomRequestQuery > > ( this . client . querySchema ) . parse (
383- request ,
384- ) ;
385- const requestRecord = createRequestRecordSchema <
386- z . ZodType < CustomRequestQuery > ,
387- z . ZodType < CustomOfferOptions >
388- > ( this . client . querySchema , this . client . offerOptionsSchema ) . parse ( {
383+ request = createRequestDataSchema < CustomRequestQuery > ( this . client . querySchema ) . parse ( request ) ;
384+ const requestRecord = createRequestRecordSchema < CustomRequestQuery , CustomOfferOptions > (
385+ this . client . querySchema ,
386+ this . client . offerOptionsSchema ,
387+ ) . parse ( {
389388 data : request ,
390389 offers : [ ] ,
391390 } ) ;
@@ -452,7 +451,7 @@ export class RequestsRegistry<
452451
453452 this . requests . set (
454453 id ,
455- createRequestRecordSchema < z . ZodType < CustomRequestQuery > , z . ZodType < CustomOfferOptions > > (
454+ createRequestRecordSchema < CustomRequestQuery , CustomOfferOptions > (
456455 this . client . querySchema ,
457456 this . client . offerOptionsSchema ,
458457 ) . parse ( record ) ,
@@ -512,7 +511,7 @@ export class RequestsRegistry<
512511 * @memberof RequestsRegistry
513512 */
514513 addOffer ( offer : OfferData < CustomRequestQuery , CustomOfferOptions > ) {
515- offer = createOfferDataSchema < z . ZodType < CustomRequestQuery > , z . ZodType < CustomOfferOptions > > (
514+ offer = createOfferDataSchema < CustomRequestQuery , CustomOfferOptions > (
516515 this . client . querySchema ,
517516 this . client . offerOptionsSchema ,
518517 ) . parse ( offer ) ;
@@ -529,7 +528,7 @@ export class RequestsRegistry<
529528
530529 this . requests . set (
531530 requestId ,
532- createRequestRecordSchema < z . ZodType < CustomRequestQuery > , z . ZodType < CustomOfferOptions > > (
531+ createRequestRecordSchema < CustomRequestQuery , CustomOfferOptions > (
533532 this . client . querySchema ,
534533 this . client . offerOptionsSchema ,
535534 ) . parse ( {
0 commit comments