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 CHANGED
@@ -60,13 +60,53 @@ R2_DOCUMENTS_SECRET_ACCESS_KEY=""
60
60
 
61
61
  ## ⚡ API
62
62
 
63
- | function | description |
64
- | ------------------------------------------------- | ----------------------------------------------------------------------------------------- |
65
- | [`uploadFile`](./README.md#-uploadfile) | Adds a file to the specified bucket |
66
- | [`getFileUrl`](./README.md#-getfileurl) | Gets a pre-signed url to fetch a ressource by its `filename` from the specified `bucket`. |
67
- | [`readAsJson`](./README.md#-readasjson) | Fetches a file, expecting a content extending `Record<string, unknown>`. |
68
- | [`readAsText`](./README.md#-readastext) | Fetches a file as a string. |
69
- | [`readAsRawBinary`](./README.md#-readasrawbinary) | Fetches a file as raw binary (ArrayBuffer). |
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
- bucketName,
85
- documentKey,
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
- never
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: <TBucket extends string, TShape extends Record<string, unknown>>(
172
- bucketName: TBucket,
173
- documentKey: string
174
- ) =>
175
- Effect.Effect<
176
- TShape,
177
- ConfigError | HttpClientError | FileStorageError,
178
- Scope | HttpClient.HttpClient.Service
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.HttpClient.Service
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.HttpClient.Service
314
+ Scope | HttpClient.Service | FileStorage
276
315
  >;
277
316
  ```
278
317
 
@@ -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';
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect-cloudflare-r2-layer",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "author": "jpb06 <jp.bois.06@outlook.fr>",
5
5
  "description": "An effect layer to interact with Cloudware R2 storage service",
6
6
  "keywords": [