Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 50cc543

Browse files
authored
feat: interoperable Cloud Assembly contract (#133)
### Issue Relates to aws/aws-cdk#32998 ### Reason for this change We are publishing the `cx-api` package twice: Once as a standalone package `@aws-cdk/cx-api` and once as part of the construct library under `aws-cdk-lib/cx-api`. The code is copied during the release and the same versions of the packages will have the same code. However this makes it difficult for other packages to take a type dependency on types from this package. The most common class that's used from `cx-api` is `CloudAssembly` - the result of `app.synth()`. Previously a package had to take a dependency on the very large `aws-cdk-lib` just to use a single type. It would be better if other packages could instead depend on the smaller, much more focused `@aws-cdk/cx-api` package. ### Description of changes In aws/aws-cdk#32998 we are adding a mechanism to detect cross-library compatibility of the `CloudAssembly` class. **However, that alone doesn't help us with type checking.** Instead we introduce a new type `ICloudAssembly` into the Cloud Assembly Schema. This interface only declares a single property: `directory`. Consumers can use this type to indicate where they would like to receive a `CloudAssembly`. They can then use runtime code to either confirm a provided object already satisfies the requirements or fallback to creating a new `CloudAssembly` from the directory.
1 parent bc4db6a commit 50cc543

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/cloud-assembly/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export * from './schema';
22
export * from './metadata-schema';
33
export * from './artifact-schema';
44
export * from './context-queries';
5+
export * from './interfaces';

lib/cloud-assembly/interfaces.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// The interfaces in this file, mainly exist __here__ because this is a convenient place to put them.
2+
// The Assembly Schema package is already a jsii package and a dependency of `aws-cdk-lib`.
3+
// It is effectively the only place we can put shared interfaces to be used across the jsii ecosystem.
4+
//
5+
// Putting a shared interface in here should be a huge exception.
6+
// It needs to be justified by great benefits it provides to the ecosystems.
7+
// All interfaces should be as minimal as possible.
8+
9+
/**
10+
* Interoperable representation of a deployable cloud application.
11+
*
12+
* The external and interoperable contract for a Cloud Assembly is
13+
* a directory containing a valid Cloud Assembly.
14+
*
15+
* Implementations should use the directory to load the Cloud Assembly from disk.
16+
* It is recommended that implementations validate loaded manifest files using
17+
* the provided functionality from this package.
18+
* Within an implementation, it may be prudent to keep (parts of) the Cloud Assembly
19+
* in memory during execution and use an implementation-specific contract.
20+
* However when an implementation is providing an external contract,
21+
* this interface should be used.
22+
*/
23+
export interface ICloudAssembly {
24+
/**
25+
* The directory of the cloud assembly.
26+
*
27+
* This directory will be used to read the Cloud Assembly from.
28+
* Its contents (in particular `manifest.json`) must comply with the schema defined in this package.
29+
*/
30+
readonly directory: string;
31+
}

0 commit comments

Comments
 (0)