@restatedev/sessions 0.0.0 → 0.2.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.
Files changed (53) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +480 -2
  3. package/dist/calls.d.ts +72 -0
  4. package/dist/calls.d.ts.map +1 -0
  5. package/dist/calls.js +86 -0
  6. package/dist/calls.js.map +1 -0
  7. package/dist/database.d.ts +169 -0
  8. package/dist/database.d.ts.map +1 -0
  9. package/dist/database.js +264 -0
  10. package/dist/database.js.map +1 -0
  11. package/dist/index.d.ts +7 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +28 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/internal.d.ts +10 -0
  16. package/dist/internal.d.ts.map +1 -0
  17. package/dist/internal.js +13 -0
  18. package/dist/internal.js.map +1 -0
  19. package/dist/object.d.ts +162 -0
  20. package/dist/object.d.ts.map +1 -0
  21. package/dist/object.js +235 -0
  22. package/dist/object.js.map +1 -0
  23. package/dist/platform.d.ts +5 -0
  24. package/dist/platform.d.ts.map +1 -0
  25. package/dist/platform.js +15 -0
  26. package/dist/platform.js.map +1 -0
  27. package/dist/schema.d.ts +35 -0
  28. package/dist/schema.d.ts.map +1 -0
  29. package/dist/schema.js +118 -0
  30. package/dist/schema.js.map +1 -0
  31. package/dist/selector.d.ts +86 -0
  32. package/dist/selector.d.ts.map +1 -0
  33. package/dist/selector.js +196 -0
  34. package/dist/selector.js.map +1 -0
  35. package/dist/serve.d.ts +21 -0
  36. package/dist/serve.d.ts.map +1 -0
  37. package/dist/serve.js +49 -0
  38. package/dist/serve.js.map +1 -0
  39. package/dist/session.d.ts +167 -0
  40. package/dist/session.d.ts.map +1 -0
  41. package/dist/session.js +547 -0
  42. package/dist/session.js.map +1 -0
  43. package/package.json +40 -5
  44. package/src/calls.ts +197 -0
  45. package/src/database.ts +392 -0
  46. package/src/index.ts +38 -0
  47. package/src/internal.ts +14 -0
  48. package/src/object.ts +368 -0
  49. package/src/platform.ts +15 -0
  50. package/src/schema.ts +162 -0
  51. package/src/selector.ts +253 -0
  52. package/src/serve.ts +54 -0
  53. package/src/session.ts +663 -0
@@ -0,0 +1,86 @@
1
+ /** A future of the VM, as `do_progress` takes it. */
2
+ export type UnresolvedFuture = {
3
+ Single: number;
4
+ } | {
5
+ FirstCompleted: UnresolvedFuture[];
6
+ } | {
7
+ AllCompleted: UnresolvedFuture[];
8
+ } | {
9
+ FirstSucceededOrAllFailed: UnresolvedFuture[];
10
+ } | {
11
+ AllSucceededOrFirstFailed: UnresolvedFuture[];
12
+ } | {
13
+ Unknown: UnresolvedFuture[];
14
+ };
15
+ /** What `do_progress` returns. */
16
+ export type DoProgressResult = 'AnyCompleted' | 'WaitExternalProgress' | {
17
+ ExecuteRun: number;
18
+ } | 'CancelSignalReceived' | {
19
+ EphemeralNotificationReady: number;
20
+ };
21
+ /** What the selector needs of a promise: the shape of InternalRestatePromise. */
22
+ export interface Selectable {
23
+ /** Takes the result if it is ready, and settles the promise with it. */
24
+ tryComplete(): Promise<void>;
25
+ /** What it still waits for, or null once settled. */
26
+ unresolvedFuture(): UnresolvedFuture | null;
27
+ /** Rejects it with a CancelledError. */
28
+ tryCancel(): void;
29
+ }
30
+ /** What the selector needs of the invocation. */
31
+ export interface SelectorDriver {
32
+ doProgress(future: UnresolvedFuture): DoProgressResult;
33
+ /** Writes out what the VM has buffered. */
34
+ flushOutput(): Promise<void>;
35
+ /** Resolves on the next signal of external progress (input, a finished run, a registration). */
36
+ awaitExternalProgress(): Promise<void>;
37
+ /** Signals external progress. */
38
+ wake(): void;
39
+ executeRun(handle: number): void;
40
+ completeEphemeral(completionId: number): Promise<void>;
41
+ /** The attempt cannot go on: suspension, or an error. */
42
+ onError(e: unknown): void;
43
+ }
44
+ /**
45
+ * One loop that drives every pending promise of an invocation, so that the
46
+ * invocation has a single await point however many promises user code awaits
47
+ * at once, with its own combinators or none.
48
+ *
49
+ * A promise is registered once and stays until it settles. The loop settles
50
+ * whatever is ready, then asks the VM for progress on the first of all the
51
+ * pending promises to complete: so a suspension waits for any of them, a
52
+ * pending run starts whichever promise is awaited first, and a cancellation
53
+ * reaches all of them. Registering wakes the loop, so a promise registered
54
+ * while it waits is part of the next await point. An ephemeral command (a
55
+ * state get left out of the journal) is registered by its completion id: the
56
+ * VM reports its notification ahead of any future, and the loop goes on while
57
+ * one is in flight, even with no promise pending. The loop runs while
58
+ * something is pending, and is the only one waiting for external progress.
59
+ */
60
+ export declare class PromiseSelector {
61
+ private readonly pending;
62
+ private readonly ephemeral;
63
+ private running;
64
+ private closed;
65
+ private waiting;
66
+ private readonly driver;
67
+ constructor(driver: SelectorDriver);
68
+ register(promise: Selectable): void;
69
+ /** An ephemeral command's completion id, until its notification is ready. */
70
+ registerEphemeral(completionId: number): void;
71
+ private start;
72
+ /** Stops the loop (it finds nothing pending), at the end of the attempt. */
73
+ close(): void;
74
+ private wake;
75
+ /** The promises still pending, for tests. */
76
+ get size(): number;
77
+ private loop;
78
+ }
79
+ /**
80
+ * Drive every promise that the invocation of `ctx` (the SDK's context, not a
81
+ * proxy of it) awaits from here on with one selector. The returned function
82
+ * stops it, at the end of the attempt, and gives the invocation back its
83
+ * own loops.
84
+ */
85
+ export declare function hookSelector(ctx: object): () => void;
86
+ //# sourceMappingURL=selector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selector.d.ts","sourceRoot":"","sources":["../src/selector.ts"],"names":[],"mappings":"AAkBA,qDAAqD;AACrD,MAAM,MAAM,gBAAgB,GACxB;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAClB;IAAE,cAAc,EAAE,gBAAgB,EAAE,CAAA;CAAE,GACtC;IAAE,YAAY,EAAE,gBAAgB,EAAE,CAAA;CAAE,GACpC;IAAE,yBAAyB,EAAE,gBAAgB,EAAE,CAAA;CAAE,GACjD;IAAE,yBAAyB,EAAE,gBAAgB,EAAE,CAAA;CAAE,GACjD;IAAE,OAAO,EA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OAAO,EAAE,UAAU,GAAG,IAAI,CAIlC;IAED,6EAA6E;IAC7E,iBAAiB,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAI5C;IAED,OAAO,CAAC,KAAK;IASb,4EAA4E;IAC5E,KAAK,IAAI,IAAI,CAMZ;IAKD,OAAO,CAAC,IAAI;IAMZ,6CAA6C;IAC7C,IAAI,IAAI,IAAI,MAAM,CAEjB;YAEa,IAAI;CA2DnB;AAyBD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,IAAI,CA0BpD"}
@@ -0,0 +1,196 @@
1
+ // Concurrent awaits in a handler with SQL: one loop, the selector, drives
2
+ // every promise the handler awaits.
3
+ //
4
+ // The published SDK drives each awaited RestatePromise with a loop of its own,
5
+ // and only one of them may wait for progress from the server at a time
6
+ // (`ExternalProgressChannel.awaitNext`): two promises awaited at once that
7
+ // both need the server, such as two state reads with lazy state, fail the
8
+ // attempt with "awaitNext already pending". With journal replay, that order of
9
+ // awaits is part of what a replay must match; with explicit recovery nothing
10
+ // is replayed, so a handler with SQL hands every awaited promise to one loop,
11
+ // which asks the VM about all of them at once (`hookSelector`). The hook
12
+ // replaces the invocation's `promisesExecutor.doProgress`: it relies on the
13
+ // SDK's internals, as of the version this package pins (1.18.2).
14
+ //
15
+ // TODO: drop the selector, and the pin, once an SDK release lets a handler
16
+ // with explicit recovery await concurrently.
17
+ import { setImmediate } from 'node:timers/promises';
18
+ /**
19
+ * One loop that drives every pending promise of an invocation, so that the
20
+ * invocation has a single await point however many promises user code awaits
21
+ * at once, with its own combinators or none.
22
+ *
23
+ * A promise is registered once and stays until it settles. The loop settles
24
+ * whatever is ready, then asks the VM for progress on the first of all the
25
+ * pending promises to complete: so a suspension waits for any of them, a
26
+ * pending run starts whichever promise is awaited first, and a cancellation
27
+ * reaches all of them. Registering wakes the loop, so a promise registered
28
+ * while it waits is part of the next await point. An ephemeral command (a
29
+ * state get left out of the journal) is registered by its completion id: the
30
+ * VM reports its notification ahead of any future, and the loop goes on while
31
+ * one is in flight, even with no promise pending. The loop runs while
32
+ * something is pending, and is the only one waiting for external progress.
33
+ */
34
+ export class PromiseSelector {
35
+ pending = new Set();
36
+ // The completion ids of the ephemeral commands in flight.
37
+ ephemeral = new Set();
38
+ running = false;
39
+ closed = false;
40
+ // Between the VM's WaitExternalProgress and the next external progress.
41
+ waiting = false;
42
+ driver;
43
+ constructor(driver) {
44
+ this.driver = driver;
45
+ }
46
+ register(promise) {
47
+ if (this.closed || this.pending.has(promise))
48
+ return;
49
+ this.pending.add(promise);
50
+ this.start();
51
+ }
52
+ /** An ephemeral command's completion id, until its notification is ready. */
53
+ registerEphemeral(completionId) {
54
+ if (this.closed)
55
+ return;
56
+ this.ephemeral.add(completionId);
57
+ this.start();
58
+ }
59
+ start() {
60
+ if (this.running) {
61
+ this.wake();
62
+ }
63
+ else {
64
+ this.running = true;
65
+ void this.loop();
66
+ }
67
+ }
68
+ /** Stops the loop (it finds nothing pending), at the end of the attempt. */
69
+ close() {
70
+ if (this.closed)
71
+ return;
72
+ this.closed = true;
73
+ this.pending.clear();
74
+ this.ephemeral.clear();
75
+ if (this.running)
76
+ this.wake();
77
+ }
78
+ // Only a waiting loop needs waking, once: any other picks up the change on
79
+ // its next pass. (Waking it otherwise would buffer a signal per promise, and
80
+ // as many needless passes.)
81
+ wake() {
82
+ if (!this.waiting)
83
+ return;
84
+ this.waiting = false;
85
+ this.driver.wake();
86
+ }
87
+ /** The promises still pending, for tests. */
88
+ get size() {
89
+ return this.pending.size + this.ephemeral.size;
90
+ }
91
+ async loop() {
92
+ try {
93
+ await this.driver.flushOutput();
94
+ for (;;) {
95
+ // Settle what is ready.
96
+ for (const promise of this.pending) {
97
+ await promise.tryComplete();
98
+ }
99
+ // Let what that settled run, and register what it awaits next, so
100
+ // that one check covers them (a combinator also flags itself
101
+ // completed in a .finally, a tick late). An optimization: what is
102
+ // registered later wakes the loop anyway.
103
+ await setImmediate();
104
+ const futures = [];
105
+ for (const promise of this.pending) {
106
+ const future = promise.unresolvedFuture();
107
+ if (future === null) {
108
+ this.pending.delete(promise);
109
+ }
110
+ else {
111
+ futures.push(future);
112
+ }
113
+ }
114
+ if (futures.length === 0 && this.ephemeral.size === 0)
115
+ return;
116
+ // With only ephemeral commands in flight, no future: the VM reports
117
+ // their notifications, or waits for input.
118
+ const result = this.driver.doProgress(futures.length === 1 ? futures[0] : { FirstCompleted: futures });
119
+ if (result === 'AnyCompleted') {
120
+ continue;
121
+ }
122
+ else if (result === 'WaitExternalProgress') {
123
+ // From here, in the same turn as the check: what is registered
124
+ // after it is not part of it.
125
+ this.waiting = true;
126
+ await this.driver.flushOutput();
127
+ await this.driver.awaitExternalProgress();
128
+ this.waiting = false;
129
+ }
130
+ else if (result === 'CancelSignalReceived') {
131
+ // Reaches every pending promise; what is awaited after it is not cancelled.
132
+ for (const promise of this.pending)
133
+ promise.tryCancel();
134
+ this.pending.clear();
135
+ }
136
+ else if ('EphemeralNotificationReady' in result) {
137
+ this.ephemeral.delete(result.EphemeralNotificationReady);
138
+ await this.driver.completeEphemeral(result.EphemeralNotificationReady);
139
+ }
140
+ else {
141
+ this.driver.executeRun(result.ExecuteRun);
142
+ // Let the run start, then come back.
143
+ await setImmediate();
144
+ }
145
+ }
146
+ }
147
+ catch (e) {
148
+ this.close();
149
+ this.driver.onError(e);
150
+ }
151
+ finally {
152
+ // Decided with nothing pending, in the same turn: a registration from
153
+ // here on starts a new loop.
154
+ this.running = false;
155
+ }
156
+ }
157
+ }
158
+ const FIELDS = [
159
+ 'coreVm',
160
+ 'outputPump',
161
+ 'externalProgressChannel',
162
+ 'runClosuresTracker',
163
+ 'ephemeralRequestTracker',
164
+ 'errorCallback',
165
+ ];
166
+ /**
167
+ * Drive every promise that the invocation of `ctx` (the SDK's context, not a
168
+ * proxy of it) awaits from here on with one selector. The returned function
169
+ * stops it, at the end of the attempt, and gives the invocation back its
170
+ * own loops.
171
+ */
172
+ export function hookSelector(ctx) {
173
+ const executor = ctx.promisesExecutor;
174
+ const missing = executor ? FIELDS.filter((field) => executor[field] === undefined) : ['promisesExecutor'];
175
+ if (missing.length > 0 || typeof executor?.coreVm.do_progress !== 'function') {
176
+ throw new Error(`@restatedev/sessions drives a handler's promises through the SDK's internals, which this SDK version does not have ` +
177
+ `(${missing.join(', ') || 'coreVm.do_progress'}): use the @restatedev/restate-sdk that @restatedev/sessions pins`);
178
+ }
179
+ const { coreVm, outputPump, externalProgressChannel, runClosuresTracker, ephemeralRequestTracker } = executor;
180
+ const selector = new PromiseSelector({
181
+ doProgress: (future) => coreVm.do_progress(future),
182
+ flushOutput: () => outputPump.awaitNextProgress(),
183
+ awaitExternalProgress: () => externalProgressChannel.awaitNext(),
184
+ wake: () => externalProgressChannel.signal(),
185
+ executeRun: (handle) => runClosuresTracker.executeRun(handle),
186
+ completeEphemeral: (completionId) => ephemeralRequestTracker.complete(completionId, coreVm.take_ephemeral_notification(completionId)),
187
+ onError: (e) => executor.errorCallback(e),
188
+ });
189
+ // An own property, over the class's method: removing it gives the method back.
190
+ executor.doProgress = async (promise) => selector.register(promise);
191
+ return () => {
192
+ selector.close();
193
+ delete executor.doProgress;
194
+ };
195
+ }
196
+ //# sourceMappingURL=selector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selector.js","sourceRoot":"","sources":["../src/selector.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,oCAAoC;AACpC,EAAE;AACF,+EAA+E;AAC/E,uEAAuE;AACvE,2EAA2E;AAC3E,0EAA0E;AAC1E,+EAA+E;AAC/E,6EAA6E;AAC7E,8EAA8E;AAC9E,yEAAyE;AACzE,4EAA4E;AAC5E,iEAAiE;AACjE,EAAE;AACF,2EAA2E;AAC3E,6CAA6C;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AA4CpD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,eAAe;IACT,OAAO,GAAG,IAAI,GAAG,EAAc,CAAC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;QAC7D,iBAAiB,EAAE,CAAC,YAAY,EAAE,EAAE,CAClC,uBAAuB,CAAC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,2BAA2B,CAAC,YAAY,CAAC,CAAC;QAClG,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC;KAC1C,CAAC,CAAC;IACH,+EAA+E;IAC/E,QAAQ,CAAC,UAAU,GAAG,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IACpE,OAAO,GAAG,EAAE;QACV,QAAQ,CAAC,KAAK,EAAE,CAAC;QACjB,OAAQ,QAA8B,CAAC,UAAU,CAAC;IACpD,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,21 @@
1
+ import * as restate from '@restatedev/restate-sdk';
2
+ type Service = restate.ServeOptions['services'][number];
3
+ /**
4
+ * `definition`, which needs `services` served beside it: {@link serve}
5
+ * serves them too. For a library whose objects call one of its own (an
6
+ * agent's `signals`, say).
7
+ */
8
+ export declare const needing: <D extends object>(definition: D, services: () => Service[]) => D;
9
+ /**
10
+ * Serve `services` on PORT (default 9080), with the services they need
11
+ * beside them, each once. RESTATE_SERVE_ONLY, names separated by commas
12
+ * (`triage,planner,signals`), serves only those of them: one program (or
13
+ * image), deployed in parts.
14
+ *
15
+ * await restate.serve(notes, orders);
16
+ */
17
+ export declare const serve: (...services: Service[]) => Promise<number>;
18
+ /** What {@link serve} serves of `services`: each with what it needs beside it, once, of those `names` names. */
19
+ export declare function served(services: Service[], names?: string): Service[];
20
+ export {};
21
+ //# sourceMappingURL=serve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,OAAO,MAAM,yBAAyB,CAAC;AAEnD,KAAK,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAKxD;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,MAAM,cAAc,CAAC,YAAY,MAAM,OAAO,EAAE,KAAG,CACtB,CAAC;AAEhE;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,gBAAiB,OAAO,EAAE,oBAC2E,CAAC;AAExH,gHAAgH;AAChH,wBAAgB,MAAM,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,EAAE,CASrE"}
package/dist/serve.js ADDED
@@ -0,0 +1,49 @@
1
+ // `serve`: the services of a program, on PORT, with what they need beside
2
+ // them (a library's objects, such as @restatedev/agents' `signals`).
3
+ import * as restate from '@restatedev/restate-sdk';
4
+ /** Where a definition keeps the services it needs served beside it: see {@link needing}. */
5
+ const NEEDS = Symbol.for('restate-sessions.needs');
6
+ /**
7
+ * `definition`, which needs `services` served beside it: {@link serve}
8
+ * serves them too. For a library whose objects call one of its own (an
9
+ * agent's `signals`, say).
10
+ */
11
+ export const needing = (definition, services) => Object.defineProperty(definition, NEEDS, { value: services });
12
+ /**
13
+ * Serve `services` on PORT (default 9080), with the services they need
14
+ * beside them, each once. RESTATE_SERVE_ONLY, names separated by commas
15
+ * (`triage,planner,signals`), serves only those of them: one program (or
16
+ * image), deployed in parts.
17
+ *
18
+ * await restate.serve(notes, orders);
19
+ */
20
+ export const serve = (...services) => restate.serve({ services: served(services, process.env.RESTATE_SERVE_ONLY), port: Number(process.env.PORT ?? 9080) });
21
+ /** What {@link serve} serves of `services`: each with what it needs beside it, once, of those `names` names. */
22
+ export function served(services, names) {
23
+ const all = new Map();
24
+ const add = (service) => {
25
+ if (all.has(service.name))
26
+ return;
27
+ all.set(service.name, service);
28
+ for (const needed of service[NEEDS]?.() ?? [])
29
+ add(needed);
30
+ };
31
+ services.forEach(add);
32
+ return only([...all.values()], names);
33
+ }
34
+ /** The `services` that `names` (comma separated) names, or all of them without names; a name of none is an error. */
35
+ function only(services, names) {
36
+ const wanted = (names ?? '')
37
+ .split(',')
38
+ .map((name) => name.trim())
39
+ .filter(Boolean);
40
+ if (wanted.length === 0)
41
+ return services;
42
+ const known = services.map((s) => s.name);
43
+ const unknown = wanted.filter((name) => !known.includes(name));
44
+ if (unknown.length > 0) {
45
+ throw new Error(`RESTATE_SERVE_ONLY names ${unknown.join(', ')}: the services are ${known.join(', ')}`);
46
+ }
47
+ return services.filter((s) => wanted.includes(s.name));
48
+ }
49
+ //# sourceMappingURL=serve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve.js","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,qEAAqE;AACrE,OAAO,KAAK,OAAO,MAAM,yBAAyB,CAAC;AAInD,4FAA4F;AAC5F,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;AAEnD;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAmB,UAAa,EAAE,QAAyB,EAAK,EAAE,CACvF,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;AAEhE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,GAAG,QAAmB,EAAE,EAAE,CAC9C,OAAO,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC;AAExH,gHAAgH;AAChH,MAAM,UAAU,MAAM,CAAC,QAAmB,EAAE,KAAc;IACxD,MAAM,GAAG,GAAG,IAAI,GAAG,EAAmB,CAAC;IACvC,MAAM,GAAG,GAAG,CAAC,OAAgB,EAAE,EAAE;QAC/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AAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACzD,CAAC"}
@@ -0,0 +1,167 @@
1
+ import type * as restate from '@restatedev/restate-sdk';
2
+ import { type Serde } from '@restatedev/restate-sdk-core';
3
+ import { type Row, type Connection, type DatabaseWriter, type SqlParam, type DatabaseReader, type SqlValue, type Store } from './database.ts';
4
+ import { type Send } from './calls.ts';
5
+ export type { DatabaseReader, DatabaseWriter, Row, SqlParam, SqlValue };
6
+ /**
7
+ * The session's database, `ctx.db`, for the whole handler: each statement
8
+ * outside {@link transaction} is its own transaction. Calls run one at a
9
+ * time, in call order.
10
+ */
11
+ export interface Database extends DatabaseWriter {
12
+ /**
13
+ * Run `body` as one transaction: it commits when `body` resolves, and rolls
14
+ * back when it rejects. It holds the database: other calls wait until it
15
+ * ends, and a call to the database from inside `body` is refused, as it
16
+ * would wait for `body`. So `body` uses the `tx` it gets, which is invalid
17
+ * once `body` settles.
18
+ */
19
+ transaction<T>(body: (tx: Transaction) => Promise<T>): Promise<T>;
20
+ }
21
+ /** One transaction of a {@link Database}: its SQL, and the sends it commits with. */
22
+ export interface Transaction extends DatabaseWriter {
23
+ /**
24
+ * Sends made right after the transaction commits, and never if it rolls
25
+ * back. Each has the idempotency key it is given, or else one of the
26
+ * transaction (`transaction/<id>/<index>`), so a send an attempt makes
27
+ * again is dropped.
28
+ */
29
+ readonly send: Send;
30
+ }
31
+ /** What the session needs of the handler's context. */
32
+ export interface SqlHost {
33
+ /** A shared handler's: it reads beside the exclusive one, and stores nothing. */
34
+ readonly shared: boolean;
35
+ readonly key: string;
36
+ /** Rejects when the attempt ends (suspended, or aborted). */
37
+ readonly invocationEndPromise: {
38
+ readonly promise: Promise<unknown>;
39
+ };
40
+ readonly defaultSerde: Serde<any>;
41
+ request(): {
42
+ readonly id: string;
43
+ readonly target: {
44
+ readonly service: string;
45
+ };
46
+ };
47
+ get(name: string, serde: Serde<Uint8Array>, options: restate.EntryOptions): PromiseLike<Uint8Array | null>;
48
+ set(name: string, value: Uint8Array, serde: Serde<Uint8Array>, options: restate.EntryOptions): void;
49
+ clear(name: string, options: restate.EntryOptions): void;
50
+ /** The object's state keys. */
51
+ stateKeys(): PromiseLike<string[]>;
52
+ run(name: string, action: () => void): PromiseLike<void>;
53
+ genericSend(send: restate.GenericSend<Uint8Array>): unknown;
54
+ }
55
+ type Wrap = (store: Store) => Store;
56
+ /** Wrap each object's store, such as for fault injection in tests. */
57
+ export declare function setStoreWrapper(wrap: Wrap): void;
58
+ /**
59
+ * `connection`, opened without the SDK (`open`), as a handler's `ctx.db`:
60
+ * for a library's tests, and tools. Its transactions send nothing, and a
61
+ * library's schema applies to it (`Schema.ensure`).
62
+ */
63
+ export declare function asDatabase(connection: Connection): Database;
64
+ /**
65
+ * Empty the key's database in `tx`, a transaction of an exclusive handler's
66
+ * `ctx.db`: every table, view, index and trigger is dropped, the schemas are
67
+ * applied again (the object's, and the libraries' the attempt applied), and
68
+ * the outbox stays. It commits with `tx`: what `tx` writes after it are the
69
+ * new database's first rows, in the same commit.
70
+ */
71
+ export declare function reset(tx: Transaction): Promise<void>;
72
+ /**
73
+ * A database that `opener` opens on its first call, as a handler's `ctx.db`
74
+ * opens: for tests, which give each attempt one over the same state.
75
+ */
76
+ export declare function lazyDatabase(opener: () => Promise<Database>): Database;
77
+ /** How a handler ended. */
78
+ type Outcome<T> = {
79
+ value: T;
80
+ } | {
81
+ error: unknown;
82
+ };
83
+ /**
84
+ * The database `name` of the key, apart from the object's own (`ctx.db`, of
85
+ * the attempt whose session `db` is): for a library whose tables must be
86
+ * alone in their database, such as OpenCode's. It opens on its first use,
87
+ * and ends with the attempt, as `ctx.db` does. A name is 1 to 64 letters,
88
+ * digits, `_`, `-` or `.`.
89
+ */
90
+ export declare function database(db: Database, name: string): Database;
91
+ /**
92
+ * An attempt's SQL session: opened on its first use, or as an exclusive
93
+ * attempt starts ({@link openNow}), shared by everything the handler does,
94
+ * and saved when the handler ends ({@link end}). With `name`, of the key's database `name`
95
+ * ({@link database}), which has neither the object's schema nor an outbox.
96
+ */
97
+ export declare class Attempt {
98
+ /** `ctx.db`. */
99
+ readonly db: Database;
100
+ private readonly ctx;
101
+ private readonly name;
102
+ /** The key's other databases this attempt opened, by name. */
103
+ private readonly databases;
104
+ /** The session, from its first use on. */
105
+ private session;
106
+ /** The ids of the outbox's transactions this attempt made the sends of. */
107
+ private readonly made;
108
+ /** The schemas this attempt's database has all the steps of. */
109
+ private readonly ensured;
110
+ private ended;
111
+ /** Opened when the attempt started ({@link openNow}), and no call has seen how it went yet. */
112
+ private unseenOpen;
113
+ /** Stops closing the session when the attempt ends. */
114
+ private keepOpen;
115
+ /** The invocation's cancellation, once a request of the session failed of it. */
116
+ private cancelled;
117
+ constructor(ctx: SqlHost, name?: string);
118
+ /** The key's database `name`, in this attempt: see {@link database}. */
119
+ database(name: string): Database;
120
+ /**
121
+ * One transaction of the session, whose sends are made once it commits,
122
+ * and kept in the outbox until they are stored: `body` gets its SQL, and
123
+ * `record`, which records a send.
124
+ */
125
+ private withSends;
126
+ /**
127
+ * The handler ended with `outcome`: an SQL error that escaped it becomes
128
+ * terminal, then the outbox is emptied, and the session is saved. One that
129
+ * a storage error ended closes now, rather than when it is collected.
130
+ */
131
+ end<T>(outcome: Outcome<T>): Promise<T>;
132
+ /**
133
+ * Open the session now, as the attempt starts, rather than on its first
134
+ * call: the open makes the sends a crashed attempt committed and left
135
+ * unmade, which must not wait for a handler that uses the database.
136
+ */
137
+ openNow(): void;
138
+ /** Empty the database in the transaction `handle` ({@link reset}), and apply the schemas this attempt applied again. */
139
+ private reset;
140
+ /**
141
+ * `call` on the session, opening it on the first; its failure as the
142
+ * handler fails with it, or the invocation's cancellation, if a request of
143
+ * the session failed of it: a call it ended fails with a CancelledError,
144
+ * as any of the handler's awaits does.
145
+ */
146
+ private call;
147
+ /** Apply the steps of `schemas` that the database lacks, each schema once per attempt. */
148
+ private ensureSchemas;
149
+ /** Make the sends of a committed transaction: each with an idempotency key of the transaction (or its own), so that making them again is dropped. */
150
+ private make;
151
+ /** The outbox as committed, but the transactions this attempt made the sends of: a commit made after them stores them first. */
152
+ private unstored;
153
+ /**
154
+ * Empty the outbox, so that a later open does not make its sends again: a
155
+ * commit after them, which stores them first.
156
+ */
157
+ private flush;
158
+ /** The session, opening it on the first call. */
159
+ private opened;
160
+ private start;
161
+ private endSession;
162
+ /** Empty the outbox and save the session; one a storage error ended only closes. */
163
+ private save;
164
+ }
165
+ /** Run `handler`, then end `attempt`'s SQL session, if it opened one (see {@link Attempt.end}). */
166
+ export declare function withAttempt<T>(handler: () => Promise<T>, attempt: Attempt): Promise<T>;
167
+ //# sourceMappingURL=session.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,OAAO,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAA4B,KAAK,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACpF,OAAO,EAEL,KAAK,GAAG,EAGR,KAAK,UAAU,EACf,KAAK,cAAc,EACnB,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,KAAK,QAAQ,EACb,KAAK,KAAK,EAEX,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,KAAK,IAAI,EAAU,MAAM,YAAY,CAAC;AAE/C,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;AAExE;;;;GAIG;AACH,MAAM,WAAW,QAAS,SAAQ,cAAc;IAC9C;;;;;;OAMG;IACH,WAAW,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACnE;AAED,qFAAqF;AACrF,MAAM,WAAW,WAAY,SAAQ,cAAc;IACjD;;;;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