@restatedev/sessions 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +474 -2
- package/dist/calls.d.ts +72 -0
- package/dist/calls.d.ts.map +1 -0
- package/dist/calls.js +86 -0
- package/dist/calls.js.map +1 -0
- package/dist/database.d.ts +169 -0
- package/dist/database.d.ts.map +1 -0
- package/dist/database.js +264 -0
- package/dist/database.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +9 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +12 -0
- package/dist/internal.js.map +1 -0
- package/dist/object.d.ts +162 -0
- package/dist/object.d.ts.map +1 -0
- package/dist/object.js +235 -0
- package/dist/object.js.map +1 -0
- package/dist/platform.d.ts +5 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/platform.js +15 -0
- package/dist/platform.js.map +1 -0
- package/dist/schema.d.ts +35 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +118 -0
- package/dist/schema.js.map +1 -0
- package/dist/selector.d.ts +86 -0
- package/dist/selector.d.ts.map +1 -0
- package/dist/selector.js +196 -0
- package/dist/selector.js.map +1 -0
- package/dist/session.d.ts +167 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +547 -0
- package/dist/session.js.map +1 -0
- package/package.json +46 -3
- package/src/calls.ts +197 -0
- package/src/database.ts +392 -0
- package/src/index.ts +35 -0
- package/src/internal.ts +13 -0
- package/src/object.ts +368 -0
- package/src/platform.ts +15 -0
- package/src/schema.ts +162 -0
- package/src/selector.ts +253 -0
- package/src/session.ts +663 -0
package/dist/object.d.ts
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import * as restate from '@restatedev/restate-sdk';
|
|
2
|
+
import type { VirtualObjectDefinition } from '@restatedev/restate-sdk-core';
|
|
3
|
+
import { type Rpc, type Send } from './calls.ts';
|
|
4
|
+
import type { DatabaseReader } from './database.ts';
|
|
5
|
+
import { type Step } from './schema.ts';
|
|
6
|
+
import { type Database, type SqlHost } from './session.ts';
|
|
7
|
+
/**
|
|
8
|
+
* The context of a session object's handler. A handler runs in attempts:
|
|
9
|
+
* Restate starts a new one after a crash, a retryable error or a
|
|
10
|
+
* suspension, and each runs the handler from its first line, finding what
|
|
11
|
+
* the attempts before it committed. Its operations can be awaited together
|
|
12
|
+
* (`Promise.all`, `Promise.race`).
|
|
13
|
+
*/
|
|
14
|
+
export interface SessionContext {
|
|
15
|
+
/** The session's key. */
|
|
16
|
+
readonly key: string;
|
|
17
|
+
/** The request: its id (the same on every attempt), headers, target, and the attempt's signal. */
|
|
18
|
+
readonly request: restate.Request;
|
|
19
|
+
/**
|
|
20
|
+
* The key's database. Each statement outside a transaction is its own
|
|
21
|
+
* commit, and `db.transaction` groups several; a commit is durable when
|
|
22
|
+
* its promise resolves. Calls run one at a time, in call order.
|
|
23
|
+
*/
|
|
24
|
+
readonly db: Database;
|
|
25
|
+
/** Calls, typed (`ctx.rpc(object, key).handler(input)`) or literal. */
|
|
26
|
+
readonly rpc: Rpc;
|
|
27
|
+
/** Sends, made at once; a transaction's (`tx.send`) are made once it commits. */
|
|
28
|
+
readonly send: Send;
|
|
29
|
+
/** Cancel an invocation, by its id: see {@link Cancel}. */
|
|
30
|
+
readonly cancel: Cancel;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The context of a session object's view: it runs beside the handlers, and
|
|
34
|
+
* reads the database as committed when its invocation started, whatever they
|
|
35
|
+
* commit meanwhile. It writes nothing, and sends nothing, but it can cancel an
|
|
36
|
+
* invocation: a handler of its own object's, say, as a Stop button does.
|
|
37
|
+
*/
|
|
38
|
+
export interface ViewContext {
|
|
39
|
+
readonly key: string;
|
|
40
|
+
readonly request: restate.Request;
|
|
41
|
+
readonly db: DatabaseReader;
|
|
42
|
+
readonly rpc: Rpc;
|
|
43
|
+
readonly cancel: Cancel;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Cancel invocation `invocationId` (such as `inv_1f…`), as Restate's admin
|
|
47
|
+
* API does: made at once, and not awaited. Cancelling an invocation that
|
|
48
|
+
* already ended does nothing, so a new attempt that cancels it again is
|
|
49
|
+
* harmless.
|
|
50
|
+
*
|
|
51
|
+
* ctx.cancel(turn.invocationId);
|
|
52
|
+
*/
|
|
53
|
+
export type Cancel = (invocationId: string) => void;
|
|
54
|
+
/** A handler of `C`: its input, if any, annotated. */
|
|
55
|
+
type Fn<C> = (ctx: C, input: any) => Promise<unknown>;
|
|
56
|
+
/** The SDK's options of a handler (`input`, `output`, `description`, `ingressPrivate`, ...). */
|
|
57
|
+
export type HandlerOptions = restate.ObjectHandlerOpts<any, any>;
|
|
58
|
+
/** A handler or a view: a function, or one with options. */
|
|
59
|
+
export type Entry<C> = Fn<C> | ({
|
|
60
|
+
handler: Fn<C>;
|
|
61
|
+
} & HandlerOptions);
|
|
62
|
+
/** Each entry's function, as clients see it; none for entries left out (inferred as the constraint). */
|
|
63
|
+
type Functions<H> = string extends keyof H ? unknown : {
|
|
64
|
+
[K in keyof H]: H[K] extends {
|
|
65
|
+
handler: infer F;
|
|
66
|
+
} ? F : H[K];
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* The key of the object database's head, its first read as it opens:
|
|
70
|
+
* `HEAD_KEY` in the addon's state format
|
|
71
|
+
* (`packages/sessions/native/src/state/format.rs`).
|
|
72
|
+
*/
|
|
73
|
+
export declare const HEAD_KEY = "v22/head";
|
|
74
|
+
/**
|
|
75
|
+
* The options every session object has: an invocation starts with the
|
|
76
|
+
* database's head only, not with every page. The rest of the database it
|
|
77
|
+
* reads as it needs it: its tail entries and packs change keys with each
|
|
78
|
+
* flush, so only the head can be named.
|
|
79
|
+
*/
|
|
80
|
+
export declare const sqlOptions: {
|
|
81
|
+
state: {
|
|
82
|
+
preload: string[];
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* The metadata every session object has: Restate's UI hides the database
|
|
87
|
+
* from the journal view (its head, tail, manifests and packs in the object's
|
|
88
|
+
* state, `v22/...`; and the `sync` runs after its writes).
|
|
89
|
+
*/
|
|
90
|
+
export declare const sqlMetadata: {
|
|
91
|
+
'dev.restate.tooling.journal.hidden.names': string;
|
|
92
|
+
'dev.restate.tooling.journal.hidden.name.prefix': string;
|
|
93
|
+
};
|
|
94
|
+
export declare const recovery: () => restate.internal.ExplicitRecoveryOptions;
|
|
95
|
+
/** The SDK's runtime context, as far as the session needs it beyond its public type. */
|
|
96
|
+
type Runtime = {
|
|
97
|
+
invocationEndPromise: SqlHost['invocationEndPromise'];
|
|
98
|
+
defaultSerde: SqlHost['defaultSerde'];
|
|
99
|
+
};
|
|
100
|
+
/** What an attempt needs of the SDK's context: a test's fake has these. */
|
|
101
|
+
export type AttemptContext = Pick<restate.ObjectContext, 'key' | 'request' | 'get' | 'set' | 'clear' | 'stateKeys' | 'run' | 'genericSend' | 'genericCall' | 'invocation'> & Runtime;
|
|
102
|
+
/** What an attempt's session needs of the SDK's context `ctx`. */
|
|
103
|
+
export declare function host(ctx: restate.ObjectContext | restate.ObjectSharedContext | AttemptContext, shared: boolean): SqlHost;
|
|
104
|
+
/** The SDK's contexts behind the session objects' contexts, for @restatedev/sessions/internal. */
|
|
105
|
+
export declare const sdkContexts: WeakMap<SessionContext | ViewContext, restate.ObjectContext<restate.UntypedState> | restate.ObjectSharedContext<restate.UntypedState>>;
|
|
106
|
+
/**
|
|
107
|
+
* The context of a handler (or, with `view`, of a view) over the SDK's
|
|
108
|
+
* context `ctx`, with the database `db`: what an attempt gets, and a test's
|
|
109
|
+
* over a context of its own. With `explicitCancellation`, a handler's with
|
|
110
|
+
* that option, which {@link cancelled} and {@link cancelCalls} take.
|
|
111
|
+
*/
|
|
112
|
+
export declare function contextOf(ctx: AttemptContext, db: Database, options: {
|
|
113
|
+
view: true;
|
|
114
|
+
}): ViewContext;
|
|
115
|
+
export declare function contextOf(ctx: AttemptContext, db: Database, options?: {
|
|
116
|
+
view?: false;
|
|
117
|
+
explicitCancellation?: boolean;
|
|
118
|
+
}): SessionContext;
|
|
119
|
+
/**
|
|
120
|
+
* Run handler or view `name` of `definition` for one attempt over `ctx`, a
|
|
121
|
+
* context of a test's own, without Restate: for tests.
|
|
122
|
+
*/
|
|
123
|
+
export declare function invoke(definition: {
|
|
124
|
+
name: string;
|
|
125
|
+
}, name: string, ctx: AttemptContext, input?: unknown): Promise<unknown>;
|
|
126
|
+
/**
|
|
127
|
+
* A virtual object whose state is a SQL database per key.
|
|
128
|
+
*
|
|
129
|
+
* - `schema`: the steps that make each key's database, in order, applied
|
|
130
|
+
* once per key by the first handler that uses it. A step that ran never
|
|
131
|
+
* changes: a change is a step of its own.
|
|
132
|
+
* - `handlers`: they run one at a time per key, each with a
|
|
133
|
+
* {@link SessionContext}.
|
|
134
|
+
* - `views`: they run beside the handlers, each with a {@link ViewContext}:
|
|
135
|
+
* they read, and write nothing.
|
|
136
|
+
*
|
|
137
|
+
* Each is a function, or `{ handler, ...options }` with the SDK's handler
|
|
138
|
+
* options. A name is a handler or a view, not both. `description`,
|
|
139
|
+
* `metadata` and `options` are the SDK's object fields.
|
|
140
|
+
*/
|
|
141
|
+
export declare function sessionObject<P extends string, H extends Record<string, Entry<SessionContext>>, V extends Record<string, Entry<ViewContext>>>(definition: {
|
|
142
|
+
name: P;
|
|
143
|
+
schema?: readonly Step[];
|
|
144
|
+
handlers?: H;
|
|
145
|
+
views?: V;
|
|
146
|
+
description?: string;
|
|
147
|
+
metadata?: Record<string, string>;
|
|
148
|
+
options?: restate.ObjectOptions;
|
|
149
|
+
}): VirtualObjectDefinition<P, Functions<H> & Functions<V>>;
|
|
150
|
+
/**
|
|
151
|
+
* Resolves when Restate cancels the invocation of `ctx`, a handler's with
|
|
152
|
+
* `explicitCancellation: true`, whose awaits are left as they are: for a
|
|
153
|
+
* library that stops its own work then (a model's request, say).
|
|
154
|
+
*/
|
|
155
|
+
export declare const cancelled: (ctx: SessionContext) => Promise<void>;
|
|
156
|
+
/**
|
|
157
|
+
* Cancel the calls the attempt of `ctx` made, as a cancelled invocation's
|
|
158
|
+
* would be: a handler's with `explicitCancellation: true`.
|
|
159
|
+
*/
|
|
160
|
+
export declare const cancelCalls: (ctx: SessionContext) => Promise<void>;
|
|
161
|
+
export {};
|
|
162
|
+
//# sourceMappingURL=object.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,OAAO,MAAM,yBAAyB,CAAC;AACnD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EAAE,KAAK,GAAG,EAAS,KAAK,IAAI,EAAU,MAAM,YAAY,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAsB,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAE5D,OAAO,EAAE,KAAK,QAAQ,EAAW,KAAK,OAAO,EAAe,MAAM,cAAc,CAAC;AAEjF;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,yBAAyB;IACzB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,kGAAkG;IAClG,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;IAClC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC;IACtB,uEAAuE;IACvE,QAAQ,CAAC,GAAG,EAAE,GAAG,CAAC;IAClB,iFAAiF;IACjF,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,2DAA2D;IAC3D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAED;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,Q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c,CAAC,CAAC,EAC/C,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,EAC5C,UAAU,EAAE;IACZ,IAAI,EAAE,CAAC,CAAC;IACR,MAAM,CAAC,EAAE,SAAS,IAAI,EAAE,CAAC;IACzB,QAAQ,CAAC,EAAE,CAAC,CAAC;IACb,KAAK,CAAC,EAAE,CAAC,CAAC;IACV,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,OAAO,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC;CACjC,GAAG,uBAAuB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,CA8B1D;AAYD;;;;GAIG;AACH,eAAO,MAAM,SAAS,QAAe,cAAc,KAAG,OAAO,CAAC,IAAI,CAEjE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,QAAe,cAAc,KAAG,OAAO,CAAC,IAAI,CAEnE,CAAC"}
|
package/dist/object.js
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
// Session objects: Restate virtual objects whose state is a SQL database per
|
|
2
|
+
// key. Its handlers run one at a time per key, its views beside them; each
|
|
3
|
+
// gets a context of its own, made of the key, the request, the database and
|
|
4
|
+
// calls, and nothing else of the SDK's context:
|
|
5
|
+
//
|
|
6
|
+
// const notes = restate.sessionObject({
|
|
7
|
+
// name: 'notes',
|
|
8
|
+
// schema: ['CREATE TABLE notes (text TEXT NOT NULL)'],
|
|
9
|
+
// handlers: {
|
|
10
|
+
// add: async (ctx, text: string) => {
|
|
11
|
+
// await ctx.db.execute('INSERT INTO notes (text) VALUES (?)', [text]);
|
|
12
|
+
// },
|
|
13
|
+
// },
|
|
14
|
+
// views: {
|
|
15
|
+
// list: async (ctx) => ctx.db.query<{ text: string }>('SELECT text FROM notes'),
|
|
16
|
+
// },
|
|
17
|
+
// });
|
|
18
|
+
import * as restate from '@restatedev/restate-sdk';
|
|
19
|
+
import { rpcOf, sendOf } from './calls.js';
|
|
20
|
+
import { register, sessions } from './schema.js';
|
|
21
|
+
import { hookSelector } from './selector.js';
|
|
22
|
+
import { Attempt, withAttempt } from './session.js';
|
|
23
|
+
/**
|
|
24
|
+
* The key of the object database's head, its first read as it opens:
|
|
25
|
+
* `HEAD_KEY` in the addon's state format
|
|
26
|
+
* (`packages/sessions/native/src/state/format.rs`).
|
|
27
|
+
*/
|
|
28
|
+
export const HEAD_KEY = 'v22/head';
|
|
29
|
+
/**
|
|
30
|
+
* The options every session object has: an invocation starts with the
|
|
31
|
+
* database's head only, not with every page. The rest of the database it
|
|
32
|
+
* reads as it needs it: its tail entries and packs change keys with each
|
|
33
|
+
* flush, so only the head can be named.
|
|
34
|
+
*/
|
|
35
|
+
export const sqlOptions = { state: { preload: [HEAD_KEY] } };
|
|
36
|
+
/**
|
|
37
|
+
* The metadata every session object has: Restate's UI hides the database
|
|
38
|
+
* from the journal view (its head, tail, manifests and packs in the object's
|
|
39
|
+
* state, `v22/...`; and the `sync` runs after its writes).
|
|
40
|
+
*/
|
|
41
|
+
export const sqlMetadata = {
|
|
42
|
+
'dev.restate.tooling.journal.hidden.names': 'sync',
|
|
43
|
+
'dev.restate.tooling.journal.hidden.name.prefix': 'v22/',
|
|
44
|
+
};
|
|
45
|
+
// The handler options of every handler: explicit recovery, which runs a
|
|
46
|
+
// retried attempt from the start, since a later attempt makes different
|
|
47
|
+
// reads than a replayed journal would have.
|
|
48
|
+
export const recovery = () => restate.internal.explicitRecovery();
|
|
49
|
+
/** What an attempt's session needs of the SDK's context `ctx`. */
|
|
50
|
+
export function host(ctx, shared) {
|
|
51
|
+
const runtime = ctx;
|
|
52
|
+
const exclusive = ctx;
|
|
53
|
+
return {
|
|
54
|
+
shared,
|
|
55
|
+
key: ctx.key,
|
|
56
|
+
invocationEndPromise: runtime.invocationEndPromise,
|
|
57
|
+
defaultSerde: runtime.defaultSerde,
|
|
58
|
+
request: () => ctx.request(),
|
|
59
|
+
get: (name, serde, entry) => ctx.get(name, serde, entry),
|
|
60
|
+
set: (name, value, serde, entry) => exclusive.set(name, value, serde, entry),
|
|
61
|
+
clear: (name, entry) => exclusive.clear(name, entry),
|
|
62
|
+
stateKeys: () => ctx.stateKeys(),
|
|
63
|
+
run: (name, action) => exclusive.run(name, action),
|
|
64
|
+
genericSend: (send) => ctx.genericSend(send),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/** The SDK's contexts behind the session objects' contexts, for @restatedev/sessions/internal. */
|
|
68
|
+
export const sdkContexts = new WeakMap();
|
|
69
|
+
/** The reads of `db`, which apply a library's schema as `db` does (`Schema.ensure`). */
|
|
70
|
+
function readerOf(db) {
|
|
71
|
+
const reader = {
|
|
72
|
+
query: (sql, params) => db.query(sql, params),
|
|
73
|
+
get: (sql, params) => db.get(sql, params),
|
|
74
|
+
values: (sql, params) => db.values(sql, params),
|
|
75
|
+
};
|
|
76
|
+
const ensure = sessions.get(db);
|
|
77
|
+
if (ensure)
|
|
78
|
+
sessions.set(reader, ensure);
|
|
79
|
+
return Object.freeze(reader);
|
|
80
|
+
}
|
|
81
|
+
export function contextOf(ctx, db, { view = false, explicitCancellation = false } = {}) {
|
|
82
|
+
if (explicitCancellation)
|
|
83
|
+
explicitlyCancelled.add(ctx);
|
|
84
|
+
const rpc = rpcOf(ctx);
|
|
85
|
+
const cancel = cancelOf(ctx);
|
|
86
|
+
const context = view
|
|
87
|
+
? Object.freeze({ key: ctx.key, request: ctx.request(), db: readerOf(db), rpc, cancel })
|
|
88
|
+
: Object.freeze({
|
|
89
|
+
key: ctx.key,
|
|
90
|
+
request: ctx.request(),
|
|
91
|
+
db,
|
|
92
|
+
rpc,
|
|
93
|
+
send: sendOf((send) => void ctx.genericSend(send)),
|
|
94
|
+
cancel,
|
|
95
|
+
});
|
|
96
|
+
sdkContexts.set(context, ctx);
|
|
97
|
+
return context;
|
|
98
|
+
}
|
|
99
|
+
/** {@link Cancel} over the SDK's context `ctx`. */
|
|
100
|
+
const cancelOf = (ctx) => (invocationId) => {
|
|
101
|
+
// Not an id (the SDK's parser checks no more): a retry would fail the same way.
|
|
102
|
+
if (!invocationId.startsWith('inv'))
|
|
103
|
+
throw new restate.TerminalError(`not an invocation id: ${invocationId}`);
|
|
104
|
+
ctx.invocation(restate.InvocationIdParser.fromString(invocationId)).cancel();
|
|
105
|
+
};
|
|
106
|
+
/** One attempt of `fn` over `ctx`: its own context and session, which ends with it. */
|
|
107
|
+
function attempt(fn, { view, explicit }, ctx, input) {
|
|
108
|
+
const session = new Attempt(host(ctx, view));
|
|
109
|
+
session.openNow();
|
|
110
|
+
const context = view
|
|
111
|
+
? contextOf(ctx, session.db, { view: true })
|
|
112
|
+
: contextOf(ctx, session.db, { explicitCancellation: explicit });
|
|
113
|
+
return withAttempt(() => fn(context, input), session);
|
|
114
|
+
}
|
|
115
|
+
/** `fn` as the SDK's handler: one loop drives each attempt's awaits (see selector.ts), until it ends. */
|
|
116
|
+
function wrap(fn, view, explicit) {
|
|
117
|
+
return (ctx, input) => {
|
|
118
|
+
const unhook = hookSelector(ctx);
|
|
119
|
+
const runtime = ctx;
|
|
120
|
+
runtime.invocationEndPromise.promise.catch(unhook);
|
|
121
|
+
return attempt(fn, { view, explicit }, ctx, input).finally(unhook);
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/** Each session object's handlers and views, by name: for {@link invoke}. */
|
|
125
|
+
const entries = new WeakMap();
|
|
126
|
+
/** The SDK's contexts of the handlers with `explicitCancellation: true`: for {@link cancelled}. */
|
|
127
|
+
const explicitlyCancelled = new WeakSet();
|
|
128
|
+
/**
|
|
129
|
+
* Run handler or view `name` of `definition` for one attempt over `ctx`, a
|
|
130
|
+
* context of a test's own, without Restate: for tests.
|
|
131
|
+
*/
|
|
132
|
+
export function invoke(definition, name, ctx, input) {
|
|
133
|
+
const entry = entries.get(definition)?.get(name);
|
|
134
|
+
if (entry === undefined)
|
|
135
|
+
throw new Error(`${definition.name}.${name} is no handler or view of a session object`);
|
|
136
|
+
return attempt(entry.fn, entry, ctx, input);
|
|
137
|
+
}
|
|
138
|
+
/** Whether `value` is a handler of the SDK's already. */
|
|
139
|
+
const isSdkHandler = (value) => Object.getOwnPropertySymbols(value).some((s) => s.description === 'Handler');
|
|
140
|
+
/** The SDK's handler of entry `name` of `object`. */
|
|
141
|
+
function handlerOf(object, name, entry, view) {
|
|
142
|
+
const [fn, options] = typeof entry === 'function'
|
|
143
|
+
? [entry, {}]
|
|
144
|
+
: typeof entry === 'object' && entry !== null && typeof entry.handler === 'function'
|
|
145
|
+
? (() => {
|
|
146
|
+
const { handler, ...rest } = entry;
|
|
147
|
+
return [handler, rest];
|
|
148
|
+
})()
|
|
149
|
+
: [undefined, undefined];
|
|
150
|
+
if (fn === undefined)
|
|
151
|
+
throw new TypeError(`${object}.${name} is not a handler: a function, or { handler, ...options }`);
|
|
152
|
+
if (isSdkHandler(fn)) {
|
|
153
|
+
throw new TypeError(`${object}.${name} is an SDK handler: a session object's handlers are functions of its context. ` +
|
|
154
|
+
'Put journaled work in a restate.object, service or workflow, and call it with ctx.rpc');
|
|
155
|
+
}
|
|
156
|
+
const opts = { ...options, ...recovery() };
|
|
157
|
+
const explicit = options.explicitCancellation === true;
|
|
158
|
+
const made = wrap(fn, view, explicit);
|
|
159
|
+
const handler = view ? restate.handlers.object.shared(opts, made) : restate.handlers.object.exclusive(opts, made);
|
|
160
|
+
return { handler, entry: { fn: fn, view, explicit } };
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* A virtual object whose state is a SQL database per key.
|
|
164
|
+
*
|
|
165
|
+
* - `schema`: the steps that make each key's database, in order, applied
|
|
166
|
+
* once per key by the first handler that uses it. A step that ran never
|
|
167
|
+
* changes: a change is a step of its own.
|
|
168
|
+
* - `handlers`: they run one at a time per key, each with a
|
|
169
|
+
* {@link SessionContext}.
|
|
170
|
+
* - `views`: they run beside the handlers, each with a {@link ViewContext}:
|
|
171
|
+
* they read, and write nothing.
|
|
172
|
+
*
|
|
173
|
+
* Each is a function, or `{ handler, ...options }` with the SDK's handler
|
|
174
|
+
* options. A name is a handler or a view, not both. `description`,
|
|
175
|
+
* `metadata` and `options` are the SDK's object fields.
|
|
176
|
+
*/
|
|
177
|
+
export function sessionObject(definition) {
|
|
178
|
+
const { name, schema, handlers = {}, views = {}, description, metadata, options } = definition;
|
|
179
|
+
const both = Object.keys(handlers).filter((key) => key in views);
|
|
180
|
+
if (both.length > 0)
|
|
181
|
+
throw new Error(`${name}: ${both.join(', ')} is a handler and a view: name one otherwise`);
|
|
182
|
+
// Its state is its database's: which keys an invocation starts with is the session object's own.
|
|
183
|
+
if (options && ('state' in options || 'enableLazyState' in options)) {
|
|
184
|
+
throw new Error(`${name}: a session object sets its state options itself: leave out state and enableLazyState`);
|
|
185
|
+
}
|
|
186
|
+
if (schema)
|
|
187
|
+
register(name, schema);
|
|
188
|
+
const sdkHandlers = {};
|
|
189
|
+
const own = new Map();
|
|
190
|
+
for (const [view, map] of [
|
|
191
|
+
[false, handlers],
|
|
192
|
+
[true, views],
|
|
193
|
+
]) {
|
|
194
|
+
for (const [key, value] of Object.entries(map)) {
|
|
195
|
+
const { handler, entry } = handlerOf(name, key, value, view);
|
|
196
|
+
sdkHandlers[key] = handler;
|
|
197
|
+
own.set(key, entry);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
const made = restate.object({
|
|
201
|
+
name,
|
|
202
|
+
description,
|
|
203
|
+
handlers: sdkHandlers,
|
|
204
|
+
metadata: { ...sqlMetadata, ...metadata },
|
|
205
|
+
options: { ...sqlOptions, ...options },
|
|
206
|
+
});
|
|
207
|
+
entries.set(made, own);
|
|
208
|
+
return made;
|
|
209
|
+
}
|
|
210
|
+
/** The SDK's context behind `ctx`, a handler's with `explicitCancellation: true`. */
|
|
211
|
+
function explicitOf(ctx, of) {
|
|
212
|
+
const sdk = sdkContexts.get(ctx);
|
|
213
|
+
if (sdk === undefined)
|
|
214
|
+
throw new restate.TerminalError(`${of} takes a session object's ctx`);
|
|
215
|
+
if (!explicitlyCancelled.has(sdk)) {
|
|
216
|
+
throw new restate.TerminalError(`${of} takes the ctx of a handler with explicitCancellation: true`);
|
|
217
|
+
}
|
|
218
|
+
return restate.internal.asInternal(sdk);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Resolves when Restate cancels the invocation of `ctx`, a handler's with
|
|
222
|
+
* `explicitCancellation: true`, whose awaits are left as they are: for a
|
|
223
|
+
* library that stops its own work then (a model's request, say).
|
|
224
|
+
*/
|
|
225
|
+
export const cancelled = async (ctx) => {
|
|
226
|
+
await explicitOf(ctx, 'cancelled').cancellation();
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* Cancel the calls the attempt of `ctx` made, as a cancelled invocation's
|
|
230
|
+
* would be: a handler's with `explicitCancellation: true`.
|
|
231
|
+
*/
|
|
232
|
+
export const cancelCalls = async (ctx) => {
|
|
233
|
+
await explicitOf(ctx, 'cancelCalls').cancelPreviousCalls();
|
|
234
|
+
};
|
|
235
|
+
//# sourceMappingURL=object.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.js","sourceRoot":"","sources":["../src/object.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,2EAA2E;AAC3E,4EAA4E;AAC5E,gDAAgD;AAChD,EAAE;AACF,0CAA0C;AAC1C,qBAAqB;AACrB,2DAA2D;AAC3D,kBAAkB;AAClB,4CAA4C;AAC5C,+EAA+E;AAC/E,WAAW;AACX,SAAS;AACT,eAAe;AACf,uFAAuF;AACvF,SAAS;AACT,QAAQ;AACR,OAAO,KAAK,OAAO,MAAM,yBAAyB,CAAC;AAEnD,OAAO,EAAY,KAAK,EAAa,MAAM,EAAE,MAAM,YAAY,CAAC;AAEhE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAa,MAAM,aAAa,CAAC;AAC5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AC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,IAAI,OAAO,CAAC,aAAa,CAAC,GAAG,EAAE,6DAA6D,CAAC,CAAC;IACtG,CAAC;IACD,OAAO,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;AAC1C,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAAE,GAAmB,EAAiB,EAAE;IACpE,MAAM,UAAU,CAAC,GAAG,EAAE,WAAW,CAAC,CAAC,YAAY,EAAE,CAAC;AACpD,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAAE,GAAmB,EAAiB,EAAE;IACtE,MAAM,UAAU,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC,mBAAmB,EAAE,CAAC;AAC7D,CAAC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** The platforms built, as their packages name them. */
|
|
2
|
+
export declare const PLATFORMS: readonly ['linux-x64-gnu', 'linux-arm64-gnu', 'darwin-arm64'];
|
|
3
|
+
/** This machine's platform, as a package of the addon would name it. */
|
|
4
|
+
export declare function platform(): string;
|
|
5
|
+
//# sourceMappingURL=platform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAMA,wDAAwD;AACxD,eAAO,MAAM,SAAS,YAAI,eAAe,EAAE,iBAAiB,EAAE,cAAc,CAAU,CAAC;AAEvF,wEAAwE;AACxE,wBAAgB,QAAQ,IAAI,MAAM,CAIjC"}
|
package/dist/platform.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// The platforms @restatedev/sessions ships its addon for, each a package of its
|
|
2
|
+
// own (npm/<platform>, `@restatedev/sessions-<platform>`) that @restatedev/sessions
|
|
3
|
+
// depends on optionally: a package manager installs the one of its machine
|
|
4
|
+
// alone (by the `os`, `cpu` and `libc` of each). The CI builds them
|
|
5
|
+
// (.github/workflows/packages.yml); `pnpm build` builds this machine's.
|
|
6
|
+
/** The platforms built, as their packages name them. */
|
|
7
|
+
export const PLATFORMS = ['linux-x64-gnu', 'linux-arm64-gnu', 'darwin-arm64'];
|
|
8
|
+
/** This machine's platform, as a package of the addon would name it. */
|
|
9
|
+
export function platform() {
|
|
10
|
+
if (process.platform !== 'linux')
|
|
11
|
+
return `${process.platform}-${process.arch}`;
|
|
12
|
+
const report = process.report.getReport();
|
|
13
|
+
return `linux-${process.arch}-${report.header?.glibcVersionRuntime ? 'gnu' : 'musl'}`;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,oFAAoF;AACpF,2EAA2E;AAC3E,oEAAoE;AACpE,wEAAwE;AAExE,wDAAwD;AACxD,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,eAAe,EAAE,iBAAiB,EAAE,cAAc,CAAU,CAAC;AAEvF,wEAAwE;AACxE,MAAM,UAAU,QAAQ;IACtB,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;QAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAC/E,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,SAAS,EAAmD,CAAC;IAC3F,OAAO,SAAS,OAAO,CAAC,IAAI,IAAI,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;AACxF,CAAC"}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { Connection, DatabaseReader, DatabaseWriter, ConnectionTransaction } from './database.ts';
|
|
2
|
+
/** A statement, or an async function of the transaction. */
|
|
3
|
+
export type Step = string | ((tx: DatabaseWriter) => Promise<void>);
|
|
4
|
+
/** A part of a database's schema: its `name`, and the `steps` that make it, in order. */
|
|
5
|
+
export declare class Schema {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly steps: readonly Step[];
|
|
8
|
+
constructor(name: string, steps: readonly Step[]);
|
|
9
|
+
/**
|
|
10
|
+
* Apply the steps `db` lacks: a library's tables, where it uses them, in
|
|
11
|
+
* any object. On a handler's `ctx.db`, once per attempt, and a shared
|
|
12
|
+
* handler's are its own, vanishing with its session.
|
|
13
|
+
*/
|
|
14
|
+
ensure(db: DatabaseReader | Connection): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
/** The handlers' sessions (`ctx.db`), each with how it applies schemas. */
|
|
17
|
+
export declare const sessions: WeakMap<object, (schemas: readonly Schema[]) => Promise<void>>;
|
|
18
|
+
/** The session object `name`'s own schema: its steps, which each of its databases is made by. */
|
|
19
|
+
export declare const register: (name: string, steps: readonly Step[]) => undefined;
|
|
20
|
+
/** The session object `name`'s own schema, if it has one. */
|
|
21
|
+
export declare const ofObject: (name: string) => Schema | undefined;
|
|
22
|
+
/** Apply the steps of `schemas` that `db` lacks, in one transaction, with how far each got. */
|
|
23
|
+
export declare function apply(db: Connection, schemas: readonly Schema[], { reader }?: {
|
|
24
|
+
reader?: boolean | undefined;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
/** Apply the steps of `schemas` that the transaction `tx` lacks, and record how far each got. */
|
|
27
|
+
export declare function applyIn(tx: ConnectionTransaction, schemas: readonly Schema[]): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Empty the database in the transaction `tx`: drop every table, view, index
|
|
30
|
+
* and trigger, and forget every schema, then apply `schemas` again. Its
|
|
31
|
+
* other records (the outbox) stay. It commits with `tx`: what `tx` writes
|
|
32
|
+
* after it are the new database's first rows.
|
|
33
|
+
*/
|
|
34
|
+
export declare function dropAll(tx: ConnectionTransaction, schemas: readonly Schema[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AC,EAAE,EAAE,qBAAqB,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,iBAgBlF"}
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The database's record of its schemas: how many steps of each it has, by
|
|
3
|
+
* name. One record, so that `reset` clears all of them, a library's this
|
|
4
|
+
* process never loaded too.
|
|
5
|
+
*/
|
|
6
|
+
const RECORD = 'schema';
|
|
7
|
+
async function appliedIn(db) {
|
|
8
|
+
const record = await db.record(RECORD);
|
|
9
|
+
return record.length === 0 ? {} : JSON.parse(new TextDecoder().decode(record));
|
|
10
|
+
}
|
|
11
|
+
/** A part of a database's schema: its `name`, and the `steps` that make it, in order. */
|
|
12
|
+
export class Schema {
|
|
13
|
+
name;
|
|
14
|
+
steps;
|
|
15
|
+
constructor(name, steps) {
|
|
16
|
+
this.name = name;
|
|
17
|
+
this.steps = steps;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Apply the steps `db` lacks: a library's tables, where it uses them, in
|
|
21
|
+
* any object. On a handler's `ctx.db`, once per attempt, and a shared
|
|
22
|
+
* handler's are its own, vanishing with its session.
|
|
23
|
+
*/
|
|
24
|
+
ensure(db) {
|
|
25
|
+
const session = sessions.get(db);
|
|
26
|
+
return session ? session([this]) : apply(db, [this]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** The handlers' sessions (`ctx.db`), each with how it applies schemas. */
|
|
30
|
+
export const sessions = new WeakMap();
|
|
31
|
+
// The schema of each session object, by its name.
|
|
32
|
+
const objects = new Map();
|
|
33
|
+
/** The session object `name`'s own schema: its steps, which each of its databases is made by. */
|
|
34
|
+
export const register = (name, steps) => void objects.set(name, new Schema(name, steps));
|
|
35
|
+
/** The session object `name`'s own schema, if it has one. */
|
|
36
|
+
export const ofObject = (name) => objects.get(name);
|
|
37
|
+
/** Apply the steps of `schemas` that `db` lacks, in one transaction, with how far each got. */
|
|
38
|
+
export async function apply(db, schemas, { reader = false } = {}) {
|
|
39
|
+
if (behind(await appliedIn(db), schemas).length === 0)
|
|
40
|
+
return;
|
|
41
|
+
// Again in the transaction, which holds the session: a call before it may
|
|
42
|
+
// have applied them.
|
|
43
|
+
await db.transaction(async (tx) => {
|
|
44
|
+
if (!reader)
|
|
45
|
+
return applyIn(tx, schemas);
|
|
46
|
+
// A reader's session is query-only, but for its schemas.
|
|
47
|
+
await tx.execute('PRAGMA query_only = 0');
|
|
48
|
+
try {
|
|
49
|
+
await applyIn(tx, schemas);
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
await tx.execute('PRAGMA query_only = 1');
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
/** Apply the steps of `schemas` that the transaction `tx` lacks, and record how far each got. */
|
|
57
|
+
export async function applyIn(tx, schemas) {
|
|
58
|
+
const applied = await appliedIn(tx);
|
|
59
|
+
const lacking = behind(applied, schemas);
|
|
60
|
+
if (lacking.length === 0)
|
|
61
|
+
return;
|
|
62
|
+
for (const schema of lacking) {
|
|
63
|
+
for (const step of schema.steps.slice(applied[schema.name] ?? 0)) {
|
|
64
|
+
await (typeof step === 'string' ? tx.execute(step) : step(tx));
|
|
65
|
+
}
|
|
66
|
+
applied[schema.name] = schema.steps.length;
|
|
67
|
+
}
|
|
68
|
+
tx.setRecord(RECORD, new TextEncoder().encode(JSON.stringify(applied)));
|
|
69
|
+
}
|
|
70
|
+
/** The schemas of `schemas` that `applied` lacks steps of. */
|
|
71
|
+
const behind = (applied, schemas) => schemas.filter((schema) => (applied[schema.name] ?? 0) < schema.steps.length);
|
|
72
|
+
/**
|
|
73
|
+
* Empty the database in the transaction `tx`: drop every table, view, index
|
|
74
|
+
* and trigger, and forget every schema, then apply `schemas` again. Its
|
|
75
|
+
* other records (the outbox) stay. It commits with `tx`: what `tx` writes
|
|
76
|
+
* after it are the new database's first rows.
|
|
77
|
+
*/
|
|
78
|
+
export async function dropAll(tx, schemas) {
|
|
79
|
+
const made = await tx.query("SELECT type, name FROM sqlite_schema WHERE substr(name, 1, 7) != 'sqlite_'");
|
|
80
|
+
// A trigger or view may name a table; an index goes with its table.
|
|
81
|
+
for (const type of ['trigger', 'view']) {
|
|
82
|
+
for (const { name } of made.filter((m) => m.type === type))
|
|
83
|
+
await drop(tx, type, name);
|
|
84
|
+
}
|
|
85
|
+
for (const name of await childrenFirst(tx, made.filter((m) => m.type === 'table').map((m) => m.name))) {
|
|
86
|
+
await drop(tx, 'table', name);
|
|
87
|
+
}
|
|
88
|
+
tx.setRecord(RECORD, new Uint8Array());
|
|
89
|
+
await applyIn(tx, schemas);
|
|
90
|
+
}
|
|
91
|
+
function drop(tx, type, name) {
|
|
92
|
+
return tx.execute(`DROP ${type.toUpperCase()} IF EXISTS "${name.replaceAll('"', '""')}"`);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* `tables`, each after every table whose foreign keys name it: with foreign
|
|
96
|
+
* keys on, dropping a table deletes its rows, which a child's rows may not
|
|
97
|
+
* outlive. Tables in a cycle stay in their order.
|
|
98
|
+
*/
|
|
99
|
+
async function childrenFirst(tx, tables) {
|
|
100
|
+
const parents = new Map();
|
|
101
|
+
for (const name of tables) {
|
|
102
|
+
const keys = await tx.query('SELECT "table" FROM pragma_foreign_key_list(?)', [name]);
|
|
103
|
+
// SQL names are case-insensitive.
|
|
104
|
+
const own = name.toLowerCase();
|
|
105
|
+
parents.set(name, new Set(keys.map((k) => k.table.toLowerCase()).filter((t) => t !== own)));
|
|
106
|
+
}
|
|
107
|
+
const ordered = [];
|
|
108
|
+
let left = tables;
|
|
109
|
+
while (left.length > 0) {
|
|
110
|
+
const named = new Set(left.flatMap((name) => [...parents.get(name)]));
|
|
111
|
+
const unnamed = left.filter((name) => !named.has(name.toLowerCase()));
|
|
112
|
+
const next = unnamed.length > 0 ? unnamed : left;
|
|
113
|
+
ordered.push(...next);
|
|
114
|
+
left = left.filter((name) => !next.includes(name));
|
|
115
|
+
}
|
|
116
|
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