transit-kit 0.2.0 → 0.2.1
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/dist/server/handlers/api/EndpointHandler.d.ts +1 -1
- package/dist/server/handlers/api/PathParameters.d.ts +1 -1
- package/dist/server/handlers/api/createApiHandler.d.ts +2 -3
- package/dist/server/handlers/api/createApiHandler.js +0 -1
- package/dist/server/handlers/api/createApiHandler.spec.d.ts +1 -0
- package/dist/server/handlers/api/createApiHandler.spec.js +31 -0
- package/dist/server/server.d.ts +4 -3
- package/dist/server/server.js +3 -3
- package/package.json +3 -1
- /package/dist/server/handlers/api/{HandlerFormDefinition.spec.d.ts → HandlerFromDefinition.spec.d.ts} +0 -0
- /package/dist/server/handlers/api/{HandlerFormDefinition.spec.js → HandlerFromDefinition.spec.js} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Request } from "express";
|
|
2
2
|
import { HttpStatusCodes } from "../../constants/HttpStatusCodes";
|
|
3
3
|
import { GenericResponse } from "./responses";
|
|
4
|
-
export type ApiEndpointHandler<PathParams extends Record<string, string>
|
|
4
|
+
export type ApiEndpointHandler<PathParams extends Record<string, string> = {}, RequestBody = unknown, Query = unknown, Responses extends GenericResponse = never> = (request: Request<PathParams, unknown, RequestBody, Query, Record<string, unknown>>) => Promise<Responses | {
|
|
5
5
|
code: (typeof HttpStatusCodes)["InternalServerError_500"];
|
|
6
6
|
}>;
|
|
@@ -3,10 +3,9 @@ import { HttpMethod } from "../../constants/HttpMethods";
|
|
|
3
3
|
import { ApiEndpointDefinition } from "./EndpointDefinition";
|
|
4
4
|
import { ApiEndpointHandler } from "./EndpointHandler";
|
|
5
5
|
import { HandlerForDefinition } from "./HandlerFromDefinition";
|
|
6
|
-
import { GenericResponseSchemaMap } from "./responses";
|
|
6
|
+
import { GenericResponse, GenericResponseSchemaMap } from "./responses";
|
|
7
7
|
export declare function createApiEndpointHandler<const ResponsesMap extends GenericResponseSchemaMap, const Path extends string, const Method extends HttpMethod, const RequestBody extends z.ZodType | undefined = undefined, const Query extends z.ZodType | undefined = undefined>(definition: ApiEndpointDefinition<Path, Method, RequestBody, Query, ResponsesMap>, handler: HandlerForDefinition<Path, RequestBody, Query, ResponsesMap>): {
|
|
8
|
-
type: string;
|
|
9
8
|
definition: ApiEndpointDefinition<Path, Method, RequestBody, Query, ResponsesMap>;
|
|
10
9
|
handler: HandlerForDefinition<Path, RequestBody, Query, ResponsesMap>;
|
|
11
10
|
};
|
|
12
|
-
export declare function buildApiEndpointHandler(handler: ApiEndpointHandler): import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
11
|
+
export declare function buildApiEndpointHandler(handler: ApiEndpointHandler<Record<string, string>, unknown, unknown, GenericResponse>): import("express").RequestHandler<import("express-serve-static-core").ParamsDictionary, any, any, import("qs").ParsedQs, Record<string, any>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, it } from "vitest";
|
|
2
|
+
import { createServer } from "../../server";
|
|
3
|
+
import { createApiEndpointHandler } from "./createApiHandler";
|
|
4
|
+
import testRequest from "supertest";
|
|
5
|
+
describe("createApiHandler", () => {
|
|
6
|
+
it("can create an API handler", () => {
|
|
7
|
+
const endpoint = createApiEndpointHandler({
|
|
8
|
+
meta: {
|
|
9
|
+
name: "",
|
|
10
|
+
description: "",
|
|
11
|
+
group: "",
|
|
12
|
+
},
|
|
13
|
+
method: "get",
|
|
14
|
+
path: "/test",
|
|
15
|
+
responseSchemas: {
|
|
16
|
+
200: {},
|
|
17
|
+
},
|
|
18
|
+
}, async () => {
|
|
19
|
+
return {
|
|
20
|
+
code: 200,
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
const server = createServer({
|
|
24
|
+
inDevMode: true,
|
|
25
|
+
port: 3000,
|
|
26
|
+
logger: false,
|
|
27
|
+
endpoints: [endpoint],
|
|
28
|
+
});
|
|
29
|
+
testRequest(server.expressApp).get("/test").expect(200);
|
|
30
|
+
});
|
|
31
|
+
});
|
package/dist/server/server.d.ts
CHANGED
|
@@ -3,20 +3,21 @@ import z from "zod";
|
|
|
3
3
|
import { HttpMethod } from "./constants/HttpMethods";
|
|
4
4
|
import { ApiEndpointDefinition } from "./handlers/api/EndpointDefinition";
|
|
5
5
|
import { ApiEndpointHandler } from "./handlers/api/EndpointHandler";
|
|
6
|
+
import { GenericResponse, GenericResponseSchemaMap } from "./handlers/api/responses";
|
|
6
7
|
import { Logger } from "./utils/logging";
|
|
7
8
|
export interface ServerConfig {
|
|
8
9
|
inDevMode: boolean;
|
|
9
10
|
port: number;
|
|
10
11
|
logger: Logger | boolean;
|
|
11
12
|
endpoints: Array<{
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
handler: ApiEndpointHandler<Record<string, string>, any, any, GenericResponse>;
|
|
14
|
+
definition: ApiEndpointDefinition<string, HttpMethod, z.ZodType | undefined, z.ZodType | undefined, GenericResponseSchemaMap>;
|
|
14
15
|
}>;
|
|
15
16
|
}
|
|
16
17
|
export interface Server {
|
|
17
18
|
expressApp: Application;
|
|
18
19
|
logger: Logger | boolean;
|
|
19
|
-
endpointDefinitions: ApiEndpointDefinition<string, HttpMethod, z.ZodType, z.ZodType,
|
|
20
|
+
endpointDefinitions: ApiEndpointDefinition<string, HttpMethod, z.ZodType | undefined, z.ZodType | undefined, GenericResponseSchemaMap>[];
|
|
20
21
|
start: () => void;
|
|
21
22
|
}
|
|
22
23
|
export declare function createServer(config: ServerConfig): Server;
|
package/dist/server/server.js
CHANGED
|
@@ -30,13 +30,13 @@ export function createServer(config) {
|
|
|
30
30
|
app.use(cookieParser());
|
|
31
31
|
app.use(buildRequestLogger(logger, inDevMode));
|
|
32
32
|
app.use(buildResponseLogger(logger, inDevMode));
|
|
33
|
-
endpoints.forEach(({
|
|
34
|
-
registerApiEndpoint(app,
|
|
33
|
+
endpoints.forEach(({ definition, handler }) => {
|
|
34
|
+
registerApiEndpoint(app, definition, handler);
|
|
35
35
|
});
|
|
36
36
|
return {
|
|
37
37
|
expressApp: app,
|
|
38
38
|
logger: logger,
|
|
39
|
-
endpointDefinitions: endpoints.map((e) => e.
|
|
39
|
+
endpointDefinitions: endpoints.map((e) => e.definition),
|
|
40
40
|
start: () => {
|
|
41
41
|
app.listen(port);
|
|
42
42
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "transit-kit",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "A declarative TypeScript framework for building type-safe Express.js APIs with automatic OpenAPI generation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"express",
|
|
@@ -42,6 +42,7 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/cookie-parser": "^1.4.9",
|
|
44
44
|
"@types/express": "^5.0.0",
|
|
45
|
+
"@types/supertest": "^6.0.3",
|
|
45
46
|
"@vitest/coverage-v8": "^4.0.15",
|
|
46
47
|
"@vitest/eslint-plugin": "^1.5.2",
|
|
47
48
|
"eslint": "^9.39.1",
|
|
@@ -49,6 +50,7 @@
|
|
|
49
50
|
"eslint-plugin-prettier": "^5.5.4",
|
|
50
51
|
"jiti": "^2.6.1",
|
|
51
52
|
"prettier": "^3.7.4",
|
|
53
|
+
"supertest": "^7.1.4",
|
|
52
54
|
"tslib": "2.8.1",
|
|
53
55
|
"typescript": "^5.9.3",
|
|
54
56
|
"typescript-eslint": "^8.49.0",
|
|
File without changes
|
/package/dist/server/handlers/api/{HandlerFormDefinition.spec.js → HandlerFromDefinition.spec.js}
RENAMED
|
File without changes
|