@restatedev/restate-sdk-clients 1.16.9 → 1.17.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/dist/api.d.cts +36 -5
- package/dist/api.d.cts.map +1 -1
- package/dist/api.d.ts +36 -5
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/ingress.cjs +42 -24
- package/dist/ingress.d.cts.map +1 -1
- package/dist/ingress.d.ts.map +1 -1
- package/dist/ingress.js +42 -24
- package/dist/ingress.js.map +1 -1
- package/package.json +2 -2
package/dist/api.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Duration, JournalValueCodec, Serde, Service, ServiceDefinitionFrom, VirtualObject, VirtualObjectDefinitionFrom, Workflow, WorkflowDefinitionFrom } from "@restatedev/restate-sdk-core";
|
|
1
|
+
import { Duration, HandlerDescriptor, InferInput, InferOutput, JournalValueCodec, ObjectDescriptor, Serde, Service, ServiceDefinitionFrom, ServiceDescriptor, VirtualObject, VirtualObjectDefinitionFrom, Workflow, WorkflowDefinitionFrom, WorkflowDescriptor } from "@restatedev/restate-sdk-core";
|
|
2
2
|
|
|
3
3
|
//#region src/api.d.ts
|
|
4
4
|
|
|
@@ -28,13 +28,35 @@ interface Ingress {
|
|
|
28
28
|
*/
|
|
29
29
|
objectClient<D>(opts: VirtualObjectDefinitionFrom<D>, key: string): IngressClient<VirtualObject<D>>;
|
|
30
30
|
/**
|
|
31
|
-
* Create a client from a {@link ServiceDefinition}.
|
|
31
|
+
* Create a send client from a {@link ServiceDefinition}.
|
|
32
32
|
*/
|
|
33
33
|
serviceSendClient<D>(opts: ServiceDefinitionFrom<D>): IngressSendClient<Service<D>>;
|
|
34
34
|
/**
|
|
35
|
-
* Create a client from a {@link VirtualObjectDefinition}.
|
|
35
|
+
* Create a send client from a {@link VirtualObjectDefinition}.
|
|
36
36
|
*/
|
|
37
37
|
objectSendClient<D>(opts: VirtualObjectDefinitionFrom<D>, key: string): IngressSendClient<VirtualObject<D>>;
|
|
38
|
+
/**
|
|
39
|
+
* Create a request/response client from a service interface / `Descriptor`.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* ingress.client(greeter).greet(req); // service
|
|
44
|
+
* ingress.client(counter, "k").add(1); // virtual object / workflow
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
client<P$1 extends string, H extends Record<string, HandlerDescriptor>>(serviceInterface: ServiceDescriptor<P$1, H>): IngressClientFromDescriptors<H>;
|
|
48
|
+
client<P$1 extends string, H extends Record<string, HandlerDescriptor>>(objectOrWorkflowInterface: ObjectDescriptor<P$1, H> | WorkflowDescriptor<P$1, H>, key: string): IngressClientFromDescriptors<H>;
|
|
49
|
+
/**
|
|
50
|
+
* Send-client (one-way) counterpart of {@link Ingress.client}.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* ingress.sendClient(greeter).greet(req);
|
|
55
|
+
* ingress.sendClient(counter, "k").add(1);
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
sendClient<P$1 extends string, H extends Record<string, HandlerDescriptor>>(serviceInterface: ServiceDescriptor<P$1, H>): IngressSendClientFromDescriptors<H>;
|
|
59
|
+
sendClient<P$1 extends string, H extends Record<string, HandlerDescriptor>>(objectOrWorkflowInterface: ObjectDescriptor<P$1, H> | WorkflowDescriptor<P$1, H>, key: string): IngressSendClientFromDescriptors<H>;
|
|
38
60
|
/**
|
|
39
61
|
* Resolve an awakeable from the ingress client.
|
|
40
62
|
*/
|
|
@@ -141,7 +163,7 @@ interface Ingress {
|
|
|
141
163
|
* @experimental
|
|
142
164
|
* @interface
|
|
143
165
|
*/
|
|
144
|
-
type ScopedIngress = Pick<Ingress, "serviceClient" | "serviceSendClient" | "objectClient" | "objectSendClient" | "workflowClient">;
|
|
166
|
+
type ScopedIngress = Pick<Ingress, "serviceClient" | "serviceSendClient" | "objectClient" | "objectSendClient" | "workflowClient" | "client" | "sendClient">;
|
|
145
167
|
interface IngressCallOptions<I$1 = unknown, O$1 = unknown> {
|
|
146
168
|
/**
|
|
147
169
|
* Key to use for idempotency key.
|
|
@@ -218,6 +240,15 @@ declare class SendOpts<I$1 = unknown> {
|
|
|
218
240
|
}
|
|
219
241
|
type InferArgType<P$1> = P$1 extends [infer A, ...any[]] ? A : unknown;
|
|
220
242
|
type IngressClient<M> = { [K in keyof M as M[K] extends never ? never : K]: M[K] extends ((arg: any, ...args: infer P) => PromiseLike<infer O>) ? (...args: [...P, ...[opts?: Opts<InferArgType<P>, O>]]) => PromiseLike<O> : never };
|
|
243
|
+
/**
|
|
244
|
+
* Typed ingress request/response client derived from a service interface's
|
|
245
|
+
* handler descriptor map `H` (see `iface` in `@restatedev/restate-sdk-core`).
|
|
246
|
+
* Recovers the input/output types directly from the descriptors, so a code-free
|
|
247
|
+
* interface value produces a fully typed client that reuses the declared serdes.
|
|
248
|
+
*/
|
|
249
|
+
type IngressClientFromDescriptors<H extends Record<string, HandlerDescriptor>> = { readonly [K in keyof H]: [InferInput<H[K]>] extends [void] ? (opts?: Opts<InferInput<H[K]>, InferOutput<H[K]>>) => Promise<InferOutput<H[K]>> : (input: InferInput<H[K]>, opts?: Opts<InferInput<H[K]>, InferOutput<H[K]>>) => Promise<InferOutput<H[K]>> };
|
|
250
|
+
/** One-way (send) counterpart of {@link IngressClientFromDescriptors}. */
|
|
251
|
+
type IngressSendClientFromDescriptors<H extends Record<string, HandlerDescriptor>> = { readonly [K in keyof H]: [InferInput<H[K]>] extends [void] ? (opts?: SendOpts<InferInput<H[K]>>) => Promise<Send<InferOutput<H[K]>>> : (input: InferInput<H[K]>, opts?: SendOpts<InferInput<H[K]>>) => Promise<Send<InferOutput<H[K]>>> };
|
|
221
252
|
declare namespace rpc {
|
|
222
253
|
const opts: <I$1, O$1>(opts: IngressCallOptions<I$1, O$1>) => Opts<I$1, O$1>;
|
|
223
254
|
const sendOpts: <I$1>(opts: IngressSendOptions<I$1>) => SendOpts<I$1>;
|
|
@@ -481,5 +512,5 @@ type ConnectionOpts = {
|
|
|
481
512
|
fetch?: typeof globalThis.fetch;
|
|
482
513
|
};
|
|
483
514
|
//#endregion
|
|
484
|
-
export { ConnectionOpts, InferArgType, Ingress, IngressCallOptions, IngressClient, IngressSendClient, IngressSendOptions, IngressWorkflowClient, Opts, Output, RetryFailure, RetryPolicy, ScopedIngress, Send, SendOpts, WorkflowSubmission, rpc };
|
|
515
|
+
export { ConnectionOpts, InferArgType, Ingress, IngressCallOptions, IngressClient, IngressClientFromDescriptors, IngressSendClient, IngressSendClientFromDescriptors, IngressSendOptions, IngressWorkflowClient, Opts, Output, RetryFailure, RetryPolicy, ScopedIngress, Send, SendOpts, WorkflowSubmission, rpc };
|
|
485
516
|
//# sourceMappingURL=api.d.cts.map
|
package/dist/api.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.cts","names":[],"sources":["../src/api.ts"],"sourcesContent":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"api.d.cts","names":[],"sources":["../src/api.ts"],"sourcesContent":[],"mappings":";;;;;;AA8BA;;;;;;;AAYU,UAZO,OAAA,CAYP;EAE0B;;;EAOE,aAAA,CAAA,CAAA,CAAA,CAAA,IAAA,EAjBb,qBAiBa,CAjBS,CAiBT,CAAA,CAAA,EAjBc,aAiBd,CAjB4B,OAiB5B,CAjBoC,CAiBpC,CAAA,CAAA;EAA5B;;;;;EAQA,cAAA,CAAA,CAAA,CAAA,CAAA,IAAA,EAjBA,sBAiBA,CAjBuB,CAiBvB,CAAA,EAAA,GAAA,EAAA,MAAA,CAAA,EAfL,qBAeK,CAfiB,QAejB,CAf0B,CAe1B,CAAA,CAAA;EACqB;;;;EAMrB,YAAA,CAAA,CAA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;kBAgBxB,UAAU,0BACtB,oCAAmC,4BACzB,WAAW,OAAO,QAAQ,OAAO;;;;;;;KAavC;;;;;;;;;;;KAcA,qCACE,KAAK,EAAE,2BAA2B,IAAI,EAAE,4CAG/C,sCAEc,cAAc,SAAS,aAAa,UAC9C,QAAQ,KAAK;;;;;;;KAUZ,YAAA;;;;;;;;oBAUY;;;;;;;;;;;;;;;;;;;;;;UAuBP,WAAA;;;;;;;;;;;;;;;;;;;;;gBAsBD;;;;;oBAMI;;;;;gBAMJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAoCU;;KAGd,cAAA;;;;;;;;;;YAUA;;;;;;;;;;;;;;;;;UAkBF;;;;;;;;UASA;;;;;;sBAOY;;;;;;;;iBASL,UAAA,CAAW"}
|
package/dist/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Duration, JournalValueCodec, Serde, Service, ServiceDefinitionFrom, VirtualObject, VirtualObjectDefinitionFrom, Workflow, WorkflowDefinitionFrom } from "@restatedev/restate-sdk-core";
|
|
1
|
+
import { Duration, HandlerDescriptor, InferInput, InferOutput, JournalValueCodec, ObjectDescriptor, Serde, Service, ServiceDefinitionFrom, ServiceDescriptor, VirtualObject, VirtualObjectDefinitionFrom, Workflow, WorkflowDefinitionFrom, WorkflowDescriptor } from "@restatedev/restate-sdk-core";
|
|
2
2
|
|
|
3
3
|
//#region src/api.d.ts
|
|
4
4
|
|
|
@@ -28,13 +28,35 @@ interface Ingress {
|
|
|
28
28
|
*/
|
|
29
29
|
objectClient<D>(opts: VirtualObjectDefinitionFrom<D>, key: string): IngressClient<VirtualObject<D>>;
|
|
30
30
|
/**
|
|
31
|
-
* Create a client from a {@link ServiceDefinition}.
|
|
31
|
+
* Create a send client from a {@link ServiceDefinition}.
|
|
32
32
|
*/
|
|
33
33
|
serviceSendClient<D>(opts: ServiceDefinitionFrom<D>): IngressSendClient<Service<D>>;
|
|
34
34
|
/**
|
|
35
|
-
* Create a client from a {@link VirtualObjectDefinition}.
|
|
35
|
+
* Create a send client from a {@link VirtualObjectDefinition}.
|
|
36
36
|
*/
|
|
37
37
|
objectSendClient<D>(opts: VirtualObjectDefinitionFrom<D>, key: string): IngressSendClient<VirtualObject<D>>;
|
|
38
|
+
/**
|
|
39
|
+
* Create a request/response client from a service interface / `Descriptor`.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* ingress.client(greeter).greet(req); // service
|
|
44
|
+
* ingress.client(counter, "k").add(1); // virtual object / workflow
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
client<P$1 extends string, H extends Record<string, HandlerDescriptor>>(serviceInterface: ServiceDescriptor<P$1, H>): IngressClientFromDescriptors<H>;
|
|
48
|
+
client<P$1 extends string, H extends Record<string, HandlerDescriptor>>(objectOrWorkflowInterface: ObjectDescriptor<P$1, H> | WorkflowDescriptor<P$1, H>, key: string): IngressClientFromDescriptors<H>;
|
|
49
|
+
/**
|
|
50
|
+
* Send-client (one-way) counterpart of {@link Ingress.client}.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* ingress.sendClient(greeter).greet(req);
|
|
55
|
+
* ingress.sendClient(counter, "k").add(1);
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
sendClient<P$1 extends string, H extends Record<string, HandlerDescriptor>>(serviceInterface: ServiceDescriptor<P$1, H>): IngressSendClientFromDescriptors<H>;
|
|
59
|
+
sendClient<P$1 extends string, H extends Record<string, HandlerDescriptor>>(objectOrWorkflowInterface: ObjectDescriptor<P$1, H> | WorkflowDescriptor<P$1, H>, key: string): IngressSendClientFromDescriptors<H>;
|
|
38
60
|
/**
|
|
39
61
|
* Resolve an awakeable from the ingress client.
|
|
40
62
|
*/
|
|
@@ -141,7 +163,7 @@ interface Ingress {
|
|
|
141
163
|
* @experimental
|
|
142
164
|
* @interface
|
|
143
165
|
*/
|
|
144
|
-
type ScopedIngress = Pick<Ingress, "serviceClient" | "serviceSendClient" | "objectClient" | "objectSendClient" | "workflowClient">;
|
|
166
|
+
type ScopedIngress = Pick<Ingress, "serviceClient" | "serviceSendClient" | "objectClient" | "objectSendClient" | "workflowClient" | "client" | "sendClient">;
|
|
145
167
|
interface IngressCallOptions<I$1 = unknown, O$1 = unknown> {
|
|
146
168
|
/**
|
|
147
169
|
* Key to use for idempotency key.
|
|
@@ -218,6 +240,15 @@ declare class SendOpts<I$1 = unknown> {
|
|
|
218
240
|
}
|
|
219
241
|
type InferArgType<P$1> = P$1 extends [infer A, ...any[]] ? A : unknown;
|
|
220
242
|
type IngressClient<M> = { [K in keyof M as M[K] extends never ? never : K]: M[K] extends ((arg: any, ...args: infer P) => PromiseLike<infer O>) ? (...args: [...P, ...[opts?: Opts<InferArgType<P>, O>]]) => PromiseLike<O> : never };
|
|
243
|
+
/**
|
|
244
|
+
* Typed ingress request/response client derived from a service interface's
|
|
245
|
+
* handler descriptor map `H` (see `iface` in `@restatedev/restate-sdk-core`).
|
|
246
|
+
* Recovers the input/output types directly from the descriptors, so a code-free
|
|
247
|
+
* interface value produces a fully typed client that reuses the declared serdes.
|
|
248
|
+
*/
|
|
249
|
+
type IngressClientFromDescriptors<H extends Record<string, HandlerDescriptor>> = { readonly [K in keyof H]: [InferInput<H[K]>] extends [void] ? (opts?: Opts<InferInput<H[K]>, InferOutput<H[K]>>) => Promise<InferOutput<H[K]>> : (input: InferInput<H[K]>, opts?: Opts<InferInput<H[K]>, InferOutput<H[K]>>) => Promise<InferOutput<H[K]>> };
|
|
250
|
+
/** One-way (send) counterpart of {@link IngressClientFromDescriptors}. */
|
|
251
|
+
type IngressSendClientFromDescriptors<H extends Record<string, HandlerDescriptor>> = { readonly [K in keyof H]: [InferInput<H[K]>] extends [void] ? (opts?: SendOpts<InferInput<H[K]>>) => Promise<Send<InferOutput<H[K]>>> : (input: InferInput<H[K]>, opts?: SendOpts<InferInput<H[K]>>) => Promise<Send<InferOutput<H[K]>>> };
|
|
221
252
|
declare namespace rpc {
|
|
222
253
|
const opts: <I$1, O$1>(opts: IngressCallOptions<I$1, O$1>) => Opts<I$1, O$1>;
|
|
223
254
|
const sendOpts: <I$1>(opts: IngressSendOptions<I$1>) => SendOpts<I$1>;
|
|
@@ -481,5 +512,5 @@ type ConnectionOpts = {
|
|
|
481
512
|
fetch?: typeof globalThis.fetch;
|
|
482
513
|
};
|
|
483
514
|
//#endregion
|
|
484
|
-
export { ConnectionOpts, InferArgType, Ingress, IngressCallOptions, IngressClient, IngressSendClient, IngressSendOptions, IngressWorkflowClient, Opts, Output, RetryFailure, RetryPolicy, ScopedIngress, Send, SendOpts, WorkflowSubmission, rpc };
|
|
515
|
+
export { ConnectionOpts, InferArgType, Ingress, IngressCallOptions, IngressClient, IngressClientFromDescriptors, IngressSendClient, IngressSendClientFromDescriptors, IngressSendOptions, IngressWorkflowClient, Opts, Output, RetryFailure, RetryPolicy, ScopedIngress, Send, SendOpts, WorkflowSubmission, rpc };
|
|
485
516
|
//# sourceMappingURL=api.d.ts.map
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","names":[],"sources":["../src/api.ts"],"sourcesContent":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"api.d.ts","names":[],"sources":["../src/api.ts"],"sourcesContent":[],"mappings":";;;;;;AA8BA;;;;;;;AAYU,UAZO,OAAA,CAYP;EAE0B;;;EAOE,aAAA,CAAA,CAAA,CAAA,CAAA,IAAA,EAjBb,qBAiBa,CAjBS,CAiBT,CAAA,CAAA,EAjBc,aAiBd,CAjB4B,OAiB5B,CAjBoC,CAiBpC,CAAA,CAAA;EAA5B;;;;;EAQA,cAAA,CAAA,CAAA,CAAA,CAAA,IAAA,EAjBA,sBAiBA,CAjBuB,CAiBvB,CAAA,EAAA,GAAA,EAAA,MAAA,CAAA,EAfL,qBAeK,CAfiB,QAejB,CAf0B,CAe1B,CAAA,CAAA;EAC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AW,OAAO,QAAQ;;;;;;;;;;;;;kBAgBxB,UAAU,0BACtB,oCAAmC,4BACzB,WAAW,OAAO,QAAQ,OAAO;;;;;;;KAavC;;;;;;;;;;;KAcA,qCACE,KAAK,EAAE,2BAA2B,IAAI,EAAE,4CAG/C,sCAEc,cAAc,SAAS,aAAa,UAC9C,QAAQ,KAAK;;;;;;;KAUZ,YAAA;;;;;;;;oBAUY;;;;;;;;;;;;;;;;;;;;;;UAuBP,WAAA;;;;;;;;;;;;;;;;;;;;;gBAsBD;;;;;oBAMI;;;;;gBAMJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0BAoCU;;KAGd,cAAA;;;;;;;;;;YAUA;;;;;;;;;;;;;;;;;UAkBF;;;;;;;;UASA;;;;;;sBAOY;;;;;;;;iBASL,UAAA,CAAW"}
|
package/dist/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","names":["opts: IngressCallOptions<I, O>","opts: IngressSendOptions<I>"],"sources":["../src/api.ts"],"sourcesContent":["import type {\n Service,\n VirtualObjectDefinitionFrom,\n Workflow,\n VirtualObject,\n ServiceDefinitionFrom,\n WorkflowDefinitionFrom,\n Serde,\n Duration,\n JournalValueCodec,\n} from \"@restatedev/restate-sdk-core\";\nimport { millisOrDurationToMillis } from \"@restatedev/restate-sdk-core\";\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * A remote client for a Restate service.\n *\n * Use the following client to interact with services defined\n * - `serviceClient` to create a client for a service.\n * - `workflowClient` to create a client for a workflow.\n * - `objectClient` to create a client for a virtual object.\n *\n */\nexport interface Ingress {\n /**\n * Create a client from a {@link ServiceDefinition}.\n */\n serviceClient<D>(opts: ServiceDefinitionFrom<D>): IngressClient<Service<D>>;\n\n /**\n * Create a client from a {@link WorkflowDefinition}.\n *\n * @param key the key of the workflow.\n */\n workflowClient<D>(\n opts: WorkflowDefinitionFrom<D>,\n key: string\n ): IngressWorkflowClient<Workflow<D>>;\n\n /**\n * Create a client from a {@link VirtualObjectDefinition}.\n * @param key the key of the virtual object.\n */\n objectClient<D>(\n opts: VirtualObjectDefinitionFrom<D>,\n key: string\n ): IngressClient<VirtualObject<D>>;\n\n /**\n * Create a client from a {@link ServiceDefinition}.\n */\n serviceSendClient<D>(\n opts: ServiceDefinitionFrom<D>\n ): IngressSendClient<Service<D>>;\n\n /**\n * Create a client from a {@link VirtualObjectDefinition}.\n */\n objectSendClient<D>(\n opts: VirtualObjectDefinitionFrom<D>,\n key: string\n ): IngressSendClient<VirtualObject<D>>;\n\n /**\n * Resolve an awakeable from the ingress client.\n */\n resolveAwakeable<T>(\n id: string,\n payload?: T,\n payloadSerde?: Serde<T>\n ): Promise<void>;\n\n /**\n * Reject an awakeable from the ingress client.\n */\n rejectAwakeable(id: string, reason: string): Promise<void>;\n\n /**\n * Obtain the result of a service that was asynchronously submitted (via a sendClient).\n *\n * @param send either the send response or the workflow submission as obtained by the respective clients.\n */\n result<T>(\n send: Send<T> | WorkflowSubmission<T>,\n resultSerde?: Serde<T>\n ): Promise<T>;\n\n /** Generic request-response call. Routes directly by service name without a typed definition. */\n call<I = Uint8Array, O = Uint8Array>(opts: {\n service: string;\n handler: string;\n parameter: I;\n key?: string;\n /**\n * Route this call within the given scope. See {@link Ingress.scope}.\n *\n * *NOTE:* This API is experimental. To use it you need a restate-server >= 1.7,\n * configured to enable\n * [service protocol v7](https://github.com/restatedev/restate/blob/main/release-notes/v1.7.0.md#service-protocol-v7)\n * and [flow control](https://github.com/restatedev/restate/blob/main/release-notes/v1.7.0.md#flow-control).\n * For example, start the restate-server with the environment variables\n * `RESTATE_EXPERIMENTAL_ENABLE_PROTOCOL_V7=true` and `RESTATE_EXPERIMENTAL_ENABLE_VQUEUES=true`.\n *\n * @experimental\n */\n scope?: string;\n opts?: Opts<I, O>;\n }): Promise<O>;\n\n /** Generic fire-and-forget send. Routes directly by service name without a typed definition. */\n send<I = Uint8Array>(opts: {\n service: string;\n handler: string;\n parameter: I;\n key?: string;\n /**\n * Route this send within the given scope. See {@link Ingress.scope}.\n *\n * *NOTE:* This API is experimental. To use it you need a restate-server >= 1.7,\n * configured to enable\n * [service protocol v7](https://github.com/restatedev/restate/blob/main/release-notes/v1.7.0.md#service-protocol-v7)\n * and [flow control](https://github.com/restatedev/restate/blob/main/release-notes/v1.7.0.md#flow-control).\n * For example, start the restate-server with the environment variables\n * `RESTATE_EXPERIMENTAL_ENABLE_PROTOCOL_V7=true` and `RESTATE_EXPERIMENTAL_ENABLE_VQUEUES=true`.\n *\n * @experimental\n */\n scope?: string;\n opts?: SendOpts<I>;\n }): Promise<Send>;\n\n /**\n * Returns a {@link ScopedIngress} that routes all calls within the given scope.\n *\n * **NOTE:** This API is in preview and is not enabled by default.\n * To use it in restate-server 1.7, enable the flow control and protocol v7 experimental features,\n * via `RESTATE_EXPERIMENTAL_ENABLE_PROTOCOL_V7=true` and `RESTATE_EXPERIMENTAL_ENABLE_VQUEUES=true`.\n * These can be enabled only on **new clusters**, for more info check out https://docs.restate.dev/services/flow-control#enabling-flow-control.\n * If these experimental features aren't enabled, the invocation won't be ingested and the client request fails.\n *\n * A scope is a sub-grouping of resources (invocations, virtual object instances, workflow\n * instances, concurrency limits) within the Restate cluster.\n * It becomes part of the target identity tuple:\n * - `scope, service, handler, idempotencyKey?`\n * - `scope, virtualObject, objectKey, handler, idempotencyKey?`\n * - `scope, workflow, workflowKey, handler`\n *\n * Under the hood, the scope contributes to the partition key, so all resources in a scope get co-located by the restate-server.\n *\n * Omitting the scope (i.e. using the regular `serviceClient` / `workflowClient` methods)\n * is equivalent to calling with no scope, which is the existing behavior.\n *\n * The scope key must consist only of `[a-zA-Z0-9_.-]` characters, with 1 <= length <= 36 chars.\n *\n * @example\n * ```ts\n * // Route a call into a named scope\n * await ingress.scope(\"tenant-123\").serviceClient(MyService).process(payload);\n *\n * // Idempotency keys are scoped — \"req-1\" in \"tenant-123\" is distinct from \"req-1\" in \"tenant-456\"\n * await ingress.scope(\"tenant-123\").serviceClient(MyService)\n * .process(payload, rpc.opts({ idempotencyKey: \"req-1\" }));\n *\n * // Combine with a limit key to enforce per-scope concurrency limits\n * await ingress.scope(\"tenant-123\").workflowClient(MyWorkflow, \"wf-key\")\n * .run(input, rpc.opts({ limitKey: \"api-key/user42\" }));\n * ```\n *\n * @param scopeKey the scope identifier\n * @see https://docs.restate.dev/services/flow-control\n * @experimental\n */\n scope(scopeKey: string): ScopedIngress;\n}\n\n/**\n * An ingress client for making RPC calls within a specific scope.\n *\n * @see {@link Ingress.scope}\n * @experimental\n * @interface\n */\nexport type ScopedIngress = Pick<\n Ingress,\n | \"serviceClient\"\n | \"serviceSendClient\"\n | \"objectClient\"\n | \"objectSendClient\"\n | \"workflowClient\"\n>;\n\nexport interface IngressCallOptions<I = unknown, O = unknown> {\n /**\n * Key to use for idempotency key.\n *\n * See https://docs.restate.dev/operate/invocation#invoke-a-handler-idempotently for more details.\n */\n idempotencyKey?: string;\n\n /**\n * An optional concurrency limit key within the scope.\n * A limit key can only be used in conjunction with a scope (see {@link Ingress.scope}).\n *\n * **NOTE:** This API is in preview and is not enabled by default.\n * To use it in restate-server 1.7, enable the flow control and protocol v7 experimental features,\n * via `RESTATE_EXPERIMENTAL_ENABLE_PROTOCOL_V7=true` and `RESTATE_EXPERIMENTAL_ENABLE_VQUEUES=true`.\n * These can be enabled only on **new clusters**, for more info check out https://docs.restate.dev/services/flow-control#enabling-flow-control.\n * If these experimental features aren't enabled, the invocation isn't ingested and the client request fails.\n *\n * The limit key enforces hierarchical concurrency limits on invocations sharing the same scope.\n * It can have one or two levels separated by `/` (e.g. `\"tenant1\"` or `\"tenant1/user42\"`).\n * Each level must consist only of `[a-zA-Z0-9_.-]` characters, and 1 <= length <= 36.\n *\n * The limit key is **not** part of the request identity: two calls to the same target with the\n * same scope and object key but different limit keys refer to the **same** resource instance.\n * The limit key only affects concurrency limits, not resource identity.\n *\n * @experimental\n */\n limitKey?: string;\n\n /**\n * Headers to attach to the request.\n */\n headers?: Record<string, string>;\n\n input?: Serde<I>;\n\n output?: Serde<O>;\n\n /**\n * Timeout to be used when executing the request. In milliseconds.\n *\n * Same as {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal#aborting_a_fetch_with_timeout_or_explicit_abort | AbortSignal.timeout()}.\n *\n * This field is exclusive with `signal`, and using both of them will result in a runtime failure.\n */\n timeout?: number;\n\n /**\n * Signal to abort the underlying `fetch` operation. See {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}.\n *\n * This field is exclusive with `timeout`, and using both of them will result in a runtime failure.\n */\n signal?: AbortSignal;\n}\n\nexport interface IngressSendOptions<I> extends IngressCallOptions<I, void> {\n /**\n * If set, the invocation will be enqueued now to be executed after the provided delay. In milliseconds.\n */\n delay?: number | Duration;\n}\n\nexport class Opts<I, O> {\n /**\n * Create a call configuration from the provided options.\n *\n * @param opts the call configuration\n */\n public static from<I = unknown, O = unknown>(\n opts: IngressCallOptions<I, O>\n ): Opts<I, O> {\n return new Opts(opts);\n }\n\n constructor(readonly opts: IngressCallOptions<I, O>) {}\n}\n\nexport class SendOpts<I = unknown> {\n /**\n * @param opts Create send options\n */\n public static from<I = unknown>(opts: IngressSendOptions<I>): SendOpts<I> {\n return new SendOpts(opts);\n }\n\n delay(): number | undefined {\n if (this.opts.delay !== undefined) {\n return millisOrDurationToMillis(this.opts.delay);\n }\n return undefined;\n }\n\n constructor(readonly opts: IngressSendOptions<I>) {}\n}\n\nexport type InferArgType<P> = P extends [infer A, ...any[]] ? A : unknown;\n\nexport type IngressClient<M> = {\n [K in keyof M as M[K] extends never ? never : K]: M[K] extends (\n arg: any,\n ...args: infer P\n ) => PromiseLike<infer O>\n ? (...args: [...P, ...[opts?: Opts<InferArgType<P>, O>]]) => PromiseLike<O>\n : never;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport namespace rpc {\n export const opts = <I, O>(opts: IngressCallOptions<I, O>) => Opts.from(opts);\n\n export const sendOpts = <I>(opts: IngressSendOptions<I>) =>\n SendOpts.from(opts);\n}\n\n/**\n * Represents the output of a workflow.\n */\nexport interface Output<O> {\n /**\n * Whether the output is ready.\n */\n ready: boolean;\n\n /**\n * The output of the workflow.\n */\n result: O;\n}\n\n/**\n * Represents a successful workflow submission.\n *\n */\n/* eslint-disable-next-line @typescript-eslint/no-unused-vars */\nexport type WorkflowSubmission<T> = {\n /**\n * The invocation id of the workflow. You can use that id to\n * with the introspection tools (restate cli, logging, metrics)\n *\n */\n readonly invocationId: string;\n /**\n * Whether the workflow was accepted by this request or had already been\n * accepted.\n *\n * When automatic retries are enabled, this may be `PreviouslyAccepted` if an\n * earlier attempt from the same `workflowSubmit` call was accepted but its\n * response was not observed by the client.\n */\n readonly status: \"Accepted\" | \"PreviouslyAccepted\";\n readonly attachable: true;\n};\n\n/**\n * A client for a workflow.\n *\n * This client represents the workflow definition, with the following additional methods:\n * - `workflowSubmit` to submit the workflow.\n * - `workflowAttach` to attach to the workflow and wait for its completion\n * - `workflowOutput` to check if the workflow's output is ready/available.\n *\n * Once a workflow is submitted, it can be attached to, and the output can be retrieved.\n *\n * @typeParam M the type of the workflow.\n */\nexport type IngressWorkflowClient<M> = Omit<\n {\n [K in keyof M as M[K] extends never ? never : K]: M[K] extends (\n arg: any,\n ...args: infer P\n ) => PromiseLike<infer O>\n ? (\n ...args: [...P, ...[opts?: Opts<InferArgType<P>, O>]]\n ) => PromiseLike<O>\n : never;\n } & {\n /**\n * Submit this workflow.\n *\n * This instructs restate to execute the 'run' handler of the workflow, idempotently.\n * The workflow will be executed asynchronously, and the promise will resolve when the workflow has been accepted.\n * Please note that submitting a workflow does not wait for it to completion.\n * When automatic retries are enabled on the connection, the client safely retries\n * ambiguous submission failures using the workflow ID as the request identity.\n *\n * @param argument the same argument type as defined by the 'run' handler.\n */\n workflowSubmit: M extends Record<string, unknown>\n ? M[\"run\"] extends (arg: any, ...args: infer I) => Promise<infer O>\n ? (\n ...args: [...I, ...[opts?: SendOpts<InferArgType<I>>]]\n ) => Promise<WorkflowSubmission<O>>\n : never\n : never;\n\n /**\n * Attach to this workflow.\n *\n * This instructs restate to attach to the workflow and wait for it to complete.\n * It is only possible to 'attach' to a workflow that has been previously submitted.\n * The promise will resolve when the workflow has completed either successfully with a result,\n * or be rejected with an error.\n * This operation is safe to retry many times, and it will always return the same result.\n * When automatic retries are enabled on the connection, the client retries\n * ambiguous attach failures according to the configured retry policy.\n *\n * @returns a promise that resolves when the workflow has completed.\n */\n workflowAttach: M extends Record<string, unknown>\n ? M[\"run\"] extends (...args: any) => Promise<infer O>\n ? (opts?: Opts<void, O>) => Promise<O>\n : never\n : never;\n\n /**\n * Try retrieving the output of this workflow.\n *\n * This instructs restate to check if the workflow's output is ready/available.\n * The returned Output object will have a 'ready' field set to true if the output is ready.\n * If the output is ready, the 'result' field will contain the output.\n * note: that this operation will not wait for the workflow to complete, to do so use 'workflowAttach'.\n * When automatic retries are enabled on the connection, the client retries\n * ambiguous output retrieval failures according to the configured retry policy.\n *\n * @returns a promise that resolves if the workflow's output is ready/available.\n */\n workflowOutput: M extends Record<string, unknown>\n ? M[\"run\"] extends (...args: any) => Promise<infer O>\n ? (opts?: Opts<void, O>) => Promise<Output<O>>\n : never\n : never;\n },\n \"run\"\n>;\n\n/**\n * A send response.\n *\n * @typeParam T the type of the response.\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport type Send<T = unknown> = {\n /**\n * The invocation id of the send.\n */\n invocationId: string;\n\n /**\n * The status of the send.\n */\n status: \"Accepted\" | \"PreviouslyAccepted\";\n\n attachable: boolean;\n};\n\nexport type IngressSendClient<M> = {\n [K in keyof M as M[K] extends never ? never : K]: M[K] extends (\n arg: any,\n ...args: infer P\n ) => PromiseLike<infer O>\n ? (\n ...args: [...P, ...[opts?: SendOpts<InferArgType<P>>]]\n ) => Promise<Send<O>>\n : never;\n};\n\n/**\n * An ambiguous ingress failure that may be retried.\n *\n * Passed to {@link RetryPolicy.shouldRetry} so a caller can inspect the failure\n * and decide whether to retry.\n */\nexport type RetryFailure =\n | {\n /** The underlying `fetch` call rejected (connection refused/reset, DNS). */\n readonly kind: \"network\";\n readonly error: unknown;\n }\n | {\n /** The server returned a non-2xx response. */\n readonly kind: \"response\";\n readonly status: number;\n readonly headers: Headers;\n /**\n * The response body, decoded as text, when the response carried a\n * non-empty body; `undefined` otherwise.\n */\n readonly body?: string;\n };\n\n/**\n * Policy controlling automatic retries of ambiguous ingress failures.\n *\n * Retries are **opt-in**: they happen only when a policy is configured (see\n * {@link ConnectionOpts.retry}) and the request is safe to repeat. Regular\n * calls require an `idempotencyKey` (see\n * {@link IngressCallOptions.idempotencyKey}); workflow submissions are\n * idempotent by workflow ID, while workflow attaches and output retrieval only\n * observe the existing workflow.\n *\n * By default the following failures are retried: network errors (the underlying\n * `fetch` rejecting) and responses with a transient status (`408`, `425`, `429`,\n * or `5xx`). A terminal error of the invocation is never retried, whatever its status code.\n * Override all of this with {@link RetryPolicy.shouldRetry}.\n */\nexport interface RetryPolicy {\n /**\n * Max number of attempts (including the initial), before giving up.\n *\n * Retrying stops as soon as **either** `maxDuration` or {@link maxAttempts} is reached.\n *\n * Defaults to `6` (the initial attempt plus up to 5 retries). Pass `false` to\n * remove the attempt bound.\n */\n maxAttempts?: number | false;\n\n /**\n * Max total duration of retries, measured from the first attempt, before\n * giving up. If a number is provided, it is interpreted as milliseconds.\n *\n * This bound is checked only when deciding whether to start another\n * attempt after a failure: it never aborts an in-flight request.\n *\n * Retrying stops as soon as **either** {@link maxDuration} or {@link maxAttempts} is reached.\n *\n * Defaults to 60 seconds. Pass `false` to remove the duration bound.\n */\n maxDuration?: Duration | number | false;\n\n /**\n * Initial backoff interval. If a number is provided, it is interpreted as\n * milliseconds. Defaults to `250` milliseconds.\n */\n initialInterval?: Duration | number;\n\n /**\n * Maximum backoff interval. If a number is provided, it is interpreted as\n * milliseconds. Defaults to `3000` milliseconds.\n */\n maxInterval?: Duration | number;\n\n /**\n * Exponentiation factor to use when computing the next retry delay.\n * Defaults to `2`.\n */\n exponentiationFactor?: number;\n\n /**\n * Whether to honor a `Retry-After` response header when the server provides\n * one. When `true` (the default), a `Retry-After` value overrides the computed\n * exponential backoff for that attempt.\n *\n * Set to `false` to always use the exponential backoff and ignore the header.\n *\n * Note that `Retry-After` never extends the number of retries: {@link maxAttempts} and\n * {@link maxDuration} is always respected regardless of this setting.\n *\n * Defaults to `true`.\n */\n respectRetryAfter?: boolean;\n\n /**\n * Decide whether a given failure should be retried. When provided, this\n * fully replaces the built-in rule (network / transient `408`/`425`/`429`/`5xx`,\n * excluding invocation-sourced errors).\n *\n * The idempotency-key gate still applies to regular invocations; workflow\n * submissions, attaches, and output retrieval remain eligible without an\n * idempotency key. The `maxAttempts` cap applies to all of them. This predicate\n * only narrows or broadens *which failures* are retryable within those bounds.\n * Compose with the built-in rule via the exported `defaultShouldRetry`.\n *\n * @param failure the failure being considered\n * @param attempt the zero-based index of the attempt that just failed\n */\n shouldRetry?: (failure: RetryFailure, attempt: number) => boolean;\n}\n\nexport type ConnectionOpts = {\n /**\n * Restate ingress URL.\n * For example: http://localhost:8080\n */\n url: string;\n /**\n * Headers to attach on every request.\n * Use this to attach authentication headers.\n */\n headers?: Record<string, string>;\n\n /**\n * Opt in to automatic retries of ambiguous ingress failures (network errors\n * and transient HTTP statuses `408`/`425`/`429`/`5xx`, excluding errors\n * restate attributes to the invocation itself).\n *\n * Retries are **disabled by default**. Set `true` to enable the built-in\n * policy ({@link RetryPolicy}), or pass a {@link RetryPolicy} to tune it.\n *\n * Even when enabled, regular calls are retried **only** when an\n * `idempotencyKey` is set — without one a retry could double-execute a\n * non-idempotent invocation. Workflow submissions, attaches, and output\n * retrieval are also retried: submissions are idempotent by workflow ID,\n * while attach and output operations only observe the existing workflow. If a\n * submission retry observes a workflow accepted by an earlier attempt, its\n * status is `PreviouslyAccepted`.\n */\n retry?: RetryPolicy | boolean;\n\n /**\n * Default serde to use for ingress payloads when no operation-specific serde\n * is provided. Applies to handler calls, workflow attaches/output polling,\n * awakeable resolution, and attached invocation results.\n *\n * Defaults to `restate.serde.json`.\n */\n serde?: Serde<any>;\n\n /**\n * Codec to use for input/outputs. Check {@link JournalValueCodec} for more details\n *\n * @experimental\n */\n journalValueCodec?: JournalValueCodec;\n\n /**\n * Custom fetch client\n *\n * Allows you to provide a different fetch implementation (e.g., undici fetch for HTTP/2 support).\n *\n * @defaultValue `globalThis.fetch`\n */\n fetch?: typeof globalThis.fetch;\n};\n"],"mappings":";;;AA+PA,IAAa,OAAb,MAAa,KAAW;;;;;;CAMtB,OAAc,KACZ,MACY;AACZ,SAAO,IAAI,KAAK,KAAK;;CAGvB,YAAY,AAASA,MAAgC;EAAhC;;;AAGvB,IAAa,WAAb,MAAa,SAAsB;;;;CAIjC,OAAc,KAAkB,MAA0C;AACxE,SAAO,IAAI,SAAS,KAAK;;CAG3B,QAA4B;AAC1B,MAAI,KAAK,KAAK,UAAU,OACtB,QAAO,yBAAyB,KAAK,KAAK,MAAM;;CAKpD,YAAY,AAASC,MAA6B;EAA7B;;;;;cAgBM,SAAmC,KAAK,KAAK,KAAK;kBAEjD,SAC1B,SAAS,KAAK,KAAK"}
|
|
1
|
+
{"version":3,"file":"api.js","names":["opts: IngressCallOptions<I, O>","opts: IngressSendOptions<I>"],"sources":["../src/api.ts"],"sourcesContent":["import type {\n Service,\n VirtualObjectDefinitionFrom,\n Workflow,\n VirtualObject,\n ServiceDefinitionFrom,\n WorkflowDefinitionFrom,\n Serde,\n Duration,\n JournalValueCodec,\n HandlerDescriptor,\n ServiceDescriptor,\n ObjectDescriptor,\n WorkflowDescriptor,\n InferInput,\n InferOutput,\n} from \"@restatedev/restate-sdk-core\";\nimport { millisOrDurationToMillis } from \"@restatedev/restate-sdk-core\";\n\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\n/**\n * A remote client for a Restate service.\n *\n * Use the following client to interact with services defined\n * - `serviceClient` to create a client for a service.\n * - `workflowClient` to create a client for a workflow.\n * - `objectClient` to create a client for a virtual object.\n *\n */\nexport interface Ingress {\n /**\n * Create a client from a {@link ServiceDefinition}.\n */\n serviceClient<D>(opts: ServiceDefinitionFrom<D>): IngressClient<Service<D>>;\n\n /**\n * Create a client from a {@link WorkflowDefinition}.\n *\n * @param key the key of the workflow.\n */\n workflowClient<D>(\n opts: WorkflowDefinitionFrom<D>,\n key: string\n ): IngressWorkflowClient<Workflow<D>>;\n\n /**\n * Create a client from a {@link VirtualObjectDefinition}.\n * @param key the key of the virtual object.\n */\n objectClient<D>(\n opts: VirtualObjectDefinitionFrom<D>,\n key: string\n ): IngressClient<VirtualObject<D>>;\n\n /**\n * Create a send client from a {@link ServiceDefinition}.\n */\n serviceSendClient<D>(\n opts: ServiceDefinitionFrom<D>\n ): IngressSendClient<Service<D>>;\n\n /**\n * Create a send client from a {@link VirtualObjectDefinition}.\n */\n objectSendClient<D>(\n opts: VirtualObjectDefinitionFrom<D>,\n key: string\n ): IngressSendClient<VirtualObject<D>>;\n\n /**\n * Create a request/response client from a service interface / `Descriptor`.\n *\n * @example\n * ```ts\n * ingress.client(greeter).greet(req); // service\n * ingress.client(counter, \"k\").add(1); // virtual object / workflow\n * ```\n */\n client<P extends string, H extends Record<string, HandlerDescriptor>>(\n serviceInterface: ServiceDescriptor<P, H>\n ): IngressClientFromDescriptors<H>;\n client<P extends string, H extends Record<string, HandlerDescriptor>>(\n objectOrWorkflowInterface:\n | ObjectDescriptor<P, H>\n | WorkflowDescriptor<P, H>,\n key: string\n ): IngressClientFromDescriptors<H>;\n\n /**\n * Send-client (one-way) counterpart of {@link Ingress.client}.\n *\n * @example\n * ```ts\n * ingress.sendClient(greeter).greet(req);\n * ingress.sendClient(counter, \"k\").add(1);\n * ```\n */\n sendClient<P extends string, H extends Record<string, HandlerDescriptor>>(\n serviceInterface: ServiceDescriptor<P, H>\n ): IngressSendClientFromDescriptors<H>;\n sendClient<P extends string, H extends Record<string, HandlerDescriptor>>(\n objectOrWorkflowInterface:\n | ObjectDescriptor<P, H>\n | WorkflowDescriptor<P, H>,\n key: string\n ): IngressSendClientFromDescriptors<H>;\n\n /**\n * Resolve an awakeable from the ingress client.\n */\n resolveAwakeable<T>(\n id: string,\n payload?: T,\n payloadSerde?: Serde<T>\n ): Promise<void>;\n\n /**\n * Reject an awakeable from the ingress client.\n */\n rejectAwakeable(id: string, reason: string): Promise<void>;\n\n /**\n * Obtain the result of a service that was asynchronously submitted (via a sendClient).\n *\n * @param send either the send response or the workflow submission as obtained by the respective clients.\n */\n result<T>(\n send: Send<T> | WorkflowSubmission<T>,\n resultSerde?: Serde<T>\n ): Promise<T>;\n\n /** Generic request-response call. Routes directly by service name without a typed definition. */\n call<I = Uint8Array, O = Uint8Array>(opts: {\n service: string;\n handler: string;\n parameter: I;\n key?: string;\n /**\n * Route this call within the given scope. See {@link Ingress.scope}.\n *\n * *NOTE:* This API is experimental. To use it you need a restate-server >= 1.7,\n * configured to enable\n * [service protocol v7](https://github.com/restatedev/restate/blob/main/release-notes/v1.7.0.md#service-protocol-v7)\n * and [flow control](https://github.com/restatedev/restate/blob/main/release-notes/v1.7.0.md#flow-control).\n * For example, start the restate-server with the environment variables\n * `RESTATE_EXPERIMENTAL_ENABLE_PROTOCOL_V7=true` and `RESTATE_EXPERIMENTAL_ENABLE_VQUEUES=true`.\n *\n * @experimental\n */\n scope?: string;\n opts?: Opts<I, O>;\n }): Promise<O>;\n\n /** Generic fire-and-forget send. Routes directly by service name without a typed definition. */\n send<I = Uint8Array>(opts: {\n service: string;\n handler: string;\n parameter: I;\n key?: string;\n /**\n * Route this send within the given scope. See {@link Ingress.scope}.\n *\n * *NOTE:* This API is experimental. To use it you need a restate-server >= 1.7,\n * configured to enable\n * [service protocol v7](https://github.com/restatedev/restate/blob/main/release-notes/v1.7.0.md#service-protocol-v7)\n * and [flow control](https://github.com/restatedev/restate/blob/main/release-notes/v1.7.0.md#flow-control).\n * For example, start the restate-server with the environment variables\n * `RESTATE_EXPERIMENTAL_ENABLE_PROTOCOL_V7=true` and `RESTATE_EXPERIMENTAL_ENABLE_VQUEUES=true`.\n *\n * @experimental\n */\n scope?: string;\n opts?: SendOpts<I>;\n }): Promise<Send>;\n\n /**\n * Returns a {@link ScopedIngress} that routes all calls within the given scope.\n *\n * **NOTE:** This API is in preview and is not enabled by default.\n * To use it in restate-server 1.7, enable the flow control and protocol v7 experimental features,\n * via `RESTATE_EXPERIMENTAL_ENABLE_PROTOCOL_V7=true` and `RESTATE_EXPERIMENTAL_ENABLE_VQUEUES=true`.\n * These can be enabled only on **new clusters**, for more info check out https://docs.restate.dev/services/flow-control#enabling-flow-control.\n * If these experimental features aren't enabled, the invocation won't be ingested and the client request fails.\n *\n * A scope is a sub-grouping of resources (invocations, virtual object instances, workflow\n * instances, concurrency limits) within the Restate cluster.\n * It becomes part of the target identity tuple:\n * - `scope, service, handler, idempotencyKey?`\n * - `scope, virtualObject, objectKey, handler, idempotencyKey?`\n * - `scope, workflow, workflowKey, handler`\n *\n * Under the hood, the scope contributes to the partition key, so all resources in a scope get co-located by the restate-server.\n *\n * Omitting the scope (i.e. using the regular `serviceClient` / `workflowClient` methods)\n * is equivalent to calling with no scope, which is the existing behavior.\n *\n * The scope key must consist only of `[a-zA-Z0-9_.-]` characters, with 1 <= length <= 36 chars.\n *\n * @example\n * ```ts\n * // Route a call into a named scope\n * await ingress.scope(\"tenant-123\").serviceClient(MyService).process(payload);\n *\n * // Idempotency keys are scoped — \"req-1\" in \"tenant-123\" is distinct from \"req-1\" in \"tenant-456\"\n * await ingress.scope(\"tenant-123\").serviceClient(MyService)\n * .process(payload, rpc.opts({ idempotencyKey: \"req-1\" }));\n *\n * // Combine with a limit key to enforce per-scope concurrency limits\n * await ingress.scope(\"tenant-123\").workflowClient(MyWorkflow, \"wf-key\")\n * .run(input, rpc.opts({ limitKey: \"api-key/user42\" }));\n * ```\n *\n * @param scopeKey the scope identifier\n * @see https://docs.restate.dev/services/flow-control\n * @experimental\n */\n scope(scopeKey: string): ScopedIngress;\n}\n\n/**\n * An ingress client for making RPC calls within a specific scope.\n *\n * @see {@link Ingress.scope}\n * @experimental\n * @interface\n */\nexport type ScopedIngress = Pick<\n Ingress,\n | \"serviceClient\"\n | \"serviceSendClient\"\n | \"objectClient\"\n | \"objectSendClient\"\n | \"workflowClient\"\n | \"client\"\n | \"sendClient\"\n>;\n\nexport interface IngressCallOptions<I = unknown, O = unknown> {\n /**\n * Key to use for idempotency key.\n *\n * See https://docs.restate.dev/operate/invocation#invoke-a-handler-idempotently for more details.\n */\n idempotencyKey?: string;\n\n /**\n * An optional concurrency limit key within the scope.\n * A limit key can only be used in conjunction with a scope (see {@link Ingress.scope}).\n *\n * **NOTE:** This API is in preview and is not enabled by default.\n * To use it in restate-server 1.7, enable the flow control and protocol v7 experimental features,\n * via `RESTATE_EXPERIMENTAL_ENABLE_PROTOCOL_V7=true` and `RESTATE_EXPERIMENTAL_ENABLE_VQUEUES=true`.\n * These can be enabled only on **new clusters**, for more info check out https://docs.restate.dev/services/flow-control#enabling-flow-control.\n * If these experimental features aren't enabled, the invocation isn't ingested and the client request fails.\n *\n * The limit key enforces hierarchical concurrency limits on invocations sharing the same scope.\n * It can have one or two levels separated by `/` (e.g. `\"tenant1\"` or `\"tenant1/user42\"`).\n * Each level must consist only of `[a-zA-Z0-9_.-]` characters, and 1 <= length <= 36.\n *\n * The limit key is **not** part of the request identity: two calls to the same target with the\n * same scope and object key but different limit keys refer to the **same** resource instance.\n * The limit key only affects concurrency limits, not resource identity.\n *\n * @experimental\n */\n limitKey?: string;\n\n /**\n * Headers to attach to the request.\n */\n headers?: Record<string, string>;\n\n input?: Serde<I>;\n\n output?: Serde<O>;\n\n /**\n * Timeout to be used when executing the request. In milliseconds.\n *\n * Same as {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal#aborting_a_fetch_with_timeout_or_explicit_abort | AbortSignal.timeout()}.\n *\n * This field is exclusive with `signal`, and using both of them will result in a runtime failure.\n */\n timeout?: number;\n\n /**\n * Signal to abort the underlying `fetch` operation. See {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}.\n *\n * This field is exclusive with `timeout`, and using both of them will result in a runtime failure.\n */\n signal?: AbortSignal;\n}\n\nexport interface IngressSendOptions<I> extends IngressCallOptions<I, void> {\n /**\n * If set, the invocation will be enqueued now to be executed after the provided delay. In milliseconds.\n */\n delay?: number | Duration;\n}\n\nexport class Opts<I, O> {\n /**\n * Create a call configuration from the provided options.\n *\n * @param opts the call configuration\n */\n public static from<I = unknown, O = unknown>(\n opts: IngressCallOptions<I, O>\n ): Opts<I, O> {\n return new Opts(opts);\n }\n\n constructor(readonly opts: IngressCallOptions<I, O>) {}\n}\n\nexport class SendOpts<I = unknown> {\n /**\n * @param opts Create send options\n */\n public static from<I = unknown>(opts: IngressSendOptions<I>): SendOpts<I> {\n return new SendOpts(opts);\n }\n\n delay(): number | undefined {\n if (this.opts.delay !== undefined) {\n return millisOrDurationToMillis(this.opts.delay);\n }\n return undefined;\n }\n\n constructor(readonly opts: IngressSendOptions<I>) {}\n}\n\nexport type InferArgType<P> = P extends [infer A, ...any[]] ? A : unknown;\n\nexport type IngressClient<M> = {\n [K in keyof M as M[K] extends never ? never : K]: M[K] extends (\n arg: any,\n ...args: infer P\n ) => PromiseLike<infer O>\n ? (...args: [...P, ...[opts?: Opts<InferArgType<P>, O>]]) => PromiseLike<O>\n : never;\n};\n\n/**\n * Typed ingress request/response client derived from a service interface's\n * handler descriptor map `H` (see `iface` in `@restatedev/restate-sdk-core`).\n * Recovers the input/output types directly from the descriptors, so a code-free\n * interface value produces a fully typed client that reuses the declared serdes.\n */\nexport type IngressClientFromDescriptors<\n H extends Record<string, HandlerDescriptor>,\n> = {\n readonly [K in keyof H]: [InferInput<H[K]>] extends [void]\n ? (\n opts?: Opts<InferInput<H[K]>, InferOutput<H[K]>>\n ) => Promise<InferOutput<H[K]>>\n : (\n input: InferInput<H[K]>,\n opts?: Opts<InferInput<H[K]>, InferOutput<H[K]>>\n ) => Promise<InferOutput<H[K]>>;\n};\n\n/** One-way (send) counterpart of {@link IngressClientFromDescriptors}. */\nexport type IngressSendClientFromDescriptors<\n H extends Record<string, HandlerDescriptor>,\n> = {\n readonly [K in keyof H]: [InferInput<H[K]>] extends [void]\n ? (opts?: SendOpts<InferInput<H[K]>>) => Promise<Send<InferOutput<H[K]>>>\n : (\n input: InferInput<H[K]>,\n opts?: SendOpts<InferInput<H[K]>>\n ) => Promise<Send<InferOutput<H[K]>>>;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-namespace\nexport namespace rpc {\n export const opts = <I, O>(opts: IngressCallOptions<I, O>) => Opts.from(opts);\n\n export const sendOpts = <I>(opts: IngressSendOptions<I>) =>\n SendOpts.from(opts);\n}\n\n/**\n * Represents the output of a workflow.\n */\nexport interface Output<O> {\n /**\n * Whether the output is ready.\n */\n ready: boolean;\n\n /**\n * The output of the workflow.\n */\n result: O;\n}\n\n/**\n * Represents a successful workflow submission.\n *\n */\n/* eslint-disable-next-line @typescript-eslint/no-unused-vars */\nexport type WorkflowSubmission<T> = {\n /**\n * The invocation id of the workflow. You can use that id to\n * with the introspection tools (restate cli, logging, metrics)\n *\n */\n readonly invocationId: string;\n /**\n * Whether the workflow was accepted by this request or had already been\n * accepted.\n *\n * When automatic retries are enabled, this may be `PreviouslyAccepted` if an\n * earlier attempt from the same `workflowSubmit` call was accepted but its\n * response was not observed by the client.\n */\n readonly status: \"Accepted\" | \"PreviouslyAccepted\";\n readonly attachable: true;\n};\n\n/**\n * A client for a workflow.\n *\n * This client represents the workflow definition, with the following additional methods:\n * - `workflowSubmit` to submit the workflow.\n * - `workflowAttach` to attach to the workflow and wait for its completion\n * - `workflowOutput` to check if the workflow's output is ready/available.\n *\n * Once a workflow is submitted, it can be attached to, and the output can be retrieved.\n *\n * @typeParam M the type of the workflow.\n */\nexport type IngressWorkflowClient<M> = Omit<\n {\n [K in keyof M as M[K] extends never ? never : K]: M[K] extends (\n arg: any,\n ...args: infer P\n ) => PromiseLike<infer O>\n ? (\n ...args: [...P, ...[opts?: Opts<InferArgType<P>, O>]]\n ) => PromiseLike<O>\n : never;\n } & {\n /**\n * Submit this workflow.\n *\n * This instructs restate to execute the 'run' handler of the workflow, idempotently.\n * The workflow will be executed asynchronously, and the promise will resolve when the workflow has been accepted.\n * Please note that submitting a workflow does not wait for it to completion.\n * When automatic retries are enabled on the connection, the client safely retries\n * ambiguous submission failures using the workflow ID as the request identity.\n *\n * @param argument the same argument type as defined by the 'run' handler.\n */\n workflowSubmit: M extends Record<string, unknown>\n ? M[\"run\"] extends (arg: any, ...args: infer I) => Promise<infer O>\n ? (\n ...args: [...I, ...[opts?: SendOpts<InferArgType<I>>]]\n ) => Promise<WorkflowSubmission<O>>\n : never\n : never;\n\n /**\n * Attach to this workflow.\n *\n * This instructs restate to attach to the workflow and wait for it to complete.\n * It is only possible to 'attach' to a workflow that has been previously submitted.\n * The promise will resolve when the workflow has completed either successfully with a result,\n * or be rejected with an error.\n * This operation is safe to retry many times, and it will always return the same result.\n * When automatic retries are enabled on the connection, the client retries\n * ambiguous attach failures according to the configured retry policy.\n *\n * @returns a promise that resolves when the workflow has completed.\n */\n workflowAttach: M extends Record<string, unknown>\n ? M[\"run\"] extends (...args: any) => Promise<infer O>\n ? (opts?: Opts<void, O>) => Promise<O>\n : never\n : never;\n\n /**\n * Try retrieving the output of this workflow.\n *\n * This instructs restate to check if the workflow's output is ready/available.\n * The returned Output object will have a 'ready' field set to true if the output is ready.\n * If the output is ready, the 'result' field will contain the output.\n * note: that this operation will not wait for the workflow to complete, to do so use 'workflowAttach'.\n * When automatic retries are enabled on the connection, the client retries\n * ambiguous output retrieval failures according to the configured retry policy.\n *\n * @returns a promise that resolves if the workflow's output is ready/available.\n */\n workflowOutput: M extends Record<string, unknown>\n ? M[\"run\"] extends (...args: any) => Promise<infer O>\n ? (opts?: Opts<void, O>) => Promise<Output<O>>\n : never\n : never;\n },\n \"run\"\n>;\n\n/**\n * A send response.\n *\n * @typeParam T the type of the response.\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport type Send<T = unknown> = {\n /**\n * The invocation id of the send.\n */\n invocationId: string;\n\n /**\n * The status of the send.\n */\n status: \"Accepted\" | \"PreviouslyAccepted\";\n\n attachable: boolean;\n};\n\nexport type IngressSendClient<M> = {\n [K in keyof M as M[K] extends never ? never : K]: M[K] extends (\n arg: any,\n ...args: infer P\n ) => PromiseLike<infer O>\n ? (\n ...args: [...P, ...[opts?: SendOpts<InferArgType<P>>]]\n ) => Promise<Send<O>>\n : never;\n};\n\n/**\n * An ambiguous ingress failure that may be retried.\n *\n * Passed to {@link RetryPolicy.shouldRetry} so a caller can inspect the failure\n * and decide whether to retry.\n */\nexport type RetryFailure =\n | {\n /** The underlying `fetch` call rejected (connection refused/reset, DNS). */\n readonly kind: \"network\";\n readonly error: unknown;\n }\n | {\n /** The server returned a non-2xx response. */\n readonly kind: \"response\";\n readonly status: number;\n readonly headers: Headers;\n /**\n * The response body, decoded as text, when the response carried a\n * non-empty body; `undefined` otherwise.\n */\n readonly body?: string;\n };\n\n/**\n * Policy controlling automatic retries of ambiguous ingress failures.\n *\n * Retries are **opt-in**: they happen only when a policy is configured (see\n * {@link ConnectionOpts.retry}) and the request is safe to repeat. Regular\n * calls require an `idempotencyKey` (see\n * {@link IngressCallOptions.idempotencyKey}); workflow submissions are\n * idempotent by workflow ID, while workflow attaches and output retrieval only\n * observe the existing workflow.\n *\n * By default the following failures are retried: network errors (the underlying\n * `fetch` rejecting) and responses with a transient status (`408`, `425`, `429`,\n * or `5xx`). A terminal error of the invocation is never retried, whatever its status code.\n * Override all of this with {@link RetryPolicy.shouldRetry}.\n */\nexport interface RetryPolicy {\n /**\n * Max number of attempts (including the initial), before giving up.\n *\n * Retrying stops as soon as **either** `maxDuration` or {@link maxAttempts} is reached.\n *\n * Defaults to `6` (the initial attempt plus up to 5 retries). Pass `false` to\n * remove the attempt bound.\n */\n maxAttempts?: number | false;\n\n /**\n * Max total duration of retries, measured from the first attempt, before\n * giving up. If a number is provided, it is interpreted as milliseconds.\n *\n * This bound is checked only when deciding whether to start another\n * attempt after a failure: it never aborts an in-flight request.\n *\n * Retrying stops as soon as **either** {@link maxDuration} or {@link maxAttempts} is reached.\n *\n * Defaults to 60 seconds. Pass `false` to remove the duration bound.\n */\n maxDuration?: Duration | number | false;\n\n /**\n * Initial backoff interval. If a number is provided, it is interpreted as\n * milliseconds. Defaults to `250` milliseconds.\n */\n initialInterval?: Duration | number;\n\n /**\n * Maximum backoff interval. If a number is provided, it is interpreted as\n * milliseconds. Defaults to `3000` milliseconds.\n */\n maxInterval?: Duration | number;\n\n /**\n * Exponentiation factor to use when computing the next retry delay.\n * Defaults to `2`.\n */\n exponentiationFactor?: number;\n\n /**\n * Whether to honor a `Retry-After` response header when the server provides\n * one. When `true` (the default), a `Retry-After` value overrides the computed\n * exponential backoff for that attempt.\n *\n * Set to `false` to always use the exponential backoff and ignore the header.\n *\n * Note that `Retry-After` never extends the number of retries: {@link maxAttempts} and\n * {@link maxDuration} is always respected regardless of this setting.\n *\n * Defaults to `true`.\n */\n respectRetryAfter?: boolean;\n\n /**\n * Decide whether a given failure should be retried. When provided, this\n * fully replaces the built-in rule (network / transient `408`/`425`/`429`/`5xx`,\n * excluding invocation-sourced errors).\n *\n * The idempotency-key gate still applies to regular invocations; workflow\n * submissions, attaches, and output retrieval remain eligible without an\n * idempotency key. The `maxAttempts` cap applies to all of them. This predicate\n * only narrows or broadens *which failures* are retryable within those bounds.\n * Compose with the built-in rule via the exported `defaultShouldRetry`.\n *\n * @param failure the failure being considered\n * @param attempt the zero-based index of the attempt that just failed\n */\n shouldRetry?: (failure: RetryFailure, attempt: number) => boolean;\n}\n\nexport type ConnectionOpts = {\n /**\n * Restate ingress URL.\n * For example: http://localhost:8080\n */\n url: string;\n /**\n * Headers to attach on every request.\n * Use this to attach authentication headers.\n */\n headers?: Record<string, string>;\n\n /**\n * Opt in to automatic retries of ambiguous ingress failures (network errors\n * and transient HTTP statuses `408`/`425`/`429`/`5xx`, excluding errors\n * restate attributes to the invocation itself).\n *\n * Retries are **disabled by default**. Set `true` to enable the built-in\n * policy ({@link RetryPolicy}), or pass a {@link RetryPolicy} to tune it.\n *\n * Even when enabled, regular calls are retried **only** when an\n * `idempotencyKey` is set — without one a retry could double-execute a\n * non-idempotent invocation. Workflow submissions, attaches, and output\n * retrieval are also retried: submissions are idempotent by workflow ID,\n * while attach and output operations only observe the existing workflow. If a\n * submission retry observes a workflow accepted by an earlier attempt, its\n * status is `PreviouslyAccepted`.\n */\n retry?: RetryPolicy | boolean;\n\n /**\n * Default serde to use for ingress payloads when no operation-specific serde\n * is provided. Applies to handler calls, workflow attaches/output polling,\n * awakeable resolution, and attached invocation results.\n *\n * Defaults to `restate.serde.json`.\n */\n serde?: Serde<any>;\n\n /**\n * Codec to use for input/outputs. Check {@link JournalValueCodec} for more details\n *\n * @experimental\n */\n journalValueCodec?: JournalValueCodec;\n\n /**\n * Custom fetch client\n *\n * Allows you to provide a different fetch implementation (e.g., undici fetch for HTTP/2 support).\n *\n * @defaultValue `globalThis.fetch`\n */\n fetch?: typeof globalThis.fetch;\n};\n"],"mappings":";;;AA6SA,IAAa,OAAb,MAAa,KAAW;;;;;;CAMtB,OAAc,KACZ,MACY;AACZ,SAAO,IAAI,KAAK,KAAK;;CAGvB,YAAY,AAASA,MAAgC;EAAhC;;;AAGvB,IAAa,WAAb,MAAa,SAAsB;;;;CAIjC,OAAc,KAAkB,MAA0C;AACxE,SAAO,IAAI,SAAS,KAAK;;CAG3B,QAA4B;AAC1B,MAAI,KAAK,KAAK,UAAU,OACtB,QAAO,yBAAyB,KAAK,KAAK,MAAM;;CAKpD,YAAY,AAASC,MAA6B;EAA7B;;;;;cA+CM,SAAmC,KAAK,KAAK,KAAK;kBAEjD,SAC1B,SAAS,KAAK,KAAK"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ConnectionOpts, InferArgType, Ingress, IngressCallOptions, IngressClient, IngressSendClient, IngressSendOptions, IngressWorkflowClient, Opts, Output, RetryFailure, RetryPolicy, ScopedIngress, Send, SendOpts, WorkflowSubmission, rpc } from "./api.cjs";
|
|
1
|
+
import { ConnectionOpts, InferArgType, Ingress, IngressCallOptions, IngressClient, IngressClientFromDescriptors, IngressSendClient, IngressSendClientFromDescriptors, IngressSendOptions, IngressWorkflowClient, Opts, Output, RetryFailure, RetryPolicy, ScopedIngress, Send, SendOpts, WorkflowSubmission, rpc } from "./api.cjs";
|
|
2
2
|
import { HttpCallError, connect } from "./ingress.cjs";
|
|
3
3
|
import { defaultShouldRetry } from "./retry.cjs";
|
|
4
4
|
import { Duration, JournalValueCodec, Serde, Service, ServiceDefinition, ServiceDefinitionFrom, VirtualObject, VirtualObjectDefinition, VirtualObjectDefinitionFrom, Workflow, WorkflowDefinition, WorkflowDefinitionFrom, serde } from "@restatedev/restate-sdk-core";
|
|
5
|
-
export { type ConnectionOpts, type Duration, HttpCallError, type InferArgType, type Ingress, type IngressCallOptions, type IngressClient, type IngressSendClient, type IngressSendOptions, type IngressWorkflowClient, type JournalValueCodec, Opts, type Output, type RetryFailure, type RetryPolicy, type ScopedIngress, type Send, SendOpts, type Serde, type Service, type ServiceDefinition, type ServiceDefinitionFrom, type VirtualObject, type VirtualObjectDefinition, type VirtualObjectDefinitionFrom, type Workflow, type WorkflowDefinition, type WorkflowDefinitionFrom, type WorkflowSubmission, connect, defaultShouldRetry, rpc, serde };
|
|
5
|
+
export { type ConnectionOpts, type Duration, HttpCallError, type InferArgType, type Ingress, type IngressCallOptions, type IngressClient, type IngressClientFromDescriptors, type IngressSendClient, type IngressSendClientFromDescriptors, type IngressSendOptions, type IngressWorkflowClient, type JournalValueCodec, Opts, type Output, type RetryFailure, type RetryPolicy, type ScopedIngress, type Send, SendOpts, type Serde, type Service, type ServiceDefinition, type ServiceDefinitionFrom, type VirtualObject, type VirtualObjectDefinition, type VirtualObjectDefinitionFrom, type Workflow, type WorkflowDefinition, type WorkflowDefinitionFrom, type WorkflowSubmission, connect, defaultShouldRetry, rpc, serde };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ConnectionOpts, InferArgType, Ingress, IngressCallOptions, IngressClient, IngressSendClient, IngressSendOptions, IngressWorkflowClient, Opts, Output, RetryFailure, RetryPolicy, ScopedIngress, Send, SendOpts, WorkflowSubmission, rpc } from "./api.js";
|
|
1
|
+
import { ConnectionOpts, InferArgType, Ingress, IngressCallOptions, IngressClient, IngressClientFromDescriptors, IngressSendClient, IngressSendClientFromDescriptors, IngressSendOptions, IngressWorkflowClient, Opts, Output, RetryFailure, RetryPolicy, ScopedIngress, Send, SendOpts, WorkflowSubmission, rpc } from "./api.js";
|
|
2
2
|
import { HttpCallError, connect } from "./ingress.js";
|
|
3
3
|
import { defaultShouldRetry } from "./retry.js";
|
|
4
4
|
import { Duration, JournalValueCodec, Serde, Service, ServiceDefinition, ServiceDefinitionFrom, VirtualObject, VirtualObjectDefinition, VirtualObjectDefinitionFrom, Workflow, WorkflowDefinition, WorkflowDefinitionFrom, serde } from "@restatedev/restate-sdk-core";
|
|
5
|
-
export { type ConnectionOpts, type Duration, HttpCallError, type InferArgType, type Ingress, type IngressCallOptions, type IngressClient, type IngressSendClient, type IngressSendOptions, type IngressWorkflowClient, type JournalValueCodec, Opts, type Output, type RetryFailure, type RetryPolicy, type ScopedIngress, type Send, SendOpts, type Serde, type Service, type ServiceDefinition, type ServiceDefinitionFrom, type VirtualObject, type VirtualObjectDefinition, type VirtualObjectDefinitionFrom, type Workflow, type WorkflowDefinition, type WorkflowDefinitionFrom, type WorkflowSubmission, connect, defaultShouldRetry, rpc, serde };
|
|
5
|
+
export { type ConnectionOpts, type Duration, HttpCallError, type InferArgType, type Ingress, type IngressCallOptions, type IngressClient, type IngressClientFromDescriptors, type IngressSendClient, type IngressSendClientFromDescriptors, type IngressSendOptions, type IngressWorkflowClient, type JournalValueCodec, Opts, type Output, type RetryFailure, type RetryPolicy, type ScopedIngress, type Send, SendOpts, type Serde, type Service, type ServiceDefinition, type ServiceDefinitionFrom, type VirtualObject, type VirtualObjectDefinition, type VirtualObjectDefinitionFrom, type Workflow, type WorkflowDefinition, type WorkflowDefinitionFrom, type WorkflowSubmission, connect, defaultShouldRetry, rpc, serde };
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,YAAY,EACV,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EAClB,qBAAqB,EACrB,2BAA2B,EAC3B,sBAAsB,EACtB,KAAK,EACL,OAAO,EACP,QAAQ,EACR,aAAa,EACb,QAAQ,EACR,iBAAiB,GAClB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAErD,YAAY,EACV,OAAO,EACP,aAAa,EACb,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,IAAI,EACJ,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,EACZ,MAAM,GACP,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAE1C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,YAAY,EACV,iBAAiB,EACjB,uBAAuB,EACvB,kBAAkB,EAClB,qBAAqB,EACrB,2BAA2B,EAC3B,sBAAsB,EACtB,KAAK,EACL,OAAO,EACP,QAAQ,EACR,aAAa,EACb,QAAQ,EACR,iBAAiB,GAClB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAErD,YAAY,EACV,OAAO,EACP,aAAa,EACb,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,4BAA4B,EAC5B,gCAAgC,EAChC,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,IAAI,EACJ,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,EACZ,MAAM,GACP,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAE1C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAiBH,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAiBH,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAoBrD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAE1C,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/ingress.cjs
CHANGED
|
@@ -127,7 +127,7 @@ const doComponentInvocation = async (opts, params, canBeRetried = Boolean(params
|
|
|
127
127
|
else fragments.push("send");
|
|
128
128
|
url = fragments.join("/");
|
|
129
129
|
}
|
|
130
|
-
const inputSerde = params.opts?.opts.input ?? opts.serde ?? __restatedev_restate_sdk_core.serde.json;
|
|
130
|
+
const inputSerde = params.opts?.opts.input ?? params.handlerDesc?._inputSerde ?? opts.serde ?? __restatedev_restate_sdk_core.serde.json;
|
|
131
131
|
const { body, contentType } = serializeBodyWithContentType(params.parameter, inputSerde, opts.journalValueCodec);
|
|
132
132
|
const headers = {
|
|
133
133
|
...opts.headers ?? {},
|
|
@@ -149,15 +149,15 @@ const doComponentInvocation = async (opts, params, canBeRetried = Boolean(params
|
|
|
149
149
|
}, params.opts, retryPolicy);
|
|
150
150
|
if (!params.send) {
|
|
151
151
|
const decodedBuf = opts.journalValueCodec ? await opts.journalValueCodec.decode(responseBuf) : responseBuf;
|
|
152
|
-
return (params.opts?.opts.output ?? opts.serde ?? __restatedev_restate_sdk_core.serde.json).deserialize(decodedBuf);
|
|
152
|
+
return (params.opts?.opts.output ?? params.handlerDesc?._outputSerde ?? opts.serde ?? __restatedev_restate_sdk_core.serde.json).deserialize(decodedBuf);
|
|
153
153
|
}
|
|
154
154
|
return {
|
|
155
155
|
...__restatedev_restate_sdk_core.serde.json.deserialize(responseBuf),
|
|
156
156
|
attachable
|
|
157
157
|
};
|
|
158
158
|
};
|
|
159
|
-
const doWorkflowHandleCall = async (opts, wfName, wfKey, op, callOpts) => {
|
|
160
|
-
const outputSerde = callOpts?.opts.output ?? opts.serde ?? __restatedev_restate_sdk_core.serde.json;
|
|
159
|
+
const doWorkflowHandleCall = async (opts, wfName, wfKey, op, callOpts, runOutputSerde) => {
|
|
160
|
+
const outputSerde = callOpts?.opts.output ?? runOutputSerde ?? opts.serde ?? __restatedev_restate_sdk_core.serde.json;
|
|
161
161
|
const headers = { ...opts.headers ?? {} };
|
|
162
162
|
const url = `${opts.url}/restate/workflow/${wfName}/${encodeURIComponent(wfKey)}/${op}`;
|
|
163
163
|
const retryPolicy = require_retry.resolveRetryPolicy(opts.retry);
|
|
@@ -172,7 +172,7 @@ var HttpIngress = class {
|
|
|
172
172
|
constructor(opts) {
|
|
173
173
|
this.opts = opts;
|
|
174
174
|
}
|
|
175
|
-
proxy(component, key, send) {
|
|
175
|
+
proxy(component, key, send, handlers) {
|
|
176
176
|
return new Proxy({}, { get: (_target, prop) => {
|
|
177
177
|
const handler = prop;
|
|
178
178
|
return (...args) => {
|
|
@@ -183,19 +183,22 @@ var HttpIngress = class {
|
|
|
183
183
|
key,
|
|
184
184
|
parameter,
|
|
185
185
|
opts,
|
|
186
|
-
send
|
|
186
|
+
send,
|
|
187
|
+
handlerDesc: handlers?.[handler]
|
|
187
188
|
});
|
|
188
189
|
};
|
|
189
190
|
} });
|
|
190
191
|
}
|
|
191
192
|
serviceClient(opts) {
|
|
192
|
-
return this.proxy(opts.name);
|
|
193
|
+
return this.proxy(opts.name, void 0, void 0, opts._handlers);
|
|
193
194
|
}
|
|
194
195
|
objectClient(opts, key) {
|
|
195
|
-
return this.proxy(opts.name, key);
|
|
196
|
+
return this.proxy(opts.name, key, void 0, opts._handlers);
|
|
196
197
|
}
|
|
197
198
|
workflowClient(opts, key) {
|
|
198
199
|
const component = opts.name;
|
|
200
|
+
const handlers = opts._handlers;
|
|
201
|
+
const runOutputSerde = handlers?.run?._outputSerde;
|
|
199
202
|
const conn = this.opts;
|
|
200
203
|
const workflowSubmit = async (...args) => {
|
|
201
204
|
const { parameter, opts: opts$1 } = optsFromArgs(args);
|
|
@@ -205,7 +208,8 @@ var HttpIngress = class {
|
|
|
205
208
|
key,
|
|
206
209
|
send: true,
|
|
207
210
|
parameter,
|
|
208
|
-
opts: opts$1
|
|
211
|
+
opts: opts$1,
|
|
212
|
+
handlerDesc: handlers?.run
|
|
209
213
|
}, true);
|
|
210
214
|
return {
|
|
211
215
|
invocationId: res.invocationId,
|
|
@@ -213,12 +217,12 @@ var HttpIngress = class {
|
|
|
213
217
|
attachable: true
|
|
214
218
|
};
|
|
215
219
|
};
|
|
216
|
-
const workflowAttach = (opts$1) => doWorkflowHandleCall(conn, component, key, "attach", opts$1);
|
|
220
|
+
const workflowAttach = (opts$1) => doWorkflowHandleCall(conn, component, key, "attach", opts$1, runOutputSerde);
|
|
217
221
|
const workflowOutput = async (opts$1) => {
|
|
218
222
|
try {
|
|
219
223
|
return {
|
|
220
224
|
ready: true,
|
|
221
|
-
result: await doWorkflowHandleCall(conn, component, key, "output", opts$1)
|
|
225
|
+
result: await doWorkflowHandleCall(conn, component, key, "output", opts$1, runOutputSerde)
|
|
222
226
|
};
|
|
223
227
|
} catch (e) {
|
|
224
228
|
if (!(e instanceof HttpCallError) || e.status !== 470) throw e;
|
|
@@ -242,20 +246,27 @@ var HttpIngress = class {
|
|
|
242
246
|
handler,
|
|
243
247
|
key,
|
|
244
248
|
parameter,
|
|
245
|
-
opts: opts$1
|
|
249
|
+
opts: opts$1,
|
|
250
|
+
handlerDesc: handlers?.[handler]
|
|
246
251
|
});
|
|
247
252
|
};
|
|
248
253
|
} });
|
|
249
254
|
}
|
|
250
255
|
objectSendClient(opts, key) {
|
|
251
|
-
return this.proxy(opts.name, key, true);
|
|
256
|
+
return this.proxy(opts.name, key, true, opts._handlers);
|
|
252
257
|
}
|
|
253
258
|
serviceSendClient(opts) {
|
|
254
|
-
return this.proxy(opts.name, void 0, true);
|
|
259
|
+
return this.proxy(opts.name, void 0, true, opts._handlers);
|
|
260
|
+
}
|
|
261
|
+
client(opts, key) {
|
|
262
|
+
return opts._kind === "service" ? this.serviceClient(opts) : this.objectClient(opts, key);
|
|
263
|
+
}
|
|
264
|
+
sendClient(opts, key) {
|
|
265
|
+
return opts._kind === "service" ? this.serviceSendClient(opts) : this.objectSendClient(opts, key);
|
|
255
266
|
}
|
|
256
267
|
scope(scopeKey) {
|
|
257
268
|
const conn = this.opts;
|
|
258
|
-
const scopedProxy = (component, key, send) => new Proxy({}, { get: (_target, prop) => {
|
|
269
|
+
const scopedProxy = (component, key, send, handlers) => new Proxy({}, { get: (_target, prop) => {
|
|
259
270
|
const handler = prop;
|
|
260
271
|
return (...args) => {
|
|
261
272
|
const { parameter, opts } = optsFromArgs(args);
|
|
@@ -266,17 +277,22 @@ var HttpIngress = class {
|
|
|
266
277
|
parameter,
|
|
267
278
|
opts,
|
|
268
279
|
send,
|
|
269
|
-
scope: scopeKey
|
|
280
|
+
scope: scopeKey,
|
|
281
|
+
handlerDesc: handlers?.[handler]
|
|
270
282
|
});
|
|
271
283
|
};
|
|
272
284
|
} });
|
|
273
285
|
return {
|
|
274
|
-
serviceClient: (opts) => scopedProxy(opts.name),
|
|
275
|
-
serviceSendClient: (opts) => scopedProxy(opts.name, void 0, true),
|
|
276
|
-
objectClient: (opts, key) => scopedProxy(opts.name, key),
|
|
277
|
-
objectSendClient: (opts, key) => scopedProxy(opts.name, key, true),
|
|
286
|
+
serviceClient: (opts) => scopedProxy(opts.name, void 0, void 0, opts._handlers),
|
|
287
|
+
serviceSendClient: (opts) => scopedProxy(opts.name, void 0, true, opts._handlers),
|
|
288
|
+
objectClient: (opts, key) => scopedProxy(opts.name, key, void 0, opts._handlers),
|
|
289
|
+
objectSendClient: (opts, key) => scopedProxy(opts.name, key, true, opts._handlers),
|
|
290
|
+
client: (opts, key) => opts._kind === "service" ? scopedProxy(opts.name, void 0, void 0, opts._handlers) : scopedProxy(opts.name, key, void 0, opts._handlers),
|
|
291
|
+
sendClient: (opts, key) => opts._kind === "service" ? scopedProxy(opts.name, void 0, true, opts._handlers) : scopedProxy(opts.name, key, true, opts._handlers),
|
|
278
292
|
workflowClient: (opts, key) => {
|
|
279
293
|
const component = opts.name;
|
|
294
|
+
const handlers = opts._handlers;
|
|
295
|
+
const runOutputSerde = handlers?.run?._outputSerde;
|
|
280
296
|
const workflowSubmit = async (...args) => {
|
|
281
297
|
const { parameter, opts: opts$1 } = optsFromArgs(args);
|
|
282
298
|
const res = await doComponentInvocation(conn, {
|
|
@@ -286,7 +302,8 @@ var HttpIngress = class {
|
|
|
286
302
|
send: true,
|
|
287
303
|
parameter,
|
|
288
304
|
opts: opts$1,
|
|
289
|
-
scope: scopeKey
|
|
305
|
+
scope: scopeKey,
|
|
306
|
+
handlerDesc: handlers?.run
|
|
290
307
|
}, true);
|
|
291
308
|
return {
|
|
292
309
|
invocationId: res.invocationId,
|
|
@@ -294,12 +311,12 @@ var HttpIngress = class {
|
|
|
294
311
|
attachable: true
|
|
295
312
|
};
|
|
296
313
|
};
|
|
297
|
-
const workflowAttach = (opts$1) => doWorkflowHandleCall(conn, component, key, "attach", opts$1);
|
|
314
|
+
const workflowAttach = (opts$1) => doWorkflowHandleCall(conn, component, key, "attach", opts$1, runOutputSerde);
|
|
298
315
|
const workflowOutput = async (opts$1) => {
|
|
299
316
|
try {
|
|
300
317
|
return {
|
|
301
318
|
ready: true,
|
|
302
|
-
result: await doWorkflowHandleCall(conn, component, key, "output", opts$1)
|
|
319
|
+
result: await doWorkflowHandleCall(conn, component, key, "output", opts$1, runOutputSerde)
|
|
303
320
|
};
|
|
304
321
|
} catch (e) {
|
|
305
322
|
if (!(e instanceof HttpCallError) || e.status !== 470) throw e;
|
|
@@ -324,7 +341,8 @@ var HttpIngress = class {
|
|
|
324
341
|
key,
|
|
325
342
|
parameter,
|
|
326
343
|
opts: opts$1,
|
|
327
|
-
scope: scopeKey
|
|
344
|
+
scope: scopeKey,
|
|
345
|
+
handlerDesc: handlers?.[handler]
|
|
328
346
|
});
|
|
329
347
|
};
|
|
330
348
|
} });
|
package/dist/ingress.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ingress.d.cts","names":[],"sources":["../src/ingress.ts"],"sourcesContent":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"ingress.d.cts","names":[],"sources":["../src/ingress.ts"],"sourcesContent":[],"mappings":";;;;;;AA8CA;AAgBA;;;iBAhBgB,OAAA,OAAc,iBAAiB;cAgBlC,aAAA,SAAsB,KAAA"}
|
package/dist/ingress.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ingress.d.ts","names":[],"sources":["../src/ingress.ts"],"sourcesContent":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"ingress.d.ts","names":[],"sources":["../src/ingress.ts"],"sourcesContent":[],"mappings":";;;;;;AA8CA;AAgBA;;;iBAhBgB,OAAA,OAAc,iBAAiB;cAgBlC,aAAA,SAAsB,KAAA"}
|
package/dist/ingress.js
CHANGED
|
@@ -125,7 +125,7 @@ const doComponentInvocation = async (opts, params, canBeRetried = Boolean(params
|
|
|
125
125
|
else fragments.push("send");
|
|
126
126
|
url = fragments.join("/");
|
|
127
127
|
}
|
|
128
|
-
const inputSerde = params.opts?.opts.input ?? opts.serde ?? serde.json;
|
|
128
|
+
const inputSerde = params.opts?.opts.input ?? params.handlerDesc?._inputSerde ?? opts.serde ?? serde.json;
|
|
129
129
|
const { body, contentType } = serializeBodyWithContentType(params.parameter, inputSerde, opts.journalValueCodec);
|
|
130
130
|
const headers = {
|
|
131
131
|
...opts.headers ?? {},
|
|
@@ -147,15 +147,15 @@ const doComponentInvocation = async (opts, params, canBeRetried = Boolean(params
|
|
|
147
147
|
}, params.opts, retryPolicy);
|
|
148
148
|
if (!params.send) {
|
|
149
149
|
const decodedBuf = opts.journalValueCodec ? await opts.journalValueCodec.decode(responseBuf) : responseBuf;
|
|
150
|
-
return (params.opts?.opts.output ?? opts.serde ?? serde.json).deserialize(decodedBuf);
|
|
150
|
+
return (params.opts?.opts.output ?? params.handlerDesc?._outputSerde ?? opts.serde ?? serde.json).deserialize(decodedBuf);
|
|
151
151
|
}
|
|
152
152
|
return {
|
|
153
153
|
...serde.json.deserialize(responseBuf),
|
|
154
154
|
attachable
|
|
155
155
|
};
|
|
156
156
|
};
|
|
157
|
-
const doWorkflowHandleCall = async (opts, wfName, wfKey, op, callOpts) => {
|
|
158
|
-
const outputSerde = callOpts?.opts.output ?? opts.serde ?? serde.json;
|
|
157
|
+
const doWorkflowHandleCall = async (opts, wfName, wfKey, op, callOpts, runOutputSerde) => {
|
|
158
|
+
const outputSerde = callOpts?.opts.output ?? runOutputSerde ?? opts.serde ?? serde.json;
|
|
159
159
|
const headers = { ...opts.headers ?? {} };
|
|
160
160
|
const url = `${opts.url}/restate/workflow/${wfName}/${encodeURIComponent(wfKey)}/${op}`;
|
|
161
161
|
const retryPolicy = resolveRetryPolicy(opts.retry);
|
|
@@ -170,7 +170,7 @@ var HttpIngress = class {
|
|
|
170
170
|
constructor(opts) {
|
|
171
171
|
this.opts = opts;
|
|
172
172
|
}
|
|
173
|
-
proxy(component, key, send) {
|
|
173
|
+
proxy(component, key, send, handlers) {
|
|
174
174
|
return new Proxy({}, { get: (_target, prop) => {
|
|
175
175
|
const handler = prop;
|
|
176
176
|
return (...args) => {
|
|
@@ -181,19 +181,22 @@ var HttpIngress = class {
|
|
|
181
181
|
key,
|
|
182
182
|
parameter,
|
|
183
183
|
opts,
|
|
184
|
-
send
|
|
184
|
+
send,
|
|
185
|
+
handlerDesc: handlers?.[handler]
|
|
185
186
|
});
|
|
186
187
|
};
|
|
187
188
|
} });
|
|
188
189
|
}
|
|
189
190
|
serviceClient(opts) {
|
|
190
|
-
return this.proxy(opts.name);
|
|
191
|
+
return this.proxy(opts.name, void 0, void 0, opts._handlers);
|
|
191
192
|
}
|
|
192
193
|
objectClient(opts, key) {
|
|
193
|
-
return this.proxy(opts.name, key);
|
|
194
|
+
return this.proxy(opts.name, key, void 0, opts._handlers);
|
|
194
195
|
}
|
|
195
196
|
workflowClient(opts, key) {
|
|
196
197
|
const component = opts.name;
|
|
198
|
+
const handlers = opts._handlers;
|
|
199
|
+
const runOutputSerde = handlers?.run?._outputSerde;
|
|
197
200
|
const conn = this.opts;
|
|
198
201
|
const workflowSubmit = async (...args) => {
|
|
199
202
|
const { parameter, opts: opts$1 } = optsFromArgs(args);
|
|
@@ -203,7 +206,8 @@ var HttpIngress = class {
|
|
|
203
206
|
key,
|
|
204
207
|
send: true,
|
|
205
208
|
parameter,
|
|
206
|
-
opts: opts$1
|
|
209
|
+
opts: opts$1,
|
|
210
|
+
handlerDesc: handlers?.run
|
|
207
211
|
}, true);
|
|
208
212
|
return {
|
|
209
213
|
invocationId: res.invocationId,
|
|
@@ -211,12 +215,12 @@ var HttpIngress = class {
|
|
|
211
215
|
attachable: true
|
|
212
216
|
};
|
|
213
217
|
};
|
|
214
|
-
const workflowAttach = (opts$1) => doWorkflowHandleCall(conn, component, key, "attach", opts$1);
|
|
218
|
+
const workflowAttach = (opts$1) => doWorkflowHandleCall(conn, component, key, "attach", opts$1, runOutputSerde);
|
|
215
219
|
const workflowOutput = async (opts$1) => {
|
|
216
220
|
try {
|
|
217
221
|
return {
|
|
218
222
|
ready: true,
|
|
219
|
-
result: await doWorkflowHandleCall(conn, component, key, "output", opts$1)
|
|
223
|
+
result: await doWorkflowHandleCall(conn, component, key, "output", opts$1, runOutputSerde)
|
|
220
224
|
};
|
|
221
225
|
} catch (e) {
|
|
222
226
|
if (!(e instanceof HttpCallError) || e.status !== 470) throw e;
|
|
@@ -240,20 +244,27 @@ var HttpIngress = class {
|
|
|
240
244
|
handler,
|
|
241
245
|
key,
|
|
242
246
|
parameter,
|
|
243
|
-
opts: opts$1
|
|
247
|
+
opts: opts$1,
|
|
248
|
+
handlerDesc: handlers?.[handler]
|
|
244
249
|
});
|
|
245
250
|
};
|
|
246
251
|
} });
|
|
247
252
|
}
|
|
248
253
|
objectSendClient(opts, key) {
|
|
249
|
-
return this.proxy(opts.name, key, true);
|
|
254
|
+
return this.proxy(opts.name, key, true, opts._handlers);
|
|
250
255
|
}
|
|
251
256
|
serviceSendClient(opts) {
|
|
252
|
-
return this.proxy(opts.name, void 0, true);
|
|
257
|
+
return this.proxy(opts.name, void 0, true, opts._handlers);
|
|
258
|
+
}
|
|
259
|
+
client(opts, key) {
|
|
260
|
+
return opts._kind === "service" ? this.serviceClient(opts) : this.objectClient(opts, key);
|
|
261
|
+
}
|
|
262
|
+
sendClient(opts, key) {
|
|
263
|
+
return opts._kind === "service" ? this.serviceSendClient(opts) : this.objectSendClient(opts, key);
|
|
253
264
|
}
|
|
254
265
|
scope(scopeKey) {
|
|
255
266
|
const conn = this.opts;
|
|
256
|
-
const scopedProxy = (component, key, send) => new Proxy({}, { get: (_target, prop) => {
|
|
267
|
+
const scopedProxy = (component, key, send, handlers) => new Proxy({}, { get: (_target, prop) => {
|
|
257
268
|
const handler = prop;
|
|
258
269
|
return (...args) => {
|
|
259
270
|
const { parameter, opts } = optsFromArgs(args);
|
|
@@ -264,17 +275,22 @@ var HttpIngress = class {
|
|
|
264
275
|
parameter,
|
|
265
276
|
opts,
|
|
266
277
|
send,
|
|
267
|
-
scope: scopeKey
|
|
278
|
+
scope: scopeKey,
|
|
279
|
+
handlerDesc: handlers?.[handler]
|
|
268
280
|
});
|
|
269
281
|
};
|
|
270
282
|
} });
|
|
271
283
|
return {
|
|
272
|
-
serviceClient: (opts) => scopedProxy(opts.name),
|
|
273
|
-
serviceSendClient: (opts) => scopedProxy(opts.name, void 0, true),
|
|
274
|
-
objectClient: (opts, key) => scopedProxy(opts.name, key),
|
|
275
|
-
objectSendClient: (opts, key) => scopedProxy(opts.name, key, true),
|
|
284
|
+
serviceClient: (opts) => scopedProxy(opts.name, void 0, void 0, opts._handlers),
|
|
285
|
+
serviceSendClient: (opts) => scopedProxy(opts.name, void 0, true, opts._handlers),
|
|
286
|
+
objectClient: (opts, key) => scopedProxy(opts.name, key, void 0, opts._handlers),
|
|
287
|
+
objectSendClient: (opts, key) => scopedProxy(opts.name, key, true, opts._handlers),
|
|
288
|
+
client: (opts, key) => opts._kind === "service" ? scopedProxy(opts.name, void 0, void 0, opts._handlers) : scopedProxy(opts.name, key, void 0, opts._handlers),
|
|
289
|
+
sendClient: (opts, key) => opts._kind === "service" ? scopedProxy(opts.name, void 0, true, opts._handlers) : scopedProxy(opts.name, key, true, opts._handlers),
|
|
276
290
|
workflowClient: (opts, key) => {
|
|
277
291
|
const component = opts.name;
|
|
292
|
+
const handlers = opts._handlers;
|
|
293
|
+
const runOutputSerde = handlers?.run?._outputSerde;
|
|
278
294
|
const workflowSubmit = async (...args) => {
|
|
279
295
|
const { parameter, opts: opts$1 } = optsFromArgs(args);
|
|
280
296
|
const res = await doComponentInvocation(conn, {
|
|
@@ -284,7 +300,8 @@ var HttpIngress = class {
|
|
|
284
300
|
send: true,
|
|
285
301
|
parameter,
|
|
286
302
|
opts: opts$1,
|
|
287
|
-
scope: scopeKey
|
|
303
|
+
scope: scopeKey,
|
|
304
|
+
handlerDesc: handlers?.run
|
|
288
305
|
}, true);
|
|
289
306
|
return {
|
|
290
307
|
invocationId: res.invocationId,
|
|
@@ -292,12 +309,12 @@ var HttpIngress = class {
|
|
|
292
309
|
attachable: true
|
|
293
310
|
};
|
|
294
311
|
};
|
|
295
|
-
const workflowAttach = (opts$1) => doWorkflowHandleCall(conn, component, key, "attach", opts$1);
|
|
312
|
+
const workflowAttach = (opts$1) => doWorkflowHandleCall(conn, component, key, "attach", opts$1, runOutputSerde);
|
|
296
313
|
const workflowOutput = async (opts$1) => {
|
|
297
314
|
try {
|
|
298
315
|
return {
|
|
299
316
|
ready: true,
|
|
300
|
-
result: await doWorkflowHandleCall(conn, component, key, "output", opts$1)
|
|
317
|
+
result: await doWorkflowHandleCall(conn, component, key, "output", opts$1, runOutputSerde)
|
|
301
318
|
};
|
|
302
319
|
} catch (e) {
|
|
303
320
|
if (!(e instanceof HttpCallError) || e.status !== 470) throw e;
|
|
@@ -322,7 +339,8 @@ var HttpIngress = class {
|
|
|
322
339
|
key,
|
|
323
340
|
parameter,
|
|
324
341
|
opts: opts$1,
|
|
325
|
-
scope: scopeKey
|
|
342
|
+
scope: scopeKey,
|
|
343
|
+
handlerDesc: handlers?.[handler]
|
|
326
344
|
});
|
|
327
345
|
};
|
|
328
346
|
} });
|
package/dist/ingress.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ingress.js","names":["status: number","responseText: string","message: string","parameter: unknown","opts: Opts<unknown, unknown> | SendOpts<unknown> | undefined","response: Response","errorBody: string","url: string","opts: ConnectionOpts","res: Send","opts","body","serde"],"sources":["../src/ingress.ts"],"sourcesContent":["/*\n * Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH\n *\n * This file is part of the Restate SDK for Node.js/TypeScript,\n * which is released under the MIT license.\n *\n * You can find a copy of the license in file LICENSE in the root\n * directory of this repository or package, or at\n * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE\n */\n\nimport {\n type Service,\n type ServiceDefinitionFrom,\n type VirtualObject,\n type WorkflowDefinitionFrom,\n type Workflow,\n type VirtualObjectDefinitionFrom,\n type Serde,\n serde,\n type JournalValueCodec,\n} from \"@restatedev/restate-sdk-core\";\nimport {\n ConnectionOpts,\n Ingress,\n IngressClient,\n IngressSendClient,\n IngressWorkflowClient,\n Output,\n Send,\n ScopedIngress,\n WorkflowSubmission,\n} from \"./api.js\";\n\nimport { Opts, SendOpts } from \"./api.js\";\nimport {\n abortableSleep,\n backoffDelay,\n defaultShouldRetry,\n parseRetryAfter,\n type ResolvedRetryPolicy,\n resolveRetryPolicy,\n} from \"./retry.js\";\n\n/**\n * Connect to the restate Ingress\n *\n * @param opts connection options\n * @returns a connection the the restate ingress\n */\nexport function connect(opts: ConnectionOpts): Ingress {\n return new HttpIngress(opts);\n}\n\nexport class HttpCallError extends Error {\n constructor(\n public readonly status: number,\n public readonly responseText: string,\n public override readonly message: string\n ) {\n super(message);\n }\n}\n\ntype InvocationParameters<I> = {\n component: string;\n handler: string;\n key?: string;\n send?: boolean;\n opts?: Opts<I, unknown> | SendOpts<I>;\n parameter?: I;\n method?: string;\n scope?: string;\n};\n\nfunction optsFromArgs(args: unknown[]): {\n parameter?: unknown;\n opts?: Opts<unknown, unknown> | SendOpts<unknown>;\n} {\n let parameter: unknown;\n let opts: Opts<unknown, unknown> | SendOpts<unknown> | undefined;\n switch (args.length) {\n case 0: {\n break;\n }\n case 1: {\n if (args[0] instanceof Opts) {\n opts = args[0];\n } else if (args[0] instanceof SendOpts) {\n opts = args[0];\n } else {\n parameter = args[0];\n }\n break;\n }\n case 2: {\n parameter = args[0];\n if (args[1] instanceof Opts) {\n opts = args[1];\n } else if (args[1] instanceof SendOpts) {\n opts = args[1];\n } else {\n throw new TypeError(\n \"The second argument must be either Opts or SendOpts\"\n );\n }\n break;\n }\n default: {\n throw new TypeError(\"unexpected number of arguments\");\n }\n }\n return {\n parameter,\n opts,\n };\n}\n\nconst IDEMPOTENCY_KEY_HEADER = \"idempotency-key\";\nconst LIMIT_KEY_HEADER = \"x-restate-limit-key\";\n// Carries the 1-based attempt number on every request so the server can observe\n// how many times the client has (re)issued it.\nconst ATTEMPT_HEADER = \"x-restateclient-retry-attempt\";\n\nconst getFetch = (opts: ConnectionOpts): NonNullable<ConnectionOpts[\"fetch\"]> =>\n opts.fetch ?? globalThis.fetch;\n\nconst fetchWithRetries = async (\n opts: ConnectionOpts,\n url: string,\n init: RequestInit,\n callOpts: Opts<unknown, unknown> | SendOpts<unknown> | undefined,\n retryPolicy: ResolvedRetryPolicy | undefined\n): Promise<Uint8Array> => {\n const userSignal = callOpts?.opts.signal;\n const timeout = callOpts?.opts.timeout;\n if (userSignal !== undefined && timeout !== undefined) {\n // The caller configured two mutually exclusive ways to abort each attempt.\n throw new Error(\n \"You can't specify both signal and timeout options at the same time\"\n );\n }\n // A fresh timeout signal is minted per attempt below — a single\n // AbortSignal.timeout() would already be aborted on the second attempt.\n const attemptSignal = (): AbortSignal | undefined =>\n userSignal ??\n (timeout !== undefined ? AbortSignal.timeout(timeout) : undefined);\n const shouldRetry = retryPolicy?.shouldRetry ?? defaultShouldRetry;\n\n // Whether waiting `delay` and then starting the next attempt would still fall\n // within the maxDuration budget (measured from the first attempt; a non-finite\n // maxDuration disables the bound). Checked *after* the delay is known so we\n // never sleep out a backoff — or a long Retry-After — only to give up on the\n // attempt it precedes. This is a decision-time gate only: it never aborts an\n // in-flight request. The maxAttempts count is gated separately, before the\n // delay is computed.\n const startTime = Date.now();\n const nextAttemptFitsBudget = (\n policy: ResolvedRetryPolicy,\n delay: number\n ): boolean => Date.now() - startTime + delay < policy.maxDuration;\n\n // Headers are always a plain record in this codebase; carry them forward and\n // stamp the attempt number afresh on each try.\n const baseHeaders = (init.headers ?? {}) as Record<string, string>;\n\n for (let attempt = 0; ; attempt++) {\n let response: Response;\n let errorBody: string;\n try {\n response = await getFetch(opts)(url, {\n ...init,\n headers: { ...baseHeaders, [ATTEMPT_HEADER]: String(attempt + 1) },\n signal: attemptSignal(),\n });\n if (response.ok) {\n // A 2xx response was received. Keep the body read inside this try so a\n // connection failure while streaming the body is retried as ambiguous.\n return new Uint8Array(await response.arrayBuffer());\n }\n // fetch resolves normally for non-2xx statuses. Read the body here both\n // for RetryFailure inspection and the final HttpCallError.\n errorBody = await response.text();\n } catch (e) {\n // fetch rejected, or the response body failed while streaming. Both are\n // ambiguous because the server may already have processed the request.\n if (\n retryPolicy &&\n attempt < retryPolicy.maxAttempts - 1 &&\n !userSignal?.aborted &&\n shouldRetry({ kind: \"network\", error: e }, attempt)\n ) {\n // Retries are enabled, attempts remain, the caller did not abort, and\n // the policy accepted this failure. Retry only if the backoff still\n // leaves us within the duration budget.\n const delay = backoffDelay(retryPolicy, attempt);\n if (nextAttemptFitsBudget(retryPolicy, delay)) {\n await abortableSleep(delay, userSignal);\n continue;\n }\n }\n // Retries are disabled or exhausted, the caller aborted, the policy\n // rejected this failure, or the duration budget is spent.\n throw e;\n }\n if (\n retryPolicy &&\n attempt < retryPolicy.maxAttempts - 1 &&\n !userSignal?.aborted &&\n shouldRetry(\n {\n kind: \"response\",\n status: response.status,\n headers: response.headers,\n body: errorBody || undefined,\n },\n attempt\n )\n ) {\n // A non-2xx response was received, attempts remain, and the policy chose\n // to retry it (by default, transient statuses 408/425/429/5xx, unless the\n // error is attributed to the invocation via x-restate-error-source). The\n // delay is the server's Retry-After when present, else the computed\n // backoff; either way we only retry if it still fits the duration budget.\n const retryAfter = retryPolicy.respectRetryAfter\n ? parseRetryAfter(response.headers)\n : undefined;\n const delay = retryAfter ?? backoffDelay(retryPolicy, attempt);\n if (nextAttemptFitsBudget(retryPolicy, delay)) {\n await abortableSleep(delay, userSignal);\n continue;\n }\n }\n // The response is not retryable, retries are disabled or exhausted, the\n // caller aborted, or the policy rejected this response.\n throw new HttpCallError(\n response.status,\n errorBody,\n `Request failed: ${response.status}\\n${errorBody}`\n );\n }\n};\n\nconst doComponentInvocation = async <I, O>(\n opts: ConnectionOpts,\n params: InvocationParameters<I>,\n canBeRetried = Boolean(params.opts?.opts.idempotencyKey)\n): Promise<O> => {\n let attachable = false;\n //\n // ingress URL\n //\n let url: string;\n if (params.scope) {\n // Scoped path: /restate/scope/{scope}/{call|send}/{service}/{key?}/{handler}\n const pathType = params.send ? \"send\" : \"call\";\n const parts = [\n opts.url,\n \"restate/scope\",\n encodeURIComponent(params.scope),\n pathType,\n params.component,\n ];\n if (params.key) {\n parts.push(encodeURIComponent(params.key));\n }\n parts.push(params.handler);\n url = parts.join(\"/\");\n if (params.send && params.opts instanceof SendOpts) {\n const delay = params.opts.delay();\n if (delay) url += `?delay=${delay}ms`;\n }\n } else {\n const fragments = [opts.url, params.component];\n if (params.key) {\n fragments.push(encodeURIComponent(params.key));\n }\n fragments.push(params.handler);\n if (params.send ?? false) {\n if (params.opts instanceof SendOpts) {\n fragments.push(computeDelayAsIso(params.opts));\n } else {\n fragments.push(\"send\");\n }\n }\n url = fragments.join(\"/\");\n }\n //\n // request body\n //\n const inputSerde = params.opts?.opts.input ?? opts.serde ?? serde.json;\n\n const { body, contentType } = serializeBodyWithContentType(\n params.parameter,\n inputSerde,\n opts.journalValueCodec\n );\n //\n // headers\n //\n const headers = {\n ...(opts.headers ?? {}),\n ...(params.opts?.opts?.headers ?? {}),\n };\n if (contentType) {\n headers[\"Content-Type\"] = contentType;\n }\n //\n // idempotency\n //\n const idempotencyKey = params.opts?.opts.idempotencyKey;\n if (idempotencyKey) {\n headers[IDEMPOTENCY_KEY_HEADER] = idempotencyKey;\n attachable = true;\n }\n //\n // limit key\n //\n const limitKey = params.opts?.opts.limitKey;\n if (limitKey) {\n headers[LIMIT_KEY_HEADER] = limitKey;\n }\n\n //\n // retries\n //\n // Regular invocations default eligibility from the idempotency key, while\n // workflow submissions opt in because the workflow ID identifies the run.\n const retryPolicy = canBeRetried ? resolveRetryPolicy(opts.retry) : undefined;\n\n //\n // make the call\n //\n const responseBuf = await fetchWithRetries(\n opts,\n url,\n {\n method: params.method ?? \"POST\",\n headers,\n body,\n },\n params.opts,\n retryPolicy\n );\n if (!params.send) {\n const decodedBuf = opts.journalValueCodec\n ? await opts.journalValueCodec.decode(responseBuf)\n : responseBuf;\n const outputSerde = params.opts?.opts.output ?? opts.serde ?? serde.json;\n return outputSerde.deserialize(decodedBuf) as O;\n }\n const json = serde.json.deserialize(responseBuf) as O;\n return { ...json, attachable };\n};\n\nconst doWorkflowHandleCall = async <O>(\n opts: ConnectionOpts,\n wfName: string,\n wfKey: string,\n op: \"output\" | \"attach\",\n callOpts?: Opts<unknown, O> | SendOpts<unknown>\n): Promise<O> => {\n const outputSerde = callOpts?.opts.output ?? opts.serde ?? serde.json;\n //\n // headers\n //\n const headers = {\n ...(opts.headers ?? {}),\n };\n //\n // make the call\n //\n const url = `${opts.url}/restate/workflow/${wfName}/${encodeURIComponent(\n wfKey\n )}/${op}`;\n // Attach and output only observe the existing workflow, so both are eligible\n // when the connection has a retry policy.\n const retryPolicy = resolveRetryPolicy(opts.retry);\n\n const responseBuf = await fetchWithRetries(\n opts,\n url,\n { method: \"GET\", headers },\n callOpts,\n retryPolicy\n );\n const decodedBuf = opts.journalValueCodec\n ? await opts.journalValueCodec.decode(responseBuf)\n : responseBuf;\n return outputSerde.deserialize(decodedBuf) as O;\n};\n\nclass HttpIngress implements Ingress {\n constructor(private readonly opts: ConnectionOpts) {}\n\n private proxy(component: string, key?: string, send?: boolean) {\n return new Proxy(\n {},\n {\n get: (_target, prop) => {\n const handler = prop as string;\n return (...args: unknown[]) => {\n const { parameter, opts } = optsFromArgs(args);\n return doComponentInvocation<unknown, unknown>(this.opts, {\n component,\n handler,\n key,\n parameter,\n opts,\n send,\n });\n };\n },\n }\n );\n }\n\n serviceClient<D>(opts: ServiceDefinitionFrom<D>): IngressClient<Service<D>> {\n return this.proxy(opts.name) as IngressClient<Service<D>>;\n }\n\n objectClient<D>(\n opts: VirtualObjectDefinitionFrom<D>,\n key: string\n ): IngressClient<VirtualObject<D>> {\n return this.proxy(opts.name, key) as IngressClient<VirtualObject<D>>;\n }\n\n workflowClient<D>(\n opts: WorkflowDefinitionFrom<D>,\n key: string\n ): IngressWorkflowClient<Workflow<D>> {\n const component = opts.name;\n const conn = this.opts;\n\n const workflowSubmit = async (\n ...args: unknown[]\n ): Promise<WorkflowSubmission<unknown>> => {\n const { parameter, opts } = optsFromArgs(args);\n const res: Send = await doComponentInvocation(\n conn,\n {\n component,\n handler: \"run\",\n key,\n send: true,\n parameter,\n opts,\n },\n true\n );\n\n return {\n invocationId: res.invocationId,\n status: res.status,\n attachable: true,\n };\n };\n\n const workflowAttach = (opts?: Opts<void, unknown>) =>\n doWorkflowHandleCall(conn, component, key, \"attach\", opts);\n\n const workflowOutput = async (\n opts?: Opts<void, unknown>\n ): Promise<Output<unknown>> => {\n try {\n const result = await doWorkflowHandleCall(\n conn,\n component,\n key,\n \"output\",\n opts\n );\n\n return {\n ready: true,\n result,\n };\n } catch (e) {\n if (!(e instanceof HttpCallError) || e.status !== 470) {\n throw e;\n }\n return {\n ready: false,\n get result() {\n throw new Error(\"Calling result() on a non ready workflow\");\n },\n };\n }\n };\n\n return new Proxy(\n {},\n {\n get: (_target, prop) => {\n const handler = prop as string;\n if (handler === \"workflowSubmit\") {\n return workflowSubmit;\n } else if (handler === \"workflowAttach\") {\n return workflowAttach;\n } else if (handler === \"workflowOutput\") {\n return workflowOutput;\n }\n // shared handlers pass trough via the ingress's normal invocation form\n // i.e. POST /<svc>/<key>/<handler>\n return (...args: unknown[]) => {\n const { parameter, opts } = optsFromArgs(args);\n return doComponentInvocation(conn, {\n component,\n handler,\n key,\n parameter,\n opts,\n });\n };\n },\n }\n ) as IngressWorkflowClient<Workflow<D>>;\n }\n\n objectSendClient<D>(\n opts: VirtualObjectDefinitionFrom<D>,\n key: string\n ): IngressSendClient<VirtualObject<D>> {\n return this.proxy(opts.name, key, true) as IngressSendClient<\n VirtualObject<D>\n >;\n }\n\n serviceSendClient<D>(\n opts: ServiceDefinitionFrom<D>\n ): IngressSendClient<Service<D>> {\n return this.proxy(opts.name, undefined, true) as IngressSendClient<\n Service<D>\n >;\n }\n\n scope(scopeKey: string): ScopedIngress {\n const conn = this.opts;\n const scopedProxy = (component: string, key?: string, send?: boolean) =>\n new Proxy(\n {},\n {\n get: (_target, prop) => {\n const handler = prop as string;\n return (...args: unknown[]) => {\n const { parameter, opts } = optsFromArgs(args);\n return doComponentInvocation<unknown, unknown>(conn, {\n component,\n handler,\n key,\n parameter,\n opts,\n send,\n scope: scopeKey,\n });\n };\n },\n }\n );\n\n return {\n serviceClient: <D>(opts: ServiceDefinitionFrom<D>) =>\n scopedProxy(opts.name) as IngressClient<Service<D>>,\n serviceSendClient: <D>(opts: ServiceDefinitionFrom<D>) =>\n scopedProxy(opts.name, undefined, true) as IngressSendClient<\n Service<D>\n >,\n objectClient: <D>(opts: VirtualObjectDefinitionFrom<D>, key: string) =>\n scopedProxy(opts.name, key) as IngressClient<VirtualObject<D>>,\n objectSendClient: <D>(\n opts: VirtualObjectDefinitionFrom<D>,\n key: string\n ) =>\n scopedProxy(opts.name, key, true) as IngressSendClient<\n VirtualObject<D>\n >,\n workflowClient: <D>(\n opts: WorkflowDefinitionFrom<D>,\n key: string\n ): IngressWorkflowClient<Workflow<D>> => {\n const component = opts.name;\n\n const workflowSubmit = async (\n ...args: unknown[]\n ): Promise<WorkflowSubmission<unknown>> => {\n const { parameter, opts } = optsFromArgs(args);\n const res: Send = await doComponentInvocation(\n conn,\n {\n component,\n handler: \"run\",\n key,\n send: true,\n parameter,\n opts,\n scope: scopeKey,\n },\n true\n );\n return {\n invocationId: res.invocationId,\n status: res.status,\n attachable: true,\n };\n };\n\n const workflowAttach = (opts?: Opts<void, unknown>) =>\n doWorkflowHandleCall(conn, component, key, \"attach\", opts);\n\n const workflowOutput = async (\n opts?: Opts<void, unknown>\n ): Promise<Output<unknown>> => {\n try {\n const result = await doWorkflowHandleCall(\n conn,\n component,\n key,\n \"output\",\n opts\n );\n return { ready: true, result };\n } catch (e) {\n if (!(e instanceof HttpCallError) || e.status !== 470) {\n throw e;\n }\n return {\n ready: false,\n get result() {\n throw new Error(\"Calling result() on a non ready workflow\");\n },\n };\n }\n };\n\n return new Proxy(\n {},\n {\n get: (_target, prop) => {\n const handler = prop as string;\n if (handler === \"workflowSubmit\") {\n return workflowSubmit;\n } else if (handler === \"workflowAttach\") {\n return workflowAttach;\n } else if (handler === \"workflowOutput\") {\n return workflowOutput;\n }\n return (...args: unknown[]) => {\n const { parameter, opts } = optsFromArgs(args);\n return doComponentInvocation(conn, {\n component,\n handler,\n key,\n parameter,\n opts,\n scope: scopeKey,\n });\n };\n },\n }\n ) as IngressWorkflowClient<Workflow<D>>;\n },\n };\n }\n\n async call<I, O>(opts: {\n service: string;\n handler: string;\n parameter: I;\n key?: string;\n scope?: string;\n opts?: Opts<I, O>;\n }): Promise<O> {\n return doComponentInvocation<I, O>(this.opts, {\n component: opts.service,\n handler: opts.handler,\n key: opts.key,\n scope: opts.scope,\n parameter: opts.parameter,\n send: false,\n opts: opts.opts,\n });\n }\n\n async send<I>(opts: {\n service: string;\n handler: string;\n parameter: I;\n key?: string;\n scope?: string;\n opts?: SendOpts<I>;\n }): Promise<Send> {\n return doComponentInvocation<I, Send>(this.opts, {\n component: opts.service,\n handler: opts.handler,\n key: opts.key,\n scope: opts.scope,\n parameter: opts.parameter,\n send: true,\n opts: opts.opts,\n });\n }\n\n async resolveAwakeable<T>(\n id: string,\n payload?: T,\n payloadSerde?: Serde<T>\n ): Promise<void> {\n const url = `${this.opts.url}/restate/a/${id}/resolve`;\n const { body, contentType } = serializeBodyWithContentType(\n payload,\n payloadSerde ?? this.opts.serde ?? serde.json,\n this.opts.journalValueCodec\n );\n const headers = {\n ...(this.opts.headers ?? {}),\n };\n if (contentType) {\n headers[\"Content-Type\"] = contentType;\n }\n const httpResponse = await getFetch(this.opts)(url, {\n method: \"POST\",\n headers,\n body,\n });\n if (!httpResponse.ok) {\n const body = await httpResponse.text();\n throw new HttpCallError(\n httpResponse.status,\n body,\n `Request failed: ${httpResponse.status}\\n${body}`\n );\n }\n }\n\n async rejectAwakeable(id: string, reason: string): Promise<void> {\n const url = `${this.opts.url}/restate/a/${id}/reject`;\n const headers = {\n \"Content-Type\": \"text/plain\",\n ...(this.opts.headers ?? {}),\n };\n const httpResponse = await getFetch(this.opts)(url, {\n method: \"POST\",\n headers,\n body: reason,\n });\n if (!httpResponse.ok) {\n const body = await httpResponse.text();\n throw new HttpCallError(\n httpResponse.status,\n body,\n `Request failed: ${httpResponse.status}\\n${body}`\n );\n }\n }\n\n async result<T>(\n send: Send<T> | WorkflowSubmission<T>,\n resultSerde?: Serde<T>\n ): Promise<T> {\n if (!send.attachable) {\n throw new Error(\n `Unable to fetch the result for ${send.invocationId}.\n A service's result is stored only with an idempotencyKey is supplied when invocating the service.`\n );\n }\n //\n // headers\n //\n const headers = {\n ...(this.opts.headers ?? {}),\n };\n //\n // make the call\n //\n const url = `${this.opts.url}/restate/invocation/${send.invocationId}/attach`;\n // Attaching only observes the existing invocation, so it is safe to retry\n // when the connection has a retry policy.\n const retryPolicy = resolveRetryPolicy(this.opts.retry);\n\n const responseBuf = await fetchWithRetries(\n this.opts,\n url,\n { method: \"GET\", headers },\n undefined,\n retryPolicy\n );\n const decodedBuf = this.opts.journalValueCodec\n ? await this.opts.journalValueCodec.decode(responseBuf)\n : responseBuf;\n return (resultSerde ?? this.opts.serde ?? serde.json).deserialize(\n decodedBuf\n ) as T;\n }\n}\n\nfunction computeDelayAsIso(opts: SendOpts): string {\n const delay = opts.delay();\n if (!delay) {\n return \"send\";\n }\n return `send?delay=${delay}ms`;\n}\n\nfunction serializeBodyWithContentType(\n body: unknown,\n serde: Serde<unknown>,\n journalValueCodec?: JournalValueCodec\n): {\n body?: Uint8Array;\n contentType?: string;\n} {\n let buffer = serde.serialize(body);\n if (journalValueCodec) {\n buffer = journalValueCodec.encode(buffer);\n }\n return {\n body: buffer,\n contentType: serde.contentType,\n };\n}\n"],"mappings":";;;;;;;;;;;AAkDA,SAAgB,QAAQ,MAA+B;AACrD,QAAO,IAAI,YAAY,KAAK;;AAG9B,IAAa,gBAAb,cAAmC,MAAM;CACvC,YACE,AAAgBA,QAChB,AAAgBC,cAChB,AAAyBC,SACzB;AACA,QAAM,QAAQ;EAJE;EACA;EACS;;;AAiB7B,SAAS,aAAa,MAGpB;CACA,IAAIC;CACJ,IAAIC;AACJ,SAAQ,KAAK,QAAb;EACE,KAAK,EACH;EAEF,KAAK;AACH,OAAI,KAAK,cAAc,KACrB,QAAO,KAAK;YACH,KAAK,cAAc,SAC5B,QAAO,KAAK;OAEZ,aAAY,KAAK;AAEnB;EAEF,KAAK;AACH,eAAY,KAAK;AACjB,OAAI,KAAK,cAAc,KACrB,QAAO,KAAK;YACH,KAAK,cAAc,SAC5B,QAAO,KAAK;OAEZ,OAAM,IAAI,UACR,sDACD;AAEH;EAEF,QACE,OAAM,IAAI,UAAU,iCAAiC;;AAGzD,QAAO;EACL;EACA;EACD;;AAGH,MAAM,yBAAyB;AAC/B,MAAM,mBAAmB;AAGzB,MAAM,iBAAiB;AAEvB,MAAM,YAAY,SAChB,KAAK,SAAS,WAAW;AAE3B,MAAM,mBAAmB,OACvB,MACA,KACA,MACA,UACA,gBACwB;CACxB,MAAM,aAAa,UAAU,KAAK;CAClC,MAAM,UAAU,UAAU,KAAK;AAC/B,KAAI,eAAe,UAAa,YAAY,OAE1C,OAAM,IAAI,MACR,qEACD;CAIH,MAAM,sBACJ,eACC,YAAY,SAAY,YAAY,QAAQ,QAAQ,GAAG;CAC1D,MAAM,cAAc,aAAa,eAAe;CAShD,MAAM,YAAY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;AACtC,SAAM,IAAI,cACR,aAAa,QACb,MACA,mBAAmB,aAAa,OAAO,IAAI,OAC5C;;;CAIL,MAAM,OACJ,MACA,aACY;AACZ,MAAI,CAAC,KAAK,WACR,OAAM,IAAI,MACR,kCAAkC,KAAK,aAAa;2GAErD;EAKH,MAAM,UAAU,EACd,GAAI,KAAK,KAAK,WAAW,EAAE,EAC5B;EAID,MAAM,MAAM,GAAG,KAAK,KAAK,IAAI,sBAAsB,KAAK,aAAa;EAGrE,MAAM,cAAc,mBAAmB,KAAK,KAAK,MAAM;EAEvD,MAAM,cAAc,MAAM,iBACxB,KAAK,MACL,KACA;GAAE,QAAQ;GAAO;GAAS,EAC1B,QACA,YACD;EACD,MAAM,aAAa,KAAK,KAAK,oBACzB,MAAM,KAAK,KAAK,kBAAkB,OAAO,YAAY,GACrD;AACJ,UAAQ,eAAe,KAAK,KAAK,SAAS,MAAM,MAAM,YACpD,WACD;;;AAIL,SAAS,kBAAkB,MAAwB;CACjD,MAAM,QAAQ,KAAK,OAAO;AAC1B,KAAI,CAAC,MACH,QAAO;AAET,QAAO,cAAc,MAAM;;AAG7B,SAAS,6BACP,MACA,SACA,mBAIA;CACA,IAAI,SAASC,QAAM,UAAU,KAAK;AAClC,KAAI,kBACF,UAAS,kBAAkB,OAAO,OAAO;AAE3C,QAAO;EACL,MAAM;EACN,aAAaA,QAAM;EACpB"}
|
|
1
|
+
{"version":3,"file":"ingress.js","names":["status: number","responseText: string","message: string","parameter: unknown","opts: Opts<unknown, unknown> | SendOpts<unknown> | undefined","response: Response","errorBody: string","url: string","opts: ConnectionOpts","res: Send","opts","body","serde"],"sources":["../src/ingress.ts"],"sourcesContent":["/*\n * Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH\n *\n * This file is part of the Restate SDK for Node.js/TypeScript,\n * which is released under the MIT license.\n *\n * You can find a copy of the license in file LICENSE in the root\n * directory of this repository or package, or at\n * https://github.com/restatedev/sdk-typescript/blob/main/LICENSE\n */\n// The client methods implement the overloaded `Ingress` interface (classic\n// definition OR service interface), which requires an `any` return on the\n// implementation signatures.\n/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport {\n type Serde,\n serde,\n type JournalValueCodec,\n type HandlerDescriptor,\n} from \"@restatedev/restate-sdk-core\";\nimport {\n ConnectionOpts,\n Ingress,\n Output,\n Send,\n ScopedIngress,\n WorkflowSubmission,\n} from \"./api.js\";\n\nimport { Opts, SendOpts } from \"./api.js\";\nimport {\n abortableSleep,\n backoffDelay,\n defaultShouldRetry,\n parseRetryAfter,\n type ResolvedRetryPolicy,\n resolveRetryPolicy,\n} from \"./retry.js\";\n\n/**\n * Connect to the restate Ingress\n *\n * @param opts connection options\n * @returns a connection the the restate ingress\n */\nexport function connect(opts: ConnectionOpts): Ingress {\n return new HttpIngress(opts);\n}\n\n/**\n * The runtime shape a client method needs off a definition value: the service\n * name, plus (for interface / `implement()` values) the per-handler serde\n * descriptors. Classic definitions carry no `_handlers`, so serde reuse is a\n * no-op for them.\n */\ntype ClientTarget = {\n name: string;\n _handlers?: Record<string, HandlerDescriptor>;\n _kind?: \"service\" | \"object\" | \"workflow\";\n};\n\nexport class HttpCallError extends Error {\n constructor(\n public readonly status: number,\n public readonly responseText: string,\n public override readonly message: string\n ) {\n super(message);\n }\n}\n\ntype InvocationParameters<I> = {\n component: string;\n handler: string;\n key?: string;\n send?: boolean;\n opts?: Opts<I, unknown> | SendOpts<I>;\n parameter?: I;\n method?: string;\n scope?: string;\n /** Serdes declared by the callee's service interface, if the client was built from one. */\n handlerDesc?: HandlerDescriptor;\n};\n\nfunction optsFromArgs(args: unknown[]): {\n parameter?: unknown;\n opts?: Opts<unknown, unknown> | SendOpts<unknown>;\n} {\n let parameter: unknown;\n let opts: Opts<unknown, unknown> | SendOpts<unknown> | undefined;\n switch (args.length) {\n case 0: {\n break;\n }\n case 1: {\n if (args[0] instanceof Opts) {\n opts = args[0];\n } else if (args[0] instanceof SendOpts) {\n opts = args[0];\n } else {\n parameter = args[0];\n }\n break;\n }\n case 2: {\n parameter = args[0];\n if (args[1] instanceof Opts) {\n opts = args[1];\n } else if (args[1] instanceof SendOpts) {\n opts = args[1];\n } else {\n throw new TypeError(\n \"The second argument must be either Opts or SendOpts\"\n );\n }\n break;\n }\n default: {\n throw new TypeError(\"unexpected number of arguments\");\n }\n }\n return {\n parameter,\n opts,\n };\n}\n\nconst IDEMPOTENCY_KEY_HEADER = \"idempotency-key\";\nconst LIMIT_KEY_HEADER = \"x-restate-limit-key\";\n// Carries the 1-based attempt number on every request so the server can observe\n// how many times the client has (re)issued it.\nconst ATTEMPT_HEADER = \"x-restateclient-retry-attempt\";\n\nconst getFetch = (opts: ConnectionOpts): NonNullable<ConnectionOpts[\"fetch\"]> =>\n opts.fetch ?? globalThis.fetch;\n\nconst fetchWithRetries = async (\n opts: ConnectionOpts,\n url: string,\n init: RequestInit,\n callOpts: Opts<unknown, unknown> | SendOpts<unknown> | undefined,\n retryPolicy: ResolvedRetryPolicy | undefined\n): Promise<Uint8Array> => {\n const userSignal = callOpts?.opts.signal;\n const timeout = callOpts?.opts.timeout;\n if (userSignal !== undefined && timeout !== undefined) {\n // The caller configured two mutually exclusive ways to abort each attempt.\n throw new Error(\n \"You can't specify both signal and timeout options at the same time\"\n );\n }\n // A fresh timeout signal is minted per attempt below — a single\n // AbortSignal.timeout() would already be aborted on the second attempt.\n const attemptSignal = (): AbortSignal | undefined =>\n userSignal ??\n (timeout !== undefined ? AbortSignal.timeout(timeout) : undefined);\n const shouldRetry = retryPolicy?.shouldRetry ?? defaultShouldRetry;\n\n // Whether waiting `delay` and then starting the next attempt would still fall\n // within the maxDuration budget (measured from the first attempt; a non-finite\n // maxDuration disables the bound). Checked *after* the delay is known so we\n // never sleep out a backoff — or a long Retry-After — only to give up on the\n // attempt it precedes. This is a decision-time gate only: it never aborts an\n // in-flight request. The maxAttempts count is gated separately, before the\n // delay is computed.\n const startTime = Date.now();\n const nextAttemptFitsBudget = (\n policy: ResolvedRetryPolicy,\n delay: number\n ): boolean => Date.now() - startTime + delay < policy.maxDuration;\n\n // Headers are always a plain record in this codebase; carry them forward and\n // stamp the attempt number afresh on each try.\n const baseHeaders = (init.headers ?? {}) as Record<string, string>;\n\n for (let attempt = 0; ; attempt++) {\n let response: Response;\n let errorBody: string;\n try {\n response = await getFetch(opts)(url, {\n ...init,\n headers: { ...baseHeaders, [ATTEMPT_HEADER]: String(attempt + 1) },\n signal: attemptSignal(),\n });\n if (response.ok) {\n // A 2xx response was received. Keep the body read inside this try so a\n // connection failure while streaming the body is retried as ambiguous.\n return new Uint8Array(await response.arrayBuffer());\n }\n // fetch resolves normally for non-2xx statuses. Read the body here both\n // for RetryFailure inspection and the final HttpCallError.\n errorBody = await response.text();\n } catch (e) {\n // fetch rejected, or the response body failed while streaming. Both are\n // ambiguous because the server may already have processed the request.\n if (\n retryPolicy &&\n attempt < retryPolicy.maxAttempts - 1 &&\n !userSignal?.aborted &&\n shouldRetry({ kind: \"network\", error: e }, attempt)\n ) {\n // Retries are enabled, attempts remain, the caller did not abort, and\n // the policy accepted this failure. Retry only if the backoff still\n // leaves us within the duration budget.\n const delay = backoffDelay(retryPolicy, attempt);\n if (nextAttemptFitsBudget(retryPolicy, delay)) {\n await abortableSleep(delay, userSignal);\n continue;\n }\n }\n // Retries are disabled or exhausted, the caller aborted, the policy\n // rejected this failure, or the duration budget is spent.\n throw e;\n }\n if (\n retryPolicy &&\n attempt < retryPolicy.maxAttempts - 1 &&\n !userSignal?.aborted &&\n shouldRetry(\n {\n kind: \"response\",\n status: response.status,\n headers: response.headers,\n body: errorBody || undefined,\n },\n attempt\n )\n ) {\n // A non-2xx response was received, attempts remain, and the policy chose\n // to retry it (by default, transient statuses 408/425/429/5xx, unless the\n // error is attributed to the invocation via x-restate-error-source). The\n // delay is the server's Retry-After when present, else the computed\n // backoff; either way we only retry if it still fits the duration budget.\n const retryAfter = retryPolicy.respectRetryAfter\n ? parseRetryAfter(response.headers)\n : undefined;\n const delay = retryAfter ?? backoffDelay(retryPolicy, attempt);\n if (nextAttemptFitsBudget(retryPolicy, delay)) {\n await abortableSleep(delay, userSignal);\n continue;\n }\n }\n // The response is not retryable, retries are disabled or exhausted, the\n // caller aborted, or the policy rejected this response.\n throw new HttpCallError(\n response.status,\n errorBody,\n `Request failed: ${response.status}\\n${errorBody}`\n );\n }\n};\n\nconst doComponentInvocation = async <I, O>(\n opts: ConnectionOpts,\n params: InvocationParameters<I>,\n canBeRetried = Boolean(params.opts?.opts.idempotencyKey)\n): Promise<O> => {\n let attachable = false;\n //\n // ingress URL\n //\n let url: string;\n if (params.scope) {\n // Scoped path: /restate/scope/{scope}/{call|send}/{service}/{key?}/{handler}\n const pathType = params.send ? \"send\" : \"call\";\n const parts = [\n opts.url,\n \"restate/scope\",\n encodeURIComponent(params.scope),\n pathType,\n params.component,\n ];\n if (params.key) {\n parts.push(encodeURIComponent(params.key));\n }\n parts.push(params.handler);\n url = parts.join(\"/\");\n if (params.send && params.opts instanceof SendOpts) {\n const delay = params.opts.delay();\n if (delay) url += `?delay=${delay}ms`;\n }\n } else {\n const fragments = [opts.url, params.component];\n if (params.key) {\n fragments.push(encodeURIComponent(params.key));\n }\n fragments.push(params.handler);\n if (params.send ?? false) {\n if (params.opts instanceof SendOpts) {\n fragments.push(computeDelayAsIso(params.opts));\n } else {\n fragments.push(\"send\");\n }\n }\n url = fragments.join(\"/\");\n }\n //\n // request body\n //\n const inputSerde =\n params.opts?.opts.input ??\n params.handlerDesc?._inputSerde ??\n opts.serde ??\n serde.json;\n\n const { body, contentType } = serializeBodyWithContentType(\n params.parameter,\n inputSerde,\n opts.journalValueCodec\n );\n //\n // headers\n //\n const headers = {\n ...(opts.headers ?? {}),\n ...(params.opts?.opts?.headers ?? {}),\n };\n if (contentType) {\n headers[\"Content-Type\"] = contentType;\n }\n //\n // idempotency\n //\n const idempotencyKey = params.opts?.opts.idempotencyKey;\n if (idempotencyKey) {\n headers[IDEMPOTENCY_KEY_HEADER] = idempotencyKey;\n attachable = true;\n }\n //\n // limit key\n //\n const limitKey = params.opts?.opts.limitKey;\n if (limitKey) {\n headers[LIMIT_KEY_HEADER] = limitKey;\n }\n\n //\n // retries\n //\n // Regular invocations default eligibility from the idempotency key, while\n // workflow submissions opt in because the workflow ID identifies the run.\n const retryPolicy = canBeRetried ? resolveRetryPolicy(opts.retry) : undefined;\n\n //\n // make the call\n //\n const responseBuf = await fetchWithRetries(\n opts,\n url,\n {\n method: params.method ?? \"POST\",\n headers,\n body,\n },\n params.opts,\n retryPolicy\n );\n if (!params.send) {\n const decodedBuf = opts.journalValueCodec\n ? await opts.journalValueCodec.decode(responseBuf)\n : responseBuf;\n const outputSerde =\n params.opts?.opts.output ??\n params.handlerDesc?._outputSerde ??\n opts.serde ??\n serde.json;\n return outputSerde.deserialize(decodedBuf) as O;\n }\n const json = serde.json.deserialize(responseBuf) as O;\n return { ...json, attachable };\n};\n\nconst doWorkflowHandleCall = async <O>(\n opts: ConnectionOpts,\n wfName: string,\n wfKey: string,\n op: \"output\" | \"attach\",\n callOpts?: Opts<unknown, O> | SendOpts<unknown>,\n runOutputSerde?: Serde<unknown>\n): Promise<O> => {\n const outputSerde =\n callOpts?.opts.output ?? runOutputSerde ?? opts.serde ?? serde.json;\n //\n // headers\n //\n const headers = {\n ...(opts.headers ?? {}),\n };\n //\n // make the call\n //\n const url = `${opts.url}/restate/workflow/${wfName}/${encodeURIComponent(\n wfKey\n )}/${op}`;\n // Attach and output only observe the existing workflow, so both are eligible\n // when the connection has a retry policy.\n const retryPolicy = resolveRetryPolicy(opts.retry);\n\n const responseBuf = await fetchWithRetries(\n opts,\n url,\n { method: \"GET\", headers },\n callOpts,\n retryPolicy\n );\n const decodedBuf = opts.journalValueCodec\n ? await opts.journalValueCodec.decode(responseBuf)\n : responseBuf;\n return outputSerde.deserialize(decodedBuf) as O;\n};\n\nclass HttpIngress implements Ingress {\n constructor(private readonly opts: ConnectionOpts) {}\n\n private proxy(\n component: string,\n key?: string,\n send?: boolean,\n handlers?: Record<string, HandlerDescriptor>\n ) {\n return new Proxy(\n {},\n {\n get: (_target, prop) => {\n const handler = prop as string;\n return (...args: unknown[]) => {\n const { parameter, opts } = optsFromArgs(args);\n return doComponentInvocation<unknown, unknown>(this.opts, {\n component,\n handler,\n key,\n parameter,\n opts,\n send,\n handlerDesc: handlers?.[handler],\n });\n };\n },\n }\n );\n }\n\n serviceClient(opts: ClientTarget): any {\n return this.proxy(opts.name, undefined, undefined, opts._handlers);\n }\n\n objectClient(opts: ClientTarget, key: string): any {\n return this.proxy(opts.name, key, undefined, opts._handlers);\n }\n\n workflowClient(opts: ClientTarget, key: string): any {\n const component = opts.name;\n const handlers = opts._handlers;\n const runOutputSerde = handlers?.run?._outputSerde;\n const conn = this.opts;\n\n const workflowSubmit = async (\n ...args: unknown[]\n ): Promise<WorkflowSubmission<unknown>> => {\n const { parameter, opts } = optsFromArgs(args);\n const res: Send = await doComponentInvocation(\n conn,\n {\n component,\n handler: \"run\",\n key,\n send: true,\n parameter,\n opts,\n handlerDesc: handlers?.run,\n },\n true\n );\n\n return {\n invocationId: res.invocationId,\n status: res.status,\n attachable: true,\n };\n };\n\n const workflowAttach = (opts?: Opts<void, unknown>) =>\n doWorkflowHandleCall(\n conn,\n component,\n key,\n \"attach\",\n opts,\n runOutputSerde\n );\n\n const workflowOutput = async (\n opts?: Opts<void, unknown>\n ): Promise<Output<unknown>> => {\n try {\n const result = await doWorkflowHandleCall(\n conn,\n component,\n key,\n \"output\",\n opts,\n runOutputSerde\n );\n\n return {\n ready: true,\n result,\n };\n } catch (e) {\n if (!(e instanceof HttpCallError) || e.status !== 470) {\n throw e;\n }\n return {\n ready: false,\n get result() {\n throw new Error(\"Calling result() on a non ready workflow\");\n },\n };\n }\n };\n\n return new Proxy(\n {},\n {\n get: (_target, prop) => {\n const handler = prop as string;\n if (handler === \"workflowSubmit\") {\n return workflowSubmit;\n } else if (handler === \"workflowAttach\") {\n return workflowAttach;\n } else if (handler === \"workflowOutput\") {\n return workflowOutput;\n }\n // shared handlers pass trough via the ingress's normal invocation form\n // i.e. POST /<svc>/<key>/<handler>\n return (...args: unknown[]) => {\n const { parameter, opts } = optsFromArgs(args);\n return doComponentInvocation(conn, {\n component,\n handler,\n key,\n parameter,\n opts,\n handlerDesc: handlers?.[handler],\n });\n };\n },\n }\n );\n }\n\n objectSendClient(opts: ClientTarget, key: string): any {\n return this.proxy(opts.name, key, true, opts._handlers);\n }\n\n serviceSendClient(opts: ClientTarget): any {\n return this.proxy(opts.name, undefined, true, opts._handlers);\n }\n\n // Factory that dispatches on the interface's kind — mirrors the generator\n // SDK's `client(ingress, def)` / `sendClient(ingress, def)` ergonomics.\n client(opts: ClientTarget, key?: string): any {\n return opts._kind === \"service\"\n ? this.serviceClient(opts)\n : this.objectClient(opts, key as string);\n }\n\n sendClient(opts: ClientTarget, key?: string): any {\n return opts._kind === \"service\"\n ? this.serviceSendClient(opts)\n : this.objectSendClient(opts, key as string);\n }\n\n scope(scopeKey: string): ScopedIngress {\n const conn = this.opts;\n const scopedProxy = (\n component: string,\n key?: string,\n send?: boolean,\n handlers?: Record<string, HandlerDescriptor>\n ) =>\n new Proxy(\n {},\n {\n get: (_target, prop) => {\n const handler = prop as string;\n return (...args: unknown[]) => {\n const { parameter, opts } = optsFromArgs(args);\n return doComponentInvocation<unknown, unknown>(conn, {\n component,\n handler,\n key,\n parameter,\n opts,\n send,\n scope: scopeKey,\n handlerDesc: handlers?.[handler],\n });\n };\n },\n }\n );\n\n return {\n serviceClient: (opts: ClientTarget): any =>\n scopedProxy(opts.name, undefined, undefined, opts._handlers),\n serviceSendClient: (opts: ClientTarget): any =>\n scopedProxy(opts.name, undefined, true, opts._handlers),\n objectClient: (opts: ClientTarget, key: string): any =>\n scopedProxy(opts.name, key, undefined, opts._handlers),\n objectSendClient: (opts: ClientTarget, key: string): any =>\n scopedProxy(opts.name, key, true, opts._handlers),\n client: (opts: ClientTarget, key?: string): any =>\n opts._kind === \"service\"\n ? scopedProxy(opts.name, undefined, undefined, opts._handlers)\n : scopedProxy(opts.name, key, undefined, opts._handlers),\n sendClient: (opts: ClientTarget, key?: string): any =>\n opts._kind === \"service\"\n ? scopedProxy(opts.name, undefined, true, opts._handlers)\n : scopedProxy(opts.name, key, true, opts._handlers),\n workflowClient: (opts: ClientTarget, key: string): any => {\n const component = opts.name;\n const handlers = opts._handlers;\n const runOutputSerde = handlers?.run?._outputSerde;\n\n const workflowSubmit = async (\n ...args: unknown[]\n ): Promise<WorkflowSubmission<unknown>> => {\n const { parameter, opts } = optsFromArgs(args);\n const res: Send = await doComponentInvocation(\n conn,\n {\n component,\n handler: \"run\",\n key,\n send: true,\n parameter,\n opts,\n scope: scopeKey,\n handlerDesc: handlers?.run,\n },\n true\n );\n return {\n invocationId: res.invocationId,\n status: res.status,\n attachable: true,\n };\n };\n\n const workflowAttach = (opts?: Opts<void, unknown>) =>\n doWorkflowHandleCall(\n conn,\n component,\n key,\n \"attach\",\n opts,\n runOutputSerde\n );\n\n const workflowOutput = async (\n opts?: Opts<void, unknown>\n ): Promise<Output<unknown>> => {\n try {\n const result = await doWorkflowHandleCall(\n conn,\n component,\n key,\n \"output\",\n opts,\n runOutputSerde\n );\n return { ready: true, result };\n } catch (e) {\n if (!(e instanceof HttpCallError) || e.status !== 470) {\n throw e;\n }\n return {\n ready: false,\n get result() {\n throw new Error(\"Calling result() on a non ready workflow\");\n },\n };\n }\n };\n\n return new Proxy(\n {},\n {\n get: (_target, prop) => {\n const handler = prop as string;\n if (handler === \"workflowSubmit\") {\n return workflowSubmit;\n } else if (handler === \"workflowAttach\") {\n return workflowAttach;\n } else if (handler === \"workflowOutput\") {\n return workflowOutput;\n }\n return (...args: unknown[]) => {\n const { parameter, opts } = optsFromArgs(args);\n return doComponentInvocation(conn, {\n component,\n handler,\n key,\n parameter,\n opts,\n scope: scopeKey,\n handlerDesc: handlers?.[handler],\n });\n };\n },\n }\n );\n },\n };\n }\n\n async call<I, O>(opts: {\n service: string;\n handler: string;\n parameter: I;\n key?: string;\n scope?: string;\n opts?: Opts<I, O>;\n }): Promise<O> {\n return doComponentInvocation<I, O>(this.opts, {\n component: opts.service,\n handler: opts.handler,\n key: opts.key,\n scope: opts.scope,\n parameter: opts.parameter,\n send: false,\n opts: opts.opts,\n });\n }\n\n async send<I>(opts: {\n service: string;\n handler: string;\n parameter: I;\n key?: string;\n scope?: string;\n opts?: SendOpts<I>;\n }): Promise<Send> {\n return doComponentInvocation<I, Send>(this.opts, {\n component: opts.service,\n handler: opts.handler,\n key: opts.key,\n scope: opts.scope,\n parameter: opts.parameter,\n send: true,\n opts: opts.opts,\n });\n }\n\n async resolveAwakeable<T>(\n id: string,\n payload?: T,\n payloadSerde?: Serde<T>\n ): Promise<void> {\n const url = `${this.opts.url}/restate/a/${id}/resolve`;\n const { body, contentType } = serializeBodyWithContentType(\n payload,\n payloadSerde ?? this.opts.serde ?? serde.json,\n this.opts.journalValueCodec\n );\n const headers = {\n ...(this.opts.headers ?? {}),\n };\n if (contentType) {\n headers[\"Content-Type\"] = contentType;\n }\n const httpResponse = await getFetch(this.opts)(url, {\n method: \"POST\",\n headers,\n body,\n });\n if (!httpResponse.ok) {\n const body = await httpResponse.text();\n throw new HttpCallError(\n httpResponse.status,\n body,\n `Request failed: ${httpResponse.status}\\n${body}`\n );\n }\n }\n\n async rejectAwakeable(id: string, reason: string): Promise<void> {\n const url = `${this.opts.url}/restate/a/${id}/reject`;\n const headers = {\n \"Content-Type\": \"text/plain\",\n ...(this.opts.headers ?? {}),\n };\n const httpResponse = await getFetch(this.opts)(url, {\n method: \"POST\",\n headers,\n body: reason,\n });\n if (!httpResponse.ok) {\n const body = await httpResponse.text();\n throw new HttpCallError(\n httpResponse.status,\n body,\n `Request failed: ${httpResponse.status}\\n${body}`\n );\n }\n }\n\n async result<T>(\n send: Send<T> | WorkflowSubmission<T>,\n resultSerde?: Serde<T>\n ): Promise<T> {\n if (!send.attachable) {\n throw new Error(\n `Unable to fetch the result for ${send.invocationId}.\n A service's result is stored only with an idempotencyKey is supplied when invocating the service.`\n );\n }\n //\n // headers\n //\n const headers = {\n ...(this.opts.headers ?? {}),\n };\n //\n // make the call\n //\n const url = `${this.opts.url}/restate/invocation/${send.invocationId}/attach`;\n // Attaching only observes the existing invocation, so it is safe to retry\n // when the connection has a retry policy.\n const retryPolicy = resolveRetryPolicy(this.opts.retry);\n\n const responseBuf = await fetchWithRetries(\n this.opts,\n url,\n { method: \"GET\", headers },\n undefined,\n retryPolicy\n );\n const decodedBuf = this.opts.journalValueCodec\n ? await this.opts.journalValueCodec.decode(responseBuf)\n : responseBuf;\n return (resultSerde ?? this.opts.serde ?? serde.json).deserialize(\n decodedBuf\n ) as T;\n }\n}\n\nfunction computeDelayAsIso(opts: SendOpts): string {\n const delay = opts.delay();\n if (!delay) {\n return \"send\";\n }\n return `send?delay=${delay}ms`;\n}\n\nfunction serializeBodyWithContentType(\n body: unknown,\n serde: Serde<unknown>,\n journalValueCodec?: JournalValueCodec\n): {\n body?: Uint8Array;\n contentType?: string;\n} {\n let buffer = serde.serialize(body);\n if (journalValueCodec) {\n buffer = journalValueCodec.encode(buffer);\n }\n return {\n body: buffer,\n contentType: serde.contentType,\n };\n}\n"],"mappings":";;;;;;;;;;;AA8CA,SAAgB,QAAQ,MAA+B;AACrD,QAAO,IAAI,YAAY,KAAK;;AAe9B,IAAa,gBAAb,cAAmC,MAAM;CACvC,YACE,AAAgBA,QAChB,AAAgBC,cAChB,AAAyBC,SACzB;AACA,QAAM,QAAQ;EAJE;EACA;EACS;;;AAmB7B,SAAS,aAAa,MAGpB;CACA,IAAIC;CACJ,IAAIC;AACJ,SAAQ,KAAK,QAAb;EACE,KAAK,EACH;EAEF,KAAK;AACH,OAAI,KAAK,cAAc,KACrB,QAAO,KAAK;YACH,KAAK,cAAc,SAC5B,QAAO,KAAK;OAEZ,aAAY,KAAK;AAEnB;EAEF,KAAK;AACH,eAAY,KAAK;AACjB,OAAI,KAAK,cAAc,KACrB,QAAO,KAAK;YACH,KAAK,cAAc,SAC5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AAK,KAAK,WAAW,EAAE;GAC5B;EACD,MAAM,eAAe,MAAM,SAAS,KAAK,KAAK,CAAC,KAAK;GAClD,QAAQ;GACR;GACA,MAAM;GACP,CAAC;AACF,MAAI,CAAC,aAAa,IAAI;GACpB,MAAM,OAAO,MAAM,aAAa,MAAM;AACtC,SAAM,IAAI,cACR,aAAa,QACb,MACA,mBAAmB,aAAa,OAAO,IAAI,OAC5C;;;CAIL,MAAM,OACJ,MACA,aACY;AACZ,MAAI,CAAC,KAAK,WACR,OAAM,IAAI,MACR,kCAAkC,KAAK,aAAa;2GAErD;EAKH,MAAM,UAAU,EACd,GAAI,KAAK,KAAK,WAAW,EAAE,EAC5B;EAID,MAAM,MAAM,GAAG,KAAK,KAAK,IAAI,sBAAsB,KAAK,aAAa;EAGrE,MAAM,cAAc,mBAAmB,KAAK,KAAK,MAAM;EAEvD,MAAM,cAAc,MAAM,iBACxB,KAAK,MACL,KACA;GAAE,QAAQ;GAAO;GAAS,EAC1B,QACA,YACD;EACD,MAAM,aAAa,KAAK,KAAK,oBACzB,MAAM,KAAK,KAAK,kBAAkB,OAAO,YAAY,GACrD;AACJ,UAAQ,eAAe,KAAK,KAAK,SAAS,MAAM,MAAM,YACpD,WACD;;;AAIL,SAAS,kBAAkB,MAAwB;CACjD,MAAM,QAAQ,KAAK,OAAO;AAC1B,KAAI,CAAC,MACH,QAAO;AAET,QAAO,cAAc,MAAM;;AAG7B,SAAS,6BACP,MACA,SACA,mBAIA;CACA,IAAI,SAASC,QAAM,UAAU,KAAK;AAClC,KAAI,kBACF,UAAS,kBAAkB,OAAO,OAAO;AAE3C,QAAO;EACL,MAAM;EACN,aAAaA,QAAM;EACpB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@restatedev/restate-sdk-clients",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.1",
|
|
4
4
|
"description": "Typescript SDK for Restate",
|
|
5
5
|
"author": "Restate Developers",
|
|
6
6
|
"email": "code@restate.dev",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@restatedev/restate-sdk-core": "1.
|
|
35
|
+
"@restatedev/restate-sdk-core": "1.17.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {},
|
|
38
38
|
"scripts": {
|