@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.
Files changed (96) hide show
  1. package/README.md +330 -178
  2. package/dist/addon.d.ts +1 -0
  3. package/dist/addon.d.ts.map +1 -1
  4. package/dist/addon.js.map +1 -1
  5. package/dist/calls.d.ts +28 -28
  6. package/dist/calls.d.ts.map +1 -1
  7. package/dist/calls.js +25 -25
  8. package/dist/calls.js.map +1 -1
  9. package/dist/database.d.ts +90 -166
  10. package/dist/database.d.ts.map +1 -1
  11. package/dist/database.js +137 -249
  12. package/dist/database.js.map +1 -1
  13. package/dist/driver.d.ts +129 -126
  14. package/dist/driver.d.ts.map +1 -1
  15. package/dist/driver.js +337 -276
  16. package/dist/driver.js.map +1 -1
  17. package/dist/endpoint.d.ts +47 -5
  18. package/dist/endpoint.d.ts.map +1 -1
  19. package/dist/endpoint.js +175 -60
  20. package/dist/endpoint.js.map +1 -1
  21. package/dist/handler.d.ts +20 -17
  22. package/dist/handler.d.ts.map +1 -1
  23. package/dist/handler.js +161 -127
  24. package/dist/handler.js.map +1 -1
  25. package/dist/host.d.ts +29 -0
  26. package/dist/host.d.ts.map +1 -0
  27. package/dist/host.js +2 -0
  28. package/dist/host.js.map +1 -0
  29. package/dist/index.d.ts +1 -1
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +5 -26
  32. package/dist/index.js.map +1 -1
  33. package/dist/internal.d.ts +11 -11
  34. package/dist/internal.d.ts.map +1 -1
  35. package/dist/internal.js +20 -16
  36. package/dist/internal.js.map +1 -1
  37. package/dist/link.d.ts +1 -2
  38. package/dist/link.d.ts.map +1 -1
  39. package/dist/link.js +4 -5
  40. package/dist/link.js.map +1 -1
  41. package/dist/log.d.ts +14 -0
  42. package/dist/log.d.ts.map +1 -0
  43. package/dist/log.js +21 -0
  44. package/dist/log.js.map +1 -0
  45. package/dist/object.d.ts +217 -142
  46. package/dist/object.d.ts.map +1 -1
  47. package/dist/object.js +195 -241
  48. package/dist/object.js.map +1 -1
  49. package/dist/platform.d.ts +0 -1
  50. package/dist/platform.d.ts.map +1 -1
  51. package/dist/platform.js +4 -6
  52. package/dist/platform.js.map +1 -1
  53. package/dist/schema.d.ts +14 -22
  54. package/dist/schema.d.ts.map +1 -1
  55. package/dist/schema.js +31 -69
  56. package/dist/schema.js.map +1 -1
  57. package/dist/serve.d.ts +11 -17
  58. package/dist/serve.d.ts.map +1 -1
  59. package/dist/serve.js +21 -39
  60. package/dist/serve.js.map +1 -1
  61. package/dist/session.d.ts +58 -236
  62. package/dist/session.d.ts.map +1 -1
  63. package/dist/session.js +206 -513
  64. package/dist/session.js.map +1 -1
  65. package/dist/stop.d.ts +59 -0
  66. package/dist/stop.d.ts.map +1 -0
  67. package/dist/stop.js +220 -0
  68. package/dist/stop.js.map +1 -0
  69. package/dist/vm.d.ts +108 -29
  70. package/dist/vm.d.ts.map +1 -1
  71. package/dist/vm.js +43 -10
  72. package/dist/vm.js.map +1 -1
  73. package/package.json +4 -4
  74. package/src/addon.ts +1 -0
  75. package/src/calls.ts +51 -47
  76. package/src/database.ts +195 -339
  77. package/src/driver.ts +379 -315
  78. package/src/endpoint.ts +217 -62
  79. package/src/handler.ts +183 -164
  80. package/src/host.ts +28 -0
  81. package/src/index.ts +6 -26
  82. package/src/internal.ts +28 -39
  83. package/src/link.ts +4 -5
  84. package/src/log.ts +42 -0
  85. package/src/object.ts +379 -335
  86. package/src/platform.ts +4 -6
  87. package/src/schema.ts +37 -103
  88. package/src/serve.ts +20 -41
  89. package/src/session.ts +236 -613
  90. package/src/stop.ts +225 -0
  91. package/src/vm.ts +151 -55
  92. package/dist/scope.d.ts +0 -38
  93. package/dist/scope.d.ts.map +0 -1
  94. package/dist/scope.js +0 -55
  95. package/dist/scope.js.map +0 -1
  96. package/src/scope.ts +0 -78
package/dist/vm.js CHANGED
@@ -1,16 +1,48 @@
1
- // The VM of a session object's attempt: shared-core's explicit recovery state
2
- // machine, through the addon (`native/src/vm.rs`).
1
+ // The VM of a session object's attempt, on the explicit recovery protocol
2
+ // (version 1): shared-core's state machine, through the addon
3
+ // (`native/src/vm.rs`).
3
4
  //
4
- // It never replays a journal: every attempt runs the handler from the start
5
- // and recovers from the state the earlier attempts stored. An action returns
6
- // a handle, and its result comes back as a notification of that handle
7
- // (`takeNotification`), which the driver settles a promise with. There is no
8
- // `do_progress` and no single await point, so a handler awaits what it likes,
9
- // with its own combinators.
5
+ // It has no journal: every attempt runs the handler from the start and
6
+ // recovers from the state the earlier attempts stored. An action returns a
7
+ // handle, and its result comes back as a notification of that handle
8
+ // (`takeNotification`), which the driver settles a promise with, in its tick:
9
+ // the only place notifications are taken, since taking one is processing it
10
+ // (it counts in the `ShutdownMessage` of a shut-down attempt). There is no
11
+ // single await point, so a handler awaits what it likes, with its own
12
+ // combinators.
10
13
  //
11
14
  // The VM is synchronous and does no I/O: every call only buffers output.
12
15
  import { addon } from './addon.js';
13
16
  export const Vm = addon.Vm;
17
+ /** The range of versions of the explicit recovery protocol the VM speaks, for discovery. */
18
+ export const explicitRecoveryProtocolRange = () => addon.explicitRecoveryProtocolRange();
19
+ /**
20
+ * The HTTP status to answer a request with whose VM could not be made: 415
21
+ * for a content type of another protocol family or version. `undefined` if
22
+ * `error` is not such a refusal.
23
+ */
24
+ export function refusedStatus(error) {
25
+ const message = error.message;
26
+ if (typeof message !== 'string')
27
+ return undefined;
28
+ const match = /^VM_REFUSED (\d+):/.exec(message);
29
+ return match === null ? undefined : Number(match[1]);
30
+ }
31
+ /**
32
+ * The VM's refusal of a value user code passed to an action, which Restate
33
+ * would refuse as malformed (an invocation id that is not one, say): its code
34
+ * (400) and why. The VM sent nothing, and the attempt goes on: the driver
35
+ * fails that action alone, with a `TerminalError`. `undefined` if `error` is
36
+ * not such a refusal.
37
+ */
38
+ export function invalidInput(error) {
39
+ const message = error?.message;
40
+ if (typeof message !== 'string')
41
+ return undefined;
42
+ // Anywhere in the text: a commit's send crosses the SQL engine, which may wrap it.
43
+ const match = /INVALID_INPUT (\d+): ([\s\S]*)$/.exec(message);
44
+ return match === null ? undefined : { code: Number(match[1]), message: match[2] ?? '' };
45
+ }
14
46
  export const Identity = addon.Identity;
15
47
  /**
16
48
  * What the database's store's waits fail with once the attempt is over, as
@@ -21,8 +53,9 @@ export const STATE_WAIT_OVER = 'restate-sessions: the attempt is over';
21
53
  /** The message of the error a closed attempt throws when Restate shut it down. */
22
54
  const SHUT_DOWN = 'ATTEMPT_SHUT_DOWN';
23
55
  /**
24
- * Whether `error` says the attempt was shut down (Restate closed the input),
25
- * rather than failed. A new attempt runs the handler from the start.
56
+ * Whether `error` says the attempt was shut down (Restate closed the input,
57
+ * or the process is going away), rather than failed. A new attempt runs the
58
+ * handler from the start.
26
59
  */
27
60
  export const isShutDown = (error) => error instanceof Error && error.message.startsWith(SHUT_DOWN);
28
61
  //# sourceMappingURL=vm.js.map
package/dist/vm.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"vm.js","sourceRoot":"","sources":["../src/vm.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,mDAAmD;AACnD,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAC7E,uEAAuE;AACvE,6EAA6E;AAC7E,8EAA8E;AAC9E,4BAA4B;AAC5B,EAAE;AACF,yEAAyE;AACzE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAkJnC,MAAM,CAAC,MAAM,EAAE,GAAI,KAA+B,CAAC,EAAE,CAAC;AAqBtD,MAAM,CAAC,MAAM,QAAQ,GAAI,KAA2C,CAAC,QAAQ,CAAC;AAE9E;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,uCAAuC,CAAC;AAEvE,kFAAkF;AAClF,MAAM,SAAS,GAAG,mBAAmB,CAAC;AAEtC;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAc,EAAW,EAAE,CAAC,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC"}
1
+ {"version":3,"file":"vm.js","sourceRoot":"","sources":["../src/vm.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,8DAA8D;AAC9D,wBAAwB;AACxB,EAAE;AACF,uEAAuE;AACvE,2EAA2E;AAC3E,qEAAqE;AACrE,8EAA8E;AAC9E,4EAA4E;AAC5E,2EAA2E;AAC3E,sEAAsE;AACtE,eAAe;AACf,EAAE;AACF,yEAAyE;AACzE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AA6MnC,MAAM,CAAC,MAAM,EAAE,GAAI,KAA+B,CAAC,EAAE,CAAC;AAEtD,4FAA4F;AAC5F,MAAM,CAAC,MAAM,6BAA6B,GAAG,GAA+C,EAAE,CAE1F,KACD,CAAC,6BAA6B,EAAE,CAAC;AAEpC;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,MAAM,OAAO,GAAI,KAA+B,CAAC,OAAO,CAAC;IACzD,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAClD,MAAM,KAAK,GAAG,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACjD,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,MAAM,OAAO,GAAI,KAA2C,EAAE,OAAO,CAAC;IACtE,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAClD,mFAAmF;IACnF,MAAM,KAAK,GAAG,iCAAiC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC9D,OAAO,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;AAC1F,CAAC;AAqBD,MAAM,CAAC,MAAM,QAAQ,GAAI,KAA2C,CAAC,QAAQ,CAAC;AAE9E;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,uCAAuC,CAAC;AAEvE,kFAAkF;AAClF,MAAM,SAAS,GAAG,mBAAmB,CAAC;AAEtC;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAc,EAAW,EAAE,CAAC,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@restatedev/sessions",
3
- "version": "0.11.1",
3
+ "version": "0.12.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.11.1",
33
- "@restatedev/sessions-linux-arm64-gnu": "0.11.1",
34
- "@restatedev/sessions-linux-x64-gnu": "0.11.1"
32
+ "@restatedev/sessions-darwin-arm64": "0.12.0",
33
+ "@restatedev/sessions-linux-arm64-gnu": "0.12.0",
34
+ "@restatedev/sessions-linux-x64-gnu": "0.12.0"
35
35
  },
36
36
  "engines": {
37
37
  "node": ">=24"
package/src/addon.ts CHANGED
@@ -8,6 +8,7 @@ interface Addon {
8
8
  open(namespace: string, store: unknown, reader: boolean): Promise<unknown>;
9
9
  Vm: unknown;
10
10
  Identity: unknown;
11
+ explicitRecoveryProtocolRange: unknown;
11
12
  }
12
13
 
13
14
  /** The addon of this machine's platform, from its package (see platform.ts). */
package/src/calls.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  // oxlint-disable eslint/no-underscore-dangle -- the SDK's names, in its definitions
2
2
 
3
- // Calls and sends from a session object's handler: `ctx.rpc` and `ctx.send`,
4
- // and a transaction's `tx.send`. A target is a definition (with its key for
5
- // an object or a workflow), or a literal naming it, for one known only at run
6
- // time. Options go with the target: a client's methods take only their input.
3
+ // Calls and sends from a session object handler: `ctx.rpc`, `ctx.send` and
4
+ // `tx.send`. A target is a definition (with its key for an object or a
5
+ // workflow), or a literal for a target known only at run time. Options go with
6
+ // the target: client methods take only their input.
7
7
  import type * as restate from '@restatedev/restate-sdk';
8
8
  import { serde, TerminalError } from '@restatedev/restate-sdk';
9
9
  import type {
@@ -15,22 +15,21 @@ import type {
15
15
  WorkflowDefinition,
16
16
  } from '@restatedev/restate-sdk-core';
17
17
 
18
- /** The options of a call, which apply to every call its client makes. */
18
+ /** Options of a call. They apply to every call its client makes. */
19
19
  export interface CallOptions {
20
20
  /**
21
- * A key that is the same on every attempt, so that a new attempt gets the
22
- * first call's result. Without one, every attempt makes the call again,
23
- * including the one that resumes a suspension: a call that may wait long
24
- * wants a key. Restate scopes it to the target handler: two calls of the
25
- * same handler through one keyed client are one invocation, so make a
26
- * client per call when that is not what you mean.
21
+ * A key that is the same on every attempt, so that a retry gets the result
22
+ * of the first call. Without one, every attempt makes the call again,
23
+ * including the one that resumes after a suspension, so a call that may
24
+ * wait long needs a key. Restate scopes it to the target handler: two calls
25
+ * of the same handler through one keyed client are one invocation. Make a
26
+ * client per call if that is not what you want.
27
27
  */
28
28
  idempotencyKey?: string;
29
- /** Headers of the call. */
30
29
  headers?: Record<string, string>;
31
30
  }
32
31
 
33
- /** The options of a send. */
32
+ /** Options of a send. */
34
33
  export interface SendOptions extends CallOptions {
35
34
  /** How long after the send (for `tx.send`, after the commit) the target runs. */
36
35
  delay?: Duration | number;
@@ -46,20 +45,19 @@ export interface Target {
46
45
  inputSerde?: Serde<unknown>;
47
46
  }
48
47
 
49
- /** A definition the clients take: a service, a virtual object or a workflow, as `restate` makes them. */
48
+ /** A service, virtual object or workflow definition. */
50
49
  type Definition = { name: string };
51
50
 
52
- /** Marks a {@link remote}: {@link served} refuses one, since nothing here implements it. */
51
+ /** Marks a {@link remote} handle, which {@link served} refuses. */
53
52
  const REMOTE = Symbol.for('restate-sessions.remote');
54
53
 
55
- /** Whether `service` is a {@link remote} handle rather than something to serve. */
56
54
  export const isRemote = (service: object): boolean => REMOTE in service;
57
55
 
58
- /** A handle of `kind`, carrying what the clients read of a definition: its name and its kind. */
56
+ /** A handle with what the clients read of a definition: its name and kind. */
59
57
  const handle = (kind: 'service' | 'object' | 'workflow', name: string) => ({
60
58
  name,
61
- // The kind, by both conventions: `_kind` for the clients here, the key
62
- // itself for @restatedev/agents' tools (`'object' in target`).
59
+ // Both conventions: `_kind` for the clients here, and the key itself for
60
+ // code that tests the kind with `'object' in target`.
63
61
  [kind]: {},
64
62
  _kind: kind,
65
63
  [REMOTE]: true,
@@ -67,20 +65,18 @@ const handle = (kind: 'service' | 'object' | 'workflow', name: string) => ({
67
65
 
68
66
  /**
69
67
  * A handle on something another deployment serves, named and typed but not
70
- * implemented here: `ctx.rpc`, `ctx.send` and the agents' tools take it as
71
- * they take a definition, and the call goes out through Restate.
72
- *
73
- * Type it with the definition it names, imported for its type alone, so that
74
- * nothing of the other deployment is imported at run time:
68
+ * implemented here. `ctx.rpc` and `ctx.send` take it like a definition.
69
+ * Type it with a type-only import of the definition, so nothing of the other
70
+ * deployment is imported at run time:
75
71
  *
76
72
  * import type { workspace as impl } from '../coders/services/workspace.ts';
77
73
  *
78
74
  * export const workspace = remote.object<typeof impl>('workspace');
79
75
  * await ctx.rpc(workspace, key).clone(issue); // typed as the real one
80
76
  *
81
- * The name is checked against the definition's, so a typo is a type error.
82
- * Serving a handle is one too, at run time: {@link served} refuses it, rather
83
- * than registering a service with no handlers over the real one.
77
+ * The name is checked against the definition, so a typo is a type error.
78
+ * {@link served} refuses a handle at run time, instead of registering a
79
+ * service with no handlers over the real one.
84
80
  */
85
81
  export const remote = {
86
82
  service: <D extends Definition>(name: D['name']): D => handle('service', name) as unknown as D,
@@ -88,8 +84,7 @@ export const remote = {
88
84
  workflow: <D extends Definition>(name: D['name']): D => handle('workflow', name) as unknown as D,
89
85
  };
90
86
 
91
- // The handlers of a definition, of whichever kind: each kind's type only
92
- // infers from its own definitions, and is `unknown` for the others.
87
+ // The handlers of a definition of any kind: each type infers only from its own kind, else `unknown`.
93
88
  type OfObject<D> = D extends VirtualObjectDefinition<string, infer M> ? M : unknown;
94
89
  type OfService<D> = D extends ServiceDefinition<string, infer M> ? M : unknown;
95
90
  type OfWorkflow<D> = D extends WorkflowDefinition<string, infer M> ? M : unknown;
@@ -112,10 +107,10 @@ export type SendClient<D> = {
112
107
 
113
108
  /**
114
109
  * Calls: `ctx.rpc(service)` or `ctx.rpc(object, key)` for a typed client, with
115
- * the options of its calls last; or `ctx.rpc({ service, key, handler, input })`
116
- * for a target known only at run time. A typed client of an object or a
117
- * workflow needs its key, and one of a service has none: it fails at once
118
- * otherwise. A literal target names no kind: its `key` is the caller's to give.
110
+ * call options last; or `ctx.rpc({ service, key, handler, input })` for a
111
+ * target known only at run time. A typed client of an object or workflow
112
+ * needs a key, and one of a service takes none; otherwise it throws. A
113
+ * literal target names no kind, so the caller decides whether to give `key`.
119
114
  */
120
115
  export interface Rpc {
121
116
  <D extends Definition>(target: D, options?: CallOptions): Client<D>;
@@ -123,21 +118,21 @@ export interface Rpc {
123
118
  <O = unknown>(call: Target & CallOptions & { outputSerde?: Serde<O> }): Promise<O>;
124
119
  }
125
120
 
126
- /** Sends, as {@link Rpc}'s calls: each returns at once, with nothing. */
121
+ /** Sends, shaped like {@link Rpc}. Each returns immediately, with nothing. */
127
122
  export interface Send {
128
123
  <D extends Definition>(target: D, options?: SendOptions): SendClient<D>;
129
124
  <D extends Definition>(target: D, key: string, options?: SendOptions): SendClient<D>;
130
125
  (send: Target & SendOptions): void;
131
126
  }
132
127
 
133
- /** What a definition holds at run time, beside its name. */
128
+ /** What a definition holds at run time. */
134
129
  type Defined = {
135
130
  name: string;
136
131
  _kind?: 'service' | 'object' | 'workflow';
137
132
  _handlers?: Record<string, HandlerDescriptor>;
138
133
  };
139
134
 
140
- /** The target, key and options of a typed client's arguments. */
135
+ /** The target, key and options from the arguments of a typed client. */
141
136
  function clientOf(args: unknown[]): { def: Defined; key: string | undefined; options: SendOptions } {
142
137
  const [def, second, third] = args as [Defined, unknown, unknown];
143
138
  const key = typeof second === 'string' ? second : undefined;
@@ -152,11 +147,10 @@ function clientOf(args: unknown[]): { def: Defined; key: string | undefined; opt
152
147
  return { def, key, options };
153
148
  }
154
149
 
155
- /** Whether `value` is a literal target rather than a definition. */
156
150
  const isLiteral = (value: unknown): value is Target =>
157
151
  typeof (value as Target).handler === 'string' && typeof (value as Target).service === 'string';
158
152
 
159
- /** A client whose methods make `call` of each one, with its input. */
153
+ /** A client whose methods each run `call` with their input. */
160
154
  function proxy(call: (method: string, input: unknown) => unknown): never {
161
155
  return new Proxy(
162
156
  {},
@@ -168,13 +162,20 @@ function proxy(call: (method: string, input: unknown) => unknown): never {
168
162
  ) as never;
169
163
  }
170
164
 
171
- /** `ctx.rpc` over the SDK context `ctx`. */
172
- export function rpcOf(ctx: Pick<restate.Context, 'genericCall'>): Rpc {
165
+ /**
166
+ * `ctx.rpc` over `call`. A typed client's call to a handler whose definition
167
+ * declares no serde uses `fallback`, as the SDK's clients use the calling
168
+ * handler's `serde` option; a literal target is JSON unless it gives serdes.
169
+ */
170
+ export function rpcOf(
171
+ call: (call: restate.GenericCall<unknown, unknown>) => Promise<unknown>,
172
+ fallback: Serde<unknown> = serde.json,
173
+ ): Rpc {
173
174
  return (...args: unknown[]) => {
174
175
  if (isLiteral(args[0])) {
175
176
  const { service, key, handler, input, inputSerde, outputSerde, idempotencyKey, headers } = args[0] as Target &
176
177
  CallOptions & { outputSerde?: Serde<unknown> };
177
- return ctx.genericCall({
178
+ return call({
178
179
  service,
179
180
  method: handler,
180
181
  key,
@@ -187,13 +188,13 @@ export function rpcOf(ctx: Pick<restate.Context, 'genericCall'>): Rpc {
187
188
  }
188
189
  const { def, key, options } = clientOf(args);
189
190
  return proxy((method, input) =>
190
- ctx.genericCall({
191
+ call({
191
192
  service: def.name,
192
193
  method,
193
194
  key,
194
195
  parameter: input,
195
- inputSerde: def._handlers?.[method]?._inputSerde ?? serde.json,
196
- outputSerde: def._handlers?.[method]?._outputSerde ?? serde.json,
196
+ inputSerde: def._handlers?.[method]?._inputSerde ?? fallback,
197
+ outputSerde: def._handlers?.[method]?._outputSerde ?? fallback,
197
198
  idempotencyKey: options.idempotencyKey,
198
199
  headers: options.headers,
199
200
  }),
@@ -201,8 +202,11 @@ export function rpcOf(ctx: Pick<restate.Context, 'genericCall'>): Rpc {
201
202
  };
202
203
  }
203
204
 
204
- /** A send over `send`: `ctx.send` makes each at once, `tx.send` records it for its commit. */
205
- export function sendOf(send: (send: restate.GenericSend<unknown>) => void): Send {
205
+ /** A send over `send`: `ctx.send` sends immediately, `tx.send` records it for the commit. `fallback`: see {@link rpcOf}. */
206
+ export function sendOf(
207
+ send: (send: restate.GenericSend<unknown>) => void,
208
+ fallback: Serde<unknown> = serde.json,
209
+ ): Send {
206
210
  return ((...args: unknown[]) => {
207
211
  if (isLiteral(args[0])) {
208
212
  const { service, key, handler, input, inputSerde, idempotencyKey, headers, delay } = args[0] as Target &
@@ -226,7 +230,7 @@ export function sendOf(send: (send: restate.GenericSend<unknown>) => void): Send
226
230
  method,
227
231
  key,
228
232
  parameter: input,
229
- inputSerde: def._handlers?.[method]?._inputSerde ?? serde.json,
233
+ inputSerde: def._handlers?.[method]?._inputSerde ?? fallback,
230
234
  idempotencyKey: options.idempotencyKey,
231
235
  headers: options.headers,
232
236
  delay: options.delay,