express-endpoints-collection 1.0.4 → 1.0.6
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/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -39
- package/dist/index.js.map +1 -1
- package/dist/types/EndpointArgs.d.ts +3 -4
- package/dist/types/EndpointArgs.d.ts.map +1 -1
- package/dist/types/TypedRequest.d.ts +2 -1
- package/dist/types/TypedRequest.d.ts.map +1 -1
- package/dist/types/TypedRequestHandler.d.ts +2 -1
- package/dist/types/TypedRequestHandler.d.ts.map +1 -1
- package/dist/types/TypedResponse.d.ts +3 -1
- package/dist/types/TypedResponse.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -10,8 +10,7 @@ export declare class EndpointsCollection {
|
|
|
10
10
|
private router;
|
|
11
11
|
constructor();
|
|
12
12
|
private static validateInput;
|
|
13
|
-
|
|
14
|
-
callOriginal(method: HttpMethod, path: string, { inputSchema, outputSchema, summary, afterOutput, beforeOutput, afterInput, beforeInput, }: EndpointArgs<EndpointInputSchema, EndpointOutputSchema>, handlers: RequestHandler | RequestHandler[] | TypedRequestHandler<any, any>): import("express-serve-static-core").Router;
|
|
13
|
+
callOriginal(method: HttpMethod, path: string, { inputSchema, outputSchema, summary, beforeResponse, afterInputValidation, beforeInputValidation, }: EndpointArgs<EndpointInputSchema, EndpointOutputSchema>, handlers: RequestHandler | RequestHandler[] | TypedRequestHandler<any, any>): import("express-serve-static-core").Router;
|
|
15
14
|
get<TInput extends EndpointInputSchema, TOutput extends EndpointOutputSchema>(path: string, args: EndpointArgs<TInput, TOutput>, handlers: TypedRequestHandler<TInput, TOutput>): import("express-serve-static-core").Router;
|
|
16
15
|
post<TInput extends EndpointInputSchema, TOutput extends EndpointOutputSchema>(path: string, args: EndpointArgs<TInput, TOutput>, handler: TypedRequestHandler<TInput, TOutput>): import("express-serve-static-core").Router;
|
|
17
16
|
put<TInput extends EndpointInputSchema, TOutput extends EndpointOutputSchema>(path: string, args: EndpointArgs<TInput, TOutput>, handlers: TypedRequestHandler<TInput, TOutput>): import("express-serve-static-core").Router;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,cAAc,EACf,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,SAAS,CAAsB;IACvC,OAAO,CAAC,MAAM,CAAY;;IAI1B,OAAO,CAAC,MAAM,CAAC,aAAa;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,cAAc,EACf,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,SAAS,CAAsB;IACvC,OAAO,CAAC,MAAM,C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,IAAI,EAAE,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,QAAQ,EAAE,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC;IAKzC,OAAO,CACZ,MAAM,SAAS,mBAAmB,EAClC,OAAO,SAAS,oBAAoB,EAEpC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,QAAQ,EAAE,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC;IAKzC,IAAI,CACT,MAAM,SAAS,mBAAmB,EAClC,OAAO,SAAS,oBAAoB,EAEpC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,QAAQ,EAAE,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC;IAKzC,KAAK,CACV,MAAM,SAAS,mBAAmB,EAClC,OAAO,SAAS,oBAAoB,EAEpC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,QAAQ,EAAE,mBAAmB,CAAC,MAAM,EAAE,OAAO,CAAC;IAKzC,YAAY;IAIZ,SAAS;CAGjB"}
|
package/dist/index.js
CHANGED
|
@@ -31,33 +31,7 @@ class EndpointsCollection {
|
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
return (req, res, next) => {
|
|
36
|
-
const originalJson = res.json;
|
|
37
|
-
// @ts-ignore
|
|
38
|
-
res.json = (body) => {
|
|
39
|
-
const status = res.statusCode;
|
|
40
|
-
const schemaForStatus = schema.find((s) => s.status === status);
|
|
41
|
-
try {
|
|
42
|
-
if (schemaForStatus?.body) {
|
|
43
|
-
schemaForStatus.body.parse(body);
|
|
44
|
-
}
|
|
45
|
-
originalJson.call(res, body);
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
if (error instanceof zod_1.z.ZodError) {
|
|
49
|
-
console.error("Error in response validation", error.errors);
|
|
50
|
-
return res.status(500).json({
|
|
51
|
-
error: "Internal server error",
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
next(error);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
next();
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
callOriginal(method, path, { inputSchema, outputSchema, summary, afterOutput = [], beforeOutput = [], afterInput = [], beforeInput = [], }, handlers) {
|
|
34
|
+
callOriginal(method, path, { inputSchema, outputSchema, summary, beforeResponse = [], afterInputValidation = [], beforeInputValidation = [], }, handlers) {
|
|
61
35
|
this.endpoints.push({
|
|
62
36
|
path,
|
|
63
37
|
method: method,
|
|
@@ -66,24 +40,18 @@ class EndpointsCollection {
|
|
|
66
40
|
summary,
|
|
67
41
|
});
|
|
68
42
|
const combinedHandlers = [];
|
|
69
|
-
if (
|
|
70
|
-
combinedHandlers.push(
|
|
43
|
+
if (beforeInputValidation) {
|
|
44
|
+
combinedHandlers.push(beforeInputValidation);
|
|
71
45
|
}
|
|
72
46
|
if (inputSchema) {
|
|
73
47
|
combinedHandlers.push(EndpointsCollection.validateInput(inputSchema));
|
|
74
48
|
}
|
|
75
|
-
if (
|
|
76
|
-
combinedHandlers.push(
|
|
49
|
+
if (afterInputValidation) {
|
|
50
|
+
combinedHandlers.push(afterInputValidation);
|
|
77
51
|
}
|
|
78
52
|
combinedHandlers.push(handlers);
|
|
79
|
-
if (
|
|
80
|
-
combinedHandlers.push(
|
|
81
|
-
}
|
|
82
|
-
if (outputSchema) {
|
|
83
|
-
combinedHandlers.push(EndpointsCollection.validateOutput(outputSchema));
|
|
84
|
-
}
|
|
85
|
-
if (afterOutput) {
|
|
86
|
-
combinedHandlers.push(afterOutput);
|
|
53
|
+
if (beforeResponse) {
|
|
54
|
+
combinedHandlers.push(beforeResponse);
|
|
87
55
|
}
|
|
88
56
|
return this.router[method](path, ...combinedHandlers);
|
|
89
57
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAMiB;AAMjB,6BAAwB;AAGxB,MAAa,mBAAmB;IAI9B;QAHQ,cAAS,GAAmB,EAAE,CAAC;QAC/B,WAAM,GAAG,IAAA,gBAAM,GAAE,CAAC;IAEJ,CAAC;IAEf,MAAM,CAAC,aAAa,CAAC,MAA2B;QACtD,OAAO,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;YACzD,IAAI,CAAC;gBACH,IAAI,MAAM,CAAC,KAAK;oBAAE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;gBAChD,IAAI,MAAM,CAAC,IAAI;oBAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;gBAC7C,IAAI,MAAM,CAAC,MAAM;oBAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;gBACnD,IAAI,MAAM,CAAC,OAAO;oBAAE,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;gBACtD,IAAI,EAAE,CAAC;YACT,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,KAAK,YAAY,OAAC,CAAC,QAAQ,EAAE,CAAC;oBAChC,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC;wBAC1B,KAAK,EAAE,KAAK,CAAC,MAAM;qBACpB,CAAC,CAAC;gBACL,CAAC;gBACD,IAAI,CAAC,KAAK,CAAC,CAAC;YACd,CAAC;QACH,CAAC,CAAC;IACJ,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAMiB;AAMjB,6BAAwB;AAGxB,MAAa,mBAAmB;IAI9B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,QAAQ,CAAC,CAAC;IAC3D,CAAC;IAEM,KAAK,CAIV,IAAY,EACZ,IAAmC,EACnC,QAA8C;QAE9C,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC1D,CAAC;IAEM,OAAO,CAIZ,IAAY,EACZ,IAAmC,EACnC,QAA8C;QAE9C,OAAO,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC5D,CAAC;IAEM,IAAI,CAIT,IAAY,EACZ,IAAmC,EACnC,QAA8C;QAE9C,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IACzD,CAAC;IAEM,KAAK,CAIV,IAAY,EACZ,IAAmC,EACnC,QAA8C;QAE9C,OAAO,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC1D,CAAC;IAEM,YAAY;QACjB,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAEM,SAAS;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF;AApKD,kDAoKC"}
|
|
@@ -5,9 +5,8 @@ export type EndpointArgs<TInput extends EndpointInputSchema, TOutput extends End
|
|
|
5
5
|
inputSchema?: TInput;
|
|
6
6
|
outputSchema: TOutput;
|
|
7
7
|
summary?: string;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
afterOutput?: RequestHandler | RequestHandler[];
|
|
8
|
+
beforeInputValidation?: RequestHandler | RequestHandler[];
|
|
9
|
+
afterInputValidation?: RequestHandler | RequestHandler[];
|
|
10
|
+
beforeResponse?: RequestHandler | RequestHandler[];
|
|
12
11
|
};
|
|
13
12
|
//# sourceMappingURL=EndpointArgs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EndpointArgs.d.ts","sourceRoot":"","sources":["../../src/types/EndpointArgs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,MAAM,MAAM,YAAY,CACtB,MAAM,SAAS,mBAAmB,EAClC,OAAO,SAAS,oBAAoB,IAClC;IACF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,
|
|
1
|
+
{"version":3,"file":"EndpointArgs.d.ts","sourceRoot":"","sources":["../../src/types/EndpointArgs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,MAAM,MAAM,YAAY,CACtB,MAAM,SAAS,mBAAmB,EAClC,OAAO,SAAS,oBAAoB,IAClC;IACF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,qBAAqB,CAAC,EAAE,cAAc,GAAG,cAAc,EAAE,CAAC;IAC1D,oBAAoB,CAAC,EAAE,cAAc,GAAG,cAAc,EAAE,CAAC;IACzD,cAAc,CAAC,EAAE,cAAc,GAAG,cAAc,EAAE,CAAC;CACpD,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { EndpointInputSchema } from "./EndpointInputSchema";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
|
|
3
|
+
import { Request } from "express";
|
|
4
|
+
export type TypedRequest<T extends EndpointInputSchema> = Omit<Request, "body" | "query" | "params" | "headers"> & {
|
|
4
5
|
body: z.infer<NonNullable<T["body"]>>;
|
|
5
6
|
query: z.infer<NonNullable<T["query"]>>;
|
|
6
7
|
params: z.infer<NonNullable<T["params"]>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedRequest.d.ts","sourceRoot":"","sources":["../../src/types/TypedRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"TypedRequest.d.ts","sourceRoot":"","sources":["../../src/types/TypedRequest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,mBAAmB,IAAI,IAAI,CAC5D,OAAO,EACP,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CACxC,GAAG;IACF,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACtC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IACxC,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAC1C,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;CAC7C,CAAC"}
|
|
@@ -2,5 +2,6 @@ import { EndpointInputSchema } from "./EndpointInputSchema";
|
|
|
2
2
|
import { EndpointOutputSchema } from "./EndpointOutputSchema";
|
|
3
3
|
import { TypedRequest } from "./TypedRequest";
|
|
4
4
|
import { TypedResponse } from "./TypedResponse";
|
|
5
|
-
|
|
5
|
+
import { NextFunction } from "express";
|
|
6
|
+
export type TypedRequestHandler<TInput extends EndpointInputSchema, TOutput extends EndpointOutputSchema> = (req: TypedRequest<TInput>, res: TypedResponse<TOutput>, next: NextFunction) => void | Promise<void>;
|
|
6
7
|
//# sourceMappingURL=TypedRequestHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedRequestHandler.d.ts","sourceRoot":"","sources":["../../src/types/TypedRequestHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"TypedRequestHandler.d.ts","sourceRoot":"","sources":["../../src/types/TypedRequestHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,MAAM,mBAAmB,CAC7B,MAAM,SAAS,mBAAmB,EAClC,OAAO,SAAS,oBAAoB,IAClC,CACF,GAAG,EAAE,YAAY,CAAC,MAAM,CAAC,EACzB,GAAG,EAAE,aAAa,CAAC,OAAO,CAAC,EAC3B,IAAI,EAAE,YAAY,KACf,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { EndpointOutputSchema } from "./EndpointOutputSchema";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
|
|
3
|
+
import { Response } from "express";
|
|
4
|
+
export type TypedResponse<T extends EndpointOutputSchema> = Omit<Response, "json" | "status" | "sendStatus"> & {
|
|
4
5
|
json: (data: z.infer<NonNullable<T[number]["body"]>>) => void;
|
|
5
6
|
status: <S extends T[number]["status"]>(code: S) => Omit<TypedResponse<T>, "status"> & {
|
|
6
7
|
json: (data: z.infer<NonNullable<Extract<T[number], {
|
|
7
8
|
status: S;
|
|
8
9
|
}>["body"]>>) => void;
|
|
9
10
|
};
|
|
11
|
+
sendStatus: <S extends T[number]["status"]>(code: S) => void;
|
|
10
12
|
};
|
|
11
13
|
//# sourceMappingURL=TypedResponse.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypedResponse.d.ts","sourceRoot":"","sources":["../../src/types/TypedResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"TypedResponse.d.ts","sourceRoot":"","sources":["../../src/types/TypedResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,oBAAoB,IAAI,IAAI,CAC9D,QAAQ,EACR,MAAM,GAAG,QAAQ,GAAG,YAAY,CACjC,GAAG;IACF,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IAC9D,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,EACpC,IAAI,EAAE,CAAC,KACJ,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG;QACtC,IAAI,EAAE,CACJ,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE;YAAE,MAAM,EAAE,CAAC,CAAA;SAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAClE,IAAI,CAAC;KACX,CAAC;IACF,UAAU,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;CAC9D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "express-endpoints-collection",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"repository": "https://github.com/pilotpirxie/express-endpoints-collection.git",
|
|
6
6
|
"author": "pilotpirxie <10637666+pilotpirxie@users.noreply.github.com>",
|