@restatedev/restate-sdk-gen 0.0.0 → 1.14.2
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/index.cjs +1129 -0
- package/dist/index.d.cts +269 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +269 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1078 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -3
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import * as restate from "@restatedev/restate-sdk";
|
|
2
|
+
|
|
3
|
+
//#region src/operation.d.ts
|
|
4
|
+
interface Operation<T> {
|
|
5
|
+
[Symbol.iterator](): Iterator<unknown, T, unknown>;
|
|
6
|
+
}
|
|
7
|
+
declare function gen<T>(body: () => Generator<unknown, T, unknown>): Operation<T>;
|
|
8
|
+
declare function spawn<T>(op: Operation<T>): Operation<Future<T>>;
|
|
9
|
+
type SelectResult<B extends Record<string, Future<unknown>>> = { [K in keyof B]: {
|
|
10
|
+
tag: K;
|
|
11
|
+
future: B[K];
|
|
12
|
+
} }[keyof B];
|
|
13
|
+
declare function select<B extends Record<string, Future<unknown>>>(branches: B): Generator<unknown, SelectResult<B>, unknown>;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/future.d.ts
|
|
16
|
+
interface Future<T> extends Operation<T> {}
|
|
17
|
+
/** Extract the value type from a `Future<U>`; `never` for non-Futures. */
|
|
18
|
+
type FutureValue<F> = F extends Future<infer U> ? U : never;
|
|
19
|
+
/**
|
|
20
|
+
* Map a tuple of Futures to the tuple of their value types.
|
|
21
|
+
* For `[Future<A>, Future<B>]` produces `[A, B]`.
|
|
22
|
+
* For an unbounded `Future<X>[]` produces `X[]`.
|
|
23
|
+
*/
|
|
24
|
+
type FutureValues<T extends readonly Future<unknown>[] | []> = { -readonly [P in keyof T]: T[P] extends Future<infer U> ? U : never };
|
|
25
|
+
interface FutureFulfilledResult<T> {
|
|
26
|
+
readonly status: "fulfilled";
|
|
27
|
+
readonly value: T;
|
|
28
|
+
}
|
|
29
|
+
interface FutureRejectedResult {
|
|
30
|
+
readonly status: "rejected";
|
|
31
|
+
readonly reason: unknown;
|
|
32
|
+
}
|
|
33
|
+
type FutureSettledResult<T> = FutureFulfilledResult<T> | FutureRejectedResult;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/channel.d.ts
|
|
36
|
+
interface Channel<T> {
|
|
37
|
+
/**
|
|
38
|
+
* Yieldable. Use as `yield* ch.send(value)` from within a gen body.
|
|
39
|
+
* The first call settles the channel; subsequent calls are silently
|
|
40
|
+
* dropped (idempotent).
|
|
41
|
+
*
|
|
42
|
+
* Return value is `Operation<void>` rather than `void` so the only
|
|
43
|
+
* way to fire send is via `yield*` inside a fiber — which enforces
|
|
44
|
+
* the channel-is-intra-workflow contract at the type level.
|
|
45
|
+
*/
|
|
46
|
+
send(value: T): Operation<void>;
|
|
47
|
+
readonly receive: Future<T>;
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/clients.d.ts
|
|
51
|
+
/**
|
|
52
|
+
* Same shape as the SDK's `Client<M>` but each handler returns
|
|
53
|
+
* `Future<O>` instead of `InvocationPromise<O>`. The mapped type
|
|
54
|
+
* preserves the original argument list (including the trailing
|
|
55
|
+
* `opts?: Opts<...>` parameter from the SDK).
|
|
56
|
+
*/
|
|
57
|
+
type FluentClient<C> = { [K in keyof C]: C[K] extends ((...args: infer A) => restate.InvocationPromise<infer R>) ? (...args: A) => Future<R> : C[K] };
|
|
58
|
+
/**
|
|
59
|
+
* Same shape as the SDK's `DurablePromise<T>` but each method returns
|
|
60
|
+
* `Future<...>` instead of `Promise<...>`/`RestatePromise<...>`.
|
|
61
|
+
*
|
|
62
|
+
* Workflow promises are durable; reads are journaled (so `peek`/`get`
|
|
63
|
+
* are journal-backed Futures), and writes (`resolve`/`reject`) record
|
|
64
|
+
* a journal entry that the user yields on.
|
|
65
|
+
*/
|
|
66
|
+
type FluentDurablePromise<T> = {
|
|
67
|
+
peek(): Future<T | undefined>;
|
|
68
|
+
resolve(value?: T): Future<void>;
|
|
69
|
+
reject(errorMsg: string): Future<void>;
|
|
70
|
+
get(): Future<T>;
|
|
71
|
+
};
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/state.d.ts
|
|
74
|
+
/**
|
|
75
|
+
* Marker types matching the SDK's typed-state convention. Pass a
|
|
76
|
+
* concrete shape (e.g. `{count: number; name: string}`) to enable
|
|
77
|
+
* keyof-checked names; leave the default to keep names as `string`
|
|
78
|
+
* with a per-call value generic.
|
|
79
|
+
*/
|
|
80
|
+
type TypedState = Record<string, unknown>;
|
|
81
|
+
type UntypedState = {
|
|
82
|
+
_: never;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Read-only state, for handlers running under an
|
|
86
|
+
* ObjectSharedContext or WorkflowSharedContext.
|
|
87
|
+
*/
|
|
88
|
+
interface SharedState<TState extends TypedState = UntypedState> {
|
|
89
|
+
/** Read a state value. Returns null if the key isn't set. */
|
|
90
|
+
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>;
|
|
91
|
+
/** List all currently-known state keys. */
|
|
92
|
+
keys(): Future<string[]>;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Read-write state, for handlers running under an ObjectContext or
|
|
96
|
+
* WorkflowContext. Extends SharedState with mutation methods.
|
|
97
|
+
*
|
|
98
|
+
* Writes are synchronous in the SDK — the journal entry is recorded
|
|
99
|
+
* immediately, no yield required — so `set` / `clear` / `clearAll`
|
|
100
|
+
* return `void` rather than `Operation<void>`.
|
|
101
|
+
*/
|
|
102
|
+
interface State<TState extends TypedState = UntypedState> extends SharedState<TState> {
|
|
103
|
+
/** Write a state value. Sync; journal entry recorded immediately. */
|
|
104
|
+
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;
|
|
105
|
+
/** Clear a single key. */
|
|
106
|
+
clear<TKey extends keyof TState>(name: TState extends UntypedState ? string : TKey): void;
|
|
107
|
+
/** Clear all state for this invocation. */
|
|
108
|
+
clearAll(): void;
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/restate-operations.d.ts
|
|
112
|
+
/**
|
|
113
|
+
* Retry policy for `run`. Mirrors the SDK's `RunOptions` retry knobs
|
|
114
|
+
* but namespaced (no `Retry` prefix on each field) and grouped under
|
|
115
|
+
* `RunOpts.retry` for readability.
|
|
116
|
+
*/
|
|
117
|
+
type RetryOptions = {
|
|
118
|
+
/**
|
|
119
|
+
* Max attempts (including the initial). When reached, `run` throws
|
|
120
|
+
* a `TerminalError` wrapping the original error message.
|
|
121
|
+
*/
|
|
122
|
+
maxAttempts?: number;
|
|
123
|
+
/**
|
|
124
|
+
* Max total duration of retries before giving up. Number is ms.
|
|
125
|
+
*/
|
|
126
|
+
maxDuration?: restate.Duration | number;
|
|
127
|
+
/**
|
|
128
|
+
* First retry delay. Subsequent delays grow by `intervalFactor`.
|
|
129
|
+
* Number is ms. Defaults to 50 ms.
|
|
130
|
+
*/
|
|
131
|
+
initialInterval?: restate.Duration | number;
|
|
132
|
+
/**
|
|
133
|
+
* Cap on retry delay. Number is ms. Defaults to 10 s.
|
|
134
|
+
*/
|
|
135
|
+
maxInterval?: restate.Duration | number;
|
|
136
|
+
/**
|
|
137
|
+
* Multiplier applied to the previous delay. Defaults to 2.
|
|
138
|
+
*/
|
|
139
|
+
intervalFactor?: number;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Options for `run`. Both fields are optional; if `name` is omitted,
|
|
143
|
+
* the action's `Function.name` is used (works for named functions and
|
|
144
|
+
* for arrow functions assigned to a `const` since JS infers names from
|
|
145
|
+
* the binding site). If neither resolves, `run` throws.
|
|
146
|
+
*/
|
|
147
|
+
type RunOpts<T> = {
|
|
148
|
+
/** Journal entry name. Falls back to `action.name` if absent. */
|
|
149
|
+
name?: string;
|
|
150
|
+
/** Retry policy. Defaults to the SDK's defaults if absent. */
|
|
151
|
+
retry?: RetryOptions;
|
|
152
|
+
/** Custom serde for the journaled value. */
|
|
153
|
+
serde?: restate.Serde<T>;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Options object passed to the closure of `run(...)`. Carries an
|
|
157
|
+
* AbortSignal that fires when invocation cancellation arrives.
|
|
158
|
+
*
|
|
159
|
+
* Using an object (rather than positional args) leaves room to extend
|
|
160
|
+
* the closure's API surface — additional fields may be added later
|
|
161
|
+
* without breaking existing closures.
|
|
162
|
+
*/
|
|
163
|
+
type RunActionOpts = {
|
|
164
|
+
readonly signal: AbortSignal;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* The closure that `run` invokes. Receives `{ signal }` — pass the
|
|
168
|
+
* signal into AbortSignal-aware APIs (e.g. `fetch(url, { signal })`)
|
|
169
|
+
* to cancel in-flight syscalls promptly.
|
|
170
|
+
*/
|
|
171
|
+
type RunAction<T> = (opts: RunActionOpts) => Promise<T>;
|
|
172
|
+
/**
|
|
173
|
+
* Wrap a user-supplied `run` closure to surface the abort reason
|
|
174
|
+
* (typically a TerminalError(CANCELLED)) on throw paths if the signal
|
|
175
|
+
* aborted during execution. This converts AbortError (and any other
|
|
176
|
+
* abort-caused failure) into the canonical cancellation TerminalError
|
|
177
|
+
* for journal recording.
|
|
178
|
+
*
|
|
179
|
+
* Defensive coercion: if `signal.reason` is itself not a TerminalError
|
|
180
|
+
* (which shouldn't happen in production but might during testing or
|
|
181
|
+
* with non-cancellation race rejections), we wrap it in one. The
|
|
182
|
+
* journal must record a *terminal* outcome to avoid retries against
|
|
183
|
+
* a cancelled invocation.
|
|
184
|
+
*
|
|
185
|
+
* Exposed for testing — the wrapper's behavior is the part that has
|
|
186
|
+
* semantic bite, separate from the ctx.run plumbing.
|
|
187
|
+
*/
|
|
188
|
+
declare function wrapActionForCancellation<T>(signal: AbortSignal, action: RunAction<T>): () => Promise<T>;
|
|
189
|
+
/**
|
|
190
|
+
* Run a generator-based workflow against a Restate context.
|
|
191
|
+
*
|
|
192
|
+
* `op` is an `Operation<T>` — typically the result of
|
|
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
|
+
* }));
|
|
207
|
+
*/
|
|
208
|
+
declare function execute<T>(context: restate.Context, op: Operation<T>): Promise<T>;
|
|
209
|
+
//#endregion
|
|
210
|
+
//#region src/free.d.ts
|
|
211
|
+
/**
|
|
212
|
+
* Run a side-effecting closure as a journal entry. See
|
|
213
|
+
* `RestateOperations.run` for full semantics.
|
|
214
|
+
*
|
|
215
|
+
* `name` is derived from `action.name` (works for named functions and
|
|
216
|
+
* arrow functions assigned to a `const`) or specified explicitly via
|
|
217
|
+
* `opts.name`. If neither resolves, throws.
|
|
218
|
+
*/
|
|
219
|
+
declare const run: <T>(action: RunAction<T>, opts?: RunOpts<T>) => Future<T>;
|
|
220
|
+
declare const sleep: (duration: restate.Duration | number, name?: string) => Future<void>;
|
|
221
|
+
declare const awakeable: <T>(serde?: restate.Serde<T>) => {
|
|
222
|
+
id: string;
|
|
223
|
+
promise: Future<T>;
|
|
224
|
+
};
|
|
225
|
+
declare const resolveAwakeable: <T>(id: string, payload?: T, serde?: restate.Serde<T>) => void;
|
|
226
|
+
declare const rejectAwakeable: (id: string, reason: string | restate.TerminalError) => void;
|
|
227
|
+
declare const signal: <T>(name: string, serde?: restate.Serde<T>) => Future<T>;
|
|
228
|
+
declare const attach: <T>(invocationId: restate.InvocationId, serde?: restate.Serde<T>) => Future<T>;
|
|
229
|
+
declare const serviceClient: <D>(api: restate.ServiceDefinitionFrom<D>) => FluentClient<restate.Client<restate.Service<D>>>;
|
|
230
|
+
declare const objectClient: <D>(api: restate.VirtualObjectDefinitionFrom<D>, key: string) => FluentClient<restate.Client<restate.VirtualObject<D>>>;
|
|
231
|
+
declare const workflowClient: <D>(api: restate.WorkflowDefinitionFrom<D>, key: string) => FluentClient<restate.Client<restate.Workflow<D>>>;
|
|
232
|
+
declare const serviceSendClient: <D>(api: restate.ServiceDefinitionFrom<D>) => restate.SendClient<restate.Service<D>>;
|
|
233
|
+
declare const objectSendClient: <D>(api: restate.VirtualObjectDefinitionFrom<D>, key: string) => restate.SendClient<restate.VirtualObject<D>>;
|
|
234
|
+
declare const workflowSendClient: <D>(api: restate.WorkflowDefinitionFrom<D>, key: string) => restate.SendClient<restate.Workflow<D>>;
|
|
235
|
+
declare const genericCall: <REQ = Uint8Array, RES = Uint8Array>(call: restate.GenericCall<REQ, RES>) => Future<RES>;
|
|
236
|
+
declare const genericSend: <REQ = Uint8Array>(call: restate.GenericSend<REQ>) => restate.InvocationHandle;
|
|
237
|
+
declare const cancel: (invocationId: restate.InvocationId) => void;
|
|
238
|
+
declare const channel: <T>() => Channel<T>;
|
|
239
|
+
declare const state: <TState extends TypedState = UntypedState>() => State<TState>;
|
|
240
|
+
declare const sharedState: <TState extends TypedState = UntypedState>() => SharedState<TState>;
|
|
241
|
+
declare const workflowPromise: <T>(name: string, serde?: restate.Serde<T>) => FluentDurablePromise<T>;
|
|
242
|
+
/**
|
|
243
|
+
* Wait for every future to settle; return their values in input order.
|
|
244
|
+
* Heterogeneous-tuple typing — `all([fA, fB])` where `fA: Future<A>`
|
|
245
|
+
* and `fB: Future<B>` yields `Future<[A, B]>`. Mirrors `Promise.all`.
|
|
246
|
+
*/
|
|
247
|
+
declare const all: <const T extends readonly Future<unknown>[] | []>(futures: T) => Future<FutureValues<T>>;
|
|
248
|
+
/**
|
|
249
|
+
* Return the first future to settle; losers continue running but their
|
|
250
|
+
* results are discarded. Heterogeneous-tuple typing — `race([fA, fB])`
|
|
251
|
+
* yields `Future<A | B>`. Mirrors `Promise.race`.
|
|
252
|
+
*/
|
|
253
|
+
declare const race: <const T extends readonly Future<unknown>[] | []>(futures: T) => Future<FutureValues<T>[number]>;
|
|
254
|
+
/**
|
|
255
|
+
* First-to-succeed wins (non-rejected). Rejects with `AggregateError(errors)`
|
|
256
|
+
* when every input rejects (including the empty input case). Tuple-aware —
|
|
257
|
+
* `any([fA, fB])` yields `Future<A | B>`. Mirrors `Promise.any`.
|
|
258
|
+
*/
|
|
259
|
+
declare const any: <const T extends readonly Future<unknown>[] | []>(futures: T) => Future<FutureValues<T>[number]>;
|
|
260
|
+
/**
|
|
261
|
+
* Wait for every future to settle; never rejects. Tuple-aware —
|
|
262
|
+
* `allSettled([fA, fB])` yields
|
|
263
|
+
* `Future<[FutureSettledResult<A>, FutureSettledResult<B>]>`.
|
|
264
|
+
* Mirrors `Promise.allSettled`.
|
|
265
|
+
*/
|
|
266
|
+
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> }>;
|
|
267
|
+
//#endregion
|
|
268
|
+
export { type Channel, type FluentClient, type FluentDurablePromise, type Future, type FutureFulfilledResult, type FutureRejectedResult, type FutureSettledResult, type FutureValue, type FutureValues, type Operation, type RetryOptions, type RunAction, type RunActionOpts, type RunOpts, type SelectResult, type SharedState, type State, type TypedState, type UntypedState, all, allSettled, any, attach, awakeable, cancel, channel, execute, gen, genericCall, genericSend, objectClient, objectSendClient, race, rejectAwakeable, resolveAwakeable, run, select, serviceClient, serviceSendClient, sharedState, signal, sleep, spawn, state, workflowClient, workflowPromise, workflowSendClient, wrapActionForCancellation };
|
|
269
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/operation.ts","../src/future.ts","../src/channel.ts","../src/clients.ts","../src/state.ts","../src/restate-operations.ts","../src/free.ts"],"sourcesContent":[],"mappings":";;;AA4BiB,UAAA,SAAS,CAAA,CAAA,CACe,CAAA;EA0DzB,CAAA,MAAG,CAAA,QAAA,GAAA,EA1DI,QA0DJ,CAAA,OAAA,EA1DsB,CA0DtB,EAAA,OAAA,CAAA;;AAkCe,iBAlClB,GAkCkB,CAAA,CAAA,CAAA,CAAA,IAAA,EAAA,GAAA,GAjCpB,SAiCoB,CAAA,OAAA,EAjCD,CAiCC,EAAA,OAAA,CAAA,CAAA,EAhC/B,SAgC+B,CAhCrB,CAgCqB,CAAA;AACtB,iBAtBI,KAsBJ,CAAA,CAAA,CAAA,CAAA,EAAA,EAtBiB,SAsBjB,CAtB2B,CAsB3B,CAAA,CAAA,EAtBgC,SAsBhC,CAtB0C,MAsB1C,CAtBiD,CAsBjD,CAAA,CAAA;AACuB,KANvB,YAMuB,CAAA,UANA,MAMA,CAAA,MAAA,EANe,MAMf,CAAA,OAAA,CAAA,CAAA,CAAA,GAAA,QAAb,MALR,CAKQ,GAAA;EAAnB,GAAA,EALsB,CAKtB;EAAS,MAAA,EALwB,CAKxB,CAL0B,CAK1B,CAAA;UAJJ;iBAES,iBAAiB,eAAe,4BACrC,IACT,mBAAmB,aAAa;;;AAAb,UCtCL,MDsCK,CAAA,CAAA,CAAA,SCtCa,SDsCb,CCtCuB,CDsCvB,CAAA,CAAA;ACsDtB;AAC0B,KA5Bd,WA4Bc,CAAA,CAAA,CAAA,GA5BG,C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
+
import * as restate from "@restatedev/restate-sdk";
|
|
2
|
+
|
|
3
|
+
//#region src/operation.d.ts
|
|
4
|
+
interface Operation<T> {
|
|
5
|
+
[Symbol.iterator](): Iterator<unknown, T, unknown>;
|
|
6
|
+
}
|
|
7
|
+
declare function gen<T>(body: () => Generator<unknown, T, unknown>): Operation<T>;
|
|
8
|
+
declare function spawn<T>(op: Operation<T>): Operation<Future<T>>;
|
|
9
|
+
type SelectResult<B extends Record<string, Future<unknown>>> = { [K in keyof B]: {
|
|
10
|
+
tag: K;
|
|
11
|
+
future: B[K];
|
|
12
|
+
} }[keyof B];
|
|
13
|
+
declare function select<B extends Record<string, Future<unknown>>>(branches: B): Generator<unknown, SelectResult<B>, unknown>;
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/future.d.ts
|
|
16
|
+
interface Future<T> extends Operation<T> {}
|
|
17
|
+
/** Extract the value type from a `Future<U>`; `never` for non-Futures. */
|
|
18
|
+
type FutureValue<F> = F extends Future<infer U> ? U : never;
|
|
19
|
+
/**
|
|
20
|
+
* Map a tuple of Futures to the tuple of their value types.
|
|
21
|
+
* For `[Future<A>, Future<B>]` produces `[A, B]`.
|
|
22
|
+
* For an unbounded `Future<X>[]` produces `X[]`.
|
|
23
|
+
*/
|
|
24
|
+
type FutureValues<T extends readonly Future<unknown>[] | []> = { -readonly [P in keyof T]: T[P] extends Future<infer U> ? U : never };
|
|
25
|
+
interface FutureFulfilledResult<T> {
|
|
26
|
+
readonly status: "fulfilled";
|
|
27
|
+
readonly value: T;
|
|
28
|
+
}
|
|
29
|
+
interface FutureRejectedResult {
|
|
30
|
+
readonly status: "rejected";
|
|
31
|
+
readonly reason: unknown;
|
|
32
|
+
}
|
|
33
|
+
type FutureSettledResult<T> = FutureFulfilledResult<T> | FutureRejectedResult;
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/channel.d.ts
|
|
36
|
+
interface Channel<T> {
|
|
37
|
+
/**
|
|
38
|
+
* Yieldable. Use as `yield* ch.send(value)` from within a gen body.
|
|
39
|
+
* The first call settles the channel; subsequent calls are silently
|
|
40
|
+
* dropped (idempotent).
|
|
41
|
+
*
|
|
42
|
+
* Return value is `Operation<void>` rather than `void` so the only
|
|
43
|
+
* way to fire send is via `yield*` inside a fiber — which enforces
|
|
44
|
+
* the channel-is-intra-workflow contract at the type level.
|
|
45
|
+
*/
|
|
46
|
+
send(value: T): Operation<void>;
|
|
47
|
+
readonly receive: Future<T>;
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/clients.d.ts
|
|
51
|
+
/**
|
|
52
|
+
* Same shape as the SDK's `Client<M>` but each handler returns
|
|
53
|
+
* `Future<O>` instead of `InvocationPromise<O>`. The mapped type
|
|
54
|
+
* preserves the original argument list (including the trailing
|
|
55
|
+
* `opts?: Opts<...>` parameter from the SDK).
|
|
56
|
+
*/
|
|
57
|
+
type FluentClient<C> = { [K in keyof C]: C[K] extends ((...args: infer A) => restate.InvocationPromise<infer R>) ? (...args: A) => Future<R> : C[K] };
|
|
58
|
+
/**
|
|
59
|
+
* Same shape as the SDK's `DurablePromise<T>` but each method returns
|
|
60
|
+
* `Future<...>` instead of `Promise<...>`/`RestatePromise<...>`.
|
|
61
|
+
*
|
|
62
|
+
* Workflow promises are durable; reads are journaled (so `peek`/`get`
|
|
63
|
+
* are journal-backed Futures), and writes (`resolve`/`reject`) record
|
|
64
|
+
* a journal entry that the user yields on.
|
|
65
|
+
*/
|
|
66
|
+
type FluentDurablePromise<T> = {
|
|
67
|
+
peek(): Future<T | undefined>;
|
|
68
|
+
resolve(value?: T): Future<void>;
|
|
69
|
+
reject(errorMsg: string): Future<void>;
|
|
70
|
+
get(): Future<T>;
|
|
71
|
+
};
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/state.d.ts
|
|
74
|
+
/**
|
|
75
|
+
* Marker types matching the SDK's typed-state convention. Pass a
|
|
76
|
+
* concrete shape (e.g. `{count: number; name: string}`) to enable
|
|
77
|
+
* keyof-checked names; leave the default to keep names as `string`
|
|
78
|
+
* with a per-call value generic.
|
|
79
|
+
*/
|
|
80
|
+
type TypedState = Record<string, unknown>;
|
|
81
|
+
type UntypedState = {
|
|
82
|
+
_: never;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Read-only state, for handlers running under an
|
|
86
|
+
* ObjectSharedContext or WorkflowSharedContext.
|
|
87
|
+
*/
|
|
88
|
+
interface SharedState<TState extends TypedState = UntypedState> {
|
|
89
|
+
/** Read a state value. Returns null if the key isn't set. */
|
|
90
|
+
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>;
|
|
91
|
+
/** List all currently-known state keys. */
|
|
92
|
+
keys(): Future<string[]>;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Read-write state, for handlers running under an ObjectContext or
|
|
96
|
+
* WorkflowContext. Extends SharedState with mutation methods.
|
|
97
|
+
*
|
|
98
|
+
* Writes are synchronous in the SDK — the journal entry is recorded
|
|
99
|
+
* immediately, no yield required — so `set` / `clear` / `clearAll`
|
|
100
|
+
* return `void` rather than `Operation<void>`.
|
|
101
|
+
*/
|
|
102
|
+
interface State<TState extends TypedState = UntypedState> extends SharedState<TState> {
|
|
103
|
+
/** Write a state value. Sync; journal entry recorded immediately. */
|
|
104
|
+
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;
|
|
105
|
+
/** Clear a single key. */
|
|
106
|
+
clear<TKey extends keyof TState>(name: TState extends UntypedState ? string : TKey): void;
|
|
107
|
+
/** Clear all state for this invocation. */
|
|
108
|
+
clearAll(): void;
|
|
109
|
+
}
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/restate-operations.d.ts
|
|
112
|
+
/**
|
|
113
|
+
* Retry policy for `run`. Mirrors the SDK's `RunOptions` retry knobs
|
|
114
|
+
* but namespaced (no `Retry` prefix on each field) and grouped under
|
|
115
|
+
* `RunOpts.retry` for readability.
|
|
116
|
+
*/
|
|
117
|
+
type RetryOptions = {
|
|
118
|
+
/**
|
|
119
|
+
* Max attempts (including the initial). When reached, `run` throws
|
|
120
|
+
* a `TerminalError` wrapping the original error message.
|
|
121
|
+
*/
|
|
122
|
+
maxAttempts?: number;
|
|
123
|
+
/**
|
|
124
|
+
* Max total duration of retries before giving up. Number is ms.
|
|
125
|
+
*/
|
|
126
|
+
maxDuration?: restate.Duration | number;
|
|
127
|
+
/**
|
|
128
|
+
* First retry delay. Subsequent delays grow by `intervalFactor`.
|
|
129
|
+
* Number is ms. Defaults to 50 ms.
|
|
130
|
+
*/
|
|
131
|
+
initialInterval?: restate.Duration | number;
|
|
132
|
+
/**
|
|
133
|
+
* Cap on retry delay. Number is ms. Defaults to 10 s.
|
|
134
|
+
*/
|
|
135
|
+
maxInterval?: restate.Duration | number;
|
|
136
|
+
/**
|
|
137
|
+
* Multiplier applied to the previous delay. Defaults to 2.
|
|
138
|
+
*/
|
|
139
|
+
intervalFactor?: number;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Options for `run`. Both fields are optional; if `name` is omitted,
|
|
143
|
+
* the action's `Function.name` is used (works for named functions and
|
|
144
|
+
* for arrow functions assigned to a `const` since JS infers names from
|
|
145
|
+
* the binding site). If neither resolves, `run` throws.
|
|
146
|
+
*/
|
|
147
|
+
type RunOpts<T> = {
|
|
148
|
+
/** Journal entry name. Falls back to `action.name` if absent. */
|
|
149
|
+
name?: string;
|
|
150
|
+
/** Retry policy. Defaults to the SDK's defaults if absent. */
|
|
151
|
+
retry?: RetryOptions;
|
|
152
|
+
/** Custom serde for the journaled value. */
|
|
153
|
+
serde?: restate.Serde<T>;
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* Options object passed to the closure of `run(...)`. Carries an
|
|
157
|
+
* AbortSignal that fires when invocation cancellation arrives.
|
|
158
|
+
*
|
|
159
|
+
* Using an object (rather than positional args) leaves room to extend
|
|
160
|
+
* the closure's API surface — additional fields may be added later
|
|
161
|
+
* without breaking existing closures.
|
|
162
|
+
*/
|
|
163
|
+
type RunActionOpts = {
|
|
164
|
+
readonly signal: AbortSignal;
|
|
165
|
+
};
|
|
166
|
+
/**
|
|
167
|
+
* The closure that `run` invokes. Receives `{ signal }` — pass the
|
|
168
|
+
* signal into AbortSignal-aware APIs (e.g. `fetch(url, { signal })`)
|
|
169
|
+
* to cancel in-flight syscalls promptly.
|
|
170
|
+
*/
|
|
171
|
+
type RunAction<T> = (opts: RunActionOpts) => Promise<T>;
|
|
172
|
+
/**
|
|
173
|
+
* Wrap a user-supplied `run` closure to surface the abort reason
|
|
174
|
+
* (typically a TerminalError(CANCELLED)) on throw paths if the signal
|
|
175
|
+
* aborted during execution. This converts AbortError (and any other
|
|
176
|
+
* abort-caused failure) into the canonical cancellation TerminalError
|
|
177
|
+
* for journal recording.
|
|
178
|
+
*
|
|
179
|
+
* Defensive coercion: if `signal.reason` is itself not a TerminalError
|
|
180
|
+
* (which shouldn't happen in production but might during testing or
|
|
181
|
+
* with non-cancellation race rejections), we wrap it in one. The
|
|
182
|
+
* journal must record a *terminal* outcome to avoid retries against
|
|
183
|
+
* a cancelled invocation.
|
|
184
|
+
*
|
|
185
|
+
* Exposed for testing — the wrapper's behavior is the part that has
|
|
186
|
+
* semantic bite, separate from the ctx.run plumbing.
|
|
187
|
+
*/
|
|
188
|
+
declare function wrapActionForCancellation<T>(signal: AbortSignal, action: RunAction<T>): () => Promise<T>;
|
|
189
|
+
/**
|
|
190
|
+
* Run a generator-based workflow against a Restate context.
|
|
191
|
+
*
|
|
192
|
+
* `op` is an `Operation<T>` — typically the result of
|
|
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
|
+
* }));
|
|
207
|
+
*/
|
|
208
|
+
declare function execute<T>(context: restate.Context, op: Operation<T>): Promise<T>;
|
|
209
|
+
//#endregion
|
|
210
|
+
//#region src/free.d.ts
|
|
211
|
+
/**
|
|
212
|
+
* Run a side-effecting closure as a journal entry. See
|
|
213
|
+
* `RestateOperations.run` for full semantics.
|
|
214
|
+
*
|
|
215
|
+
* `name` is derived from `action.name` (works for named functions and
|
|
216
|
+
* arrow functions assigned to a `const`) or specified explicitly via
|
|
217
|
+
* `opts.name`. If neither resolves, throws.
|
|
218
|
+
*/
|
|
219
|
+
declare const run: <T>(action: RunAction<T>, opts?: RunOpts<T>) => Future<T>;
|
|
220
|
+
declare const sleep: (duration: restate.Duration | number, name?: string) => Future<void>;
|
|
221
|
+
declare const awakeable: <T>(serde?: restate.Serde<T>) => {
|
|
222
|
+
id: string;
|
|
223
|
+
promise: Future<T>;
|
|
224
|
+
};
|
|
225
|
+
declare const resolveAwakeable: <T>(id: string, payload?: T, serde?: restate.Serde<T>) => void;
|
|
226
|
+
declare const rejectAwakeable: (id: string, reason: string | restate.TerminalError) => void;
|
|
227
|
+
declare const signal: <T>(name: string, serde?: restate.Serde<T>) => Future<T>;
|
|
228
|
+
declare const attach: <T>(invocationId: restate.InvocationId, serde?: restate.Serde<T>) => Future<T>;
|
|
229
|
+
declare const serviceClient: <D>(api: restate.ServiceDefinitionFrom<D>) => FluentClient<restate.Client<restate.Service<D>>>;
|
|
230
|
+
declare const objectClient: <D>(api: restate.VirtualObjectDefinitionFrom<D>, key: string) => FluentClient<restate.Client<restate.VirtualObject<D>>>;
|
|
231
|
+
declare const workflowClient: <D>(api: restate.WorkflowDefinitionFrom<D>, key: string) => FluentClient<restate.Client<restate.Workflow<D>>>;
|
|
232
|
+
declare const serviceSendClient: <D>(api: restate.ServiceDefinitionFrom<D>) => restate.SendClient<restate.Service<D>>;
|
|
233
|
+
declare const objectSendClient: <D>(api: restate.VirtualObjectDefinitionFrom<D>, key: string) => restate.SendClient<restate.VirtualObject<D>>;
|
|
234
|
+
declare const workflowSendClient: <D>(api: restate.WorkflowDefinitionFrom<D>, key: string) => restate.SendClient<restate.Workflow<D>>;
|
|
235
|
+
declare const genericCall: <REQ = Uint8Array, RES = Uint8Array>(call: restate.GenericCall<REQ, RES>) => Future<RES>;
|
|
236
|
+
declare const genericSend: <REQ = Uint8Array>(call: restate.GenericSend<REQ>) => restate.InvocationHandle;
|
|
237
|
+
declare const cancel: (invocationId: restate.InvocationId) => void;
|
|
238
|
+
declare const channel: <T>() => Channel<T>;
|
|
239
|
+
declare const state: <TState extends TypedState = UntypedState>() => State<TState>;
|
|
240
|
+
declare const sharedState: <TState extends TypedState = UntypedState>() => SharedState<TState>;
|
|
241
|
+
declare const workflowPromise: <T>(name: string, serde?: restate.Serde<T>) => FluentDurablePromise<T>;
|
|
242
|
+
/**
|
|
243
|
+
* Wait for every future to settle; return their values in input order.
|
|
244
|
+
* Heterogeneous-tuple typing — `all([fA, fB])` where `fA: Future<A>`
|
|
245
|
+
* and `fB: Future<B>` yields `Future<[A, B]>`. Mirrors `Promise.all`.
|
|
246
|
+
*/
|
|
247
|
+
declare const all: <const T extends readonly Future<unknown>[] | []>(futures: T) => Future<FutureValues<T>>;
|
|
248
|
+
/**
|
|
249
|
+
* Return the first future to settle; losers continue running but their
|
|
250
|
+
* results are discarded. Heterogeneous-tuple typing — `race([fA, fB])`
|
|
251
|
+
* yields `Future<A | B>`. Mirrors `Promise.race`.
|
|
252
|
+
*/
|
|
253
|
+
declare const race: <const T extends readonly Future<unknown>[] | []>(futures: T) => Future<FutureValues<T>[number]>;
|
|
254
|
+
/**
|
|
255
|
+
* First-to-succeed wins (non-rejected). Rejects with `AggregateError(errors)`
|
|
256
|
+
* when every input rejects (including the empty input case). Tuple-aware —
|
|
257
|
+
* `any([fA, fB])` yields `Future<A | B>`. Mirrors `Promise.any`.
|
|
258
|
+
*/
|
|
259
|
+
declare const any: <const T extends readonly Future<unknown>[] | []>(futures: T) => Future<FutureValues<T>[number]>;
|
|
260
|
+
/**
|
|
261
|
+
* Wait for every future to settle; never rejects. Tuple-aware —
|
|
262
|
+
* `allSettled([fA, fB])` yields
|
|
263
|
+
* `Future<[FutureSettledResult<A>, FutureSettledResult<B>]>`.
|
|
264
|
+
* Mirrors `Promise.allSettled`.
|
|
265
|
+
*/
|
|
266
|
+
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> }>;
|
|
267
|
+
//#endregion
|
|
268
|
+
export { type Channel, type FluentClient, type FluentDurablePromise, type Future, type FutureFulfilledResult, type FutureRejectedResult, type FutureSettledResult, type FutureValue, type FutureValues, type Operation, type RetryOptions, type RunAction, type RunActionOpts, type RunOpts, type SelectResult, type SharedState, type State, type TypedState, type UntypedState, all, allSettled, any, attach, awakeable, cancel, channel, execute, gen, genericCall, genericSend, objectClient, objectSendClient, race, rejectAwakeable, resolveAwakeable, run, select, serviceClient, serviceSendClient, sharedState, signal, sleep, spawn, state, workflowClient, workflowPromise, workflowSendClient, wrapActionForCancellation };
|
|
269
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/operation.ts","../src/future.ts","../src/channel.ts","../src/clients.ts","../src/state.ts","../src/restate-operations.ts","../src/free.ts"],"sourcesContent":[],"mappings":";;;AA4BiB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