cloudrop 0.0.0-stage → 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/CHANGELOG.md +56 -0
- package/LICENSE +21 -0
- package/README.md +101 -2
- package/dist/adapters/drizzle.d.ts +204 -0
- package/dist/adapters/drizzle.js +216 -0
- package/dist/adapters/drizzle.js.map +1 -0
- package/dist/adapters/prisma.d.ts +81 -0
- package/dist/adapters/prisma.js +32 -0
- package/dist/adapters/prisma.js.map +1 -0
- package/dist/adapters/sql.d.ts +98 -0
- package/dist/adapters/sql.js +70 -0
- package/dist/adapters/sql.js.map +1 -0
- package/dist/client-Dj6ON4MN.d.ts +214 -0
- package/dist/client-Y1zUEbCj.js +1561 -0
- package/dist/client-Y1zUEbCj.js.map +1 -0
- package/dist/client.d.ts +3 -0
- package/dist/client.js +3 -0
- package/dist/d1-BY2c5bcL.js +16 -0
- package/dist/d1-BY2c5bcL.js.map +1 -0
- package/dist/errors-CUxMmFAe.js +40 -0
- package/dist/errors-CUxMmFAe.js.map +1 -0
- package/dist/executor-CEA7WV2W.d.ts +27 -0
- package/dist/index.d.ts +421 -0
- package/dist/index.js +3007 -0
- package/dist/index.js.map +1 -0
- package/dist/input-DTC476_I.js +13 -0
- package/dist/input-DTC476_I.js.map +1 -0
- package/dist/next.d.ts +9 -0
- package/dist/next.js +14 -0
- package/dist/next.js.map +1 -0
- package/dist/node.d.ts +32 -0
- package/dist/node.js +100 -0
- package/dist/node.js.map +1 -0
- package/dist/part-size-CvMoobfC.js +9 -0
- package/dist/part-size-CvMoobfC.js.map +1 -0
- package/dist/react.d.ts +123 -0
- package/dist/react.js +355 -0
- package/dist/react.js.map +1 -0
- package/dist/route-CspI1Ypt.js +72 -0
- package/dist/route-CspI1Ypt.js.map +1 -0
- package/dist/store-BfCJejGh.d.ts +382 -0
- package/dist/tables-DZnw2sPK.d.ts +11 -0
- package/dist/transactional-DnvnGsVH.js +672 -0
- package/dist/transactional-DnvnGsVH.js.map +1 -0
- package/dist/types-BZUOaz_B.js +5 -0
- package/dist/types-BZUOaz_B.js.map +1 -0
- package/dist/types-BrAx3dA4.d.ts +185 -0
- package/package.json +110 -4
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
import { D as CloudropErrorCode, E as CloudropError, O as CloudropErrorOptions, T as UploadedFile, _ as RouteResult, g as RouteName, h as RouteMetadata, k as Result, u as InferableCloudrop } from "./types-BrAx3dA4.js";
|
|
2
|
+
import { C as forbidden, D as StandardSchema, E as Size, S as allowAnyone, T as unauthorized, _ as Route, a as FileStatus, b as RouteFunction, c as TransactionalStore, d as AuthorizeContext, f as Awaitable, g as Refusal, h as OwnerContext, i as FileRecord, l as Transition, m as KeyContext, n as CloudropStore, o as NewFile, p as CompleteContext, r as EndedStatus, s as OwnerUsage, t as ClaimOutcome, u as AfterCompleteContext, v as RouteCallbacks, w as route, x as RoutePolicy, y as RouteDefinition } from "./store-BfCJejGh.js";
|
|
3
|
+
/** Limits of a storage backend, in bytes and seconds. */
|
|
4
|
+
interface StorageRules {
|
|
5
|
+
minPartSize: number;
|
|
6
|
+
maxPartSize: number;
|
|
7
|
+
maxParts: number;
|
|
8
|
+
maxSinglePutSize: number;
|
|
9
|
+
maxObjectSize: number;
|
|
10
|
+
maxPresignSeconds: number;
|
|
11
|
+
}
|
|
12
|
+
type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
13
|
+
/** Stored with the object. Metadata names use lowercase letters, digits and hyphens. */
|
|
14
|
+
interface ObjectOptions {
|
|
15
|
+
type?: string;
|
|
16
|
+
disposition?: string;
|
|
17
|
+
metadata?: Record<string, string>;
|
|
18
|
+
}
|
|
19
|
+
interface WriteOptions extends ObjectOptions {
|
|
20
|
+
/** Create-only: the write fails with ALREADY_EXISTS when the key exists. */
|
|
21
|
+
ifNoneMatch?: boolean;
|
|
22
|
+
/** Base64 CRC32C of the body; the storage rejects mismatching bytes. */
|
|
23
|
+
checksumCrc32c?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A presigned request. Send `headers` exactly as given. The body length must equal the signed size; clients do not
|
|
27
|
+
* set Content-Length themselves (browsers forbid it), the HTTP stack derives it from the body.
|
|
28
|
+
*/
|
|
29
|
+
interface PresignedRequest {
|
|
30
|
+
method: "PUT";
|
|
31
|
+
url: string;
|
|
32
|
+
headers: Record<string, string>;
|
|
33
|
+
expiresAt: Date;
|
|
34
|
+
}
|
|
35
|
+
interface ObjectInfo {
|
|
36
|
+
key: string;
|
|
37
|
+
size: number;
|
|
38
|
+
type?: string;
|
|
39
|
+
disposition?: string;
|
|
40
|
+
etag: string;
|
|
41
|
+
uploadedAt: Date;
|
|
42
|
+
metadata: Record<string, string>;
|
|
43
|
+
checksumCrc64nvme?: string;
|
|
44
|
+
}
|
|
45
|
+
interface PartInfo {
|
|
46
|
+
partNumber: number;
|
|
47
|
+
size: number;
|
|
48
|
+
etag: string;
|
|
49
|
+
checksumCrc32c?: string;
|
|
50
|
+
}
|
|
51
|
+
interface CompletedPart {
|
|
52
|
+
partNumber: number;
|
|
53
|
+
etag: string;
|
|
54
|
+
}
|
|
55
|
+
interface ListedObject {
|
|
56
|
+
key: string;
|
|
57
|
+
size: number;
|
|
58
|
+
etag: string;
|
|
59
|
+
uploadedAt: Date;
|
|
60
|
+
}
|
|
61
|
+
/** One rule of the bucket's CORS configuration, as S3's GetBucketCors returns it. */
|
|
62
|
+
interface BucketCorsRule {
|
|
63
|
+
allowedOrigins: string[];
|
|
64
|
+
allowedMethods: string[];
|
|
65
|
+
allowedHeaders: string[];
|
|
66
|
+
exposeHeaders: string[];
|
|
67
|
+
}
|
|
68
|
+
/** One rule of the bucket's lifecycle configuration; only what cloudrop checks. */
|
|
69
|
+
interface BucketLifecycleRule {
|
|
70
|
+
id: string;
|
|
71
|
+
enabled: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* The rule's first `<Prefix>`, from its filter or the legacy field; "" covers the whole bucket. Tag and size filters
|
|
74
|
+
* are not read, so a rule scoped only by them also reads as "". S3 allows no tag filter on a rule that aborts
|
|
75
|
+
* incomplete multipart uploads.
|
|
76
|
+
*/
|
|
77
|
+
prefix: string;
|
|
78
|
+
/** Days after which an incomplete multipart upload is aborted, when the rule does that. */
|
|
79
|
+
abortIncompleteMultipartUploadDays?: number;
|
|
80
|
+
}
|
|
81
|
+
/** Implemented by cloudrop's presets, r2() and s3(); its methods may change before 1.0. */
|
|
82
|
+
interface StorageDriver {
|
|
83
|
+
readonly rules: StorageRules;
|
|
84
|
+
readonly publicUrl?: string;
|
|
85
|
+
presignPut(key: string, options: WriteOptions & {
|
|
86
|
+
size: number;
|
|
87
|
+
expiresIn: number;
|
|
88
|
+
}): Promise<Result<PresignedRequest>>;
|
|
89
|
+
createMultipart(key: string, options: ObjectOptions): Promise<Result<{
|
|
90
|
+
uploadId: string;
|
|
91
|
+
}>>;
|
|
92
|
+
presignPart(key: string, uploadId: string, partNumber: number, options: {
|
|
93
|
+
size: number;
|
|
94
|
+
expiresIn: number;
|
|
95
|
+
checksumCrc32c?: string;
|
|
96
|
+
}): Promise<Result<PresignedRequest>>;
|
|
97
|
+
listParts(key: string, uploadId: string): Promise<Result<PartInfo[]>>;
|
|
98
|
+
completeMultipart(key: string, uploadId: string, parts: readonly CompletedPart[], options?: {
|
|
99
|
+
ifNoneMatch?: boolean;
|
|
100
|
+
}): Promise<Result<{
|
|
101
|
+
etag: string;
|
|
102
|
+
}>>;
|
|
103
|
+
/** Idempotent: aborting an unknown or finished upload succeeds. */
|
|
104
|
+
abortMultipart(key: string, uploadId: string): Promise<Result<void>>;
|
|
105
|
+
/**
|
|
106
|
+
* A presigned GET. `signedAt` (default now) lets callers round the signing time so that one URL is shared by everyone
|
|
107
|
+
* in a time window. `disposition` is signed into the URL as `response-content-disposition`.
|
|
108
|
+
*/
|
|
109
|
+
presignGet(key: string, options: {
|
|
110
|
+
expiresIn: number;
|
|
111
|
+
signedAt?: Date;
|
|
112
|
+
disposition?: string;
|
|
113
|
+
}): Promise<Result<{
|
|
114
|
+
url: string;
|
|
115
|
+
expiresAt: Date;
|
|
116
|
+
}>>;
|
|
117
|
+
/** The bucket's CORS rules; [] when it has none. Credentials that may not read them get STORAGE_DENIED. */
|
|
118
|
+
getBucketCors(): Promise<Result<BucketCorsRule[]>>;
|
|
119
|
+
/** The bucket's lifecycle rules; [] when it has none. Credentials that may not read them get STORAGE_DENIED. */
|
|
120
|
+
getBucketLifecycle(): Promise<Result<BucketLifecycleRule[]>>;
|
|
121
|
+
/** `null` only when the object does not exist; every other failure is an error. */
|
|
122
|
+
head(key: string): Promise<Result<ObjectInfo | null>>;
|
|
123
|
+
/** Inclusive byte range. */
|
|
124
|
+
getRange(key: string, start: number, end: number): Promise<Result<Uint8Array>>;
|
|
125
|
+
/**
|
|
126
|
+
* Single PUT, up to `rules.maxSinglePutSize`. A Blob is streamed to the storage, never read into memory, so its
|
|
127
|
+
* payload is signed as UNSIGNED-PAYLOAD; other bodies are signed with their SHA-256. Without `options.type`, a Blob's
|
|
128
|
+
* own `type` becomes the stored content type.
|
|
129
|
+
*/
|
|
130
|
+
put(key: string, body: Uint8Array<ArrayBuffer> | ArrayBuffer | string | Blob, options?: WriteOptions): Promise<Result<{
|
|
131
|
+
etag: string;
|
|
132
|
+
}>>;
|
|
133
|
+
/**
|
|
134
|
+
* Server-side copy that keeps type, disposition and metadata; multipart copy above the single-PUT limit. Every copy
|
|
135
|
+
* request is conditional on the source's ETag, so a source overwritten during the copy fails it with a retryable
|
|
136
|
+
* STORAGE_ERROR instead of mixing two versions.
|
|
137
|
+
*/
|
|
138
|
+
copy(from: string, to: string): Promise<Result<{
|
|
139
|
+
etag: string;
|
|
140
|
+
}>>;
|
|
141
|
+
/** Idempotent: deleting a missing key succeeds. */
|
|
142
|
+
delete(key: string): Promise<Result<void>>;
|
|
143
|
+
/**
|
|
144
|
+
* Deletes any number of keys, one DeleteObject request per key, 16 at a time. Every key ends up in `deleted` (a
|
|
145
|
+
* missing key counts as deleted) or in `failed` with its own error; an invalid key fails without a request. Order is
|
|
146
|
+
* not guaranteed.
|
|
147
|
+
*/
|
|
148
|
+
deleteMany(keys: readonly string[]): Promise<Result<{
|
|
149
|
+
deleted: string[];
|
|
150
|
+
failed: {
|
|
151
|
+
key: string;
|
|
152
|
+
error: CloudropError;
|
|
153
|
+
}[];
|
|
154
|
+
}>>;
|
|
155
|
+
list(prefix: string, options?: {
|
|
156
|
+
cursor?: string;
|
|
157
|
+
limit?: number;
|
|
158
|
+
}): Promise<Result<{
|
|
159
|
+
items: ListedObject[];
|
|
160
|
+
nextCursor: string | null;
|
|
161
|
+
}>>;
|
|
162
|
+
}
|
|
163
|
+
/** A file the server has accepted and given a key, before any byte is uploaded. */
|
|
164
|
+
interface PluginFile {
|
|
165
|
+
id: string;
|
|
166
|
+
key: string;
|
|
167
|
+
name: string;
|
|
168
|
+
size: number;
|
|
169
|
+
type: string;
|
|
170
|
+
}
|
|
171
|
+
interface BeforeUploadContext {
|
|
172
|
+
request: Request;
|
|
173
|
+
route: string;
|
|
174
|
+
files: readonly PluginFile[];
|
|
175
|
+
metadata: unknown;
|
|
176
|
+
auth: unknown;
|
|
177
|
+
}
|
|
178
|
+
interface AfterVerifyContext {
|
|
179
|
+
request: Request;
|
|
180
|
+
route: string;
|
|
181
|
+
file: UploadedFile;
|
|
182
|
+
metadata: unknown;
|
|
183
|
+
auth: unknown;
|
|
184
|
+
storage: StorageDriver;
|
|
185
|
+
}
|
|
186
|
+
interface AbortContext {
|
|
187
|
+
route: string;
|
|
188
|
+
file: PluginFile;
|
|
189
|
+
metadata: unknown;
|
|
190
|
+
auth: unknown;
|
|
191
|
+
/** "aborted": the client called /abort. "rejected": a check refused the file. "failed": the server could not start it. */
|
|
192
|
+
reason: "aborted" | "rejected" | "failed";
|
|
193
|
+
}
|
|
194
|
+
interface ServerHooks {
|
|
195
|
+
/** Runs in `/upload` after authorization and policy, before anything is signed. Return an error to refuse every file. */
|
|
196
|
+
beforeUpload?(context: BeforeUploadContext): Awaitable<CloudropError | undefined>;
|
|
197
|
+
/** Runs in `/complete` after verification, before `onComplete`. An error deletes the object and reaches the client. */
|
|
198
|
+
afterVerify?(context: AfterVerifyContext): Awaitable<CloudropError | undefined>;
|
|
199
|
+
/**
|
|
200
|
+
* Runs when a file this plugin's `beforeUpload` accepted is refused, cannot be started, is rejected at `/complete` or
|
|
201
|
+
* is ended through an `/abort` that keeps nothing: after a cancel, or after a failure no `/complete` may have
|
|
202
|
+
* finished, which the client cleans up at once. Release a reservation here. Nothing runs when an abandoned upload's
|
|
203
|
+
* token expires, so a reservation also needs its own expiry. It can run more than once for one file; make it
|
|
204
|
+
* idempotent by `file.id`.
|
|
205
|
+
*/
|
|
206
|
+
onAbort?(context: AbortContext): Awaitable<void>;
|
|
207
|
+
/** Runs once per route in `createCloudrop`; throw a CloudropError with INVALID_CONFIG to refuse the route. */
|
|
208
|
+
extendRoute?(route: {
|
|
209
|
+
name: string;
|
|
210
|
+
definition: RouteDefinition;
|
|
211
|
+
}): void;
|
|
212
|
+
}
|
|
213
|
+
interface CloudropPlugin {
|
|
214
|
+
id: string;
|
|
215
|
+
server?: ServerHooks;
|
|
216
|
+
}
|
|
217
|
+
interface Logger {
|
|
218
|
+
error(message: string, error?: unknown): void;
|
|
219
|
+
warn(message: string): void;
|
|
220
|
+
}
|
|
221
|
+
/** An owner's limit in bytes, or null for no limit. */
|
|
222
|
+
type Quota = (owner: string) => Awaitable<number | null>;
|
|
223
|
+
interface StoreOptions {
|
|
224
|
+
/**
|
|
225
|
+
* A database store, such as `sqlStore(...)` from `cloudrop/adapters/sql`. With one, `/upload` writes a row per file
|
|
226
|
+
* before anything is signed, `onComplete` runs once per file, `/abort` never deletes a completed file, and `api`
|
|
227
|
+
* gains `file`, `usage`, `revokeUploads`, `deleteFile`, `reconcile` and `sweep`.
|
|
228
|
+
*/
|
|
229
|
+
store?: CloudropStore<unknown>;
|
|
230
|
+
/**
|
|
231
|
+
* With a store: each owner's limit in bytes (null: no limit), asked once per `/upload` before its files are reserved.
|
|
232
|
+
* A file over the limit is refused with QUOTA_EXCEEDED; a throw refuses the whole upload, retryably.
|
|
233
|
+
*/
|
|
234
|
+
quota?: Quota;
|
|
235
|
+
/**
|
|
236
|
+
* With a store: how long a `/complete` may hold a file while `onComplete` runs before another request may take it
|
|
237
|
+
* over. Make it longer than your slowest `onComplete`. Default 300000 (5 minutes).
|
|
238
|
+
*/
|
|
239
|
+
completionLeaseMs?: number;
|
|
240
|
+
}
|
|
241
|
+
interface CloudropOptions<TRoutes extends Record<string, Route>> extends StoreOptions {
|
|
242
|
+
/** `r2({ bucket })` or `s3({ ... })`. */
|
|
243
|
+
storage: StorageDriver;
|
|
244
|
+
routes: TRoutes;
|
|
245
|
+
/**
|
|
246
|
+
* HMAC secrets for upload tokens, each at least 32 characters. The first signs; every one verifies, so put a new
|
|
247
|
+
* secret first and keep the old one until its tokens expire (24 hours). Use a different secret for every deployment:
|
|
248
|
+
* a token verifies wherever its secret is configured. Default: env CLOUDROP_SECRET.
|
|
249
|
+
*/
|
|
250
|
+
secret?: string | readonly string[];
|
|
251
|
+
/** Where the handler is mounted. Default "/api/cloudrop". */
|
|
252
|
+
basePath?: string;
|
|
253
|
+
/**
|
|
254
|
+
* Exact origins, such as "https://app.example.com", allowed to call the handler cross-origin with credentials. Behind
|
|
255
|
+
* a proxy that terminates TLS or rewrites Host, list the app's own public origin too: no forwarded header is trusted.
|
|
256
|
+
*/
|
|
257
|
+
trustedOrigins?: readonly string[];
|
|
258
|
+
/** Files larger than this use multipart. Default 64 MiB. */
|
|
259
|
+
multipartThreshold?: Size;
|
|
260
|
+
plugins?: readonly CloudropPlugin[];
|
|
261
|
+
/** Where failures inside the handler and configuration warnings go. Default: console. */
|
|
262
|
+
logger?: Logger;
|
|
263
|
+
}
|
|
264
|
+
interface BucketCheck {
|
|
265
|
+
/**
|
|
266
|
+
* "unknown": the credentials may not read this setting (R2 object tokens cannot), the storage cannot report it
|
|
267
|
+
* (Wrangler's local R2), or nothing was given to check.
|
|
268
|
+
*/
|
|
269
|
+
status: "ok" | "problem" | "unknown";
|
|
270
|
+
message: string;
|
|
271
|
+
}
|
|
272
|
+
interface BucketReport {
|
|
273
|
+
cors: BucketCheck;
|
|
274
|
+
lifecycle: BucketCheck;
|
|
275
|
+
publicAccess: BucketCheck;
|
|
276
|
+
}
|
|
277
|
+
interface SweepOptions {
|
|
278
|
+
/** Rows handled in this call, 1 to 1000. Default 100. */
|
|
279
|
+
limit?: number;
|
|
280
|
+
/** The `cursor` an earlier sweep returned, to continue where it stopped. */
|
|
281
|
+
cursor?: string;
|
|
282
|
+
/**
|
|
283
|
+
* How long past its token's deadline an unfinished upload, and past its end an ended one, is left alone. At least
|
|
284
|
+
* 900000 (15 minutes, the life of an upload URL), so no new PUT can start once a row may be cleaned up. A PUT already
|
|
285
|
+
* under way that lands after its row was cleaned is left in the bucket. Default 3600000 (1 hour). The sweep takes
|
|
286
|
+
* each row before it deletes anything, so a completion that started in time is never harmed; the grace keeps a slow
|
|
287
|
+
* one from being refused.
|
|
288
|
+
*/
|
|
289
|
+
graceMs?: number;
|
|
290
|
+
}
|
|
291
|
+
interface SweepReport {
|
|
292
|
+
/** Unfinished uploads ended as expired, with what they left removed. */
|
|
293
|
+
expired: number;
|
|
294
|
+
/** Ended uploads whose late objects and parts were removed. */
|
|
295
|
+
cleaned: number;
|
|
296
|
+
/**
|
|
297
|
+
* Rows that failed this time (a storage or database error, logged with the row's id). Each stays as it was and the
|
|
298
|
+
* next sweep tries it again; the rows after it were still swept. A listing that failed after some rows counts too.
|
|
299
|
+
*/
|
|
300
|
+
failed: number;
|
|
301
|
+
/**
|
|
302
|
+
* Completions stuck past their lease and deadline, now ended as failed. Their objects are kept, because their
|
|
303
|
+
* onComplete may have recorded them: check each one. A row is reported once.
|
|
304
|
+
*/
|
|
305
|
+
reported: FileRecord[];
|
|
306
|
+
/**
|
|
307
|
+
* Pass it to the next sweep to continue; null when every row has been seen, or when a listing failed after this call
|
|
308
|
+
* had handled rows (counted in `failed`). A listing that fails before any row answers the store's error instead.
|
|
309
|
+
*/
|
|
310
|
+
cursor: string | null;
|
|
311
|
+
}
|
|
312
|
+
interface StoreFileApi {
|
|
313
|
+
/** A file's row, or null when the store has none. */
|
|
314
|
+
file(id: string): Promise<Result<FileRecord | null>>;
|
|
315
|
+
/** An owner's counters, with or without a quota. */
|
|
316
|
+
usage(owner: string): Promise<Result<OwnerUsage>>;
|
|
317
|
+
/** Ends an owner's unfinished uploads, such as at sign-out: their next /sign or /complete is refused. */
|
|
318
|
+
revokeUploads(options: {
|
|
319
|
+
owner: string;
|
|
320
|
+
}): Promise<Result<{
|
|
321
|
+
revoked: number;
|
|
322
|
+
}>>;
|
|
323
|
+
/** Deletes a completed file: its row becomes `deleted`, its bytes are released and its object removed. Idempotent. */
|
|
324
|
+
deleteFile(id: string): Promise<Result<{
|
|
325
|
+
id: string;
|
|
326
|
+
}>>;
|
|
327
|
+
/** Recounts one owner's counters from their rows, or every owner's: for drift after manual database edits. */
|
|
328
|
+
reconcile(options?: {
|
|
329
|
+
owner?: string;
|
|
330
|
+
}): Promise<Result<{
|
|
331
|
+
checked: number;
|
|
332
|
+
repaired: number;
|
|
333
|
+
}>>;
|
|
334
|
+
/** One bounded round of cleanup; run it on a schedule, such as an hourly cron. */
|
|
335
|
+
sweep(options?: SweepOptions): Promise<Result<SweepReport>>;
|
|
336
|
+
}
|
|
337
|
+
interface FileApi extends Pick<StorageDriver, "head" | "delete" | "deleteMany" | "copy">, StoreFileApi {
|
|
338
|
+
/**
|
|
339
|
+
* A URL to read the object. With the storage's publicUrl and no options: the plain public URL. Otherwise a presigned
|
|
340
|
+
* GET signed at the start of an `expiresIn` window (default 3600 s) and valid for two windows, so every viewer in a
|
|
341
|
+
* window gets the same cacheable URL, valid for at least `expiresIn` more seconds. `download` names the saved file.
|
|
342
|
+
*/
|
|
343
|
+
getUrl(key: string, options?: {
|
|
344
|
+
expiresIn?: number;
|
|
345
|
+
download?: string;
|
|
346
|
+
}): Promise<Result<{
|
|
347
|
+
url: string;
|
|
348
|
+
expiresAt: Date | null;
|
|
349
|
+
}>>;
|
|
350
|
+
/** A small server-side upload, up to the storage's single-PUT limit. */
|
|
351
|
+
put(key: string, body: Uint8Array<ArrayBuffer> | ArrayBuffer | string | Blob, options?: ObjectOptions): Promise<Result<{
|
|
352
|
+
etag: string;
|
|
353
|
+
}>>;
|
|
354
|
+
/**
|
|
355
|
+
* Deletes everything under a folder prefix ending in "/", page by page, then lists it again: `verifiedAt` is when the
|
|
356
|
+
* listing came back empty. For erasure requests.
|
|
357
|
+
*/
|
|
358
|
+
deletePrefix(prefix: string): Promise<Result<{
|
|
359
|
+
deleted: number;
|
|
360
|
+
verifiedAt: Date;
|
|
361
|
+
}>>;
|
|
362
|
+
/** CORS for `origins` (default: trustedOrigins), the abort-incomplete lifecycle rule, and public-domain conflicts. */
|
|
363
|
+
checkBucket(options?: {
|
|
364
|
+
origins?: readonly string[];
|
|
365
|
+
}): Promise<Result<BucketReport>>;
|
|
366
|
+
}
|
|
367
|
+
type RouteTypeMap<TRoutes extends Record<string, Route>> = { [TName in keyof TRoutes & string]: TRoutes[TName] extends Route<infer TMetadata, infer TResult> ? {
|
|
368
|
+
metadata: TMetadata;
|
|
369
|
+
result: TResult;
|
|
370
|
+
} : never; };
|
|
371
|
+
interface Cloudrop<TRoutes extends Record<string, Route> = Record<string, Route>> extends InferableCloudrop<RouteTypeMap<TRoutes>> {
|
|
372
|
+
/** The single adapter surface: mount it at `basePath` in any framework that speaks Request and Response. */
|
|
373
|
+
handler(request: Request): Promise<Response>;
|
|
374
|
+
/** Server-side file operations on the same storage, each returning { data, error }. */
|
|
375
|
+
readonly api: FileApi;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Checks every option now and throws INVALID_CONFIG for a mistake, so a misconfigured server fails at start-up.
|
|
379
|
+
* Settings from the environment (CLOUDROP_SECRET, a storage preset's variables) are read on the first request instead,
|
|
380
|
+
* so a build needs no secrets; one still missing then makes every request answer 500 and every api call INVALID_CONFIG
|
|
381
|
+
* until it is set. With NODE_ENV=development they are checked now too.
|
|
382
|
+
*/
|
|
383
|
+
export declare function createCloudrop<TRoutes extends Record<string, Route>>(options: CloudropOptions<TRoutes>): Cloudrop<TRoutes>;
|
|
384
|
+
interface R2Options {
|
|
385
|
+
/** Default: env CLOUDROP_R2_BUCKET. */
|
|
386
|
+
bucket?: string;
|
|
387
|
+
/** Default: env CLOUDROP_R2_ACCOUNT_ID. */
|
|
388
|
+
accountId?: string;
|
|
389
|
+
/** Default: env CLOUDROP_R2_ACCESS_KEY_ID. */
|
|
390
|
+
accessKeyId?: string;
|
|
391
|
+
/** Default: env CLOUDROP_R2_SECRET_ACCESS_KEY. */
|
|
392
|
+
secretAccessKey?: string;
|
|
393
|
+
/** The bucket's jurisdiction, which selects its endpoint. Omit it for a bucket in the default location. */
|
|
394
|
+
jurisdiction?: "eu" | "fedramp";
|
|
395
|
+
/**
|
|
396
|
+
* Where the bucket is served publicly (a custom domain or r2.dev URL, a path allowed), such as
|
|
397
|
+
* "https://cdn.example.com/files"; no query or fragment. Trailing slashes are dropped.
|
|
398
|
+
*/
|
|
399
|
+
publicUrl?: string;
|
|
400
|
+
fetch?: FetchLike;
|
|
401
|
+
}
|
|
402
|
+
interface S3Options {
|
|
403
|
+
/**
|
|
404
|
+
* An http or https URL with no query or fragment, such as "https://s3.us-east-1.amazonaws.com". A path is kept as a
|
|
405
|
+
* prefix of every request, for a service behind a proxy path. Default: env CLOUDROP_S3_ENDPOINT.
|
|
406
|
+
*/
|
|
407
|
+
endpoint?: string;
|
|
408
|
+
/** Default: env CLOUDROP_S3_REGION. */
|
|
409
|
+
region?: string;
|
|
410
|
+
/** Default: env CLOUDROP_S3_BUCKET. */
|
|
411
|
+
bucket?: string;
|
|
412
|
+
/** Default: env CLOUDROP_S3_ACCESS_KEY_ID. */
|
|
413
|
+
accessKeyId?: string;
|
|
414
|
+
/** Default: env CLOUDROP_S3_SECRET_ACCESS_KEY. */
|
|
415
|
+
secretAccessKey?: string;
|
|
416
|
+
publicUrl?: string;
|
|
417
|
+
fetch?: FetchLike;
|
|
418
|
+
}
|
|
419
|
+
export declare function r2(given?: R2Options): StorageDriver;
|
|
420
|
+
export declare function s3(given?: S3Options): StorageDriver;
|
|
421
|
+
export { type AbortContext, type AfterCompleteContext, type AfterVerifyContext, type AuthorizeContext, type BeforeUploadContext, type BucketCheck, type BucketCorsRule, type BucketLifecycleRule, type BucketReport, type ClaimOutcome, type Cloudrop, CloudropError, type CloudropErrorCode, type CloudropErrorOptions, type CloudropOptions, type CloudropPlugin, type CloudropStore, type CompleteContext, type CompletedPart, type EndedStatus, type FetchLike, type FileApi, type FileRecord, type FileStatus, type InferableCloudrop, type KeyContext, type ListedObject, type Logger, type NewFile, type ObjectInfo, type ObjectOptions, type OwnerContext, type OwnerUsage, type PartInfo, type PluginFile, type PresignedRequest, type Quota, type R2Options, type Refusal, type Result, type Route, type RouteCallbacks, type RouteDefinition, type RouteFunction, type RouteMetadata, type RouteName, type RoutePolicy, type RouteResult, type S3Options, type ServerHooks, type Size, type StandardSchema, type StorageDriver, type StorageRules, type StoreFileApi, type StoreOptions, type SweepOptions, type SweepReport, type TransactionalStore, type Transition, type UploadedFile, type WriteOptions, allowAnyone, forbidden, route, unauthorized };
|