Skip to content

Commit af6a2fc

Browse files
committed
patch(feat): octo-aws-cdk anchors must synth properties.
1 parent c3213f2 commit af6a2fc

File tree

2 files changed

+76
-3
lines changed

2 files changed

+76
-3
lines changed
Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,47 @@
1-
import { AAnchor, Anchor } from '@quadnix/octo';
1+
import { AAnchor, Anchor, IAnchor, UnknownModel } from '@quadnix/octo';
22
import { AwsRegion } from '../models/region/aws.region.model.js';
33

4+
interface IRegionFilesystemAnchor extends IAnchor {
5+
filesystemName: string;
6+
}
7+
48
@Anchor()
59
export class RegionFilesystemAnchor extends AAnchor {
6-
constructor(anchorId: string, parent: AwsRegion) {
10+
readonly filesystemName: string;
11+
12+
constructor(anchorId: string, filesystemName: string, parent: AwsRegion) {
713
super(anchorId, parent);
14+
this.filesystemName = filesystemName;
15+
}
16+
17+
override synth(): IRegionFilesystemAnchor {
18+
return {
19+
anchorId: this.anchorId,
20+
filesystemName: this.filesystemName,
21+
parent: { context: this.getParent().getContext() },
22+
};
23+
}
24+
25+
override toJSON(): object {
26+
return {
27+
anchorId: this.anchorId,
28+
filesystemName: this.filesystemName,
29+
parent: this.getParent().getContext(),
30+
};
31+
}
32+
33+
static override async unSynth(
34+
deserializationClass: any,
35+
anchor: IRegionFilesystemAnchor,
36+
deReferenceContext: (context: string) => Promise<UnknownModel>,
37+
): Promise<RegionFilesystemAnchor> {
38+
const parent = await deReferenceContext(anchor.parent.context);
39+
const newAnchor = parent.getAnchor(anchor.anchorId) as RegionFilesystemAnchor;
40+
if (!newAnchor) {
41+
const deserializedAnchor = new deserializationClass(anchor.anchorId, parent);
42+
deserializedAnchor.filesystemName = anchor.filesystemName;
43+
return deserializedAnchor;
44+
}
45+
return newAnchor;
846
}
947
}

packages/octo-aws-cdk/src/anchors/security-group.anchor.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import { AAnchor, Anchor } from '@quadnix/octo';
1+
import { AAnchor, Anchor, IAnchor, UnknownModel } from '@quadnix/octo';
22
import { AwsExecution } from '../models/execution/aws.execution.model.js';
33
import { AwsServer } from '../models/server/aws.server.model.js';
44

5+
interface ISecurityGroupAnchor extends IAnchor {
6+
rules: ISecurityGroupAnchorRule[];
7+
}
8+
59
interface ISecurityGroupAnchorRule {
610
CidrBlock: string;
711
Egress: boolean;
@@ -18,4 +22,35 @@ export class SecurityGroupAnchor extends AAnchor {
1822
super(anchorId, parent);
1923
this.rules = rules;
2024
}
25+
26+
override synth(): ISecurityGroupAnchor {
27+
return {
28+
anchorId: this.anchorId,
29+
parent: { context: this.getParent().getContext() },
30+
rules: [...this.rules],
31+
};
32+
}
33+
34+
override toJSON(): object {
35+
return {
36+
anchorId: this.anchorId,
37+
parent: this.getParent().getContext(),
38+
rules: [...this.rules],
39+
};
40+
}
41+
42+
static override async unSynth(
43+
deserializationClass: any,
44+
anchor: ISecurityGroupAnchor,
45+
deReferenceContext: (context: string) => Promise<UnknownModel>,
46+
): Promise<SecurityGroupAnchor> {
47+
const parent = await deReferenceContext(anchor.parent.context);
48+
const newAnchor = parent.getAnchor(anchor.anchorId) as SecurityGroupAnchor;
49+
if (!newAnchor) {
50+
const deserializedAnchor = new deserializationClass(anchor.anchorId, parent);
51+
deserializedAnchor.rules = anchor.rules;
52+
return deserializedAnchor;
53+
}
54+
return newAnchor;
55+
}
2156
}

0 commit comments

Comments
 (0)