effect-cloudflare-r2-layer 1.0.7 → 1.0.9

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/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
 
@@ -5,6 +5,7 @@ const effect_1 = require("effect");
5
5
  const tapLayer_effect_js_1 = require("./../effects/tapLayer.effect.js");
6
6
  exports.FileStorageLayerContext = effect_1.Context.GenericTag('file-storage');
7
7
  exports.FileStorageLayer = {
8
+ createBucket: (input) => (0, tapLayer_effect_js_1.tapLayer)(exports.FileStorageLayerContext, ({ createBucket }) => createBucket(input)),
8
9
  getFileUrl: (bucket, fileName) => (0, tapLayer_effect_js_1.tapLayer)(exports.FileStorageLayerContext, ({ getFileUrl }) => getFileUrl(bucket, fileName)),
9
10
  readAsRawBinary: (bucket, fileName) => (0, tapLayer_effect_js_1.tapLayer)(exports.FileStorageLayerContext, ({ readAsRawBinary }) => readAsRawBinary(bucket, fileName)),
10
11
  readAsJson: (bucket, fileName) => (0, tapLayer_effect_js_1.tapLayer)(exports.FileStorageLayerContext, ({ readAsJson }) => readAsJson(bucket, fileName)),
@@ -1 +1 @@
1
- {"version":3,"file":"file-storage.layer.js","sourceRoot":"","sources":["../../../src/layer/file-storage.layer.ts"],"names":[],"mappings":";;;AAEA,mCAAiC;AAOjC,wEAA2D;AA8C9C,QAAA,uBAAuB,GAClC,gBAAO,CAAC,UAAU,CAAc,cAAc,CAAC,CAAC;AAErC,QAAA,gBAAgB,GAAG;IAC9B,UAAU,EAAE,CAAyB,MAAe,EAAE,QAAgB,EAAE,EAAE,CACxE,IAAA,6BAAQ,EAAC,+BAAuB,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CACnD,UAAU,CAA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AAE,EAAE,EAAE,CACnD,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC,CAC7B;IACH,eAAe,EAAE,CACf,MAAe,EACf,QAAgB,EAChB,EAAE,CACF,IAAA,6BAAQ,EAAC,+BAAuB,EAAE,CAAC,EAAE,eAAe,EAAE,EAAE,EAAE,CACxD,eAAe,CAAC,MAAM,EAAE,QAAQ,CAAC,CAClC;IACH,UAAU,EAAE,CACV,MAAe,EACf,QAAgB,EAChB,EAAE,CACF,IAAA,6BAAQ,EAAC,+BAAuB,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CACnD,UAAU,CAAkB,MAAM,EAAE,QAAQ,CAAC,CAC9C;IACH,UAAU,EAAE,CAAyB,MAAe,EAAE,QAAgB,EAAE,EAAE,CACxE,IAAA,6BAAQ,EAAC,+BAAuB,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CACnD,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC,CAC7B;IACH,UAAU,EAAE,CAAyB,KAA+B,EAAE,EAAE,CACtE,IAAA,6BAAQ,EAAC,+BAAuB,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;CAC3E,CAAC"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createBucket = void 0;
4
+ const client_s3_1 = require("@aws-sdk/client-s3");
5
+ const effect_1 = require("effect");
6
+ const file_storage_error_js_1 = require("../../errors/file-storage.error.js");
7
+ const r2_file_storage_provider_js_1 = require("../providers/r2-file-storage.provider.js");
8
+ const createBucket = (input) => effect_1.Effect.withSpan('create-bucket', { attributes: { ...input } })((0, effect_1.pipe)(r2_file_storage_provider_js_1.cloudflareR2StorageProvider, effect_1.Effect.flatMap((provider) => effect_1.Effect.tryPromise({
9
+ try: () => provider.send(new client_s3_1.CreateBucketCommand(input)),
10
+ catch: (e) => new file_storage_error_js_1.FileStorageError({ cause: e }),
11
+ }))));
12
+ exports.createBucket = createBucket;
13
+ //# sourceMappingURL=create-bucket.effect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-bucket.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/create-bucket.effect.ts"],"names":[],"mappings":";;;AAAA,kDAG4B;AAC5B,mCAAsC;AAEtC,8EAAsE;AACtE,0FAAuF;AAEhF,MAAM,YAAY,GAAG,CAAC,KAA+B,EAAE,EAAE,CAC9D,eAAM,CAAC,QAAQ,CAAC,eAAe,EAAE,EAAE,UAAU,EAAE,EAAE,GAAG,KAAK,EAAE,EAAE,CAAC,CAC5D,IAAA,aAAI,EACF,yDAA2B,EAC3B,eAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAC1B,eAAM,CAAC,UAAU,CAAC;IAChB,GAAG,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,+BAAmB,CAAC,KAAK,CAAC,CAAC;IACxD,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,wCAAgB,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;CACjD,CAAC,CACH,CACF,CACF,CAAC;AAXS,QAAA,YAAY,gBAWrB"}
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./create-bucket.effect.js"), exports);
17
18
  __exportStar(require("./get-file-url.effect.js"), exports);
18
19
  __exportStar(require("./upload-file.effect.js"), exports);
19
20
  __exportStar(require("./read-as-json.effect.js"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/r2/implementations/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2DAAyC;AACzC,0DAAwC;AACxC,2DAAyC;AACzC,iEAA+C;AAC/C,2DAAyC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/r2/implementations/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,2DAAyC;AACzC,0DAAwC;AACxC,2DAAyC;AACzC,iEAA+C;AAC/C,2DAAyC"}
@@ -5,6 +5,7 @@ const effect_1 = require("effect");
5
5
  const file_storage_layer_js_1 = require("../layer/file-storage.layer.js");
6
6
  const index_js_1 = require("./implementations/index.js");
7
7
  exports.CloudflareR2StorageLayerLive = effect_1.Layer.succeed(file_storage_layer_js_1.FileStorageLayerContext, file_storage_layer_js_1.FileStorageLayerContext.of({
8
+ createBucket: index_js_1.createBucket,
8
9
  getFileUrl: index_js_1.getFileUrl,
9
10
  uploadFile: index_js_1.uploadFile,
10
11
  readAsText: index_js_1.readAsText,
@@ -1 +1 @@
1
- {"version":3,"file":"r2-file-storage.layer.js","sourceRoot":"","sources":["../../../src/r2/r2-file-storage.layer.ts"],"names":[],"mappings":";;;AAAA,mCAA+B;AAE/B,0EAAyE;AACzE,yDAMoC;AAEvB,QAAA,4BAA4B,GAAG,cAAK,CAAC,OAAO,CACvD,+CAAuB,EACvB,+CAAuB,CAAC,EAAE,CAAC;IACzB,UAAU,EAAV,qBAAU;IACV,UAAU,EAAV,qBAAU;IACV,UAAU,EAAV,qBAAU;IACV,UAAU,EAAV,qBAAU;IACV,eAAe,EAAf,0BAAe;CAChB,CAAC,CACH,CAAC"}
1
+ {"version":3,"file":"r2-file-storage.layer.js","sourceRoot":"","sources":["../../../src/r2/r2-file-storage.layer.ts"],"names":[],"mappings":";;;AAAA,mCAA+B;AAE/B,0EAAyE;AACzE,yDAOoC;AAEvB,QAAA,4BAA4B,GAAG,cAAK,CAAC,OAAO,CACvD,+CAAuB,EACvB,+CAAuB,CAAC,EAAE,CAAC;IACzB,YAAY,EAAZ,uBAAY;IACZ,UAAU,EAAV,qBAAU;IACV,UAAU,EAAV,qBAAU;IACV,UAAU,EAAV,qBAAU;IACV,UAAU,EAAV,qBAAU;IACV,eAAe,EAAf,0BAAe;CAChB,CAAC,CACH,CAAC"}
@@ -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';
@@ -1,12 +1,13 @@
1
1
  import { HttpClientError } from '@effect/platform/HttpClientError';
2
2
  import type { ConfigError, Effect } from 'effect';
3
3
  import { Context } from 'effect';
4
- import { PutObjectCommandOutput } from '@aws-sdk/client-s3';
4
+ import { CreateBucketCommandInput, CreateBucketCommandOutput, PutObjectCommandOutput } from '@aws-sdk/client-s3';
5
5
  import { HttpClient } from '@effect/platform';
6
6
  import { Scope } from 'effect/Scope';
7
7
  import type { FileStorageError } from '../errors/file-storage.error.js';
8
8
  import type { UploadFileInput } from '../r2/implementations/index.js';
9
9
  export interface FileStorage {
10
+ readonly createBucket: (input: CreateBucketCommandInput) => Effect.Effect<CreateBucketCommandOutput, ConfigError.ConfigError | FileStorageError, never>;
10
11
  readonly getFileUrl: <TBucket extends string>(fileName: string, bucket: TBucket) => Effect.Effect<string, FileStorageError | ConfigError.ConfigError>;
11
12
  readonly readAsRawBinary: <TBucket extends string>(bucketName: TBucket, documentKey: string) => Effect.Effect<ArrayBuffer, ConfigError.ConfigError | HttpClientError | FileStorageError, Scope | HttpClient.HttpClient.Service>;
12
13
  readonly readAsJson: <TBucket extends string, TShape extends Record<string, unknown>>(bucketName: TBucket, documentKey: string) => Effect.Effect<TShape, ConfigError.ConfigError | HttpClientError | FileStorageError, Scope | HttpClient.HttpClient.Service>;
@@ -15,6 +16,7 @@ export interface FileStorage {
15
16
  }
16
17
  export declare const FileStorageLayerContext: Context.Tag<FileStorage, FileStorage>;
17
18
  export declare const FileStorageLayer: {
19
+ createBucket: (input: CreateBucketCommandInput) => Effect.Effect<CreateBucketCommandOutput, FileStorageError | ConfigError.ConfigError, FileStorage>;
18
20
  getFileUrl: <TBucket extends string>(bucket: TBucket, fileName: string) => Effect.Effect<string, FileStorageError | ConfigError.ConfigError, FileStorage>;
19
21
  readAsRawBinary: <TBucket extends string>(bucket: TBucket, fileName: string) => Effect.Effect<ArrayBuffer, FileStorageError | ConfigError.ConfigError | HttpClientError, Scope | HttpClient.HttpClient.Service | FileStorage>;
20
22
  readAsJson: <TBucket extends string, TShape extends Record<string, unknown>>(bucket: TBucket, fileName: string) => Effect.Effect<TShape, FileStorageError | ConfigError.ConfigError | HttpClientError, Scope | HttpClient.HttpClient.Service | FileStorage>;
@@ -0,0 +1,4 @@
1
+ import { CreateBucketCommandInput } from '@aws-sdk/client-s3';
2
+ import { Effect } from 'effect';
3
+ import { FileStorageError } from '../../errors/file-storage.error.js';
4
+ export declare const createBucket: (input: CreateBucketCommandInput) => Effect.Effect<import("@aws-sdk/client-s3").CreateBucketCommandOutput, FileStorageError | import("effect/ConfigError").ConfigError, never>;
@@ -1,3 +1,4 @@
1
+ export * from './create-bucket.effect.js';
1
2
  export * from './get-file-url.effect.js';
2
3
  export * from './upload-file.effect.js';
3
4
  export * from './read-as-json.effect.js';
@@ -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';
@@ -1,12 +1,13 @@
1
1
  import { HttpClientError } from '@effect/platform/HttpClientError';
2
2
  import type { ConfigError, Effect } from 'effect';
3
3
  import { Context } from 'effect';
4
- import { PutObjectCommandOutput } from '@aws-sdk/client-s3';
4
+ import { CreateBucketCommandInput, CreateBucketCommandOutput, PutObjectCommandOutput } from '@aws-sdk/client-s3';
5
5
  import { HttpClient } from '@effect/platform';
6
6
  import { Scope } from 'effect/Scope';
7
7
  import type { FileStorageError } from '../errors/file-storage.error.js';
8
8
  import type { UploadFileInput } from '../r2/implementations/index.js';
9
9
  export interface FileStorage {
10
+ readonly createBucket: (input: CreateBucketCommandInput) => Effect.Effect<CreateBucketCommandOutput, ConfigError.ConfigError | FileStorageError, never>;
10
11
  readonly getFileUrl: <TBucket extends string>(fileName: string, bucket: TBucket) => Effect.Effect<string, FileStorageError | ConfigError.ConfigError>;
11
12
  readonly readAsRawBinary: <TBucket extends string>(bucketName: TBucket, documentKey: string) => Effect.Effect<ArrayBuffer, ConfigError.ConfigError | HttpClientError | FileStorageError, Scope | HttpClient.HttpClient.Service>;
12
13
  readonly readAsJson: <TBucket extends string, TShape extends Record<string, unknown>>(bucketName: TBucket, documentKey: string) => Effect.Effect<TShape, ConfigError.ConfigError | HttpClientError | FileStorageError, Scope | HttpClient.HttpClient.Service>;
@@ -15,6 +16,7 @@ export interface FileStorage {
15
16
  }
16
17
  export declare const FileStorageLayerContext: Context.Tag<FileStorage, FileStorage>;
17
18
  export declare const FileStorageLayer: {
19
+ createBucket: (input: CreateBucketCommandInput) => Effect.Effect<CreateBucketCommandOutput, FileStorageError | ConfigError.ConfigError, FileStorage>;
18
20
  getFileUrl: <TBucket extends string>(bucket: TBucket, fileName: string) => Effect.Effect<string, FileStorageError | ConfigError.ConfigError, FileStorage>;
19
21
  readAsRawBinary: <TBucket extends string>(bucket: TBucket, fileName: string) => Effect.Effect<ArrayBuffer, FileStorageError | ConfigError.ConfigError | HttpClientError, Scope | HttpClient.HttpClient.Service | FileStorage>;
20
22
  readAsJson: <TBucket extends string, TShape extends Record<string, unknown>>(bucket: TBucket, fileName: string) => Effect.Effect<TShape, FileStorageError | ConfigError.ConfigError | HttpClientError, Scope | HttpClient.HttpClient.Service | FileStorage>;
@@ -0,0 +1,4 @@
1
+ import { CreateBucketCommandInput } from '@aws-sdk/client-s3';
2
+ import { Effect } from 'effect';
3
+ import { FileStorageError } from '../../errors/file-storage.error.js';
4
+ export declare const createBucket: (input: CreateBucketCommandInput) => Effect.Effect<import("@aws-sdk/client-s3").CreateBucketCommandOutput, FileStorageError | import("effect/ConfigError").ConfigError, never>;
@@ -1,3 +1,4 @@
1
+ export * from './create-bucket.effect.js';
1
2
  export * from './get-file-url.effect.js';
2
3
  export * from './upload-file.effect.js';
3
4
  export * from './read-as-json.effect.js';
@@ -2,6 +2,7 @@ import { Context } from 'effect';
2
2
  import { tapLayer } from './../effects/tapLayer.effect.js';
3
3
  export const FileStorageLayerContext = Context.GenericTag('file-storage');
4
4
  export const FileStorageLayer = {
5
+ createBucket: (input) => tapLayer(FileStorageLayerContext, ({ createBucket }) => createBucket(input)),
5
6
  getFileUrl: (bucket, fileName) => tapLayer(FileStorageLayerContext, ({ getFileUrl }) => getFileUrl(bucket, fileName)),
6
7
  readAsRawBinary: (bucket, fileName) => tapLayer(FileStorageLayerContext, ({ readAsRawBinary }) => readAsRawBinary(bucket, fileName)),
7
8
  readAsJson: (bucket, fileName) => tapLayer(FileStorageLayerContext, ({ readAsJson }) => readAsJson(bucket, fileName)),
@@ -1 +1 @@
1
- {"version":3,"file":"file-storage.layer.js","sourceRoot":"","sources":["../../../src/layer/file-storage.layer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAOjC,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AA8C3D,MAAM,CAAC,MAAM,uBAAuB,GAClC,OAAO,CAAC,UAAU,CAAc,cAAc,CAAC,CAAC;AAElD,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,UAAU,EAAE,CAAyB,MAAe,EAAE,QAAgB,EAAE,EAAE,CACxE,QAAQ,CAAC,uBAAuB,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CACnD,UAAU,CAAC,MAAM,EA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AAC,uBAAuB,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CACnD,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC,CAC7B;IACH,eAAe,EAAE,CACf,MAAe,EACf,QAAgB,EAChB,EAAE,CACF,QAAQ,CAAC,uBAAuB,EAAE,CAAC,EAAE,eAAe,EAAE,EAAE,EAAE,CACxD,eAAe,CAAC,MAAM,EAAE,QAAQ,CAAC,CAClC;IACH,UAAU,EAAE,CACV,MAAe,EACf,QAAgB,EAChB,EAAE,CACF,QAAQ,CAAC,uBAAuB,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CACnD,UAAU,CAAkB,MAAM,EAAE,QAAQ,CAAC,CAC9C;IACH,UAAU,EAAE,CAAyB,MAAe,EAAE,QAAgB,EAAE,EAAE,CACxE,QAAQ,CAAC,uBAAuB,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CACnD,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC,CAC7B;IACH,UAAU,EAAE,CAAyB,KAA+B,EAAE,EAAE,CACtE,QAAQ,CAAC,uBAAuB,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;CAC3E,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { CreateBucketCommand, } from '@aws-sdk/client-s3';
2
+ import { Effect, pipe } from 'effect';
3
+ import { FileStorageError } from '../../errors/file-storage.error.js';
4
+ import { cloudflareR2StorageProvider } from '../providers/r2-file-storage.provider.js';
5
+ export const createBucket = (input) => Effect.withSpan('create-bucket', { attributes: { ...input } })(pipe(cloudflareR2StorageProvider, Effect.flatMap((provider) => Effect.tryPromise({
6
+ try: () => provider.send(new CreateBucketCommand(input)),
7
+ catch: (e) => new FileStorageError({ cause: e }),
8
+ }))));
9
+ //# sourceMappingURL=create-bucket.effect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-bucket.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/create-bucket.effect.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,GAEpB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACtE,OAAO,EAAE,2BAA2B,EAAE,MAAM,0CAA0C,CAAC;AAEvF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAA+B,EAAE,EAAE,CAC9D,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE,EAAE,UAAU,EAAE,EAAE,GAAG,KAAK,EAAE,EAAE,CAAC,CAC5D,IAAI,CACF,2BAA2B,EAC3B,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAC1B,MAAM,CAAC,UAAU,CAAC;IAChB,GAAG,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,mBAAmB,CAAC,KAAK,CAAC,CAAC;IACxD,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,gBAAgB,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;CACjD,CAAC,CACH,CACF,CACF,CAAC"}
@@ -1,3 +1,4 @@
1
+ export * from './create-bucket.effect.js';
1
2
  export * from './get-file-url.effect.js';
2
3
  export * from './upload-file.effect.js';
3
4
  export * from './read-as-json.effect.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/r2/implementations/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/r2/implementations/index.ts"],"names":[],"mappings":"AAAA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC"}
@@ -1,7 +1,8 @@
1
1
  import { Layer } from 'effect';
2
2
  import { FileStorageLayerContext } from '../layer/file-storage.layer.js';
3
- import { getFileUrl, readAsJson, readAsRawBinary, readAsText, uploadFile, } from './implementations/index.js';
3
+ import { createBucket, getFileUrl, readAsJson, readAsRawBinary, readAsText, uploadFile, } from './implementations/index.js';
4
4
  export const CloudflareR2StorageLayerLive = Layer.succeed(FileStorageLayerContext, FileStorageLayerContext.of({
5
+ createBucket,
5
6
  getFileUrl,
6
7
  uploadFile,
7
8
  readAsText,
@@ -1 +1 @@
1
- {"version":3,"file":"r2-file-storage.layer.js","sourceRoot":"","sources":["../../../src/r2/r2-file-storage.layer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE/B,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EACL,UAAU,EACV,UAAU,EACV,eAAe,EACf,UAAU,EACV,UAAU,GACX,MAAM,4BAA4B,CAAC;AAEpC,MAAM,CAAC,MAAM,4BAA4B,GAAG,KAAK,CAAC,OAAO,CACvD,uBAAuB,EACvB,uBAAuB,CAAC,EAAE,CAAC;IACzB,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,eAAe;CAChB,CAAC,CACH,CAAC"}
1
+ {"version":3,"file":"r2-file-storage.layer.js","sourceRoot":"","sources":["../../../src/r2/r2-file-storage.layer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAE/B,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EACL,YAAY,EACZ,UAAU,EACV,UAAU,EACV,eAAe,EACf,UAAU,EACV,UAAU,GACX,MAAM,4BAA4B,CAAC;AAEpC,MAAM,CAAC,MAAM,4BAA4B,GAAG,KAAK,CAAC,OAAO,CACvD,uBAAuB,EACvB,uBAAuB,CAAC,EAAE,CAAC;IACzB,YAAY;IACZ,UAAU;IACV,UAAU;IACV,UAAU;IACV,UAAU;IACV,eAAe;CAChB,CAAC,CACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effect-cloudflare-r2-layer",
3
- "version": "1.0.7",
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": [
@@ -56,6 +56,7 @@
56
56
  "@types/fs-extra": "^11.0.4",
57
57
  "copyfiles": "^2.4.1",
58
58
  "del-cli": "^5.1.0",
59
+ "effect-errors": "^1.7.12",
59
60
  "fs-extra": "^11.2.0",
60
61
  "readme-package-icons": "^1.1.15",
61
62
  "tsx": "^4.19.1"