@parsrun/storage 0.1.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 +176 -0
- package/dist/adapters/memory.d.ts +67 -0
- package/dist/adapters/memory.js +311 -0
- package/dist/adapters/memory.js.map +1 -0
- package/dist/adapters/r2.d.ts +180 -0
- package/dist/adapters/r2.js +818 -0
- package/dist/adapters/r2.js.map +1 -0
- package/dist/adapters/s3.d.ts +76 -0
- package/dist/adapters/s3.js +473 -0
- package/dist/adapters/s3.js.map +1 -0
- package/dist/index.d.ts +111 -0
- package/dist/index.js +1316 -0
- package/dist/index.js.map +1 -0
- package/dist/types-CCTK5LsZ.d.ts +290 -0
- package/package.json +68 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { a as StorageAdapter, R as R2Config, U as UploadOptions, F as FileMetadata, D as DownloadOptions, d as DeleteResult, B as BatchDeleteResult, L as ListOptions, c as ListResult, C as CopyOptions, P as PresignedUrlOptions } from '../types-CCTK5LsZ.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @parsrun/storage - R2 Adapter
|
|
5
|
+
* Cloudflare R2 storage adapter (edge-native)
|
|
6
|
+
*
|
|
7
|
+
* This adapter works in two modes:
|
|
8
|
+
* 1. Worker binding (native R2 API) - fastest, edge-native
|
|
9
|
+
* 2. S3-compatible API - for non-Worker environments
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Cloudflare R2 Bucket binding type
|
|
14
|
+
*/
|
|
15
|
+
interface R2Bucket {
|
|
16
|
+
head(key: string): Promise<R2Object | null>;
|
|
17
|
+
get(key: string, options?: R2GetOptions): Promise<R2ObjectBody | null>;
|
|
18
|
+
put(key: string, value: ArrayBuffer | ArrayBufferView | ReadableStream | string | null | Blob, options?: R2PutOptions): Promise<R2Object>;
|
|
19
|
+
delete(keys: string | string[]): Promise<void>;
|
|
20
|
+
list(options?: R2ListOptions): Promise<R2Objects>;
|
|
21
|
+
createMultipartUpload(key: string, options?: R2MultipartOptions): Promise<R2MultipartUpload>;
|
|
22
|
+
}
|
|
23
|
+
interface R2Object {
|
|
24
|
+
key: string;
|
|
25
|
+
version: string;
|
|
26
|
+
size: number;
|
|
27
|
+
etag: string;
|
|
28
|
+
httpEtag: string;
|
|
29
|
+
checksums: R2Checksums;
|
|
30
|
+
uploaded: Date;
|
|
31
|
+
httpMetadata?: R2HTTPMetadata;
|
|
32
|
+
customMetadata?: Record<string, string>;
|
|
33
|
+
range?: R2Range;
|
|
34
|
+
}
|
|
35
|
+
interface R2ObjectBody extends R2Object {
|
|
36
|
+
body: ReadableStream;
|
|
37
|
+
bodyUsed: boolean;
|
|
38
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
39
|
+
text(): Promise<string>;
|
|
40
|
+
json<T>(): Promise<T>;
|
|
41
|
+
blob(): Promise<Blob>;
|
|
42
|
+
}
|
|
43
|
+
interface R2Checksums {
|
|
44
|
+
md5?: ArrayBuffer;
|
|
45
|
+
sha1?: ArrayBuffer;
|
|
46
|
+
sha256?: ArrayBuffer;
|
|
47
|
+
sha384?: ArrayBuffer;
|
|
48
|
+
sha512?: ArrayBuffer;
|
|
49
|
+
}
|
|
50
|
+
interface R2HTTPMetadata {
|
|
51
|
+
contentType?: string;
|
|
52
|
+
contentLanguage?: string;
|
|
53
|
+
contentDisposition?: string;
|
|
54
|
+
contentEncoding?: string;
|
|
55
|
+
cacheControl?: string;
|
|
56
|
+
cacheExpiry?: Date;
|
|
57
|
+
}
|
|
58
|
+
interface R2Range {
|
|
59
|
+
offset: number;
|
|
60
|
+
length: number;
|
|
61
|
+
}
|
|
62
|
+
interface R2GetOptions {
|
|
63
|
+
onlyIf?: R2Conditional;
|
|
64
|
+
range?: R2Range | {
|
|
65
|
+
offset?: number;
|
|
66
|
+
length?: number;
|
|
67
|
+
suffix?: number;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
interface R2PutOptions {
|
|
71
|
+
httpMetadata?: R2HTTPMetadata;
|
|
72
|
+
customMetadata?: Record<string, string>;
|
|
73
|
+
md5?: ArrayBuffer | string;
|
|
74
|
+
sha1?: ArrayBuffer | string;
|
|
75
|
+
sha256?: ArrayBuffer | string;
|
|
76
|
+
sha384?: ArrayBuffer | string;
|
|
77
|
+
sha512?: ArrayBuffer | string;
|
|
78
|
+
}
|
|
79
|
+
interface R2Conditional {
|
|
80
|
+
etagMatches?: string;
|
|
81
|
+
etagDoesNotMatch?: string;
|
|
82
|
+
uploadedBefore?: Date;
|
|
83
|
+
uploadedAfter?: Date;
|
|
84
|
+
}
|
|
85
|
+
interface R2ListOptions {
|
|
86
|
+
prefix?: string;
|
|
87
|
+
cursor?: string;
|
|
88
|
+
delimiter?: string;
|
|
89
|
+
limit?: number;
|
|
90
|
+
include?: ("httpMetadata" | "customMetadata")[];
|
|
91
|
+
}
|
|
92
|
+
interface R2Objects {
|
|
93
|
+
objects: R2Object[];
|
|
94
|
+
truncated: boolean;
|
|
95
|
+
cursor?: string;
|
|
96
|
+
delimitedPrefixes: string[];
|
|
97
|
+
}
|
|
98
|
+
interface R2MultipartOptions {
|
|
99
|
+
httpMetadata?: R2HTTPMetadata;
|
|
100
|
+
customMetadata?: Record<string, string>;
|
|
101
|
+
}
|
|
102
|
+
interface R2MultipartUpload {
|
|
103
|
+
key: string;
|
|
104
|
+
uploadId: string;
|
|
105
|
+
uploadPart(partNumber: number, value: ArrayBuffer | ArrayBufferView | ReadableStream | string | Blob): Promise<R2UploadedPart>;
|
|
106
|
+
abort(): Promise<void>;
|
|
107
|
+
complete(uploadedParts: R2UploadedPart[]): Promise<R2Object>;
|
|
108
|
+
}
|
|
109
|
+
interface R2UploadedPart {
|
|
110
|
+
partNumber: number;
|
|
111
|
+
etag: string;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* R2 Storage Adapter
|
|
115
|
+
* Native Cloudflare R2 adapter optimized for Workers/Edge
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* // In Cloudflare Worker with binding
|
|
120
|
+
* const r2 = new R2Adapter({
|
|
121
|
+
* type: 'r2',
|
|
122
|
+
* bucket: 'my-bucket',
|
|
123
|
+
* accountId: env.CF_ACCOUNT_ID,
|
|
124
|
+
* accessKeyId: env.R2_ACCESS_KEY,
|
|
125
|
+
* secretAccessKey: env.R2_SECRET_KEY,
|
|
126
|
+
* binding: env.MY_BUCKET, // R2 binding
|
|
127
|
+
* });
|
|
128
|
+
*
|
|
129
|
+
* // Using S3-compatible API (non-Worker)
|
|
130
|
+
* const r2 = new R2Adapter({
|
|
131
|
+
* type: 'r2',
|
|
132
|
+
* bucket: 'my-bucket',
|
|
133
|
+
* accountId: env.CF_ACCOUNT_ID,
|
|
134
|
+
* accessKeyId: env.R2_ACCESS_KEY,
|
|
135
|
+
* secretAccessKey: env.R2_SECRET_KEY,
|
|
136
|
+
* });
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
declare class R2Adapter implements StorageAdapter {
|
|
140
|
+
readonly type: "r2";
|
|
141
|
+
readonly bucket: string;
|
|
142
|
+
private binding;
|
|
143
|
+
private s3Adapter;
|
|
144
|
+
private config;
|
|
145
|
+
private basePath;
|
|
146
|
+
constructor(config: R2Config & {
|
|
147
|
+
binding?: R2Bucket;
|
|
148
|
+
});
|
|
149
|
+
/**
|
|
150
|
+
* Get S3 adapter for fallback
|
|
151
|
+
*/
|
|
152
|
+
private getS3Adapter;
|
|
153
|
+
private getFullKey;
|
|
154
|
+
private validateKey;
|
|
155
|
+
private dataToBody;
|
|
156
|
+
upload(key: string, data: Uint8Array | ReadableStream<Uint8Array> | Blob | string, options?: UploadOptions): Promise<FileMetadata>;
|
|
157
|
+
download(key: string, options?: DownloadOptions): Promise<Uint8Array>;
|
|
158
|
+
downloadStream(key: string, options?: DownloadOptions): Promise<ReadableStream<Uint8Array>>;
|
|
159
|
+
head(key: string): Promise<FileMetadata | null>;
|
|
160
|
+
exists(key: string): Promise<boolean>;
|
|
161
|
+
delete(key: string): Promise<DeleteResult>;
|
|
162
|
+
deleteMany(keys: string[]): Promise<BatchDeleteResult>;
|
|
163
|
+
list(options?: ListOptions): Promise<ListResult>;
|
|
164
|
+
copy(sourceKey: string, destKey: string, options?: CopyOptions): Promise<FileMetadata>;
|
|
165
|
+
move(sourceKey: string, destKey: string): Promise<FileMetadata>;
|
|
166
|
+
getPresignedUrl(key: string, options?: PresignedUrlOptions): Promise<string>;
|
|
167
|
+
getUploadUrl(key: string, options?: PresignedUrlOptions): Promise<string>;
|
|
168
|
+
/**
|
|
169
|
+
* Get public URL for a file (if custom domain is configured)
|
|
170
|
+
*/
|
|
171
|
+
getPublicUrl(key: string): string | null;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Create an R2 storage adapter
|
|
175
|
+
*/
|
|
176
|
+
declare function createR2Adapter(config: R2Config & {
|
|
177
|
+
binding?: R2Bucket;
|
|
178
|
+
}): R2Adapter;
|
|
179
|
+
|
|
180
|
+
export { R2Adapter, type R2Bucket, createR2Adapter };
|