@openworkers/workers-types 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 +42 -0
- package/index.d.ts +14 -0
- package/package.json +29 -0
- package/types/abort.d.ts +12 -0
- package/types/bindings.d.ts +52 -0
- package/types/blob.d.ts +36 -0
- package/types/console.d.ts +15 -0
- package/types/crypto.d.ts +78 -0
- package/types/encoding.d.ts +21 -0
- package/types/events.d.ts +48 -0
- package/types/fetch.d.ts +79 -0
- package/types/streams.d.ts +67 -0
- package/types/timers.d.ts +17 -0
- package/types/url.d.ts +40 -0
- package/types/workers.d.ts +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# @openworkers/workers-types
|
|
2
|
+
|
|
3
|
+
TypeScript types for the OpenWorkers runtime.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
bun add -d @openworkers/workers-types
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Add to your `tsconfig.json`:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"compilerOptions": {
|
|
18
|
+
"types": ["@openworkers/workers-types"]
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Or use a triple-slash directive:
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
/// <reference types="@openworkers/workers-types" />
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Structure
|
|
30
|
+
|
|
31
|
+
- `types/fetch.d.ts` - Request, Response, Headers, fetch
|
|
32
|
+
- `types/url.d.ts` - URL, URLSearchParams
|
|
33
|
+
- `types/streams.d.ts` - ReadableStream, WritableStream
|
|
34
|
+
- `types/crypto.d.ts` - Web Crypto API
|
|
35
|
+
- `types/encoding.d.ts` - TextEncoder, TextDecoder, atob, btoa
|
|
36
|
+
- `types/console.d.ts` - Console API
|
|
37
|
+
- `types/timers.d.ts` - setTimeout, setInterval
|
|
38
|
+
- `types/events.d.ts` - Event, EventTarget
|
|
39
|
+
- `types/abort.d.ts` - AbortController, AbortSignal
|
|
40
|
+
- `types/blob.d.ts` - Blob, File, FormData
|
|
41
|
+
- `types/workers.d.ts` - ExecutionContext, ScheduledEvent, ExportedHandler
|
|
42
|
+
- `types/bindings.d.ts` - BindingAssets, BindingStorage, BindingKV, BindingDatabase, BindingWorker
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// OpenWorkers Runtime Types
|
|
2
|
+
|
|
3
|
+
/// <reference path="./types/events.d.ts" />
|
|
4
|
+
/// <reference path="./types/abort.d.ts" />
|
|
5
|
+
/// <reference path="./types/streams.d.ts" />
|
|
6
|
+
/// <reference path="./types/blob.d.ts" />
|
|
7
|
+
/// <reference path="./types/url.d.ts" />
|
|
8
|
+
/// <reference path="./types/fetch.d.ts" />
|
|
9
|
+
/// <reference path="./types/encoding.d.ts" />
|
|
10
|
+
/// <reference path="./types/crypto.d.ts" />
|
|
11
|
+
/// <reference path="./types/console.d.ts" />
|
|
12
|
+
/// <reference path="./types/timers.d.ts" />
|
|
13
|
+
/// <reference path="./types/workers.d.ts" />
|
|
14
|
+
/// <reference path="./types/bindings.d.ts" />
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@openworkers/workers-types",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "TypeScript types for the OpenWorkers runtime",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/openworkers/workers-types"
|
|
9
|
+
},
|
|
10
|
+
"keywords": [
|
|
11
|
+
"openworkers",
|
|
12
|
+
"workers",
|
|
13
|
+
"typescript",
|
|
14
|
+
"types"
|
|
15
|
+
],
|
|
16
|
+
"types": "index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"index.d.ts",
|
|
19
|
+
"types/*.d.ts"
|
|
20
|
+
],
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"typescript": "^5"
|
|
23
|
+
},
|
|
24
|
+
"publishConfig": {
|
|
25
|
+
"access": "public",
|
|
26
|
+
"registry": "https://registry.npmjs.org/",
|
|
27
|
+
"provenance": true
|
|
28
|
+
}
|
|
29
|
+
}
|
package/types/abort.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// AbortController API types
|
|
2
|
+
|
|
3
|
+
interface AbortSignal extends EventTarget {
|
|
4
|
+
readonly aborted: boolean;
|
|
5
|
+
readonly reason: unknown;
|
|
6
|
+
throwIfAborted(): void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare class AbortController {
|
|
10
|
+
readonly signal: AbortSignal;
|
|
11
|
+
abort(reason?: unknown): void;
|
|
12
|
+
}
|
|
@@ -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
|
+
}
|
package/types/blob.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Blob & FormData API types
|
|
2
|
+
|
|
3
|
+
declare class Blob {
|
|
4
|
+
constructor(
|
|
5
|
+
blobParts?: (ArrayBuffer | Uint8Array | Blob | string)[],
|
|
6
|
+
options?: { type?: string }
|
|
7
|
+
);
|
|
8
|
+
readonly size: number;
|
|
9
|
+
readonly type: string;
|
|
10
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
11
|
+
slice(start?: number, end?: number, contentType?: string): Blob;
|
|
12
|
+
stream(): ReadableStream<Uint8Array>;
|
|
13
|
+
text(): Promise<string>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface File extends Blob {
|
|
17
|
+
readonly lastModified: number;
|
|
18
|
+
readonly name: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare class FormData {
|
|
22
|
+
constructor();
|
|
23
|
+
append(name: string, value: string | Blob, filename?: string): void;
|
|
24
|
+
delete(name: string): void;
|
|
25
|
+
get(name: string): string | File | null;
|
|
26
|
+
getAll(name: string): (string | File)[];
|
|
27
|
+
has(name: string): boolean;
|
|
28
|
+
set(name: string, value: string | Blob, filename?: string): void;
|
|
29
|
+
forEach(
|
|
30
|
+
callback: (value: string | File, key: string, parent: FormData) => void
|
|
31
|
+
): void;
|
|
32
|
+
entries(): IterableIterator<[string, string | File]>;
|
|
33
|
+
keys(): IterableIterator<string>;
|
|
34
|
+
values(): IterableIterator<string | File>;
|
|
35
|
+
[Symbol.iterator](): IterableIterator<[string, string | File]>;
|
|
36
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Console API types
|
|
2
|
+
|
|
3
|
+
interface Console {
|
|
4
|
+
log(...args: unknown[]): void;
|
|
5
|
+
info(...args: unknown[]): void;
|
|
6
|
+
warn(...args: unknown[]): void;
|
|
7
|
+
error(...args: unknown[]): void;
|
|
8
|
+
debug(...args: unknown[]): void;
|
|
9
|
+
trace(...args: unknown[]): void;
|
|
10
|
+
time(label?: string): void;
|
|
11
|
+
timeEnd(label?: string): void;
|
|
12
|
+
timeLog(label?: string, ...args: unknown[]): void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare var console: Console;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Web Crypto API types
|
|
2
|
+
|
|
3
|
+
interface SubtleCrypto {
|
|
4
|
+
digest(
|
|
5
|
+
algorithm: string | { name: string },
|
|
6
|
+
data: ArrayBuffer | Uint8Array
|
|
7
|
+
): Promise<ArrayBuffer>;
|
|
8
|
+
encrypt(
|
|
9
|
+
algorithm: unknown,
|
|
10
|
+
key: CryptoKey,
|
|
11
|
+
data: ArrayBuffer | Uint8Array
|
|
12
|
+
): Promise<ArrayBuffer>;
|
|
13
|
+
decrypt(
|
|
14
|
+
algorithm: unknown,
|
|
15
|
+
key: CryptoKey,
|
|
16
|
+
data: ArrayBuffer | Uint8Array
|
|
17
|
+
): Promise<ArrayBuffer>;
|
|
18
|
+
sign(
|
|
19
|
+
algorithm: unknown,
|
|
20
|
+
key: CryptoKey,
|
|
21
|
+
data: ArrayBuffer | Uint8Array
|
|
22
|
+
): Promise<ArrayBuffer>;
|
|
23
|
+
verify(
|
|
24
|
+
algorithm: unknown,
|
|
25
|
+
key: CryptoKey,
|
|
26
|
+
signature: ArrayBuffer | Uint8Array,
|
|
27
|
+
data: ArrayBuffer | Uint8Array
|
|
28
|
+
): Promise<boolean>;
|
|
29
|
+
generateKey(
|
|
30
|
+
algorithm: unknown,
|
|
31
|
+
extractable: boolean,
|
|
32
|
+
keyUsages: string[]
|
|
33
|
+
): Promise<CryptoKey | CryptoKeyPair>;
|
|
34
|
+
importKey(
|
|
35
|
+
format: string,
|
|
36
|
+
keyData: unknown,
|
|
37
|
+
algorithm: unknown,
|
|
38
|
+
extractable: boolean,
|
|
39
|
+
keyUsages: string[]
|
|
40
|
+
): Promise<CryptoKey>;
|
|
41
|
+
exportKey(format: string, key: CryptoKey): Promise<ArrayBuffer | JsonWebKey>;
|
|
42
|
+
deriveBits(
|
|
43
|
+
algorithm: unknown,
|
|
44
|
+
baseKey: CryptoKey,
|
|
45
|
+
length: number
|
|
46
|
+
): Promise<ArrayBuffer>;
|
|
47
|
+
deriveKey(
|
|
48
|
+
algorithm: unknown,
|
|
49
|
+
baseKey: CryptoKey,
|
|
50
|
+
derivedKeyType: unknown,
|
|
51
|
+
extractable: boolean,
|
|
52
|
+
keyUsages: string[]
|
|
53
|
+
): Promise<CryptoKey>;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface CryptoKey {
|
|
57
|
+
readonly algorithm: unknown;
|
|
58
|
+
readonly extractable: boolean;
|
|
59
|
+
readonly type: string;
|
|
60
|
+
readonly usages: string[];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
interface CryptoKeyPair {
|
|
64
|
+
readonly privateKey: CryptoKey;
|
|
65
|
+
readonly publicKey: CryptoKey;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface JsonWebKey {
|
|
69
|
+
[key: string]: unknown;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface Crypto {
|
|
73
|
+
readonly subtle: SubtleCrypto;
|
|
74
|
+
getRandomValues<T extends ArrayBufferView>(array: T): T;
|
|
75
|
+
randomUUID(): string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
declare var crypto: Crypto;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Encoding API types
|
|
2
|
+
|
|
3
|
+
declare class TextEncoder {
|
|
4
|
+
readonly encoding: string;
|
|
5
|
+
encode(input?: string): Uint8Array;
|
|
6
|
+
encodeInto(
|
|
7
|
+
source: string,
|
|
8
|
+
destination: Uint8Array
|
|
9
|
+
): { read: number; written: number };
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare class TextDecoder {
|
|
13
|
+
constructor(label?: string, options?: { fatal?: boolean; ignoreBOM?: boolean });
|
|
14
|
+
readonly encoding: string;
|
|
15
|
+
readonly fatal: boolean;
|
|
16
|
+
readonly ignoreBOM: boolean;
|
|
17
|
+
decode(input?: ArrayBuffer | Uint8Array, options?: { stream?: boolean }): string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare function atob(data: string): string;
|
|
21
|
+
declare function btoa(data: string): string;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// Event API types
|
|
2
|
+
|
|
3
|
+
interface EventTarget {
|
|
4
|
+
addEventListener(
|
|
5
|
+
type: string,
|
|
6
|
+
listener: EventListenerOrEventListenerObject | null,
|
|
7
|
+
options?: boolean | AddEventListenerOptions
|
|
8
|
+
): void;
|
|
9
|
+
removeEventListener(
|
|
10
|
+
type: string,
|
|
11
|
+
listener: EventListenerOrEventListenerObject | null,
|
|
12
|
+
options?: boolean | EventListenerOptions
|
|
13
|
+
): void;
|
|
14
|
+
dispatchEvent(event: Event): boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface Event {
|
|
18
|
+
readonly type: string;
|
|
19
|
+
readonly target: EventTarget | null;
|
|
20
|
+
readonly currentTarget: EventTarget | null;
|
|
21
|
+
readonly bubbles: boolean;
|
|
22
|
+
readonly cancelable: boolean;
|
|
23
|
+
readonly defaultPrevented: boolean;
|
|
24
|
+
readonly timeStamp: number;
|
|
25
|
+
preventDefault(): void;
|
|
26
|
+
stopPropagation(): void;
|
|
27
|
+
stopImmediatePropagation(): void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
interface EventListenerOptions {
|
|
31
|
+
capture?: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface AddEventListenerOptions extends EventListenerOptions {
|
|
35
|
+
once?: boolean;
|
|
36
|
+
passive?: boolean;
|
|
37
|
+
signal?: AbortSignal;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface EventListener {
|
|
41
|
+
(evt: Event): void;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface EventListenerObject {
|
|
45
|
+
handleEvent(object: Event): void;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type EventListenerOrEventListenerObject = EventListener | EventListenerObject;
|
package/types/fetch.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Fetch API types
|
|
2
|
+
|
|
3
|
+
type BodyInit =
|
|
4
|
+
| ReadableStream
|
|
5
|
+
| Blob
|
|
6
|
+
| ArrayBuffer
|
|
7
|
+
| Uint8Array
|
|
8
|
+
| FormData
|
|
9
|
+
| URLSearchParams
|
|
10
|
+
| string;
|
|
11
|
+
|
|
12
|
+
type HeadersInit = Headers | Record<string, string> | [string, string][];
|
|
13
|
+
|
|
14
|
+
declare class Headers {
|
|
15
|
+
constructor(init?: HeadersInit);
|
|
16
|
+
append(name: string, value: string): void;
|
|
17
|
+
delete(name: string): void;
|
|
18
|
+
get(name: string): string | null;
|
|
19
|
+
has(name: string): boolean;
|
|
20
|
+
set(name: string, value: string): void;
|
|
21
|
+
forEach(callback: (value: string, key: string, parent: Headers) => void): void;
|
|
22
|
+
entries(): IterableIterator<[string, string]>;
|
|
23
|
+
keys(): IterableIterator<string>;
|
|
24
|
+
values(): IterableIterator<string>;
|
|
25
|
+
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface RequestInit {
|
|
29
|
+
method?: string;
|
|
30
|
+
headers?: HeadersInit;
|
|
31
|
+
body?: BodyInit | null;
|
|
32
|
+
redirect?: "follow" | "error" | "manual";
|
|
33
|
+
signal?: AbortSignal;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
declare class Request {
|
|
37
|
+
constructor(input: Request | string | URL, init?: RequestInit);
|
|
38
|
+
readonly method: string;
|
|
39
|
+
readonly url: string;
|
|
40
|
+
readonly headers: Headers;
|
|
41
|
+
readonly body: ReadableStream<Uint8Array> | null;
|
|
42
|
+
readonly bodyUsed: boolean;
|
|
43
|
+
clone(): Request;
|
|
44
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
45
|
+
blob(): Promise<Blob>;
|
|
46
|
+
formData(): Promise<FormData>;
|
|
47
|
+
json(): Promise<unknown>;
|
|
48
|
+
text(): Promise<string>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface ResponseInit {
|
|
52
|
+
status?: number;
|
|
53
|
+
statusText?: string;
|
|
54
|
+
headers?: HeadersInit;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
declare class Response {
|
|
58
|
+
constructor(body?: BodyInit | null, init?: ResponseInit);
|
|
59
|
+
static json(data: unknown, init?: ResponseInit): Response;
|
|
60
|
+
static redirect(url: string | URL, status?: number): Response;
|
|
61
|
+
static error(): Response;
|
|
62
|
+
readonly ok: boolean;
|
|
63
|
+
readonly status: number;
|
|
64
|
+
readonly statusText: string;
|
|
65
|
+
readonly headers: Headers;
|
|
66
|
+
readonly body: ReadableStream<Uint8Array> | null;
|
|
67
|
+
readonly bodyUsed: boolean;
|
|
68
|
+
clone(): Response;
|
|
69
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
70
|
+
blob(): Promise<Blob>;
|
|
71
|
+
formData(): Promise<FormData>;
|
|
72
|
+
json(): Promise<unknown>;
|
|
73
|
+
text(): Promise<string>;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
declare function fetch(
|
|
77
|
+
input: Request | string | URL,
|
|
78
|
+
init?: RequestInit
|
|
79
|
+
): Promise<Response>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Streams API types
|
|
2
|
+
|
|
3
|
+
interface ReadableStreamDefaultReader<R = unknown> {
|
|
4
|
+
readonly closed: Promise<undefined>;
|
|
5
|
+
cancel(reason?: unknown): Promise<void>;
|
|
6
|
+
read(): Promise<{ done: false; value: R } | { done: true; value?: undefined }>;
|
|
7
|
+
releaseLock(): void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface ReadableStream<R = unknown> {
|
|
11
|
+
readonly locked: boolean;
|
|
12
|
+
cancel(reason?: unknown): Promise<void>;
|
|
13
|
+
getReader(): ReadableStreamDefaultReader<R>;
|
|
14
|
+
pipeThrough<T>(transform: {
|
|
15
|
+
writable: WritableStream<R>;
|
|
16
|
+
readable: ReadableStream<T>;
|
|
17
|
+
}): ReadableStream<T>;
|
|
18
|
+
pipeTo(dest: WritableStream<R>): Promise<void>;
|
|
19
|
+
tee(): [ReadableStream<R>, ReadableStream<R>];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface ReadableStreamDefaultController<R = unknown> {
|
|
23
|
+
readonly desiredSize: number | null;
|
|
24
|
+
close(): void;
|
|
25
|
+
enqueue(chunk: R): void;
|
|
26
|
+
error(e?: unknown): void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare var ReadableStream: {
|
|
30
|
+
prototype: ReadableStream;
|
|
31
|
+
new <R = unknown>(source?: {
|
|
32
|
+
start?(controller: ReadableStreamDefaultController<R>): void | Promise<void>;
|
|
33
|
+
pull?(controller: ReadableStreamDefaultController<R>): void | Promise<void>;
|
|
34
|
+
cancel?(reason?: unknown): void | Promise<void>;
|
|
35
|
+
}): ReadableStream<R>;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
interface WritableStreamDefaultWriter<W = unknown> {
|
|
39
|
+
readonly closed: Promise<undefined>;
|
|
40
|
+
readonly desiredSize: number | null;
|
|
41
|
+
readonly ready: Promise<undefined>;
|
|
42
|
+
abort(reason?: unknown): Promise<void>;
|
|
43
|
+
close(): Promise<void>;
|
|
44
|
+
releaseLock(): void;
|
|
45
|
+
write(chunk: W): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
interface WritableStream<W = unknown> {
|
|
49
|
+
readonly locked: boolean;
|
|
50
|
+
abort(reason?: unknown): Promise<void>;
|
|
51
|
+
close(): Promise<void>;
|
|
52
|
+
getWriter(): WritableStreamDefaultWriter<W>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface WritableStreamDefaultController {
|
|
56
|
+
error(e?: unknown): void;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
declare var WritableStream: {
|
|
60
|
+
prototype: WritableStream;
|
|
61
|
+
new <W = unknown>(sink?: {
|
|
62
|
+
start?(controller: WritableStreamDefaultController): void | Promise<void>;
|
|
63
|
+
write?(chunk: W, controller: WritableStreamDefaultController): void | Promise<void>;
|
|
64
|
+
close?(controller: WritableStreamDefaultController): void | Promise<void>;
|
|
65
|
+
abort?(reason?: unknown): void | Promise<void>;
|
|
66
|
+
}): WritableStream<W>;
|
|
67
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Timer API types
|
|
2
|
+
|
|
3
|
+
declare function setTimeout(
|
|
4
|
+
callback: (...args: unknown[]) => void,
|
|
5
|
+
ms?: number,
|
|
6
|
+
...args: unknown[]
|
|
7
|
+
): number;
|
|
8
|
+
|
|
9
|
+
declare function clearTimeout(id: number): void;
|
|
10
|
+
|
|
11
|
+
declare function setInterval(
|
|
12
|
+
callback: (...args: unknown[]) => void,
|
|
13
|
+
ms?: number,
|
|
14
|
+
...args: unknown[]
|
|
15
|
+
): number;
|
|
16
|
+
|
|
17
|
+
declare function clearInterval(id: number): void;
|
package/types/url.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// URL API types
|
|
2
|
+
|
|
3
|
+
declare class URL {
|
|
4
|
+
constructor(url: string | URL, base?: string | URL);
|
|
5
|
+
hash: string;
|
|
6
|
+
host: string;
|
|
7
|
+
hostname: string;
|
|
8
|
+
href: string;
|
|
9
|
+
readonly origin: string;
|
|
10
|
+
password: string;
|
|
11
|
+
pathname: string;
|
|
12
|
+
port: string;
|
|
13
|
+
protocol: string;
|
|
14
|
+
search: string;
|
|
15
|
+
readonly searchParams: URLSearchParams;
|
|
16
|
+
username: string;
|
|
17
|
+
toString(): string;
|
|
18
|
+
toJSON(): string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare class URLSearchParams {
|
|
22
|
+
constructor(
|
|
23
|
+
init?: string | URLSearchParams | Record<string, string> | [string, string][]
|
|
24
|
+
);
|
|
25
|
+
append(name: string, value: string): void;
|
|
26
|
+
delete(name: string): void;
|
|
27
|
+
get(name: string): string | null;
|
|
28
|
+
getAll(name: string): string[];
|
|
29
|
+
has(name: string): boolean;
|
|
30
|
+
set(name: string, value: string): void;
|
|
31
|
+
sort(): void;
|
|
32
|
+
toString(): string;
|
|
33
|
+
forEach(
|
|
34
|
+
callback: (value: string, key: string, parent: URLSearchParams) => void
|
|
35
|
+
): void;
|
|
36
|
+
entries(): IterableIterator<[string, string]>;
|
|
37
|
+
keys(): IterableIterator<string>;
|
|
38
|
+
values(): IterableIterator<string>;
|
|
39
|
+
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// OpenWorkers-specific types
|
|
2
|
+
|
|
3
|
+
interface ScheduledEvent {
|
|
4
|
+
scheduledTime: number;
|
|
5
|
+
cron?: string;
|
|
6
|
+
waitUntil(promise: Promise<unknown>): void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface ExecutionContext {
|
|
10
|
+
waitUntil(promise: Promise<unknown>): void;
|
|
11
|
+
passThroughOnException(): void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface ExportedHandler<Env = unknown> {
|
|
15
|
+
fetch?(
|
|
16
|
+
request: Request,
|
|
17
|
+
env: Env,
|
|
18
|
+
ctx: ExecutionContext
|
|
19
|
+
): Response | Promise<Response>;
|
|
20
|
+
scheduled?(
|
|
21
|
+
event: ScheduledEvent,
|
|
22
|
+
env: Env,
|
|
23
|
+
ctx: ExecutionContext
|
|
24
|
+
): void | Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// addEventListener pattern
|
|
28
|
+
|
|
29
|
+
interface FetchEvent extends Event {
|
|
30
|
+
readonly request: Request;
|
|
31
|
+
respondWith(response: Response | Promise<Response>): void;
|
|
32
|
+
waitUntil(promise: Promise<unknown>): void;
|
|
33
|
+
passThroughOnException(): void;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
interface ScheduledEventListener {
|
|
37
|
+
(event: ScheduledEvent & { waitUntil(promise: Promise<unknown>): void }): void;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
declare function addEventListener(
|
|
41
|
+
type: "fetch",
|
|
42
|
+
listener: (event: FetchEvent) => void
|
|
43
|
+
): void;
|
|
44
|
+
|
|
45
|
+
declare function addEventListener(
|
|
46
|
+
type: "scheduled",
|
|
47
|
+
listener: ScheduledEventListener
|
|
48
|
+
): void;
|