UNPKG

2.76 kBTypeScriptView Raw
1import { Constructor } from '@loopback/core';
2import { ArtifactOptions, Booter } from '../types';
3/**
4 * This class serves as a base class for Booters which follow a pattern of
5 * configure, discover files in a folder(s) using explicit folder / extensions
6 * or a glob pattern and lastly identifying exported classes from such files and
7 * performing an action on such files such as binding them.
8 *
9 * Any Booter extending this base class is expected to
10 *
11 * 1. Set the 'options' property to a object of ArtifactOptions type. (Each extending
12 * class should provide defaults for the ArtifactOptions and use Object.assign to merge
13 * the properties with user provided Options).
14 * 2. Provide it's own logic for 'load' after calling 'await super.load()' to
15 * actually boot the Artifact classes.
16 *
17 * Currently supports the following boot phases: configure, discover, load.
18 *
19 */
20export declare class BaseArtifactBooter implements Booter {
21 /**
22 * Options being used by the Booter.
23 */
24 readonly options: ArtifactOptions;
25 /**
26 * Project root relative to which all other paths are resolved
27 */
28 readonly projectRoot: string;
29 /**
30 * Relative paths of directories to be searched
31 */
32 dirs: string[];
33 /**
34 * File extensions to be searched
35 */
36 extensions: string[];
37 /**
38 * `glob` pattern to match artifact paths
39 */
40 glob: string;
41 /**
42 * List of files discovered by the Booter that matched artifact requirements
43 */
44 discovered: string[];
45 /**
46 * List of exported classes discovered in the files
47 */
48 classes: Constructor<{}>[];
49 constructor(projectRoot: string, options: ArtifactOptions);
50 /**
51 * Get the name of the artifact loaded by this booter, e.g. "Controller".
52 * Subclasses can override the default logic based on the class name.
53 */
54 get artifactName(): string;
55 /**
56 * Configure the Booter by initializing the 'dirs', 'extensions' and 'glob'
57 * properties.
58 *
59 * NOTE: All properties are configured even if all aren't used.
60 */
61 configure(): Promise<void>;
62 /**
63 * Discover files based on the 'glob' property relative to the 'projectRoot'.
64 * Discovered artifact files matching the pattern are saved to the
65 * 'discovered' property.
66 */
67 discover(): Promise<void>;
68 /**
69 * Filters the exports of 'discovered' files to only be Classes (in case
70 * function / types are exported) as an artifact is a Class. The filtered
71 * artifact Classes are saved in the 'classes' property.
72 *
73 * NOTE: Booters extending this class should call this method (await super.load())
74 * and then process the artifact classes as appropriate.
75 */
76 load(): Promise<void>;
77}