bootpress 9.0.2 → 9.1.0
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/README.md +10 -6
- package/helpers/index.d.ts +1 -0
- package/index.d.ts +27 -16
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -61,13 +61,17 @@ class PostServiceImpl {
|
|
|
61
61
|
return new HttpResponse(201, casted.id);
|
|
62
62
|
}
|
|
63
63
|
delete(deleteInQuery: string | undefined, idInQuery: string | undefined) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
this
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
if (deleteInQuery === "yes") {
|
|
65
|
+
const id = as(idInQuery, "integer");
|
|
66
|
+
const index = this.posts.indexOf(id);
|
|
67
|
+
if (index > -1) {
|
|
68
|
+
this.#logDeleted(idInQuery!);
|
|
69
|
+
return this.posts.splice(index, 1);
|
|
70
|
+
} else {
|
|
71
|
+
throw new HttpError(404, "Post is not found")
|
|
72
|
+
}
|
|
70
73
|
}
|
|
74
|
+
throw new HttpError(400, "Bad Request");
|
|
71
75
|
}
|
|
72
76
|
// use private methods to
|
|
73
77
|
#logDeleted(id: number | string) {
|
package/helpers/index.d.ts
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { Response, Request } from "express"
|
|
2
|
-
import { ArraySchema, JsSchema, ValidTypeKeys, TypedSchema } from "./helpers"
|
|
2
|
+
import { ArraySchema, JsSchema, ValidTypeKeys, TypedSchema, ValOf, TypedArraySchema } from "./helpers"
|
|
3
3
|
|
|
4
4
|
type RequestHandler = (req: Request, res: Response) => void
|
|
5
|
-
type
|
|
6
|
-
type
|
|
5
|
+
type ArrayWithLastElement<L> = [...rest: any[], lastArg: L];
|
|
6
|
+
type RequsetHandlerWithLastArg<T, F extends (...args: any) => RequestHandler = (...args: any[]) => RequestHandler, P extends ArrayWithLastElement<T> = Parameters<F>> = (...args: P) => RequestHandler;
|
|
7
7
|
type NonEmptyArray = readonly [any, ...any[]];
|
|
8
|
-
type ShiftRequestHandler<F extends
|
|
8
|
+
type ShiftRequestHandler<F extends RequsetHandlerWithLastArg<any> | RequestHandler> =
|
|
9
|
+
F extends (arg1: infer T, ...rest: infer U) => RequestHandler ?
|
|
10
|
+
U extends NonEmptyArray ? (...rest: U) => RequestHandler : RequestHandler
|
|
11
|
+
: RequestHandler
|
|
9
12
|
|
|
10
|
-
type RestedService<T extends Record<PropertyKey, any>> = {
|
|
13
|
+
type RestedService<T extends Record<PropertyKey, any>> = {
|
|
14
|
+
[K in keyof T]:
|
|
11
15
|
T[K] extends Function
|
|
12
16
|
? (...args: Parameters<T[K]>) => RequestHandler
|
|
13
17
|
: T[K]
|
|
@@ -15,21 +19,28 @@ type RestedService<T extends Record<PropertyKey, any>> = { [K in keyof T]:
|
|
|
15
19
|
|
|
16
20
|
type InstanceOrClass<T extends Record<PropertyKey, any>> = T | (new () => T);
|
|
17
21
|
|
|
22
|
+
type TypeValueOf<S extends ValidTypeKeys | JsSchema | TypedSchema<any> | ArraySchema> =
|
|
23
|
+
S extends ValidTypeKeys ? ValOf<S>
|
|
24
|
+
: S extends JsSchema ? TypedSchema<S>
|
|
25
|
+
: S extends TypedSchema<any> ? S
|
|
26
|
+
: S extends ArraySchema ? TypedArraySchema<S>
|
|
27
|
+
: never;
|
|
28
|
+
|
|
18
29
|
declare function RestService<T extends Record<PropertyKey, any>>(service: InstanceOrClass<T>): RestedService<T>;
|
|
19
30
|
declare function RestMethod<T>(callback: () => T): RequestHandler;
|
|
20
31
|
declare function Restify(target: any, key: PropertyKey, desc: PropertyDescriptor): PropertyDescriptor;
|
|
21
32
|
|
|
22
|
-
declare function PassBody<F extends
|
|
23
|
-
declare function ParseBodyAs<
|
|
24
|
-
declare function PassBodyAs<
|
|
25
|
-
declare function PassAllParams<F extends
|
|
26
|
-
declare function PassAllQueries<F extends
|
|
27
|
-
declare function PassAllCookies<F extends
|
|
28
|
-
declare function PassParam<F extends
|
|
29
|
-
declare function PassQuery<F extends
|
|
30
|
-
declare function PassCookie<F extends
|
|
31
|
-
declare function PassRequest<F extends
|
|
32
|
-
declare function PassResponse<F extends
|
|
33
|
+
declare function PassBody<F extends RequsetHandlerWithLastArg<any>>(serviceFunction: F): ShiftRequestHandler<F>
|
|
34
|
+
declare function ParseBodyAs<S extends ValidTypeKeys | JsSchema | TypedSchema<any> | ArraySchema, T = TypeValueOf<S>>(type: S): <F extends RequsetHandlerWithLastArg<T>>(serviceFunction: F) => ShiftRequestHandler<F>
|
|
35
|
+
declare function PassBodyAs<S extends ValidTypeKeys | JsSchema | TypedSchema<any> | ArraySchema, T = TypeValueOf<S>>(type: S): <F extends RequsetHandlerWithLastArg<T>>(serviceFunction: F) => ShiftRequestHandler<F>
|
|
36
|
+
declare function PassAllParams<F extends RequsetHandlerWithLastArg<string[]>>(serviceFunction: F): ShiftRequestHandler<F>
|
|
37
|
+
declare function PassAllQueries<F extends RequsetHandlerWithLastArg<string[]>>(serviceFunction: F): ShiftRequestHandler<F>
|
|
38
|
+
declare function PassAllCookies<F extends RequsetHandlerWithLastArg<string[]>>(serviceFunction: F): ShiftRequestHandler<F>
|
|
39
|
+
declare function PassParam(paramName: string): <F extends RequsetHandlerWithLastArg<string | undefined>>(serviceFunction: F) => ShiftRequestHandler<F>
|
|
40
|
+
declare function PassQuery(queryName: string): <F extends RequsetHandlerWithLastArg<string | undefined>>(serviceFunction: F) => ShiftRequestHandler<F>
|
|
41
|
+
declare function PassCookie(cookieName: string): <F extends RequsetHandlerWithLastArg<string | undefined>>(serviceFunction: F) => ShiftRequestHandler<F>
|
|
42
|
+
declare function PassRequest<F extends RequsetHandlerWithLastArg<Request>>(serviceFunction: F): ShiftRequestHandler<F>
|
|
43
|
+
declare function PassResponse<F extends RequsetHandlerWithLastArg<Response>>(serviceFunction: F): ShiftRequestHandler<F>
|
|
33
44
|
|
|
34
45
|
export {
|
|
35
46
|
RestService,
|