UNPKG

@webda/shell

Version:

Deploy a Webda app or configure it

322 lines (321 loc) 9.24 kB
import { Application, Logger } from "@webda/core"; import { JSONSchema7 } from "json-schema"; import { BaseType, Definition, FunctionType, SchemaGenerator, SubTypeFormatter } from "ts-json-schema-generator"; import ts from "typescript"; import { SourceApplication } from "./sourceapplication.js"; type WebdaSearchResult = { type: ts.Type; symbol: ts.Symbol; node: ts.Node; tags: { [key: string]: string; }; jsFile: string; name: string; lib: boolean; }; type WebdaSearchResults = { [key: string]: WebdaSearchResult; }; declare class WebdaSchemaResults { protected store: { [key: string]: { name: string; schemaNode?: ts.Node; link?: string; title?: string; addOpenApi: boolean; }; }; protected byNode: Map<ts.Node, string>; get(node: ts.Node): string; /** * Generate all schemas * @param info */ generateSchemas(compiler: Compiler): {}; add(name: string, info?: ts.Node | string, title?: string, addOpenApi?: boolean): void; } /** * Copy from https://github.com/vega/ts-json-schema-generator/blob/next/src/Utils/modifiers.ts * They are not exported correctly */ /** * Checks if given node has the given modifier. * * @param node - The node to check. * @param modifier - The modifier to look for. * @return True if node has the modifier, false if not. */ export declare function hasModifier(node: ts.Node, modifier: ts.SyntaxKind): boolean; /** * Checks if given node is public. A node is public if it has the public modifier or has no modifiers at all. * * @param node - The node to check. * @return True if node is public, false if not. */ export declare function isPublic(node: ts.Node): boolean; /** * Checks if given node has the static modifier. * * @param node - The node to check. * @return True if node is static, false if not. */ export declare function isStatic(node: ts.Node): boolean; /** * Temporary fix while waiting for https://github.com/vega/ts-json-schema-generator/pull/1182 */ export declare class FunctionTypeFormatter implements SubTypeFormatter { supportsType(type: FunctionType): boolean; getDefinition(_type: FunctionType): Definition; getChildren(_type: FunctionType): BaseType[]; } export declare class NullTypeFormatter implements SubTypeFormatter { supportsType(type: FunctionType): boolean; getDefinition(_type: FunctionType): Definition; getChildren(_type: FunctionType): BaseType[]; } export declare function hash(a: unknown): string | number; export type SymbolRef = { name: string; typeName: string; fullyQualifiedName: string; symbol: ts.Symbol; }; export declare class Compiler { workingDir: string; sourceFile: ts.SourceFile; app: SourceApplication; types: { [key: string]: { library: boolean; type: ts.Type; extenders: Set<string>; }; }; configParseResult: any; schemaGenerator: SchemaGenerator; typeChecker: ts.TypeChecker; compiled: boolean; tsProgram: ts.Program; watchProgram: ts.WatchOfConfigFile<ts.SemanticDiagnosticsBuilderProgram>; static watchOptions: ts.WatchOptions; /** * Construct a compiler for a WebdaApplication * @param app */ constructor(app: SourceApplication); /** * Load the tsconfig.json */ loadTsconfig(app: Application): void; /** * Generate a program from app * @param app * @returns */ createProgramFromApp(app?: Application): void; /** * Return the Javascript target file for a source * @param sourceFile * @param absolutePath * @returns */ getJSTargetFile(sourceFile: ts.SourceFile, absolutePath?: boolean): string; /** * Get the name of the export for a class * * Will also check if it is exported with a `export { MyClass }` * * @param node * @returns */ getExportedName(node: ts.ClassDeclaration | ts.InterfaceDeclaration): string | undefined; /** * Generate a single schema * @param schemaNode */ generateSchema(schemaNode: ts.Node, title?: string): any; /** * Get a schema for a typed node * @param classTree * @param typeName * @param packageName * @returns */ getSchemaNode(classTree: ts.Type[], typeName?: string, packageName?: string): ts.Node; /** * Load all JSDoc tags for a node * @param node * @returns */ getTagsName(node: ts.Node): {}; /** * Retrieve all webda objects from source * * If an object have a @WebdaIgnore tag, it will be ignored * Every CoreModel object will be added if it is exported and not abstract * @returns */ searchForWebdaObjects(): { schemas: WebdaSchemaResults; models: WebdaSearchResults; moddas: WebdaSearchResults; deployers: WebdaSearchResults; beans: WebdaSearchResults; }; /** * Get a model name from a library path based on file and classname * @param fileName * @param className * @returns */ getLibraryModelName(fileName: string, className: string): string; /** * Generating the local module from source * * It scans for JSDoc @WebdaModda and @WebdaModel * to detect Modda and Model * * The @Bean and @Route Decorator will detect the Bean and ImplicitBean * * @param this.tsProgram * @returns */ generateModule(): { beans: any; deployers: any; moddas: any; models: { graph: any; tree: any; plurals: any; list: any; reflections: any; }; schemas: {}; }; /** * Explore services or beans for @Operation and @Route methods * @param services * @param schemas */ exploreServices(services: WebdaSearchResults, schemas: WebdaSchemaResults): void; /** * Ensure each method that are supposed to have a context have one * And detect their input/output schema * * @param rootName * @param method * @param schemas * @returns */ checkMethodForContext(rootName: string, method: ts.MethodDeclaration, schemas: WebdaSchemaResults): void; /** * Explore models * @param models * @param schemas */ exploreModelsAction(models: WebdaSearchResults, schemas: WebdaSchemaResults): void; /** * Get id from TypeNode * * The id is not exposed in the TypeNode * @param type * @returns */ getTypeIdFromTypeNode(type: ts.TypeNode): any; /** * Generate the graph relationship between models * And the hierarchy tree * @param models */ processModels(models: WebdaSearchResults): { graph: any; tree: any; plurals: any; list: any; reflections: any; }; /** * Get the package name for a type * @param type * @returns */ getPackageFromType(type: ts.Type): string; /** * Check if a type extends a certain subtype (packageName/symbolName) * * types can be obtained by using this.getClassTree(type: ts.Type) */ extends(types: ts.Type[], packageName: string, symbolName: string): boolean; createSchemaGenerator(program: ts.Program): void; /** * Compile typescript */ compile(force?: boolean): boolean; /** * Generate the configuration schema * * @param filename to save for * @param full to keep all required */ generateConfigurationSchemas(filename?: string, deploymentFilename?: string, full?: boolean): void; /** * Generate regex based on a service name * * The regex will ensure the namespace is optional * * @param type * @returns */ getServiceTypePattern(type: string): string; /** * Retrieve a schema from a Modda * @param type */ getSchema(type: string): JSONSchema7; /** * Launch compiler in watch mode * @param callback */ watch(callback: (diagnostic: ts.Diagnostic | string) => void, logger: Logger): void; /** * Stop watching for change on typescript */ stopWatch(): void; /** * Get the class hierarchy * @param type * @returns */ getClassTree(type: ts.Type): ts.Type[]; /********************* DEVELOPMENT UTILS ****************/ /** * Utils to display a tree in console * * Useful during development * @param node * @param level */ static displayTree(node: ts.Node, stream?: (...args: any[]) => void, level?: number): void; /** * Display an item * @param node * @param level */ static displayItem(node: ts.Node, log?: (...args: any[]) => void, level?: number): void; /** * Get a parent of a certain Type * @param node * @param type * @returns */ getParent(node: ts.Node, type: ts.SyntaxKind): ts.Node; /** * Display all parent of a Node * @param node */ static displayParents(node: ts.Node, stream?: any): void; } export {};