UNPKG

@webda/core

Version:

Expose API with Lambda

153 lines (152 loc) 4.17 kB
import { Application, CoreModelDefinition, DeepPartial, Service, ServiceParameters, WebContext } from "../index.js"; import { TransformCaseType } from "../utils/case.js"; /** * @WebdaModda */ export declare class ModelsOperationsService extends Service { /** * Add operations for all exposed models * @returns */ initOperations(): void; } export declare class DomainServiceParameters extends ServiceParameters { /** * Expose objects as operations too */ operations: boolean; /** * Transform the name of the model to be used in the URL * * @see https://blog.boot.dev/clean-code/casings-in-coding/#:~:text=%F0%9F%94%97%20Camel%20Case,Go */ nameTransfomer: TransformCaseType; /** * Method used for query objects * * @default "PUT" */ queryMethod: "PUT" | "GET"; /** * List of models to include * * If model is prefixed with a ! it will be excluded * * @default ["*"] */ models: string[]; /** * * @SchemaIgnore */ private excludedModels; constructor(params: DeepPartial<DomainServiceParameters>); /** * Is a model is included in the service * @param model * @returns */ isIncluded(model: string): boolean; /** * Is a model excluded from the service * @param model * @returns */ isExcluded(model: string): boolean; } /** * Domain Service expose all the models as Route and Operations * * Model are exposed if they have a Expose decorator * * Children models Exposed should be under the first ModelRelated targetting them or the segment endpoint of Expose * * Other relations (ModelLinks, ModelParent) should only display their information but not be exposed * ModelRelated should be ignored */ export declare abstract class DomainService<T extends DomainServiceParameters = DomainServiceParameters> extends Service<T> { app: Application; /** * Load the paremeters for your service * @param params * @param name */ abstract loadParameters(params: DeepPartial<DomainServiceParameters>): DomainServiceParameters; /** * Return the model name for this service * @param name * @returns * * @see https://blog.boot.dev/clean-code/casings-in-coding/#:~:text=%F0%9F%94%97%20Camel%20Case,Go */ transformName(name: string): string; /** * Handle one model and expose it based on the service * @param model * @param name * @param context * @returns */ abstract handleModel(model: CoreModelDefinition, name: string, context: any): boolean; /** * Explore the models * @param model * @param name * @param depth * @param modelContext * @returns */ walkModel(model: CoreModelDefinition, name: string, depth?: number, modelContext?: any): void; /** * Your service is now created as all the other services */ resolve(): this; } /** * */ export declare class RESTDomainServiceParameters extends DomainServiceParameters { /** * Expose the OpenAPI * * @default true if debug false otherwise */ exposeOpenAPI: boolean; /** * Set default url to / * @param params */ constructor(params: any); } /** * Expose all models via a REST API * @WebdaModda */ export declare class RESTDomainService<T extends RESTDomainServiceParameters = RESTDomainServiceParameters> extends DomainService<T> { /** * OpenAPI cache */ openapiContent: string; /** * Override to fallback on isDebug for exposeOpenAPI * @returns */ resolve(): this; /** * @override */ loadParameters(params: DeepPartial<DomainServiceParameters>): DomainServiceParameters; /** * Handle one model and expose it based on the service * @param model * @param name * @param context * @returns */ handleModel(model: CoreModelDefinition, name: string, context: any): boolean; /** * Serve the openapi with the swagger-ui * @param ctx */ openapi(ctx: WebContext): Promise<void>; }