Skip to content

Commit

Permalink
[up] upgrade integration with [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
leomerida15 committed Oct 15, 2023
1 parent 09b20b2 commit 0a2a3b0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 63 deletions.
50 changes: 25 additions & 25 deletions src/resolvers/yup/ValidAndFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,37 +38,37 @@ export default class ValidAndFormat<
return this.Schemas.context.validateSync(this.NativeContext);
}

private getQueryWhoNoHasSchema(
queriesArray: Array<keyof InferType<Q>>,
): Partial<InferType<Q>> {
//
const resQueries: any = {};
private getQueryWhoNoHasSchema() {
return (queriesArray: Array<keyof InferType<Q>>): Partial<InferType<Q>> => {
//
const resQueries: any = {};

const symbolsReq = Object.getOwnPropertySymbols(this.nativeRequest);
const symbolsReq = Object.getOwnPropertySymbols(this.nativeRequest);

const UrlNative = symbolsReq
.filter((S) => {
//@ts-ignore
const item = this.nativeRequest[S];
const UrlNative = symbolsReq
.filter((S) => {
//@ts-ignore
const item = this.nativeRequest[S];

return item?.url;
})
.map<URL>((S) => {
//@ts-ignore
const item = this.nativeRequest[S];
return item?.url;
})
.map<URL>((S) => {
//@ts-ignore
const item = this.nativeRequest[S];

return item?.url;
})[0];
return item?.url;
})[0];

const validUrlNative = Object.keys(this.nativeRequest).includes("url");
const validUrlNative = Object.keys(this.nativeRequest).includes("url");

const url = validUrlNative ? new URL(this.nativeRequest.url) : UrlNative;
const url = validUrlNative ? new URL(this.nativeRequest.url) : UrlNative;

queriesArray.map((q) => {
resQueries[q] = url.searchParams.get(String(q));
});
queriesArray.map((q) => {
resQueries[q] = url.searchParams.get(String(q));
});

return resQueries;
return resQueries;
};
}

private createGetQueryWhoHasSchema(queryFormat: InferType<Q>) {
Expand All @@ -86,11 +86,11 @@ export default class ValidAndFormat<
}

query() {
if (!this.Schemas?.query) return this.getQueryWhoNoHasSchema;
if (!this.Schemas?.query) return this.getQueryWhoNoHasSchema();

const keys = Object.keys(this.Schemas.query.fields);

const query = this.getQueryWhoNoHasSchema(keys);
const query = this.getQueryWhoNoHasSchema()(keys);

const queryFormat = this.Schemas.query.validateSync(query) as InferType<Q>;

Expand Down
74 changes: 37 additions & 37 deletions src/resolvers/zod/ValidAndFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,49 +26,37 @@ export default class ValidAndFormat<
this.nativeRequest = nativeRequest;
}

headers(): TypeOf<H> | ReadonlyHeaders {
if (!this.Schemas?.headers) return Headers();

return this.Schemas.headers.parse(Headers());
}

context(): TypeOf<C> {
if (!this.Schemas?.context) return this.NativeContext;

return this.Schemas.context.parse(this.NativeContext);
}

private getQueryWhoNoHasSchema(
queriesArray: Array<keyof TypeOf<Q>>,
): Partial<TypeOf<Q>> {
//
const resQueries: any = {};
private getQueryWhoNoHasSchema() {
return (queriesArray: Array<keyof TypeOf<Q>>): Partial<TypeOf<Q>> => {
//
const resQueries: any = {};

const symbolsReq = Object.getOwnPropertySymbols(this.nativeRequest);
const symbolsReq = Object.getOwnPropertySymbols(this.nativeRequest);

const UrlNative = symbolsReq
.filter((S) => {
//@ts-ignore
const item = this.nativeRequest[S];
const UrlNative = symbolsReq
.filter((S) => {
//@ts-ignore
const item = this.nativeRequest[S];

return item?.url;
})
.map<URL>((S) => {
//@ts-ignore
const item = this.nativeRequest[S];
return item?.url;
})
.map<URL>((S) => {
//@ts-ignore
const item = this.nativeRequest[S];

return item?.url;
})[0];
return item?.url;
})[0];

const validUrlNative = Object.keys(this.nativeRequest).includes("url");
const validUrlNative = Object.keys(this.nativeRequest).includes("url");

const url = validUrlNative ? new URL(this.nativeRequest.url) : UrlNative;
const url = validUrlNative ? new URL(this.nativeRequest.url) : UrlNative;

queriesArray.map((q) => {
resQueries[q] = url.searchParams.get(String(q));
});
queriesArray.map((q) => {
resQueries[q] = url.searchParams.get(String(q));
});

return resQueries;
return resQueries;
};
}

private createGetQueryWhoHasSchema(queryFormat: TypeOf<Q>) {
Expand All @@ -85,12 +73,24 @@ export default class ValidAndFormat<
};
}

headers(): TypeOf<H> | ReadonlyHeaders {
if (!this.Schemas?.headers) return Headers();

return this.Schemas.headers.parse(Headers());
}

context(): TypeOf<C> {
if (!this.Schemas?.context) return this.NativeContext;

return this.Schemas.context.parse(this.NativeContext);
}

query() {
if (!this.Schemas?.query) return this.getQueryWhoNoHasSchema;
if (!this.Schemas?.query) return this.getQueryWhoNoHasSchema();

const keys = Object.keys(this.Schemas.query.shape);

const query = this.getQueryWhoNoHasSchema(keys);
const query = this.getQueryWhoNoHasSchema()(keys);

const queryFormat = this.Schemas.query.parse(query) as TypeOf<Q>;

Expand Down
3 changes: 2 additions & 1 deletion src/resolvers/zod/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export type ZodResponseFactoryKeyJsonType = ReturnType<

export type ZodHandlerReturn =
| void
| Response
| ReturnType<ReturnType<ZodResponseFactoryType>["json"]>
| ReturnType<ReturnType<ZodResponseFactoryType>["redirect"]>
| ReturnType<ReturnType<ZodResponseFactoryType>["rewrite"]>
Expand Down Expand Up @@ -73,7 +74,7 @@ export interface IZodRouteParams<
req: IZodRequestFactoryResp<B, C, Q>,
reply: ReturnType<typeof responseFactory>,
context: TypeOf<C>,
) => ZodHandlerReturn | Promise<ZodHandlerReturn>;
) => ZodHandlerReturn;
}

export type ZodRouteType = typeof zodRoute;

0 comments on commit 0a2a3b0

Please sign in to comment.