@sentzunhat/zacatl 0.0.10 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@sentzunhat/zacatl",
3
3
  "main": "src/index.ts",
4
4
  "module": "src/index.ts",
5
- "version": "0.0.10",
5
+ "version": "0.0.12",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/sentzunhat/zacatl.git"
@@ -56,7 +56,8 @@
56
56
  "test": "NODE_ENV=test ENV=test vitest run",
57
57
  "test:coverage": "npm run test -- --coverage",
58
58
  "type:check": "tsc -p ./tsconfig.json && tsc -p test/tsconfig.json",
59
- "lint": "DEBUG=eslint:cli-engine bun eslint ."
59
+ "lint": "DEBUG=eslint:cli-engine bun eslint .",
60
+ "publish:latest": "npm i && npm run test && npm run test:coverage && npm run type:check && npm run lint && npm run build && npm publish --access public --tag latest"
60
61
  },
61
62
  "devDependencies": {
62
63
  "@eslint/eslintrc": "^3.3.1",
@@ -3,10 +3,11 @@ import { FastifyReply } from "fastify";
3
3
  import { Request } from "./request";
4
4
 
5
5
  export type Handler<
6
- TBody,
7
- TQuerystring = Record<string, string>,
8
- TParams = void
6
+ TBody = void,
7
+ TQuerystring = void,
8
+ TParams = void,
9
+ THeaders = void
9
10
  > = (
10
- request: Request<TBody, TQuerystring, TParams>,
11
+ request: Request<TBody, TQuerystring, TParams, THeaders>,
11
12
  reply: FastifyReply
12
13
  ) => Promise<void>;
@@ -2,15 +2,16 @@ import { IncomingMessage } from "http";
2
2
  import { FastifySchema, FastifyRequest, RawServerBase } from "fastify";
3
3
 
4
4
  export type Request<
5
- TBody,
5
+ TBody = void,
6
6
  TQuerystring = void,
7
- TParams = void
7
+ TParams = void,
8
+ THeaders = void
8
9
  > = FastifyRequest<
9
10
  {
10
11
  Body: TBody;
11
12
  Querystring: TQuerystring;
12
13
  Params: TParams;
13
- Headers: Record<string, string>;
14
+ Headers: THeaders;
14
15
  },
15
16
  RawServerBase,
16
17
  IncomingMessage,
@@ -7,9 +7,9 @@ import { Request } from "../common/request";
7
7
 
8
8
  export type RouteSchema<
9
9
  TBody = void,
10
- TQuerystring = Record<string, string>,
11
- TParams = Record<string, string>,
12
- THeaders = Record<string, string>,
10
+ TQuerystring = void,
11
+ TParams = void,
12
+ THeaders = void,
13
13
  TResponse = void
14
14
  > = {
15
15
  body?: z.ZodSchema<TBody>;
@@ -29,10 +29,11 @@ export type HandlerOutput<TResponse> = TResponse;
29
29
 
30
30
  export abstract class AbstractRouteHandler<
31
31
  TBody = void,
32
- TQuerystring = Record<string, string>,
32
+ TQuerystring = void,
33
33
  TResponse = void,
34
- TParams = Record<string, string>
35
- > implements RouteHandler<TBody, TQuerystring, TParams>
34
+ TParams = void,
35
+ THeaders = void
36
+ > implements RouteHandler<TBody, TQuerystring, TParams, THeaders>
36
37
  {
37
38
  public url: string;
38
39
  public method: HTTPMethods;
@@ -45,12 +46,12 @@ export abstract class AbstractRouteHandler<
45
46
  }
46
47
 
47
48
  abstract handler(
48
- request: Request<TBody, TQuerystring, TParams>,
49
+ request: Request<TBody, TQuerystring, TParams, THeaders>,
49
50
  reply: FastifyReply
50
51
  ): Promise<HandlerOutput<TResponse>> | HandlerOutput<TResponse>;
51
52
 
52
53
  public async execute(
53
- request: Request<TBody, TQuerystring, TParams>,
54
+ request: Request<TBody, TQuerystring, TParams, THeaders>,
54
55
  reply: FastifyReply
55
56
  ): Promise<void> {
56
57
  const response = await this.handler(request, reply);
@@ -8,7 +8,7 @@ export type GetRouteHandlerConstructor = {
8
8
 
9
9
  export abstract class GetRouteHandler<
10
10
  TBody = void,
11
- TQuerystring = Record<string, string>,
11
+ TQuerystring = void,
12
12
  TResponse = void,
13
13
  TParams = void
14
14
  > extends AbstractRouteHandler<TBody, TQuerystring, TResponse, TParams> {
@@ -7,10 +7,10 @@ export type PostRouteHandlerConstructor = {
7
7
  };
8
8
 
9
9
  export abstract class PostRouteHandler<
10
- TBody = unknown,
11
- TResponse = unknown,
12
- TQuerystring = Record<string, string>,
13
- TParams = Record<string, string>
10
+ TBody = void,
11
+ TResponse = void,
12
+ TQuerystring = void,
13
+ TParams = void
14
14
  > extends AbstractRouteHandler<TBody, TQuerystring, TResponse, TParams> {
15
15
  constructor(args: PostRouteHandlerConstructor) {
16
16
  super({
@@ -4,11 +4,12 @@ import { Handler } from "../common/handler";
4
4
 
5
5
  export type RouteHandler<
6
6
  TBody = void,
7
- TQuerystring = Record<string, string>,
8
- TParams = void
7
+ TQuerystring = void,
8
+ TParams = void,
9
+ THeaders = void
9
10
  > = {
10
11
  url: string;
11
12
  method: HTTPMethods;
12
13
  schema: FastifySchema;
13
- execute: Handler<TBody, TQuerystring, TParams>;
14
+ execute: Handler<TBody, TQuerystring, TParams, THeaders>;
14
15
  };
@@ -18,12 +18,7 @@ class DummyHookHandler implements HookHandler {
18
18
 
19
19
  import { FastifyReply } from "fastify";
20
20
 
21
- class DummyRouteHandler extends AbstractRouteHandler<
22
- void, // Body
23
- Record<string, string>, // Querystring
24
- void, // Params
25
- void // Response
26
- > {
21
+ class DummyRouteHandler extends AbstractRouteHandler {
27
22
  constructor() {
28
23
  super({
29
24
  url: "/",
@@ -32,14 +27,7 @@ class DummyRouteHandler extends AbstractRouteHandler<
32
27
  });
33
28
  }
34
29
 
35
- handler(
36
- _: Request<
37
- void, // Body
38
- Record<string, string>, // Querystring
39
- void // Params
40
- >,
41
- __: FastifyReply
42
- ): void | Promise<void> {
30
+ handler(_: Request, __: FastifyReply): void | Promise<void> {
43
31
  // Dummy implementation
44
32
  return;
45
33
  }