@aponiajs/common 0.3.18 → 0.3.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +9 -2
- package/dist/index.mjs +18 -17
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -73,6 +73,7 @@ declare function provideAlias<T>(provide: Token<T>, useExisting: Token<T>): Alia
|
|
|
73
73
|
//#region src/module.d.ts
|
|
74
74
|
interface ModuleDefinition {
|
|
75
75
|
readonly id: string;
|
|
76
|
+
readonly instanceId?: symbol;
|
|
76
77
|
readonly imports: readonly ModuleDefinition[];
|
|
77
78
|
readonly controllers: readonly ControllerDefinition[];
|
|
78
79
|
readonly providers: readonly Provider[];
|
|
@@ -80,6 +81,7 @@ interface ModuleDefinition {
|
|
|
80
81
|
}
|
|
81
82
|
interface ModuleOptions {
|
|
82
83
|
readonly id: string;
|
|
84
|
+
readonly instanceId?: symbol;
|
|
83
85
|
readonly imports?: readonly ModuleDefinition[];
|
|
84
86
|
readonly controllers?: readonly ControllerDefinition[];
|
|
85
87
|
readonly providers?: readonly Provider[];
|
|
@@ -89,7 +91,7 @@ declare function defineModule<const TOptions extends ModuleOptions>(options: TOp
|
|
|
89
91
|
//#endregion
|
|
90
92
|
//#region src/decorators.d.ts
|
|
91
93
|
type ModuleClass = ClassToken<unknown>;
|
|
92
|
-
type ModuleImport = ModuleClass | ModuleDefinition;
|
|
94
|
+
type ModuleImport = ModuleClass | ModuleDefinition | DynamicModule;
|
|
93
95
|
type ModuleProvider = ClassToken<unknown> | Provider;
|
|
94
96
|
interface ModuleMetadata {
|
|
95
97
|
readonly imports?: readonly ModuleImport[];
|
|
@@ -97,6 +99,11 @@ interface ModuleMetadata {
|
|
|
97
99
|
readonly providers?: readonly ModuleProvider[];
|
|
98
100
|
readonly exports?: readonly Token<unknown>[];
|
|
99
101
|
}
|
|
102
|
+
interface DynamicModule extends ModuleMetadata {
|
|
103
|
+
readonly module: ModuleClass;
|
|
104
|
+
readonly id: string;
|
|
105
|
+
readonly instanceId: symbol;
|
|
106
|
+
}
|
|
100
107
|
interface ControllerMetadata {
|
|
101
108
|
readonly path: string;
|
|
102
109
|
}
|
|
@@ -166,4 +173,4 @@ declare class ConsoleLogger implements LoggerService {
|
|
|
166
173
|
}
|
|
167
174
|
declare class Logger extends ConsoleLogger {}
|
|
168
175
|
//#endregion
|
|
169
|
-
export { type AliasProvider, AponiaError, type AponiaErrorCode, type ClassProvider, type ClassToken, ConsoleLogger, type ConsoleLoggerOptions, type Constructor, Controller, type ControllerDefinition, type ControllerMetadata, Delete, type FactoryProvider, Get, Inject, Injectable, type InjectionToken, type LogLevel, Logger, type LoggerService, Module, type ModuleClass, type ModuleDefinition, type ModuleImport, type ModuleMetadata, type ModuleOptions, type ModuleProvider, Patch, Post, type Provider, type ProviderScope, Put, type RequestMethod, type RouteMetadata, type Token, type TokenValue, type TokenValues, type ValueProvider, createToken, defineModule, getConstructorDependencies, getControllerMetadata, getModuleMetadata, getRouteMetadata, provideAlias, provideClass, provideFactory, provideValue, tokenName };
|
|
176
|
+
export { type AliasProvider, AponiaError, type AponiaErrorCode, type ClassProvider, type ClassToken, ConsoleLogger, type ConsoleLoggerOptions, type Constructor, Controller, type ControllerDefinition, type ControllerMetadata, Delete, type DynamicModule, type FactoryProvider, Get, Inject, Injectable, type InjectionToken, type LogLevel, Logger, type LoggerService, Module, type ModuleClass, type ModuleDefinition, type ModuleImport, type ModuleMetadata, type ModuleOptions, type ModuleProvider, Patch, Post, type Provider, type ProviderScope, Put, type RequestMethod, type RouteMetadata, type Token, type TokenValue, type TokenValues, type ValueProvider, createToken, defineModule, getConstructorDependencies, getControllerMetadata, getModuleMetadata, getRouteMetadata, provideAlias, provideClass, provideFactory, provideValue, tokenName };
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "reflect-metadata";
|
|
2
2
|
import { inspect } from "node:util";
|
|
3
3
|
//#region src/decorators.ts
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
4
|
+
const moduleMetadataKey = Symbol.for("aponia.module.metadata");
|
|
5
|
+
const controllerMetadataKey = Symbol.for("aponia.controller.metadata");
|
|
6
|
+
const routeMetadataKey = Symbol.for("aponia.route.metadata");
|
|
7
|
+
const injectedTokensMetadataKey = Symbol.for("aponia.injected-tokens.metadata");
|
|
8
8
|
function Module(metadata) {
|
|
9
9
|
const normalized = Object.freeze({
|
|
10
10
|
imports: Object.freeze([...metadata.imports ?? []]),
|
|
@@ -13,7 +13,7 @@ function Module(metadata) {
|
|
|
13
13
|
exports: Object.freeze([...metadata.exports ?? []])
|
|
14
14
|
});
|
|
15
15
|
return (target) => {
|
|
16
|
-
|
|
16
|
+
Reflect.defineMetadata(moduleMetadataKey, normalized, target);
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
19
|
function Injectable() {
|
|
@@ -21,15 +21,16 @@ function Injectable() {
|
|
|
21
21
|
}
|
|
22
22
|
function Controller(path = "") {
|
|
23
23
|
return (target) => {
|
|
24
|
-
|
|
24
|
+
Reflect.defineMetadata(controllerMetadataKey, Object.freeze({ path }), target);
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
function Inject(token) {
|
|
28
28
|
return (target, _propertyKey, parameterIndex) => {
|
|
29
29
|
const constructor = typeof target === "function" ? target : target.constructor;
|
|
30
|
-
const parameters =
|
|
31
|
-
parameters
|
|
32
|
-
|
|
30
|
+
const parameters = Reflect.getOwnMetadata(injectedTokensMetadataKey, constructor) ?? /* @__PURE__ */ new Map();
|
|
31
|
+
const updatedParameters = new Map(parameters);
|
|
32
|
+
updatedParameters.set(parameterIndex, token);
|
|
33
|
+
Reflect.defineMetadata(injectedTokensMetadataKey, updatedParameters, constructor);
|
|
33
34
|
};
|
|
34
35
|
}
|
|
35
36
|
const Delete = createRouteDecorator("DELETE");
|
|
@@ -38,30 +39,30 @@ const Patch = createRouteDecorator("PATCH");
|
|
|
38
39
|
const Post = createRouteDecorator("POST");
|
|
39
40
|
const Put = createRouteDecorator("PUT");
|
|
40
41
|
function getModuleMetadata(target) {
|
|
41
|
-
return
|
|
42
|
+
return Reflect.getOwnMetadata(moduleMetadataKey, target);
|
|
42
43
|
}
|
|
43
44
|
function getControllerMetadata(target) {
|
|
44
|
-
return
|
|
45
|
+
return Reflect.getOwnMetadata(controllerMetadataKey, target);
|
|
45
46
|
}
|
|
46
47
|
function getRouteMetadata(target) {
|
|
47
|
-
|
|
48
|
+
const routes = Reflect.getOwnMetadata(routeMetadataKey, target.prototype) ?? [];
|
|
49
|
+
return Object.freeze([...routes]);
|
|
48
50
|
}
|
|
49
51
|
function getConstructorDependencies(target) {
|
|
50
52
|
const reflected = Reflect.getMetadata("design:paramtypes", target) ?? [];
|
|
51
|
-
const explicit =
|
|
53
|
+
const explicit = Reflect.getOwnMetadata(injectedTokensMetadataKey, target);
|
|
52
54
|
const explicitLength = explicit ? Math.max(0, ...[...explicit.keys()].map((index) => index + 1)) : 0;
|
|
53
55
|
const length = Math.max(reflected.length, explicitLength);
|
|
54
56
|
return Object.freeze(Array.from({ length }, (_, index) => explicit?.get(index) ?? asToken(reflected[index], target)));
|
|
55
57
|
}
|
|
56
58
|
function createRouteDecorator(method) {
|
|
57
59
|
return (path = "") => (target, propertyKey) => {
|
|
58
|
-
const controllerRoutes =
|
|
59
|
-
|
|
60
|
+
const controllerRoutes = Reflect.getOwnMetadata(routeMetadataKey, target) ?? [];
|
|
61
|
+
Reflect.defineMetadata(routeMetadataKey, Object.freeze([...controllerRoutes, Object.freeze({
|
|
60
62
|
method,
|
|
61
63
|
path,
|
|
62
64
|
propertyKey
|
|
63
|
-
}));
|
|
64
|
-
routes.set(target, controllerRoutes);
|
|
65
|
+
})]), target);
|
|
65
66
|
};
|
|
66
67
|
}
|
|
67
68
|
function asToken(value, target) {
|
package/package.json
CHANGED