import type { Typeorm } from "../../packages"; import { AnyFn, HttpMethod, NMongoTunnel, NSchemeService, NStreamService, ExtendedRecordObject, NAbstractHttpAdapter, NAbstractFileStorageStrategy, NAbstractWsAdapter, } from "../../fn-components"; import type { NRabbitMQConnector } from "../../connectors"; export interface ISchemeLoader { readonly services: NSchemeService.BusinessScheme; readonly init(): void; readonly destroy(): void; readonly setBusinessLogic(services: NSchemaLoader.ServiceStructure[]): void; } export namespace NSchemaLoader { export type RouterStructure = { [key in R]: { [key in HttpMethod]?: { scope?: NSchemeService.AuthScope; version?: NSchemeService.Version; params?: NSchemeService.RouteParams[]; headers?: NSchemeService.HeaderParams[]; queries?: NSchemeService.QueryParams[]; handler: NAbstractHttpAdapter.ApiHandler; }; }; }; export type StreamerStructure = { [key in R]: { scope?: NSchemeService.AuthScope; version?: NSchemeService.Version; params?: NSchemeService.RouteParams[]; headers?: NSchemeService.HeaderParams[]; queries?: NSchemeService.QueryParams[]; limits?: NAbstractFileStorageStrategy.StreamLimits; handler: NAbstractHttpAdapter.StreamHandler; }; }; export type EmitterStructure = { [key in E]: { [key in NSchemeService.EventKind]?: { scope?: NSchemeService.AuthScope; version?: NSchemeService.Version; handler: NAbstractWsAdapter.Handler; }; }; }; export type BrokerStructure = { [key in T]: NRabbitMQConnector.Topic; }; export type DictionaryStructure< L extends string = string, D extends ExtendedRecordObject = ExtendedRecordObject > = { language: L | L[]; dictionary: D; }; export type HelperStructure< T extends Record = Record > = T; export type ValidatorStructure< T extends Record = Record > = { [K in keyof T]: T[K] extends infer I ? NSchemeService.ValidatorHandler : T[K]; }; export type RepositoryHandler = ( args: ARGS ) => Promise; export type TypeormSchemaStructure = ( agent: NAbstractHttpAdapter.Agents ) => Typeorm.EntitySchemaOptions; export type TypeormRepositoryStructure< S = any, T extends Record = Record< string, RepositoryHandler > > = { [K in keyof T]: T[K] extends (data: infer D, ...args: infer A) => infer R ? NSchemeService.TypeormHandler : T[K]; }; export type MongoRepositoryStructure< S = any, T extends Record = Record< string, RepositoryHandler > > = { [K in keyof T]: T[K] extends (data: infer D, ...args: infer A) => infer R ? NSchemeService.MongoHandler : T[K]; }; export type MongoSchemaStructure = ( agents: NSchemeService.Agents ) => NMongoTunnel.Schema; export type DocumentsStructure = { router?: RouterStructure; emitter?: EmitterStructure; helper?: HelperStructure; broker?: BrokerStructure; streamer?: StreamerStructure; dictionaries?: DictionaryStructure | DictionaryStructure[]; validator?: ValidatorStructure; typeorm?: { name: string; schema: NSchemeService.TypeormSchema; repository?: TypeormRepositoryStructure; }; mongo?: { name: string; model: MongoSchemaStructure; repository?: MongoRepositoryStructure; }; }; export type DomainStructure = { domain: D; documents: DocumentsStructure; }; export type ServiceStructure = { service: S; domains: DomainStructure[]; }; }