@kanjijs/core 0.2.0-beta.12 → 0.2.0-beta.14
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/context.d.ts +7 -0
- package/dist/decorators.d.ts +29 -0
- package/dist/di/container.d.ts +26 -0
- package/dist/di/module-compiler.d.ts +11 -0
- package/dist/exceptions/exception.filter.d.ts +3 -0
- package/dist/exceptions/http.exception.d.ts +7 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +1 -1
- package/dist/metadata.d.ts +56 -0
- package/package.json +4 -4
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
export interface RequestContext {
|
|
3
|
+
requestId: string;
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}
|
|
6
|
+
export declare const kanjijsContext: AsyncLocalStorage<RequestContext>;
|
|
7
|
+
export declare function getRequestId(): string | undefined;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ContractSpec } from "@kanjijs/contracts";
|
|
2
|
+
import { type ModuleMetadata } from "./metadata";
|
|
3
|
+
/**
|
|
4
|
+
* @Module({ controllers: [...] })
|
|
5
|
+
*/
|
|
6
|
+
export declare function Module(metadata: ModuleMetadata): ClassDecorator;
|
|
7
|
+
/**
|
|
8
|
+
* @Contract({ ... })
|
|
9
|
+
*/
|
|
10
|
+
export declare function Contract(spec: ContractSpec): MethodDecorator;
|
|
11
|
+
/**
|
|
12
|
+
* @Controller('/users')
|
|
13
|
+
*/
|
|
14
|
+
export declare function Controller(prefix?: string): ClassDecorator;
|
|
15
|
+
export declare function Injectable(): ClassDecorator;
|
|
16
|
+
export declare const Get: (path?: string) => MethodDecorator;
|
|
17
|
+
export declare const Post: (path?: string) => MethodDecorator;
|
|
18
|
+
export declare const Put: (path?: string) => MethodDecorator;
|
|
19
|
+
export declare const Delete: (path?: string) => MethodDecorator;
|
|
20
|
+
export declare const Patch: (path?: string) => MethodDecorator;
|
|
21
|
+
/**
|
|
22
|
+
* @Inject("DATABASE_CLIENT")
|
|
23
|
+
*/
|
|
24
|
+
export declare function Inject(token: any): ParameterDecorator;
|
|
25
|
+
/**
|
|
26
|
+
* @Use(middleware1, middleware2)
|
|
27
|
+
* Attaches middlewares to a controller or method.
|
|
28
|
+
*/
|
|
29
|
+
export declare function Use(...middlewares: any[]): MethodDecorator & ClassDecorator;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Constructor } from "../metadata";
|
|
2
|
+
import "reflect-metadata";
|
|
3
|
+
export declare class KanjijsIoC {
|
|
4
|
+
private static providers;
|
|
5
|
+
static register<T>(target: Constructor<T>): void;
|
|
6
|
+
static register(token: any, provider: {
|
|
7
|
+
useValue?: any;
|
|
8
|
+
useClass?: Constructor;
|
|
9
|
+
}): void;
|
|
10
|
+
static resolve<T>(target: Constructor<T> | any): T;
|
|
11
|
+
static clear(): void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* V2 STRICT CONTAINER
|
|
15
|
+
* Instance-based, no auto-registration, explicit visibility.
|
|
16
|
+
*/
|
|
17
|
+
export declare class Container {
|
|
18
|
+
private providers;
|
|
19
|
+
register(token: any, provider: {
|
|
20
|
+
useValue?: any;
|
|
21
|
+
useClass?: Constructor;
|
|
22
|
+
useFactory?: Function;
|
|
23
|
+
inject?: any[];
|
|
24
|
+
}): void;
|
|
25
|
+
resolve<T>(token: Constructor<T> | any): T;
|
|
26
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Constructor } from "../metadata";
|
|
2
|
+
import { Container } from "./container";
|
|
3
|
+
export declare class ModuleCompiler {
|
|
4
|
+
private nodes;
|
|
5
|
+
private globalExportedTokens;
|
|
6
|
+
compile(rootModule: Constructor): Container;
|
|
7
|
+
private scan;
|
|
8
|
+
private processProviders;
|
|
9
|
+
private validate;
|
|
10
|
+
private checkDependencies;
|
|
11
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./decorators";
|
|
2
|
+
export * from "./metadata";
|
|
3
|
+
export * from "./di/container";
|
|
4
|
+
export * from "./context";
|
|
5
|
+
export * from "./exceptions/http.exception";
|
|
6
|
+
export * from "./exceptions/exception.filter";
|
|
7
|
+
export * from "./di/module-compiler";
|
|
8
|
+
export * from "@kanjijs/contracts";
|
|
9
|
+
export declare const GLOBAL_MIDDLEWARE_TOKEN: unique symbol;
|
package/dist/index.js
CHANGED
|
@@ -1336,7 +1336,7 @@ class ModuleCompiler {
|
|
|
1336
1336
|
const paramTypes = Reflect.getMetadata("design:paramtypes", clazz) || [];
|
|
1337
1337
|
const injectionTokens = MetadataStorage.getInjections(clazz) || new Map;
|
|
1338
1338
|
dependencies = paramTypes.map((t, i) => injectionTokens.get(i) || t);
|
|
1339
|
-
} else if ("useFactory" in provider
|
|
1339
|
+
} else if ("useFactory" in provider) {
|
|
1340
1340
|
targetName = provider.provide?.name || String(provider.provide);
|
|
1341
1341
|
dependencies = provider.inject || [];
|
|
1342
1342
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { ContractSpec } from "@kanjijs/contracts";
|
|
2
|
+
import "reflect-metadata";
|
|
3
|
+
export type Constructor<T = any> = new (...args: any[]) => T;
|
|
4
|
+
export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
5
|
+
export interface RouteMetadata {
|
|
6
|
+
method: HttpMethod;
|
|
7
|
+
path: string;
|
|
8
|
+
contract?: ContractSpec;
|
|
9
|
+
middlewares?: any[];
|
|
10
|
+
}
|
|
11
|
+
export interface ControllerMetadata {
|
|
12
|
+
prefix: string;
|
|
13
|
+
middlewares?: any[];
|
|
14
|
+
}
|
|
15
|
+
export type Token<T = any> = string | symbol | Constructor<T>;
|
|
16
|
+
export type Provider<T = any> = Constructor<T> | {
|
|
17
|
+
provide: Token<T>;
|
|
18
|
+
useValue: T;
|
|
19
|
+
} | {
|
|
20
|
+
provide: Token<T>;
|
|
21
|
+
useClass: Constructor<T>;
|
|
22
|
+
} | {
|
|
23
|
+
provide: Token<T>;
|
|
24
|
+
useFactory: (...args: any[]) => T | Promise<T>;
|
|
25
|
+
inject?: Token[];
|
|
26
|
+
};
|
|
27
|
+
export interface DynamicModule {
|
|
28
|
+
module: Constructor;
|
|
29
|
+
providers?: Provider[];
|
|
30
|
+
imports?: Array<Constructor | DynamicModule>;
|
|
31
|
+
exports?: Token[];
|
|
32
|
+
global?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface ModuleMetadata {
|
|
35
|
+
controllers?: Constructor[];
|
|
36
|
+
providers?: Provider[];
|
|
37
|
+
imports?: Array<Constructor | DynamicModule>;
|
|
38
|
+
exports?: Token[];
|
|
39
|
+
global?: boolean;
|
|
40
|
+
}
|
|
41
|
+
export interface IMetadataStorage {
|
|
42
|
+
addRoute(target: object, methodName: string, meta: RouteMetadata): void;
|
|
43
|
+
addContract(target: object, methodName: string, contract: ContractSpec): void;
|
|
44
|
+
addMiddleware(target: object, middleware: any, methodName?: string): void;
|
|
45
|
+
getRoutes(target: object): Map<string, RouteMetadata> | undefined;
|
|
46
|
+
setController(target: object, meta: ControllerMetadata): void;
|
|
47
|
+
getController(target: object): ControllerMetadata | undefined;
|
|
48
|
+
defineModule(target: object, meta: ModuleMetadata): void;
|
|
49
|
+
getModule(target: object): ModuleMetadata | undefined;
|
|
50
|
+
addInjection(target: object, index: number, token: any): void;
|
|
51
|
+
getInjections(target: object): Map<number, any> | undefined;
|
|
52
|
+
}
|
|
53
|
+
declare global {
|
|
54
|
+
var KANJI_METADATA_STORAGE: IMetadataStorage | undefined;
|
|
55
|
+
}
|
|
56
|
+
export declare const MetadataStorage: IMetadataStorage;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kanjijs/core",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.14",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
"LICENSE"
|
|
11
11
|
],
|
|
12
12
|
"scripts": {
|
|
13
|
-
"build": "bun build src/index.ts --outdir dist --target bun",
|
|
13
|
+
"build": "bun build src/index.ts --outdir dist --target bun && tsc --emitDeclarationOnly --declaration --outDir dist && tsc --emitDeclarationOnly --declaration --outDir dist",
|
|
14
14
|
"test": "bun test"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@kanjijs/common": "^0.2.0-beta.
|
|
18
|
-
"@kanjijs/contracts": "^0.2.0-beta.
|
|
17
|
+
"@kanjijs/common": "^0.2.0-beta.14",
|
|
18
|
+
"@kanjijs/contracts": "^0.2.0-beta.14",
|
|
19
19
|
"reflect-metadata": "^0.2.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|