@composurecdk/core 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/dist/commonjs/builder.d.ts.map +1 -0
  2. package/dist/commonjs/builder.js +86 -0
  3. package/dist/commonjs/builder.js.map +1 -0
  4. package/dist/commonjs/compose.d.ts.map +1 -0
  5. package/dist/commonjs/compose.js +114 -0
  6. package/dist/commonjs/compose.js.map +1 -0
  7. package/dist/commonjs/construct-id.d.ts.map +1 -0
  8. package/dist/commonjs/construct-id.js +58 -0
  9. package/dist/commonjs/construct-id.js.map +1 -0
  10. package/dist/commonjs/cyclic-dependency-error.d.ts.map +1 -0
  11. package/dist/commonjs/cyclic-dependency-error.js +20 -0
  12. package/dist/commonjs/cyclic-dependency-error.js.map +1 -0
  13. package/dist/commonjs/index.d.ts.map +1 -0
  14. package/dist/commonjs/index.js +22 -0
  15. package/dist/commonjs/index.js.map +1 -0
  16. package/dist/commonjs/lifecycle.d.ts.map +1 -0
  17. package/dist/commonjs/lifecycle.js +3 -0
  18. package/dist/{lifecycle.js.map → commonjs/lifecycle.js.map} +1 -1
  19. package/dist/commonjs/package.json +3 -0
  20. package/dist/{ref.d.ts → commonjs/ref.d.ts} +16 -0
  21. package/dist/commonjs/ref.d.ts.map +1 -0
  22. package/dist/commonjs/ref.js +129 -0
  23. package/dist/commonjs/ref.js.map +1 -0
  24. package/dist/commonjs/stack-strategy.d.ts.map +1 -0
  25. package/dist/commonjs/stack-strategy.js +59 -0
  26. package/dist/commonjs/stack-strategy.js.map +1 -0
  27. package/dist/commonjs/testing.d.ts +71 -0
  28. package/dist/commonjs/testing.d.ts.map +1 -0
  29. package/dist/commonjs/testing.js +124 -0
  30. package/dist/commonjs/testing.js.map +1 -0
  31. package/dist/esm/builder.d.ts +103 -0
  32. package/dist/esm/builder.d.ts.map +1 -0
  33. package/dist/esm/builder.js.map +1 -0
  34. package/dist/esm/compose.d.ts +177 -0
  35. package/dist/esm/compose.d.ts.map +1 -0
  36. package/dist/esm/compose.js.map +1 -0
  37. package/dist/esm/construct-id.d.ts +45 -0
  38. package/dist/esm/construct-id.d.ts.map +1 -0
  39. package/dist/{construct-id.js → esm/construct-id.js} +1 -1
  40. package/dist/esm/construct-id.js.map +1 -0
  41. package/dist/esm/cyclic-dependency-error.d.ts +12 -0
  42. package/dist/esm/cyclic-dependency-error.d.ts.map +1 -0
  43. package/dist/esm/cyclic-dependency-error.js.map +1 -0
  44. package/dist/esm/index.d.ts +8 -0
  45. package/dist/esm/index.d.ts.map +1 -0
  46. package/dist/esm/index.js.map +1 -0
  47. package/dist/esm/lifecycle.d.ts +23 -0
  48. package/dist/esm/lifecycle.d.ts.map +1 -0
  49. package/dist/esm/lifecycle.js.map +1 -0
  50. package/dist/esm/package.json +3 -0
  51. package/dist/esm/ref.d.ts +133 -0
  52. package/dist/esm/ref.d.ts.map +1 -0
  53. package/dist/{ref.js → esm/ref.js} +17 -1
  54. package/dist/esm/ref.js.map +1 -0
  55. package/dist/esm/stack-strategy.d.ts +75 -0
  56. package/dist/esm/stack-strategy.d.ts.map +1 -0
  57. package/dist/esm/stack-strategy.js.map +1 -0
  58. package/dist/esm/testing.d.ts +71 -0
  59. package/dist/esm/testing.d.ts.map +1 -0
  60. package/dist/esm/testing.js +121 -0
  61. package/dist/esm/testing.js.map +1 -0
  62. package/package.json +42 -13
  63. package/dist/builder.d.ts.map +0 -1
  64. package/dist/builder.js.map +0 -1
  65. package/dist/compose.d.ts.map +0 -1
  66. package/dist/compose.js.map +0 -1
  67. package/dist/construct-id.d.ts.map +0 -1
  68. package/dist/construct-id.js.map +0 -1
  69. package/dist/cyclic-dependency-error.d.ts.map +0 -1
  70. package/dist/cyclic-dependency-error.js.map +0 -1
  71. package/dist/index.d.ts.map +0 -1
  72. package/dist/index.js.map +0 -1
  73. package/dist/lifecycle.d.ts.map +0 -1
  74. package/dist/ref.d.ts.map +0 -1
  75. package/dist/ref.js.map +0 -1
  76. package/dist/stack-strategy.d.ts.map +0 -1
  77. package/dist/stack-strategy.js.map +0 -1
  78. /package/dist/{builder.d.ts → commonjs/builder.d.ts} +0 -0
  79. /package/dist/{compose.d.ts → commonjs/compose.d.ts} +0 -0
  80. /package/dist/{construct-id.d.ts → commonjs/construct-id.d.ts} +0 -0
  81. /package/dist/{cyclic-dependency-error.d.ts → commonjs/cyclic-dependency-error.d.ts} +0 -0
  82. /package/dist/{index.d.ts → commonjs/index.d.ts} +0 -0
  83. /package/dist/{lifecycle.d.ts → commonjs/lifecycle.d.ts} +0 -0
  84. /package/dist/{stack-strategy.d.ts → commonjs/stack-strategy.d.ts} +0 -0
  85. /package/dist/{builder.js → esm/builder.js} +0 -0
  86. /package/dist/{compose.js → esm/compose.js} +0 -0
  87. /package/dist/{cyclic-dependency-error.js → esm/cyclic-dependency-error.js} +0 -0
  88. /package/dist/{index.js → esm/index.js} +0 -0
  89. /package/dist/{lifecycle.js → esm/lifecycle.js} +0 -0
  90. /package/dist/{stack-strategy.js → esm/stack-strategy.js} +0 -0
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Asserts that {@link IBuilder.copy | `.copy()`} returns an independent
3
+ * builder that preserves non-`props` state set via {@link COPY_STATE}.
4
+ *
5
+ * The helper is the standard way per-package tests verify each accumulator
6
+ * a builder holds outside `props`. It executes the following sequence and
7
+ * asserts the two invariants implied by ADR-0005:
8
+ *
9
+ * 1. Build a **baseline**: `factory()` then `configure()`.
10
+ * 2. Build the **copy**: `factory()`, `configure()`, then `.copy()`.
11
+ * Apply `mutate()` to the original *after* the copy is taken.
12
+ * 3. Build the **original** (now carrying both `configure` and `mutate`).
13
+ *
14
+ * Note that the baseline is constructed via `factory()` rather than via
15
+ * `.copy()` — using `.copy()` would make the helper unable to detect a
16
+ * broken `[COPY_STATE]`, since both the "baseline" and the "copy" would
17
+ * drop the same state and still match.
18
+ *
19
+ * Then:
20
+ *
21
+ * - `inspect(copyResult)` must deep-equal `inspect(baselineResult)` —
22
+ * the copy preserved exactly the state that `configure` set up.
23
+ * A failure here means `[COPY_STATE]` is missing, incomplete, or buggy.
24
+ * - `inspect(originalResult)` must deep-not-equal `inspect(baselineResult)` —
25
+ * `mutate` actually changed inspectable state. Without this sanity
26
+ * check, a no-op `mutate` would let the first assertion pass
27
+ * trivially, hiding an isolation bug.
28
+ *
29
+ * @param args.factory - Returns a fresh, unconfigured builder. Called
30
+ * twice — the helper builds two independent instances so that the
31
+ * build calls don't share construct scopes and so the baseline does
32
+ * not depend on `.copy()`.
33
+ * @param args.configure - Applies the state under test (e.g. adds a
34
+ * `customAlarm`, configures `#vpc`, appends a `subscription`). Called
35
+ * on the baseline and on the original.
36
+ * @param args.mutate - Applied to the original *after* the copy is taken.
37
+ * Must change something the `inspect` callback can see — typically a
38
+ * second `configure`-shaped call that adds another item to the
39
+ * accumulator under test.
40
+ * @param args.build - Calls `.build(scope, id)` against a fresh CDK
41
+ * scope. Three separate scopes are required (one per build) — return a
42
+ * freshly constructed scope each call. Reusing a scope across calls
43
+ * surfaces as a CDK duplicate-id error rather than a silent leak.
44
+ * @param args.inspect - Extracts the slice of the build result whose
45
+ * shape depends on the state under test (e.g.
46
+ * `result => Object.keys(result.alarms)`).
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * import { App, Stack } from "aws-cdk-lib";
51
+ * import { assertCopyPreservesState } from "@composurecdk/core/testing";
52
+ *
53
+ * assertCopyPreservesState({
54
+ * factory: () => createCertificateBuilder().domainName("example.com"),
55
+ * configure: (b) => b.customAlarm({ id: "FirstAlarm", ... }),
56
+ * mutate: (b) => b.customAlarm({ id: "SecondAlarm", ... }),
57
+ * build: (b) => b.build(new Stack(new App(), "S"), "Cert"),
58
+ * inspect: (r) => Object.keys(r.alarms).sort(),
59
+ * });
60
+ * ```
61
+ */
62
+ export declare function assertCopyPreservesState<B extends {
63
+ copy(): B;
64
+ }, R>(args: {
65
+ factory: () => B;
66
+ configure: (builder: B) => void;
67
+ mutate: (builder: B) => void;
68
+ build: (builder: B) => R;
69
+ inspect: (result: R) => unknown;
70
+ }): void;
71
+ //# sourceMappingURL=testing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../../src/testing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,SAAS;IAAE,IAAI,IAAI,CAAC,CAAA;CAAE,EAAE,CAAC,EAAE,IAAI,EAAE;IACzE,OAAO,EAAE,MAAM,CAAC,CAAC;IACjB,SAAS,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,CAAC;IAChC,MAAM,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,IAAI,CAAC;IAC7B,KAAK,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC;IACzB,OAAO,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,OAAO,CAAC;CACjC,GAAG,IAAI,CAsCP"}
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertCopyPreservesState = assertCopyPreservesState;
4
+ /**
5
+ * Asserts that {@link IBuilder.copy | `.copy()`} returns an independent
6
+ * builder that preserves non-`props` state set via {@link COPY_STATE}.
7
+ *
8
+ * The helper is the standard way per-package tests verify each accumulator
9
+ * a builder holds outside `props`. It executes the following sequence and
10
+ * asserts the two invariants implied by ADR-0005:
11
+ *
12
+ * 1. Build a **baseline**: `factory()` then `configure()`.
13
+ * 2. Build the **copy**: `factory()`, `configure()`, then `.copy()`.
14
+ * Apply `mutate()` to the original *after* the copy is taken.
15
+ * 3. Build the **original** (now carrying both `configure` and `mutate`).
16
+ *
17
+ * Note that the baseline is constructed via `factory()` rather than via
18
+ * `.copy()` — using `.copy()` would make the helper unable to detect a
19
+ * broken `[COPY_STATE]`, since both the "baseline" and the "copy" would
20
+ * drop the same state and still match.
21
+ *
22
+ * Then:
23
+ *
24
+ * - `inspect(copyResult)` must deep-equal `inspect(baselineResult)` —
25
+ * the copy preserved exactly the state that `configure` set up.
26
+ * A failure here means `[COPY_STATE]` is missing, incomplete, or buggy.
27
+ * - `inspect(originalResult)` must deep-not-equal `inspect(baselineResult)` —
28
+ * `mutate` actually changed inspectable state. Without this sanity
29
+ * check, a no-op `mutate` would let the first assertion pass
30
+ * trivially, hiding an isolation bug.
31
+ *
32
+ * @param args.factory - Returns a fresh, unconfigured builder. Called
33
+ * twice — the helper builds two independent instances so that the
34
+ * build calls don't share construct scopes and so the baseline does
35
+ * not depend on `.copy()`.
36
+ * @param args.configure - Applies the state under test (e.g. adds a
37
+ * `customAlarm`, configures `#vpc`, appends a `subscription`). Called
38
+ * on the baseline and on the original.
39
+ * @param args.mutate - Applied to the original *after* the copy is taken.
40
+ * Must change something the `inspect` callback can see — typically a
41
+ * second `configure`-shaped call that adds another item to the
42
+ * accumulator under test.
43
+ * @param args.build - Calls `.build(scope, id)` against a fresh CDK
44
+ * scope. Three separate scopes are required (one per build) — return a
45
+ * freshly constructed scope each call. Reusing a scope across calls
46
+ * surfaces as a CDK duplicate-id error rather than a silent leak.
47
+ * @param args.inspect - Extracts the slice of the build result whose
48
+ * shape depends on the state under test (e.g.
49
+ * `result => Object.keys(result.alarms)`).
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * import { App, Stack } from "aws-cdk-lib";
54
+ * import { assertCopyPreservesState } from "@composurecdk/core/testing";
55
+ *
56
+ * assertCopyPreservesState({
57
+ * factory: () => createCertificateBuilder().domainName("example.com"),
58
+ * configure: (b) => b.customAlarm({ id: "FirstAlarm", ... }),
59
+ * mutate: (b) => b.customAlarm({ id: "SecondAlarm", ... }),
60
+ * build: (b) => b.build(new Stack(new App(), "S"), "Cert"),
61
+ * inspect: (r) => Object.keys(r.alarms).sort(),
62
+ * });
63
+ * ```
64
+ */
65
+ function assertCopyPreservesState(args) {
66
+ const { factory, configure, mutate, build, inspect } = args;
67
+ const baseline = factory();
68
+ configure(baseline);
69
+ const baselineState = inspect(build(baseline));
70
+ const original = factory();
71
+ configure(original);
72
+ if (typeof original.copy !== "function") {
73
+ throw new Error("assertCopyPreservesState: builder returned by `factory` has no `.copy()` method. " +
74
+ "Pass a builder produced by `Builder()` / `taggedBuilder()` from `@composurecdk/core` / `@composurecdk/cloudformation`.");
75
+ }
76
+ const copy = original.copy();
77
+ mutate(original);
78
+ const originalState = inspect(build(original));
79
+ const copyState = inspect(build(copy));
80
+ if (deepEqual(originalState, baselineState)) {
81
+ throw new Error("assertCopyPreservesState: `mutate` did not change inspectable state on the original — " +
82
+ "the test cannot detect a leak through `.copy()`. Make `mutate` and `inspect` cover " +
83
+ "the same accumulator.\n" +
84
+ ` baseline: ${format(baselineState)}\n` +
85
+ ` original: ${format(originalState)}`);
86
+ }
87
+ if (!deepEqual(copyState, baselineState)) {
88
+ throw new Error("assertCopyPreservesState: `.copy()` did not preserve state set by `configure`. " +
89
+ "The builder is missing, incomplete, or has a buggy `[COPY_STATE]` hook (see ADR-0005).\n" +
90
+ ` baseline: ${format(baselineState)}\n` +
91
+ ` copy: ${format(copyState)}`);
92
+ }
93
+ }
94
+ function deepEqual(a, b) {
95
+ if (Object.is(a, b))
96
+ return true;
97
+ if (typeof a !== "object" || a === null)
98
+ return false;
99
+ if (typeof b !== "object" || b === null)
100
+ return false;
101
+ if (Array.isArray(a)) {
102
+ if (!Array.isArray(b) || a.length !== b.length)
103
+ return false;
104
+ return a.every((item, i) => deepEqual(item, b[i]));
105
+ }
106
+ if (Array.isArray(b))
107
+ return false;
108
+ const aKeys = Object.keys(a);
109
+ const bKeys = Object.keys(b);
110
+ if (aKeys.length !== bKeys.length)
111
+ return false;
112
+ const bRec = b;
113
+ return aKeys.every((k) => Object.prototype.hasOwnProperty.call(bRec, k) &&
114
+ deepEqual(a[k], bRec[k]));
115
+ }
116
+ function format(value) {
117
+ try {
118
+ return JSON.stringify(value);
119
+ }
120
+ catch {
121
+ return String(value);
122
+ }
123
+ }
124
+ //# sourceMappingURL=testing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.js","sourceRoot":"","sources":["../../src/testing.ts"],"names":[],"mappings":";;AA6DA,4DA4CC;AAzGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH,SAAgB,wBAAwB,CAA6B,IAMpE;IACC,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAE5D,MAAM,QAAQ,GAAG,OAAO,EAAE,CAAC;IAC3B,SAAS,CAAC,QAAQ,CAAC,CAAC;IACpB,MAAM,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;IAE/C,MAAM,QAAQ,GAAG,OAAO,EAAE,CAAC;IAC3B,SAAS,CAAC,QAAQ,CAAC,CAAC;IACpB,IAAI,OAAQ,QAA+B,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;QAChE,MAAM,IAAI,KAAK,CACb,mFAAmF;YACjF,wHAAwH,CAC3H,CAAC;IACJ,CAAC;IACD,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,CAAC;IAC7B,MAAM,CAAC,QAAQ,CAAC,CAAC;IAEjB,MAAM,aAAa,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC/C,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IAEvC,IAAI,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CACb,wFAAwF;YACtF,qFAAqF;YACrF,yBAAyB;YACzB,eAAe,MAAM,CAAC,aAAa,CAAC,IAAI;YACxC,eAAe,MAAM,CAAC,aAAa,CAAC,EAAE,CACzC,CAAC;IACJ,CA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AAK,CAChB,CAAC,CAAC,EAAE,EAAE,CACJ,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAC7C,SAAS,CAAE,CAA6B,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CACxD,CAAC;AACJ,CAAC;AAED,SAAS,MAAM,CAAC,KAAc;IAC5B,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;AACH,CAAC"}
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Constructs an instance of `T`.
3
+ */
4
+ type Constructor<T> = new () => T;
5
+ /**
6
+ * Constrains `T` to have a mutable `props` property of type `Props`.
7
+ * Classes used with {@link Builder} must expose their configuration this way.
8
+ */
9
+ interface ObjectWithProps<Props extends object> {
10
+ props: Partial<Props>;
11
+ }
12
+ /**
13
+ * Optional hook a builder class can implement to clone non-`props` state
14
+ * during {@link IBuilder.copy}.
15
+ *
16
+ * The default `.copy()` shallow-clones `props` and wraps a fresh instance.
17
+ * State stored outside `props` (private fields, internal accumulators) is
18
+ * invisible to that default. A class with such state defines a method
19
+ * keyed by this symbol to copy it onto the new instance.
20
+ *
21
+ * See ADR-0005 for the full protocol, including how decorator layers
22
+ * participate.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * class StackBuilder {
27
+ * props: Partial<StackProps> = {};
28
+ * readonly #tags: [string, string][] = [];
29
+ *
30
+ * [COPY_STATE](target: StackBuilder): void {
31
+ * target.#tags.push(...this.#tags);
32
+ * }
33
+ * }
34
+ * ```
35
+ */
36
+ export declare const COPY_STATE: unique symbol;
37
+ /**
38
+ * A fluent builder interface generated from a props type and a target class.
39
+ *
40
+ * For each key in `Props`, the builder exposes an overloaded method:
41
+ * - Called with an argument: sets the prop value and returns the builder for chaining.
42
+ * - Called with no arguments: returns the current prop value.
43
+ *
44
+ * Methods from `T` that return `T` (chainable methods) have their return type
45
+ * replaced to return the builder. All other members of `T` pass through as-is,
46
+ * allowing methods like `build()` to be called directly on the builder.
47
+ *
48
+ * Every builder also exposes {@link IBuilder.copy | `.copy()`}, which returns
49
+ * an independent builder with the same configured state.
50
+ *
51
+ * @typeParam Props - The configurable properties.
52
+ * @typeParam T - The target class the builder wraps.
53
+ */
54
+ export type IBuilder<Props extends object, T> = {
55
+ [K in keyof Props]-?: ((arg: Props[K]) => IBuilder<Props, T>) & (() => Props[K]);
56
+ } & {
57
+ [K in keyof T]: T[K] extends (...args: infer A) => T ? (...args: A) => IBuilder<Props, T> : T[K];
58
+ } & {
59
+ /**
60
+ * Returns an independent builder with the same configured props and any
61
+ * state that the underlying class copies via {@link COPY_STATE}.
62
+ *
63
+ * Mutations to the returned builder do not affect the original, and
64
+ * vice versa.
65
+ *
66
+ * `props` is shallow-cloned (`{ ...this.props }`). Top-level keys are
67
+ * independent; nested object references (CDK constructs, IRoles, IVpcs,
68
+ * etc.) are shared by design — they are construct identities, not
69
+ * configuration data. Builders with internal lists/maps/sets that should
70
+ * be deep-cloned implement {@link COPY_STATE}.
71
+ *
72
+ * Use cases:
73
+ * - **Variant authoring** — derive multiple builders from a shared base
74
+ * (`const us = base.copy().region("us-east-1")`).
75
+ * - **Strategy hand-off snapshot** — pass an isolated builder to a stack
76
+ * strategy (`singleStack(base.copy())`) so later mutations to the
77
+ * original don't leak into the strategy's lazy `build()`.
78
+ *
79
+ * See ADR-0005 for the design rationale.
80
+ */
81
+ copy(): IBuilder<Props, T>;
82
+ };
83
+ /**
84
+ * Creates a fluent builder wrapping an instance of `T`.
85
+ *
86
+ * The builder is backed by a {@link Proxy} that intercepts property access:
87
+ * - For `copy`: returns a function that produces an independent builder with
88
+ * the same configured state (see {@link IBuilder.copy}).
89
+ * - For keys in `Props`: returns a getter/setter function. When called with a
90
+ * value, it sets the prop and returns the builder. When called with no args,
91
+ * it returns the current value.
92
+ * - For methods on `T` that return `T`: wraps them to return the builder instead.
93
+ * - For all other members: delegates directly to the underlying instance.
94
+ *
95
+ * @param constructor - The class to instantiate and wrap.
96
+ * @param instance - Optional pre-existing instance to wrap. Defaults to
97
+ * `new constructor()`. Used internally by {@link IBuilder.copy} to wrap a
98
+ * freshly cloned instance without re-running the constructor for new state.
99
+ * @returns A fluent {@link IBuilder} wrapping `instance`.
100
+ */
101
+ export declare function Builder<Props extends object, T extends ObjectWithProps<Props>>(constructor: Constructor<T>, instance?: T): IBuilder<Props, T>;
102
+ export {};
103
+ //# sourceMappingURL=builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/builder.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,KAAK,WAAW,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC;AAElC;;;GAGG;AACH,UAAU,eAAe,CAAC,KAAK,SAAS,MAAM;IAC5C,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,UAAU,eAA+C,CAAC;AAEvE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,QAAQ,CAAC,KAAK,SAAS,MAAM,EAAE,CAAC,IAAI;KAC7C,CAAC,IAAI,MAAM,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC;CACjF,GAAG;KACD,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC,GAAG,C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} from "./stack-strategy.js";
4
+ /**
5
+ * Maps a record of {@link Lifecycle} components to a record of their build outputs.
6
+ * Each property's type is derived from the return type of the corresponding
7
+ * component's `build` method, preserving full type information through composition.
8
+ *
9
+ * @typeParam T - A record where every value implements {@link Lifecycle}.
10
+ */
11
+ type BuildResult<T extends {
12
+ [Property in keyof T]: Lifecycle;
13
+ }> = {
14
+ [Property in keyof T]: ReturnType<T[Property]["build"]>;
15
+ };
16
+ /**
17
+ * Declares which other components a component depends on within a system.
18
+ * Dependencies are expressed as an array of component keys. During build,
19
+ * the resolved outputs of these components are passed as the component's context.
20
+ *
21
+ * @typeParam Components - The full set of components in the system.
22
+ */
23
+ type Dependency<Components extends Record<string, Lifecycle>> = (keyof Components)[];
24
+ /**
25
+ * A callback invoked after all components in a composed system have been
26
+ * built. Receives the top-level scope, system id, the fully-typed build
27
+ * results of every component, and a record mapping each component key to
28
+ * the scope it was built into.
29
+ *
30
+ * `componentScopes` makes per-component scopes visible to hooks so they can
31
+ * attach additional constructs to the same stack a given component was
32
+ * routed to — useful under {@link ComposedSystem.withStacks} or
33
+ * {@link ComposedSystem.withStackStrategy}, where different components may
34
+ * live in different stacks.
35
+ *
36
+ * Domain-specific packages provide helper functions that return hooks. For
37
+ * example, `@composurecdk/cloudformation` exports {@link outputs} which
38
+ * creates `CfnOutput` constructs from {@link Ref}-based definitions.
39
+ *
40
+ * @typeParam T - The build result type of the composed system.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const logResults: AfterBuildHook<{ site: BucketBuilderResult }> =
45
+ * (_scope, _id, results) => {
46
+ * console.log("Bucket:", results.site.bucket.bucketName);
47
+ * };
48
+ * ```
49
+ */
50
+ export type AfterBuildHook<T extends object> = (scope: IConstruct, id: string, results: T, componentScopes: {
51
+ readonly [K in keyof T]: IConstruct;
52
+ }) => void;
53
+ /**
54
+ * A {@link Lifecycle} produced by {@link compose}, extended with methods
55
+ * for controlling how components are routed to scopes and for registering
56
+ * post-build hooks.
57
+ *
58
+ * Because `ComposedSystem` extends `Lifecycle`, a composed system can be
59
+ * nested as a component inside another `compose` call — composition is
60
+ * recursive.
61
+ */
62
+ export interface ComposedSystem<Components extends Record<string, Lifecycle>> extends Lifecycle<BuildResult<Components>> {
63
+ /**
64
+ * Returns a new {@link Lifecycle} that routes components to specific scopes
65
+ * (typically Stacks) during build. Components not listed in the map use the
66
+ * default scope passed to `build`.
67
+ *
68
+ * Accepts any `IConstruct`, so `Stack`, `DeploymentStack`, or custom
69
+ * subclasses all work.
70
+ *
71
+ * @param stacks - A partial map from component key to scope.
72
+ * @returns A {@link Lifecycle} with stack routing applied.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * compose({ handler, api }, { handler: [], api: ["handler"] })
77
+ * .withStacks({ handler: serviceStack, api: apiStack })
78
+ * .build(app, "MySystem");
79
+ * ```
80
+ */
81
+ withStacks(stacks: {
82
+ [K in keyof Components]?: IConstruct;
83
+ }): ConfiguredSystem<Components>;
84
+ /**
85
+ * Returns a new {@link ConfiguredSystem} that uses a {@link StackStrategy}
86
+ * to determine each component's scope during build. The returned system
87
+ * supports further chaining of {@link ConfiguredSystem.afterBuild | .afterBuild()} hooks.
88
+ *
89
+ * Mutually exclusive with {@link withStacks} — calling one locks the
90
+ * stack routing; further stack-routing methods are not available on the
91
+ * returned {@link ConfiguredSystem}.
92
+ *
93
+ * @param strategy - The strategy that resolves scopes for components.
94
+ * @returns A {@link ConfiguredSystem} with strategy-based stack routing applied.
95
+ *
96
+ * @example
97
+ * ```ts
98
+ * compose({ handler, api, table }, { ... })
99
+ * .withStackStrategy(groupedStacks(
100
+ * key => key === "table" ? "persistence" : "service",
101
+ * (app, id) => new Stack(app, id),
102
+ * ))
103
+ * .afterBuild(outputs({ ... }))
104
+ * .build(app, "MySystem");
105
+ * ```
106
+ */
107
+ withStackStrategy(strategy: StackStrategy): ConfiguredSystem<Components>;
108
+ /**
109
+ * Returns a new {@link ConfiguredSystem} that invokes the given hook after
110
+ * all components have been built. The hook receives the scope, system id,
111
+ * and the fully-typed build results.
112
+ *
113
+ * Multiple hooks can be chained — each `.afterBuild()` appends to the
114
+ * hook list and returns the same {@link ConfiguredSystem} for further
115
+ * chaining.
116
+ *
117
+ * This is the extension point for adding post-build behaviour to a
118
+ * composed system without modifying the system itself. Domain-specific
119
+ * packages provide helper functions that return hooks — for example,
120
+ * `outputs()` from `@composurecdk/cloudformation` creates CfnOutput
121
+ * constructs.
122
+ *
123
+ * @param hook - A callback invoked after all components are built.
124
+ * @returns A {@link ConfiguredSystem} with the hook applied.
125
+ *
126
+ * @example
127
+ * ```ts
128
+ * compose({ site, cdn }, { site: [], cdn: ["site"] })
129
+ * .afterBuild(outputs({
130
+ * Url: { value: ref("cdn", r => r.distribution.domainName) },
131
+ * }))
132
+ * .build(stack, "MySystem");
133
+ * ```
134
+ */
135
+ afterBuild(hook: AfterBuildHook<BuildResult<Components>>): ConfiguredSystem<Components>;
136
+ }
137
+ /**
138
+ * A {@link Lifecycle} with stack routing or post-build hooks applied.
139
+ * Returned by {@link ComposedSystem.withStacks},
140
+ * {@link ComposedSystem.withStackStrategy}, and
141
+ * {@link ComposedSystem.afterBuild}.
142
+ *
143
+ * Supports chaining further {@link afterBuild} hooks. Stack routing methods
144
+ * are not available — they are mutually exclusive and must be chosen on
145
+ * the original {@link ComposedSystem}.
146
+ */
147
+ export interface ConfiguredSystem<Components extends Record<string, Lifecycle>> extends Lifecycle<BuildResult<Components>> {
148
+ /**
149
+ * Appends a post-build hook. Multiple hooks can be chained; they execute
150
+ * in registration order after all components have been built.
151
+ *
152
+ * @param hook - A callback invoked after all components are built.
153
+ * @returns This {@link ConfiguredSystem} for further chaining.
154
+ */
155
+ afterBuild(hook: AfterBuildHook<BuildResult<Components>>): ConfiguredSystem<Components>;
156
+ }
157
+ /**
158
+ * Composes a set of {@link Lifecycle} components into a single system that
159
+ * manages their build order and dependency resolution.
160
+ *
161
+ * A directed acyclic graph is built eagerly from the declared dependencies.
162
+ * Cyclic dependencies are detected at composition time and throw immediately.
163
+ * When `build` is called, components are built in topological order, each
164
+ * receiving the build outputs of its dependencies as its context.
165
+ *
166
+ * The returned {@link ComposedSystem} is a {@link Lifecycle}, so it can be
167
+ * nested as a component in a larger `compose` call.
168
+ *
169
+ * @param components - A record of named {@link Lifecycle} components.
170
+ * @param dependencies - For each component, the list of other component keys it depends on.
171
+ * @returns A {@link ComposedSystem} whose build output is the combined {@link BuildResult} of all components.
172
+ */
173
+ export declare function compose<Components extends Record<string, Lifecycle>>(components: Components, dependencies: {
174
+ [Property in keyof Components]: Dependency<Components>;
175
+ }): ComposedSystem<Components>;
176
+ export {};
177
+ //# sourceMappingURL=compose.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../../src/compose.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD;;;;;;GAMG;AACH,KAAK,WAAW,CAAC,CAAC,SAAS;KAAG,QAAQ,IAAI,MAAM,CAAC,GAAG,SAAS;CAAE,IAAI;KAChE,QAAQ,IAAI,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,OAAO,CAAC,CAAC;CACxD,CAAC;AAEF;;;;;;GAMG;AACH,KAAK,UAAU,CAAC,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI,CAAC,MAAM,UAAU,CAAC,EAAE,CAAC;AA+BrF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,MAAM,IAAI,CAC7C,KAAK,EAAE,UAAU,EACjB,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,CAAC,EACV,eAAe,EAAE;IAAE,QAAQ,EAAE,CAAC,IAA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AAI,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,EAAE,aAAa,CAAC,CAAC;QAC7E,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAC/B,IAAI,CAAC,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC;QAC5C,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,OAAO,CACrB,UAAsB,EACtB,YAAwE;IAExE,OAAO,IAAI,iBAAiB,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;AACzD,CAAC"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Utilities for producing safe CDK construct IDs from arbitrary strings.
3
+ *
4
+ * The `constructs` library uses `/` as the path separator between construct
5
+ * IDs. When user-supplied strings (DNS names, ARNs, filesystem paths) are
6
+ * passed through to a construct ID, any embedded `/` silently gets rewritten
7
+ * to `--`, which produces unreadable CloudFormation logical IDs. Control
8
+ * characters are likewise unsafe.
9
+ *
10
+ * These helpers consolidate that sanitization in one place so every builder
11
+ * in the monorepo applies the same constraints.
12
+ */
13
+ /**
14
+ * Return a construct-ID-safe copy of `raw` by replacing unsafe characters
15
+ * (`/` and control characters) with a single `-`.
16
+ *
17
+ * Does not touch other characters — CDK construct IDs are otherwise
18
+ * permissive, and collapsing further (e.g., to PascalCase) would destroy
19
+ * information a reader expects to see in the synthesised tree.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * sanitizeConstructId("a/b") // "a-b"
24
+ * sanitizeConstructId("_sip._tcp") // "_sip._tcp" (unchanged)
25
+ * ```
26
+ */
27
+ export declare function sanitizeConstructId(raw: string): string;
28
+ /**
29
+ * Join the supplied parts into a single construct ID. Falsy parts are
30
+ * dropped; each remaining part is passed through {@link sanitizeConstructId}
31
+ * and the results are joined with `-`.
32
+ *
33
+ * Intended for composing IDs from a mix of static prefixes and user-supplied
34
+ * fragments — the sanitization step means callers don't have to reason about
35
+ * what characters their inputs might contain.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * constructId("records", "a", "api") // "records-a-api"
40
+ * constructId("zone", undefined, "www") // "zone-www"
41
+ * constructId("records", "a/b") // "records-a-b"
42
+ * ```
43
+ */
44
+ export declare function constructId(...parts: readonly (string | undefined | null | false)[]): string;
45
+ //# sourceMappingURL=construct-id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"construct-id.d.ts","sourceRoot":"","sources":["../../src/construct-id.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,GAAG,KAAK,EAAE,SAAS,CAAC,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,KAAK,CAAC,EAAE,GAAG,MAAM,CAK5F"}
@@ -10,7 +10,7 @@
10
10
  * These helpers consolidate that sanitization in one place so every builder
11
11
  * in the monorepo applies the same constraints.
12
12
  */
13
- // eslint-disable-next-line no-control-regex
13
+ // eslint-disable-next-line no-control-regex -- the regex must literally match control characters to strip them from construct IDs
14
14
  const UNSAFE = /[/\x00-\x1f\x7f]/g;
15
15
  /**
16
16
  * Return a construct-ID-safe copy of `raw` by replacing unsafe characters
@@ -0,0 +1 @@
1
+ {"version":3,"file":"construct-id.js","sourceRoot":"","sources":["../../src/construct-id.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,kIAAkI;AAClI,MAAM,MAAM,GAAG,mBAAmB,CAAC;AAEnC;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,mBAAmB,CAAC,GAAW;IAC7C,OAAO,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAClC,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,WAAW,CAAC,GAAG,KAAqD;IAClF,OAAO,KAAK;SACT,MAAM,CAAC,CAAC,CAAC,EAAe,EAAE,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;SACjE,GAAG,CAAC,mBAAmB,CAAC;SACxB,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Thrown when {@link compose} detects a cycle in the component dependency graph.
3
+ * Carries the detected cycles so callers can inspect or report them programmatically.
4
+ */
5
+ export declare class CyclicDependencyError extends Error {
6
+ readonly cycles: string[][];
7
+ /**
8
+ * @param cycles - Each element is an array of component keys forming a cycle.
9
+ */
10
+ constructor(cycles: string[][]);
11
+ }
12
+ //# sourceMappingURL=cyclic-dependency-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cyclic-dependency-error.d.ts","sourceRoot":"","sources":["../../src/cyclic-dependency-error.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;aAIlB,MAAM,EAAE,MAAM,EAAE,EAAE;IAH9C;;OAEG;gBACyB,MAAM,EAAE,MAAM,EAAE,EAAE;CAI/C"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cyclic-dependency-error.js","sourceRoot":"","sources":["../../src/cyclic-dependency-error.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAIlB;IAH5B;;OAEG;IACH,YAA4B,MAAkB;QAC5C,KAAK,CAAC,iCAAiC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAD7D,WAAM,GAAN,MAAM,CAAY;QAE5C,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;IACtC,CAAC;CACF"}
@@ -0,0 +1,8 @@
1
+ export { Builder, COPY_STATE, type IBuilder } from "./builder.js";
2
+ export { constructId, sanitizeConstructId } from "./construct-id.js";
3
+ export { compose, type ComposedSystem, type ConfiguredSystem, type AfterBuildHook, } from "./compose.js";
4
+ export { CyclicDependencyError } from "./cyclic-dependency-error.js";
5
+ export { type Lifecycle } from "./lifecycle.js";
6
+ export { Ref, ref, resolve, isRef, type Resolvable } from "./ref.js";
7
+ export { type StackStrategy, type ScopeFactory, singleStack, groupedStacks, } from "./stack-strategy.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,QAAQ,EAAE,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EACL,OAAO,EACP,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,cAAc,GACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,WAAW,EACX,aAAa,GACd,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAiB,MAAM,cAAc,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EACL,OAAO,GAIR,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAmB,MAAM,UAAU,CAAC;AACrE,OAAO,EAGL,WAAW,EACX,aAAa,GACd,MAAM,qBAAqB,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { type IConstruct } from "constructs";
2
+ /**
3
+ * Base type for the dependency context passed to a component's {@link Lifecycle.build} method.
4
+ * A record of named dependencies, each being a record of their build outputs.
5
+ */
6
+ type LifecycleComponentBase = Record<string, object>;
7
+ /**
8
+ * The core interface for all ComposureCDK components. A `Lifecycle` represents
9
+ * a unit of infrastructure that can be built within a CDK construct tree.
10
+ *
11
+ * Components implement this interface to define what resources they create
12
+ * and what dependencies they require. The {@link compose} function assembles
13
+ * components into a system, resolving dependencies and invoking `build` in
14
+ * the correct order.
15
+ *
16
+ * @typeParam T - The record of resources and values this component produces when built.
17
+ * @typeParam Context - The resolved dependencies this component requires, keyed by component name.
18
+ */
19
+ export interface Lifecycle<T extends object = object, Context extends LifecycleComponentBase = LifecycleComponentBase> {
20
+ build(scope: IConstruct, id: string, context?: Context): T;
21
+ }
22
+ export {};
23
+ //# sourceMappingURL=lifecycle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../src/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C;;;GAGG;AACH,KAAK,sBAAsB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAErD;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,SAAS,CACxB,CAAC,SAAS,MAAM,GAAG,MAAM,EACzB,OAAO,SAAS,sBAAsB,GAAG,sBAAsB;IAE/D,KAAK,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC;CAC5D"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../../src/lifecycle.ts"],"names":[],"mappings":""}