@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
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
+
var Container_exports = {};
|
|
16
|
+
__export(Container_exports, {
|
|
17
|
+
Container: () => Container,
|
|
18
|
+
Scope: () => Scope
|
|
19
|
+
});
|
|
20
|
+
module.exports = __toCommonJS(Container_exports);
|
|
21
|
+
var Scope = /* @__PURE__ */ ((Scope2) => (Scope2.SINGLETON = "singleton", Scope2.REQUEST = "request", Scope2.INSTANCE = "instance", Scope2))(Scope || {});
|
|
22
|
+
class Container {
|
|
23
|
+
constructor() {
|
|
24
|
+
this.configs = /* @__PURE__ */ new Map();
|
|
25
|
+
this.instances = /* @__PURE__ */ new Map();
|
|
26
|
+
this.resolving = /* @__PURE__ */ new Set();
|
|
27
|
+
}
|
|
28
|
+
register(config) {
|
|
29
|
+
const normalized = this.normalizeConfig(config);
|
|
30
|
+
return this.configs.set(normalized.token, normalized), normalized.useValue !== void 0 && this.instances.set(normalized.token, normalized.useValue), this;
|
|
31
|
+
}
|
|
32
|
+
get(token) {
|
|
33
|
+
const cached = this.instances.get(token);
|
|
34
|
+
return cached !== void 0 ? cached : this.resolveInternal(token).instance;
|
|
35
|
+
}
|
|
36
|
+
has(token) {
|
|
37
|
+
return this.configs.has(token);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Resolves a token to return instance and its effective scope.
|
|
41
|
+
*/
|
|
42
|
+
resolveInternal(token, requestLocals) {
|
|
43
|
+
if (requestLocals?.has(token))
|
|
44
|
+
return { instance: requestLocals.get(token), scope: "request" /* REQUEST */ };
|
|
45
|
+
const cached = this.instances.get(token);
|
|
46
|
+
if (cached !== void 0)
|
|
47
|
+
return { instance: cached, scope: "singleton" /* SINGLETON */ };
|
|
48
|
+
const config = this.configs.get(token);
|
|
49
|
+
if (!config)
|
|
50
|
+
throw new Error(`Provider not found: ${token.name}`);
|
|
51
|
+
const creation = this.createInstance(config, requestLocals);
|
|
52
|
+
return creation.scope === "singleton" /* SINGLETON */ ? this.instances.set(token, creation.instance) : creation.scope === "request" /* REQUEST */ && requestLocals && requestLocals.set(token, creation.instance), creation;
|
|
53
|
+
}
|
|
54
|
+
createInstance(config, requestLocals) {
|
|
55
|
+
const target = config.useClass ?? config.token;
|
|
56
|
+
if (this.resolving.has(target))
|
|
57
|
+
throw new Error(`Circular dependency detected: ${target.name}`);
|
|
58
|
+
this.resolving.add(target);
|
|
59
|
+
try {
|
|
60
|
+
const depsToken = this.getDependencies(target);
|
|
61
|
+
if (depsToken.length === 0)
|
|
62
|
+
return { instance: new target(), scope: config.scope || "singleton" /* SINGLETON */ };
|
|
63
|
+
const args = [];
|
|
64
|
+
let effectiveScope = config.scope || "singleton" /* SINGLETON */;
|
|
65
|
+
for (const depToken of depsToken) {
|
|
66
|
+
const depResult = this.resolveInternal(depToken, requestLocals);
|
|
67
|
+
args.push(depResult.instance), depResult.scope === "request" /* REQUEST */ && effectiveScope === "singleton" /* SINGLETON */ && (effectiveScope = "request" /* REQUEST */);
|
|
68
|
+
}
|
|
69
|
+
return { instance: new target(...args), scope: effectiveScope };
|
|
70
|
+
} finally {
|
|
71
|
+
this.resolving.delete(target);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
getDependencies(target) {
|
|
75
|
+
return (Reflect.getMetadata("design:paramtypes", target) || []).filter((t) => t && typeof t == "function" && !this.isPrimitive(t));
|
|
76
|
+
}
|
|
77
|
+
isPrimitive(type) {
|
|
78
|
+
return type === String || type === Number || type === Boolean || type === Object || type === Array || type === Symbol;
|
|
79
|
+
}
|
|
80
|
+
normalizeConfig(config) {
|
|
81
|
+
return typeof config == "function" ? {
|
|
82
|
+
token: config,
|
|
83
|
+
useClass: config,
|
|
84
|
+
scope: "singleton" /* SINGLETON */
|
|
85
|
+
} : {
|
|
86
|
+
...config,
|
|
87
|
+
useClass: config.useClass ?? config.token,
|
|
88
|
+
scope: config.scope ?? "singleton" /* SINGLETON */
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
clear() {
|
|
92
|
+
this.configs.clear(), this.instances.clear();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
96
|
+
0 && (module.exports = {
|
|
97
|
+
Container,
|
|
98
|
+
Scope
|
|
99
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
var Scope = /* @__PURE__ */ ((Scope2) => (Scope2.SINGLETON = "singleton", Scope2.REQUEST = "request", Scope2.INSTANCE = "instance", Scope2))(Scope || {});
|
|
2
|
+
class Container {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.configs = /* @__PURE__ */ new Map();
|
|
5
|
+
this.instances = /* @__PURE__ */ new Map();
|
|
6
|
+
this.resolving = /* @__PURE__ */ new Set();
|
|
7
|
+
}
|
|
8
|
+
register(config) {
|
|
9
|
+
const normalized = this.normalizeConfig(config);
|
|
10
|
+
return this.configs.set(normalized.token, normalized), normalized.useValue !== void 0 && this.instances.set(normalized.token, normalized.useValue), this;
|
|
11
|
+
}
|
|
12
|
+
get(token) {
|
|
13
|
+
const cached = this.instances.get(token);
|
|
14
|
+
return cached !== void 0 ? cached : this.resolveInternal(token).instance;
|
|
15
|
+
}
|
|
16
|
+
has(token) {
|
|
17
|
+
return this.configs.has(token);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Resolves a token to return instance and its effective scope.
|
|
21
|
+
*/
|
|
22
|
+
resolveInternal(token, requestLocals) {
|
|
23
|
+
if (requestLocals?.has(token))
|
|
24
|
+
return { instance: requestLocals.get(token), scope: "request" /* REQUEST */ };
|
|
25
|
+
const cached = this.instances.get(token);
|
|
26
|
+
if (cached !== void 0)
|
|
27
|
+
return { instance: cached, scope: "singleton" /* SINGLETON */ };
|
|
28
|
+
const config = this.configs.get(token);
|
|
29
|
+
if (!config)
|
|
30
|
+
throw new Error(`Provider not found: ${token.name}`);
|
|
31
|
+
const creation = this.createInstance(config, requestLocals);
|
|
32
|
+
return creation.scope === "singleton" /* SINGLETON */ ? this.instances.set(token, creation.instance) : creation.scope === "request" /* REQUEST */ && requestLocals && requestLocals.set(token, creation.instance), creation;
|
|
33
|
+
}
|
|
34
|
+
createInstance(config, requestLocals) {
|
|
35
|
+
const target = config.useClass ?? config.token;
|
|
36
|
+
if (this.resolving.has(target))
|
|
37
|
+
throw new Error(`Circular dependency detected: ${target.name}`);
|
|
38
|
+
this.resolving.add(target);
|
|
39
|
+
try {
|
|
40
|
+
const depsToken = this.getDependencies(target);
|
|
41
|
+
if (depsToken.length === 0)
|
|
42
|
+
return { instance: new target(), scope: config.scope || "singleton" /* SINGLETON */ };
|
|
43
|
+
const args = [];
|
|
44
|
+
let effectiveScope = config.scope || "singleton" /* SINGLETON */;
|
|
45
|
+
for (const depToken of depsToken) {
|
|
46
|
+
const depResult = this.resolveInternal(depToken, requestLocals);
|
|
47
|
+
args.push(depResult.instance), depResult.scope === "request" /* REQUEST */ && effectiveScope === "singleton" /* SINGLETON */ && (effectiveScope = "request" /* REQUEST */);
|
|
48
|
+
}
|
|
49
|
+
return { instance: new target(...args), scope: effectiveScope };
|
|
50
|
+
} finally {
|
|
51
|
+
this.resolving.delete(target);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
getDependencies(target) {
|
|
55
|
+
return (Reflect.getMetadata("design:paramtypes", target) || []).filter((t) => t && typeof t == "function" && !this.isPrimitive(t));
|
|
56
|
+
}
|
|
57
|
+
isPrimitive(type) {
|
|
58
|
+
return type === String || type === Number || type === Boolean || type === Object || type === Array || type === Symbol;
|
|
59
|
+
}
|
|
60
|
+
normalizeConfig(config) {
|
|
61
|
+
return typeof config == "function" ? {
|
|
62
|
+
token: config,
|
|
63
|
+
useClass: config,
|
|
64
|
+
scope: "singleton" /* SINGLETON */
|
|
65
|
+
} : {
|
|
66
|
+
...config,
|
|
67
|
+
useClass: config.useClass ?? config.token,
|
|
68
|
+
scope: config.scope ?? "singleton" /* SINGLETON */
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
clear() {
|
|
72
|
+
this.configs.clear(), this.instances.clear();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export {
|
|
76
|
+
Container,
|
|
77
|
+
Scope
|
|
78
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
+
var Context_exports = {};
|
|
16
|
+
__export(Context_exports, {
|
|
17
|
+
Context: () => Context
|
|
18
|
+
});
|
|
19
|
+
module.exports = __toCommonJS(Context_exports);
|
|
20
|
+
const EMPTY_PARAMS = Object.freeze({});
|
|
21
|
+
class Context {
|
|
22
|
+
constructor(req, params = EMPTY_PARAMS) {
|
|
23
|
+
this.locals = {};
|
|
24
|
+
// Lazy fields - only allocated when accessed
|
|
25
|
+
this._query = null;
|
|
26
|
+
this._bodyParsed = !1;
|
|
27
|
+
this._url = null;
|
|
28
|
+
this._status = 0;
|
|
29
|
+
this.req = req, this.params = params;
|
|
30
|
+
}
|
|
31
|
+
get status() {
|
|
32
|
+
return this._status || 200;
|
|
33
|
+
}
|
|
34
|
+
set status(value) {
|
|
35
|
+
this._status = value;
|
|
36
|
+
}
|
|
37
|
+
get url() {
|
|
38
|
+
return this._url || (this._url = new URL(this.req.url)), this._url;
|
|
39
|
+
}
|
|
40
|
+
get query() {
|
|
41
|
+
return this._query || (this._query = Object.fromEntries(this.url.searchParams)), this._query;
|
|
42
|
+
}
|
|
43
|
+
get body() {
|
|
44
|
+
return this._body;
|
|
45
|
+
}
|
|
46
|
+
async parseBody() {
|
|
47
|
+
if (this._bodyParsed)
|
|
48
|
+
return this._body;
|
|
49
|
+
this._bodyParsed = !0;
|
|
50
|
+
const contentType = this.req.headers.get("content-type") || "";
|
|
51
|
+
if (contentType.includes("application/json"))
|
|
52
|
+
this._body = await this.req.json();
|
|
53
|
+
else if (contentType.includes("form")) {
|
|
54
|
+
const formData = await this.req.formData();
|
|
55
|
+
this._body = Object.fromEntries(formData);
|
|
56
|
+
} else contentType.includes("text") ? this._body = await this.req.text() : this._body = await this.req.arrayBuffer();
|
|
57
|
+
return this._body;
|
|
58
|
+
}
|
|
59
|
+
get method() {
|
|
60
|
+
return this.req.method;
|
|
61
|
+
}
|
|
62
|
+
get headers() {
|
|
63
|
+
return this.req.headers;
|
|
64
|
+
}
|
|
65
|
+
get path() {
|
|
66
|
+
return this.url.pathname;
|
|
67
|
+
}
|
|
68
|
+
json(data, status) {
|
|
69
|
+
return status && (this.status = status), Response.json(data, { status: this.status });
|
|
70
|
+
}
|
|
71
|
+
text(data, status) {
|
|
72
|
+
return status && (this.status = status), new Response(data, {
|
|
73
|
+
status: this.status,
|
|
74
|
+
headers: { "Content-Type": "text/plain" }
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
html(data, status) {
|
|
78
|
+
return status && (this.status = status), new Response(data, {
|
|
79
|
+
status: this.status,
|
|
80
|
+
headers: { "Content-Type": "text/html" }
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
redirect(url, status = 302) {
|
|
84
|
+
return Response.redirect(url, status);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Creates a Context from a job (for queue processing).
|
|
88
|
+
*/
|
|
89
|
+
static createFromJob(job) {
|
|
90
|
+
const fakeRequest = new Request("http://localhost/job"), ctx = new Context(fakeRequest);
|
|
91
|
+
return ctx.locals.job = job, ctx;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
95
|
+
0 && (module.exports = {
|
|
96
|
+
Context
|
|
97
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const EMPTY_PARAMS = Object.freeze({});
|
|
2
|
+
class Context {
|
|
3
|
+
constructor(req, params = EMPTY_PARAMS) {
|
|
4
|
+
this.locals = {};
|
|
5
|
+
// Lazy fields - only allocated when accessed
|
|
6
|
+
this._query = null;
|
|
7
|
+
this._bodyParsed = !1;
|
|
8
|
+
this._url = null;
|
|
9
|
+
this._status = 0;
|
|
10
|
+
this.req = req, this.params = params;
|
|
11
|
+
}
|
|
12
|
+
get status() {
|
|
13
|
+
return this._status || 200;
|
|
14
|
+
}
|
|
15
|
+
set status(value) {
|
|
16
|
+
this._status = value;
|
|
17
|
+
}
|
|
18
|
+
get url() {
|
|
19
|
+
return this._url || (this._url = new URL(this.req.url)), this._url;
|
|
20
|
+
}
|
|
21
|
+
get query() {
|
|
22
|
+
return this._query || (this._query = Object.fromEntries(this.url.searchParams)), this._query;
|
|
23
|
+
}
|
|
24
|
+
get body() {
|
|
25
|
+
return this._body;
|
|
26
|
+
}
|
|
27
|
+
async parseBody() {
|
|
28
|
+
if (this._bodyParsed)
|
|
29
|
+
return this._body;
|
|
30
|
+
this._bodyParsed = !0;
|
|
31
|
+
const contentType = this.req.headers.get("content-type") || "";
|
|
32
|
+
if (contentType.includes("application/json"))
|
|
33
|
+
this._body = await this.req.json();
|
|
34
|
+
else if (contentType.includes("form")) {
|
|
35
|
+
const formData = await this.req.formData();
|
|
36
|
+
this._body = Object.fromEntries(formData);
|
|
37
|
+
} else contentType.includes("text") ? this._body = await this.req.text() : this._body = await this.req.arrayBuffer();
|
|
38
|
+
return this._body;
|
|
39
|
+
}
|
|
40
|
+
get method() {
|
|
41
|
+
return this.req.method;
|
|
42
|
+
}
|
|
43
|
+
get headers() {
|
|
44
|
+
return this.req.headers;
|
|
45
|
+
}
|
|
46
|
+
get path() {
|
|
47
|
+
return this.url.pathname;
|
|
48
|
+
}
|
|
49
|
+
json(data, status) {
|
|
50
|
+
return status && (this.status = status), Response.json(data, { status: this.status });
|
|
51
|
+
}
|
|
52
|
+
text(data, status) {
|
|
53
|
+
return status && (this.status = status), new Response(data, {
|
|
54
|
+
status: this.status,
|
|
55
|
+
headers: { "Content-Type": "text/plain" }
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
html(data, status) {
|
|
59
|
+
return status && (this.status = status), new Response(data, {
|
|
60
|
+
status: this.status,
|
|
61
|
+
headers: { "Content-Type": "text/html" }
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
redirect(url, status = 302) {
|
|
65
|
+
return Response.redirect(url, status);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Creates a Context from a job (for queue processing).
|
|
69
|
+
*/
|
|
70
|
+
static createFromJob(job) {
|
|
71
|
+
const fakeRequest = new Request("http://localhost/job"), ctx = new Context(fakeRequest);
|
|
72
|
+
return ctx.locals.job = job, ctx;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export {
|
|
76
|
+
Context
|
|
77
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
+
var CorsHandler_exports = {};
|
|
16
|
+
__export(CorsHandler_exports, {
|
|
17
|
+
CorsHandler: () => CorsHandler,
|
|
18
|
+
DEFAULT_CORS_HEADERS: () => DEFAULT_CORS_HEADERS,
|
|
19
|
+
DEFAULT_CORS_METHODS: () => DEFAULT_CORS_METHODS
|
|
20
|
+
});
|
|
21
|
+
module.exports = __toCommonJS(CorsHandler_exports);
|
|
22
|
+
const DEFAULT_CORS_METHODS = ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"], DEFAULT_CORS_HEADERS = ["Content-Type", "Authorization", "X-Requested-With", "Accept", "Origin"];
|
|
23
|
+
class CorsHandler {
|
|
24
|
+
constructor(config) {
|
|
25
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
26
|
+
// Pre-created preflight response for wildcard CORS
|
|
27
|
+
this.preflightResponse = null;
|
|
28
|
+
this.methodsStr = (config.methods || DEFAULT_CORS_METHODS).join(", "), this.headersStr = (config.allowedHeaders || DEFAULT_CORS_HEADERS).join(", "), this.exposedStr = config.exposedHeaders?.join(", ") || null, this.maxAgeStr = config.maxAge?.toString() || null, this.hasCredentials = !!config.credentials, this.isWildcard = config.origins === "*", this.matcher = this.buildMatcher(config.origins), this.isWildcard && (this.preflightResponse = new Response(null, {
|
|
29
|
+
status: 204,
|
|
30
|
+
headers: this.buildHeaders("*")
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Handle preflight (OPTIONS) request.
|
|
35
|
+
*/
|
|
36
|
+
preflight(origin) {
|
|
37
|
+
return this.isWildcard && this.preflightResponse ? this.preflightResponse.clone() : this.isAllowed(origin) ? new Response(null, {
|
|
38
|
+
status: 204,
|
|
39
|
+
headers: this.getHeaders(origin)
|
|
40
|
+
}) : new Response(null, { status: 403 });
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Apply CORS headers to a response.
|
|
44
|
+
*/
|
|
45
|
+
apply(response, origin) {
|
|
46
|
+
if (!this.isAllowed(origin))
|
|
47
|
+
return response;
|
|
48
|
+
const headers = this.getHeaders(origin);
|
|
49
|
+
for (const [key, value] of Object.entries(headers))
|
|
50
|
+
response.headers.set(key, value);
|
|
51
|
+
return response;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Check if origin is allowed.
|
|
55
|
+
*/
|
|
56
|
+
isAllowed(origin) {
|
|
57
|
+
return this.matcher(origin);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get cached CORS headers for origin.
|
|
61
|
+
*/
|
|
62
|
+
getHeaders(origin) {
|
|
63
|
+
const key = this.isWildcard ? "*" : origin;
|
|
64
|
+
let headers = this.cache.get(key);
|
|
65
|
+
return headers || (headers = this.buildHeaders(origin), this.cache.set(key, headers)), headers;
|
|
66
|
+
}
|
|
67
|
+
buildHeaders(origin) {
|
|
68
|
+
const headers = {
|
|
69
|
+
"Access-Control-Allow-Origin": this.isWildcard ? "*" : origin,
|
|
70
|
+
"Access-Control-Allow-Methods": this.methodsStr,
|
|
71
|
+
"Access-Control-Allow-Headers": this.headersStr
|
|
72
|
+
};
|
|
73
|
+
return this.hasCredentials && (headers["Access-Control-Allow-Credentials"] = "true"), this.exposedStr && (headers["Access-Control-Expose-Headers"] = this.exposedStr), this.maxAgeStr && (headers["Access-Control-Max-Age"] = this.maxAgeStr), headers;
|
|
74
|
+
}
|
|
75
|
+
buildMatcher(origins) {
|
|
76
|
+
if (origins === "*") return () => !0;
|
|
77
|
+
if (typeof origins == "string") return (o) => o === origins;
|
|
78
|
+
if (Array.isArray(origins)) {
|
|
79
|
+
const set = new Set(origins);
|
|
80
|
+
return (o) => set.has(o);
|
|
81
|
+
}
|
|
82
|
+
return origins instanceof RegExp ? (o) => origins.test(o) : typeof origins == "function" ? origins : () => !1;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
86
|
+
0 && (module.exports = {
|
|
87
|
+
CorsHandler,
|
|
88
|
+
DEFAULT_CORS_HEADERS,
|
|
89
|
+
DEFAULT_CORS_METHODS
|
|
90
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const DEFAULT_CORS_METHODS = ["GET", "HEAD", "PUT", "PATCH", "POST", "DELETE"], DEFAULT_CORS_HEADERS = ["Content-Type", "Authorization", "X-Requested-With", "Accept", "Origin"];
|
|
2
|
+
class CorsHandler {
|
|
3
|
+
constructor(config) {
|
|
4
|
+
this.cache = /* @__PURE__ */ new Map();
|
|
5
|
+
// Pre-created preflight response for wildcard CORS
|
|
6
|
+
this.preflightResponse = null;
|
|
7
|
+
this.methodsStr = (config.methods || DEFAULT_CORS_METHODS).join(", "), this.headersStr = (config.allowedHeaders || DEFAULT_CORS_HEADERS).join(", "), this.exposedStr = config.exposedHeaders?.join(", ") || null, this.maxAgeStr = config.maxAge?.toString() || null, this.hasCredentials = !!config.credentials, this.isWildcard = config.origins === "*", this.matcher = this.buildMatcher(config.origins), this.isWildcard && (this.preflightResponse = new Response(null, {
|
|
8
|
+
status: 204,
|
|
9
|
+
headers: this.buildHeaders("*")
|
|
10
|
+
}));
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Handle preflight (OPTIONS) request.
|
|
14
|
+
*/
|
|
15
|
+
preflight(origin) {
|
|
16
|
+
return this.isWildcard && this.preflightResponse ? this.preflightResponse.clone() : this.isAllowed(origin) ? new Response(null, {
|
|
17
|
+
status: 204,
|
|
18
|
+
headers: this.getHeaders(origin)
|
|
19
|
+
}) : new Response(null, { status: 403 });
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Apply CORS headers to a response.
|
|
23
|
+
*/
|
|
24
|
+
apply(response, origin) {
|
|
25
|
+
if (!this.isAllowed(origin))
|
|
26
|
+
return response;
|
|
27
|
+
const headers = this.getHeaders(origin);
|
|
28
|
+
for (const [key, value] of Object.entries(headers))
|
|
29
|
+
response.headers.set(key, value);
|
|
30
|
+
return response;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Check if origin is allowed.
|
|
34
|
+
*/
|
|
35
|
+
isAllowed(origin) {
|
|
36
|
+
return this.matcher(origin);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get cached CORS headers for origin.
|
|
40
|
+
*/
|
|
41
|
+
getHeaders(origin) {
|
|
42
|
+
const key = this.isWildcard ? "*" : origin;
|
|
43
|
+
let headers = this.cache.get(key);
|
|
44
|
+
return headers || (headers = this.buildHeaders(origin), this.cache.set(key, headers)), headers;
|
|
45
|
+
}
|
|
46
|
+
buildHeaders(origin) {
|
|
47
|
+
const headers = {
|
|
48
|
+
"Access-Control-Allow-Origin": this.isWildcard ? "*" : origin,
|
|
49
|
+
"Access-Control-Allow-Methods": this.methodsStr,
|
|
50
|
+
"Access-Control-Allow-Headers": this.headersStr
|
|
51
|
+
};
|
|
52
|
+
return this.hasCredentials && (headers["Access-Control-Allow-Credentials"] = "true"), this.exposedStr && (headers["Access-Control-Expose-Headers"] = this.exposedStr), this.maxAgeStr && (headers["Access-Control-Max-Age"] = this.maxAgeStr), headers;
|
|
53
|
+
}
|
|
54
|
+
buildMatcher(origins) {
|
|
55
|
+
if (origins === "*") return () => !0;
|
|
56
|
+
if (typeof origins == "string") return (o) => o === origins;
|
|
57
|
+
if (Array.isArray(origins)) {
|
|
58
|
+
const set = new Set(origins);
|
|
59
|
+
return (o) => set.has(o);
|
|
60
|
+
}
|
|
61
|
+
return origins instanceof RegExp ? (o) => origins.test(o) : typeof origins == "function" ? origins : () => !1;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export {
|
|
65
|
+
CorsHandler,
|
|
66
|
+
DEFAULT_CORS_HEADERS,
|
|
67
|
+
DEFAULT_CORS_METHODS
|
|
68
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
+
var Controller_exports = {};
|
|
16
|
+
__export(Controller_exports, {
|
|
17
|
+
Controller: () => Controller
|
|
18
|
+
});
|
|
19
|
+
module.exports = __toCommonJS(Controller_exports);
|
|
20
|
+
var import_metadata = require('../metadata.js');
|
|
21
|
+
function normalizeOptions(pathOrOptions) {
|
|
22
|
+
return pathOrOptions ? typeof pathOrOptions == "string" ? { path: pathOrOptions } : pathOrOptions : {};
|
|
23
|
+
}
|
|
24
|
+
function normalizePath(path) {
|
|
25
|
+
if (!path) return "";
|
|
26
|
+
let normalized = path.startsWith("/") ? path : "/" + path;
|
|
27
|
+
return normalized !== "/" && normalized.endsWith("/") && (normalized = normalized.slice(0, -1)), normalized;
|
|
28
|
+
}
|
|
29
|
+
function Controller(pathOrOptions) {
|
|
30
|
+
return (target) => {
|
|
31
|
+
const options = normalizeOptions(pathOrOptions), meta = {
|
|
32
|
+
path: normalizePath(options.path || ""),
|
|
33
|
+
scope: options.scope,
|
|
34
|
+
children: options.children
|
|
35
|
+
};
|
|
36
|
+
Reflect.defineMetadata(import_metadata.CONTROLLER_META, meta, target), Reflect.hasMetadata(import_metadata.ROUTES_META, target) || Reflect.defineMetadata(import_metadata.ROUTES_META, [], target);
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
Controller
|
|
42
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { CONTROLLER_META, ROUTES_META } from "../metadata.mjs";
|
|
2
|
+
function normalizeOptions(pathOrOptions) {
|
|
3
|
+
return pathOrOptions ? typeof pathOrOptions == "string" ? { path: pathOrOptions } : pathOrOptions : {};
|
|
4
|
+
}
|
|
5
|
+
function normalizePath(path) {
|
|
6
|
+
if (!path) return "";
|
|
7
|
+
let normalized = path.startsWith("/") ? path : "/" + path;
|
|
8
|
+
return normalized !== "/" && normalized.endsWith("/") && (normalized = normalized.slice(0, -1)), normalized;
|
|
9
|
+
}
|
|
10
|
+
function Controller(pathOrOptions) {
|
|
11
|
+
return (target) => {
|
|
12
|
+
const options = normalizeOptions(pathOrOptions), meta = {
|
|
13
|
+
path: normalizePath(options.path || ""),
|
|
14
|
+
scope: options.scope,
|
|
15
|
+
children: options.children
|
|
16
|
+
};
|
|
17
|
+
Reflect.defineMetadata(CONTROLLER_META, meta, target), Reflect.hasMetadata(ROUTES_META, target) || Reflect.defineMetadata(ROUTES_META, [], target);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
Controller
|
|
22
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
+
var Inject_exports = {};
|
|
16
|
+
__export(Inject_exports, {
|
|
17
|
+
Inject: () => Inject
|
|
18
|
+
});
|
|
19
|
+
module.exports = __toCommonJS(Inject_exports);
|
|
20
|
+
var import_metadata = require('../metadata.js');
|
|
21
|
+
function Inject(token) {
|
|
22
|
+
return (target, propertyKey, parameterIndex) => {
|
|
23
|
+
const existing = Reflect.getMetadata(import_metadata.INJECT_META, target) || /* @__PURE__ */ new Map();
|
|
24
|
+
existing.set(parameterIndex, token), Reflect.defineMetadata(import_metadata.INJECT_META, existing, target);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
Inject
|
|
30
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { INJECT_META } from "../metadata.mjs";
|
|
2
|
+
function Inject(token) {
|
|
3
|
+
return (target, propertyKey, parameterIndex) => {
|
|
4
|
+
const existing = Reflect.getMetadata(INJECT_META, target) || /* @__PURE__ */ new Map();
|
|
5
|
+
existing.set(parameterIndex, token), Reflect.defineMetadata(INJECT_META, existing, target);
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
Inject
|
|
10
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
8
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
15
|
+
var Middleware_exports = {};
|
|
16
|
+
__export(Middleware_exports, {
|
|
17
|
+
Use: () => Use
|
|
18
|
+
});
|
|
19
|
+
module.exports = __toCommonJS(Middleware_exports);
|
|
20
|
+
var import_metadata = require('../metadata.js');
|
|
21
|
+
function Use(...middlewares) {
|
|
22
|
+
return function(target, propertyKey) {
|
|
23
|
+
const isMethod = propertyKey !== void 0, metaTarget = isMethod ? target.constructor : target, existing = Reflect.getMetadata(import_metadata.MIDDLEWARE_META, metaTarget) || [];
|
|
24
|
+
for (const handler of middlewares)
|
|
25
|
+
existing.push({
|
|
26
|
+
handler,
|
|
27
|
+
target: isMethod ? propertyKey : void 0
|
|
28
|
+
});
|
|
29
|
+
Reflect.defineMetadata(import_metadata.MIDDLEWARE_META, existing, metaTarget);
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
Use
|
|
35
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { MIDDLEWARE_META } from "../metadata.mjs";
|
|
2
|
+
function Use(...middlewares) {
|
|
3
|
+
return function(target, propertyKey) {
|
|
4
|
+
const isMethod = propertyKey !== void 0, metaTarget = isMethod ? target.constructor : target, existing = Reflect.getMetadata(MIDDLEWARE_META, metaTarget) || [];
|
|
5
|
+
for (const handler of middlewares)
|
|
6
|
+
existing.push({
|
|
7
|
+
handler,
|
|
8
|
+
target: isMethod ? propertyKey : void 0
|
|
9
|
+
});
|
|
10
|
+
Reflect.defineMetadata(MIDDLEWARE_META, existing, metaTarget);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
Use
|
|
15
|
+
};
|