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.
- package/LICENSE +19 -0
- package/README.md +45 -0
- package/bin/nomoss +13 -0
- package/docs/code-documentation.md +36 -0
- package/docs/effect-native-development.md +55 -0
- package/docs/engine-design.md +93 -0
- package/docs/linting.md +88 -0
- package/docs/releasing.md +13 -0
- package/docs/resource-command-policy-stage.md +71 -0
- package/docs/resource-graph-mvp.md +31 -0
- package/docs/resource-graph-testing-approach.md +11 -0
- package/docs/resource-lifecycle-tracker.md +93 -0
- package/docs/testing.md +86 -0
- package/examples/upload-events/README.md +41 -0
- package/media/nomoss.gif +0 -0
- package/package.json +64 -0
- package/src/cli.ts +18 -0
- package/src/cliCommand.ts +186 -0
- package/src/cliRuntimeLayer.ts +49 -0
- package/src/core/index.ts +17 -0
- package/src/core/lifecycle.ts +127 -0
- package/src/core/model.ts +229 -0
- package/src/core/physicalNameStore.ts +226 -0
- package/src/core/planner.ts +645 -0
- package/src/core/resourceCommandPolicy.ts +79 -0
- package/src/core/resourceGraphBuilder.ts +167 -0
- package/src/core/resourceGraphStore.ts +288 -0
- package/src/core/resourceOutputResolver.ts +185 -0
- package/src/core/resourcePolicy.ts +77 -0
- package/src/core/resourceStackDefinition.ts +17 -0
- package/src/core/resourceStackLifecycle.ts +456 -0
- package/src/core/resourceStackOperations.ts +129 -0
- package/src/core/runtimeLayer.ts +73 -0
- package/src/core/stackWorkflowRenderer.ts +239 -0
- package/src/core/stateSecretService.ts +553 -0
- package/src/core/stateStore.ts +652 -0
- package/src/core/tracing.ts +26 -0
- package/src/index.ts +2 -0
- package/src/providers/aws/awsApply.ts +132 -0
- package/src/providers/aws/awsBucket.ts +329 -0
- package/src/providers/aws/awsBucketNotification.ts +351 -0
- package/src/providers/aws/awsBucketNotificationResourcePolicy.ts +251 -0
- package/src/providers/aws/awsBucketResourcePolicy.ts +198 -0
- package/src/providers/aws/awsProviderLayer.ts +274 -0
- package/src/providers/aws/awsQueue.ts +346 -0
- package/src/providers/aws/awsQueuePolicy.ts +419 -0
- package/src/providers/aws/awsQueuePolicyResourcePolicy.ts +215 -0
- package/src/providers/aws/awsQueueResourcePolicy.ts +270 -0
- package/src/providers/aws/awsReconciliation.ts +92 -0
- package/src/providers/aws/awsRefresh.ts +50 -0
- package/src/providers/aws/awsResourceLifecycle.ts +118 -0
- package/src/providers/aws/awsResourcePolicy.ts +83 -0
- package/src/providers/aws/awsResources.ts +274 -0
- package/src/providers/aws/awsRuntimeLayer.ts +21 -0
- package/src/providers/aws/awsSqsTransport.ts +33 -0
- package/src/providers/aws/awsStackLifecycle.ts +272 -0
- package/src/providers/aws/awsTagging.ts +186 -0
- package/src/providers/aws/constants.ts +3 -0
- package/src/providers/aws/index.ts +22 -0
- package/src/providers/aws/sampleStack.ts +65 -0
- package/src/providers/aws/stackWorkflow.ts +443 -0
- package/src/providers/index.ts +5 -0
- package/src/providers/provider.ts +5 -0
- package/src/providers/providerRuntimeLayer.ts +121 -0
- package/src/providers/resourceCommandPolicyLayer.ts +240 -0
- package/src/providers/stripe/index.ts +15 -0
- package/src/providers/stripe/stripeAccount.ts +139 -0
- package/src/providers/stripe/stripeBillingConfigurationExport.ts +180 -0
- package/src/providers/stripe/stripeBillingConfigurationExportResourcePolicy.ts +178 -0
- package/src/providers/stripe/stripeBillingPortalConfiguration.ts +153 -0
- package/src/providers/stripe/stripeBillingPortalConfigurationResourcePolicy.ts +177 -0
- package/src/providers/stripe/stripeCustomer.ts +148 -0
- package/src/providers/stripe/stripeCustomerResourcePolicy.ts +160 -0
- package/src/providers/stripe/stripePrice.ts +218 -0
- package/src/providers/stripe/stripePriceResourcePolicy.ts +151 -0
- package/src/providers/stripe/stripeProduct.ts +171 -0
- package/src/providers/stripe/stripeProductResourcePolicy.ts +161 -0
- package/src/providers/stripe/stripeResources.ts +454 -0
- package/src/providers/stripe/stripeRuntimeLayer.ts +131 -0
- package/src/providers/stripe/stripeWebhookEndpoint.ts +293 -0
- package/src/providers/stripe/stripeWebhookEndpointResourcePolicy.ts +198 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Array as Arr,
|
|
3
|
+
Context,
|
|
4
|
+
Data,
|
|
5
|
+
Duration,
|
|
6
|
+
Effect,
|
|
7
|
+
Option,
|
|
8
|
+
} from "effect";
|
|
9
|
+
|
|
10
|
+
import type { PlanDecision } from "../../core/lifecycle.js";
|
|
11
|
+
import {
|
|
12
|
+
keyString,
|
|
13
|
+
type PlanAction,
|
|
14
|
+
type ResourceKey,
|
|
15
|
+
} from "../../core/model.js";
|
|
16
|
+
import {
|
|
17
|
+
type ResourceDependencyGraph,
|
|
18
|
+
ResourcePlanner,
|
|
19
|
+
} from "../../core/planner.js";
|
|
20
|
+
import {
|
|
21
|
+
type AppliedResourceCommandResult,
|
|
22
|
+
AwsResourceLifecycle,
|
|
23
|
+
} from "./awsResourceLifecycle.js";
|
|
24
|
+
|
|
25
|
+
export class ResourceDecisionMissing extends Data.TaggedError(
|
|
26
|
+
"ResourceDecisionMissing",
|
|
27
|
+
)<{
|
|
28
|
+
readonly key: ResourceKey;
|
|
29
|
+
}> {}
|
|
30
|
+
|
|
31
|
+
export type AppliedResource = {
|
|
32
|
+
readonly result: AppliedResourceCommandResult;
|
|
33
|
+
readonly durationMillis: number;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* AWS apply runs reconciliation decisions in planner order while allowing each
|
|
38
|
+
* independent batch to execute through resource policies concurrently.
|
|
39
|
+
*/
|
|
40
|
+
export class AwsApply extends Context.Service<AwsApply>()(
|
|
41
|
+
"nomoss/providers/aws/awsApply",
|
|
42
|
+
{
|
|
43
|
+
make: Effect.gen(function* () {
|
|
44
|
+
const lifecycle = yield* AwsResourceLifecycle;
|
|
45
|
+
const planner = yield* ResourcePlanner;
|
|
46
|
+
|
|
47
|
+
return {
|
|
48
|
+
applyDecisions: Effect.fn("AwsApply.applyDecisions")(function* (
|
|
49
|
+
graph: ResourceDependencyGraph,
|
|
50
|
+
decisions: ReadonlyMap<string, PlanDecision>,
|
|
51
|
+
) {
|
|
52
|
+
const changed = Arr.filter(
|
|
53
|
+
Arr.fromIterable(decisions.values()),
|
|
54
|
+
(decision) => decision._tag !== "NoOp",
|
|
55
|
+
);
|
|
56
|
+
const destroyOnly = Arr.every(
|
|
57
|
+
changed,
|
|
58
|
+
(decision) => decision._tag === "Destroy",
|
|
59
|
+
);
|
|
60
|
+
function isCreateOrRepairAction(action: PlanAction): boolean {
|
|
61
|
+
const decision = decisions.get(keyString(action.node.key));
|
|
62
|
+
|
|
63
|
+
return decision?._tag === "Create" || decision?._tag === "Repair";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const batches = Option.filter(
|
|
67
|
+
Option.some(changed),
|
|
68
|
+
() => destroyOnly,
|
|
69
|
+
).pipe(
|
|
70
|
+
Option.match({
|
|
71
|
+
onSome: () =>
|
|
72
|
+
Arr.map(
|
|
73
|
+
planner.destroyBatches(
|
|
74
|
+
graph,
|
|
75
|
+
Arr.map(changed, (decision) => decision.node.key),
|
|
76
|
+
),
|
|
77
|
+
(batch) => Arr.map(batch, (action) => action.node),
|
|
78
|
+
),
|
|
79
|
+
onNone: () =>
|
|
80
|
+
Arr.filter(
|
|
81
|
+
Arr.map(planner.createOrUpdateBatches(graph, []), (batch) =>
|
|
82
|
+
Arr.map(
|
|
83
|
+
Arr.filter(batch, isCreateOrRepairAction),
|
|
84
|
+
(action) => action.node,
|
|
85
|
+
),
|
|
86
|
+
),
|
|
87
|
+
(batch) => batch.length > 0,
|
|
88
|
+
),
|
|
89
|
+
}),
|
|
90
|
+
);
|
|
91
|
+
const results = yield* Effect.forEach(batches, (batch) =>
|
|
92
|
+
Effect.forEach(
|
|
93
|
+
batch,
|
|
94
|
+
Effect.fn("AwsApply.applyNode")(function* (node) {
|
|
95
|
+
const key = keyString(node.key);
|
|
96
|
+
const decision = yield* Option.fromUndefinedOr(
|
|
97
|
+
decisions.get(key),
|
|
98
|
+
).pipe(
|
|
99
|
+
Option.match({
|
|
100
|
+
onNone: () =>
|
|
101
|
+
Effect.fail(
|
|
102
|
+
new ResourceDecisionMissing({
|
|
103
|
+
key: { logicalId: key },
|
|
104
|
+
}),
|
|
105
|
+
),
|
|
106
|
+
onSome: Effect.succeed,
|
|
107
|
+
}),
|
|
108
|
+
);
|
|
109
|
+
const [duration, result] = yield* lifecycle.apply(decision).pipe(
|
|
110
|
+
Effect.timed,
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
return Option.map(result, (defined) => ({
|
|
114
|
+
result: defined,
|
|
115
|
+
durationMillis: Duration.toMillis(duration),
|
|
116
|
+
} satisfies AppliedResource));
|
|
117
|
+
}),
|
|
118
|
+
{ concurrency: "unbounded" },
|
|
119
|
+
),
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
return Arr.flatMap(Arr.flatten(results), (result) =>
|
|
123
|
+
Option.match(result, {
|
|
124
|
+
onNone: () => [],
|
|
125
|
+
onSome: (defined) => [defined],
|
|
126
|
+
}),
|
|
127
|
+
);
|
|
128
|
+
}),
|
|
129
|
+
};
|
|
130
|
+
}),
|
|
131
|
+
},
|
|
132
|
+
) {}
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import type * as S3 from "@distilled.cloud/aws/s3";
|
|
2
|
+
import * as s3 from "@distilled.cloud/aws/s3";
|
|
3
|
+
import { Array as Arr, Context, Data, Effect, Option, Schema } from "effect";
|
|
4
|
+
|
|
5
|
+
import { annotateResourceSchema } from "../../core/model.js";
|
|
6
|
+
|
|
7
|
+
export const BucketPropsSchema = annotateResourceSchema(
|
|
8
|
+
Schema.Struct({
|
|
9
|
+
ACL: Schema.optional(s3.BucketCannedACL),
|
|
10
|
+
Bucket: Schema.String,
|
|
11
|
+
CreateBucketConfiguration: Schema.optional(s3.CreateBucketConfiguration),
|
|
12
|
+
GrantFullControl: Schema.optional(Schema.String),
|
|
13
|
+
GrantRead: Schema.optional(Schema.String),
|
|
14
|
+
GrantReadACP: Schema.optional(Schema.String),
|
|
15
|
+
GrantWrite: Schema.optional(Schema.String),
|
|
16
|
+
GrantWriteACP: Schema.optional(Schema.String),
|
|
17
|
+
ObjectLockEnabledForBucket: Schema.optional(Schema.Boolean),
|
|
18
|
+
ObjectOwnership: Schema.optional(s3.ObjectOwnership),
|
|
19
|
+
BucketNamespace: Schema.optional(s3.BucketNamespace),
|
|
20
|
+
ForceDestroy: Schema.optional(Schema.Boolean),
|
|
21
|
+
}),
|
|
22
|
+
{
|
|
23
|
+
provider: "aws",
|
|
24
|
+
service: "s3",
|
|
25
|
+
resource: "bucket",
|
|
26
|
+
operation: "create",
|
|
27
|
+
stateSecretOutputKeys: [],
|
|
28
|
+
},
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
export type BucketProps = Schema.Schema.Type<typeof BucketPropsSchema>;
|
|
32
|
+
|
|
33
|
+
export const BucketOutputsSchema = Schema.Struct({
|
|
34
|
+
Bucket: Schema.String,
|
|
35
|
+
BucketArn: Schema.String,
|
|
36
|
+
Location: Schema.String,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export const BucketObservedStateSchema = annotateResourceSchema(
|
|
40
|
+
Schema.Struct({
|
|
41
|
+
head: s3.HeadBucketOutput,
|
|
42
|
+
tagging: Schema.optional(s3.GetBucketTaggingOutput),
|
|
43
|
+
}),
|
|
44
|
+
{
|
|
45
|
+
provider: "aws",
|
|
46
|
+
service: "s3",
|
|
47
|
+
resource: "bucket",
|
|
48
|
+
operation: "read",
|
|
49
|
+
stateSecretOutputKeys: [],
|
|
50
|
+
},
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
export type BucketState = {
|
|
54
|
+
readonly bucketName: string;
|
|
55
|
+
readonly bucketArn: `arn:aws:s3:::${string}`;
|
|
56
|
+
readonly region: S3.BucketLocationConstraint | "us-east-1";
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type BucketOutputs = Schema.Schema.Type<typeof BucketOutputsSchema>;
|
|
60
|
+
|
|
61
|
+
export type BucketObservedState = Schema.Schema.Type<
|
|
62
|
+
typeof BucketObservedStateSchema
|
|
63
|
+
>;
|
|
64
|
+
|
|
65
|
+
export class BucketCreateFailed extends Data.TaggedError("BucketCreateFailed")<{
|
|
66
|
+
readonly cause: S3.CreateBucketError;
|
|
67
|
+
}> {}
|
|
68
|
+
|
|
69
|
+
export class BucketReadFailed extends Data.TaggedError("BucketReadFailed")<{
|
|
70
|
+
readonly cause: S3.HeadBucketError | S3.GetBucketTaggingError;
|
|
71
|
+
}> {}
|
|
72
|
+
|
|
73
|
+
export class BucketDeleteFailed extends Data.TaggedError("BucketDeleteFailed")<{
|
|
74
|
+
readonly cause: S3.DeleteBucketError;
|
|
75
|
+
}> {}
|
|
76
|
+
|
|
77
|
+
export class BucketEmptyFailed extends Data.TaggedError("BucketEmptyFailed")<{
|
|
78
|
+
readonly cause:
|
|
79
|
+
| S3.DeleteObjectsError
|
|
80
|
+
| S3.ListObjectsV2Error
|
|
81
|
+
| S3.ListObjectVersionsError;
|
|
82
|
+
}> {}
|
|
83
|
+
|
|
84
|
+
export type BucketError =
|
|
85
|
+
| BucketCreateFailed
|
|
86
|
+
| BucketReadFailed
|
|
87
|
+
| BucketDeleteFailed
|
|
88
|
+
| BucketEmptyFailed;
|
|
89
|
+
|
|
90
|
+
export function bucketOutputsFromState(state: BucketState): BucketOutputs {
|
|
91
|
+
const bucketOutputs: BucketOutputs = {
|
|
92
|
+
Bucket: state.bucketName,
|
|
93
|
+
BucketArn: state.bucketArn,
|
|
94
|
+
Location: `/${state.bucketName}`,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
return bucketOutputs;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export function bucketOutputsFromProps(props: BucketProps): BucketOutputs {
|
|
101
|
+
const bucketOutputs: BucketOutputs = {
|
|
102
|
+
Bucket: props.Bucket,
|
|
103
|
+
BucketArn: `arn:aws:s3:::${props.Bucket}`,
|
|
104
|
+
Location: `/${props.Bucket}`,
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
return bucketOutputs;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export const createBucketRequest = (
|
|
111
|
+
props: BucketProps,
|
|
112
|
+
): S3.CreateBucketRequest => ({
|
|
113
|
+
ACL: props.ACL,
|
|
114
|
+
Bucket: props.Bucket,
|
|
115
|
+
CreateBucketConfiguration: props.CreateBucketConfiguration,
|
|
116
|
+
GrantFullControl: props.GrantFullControl,
|
|
117
|
+
GrantRead: props.GrantRead,
|
|
118
|
+
GrantReadACP: props.GrantReadACP,
|
|
119
|
+
GrantWrite: props.GrantWrite,
|
|
120
|
+
GrantWriteACP: props.GrantWriteACP,
|
|
121
|
+
ObjectLockEnabledForBucket: props.ObjectLockEnabledForBucket,
|
|
122
|
+
ObjectOwnership: props.ObjectOwnership,
|
|
123
|
+
BucketNamespace: props.BucketNamespace,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Bucket policies use this adapter so force-destroy cleanup and AWS error
|
|
128
|
+
* translation stay outside graph-level resource logic.
|
|
129
|
+
*/
|
|
130
|
+
export class BucketLifecycleService extends Context.Service<BucketLifecycleService>()(
|
|
131
|
+
"nomoss/providers/aws/awsBucket/BucketLifecycleService",
|
|
132
|
+
{
|
|
133
|
+
make: Effect.gen(function* () {
|
|
134
|
+
const createBucket = yield* s3.createBucket;
|
|
135
|
+
const headBucket = yield* s3.headBucket;
|
|
136
|
+
const getBucketTagging = yield* s3.getBucketTagging;
|
|
137
|
+
const deleteBucket = yield* s3.deleteBucket;
|
|
138
|
+
const listObjectsV2 = yield* s3.listObjectsV2;
|
|
139
|
+
const listObjectVersions = yield* s3.listObjectVersions;
|
|
140
|
+
const deleteObjects = yield* s3.deleteObjects;
|
|
141
|
+
|
|
142
|
+
const bucketRegionFromProps = (
|
|
143
|
+
props: BucketProps,
|
|
144
|
+
): S3.BucketLocationConstraint | "us-east-1" =>
|
|
145
|
+
Option.fromUndefinedOr(props.CreateBucketConfiguration).pipe(
|
|
146
|
+
Option.flatMap((configuration) =>
|
|
147
|
+
Option.fromUndefinedOr(configuration.LocationConstraint),
|
|
148
|
+
),
|
|
149
|
+
Option.getOrElse(() => "us-east-1"),
|
|
150
|
+
);
|
|
151
|
+
const bucketStateFromProps = (props: BucketProps): BucketState => ({
|
|
152
|
+
bucketName: props.Bucket,
|
|
153
|
+
bucketArn: `arn:aws:s3:::${props.Bucket}`,
|
|
154
|
+
region: bucketRegionFromProps(props),
|
|
155
|
+
});
|
|
156
|
+
const bucketForceDestroyEnabled = (props: BucketProps) =>
|
|
157
|
+
props.ForceDestroy === true;
|
|
158
|
+
const objectIdentifiersFromList = (
|
|
159
|
+
objects: ReadonlyArray<{ readonly Key?: string }>,
|
|
160
|
+
) =>
|
|
161
|
+
Arr.flatMap(objects, (object) =>
|
|
162
|
+
Option.fromUndefinedOr(object.Key).pipe(
|
|
163
|
+
Option.match({
|
|
164
|
+
onNone: () => [] as Array<S3.ObjectIdentifier>,
|
|
165
|
+
onSome: (key) => [{ Key: key }],
|
|
166
|
+
}),
|
|
167
|
+
),
|
|
168
|
+
);
|
|
169
|
+
const versionIdentifiersFromList = (
|
|
170
|
+
objects: ReadonlyArray<{
|
|
171
|
+
readonly Key?: string;
|
|
172
|
+
readonly VersionId?: string;
|
|
173
|
+
}>,
|
|
174
|
+
) =>
|
|
175
|
+
Arr.flatMap(objects, (object) =>
|
|
176
|
+
Option.fromUndefinedOr(object.Key).pipe(
|
|
177
|
+
Option.match({
|
|
178
|
+
onNone: () => [] as Array<S3.ObjectIdentifier>,
|
|
179
|
+
onSome: (key) => [
|
|
180
|
+
{
|
|
181
|
+
Key: key,
|
|
182
|
+
VersionId: object.VersionId,
|
|
183
|
+
},
|
|
184
|
+
],
|
|
185
|
+
}),
|
|
186
|
+
),
|
|
187
|
+
);
|
|
188
|
+
const bucketObservedState = (
|
|
189
|
+
head: S3.HeadBucketOutput,
|
|
190
|
+
tagging: Option.Option<S3.GetBucketTaggingOutput>,
|
|
191
|
+
): BucketObservedState =>
|
|
192
|
+
BucketObservedStateSchema.make(
|
|
193
|
+
Option.match(tagging, {
|
|
194
|
+
onNone: () => ({ head }),
|
|
195
|
+
onSome: (tagOutput) => ({ head, tagging: tagOutput }),
|
|
196
|
+
}),
|
|
197
|
+
);
|
|
198
|
+
const emptyListObjectsV2Output: S3.ListObjectsV2Output = {
|
|
199
|
+
Contents: [],
|
|
200
|
+
};
|
|
201
|
+
const emptyListObjectVersionsOutput: S3.ListObjectVersionsOutput = {
|
|
202
|
+
Versions: [],
|
|
203
|
+
DeleteMarkers: [],
|
|
204
|
+
};
|
|
205
|
+
return {
|
|
206
|
+
create: Effect.fn("BucketLifecycleService.create")(function* (
|
|
207
|
+
props: BucketProps,
|
|
208
|
+
) {
|
|
209
|
+
yield* createBucket(createBucketRequest(props)).pipe(
|
|
210
|
+
Effect.mapError((cause) => new BucketCreateFailed({ cause })),
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
return bucketStateFromProps(props);
|
|
214
|
+
}),
|
|
215
|
+
read: Effect.fn("BucketLifecycleService.read")(function* (
|
|
216
|
+
props: BucketProps,
|
|
217
|
+
) {
|
|
218
|
+
const head = yield* headBucket({ Bucket: props.Bucket }).pipe(
|
|
219
|
+
Effect.map(Option.some),
|
|
220
|
+
Effect.catchTags({
|
|
221
|
+
NoSuchBucket: () =>
|
|
222
|
+
Effect.succeed(Option.none<S3.HeadBucketOutput>()),
|
|
223
|
+
NotFound: () =>
|
|
224
|
+
Effect.succeed(Option.none<S3.HeadBucketOutput>()),
|
|
225
|
+
}),
|
|
226
|
+
Effect.mapError((cause) => new BucketReadFailed({ cause })),
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
return yield* Option.match(head, {
|
|
230
|
+
onNone: () => Effect.succeed(Option.none<BucketObservedState>()),
|
|
231
|
+
onSome: (headOutput) =>
|
|
232
|
+
getBucketTagging({
|
|
233
|
+
Bucket: props.Bucket,
|
|
234
|
+
}).pipe(
|
|
235
|
+
Effect.map(Option.some),
|
|
236
|
+
Effect.catchTag("NoSuchTagSet", () =>
|
|
237
|
+
Effect.succeed(Option.none<S3.GetBucketTaggingOutput>()),
|
|
238
|
+
),
|
|
239
|
+
Effect.mapError((cause) => new BucketReadFailed({ cause })),
|
|
240
|
+
Effect.map((tagging) =>
|
|
241
|
+
Option.some(bucketObservedState(headOutput, tagging)),
|
|
242
|
+
),
|
|
243
|
+
),
|
|
244
|
+
});
|
|
245
|
+
}),
|
|
246
|
+
destroy: Effect.fn("BucketLifecycleService.destroy")(function* (
|
|
247
|
+
props: BucketProps,
|
|
248
|
+
) {
|
|
249
|
+
const deleteBucketObjects = Effect.fn(
|
|
250
|
+
"BucketLifecycleService.destroy/deleteBucketObjects",
|
|
251
|
+
)(function* (
|
|
252
|
+
bucket: string,
|
|
253
|
+
objects: ReadonlyArray<S3.ObjectIdentifier>,
|
|
254
|
+
) {
|
|
255
|
+
return yield* Option.match(
|
|
256
|
+
Option.liftPredicate(objects, (value) => value.length > 0),
|
|
257
|
+
{
|
|
258
|
+
onNone: () => Effect.succeed(false),
|
|
259
|
+
onSome: (presentObjects) =>
|
|
260
|
+
deleteObjects({
|
|
261
|
+
Bucket: bucket,
|
|
262
|
+
Delete: {
|
|
263
|
+
Objects: Arr.fromIterable(presentObjects),
|
|
264
|
+
},
|
|
265
|
+
}).pipe(
|
|
266
|
+
Effect.mapError(
|
|
267
|
+
(cause) => new BucketEmptyFailed({ cause }),
|
|
268
|
+
),
|
|
269
|
+
Effect.map(() => true),
|
|
270
|
+
),
|
|
271
|
+
},
|
|
272
|
+
);
|
|
273
|
+
});
|
|
274
|
+
const emptyBucketCurrentObjects = Effect.fn(
|
|
275
|
+
"BucketLifecycleService.destroy/emptyBucketCurrentObjects",
|
|
276
|
+
)(function* (bucket: string) {
|
|
277
|
+
const listed = yield* listObjectsV2({ Bucket: bucket }).pipe(
|
|
278
|
+
Effect.catchTag("NoSuchBucket", () =>
|
|
279
|
+
Effect.succeed(emptyListObjectsV2Output),
|
|
280
|
+
),
|
|
281
|
+
Effect.mapError((cause) => new BucketEmptyFailed({ cause })),
|
|
282
|
+
);
|
|
283
|
+
const objects = objectIdentifiersFromList(listed.Contents ?? []);
|
|
284
|
+
|
|
285
|
+
return yield* deleteBucketObjects(bucket, objects);
|
|
286
|
+
});
|
|
287
|
+
const emptyBucketVersions = Effect.fn(
|
|
288
|
+
"BucketLifecycleService.destroy/emptyBucketVersions",
|
|
289
|
+
)(function* (bucket: string) {
|
|
290
|
+
const listed = yield* listObjectVersions({ Bucket: bucket }).pipe(
|
|
291
|
+
Effect.catchTag("NoSuchBucket", () =>
|
|
292
|
+
Effect.succeed(emptyListObjectVersionsOutput),
|
|
293
|
+
),
|
|
294
|
+
Effect.mapError((cause) => new BucketEmptyFailed({ cause })),
|
|
295
|
+
);
|
|
296
|
+
const objects = versionIdentifiersFromList(
|
|
297
|
+
Arr.appendAll(listed.Versions ?? [], listed.DeleteMarkers ?? []),
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
return yield* deleteBucketObjects(bucket, objects);
|
|
301
|
+
});
|
|
302
|
+
const emptyBucketContents = (bucket: string) =>
|
|
303
|
+
Effect.repeat(emptyBucketVersions(bucket), {
|
|
304
|
+
while: (deletedObjects) => deletedObjects,
|
|
305
|
+
}).pipe(
|
|
306
|
+
Effect.andThen(() =>
|
|
307
|
+
Effect.repeat(emptyBucketCurrentObjects(bucket), {
|
|
308
|
+
while: (deletedObjects) => deletedObjects,
|
|
309
|
+
}),
|
|
310
|
+
),
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
yield* Option.match(
|
|
314
|
+
Option.liftPredicate(props, bucketForceDestroyEnabled),
|
|
315
|
+
{
|
|
316
|
+
onNone: () => Effect.void,
|
|
317
|
+
onSome: () => emptyBucketContents(props.Bucket),
|
|
318
|
+
},
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
yield* deleteBucket({ Bucket: props.Bucket }).pipe(
|
|
322
|
+
Effect.catchTag("NoSuchBucket", () => Effect.void),
|
|
323
|
+
Effect.mapError((cause) => new BucketDeleteFailed({ cause })),
|
|
324
|
+
);
|
|
325
|
+
}),
|
|
326
|
+
};
|
|
327
|
+
}),
|
|
328
|
+
},
|
|
329
|
+
) {}
|