@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 +12 -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 +1 -1
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1 -1
- package/dist/internal.js.map +1 -1
- package/dist/serve.d.ts +19 -26
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +16 -30
- package/dist/serve.js.map +1 -1
- package/package.json +4 -4
- package/src/index.ts +3 -2
- package/src/internal.ts +1 -1
- package/src/serve.ts +21 -39
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
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;AAElG,OAAO,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;
|
|
30
|
-
|
|
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
|
|
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/internal.d.ts
CHANGED
|
@@ -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
|
|
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
|
package/dist/internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"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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
|
@@ -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
|
|
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
|
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,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,
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
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
|
|
25
|
-
/**
|
|
26
|
-
|
|
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
|
-
|
|
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,
|
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;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
|
|
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
|
@@ -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
|
|
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
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
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
|
|
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,w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AC,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/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;
|
|
41
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
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
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|