alchemy 0.5.0 → 0.5.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/lib/apply.js +0 -8
- package/lib/cloudflare/bucket.d.ts +16 -2
- package/lib/cloudflare/bucket.js +15 -6
- package/package.json +1 -1
- package/src/apply.ts +0 -9
- package/src/cloudflare/bucket.ts +24 -9
package/lib/apply.js
CHANGED
|
@@ -48,14 +48,6 @@ export async function apply(resource, props, options) {
|
|
|
48
48
|
}
|
|
49
49
|
return state.output;
|
|
50
50
|
}
|
|
51
|
-
const diff = await import("diff");
|
|
52
|
-
const yaml = await import("yaml");
|
|
53
|
-
const old = yaml.stringify(oldProps);
|
|
54
|
-
const news = yaml.stringify(newProps);
|
|
55
|
-
const patch = diff.createPatch(resource.ID, old, news);
|
|
56
|
-
// console.log(patch);
|
|
57
|
-
// if (resource.ID === "what-is-alchemy") {
|
|
58
|
-
// }
|
|
59
51
|
}
|
|
60
52
|
const phase = state.status === "creating" ? "create" : "update";
|
|
61
53
|
state.status = phase === "create" ? "creating" : "updating";
|
|
@@ -28,11 +28,17 @@ export interface BucketProps extends CloudflareApiOptions {
|
|
|
28
28
|
*/
|
|
29
29
|
allowPublicAccess?: boolean;
|
|
30
30
|
/**
|
|
31
|
-
* Whether to delete the bucket
|
|
31
|
+
* Whether to delete the bucket.
|
|
32
32
|
* If set to false, the bucket will remain but the resource will be removed from state
|
|
33
|
-
*
|
|
33
|
+
*
|
|
34
|
+
* @default true
|
|
34
35
|
*/
|
|
35
36
|
delete?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Whether to empty the bucket and delete all objects during resource deletion
|
|
39
|
+
* @default false
|
|
40
|
+
*/
|
|
41
|
+
empty?: boolean;
|
|
36
42
|
}
|
|
37
43
|
/**
|
|
38
44
|
* Output returned after R2 Bucket creation/update
|
|
@@ -85,6 +91,14 @@ export interface R2Bucket extends Resource<"cloudflare::R2Bucket">, BucketProps
|
|
|
85
91
|
* jurisdiction: "fedramp"
|
|
86
92
|
* });
|
|
87
93
|
*
|
|
94
|
+
* @example
|
|
95
|
+
* // Create a bucket that will be automatically emptied when deleted
|
|
96
|
+
* // This will delete all objects in the bucket before deleting the bucket itself
|
|
97
|
+
* const temporaryBucket = await R2Bucket("temp-storage", {
|
|
98
|
+
* name: "temp-storage",
|
|
99
|
+
* empty: true // All objects will be deleted when this resource is destroyed
|
|
100
|
+
* });
|
|
101
|
+
*
|
|
88
102
|
* @see https://developers.cloudflare.com/r2/buckets/
|
|
89
103
|
*/
|
|
90
104
|
export declare const R2Bucket: (((this: any, id: string, props?: {}) => never) & (new (_: never) => never)) | ((this: Context<R2Bucket>, id: string, props: BucketProps) => Promise<R2Bucket>);
|
package/lib/cloudflare/bucket.js
CHANGED
|
@@ -35,19 +35,28 @@ import { CloudflareAccountId, CloudflareApi, CloudflareApiError, createCloudflar
|
|
|
35
35
|
* jurisdiction: "fedramp"
|
|
36
36
|
* });
|
|
37
37
|
*
|
|
38
|
+
* @example
|
|
39
|
+
* // Create a bucket that will be automatically emptied when deleted
|
|
40
|
+
* // This will delete all objects in the bucket before deleting the bucket itself
|
|
41
|
+
* const temporaryBucket = await R2Bucket("temp-storage", {
|
|
42
|
+
* name: "temp-storage",
|
|
43
|
+
* empty: true // All objects will be deleted when this resource is destroyed
|
|
44
|
+
* });
|
|
45
|
+
*
|
|
38
46
|
* @see https://developers.cloudflare.com/r2/buckets/
|
|
39
47
|
*/
|
|
40
48
|
export const R2Bucket = Resource("cloudflare::R2Bucket", async function (id, props) {
|
|
41
|
-
const
|
|
42
|
-
createCloudflareApi(props),
|
|
43
|
-
createR2Client(props),
|
|
44
|
-
]);
|
|
49
|
+
const api = await createCloudflareApi(props);
|
|
45
50
|
const bucketName = props.name || this.id;
|
|
46
51
|
if (this.phase === "delete") {
|
|
47
52
|
console.log("Deleting R2 bucket:", bucketName);
|
|
48
53
|
if (props.delete !== false) {
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
if (props.empty) {
|
|
55
|
+
console.log("Emptying R2 bucket:", bucketName);
|
|
56
|
+
const r2Client = await createR2Client(props);
|
|
57
|
+
// Empty the bucket first by deleting all objects
|
|
58
|
+
await emptyBucket(r2Client, bucketName, props.jurisdiction);
|
|
59
|
+
}
|
|
51
60
|
// Delete R2 bucket
|
|
52
61
|
console.log("Deleting R2 bucket:", bucketName);
|
|
53
62
|
await deleteBucket(api, bucketName, props);
|
package/package.json
CHANGED
package/src/apply.ts
CHANGED
|
@@ -70,15 +70,6 @@ export async function apply<Out extends Resource>(
|
|
|
70
70
|
}
|
|
71
71
|
return state.output as Awaited<Out>;
|
|
72
72
|
}
|
|
73
|
-
|
|
74
|
-
const diff = await import("diff");
|
|
75
|
-
const yaml = await import("yaml");
|
|
76
|
-
const old = yaml.stringify(oldProps);
|
|
77
|
-
const news = yaml.stringify(newProps);
|
|
78
|
-
const patch = diff.createPatch(resource.ID, old, news);
|
|
79
|
-
// console.log(patch);
|
|
80
|
-
// if (resource.ID === "what-is-alchemy") {
|
|
81
|
-
// }
|
|
82
73
|
}
|
|
83
74
|
|
|
84
75
|
const phase = state.status === "creating" ? "create" : "update";
|
package/src/cloudflare/bucket.ts
CHANGED
|
@@ -40,11 +40,18 @@ export interface BucketProps extends CloudflareApiOptions {
|
|
|
40
40
|
allowPublicAccess?: boolean;
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
|
-
* Whether to delete the bucket
|
|
43
|
+
* Whether to delete the bucket.
|
|
44
44
|
* If set to false, the bucket will remain but the resource will be removed from state
|
|
45
|
-
*
|
|
45
|
+
*
|
|
46
|
+
* @default true
|
|
46
47
|
*/
|
|
47
48
|
delete?: boolean;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Whether to empty the bucket and delete all objects during resource deletion
|
|
52
|
+
* @default false
|
|
53
|
+
*/
|
|
54
|
+
empty?: boolean;
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
/**
|
|
@@ -103,6 +110,14 @@ export interface R2Bucket
|
|
|
103
110
|
* jurisdiction: "fedramp"
|
|
104
111
|
* });
|
|
105
112
|
*
|
|
113
|
+
* @example
|
|
114
|
+
* // Create a bucket that will be automatically emptied when deleted
|
|
115
|
+
* // This will delete all objects in the bucket before deleting the bucket itself
|
|
116
|
+
* const temporaryBucket = await R2Bucket("temp-storage", {
|
|
117
|
+
* name: "temp-storage",
|
|
118
|
+
* empty: true // All objects will be deleted when this resource is destroyed
|
|
119
|
+
* });
|
|
120
|
+
*
|
|
106
121
|
* @see https://developers.cloudflare.com/r2/buckets/
|
|
107
122
|
*/
|
|
108
123
|
export const R2Bucket = Resource(
|
|
@@ -112,18 +127,18 @@ export const R2Bucket = Resource(
|
|
|
112
127
|
id: string,
|
|
113
128
|
props: BucketProps
|
|
114
129
|
): Promise<R2Bucket> {
|
|
115
|
-
const
|
|
116
|
-
createCloudflareApi(props),
|
|
117
|
-
createR2Client(props),
|
|
118
|
-
]);
|
|
119
|
-
|
|
130
|
+
const api = await createCloudflareApi(props);
|
|
120
131
|
const bucketName = props.name || this.id;
|
|
121
132
|
|
|
122
133
|
if (this.phase === "delete") {
|
|
123
134
|
console.log("Deleting R2 bucket:", bucketName);
|
|
124
135
|
if (props.delete !== false) {
|
|
125
|
-
|
|
126
|
-
|
|
136
|
+
if (props.empty) {
|
|
137
|
+
console.log("Emptying R2 bucket:", bucketName);
|
|
138
|
+
const r2Client = await createR2Client(props);
|
|
139
|
+
// Empty the bucket first by deleting all objects
|
|
140
|
+
await emptyBucket(r2Client, bucketName, props.jurisdiction);
|
|
141
|
+
}
|
|
127
142
|
|
|
128
143
|
// Delete R2 bucket
|
|
129
144
|
console.log("Deleting R2 bucket:", bucketName);
|