Skip to content

Commit 13477d8

Browse files
committed
fix(request): allow ZodTypeAny to account for effects
1 parent a7f421e commit 13477d8

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

src/request.ts

+24-24
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ export const relationship = <TData extends RelationshipDataSchema>(
163163

164164
type ParseDataRequestOptions<
165165
TType extends string,
166-
TAttributesSchema extends z.SomeZodObject | undefined,
167-
TRelationshipsSchema extends z.SomeZodObject | undefined,
166+
TAttributesSchema extends z.ZodTypeAny | undefined,
167+
TRelationshipsSchema extends z.ZodTypeAny | undefined,
168168
> = {
169169
type: TType;
170170
attributesSchema?: TAttributesSchema;
@@ -174,13 +174,13 @@ type ParseDataRequestOptions<
174174
type ParseDataRequestResult<
175175
TIdSchema extends z.ZodType<unknown>,
176176
TType extends string,
177-
TAttributesSchema extends z.SomeZodObject | undefined,
178-
TRelationshipsSchema extends z.SomeZodObject | undefined,
177+
TAttributesSchema extends z.ZodTypeAny | undefined,
178+
TRelationshipsSchema extends z.ZodTypeAny | undefined,
179179
> = {
180180
id: z.output<TIdSchema>;
181181
type: TType;
182-
attributes: TAttributesSchema extends z.SomeZodObject ? z.output<TAttributesSchema> : undefined;
183-
relationships: TRelationshipsSchema extends z.SomeZodObject
182+
attributes: TAttributesSchema extends z.ZodTypeAny ? z.output<TAttributesSchema> : undefined;
183+
relationships: TRelationshipsSchema extends z.ZodTypeAny
184184
? z.output<TRelationshipsSchema>
185185
: undefined;
186186
};
@@ -231,8 +231,8 @@ const validateContentType = (context: Context): void => {
231231
const parseDataRequest = <
232232
TIdSchema extends z.ZodType<unknown>,
233233
TType extends string,
234-
TAttributesSchema extends z.SomeZodObject | undefined,
235-
TRelationshipsSchema extends z.SomeZodObject | undefined,
234+
TAttributesSchema extends z.ZodTypeAny | undefined,
235+
TRelationshipsSchema extends z.ZodTypeAny | undefined,
236236
>(
237237
idSchema: TIdSchema,
238238
koaContext: Context,
@@ -246,10 +246,10 @@ const parseDataRequest = <
246246
id: idSchema as z.ZodType<unknown>,
247247
type: fixedTypeSchema(options.type) as z.ZodType<unknown>,
248248
attributes: options.attributesSchema
249-
? (options.attributesSchema as z.SomeZodObject)
249+
? (options.attributesSchema as z.ZodTypeAny)
250250
: z.undefined(),
251251
relationships: options.relationshipsSchema
252-
? (options.relationshipsSchema as z.SomeZodObject)
252+
? (options.relationshipsSchema as z.ZodTypeAny)
253253
: z.undefined(),
254254
}),
255255
})
@@ -262,26 +262,26 @@ const parseDataRequest = <
262262
return {
263263
id: parseResult.data.data.id,
264264
type: parseResult.data.data.type as TType,
265-
attributes: parseResult.data.data.attributes as TAttributesSchema extends z.SomeZodObject
265+
attributes: parseResult.data.data.attributes as TAttributesSchema extends z.ZodTypeAny
266266
? z.output<TAttributesSchema>
267267
: undefined,
268268
relationships: parseResult.data.data
269-
.relationships as TRelationshipsSchema extends z.SomeZodObject
269+
.relationships as TRelationshipsSchema extends z.ZodTypeAny
270270
? z.output<TRelationshipsSchema>
271271
: undefined,
272272
};
273273
};
274274

275275
export type ParseCreateRequestOptions<
276276
TType extends string,
277-
TAttributesSchema extends z.SomeZodObject | undefined,
278-
TRelationshipsSchema extends z.SomeZodObject | undefined,
277+
TAttributesSchema extends z.ZodTypeAny | undefined,
278+
TRelationshipsSchema extends z.ZodTypeAny | undefined,
279279
> = ParseDataRequestOptions<TType, TAttributesSchema, TRelationshipsSchema>;
280280

281281
export type ParseCreateRequestResult<
282282
TType extends string,
283-
TAttributesSchema extends z.SomeZodObject | undefined,
284-
TRelationshipsSchema extends z.SomeZodObject | undefined,
283+
TAttributesSchema extends z.ZodTypeAny | undefined,
284+
TRelationshipsSchema extends z.ZodTypeAny | undefined,
285285
> = ParseDataRequestResult<
286286
z.ZodOptional<z.ZodString>,
287287
TType,
@@ -293,8 +293,8 @@ export type ParseCreateRequestResult<
293293

294294
export const parseCreateRequest = <
295295
TType extends string,
296-
TAttributesSchema extends z.SomeZodObject | undefined,
297-
TRelationshipsSchema extends z.SomeZodObject | undefined,
296+
TAttributesSchema extends z.ZodTypeAny | undefined,
297+
TRelationshipsSchema extends z.ZodTypeAny | undefined,
298298
>(
299299
koaContext: Context,
300300
options: ParseCreateRequestOptions<TType, TAttributesSchema, TRelationshipsSchema>,
@@ -304,24 +304,24 @@ export const parseCreateRequest = <
304304

305305
export type ParseUpdateRequestOptions<
306306
TType extends string,
307-
TAttributesSchema extends z.SomeZodObject | undefined,
308-
TRelationshipsSchema extends z.SomeZodObject | undefined,
307+
TAttributesSchema extends z.ZodTypeAny | undefined,
308+
TRelationshipsSchema extends z.ZodTypeAny | undefined,
309309
> = ParseDataRequestOptions<TType, TAttributesSchema, TRelationshipsSchema>;
310310

311311
export type ParseUpdateRequestResult<
312312
TId extends string,
313313
TType extends string,
314-
TAttributesSchema extends z.SomeZodObject | undefined,
315-
TRelationshipsSchema extends z.SomeZodObject | undefined,
314+
TAttributesSchema extends z.ZodTypeAny | undefined,
315+
TRelationshipsSchema extends z.ZodTypeAny | undefined,
316316
> = ParseDataRequestResult<z.ZodType<TId>, TType, TAttributesSchema, TRelationshipsSchema> & {
317317
id: TId;
318318
};
319319

320320
export const parseUpdateRequest = <
321321
TId extends string,
322322
TType extends string,
323-
TAttributesSchema extends z.SomeZodObject | undefined,
324-
TRelationshipsSchema extends z.SomeZodObject | undefined,
323+
TAttributesSchema extends z.ZodTypeAny | undefined,
324+
TRelationshipsSchema extends z.ZodTypeAny | undefined,
325325
>(
326326
id: TId,
327327
koaContext: Context,

0 commit comments

Comments
 (0)