@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/src/scope.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
// An attempt's scope: what its code keeps for the attempt (an agent's turn,
|
|
2
|
-
// the calls of its tools...), which its context holds and which ends with it.
|
|
3
|
-
// A retry gets a context, and so a scope, of its own. A module holds only the
|
|
4
|
-
// key of what it keeps (`ScopeKey`), never the state.
|
|
5
|
-
import type * as restate from '@restatedev/restate-sdk';
|
|
6
|
-
import { Link } from './link.ts';
|
|
7
|
-
import type { SessionContext, ViewContext } from './object.ts';
|
|
8
|
-
|
|
9
|
-
/** A context of an attempt: a handler's or a view's. */
|
|
10
|
-
type Context = SessionContext | ViewContext;
|
|
11
|
-
|
|
12
|
-
/** The scope's values, which only {@link ScopeKey} reaches. */
|
|
13
|
-
const VALUES = Symbol('values');
|
|
14
|
-
|
|
15
|
-
/** An attempt's own, as @restatedev/sessions made it, and what its code keeps for it ({@link ScopeKey}). */
|
|
16
|
-
export class Scope {
|
|
17
|
-
/** The SDK's context of the attempt. */
|
|
18
|
-
readonly sdk: restate.ObjectContext | restate.ObjectSharedContext;
|
|
19
|
-
/** Whether its handler has `explicitCancellation: true`. */
|
|
20
|
-
readonly explicitCancellation: boolean;
|
|
21
|
-
/** The definition of the session object whose handler or view it runs, if any. */
|
|
22
|
-
readonly definition: object | undefined;
|
|
23
|
-
readonly [VALUES] = new Map<ScopeKey<unknown>, unknown>();
|
|
24
|
-
|
|
25
|
-
constructor(
|
|
26
|
-
sdk: restate.ObjectContext | restate.ObjectSharedContext,
|
|
27
|
-
{ explicitCancellation = false, definition = undefined as object | undefined } = {},
|
|
28
|
-
) {
|
|
29
|
-
this.sdk = sdk;
|
|
30
|
-
this.explicitCancellation = explicitCancellation;
|
|
31
|
-
this.definition = definition;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** The attempt's scope, on its context. */
|
|
36
|
-
const SCOPE = new Link<Scope>('scope');
|
|
37
|
-
|
|
38
|
-
/** `context`, holding `scope`: as it is made, before it is frozen. */
|
|
39
|
-
export const holding = <C extends Context>(context: C, scope: Scope): C => SCOPE.on(context, scope);
|
|
40
|
-
|
|
41
|
-
/** The scope of the attempt whose context `ctx` is, if it is one of @restatedev/sessions. */
|
|
42
|
-
export const scopeOf = (ctx: Context): Scope | undefined => SCOPE.of(ctx);
|
|
43
|
-
|
|
44
|
-
/** A kind of state an attempt's code keeps, by its context: its key in the attempt's scope. */
|
|
45
|
-
export class ScopeKey<T> {
|
|
46
|
-
/** What it is, for an error. */
|
|
47
|
-
private readonly what: string;
|
|
48
|
-
|
|
49
|
-
constructor(what: string) {
|
|
50
|
-
this.what = what;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
get(ctx: Context): T | undefined {
|
|
54
|
-
return this.values(ctx).get(this) as T | undefined;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
set(ctx: Context, value: T): void {
|
|
58
|
-
this.values(ctx).set(this, value);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
delete(ctx: Context): void {
|
|
62
|
-
this.values(ctx).delete(this);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** The attempt's, made by `make` the first time. */
|
|
66
|
-
of(ctx: Context, make: () => T): T {
|
|
67
|
-
const values = this.values(ctx);
|
|
68
|
-
if (!values.has(this)) values.set(this, make());
|
|
69
|
-
return values.get(this) as T;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
private values(ctx: Context): Map<ScopeKey<unknown>, unknown> {
|
|
73
|
-
const scope = scopeOf(ctx);
|
|
74
|
-
if (scope === undefined)
|
|
75
|
-
throw new TypeError(`${this.what} takes the context of a session object's handler or view`);
|
|
76
|
-
return scope[VALUES];
|
|
77
|
-
}
|
|
78
|
-
}
|