@carno.js/core 0.2.3
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/LICENSE +674 -0
- package/dist/Carno.d.ts +65 -0
- package/dist/Carno.js +307 -0
- package/dist/Cheetah.d.ts +65 -0
- package/dist/Cheetah.js +307 -0
- package/dist/cache/bento-cache.driver.d.ts +13 -0
- package/dist/cache/bento-cache.driver.js +55 -0
- package/dist/cache/cache.service.d.ts +8 -0
- package/dist/cache/cache.service.js +6 -0
- package/dist/commons/decorators/Injectable.decorator.d.ts +20 -0
- package/dist/commons/decorators/Injectable.decorator.js +33 -0
- package/dist/commons/decorators/controller.decorator.d.ts +8 -0
- package/dist/commons/decorators/controller.decorator.js +22 -0
- package/dist/commons/decorators/http.decorators.d.ts +13 -0
- package/dist/commons/decorators/http.decorators.js +44 -0
- package/dist/commons/decorators/index.d.ts +5 -0
- package/dist/commons/decorators/index.js +21 -0
- package/dist/commons/decorators/inject.decorator.d.ts +1 -0
- package/dist/commons/decorators/inject.decorator.js +5 -0
- package/dist/commons/decorators/middleware.decorator.d.ts +2 -0
- package/dist/commons/decorators/middleware.decorator.js +30 -0
- package/dist/commons/decorators/service.decorator.d.ts +2 -0
- package/dist/commons/decorators/service.decorator.js +7 -0
- package/dist/commons/http-code.enum.d.ts +50 -0
- package/dist/commons/http-code.enum.js +54 -0
- package/dist/commons/index.d.ts +3 -0
- package/dist/commons/index.js +19 -0
- package/dist/commons/registries/ProviderControl.d.ts +77 -0
- package/dist/commons/registries/ProviderControl.js +112 -0
- package/dist/commons/registries/ProviderRegistry.d.ts +7 -0
- package/dist/commons/registries/ProviderRegistry.js +20 -0
- package/dist/constants.d.ts +7 -0
- package/dist/constants.js +10 -0
- package/dist/container/ContainerConfiguration.d.ts +45 -0
- package/dist/container/ContainerConfiguration.js +121 -0
- package/dist/container/DependencyResolver.d.ts +18 -0
- package/dist/container/DependencyResolver.js +81 -0
- package/dist/container/InjectorService.d.ts +34 -0
- package/dist/container/InjectorService.js +157 -0
- package/dist/container/MethodInvoker.d.ts +17 -0
- package/dist/container/MethodInvoker.js +69 -0
- package/dist/container/RouteResolver.d.ts +27 -0
- package/dist/container/RouteResolver.js +173 -0
- package/dist/container/container.d.ts +41 -0
- package/dist/container/container.js +71 -0
- package/dist/container/createContainer.d.ts +3 -0
- package/dist/container/createContainer.js +12 -0
- package/dist/container/createInjector.d.ts +2 -0
- package/dist/container/createInjector.js +7 -0
- package/dist/container/index.d.ts +6 -0
- package/dist/container/index.js +22 -0
- package/dist/container/middleware.resolver.d.ts +9 -0
- package/dist/container/middleware.resolver.js +35 -0
- package/dist/default-routes-carno.d.ts +3 -0
- package/dist/default-routes-carno.js +29 -0
- package/dist/default-routes-cheetah.d.ts +3 -0
- package/dist/default-routes-cheetah.js +29 -0
- package/dist/domain/CarnoClosure.d.ts +1 -0
- package/dist/domain/CarnoClosure.js +2 -0
- package/dist/domain/CarnoMiddleware.d.ts +5 -0
- package/dist/domain/CarnoMiddleware.js +2 -0
- package/dist/domain/CheetahClosure.d.ts +1 -0
- package/dist/domain/CheetahClosure.js +2 -0
- package/dist/domain/CheetahMiddleware.d.ts +5 -0
- package/dist/domain/CheetahMiddleware.js +2 -0
- package/dist/domain/Context.d.ts +26 -0
- package/dist/domain/Context.js +107 -0
- package/dist/domain/LocalsContainer.d.ts +4 -0
- package/dist/domain/LocalsContainer.js +10 -0
- package/dist/domain/Metadata.d.ts +449 -0
- package/dist/domain/Metadata.js +511 -0
- package/dist/domain/cors-config.d.ts +12 -0
- package/dist/domain/cors-config.js +18 -0
- package/dist/domain/http-method.d.ts +7 -0
- package/dist/domain/http-method.js +11 -0
- package/dist/domain/index.d.ts +10 -0
- package/dist/domain/index.js +26 -0
- package/dist/domain/provider-scope.d.ts +5 -0
- package/dist/domain/provider-scope.js +9 -0
- package/dist/domain/provider-type.d.ts +6 -0
- package/dist/domain/provider-type.js +10 -0
- package/dist/domain/provider.d.ts +37 -0
- package/dist/domain/provider.js +70 -0
- package/dist/events/hooks.decorator.d.ts +3 -0
- package/dist/events/hooks.decorator.js +29 -0
- package/dist/events/index.d.ts +2 -0
- package/dist/events/index.js +18 -0
- package/dist/events/on-event.d.ts +13 -0
- package/dist/events/on-event.js +11 -0
- package/dist/exceptions/HttpException.d.ts +9 -0
- package/dist/exceptions/HttpException.js +26 -0
- package/dist/exceptions/index.d.ts +1 -0
- package/dist/exceptions/index.js +17 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +32 -0
- package/dist/route/Matcher.d.ts +16 -0
- package/dist/route/Matcher.js +48 -0
- package/dist/route/RouteExecutor.d.ts +13 -0
- package/dist/route/RouteExecutor.js +70 -0
- package/dist/route/memoirist.d.ts +25 -0
- package/dist/route/memoirist.js +250 -0
- package/dist/services/logger.service.d.ts +23 -0
- package/dist/services/logger.service.js +54 -0
- package/dist/services/request-logger.service.d.ts +15 -0
- package/dist/services/request-logger.service.js +50 -0
- package/dist/testing/core-testing.d.ts +24 -0
- package/dist/testing/core-testing.js +98 -0
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.js +17 -0
- package/dist/utils/ancestorOf.d.ts +2 -0
- package/dist/utils/ancestorOf.js +10 -0
- package/dist/utils/ancestorsOf.d.ts +6 -0
- package/dist/utils/ancestorsOf.js +20 -0
- package/dist/utils/classOf.d.ts +13 -0
- package/dist/utils/classOf.js +21 -0
- package/dist/utils/cleanObject.d.ts +6 -0
- package/dist/utils/cleanObject.js +22 -0
- package/dist/utils/constructorOf.d.ts +11 -0
- package/dist/utils/constructorOf.js +18 -0
- package/dist/utils/createInstance.d.ts +1 -0
- package/dist/utils/createInstance.js +7 -0
- package/dist/utils/decoratorTypeOf.d.ts +11 -0
- package/dist/utils/decoratorTypeOf.js +32 -0
- package/dist/utils/deepClone.d.ts +6 -0
- package/dist/utils/deepClone.js +63 -0
- package/dist/utils/deepMerge.d.ts +9 -0
- package/dist/utils/deepMerge.js +62 -0
- package/dist/utils/descriptorOf.d.ts +8 -0
- package/dist/utils/descriptorOf.js +16 -0
- package/dist/utils/getClassOrSymbol.d.ts +1 -0
- package/dist/utils/getClassOrSymbol.js +8 -0
- package/dist/utils/getConstructorArgNames.d.ts +1 -0
- package/dist/utils/getConstructorArgNames.js +12 -0
- package/dist/utils/getMethodArgTypes.d.ts +1 -0
- package/dist/utils/getMethodArgTypes.js +9 -0
- package/dist/utils/getValue.d.ts +32 -0
- package/dist/utils/getValue.js +47 -0
- package/dist/utils/hasJsonMethod.d.ts +1 -0
- package/dist/utils/hasJsonMethod.js +6 -0
- package/dist/utils/index.d.ts +15 -0
- package/dist/utils/index.js +31 -0
- package/dist/utils/isArray.d.ts +13 -0
- package/dist/utils/isArray.js +21 -0
- package/dist/utils/isArrowFn.d.ts +1 -0
- package/dist/utils/isArrowFn.js +7 -0
- package/dist/utils/isBoolean.d.ts +7 -0
- package/dist/utils/isBoolean.js +15 -0
- package/dist/utils/isBuffer.d.ts +7 -0
- package/dist/utils/isBuffer.js +19 -0
- package/dist/utils/isClass.d.ts +1 -0
- package/dist/utils/isClass.js +26 -0
- package/dist/utils/isClassValidator.d.ts +6 -0
- package/dist/utils/isClassValidator.js +13 -0
- package/dist/utils/isCollection.d.ts +6 -0
- package/dist/utils/isCollection.js +20 -0
- package/dist/utils/isDate.d.ts +6 -0
- package/dist/utils/isDate.js +11 -0
- package/dist/utils/isEmpty.d.ts +6 -0
- package/dist/utils/isEmpty.js +12 -0
- package/dist/utils/isFunction.d.ts +1 -0
- package/dist/utils/isFunction.js +6 -0
- package/dist/utils/isInheritedFrom.d.ts +1 -0
- package/dist/utils/isInheritedFrom.js +24 -0
- package/dist/utils/isMomentObject.d.ts +1 -0
- package/dist/utils/isMomentObject.js +6 -0
- package/dist/utils/isMongooseObject.d.ts +2 -0
- package/dist/utils/isMongooseObject.js +11 -0
- package/dist/utils/isNil.d.ts +1 -0
- package/dist/utils/isNil.js +6 -0
- package/dist/utils/isNumber.d.ts +7 -0
- package/dist/utils/isNumber.js +15 -0
- package/dist/utils/isObject.d.ts +1 -0
- package/dist/utils/isObject.js +6 -0
- package/dist/utils/isObservable.d.ts +1 -0
- package/dist/utils/isObservable.js +6 -0
- package/dist/utils/isPlainObject.d.ts +7 -0
- package/dist/utils/isPlainObject.js +16 -0
- package/dist/utils/isPrimitive.d.ts +14 -0
- package/dist/utils/isPrimitive.js +28 -0
- package/dist/utils/isPrimitiveType.d.ts +1 -0
- package/dist/utils/isPrimitiveType.js +11 -0
- package/dist/utils/isPromise.d.ts +7 -0
- package/dist/utils/isPromise.js +14 -0
- package/dist/utils/isProtectedKey.d.ts +5 -0
- package/dist/utils/isProtectedKey.js +10 -0
- package/dist/utils/isRegExp.d.ts +1 -0
- package/dist/utils/isRegExp.js +6 -0
- package/dist/utils/isRequestScope.d.ts +11 -0
- package/dist/utils/isRequestScope.js +23 -0
- package/dist/utils/isSerializable.d.ts +1 -0
- package/dist/utils/isSerializable.js +11 -0
- package/dist/utils/isStream.d.ts +1 -0
- package/dist/utils/isStream.js +6 -0
- package/dist/utils/isString.d.ts +6 -0
- package/dist/utils/isString.js +14 -0
- package/dist/utils/isSymbol.d.ts +6 -0
- package/dist/utils/isSymbol.js +14 -0
- package/dist/utils/methodsOf.d.ts +9 -0
- package/dist/utils/methodsOf.js +24 -0
- package/dist/utils/nameOf.d.ts +14 -0
- package/dist/utils/nameOf.js +31 -0
- package/dist/utils/objectKeys.d.ts +1 -0
- package/dist/utils/objectKeys.js +7 -0
- package/dist/utils/primitiveOf.d.ts +1 -0
- package/dist/utils/primitiveOf.js +18 -0
- package/dist/utils/prototypeOf.d.ts +6 -0
- package/dist/utils/prototypeOf.js +12 -0
- package/dist/utils/setValue.d.ts +1 -0
- package/dist/utils/setValue.js +32 -0
- package/dist/utils/toMap.d.ts +3 -0
- package/dist/utils/toMap.js +34 -0
- package/dist/utils/toStringConstructor.d.ts +1 -0
- package/dist/utils/toStringConstructor.js +10 -0
- package/package.json +55 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Provider = void 0;
|
|
4
|
+
const provider_type_1 = require("./provider-type");
|
|
5
|
+
const provider_scope_1 = require("./provider-scope");
|
|
6
|
+
const methodsOf_1 = require("../utils/methodsOf");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
class Provider {
|
|
9
|
+
constructor(token, options = {}) {
|
|
10
|
+
/**
|
|
11
|
+
* Token group provider to retrieve all provider from the same type
|
|
12
|
+
*/
|
|
13
|
+
this.type = provider_type_1.ProviderType.PROVIDER;
|
|
14
|
+
this.deps = [];
|
|
15
|
+
/**
|
|
16
|
+
* Scope used by the injector to build the provider.
|
|
17
|
+
*/
|
|
18
|
+
this.scope = provider_scope_1.ProviderScope.SINGLETON;
|
|
19
|
+
this.children = [];
|
|
20
|
+
this.provide = token;
|
|
21
|
+
this.useClass = token;
|
|
22
|
+
Object.assign(this, options);
|
|
23
|
+
}
|
|
24
|
+
get token() {
|
|
25
|
+
return this._provide;
|
|
26
|
+
}
|
|
27
|
+
get useClass() {
|
|
28
|
+
return this._useClass;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create a new store if the given value is a class. Otherwise the value is ignored.
|
|
32
|
+
* @param value
|
|
33
|
+
*/
|
|
34
|
+
set useClass(value) {
|
|
35
|
+
if ((0, utils_1.isClass)(value)) {
|
|
36
|
+
this._useClass = (0, utils_1.classOf)(value);
|
|
37
|
+
this.hooks = (0, methodsOf_1.methodsOf)(this._useClass).reduce((hooks, { propertyKey }) => {
|
|
38
|
+
if (String(propertyKey).startsWith("$")) {
|
|
39
|
+
return {
|
|
40
|
+
...hooks,
|
|
41
|
+
[propertyKey]: (instance, ...args) => instance[propertyKey](...args),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return hooks;
|
|
45
|
+
}, {});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
get useValue() {
|
|
49
|
+
return this._useValue;
|
|
50
|
+
}
|
|
51
|
+
set useValue(value) {
|
|
52
|
+
this._useValue = value();
|
|
53
|
+
}
|
|
54
|
+
get provide() {
|
|
55
|
+
return this._provide;
|
|
56
|
+
}
|
|
57
|
+
set provide(value) {
|
|
58
|
+
if (!value) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this._provide = value;
|
|
62
|
+
}
|
|
63
|
+
clone() {
|
|
64
|
+
return new ((0, utils_1.classOf)(this))(this._provide, this);
|
|
65
|
+
}
|
|
66
|
+
isChild() {
|
|
67
|
+
return !!this.parent;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.Provider = Provider;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OnApplicationInit = OnApplicationInit;
|
|
4
|
+
exports.OnApplicationShutdown = OnApplicationShutdown;
|
|
5
|
+
exports.OnApplicationBoot = OnApplicationBoot;
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
const Metadata_1 = require("../domain/Metadata");
|
|
8
|
+
const on_event_1 = require("./on-event");
|
|
9
|
+
function OnApplicationInit(priority = 0) {
|
|
10
|
+
return (target, propertyKey) => {
|
|
11
|
+
const anotherEvents = Metadata_1.Metadata.get(constants_1.CONTROLLER_EVENTS, Reflect) || [];
|
|
12
|
+
anotherEvents.push({ methodName: propertyKey, eventName: on_event_1.EventType.OnApplicationInit, target: target.constructor, priority });
|
|
13
|
+
Metadata_1.Metadata.set(constants_1.CONTROLLER_EVENTS, anotherEvents, Reflect);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function OnApplicationShutdown(priority = 0) {
|
|
17
|
+
return (target, propertyKey) => {
|
|
18
|
+
const anotherEvents = Metadata_1.Metadata.get(constants_1.CONTROLLER_EVENTS, Reflect) || [];
|
|
19
|
+
anotherEvents.push({ methodName: propertyKey, eventName: on_event_1.EventType.OnApplicationShutdown, target: target.constructor, priority });
|
|
20
|
+
Metadata_1.Metadata.set(constants_1.CONTROLLER_EVENTS, anotherEvents, Reflect);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function OnApplicationBoot(priority = 0) {
|
|
24
|
+
return (target, propertyKey) => {
|
|
25
|
+
const anotherEvents = Metadata_1.Metadata.get(constants_1.CONTROLLER_EVENTS, Reflect) || [];
|
|
26
|
+
anotherEvents.push({ methodName: propertyKey, eventName: on_event_1.EventType.OnApplicationBoot, target: target.constructor, priority });
|
|
27
|
+
Metadata_1.Metadata.set(constants_1.CONTROLLER_EVENTS, anotherEvents, Reflect);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./on-event"), exports);
|
|
18
|
+
__exportStar(require("./hooks.decorator"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare enum EventType {
|
|
2
|
+
OnApplicationBoot = "OnApplicationBoot",
|
|
3
|
+
OnApplicationInit = "OnApplicationInit",
|
|
4
|
+
OnApplicationShutdown = "OnApplicationShutdown",
|
|
5
|
+
OnRequest = "OnRequest",
|
|
6
|
+
OnResponse = "OnResponse"
|
|
7
|
+
}
|
|
8
|
+
export interface OnEvent {
|
|
9
|
+
methodName: string;
|
|
10
|
+
eventName: EventType;
|
|
11
|
+
target: Object;
|
|
12
|
+
priority: number;
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventType = void 0;
|
|
4
|
+
var EventType;
|
|
5
|
+
(function (EventType) {
|
|
6
|
+
EventType["OnApplicationBoot"] = "OnApplicationBoot";
|
|
7
|
+
EventType["OnApplicationInit"] = "OnApplicationInit";
|
|
8
|
+
EventType["OnApplicationShutdown"] = "OnApplicationShutdown";
|
|
9
|
+
EventType["OnRequest"] = "OnRequest";
|
|
10
|
+
EventType["OnResponse"] = "OnResponse";
|
|
11
|
+
})(EventType || (exports.EventType = EventType = {}));
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpException = void 0;
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
class HttpException {
|
|
6
|
+
constructor(response, statusCode) {
|
|
7
|
+
this.response = response;
|
|
8
|
+
this.statusCode = statusCode;
|
|
9
|
+
this.initMessage();
|
|
10
|
+
}
|
|
11
|
+
initMessage() {
|
|
12
|
+
if ((0, utils_1.isObject)(this.response)) {
|
|
13
|
+
this.message = this.response;
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
this.message = this.response;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
getResponse() {
|
|
20
|
+
return this.message;
|
|
21
|
+
}
|
|
22
|
+
getStatus() {
|
|
23
|
+
return this.statusCode;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.HttpException = HttpException;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './HttpException';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./HttpException"), exports);
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from "./commons";
|
|
2
|
+
export * from "./container";
|
|
3
|
+
export * from "./domain";
|
|
4
|
+
export * from "./route/Matcher";
|
|
5
|
+
export * from "./route/RouteExecutor";
|
|
6
|
+
export * from "./exceptions";
|
|
7
|
+
export * from "./Carno";
|
|
8
|
+
export * from "./events";
|
|
9
|
+
export * from "./constants";
|
|
10
|
+
export * from "./utils";
|
|
11
|
+
export * from "./default-routes-carno";
|
|
12
|
+
export * from "./services/logger.service";
|
|
13
|
+
export * from "./services/request-logger.service";
|
|
14
|
+
export * from "./cache/cache.service";
|
|
15
|
+
export * from "./cache/bento-cache.driver";
|
|
16
|
+
export * from "./testing";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./commons"), exports);
|
|
18
|
+
__exportStar(require("./container"), exports);
|
|
19
|
+
__exportStar(require("./domain"), exports);
|
|
20
|
+
__exportStar(require("./route/Matcher"), exports);
|
|
21
|
+
__exportStar(require("./route/RouteExecutor"), exports);
|
|
22
|
+
__exportStar(require("./exceptions"), exports);
|
|
23
|
+
__exportStar(require("./Carno"), exports);
|
|
24
|
+
__exportStar(require("./events"), exports);
|
|
25
|
+
__exportStar(require("./constants"), exports);
|
|
26
|
+
__exportStar(require("./utils"), exports);
|
|
27
|
+
__exportStar(require("./default-routes-carno"), exports);
|
|
28
|
+
__exportStar(require("./services/logger.service"), exports);
|
|
29
|
+
__exportStar(require("./services/request-logger.service"), exports);
|
|
30
|
+
__exportStar(require("./cache/cache.service"), exports);
|
|
31
|
+
__exportStar(require("./cache/bento-cache.driver"), exports);
|
|
32
|
+
__exportStar(require("./testing"), exports);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TokenRouteWithProvider, TokenRouteWithProviderMap } from "../container";
|
|
2
|
+
import { Context } from "../domain";
|
|
3
|
+
declare class Matcher {
|
|
4
|
+
match(request: Request, routes: TokenRouteWithProviderMap, context: Context): TokenRouteWithProvider;
|
|
5
|
+
/**
|
|
6
|
+
* Identify route by url path.
|
|
7
|
+
* The route can have params (:param) and wildcards (*).
|
|
8
|
+
*
|
|
9
|
+
* @param route
|
|
10
|
+
* @param url
|
|
11
|
+
* @param context
|
|
12
|
+
*/
|
|
13
|
+
identifyRoute(route: TokenRouteWithProvider, url: URL, context: Context): boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare const RouteResolver: Matcher;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RouteResolver = void 0;
|
|
4
|
+
const parseUrl = require('parseurl-fast');
|
|
5
|
+
class Matcher {
|
|
6
|
+
match(request, routes, context) {
|
|
7
|
+
const method = request.method.toLowerCase();
|
|
8
|
+
if (!routes) {
|
|
9
|
+
throw new Error(`Method not allowed for ${request.url}`);
|
|
10
|
+
}
|
|
11
|
+
const routeMethod = routes.get(method);
|
|
12
|
+
const url = parseUrl(request);
|
|
13
|
+
const route = routeMethod?.find(route => this.identifyRoute(route, url, context));
|
|
14
|
+
if (!route) {
|
|
15
|
+
throw new Error('Method not allowed');
|
|
16
|
+
}
|
|
17
|
+
return route;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Identify route by url path.
|
|
21
|
+
* The route can have params (:param) and wildcards (*).
|
|
22
|
+
*
|
|
23
|
+
* @param route
|
|
24
|
+
* @param url
|
|
25
|
+
* @param context
|
|
26
|
+
*/
|
|
27
|
+
identifyRoute(route, url, context) {
|
|
28
|
+
const urlPath = url.pathname.split('/');
|
|
29
|
+
const routePathSegments = route.path.split('/');
|
|
30
|
+
if (urlPath.length !== routePathSegments.length) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
return routePathSegments.every((path, index) => {
|
|
34
|
+
if (path === '*') {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
if (path.startsWith(':')) {
|
|
38
|
+
context.setParam({
|
|
39
|
+
...context.param,
|
|
40
|
+
[path.replace(':', '')]: urlPath[index]
|
|
41
|
+
});
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
return path === urlPath[index];
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.RouteResolver = new Matcher();
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { InjectorService, TokenRouteWithProvider } from "../container";
|
|
2
|
+
import { Context, LocalsContainer } from "../domain";
|
|
3
|
+
declare class Router {
|
|
4
|
+
private readonly jsonHeaders;
|
|
5
|
+
private readonly textHeaders;
|
|
6
|
+
executeRoute(route: TokenRouteWithProvider, injector: InjectorService, context: Context, locals: LocalsContainer): Promise<Response>;
|
|
7
|
+
private mountResponse;
|
|
8
|
+
private isNativeResponse;
|
|
9
|
+
private isBodyInit;
|
|
10
|
+
private createJsonResponse;
|
|
11
|
+
}
|
|
12
|
+
export declare const RouteExecutor: Router;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RouteExecutor = void 0;
|
|
4
|
+
const events_1 = require("../events");
|
|
5
|
+
class Router {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.jsonHeaders = { "Content-Type": "application/json" };
|
|
8
|
+
this.textHeaders = { "Content-Type": "text/html" };
|
|
9
|
+
}
|
|
10
|
+
async executeRoute(route, injector, context, locals) {
|
|
11
|
+
const provider = injector.invoke(route.provider, locals);
|
|
12
|
+
route.provider.instance = provider;
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
if (!provider[route.methodName]) {
|
|
15
|
+
throw new Error("Controller not found");
|
|
16
|
+
}
|
|
17
|
+
const result = await injector.invokeRoute(route, context, locals);
|
|
18
|
+
await injector.callHook(events_1.EventType.OnResponse, { context, result });
|
|
19
|
+
return this.mountResponse(result, context);
|
|
20
|
+
}
|
|
21
|
+
mountResponse(result, context) {
|
|
22
|
+
const status = context.getResponseStatus() || 200;
|
|
23
|
+
if (this.isNativeResponse(result)) {
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
26
|
+
if (result === null || result === undefined) {
|
|
27
|
+
return new Response("", { status, headers: this.textHeaders });
|
|
28
|
+
}
|
|
29
|
+
const resultType = typeof result;
|
|
30
|
+
if (resultType === "string") {
|
|
31
|
+
return new Response(result, { status, headers: this.textHeaders });
|
|
32
|
+
}
|
|
33
|
+
if (resultType === "number" || resultType === "boolean") {
|
|
34
|
+
return new Response(String(result), { status, headers: this.textHeaders });
|
|
35
|
+
}
|
|
36
|
+
if (this.isBodyInit(result)) {
|
|
37
|
+
return new Response(result, { status });
|
|
38
|
+
}
|
|
39
|
+
return this.createJsonResponse(result, status);
|
|
40
|
+
}
|
|
41
|
+
isNativeResponse(result) {
|
|
42
|
+
return result instanceof Response;
|
|
43
|
+
}
|
|
44
|
+
isBodyInit(result) {
|
|
45
|
+
if (!result) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
if (result instanceof ReadableStream) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
if (result instanceof Blob || result instanceof ArrayBuffer) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
if (ArrayBuffer.isView(result)) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
return result instanceof FormData || result instanceof URLSearchParams;
|
|
58
|
+
}
|
|
59
|
+
createJsonResponse(body, status) {
|
|
60
|
+
try {
|
|
61
|
+
const json = JSON.stringify(body);
|
|
62
|
+
return new Response(json, { status, headers: this.jsonHeaders });
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
const fallback = JSON.stringify({ error: "Serialization failed" });
|
|
66
|
+
return new Response(fallback, { status: 500, headers: this.jsonHeaders });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.RouteExecutor = new Router();
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface FindResult<T> {
|
|
2
|
+
store: T;
|
|
3
|
+
params: Record<string, any>;
|
|
4
|
+
}
|
|
5
|
+
export interface ParamNode<T> {
|
|
6
|
+
paramName: string | null;
|
|
7
|
+
names: Map<T, string>;
|
|
8
|
+
store: T | null;
|
|
9
|
+
inert: Node<T> | null;
|
|
10
|
+
}
|
|
11
|
+
export interface Node<T> {
|
|
12
|
+
part: string;
|
|
13
|
+
store: T | null;
|
|
14
|
+
inert: Map<number, Node<T>> | null;
|
|
15
|
+
params: ParamNode<T> | null;
|
|
16
|
+
wildcardStore: T | null;
|
|
17
|
+
}
|
|
18
|
+
export declare class Memoirist<T> {
|
|
19
|
+
root: Record<string, Node<T>>;
|
|
20
|
+
history: [string, string, T][];
|
|
21
|
+
private static regex;
|
|
22
|
+
add(method: string, path: string, store: T): FindResult<T>['store'];
|
|
23
|
+
find(method: string, url: string): FindResult<T> | null;
|
|
24
|
+
}
|
|
25
|
+
export default Memoirist;
|