@gl-life/gl-life-database 1.0.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/API.md +1486 -0
- package/LICENSE +190 -0
- package/README.md +480 -0
- package/dist/cache/index.d.ts +4 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/invalidation.d.ts +156 -0
- package/dist/cache/invalidation.d.ts.map +1 -0
- package/dist/cache/kv-cache.d.ts +79 -0
- package/dist/cache/kv-cache.d.ts.map +1 -0
- package/dist/cache/memory-cache.d.ts +68 -0
- package/dist/cache/memory-cache.d.ts.map +1 -0
- package/dist/cloudforge/d1-adapter.d.ts +67 -0
- package/dist/cloudforge/d1-adapter.d.ts.map +1 -0
- package/dist/cloudforge/do-storage.d.ts +51 -0
- package/dist/cloudforge/do-storage.d.ts.map +1 -0
- package/dist/cloudforge/index.d.ts +4 -0
- package/dist/cloudforge/index.d.ts.map +1 -0
- package/dist/cloudforge/r2-backup.d.ts +38 -0
- package/dist/cloudforge/r2-backup.d.ts.map +1 -0
- package/dist/connection/index.d.ts +2 -0
- package/dist/connection/index.d.ts.map +1 -0
- package/dist/connection/manager.d.ts +54 -0
- package/dist/connection/manager.d.ts.map +1 -0
- package/dist/index.cjs +4762 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4701 -0
- package/dist/index.js.map +1 -0
- package/dist/migration/index.d.ts +4 -0
- package/dist/migration/index.d.ts.map +1 -0
- package/dist/migration/loader.d.ts +88 -0
- package/dist/migration/loader.d.ts.map +1 -0
- package/dist/migration/runner.d.ts +91 -0
- package/dist/migration/runner.d.ts.map +1 -0
- package/dist/migration/seeder.d.ts +95 -0
- package/dist/migration/seeder.d.ts.map +1 -0
- package/dist/query/builder.d.ts +47 -0
- package/dist/query/builder.d.ts.map +1 -0
- package/dist/query/index.d.ts +3 -0
- package/dist/query/index.d.ts.map +1 -0
- package/dist/query/raw.d.ts +92 -0
- package/dist/query/raw.d.ts.map +1 -0
- package/dist/tenant/context.d.ts +52 -0
- package/dist/tenant/context.d.ts.map +1 -0
- package/dist/tenant/index.d.ts +4 -0
- package/dist/tenant/index.d.ts.map +1 -0
- package/dist/tenant/query-wrapper.d.ts +96 -0
- package/dist/tenant/query-wrapper.d.ts.map +1 -0
- package/dist/tenant/schema-manager.d.ts +185 -0
- package/dist/tenant/schema-manager.d.ts.map +1 -0
- package/dist/transaction/index.d.ts +2 -0
- package/dist/transaction/index.d.ts.map +1 -0
- package/dist/transaction/transaction.d.ts +51 -0
- package/dist/transaction/transaction.d.ts.map +1 -0
- package/dist/types/cache.d.ts +214 -0
- package/dist/types/cache.d.ts.map +1 -0
- package/dist/types/cloudforge.d.ts +753 -0
- package/dist/types/cloudforge.d.ts.map +1 -0
- package/dist/types/connection.d.ts +91 -0
- package/dist/types/connection.d.ts.map +1 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/migration.d.ts +225 -0
- package/dist/types/migration.d.ts.map +1 -0
- package/dist/types/plugin.d.ts +432 -0
- package/dist/types/plugin.d.ts.map +1 -0
- package/dist/types/query-builder.d.ts +217 -0
- package/dist/types/query-builder.d.ts.map +1 -0
- package/dist/types/seed.d.ts +187 -0
- package/dist/types/seed.d.ts.map +1 -0
- package/dist/types/tenant.d.ts +140 -0
- package/dist/types/tenant.d.ts.map +1 -0
- package/dist/types/transaction.d.ts +144 -0
- package/dist/types/transaction.d.ts.map +1 -0
- package/package.json +78 -0
|
@@ -0,0 +1,753 @@
|
|
|
1
|
+
import { Result } from '@gl-life/gl-life-core';
|
|
2
|
+
import type { DatabaseConnectionError } from './connection.js';
|
|
3
|
+
/**
|
|
4
|
+
* Cloudflare D1 database binding interface
|
|
5
|
+
*
|
|
6
|
+
* This represents the D1 database binding available in Cloudflare Workers
|
|
7
|
+
*/
|
|
8
|
+
export interface D1Database {
|
|
9
|
+
/**
|
|
10
|
+
* Execute a query and return results
|
|
11
|
+
*/
|
|
12
|
+
prepare(query: string): D1PreparedStatement;
|
|
13
|
+
/**
|
|
14
|
+
* Execute multiple queries in a batch
|
|
15
|
+
*/
|
|
16
|
+
batch<T = unknown>(statements: D1PreparedStatement[]): Promise<D1Result<T>[]>;
|
|
17
|
+
/**
|
|
18
|
+
* Execute SQL directly (for migrations)
|
|
19
|
+
*/
|
|
20
|
+
exec(sql: string): Promise<D1ExecResult>;
|
|
21
|
+
/**
|
|
22
|
+
* Dump database schema and data
|
|
23
|
+
*/
|
|
24
|
+
dump(): Promise<ArrayBuffer>;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* D1 prepared statement interface
|
|
28
|
+
*/
|
|
29
|
+
export interface D1PreparedStatement {
|
|
30
|
+
/**
|
|
31
|
+
* Bind parameters to the statement
|
|
32
|
+
*/
|
|
33
|
+
bind(...params: unknown[]): D1PreparedStatement;
|
|
34
|
+
/**
|
|
35
|
+
* Execute and return first row
|
|
36
|
+
*/
|
|
37
|
+
first<T = unknown>(colName?: string): Promise<T | null>;
|
|
38
|
+
/**
|
|
39
|
+
* Execute and return all rows
|
|
40
|
+
*/
|
|
41
|
+
all<T = unknown>(): Promise<D1Result<T>>;
|
|
42
|
+
/**
|
|
43
|
+
* Execute and return raw results
|
|
44
|
+
*/
|
|
45
|
+
raw<T = unknown[]>(): Promise<T[]>;
|
|
46
|
+
/**
|
|
47
|
+
* Execute without returning results
|
|
48
|
+
*/
|
|
49
|
+
run(): Promise<D1Result>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* D1 query result interface
|
|
53
|
+
*/
|
|
54
|
+
export interface D1Result<T = unknown> {
|
|
55
|
+
/**
|
|
56
|
+
* Query results
|
|
57
|
+
*/
|
|
58
|
+
results?: T[];
|
|
59
|
+
/**
|
|
60
|
+
* Whether the query was successful
|
|
61
|
+
*/
|
|
62
|
+
success: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Query execution metadata
|
|
65
|
+
*/
|
|
66
|
+
meta?: {
|
|
67
|
+
/**
|
|
68
|
+
* Number of rows changed
|
|
69
|
+
*/
|
|
70
|
+
changes?: number;
|
|
71
|
+
/**
|
|
72
|
+
* Last inserted row ID
|
|
73
|
+
*/
|
|
74
|
+
last_row_id?: number;
|
|
75
|
+
/**
|
|
76
|
+
* Query duration in milliseconds
|
|
77
|
+
*/
|
|
78
|
+
duration?: number;
|
|
79
|
+
/**
|
|
80
|
+
* Number of rows returned
|
|
81
|
+
*/
|
|
82
|
+
rows_read?: number;
|
|
83
|
+
/**
|
|
84
|
+
* Number of rows written
|
|
85
|
+
*/
|
|
86
|
+
rows_written?: number;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Error information (if success is false)
|
|
90
|
+
*/
|
|
91
|
+
error?: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* D1 exec result interface (for raw SQL execution)
|
|
95
|
+
*/
|
|
96
|
+
export interface D1ExecResult {
|
|
97
|
+
/**
|
|
98
|
+
* Number of statements executed
|
|
99
|
+
*/
|
|
100
|
+
count: number;
|
|
101
|
+
/**
|
|
102
|
+
* Query duration in milliseconds
|
|
103
|
+
*/
|
|
104
|
+
duration: number;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* D1 adapter configuration
|
|
108
|
+
*/
|
|
109
|
+
export interface D1AdapterConfig {
|
|
110
|
+
/**
|
|
111
|
+
* D1 database binding
|
|
112
|
+
*/
|
|
113
|
+
database: D1Database;
|
|
114
|
+
/**
|
|
115
|
+
* Database name for logging
|
|
116
|
+
*/
|
|
117
|
+
name: string;
|
|
118
|
+
/**
|
|
119
|
+
* Enable query logging
|
|
120
|
+
*/
|
|
121
|
+
enableQueryLogging?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Maximum batch size for batch operations
|
|
124
|
+
*/
|
|
125
|
+
maxBatchSize?: number;
|
|
126
|
+
/**
|
|
127
|
+
* Query timeout in milliseconds
|
|
128
|
+
*/
|
|
129
|
+
timeout?: number;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* D1 adapter error types
|
|
133
|
+
*/
|
|
134
|
+
export type D1AdapterError = DatabaseConnectionError | {
|
|
135
|
+
type: 'QUERY_FAILED';
|
|
136
|
+
message: string;
|
|
137
|
+
sql: string;
|
|
138
|
+
cause?: unknown;
|
|
139
|
+
} | {
|
|
140
|
+
type: 'BATCH_FAILED';
|
|
141
|
+
message: string;
|
|
142
|
+
cause?: unknown;
|
|
143
|
+
} | {
|
|
144
|
+
type: 'INVALID_QUERY';
|
|
145
|
+
message: string;
|
|
146
|
+
sql: string;
|
|
147
|
+
} | {
|
|
148
|
+
type: 'PARAMETER_ERROR';
|
|
149
|
+
message: string;
|
|
150
|
+
} | {
|
|
151
|
+
type: 'EXEC_FAILED';
|
|
152
|
+
message: string;
|
|
153
|
+
cause?: unknown;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* D1 database adapter interface
|
|
157
|
+
*
|
|
158
|
+
* Provides a standardized interface for interacting with Cloudflare D1 databases
|
|
159
|
+
*/
|
|
160
|
+
export interface D1Adapter {
|
|
161
|
+
/**
|
|
162
|
+
* Adapter configuration
|
|
163
|
+
*/
|
|
164
|
+
readonly config: D1AdapterConfig;
|
|
165
|
+
/**
|
|
166
|
+
* Execute a SQL query
|
|
167
|
+
*
|
|
168
|
+
* @param sql - SQL query string
|
|
169
|
+
* @param params - Query parameters
|
|
170
|
+
* @returns Result with query results or D1AdapterError
|
|
171
|
+
*/
|
|
172
|
+
query<T = unknown>(sql: string, params?: unknown[]): Promise<Result<T[], D1AdapterError>>;
|
|
173
|
+
/**
|
|
174
|
+
* Execute a SQL query and return first result
|
|
175
|
+
*
|
|
176
|
+
* @param sql - SQL query string
|
|
177
|
+
* @param params - Query parameters
|
|
178
|
+
* @returns Result with first result or D1AdapterError
|
|
179
|
+
*/
|
|
180
|
+
queryFirst<T = unknown>(sql: string, params?: unknown[]): Promise<Result<T | null, D1AdapterError>>;
|
|
181
|
+
/**
|
|
182
|
+
* Execute a SQL statement (INSERT, UPDATE, DELETE)
|
|
183
|
+
*
|
|
184
|
+
* @param sql - SQL statement string
|
|
185
|
+
* @param params - Statement parameters
|
|
186
|
+
* @returns Result with execution metadata or D1AdapterError
|
|
187
|
+
*/
|
|
188
|
+
execute(sql: string, params?: unknown[]): Promise<Result<D1Result, D1AdapterError>>;
|
|
189
|
+
/**
|
|
190
|
+
* Execute multiple SQL statements in a batch
|
|
191
|
+
*
|
|
192
|
+
* @param statements - Array of SQL statements with parameters
|
|
193
|
+
* @returns Result with array of execution results or D1AdapterError
|
|
194
|
+
*/
|
|
195
|
+
batch(statements: Array<{
|
|
196
|
+
sql: string;
|
|
197
|
+
params?: unknown[];
|
|
198
|
+
}>): Promise<Result<D1Result[], D1AdapterError>>;
|
|
199
|
+
/**
|
|
200
|
+
* Execute raw SQL (for migrations and schema changes)
|
|
201
|
+
*
|
|
202
|
+
* @param sql - Raw SQL to execute
|
|
203
|
+
* @returns Result with execution result or D1AdapterError
|
|
204
|
+
*/
|
|
205
|
+
exec(sql: string): Promise<Result<D1ExecResult, D1AdapterError>>;
|
|
206
|
+
/**
|
|
207
|
+
* Begin a transaction
|
|
208
|
+
*
|
|
209
|
+
* @param callback - Transaction callback function
|
|
210
|
+
* @returns Result with callback result or D1AdapterError
|
|
211
|
+
*/
|
|
212
|
+
transaction<T>(callback: (adapter: D1Adapter) => Promise<Result<T, D1AdapterError>>): Promise<Result<T, D1AdapterError>>;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Cloudflare Durable Objects Storage interface
|
|
216
|
+
*
|
|
217
|
+
* This represents the storage API available in Durable Objects
|
|
218
|
+
*/
|
|
219
|
+
export interface DurableObjectStorage {
|
|
220
|
+
/**
|
|
221
|
+
* Get a single value or multiple values by key
|
|
222
|
+
*/
|
|
223
|
+
get(key: string): Promise<any>;
|
|
224
|
+
get(keys: string[]): Promise<Map<string, any>>;
|
|
225
|
+
get(key: string | string[]): Promise<any | Map<string, any>>;
|
|
226
|
+
/**
|
|
227
|
+
* Put a single key-value pair or multiple pairs
|
|
228
|
+
*/
|
|
229
|
+
put(key: string, value: any): Promise<void>;
|
|
230
|
+
put(entries: Record<string, any>): Promise<void>;
|
|
231
|
+
put(key: string | Record<string, any>, value?: any): Promise<void>;
|
|
232
|
+
/**
|
|
233
|
+
* Delete a single key or multiple keys
|
|
234
|
+
*/
|
|
235
|
+
delete(key: string): Promise<boolean>;
|
|
236
|
+
delete(keys: string[]): Promise<number>;
|
|
237
|
+
delete(key: string | string[]): Promise<boolean | number>;
|
|
238
|
+
/**
|
|
239
|
+
* List keys in storage
|
|
240
|
+
*/
|
|
241
|
+
list(options?: StorageListOptions): Promise<Map<string, any>>;
|
|
242
|
+
/**
|
|
243
|
+
* Delete all keys in storage
|
|
244
|
+
*/
|
|
245
|
+
deleteAll(options?: StorageListOptions): Promise<void>;
|
|
246
|
+
/**
|
|
247
|
+
* Execute a transaction
|
|
248
|
+
*/
|
|
249
|
+
transaction<T>(callback: (txn: DurableObjectStorage) => Promise<T>): Promise<T>;
|
|
250
|
+
/**
|
|
251
|
+
* Get the current alarm timestamp
|
|
252
|
+
*/
|
|
253
|
+
getAlarm(): Promise<number | null>;
|
|
254
|
+
/**
|
|
255
|
+
* Set an alarm to trigger at a specific time
|
|
256
|
+
*/
|
|
257
|
+
setAlarm(scheduledTime: number | Date): Promise<void>;
|
|
258
|
+
/**
|
|
259
|
+
* Delete the current alarm
|
|
260
|
+
*/
|
|
261
|
+
deleteAlarm(): Promise<void>;
|
|
262
|
+
/**
|
|
263
|
+
* Synchronize storage to disk
|
|
264
|
+
*/
|
|
265
|
+
sync(): Promise<void>;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Storage list options
|
|
269
|
+
*/
|
|
270
|
+
export interface StorageListOptions {
|
|
271
|
+
/**
|
|
272
|
+
* Start key (inclusive)
|
|
273
|
+
*/
|
|
274
|
+
start?: string;
|
|
275
|
+
/**
|
|
276
|
+
* End key (exclusive)
|
|
277
|
+
*/
|
|
278
|
+
end?: string;
|
|
279
|
+
/**
|
|
280
|
+
* Key prefix filter
|
|
281
|
+
*/
|
|
282
|
+
prefix?: string;
|
|
283
|
+
/**
|
|
284
|
+
* Reverse the order of results
|
|
285
|
+
*/
|
|
286
|
+
reverse?: boolean;
|
|
287
|
+
/**
|
|
288
|
+
* Maximum number of keys to return
|
|
289
|
+
*/
|
|
290
|
+
limit?: number;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Durable Objects storage adapter configuration
|
|
294
|
+
*/
|
|
295
|
+
export interface DurableObjectStorageConfig {
|
|
296
|
+
/**
|
|
297
|
+
* Storage name for logging
|
|
298
|
+
*/
|
|
299
|
+
name: string;
|
|
300
|
+
/**
|
|
301
|
+
* Enable operation logging
|
|
302
|
+
*/
|
|
303
|
+
enableLogging?: boolean;
|
|
304
|
+
/**
|
|
305
|
+
* Allow concurrent operations (default: false for consistency)
|
|
306
|
+
*/
|
|
307
|
+
allowConcurrency?: boolean;
|
|
308
|
+
/**
|
|
309
|
+
* Cache options
|
|
310
|
+
*/
|
|
311
|
+
cacheOptions?: {
|
|
312
|
+
/**
|
|
313
|
+
* Enable in-memory caching
|
|
314
|
+
*/
|
|
315
|
+
enableMemoryCache?: boolean;
|
|
316
|
+
/**
|
|
317
|
+
* Cache TTL in milliseconds
|
|
318
|
+
*/
|
|
319
|
+
ttl?: number;
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Durable Objects storage error types
|
|
324
|
+
*/
|
|
325
|
+
export type DurableObjectStorageError = {
|
|
326
|
+
type: 'STORAGE_FAILED';
|
|
327
|
+
message: string;
|
|
328
|
+
key?: string;
|
|
329
|
+
cause?: unknown;
|
|
330
|
+
} | {
|
|
331
|
+
type: 'SERIALIZATION_ERROR';
|
|
332
|
+
message: string;
|
|
333
|
+
cause?: unknown;
|
|
334
|
+
} | {
|
|
335
|
+
type: 'TRANSACTION_FAILED';
|
|
336
|
+
message: string;
|
|
337
|
+
cause?: unknown;
|
|
338
|
+
} | {
|
|
339
|
+
type: 'QUOTA_EXCEEDED';
|
|
340
|
+
message: string;
|
|
341
|
+
} | {
|
|
342
|
+
type: 'INVALID_KEY';
|
|
343
|
+
message: string;
|
|
344
|
+
key?: string;
|
|
345
|
+
} | {
|
|
346
|
+
type: 'UNKNOWN';
|
|
347
|
+
message: string;
|
|
348
|
+
cause?: unknown;
|
|
349
|
+
};
|
|
350
|
+
/**
|
|
351
|
+
* Storage transaction interface for callback operations
|
|
352
|
+
*/
|
|
353
|
+
export interface StorageTransaction {
|
|
354
|
+
get<T>(key: string): Promise<Result<T | null, DurableObjectStorageError>>;
|
|
355
|
+
getMultiple<T>(keys: string[]): Promise<Result<Map<string, T>, DurableObjectStorageError>>;
|
|
356
|
+
put<T>(key: string, value: T): Promise<Result<void, DurableObjectStorageError>>;
|
|
357
|
+
putMultiple<T>(entries: [string, T][]): Promise<Result<void, DurableObjectStorageError>>;
|
|
358
|
+
delete(key: string): Promise<Result<boolean, DurableObjectStorageError>>;
|
|
359
|
+
deleteMultiple(keys: string[]): Promise<Result<number, DurableObjectStorageError>>;
|
|
360
|
+
list(options?: StorageListOptions): Promise<Result<Map<string, any>, DurableObjectStorageError>>;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Durable Objects storage adapter interface
|
|
364
|
+
*
|
|
365
|
+
* Provides a standardized interface for interacting with Durable Objects storage
|
|
366
|
+
*/
|
|
367
|
+
export interface DurableObjectStorageAdapter {
|
|
368
|
+
/**
|
|
369
|
+
* Adapter configuration
|
|
370
|
+
*/
|
|
371
|
+
readonly config: DurableObjectStorageConfig;
|
|
372
|
+
/**
|
|
373
|
+
* Get a single value by key
|
|
374
|
+
*
|
|
375
|
+
* @param key - Storage key
|
|
376
|
+
* @returns Result with value or null if not found
|
|
377
|
+
*/
|
|
378
|
+
get<T>(key: string): Promise<Result<T | null, DurableObjectStorageError>>;
|
|
379
|
+
/**
|
|
380
|
+
* Get multiple values by keys
|
|
381
|
+
*
|
|
382
|
+
* @param keys - Array of storage keys
|
|
383
|
+
* @returns Result with Map of key-value pairs
|
|
384
|
+
*/
|
|
385
|
+
getMultiple<T>(keys: string[]): Promise<Result<Map<string, T>, DurableObjectStorageError>>;
|
|
386
|
+
/**
|
|
387
|
+
* Put a single key-value pair
|
|
388
|
+
*
|
|
389
|
+
* @param key - Storage key
|
|
390
|
+
* @param value - Value to store
|
|
391
|
+
* @returns Result with void or error
|
|
392
|
+
*/
|
|
393
|
+
put<T>(key: string, value: T): Promise<Result<void, DurableObjectStorageError>>;
|
|
394
|
+
/**
|
|
395
|
+
* Put multiple key-value pairs
|
|
396
|
+
*
|
|
397
|
+
* @param entries - Array of [key, value] tuples
|
|
398
|
+
* @returns Result with void or error
|
|
399
|
+
*/
|
|
400
|
+
putMultiple<T>(entries: [string, T][]): Promise<Result<void, DurableObjectStorageError>>;
|
|
401
|
+
/**
|
|
402
|
+
* Delete a single key
|
|
403
|
+
*
|
|
404
|
+
* @param key - Storage key to delete
|
|
405
|
+
* @returns Result with boolean indicating if key existed
|
|
406
|
+
*/
|
|
407
|
+
delete(key: string): Promise<Result<boolean, DurableObjectStorageError>>;
|
|
408
|
+
/**
|
|
409
|
+
* Delete multiple keys
|
|
410
|
+
*
|
|
411
|
+
* @param keys - Array of storage keys to delete
|
|
412
|
+
* @returns Result with count of deleted keys
|
|
413
|
+
*/
|
|
414
|
+
deleteMultiple(keys: string[]): Promise<Result<number, DurableObjectStorageError>>;
|
|
415
|
+
/**
|
|
416
|
+
* Delete all keys in storage
|
|
417
|
+
*
|
|
418
|
+
* @returns Result with void or error
|
|
419
|
+
*/
|
|
420
|
+
deleteAll(): Promise<Result<void, DurableObjectStorageError>>;
|
|
421
|
+
/**
|
|
422
|
+
* List keys in storage
|
|
423
|
+
*
|
|
424
|
+
* @param options - List options (prefix, start, end, limit, reverse)
|
|
425
|
+
* @returns Result with Map of key-value pairs
|
|
426
|
+
*/
|
|
427
|
+
list(options?: StorageListOptions): Promise<Result<Map<string, any>, DurableObjectStorageError>>;
|
|
428
|
+
/**
|
|
429
|
+
* Execute operations in a transaction
|
|
430
|
+
*
|
|
431
|
+
* @param callback - Transaction callback function
|
|
432
|
+
* @returns Result with callback result or error
|
|
433
|
+
*/
|
|
434
|
+
transaction<T>(callback: (txn: StorageTransaction) => Promise<Result<T, DurableObjectStorageError>>): Promise<Result<T, DurableObjectStorageError>>;
|
|
435
|
+
}
|
|
436
|
+
/**
|
|
437
|
+
* Cloudflare R2 bucket binding interface
|
|
438
|
+
*
|
|
439
|
+
* This represents the R2 bucket binding available in Cloudflare Workers
|
|
440
|
+
*/
|
|
441
|
+
export interface R2Bucket {
|
|
442
|
+
/**
|
|
443
|
+
* Get object metadata only
|
|
444
|
+
*/
|
|
445
|
+
head(key: string): Promise<R2Object | null>;
|
|
446
|
+
/**
|
|
447
|
+
* Get object with body
|
|
448
|
+
*/
|
|
449
|
+
get(key: string, options?: R2GetOptions): Promise<R2ObjectBody | null>;
|
|
450
|
+
/**
|
|
451
|
+
* Put object
|
|
452
|
+
*/
|
|
453
|
+
put(key: string, value: ReadableStream | ArrayBuffer | ArrayBufferView | string | Blob, options?: R2PutOptions): Promise<R2Object>;
|
|
454
|
+
/**
|
|
455
|
+
* Delete single or multiple objects
|
|
456
|
+
*/
|
|
457
|
+
delete(key: string | string[]): Promise<void>;
|
|
458
|
+
/**
|
|
459
|
+
* List objects in bucket
|
|
460
|
+
*/
|
|
461
|
+
list(options?: R2ListOptions): Promise<R2Objects>;
|
|
462
|
+
/**
|
|
463
|
+
* Create multipart upload
|
|
464
|
+
*/
|
|
465
|
+
createMultipartUpload(key: string, options?: R2MultipartOptions): Promise<R2MultipartUpload>;
|
|
466
|
+
/**
|
|
467
|
+
* Resume multipart upload
|
|
468
|
+
*/
|
|
469
|
+
resumeMultipartUpload(key: string, uploadId: string): R2MultipartUpload;
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* R2 object metadata
|
|
473
|
+
*/
|
|
474
|
+
export interface R2Object {
|
|
475
|
+
key: string;
|
|
476
|
+
version: string;
|
|
477
|
+
size: number;
|
|
478
|
+
etag: string;
|
|
479
|
+
httpEtag: string;
|
|
480
|
+
uploaded: Date;
|
|
481
|
+
httpMetadata?: R2HttpMetadata;
|
|
482
|
+
customMetadata?: Record<string, string>;
|
|
483
|
+
storageClass?: 'Standard' | 'InfrequentAccess';
|
|
484
|
+
checksums?: R2Checksums;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* R2 object with body
|
|
488
|
+
*/
|
|
489
|
+
export interface R2ObjectBody extends R2Object {
|
|
490
|
+
body: ReadableStream;
|
|
491
|
+
bodyUsed: boolean;
|
|
492
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
493
|
+
text(): Promise<string>;
|
|
494
|
+
json<T = unknown>(): Promise<T>;
|
|
495
|
+
blob(): Promise<Blob>;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* R2 HTTP metadata
|
|
499
|
+
*/
|
|
500
|
+
export interface R2HttpMetadata {
|
|
501
|
+
contentType?: string;
|
|
502
|
+
contentLanguage?: string;
|
|
503
|
+
contentDisposition?: string;
|
|
504
|
+
contentEncoding?: string;
|
|
505
|
+
cacheControl?: string;
|
|
506
|
+
expires?: Date;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* R2 checksums
|
|
510
|
+
*/
|
|
511
|
+
export interface R2Checksums {
|
|
512
|
+
md5?: ArrayBuffer;
|
|
513
|
+
sha1?: ArrayBuffer;
|
|
514
|
+
sha256?: ArrayBuffer;
|
|
515
|
+
sha384?: ArrayBuffer;
|
|
516
|
+
sha512?: ArrayBuffer;
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* R2 get options
|
|
520
|
+
*/
|
|
521
|
+
export interface R2GetOptions {
|
|
522
|
+
onlyIf?: R2Conditional;
|
|
523
|
+
range?: {
|
|
524
|
+
offset?: number;
|
|
525
|
+
length?: number;
|
|
526
|
+
suffix?: number;
|
|
527
|
+
};
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* R2 conditional request
|
|
531
|
+
*/
|
|
532
|
+
export interface R2Conditional {
|
|
533
|
+
etagMatches?: string;
|
|
534
|
+
etagDoesNotMatch?: string;
|
|
535
|
+
uploadedBefore?: Date;
|
|
536
|
+
uploadedAfter?: Date;
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* R2 put options
|
|
540
|
+
*/
|
|
541
|
+
export interface R2PutOptions {
|
|
542
|
+
httpMetadata?: R2HttpMetadata;
|
|
543
|
+
customMetadata?: Record<string, string>;
|
|
544
|
+
md5?: string | ArrayBuffer;
|
|
545
|
+
sha256?: string | ArrayBuffer;
|
|
546
|
+
storageClass?: 'Standard' | 'InfrequentAccess';
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* R2 list options
|
|
550
|
+
*/
|
|
551
|
+
export interface R2ListOptions {
|
|
552
|
+
limit?: number;
|
|
553
|
+
prefix?: string;
|
|
554
|
+
cursor?: string;
|
|
555
|
+
delimiter?: string;
|
|
556
|
+
include?: ('httpMetadata' | 'customMetadata')[];
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* R2 list result
|
|
560
|
+
*/
|
|
561
|
+
export interface R2Objects {
|
|
562
|
+
objects: R2Object[];
|
|
563
|
+
truncated: boolean;
|
|
564
|
+
cursor?: string;
|
|
565
|
+
delimitedPrefixes: string[];
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* R2 multipart upload
|
|
569
|
+
*/
|
|
570
|
+
export interface R2MultipartUpload {
|
|
571
|
+
uploadPart(partNumber: number, value: ReadableStream | ArrayBuffer | ArrayBufferView | string | Blob): Promise<R2UploadedPart>;
|
|
572
|
+
completeMultipartUpload(parts: R2UploadedPart[]): Promise<R2Object>;
|
|
573
|
+
abort(): Promise<void>;
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* R2 multipart options
|
|
577
|
+
*/
|
|
578
|
+
export interface R2MultipartOptions {
|
|
579
|
+
httpMetadata?: R2HttpMetadata;
|
|
580
|
+
customMetadata?: Record<string, string>;
|
|
581
|
+
}
|
|
582
|
+
/**
|
|
583
|
+
* R2 uploaded part
|
|
584
|
+
*/
|
|
585
|
+
export interface R2UploadedPart {
|
|
586
|
+
partNumber: number;
|
|
587
|
+
etag: string;
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* Backup information
|
|
591
|
+
*/
|
|
592
|
+
export interface BackupInfo {
|
|
593
|
+
key: string;
|
|
594
|
+
size: number;
|
|
595
|
+
compressedSize: number;
|
|
596
|
+
compressionRatio: number;
|
|
597
|
+
uploadedAt: Date;
|
|
598
|
+
etag: string;
|
|
599
|
+
metadata?: {
|
|
600
|
+
databaseVersion?: string;
|
|
601
|
+
backupType?: string;
|
|
602
|
+
originalChecksum?: string;
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Backup options
|
|
607
|
+
*/
|
|
608
|
+
export interface BackupOptions {
|
|
609
|
+
/**
|
|
610
|
+
* Compression level (0-9, default: 6)
|
|
611
|
+
*/
|
|
612
|
+
compressionLevel?: number;
|
|
613
|
+
/**
|
|
614
|
+
* Custom metadata to attach
|
|
615
|
+
*/
|
|
616
|
+
metadata?: Record<string, string>;
|
|
617
|
+
/**
|
|
618
|
+
* Storage class
|
|
619
|
+
*/
|
|
620
|
+
storageClass?: 'Standard' | 'InfrequentAccess';
|
|
621
|
+
/**
|
|
622
|
+
* Use multipart upload threshold (bytes, default: 100MB)
|
|
623
|
+
*/
|
|
624
|
+
multipartThreshold?: number;
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* Restore options
|
|
628
|
+
*/
|
|
629
|
+
export interface RestoreOptions {
|
|
630
|
+
/**
|
|
631
|
+
* Verify checksum after restore
|
|
632
|
+
*/
|
|
633
|
+
verifyChecksum?: boolean;
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* R2 backup adapter configuration
|
|
637
|
+
*/
|
|
638
|
+
export interface R2BackupConfig {
|
|
639
|
+
/**
|
|
640
|
+
* R2 bucket binding
|
|
641
|
+
*/
|
|
642
|
+
bucket: R2Bucket;
|
|
643
|
+
/**
|
|
644
|
+
* Backup name prefix
|
|
645
|
+
*/
|
|
646
|
+
name: string;
|
|
647
|
+
/**
|
|
648
|
+
* Enable operation logging
|
|
649
|
+
*/
|
|
650
|
+
enableLogging?: boolean;
|
|
651
|
+
/**
|
|
652
|
+
* Default compression level (0-9)
|
|
653
|
+
*/
|
|
654
|
+
defaultCompressionLevel?: number;
|
|
655
|
+
/**
|
|
656
|
+
* Multipart upload threshold in bytes
|
|
657
|
+
*/
|
|
658
|
+
multipartThreshold?: number;
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* R2 backup error types
|
|
662
|
+
*/
|
|
663
|
+
export type R2BackupError = {
|
|
664
|
+
type: 'UPLOAD_FAILED';
|
|
665
|
+
message: string;
|
|
666
|
+
key?: string;
|
|
667
|
+
cause?: unknown;
|
|
668
|
+
} | {
|
|
669
|
+
type: 'DOWNLOAD_FAILED';
|
|
670
|
+
message: string;
|
|
671
|
+
key?: string;
|
|
672
|
+
cause?: unknown;
|
|
673
|
+
} | {
|
|
674
|
+
type: 'RESTORE_FAILED';
|
|
675
|
+
message: string;
|
|
676
|
+
cause?: unknown;
|
|
677
|
+
} | {
|
|
678
|
+
type: 'COMPRESSION_FAILED';
|
|
679
|
+
message: string;
|
|
680
|
+
cause?: unknown;
|
|
681
|
+
} | {
|
|
682
|
+
type: 'DECOMPRESSION_FAILED';
|
|
683
|
+
message: string;
|
|
684
|
+
cause?: unknown;
|
|
685
|
+
} | {
|
|
686
|
+
type: 'BACKUP_NOT_FOUND';
|
|
687
|
+
message: string;
|
|
688
|
+
key: string;
|
|
689
|
+
} | {
|
|
690
|
+
type: 'INVALID_BACKUP';
|
|
691
|
+
message: string;
|
|
692
|
+
cause?: unknown;
|
|
693
|
+
} | {
|
|
694
|
+
type: 'SCHEDULE_FAILED';
|
|
695
|
+
message: string;
|
|
696
|
+
cause?: unknown;
|
|
697
|
+
} | {
|
|
698
|
+
type: 'UNKNOWN';
|
|
699
|
+
message: string;
|
|
700
|
+
cause?: unknown;
|
|
701
|
+
};
|
|
702
|
+
/**
|
|
703
|
+
* R2 backup adapter interface
|
|
704
|
+
*
|
|
705
|
+
* Provides database backup and restore functionality using Cloudflare R2
|
|
706
|
+
*/
|
|
707
|
+
export interface R2BackupAdapter {
|
|
708
|
+
/**
|
|
709
|
+
* Adapter configuration
|
|
710
|
+
*/
|
|
711
|
+
readonly config: R2BackupConfig;
|
|
712
|
+
/**
|
|
713
|
+
* Create a backup
|
|
714
|
+
*
|
|
715
|
+
* @param data - Data to backup
|
|
716
|
+
* @param options - Backup options
|
|
717
|
+
* @returns Result with backup information
|
|
718
|
+
*/
|
|
719
|
+
backup(data: ArrayBuffer | Buffer, options?: BackupOptions): Promise<Result<BackupInfo, R2BackupError>>;
|
|
720
|
+
/**
|
|
721
|
+
* Restore from a backup
|
|
722
|
+
*
|
|
723
|
+
* @param key - Backup key
|
|
724
|
+
* @param options - Restore options
|
|
725
|
+
* @returns Result with restored data
|
|
726
|
+
*/
|
|
727
|
+
restore(key: string, options?: RestoreOptions): Promise<Result<ArrayBuffer, R2BackupError>>;
|
|
728
|
+
/**
|
|
729
|
+
* List all backups
|
|
730
|
+
*
|
|
731
|
+
* @param options - List options
|
|
732
|
+
* @returns Result with array of backup information
|
|
733
|
+
*/
|
|
734
|
+
listBackups(options?: {
|
|
735
|
+
limit?: number;
|
|
736
|
+
cursor?: string;
|
|
737
|
+
}): Promise<Result<BackupInfo[], R2BackupError>>;
|
|
738
|
+
/**
|
|
739
|
+
* Delete a backup
|
|
740
|
+
*
|
|
741
|
+
* @param key - Backup key to delete
|
|
742
|
+
* @returns Result with void or error
|
|
743
|
+
*/
|
|
744
|
+
deleteBackup(key: string): Promise<Result<void, R2BackupError>>;
|
|
745
|
+
/**
|
|
746
|
+
* Delete multiple backups
|
|
747
|
+
*
|
|
748
|
+
* @param keys - Backup keys to delete
|
|
749
|
+
* @returns Result with void or error
|
|
750
|
+
*/
|
|
751
|
+
deleteMultipleBackups(keys: string[]): Promise<Result<void, R2BackupError>>;
|
|
752
|
+
}
|
|
753
|
+
//# sourceMappingURL=cloudforge.d.ts.map
|