@carno.js/core 0.2.11 → 1.0.2
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 +673 -673
- package/README.md +188 -0
- package/dist/Carno.js +272 -333
- package/dist/Carno.mjs +268 -0
- package/dist/DefaultRoutes.js +51 -0
- package/dist/DefaultRoutes.mjs +34 -0
- package/dist/bun/index.js +183 -0
- package/dist/bun/index.js.map +86 -0
- package/dist/cache/CacheDriver.js +13 -0
- package/dist/cache/CacheDriver.mjs +0 -0
- package/dist/cache/CacheService.js +113 -0
- package/dist/cache/CacheService.mjs +93 -0
- package/dist/cache/MemoryDriver.js +66 -0
- package/dist/cache/MemoryDriver.mjs +46 -0
- package/dist/cache/RedisDriver.js +81 -0
- package/dist/cache/RedisDriver.mjs +61 -0
- package/dist/compiler/JITCompiler.js +111 -0
- package/dist/compiler/JITCompiler.mjs +89 -0
- package/dist/container/Container.js +99 -0
- package/dist/container/Container.mjs +78 -0
- package/dist/context/Context.js +97 -0
- package/dist/context/Context.mjs +77 -0
- package/dist/cors/CorsHandler.js +90 -0
- package/dist/cors/CorsHandler.mjs +68 -0
- package/dist/decorators/Controller.js +42 -0
- package/dist/decorators/Controller.mjs +22 -0
- package/dist/decorators/Inject.js +30 -0
- package/dist/decorators/Inject.mjs +10 -0
- package/dist/decorators/Middleware.js +35 -0
- package/dist/decorators/Middleware.mjs +15 -0
- package/dist/decorators/Service.js +31 -0
- package/dist/decorators/Service.mjs +12 -0
- package/dist/decorators/methods.js +60 -0
- package/dist/decorators/methods.mjs +34 -0
- package/dist/decorators/params.js +63 -0
- package/dist/decorators/params.mjs +37 -0
- package/dist/events/Lifecycle.js +69 -0
- package/dist/events/Lifecycle.mjs +41 -0
- package/dist/exceptions/HttpException.js +112 -26
- package/dist/exceptions/HttpException.mjs +82 -0
- package/dist/index.js +129 -31
- package/dist/index.mjs +94 -0
- package/dist/metadata.js +34 -0
- package/dist/metadata.mjs +9 -0
- package/dist/middleware/CarnoMiddleware.js +13 -0
- package/dist/middleware/CarnoMiddleware.mjs +0 -0
- package/dist/router/RadixRouter.js +121 -0
- package/dist/router/RadixRouter.mjs +101 -0
- package/dist/testing/TestHarness.js +81 -0
- package/dist/testing/TestHarness.mjs +60 -0
- package/dist/utils/Metadata.js +53 -0
- package/dist/utils/Metadata.mjs +31 -0
- package/dist/validation/ValibotAdapter.js +67 -0
- package/dist/validation/ValibotAdapter.mjs +48 -0
- package/dist/validation/ValidatorAdapter.js +35 -19
- package/dist/validation/ValidatorAdapter.mjs +14 -0
- package/dist/validation/ZodAdapter.js +80 -0
- package/dist/validation/ZodAdapter.mjs +59 -0
- package/package.json +21 -63
- package/src/Carno.ts +605 -0
- package/src/DefaultRoutes.ts +34 -0
- package/src/cache/CacheDriver.ts +50 -0
- package/src/cache/CacheService.ts +139 -0
- package/src/cache/MemoryDriver.ts +104 -0
- package/src/cache/RedisDriver.ts +116 -0
- package/src/compiler/JITCompiler.ts +167 -0
- package/src/container/Container.ts +168 -0
- package/src/context/Context.ts +128 -0
- package/src/cors/CorsHandler.ts +145 -0
- package/src/decorators/Controller.ts +63 -0
- package/src/decorators/Inject.ts +16 -0
- package/src/decorators/Middleware.ts +22 -0
- package/src/decorators/Service.ts +18 -0
- package/src/decorators/methods.ts +58 -0
- package/src/decorators/params.ts +47 -0
- package/src/events/Lifecycle.ts +97 -0
- package/src/exceptions/HttpException.ts +99 -0
- package/src/index.ts +92 -0
- package/src/metadata.ts +46 -0
- package/src/middleware/CarnoMiddleware.ts +14 -0
- package/src/router/RadixRouter.ts +225 -0
- package/src/testing/TestHarness.ts +177 -0
- package/src/utils/Metadata.ts +43 -0
- package/src/validation/ValibotAdapter.ts +95 -0
- package/src/validation/ValidatorAdapter.ts +69 -0
- package/src/validation/ZodAdapter.ts +102 -0
- package/dist/Carno.d.ts +0 -75
- package/dist/cache/bento-cache.driver.d.ts +0 -13
- package/dist/cache/bento-cache.driver.js +0 -55
- package/dist/cache/cache.service.d.ts +0 -8
- package/dist/cache/cache.service.js +0 -6
- package/dist/commons/decorators/Injectable.decorator.d.ts +0 -20
- package/dist/commons/decorators/Injectable.decorator.js +0 -33
- package/dist/commons/decorators/controller.decorator.d.ts +0 -8
- package/dist/commons/decorators/controller.decorator.js +0 -22
- package/dist/commons/decorators/http.decorators.d.ts +0 -13
- package/dist/commons/decorators/http.decorators.js +0 -63
- package/dist/commons/decorators/index.d.ts +0 -6
- package/dist/commons/decorators/index.js +0 -22
- package/dist/commons/decorators/inject.decorator.d.ts +0 -1
- package/dist/commons/decorators/inject.decorator.js +0 -5
- package/dist/commons/decorators/middleware.decorator.d.ts +0 -2
- package/dist/commons/decorators/middleware.decorator.js +0 -30
- package/dist/commons/decorators/service.decorator.d.ts +0 -2
- package/dist/commons/decorators/service.decorator.js +0 -7
- package/dist/commons/decorators/validation.decorator.d.ts +0 -32
- package/dist/commons/decorators/validation.decorator.js +0 -40
- package/dist/commons/http-code.enum.d.ts +0 -50
- package/dist/commons/http-code.enum.js +0 -54
- package/dist/commons/index.d.ts +0 -3
- package/dist/commons/index.js +0 -19
- package/dist/commons/registries/ProviderControl.d.ts +0 -77
- package/dist/commons/registries/ProviderControl.js +0 -112
- package/dist/commons/registries/ProviderRegistry.d.ts +0 -7
- package/dist/commons/registries/ProviderRegistry.js +0 -20
- package/dist/constants.d.ts +0 -8
- package/dist/constants.js +0 -11
- package/dist/container/ContainerConfiguration.d.ts +0 -45
- package/dist/container/ContainerConfiguration.js +0 -121
- package/dist/container/DependencyResolver.d.ts +0 -20
- package/dist/container/DependencyResolver.js +0 -85
- package/dist/container/InjectorService.d.ts +0 -58
- package/dist/container/InjectorService.js +0 -286
- package/dist/container/MethodInvoker.d.ts +0 -21
- package/dist/container/MethodInvoker.js +0 -83
- package/dist/container/RouteResolver.d.ts +0 -27
- package/dist/container/RouteResolver.js +0 -173
- package/dist/container/container.d.ts +0 -41
- package/dist/container/container.js +0 -71
- package/dist/container/createContainer.d.ts +0 -3
- package/dist/container/createContainer.js +0 -12
- package/dist/container/createInjector.d.ts +0 -2
- package/dist/container/createInjector.js +0 -7
- package/dist/container/index.d.ts +0 -6
- package/dist/container/index.js +0 -22
- package/dist/container/middleware.resolver.d.ts +0 -9
- package/dist/container/middleware.resolver.js +0 -35
- package/dist/default-routes-carno.d.ts +0 -3
- package/dist/default-routes-carno.js +0 -29
- package/dist/domain/BaseContext.d.ts +0 -15
- package/dist/domain/BaseContext.js +0 -2
- package/dist/domain/CarnoClosure.d.ts +0 -1
- package/dist/domain/CarnoClosure.js +0 -2
- package/dist/domain/CarnoMiddleware.d.ts +0 -5
- package/dist/domain/CarnoMiddleware.js +0 -2
- package/dist/domain/Context.d.ts +0 -58
- package/dist/domain/Context.js +0 -188
- package/dist/domain/FastContext.d.ts +0 -34
- package/dist/domain/FastContext.js +0 -59
- package/dist/domain/LocalsContainer.d.ts +0 -4
- package/dist/domain/LocalsContainer.js +0 -10
- package/dist/domain/Metadata.d.ts +0 -449
- package/dist/domain/Metadata.js +0 -511
- package/dist/domain/cors-config.d.ts +0 -12
- package/dist/domain/cors-config.js +0 -18
- package/dist/domain/cors-headers-cache.d.ts +0 -17
- package/dist/domain/cors-headers-cache.js +0 -101
- package/dist/domain/http-method.d.ts +0 -7
- package/dist/domain/http-method.js +0 -11
- package/dist/domain/index.d.ts +0 -10
- package/dist/domain/index.js +0 -26
- package/dist/domain/provider-scope.d.ts +0 -5
- package/dist/domain/provider-scope.js +0 -9
- package/dist/domain/provider-type.d.ts +0 -6
- package/dist/domain/provider-type.js +0 -10
- package/dist/domain/provider.d.ts +0 -37
- package/dist/domain/provider.js +0 -70
- package/dist/events/hooks.decorator.d.ts +0 -3
- package/dist/events/hooks.decorator.js +0 -29
- package/dist/events/index.d.ts +0 -2
- package/dist/events/index.js +0 -18
- package/dist/events/on-event.d.ts +0 -13
- package/dist/events/on-event.js +0 -11
- package/dist/exceptions/HttpException.d.ts +0 -9
- package/dist/exceptions/index.d.ts +0 -1
- package/dist/exceptions/index.js +0 -17
- package/dist/index.d.ts +0 -16
- package/dist/route/CompiledRoute.d.ts +0 -23
- package/dist/route/CompiledRoute.js +0 -9
- package/dist/route/FastPathExecutor.d.ts +0 -12
- package/dist/route/FastPathExecutor.js +0 -50
- package/dist/route/JITCompiler.d.ts +0 -28
- package/dist/route/JITCompiler.js +0 -245
- package/dist/route/Matcher.d.ts +0 -11
- package/dist/route/Matcher.js +0 -48
- package/dist/route/ParamResolverFactory.d.ts +0 -14
- package/dist/route/ParamResolverFactory.js +0 -49
- package/dist/route/RouteCompiler.d.ts +0 -28
- package/dist/route/RouteCompiler.js +0 -157
- package/dist/route/RouteExecutor.d.ts +0 -12
- package/dist/route/RouteExecutor.js +0 -84
- package/dist/route/memoirist.d.ts +0 -31
- package/dist/route/memoirist.js +0 -373
- package/dist/services/logger.service.d.ts +0 -23
- package/dist/services/logger.service.js +0 -47
- package/dist/testing/core-testing.d.ts +0 -24
- package/dist/testing/core-testing.js +0 -102
- package/dist/testing/index.d.ts +0 -1
- package/dist/testing/index.js +0 -17
- package/dist/utils/ValidationCache.d.ts +0 -5
- package/dist/utils/ValidationCache.js +0 -35
- package/dist/utils/ancestorOf.d.ts +0 -2
- package/dist/utils/ancestorOf.js +0 -10
- package/dist/utils/ancestorsOf.d.ts +0 -6
- package/dist/utils/ancestorsOf.js +0 -20
- package/dist/utils/classOf.d.ts +0 -13
- package/dist/utils/classOf.js +0 -21
- package/dist/utils/cleanObject.d.ts +0 -6
- package/dist/utils/cleanObject.js +0 -22
- package/dist/utils/constructorOf.d.ts +0 -11
- package/dist/utils/constructorOf.js +0 -18
- package/dist/utils/createInstance.d.ts +0 -1
- package/dist/utils/createInstance.js +0 -7
- package/dist/utils/decoratorTypeOf.d.ts +0 -11
- package/dist/utils/decoratorTypeOf.js +0 -32
- package/dist/utils/deepClone.d.ts +0 -6
- package/dist/utils/deepClone.js +0 -63
- package/dist/utils/deepMerge.d.ts +0 -9
- package/dist/utils/deepMerge.js +0 -62
- package/dist/utils/descriptorOf.d.ts +0 -8
- package/dist/utils/descriptorOf.js +0 -16
- package/dist/utils/formatValidationErrors.d.ts +0 -5
- package/dist/utils/formatValidationErrors.js +0 -80
- package/dist/utils/getClassOrSymbol.d.ts +0 -1
- package/dist/utils/getClassOrSymbol.js +0 -8
- package/dist/utils/getConstructorArgNames.d.ts +0 -1
- package/dist/utils/getConstructorArgNames.js +0 -12
- package/dist/utils/getMethodArgTypes.d.ts +0 -1
- package/dist/utils/getMethodArgTypes.js +0 -9
- package/dist/utils/getValue.d.ts +0 -32
- package/dist/utils/getValue.js +0 -47
- package/dist/utils/hasJsonMethod.d.ts +0 -1
- package/dist/utils/hasJsonMethod.js +0 -6
- package/dist/utils/index.d.ts +0 -15
- package/dist/utils/index.js +0 -31
- package/dist/utils/isArray.d.ts +0 -13
- package/dist/utils/isArray.js +0 -21
- package/dist/utils/isArrowFn.d.ts +0 -1
- package/dist/utils/isArrowFn.js +0 -7
- package/dist/utils/isBoolean.d.ts +0 -7
- package/dist/utils/isBoolean.js +0 -15
- package/dist/utils/isBuffer.d.ts +0 -7
- package/dist/utils/isBuffer.js +0 -19
- package/dist/utils/isClass.d.ts +0 -1
- package/dist/utils/isClass.js +0 -26
- package/dist/utils/isCollection.d.ts +0 -6
- package/dist/utils/isCollection.js +0 -20
- package/dist/utils/isDate.d.ts +0 -6
- package/dist/utils/isDate.js +0 -11
- package/dist/utils/isEmpty.d.ts +0 -6
- package/dist/utils/isEmpty.js +0 -12
- package/dist/utils/isFunction.d.ts +0 -1
- package/dist/utils/isFunction.js +0 -6
- package/dist/utils/isInheritedFrom.d.ts +0 -1
- package/dist/utils/isInheritedFrom.js +0 -24
- package/dist/utils/isMomentObject.d.ts +0 -1
- package/dist/utils/isMomentObject.js +0 -6
- package/dist/utils/isMongooseObject.d.ts +0 -2
- package/dist/utils/isMongooseObject.js +0 -11
- package/dist/utils/isNil.d.ts +0 -1
- package/dist/utils/isNil.js +0 -6
- package/dist/utils/isNumber.d.ts +0 -7
- package/dist/utils/isNumber.js +0 -15
- package/dist/utils/isObject.d.ts +0 -1
- package/dist/utils/isObject.js +0 -6
- package/dist/utils/isObservable.d.ts +0 -1
- package/dist/utils/isObservable.js +0 -6
- package/dist/utils/isPlainObject.d.ts +0 -7
- package/dist/utils/isPlainObject.js +0 -16
- package/dist/utils/isPrimitive.d.ts +0 -14
- package/dist/utils/isPrimitive.js +0 -28
- package/dist/utils/isPrimitiveType.d.ts +0 -1
- package/dist/utils/isPrimitiveType.js +0 -11
- package/dist/utils/isPromise.d.ts +0 -7
- package/dist/utils/isPromise.js +0 -14
- package/dist/utils/isProtectedKey.d.ts +0 -5
- package/dist/utils/isProtectedKey.js +0 -10
- package/dist/utils/isRegExp.d.ts +0 -1
- package/dist/utils/isRegExp.js +0 -6
- package/dist/utils/isRequestScope.d.ts +0 -11
- package/dist/utils/isRequestScope.js +0 -23
- package/dist/utils/isSerializable.d.ts +0 -1
- package/dist/utils/isSerializable.js +0 -11
- package/dist/utils/isStream.d.ts +0 -1
- package/dist/utils/isStream.js +0 -6
- package/dist/utils/isString.d.ts +0 -6
- package/dist/utils/isString.js +0 -14
- package/dist/utils/isSymbol.d.ts +0 -6
- package/dist/utils/isSymbol.js +0 -14
- package/dist/utils/methodsOf.d.ts +0 -9
- package/dist/utils/methodsOf.js +0 -24
- package/dist/utils/nameOf.d.ts +0 -14
- package/dist/utils/nameOf.js +0 -31
- package/dist/utils/objectKeys.d.ts +0 -1
- package/dist/utils/objectKeys.js +0 -7
- package/dist/utils/primitiveOf.d.ts +0 -1
- package/dist/utils/primitiveOf.js +0 -18
- package/dist/utils/prototypeOf.d.ts +0 -6
- package/dist/utils/prototypeOf.js +0 -12
- package/dist/utils/setValue.d.ts +0 -1
- package/dist/utils/setValue.js +0 -32
- package/dist/utils/toMap.d.ts +0 -3
- package/dist/utils/toMap.js +0 -34
- package/dist/utils/toStringConstructor.d.ts +0 -1
- package/dist/utils/toStringConstructor.js +0 -10
- package/dist/validation/ValidatorAdapter.d.ts +0 -66
- package/dist/validation/adapters/ClassValidatorAdapter.d.ts +0 -23
- package/dist/validation/adapters/ClassValidatorAdapter.js +0 -47
- package/dist/validation/adapters/ZodAdapter.d.ts +0 -14
- package/dist/validation/adapters/ZodAdapter.js +0 -56
- package/dist/validation/adapters/index.d.ts +0 -4
- package/dist/validation/adapters/index.js +0 -7
- package/dist/validation/index.d.ts +0 -3
- package/dist/validation/index.js +0 -20
package/dist/domain/Metadata.js
DELETED
|
@@ -1,511 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Metadata = void 0;
|
|
4
|
-
require("reflect-metadata");
|
|
5
|
-
const constants_1 = require("../constants");
|
|
6
|
-
const classOf_1 = require("../utils/classOf");
|
|
7
|
-
/**
|
|
8
|
-
* Metadata key
|
|
9
|
-
* @private
|
|
10
|
-
* @type {string}
|
|
11
|
-
*/
|
|
12
|
-
const DESIGN_PARAM_TYPES = "design:paramtypes";
|
|
13
|
-
/**
|
|
14
|
-
* Metadata key
|
|
15
|
-
* @private
|
|
16
|
-
* @type {string}
|
|
17
|
-
*/
|
|
18
|
-
const DESIGN_TYPE = "design:type";
|
|
19
|
-
/**
|
|
20
|
-
* Metadata key
|
|
21
|
-
* @private
|
|
22
|
-
* @type {string}
|
|
23
|
-
*/
|
|
24
|
-
const DESIGN_RETURN_TYPE = "design:returntype";
|
|
25
|
-
/**
|
|
26
|
-
* Properties collections
|
|
27
|
-
* @private
|
|
28
|
-
* @type {string}
|
|
29
|
-
*/
|
|
30
|
-
const PROPERTIES = new Map();
|
|
31
|
-
/**
|
|
32
|
-
* @stable
|
|
33
|
-
*/
|
|
34
|
-
class Metadata {
|
|
35
|
-
/**
|
|
36
|
-
* Gets the metadata value for the provided metadata key on the target object or its prototype chain.
|
|
37
|
-
* @param key A key used to store and retrieve metadata.
|
|
38
|
-
* @param target The target object on which the metadata is defined.
|
|
39
|
-
* @param propertyKey The property key for the target.
|
|
40
|
-
* @returns The metadata value for the metadata key if found; otherwise, `undefined`.
|
|
41
|
-
* @example
|
|
42
|
-
*
|
|
43
|
-
* ```typescript
|
|
44
|
-
* class Example {
|
|
45
|
-
* // property declarations are not part of ES6, though they are valid in TypeScript:
|
|
46
|
-
* // static staticProperty;
|
|
47
|
-
* // property;
|
|
48
|
-
*
|
|
49
|
-
* static staticMethod(p) { }
|
|
50
|
-
* method(p) { }
|
|
51
|
-
* }
|
|
52
|
-
*
|
|
53
|
-
* // constructor
|
|
54
|
-
* result = Metadata.get("custom:annotation", Example);
|
|
55
|
-
*
|
|
56
|
-
* // property (on constructor)
|
|
57
|
-
* result = Metadata.get("custom:annotation", Example, "staticProperty");
|
|
58
|
-
*
|
|
59
|
-
* // property (on prototype)
|
|
60
|
-
* result = Metadata.get("custom:annotation", Example.prototype, "property");
|
|
61
|
-
*
|
|
62
|
-
* // method (on constructor)
|
|
63
|
-
* result = Metadata.get("custom:annotation", Example, "staticMethod");
|
|
64
|
-
*
|
|
65
|
-
* // method (on prototype)
|
|
66
|
-
* result = Metadata.get("custom:annotation", Example.prototype, "method");
|
|
67
|
-
* ```
|
|
68
|
-
*
|
|
69
|
-
*/
|
|
70
|
-
static get(key, target, propertyKey) {
|
|
71
|
-
return Reflect.getMetadata(key, (0, classOf_1.classOf)(target), propertyKey);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Gets the metadata value for the provided metadata key on the target object or its prototype chain.
|
|
75
|
-
* @param key A key used to store and retrieve metadata.
|
|
76
|
-
* @param target The target object on which the metadata is defined.
|
|
77
|
-
* @param propertyKey The property key for the target.
|
|
78
|
-
* @returns The metadata value for the metadata key if found; otherwise, `undefined`.
|
|
79
|
-
* @example
|
|
80
|
-
*
|
|
81
|
-
* ```typescript
|
|
82
|
-
* class Example {
|
|
83
|
-
* // property declarations are not part of ES6, though they are valid in TypeScript:
|
|
84
|
-
* // static staticProperty;
|
|
85
|
-
* // property;
|
|
86
|
-
*
|
|
87
|
-
* static staticMethod(p) { }
|
|
88
|
-
* method(p) { }
|
|
89
|
-
* }
|
|
90
|
-
*
|
|
91
|
-
* // constructor
|
|
92
|
-
* result = Metadata.getOwn("custom:annotation", Example);
|
|
93
|
-
*
|
|
94
|
-
* // property (on constructor)
|
|
95
|
-
* result = Metadata.getOwn("custom:annotation", Example, "staticProperty");
|
|
96
|
-
*
|
|
97
|
-
* // property (on prototype)
|
|
98
|
-
* result = Metadata.getOwn("custom:annotation", Example.prototype, "property");
|
|
99
|
-
*
|
|
100
|
-
* // method (on constructor)
|
|
101
|
-
* result = Metadata.getOwn("custom:annotation", Example, "staticMethod");
|
|
102
|
-
*
|
|
103
|
-
* // method (on prototype)
|
|
104
|
-
* result = Metadata.getOwn("custom:annotation", Example.prototype, "method");
|
|
105
|
-
* ```
|
|
106
|
-
*
|
|
107
|
-
*/
|
|
108
|
-
static getOwn(key, target, propertyKey) {
|
|
109
|
-
return Reflect.getOwnMetadata(key, (0, classOf_1.classOf)(target), propertyKey);
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Gets the metadata value for the provided metadata DESIGN_TYPE on the target object or its prototype chain.
|
|
113
|
-
* @param target The target object on which the metadata is defined.
|
|
114
|
-
* @param propertyKey The property key for the target.
|
|
115
|
-
* @returns The metadata value for the metadata key if found; otherwise, `undefined`.
|
|
116
|
-
* @example
|
|
117
|
-
*
|
|
118
|
-
* ```typescript
|
|
119
|
-
* class Example {
|
|
120
|
-
* // property declarations are not part of ES6, though they are valid in TypeScript:
|
|
121
|
-
* // static staticProperty;
|
|
122
|
-
* // property;
|
|
123
|
-
*
|
|
124
|
-
* static staticMethod(p) { }
|
|
125
|
-
* method(p) { }
|
|
126
|
-
* }
|
|
127
|
-
*
|
|
128
|
-
* // on contructor
|
|
129
|
-
* result = Metadata.getType(Example);
|
|
130
|
-
*
|
|
131
|
-
* // property (on constructor)
|
|
132
|
-
* result = Metadata.getType(Example, "staticProperty");
|
|
133
|
-
*
|
|
134
|
-
* // method (on constructor)
|
|
135
|
-
* result = Metadata.getType(Example, "staticMethod");
|
|
136
|
-
* ```
|
|
137
|
-
*
|
|
138
|
-
*/
|
|
139
|
-
static getType(target, propertyKey) {
|
|
140
|
-
return Reflect.getMetadata(DESIGN_TYPE, target, propertyKey);
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Gets the metadata value for the provided metadata DESIGN_TYPE on the target object or its prototype chain.
|
|
144
|
-
* @param target The target object on which the metadata is defined.
|
|
145
|
-
* @param propertyKey The property key for the target.
|
|
146
|
-
* @returns The metadata value for the metadata key if found; otherwise, `undefined`.
|
|
147
|
-
* @example
|
|
148
|
-
*
|
|
149
|
-
* ```typescript
|
|
150
|
-
* class Example {
|
|
151
|
-
* // property declarations are not part of ES6, though they are valid in TypeScript:
|
|
152
|
-
* // static staticProperty;
|
|
153
|
-
* // property;
|
|
154
|
-
*
|
|
155
|
-
* static staticMethod(p) { }
|
|
156
|
-
* method(p) { }
|
|
157
|
-
* }
|
|
158
|
-
*
|
|
159
|
-
* // on contructor
|
|
160
|
-
* result = Metadata.getOwnType(Example);
|
|
161
|
-
*
|
|
162
|
-
* // property (on constructor)
|
|
163
|
-
* result = Metadata.getOwnType(Example, "staticProperty");
|
|
164
|
-
*
|
|
165
|
-
* // method (on constructor)
|
|
166
|
-
* result = Metadata.getOwnType(Example, "staticMethod");
|
|
167
|
-
* ```
|
|
168
|
-
*
|
|
169
|
-
*/
|
|
170
|
-
static getOwnType(target, propertyKey) {
|
|
171
|
-
return Reflect.getMetadata(DESIGN_TYPE, target, propertyKey);
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Gets the metadata value for the provided metadata DESIGN_RETURN_TYPE on the target object or its prototype chain.
|
|
175
|
-
* @param target The target object on which the metadata is defined.
|
|
176
|
-
* @param propertyKey The property key for the target.
|
|
177
|
-
* @returns The metadata value for the metadata key if found; otherwise, `undefined`.
|
|
178
|
-
* @example
|
|
179
|
-
*
|
|
180
|
-
* ```typescript
|
|
181
|
-
* class Example {
|
|
182
|
-
* // property declarations are not part of ES6, though they are valid in TypeScript:
|
|
183
|
-
* // static staticProperty;
|
|
184
|
-
* // property;
|
|
185
|
-
*
|
|
186
|
-
* static staticMethod(p) { }
|
|
187
|
-
* method(p) { }
|
|
188
|
-
* }
|
|
189
|
-
*
|
|
190
|
-
* // on contructor
|
|
191
|
-
* result = Metadata.getReturnType(Example);
|
|
192
|
-
*
|
|
193
|
-
* // property (on constructor)
|
|
194
|
-
* result = Metadata.getReturnType(Example, "staticProperty");
|
|
195
|
-
*
|
|
196
|
-
* // method (on constructor)
|
|
197
|
-
* result = Metadata.getReturnType(Example, "staticMethod");
|
|
198
|
-
* ```
|
|
199
|
-
*
|
|
200
|
-
*/
|
|
201
|
-
static getReturnType(target, propertyKey) {
|
|
202
|
-
return Reflect.getMetadata(DESIGN_RETURN_TYPE, target, propertyKey);
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Gets the metadata value for the provided metadata DESIGN_RETURN_TYPE on the target object or its prototype chain.
|
|
206
|
-
* @param target The target object on which the metadata is defined.
|
|
207
|
-
* @param propertyKey The property key for the target.
|
|
208
|
-
* @returns The metadata value for the metadata key if found; otherwise, `undefined`.
|
|
209
|
-
* @example
|
|
210
|
-
*
|
|
211
|
-
* ```typescript
|
|
212
|
-
* class Example {
|
|
213
|
-
* // property declarations are not part of ES6, though they are valid in TypeScript:
|
|
214
|
-
* // static staticProperty;
|
|
215
|
-
* // property;
|
|
216
|
-
*
|
|
217
|
-
* static staticMethod(p) { }
|
|
218
|
-
* method(p) { }
|
|
219
|
-
* }
|
|
220
|
-
*
|
|
221
|
-
* // on contructor
|
|
222
|
-
* result = Metadata.getOwnReturnType(Example);
|
|
223
|
-
*
|
|
224
|
-
* // property (on constructor)
|
|
225
|
-
* result = Metadata.getOwnReturnType(Example, "staticProperty");
|
|
226
|
-
*
|
|
227
|
-
* // method (on constructor)
|
|
228
|
-
* result = Metadata.getOwnReturnType(Example, "staticMethod");
|
|
229
|
-
* ```
|
|
230
|
-
*
|
|
231
|
-
*/
|
|
232
|
-
static getOwnReturnType(target, propertyKey) {
|
|
233
|
-
return Reflect.getOwnMetadata(DESIGN_RETURN_TYPE, target, propertyKey);
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.
|
|
237
|
-
* @param key A key used to store and retrieve metadata.
|
|
238
|
-
* @param target The target object on which the metadata is defined.
|
|
239
|
-
* @param propertyKey The property key for the target.
|
|
240
|
-
* @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.
|
|
241
|
-
* @example
|
|
242
|
-
*
|
|
243
|
-
* ```typescript
|
|
244
|
-
* class Example {
|
|
245
|
-
* // property declarations are not part of ES6, though they are valid in TypeScript:
|
|
246
|
-
* // static staticProperty;
|
|
247
|
-
* // property;
|
|
248
|
-
*
|
|
249
|
-
* static staticMethod(p) { }
|
|
250
|
-
* method(p) { }
|
|
251
|
-
* }
|
|
252
|
-
*
|
|
253
|
-
* // constructor
|
|
254
|
-
* result = Metadata.has("custom:annotation", Example);
|
|
255
|
-
*
|
|
256
|
-
* // property (on constructor)
|
|
257
|
-
* result = Metadata.has("custom:annotation", Example, "staticProperty");
|
|
258
|
-
*
|
|
259
|
-
* // property (on prototype)
|
|
260
|
-
* result = Metadata.has("custom:annotation", Example.prototype, "property");
|
|
261
|
-
*
|
|
262
|
-
* // method (on constructor)
|
|
263
|
-
* result = Metadata.has("custom:annotation", Example, "staticMethod");
|
|
264
|
-
*
|
|
265
|
-
* // method (on prototype)
|
|
266
|
-
* result = Metadata.has("custom:annotation", Example.prototype, "method");
|
|
267
|
-
* ```
|
|
268
|
-
*
|
|
269
|
-
*/
|
|
270
|
-
static has(key, target, propertyKey) {
|
|
271
|
-
try {
|
|
272
|
-
return Reflect.hasMetadata(key, (0, classOf_1.classOf)(target), propertyKey);
|
|
273
|
-
}
|
|
274
|
-
catch (er) { }
|
|
275
|
-
return false;
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Gets a value indicating whether the target object or its prototype chain has the provided metadata key defined.
|
|
279
|
-
* @param key A key used to store and retrieve metadata.
|
|
280
|
-
* @param target The target object on which the metadata is defined.
|
|
281
|
-
* @param propertyKey The property key for the target.
|
|
282
|
-
* @returns `true` if the metadata key was defined on the target object or its prototype chain; otherwise, `false`.
|
|
283
|
-
* @example
|
|
284
|
-
*
|
|
285
|
-
* ```typescript
|
|
286
|
-
* class Example {
|
|
287
|
-
* // property declarations are not part of ES6, though they are valid in TypeScript:
|
|
288
|
-
* // static staticProperty;
|
|
289
|
-
* // property;
|
|
290
|
-
*
|
|
291
|
-
* static staticMethod(p) { }
|
|
292
|
-
* method(p) { }
|
|
293
|
-
* }
|
|
294
|
-
*
|
|
295
|
-
* // constructor
|
|
296
|
-
* result = Metadata.has("custom:annotation", Example);
|
|
297
|
-
*
|
|
298
|
-
* // property (on constructor)
|
|
299
|
-
* result = Metadata.hasOwn("custom:annotation", Example, "staticProperty");
|
|
300
|
-
*
|
|
301
|
-
* // property (on prototype)
|
|
302
|
-
* result = Metadata.hasOwn("custom:annotation", Example.prototype, "property");
|
|
303
|
-
*
|
|
304
|
-
* // method (on constructor)
|
|
305
|
-
* result = Metadata.hasOwn("custom:annotation", Example, "staticMethod");
|
|
306
|
-
*
|
|
307
|
-
* // method (on prototype)
|
|
308
|
-
* result = Metadata.hasOwn("custom:annotation", Example.prototype, "method");
|
|
309
|
-
* ```
|
|
310
|
-
*
|
|
311
|
-
*/
|
|
312
|
-
static hasOwn(key, target, propertyKey) {
|
|
313
|
-
return Reflect.hasOwnMetadata(key, (0, classOf_1.classOf)(target), propertyKey);
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Deletes the metadata entry from the target object with the provided key.
|
|
317
|
-
* @param key A key used to store and retrieve metadata.
|
|
318
|
-
* @param target The target object on which the metadata is defined.
|
|
319
|
-
* @param propertyKey The property key for the target.
|
|
320
|
-
* @returns `true` if the metadata entry was found and deleted; otherwise, false.
|
|
321
|
-
* @example
|
|
322
|
-
*
|
|
323
|
-
* ```typescript
|
|
324
|
-
* class Example {
|
|
325
|
-
* // property declarations are not part of ES6, though they are valid in TypeScript:
|
|
326
|
-
* // static staticProperty;
|
|
327
|
-
* // property;
|
|
328
|
-
*
|
|
329
|
-
* static staticMethod(p) { }
|
|
330
|
-
* method(p) { }
|
|
331
|
-
* }
|
|
332
|
-
*
|
|
333
|
-
* // constructor
|
|
334
|
-
* result = Metadata.delete("custom:annotation", Example);
|
|
335
|
-
*
|
|
336
|
-
* // property (on constructor)
|
|
337
|
-
* result = Metadata.delete("custom:annotation", Example, "staticProperty");
|
|
338
|
-
*
|
|
339
|
-
* // property (on prototype)
|
|
340
|
-
* result = Metadata.delete("custom:annotation", Example.prototype, "property");
|
|
341
|
-
*
|
|
342
|
-
* // method (on constructor)
|
|
343
|
-
* result = Metadata.delete("custom:annotation", Example, "staticMethod");
|
|
344
|
-
*
|
|
345
|
-
* // method (on prototype)
|
|
346
|
-
* result = Metadata.delete("custom:annotation", Example.prototype, "method");
|
|
347
|
-
* ```
|
|
348
|
-
*
|
|
349
|
-
*/
|
|
350
|
-
static delete(key, target, propertyKey) {
|
|
351
|
-
return Reflect.deleteMetadata(key, (0, classOf_1.classOf)(target), propertyKey);
|
|
352
|
-
}
|
|
353
|
-
/**
|
|
354
|
-
* Set the metadata value for the provided metadata DESIGN_PARAM_TYPES on the target object or its prototype chain.
|
|
355
|
-
* @param target The target object on which the metadata is defined.
|
|
356
|
-
* @param propertyKey The property key for the target.
|
|
357
|
-
* @param value A value that contains attached metadata.
|
|
358
|
-
* @returns The metadata value for the metadata key if found; otherwise, `undefined`.
|
|
359
|
-
* @example
|
|
360
|
-
*
|
|
361
|
-
* ```typescript
|
|
362
|
-
* class Example {
|
|
363
|
-
* // property declarations are not part of ES6, though they are valid in TypeScript:
|
|
364
|
-
* // static staticProperty;
|
|
365
|
-
* // property;
|
|
366
|
-
*
|
|
367
|
-
* static staticMethod(p) { }
|
|
368
|
-
* method(p) { }
|
|
369
|
-
* }
|
|
370
|
-
*
|
|
371
|
-
* // on contructor
|
|
372
|
-
* result = Metadata.setParamTypes(Example, undefined, [Object]);
|
|
373
|
-
*
|
|
374
|
-
* // property (on constructor)
|
|
375
|
-
* result = Metadata.setParamTypes(Example, "staticProperty", [Object]);
|
|
376
|
-
*
|
|
377
|
-
* // property (on prototype)
|
|
378
|
-
* result = Metadata.setParamTypes(Example.prototype, "property", [Object]);
|
|
379
|
-
*
|
|
380
|
-
* // method (on constructor)
|
|
381
|
-
* result = Metadata.setParamTypes(Example, "staticMethod", [Object]);
|
|
382
|
-
*
|
|
383
|
-
* // method (on prototype)
|
|
384
|
-
* result = Metadata.setParamTypes(Example.prototype, "method", [Object]);
|
|
385
|
-
* ```
|
|
386
|
-
*
|
|
387
|
-
*/
|
|
388
|
-
static setParamTypes(target, propertyKey, value) {
|
|
389
|
-
return this.set(DESIGN_PARAM_TYPES, value, target.prototype, propertyKey);
|
|
390
|
-
}
|
|
391
|
-
/**
|
|
392
|
-
* Define a unique metadata entry on the target.
|
|
393
|
-
* @param key A key used to store and retrieve metadata.
|
|
394
|
-
* @param value A value that contains attached metadata.
|
|
395
|
-
* @param target The target object on which to define metadata.
|
|
396
|
-
* @param propertyKey The property key for the target.
|
|
397
|
-
* @example
|
|
398
|
-
*
|
|
399
|
-
* ```typescript
|
|
400
|
-
* class Example {
|
|
401
|
-
* // property declarations are not part of ES6, though they are valid in TypeScript:
|
|
402
|
-
* // static staticProperty;
|
|
403
|
-
* // property;
|
|
404
|
-
*
|
|
405
|
-
* static staticMethod(p) { }
|
|
406
|
-
* method(p) { }
|
|
407
|
-
* }
|
|
408
|
-
*
|
|
409
|
-
* // constructor
|
|
410
|
-
* Reflect.defineMetadata("custom:annotation", options, Example);
|
|
411
|
-
*
|
|
412
|
-
* // property (on constructor)
|
|
413
|
-
* Reflect.defineMetadata("custom:annotation", Number, Example, "staticProperty");
|
|
414
|
-
*
|
|
415
|
-
* // property (on prototype)
|
|
416
|
-
* Reflect.defineMetadata("custom:annotation", Number, Example.prototype, "property");
|
|
417
|
-
*
|
|
418
|
-
* // method (on constructor)
|
|
419
|
-
* Reflect.defineMetadata("custom:annotation", Number, Example, "staticMethod");
|
|
420
|
-
*
|
|
421
|
-
* // method (on prototype)
|
|
422
|
-
* Reflect.defineMetadata("custom:annotation", Number, Example.prototype, "method");
|
|
423
|
-
*
|
|
424
|
-
* // decorator factory as metadata-producing annotation.
|
|
425
|
-
* function MyAnnotation(options): PropertyDecorator {
|
|
426
|
-
* return (target, key) => Reflect.defineMetadata("custom:annotation", options, target, key);
|
|
427
|
-
* }
|
|
428
|
-
* ```
|
|
429
|
-
*
|
|
430
|
-
*/
|
|
431
|
-
static set(key, value, target, propertyKey) {
|
|
432
|
-
const targets = PROPERTIES.has(key) ? PROPERTIES.get(key) || [] : [];
|
|
433
|
-
const classConstructor = (0, classOf_1.classOf)(target);
|
|
434
|
-
if (targets.indexOf(classConstructor) === -1) {
|
|
435
|
-
targets.push(classConstructor);
|
|
436
|
-
PROPERTIES.set(key, targets);
|
|
437
|
-
}
|
|
438
|
-
Reflect.defineMetadata(key, value, (0, classOf_1.classOf)(target), propertyKey);
|
|
439
|
-
}
|
|
440
|
-
/**
|
|
441
|
-
* Gets the metadata value for the provided metadata DESIGN_PARAM_TYPES on the target object or its prototype chain.
|
|
442
|
-
* @param targetPrototype
|
|
443
|
-
* @param propertyKey The property key for the target.
|
|
444
|
-
* @returns The metadata value for the metadata key if found; otherwise, `undefined`.
|
|
445
|
-
* @example
|
|
446
|
-
*
|
|
447
|
-
* ```typescript
|
|
448
|
-
* class Example {
|
|
449
|
-
* // property declarations are not part of ES6, though they are valid in TypeScript:
|
|
450
|
-
* // static staticProperty;
|
|
451
|
-
* // property;
|
|
452
|
-
*
|
|
453
|
-
* static staticMethod(p) { }
|
|
454
|
-
* method(p) { }
|
|
455
|
-
* }
|
|
456
|
-
*
|
|
457
|
-
* // on contructor
|
|
458
|
-
* result = Metadata.getParamTypes(Example.prototype);
|
|
459
|
-
*
|
|
460
|
-
* // property (on constructor)
|
|
461
|
-
* result = Metadata.getParamTypes(Example.prototype, "staticProperty");
|
|
462
|
-
*
|
|
463
|
-
* // method (on constructor)
|
|
464
|
-
* result = Metadata.getParamTypes(Example.prototype, "staticMethod");
|
|
465
|
-
* ```
|
|
466
|
-
*
|
|
467
|
-
*/
|
|
468
|
-
static getParamTypes(targetPrototype, propertyKey) {
|
|
469
|
-
return Reflect.getMetadata(DESIGN_PARAM_TYPES, targetPrototype, propertyKey) || [];
|
|
470
|
-
}
|
|
471
|
-
/**
|
|
472
|
-
* Gets the metadata value for the provided metadata DESIGN_PARAM_TYPES on the target object or its prototype chain.
|
|
473
|
-
* @param target The target object on which the metadata is defined.
|
|
474
|
-
* @param propertyKey The property key for the target.
|
|
475
|
-
* @returns The metadata value for the metadata key if found; otherwise, `undefined`.
|
|
476
|
-
* @example
|
|
477
|
-
*
|
|
478
|
-
* ```typescript
|
|
479
|
-
* class Example {
|
|
480
|
-
* // property declarations are not part of ES6, though they are valid in TypeScript:
|
|
481
|
-
* // static staticProperty;
|
|
482
|
-
* // property;
|
|
483
|
-
*
|
|
484
|
-
* static staticMethod(p) { }
|
|
485
|
-
* method(p) { }
|
|
486
|
-
* }
|
|
487
|
-
*
|
|
488
|
-
* // on contructor
|
|
489
|
-
* result = Metadata.getParamTypes(Example);
|
|
490
|
-
*
|
|
491
|
-
* // property (on constructor)
|
|
492
|
-
* result = Metadata.getParamTypes(Example, "staticProperty");
|
|
493
|
-
*
|
|
494
|
-
* // method (on constructor)
|
|
495
|
-
* result = Metadata.getParamTypes(Example, "staticMethod");
|
|
496
|
-
* ```
|
|
497
|
-
*
|
|
498
|
-
*/
|
|
499
|
-
static getOwnParamTypes(target, propertyKey) {
|
|
500
|
-
return Reflect.getOwnMetadata(DESIGN_PARAM_TYPES, target, propertyKey) || [];
|
|
501
|
-
}
|
|
502
|
-
static getParamDecoratorFunc(target, propertyKey) {
|
|
503
|
-
return Reflect.getMetadata(constants_1.ROUTE_PARAM, target.constructor, propertyKey);
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
exports.Metadata = Metadata;
|
|
507
|
-
/**
|
|
508
|
-
* Get all metadata for a metadataKey.
|
|
509
|
-
* @param metadataKey
|
|
510
|
-
*/
|
|
511
|
-
Metadata.getTargetsFromPropertyKey = (metadataKey) => PROPERTIES.has(metadataKey) ? PROPERTIES.get(metadataKey) || [] : [];
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export type CorsOrigin = string | string[] | RegExp | ((origin: string) => boolean);
|
|
2
|
-
export interface CorsConfig {
|
|
3
|
-
origins: CorsOrigin;
|
|
4
|
-
methods?: string[];
|
|
5
|
-
allowedHeaders?: string[];
|
|
6
|
-
exposedHeaders?: string[];
|
|
7
|
-
credentials?: boolean;
|
|
8
|
-
maxAge?: number;
|
|
9
|
-
preflightContinue?: boolean;
|
|
10
|
-
}
|
|
11
|
-
export declare const DEFAULT_CORS_METHODS: string[];
|
|
12
|
-
export declare const DEFAULT_CORS_ALLOWED_HEADERS: string[];
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_CORS_ALLOWED_HEADERS = exports.DEFAULT_CORS_METHODS = void 0;
|
|
4
|
-
exports.DEFAULT_CORS_METHODS = [
|
|
5
|
-
"GET",
|
|
6
|
-
"HEAD",
|
|
7
|
-
"PUT",
|
|
8
|
-
"PATCH",
|
|
9
|
-
"POST",
|
|
10
|
-
"DELETE",
|
|
11
|
-
];
|
|
12
|
-
exports.DEFAULT_CORS_ALLOWED_HEADERS = [
|
|
13
|
-
"Content-Type",
|
|
14
|
-
"Authorization",
|
|
15
|
-
"X-Requested-With",
|
|
16
|
-
"Accept",
|
|
17
|
-
"Origin",
|
|
18
|
-
];
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { CorsConfig } from './cors-config';
|
|
2
|
-
export declare class CorsHeadersCache {
|
|
3
|
-
private readonly config;
|
|
4
|
-
private readonly cache;
|
|
5
|
-
private readonly methodsString;
|
|
6
|
-
private readonly allowedHeadersString;
|
|
7
|
-
private readonly exposedHeadersString;
|
|
8
|
-
private readonly maxAgeString;
|
|
9
|
-
private readonly hasCredentials;
|
|
10
|
-
private readonly isWildcard;
|
|
11
|
-
private readonly originAllowed;
|
|
12
|
-
constructor(config: CorsConfig);
|
|
13
|
-
get(origin: string): Record<string, string>;
|
|
14
|
-
private buildHeaders;
|
|
15
|
-
applyToResponse(response: Response, origin: string): Response;
|
|
16
|
-
isOriginAllowed(origin: string): boolean;
|
|
17
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CorsHeadersCache = void 0;
|
|
4
|
-
const cors_config_1 = require("./cors-config");
|
|
5
|
-
const allowAnyOrigin = () => {
|
|
6
|
-
return true;
|
|
7
|
-
};
|
|
8
|
-
const denyAnyOrigin = () => {
|
|
9
|
-
return false;
|
|
10
|
-
};
|
|
11
|
-
function buildOriginAllowed(origins) {
|
|
12
|
-
if (origins === '*') {
|
|
13
|
-
return allowAnyOrigin;
|
|
14
|
-
}
|
|
15
|
-
if (typeof origins === 'string') {
|
|
16
|
-
return createExactOriginMatcher(origins);
|
|
17
|
-
}
|
|
18
|
-
if (Array.isArray(origins)) {
|
|
19
|
-
return createSetOriginMatcher(origins);
|
|
20
|
-
}
|
|
21
|
-
if (origins instanceof RegExp) {
|
|
22
|
-
return createRegexOriginMatcher(origins);
|
|
23
|
-
}
|
|
24
|
-
if (typeof origins === 'function') {
|
|
25
|
-
return origins;
|
|
26
|
-
}
|
|
27
|
-
return denyAnyOrigin;
|
|
28
|
-
}
|
|
29
|
-
function createExactOriginMatcher(origin) {
|
|
30
|
-
return (value) => {
|
|
31
|
-
return value === origin;
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
function createSetOriginMatcher(origins) {
|
|
35
|
-
const originSet = new Set(origins);
|
|
36
|
-
return (value) => {
|
|
37
|
-
return originSet.has(value);
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
function createRegexOriginMatcher(origins) {
|
|
41
|
-
return (value) => {
|
|
42
|
-
return origins.test(value);
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
class CorsHeadersCache {
|
|
46
|
-
constructor(config) {
|
|
47
|
-
this.config = config;
|
|
48
|
-
this.cache = new Map();
|
|
49
|
-
const methods = config.methods || cors_config_1.DEFAULT_CORS_METHODS;
|
|
50
|
-
this.methodsString = methods.join(', ');
|
|
51
|
-
const allowedHeaders = config.allowedHeaders || cors_config_1.DEFAULT_CORS_ALLOWED_HEADERS;
|
|
52
|
-
this.allowedHeadersString = allowedHeaders.join(', ');
|
|
53
|
-
this.exposedHeadersString = config.exposedHeaders?.length
|
|
54
|
-
? config.exposedHeaders.join(', ')
|
|
55
|
-
: null;
|
|
56
|
-
this.maxAgeString = config.maxAge !== undefined
|
|
57
|
-
? config.maxAge.toString()
|
|
58
|
-
: null;
|
|
59
|
-
this.hasCredentials = !!config.credentials;
|
|
60
|
-
this.isWildcard = config.origins === '*';
|
|
61
|
-
this.originAllowed = buildOriginAllowed(config.origins);
|
|
62
|
-
}
|
|
63
|
-
get(origin) {
|
|
64
|
-
const cacheKey = this.isWildcard ? '*' : origin;
|
|
65
|
-
let cached = this.cache.get(cacheKey);
|
|
66
|
-
if (cached) {
|
|
67
|
-
return cached;
|
|
68
|
-
}
|
|
69
|
-
cached = this.buildHeaders(origin);
|
|
70
|
-
this.cache.set(cacheKey, cached);
|
|
71
|
-
return cached;
|
|
72
|
-
}
|
|
73
|
-
buildHeaders(origin) {
|
|
74
|
-
const headers = {
|
|
75
|
-
'Access-Control-Allow-Origin': this.isWildcard ? '*' : origin,
|
|
76
|
-
'Access-Control-Allow-Methods': this.methodsString,
|
|
77
|
-
'Access-Control-Allow-Headers': this.allowedHeadersString,
|
|
78
|
-
};
|
|
79
|
-
if (this.hasCredentials) {
|
|
80
|
-
headers['Access-Control-Allow-Credentials'] = 'true';
|
|
81
|
-
}
|
|
82
|
-
if (this.exposedHeadersString) {
|
|
83
|
-
headers['Access-Control-Expose-Headers'] = this.exposedHeadersString;
|
|
84
|
-
}
|
|
85
|
-
if (this.maxAgeString) {
|
|
86
|
-
headers['Access-Control-Max-Age'] = this.maxAgeString;
|
|
87
|
-
}
|
|
88
|
-
return headers;
|
|
89
|
-
}
|
|
90
|
-
applyToResponse(response, origin) {
|
|
91
|
-
const corsHeaders = this.get(origin);
|
|
92
|
-
for (const key in corsHeaders) {
|
|
93
|
-
response.headers.set(key, corsHeaders[key]);
|
|
94
|
-
}
|
|
95
|
-
return response;
|
|
96
|
-
}
|
|
97
|
-
isOriginAllowed(origin) {
|
|
98
|
-
return this.originAllowed(origin);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
exports.CorsHeadersCache = CorsHeadersCache;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.HttpMethod = void 0;
|
|
4
|
-
var HttpMethod;
|
|
5
|
-
(function (HttpMethod) {
|
|
6
|
-
HttpMethod["GET"] = "get";
|
|
7
|
-
HttpMethod["PUT"] = "put";
|
|
8
|
-
HttpMethod["POST"] = "post";
|
|
9
|
-
HttpMethod["DELETE"] = "delete";
|
|
10
|
-
HttpMethod["PATCH"] = "patch";
|
|
11
|
-
})(HttpMethod || (exports.HttpMethod = HttpMethod = {}));
|
package/dist/domain/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export * from './provider-scope';
|
|
2
|
-
export * from './provider-type';
|
|
3
|
-
export * from './Context';
|
|
4
|
-
export * from './LocalsContainer';
|
|
5
|
-
export * from './Metadata';
|
|
6
|
-
export * from './provider';
|
|
7
|
-
export * from './CarnoMiddleware';
|
|
8
|
-
export * from './CarnoClosure';
|
|
9
|
-
export * from './http-method';
|
|
10
|
-
export * from './cors-config';
|