@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/route/memoirist.js
DELETED
|
@@ -1,373 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Memoirist = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* * Empty object shared for static routes without parameters.
|
|
6
|
-
* * Frozen for V8 optimization and immutability.
|
|
7
|
-
* * Avoid allocating an empty object on every request in static routes.
|
|
8
|
-
* */
|
|
9
|
-
const EMPTY_PARAMS = Object.freeze({});
|
|
10
|
-
const createNode = (part, inert) => ({
|
|
11
|
-
part,
|
|
12
|
-
store: null,
|
|
13
|
-
inert: inert !== undefined
|
|
14
|
-
? new Map(inert.map((child) => [child.part.charCodeAt(0), child]))
|
|
15
|
-
: null,
|
|
16
|
-
params: null,
|
|
17
|
-
wildcardStore: null
|
|
18
|
-
});
|
|
19
|
-
const cloneNode = (node, part) => ({
|
|
20
|
-
...node,
|
|
21
|
-
part
|
|
22
|
-
});
|
|
23
|
-
const createParamNode = () => ({
|
|
24
|
-
paramName: null,
|
|
25
|
-
names: new Map(),
|
|
26
|
-
store: null,
|
|
27
|
-
inert: null
|
|
28
|
-
});
|
|
29
|
-
const ensureSameNameForStore = (param, store, name) => {
|
|
30
|
-
const existing = param.names.get(store);
|
|
31
|
-
if (!existing || existing === name)
|
|
32
|
-
return;
|
|
33
|
-
throw new Error(`Route already registered with parameter "${existing}" for this handler`);
|
|
34
|
-
};
|
|
35
|
-
const ensureDefaultName = (param, name) => {
|
|
36
|
-
if (param.paramName)
|
|
37
|
-
return;
|
|
38
|
-
param.paramName = name;
|
|
39
|
-
};
|
|
40
|
-
const persistStoreName = (param, store, name) => {
|
|
41
|
-
if (param.names.has(store))
|
|
42
|
-
return;
|
|
43
|
-
param.names.set(store, name);
|
|
44
|
-
};
|
|
45
|
-
const registerParamName = (param, store, name) => {
|
|
46
|
-
ensureSameNameForStore(param, store, name);
|
|
47
|
-
ensureDefaultName(param, name);
|
|
48
|
-
persistStoreName(param, store, name);
|
|
49
|
-
};
|
|
50
|
-
const resolveParamName = (param, store) => {
|
|
51
|
-
if (store && param.names.has(store)) {
|
|
52
|
-
return param.names.get(store);
|
|
53
|
-
}
|
|
54
|
-
if (param.paramName) {
|
|
55
|
-
return param.paramName;
|
|
56
|
-
}
|
|
57
|
-
throw new Error('Unable to resolve parameter name for route');
|
|
58
|
-
};
|
|
59
|
-
class Memoirist {
|
|
60
|
-
constructor() {
|
|
61
|
-
this.root = {};
|
|
62
|
-
this.history = [];
|
|
63
|
-
this.routeCache = new Map();
|
|
64
|
-
}
|
|
65
|
-
add(method, path, store) {
|
|
66
|
-
if (typeof path !== 'string')
|
|
67
|
-
throw new TypeError('Route path must be a string');
|
|
68
|
-
if (path === '')
|
|
69
|
-
path = '/';
|
|
70
|
-
else if (path[0] !== '/')
|
|
71
|
-
path = `/${path}`;
|
|
72
|
-
this.invalidateCache();
|
|
73
|
-
this.history.push([method, path, store]);
|
|
74
|
-
const isWildcard = path[path.length - 1] === '*';
|
|
75
|
-
if (isWildcard) {
|
|
76
|
-
// Slice off trailing '*'
|
|
77
|
-
path = path.slice(0, -1);
|
|
78
|
-
}
|
|
79
|
-
const inertParts = path.split(Memoirist.regex.static);
|
|
80
|
-
const paramParts = path.match(Memoirist.regex.params) || [];
|
|
81
|
-
if (inertParts[inertParts.length - 1] === '')
|
|
82
|
-
inertParts.pop();
|
|
83
|
-
let node;
|
|
84
|
-
if (!this.root[method])
|
|
85
|
-
node = this.root[method] = createNode('/');
|
|
86
|
-
else
|
|
87
|
-
node = this.root[method];
|
|
88
|
-
let paramPartsIndex = 0;
|
|
89
|
-
for (let i = 0; i < inertParts.length; ++i) {
|
|
90
|
-
let part = inertParts[i];
|
|
91
|
-
if (i > 0) {
|
|
92
|
-
// Set param on the node
|
|
93
|
-
const param = paramParts[paramPartsIndex++].slice(1);
|
|
94
|
-
if (node.params === null) {
|
|
95
|
-
node.params = createParamNode();
|
|
96
|
-
}
|
|
97
|
-
registerParamName(node.params, store, param);
|
|
98
|
-
const params = node.params;
|
|
99
|
-
if (params.inert === null) {
|
|
100
|
-
node = params.inert = createNode(part);
|
|
101
|
-
continue;
|
|
102
|
-
}
|
|
103
|
-
node = params.inert;
|
|
104
|
-
}
|
|
105
|
-
for (let j = 0;;) {
|
|
106
|
-
if (j === part.length) {
|
|
107
|
-
if (j < node.part.length) {
|
|
108
|
-
// Move the current node down
|
|
109
|
-
const childNode = cloneNode(node, node.part.slice(j));
|
|
110
|
-
Object.assign(node, createNode(part, [childNode]));
|
|
111
|
-
}
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
if (j === node.part.length) {
|
|
115
|
-
// Add static child
|
|
116
|
-
if (node.inert === null)
|
|
117
|
-
node.inert = new Map();
|
|
118
|
-
else if (node.inert.has(part.charCodeAt(j))) {
|
|
119
|
-
// Re-run loop with existing static node
|
|
120
|
-
node = node.inert.get(part.charCodeAt(j));
|
|
121
|
-
part = part.slice(j);
|
|
122
|
-
j = 0;
|
|
123
|
-
continue;
|
|
124
|
-
}
|
|
125
|
-
// Create new node
|
|
126
|
-
const childNode = createNode(part.slice(j));
|
|
127
|
-
node.inert.set(part.charCodeAt(j), childNode);
|
|
128
|
-
node = childNode;
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
if (part[j] !== node.part[j]) {
|
|
132
|
-
// Split the node
|
|
133
|
-
const existingChild = cloneNode(node, node.part.slice(j));
|
|
134
|
-
const newChild = createNode(part.slice(j));
|
|
135
|
-
Object.assign(node, createNode(node.part.slice(0, j), [
|
|
136
|
-
existingChild,
|
|
137
|
-
newChild
|
|
138
|
-
]));
|
|
139
|
-
node = newChild;
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
++j;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
if (paramPartsIndex < paramParts.length) {
|
|
146
|
-
// The final part is a parameter
|
|
147
|
-
const param = paramParts[paramPartsIndex];
|
|
148
|
-
const paramName = param.slice(1);
|
|
149
|
-
if (node.params === null) {
|
|
150
|
-
node.params = createParamNode();
|
|
151
|
-
}
|
|
152
|
-
registerParamName(node.params, store, paramName);
|
|
153
|
-
if (node.params.store === null) {
|
|
154
|
-
node.params.store = store;
|
|
155
|
-
}
|
|
156
|
-
else if (node.params.store !== store) {
|
|
157
|
-
throw new Error(`Route "${path}" already registered`);
|
|
158
|
-
}
|
|
159
|
-
return node.params.store;
|
|
160
|
-
}
|
|
161
|
-
if (isWildcard) {
|
|
162
|
-
// The final part is a wildcard
|
|
163
|
-
if (node.wildcardStore === null)
|
|
164
|
-
node.wildcardStore = store;
|
|
165
|
-
return node.wildcardStore;
|
|
166
|
-
}
|
|
167
|
-
// The final part is static
|
|
168
|
-
if (node.store === null)
|
|
169
|
-
node.store = store;
|
|
170
|
-
return node.store;
|
|
171
|
-
}
|
|
172
|
-
find(method, url) {
|
|
173
|
-
let methodCache = this.routeCache.get(url);
|
|
174
|
-
if (methodCache && methodCache[method] !== undefined) {
|
|
175
|
-
return methodCache[method];
|
|
176
|
-
}
|
|
177
|
-
const root = this.root[method];
|
|
178
|
-
if (!root)
|
|
179
|
-
return null;
|
|
180
|
-
const result = matchRoute(url, url.length, root, 0);
|
|
181
|
-
if (!methodCache) {
|
|
182
|
-
methodCache = {};
|
|
183
|
-
this.routeCache.set(url, methodCache);
|
|
184
|
-
}
|
|
185
|
-
methodCache[method] = result;
|
|
186
|
-
return result;
|
|
187
|
-
}
|
|
188
|
-
updateStore(method, path, oldStore, newStore) {
|
|
189
|
-
const node = this.findNode(method, path);
|
|
190
|
-
if (!node) {
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
if (node.store === oldStore) {
|
|
194
|
-
node.store = newStore;
|
|
195
|
-
this.updateHistoryStore(method, path, newStore);
|
|
196
|
-
this.invalidateCache();
|
|
197
|
-
return true;
|
|
198
|
-
}
|
|
199
|
-
if (node.params?.store === oldStore) {
|
|
200
|
-
node.params.store = newStore;
|
|
201
|
-
const paramName = node.params.names.get(oldStore);
|
|
202
|
-
if (paramName) {
|
|
203
|
-
node.params.names.set(newStore, paramName);
|
|
204
|
-
}
|
|
205
|
-
this.updateHistoryStore(method, path, newStore);
|
|
206
|
-
this.invalidateCache();
|
|
207
|
-
return true;
|
|
208
|
-
}
|
|
209
|
-
if (node.wildcardStore === oldStore) {
|
|
210
|
-
node.wildcardStore = newStore;
|
|
211
|
-
this.updateHistoryStore(method, path, newStore);
|
|
212
|
-
this.invalidateCache();
|
|
213
|
-
return true;
|
|
214
|
-
}
|
|
215
|
-
return false;
|
|
216
|
-
}
|
|
217
|
-
invalidateCache() {
|
|
218
|
-
this.routeCache.clear();
|
|
219
|
-
}
|
|
220
|
-
updateHistoryStore(method, path, newStore) {
|
|
221
|
-
const normalizedPath = this.normalizePath(path);
|
|
222
|
-
for (let i = 0; i < this.history.length; i++) {
|
|
223
|
-
const [m, p] = this.history[i];
|
|
224
|
-
if (m === method && this.normalizePath(p) === normalizedPath) {
|
|
225
|
-
this.history[i] = [method, p, newStore];
|
|
226
|
-
break;
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
normalizePath(path) {
|
|
231
|
-
if (path === '') {
|
|
232
|
-
return '/';
|
|
233
|
-
}
|
|
234
|
-
return path[0] !== '/' ? `/${path}` : path;
|
|
235
|
-
}
|
|
236
|
-
findNode(method, path) {
|
|
237
|
-
if (path === '') {
|
|
238
|
-
path = '/';
|
|
239
|
-
}
|
|
240
|
-
else if (path[0] !== '/') {
|
|
241
|
-
path = `/${path}`;
|
|
242
|
-
}
|
|
243
|
-
const isWildcard = path[path.length - 1] === '*';
|
|
244
|
-
if (isWildcard) {
|
|
245
|
-
path = path.slice(0, -1);
|
|
246
|
-
}
|
|
247
|
-
const inertParts = path.split(Memoirist.regex.static);
|
|
248
|
-
const paramParts = path.match(Memoirist.regex.params) || [];
|
|
249
|
-
if (inertParts[inertParts.length - 1] === '') {
|
|
250
|
-
inertParts.pop();
|
|
251
|
-
}
|
|
252
|
-
let node = this.root[method];
|
|
253
|
-
if (!node) {
|
|
254
|
-
return null;
|
|
255
|
-
}
|
|
256
|
-
let paramPartsIndex = 0;
|
|
257
|
-
for (let i = 0; i < inertParts.length; ++i) {
|
|
258
|
-
let part = inertParts[i];
|
|
259
|
-
if (i > 0) {
|
|
260
|
-
paramPartsIndex++;
|
|
261
|
-
if (!node.params?.inert) {
|
|
262
|
-
return null;
|
|
263
|
-
}
|
|
264
|
-
node = node.params.inert;
|
|
265
|
-
}
|
|
266
|
-
for (let j = 0;;) {
|
|
267
|
-
if (j === part.length) {
|
|
268
|
-
break;
|
|
269
|
-
}
|
|
270
|
-
if (j === node.part.length) {
|
|
271
|
-
if (!node.inert?.has(part.charCodeAt(j))) {
|
|
272
|
-
return null;
|
|
273
|
-
}
|
|
274
|
-
node = node.inert.get(part.charCodeAt(j));
|
|
275
|
-
part = part.slice(j);
|
|
276
|
-
j = 0;
|
|
277
|
-
continue;
|
|
278
|
-
}
|
|
279
|
-
if (part[j] !== node.part[j]) {
|
|
280
|
-
return null;
|
|
281
|
-
}
|
|
282
|
-
++j;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
return node;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
exports.Memoirist = Memoirist;
|
|
289
|
-
Memoirist.regex = {
|
|
290
|
-
static: /:[^/]+/,
|
|
291
|
-
params: /:[^/]+/g
|
|
292
|
-
};
|
|
293
|
-
const matchRoute = (url, urlLength, node, startIndex) => {
|
|
294
|
-
const part = node?.part;
|
|
295
|
-
const endIndex = startIndex + part.length;
|
|
296
|
-
// Only check the pathPart if its length is > 1 since the parent has
|
|
297
|
-
// already checked that the url matches the first character
|
|
298
|
-
if (part.length > 1) {
|
|
299
|
-
if (endIndex > urlLength)
|
|
300
|
-
return null;
|
|
301
|
-
if (part.length < 15) {
|
|
302
|
-
// Using a loop is faster for short strings
|
|
303
|
-
for (let i = 1, j = startIndex + 1; i < part.length; ++i, ++j)
|
|
304
|
-
if (part.charCodeAt(i) !== url.charCodeAt(j))
|
|
305
|
-
return null;
|
|
306
|
-
}
|
|
307
|
-
else if (url.substring(startIndex, endIndex) !== part)
|
|
308
|
-
return null;
|
|
309
|
-
}
|
|
310
|
-
if (endIndex === urlLength) {
|
|
311
|
-
// Reached the end of the URL
|
|
312
|
-
if (node.store !== null)
|
|
313
|
-
return {
|
|
314
|
-
store: node.store,
|
|
315
|
-
params: EMPTY_PARAMS
|
|
316
|
-
};
|
|
317
|
-
if (node.wildcardStore !== null)
|
|
318
|
-
return {
|
|
319
|
-
store: node.wildcardStore,
|
|
320
|
-
params: { '*': '' }
|
|
321
|
-
};
|
|
322
|
-
return null;
|
|
323
|
-
}
|
|
324
|
-
if (node.inert !== null) {
|
|
325
|
-
const inert = node.inert.get(url.charCodeAt(endIndex));
|
|
326
|
-
if (inert !== undefined) {
|
|
327
|
-
const route = matchRoute(url, urlLength, inert, endIndex);
|
|
328
|
-
if (route !== null)
|
|
329
|
-
return route;
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
if (node.params !== null) {
|
|
333
|
-
const param = node.params;
|
|
334
|
-
const slashIndex = url.indexOf('/', endIndex);
|
|
335
|
-
if (slashIndex !== endIndex) {
|
|
336
|
-
// Params cannot be empty
|
|
337
|
-
if (slashIndex === -1 || slashIndex >= urlLength) {
|
|
338
|
-
if (param.store !== null) {
|
|
339
|
-
const params = {};
|
|
340
|
-
const paramName = resolveParamName(param, param.store);
|
|
341
|
-
params[paramName] = url.substring(endIndex, urlLength);
|
|
342
|
-
return {
|
|
343
|
-
store: param.store,
|
|
344
|
-
params
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
else if (param.inert !== null) {
|
|
349
|
-
const route = matchRoute(url, urlLength, param.inert, slashIndex);
|
|
350
|
-
if (route !== null) {
|
|
351
|
-
const paramName = resolveParamName(param, route.store);
|
|
352
|
-
const paramValue = url.substring(endIndex, slashIndex);
|
|
353
|
-
if (route.params === EMPTY_PARAMS) {
|
|
354
|
-
route.params = { [paramName]: paramValue };
|
|
355
|
-
}
|
|
356
|
-
else {
|
|
357
|
-
route.params[paramName] = paramValue;
|
|
358
|
-
}
|
|
359
|
-
return route;
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
if (node.wildcardStore !== null)
|
|
365
|
-
return {
|
|
366
|
-
store: node.wildcardStore,
|
|
367
|
-
params: {
|
|
368
|
-
'*': url.substring(endIndex, urlLength)
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
return null;
|
|
372
|
-
};
|
|
373
|
-
exports.default = Memoirist;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import Pino from "pino";
|
|
2
|
-
import { InjectorService } from "../container/InjectorService";
|
|
3
|
-
export interface LoggerAdapter {
|
|
4
|
-
info(message: string, ...args: any[]): void;
|
|
5
|
-
warn(message: string, ...args: any[]): void;
|
|
6
|
-
error(message: string, ...args: any[]): void;
|
|
7
|
-
debug(message: string, ...args: any[]): void;
|
|
8
|
-
fatal(message: string, ...args: any[]): void;
|
|
9
|
-
trace(message: string, ...args: any[]): void;
|
|
10
|
-
}
|
|
11
|
-
export declare class LoggerService implements LoggerAdapter {
|
|
12
|
-
private injector;
|
|
13
|
-
private logger;
|
|
14
|
-
constructor(injector: InjectorService);
|
|
15
|
-
child(bindings: Record<string, any>): LoggerAdapter;
|
|
16
|
-
info(message: string, ...args: any[]): void;
|
|
17
|
-
warn(message: string, ...args: any[]): void;
|
|
18
|
-
error(message: string, ...args: any[]): void;
|
|
19
|
-
debug(message: string, ...args: any[]): void;
|
|
20
|
-
fatal(message: string, ...args: any[]): void;
|
|
21
|
-
trace(message: string, ...args: any[]): void;
|
|
22
|
-
getLogger(): Pino.Logger;
|
|
23
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.LoggerService = void 0;
|
|
7
|
-
const pino_1 = __importDefault(require("pino"));
|
|
8
|
-
class LoggerService {
|
|
9
|
-
constructor(injector) {
|
|
10
|
-
this.injector = injector;
|
|
11
|
-
const pinoConfig = this.injector.applicationConfig.logger || {};
|
|
12
|
-
this.logger = (0, pino_1.default)(pinoConfig);
|
|
13
|
-
}
|
|
14
|
-
child(bindings) {
|
|
15
|
-
const child = this.logger.child(bindings);
|
|
16
|
-
return {
|
|
17
|
-
info: (message, ...args) => child.info(message, ...args),
|
|
18
|
-
warn: (message, ...args) => child.warn(message, ...args),
|
|
19
|
-
error: (message, ...args) => child.error(message, ...args),
|
|
20
|
-
debug: (message, ...args) => child.debug(message, ...args),
|
|
21
|
-
fatal: (message, ...args) => child.fatal(message, ...args),
|
|
22
|
-
trace: (message, ...args) => child.trace(message, ...args),
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
info(message, ...args) {
|
|
26
|
-
this.logger.info(message, ...args);
|
|
27
|
-
}
|
|
28
|
-
warn(message, ...args) {
|
|
29
|
-
this.logger.warn(message, ...args);
|
|
30
|
-
}
|
|
31
|
-
error(message, ...args) {
|
|
32
|
-
this.logger.error(message, ...args);
|
|
33
|
-
}
|
|
34
|
-
debug(message, ...args) {
|
|
35
|
-
this.logger.debug(message, ...args);
|
|
36
|
-
}
|
|
37
|
-
fatal(message, ...args) {
|
|
38
|
-
this.logger.fatal(message, ...args);
|
|
39
|
-
}
|
|
40
|
-
trace(message, ...args) {
|
|
41
|
-
this.logger.trace(message, ...args);
|
|
42
|
-
}
|
|
43
|
-
getLogger() {
|
|
44
|
-
return this.logger;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.LoggerService = LoggerService;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { Server } from 'bun';
|
|
2
|
-
import { Carno, ApplicationConfig } from '../Carno';
|
|
3
|
-
import { TokenProvider, Type } from '../commons';
|
|
4
|
-
import { InjectorService } from '../container/InjectorService';
|
|
5
|
-
export type CoreTestOptions = {
|
|
6
|
-
config?: ApplicationConfig;
|
|
7
|
-
listen?: boolean | number;
|
|
8
|
-
port?: number;
|
|
9
|
-
plugins?: CoreTestPlugin[];
|
|
10
|
-
};
|
|
11
|
-
export type CoreTestPlugin = Carno | (() => Carno);
|
|
12
|
-
export type CoreTestHarness = {
|
|
13
|
-
app: Carno;
|
|
14
|
-
injector: InjectorService;
|
|
15
|
-
server?: Server<any>;
|
|
16
|
-
port?: number;
|
|
17
|
-
resolve<T>(token: Type<T>): T;
|
|
18
|
-
resolve<T>(token: TokenProvider<T>): T;
|
|
19
|
-
request(target: string | URL, init?: RequestInit): Promise<Response>;
|
|
20
|
-
close(): Promise<void>;
|
|
21
|
-
};
|
|
22
|
-
export type CoreTestRoutine = (harness: CoreTestHarness) => Promise<void>;
|
|
23
|
-
export declare function createCoreTestHarness(options?: CoreTestOptions): Promise<CoreTestHarness>;
|
|
24
|
-
export declare function withCoreApplication(routine: CoreTestRoutine, options?: CoreTestOptions): Promise<void>;
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createCoreTestHarness = createCoreTestHarness;
|
|
4
|
-
exports.withCoreApplication = withCoreApplication;
|
|
5
|
-
const Carno_1 = require("../Carno");
|
|
6
|
-
async function createCoreTestHarness(options = {}) {
|
|
7
|
-
const config = { ...options.config };
|
|
8
|
-
if (config.disableStartupLog === undefined) {
|
|
9
|
-
config.disableStartupLog = true;
|
|
10
|
-
}
|
|
11
|
-
const app = new Carno_1.Carno(config);
|
|
12
|
-
applyPlugins(app, options.plugins);
|
|
13
|
-
const boot = await bootApplication(app, options);
|
|
14
|
-
const injector = app.getInjector();
|
|
15
|
-
const resolve = (token) => {
|
|
16
|
-
return injector.invoke(token);
|
|
17
|
-
};
|
|
18
|
-
const request = async (target, init) => {
|
|
19
|
-
if (!boot.server) {
|
|
20
|
-
throw new Error('HTTP server is not running. Enable the listen option to issue requests.');
|
|
21
|
-
}
|
|
22
|
-
const url = buildRequestUrl(boot.port ?? boot.server.port, target);
|
|
23
|
-
return fetch(url, init);
|
|
24
|
-
};
|
|
25
|
-
const close = async () => shutdown(app, boot.server);
|
|
26
|
-
return {
|
|
27
|
-
app,
|
|
28
|
-
injector,
|
|
29
|
-
server: boot.server,
|
|
30
|
-
port: boot.port ?? boot.server?.port,
|
|
31
|
-
resolve,
|
|
32
|
-
request,
|
|
33
|
-
close,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
async function withCoreApplication(routine, options = {}) {
|
|
37
|
-
const harness = await createCoreTestHarness(options);
|
|
38
|
-
try {
|
|
39
|
-
await routine(harness);
|
|
40
|
-
}
|
|
41
|
-
finally {
|
|
42
|
-
await harness.close();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
async function bootApplication(app, options) {
|
|
46
|
-
if (!shouldListen(options.listen)) {
|
|
47
|
-
await app.init();
|
|
48
|
-
return {};
|
|
49
|
-
}
|
|
50
|
-
const port = resolveListenPort(options);
|
|
51
|
-
await app.listen(port);
|
|
52
|
-
const server = app.getHttpServer();
|
|
53
|
-
const runningPort = server?.port ?? port;
|
|
54
|
-
return { server, port: runningPort };
|
|
55
|
-
}
|
|
56
|
-
function shouldListen(value) {
|
|
57
|
-
if (typeof value === 'number') {
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
return Boolean(value);
|
|
61
|
-
}
|
|
62
|
-
function resolveListenPort(options) {
|
|
63
|
-
if (typeof options.listen === 'number') {
|
|
64
|
-
return options.listen;
|
|
65
|
-
}
|
|
66
|
-
if (typeof options.port === 'number') {
|
|
67
|
-
return options.port;
|
|
68
|
-
}
|
|
69
|
-
return 0;
|
|
70
|
-
}
|
|
71
|
-
function buildRequestUrl(port, target) {
|
|
72
|
-
if (target instanceof URL) {
|
|
73
|
-
return target.toString();
|
|
74
|
-
}
|
|
75
|
-
if (isAbsoluteUrl(target)) {
|
|
76
|
-
return target;
|
|
77
|
-
}
|
|
78
|
-
const path = target.startsWith('/') ? target : `/${target}`;
|
|
79
|
-
return `http://127.0.0.1:${port}${path}`;
|
|
80
|
-
}
|
|
81
|
-
function isAbsoluteUrl(target) {
|
|
82
|
-
return /^https?:\/\//i.test(target);
|
|
83
|
-
}
|
|
84
|
-
async function shutdown(app, server) {
|
|
85
|
-
if (!server) {
|
|
86
|
-
app.close();
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
app.close(true);
|
|
90
|
-
}
|
|
91
|
-
function applyPlugins(app, plugins) {
|
|
92
|
-
if (!plugins?.length) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
plugins.forEach((plugin) => app.use(resolvePlugin(plugin)));
|
|
96
|
-
}
|
|
97
|
-
function resolvePlugin(entry) {
|
|
98
|
-
if (typeof entry === 'function') {
|
|
99
|
-
return entry();
|
|
100
|
-
}
|
|
101
|
-
return entry;
|
|
102
|
-
}
|
package/dist/testing/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './core-testing';
|
package/dist/testing/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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("./core-testing"), exports);
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { ValidatorAdapter } from '../validation/ValidatorAdapter';
|
|
2
|
-
export declare function setValidatorAdapter(adapter: ValidatorAdapter): void;
|
|
3
|
-
export declare function isValidatable(token: Function): boolean;
|
|
4
|
-
export declare function preloadValidationForParams(args: any[]): number[];
|
|
5
|
-
export declare function clearValidationCache(): void;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setValidatorAdapter = setValidatorAdapter;
|
|
4
|
-
exports.isValidatable = isValidatable;
|
|
5
|
-
exports.preloadValidationForParams = preloadValidationForParams;
|
|
6
|
-
exports.clearValidationCache = clearValidationCache;
|
|
7
|
-
let currentAdapter = null;
|
|
8
|
-
const cache = new Map();
|
|
9
|
-
function setValidatorAdapter(adapter) {
|
|
10
|
-
currentAdapter = adapter;
|
|
11
|
-
cache.clear();
|
|
12
|
-
}
|
|
13
|
-
function isValidatable(token) {
|
|
14
|
-
if (!currentAdapter) {
|
|
15
|
-
throw new Error('Validator adapter not initialized. Call setValidatorAdapter() first.');
|
|
16
|
-
}
|
|
17
|
-
let result = cache.get(token);
|
|
18
|
-
if (result === undefined) {
|
|
19
|
-
result = currentAdapter.hasValidation(token);
|
|
20
|
-
cache.set(token, result);
|
|
21
|
-
}
|
|
22
|
-
return result;
|
|
23
|
-
}
|
|
24
|
-
function preloadValidationForParams(args) {
|
|
25
|
-
const indices = [];
|
|
26
|
-
for (let i = 0; i < args.length; i++) {
|
|
27
|
-
if (typeof args[i] === 'function' && isValidatable(args[i])) {
|
|
28
|
-
indices.push(i);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return indices;
|
|
32
|
-
}
|
|
33
|
-
function clearValidationCache() {
|
|
34
|
-
cache.clear();
|
|
35
|
-
}
|
package/dist/utils/ancestorOf.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ancestorOf = ancestorOf;
|
|
4
|
-
exports.getInheritedClass = getInheritedClass;
|
|
5
|
-
function ancestorOf(target) {
|
|
6
|
-
return target && Object.getPrototypeOf(target);
|
|
7
|
-
}
|
|
8
|
-
function getInheritedClass(target) {
|
|
9
|
-
return ancestorOf(target);
|
|
10
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ancestorsOf = ancestorsOf;
|
|
4
|
-
const classOf_1 = require("./classOf");
|
|
5
|
-
const ancestorOf_1 = require("./ancestorOf");
|
|
6
|
-
const nameOf_1 = require("./nameOf");
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* @param target
|
|
10
|
-
* @returns {Array}
|
|
11
|
-
*/
|
|
12
|
-
function ancestorsOf(target) {
|
|
13
|
-
const classes = [];
|
|
14
|
-
let currentTarget = (0, classOf_1.classOf)(target);
|
|
15
|
-
while (currentTarget && (0, nameOf_1.nameOf)(currentTarget) !== "") {
|
|
16
|
-
classes.unshift(currentTarget);
|
|
17
|
-
currentTarget = (0, ancestorOf_1.getInheritedClass)(currentTarget);
|
|
18
|
-
}
|
|
19
|
-
return classes;
|
|
20
|
-
}
|
package/dist/utils/classOf.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get the provide constructor if target is an instance.
|
|
3
|
-
* @param target
|
|
4
|
-
* @returns {*}
|
|
5
|
-
*/
|
|
6
|
-
export declare function getClass(target: any): any;
|
|
7
|
-
/**
|
|
8
|
-
* Get the provide constructor if target is an instance.
|
|
9
|
-
* @param target
|
|
10
|
-
* @returns {*}
|
|
11
|
-
* @alias getClass
|
|
12
|
-
*/
|
|
13
|
-
export declare function classOf(target: any): any;
|