@restatedev/sessions 0.11.1 → 0.12.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 +330 -178
- package/dist/addon.d.ts +1 -0
- package/dist/addon.d.ts.map +1 -1
- package/dist/addon.js.map +1 -1
- package/dist/calls.d.ts +28 -28
- package/dist/calls.d.ts.map +1 -1
- package/dist/calls.js +25 -25
- package/dist/calls.js.map +1 -1
- package/dist/database.d.ts +90 -166
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +137 -249
- package/dist/database.js.map +1 -1
- package/dist/driver.d.ts +129 -126
- package/dist/driver.d.ts.map +1 -1
- package/dist/driver.js +337 -276
- package/dist/driver.js.map +1 -1
- package/dist/endpoint.d.ts +47 -5
- package/dist/endpoint.d.ts.map +1 -1
- package/dist/endpoint.js +175 -60
- package/dist/endpoint.js.map +1 -1
- package/dist/handler.d.ts +20 -17
- package/dist/handler.d.ts.map +1 -1
- package/dist/handler.js +161 -127
- package/dist/handler.js.map +1 -1
- package/dist/host.d.ts +29 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +2 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -26
- package/dist/index.js.map +1 -1
- package/dist/internal.d.ts +11 -11
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +20 -16
- package/dist/internal.js.map +1 -1
- package/dist/link.d.ts +1 -2
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +4 -5
- package/dist/link.js.map +1 -1
- package/dist/log.d.ts +14 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +21 -0
- package/dist/log.js.map +1 -0
- package/dist/object.d.ts +217 -142
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +195 -241
- package/dist/object.js.map +1 -1
- package/dist/platform.d.ts +0 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +4 -6
- package/dist/platform.js.map +1 -1
- package/dist/schema.d.ts +14 -22
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +31 -69
- package/dist/schema.js.map +1 -1
- package/dist/serve.d.ts +11 -17
- package/dist/serve.d.ts.map +1 -1
- package/dist/serve.js +21 -39
- package/dist/serve.js.map +1 -1
- package/dist/session.d.ts +58 -236
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +206 -513
- package/dist/session.js.map +1 -1
- package/dist/stop.d.ts +59 -0
- package/dist/stop.d.ts.map +1 -0
- package/dist/stop.js +220 -0
- package/dist/stop.js.map +1 -0
- package/dist/vm.d.ts +108 -29
- package/dist/vm.d.ts.map +1 -1
- package/dist/vm.js +43 -10
- package/dist/vm.js.map +1 -1
- package/package.json +4 -4
- package/src/addon.ts +1 -0
- package/src/calls.ts +51 -47
- package/src/database.ts +195 -339
- package/src/driver.ts +379 -315
- package/src/endpoint.ts +217 -62
- package/src/handler.ts +183 -164
- package/src/host.ts +28 -0
- package/src/index.ts +6 -26
- package/src/internal.ts +28 -39
- package/src/link.ts +4 -5
- package/src/log.ts +42 -0
- package/src/object.ts +379 -335
- package/src/platform.ts +4 -6
- package/src/schema.ts +37 -103
- package/src/serve.ts +20 -41
- package/src/session.ts +236 -613
- package/src/stop.ts +225 -0
- package/src/vm.ts +151 -55
- package/dist/scope.d.ts +0 -38
- package/dist/scope.d.ts.map +0 -1
- package/dist/scope.js +0 -55
- package/dist/scope.js.map +0 -1
- package/src/scope.ts +0 -78
package/dist/platform.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
// The platforms
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// (.github/workflows/packages.yml); `pnpm build` builds this machine's.
|
|
6
|
-
/** The platforms built, as their packages name them. */
|
|
1
|
+
// The platforms the addon ships for. Each is an optional dependency package
|
|
2
|
+
// (npm/<platform>, `@restatedev/sessions-<platform>`), and a package manager
|
|
3
|
+
// installs only the one matching `os`, `cpu` and `libc`. CI builds them
|
|
4
|
+
// (.github/workflows/packages.yml); `pnpm build` builds the one for this machine.
|
|
7
5
|
export const PLATFORMS = ['linux-x64-gnu', 'linux-arm64-gnu', 'darwin-arm64'];
|
|
8
6
|
/** This machine's platform, as a package of the addon would name it. */
|
|
9
7
|
export function platform() {
|
package/dist/platform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../src/platform.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,6EAA6E;AAC7E,wEAAwE;AACxE,kFAAkF;AAElF,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,eAAe,EAAE,iBAAiB,EAAE,cAAc,CAAU,CAAC;AAEvF,wEAAwE;AACxE,MAAM,UAAU,QAAQ;IACtB,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO;QAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAC/E,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,SAAS,EAAmD,CAAC;IAC3F,OAAO,SAAS,OAAO,CAAC,IAAI,IAAI,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;AACxF,CAAC"}
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,42 +1,34 @@
|
|
|
1
|
-
import
|
|
2
|
-
/**
|
|
1
|
+
import { Connection, type DatabaseReader, type DatabaseWriter } from './database.ts';
|
|
2
|
+
/**
|
|
3
|
+
* A statement, or an async function of the transaction (to move data). A step
|
|
4
|
+
* never changes or goes away once it ran: a change is a new step.
|
|
5
|
+
*/
|
|
3
6
|
export type Step = string | ((tx: DatabaseWriter) => Promise<void>);
|
|
4
|
-
/** A part of a database
|
|
7
|
+
/** A named part of a database schema: the `steps` that make it, in order. */
|
|
5
8
|
export declare class Schema {
|
|
6
9
|
readonly name: string;
|
|
7
10
|
readonly steps: readonly Step[];
|
|
8
11
|
constructor(name: string, steps: readonly Step[]);
|
|
9
12
|
/**
|
|
10
|
-
* Apply the steps `db` lacks
|
|
11
|
-
*
|
|
12
|
-
* handler's are its own, vanishing with its session.
|
|
13
|
+
* Apply the steps that `db` lacks, in any object. On `ctx.db` this runs
|
|
14
|
+
* once per attempt. In a view the steps are never stored.
|
|
13
15
|
*/
|
|
14
16
|
ensure(db: DatabaseReader | Connection): Promise<void>;
|
|
15
17
|
}
|
|
16
18
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* first handler, say) gets them in one commit rather than one each.
|
|
19
|
+
* {@link Schema.ensure} for several schemas in one transaction, so a database
|
|
20
|
+
* that lacks several (on the first handler of a key) gets them in one commit.
|
|
20
21
|
*/
|
|
21
22
|
export declare function ensureSchemas(db: DatabaseReader | Connection, schemas: readonly Schema[]): Promise<void>;
|
|
22
|
-
/** How a database applies schemas:
|
|
23
|
+
/** How a database applies schemas: `ctx.db`, its reader, or a database from `asDatabase`. */
|
|
23
24
|
type Ensure = (schemas: readonly Schema[]) => Promise<void>;
|
|
24
|
-
/** `db`,
|
|
25
|
+
/** `db`, marked to apply schemas with `ensure`. */
|
|
25
26
|
export declare const ensuring: <D extends object>(db: D, ensure: Ensure) => D;
|
|
26
|
-
/** How `db` applies schemas, if
|
|
27
|
+
/** How `db` applies schemas, if this package made it. */
|
|
27
28
|
export declare const ensureOf: (db: object) => Ensure | undefined;
|
|
28
|
-
/** Apply the steps of `schemas` that `db` lacks, in one transaction,
|
|
29
|
+
/** Apply the steps of `schemas` that `db` lacks, in one transaction, and record them. */
|
|
29
30
|
export declare function apply(db: Connection, schemas: readonly Schema[], { reader }?: {
|
|
30
31
|
reader?: boolean | undefined;
|
|
31
32
|
}): Promise<void>;
|
|
32
|
-
/** Apply the steps of `schemas` that the transaction `tx` lacks, and record how far each got. */
|
|
33
|
-
export declare function applyIn(tx: ConnectionTransaction, schemas: readonly Schema[]): Promise<void>;
|
|
34
|
-
/**
|
|
35
|
-
* Empty the database in the transaction `tx`: drop every table, view, index
|
|
36
|
-
* and trigger, and forget every schema, then apply `schemas` again. Its
|
|
37
|
-
* other records (the outbox) stay. It commits with `tx`: what `tx` writes
|
|
38
|
-
* after it are the new database's first rows.
|
|
39
|
-
*/
|
|
40
|
-
export declare function dropAll(tx: ConnectionTransaction, schemas: readonly Schema[]): Promise<void>;
|
|
41
33
|
export {};
|
|
42
34
|
//# sourceMappingURL=schema.d.ts.map
|
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,UAAU,EAAE,KAAK,cAAc,EAAE,KAAK,cAAc,EAA8B,MAAM,eAAe,CAAC;AAajH;;;GAGG;AACH,MAAM,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,CAAC,EAAE,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;AAEpE,6EAA6E;AAC7E,qBAAa,MAAM;IACjB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,SAAS,IAAI,EAAE,CAAC;IAEhC,YAAY,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,IAAI,EAAE,EAG/C;IAED;;;OAGG;IACH,MAAM,CAAC,EAAE,EAAE,cAAc,GAAG,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAErD;CACF;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,cAAc,GAAG,UAAU,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAQxG;AAED,6FAA6F;AAC7F,KAAK,MAAM,GAAG,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAI5D,mDAAmD;AACnD,eAAO,MAAM,QAAQ,GAAI,CAAC,SAAS,MAAM,MAAM,CAAC,UAAU,MAAM,KAAG,CAA0B,CAAC;AAE9F,yDAAyD;AACzD,eAAO,MAAM,QAAQ,OAAQ,MAAM,KAAG,MAAM,GAAG,SAA0B,CAAC;AAE1E,yFAAyF;AACzF,wBAAsB,KAAK,CAAC,EAAE,EAAE,UAAU,EAAE,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,EAAE,MAAc,EAAE;;CAAK,iBAa9F"}
|
package/dist/schema.js
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
|
+
// The schema of the databases of a session object. Every key's database is
|
|
2
|
+
// made by the same steps, in order, each applied once. The record `schema`
|
|
3
|
+
// holds how many steps of each schema the database has, committed with the
|
|
4
|
+
// steps, so a step added later (a column, an index) runs on each key's
|
|
5
|
+
// database when that key is next opened. A view applies missing steps only in
|
|
6
|
+
// its session, which stores nothing, so a key never written reads as empty
|
|
7
|
+
// tables. A library can keep its tables in a named `Schema` and apply it where
|
|
8
|
+
// it uses it with `schema.ensure(ctx.db)`, or `ensureSchemas` for several in
|
|
9
|
+
// one commit (from @restatedev/sessions/internal). The pi integration of
|
|
10
|
+
// @restatedev/agents uses none: pi-durable's storage runs its own migrations,
|
|
11
|
+
// and the integration creates its one table in pi's commits.
|
|
12
|
+
import { TerminalError } from '@restatedev/restate-sdk';
|
|
13
|
+
import { Connection } from './database.js';
|
|
1
14
|
import { Link } from './link.js';
|
|
2
|
-
/**
|
|
3
|
-
* The database's record of its schemas: how many steps of each it has, by
|
|
4
|
-
* name. One record, so that `reset` clears all of them, a library's this
|
|
5
|
-
* process never loaded too.
|
|
6
|
-
*/
|
|
7
15
|
const RECORD = 'schema';
|
|
8
16
|
async function appliedIn(db) {
|
|
9
17
|
const record = await db.record(RECORD);
|
|
10
18
|
return record.length === 0 ? {} : JSON.parse(new TextDecoder().decode(record));
|
|
11
19
|
}
|
|
12
|
-
/** A part of a database
|
|
20
|
+
/** A named part of a database schema: the `steps` that make it, in order. */
|
|
13
21
|
export class Schema {
|
|
14
22
|
name;
|
|
15
23
|
steps;
|
|
@@ -18,39 +26,40 @@ export class Schema {
|
|
|
18
26
|
this.steps = steps;
|
|
19
27
|
}
|
|
20
28
|
/**
|
|
21
|
-
* Apply the steps `db` lacks
|
|
22
|
-
*
|
|
23
|
-
* handler's are its own, vanishing with its session.
|
|
29
|
+
* Apply the steps that `db` lacks, in any object. On `ctx.db` this runs
|
|
30
|
+
* once per attempt. In a view the steps are never stored.
|
|
24
31
|
*/
|
|
25
32
|
ensure(db) {
|
|
26
33
|
return ensureSchemas(db, [this]);
|
|
27
34
|
}
|
|
28
35
|
}
|
|
29
36
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
* first handler, say) gets them in one commit rather than one each.
|
|
37
|
+
* {@link Schema.ensure} for several schemas in one transaction, so a database
|
|
38
|
+
* that lacks several (on the first handler of a key) gets them in one commit.
|
|
33
39
|
*/
|
|
34
40
|
export function ensureSchemas(db, schemas) {
|
|
35
41
|
const ensure = ensureOf(db);
|
|
36
|
-
|
|
42
|
+
if (ensure)
|
|
43
|
+
return ensure(schemas);
|
|
44
|
+
if (db instanceof Connection)
|
|
45
|
+
return apply(db, schemas);
|
|
46
|
+
// A transaction `tx`, for example, cannot commit the steps itself.
|
|
47
|
+
return Promise.reject(new TerminalError("Schema.ensure takes a handler's ctx.db (or its reader), or a database of asDatabase"));
|
|
37
48
|
}
|
|
38
|
-
/** A database's {@link Ensure}. */
|
|
39
49
|
const ENSURE = new Link('Schema.ensure');
|
|
40
|
-
/** `db`,
|
|
50
|
+
/** `db`, marked to apply schemas with `ensure`. */
|
|
41
51
|
export const ensuring = (db, ensure) => ENSURE.on(db, ensure);
|
|
42
|
-
/** How `db` applies schemas, if
|
|
52
|
+
/** How `db` applies schemas, if this package made it. */
|
|
43
53
|
export const ensureOf = (db) => ENSURE.of(db);
|
|
44
|
-
/** Apply the steps of `schemas` that `db` lacks, in one transaction,
|
|
54
|
+
/** Apply the steps of `schemas` that `db` lacks, in one transaction, and record them. */
|
|
45
55
|
export async function apply(db, schemas, { reader = false } = {}) {
|
|
46
56
|
if (behind(await appliedIn(db), schemas).length === 0)
|
|
47
57
|
return;
|
|
48
|
-
//
|
|
49
|
-
// have applied them.
|
|
58
|
+
// Check again in the transaction, which holds the session: an earlier call may have applied them.
|
|
50
59
|
await db.transaction(async (tx) => {
|
|
51
60
|
if (!reader)
|
|
52
61
|
return applyIn(tx, schemas);
|
|
53
|
-
// A reader
|
|
62
|
+
// A reader session is query-only, except while applying schemas.
|
|
54
63
|
await tx.execute('PRAGMA query_only = 0');
|
|
55
64
|
try {
|
|
56
65
|
await applyIn(tx, schemas);
|
|
@@ -60,8 +69,7 @@ export async function apply(db, schemas, { reader = false } = {}) {
|
|
|
60
69
|
}
|
|
61
70
|
});
|
|
62
71
|
}
|
|
63
|
-
|
|
64
|
-
export async function applyIn(tx, schemas) {
|
|
72
|
+
async function applyIn(tx, schemas) {
|
|
65
73
|
const applied = await appliedIn(tx);
|
|
66
74
|
const lacking = behind(applied, schemas);
|
|
67
75
|
if (lacking.length === 0)
|
|
@@ -74,52 +82,6 @@ export async function applyIn(tx, schemas) {
|
|
|
74
82
|
}
|
|
75
83
|
tx.setRecord(RECORD, new TextEncoder().encode(JSON.stringify(applied)));
|
|
76
84
|
}
|
|
77
|
-
/** The schemas
|
|
85
|
+
/** The schemas with steps missing from `applied`. */
|
|
78
86
|
const behind = (applied, schemas) => schemas.filter((schema) => (applied[schema.name] ?? 0) < schema.steps.length);
|
|
79
|
-
/**
|
|
80
|
-
* Empty the database in the transaction `tx`: drop every table, view, index
|
|
81
|
-
* and trigger, and forget every schema, then apply `schemas` again. Its
|
|
82
|
-
* other records (the outbox) stay. It commits with `tx`: what `tx` writes
|
|
83
|
-
* after it are the new database's first rows.
|
|
84
|
-
*/
|
|
85
|
-
export async function dropAll(tx, schemas) {
|
|
86
|
-
const made = await tx.query("SELECT type, name FROM sqlite_schema WHERE substr(name, 1, 7) != 'sqlite_'");
|
|
87
|
-
// A trigger or view may name a table; an index goes with its table.
|
|
88
|
-
for (const type of ['trigger', 'view']) {
|
|
89
|
-
for (const { name } of made.filter((m) => m.type === type))
|
|
90
|
-
await drop(tx, type, name);
|
|
91
|
-
}
|
|
92
|
-
for (const name of await childrenFirst(tx, made.filter((m) => m.type === 'table').map((m) => m.name))) {
|
|
93
|
-
await drop(tx, 'table', name);
|
|
94
|
-
}
|
|
95
|
-
tx.setRecord(RECORD, new Uint8Array());
|
|
96
|
-
await applyIn(tx, schemas);
|
|
97
|
-
}
|
|
98
|
-
function drop(tx, type, name) {
|
|
99
|
-
return tx.execute(`DROP ${type.toUpperCase()} IF EXISTS "${name.replaceAll('"', '""')}"`);
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* `tables`, each after every table whose foreign keys name it: with foreign
|
|
103
|
-
* keys on, dropping a table deletes its rows, which a child's rows may not
|
|
104
|
-
* outlive. Tables in a cycle stay in their order.
|
|
105
|
-
*/
|
|
106
|
-
async function childrenFirst(tx, tables) {
|
|
107
|
-
const parents = new Map();
|
|
108
|
-
for (const name of tables) {
|
|
109
|
-
const keys = await tx.query('SELECT "table" FROM pragma_foreign_key_list(?)', [name]);
|
|
110
|
-
// SQL names are case-insensitive.
|
|
111
|
-
const own = name.toLowerCase();
|
|
112
|
-
parents.set(name, new Set(keys.map((k) => k.table.toLowerCase()).filter((t) => t !== own)));
|
|
113
|
-
}
|
|
114
|
-
const ordered = [];
|
|
115
|
-
let left = tables;
|
|
116
|
-
while (left.length > 0) {
|
|
117
|
-
const named = new Set(left.flatMap((name) => [...parents.get(name)]));
|
|
118
|
-
const unnamed = left.filter((name) => !named.has(name.toLowerCase()));
|
|
119
|
-
const next = unnamed.length > 0 ? unnamed : left;
|
|
120
|
-
ordered.push(...next);
|
|
121
|
-
left = left.filter((name) => !next.includes(name));
|
|
122
|
-
}
|
|
123
|
-
return ordered;
|
|
124
|
-
}
|
|
125
87
|
//# sourceMappingURL=schema.js.map
|
package/dist/schema.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,uEAAuE;AACvE,8EAA8E;AAC9E,2EAA2E;AAC3E,+EAA+E;AAC/E,6EAA6E;AAC7E,yEAAyE;AACzE,8EAA8E;AAC9E,6DAA6D;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAwE,MAAM,eAAe,CAAC;AACjH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,MAAM,GAAG,QAAQ,CAAC;AAKxB,KAAK,UAAU,SAAS,CAAC,EAAsC;IAC7D,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACvC,OAAO,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAE,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAa,CAAC;AAC9F,CAAC;AAQD,6EAA6E;AAC7E,MAAM,OAAO,MAAM;IACR,IAAI,CAAS;IACb,KAAK,CAAkB;IAEhC,YAAY,IAAY,EAAE,KAAsB;QAC9C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,MAAM,C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,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC"}
|
package/dist/serve.d.ts
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
import * as restate from '@restatedev/restate-sdk';
|
|
2
2
|
type Service = restate.ServeOptions['services'][number];
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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`), serves only those of them, each with what it needs
|
|
13
|
-
* beside it: one program (or image), deployed in parts.
|
|
4
|
+
* Serve `services` on PORT (default 9080), each once. RESTATE_SERVE_ONLY,
|
|
5
|
+
* names separated by commas (`triage,planner`), serves only those of them:
|
|
6
|
+
* one program (or image), deployed in parts.
|
|
14
7
|
*
|
|
15
8
|
* await restate.serve(notes, orders);
|
|
16
9
|
*/
|
|
17
10
|
export declare const serve: (...services: Service[]) => Promise<number>;
|
|
18
11
|
/**
|
|
19
|
-
* Connect out to Restate
|
|
20
|
-
*
|
|
21
|
-
*
|
|
12
|
+
* Connect out to a Restate server instead of listening: the SDK `connect`,
|
|
13
|
+
* with the services as {@link served} lists them (the SDK would bind a remote
|
|
14
|
+
* handle too). The server must accept deployments that connect out, and, as
|
|
15
|
+
* for every session object, serve the explicit recovery protocol.
|
|
22
16
|
*
|
|
23
17
|
* restate.connect({ services: [notes, orders], name: 'notes-v1' });
|
|
24
18
|
*
|
|
@@ -28,14 +22,14 @@ export declare const serve: (...services: Service[]) => Promise<number>;
|
|
|
28
22
|
* the handshake: `await restate.connect(…).ready` is what waits.
|
|
29
23
|
*/
|
|
30
24
|
export declare const connect: (options: ConnectOptions) => restate.Connection;
|
|
31
|
-
/**
|
|
25
|
+
/** The SDK `connect` options, with `services` passed through {@link served}. */
|
|
32
26
|
type ConnectOptions = Omit<Parameters<typeof restate.connect>[0], 'services'> & {
|
|
33
27
|
services: Service[];
|
|
34
28
|
};
|
|
35
29
|
/**
|
|
36
|
-
* What {@link serve} serves of `services`: each with
|
|
37
|
-
*
|
|
38
|
-
*
|
|
30
|
+
* What {@link serve} serves of `services`: each once; with `names`
|
|
31
|
+
* (separated by commas), only the services it names. For an endpoint of
|
|
32
|
+
* your own:
|
|
39
33
|
*
|
|
40
34
|
* const endpoint = restate.endpoint();
|
|
41
35
|
* for (const service of restate.served([notes, orders])) endpoint.bind(service);
|
package/dist/serve.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,OAAO,MAAM,yBAAyB,CAAC;AAGnD,KAAK,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,CAAC;AAExD;;;;;;GAMG;AACH,eAAO,MAAM,KAAK,gBAAiB,OAAO,EAAE,oBAC2E,CAAC;AAExH;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,OAAO,YAAa,cAAc,uBACsD,CAAC;AAEtG,gFAAgF;AAChF,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,CAoBrE"}
|
package/dist/serve.js
CHANGED
|
@@ -1,33 +1,21 @@
|
|
|
1
|
-
// `serve`: the services of a program,
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
// A session object's invocations run on the explicit recovery VM whichever of
|
|
5
|
-
// these serves them, and so does an endpoint built by hand: `endpoint.ts`
|
|
6
|
-
// wraps the SDK's endpoint class, which every transport builds its request
|
|
7
|
-
// handler from.
|
|
1
|
+
// `serve`, `connect` and `served`: the services of a program, each once, or
|
|
2
|
+
// those RESTATE_SERVE_ONLY names. Session objects run on the VM however they
|
|
3
|
+
// are served, also from an endpoint built by hand (see endpoint.ts).
|
|
8
4
|
import * as restate from '@restatedev/restate-sdk';
|
|
9
5
|
import { isRemote } from './calls.js';
|
|
10
|
-
/** Where a definition keeps the services it needs served beside it: see {@link needing}. */
|
|
11
|
-
const NEEDS = Symbol.for('restate-sessions.needs');
|
|
12
6
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
export const needing = (definition, services) => Object.defineProperty(definition, NEEDS, { value: services });
|
|
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`), serves only those of them, each with what it needs
|
|
22
|
-
* beside it: one program (or image), deployed in parts.
|
|
7
|
+
* Serve `services` on PORT (default 9080), each once. RESTATE_SERVE_ONLY,
|
|
8
|
+
* names separated by commas (`triage,planner`), serves only those of them:
|
|
9
|
+
* one program (or image), deployed in parts.
|
|
23
10
|
*
|
|
24
11
|
* await restate.serve(notes, orders);
|
|
25
12
|
*/
|
|
26
13
|
export const serve = (...services) => restate.serve({ services: served(services, process.env.RESTATE_SERVE_ONLY), port: Number(process.env.PORT ?? 9080) });
|
|
27
14
|
/**
|
|
28
|
-
* Connect out to Restate
|
|
29
|
-
*
|
|
30
|
-
*
|
|
15
|
+
* Connect out to a Restate server instead of listening: the SDK `connect`,
|
|
16
|
+
* with the services as {@link served} lists them (the SDK would bind a remote
|
|
17
|
+
* handle too). The server must accept deployments that connect out, and, as
|
|
18
|
+
* for every session object, serve the explicit recovery protocol.
|
|
31
19
|
*
|
|
32
20
|
* restate.connect({ services: [notes, orders], name: 'notes-v1' });
|
|
33
21
|
*
|
|
@@ -38,21 +26,20 @@ export const serve = (...services) => restate.serve({ services: served(services,
|
|
|
38
26
|
*/
|
|
39
27
|
export const connect = (options) => restate.connect({ ...options, services: served(options.services, process.env.RESTATE_SERVE_ONLY) });
|
|
40
28
|
/**
|
|
41
|
-
* What {@link serve} serves of `services`: each with
|
|
42
|
-
*
|
|
43
|
-
*
|
|
29
|
+
* What {@link serve} serves of `services`: each once; with `names`
|
|
30
|
+
* (separated by commas), only the services it names. For an endpoint of
|
|
31
|
+
* your own:
|
|
44
32
|
*
|
|
45
33
|
* const endpoint = restate.endpoint();
|
|
46
34
|
* for (const service of restate.served([notes, orders])) endpoint.bind(service);
|
|
47
35
|
*/
|
|
48
36
|
export function served(services, names) {
|
|
49
|
-
//
|
|
50
|
-
// service with no handlers, over the real one: the collision, from inside.
|
|
37
|
+
// Binding a remote handle would register a service with no handlers over the real one.
|
|
51
38
|
const handles = services.filter(isRemote).map((s) => s.name);
|
|
52
39
|
if (handles.length > 0) {
|
|
53
40
|
throw new Error(`${handles.join(', ')}: a remote handle names what another deployment serves, so it cannot be served here`);
|
|
54
41
|
}
|
|
55
|
-
const all =
|
|
42
|
+
const all = once(services);
|
|
56
43
|
const wanted = (names ?? '')
|
|
57
44
|
.split(',')
|
|
58
45
|
.map((name) => name.trim())
|
|
@@ -64,19 +51,14 @@ export function served(services, names) {
|
|
|
64
51
|
if (unknown.length > 0) {
|
|
65
52
|
throw new Error(`RESTATE_SERVE_ONLY names ${unknown.join(', ')}: the services are ${known.join(', ')}`);
|
|
66
53
|
}
|
|
67
|
-
return
|
|
54
|
+
return all.filter((s) => wanted.includes(s.name));
|
|
68
55
|
}
|
|
69
|
-
/**
|
|
70
|
-
function
|
|
56
|
+
/** The first service of each name. */
|
|
57
|
+
function once(services) {
|
|
71
58
|
const all = new Map();
|
|
72
|
-
const
|
|
73
|
-
if (all.has(service.name))
|
|
74
|
-
|
|
75
|
-
all.set(service.name, service);
|
|
76
|
-
for (const needed of service[NEEDS]?.() ?? [])
|
|
77
|
-
add(needed);
|
|
78
|
-
};
|
|
79
|
-
services.forEach(add);
|
|
59
|
+
for (const service of services)
|
|
60
|
+
if (!all.has(service.name))
|
|
61
|
+
all.set(service.name, service);
|
|
80
62
|
return [...all.values()];
|
|
81
63
|
}
|
|
82
64
|
//# sourceMappingURL=serve.js.map
|
package/dist/serve.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"serve.js","sourceRoot":"","sources":["../src/serve.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,6EAA6E;AAC7E,qEAAqE;AACrE,OAAO,KAAK,OAAO,MAAM,yBAAyB,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC;;;;;;GAMG;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;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,OAAuB,EAAE,EAAE,CACjD,OAAO,CAAC,OAAO,CAAC,EAAE,GAAG,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC;AAKtG;;;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