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,270 @@
1
+ import {
2
+ Array as Arr,
3
+ Context,
4
+ Effect,
5
+ Equal,
6
+ Match,
7
+ Option,
8
+ Order,
9
+ Record,
10
+ type Schema,
11
+ } from "effect";
12
+
13
+ import {
14
+ PlanDecision,
15
+ type PlanDecision as PlanDecisionValue,
16
+ PlanRepairChange,
17
+ ResourceCommand,
18
+ ResourceCommandResult,
19
+ ResourceCommandUnsupported,
20
+ type ResourceObservation,
21
+ } from "../../core/lifecycle.js";
22
+ import {
23
+ ResourceModel,
24
+ type ResourceNode,
25
+ readResourceSchemaAnnotation,
26
+ } from "../../core/model.js";
27
+ import { ResourcePolicy } from "../../core/resourcePolicy.js";
28
+ import {
29
+ QueueLifecycleService,
30
+ type QueueObservedState,
31
+ QueueObservedStateSchema,
32
+ QueueOutputsSchema,
33
+ QueuePropsSchema,
34
+ QueueUrlMissing,
35
+ queueOutputsFromState,
36
+ } from "./awsQueue.js";
37
+ import { AwsTagging } from "./awsTagging.js";
38
+
39
+ const definedTags = (tags: Record<string, string | undefined>) =>
40
+ Record.filter(tags, (value): value is string => value !== undefined);
41
+
42
+ const formatTagValue = (value: string | undefined) =>
43
+ Match.value(value).pipe(
44
+ Match.when(undefined, () => "undefined"),
45
+ Match.orElse((defined) => `"${defined}"`),
46
+ );
47
+
48
+ /**
49
+ * A live SQS queue can exist with a tag set that differs from its stack
50
+ * declaration. The plan renderer uses these per-key changes to show what the
51
+ * queue repair command will reconcile through `AwsTagging`, including tags the
52
+ * declaration no longer contains.
53
+ */
54
+ const queueTagDecision = (
55
+ node: ResourceNode,
56
+ desiredTags: Record<string, string>,
57
+ observedTags: Record<string, string>,
58
+ ) => {
59
+ const tagKeys: ReadonlyArray<string> = Arr.sort(
60
+ Arr.union(Record.keys(desiredTags), Record.keys(observedTags)),
61
+ Order.String,
62
+ );
63
+
64
+ return Match.value(Equal.equals(desiredTags, observedTags)).pipe(
65
+ Match.when(false, () =>
66
+ PlanDecision.Repair({
67
+ node,
68
+ reason: "queue tags differ from desired state",
69
+ changes: Arr.flatMap(
70
+ Arr.filter<string>(
71
+ tagKeys,
72
+ (key) => desiredTags[key] !== observedTags[key],
73
+ ),
74
+ (key): ReadonlyArray<PlanRepairChange> =>
75
+ Option.match(Option.fromUndefinedOr(desiredTags[key]), {
76
+ onNone: () => [
77
+ PlanRepairChange.Removed({
78
+ path: ["aws", "sqs", "queue", "tags", key],
79
+ before: formatTagValue(observedTags[key]),
80
+ }),
81
+ ],
82
+ onSome: (desiredTag) => [
83
+ PlanRepairChange.Updated({
84
+ path: ["aws", "sqs", "queue", "tags", key],
85
+ before: formatTagValue(observedTags[key]),
86
+ after: formatTagValue(desiredTag),
87
+ }),
88
+ ],
89
+ }),
90
+ ),
91
+ }),
92
+ ),
93
+ Match.orElse(() => PlanDecision.NoOp({ node })),
94
+ );
95
+ };
96
+
97
+ /**
98
+ * The AWS resource dispatcher reaches queue behavior through this policy so
99
+ * SQS reads, writes, and tag reconciliation stay in the provider path.
100
+ */
101
+ export class QueueResourcePolicy extends Context.Service<QueueResourcePolicy>()(
102
+ "nomoss/providers/aws/awsQueueResourcePolicy/QueueResourcePolicy",
103
+ {
104
+ make: Effect.gen(function* () {
105
+ const lifecycle = yield* QueueLifecycleService;
106
+ const tagging = yield* AwsTagging;
107
+ const model = yield* ResourceModel;
108
+ const resourcePolicy = yield* ResourcePolicy;
109
+ const schema = yield* readResourceSchemaAnnotation(QueuePropsSchema).pipe(
110
+ Effect.fromOption,
111
+ );
112
+
113
+ const decidePresent = (node: ResourceNode, observed: Schema.Json) =>
114
+ model
115
+ .decodeProps(node, QueuePropsSchema)
116
+ .pipe(
117
+ Effect.flatMap((props) =>
118
+ Effect.map(
119
+ model.decodeJson(QueueObservedStateSchema, observed),
120
+ (state) =>
121
+ queueTagDecision(
122
+ node,
123
+ definedTags(props.tags ?? {}),
124
+ definedTags(state.tags.Tags ?? {}),
125
+ ),
126
+ ),
127
+ ),
128
+ );
129
+
130
+ const read = Effect.fn("QueueResourcePolicy.read")(function* (
131
+ node: ResourceNode,
132
+ ) {
133
+ const props = yield* model.decodeProps(node, QueuePropsSchema);
134
+ const output = yield* lifecycle.read(props);
135
+ const result = yield* Effect.fromOption(output).pipe(
136
+ Effect.flatMap((state: QueueObservedState) =>
137
+ Effect.map(
138
+ model.encodeJson(QueueObservedStateSchema, state),
139
+ (observed) => resourcePolicy.present(node, observed),
140
+ ),
141
+ ),
142
+ Effect.catchNoSuchElement,
143
+ Effect.map(Option.getOrElse(() => resourcePolicy.missing(node))),
144
+ );
145
+
146
+ return result;
147
+ });
148
+ const diff = Effect.fn("QueueResourcePolicy.diff")(function* (
149
+ node: ResourceNode,
150
+ observation: ResourceObservation,
151
+ ) {
152
+ const decision = yield* Match.value(observation).pipe(
153
+ Match.tagsExhaustive({
154
+ Missing: () => Effect.succeed(PlanDecision.Create({ node })),
155
+ Unreadable: ({ reason }) =>
156
+ Effect.succeed(PlanDecision.Repair({ node, reason })),
157
+ Drifted: ({ reason }) =>
158
+ Effect.succeed(PlanDecision.Repair({ node, reason })),
159
+ Present: ({ observed }) => decidePresent(node, observed),
160
+ }),
161
+ );
162
+
163
+ return ResourceCommandResult.Decided({ decision });
164
+ });
165
+ const create = Effect.fn("QueueResourcePolicy.create")(function* (
166
+ node: ResourceNode,
167
+ ) {
168
+ const props = yield* model.decodeProps(node, QueuePropsSchema);
169
+ const state = yield* lifecycle.create(props);
170
+ const appliedNode = yield* model.nodeFromResource({
171
+ key: node.key,
172
+ propsSchema: QueuePropsSchema,
173
+ outputsSchema: QueueOutputsSchema,
174
+ props,
175
+ outputs: queueOutputsFromState(state),
176
+ });
177
+
178
+ return ResourceCommandResult.Created({ node: appliedNode });
179
+ });
180
+ const repair = Effect.fn("QueueResourcePolicy.repair")(function* (
181
+ node: ResourceNode,
182
+ ) {
183
+ const props = yield* model.decodeProps(node, QueuePropsSchema);
184
+ const observed = yield* lifecycle.read(props);
185
+ const state = yield* Effect.fromOption(observed);
186
+ const queueUrl = yield* Option.match(
187
+ Option.fromUndefinedOr(state.url.QueueUrl),
188
+ {
189
+ onNone: () =>
190
+ Effect.fail(new QueueUrlMissing({ queueName: props.QueueName })),
191
+ onSome: Effect.succeed,
192
+ },
193
+ );
194
+
195
+ yield* tagging.reconcile({
196
+ target: { _tag: "SqsQueue", queueUrl },
197
+ desiredTags: definedTags(props.tags ?? {}),
198
+ observedTags: definedTags(state.tags.Tags ?? {}),
199
+ });
200
+
201
+ return ResourceCommandResult.Updated({ node });
202
+ });
203
+ const destroy = Effect.fn("QueueResourcePolicy.destroy")(function* (
204
+ node: ResourceNode,
205
+ ) {
206
+ const props = yield* model.decodeProps(node, QueuePropsSchema);
207
+ yield* lifecycle.destroy(props);
208
+
209
+ return ResourceCommandResult.Destroyed({ node });
210
+ });
211
+ const apply = Effect.fn("QueueResourcePolicy.apply")(function* (
212
+ decision: PlanDecisionValue,
213
+ ) {
214
+ return yield* Match.value(decision).pipe(
215
+ Match.tagsExhaustive({
216
+ Create: ({ node }) => create(node),
217
+ Repair: ({ node }) => repair(node),
218
+ Destroy: ({ node }) => destroy(node),
219
+ NoOp: () =>
220
+ Effect.fail(
221
+ new ResourceCommandUnsupported({
222
+ command: ResourceCommand.Apply({ decision }),
223
+ }),
224
+ ),
225
+ Update: () =>
226
+ Effect.fail(
227
+ new ResourceCommandUnsupported({
228
+ command: ResourceCommand.Apply({ decision }),
229
+ }),
230
+ ),
231
+ Delete: () =>
232
+ Effect.fail(
233
+ new ResourceCommandUnsupported({
234
+ command: ResourceCommand.Apply({ decision }),
235
+ }),
236
+ ),
237
+ }),
238
+ );
239
+ });
240
+
241
+ return {
242
+ schema,
243
+ read,
244
+ diff,
245
+ create,
246
+ repair,
247
+ destroy,
248
+ apply,
249
+ execute: Effect.fn("QueueResourcePolicy.execute")(function* (
250
+ command: ResourceCommand,
251
+ ) {
252
+ return yield* Match.value(command).pipe(
253
+ Match.tagsExhaustive({
254
+ Read: ({ node }) => read(node),
255
+ Diff: ({ node, observation }) => diff(node, observation),
256
+ Apply: ({ decision }) => apply(decision),
257
+ Create: ({ node }) => create(node),
258
+ Update: () =>
259
+ Effect.fail(new ResourceCommandUnsupported({ command })),
260
+ Delete: () =>
261
+ Effect.fail(new ResourceCommandUnsupported({ command })),
262
+ Destroy: () =>
263
+ Effect.fail(new ResourceCommandUnsupported({ command })),
264
+ }),
265
+ );
266
+ }),
267
+ };
268
+ }),
269
+ },
270
+ ) {}
@@ -0,0 +1,92 @@
1
+ import {
2
+ Array as Arr,
3
+ Context,
4
+ Data,
5
+ Effect,
6
+ Graph,
7
+ Match,
8
+ Option,
9
+ } from "effect";
10
+
11
+ import {
12
+ PlanDecision,
13
+ type ResourceObservation,
14
+ } from "../../core/lifecycle.js";
15
+ import { keyString, type ResourceKey } from "../../core/model.js";
16
+ import type { ResourceDependencyGraph } from "../../core/planner.js";
17
+ import { AwsResourceLifecycle } from "./awsResourceLifecycle.js";
18
+
19
+ export class ResourceObservationMissing extends Data.TaggedError(
20
+ "ResourceObservationMissing",
21
+ )<{
22
+ readonly key: ResourceKey;
23
+ }> {}
24
+
25
+ /**
26
+ * Reconciliation keeps graph order while delegating provider-specific diff
27
+ * decisions to resource policies for apply and rendering workflows.
28
+ */
29
+ export class AwsReconciliation extends Context.Service<AwsReconciliation>()(
30
+ "nomoss/providers/aws/awsReconciliation",
31
+ {
32
+ make: Effect.gen(function* () {
33
+ const lifecycle = yield* AwsResourceLifecycle;
34
+
35
+ return {
36
+ decideFromObservations: Effect.fn(
37
+ "AwsReconciliation.decideFromObservations",
38
+ )(function* (
39
+ graph: ResourceDependencyGraph,
40
+ observations: ReadonlyArray<ResourceObservation>,
41
+ ) {
42
+ const observationsByKey = new Map(
43
+ Arr.map(
44
+ observations,
45
+ (observation): readonly [string, ResourceObservation] => [
46
+ keyString(observation.node.key),
47
+ observation,
48
+ ],
49
+ ),
50
+ );
51
+ const decisionEntries = yield* Effect.forEach(
52
+ Graph.values(Graph.topo(graph)),
53
+ Effect.fn("AwsReconciliation.decideNode")(function* (node) {
54
+ const observation = yield* Option.fromUndefinedOr(
55
+ observationsByKey.get(keyString(node.key)),
56
+ ).pipe(
57
+ Option.match({
58
+ onNone: () =>
59
+ Effect.fail(
60
+ new ResourceObservationMissing({ key: node.key }),
61
+ ),
62
+ onSome: Effect.succeed,
63
+ }),
64
+ );
65
+ const decision = yield* Match.value(observation).pipe(
66
+ Match.tagsExhaustive({
67
+ Unreadable: () => Effect.succeed(PlanDecision.NoOp({ node })),
68
+ Present: () => lifecycle.diff(node, observation),
69
+ Missing: () => lifecycle.diff(node, observation),
70
+ Drifted: () => lifecycle.diff(node, observation),
71
+ }),
72
+ );
73
+
74
+ return decision;
75
+ }),
76
+ );
77
+ const decisions = new Map(
78
+ Arr.map(
79
+ decisionEntries,
80
+ (entry): readonly [string, PlanDecision] => [
81
+ keyString(entry.node.key),
82
+ entry,
83
+ ],
84
+ ),
85
+ );
86
+
87
+ return decisions;
88
+ }),
89
+ };
90
+ }),
91
+ },
92
+ ) {}
@@ -0,0 +1,50 @@
1
+ import { Context, Effect, Graph } from "effect";
2
+
3
+ import type { ResourceDependencyGraph } from "../../core/planner.js";
4
+ import { ResourcePolicy } from "../../core/resourcePolicy.js";
5
+ import { AwsResourceLifecycle } from "./awsResourceLifecycle.js";
6
+
7
+ /**
8
+ * Refresh turns resource-policy reads into graph observations and records
9
+ * unsupported reads as typed observations for reconciliation.
10
+ */
11
+ export class AwsRefresh extends Context.Service<AwsRefresh>()(
12
+ "nomoss/providers/aws/awsRefresh",
13
+ {
14
+ make: Effect.gen(function* () {
15
+ const lifecycle = yield* AwsResourceLifecycle;
16
+ const resourcePolicy = yield* ResourcePolicy;
17
+
18
+ return {
19
+ refreshGraph: Effect.fn("AwsRefresh.refreshGraph")(function* (
20
+ graph: ResourceDependencyGraph,
21
+ ) {
22
+ const observations = yield* Effect.forEach(
23
+ Graph.values(Graph.topo(graph)),
24
+ (node) =>
25
+ lifecycle.read(node).pipe(
26
+ Effect.catchTags({
27
+ ResourceCommandUnsupported: () =>
28
+ Effect.succeed(
29
+ resourcePolicy.unreadableObservation(
30
+ node,
31
+ "read unsupported",
32
+ ),
33
+ ),
34
+ AwsResourceKindUnsupported: () =>
35
+ Effect.succeed(
36
+ resourcePolicy.unreadableObservation(
37
+ node,
38
+ "resource kind unsupported",
39
+ ),
40
+ ),
41
+ }),
42
+ ),
43
+ );
44
+
45
+ return observations;
46
+ }),
47
+ };
48
+ }),
49
+ },
50
+ ) {}
@@ -0,0 +1,118 @@
1
+ import { Context, Data, Effect, Match, Option } from "effect";
2
+
3
+ import {
4
+ type PlanDecision,
5
+ ResourceCommand,
6
+ type ResourceCommandResult,
7
+ type ResourceObservation,
8
+ } from "../../core/lifecycle.js";
9
+ import type { ResourceNode } from "../../core/model.js";
10
+ import { AwsResourcePolicy } from "./awsResourcePolicy.js";
11
+
12
+ export class ResourceObservationResultExpected extends Data.TaggedError(
13
+ "ResourceObservationResultExpected",
14
+ )<{
15
+ readonly result: ResourceCommandResult;
16
+ }> {}
17
+
18
+ export class ResourceDecisionResultExpected extends Data.TaggedError(
19
+ "ResourceDecisionResultExpected",
20
+ )<{
21
+ readonly result: ResourceCommandResult;
22
+ }> {}
23
+
24
+ export class ResourceApplyResultExpected extends Data.TaggedError(
25
+ "ResourceApplyResultExpected",
26
+ )<{
27
+ readonly result: ResourceCommandResult;
28
+ }> {}
29
+
30
+ export type AppliedResourceCommandResult = Extract<
31
+ ResourceCommandResult,
32
+ { readonly _tag: "Created" | "Updated" | "Destroyed" }
33
+ >;
34
+
35
+ /**
36
+ * Refresh, reconciliation, and apply code use this command protocol instead of
37
+ * unpacking provider-specific resource results locally.
38
+ */
39
+ export class AwsResourceLifecycle extends Context.Service<AwsResourceLifecycle>()(
40
+ "nomoss/providers/aws/awsResourceLifecycle",
41
+ {
42
+ make: Effect.gen(function* () {
43
+ const policy = yield* AwsResourcePolicy;
44
+
45
+ const applyChangedDecision = Effect.fn(
46
+ "AwsResourceLifecycle.applyChangedDecision",
47
+ )(function* (
48
+ nextDecision: Exclude<PlanDecision, { readonly _tag: "NoOp" }>,
49
+ ) {
50
+ const result = yield* policy.execute(
51
+ ResourceCommand.Apply({ decision: nextDecision }),
52
+ );
53
+ const applied = yield* Match.value(result).pipe(
54
+ Match.when({ _tag: "Created" }, (created) =>
55
+ Effect.succeed(created),
56
+ ),
57
+ Match.when({ _tag: "Updated" }, (updated) =>
58
+ Effect.succeed(updated),
59
+ ),
60
+ Match.when({ _tag: "Destroyed" }, (destroyed) =>
61
+ Effect.succeed(destroyed),
62
+ ),
63
+ Match.orElse(() =>
64
+ Effect.fail(new ResourceApplyResultExpected({ result })),
65
+ ),
66
+ );
67
+
68
+ return Option.some(applied);
69
+ });
70
+
71
+ return {
72
+ read: Effect.fn("AwsResourceLifecycle.read")(function* (
73
+ node: ResourceNode,
74
+ ) {
75
+ const result = yield* policy.execute(ResourceCommand.Read({ node }));
76
+ const observation = yield* Match.value(result).pipe(
77
+ Match.when({ _tag: "Observed" }, ({ observation }) =>
78
+ Effect.succeed(observation),
79
+ ),
80
+ Match.orElse(() =>
81
+ Effect.fail(new ResourceObservationResultExpected({ result })),
82
+ ),
83
+ );
84
+
85
+ return observation;
86
+ }),
87
+
88
+ diff: Effect.fn("AwsResourceLifecycle.diff")(function* (
89
+ node: ResourceNode,
90
+ observation: ResourceObservation,
91
+ ) {
92
+ const result = yield* policy.execute(
93
+ ResourceCommand.Diff({ node, observation }),
94
+ );
95
+ const decision = yield* Match.value(result).pipe(
96
+ Match.when({ _tag: "Decided" }, ({ decision }) =>
97
+ Effect.succeed(decision),
98
+ ),
99
+ Match.orElse(() =>
100
+ Effect.fail(new ResourceDecisionResultExpected({ result })),
101
+ ),
102
+ );
103
+
104
+ return decision;
105
+ }),
106
+
107
+ apply: Effect.fn("AwsResourceLifecycle.apply")(function* (
108
+ decision: PlanDecision,
109
+ ) {
110
+ return yield* Match.value(decision).pipe(
111
+ Match.when({ _tag: "NoOp" }, () => Effect.succeed(Option.none())),
112
+ Match.orElse(applyChangedDecision),
113
+ );
114
+ }),
115
+ };
116
+ }),
117
+ },
118
+ ) {}
@@ -0,0 +1,83 @@
1
+ import { Context, Data, Effect, Match } from "effect";
2
+
3
+ import type { ResourceCommand } from "../../core/lifecycle.js";
4
+ import type { ResourceNode } from "../../core/model.js";
5
+ import { BucketNotificationResourcePolicy } from "./awsBucketNotificationResourcePolicy.js";
6
+ import { BucketResourcePolicy } from "./awsBucketResourcePolicy.js";
7
+ import { QueuePolicyResourcePolicy } from "./awsQueuePolicyResourcePolicy.js";
8
+ import { QueueResourcePolicy } from "./awsQueueResourcePolicy.js";
9
+
10
+ export class AwsResourceKindUnsupported extends Data.TaggedError(
11
+ "AwsResourceKindUnsupported",
12
+ )<{
13
+ readonly node: ResourceNode;
14
+ }> {}
15
+
16
+ /**
17
+ * Resource-kind selection stays explicit here before graph commands reach the
18
+ * assigned AWS policy.
19
+ */
20
+ export class AwsResourcePolicy extends Context.Service<AwsResourcePolicy>()(
21
+ "nomoss/providers/aws/awsResourcePolicy",
22
+ {
23
+ make: Effect.gen(function* () {
24
+ const bucket = yield* BucketResourcePolicy;
25
+ const queue = yield* QueueResourcePolicy;
26
+ const queuePolicy = yield* QueuePolicyResourcePolicy;
27
+ const bucketNotification = yield* BucketNotificationResourcePolicy;
28
+
29
+ return {
30
+ execute: Effect.fn("AwsResourcePolicy.execute")(function* (
31
+ command: ResourceCommand,
32
+ ) {
33
+ const node = Match.value(command).pipe(
34
+ Match.when({ _tag: "Apply" }, ({ decision }) => decision.node),
35
+ Match.orElse(({ node }) => node),
36
+ );
37
+
38
+ return yield* Match.value(node.schema).pipe(
39
+ Match.when(
40
+ {
41
+ provider: "aws",
42
+ service: "s3",
43
+ resource: "bucket",
44
+ operation: "create",
45
+ },
46
+ () => bucket.execute(command),
47
+ ),
48
+ Match.when(
49
+ {
50
+ provider: "aws",
51
+ service: "sqs",
52
+ resource: "queue",
53
+ operation: "create",
54
+ },
55
+ () => queue.execute(command),
56
+ ),
57
+ Match.when(
58
+ {
59
+ provider: "aws",
60
+ service: "sqs",
61
+ resource: "queue-policy",
62
+ operation: "create",
63
+ },
64
+ () => queuePolicy.execute(command),
65
+ ),
66
+ Match.when(
67
+ {
68
+ provider: "aws",
69
+ service: "s3",
70
+ resource: "bucket-notification",
71
+ operation: "create",
72
+ },
73
+ () => bucketNotification.execute(command),
74
+ ),
75
+ Match.orElse(() =>
76
+ Effect.fail(new AwsResourceKindUnsupported({ node })),
77
+ ),
78
+ );
79
+ }),
80
+ };
81
+ }),
82
+ },
83
+ ) {}