import type { Joi, Typeorm } from "../../packages"; import type { NMongoTunnel } from "../tunnels"; import type { NStreamService } from "./stream.service"; import type { IAbstractService } from "./abstract.service"; import type { NRabbitMQConnector } from "../../connectors"; import type { NAbstractHttpAdapter, NAbstractWsAdapter } from "../adapters"; import type { AnyFn, FnObject, AnyObject, HttpMethod, ExtendedRecordObject, } from "../utils"; import type { ISchemeAgent, NSchemaAgent, IFunctionalityAgent, IIntegrationAgent, } from "../../ba-communication"; export interface ISchemeService extends IAbstractService { readonly schema: NSchemeService.BusinessScheme; getMongoRepository(): T; getAnotherMongoRepository(name: string): T; getValidator< T extends Record >(): NSchemeService.ValidatorStructure; getAnotherValidator>( name: string ): NSchemeService.ValidatorStructure; getTypeormRepository(): T; getAnotherTypeormRepository(name: string): T; getResource( resource: string, substitutions?: Record | undefined | null, language?: string ): string; getAnotherResource( name: string, resource: string, substitutions?: Record | undefined | null, language?: string ): string; readonly typeormSchemas: NSchemeService.TypeormEntities; on(event: NSchemeService.Events, listener: () => void): void; } export namespace NSchemeService { export type Config = {}; export type Agents = { fnAgent: IFunctionalityAgent; schemaAgent: ISchemeAgent; inAgent: IIntegrationAgent; }; export type Events = | `services:${ServiceName}:schemas-init` | `services:${ServiceName}:schemas-load` | `services:${ServiceName}:schemas-error`; export type EventKind = "session:to:session" | "session:to:service"; export type AuthScope = "public:route" | "private:user" | "private:system"; export type Version = "v1" | "v2" | "v3" | "v4" | "v5" | string; export type RouteParams = { name: string; scope: "required" | "optional"; }; export type HeaderParams = { name: string; scope: "required" | "optional"; }; export type QueryParameter = | "string" | "string[]" | "number" | "number[]" | "boolean" | "boolean[]"; export type QueryParams = { name: string; format: QueryParameter[]; scope: "required" | "optional"; }; export type Route = { path: string; method: HttpMethod; scope: AuthScope; version: Version; params: RouteParams[] | null; headers: HeaderParams[] | null; queries: QueryParams[] | null; handler: NAbstractHttpAdapter.ApiHandler; }; export type Stream = { path: string; scope: AuthScope; version: Version; params: RouteParams[] | null; headers: HeaderParams[] | null; queries: QueryParams[] | null; limits: NStreamService.StreamLimits | null; handler: NAbstractHttpAdapter.StreamHandler; }; export type Event = { event: string; kind: EventKind; scope: AuthScope; version: Version; handler: NAbstractWsAdapter.Handler; }; export type TypeormEntities = Map>; export type ValidateErrors = Array<{ message: string; key?: string; value?: string; }>; export type ValidatorHandler = ( provider: Joi.Root, localization: NSchemaAgent.Localization, data: I ) => ValidateErrors | void; export type ValidatorStructure = { [K in keyof T]: T[K] extends infer I ? ValidatorHandler : T[K]; }; export type TypeormSchema = ( agent: Agents ) => Typeorm.EntitySchemaOptions; export type TypeormHandler = ( provider: Typeorm.Repository, agents: Agents, data: D ) => R; export type MongoSchema = ( agents: Agents ) => NMongoTunnel.SchemaFn; export type MongoHandler = ( provider: NMongoTunnel.Repository, agents: Agents, data: D ) => R; export type Domain = { routes: Map; events: Map; streams: Map; helper: Map; broker: Map; dictionaries: Map; validator: Map; typeorm?: { name: string; schema: TypeormSchema; repository: Map; }; mongo?: { name: string; schema: MongoSchema; repository: Map; }; }; export type Service = Map; export type BusinessScheme = Map; }