@restatedev/sessions 0.1.0 → 0.2.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 +7 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +1 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1 -0
- package/dist/internal.js.map +1 -1
- package/dist/serve.d.ts +21 -0
- package/dist/serve.d.ts.map +1 -0
- package/dist/serve.js +49 -0
- package/dist/serve.js.map +1 -0
- package/package.json +4 -4
- package/src/index.ts +4 -1
- package/src/internal.ts +1 -0
- package/src/serve.ts +54 -0
package/README.md
CHANGED
|
@@ -59,6 +59,13 @@ SDK handlers (`restate.handlers.*`) aren't accepted. Journaled work belongs
|
|
|
59
59
|
in a regular `restate.object`, `restate.service` or `restate.workflow`, which
|
|
60
60
|
your session object can call.
|
|
61
61
|
|
|
62
|
+
`restate.serve(...services)` serves them, session objects and the SDK's
|
|
63
|
+
alike, on `PORT` (9080 by default), with what they need beside them (such
|
|
64
|
+
as @restatedev/agents' `signals`, which each agent brings with it).
|
|
65
|
+
`RESTATE_SERVE_ONLY=a,b` serves only the services it names: one program,
|
|
66
|
+
deployed in parts. For anything else (another port, HTTP/1.1, a
|
|
67
|
+
Lambda handler), the SDK's `restate.endpoint()` is there as ever.
|
|
68
|
+
|
|
62
69
|
### The contexts
|
|
63
70
|
|
|
64
71
|
The contexts are small and explicit, and a new one is built for each
|
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,5 @@ export type { Database, DatabaseReader, DatabaseWriter, Row, SqlParam, SqlValue,
|
|
|
3
3
|
export type { Step } from './schema.ts';
|
|
4
4
|
export { sessionObject, type Cancel, type Entry, type HandlerOptions, type SessionContext, type ViewContext, } from './object.ts';
|
|
5
5
|
export type { CallOptions, Client, Rpc, Send, SendClient, SendOptions, Target } from './calls.ts';
|
|
6
|
+
export { serve } from './serve.ts';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
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,KAAK,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -19,7 +19,10 @@
|
|
|
19
19
|
//
|
|
20
20
|
// See README.md.
|
|
21
21
|
// The SDK, and what this module adds to it (or declares in its place: its
|
|
22
|
-
// `Client`, `SendClient` and `Target` are a session object's
|
|
22
|
+
// `Client`, `SendClient` and `Target` are a session object's, and `serve`
|
|
23
|
+
// takes the services, with what they need beside them).
|
|
23
24
|
export * from '@restatedev/restate-sdk';
|
|
24
25
|
export { sessionObject, } from './object.js';
|
|
26
|
+
// In place of the SDK's: the services, on PORT, with what they need beside them.
|
|
27
|
+
export { serve } from './serve.js';
|
|
25
28
|
//# 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
|
|
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,iFAAiF;AACjF,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/internal.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export { asDatabase, lazyDatabase, database, reset, setStoreWrapper, Attempt, wi
|
|
|
4
4
|
export type { SqlHost } from './session.ts';
|
|
5
5
|
export { open, type Connection, type Store, type ConnectionTransaction } from './database.ts';
|
|
6
6
|
export { PromiseSelector } from './selector.ts';
|
|
7
|
+
export { needing, served } from './serve.ts';
|
|
7
8
|
export { cancelCalls, cancelled, contextOf, HEAD_KEY, invoke, type AttemptContext } from './object.ts';
|
|
8
9
|
export type { DoProgressResult, Selectable, UnresolvedFuture } from './selector.ts';
|
|
9
10
|
//# sourceMappingURL=internal.d.ts.map
|
package/dist/internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChH,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,KAAK,UAAU,EAAE,KAAK,KAAK,EAAE,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC9F,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AACvG,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,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAChH,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,IAAI,EAAE,KAAK,UAAU,EAAE,KAAK,KAAK,EAAE,KAAK,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC9F,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AACvG,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/internal.js
CHANGED
|
@@ -8,5 +8,6 @@ export { Schema } from './schema.js';
|
|
|
8
8
|
export { asDatabase, lazyDatabase, database, reset, setStoreWrapper, Attempt, withAttempt } from './session.js';
|
|
9
9
|
export { open } from './database.js';
|
|
10
10
|
export { PromiseSelector } from './selector.js';
|
|
11
|
+
export { needing, served } from './serve.js';
|
|
11
12
|
export { cancelCalls, cancelled, contextOf, HEAD_KEY, invoke } from './object.js';
|
|
12
13
|
//# sourceMappingURL=internal.js.map
|
package/dist/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,6EAA6E;AAC7E,6EAA6E;AAC7E,mFAAmF;AACnF,8EAA8E;AAC9E,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhH,OAAO,EAAE,IAAI,EAA2D,MAAM,eAAe,CAAC;AAC9F,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAuB,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,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhH,OAAO,EAAE,IAAI,EAA2D,MAAM,eAAe,CAAC;AAC9F,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAuB,MAAM,aAAa,CAAC"}
|
package/dist/serve.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as restate from '@restatedev/restate-sdk';
|
|
2
|
+
type Service = restate.ServeOptions['services'][number];
|
|
3
|
+
/**
|
|
4
|
+
* `definition`, which needs `services` served beside it: {@link serve}
|
|
5
|
+
* serves them too. For a library whose objects call one of its own (an
|
|
6
|
+
* agent's `signals`, say).
|
|
7
|
+
*/
|
|
8
|
+
export declare const needing: <D extends object>(definition: D, services: () => Service[]) => D;
|
|
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,signals`), serves only those of them: one program (or
|
|
13
|
+
* image), deployed in parts.
|
|
14
|
+
*
|
|
15
|
+
* await restate.serve(notes, orders);
|
|
16
|
+
*/
|
|
17
|
+
export declare const serve: (...services: Service[]) => Promise<number>;
|
|
18
|
+
/** What {@link serve} serves of `services`: each with what it needs beside it, once, of those `names` names. */
|
|
19
|
+
export declare function served(services: Service[], names?: string): Service[];
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=serve.d.ts.map
|
|
@@ -0,0 +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,gHAAgH;AAChH,wBAAgB,MAAM,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,EAAE,CASrE"}
|
package/dist/serve.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// `serve`: the services of a program, on PORT, with what they need beside
|
|
2
|
+
// them (a library's objects, such as @restatedev/agents' `signals`).
|
|
3
|
+
import * as restate from '@restatedev/restate-sdk';
|
|
4
|
+
/** Where a definition keeps the services it needs served beside it: see {@link needing}. */
|
|
5
|
+
const NEEDS = Symbol.for('restate-sessions.needs');
|
|
6
|
+
/**
|
|
7
|
+
* `definition`, which needs `services` served beside it: {@link serve}
|
|
8
|
+
* serves them too. For a library whose objects call one of its own (an
|
|
9
|
+
* agent's `signals`, say).
|
|
10
|
+
*/
|
|
11
|
+
export const needing = (definition, services) => Object.defineProperty(definition, NEEDS, { value: services });
|
|
12
|
+
/**
|
|
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,signals`), serves only those of them: one program (or
|
|
16
|
+
* image), deployed in parts.
|
|
17
|
+
*
|
|
18
|
+
* await restate.serve(notes, orders);
|
|
19
|
+
*/
|
|
20
|
+
export const serve = (...services) => restate.serve({ services: served(services, process.env.RESTATE_SERVE_ONLY), port: Number(process.env.PORT ?? 9080) });
|
|
21
|
+
/** What {@link serve} serves of `services`: each with what it needs beside it, once, of those `names` names. */
|
|
22
|
+
export function served(services, names) {
|
|
23
|
+
const all = new Map();
|
|
24
|
+
const add = (service) => {
|
|
25
|
+
if (all.has(service.name))
|
|
26
|
+
return;
|
|
27
|
+
all.set(service.name, service);
|
|
28
|
+
for (const needed of service[NEEDS]?.() ?? [])
|
|
29
|
+
add(needed);
|
|
30
|
+
};
|
|
31
|
+
services.forEach(add);
|
|
32
|
+
return only([...all.values()], names);
|
|
33
|
+
}
|
|
34
|
+
/** The `services` that `names` (comma separated) names, or all of them without names; a name of none is an error. */
|
|
35
|
+
function only(services, names) {
|
|
36
|
+
const wanted = (names ?? '')
|
|
37
|
+
.split(',')
|
|
38
|
+
.map((name) => name.trim())
|
|
39
|
+
.filter(Boolean);
|
|
40
|
+
if (wanted.length === 0)
|
|
41
|
+
return services;
|
|
42
|
+
const known = services.map((s) => s.name);
|
|
43
|
+
const unknown = wanted.filter((name) => !known.includes(name));
|
|
44
|
+
if (unknown.length > 0) {
|
|
45
|
+
throw new Error(`RESTATE_SERVE_ONLY names ${unknown.join(', ')}: the services are ${known.join(', ')}`);
|
|
46
|
+
}
|
|
47
|
+
return services.filter((s) => wanted.includes(s.name));
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=serve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,qEAAqE;AACrE,OAAO,KAAK,OAAO,MAAM,yBAAyB,CAAC;AAInD,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,gHAAgH;AAChH,MAAM,UAAU,MAAM,CAAC,QAAmB,EAAE,KAAc;IACxD,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,IAAI,CAAC,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;AACxC,CAAC;AAED,qHAAqH;AACrH,SAAS,IAAI,CAAC,QAAmB,EAAE,KAAyB;IAC1D,MAAM,MAAM,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;SACzB,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;SAC1B,MAAM,CAAC,OAAO,CAAC,CAAC;IACnB,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,QAAQ,CAAC;IACzC,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAC1C,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,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,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACzD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@restatedev/sessions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.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.2.0",
|
|
33
|
+
"@restatedev/sessions-linux-arm64-gnu": "0.2.0",
|
|
34
|
+
"@restatedev/sessions-linux-x64-gnu": "0.2.0"
|
|
35
35
|
},
|
|
36
36
|
"engines": {
|
|
37
37
|
"node": ">=24"
|
package/src/index.ts
CHANGED
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
// See README.md.
|
|
21
21
|
|
|
22
22
|
// The SDK, and what this module adds to it (or declares in its place: its
|
|
23
|
-
// `Client`, `SendClient` and `Target` are a session object's
|
|
23
|
+
// `Client`, `SendClient` and `Target` are a session object's, and `serve`
|
|
24
|
+
// takes the services, with what they need beside them).
|
|
24
25
|
export * from '@restatedev/restate-sdk';
|
|
25
26
|
export type { Database, DatabaseReader, DatabaseWriter, Row, SqlParam, SqlValue, Transaction } from './session.ts';
|
|
26
27
|
export type { Step } from './schema.ts';
|
|
@@ -33,3 +34,5 @@ export {
|
|
|
33
34
|
type ViewContext,
|
|
34
35
|
} from './object.ts';
|
|
35
36
|
export type { CallOptions, Client, Rpc, Send, SendClient, SendOptions, Target } from './calls.ts';
|
|
37
|
+
// In place of the SDK's: the services, on PORT, with what they need beside them.
|
|
38
|
+
export { serve } from './serve.ts';
|
package/src/internal.ts
CHANGED
|
@@ -9,5 +9,6 @@ export { asDatabase, lazyDatabase, database, reset, setStoreWrapper, Attempt, wi
|
|
|
9
9
|
export type { SqlHost } from './session.ts';
|
|
10
10
|
export { open, type Connection, type Store, type ConnectionTransaction } from './database.ts';
|
|
11
11
|
export { PromiseSelector } from './selector.ts';
|
|
12
|
+
export { needing, served } from './serve.ts';
|
|
12
13
|
export { cancelCalls, cancelled, contextOf, HEAD_KEY, invoke, type AttemptContext } from './object.ts';
|
|
13
14
|
export type { DoProgressResult, Selectable, UnresolvedFuture } from './selector.ts';
|
package/src/serve.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// `serve`: the services of a program, on PORT, with what they need beside
|
|
2
|
+
// them (a library's objects, such as @restatedev/agents' `signals`).
|
|
3
|
+
import * as restate from '@restatedev/restate-sdk';
|
|
4
|
+
|
|
5
|
+
type Service = restate.ServeOptions['services'][number];
|
|
6
|
+
|
|
7
|
+
/** Where a definition keeps the services it needs served beside it: see {@link needing}. */
|
|
8
|
+
const NEEDS = Symbol.for('restate-sessions.needs');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* `definition`, which needs `services` served beside it: {@link serve}
|
|
12
|
+
* serves them too. For a library whose objects call one of its own (an
|
|
13
|
+
* agent's `signals`, say).
|
|
14
|
+
*/
|
|
15
|
+
export const needing = <D extends object>(definition: D, services: () => Service[]): D =>
|
|
16
|
+
Object.defineProperty(definition, NEEDS, { value: services });
|
|
17
|
+
|
|
18
|
+
/**
|
|
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,signals`), serves only those of them: one program (or
|
|
22
|
+
* image), deployed in parts.
|
|
23
|
+
*
|
|
24
|
+
* await restate.serve(notes, orders);
|
|
25
|
+
*/
|
|
26
|
+
export const serve = (...services: Service[]) =>
|
|
27
|
+
restate.serve({ services: served(services, process.env.RESTATE_SERVE_ONLY), port: Number(process.env.PORT ?? 9080) });
|
|
28
|
+
|
|
29
|
+
/** What {@link serve} serves of `services`: each with what it needs beside it, once, of those `names` names. */
|
|
30
|
+
export function served(services: Service[], names?: string): Service[] {
|
|
31
|
+
const all = new Map<string, Service>();
|
|
32
|
+
const add = (service: Service) => {
|
|
33
|
+
if (all.has(service.name)) return;
|
|
34
|
+
all.set(service.name, service);
|
|
35
|
+
for (const needed of (service as { [NEEDS]?: () => Service[] })[NEEDS]?.() ?? []) add(needed);
|
|
36
|
+
};
|
|
37
|
+
services.forEach(add);
|
|
38
|
+
return only([...all.values()], names);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The `services` that `names` (comma separated) names, or all of them without names; a name of none is an error. */
|
|
42
|
+
function only(services: Service[], names: string | undefined) {
|
|
43
|
+
const wanted = (names ?? '')
|
|
44
|
+
.split(',')
|
|
45
|
+
.map((name) => name.trim())
|
|
46
|
+
.filter(Boolean);
|
|
47
|
+
if (wanted.length === 0) return services;
|
|
48
|
+
const known = services.map((s) => s.name);
|
|
49
|
+
const unknown = wanted.filter((name) => !known.includes(name));
|
|
50
|
+
if (unknown.length > 0) {
|
|
51
|
+
throw new Error(`RESTATE_SERVE_ONLY names ${unknown.join(', ')}: the services are ${known.join(', ')}`);
|
|
52
|
+
}
|
|
53
|
+
return services.filter((s) => wanted.includes(s.name));
|
|
54
|
+
}
|