@agentuity/storage 3.0.0-alpha.7
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/AGENTS.md +62 -0
- package/README.md +73 -0
- package/dist/bun.d.ts +24 -0
- package/dist/bun.d.ts.map +1 -0
- package/dist/bun.js +83 -0
- package/dist/bun.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/node.d.ts +34 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +326 -0
- package/dist/node.js.map +1 -0
- package/dist/types.d.ts +105 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/package.json +67 -0
- package/src/bun.ts +109 -0
- package/src/index.ts +15 -0
- package/src/node.ts +380 -0
- package/src/types.ts +113 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared types for `@agentuity/storage`.
|
|
3
|
+
*
|
|
4
|
+
* Both the Bun-backed and Node-backed implementations conform to the
|
|
5
|
+
* `S3ClientLike` interface. Callers should program against this surface
|
|
6
|
+
* rather than backend-specific shapes, so that swapping the backend (or
|
|
7
|
+
* letting the package conditionally pick one) is transparent.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** Bucket connection configuration. */
|
|
11
|
+
export interface BucketConfig {
|
|
12
|
+
/**
|
|
13
|
+
* Bucket-specific endpoint, e.g. `my-bucket.agentuity.run`. May be
|
|
14
|
+
* provided with or without a scheme; missing schemes default to
|
|
15
|
+
* `https://`.
|
|
16
|
+
*/
|
|
17
|
+
endpoint: string;
|
|
18
|
+
/** S3 access key ID. */
|
|
19
|
+
access_key: string;
|
|
20
|
+
/** S3 secret access key. */
|
|
21
|
+
secret_key: string;
|
|
22
|
+
/** Optional region. Defaults to `'auto'` when omitted or null. */
|
|
23
|
+
region?: string | null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Options for `list()`. */
|
|
27
|
+
export interface S3ListOptions {
|
|
28
|
+
/** Only return objects whose key starts with this prefix. */
|
|
29
|
+
prefix?: string;
|
|
30
|
+
/** Maximum number of objects to return in this response. */
|
|
31
|
+
maxKeys?: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** A single object entry in a list result. */
|
|
35
|
+
export interface S3Object {
|
|
36
|
+
key: string;
|
|
37
|
+
size: number;
|
|
38
|
+
/**
|
|
39
|
+
* ISO 8601 timestamp string. Both backends normalize to a string so
|
|
40
|
+
* downstream code does not have to branch on `Date | string`.
|
|
41
|
+
*/
|
|
42
|
+
lastModified: string;
|
|
43
|
+
etag?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Result of a `list()` call. */
|
|
47
|
+
export interface S3ListResult {
|
|
48
|
+
contents: S3Object[];
|
|
49
|
+
isTruncated: boolean;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Result of a `stat()` (HEAD) call. */
|
|
53
|
+
export interface S3StatResult {
|
|
54
|
+
size: number;
|
|
55
|
+
/** Content-Type of the object, when present. */
|
|
56
|
+
type?: string;
|
|
57
|
+
lastModified?: Date;
|
|
58
|
+
etag?: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Options for `write()`. */
|
|
62
|
+
export interface S3WriteOptions {
|
|
63
|
+
/** Content-Type to record on the object. */
|
|
64
|
+
type?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Anything we can upload as an object body.
|
|
69
|
+
*
|
|
70
|
+
* The Bun backend forwards these directly to `Bun.S3Client.write`, which
|
|
71
|
+
* accepts the same shapes. The Node backend converts them to formats
|
|
72
|
+
* accepted by `@aws-sdk/client-s3`'s `PutObjectCommand`.
|
|
73
|
+
*/
|
|
74
|
+
export type S3Body = string | Uint8Array | ArrayBuffer | Blob | ReadableStream<Uint8Array>;
|
|
75
|
+
|
|
76
|
+
/** A handle to an object on the server. Returned by `client.file(key)`. */
|
|
77
|
+
export interface S3FileLike {
|
|
78
|
+
/** Read the entire object into memory as an `ArrayBuffer`. */
|
|
79
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
80
|
+
/** Read the entire object as UTF-8 text. */
|
|
81
|
+
text(): Promise<string>;
|
|
82
|
+
/** Get a Web `ReadableStream` for the object body. */
|
|
83
|
+
stream(): ReadableStream<Uint8Array>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Unified S3 client interface.
|
|
88
|
+
*
|
|
89
|
+
* Implemented by both `@agentuity/storage/bun` and
|
|
90
|
+
* `@agentuity/storage/node`. The surface mirrors `Bun.S3Client` so the
|
|
91
|
+
* Bun backend can be a thin wrapper, and the Node backend translates
|
|
92
|
+
* to `@aws-sdk/client-s3` commands.
|
|
93
|
+
*/
|
|
94
|
+
export interface S3ClientLike {
|
|
95
|
+
/**
|
|
96
|
+
* List objects in the bucket. Pass `null` (or omit) to list from the
|
|
97
|
+
* root with no prefix; otherwise narrow with `{ prefix, maxKeys }`.
|
|
98
|
+
*/
|
|
99
|
+
list(opts?: S3ListOptions | null): Promise<S3ListResult>;
|
|
100
|
+
/** Get object metadata (HEAD). */
|
|
101
|
+
stat(key: string): Promise<S3StatResult>;
|
|
102
|
+
/** Get a handle to an object for streaming reads. */
|
|
103
|
+
file(key: string): S3FileLike;
|
|
104
|
+
/**
|
|
105
|
+
* Upload an object. Returns the number of bytes written.
|
|
106
|
+
*
|
|
107
|
+
* For streaming bodies, the byte count is measured by a counting
|
|
108
|
+
* pass-through stream so that the return value is always accurate.
|
|
109
|
+
*/
|
|
110
|
+
write(key: string, body: S3Body, opts?: S3WriteOptions): Promise<number>;
|
|
111
|
+
/** Delete an object. No-op (does not throw) if the object is absent. */
|
|
112
|
+
delete(key: string): Promise<void>;
|
|
113
|
+
}
|