@restatedev/sessions 0.7.0 → 0.9.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 +29 -0
- package/dist/calls.d.ts +24 -0
- package/dist/calls.d.ts.map +1 -1
- package/dist/calls.js +35 -0
- package/dist/calls.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/serve.d.ts +17 -0
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +20 -0
- package/dist/serve.js.map +1 -1
- package/package.json +4 -4
- package/src/calls.ts +39 -0
- package/src/index.ts +5 -2
- package/src/serve.ts +27 -0
package/README.md
CHANGED
|
@@ -62,6 +62,35 @@ your session object can call.
|
|
|
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
64
|
as the companion each @restatedev/agents agent brings with it).
|
|
65
|
+
`restate.connect` does the same for Restate Cloud, where the program
|
|
66
|
+
connects out rather than being called in:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
restate.connect({ services: [notes, orders], name: 'notes-v1' });
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`name` is the deployment you register (`connect://notes-v1`), and the key
|
|
73
|
+
is `RESTATE_CONNECT_KEY`. It returns at once, with the SDK's `Connection`;
|
|
74
|
+
`await restate.connect(…).ready` waits for the first handshake. Use this one, not the SDK's own `connect`: the
|
|
75
|
+
SDK's binds only the services you list, leaving out what they need beside
|
|
76
|
+
them, so an agent would run without its companion.
|
|
77
|
+
|
|
78
|
+
`restate.remote` is a handle on something another program serves: named and
|
|
79
|
+
typed here, implemented there. Type it with the definition it names,
|
|
80
|
+
imported for its type alone, so that nothing of the other program is
|
|
81
|
+
imported, bundled or run here:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import type { orders as theirs } from '../their/orders.ts';
|
|
85
|
+
|
|
86
|
+
const orders = restate.remote.object<typeof theirs>('orders');
|
|
87
|
+
await ctx.rpc(orders, key).status(id); // typed as the one they serve
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Wrong input, an unknown handler and a misspelt name are each a type error.
|
|
91
|
+
`serve` refuses a handle, since a service with no handlers would register
|
|
92
|
+
over the real one.
|
|
93
|
+
|
|
65
94
|
`RESTATE_SERVE_ONLY=a,b` serves only the services it names, each with what
|
|
66
95
|
it needs: one program, deployed in parts. For anything else (another port,
|
|
67
96
|
HTTP/1.1, a Lambda handler), the SDK's `restate.endpoint()` is there as
|
package/dist/calls.d.ts
CHANGED
|
@@ -32,6 +32,30 @@ export interface Target {
|
|
|
32
32
|
type Definition = {
|
|
33
33
|
name: string;
|
|
34
34
|
};
|
|
35
|
+
/** Whether `service` is a {@link remote} handle rather than something to serve. */
|
|
36
|
+
export declare const isRemote: (service: object) => boolean;
|
|
37
|
+
/**
|
|
38
|
+
* A handle on something another deployment serves, named and typed but not
|
|
39
|
+
* implemented here: `ctx.rpc`, `ctx.send` and the agents' tools take it as
|
|
40
|
+
* they take a definition, and the call goes out through Restate.
|
|
41
|
+
*
|
|
42
|
+
* Type it with the definition it names, imported for its type alone, so that
|
|
43
|
+
* nothing of the other deployment is imported at run time:
|
|
44
|
+
*
|
|
45
|
+
* import type { workspace as impl } from '../coders/services/workspace.ts';
|
|
46
|
+
*
|
|
47
|
+
* export const workspace = remote.object<typeof impl>('workspace');
|
|
48
|
+
* await ctx.rpc(workspace, key).clone(issue); // typed as the real one
|
|
49
|
+
*
|
|
50
|
+
* The name is checked against the definition's, so a typo is a type error.
|
|
51
|
+
* Serving a handle is one too, at run time: {@link served} refuses it, rather
|
|
52
|
+
* than registering a service with no handlers over the real one.
|
|
53
|
+
*/
|
|
54
|
+
export declare const remote: {
|
|
55
|
+
service: <D extends Definition>(name: D['name']) => D;
|
|
56
|
+
object: <D extends Definition>(name: D['name']) => D;
|
|
57
|
+
workflow: <D extends Definition>(name: D['name']) => D;
|
|
58
|
+
};
|
|
35
59
|
type OfObject<D> = D extends VirtualObjectDefinition<string, infer M> ? M : unknown;
|
|
36
60
|
type OfService<D> = D extends ServiceDefinition<string, infer M> ? M : unknown;
|
|
37
61
|
type OfWorkflow<D> = D extends WorkflowDefinition<string, infer M> ? M : unknown;
|
package/dist/calls.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calls.d.ts","sourceRoot":"","sources":["../src/calls.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,OAAO,MAAM,yBAAyB,CAAC;AAExD,OAAO,KAAK,EACV,QAAQ,EAER,KAAK,EACL,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EACnB,MAAM,8BAA8B,CAAC;AAEtC,yEAAyE;AACzE,MAAM,WAAW,WAAW;IAC1B;;;;;;;OAOG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,2BAA2B;IAC3B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,6BAA6B;AAC7B,MAAM,WAAW,WAAY,SAAQ,WAAW;IAC9C,iFAAiF;IACjF,KAAK,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;CAC3B;AAED,kFAAkF;AAClF,MAAM,WAAW,MAAM;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,0CAA0C;IAC1C,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,UAAU,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;CAC7B;AAED,yGAAyG;AACzG,KAAK,UAAU,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"calls.d.ts","sourceRoot":"","sources":["../src/calls.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,KAAK,OAA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MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACpE,CAAC,CAAC,SAAS,UAAU,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACjF,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG;QAAE,WAAW,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACpF;AAED,yEAAyE;AACzE,MAAM,WAAW,IAAI;IACnB,CAAC,CAAC,SAAS,UAAU,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IACxE,CAAC,CAAC,SAAS,UAAU,EAAE,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;IACrF,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAAC;CACpC;AAwCD,4CAA4C;AAC5C,wBAAgB,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,aAAa,CAAC,GAAG,GAAG,CA8BpE;AAED,8FAA8F;AAC9F,wBAAgB,MAAM,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,IAAI,GAAG,IAAI,CA+B/E"}
|
package/dist/calls.js
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
// oxlint-disable eslint/no-underscore-dangle -- the SDK's names, in its definitions
|
|
2
2
|
import { serde, TerminalError } from '@restatedev/restate-sdk';
|
|
3
|
+
/** Marks a {@link remote}: {@link served} refuses one, since nothing here implements it. */
|
|
4
|
+
const REMOTE = Symbol.for('restate-sessions.remote');
|
|
5
|
+
/** Whether `service` is a {@link remote} handle rather than something to serve. */
|
|
6
|
+
export const isRemote = (service) => REMOTE in service;
|
|
7
|
+
/** A handle of `kind`, carrying what the clients read of a definition: its name and its kind. */
|
|
8
|
+
const handle = (kind, name) => ({
|
|
9
|
+
name,
|
|
10
|
+
// The kind, by both conventions: `_kind` for the clients here, the key
|
|
11
|
+
// itself for @restatedev/agents' tools (`'object' in target`).
|
|
12
|
+
[kind]: {},
|
|
13
|
+
_kind: kind,
|
|
14
|
+
[REMOTE]: true,
|
|
15
|
+
});
|
|
16
|
+
/**
|
|
17
|
+
* A handle on something another deployment serves, named and typed but not
|
|
18
|
+
* implemented here: `ctx.rpc`, `ctx.send` and the agents' tools take it as
|
|
19
|
+
* they take a definition, and the call goes out through Restate.
|
|
20
|
+
*
|
|
21
|
+
* Type it with the definition it names, imported for its type alone, so that
|
|
22
|
+
* nothing of the other deployment is imported at run time:
|
|
23
|
+
*
|
|
24
|
+
* import type { workspace as impl } from '../coders/services/workspace.ts';
|
|
25
|
+
*
|
|
26
|
+
* export const workspace = remote.object<typeof impl>('workspace');
|
|
27
|
+
* await ctx.rpc(workspace, key).clone(issue); // typed as the real one
|
|
28
|
+
*
|
|
29
|
+
* The name is checked against the definition's, so a typo is a type error.
|
|
30
|
+
* Serving a handle is one too, at run time: {@link served} refuses it, rather
|
|
31
|
+
* than registering a service with no handlers over the real one.
|
|
32
|
+
*/
|
|
33
|
+
export const remote = {
|
|
34
|
+
service: (name) => handle('service', name),
|
|
35
|
+
object: (name) => handle('object', name),
|
|
36
|
+
workflow: (name) => handle('workflow', name),
|
|
37
|
+
};
|
|
3
38
|
/** The target, key and options of a typed client's arguments. */
|
|
4
39
|
function clientOf(args) {
|
|
5
40
|
const [def, second, third] = args;
|
package/dist/calls.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calls.js","sourceRoot":"","sources":["../src/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AE,CAAC;YACvB,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC,CAC9E,CAAC;YACd,IAAI,CAAC;gBACH,OAAO;gBACP,MAAM,EAAE,OAAO;gBACf,GAAG;gBACH,SAAS,EAAE,KAAK;gBAChB,UAAU,EAAE,UAAU,IAAI,KAAK,CAAC,IAAI;gBACpC,cAAc;gBACd,OAAO;gBACP,KAAK;aACN,CAAC,CAAC;YACH,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC7C,OAAO,KAAK,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;YAC7B,IAAI,CAAC;gBACH,OAAO,EAAE,GAAG,CAAC,IAAI;gBACjB,MAAM;gBACN,GAAG;gBACH,SAAS,EAAE,KAAK;gBAChB,UAAU,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC,MAAM,CAAC,EAAE,WAAW,IAAI,KAAK,CAAC,IAAI;gBAC9D,cAAc,EAAE,OAAO,CAAC,cAAc;gBACtC,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,KAAK,EAAE,OAAO,CAAC,KAAK;aACrB,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAS,CAAC;AACb,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ 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 {
|
|
6
|
+
export { remote } from './calls.ts';
|
|
7
|
+
export { connect, serve, served } from './serve.ts';
|
|
7
8
|
//# 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;AAElG,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAIpC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -23,7 +23,10 @@
|
|
|
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
|
+
// A handle on what another deployment serves: named and typed, not implemented here.
|
|
27
|
+
export { remote } from './calls.js';
|
|
26
28
|
// In place of the SDK's: the services, on PORT, with what they need beside
|
|
27
|
-
// them;
|
|
28
|
-
|
|
29
|
+
// them; `connect`, the same for Restate Cloud (the SDK's own leaves them out);
|
|
30
|
+
// and `served`, the services with what they need, for an endpoint of your own.
|
|
31
|
+
export { connect, serve, served } from './serve.js';
|
|
29
32
|
//# 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,2EAA2E;AAC3E
|
|
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,qFAAqF;AACrF,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,2EAA2E;AAC3E,+EAA+E;AAC/E,+EAA+E;AAC/E,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/serve.d.ts
CHANGED
|
@@ -15,6 +15,23 @@ export declare const needing: <D extends object>(definition: D, services: () =>
|
|
|
15
15
|
* await restate.serve(notes, orders);
|
|
16
16
|
*/
|
|
17
17
|
export declare const serve: (...services: Service[]) => Promise<number>;
|
|
18
|
+
/**
|
|
19
|
+
* Connect out to Restate Cloud, rather than listening for it: the SDK's
|
|
20
|
+
* `connect`, with the services it needs beside them, each once (the SDK's
|
|
21
|
+
* own leaves them out, so an agent would run without its companion).
|
|
22
|
+
*
|
|
23
|
+
* restate.connect({ services: [notes, orders], name: 'notes-v1' });
|
|
24
|
+
*
|
|
25
|
+
* `name` is the deployment you register (`connect://notes-v1`); the key is
|
|
26
|
+
* RESTATE_CONNECT_KEY. RESTATE_SERVE_ONLY applies as it does to
|
|
27
|
+
* {@link serve}. It returns the SDK's `Connection` and does not wait for
|
|
28
|
+
* the handshake: `await restate.connect(…).ready` is what waits.
|
|
29
|
+
*/
|
|
30
|
+
export declare const connect: (options: ConnectOptions) => restate.Connection;
|
|
31
|
+
/** {@link connect}'s options: the SDK's, whose `services` this module completes. */
|
|
32
|
+
type ConnectOptions = Omit<Parameters<typeof restate.connect>[0], 'services'> & {
|
|
33
|
+
services: Service[];
|
|
34
|
+
};
|
|
18
35
|
/**
|
|
19
36
|
* What {@link serve} serves of `services`: each with what it needs beside
|
|
20
37
|
* it, once; with `names` (separated by commas), only the services it names,
|
package/dist/serve.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,OAAO,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,OAAO,MAAM,yBAAyB,CAAC;AAGnD,KAAK,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAKxD;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,MAAM,cAAc,CAAC,YAAY,MAAM,OAAO,EAAE,KAAG,CACtB,CAAC;AAEhE;;;;;;;GAOG;AACH,eAAO,MAAM,KAAK,gBAAiB,OAAO,EAAE,oBAC2E,CAAC;AAExH;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,OAAO,YAAa,cAAc,uBACsD,CAAC;AAEtG,oFAAoF;AACpF,KAAK,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG;IAAE,QAAQ,EAAE,OAAO,EAAE,CAAA;CAAE,CAAC;AAExG;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,EAAE,CAqBrE"}
|
package/dist/serve.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// `serve`: the services of a program, on PORT, with what they need beside
|
|
2
2
|
// them (a library's objects, such as each @restatedev/agents agent's companion).
|
|
3
3
|
import * as restate from '@restatedev/restate-sdk';
|
|
4
|
+
import { isRemote } from './calls.js';
|
|
4
5
|
/** Where a definition keeps the services it needs served beside it: see {@link needing}. */
|
|
5
6
|
const NEEDS = Symbol.for('restate-sessions.needs');
|
|
6
7
|
/**
|
|
@@ -18,6 +19,19 @@ export const needing = (definition, services) => Object.defineProperty(definitio
|
|
|
18
19
|
* await restate.serve(notes, orders);
|
|
19
20
|
*/
|
|
20
21
|
export const serve = (...services) => restate.serve({ services: served(services, process.env.RESTATE_SERVE_ONLY), port: Number(process.env.PORT ?? 9080) });
|
|
22
|
+
/**
|
|
23
|
+
* Connect out to Restate Cloud, rather than listening for it: the SDK's
|
|
24
|
+
* `connect`, with the services it needs beside them, each once (the SDK's
|
|
25
|
+
* own leaves them out, so an agent would run without its companion).
|
|
26
|
+
*
|
|
27
|
+
* restate.connect({ services: [notes, orders], name: 'notes-v1' });
|
|
28
|
+
*
|
|
29
|
+
* `name` is the deployment you register (`connect://notes-v1`); the key is
|
|
30
|
+
* RESTATE_CONNECT_KEY. RESTATE_SERVE_ONLY applies as it does to
|
|
31
|
+
* {@link serve}. It returns the SDK's `Connection` and does not wait for
|
|
32
|
+
* the handshake: `await restate.connect(…).ready` is what waits.
|
|
33
|
+
*/
|
|
34
|
+
export const connect = (options) => restate.connect({ ...options, services: served(options.services, process.env.RESTATE_SERVE_ONLY) });
|
|
21
35
|
/**
|
|
22
36
|
* What {@link serve} serves of `services`: each with what it needs beside
|
|
23
37
|
* it, once; with `names` (separated by commas), only the services it names,
|
|
@@ -27,6 +41,12 @@ export const serve = (...services) => restate.serve({ services: served(services,
|
|
|
27
41
|
* for (const service of restate.served([notes, orders])) endpoint.bind(service);
|
|
28
42
|
*/
|
|
29
43
|
export function served(services, names) {
|
|
44
|
+
// A handle names what another deployment serves. Binding one would register a
|
|
45
|
+
// service with no handlers, over the real one: the collision, from inside.
|
|
46
|
+
const handles = services.filter(isRemote).map((s) => s.name);
|
|
47
|
+
if (handles.length > 0) {
|
|
48
|
+
throw new Error(`${handles.join(', ')}: a remote handle names what another deployment serves, so it cannot be served here`);
|
|
49
|
+
}
|
|
30
50
|
const all = withNeeds(services);
|
|
31
51
|
const wanted = (names ?? '')
|
|
32
52
|
.split(',')
|
package/dist/serve.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,iFAAiF;AACjF,OAAO,KAAK,OAAO,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,iFAAiF;AACjF,OAAO,KAAK,OAAO,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC,4FAA4F;AAC5F,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;AAEnD;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAmB,UAAa,EAAE,QAAyB,EAAK,EAAE,CACvF,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;AAEhE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,GAAG,QAAmB,EAAE,EAAE,CAC9C,OAAO,CAAC,KAAK,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC;AAExH;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,OAAuB,EAAE,EAAE,CACjD,OAAO,CAAC,OAAO,CAAC,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,QAAQ,EAA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AAO,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAC/D,CAAC;AAED,2DAA2D;AAC3D,SAAS,SAAS,CAAC,QAAmB;IACpC,MAAM,GAAG,GAAG,IAAI,GAAG,EAAmB,CAAC;IACvC,MAAM,GAAG,GAAG,CAAC,OAAgB,EAAE,EAAE;QAC/B,IAAI,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC;YAAE,OAAO;QAClC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC/B,KAAK,MAAM,MAAM,IAAK,OAAyC,CAAC,KAAK,CAAC,EAAE,EAAE,IAAI,EAAE;YAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAChG,CAAC,CAAC;IACF,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACtB,OAAO,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC;AAC3B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@restatedev/sessions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Session objects on Restate: virtual objects with a SQL database per key, kept in the object's state (ctx.db)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"@restatedev/restate-sdk-core": "1.18.2"
|
|
30
30
|
},
|
|
31
31
|
"optionalDependencies": {
|
|
32
|
-
"@restatedev/sessions-darwin-arm64": "0.
|
|
33
|
-
"@restatedev/sessions-linux-arm64-gnu": "0.
|
|
34
|
-
"@restatedev/sessions-linux-x64-gnu": "0.
|
|
32
|
+
"@restatedev/sessions-darwin-arm64": "0.9.0",
|
|
33
|
+
"@restatedev/sessions-linux-arm64-gnu": "0.9.0",
|
|
34
|
+
"@restatedev/sessions-linux-x64-gnu": "0.9.0"
|
|
35
35
|
},
|
|
36
36
|
"engines": {
|
|
37
37
|
"node": ">=24"
|
package/src/calls.ts
CHANGED
|
@@ -49,6 +49,45 @@ export interface Target {
|
|
|
49
49
|
/** A definition the clients take: a service, a virtual object or a workflow, as `restate` makes them. */
|
|
50
50
|
type Definition = { name: string };
|
|
51
51
|
|
|
52
|
+
/** Marks a {@link remote}: {@link served} refuses one, since nothing here implements it. */
|
|
53
|
+
const REMOTE = Symbol.for('restate-sessions.remote');
|
|
54
|
+
|
|
55
|
+
/** Whether `service` is a {@link remote} handle rather than something to serve. */
|
|
56
|
+
export const isRemote = (service: object): boolean => REMOTE in service;
|
|
57
|
+
|
|
58
|
+
/** A handle of `kind`, carrying what the clients read of a definition: its name and its kind. */
|
|
59
|
+
const handle = (kind: 'service' | 'object' | 'workflow', name: string) => ({
|
|
60
|
+
name,
|
|
61
|
+
// The kind, by both conventions: `_kind` for the clients here, the key
|
|
62
|
+
// itself for @restatedev/agents' tools (`'object' in target`).
|
|
63
|
+
[kind]: {},
|
|
64
|
+
_kind: kind,
|
|
65
|
+
[REMOTE]: true,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A handle on something another deployment serves, named and typed but not
|
|
70
|
+
* implemented here: `ctx.rpc`, `ctx.send` and the agents' tools take it as
|
|
71
|
+
* they take a definition, and the call goes out through Restate.
|
|
72
|
+
*
|
|
73
|
+
* Type it with the definition it names, imported for its type alone, so that
|
|
74
|
+
* nothing of the other deployment is imported at run time:
|
|
75
|
+
*
|
|
76
|
+
* import type { workspace as impl } from '../coders/services/workspace.ts';
|
|
77
|
+
*
|
|
78
|
+
* export const workspace = remote.object<typeof impl>('workspace');
|
|
79
|
+
* await ctx.rpc(workspace, key).clone(issue); // typed as the real one
|
|
80
|
+
*
|
|
81
|
+
* The name is checked against the definition's, so a typo is a type error.
|
|
82
|
+
* Serving a handle is one too, at run time: {@link served} refuses it, rather
|
|
83
|
+
* than registering a service with no handlers over the real one.
|
|
84
|
+
*/
|
|
85
|
+
export const remote = {
|
|
86
|
+
service: <D extends Definition>(name: D['name']): D => handle('service', name) as unknown as D,
|
|
87
|
+
object: <D extends Definition>(name: D['name']): D => handle('object', name) as unknown as D,
|
|
88
|
+
workflow: <D extends Definition>(name: D['name']): D => handle('workflow', name) as unknown as D,
|
|
89
|
+
};
|
|
90
|
+
|
|
52
91
|
// The handlers of a definition, of whichever kind: each kind's type only
|
|
53
92
|
// infers from its own definitions, and is `unknown` for the others.
|
|
54
93
|
type OfObject<D> = D extends VirtualObjectDefinition<string, infer M> ? M : unknown;
|
package/src/index.ts
CHANGED
|
@@ -34,6 +34,9 @@ export {
|
|
|
34
34
|
type ViewContext,
|
|
35
35
|
} from './object.ts';
|
|
36
36
|
export type { CallOptions, Client, Rpc, Send, SendClient, SendOptions, Target } from './calls.ts';
|
|
37
|
+
// A handle on what another deployment serves: named and typed, not implemented here.
|
|
38
|
+
export { remote } from './calls.ts';
|
|
37
39
|
// In place of the SDK's: the services, on PORT, with what they need beside
|
|
38
|
-
// them;
|
|
39
|
-
|
|
40
|
+
// them; `connect`, the same for Restate Cloud (the SDK's own leaves them out);
|
|
41
|
+
// and `served`, the services with what they need, for an endpoint of your own.
|
|
42
|
+
export { connect, serve, served } from './serve.ts';
|
package/src/serve.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// `serve`: the services of a program, on PORT, with what they need beside
|
|
2
2
|
// them (a library's objects, such as each @restatedev/agents agent's companion).
|
|
3
3
|
import * as restate from '@restatedev/restate-sdk';
|
|
4
|
+
import { isRemote } from './calls.ts';
|
|
4
5
|
|
|
5
6
|
type Service = restate.ServeOptions['services'][number];
|
|
6
7
|
|
|
@@ -26,6 +27,24 @@ export const needing = <D extends object>(definition: D, services: () => Service
|
|
|
26
27
|
export const serve = (...services: Service[]) =>
|
|
27
28
|
restate.serve({ services: served(services, process.env.RESTATE_SERVE_ONLY), port: Number(process.env.PORT ?? 9080) });
|
|
28
29
|
|
|
30
|
+
/**
|
|
31
|
+
* Connect out to Restate Cloud, rather than listening for it: the SDK's
|
|
32
|
+
* `connect`, with the services it needs beside them, each once (the SDK's
|
|
33
|
+
* own leaves them out, so an agent would run without its companion).
|
|
34
|
+
*
|
|
35
|
+
* restate.connect({ services: [notes, orders], name: 'notes-v1' });
|
|
36
|
+
*
|
|
37
|
+
* `name` is the deployment you register (`connect://notes-v1`); the key is
|
|
38
|
+
* RESTATE_CONNECT_KEY. RESTATE_SERVE_ONLY applies as it does to
|
|
39
|
+
* {@link serve}. It returns the SDK's `Connection` and does not wait for
|
|
40
|
+
* the handshake: `await restate.connect(…).ready` is what waits.
|
|
41
|
+
*/
|
|
42
|
+
export const connect = (options: ConnectOptions) =>
|
|
43
|
+
restate.connect({ ...options, services: served(options.services, process.env.RESTATE_SERVE_ONLY) });
|
|
44
|
+
|
|
45
|
+
/** {@link connect}'s options: the SDK's, whose `services` this module completes. */
|
|
46
|
+
type ConnectOptions = Omit<Parameters<typeof restate.connect>[0], 'services'> & { services: Service[] };
|
|
47
|
+
|
|
29
48
|
/**
|
|
30
49
|
* What {@link serve} serves of `services`: each with what it needs beside
|
|
31
50
|
* it, once; with `names` (separated by commas), only the services it names,
|
|
@@ -35,6 +54,14 @@ export const serve = (...services: Service[]) =>
|
|
|
35
54
|
* for (const service of restate.served([notes, orders])) endpoint.bind(service);
|
|
36
55
|
*/
|
|
37
56
|
export function served(services: Service[], names?: string): Service[] {
|
|
57
|
+
// A handle names what another deployment serves. Binding one would register a
|
|
58
|
+
// service with no handlers, over the real one: the collision, from inside.
|
|
59
|
+
const handles = services.filter(isRemote).map((s) => s.name);
|
|
60
|
+
if (handles.length > 0) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
`${handles.join(', ')}: a remote handle names what another deployment serves, so it cannot be served here`,
|
|
63
|
+
);
|
|
64
|
+
}
|
|
38
65
|
const all = withNeeds(services);
|
|
39
66
|
const wanted = (names ?? '')
|
|
40
67
|
.split(',')
|