effect-cloudflare-r2-layer 1.0.35 → 1.0.37
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +52 -0
- package/cjs/layer/file-storage.layer.js +1 -0
- package/cjs/layer/file-storage.layer.js.map +1 -1
- package/cjs/r2/implementations/bucket-infos.effect.js +2 -2
- package/cjs/r2/implementations/bucket-infos.effect.js.map +1 -1
- package/cjs/r2/implementations/create-bucket.effect.js +2 -2
- package/cjs/r2/implementations/create-bucket.effect.js.map +1 -1
- package/cjs/r2/implementations/delete-file.effect.js +18 -0
- package/cjs/r2/implementations/delete-file.effect.js.map +1 -0
- package/cjs/r2/implementations/get-file-url.effect.js +3 -1
- package/cjs/r2/implementations/get-file-url.effect.js.map +1 -1
- package/cjs/r2/implementations/index.js +1 -0
- package/cjs/r2/implementations/index.js.map +1 -1
- package/cjs/r2/implementations/internal/fetch-file.effect.js +7 -2
- package/cjs/r2/implementations/internal/fetch-file.effect.js.map +1 -1
- package/cjs/r2/implementations/internal/get-url.effect.js +2 -2
- package/cjs/r2/implementations/internal/get-url.effect.js.map +1 -1
- package/cjs/r2/implementations/read-as-json.effect.js +2 -2
- package/cjs/r2/implementations/read-as-json.effect.js.map +1 -1
- package/cjs/r2/implementations/read-as-raw-binary.effect.js +2 -2
- package/cjs/r2/implementations/read-as-raw-binary.effect.js.map +1 -1
- package/cjs/r2/implementations/read-as-text.effect.js +2 -2
- package/cjs/r2/implementations/read-as-text.effect.js.map +1 -1
- package/cjs/r2/implementations/upload-file.effect.js +4 -4
- package/cjs/r2/implementations/upload-file.effect.js.map +1 -1
- package/cjs/r2/r2-file-storage.layer.js +1 -0
- package/cjs/r2/r2-file-storage.layer.js.map +1 -1
- package/dts/layer/file-storage.layer.d.ts +5 -3
- package/dts/r2/implementations/delete-file.effect.d.ts +7 -0
- package/dts/r2/implementations/index.d.ts +1 -0
- package/esm/layer/file-storage.layer.js +1 -0
- package/esm/layer/file-storage.layer.js.map +1 -1
- package/esm/r2/implementations/bucket-infos.effect.js +2 -2
- package/esm/r2/implementations/bucket-infos.effect.js.map +1 -1
- package/esm/r2/implementations/create-bucket.effect.js +2 -2
- package/esm/r2/implementations/create-bucket.effect.js.map +1 -1
- package/esm/r2/implementations/delete-file.effect.js +14 -0
- package/esm/r2/implementations/delete-file.effect.js.map +1 -0
- package/esm/r2/implementations/get-file-url.effect.js +3 -1
- package/esm/r2/implementations/get-file-url.effect.js.map +1 -1
- package/esm/r2/implementations/index.js +1 -0
- package/esm/r2/implementations/index.js.map +1 -1
- package/esm/r2/implementations/internal/fetch-file.effect.js +8 -3
- package/esm/r2/implementations/internal/fetch-file.effect.js.map +1 -1
- package/esm/r2/implementations/internal/get-url.effect.js +3 -3
- package/esm/r2/implementations/internal/get-url.effect.js.map +1 -1
- package/esm/r2/implementations/read-as-json.effect.js +2 -2
- package/esm/r2/implementations/read-as-json.effect.js.map +1 -1
- package/esm/r2/implementations/read-as-raw-binary.effect.js +2 -2
- package/esm/r2/implementations/read-as-raw-binary.effect.js.map +1 -1
- package/esm/r2/implementations/read-as-text.effect.js +2 -2
- package/esm/r2/implementations/read-as-text.effect.js.map +1 -1
- package/esm/r2/implementations/upload-file.effect.js +4 -4
- package/esm/r2/implementations/upload-file.effect.js.map +1 -1
- package/esm/r2/r2-file-storage.layer.js +2 -1
- package/esm/r2/r2-file-storage.layer.js.map +1 -1
- package/package.json +7 -8
package/README.md
CHANGED
@@ -65,6 +65,7 @@ R2_DOCUMENTS_SECRET_ACCESS_KEY=""
|
|
65
65
|
| [`createBucket`](#-createbucket) | Create a bucket |
|
66
66
|
| [`bucketInfos`](#-bucketinfos) | Get bucket infos |
|
67
67
|
| [`uploadFile`](#-uploadfile) | Adds a file to the specified bucket |
|
68
|
+
| [`deleteFile`](#-deleteFile) | Removes a file from the specified bucket |
|
68
69
|
| [`getFileUrl`](#-getfileurl) | Gets a pre-signed url to fetch a ressource by its `filename` from the specified `bucket`. |
|
69
70
|
| [`readAsJson`](#-readasjson) | Fetches a file, expecting a content extending `Record<string, unknown>`. |
|
70
71
|
| [`readAsText`](#-readastext) | Fetches a file as a string. |
|
@@ -208,6 +209,57 @@ const task = pipe(
|
|
208
209
|
);
|
209
210
|
```
|
210
211
|
|
212
|
+
### 🔶 `deleteFile`
|
213
|
+
|
214
|
+
Removes a file from the specified bucket.
|
215
|
+
|
216
|
+
```typescript
|
217
|
+
interface DeleteFileInput<TBucket extends string> {
|
218
|
+
bucketName: TBucket;
|
219
|
+
key: string;
|
220
|
+
}
|
221
|
+
|
222
|
+
type deleteFile = <TBucket extends string>(
|
223
|
+
input: DeleteFileInput<TBucket>
|
224
|
+
) => Effect.Effect<
|
225
|
+
DeleteObjectCommandOutput,
|
226
|
+
FileStorageError | ConfigError.ConfigError,
|
227
|
+
FileStorage
|
228
|
+
>;
|
229
|
+
```
|
230
|
+
|
231
|
+
#### 🧿 Example
|
232
|
+
|
233
|
+
```typescript
|
234
|
+
import { Effect, pipe } from 'effect';
|
235
|
+
import {
|
236
|
+
CloudflareR2StorageLayerLive,
|
237
|
+
FileStorageLayer,
|
238
|
+
} from 'effect-cloudflare-r2-layer';
|
239
|
+
import { readFile } from 'fs-extra';
|
240
|
+
|
241
|
+
type Buckets = 'assets' | 'config';
|
242
|
+
const fileName = 'yolo.jpg';
|
243
|
+
const filePath = './assets/yolo.jpg';
|
244
|
+
|
245
|
+
const task = pipe(
|
246
|
+
Effect.gen(function* () {
|
247
|
+
const fileData = yield* Effect.tryPromise({
|
248
|
+
try: () => readFile(filePath),
|
249
|
+
catch: (e) => new FsError({ cause: e }),
|
250
|
+
});
|
251
|
+
|
252
|
+
yield* FileStorageLayer.deleteFile<Buckets>({
|
253
|
+
bucketName: 'assets',
|
254
|
+
documentKey: fileName,
|
255
|
+
});
|
256
|
+
|
257
|
+
// ...
|
258
|
+
}),
|
259
|
+
Effect.provide(CloudflareR2StorageLayerLive);
|
260
|
+
);
|
261
|
+
```
|
262
|
+
|
211
263
|
### 🔶 `getFileUrl`
|
212
264
|
|
213
265
|
Gets a pre-signed url to fetch a ressource by its `filename` from the specified `bucket`.
|
@@ -12,5 +12,6 @@ exports.FileStorageLayer = {
|
|
12
12
|
readAsJson: (bucket, fileName) => (0, _effects_1.tapLayer)(exports.FileStorageLayerContext, ({ readAsJson }) => readAsJson(bucket, fileName)),
|
13
13
|
readAsText: (bucket, fileName) => (0, _effects_1.tapLayer)(exports.FileStorageLayerContext, ({ readAsText }) => readAsText(bucket, fileName)),
|
14
14
|
uploadFile: (input) => (0, _effects_1.tapLayer)(exports.FileStorageLayerContext, ({ uploadFile }) => uploadFile(input)),
|
15
|
+
deleteFile: (input) => (0, _effects_1.tapLayer)(exports.FileStorageLayerContext, ({ deleteFile }) => deleteFile(input)),
|
15
16
|
};
|
16
17
|
//# sourceMappingURL=file-storage.layer.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"file-storage.layer.js","sourceRoot":"","sources":["../../../src/layer/file-storage.layer.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"file":"file-storage.layer.js","sourceRoot":"","sources":["../../../src/layer/file-storage.layer.ts"],"names":[],"mappings":";;;AAQA,mCAAiC;AAIjC,uCAAoC;AA2EvB,QAAA,uBAAuB,GAClC,gBAAO,CAAC,UAAU,CAAc,cAAc,CAAC,CAAC;AAErC,QAAA,gBAAgB,GAAG;IAC9B,YAAY,EAAE,CAAC,KAA+B,EAAE,EAAE,CAChD,IAAA,mBAAQ,EAAC,+BAAuB,EAAE,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CACrD,YAAY,CAAC,KAAK,CAAC,CACpB;IACH,WAAW,EAAE,CAAyB,KAAgC,EAAE,EAAE,CACxE,IAAA,mBAAQ,EAAC,+BAAuB,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAC5E,UAAU,EAAE,CAAyB,MAAe,EAAE,QAAgB,EAAE,EAAE,CACxE,IAAA,mBAAQ,EAAC,+BAAuB,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,IAAA,mBAAQ,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,mBAAQ,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,mBAAQ,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,mBAAQ,EAAC,+BAAuB,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAC1E,UAAU,EAAE,CAAyB,KAA+B,EAAE,EAAE,CACtE,IAAA,mBAAQ,EAAC,+BAAuB,EAAE,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;CAC3E,CAAC"}
|
@@ -8,7 +8,7 @@ const _provider_1 = require("./../providers/r2-file-storage.provider.js");
|
|
8
8
|
const hasName = (error) => {
|
9
9
|
return error?.name !== undefined;
|
10
10
|
};
|
11
|
-
const bucketInfos = (input) =>
|
11
|
+
const bucketInfos = (input) => (0, effect_1.pipe)(_provider_1.cloudflareR2StorageProvider, effect_1.Effect.flatMap((provider) => effect_1.Effect.tryPromise({
|
12
12
|
try: () => provider.send(new client_s3_1.HeadBucketCommand(input)),
|
13
13
|
catch: (e) => {
|
14
14
|
if (hasName(e) && e.name === 'NotFound') {
|
@@ -18,6 +18,6 @@ const bucketInfos = (input) => effect_1.Effect.withSpan('bucket-infos', { attrib
|
|
18
18
|
},
|
19
19
|
})), effect_1.Effect.map((response) => ({
|
20
20
|
region: response.BucketRegion,
|
21
|
-
}))));
|
21
|
+
})), effect_1.Effect.withSpan('bucket-infos', { attributes: { ...input } }));
|
22
22
|
exports.bucketInfos = bucketInfos;
|
23
23
|
//# sourceMappingURL=bucket-infos.effect.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"bucket-infos.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/bucket-infos.effect.ts"],"names":[],"mappings":";;;AAAA,kDAAuD;AACvD,mCAAsC;AAEtC,qCAAgE;AAChE,yCAAwD;AAIxD,MAAM,OAAO,GAAG,CAAC,KAAc,EAAoC,EAAE;IACnE,OAAQ,KAAuB,EAAE,IAAI,KAAK,SAAS,CAAC;AACtD,CAAC,CAAC;AAWK,MAAM,WAAW,GAAG,CACzB,KAAgC,EAChC,EAAE,CACF,
|
1
|
+
{"version":3,"file":"bucket-infos.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/bucket-infos.effect.ts"],"names":[],"mappings":";;;AAAA,kDAAuD;AACvD,mCAAsC;AAEtC,qCAAgE;AAChE,yCAAwD;AAIxD,MAAM,OAAO,GAAG,CAAC,KAAc,EAAoC,EAAE;IACnE,OAAQ,KAAuB,EAAE,IAAI,KAAK,SAAS,CAAC;AACtD,CAAC,CAAC;AAWK,MAAM,WAAW,GAAG,CACzB,KAAgC,EAChC,EAAE,CACF,IAAA,aAAI,EACF,uCAA2B,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,6BAAiB,CAAC,KAAK,CAAC,CAAC;IACtD,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE;QACX,IAAI,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YACxC,OAAO,IAAI,6BAAmB,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;QAC/C,CAAC;QAED,OAAO,IAAI,0BAAgB,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;IAC5C,CAAC;CACF,CAAC,CACH,EACD,eAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACxB,MAAM,EAAE,QAAQ,CAAC,YAAY;CAC9B,CAAC,CAAC,EACH,eAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,EAAE,UAAU,EAAE,EAAE,GAAG,KAAK,EAAE,EAAE,CAAC,CAC9D,CAAC;AArBS,QAAA,WAAW,eAqBpB"}
|
@@ -5,9 +5,9 @@ const client_s3_1 = require("@aws-sdk/client-s3");
|
|
5
5
|
const effect_1 = require("effect");
|
6
6
|
const _errors_1 = require("./../../errors/index.js");
|
7
7
|
const _provider_1 = require("./../providers/r2-file-storage.provider.js");
|
8
|
-
const createBucket = (input) =>
|
8
|
+
const createBucket = (input) => (0, effect_1.pipe)(_provider_1.cloudflareR2StorageProvider, effect_1.Effect.flatMap((provider) => effect_1.Effect.tryPromise({
|
9
9
|
try: () => provider.send(new client_s3_1.CreateBucketCommand(input)),
|
10
10
|
catch: (e) => new _errors_1.FileStorageError({ cause: e }),
|
11
|
-
}))));
|
11
|
+
})), effect_1.Effect.withSpan('create-bucket', { attributes: { ...input } }));
|
12
12
|
exports.createBucket = createBucket;
|
13
13
|
//# sourceMappingURL=create-bucket.effect.js.map
|
@@ -1 +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,qCAA2C;AAC3C,yCAAwD;AAEjD,MAAM,YAAY,GAAG,CAAC,KAA+B,EAAE,EAAE,CAC9D,
|
1
|
+
{"version":3,"file":"create-bucket.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/create-bucket.effect.ts"],"names":[],"mappings":";;;AAAA,kDAG4B;AAC5B,mCAAsC;AAEtC,qCAA2C;AAC3C,yCAAwD;AAEjD,MAAM,YAAY,GAAG,CAAC,KAA+B,EAAE,EAAE,CAC9D,IAAA,aAAI,EACF,uCAA2B,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,0BAAgB,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;CACjD,CAAC,CACH,EACD,eAAM,CAAC,QAAQ,CAAC,eAAe,EAAE,EAAE,UAAU,EAAE,EAAE,GAAG,KAAK,EAAE,EAAE,CAAC,CAC/D,CAAC;AAVS,QAAA,YAAY,gBAUrB"}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.deleteFile = void 0;
|
4
|
+
const client_s3_1 = require("@aws-sdk/client-s3");
|
5
|
+
const effect_1 = require("effect");
|
6
|
+
const _errors_1 = require("./../../errors/index.js");
|
7
|
+
const _provider_1 = require("./../providers/r2-file-storage.provider.js");
|
8
|
+
const deleteFile = ({ bucketName, documentKey, }) => (0, effect_1.pipe)(_provider_1.cloudflareR2StorageProvider, effect_1.Effect.flatMap((provider) => effect_1.Effect.tryPromise({
|
9
|
+
try: () => provider.send(new client_s3_1.DeleteObjectCommand({
|
10
|
+
Key: documentKey,
|
11
|
+
Bucket: bucketName,
|
12
|
+
})),
|
13
|
+
catch: (e) => new _errors_1.FileStorageError({ cause: e }),
|
14
|
+
})), effect_1.Effect.withSpan('delete-file', {
|
15
|
+
attributes: { bucketName, documentKey },
|
16
|
+
}));
|
17
|
+
exports.deleteFile = deleteFile;
|
18
|
+
//# sourceMappingURL=delete-file.effect.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"delete-file.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/delete-file.effect.ts"],"names":[],"mappings":";;;AAAA,kDAAyD;AACzD,mCAAsC;AAEtC,qCAA2C;AAC3C,yCAAwD;AAOjD,MAAM,UAAU,GAAG,CAAyB,EACjD,UAAU,EACV,WAAW,GACc,EAAE,EAAE,CAC7B,IAAA,aAAI,EACF,uCAA2B,EAC3B,eAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAC1B,eAAM,CAAC,UAAU,CAAC;IAChB,GAAG,EAAE,GAAG,EAAE,CACR,QAAQ,CAAC,IAAI,CACX,IAAI,+BAAmB,CAAC;QACtB,GAAG,EAAE,WAAW;QAChB,MAAM,EAAE,UAAU;KACnB,CAAC,CACH;IACH,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,0BAAgB,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;CACjD,CAAC,CACH,EACD,eAAM,CAAC,QAAQ,CAAC,aAAa,EAAE;IAC7B,UAAU,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE;CACxC,CAAC,CACH,CAAC;AArBS,QAAA,UAAU,cAqBnB"}
|
@@ -4,6 +4,8 @@ exports.getFileUrl = void 0;
|
|
4
4
|
const effect_1 = require("effect");
|
5
5
|
const _provider_1 = require("./../providers/r2-file-storage.provider.js");
|
6
6
|
const index_js_1 = require("./internal/index.js");
|
7
|
-
const getFileUrl = (bucketName, documentKey) =>
|
7
|
+
const getFileUrl = (bucketName, documentKey) => (0, effect_1.pipe)(_provider_1.cloudflareR2StorageProvider, effect_1.Effect.flatMap((provider) => (0, index_js_1.getUrl)(provider, bucketName, documentKey)), effect_1.Effect.withSpan('get-file-url', {
|
8
|
+
attributes: { bucketName, documentKey },
|
9
|
+
}));
|
8
10
|
exports.getFileUrl = getFileUrl;
|
9
11
|
//# sourceMappingURL=get-file-url.effect.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"get-file-url.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/get-file-url.effect.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;AAEtC,yCAAwD;AAExD,kDAA6C;AAEtC,MAAM,UAAU,GAAG,CACxB,UAAmB,EACnB,WAAmB,EACnB,EAAE,CACF,
|
1
|
+
{"version":3,"file":"get-file-url.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/get-file-url.effect.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;AAEtC,yCAAwD;AAExD,kDAA6C;AAEtC,MAAM,UAAU,GAAG,CACxB,UAAmB,EACnB,WAAmB,EACnB,EAAE,CACF,IAAA,aAAI,EACF,uCAA2B,EAC3B,eAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAA,iBAAM,EAAC,QAAQ,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC,EACvE,eAAM,CAAC,QAAQ,CAAC,cAAc,EAAE;IAC9B,UAAU,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE;CACxC,CAAC,CACH,CAAC;AAVS,QAAA,UAAU,cAUnB"}
|
@@ -21,4 +21,5 @@ __exportStar(require("./upload-file.effect.js"), exports);
|
|
21
21
|
__exportStar(require("./read-as-json.effect.js"), exports);
|
22
22
|
__exportStar(require("./read-as-raw-binary.effect.js"), exports);
|
23
23
|
__exportStar(require("./read-as-text.effect.js"), exports);
|
24
|
+
__exportStar(require("./delete-file.effect.js"), exports);
|
24
25
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/r2/implementations/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4DAA0C;AAC1C,2DAAyC;AACzC,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,2DAAyC;AACzC,0DAAwC;AACxC,2DAAyC;AACzC,iEAA+C;AAC/C,2DAAyC;AACzC,0DAAwC"}
|
@@ -5,11 +5,16 @@ const platform_1 = require("@effect/platform");
|
|
5
5
|
const effect_1 = require("effect");
|
6
6
|
const _provider_1 = require("./../../providers/r2-file-storage.provider.js");
|
7
7
|
const get_url_effect_js_1 = require("./get-url.effect.js");
|
8
|
-
const fetchFile = (bucketName, documentKey) => effect_1.Effect.gen(function* () {
|
8
|
+
const fetchFile = (bucketName, documentKey) => (0, effect_1.pipe)(effect_1.Effect.gen(function* () {
|
9
9
|
const provider = yield* _provider_1.cloudflareR2StorageProvider;
|
10
10
|
const url = yield* (0, get_url_effect_js_1.getUrl)(provider, bucketName, documentKey);
|
11
11
|
const client = yield* platform_1.HttpClient.HttpClient;
|
12
12
|
return yield* client.get(url);
|
13
|
-
})
|
13
|
+
}), effect_1.Effect.withSpan('fetch-file', {
|
14
|
+
attributes: {
|
15
|
+
bucketName,
|
16
|
+
documentKey,
|
17
|
+
},
|
18
|
+
}));
|
14
19
|
exports.fetchFile = fetchFile;
|
15
20
|
//# sourceMappingURL=fetch-file.effect.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"fetch-file.effect.js","sourceRoot":"","sources":["../../../../../src/r2/implementations/internal/fetch-file.effect.ts"],"names":[],"mappings":";;;AAAA,+CAA8C;AAC9C,
|
1
|
+
{"version":3,"file":"fetch-file.effect.js","sourceRoot":"","sources":["../../../../../src/r2/implementations/internal/fetch-file.effect.ts"],"names":[],"mappings":";;;AAAA,+CAA8C;AAC9C,mCAAsC;AAEtC,yCAAwD;AAExD,2DAA6C;AAEtC,MAAM,SAAS,GAAG,CAAC,UAAkB,EAAE,WAAmB,EAAE,EAAE,CACnE,IAAA,aAAI,EACF,eAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,uCAA2B,CAAC;IACpD,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,IAAA,0BAAM,EAAC,QAAQ,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;IAE7D,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,qBAAU,CAAC,UAAU,CAAC;IAC5C,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAChC,CAAC,CAAC,EACF,eAAM,CAAC,QAAQ,CAAC,YAAY,EAAE;IAC5B,UAAU,EAAE;QACV,UAAU;QACV,WAAW;KACZ;CACF,CAAC,CACH,CAAC;AAfS,QAAA,SAAS,aAelB"}
|
@@ -6,7 +6,7 @@ const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
|
|
6
6
|
const effect_1 = require("effect");
|
7
7
|
const _errors_1 = require("./../../../errors/index.js");
|
8
8
|
const oneHourDuration = 60 * 60;
|
9
|
-
const getUrl = (provider, bucketName, documentKey) =>
|
9
|
+
const getUrl = (provider, bucketName, documentKey) => (0, effect_1.pipe)(effect_1.Effect.tryPromise({
|
10
10
|
try: () => (0, s3_request_presigner_1.getSignedUrl)(provider, new client_s3_1.GetObjectCommand({
|
11
11
|
Bucket: bucketName,
|
12
12
|
Key: documentKey,
|
@@ -14,6 +14,6 @@ const getUrl = (provider, bucketName, documentKey) => effect_1.Effect.withSpan('
|
|
14
14
|
expiresIn: oneHourDuration,
|
15
15
|
}),
|
16
16
|
catch: (e) => new _errors_1.FileStorageError({ cause: e }),
|
17
|
-
}));
|
17
|
+
}), effect_1.Effect.withSpan('get-url', { attributes: { bucketName, documentKey } }));
|
18
18
|
exports.getUrl = getUrl;
|
19
19
|
//# sourceMappingURL=get-url.effect.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"get-url.effect.js","sourceRoot":"","sources":["../../../../../src/r2/implementations/internal/get-url.effect.ts"],"names":[],"mappings":";;;AACA,kDAAsD;AACtD,wEAAgF;AAChF,
|
1
|
+
{"version":3,"file":"get-url.effect.js","sourceRoot":"","sources":["../../../../../src/r2/implementations/internal/get-url.effect.ts"],"names":[],"mappings":";;;AACA,kDAAsD;AACtD,wEAAgF;AAChF,mCAAsC;AAEtC,qCAA2C;AAE3C,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,CAAC;AAEzB,MAAM,MAAM,GAAG,CACpB,QAAkB,EAClB,UAAmB,EACnB,WAAoB,EACpB,EAAE,CACF,IAAA,aAAI,EACF,eAAM,CAAC,UAAU,CAAC;IAChB,GAAG,EAAE,GAAG,EAAE,CACR,IAAA,mCAAe,EACb,QAAQ,EACR,IAAI,4BAAgB,CAAC;QACnB,MAAM,EAAE,UAAU;QAClB,GAAG,EAAE,WAAW;KACjB,CAAC,EACF;QACE,SAAS,EAAE,eAAe;KAC3B,CACF;IACH,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,0BAAgB,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;CACjD,CAAC,EACF,eAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,UAAU,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,EAAE,CAAC,CACxE,CAAC;AArBS,QAAA,MAAM,UAqBf"}
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.readAsJson = void 0;
|
4
4
|
const effect_1 = require("effect");
|
5
5
|
const index_js_1 = require("./internal/index.js");
|
6
|
-
const readAsJson = (bucketName, documentKey) => effect_1.Effect.withSpan('read-as-json', {
|
6
|
+
const readAsJson = (bucketName, documentKey) => (0, effect_1.pipe)((0, index_js_1.fetchFile)(bucketName, documentKey), effect_1.Effect.flatMap((response) => response.json), effect_1.Effect.map((json) => json), effect_1.Effect.withSpan('read-as-json', {
|
7
7
|
attributes: { bucketName, documentKey },
|
8
|
-
})
|
8
|
+
}));
|
9
9
|
exports.readAsJson = readAsJson;
|
10
10
|
//# sourceMappingURL=read-as-json.effect.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"read-as-json.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/read-as-json.effect.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;AAEtC,kDAAgD;AAEzC,MAAM,UAAU,GAAG,CAIxB,UAAmB,EACnB,WAAmB,EACnB,EAAE,CACF,
|
1
|
+
{"version":3,"file":"read-as-json.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/read-as-json.effect.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;AAEtC,kDAAgD;AAEzC,MAAM,UAAU,GAAG,CAIxB,UAAmB,EACnB,WAAmB,EACnB,EAAE,CACF,IAAA,aAAI,EACF,IAAA,oBAAS,EAAC,UAAU,EAAE,WAAW,CAAC,EAClC,eAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAC3C,eAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAc,CAAC,EACpC,eAAM,CAAC,QAAQ,CAAC,cAAc,EAAE;IAC9B,UAAU,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE;CACxC,CAAC,CACH,CAAC;AAdS,QAAA,UAAU,cAcnB"}
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.readAsRawBinary = void 0;
|
4
4
|
const effect_1 = require("effect");
|
5
5
|
const index_js_1 = require("./internal/index.js");
|
6
|
-
const readAsRawBinary = (bucketName, documentKey) => effect_1.Effect.withSpan('read-as-raw-binary', {
|
6
|
+
const readAsRawBinary = (bucketName, documentKey) => (0, effect_1.pipe)((0, index_js_1.fetchFile)(bucketName, documentKey), effect_1.Effect.flatMap((response) => response.arrayBuffer), effect_1.Effect.withSpan('read-as-raw-binary', {
|
7
7
|
attributes: { bucketName, documentKey },
|
8
|
-
})
|
8
|
+
}));
|
9
9
|
exports.readAsRawBinary = readAsRawBinary;
|
10
10
|
//# sourceMappingURL=read-as-raw-binary.effect.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"read-as-raw-binary.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/read-as-raw-binary.effect.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;AAEtC,kDAAgD;AAEzC,MAAM,eAAe,GAAG,CAC7B,UAAmB,EACnB,WAAmB,EACnB,EAAE,CACF,
|
1
|
+
{"version":3,"file":"read-as-raw-binary.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/read-as-raw-binary.effect.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;AAEtC,kDAAgD;AAEzC,MAAM,eAAe,GAAG,CAC7B,UAAmB,EACnB,WAAmB,EACnB,EAAE,CACF,IAAA,aAAI,EACF,IAAA,oBAAS,EAAC,UAAU,EAAE,WAAW,CAAC,EAClC,eAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,EAClD,eAAM,CAAC,QAAQ,CAAC,oBAAoB,EAAE;IACpC,UAAU,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE;CACxC,CAAC,CACH,CAAC;AAVS,QAAA,eAAe,mBAUxB"}
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.readAsText = void 0;
|
4
4
|
const effect_1 = require("effect");
|
5
5
|
const index_js_1 = require("./internal/index.js");
|
6
|
-
const readAsText = (bucketName, documentKey) => effect_1.Effect.withSpan('read-as-text', {
|
6
|
+
const readAsText = (bucketName, documentKey) => (0, effect_1.pipe)((0, index_js_1.fetchFile)(bucketName, documentKey), effect_1.Effect.flatMap((response) => response.text), effect_1.Effect.withSpan('read-as-text', {
|
7
7
|
attributes: { bucketName, documentKey },
|
8
|
-
})
|
8
|
+
}));
|
9
9
|
exports.readAsText = readAsText;
|
10
10
|
//# sourceMappingURL=read-as-text.effect.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"read-as-text.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/read-as-text.effect.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;AAEtC,kDAAgD;AAEzC,MAAM,UAAU,GAAG,CACxB,UAAmB,EACnB,WAAmB,EACnB,EAAE,CACF,
|
1
|
+
{"version":3,"file":"read-as-text.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/read-as-text.effect.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;AAEtC,kDAAgD;AAEzC,MAAM,UAAU,GAAG,CACxB,UAAmB,EACnB,WAAmB,EACnB,EAAE,CACF,IAAA,aAAI,EACF,IAAA,oBAAS,EAAC,UAAU,EAAE,WAAW,CAAC,EAClC,eAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAC3C,eAAM,CAAC,QAAQ,CAAC,cAAc,EAAE;IAC9B,UAAU,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE;CACxC,CAAC,CACH,CAAC;AAVS,QAAA,UAAU,cAUnB"}
|
@@ -5,9 +5,7 @@ const client_s3_1 = require("@aws-sdk/client-s3");
|
|
5
5
|
const effect_1 = require("effect");
|
6
6
|
const _errors_1 = require("./../../errors/index.js");
|
7
7
|
const _provider_1 = require("./../providers/r2-file-storage.provider.js");
|
8
|
-
const uploadFile = ({ bucketName, documentKey, data, contentType, }) => effect_1.Effect.
|
9
|
-
attributes: { bucketName, documentKey, contentType },
|
10
|
-
})((0, effect_1.pipe)(_provider_1.cloudflareR2StorageProvider, effect_1.Effect.flatMap((provider) => effect_1.Effect.tryPromise({
|
8
|
+
const uploadFile = ({ bucketName, documentKey, data, contentType, }) => (0, effect_1.pipe)(_provider_1.cloudflareR2StorageProvider, effect_1.Effect.flatMap((provider) => effect_1.Effect.tryPromise({
|
11
9
|
try: () => provider.send(new client_s3_1.PutObjectCommand({
|
12
10
|
Body: data,
|
13
11
|
ContentType: contentType,
|
@@ -15,6 +13,8 @@ const uploadFile = ({ bucketName, documentKey, data, contentType, }) => effect_1
|
|
15
13
|
Bucket: bucketName,
|
16
14
|
})),
|
17
15
|
catch: (e) => new _errors_1.FileStorageError({ cause: e }),
|
18
|
-
}))
|
16
|
+
})), effect_1.Effect.withSpan('upload-file', {
|
17
|
+
attributes: { bucketName, documentKey, contentType },
|
18
|
+
}));
|
19
19
|
exports.uploadFile = uploadFile;
|
20
20
|
//# sourceMappingURL=upload-file.effect.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"upload-file.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/upload-file.effect.ts"],"names":[],"mappings":";;;AAAA,kDAAsD;AACtD,mCAAsC;AAEtC,qCAA2C;AAC3C,yCAAwD;AASjD,MAAM,UAAU,GAAG,CAAyB,EACjD,UAAU,EACV,WAAW,EACX,IAAI,EACJ,WAAW,GACc,EAAE,EAAE,CAC7B,
|
1
|
+
{"version":3,"file":"upload-file.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/upload-file.effect.ts"],"names":[],"mappings":";;;AAAA,kDAAsD;AACtD,mCAAsC;AAEtC,qCAA2C;AAC3C,yCAAwD;AASjD,MAAM,UAAU,GAAG,CAAyB,EACjD,UAAU,EACV,WAAW,EACX,IAAI,EACJ,WAAW,GACc,EAAE,EAAE,CAC7B,IAAA,aAAI,EACF,uCAA2B,EAC3B,eAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAC1B,eAAM,CAAC,UAAU,CAAC;IAChB,GAAG,EAAE,GAAG,EAAE,CACR,QAAQ,CAAC,IAAI,CACX,IAAI,4BAAgB,CAAC;QACnB,IAAI,EAAE,IAAI;QACV,WAAW,EAAE,WAAqB;QAClC,GAAG,EAAE,WAAW;QAChB,MAAM,EAAE,UAAU;KACnB,CAAC,CACH;IACH,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,0BAAgB,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;CACjD,CAAC,CACH,EACD,eAAM,CAAC,QAAQ,CAAC,aAAa,EAAE;IAC7B,UAAU,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE;CACrD,CAAC,CACH,CAAC;AAzBS,QAAA,UAAU,cAyBnB"}
|
@@ -9,6 +9,7 @@ exports.CloudflareR2StorageLayerLive = effect_1.Layer.succeed(file_storage_layer
|
|
9
9
|
bucketInfos: _implementation_1.bucketInfos,
|
10
10
|
getFileUrl: _implementation_1.getFileUrl,
|
11
11
|
uploadFile: _implementation_1.uploadFile,
|
12
|
+
deleteFile: _implementation_1.deleteFile,
|
12
13
|
readAsText: _implementation_1.readAsText,
|
13
14
|
readAsJson: _implementation_1.readAsJson,
|
14
15
|
readAsRawBinary: _implementation_1.readAsRawBinary,
|
@@ -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,
|
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,qDASyB;AAEzB,0EAAyE;AAE5D,QAAA,4BAA4B,GAAG,cAAK,CAAC,OAAO,CACvD,+CAAuB,EACvB,+CAAuB,CAAC,EAAE,CAAC;IACzB,YAAY,EAAZ,8BAAY;IACZ,WAAW,EAAX,6BAAW;IACX,UAAU,EAAV,4BAAU;IACV,UAAU,EAAV,4BAAU;IACV,UAAU,EAAV,4BAAU;IACV,UAAU,EAAV,4BAAU;IACV,UAAU,EAAV,4BAAU;IACV,eAAe,EAAf,iCAAe;CAChB,CAAC,CACH,CAAC"}
|
@@ -1,11 +1,11 @@
|
|
1
|
+
import { CreateBucketCommandInput, CreateBucketCommandOutput, DeleteObjectCommandOutput, PutObjectCommandOutput } from '@aws-sdk/client-s3';
|
1
2
|
import { HttpClientError } from '@effect/platform/HttpClientError';
|
2
3
|
import type { ConfigError, Effect } from 'effect';
|
3
4
|
import { Context } from 'effect';
|
4
|
-
import { CreateBucketCommandInput, CreateBucketCommandOutput, PutObjectCommandOutput } from '@aws-sdk/client-s3';
|
5
|
-
import { HttpClient } from '@effect/platform/HttpClient';
|
6
5
|
import { Scope } from 'effect/Scope';
|
6
|
+
import { HttpClient } from '@effect/platform/HttpClient';
|
7
7
|
import type { BucketNotFoundError, FileStorageError } from './../errors/index.js';
|
8
|
-
import type { BucketInfosInput, BucketInfosResult, UploadFileInput } from './../r2/implementations/index.js';
|
8
|
+
import type { BucketInfosInput, BucketInfosResult, DeleteFileInput, UploadFileInput } from './../r2/implementations/index.js';
|
9
9
|
export interface FileStorage {
|
10
10
|
readonly createBucket: (input: CreateBucketCommandInput) => Effect.Effect<CreateBucketCommandOutput, ConfigError.ConfigError | FileStorageError, never>;
|
11
11
|
readonly bucketInfos: <TBucket extends string>(input: BucketInfosInput<TBucket>) => Effect.Effect<BucketInfosResult, ConfigError.ConfigError | FileStorageError | BucketNotFoundError, never>;
|
@@ -14,6 +14,7 @@ export interface FileStorage {
|
|
14
14
|
readonly readAsJson: <TBucket extends string, TShape extends Record<string, unknown>>(bucketName: TBucket, documentKey: string) => Effect.Effect<TShape, ConfigError.ConfigError | HttpClientError | FileStorageError, HttpClient<HttpClientError, Scope> | Scope>;
|
15
15
|
readonly readAsText: <TBucket extends string>(bucketName: TBucket, documentKey: string) => Effect.Effect<string, ConfigError.ConfigError | HttpClientError | FileStorageError, HttpClient<HttpClientError, Scope> | Scope>;
|
16
16
|
readonly uploadFile: <TBucket extends string>({ bucketName, documentKey, data, contentType, }: UploadFileInput<TBucket>) => Effect.Effect<PutObjectCommandOutput, ConfigError.ConfigError | FileStorageError, never>;
|
17
|
+
readonly deleteFile: <TBucket extends string>({ bucketName, documentKey, }: DeleteFileInput<TBucket>) => Effect.Effect<DeleteObjectCommandOutput, ConfigError.ConfigError | FileStorageError, never>;
|
17
18
|
}
|
18
19
|
export declare const FileStorageLayerContext: Context.Tag<FileStorage, FileStorage>;
|
19
20
|
export declare const FileStorageLayer: {
|
@@ -24,4 +25,5 @@ export declare const FileStorageLayer: {
|
|
24
25
|
readAsJson: <TBucket extends string, TShape extends Record<string, unknown>>(bucket: TBucket, fileName: string) => Effect.Effect<TShape, FileStorageError | ConfigError.ConfigError | HttpClientError, Scope | HttpClient<HttpClientError, Scope> | FileStorage>;
|
25
26
|
readAsText: <TBucket extends string>(bucket: TBucket, fileName: string) => Effect.Effect<string, FileStorageError | ConfigError.ConfigError | HttpClientError, Scope | HttpClient<HttpClientError, Scope> | FileStorage>;
|
26
27
|
uploadFile: <TBucket extends string>(input: UploadFileInput<TBucket>) => Effect.Effect<PutObjectCommandOutput, FileStorageError | ConfigError.ConfigError, FileStorage>;
|
28
|
+
deleteFile: <TBucket extends string>(input: DeleteFileInput<TBucket>) => Effect.Effect<DeleteObjectCommandOutput, FileStorageError | ConfigError.ConfigError, FileStorage>;
|
27
29
|
};
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import { Effect } from 'effect';
|
2
|
+
import { FileStorageError } from './../../errors/index.js';
|
3
|
+
export interface DeleteFileInput<TBucket extends string> {
|
4
|
+
bucketName: TBucket;
|
5
|
+
documentKey: string;
|
6
|
+
}
|
7
|
+
export declare const deleteFile: <TBucket extends string>({ bucketName, documentKey, }: DeleteFileInput<TBucket>) => Effect.Effect<import("@aws-sdk/client-s3").DeleteObjectCommandOutput, FileStorageError | import("effect/ConfigError").ConfigError, never>;
|
@@ -9,5 +9,6 @@ export const FileStorageLayer = {
|
|
9
9
|
readAsJson: (bucket, fileName) => tapLayer(FileStorageLayerContext, ({ readAsJson }) => readAsJson(bucket, fileName)),
|
10
10
|
readAsText: (bucket, fileName) => tapLayer(FileStorageLayerContext, ({ readAsText }) => readAsText(bucket, fileName)),
|
11
11
|
uploadFile: (input) => tapLayer(FileStorageLayerContext, ({ uploadFile }) => uploadFile(input)),
|
12
|
+
deleteFile: (input) => tapLayer(FileStorageLayerContext, ({ deleteFile }) => deleteFile(input)),
|
12
13
|
};
|
13
14
|
//# sourceMappingURL=file-storage.layer.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"file-storage.layer.js","sourceRoot":"","sources":["../../../src/layer/file-storage.layer.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"file-storage.layer.js","sourceRoot":"","sources":["../../../src/layer/file-storage.layer.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAIjC,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AA2EpC,MAAM,CAAC,MAAM,uBAAuB,GAClC,OAAO,CAAC,UAAU,CAAc,cAAc,CAAC,CAAC;AAElD,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,YAAY,EAAE,CAAC,KAA+B,EAAE,EAAE,CAChD,QAAQ,CAAC,uBAAuB,EAAE,CAAC,EAAE,YAAY,EAAE,EAAE,EAAE,CACrD,YAAY,CAAC,KAAK,CAAC,CACpB;IACH,WAAW,EAAE,CAAyB,KAAgC,EAAE,EAAE,CACxE,QAAQ,CAAC,uBAAuB,EAAE,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAC5E,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,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;IAC1E,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"}
|
@@ -5,7 +5,7 @@ import { cloudflareR2StorageProvider } from './../providers/r2-file-storage.prov
|
|
5
5
|
const hasName = (error) => {
|
6
6
|
return error?.name !== undefined;
|
7
7
|
};
|
8
|
-
export const bucketInfos = (input) =>
|
8
|
+
export const bucketInfos = (input) => pipe(cloudflareR2StorageProvider, Effect.flatMap((provider) => Effect.tryPromise({
|
9
9
|
try: () => provider.send(new HeadBucketCommand(input)),
|
10
10
|
catch: (e) => {
|
11
11
|
if (hasName(e) && e.name === 'NotFound') {
|
@@ -15,5 +15,5 @@ export const bucketInfos = (input) => Effect.withSpan('bucket-infos', { attribut
|
|
15
15
|
},
|
16
16
|
})), Effect.map((response) => ({
|
17
17
|
region: response.BucketRegion,
|
18
|
-
}))));
|
18
|
+
})), Effect.withSpan('bucket-infos', { attributes: { ...input } }));
|
19
19
|
//# sourceMappingURL=bucket-infos.effect.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"bucket-infos.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/bucket-infos.effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAIxD,MAAM,OAAO,GAAG,CAAC,KAAc,EAAoC,EAAE;IACnE,OAAQ,KAAuB,EAAE,IAAI,KAAK,SAAS,CAAC;AACtD,CAAC,CAAC;AAWF,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,KAAgC,EAChC,EAAE,CACF,
|
1
|
+
{"version":3,"file":"bucket-infos.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/bucket-infos.effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAIxD,MAAM,OAAO,GAAG,CAAC,KAAc,EAAoC,EAAE;IACnE,OAAQ,KAAuB,EAAE,IAAI,KAAK,SAAS,CAAC;AACtD,CAAC,CAAC;AAWF,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,KAAgC,EAChC,EAAE,CACF,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,iBAAiB,CAAC,KAAK,CAAC,CAAC;IACtD,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE;QACX,IAAI,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YACxC,OAAO,IAAI,mBAAmB,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;QAC/C,CAAC;QAED,OAAO,IAAI,gBAAgB,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;IAC5C,CAAC;CACF,CAAC,CACH,EACD,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IACxB,MAAM,EAAE,QAAQ,CAAC,YAAY;CAC9B,CAAC,CAAC,EACH,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,EAAE,UAAU,EAAE,EAAE,GAAG,KAAK,EAAE,EAAE,CAAC,CAC9D,CAAC"}
|
@@ -2,8 +2,8 @@ import { CreateBucketCommand, } from '@aws-sdk/client-s3';
|
|
2
2
|
import { Effect, pipe } from 'effect';
|
3
3
|
import { FileStorageError } from './../../errors/index.js';
|
4
4
|
import { cloudflareR2StorageProvider } from './../providers/r2-file-storage.provider.js';
|
5
|
-
export const createBucket = (input) =>
|
5
|
+
export const createBucket = (input) => pipe(cloudflareR2StorageProvider, Effect.flatMap((provider) => Effect.tryPromise({
|
6
6
|
try: () => provider.send(new CreateBucketCommand(input)),
|
7
7
|
catch: (e) => new FileStorageError({ cause: e }),
|
8
|
-
}))));
|
8
|
+
})), Effect.withSpan('create-bucket', { attributes: { ...input } }));
|
9
9
|
//# sourceMappingURL=create-bucket.effect.js.map
|
@@ -1 +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,SAAS,CAAC;AAC3C,OAAO,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAExD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAA+B,EAAE,EAAE,CAC9D,
|
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,SAAS,CAAC;AAC3C,OAAO,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAExD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAA+B,EAAE,EAAE,CAC9D,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,EACD,MAAM,CAAC,QAAQ,CAAC,eAAe,EAAE,EAAE,UAAU,EAAE,EAAE,GAAG,KAAK,EAAE,EAAE,CAAC,CAC/D,CAAC"}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { DeleteObjectCommand } from '@aws-sdk/client-s3';
|
2
|
+
import { Effect, pipe } from 'effect';
|
3
|
+
import { FileStorageError } from './../../errors/index.js';
|
4
|
+
import { cloudflareR2StorageProvider } from './../providers/r2-file-storage.provider.js';
|
5
|
+
export const deleteFile = ({ bucketName, documentKey, }) => pipe(cloudflareR2StorageProvider, Effect.flatMap((provider) => Effect.tryPromise({
|
6
|
+
try: () => provider.send(new DeleteObjectCommand({
|
7
|
+
Key: documentKey,
|
8
|
+
Bucket: bucketName,
|
9
|
+
})),
|
10
|
+
catch: (e) => new FileStorageError({ cause: e }),
|
11
|
+
})), Effect.withSpan('delete-file', {
|
12
|
+
attributes: { bucketName, documentKey },
|
13
|
+
}));
|
14
|
+
//# sourceMappingURL=delete-file.effect.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"delete-file.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/delete-file.effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAOxD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAyB,EACjD,UAAU,EACV,WAAW,GACc,EAAE,EAAE,CAC7B,IAAI,CACF,2BAA2B,EAC3B,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAC1B,MAAM,CAAC,UAAU,CAAC;IAChB,GAAG,EAAE,GAAG,EAAE,CACR,QAAQ,CAAC,IAAI,CACX,IAAI,mBAAmB,CAAC;QACtB,GAAG,EAAE,WAAW;QAChB,MAAM,EAAE,UAAU;KACnB,CAAC,CACH;IACH,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,gBAAgB,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;CACjD,CAAC,CACH,EACD,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE;IAC7B,UAAU,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE;CACxC,CAAC,CACH,CAAC"}
|
@@ -1,5 +1,7 @@
|
|
1
1
|
import { Effect, pipe } from 'effect';
|
2
2
|
import { cloudflareR2StorageProvider } from './../providers/r2-file-storage.provider.js';
|
3
3
|
import { getUrl } from './internal/index.js';
|
4
|
-
export const getFileUrl = (bucketName, documentKey) =>
|
4
|
+
export const getFileUrl = (bucketName, documentKey) => pipe(cloudflareR2StorageProvider, Effect.flatMap((provider) => getUrl(provider, bucketName, documentKey)), Effect.withSpan('get-file-url', {
|
5
|
+
attributes: { bucketName, documentKey },
|
6
|
+
}));
|
5
7
|
//# sourceMappingURL=get-file-url.effect.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"get-file-url.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/get-file-url.effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAExD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,UAAmB,EACnB,WAAmB,EACnB,EAAE,CACF,MAAM,CAAC,
|
1
|
+
{"version":3,"file":"get-file-url.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/get-file-url.effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAExD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,UAAmB,EACnB,WAAmB,EACnB,EAAE,CACF,IAAI,CACF,2BAA2B,EAC3B,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC,EACvE,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE;IAC9B,UAAU,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE;CACxC,CAAC,CACH,CAAC"}
|
@@ -1 +1 @@
|
|
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,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,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC"}
|
@@ -1,11 +1,16 @@
|
|
1
1
|
import { HttpClient } from '@effect/platform';
|
2
|
-
import { Effect } from 'effect';
|
2
|
+
import { Effect, pipe } from 'effect';
|
3
3
|
import { cloudflareR2StorageProvider } from './../../providers/r2-file-storage.provider.js';
|
4
4
|
import { getUrl } from './get-url.effect.js';
|
5
|
-
export const fetchFile = (bucketName, documentKey) => Effect.gen(function* () {
|
5
|
+
export const fetchFile = (bucketName, documentKey) => pipe(Effect.gen(function* () {
|
6
6
|
const provider = yield* cloudflareR2StorageProvider;
|
7
7
|
const url = yield* getUrl(provider, bucketName, documentKey);
|
8
8
|
const client = yield* HttpClient.HttpClient;
|
9
9
|
return yield* client.get(url);
|
10
|
-
})
|
10
|
+
}), Effect.withSpan('fetch-file', {
|
11
|
+
attributes: {
|
12
|
+
bucketName,
|
13
|
+
documentKey,
|
14
|
+
},
|
15
|
+
}));
|
11
16
|
//# sourceMappingURL=fetch-file.effect.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"fetch-file.effect.js","sourceRoot":"","sources":["../../../../../src/r2/implementations/internal/fetch-file.effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
1
|
+
{"version":3,"file":"fetch-file.effect.js","sourceRoot":"","sources":["../../../../../src/r2/implementations/internal/fetch-file.effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AAExD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,UAAkB,EAAE,WAAmB,EAAE,EAAE,CACnE,IAAI,CACF,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,2BAA2B,CAAC;IACpD,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;IAE7D,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC;IAC5C,OAAO,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAChC,CAAC,CAAC,EACF,MAAM,CAAC,QAAQ,CAAC,YAAY,EAAE;IAC5B,UAAU,EAAE;QACV,UAAU;QACV,WAAW;KACZ;CACF,CAAC,CACH,CAAC"}
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { GetObjectCommand } from '@aws-sdk/client-s3';
|
2
2
|
import { getSignedUrl as awsGetSignedUrl } from '@aws-sdk/s3-request-presigner';
|
3
|
-
import { Effect } from 'effect';
|
3
|
+
import { Effect, pipe } from 'effect';
|
4
4
|
import { FileStorageError } from './../../../errors/index.js';
|
5
5
|
const oneHourDuration = 60 * 60;
|
6
|
-
export const getUrl = (provider, bucketName, documentKey) =>
|
6
|
+
export const getUrl = (provider, bucketName, documentKey) => pipe(Effect.tryPromise({
|
7
7
|
try: () => awsGetSignedUrl(provider, new GetObjectCommand({
|
8
8
|
Bucket: bucketName,
|
9
9
|
Key: documentKey,
|
@@ -11,5 +11,5 @@ export const getUrl = (provider, bucketName, documentKey) => Effect.withSpan('ge
|
|
11
11
|
expiresIn: oneHourDuration,
|
12
12
|
}),
|
13
13
|
catch: (e) => new FileStorageError({ cause: e }),
|
14
|
-
}));
|
14
|
+
}), Effect.withSpan('get-url', { attributes: { bucketName, documentKey } }));
|
15
15
|
//# sourceMappingURL=get-url.effect.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"get-url.effect.js","sourceRoot":"","sources":["../../../../../src/r2/implementations/internal/get-url.effect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,YAAY,IAAI,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
1
|
+
{"version":3,"file":"get-url.effect.js","sourceRoot":"","sources":["../../../../../src/r2/implementations/internal/get-url.effect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,YAAY,IAAI,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAE3C,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,CAAC;AAEhC,MAAM,CAAC,MAAM,MAAM,GAAG,CACpB,QAAkB,EAClB,UAAmB,EACnB,WAAoB,EACpB,EAAE,CACF,IAAI,CACF,MAAM,CAAC,UAAU,CAAC;IAChB,GAAG,EAAE,GAAG,EAAE,CACR,eAAe,CACb,QAAQ,EACR,IAAI,gBAAgB,CAAC;QACnB,MAAM,EAAE,UAAU;QAClB,GAAG,EAAE,WAAW;KACjB,CAAC,EACF;QACE,SAAS,EAAE,eAAe;KAC3B,CACF;IACH,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,gBAAgB,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;CACjD,CAAC,EACF,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,UAAU,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,EAAE,CAAC,CACxE,CAAC"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Effect, pipe } from 'effect';
|
2
2
|
import { fetchFile } from './internal/index.js';
|
3
|
-
export const readAsJson = (bucketName, documentKey) => Effect.withSpan('read-as-json', {
|
3
|
+
export const readAsJson = (bucketName, documentKey) => pipe(fetchFile(bucketName, documentKey), Effect.flatMap((response) => response.json), Effect.map((json) => json), Effect.withSpan('read-as-json', {
|
4
4
|
attributes: { bucketName, documentKey },
|
5
|
-
})
|
5
|
+
}));
|
6
6
|
//# sourceMappingURL=read-as-json.effect.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"read-as-json.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/read-as-json.effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,MAAM,CAAC,MAAM,UAAU,GAAG,CAIxB,UAAmB,EACnB,WAAmB,EACnB,EAAE,CACF,
|
1
|
+
{"version":3,"file":"read-as-json.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/read-as-json.effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,MAAM,CAAC,MAAM,UAAU,GAAG,CAIxB,UAAmB,EACnB,WAAmB,EACnB,EAAE,CACF,IAAI,CACF,SAAS,CAAC,UAAU,EAAE,WAAW,CAAC,EAClC,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAC3C,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAc,CAAC,EACpC,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE;IAC9B,UAAU,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE;CACxC,CAAC,CACH,CAAC"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Effect, pipe } from 'effect';
|
2
2
|
import { fetchFile } from './internal/index.js';
|
3
|
-
export const readAsRawBinary = (bucketName, documentKey) => Effect.withSpan('read-as-raw-binary', {
|
3
|
+
export const readAsRawBinary = (bucketName, documentKey) => pipe(fetchFile(bucketName, documentKey), Effect.flatMap((response) => response.arrayBuffer), Effect.withSpan('read-as-raw-binary', {
|
4
4
|
attributes: { bucketName, documentKey },
|
5
|
-
})
|
5
|
+
}));
|
6
6
|
//# sourceMappingURL=read-as-raw-binary.effect.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"read-as-raw-binary.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/read-as-raw-binary.effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,UAAmB,EACnB,WAAmB,EACnB,EAAE,CACF,
|
1
|
+
{"version":3,"file":"read-as-raw-binary.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/read-as-raw-binary.effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,UAAmB,EACnB,WAAmB,EACnB,EAAE,CACF,IAAI,CACF,SAAS,CAAC,UAAU,EAAE,WAAW,CAAC,EAClC,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,EAClD,MAAM,CAAC,QAAQ,CAAC,oBAAoB,EAAE;IACpC,UAAU,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE;CACxC,CAAC,CACH,CAAC"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Effect, pipe } from 'effect';
|
2
2
|
import { fetchFile } from './internal/index.js';
|
3
|
-
export const readAsText = (bucketName, documentKey) => Effect.withSpan('read-as-text', {
|
3
|
+
export const readAsText = (bucketName, documentKey) => pipe(fetchFile(bucketName, documentKey), Effect.flatMap((response) => response.text), Effect.withSpan('read-as-text', {
|
4
4
|
attributes: { bucketName, documentKey },
|
5
|
-
})
|
5
|
+
}));
|
6
6
|
//# sourceMappingURL=read-as-text.effect.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"read-as-text.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/read-as-text.effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,UAAmB,EACnB,WAAmB,EACnB,EAAE,CACF,
|
1
|
+
{"version":3,"file":"read-as-text.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/read-as-text.effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,UAAmB,EACnB,WAAmB,EACnB,EAAE,CACF,IAAI,CACF,SAAS,CAAC,UAAU,EAAE,WAAW,CAAC,EAClC,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,EAC3C,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE;IAC9B,UAAU,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE;CACxC,CAAC,CACH,CAAC"}
|
@@ -2,9 +2,7 @@ import { PutObjectCommand } from '@aws-sdk/client-s3';
|
|
2
2
|
import { Effect, pipe } from 'effect';
|
3
3
|
import { FileStorageError } from './../../errors/index.js';
|
4
4
|
import { cloudflareR2StorageProvider } from './../providers/r2-file-storage.provider.js';
|
5
|
-
export const uploadFile = ({ bucketName, documentKey, data, contentType, }) => Effect.
|
6
|
-
attributes: { bucketName, documentKey, contentType },
|
7
|
-
})(pipe(cloudflareR2StorageProvider, Effect.flatMap((provider) => Effect.tryPromise({
|
5
|
+
export const uploadFile = ({ bucketName, documentKey, data, contentType, }) => pipe(cloudflareR2StorageProvider, Effect.flatMap((provider) => Effect.tryPromise({
|
8
6
|
try: () => provider.send(new PutObjectCommand({
|
9
7
|
Body: data,
|
10
8
|
ContentType: contentType,
|
@@ -12,5 +10,7 @@ export const uploadFile = ({ bucketName, documentKey, data, contentType, }) => E
|
|
12
10
|
Bucket: bucketName,
|
13
11
|
})),
|
14
12
|
catch: (e) => new FileStorageError({ cause: e }),
|
15
|
-
}))
|
13
|
+
})), Effect.withSpan('upload-file', {
|
14
|
+
attributes: { bucketName, documentKey, contentType },
|
15
|
+
}));
|
16
16
|
//# sourceMappingURL=upload-file.effect.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"upload-file.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/upload-file.effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AASxD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAyB,EACjD,UAAU,EACV,WAAW,EACX,IAAI,EACJ,WAAW,GACc,EAAE,EAAE,CAC7B,
|
1
|
+
{"version":3,"file":"upload-file.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/upload-file.effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,2BAA2B,EAAE,MAAM,WAAW,CAAC;AASxD,MAAM,CAAC,MAAM,UAAU,GAAG,CAAyB,EACjD,UAAU,EACV,WAAW,EACX,IAAI,EACJ,WAAW,GACc,EAAE,EAAE,CAC7B,IAAI,CACF,2BAA2B,EAC3B,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAC1B,MAAM,CAAC,UAAU,CAAC;IAChB,GAAG,EAAE,GAAG,EAAE,CACR,QAAQ,CAAC,IAAI,CACX,IAAI,gBAAgB,CAAC;QACnB,IAAI,EAAE,IAAI;QACV,WAAW,EAAE,WAAqB;QAClC,GAAG,EAAE,WAAW;QAChB,MAAM,EAAE,UAAU;KACnB,CAAC,CACH;IACH,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,gBAAgB,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;CACjD,CAAC,CACH,EACD,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE;IAC7B,UAAU,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE;CACrD,CAAC,CACH,CAAC"}
|
@@ -1,11 +1,12 @@
|
|
1
1
|
import { Layer } from 'effect';
|
2
|
-
import { bucketInfos, createBucket, getFileUrl, readAsJson, readAsRawBinary, readAsText, uploadFile, } from './implementations/index.js';
|
2
|
+
import { bucketInfos, createBucket, deleteFile, getFileUrl, readAsJson, readAsRawBinary, readAsText, uploadFile, } from './implementations/index.js';
|
3
3
|
import { FileStorageLayerContext } from '../layer/file-storage.layer.js';
|
4
4
|
export const CloudflareR2StorageLayerLive = Layer.succeed(FileStorageLayerContext, FileStorageLayerContext.of({
|
5
5
|
createBucket,
|
6
6
|
bucketInfos,
|
7
7
|
getFileUrl,
|
8
8
|
uploadFile,
|
9
|
+
deleteFile,
|
9
10
|
readAsText,
|
10
11
|
readAsJson,
|
11
12
|
readAsRawBinary,
|
@@ -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,EACL,WAAW,EACX,YAAY,EACZ,UAAU,EACV,UAAU,EACV,eAAe,EACf,UAAU,EACV,UAAU,GACX,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEzE,MAAM,CAAC,MAAM,4BAA4B,GAAG,KAAK,CAAC,OAAO,CACvD,uBAAuB,EACvB,uBAAuB,CAAC,EAAE,CAAC;IACzB,YAAY;IACZ,WAAW;IACX,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,EACL,WAAW,EACX,YAAY,EACZ,UAAU,EACV,UAAU,EACV,UAAU,EACV,eAAe,EACf,UAAU,EACV,UAAU,GACX,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEzE,MAAM,CAAC,MAAM,4BAA4B,GAAG,KAAK,CAAC,OAAO,CACvD,uBAAuB,EACvB,uBAAuB,CAAC,EAAE,CAAC;IACzB,YAAY;IACZ,WAAW;IACX,UAAU;IACV,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.
|
3
|
+
"version": "1.0.37",
|
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": [
|
@@ -46,11 +46,11 @@
|
|
46
46
|
"sync-icons": "bun generateReadmeIcons -h 50"
|
47
47
|
},
|
48
48
|
"dependencies": {
|
49
|
-
"@aws-sdk/client-s3": "^3.
|
50
|
-
"@aws-sdk/s3-request-presigner": "^3.
|
51
|
-
"@effect/platform": "^0.
|
49
|
+
"@aws-sdk/client-s3": "^3.709.0",
|
50
|
+
"@aws-sdk/s3-request-presigner": "^3.709.0",
|
51
|
+
"@effect/platform": "^0.71.2",
|
52
52
|
"dotenv": "^16.4.7",
|
53
|
-
"effect": "^3.11.
|
53
|
+
"effect": "^3.11.7"
|
54
54
|
},
|
55
55
|
"peerDependencies": {
|
56
56
|
"typescript": "5.7.2"
|
@@ -63,12 +63,11 @@
|
|
63
63
|
"comment-json": "^4.2.5",
|
64
64
|
"copyfiles": "^2.4.1",
|
65
65
|
"del-cli": "^6.0.0",
|
66
|
-
"effect-errors": "^1.7.
|
66
|
+
"effect-errors": "^1.7.44",
|
67
67
|
"fs-extra": "^11.2.0",
|
68
68
|
"glob": "^11.0.0",
|
69
69
|
"readme-package-icons": "^1.1.16",
|
70
|
-
"ts-
|
71
|
-
"ts-paths-resolver": "1.2.6",
|
70
|
+
"ts-paths-resolver": "1.2.9",
|
72
71
|
"tsx": "^4.19.2",
|
73
72
|
"vitest": "^2.1.8",
|
74
73
|
"vitest-mock-extended": "^2.0.2"
|