@thisisagile/easy
Version:
Straightforward library for building domain-driven microservice architectures
65 lines (64 loc) • 1.9 kB
TypeScript
import { Uuid } from './Uuid';
import { Identity } from './Identity';
import { Optional } from './Types';
export interface EnvContext {
readonly domain: string;
readonly name: string;
readonly host: string;
readonly port: number;
readonly app: string;
get(key: string, alt?: string): Optional<string>;
}
export declare class DotEnvContext implements EnvContext {
readonly domain: string;
readonly name: string;
readonly host: string;
readonly port: number;
readonly app: string;
readonly get: (key: string, alt?: string) => Optional<string>;
}
export interface RequestContext {
token?: any;
identity?: Identity;
jwt: string;
correlationId?: Uuid;
lastError?: string;
lastErrorStack?: string;
create: (f: () => void) => void;
get<T>(key: string): T;
set<T>(key: string, value: T): T;
wrap<T>(f: () => Promise<T>): Promise<T>;
}
export declare class BaseRequestContext implements RequestContext {
private state;
get token(): any;
set token(token: any);
get identity(): Identity;
get jwt(): string;
set jwt(jwt: string);
get correlationId(): Uuid;
set correlationId(id: Uuid);
get lastError(): Optional<string>;
set lastError(error: Optional<string>);
get<T>(key: string): T;
set<T>(key: string, value: T): T;
readonly create: (f: () => void) => void;
readonly wrap: <T>(f: () => Promise<T>) => Promise<T>;
}
export declare class BaseContext extends BaseRequestContext {
}
export interface Contexts {
env?: EnvContext;
request?: RequestContext;
other?: any;
}
export declare class Context {
protected state: Contexts;
constructor(state?: Contexts);
get env(): EnvContext;
set env(env: EnvContext);
get request(): RequestContext;
set request(request: RequestContext);
get other(): any;
}
export declare const ctx: Context;