UNPKG

@feroomjs/server

Version:
271 lines (241 loc) 8.32 kB
/// <reference types="node" /> import EventEmitter from 'events'; import { HttpError } from '@wooksjs/event-http'; import { Mate } from '@prostojs/mate'; import { Moost } from 'moost'; import { Plugin as Plugin_2 } from 'rollup'; import { TMoostMetadata } from 'moost'; import { TWooksErrorBody } from '@wooksjs/event-http'; import { WooksHttp } from '@wooksjs/event-http'; declare class FeModule<EXT extends object = object> { protected data: TModuleData<EXT>; protected config: FeRoomConfig; constructor(data: TModuleData<EXT>, config: FeRoomConfig); get id(): string; get files(): Record<string, string | { type: "Buffer"; data: number[]; } | Buffer>; getGlobals(): object; getRegisterOptions(): TFeRoomRegisterOptions; getExtensions(): EXT | undefined; buildPath(path: string, version?: string): string; entryPath(version?: string): string; hasEntry(): boolean; renderPreloadCss(): string; renderPreloadScript(): string; renderComment(text: string): string; renderPreloadModule(): string; getImportMap(reg: FeRegistry): Record<string, string>; } export declare class FeRegistry<CFG extends object = object> extends EventEmitter { normalizeModuleData(data: Partial<TModuleData<CFG>>): TModuleData<CFG>; registerModule(data: Partial<TModuleData<CFG>>): { files: string[]; id: string; version: string; entry: string; source: string; config: TFeRoomConfig<CFG>; activate?: boolean | undefined; }; registerFromNpm(npmData: TNpmModuleData<CFG>): Promise<"Module already exists" | { files: string[]; id: string; version: string; entry: string; source: string; config: TFeRoomConfig<CFG>; activate?: boolean | undefined; }>; readModule(id: string, version?: string): TModuleData<CFG>; exists(id: string, version?: string): boolean; getActiveVersion(id: string, silent?: boolean): string; getModulesList(): string[]; getAllModules(): TModuleData<CFG>[]; } export declare class FeRoom extends Moost { protected _registry: FeRegistry; protected _config: FeRoomConfig; protected _ext: (() => Promise<TWrappedExt> | TWrappedExt)[]; constructor(options?: TFeRoomServerOptions, registry?: FeRegistry); init(): Promise<void>; ext(...args: (TClassConstructor<TFeRoomExtension> | TFeRoomExtension)[]): void; } export declare class FeRoomConfig { protected options: TFeRoomServerOptions; constructor(options: TFeRoomServerOptions); get modulesPrefixPath(): string; get globals(): object; get title(): string; get preloadCss(): (string | [string, string])[]; get preloadScript(): (string | [string, string])[]; get preloadModule(): string[]; get body(): string; get head(): string; get importMap(): { [name: string]: string; }; get npmDeps(): TNpmModuleData[]; } export declare function FeRoomExtension(name: string): MethodDecorator & ClassDecorator & ParameterDecorator & PropertyDecorator; export declare class FeRoomIndex { protected _registry: FeRegistry; protected config: FeRoomConfig; protected ext: (() => Promise<TWrappedExt_2> | TWrappedExt_2)[]; constructor(_registry: FeRegistry, config: FeRoomConfig, ext: (() => Promise<TWrappedExt_2> | TWrappedExt_2)[]); getExtInstances(): Promise<{ instance: TFeRoomExtension; name: string; }[]>; getExtHead(): Promise<string>; getExtBody(): Promise<string>; getModules(): FeModule[]; getGlobals(modules: FeModule[]): Promise<string>; getImportmap(modules: FeModule[]): Promise<string>; getCss(modules: FeModule[]): string; getScripts(modules: FeModule[]): string; getPreloadModule(modules: FeModule[]): string; getHead(modules: FeModule[]): Promise<string>; getBody(modules: FeModule[]): Promise<string>; index(): Promise<string>; } export declare const feroomMate: Mate<TMoostMetadata & TFeroomMetadata & TFeroomMetadata & TFeroomMetadata>; export declare class FeRoomServe { protected _registry: FeRegistry; protected wHttp: WooksHttp; protected config: FeRoomConfig; constructor(_registry: FeRegistry, wHttp: WooksHttp, config: FeRoomConfig); protected registered: Record<string, boolean>; registerHttpModulePath(data: TModuleData): TModuleData<object>; serveModule(id: string, version?: string, path?: string): string | Buffer | HttpError<TWooksErrorBody>; updateModulePaths(): void; } declare type TClassConstructor<T = unknown> = new (...args: any[]) => T; declare interface TFeRoomConfig<EXT extends object = TFeRoomExtensionsOptionsAll> { devServer?: TFeRoomDevServerOptions; registerOptions?: TFeRoomRegisterOptions; buildOptions?: TFeRoomRollupOptions; extensions?: EXT; } declare interface TFeRoomDevServerOptions { port?: number; shared?: string; feroom?: TFeRoomServerOptions; ext?: (TClassConstructor<TFeRoomExtension> | TFeRoomExtension)[]; } declare interface TFeRoomExtension { injectGlobals?(): Record<string, unknown>; injectImportMap?(): Record<string, string>; injectHead?(): string; injectIndexBody?(): string; } declare type TFeRoomExtensionsOptionsAll = TSharedMenuCfg & TVueRoutesCfg; export declare interface TFeroomMetadata { feroom_isExtension?: boolean; feroom_extensionName?: string; } declare interface TFeRoomRegisterOptions { id?: string; entry?: string; label?: string; description?: string; include?: string[]; exclude?: string[]; preloadEntry?: boolean | 'head' | 'body:first' | 'body:last'; preloadScripts?: string | string[]; preloadCss?: string | string[]; appendHead?: string; appendBody?: string; globals?: object; lockDependency?: { [name: string]: string; }; importNpmDependencies?: { [name: string]: TNpmModuleData; }; } declare interface TFeRoomRollupOptions { input?: string; ts?: boolean | object; vue?: boolean | object; css?: string | object; nodeResolve?: object; dependencies?: { bundle?: string[]; lockVersion?: string[]; }; output?: string; plugins?: Plugin_2[]; } declare interface TFeRoomServerOptions { modulesPrefixPath?: string; globals?: object; title?: string; preloadCss?: (string | [string, string])[]; preloadScript?: (string | [string, string])[]; preloadModule?: string[]; body?: string; head?: string; importMap?: { [name: string]: string; }; importNpmDependencies?: { [name: string]: TNpmModuleData; }; } declare interface TMenuItem { icon?: string; route?: string; children?: Record<string, TMenuItem>; description?: string; params?: Record<string, string>; } declare interface TModuleData<EXT extends object = object> { id: string; version: string; files: Record<string, string | { type: 'Buffer'; data: number[]; } | Buffer>; entry: string; source: string; config: TFeRoomConfig<EXT>; activate?: boolean; } export declare interface TModuleRoutes { name: string; pattern: string; layout?: string; component: string; } declare type TNpmModuleData<EXT extends object = object> = { registry?: string; name?: string; version?: string; forceRegister?: boolean; activateIfNewer?: boolean; } & Partial<TModuleData<EXT>>; declare type TSharedMenu = Record<string, TMenuItem>; declare interface TSharedMenuCfg { sharedMenu?: TSharedMenu; } declare interface TVueRoute { path: string; component?: string; children?: TVueRoute[]; name?: string; props?: boolean; } declare interface TVueRoutesCfg { vueRoutes?: TVueRoute[]; } declare interface TWrappedExt { instance: TFeRoomExtension; name: string; } declare interface TWrappedExt_2 { instance: TFeRoomExtension; name: string; } export { }