@restatedev/sessions 0.11.2 → 0.12.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 +330 -178
- package/dist/addon.d.ts +1 -0
- package/dist/addon.d.ts.map +1 -1
- package/dist/addon.js.map +1 -1
- package/dist/calls.d.ts +28 -28
- package/dist/calls.d.ts.map +1 -1
- package/dist/calls.js +25 -25
- package/dist/calls.js.map +1 -1
- package/dist/database.d.ts +90 -166
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +137 -249
- package/dist/database.js.map +1 -1
- package/dist/driver.d.ts +129 -126
- package/dist/driver.d.ts.map +1 -1
- package/dist/driver.js +337 -276
- package/dist/driver.js.map +1 -1
- package/dist/endpoint.d.ts +47 -5
- package/dist/endpoint.d.ts.map +1 -1
- package/dist/endpoint.js +175 -60
- package/dist/endpoint.js.map +1 -1
- package/dist/handler.d.ts +20 -17
- package/dist/handler.d.ts.map +1 -1
- package/dist/handler.js +161 -127
- package/dist/handler.js.map +1 -1
- package/dist/host.d.ts +29 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +2 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -26
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +11 -11
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +20 -16
- package/dist/internal.js.map +1 -1
- package/dist/link.d.ts +1 -2
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +4 -5
- package/dist/link.js.map +1 -1
- package/dist/log.d.ts +14 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +21 -0
- package/dist/log.js.map +1 -0
- package/dist/object.d.ts +217 -142
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +195 -241
- package/dist/object.js.map +1 -1
- package/dist/platform.d.ts +0 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +4 -6
- package/dist/platform.js.map +1 -1
- package/dist/schema.d.ts +14 -22
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +31 -69
- package/dist/schema.js.map +1 -1
- package/dist/serve.d.ts +11 -17
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +21 -39
- package/dist/serve.js.map +1 -1
- package/dist/session.d.ts +58 -240
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +206 -532
- package/dist/session.js.map +1 -1
- package/dist/stop.d.ts +59 -0
- package/dist/stop.d.ts.map +1 -0
- package/dist/stop.js +220 -0
- package/dist/stop.js.map +1 -0
- package/dist/vm.d.ts +108 -29
- package/dist/vm.d.ts.map +1 -1
- package/dist/vm.js +43 -10
- package/dist/vm.js.map +1 -1
- package/package.json +4 -4
- package/src/addon.ts +1 -0
- package/src/calls.ts +51 -47
- package/src/database.ts +195 -339
- package/src/driver.ts +379 -315
- package/src/endpoint.ts +217 -62
- package/src/handler.ts +183 -164
- package/src/host.ts +28 -0
- package/src/index.ts +6 -26
- package/src/internal.ts +28 -39
- package/src/link.ts +4 -5
- package/src/log.ts +42 -0
- package/src/object.ts +379 -335
- package/src/platform.ts +4 -6
- package/src/schema.ts +37 -103
- package/src/serve.ts +20 -41
- package/src/session.ts +236 -629
- package/src/stop.ts +225 -0
- package/src/vm.ts +151 -55
- package/dist/scope.d.ts +0 -38
- package/dist/scope.d.ts.map +0 -1
- package/dist/scope.js +0 -55
- package/dist/scope.js.map +0 -1
- package/src/scope.ts +0 -78
package/dist/handler.js
CHANGED
|
@@ -1,71 +1,98 @@
|
|
|
1
|
-
// Serving one
|
|
2
|
-
//
|
|
3
|
-
// which replays and would hold such a handler to one await at a time.
|
|
1
|
+
// Serving one attempt of a session object's handler on the explicit recovery
|
|
2
|
+
// protocol (`driver.ts`), rather than through the SDK's journaled context.
|
|
4
3
|
//
|
|
5
4
|
// The core takes a stream — the request's headers and body, and where to write
|
|
6
|
-
// the response — so that a test can drive it with wire bytes and `
|
|
5
|
+
// the response — so that a test can drive it with wire bytes and `endpoint.ts`
|
|
7
6
|
// can hand it an HTTP/2 one. It is reached only for a session object's
|
|
8
7
|
// handler; everything else a deployment serves stays the SDK's.
|
|
9
8
|
import * as restate from '@restatedev/restate-sdk';
|
|
10
9
|
import { millisOrDurationToMillis } from '@restatedev/restate-sdk-core';
|
|
11
|
-
import { AttemptDriver, AttemptFailed, AttemptShutDown } from './driver.js';
|
|
10
|
+
import { AttemptDriver, AttemptFailed, AttemptShutDown, quiet } from './driver.js';
|
|
11
|
+
import { silent } from './log.js';
|
|
12
12
|
import { handlerEntry, invoke } from './object.js';
|
|
13
|
-
import { Vm } from './vm.js';
|
|
14
|
-
/** The
|
|
15
|
-
export const
|
|
13
|
+
import { refusedStatus, Vm } from './vm.js';
|
|
14
|
+
/** The content type of the explicit recovery protocol's invocations, version 1. */
|
|
15
|
+
export const CONTENT_TYPE = 'application/vnd.restate.invocation.explicitrecovery.v1';
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* A Restate that speaks less once reached the SDK's VM through the selector.
|
|
21
|
-
* That is gone, and a session object cannot run on a VM that replays, so an
|
|
22
|
-
* older server cannot serve one at all: `endpoint.ts` answers such an
|
|
23
|
-
* invocation itself rather than handing it on. Everything that is not a
|
|
24
|
-
* session object is still the SDK's at any version it supports.
|
|
17
|
+
* How long the response waits, after the attempt's last message, for Restate
|
|
18
|
+
* to close the request: Restate closes first, then the attempt (D35). One
|
|
19
|
+
* that never does is closed anyway.
|
|
25
20
|
*/
|
|
26
|
-
export
|
|
27
|
-
const type = headers['content-type'];
|
|
28
|
-
const match = /application\/vnd\.restate\.invocation\.v(\d+)/.exec((Array.isArray(type) ? type[0] : type) ?? '');
|
|
29
|
-
return match !== null && Number(match[1]) >= MIN_PROTOCOL;
|
|
30
|
-
}
|
|
21
|
+
export const CLOSE_TIMEOUT_MS = 30_000;
|
|
31
22
|
/** `headers` as the VM takes them. */
|
|
32
23
|
function vmHeaders(headers) {
|
|
33
24
|
return Object.entries(headers).flatMap(([key, value]) => value === undefined ? [] : [{ key, value: Array.isArray(value) ? (value[0] ?? '') : value }]);
|
|
34
25
|
}
|
|
26
|
+
/** The attempts this process is serving, with what closes each one's response: a SIGTERM ends them (`goAway`). */
|
|
27
|
+
const live = new Map();
|
|
28
|
+
/**
|
|
29
|
+
* The process is going away: end every attempt it serves with an unasked
|
|
30
|
+
* `ShutdownMessage` and close its response at once; Restate starts each
|
|
31
|
+
* again, elsewhere. Returns how many there were.
|
|
32
|
+
*/
|
|
33
|
+
export function goAway() {
|
|
34
|
+
const attempts = [...live];
|
|
35
|
+
for (const [driver, close] of attempts) {
|
|
36
|
+
driver.goAway();
|
|
37
|
+
close();
|
|
38
|
+
}
|
|
39
|
+
return attempts.length;
|
|
40
|
+
}
|
|
35
41
|
/**
|
|
36
42
|
* Run one attempt of `definition`'s handler `name` over `stream`, and end its
|
|
37
|
-
* response.
|
|
38
|
-
*
|
|
39
|
-
*
|
|
43
|
+
* response. A request of another protocol family or version is answered with
|
|
44
|
+
* the status the VM refuses it with (415), and nothing runs. `log` gets a
|
|
45
|
+
* line for that refusal, for an attempt that fails and is retried, and for
|
|
46
|
+
* one the VM failed (a protocol failure): the error's message, never the
|
|
47
|
+
* input or a header.
|
|
40
48
|
*/
|
|
41
|
-
export async function serveSession(definition, name, stream,
|
|
42
|
-
const entry = handlerEntry(definition, name);
|
|
49
|
+
export async function serveSession(definition, name, stream, defaults = {}, log = silent) {
|
|
50
|
+
const entry = handlerEntry(definition, name, defaults);
|
|
43
51
|
if (entry === undefined)
|
|
44
52
|
throw new Error(`${definition.name}/${name} is no handler or view of a session object`);
|
|
45
|
-
|
|
53
|
+
let vm;
|
|
54
|
+
try {
|
|
55
|
+
vm = new Vm(vmHeaders(stream.headers));
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
const status = refusedStatus(error);
|
|
59
|
+
// Its text may quote a header: the caller logs what it throws.
|
|
60
|
+
if (status === undefined)
|
|
61
|
+
throw new Error('the VM could not start the invocation', { cause: error });
|
|
62
|
+
log('warn', `${definition.name}/${name}: answered ${status}: the request is not on the explicit recovery protocol, version 1`);
|
|
63
|
+
// Not a 500: Restate offers the next lower version of its range on a 415.
|
|
64
|
+
stream.writeHead(status, {});
|
|
65
|
+
stream.close();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
46
68
|
const head = vm.getResponseHead();
|
|
47
69
|
stream.writeHead(head.statusCode, Object.fromEntries(head.headers.map(({ key, value }) => [key, value])));
|
|
48
70
|
const driver = new AttemptDriver(vm, (chunk) => stream.write(chunk), {
|
|
49
71
|
service: definition.name,
|
|
50
72
|
handler: name,
|
|
51
|
-
shared: entry.view,
|
|
52
73
|
explicitCancellation: entry.explicit,
|
|
74
|
+
inactivityTimeoutMs: entry.inactivityTimeoutMs,
|
|
53
75
|
});
|
|
54
76
|
// The database's store acts on the VM from the runtime's thread, in the
|
|
55
77
|
// addon; this is how it asks for the tick that writes what it sent.
|
|
56
78
|
vm.setScheduler(() => driver.scheduleTick());
|
|
57
|
-
// The response
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
// `ctx.working`) runs on until that work is done,
|
|
79
|
+
// The response closes once the attempt's last message is written and the
|
|
80
|
+
// runtime closed its side (it closes first), or when the process goes
|
|
81
|
+
// away: not when the handler returns. A handler that Restate shut down at
|
|
82
|
+
// work of its own (outside `ctx.working`) runs on until that work is done,
|
|
83
|
+
// its actions throwing.
|
|
61
84
|
let closed = false;
|
|
85
|
+
const whenClosed = Promise.withResolvers();
|
|
62
86
|
const close = () => {
|
|
63
87
|
if (closed)
|
|
64
88
|
return;
|
|
65
89
|
closed = true;
|
|
90
|
+
live.delete(driver);
|
|
66
91
|
stream.close();
|
|
92
|
+
whenClosed.resolve();
|
|
67
93
|
};
|
|
68
|
-
|
|
94
|
+
live.set(driver, close);
|
|
95
|
+
driver.whenClosable(close);
|
|
69
96
|
// The input pump: the only reader of the request body. It runs until the
|
|
70
97
|
// body ends, beside the handler.
|
|
71
98
|
const ready = Promise.withResolvers();
|
|
@@ -87,6 +114,7 @@ export async function serveSession(definition, name, stream, { bidirectional = t
|
|
|
87
114
|
ready.resolve();
|
|
88
115
|
}
|
|
89
116
|
})();
|
|
117
|
+
let invocation;
|
|
90
118
|
try {
|
|
91
119
|
await ready.promise;
|
|
92
120
|
if (driver.over !== undefined || !driver.isReadyToExecute())
|
|
@@ -95,81 +123,119 @@ export async function serveSession(definition, name, stream, { bidirectional = t
|
|
|
95
123
|
// either: a terminal failure ends the invocation, where a retryable one
|
|
96
124
|
// would have Restate send the same bytes forever. The SDK's own handler
|
|
97
125
|
// does the same for input its journal codec cannot decode.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
126
|
+
const request = driver.request(new Map(Object.entries(stream.headers)));
|
|
127
|
+
invocation = { id: request.id, service: definition.name, handler: name };
|
|
128
|
+
let output;
|
|
129
|
+
// The hooks' handler interceptors wrap all of it, as the SDK's do.
|
|
130
|
+
await intercepted(entry.hooks, request)(async () => {
|
|
131
|
+
let input;
|
|
132
|
+
try {
|
|
133
|
+
input = entry.inputSerde.deserialize(driver.body);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
throw new restate.TerminalError(`failed to deserialize the input: ${error.message}`, {
|
|
137
|
+
errorCode: 400,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
output = entry.outputSerde.serialize(await invoke(definition, name, hostOf(driver, request, vm), input, entry));
|
|
141
|
+
});
|
|
108
142
|
// A cancellation that arrived while the handler ran is still cancelling
|
|
109
143
|
// its calls: they go out before the attempt ends, or not at all.
|
|
110
144
|
await driver.cancellingCalls;
|
|
111
|
-
driver.endSuccess(
|
|
145
|
+
driver.endSuccess(output);
|
|
112
146
|
}
|
|
113
147
|
catch (error) {
|
|
114
148
|
await driver.cancellingCalls;
|
|
115
|
-
endWith(driver, error, entry.asTerminalError);
|
|
149
|
+
endWith(driver, error, entry.asTerminalError, (message) => log('warn', message, invocation));
|
|
116
150
|
}
|
|
117
151
|
finally {
|
|
118
|
-
|
|
119
|
-
|
|
152
|
+
if (driver.over instanceof AttemptFailed)
|
|
153
|
+
log('warn', `the attempt failed: ${driver.over.message}`, invocation);
|
|
154
|
+
// The attempt's last words are buffered: a turn lets the tick write them,
|
|
155
|
+
// and the response closes once Restate closed the request too.
|
|
120
156
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
157
|
+
if (!closed) {
|
|
158
|
+
const timeout = setTimeout(close, CLOSE_TIMEOUT_MS);
|
|
159
|
+
timeout.unref?.();
|
|
160
|
+
await Promise.race([pump, whenClosed.promise]);
|
|
161
|
+
// The end of the input reached the VM: the tick that follows closes.
|
|
162
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
163
|
+
driver.scheduleTick();
|
|
164
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
165
|
+
// Restate closed the request, and the VM has no last message to write:
|
|
166
|
+
// it was shut down before it started, say. Nothing more will come.
|
|
167
|
+
if (!closed && driver.over !== undefined)
|
|
168
|
+
close();
|
|
169
|
+
clearTimeout(timeout);
|
|
170
|
+
}
|
|
121
171
|
close();
|
|
122
172
|
}
|
|
123
173
|
}
|
|
124
|
-
/**
|
|
125
|
-
|
|
174
|
+
/** What the SDK's hook context carries for its own instrumentation: whether the invocation is past replay. */
|
|
175
|
+
const IS_PROCESSING = Symbol.for('@restatedev/restate-sdk/hooks.isProcessing');
|
|
176
|
+
/**
|
|
177
|
+
* Run an attempt inside the `handler` interceptors of `hooks`, the first
|
|
178
|
+
* outermost, as the SDK does (`startUserHandler`, `composeInterceptors`):
|
|
179
|
+
* each provider is called once per attempt with the request. An interceptor
|
|
180
|
+
* and its `next()` reject with what ended the attempt once it ends (a
|
|
181
|
+
* shutdown, say), so that none waits on a function that may never return,
|
|
182
|
+
* as the SDK's `raceWithAttemptEnd` does. A session object's context has no
|
|
183
|
+
* `ctx.run`, so a `run` interceptor is never called, and an attempt is never
|
|
184
|
+
* a replay.
|
|
185
|
+
*/
|
|
186
|
+
function intercepted(hooks, request) {
|
|
187
|
+
const interceptors = hooks.flatMap((provider) => {
|
|
188
|
+
const context = { request };
|
|
189
|
+
Object.defineProperty(context, IS_PROCESSING, { value: () => true, enumerable: false });
|
|
190
|
+
const handler = provider(context).interceptor?.handler;
|
|
191
|
+
return handler === undefined ? [] : [handler];
|
|
192
|
+
});
|
|
193
|
+
if (interceptors.length === 0)
|
|
194
|
+
return (run) => run();
|
|
195
|
+
const signal = request.attemptCompletedSignal;
|
|
196
|
+
const ended = new Promise((_, reject) => {
|
|
197
|
+
if (signal.aborted)
|
|
198
|
+
reject(signal.reason);
|
|
199
|
+
else
|
|
200
|
+
signal.addEventListener('abort', () => reject(signal.reason), { once: true });
|
|
201
|
+
});
|
|
202
|
+
ended.catch(() => { });
|
|
203
|
+
const racing = (promise) => Promise.race([promise, ended]);
|
|
204
|
+
return (run) => interceptors.reduceRight((next, interceptor) => () => racing(interceptor(() => racing(next()))), run)();
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* End the attempt the way `error` says to. The `asTerminalError` option
|
|
208
|
+
* applies as the SDK applies it (`ensureError`, `notifyError`): what it
|
|
209
|
+
* returns takes the error's place, and ends the invocation if it is a
|
|
210
|
+
* `TerminalError`; anything else fails the attempt, and Restate retries it.
|
|
211
|
+
*/
|
|
212
|
+
function endWith(driver, error, asTerminalError, retried) {
|
|
126
213
|
if (error instanceof AttemptShutDown)
|
|
127
214
|
return; // the attempt is over; nothing more is sent
|
|
128
|
-
// The handler option of the same name: an error it names ends the
|
|
129
|
-
// invocation rather than being retried. The SDK applies it, so this does.
|
|
130
|
-
if (asTerminalError !== undefined && !(error instanceof restate.TerminalError)) {
|
|
131
|
-
const terminal = asTerminalError(error);
|
|
132
|
-
if (terminal !== undefined) {
|
|
133
|
-
driver.endFailure(terminal instanceof restate.TerminalError ? terminal : new restate.TerminalError(terminal.message));
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
if (error instanceof restate.TerminalError) {
|
|
138
|
-
driver.endFailure(error);
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
215
|
if (error instanceof AttemptFailed)
|
|
142
216
|
return; // the VM wrote why
|
|
143
|
-
const
|
|
144
|
-
|
|
145
|
-
|
|
217
|
+
const mapped = error instanceof restate.TerminalError ? error : asTerminalError?.(error) || error;
|
|
218
|
+
if (mapped instanceof restate.TerminalError) {
|
|
219
|
+
driver.endFailure(mapped);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const { retryAfter } = mapped;
|
|
223
|
+
const thrown = mapped instanceof Error ? mapped : new Error(String(mapped));
|
|
224
|
+
// The VM takes a whole number of milliseconds.
|
|
225
|
+
const delay = retryAfter === undefined ? undefined : Math.round(millisOrDurationToMillis(retryAfter));
|
|
226
|
+
retried(`the handler failed, and Restate retries it${delay === undefined ? '' : ` in ${delay} ms`}: ${thrown.name}: ${thrown.message}`);
|
|
227
|
+
driver.fail(thrown.message, thrown.stack, delay);
|
|
146
228
|
}
|
|
147
|
-
/**
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
*/
|
|
151
|
-
function contextOf(driver, attemptHeaders, vm) {
|
|
152
|
-
const headers = new Map(Object.entries(attemptHeaders));
|
|
153
|
-
const request = driver.request(headers);
|
|
154
|
-
/** The attempt's end, as `invocationEndPromise` gives it: a promise that rejects. */
|
|
155
|
-
const ending = Promise.withResolvers();
|
|
156
|
-
ending.promise.catch(() => { });
|
|
157
|
-
driver.whenEnded(() => ending.reject(driver.over ?? new AttemptShutDown()));
|
|
158
|
-
const context = {
|
|
229
|
+
/** The attempt over `driver`, as a session object handler sees it (object.ts). */
|
|
230
|
+
function hostOf(driver, request, vm) {
|
|
231
|
+
return {
|
|
159
232
|
key: driver.key,
|
|
160
|
-
request
|
|
161
|
-
|
|
162
|
-
//
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
set: servedByVm('set'),
|
|
167
|
-
clear: servedByVm('clear'),
|
|
168
|
-
stateKeys: servedByVm('stateKeys'),
|
|
169
|
-
run: () => {
|
|
170
|
-
throw new restate.TerminalError('a session object has no ctx.run: put journaled work in a restate.object, service or workflow, and call it with ctx.rpc');
|
|
171
|
-
},
|
|
172
|
-
genericCall: (call) => {
|
|
233
|
+
request,
|
|
234
|
+
stop: driver.stop,
|
|
235
|
+
// The addon reads and writes the object state on the VM (see `openOnVm`).
|
|
236
|
+
vm,
|
|
237
|
+
driver,
|
|
238
|
+
call: (call) => {
|
|
173
239
|
const { result, invocationId } = driver.call({
|
|
174
240
|
service: call.service,
|
|
175
241
|
handler: call.method,
|
|
@@ -178,54 +244,22 @@ function contextOf(driver, attemptHeaders, vm) {
|
|
|
178
244
|
idempotencyKey: call.idempotencyKey,
|
|
179
245
|
headers: Object.entries(call.headers ?? {}).map(([key, value]) => ({ key, value })),
|
|
180
246
|
});
|
|
181
|
-
// Marked handled:
|
|
182
|
-
//
|
|
183
|
-
// and at the end of every attempt — including a successful one.
|
|
247
|
+
// Marked handled: a handler need not await a call (a lost race), and it
|
|
248
|
+
// rejects at the end of every attempt, even a successful one.
|
|
184
249
|
const answered = quiet(result.then((value) => (call.outputSerde ?? restate.serde.json).deserialize(value ?? new Uint8Array())));
|
|
185
250
|
return Object.assign(answered, { invocationId });
|
|
186
251
|
},
|
|
187
|
-
|
|
252
|
+
send: (send) => driver.send({
|
|
188
253
|
service: send.service,
|
|
189
254
|
handler: send.method,
|
|
190
255
|
key: send.key,
|
|
191
256
|
input: (send.inputSerde ?? restate.serde.json).serialize(send.parameter),
|
|
192
|
-
//
|
|
193
|
-
// milliseconds.
|
|
257
|
+
// The VM takes milliseconds.
|
|
194
258
|
delay: send.delay === undefined ? undefined : millisOrDurationToMillis(send.delay),
|
|
195
259
|
idempotencyKey: send.idempotencyKey,
|
|
196
260
|
headers: Object.entries(send.headers ?? {}).map(([key, value]) => ({ key, value })),
|
|
197
261
|
}),
|
|
198
|
-
|
|
199
|
-
cancel: () => driver.cancel(String(invocationId)),
|
|
200
|
-
attach: (serde) => quiet(driver
|
|
201
|
-
.attach(String(invocationId))
|
|
202
|
-
.then((value) => (serde ?? restate.serde.json).deserialize(value ?? new Uint8Array()))),
|
|
203
|
-
}),
|
|
204
|
-
cancellation: () => driver.cancellation(),
|
|
205
|
-
// A cancellation owed to the handler's next await, which a call of its
|
|
206
|
-
// database takes before it issues anything (`session.ts`).
|
|
207
|
-
takeCancellation: () => driver.takeCarriedCancellation(),
|
|
208
|
-
cancelPreviousCalls: () => driver.cancelPreviousCalls(),
|
|
209
|
-
// What `ctx.working` keeps alive, and the database's own calls too (`session.ts`).
|
|
210
|
-
working: (fn) => driver.working(fn),
|
|
211
|
-
invocationEndPromise: { promise: ending.promise },
|
|
212
|
-
defaultSerde: restate.serde.json,
|
|
213
|
-
// The addon reads and writes the object's state on this, rather than
|
|
214
|
-
// calling back into JavaScript for every page (see `openOnVm`).
|
|
215
|
-
vm,
|
|
262
|
+
cancel: (invocationId) => driver.cancel(invocationId),
|
|
216
263
|
};
|
|
217
|
-
return context;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Mark a promise handled, so that one the handler never awaits does not bring
|
|
221
|
-
* the process down when the attempt ends. The caller still sees the rejection.
|
|
222
|
-
*/
|
|
223
|
-
function quiet(promise) {
|
|
224
|
-
promise.catch(() => { });
|
|
225
|
-
return promise;
|
|
226
264
|
}
|
|
227
|
-
/** What a state member of the context does if anything calls it. */
|
|
228
|
-
const servedByVm = (of) => () => {
|
|
229
|
-
throw new restate.TerminalError(`@restatedev/sessions: the VM serves the object's state in the addon; ctx.${of} is not called`);
|
|
230
|
-
};
|
|
231
265
|
//# sourceMappingURL=handler.js.map
|
package/dist/handler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,2EAA2E;AAC3E,EAAE;AACF,+EAA+E;AAC/E,+EAA+E;AAC/E,uEAAuE;AACvE,gEAAgE;AAChE,OAAO,KAAK,OAAO,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAiB,MAAM,8BAA8B,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEnF,OAAO,EAA6B,MAAM,EAAE,MAAM,UAAU,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,EAAuB,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,EAAE,EAAiB,MAAM,SAAS,CAAC;AAE3D,mFAAmF;AACnF,MAAM,CAAC,MAAM,YAAY,GAAG,wDAAwD,CAAC;AAErF;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAavC,sCAAsC;AACtC,SAAS,SAAS,CAAC,OAAgE;IACjF,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CACtD,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAC7F,CAAC;AACJ,CAAC;AAED,kHAAkH;AAClH,MAAM,IAAI,GAAG,IAAI,GAAG,EAA6B,CAAC;AAElD;;;;GAIG;AACH,MAAM,UAAU,MAAM;IACp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AG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;SACpF,CAAC;QACJ,MAAM,EAAE,CAAC,YAAY,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC;KACtD,CAAC;AACJ,CAAC"}
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type * as restate from '@restatedev/restate-sdk';
|
|
2
|
+
import type { Store } from './database.ts';
|
|
3
|
+
import type { AttemptDriver } from './driver.ts';
|
|
4
|
+
import type { SessionRequest } from './object.ts';
|
|
5
|
+
import type { Stop } from './stop.ts';
|
|
6
|
+
import type { Vm } from './vm.ts';
|
|
7
|
+
/** What one attempt runs on: the driver over its VM (handler.ts), or a test's fake (test/support.ts). */
|
|
8
|
+
export interface AttemptHost {
|
|
9
|
+
readonly key: string;
|
|
10
|
+
/** Its `attemptCompletedSignal` aborts, with the error that ended it, when the attempt ends. */
|
|
11
|
+
readonly request: SessionRequest;
|
|
12
|
+
/** See stop.ts. */
|
|
13
|
+
readonly stop: Stop;
|
|
14
|
+
/** The addon reads and writes the object state on it. A test gives `store` instead. */
|
|
15
|
+
readonly vm?: Vm;
|
|
16
|
+
/** The object's state in JavaScript, for an attempt without a VM (tests). */
|
|
17
|
+
readonly store?: Store;
|
|
18
|
+
/**
|
|
19
|
+
* The attempt's driver, on the VM: spans, and what the protocol adds beyond
|
|
20
|
+
* calls and sends (invocation state, signals, flush). A test's has none.
|
|
21
|
+
*/
|
|
22
|
+
readonly driver?: AttemptDriver;
|
|
23
|
+
call(call: restate.GenericCall<unknown, unknown>): Promise<unknown> & {
|
|
24
|
+
invocationId: Promise<string>;
|
|
25
|
+
};
|
|
26
|
+
send(send: restate.GenericSend<unknown>): void;
|
|
27
|
+
cancel(invocationId: string): void;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=host.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,OAAO,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAElC,yGAAyG;AACzG,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,gGAAgG;IAChG,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;IACjC,mBAAmB;IACnB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,uFAAuF;IACvF,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IACjB,6EAA6E;IAC7E,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,aAAa,CAAC;IAChC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG;QAAE,YAAY,EAAE,OAAO,CAAC,MAAM,CAAC,CAAA;KAAE,CAAC;IACxG,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IAC/C,MAAM,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CACpC"}
|
package/dist/host.js
ADDED
package/dist/host.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.js","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export * from '@restatedev/restate-sdk';
|
|
2
2
|
export type { Database, DatabaseReader, DatabaseWriter, Row, SqlParam, SqlValue, Transaction } from './session.ts';
|
|
3
3
|
export type { Step } from './schema.ts';
|
|
4
|
-
export { sessionObject, type Cancel, type Entry, type HandlerOptions, type SessionContext, type ViewContext, } from './object.ts';
|
|
4
|
+
export { sessionObject, type Cancel, type Entry, type HandlerOptions, type SessionContext, type SessionRequest, type ViewContext, } from './object.ts';
|
|
5
5
|
export type { CallOptions, Client, Rpc, Send, SendClient, SendOptions, Target } from './calls.ts';
|
|
6
6
|
export { remote } from './calls.ts';
|
|
7
7
|
export { connect, serve, served } from './serve.ts';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,cAAc,yBAAyB,CAAC;AACxC,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,cAAc,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACnH,YAAY,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EACL,aAAa,EACb,KAAK,MAAM,EACX,KAAK,KAAK,EACV,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,WAAW,GACjB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAClG,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,33 +1,12 @@
|
|
|
1
1
|
// Session objects: Restate virtual objects whose state is a SQL database per
|
|
2
|
-
// key.
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// import * as restate from '@restatedev/sessions';
|
|
6
|
-
//
|
|
7
|
-
// const notes = restate.sessionObject({
|
|
8
|
-
// name: 'notes',
|
|
9
|
-
// schema: ['CREATE TABLE notes (text TEXT NOT NULL)'],
|
|
10
|
-
// handlers: {
|
|
11
|
-
// add: async (ctx, text: string) => {
|
|
12
|
-
// await ctx.db.execute('INSERT INTO notes (text) VALUES (?)', [text]);
|
|
13
|
-
// },
|
|
14
|
-
// },
|
|
15
|
-
// views: {
|
|
16
|
-
// list: async (ctx) => ctx.db.query<{ text: string }>('SELECT text FROM notes'),
|
|
17
|
-
// },
|
|
18
|
-
// });
|
|
19
|
-
//
|
|
2
|
+
// key. This module is the Restate SDK (`import * as restate from
|
|
3
|
+
// '@restatedev/sessions'`) plus `restate.sessionObject` (example in object.ts).
|
|
20
4
|
// See README.md.
|
|
21
|
-
// The SDK,
|
|
22
|
-
// `
|
|
23
|
-
// takes the services, with what they need beside them).
|
|
5
|
+
// The SDK, plus additions. `Client`, `SendClient`, `Target`, `serve` and
|
|
6
|
+
// `connect` replace the SDK exports of the same name.
|
|
24
7
|
export * from '@restatedev/restate-sdk';
|
|
25
8
|
export { sessionObject, } from './object.js';
|
|
26
|
-
// A handle on what another deployment serves: named and typed, not implemented here.
|
|
27
9
|
export { remote } from './calls.js';
|
|
28
|
-
//
|
|
29
|
-
// them; `connect`, the same for Restate Cloud (the SDK's own leaves them out);
|
|
30
|
-
// and `served`, the services with what they need, for an endpoint of your own
|
|
31
|
-
// — which runs them on the VM too (`endpoint.ts`).
|
|
10
|
+
// See serve.ts.
|
|
32
11
|
export { connect, serve, served } from './serve.js';
|
|
33
12
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,iEAAiE;AACjE,gFAAgF;AAChF,iBAAiB;AAEjB,yEAAyE;AACzE,sDAAsD;AACtD,cAAc,yBAAyB,CAAC;AAGxC,OAAO,EACL,aAAa,GAOd,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,gBAAgB;AAChB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export * as sdk from '@restatedev/restate-sdk';
|
|
2
2
|
export { ensureSchemas, Schema } from './schema.ts';
|
|
3
|
-
export { asDatabase, lazyDatabase, database,
|
|
4
|
-
export type
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
3
|
+
export { asDatabase, lazyDatabase, database, Attempt } from './session.ts';
|
|
4
|
+
export { open, type Connection, type Store, type ConnectionTransaction, type Stoppable, type Suspendable, type Working, } from './database.ts';
|
|
5
|
+
export { AttemptDriver, AttemptShutDown } from './driver.ts';
|
|
6
|
+
export type { AttemptHost } from './host.ts';
|
|
7
|
+
export { locateScopes, type Scope, Stop } from './stop.ts';
|
|
8
|
+
export { Vm } from './vm.ts';
|
|
9
|
+
export { served } from './serve.ts';
|
|
10
|
+
export { configOf, contextOf, HEAD_KEY, invoke, openScope, withAttempt } from './object.ts';
|
|
11
|
+
export { goAway, CONTENT_TYPE } from './handler.ts';
|
|
12
|
+
export { manifestV6 } from './endpoint.ts';
|
|
13
|
+
export { invocationState, readSignal, sendSignal, flush, type InvocationState } from './object.ts';
|
|
14
14
|
//# sourceMappingURL=internal.d.ts.map
|
package/dist/internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EACL,IAAI,EACJ,KAAK,UAAU,EACf,KAAK,KAAK,EACV,KAAK,qBAAqB,EAC1B,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,OAAO,GACb,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC7D,YAAY,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,OAAO,EAAE,YAAY,EAAE,KAAK,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAI5F,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC"}
|