UNPKG

2.35 kBTypeScriptView Raw
1import { IConstruct } from './construct-compat';
2/**
3 * Trait marker for classes that can be depended upon
4 *
5 * The presence of this interface indicates that an object has
6 * an `IDependableTrait` implementation.
7 *
8 * This interface can be used to take an (ordering) dependency on a set of
9 * constructs. An ordering dependency implies that the resources represented by
10 * those constructs are deployed before the resources depending ON them are
11 * deployed.
12 */
13export interface IDependable {
14}
15/**
16 * A set of constructs to be used as a dependable
17 *
18 * This class can be used when a set of constructs which are disjoint in the
19 * construct tree needs to be combined to be used as a single dependable.
20 *
21 */
22export declare class ConcreteDependable implements IDependable {
23 private readonly _dependencyRoots;
24 constructor();
25 /**
26 * Add a construct to the dependency roots
27 */
28 add(construct: IConstruct): void;
29}
30/**
31 * Trait for IDependable
32 *
33 * Traits are interfaces that are privately implemented by objects. Instead of
34 * showing up in the public interface of a class, they need to be queried
35 * explicitly. This is used to implement certain framework features that are
36 * not intended to be used by Construct consumers, and so should be hidden
37 * from accidental use.
38 *
39 * @example
40 *
41 * // Usage
42 * const roots = DependableTrait.get(construct).dependencyRoots;
43 *
44 * // Definition
45 * class TraitImplementation implements DependableTrait {
46 * public readonly dependencyRoots: IConstruct[];
47 * constructor() {
48 * this.dependencyRoots = [constructA, constructB, constructC];
49 * }
50 * }
51 * DependableTrait.implement(construct, new TraitImplementation());
52 *
53 */
54export declare abstract class DependableTrait {
55 /**
56 * Register `instance` to have the given DependableTrait
57 *
58 * Should be called in the class constructor.
59 */
60 static implement(instance: IDependable, trait: DependableTrait): void;
61 /**
62 * Return the matching DependableTrait for the given class instance.
63 */
64 static get(instance: IDependable): DependableTrait;
65 /**
66 * The set of constructs that form the root of this dependable
67 *
68 * All resources under all returned constructs are included in the ordering
69 * dependency.
70 */
71 abstract readonly dependencyRoots: IConstruct[];
72}