@restatedev/restate-sdk-gen 0.0.0 → 1.14.3
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/LICENSE +21 -0
- package/README.md +115 -0
- package/dist/chunk-Bp6m_JJh.js +13 -0
- package/dist/index.cjs +1558 -0
- package/dist/index.d.cts +1022 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +1020 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1475 -0
- package/dist/index.js.map +1 -0
- package/package.json +56 -3
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,1022 @@
|
|
|
1
|
+
import * as restate from "@restatedev/restate-sdk";
|
|
2
|
+
import { ContextDate, InvocationId, Opts, Rand, SendOpts, Target as Target$1 } from "@restatedev/restate-sdk";
|
|
3
|
+
|
|
4
|
+
//#region rolldown:runtime
|
|
5
|
+
//#endregion
|
|
6
|
+
//#region src/operation.d.ts
|
|
7
|
+
interface Operation<T> {
|
|
8
|
+
[Symbol.iterator](): Iterator<unknown, T, unknown>;
|
|
9
|
+
}
|
|
10
|
+
declare function gen<T>(body: () => Generator<unknown, T, unknown>): Operation<T>;
|
|
11
|
+
type SelectResult<B extends Record<string, Future<unknown>>> = { [K in keyof B]: {
|
|
12
|
+
tag: K;
|
|
13
|
+
future: B[K];
|
|
14
|
+
} }[keyof B];
|
|
15
|
+
declare function select<B extends Record<string, Future<unknown>>>(branches: B): Generator<unknown, SelectResult<B>, unknown>;
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/future.d.ts
|
|
18
|
+
declare const futureBrand: unique symbol;
|
|
19
|
+
interface Future<T> extends Operation<T> {
|
|
20
|
+
readonly [futureBrand]: unknown;
|
|
21
|
+
}
|
|
22
|
+
/** Extract the value type from a `Future<U>`; `never` for non-Futures. */
|
|
23
|
+
type FutureValue<F> = F extends Future<infer U> ? U : never;
|
|
24
|
+
/**
|
|
25
|
+
* Map a tuple of Futures to the tuple of their value types.
|
|
26
|
+
* For `[Future<A>, Future<B>]` produces `[A, B]`.
|
|
27
|
+
* For an unbounded `Future<X>[]` produces `X[]`.
|
|
28
|
+
*/
|
|
29
|
+
type FutureValues<T extends readonly Future<unknown>[] | []> = { -readonly [P in keyof T]: T[P] extends Future<infer U> ? U : never };
|
|
30
|
+
interface FutureFulfilledResult<T> {
|
|
31
|
+
readonly status: "fulfilled";
|
|
32
|
+
readonly value: T;
|
|
33
|
+
}
|
|
34
|
+
interface FutureRejectedResult {
|
|
35
|
+
readonly status: "rejected";
|
|
36
|
+
readonly reason: unknown;
|
|
37
|
+
}
|
|
38
|
+
type FutureSettledResult<T> = FutureFulfilledResult<T> | FutureRejectedResult;
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/channel.d.ts
|
|
41
|
+
interface Channel<T> {
|
|
42
|
+
/**
|
|
43
|
+
* Yieldable. Use as `yield* ch.send(value)` from within a gen body.
|
|
44
|
+
* The first call settles the channel; subsequent calls are silently
|
|
45
|
+
* dropped (idempotent).
|
|
46
|
+
*
|
|
47
|
+
* Return value is `Operation<void>` rather than `void` so the only
|
|
48
|
+
* way to fire send is via `yield*` inside a fiber — which enforces
|
|
49
|
+
* the channel-is-intra-workflow contract at the type level.
|
|
50
|
+
*/
|
|
51
|
+
send(value: T): Operation<void>;
|
|
52
|
+
readonly receive: Future<T>;
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/invocation-reference.d.ts
|
|
56
|
+
/** Synchronous handle for resolving or rejecting a signal on a target invocation */
|
|
57
|
+
interface SignalReference<T> {
|
|
58
|
+
resolve(payload?: T): void;
|
|
59
|
+
reject(reason: string | restate.TerminalError): void;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A typed reference to a running invocation. Returned by `sendClient()` methods
|
|
63
|
+
* (wrapped in `Future<InvocationReference<O>>`), or created via `invocation(id)`.
|
|
64
|
+
*
|
|
65
|
+
* - `attach()` returns a `Future<O>` with the serde from the original descriptor.
|
|
66
|
+
* - `signal()` sends a named signal to the target invocation.
|
|
67
|
+
* - `cancel()` cancels the target invocation.
|
|
68
|
+
*/
|
|
69
|
+
interface InvocationReference<O$1 = unknown> {
|
|
70
|
+
readonly id: string;
|
|
71
|
+
attach(serde?: restate.Serde<O$1>): Future<O$1>;
|
|
72
|
+
signal<T = unknown>(name: string, serde?: restate.Serde<T>): SignalReference<T>;
|
|
73
|
+
cancel(): void;
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region ../restate-sdk-core/src/core.d.ts
|
|
77
|
+
type ServiceDefinition<P$1 extends string, M> = {
|
|
78
|
+
name: P$1;
|
|
79
|
+
};
|
|
80
|
+
type Service<M> = M extends ServiceDefinition<string, infer S> ? S : M;
|
|
81
|
+
type ServiceDefinitionFrom<M> = M extends ServiceDefinition<string, unknown> ? M : ServiceDefinition<string, M>;
|
|
82
|
+
type VirtualObjectDefinition<P$1 extends string, M> = {
|
|
83
|
+
name: P$1;
|
|
84
|
+
};
|
|
85
|
+
type VirtualObject<M> = M extends VirtualObjectDefinition<string, infer O> ? O : M;
|
|
86
|
+
type VirtualObjectDefinitionFrom<M> = M extends VirtualObjectDefinition<string, unknown> ? M : VirtualObjectDefinition<string, M>;
|
|
87
|
+
type WorkflowDefinition<P$1 extends string, M> = {
|
|
88
|
+
name: P$1;
|
|
89
|
+
};
|
|
90
|
+
type Workflow<M> = M extends WorkflowDefinition<string, infer W> ? W : M;
|
|
91
|
+
type WorkflowDefinitionFrom<M> = M extends WorkflowDefinition<string, unknown> ? M : WorkflowDefinition<string, M>;
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region ../restate-sdk-core/src/standard_schema.d.ts
|
|
94
|
+
/**
|
|
95
|
+
* This file is copy pasted as is from https://standardschema.dev/
|
|
96
|
+
*/
|
|
97
|
+
/** The Standard Typed interface. This is a base type extended by other specs. */
|
|
98
|
+
interface StandardTypedV1<Input = unknown, Output$1 = Input> {
|
|
99
|
+
/** The Standard properties. */
|
|
100
|
+
readonly "~standard": StandardTypedV1.Props<Input, Output$1>;
|
|
101
|
+
}
|
|
102
|
+
declare namespace StandardTypedV1 {
|
|
103
|
+
/** The Standard Typed properties interface. */
|
|
104
|
+
interface Props<Input = unknown, Output$1 = Input> {
|
|
105
|
+
/** The version number of the standard. */
|
|
106
|
+
readonly version: 1;
|
|
107
|
+
/** The vendor name of the schema library. */
|
|
108
|
+
readonly vendor: string;
|
|
109
|
+
/** Inferred types associated with the schema. */
|
|
110
|
+
readonly types?: Types<Input, Output$1> | undefined;
|
|
111
|
+
}
|
|
112
|
+
/** The Standard Typed types interface. */
|
|
113
|
+
interface Types<Input = unknown, Output$1 = Input> {
|
|
114
|
+
/** The input type of the schema. */
|
|
115
|
+
readonly input: Input;
|
|
116
|
+
/** The output type of the schema. */
|
|
117
|
+
readonly output: Output$1;
|
|
118
|
+
}
|
|
119
|
+
/** Infers the input type of a Standard Typed. */
|
|
120
|
+
type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
121
|
+
/** Infers the output type of a Standard Typed. */
|
|
122
|
+
type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
123
|
+
}
|
|
124
|
+
/** The Standard Schema interface. */
|
|
125
|
+
interface StandardSchemaV1<Input = unknown, Output$1 = Input> {
|
|
126
|
+
/** The Standard Schema properties. */
|
|
127
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output$1>;
|
|
128
|
+
}
|
|
129
|
+
declare namespace StandardSchemaV1 {
|
|
130
|
+
/** The Standard Schema properties interface. */
|
|
131
|
+
interface Props<Input = unknown, Output$1 = Input> extends StandardTypedV1.Props<Input, Output$1> {
|
|
132
|
+
/** Validates unknown input values. */
|
|
133
|
+
readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output$1> | Promise<Result<Output$1>>;
|
|
134
|
+
}
|
|
135
|
+
/** The result interface of the validate function. */
|
|
136
|
+
type Result<Output$1> = SuccessResult<Output$1> | FailureResult;
|
|
137
|
+
/** The result interface if validation succeeds. */
|
|
138
|
+
interface SuccessResult<Output$1> {
|
|
139
|
+
/** The typed output value. */
|
|
140
|
+
readonly value: Output$1;
|
|
141
|
+
/** A falsy value for `issues` indicates success. */
|
|
142
|
+
readonly issues?: undefined;
|
|
143
|
+
}
|
|
144
|
+
interface Options {
|
|
145
|
+
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
146
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
147
|
+
}
|
|
148
|
+
/** The result interface if validation fails. */
|
|
149
|
+
interface FailureResult {
|
|
150
|
+
/** The issues of failed validation. */
|
|
151
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
152
|
+
}
|
|
153
|
+
/** The issue interface of the failure output. */
|
|
154
|
+
interface Issue {
|
|
155
|
+
/** The error message of the issue. */
|
|
156
|
+
readonly message: string;
|
|
157
|
+
/** The path of the issue, if any. */
|
|
158
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
159
|
+
}
|
|
160
|
+
/** The path segment interface of the issue. */
|
|
161
|
+
interface PathSegment {
|
|
162
|
+
/** The key representing a path segment. */
|
|
163
|
+
readonly key: PropertyKey;
|
|
164
|
+
}
|
|
165
|
+
/** The Standard types interface. */
|
|
166
|
+
interface Types<Input = unknown, Output$1 = Input> extends StandardTypedV1.Types<Input, Output$1> {}
|
|
167
|
+
/** Infers the input type of a Standard. */
|
|
168
|
+
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
169
|
+
/** Infers the output type of a Standard. */
|
|
170
|
+
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region ../restate-sdk-core/src/serde_api.d.ts
|
|
174
|
+
/**
|
|
175
|
+
* Serializer/deserializer pair for any Restate-managed value of type `T` —
|
|
176
|
+
* handler inputs and outputs, service state, side-effect results,
|
|
177
|
+
* awakeables, durable promises, and so on.
|
|
178
|
+
*
|
|
179
|
+
* A `Serde<T>` is responsible for two conversions:
|
|
180
|
+
*
|
|
181
|
+
* - **Wire format**: `serialize` / `deserialize` convert a value `T` to and
|
|
182
|
+
* from the raw bytes that flow over the network and get stored in the
|
|
183
|
+
* journal.
|
|
184
|
+
* - **JSON preview (optional)**: `preview.toJsonString` /
|
|
185
|
+
* `preview.fromJsonString` convert a value `T` to and from a JSON string,
|
|
186
|
+
* used by tooling to render and edit values that humans can read.
|
|
187
|
+
*
|
|
188
|
+
* It also advertises metadata (`contentType`, `jsonSchema`) that surfaces in
|
|
189
|
+
* service discovery.
|
|
190
|
+
*/
|
|
191
|
+
interface Serde<T> {
|
|
192
|
+
/**
|
|
193
|
+
* MIME type of the bytes produced by `serialize` (and accepted by
|
|
194
|
+
* `deserialize`).
|
|
195
|
+
*/
|
|
196
|
+
contentType?: string;
|
|
197
|
+
/**
|
|
198
|
+
* Optional JSON Schema describing the logical shape of `T`. Surfaced in
|
|
199
|
+
* discovery so that tooling can generate forms, auto-complete payloads,
|
|
200
|
+
* etc. Has no effect on serialization at runtime.
|
|
201
|
+
*/
|
|
202
|
+
jsonSchema?: object;
|
|
203
|
+
/**
|
|
204
|
+
* Optional bridge between the serde's wire format and a JSON
|
|
205
|
+
* representation that humans (and tooling like the Restate UI) can read
|
|
206
|
+
* and edit.
|
|
207
|
+
*
|
|
208
|
+
* Only useful for serdes whose wire format isn't already plain JSON —
|
|
209
|
+
* protobuf, MessagePack, length-prefixed binary, JSON variants that need
|
|
210
|
+
* post-processing for bigints/dates, etc. Both methods may be async if the
|
|
211
|
+
* conversion needs I/O.
|
|
212
|
+
*
|
|
213
|
+
* ### Preview flow
|
|
214
|
+
*
|
|
215
|
+
* Together with `serialize` / `deserialize`, the four functions chain in
|
|
216
|
+
* both directions between a JSON string and on-the-wire bytes:
|
|
217
|
+
*
|
|
218
|
+
* ```text
|
|
219
|
+
* JSON string ──fromJsonString──► T ──serialize──► wire bytes
|
|
220
|
+
* wire bytes ──deserialize────► T ──toJsonString──► JSON string
|
|
221
|
+
* ```
|
|
222
|
+
*
|
|
223
|
+
* The split keeps `serialize` / `deserialize` responsible for the full
|
|
224
|
+
* on-the-wire format; `preview` only handles the JSON ↔ `T` bridge.
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```ts
|
|
228
|
+
* // Wire format is protobuf; the protobuf-es runtime already ships
|
|
229
|
+
* // `toJsonString` / `fromJsonString`, so preview is a direct pass-through.
|
|
230
|
+
* import {
|
|
231
|
+
* fromBinary,
|
|
232
|
+
* fromJsonString,
|
|
233
|
+
* toBinary,
|
|
234
|
+
* toJsonString,
|
|
235
|
+
* } from "@bufbuild/protobuf";
|
|
236
|
+
* import { PersonSchema, type Person } from "./person_pb.js";
|
|
237
|
+
*
|
|
238
|
+
* const personSerde: Serde<Person> = {
|
|
239
|
+
* contentType: "application/protobuf",
|
|
240
|
+
* serialize(message) { return toBinary(PersonSchema, message); },
|
|
241
|
+
* deserialize(bytes) { return fromBinary(PersonSchema, bytes); },
|
|
242
|
+
* preview: {
|
|
243
|
+
* toJsonString: (v) => toJsonString(PersonSchema, v),
|
|
244
|
+
* fromJsonString: (j) => fromJsonString(PersonSchema, j),
|
|
245
|
+
* },
|
|
246
|
+
* };
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
preview?: {
|
|
250
|
+
/**
|
|
251
|
+
* Convert a value into a JSON string for display or editing by humans.
|
|
252
|
+
* The returned string must round-trip through `fromJsonString` back to
|
|
253
|
+
* the same logical value.
|
|
254
|
+
*/
|
|
255
|
+
toJsonString(value: T): Promise<string> | string;
|
|
256
|
+
/**
|
|
257
|
+
* Parse a human-supplied JSON string back into a value of type `T`.
|
|
258
|
+
* Should throw (or reject) if `json` is invalid for this serde.
|
|
259
|
+
*/
|
|
260
|
+
fromJsonString(json: string): Promise<T> | T;
|
|
261
|
+
};
|
|
262
|
+
/**
|
|
263
|
+
* Convert a value of type `T` into its on-the-wire bytes. This is the
|
|
264
|
+
* format Restate sends between services and persists in the journal.
|
|
265
|
+
*
|
|
266
|
+
* Must be the inverse of `deserialize` — `deserialize(serialize(v))`
|
|
267
|
+
* should produce a value equivalent to `v`.
|
|
268
|
+
*/
|
|
269
|
+
serialize(value: T): Uint8Array;
|
|
270
|
+
/**
|
|
271
|
+
* Convert on-the-wire bytes back into a value of type `T`. Must be the
|
|
272
|
+
* inverse of `serialize`.
|
|
273
|
+
*
|
|
274
|
+
* May throw if `data` doesn't conform to the expected wire format.
|
|
275
|
+
*/
|
|
276
|
+
deserialize(data: Uint8Array): T;
|
|
277
|
+
}
|
|
278
|
+
declare namespace serde {
|
|
279
|
+
class JsonSerde<T> implements Serde<T | undefined> {
|
|
280
|
+
readonly jsonSchema?: object | undefined;
|
|
281
|
+
contentType: string;
|
|
282
|
+
constructor(jsonSchema?: object | undefined);
|
|
283
|
+
serialize(value: T): Uint8Array;
|
|
284
|
+
deserialize(data: Uint8Array): T | undefined;
|
|
285
|
+
schema<U$1>(schema: object): Serde<U$1>;
|
|
286
|
+
}
|
|
287
|
+
const json: JsonSerde<any>;
|
|
288
|
+
const binary: Serde<Uint8Array>;
|
|
289
|
+
const empty: Serde<void>;
|
|
290
|
+
/**
|
|
291
|
+
* A Standard Schema-based serde.
|
|
292
|
+
*
|
|
293
|
+
* @param schema the standard schema
|
|
294
|
+
* @param validateOptions options passed to `StandardSchemaV1.Options.libraryOptions` when validating
|
|
295
|
+
* @param jsonSchemaOptions options passed to `StandardJsonSchemaV1.Options.libraryOptions` for code generation
|
|
296
|
+
* @returns a serde that will validate the data with the standard schema
|
|
297
|
+
*/
|
|
298
|
+
const schema: <T extends {
|
|
299
|
+
"~standard": StandardSchemaV1.Props;
|
|
300
|
+
}>(schema: T, validateOptions?: Record<string, unknown>, jsonSchemaOptions?: Record<string, unknown>) => Serde<StandardSchemaV1.InferOutput<T>>;
|
|
301
|
+
}
|
|
302
|
+
//#endregion
|
|
303
|
+
//#region ../restate-sdk-core/src/duration.d.ts
|
|
304
|
+
/**
|
|
305
|
+
* Duration type. Note that fields are additive.
|
|
306
|
+
*/
|
|
307
|
+
type Duration = {
|
|
308
|
+
days?: number;
|
|
309
|
+
hours?: number;
|
|
310
|
+
minutes?: number;
|
|
311
|
+
seconds?: number;
|
|
312
|
+
milliseconds?: number;
|
|
313
|
+
};
|
|
314
|
+
//#endregion
|
|
315
|
+
//#region ../restate-sdk-core/src/entry_codec.d.ts
|
|
316
|
+
/**
|
|
317
|
+
* Journal values codec.
|
|
318
|
+
*
|
|
319
|
+
* This allows to transform journal values after being serialized, before writing them to the wire.
|
|
320
|
+
*
|
|
321
|
+
* Values that are passed through the codec:
|
|
322
|
+
*
|
|
323
|
+
* * Handlers input and success output
|
|
324
|
+
* * ctx.run success results
|
|
325
|
+
* * Awakeables/Promise success results
|
|
326
|
+
* * State values
|
|
327
|
+
*
|
|
328
|
+
* @experimental
|
|
329
|
+
*/
|
|
330
|
+
type JournalValueCodec = {
|
|
331
|
+
/**
|
|
332
|
+
* Encodes the given buffer.
|
|
333
|
+
*
|
|
334
|
+
* This will be applied *after* serialization.
|
|
335
|
+
*
|
|
336
|
+
* @param buf The buffer to encode. Empty byte buffers should be appropriately handled as well.
|
|
337
|
+
* @returns The encoded buffer
|
|
338
|
+
*/
|
|
339
|
+
encode(buf: Uint8Array): Uint8Array;
|
|
340
|
+
/**
|
|
341
|
+
* Decodes the given buffer.
|
|
342
|
+
*
|
|
343
|
+
* This will be applied *before* deserialization.
|
|
344
|
+
*
|
|
345
|
+
* @param buf The buffer to decode.
|
|
346
|
+
* @returns A promise that resolves to the decoded buffer.
|
|
347
|
+
*/
|
|
348
|
+
decode(buf: Uint8Array): Promise<Uint8Array>;
|
|
349
|
+
};
|
|
350
|
+
//#endregion
|
|
351
|
+
//#region src/define.d.ts
|
|
352
|
+
/**
|
|
353
|
+
* Minimal descriptor stored in Descriptor._handlers per handler.
|
|
354
|
+
*/
|
|
355
|
+
type HandlerDescriptor<I$1 = any, O$1 = any> = {
|
|
356
|
+
readonly _inputSerde?: restate.Serde<I$1>;
|
|
357
|
+
readonly _outputSerde?: restate.Serde<O$1>;
|
|
358
|
+
};
|
|
359
|
+
/**
|
|
360
|
+
* The single client-facing type for all definition styles.
|
|
361
|
+
* - Returned by service() / object() / workflow() (also bindable to serve())
|
|
362
|
+
* - Returned by restate.interface.service/object/workflow (pure, not bindable)
|
|
363
|
+
* - Returned by implement() (also bindable)
|
|
364
|
+
*/
|
|
365
|
+
type Descriptor<P$1 extends string = string, H extends Record<string, HandlerDescriptor> = Record<string, HandlerDescriptor>, Kind extends "service" | "object" | "workflow" = "service" | "object" | "workflow"> = {
|
|
366
|
+
readonly name: P$1;
|
|
367
|
+
readonly _kind: Kind;
|
|
368
|
+
readonly _handlers: H;
|
|
369
|
+
};
|
|
370
|
+
/** Kind-specific aliases for the common Descriptor type */
|
|
371
|
+
type ServiceDescriptor<P$1 extends string = string, H extends Record<string, HandlerDescriptor> = Record<string, HandlerDescriptor>> = Descriptor<P$1, H, "service">;
|
|
372
|
+
type ObjectDescriptor<P$1 extends string = string, H extends Record<string, HandlerDescriptor> = Record<string, HandlerDescriptor>> = Descriptor<P$1, H, "object">;
|
|
373
|
+
type WorkflowDescriptor<P$1 extends string = string, H extends Record<string, HandlerDescriptor> = Record<string, HandlerDescriptor>> = Descriptor<P$1, H, "workflow">;
|
|
374
|
+
/** Implemented definition — extends Descriptor and also bindable to serve() */
|
|
375
|
+
type ImplementedServiceDefinition<P$1 extends string, H extends Record<string, HandlerDescriptor>> = restate.ServiceDefinition<P$1, any> & ServiceDescriptor<P$1, H>;
|
|
376
|
+
type ImplementedObjectDefinition<P$1 extends string, H extends Record<string, HandlerDescriptor>> = restate.VirtualObjectDefinition<P$1, any> & ObjectDescriptor<P$1, H>;
|
|
377
|
+
type ImplementedWorkflowDefinition<P$1 extends string, H extends Record<string, HandlerDescriptor>> = restate.WorkflowDefinition<P$1, any> & WorkflowDescriptor<P$1, H>;
|
|
378
|
+
type ImplementedDefinition<P$1 extends string, H extends Record<string, HandlerDescriptor>, Kind extends "service" | "object" | "workflow"> = Kind extends "service" ? ImplementedServiceDefinition<P$1, H> : Kind extends "object" ? ImplementedObjectDefinition<P$1, H> : ImplementedWorkflowDefinition<P$1, H>;
|
|
379
|
+
/** @internal
|
|
380
|
+
* @internal - Wraps a generator function with optional serde. Produced by typed().
|
|
381
|
+
* Discriminated by _genFn for runtime detection (distinct from bare gen fns,
|
|
382
|
+
* which are plain functions rather than objects).
|
|
383
|
+
*/
|
|
384
|
+
type HandlerDef<I$1 = any, O$1 = any> = {
|
|
385
|
+
readonly _genFn: (input: I$1) => Operation<O$1>;
|
|
386
|
+
} & HandlerDescriptor<I$1, O$1>;
|
|
387
|
+
/** @internal */
|
|
388
|
+
type EntryToDescriptor<E> = E extends HandlerDef<infer I, infer O> ? HandlerDescriptor<I, O> : E extends (() => Operation<infer O>) ? HandlerDescriptor<void, O> : E extends ((input: infer I) => Operation<infer O>) ? HandlerDescriptor<I, O> : HandlerDescriptor;
|
|
389
|
+
/** Map a full handler map type to the corresponding descriptor map type */
|
|
390
|
+
type HandlerDescriptors<H extends Record<string, HandlerOrHandlerDescriptor>> = { [K in keyof H]: EntryToDescriptor<H[K]> };
|
|
391
|
+
/** Options valid for all handler types (no serde — those live in typed()) */
|
|
392
|
+
type GenHandlerOpts = {
|
|
393
|
+
idempotencyRetention?: restate.Duration | number;
|
|
394
|
+
journalRetention?: restate.Duration | number;
|
|
395
|
+
inactivityTimeout?: restate.Duration | number;
|
|
396
|
+
abortTimeout?: restate.Duration | number;
|
|
397
|
+
retryPolicy?: restate.RetryPolicy;
|
|
398
|
+
description?: string;
|
|
399
|
+
metadata?: Record<string, string>;
|
|
400
|
+
ingressPrivate?: boolean;
|
|
401
|
+
explicitCancellation?: boolean;
|
|
402
|
+
};
|
|
403
|
+
/** Handler options for virtual object handlers */
|
|
404
|
+
type GenObjectHandlerOpts = GenHandlerOpts & {
|
|
405
|
+
shared?: boolean;
|
|
406
|
+
enableLazyState?: boolean;
|
|
407
|
+
};
|
|
408
|
+
/** Handler options for workflow handlers (shared is implicit from name) */
|
|
409
|
+
type GenWorkflowHandlerOpts = {
|
|
410
|
+
enableLazyState?: boolean;
|
|
411
|
+
};
|
|
412
|
+
/** @internal */
|
|
413
|
+
type AnyGenFn = (input: any) => Operation<any>;
|
|
414
|
+
/** A handler entry: either a bare generator fn or the result of typed() */
|
|
415
|
+
type HandlerOrHandlerDescriptor = AnyGenFn | HandlerDef<any, any>;
|
|
416
|
+
/** serdes(opts, fn) — explicit Serde per field */
|
|
417
|
+
declare function serdes<I$1, O$1>(opts: {
|
|
418
|
+
input: restate.Serde<I$1>;
|
|
419
|
+
output: restate.Serde<O$1>;
|
|
420
|
+
}, fn: (input: I$1) => Operation<O$1>): HandlerDef<I$1, O$1>;
|
|
421
|
+
/** schemas(opts, fn) — Standard Schema (Zod, TypeBox, Valibot, …) per field */
|
|
422
|
+
declare function schemas<SI extends StandardSchemaV1<any>, SO extends StandardSchemaV1<any>>(opts: {
|
|
423
|
+
input: SI;
|
|
424
|
+
output: SO;
|
|
425
|
+
}, fn: (input: StandardSchemaV1.InferOutput<SI>) => Operation<StandardSchemaV1.InferOutput<SO>>): HandlerDef<StandardSchemaV1.InferOutput<SI>, StandardSchemaV1.InferOutput<SO>>;
|
|
426
|
+
declare function service<P$1 extends string, H extends Record<string, HandlerOrHandlerDescriptor>>(config: {
|
|
427
|
+
name: P$1;
|
|
428
|
+
description?: string;
|
|
429
|
+
metadata?: Record<string, string>;
|
|
430
|
+
handlers: H;
|
|
431
|
+
options?: restate.ServiceOptions & {
|
|
432
|
+
handlers?: Partial<Record<keyof H, GenHandlerOpts>>;
|
|
433
|
+
};
|
|
434
|
+
}): ImplementedServiceDefinition<P$1, HandlerDescriptors<H>>;
|
|
435
|
+
declare function object<P$1 extends string, H extends Record<string, HandlerOrHandlerDescriptor>>(config: {
|
|
436
|
+
name: P$1;
|
|
437
|
+
description?: string;
|
|
438
|
+
metadata?: Record<string, string>;
|
|
439
|
+
handlers: H;
|
|
440
|
+
options?: restate.ObjectOptions & {
|
|
441
|
+
handlers?: Partial<Record<keyof H, GenObjectHandlerOpts>>;
|
|
442
|
+
};
|
|
443
|
+
}): ImplementedObjectDefinition<P$1, HandlerDescriptors<H>>;
|
|
444
|
+
declare function workflow<P$1 extends string, H extends Record<string, HandlerOrHandlerDescriptor>>(config: {
|
|
445
|
+
name: P$1;
|
|
446
|
+
description?: string;
|
|
447
|
+
metadata?: Record<string, string>;
|
|
448
|
+
handlers: H;
|
|
449
|
+
options?: restate.WorkflowOptions & {
|
|
450
|
+
handlers?: Partial<Record<keyof H, GenWorkflowHandlerOpts>>;
|
|
451
|
+
};
|
|
452
|
+
}): ImplementedWorkflowDefinition<P$1, HandlerDescriptors<H>>;
|
|
453
|
+
//#endregion
|
|
454
|
+
//#region src/clients.d.ts
|
|
455
|
+
/**
|
|
456
|
+
* A Future<O> that also carries an `invocation` field — a Future<InvocationReference<O>>
|
|
457
|
+
* for accessing the invocationId, attach, cancel, and signal of the underlying call.
|
|
458
|
+
*/
|
|
459
|
+
type ClientFuture<O$1> = Future<O$1> & {
|
|
460
|
+
invocation: Future<InvocationReference<O$1>>;
|
|
461
|
+
};
|
|
462
|
+
/** Client type returned by client() — each method returns ClientFuture<O> */
|
|
463
|
+
type GenClient<H extends Record<string, HandlerDescriptor>> = { readonly [K in keyof H]: H[K] extends HandlerDescriptor<infer I, infer O> ? [I] extends [void] ? (opts?: Opts<I, O>) => ClientFuture<O> : (input: I, opts?: Opts<I, O>) => ClientFuture<O> : never };
|
|
464
|
+
/** Client type returned by sendClient() — each method returns Future<InvocationReference<O>> */
|
|
465
|
+
type GenSendClient<H extends Record<string, HandlerDescriptor>> = { readonly [K in keyof H]: H[K] extends HandlerDescriptor<infer I, infer O> ? [I] extends [void] ? (opts?: SendOpts<I>) => Future<InvocationReference<O>> : (input: I, opts?: SendOpts<I>) => Future<InvocationReference<O>> : never };
|
|
466
|
+
//#endregion
|
|
467
|
+
//#region src/durable-promise.d.ts
|
|
468
|
+
/** Same shape as the SDK's DurablePromise<T> but each method returns Future<...>. */
|
|
469
|
+
type GenDurablePromise<T> = {
|
|
470
|
+
peek(): Future<T | undefined>;
|
|
471
|
+
resolve(value?: T): Future<void>;
|
|
472
|
+
reject(errorMsg: string): Future<void>;
|
|
473
|
+
get(): Future<T>;
|
|
474
|
+
};
|
|
475
|
+
//#endregion
|
|
476
|
+
//#region src/state.d.ts
|
|
477
|
+
/**
|
|
478
|
+
* Marker types matching the SDK's typed-state convention. Pass a
|
|
479
|
+
* concrete shape (e.g. `{count: number; name: string}`) to enable
|
|
480
|
+
* keyof-checked names; leave the default to keep names as `string`
|
|
481
|
+
* with a per-call value generic.
|
|
482
|
+
*/
|
|
483
|
+
type TypedState = Record<string, unknown>;
|
|
484
|
+
type UntypedState = {
|
|
485
|
+
_: never;
|
|
486
|
+
};
|
|
487
|
+
/**
|
|
488
|
+
* Read-only state, for handlers running under an
|
|
489
|
+
* ObjectSharedContext or WorkflowSharedContext.
|
|
490
|
+
*/
|
|
491
|
+
interface SharedState<TState extends TypedState = UntypedState> {
|
|
492
|
+
/** Read a state value. Returns null if the key isn't set. */
|
|
493
|
+
get<TValue, TKey extends keyof TState = string>(name: TState extends UntypedState ? string : TKey, serde?: restate.Serde<TState extends UntypedState ? TValue : TState[TKey]>): Future<(TState extends UntypedState ? TValue : TState[TKey]) | null>;
|
|
494
|
+
/** List all currently-known state keys. */
|
|
495
|
+
keys(): Future<string[]>;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* Read-write state, for handlers running under an ObjectContext or
|
|
499
|
+
* WorkflowContext. Extends SharedState with mutation methods.
|
|
500
|
+
*
|
|
501
|
+
* Writes are synchronous in the SDK — the journal entry is recorded
|
|
502
|
+
* immediately, no yield required — so `set` / `clear` / `clearAll`
|
|
503
|
+
* return `void` rather than `Operation<void>`.
|
|
504
|
+
*/
|
|
505
|
+
interface State<TState extends TypedState = UntypedState> extends SharedState<TState> {
|
|
506
|
+
/** Write a state value. Sync; journal entry recorded immediately. */
|
|
507
|
+
set<TValue, TKey extends keyof TState = string>(name: TState extends UntypedState ? string : TKey, value: TState extends UntypedState ? TValue : TState[TKey], serde?: restate.Serde<TState extends UntypedState ? TValue : TState[TKey]>): void;
|
|
508
|
+
/** Clear a single key. */
|
|
509
|
+
clear<TKey extends keyof TState>(name: TState extends UntypedState ? string : TKey): void;
|
|
510
|
+
/** Clear all state for this invocation. */
|
|
511
|
+
clearAll(): void;
|
|
512
|
+
}
|
|
513
|
+
//#endregion
|
|
514
|
+
//#region src/restate-operations.d.ts
|
|
515
|
+
type HandlerRequest = {
|
|
516
|
+
readonly target: Target$1;
|
|
517
|
+
/**
|
|
518
|
+
* The unique id that identifies the current function invocation. This id is guaranteed to be
|
|
519
|
+
* unique across invocations, but constant across reties and suspensions.
|
|
520
|
+
*/
|
|
521
|
+
readonly id: InvocationId;
|
|
522
|
+
readonly key?: string;
|
|
523
|
+
/**
|
|
524
|
+
* Request headers - the following headers capture the original invocation headers, as provided to
|
|
525
|
+
* the ingress.
|
|
526
|
+
*/
|
|
527
|
+
readonly headers: ReadonlyMap<string, string>;
|
|
528
|
+
/**
|
|
529
|
+
* Attempt headers - the following headers are sent by the restate runtime.
|
|
530
|
+
* These headers are attempt specific, generated by the restate runtime uniquely for each attempt.
|
|
531
|
+
* These headers might contain information such as the W3C trace context, and attempt specific information.
|
|
532
|
+
*/
|
|
533
|
+
readonly attemptHeaders: ReadonlyMap<string, string | string[] | undefined>;
|
|
534
|
+
/**
|
|
535
|
+
* Raw unparsed request body
|
|
536
|
+
*/
|
|
537
|
+
readonly body: Uint8Array;
|
|
538
|
+
/**
|
|
539
|
+
* Extra arguments provided to the request handler:
|
|
540
|
+
* Lambda: [Context]
|
|
541
|
+
* Cloudflare workers: [Env, ExecutionContext]
|
|
542
|
+
* Deno: [ConnInfo]
|
|
543
|
+
* Bun: [Server]
|
|
544
|
+
* These arguments can contain request-specific values that could change after a suspension.
|
|
545
|
+
* Care should be taken to use them deterministically.
|
|
546
|
+
*/
|
|
547
|
+
readonly extraArgs: unknown[];
|
|
548
|
+
};
|
|
549
|
+
/**
|
|
550
|
+
* Retry policy for `run`. Mirrors the SDK's `RunOptions` retry knobs
|
|
551
|
+
* but namespaced (no `Retry` prefix on each field) and grouped under
|
|
552
|
+
* `RunOpts.retry` for readability.
|
|
553
|
+
*/
|
|
554
|
+
type RetryOptions = {
|
|
555
|
+
/**
|
|
556
|
+
* Max attempts (including the initial). When reached, `run` throws
|
|
557
|
+
* a `TerminalError` wrapping the original error message.
|
|
558
|
+
*/
|
|
559
|
+
maxAttempts?: number;
|
|
560
|
+
/**
|
|
561
|
+
* Max total duration of retries before giving up. Number is ms.
|
|
562
|
+
*/
|
|
563
|
+
maxDuration?: restate.Duration | number;
|
|
564
|
+
/**
|
|
565
|
+
* First retry delay. Subsequent delays grow by `intervalFactor`.
|
|
566
|
+
* Number is ms. Defaults to 50 ms.
|
|
567
|
+
*/
|
|
568
|
+
initialInterval?: restate.Duration | number;
|
|
569
|
+
/**
|
|
570
|
+
* Cap on retry delay. Number is ms. Defaults to 10 s.
|
|
571
|
+
*/
|
|
572
|
+
maxInterval?: restate.Duration | number;
|
|
573
|
+
/**
|
|
574
|
+
* Multiplier applied to the previous delay. Defaults to 2.
|
|
575
|
+
*/
|
|
576
|
+
intervalFactor?: number;
|
|
577
|
+
};
|
|
578
|
+
/**
|
|
579
|
+
* Options for `run`. Both fields are optional; if `name` is omitted,
|
|
580
|
+
* the action's `Function.name` is used (works for named functions and
|
|
581
|
+
* for arrow functions assigned to a `const` since JS infers names from
|
|
582
|
+
* the binding site). If neither resolves, `run` throws.
|
|
583
|
+
*/
|
|
584
|
+
type RunOpts<T> = {
|
|
585
|
+
/** Journal entry name. Falls back to `action.name` if absent. */
|
|
586
|
+
name?: string;
|
|
587
|
+
/** Retry policy. Defaults to the SDK's defaults if absent. */
|
|
588
|
+
retry?: RetryOptions;
|
|
589
|
+
/** Custom serde for the journaled value. */
|
|
590
|
+
serde?: restate.Serde<T>;
|
|
591
|
+
};
|
|
592
|
+
/**
|
|
593
|
+
* Options object passed to the closure of `run(...)`. Carries an
|
|
594
|
+
* AbortSignal that fires when invocation cancellation arrives.
|
|
595
|
+
*
|
|
596
|
+
* Using an object (rather than positional args) leaves room to extend
|
|
597
|
+
* the closure's API surface — additional fields may be added later
|
|
598
|
+
* without breaking existing closures.
|
|
599
|
+
*/
|
|
600
|
+
type RunActionOpts = {
|
|
601
|
+
readonly signal: AbortSignal;
|
|
602
|
+
};
|
|
603
|
+
/**
|
|
604
|
+
* The closure that `run` invokes. Receives `{ signal }` — pass the
|
|
605
|
+
* signal into AbortSignal-aware APIs (e.g. `fetch(url, { signal })`)
|
|
606
|
+
* to cancel in-flight syscalls promptly.
|
|
607
|
+
*/
|
|
608
|
+
type RunAction<T> = (opts: RunActionOpts) => Promise<T>;
|
|
609
|
+
/**
|
|
610
|
+
* Wrap a user-supplied `run` closure to surface the abort reason
|
|
611
|
+
* (typically a TerminalError(CANCELLED)) on throw paths if the signal
|
|
612
|
+
* aborted during execution. This converts AbortError (and any other
|
|
613
|
+
* abort-caused failure) into the canonical cancellation TerminalError
|
|
614
|
+
* for journal recording.
|
|
615
|
+
*
|
|
616
|
+
* Defensive coercion: if `signal.reason` is itself not a TerminalError
|
|
617
|
+
* (which shouldn't happen in production but might during testing or
|
|
618
|
+
* with non-cancellation race rejections), we wrap it in one. The
|
|
619
|
+
* journal must record a *terminal* outcome to avoid retries against
|
|
620
|
+
* a cancelled invocation.
|
|
621
|
+
*
|
|
622
|
+
* Exposed for testing — the wrapper's behavior is the part that has
|
|
623
|
+
* semantic bite, separate from the ctx.run plumbing.
|
|
624
|
+
*/
|
|
625
|
+
declare function wrapActionForCancellation<T>(signal: AbortSignal, action: RunAction<T>): () => Promise<T>;
|
|
626
|
+
/**
|
|
627
|
+
* Deterministic date methods that return journal-backed Futures.
|
|
628
|
+
* Wraps the SDK's `ContextDate` (which returns Promises via internal
|
|
629
|
+
* `ctx.run()` calls) so that gen-SDK user code can `yield*` them.
|
|
630
|
+
*/
|
|
631
|
+
interface GenContextDate {
|
|
632
|
+
now(): Future<number>;
|
|
633
|
+
toJSON(): Future<string>;
|
|
634
|
+
}
|
|
635
|
+
//#endregion
|
|
636
|
+
//#region src/free.d.ts
|
|
637
|
+
declare const rand: () => restate.Rand;
|
|
638
|
+
declare const date: () => GenContextDate;
|
|
639
|
+
declare const logger: () => Console;
|
|
640
|
+
/**
|
|
641
|
+
* Returns the current invocation's request metadata plus the optional
|
|
642
|
+
* virtual-object / workflow key. The `key` field is only present when
|
|
643
|
+
* the handler belongs to an object or workflow.
|
|
644
|
+
*/
|
|
645
|
+
declare const handlerRequest: () => HandlerRequest;
|
|
646
|
+
/**
|
|
647
|
+
* Run a side-effecting closure as a journal entry. See
|
|
648
|
+
* `RestateOperations.run` for full semantics.
|
|
649
|
+
*
|
|
650
|
+
* `name` is derived from `action.name` (works for named functions and
|
|
651
|
+
* arrow functions assigned to a `const`) or specified explicitly via
|
|
652
|
+
* `opts.name`. If neither resolves, throws.
|
|
653
|
+
*/
|
|
654
|
+
declare const run: <T>(action: RunAction<T>, opts?: RunOpts<T>) => Future<T>;
|
|
655
|
+
declare const sleep: (duration: restate.Duration | number, name?: string) => Future<void>;
|
|
656
|
+
declare const awakeable: <T>(serde?: restate.Serde<T>) => {
|
|
657
|
+
id: string;
|
|
658
|
+
promise: Future<T>;
|
|
659
|
+
};
|
|
660
|
+
declare const resolveAwakeable: <T>(id: string, payload?: T, serde?: restate.Serde<T>) => void;
|
|
661
|
+
declare const rejectAwakeable: (id: string, reason: string | restate.TerminalError) => void;
|
|
662
|
+
declare const signal: <T>(name: string, serde?: restate.Serde<T>) => Future<T>;
|
|
663
|
+
declare const attach: <T>(invocationId: restate.InvocationId, serde?: restate.Serde<T>) => Future<T>;
|
|
664
|
+
declare function client<H extends Record<string, HandlerDescriptor>>(def: Descriptor<string, H, "service">): GenClient<H>;
|
|
665
|
+
declare function client<H extends Record<string, HandlerDescriptor>>(def: Descriptor<string, H, "object" | "workflow">, key: string): GenClient<H>;
|
|
666
|
+
declare function sendClient<H extends Record<string, HandlerDescriptor>>(def: Descriptor<string, H, "service">): GenSendClient<H>;
|
|
667
|
+
declare function sendClient<H extends Record<string, HandlerDescriptor>>(def: Descriptor<string, H, "object" | "workflow">, key: string): GenSendClient<H>;
|
|
668
|
+
declare const call: <REQ = Uint8Array, RES = Uint8Array>(c: restate.GenericCall<REQ, RES>) => ClientFuture<RES>;
|
|
669
|
+
declare const send: <REQ = Uint8Array, RES = unknown>(c: restate.GenericSend<REQ>, outputSerde?: restate.Serde<RES>) => Future<InvocationReference<RES>>;
|
|
670
|
+
/**
|
|
671
|
+
* Create an InvocationReference from a known invocation ID (e.g. retrieved from state).
|
|
672
|
+
* `attach()` and `cancel()` on the result use the current fiber slot like all free functions.
|
|
673
|
+
*/
|
|
674
|
+
declare function invocation<O$1 = unknown>(id: string, opts?: {
|
|
675
|
+
outputSerde?: restate.Serde<O$1>;
|
|
676
|
+
}): InvocationReference<O$1>;
|
|
677
|
+
declare const cancel: (invocationId: restate.InvocationId) => void;
|
|
678
|
+
declare const channel: <T>() => Channel<T>;
|
|
679
|
+
declare const state: <TState extends TypedState = UntypedState>() => State<TState>;
|
|
680
|
+
declare const sharedState: <TState extends TypedState = UntypedState>() => SharedState<TState>;
|
|
681
|
+
declare const workflowPromise: <T>(name: string, serde?: restate.Serde<T>) => GenDurablePromise<T>;
|
|
682
|
+
/**
|
|
683
|
+
* Wait for every future to settle; return their values in input order.
|
|
684
|
+
* Heterogeneous-tuple typing — `all([fA, fB])` where `fA: Future<A>`
|
|
685
|
+
* and `fB: Future<B>` yields `Future<[A, B]>`. Mirrors `Promise.all`.
|
|
686
|
+
*/
|
|
687
|
+
declare const all: <const T extends readonly Future<unknown>[] | []>(futures: T) => Future<FutureValues<T>>;
|
|
688
|
+
/**
|
|
689
|
+
* Return the first future to settle; losers continue running but their
|
|
690
|
+
* results are discarded. Heterogeneous-tuple typing — `race([fA, fB])`
|
|
691
|
+
* yields `Future<A | B>`. Mirrors `Promise.race`.
|
|
692
|
+
*/
|
|
693
|
+
declare const race: <const T extends readonly Future<unknown>[] | []>(futures: T) => Future<FutureValues<T>[number]>;
|
|
694
|
+
/**
|
|
695
|
+
* First-to-succeed wins (non-rejected). Rejects with `AggregateError(errors)`
|
|
696
|
+
* when every input rejects (including the empty input case). Tuple-aware —
|
|
697
|
+
* `any([fA, fB])` yields `Future<A | B>`. Mirrors `Promise.any`.
|
|
698
|
+
*/
|
|
699
|
+
declare const any: <const T extends readonly Future<unknown>[] | []>(futures: T) => Future<FutureValues<T>[number]>;
|
|
700
|
+
/**
|
|
701
|
+
* Wait for every future to settle; never rejects. Tuple-aware —
|
|
702
|
+
* `allSettled([fA, fB])` yields
|
|
703
|
+
* `Future<[FutureSettledResult<A>, FutureSettledResult<B>]>`.
|
|
704
|
+
* Mirrors `Promise.allSettled`.
|
|
705
|
+
*/
|
|
706
|
+
declare const allSettled: <const T extends readonly Future<unknown>[] | []>(futures: T) => Future<{ -readonly [P in keyof T]: FutureSettledResult<T[P] extends Future<infer U> ? U : never> }>;
|
|
707
|
+
/**
|
|
708
|
+
* Register `op` as a fresh routine and return a `Future<T>` for its
|
|
709
|
+
* eventual outcome. Eager — the child is already in flight by the time
|
|
710
|
+
* `spawn` returns. See `RestateOperations.spawn` for full semantics.
|
|
711
|
+
*/
|
|
712
|
+
declare const spawn: <T>(op: Operation<T>) => Future<T>;
|
|
713
|
+
declare namespace interface_d_exports {
|
|
714
|
+
export { ImplementHandlers, InferInput, InferOutput, implement, json, object$1 as object, schemas$1 as schemas, serdes$1 as serdes, service$1 as service, workflow$1 as workflow };
|
|
715
|
+
}
|
|
716
|
+
/** json<I, O>() — type params, default JSON serde */
|
|
717
|
+
declare function json<I$1 = void, O$1 = void>(): HandlerDescriptor<I$1, O$1>;
|
|
718
|
+
/** serdes(opts) — explicit Serde per field */
|
|
719
|
+
declare function serdes$1<SI extends restate.Serde<any>, SO extends restate.Serde<any>>(opts: {
|
|
720
|
+
input?: SI;
|
|
721
|
+
output?: SO;
|
|
722
|
+
}): HandlerDescriptor<SI extends restate.Serde<infer I> ? I : never, SO extends restate.Serde<infer O> ? O : never>;
|
|
723
|
+
/** schemas(opts) — Standard Schema (Zod, TypeBox, Valibot, …) per field */
|
|
724
|
+
declare function schemas$1<SI extends StandardSchemaV1<any>, SO extends StandardSchemaV1<any>>(opts: {
|
|
725
|
+
input?: SI;
|
|
726
|
+
output?: SO;
|
|
727
|
+
}): HandlerDescriptor<StandardSchemaV1.InferOutput<NonNullable<SI>>, StandardSchemaV1.InferOutput<NonNullable<SO>>>;
|
|
728
|
+
declare function service$1<P$1 extends string, H extends Record<string, HandlerDescriptor>>(name: P$1, handlers: H): ServiceDescriptor<P$1, H>;
|
|
729
|
+
declare function object$1<P$1 extends string, H extends Record<string, HandlerDescriptor>>(name: P$1, handlers: H): ObjectDescriptor<P$1, H>;
|
|
730
|
+
declare function workflow$1<P$1 extends string, H extends Record<string, HandlerDescriptor>>(name: P$1, handlers: H): WorkflowDescriptor<P$1, H>;
|
|
731
|
+
/** @internal */
|
|
732
|
+
type InferInput<D> = D extends HandlerDescriptor<infer I, any> ? I : any;
|
|
733
|
+
/** @internal */
|
|
734
|
+
type InferOutput<D> = D extends HandlerDescriptor<any, infer O> ? O : any;
|
|
735
|
+
/** @internal */
|
|
736
|
+
type ImplementHandlers<H extends Record<string, HandlerDescriptor>> = { [K in keyof H]: (input: InferInput<H[K]>) => Operation<InferOutput<H[K]>> };
|
|
737
|
+
declare function implement<P$1 extends string, H extends Record<string, HandlerDescriptor>>(iface: ServiceDescriptor<P$1, H>, config: {
|
|
738
|
+
handlers: ImplementHandlers<H>;
|
|
739
|
+
options?: restate.ServiceOptions & {
|
|
740
|
+
handlers?: Partial<Record<keyof H, GenHandlerOpts>>;
|
|
741
|
+
};
|
|
742
|
+
}): ImplementedServiceDefinition<P$1, H>;
|
|
743
|
+
declare function implement<P$1 extends string, H extends Record<string, HandlerDescriptor>>(iface: ObjectDescriptor<P$1, H>, config: {
|
|
744
|
+
handlers: ImplementHandlers<H>;
|
|
745
|
+
options?: restate.ObjectOptions & {
|
|
746
|
+
handlers?: Partial<Record<keyof H, GenObjectHandlerOpts>>;
|
|
747
|
+
};
|
|
748
|
+
}): ImplementedObjectDefinition<P$1, H>;
|
|
749
|
+
declare function implement<P$1 extends string, H extends Record<string, HandlerDescriptor>>(iface: WorkflowDescriptor<P$1, H>, config: {
|
|
750
|
+
handlers: ImplementHandlers<H>;
|
|
751
|
+
options?: restate.WorkflowOptions & {
|
|
752
|
+
handlers?: Partial<Record<keyof H, GenWorkflowHandlerOpts>>;
|
|
753
|
+
};
|
|
754
|
+
}): ImplementedWorkflowDefinition<P$1, H>;
|
|
755
|
+
//#endregion
|
|
756
|
+
//#region ../restate-sdk-clients/src/api.d.ts
|
|
757
|
+
/**
|
|
758
|
+
* A remote client for a Restate service.
|
|
759
|
+
*
|
|
760
|
+
* Use the following client to interact with services defined
|
|
761
|
+
* - `serviceClient` to create a client for a service.
|
|
762
|
+
* - `workflowClient` to create a client for a workflow.
|
|
763
|
+
* - `objectClient` to create a client for a virtual object.
|
|
764
|
+
*
|
|
765
|
+
*/
|
|
766
|
+
interface Ingress {
|
|
767
|
+
/**
|
|
768
|
+
* Create a client from a {@link ServiceDefinition}.
|
|
769
|
+
*/
|
|
770
|
+
serviceClient<D>(opts: ServiceDefinitionFrom<D>): IngressClient<Service<D>>;
|
|
771
|
+
/**
|
|
772
|
+
* Create a client from a {@link WorkflowDefinition}.
|
|
773
|
+
*
|
|
774
|
+
* @param key the key of the workflow.
|
|
775
|
+
*/
|
|
776
|
+
workflowClient<D>(opts: WorkflowDefinitionFrom<D>, key: string): IngressWorkflowClient<Workflow<D>>;
|
|
777
|
+
/**
|
|
778
|
+
* Create a client from a {@link VirtualObjectDefinition}.
|
|
779
|
+
* @param key the key of the virtual object.
|
|
780
|
+
*/
|
|
781
|
+
objectClient<D>(opts: VirtualObjectDefinitionFrom<D>, key: string): IngressClient<VirtualObject<D>>;
|
|
782
|
+
/**
|
|
783
|
+
* Create a client from a {@link ServiceDefinition}.
|
|
784
|
+
*/
|
|
785
|
+
serviceSendClient<D>(opts: ServiceDefinitionFrom<D>): IngressSendClient<Service<D>>;
|
|
786
|
+
/**
|
|
787
|
+
* Create a client from a {@link VirtualObjectDefinition}.
|
|
788
|
+
*/
|
|
789
|
+
objectSendClient<D>(opts: VirtualObjectDefinitionFrom<D>, key: string): IngressSendClient<VirtualObject<D>>;
|
|
790
|
+
/**
|
|
791
|
+
* Resolve an awakeable from the ingress client.
|
|
792
|
+
*/
|
|
793
|
+
resolveAwakeable<T>(id: string, payload?: T, payloadSerde?: Serde<T>): Promise<void>;
|
|
794
|
+
/**
|
|
795
|
+
* Reject an awakeable from the ingress client.
|
|
796
|
+
*/
|
|
797
|
+
rejectAwakeable(id: string, reason: string): Promise<void>;
|
|
798
|
+
/**
|
|
799
|
+
* Obtain the result of a service that was asynchronously submitted (via a sendClient).
|
|
800
|
+
*
|
|
801
|
+
* @param send either the send response or the workflow submission as obtained by the respective clients.
|
|
802
|
+
*/
|
|
803
|
+
result<T>(send: Send<T> | WorkflowSubmission<T>, resultSerde?: Serde<T>): Promise<T>;
|
|
804
|
+
/** Generic request-response call. Routes directly by service name without a typed definition. */
|
|
805
|
+
call<I$1 = Uint8Array, O$1 = Uint8Array>(opts: {
|
|
806
|
+
service: string;
|
|
807
|
+
handler: string;
|
|
808
|
+
parameter: I$1;
|
|
809
|
+
key?: string;
|
|
810
|
+
opts?: Opts$1<I$1, O$1>;
|
|
811
|
+
}): Promise<O$1>;
|
|
812
|
+
/** Generic fire-and-forget send. Routes directly by service name without a typed definition. */
|
|
813
|
+
send<I$1 = Uint8Array>(opts: {
|
|
814
|
+
service: string;
|
|
815
|
+
handler: string;
|
|
816
|
+
parameter: I$1;
|
|
817
|
+
key?: string;
|
|
818
|
+
opts?: SendOpts$1<I$1>;
|
|
819
|
+
}): Promise<Send>;
|
|
820
|
+
}
|
|
821
|
+
interface IngressCallOptions<I$1 = unknown, O$1 = unknown> {
|
|
822
|
+
/**
|
|
823
|
+
* Key to use for idempotency key.
|
|
824
|
+
*
|
|
825
|
+
* See https://docs.restate.dev/operate/invocation#invoke-a-handler-idempotently for more details.
|
|
826
|
+
*/
|
|
827
|
+
idempotencyKey?: string;
|
|
828
|
+
/**
|
|
829
|
+
* Headers to attach to the request.
|
|
830
|
+
*/
|
|
831
|
+
headers?: Record<string, string>;
|
|
832
|
+
input?: Serde<I$1>;
|
|
833
|
+
output?: Serde<O$1>;
|
|
834
|
+
/**
|
|
835
|
+
* Timeout to be used when executing the request. In milliseconds.
|
|
836
|
+
*
|
|
837
|
+
* Same as {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal#aborting_a_fetch_with_timeout_or_explicit_abort | AbortSignal.timeout()}.
|
|
838
|
+
*
|
|
839
|
+
* This field is exclusive with `signal`, and using both of them will result in a runtime failure.
|
|
840
|
+
*/
|
|
841
|
+
timeout?: number;
|
|
842
|
+
/**
|
|
843
|
+
* Signal to abort the underlying `fetch` operation. See {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}.
|
|
844
|
+
*
|
|
845
|
+
* This field is exclusive with `timeout`, and using both of them will result in a runtime failure.
|
|
846
|
+
*/
|
|
847
|
+
signal?: AbortSignal;
|
|
848
|
+
}
|
|
849
|
+
interface IngressSendOptions<I$1> extends IngressCallOptions<I$1, void> {
|
|
850
|
+
/**
|
|
851
|
+
* If set, the invocation will be enqueued now to be executed after the provided delay. In milliseconds.
|
|
852
|
+
*/
|
|
853
|
+
delay?: number | Duration;
|
|
854
|
+
}
|
|
855
|
+
declare class Opts$1<I$1, O$1> {
|
|
856
|
+
readonly opts: IngressCallOptions<I$1, O$1>;
|
|
857
|
+
/**
|
|
858
|
+
* Create a call configuration from the provided options.
|
|
859
|
+
*
|
|
860
|
+
* @param opts the call configuration
|
|
861
|
+
*/
|
|
862
|
+
static from<I$1 = unknown, O$1 = unknown>(opts: IngressCallOptions<I$1, O$1>): Opts$1<I$1, O$1>;
|
|
863
|
+
constructor(opts: IngressCallOptions<I$1, O$1>);
|
|
864
|
+
}
|
|
865
|
+
declare class SendOpts$1<I$1 = unknown> {
|
|
866
|
+
readonly opts: IngressSendOptions<I$1>;
|
|
867
|
+
/**
|
|
868
|
+
* @param opts Create send options
|
|
869
|
+
*/
|
|
870
|
+
static from<I$1 = unknown>(opts: IngressSendOptions<I$1>): SendOpts$1<I$1>;
|
|
871
|
+
delay(): number | undefined;
|
|
872
|
+
constructor(opts: IngressSendOptions<I$1>);
|
|
873
|
+
}
|
|
874
|
+
type InferArgType<P$1> = P$1 extends [infer A, ...any[]] ? A : unknown;
|
|
875
|
+
type IngressClient<M> = { [K in keyof M as M[K] extends never ? never : K]: M[K] extends ((arg: any, ...args: infer P) => PromiseLike<infer O>) ? (...args: [...P, ...[opts?: Opts$1<InferArgType<P>, O>]]) => PromiseLike<O> : never };
|
|
876
|
+
/**
|
|
877
|
+
* Represents the output of a workflow.
|
|
878
|
+
*/
|
|
879
|
+
interface Output<O$1> {
|
|
880
|
+
/**
|
|
881
|
+
* Whether the output is ready.
|
|
882
|
+
*/
|
|
883
|
+
ready: boolean;
|
|
884
|
+
/**
|
|
885
|
+
* The output of the workflow.
|
|
886
|
+
*/
|
|
887
|
+
result: O$1;
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* Represents a successful workflow submission.
|
|
891
|
+
*
|
|
892
|
+
*/
|
|
893
|
+
type WorkflowSubmission<T> = {
|
|
894
|
+
/**
|
|
895
|
+
* The invocation id of the workflow. You can use that id to
|
|
896
|
+
* with the introspection tools (restate cli, logging, metrics)
|
|
897
|
+
*
|
|
898
|
+
*/
|
|
899
|
+
readonly invocationId: string;
|
|
900
|
+
readonly status: "Accepted" | "PreviouslyAccepted";
|
|
901
|
+
readonly attachable: true;
|
|
902
|
+
};
|
|
903
|
+
/**
|
|
904
|
+
* A client for a workflow.
|
|
905
|
+
*
|
|
906
|
+
* This client represents the workflow definition, with the following additional methods:
|
|
907
|
+
* - `workflowSubmit` to submit the workflow.
|
|
908
|
+
* - `workflowAttach` to attach to the workflow and wait for its completion
|
|
909
|
+
* - `workflowOutput` to check if the workflow's output is ready/available.
|
|
910
|
+
*
|
|
911
|
+
* Once a workflow is submitted, it can be attached to, and the output can be retrieved.
|
|
912
|
+
*
|
|
913
|
+
* @typeParam M the type of the workflow.
|
|
914
|
+
*/
|
|
915
|
+
type IngressWorkflowClient<M> = Omit<{ [K in keyof M as M[K] extends never ? never : K]: M[K] extends ((arg: any, ...args: infer P) => PromiseLike<infer O>) ? (...args: [...P, ...[opts?: Opts$1<InferArgType<P>, O>]]) => PromiseLike<O> : never } & {
|
|
916
|
+
/**
|
|
917
|
+
* Submit this workflow.
|
|
918
|
+
*
|
|
919
|
+
* This instructs restate to execute the 'run' handler of the workflow, idempotently.
|
|
920
|
+
* The workflow will be executed asynchronously, and the promise will resolve when the workflow has been accepted.
|
|
921
|
+
* Please note that submitting a workflow does not wait for it to completion, and it is safe to retry the submission,
|
|
922
|
+
* in case of failure.
|
|
923
|
+
*
|
|
924
|
+
* @param argument the same argument type as defined by the 'run' handler.
|
|
925
|
+
*/
|
|
926
|
+
workflowSubmit: M extends Record<string, unknown> ? M["run"] extends ((arg: any, ...args: infer I) => Promise<infer O>) ? (...args: [...I, ...[opts?: SendOpts$1<InferArgType<I>>]]) => Promise<WorkflowSubmission<O>> : never : never;
|
|
927
|
+
/**
|
|
928
|
+
* Attach to this workflow.
|
|
929
|
+
*
|
|
930
|
+
* This instructs restate to attach to the workflow and wait for it to complete.
|
|
931
|
+
* It is only possible to 'attach' to a workflow that has been previously submitted.
|
|
932
|
+
* The promise will resolve when the workflow has completed either successfully with a result,
|
|
933
|
+
* or be rejected with an error.
|
|
934
|
+
* This operation is safe to retry many times, and it will always return the same result.
|
|
935
|
+
*
|
|
936
|
+
* @returns a promise that resolves when the workflow has completed.
|
|
937
|
+
*/
|
|
938
|
+
workflowAttach: M extends Record<string, unknown> ? M["run"] extends ((...args: any) => Promise<infer O>) ? (opts?: Opts$1<void, O>) => Promise<O> : never : never;
|
|
939
|
+
/**
|
|
940
|
+
* Try retrieving the output of this workflow.
|
|
941
|
+
*
|
|
942
|
+
* This instructs restate to check if the workflow's output is ready/available.
|
|
943
|
+
* The returned Output object will have a 'ready' field set to true if the output is ready.
|
|
944
|
+
* If the output is ready, the 'result' field will contain the output.
|
|
945
|
+
* note: that this operation will not wait for the workflow to complete, to do so use 'workflowAttach'.
|
|
946
|
+
*
|
|
947
|
+
* @returns a promise that resolves if the workflow's output is ready/available.
|
|
948
|
+
*/
|
|
949
|
+
workflowOutput: M extends Record<string, unknown> ? M["run"] extends ((...args: any) => Promise<infer O>) ? (opts?: Opts$1<void, O>) => Promise<Output<O>> : never : never;
|
|
950
|
+
}, "run">;
|
|
951
|
+
/**
|
|
952
|
+
* A send response.
|
|
953
|
+
*
|
|
954
|
+
* @typeParam T the type of the response.
|
|
955
|
+
*/
|
|
956
|
+
type Send<T = unknown> = {
|
|
957
|
+
/**
|
|
958
|
+
* The invocation id of the send.
|
|
959
|
+
*/
|
|
960
|
+
invocationId: string;
|
|
961
|
+
/**
|
|
962
|
+
* The status of the send.
|
|
963
|
+
*/
|
|
964
|
+
status: "Accepted" | "PreviouslyAccepted";
|
|
965
|
+
attachable: boolean;
|
|
966
|
+
};
|
|
967
|
+
type IngressSendClient<M> = { [K in keyof M as M[K] extends never ? never : K]: M[K] extends ((arg: any, ...args: infer P) => PromiseLike<infer O>) ? (...args: [...P, ...[opts?: SendOpts$1<InferArgType<P>>]]) => Promise<Send<O>> : never };
|
|
968
|
+
type ConnectionOpts = {
|
|
969
|
+
/**
|
|
970
|
+
* Restate ingress URL.
|
|
971
|
+
* For example: http://localhost:8080
|
|
972
|
+
*/
|
|
973
|
+
url: string;
|
|
974
|
+
/**
|
|
975
|
+
* Headers to attach on every request.
|
|
976
|
+
* Use this to attach authentication headers.
|
|
977
|
+
*/
|
|
978
|
+
headers?: Record<string, string>;
|
|
979
|
+
/**
|
|
980
|
+
* Default serde to use for ingress payloads when no operation-specific serde
|
|
981
|
+
* is provided. Applies to handler calls, workflow attaches/output polling,
|
|
982
|
+
* awakeable resolution, and attached invocation results.
|
|
983
|
+
*
|
|
984
|
+
* Defaults to `restate.serde.json`.
|
|
985
|
+
*/
|
|
986
|
+
serde?: Serde<any>;
|
|
987
|
+
/**
|
|
988
|
+
* Codec to use for input/outputs. Check {@link JournalValueCodec} for more details
|
|
989
|
+
*
|
|
990
|
+
* @experimental
|
|
991
|
+
*/
|
|
992
|
+
journalValueCodec?: JournalValueCodec;
|
|
993
|
+
};
|
|
994
|
+
declare namespace ingress_d_exports {
|
|
995
|
+
export { ConnectionOpts, GenIngress, Ingress, IngressClient, IngressHandlerClient, IngressSendClient, IngressSendHandlerClient, IngressWorkflowClient, Opts$1 as Opts, Send, SendOpts$1 as SendOpts, client$1 as client, connect, sendClient$1 as sendClient };
|
|
996
|
+
}
|
|
997
|
+
/**
|
|
998
|
+
* Connect to the Restate Ingress.
|
|
999
|
+
*
|
|
1000
|
+
* @param opts connection options
|
|
1001
|
+
* @returns a connection the the restate ingress
|
|
1002
|
+
*/
|
|
1003
|
+
declare function connect(opts: ConnectionOpts): GenIngress;
|
|
1004
|
+
/**
|
|
1005
|
+
* Minimal ingress interface required by the sdk-gen ingress helpers.
|
|
1006
|
+
* Structurally compatible with `Ingress` from `@restatedev/restate-sdk-clients`
|
|
1007
|
+
* — any object returned by `connect()` satisfies this.
|
|
1008
|
+
*/
|
|
1009
|
+
type GenIngress = Omit<Ingress, "serviceClient" | "serviceSendClient" | "objectClient" | "objectSendClient" | "workflowClient">;
|
|
1010
|
+
type InferInput$1<D> = D extends HandlerDescriptor<infer I, any> ? I : unknown;
|
|
1011
|
+
type InferOutput$1<D> = D extends HandlerDescriptor<any, infer O> ? O : unknown;
|
|
1012
|
+
/** Typed ingress call client — each method returns Promise<O> */
|
|
1013
|
+
type IngressHandlerClient<H extends Record<string, HandlerDescriptor>> = { readonly [K in keyof H]: (input: InferInput$1<H[K]>, opts?: Opts$1<InferInput$1<H[K]>, InferOutput$1<H[K]>>) => Promise<InferOutput$1<H[K]>> };
|
|
1014
|
+
/** Typed ingress send client — each method returns Promise<Send> */
|
|
1015
|
+
type IngressSendHandlerClient<H extends Record<string, HandlerDescriptor>> = { readonly [K in keyof H]: [InferInput$1<H[K]>] extends [void] ? (opts?: SendOpts$1<void>) => Promise<Send> : (input: InferInput$1<H[K]>, opts?: SendOpts$1<InferInput$1<H[K]>>) => Promise<Send> };
|
|
1016
|
+
declare function client$1<H extends Record<string, HandlerDescriptor>>(ingress: GenIngress, def: Descriptor<string, H, "service">): IngressHandlerClient<H>;
|
|
1017
|
+
declare function client$1<H extends Record<string, HandlerDescriptor>>(ingress: GenIngress, def: Descriptor<string, H, "object" | "workflow">, key: string): IngressHandlerClient<H>;
|
|
1018
|
+
declare function sendClient$1<H extends Record<string, HandlerDescriptor>>(ingress: GenIngress, def: Descriptor<string, H, "service">): IngressSendHandlerClient<H>;
|
|
1019
|
+
declare function sendClient$1<H extends Record<string, HandlerDescriptor>>(ingress: GenIngress, def: Descriptor<string, H, "object" | "workflow">, key: string): IngressSendHandlerClient<H>;
|
|
1020
|
+
//#endregion
|
|
1021
|
+
export { type AnyGenFn, type Channel, type ClientFuture, type ContextDate, type Descriptor, type Duration, type EntryToDescriptor, type Future, type FutureFulfilledResult, type FutureRejectedResult, type FutureSettledResult, type FutureValue, type FutureValues, type GenClient, type GenContextDate, type GenDurablePromise, type GenHandlerOpts, type GenObjectHandlerOpts, type GenSendClient, type GenWorkflowHandlerOpts, type HandlerDef, type HandlerDescriptor, type HandlerDescriptors, type HandlerOrHandlerDescriptor, type HandlerRequest, type ImplementHandlers, type ImplementedDefinition, type ImplementedObjectDefinition, type ImplementedServiceDefinition, type ImplementedWorkflowDefinition, type InferInput, type InferOutput, type InvocationReference, type ObjectDescriptor, type Operation, type Rand, type RetryOptions, type RunAction, type RunActionOpts, type RunOpts, type SelectResult, type Serde, type Service, type ServiceDefinition, type ServiceDefinitionFrom, type ServiceDescriptor, type SharedState, type SignalReference, type StandardSchemaV1, type StandardTypedV1, type State, type TypedState, type UntypedState, type VirtualObject, type VirtualObjectDefinition, type VirtualObjectDefinitionFrom, type Workflow, type WorkflowDefinition, type WorkflowDefinitionFrom, type WorkflowDescriptor, all, allSettled, any, attach, awakeable, call, cancel, channel, client, ingress_d_exports as clients, date, gen, handlerRequest, interface_d_exports as iface, implement, invocation, logger, object, race, rand, rejectAwakeable, resolveAwakeable, run, schemas, select, send, sendClient, serde, serdes, service, sharedState, signal, sleep, spawn, state, workflow, workflowPromise, wrapActionForCancellation };
|
|
1022
|
+
//# sourceMappingURL=index.d.cts.map
|