@tahminator/sapling 1.5.1 → 1.5.4

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 CHANGED
@@ -31,7 +31,7 @@ A lightweight library that brings some structure to Express.js
31
31
 
32
32
  Check the `/example` folder for a basic todo app with database integration.
33
33
 
34
- Sapling is also powering one of my more complex projects with 400+ users in production, which you can view at [instalock-web](https://github.com/tahminator/instalock-web).
34
+ Sapling is also powering one of my more complex projects with 600+ users in production, which you can view at [instalock-web](https://github.com/tahminator/instalock-web).
35
35
 
36
36
  ## Install
37
37
 
@@ -188,7 +188,7 @@ import { Controller, Middleware } from "@tahminator/sapling";
188
188
  import cookieParser from "cookie-parser";
189
189
  import { NextFunction, Request, Response } from "express";
190
190
 
191
- @Controller()
191
+ @MiddlewareClass() // works the same as @Controller, semantically different
192
192
  class CookieParserMiddleware {
193
193
  private readonly plugin: ReturnType<typeof cookieParser>;
194
194
 
@@ -1,3 +1,4 @@
1
1
  export * from "./controller";
2
2
  export * from "./injectable";
3
3
  export * from "./route";
4
+ export * from "./middleware";
@@ -1,3 +1,4 @@
1
1
  export * from "./controller";
2
2
  export * from "./injectable";
3
3
  export * from "./route";
4
+ export * from "./middleware";
@@ -0,0 +1,9 @@
1
+ import { Controller } from "./controller";
2
+ /**
3
+ * Used to define a middleware-only class.
4
+ *
5
+ * __NOTE:__ `@MiddlewareClass` works exactly the same as `@Controller`. As such, you
6
+ * can still register `@Route` and `@Middleware` methods, though you very well should not
7
+ * for the sake of semantics.
8
+ */
9
+ export declare function MiddlewareClass(...args: Parameters<typeof Controller>): ClassDecorator;
@@ -0,0 +1,11 @@
1
+ import { Controller } from "./controller";
2
+ /**
3
+ * Used to define a middleware-only class.
4
+ *
5
+ * __NOTE:__ `@MiddlewareClass` works exactly the same as `@Controller`. As such, you
6
+ * can still register `@Route` and `@Middleware` methods, though you very well should not
7
+ * for the sake of semantics.
8
+ */
9
+ export function MiddlewareClass(...args) {
10
+ return Controller(...args);
11
+ }
@@ -19,7 +19,7 @@ export declare class Sapling {
19
19
  * app.use(router);
20
20
  * ```
21
21
  */
22
- static resolve<TClass>(clazz: Class<TClass>): Router;
22
+ static resolve<TClass>(this: void, clazz: Class<TClass>): Router;
23
23
  /**
24
24
  * Register this function as a middleware in order to utilize Sapling's `deserialize` function.
25
25
  *
@@ -32,7 +32,7 @@ export declare class Sapling {
32
32
  * app.use(Sapling.json());
33
33
  * ```
34
34
  */
35
- static json(): ExpressMiddlewareFn;
35
+ static json(this: void): ExpressMiddlewareFn;
36
36
  /**
37
37
  * Register your application with all the necessary middlewares and logics for Sapling to function.
38
38
  *
@@ -68,7 +68,7 @@ export declare class Sapling {
68
68
  * });
69
69
  * ```
70
70
  */
71
- static loadResponseStatusErrorMiddleware(app: e.Express, fn: (err: ResponseStatusError, request: e.Request, response: e.Response, next: e.NextFunction) => void): void;
71
+ static loadResponseStatusErrorMiddleware(this: void, app: e.Express, fn: (err: ResponseStatusError, request: e.Request, response: e.Response, next: e.NextFunction) => void): void;
72
72
  /**
73
73
  * Serialize a value into a JSON string.
74
74
  *
@@ -78,11 +78,11 @@ export declare class Sapling {
78
78
  *
79
79
  * @defaultValue `JSON.stringify`
80
80
  */
81
- static serialize(value: any): string;
81
+ static serialize(this: void, value: any): string;
82
82
  /**
83
83
  * Replace the function used for `serialize`.
84
84
  */
85
- static setSerializeFn(fn: (value: any) => string): void;
85
+ static setSerializeFn(this: void, fn: (value: any) => string): void;
86
86
  /**
87
87
  * De-serialize a JSON string back to a JavaScript object.
88
88
  *
@@ -92,9 +92,9 @@ export declare class Sapling {
92
92
  *
93
93
  * @defaultValue `JSON.parse`
94
94
  */
95
- static deserialize<T = any>(value: string): T;
95
+ static deserialize<T = any>(this: void, value: string): T;
96
96
  /**
97
97
  * Replace the function used for `deserialize`
98
98
  */
99
- static setDeserializeFn(fn: (value: string) => any): void;
99
+ static setDeserializeFn(this: void, fn: (value: string) => any): void;
100
100
  }
@@ -1,7 +1,7 @@
1
1
  import e from "express";
2
2
  import { _ControllerRegistry } from "../annotation/controller";
3
3
  import { ResponseStatusError } from "./error";
4
- let settings = {
4
+ const settings = {
5
5
  serialize: JSON.stringify,
6
6
  deserialize: JSON.parse,
7
7
  };
@@ -80,7 +80,7 @@ export class Sapling {
80
80
  */
81
81
  static registerApp(app) {
82
82
  app.use(e.text({ type: "application/json" }));
83
- app.use(this.json());
83
+ app.use(Sapling.json());
84
84
  }
85
85
  /**
86
86
  * Register a middleware that will handle {@link ResponseStatusError}.
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "@tahminator/sapling",
3
- "version": "1.5.1",
3
+ "version": "1.5.4",
4
+ "author": "Tahmid Ahmed",
4
5
  "description": "A library to help you write cleaner Express.js code",
6
+ "repository": {
7
+ "url": "git+https://github.com/tahminator/sapling.git"
8
+ },
5
9
  "scripts": {
6
10
  "test": "pnpm run build",
7
11
  "build": "rm -rf dist && tsc"
@@ -12,14 +16,14 @@
12
16
  "exports": {
13
17
  ".": {
14
18
  "types": "./dist/index.d.ts",
15
- "import": "./dist/index.js"
19
+ "import": "./dist/index.js",
20
+ "require": "./dist/index.js"
16
21
  }
17
22
  },
18
23
  "files": [
19
24
  "/dist"
20
25
  ],
21
26
  "keywords": [],
22
- "author": "Tahmid Ahmed",
23
27
  "license": "ISC",
24
28
  "packageManager": "pnpm@10.12.4",
25
29
  "dependencies": {