@tahminator/sapling 1.5.16 → 1.5.17

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 (45) hide show
  1. package/dist/eslint.config.d.ts +2 -0
  2. package/dist/eslint.config.js +38 -0
  3. package/dist/exclusions.d.ts +5 -0
  4. package/dist/exclusions.js +6 -0
  5. package/dist/index.d.ts +1 -0
  6. package/dist/index.js +1 -0
  7. package/dist/lib/weakmap.d.ts +15 -0
  8. package/dist/lib/weakmap.js +77 -0
  9. package/dist/src/annotation/controller.d.ts +21 -0
  10. package/dist/src/annotation/controller.js +78 -0
  11. package/dist/src/annotation/index.d.ts +4 -0
  12. package/dist/src/annotation/index.js +4 -0
  13. package/dist/src/annotation/injectable.d.ts +25 -0
  14. package/dist/src/annotation/injectable.js +69 -0
  15. package/dist/src/annotation/middleware.d.ts +9 -0
  16. package/dist/src/annotation/middleware.js +11 -0
  17. package/dist/src/annotation/route.d.ts +47 -0
  18. package/dist/src/annotation/route.js +77 -0
  19. package/dist/src/enum/http.d.ts +68 -0
  20. package/dist/src/enum/http.js +71 -0
  21. package/dist/src/enum/index.d.ts +1 -0
  22. package/dist/src/enum/index.js +1 -0
  23. package/dist/src/helper/error.d.ts +10 -0
  24. package/dist/src/helper/error.js +19 -0
  25. package/dist/src/helper/importer.d.ts +1 -0
  26. package/dist/src/helper/importer.js +6 -0
  27. package/dist/src/helper/index.d.ts +4 -0
  28. package/dist/src/helper/index.js +4 -0
  29. package/dist/src/helper/redirect.d.ts +14 -0
  30. package/dist/src/helper/redirect.js +19 -0
  31. package/dist/src/helper/response.d.ts +68 -0
  32. package/dist/src/helper/response.js +90 -0
  33. package/dist/src/helper/sapling.d.ts +101 -0
  34. package/dist/src/helper/sapling.js +153 -0
  35. package/dist/src/html/404.d.ts +4 -0
  36. package/dist/src/html/404.js +15 -0
  37. package/dist/src/html/index.d.ts +1 -0
  38. package/dist/src/html/index.js +1 -0
  39. package/dist/src/index.d.ts +5 -0
  40. package/dist/src/index.js +5 -0
  41. package/dist/src/types.d.ts +21 -0
  42. package/dist/src/types.js +11 -0
  43. package/dist/vite.config.d.ts +2 -0
  44. package/dist/vite.config.js +17 -0
  45. package/package.json +2 -2
@@ -0,0 +1,2 @@
1
+ declare const _default: import("typescript-eslint").FlatConfig.ConfigArray;
2
+ export default _default;
@@ -0,0 +1,38 @@
1
+ import js from "@eslint/js";
2
+ import perfectionist from "eslint-plugin-perfectionist";
3
+ import globals from "globals";
4
+ import tseslint from "typescript-eslint";
5
+ export default tseslint.config(js.configs.recommended, ...tseslint.configs.recommended, { ignores: ["dist", "example"] }, {
6
+ plugins: {
7
+ perfectionist,
8
+ },
9
+ rules: {
10
+ "perfectionist/sort-imports": "error",
11
+ },
12
+ }, {
13
+ files: ["**/*.{ts,tsx}"],
14
+ languageOptions: {
15
+ ecmaVersion: 2020,
16
+ globals: globals["node"],
17
+ },
18
+ rules: {
19
+ "@typescript-eslint/no-namespace": ["off"],
20
+ "@typescript-eslint/no-non-null-assertion": ["error"],
21
+ "@typescript-eslint/no-empty-object-type": ["off"],
22
+ "@typescript-eslint/no-unused-vars": [
23
+ "error",
24
+ {
25
+ argsIgnorePattern: "^_",
26
+ varsIgnorePattern: "^_",
27
+ caughtErrorsIgnorePattern: "^_",
28
+ },
29
+ ],
30
+ "@typescript-eslint/consistent-type-imports": [
31
+ "error",
32
+ {
33
+ prefer: "type-imports",
34
+ fixStyle: "separate-type-imports",
35
+ },
36
+ ],
37
+ },
38
+ }, {});
@@ -0,0 +1,5 @@
1
+ /**
2
+ * See https://github.com/tahminator/sapling/blob/main/.github/scripts/src/test/index.ts
3
+ * for test exclusion usages.
4
+ */
5
+ export declare const exclusions: string[];
@@ -0,0 +1,6 @@
1
+ /**
2
+ * See https://github.com/tahminator/sapling/blob/main/.github/scripts/src/test/index.ts
3
+ * for test exclusion usages.
4
+ */
5
+ const baseDir = "src";
6
+ export const exclusions = [`${baseDir}/**/*.test.ts`];
@@ -0,0 +1 @@
1
+ export * from "./src";
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./src";
@@ -0,0 +1,15 @@
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
+ }
@@ -0,0 +1,77 @@
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;
@@ -0,0 +1,21 @@
1
+ import { Router } from "express";
2
+ import type { 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 {};
@@ -0,0 +1,78 @@
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
+ /* eslint-disable @typescript-eslint/no-unsafe-function-type */
11
+ /* eslint-disable @typescript-eslint/no-explicit-any */
12
+ import { Router } from "express";
13
+ import { ResponseEntity, RedirectView } from "../helper";
14
+ import { Sapling } from "../helper/sapling";
15
+ import { Html404ErrorPage } from "../html/404";
16
+ import { methodResolve } from "../types";
17
+ import { _InjectableDeps, _resolve } from "./injectable";
18
+ import { _getRoutes } from "./route";
19
+ export const _ControllerRegistry = new WeakMap();
20
+ /**
21
+ * Registers a class as an HTTP controller and registers its routes.
22
+ *
23
+ * @param [prefix] Optional URL prefix applied to all routes in the controller. Defaults to "".
24
+ * @param [deps] Optional array of dependencies to be injected into the constructor that are `@Injectable`
25
+ */
26
+ export function Controller({ prefix = "", deps = [], } = {}) {
27
+ return (target) => {
28
+ const targetClass = target;
29
+ const router = Router();
30
+ const routes = _getRoutes(target);
31
+ const usedRoutes = new Set();
32
+ _InjectableDeps.set(targetClass, deps);
33
+ const controllerInstance = _resolve(targetClass);
34
+ for (const { method, path, fnName } of routes) {
35
+ const fn = controllerInstance[fnName];
36
+ if (typeof fn !== "function")
37
+ continue;
38
+ // When path is a RegExp, use it directly without prefix
39
+ // When path is a string, prepend the prefix
40
+ const fp = path instanceof RegExp ? path : prefix + path;
41
+ const routeKey = method + " " + (path instanceof RegExp ? path.source : fp);
42
+ // Only check for duplicates on non-middleware routes
43
+ // Middleware (USE) can have duplicate paths, and different HTTP methods can share paths
44
+ if (method !== "USE" && usedRoutes.has(routeKey)) {
45
+ throw new Error(`Duplicate route [${method}] "${path instanceof RegExp ? path.source : fp}" detected in controller "${target.name}"`);
46
+ }
47
+ if (method !== "USE") {
48
+ usedRoutes.add(routeKey);
49
+ }
50
+ const methodName = methodResolve[method];
51
+ router[methodName](fp, (request, response, next) => __awaiter(this, void 0, void 0, function* () {
52
+ const result = yield fn.bind(controllerInstance)(request, response, next);
53
+ // Middleware (USE) should not send responses, just call next()
54
+ if (method === "USE") {
55
+ return;
56
+ }
57
+ if (result instanceof ResponseEntity) {
58
+ response
59
+ .contentType("application/json")
60
+ .status(result.getStatusCode())
61
+ .set(result.getHeaders())
62
+ .send(Sapling.serialize(result.getBody()));
63
+ return;
64
+ }
65
+ if (result instanceof RedirectView) {
66
+ response.redirect(result.getUrl());
67
+ return;
68
+ }
69
+ if (!response.writableEnded) {
70
+ response
71
+ .status(404)
72
+ .send(Html404ErrorPage(`Cannot ${methodName.toUpperCase()} ${path instanceof RegExp ? path.source : fp}`));
73
+ }
74
+ }));
75
+ }
76
+ _ControllerRegistry.set(targetClass, router);
77
+ };
78
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./controller";
2
+ export * from "./injectable";
3
+ export * from "./route";
4
+ export * from "./middleware";
@@ -0,0 +1,4 @@
1
+ export * from "./controller";
2
+ export * from "./injectable";
3
+ export * from "./route";
4
+ export * from "./middleware";
@@ -0,0 +1,25 @@
1
+ import type { Class } from "../types";
2
+ import { IterableWeakMap } from "../../lib/weakmap";
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;
@@ -0,0 +1,69 @@
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
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
37
+ inDegree.set(node, inDegree.get(node) + 1);
38
+ if (!graph.has(dep))
39
+ graph.set(dep, []);
40
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
41
+ graph.get(dep).push(node);
42
+ });
43
+ });
44
+ const queue = [];
45
+ inDegree.forEach((deg, node) => {
46
+ if (deg === 0)
47
+ queue.push(node);
48
+ });
49
+ while (queue.length) {
50
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
51
+ const current = queue.shift();
52
+ if (!_InjectableRegistry.get(current)) {
53
+ const deps = _InjectableDeps.get(current) || [];
54
+ const params = deps.map((dep) => _InjectableRegistry.get(dep));
55
+ const instance = new current(...params);
56
+ _InjectableRegistry.set(current, instance);
57
+ }
58
+ (graph.get(current) || []).forEach((neighbor) => {
59
+ var _a;
60
+ inDegree.set(neighbor, ((_a = inDegree.get(neighbor)) !== null && _a !== void 0 ? _a : 0) - 1);
61
+ if (inDegree.get(neighbor) === 0)
62
+ queue.push(neighbor);
63
+ });
64
+ }
65
+ if (!_InjectableRegistry.get(ctor)) {
66
+ throw new Error("Circular dependency detected or injectable not registered");
67
+ }
68
+ return _InjectableRegistry.get(ctor);
69
+ }
@@ -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
+ }
@@ -0,0 +1,47 @@
1
+ import type { RouteDefinition, ExpressRouterMethodKey } from "../types";
2
+ type OptionalStrOrRegExp = string | RegExp | undefined;
3
+ /**
4
+ * Custom annotation that will store all routes inside of a map,
5
+ * which can then be used to initialize all the routes to the router.
6
+ */
7
+ export declare function _Route({ method, path, }: {
8
+ method: ExpressRouterMethodKey;
9
+ path: OptionalStrOrRegExp;
10
+ }): MethodDecorator;
11
+ /**
12
+ * Register GET route on the given path (default "") for the given controller.
13
+ */
14
+ export declare const GET: (path?: OptionalStrOrRegExp) => MethodDecorator;
15
+ /**
16
+ * Register POST route on the given path (default "") for the given controller.
17
+ */
18
+ export declare const POST: (path?: OptionalStrOrRegExp) => MethodDecorator;
19
+ /**
20
+ * Register PUT route on the given path (default "") for the given controller.
21
+ */
22
+ export declare const PUT: (path?: OptionalStrOrRegExp) => MethodDecorator;
23
+ /**
24
+ * Register DELETE route on the given path (default "") for the given controller.
25
+ */
26
+ export declare const DELETE: (path?: OptionalStrOrRegExp) => MethodDecorator;
27
+ /**
28
+ * Register OPTIONS route on the given path (default "") for the given controller.
29
+ */
30
+ export declare const OPTIONS: (path?: OptionalStrOrRegExp) => MethodDecorator;
31
+ /**
32
+ * Register PATCH route on the given path (default "") for the given controller.
33
+ */
34
+ export declare const PATCH: (path?: OptionalStrOrRegExp) => MethodDecorator;
35
+ /**
36
+ * Register HEAD route on the given path (default "") for the given controller.
37
+ */
38
+ export declare const HEAD: (path?: OptionalStrOrRegExp) => MethodDecorator;
39
+ /**
40
+ * Register a middleware route on the given path (default "") for the given controller.
41
+ */
42
+ export declare const Middleware: (path?: OptionalStrOrRegExp) => MethodDecorator;
43
+ /**
44
+ * Given a class constructor, fetch all the routes attached.
45
+ */
46
+ export declare function _getRoutes(ctor: Function): readonly RouteDefinition[];
47
+ export {};
@@ -0,0 +1,77 @@
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
+ }
@@ -0,0 +1,68 @@
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
+ }
@@ -0,0 +1,71 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
2
+ import {} from "../helper";
3
+ /**
4
+ * Enum of every valid HTTP status code mapped to a specific enum member.
5
+ *
6
+ * @see {@link ResponseEntity}
7
+ */
8
+ export var HttpStatus;
9
+ (function (HttpStatus) {
10
+ HttpStatus[HttpStatus["CONTINUE"] = 100] = "CONTINUE";
11
+ HttpStatus[HttpStatus["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
12
+ HttpStatus[HttpStatus["PROCESSING"] = 102] = "PROCESSING";
13
+ HttpStatus[HttpStatus["EARLY_HINTS"] = 103] = "EARLY_HINTS";
14
+ HttpStatus[HttpStatus["OK"] = 200] = "OK";
15
+ HttpStatus[HttpStatus["CREATED"] = 201] = "CREATED";
16
+ HttpStatus[HttpStatus["ACCEPTED"] = 202] = "ACCEPTED";
17
+ HttpStatus[HttpStatus["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
18
+ HttpStatus[HttpStatus["NO_CONTENT"] = 204] = "NO_CONTENT";
19
+ HttpStatus[HttpStatus["RESET_CONTENT"] = 205] = "RESET_CONTENT";
20
+ HttpStatus[HttpStatus["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
21
+ HttpStatus[HttpStatus["MULTI_STATUS"] = 207] = "MULTI_STATUS";
22
+ HttpStatus[HttpStatus["ALREADY_REPORTED"] = 208] = "ALREADY_REPORTED";
23
+ HttpStatus[HttpStatus["IM_USED"] = 226] = "IM_USED";
24
+ HttpStatus[HttpStatus["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
25
+ HttpStatus[HttpStatus["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
26
+ HttpStatus[HttpStatus["FOUND"] = 302] = "FOUND";
27
+ HttpStatus[HttpStatus["SEE_OTHER"] = 303] = "SEE_OTHER";
28
+ HttpStatus[HttpStatus["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
29
+ HttpStatus[HttpStatus["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
30
+ HttpStatus[HttpStatus["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
31
+ HttpStatus[HttpStatus["BAD_REQUEST"] = 400] = "BAD_REQUEST";
32
+ HttpStatus[HttpStatus["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
33
+ HttpStatus[HttpStatus["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
34
+ HttpStatus[HttpStatus["FORBIDDEN"] = 403] = "FORBIDDEN";
35
+ HttpStatus[HttpStatus["NOT_FOUND"] = 404] = "NOT_FOUND";
36
+ HttpStatus[HttpStatus["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
37
+ HttpStatus[HttpStatus["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
38
+ HttpStatus[HttpStatus["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
39
+ HttpStatus[HttpStatus["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
40
+ HttpStatus[HttpStatus["CONFLICT"] = 409] = "CONFLICT";
41
+ HttpStatus[HttpStatus["GONE"] = 410] = "GONE";
42
+ HttpStatus[HttpStatus["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
43
+ HttpStatus[HttpStatus["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
44
+ HttpStatus[HttpStatus["PAYLOAD_TOO_LARGE"] = 413] = "PAYLOAD_TOO_LARGE";
45
+ HttpStatus[HttpStatus["URI_TOO_LONG"] = 414] = "URI_TOO_LONG";
46
+ HttpStatus[HttpStatus["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
47
+ HttpStatus[HttpStatus["REQUESTED_RANGE_NOT_SATISFIABLE"] = 416] = "REQUESTED_RANGE_NOT_SATISFIABLE";
48
+ HttpStatus[HttpStatus["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
49
+ HttpStatus[HttpStatus["I_AM_A_TEAPOT"] = 418] = "I_AM_A_TEAPOT";
50
+ HttpStatus[HttpStatus["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
51
+ HttpStatus[HttpStatus["LOCKED"] = 423] = "LOCKED";
52
+ HttpStatus[HttpStatus["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
53
+ HttpStatus[HttpStatus["TOO_EARLY"] = 425] = "TOO_EARLY";
54
+ HttpStatus[HttpStatus["UPGRADE_REQUIRED"] = 426] = "UPGRADE_REQUIRED";
55
+ HttpStatus[HttpStatus["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
56
+ HttpStatus[HttpStatus["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
57
+ HttpStatus[HttpStatus["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
58
+ HttpStatus[HttpStatus["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
59
+ HttpStatus[HttpStatus["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
60
+ HttpStatus[HttpStatus["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
61
+ HttpStatus[HttpStatus["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
62
+ HttpStatus[HttpStatus["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
63
+ HttpStatus[HttpStatus["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
64
+ HttpStatus[HttpStatus["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
65
+ HttpStatus[HttpStatus["VARIANT_ALSO_NEGOTIATES"] = 506] = "VARIANT_ALSO_NEGOTIATES";
66
+ HttpStatus[HttpStatus["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
67
+ HttpStatus[HttpStatus["LOOP_DETECTED"] = 508] = "LOOP_DETECTED";
68
+ HttpStatus[HttpStatus["BANDWIDTH_LIMIT_EXCEEDED"] = 509] = "BANDWIDTH_LIMIT_EXCEEDED";
69
+ HttpStatus[HttpStatus["NOT_EXTENDED"] = 510] = "NOT_EXTENDED";
70
+ HttpStatus[HttpStatus["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
71
+ })(HttpStatus || (HttpStatus = {}));
@@ -0,0 +1 @@
1
+ export * from "./http";
@@ -0,0 +1 @@
1
+ export * from "./http";