UNPKG

5.26 kBTypeScriptView Raw
1import { ProcessorDef } from './Processor';
2import { Module, FactoryDef, TypeDef } from './Module';
3export declare type PackageRef = Package | string;
4/**
5 * A Dgeni Package containing processors, services and config blocks.
6 * @param {string} name The name of the package
7 * @param {string[]} dependencies The names of packages (or the actual packages) that this package
8 * depends upon
9 */
10export declare class Package {
11 name: string;
12 dependencies: PackageRef[];
13 static isPackage(pkg: any): pkg is Package;
14 processors: any[];
15 configFns: any[];
16 handlers: {
17 [key: string]: string[];
18 };
19 module: Module;
20 namedDependencies: string[];
21 constructor(name: string, dependencies?: PackageRef[]);
22 /**
23 * Add a new processor to the package. The processor can be defined by a processor definition object
24 * or a factory function, which can be injected with services and will return the processor definition
25 * object. The following properties of a processor definition object have special meaning to Dgeni:
26 *
27 * * `name : {string}`: The name of the processor - if the processor is defined by a factory
28 * function or a name is explicitly provided as the first parameter, then this is ignored
29 * * `$process(docs : {string}) : {Array|Promise|undefined}`: The method that will be called to
30 * process the documents. If it is async then it should return a Promise.
31 * * `$runAfter : {string[]}`: Dgeni will ensure that this processor runs after those named here.
32 * * `$runBefore : {string[]}`: Dgeni will ensure that this processor runs before those named here.
33 * * `$validate: {Object}`: Dgeni will check that the properties of the processor, which match the
34 * keys of this object, pass the validation rules provided as the values of this object. See
35 * http://validatejs.org
36 *
37 * @param {function|object|string} processorDefOrName
38 * If this parameter is a string then it will be used as the processor's name, otherwise it is
39 * assumed that it used as the `processorDef`
40 *
41 * @param {function|object} processorDef
42 * The factory function or object that will be used by the injector to create the processor.
43 * * If a function then it is a factory and it must not be anonymous - it must have a name, e.g.
44 * `function myProcessor(dep1, dep2) { ... }` - since the name of the processor is taken from the
45 * name of the factory function.
46 * * If an object, then it is the actual processor and must have a `name` property. In this case,
47 * you cannot inject services into this processor.
48 *
49 * @return {Package}
50 * `this` package, to allow methods to be chained.
51 */
52 processor(processorDefOrName: string | ProcessorDef, processorDef?: ProcessorDef): this;
53 /**
54 * Add a new service, defined by a factory function, to the package
55 *
56 * @param {function|string} serviceFactoryOrName
57 * If a string then this is the name of the service, otherwise it is assumed to be the
58 * `serviceFactory`.
59 *
60 * @param {function} serviceFactory
61 * The factory function that will be used by the injector to create the service. The function must
62 * not be anonymous - it must have a name, e.g. `function myService() { ... }` - since the name of
63 * the service is taken from the name of the factory function.
64 *
65 * @return {Package}
66 * "This" package, to allow methods to be chained.
67 */
68 factory(serviceFactoryOrName: string | FactoryDef, serviceFactory?: FactoryDef): this;
69 /**
70 * Add a new service, defined as a Type to instantiated, to the package
71 *
72 * @param {function|string} ServiceTypeOrName
73 * If a string then this is the name of the service, otherwise it is assumed to be the
74 * `ServiceType`.
75 *
76 * @param {function} ServiceType
77 * The constructor function that will be used by the injector to create the processor. The function
78 * must not be anonymous - it must have a name, e.g. `function MyType() { ... }` - since the name of
79 * the service is taken from the name of the constructor function.
80 *
81 * @return {Package}
82 * "This" package, to allow methods to be chained.
83 */
84 type(ServiceTypeOrName: string | TypeDef, ServiceType?: TypeDef): this;
85 /**
86 * Add a new config block to the package. Config blocks are run at the beginning of the doc
87 * generation before the processors are run. They can be injected with services and processors
88 * to allow you access to their properties so that you can configure them.
89 *
90 * @param {function} configFn The config block function to run
91 *
92 * @return {Package}
93 * "This" package, to allow methods to be chained.
94 */
95 config(configFn: Function): this;
96 /**
97 * Add an event handler to this package
98 * @param {string} eventName The name of the event to handle
99 * @param {function} handlerFactory An injectable factory function that will return the handler
100 * @return {Package} This package for chaining
101 */
102 eventHandler(eventName: string, handlerFactory: FactoryDef): this;
103}
104
\No newline at end of file