nomoss 0.0.1

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 (81) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +45 -0
  3. package/bin/nomoss +13 -0
  4. package/docs/code-documentation.md +36 -0
  5. package/docs/effect-native-development.md +55 -0
  6. package/docs/engine-design.md +93 -0
  7. package/docs/linting.md +88 -0
  8. package/docs/releasing.md +13 -0
  9. package/docs/resource-command-policy-stage.md +71 -0
  10. package/docs/resource-graph-mvp.md +31 -0
  11. package/docs/resource-graph-testing-approach.md +11 -0
  12. package/docs/resource-lifecycle-tracker.md +93 -0
  13. package/docs/testing.md +86 -0
  14. package/examples/upload-events/README.md +41 -0
  15. package/media/nomoss.gif +0 -0
  16. package/package.json +64 -0
  17. package/src/cli.ts +18 -0
  18. package/src/cliCommand.ts +186 -0
  19. package/src/cliRuntimeLayer.ts +49 -0
  20. package/src/core/index.ts +17 -0
  21. package/src/core/lifecycle.ts +127 -0
  22. package/src/core/model.ts +229 -0
  23. package/src/core/physicalNameStore.ts +226 -0
  24. package/src/core/planner.ts +645 -0
  25. package/src/core/resourceCommandPolicy.ts +79 -0
  26. package/src/core/resourceGraphBuilder.ts +167 -0
  27. package/src/core/resourceGraphStore.ts +288 -0
  28. package/src/core/resourceOutputResolver.ts +185 -0
  29. package/src/core/resourcePolicy.ts +77 -0
  30. package/src/core/resourceStackDefinition.ts +17 -0
  31. package/src/core/resourceStackLifecycle.ts +456 -0
  32. package/src/core/resourceStackOperations.ts +129 -0
  33. package/src/core/runtimeLayer.ts +73 -0
  34. package/src/core/stackWorkflowRenderer.ts +239 -0
  35. package/src/core/stateSecretService.ts +553 -0
  36. package/src/core/stateStore.ts +652 -0
  37. package/src/core/tracing.ts +26 -0
  38. package/src/index.ts +2 -0
  39. package/src/providers/aws/awsApply.ts +132 -0
  40. package/src/providers/aws/awsBucket.ts +329 -0
  41. package/src/providers/aws/awsBucketNotification.ts +351 -0
  42. package/src/providers/aws/awsBucketNotificationResourcePolicy.ts +251 -0
  43. package/src/providers/aws/awsBucketResourcePolicy.ts +198 -0
  44. package/src/providers/aws/awsProviderLayer.ts +274 -0
  45. package/src/providers/aws/awsQueue.ts +346 -0
  46. package/src/providers/aws/awsQueuePolicy.ts +419 -0
  47. package/src/providers/aws/awsQueuePolicyResourcePolicy.ts +215 -0
  48. package/src/providers/aws/awsQueueResourcePolicy.ts +270 -0
  49. package/src/providers/aws/awsReconciliation.ts +92 -0
  50. package/src/providers/aws/awsRefresh.ts +50 -0
  51. package/src/providers/aws/awsResourceLifecycle.ts +118 -0
  52. package/src/providers/aws/awsResourcePolicy.ts +83 -0
  53. package/src/providers/aws/awsResources.ts +274 -0
  54. package/src/providers/aws/awsRuntimeLayer.ts +21 -0
  55. package/src/providers/aws/awsSqsTransport.ts +33 -0
  56. package/src/providers/aws/awsStackLifecycle.ts +272 -0
  57. package/src/providers/aws/awsTagging.ts +186 -0
  58. package/src/providers/aws/constants.ts +3 -0
  59. package/src/providers/aws/index.ts +22 -0
  60. package/src/providers/aws/sampleStack.ts +65 -0
  61. package/src/providers/aws/stackWorkflow.ts +443 -0
  62. package/src/providers/index.ts +5 -0
  63. package/src/providers/provider.ts +5 -0
  64. package/src/providers/providerRuntimeLayer.ts +121 -0
  65. package/src/providers/resourceCommandPolicyLayer.ts +240 -0
  66. package/src/providers/stripe/index.ts +15 -0
  67. package/src/providers/stripe/stripeAccount.ts +139 -0
  68. package/src/providers/stripe/stripeBillingConfigurationExport.ts +180 -0
  69. package/src/providers/stripe/stripeBillingConfigurationExportResourcePolicy.ts +178 -0
  70. package/src/providers/stripe/stripeBillingPortalConfiguration.ts +153 -0
  71. package/src/providers/stripe/stripeBillingPortalConfigurationResourcePolicy.ts +177 -0
  72. package/src/providers/stripe/stripeCustomer.ts +148 -0
  73. package/src/providers/stripe/stripeCustomerResourcePolicy.ts +160 -0
  74. package/src/providers/stripe/stripePrice.ts +218 -0
  75. package/src/providers/stripe/stripePriceResourcePolicy.ts +151 -0
  76. package/src/providers/stripe/stripeProduct.ts +171 -0
  77. package/src/providers/stripe/stripeProductResourcePolicy.ts +161 -0
  78. package/src/providers/stripe/stripeResources.ts +454 -0
  79. package/src/providers/stripe/stripeRuntimeLayer.ts +131 -0
  80. package/src/providers/stripe/stripeWebhookEndpoint.ts +293 -0
  81. package/src/providers/stripe/stripeWebhookEndpointResourcePolicy.ts +198 -0
@@ -0,0 +1,274 @@
1
+ import { Context, Effect, Match, Option, Struct } from "effect";
2
+
3
+ import {
4
+ type ResourceKey,
5
+ type ResourceOutputRef,
6
+ resourceOutputRef,
7
+ } from "../../core/model.js";
8
+ import { PhysicalNameStore } from "../../core/physicalNameStore.js";
9
+ import { ResourceGraphBuilder } from "../../core/resourceGraphBuilder.js";
10
+ import {
11
+ BucketOutputsSchema,
12
+ type BucketProps,
13
+ BucketPropsSchema,
14
+ bucketOutputsFromProps,
15
+ } from "./awsBucket.js";
16
+ import {
17
+ BucketNotificationOutputsSchema,
18
+ BucketNotificationPropsSchema,
19
+ } from "./awsBucketNotification.js";
20
+ import {
21
+ QueueOutputsSchema,
22
+ type QueueProps,
23
+ QueuePropsSchema,
24
+ queueOutputsFromProps,
25
+ } from "./awsQueue.js";
26
+ import {
27
+ QueuePolicyOutputsSchema,
28
+ QueuePolicyPropsSchema,
29
+ s3SendMessageQueuePolicy,
30
+ } from "./awsQueuePolicy.js";
31
+
32
+ type GraphBucketProps = Omit<BucketProps, "Bucket"> & {
33
+ readonly Bucket?: string;
34
+ };
35
+
36
+ type GraphQueueProps = Omit<QueueProps, "QueueName"> & {
37
+ readonly QueueName?: string;
38
+ };
39
+
40
+ type GraphBucketInput = {
41
+ readonly logicalId: string;
42
+ readonly props?: GraphBucketProps;
43
+ readonly forceDestroy?: boolean;
44
+ };
45
+
46
+ type GraphQueueInput = {
47
+ readonly logicalId: string;
48
+ readonly props?: GraphQueueProps;
49
+ };
50
+
51
+ type GraphQueuePolicyInput = {
52
+ readonly logicalId: string;
53
+ readonly bucketArn: ResourceOutputRef;
54
+ readonly queueUrl: ResourceOutputRef;
55
+ readonly queueArn: ResourceOutputRef;
56
+ };
57
+
58
+ type GraphBucketNotificationInput = {
59
+ readonly logicalId: string;
60
+ readonly bucketName: ResourceOutputRef;
61
+ readonly queueArn: ResourceOutputRef;
62
+ readonly queuePolicy: ResourceKey;
63
+ };
64
+
65
+ /**
66
+ * Stack graph programs use these declarations to validate AWS props, create
67
+ * output refs, and let `ResourceGraphBuilder` record dependency edges when
68
+ * declarations consume another resource output.
69
+ */
70
+ export class AwsResources extends Context.Service<AwsResources>()(
71
+ "nomoss/providers/aws/awsResources",
72
+ {
73
+ make: Effect.gen(function* () {
74
+ const graph = yield* ResourceGraphBuilder;
75
+ const physicalNames = yield* PhysicalNameStore;
76
+
77
+ return {
78
+ Bucket: Effect.fn("AwsResources.Bucket")(function* (
79
+ input: GraphBucketInput,
80
+ ) {
81
+ const key = { logicalId: input.logicalId };
82
+ const resource = yield* graph.resource(key);
83
+ const inputProps = input.props ?? {};
84
+ const bucketName = yield* Option.fromUndefinedOr(
85
+ inputProps.Bucket,
86
+ ).pipe(
87
+ Option.match({
88
+ onNone: () => physicalNames.bucketNameFor(input.logicalId),
89
+ onSome: Effect.succeed,
90
+ }),
91
+ );
92
+ const bucketPropsInput = Match.value(input.forceDestroy).pipe(
93
+ Match.when(undefined, () =>
94
+ Struct.assign(inputProps, {
95
+ Bucket: bucketName,
96
+ }),
97
+ ),
98
+ Match.orElse((forceDestroy) =>
99
+ Struct.assign(inputProps, {
100
+ Bucket: bucketName,
101
+ ForceDestroy: forceDestroy,
102
+ }),
103
+ ),
104
+ );
105
+ const props = yield* BucketPropsSchema.makeEffect(bucketPropsInput);
106
+ const outputs = bucketOutputsFromProps(props);
107
+
108
+ yield* resource.register({
109
+ propsSchema: BucketPropsSchema,
110
+ outputsSchema: BucketOutputsSchema,
111
+ props,
112
+ outputs,
113
+ });
114
+
115
+ return {
116
+ key,
117
+ props,
118
+ Bucket: resourceOutputRef(key, "Bucket"),
119
+ BucketArn: resourceOutputRef(key, "BucketArn"),
120
+ };
121
+ }),
122
+
123
+ Queue: Effect.fn("AwsResources.Queue")(function* (
124
+ input: GraphQueueInput,
125
+ ) {
126
+ const key = { logicalId: input.logicalId };
127
+ const resource = yield* graph.resource(key);
128
+ const inputProps = input.props ?? {};
129
+ const queueName = yield* Option.fromUndefinedOr(
130
+ inputProps.QueueName,
131
+ ).pipe(
132
+ Option.match({
133
+ onNone: () => physicalNames.queueNameFor(input.logicalId),
134
+ onSome: Effect.succeed,
135
+ }),
136
+ );
137
+ const props = yield* QueuePropsSchema.makeEffect(
138
+ Struct.assign(inputProps, {
139
+ QueueName: queueName,
140
+ }),
141
+ );
142
+ const outputs = queueOutputsFromProps(props);
143
+
144
+ yield* resource.register({
145
+ propsSchema: QueuePropsSchema,
146
+ outputsSchema: QueueOutputsSchema,
147
+ props,
148
+ outputs,
149
+ });
150
+
151
+ return {
152
+ key,
153
+ props,
154
+ QueueUrl: resourceOutputRef(key, "QueueUrl"),
155
+ QueueArn: resourceOutputRef(key, "QueueArn"),
156
+ };
157
+ }),
158
+
159
+ QueuePolicy: Effect.fn("AwsResources.QueuePolicy")(function* (
160
+ input: GraphQueuePolicyInput,
161
+ ) {
162
+ const key = { logicalId: input.logicalId };
163
+ const resource = yield* graph.resource(key);
164
+ const bucketArn = yield* resource.stringFrom(
165
+ input.bucketArn,
166
+ "bucketArn",
167
+ );
168
+ const queueUrl = yield* resource.stringFrom(
169
+ input.queueUrl,
170
+ "queueUrl",
171
+ );
172
+ const queueArn = yield* resource.stringFrom(
173
+ input.queueArn,
174
+ "queueArn",
175
+ );
176
+ const policy = yield* s3SendMessageQueuePolicy(bucketArn, queueArn);
177
+ const props = yield* QueuePolicyPropsSchema.makeEffect({
178
+ QueueUrl: queueUrl,
179
+ Attributes: {
180
+ Policy: policy,
181
+ },
182
+ });
183
+ const outputs = {};
184
+
185
+ yield* resource.register({
186
+ propsSchema: QueuePolicyPropsSchema,
187
+ outputsSchema: QueuePolicyOutputsSchema,
188
+ props,
189
+ outputs,
190
+ });
191
+
192
+ return {
193
+ key,
194
+ props,
195
+ };
196
+ }),
197
+
198
+ BucketNotification: Effect.fn("AwsResources.BucketNotification")(
199
+ function* (input: GraphBucketNotificationInput) {
200
+ const key = { logicalId: input.logicalId };
201
+ const resource = yield* graph.resource(key);
202
+ const bucketName = yield* resource.stringFrom(
203
+ input.bucketName,
204
+ "bucketName",
205
+ );
206
+ const queueArn = yield* resource.stringFrom(
207
+ input.queueArn,
208
+ "queueArn",
209
+ );
210
+ yield* resource.after(input.queuePolicy, "queuePolicy", "Policy");
211
+ const queueConfiguration = {
212
+ Id: input.logicalId,
213
+ QueueArn: queueArn,
214
+ Events: ["s3:ObjectCreated:*"],
215
+ };
216
+ const props = yield* BucketNotificationPropsSchema.makeEffect({
217
+ Bucket: bucketName,
218
+ NotificationConfiguration: {
219
+ QueueConfigurations: [queueConfiguration],
220
+ },
221
+ });
222
+ const outputs = {};
223
+
224
+ yield* resource.register({
225
+ propsSchema: BucketNotificationPropsSchema,
226
+ outputsSchema: BucketNotificationOutputsSchema,
227
+ props,
228
+ outputs,
229
+ });
230
+
231
+ return {
232
+ key,
233
+ props,
234
+ };
235
+ },
236
+ ),
237
+ };
238
+ }),
239
+ },
240
+ ) {}
241
+
242
+ /**
243
+ * Stack definitions use these CDK-style constructors while live provider
244
+ * behavior remains in AWS lifecycle policies.
245
+ */
246
+ export const Aws = {
247
+ Bucket: (input: GraphBucketInput) =>
248
+ Effect.gen(function* () {
249
+ const resources = yield* AwsResources;
250
+
251
+ return yield* resources.Bucket(input);
252
+ }),
253
+
254
+ Queue: (input: GraphQueueInput) =>
255
+ Effect.gen(function* () {
256
+ const resources = yield* AwsResources;
257
+
258
+ return yield* resources.Queue(input);
259
+ }),
260
+
261
+ QueuePolicy: (input: GraphQueuePolicyInput) =>
262
+ Effect.gen(function* () {
263
+ const resources = yield* AwsResources;
264
+
265
+ return yield* resources.QueuePolicy(input);
266
+ }),
267
+
268
+ BucketNotification: (input: GraphBucketNotificationInput) =>
269
+ Effect.gen(function* () {
270
+ const resources = yield* AwsResources;
271
+
272
+ return yield* resources.BucketNotification(input);
273
+ }),
274
+ };
@@ -0,0 +1,21 @@
1
+ import { Layer } from "effect";
2
+
3
+ import { resourceModelLayer } from "../../core/runtimeLayer.js";
4
+ import { AwsStackLifecycle } from "./awsStackLifecycle.js";
5
+ import { StackCatalog } from "./sampleStack.js";
6
+ import { StackWorkflowRenderer } from "./stackWorkflow.js";
7
+
8
+ export const stackCatalogLayerLive = Layer.effect(
9
+ StackCatalog,
10
+ StackCatalog.make,
11
+ );
12
+
13
+ export const awsStackLifecycleLayerLive = Layer.effect(
14
+ AwsStackLifecycle,
15
+ AwsStackLifecycle.make,
16
+ );
17
+
18
+ export const stackWorkflowRendererLayerLive = Layer.effect(
19
+ StackWorkflowRenderer,
20
+ StackWorkflowRenderer.make,
21
+ ).pipe(Layer.provideMerge(resourceModelLayer));
@@ -0,0 +1,33 @@
1
+ import type * as SQS from "@distilled.cloud/aws/sqs";
2
+ import * as sqs from "@distilled.cloud/aws/sqs";
3
+ import { Context, Effect } from "effect";
4
+
5
+ /**
6
+ * Queue lifecycle code reaches Distilled SQS through this adapter so tests can
7
+ * replace external responses without replacing lifecycle or policy services.
8
+ */
9
+ export class AwsSqsTransport extends Context.Service<AwsSqsTransport>()(
10
+ "nomoss/providers/aws/awsSqsTransport",
11
+ {
12
+ make: Effect.gen(function* () {
13
+ const distilledCreateQueue = yield* sqs.createQueue;
14
+ const distilledDeleteQueue = yield* sqs.deleteQueue;
15
+ const distilledGetQueueAttributes = yield* sqs.getQueueAttributes;
16
+ const distilledGetQueueUrl = yield* sqs.getQueueUrl;
17
+ const distilledListQueueTags = yield* sqs.listQueueTags;
18
+
19
+ return {
20
+ createQueue: (request: SQS.CreateQueueRequest) =>
21
+ distilledCreateQueue(request),
22
+ deleteQueue: (request: SQS.DeleteQueueRequest) =>
23
+ distilledDeleteQueue(request),
24
+ getQueueAttributes: (request: SQS.GetQueueAttributesRequest) =>
25
+ distilledGetQueueAttributes(request),
26
+ getQueueUrl: (request: SQS.GetQueueUrlRequest) =>
27
+ distilledGetQueueUrl(request),
28
+ listQueueTags: (request: SQS.ListQueueTagsRequest) =>
29
+ distilledListQueueTags(request),
30
+ };
31
+ }),
32
+ },
33
+ ) {}
@@ -0,0 +1,272 @@
1
+ import { Array as Arr, Context, Duration, Effect, Graph, Option } from "effect";
2
+
3
+ import type { PlanDecision } from "../../core/lifecycle.js";
4
+ import type { ResourceNode } from "../../core/model.js";
5
+ import { PhysicalNameStore } from "../../core/physicalNameStore.js";
6
+ import type { ResourceDependencyGraph } from "../../core/planner.js";
7
+ import { ResourceGraphStore } from "../../core/resourceGraphStore.js";
8
+ import { ResourceStateStore } from "../../core/stateStore.js";
9
+ import { type AppliedResource, AwsApply } from "./awsApply.js";
10
+ import { AwsProviderRuntime } from "./awsProviderLayer.js";
11
+ import { AwsReconciliation } from "./awsReconciliation.js";
12
+ import { AwsRefresh } from "./awsRefresh.js";
13
+ import { AwsResources } from "./awsResources.js";
14
+ import { StackCatalog, type StackName } from "./sampleStack.js";
15
+
16
+ export type ResourceListing = {
17
+ readonly logicalId: string;
18
+ readonly type: string;
19
+ readonly provider: string;
20
+ readonly service: string;
21
+ readonly resource: string;
22
+ readonly props: unknown;
23
+ readonly outputs: unknown;
24
+ };
25
+
26
+ export type DecisionReport = {
27
+ readonly stackName: string;
28
+ readonly decisions: ReadonlyMap<string, PlanDecision>;
29
+ readonly changed: ReadonlyArray<PlanDecision>;
30
+ };
31
+
32
+ export type StackApplyResult = {
33
+ readonly report: DecisionReport;
34
+ readonly applied: boolean;
35
+ readonly resources: ReadonlyArray<AppliedResource>;
36
+ readonly durationMillis: number;
37
+ };
38
+
39
+ export type StackDestroyResult = {
40
+ readonly report: DecisionReport;
41
+ };
42
+
43
+ export type PreparedStack = {
44
+ readonly stackName: string;
45
+ readonly region: string;
46
+ readonly desired: ResourceDependencyGraph;
47
+ };
48
+
49
+ /**
50
+ * CLI workflows call this service for stack preparation and live AWS changes,
51
+ * then render the typed reports outside the lifecycle path.
52
+ */
53
+ export class AwsStackLifecycle extends Context.Service<AwsStackLifecycle>()(
54
+ "nomoss/providers/aws/awsStackLifecycle",
55
+ {
56
+ make: Effect.gen(function* () {
57
+ const catalog = yield* StackCatalog;
58
+ const graphStore = yield* ResourceGraphStore;
59
+ const stateStore = yield* ResourceStateStore;
60
+ const physicalNames = yield* PhysicalNameStore;
61
+ const resources = yield* AwsResources;
62
+ const providerRuntime = yield* AwsProviderRuntime;
63
+
64
+ const changedDecisions = (decisions: ReadonlyMap<string, PlanDecision>) =>
65
+ Arr.filter(
66
+ Arr.fromIterable(decisions.values()),
67
+ (decision) => decision._tag !== "NoOp",
68
+ );
69
+ const reportFor = (
70
+ stackName: string,
71
+ decisions: ReadonlyMap<string, PlanDecision>,
72
+ ): DecisionReport =>
73
+ ({
74
+ stackName,
75
+ decisions,
76
+ changed: changedDecisions(decisions),
77
+ }) satisfies DecisionReport;
78
+ const resourceListing = (node: ResourceNode): ResourceListing => ({
79
+ logicalId: node.key.logicalId,
80
+ type: `${node.schema.provider}:${node.schema.service}:${node.schema.resource}`,
81
+ provider: node.schema.provider,
82
+ service: node.schema.service,
83
+ resource: node.schema.resource,
84
+ props: node.props,
85
+ outputs: node.outputs,
86
+ });
87
+ const resourceListings = (graph: ResourceDependencyGraph) =>
88
+ Arr.map(
89
+ Arr.fromIterable(Graph.values(Graph.topo(graph))),
90
+ resourceListing,
91
+ );
92
+ const providerDecisionLayer = (profile: string, region: string) =>
93
+ providerRuntime.decisionLayerSsoRegion(profile, region);
94
+ const liveDecisions = Effect.fn("AwsStackLifecycle.liveDecisions")(
95
+ function* (desired: ResourceDependencyGraph) {
96
+ const refresh = yield* AwsRefresh;
97
+ const reconciliation = yield* AwsReconciliation;
98
+ const observations = yield* refresh.refreshGraph(desired);
99
+ const decisions = yield* reconciliation.decideFromObservations(
100
+ desired,
101
+ observations,
102
+ );
103
+
104
+ return decisions;
105
+ },
106
+ );
107
+ const applyDecisions = Effect.fn("AwsStackLifecycle.applyDecisions")(
108
+ function* (input: {
109
+ readonly desired: ResourceDependencyGraph;
110
+ readonly decisions: ReadonlyMap<string, PlanDecision>;
111
+ readonly stackName: string;
112
+ readonly desiredResources: ReadonlyArray<ResourceNode>;
113
+ }) {
114
+ const applyService = yield* AwsApply;
115
+
116
+ const results = yield* applyService.applyDecisions(
117
+ input.desired,
118
+ input.decisions,
119
+ );
120
+ yield* stateStore.saveResources(
121
+ input.stackName,
122
+ input.desiredResources,
123
+ );
124
+
125
+ return results;
126
+ },
127
+ );
128
+ const prepareStack = Effect.fn("AwsStackLifecycle.prepare")(function* (
129
+ stackName: StackName,
130
+ ) {
131
+ const stack = yield* catalog.get(stackName);
132
+
133
+ yield* graphStore.reset;
134
+ yield* stack.graph.pipe(Effect.provideService(AwsResources, resources));
135
+ const desired = yield* graphStore.snapshot;
136
+ const prepared: PreparedStack = {
137
+ stackName: stack.name,
138
+ region: stack.region,
139
+ desired,
140
+ };
141
+
142
+ return prepared;
143
+ });
144
+
145
+ return {
146
+ prepare: prepareStack,
147
+
148
+ mermaid: Effect.fn("AwsStackLifecycle.mermaid")(function* (
149
+ stackName: StackName,
150
+ ) {
151
+ yield* prepareStack(stackName);
152
+
153
+ return yield* graphStore.mermaid;
154
+ }),
155
+
156
+ describeResources: Effect.fn("AwsStackLifecycle.describeResources")(
157
+ function* (stackName: StackName) {
158
+ const prepared = yield* prepareStack(stackName);
159
+
160
+ return resourceListings(prepared.desired);
161
+ },
162
+ ),
163
+
164
+ diffLive: Effect.fn("AwsStackLifecycle.diffLive")(function* (input: {
165
+ readonly profile: string;
166
+ readonly stackName: StackName;
167
+ }) {
168
+ const prepared = yield* prepareStack(input.stackName);
169
+ const decisions = yield* liveDecisions(prepared.desired).pipe(
170
+ Effect.provide(
171
+ providerDecisionLayer(input.profile, prepared.region),
172
+ ),
173
+ );
174
+
175
+ return reportFor(prepared.stackName, decisions);
176
+ }),
177
+
178
+ applyLive: Effect.fn("AwsStackLifecycle.applyLive")(function* (input: {
179
+ readonly profile: string;
180
+ readonly stackName: StackName;
181
+ }) {
182
+ const prepared = yield* prepareStack(input.stackName);
183
+ const desiredResources = stateStore.resourcesFromGraph(
184
+ prepared.desired,
185
+ );
186
+ const decisionLayer = providerDecisionLayer(
187
+ input.profile,
188
+ prepared.region,
189
+ );
190
+ const decisions = yield* liveDecisions(prepared.desired).pipe(
191
+ Effect.provide(decisionLayer),
192
+ );
193
+ const report = reportFor(prepared.stackName, decisions);
194
+ return yield* Option.match(
195
+ Option.liftPredicate(report, (value) => value.changed.length > 0),
196
+ {
197
+ onNone: () =>
198
+ Effect.succeed({
199
+ report,
200
+ applied: false,
201
+ resources: [],
202
+ durationMillis: 0,
203
+ }),
204
+ onSome: () =>
205
+ applyDecisions({
206
+ desired: prepared.desired,
207
+ decisions,
208
+ stackName: prepared.stackName,
209
+ desiredResources,
210
+ }).pipe(
211
+ Effect.provide(decisionLayer),
212
+ Effect.timed,
213
+ Effect.map(
214
+ ([duration, resources]): StackApplyResult => ({
215
+ report,
216
+ applied: true,
217
+ resources,
218
+ durationMillis: Duration.toMillis(duration),
219
+ }),
220
+ ),
221
+ ),
222
+ },
223
+ );
224
+ }),
225
+
226
+ destroyLive: Effect.fn("AwsStackLifecycle.destroyLive")(
227
+ function* (input: {
228
+ readonly profile: string;
229
+ readonly stackName: StackName;
230
+ }) {
231
+ const prepared = yield* prepareStack(input.stackName);
232
+ const graphNodes = Arr.fromIterable(
233
+ Graph.values(Graph.topo(prepared.desired)),
234
+ );
235
+ const decisions = new Map(
236
+ Arr.map(graphNodes, (node) => [
237
+ node.key.logicalId,
238
+ { _tag: "Destroy", node } as PlanDecision,
239
+ ]),
240
+ );
241
+ const report = reportFor(prepared.stackName, decisions);
242
+ const logicalIds = Arr.map(
243
+ graphNodes,
244
+ (node) => node.key.logicalId,
245
+ );
246
+
247
+ yield* applyDecisions({
248
+ desired: prepared.desired,
249
+ decisions,
250
+ stackName: prepared.stackName,
251
+ desiredResources: [],
252
+ }).pipe(
253
+ Effect.provide(
254
+ providerRuntime.applyLayerSsoRegion(
255
+ input.profile,
256
+ prepared.region,
257
+ ),
258
+ ),
259
+ Effect.andThen(physicalNames.deleteNames(logicalIds)),
260
+ );
261
+
262
+ const result: StackDestroyResult = {
263
+ report,
264
+ };
265
+
266
+ return result;
267
+ },
268
+ ),
269
+ };
270
+ }),
271
+ },
272
+ ) {}