@restatedev/restate-sdk-cloudflare-workers 1.9.1 → 1.10.1
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/dist/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/common_api.cjs +25 -0
- package/dist/common_api.d.cts +30 -0
- package/dist/common_api.d.cts.map +1 -0
- package/dist/common_api.d.ts +30 -0
- package/dist/common_api.d.ts.map +1 -0
- package/dist/common_api.js +19 -0
- package/dist/common_api.js.map +1 -0
- package/dist/context.cjs +29 -0
- package/dist/context.d.cts +699 -0
- package/dist/context.d.cts.map +1 -0
- package/dist/context.d.ts +699 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +29 -0
- package/dist/context.js.map +1 -0
- package/dist/context_impl.cjs +441 -0
- package/dist/context_impl.js +440 -0
- package/dist/context_impl.js.map +1 -0
- package/dist/endpoint/components.cjs +257 -0
- package/dist/endpoint/components.js +253 -0
- package/dist/endpoint/components.js.map +1 -0
- package/dist/endpoint/endpoint.cjs +117 -0
- package/dist/endpoint/endpoint.js +118 -0
- package/dist/endpoint/endpoint.js.map +1 -0
- package/dist/endpoint/fetch_endpoint.cjs +41 -0
- package/dist/endpoint/fetch_endpoint.d.cts +39 -0
- package/dist/endpoint/fetch_endpoint.d.cts.map +1 -0
- package/dist/endpoint/fetch_endpoint.d.ts +39 -0
- package/dist/endpoint/fetch_endpoint.d.ts.map +1 -0
- package/dist/endpoint/fetch_endpoint.js +42 -0
- package/dist/endpoint/fetch_endpoint.js.map +1 -0
- package/dist/endpoint/handlers/fetch.cjs +21 -0
- package/dist/endpoint/handlers/fetch.js +21 -0
- package/dist/endpoint/handlers/fetch.js.map +1 -0
- package/dist/endpoint/handlers/generic.cjs +328 -0
- package/dist/endpoint/handlers/generic.js +324 -0
- package/dist/endpoint/handlers/generic.js.map +1 -0
- package/dist/endpoint/handlers/lambda.cjs +93 -0
- package/dist/endpoint/handlers/lambda.js +89 -0
- package/dist/endpoint/handlers/lambda.js.map +1 -0
- package/dist/endpoint/lambda_endpoint.cjs +36 -0
- package/dist/endpoint/lambda_endpoint.d.cts +26 -0
- package/dist/endpoint/lambda_endpoint.d.cts.map +1 -0
- package/dist/endpoint/lambda_endpoint.d.ts +26 -0
- package/dist/endpoint/lambda_endpoint.d.ts.map +1 -0
- package/dist/endpoint/lambda_endpoint.js +37 -0
- package/dist/endpoint/lambda_endpoint.js.map +1 -0
- package/dist/endpoint/node_endpoint.cjs +101 -0
- package/dist/endpoint/node_endpoint.js +99 -0
- package/dist/endpoint/node_endpoint.js.map +1 -0
- package/dist/endpoint/types.d.cts +61 -0
- package/dist/endpoint/types.d.cts.map +1 -0
- package/dist/endpoint/types.d.ts +61 -0
- package/dist/endpoint/types.d.ts.map +1 -0
- package/dist/endpoint/withOptions.cjs +15 -0
- package/dist/endpoint/withOptions.js +15 -0
- package/dist/endpoint/withOptions.js.map +1 -0
- package/dist/endpoint.d.cts +112 -0
- package/dist/endpoint.d.cts.map +1 -0
- package/dist/endpoint.d.ts +112 -0
- package/dist/endpoint.d.ts.map +1 -0
- package/dist/fetch.cjs +83 -0
- package/dist/fetch.d.cts +52 -0
- package/dist/fetch.d.cts.map +1 -0
- package/dist/fetch.d.ts +52 -0
- package/dist/fetch.d.ts.map +1 -0
- package/dist/{esm/src/fetch.js → fetch.js} +15 -18
- package/dist/fetch.js.map +1 -0
- package/dist/index.cjs +48 -0
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +7 -0
- package/dist/io.cjs +48 -0
- package/dist/io.js +48 -0
- package/dist/io.js.map +1 -0
- package/dist/lambda.cjs +74 -0
- package/dist/lambda.d.cts +32 -0
- package/dist/lambda.d.cts.map +1 -0
- package/dist/lambda.d.ts +32 -0
- package/dist/lambda.d.ts.map +1 -0
- package/dist/lambda.js +35 -0
- package/dist/lambda.js.map +1 -0
- package/dist/logging/console_logger_transport.cjs +54 -0
- package/dist/logging/console_logger_transport.js +54 -0
- package/dist/logging/console_logger_transport.js.map +1 -0
- package/dist/logging/logger.cjs +43 -0
- package/dist/logging/logger.js +44 -0
- package/dist/logging/logger.js.map +1 -0
- package/dist/logging/logger_transport.cjs +42 -0
- package/dist/logging/logger_transport.d.cts +57 -0
- package/dist/logging/logger_transport.d.cts.map +1 -0
- package/dist/logging/logger_transport.d.ts +57 -0
- package/dist/logging/logger_transport.d.ts.map +1 -0
- package/dist/logging/logger_transport.js +40 -0
- package/dist/logging/logger_transport.js.map +1 -0
- package/dist/node.cjs +90 -0
- package/dist/node.d.cts +51 -0
- package/dist/node.d.cts.map +1 -0
- package/dist/node.d.ts +51 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +50 -0
- package/dist/node.js.map +1 -0
- package/dist/package.cjs +11 -0
- package/dist/package.js +6 -0
- package/dist/package.js.map +1 -0
- package/dist/promises.cjs +234 -0
- package/dist/promises.js +226 -0
- package/dist/promises.js.map +1 -0
- package/dist/types/errors.cjs +110 -0
- package/dist/types/errors.d.cts +71 -0
- package/dist/types/errors.d.cts.map +1 -0
- package/dist/types/errors.d.ts +71 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +102 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/rpc.cjs +425 -0
- package/dist/types/rpc.d.cts +580 -0
- package/dist/types/rpc.d.cts.map +1 -0
- package/dist/types/rpc.d.ts +580 -0
- package/dist/types/rpc.d.ts.map +1 -0
- package/dist/types/rpc.js +406 -0
- package/dist/types/rpc.js.map +1 -0
- package/dist/user_agent.cjs +7 -0
- package/dist/user_agent.js +8 -0
- package/dist/user_agent.js.map +1 -0
- package/dist/utils/completable_promise.cjs +22 -0
- package/dist/utils/completable_promise.js +22 -0
- package/dist/utils/completable_promise.js.map +1 -0
- package/dist/utils/rand.cjs +72 -0
- package/dist/utils/rand.js +71 -0
- package/dist/utils/rand.js.map +1 -0
- package/dist/utils/streams.cjs +14 -0
- package/dist/utils/streams.js +13 -0
- package/dist/utils/streams.js.map +1 -0
- package/package.json +30 -52
- package/dist/esm/src/common_api.d.ts +0 -37
- package/dist/esm/src/common_api.d.ts.map +0 -1
- package/dist/esm/src/common_api.js +0 -32
- package/dist/esm/src/common_api.js.map +0 -1
- package/dist/esm/src/context.d.ts +0 -695
- package/dist/esm/src/context.d.ts.map +0 -1
- package/dist/esm/src/context.js +0 -87
- package/dist/esm/src/context.js.map +0 -1
- package/dist/esm/src/context_impl.d.ts +0 -69
- package/dist/esm/src/context_impl.d.ts.map +0 -1
- package/dist/esm/src/context_impl.js +0 -592
- package/dist/esm/src/context_impl.js.map +0 -1
- package/dist/esm/src/endpoint/components.d.ts +0 -97
- package/dist/esm/src/endpoint/components.d.ts.map +0 -1
- package/dist/esm/src/endpoint/components.js +0 -343
- package/dist/esm/src/endpoint/components.js.map +0 -1
- package/dist/esm/src/endpoint/discovery.d.ts +0 -184
- package/dist/esm/src/endpoint/discovery.d.ts.map +0 -1
- package/dist/esm/src/endpoint/discovery.js +0 -8
- package/dist/esm/src/endpoint/discovery.js.map +0 -1
- package/dist/esm/src/endpoint/endpoint.d.ts +0 -39
- package/dist/esm/src/endpoint/endpoint.d.ts.map +0 -1
- package/dist/esm/src/endpoint/endpoint.js +0 -155
- package/dist/esm/src/endpoint/endpoint.js.map +0 -1
- package/dist/esm/src/endpoint/fetch_endpoint.d.ts +0 -49
- package/dist/esm/src/endpoint/fetch_endpoint.d.ts.map +0 -1
- package/dist/esm/src/endpoint/fetch_endpoint.js +0 -49
- package/dist/esm/src/endpoint/fetch_endpoint.js.map +0 -1
- package/dist/esm/src/endpoint/handlers/fetch.d.ts +0 -5
- package/dist/esm/src/endpoint/handlers/fetch.d.ts.map +0 -1
- package/dist/esm/src/endpoint/handlers/fetch.js +0 -31
- package/dist/esm/src/endpoint/handlers/fetch.js.map +0 -1
- package/dist/esm/src/endpoint/handlers/generic.d.ts +0 -61
- package/dist/esm/src/endpoint/handlers/generic.d.ts.map +0 -1
- package/dist/esm/src/endpoint/handlers/generic.js +0 -470
- package/dist/esm/src/endpoint/handlers/generic.js.map +0 -1
- package/dist/esm/src/endpoint/handlers/lambda.d.ts +0 -10
- package/dist/esm/src/endpoint/handlers/lambda.d.ts.map +0 -1
- package/dist/esm/src/endpoint/handlers/lambda.js +0 -143
- package/dist/esm/src/endpoint/handlers/lambda.js.map +0 -1
- package/dist/esm/src/endpoint/lambda_endpoint.d.ts +0 -30
- package/dist/esm/src/endpoint/lambda_endpoint.d.ts.map +0 -1
- package/dist/esm/src/endpoint/lambda_endpoint.js +0 -48
- package/dist/esm/src/endpoint/lambda_endpoint.js.map +0 -1
- package/dist/esm/src/endpoint/node_endpoint.d.ts +0 -16
- package/dist/esm/src/endpoint/node_endpoint.d.ts.map +0 -1
- package/dist/esm/src/endpoint/node_endpoint.js +0 -124
- package/dist/esm/src/endpoint/node_endpoint.js.map +0 -1
- package/dist/esm/src/endpoint/types.d.ts +0 -55
- package/dist/esm/src/endpoint/types.d.ts.map +0 -1
- package/dist/esm/src/endpoint/types.js +0 -2
- package/dist/esm/src/endpoint/types.js.map +0 -1
- package/dist/esm/src/endpoint/withOptions.d.ts +0 -4
- package/dist/esm/src/endpoint/withOptions.d.ts.map +0 -1
- package/dist/esm/src/endpoint/withOptions.js +0 -19
- package/dist/esm/src/endpoint/withOptions.js.map +0 -1
- package/dist/esm/src/endpoint.d.ts +0 -108
- package/dist/esm/src/endpoint.d.ts.map +0 -1
- package/dist/esm/src/endpoint.js +0 -12
- package/dist/esm/src/endpoint.js.map +0 -1
- package/dist/esm/src/fetch.d.ts +0 -43
- package/dist/esm/src/fetch.d.ts.map +0 -1
- package/dist/esm/src/fetch.js.map +0 -1
- package/dist/esm/src/generated/version.d.ts +0 -2
- package/dist/esm/src/generated/version.d.ts.map +0 -1
- package/dist/esm/src/generated/version.js +0 -2
- package/dist/esm/src/generated/version.js.map +0 -1
- package/dist/esm/src/io.d.ts +0 -24
- package/dist/esm/src/io.d.ts.map +0 -1
- package/dist/esm/src/io.js +0 -73
- package/dist/esm/src/io.js.map +0 -1
- package/dist/esm/src/lambda.d.ts +0 -23
- package/dist/esm/src/lambda.d.ts.map +0 -1
- package/dist/esm/src/lambda.js +0 -37
- package/dist/esm/src/lambda.js.map +0 -1
- package/dist/esm/src/logging/console_logger_transport.d.ts +0 -5
- package/dist/esm/src/logging/console_logger_transport.d.ts.map +0 -1
- package/dist/esm/src/logging/console_logger_transport.js +0 -94
- package/dist/esm/src/logging/console_logger_transport.js.map +0 -1
- package/dist/esm/src/logging/logger.d.ts +0 -10
- package/dist/esm/src/logging/logger.d.ts.map +0 -1
- package/dist/esm/src/logging/logger.js +0 -57
- package/dist/esm/src/logging/logger.js.map +0 -1
- package/dist/esm/src/logging/logger_transport.d.ts +0 -52
- package/dist/esm/src/logging/logger_transport.d.ts.map +0 -1
- package/dist/esm/src/logging/logger_transport.js +0 -55
- package/dist/esm/src/logging/logger_transport.js.map +0 -1
- package/dist/esm/src/node.d.ts +0 -39
- package/dist/esm/src/node.d.ts.map +0 -1
- package/dist/esm/src/node.js +0 -52
- package/dist/esm/src/node.js.map +0 -1
- package/dist/esm/src/promises.d.ts +0 -111
- package/dist/esm/src/promises.d.ts.map +0 -1
- package/dist/esm/src/promises.js +0 -314
- package/dist/esm/src/promises.js.map +0 -1
- package/dist/esm/src/public_api.d.ts +0 -2
- package/dist/esm/src/public_api.d.ts.map +0 -1
- package/dist/esm/src/public_api.js +0 -12
- package/dist/esm/src/public_api.js.map +0 -1
- package/dist/esm/src/types/errors.d.ts +0 -74
- package/dist/esm/src/types/errors.d.ts.map +0 -1
- package/dist/esm/src/types/errors.js +0 -128
- package/dist/esm/src/types/errors.js.map +0 -1
- package/dist/esm/src/types/rpc.d.ts +0 -620
- package/dist/esm/src/types/rpc.d.ts.map +0 -1
- package/dist/esm/src/types/rpc.js +0 -577
- package/dist/esm/src/types/rpc.js.map +0 -1
- package/dist/esm/src/user_agent.d.ts +0 -2
- package/dist/esm/src/user_agent.d.ts.map +0 -1
- package/dist/esm/src/user_agent.js +0 -13
- package/dist/esm/src/user_agent.js.map +0 -1
- package/dist/esm/src/utils/completable_promise.d.ts +0 -9
- package/dist/esm/src/utils/completable_promise.d.ts.map +0 -1
- package/dist/esm/src/utils/completable_promise.js +0 -30
- package/dist/esm/src/utils/completable_promise.js.map +0 -1
- package/dist/esm/src/utils/rand.d.ts +0 -13
- package/dist/esm/src/utils/rand.d.ts.map +0 -1
- package/dist/esm/src/utils/rand.js +0 -109
- package/dist/esm/src/utils/rand.js.map +0 -1
- package/dist/esm/src/utils/streams.d.ts +0 -3
- package/dist/esm/src/utils/streams.d.ts.map +0 -1
- package/dist/esm/src/utils/streams.js +0 -20
- package/dist/esm/src/utils/streams.js.map +0 -1
- package/dist/esm/tsconfig.tsbuildinfo +0 -1
- /package/dist/{esm/src/endpoint → endpoint}/handlers/vm/sdk_shared_core_wasm_bindings.d.ts +0 -0
- /package/dist/{esm/src/endpoint → endpoint}/handlers/vm/sdk_shared_core_wasm_bindings.js +0 -0
- /package/dist/{esm/src/endpoint → endpoint}/handlers/vm/sdk_shared_core_wasm_bindings_bg.js +0 -0
- /package/dist/{esm/src/endpoint → endpoint}/handlers/vm/sdk_shared_core_wasm_bindings_bg.wasm +0 -0
- /package/dist/{esm/src/endpoint → endpoint}/handlers/vm/sdk_shared_core_wasm_bindings_bg.wasm.d.ts +0 -0
|
@@ -1,695 +0,0 @@
|
|
|
1
|
-
import type { Client, SendClient } from "./types/rpc.js";
|
|
2
|
-
import type { RestateContext, RestateObjectContext, RestateObjectSharedContext, RestateWorkflowContext, RestateWorkflowSharedContext, Service, ServiceDefinitionFrom, VirtualObject, VirtualObjectDefinitionFrom, Workflow, WorkflowDefinitionFrom, Serde, Duration } from "@restatedev/restate-sdk-core";
|
|
3
|
-
import type { TerminalError } from "./types/errors.js";
|
|
4
|
-
/**
|
|
5
|
-
* Represents the original request as sent to this handler.
|
|
6
|
-
*
|
|
7
|
-
* A request object includes the request headers, and the raw unparsed
|
|
8
|
-
* request body.
|
|
9
|
-
*/
|
|
10
|
-
export interface Request {
|
|
11
|
-
/**
|
|
12
|
-
* The unique id that identifies the current function invocation. This id is guaranteed to be
|
|
13
|
-
* unique across invocations, but constant across reties and suspensions.
|
|
14
|
-
*/
|
|
15
|
-
readonly id: string;
|
|
16
|
-
/**
|
|
17
|
-
* Request headers - the following headers capture the original invocation headers, as provided to
|
|
18
|
-
* the ingress.
|
|
19
|
-
*/
|
|
20
|
-
readonly headers: ReadonlyMap<string, string>;
|
|
21
|
-
/**
|
|
22
|
-
* Attempt headers - the following headers are sent by the restate runtime.
|
|
23
|
-
* These headers are attempt specific, generated by the restate runtime uniquely for each attempt.
|
|
24
|
-
* These headers might contain information such as the W3C trace context, and attempt specific information.
|
|
25
|
-
*/
|
|
26
|
-
readonly attemptHeaders: ReadonlyMap<string, string | string[] | undefined>;
|
|
27
|
-
/**
|
|
28
|
-
* Raw unparsed request body
|
|
29
|
-
*/
|
|
30
|
-
readonly body: Uint8Array;
|
|
31
|
-
/**
|
|
32
|
-
* Extra arguments provided to the request handler:
|
|
33
|
-
* Lambda: [Context]
|
|
34
|
-
* Cloudflare workers: [Env, ExecutionContext]
|
|
35
|
-
* Deno: [ConnInfo]
|
|
36
|
-
* Bun: [Server]
|
|
37
|
-
* These arguments can contain request-specific values that could change after a suspension.
|
|
38
|
-
* Care should be taken to use them deterministically.
|
|
39
|
-
*/
|
|
40
|
-
readonly extraArgs: unknown[];
|
|
41
|
-
/**
|
|
42
|
-
* This is a signal that is aborted when the current attempt has been completed either successful or unsuccessfully.
|
|
43
|
-
* When the signal is aborted, the current attempt has been completed and the handler should not perform any more work, other
|
|
44
|
-
* than cleanup any external resources that might be shared across attempts (e.g. database connections).
|
|
45
|
-
*/
|
|
46
|
-
readonly attemptCompletedSignal: AbortSignal;
|
|
47
|
-
}
|
|
48
|
-
export type TypedState = Record<string, any>;
|
|
49
|
-
export type UntypedState = {
|
|
50
|
-
_: never;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* Key value store operations. Only keyed services have an attached key-value store.
|
|
54
|
-
*/
|
|
55
|
-
export interface KeyValueStore<TState extends TypedState> {
|
|
56
|
-
/**
|
|
57
|
-
* Get/retrieve state from the Restate runtime.
|
|
58
|
-
* Note that state objects are serialized with `Buffer.from(JSON.stringify(theObject))`
|
|
59
|
-
* and deserialized with `JSON.parse(value.toString()) as T`.
|
|
60
|
-
*
|
|
61
|
-
* @param name key of the state to retrieve
|
|
62
|
-
* @returns a Promise that is resolved with the value of the state key
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* const state = await ctx.get<string>("STATE");
|
|
66
|
-
*/
|
|
67
|
-
get<TValue, TKey extends keyof TState = string>(name: TState extends UntypedState ? string : TKey, serde?: Serde<TState extends UntypedState ? TValue : TState[TKey]>): Promise<(TState extends UntypedState ? TValue : TState[TKey]) | null>;
|
|
68
|
-
stateKeys(): Promise<Array<string>>;
|
|
69
|
-
/**
|
|
70
|
-
* Set/store state in the Restate runtime.
|
|
71
|
-
* Note that state objects are serialized with `Buffer.from(JSON.stringify(theObject))`
|
|
72
|
-
* and deserialized with `JSON.parse(value.toString()) as T`.
|
|
73
|
-
*
|
|
74
|
-
* @param name key of the state to set
|
|
75
|
-
* @param value value to set
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* ctx.set("STATE", "Hello");
|
|
79
|
-
*/
|
|
80
|
-
set<TValue, TKey extends keyof TState = string>(name: TState extends UntypedState ? string : TKey, value: TState extends UntypedState ? TValue : TState[TKey], serde?: Serde<TState extends UntypedState ? TValue : TState[TKey]>): void;
|
|
81
|
-
/**
|
|
82
|
-
* Clear/delete state in the Restate runtime.
|
|
83
|
-
* @param name key of the state to delete
|
|
84
|
-
*
|
|
85
|
-
* @example
|
|
86
|
-
* ctx.clear("STATE");
|
|
87
|
-
*/
|
|
88
|
-
clear<TKey extends keyof TState>(name: TState extends UntypedState ? string : TKey): void;
|
|
89
|
-
/**
|
|
90
|
-
* Clear/delete all the state entries in the Restate runtime.
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ctx.clearAll();
|
|
94
|
-
*/
|
|
95
|
-
clearAll(): void;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* @deprecated SendOptions on the client factory are deprecated, please use `restate.rpc.sendOpts` instead
|
|
99
|
-
*/
|
|
100
|
-
export interface SendOptions {
|
|
101
|
-
/**
|
|
102
|
-
* @deprecated SendOptions on the client factory are deprecated, please use `restate.rpc.sendOpts` instead
|
|
103
|
-
*/
|
|
104
|
-
delay?: number;
|
|
105
|
-
}
|
|
106
|
-
export interface ContextDate {
|
|
107
|
-
/** Returns the number of milliseconds elapsed since midnight, January 1, 1970 Universal Coordinated Time (UTC).
|
|
108
|
-
* This is equivalent to Date.now()
|
|
109
|
-
*/
|
|
110
|
-
now(): Promise<number>;
|
|
111
|
-
/** Returns the JSON representation of the current date.
|
|
112
|
-
* This is equivalent to new Date().toJSON()
|
|
113
|
-
**/
|
|
114
|
-
toJSON(): Promise<string>;
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* A function that can be run and its result durably persisted by Restate.
|
|
118
|
-
*/
|
|
119
|
-
export type RunAction<T> = (() => Promise<T>) | (() => T);
|
|
120
|
-
export type RunOptions<T> = {
|
|
121
|
-
serde?: Serde<T>;
|
|
122
|
-
/**
|
|
123
|
-
* Max number of attempts (including the initial), before giving up.
|
|
124
|
-
*
|
|
125
|
-
* When giving up, `ctx.run` will throw a `TerminalError` wrapping the original error message.
|
|
126
|
-
*/
|
|
127
|
-
maxRetryAttempts?: number;
|
|
128
|
-
/**
|
|
129
|
-
* @deprecated Use `maxRetryDuration` instead.
|
|
130
|
-
*/
|
|
131
|
-
maxRetryDurationMillis?: number;
|
|
132
|
-
/**
|
|
133
|
-
* Max duration of retries, before giving up.
|
|
134
|
-
*
|
|
135
|
-
* When giving up, `ctx.run` will throw a `TerminalError` wrapping the original error message.
|
|
136
|
-
*
|
|
137
|
-
* If a number is provided, it will be interpreted as milliseconds.
|
|
138
|
-
*/
|
|
139
|
-
maxRetryDuration?: Duration | number;
|
|
140
|
-
/**
|
|
141
|
-
* @deprecated Use `initialRetryInterval` instead.
|
|
142
|
-
*/
|
|
143
|
-
initialRetryIntervalMillis?: number;
|
|
144
|
-
/**
|
|
145
|
-
* Initial interval for the first retry attempt.
|
|
146
|
-
* Retry interval will grow by a factor specified in `retryIntervalFactor`.
|
|
147
|
-
*
|
|
148
|
-
* The default is 50 milliseconds.
|
|
149
|
-
*
|
|
150
|
-
* If a number is provided, it will be interpreted as milliseconds.
|
|
151
|
-
*/
|
|
152
|
-
initialRetryInterval?: Duration | number;
|
|
153
|
-
/**
|
|
154
|
-
* @deprecated Use `maxRetryInterval` instead.
|
|
155
|
-
*/
|
|
156
|
-
maxRetryIntervalMillis?: number;
|
|
157
|
-
/**
|
|
158
|
-
* Max interval between retries.
|
|
159
|
-
* Retry interval will grow by a factor specified in `retryIntervalFactor`.
|
|
160
|
-
*
|
|
161
|
-
* The default is 10 seconds.
|
|
162
|
-
*
|
|
163
|
-
* If a number is provided, it will be interpreted as milliseconds.
|
|
164
|
-
*/
|
|
165
|
-
maxRetryInterval?: Duration | number;
|
|
166
|
-
/**
|
|
167
|
-
* Exponentiation factor to use when computing the next retry delay.
|
|
168
|
-
*
|
|
169
|
-
* The default value is `2`, meaning retry interval will double at each attempt.
|
|
170
|
-
*/
|
|
171
|
-
retryIntervalFactor?: number;
|
|
172
|
-
};
|
|
173
|
-
/**
|
|
174
|
-
* Call a handler directly avoiding restate's type safety checks.
|
|
175
|
-
* This is a generic mechanism to invoke handlers directly by only knowing
|
|
176
|
-
* the service and handler name, (or key in the case of objects or workflows)
|
|
177
|
-
*/
|
|
178
|
-
export type GenericCall<REQ, RES> = {
|
|
179
|
-
service: string;
|
|
180
|
-
method: string;
|
|
181
|
-
parameter: REQ;
|
|
182
|
-
key?: string;
|
|
183
|
-
headers?: Record<string, string>;
|
|
184
|
-
inputSerde?: Serde<REQ>;
|
|
185
|
-
outputSerde?: Serde<RES>;
|
|
186
|
-
idempotencyKey?: string;
|
|
187
|
-
};
|
|
188
|
-
/**
|
|
189
|
-
* Send a message to an handler directly avoiding restate's type safety checks.
|
|
190
|
-
* This is a generic mechanism to invoke handlers directly by only knowing
|
|
191
|
-
* the service and handler name, (or key in the case of objects or workflows)
|
|
192
|
-
*/
|
|
193
|
-
export type GenericSend<REQ> = {
|
|
194
|
-
service: string;
|
|
195
|
-
method: string;
|
|
196
|
-
parameter: REQ;
|
|
197
|
-
key?: string;
|
|
198
|
-
headers?: Record<string, string>;
|
|
199
|
-
inputSerde?: Serde<REQ>;
|
|
200
|
-
delay?: Duration | number;
|
|
201
|
-
idempotencyKey?: string;
|
|
202
|
-
};
|
|
203
|
-
/**
|
|
204
|
-
* The context that gives access to all Restate-backed operations, for example
|
|
205
|
-
* - sending reliable messages / RPC through Restate
|
|
206
|
-
* - execute non-deterministic closures and memoize their result
|
|
207
|
-
* - sleeps and delayed calls
|
|
208
|
-
* - awakeables
|
|
209
|
-
* - ...
|
|
210
|
-
*
|
|
211
|
-
* Virtual objects can also access their key-value store using the {@link ObjectContext}.
|
|
212
|
-
*
|
|
213
|
-
*/
|
|
214
|
-
export interface Context extends RestateContext {
|
|
215
|
-
/**
|
|
216
|
-
* Deterministic random methods; these are inherently predictable (seeded on the invocation ID, which is not secret)
|
|
217
|
-
* and so should not be used for any cryptographic purposes. They are useful for identifiers, idempotency keys,
|
|
218
|
-
* and for uniform sampling from a set of options. If a cryptographically secure value is needed, please generate that
|
|
219
|
-
* externally and capture the result with a side effect.
|
|
220
|
-
*
|
|
221
|
-
* Calls to these methods from inside `ctx.run` are disallowed and will fail - side effects must be idempotent, and
|
|
222
|
-
* these calls are not.
|
|
223
|
-
*/
|
|
224
|
-
rand: Rand;
|
|
225
|
-
/**
|
|
226
|
-
* Console to use for logging. It attaches to each log message some contextual information,
|
|
227
|
-
* such as invoked service method and invocation id, and automatically excludes logs during replay.
|
|
228
|
-
*/
|
|
229
|
-
console: Console;
|
|
230
|
-
/**
|
|
231
|
-
* Deterministic date.
|
|
232
|
-
*/
|
|
233
|
-
date: ContextDate;
|
|
234
|
-
/**
|
|
235
|
-
* Run an operation and store the result in Restate. The operation will thus not
|
|
236
|
-
* be re-run during a later replay, but take the durable result from Restate.
|
|
237
|
-
*
|
|
238
|
-
* This let you capture potentially non-deterministic computation and interaction
|
|
239
|
-
* with external systems in a safe way.
|
|
240
|
-
*
|
|
241
|
-
* Failure semantics are:
|
|
242
|
-
* - If an operation has run and persisted before, the result (value or Error) will be
|
|
243
|
-
* taken from the Restate journal.
|
|
244
|
-
* - There is a small window where an action may be re-run, if a failure
|
|
245
|
-
* occurred between a successful run and persisting the result.
|
|
246
|
-
* - No second action will be run while a previous run's result is not
|
|
247
|
-
* yet durable. That way, effects that build on top of each other can assume
|
|
248
|
-
* deterministic results from previous runs, and at most one run will be
|
|
249
|
-
* re-executed on replay (the latest, if the failure happened in the small windows
|
|
250
|
-
* described above).
|
|
251
|
-
*
|
|
252
|
-
* You can customize retry options by either:
|
|
253
|
-
*
|
|
254
|
-
* - Providing retry policy options in {@link RunOptions}
|
|
255
|
-
* - Throwing {@link RetryableError}, providing `retryAfter` option. This can be especially useful when interacting with HTTP requests returning the `Retry-After` header. You can combine the usage of throwing {@link RetryableError} with the `maxRetryAttempts`/`maxRetryDuration` from {@link RunOptions}.
|
|
256
|
-
*
|
|
257
|
-
* @example Run some external action and persist its result
|
|
258
|
-
* ```ts
|
|
259
|
-
* const result = await ctx.run(someExternalAction)
|
|
260
|
-
*```
|
|
261
|
-
* @example Add some retry options
|
|
262
|
-
* ```ts
|
|
263
|
-
* const result = await ctx.run("my action", someExternalAction, { maxRetryAttempts: 10 })
|
|
264
|
-
* ```
|
|
265
|
-
* @example Terminal errors and retryable errors
|
|
266
|
-
* ```ts
|
|
267
|
-
* await ctx.run("payment action", async () => {
|
|
268
|
-
* const result = await paymentProvider.charge(txId, paymentInfo);
|
|
269
|
-
* if (result.paymentRejected) {
|
|
270
|
-
* // this action will not be retried anymore
|
|
271
|
-
* throw new TerminalError("Payment failed");
|
|
272
|
-
* } else if (result.paymentGatewayBusy) {
|
|
273
|
-
* // restate will retry automatically
|
|
274
|
-
* // to bound retries, use RunOptions
|
|
275
|
-
* throw new Error("Payment gateway busy");
|
|
276
|
-
* } else {
|
|
277
|
-
* // success!
|
|
278
|
-
* }
|
|
279
|
-
* });
|
|
280
|
-
* ```
|
|
281
|
-
* @example Retryable error with custom retry delay
|
|
282
|
-
* ```ts
|
|
283
|
-
* await ctx.run("payment action", async () => {
|
|
284
|
-
* const res = fetch(...);
|
|
285
|
-
* if (!res.ok) {
|
|
286
|
-
* // Read Retry-After header
|
|
287
|
-
* const retryAfterHeader = res.headers['Retry-After']
|
|
288
|
-
*
|
|
289
|
-
* // Use RetryableError to customize in how long to retry
|
|
290
|
-
* throw RetryableError.from(cause, { retryAfter: { seconds: retryAfterHeader } })
|
|
291
|
-
* }
|
|
292
|
-
* }, {
|
|
293
|
-
* // Retry at most ten times
|
|
294
|
-
* maxRetryAttempts: 10
|
|
295
|
-
* });
|
|
296
|
-
* ```
|
|
297
|
-
*
|
|
298
|
-
* @param action The function to run.
|
|
299
|
-
*/
|
|
300
|
-
run<T>(action: RunAction<T>): RestatePromise<T>;
|
|
301
|
-
/**
|
|
302
|
-
* Same as {@link run}, but providing a name, used for observability purposes.
|
|
303
|
-
*/
|
|
304
|
-
run<T>(name: string, action: RunAction<T>): RestatePromise<T>;
|
|
305
|
-
/**
|
|
306
|
-
* See {@link run}
|
|
307
|
-
*/
|
|
308
|
-
run<T>(name: string, action: RunAction<T>, options: RunOptions<T>): RestatePromise<T>;
|
|
309
|
-
/**
|
|
310
|
-
* Register an awakeable and pause the processing until the awakeable ID (and optional payload) have been returned to the service
|
|
311
|
-
* (via ctx.completeAwakeable(...)). The SDK deserializes the payload with `JSON.parse(result.toString()) as T`.
|
|
312
|
-
* @returns
|
|
313
|
-
* - id: the string ID that has to be used to complete the awakaeble by some external service
|
|
314
|
-
* - promise: the Promise that needs to be awaited and that is resolved with the payload that was supplied by the service which completed the awakeable
|
|
315
|
-
* @example Retryable errors and terminal errors
|
|
316
|
-
* const awakeable = ctx.awakeable<string>();
|
|
317
|
-
*
|
|
318
|
-
* // send the awakeable ID to some external service that will wake this one back up
|
|
319
|
-
* // The ID can be retrieved by:
|
|
320
|
-
* const id = awakeable.id;
|
|
321
|
-
*
|
|
322
|
-
* // ... send to external service ...
|
|
323
|
-
*
|
|
324
|
-
* // Wait for the external service to wake this service back up
|
|
325
|
-
* const result = await awakeable.promise;
|
|
326
|
-
*/
|
|
327
|
-
awakeable<T>(serde?: Serde<T>): {
|
|
328
|
-
id: string;
|
|
329
|
-
promise: RestatePromise<T>;
|
|
330
|
-
};
|
|
331
|
-
/**
|
|
332
|
-
* Resolve an awakeable.
|
|
333
|
-
* @param id the string ID of the awakeable.
|
|
334
|
-
* This is supplied by the service that needs to be woken up.
|
|
335
|
-
* @param payload the payload to pass to the service that is woken up.
|
|
336
|
-
* The SDK serializes the payload with `Buffer.from(JSON.stringify(payload))`
|
|
337
|
-
* and deserializes it in the receiving service with `JSON.parse(result.toString()) as T`.
|
|
338
|
-
* @example Retryable error with custom retry delay
|
|
339
|
-
* // The sleeping service should have sent the awakeableIdentifier string to this service.
|
|
340
|
-
* ctx.resolveAwakeable(awakeableIdentifier, "hello");
|
|
341
|
-
*/
|
|
342
|
-
resolveAwakeable<T>(id: string, payload?: T, serde?: Serde<T>): void;
|
|
343
|
-
/**
|
|
344
|
-
* Reject an awakeable. When rejecting, the service waiting on this awakeable will be woken up with a terminal error with the provided reason.
|
|
345
|
-
* @param id the string ID of the awakeable.
|
|
346
|
-
* This is supplied by the service that needs to be woken up.
|
|
347
|
-
* @param reason the reason of the rejection.
|
|
348
|
-
*
|
|
349
|
-
* @example
|
|
350
|
-
* // The sleeping service should have sent the awakeableIdentifier string to this service.
|
|
351
|
-
* ctx.rejectAwakeable(awakeableIdentifier, "super bad error");
|
|
352
|
-
*/
|
|
353
|
-
rejectAwakeable(id: string, reason: string): void;
|
|
354
|
-
/**
|
|
355
|
-
* Sleep until a timeout has passed.
|
|
356
|
-
* @param duration either Duration type or milliseconds.
|
|
357
|
-
* @param name Observability name. This will be shown in the UI.
|
|
358
|
-
* This is a lower-bound.
|
|
359
|
-
*
|
|
360
|
-
* @example
|
|
361
|
-
* await ctx.sleep(1000);
|
|
362
|
-
*/
|
|
363
|
-
sleep(duration: Duration | number, name?: string): RestatePromise<void>;
|
|
364
|
-
/**
|
|
365
|
-
* Makes a type-safe request/response RPC to the specified target service.
|
|
366
|
-
*
|
|
367
|
-
* The RPC goes through Restate and is guaranteed to be reliably delivered. The RPC is also
|
|
368
|
-
* journaled for durable execution and will thus not be duplicated when the handler is re-invoked
|
|
369
|
-
* for retries or after suspending.
|
|
370
|
-
*
|
|
371
|
-
* This call will return the result produced by the target handler, or the Error, if the target
|
|
372
|
-
* handler finishes with a Terminal Error.
|
|
373
|
-
*
|
|
374
|
-
* This call is a suspension point: The handler might suspend while awaiting the response and
|
|
375
|
-
* resume once the response is available.
|
|
376
|
-
*
|
|
377
|
-
* @example
|
|
378
|
-
* *Service Side:*
|
|
379
|
-
* ```ts
|
|
380
|
-
* const service = restate.service(
|
|
381
|
-
* name: "myservice",
|
|
382
|
-
* handlers: {
|
|
383
|
-
* someAction: async(ctx: restate.Context, req: string) => { ... },
|
|
384
|
-
* anotherAction: async(ctx: restate.Context, count: number) => { ... }
|
|
385
|
-
* });
|
|
386
|
-
*
|
|
387
|
-
* // option 1: export only the type signature
|
|
388
|
-
* export type Service = typeof service;
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
* restate.serve({ services: [service], port: 9080 });
|
|
392
|
-
* ```
|
|
393
|
-
* *Client side:*
|
|
394
|
-
* ```ts
|
|
395
|
-
* // option 1: use only types and supply service name separately
|
|
396
|
-
* const result1 = await ctx.serviceClient<Service>({name: "myservice"}).someAction("hello!");
|
|
397
|
-
*
|
|
398
|
-
* // option 2: use full API spec
|
|
399
|
-
* type MyService: Service = { name: "myservice" };
|
|
400
|
-
* const result2 = await ctx.serviceClient(Service).anotherAction(1337);
|
|
401
|
-
* ```
|
|
402
|
-
*/
|
|
403
|
-
serviceClient<D>(opts: ServiceDefinitionFrom<D>): Client<Service<D>>;
|
|
404
|
-
/**
|
|
405
|
-
* Same as {@link serviceClient} but for virtual objects.
|
|
406
|
-
*
|
|
407
|
-
* @param opts
|
|
408
|
-
* @param key the virtual object key
|
|
409
|
-
*/
|
|
410
|
-
objectClient<D>(opts: VirtualObjectDefinitionFrom<D>, key: string): Client<VirtualObject<D>>;
|
|
411
|
-
/**
|
|
412
|
-
* Same as {@link serviceClient} but for workflows.
|
|
413
|
-
*
|
|
414
|
-
* @param opts
|
|
415
|
-
* @param key the workflow key
|
|
416
|
-
*/
|
|
417
|
-
workflowClient<D>(opts: WorkflowDefinitionFrom<D>, key: string): Client<Workflow<D>>;
|
|
418
|
-
/**
|
|
419
|
-
* Same as {@link objectSendClient} but for workflows.
|
|
420
|
-
*
|
|
421
|
-
* @param opts
|
|
422
|
-
* @param key the workflow key
|
|
423
|
-
*/
|
|
424
|
-
workflowSendClient<D>(opts: WorkflowDefinitionFrom<D>, key: string): SendClient<Workflow<D>>;
|
|
425
|
-
/**
|
|
426
|
-
* Makes a type-safe one-way RPC to the specified target service. This method effectively behaves
|
|
427
|
-
* like enqueuing the message in a message queue.
|
|
428
|
-
*
|
|
429
|
-
* The message goes through Restate and is guaranteed to be reliably delivered. The RPC is also
|
|
430
|
-
* journaled for durable execution and will thus not be duplicated when the handler is re-invoked
|
|
431
|
-
* for retries or after suspending.
|
|
432
|
-
*
|
|
433
|
-
* This call will return immediately; the message sending happens asynchronously in the background.
|
|
434
|
-
* Despite that, the message is guaranteed to be sent, because the completion of the invocation that
|
|
435
|
-
* triggers the send (calls this function) happens logically after the sending. That means that any
|
|
436
|
-
* failure where the message does not reach Restate also cannot complete this invocation, and will
|
|
437
|
-
* hence recover this handler and (through the durable execution) recover the message to be sent.
|
|
438
|
-
*
|
|
439
|
-
* @example
|
|
440
|
-
* *Service Side:*
|
|
441
|
-
* ```ts
|
|
442
|
-
* const service = restate.service(
|
|
443
|
-
* name: "myservice",
|
|
444
|
-
* handlers: {
|
|
445
|
-
* someAction: async(ctx: restate.Context, req: string) => { ... },
|
|
446
|
-
* anotherAction: async(ctx: restate.Context, count: number) => { ... }
|
|
447
|
-
* });
|
|
448
|
-
*
|
|
449
|
-
* // option 1: export only the type signature of the router
|
|
450
|
-
* export type MyApi = typeof service;
|
|
451
|
-
*
|
|
452
|
-
* // option 2: export the API definition with type and name (name)
|
|
453
|
-
* const MyService: MyApi = { name: "myservice" };
|
|
454
|
-
*
|
|
455
|
-
* restate.serve({ services: [service], port: 9080 });
|
|
456
|
-
* ```
|
|
457
|
-
* *Client side:*
|
|
458
|
-
* ```ts
|
|
459
|
-
* // option 1: use only types and supply service name separately
|
|
460
|
-
* ctx.serviceSendClient<MyApi>({name: "myservice"}).someAction("hello!");
|
|
461
|
-
*
|
|
462
|
-
* // option 2: use full API spec
|
|
463
|
-
* ctx.serviceSendClient(MyService).anotherAction(1337);
|
|
464
|
-
* ```
|
|
465
|
-
*/
|
|
466
|
-
serviceSendClient<D>(service: ServiceDefinitionFrom<D>, opts?: SendOptions): SendClient<Service<D>>;
|
|
467
|
-
/**
|
|
468
|
-
* Same as {@link serviceSendClient} but for virtual objects.
|
|
469
|
-
*
|
|
470
|
-
* @param obj
|
|
471
|
-
* @param key the virtual object key
|
|
472
|
-
* @param opts Send options
|
|
473
|
-
*/
|
|
474
|
-
objectSendClient<D>(obj: VirtualObjectDefinitionFrom<D>, key: string, opts?: SendOptions): SendClient<VirtualObject<D>>;
|
|
475
|
-
genericCall<REQ = Uint8Array, RES = Uint8Array>(call: GenericCall<REQ, RES>): InvocationPromise<RES>;
|
|
476
|
-
genericSend<REQ = Uint8Array>(call: GenericSend<REQ>): InvocationHandle;
|
|
477
|
-
/**
|
|
478
|
-
* Returns the raw request that triggered that handler.
|
|
479
|
-
* Use that object to inspect the original request headers
|
|
480
|
-
*/
|
|
481
|
-
request(): Request;
|
|
482
|
-
/**
|
|
483
|
-
* Cancel an invocation
|
|
484
|
-
*
|
|
485
|
-
* @param invocationId the invocation id to cancel
|
|
486
|
-
*/
|
|
487
|
-
cancel(invocationId: InvocationId): void;
|
|
488
|
-
/**
|
|
489
|
-
* Attach to an invocation
|
|
490
|
-
*
|
|
491
|
-
* @param invocationId the invocation id to attach to
|
|
492
|
-
* @param serde the serde to use for the result, default to JSON serde.
|
|
493
|
-
*/
|
|
494
|
-
attach<T>(invocationId: InvocationId, serde?: Serde<T>): RestatePromise<T>;
|
|
495
|
-
}
|
|
496
|
-
/**
|
|
497
|
-
* The context that gives access to all Restate-backed operations, for example
|
|
498
|
-
* - sending reliable messages / RPC through Restate
|
|
499
|
-
* - access/update state
|
|
500
|
-
* - execute non-deterministic closures and memoize their result
|
|
501
|
-
* - sleeps and delayed calls
|
|
502
|
-
* - awakeables
|
|
503
|
-
* - ...
|
|
504
|
-
*
|
|
505
|
-
* This context can be used only within virtual objects.
|
|
506
|
-
*
|
|
507
|
-
*/
|
|
508
|
-
export interface ObjectContext<TState extends TypedState = UntypedState> extends Context, KeyValueStore<TState>, RestateObjectContext {
|
|
509
|
-
key: string;
|
|
510
|
-
}
|
|
511
|
-
/**
|
|
512
|
-
* The context that gives access to all Restate-backed operations, for example
|
|
513
|
-
* - sending reliable messages / RPC through Restate
|
|
514
|
-
* - execute non-deterministic closures and memoize their result
|
|
515
|
-
* - sleeps and delayed calls
|
|
516
|
-
* - awakeables
|
|
517
|
-
* - ...
|
|
518
|
-
*
|
|
519
|
-
* This context can be used only within a shared virtual objects.
|
|
520
|
-
*
|
|
521
|
-
*/
|
|
522
|
-
export interface ObjectSharedContext<TState extends TypedState = UntypedState> extends Context, RestateObjectSharedContext {
|
|
523
|
-
key: string;
|
|
524
|
-
/**
|
|
525
|
-
* Get/retrieve state from the Restate runtime.
|
|
526
|
-
* Note that state objects are serialized with `Buffer.from(JSON.stringify(theObject))`
|
|
527
|
-
* and deserialized with `JSON.parse(value.toString()) as T`.
|
|
528
|
-
*
|
|
529
|
-
* @param name key of the state to retrieve
|
|
530
|
-
* @returns a Promise that is resolved with the value of the state key
|
|
531
|
-
*
|
|
532
|
-
* @example
|
|
533
|
-
* const state = await ctx.get<string>("STATE");
|
|
534
|
-
*/
|
|
535
|
-
get<TValue, TKey extends keyof TState = string>(name: TState extends UntypedState ? string : TKey, serde?: Serde<TState extends UntypedState ? TValue : TState[TKey]>): Promise<(TState extends UntypedState ? TValue : TState[TKey]) | null>;
|
|
536
|
-
/**
|
|
537
|
-
* Retrieve all the state keys for this object.
|
|
538
|
-
*/
|
|
539
|
-
stateKeys(): Promise<Array<string>>;
|
|
540
|
-
}
|
|
541
|
-
export interface Rand {
|
|
542
|
-
/**
|
|
543
|
-
* Equivalent of JS `Math.random()` but deterministic; seeded by the invocation ID of the current invocation,
|
|
544
|
-
* each call will return a new pseudorandom float within the range [0,1)
|
|
545
|
-
*/
|
|
546
|
-
random(): number;
|
|
547
|
-
/**
|
|
548
|
-
* Using the same random source and seed as random(), produce a UUID version 4 string. This is inherently predictable
|
|
549
|
-
* based on the invocation ID and should not be used in cryptographic contexts
|
|
550
|
-
*/
|
|
551
|
-
uuidv4(): string;
|
|
552
|
-
}
|
|
553
|
-
/**
|
|
554
|
-
* A promise that can be combined using Promise combinators in RestateContext.
|
|
555
|
-
*/
|
|
556
|
-
export type RestatePromise<T> = Promise<T> & {
|
|
557
|
-
/**
|
|
558
|
-
* Creates a promise that awaits for the current promise up to the specified timeout duration.
|
|
559
|
-
* If the timeout is fired, this Promise will be rejected with a {@link TimeoutError}.
|
|
560
|
-
*
|
|
561
|
-
* @param millis duration of the sleep in millis.
|
|
562
|
-
* This is a lower-bound.
|
|
563
|
-
*/
|
|
564
|
-
orTimeout(millis: Duration | number): RestatePromise<T>;
|
|
565
|
-
/**
|
|
566
|
-
* Creates a new {@link RestatePromise} that maps the result of this promise with
|
|
567
|
-
* the provided `mapper`, once this promise is fulfilled.
|
|
568
|
-
*
|
|
569
|
-
* **NOTE**: You **MUST** use this API when you need to map the result of a
|
|
570
|
-
* {@link RestatePromise} without `await`ing it, rather than using {@link Promise.then}.
|
|
571
|
-
* {@link Promise.then} is used by Restate to distinguish when awaiting an asynchronous operation,
|
|
572
|
-
* thus calling `.then` on several Restate promises can lead to concurrency issues.
|
|
573
|
-
*
|
|
574
|
-
* @param mapper the function to execute when this promise is fulfilled.
|
|
575
|
-
* If the promise completed successfully, `value` is provided as input, otherwise `failure` is provided as input.
|
|
576
|
-
* If this mapper returns a value, this value will be used to resolve the returned {@link RestatePromise}.
|
|
577
|
-
* If the mapper throws a {@link TerminalError}, this error will be used to reject the returned {@link RestatePromise}.
|
|
578
|
-
*/
|
|
579
|
-
map<U>(mapper: (value?: T, failure?: TerminalError) => U): RestatePromise<U>;
|
|
580
|
-
};
|
|
581
|
-
/**
|
|
582
|
-
* Represents an invocation id.
|
|
583
|
-
* @see {@link InvocationIdParser}
|
|
584
|
-
*/
|
|
585
|
-
export type InvocationId = string & {
|
|
586
|
-
__brand: "InvocationId";
|
|
587
|
-
};
|
|
588
|
-
export declare const InvocationIdParser: {
|
|
589
|
-
/**
|
|
590
|
-
* Creates an invocation id from a string.
|
|
591
|
-
* @param id the string to use as invocation id.
|
|
592
|
-
*/
|
|
593
|
-
fromString(id: string): InvocationId;
|
|
594
|
-
};
|
|
595
|
-
export type InvocationHandle = {
|
|
596
|
-
readonly invocationId: Promise<InvocationId>;
|
|
597
|
-
};
|
|
598
|
-
export type InvocationPromise<T> = RestatePromise<T> & InvocationHandle;
|
|
599
|
-
export declare const RestatePromise: {
|
|
600
|
-
/**
|
|
601
|
-
* Creates a Promise that is resolved with an array of results when all of the provided Promises
|
|
602
|
-
* resolve, or rejected when any Promise is rejected.
|
|
603
|
-
*
|
|
604
|
-
* See {@link Promise.all} for more details.
|
|
605
|
-
*
|
|
606
|
-
* @param values An iterable of Promises.
|
|
607
|
-
* @returns A new Promise.
|
|
608
|
-
*/
|
|
609
|
-
all<const T extends readonly RestatePromise<unknown>[]>(values: T): RestatePromise<{ -readonly [P in keyof T]: Awaited<T[P]>; }>;
|
|
610
|
-
/**
|
|
611
|
-
* Creates a Promise that is resolved or rejected when any of the provided Promises are resolved
|
|
612
|
-
* or rejected.
|
|
613
|
-
*
|
|
614
|
-
* See {@link Promise.race} for more details.
|
|
615
|
-
*
|
|
616
|
-
* @param values An iterable of Promises.
|
|
617
|
-
* @returns A new Promise.
|
|
618
|
-
*/
|
|
619
|
-
race<const T extends readonly RestatePromise<unknown>[]>(values: T): RestatePromise<Awaited<T[number]>>;
|
|
620
|
-
/**
|
|
621
|
-
* Creates a promise that fulfills when any of the input's promises fulfills, with this first fulfillment value.
|
|
622
|
-
* It rejects when all the input's promises reject (including when an empty iterable is passed),
|
|
623
|
-
* with an AggregateError containing an array of rejection reasons.
|
|
624
|
-
*
|
|
625
|
-
* See {@link Promise.any} for more details.
|
|
626
|
-
*
|
|
627
|
-
* @param values An iterable of Promises.
|
|
628
|
-
* @returns A new Promise.
|
|
629
|
-
*/
|
|
630
|
-
any<const T extends readonly RestatePromise<unknown>[]>(values: T): RestatePromise<Awaited<T[number]>>;
|
|
631
|
-
/**
|
|
632
|
-
* Creates a promise that fulfills when all the input's promises settle (including when an empty iterable is passed),
|
|
633
|
-
* with an array of objects that describe the outcome of each promise.
|
|
634
|
-
*
|
|
635
|
-
* See {@link Promise.allSettled} for more details.
|
|
636
|
-
*
|
|
637
|
-
* @param values An iterable of Promises.
|
|
638
|
-
* @returns A new Promise.
|
|
639
|
-
*/
|
|
640
|
-
allSettled<const T extends readonly RestatePromise<unknown>[]>(values: T): RestatePromise<{ -readonly [P in keyof T]: PromiseSettledResult<Awaited<T[P]>>; }>;
|
|
641
|
-
};
|
|
642
|
-
/**
|
|
643
|
-
* Workflow bound durable promise
|
|
644
|
-
*
|
|
645
|
-
* See {@link WorkflowSharedContext} promise..
|
|
646
|
-
*/
|
|
647
|
-
export type DurablePromise<T> = Promise<T> & {
|
|
648
|
-
/**
|
|
649
|
-
* Returns the value of the promise, if it has been resolved.
|
|
650
|
-
*/
|
|
651
|
-
peek(): Promise<T | undefined>;
|
|
652
|
-
/**
|
|
653
|
-
* Resolve the promise with the given value.
|
|
654
|
-
* @param value the value to resolve the promise with
|
|
655
|
-
*/
|
|
656
|
-
resolve(value?: T): Promise<void>;
|
|
657
|
-
/**
|
|
658
|
-
* Reject the promise with the given error message.
|
|
659
|
-
* @param errorMsg the error message to use for rejection.
|
|
660
|
-
*/
|
|
661
|
-
reject(errorMsg: string): Promise<void>;
|
|
662
|
-
/**
|
|
663
|
-
* Obtain a {@link RestatePromise} variant of this promise.
|
|
664
|
-
*/
|
|
665
|
-
get(): RestatePromise<T>;
|
|
666
|
-
};
|
|
667
|
-
export interface WorkflowSharedContext<TState extends TypedState = UntypedState> extends ObjectSharedContext<TState>, RestateWorkflowSharedContext {
|
|
668
|
-
/**
|
|
669
|
-
* Create a durable promise that can be resolved or rejected during the workflow execution.
|
|
670
|
-
* The promise is bound to the workflow and will be persisted across suspensions and retries.
|
|
671
|
-
* @example Add some retry options
|
|
672
|
-
* ```ts
|
|
673
|
-
* const wf = restate.workflow({
|
|
674
|
-
* name: "myWorkflow",
|
|
675
|
-
* handlers: {
|
|
676
|
-
* run: async (ctx: restate.WorkflowContext) => {
|
|
677
|
-
* // ... do some work ...
|
|
678
|
-
* const payment = await ctx.promise<Payment>("payment.succeeded");
|
|
679
|
-
* // ... do some more work ...
|
|
680
|
-
* },
|
|
681
|
-
*
|
|
682
|
-
* onPaymentSucceeded: async (ctx: restate.WorkflowContext, payment) => {
|
|
683
|
-
* // ... handle payment succeeded ...
|
|
684
|
-
* await ctx.promise("payment.succeeded").resolve(payment);
|
|
685
|
-
* }
|
|
686
|
-
* });
|
|
687
|
-
* ```
|
|
688
|
-
*
|
|
689
|
-
* @param name the name of the durable promise
|
|
690
|
-
*/
|
|
691
|
-
promise<T>(name: string, serde?: Serde<T>): DurablePromise<T>;
|
|
692
|
-
}
|
|
693
|
-
export interface WorkflowContext<TState extends TypedState = UntypedState> extends WorkflowSharedContext<TState>, ObjectContext<TState>, RestateWorkflowContext {
|
|
694
|
-
}
|
|
695
|
-
//# sourceMappingURL=context.d.ts.map
|