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,456 @@
1
+ import {
2
+ Array as Arr,
3
+ Context,
4
+ Data,
5
+ Effect,
6
+ Exit,
7
+ Graph,
8
+ Match,
9
+ Option,
10
+ } from "effect";
11
+
12
+ import {
13
+ PlanDecision,
14
+ ResourceCommand,
15
+ type ResourceCommandResult,
16
+ } from "./lifecycle.js";
17
+ import {
18
+ keyString,
19
+ PlanAction,
20
+ type PlanAction as PlanActionValue,
21
+ type ResourceNode,
22
+ type ResourcePlan,
23
+ } from "./model.js";
24
+ import type { ResourceDependencyGraph } from "./planner.js";
25
+ import { ResourcePlanner } from "./planner.js";
26
+ import { ResourceCommandPolicy } from "./resourceCommandPolicy.js";
27
+ import { ResourceGraphStore } from "./resourceGraphStore.js";
28
+ import { ResourceOutputResolver } from "./resourceOutputResolver.js";
29
+ import { ResourceStateStore } from "./stateStore.js";
30
+
31
+ export type ResourcePreparedStack = {
32
+ readonly stackName: string;
33
+ readonly desired: ResourceDependencyGraph;
34
+ };
35
+
36
+ export type ResourceApplyResult = {
37
+ readonly stackName: string;
38
+ readonly plan: ResourcePlan;
39
+ readonly applied: boolean;
40
+ readonly resources: ReadonlyArray<ResourceNode>;
41
+ };
42
+
43
+ export type ResourceDestroyResult = {
44
+ readonly stackName: string;
45
+ readonly plan: ResourcePlan;
46
+ readonly destroyed: boolean;
47
+ readonly resources: ReadonlyArray<ResourceNode>;
48
+ };
49
+
50
+ export class ResourceActionResultExpected extends Data.TaggedError(
51
+ "ResourceActionResultExpected",
52
+ )<{
53
+ readonly action: PlanActionValue;
54
+ readonly result: ResourceCommandResult;
55
+ }> {}
56
+
57
+ export class ResourceCurrentNodeMissing extends Data.TaggedError(
58
+ "ResourceCurrentNodeMissing",
59
+ )<{
60
+ readonly action: PlanActionValue;
61
+ }> {}
62
+
63
+ /**
64
+ * Applications use this service to prepare, plan, apply, and destroy any
65
+ * resource graph whose providers satisfy `ResourceCommandPolicy`.
66
+ */
67
+ export class ResourceStackLifecycle extends Context.Service<ResourceStackLifecycle>()(
68
+ "nomoss/core/resourceStackLifecycle",
69
+ {
70
+ make: Effect.gen(function* () {
71
+ const graphStore = yield* ResourceGraphStore;
72
+ const stateStore = yield* ResourceStateStore;
73
+ const planner = yield* ResourcePlanner;
74
+ const policy = yield* ResourceCommandPolicy;
75
+ const outputResolver = yield* ResourceOutputResolver;
76
+
77
+ const nodeByKey = (nodes: ReadonlyArray<ResourceNode>) =>
78
+ new Map(Arr.map(nodes, (node) => [keyString(node.key), node]));
79
+
80
+ /**
81
+ * The planner resolves dependency outputs from current state when desired
82
+ * nodes still contain resource refs. If an output is missing, the node
83
+ * remains unresolved so create planning can still introduce the first
84
+ * producer in the graph.
85
+ */
86
+ const resolveGraphNode = Effect.fn(
87
+ "ResourceStackLifecycle.resolveGraphNode",
88
+ )(function* (
89
+ index: number,
90
+ node: ResourceNode,
91
+ resources: ReadonlyArray<ResourceNode>,
92
+ ) {
93
+ const dependencies = yield* graphStore.dependencyEdgesOf(node.key);
94
+
95
+ const resolvedNode = yield* Arr.match(dependencies, {
96
+ onEmpty: () => Effect.succeed(node),
97
+ onNonEmpty: (dependencies) =>
98
+ outputResolver
99
+ .resolveNode(node, resources, dependencies)
100
+ .pipe(
101
+ Effect.catchTag("ResourceOutputResolutionMissing", () =>
102
+ Effect.succeed(node),
103
+ ),
104
+ ),
105
+ });
106
+
107
+ return [index, resolvedNode] as const;
108
+ });
109
+
110
+ const graphWithResolvedNodes = Effect.fn(
111
+ "ResourceStackLifecycle.graphWithResolvedNodes",
112
+ )(function* (
113
+ graph: ResourceDependencyGraph,
114
+ resources: ReadonlyArray<ResourceNode>,
115
+ ) {
116
+ const resolvedNodes = yield* Effect.forEach(
117
+ Arr.fromIterable(Graph.nodes(graph)),
118
+ ([index, node]) => resolveGraphNode(index, node, resources),
119
+ );
120
+ const resolvedGraph = Graph.mutate(graph, (mutable) => {
121
+ Arr.reduce(resolvedNodes, mutable, (next, [index, node]) => {
122
+ Graph.updateNode(next, index, () => node);
123
+
124
+ return next;
125
+ });
126
+ });
127
+
128
+ return resolvedGraph;
129
+ });
130
+
131
+ const decisionFromAction = (action: PlanAction) =>
132
+ Match.value(action).pipe(
133
+ Match.tagsExhaustive({
134
+ Create: ({ node }) => PlanDecision.Create({ node }),
135
+ Update: ({ node, current }) =>
136
+ PlanDecision.Update({ node, current }),
137
+ Delete: ({ node }) => PlanDecision.Delete({ node }),
138
+ Destroy: ({ node }) => PlanDecision.Destroy({ node }),
139
+ }),
140
+ );
141
+
142
+ const resolveCreateAction = Effect.fn(
143
+ "ResourceStackLifecycle.resolveCreateAction",
144
+ )(function* (node: ResourceNode, resources: ReadonlyArray<ResourceNode>) {
145
+ const dependencies = yield* graphStore.dependencyEdgesOf(node.key);
146
+ const resolvedNode = yield* outputResolver.resolveNode(
147
+ node,
148
+ resources,
149
+ dependencies,
150
+ );
151
+
152
+ return PlanAction.Create({ node: resolvedNode });
153
+ });
154
+
155
+ const resolveUpdateAction = Effect.fn(
156
+ "ResourceStackLifecycle.resolveUpdateAction",
157
+ )(function* (
158
+ node: ResourceNode,
159
+ current: ResourceNode,
160
+ resources: ReadonlyArray<ResourceNode>,
161
+ ) {
162
+ const dependencies = yield* graphStore.dependencyEdgesOf(node.key);
163
+ const resolvedNode = yield* outputResolver.resolveNode(
164
+ node,
165
+ resources,
166
+ dependencies,
167
+ );
168
+
169
+ return PlanAction.Update({ node: resolvedNode, current });
170
+ });
171
+
172
+ const resolveAction = Effect.fn("ResourceStackLifecycle.resolveAction")(
173
+ function* (stackName: string, action: PlanActionValue) {
174
+ const resources = yield* stateStore.loadResources(stackName);
175
+
176
+ return yield* Match.value(action).pipe(
177
+ Match.when({ _tag: "Create" }, ({ node }) =>
178
+ resolveCreateAction(node, resources),
179
+ ),
180
+ Match.when({ _tag: "Update" }, ({ node, current }) =>
181
+ resolveUpdateAction(node, current, resources),
182
+ ),
183
+ Match.orElse(() => Effect.succeed(action)),
184
+ );
185
+ },
186
+ );
187
+
188
+ const appliedNodeFromActionResult = Effect.fn(
189
+ "ResourceStackLifecycle.appliedNodeFromActionResult",
190
+ )(function* (action: PlanActionValue, result: ResourceCommandResult) {
191
+ return yield* Match.value(result).pipe(
192
+ Match.when({ _tag: "Created" }, ({ node }) => Effect.succeed(node)),
193
+ Match.when({ _tag: "Updated" }, ({ node }) => Effect.succeed(node)),
194
+ Match.when({ _tag: "Deleted" }, ({ node }) => Effect.succeed(node)),
195
+ Match.when({ _tag: "Destroyed" }, ({ node }) => Effect.succeed(node)),
196
+ Match.orElse(() =>
197
+ Effect.fail(new ResourceActionResultExpected({ action, result })),
198
+ ),
199
+ );
200
+ });
201
+
202
+ const appliedStateTagFromActionResult = (
203
+ result: ResourceCommandResult,
204
+ ): "Created" | "Updated" =>
205
+ Match.value(result).pipe(
206
+ Match.when({ _tag: "Updated" }, (): "Updated" => "Updated"),
207
+ Match.orElse((): "Created" => "Created"),
208
+ );
209
+
210
+ /**
211
+ * Apply records started, applied, and failed phases around provider
212
+ * command execution. Interrupted or failed runs can then retry from
213
+ * persisted stack state instead of losing the resource transition.
214
+ */
215
+ const applyAction = Effect.fn("ResourceStackLifecycle.applyAction")(
216
+ function* (stackName: string, action: PlanActionValue) {
217
+ yield* stateStore.markResourceStarted(stackName, action);
218
+ const resolvedAction = yield* resolveAction(stackName, action).pipe(
219
+ Effect.tapErrorTag("ResourceOutputResolutionMissing", (failure) =>
220
+ stateStore.markResourceFailure(stackName, action.node, failure),
221
+ ),
222
+ Effect.tapErrorTag("ResourceOutputPropertyPathInvalid", (failure) =>
223
+ stateStore.markResourceFailure(stackName, action.node, failure),
224
+ ),
225
+ );
226
+ const result = yield* policy
227
+ .execute(
228
+ ResourceCommand.Apply({
229
+ decision: decisionFromAction(resolvedAction),
230
+ }),
231
+ )
232
+ .pipe(
233
+ Effect.tapErrorTag(
234
+ "ResourceCommandExecutionFailed",
235
+ ({ cause }) =>
236
+ stateStore.markResourceFailure(stackName, action.node, cause),
237
+ ),
238
+ );
239
+ const appliedNode = yield* appliedNodeFromActionResult(
240
+ resolvedAction,
241
+ result,
242
+ ).pipe(
243
+ Effect.tapErrorTag("ResourceActionResultExpected", (failure) =>
244
+ stateStore.markResourceFailure(stackName, action.node, failure),
245
+ ),
246
+ );
247
+
248
+ yield* stateStore.markResourceApplied(
249
+ stackName,
250
+ appliedNode,
251
+ appliedStateTagFromActionResult(result),
252
+ );
253
+
254
+ return appliedNode;
255
+ },
256
+ );
257
+
258
+ const rollbackCreatedResource = Effect.fn(
259
+ "ResourceStackLifecycle.rollbackCreatedResource",
260
+ )(function* (stackName: string, node: ResourceNode) {
261
+ const rollbackAction = PlanAction.Destroy({ node });
262
+
263
+ yield* stateStore.markResourceStarted(stackName, rollbackAction);
264
+ yield* policy.execute(
265
+ ResourceCommand.Apply({
266
+ decision: PlanDecision.Destroy({ node }),
267
+ }),
268
+ );
269
+ yield* stateStore.deleteResourceState(stackName, node);
270
+ });
271
+
272
+ const applyScopedAction = Effect.fn(
273
+ "ResourceStackLifecycle.applyScopedAction",
274
+ )(function* (stackName: string, action: PlanActionValue) {
275
+ return yield* Match.value(action).pipe(
276
+ Match.when({ _tag: "Create" }, () =>
277
+ Effect.acquireRelease(
278
+ applyAction(stackName, action),
279
+ (node, exit) =>
280
+ Exit.match(exit, {
281
+ onFailure: () =>
282
+ Effect.ignore(rollbackCreatedResource(stackName, node)),
283
+ onSuccess: () => Effect.void,
284
+ }),
285
+ ),
286
+ ),
287
+ Match.orElse(() => applyAction(stackName, action)),
288
+ );
289
+ });
290
+
291
+ const currentDestroyAction = Effect.fn(
292
+ "ResourceStackLifecycle.currentDestroyAction",
293
+ )(function* (
294
+ action: Extract<PlanActionValue, { readonly _tag: "Destroy" }>,
295
+ currentResources: ReadonlyMap<string, ResourceNode>,
296
+ ) {
297
+ const currentNode = yield* Effect.fromOption(
298
+ Option.fromUndefinedOr(
299
+ currentResources.get(keyString(action.node.key)),
300
+ ),
301
+ ).pipe(
302
+ Effect.mapError(() => new ResourceCurrentNodeMissing({ action })),
303
+ );
304
+
305
+ return PlanAction.Destroy({ node: currentNode });
306
+ });
307
+
308
+ const destroyAction = Effect.fn("ResourceStackLifecycle.destroyAction")(
309
+ function* (
310
+ stackName: string,
311
+ action: PlanActionValue,
312
+ currentResources: ReadonlyMap<string, ResourceNode>,
313
+ ) {
314
+ const currentAction = yield* Match.value(action).pipe(
315
+ Match.when({ _tag: "Destroy" }, (destroyAction) =>
316
+ currentDestroyAction(destroyAction, currentResources),
317
+ ),
318
+ Match.orElse(() => Effect.succeed(action)),
319
+ );
320
+
321
+ return yield* applyAction(stackName, currentAction);
322
+ },
323
+ );
324
+
325
+ return {
326
+ prepare: Effect.fn("ResourceStackLifecycle.prepare")(function* (
327
+ stackName: string,
328
+ ) {
329
+ const desired = yield* graphStore.snapshot;
330
+ const prepared: ResourcePreparedStack = {
331
+ stackName,
332
+ desired,
333
+ };
334
+
335
+ return prepared;
336
+ }),
337
+
338
+ plan: Effect.fn("ResourceStackLifecycle.plan")(function* (
339
+ prepared: ResourcePreparedStack,
340
+ ) {
341
+ const current = yield* stateStore.loadResources(prepared.stackName);
342
+ const desired = yield* graphWithResolvedNodes(
343
+ prepared.desired,
344
+ current,
345
+ );
346
+ const plan = planner.planFromGraph(desired, current);
347
+
348
+ return plan;
349
+ }),
350
+
351
+ apply: Effect.fn("ResourceStackLifecycle.apply")(function* (
352
+ prepared: ResourcePreparedStack,
353
+ ) {
354
+ const current = yield* stateStore.loadResources(prepared.stackName);
355
+ const desired = yield* graphWithResolvedNodes(
356
+ prepared.desired,
357
+ current,
358
+ );
359
+ const plan = planner.planFromGraph(desired, current);
360
+
361
+ yield* Effect.forEach(
362
+ plan.delete,
363
+ (batch) =>
364
+ Effect.forEach(
365
+ batch,
366
+ (action) => applyAction(prepared.stackName, action),
367
+ { discard: true },
368
+ ),
369
+ { discard: true },
370
+ );
371
+
372
+ const appliedNodeBatches = yield* Effect.forEach(
373
+ plan.createOrUpdate,
374
+ (batch) =>
375
+ Effect.forEach(batch, (action) =>
376
+ applyScopedAction(prepared.stackName, action),
377
+ ),
378
+ ).pipe(Effect.scoped);
379
+ const appliedNodes = Arr.flatten(appliedNodeBatches);
380
+ const currentResources = nodeByKey(current);
381
+ const appliedResources = nodeByKey(appliedNodes);
382
+ const desiredResources = stateStore.resourcesFromGraph(desired);
383
+ const resources = Arr.map(desiredResources, (node) =>
384
+ Option.fromUndefinedOr(
385
+ appliedResources.get(keyString(node.key)),
386
+ ).pipe(
387
+ Option.orElse(() =>
388
+ Option.fromUndefinedOr(
389
+ currentResources.get(keyString(node.key)),
390
+ ),
391
+ ),
392
+ Option.getOrElse(() => node),
393
+ ),
394
+ );
395
+
396
+ yield* stateStore.saveResources(prepared.stackName, resources);
397
+
398
+ const result: ResourceApplyResult = {
399
+ stackName: prepared.stackName,
400
+ plan,
401
+ applied:
402
+ Arr.flatten(plan.createOrUpdate).length +
403
+ Arr.flatten(plan.delete).length >
404
+ 0,
405
+ resources,
406
+ };
407
+
408
+ return result;
409
+ }),
410
+
411
+ destroy: Effect.fn("ResourceStackLifecycle.destroy")(function* (
412
+ prepared: ResourcePreparedStack,
413
+ ) {
414
+ const current = yield* stateStore.loadResources(prepared.stackName);
415
+ const currentResources = nodeByKey(current);
416
+ const desiredResources = stateStore.resourcesFromGraph(
417
+ prepared.desired,
418
+ );
419
+ const savedDesiredResources = Arr.filter(desiredResources, (node) =>
420
+ currentResources.has(keyString(node.key)),
421
+ );
422
+ const plan: ResourcePlan = {
423
+ createOrUpdate: [],
424
+ delete: [],
425
+ destroy: planner.destroyBatches(
426
+ prepared.desired,
427
+ Arr.map(savedDesiredResources, (node) => node.key),
428
+ ),
429
+ };
430
+
431
+ yield* Effect.forEach(
432
+ plan.destroy,
433
+ (batch) =>
434
+ Effect.forEach(
435
+ batch,
436
+ (action) =>
437
+ destroyAction(prepared.stackName, action, currentResources),
438
+ { discard: true },
439
+ ),
440
+ { discard: true },
441
+ );
442
+ yield* stateStore.saveResources(prepared.stackName, []);
443
+
444
+ const result: ResourceDestroyResult = {
445
+ stackName: prepared.stackName,
446
+ plan,
447
+ destroyed: Arr.flatten(plan.destroy).length > 0,
448
+ resources: current,
449
+ };
450
+
451
+ return result;
452
+ }),
453
+ };
454
+ }),
455
+ },
456
+ ) {}
@@ -0,0 +1,129 @@
1
+ import { Console, Context, Data, Effect, Option } from "effect";
2
+
3
+ import { ResourceStackDefinition } from "./resourceStackDefinition.js";
4
+ import { ResourceStackLifecycle } from "./resourceStackLifecycle.js";
5
+ import { StackWorkflowRenderer } from "./stackWorkflowRenderer.js";
6
+
7
+ export class ResourceStackOperationFailed extends Data.TaggedError(
8
+ "ResourceStackOperationFailed",
9
+ )<{
10
+ readonly stackName: string;
11
+ readonly operation: "plan" | "apply" | "destroy";
12
+ readonly cause: unknown;
13
+ }> {}
14
+
15
+ /**
16
+ * Resource stack operations run an application-provided stack declaration
17
+ * through Nomoss graph preparation, planning, mutation, state persistence,
18
+ * and operator rendering. Consumers use this service for plan, apply, and
19
+ * destroy entrypoints instead of assembling lifecycle and renderer calls.
20
+ */
21
+ export class ResourceStackOperations extends Context.Service<ResourceStackOperations>()(
22
+ "nomoss/core/resourceStackOperations",
23
+ {
24
+ make: Effect.gen(function* () {
25
+ const definition = yield* ResourceStackDefinition;
26
+ const lifecycle = yield* ResourceStackLifecycle;
27
+ const renderer = yield* StackWorkflowRenderer;
28
+
29
+ const prepare = Effect.fn("ResourceStackOperations.prepare")(
30
+ function* () {
31
+ yield* definition.declare();
32
+
33
+ return yield* lifecycle.prepare(definition.stackName);
34
+ },
35
+ );
36
+ const plan = Effect.fn("ResourceStackOperations.plan")(function* () {
37
+ const prepared = yield* prepare();
38
+
39
+ return yield* lifecycle.plan(prepared).pipe(
40
+ Effect.mapError(
41
+ (cause) =>
42
+ new ResourceStackOperationFailed({
43
+ stackName: definition.stackName,
44
+ operation: "plan",
45
+ cause,
46
+ }),
47
+ ),
48
+ );
49
+ });
50
+ const apply = Effect.fn("ResourceStackOperations.apply")(function* () {
51
+ const prepared = yield* prepare();
52
+
53
+ return yield* lifecycle.apply(prepared).pipe(
54
+ Effect.mapError(
55
+ (cause) =>
56
+ new ResourceStackOperationFailed({
57
+ stackName: definition.stackName,
58
+ operation: "apply",
59
+ cause,
60
+ }),
61
+ ),
62
+ );
63
+ });
64
+ const destroy = Effect.fn("ResourceStackOperations.destroy")(
65
+ function* () {
66
+ const prepared = yield* prepare();
67
+
68
+ return yield* lifecycle.destroy(prepared).pipe(
69
+ Effect.mapError(
70
+ (cause) =>
71
+ new ResourceStackOperationFailed({
72
+ stackName: definition.stackName,
73
+ operation: "destroy",
74
+ cause,
75
+ }),
76
+ ),
77
+ );
78
+ },
79
+ );
80
+
81
+ return {
82
+ prepare,
83
+ plan,
84
+ apply,
85
+ destroy,
86
+ renderPlan: Effect.fn("ResourceStackOperations.renderPlan")(
87
+ function* () {
88
+ const stackPlan = yield* plan();
89
+
90
+ yield* renderer.renderPlan({
91
+ stackName: definition.stackName,
92
+ plan: stackPlan,
93
+ });
94
+ },
95
+ ),
96
+ renderApply: Effect.fn("ResourceStackOperations.renderApply")(
97
+ function* () {
98
+ const result = yield* apply();
99
+
100
+ yield* renderer.renderApplyResult(result);
101
+ yield* Option.match(
102
+ Option.liftPredicate(result, (value) => value.applied),
103
+ {
104
+ onNone: () => Effect.void,
105
+ onSome: () =>
106
+ Console.log(`applied stack ${definition.stackName}`),
107
+ },
108
+ );
109
+ },
110
+ ),
111
+ renderDestroy: Effect.fn("ResourceStackOperations.renderDestroy")(
112
+ function* () {
113
+ const result = yield* destroy();
114
+
115
+ yield* renderer.renderDestroyResult(result);
116
+ yield* Option.match(
117
+ Option.liftPredicate(result, (value) => value.destroyed),
118
+ {
119
+ onNone: () => Effect.void,
120
+ onSome: () =>
121
+ Console.log(`destroyed stack ${definition.stackName}`),
122
+ },
123
+ );
124
+ },
125
+ ),
126
+ };
127
+ }),
128
+ },
129
+ ) {}
@@ -0,0 +1,73 @@
1
+ import { Layer } from "effect";
2
+
3
+ import { ResourceModel } from "./model.js";
4
+ import { PhysicalNameStore } from "./physicalNameStore.js";
5
+ import { ResourcePlanner } from "./planner.js";
6
+ import { ResourceGraphBuilder } from "./resourceGraphBuilder.js";
7
+ import { ResourceGraphStore } from "./resourceGraphStore.js";
8
+ import { ResourceOutputResolver } from "./resourceOutputResolver.js";
9
+ import { ResourcePolicy } from "./resourcePolicy.js";
10
+ import { ResourceStackLifecycle } from "./resourceStackLifecycle.js";
11
+ import { ResourceStackOperations } from "./resourceStackOperations.js";
12
+ import { StackWorkflowRenderer } from "./stackWorkflowRenderer.js";
13
+ import { StateSecretServiceDefaultLayer } from "./stateSecretService.js";
14
+ import { ResourceStateStore } from "./stateStore.js";
15
+
16
+ export const resourceModelLayer = Layer.effect(
17
+ ResourceModel,
18
+ ResourceModel.make,
19
+ );
20
+
21
+ export const resourceGraphStoreLayer = Layer.effect(
22
+ ResourceGraphStore,
23
+ ResourceGraphStore.make,
24
+ ).pipe(Layer.provideMerge(resourceModelLayer));
25
+
26
+ export const resourceGraphBuilderLayer = Layer.effect(
27
+ ResourceGraphBuilder,
28
+ ResourceGraphBuilder.make,
29
+ ).pipe(Layer.provideMerge(resourceModelLayer));
30
+
31
+ export const resourcePlannerLayer = Layer.effect(
32
+ ResourcePlanner,
33
+ ResourcePlanner.make,
34
+ ).pipe(Layer.provideMerge(resourceModelLayer));
35
+
36
+ export const resourceOutputResolverLayer = Layer.effect(
37
+ ResourceOutputResolver,
38
+ ResourceOutputResolver.make,
39
+ );
40
+
41
+ export const resourcePolicyLayer = Layer.effect(
42
+ ResourcePolicy,
43
+ ResourcePolicy.make,
44
+ );
45
+
46
+ export const physicalNameStoreLayer = Layer.effect(
47
+ PhysicalNameStore,
48
+ PhysicalNameStore.make,
49
+ );
50
+
51
+ export const resourceStateStoreBaseLayer = Layer.effect(
52
+ ResourceStateStore,
53
+ ResourceStateStore.make,
54
+ );
55
+
56
+ export const resourceStateStoreLayer = resourceStateStoreBaseLayer.pipe(
57
+ Layer.provideMerge(StateSecretServiceDefaultLayer),
58
+ );
59
+
60
+ export const resourceStackLifecycleLayer = Layer.effect(
61
+ ResourceStackLifecycle,
62
+ ResourceStackLifecycle.make,
63
+ );
64
+
65
+ export const resourceStackOperationsLayer = Layer.effect(
66
+ ResourceStackOperations,
67
+ ResourceStackOperations.make,
68
+ );
69
+
70
+ export const stackWorkflowRendererLayer = Layer.effect(
71
+ StackWorkflowRenderer,
72
+ StackWorkflowRenderer.make,
73
+ );