effect-cloudflare-r2-layer 1.0.8 → 1.0.10
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +103 -26
- package/cjs/effects/index.js +18 -0
- package/cjs/effects/index.js.map +1 -0
- package/cjs/errors/bucket-not-found.js +8 -0
- package/cjs/errors/bucket-not-found.js.map +1 -0
- package/cjs/errors/index.js +19 -0
- package/cjs/errors/index.js.map +1 -0
- package/cjs/layer/file-storage.layer.js +8 -7
- package/cjs/layer/file-storage.layer.js.map +1 -1
- package/cjs/r2/implementations/bucket-infos.effect.js +23 -0
- package/cjs/r2/implementations/bucket-infos.effect.js.map +1 -0
- package/cjs/r2/implementations/create-bucket.effect.js +4 -4
- package/cjs/r2/implementations/create-bucket.effect.js.map +1 -1
- package/cjs/r2/implementations/get-file-url.effect.js +3 -3
- 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 +2 -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/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 +8 -7
- package/cjs/r2/r2-file-storage.layer.js.map +1 -1
- package/dts/cjs/effects/index.d.ts +1 -0
- package/dts/cjs/errors/bucket-not-found.d.ts +9 -0
- package/dts/cjs/errors/index.d.ts +2 -0
- package/dts/cjs/index.d.ts +2 -1
- package/dts/cjs/layer/file-storage.layer.d.ts +5 -3
- package/dts/cjs/r2/implementations/bucket-infos.effect.d.ts +9 -0
- package/dts/cjs/r2/implementations/create-bucket.effect.d.ts +1 -1
- package/dts/cjs/r2/implementations/index.d.ts +1 -0
- package/dts/cjs/r2/implementations/internal/get-url.effect.d.ts +1 -1
- package/dts/cjs/r2/implementations/upload-file.effect.d.ts +1 -1
- package/dts/esm/effects/index.d.ts +1 -0
- package/dts/esm/errors/bucket-not-found.d.ts +9 -0
- package/dts/esm/errors/index.d.ts +2 -0
- package/dts/esm/index.d.ts +2 -1
- package/dts/esm/layer/file-storage.layer.d.ts +5 -3
- package/dts/esm/r2/implementations/bucket-infos.effect.d.ts +9 -0
- package/dts/esm/r2/implementations/create-bucket.effect.d.ts +1 -1
- package/dts/esm/r2/implementations/index.d.ts +1 -0
- package/dts/esm/r2/implementations/internal/get-url.effect.d.ts +1 -1
- package/dts/esm/r2/implementations/upload-file.effect.d.ts +1 -1
- package/esm/effects/index.js +2 -0
- package/esm/effects/index.js.map +1 -0
- package/esm/errors/bucket-not-found.js +4 -0
- package/esm/errors/bucket-not-found.js.map +1 -0
- package/esm/errors/index.js +3 -0
- package/esm/errors/index.js.map +1 -0
- package/esm/layer/file-storage.layer.js +2 -1
- package/esm/layer/file-storage.layer.js.map +1 -1
- package/esm/r2/implementations/bucket-infos.effect.js +19 -0
- package/esm/r2/implementations/bucket-infos.effect.js.map +1 -0
- 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/get-file-url.effect.js +2 -2
- 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 +1 -1
- package/esm/r2/implementations/internal/fetch-file.effect.js.map +1 -1
- package/esm/r2/implementations/internal/get-url.effect.js +1 -1
- package/esm/r2/implementations/internal/get-url.effect.js.map +1 -1
- package/esm/r2/implementations/upload-file.effect.js +2 -2
- 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 +1 -1
package/README.md
CHANGED
@@ -60,13 +60,91 @@ 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
|
+
| [`bucketInfos`](#-bucketinfos) | Get bucket infos |
|
67
|
+
| [`uploadFile`](#-uploadfile) | Adds a file to the specified bucket |
|
68
|
+
| [`getFileUrl`](#-getfileurl) | Gets a pre-signed url to fetch a ressource by its `filename` from the specified `bucket`. |
|
69
|
+
| [`readAsJson`](#-readasjson) | Fetches a file, expecting a content extending `Record<string, unknown>`. |
|
70
|
+
| [`readAsText`](#-readastext) | Fetches a file as a string. |
|
71
|
+
| [`readAsRawBinary`](#-readasrawbinary) | Fetches a file as raw binary (ArrayBuffer). |
|
72
|
+
|
73
|
+
### 🔶 `createBucket`
|
74
|
+
|
75
|
+
```typescript
|
76
|
+
type createBucket = (
|
77
|
+
input: CreateBucketCommandInput
|
78
|
+
) => Effect.Effect<
|
79
|
+
CreateBucketCommandOutput,
|
80
|
+
FileStorageError | ConfigError.ConfigError,
|
81
|
+
FileStorage
|
82
|
+
>;
|
83
|
+
```
|
84
|
+
|
85
|
+
#### 🧿 Example
|
86
|
+
|
87
|
+
```typescript
|
88
|
+
import { Effect, pipe } from 'effect';
|
89
|
+
import {
|
90
|
+
CloudflareR2StorageLayerLive,
|
91
|
+
FileStorageLayer,
|
92
|
+
} from 'effect-cloudflare-r2-layer';
|
93
|
+
|
94
|
+
const task = pipe(
|
95
|
+
Effect.gen(function* () {
|
96
|
+
const result = yield* FileStorageLayer.createBucket({
|
97
|
+
Bucket: 'test',
|
98
|
+
CreateBucketConfiguration: {
|
99
|
+
Bucket: {
|
100
|
+
Type: 'Directory',
|
101
|
+
DataRedundancy: 'SingleAvailabilityZone',
|
102
|
+
},
|
103
|
+
},
|
104
|
+
});
|
105
|
+
|
106
|
+
// ...
|
107
|
+
}),
|
108
|
+
Effect.provide(CloudflareR2StorageLayerLive)
|
109
|
+
);
|
110
|
+
```
|
111
|
+
|
112
|
+
### 🔶 `bucketInfos`
|
113
|
+
|
114
|
+
```typescript
|
115
|
+
type BucketInfosResult = {
|
116
|
+
region?: string;
|
117
|
+
};
|
118
|
+
|
119
|
+
type bucketInfos = (
|
120
|
+
input: HeadBucketCommandInput
|
121
|
+
) => Effect.Effect<
|
122
|
+
BucketInfosResult,
|
123
|
+
ConfigError | FileStorageError | BucketNotFoundError,
|
124
|
+
FileStorage
|
125
|
+
>;
|
126
|
+
```
|
127
|
+
|
128
|
+
#### 🧿 Example
|
129
|
+
|
130
|
+
```typescript
|
131
|
+
import { Effect, pipe } from 'effect';
|
132
|
+
import {
|
133
|
+
CloudflareR2StorageLayerLive,
|
134
|
+
FileStorageLayer,
|
135
|
+
} from 'effect-cloudflare-r2-layer';
|
136
|
+
|
137
|
+
const task = pipe(
|
138
|
+
Effect.gen(function* () {
|
139
|
+
const result = yield* FileStorageLayer.bucketInfos({
|
140
|
+
Bucket: 'assets',
|
141
|
+
});
|
142
|
+
|
143
|
+
// ...
|
144
|
+
}),
|
145
|
+
Effect.provide(CloudflareR2StorageLayerLive)
|
146
|
+
);
|
147
|
+
```
|
70
148
|
|
71
149
|
### 🔶 `uploadFile`
|
72
150
|
|
@@ -80,15 +158,12 @@ interface UploadFileInput<TBucket extends string> {
|
|
80
158
|
contentType: string | undefined;
|
81
159
|
}
|
82
160
|
|
83
|
-
type uploadFile = <TBucket extends string>(
|
84
|
-
|
85
|
-
|
86
|
-
data,
|
87
|
-
contentType,
|
88
|
-
}: UploadFileInput<TBucket>) => Effect.Effect<
|
161
|
+
type uploadFile = <TBucket extends string>(
|
162
|
+
input: UploadFileInput<TBucket>
|
163
|
+
) => Effect.Effect<
|
89
164
|
PutObjectCommandOutput,
|
90
|
-
FileStorageError | ConfigError,
|
91
|
-
|
165
|
+
FileStorageError | ConfigError.ConfigError,
|
166
|
+
FileStorage
|
92
167
|
>;
|
93
168
|
```
|
94
169
|
|
@@ -168,15 +243,17 @@ const task = pipe(
|
|
168
243
|
Fetches a file, expecting a content extending `Record<string, unknown>`.
|
169
244
|
|
170
245
|
```typescript
|
171
|
-
readAsJson
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
246
|
+
type readAsJson = <
|
247
|
+
TBucket extends string,
|
248
|
+
TShape extends Record<string, unknown>
|
249
|
+
>(
|
250
|
+
bucket: TBucket,
|
251
|
+
fileName: string
|
252
|
+
) => Effect.Effect<
|
253
|
+
TShape,
|
254
|
+
HttpClientError | FileStorageError | ConfigError.ConfigError,
|
255
|
+
Scope | HttpClient.Service | FileStorage
|
256
|
+
>;
|
180
257
|
```
|
181
258
|
|
182
259
|
#### 🧿 Example
|
@@ -226,7 +303,7 @@ readAsText: <TBucket extends string>(
|
|
226
303
|
Effect.Effect<
|
227
304
|
string,
|
228
305
|
ConfigError | HttpClientError | FileStorageError,
|
229
|
-
Scope | HttpClient.
|
306
|
+
Scope | HttpClient.Service | FileStorage
|
230
307
|
>;
|
231
308
|
```
|
232
309
|
|
@@ -272,7 +349,7 @@ readAsRawBinary: <TBucket extends string>(
|
|
272
349
|
Effect.Effect<
|
273
350
|
ArrayBuffer,
|
274
351
|
ConfigError | HttpClientError | FileStorageError,
|
275
|
-
Scope | HttpClient.
|
352
|
+
Scope | HttpClient.Service | FileStorage
|
276
353
|
>;
|
277
354
|
```
|
278
355
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./tapLayer.effect.js"), exports);
|
18
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/effects/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.BucketNotFoundError = void 0;
|
4
|
+
const Data_1 = require("effect/Data");
|
5
|
+
class BucketNotFoundError extends (0, Data_1.TaggedError)('bucket-not-found-error') {
|
6
|
+
}
|
7
|
+
exports.BucketNotFoundError = BucketNotFoundError;
|
8
|
+
//# sourceMappingURL=bucket-not-found.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"bucket-not-found.js","sourceRoot":"","sources":["../../../src/errors/bucket-not-found.ts"],"names":[],"mappings":";;;AAAA,sCAA0C;AAE1C,MAAa,mBAAoB,SAAQ,IAAA,kBAAW,EAAC,wBAAwB,CAG3E;CAAG;AAHL,kDAGK"}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./bucket-not-found.js"), exports);
|
18
|
+
__exportStar(require("./file-storage.error.js"), exports);
|
19
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/errors/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wDAAsC;AACtC,0DAAwC"}
|
@@ -2,14 +2,15 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.FileStorageLayer = exports.FileStorageLayerContext = void 0;
|
4
4
|
const effect_1 = require("effect");
|
5
|
-
const
|
5
|
+
const _effects_1 = require("@effects");
|
6
6
|
exports.FileStorageLayerContext = effect_1.Context.GenericTag('file-storage');
|
7
7
|
exports.FileStorageLayer = {
|
8
|
-
createBucket: (input) => (0,
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
createBucket: (input) => (0, _effects_1.tapLayer)(exports.FileStorageLayerContext, ({ createBucket }) => createBucket(input)),
|
9
|
+
bucketInfos: (input) => (0, _effects_1.tapLayer)(exports.FileStorageLayerContext, ({ bucketInfos }) => bucketInfos(input)),
|
10
|
+
getFileUrl: (bucket, fileName) => (0, _effects_1.tapLayer)(exports.FileStorageLayerContext, ({ getFileUrl }) => getFileUrl(bucket, fileName)),
|
11
|
+
readAsRawBinary: (bucket, fileName) => (0, _effects_1.tapLayer)(exports.FileStorageLayerContext, ({ readAsRawBinary }) => readAsRawBinary(bucket, fileName)),
|
12
|
+
readAsJson: (bucket, fileName) => (0, _effects_1.tapLayer)(exports.FileStorageLayerContext, ({ readAsJson }) => readAsJson(bucket, fileName)),
|
13
|
+
readAsText: (bucket, fileName) => (0, _effects_1.tapLayer)(exports.FileStorageLayerContext, ({ readAsText }) => readAsText(bucket, fileName)),
|
14
|
+
uploadFile: (input) => (0, _effects_1.tapLayer)(exports.FileStorageLayerContext, ({ uploadFile }) => uploadFile(input)),
|
14
15
|
};
|
15
16
|
//# 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":";;;AAEA,mCAAiC;AAWjC,
|
1
|
+
{"version":3,"file":"file-storage.layer.js","sourceRoot":"","sources":["../../../src/layer/file-storage.layer.ts"],"names":[],"mappings":";;;AAEA,mCAAiC;AAWjC,uCAAoC;AA8DvB,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,CAAC,KAA6B,EAAE,EAAE,CAC7C,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;CAC3E,CAAC"}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.bucketInfos = void 0;
|
4
|
+
const client_s3_1 = require("@aws-sdk/client-s3");
|
5
|
+
const effect_1 = require("effect");
|
6
|
+
const _errors_1 = require("@errors");
|
7
|
+
const _provider_1 = require("@provider");
|
8
|
+
const hasName = (error) => {
|
9
|
+
return error?.name !== undefined;
|
10
|
+
};
|
11
|
+
const bucketInfos = (input) => effect_1.Effect.withSpan('bucket-infos', { attributes: { ...input } })((0, effect_1.pipe)(_provider_1.cloudflareR2StorageProvider, effect_1.Effect.flatMap((provider) => effect_1.Effect.tryPromise({
|
12
|
+
try: () => provider.send(new client_s3_1.HeadBucketCommand(input)),
|
13
|
+
catch: (e) => {
|
14
|
+
if (hasName(e) && e.name === 'NotFound') {
|
15
|
+
return new _errors_1.BucketNotFoundError({ cause: e });
|
16
|
+
}
|
17
|
+
return new _errors_1.FileStorageError({ cause: e });
|
18
|
+
},
|
19
|
+
})), effect_1.Effect.map((response) => ({
|
20
|
+
region: response.BucketRegion,
|
21
|
+
}))));
|
22
|
+
exports.bucketInfos = bucketInfos;
|
23
|
+
//# sourceMappingURL=bucket-infos.effect.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"bucket-infos.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/bucket-infos.effect.ts"],"names":[],"mappings":";;;AAAA,kDAA+E;AAC/E,mCAAsC;AAEtC,qCAAgE;AAChE,yCAAwD;AAIxD,MAAM,OAAO,GAAG,CAAC,KAAc,EAAoC,EAAE;IACnE,OAAQ,KAAuB,EAAE,IAAI,KAAK,SAAS,CAAC;AACtD,CAAC,CAAC;AAMK,MAAM,WAAW,GAAG,CAAC,KAA6B,EAAE,EAAE,CAC3D,eAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,EAAE,UAAU,EAAE,EAAE,GAAG,KAAK,EAAE,EAAE,CAAC,CAC3D,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,CACJ,CACF,CAAC;AApBS,QAAA,WAAW,eAoBpB"}
|
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createBucket = void 0;
|
4
4
|
const client_s3_1 = require("@aws-sdk/client-s3");
|
5
5
|
const effect_1 = require("effect");
|
6
|
-
const
|
7
|
-
const
|
8
|
-
const createBucket = (input) => effect_1.Effect.withSpan('create-bucket', { attributes: { ...input } })((0, effect_1.pipe)(
|
6
|
+
const _errors_1 = require("@errors");
|
7
|
+
const _provider_1 = require("@provider");
|
8
|
+
const createBucket = (input) => effect_1.Effect.withSpan('create-bucket', { attributes: { ...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
|
-
catch: (e) => new
|
10
|
+
catch: (e) => new _errors_1.FileStorageError({ cause: e }),
|
11
11
|
}))));
|
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,
|
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,eAAM,CAAC,QAAQ,CAAC,eAAe,EAAE,EAAE,UAAU,EAAE,EAAE,GAAG,KAAK,EAAE,EAAE,CAAC,CAC5D,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,CACF,CACF,CAAC;AAXS,QAAA,YAAY,gBAWrB"}
|
@@ -2,8 +2,8 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.getFileUrl = void 0;
|
4
4
|
const effect_1 = require("effect");
|
5
|
-
const
|
6
|
-
const
|
7
|
-
const getFileUrl = (bucketName, documentKey) => effect_1.Effect.withSpan('get-file-url', { attributes: { bucketName, documentKey } })((0, effect_1.pipe)(
|
5
|
+
const _provider_1 = require("@provider");
|
6
|
+
const index_js_1 = require("./internal/index.js");
|
7
|
+
const getFileUrl = (bucketName, documentKey) => effect_1.Effect.withSpan('get-file-url', { attributes: { bucketName, documentKey } })((0, effect_1.pipe)(_provider_1.cloudflareR2StorageProvider, effect_1.Effect.flatMap((provider) => (0, index_js_1.getUrl)(provider, bucketName, documentKey))));
|
8
8
|
exports.getFileUrl = getFileUrl;
|
9
9
|
//# 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,
|
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,eAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,EAAE,UAAU,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,EAAE,CAAC,CAC1E,IAAA,aAAI,EACF,uCAA2B,EAC3B,eAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,IAAA,iBAAM,EAAC,QAAQ,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC,CACxE,CACF,CAAC;AATS,QAAA,UAAU,cASnB"}
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
17
|
__exportStar(require("./create-bucket.effect.js"), exports);
|
18
|
+
__exportStar(require("./bucket-infos.effect.js"), exports);
|
18
19
|
__exportStar(require("./get-file-url.effect.js"), exports);
|
19
20
|
__exportStar(require("./upload-file.effect.js"), exports);
|
20
21
|
__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,4DAA0C;AAC1C,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"}
|
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.fetchFile = void 0;
|
4
4
|
const platform_1 = require("@effect/platform");
|
5
5
|
const effect_1 = require("effect");
|
6
|
-
const
|
6
|
+
const _provider_1 = require("@provider");
|
7
7
|
const get_url_effect_js_1 = require("./get-url.effect.js");
|
8
8
|
const fetchFile = (bucketName, documentKey) => effect_1.Effect.gen(function* () {
|
9
|
-
const provider = yield*
|
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);
|
@@ -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,mCAAgC;AAEhC,
|
1
|
+
{"version":3,"file":"fetch-file.effect.js","sourceRoot":"","sources":["../../../../../src/r2/implementations/internal/fetch-file.effect.ts"],"names":[],"mappings":";;;AAAA,+CAA8C;AAC9C,mCAAgC;AAEhC,yCAAwD;AAExD,2DAA6C;AAEtC,MAAM,SAAS,GAAG,CAAC,UAAkB,EAAE,WAAmB,EAAE,EAAE,CACnE,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,CAAC;AAPQ,QAAA,SAAS,aAOjB"}
|
@@ -4,7 +4,7 @@ exports.getUrl = void 0;
|
|
4
4
|
const client_s3_1 = require("@aws-sdk/client-s3");
|
5
5
|
const s3_request_presigner_1 = require("@aws-sdk/s3-request-presigner");
|
6
6
|
const effect_1 = require("effect");
|
7
|
-
const
|
7
|
+
const _errors_1 = require("@errors");
|
8
8
|
const oneHourDuration = 60 * 60;
|
9
9
|
const getUrl = (provider, bucketName, documentKey) => effect_1.Effect.withSpan('get-url', { attributes: { bucketName, documentKey } })(effect_1.Effect.tryPromise({
|
10
10
|
try: () => (0, s3_request_presigner_1.getSignedUrl)(provider, new client_s3_1.GetObjectCommand({
|
@@ -13,7 +13,7 @@ const getUrl = (provider, bucketName, documentKey) => effect_1.Effect.withSpan('
|
|
13
13
|
}), {
|
14
14
|
expiresIn: oneHourDuration,
|
15
15
|
}),
|
16
|
-
catch: (e) => new
|
16
|
+
catch: (e) => new _errors_1.FileStorageError({ cause: e }),
|
17
17
|
}));
|
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,mCAAgC;AAEhC,
|
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,mCAAgC;AAEhC,qCAA2C;AAE3C,MAAM,eAAe,GAAG,EAAE,GAAG,EAAE,CAAC;AAEzB,MAAM,MAAM,GAAG,CACpB,QAAkB,EAClB,UAAmB,EACnB,WAAoB,EACpB,EAAE,CACF,eAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,UAAU,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,EAAE,CAAC,CACrE,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,CACH,CAAC;AApBS,QAAA,MAAM,UAoBf"}
|
@@ -3,18 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.uploadFile = void 0;
|
4
4
|
const client_s3_1 = require("@aws-sdk/client-s3");
|
5
5
|
const effect_1 = require("effect");
|
6
|
-
const
|
7
|
-
const
|
6
|
+
const _errors_1 = require("@errors");
|
7
|
+
const _provider_1 = require("@provider");
|
8
8
|
const uploadFile = ({ bucketName, documentKey, data, contentType, }) => effect_1.Effect.withSpan('upload-file', {
|
9
9
|
attributes: { bucketName, documentKey, contentType },
|
10
|
-
})((0, effect_1.pipe)(
|
10
|
+
})((0, effect_1.pipe)(_provider_1.cloudflareR2StorageProvider, effect_1.Effect.flatMap((provider) => effect_1.Effect.tryPromise({
|
11
11
|
try: () => provider.send(new client_s3_1.PutObjectCommand({
|
12
12
|
Body: data,
|
13
13
|
ContentType: contentType,
|
14
14
|
Key: documentKey,
|
15
15
|
Bucket: bucketName,
|
16
16
|
})),
|
17
|
-
catch: (e) => new
|
17
|
+
catch: (e) => new _errors_1.FileStorageError({ cause: e }),
|
18
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,
|
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,eAAM,CAAC,QAAQ,CAAC,aAAa,EAAE;IAC7B,UAAU,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE;CACrD,CAAC,CACA,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,CACF,CACF,CAAC;AA1BS,QAAA,UAAU,cA0BnB"}
|
@@ -2,14 +2,15 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.CloudflareR2StorageLayerLive = void 0;
|
4
4
|
const effect_1 = require("effect");
|
5
|
+
const _implementation_1 = require("@implementation");
|
5
6
|
const file_storage_layer_js_1 = require("../layer/file-storage.layer.js");
|
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:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
createBucket: _implementation_1.createBucket,
|
9
|
+
bucketInfos: _implementation_1.bucketInfos,
|
10
|
+
getFileUrl: _implementation_1.getFileUrl,
|
11
|
+
uploadFile: _implementation_1.uploadFile,
|
12
|
+
readAsText: _implementation_1.readAsText,
|
13
|
+
readAsJson: _implementation_1.readAsJson,
|
14
|
+
readAsRawBinary: _implementation_1.readAsRawBinary,
|
14
15
|
}));
|
15
16
|
//# sourceMappingURL=r2-file-storage.layer.js.map
|
@@ -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,qDAQyB;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,eAAe,EAAf,iCAAe;CAChB,CAAC,CACH,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './tapLayer.effect.js';
|
@@ -0,0 +1,9 @@
|
|
1
|
+
declare const BucketNotFoundError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
2
|
+
readonly _tag: "bucket-not-found-error";
|
3
|
+
} & Readonly<A>;
|
4
|
+
export declare class BucketNotFoundError extends BucketNotFoundError_base<{
|
5
|
+
cause?: unknown;
|
6
|
+
message?: string;
|
7
|
+
}> {
|
8
|
+
}
|
9
|
+
export {};
|
package/dts/cjs/index.d.ts
CHANGED
@@ -3,4 +3,5 @@ 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, HeadBucketCommandInput, } from '@aws-sdk/client-s3';
|
7
|
+
export type { BucketInfosResult } from './r2/implementations/bucket-infos.effect.js';
|
@@ -1,13 +1,14 @@
|
|
1
1
|
import { HttpClientError } from '@effect/platform/HttpClientError';
|
2
2
|
import type { ConfigError, Effect } from 'effect';
|
3
3
|
import { Context } from 'effect';
|
4
|
-
import { CreateBucketCommandInput, CreateBucketCommandOutput, PutObjectCommandOutput } from '@aws-sdk/client-s3';
|
4
|
+
import { CreateBucketCommandInput, CreateBucketCommandOutput, HeadBucketCommandInput, PutObjectCommandOutput } from '@aws-sdk/client-s3';
|
5
5
|
import { HttpClient } from '@effect/platform';
|
6
6
|
import { Scope } from 'effect/Scope';
|
7
|
-
import type { FileStorageError } from '
|
8
|
-
import type { UploadFileInput } from '
|
7
|
+
import type { BucketNotFoundError, FileStorageError } from '@errors';
|
8
|
+
import type { BucketInfosResult, UploadFileInput } from '@implementation';
|
9
9
|
export interface FileStorage {
|
10
10
|
readonly createBucket: (input: CreateBucketCommandInput) => Effect.Effect<CreateBucketCommandOutput, ConfigError.ConfigError | FileStorageError, never>;
|
11
|
+
readonly bucketInfos: (input: HeadBucketCommandInput) => Effect.Effect<BucketInfosResult, ConfigError.ConfigError | FileStorageError | BucketNotFoundError, never>;
|
11
12
|
readonly getFileUrl: <TBucket extends string>(fileName: string, bucket: TBucket) => Effect.Effect<string, FileStorageError | ConfigError.ConfigError>;
|
12
13
|
readonly readAsRawBinary: <TBucket extends string>(bucketName: TBucket, documentKey: string) => Effect.Effect<ArrayBuffer, ConfigError.ConfigError | HttpClientError | FileStorageError, Scope | HttpClient.HttpClient.Service>;
|
13
14
|
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>;
|
@@ -17,6 +18,7 @@ export interface FileStorage {
|
|
17
18
|
export declare const FileStorageLayerContext: Context.Tag<FileStorage, FileStorage>;
|
18
19
|
export declare const FileStorageLayer: {
|
19
20
|
createBucket: (input: CreateBucketCommandInput) => Effect.Effect<CreateBucketCommandOutput, FileStorageError | ConfigError.ConfigError, FileStorage>;
|
21
|
+
bucketInfos: (input: HeadBucketCommandInput) => Effect.Effect<BucketInfosResult, BucketNotFoundError | FileStorageError | ConfigError.ConfigError, FileStorage>;
|
20
22
|
getFileUrl: <TBucket extends string>(bucket: TBucket, fileName: string) => Effect.Effect<string, FileStorageError | ConfigError.ConfigError, FileStorage>;
|
21
23
|
readAsRawBinary: <TBucket extends string>(bucket: TBucket, fileName: string) => Effect.Effect<ArrayBuffer, FileStorageError | ConfigError.ConfigError | HttpClientError, Scope | HttpClient.HttpClient.Service | FileStorage>;
|
22
24
|
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,9 @@
|
|
1
|
+
import { HeadBucketCommandInput } from '@aws-sdk/client-s3';
|
2
|
+
import { Effect } from 'effect';
|
3
|
+
import { BucketNotFoundError, FileStorageError } from '@errors';
|
4
|
+
export type BucketInfosResult = {
|
5
|
+
region: string | undefined;
|
6
|
+
};
|
7
|
+
export declare const bucketInfos: (input: HeadBucketCommandInput) => Effect.Effect<{
|
8
|
+
region: string | undefined;
|
9
|
+
}, BucketNotFoundError | FileStorageError | import("effect/ConfigError").ConfigError, never>;
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import { CreateBucketCommandInput } from '@aws-sdk/client-s3';
|
2
2
|
import { Effect } from 'effect';
|
3
|
-
import { FileStorageError } from '
|
3
|
+
import { FileStorageError } from '@errors';
|
4
4
|
export declare const createBucket: (input: CreateBucketCommandInput) => Effect.Effect<import("@aws-sdk/client-s3").CreateBucketCommandOutput, FileStorageError | import("effect/ConfigError").ConfigError, never>;
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import type { S3Client } from '@aws-sdk/client-s3';
|
2
2
|
import { Effect } from 'effect';
|
3
|
-
import { FileStorageError } from '
|
3
|
+
import { FileStorageError } from '@errors';
|
4
4
|
export declare const getUrl: <TBucket extends string>(provider: S3Client, bucketName: TBucket, documentKey: TBucket) => Effect.Effect<string, FileStorageError, never>;
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from './tapLayer.effect.js';
|
@@ -0,0 +1,9 @@
|
|
1
|
+
declare const BucketNotFoundError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
2
|
+
readonly _tag: "bucket-not-found-error";
|
3
|
+
} & Readonly<A>;
|
4
|
+
export declare class BucketNotFoundError extends BucketNotFoundError_base<{
|
5
|
+
cause?: unknown;
|
6
|
+
message?: string;
|
7
|
+
}> {
|
8
|
+
}
|
9
|
+
export {};
|
package/dts/esm/index.d.ts
CHANGED
@@ -3,4 +3,5 @@ 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, HeadBucketCommandInput, } from '@aws-sdk/client-s3';
|
7
|
+
export type { BucketInfosResult } from './r2/implementations/bucket-infos.effect.js';
|
@@ -1,13 +1,14 @@
|
|
1
1
|
import { HttpClientError } from '@effect/platform/HttpClientError';
|
2
2
|
import type { ConfigError, Effect } from 'effect';
|
3
3
|
import { Context } from 'effect';
|
4
|
-
import { CreateBucketCommandInput, CreateBucketCommandOutput, PutObjectCommandOutput } from '@aws-sdk/client-s3';
|
4
|
+
import { CreateBucketCommandInput, CreateBucketCommandOutput, HeadBucketCommandInput, PutObjectCommandOutput } from '@aws-sdk/client-s3';
|
5
5
|
import { HttpClient } from '@effect/platform';
|
6
6
|
import { Scope } from 'effect/Scope';
|
7
|
-
import type { FileStorageError } from '
|
8
|
-
import type { UploadFileInput } from '
|
7
|
+
import type { BucketNotFoundError, FileStorageError } from '@errors';
|
8
|
+
import type { BucketInfosResult, UploadFileInput } from '@implementation';
|
9
9
|
export interface FileStorage {
|
10
10
|
readonly createBucket: (input: CreateBucketCommandInput) => Effect.Effect<CreateBucketCommandOutput, ConfigError.ConfigError | FileStorageError, never>;
|
11
|
+
readonly bucketInfos: (input: HeadBucketCommandInput) => Effect.Effect<BucketInfosResult, ConfigError.ConfigError | FileStorageError | BucketNotFoundError, never>;
|
11
12
|
readonly getFileUrl: <TBucket extends string>(fileName: string, bucket: TBucket) => Effect.Effect<string, FileStorageError | ConfigError.ConfigError>;
|
12
13
|
readonly readAsRawBinary: <TBucket extends string>(bucketName: TBucket, documentKey: string) => Effect.Effect<ArrayBuffer, ConfigError.ConfigError | HttpClientError | FileStorageError, Scope | HttpClient.HttpClient.Service>;
|
13
14
|
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>;
|
@@ -17,6 +18,7 @@ export interface FileStorage {
|
|
17
18
|
export declare const FileStorageLayerContext: Context.Tag<FileStorage, FileStorage>;
|
18
19
|
export declare const FileStorageLayer: {
|
19
20
|
createBucket: (input: CreateBucketCommandInput) => Effect.Effect<CreateBucketCommandOutput, FileStorageError | ConfigError.ConfigError, FileStorage>;
|
21
|
+
bucketInfos: (input: HeadBucketCommandInput) => Effect.Effect<BucketInfosResult, BucketNotFoundError | FileStorageError | ConfigError.ConfigError, FileStorage>;
|
20
22
|
getFileUrl: <TBucket extends string>(bucket: TBucket, fileName: string) => Effect.Effect<string, FileStorageError | ConfigError.ConfigError, FileStorage>;
|
21
23
|
readAsRawBinary: <TBucket extends string>(bucket: TBucket, fileName: string) => Effect.Effect<ArrayBuffer, FileStorageError | ConfigError.ConfigError | HttpClientError, Scope | HttpClient.HttpClient.Service | FileStorage>;
|
22
24
|
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,9 @@
|
|
1
|
+
import { HeadBucketCommandInput } from '@aws-sdk/client-s3';
|
2
|
+
import { Effect } from 'effect';
|
3
|
+
import { BucketNotFoundError, FileStorageError } from '@errors';
|
4
|
+
export type BucketInfosResult = {
|
5
|
+
region: string | undefined;
|
6
|
+
};
|
7
|
+
export declare const bucketInfos: (input: HeadBucketCommandInput) => Effect.Effect<{
|
8
|
+
region: string | undefined;
|
9
|
+
}, BucketNotFoundError | FileStorageError | import("effect/ConfigError").ConfigError, never>;
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import { CreateBucketCommandInput } from '@aws-sdk/client-s3';
|
2
2
|
import { Effect } from 'effect';
|
3
|
-
import { FileStorageError } from '
|
3
|
+
import { FileStorageError } from '@errors';
|
4
4
|
export declare const createBucket: (input: CreateBucketCommandInput) => Effect.Effect<import("@aws-sdk/client-s3").CreateBucketCommandOutput, FileStorageError | import("effect/ConfigError").ConfigError, never>;
|
@@ -1,4 +1,4 @@
|
|
1
1
|
import type { S3Client } from '@aws-sdk/client-s3';
|
2
2
|
import { Effect } from 'effect';
|
3
|
-
import { FileStorageError } from '
|
3
|
+
import { FileStorageError } from '@errors';
|
4
4
|
export declare const getUrl: <TBucket extends string>(provider: S3Client, bucketName: TBucket, documentKey: TBucket) => Effect.Effect<string, FileStorageError, never>;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/effects/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"bucket-not-found.js","sourceRoot":"","sources":["../../../src/errors/bucket-not-found.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,MAAM,OAAO,mBAAoB,SAAQ,WAAW,CAAC,wBAAwB,CAG3E;CAAG"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC"}
|
@@ -1,8 +1,9 @@
|
|
1
1
|
import { Context } from 'effect';
|
2
|
-
import { tapLayer } from '
|
2
|
+
import { tapLayer } from '@effects';
|
3
3
|
export const FileStorageLayerContext = Context.GenericTag('file-storage');
|
4
4
|
export const FileStorageLayer = {
|
5
5
|
createBucket: (input) => tapLayer(FileStorageLayerContext, ({ createBucket }) => createBucket(input)),
|
6
|
+
bucketInfos: (input) => tapLayer(FileStorageLayerContext, ({ bucketInfos }) => bucketInfos(input)),
|
6
7
|
getFileUrl: (bucket, fileName) => tapLayer(FileStorageLayerContext, ({ getFileUrl }) => getFileUrl(bucket, fileName)),
|
7
8
|
readAsRawBinary: (bucket, fileName) => tapLayer(FileStorageLayerContext, ({ readAsRawBinary }) => readAsRawBinary(bucket, fileName)),
|
8
9
|
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;AAWjC,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
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;AAWjC,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AA8DpC,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,CAAC,KAA6B,EAAE,EAAE,CAC7C,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;CAC3E,CAAC"}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { HeadBucketCommand } from '@aws-sdk/client-s3';
|
2
|
+
import { Effect, pipe } from 'effect';
|
3
|
+
import { BucketNotFoundError, FileStorageError } from '@errors';
|
4
|
+
import { cloudflareR2StorageProvider } from '@provider';
|
5
|
+
const hasName = (error) => {
|
6
|
+
return error?.name !== undefined;
|
7
|
+
};
|
8
|
+
export const bucketInfos = (input) => Effect.withSpan('bucket-infos', { attributes: { ...input } })(pipe(cloudflareR2StorageProvider, Effect.flatMap((provider) => Effect.tryPromise({
|
9
|
+
try: () => provider.send(new HeadBucketCommand(input)),
|
10
|
+
catch: (e) => {
|
11
|
+
if (hasName(e) && e.name === 'NotFound') {
|
12
|
+
return new BucketNotFoundError({ cause: e });
|
13
|
+
}
|
14
|
+
return new FileStorageError({ cause: e });
|
15
|
+
},
|
16
|
+
})), Effect.map((response) => ({
|
17
|
+
region: response.BucketRegion,
|
18
|
+
}))));
|
19
|
+
//# sourceMappingURL=bucket-infos.effect.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"bucket-infos.effect.js","sourceRoot":"","sources":["../../../../src/r2/implementations/bucket-infos.effect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAA0B,MAAM,oBAAoB,CAAC;AAC/E,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;AAMF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAA6B,EAAE,EAAE,CAC3D,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,EAAE,UAAU,EAAE,EAAE,GAAG,KAAK,EAAE,EAAE,CAAC,CAC3D,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,CACJ,CACF,CAAC"}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { CreateBucketCommand, } from '@aws-sdk/client-s3';
|
2
2
|
import { Effect, pipe } from 'effect';
|
3
|
-
import { FileStorageError } from '
|
4
|
-
import { cloudflareR2StorageProvider } from '
|
3
|
+
import { FileStorageError } from '@errors';
|
4
|
+
import { cloudflareR2StorageProvider } from '@provider';
|
5
5
|
export const createBucket = (input) => Effect.withSpan('create-bucket', { attributes: { ...input } })(pipe(cloudflareR2StorageProvider, Effect.flatMap((provider) => Effect.tryPromise({
|
6
6
|
try: () => provider.send(new CreateBucketCommand(input)),
|
7
7
|
catch: (e) => new FileStorageError({ cause: e }),
|
@@ -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,
|
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,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,5 +1,5 @@
|
|
1
1
|
import { Effect, pipe } from 'effect';
|
2
|
-
import { cloudflareR2StorageProvider } from '
|
3
|
-
import { getUrl } from './internal/
|
2
|
+
import { cloudflareR2StorageProvider } from '@provider';
|
3
|
+
import { getUrl } from './internal/index.js';
|
4
4
|
export const getFileUrl = (bucketName, documentKey) => Effect.withSpan('get-file-url', { attributes: { bucketName, documentKey } })(pipe(cloudflareR2StorageProvider, Effect.flatMap((provider) => getUrl(provider, bucketName, documentKey))));
|
5
5
|
//# 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,
|
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,QAAQ,CAAC,cAAc,EAAE,EAAE,UAAU,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,EAAE,CAAC,CAC1E,IAAI,CACF,2BAA2B,EAC3B,MAAM,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC,CACxE,CACF,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,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"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { HttpClient } from '@effect/platform';
|
2
2
|
import { Effect } from 'effect';
|
3
|
-
import { cloudflareR2StorageProvider } from '
|
3
|
+
import { cloudflareR2StorageProvider } from '@provider';
|
4
4
|
import { getUrl } from './get-url.effect.js';
|
5
5
|
export const fetchFile = (bucketName, documentKey) => Effect.gen(function* () {
|
6
6
|
const provider = yield* cloudflareR2StorageProvider;
|
@@ -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;AAEhC,OAAO,EAAE,2BAA2B,EAAE,MAAM,
|
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;AAEhC,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,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,CAAC"}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { GetObjectCommand } from '@aws-sdk/client-s3';
|
2
2
|
import { getSignedUrl as awsGetSignedUrl } from '@aws-sdk/s3-request-presigner';
|
3
3
|
import { Effect } from 'effect';
|
4
|
-
import { FileStorageError } from '
|
4
|
+
import { FileStorageError } from '@errors';
|
5
5
|
const oneHourDuration = 60 * 60;
|
6
6
|
export const getUrl = (provider, bucketName, documentKey) => Effect.withSpan('get-url', { attributes: { bucketName, documentKey } })(Effect.tryPromise({
|
7
7
|
try: () => awsGetSignedUrl(provider, new GetObjectCommand({
|
@@ -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;AAEhC,OAAO,EAAE,gBAAgB,EAAE,MAAM,
|
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;AAEhC,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,MAAM,CAAC,QAAQ,CAAC,SAAS,EAAE,EAAE,UAAU,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,EAAE,CAAC,CACrE,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,CACH,CAAC"}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { PutObjectCommand } from '@aws-sdk/client-s3';
|
2
2
|
import { Effect, pipe } from 'effect';
|
3
|
-
import { FileStorageError } from '
|
4
|
-
import { cloudflareR2StorageProvider } from '
|
3
|
+
import { FileStorageError } from '@errors';
|
4
|
+
import { cloudflareR2StorageProvider } from '@provider';
|
5
5
|
export const uploadFile = ({ bucketName, documentKey, data, contentType, }) => Effect.withSpan('upload-file', {
|
6
6
|
attributes: { bucketName, documentKey, contentType },
|
7
7
|
})(pipe(cloudflareR2StorageProvider, Effect.flatMap((provider) => Effect.tryPromise({
|
@@ -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,
|
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,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE;IAC7B,UAAU,EAAE,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE;CACrD,CAAC,CACA,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,CACF,CACF,CAAC"}
|
@@ -1,8 +1,9 @@
|
|
1
1
|
import { Layer } from 'effect';
|
2
|
+
import { bucketInfos, createBucket, getFileUrl, readAsJson, readAsRawBinary, readAsText, uploadFile, } from '@implementation';
|
2
3
|
import { FileStorageLayerContext } from '../layer/file-storage.layer.js';
|
3
|
-
import { createBucket, getFileUrl, readAsJson, readAsRawBinary, readAsText, uploadFile, } from './implementations/index.js';
|
4
4
|
export const CloudflareR2StorageLayerLive = Layer.succeed(FileStorageLayerContext, FileStorageLayerContext.of({
|
5
5
|
createBucket,
|
6
|
+
bucketInfos,
|
6
7
|
getFileUrl,
|
7
8
|
uploadFile,
|
8
9
|
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,
|
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"}
|