@@ -19,24 +19,29 @@ const logger = createLogger('RequestsRegistry');
19
19
/**
20
20
* Creates request record schema
21
21
*
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
24
26
* @returns {z.ZodType } Request record schema
25
27
*/
26
28
export const createRequestRecordSchema = <
27
- TQuery extends z . ZodTypeAny ,
28
- TOfferOptions extends z . ZodTypeAny ,
29
+ CustomRequestQuery extends GenericQuery ,
30
+ CustomOfferOptions extends GenericOfferOptions ,
29
31
> (
30
- querySchema : TQuery ,
31
- offerOptionsSchema : TOfferOptions ,
32
+ querySchema : z . ZodType < CustomRequestQuery > ,
33
+ offerOptionsSchema : z . ZodType < CustomOfferOptions > ,
32
34
) =>
33
35
z
34
36
. object ( {
35
37
/** Raw request data */
36
- data : createRequestDataSchema < TQuery > ( querySchema ) ,
38
+ data : createRequestDataSchema < CustomRequestQuery > ( querySchema ) ,
37
39
/** Offers associated with a request*/
38
40
offers : z . array (
39
- createOfferDataSchema < TQuery , TOfferOptions > ( querySchema , offerOptionsSchema ) ,
41
+ createOfferDataSchema < CustomRequestQuery , CustomOfferOptions > (
42
+ querySchema ,
43
+ offerOptionsSchema ,
44
+ ) ,
40
45
) ,
41
46
/** Request cancelation flag */
42
47
cancelled : z . boolean ( ) . default ( false ) ,
@@ -84,11 +89,7 @@ export type RequestsRegistryOptions<
84
89
export type RequestRecord <
85
90
CustomRequestQuery extends GenericQuery ,
86
91
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 > > > ;
92
93
93
94
/**
94
95
* Request manager events interface
@@ -260,10 +261,10 @@ export class RequestsRegistry<
260
261
261
262
for ( let requestRecord of rawRecords ) {
262
263
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 ) ;
267
268
268
269
// `record.data` marked as optional because of Zod generics issue
269
270
this . requests . set (
@@ -379,13 +380,11 @@ export class RequestsRegistry<
379
380
throw new Error ( 'Client not connected to the coordination server yet' ) ;
380
381
}
381
382
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 ( {
389
388
data : request ,
390
389
offers : [ ] ,
391
390
} ) ;
@@ -452,7 +451,7 @@ export class RequestsRegistry<
452
451
453
452
this . requests . set (
454
453
id ,
455
- createRequestRecordSchema < z . ZodType < CustomRequestQuery > , z . ZodType < CustomOfferOptions > > (
454
+ createRequestRecordSchema < CustomRequestQuery , CustomOfferOptions > (
456
455
this . client . querySchema ,
457
456
this . client . offerOptionsSchema ,
458
457
) . parse ( record ) ,
@@ -512,7 +511,7 @@ export class RequestsRegistry<
512
511
* @memberof RequestsRegistry
513
512
*/
514
513
addOffer ( offer : OfferData < CustomRequestQuery , CustomOfferOptions > ) {
515
- offer = createOfferDataSchema < z . ZodType < CustomRequestQuery > , z . ZodType < CustomOfferOptions > > (
514
+ offer = createOfferDataSchema < CustomRequestQuery , CustomOfferOptions > (
516
515
this . client . querySchema ,
517
516
this . client . offerOptionsSchema ,
518
517
) . parse ( offer ) ;
@@ -529,7 +528,7 @@ export class RequestsRegistry<
529
528
530
529
this . requests . set (
531
530
requestId ,
532
- createRequestRecordSchema < z . ZodType < CustomRequestQuery > , z . ZodType < CustomOfferOptions > > (
531
+ createRequestRecordSchema < CustomRequestQuery , CustomOfferOptions > (
533
532
this . client . querySchema ,
534
533
this . client . offerOptionsSchema ,
535
534
) . parse ( {
0 commit comments