@composurecdk/core 0.1.3 → 0.3.2
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.
- package/README.md +98 -0
- package/package.json +4 -4
package/README.md
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# @composurecdk/core
|
|
2
|
+
|
|
3
|
+
Core primitives for [ComposureCDK](../../README.md).
|
|
4
|
+
|
|
5
|
+
This package provides the foundational types and utilities that all ComposureCDK resource packages build on: the fluent `Builder` proxy, the `compose` function for assembling component systems with dependency resolution, lazy `Ref` cross-references, and stack strategies for routing components to scopes.
|
|
6
|
+
|
|
7
|
+
Most users interact with these primitives indirectly through resource packages (e.g., `@composurecdk/lambda`, `@composurecdk/s3`). Use this package directly when building a custom ComposureCDK resource package or when composing systems.
|
|
8
|
+
|
|
9
|
+
## Builder
|
|
10
|
+
|
|
11
|
+
Generic fluent-builder factory that wraps a class, exposing every property in `Props` as an overloaded getter/setter method. Resource packages use this internally to create their builders.
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { Builder, type IBuilder } from "@composurecdk/core";
|
|
15
|
+
|
|
16
|
+
type IMyBuilder = IBuilder<MyProps, MyLifecycle>;
|
|
17
|
+
|
|
18
|
+
export function createMyBuilder(): IMyBuilder {
|
|
19
|
+
return Builder<MyProps, MyLifecycle>(MyLifecycle);
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## compose
|
|
24
|
+
|
|
25
|
+
Composes a set of `Lifecycle` components into a single system with automatic dependency resolution. Dependencies are declared as data; the system builds components in topological order and passes resolved outputs as context.
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { compose } from "@composurecdk/core";
|
|
29
|
+
|
|
30
|
+
const system = compose(
|
|
31
|
+
{ handler: createFunctionBuilder(), api: createRestApiBuilder() },
|
|
32
|
+
{ handler: [], api: ["handler"] },
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
system.build(stack, "MySystem");
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Cyclic dependencies are detected at composition time and throw a `CyclicDependencyError`.
|
|
39
|
+
|
|
40
|
+
### Stack routing
|
|
41
|
+
|
|
42
|
+
Route components to different scopes (typically Stacks) using `withStacks` or `withStackStrategy`:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
// Explicit scope mapping
|
|
46
|
+
system.withStacks({ handler: serviceStack, api: apiStack }).build(app, "MySystem");
|
|
47
|
+
|
|
48
|
+
// Strategy-based routing
|
|
49
|
+
import { singleStack, groupedStacks } from "@composurecdk/core";
|
|
50
|
+
|
|
51
|
+
system.withStackStrategy(singleStack(myFactory)).build(app, "MySystem");
|
|
52
|
+
|
|
53
|
+
system
|
|
54
|
+
.withStackStrategy(groupedStacks((key) => (key === "handler" ? "compute" : "api"), myFactory))
|
|
55
|
+
.build(app, "MySystem");
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Post-build hooks
|
|
59
|
+
|
|
60
|
+
Register callbacks that run after all components are built via `afterBuild`. Domain-specific packages provide helper functions that return hooks — for example, `outputs()` from `@composurecdk/cloudformation`.
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
system
|
|
64
|
+
.afterBuild((scope, id, results) => {
|
|
65
|
+
console.log("Built:", Object.keys(results));
|
|
66
|
+
})
|
|
67
|
+
.build(stack, "MySystem");
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Ref
|
|
71
|
+
|
|
72
|
+
Lazy cross-component references that are resolved at build time. Use `ref` to reference a dependency's output at configuration time — the value is resolved when the system is built.
|
|
73
|
+
|
|
74
|
+
```ts
|
|
75
|
+
import { ref } from "@composurecdk/core";
|
|
76
|
+
import type { FunctionBuilderResult } from "@composurecdk/lambda";
|
|
77
|
+
|
|
78
|
+
// Reference the full build result
|
|
79
|
+
ref<FunctionBuilderResult>("handler");
|
|
80
|
+
|
|
81
|
+
// Narrow to a specific property
|
|
82
|
+
ref<FunctionBuilderResult>("handler").get("function");
|
|
83
|
+
|
|
84
|
+
// Transform the referenced value
|
|
85
|
+
ref<FunctionBuilderResult>("handler")
|
|
86
|
+
.get("function")
|
|
87
|
+
.map((fn) => new LambdaIntegration(fn));
|
|
88
|
+
|
|
89
|
+
// Shorthand with inline transform
|
|
90
|
+
ref<FunctionBuilderResult>("handler", (r) => new LambdaIntegration(r.function));
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Examples
|
|
94
|
+
|
|
95
|
+
- [MultiStackApp](../examples/src/multi-stack-app.ts) — System composed with `withStacks` for multi-stack routing
|
|
96
|
+
- [StrategyStackApp](../examples/src/strategy-stack-app.ts) — System composed with `withStackStrategy`
|
|
97
|
+
- [LambdaApiStack](../examples/src/lambda-api-app.ts) — Cross-component wiring with `ref`
|
|
98
|
+
- [StaticWebsiteStack](../examples/src/static-website/app.ts) — S3 + CloudFront composed system with `ref` and `afterBuild`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@composurecdk/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Composable CDK component system — lifecycle, dependency resolution, and builder pattern",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"constructs": "^10.6.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@types/node": "^25.
|
|
48
|
-
"typescript": "^6.0.
|
|
49
|
-
"vitest": "^4.1.
|
|
47
|
+
"@types/node": "^25.6.0",
|
|
48
|
+
"typescript": "^6.0.3",
|
|
49
|
+
"vitest": "^4.1.4"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@dagrejs/graphlib": "^4.0.1"
|