@restatedev/sessions 0.6.0 → 0.8.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 CHANGED
@@ -62,6 +62,28 @@ 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
+ With `RESTATE_CONNECT_KEY` set, `serve` connects out to Restate Cloud
66
+ instead of listening, under `RESTATE_CONNECT_NAME` (the deployment you
67
+ register, `connect://<name>`): the same program either way, with nothing to
68
+ change in it. Both ways go through `served`, so an agent always has its
69
+ companion beside it.
70
+
71
+ `restate.remote` is a handle on something another program serves: named and
72
+ typed here, implemented there. Type it with the definition it names,
73
+ imported for its type alone, so that nothing of the other program is
74
+ imported, bundled or run here:
75
+
76
+ ```ts
77
+ import type { orders as theirs } from '../their/orders.ts';
78
+
79
+ const orders = restate.remote.object<typeof theirs>('orders');
80
+ await ctx.rpc(orders, key).status(id); // typed as the one they serve
81
+ ```
82
+
83
+ Wrong input, an unknown handler and a misspelt name are each a type error.
84
+ `serve` refuses a handle, since a service with no handlers would register
85
+ over the real one.
86
+
65
87
  `RESTATE_SERVE_ONLY=a,b` serves only the services it names, each with what
66
88
  it needs: one program, deployed in parts. For anything else (another port,
67
89
  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;
@@ -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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'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/calls.ts"],"names":[],"mappings":"AAAA,oFAAoF;AAOpF,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AA6F/D,iEAAiE;AACjE,SAAS,QAAQ,CAAC,IAAe;IAC/B,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE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C,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 { remote } from './calls.ts';
6
7
  export { serve, served } from './serve.ts';
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -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;AAGlG,OAAO,EAAE,KAAK,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;AAGpC,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -23,6 +23,8 @@
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
29
  // them; and `served`, the services with what they need, for an endpoint of your own.
28
30
  export { serve, served } from './serve.js';
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,qFAAqF;AACrF,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC"}
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,qFAAqF;AACrF,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC"}
@@ -6,7 +6,7 @@ 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
8
  export { failpoints, PromiseSelector, type Failpoint } from './selector.ts';
9
- export { needing, served } from './serve.ts';
9
+ export { needing, served, serving, type Serving } from './serve.ts';
10
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
@@ -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,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"}
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,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AACpE,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
@@ -10,6 +10,6 @@ export { Link } from './link.js';
10
10
  export { ScopeKey } from './scope.js';
11
11
  export { open } from './database.js';
12
12
  export { failpoints, PromiseSelector } from './selector.js';
13
- export { needing, served } from './serve.js';
13
+ export { needing, served, serving } from './serve.js';
14
14
  export { attach, cancelCalls, cancelled, configOf, contextOf, definitionOf, HEAD_KEY, invoke, start, withStoreWrapper, } from './object.js';
15
15
  //# sourceMappingURL=internal.js.map
@@ -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,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"}
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,OAAO,EAAgB,MAAM,YAAY,CAAC;AACpE,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/serve.d.ts CHANGED
@@ -7,14 +7,38 @@ type Service = restate.ServeOptions['services'][number];
7
7
  */
8
8
  export declare const needing: <D extends object>(definition: D, services: () => Service[]) => D;
9
9
  /**
10
- * Serve `services` on PORT (default 9080), with the services they need
11
- * beside them, each once. RESTATE_SERVE_ONLY, names separated by commas
12
- * (`triage,planner`), serves only those of them, each with what it needs
13
- * beside it: one program (or image), deployed in parts.
10
+ * Serve `services`, with the services they need beside them, each once:
14
11
  *
15
12
  * await restate.serve(notes, orders);
13
+ *
14
+ * On PORT (default 9080), for a Restate server that calls in. With
15
+ * RESTATE_CONNECT_KEY set, it connects out to Restate Cloud instead, under
16
+ * RESTATE_CONNECT_NAME (the deployment you register,
17
+ * `connect://<name>`): the same program, deployed either way, with nothing
18
+ * to change in it.
19
+ *
20
+ * RESTATE_SERVE_ONLY, names separated by commas (`triage,planner`), serves
21
+ * only those of them, each with what it needs beside it: one program (or
22
+ * image), deployed in parts.
23
+ */
24
+ export declare const serve: (...services: Service[]) => restate.Connection | Promise<number>;
25
+ /** What {@link serve} does with `services`, by the environment: see {@link serving}. */
26
+ export interface Serving {
27
+ /** The services it binds, each with what it needs beside it. */
28
+ services: Service[];
29
+ /** Set when it connects out: the deployment name to register, if the environment names one. */
30
+ connect?: {
31
+ name?: string;
32
+ };
33
+ /** The port it listens on, when it does not connect out. */
34
+ port?: number;
35
+ }
36
+ /**
37
+ * What {@link serve} does with `services` under `env`, decided and not done:
38
+ * which services it binds, and whether it listens or connects out. A pure
39
+ * function, so that a program (or a tool) can ask before anything is served.
16
40
  */
17
- export declare const serve: (...services: Service[]) => Promise<number>;
41
+ export declare function serving(services: Service[], env?: Record<string, string | undefined>): Serving;
18
42
  /**
19
43
  * What {@link serve} serves of `services`: each with what it needs beside
20
44
  * it, once; with `names` (separated by commas), only the services it names,
@@ -1 +1 @@
1
- {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,OAAO,MAAM,yBAAyB,CAAC;AAEnD,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;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,EAAE,CAarE"}
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;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,KAAK,gBAAiB,OAAO,EAAE,yCAK3C,CAAC;AAEF,wFAAwF;AACxF,MAAM,WAAW,OAAO;IACtB,gEAAgE;IAChE,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,+FAA+F;IAC/F,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5B,4DAA4D;IAC5D,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GAAG,OAAO,CAQ3G;AAED;;;;;;;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
  /**
@@ -10,14 +11,41 @@ const NEEDS = Symbol.for('restate-sessions.needs');
10
11
  */
11
12
  export const needing = (definition, services) => Object.defineProperty(definition, NEEDS, { value: services });
12
13
  /**
13
- * Serve `services` on PORT (default 9080), with the services they need
14
- * beside them, each once. RESTATE_SERVE_ONLY, names separated by commas
15
- * (`triage,planner`), serves only those of them, each with what it needs
16
- * beside it: one program (or image), deployed in parts.
14
+ * Serve `services`, with the services they need beside them, each once:
17
15
  *
18
16
  * await restate.serve(notes, orders);
17
+ *
18
+ * On PORT (default 9080), for a Restate server that calls in. With
19
+ * RESTATE_CONNECT_KEY set, it connects out to Restate Cloud instead, under
20
+ * RESTATE_CONNECT_NAME (the deployment you register,
21
+ * `connect://<name>`): the same program, deployed either way, with nothing
22
+ * to change in it.
23
+ *
24
+ * RESTATE_SERVE_ONLY, names separated by commas (`triage,planner`), serves
25
+ * only those of them, each with what it needs beside it: one program (or
26
+ * image), deployed in parts.
27
+ */
28
+ export const serve = (...services) => {
29
+ const plan = serving(services);
30
+ return plan.connect === undefined
31
+ ? restate.serve({ services: plan.services, port: plan.port })
32
+ : restate.connect({ services: plan.services, ...plan.connect });
33
+ };
34
+ /**
35
+ * What {@link serve} does with `services` under `env`, decided and not done:
36
+ * which services it binds, and whether it listens or connects out. A pure
37
+ * function, so that a program (or a tool) can ask before anything is served.
19
38
  */
20
- export const serve = (...services) => restate.serve({ services: served(services, process.env.RESTATE_SERVE_ONLY), port: Number(process.env.PORT ?? 9080) });
39
+ export function serving(services, env = process.env) {
40
+ const bound = served(services, env.RESTATE_SERVE_ONLY);
41
+ // Blank counts as unset, as it does in the SDK (its `readEnv` maps '' to
42
+ // undefined): `RESTATE_CONNECT_KEY=` in a .env, or `${RESTATE_CONNECT_KEY:-}`
43
+ // in a compose file, would otherwise connect out and fail for want of a key.
44
+ if (!env.RESTATE_CONNECT_KEY)
45
+ return { services: bound, port: Number(env.PORT ?? 9080) };
46
+ const name = env.RESTATE_CONNECT_NAME;
47
+ return { services: bound, connect: name ? { name } : {} };
48
+ }
21
49
  /**
22
50
  * What {@link serve} serves of `services`: each with what it needs beside
23
51
  * it, once; with `names` (separated by commas), only the services it names,
@@ -27,6 +55,12 @@ export const serve = (...services) => restate.serve({ services: served(services,
27
55
  * for (const service of restate.served([notes, orders])) endpoint.bind(service);
28
56
  */
29
57
  export function served(services, names) {
58
+ // A handle names what another deployment serves. Binding one would register a
59
+ // service with no handlers, over the real one: the collision, from inside.
60
+ const handles = services.filter(isRemote).map((s) => s.name);
61
+ if (handles.length > 0) {
62
+ throw new Error(`${handles.join(', ')}: a remote handle names what another deployment serves, so it cannot be served here`);
63
+ }
30
64
  const all = withNeeds(services);
31
65
  const wanted = (names ?? '')
32
66
  .split(',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C,CAAC;IAC1G,CAAC;IACD,OAAO,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.6.0",
3
+ "version": "0.8.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.6.0",
33
- "@restatedev/sessions-linux-arm64-gnu": "0.6.0",
34
- "@restatedev/sessions-linux-x64-gnu": "0.6.0"
32
+ "@restatedev/sessions-darwin-arm64": "0.8.0",
33
+ "@restatedev/sessions-linux-arm64-gnu": "0.8.0",
34
+ "@restatedev/sessions-linux-x64-gnu": "0.8.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,8 @@ 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
40
  // them; and `served`, the services with what they need, for an endpoint of your own.
39
41
  export { serve, served } from './serve.ts';
package/src/internal.ts CHANGED
@@ -11,7 +11,7 @@ export { Link } from './link.ts';
11
11
  export { ScopeKey } from './scope.ts';
12
12
  export { open, type Connection, type Store, type ConnectionTransaction } from './database.ts';
13
13
  export { failpoints, PromiseSelector, type Failpoint } from './selector.ts';
14
- export { needing, served } from './serve.ts';
14
+ export { needing, served, serving, type Serving } from './serve.ts';
15
15
  export {
16
16
  attach,
17
17
  cancelCalls,
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
 
@@ -16,15 +17,51 @@ export const needing = <D extends object>(definition: D, services: () => Service
16
17
  Object.defineProperty(definition, NEEDS, { value: services });
17
18
 
18
19
  /**
19
- * Serve `services` on PORT (default 9080), with the services they need
20
- * beside them, each once. RESTATE_SERVE_ONLY, names separated by commas
21
- * (`triage,planner`), serves only those of them, each with what it needs
22
- * beside it: one program (or image), deployed in parts.
20
+ * Serve `services`, with the services they need beside them, each once:
23
21
  *
24
22
  * await restate.serve(notes, orders);
23
+ *
24
+ * On PORT (default 9080), for a Restate server that calls in. With
25
+ * RESTATE_CONNECT_KEY set, it connects out to Restate Cloud instead, under
26
+ * RESTATE_CONNECT_NAME (the deployment you register,
27
+ * `connect://<name>`): the same program, deployed either way, with nothing
28
+ * to change in it.
29
+ *
30
+ * RESTATE_SERVE_ONLY, names separated by commas (`triage,planner`), serves
31
+ * only those of them, each with what it needs beside it: one program (or
32
+ * image), deployed in parts.
25
33
  */
26
- export const serve = (...services: Service[]) =>
27
- restate.serve({ services: served(services, process.env.RESTATE_SERVE_ONLY), port: Number(process.env.PORT ?? 9080) });
34
+ export const serve = (...services: Service[]) => {
35
+ const plan = serving(services);
36
+ return plan.connect === undefined
37
+ ? restate.serve({ services: plan.services, port: plan.port })
38
+ : restate.connect({ services: plan.services, ...plan.connect });
39
+ };
40
+
41
+ /** What {@link serve} does with `services`, by the environment: see {@link serving}. */
42
+ export interface Serving {
43
+ /** The services it binds, each with what it needs beside it. */
44
+ services: Service[];
45
+ /** Set when it connects out: the deployment name to register, if the environment names one. */
46
+ connect?: { name?: string };
47
+ /** The port it listens on, when it does not connect out. */
48
+ port?: number;
49
+ }
50
+
51
+ /**
52
+ * What {@link serve} does with `services` under `env`, decided and not done:
53
+ * which services it binds, and whether it listens or connects out. A pure
54
+ * function, so that a program (or a tool) can ask before anything is served.
55
+ */
56
+ export function serving(services: Service[], env: Record<string, string | undefined> = process.env): Serving {
57
+ const bound = served(services, env.RESTATE_SERVE_ONLY);
58
+ // Blank counts as unset, as it does in the SDK (its `readEnv` maps '' to
59
+ // undefined): `RESTATE_CONNECT_KEY=` in a .env, or `${RESTATE_CONNECT_KEY:-}`
60
+ // in a compose file, would otherwise connect out and fail for want of a key.
61
+ if (!env.RESTATE_CONNECT_KEY) return { services: bound, port: Number(env.PORT ?? 9080) };
62
+ const name = env.RESTATE_CONNECT_NAME;
63
+ return { services: bound, connect: name ? { name } : {} };
64
+ }
28
65
 
29
66
  /**
30
67
  * What {@link serve} serves of `services`: each with what it needs beside
@@ -35,6 +72,14 @@ export const serve = (...services: Service[]) =>
35
72
  * for (const service of restate.served([notes, orders])) endpoint.bind(service);
36
73
  */
37
74
  export function served(services: Service[], names?: string): Service[] {
75
+ // A handle names what another deployment serves. Binding one would register a
76
+ // service with no handlers, over the real one: the collision, from inside.
77
+ const handles = services.filter(isRemote).map((s) => s.name);
78
+ if (handles.length > 0) {
79
+ throw new Error(
80
+ `${handles.join(', ')}: a remote handle names what another deployment serves, so it cannot be served here`,
81
+ );
82
+ }
38
83
  const all = withNeeds(services);
39
84
  const wanted = (names ?? '')
40
85
  .split(',')