| 541 | * another construct. |
| 542 | */ |
| 543 | export class Construct implements IConstruct { |
| 544 | /** |
| 545 | * Checks if `x` is a construct. |
| 546 | * |
| 547 | * Use this method instead of `instanceof` to properly detect `Construct` |
| 548 | * instances, even when the construct library is symlinked. |
| 549 | * |
| 550 | * Explanation: in JavaScript, multiple copies of the `constructs` library on |
| 551 | * disk are seen as independent, completely different libraries. As a |
| 552 | * consequence, the class `Construct` in each copy of the `constructs` library |
| 553 | * is seen as a different class, and an instance of one class will not test as |
| 554 | * `instanceof` the other class. `npm install` will not create installations |
| 555 | * like this, but users may manually symlink construct libraries together or |
| 556 | * use a monorepo tool: in those cases, multiple copies of the `constructs` |
| 557 | * library can be accidentally installed, and `instanceof` will behave |
| 558 | * unpredictably. It is safest to avoid using `instanceof`, and using |
| 559 | * this type-testing method instead. |
| 560 | * |
| 561 | * @returns true if `x` is an object created from a class which extends `Construct`. |
| 562 | * @param x Any object |
| 563 | */ |
| 564 | public static isConstruct(x: any): x is Construct { |
| 565 | return x && typeof x === 'object' && x[CONSTRUCT_SYM]; |
| 566 | } |
| 567 | |
| 568 | /** |
| 569 | * The tree node. |
| 570 | */ |
| 571 | public readonly node: Node; |
| 572 | |
| 573 | /** |
| 574 | * Creates a new construct node. |
| 575 | * |
| 576 | * @param scope The scope in which to define this construct |
| 577 | * @param id The scoped construct ID. Must be unique amongst siblings. If |
| 578 | * the ID includes a path separator (`/`) or a newline, then it will be |
| 579 | * replaced by double dash `--`. |
| 580 | */ |
| 581 | constructor(scope: Construct, id: string) { |
| 582 | this.node = new Node(this, scope, id); |
| 583 | |
| 584 | // implement IDependable privately |
| 585 | Dependable.implement(this, { |
| 586 | dependencyRoots: [this], |
| 587 | }); |
| 588 | } |
| 589 | |
| 590 | /** |
| 591 | * Applies one or more mixins to this construct. |
| 592 | * |
| 593 | * Mixins are applied in order. The list of constructs is captured at the |
| 594 | * start of the call, so constructs added by a mixin will not be visited. |
| 595 | * Use multiple `with()` calls if subsequent mixins should apply to added |
| 596 | * constructs. |
| 597 | * |
| 598 | * @param mixins The mixins to apply |
| 599 | * @returns This construct for chaining |
| 600 | */ |
nothing calls this directly
no outgoing calls
no test coverage detected