@anabranch/storage-s3 0.1.6 → 0.2.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
@@ -6,24 +6,24 @@ LocalStack, and other S3-compatible APIs.
6
6
  ## Usage
7
7
 
8
8
  ```ts
9
- import { createS3 } from "@anabranch/storage-s3";
10
- import { Storage } from "@anabranch/storage";
9
+ import { createS3 } from '@anabranch/storage-s3'
10
+ import { Storage } from '@anabranch/storage'
11
11
 
12
12
  const connector = createS3({
13
- bucket: "my-bucket",
14
- region: "us-east-1",
13
+ bucket: 'my-bucket',
14
+ region: 'us-east-1',
15
15
  credentials: {
16
- accessKeyId: "...",
17
- secretAccessKey: "...",
16
+ accessKeyId: '...',
17
+ secretAccessKey: '...',
18
18
  },
19
- });
19
+ })
20
20
 
21
- const storage = new Storage(await connector.connect());
21
+ const storage = new Storage(await connector.connect())
22
22
 
23
- await storage.put("hello.txt", "world").run();
23
+ await storage.put('hello.txt', 'world').run()
24
24
 
25
- const content = await storage.get("hello.txt").run();
26
- console.log(await new Response(content.body).text());
25
+ const content = await storage.get('hello.txt').run()
26
+ console.log(await new Response(content.body).text())
27
27
  ```
28
28
 
29
29
  ## Features
@@ -1,4 +1,4 @@
1
- import type { StorageConnector, StorageOptions } from "@anabranch/storage";
1
+ import type { StorageConnector, StorageOptions } from '@anabranch/storage';
2
2
  /** Options for creating an S3 storage connector. */
3
3
  export interface S3StorageOptions extends StorageOptions {
4
4
  bucket: string;
@@ -1 +1 @@
1
- {"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../src/connector.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAG3E,oDAAoD;AACpD,MAAM,WAAW,gBAAiB,SAAQ,cAAc;IACtD,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE;QACZ,WAAW,EAAE,MAAM,CAAC;QACpB,eAAe,EAAE,MAAM,CAAC;QACxB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,CAAC;IACF,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,gBAAgB,GAAG,gBAAgB,CAwBpE"}
1
+ {"version":3,"file":"connector.d.ts","sourceRoot":"","sources":["../src/connector.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAG1E,oDAAoD;AACpD,MAAM,WAAW,gBAAiB,SAAQ,cAAc;IACtD,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE;QACZ,WAAW,EAAE,MAAM,CAAA;QACnB,eAAe,EAAE,MAAM,CAAA;QACvB,YAAY,CAAC,EAAE,MAAM,CAAA;KACtB,CAAA;IACD,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,gBAAgB,GAAG,gBAAgB,CAwBpE"}
package/esm/connector.js CHANGED
@@ -1,15 +1,15 @@
1
- import { S3Client } from "@aws-sdk/client-s3";
2
- import { NodeHttpHandler } from "@smithy/node-http-handler";
3
- import { Agent } from "node:https";
4
- import { Agent as HttpAgent } from "node:http";
5
- import { S3Adapter } from "./s3.js";
1
+ import { S3Client } from '@aws-sdk/client-s3';
2
+ import { NodeHttpHandler } from '@smithy/node-http-handler';
3
+ import { Agent } from 'node:https';
4
+ import { Agent as HttpAgent } from 'node:http';
5
+ import { S3Adapter } from './s3.js';
6
6
  /**
7
7
  * Creates a {@link StorageConnector} for AWS S3 and compatible services.
8
8
  */
9
9
  export function createS3(options) {
10
10
  const pooled = options.pooled ?? true;
11
11
  const client = new S3Client({
12
- region: options.region ?? "us-east-1",
12
+ region: options.region ?? 'us-east-1',
13
13
  endpoint: options.endpoint,
14
14
  credentials: options.credentials,
15
15
  forcePathStyle: options.forcePathStyle,
@@ -19,7 +19,7 @@ export function createS3(options) {
19
19
  }),
20
20
  });
21
21
  return {
22
- connect: () => Promise.resolve(new S3Adapter(client, options.bucket, options.prefix ?? "")),
22
+ connect: () => Promise.resolve(new S3Adapter(client, options.bucket, options.prefix ?? '')),
23
23
  end: () => {
24
24
  client.destroy();
25
25
  return Promise.resolve();
package/esm/index.d.ts CHANGED
@@ -99,7 +99,7 @@
99
99
  *
100
100
  * @module
101
101
  */
102
- export { S3Adapter } from "./s3.js";
103
- export { createS3 } from "./connector.js";
104
- export type { S3StorageOptions } from "./connector.js";
102
+ export { S3Adapter } from './s3.js';
103
+ export { createS3 } from './connector.js';
104
+ export type { S3StorageOptions } from './connector.js';
105
105
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoGG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoGG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AACzC,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA"}
package/esm/index.js CHANGED
@@ -99,5 +99,5 @@
99
99
  *
100
100
  * @module
101
101
  */
102
- export { S3Adapter } from "./s3.js";
103
- export { createS3 } from "./connector.js";
102
+ export { S3Adapter } from './s3.js';
103
+ export { createS3 } from './connector.js';
package/esm/s3.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S3Client } from "@aws-sdk/client-s3";
2
- import type { BodyInput, PresignableAdapter, PresignOptions, PutOptions, StorageEntry, StorageMetadata, StorageObject } from "@anabranch/storage";
1
+ import { S3Client } from '@aws-sdk/client-s3';
2
+ import type { BodyInput, PresignableAdapter, PresignOptions, PutOptions, StorageEntry, StorageMetadata, StorageObject } from '@anabranch/storage';
3
3
  /**
4
4
  * Adapter for AWS S3 and compatible services (Minio, LocalStack, etc.).
5
5
  */
package/esm/s3.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"s3.d.ts","sourceRoot":"","sources":["../src/s3.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,QAAQ,EACT,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EACV,SAAS,EACT,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,YAAY,EACZ,eAAe,EACf,aAAa,EACd,MAAM,oBAAoB,CAAC;AAW5B;;GAEG;AACH,qBAAa,SAAU,YAAW,kBAAkB;IAEhD,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAFN,MAAM,EAAE,QAAQ,EAChB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM;IAG3B,GAAG,CAAC,GAAG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9C;;;OAGG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkBlC,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IA8BjD,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC,YAAY,CAAC;IA0C5C,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;IAmBpE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,OAAO,CAAC,UAAU;CAWnB"}
package/esm/s3.js CHANGED
@@ -1,6 +1,6 @@
1
- import { DeleteObjectCommand, GetObjectCommand, HeadObjectCommand, ListObjectsV2Command, PutObjectCommand, } from "@aws-sdk/client-s3";
2
- import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
3
- import { StorageDeleteFailed, StorageGetFailed, StorageHeadFailed, StorageListFailed, StorageObjectNotFound, StoragePresignFailed, StoragePutFailed, } from "@anabranch/storage";
1
+ import { DeleteObjectCommand, GetObjectCommand, HeadObjectCommand, ListObjectsV2Command, PutObjectCommand, } from '@aws-sdk/client-s3';
2
+ import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
3
+ import { StorageDeleteFailed, StorageGetFailed, StorageHeadFailed, StorageListFailed, StorageObjectNotFound, StoragePresignFailed, StoragePutFailed, } from '@anabranch/storage';
4
4
  /**
5
5
  * Adapter for AWS S3 and compatible services (Minio, LocalStack, etc.).
6
6
  */
@@ -48,7 +48,7 @@ export class S3Adapter {
48
48
  Key: fullKey,
49
49
  }));
50
50
  if (!response.Body) {
51
- throw new Error("Empty body in S3 response");
51
+ throw new Error('Empty body in S3 response');
52
52
  }
53
53
  return {
54
54
  body: response.Body.transformToWebStream(),
@@ -109,7 +109,7 @@ export class S3Adapter {
109
109
  }
110
110
  }
111
111
  list(prefix) {
112
- const searchPrefix = this.prefix + (prefix ?? "");
112
+ const searchPrefix = this.prefix + (prefix ?? '');
113
113
  const client = this.client;
114
114
  const bucket = this.bucket;
115
115
  const rootPrefix = this.prefix;
@@ -144,7 +144,7 @@ export class S3Adapter {
144
144
  async presign(key, options) {
145
145
  const fullKey = this.prefix + key;
146
146
  try {
147
- const command = options.method === "PUT"
147
+ const command = options.method === 'PUT'
148
148
  ? new PutObjectCommand({ Bucket: this.bucket, Key: fullKey })
149
149
  : new GetObjectCommand({ Bucket: this.bucket, Key: fullKey });
150
150
  return await getSignedUrl(this.client, command, {
@@ -160,8 +160,8 @@ export class S3Adapter {
160
160
  }
161
161
  isNotFound(error) {
162
162
  const err = error;
163
- return (err.name === "NoSuchKey" ||
164
- err.name === "NotFound" ||
163
+ return (err.name === 'NoSuchKey' ||
164
+ err.name === 'NotFound' ||
165
165
  err.$metadata?.httpStatusCode === 404);
166
166
  }
167
167
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anabranch/storage-s3",
3
- "version": "0.1.6",
3
+ "version": "0.2.0",
4
4
  "description": "S3 adapter for @anabranch/storage using @aws-sdk/client-s3. Supports presigned URLs, multipart uploads, and all storage operations.",
5
5
  "repository": {
6
6
  "type": "git",