@computesdk/s3 1.1.5 → 1.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/dist/index.d.mts +21 -42
- package/dist/index.d.ts +21 -42
- package/dist/index.js +80 -85
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +80 -85
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,68 +1,47 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { put, get, list, remove } from '@tigrisdata/storage';
|
|
2
2
|
import { StorageProvider, UploadOptions, StorageObject, DownloadResult, ListOptions, ListResult } from '@computesdk/provider';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* S3-Compatible Storage Provider
|
|
6
6
|
*
|
|
7
|
-
* Object storage using
|
|
7
|
+
* Object storage using the Tigris Storage SDK.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* S3-compatible configuration options.
|
|
12
12
|
*/
|
|
13
13
|
interface S3Config {
|
|
14
|
-
/**
|
|
14
|
+
/** Access Key ID - if not provided, uses TIGRIS_STORAGE_ACCESS_KEY_ID */
|
|
15
15
|
accessKeyId?: string;
|
|
16
|
-
/**
|
|
16
|
+
/** Secret Access Key - if not provided, uses TIGRIS_STORAGE_SECRET_ACCESS_KEY */
|
|
17
17
|
secretAccessKey?: string;
|
|
18
|
-
/**
|
|
19
|
-
region?: string;
|
|
20
|
-
/** Optional custom endpoint for S3-compatible services */
|
|
18
|
+
/** Required endpoint for the target S3-compatible service */
|
|
21
19
|
endpoint?: string;
|
|
22
|
-
/** Optional force path style (needed for some S3-compatible services) */
|
|
23
|
-
forcePathStyle?: boolean;
|
|
24
20
|
}
|
|
25
21
|
/**
|
|
26
|
-
*
|
|
22
|
+
* S3-compatible storage instance
|
|
27
23
|
*/
|
|
28
24
|
interface S3 extends StorageProvider {
|
|
29
|
-
/** Upload data
|
|
25
|
+
/** Upload data */
|
|
30
26
|
upload(bucket: string, key: string, data: Uint8Array | string, options?: UploadOptions): Promise<StorageObject>;
|
|
31
|
-
/** Download data
|
|
27
|
+
/** Download data */
|
|
32
28
|
download(bucket: string, key: string): Promise<DownloadResult>;
|
|
33
|
-
/** Delete object
|
|
29
|
+
/** Delete object */
|
|
34
30
|
delete(bucket: string, key: string): Promise<void>;
|
|
35
|
-
/** List objects in
|
|
31
|
+
/** List objects in bucket */
|
|
36
32
|
list(bucket: string, options?: ListOptions): Promise<ListResult>;
|
|
37
|
-
/**
|
|
38
|
-
getClient():
|
|
33
|
+
/** Exposes storage SDK operations for advanced use */
|
|
34
|
+
getClient(): {
|
|
35
|
+
put: (key: string, body: string | Uint8Array | Buffer, options?: Parameters<typeof put>[2]) => ReturnType<typeof put>;
|
|
36
|
+
get: (key: string, format: Parameters<typeof get>[1], options?: Parameters<typeof get>[2]) => ReturnType<typeof get>;
|
|
37
|
+
list: (options?: Parameters<typeof list>[0]) => ReturnType<typeof list>;
|
|
38
|
+
remove: (key: string, options?: Parameters<typeof remove>[1]) => ReturnType<typeof remove>;
|
|
39
|
+
};
|
|
39
40
|
}
|
|
40
41
|
/**
|
|
41
|
-
* Create an
|
|
42
|
+
* Create an S3-compatible storage provider instance backed by Tigris SDK.
|
|
42
43
|
*
|
|
43
|
-
*
|
|
44
|
-
* @returns S3 instance
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```typescript
|
|
48
|
-
* import { s3 } from '@computesdk/s3';
|
|
49
|
-
*
|
|
50
|
-
* const storage = s3({
|
|
51
|
-
* accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
52
|
-
* secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
53
|
-
* region: 'us-east-1'
|
|
54
|
-
* });
|
|
55
|
-
*
|
|
56
|
-
* // Upload a file
|
|
57
|
-
* await storage.upload('my-bucket', 'path/to/file.txt', 'Hello, World!');
|
|
58
|
-
*
|
|
59
|
-
* // Download a file
|
|
60
|
-
* const result = await storage.download('my-bucket', 'path/to/file.txt');
|
|
61
|
-
* console.log(result.data.toString());
|
|
62
|
-
*
|
|
63
|
-
* // Delete a file
|
|
64
|
-
* await storage.delete('my-bucket', 'path/to/file.txt');
|
|
65
|
-
* ```
|
|
44
|
+
* Uses explicit config values or TIGRIS_STORAGE_* env vars via per-call config.
|
|
66
45
|
*/
|
|
67
46
|
declare function s3(config: S3Config): S3;
|
|
68
47
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,68 +1,47 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { put, get, list, remove } from '@tigrisdata/storage';
|
|
2
2
|
import { StorageProvider, UploadOptions, StorageObject, DownloadResult, ListOptions, ListResult } from '@computesdk/provider';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* S3-Compatible Storage Provider
|
|
6
6
|
*
|
|
7
|
-
* Object storage using
|
|
7
|
+
* Object storage using the Tigris Storage SDK.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* S3-compatible configuration options.
|
|
12
12
|
*/
|
|
13
13
|
interface S3Config {
|
|
14
|
-
/**
|
|
14
|
+
/** Access Key ID - if not provided, uses TIGRIS_STORAGE_ACCESS_KEY_ID */
|
|
15
15
|
accessKeyId?: string;
|
|
16
|
-
/**
|
|
16
|
+
/** Secret Access Key - if not provided, uses TIGRIS_STORAGE_SECRET_ACCESS_KEY */
|
|
17
17
|
secretAccessKey?: string;
|
|
18
|
-
/**
|
|
19
|
-
region?: string;
|
|
20
|
-
/** Optional custom endpoint for S3-compatible services */
|
|
18
|
+
/** Required endpoint for the target S3-compatible service */
|
|
21
19
|
endpoint?: string;
|
|
22
|
-
/** Optional force path style (needed for some S3-compatible services) */
|
|
23
|
-
forcePathStyle?: boolean;
|
|
24
20
|
}
|
|
25
21
|
/**
|
|
26
|
-
*
|
|
22
|
+
* S3-compatible storage instance
|
|
27
23
|
*/
|
|
28
24
|
interface S3 extends StorageProvider {
|
|
29
|
-
/** Upload data
|
|
25
|
+
/** Upload data */
|
|
30
26
|
upload(bucket: string, key: string, data: Uint8Array | string, options?: UploadOptions): Promise<StorageObject>;
|
|
31
|
-
/** Download data
|
|
27
|
+
/** Download data */
|
|
32
28
|
download(bucket: string, key: string): Promise<DownloadResult>;
|
|
33
|
-
/** Delete object
|
|
29
|
+
/** Delete object */
|
|
34
30
|
delete(bucket: string, key: string): Promise<void>;
|
|
35
|
-
/** List objects in
|
|
31
|
+
/** List objects in bucket */
|
|
36
32
|
list(bucket: string, options?: ListOptions): Promise<ListResult>;
|
|
37
|
-
/**
|
|
38
|
-
getClient():
|
|
33
|
+
/** Exposes storage SDK operations for advanced use */
|
|
34
|
+
getClient(): {
|
|
35
|
+
put: (key: string, body: string | Uint8Array | Buffer, options?: Parameters<typeof put>[2]) => ReturnType<typeof put>;
|
|
36
|
+
get: (key: string, format: Parameters<typeof get>[1], options?: Parameters<typeof get>[2]) => ReturnType<typeof get>;
|
|
37
|
+
list: (options?: Parameters<typeof list>[0]) => ReturnType<typeof list>;
|
|
38
|
+
remove: (key: string, options?: Parameters<typeof remove>[1]) => ReturnType<typeof remove>;
|
|
39
|
+
};
|
|
39
40
|
}
|
|
40
41
|
/**
|
|
41
|
-
* Create an
|
|
42
|
+
* Create an S3-compatible storage provider instance backed by Tigris SDK.
|
|
42
43
|
*
|
|
43
|
-
*
|
|
44
|
-
* @returns S3 instance
|
|
45
|
-
*
|
|
46
|
-
* @example
|
|
47
|
-
* ```typescript
|
|
48
|
-
* import { s3 } from '@computesdk/s3';
|
|
49
|
-
*
|
|
50
|
-
* const storage = s3({
|
|
51
|
-
* accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
52
|
-
* secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
53
|
-
* region: 'us-east-1'
|
|
54
|
-
* });
|
|
55
|
-
*
|
|
56
|
-
* // Upload a file
|
|
57
|
-
* await storage.upload('my-bucket', 'path/to/file.txt', 'Hello, World!');
|
|
58
|
-
*
|
|
59
|
-
* // Download a file
|
|
60
|
-
* const result = await storage.download('my-bucket', 'path/to/file.txt');
|
|
61
|
-
* console.log(result.data.toString());
|
|
62
|
-
*
|
|
63
|
-
* // Delete a file
|
|
64
|
-
* await storage.delete('my-bucket', 'path/to/file.txt');
|
|
65
|
-
* ```
|
|
44
|
+
* Uses explicit config values or TIGRIS_STORAGE_* env vars via per-call config.
|
|
66
45
|
*/
|
|
67
46
|
declare function s3(config: S3Config): S3;
|
|
68
47
|
|
package/dist/index.js
CHANGED
|
@@ -23,76 +23,71 @@ __export(index_exports, {
|
|
|
23
23
|
s3: () => s3
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(index_exports);
|
|
26
|
-
var
|
|
27
|
-
var import_lib_storage = require("@aws-sdk/lib-storage");
|
|
26
|
+
var import_storage = require("@tigrisdata/storage");
|
|
28
27
|
function s3(config) {
|
|
29
|
-
const accessKeyId = config.accessKeyId || process.env.
|
|
30
|
-
const secretAccessKey = config.secretAccessKey || process.env.
|
|
31
|
-
const
|
|
28
|
+
const accessKeyId = config.accessKeyId || process.env.TIGRIS_STORAGE_ACCESS_KEY_ID;
|
|
29
|
+
const secretAccessKey = config.secretAccessKey || process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY;
|
|
30
|
+
const endpoint = config.endpoint || process.env.TIGRIS_STORAGE_ENDPOINT;
|
|
32
31
|
if (!accessKeyId) {
|
|
33
|
-
throw new Error(
|
|
34
|
-
`Missing AWS Access Key ID. Provide 'accessKeyId' in config or set AWS_ACCESS_KEY_ID environment variable.`
|
|
35
|
-
);
|
|
32
|
+
throw new Error(`Missing access key. Provide 'accessKeyId' in config or set TIGRIS_STORAGE_ACCESS_KEY_ID.`);
|
|
36
33
|
}
|
|
37
34
|
if (!secretAccessKey) {
|
|
38
|
-
throw new Error(
|
|
39
|
-
`Missing AWS Secret Access Key. Provide 'secretAccessKey' in config or set AWS_SECRET_ACCESS_KEY environment variable.`
|
|
40
|
-
);
|
|
35
|
+
throw new Error(`Missing secret key. Provide 'secretAccessKey' in config or set TIGRIS_STORAGE_SECRET_ACCESS_KEY.`);
|
|
41
36
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
37
|
+
if (!endpoint) {
|
|
38
|
+
throw new Error(`Missing endpoint. Provide 'endpoint' in config or set TIGRIS_STORAGE_ENDPOINT.`);
|
|
39
|
+
}
|
|
40
|
+
const operationConfig = { accessKeyId, secretAccessKey, endpoint };
|
|
41
|
+
const withConfig = (bucket, options) => {
|
|
42
|
+
const baseOptions = options ?? {};
|
|
43
|
+
const optionConfig = options?.config;
|
|
44
|
+
return {
|
|
45
|
+
...baseOptions,
|
|
46
|
+
config: {
|
|
47
|
+
...operationConfig,
|
|
48
|
+
...bucket ? { bucket } : {},
|
|
49
|
+
...optionConfig || {}
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
};
|
|
51
53
|
return {
|
|
52
54
|
async upload(bucket, key, data, options) {
|
|
53
55
|
try {
|
|
54
|
-
const body = typeof data === "string" ?
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
ContentType: contentType,
|
|
63
|
-
...options?.metadata && { Metadata: options.metadata }
|
|
64
|
-
},
|
|
65
|
-
queueSize: 4,
|
|
66
|
-
partSize: 5 * 1024 * 1024
|
|
67
|
-
// 5MB
|
|
68
|
-
});
|
|
69
|
-
await upload.done();
|
|
56
|
+
const body = typeof data === "string" ? data : Buffer.from(data.buffer, data.byteOffset, data.byteLength);
|
|
57
|
+
const result = await (0, import_storage.put)(key, body, withConfig(bucket, {
|
|
58
|
+
...options?.contentType ? { contentType: options.contentType } : {},
|
|
59
|
+
...options?.metadata ? { metadata: options.metadata } : {}
|
|
60
|
+
}));
|
|
61
|
+
if (result.error) {
|
|
62
|
+
throw new Error(result.error.message);
|
|
63
|
+
}
|
|
70
64
|
return {
|
|
71
65
|
bucket,
|
|
72
66
|
key,
|
|
73
|
-
size:
|
|
67
|
+
size: typeof data === "string" ? Buffer.byteLength(data, "utf8") : data.byteLength,
|
|
74
68
|
etag: void 0,
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
lastModified: /* @__PURE__ */ new Date(),
|
|
70
|
+
metadata: options?.metadata
|
|
77
71
|
};
|
|
78
72
|
} catch (error) {
|
|
79
|
-
throw new Error(
|
|
80
|
-
`Failed to upload to S3: ${error instanceof Error ? error.message : String(error)}`
|
|
81
|
-
);
|
|
73
|
+
throw new Error(`Failed to upload to storage: ${error instanceof Error ? error.message : String(error)}`);
|
|
82
74
|
}
|
|
83
75
|
},
|
|
84
76
|
async download(bucket, key) {
|
|
85
77
|
try {
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
const
|
|
78
|
+
const result = await (0, import_storage.get)(key, "stream", withConfig(bucket));
|
|
79
|
+
if (result.error) {
|
|
80
|
+
throw new Error(result.error.message);
|
|
81
|
+
}
|
|
82
|
+
const headResult = await (0, import_storage.head)(key, withConfig(bucket));
|
|
83
|
+
const headData = headResult.error ? void 0 : headResult.data;
|
|
84
|
+
const stream = result.data;
|
|
85
|
+
const reader = stream.getReader();
|
|
91
86
|
const chunks = [];
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
87
|
+
while (true) {
|
|
88
|
+
const { done, value } = await reader.read();
|
|
89
|
+
if (done) break;
|
|
90
|
+
chunks.push(value);
|
|
96
91
|
}
|
|
97
92
|
let totalLength = 0;
|
|
98
93
|
for (const chunk of chunks) {
|
|
@@ -107,61 +102,61 @@ function s3(config) {
|
|
|
107
102
|
return {
|
|
108
103
|
data,
|
|
109
104
|
size: data.length,
|
|
110
|
-
contentType:
|
|
111
|
-
etag:
|
|
112
|
-
lastModified:
|
|
113
|
-
metadata:
|
|
105
|
+
contentType: headData?.contentType,
|
|
106
|
+
etag: headData?.etag,
|
|
107
|
+
lastModified: headData?.lastModified ? new Date(headData.lastModified) : void 0,
|
|
108
|
+
metadata: headData?.metadata
|
|
114
109
|
};
|
|
115
110
|
} catch (error) {
|
|
116
|
-
if (error instanceof Error && error.
|
|
111
|
+
if (error instanceof Error && /not\s*found|no\s*such\s*key/i.test(error.message)) {
|
|
117
112
|
throw new Error(`Object not found: s3://${bucket}/${key}`);
|
|
118
113
|
}
|
|
119
|
-
throw new Error(
|
|
120
|
-
`Failed to download from S3: ${error instanceof Error ? error.message : String(error)}`
|
|
121
|
-
);
|
|
114
|
+
throw new Error(`Failed to download from storage: ${error instanceof Error ? error.message : String(error)}`);
|
|
122
115
|
}
|
|
123
116
|
},
|
|
124
117
|
async delete(bucket, key) {
|
|
125
118
|
try {
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
await client.send(command);
|
|
119
|
+
const result = await (0, import_storage.remove)(key, withConfig(bucket));
|
|
120
|
+
if (result.error) {
|
|
121
|
+
throw new Error(result.error.message);
|
|
122
|
+
}
|
|
131
123
|
} catch (error) {
|
|
132
|
-
throw new Error(
|
|
133
|
-
`Failed to delete from S3: ${error instanceof Error ? error.message : String(error)}`
|
|
134
|
-
);
|
|
124
|
+
throw new Error(`Failed to delete from storage: ${error instanceof Error ? error.message : String(error)}`);
|
|
135
125
|
}
|
|
136
126
|
},
|
|
137
127
|
async list(bucket, options) {
|
|
138
128
|
try {
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
129
|
+
const result = await (0, import_storage.list)(withConfig(bucket, {
|
|
130
|
+
prefix: options?.prefix,
|
|
131
|
+
limit: options?.maxKeys,
|
|
132
|
+
cursor: options?.continuationToken
|
|
133
|
+
}));
|
|
134
|
+
if (result.error) {
|
|
135
|
+
throw new Error(result.error.message);
|
|
136
|
+
}
|
|
137
|
+
const responseData = result.data ?? {};
|
|
146
138
|
return {
|
|
147
|
-
objects: (
|
|
139
|
+
objects: (responseData.objects || []).map((obj) => ({
|
|
148
140
|
bucket,
|
|
149
|
-
key: obj.
|
|
150
|
-
size: obj.
|
|
151
|
-
etag: obj.
|
|
152
|
-
lastModified: obj.
|
|
141
|
+
key: obj.key || "",
|
|
142
|
+
size: obj.size || 0,
|
|
143
|
+
etag: obj.etag,
|
|
144
|
+
lastModified: obj.lastModified ? new Date(obj.lastModified) : void 0
|
|
153
145
|
})),
|
|
154
|
-
truncated:
|
|
155
|
-
continuationToken:
|
|
146
|
+
truncated: responseData?.truncated || false,
|
|
147
|
+
continuationToken: responseData?.nextContinuationToken
|
|
156
148
|
};
|
|
157
149
|
} catch (error) {
|
|
158
|
-
throw new Error(
|
|
159
|
-
`Failed to list objects in S3: ${error instanceof Error ? error.message : String(error)}`
|
|
160
|
-
);
|
|
150
|
+
throw new Error(`Failed to list objects in storage: ${error instanceof Error ? error.message : String(error)}`);
|
|
161
151
|
}
|
|
162
152
|
},
|
|
163
153
|
getClient() {
|
|
164
|
-
return
|
|
154
|
+
return {
|
|
155
|
+
put: (key, body, options) => (0, import_storage.put)(key, typeof body === "string" || Buffer.isBuffer(body) ? body : Buffer.from(body), withConfig(void 0, options)),
|
|
156
|
+
get: (key, format, options) => (0, import_storage.get)(key, format, withConfig(void 0, options)),
|
|
157
|
+
list: (options) => (0, import_storage.list)(withConfig(void 0, options)),
|
|
158
|
+
remove: (key, options) => (0, import_storage.remove)(key, withConfig(void 0, options))
|
|
159
|
+
};
|
|
165
160
|
}
|
|
166
161
|
};
|
|
167
162
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * AWS S3 Storage Provider\n * \n * Object storage using AWS S3 with the ComputeSDK storage interface.\n */\n\nimport { S3Client, GetObjectCommand, DeleteObjectCommand, ListObjectsV2Command } from '@aws-sdk/client-s3';\nimport { Upload } from '@aws-sdk/lib-storage';\nimport type { StorageProvider, StorageObject, UploadOptions, DownloadResult, ListOptions, ListResult } from '@computesdk/provider';\n\n/**\n * AWS S3-specific configuration options\n */\nexport interface S3Config {\n /** AWS Access Key ID - if not provided, will use AWS_ACCESS_KEY_ID environment variable */\n accessKeyId?: string;\n /** AWS Secret Access Key - if not provided, will use AWS_SECRET_ACCESS_KEY environment variable */\n secretAccessKey?: string;\n /** AWS region - defaults to us-east-1 */\n region?: string;\n /** Optional custom endpoint for S3-compatible services */\n endpoint?: string;\n /** Optional force path style (needed for some S3-compatible services) */\n forcePathStyle?: boolean;\n}\n\n/**\n * AWS S3 Storage instance\n */\nexport interface S3 extends StorageProvider {\n /** Upload data to S3 */\n upload(bucket: string, key: string, data: Uint8Array | string, options?: UploadOptions): Promise<StorageObject>;\n /** Download data from S3 */\n download(bucket: string, key: string): Promise<DownloadResult>;\n /** Delete object from S3 */\n delete(bucket: string, key: string): Promise<void>;\n /** List objects in S3 bucket */\n list(bucket: string, options?: ListOptions): Promise<ListResult>;\n /** Get the underlying S3 client for advanced operations */\n getClient(): S3Client;\n}\n\n/**\n * Create an AWS S3 storage provider instance\n * \n * @param config - S3 configuration options\n * @returns S3 instance\n * \n * @example\n * ```typescript\n * import { s3 } from '@computesdk/s3';\n * \n * const storage = s3({\n * accessKeyId: process.env.AWS_ACCESS_KEY_ID,\n * secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,\n * region: 'us-east-1'\n * });\n * \n * // Upload a file\n * await storage.upload('my-bucket', 'path/to/file.txt', 'Hello, World!');\n * \n * // Download a file\n * const result = await storage.download('my-bucket', 'path/to/file.txt');\n * console.log(result.data.toString());\n * \n * // Delete a file\n * await storage.delete('my-bucket', 'path/to/file.txt');\n * ```\n */\nexport function s3(config: S3Config): S3 {\n // Resolve configuration from parameters or environment\n const accessKeyId = config.accessKeyId || process.env.AWS_ACCESS_KEY_ID;\n const secretAccessKey = config.secretAccessKey || process.env.AWS_SECRET_ACCESS_KEY;\n const region = config.region || process.env.AWS_REGION || 'us-east-1';\n\n if (!accessKeyId) {\n throw new Error(\n `Missing AWS Access Key ID. Provide 'accessKeyId' in config or set AWS_ACCESS_KEY_ID environment variable.`\n );\n }\n\n if (!secretAccessKey) {\n throw new Error(\n `Missing AWS Secret Access Key. Provide 'secretAccessKey' in config or set AWS_SECRET_ACCESS_KEY environment variable.`\n );\n }\n\n // Create S3 client\n const client = new S3Client({\n region,\n credentials: {\n accessKeyId,\n secretAccessKey,\n },\n ...(config.endpoint && { endpoint: config.endpoint }),\n ...(config.forcePathStyle && { forcePathStyle: config.forcePathStyle }),\n });\n\n return {\n async upload(bucket: string, key: string, data: Uint8Array | string, options?: UploadOptions): Promise<StorageObject> {\n try {\n const body = typeof data === 'string' ? Buffer.from(data) : Buffer.from(data);\n const contentType = options?.contentType || 'application/octet-stream';\n\n // Use multipart upload for files larger than 5MB\n const upload = new Upload({\n client,\n params: {\n Bucket: bucket,\n Key: key,\n Body: body,\n ContentType: contentType,\n ...(options?.metadata && { Metadata: options.metadata }),\n },\n queueSize: 4,\n partSize: 5 * 1024 * 1024, // 5MB\n });\n\n await upload.done();\n\n return {\n bucket,\n key,\n size: body.length,\n etag: undefined, // Upload doesn't return ETag directly\n lastModified: new Date(),\n };\n } catch (error) {\n throw new Error(\n `Failed to upload to S3: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n async download(bucket: string, key: string): Promise<DownloadResult> {\n try {\n const command = new GetObjectCommand({\n Bucket: bucket,\n Key: key,\n });\n\n const response = await client.send(command);\n \n // Convert stream to Uint8Array\n const chunks: Uint8Array[] = [];\n if (response.Body) {\n for await (const chunk of response.Body as any) {\n chunks.push(new Uint8Array(chunk));\n }\n }\n \n // Concatenate all chunks\n let totalLength = 0;\n for (const chunk of chunks) {\n totalLength += chunk.length;\n }\n const data = new Uint8Array(totalLength);\n let offset = 0;\n for (const chunk of chunks) {\n data.set(chunk, offset);\n offset += chunk.length;\n }\n\n return {\n data,\n size: data.length,\n contentType: response.ContentType,\n etag: response.ETag,\n lastModified: response.LastModified,\n metadata: response.Metadata,\n };\n } catch (error) {\n if (error instanceof Error && error.name === 'NoSuchKey') {\n throw new Error(`Object not found: s3://${bucket}/${key}`);\n }\n throw new Error(\n `Failed to download from S3: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n async delete(bucket: string, key: string): Promise<void> {\n try {\n const command = new DeleteObjectCommand({\n Bucket: bucket,\n Key: key,\n });\n\n await client.send(command);\n } catch (error) {\n throw new Error(\n `Failed to delete from S3: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n async list(bucket: string, options?: ListOptions): Promise<ListResult> {\n try {\n const command = new ListObjectsV2Command({\n Bucket: bucket,\n Prefix: options?.prefix,\n MaxKeys: options?.maxKeys ?? 1000,\n ContinuationToken: options?.continuationToken,\n });\n\n const response = await client.send(command);\n\n return {\n objects: (response.Contents || []).map(obj => ({\n bucket,\n key: obj.Key || '',\n size: obj.Size || 0,\n etag: obj.ETag,\n lastModified: obj.LastModified,\n })),\n truncated: response.IsTruncated || false,\n continuationToken: response.NextContinuationToken,\n };\n } catch (error) {\n throw new Error(\n `Failed to list objects in S3: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n getClient(): S3Client {\n return client;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,uBAAsF;AACtF,yBAAuB;AA8DhB,SAAS,GAAG,QAAsB;AAEvC,QAAM,cAAc,OAAO,eAAe,QAAQ,IAAI;AACtD,QAAM,kBAAkB,OAAO,mBAAmB,QAAQ,IAAI;AAC9D,QAAM,SAAS,OAAO,UAAU,QAAQ,IAAI,cAAc;AAE1D,MAAI,CAAC,aAAa;AAChB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;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AAS;AAAA,QAC9B,CAAC;AAED,cAAM,WAAW,MAAM,OAAO,KAAK,OAAO;AAE1C,eAAO;AAAA,UACL,UAAU,SAAS,YAAY,CAAC,GAAG,IAAI,UAAQ;AAAA,YAC7C;AAAA,YACA,KAAK,IAAI,OAAO;AAAA,YAChB,MAAM,IAAI,QAAQ;AAAA,YAClB,MAAM,IAAI;AAAA,YACV,cAAc,IAAI;AAAA,UACpB,EAAE;AAAA,UACF,WAAW,SAAS,eAAe;AAAA,UACnC,mBAAmB,SAAS;AAAA,QAC9B;AAAA,MACF,SAAS,OAAO;AACd,cAAM,IAAI;AAAA,UACR,iCAAiC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,QACzF;AAAA,MACF;AAAA,IACF;AAAA,IAEA,YAAsB;AACpB,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * S3-Compatible Storage Provider\n *\n * Object storage using the Tigris Storage SDK.\n */\n\nimport { get, head, list as tigrisList, put, remove } from '@tigrisdata/storage';\nimport type { StorageProvider, StorageObject, UploadOptions, DownloadResult, ListOptions, ListResult } from '@computesdk/provider';\n\n/**\n * S3-compatible configuration options.\n */\nexport interface S3Config {\n /** Access Key ID - if not provided, uses TIGRIS_STORAGE_ACCESS_KEY_ID */\n accessKeyId?: string;\n /** Secret Access Key - if not provided, uses TIGRIS_STORAGE_SECRET_ACCESS_KEY */\n secretAccessKey?: string;\n /** Required endpoint for the target S3-compatible service */\n endpoint?: string;\n}\n\n/**\n * S3-compatible storage instance\n */\nexport interface S3 extends StorageProvider {\n /** Upload data */\n upload(bucket: string, key: string, data: Uint8Array | string, options?: UploadOptions): Promise<StorageObject>;\n /** Download data */\n download(bucket: string, key: string): Promise<DownloadResult>;\n /** Delete object */\n delete(bucket: string, key: string): Promise<void>;\n /** List objects in bucket */\n list(bucket: string, options?: ListOptions): Promise<ListResult>;\n /** Exposes storage SDK operations for advanced use */\n getClient(): {\n put: (key: string, body: string | Uint8Array | Buffer, options?: Parameters<typeof put>[2]) => ReturnType<typeof put>;\n get: (key: string, format: Parameters<typeof get>[1], options?: Parameters<typeof get>[2]) => ReturnType<typeof get>;\n list: (options?: Parameters<typeof tigrisList>[0]) => ReturnType<typeof tigrisList>;\n remove: (key: string, options?: Parameters<typeof remove>[1]) => ReturnType<typeof remove>;\n };\n}\n\ninterface ListedObject {\n key?: string;\n size?: number;\n etag?: string;\n lastModified?: string | Date;\n}\n\ninterface ListData {\n objects?: ListedObject[];\n truncated?: boolean;\n nextContinuationToken?: string;\n}\n\ninterface HeadData {\n contentType?: string;\n etag?: string;\n lastModified?: string | Date;\n metadata?: Record<string, string>;\n}\n\n/**\n * Create an S3-compatible storage provider instance backed by Tigris SDK.\n *\n * Uses explicit config values or TIGRIS_STORAGE_* env vars via per-call config.\n */\nexport function s3(config: S3Config): S3 {\n const accessKeyId =\n config.accessKeyId ||\n process.env.TIGRIS_STORAGE_ACCESS_KEY_ID;\n const secretAccessKey =\n config.secretAccessKey ||\n process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY;\n const endpoint = config.endpoint || process.env.TIGRIS_STORAGE_ENDPOINT;\n\n if (!accessKeyId) {\n throw new Error(`Missing access key. Provide 'accessKeyId' in config or set TIGRIS_STORAGE_ACCESS_KEY_ID.`);\n }\n\n if (!secretAccessKey) {\n throw new Error(`Missing secret key. Provide 'secretAccessKey' in config or set TIGRIS_STORAGE_SECRET_ACCESS_KEY.`);\n }\n\n if (!endpoint) {\n throw new Error(`Missing endpoint. Provide 'endpoint' in config or set TIGRIS_STORAGE_ENDPOINT.`);\n }\n\n const operationConfig = { accessKeyId, secretAccessKey, endpoint };\n const withConfig = <T extends object | undefined>(bucket: string | undefined, options?: T): T & { config: Record<string, string> } => {\n const baseOptions = (options ?? {}) as object;\n const optionConfig = (options as { config?: Record<string, string> } | undefined)?.config;\n return {\n ...(baseOptions as object),\n config: {\n ...operationConfig,\n ...(bucket ? { bucket } : {}),\n ...(optionConfig || {}),\n },\n } as T & { config: Record<string, string> };\n };\n\n return {\n async upload(bucket: string, key: string, data: Uint8Array | string, options?: UploadOptions): Promise<StorageObject> {\n try {\n const body = typeof data === 'string' ? data : Buffer.from(data.buffer, data.byteOffset, data.byteLength);\n const result = await put(key, body, withConfig(bucket, {\n ...(options?.contentType ? { contentType: options.contentType } : {}),\n ...(options?.metadata ? { metadata: options.metadata } : {}),\n }));\n\n if (result.error) {\n throw new Error(result.error.message);\n }\n\n return {\n bucket,\n key,\n size: typeof data === 'string' ? Buffer.byteLength(data, 'utf8') : data.byteLength,\n etag: undefined,\n lastModified: new Date(),\n metadata: options?.metadata,\n };\n } catch (error) {\n throw new Error(`Failed to upload to storage: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n async download(bucket: string, key: string): Promise<DownloadResult> {\n try {\n const result = await get(key, 'stream', withConfig(bucket));\n if (result.error) {\n throw new Error(result.error.message);\n }\n\n const headResult = await head(key, withConfig(bucket));\n const headData: HeadData | undefined = headResult.error ? undefined : (headResult.data as HeadData | undefined);\n\n const stream = result.data as ReadableStream;\n const reader = stream.getReader();\n const chunks: Uint8Array[] = [];\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n chunks.push(value);\n }\n\n let totalLength = 0;\n for (const chunk of chunks) {\n totalLength += chunk.length;\n }\n const data = new Uint8Array(totalLength);\n let offset = 0;\n for (const chunk of chunks) {\n data.set(chunk, offset);\n offset += chunk.length;\n }\n\n return {\n data,\n size: data.length,\n contentType: headData?.contentType,\n etag: headData?.etag,\n lastModified: headData?.lastModified ? new Date(headData.lastModified) : undefined,\n metadata: headData?.metadata,\n };\n } catch (error) {\n if (error instanceof Error && /not\\s*found|no\\s*such\\s*key/i.test(error.message)) {\n throw new Error(`Object not found: s3://${bucket}/${key}`);\n }\n throw new Error(`Failed to download from storage: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n async delete(bucket: string, key: string): Promise<void> {\n try {\n const result = await remove(key, withConfig(bucket));\n if (result.error) {\n throw new Error(result.error.message);\n }\n } catch (error) {\n throw new Error(`Failed to delete from storage: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n async list(bucket: string, options?: ListOptions): Promise<ListResult> {\n try {\n const result = await tigrisList(withConfig(bucket, {\n prefix: options?.prefix,\n limit: options?.maxKeys,\n cursor: options?.continuationToken,\n }));\n\n if (result.error) {\n throw new Error(result.error.message);\n }\n\n const responseData = (result.data ?? {}) as ListData;\n\n return {\n objects: (responseData.objects || []).map((obj) => ({\n bucket,\n key: obj.key || '',\n size: obj.size || 0,\n etag: obj.etag,\n lastModified: obj.lastModified ? new Date(obj.lastModified) : undefined,\n })),\n truncated: responseData?.truncated || false,\n continuationToken: responseData?.nextContinuationToken,\n };\n } catch (error) {\n throw new Error(`Failed to list objects in storage: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n getClient() {\n return {\n put: (key: string, body: string | Uint8Array | Buffer, options?: Parameters<typeof put>[2]) =>\n put(key, typeof body === 'string' || Buffer.isBuffer(body) ? body : Buffer.from(body), withConfig(undefined, options)),\n get: (key: string, format: Parameters<typeof get>[1], options?: Parameters<typeof get>[2]) =>\n get(key, format, withConfig(undefined, options)),\n list: (options?: Parameters<typeof tigrisList>[0]) =>\n tigrisList(withConfig(undefined, options)),\n remove: (key: string, options?: Parameters<typeof remove>[1]) =>\n remove(key, withConfig(undefined, options)),\n };\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,qBAA2D;AA6DpD,SAAS,GAAG,QAAsB;AACvC,QAAM,cACJ,OAAO,eACP,QAAQ,IAAI;AACd,QAAM,kBACJ,OAAO,mBACP,QAAQ,IAAI;AACd,QAAM,WAAW,OAAO,YAAY,QAAQ,IAAI;AAEhD,MAAI,CAAC,aAAa;AAChB,UAAM,IAAI,MAAM,0FAA0F;AAAA,EAC5G;AAEA,MAAI,CAAC,iBAAiB;AACp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AW,QAAW,OAAO,CAAC;AAAA,QACjD,MAAM,CAAC,gBACL,eAAAA,MAAW,WAAW,QAAW,OAAO,CAAC;AAAA,QAC3C,QAAQ,CAAC,KAAa,gBACpB,uBAAO,KAAK,WAAW,QAAW,OAAO,CAAC;AAAA,MAC9C;AAAA,IACF;AAAA,EACF;AACF;","names":["tigrisList"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,74 +1,69 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import {
|
|
3
|
-
import { Upload } from "@aws-sdk/lib-storage";
|
|
2
|
+
import { get, head, list as tigrisList, put, remove } from "@tigrisdata/storage";
|
|
4
3
|
function s3(config) {
|
|
5
|
-
const accessKeyId = config.accessKeyId || process.env.
|
|
6
|
-
const secretAccessKey = config.secretAccessKey || process.env.
|
|
7
|
-
const
|
|
4
|
+
const accessKeyId = config.accessKeyId || process.env.TIGRIS_STORAGE_ACCESS_KEY_ID;
|
|
5
|
+
const secretAccessKey = config.secretAccessKey || process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY;
|
|
6
|
+
const endpoint = config.endpoint || process.env.TIGRIS_STORAGE_ENDPOINT;
|
|
8
7
|
if (!accessKeyId) {
|
|
9
|
-
throw new Error(
|
|
10
|
-
`Missing AWS Access Key ID. Provide 'accessKeyId' in config or set AWS_ACCESS_KEY_ID environment variable.`
|
|
11
|
-
);
|
|
8
|
+
throw new Error(`Missing access key. Provide 'accessKeyId' in config or set TIGRIS_STORAGE_ACCESS_KEY_ID.`);
|
|
12
9
|
}
|
|
13
10
|
if (!secretAccessKey) {
|
|
14
|
-
throw new Error(
|
|
15
|
-
`Missing AWS Secret Access Key. Provide 'secretAccessKey' in config or set AWS_SECRET_ACCESS_KEY environment variable.`
|
|
16
|
-
);
|
|
11
|
+
throw new Error(`Missing secret key. Provide 'secretAccessKey' in config or set TIGRIS_STORAGE_SECRET_ACCESS_KEY.`);
|
|
17
12
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
13
|
+
if (!endpoint) {
|
|
14
|
+
throw new Error(`Missing endpoint. Provide 'endpoint' in config or set TIGRIS_STORAGE_ENDPOINT.`);
|
|
15
|
+
}
|
|
16
|
+
const operationConfig = { accessKeyId, secretAccessKey, endpoint };
|
|
17
|
+
const withConfig = (bucket, options) => {
|
|
18
|
+
const baseOptions = options ?? {};
|
|
19
|
+
const optionConfig = options?.config;
|
|
20
|
+
return {
|
|
21
|
+
...baseOptions,
|
|
22
|
+
config: {
|
|
23
|
+
...operationConfig,
|
|
24
|
+
...bucket ? { bucket } : {},
|
|
25
|
+
...optionConfig || {}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
};
|
|
27
29
|
return {
|
|
28
30
|
async upload(bucket, key, data, options) {
|
|
29
31
|
try {
|
|
30
|
-
const body = typeof data === "string" ?
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
ContentType: contentType,
|
|
39
|
-
...options?.metadata && { Metadata: options.metadata }
|
|
40
|
-
},
|
|
41
|
-
queueSize: 4,
|
|
42
|
-
partSize: 5 * 1024 * 1024
|
|
43
|
-
// 5MB
|
|
44
|
-
});
|
|
45
|
-
await upload.done();
|
|
32
|
+
const body = typeof data === "string" ? data : Buffer.from(data.buffer, data.byteOffset, data.byteLength);
|
|
33
|
+
const result = await put(key, body, withConfig(bucket, {
|
|
34
|
+
...options?.contentType ? { contentType: options.contentType } : {},
|
|
35
|
+
...options?.metadata ? { metadata: options.metadata } : {}
|
|
36
|
+
}));
|
|
37
|
+
if (result.error) {
|
|
38
|
+
throw new Error(result.error.message);
|
|
39
|
+
}
|
|
46
40
|
return {
|
|
47
41
|
bucket,
|
|
48
42
|
key,
|
|
49
|
-
size:
|
|
43
|
+
size: typeof data === "string" ? Buffer.byteLength(data, "utf8") : data.byteLength,
|
|
50
44
|
etag: void 0,
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
lastModified: /* @__PURE__ */ new Date(),
|
|
46
|
+
metadata: options?.metadata
|
|
53
47
|
};
|
|
54
48
|
} catch (error) {
|
|
55
|
-
throw new Error(
|
|
56
|
-
`Failed to upload to S3: ${error instanceof Error ? error.message : String(error)}`
|
|
57
|
-
);
|
|
49
|
+
throw new Error(`Failed to upload to storage: ${error instanceof Error ? error.message : String(error)}`);
|
|
58
50
|
}
|
|
59
51
|
},
|
|
60
52
|
async download(bucket, key) {
|
|
61
53
|
try {
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
const
|
|
54
|
+
const result = await get(key, "stream", withConfig(bucket));
|
|
55
|
+
if (result.error) {
|
|
56
|
+
throw new Error(result.error.message);
|
|
57
|
+
}
|
|
58
|
+
const headResult = await head(key, withConfig(bucket));
|
|
59
|
+
const headData = headResult.error ? void 0 : headResult.data;
|
|
60
|
+
const stream = result.data;
|
|
61
|
+
const reader = stream.getReader();
|
|
67
62
|
const chunks = [];
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
63
|
+
while (true) {
|
|
64
|
+
const { done, value } = await reader.read();
|
|
65
|
+
if (done) break;
|
|
66
|
+
chunks.push(value);
|
|
72
67
|
}
|
|
73
68
|
let totalLength = 0;
|
|
74
69
|
for (const chunk of chunks) {
|
|
@@ -83,61 +78,61 @@ function s3(config) {
|
|
|
83
78
|
return {
|
|
84
79
|
data,
|
|
85
80
|
size: data.length,
|
|
86
|
-
contentType:
|
|
87
|
-
etag:
|
|
88
|
-
lastModified:
|
|
89
|
-
metadata:
|
|
81
|
+
contentType: headData?.contentType,
|
|
82
|
+
etag: headData?.etag,
|
|
83
|
+
lastModified: headData?.lastModified ? new Date(headData.lastModified) : void 0,
|
|
84
|
+
metadata: headData?.metadata
|
|
90
85
|
};
|
|
91
86
|
} catch (error) {
|
|
92
|
-
if (error instanceof Error && error.
|
|
87
|
+
if (error instanceof Error && /not\s*found|no\s*such\s*key/i.test(error.message)) {
|
|
93
88
|
throw new Error(`Object not found: s3://${bucket}/${key}`);
|
|
94
89
|
}
|
|
95
|
-
throw new Error(
|
|
96
|
-
`Failed to download from S3: ${error instanceof Error ? error.message : String(error)}`
|
|
97
|
-
);
|
|
90
|
+
throw new Error(`Failed to download from storage: ${error instanceof Error ? error.message : String(error)}`);
|
|
98
91
|
}
|
|
99
92
|
},
|
|
100
93
|
async delete(bucket, key) {
|
|
101
94
|
try {
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
await client.send(command);
|
|
95
|
+
const result = await remove(key, withConfig(bucket));
|
|
96
|
+
if (result.error) {
|
|
97
|
+
throw new Error(result.error.message);
|
|
98
|
+
}
|
|
107
99
|
} catch (error) {
|
|
108
|
-
throw new Error(
|
|
109
|
-
`Failed to delete from S3: ${error instanceof Error ? error.message : String(error)}`
|
|
110
|
-
);
|
|
100
|
+
throw new Error(`Failed to delete from storage: ${error instanceof Error ? error.message : String(error)}`);
|
|
111
101
|
}
|
|
112
102
|
},
|
|
113
103
|
async list(bucket, options) {
|
|
114
104
|
try {
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
105
|
+
const result = await tigrisList(withConfig(bucket, {
|
|
106
|
+
prefix: options?.prefix,
|
|
107
|
+
limit: options?.maxKeys,
|
|
108
|
+
cursor: options?.continuationToken
|
|
109
|
+
}));
|
|
110
|
+
if (result.error) {
|
|
111
|
+
throw new Error(result.error.message);
|
|
112
|
+
}
|
|
113
|
+
const responseData = result.data ?? {};
|
|
122
114
|
return {
|
|
123
|
-
objects: (
|
|
115
|
+
objects: (responseData.objects || []).map((obj) => ({
|
|
124
116
|
bucket,
|
|
125
|
-
key: obj.
|
|
126
|
-
size: obj.
|
|
127
|
-
etag: obj.
|
|
128
|
-
lastModified: obj.
|
|
117
|
+
key: obj.key || "",
|
|
118
|
+
size: obj.size || 0,
|
|
119
|
+
etag: obj.etag,
|
|
120
|
+
lastModified: obj.lastModified ? new Date(obj.lastModified) : void 0
|
|
129
121
|
})),
|
|
130
|
-
truncated:
|
|
131
|
-
continuationToken:
|
|
122
|
+
truncated: responseData?.truncated || false,
|
|
123
|
+
continuationToken: responseData?.nextContinuationToken
|
|
132
124
|
};
|
|
133
125
|
} catch (error) {
|
|
134
|
-
throw new Error(
|
|
135
|
-
`Failed to list objects in S3: ${error instanceof Error ? error.message : String(error)}`
|
|
136
|
-
);
|
|
126
|
+
throw new Error(`Failed to list objects in storage: ${error instanceof Error ? error.message : String(error)}`);
|
|
137
127
|
}
|
|
138
128
|
},
|
|
139
129
|
getClient() {
|
|
140
|
-
return
|
|
130
|
+
return {
|
|
131
|
+
put: (key, body, options) => put(key, typeof body === "string" || Buffer.isBuffer(body) ? body : Buffer.from(body), withConfig(void 0, options)),
|
|
132
|
+
get: (key, format, options) => get(key, format, withConfig(void 0, options)),
|
|
133
|
+
list: (options) => tigrisList(withConfig(void 0, options)),
|
|
134
|
+
remove: (key, options) => remove(key, withConfig(void 0, options))
|
|
135
|
+
};
|
|
141
136
|
}
|
|
142
137
|
};
|
|
143
138
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * AWS S3 Storage Provider\n * \n * Object storage using AWS S3 with the ComputeSDK storage interface.\n */\n\nimport { S3Client, GetObjectCommand, DeleteObjectCommand, ListObjectsV2Command } from '@aws-sdk/client-s3';\nimport { Upload } from '@aws-sdk/lib-storage';\nimport type { StorageProvider, StorageObject, UploadOptions, DownloadResult, ListOptions, ListResult } from '@computesdk/provider';\n\n/**\n * AWS S3-specific configuration options\n */\nexport interface S3Config {\n /** AWS Access Key ID - if not provided, will use AWS_ACCESS_KEY_ID environment variable */\n accessKeyId?: string;\n /** AWS Secret Access Key - if not provided, will use AWS_SECRET_ACCESS_KEY environment variable */\n secretAccessKey?: string;\n /** AWS region - defaults to us-east-1 */\n region?: string;\n /** Optional custom endpoint for S3-compatible services */\n endpoint?: string;\n /** Optional force path style (needed for some S3-compatible services) */\n forcePathStyle?: boolean;\n}\n\n/**\n * AWS S3 Storage instance\n */\nexport interface S3 extends StorageProvider {\n /** Upload data to S3 */\n upload(bucket: string, key: string, data: Uint8Array | string, options?: UploadOptions): Promise<StorageObject>;\n /** Download data from S3 */\n download(bucket: string, key: string): Promise<DownloadResult>;\n /** Delete object from S3 */\n delete(bucket: string, key: string): Promise<void>;\n /** List objects in S3 bucket */\n list(bucket: string, options?: ListOptions): Promise<ListResult>;\n /** Get the underlying S3 client for advanced operations */\n getClient(): S3Client;\n}\n\n/**\n * Create an AWS S3 storage provider instance\n * \n * @param config - S3 configuration options\n * @returns S3 instance\n * \n * @example\n * ```typescript\n * import { s3 } from '@computesdk/s3';\n * \n * const storage = s3({\n * accessKeyId: process.env.AWS_ACCESS_KEY_ID,\n * secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,\n * region: 'us-east-1'\n * });\n * \n * // Upload a file\n * await storage.upload('my-bucket', 'path/to/file.txt', 'Hello, World!');\n * \n * // Download a file\n * const result = await storage.download('my-bucket', 'path/to/file.txt');\n * console.log(result.data.toString());\n * \n * // Delete a file\n * await storage.delete('my-bucket', 'path/to/file.txt');\n * ```\n */\nexport function s3(config: S3Config): S3 {\n // Resolve configuration from parameters or environment\n const accessKeyId = config.accessKeyId || process.env.AWS_ACCESS_KEY_ID;\n const secretAccessKey = config.secretAccessKey || process.env.AWS_SECRET_ACCESS_KEY;\n const region = config.region || process.env.AWS_REGION || 'us-east-1';\n\n if (!accessKeyId) {\n throw new Error(\n `Missing AWS Access Key ID. Provide 'accessKeyId' in config or set AWS_ACCESS_KEY_ID environment variable.`\n );\n }\n\n if (!secretAccessKey) {\n throw new Error(\n `Missing AWS Secret Access Key. Provide 'secretAccessKey' in config or set AWS_SECRET_ACCESS_KEY environment variable.`\n );\n }\n\n // Create S3 client\n const client = new S3Client({\n region,\n credentials: {\n accessKeyId,\n secretAccessKey,\n },\n ...(config.endpoint && { endpoint: config.endpoint }),\n ...(config.forcePathStyle && { forcePathStyle: config.forcePathStyle }),\n });\n\n return {\n async upload(bucket: string, key: string, data: Uint8Array | string, options?: UploadOptions): Promise<StorageObject> {\n try {\n const body = typeof data === 'string' ? Buffer.from(data) : Buffer.from(data);\n const contentType = options?.contentType || 'application/octet-stream';\n\n // Use multipart upload for files larger than 5MB\n const upload = new Upload({\n client,\n params: {\n Bucket: bucket,\n Key: key,\n Body: body,\n ContentType: contentType,\n ...(options?.metadata && { Metadata: options.metadata }),\n },\n queueSize: 4,\n partSize: 5 * 1024 * 1024, // 5MB\n });\n\n await upload.done();\n\n return {\n bucket,\n key,\n size: body.length,\n etag: undefined, // Upload doesn't return ETag directly\n lastModified: new Date(),\n };\n } catch (error) {\n throw new Error(\n `Failed to upload to S3: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n async download(bucket: string, key: string): Promise<DownloadResult> {\n try {\n const command = new GetObjectCommand({\n Bucket: bucket,\n Key: key,\n });\n\n const response = await client.send(command);\n \n // Convert stream to Uint8Array\n const chunks: Uint8Array[] = [];\n if (response.Body) {\n for await (const chunk of response.Body as any) {\n chunks.push(new Uint8Array(chunk));\n }\n }\n \n // Concatenate all chunks\n let totalLength = 0;\n for (const chunk of chunks) {\n totalLength += chunk.length;\n }\n const data = new Uint8Array(totalLength);\n let offset = 0;\n for (const chunk of chunks) {\n data.set(chunk, offset);\n offset += chunk.length;\n }\n\n return {\n data,\n size: data.length,\n contentType: response.ContentType,\n etag: response.ETag,\n lastModified: response.LastModified,\n metadata: response.Metadata,\n };\n } catch (error) {\n if (error instanceof Error && error.name === 'NoSuchKey') {\n throw new Error(`Object not found: s3://${bucket}/${key}`);\n }\n throw new Error(\n `Failed to download from S3: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n async delete(bucket: string, key: string): Promise<void> {\n try {\n const command = new DeleteObjectCommand({\n Bucket: bucket,\n Key: key,\n });\n\n await client.send(command);\n } catch (error) {\n throw new Error(\n `Failed to delete from S3: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n async list(bucket: string, options?: ListOptions): Promise<ListResult> {\n try {\n const command = new ListObjectsV2Command({\n Bucket: bucket,\n Prefix: options?.prefix,\n MaxKeys: options?.maxKeys ?? 1000,\n ContinuationToken: options?.continuationToken,\n });\n\n const response = await client.send(command);\n\n return {\n objects: (response.Contents || []).map(obj => ({\n bucket,\n key: obj.Key || '',\n size: obj.Size || 0,\n etag: obj.ETag,\n lastModified: obj.LastModified,\n })),\n truncated: response.IsTruncated || false,\n continuationToken: response.NextContinuationToken,\n };\n } catch (error) {\n throw new Error(\n `Failed to list objects in S3: ${error instanceof Error ? error.message : String(error)}`\n );\n }\n },\n\n getClient(): S3Client {\n return client;\n },\n };\n}\n"],"mappings":";AAMA,SAAS,UAAU,kBAAkB,qBAAqB,4BAA4B;AACtF,SAAS,cAAc;AA8DhB,SAAS,GAAG,QAAsB;AAEvC,QAAM,cAAc,OAAO,eAAe,QAAQ,IAAI;AACtD,QAAM,kBAAkB,OAAO,mBAAmB,QAAQ,IAAI;AAC9D,QAAM,SAAS,OAAO,UAAU,QAAQ,IAAI,cAAc;AAE1D,MAAI,CAAC,aAAa;AAChB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,MAAI,CAAC,iBAAiB;AACpB,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAGA,QAAM,SAAS,IAAI,SAAS;AAAA,IAC1B;AAAA,IACA,aAAa;AAAA,MACX;AAAA,MACA;AAAA,IACF;AAAA,IACA,GAAI,OAAO,YAAY,EAAE,UAAU,OAAO,SAAS;AAAA,IACnD,GAAI,OAAO,kBAAkB,EAAE,gBAAgB,OAAO,eAAe;AAAA,EACvE,CAAC;AAED,SAAO;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BAAmB,SAAS;AAAA,QAC9B;AAAA,MACF,SAAS,OAAO;AACd,cAAM,IAAI;AAAA,UACR,iCAAiC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;AAAA,QACzF;AAAA,MACF;AAAA,IACF;AAAA,IAEA,YAAsB;AACpB,aAAO;AAAA,IACT;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * S3-Compatible Storage Provider\n *\n * Object storage using the Tigris Storage SDK.\n */\n\nimport { get, head, list as tigrisList, put, remove } from '@tigrisdata/storage';\nimport type { StorageProvider, StorageObject, UploadOptions, DownloadResult, ListOptions, ListResult } from '@computesdk/provider';\n\n/**\n * S3-compatible configuration options.\n */\nexport interface S3Config {\n /** Access Key ID - if not provided, uses TIGRIS_STORAGE_ACCESS_KEY_ID */\n accessKeyId?: string;\n /** Secret Access Key - if not provided, uses TIGRIS_STORAGE_SECRET_ACCESS_KEY */\n secretAccessKey?: string;\n /** Required endpoint for the target S3-compatible service */\n endpoint?: string;\n}\n\n/**\n * S3-compatible storage instance\n */\nexport interface S3 extends StorageProvider {\n /** Upload data */\n upload(bucket: string, key: string, data: Uint8Array | string, options?: UploadOptions): Promise<StorageObject>;\n /** Download data */\n download(bucket: string, key: string): Promise<DownloadResult>;\n /** Delete object */\n delete(bucket: string, key: string): Promise<void>;\n /** List objects in bucket */\n list(bucket: string, options?: ListOptions): Promise<ListResult>;\n /** Exposes storage SDK operations for advanced use */\n getClient(): {\n put: (key: string, body: string | Uint8Array | Buffer, options?: Parameters<typeof put>[2]) => ReturnType<typeof put>;\n get: (key: string, format: Parameters<typeof get>[1], options?: Parameters<typeof get>[2]) => ReturnType<typeof get>;\n list: (options?: Parameters<typeof tigrisList>[0]) => ReturnType<typeof tigrisList>;\n remove: (key: string, options?: Parameters<typeof remove>[1]) => ReturnType<typeof remove>;\n };\n}\n\ninterface ListedObject {\n key?: string;\n size?: number;\n etag?: string;\n lastModified?: string | Date;\n}\n\ninterface ListData {\n objects?: ListedObject[];\n truncated?: boolean;\n nextContinuationToken?: string;\n}\n\ninterface HeadData {\n contentType?: string;\n etag?: string;\n lastModified?: string | Date;\n metadata?: Record<string, string>;\n}\n\n/**\n * Create an S3-compatible storage provider instance backed by Tigris SDK.\n *\n * Uses explicit config values or TIGRIS_STORAGE_* env vars via per-call config.\n */\nexport function s3(config: S3Config): S3 {\n const accessKeyId =\n config.accessKeyId ||\n process.env.TIGRIS_STORAGE_ACCESS_KEY_ID;\n const secretAccessKey =\n config.secretAccessKey ||\n process.env.TIGRIS_STORAGE_SECRET_ACCESS_KEY;\n const endpoint = config.endpoint || process.env.TIGRIS_STORAGE_ENDPOINT;\n\n if (!accessKeyId) {\n throw new Error(`Missing access key. Provide 'accessKeyId' in config or set TIGRIS_STORAGE_ACCESS_KEY_ID.`);\n }\n\n if (!secretAccessKey) {\n throw new Error(`Missing secret key. Provide 'secretAccessKey' in config or set TIGRIS_STORAGE_SECRET_ACCESS_KEY.`);\n }\n\n if (!endpoint) {\n throw new Error(`Missing endpoint. Provide 'endpoint' in config or set TIGRIS_STORAGE_ENDPOINT.`);\n }\n\n const operationConfig = { accessKeyId, secretAccessKey, endpoint };\n const withConfig = <T extends object | undefined>(bucket: string | undefined, options?: T): T & { config: Record<string, string> } => {\n const baseOptions = (options ?? {}) as object;\n const optionConfig = (options as { config?: Record<string, string> } | undefined)?.config;\n return {\n ...(baseOptions as object),\n config: {\n ...operationConfig,\n ...(bucket ? { bucket } : {}),\n ...(optionConfig || {}),\n },\n } as T & { config: Record<string, string> };\n };\n\n return {\n async upload(bucket: string, key: string, data: Uint8Array | string, options?: UploadOptions): Promise<StorageObject> {\n try {\n const body = typeof data === 'string' ? data : Buffer.from(data.buffer, data.byteOffset, data.byteLength);\n const result = await put(key, body, withConfig(bucket, {\n ...(options?.contentType ? { contentType: options.contentType } : {}),\n ...(options?.metadata ? { metadata: options.metadata } : {}),\n }));\n\n if (result.error) {\n throw new Error(result.error.message);\n }\n\n return {\n bucket,\n key,\n size: typeof data === 'string' ? Buffer.byteLength(data, 'utf8') : data.byteLength,\n etag: undefined,\n lastModified: new Date(),\n metadata: options?.metadata,\n };\n } catch (error) {\n throw new Error(`Failed to upload to storage: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n async download(bucket: string, key: string): Promise<DownloadResult> {\n try {\n const result = await get(key, 'stream', withConfig(bucket));\n if (result.error) {\n throw new Error(result.error.message);\n }\n\n const headResult = await head(key, withConfig(bucket));\n const headData: HeadData | undefined = headResult.error ? undefined : (headResult.data as HeadData | undefined);\n\n const stream = result.data as ReadableStream;\n const reader = stream.getReader();\n const chunks: Uint8Array[] = [];\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n chunks.push(value);\n }\n\n let totalLength = 0;\n for (const chunk of chunks) {\n totalLength += chunk.length;\n }\n const data = new Uint8Array(totalLength);\n let offset = 0;\n for (const chunk of chunks) {\n data.set(chunk, offset);\n offset += chunk.length;\n }\n\n return {\n data,\n size: data.length,\n contentType: headData?.contentType,\n etag: headData?.etag,\n lastModified: headData?.lastModified ? new Date(headData.lastModified) : undefined,\n metadata: headData?.metadata,\n };\n } catch (error) {\n if (error instanceof Error && /not\\s*found|no\\s*such\\s*key/i.test(error.message)) {\n throw new Error(`Object not found: s3://${bucket}/${key}`);\n }\n throw new Error(`Failed to download from storage: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n async delete(bucket: string, key: string): Promise<void> {\n try {\n const result = await remove(key, withConfig(bucket));\n if (result.error) {\n throw new Error(result.error.message);\n }\n } catch (error) {\n throw new Error(`Failed to delete from storage: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n async list(bucket: string, options?: ListOptions): Promise<ListResult> {\n try {\n const result = await tigrisList(withConfig(bucket, {\n prefix: options?.prefix,\n limit: options?.maxKeys,\n cursor: options?.continuationToken,\n }));\n\n if (result.error) {\n throw new Error(result.error.message);\n }\n\n const responseData = (result.data ?? {}) as ListData;\n\n return {\n objects: (responseData.objects || []).map((obj) => ({\n bucket,\n key: obj.key || '',\n size: obj.size || 0,\n etag: obj.etag,\n lastModified: obj.lastModified ? new Date(obj.lastModified) : undefined,\n })),\n truncated: responseData?.truncated || false,\n continuationToken: responseData?.nextContinuationToken,\n };\n } catch (error) {\n throw new Error(`Failed to list objects in storage: ${error instanceof Error ? error.message : String(error)}`);\n }\n },\n\n getClient() {\n return {\n put: (key: string, body: string | Uint8Array | Buffer, options?: Parameters<typeof put>[2]) =>\n put(key, typeof body === 'string' || Buffer.isBuffer(body) ? body : Buffer.from(body), withConfig(undefined, options)),\n get: (key: string, format: Parameters<typeof get>[1], options?: Parameters<typeof get>[2]) =>\n get(key, format, withConfig(undefined, options)),\n list: (options?: Parameters<typeof tigrisList>[0]) =>\n tigrisList(withConfig(undefined, options)),\n remove: (key: string, options?: Parameters<typeof remove>[1]) =>\n remove(key, withConfig(undefined, options)),\n };\n },\n };\n}\n"],"mappings":";AAMA,SAAS,KAAK,MAAM,QAAQ,YAAY,KAAK,cAAc;AA6DpD,SAAS,GAAG,QAAsB;AACvC,QAAM,cACJ,OAAO,eACP,QAAQ,IAAI;AACd,QAAM,kBACJ,OAAO,mBACP,QAAQ,IAAI;AACd,QAAM,WAAW,OAAO,YAAY,QAAQ,IAAI;AAEhD,MAAI,CAAC,aAAa;AAChB,UAAM,IAAI,MAAM,0FAA0F;AAAA,EAC5G;AAEA,MAAI,CAAC,iBAAiB;AACpB,UAAM,IAAI,MAAM,kGAAkG;AAAA,EACpH;AAEA,MAAI,CAAC,UAAU;AACb,UAAM,IAAI,MAAM,gFAAgF;AAAA,EAClG;AAEA,QAAM,kBAAkB,EAAE,aAAa,iBAAiB,SAAS;AACjE,QAAM,aAAa,CAA+B,QAA4B,YAAwD;AACpI,UAAM,cAAe,WAAW,CAAC;AACjC,UAAM,eAAgB,SAA6D;AACnF,WAAO;AAAA,MACL,GAAI;AAAA,MACJ,QAAQ;AAAA,QACN,GAAG;AAAA,QACH,GAA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": "AWS S3 storage provider for ComputeSDK - object storage with S3-compatible API",
|
|
5
5
|
"author": "Garrison",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,8 +18,7 @@
|
|
|
18
18
|
"dist"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@
|
|
22
|
-
"@aws-sdk/lib-storage": "^3.450.0",
|
|
21
|
+
"@tigrisdata/storage": "^3.6.0",
|
|
23
22
|
"@computesdk/provider": "2.0.0"
|
|
24
23
|
},
|
|
25
24
|
"keywords": [
|