@tahminator/sapling 1.5.4 → 1.5.5

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.
Files changed (39) hide show
  1. package/package.json +27 -2
  2. package/dist/index.d.ts +0 -1
  3. package/dist/index.js +0 -1
  4. package/dist/lib/weakmap.d.ts +0 -15
  5. package/dist/lib/weakmap.js +0 -77
  6. package/dist/src/annotation/controller.d.ts +0 -21
  7. package/dist/src/annotation/controller.js +0 -79
  8. package/dist/src/annotation/index.d.ts +0 -4
  9. package/dist/src/annotation/index.js +0 -4
  10. package/dist/src/annotation/injectable.d.ts +0 -25
  11. package/dist/src/annotation/injectable.js +0 -66
  12. package/dist/src/annotation/middleware.d.ts +0 -9
  13. package/dist/src/annotation/middleware.js +0 -11
  14. package/dist/src/annotation/route.d.ts +0 -45
  15. package/dist/src/annotation/route.js +0 -77
  16. package/dist/src/enum/http.d.ts +0 -68
  17. package/dist/src/enum/http.js +0 -69
  18. package/dist/src/enum/index.d.ts +0 -1
  19. package/dist/src/enum/index.js +0 -1
  20. package/dist/src/helper/error.d.ts +0 -10
  21. package/dist/src/helper/error.js +0 -17
  22. package/dist/src/helper/importer.d.ts +0 -1
  23. package/dist/src/helper/importer.js +0 -5
  24. package/dist/src/helper/index.d.ts +0 -4
  25. package/dist/src/helper/index.js +0 -4
  26. package/dist/src/helper/redirect.d.ts +0 -14
  27. package/dist/src/helper/redirect.js +0 -19
  28. package/dist/src/helper/response.d.ts +0 -68
  29. package/dist/src/helper/response.js +0 -88
  30. package/dist/src/helper/sapling.d.ts +0 -100
  31. package/dist/src/helper/sapling.js +0 -153
  32. package/dist/src/html/404.d.ts +0 -4
  33. package/dist/src/html/404.js +0 -15
  34. package/dist/src/html/index.d.ts +0 -1
  35. package/dist/src/html/index.js +0 -1
  36. package/dist/src/index.d.ts +0 -5
  37. package/dist/src/index.js +0 -5
  38. package/dist/src/types.d.ts +0 -21
  39. package/dist/src/types.js +0 -11
package/package.json CHANGED
@@ -1,13 +1,23 @@
1
1
  {
2
2
  "name": "@tahminator/sapling",
3
- "version": "1.5.4",
3
+ "version": "1.5.5",
4
4
  "author": "Tahmid Ahmed",
5
5
  "description": "A library to help you write cleaner Express.js code",
6
6
  "repository": {
7
7
  "url": "git+https://github.com/tahminator/sapling.git"
8
8
  },
9
9
  "scripts": {
10
- "test": "pnpm run build",
10
+ "test": "pnpm run typecheck && pnpm run lint && pnpm run fmt && pnpm run vt && pnpm run build",
11
+ "vt": "vitest run",
12
+ "fmt": "pnpm run prettier",
13
+ "fmt:fix": "pnpm run prettier:fix",
14
+ "lint": "pnpm run eslint",
15
+ "lint:fix": "pnpm run eslint:fix",
16
+ "eslint": "eslint .",
17
+ "eslint:fix": "eslint . --fix",
18
+ "prettier": "NODE_OPTIONS=\"--experimental-strip-types\" prettier --check .",
19
+ "prettier:fix": "NODE_OPTIONS=\"--experimental-strip-types\" prettier --write .",
20
+ "typecheck": "tsc -b --noEmit",
11
21
  "build": "rm -rf dist && tsc"
12
22
  },
13
23
  "main": "./dist/index.js",
@@ -29,5 +39,20 @@
29
39
  "dependencies": {
30
40
  "@types/express": "^5.0.6",
31
41
  "express": "^5.2.1"
42
+ },
43
+ "devDependencies": {
44
+ "@eslint/js": "^10.0.1",
45
+ "@types/supertest": "^7.2.0",
46
+ "@vitest/coverage-istanbul": "^4.1.2",
47
+ "eslint": "^10.1.0",
48
+ "eslint-plugin-perfectionist": "^5.7.0",
49
+ "globals": "^17.4.0",
50
+ "jiti": "^2.6.1",
51
+ "jsdom": "^29.0.1",
52
+ "prettier": "^3.8.1",
53
+ "supertest": "^7.2.2",
54
+ "typescript-eslint": "^8.57.2",
55
+ "vite-tsconfig-paths": "^6.1.1",
56
+ "vitest": "^4.1.2"
32
57
  }
33
58
  }
package/dist/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src";
package/dist/index.js DELETED
@@ -1 +0,0 @@
1
- export * from "./src";
@@ -1,15 +0,0 @@
1
- /**
2
- * WeakMap that is iterable.
3
- */
4
- export declare class IterableWeakMap<K extends object, V> {
5
- #private;
6
- constructor(iterable?: Iterable<[K, V]>);
7
- set(key: K, value: V): this;
8
- get(key: K): V | undefined;
9
- delete(key: K): boolean;
10
- [Symbol.iterator](): IterableIterator<[K, V]>;
11
- entries(): IterableIterator<[K, V]>;
12
- keys(): IterableIterator<K>;
13
- values(): IterableIterator<V>;
14
- forEach(callback: (value: V, key: K, map: this) => void, thisArg?: any): void;
15
- }
@@ -1,77 +0,0 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
- var _a, _IterableWeakMap_weakMap, _IterableWeakMap_refSet, _IterableWeakMap_finalizationGroup, _IterableWeakMap_cleanup;
7
- /**
8
- * WeakMap that is iterable.
9
- */
10
- export class IterableWeakMap {
11
- constructor(iterable) {
12
- _IterableWeakMap_weakMap.set(this, new WeakMap());
13
- _IterableWeakMap_refSet.set(this, new Set());
14
- _IterableWeakMap_finalizationGroup.set(this, new FinalizationRegistry(__classPrivateFieldGet(_a, _a, "m", _IterableWeakMap_cleanup)));
15
- if (iterable) {
16
- for (const [key, value] of iterable) {
17
- this.set(key, value);
18
- }
19
- }
20
- }
21
- set(key, value) {
22
- const ref = new WeakRef(key);
23
- __classPrivateFieldGet(this, _IterableWeakMap_weakMap, "f").set(key, { value, ref });
24
- __classPrivateFieldGet(this, _IterableWeakMap_refSet, "f").add(ref);
25
- __classPrivateFieldGet(this, _IterableWeakMap_finalizationGroup, "f").register(key, {
26
- set: __classPrivateFieldGet(this, _IterableWeakMap_refSet, "f"),
27
- ref,
28
- }, ref);
29
- return this;
30
- }
31
- get(key) {
32
- const entry = __classPrivateFieldGet(this, _IterableWeakMap_weakMap, "f").get(key);
33
- return entry === null || entry === void 0 ? void 0 : entry.value;
34
- }
35
- delete(key) {
36
- const entry = __classPrivateFieldGet(this, _IterableWeakMap_weakMap, "f").get(key);
37
- if (!entry) {
38
- return false;
39
- }
40
- __classPrivateFieldGet(this, _IterableWeakMap_weakMap, "f").delete(key);
41
- __classPrivateFieldGet(this, _IterableWeakMap_refSet, "f").delete(entry.ref);
42
- __classPrivateFieldGet(this, _IterableWeakMap_finalizationGroup, "f").unregister(entry.ref);
43
- return true;
44
- }
45
- *[(_IterableWeakMap_weakMap = new WeakMap(), _IterableWeakMap_refSet = new WeakMap(), _IterableWeakMap_finalizationGroup = new WeakMap(), _IterableWeakMap_cleanup = function _IterableWeakMap_cleanup(heldValue) {
46
- heldValue.set.delete(heldValue.ref);
47
- }, Symbol.iterator)]() {
48
- for (const ref of __classPrivateFieldGet(this, _IterableWeakMap_refSet, "f")) {
49
- const key = ref.deref();
50
- if (!key)
51
- continue;
52
- const entry = __classPrivateFieldGet(this, _IterableWeakMap_weakMap, "f").get(key);
53
- if (entry) {
54
- yield [key, entry.value];
55
- }
56
- }
57
- }
58
- entries() {
59
- return this[Symbol.iterator]();
60
- }
61
- *keys() {
62
- for (const [key] of this) {
63
- yield key;
64
- }
65
- }
66
- *values() {
67
- for (const [, value] of this) {
68
- yield value;
69
- }
70
- }
71
- forEach(callback, thisArg) {
72
- for (const [key, value] of this) {
73
- callback.call(thisArg, value, key, this);
74
- }
75
- }
76
- }
77
- _a = IterableWeakMap;
@@ -1,21 +0,0 @@
1
- import { Router } from "express";
2
- import { Class } from "../types";
3
- export declare const _ControllerRegistry: WeakMap<Function, Router>;
4
- type ControllerProps = {
5
- /**
6
- * Optional URL prefix applied to all routes in the controller. Defaults to "".
7
- */
8
- prefix?: string;
9
- /**
10
- * Optional array of dependencies to be injected into the constructor that are `@Injectable`
11
- */
12
- deps?: Array<Class<any>>;
13
- } | undefined;
14
- /**
15
- * Registers a class as an HTTP controller and registers its routes.
16
- *
17
- * @param [prefix] Optional URL prefix applied to all routes in the controller. Defaults to "".
18
- * @param [deps] Optional array of dependencies to be injected into the constructor that are `@Injectable`
19
- */
20
- export declare function Controller({ prefix, deps }?: ControllerProps): ClassDecorator;
21
- export {};
@@ -1,79 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { Router } from "express";
11
- import { _InjectableDeps, _resolve } from "./injectable";
12
- import { methodResolve } from "../types";
13
- import { _getRoutes } from "./route";
14
- import { Sapling } from "../helper/sapling";
15
- import { Html404ErrorPage } from "../html/404";
16
- import { ResponseEntity, RedirectView } from "../helper";
17
- export const _ControllerRegistry = new WeakMap();
18
- /**
19
- * Registers a class as an HTTP controller and registers its routes.
20
- *
21
- * @param [prefix] Optional URL prefix applied to all routes in the controller. Defaults to "".
22
- * @param [deps] Optional array of dependencies to be injected into the constructor that are `@Injectable`
23
- */
24
- export function Controller({ prefix = "", deps = [] } = {
25
- prefix: "",
26
- deps: [],
27
- }) {
28
- return (target) => {
29
- const targetClass = target;
30
- const router = Router();
31
- const routes = _getRoutes(target);
32
- const usedRoutes = new Set();
33
- _InjectableDeps.set(targetClass, deps);
34
- const controllerInstance = _resolve(targetClass);
35
- for (const { method, path, fnName } of routes) {
36
- const fn = controllerInstance[fnName];
37
- if (typeof fn !== "function")
38
- continue;
39
- // When path is a RegExp, use it directly without prefix
40
- // When path is a string, prepend the prefix
41
- const fp = path instanceof RegExp ? path : prefix + path;
42
- const routeKey = method + " " + (path instanceof RegExp ? path.source : fp);
43
- // Only check for duplicates on non-middleware routes
44
- // Middleware (USE) can have duplicate paths, and different HTTP methods can share paths
45
- if (method !== "USE" && usedRoutes.has(routeKey)) {
46
- throw new Error(`Duplicate route [${method}] "${path instanceof RegExp ? path.source : fp}" detected in controller "${target.name}"`);
47
- }
48
- if (method !== "USE") {
49
- usedRoutes.add(routeKey);
50
- }
51
- const methodName = methodResolve[method];
52
- router[methodName](fp, (request, response, next) => __awaiter(this, void 0, void 0, function* () {
53
- const result = yield fn.bind(controllerInstance)(request, response, next);
54
- // Middleware (USE) should not send responses, just call next()
55
- if (method === "USE") {
56
- return;
57
- }
58
- if (result instanceof ResponseEntity) {
59
- response
60
- .contentType("application/json")
61
- .status(result.getStatusCode())
62
- .set(result.getHeaders())
63
- .send(Sapling.serialize(result.getBody()));
64
- return;
65
- }
66
- if (result instanceof RedirectView) {
67
- response.redirect(result.getUrl());
68
- return;
69
- }
70
- if (!response.writableEnded) {
71
- response
72
- .status(404)
73
- .send(Html404ErrorPage(`Cannot ${methodName.toUpperCase()} ${path instanceof RegExp ? path.source : fp}`));
74
- }
75
- }));
76
- }
77
- _ControllerRegistry.set(targetClass, router);
78
- };
79
- }
@@ -1,4 +0,0 @@
1
- export * from "./controller";
2
- export * from "./injectable";
3
- export * from "./route";
4
- export * from "./middleware";
@@ -1,4 +0,0 @@
1
- export * from "./controller";
2
- export * from "./injectable";
3
- export * from "./route";
4
- export * from "./middleware";
@@ -1,25 +0,0 @@
1
- import { IterableWeakMap } from "../../lib/weakmap";
2
- import { Class } from "../types";
3
- export declare const _InjectableRegistry: WeakMap<Class<any>, any>;
4
- export declare const _InjectableDeps: IterableWeakMap<Class<any>, Class<any>[]>;
5
- /**
6
- * Mark the class as an injectable to be handled by Sapling. The class can now be
7
- * be injected into other classes, as well as allow the class to inject other `@Injectable` classes.
8
- *
9
- * @argument deps - An optional array to define any dependencies that this class may require.
10
- */
11
- export declare function Injectable(deps?: Array<Class<any>>): ClassDecorator;
12
- /**
13
- * Resolves and instantiates a class along with all of it's transitive dependencies.
14
- *
15
- * Uses topological sort (Kahn's algorithm) to ensure that the dependency graph is created
16
- * in a correct order.
17
- *
18
- * When `resolve` is first called (usually during controller registration),
19
- * it will compute the dependency graph of all `@Injectable` classes and instantiates
20
- * them in the correct order.
21
- *
22
- * Subsequent calls to dependencies that have already been resolved are cached, so they will
23
- * re-use the created singletons instead of re-instantiation.
24
- */
25
- export declare function _resolve<T>(ctor: Class<T>): T;
@@ -1,66 +0,0 @@
1
- import { IterableWeakMap } from "../../lib/weakmap";
2
- export const _InjectableRegistry = new WeakMap();
3
- export const _InjectableDeps = new IterableWeakMap();
4
- /**
5
- * Mark the class as an injectable to be handled by Sapling. The class can now be
6
- * be injected into other classes, as well as allow the class to inject other `@Injectable` classes.
7
- *
8
- * @argument deps - An optional array to define any dependencies that this class may require.
9
- */
10
- export function Injectable(deps = []) {
11
- return function (target) {
12
- _InjectableRegistry.set(target, null);
13
- _InjectableDeps.set(target, deps);
14
- };
15
- }
16
- /**
17
- * Resolves and instantiates a class along with all of it's transitive dependencies.
18
- *
19
- * Uses topological sort (Kahn's algorithm) to ensure that the dependency graph is created
20
- * in a correct order.
21
- *
22
- * When `resolve` is first called (usually during controller registration),
23
- * it will compute the dependency graph of all `@Injectable` classes and instantiates
24
- * them in the correct order.
25
- *
26
- * Subsequent calls to dependencies that have already been resolved are cached, so they will
27
- * re-use the created singletons instead of re-instantiation.
28
- */
29
- export function _resolve(ctor) {
30
- const inDegree = new Map();
31
- const graph = new Map();
32
- _InjectableDeps.forEach((deps, node) => {
33
- inDegree.set(node, inDegree.get(node) || 0);
34
- deps.forEach((dep) => {
35
- inDegree.set(dep, inDegree.get(dep) || 0);
36
- inDegree.set(node, inDegree.get(node) + 1);
37
- if (!graph.has(dep))
38
- graph.set(dep, []);
39
- graph.get(dep).push(node);
40
- });
41
- });
42
- const queue = [];
43
- inDegree.forEach((deg, node) => {
44
- if (deg === 0)
45
- queue.push(node);
46
- });
47
- while (queue.length) {
48
- const current = queue.shift();
49
- if (!_InjectableRegistry.get(current)) {
50
- const deps = _InjectableDeps.get(current) || [];
51
- const params = deps.map((dep) => _InjectableRegistry.get(dep));
52
- const instance = new current(...params);
53
- _InjectableRegistry.set(current, instance);
54
- }
55
- (graph.get(current) || []).forEach((neighbor) => {
56
- var _a;
57
- inDegree.set(neighbor, ((_a = inDegree.get(neighbor)) !== null && _a !== void 0 ? _a : 0) - 1);
58
- if (inDegree.get(neighbor) === 0)
59
- queue.push(neighbor);
60
- });
61
- }
62
- if (!_InjectableRegistry.get(ctor)) {
63
- throw new Error("Circular dependency detected or injectable not registered");
64
- }
65
- return _InjectableRegistry.get(ctor);
66
- }
@@ -1,9 +0,0 @@
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;
@@ -1,11 +0,0 @@
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
- }
@@ -1,45 +0,0 @@
1
- import { RouteDefinition, ExpressRouterMethodKey } from "../types";
2
- /**
3
- * Custom annotation that will store all routes inside of a map,
4
- * which can then be used to initialize all the routes to the router.
5
- */
6
- export declare function _Route({ method, path, }: {
7
- method: ExpressRouterMethodKey;
8
- path: string | RegExp | undefined;
9
- }): MethodDecorator;
10
- /**
11
- * Register GET route on the given path (default "") for the given controller.
12
- */
13
- export declare const GET: (path?: string | RegExp | undefined) => MethodDecorator;
14
- /**
15
- * Register POST route on the given path (default "") for the given controller.
16
- */
17
- export declare const POST: (path?: string | RegExp | undefined) => MethodDecorator;
18
- /**
19
- * Register PUT route on the given path (default "") for the given controller.
20
- */
21
- export declare const PUT: (path?: string | RegExp | undefined) => MethodDecorator;
22
- /**
23
- * Register DELETE route on the given path (default "") for the given controller.
24
- */
25
- export declare const DELETE: (path?: string | RegExp | undefined) => MethodDecorator;
26
- /**
27
- * Register OPTIONS route on the given path (default "") for the given controller.
28
- */
29
- export declare const OPTIONS: (path?: string | RegExp | undefined) => MethodDecorator;
30
- /**
31
- * Register PATCH route on the given path (default "") for the given controller.
32
- */
33
- export declare const PATCH: (path?: string | RegExp | undefined) => MethodDecorator;
34
- /**
35
- * Register HEAD route on the given path (default "") for the given controller.
36
- */
37
- export declare const HEAD: (path?: string | RegExp | undefined) => MethodDecorator;
38
- /**
39
- * Register a middleware route on the given path (default "") for the given controller.
40
- */
41
- export declare const Middleware: (path?: string | RegExp | undefined) => MethodDecorator;
42
- /**
43
- * Given a class constructor, fetch all the routes attached.
44
- */
45
- export declare function _getRoutes(ctor: Function): readonly RouteDefinition[];
@@ -1,77 +0,0 @@
1
- const _routeStore = new WeakMap();
2
- /**
3
- * Custom annotation that will store all routes inside of a map,
4
- * which can then be used to initialize all the routes to the router.
5
- */
6
- export function _Route({ method, path = "", }) {
7
- return (target, propertyKey) => {
8
- var _a;
9
- const ctor = target.constructor;
10
- const list = (_a = _routeStore.get(ctor)) !== null && _a !== void 0 ? _a : [];
11
- list.push({ method, path: path !== null && path !== void 0 ? path : "", fnName: String(propertyKey) });
12
- _routeStore.set(ctor, list);
13
- };
14
- }
15
- /**
16
- * Register GET route on the given path (default "") for the given controller.
17
- */
18
- export const GET = (path = "") => _Route({
19
- method: "GET",
20
- path,
21
- });
22
- /**
23
- * Register POST route on the given path (default "") for the given controller.
24
- */
25
- export const POST = (path = "") => _Route({
26
- method: "POST",
27
- path,
28
- });
29
- /**
30
- * Register PUT route on the given path (default "") for the given controller.
31
- */
32
- export const PUT = (path = "") => _Route({
33
- method: "PUT",
34
- path,
35
- });
36
- /**
37
- * Register DELETE route on the given path (default "") for the given controller.
38
- */
39
- export const DELETE = (path = "") => _Route({
40
- method: "DELETE",
41
- path,
42
- });
43
- /**
44
- * Register OPTIONS route on the given path (default "") for the given controller.
45
- */
46
- export const OPTIONS = (path = "") => _Route({
47
- method: "OPTIONS",
48
- path,
49
- });
50
- /**
51
- * Register PATCH route on the given path (default "") for the given controller.
52
- */
53
- export const PATCH = (path = "") => _Route({
54
- method: "PATCH",
55
- path,
56
- });
57
- /**
58
- * Register HEAD route on the given path (default "") for the given controller.
59
- */
60
- export const HEAD = (path = "") => _Route({
61
- method: "HEAD",
62
- path,
63
- });
64
- /**
65
- * Register a middleware route on the given path (default "") for the given controller.
66
- */
67
- export const Middleware = (path = "") => _Route({
68
- method: "USE",
69
- path,
70
- });
71
- /**
72
- * Given a class constructor, fetch all the routes attached.
73
- */
74
- export function _getRoutes(ctor) {
75
- var _a;
76
- return (_a = _routeStore.get(ctor)) !== null && _a !== void 0 ? _a : [];
77
- }
@@ -1,68 +0,0 @@
1
- /**
2
- * Enum of every valid HTTP status code mapped to a specific enum member.
3
- *
4
- * @see {@link ResponseEntity}
5
- */
6
- export declare enum HttpStatus {
7
- CONTINUE = 100,
8
- SWITCHING_PROTOCOLS = 101,
9
- PROCESSING = 102,
10
- EARLY_HINTS = 103,
11
- OK = 200,
12
- CREATED = 201,
13
- ACCEPTED = 202,
14
- NON_AUTHORITATIVE_INFORMATION = 203,
15
- NO_CONTENT = 204,
16
- RESET_CONTENT = 205,
17
- PARTIAL_CONTENT = 206,
18
- MULTI_STATUS = 207,
19
- ALREADY_REPORTED = 208,
20
- IM_USED = 226,
21
- MULTIPLE_CHOICES = 300,
22
- MOVED_PERMANENTLY = 301,
23
- FOUND = 302,
24
- SEE_OTHER = 303,
25
- NOT_MODIFIED = 304,
26
- TEMPORARY_REDIRECT = 307,
27
- PERMANENT_REDIRECT = 308,
28
- BAD_REQUEST = 400,
29
- UNAUTHORIZED = 401,
30
- PAYMENT_REQUIRED = 402,
31
- FORBIDDEN = 403,
32
- NOT_FOUND = 404,
33
- METHOD_NOT_ALLOWED = 405,
34
- NOT_ACCEPTABLE = 406,
35
- PROXY_AUTHENTICATION_REQUIRED = 407,
36
- REQUEST_TIMEOUT = 408,
37
- CONFLICT = 409,
38
- GONE = 410,
39
- LENGTH_REQUIRED = 411,
40
- PRECONDITION_FAILED = 412,
41
- PAYLOAD_TOO_LARGE = 413,
42
- URI_TOO_LONG = 414,
43
- UNSUPPORTED_MEDIA_TYPE = 415,
44
- REQUESTED_RANGE_NOT_SATISFIABLE = 416,
45
- EXPECTATION_FAILED = 417,
46
- I_AM_A_TEAPOT = 418,
47
- UNPROCESSABLE_ENTITY = 422,
48
- LOCKED = 423,
49
- FAILED_DEPENDENCY = 424,
50
- TOO_EARLY = 425,
51
- UPGRADE_REQUIRED = 426,
52
- PRECONDITION_REQUIRED = 428,
53
- TOO_MANY_REQUESTS = 429,
54
- REQUEST_HEADER_FIELDS_TOO_LARGE = 431,
55
- UNAVAILABLE_FOR_LEGAL_REASONS = 451,
56
- INTERNAL_SERVER_ERROR = 500,
57
- NOT_IMPLEMENTED = 501,
58
- BAD_GATEWAY = 502,
59
- SERVICE_UNAVAILABLE = 503,
60
- GATEWAY_TIMEOUT = 504,
61
- HTTP_VERSION_NOT_SUPPORTED = 505,
62
- VARIANT_ALSO_NEGOTIATES = 506,
63
- INSUFFICIENT_STORAGE = 507,
64
- LOOP_DETECTED = 508,
65
- BANDWIDTH_LIMIT_EXCEEDED = 509,
66
- NOT_EXTENDED = 510,
67
- NETWORK_AUTHENTICATION_REQUIRED = 511
68
- }
@@ -1,69 +0,0 @@
1
- /**
2
- * Enum of every valid HTTP status code mapped to a specific enum member.
3
- *
4
- * @see {@link ResponseEntity}
5
- */
6
- export var HttpStatus;
7
- (function (HttpStatus) {
8
- HttpStatus[HttpStatus["CONTINUE"] = 100] = "CONTINUE";
9
- HttpStatus[HttpStatus["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
10
- HttpStatus[HttpStatus["PROCESSING"] = 102] = "PROCESSING";
11
- HttpStatus[HttpStatus["EARLY_HINTS"] = 103] = "EARLY_HINTS";
12
- HttpStatus[HttpStatus["OK"] = 200] = "OK";
13
- HttpStatus[HttpStatus["CREATED"] = 201] = "CREATED";
14
- HttpStatus[HttpStatus["ACCEPTED"] = 202] = "ACCEPTED";
15
- HttpStatus[HttpStatus["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
16
- HttpStatus[HttpStatus["NO_CONTENT"] = 204] = "NO_CONTENT";
17
- HttpStatus[HttpStatus["RESET_CONTENT"] = 205] = "RESET_CONTENT";
18
- HttpStatus[HttpStatus["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
19
- HttpStatus[HttpStatus["MULTI_STATUS"] = 207] = "MULTI_STATUS";
20
- HttpStatus[HttpStatus["ALREADY_REPORTED"] = 208] = "ALREADY_REPORTED";
21
- HttpStatus[HttpStatus["IM_USED"] = 226] = "IM_USED";
22
- HttpStatus[HttpStatus["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
23
- HttpStatus[HttpStatus["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
24
- HttpStatus[HttpStatus["FOUND"] = 302] = "FOUND";
25
- HttpStatus[HttpStatus["SEE_OTHER"] = 303] = "SEE_OTHER";
26
- HttpStatus[HttpStatus["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
27
- HttpStatus[HttpStatus["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
28
- HttpStatus[HttpStatus["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
29
- HttpStatus[HttpStatus["BAD_REQUEST"] = 400] = "BAD_REQUEST";
30
- HttpStatus[HttpStatus["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
31
- HttpStatus[HttpStatus["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
32
- HttpStatus[HttpStatus["FORBIDDEN"] = 403] = "FORBIDDEN";
33
- HttpStatus[HttpStatus["NOT_FOUND"] = 404] = "NOT_FOUND";
34
- HttpStatus[HttpStatus["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
35
- HttpStatus[HttpStatus["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
36
- HttpStatus[HttpStatus["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
37
- HttpStatus[HttpStatus["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
38
- HttpStatus[HttpStatus["CONFLICT"] = 409] = "CONFLICT";
39
- HttpStatus[HttpStatus["GONE"] = 410] = "GONE";
40
- HttpStatus[HttpStatus["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
41
- HttpStatus[HttpStatus["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
42
- HttpStatus[HttpStatus["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
43
- HttpStatus[HttpStatus["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
44
- HttpStatus[HttpStatus["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
45
- HttpStatus[HttpStatus["REQUESTED_RANGE_NOT_SATISFIABLE"] = 416] = "REQUESTED_RANGE_NOT_SATISFIABLE";
46
- HttpStatus[HttpStatus["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
47
- HttpStatus[HttpStatus["I_AM_A_TEAPOT"] = 418] = "I_AM_A_TEAPOT";
48
- HttpStatus[HttpStatus["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
49
- HttpStatus[HttpStatus["LOCKED"] = 423] = "LOCKED";
50
- HttpStatus[HttpStatus["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
51
- HttpStatus[HttpStatus["TOO_EARLY"] = 425] = "TOO_EARLY";
52
- HttpStatus[HttpStatus["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED";
53
- HttpStatus[HttpStatus["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
54
- HttpStatus[HttpStatus["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
55
- HttpStatus[HttpStatus["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
56
- HttpStatus[HttpStatus["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
57
- HttpStatus[HttpStatus["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
58
- HttpStatus[HttpStatus["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
59
- HttpStatus[HttpStatus["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
60
- HttpStatus[HttpStatus["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
61
- HttpStatus[HttpStatus["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
62
- HttpStatus[HttpStatus["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
63
- HttpStatus[HttpStatus["VARIANT_ALSO_NEGOTIATES"] = 506] = "VARIANT_ALSO_NEGOTIATES";
64
- HttpStatus[HttpStatus["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
65
- HttpStatus[HttpStatus["LOOP_DETECTED"] = 508] = "LOOP_DETECTED";
66
- HttpStatus[HttpStatus["BANDWIDTH_LIMIT_EXCEEDED"] = 509] = "BANDWIDTH_LIMIT_EXCEEDED";
67
- HttpStatus[HttpStatus["NOT_EXTENDED"] = 510] = "NOT_EXTENDED";
68
- HttpStatus[HttpStatus["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
69
- })(HttpStatus || (HttpStatus = {}));
@@ -1 +0,0 @@
1
- export * from "./http";
@@ -1 +0,0 @@
1
- export * from "./http";
@@ -1,10 +0,0 @@
1
- import { HttpStatus } from "../enum";
2
- /**
3
- * Ensure that you define a middleware that can handle this error.
4
- *
5
- * @see {@link Sapling.loadResponseStatusErrorMiddleware}
6
- */
7
- export declare class ResponseStatusError extends Error {
8
- readonly status: HttpStatus;
9
- constructor(status: HttpStatus, message?: string);
10
- }
@@ -1,17 +0,0 @@
1
- import { HttpStatus } from "../enum";
2
- /**
3
- * Ensure that you define a middleware that can handle this error.
4
- *
5
- * @see {@link Sapling.loadResponseStatusErrorMiddleware}
6
- */
7
- export class ResponseStatusError extends Error {
8
- constructor(status, message) {
9
- super(message !== null && message !== void 0 ? message : "Something went wrong.");
10
- this.status = status;
11
- Object.setPrototypeOf(this, new.target.prototype);
12
- this.name = `HttpError(${HttpStatus[status]})`;
13
- if (Error.captureStackTrace) {
14
- Error.captureStackTrace(this, ResponseStatusError);
15
- }
16
- }
17
- }
@@ -1 +0,0 @@
1
- export declare const getControllers: () => any;
@@ -1,5 +0,0 @@
1
- // @ts-expect-error
2
- import * as controllers from "**/*.controller.ts";
3
- export const getControllers = () => {
4
- return controllers;
5
- };
@@ -1,4 +0,0 @@
1
- export * from "./redirect";
2
- export * from "./response";
3
- export * from "./error";
4
- export * from "./sapling";
@@ -1,4 +0,0 @@
1
- export * from "./redirect";
2
- export * from "./response";
3
- export * from "./error";
4
- export * from "./sapling";
@@ -1,14 +0,0 @@
1
- /**
2
- * Generic HTTP redirect wrapped modeled after Spring's `RedirectView`.
3
- *
4
- * You can either return `new RedirectView(url)` or `RedirectView.redirect(url)` inside of a controller method.
5
- */
6
- export declare class RedirectView {
7
- _url: string;
8
- constructor(url: string);
9
- getUrl(): string;
10
- /**
11
- * Instantiate `RedirectView` with the given `url`.
12
- */
13
- static redirect(url: string): RedirectView;
14
- }
@@ -1,19 +0,0 @@
1
- /**
2
- * Generic HTTP redirect wrapped modeled after Spring's `RedirectView`.
3
- *
4
- * You can either return `new RedirectView(url)` or `RedirectView.redirect(url)` inside of a controller method.
5
- */
6
- export class RedirectView {
7
- constructor(url) {
8
- this._url = url;
9
- }
10
- getUrl() {
11
- return this._url;
12
- }
13
- /**
14
- * Instantiate `RedirectView` with the given `url`.
15
- */
16
- static redirect(url) {
17
- return new RedirectView(url);
18
- }
19
- }
@@ -1,68 +0,0 @@
1
- import { HttpHeaders } from "../types";
2
- /**
3
- * Generic HTTP response wrapper modeled after Spring's `ResponseEntity`.
4
- *
5
- * Provides status code, headers, and an optional typed body.
6
- * The body is serialized through `Spring.serialize`.
7
- *
8
- * @typeParam T - the type of the response body
9
- */
10
- export declare class ResponseEntity<T> {
11
- private _statusCode;
12
- private _headers;
13
- private _body;
14
- constructor(body: T, headers?: HttpHeaders, statusCode?: number);
15
- /**
16
- * Create a builder with a 200 status code.
17
- *
18
- * @example```ts
19
- * return ResponseEntity.ok().body({ success: true });
20
- * ```
21
- */
22
- static ok(): ResponseEntityBuilder;
23
- /**
24
- * Create a builder with a custom status code.
25
- *
26
- * @example```ts
27
- * return ResponseEntity.status(HttpStatus.BAD_REQUEST).body({ success: false });
28
- * ```
29
- *
30
- * @see {@link HttpStatus}
31
- */
32
- static status(statusCode: number): ResponseEntityBuilder;
33
- /**
34
- * Return status code.
35
- */
36
- getStatusCode(): number;
37
- /**
38
- * Return headers.
39
- */
40
- getHeaders(): HttpHeaders;
41
- /**
42
- * Return the response body.
43
- */
44
- getBody(): T;
45
- }
46
- /**
47
- * Builder for {@link ResponseEntity}.
48
- *
49
- * Forces the status code to be set first, then headers and body,
50
- * ensuring type safety when constructing the response.
51
- */
52
- export declare class ResponseEntityBuilder {
53
- private _statusCode;
54
- private _headers;
55
- constructor(statusCode: number);
56
- /**
57
- * Set all headers as an object with keys and values.
58
- */
59
- headers(headers: HttpHeaders): this;
60
- /**
61
- * Add/override a single key and value to the headers.
62
- */
63
- setHeader(key: string, value: string): this;
64
- /**
65
- * Set the response body.
66
- */
67
- body<T>(body: T): ResponseEntity<T>;
68
- }
@@ -1,88 +0,0 @@
1
- /**
2
- * Generic HTTP response wrapper modeled after Spring's `ResponseEntity`.
3
- *
4
- * Provides status code, headers, and an optional typed body.
5
- * The body is serialized through `Spring.serialize`.
6
- *
7
- * @typeParam T - the type of the response body
8
- */
9
- export class ResponseEntity {
10
- constructor(body, headers = {}, statusCode = 200) {
11
- this._headers = {};
12
- this._body = body;
13
- this._headers = headers;
14
- this._statusCode = statusCode;
15
- }
16
- /**
17
- * Create a builder with a 200 status code.
18
- *
19
- * @example```ts
20
- * return ResponseEntity.ok().body({ success: true });
21
- * ```
22
- */
23
- static ok() {
24
- return new ResponseEntityBuilder(200);
25
- }
26
- /**
27
- * Create a builder with a custom status code.
28
- *
29
- * @example```ts
30
- * return ResponseEntity.status(HttpStatus.BAD_REQUEST).body({ success: false });
31
- * ```
32
- *
33
- * @see {@link HttpStatus}
34
- */
35
- static status(statusCode) {
36
- return new ResponseEntityBuilder(statusCode);
37
- }
38
- /**
39
- * Return status code.
40
- */
41
- getStatusCode() {
42
- return this._statusCode;
43
- }
44
- /**
45
- * Return headers.
46
- */
47
- getHeaders() {
48
- return this._headers;
49
- }
50
- /**
51
- * Return the response body.
52
- */
53
- getBody() {
54
- return this._body;
55
- }
56
- }
57
- /**
58
- * Builder for {@link ResponseEntity}.
59
- *
60
- * Forces the status code to be set first, then headers and body,
61
- * ensuring type safety when constructing the response.
62
- */
63
- export class ResponseEntityBuilder {
64
- constructor(statusCode) {
65
- this._headers = {};
66
- this._statusCode = statusCode;
67
- }
68
- /**
69
- * Set all headers as an object with keys and values.
70
- */
71
- headers(headers) {
72
- this._headers = headers;
73
- return this;
74
- }
75
- /**
76
- * Add/override a single key and value to the headers.
77
- */
78
- setHeader(key, value) {
79
- this._headers[key] = value;
80
- return this;
81
- }
82
- /**
83
- * Set the response body.
84
- */
85
- body(body) {
86
- return new ResponseEntity(body, this._headers, this._statusCode);
87
- }
88
- }
@@ -1,100 +0,0 @@
1
- import e, { Router } from "express";
2
- import { Class, ExpressMiddlewareFn } from "../types";
3
- import { ResponseStatusError } from "./error";
4
- /**
5
- * Collection of utility functions which are essential for Sapling to function.
6
- */
7
- export declare class Sapling {
8
- /**
9
- * If you would prefer to manually resolve your controllers instead, call resolve
10
- * on the controller class.
11
- *
12
- * @example```ts
13
- * import { Sapling } from "@tahminator/sapling";
14
- * import TestController from "./path/to/test.controller";
15
- *
16
- * const app = express();
17
- *
18
- * const router = Sapling.resolve(TestController);
19
- * app.use(router);
20
- * ```
21
- */
22
- static resolve<TClass>(this: void, clazz: Class<TClass>): Router;
23
- /**
24
- * Register this function as a middleware in order to utilize Sapling's `deserialize` function.
25
- *
26
- * @example```ts
27
- * import { Sapling } from "@tahminator/sapling";
28
- * import express from "express";
29
- *
30
- * const app = express();
31
- *
32
- * app.use(Sapling.json());
33
- * ```
34
- */
35
- static json(this: void): ExpressMiddlewareFn;
36
- /**
37
- * Register your application with all the necessary middlewares and logics for Sapling to function.
38
- *
39
- * @example```ts
40
- * import { Sapling } from "@tahminator/sapling";
41
- * import express from "express";
42
- *
43
- * const app = express();
44
- *
45
- * app.registerApp(app);
46
- * ```
47
- */
48
- static registerApp(app: e.Express): void;
49
- /**
50
- * Register a middleware that will handle {@link ResponseStatusError}.
51
- *
52
- * This middleware will chain to the next middleware if it does not catch {@link ResponseStatusError}.
53
- * You may still define middleware to handle all other errors in a separate `app.use` call.
54
- *
55
- * @example
56
- * ```ts
57
- * import express from "express";
58
- * import { Sapling } from "@tahminator/sapling";
59
- *
60
- * const app = express();
61
- *
62
- * Sapling.loadResponseStatusErrorMiddleware(app, (err, req, res, next) => {
63
- * // `err` is guaranteed to be of type ResponseStatusError
64
- * res.status(err.status).json({
65
- * success: false,
66
- * message: err.message,
67
- * });
68
- * });
69
- * ```
70
- */
71
- static loadResponseStatusErrorMiddleware(this: void, app: e.Express, fn: (err: ResponseStatusError, request: e.Request, response: e.Response, next: e.NextFunction) => void): void;
72
- /**
73
- * Serialize a value into a JSON string.
74
- *
75
- * This function is used in {@link ResponseEntity} to serialize the `body`.
76
- *
77
- * Use `setSerializeFn` to override underlying implementation.
78
- *
79
- * @defaultValue `JSON.stringify`
80
- */
81
- static serialize(this: void, value: any): string;
82
- /**
83
- * Replace the function used for `serialize`.
84
- */
85
- static setSerializeFn(this: void, fn: (value: any) => string): void;
86
- /**
87
- * De-serialize a JSON string back to a JavaScript object.
88
- *
89
- * This function is used to de-serialize a string into a `body`.
90
- *
91
- * Use `setDeserializeFn` to override underlying implementation.
92
- *
93
- * @defaultValue `JSON.parse`
94
- */
95
- static deserialize<T = any>(this: void, value: string): T;
96
- /**
97
- * Replace the function used for `deserialize`
98
- */
99
- static setDeserializeFn(this: void, fn: (value: string) => any): void;
100
- }
@@ -1,153 +0,0 @@
1
- import e from "express";
2
- import { _ControllerRegistry } from "../annotation/controller";
3
- import { ResponseStatusError } from "./error";
4
- const settings = {
5
- serialize: JSON.stringify,
6
- deserialize: JSON.parse,
7
- };
8
- /**
9
- * Collection of utility functions which are essential for Sapling to function.
10
- */
11
- export class Sapling {
12
- /**
13
- * If you would prefer to manually resolve your controllers instead, call resolve
14
- * on the controller class.
15
- *
16
- * @example```ts
17
- * import { Sapling } from "@tahminator/sapling";
18
- * import TestController from "./path/to/test.controller";
19
- *
20
- * const app = express();
21
- *
22
- * const router = Sapling.resolve(TestController);
23
- * app.use(router);
24
- * ```
25
- */
26
- static resolve(clazz) {
27
- const router = _ControllerRegistry.get(clazz);
28
- if (!router) {
29
- throw new Error("Controller cannot be found");
30
- }
31
- return router;
32
- }
33
- /**
34
- * Register this function as a middleware in order to utilize Sapling's `deserialize` function.
35
- *
36
- * @example```ts
37
- * import { Sapling } from "@tahminator/sapling";
38
- * import express from "express";
39
- *
40
- * const app = express();
41
- *
42
- * app.use(Sapling.json());
43
- * ```
44
- */
45
- static json() {
46
- return (request, _response, next) => {
47
- try {
48
- if (!request.body) {
49
- return next();
50
- }
51
- if (request.headers["content-type"] !== "application/json") {
52
- return next();
53
- }
54
- if (typeof request.body === "string") {
55
- request.body = Sapling.deserialize(request.body);
56
- }
57
- else if (typeof request.body === "object") {
58
- // override `express.json()` middleware, if ran, and use Sapling's `deserialize` instead.
59
- const raw = JSON.stringify(request.body);
60
- request.body = Sapling.deserialize(raw);
61
- }
62
- next();
63
- }
64
- catch (err) {
65
- next(err);
66
- }
67
- };
68
- }
69
- /**
70
- * Register your application with all the necessary middlewares and logics for Sapling to function.
71
- *
72
- * @example```ts
73
- * import { Sapling } from "@tahminator/sapling";
74
- * import express from "express";
75
- *
76
- * const app = express();
77
- *
78
- * app.registerApp(app);
79
- * ```
80
- */
81
- static registerApp(app) {
82
- app.use(e.text({ type: "application/json" }));
83
- app.use(Sapling.json());
84
- }
85
- /**
86
- * Register a middleware that will handle {@link ResponseStatusError}.
87
- *
88
- * This middleware will chain to the next middleware if it does not catch {@link ResponseStatusError}.
89
- * You may still define middleware to handle all other errors in a separate `app.use` call.
90
- *
91
- * @example
92
- * ```ts
93
- * import express from "express";
94
- * import { Sapling } from "@tahminator/sapling";
95
- *
96
- * const app = express();
97
- *
98
- * Sapling.loadResponseStatusErrorMiddleware(app, (err, req, res, next) => {
99
- * // `err` is guaranteed to be of type ResponseStatusError
100
- * res.status(err.status).json({
101
- * success: false,
102
- * message: err.message,
103
- * });
104
- * });
105
- * ```
106
- */
107
- static loadResponseStatusErrorMiddleware(app, fn) {
108
- app.use(((err, req, res, next) => {
109
- if (err instanceof ResponseStatusError) {
110
- fn(err, req, res, next);
111
- }
112
- else {
113
- next(err);
114
- }
115
- }));
116
- }
117
- /**
118
- * Serialize a value into a JSON string.
119
- *
120
- * This function is used in {@link ResponseEntity} to serialize the `body`.
121
- *
122
- * Use `setSerializeFn` to override underlying implementation.
123
- *
124
- * @defaultValue `JSON.stringify`
125
- */
126
- static serialize(value) {
127
- return settings.serialize(value);
128
- }
129
- /**
130
- * Replace the function used for `serialize`.
131
- */
132
- static setSerializeFn(fn) {
133
- settings.serialize = fn;
134
- }
135
- /**
136
- * De-serialize a JSON string back to a JavaScript object.
137
- *
138
- * This function is used to de-serialize a string into a `body`.
139
- *
140
- * Use `setDeserializeFn` to override underlying implementation.
141
- *
142
- * @defaultValue `JSON.parse`
143
- */
144
- static deserialize(value) {
145
- return settings.deserialize(value);
146
- }
147
- /**
148
- * Replace the function used for `deserialize`
149
- */
150
- static setDeserializeFn(fn) {
151
- settings.deserialize = fn;
152
- }
153
- }
@@ -1,4 +0,0 @@
1
- /**
2
- * Default Express.js 404 error page, as a string.
3
- */
4
- export declare const Html404ErrorPage: (error: string) => string;
@@ -1,15 +0,0 @@
1
- /**
2
- * Default Express.js 404 error page, as a string.
3
- */
4
- export const Html404ErrorPage = (error) => `
5
- <!DOCTYPE html>
6
- <html lang="en">
7
- <head>
8
- <meta charset="utf-8">
9
- <title>Error</title>
10
- </head>
11
- <body>
12
- <pre>${error}</pre>
13
- </body>
14
- </html>
15
- `;
@@ -1 +0,0 @@
1
- export * from "./404";
@@ -1 +0,0 @@
1
- export * from "./404";
@@ -1,5 +0,0 @@
1
- export * from "./html";
2
- export * from "./annotation";
3
- export * from "./helper";
4
- export * from "./enum";
5
- export * from "./types";
package/dist/src/index.js DELETED
@@ -1,5 +0,0 @@
1
- export * from "./html";
2
- export * from "./annotation";
3
- export * from "./helper";
4
- export * from "./enum";
5
- export * from "./types";
@@ -1,21 +0,0 @@
1
- import { NextFunction, Request, Response } from "express";
2
- export type ExpressRouterMethodKey = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" | "HEAD" | "USE";
3
- export type ExpressRouterMethods = Lowercase<ExpressRouterMethodKey>;
4
- export declare const methodResolve: Record<ExpressRouterMethodKey, ExpressRouterMethods>;
5
- export type RouteDefinition = {
6
- /**
7
- * Express.js HTTP method.
8
- */
9
- method: ExpressRouterMethodKey;
10
- /**
11
- * The path to define the route on. Can be a string or RegExp.
12
- */
13
- path: string | RegExp;
14
- /**
15
- * The name of the function the `@Route` annotation was applied on.
16
- */
17
- fnName: string;
18
- };
19
- export type Class<T> = new (...args: any[]) => T;
20
- export type HttpHeaders = Record<string, string>;
21
- export type ExpressMiddlewareFn = ($1: Request, $2: Response, $3: NextFunction) => void;
package/dist/src/types.js DELETED
@@ -1,11 +0,0 @@
1
- // all exported types
2
- export const methodResolve = {
3
- GET: "get",
4
- PUT: "put",
5
- POST: "post",
6
- DELETE: "delete",
7
- OPTIONS: "options",
8
- PATCH: "patch",
9
- HEAD: "head",
10
- USE: "use",
11
- };