@lafken/bucket 0.14.4 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -216,6 +216,25 @@ for (const object of result.Contents) {
|
|
|
216
216
|
}
|
|
217
217
|
```
|
|
218
218
|
|
|
219
|
+
#### Custom Client
|
|
220
|
+
|
|
221
|
+
By default every repository shares an `S3Client` built from the ambient AWS SDK configuration (the region, credentials and endpoint the SDK resolves from the environment). Pass a `client` to reach a bucket on a different region, account or endpoint, such as a local S3-compatible instance during development:
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
import { S3Client } from '@aws-sdk/client-s3';
|
|
225
|
+
import { createRepository } from '@lafken/bucket/service';
|
|
226
|
+
|
|
227
|
+
const client = new S3Client({
|
|
228
|
+
endpoint: 'http://localhost:9000',
|
|
229
|
+
region: 'us-east-1',
|
|
230
|
+
forcePathStyle: true,
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
export const docsRepository = createRepository(DocumentBucket, { client });
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Reuse the same instance across your buckets instead of creating one per repository, so they share a single connection pool.
|
|
237
|
+
|
|
219
238
|
### X-Ray Tracing
|
|
220
239
|
|
|
221
240
|
Enable `tracing` in the `@Bucket` decorator to instrument all repository operations with AWS X-Ray:
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ClassResource } from '@lafken/common';
|
|
2
|
-
import type { RepositoryReturn } from './repository.types';
|
|
3
|
-
export declare const createRepository: <E extends ClassResource>(bucket: E) => RepositoryReturn<E>;
|
|
2
|
+
import type { RepositoryOptions, RepositoryReturn } from './repository.types';
|
|
3
|
+
export declare const createRepository: <E extends ClassResource>(bucket: E, options?: RepositoryOptions) => RepositoryReturn<E>;
|
|
@@ -4,9 +4,9 @@ exports.createRepository = void 0;
|
|
|
4
4
|
const client_s3_1 = require("@aws-sdk/client-s3");
|
|
5
5
|
const client_1 = require("../client/client");
|
|
6
6
|
const repository_utils_1 = require("./repository.utils");
|
|
7
|
-
const createRepository = (bucket) => {
|
|
7
|
+
const createRepository = (bucket, options = {}) => {
|
|
8
8
|
const { name } = (0, repository_utils_1.getBucketInformation)(bucket);
|
|
9
|
-
const bucketClient = client_1.client;
|
|
9
|
+
const bucketClient = options.client ?? client_1.client;
|
|
10
10
|
return {
|
|
11
11
|
putObject(props) {
|
|
12
12
|
const command = new client_s3_1.PutObjectCommand({
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
-
import type { _Object, CopyObjectCommandInput, CopyObjectCommandOutput, DeleteObjectCommandInput, DeleteObjectCommandOutput, GetObjectCommandInput, GetObjectCommandOutput, ListObjectsV2CommandInput, PutObjectCommandInput, PutObjectCommandOutput } from '@aws-sdk/client-s3';
|
|
1
|
+
import type { _Object, CopyObjectCommandInput, CopyObjectCommandOutput, DeleteObjectCommandInput, DeleteObjectCommandOutput, GetObjectCommandInput, GetObjectCommandOutput, ListObjectsV2CommandInput, PutObjectCommandInput, PutObjectCommandOutput, S3Client } from '@aws-sdk/client-s3';
|
|
2
2
|
import type { ClassResource } from '@lafken/common';
|
|
3
3
|
export type InputWithoutBucket<T> = Omit<T, 'Bucket'>;
|
|
4
|
+
export interface RepositoryOptions {
|
|
5
|
+
/**
|
|
6
|
+
* S3 client used by every operation of the repository.
|
|
7
|
+
*
|
|
8
|
+
* Injecting a client is the way to reach a bucket on a different region, account or endpoint,
|
|
9
|
+
* for example a local S3-compatible instance during development.
|
|
10
|
+
*
|
|
11
|
+
* @default The shared client built from the ambient AWS SDK configuration.
|
|
12
|
+
*/
|
|
13
|
+
client?: S3Client;
|
|
14
|
+
}
|
|
4
15
|
export type RepositoryReturn<_E extends ClassResource> = {
|
|
5
16
|
putObject(props: InputWithoutBucket<PutObjectCommandInput>): Promise<PutObjectCommandOutput>;
|
|
6
17
|
getObject(props: InputWithoutBucket<GetObjectCommandInput>): Promise<GetObjectCommandOutput>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lafken/bucket",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Define S3 buckets using TypeScript decorators - automatic infrastructure generation with Lafken",
|
|
6
6
|
"keywords": [
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
],
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"reflect-metadata": "^0.2.2",
|
|
60
|
-
"@lafken/resolver": "0.
|
|
60
|
+
"@lafken/resolver": "0.15.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@aws-sdk/client-s3": "^3.1106.0",
|
|
@@ -71,16 +71,16 @@
|
|
|
71
71
|
"typescript": "7.0.2",
|
|
72
72
|
"unplugin-swc": "^1.5.10",
|
|
73
73
|
"vitest": "^4.1.10",
|
|
74
|
-
"@lafken/common": "0.
|
|
74
|
+
"@lafken/common": "0.15.0"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
77
|
"@cdktn/provider-aws": ">=23.0.0",
|
|
78
78
|
"cdktn": ">=0.22.0",
|
|
79
79
|
"constructs": ">=10.7.0",
|
|
80
|
-
"@lafken/common": "0.
|
|
80
|
+
"@lafken/common": "0.15.0"
|
|
81
81
|
},
|
|
82
82
|
"engines": {
|
|
83
|
-
"node": ">=
|
|
83
|
+
"node": ">=22.13"
|
|
84
84
|
},
|
|
85
85
|
"publishConfig": {
|
|
86
86
|
"access": "public"
|
/package/{LICENCE → LICENSE}
RENAMED
|
File without changes
|