|
1 | | -import type { IConstruct } from 'constructs'; |
2 | | - |
3 | | -/** |
4 | | - * A mixin is a reusable piece of functionality that can be applied to constructs |
5 | | - * to add behavior, properties, or modify existing functionality without inheritance. |
6 | | - * |
7 | | - * Mixins follow a three-phase pattern: |
8 | | - * 1. Check if the mixin supports the target construct (supports) |
9 | | - * 2. Optionally validate the construct before applying (validate) |
10 | | - * 3. Apply the mixin functionality to the construct (applyTo) |
11 | | - */ |
12 | | -export interface IMixin { |
13 | | - /** |
14 | | - * Determines whether this mixin can be applied to the given construct. |
15 | | - * |
16 | | - * This method should perform type checking and compatibility validation |
17 | | - * to ensure the mixin can safely operate on the construct. |
18 | | - * |
19 | | - * @param construct - The construct to check for compatibility |
20 | | - * @returns true if the mixin supports this construct type, false otherwise |
21 | | - */ |
22 | | - supports(construct: IConstruct): boolean; |
23 | | - |
24 | | - /** |
25 | | - * Validates the construct before applying the mixin. |
26 | | - * |
27 | | - * This optional method allows the mixin to perform additional validation |
28 | | - * beyond basic type compatibility. It can check for required properties, |
29 | | - * configuration constraints, or other preconditions. |
30 | | - * |
31 | | - * @param construct - The construct to validate |
32 | | - * @returns An array of validation error messages, or empty array if valid |
33 | | - */ |
34 | | - validate?(construct: IConstruct): string[]; |
35 | | - |
36 | | - /** |
37 | | - * Applies the mixin functionality to the target construct. |
38 | | - * |
39 | | - * This method performs the actual work of the mixin, such as: |
40 | | - * - Adding new properties or methods |
41 | | - * - Modifying existing behavior |
42 | | - * - Setting up additional resources or configurations |
43 | | - * - Establishing relationships with other constructs |
44 | | - * |
45 | | - * @param construct - The construct to apply the mixin to |
46 | | - * @returns The modified construct (may be the same instance or a wrapper) |
47 | | - */ |
48 | | - applyTo(construct: IConstruct): IConstruct; |
49 | | -} |
50 | | - |
51 | | -/** |
52 | | - * Abstract base class for mixins that provides default implementations |
53 | | - * and simplifies mixin creation. |
54 | | - */ |
55 | | -export abstract class Mixin implements IMixin { |
56 | | - /** |
57 | | - * Default implementation that supports any construct. |
58 | | - * Override this method to add type-specific support logic. |
59 | | - */ |
60 | | - public supports(_construct: IConstruct): boolean { |
61 | | - return true; |
62 | | - } |
63 | | - |
64 | | - /** |
65 | | - * Default validation implementation that returns no errors. |
66 | | - * Override this method to add custom validation logic. |
67 | | - */ |
68 | | - public validate(_construct: IConstruct): string[] { |
69 | | - return []; |
70 | | - } |
71 | | - |
72 | | - abstract applyTo(construct: IConstruct): IConstruct; |
73 | | -} |
| 1 | +export * from './property-mixins'; |
0 commit comments