effect-cloudflare-r2-layer 1.0.8 → 1.0.9
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +65 -26
- package/dts/cjs/index.d.ts +1 -1
- package/dts/esm/index.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
@@ -60,13 +60,53 @@ R2_DOCUMENTS_SECRET_ACCESS_KEY=""
|
|
60
60
|
|
61
61
|
## ⚡ API
|
62
62
|
|
63
|
-
| function
|
64
|
-
|
|
65
|
-
| [`
|
66
|
-
| [`
|
67
|
-
| [`
|
68
|
-
| [`
|
69
|
-
| [`
|
63
|
+
| function | description |
|
64
|
+
| -------------------------------------- | ----------------------------------------------------------------------------------------- |
|
65
|
+
| [`createBucket`](#-createbucket) | Create a bucket |
|
66
|
+
| [`uploadFile`](#-uploadfile) | Adds a file to the specified bucket |
|
67
|
+
| [`getFileUrl`](#-getfileurl) | Gets a pre-signed url to fetch a ressource by its `filename` from the specified `bucket`. |
|
68
|
+
| [`readAsJson`](#-readasjson) | Fetches a file, expecting a content extending `Record<string, unknown>`. |
|
69
|
+
| [`readAsText`](#-readastext) | Fetches a file as a string. |
|
70
|
+
| [`readAsRawBinary`](#-readasrawbinary) | Fetches a file as raw binary (ArrayBuffer). |
|
71
|
+
|
72
|
+
### 🔶 `createBucket`
|
73
|
+
|
74
|
+
```typescript
|
75
|
+
type createBucket = (
|
76
|
+
input: CreateBucketCommandInput
|
77
|
+
) => Effect.Effect<
|
78
|
+
CreateBucketCommandOutput,
|
79
|
+
FileStorageError | ConfigError.ConfigError,
|
80
|
+
FileStorage
|
81
|
+
>;
|
82
|
+
```
|
83
|
+
|
84
|
+
#### 🧿 Example
|
85
|
+
|
86
|
+
```typescript
|
87
|
+
import { Effect, pipe } from 'effect';
|
88
|
+
import {
|
89
|
+
CloudflareR2StorageLayerLive,
|
90
|
+
FileStorageLayer,
|
91
|
+
} from 'effect-cloudflare-r2-layer';
|
92
|
+
|
93
|
+
const task = pipe(
|
94
|
+
Effect.gen(function* () {
|
95
|
+
const result = yield* FileStorageLayer.createBucket({
|
96
|
+
Bucket: 'test',
|
97
|
+
CreateBucketConfiguration: {
|
98
|
+
Bucket: {
|
99
|
+
Type: 'Directory',
|
100
|
+
DataRedundancy: 'SingleAvailabilityZone',
|
101
|
+
},
|
102
|
+
},
|
103
|
+
});
|
104
|
+
|
105
|
+
// ...
|
106
|
+
}),
|
107
|
+
Effect.provide(CloudflareR2StorageLayerLive)
|
108
|
+
);
|
109
|
+
```
|
70
110
|
|
71
111
|
### 🔶 `uploadFile`
|
72
112
|
|
@@ -80,15 +120,12 @@ interface UploadFileInput<TBucket extends string> {
|
|
80
120
|
contentType: string | undefined;
|
81
121
|
}
|
82
122
|
|
83
|
-
type uploadFile = <TBucket extends string>(
|
84
|
-
|
85
|
-
|
86
|
-
data,
|
87
|
-
contentType,
|
88
|
-
}: UploadFileInput<TBucket>) => Effect.Effect<
|
123
|
+
type uploadFile = <TBucket extends string>(
|
124
|
+
input: UploadFileInput<TBucket>
|
125
|
+
) => Effect.Effect<
|
89
126
|
PutObjectCommandOutput,
|
90
|
-
FileStorageError | ConfigError,
|
91
|
-
|
127
|
+
FileStorageError | ConfigError.ConfigError,
|
128
|
+
FileStorage
|
92
129
|
>;
|
93
130
|
```
|
94
131
|
|
@@ -168,15 +205,17 @@ const task = pipe(
|
|
168
205
|
Fetches a file, expecting a content extending `Record<string, unknown>`.
|
169
206
|
|
170
207
|
```typescript
|
171
|
-
readAsJson
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
208
|
+
type readAsJson = <
|
209
|
+
TBucket extends string,
|
210
|
+
TShape extends Record<string, unknown>
|
211
|
+
>(
|
212
|
+
bucket: TBucket,
|
213
|
+
fileName: string
|
214
|
+
) => Effect.Effect<
|
215
|
+
TShape,
|
216
|
+
HttpClientError | FileStorageError | ConfigError.ConfigError,
|
217
|
+
Scope | HttpClient.Service | FileStorage
|
218
|
+
>;
|
180
219
|
```
|
181
220
|
|
182
221
|
#### 🧿 Example
|
@@ -226,7 +265,7 @@ readAsText: <TBucket extends string>(
|
|
226
265
|
Effect.Effect<
|
227
266
|
string,
|
228
267
|
ConfigError | HttpClientError | FileStorageError,
|
229
|
-
Scope | HttpClient.
|
268
|
+
Scope | HttpClient.Service | FileStorage
|
230
269
|
>;
|
231
270
|
```
|
232
271
|
|
@@ -272,7 +311,7 @@ readAsRawBinary: <TBucket extends string>(
|
|
272
311
|
Effect.Effect<
|
273
312
|
ArrayBuffer,
|
274
313
|
ConfigError | HttpClientError | FileStorageError,
|
275
|
-
Scope | HttpClient.
|
314
|
+
Scope | HttpClient.Service | FileStorage
|
276
315
|
>;
|
277
316
|
```
|
278
317
|
|
package/dts/cjs/index.d.ts
CHANGED
@@ -3,4 +3,4 @@ import { FileStorageLayer } from './layer/file-storage.layer.js';
|
|
3
3
|
export { FileStorageLayer };
|
4
4
|
export type { FileStorage };
|
5
5
|
export * from './r2/r2-file-storage.layer.js';
|
6
|
-
export type { PutObjectCommandOutput } from '@aws-sdk/client-s3';
|
6
|
+
export type { PutObjectCommandOutput, CreateBucketCommandInput, CreateBucketCommandOutput, } from '@aws-sdk/client-s3';
|
package/dts/esm/index.d.ts
CHANGED
@@ -3,4 +3,4 @@ import { FileStorageLayer } from './layer/file-storage.layer.js';
|
|
3
3
|
export { FileStorageLayer };
|
4
4
|
export type { FileStorage };
|
5
5
|
export * from './r2/r2-file-storage.layer.js';
|
6
|
-
export type { PutObjectCommandOutput } from '@aws-sdk/client-s3';
|
6
|
+
export type { PutObjectCommandOutput, CreateBucketCommandInput, CreateBucketCommandOutput, } from '@aws-sdk/client-s3';
|