@plitzi/sdk-runtime 0.0.0-stage → 0.39.3
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 +18 -0
- package/README.md +84 -2
- package/dist/chunks/service-DDDJomiH.mjs +2322 -0
- package/dist/contract/runtime.d.ts +3 -0
- package/dist/functions-api.d.ts +724 -0
- package/dist/host/host.d.ts +42 -0
- package/dist/host/index.d.ts +3 -0
- package/dist/host/index.mjs +107 -0
- package/dist/host/runner.d.ts +11 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.mjs +5 -0
- package/dist/prelude.js +1 -0
- package/dist/runner/cpuMeter.d.ts +35 -0
- package/dist/runner/driver.d.ts +37 -0
- package/dist/runner/guest/bytes.d.ts +27 -0
- package/dist/runner/guest/crypto.d.ts +47 -0
- package/dist/runner/guest/events.d.ts +152 -0
- package/dist/runner/guest/fetch.d.ts +305 -0
- package/dist/runner/guest/install.d.ts +23 -0
- package/dist/runner/guest/types.d.ts +38 -0
- package/dist/runner/index.d.ts +6 -0
- package/dist/runner/index.mjs +1 -0
- package/dist/runner/isolate.d.ts +65 -0
- package/dist/runner/memoryGuard.d.ts +25 -0
- package/dist/runner/prelude.d.ts +10 -0
- package/dist/runner/service.d.ts +76 -0
- package/dist/runner/turns.d.ts +12 -0
- package/package.json +64 -3
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { GuestHost } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Events, abort and timers: `Event`, `EventTarget`, `AbortSignal`, `AbortController` and the timers, on the runner's clock.
|
|
4
|
+
*
|
|
5
|
+
* Printed into the isolate on its own, as the guest is (`isolate.ts`): it may use nothing but its parameters.
|
|
6
|
+
*/
|
|
7
|
+
export declare const guestEvents: (host: Pick<GuestHost, "sleep">) => {
|
|
8
|
+
GuestEvent: {
|
|
9
|
+
new (type: string): {
|
|
10
|
+
readonly type: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
GuestEventTarget: {
|
|
14
|
+
new (): {
|
|
15
|
+
addEventListener(type: string, listener: ((event: {
|
|
16
|
+
readonly type: string;
|
|
17
|
+
}) => void) | null, options?: boolean | {
|
|
18
|
+
once?: boolean;
|
|
19
|
+
}): void;
|
|
20
|
+
removeEventListener(type: string, listener: ((event: {
|
|
21
|
+
readonly type: string;
|
|
22
|
+
}) => void) | null): void;
|
|
23
|
+
dispatchEvent(event: {
|
|
24
|
+
readonly type: string;
|
|
25
|
+
}): boolean;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
GuestAbortSignal: {
|
|
29
|
+
new (token?: symbol): {
|
|
30
|
+
onabort: ((event: {
|
|
31
|
+
readonly type: string;
|
|
32
|
+
}) => void) | null;
|
|
33
|
+
get aborted(): boolean;
|
|
34
|
+
get reason(): unknown;
|
|
35
|
+
throwIfAborted(): void;
|
|
36
|
+
addEventListener(type: string, listener: ((event: {
|
|
37
|
+
readonly type: string;
|
|
38
|
+
}) => void) | null, options?: boolean | {
|
|
39
|
+
once?: boolean;
|
|
40
|
+
}): void;
|
|
41
|
+
removeEventListener(type: string, listener: ((event: {
|
|
42
|
+
readonly type: string;
|
|
43
|
+
}) => void) | null): void;
|
|
44
|
+
dispatchEvent(event: {
|
|
45
|
+
readonly type: string;
|
|
46
|
+
}): boolean;
|
|
47
|
+
};
|
|
48
|
+
abort(reason?: unknown): {
|
|
49
|
+
onabort: ((event: {
|
|
50
|
+
readonly type: string;
|
|
51
|
+
}) => void) | null;
|
|
52
|
+
get aborted(): boolean;
|
|
53
|
+
get reason(): unknown;
|
|
54
|
+
throwIfAborted(): void;
|
|
55
|
+
addEventListener(type: string, listener: ((event: {
|
|
56
|
+
readonly type: string;
|
|
57
|
+
}) => void) | null, options?: boolean | {
|
|
58
|
+
once?: boolean;
|
|
59
|
+
}): void;
|
|
60
|
+
removeEventListener(type: string, listener: ((event: {
|
|
61
|
+
readonly type: string;
|
|
62
|
+
}) => void) | null): void;
|
|
63
|
+
dispatchEvent(event: {
|
|
64
|
+
readonly type: string;
|
|
65
|
+
}): boolean;
|
|
66
|
+
};
|
|
67
|
+
timeout(ms: number): {
|
|
68
|
+
onabort: ((event: {
|
|
69
|
+
readonly type: string;
|
|
70
|
+
}) => void) | null;
|
|
71
|
+
get aborted(): boolean;
|
|
72
|
+
get reason(): unknown;
|
|
73
|
+
throwIfAborted(): void;
|
|
74
|
+
addEventListener(type: string, listener: ((event: {
|
|
75
|
+
readonly type: string;
|
|
76
|
+
}) => void) | null, options?: boolean | {
|
|
77
|
+
once?: boolean;
|
|
78
|
+
}): void;
|
|
79
|
+
removeEventListener(type: string, listener: ((event: {
|
|
80
|
+
readonly type: string;
|
|
81
|
+
}) => void) | null): void;
|
|
82
|
+
dispatchEvent(event: {
|
|
83
|
+
readonly type: string;
|
|
84
|
+
}): boolean;
|
|
85
|
+
};
|
|
86
|
+
any(sources: {
|
|
87
|
+
onabort: ((event: {
|
|
88
|
+
readonly type: string;
|
|
89
|
+
}) => void) | null;
|
|
90
|
+
get aborted(): boolean;
|
|
91
|
+
get reason(): unknown;
|
|
92
|
+
throwIfAborted(): void;
|
|
93
|
+
addEventListener(type: string, listener: ((event: {
|
|
94
|
+
readonly type: string;
|
|
95
|
+
}) => void) | null, options?: boolean | {
|
|
96
|
+
once?: boolean;
|
|
97
|
+
}): void;
|
|
98
|
+
removeEventListener(type: string, listener: ((event: {
|
|
99
|
+
readonly type: string;
|
|
100
|
+
}) => void) | null): void;
|
|
101
|
+
dispatchEvent(event: {
|
|
102
|
+
readonly type: string;
|
|
103
|
+
}): boolean;
|
|
104
|
+
}[]): {
|
|
105
|
+
onabort: ((event: {
|
|
106
|
+
readonly type: string;
|
|
107
|
+
}) => void) | null;
|
|
108
|
+
get aborted(): boolean;
|
|
109
|
+
get reason(): unknown;
|
|
110
|
+
throwIfAborted(): void;
|
|
111
|
+
addEventListener(type: string, listener: ((event: {
|
|
112
|
+
readonly type: string;
|
|
113
|
+
}) => void) | null, options?: boolean | {
|
|
114
|
+
once?: boolean;
|
|
115
|
+
}): void;
|
|
116
|
+
removeEventListener(type: string, listener: ((event: {
|
|
117
|
+
readonly type: string;
|
|
118
|
+
}) => void) | null): void;
|
|
119
|
+
dispatchEvent(event: {
|
|
120
|
+
readonly type: string;
|
|
121
|
+
}): boolean;
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
GuestAbortController: {
|
|
125
|
+
new (): {
|
|
126
|
+
readonly signal: {
|
|
127
|
+
onabort: ((event: {
|
|
128
|
+
readonly type: string;
|
|
129
|
+
}) => void) | null;
|
|
130
|
+
get aborted(): boolean;
|
|
131
|
+
get reason(): unknown;
|
|
132
|
+
throwIfAborted(): void;
|
|
133
|
+
addEventListener(type: string, listener: ((event: {
|
|
134
|
+
readonly type: string;
|
|
135
|
+
}) => void) | null, options?: boolean | {
|
|
136
|
+
once?: boolean;
|
|
137
|
+
}): void;
|
|
138
|
+
removeEventListener(type: string, listener: ((event: {
|
|
139
|
+
readonly type: string;
|
|
140
|
+
}) => void) | null): void;
|
|
141
|
+
dispatchEvent(event: {
|
|
142
|
+
readonly type: string;
|
|
143
|
+
}): boolean;
|
|
144
|
+
};
|
|
145
|
+
abort(reason?: unknown): void;
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
guestSetTimeout: (callback: (...args: unknown[]) => void, ms?: number, ...args: unknown[]) => number;
|
|
149
|
+
guestSetInterval: (callback: (...args: unknown[]) => void, ms?: number, ...args: unknown[]) => number;
|
|
150
|
+
clearTimer: (id?: number) => void;
|
|
151
|
+
};
|
|
152
|
+
export type GuestEvents = ReturnType<typeof guestEvents>;
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import { GuestBytes } from './bytes';
|
|
2
|
+
import { GuestEvents } from './events';
|
|
3
|
+
import { Bytes } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Headers, bodies, requests and responses — and how a body crosses to the runner and back.
|
|
6
|
+
*
|
|
7
|
+
* Printed into the isolate on its own, as the guest is (`isolate.ts`): it may use nothing but its parameters.
|
|
8
|
+
*/
|
|
9
|
+
export declare const guestFetch: ({ isRecord, encodeUtf8, decodeUtf8, bytesToBase64, base64ToBytes, copyBytes }: GuestBytes, { GuestAbortController }: GuestEvents) => {
|
|
10
|
+
GuestHeaders: {
|
|
11
|
+
new (init?: Record<string, string> | [string, string][] | {
|
|
12
|
+
append(name: string, value: unknown): void;
|
|
13
|
+
set(name: string, value: unknown): void;
|
|
14
|
+
get(name: string): string | null;
|
|
15
|
+
getSetCookie(): string[];
|
|
16
|
+
has(name: string): boolean;
|
|
17
|
+
delete(name: string): void;
|
|
18
|
+
entries(): IterableIterator<[string, string]>;
|
|
19
|
+
keys(): IterableIterator<string>;
|
|
20
|
+
values(): IterableIterator<string>;
|
|
21
|
+
forEach(callback: (value: string, name: string, headers: /*elided*/ any) => void): void;
|
|
22
|
+
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
23
|
+
}): {
|
|
24
|
+
append(name: string, value: unknown): void;
|
|
25
|
+
set(name: string, value: unknown): void;
|
|
26
|
+
get(name: string): string | null;
|
|
27
|
+
getSetCookie(): string[];
|
|
28
|
+
has(name: string): boolean;
|
|
29
|
+
delete(name: string): void;
|
|
30
|
+
entries(): IterableIterator<[string, string]>;
|
|
31
|
+
keys(): IterableIterator<string>;
|
|
32
|
+
values(): IterableIterator<string>;
|
|
33
|
+
forEach(callback: (value: string, name: string, headers: /*elided*/ any) => void): void;
|
|
34
|
+
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
GuestRequest: {
|
|
38
|
+
new (input: string | URL | {
|
|
39
|
+
readonly url: string;
|
|
40
|
+
readonly method: string;
|
|
41
|
+
readonly signal: {
|
|
42
|
+
onabort: ((event: {
|
|
43
|
+
readonly type: string;
|
|
44
|
+
}) => void) | null;
|
|
45
|
+
get aborted(): boolean;
|
|
46
|
+
get reason(): unknown;
|
|
47
|
+
throwIfAborted(): void;
|
|
48
|
+
addEventListener(type: string, listener: ((event: {
|
|
49
|
+
readonly type: string;
|
|
50
|
+
}) => void) | null, options?: boolean | {
|
|
51
|
+
once?: boolean;
|
|
52
|
+
}): void;
|
|
53
|
+
removeEventListener(type: string, listener: ((event: {
|
|
54
|
+
readonly type: string;
|
|
55
|
+
}) => void) | null): void;
|
|
56
|
+
dispatchEvent(event: {
|
|
57
|
+
readonly type: string;
|
|
58
|
+
}): boolean;
|
|
59
|
+
};
|
|
60
|
+
clone(): /*elided*/ any;
|
|
61
|
+
readonly headers: {
|
|
62
|
+
append(name: string, value: unknown): void;
|
|
63
|
+
set(name: string, value: unknown): void;
|
|
64
|
+
get(name: string): string | null;
|
|
65
|
+
getSetCookie(): string[];
|
|
66
|
+
has(name: string): boolean;
|
|
67
|
+
delete(name: string): void;
|
|
68
|
+
entries(): IterableIterator<[string, string]>;
|
|
69
|
+
keys(): IterableIterator<string>;
|
|
70
|
+
values(): IterableIterator<string>;
|
|
71
|
+
forEach(callback: (value: string, name: string, headers: /*elided*/ any) => void): void;
|
|
72
|
+
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
73
|
+
};
|
|
74
|
+
get bodyUsed(): boolean;
|
|
75
|
+
get body(): null;
|
|
76
|
+
text(): Promise<string>;
|
|
77
|
+
json(): Promise<unknown>;
|
|
78
|
+
bytes(): Promise<Bytes>;
|
|
79
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
80
|
+
}, init?: {
|
|
81
|
+
method?: string;
|
|
82
|
+
headers?: Record<string, string> | [string, string][] | {
|
|
83
|
+
append(name: string, value: unknown): void;
|
|
84
|
+
set(name: string, value: unknown): void;
|
|
85
|
+
get(name: string): string | null;
|
|
86
|
+
getSetCookie(): string[];
|
|
87
|
+
has(name: string): boolean;
|
|
88
|
+
delete(name: string): void;
|
|
89
|
+
entries(): IterableIterator<[string, string]>;
|
|
90
|
+
keys(): IterableIterator<string>;
|
|
91
|
+
values(): IterableIterator<string>;
|
|
92
|
+
forEach(callback: (value: string, name: string, headers: /*elided*/ any) => void): void;
|
|
93
|
+
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
94
|
+
};
|
|
95
|
+
body?: unknown;
|
|
96
|
+
signal?: {
|
|
97
|
+
onabort: ((event: {
|
|
98
|
+
readonly type: string;
|
|
99
|
+
}) => void) | null;
|
|
100
|
+
get aborted(): boolean;
|
|
101
|
+
get reason(): unknown;
|
|
102
|
+
throwIfAborted(): void;
|
|
103
|
+
addEventListener(type: string, listener: ((event: {
|
|
104
|
+
readonly type: string;
|
|
105
|
+
}) => void) | null, options?: boolean | {
|
|
106
|
+
once?: boolean;
|
|
107
|
+
}): void;
|
|
108
|
+
removeEventListener(type: string, listener: ((event: {
|
|
109
|
+
readonly type: string;
|
|
110
|
+
}) => void) | null): void;
|
|
111
|
+
dispatchEvent(event: {
|
|
112
|
+
readonly type: string;
|
|
113
|
+
}): boolean;
|
|
114
|
+
} | null;
|
|
115
|
+
}): {
|
|
116
|
+
readonly url: string;
|
|
117
|
+
readonly method: string;
|
|
118
|
+
readonly signal: {
|
|
119
|
+
onabort: ((event: {
|
|
120
|
+
readonly type: string;
|
|
121
|
+
}) => void) | null;
|
|
122
|
+
get aborted(): boolean;
|
|
123
|
+
get reason(): unknown;
|
|
124
|
+
throwIfAborted(): void;
|
|
125
|
+
addEventListener(type: string, listener: ((event: {
|
|
126
|
+
readonly type: string;
|
|
127
|
+
}) => void) | null, options?: boolean | {
|
|
128
|
+
once?: boolean;
|
|
129
|
+
}): void;
|
|
130
|
+
removeEventListener(type: string, listener: ((event: {
|
|
131
|
+
readonly type: string;
|
|
132
|
+
}) => void) | null): void;
|
|
133
|
+
dispatchEvent(event: {
|
|
134
|
+
readonly type: string;
|
|
135
|
+
}): boolean;
|
|
136
|
+
};
|
|
137
|
+
clone(): /*elided*/ any;
|
|
138
|
+
readonly headers: {
|
|
139
|
+
append(name: string, value: unknown): void;
|
|
140
|
+
set(name: string, value: unknown): void;
|
|
141
|
+
get(name: string): string | null;
|
|
142
|
+
getSetCookie(): string[];
|
|
143
|
+
has(name: string): boolean;
|
|
144
|
+
delete(name: string): void;
|
|
145
|
+
entries(): IterableIterator<[string, string]>;
|
|
146
|
+
keys(): IterableIterator<string>;
|
|
147
|
+
values(): IterableIterator<string>;
|
|
148
|
+
forEach(callback: (value: string, name: string, headers: /*elided*/ any) => void): void;
|
|
149
|
+
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
150
|
+
};
|
|
151
|
+
get bodyUsed(): boolean;
|
|
152
|
+
get body(): null;
|
|
153
|
+
text(): Promise<string>;
|
|
154
|
+
json(): Promise<unknown>;
|
|
155
|
+
bytes(): Promise<Bytes>;
|
|
156
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
GuestResponse: {
|
|
160
|
+
new (body?: unknown, init?: {
|
|
161
|
+
status?: number;
|
|
162
|
+
statusText?: string;
|
|
163
|
+
headers?: Record<string, string> | [string, string][] | {
|
|
164
|
+
append(name: string, value: unknown): void;
|
|
165
|
+
set(name: string, value: unknown): void;
|
|
166
|
+
get(name: string): string | null;
|
|
167
|
+
getSetCookie(): string[];
|
|
168
|
+
has(name: string): boolean;
|
|
169
|
+
delete(name: string): void;
|
|
170
|
+
entries(): IterableIterator<[string, string]>;
|
|
171
|
+
keys(): IterableIterator<string>;
|
|
172
|
+
values(): IterableIterator<string>;
|
|
173
|
+
forEach(callback: (value: string, name: string, headers: /*elided*/ any) => void): void;
|
|
174
|
+
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
175
|
+
};
|
|
176
|
+
}): {
|
|
177
|
+
readonly status: number;
|
|
178
|
+
readonly statusText: string;
|
|
179
|
+
readonly type: "default";
|
|
180
|
+
readonly url: "";
|
|
181
|
+
readonly redirected: false;
|
|
182
|
+
get ok(): boolean;
|
|
183
|
+
clone(): /*elided*/ any;
|
|
184
|
+
readonly headers: {
|
|
185
|
+
append(name: string, value: unknown): void;
|
|
186
|
+
set(name: string, value: unknown): void;
|
|
187
|
+
get(name: string): string | null;
|
|
188
|
+
getSetCookie(): string[];
|
|
189
|
+
has(name: string): boolean;
|
|
190
|
+
delete(name: string): void;
|
|
191
|
+
entries(): IterableIterator<[string, string]>;
|
|
192
|
+
keys(): IterableIterator<string>;
|
|
193
|
+
values(): IterableIterator<string>;
|
|
194
|
+
forEach(callback: (value: string, name: string, headers: /*elided*/ any) => void): void;
|
|
195
|
+
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
196
|
+
};
|
|
197
|
+
get bodyUsed(): boolean;
|
|
198
|
+
get body(): null;
|
|
199
|
+
text(): Promise<string>;
|
|
200
|
+
json(): Promise<unknown>;
|
|
201
|
+
bytes(): Promise<Bytes>;
|
|
202
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
203
|
+
};
|
|
204
|
+
json(data: unknown, init?: {
|
|
205
|
+
status?: number;
|
|
206
|
+
statusText?: string;
|
|
207
|
+
headers?: Record<string, string> | [string, string][] | {
|
|
208
|
+
append(name: string, value: unknown): void;
|
|
209
|
+
set(name: string, value: unknown): void;
|
|
210
|
+
get(name: string): string | null;
|
|
211
|
+
getSetCookie(): string[];
|
|
212
|
+
has(name: string): boolean;
|
|
213
|
+
delete(name: string): void;
|
|
214
|
+
entries(): IterableIterator<[string, string]>;
|
|
215
|
+
keys(): IterableIterator<string>;
|
|
216
|
+
values(): IterableIterator<string>;
|
|
217
|
+
forEach(callback: (value: string, name: string, headers: /*elided*/ any) => void): void;
|
|
218
|
+
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
219
|
+
};
|
|
220
|
+
}): {
|
|
221
|
+
readonly status: number;
|
|
222
|
+
readonly statusText: string;
|
|
223
|
+
readonly type: "default";
|
|
224
|
+
readonly url: "";
|
|
225
|
+
readonly redirected: false;
|
|
226
|
+
get ok(): boolean;
|
|
227
|
+
clone(): /*elided*/ any;
|
|
228
|
+
readonly headers: {
|
|
229
|
+
append(name: string, value: unknown): void;
|
|
230
|
+
set(name: string, value: unknown): void;
|
|
231
|
+
get(name: string): string | null;
|
|
232
|
+
getSetCookie(): string[];
|
|
233
|
+
has(name: string): boolean;
|
|
234
|
+
delete(name: string): void;
|
|
235
|
+
entries(): IterableIterator<[string, string]>;
|
|
236
|
+
keys(): IterableIterator<string>;
|
|
237
|
+
values(): IterableIterator<string>;
|
|
238
|
+
forEach(callback: (value: string, name: string, headers: /*elided*/ any) => void): void;
|
|
239
|
+
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
240
|
+
};
|
|
241
|
+
get bodyUsed(): boolean;
|
|
242
|
+
get body(): null;
|
|
243
|
+
text(): Promise<string>;
|
|
244
|
+
json(): Promise<unknown>;
|
|
245
|
+
bytes(): Promise<Bytes>;
|
|
246
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
247
|
+
};
|
|
248
|
+
redirect(url: string | URL, status?: number): {
|
|
249
|
+
readonly status: number;
|
|
250
|
+
readonly statusText: string;
|
|
251
|
+
readonly type: "default";
|
|
252
|
+
readonly url: "";
|
|
253
|
+
readonly redirected: false;
|
|
254
|
+
get ok(): boolean;
|
|
255
|
+
clone(): /*elided*/ any;
|
|
256
|
+
readonly headers: {
|
|
257
|
+
append(name: string, value: unknown): void;
|
|
258
|
+
set(name: string, value: unknown): void;
|
|
259
|
+
get(name: string): string | null;
|
|
260
|
+
getSetCookie(): string[];
|
|
261
|
+
has(name: string): boolean;
|
|
262
|
+
delete(name: string): void;
|
|
263
|
+
entries(): IterableIterator<[string, string]>;
|
|
264
|
+
keys(): IterableIterator<string>;
|
|
265
|
+
values(): IterableIterator<string>;
|
|
266
|
+
forEach(callback: (value: string, name: string, headers: /*elided*/ any) => void): void;
|
|
267
|
+
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
268
|
+
};
|
|
269
|
+
get bodyUsed(): boolean;
|
|
270
|
+
get body(): null;
|
|
271
|
+
text(): Promise<string>;
|
|
272
|
+
json(): Promise<unknown>;
|
|
273
|
+
bytes(): Promise<Bytes>;
|
|
274
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
wireOf: (body: {
|
|
278
|
+
readonly headers: {
|
|
279
|
+
append(name: string, value: unknown): void;
|
|
280
|
+
set(name: string, value: unknown): void;
|
|
281
|
+
get(name: string): string | null;
|
|
282
|
+
getSetCookie(): string[];
|
|
283
|
+
has(name: string): boolean;
|
|
284
|
+
delete(name: string): void;
|
|
285
|
+
entries(): IterableIterator<[string, string]>;
|
|
286
|
+
keys(): IterableIterator<string>;
|
|
287
|
+
values(): IterableIterator<string>;
|
|
288
|
+
forEach(callback: (value: string, name: string, headers: /*elided*/ any) => void): void;
|
|
289
|
+
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
290
|
+
};
|
|
291
|
+
get bodyUsed(): boolean;
|
|
292
|
+
get body(): null;
|
|
293
|
+
text(): Promise<string>;
|
|
294
|
+
json(): Promise<unknown>;
|
|
295
|
+
bytes(): Promise<Bytes>;
|
|
296
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
297
|
+
}) => ({
|
|
298
|
+
text: string;
|
|
299
|
+
} | {
|
|
300
|
+
base64: string;
|
|
301
|
+
}) | null;
|
|
302
|
+
headerPairs: (value: unknown) => [string, string][];
|
|
303
|
+
bodyOfWire: (body: unknown) => string | Bytes | null;
|
|
304
|
+
};
|
|
305
|
+
export type GuestFetch = ReturnType<typeof guestFetch>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { GuestBytes } from './bytes';
|
|
2
|
+
import { GuestCrypto } from './crypto';
|
|
3
|
+
import { GuestEvents } from './events';
|
|
4
|
+
import { GuestFetch } from './fetch';
|
|
5
|
+
import { GuestDriver, GuestHost, GuestShared } from './types';
|
|
6
|
+
/** The web APIs of the guest, each part printed in on its own and handed to the guest built (`isolate.ts`). */
|
|
7
|
+
export type GuestParts = {
|
|
8
|
+
bytes: GuestBytes;
|
|
9
|
+
events: GuestEvents;
|
|
10
|
+
fetch: GuestFetch;
|
|
11
|
+
crypto: GuestCrypto;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* The runtime a space's code finds in an isolate: the web APIs a bare V8 lacks (`Headers`, `Request`, `Response`,
|
|
15
|
+
* `TextEncoder`, `AbortSignal`, timers, `crypto`) and the `ctx` its functions are handed.
|
|
16
|
+
*
|
|
17
|
+
* It is installed by PRINTING this function into the isolate (`installGuest.toString()`), after the prelude that brings
|
|
18
|
+
* `URL`, `atob`, `structuredClone` and `DOMException` — and after its web APIs, each part printed the same way and
|
|
19
|
+
* handed in built (`parts`). So none of them may use anything from outside its own body — no import, no helper beside
|
|
20
|
+
* it — and all they have of the runner is `host`, the functions in `shared` and the parts before them. Streams are not
|
|
21
|
+
* provided: a body is text or bytes.
|
|
22
|
+
*/
|
|
23
|
+
export declare const installGuest: (scope: Record<string, unknown>, host: GuestHost, shared: GuestShared, { bytes, events, fetch, crypto }: GuestParts) => GuestDriver;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createFunctionsDriver, describeFunctions } from '../driver';
|
|
2
|
+
import { changeKv, changeListEntry } from '@plitzi/sdk-shared/functions';
|
|
3
|
+
/** What the runner hands the guest: calls into the runner's own process, the only way out of the isolate. */
|
|
4
|
+
export type GuestHost = {
|
|
5
|
+
/** A {@link FunctionCall} for the platform, as JSON; answers a `FunctionAnswer`, as JSON. */
|
|
6
|
+
call: (message: string) => Promise<string>;
|
|
7
|
+
/** Resolves after `ms` — the runner's clock, bounded by the invocation's time. */
|
|
8
|
+
sleep: (ms: number) => Promise<void>;
|
|
9
|
+
/** `length` random bytes, from the runner's CSPRNG. */
|
|
10
|
+
random: (length: number) => number[];
|
|
11
|
+
/** A `crypto.subtle` operation the runner does with its own implementation: `{ op, … }` → a `FunctionAnswer` whose
|
|
12
|
+
* value is the bytes, base64. */
|
|
13
|
+
crypto: (message: string) => Promise<string>;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Functions of the platform's the guest runs as they are, printed in beside it (`isolate.ts`) — one implementation for
|
|
17
|
+
* native code and the sandbox alike. Each is self-contained by contract, as the guest is.
|
|
18
|
+
*/
|
|
19
|
+
export type GuestShared = {
|
|
20
|
+
/** `ctx.kv.change`: the read-change-write loop, over the guest's own `get` and `swap` calls. */
|
|
21
|
+
changeKv: typeof changeKv;
|
|
22
|
+
changeListEntry: typeof changeListEntry;
|
|
23
|
+
/** What a definition declares, as a manifest. */
|
|
24
|
+
describeFunctions: typeof describeFunctions;
|
|
25
|
+
/** An invocation of a definition with its `ctx` — the same driver a space runtime runs. */
|
|
26
|
+
createFunctionsDriver: typeof createFunctionsDriver;
|
|
27
|
+
};
|
|
28
|
+
/** What the runner drives the guest with, once installed. */
|
|
29
|
+
export type GuestDriver = {
|
|
30
|
+
/** What a definition declares — the manifest the platform reads and checks — as a `FunctionAnswer` (JSON). */
|
|
31
|
+
describe: (definition: unknown) => string;
|
|
32
|
+
/** Runs one invocation (JSON) of a definition, and answers a `FunctionAnswer` (JSON). Never rejects. */
|
|
33
|
+
invoke: (definition: unknown, invocation: string) => Promise<string>;
|
|
34
|
+
/** The run was aborted: `ctx.signal` fires, for code that listens, before the runner stops it. */
|
|
35
|
+
abort: (reason: string) => void;
|
|
36
|
+
};
|
|
37
|
+
/** The bytes every part of the guest reads and writes. */
|
|
38
|
+
export type Bytes = Uint8Array<ArrayBuffer>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { PBKDF2_MAX_ITERATIONS, PBKDF2_MAX_BITS, createIsolateRunner } from './isolate';
|
|
2
|
+
export { invocationFootprintMb, startFunctionsRunnerService } from './service';
|
|
3
|
+
export { createCpuMeter } from './cpuMeter';
|
|
4
|
+
export type { IsolateRunnerOptions, IsolateRunner } from './isolate';
|
|
5
|
+
export type { CpuMeter, MeteredIsolate } from './cpuMeter';
|
|
6
|
+
export type { FunctionsRunnerServiceOptions, FunctionsRunnerService } from './service';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { r as PBKDF2_MAX_BITS, i as PBKDF2_MAX_ITERATIONS, o as createCpuMeter, a as createIsolateRunner, t as invocationFootprintMb, n as startFunctionsRunnerService } from "../chunks/service-DDDJomiH.mjs";
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { CpuMeter } from './cpuMeter';
|
|
2
|
+
import { FunctionRunner } from '@plitzi/sdk-shared/functions';
|
|
3
|
+
export type IsolateRunnerOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* Invocations running at once, at most: the runner service turns the rest away (`busy`) for the platform to place on
|
|
6
|
+
* another runner — and takes fewer while its memory is short (`memoryShare`). Each isolate may grow to about twice its
|
|
7
|
+
* `memoryMb`; most wait on the network and hold a few MB, which is why memory, not this, decides how many run.
|
|
8
|
+
*/
|
|
9
|
+
concurrency?: number;
|
|
10
|
+
/**
|
|
11
|
+
* How many bytes of bundles this runner keeps — their code and V8's cache of it — least recently used let go first.
|
|
12
|
+
* A bundle it no longer has is asked of the platform again; one it has is never sent twice. 32 MB by default: a bundle
|
|
13
|
+
* let go costs one recompile, which V8's code cache shortens.
|
|
14
|
+
*/
|
|
15
|
+
cacheBytes?: number;
|
|
16
|
+
/**
|
|
17
|
+
* How many isolates run JavaScript at once: as many as the cores this runner may use (its container's quota, at least
|
|
18
|
+
* one) by default. An isolate waiting on the platform — a call, a sleep, a derivation — gives its turn up and takes one
|
|
19
|
+
* again when the answer is back. isolated-vm runs isolates on as many threads as the machine has cores, whatever the
|
|
20
|
+
* container's quota: past it they fought for its CPU. With turns, fewer fight at once; what each is charged is the
|
|
21
|
+
* meter's (`cpuMeter`).
|
|
22
|
+
*/
|
|
23
|
+
turns?: number;
|
|
24
|
+
/**
|
|
25
|
+
* What each isolate is charged of the CPU: its share of the process's own, as the system counts it, by default
|
|
26
|
+
* (`createCpuMeter`) — never the time it waited for a core, which V8 counts as its CPU. A test hands one of its own.
|
|
27
|
+
*/
|
|
28
|
+
cpuMeter?: CpuMeter;
|
|
29
|
+
};
|
|
30
|
+
/** The isolates, and what readies them before the first invocation pays for it. */
|
|
31
|
+
export type IsolateRunner = FunctionRunner & {
|
|
32
|
+
/**
|
|
33
|
+
* Builds the prelude, the heap every isolate starts from and V8's cache of the guest, and runs a first bundle — what
|
|
34
|
+
* the first invocation of a fresh process would otherwise spend (~70 ms) on top of its own.
|
|
35
|
+
*/
|
|
36
|
+
warm: () => Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Gives back the invocation whose isolate holds the most memory — what the runner does when it runs short of its own
|
|
39
|
+
* (`startFunctionsRunnerService`): stopped as `memory` when it is past its own limit (the code's), else handed back
|
|
40
|
+
* as `busy`, for another runner (the runner's). What it gave back, or nothing when nothing runs.
|
|
41
|
+
*/
|
|
42
|
+
shed: () => {
|
|
43
|
+
overItsOwn: boolean;
|
|
44
|
+
heldMb: number;
|
|
45
|
+
spaceId: number;
|
|
46
|
+
} | undefined;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* The most a PBKDF2 derivation may ask for. The runner does the work, outside the isolate's clock, so each is bounded
|
|
50
|
+
* here and its time is charged to the run's CPU: a million rounds is past any password guidance, and 1024 bits past
|
|
51
|
+
* any key.
|
|
52
|
+
*/
|
|
53
|
+
export declare const PBKDF2_MAX_ITERATIONS = 1000000;
|
|
54
|
+
export declare const PBKDF2_MAX_BITS = 1024;
|
|
55
|
+
/**
|
|
56
|
+
* The runner as V8 isolates in this process — what the runner service serves, and what a deployment may use directly
|
|
57
|
+
* when the process holds nothing a space's code must not reach (tests, a sandbox of its own).
|
|
58
|
+
*
|
|
59
|
+
* ONE ISOLATE PER INVOCATION: each limit is then exactly that invocation's — its CPU, its memory — and stopping it
|
|
60
|
+
* disposes nothing anybody else was using. No state survives an invocation, by construction. The cost is ~2 ms: the
|
|
61
|
+
* prelude comes from a V8 snapshot, the guest and the bundle from V8's code cache after their first compile.
|
|
62
|
+
*/
|
|
63
|
+
/** How many isolates run at once when the runner is not told. */
|
|
64
|
+
export declare const DEFAULT_CONCURRENCY = 8;
|
|
65
|
+
export declare const createIsolateRunner: ({ concurrency, cacheBytes, turns: turnCount, cpuMeter: cpu }?: IsolateRunnerOptions) => IsolateRunner;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { MemoryReading } from '@plitzi/sdk-kernel/stats';
|
|
2
|
+
/** How full of its memory a runner may get before it gives the largest invocation back: above where it takes new ones. */
|
|
3
|
+
export declare const SHED_SHARE = 0.92;
|
|
4
|
+
/** How long it waits after giving one back before it looks again: its memory takes a moment to come back. */
|
|
5
|
+
export declare const SHED_COOL_MS = 500;
|
|
6
|
+
export type MemoryGuard = {
|
|
7
|
+
/** Looks once: past its share, gives the largest invocation back — unless it just did. Answers whether it did. */
|
|
8
|
+
look: () => boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* What keeps a runner from being killed for its invocations' memory.
|
|
12
|
+
*
|
|
13
|
+
* It takes an invocation while a share of what that one may grow to fits (`busy`), since most hold a few MB; nothing
|
|
14
|
+
* kept the ones it took from growing together past its container's limit, and the kernel killed the runner — every
|
|
15
|
+
* invocation in it with it (`closed with 1006`), 150 calls of one load round. Near its limit it gives back the one
|
|
16
|
+
* whose isolate holds the most (`IsolateRunner.shed`): stopped at its own limit if it is past it, else handed back as
|
|
17
|
+
* `busy` for another runner — one invocation said, never all of them lost.
|
|
18
|
+
*/
|
|
19
|
+
export declare const createMemoryGuard: ({ readMemory, shed, share, coolMs, now }: {
|
|
20
|
+
readMemory: () => MemoryReading;
|
|
21
|
+
shed: () => boolean;
|
|
22
|
+
share?: number;
|
|
23
|
+
coolMs?: number;
|
|
24
|
+
now?: () => number;
|
|
25
|
+
}) => MemoryGuard;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Where the package's build keeps the prelude it made (`scripts/prelude.mjs`), from the package's root. */
|
|
2
|
+
export declare const BUILT_PRELUDE = "dist/prelude.js";
|
|
3
|
+
/**
|
|
4
|
+
* The prelude, built from core-js with esbuild: what the package's build writes to {@link BUILT_PRELUDE}, and what a
|
|
5
|
+
* process running this package's sources (its tests, the workspace's servers) makes for itself. Neither core-js nor
|
|
6
|
+
* esbuild is a runner's to install.
|
|
7
|
+
*/
|
|
8
|
+
export declare const buildPrelude: () => Promise<string>;
|
|
9
|
+
/** The prelude's source, read or built on first use and the same for every isolate this process makes. */
|
|
10
|
+
export declare const guestPrelude: () => Promise<string>;
|