@tahminator/sapling 1.5.27 → 1.5.28
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.cjs +669 -0
- package/dist/index.d.cts +421 -0
- package/dist/index.d.mts +421 -0
- package/dist/index.mjs +621 -0
- package/package.json +11 -10
- package/dist/eslint.config.d.ts +0 -2
- package/dist/eslint.config.js +0 -38
- package/dist/exclusions.d.ts +0 -5
- package/dist/exclusions.js +0 -6
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/lib/weakmap.d.ts +0 -15
- package/dist/lib/weakmap.js +0 -77
- package/dist/src/__test__/first.d.ts +0 -6
- package/dist/src/__test__/first.js +0 -20
- package/dist/src/__test__/second.d.ts +0 -6
- package/dist/src/__test__/second.js +0 -20
- package/dist/src/annotation/controller.d.ts +0 -21
- package/dist/src/annotation/controller.js +0 -78
- package/dist/src/annotation/index.d.ts +0 -4
- package/dist/src/annotation/index.js +0 -4
- package/dist/src/annotation/injectable.d.ts +0 -25
- package/dist/src/annotation/injectable.js +0 -72
- package/dist/src/annotation/middleware.d.ts +0 -9
- package/dist/src/annotation/middleware.js +0 -11
- package/dist/src/annotation/route.d.ts +0 -47
- package/dist/src/annotation/route.js +0 -77
- package/dist/src/enum/http.d.ts +0 -68
- package/dist/src/enum/http.js +0 -71
- package/dist/src/enum/index.d.ts +0 -1
- package/dist/src/enum/index.js +0 -1
- package/dist/src/helper/error.d.ts +0 -10
- package/dist/src/helper/error.js +0 -19
- package/dist/src/helper/index.d.ts +0 -4
- package/dist/src/helper/index.js +0 -4
- package/dist/src/helper/redirect.d.ts +0 -14
- package/dist/src/helper/redirect.js +0 -19
- package/dist/src/helper/response.d.ts +0 -68
- package/dist/src/helper/response.js +0 -90
- package/dist/src/helper/sapling.d.ts +0 -101
- package/dist/src/helper/sapling.js +0 -153
- package/dist/src/html/404.d.ts +0 -4
- package/dist/src/html/404.js +0 -14
- package/dist/src/html/index.d.ts +0 -1
- package/dist/src/html/index.js +0 -1
- package/dist/src/index.d.ts +0 -5
- package/dist/src/index.js +0 -5
- package/dist/src/types.d.ts +0 -21
- package/dist/src/types.js +0 -11
- package/dist/vite.config.d.ts +0 -2
- package/dist/vite.config.js +0 -18
package/dist/eslint.config.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
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
|
-
}, {});
|
package/dist/exclusions.d.ts
DELETED
package/dist/exclusions.js
DELETED
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";
|
package/dist/lib/weakmap.d.ts
DELETED
|
@@ -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
|
-
}
|
package/dist/lib/weakmap.js
DELETED
|
@@ -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,20 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { Injectable } from "../annotation";
|
|
8
|
-
import { SecondaryMagicNumberService } from "./second";
|
|
9
|
-
/**
|
|
10
|
-
* Used to test circular imports
|
|
11
|
-
*/
|
|
12
|
-
let PrimaryMagicNumberService = class PrimaryMagicNumberService {
|
|
13
|
-
getN() {
|
|
14
|
-
return 5;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
PrimaryMagicNumberService = __decorate([
|
|
18
|
-
Injectable([SecondaryMagicNumberService])
|
|
19
|
-
], PrimaryMagicNumberService);
|
|
20
|
-
export { PrimaryMagicNumberService };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
import { Injectable } from "../annotation";
|
|
8
|
-
import { PrimaryMagicNumberService } from "./first";
|
|
9
|
-
/**
|
|
10
|
-
* Used to test circular imports
|
|
11
|
-
*/
|
|
12
|
-
let SecondaryMagicNumberService = class SecondaryMagicNumberService {
|
|
13
|
-
getN() {
|
|
14
|
-
return 4;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
SecondaryMagicNumberService = __decorate([
|
|
18
|
-
Injectable([PrimaryMagicNumberService])
|
|
19
|
-
], SecondaryMagicNumberService);
|
|
20
|
-
export { SecondaryMagicNumberService };
|
|
@@ -1,21 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,78 +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
|
-
/* 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
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
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;
|
|
@@ -1,72 +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
|
-
if (dep === undefined) {
|
|
36
|
-
throw new Error(`There is an @Injectable (${node.name}) which has a dependency that cannot be found. This is likely caused by a circular dependency.`);
|
|
37
|
-
}
|
|
38
|
-
inDegree.set(dep, inDegree.get(dep) || 0);
|
|
39
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
40
|
-
inDegree.set(node, inDegree.get(node) + 1);
|
|
41
|
-
if (!graph.has(dep))
|
|
42
|
-
graph.set(dep, []);
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
44
|
-
graph.get(dep).push(node);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
const queue = [];
|
|
48
|
-
inDegree.forEach((deg, node) => {
|
|
49
|
-
if (deg === 0)
|
|
50
|
-
queue.push(node);
|
|
51
|
-
});
|
|
52
|
-
while (queue.length) {
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
54
|
-
const current = queue.shift();
|
|
55
|
-
if (!_InjectableRegistry.get(current)) {
|
|
56
|
-
const deps = _InjectableDeps.get(current) || [];
|
|
57
|
-
const params = deps.map((dep) => _InjectableRegistry.get(dep));
|
|
58
|
-
const instance = new current(...params);
|
|
59
|
-
_InjectableRegistry.set(current, instance);
|
|
60
|
-
}
|
|
61
|
-
(graph.get(current) || []).forEach((neighbor) => {
|
|
62
|
-
var _a;
|
|
63
|
-
inDegree.set(neighbor, ((_a = inDegree.get(neighbor)) !== null && _a !== void 0 ? _a : 0) - 1);
|
|
64
|
-
if (inDegree.get(neighbor) === 0)
|
|
65
|
-
queue.push(neighbor);
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
if (!_InjectableRegistry.get(ctor)) {
|
|
69
|
-
throw new Error("Circular dependency detected or injectable not registered");
|
|
70
|
-
}
|
|
71
|
-
return _InjectableRegistry.get(ctor);
|
|
72
|
-
}
|
|
@@ -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,47 +0,0 @@
|
|
|
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 {};
|
|
@@ -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
|
-
}
|
package/dist/src/enum/http.d.ts
DELETED
|
@@ -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
|
-
}
|