@restatedev/sessions 0.8.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 CHANGED
@@ -62,11 +62,18 @@ 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.
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.
70
77
 
71
78
  `restate.remote` is a handle on something another program serves: named and
72
79
  typed here, implemented there. Type it with the definition it names,
package/dist/index.d.ts CHANGED
@@ -4,5 +4,5 @@ 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
6
  export { remote } from './calls.ts';
7
- export { serve, served } from './serve.ts';
7
+ export { connect, serve, served } from './serve.ts';
8
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;AAElG,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAGpC,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;AAIpC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -26,6 +26,7 @@ export { sessionObject, } from './object.js';
26
26
  // A handle on what another deployment serves: named and typed, not implemented here.
27
27
  export { remote } from './calls.js';
28
28
  // In place of the SDK's: the services, on PORT, with what they need beside
29
- // them; and `served`, the services with what they need, for an endpoint of your own.
30
- export { serve, served } from './serve.js';
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';
31
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,qFAAqF;AACrF,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,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,+EAA+E;AAC/E,+EAA+E;AAC/E,OAAO,EAAE,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, serving, type Serving } from './serve.ts';
9
+ export { needing, served } 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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B,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, serving } from './serve.js';
13
+ export { needing, served } 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,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"}
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/serve.d.ts CHANGED
@@ -7,38 +7,31 @@ 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`, with the services they need beside them, each once:
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.
11
14
  *
12
15
  * await restate.serve(notes, orders);
16
+ */
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).
13
22
  *
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.
23
+ * restate.connect({ services: [notes, orders], name: 'notes-v1' });
19
24
  *
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.
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.
23
29
  */
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. */
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'> & {
28
33
  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.
40
- */
41
- export declare function serving(services: Service[], env?: Record<string, string | undefined>): Serving;
34
+ };
42
35
  /**
43
36
  * What {@link serve} serves of `services`: each with what it needs beside
44
37
  * 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;AAGnD,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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
@@ -11,41 +11,27 @@ const NEEDS = Symbol.for('restate-sessions.needs');
11
11
  */
12
12
  export const needing = (definition, services) => Object.defineProperty(definition, NEEDS, { value: services });
13
13
  /**
14
- * Serve `services`, with the services they need beside them, each once:
14
+ * Serve `services` on PORT (default 9080), with the services they need
15
+ * beside them, each once. RESTATE_SERVE_ONLY, names separated by commas
16
+ * (`triage,planner`), serves only those of them, each with what it needs
17
+ * beside it: one program (or image), deployed in parts.
15
18
  *
16
19
  * 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
20
  */
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
- };
21
+ export const serve = (...services) => restate.serve({ services: served(services, process.env.RESTATE_SERVE_ONLY), port: Number(process.env.PORT ?? 9080) });
34
22
  /**
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.
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.
38
33
  */
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
- }
34
+ export const connect = (options) => restate.connect({ ...options, services: served(options.services, process.env.RESTATE_SERVE_ONLY) });
49
35
  /**
50
36
  * What {@link serve} serves of `services`: each with what it needs beside
51
37
  * it, once; with `names` (separated by commas), only the services it names,
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;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,CA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CAAC,IAAI,CAAC,CAAC,CAAC;IAC/D,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,4BAA4B,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,sBAAsB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,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.8.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.8.0",
33
- "@restatedev/sessions-linux-arm64-gnu": "0.8.0",
34
- "@restatedev/sessions-linux-x64-gnu": "0.8.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/index.ts CHANGED
@@ -37,5 +37,6 @@ export type { CallOptions, Client, Rpc, Send, SendClient, SendOptions, Target }
37
37
  // A handle on what another deployment serves: named and typed, not implemented here.
38
38
  export { remote } from './calls.ts';
39
39
  // In place of the SDK's: the services, on PORT, with what they need beside
40
- // them; and `served`, the services with what they need, for an endpoint of your own.
41
- export { serve, served } from './serve.ts';
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/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, serving, type Serving } from './serve.ts';
14
+ export { needing, served } from './serve.ts';
15
15
  export {
16
16
  attach,
17
17
  cancelCalls,
package/src/serve.ts CHANGED
@@ -17,51 +17,33 @@ export const needing = <D extends object>(definition: D, services: () => Service
17
17
  Object.defineProperty(definition, NEEDS, { value: services });
18
18
 
19
19
  /**
20
- * Serve `services`, with the services they need beside them, each once:
20
+ * Serve `services` on PORT (default 9080), with the services they need
21
+ * beside them, each once. RESTATE_SERVE_ONLY, names separated by commas
22
+ * (`triage,planner`), serves only those of them, each with what it needs
23
+ * beside it: one program (or image), deployed in parts.
21
24
  *
22
25
  * 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.
33
26
  */
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
- }
27
+ export const serve = (...services: Service[]) =>
28
+ restate.serve({ services: served(services, process.env.RESTATE_SERVE_ONLY), port: Number(process.env.PORT ?? 9080) });
50
29
 
51
30
  /**
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.
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.
55
41
  */
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
- }
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[] };
65
47
 
66
48
  /**
67
49
  * What {@link serve} serves of `services`: each with what it needs beside