@restatedev/sessions 0.4.0 → 0.6.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 +24 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +3 -3
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +3 -3
- package/dist/internal.js.map +1 -1
- package/dist/object.d.ts +36 -2
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +57 -2
- package/dist/object.js.map +1 -1
- package/dist/schema.d.ts +6 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +10 -2
- package/dist/schema.js.map +1 -1
- package/dist/selector.d.ts +58 -15
- package/dist/selector.d.ts.map +1 -1
- package/dist/selector.js +121 -66
- package/dist/selector.js.map +1 -1
- package/dist/serve.d.ts +12 -5
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +30 -22
- package/dist/serve.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +3 -2
- package/src/internal.ts +4 -2
- package/src/object.ts +66 -4
- package/src/schema.ts +13 -3
- package/src/selector.ts +144 -74
- package/src/serve.ts +29 -21
package/README.md
CHANGED
|
@@ -61,10 +61,12 @@ your session object can call.
|
|
|
61
61
|
|
|
62
62
|
`restate.serve(...services)` serves them, session objects and the SDK's
|
|
63
63
|
alike, on `PORT` (9080 by default), with what they need beside them (such
|
|
64
|
-
as @restatedev/agents
|
|
65
|
-
`RESTATE_SERVE_ONLY=a,b` serves only the services it names
|
|
66
|
-
deployed in parts. For anything else (another port,
|
|
67
|
-
Lambda handler), the SDK's `restate.endpoint()` is there as
|
|
64
|
+
as the companion each @restatedev/agents agent brings with it).
|
|
65
|
+
`RESTATE_SERVE_ONLY=a,b` serves only the services it names, each with what
|
|
66
|
+
it needs: one program, deployed in parts. For anything else (another port,
|
|
67
|
+
HTTP/1.1, a Lambda handler), the SDK's `restate.endpoint()` is there as
|
|
68
|
+
ever: bind it what `restate.served([...services])` lists, the services with
|
|
69
|
+
what they need.
|
|
68
70
|
|
|
69
71
|
### The contexts
|
|
70
72
|
|
|
@@ -355,6 +357,22 @@ which is part of the cache keys, so one process can serve several Restate
|
|
|
355
357
|
clusters, or a cluster that was wiped and recreated, without mixing up their
|
|
356
358
|
databases.
|
|
357
359
|
|
|
360
|
+
**Large databases in an object store.** By default every checkpoint pack
|
|
361
|
+
stays in the object's state. Set `RESTATE_SQL_OBJECT_STORE` to a URL
|
|
362
|
+
(`s3://bucket/path`, `gs://bucket/path`, `az://container/path`, or
|
|
363
|
+
`file:///a/directory`), and a database whose packs in Restate pass 4 MiB
|
|
364
|
+
(compressed) moves them to the object store in one upload. Restate keeps the
|
|
365
|
+
head, the tail, the manifests and the last few MiB, so a database under
|
|
366
|
+
4 MiB never touches the bucket. Each key's database gets its own directory
|
|
367
|
+
under the URL's path. Credentials and options come from the provider's own
|
|
368
|
+
variables (`AWS_ACCESS_KEY_ID`, `AWS_REGION`, `AWS_ENDPOINT` for MinIO or
|
|
369
|
+
R2, `GOOGLE_SERVICE_ACCOUNT`, `AZURE_STORAGE_ACCOUNT_NAME`, and so on). Two
|
|
370
|
+
rules: once a database has promoted, every process that serves it needs the
|
|
371
|
+
same `RESTATE_SQL_OBJECT_STORE`, or its opens fail; and give each Restate
|
|
372
|
+
cluster its own path, because a database deletes the packs under its
|
|
373
|
+
directory that its own head does not need. A URL that names no store fails
|
|
374
|
+
every open with its message.
|
|
375
|
+
|
|
358
376
|
**No journal replay.** On a retry or a resume, the SDK normally replays the
|
|
359
377
|
journal: each operation returns its recorded result, and must match it.
|
|
360
378
|
That can't work here, because a later attempt makes different reads,
|
|
@@ -507,7 +525,8 @@ in-memory copy of the object's state, through crashes and fencing.
|
|
|
507
525
|
- `configOf`: what a session object's attempts get, for attempts of a test's own.
|
|
508
526
|
|
|
509
527
|
It also has what this repository's other libraries need: `Schema` (tables a
|
|
510
|
-
library owns, applied where it uses them
|
|
528
|
+
library owns, applied where it uses them; `ensureSchemas` applies several in
|
|
529
|
+
one commit), `database` (another database of
|
|
511
530
|
the same key), `reset` (empty the key's database in a transaction), and
|
|
512
531
|
`cancelled` and `cancelCalls` (explicit cancellation, for a handler with
|
|
513
532
|
`explicitCancellation: true`), and `ScopeKey` and `definitionOf`, for what a
|
package/dist/index.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ export type { Database, DatabaseReader, DatabaseWriter, Row, SqlParam, SqlValue,
|
|
|
3
3
|
export type { Step } from './schema.ts';
|
|
4
4
|
export { sessionObject, type Cancel, type Entry, type HandlerOptions, type SessionContext, type ViewContext, } from './object.ts';
|
|
5
5
|
export type { CallOptions, Client, Rpc, Send, SendClient, SendOptions, Target } from './calls.ts';
|
|
6
|
-
export { serve } from './serve.ts';
|
|
6
|
+
export { serve, served } from './serve.ts';
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAwBA,cAAc,yBAAyB,CAAC;AACxC,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,cAAc,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACnH,YAAY,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EACL,aAAa,EACb,KAAK,MAAM,EACX,KAAK,KAAK,EACV,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,WAAW,GACjB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAwBA,cAAc,yBAAyB,CAAC;AACxC,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,cAAc,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AACnH,YAAY,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EACL,aAAa,EACb,KAAK,MAAM,EACX,KAAK,KAAK,EACV,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,WAAW,GACjB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAGlG,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
// takes the services, with what they need beside them).
|
|
24
24
|
export * from '@restatedev/restate-sdk';
|
|
25
25
|
export { sessionObject, } from './object.js';
|
|
26
|
-
// In place of the SDK's: the services, on PORT, with what they need beside
|
|
27
|
-
|
|
26
|
+
// In place of the SDK's: the services, on PORT, with what they need beside
|
|
27
|
+
// them; and `served`, the services with what they need, for an endpoint of your own.
|
|
28
|
+
export { serve, served } from './serve.js';
|
|
28
29
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,0EAA0E;AAC1E,mCAAmC;AACnC,EAAE;AACF,qDAAqD;AACrD,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,EAAE;AACF,iBAAiB;AAEjB,0EAA0E;AAC1E,0EAA0E;AAC1E,wDAAwD;AACxD,cAAc,yBAAyB,CAAC;AAGxC,OAAO,EACL,aAAa,GAMd,MAAM,aAAa,CAAC;AAErB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,0EAA0E;AAC1E,mCAAmC;AACnC,EAAE;AACF,qDAAqD;AACrD,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,EAAE;AACF,iBAAiB;AAEjB,0EAA0E;AAC1E,0EAA0E;AAC1E,wDAAwD;AACxD,cAAc,yBAAyB,CAAC;AAGxC,OAAO,EACL,aAAa,GAMd,MAAM,aAAa,CAAC;AAErB,2EAA2E;AAC3E,qFAAqF;AACrF,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/internal.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export * as sdk from '@restatedev/restate-sdk';
|
|
2
|
-
export { Schema } from './schema.ts';
|
|
2
|
+
export { ensureSchemas, Schema } from './schema.ts';
|
|
3
3
|
export { asDatabase, lazyDatabase, database, reset, Attempt, withAttempt } from './session.ts';
|
|
4
4
|
export type { ObjectConfig, SqlHost } from './session.ts';
|
|
5
5
|
export { Link } from './link.ts';
|
|
6
6
|
export { ScopeKey } from './scope.ts';
|
|
7
7
|
export { open, type Connection, type Store, type ConnectionTransaction } from './database.ts';
|
|
8
|
-
export { PromiseSelector } from './selector.ts';
|
|
8
|
+
export { failpoints, PromiseSelector, type Failpoint } from './selector.ts';
|
|
9
9
|
export { needing, served } from './serve.ts';
|
|
10
|
-
export { cancelCalls, cancelled, configOf, contextOf, definitionOf, HEAD_KEY, invoke, withStoreWrapper, type AttemptContext, } from './object.ts';
|
|
10
|
+
export { attach, cancelCalls, cancelled, configOf, contextOf, definitionOf, HEAD_KEY, invoke, start, withStoreWrapper, type AttemptContext, } from './object.ts';
|
|
11
11
|
export type { DoProgressResult, Selectable, UnresolvedFuture } from './selector.ts';
|
|
12
12
|
//# sourceMappingURL=internal.d.ts.map
|
package/dist/internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC/F,YAAY,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,KAAK,UAAU,EAAE,KAAK,KAAK,EAAE,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC9F,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EACL,MAAM,EACN,WAAW,EACX,SAAS,EACT,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,KAAK,cAAc,GACpB,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/internal.js
CHANGED
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
// databases of their own, and the Restate SDK as @restatedev/sessions runs it (its
|
|
5
5
|
// own copy, so that a library's journaled handlers serve beside its objects).
|
|
6
6
|
export * as sdk from '@restatedev/restate-sdk';
|
|
7
|
-
export { Schema } from './schema.js';
|
|
7
|
+
export { ensureSchemas, Schema } from './schema.js';
|
|
8
8
|
export { asDatabase, lazyDatabase, database, reset, Attempt, withAttempt } from './session.js';
|
|
9
9
|
export { Link } from './link.js';
|
|
10
10
|
export { ScopeKey } from './scope.js';
|
|
11
11
|
export { open } from './database.js';
|
|
12
|
-
export { PromiseSelector } from './selector.js';
|
|
12
|
+
export { failpoints, PromiseSelector } from './selector.js';
|
|
13
13
|
export { needing, served } from './serve.js';
|
|
14
|
-
export { cancelCalls, cancelled, configOf, contextOf, definitionOf, HEAD_KEY, invoke, withStoreWrapper, } from './object.js';
|
|
14
|
+
export { attach, cancelCalls, cancelled, configOf, contextOf, definitionOf, HEAD_KEY, invoke, start, withStoreWrapper, } from './object.js';
|
|
15
15
|
//# sourceMappingURL=internal.js.map
|
package/dist/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,6EAA6E;AAC7E,6EAA6E;AAC7E,mFAAmF;AACnF,8EAA8E;AAC9E,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,6EAA6E;AAC7E,6EAA6E;AAC7E,mFAAmF;AACnF,8EAA8E;AAC9E,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE/F,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,IAAI,EAA2D,MAAM,eAAe,CAAC;AAC9F,OAAO,EAAE,UAAU,EAAE,eAAe,EAAkB,MAAM,eAAe,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EACL,MAAM,EACN,WAAW,EACX,SAAS,EACT,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,MAAM,EACN,KAAK,EACL,gBAAgB,GAEjB,MAAM,aAAa,CAAC"}
|
package/dist/object.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
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';
|
|
2
|
+
import type { Serde, VirtualObjectDefinition } from '@restatedev/restate-sdk-core';
|
|
3
|
+
import { type CallOptions, type Rpc, type Send, type Target } from './calls.ts';
|
|
4
4
|
import type { DatabaseReader, Store } from './database.ts';
|
|
5
5
|
import { type Step } from './schema.ts';
|
|
6
6
|
import { type Database, type ObjectConfig, type SqlHost } from './session.ts';
|
|
@@ -160,10 +160,44 @@ export declare function sessionObject<P extends string, H extends Record<string,
|
|
|
160
160
|
metadata?: Record<string, string>;
|
|
161
161
|
options?: restate.ObjectOptions;
|
|
162
162
|
}): VirtualObjectDefinition<P, Functions<H> & Functions<V>>;
|
|
163
|
+
/**
|
|
164
|
+
* Call `target`, and resolve to the id of the call's invocation (`inv_1f…`),
|
|
165
|
+
* not waiting for its result: for a library that waits for it by
|
|
166
|
+
* {@link attach}. It is a call, not a send: a handler with
|
|
167
|
+
* `explicitCancellation` whose `cancelCalls` cancels the calls of its
|
|
168
|
+
* attempt cancels this one too, as a send's would not be.
|
|
169
|
+
*
|
|
170
|
+
* Its result is left as it comes. A call of a workflow's `run` whose run of
|
|
171
|
+
* that id started already fails ("the workflow method was already
|
|
172
|
+
* invoked"), whatever its idempotency key, but its invocation id is that
|
|
173
|
+
* run's: so a new attempt that calls again gets the id of the run an
|
|
174
|
+
* earlier one started, and its `cancelCalls` cancels that run.
|
|
175
|
+
*/
|
|
176
|
+
export declare function start(ctx: SessionContext, target: Target & CallOptions): Promise<string>;
|
|
177
|
+
/**
|
|
178
|
+
* The result of invocation `invocationId` (such as {@link start}'s), once it
|
|
179
|
+
* ends: its output, or its terminal error. Waiting for it cancels nothing
|
|
180
|
+
* when the attempt ends: the invocation is its own.
|
|
181
|
+
*/
|
|
182
|
+
export declare function attach<O = unknown>(ctx: SessionContext, invocationId: string, outputSerde?: Serde<O>): Promise<O>;
|
|
163
183
|
/**
|
|
164
184
|
* Resolves when Restate cancels the invocation of `ctx`, a handler's with
|
|
165
185
|
* `explicitCancellation: true`, whose awaits are left as they are: for a
|
|
166
186
|
* library that stops its own work then (a model's request, say).
|
|
187
|
+
*
|
|
188
|
+
* It watches for the cancellation, and holds nothing: awaited alone, it does
|
|
189
|
+
* not suspend the invocation, and Restate is not told that the handler waits
|
|
190
|
+
* (see selector.ts: the attempt's journal has a run named `work` instead,
|
|
191
|
+
* for the handler's own work). The cancel signal comes while Restate keeps
|
|
192
|
+
* the invocation's input open. Once Restate closed it (the handler sent and
|
|
193
|
+
* got nothing for the inactivity timeout), a cancellation resolves this at
|
|
194
|
+
* the handler's next await of Restate's, which suspends the invocation and
|
|
195
|
+
* resumes it at once, or not at all if it awaits nothing more.
|
|
196
|
+
*
|
|
197
|
+
* So it is not a way to park a handler until it is cancelled. One that
|
|
198
|
+
* awaits this and nothing else is not suspended: its attempt stays open past
|
|
199
|
+
* the inactivity timeout, Restate aborts it at the abort timeout and retries
|
|
200
|
+
* it from the start, and so on until the cancellation comes.
|
|
167
201
|
*/
|
|
168
202
|
export declare const cancelled: (ctx: SessionContext) => Promise<void>;
|
|
169
203
|
/**
|
package/dist/object.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
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,KAAK,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AACnF,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,GAAG,EAAS,KAAK,IAAI,EAAU,KAAK,MAAM,EAAE,MAAM,YAAY,CAAC;AAC/F,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAA8B,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AAIpE,OAAO,EAAE,KAAK,QAAQ,EAAW,KAAK,YAAY,EAAE,KAAK,OAAO,EAAe,MAAM,cAAc,CAAC;AAEpG;;;;;;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,Q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C,MAAM,CAAC,CAa9F;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,CAAC,GAAG,OAAO,EAChC,GAAG,EAAE,cAAc,EACnB,YAAY,EAAE,MAAM,EACpB,WAAW,GAAE,KAAK,CAAC,CAAC,CAAkC,GACrD,OAAO,CAAC,CAAC,CAAC,CAGZ;AAWD;;;;;;;;;;;;;;;;;;GAkBG;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
CHANGED
|
@@ -222,11 +222,52 @@ export function sessionObject(definition) {
|
|
|
222
222
|
OBJECT.on(made, { object, entries });
|
|
223
223
|
return made;
|
|
224
224
|
}
|
|
225
|
-
/** The
|
|
226
|
-
function
|
|
225
|
+
/** The scope of `ctx`, a session object's handler's context. */
|
|
226
|
+
function scopeOfHandler(ctx, of) {
|
|
227
227
|
const scope = scopeOf(ctx);
|
|
228
228
|
if (scope === undefined)
|
|
229
229
|
throw new restate.TerminalError(`${of} takes a session object's ctx`);
|
|
230
|
+
return scope;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Call `target`, and resolve to the id of the call's invocation (`inv_1f…`),
|
|
234
|
+
* not waiting for its result: for a library that waits for it by
|
|
235
|
+
* {@link attach}. It is a call, not a send: a handler with
|
|
236
|
+
* `explicitCancellation` whose `cancelCalls` cancels the calls of its
|
|
237
|
+
* attempt cancels this one too, as a send's would not be.
|
|
238
|
+
*
|
|
239
|
+
* Its result is left as it comes. A call of a workflow's `run` whose run of
|
|
240
|
+
* that id started already fails ("the workflow method was already
|
|
241
|
+
* invoked"), whatever its idempotency key, but its invocation id is that
|
|
242
|
+
* run's: so a new attempt that calls again gets the id of the run an
|
|
243
|
+
* earlier one started, and its `cancelCalls` cancels that run.
|
|
244
|
+
*/
|
|
245
|
+
export async function start(ctx, target) {
|
|
246
|
+
const { service, key, handler, input, inputSerde, idempotencyKey, headers } = target;
|
|
247
|
+
const called = scopeOfHandler(ctx, 'start').sdk.genericCall({
|
|
248
|
+
service,
|
|
249
|
+
method: handler,
|
|
250
|
+
key,
|
|
251
|
+
parameter: input,
|
|
252
|
+
inputSerde: inputSerde ?? restate.serde.json,
|
|
253
|
+
outputSerde: restate.serde.binary,
|
|
254
|
+
idempotencyKey,
|
|
255
|
+
headers,
|
|
256
|
+
});
|
|
257
|
+
return String(await called.invocationId);
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* The result of invocation `invocationId` (such as {@link start}'s), once it
|
|
261
|
+
* ends: its output, or its terminal error. Waiting for it cancels nothing
|
|
262
|
+
* when the attempt ends: the invocation is its own.
|
|
263
|
+
*/
|
|
264
|
+
export function attach(ctx, invocationId, outputSerde = restate.serde.json) {
|
|
265
|
+
const { sdk } = scopeOfHandler(ctx, 'attach');
|
|
266
|
+
return sdk.invocation(restate.InvocationIdParser.fromString(invocationId)).attach(outputSerde);
|
|
267
|
+
}
|
|
268
|
+
/** The SDK's context behind `ctx`, a handler's with `explicitCancellation: true`. */
|
|
269
|
+
function explicitOf(ctx, of) {
|
|
270
|
+
const scope = scopeOfHandler(ctx, of);
|
|
230
271
|
if (!scope.explicitCancellation) {
|
|
231
272
|
throw new restate.TerminalError(`${of} takes the ctx of a handler with explicitCancellation: true`);
|
|
232
273
|
}
|
|
@@ -236,6 +277,20 @@ function explicitOf(ctx, of) {
|
|
|
236
277
|
* Resolves when Restate cancels the invocation of `ctx`, a handler's with
|
|
237
278
|
* `explicitCancellation: true`, whose awaits are left as they are: for a
|
|
238
279
|
* library that stops its own work then (a model's request, say).
|
|
280
|
+
*
|
|
281
|
+
* It watches for the cancellation, and holds nothing: awaited alone, it does
|
|
282
|
+
* not suspend the invocation, and Restate is not told that the handler waits
|
|
283
|
+
* (see selector.ts: the attempt's journal has a run named `work` instead,
|
|
284
|
+
* for the handler's own work). The cancel signal comes while Restate keeps
|
|
285
|
+
* the invocation's input open. Once Restate closed it (the handler sent and
|
|
286
|
+
* got nothing for the inactivity timeout), a cancellation resolves this at
|
|
287
|
+
* the handler's next await of Restate's, which suspends the invocation and
|
|
288
|
+
* resumes it at once, or not at all if it awaits nothing more.
|
|
289
|
+
*
|
|
290
|
+
* So it is not a way to park a handler until it is cancelled. One that
|
|
291
|
+
* awaits this and nothing else is not suspended: its attempt stays open past
|
|
292
|
+
* the inactivity timeout, Restate aborts it at the abort timeout and retries
|
|
293
|
+
* it from the start, and so on until the cancellation comes.
|
|
239
294
|
*/
|
|
240
295
|
export const cancelled = async (ctx) => {
|
|
241
296
|
await explicitOf(ctx, 'cancelled').cancellation();
|
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,OAAO,MAAM,yBAAyB,CAAC;AAEnD,OAAO,
|
|
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,EAA8B,KAAK,EAAa,MA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C,CAAC,mBAAmB,EAAE,CAAC;AAC7D,CAAC,CAAC"}
|
package/dist/schema.d.ts
CHANGED
|
@@ -13,6 +13,12 @@ export declare class Schema {
|
|
|
13
13
|
*/
|
|
14
14
|
ensure(db: DatabaseReader | Connection): Promise<void>;
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Apply the steps of `schemas` that `db` lacks, as {@link Schema.ensure}
|
|
18
|
+
* does each, in one transaction: a database that lacks several (a key's
|
|
19
|
+
* first handler, say) gets them in one commit rather than one each.
|
|
20
|
+
*/
|
|
21
|
+
export declare function ensureSchemas(db: DatabaseReader | Connection, schemas: readonly Schema[]): Promise<void>;
|
|
16
22
|
/** How a database applies schemas: a handler's (`ctx.db`, its reader), or one of `asDatabase`. */
|
|
17
23
|
type Ensure = (schemas: readonly Schema[]) => Promise<void>;
|
|
18
24
|
/** `db`, which applies schemas with `ensure` (see {@link Schema.ensure}). */
|
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAuBA,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,CAErD;CACF;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,cAAc,GAAG,UAAU,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAGxG;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
|
@@ -23,10 +23,18 @@ export class Schema {
|
|
|
23
23
|
* handler's are its own, vanishing with its session.
|
|
24
24
|
*/
|
|
25
25
|
ensure(db) {
|
|
26
|
-
|
|
27
|
-
return ensure ? ensure([this]) : apply(db, [this]);
|
|
26
|
+
return ensureSchemas(db, [this]);
|
|
28
27
|
}
|
|
29
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Apply the steps of `schemas` that `db` lacks, as {@link Schema.ensure}
|
|
31
|
+
* does each, in one transaction: a database that lacks several (a key's
|
|
32
|
+
* first handler, say) gets them in one commit rather than one each.
|
|
33
|
+
*/
|
|
34
|
+
export function ensureSchemas(db, schemas) {
|
|
35
|
+
const ensure = ensureOf(db);
|
|
36
|
+
return ensure ? ensure(schemas) : apply(db, schemas);
|
|
37
|
+
}
|
|
30
38
|
/** A database's {@link Ensure}. */
|
|
31
39
|
const ENSURE = new Link('Schema.ensure');
|
|
32
40
|
/** `db`, which applies schemas with `ensure` (see {@link Schema.ensure}). */
|
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":"AAwBA,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,OAAO,aAAa,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;IACnC,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,E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*/
|
|
31
31
|
export interface SelectorDriver {
|
|
32
|
+
/**
|
|
33
|
+
* Asks the VM for progress on `future`. With nothing ready, the VM tells
|
|
34
|
+
* Restate what the handler waits for, unless a run is executing; and once
|
|
35
|
+
* the input closed, it suspends the invocation on it (a throw), unless a
|
|
36
|
+
* run of the future is executing.
|
|
37
|
+
*/
|
|
32
38
|
doProgress(future: UnresolvedFuture): DoProgressResult;
|
|
33
39
|
/** Writes out what the VM has buffered. */
|
|
34
40
|
flushOutput(): Promise<void>;
|
|
@@ -36,44 +42,81 @@ export interface SelectorDriver {
|
|
|
36
42
|
awaitExternalProgress(): Promise<void>;
|
|
37
43
|
/** Signals external progress. */
|
|
38
44
|
wake(): void;
|
|
45
|
+
/**
|
|
46
|
+
* The handle of the attempt's working run, made at the first call: a run
|
|
47
|
+
* that the VM hands out like any other (`ExecuteRun`) and that never ends
|
|
48
|
+
* while the attempt lasts. It stands for the handler's work outside Restate.
|
|
49
|
+
*/
|
|
50
|
+
work(): number;
|
|
39
51
|
executeRun(handle: number): void;
|
|
40
|
-
completeEphemeral(completionId: number): Promise<void>;
|
|
41
52
|
/** The attempt cannot go on: suspension, or an error. */
|
|
42
53
|
onError(e: unknown): void;
|
|
43
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* The points of the loop where a test steps in: `pass`, as a pass starts,
|
|
57
|
+
* and `wait`, between a check that found nothing and the wait for progress.
|
|
58
|
+
*/
|
|
59
|
+
export type Failpoint = 'pass' | 'wait';
|
|
60
|
+
/**
|
|
61
|
+
* For tests: what every selector's loop awaits at each of its failpoints, to
|
|
62
|
+
* hold it there while something else happens (the input closes, a signal
|
|
63
|
+
* comes). At `wait`, it gets what the check asked for, and whether that was
|
|
64
|
+
* the invocation's cancellation alone (with the working run). Empty
|
|
65
|
+
* otherwise, and the loop then awaits nothing there.
|
|
66
|
+
*/
|
|
67
|
+
export declare const failpoints: Map<Failpoint, (asked?: UnresolvedFuture, watching?: boolean) => unknown>;
|
|
44
68
|
/**
|
|
45
69
|
* One loop that drives every pending promise of an invocation, so that the
|
|
46
70
|
* invocation has a single await point however many promises user code awaits
|
|
47
71
|
* at once, with its own combinators or none.
|
|
48
72
|
*
|
|
49
|
-
* A promise is registered once and stays until it settles.
|
|
50
|
-
*
|
|
51
|
-
* pending promises to complete: so a suspension waits for any of
|
|
52
|
-
* pending run starts whichever promise is awaited first, and a
|
|
53
|
-
* reaches all of them. Registering wakes the loop, so a promise
|
|
54
|
-
* while it waits is part of the next
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
73
|
+
* A promise is registered once and stays until it settles. Each pass of the
|
|
74
|
+
* loop settles what is ready, then asks the VM for progress on the first of
|
|
75
|
+
* all the pending promises to complete: so a suspension waits for any of
|
|
76
|
+
* them, a pending run starts whichever promise is awaited first, and a
|
|
77
|
+
* cancellation reaches all of them. Registering wakes the loop, so a promise
|
|
78
|
+
* registered while it waits is part of the next pass. The loop runs while
|
|
79
|
+
* there is something to ask the VM for, and is the only one waiting for
|
|
80
|
+
* external progress.
|
|
81
|
+
*
|
|
82
|
+
* To ask is to say that the handler waits: the VM tells Restate what for,
|
|
83
|
+
* and suspends the invocation on it once the input closed (Restate's
|
|
84
|
+
* inactivity timeout). That holds for every promise but one. A handler with
|
|
85
|
+
* explicit cancellation awaits its cancellation (`cancelled(ctx)`) to stop
|
|
86
|
+
* work it does outside Restate, a model's request, say: it watches for it,
|
|
87
|
+
* and does not wait for it. Reported as awaited, the cancel signal would be
|
|
88
|
+
* all Restate believes the handler waits for; and suspended on it, the
|
|
89
|
+
* invocation would end its attempt in the middle of that work, with a
|
|
90
|
+
* cancellation as the only thing to resume it.
|
|
91
|
+
*
|
|
92
|
+
* So with only the cancellation pending, the loop asks for it together with
|
|
93
|
+
* the attempt's working run (`SelectorDriver.work`), which says what is true:
|
|
94
|
+
* the handler is at work on something of its own, as inside `ctx.run`. While
|
|
95
|
+
* a run executes, the VM reports no await, and does not suspend on a future
|
|
96
|
+
* the run is part of, whether the input is open or closed; and it still
|
|
97
|
+
* finds the cancel signal when it comes. See `awaited`.
|
|
59
98
|
*/
|
|
60
99
|
export declare class PromiseSelector {
|
|
61
100
|
private readonly pending;
|
|
62
|
-
private readonly ephemeral;
|
|
63
101
|
private running;
|
|
64
102
|
private closed;
|
|
65
103
|
private waiting;
|
|
104
|
+
private watching;
|
|
66
105
|
private readonly driver;
|
|
67
106
|
constructor(driver: SelectorDriver);
|
|
68
107
|
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
108
|
/** Stops the loop (it finds nothing pending), at the end of the attempt. */
|
|
73
109
|
close(): void;
|
|
74
110
|
private wake;
|
|
75
111
|
/** The promises still pending, for tests. */
|
|
76
112
|
get size(): number;
|
|
113
|
+
/**
|
|
114
|
+
* What to ask the VM for: the first of the pending promises to complete,
|
|
115
|
+
* or undefined with nothing pending. With only the invocation's
|
|
116
|
+
* cancellation pending, the handler watches and waits for nothing: the
|
|
117
|
+
* working run goes with it (see the class).
|
|
118
|
+
*/
|
|
119
|
+
private awaited;
|
|
77
120
|
private loop;
|
|
78
121
|
}
|
|
79
122
|
/**
|
package/dist/selector.d.ts.map
CHANGED
|
@@ -1 +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,EAAE,gBAAgB,EAAE,CAAA;C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