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