@@ -36,10 +36,13 @@ export type GenericQuery = z.infer<typeof GenericQuerySchema>;
36
36
/**
37
37
* Creates request data structure schema
38
38
*
39
- * @param {z.ZodType } querySchema
39
+ * @template {CustomRequestQuery}
40
+ * @param {z.ZodType<CustomRequestQuery> } querySchema
40
41
* @returns {z.ZodType }
41
42
*/
42
- export const createRequestDataSchema = < T extends z . ZodTypeAny > ( querySchema : T ) =>
43
+ export const createRequestDataSchema = < CustomRequestQuery extends GenericQuery > (
44
+ querySchema : z . ZodType < CustomRequestQuery > ,
45
+ ) =>
43
46
GenericMessageSchema . extend ( {
44
47
/** Request topic */
45
48
topic : z . string ( ) ,
@@ -51,16 +54,19 @@ export const createRequestDataSchema = <T extends z.ZodTypeAny>(querySchema: T)
51
54
* Request data type
52
55
*/
53
56
export type RequestData < CustomRequestQuery extends GenericQuery > = z . infer <
54
- ReturnType < typeof createRequestDataSchema < z . ZodType < CustomRequestQuery > > >
57
+ ReturnType < typeof createRequestDataSchema < CustomRequestQuery > >
55
58
> ;
56
59
57
60
/**
58
61
* Creates schema for buildRequest method options
59
62
*
60
- * @param {z.ZodType } querySchema
63
+ * @template {CustomRequestQuery}
64
+ * @param {z.ZodType<CustomRequestQuery> } querySchema
61
65
* @returns {z.ZodType }
62
66
*/
63
- export const createBuildRequestOptions = < T extends z . ZodTypeAny > ( querySchema : T ) =>
67
+ export const createBuildRequestOptions = < CustomRequestQuery extends GenericQuery > (
68
+ querySchema : z . ZodType < CustomRequestQuery > ,
69
+ ) =>
64
70
z
65
71
. object ( {
66
72
/** Expiration time */
@@ -82,23 +88,25 @@ export const createBuildRequestOptions = <T extends z.ZodTypeAny>(querySchema: T
82
88
* buildRequest method options type
83
89
*/
84
90
export type BuildRequestOptions < CustomRequestQuery extends GenericQuery > = z . infer <
85
- ReturnType < typeof createBuildRequestOptions < z . ZodType < CustomRequestQuery > > >
91
+ ReturnType < typeof createBuildRequestOptions < CustomRequestQuery > >
86
92
> ;
87
93
88
94
/**
89
95
* Builds a request
90
96
*
91
- * @template CustomRequestQuery
97
+ * @template { CustomRequestQuery}
92
98
* @param {BuildRequestOptions<CustomRequestQuery> } requestOptions
93
99
* @returns
94
100
*/
95
101
export const buildRequest = async < CustomRequestQuery extends GenericQuery > (
96
102
requestOptions : BuildRequestOptions < CustomRequestQuery > ,
97
103
) => {
98
- const { expire, nonce, topic, query, querySchema, idOverride } = createBuildRequestOptions <
99
- typeof requestOptions . querySchema
100
- > ( requestOptions . querySchema ) . parse ( requestOptions ) ;
101
- const request = createRequestDataSchema < typeof querySchema > ( querySchema ) ;
104
+ const { expire, nonce, topic, query, idOverride } = createBuildRequestOptions < CustomRequestQuery > (
105
+ requestOptions . querySchema as z . ZodType < CustomRequestQuery > ,
106
+ ) . parse ( requestOptions ) ;
107
+ const request = createRequestDataSchema < CustomRequestQuery > (
108
+ requestOptions . querySchema as z . ZodType < CustomRequestQuery > ,
109
+ ) ;
102
110
return ( await request . parseAsync ( {
103
111
id : idOverride ?? uuid4 ( ) ,
104
112
expire : typeof expire === 'number' ? parseSeconds ( expire ) : nowSec ( ) + parseSeconds ( expire ) ,
@@ -178,21 +186,21 @@ export type GenericOfferOptions = z.infer<typeof GenericOfferOptionsSchema>;
178
186
/**
179
187
* Creates a final offer data schema
180
188
*
181
- * @template TQuery
182
- * @template TOfferOptions
183
- * @param {TQuery } querySchema
184
- * @param {TOfferOptions } offerOptionsSchema
189
+ * @template {CustomRequestQuery}
190
+ * @template {CustomOfferOptions}
191
+ * @param {z.ZodType<CustomRequestQuery> } querySchema
192
+ * @param {z.ZodType<CustomOfferOptions> } offerOptionsSchema
185
193
*/
186
194
export const createOfferDataSchema = <
187
- TQuery extends z . ZodTypeAny ,
188
- TOfferOptions extends z . ZodTypeAny ,
195
+ CustomRequestQuery extends GenericQuery ,
196
+ CustomOfferOptions extends GenericOfferOptions ,
189
197
> (
190
- querySchema : TQuery ,
191
- offerOptionsSchema : TOfferOptions ,
198
+ querySchema : z . ZodType < CustomRequestQuery > ,
199
+ offerOptionsSchema : z . ZodType < CustomOfferOptions > ,
192
200
) =>
193
201
GenericMessageSchema . extend ( {
194
202
/** Copy of request */
195
- request : createRequestDataSchema < TQuery > ( querySchema ) ,
203
+ request : createRequestDataSchema < CustomRequestQuery > ( querySchema ) ,
196
204
/** Offer options */
197
205
options : offerOptionsSchema ,
198
206
/** Payment options */
@@ -211,11 +219,7 @@ export const createOfferDataSchema = <
211
219
export type OfferData <
212
220
CustomRequestQuery extends GenericQuery ,
213
221
CustomOfferOptions extends GenericOfferOptions ,
214
- > = z . infer <
215
- ReturnType <
216
- typeof createOfferDataSchema < z . ZodType < CustomRequestQuery > , z . ZodType < CustomOfferOptions > >
217
- >
218
- > ;
222
+ > = z . infer < ReturnType < typeof createOfferDataSchema < CustomRequestQuery , CustomOfferOptions > > > ;
219
223
220
224
/**
221
225
* EIP-712 JSON schema types for offer
@@ -260,17 +264,17 @@ export const offerEip712Types: Record<string, Array<TypedDataField>> = {
260
264
/**
261
265
* Creates a schema for `buildOffer` method options
262
266
*
263
- * @template TQuery
264
- * @template TOfferOptions
265
- * @param {TQuery } querySchema
266
- * @param {TOfferOptions } offerOptionsSchema
267
+ * @template {CustomRequestQuery}
268
+ * @template {CustomOfferOptions}
269
+ * @param {z.ZodType<CustomRequestQuery> } querySchema
270
+ * @param {z.ZodType<CustomOfferOptions> } offerOptionsSchema
267
271
*/
268
272
export const createBuildOfferOptions = <
269
- TQuery extends z . ZodTypeAny ,
270
- TOfferOptions extends z . ZodTypeAny ,
273
+ CustomRequestQuery extends GenericQuery ,
274
+ CustomOfferOptions extends GenericOfferOptions ,
271
275
> (
272
- querySchema : TQuery ,
273
- offerOptionsSchema : TOfferOptions ,
276
+ querySchema : z . ZodType < CustomRequestQuery > ,
277
+ offerOptionsSchema : z . ZodType < CustomOfferOptions > ,
274
278
) =>
275
279
z
276
280
. object ( {
@@ -280,7 +284,7 @@ export const createBuildOfferOptions = <
280
284
optionsSchema : z . instanceof ( z . ZodType ) ,
281
285
supplierId : z . string ( ) ,
282
286
expire : z . string ( ) . or ( z . number ( ) ) ,
283
- request : createRequestDataSchema < TQuery > ( querySchema ) ,
287
+ request : createRequestDataSchema < CustomRequestQuery > ( querySchema ) ,
284
288
options : offerOptionsSchema ,
285
289
payment : z . array ( PaymentOptionSchema ) ,
286
290
cancel : z . array ( CancelOptionSchema ) ,
@@ -293,26 +297,17 @@ export const createBuildOfferOptions = <
293
297
294
298
/**
295
299
* Type for `buildOffer` method options
296
- *
297
- * @template TQuery
298
- * @template TOfferOptions
299
- * @param {TQuery } querySchema
300
- * @param {TOfferOptions } offerOptionsSchema
301
300
*/
302
301
export type BuildOfferOptions <
303
302
CustomRequestQuery extends GenericQuery ,
304
303
CustomOfferOptions extends GenericOfferOptions ,
305
- > = z . infer <
306
- ReturnType <
307
- typeof createBuildOfferOptions < z . ZodType < CustomRequestQuery > , z . ZodType < CustomOfferOptions > >
308
- >
309
- > ;
304
+ > = z . infer < ReturnType < typeof createBuildOfferOptions < CustomRequestQuery , CustomOfferOptions > > > ;
310
305
311
306
/**
312
307
* Builds an offer
313
308
*
314
- * @template CustomRequestQuery
315
- * @template CustomOfferOptions
309
+ * @template { CustomRequestQuery}
310
+ * @template { CustomOfferOptions}
316
311
* @param {BuildOfferOptions<CustomRequestQuery, CustomOfferOptions> } offerOptions
317
312
* @returns
318
313
*/
@@ -333,13 +328,11 @@ export const buildOffer = async <
333
328
transferable,
334
329
signer,
335
330
signatureOverride,
336
- querySchema,
337
- optionsSchema,
338
331
idOverride,
339
332
expire,
340
- } = createBuildOfferOptions < typeof offerOptions . querySchema , typeof offerOptions . optionsSchema > (
341
- offerOptions . querySchema ,
342
- offerOptions . optionsSchema ,
333
+ } = createBuildOfferOptions < CustomRequestQuery , CustomOfferOptions > (
334
+ offerOptions . querySchema as z . ZodType < CustomRequestQuery > ,
335
+ offerOptions . optionsSchema as z . ZodType < CustomOfferOptions > ,
343
336
) . parse ( offerOptions ) ;
344
337
345
338
const unsignedOfferPayload = UnsignedOfferPayloadSchema . parse ( {
@@ -372,10 +365,10 @@ export const buildOffer = async <
372
365
throw new Error ( 'Either signer or signatureOverride must be provided' ) ;
373
366
}
374
367
375
- const offerSchema = createOfferDataSchema <
376
- typeof offerOptions . querySchema ,
377
- typeof offerOptions . optionsSchema
378
- > ( querySchema , optionsSchema ) ;
368
+ const offerSchema = createOfferDataSchema < CustomRequestQuery , CustomOfferOptions > (
369
+ offerOptions . querySchema as z . ZodType < CustomRequestQuery > ,
370
+ offerOptions . optionsSchema as z . ZodType < CustomOfferOptions > ,
371
+ ) ;
379
372
380
373
return ( await offerSchema . parseAsync ( {
381
374
id : idOverride ?? uuid4 ( ) ,
@@ -393,8 +386,8 @@ export const buildOffer = async <
393
386
/**
394
387
* Verifies signed offer
395
388
*
396
- * @template CustomRequestQuery
397
- * @template CustomOfferOptions
389
+ * @template { CustomRequestQuery}
390
+ * @template { CustomOfferOptions}
398
391
* @param {ContractConfig } contract
399
392
* @param {string } supplierAddress
400
393
* @param {OfferData<CustomRequestQuery, CustomOfferOptions> } offer
0 commit comments