@restatedev/sessions 0.2.0 → 0.3.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 +47 -8
- package/dist/database.d.ts +41 -2
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +99 -20
- package/dist/database.js.map +1 -1
- package/dist/internal.d.ts +5 -3
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +4 -2
- package/dist/internal.js.map +1 -1
- package/dist/link.d.ts +10 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +19 -0
- package/dist/link.js.map +1 -0
- package/dist/object.d.ts +17 -4
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +61 -46
- package/dist/object.js.map +1 -1
- package/dist/schema.d.ts +7 -6
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +9 -10
- package/dist/schema.js.map +1 -1
- package/dist/scope.d.ts +38 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +55 -0
- package/dist/scope.js.map +1 -0
- package/dist/session.d.ts +70 -34
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +273 -221
- package/dist/session.js.map +1 -1
- package/package.json +4 -4
- package/src/database.ts +111 -22
- package/src/internal.ts +15 -3
- package/src/link.ts +22 -0
- package/src/object.ts +94 -63
- package/src/schema.ts +11 -10
- package/src/scope.ts +78 -0
- package/src/session.ts +273 -230
package/dist/object.js
CHANGED
|
@@ -17,7 +17,9 @@
|
|
|
17
17
|
// });
|
|
18
18
|
import * as restate from '@restatedev/restate-sdk';
|
|
19
19
|
import { rpcOf, sendOf } from './calls.js';
|
|
20
|
-
import {
|
|
20
|
+
import { ensureOf, ensuring, Schema } from './schema.js';
|
|
21
|
+
import { Link } from './link.js';
|
|
22
|
+
import { holding, Scope, scopeOf } from './scope.js';
|
|
21
23
|
import { hookSelector } from './selector.js';
|
|
22
24
|
import { Attempt, withAttempt } from './session.js';
|
|
23
25
|
/**
|
|
@@ -64,8 +66,26 @@ export function host(ctx, shared) {
|
|
|
64
66
|
genericSend: (send) => ctx.genericSend(send),
|
|
65
67
|
};
|
|
66
68
|
}
|
|
67
|
-
/**
|
|
68
|
-
|
|
69
|
+
/** A session object's own, on its definition: for {@link invoke} and {@link withStoreWrapper}. */
|
|
70
|
+
const OBJECT = new Link('a session object');
|
|
71
|
+
/**
|
|
72
|
+
* The definition (`sessionObject`'s) of the object whose handler or view
|
|
73
|
+
* `ctx` is the context of: what a library keeps per object lives on it.
|
|
74
|
+
*/
|
|
75
|
+
export const definitionOf = (ctx) => scopeOf(ctx)?.definition;
|
|
76
|
+
/** What `definition`'s attempts get, if it is a session object: for a test's attempts of its own. */
|
|
77
|
+
export const configOf = (definition) => OBJECT.of(definition)?.object.config;
|
|
78
|
+
/**
|
|
79
|
+
* Wrap the stores of `definition`'s attempts with `wrap`: fault injection, in
|
|
80
|
+
* tests. A definition that is no session object has no store: it is left as
|
|
81
|
+
* it is.
|
|
82
|
+
*/
|
|
83
|
+
export function withStoreWrapper(definition, wrapper) {
|
|
84
|
+
const object = OBJECT.of(definition);
|
|
85
|
+
if (object !== undefined)
|
|
86
|
+
object.object.config.wrapStore = wrapper;
|
|
87
|
+
return definition;
|
|
88
|
+
}
|
|
69
89
|
/** The reads of `db`, which apply a library's schema as `db` does (`Schema.ensure`). */
|
|
70
90
|
function readerOf(db) {
|
|
71
91
|
const reader = {
|
|
@@ -73,28 +93,25 @@ function readerOf(db) {
|
|
|
73
93
|
get: (sql, params) => db.get(sql, params),
|
|
74
94
|
values: (sql, params) => db.values(sql, params),
|
|
75
95
|
};
|
|
76
|
-
const ensure =
|
|
77
|
-
|
|
78
|
-
sessions.set(reader, ensure);
|
|
79
|
-
return Object.freeze(reader);
|
|
96
|
+
const ensure = ensureOf(db);
|
|
97
|
+
return Object.freeze(ensure ? ensuring(reader, ensure) : reader);
|
|
80
98
|
}
|
|
81
|
-
export function contextOf(ctx, db, { view = false, explicitCancellation = false } = {}) {
|
|
82
|
-
if (explicitCancellation)
|
|
83
|
-
explicitlyCancelled.add(ctx);
|
|
99
|
+
export function contextOf(ctx, db, { view = false, explicitCancellation = false, definition, } = {}) {
|
|
84
100
|
const rpc = rpcOf(ctx);
|
|
85
101
|
const cancel = cancelOf(ctx);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
102
|
+
// It holds the attempt's scope (scope.ts), then is frozen.
|
|
103
|
+
const scope = new Scope(ctx, { explicitCancellation, definition });
|
|
104
|
+
const context = holding(view
|
|
105
|
+
? { key: ctx.key, request: ctx.request(), db: readerOf(db), rpc, cancel }
|
|
106
|
+
: {
|
|
89
107
|
key: ctx.key,
|
|
90
108
|
request: ctx.request(),
|
|
91
109
|
db,
|
|
92
110
|
rpc,
|
|
93
111
|
send: sendOf((send) => void ctx.genericSend(send)),
|
|
94
112
|
cancel,
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
return context;
|
|
113
|
+
}, scope);
|
|
114
|
+
return Object.freeze(context);
|
|
98
115
|
}
|
|
99
116
|
/** {@link Cancel} over the SDK's context `ctx`. */
|
|
100
117
|
const cancelOf = (ctx) => (invocationId) => {
|
|
@@ -103,42 +120,39 @@ const cancelOf = (ctx) => (invocationId) => {
|
|
|
103
120
|
throw new restate.TerminalError(`not an invocation id: ${invocationId}`);
|
|
104
121
|
ctx.invocation(restate.InvocationIdParser.fromString(invocationId)).cancel();
|
|
105
122
|
};
|
|
106
|
-
/** One attempt of `
|
|
107
|
-
function attempt(fn,
|
|
108
|
-
const session = new Attempt(host(ctx, view));
|
|
123
|
+
/** One attempt of `entry` over `ctx`: its own context and session, which ends with it. */
|
|
124
|
+
function attempt({ fn, view, explicit, object }, ctx, input) {
|
|
125
|
+
const session = new Attempt(host(ctx, view), object.config);
|
|
109
126
|
session.openNow();
|
|
127
|
+
const { definition } = object;
|
|
110
128
|
const context = view
|
|
111
|
-
? contextOf(ctx, session.db, { view: true })
|
|
112
|
-
: contextOf(ctx, session.db, { explicitCancellation: explicit });
|
|
129
|
+
? contextOf(ctx, session.db, { view: true, definition })
|
|
130
|
+
: contextOf(ctx, session.db, { explicitCancellation: explicit, definition });
|
|
113
131
|
return withAttempt(() => fn(context, input), session);
|
|
114
132
|
}
|
|
115
|
-
/** `
|
|
116
|
-
function wrap(
|
|
133
|
+
/** `entry` as the SDK's handler: one loop drives each attempt's awaits (see selector.ts), until it ends. */
|
|
134
|
+
function wrap(entry) {
|
|
117
135
|
return (ctx, input) => {
|
|
118
136
|
const unhook = hookSelector(ctx);
|
|
119
137
|
const runtime = ctx;
|
|
120
138
|
runtime.invocationEndPromise.promise.catch(unhook);
|
|
121
|
-
return attempt(
|
|
139
|
+
return attempt(entry, ctx, input).finally(unhook);
|
|
122
140
|
};
|
|
123
141
|
}
|
|
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
142
|
/**
|
|
129
143
|
* Run handler or view `name` of `definition` for one attempt over `ctx`, a
|
|
130
144
|
* context of a test's own, without Restate: for tests.
|
|
131
145
|
*/
|
|
132
146
|
export function invoke(definition, name, ctx, input) {
|
|
133
|
-
const entry =
|
|
147
|
+
const entry = OBJECT.of(definition)?.entries.get(name);
|
|
134
148
|
if (entry === undefined)
|
|
135
149
|
throw new Error(`${definition.name}.${name} is no handler or view of a session object`);
|
|
136
|
-
return attempt(entry
|
|
150
|
+
return attempt(entry, ctx, input);
|
|
137
151
|
}
|
|
138
152
|
/** Whether `value` is a handler of the SDK's already. */
|
|
139
153
|
const isSdkHandler = (value) => Object.getOwnPropertySymbols(value).some((s) => s.description === 'Handler');
|
|
140
154
|
/** The SDK's handler of entry `name` of `object`. */
|
|
141
|
-
function handlerOf(
|
|
155
|
+
function handlerOf(objectName, name, entry, view, object) {
|
|
142
156
|
const [fn, options] = typeof entry === 'function'
|
|
143
157
|
? [entry, {}]
|
|
144
158
|
: typeof entry === 'object' && entry !== null && typeof entry.handler === 'function'
|
|
@@ -148,16 +162,17 @@ function handlerOf(object, name, entry, view) {
|
|
|
148
162
|
})()
|
|
149
163
|
: [undefined, undefined];
|
|
150
164
|
if (fn === undefined)
|
|
151
|
-
throw new TypeError(`${
|
|
165
|
+
throw new TypeError(`${objectName}.${name} is not a handler: a function, or { handler, ...options }`);
|
|
152
166
|
if (isSdkHandler(fn)) {
|
|
153
|
-
throw new TypeError(`${
|
|
167
|
+
throw new TypeError(`${objectName}.${name} is an SDK handler: a session object's handlers are functions of its context. ` +
|
|
154
168
|
'Put journaled work in a restate.object, service or workflow, and call it with ctx.rpc');
|
|
155
169
|
}
|
|
156
170
|
const opts = { ...options, ...recovery() };
|
|
157
171
|
const explicit = options.explicitCancellation === true;
|
|
158
|
-
const made =
|
|
159
|
-
const
|
|
160
|
-
|
|
172
|
+
const made = { fn: fn, view, explicit, object };
|
|
173
|
+
const sdk = wrap(made);
|
|
174
|
+
const handler = view ? restate.handlers.object.shared(opts, sdk) : restate.handlers.object.exclusive(opts, sdk);
|
|
175
|
+
return { handler, entry: made };
|
|
161
176
|
}
|
|
162
177
|
/**
|
|
163
178
|
* A virtual object whose state is a SQL database per key.
|
|
@@ -183,18 +198,17 @@ export function sessionObject(definition) {
|
|
|
183
198
|
if (options && ('state' in options || 'enableLazyState' in options)) {
|
|
184
199
|
throw new Error(`${name}: a session object sets its state options itself: leave out state and enableLazyState`);
|
|
185
200
|
}
|
|
186
|
-
|
|
187
|
-
register(name, schema);
|
|
201
|
+
const object = { config: { schema: schema ? new Schema(name, schema) : undefined } };
|
|
188
202
|
const sdkHandlers = {};
|
|
189
|
-
const
|
|
203
|
+
const entries = new Map();
|
|
190
204
|
for (const [view, map] of [
|
|
191
205
|
[false, handlers],
|
|
192
206
|
[true, views],
|
|
193
207
|
]) {
|
|
194
208
|
for (const [key, value] of Object.entries(map)) {
|
|
195
|
-
const { handler, entry } = handlerOf(name, key, value, view);
|
|
209
|
+
const { handler, entry } = handlerOf(name, key, value, view, object);
|
|
196
210
|
sdkHandlers[key] = handler;
|
|
197
|
-
|
|
211
|
+
entries.set(key, entry);
|
|
198
212
|
}
|
|
199
213
|
}
|
|
200
214
|
const made = restate.object({
|
|
@@ -204,18 +218,19 @@ export function sessionObject(definition) {
|
|
|
204
218
|
metadata: { ...sqlMetadata, ...metadata },
|
|
205
219
|
options: { ...sqlOptions, ...options },
|
|
206
220
|
});
|
|
207
|
-
|
|
221
|
+
object.definition = made;
|
|
222
|
+
OBJECT.on(made, { object, entries });
|
|
208
223
|
return made;
|
|
209
224
|
}
|
|
210
225
|
/** The SDK's context behind `ctx`, a handler's with `explicitCancellation: true`. */
|
|
211
226
|
function explicitOf(ctx, of) {
|
|
212
|
-
const
|
|
213
|
-
if (
|
|
227
|
+
const scope = scopeOf(ctx);
|
|
228
|
+
if (scope === undefined)
|
|
214
229
|
throw new restate.TerminalError(`${of} takes a session object's ctx`);
|
|
215
|
-
if (!
|
|
230
|
+
if (!scope.explicitCancellation) {
|
|
216
231
|
throw new restate.TerminalError(`${of} takes the ctx of a handler with explicitCancellation: true`);
|
|
217
232
|
}
|
|
218
|
-
return restate.internal.asInternal(sdk);
|
|
233
|
+
return restate.internal.asInternal(scope.sdk);
|
|
219
234
|
}
|
|
220
235
|
/**
|
|
221
236
|
* Resolves when Restate cancels the invocation of `ctx`, a handler's with
|
package/dist/object.js.map
CHANGED
|
@@ -1 +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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G,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,KAAK,KAAK,SAAS;QAAE,MAAM,IAAI,OAAO,CAAC,aAAa,CAAC,GAAG,EAAE,+BAA+B,CAAC,CAAC;IAC/F,IAAI,CAAC,KAAK,CAAC,oBAAoB,EAAE,CAAC;QAChC,MAAM,IAAI,OAAO,CAAC,aAAa,CAAC,GAAG,EAAE,6DAA6D,CAAC,CAAC;IACtG,CAAC;IACD,OAAO,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;AAChD,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"}
|
package/dist/schema.d.ts
CHANGED
|
@@ -13,12 +13,12 @@ export declare class Schema {
|
|
|
13
13
|
*/
|
|
14
14
|
ensure(db: DatabaseReader | Connection): Promise<void>;
|
|
15
15
|
}
|
|
16
|
-
/**
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
export declare const
|
|
20
|
-
/**
|
|
21
|
-
export declare const
|
|
16
|
+
/** How a database applies schemas: a handler's (`ctx.db`, its reader), or one of `asDatabase`. */
|
|
17
|
+
type Ensure = (schemas: readonly Schema[]) => Promise<void>;
|
|
18
|
+
/** `db`, which applies schemas with `ensure` (see {@link Schema.ensure}). */
|
|
19
|
+
export declare const ensuring: <D extends object>(db: D, ensure: Ensure) => D;
|
|
20
|
+
/** How `db` applies schemas, if it is a database of this package's. */
|
|
21
|
+
export declare const ensureOf: (db: object) => Ensure | undefined;
|
|
22
22
|
/** Apply the steps of `schemas` that `db` lacks, in one transaction, with how far each got. */
|
|
23
23
|
export declare function apply(db: Connection, schemas: readonly Schema[], { reader }?: {
|
|
24
24
|
reader?: boolean | undefined;
|
|
@@ -32,4 +32,5 @@ export declare function applyIn(tx: ConnectionTransaction, schemas: readonly Sch
|
|
|
32
32
|
* after it are the new database's first rows.
|
|
33
33
|
*/
|
|
34
34
|
export declare function dropAll(tx: ConnectionTransaction, schemas: readonly Schema[]): Promise<void>;
|
|
35
|
+
export {};
|
|
35
36
|
//# sourceMappingURL=schema.d.ts.map
|
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAkBvG,4DAA4D;AAC5D,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AAEpE,yFAAyF;AACzF,qBAAa,MAAM;IACjB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;IAEhC,YAAY,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,IAAI,EAAE,EAG/C;IAED;;;;OAIG;IACH,MAAM,CAAC,EAAE,EAAE,cAAc,GAAG,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAGrD;CACF;AAED,kGAAkG;AAClG,KAAK,MAAM,GAAG,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAK5D,6EAA6E;AAC7E,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,MAAM,MAAM,CAAC,UAAU,MAAM,KAAG,CAA0B,CAAC;AAE9F,uEAAuE;AACvE,eAAO,MAAM,QAAQ,OAAQ,MAAM,KAAG,MAAM,GAAG,SAA0B,CAAC;AAE1E,+FAA+F;AAC/F,wBAAsB,KAAK,CAAC,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,EAAE,MAAc,EAAE;;CAAK,iBAc9F;AAED,iGAAiG;AACjG,wBAAsB,OAAO,CAAC,EAAE,EAAE,qBAAqB,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,iBAWlF;AAMD;;;;;GAKG;AACH,wBAAsB,OAAO,CAAC,EAAE,EAAE,qBAAqB,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,iBAgBlF"}
|
package/dist/schema.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Link } from './link.js';
|
|
1
2
|
/**
|
|
2
3
|
* The database's record of its schemas: how many steps of each it has, by
|
|
3
4
|
* name. One record, so that `reset` clears all of them, a library's this
|
|
@@ -22,18 +23,16 @@ export class Schema {
|
|
|
22
23
|
* handler's are its own, vanishing with its session.
|
|
23
24
|
*/
|
|
24
25
|
ensure(db) {
|
|
25
|
-
const
|
|
26
|
-
return
|
|
26
|
+
const ensure = ensureOf(db);
|
|
27
|
+
return ensure ? ensure([this]) : apply(db, [this]);
|
|
27
28
|
}
|
|
28
29
|
}
|
|
29
|
-
/**
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
/**
|
|
34
|
-
export const
|
|
35
|
-
/** The session object `name`'s own schema, if it has one. */
|
|
36
|
-
export const ofObject = (name) => objects.get(name);
|
|
30
|
+
/** A database's {@link Ensure}. */
|
|
31
|
+
const ENSURE = new Link('Schema.ensure');
|
|
32
|
+
/** `db`, which applies schemas with `ensure` (see {@link Schema.ensure}). */
|
|
33
|
+
export const ensuring = (db, ensure) => ENSURE.on(db, ensure);
|
|
34
|
+
/** How `db` applies schemas, if it is a database of this package's. */
|
|
35
|
+
export const ensureOf = (db) => ENSURE.of(db);
|
|
37
36
|
/** Apply the steps of `schemas` that `db` lacks, in one transaction, with how far each got. */
|
|
38
37
|
export async function apply(db, schemas, { reader = false } = {}) {
|
|
39
38
|
if (behind(await appliedIn(db), schemas).length === 0)
|
package/dist/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC;;;;GAIG;AACH,MAAM,MAAM,GAAG,QAAQ,CAAC;AAKxB,KAAK,UAAU,SAAS,CAAC,EAAsC;IAC7D,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACvC,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAE,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAa,CAAC;AAC9F,CAAC;AAKD,yFAAyF;AACzF,MAAM,OAAO,MAAM;IACR,IAAI,CAAS;IACb,KAAK,CAAkB;IAEhC,YAAY,IAAY,EAAE,KAAsB;QAC9C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,EAA+B;QACpC,MAAM,MAAM,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC5B,OAAO,MA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AC,WAAW,EAAE,CAAC;QAC/B,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC;IAC9F,CAAC;IACD,MAAM,OAAO,GAAa,EAAE,CAAC;IAC7B,IAAI,IAAI,GAAG,MAAM,CAAC;IAClB,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAE,CAAC,CAAC,CAAC,CAAC;QACvE,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;QACtE,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;QACjD,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;QACtB,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;IACrD,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/scope.d.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type * as restate from '@restatedev/restate-sdk';
|
|
2
|
+
import type { SessionContext, ViewContext } from './object.ts';
|
|
3
|
+
/** A context of an attempt: a handler's or a view's. */
|
|
4
|
+
type Context = SessionContext | ViewContext;
|
|
5
|
+
/** The scope's values, which only {@link ScopeKey} reaches. */
|
|
6
|
+
declare const VALUES: unique symbol;
|
|
7
|
+
/** An attempt's own, as @restatedev/sessions made it, and what its code keeps for it ({@link ScopeKey}). */
|
|
8
|
+
export declare class Scope {
|
|
9
|
+
/** The SDK's context of the attempt. */
|
|
10
|
+
readonly sdk: restate.ObjectContext | restate.ObjectSharedContext;
|
|
11
|
+
/** Whether its handler has `explicitCancellation: true`. */
|
|
12
|
+
readonly explicitCancellation: boolean;
|
|
13
|
+
/** The definition of the session object whose handler or view it runs, if any. */
|
|
14
|
+
readonly definition: object | undefined;
|
|
15
|
+
readonly [VALUES]: Map<ScopeKey<unknown>, unknown>;
|
|
16
|
+
constructor(sdk: restate.ObjectContext | restate.ObjectSharedContext, { explicitCancellation, definition }?: {
|
|
17
|
+
definition?: object | undefined;
|
|
18
|
+
explicitCancellation?: boolean | undefined;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/** `context`, holding `scope`: as it is made, before it is frozen. */
|
|
22
|
+
export declare const holding: <C extends Context>(context: C, scope: Scope) => C;
|
|
23
|
+
/** The scope of the attempt whose context `ctx` is, if it is one of @restatedev/sessions. */
|
|
24
|
+
export declare const scopeOf: (ctx: Context) => Scope | undefined;
|
|
25
|
+
/** A kind of state an attempt's code keeps, by its context: its key in the attempt's scope. */
|
|
26
|
+
export declare class ScopeKey<T> {
|
|
27
|
+
/** What it is, for an error. */
|
|
28
|
+
private readonly what;
|
|
29
|
+
constructor(what: string);
|
|
30
|
+
get(ctx: Context): T | undefined;
|
|
31
|
+
set(ctx: Context, value: T): void;
|
|
32
|
+
delete(ctx: Context): void;
|
|
33
|
+
/** The attempt's, made by `make` the first time. */
|
|
34
|
+
of(ctx: Context, make: () => T): T;
|
|
35
|
+
private values;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
38
|
+
//# sourceMappingURL=scope.d.ts.map
|
|
@@ -0,0 +1 @@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AED,MAAM,CAAC,GAAG,EAAE,OAAO,GAAG,IAAI,CAEzB;IAED,oDAAoD;IACpD,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAIjC;IAED,OAAO,CAAC,MAAM;CAMf"}
|
package/dist/scope.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Link } from './link.js';
|
|
2
|
+
/** The scope's values, which only {@link ScopeKey} reaches. */
|
|
3
|
+
const VALUES = Symbol('values');
|
|
4
|
+
/** An attempt's own, as @restatedev/sessions made it, and what its code keeps for it ({@link ScopeKey}). */
|
|
5
|
+
export class Scope {
|
|
6
|
+
/** The SDK's context of the attempt. */
|
|
7
|
+
sdk;
|
|
8
|
+
/** Whether its handler has `explicitCancellation: true`. */
|
|
9
|
+
explicitCancellation;
|
|
10
|
+
/** The definition of the session object whose handler or view it runs, if any. */
|
|
11
|
+
definition;
|
|
12
|
+
[VALUES] = new Map();
|
|
13
|
+
constructor(sdk, { explicitCancellation = false, definition = undefined } = {}) {
|
|
14
|
+
this.sdk = sdk;
|
|
15
|
+
this.explicitCancellation = explicitCancellation;
|
|
16
|
+
this.definition = definition;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** The attempt's scope, on its context. */
|
|
20
|
+
const SCOPE = new Link('scope');
|
|
21
|
+
/** `context`, holding `scope`: as it is made, before it is frozen. */
|
|
22
|
+
export const holding = (context, scope) => SCOPE.on(context, scope);
|
|
23
|
+
/** The scope of the attempt whose context `ctx` is, if it is one of @restatedev/sessions. */
|
|
24
|
+
export const scopeOf = (ctx) => SCOPE.of(ctx);
|
|
25
|
+
/** A kind of state an attempt's code keeps, by its context: its key in the attempt's scope. */
|
|
26
|
+
export class ScopeKey {
|
|
27
|
+
/** What it is, for an error. */
|
|
28
|
+
what;
|
|
29
|
+
constructor(what) {
|
|
30
|
+
this.what = what;
|
|
31
|
+
}
|
|
32
|
+
get(ctx) {
|
|
33
|
+
return this.values(ctx).get(this);
|
|
34
|
+
}
|
|
35
|
+
set(ctx, value) {
|
|
36
|
+
this.values(ctx).set(this, value);
|
|
37
|
+
}
|
|
38
|
+
delete(ctx) {
|
|
39
|
+
this.values(ctx).delete(this);
|
|
40
|
+
}
|
|
41
|
+
/** The attempt's, made by `make` the first time. */
|
|
42
|
+
of(ctx, make) {
|
|
43
|
+
const values = this.values(ctx);
|
|
44
|
+
if (!values.has(this))
|
|
45
|
+
values.set(this, make());
|
|
46
|
+
return values.get(this);
|
|
47
|
+
}
|
|
48
|
+
values(ctx) {
|
|
49
|
+
const scope = scopeOf(ctx);
|
|
50
|
+
if (scope === undefined)
|
|
51
|
+
throw new TypeError(`${this.what} takes the context of a session object's handler or view`);
|
|
52
|
+
return scope[VALUES];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=scope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../src/scope.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAMjC,+DAA+D;AAC/D,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;AAEhC,4GAA4G;AAC5G,MAAM,OAAO,KAAK;IAChB,wCAAwC;IAC/B,GAAG,CAAsD;IAClE,4DAA4D;IACnD,oBAAoB,CAAU;IACvC,kFAAkF;IACzE,UAAU,CAAqB;IAC/B,CAAC,MAAM,CAAC,GAAG,IAAI,GAAG,EAA8B,CAAC;IAE1D,YACE,GAAwD,EACxD,EAAE,oBAAoB,GAAG,KAAK,EAAE,UAAU,GAAG,SAA+B,EAAE,GAAG,EAAE;QAEnF,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;QACjD,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;CACF;AAED,2CAA2C;AAC3C,MAAM,K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AAI,KAAK,KAAK,SAAS;YACrB,MAAM,IAAI,SAAS,CAAC,GAAG,IAAI,CAAC,IAAI,0DAA0D,CAAC,CAAC;QAC9F,OAAO,KAAK,CAAC,MAAM,CAAC,CAAC;IACvB,CAAC;CACF"}
|
package/dist/session.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type * as restate from '@restatedev/restate-sdk';
|
|
2
2
|
import { type Serde } from '@restatedev/restate-sdk-core';
|
|
3
3
|
import { type Row, type Connection, type DatabaseWriter, type SqlParam, type DatabaseReader, type SqlValue, type Store } from './database.ts';
|
|
4
|
+
import { type Schema } from './schema.ts';
|
|
4
5
|
import { type Send } from './calls.ts';
|
|
5
6
|
export type { DatabaseReader, DatabaseWriter, Row, SqlParam, SqlValue };
|
|
6
7
|
/**
|
|
@@ -52,9 +53,12 @@ export interface SqlHost {
|
|
|
52
53
|
run(name: string, action: () => void): PromiseLike<void>;
|
|
53
54
|
genericSend(send: restate.GenericSend<Uint8Array>): unknown;
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
/** What a session object gives its attempts: its schema, and a wrapper of its store (fault injection, in tests). */
|
|
57
|
+
export interface ObjectConfig {
|
|
58
|
+
/** The object's own schema, which each of its databases is made by. */
|
|
59
|
+
readonly schema?: Schema;
|
|
60
|
+
wrapStore?: (store: Store) => Store;
|
|
61
|
+
}
|
|
58
62
|
/**
|
|
59
63
|
* `connection`, opened without the SDK (`open`), as a handler's `ctx.db`:
|
|
60
64
|
* for a library's tests, and tools. Its transactions send nothing, and a
|
|
@@ -91,14 +95,19 @@ export declare function database(db: Database, name: string): Database;
|
|
|
91
95
|
/**
|
|
92
96
|
* An attempt's SQL session: opened on its first use, or as an exclusive
|
|
93
97
|
* 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
|
|
95
|
-
* ({@link database}), which has neither the object's schema
|
|
98
|
+
* and saved when the handler ends ({@link end}). With `name`, of the key's
|
|
99
|
+
* database `name` ({@link database}), which has neither the object's schema
|
|
100
|
+
* nor an outbox.
|
|
96
101
|
*/
|
|
97
102
|
export declare class Attempt {
|
|
98
103
|
/** `ctx.db`. */
|
|
99
104
|
readonly db: Database;
|
|
100
105
|
private readonly ctx;
|
|
106
|
+
/** Its object's: the key's other databases share its store's wrapper, and have none of its schema. */
|
|
107
|
+
private readonly config;
|
|
101
108
|
private readonly name;
|
|
109
|
+
/** Whether it is the object's own database of an exclusive handler: the one with an outbox. */
|
|
110
|
+
private readonly hasOutbox;
|
|
102
111
|
/** The key's other databases this attempt opened, by name. */
|
|
103
112
|
private readonly databases;
|
|
104
113
|
/** The session, from its first use on. */
|
|
@@ -108,42 +117,75 @@ export declare class Attempt {
|
|
|
108
117
|
/** The schemas this attempt's database has all the steps of. */
|
|
109
118
|
private readonly ensured;
|
|
110
119
|
private ended;
|
|
111
|
-
|
|
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);
|
|
120
|
+
constructor(ctx: SqlHost, config?: ObjectConfig, name?: string);
|
|
118
121
|
/** The key's database `name`, in this attempt: see {@link database}. */
|
|
119
122
|
database(name: string): Database;
|
|
120
123
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
+
* Open the session now, as the attempt starts, rather than on its first
|
|
125
|
+
* call: the open makes the sends a crashed attempt committed and left
|
|
126
|
+
* unmade, which must not wait for a handler that uses the database.
|
|
124
127
|
*/
|
|
125
|
-
|
|
128
|
+
openNow(): void;
|
|
126
129
|
/**
|
|
127
|
-
* The handler ended with `outcome`:
|
|
128
|
-
*
|
|
129
|
-
* a storage error ended closes now, rather than when it is collected.
|
|
130
|
+
* The handler ended with `outcome`: the key's other databases end, then
|
|
131
|
+
* this one ({@link endSession}).
|
|
130
132
|
*/
|
|
131
133
|
end<T>(outcome: Outcome<T>): Promise<T>;
|
|
132
134
|
/**
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
135
|
+
* `body` as one transaction. In the object's own database of an exclusive
|
|
136
|
+
* handler, its sends commit with it, in the outbox, and are made with its
|
|
137
|
+
* commit, right after its writes and before it waits for anything
|
|
138
|
+
* (`withCommit`): Restate stores an attempt's commands in order, so they
|
|
139
|
+
* are stored only if the commit is, and whatever fails the commit's wait (a
|
|
140
|
+
* cancellation, say) comes after them. A second commit empties the outbox
|
|
141
|
+
* before `transaction` resolves: left until the handler's end, they would
|
|
142
|
+
* be made again by an attempt that resumes a long wait (an approval), past
|
|
143
|
+
* the idempotency retention that drops a repeat.
|
|
136
144
|
*/
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
|
|
145
|
+
private transaction;
|
|
146
|
+
/**
|
|
147
|
+
* Commit with `handle` the outbox as committed, but the sends stored since,
|
|
148
|
+
* and with `outgoing`, which the commit makes. Unchanged, it is not
|
|
149
|
+
* written again.
|
|
150
|
+
*/
|
|
151
|
+
private commitOutbox;
|
|
140
152
|
/**
|
|
141
153
|
* `call` on the session, opening it on the first; its failure as the
|
|
142
|
-
* handler fails with it
|
|
143
|
-
*
|
|
144
|
-
*
|
|
154
|
+
* handler fails with it. The call that fails on a session that a failure
|
|
155
|
+
* ended is its last: the next opens another, which reads what is stored.
|
|
156
|
+
* So the failure of an open made as the attempt started goes to the first
|
|
157
|
+
* call, as it would had that call opened it.
|
|
145
158
|
*/
|
|
146
159
|
private call;
|
|
160
|
+
/** The session, opening one if there is none, or the one there is was retired. */
|
|
161
|
+
private current;
|
|
162
|
+
private open;
|
|
163
|
+
private start;
|
|
164
|
+
/**
|
|
165
|
+
* End the session, then settle as the handler did: an SQL error that
|
|
166
|
+
* escaped it becomes terminal. The handler's error stands: what it
|
|
167
|
+
* committed is stored, and an outbox left full is made by the next open.
|
|
168
|
+
* A failure to end the session fails a handler that succeeded, which a
|
|
169
|
+
* retry then ends (a transaction it left open, say).
|
|
170
|
+
*/
|
|
171
|
+
private endSession;
|
|
172
|
+
/**
|
|
173
|
+
* Close the session as the attempt ends. A view's closes: it read the
|
|
174
|
+
* snapshot it opened on, and one that outlived 16 commits failed its read
|
|
175
|
+
* ("is gone"), which is retried. Another is saved, its outbox emptied. One
|
|
176
|
+
* that a failure ended closes, and the object's own database is opened
|
|
177
|
+
* again and saved: it may hold sends unmade (a crash left them, and this
|
|
178
|
+
* attempt's open failed) or made and not emptied (the commit's wait
|
|
179
|
+
* failed), and no attempt may follow this one (a cancelled invocation's),
|
|
180
|
+
* nor the key's next invocation come within the idempotency retention.
|
|
181
|
+
*/
|
|
182
|
+
private close;
|
|
183
|
+
/** Empty the outbox and save the session, which closes if that fails. */
|
|
184
|
+
private save;
|
|
185
|
+
/** The object's schema, which the key's other databases have none of. */
|
|
186
|
+
private ownSchema;
|
|
187
|
+
/** Empty the database in the transaction `handle` ({@link reset}), and apply the schemas this attempt applied again. */
|
|
188
|
+
private reset;
|
|
147
189
|
/** Apply the steps of `schemas` that the database lacks, each schema once per attempt. */
|
|
148
190
|
private ensureSchemas;
|
|
149
191
|
/** 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. */
|
|
@@ -155,12 +197,6 @@ export declare class Attempt {
|
|
|
155
197
|
* commit after them, which stores them first.
|
|
156
198
|
*/
|
|
157
199
|
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
200
|
}
|
|
165
201
|
/** Run `handler`, then end `attempt`'s SQL session, if it opened one (see {@link Attempt.end}). */
|
|
166
202
|
export declare function withAttempt<T>(handler: () => Promise<T>, attempt: Attempt): Promise<T>;
|