Skip to content

Commit 6c45acc

Browse files
committed
Add bindings types
1 parent 1eb690b commit 6c45acc

4 files changed

Lines changed: 55 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ Or use a triple-slash directive:
3939
- `types/abort.d.ts` - AbortController, AbortSignal
4040
- `types/blob.d.ts` - Blob, File, FormData
4141
- `types/workers.d.ts` - ExecutionContext, ScheduledEvent, ExportedHandler
42+
- `types/bindings.d.ts` - BindingAssets, BindingStorage, BindingKV, BindingDatabase, BindingWorker

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
/// <reference path="./types/console.d.ts" />
1212
/// <reference path="./types/timers.d.ts" />
1313
/// <reference path="./types/workers.d.ts" />
14+
/// <reference path="./types/bindings.d.ts" />

types/bindings.d.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// OpenWorkers Bindings types
2+
3+
interface BindingAssets {
4+
fetch(path: string, options?: RequestInit): Promise<Response>;
5+
}
6+
7+
interface StorageHeadResult {
8+
size: number;
9+
etag?: string;
10+
}
11+
12+
interface StorageListOptions {
13+
prefix?: string;
14+
limit?: number;
15+
}
16+
17+
interface StorageListResult {
18+
keys: string[];
19+
truncated: boolean;
20+
}
21+
22+
interface BindingStorage {
23+
get(key: string): Promise<string | null>;
24+
put(key: string, value: string | Uint8Array): Promise<void>;
25+
head(key: string): Promise<StorageHeadResult>;
26+
list(options?: StorageListOptions): Promise<StorageListResult>;
27+
delete(key: string): Promise<void>;
28+
}
29+
30+
interface KVPutOptions {
31+
expiresIn?: number;
32+
}
33+
34+
interface KVListOptions {
35+
prefix?: string;
36+
limit?: number;
37+
}
38+
39+
interface BindingKV {
40+
get(key: string): Promise<string | null>;
41+
put(key: string, value: string, options?: KVPutOptions): Promise<void>;
42+
delete(key: string): Promise<void>;
43+
list(options?: KVListOptions): Promise<string[]>;
44+
}
45+
46+
interface BindingDatabase {
47+
query<T = Record<string, unknown>>(sql: string, params?: unknown[]): Promise<T[]>;
48+
}
49+
50+
interface BindingWorker {
51+
fetch(request: Request | string, init?: RequestInit): Promise<Response>;
52+
}

types/workers.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
interface ScheduledEvent {
44
scheduledTime: number;
55
cron?: string;
6+
waitUntil(promise: Promise<unknown>): void;
67
}
78

89
interface ExecutionContext {

0 commit comments

Comments
 (0)