@restatedev/restate-sdk-cloudflare-workers 1.9.1 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
@@ -0,0 +1,580 @@
|
|
|
1
|
+
import { TerminalError } from "./errors.js";
|
|
2
|
+
import { Context, InvocationHandle, InvocationPromise, ObjectContext, ObjectSharedContext, TypedState, UntypedState, WorkflowContext, WorkflowSharedContext } from "../context.js";
|
|
3
|
+
import { Duration, ObjectHandler, Serde, ServiceDefinition, ServiceHandler, VirtualObjectDefinition, WorkflowDefinition, WorkflowHandler, WorkflowSharedHandler } from "@restatedev/restate-sdk-core";
|
|
4
|
+
|
|
5
|
+
//#region src/types/rpc.d.ts
|
|
6
|
+
type ClientCallOptions<I, O$1> = {
|
|
7
|
+
input?: Serde<I>;
|
|
8
|
+
output?: Serde<O$1>;
|
|
9
|
+
headers?: Record<string, string>;
|
|
10
|
+
idempotencyKey?: string;
|
|
11
|
+
};
|
|
12
|
+
declare class Opts<I, O$1> {
|
|
13
|
+
private readonly opts;
|
|
14
|
+
/**
|
|
15
|
+
* Create a call configuration from the provided options.
|
|
16
|
+
*
|
|
17
|
+
* @param opts the call configuration
|
|
18
|
+
*/
|
|
19
|
+
static from<I, O$1>(opts: ClientCallOptions<I, O$1>): Opts<I, O$1>;
|
|
20
|
+
private constructor();
|
|
21
|
+
getOpts(): ClientCallOptions<I, O$1>;
|
|
22
|
+
}
|
|
23
|
+
type ClientSendOptions<I> = {
|
|
24
|
+
input?: Serde<I>;
|
|
25
|
+
/**
|
|
26
|
+
* Makes a type-safe one-way RPC to the specified target service, after a delay specified by the
|
|
27
|
+
* milliseconds' argument.
|
|
28
|
+
* This method is like setting up a fault-tolerant cron job that enqueues the message in a
|
|
29
|
+
* message queue.
|
|
30
|
+
* The handler calling this function does not have to stay active for the delay time.
|
|
31
|
+
*
|
|
32
|
+
* Both the delay timer and the message are durably stored in Restate and guaranteed to be reliably
|
|
33
|
+
* delivered. The delivery happens no earlier than specified through the delay, but may happen
|
|
34
|
+
* later, if the target service is down, or backpressuring the system.
|
|
35
|
+
*
|
|
36
|
+
* The delay message is journaled for durable execution and will thus not be duplicated when the
|
|
37
|
+
* handler is re-invoked for retries or after suspending.
|
|
38
|
+
*
|
|
39
|
+
* This call will return immediately; the message sending happens asynchronously in the background.
|
|
40
|
+
* Despite that, the message is guaranteed to be sent, because the completion of the invocation that
|
|
41
|
+
* triggers the send (calls this function) happens logically after the sending. That means that any
|
|
42
|
+
* failure where the message does not reach Restate also cannot complete this invocation, and will
|
|
43
|
+
* hence recover this handler and (through the durable execution) recover the message to be sent.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* ctx.serviceSendClient(Service).anotherAction(1337, { delay: { seconds: 60 } });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
delay?: Duration | number;
|
|
51
|
+
headers?: Record<string, string>;
|
|
52
|
+
idempotencyKey?: string;
|
|
53
|
+
};
|
|
54
|
+
declare class SendOpts<I> {
|
|
55
|
+
private readonly opts;
|
|
56
|
+
static from<I>(opts: ClientSendOptions<I>): SendOpts<I>;
|
|
57
|
+
getOpts(): ClientSendOptions<I>;
|
|
58
|
+
private constructor();
|
|
59
|
+
}
|
|
60
|
+
declare namespace rpc {
|
|
61
|
+
const opts: <I, O$1>(opts: ClientCallOptions<I, O$1>) => Opts<I, O$1>;
|
|
62
|
+
const sendOpts: <I>(opts: ClientSendOptions<I>) => SendOpts<I>;
|
|
63
|
+
}
|
|
64
|
+
type InferArg<P$1> = P$1 extends [infer A, ...any[]] ? A : unknown;
|
|
65
|
+
type Client<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<InferArg<P>, O>]]) => InvocationPromise<O> : never };
|
|
66
|
+
type SendClient<M> = { [K in keyof M as M[K] extends never ? never : K]: M[K] extends ((arg: any, ...args: infer P) => void) ? (...args: [...P, ...[opts?: SendOpts<InferArg<P>>]]) => InvocationHandle : never };
|
|
67
|
+
type ServiceHandlerOpts<I, O$1> = {
|
|
68
|
+
/**
|
|
69
|
+
* Defines which Content-Type values are accepted when this handler is invoked via the ingress.
|
|
70
|
+
* Wildcards are supported, for example `application/*` or `* / *`.
|
|
71
|
+
*
|
|
72
|
+
* If unset, `input.contentType` will be used as the default.
|
|
73
|
+
*
|
|
74
|
+
* This setting does not affect deserialization. To customize how the input is deserialized,
|
|
75
|
+
* provide an `input` Serde.
|
|
76
|
+
*/
|
|
77
|
+
accept?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Serde used to deserialize the input parameter.
|
|
80
|
+
* Defaults to `restate.serde.json`.
|
|
81
|
+
*
|
|
82
|
+
* Provide a custom Serde if the input is not JSON, or use
|
|
83
|
+
* `restate.serde.binary` to skip serialization/deserialization altogether;
|
|
84
|
+
* in that case the input parameter is a `Uint8Array`.
|
|
85
|
+
*/
|
|
86
|
+
input?: Serde<I>;
|
|
87
|
+
/**
|
|
88
|
+
* Serde used to serialize the output value.
|
|
89
|
+
* Defaults to `restate.serde.json`.
|
|
90
|
+
*
|
|
91
|
+
* Provide a custom Serde if the output is not JSON, or use
|
|
92
|
+
* `restate.serde.binary` to skip serialization/deserialization altogether;
|
|
93
|
+
* in that case the output value is a `Uint8Array`.
|
|
94
|
+
*/
|
|
95
|
+
output?: Serde<O$1>;
|
|
96
|
+
/**
|
|
97
|
+
* Human-readable description of the handler, shown in documentation/admin tools.
|
|
98
|
+
*/
|
|
99
|
+
description?: string;
|
|
100
|
+
/**
|
|
101
|
+
* Arbitrary key/value metadata for the handler. Exposed via the Admin API.
|
|
102
|
+
*/
|
|
103
|
+
metadata?: Record<string, string>;
|
|
104
|
+
/**
|
|
105
|
+
* The retention duration of idempotent requests to this handler.
|
|
106
|
+
*
|
|
107
|
+
* Note: Available only when registering this endpoint with restate-server v1.4 or newer; otherwise service discovery will fail.
|
|
108
|
+
*/
|
|
109
|
+
idempotencyRetention?: Duration | number;
|
|
110
|
+
/**
|
|
111
|
+
* The journal retention for invocations to this handler.
|
|
112
|
+
*
|
|
113
|
+
* When a request has an idempotency key, `idempotencyRetention` caps the journal retention time.
|
|
114
|
+
*
|
|
115
|
+
* Note: Available only when registering this endpoint with restate-server v1.4 or newer; otherwise service discovery will fail.
|
|
116
|
+
*/
|
|
117
|
+
journalRetention?: Duration | number;
|
|
118
|
+
/**
|
|
119
|
+
* Guards against stalled invocations. Once this timeout expires, Restate requests a graceful
|
|
120
|
+
* suspension of the invocation (preserving intermediate progress).
|
|
121
|
+
*
|
|
122
|
+
* If the invocation does not react to the suspension request, `abortTimeout` is used to abort it.
|
|
123
|
+
*
|
|
124
|
+
* Overrides the inactivity timeout set at the service level and the default configured in the Restate server.
|
|
125
|
+
*
|
|
126
|
+
* Note: Available only when registering this endpoint with restate-server v1.4 or newer; otherwise service discovery will fail.
|
|
127
|
+
*/
|
|
128
|
+
inactivityTimeout?: Duration | number;
|
|
129
|
+
/**
|
|
130
|
+
* Guards against invocations that fail to terminate after inactivity.
|
|
131
|
+
* The abort timeout starts after `inactivityTimeout` expires and a graceful termination was requested.
|
|
132
|
+
* When this timer expires, the invocation is aborted.
|
|
133
|
+
*
|
|
134
|
+
* This timer may interrupt user code. If more time is needed for graceful termination, increase this value.
|
|
135
|
+
*
|
|
136
|
+
* Overrides the abort timeout set at the service level and the default configured in the Restate server.
|
|
137
|
+
*
|
|
138
|
+
* Note: Available only when registering this endpoint with restate-server v1.4 or newer; otherwise service discovery will fail.
|
|
139
|
+
*/
|
|
140
|
+
abortTimeout?: Duration | number;
|
|
141
|
+
/**
|
|
142
|
+
* When set to `true`, this handler cannot be invoked via the Restate server HTTP or Kafka ingress;
|
|
143
|
+
* it can only be called from other services.
|
|
144
|
+
*
|
|
145
|
+
* Note: Available only when registering this endpoint with restate-server v1.4 or newer; otherwise service discovery will fail.
|
|
146
|
+
*/
|
|
147
|
+
ingressPrivate?: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Retry policy to apply to all requests to this handler. For each unspecified field, the default value configured in the service or, if absent, in the restate-server configuration file, will be applied instead.
|
|
150
|
+
*/
|
|
151
|
+
retryPolicy?: RetryPolicy;
|
|
152
|
+
};
|
|
153
|
+
type ObjectHandlerOpts<I, O$1> = ServiceHandlerOpts<I, O$1> & {
|
|
154
|
+
/**
|
|
155
|
+
* When set to `true`, lazy state will be enabled for all invocations to this handler.
|
|
156
|
+
*
|
|
157
|
+
* *NOTE:* You can set this field only if you register this endpoint against restate-server >= 1.4,
|
|
158
|
+
* otherwise the service discovery will fail.
|
|
159
|
+
*/
|
|
160
|
+
enableLazyState?: boolean;
|
|
161
|
+
};
|
|
162
|
+
type WorkflowHandlerOpts<I, O$1> = ServiceHandlerOpts<I, O$1> & {
|
|
163
|
+
/**
|
|
164
|
+
* When set to `true`, lazy state will be enabled for all invocations to this handler.
|
|
165
|
+
*
|
|
166
|
+
* *NOTE:* You can set this field only if you register this endpoint against restate-server >= 1.4,
|
|
167
|
+
* otherwise the service discovery will fail.
|
|
168
|
+
*/
|
|
169
|
+
enableLazyState?: boolean;
|
|
170
|
+
};
|
|
171
|
+
type RemoveVoidArgument<F> = F extends ((ctx: infer C, arg: infer A) => infer R) ? A extends void ? (ctx: C) => R : F : F;
|
|
172
|
+
declare namespace handlers {
|
|
173
|
+
/**
|
|
174
|
+
* Create a service handler.
|
|
175
|
+
*
|
|
176
|
+
* @param opts additional configuration
|
|
177
|
+
* @param fn the actual handler code to execute
|
|
178
|
+
*/
|
|
179
|
+
function handler<O$1, I = void>(opts: ServiceHandlerOpts<I, O$1>, fn: (ctx: Context, input: I) => Promise<O$1>): RemoveVoidArgument<typeof fn>;
|
|
180
|
+
namespace workflow {
|
|
181
|
+
function workflow<O$1, I = void, TState extends TypedState = UntypedState>(opts: WorkflowHandlerOpts<I, O$1>, fn: (ctx: WorkflowContext<TState>, input: I) => Promise<O$1>): RemoveVoidArgument<typeof fn>;
|
|
182
|
+
function workflow<O$1, I = void, TState extends TypedState = UntypedState>(fn: (ctx: WorkflowContext<TState>, input: I) => Promise<O$1>): RemoveVoidArgument<typeof fn>;
|
|
183
|
+
/**
|
|
184
|
+
* Creates a shared handler for a workflow.
|
|
185
|
+
*
|
|
186
|
+
* A shared handler allows a read-only concurrent execution
|
|
187
|
+
* for a given key.
|
|
188
|
+
*
|
|
189
|
+
* @param opts additional configurations
|
|
190
|
+
* @param fn the handler to execute
|
|
191
|
+
*/
|
|
192
|
+
function shared<O$1, I = void, TState extends TypedState = UntypedState>(opts: WorkflowHandlerOpts<I, O$1>, fn: (ctx: WorkflowSharedContext<TState>, input: I) => Promise<O$1>): RemoveVoidArgument<typeof fn>;
|
|
193
|
+
/**
|
|
194
|
+
* Creates a shared handler for a workflow.
|
|
195
|
+
*
|
|
196
|
+
* A shared handler allows a read-only concurrent execution
|
|
197
|
+
* for a given key.
|
|
198
|
+
*
|
|
199
|
+
* @param opts additional configurations
|
|
200
|
+
* @param fn the handler to execute
|
|
201
|
+
*/
|
|
202
|
+
function shared<O$1, I = void, TState extends TypedState = UntypedState>(fn: (ctx: WorkflowSharedContext<TState>, input: I) => Promise<O$1>): RemoveVoidArgument<typeof fn>;
|
|
203
|
+
}
|
|
204
|
+
namespace object {
|
|
205
|
+
/**
|
|
206
|
+
* Creates an exclusive handler for a virtual Object.
|
|
207
|
+
*
|
|
208
|
+
* note : This applies only to a virtual object.
|
|
209
|
+
*
|
|
210
|
+
* @param opts additional configurations
|
|
211
|
+
* @param fn the handler to execute
|
|
212
|
+
*/
|
|
213
|
+
function exclusive<O$1, I = void, TState extends TypedState = UntypedState>(opts: ObjectHandlerOpts<I, O$1>, fn: (ctx: ObjectContext<TState>, input: I) => Promise<O$1>): RemoveVoidArgument<typeof fn>;
|
|
214
|
+
/**
|
|
215
|
+
* Creates an exclusive handler for a virtual Object.
|
|
216
|
+
*
|
|
217
|
+
*
|
|
218
|
+
* note 1: This applies only to a virtual object.
|
|
219
|
+
* note 2: This is the default for virtual objects, so if no
|
|
220
|
+
* additional reconfiguration is needed, you can simply
|
|
221
|
+
* use the handler directly (no need to use exclusive).
|
|
222
|
+
* This variant here is only for symmetry/convenance.
|
|
223
|
+
*
|
|
224
|
+
* @param fn the handler to execute
|
|
225
|
+
*/
|
|
226
|
+
function exclusive<O$1, I = void, TState extends TypedState = UntypedState>(fn: (ctx: ObjectContext<TState>, input: I) => Promise<O$1>): RemoveVoidArgument<typeof fn>;
|
|
227
|
+
/**
|
|
228
|
+
* Creates a shared handler for a virtual Object.
|
|
229
|
+
*
|
|
230
|
+
* A shared handler allows a read-only concurrent execution
|
|
231
|
+
* for a given key.
|
|
232
|
+
*
|
|
233
|
+
* note: This applies only to a virtual object.
|
|
234
|
+
*
|
|
235
|
+
* @param opts additional configurations
|
|
236
|
+
* @param fn the handler to execute
|
|
237
|
+
*/
|
|
238
|
+
function shared<O$1, I = void, TState extends TypedState = UntypedState>(opts: ObjectHandlerOpts<I, O$1>, fn: (ctx: ObjectSharedContext<TState>, input: I) => Promise<O$1>): RemoveVoidArgument<typeof fn>;
|
|
239
|
+
/**
|
|
240
|
+
* Creates a shared handler for a virtual Object.
|
|
241
|
+
*
|
|
242
|
+
* A shared handler allows a read-only concurrent execution
|
|
243
|
+
* for a given key.
|
|
244
|
+
*
|
|
245
|
+
* note: This applies only to a virtual object.
|
|
246
|
+
*
|
|
247
|
+
* @param opts additional configurations
|
|
248
|
+
* @param fn the handler to execute
|
|
249
|
+
*/
|
|
250
|
+
function shared<O$1, I = void, TState extends TypedState = UntypedState>(fn: (ctx: ObjectSharedContext<TState>, input: I) => Promise<O$1>): RemoveVoidArgument<typeof fn>;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
type ServiceOpts<U> = { [K in keyof U]: U[K] extends ServiceHandler<U[K], Context> ? U[K] : ServiceHandler<U[K], Context> };
|
|
254
|
+
type RetryPolicy = {
|
|
255
|
+
/**
|
|
256
|
+
* Max number of retry attempts (including the initial).
|
|
257
|
+
* When reached, the behavior specified in {@link onMaxAttempts} will be applied.
|
|
258
|
+
*/
|
|
259
|
+
maxAttempts?: number;
|
|
260
|
+
/**
|
|
261
|
+
* What to do when max attempts are reached.
|
|
262
|
+
*
|
|
263
|
+
* If `pause`, the invocation will enter the paused state and can be manually resumed from the CLI/UI.
|
|
264
|
+
*
|
|
265
|
+
* If `kill`, the invocation will get automatically killed.
|
|
266
|
+
*/
|
|
267
|
+
onMaxAttempts?: "pause" | "kill";
|
|
268
|
+
/**
|
|
269
|
+
* Initial interval for the first retry attempt.
|
|
270
|
+
* Retry interval will grow by a factor specified in `exponentiationFactor`.
|
|
271
|
+
*
|
|
272
|
+
* If a number is provided, it will be interpreted as milliseconds.
|
|
273
|
+
*/
|
|
274
|
+
initialInterval?: Duration | number;
|
|
275
|
+
/**
|
|
276
|
+
* Max interval between retries.
|
|
277
|
+
* Retry interval will grow by a factor specified in `exponentiationFactor`.
|
|
278
|
+
*
|
|
279
|
+
* If a number is provided, it will be interpreted as milliseconds.
|
|
280
|
+
*/
|
|
281
|
+
maxInterval?: Duration | number;
|
|
282
|
+
/**
|
|
283
|
+
* Exponentiation factor to use when computing the next retry delay.
|
|
284
|
+
*/
|
|
285
|
+
exponentiationFactor?: number;
|
|
286
|
+
};
|
|
287
|
+
type ServiceOptions = {
|
|
288
|
+
/**
|
|
289
|
+
* The retention duration of idempotent requests to this service.
|
|
290
|
+
*
|
|
291
|
+
* Note: Available only when registering this endpoint with restate-server v1.4 or newer; otherwise service discovery will fail.
|
|
292
|
+
*/
|
|
293
|
+
idempotencyRetention?: Duration | number;
|
|
294
|
+
/**
|
|
295
|
+
* Journal retention applied to all requests to all handlers of this service.
|
|
296
|
+
*
|
|
297
|
+
* When a request includes an idempotency key, `idempotencyRetention` caps the journal retention time.
|
|
298
|
+
*
|
|
299
|
+
* Note: Available only when registering this endpoint with restate-server v1.4 or newer; otherwise service discovery will fail.
|
|
300
|
+
*/
|
|
301
|
+
journalRetention?: Duration | number;
|
|
302
|
+
/**
|
|
303
|
+
* Guards against stalled invocations. Once this timeout expires, Restate requests a graceful
|
|
304
|
+
* suspension of the invocation (preserving intermediate progress).
|
|
305
|
+
*
|
|
306
|
+
* If the invocation does not react to the suspension request, `abortTimeout` is used to abort it.
|
|
307
|
+
*
|
|
308
|
+
* Overrides the default inactivity timeout configured in the Restate server for all invocations to this service.
|
|
309
|
+
*
|
|
310
|
+
* Note: Available only when registering this endpoint with restate-server v1.4 or newer; otherwise service discovery will fail.
|
|
311
|
+
*/
|
|
312
|
+
inactivityTimeout?: Duration | number;
|
|
313
|
+
/**
|
|
314
|
+
* Guards against invocations that fail to terminate after inactivity.
|
|
315
|
+
* The abort timeout starts after `inactivityTimeout` expires and a graceful termination was requested.
|
|
316
|
+
* When this timer expires, the invocation is aborted.
|
|
317
|
+
*
|
|
318
|
+
* This timer may interrupt user code. If more time is needed for graceful termination, increase this value.
|
|
319
|
+
*
|
|
320
|
+
* Overrides the default abort timeout configured in the Restate server for invocations to this service.
|
|
321
|
+
*
|
|
322
|
+
* Note: Available only when registering this endpoint with restate-server v1.4 or newer; otherwise service discovery will fail.
|
|
323
|
+
*/
|
|
324
|
+
abortTimeout?: Duration | number;
|
|
325
|
+
/**
|
|
326
|
+
* When set to `true`, this service (and all its handlers) cannot be invoked via the Restate server
|
|
327
|
+
* HTTP or Kafka ingress; it can only be called from other services.
|
|
328
|
+
*
|
|
329
|
+
* Note: Available only when registering this endpoint with restate-server v1.4 or newer; otherwise service discovery will fail.
|
|
330
|
+
*/
|
|
331
|
+
ingressPrivate?: boolean;
|
|
332
|
+
/**
|
|
333
|
+
* Retry policy to apply to all requests to this service. For each unspecified field, the default value configured in the restate-server configuration file will be applied instead.
|
|
334
|
+
*/
|
|
335
|
+
retryPolicy?: RetryPolicy;
|
|
336
|
+
/**
|
|
337
|
+
* By default, Restate treats errors as terminal (non-retryable) only when they are instances of `TerminalError`.
|
|
338
|
+
*
|
|
339
|
+
* Use this hook to map domain-specific errors to `TerminalError` (or return `undefined` to keep them retryable).
|
|
340
|
+
* When mapped to `TerminalError`, the error will not be retried.
|
|
341
|
+
*
|
|
342
|
+
* Note: This applies to errors thrown inside `ctx.run` closures as well as errors thrown by Restate handlers.
|
|
343
|
+
*
|
|
344
|
+
* Example:
|
|
345
|
+
*
|
|
346
|
+
* ```ts
|
|
347
|
+
* class MyValidationError extends Error {}
|
|
348
|
+
*
|
|
349
|
+
* const greeter = restate.service({
|
|
350
|
+
* name: "greeter",
|
|
351
|
+
* handlers: {
|
|
352
|
+
* greet: async (ctx: restate.Context, name: string) => {
|
|
353
|
+
* if (name.length === 0) {
|
|
354
|
+
* throw new MyValidationError("Length too short");
|
|
355
|
+
* }
|
|
356
|
+
* return `Hello ${name}`;
|
|
357
|
+
* }
|
|
358
|
+
* },
|
|
359
|
+
* options: {
|
|
360
|
+
* asTerminalError: (err) => {
|
|
361
|
+
* if (err instanceof MyValidationError) {
|
|
362
|
+
* // My validation error is terminal
|
|
363
|
+
* return new restate.TerminalError(err.message, { errorCode: 400 });
|
|
364
|
+
* }
|
|
365
|
+
*
|
|
366
|
+
* // Any other error is retryable
|
|
367
|
+
* }
|
|
368
|
+
* }
|
|
369
|
+
* });
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
asTerminalError?: (error: any) => TerminalError | undefined;
|
|
373
|
+
/**
|
|
374
|
+
* Default serde to use for requests, responses, state, side effects, awakeables, promises. Used when no other serde is specified.
|
|
375
|
+
*
|
|
376
|
+
* If not provided, defaults to `serde.json`.
|
|
377
|
+
*/
|
|
378
|
+
serde?: Serde<any>;
|
|
379
|
+
};
|
|
380
|
+
/**
|
|
381
|
+
* Define a Restate service.
|
|
382
|
+
*
|
|
383
|
+
* @example Here is an example of how to define a service:
|
|
384
|
+
*
|
|
385
|
+
* ```ts
|
|
386
|
+
* const greeter = service({
|
|
387
|
+
* name: "greeter",
|
|
388
|
+
* handlers: {
|
|
389
|
+
* greet: async (ctx: Context, name: string) => {
|
|
390
|
+
* return `Hello ${name}`;
|
|
391
|
+
* }
|
|
392
|
+
* }
|
|
393
|
+
* });
|
|
394
|
+
* ```
|
|
395
|
+
*
|
|
396
|
+
* To use the service, you can bind it to an endpoint:
|
|
397
|
+
* ```
|
|
398
|
+
* ...
|
|
399
|
+
* endpoint.bind(greeter)
|
|
400
|
+
* ```
|
|
401
|
+
* @example To use a service, you can export its type to be used in a client:
|
|
402
|
+
* ```
|
|
403
|
+
* export type Greeter = typeof greeter;
|
|
404
|
+
* ...
|
|
405
|
+
* ...
|
|
406
|
+
* import type { Greeter } from "./greeter";
|
|
407
|
+
* const client = ctx.serviceClient<Greeter>({ name : "greeter"});
|
|
408
|
+
* client.greet("World").then(console.log);
|
|
409
|
+
* ```
|
|
410
|
+
*
|
|
411
|
+
* @example Alternatively to avoid repeating the service name, you can:
|
|
412
|
+
* ```
|
|
413
|
+
* import type {Greeter} from "./greeter";
|
|
414
|
+
* const Greeter: Greeter = { name : "greeter"};
|
|
415
|
+
*
|
|
416
|
+
* // now you can reference the service like this:
|
|
417
|
+
* const client = ctx.serviceClient(Greeter);
|
|
418
|
+
* ```
|
|
419
|
+
*
|
|
420
|
+
* @param name the service name
|
|
421
|
+
* @param handlers the handlers for the service
|
|
422
|
+
* @param description an optional description for the service
|
|
423
|
+
* @param metadata an optional metadata for the service
|
|
424
|
+
* @type P the name of the service
|
|
425
|
+
* @type M the handlers for the service
|
|
426
|
+
*/
|
|
427
|
+
declare const service: <P$1 extends string, M>(service: {
|
|
428
|
+
name: P$1;
|
|
429
|
+
handlers: ServiceOpts<M> & ThisType<M>;
|
|
430
|
+
description?: string;
|
|
431
|
+
metadata?: Record<string, string>;
|
|
432
|
+
options?: ServiceOptions;
|
|
433
|
+
}) => ServiceDefinition<P$1, M>;
|
|
434
|
+
type ObjectOpts<U> = { [K in keyof U]: U[K] extends ObjectHandler<U[K], ObjectContext<any>> ? U[K] : U[K] extends ObjectHandler<U[K], ObjectSharedContext<any>> ? U[K] : ObjectHandler<U[K], ObjectContext<any>> | ObjectHandler<U[K], ObjectSharedContext<any>> };
|
|
435
|
+
type ObjectOptions = ServiceOptions & {
|
|
436
|
+
/**
|
|
437
|
+
* When set to `true`, lazy state will be enabled for all invocations to this service.
|
|
438
|
+
*
|
|
439
|
+
* *NOTE:* You can set this field only if you register this endpoint against restate-server >= 1.4,
|
|
440
|
+
* otherwise the service discovery will fail.
|
|
441
|
+
*/
|
|
442
|
+
enableLazyState?: boolean;
|
|
443
|
+
};
|
|
444
|
+
/**
|
|
445
|
+
* Define a Restate virtual object.
|
|
446
|
+
*
|
|
447
|
+
* @example Here is an example of how to define a virtual object:
|
|
448
|
+
* ```ts
|
|
449
|
+
* const counter = object({
|
|
450
|
+
* name: "counter",
|
|
451
|
+
* handlers: {
|
|
452
|
+
* add: async (ctx: ObjectContext, amount: number) => {},
|
|
453
|
+
* get: async (ctx: ObjectContext) => {}
|
|
454
|
+
* }
|
|
455
|
+
* })
|
|
456
|
+
* ```
|
|
457
|
+
*
|
|
458
|
+
* @example To use the object, you can bind it to an endpoint:
|
|
459
|
+
* ```ts
|
|
460
|
+
* ...
|
|
461
|
+
* endpoint.bind(counter)
|
|
462
|
+
* ```
|
|
463
|
+
*
|
|
464
|
+
* @see to interact with the object, you can use the object client:
|
|
465
|
+
* ```ts
|
|
466
|
+
* ...
|
|
467
|
+
* const client = ctx.objectClient<typeof counter>({ name: "counter"});
|
|
468
|
+
* const res = await client.add(1)
|
|
469
|
+
* ```
|
|
470
|
+
*
|
|
471
|
+
* ### Shared handlers
|
|
472
|
+
*
|
|
473
|
+
* Shared handlers are used to allow concurrent read-only access to the object.
|
|
474
|
+
* This is useful when you want to allow multiple clients to read the object's state at the same time.
|
|
475
|
+
* To define a shared handler, you can use the `shared` decorator as shown below:
|
|
476
|
+
*
|
|
477
|
+
* ```ts
|
|
478
|
+
* const counter = object({
|
|
479
|
+
* name: "counter",
|
|
480
|
+
* handlers: {
|
|
481
|
+
*
|
|
482
|
+
* add: async (ctx: ObjectContext, amount: number) => { .. },
|
|
483
|
+
*
|
|
484
|
+
* get: handlers.object.shared(async (ctx: ObjectSharedContext) => {
|
|
485
|
+
* return ctx.get<number>("count");
|
|
486
|
+
* })
|
|
487
|
+
* }
|
|
488
|
+
* });
|
|
489
|
+
* ```
|
|
490
|
+
*
|
|
491
|
+
* @param name the name of the object
|
|
492
|
+
* @param handlers the handlers for the object
|
|
493
|
+
* @param description an optional description for the object
|
|
494
|
+
* @param metadata an optional metadata for the object
|
|
495
|
+
* @type P the name of the object
|
|
496
|
+
* @type M the handlers for the object
|
|
497
|
+
*/
|
|
498
|
+
declare const object: <P$1 extends string, M>(object: {
|
|
499
|
+
name: P$1;
|
|
500
|
+
handlers: ObjectOpts<M> & ThisType<M>;
|
|
501
|
+
description?: string;
|
|
502
|
+
metadata?: Record<string, string>;
|
|
503
|
+
options?: ObjectOptions;
|
|
504
|
+
}) => VirtualObjectDefinition<P$1, M>;
|
|
505
|
+
/**
|
|
506
|
+
* A workflow handlers is a type that describes the handlers for a workflow.
|
|
507
|
+
* The handlers must contain exactly one handler named 'run', and this handler must accept as a first argument a WorkflowContext.
|
|
508
|
+
* It can contain any number of additional handlers, which must accept as a first argument a WorkflowSharedContext.
|
|
509
|
+
* The handlers can not be named 'workflowSubmit', 'workflowAttach', 'workflowOutput' - as these are reserved.
|
|
510
|
+
* @see {@link workflow} for an example.
|
|
511
|
+
*/
|
|
512
|
+
type WorkflowOpts<U> = {
|
|
513
|
+
run: (ctx: WorkflowContext<any>, argument: any) => Promise<any>;
|
|
514
|
+
} & { [K in keyof U]: K extends "workflowSubmit" | "workflowAttach" | "workflowOutput" ? `${K} is a reserved keyword` : K extends "run" ? U[K] extends WorkflowHandler<U[K], WorkflowContext<any>> ? U[K] : "An handler named 'run' must take as a first argument a WorkflowContext, and must return a Promise" : U[K] extends WorkflowSharedHandler<U[K], WorkflowSharedContext<any>> ? U[K] : "An handler other then 'run' must accept as a first argument a WorkflowSharedContext" };
|
|
515
|
+
type WorkflowOptions = ServiceOptions & {
|
|
516
|
+
/**
|
|
517
|
+
* The retention duration for this workflow.
|
|
518
|
+
*
|
|
519
|
+
* *NOTE:* You can set this field only if you register this endpoint against restate-server >= 1.4,
|
|
520
|
+
* otherwise the service discovery will fail.
|
|
521
|
+
*/
|
|
522
|
+
workflowRetention?: Duration | number;
|
|
523
|
+
/**
|
|
524
|
+
* When set to `true`, lazy state will be enabled for all invocations to this service.
|
|
525
|
+
*
|
|
526
|
+
* *NOTE:* You can set this field only if you register this endpoint against restate-server >= 1.4,
|
|
527
|
+
* otherwise the service discovery will fail.
|
|
528
|
+
*/
|
|
529
|
+
enableLazyState?: boolean;
|
|
530
|
+
};
|
|
531
|
+
/**
|
|
532
|
+
* Define a Restate workflow.
|
|
533
|
+
*
|
|
534
|
+
*
|
|
535
|
+
* @example Here is an example of how to define a workflow:
|
|
536
|
+
* ```ts
|
|
537
|
+
* const mywf = workflow({
|
|
538
|
+
* name: "mywf",
|
|
539
|
+
* handlers: {
|
|
540
|
+
* run: async (ctx: WorkflowContext, argument: any) => {
|
|
541
|
+
* return "Hello World";
|
|
542
|
+
* }
|
|
543
|
+
* }
|
|
544
|
+
* });
|
|
545
|
+
* ```
|
|
546
|
+
*
|
|
547
|
+
* ### Note:
|
|
548
|
+
* * That a workflow must contain exactly one handler named 'run', and this handler must accept as a first argument a WorkflowContext.
|
|
549
|
+
* * The workflow handlers other than 'run' must accept as a first argument a WorkflowSharedContext.
|
|
550
|
+
* * The workflow handlers can not be named 'workflowSubmit', 'workflowAttach', 'workflowOutput' - as these are reserved keywords.
|
|
551
|
+
*
|
|
552
|
+
* @example To use the workflow, you can bind it to an endpoint:
|
|
553
|
+
* ```ts
|
|
554
|
+
* endpoint.bind(mywf)
|
|
555
|
+
* ```
|
|
556
|
+
*
|
|
557
|
+
* @example To interact with the workflow, you can use the workflow client:
|
|
558
|
+
* ```ts
|
|
559
|
+
* const client = ctx.workflowClient<typeof mywf>({ name: "mywf"});
|
|
560
|
+
* const res = await client.run("Hello");
|
|
561
|
+
* ```
|
|
562
|
+
*
|
|
563
|
+
* To use the workflow client from any other environment (like a browser), please refer to the documentation.
|
|
564
|
+
* https://docs.restate.dev
|
|
565
|
+
*
|
|
566
|
+
*
|
|
567
|
+
*
|
|
568
|
+
* @param name the workflow name
|
|
569
|
+
* @param handlers the handlers for the workflow.
|
|
570
|
+
*/
|
|
571
|
+
declare const workflow: <P$1 extends string, M>(workflow: {
|
|
572
|
+
name: P$1;
|
|
573
|
+
handlers: WorkflowOpts<M> & ThisType<M>;
|
|
574
|
+
description?: string;
|
|
575
|
+
metadata?: Record<string, string>;
|
|
576
|
+
options?: WorkflowOptions;
|
|
577
|
+
}) => WorkflowDefinition<P$1, M>;
|
|
578
|
+
//#endregion
|
|
579
|
+
export { Client, ClientCallOptions, ClientSendOptions, InferArg, ObjectHandlerOpts, ObjectOptions, ObjectOpts, Opts, RemoveVoidArgument, RetryPolicy, SendClient, SendOpts, ServiceHandlerOpts, ServiceOptions, ServiceOpts, WorkflowHandlerOpts, WorkflowOptions, WorkflowOpts, handlers, object, rpc, service, workflow };
|
|
580
|
+
//# sourceMappingURL=rpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rpc.d.ts","names":[],"sources":["../../src/types/rpc.ts"],"sourcesContent":[],"mappings":";;;;;KA6CY;UACF,MAAM;EADJ,MAAA,CAAA,EAED,KAFC,CAEK,GAFL,CAAA;EACI,OAAA,CAAA,EAEJ,MAFI,CAAA,MAAA,EAAA,MAAA,CAAA;EAAN,cAAA,CAAA,EAAA,MAAA;CACO;AAAN,cAKE,IALF,CAAA,CAAA,EAAA,GAAA,CAAA,CAAA;EACC,iBAAA,IAAA;EAAM;AAIlB;;;;EAMgE,OAAA,IAAA,CAAA,CAAA,EAAA,GAAA,CAAA,CAAA,IAAA,EAA/B,iBAA+B,CAAb,CAAa,EAAV,GAAU,CAAA,CAAA,EAAL,IAAK,CAAA,CAAA,EAAG,GAAH,CAAA;EAAG,QAAA,WAAA,CAAA;EAAR,OAAA,CAAA,CAAA,EAMvC,iBANuC,CAMrB,CANqB,EAMlB,GANkB,CAAA;;AAMlB,KAK7B,iBAL6B,CAAA,CAAA,CAAA,GAAA;EAArB,KAAA,CAAA,EAMV,KANU,CAMJ,CANI,CAAA;EAAiB;AAKrC;;;;;;AAgCA;;;;;;;;AAYA;;;;;;;;;;EAGwD,KAAA,CAAA,EApB9C,QAoB8C,GAAA,MAAA;EAAA,OAAA,CAAA,EAnB5C,MAmB4C,CAAA,MAAA,EAAA,MAAA,CAAA;EA4H5C,cAAQ,CAAA,EAAA,MAAA;AAEpB,CAAA;AACc,cA9ID,QA8IC,CAAA,CAAA,CAAA,CAAA;EAAK,iBAAA,IAAA;EAAE,OAAA,IAAA,CAAA,CAAA,CAAA,CAAA,IAAA,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