akanjs 2.3.13-rc.1 → 2.3.13-rc.3
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/package.json
CHANGED
package/signal/guard.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Cls } from "akanjs/base";
|
|
1
|
+
import type { Cls, PromiseOrObject } from "akanjs/base";
|
|
2
2
|
import type { SignalContext } from "./signalContext";
|
|
3
3
|
|
|
4
4
|
export interface Guard {
|
|
5
|
-
canPass(context: SignalContext): boolean
|
|
5
|
+
canPass(context: SignalContext): PromiseOrObject<boolean>;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export type GuardCls<Name extends string = string> = Cls<Guard, { readonly name: Name }>;
|
|
@@ -11,7 +11,7 @@ export type GuardCls<Name extends string = string> = Cls<Guard, { readonly name:
|
|
|
11
11
|
export const guard = <T extends string>(name: T): GuardCls<T> => {
|
|
12
12
|
return class Guard {
|
|
13
13
|
static name = name;
|
|
14
|
-
canPass(context: SignalContext): boolean {
|
|
14
|
+
canPass(context: SignalContext): PromiseOrObject<boolean> {
|
|
15
15
|
return true;
|
|
16
16
|
}
|
|
17
17
|
};
|
package/signal/signalContext.ts
CHANGED
|
@@ -99,6 +99,11 @@ export class SignalContext<
|
|
|
99
99
|
}
|
|
100
100
|
return instance as T;
|
|
101
101
|
}
|
|
102
|
+
getService<T>(refName: string): T {
|
|
103
|
+
const service = this.#live.service.get(refName);
|
|
104
|
+
if (!service) throw new Exception.Error(`Service "${refName}" not found in live registry`);
|
|
105
|
+
return service as T;
|
|
106
|
+
}
|
|
102
107
|
async init() {
|
|
103
108
|
if (this.trace) {
|
|
104
109
|
const start = performance.now();
|
package/types/signal/guard.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Cls } from "akanjs/base";
|
|
1
|
+
import type { Cls, PromiseOrObject } from "akanjs/base";
|
|
2
2
|
import type { SignalContext } from "./signalContext.d.ts";
|
|
3
3
|
export interface Guard {
|
|
4
|
-
canPass(context: SignalContext): boolean
|
|
4
|
+
canPass(context: SignalContext): PromiseOrObject<boolean>;
|
|
5
5
|
}
|
|
6
6
|
export type GuardCls<Name extends string = string> = Cls<Guard, {
|
|
7
7
|
readonly name: Name;
|
|
@@ -30,6 +30,7 @@ export declare class SignalContext<Ctx extends HttpExecutionContext | WebSocketE
|
|
|
30
30
|
middleware: Map<string, MiddlewareCls>;
|
|
31
31
|
});
|
|
32
32
|
getAdaptor<T extends Adaptor>(adaptorCls: AdaptorCls<T>): T;
|
|
33
|
+
getService<T>(refName: string): T;
|
|
33
34
|
init(): Promise<this>;
|
|
34
35
|
exec(): Promise<Response | undefined>;
|
|
35
36
|
static try(endpoint: Adaptor, endpointInfo: EndpointInfo, key: string, fn: () => Promise<Response | undefined>): Promise<Response | undefined>;
|