Skip to content

Commit

Permalink
feat: bump deps and expose logger and schema compiler generics from F…
Browse files Browse the repository at this point in the history
…astify
  • Loading branch information
Coobaha committed May 22, 2022
1 parent 10431d3 commit 80d209d
Show file tree
Hide file tree
Showing 6 changed files with 284 additions and 497 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- id: release-pr
uses: GoogleCloudPlatform/release-please-action@v2
uses: GoogleCloudPlatform/release-please-action@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: node
Expand Down
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,33 @@
"dependencies": {
"crypto-js": "^4.1.1",
"escape-string-regexp": "4.0.0",
"glob": "^7.2.0",
"glob": "^8.0.3",
"json-schema-merge-allof": "^0.8.1",
"json-schema-traverse": "^1.0.0",
"typescript-json-schema": "^0.52.0",
"yargs": "^17.3.1"
"typescript-json-schema": "^0.53.1",
"yargs": "^17.5.1"
},
"devDependencies": {
"@types/crypto-js": "^4.1.0",
"@types/crypto-js": "^4.1.1",
"@types/glob": "^7.2.0",
"@types/json-schema-merge-allof": "^0.6.1",
"@types/node": "^17.0.7",
"@types/prettier": "^2.4.2",
"@types/node": "^17.0.35",
"@types/prettier": "^2.6.1",
"@types/split2": "^3.2.1",
"@types/tap": "^15.0.5",
"@types/yargs": "^17.0.8",
"fastify": "^3.25.3",
"husky": "^7.0.4",
"lint-staged": "^12.1.5",
"pinst": "^2.1.6",
"prettier": "^2.5.1",
"@types/tap": "^15.0.7",
"@types/yargs": "^17.0.10",
"fastify": "^3.29.0",
"husky": "^8.0.1",
"lint-staged": "^12.4.1",
"pinst": "^3.0.0",
"prettier": "^2.6.2",
"split2": "^4.1.0",
"syncpack": "^6.2.0",
"tap": "^15.1.6",
"syncpack": "^7.2.1",
"tap": "^16.2.0",
"ts-node-dev": "^1.1.8",
"tsd": "^0.19.1",
"type-fest": "^2.8.0",
"typescript": "^4.5.4"
"tsd": "^0.20.0",
"type-fest": "^2.12.2",
"typescript": "^4.6.4"
},
"directories": {
"test": "test/",
Expand Down
44 changes: 29 additions & 15 deletions src/typed-fastify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ const addSchema = <
RawServer extends F.RawServerBase = F.RawServerDefault,
RawRequest extends F.RawRequestDefaultExpression<RawServer> = F.RawRequestDefaultExpression<RawServer>,
RawReply extends F.RawReplyDefaultExpression<RawServer> = F.RawReplyDefaultExpression<RawServer>,
Logger = F.FastifyLoggerInstance,
ContextConfig = F.ContextConfigDefault,
S = Service<ServiceSchema, RawServer, RawRequest, RawReply, ContextConfig>,
Logger extends F.FastifyLoggerInstance = F.FastifyLoggerInstance,
S = Service<ServiceSchema, RawServer, RawRequest, RawReply, Logger>,
>(
fastify: F.FastifyInstance<RawServer, RawRequest, RawReply, Logger>,
opts: {
Expand Down Expand Up @@ -273,6 +272,8 @@ interface Request<
Path extends keyof ServiceSchema['paths'],
RawServer extends F.RawServerBase = F.RawServerDefault,
RawRequest extends F.RawRequestDefaultExpression<RawServer> = F.RawRequestDefaultExpression<RawServer>,
ContextConfig = F.ContextConfigDefault,
Logger extends F.FastifyLoggerInstance = F.FastifyLoggerInstance,
OpRequest extends Router<Op> = Router<Op>,
PathParams = OpRequest['Params'] extends never
? ExtractParams<Path>
Expand All @@ -283,7 +284,9 @@ interface Request<
? Omit<Router<Op>, 'Params'> & { Params: PathParams }
: Omit<Router<Op>, 'Params'> & { Params: Id<PathParams & Router<Op>['Params']> },
RawServer,
RawRequest
RawRequest,
ContextConfig,
Logger
>,
'headers' | 'method' | 'routerMethod' | 'routerPath'
> {
Expand Down Expand Up @@ -319,6 +322,8 @@ type Handler<
RawRequest extends F.RawRequestDefaultExpression<RawServer> = F.RawRequestDefaultExpression<RawServer>,
RawReply extends F.RawReplyDefaultExpression<RawServer> = F.RawReplyDefaultExpression<RawServer>,
ContextConfig = F.ContextConfigDefault,
SchemaCompiler = F.FastifySchema,
Logger extends F.FastifyLoggerInstance = F.FastifyLoggerInstance,
InvalidParams = GetInvalidParamsValidation<Op, Path, ServiceSchema>,
ValidSchema = [Op['response'][keyof Op['response']]] extends [never]
? Invalid<`${Extract<Path, string>} - has no response, every path should have at least one response defined`>
Expand All @@ -328,9 +333,9 @@ type Handler<
Status extends keyof Op['response'] = keyof Op['response'],
> = ValidSchema extends true
? (
this: F.FastifyInstance<RawServer, RawRequest, RawReply, ContextConfig>,
request: Request<ServiceSchema, Op, Path, RawServer, RawRequest>,
reply: Reply<Op, never, never, never, Path, ServiceSchema, RawServer, RawRequest, RawReply, ContextConfig> & {
this: F.FastifyInstance<RawServer, RawRequest, RawReply, Logger>,
request: Request<ServiceSchema, Op, Path, RawServer, RawRequest, ContextConfig, Logger>,
reply: Reply<Op, never, never, never, Path, ServiceSchema, RawServer, RawRequest, RawReply, Logger> & {
readonly __unknownReply: unique symbol;
M: MP<Path>[0];
},
Expand All @@ -345,8 +350,10 @@ type HandlerObj<
RawRequest extends F.RawRequestDefaultExpression<RawServer> = F.RawRequestDefaultExpression<RawServer>,
RawReply extends F.RawReplyDefaultExpression<RawServer> = F.RawReplyDefaultExpression<RawServer>,
ContextConfig = F.ContextConfigDefault,
> = F.RouteShorthandOptions<RawServer, RawRequest, RawReply, Router<Op>> & {
handler: Handler<Op, Path, ServiceSchema, RawServer, RawRequest, RawReply, ContextConfig>;
SchemaCompiler = F.FastifySchema,
Logger extends F.FastifyLoggerInstance = F.FastifyLoggerInstance,
> = F.RouteShorthandOptions<RawServer, RawRequest, RawReply, Router<Op>, ContextConfig, SchemaCompiler, Logger> & {
handler: Handler<Op, Path, ServiceSchema, RawServer, RawRequest, RawReply, ContextConfig, Logger>;
};

export type Service<
Expand All @@ -355,10 +362,12 @@ export type Service<
RawRequest extends F.RawRequestDefaultExpression<RawServer> = F.RawRequestDefaultExpression<RawServer>,
RawReply extends F.RawReplyDefaultExpression<RawServer> = F.RawReplyDefaultExpression<RawServer>,
ContextConfig = F.ContextConfigDefault,
SchemaCompiler = F.FastifySchema,
Logger extends F.FastifyLoggerInstance = F.FastifyLoggerInstance,
> = {
[P in keyof S['paths']]:
| Handler<S['paths'][P], P, S, RawServer, RawRequest, RawReply, ContextConfig>
| HandlerObj<S['paths'][P], P, S, RawServer, RawRequest, RawReply, ContextConfig>;
| Handler<S['paths'][P], P, S, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, Logger>
| HandlerObj<S['paths'][P], P, S, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, Logger>;
};

export type RequestHandler<
Expand All @@ -368,7 +377,9 @@ export type RequestHandler<
RawRequest extends F.RawRequestDefaultExpression<RawServer> = F.RawRequestDefaultExpression<RawServer>,
RawReply extends F.RawReplyDefaultExpression<RawServer> = F.RawReplyDefaultExpression<RawServer>,
ContextConfig = F.ContextConfigDefault,
S = Service<ServiceSchema, RawServer, RawRequest, RawReply, ContextConfig>,
SchemaCompiler = F.FastifySchema,
Logger extends F.FastifyLoggerInstance = F.FastifyLoggerInstance,
S = Service<ServiceSchema, RawServer, RawRequest, RawReply, Logger>,
Paths = ServiceSchema['paths'],
OpHandler = {
[Path in HandlerPaths]: Handler<
Expand All @@ -378,7 +389,8 @@ export type RequestHandler<
RawServer,
RawRequest,
RawReply,
ContextConfig
ContextConfig,
Logger
>;
}[HandlerPaths],
OpHandlerObj = {
Expand All @@ -389,14 +401,16 @@ export type RequestHandler<
RawServer,
RawRequest,
RawReply,
ContextConfig
ContextConfig,
SchemaCompiler,
Logger
>;
}[HandlerPaths],
> = OpHandler extends (...args: any) => any
? {
Request: Parameters<OpHandler>[0];
AsFastifyRequest: Parameters<OpHandler>[0] extends F.FastifyRequest<any, any, any>
? F.FastifyRequest<Router<Paths[keyof Paths]>, RawServer, RawRequest>
? F.FastifyRequest<Router<Paths[keyof Paths]>, RawServer, RawRequest, ContextConfig, Logger>
: never;
Reply: Parameters<OpHandler>[1];
Return: AsReply | Promise<AsReply>;
Expand Down
7 changes: 6 additions & 1 deletion tap-snapshots/test/integration.test.ts.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,12 @@ Object {
`

exports[`test/integration.test.ts TAP response is validated > error logs 1`] = `
Error: "name" is required!
Error: "name" is required! {
"serialization": Object {
"method": "GET",
"url": "/",
},
}
`

exports[`test/integration.test.ts TAP response is validated > invalid response 1`] = `
Expand Down
2 changes: 1 addition & 1 deletion test/test_schema.gen.json
Original file line number Diff line number Diff line change
Expand Up @@ -257,5 +257,5 @@
}
}
},
"$hash": "c0e0481a3e03369a96f41b124dd2d9ad3fa1efd144dd9bf45a4c4fac7a15820b__v0.5.0"
"$hash": "c0e0481a3e03369a96f41b124dd2d9ad3fa1efd144dd9bf45a4c4fac7a15820b__v0.6.0"
}
Loading

0 comments on commit 80d209d

Please sign in to comment.