@restatedev/restate-sdk-clients 1.9.1 → 1.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/api.cjs +47 -0
- package/dist/api.d.cts +224 -0
- package/dist/api.d.cts.map +1 -0
- package/dist/api.d.ts +224 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +39 -0
- package/dist/api.js.map +1 -0
- package/dist/index.cjs +22 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/ingress.cjs +269 -0
- package/dist/ingress.d.cts +20 -0
- package/dist/ingress.d.cts.map +1 -0
- package/dist/ingress.d.ts +20 -0
- package/dist/ingress.d.ts.map +1 -0
- package/dist/ingress.js +267 -0
- package/dist/ingress.js.map +1 -0
- package/package.json +31 -39
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/src/api.d.ts +0 -225
- package/dist/cjs/src/api.d.ts.map +0 -1
- package/dist/cjs/src/api.js +0 -45
- package/dist/cjs/src/api.js.map +0 -1
- package/dist/cjs/src/ingress.d.ts +0 -15
- package/dist/cjs/src/ingress.d.ts.map +0 -1
- package/dist/cjs/src/ingress.js +0 -392
- package/dist/cjs/src/ingress.js.map +0 -1
- package/dist/cjs/src/public_api.d.ts +0 -7
- package/dist/cjs/src/public_api.d.ts.map +0 -1
- package/dist/cjs/src/public_api.js +0 -24
- package/dist/cjs/src/public_api.js.map +0 -1
- package/dist/cjs/tsconfig.tsbuildinfo +0 -1
- package/dist/esm/src/api.d.ts +0 -225
- package/dist/esm/src/api.d.ts.map +0 -1
- package/dist/esm/src/api.js +0 -40
- package/dist/esm/src/api.js.map +0 -1
- package/dist/esm/src/ingress.d.ts +0 -15
- package/dist/esm/src/ingress.d.ts.map +0 -1
- package/dist/esm/src/ingress.js +0 -387
- package/dist/esm/src/ingress.js.map +0 -1
- package/dist/esm/src/public_api.d.ts +0 -7
- package/dist/esm/src/public_api.d.ts.map +0 -1
- package/dist/esm/src/public_api.js +0 -15
- package/dist/esm/src/public_api.js.map +0 -1
- package/dist/esm/tsconfig.tsbuildinfo +0 -1
package/dist/esm/src/api.d.ts
DELETED
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
import type { Service, VirtualObjectDefinitionFrom, Workflow, VirtualObject, ServiceDefinitionFrom, WorkflowDefinitionFrom, Serde, Duration, JournalValueCodec } from "@restatedev/restate-sdk-core";
|
|
2
|
-
/**
|
|
3
|
-
* A remote client for a Restate service.
|
|
4
|
-
*
|
|
5
|
-
* Use the following client to interact with services defined
|
|
6
|
-
* - `serviceClient` to create a client for a service.
|
|
7
|
-
* - `workflowClient` to create a client for a workflow.
|
|
8
|
-
* - `objectClient` to create a client for a virtual object.
|
|
9
|
-
*
|
|
10
|
-
*/
|
|
11
|
-
export interface Ingress {
|
|
12
|
-
/**
|
|
13
|
-
* Create a client from a {@link ServiceDefinition}.
|
|
14
|
-
*/
|
|
15
|
-
serviceClient<D>(opts: ServiceDefinitionFrom<D>): IngressClient<Service<D>>;
|
|
16
|
-
/**
|
|
17
|
-
* Create a client from a {@link WorkflowDefinition}.
|
|
18
|
-
*
|
|
19
|
-
* @param key the key of the workflow.
|
|
20
|
-
*/
|
|
21
|
-
workflowClient<D>(opts: WorkflowDefinitionFrom<D>, key: string): IngressWorkflowClient<Workflow<D>>;
|
|
22
|
-
/**
|
|
23
|
-
* Create a client from a {@link VirtualObjectDefinition}.
|
|
24
|
-
* @param key the key of the virtual object.
|
|
25
|
-
*/
|
|
26
|
-
objectClient<D>(opts: VirtualObjectDefinitionFrom<D>, key: string): IngressClient<VirtualObject<D>>;
|
|
27
|
-
/**
|
|
28
|
-
* Create a client from a {@link ServiceDefinition}.
|
|
29
|
-
*/
|
|
30
|
-
serviceSendClient<D>(opts: ServiceDefinitionFrom<D>): IngressSendClient<Service<D>>;
|
|
31
|
-
/**
|
|
32
|
-
* Create a client from a {@link VirtualObjectDefinition}.
|
|
33
|
-
*/
|
|
34
|
-
objectSendClient<D>(opts: VirtualObjectDefinitionFrom<D>, key: string): IngressSendClient<VirtualObject<D>>;
|
|
35
|
-
/**
|
|
36
|
-
* Resolve an awakeable from the ingress client.
|
|
37
|
-
*/
|
|
38
|
-
resolveAwakeable<T>(id: string, payload?: T): Promise<void>;
|
|
39
|
-
/**
|
|
40
|
-
* Reject an awakeable from the ingress client.
|
|
41
|
-
*/
|
|
42
|
-
rejectAwakeable(id: string, reason: string): Promise<void>;
|
|
43
|
-
/**
|
|
44
|
-
* Obtain the result of a service that was asynchronously submitted (via a sendClient).
|
|
45
|
-
*
|
|
46
|
-
* @param send either the send response or the workflow submission as obtained by the respective clients.
|
|
47
|
-
*/
|
|
48
|
-
result<T>(send: Send<T> | WorkflowSubmission<T>): Promise<T>;
|
|
49
|
-
}
|
|
50
|
-
export interface IngressCallOptions<I = unknown, O = unknown> {
|
|
51
|
-
/**
|
|
52
|
-
* Key to use for idempotency key.
|
|
53
|
-
*
|
|
54
|
-
* See https://docs.restate.dev/operate/invocation#invoke-a-handler-idempotently for more details.
|
|
55
|
-
*/
|
|
56
|
-
idempotencyKey?: string;
|
|
57
|
-
/**
|
|
58
|
-
* Headers to attach to the request.
|
|
59
|
-
*/
|
|
60
|
-
headers?: Record<string, string>;
|
|
61
|
-
input?: Serde<I>;
|
|
62
|
-
output?: Serde<O>;
|
|
63
|
-
/**
|
|
64
|
-
* Timeout to be used when executing the request. In milliseconds.
|
|
65
|
-
*
|
|
66
|
-
* Same as {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal#aborting_a_fetch_with_timeout_or_explicit_abort | AbortSignal.timeout()}.
|
|
67
|
-
*
|
|
68
|
-
* This field is exclusive with `signal`, and using both of them will result in a runtime failure.
|
|
69
|
-
*/
|
|
70
|
-
timeout?: number;
|
|
71
|
-
/**
|
|
72
|
-
* Signal to abort the underlying `fetch` operation. See {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal}.
|
|
73
|
-
*
|
|
74
|
-
* This field is exclusive with `timeout`, and using both of them will result in a runtime failure.
|
|
75
|
-
*/
|
|
76
|
-
signal?: AbortSignal;
|
|
77
|
-
}
|
|
78
|
-
export interface IngressSendOptions<I> extends IngressCallOptions<I, void> {
|
|
79
|
-
/**
|
|
80
|
-
* If set, the invocation will be enqueued now to be executed after the provided delay. In milliseconds.
|
|
81
|
-
*/
|
|
82
|
-
delay?: number | Duration;
|
|
83
|
-
}
|
|
84
|
-
export declare class Opts<I, O> {
|
|
85
|
-
readonly opts: IngressCallOptions<I, O>;
|
|
86
|
-
/**
|
|
87
|
-
* Create a call configuration from the provided options.
|
|
88
|
-
*
|
|
89
|
-
* @param opts the call configuration
|
|
90
|
-
*/
|
|
91
|
-
static from<I = unknown, O = unknown>(opts: IngressCallOptions<I, O>): Opts<I, O>;
|
|
92
|
-
constructor(opts: IngressCallOptions<I, O>);
|
|
93
|
-
}
|
|
94
|
-
export declare class SendOpts<I = unknown> {
|
|
95
|
-
readonly opts: IngressSendOptions<I>;
|
|
96
|
-
/**
|
|
97
|
-
* @param opts Create send options
|
|
98
|
-
*/
|
|
99
|
-
static from<I = unknown>(opts: IngressSendOptions<I>): SendOpts<I>;
|
|
100
|
-
delay(): number | undefined;
|
|
101
|
-
constructor(opts: IngressSendOptions<I>);
|
|
102
|
-
}
|
|
103
|
-
export type InferArgType<P> = P extends [infer A, ...any[]] ? A : unknown;
|
|
104
|
-
export type IngressClient<M> = {
|
|
105
|
-
[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;
|
|
106
|
-
};
|
|
107
|
-
export declare namespace rpc {
|
|
108
|
-
const opts: <I, O>(opts: IngressCallOptions<I, O>) => Opts<I, O>;
|
|
109
|
-
const sendOpts: <I>(opts: IngressSendOptions<I>) => SendOpts<I>;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Represents the output of a workflow.
|
|
113
|
-
*/
|
|
114
|
-
export interface Output<O> {
|
|
115
|
-
/**
|
|
116
|
-
* Whether the output is ready.
|
|
117
|
-
*/
|
|
118
|
-
ready: boolean;
|
|
119
|
-
/**
|
|
120
|
-
* The output of the workflow.
|
|
121
|
-
*/
|
|
122
|
-
result: O;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Represents a successful workflow submission.
|
|
126
|
-
*
|
|
127
|
-
*/
|
|
128
|
-
export type WorkflowSubmission<T> = {
|
|
129
|
-
/**
|
|
130
|
-
* The invocation id of the workflow. You can use that id to
|
|
131
|
-
* with the introspection tools (restate cli, logging, metrics)
|
|
132
|
-
*
|
|
133
|
-
*/
|
|
134
|
-
readonly invocationId: string;
|
|
135
|
-
readonly status: "Accepted" | "PreviouslyAccepted";
|
|
136
|
-
readonly attachable: true;
|
|
137
|
-
};
|
|
138
|
-
/**
|
|
139
|
-
* A client for a workflow.
|
|
140
|
-
*
|
|
141
|
-
* This client represents the workflow definition, with the following additional methods:
|
|
142
|
-
* - `workflowSubmit` to submit the workflow.
|
|
143
|
-
* - `workflowAttach` to attach to the workflow and wait for its completion
|
|
144
|
-
* - `workflowOutput` to check if the workflow's output is ready/available.
|
|
145
|
-
*
|
|
146
|
-
* Once a workflow is submitted, it can be attached to, and the output can be retrieved.
|
|
147
|
-
*
|
|
148
|
-
* @typeParam M the type of the workflow.
|
|
149
|
-
*/
|
|
150
|
-
export type IngressWorkflowClient<M> = Omit<{
|
|
151
|
-
[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;
|
|
152
|
-
} & {
|
|
153
|
-
/**
|
|
154
|
-
* Submit this workflow.
|
|
155
|
-
*
|
|
156
|
-
* This instructs restate to execute the 'run' handler of the workflow, idempotently.
|
|
157
|
-
* The workflow will be executed asynchronously, and the promise will resolve when the workflow has been accepted.
|
|
158
|
-
* Please note that submitting a workflow does not wait for it to completion, and it is safe to retry the submission,
|
|
159
|
-
* in case of failure.
|
|
160
|
-
*
|
|
161
|
-
* @param argument the same argument type as defined by the 'run' handler.
|
|
162
|
-
*/
|
|
163
|
-
workflowSubmit: M extends Record<string, unknown> ? M["run"] extends (arg: any, ...args: infer I) => Promise<infer O> ? (...args: [...I, ...[opts?: SendOpts<InferArgType<I>>]]) => Promise<WorkflowSubmission<O>> : never : never;
|
|
164
|
-
/**
|
|
165
|
-
* Attach to this workflow.
|
|
166
|
-
*
|
|
167
|
-
* This instructs restate to attach to the workflow and wait for it to complete.
|
|
168
|
-
* It is only possible to 'attach' to a workflow that has been previously submitted.
|
|
169
|
-
* The promise will resolve when the workflow has completed either successfully with a result,
|
|
170
|
-
* or be rejected with an error.
|
|
171
|
-
* This operation is safe to retry many times, and it will always return the same result.
|
|
172
|
-
*
|
|
173
|
-
* @returns a promise that resolves when the workflow has completed.
|
|
174
|
-
*/
|
|
175
|
-
workflowAttach: M extends Record<string, unknown> ? M["run"] extends (...args: any) => Promise<infer O> ? (opts?: Opts<void, O>) => Promise<O> : never : never;
|
|
176
|
-
/**
|
|
177
|
-
* Try retrieving the output of this workflow.
|
|
178
|
-
*
|
|
179
|
-
* This instructs restate to check if the workflow's output is ready/available.
|
|
180
|
-
* The returned Output object will have a 'ready' field set to true if the output is ready.
|
|
181
|
-
* If the output is ready, the 'result' field will contain the output.
|
|
182
|
-
* note: that this operation will not wait for the workflow to complete, to do so use 'workflowAttach'.
|
|
183
|
-
*
|
|
184
|
-
* @returns a promise that resolves if the workflow's output is ready/available.
|
|
185
|
-
*/
|
|
186
|
-
workflowOutput: M extends Record<string, unknown> ? M["run"] extends (...args: any) => Promise<infer O> ? (opts?: Opts<void, O>) => Promise<Output<O>> : never : never;
|
|
187
|
-
}, "run">;
|
|
188
|
-
/**
|
|
189
|
-
* A send response.
|
|
190
|
-
*
|
|
191
|
-
* @typeParam T the type of the response.
|
|
192
|
-
*/
|
|
193
|
-
export type Send<T = unknown> = {
|
|
194
|
-
/**
|
|
195
|
-
* The invocation id of the send.
|
|
196
|
-
*/
|
|
197
|
-
invocationId: string;
|
|
198
|
-
/**
|
|
199
|
-
* The status of the send.
|
|
200
|
-
*/
|
|
201
|
-
status: "Accepted" | "PreviouslyAccepted";
|
|
202
|
-
attachable: boolean;
|
|
203
|
-
};
|
|
204
|
-
export type IngressSendClient<M> = {
|
|
205
|
-
[K in keyof M as M[K] extends never ? never : K]: M[K] extends (arg: any, ...args: infer P) => infer O ? (...args: [...P, ...[opts?: SendOpts<InferArgType<P>>]]) => Promise<Send<O>> : never;
|
|
206
|
-
};
|
|
207
|
-
export type ConnectionOpts = {
|
|
208
|
-
/**
|
|
209
|
-
* Restate ingress URL.
|
|
210
|
-
* For example: http://localhost:8080
|
|
211
|
-
*/
|
|
212
|
-
url: string;
|
|
213
|
-
/**
|
|
214
|
-
* Headers to attach on every request.
|
|
215
|
-
* Use this to attach authentication headers.
|
|
216
|
-
*/
|
|
217
|
-
headers?: Record<string, string>;
|
|
218
|
-
/**
|
|
219
|
-
* Codec to use for input/outputs. Check {@link JournalValueCodec} for more details
|
|
220
|
-
*
|
|
221
|
-
* @experimental
|
|
222
|
-
*/
|
|
223
|
-
journalValueCodec?: JournalValueCodec;
|
|
224
|
-
};
|
|
225
|
-
//# sourceMappingURL=api.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,2BAA2B,EAC3B,QAAQ,EACR,aAAa,EACb,qBAAqB,EACrB,sBAAsB,EACtB,KAAK,EACL,QAAQ,EACR,iBAAiB,EAClB,MAAM,8BAA8B,CAAC;AAKtC;;;;;;;;GAQG;AACH,MAAM,WAAW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|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { millisOrDurationToMillis } from "@restatedev/restate-sdk-core";
|
|
2
|
-
export class Opts {
|
|
3
|
-
opts;
|
|
4
|
-
/**
|
|
5
|
-
* Create a call configuration from the provided options.
|
|
6
|
-
*
|
|
7
|
-
* @param opts the call configuration
|
|
8
|
-
*/
|
|
9
|
-
static from(opts) {
|
|
10
|
-
return new Opts(opts);
|
|
11
|
-
}
|
|
12
|
-
constructor(opts) {
|
|
13
|
-
this.opts = opts;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
export class SendOpts {
|
|
17
|
-
opts;
|
|
18
|
-
/**
|
|
19
|
-
* @param opts Create send options
|
|
20
|
-
*/
|
|
21
|
-
static from(opts) {
|
|
22
|
-
return new SendOpts(opts);
|
|
23
|
-
}
|
|
24
|
-
delay() {
|
|
25
|
-
if (this.opts.delay !== undefined) {
|
|
26
|
-
return millisOrDurationToMillis(this.opts.delay);
|
|
27
|
-
}
|
|
28
|
-
return undefined;
|
|
29
|
-
}
|
|
30
|
-
constructor(opts) {
|
|
31
|
-
this.opts = opts;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
35
|
-
export var rpc;
|
|
36
|
-
(function (rpc) {
|
|
37
|
-
rpc.opts = (opts) => Opts.from(opts);
|
|
38
|
-
rpc.sendOpts = (opts) => SendOpts.from(opts);
|
|
39
|
-
})(rpc || (rpc = {}));
|
|
40
|
-
//# sourceMappingURL=api.js.map
|
package/dist/esm/src/api.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/api.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAgHxE,MAAM,OAAO,IAAI;IAYM;IAXrB;;;;OAIG;IACI,MAAM,CAAC,IAAI,CAChB,IAA8B;QAE9B,OAAO,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,YAAqB,IAA8B;QAA9B,SAAI,GAAJ,IAAI,CAA0B;IAAG,CAAC;CACxD;AAED,MAAM,OAAO,QAAQ;IAeE;IAdrB;;OAEG;IACI,MAAM,CAAC,IAAI,CAAc,IAA2B;QACzD,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAED,KAAK;QACH,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAClC,OAAO,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnD,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,YAAqB,IAA2B;QAA3B,SAAI,GAAJ,IAAI,CAAuB;IAAG,CAAC;CACrD;AAaD,2DAA2D;AAC3D,MAAM,KAAW,GAAG,CAKnB;AALD,WAAiB,GAAG;IACL,QAAI,GAAG,CAAO,IAA8B,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEjE,YAAQ,GAAG,CAAI,IAA2B,EAAE,EAAE,CACzD,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC,EALgB,GAAG,KAAH,GAAG,QAKnB"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { ConnectionOpts, Ingress } from "./api.js";
|
|
2
|
-
/**
|
|
3
|
-
* Connect to the restate Ingress
|
|
4
|
-
*
|
|
5
|
-
* @param opts connection options
|
|
6
|
-
* @returns a connection the the restate ingress
|
|
7
|
-
*/
|
|
8
|
-
export declare function connect(opts: ConnectionOpts): Ingress;
|
|
9
|
-
export declare class HttpCallError extends Error {
|
|
10
|
-
readonly status: number;
|
|
11
|
-
readonly responseText: string;
|
|
12
|
-
readonly message: string;
|
|
13
|
-
constructor(status: number, responseText: string, message: string);
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=ingress.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ingress.d.ts","sourceRoot":"","sources":["../../../src/ingress.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EACV,cAAc,EACd,OAAO,EAOR,MAAM,UAAU,CAAC;AAIlB;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAErD;AAED,qBAAa,aAAc,SAAQ,KAAK;aAEpB,MAAM,EAAE,MAAM;aACd,YAAY,EAAE,MAAM;aACpB,OAAO,EAAE,MAAM;gBAFf,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM;CAIlC"}
|
package/dist/esm/src/ingress.js
DELETED
|
@@ -1,387 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2023-2024 - Restate Software, Inc., Restate GmbH
|
|
3
|
-
*
|
|
4
|
-
* This file is part of the Restate SDK for Node.js/TypeScript,
|
|
5
|
-
* which is released under the MIT license.
|
|
6
|
-
*
|
|
7
|
-
* You can find a copy of the license in file LICENSE in the root
|
|
8
|
-
* directory of this repository or package, or at
|
|
9
|
-
* https://github.com/restatedev/sdk-typescript/blob/main/LICENSE
|
|
10
|
-
*/
|
|
11
|
-
import { serde, } from "@restatedev/restate-sdk-core";
|
|
12
|
-
import { Opts, SendOpts } from "./api.js";
|
|
13
|
-
/**
|
|
14
|
-
* Connect to the restate Ingress
|
|
15
|
-
*
|
|
16
|
-
* @param opts connection options
|
|
17
|
-
* @returns a connection the the restate ingress
|
|
18
|
-
*/
|
|
19
|
-
export function connect(opts) {
|
|
20
|
-
return new HttpIngress(opts);
|
|
21
|
-
}
|
|
22
|
-
export class HttpCallError extends Error {
|
|
23
|
-
status;
|
|
24
|
-
responseText;
|
|
25
|
-
message;
|
|
26
|
-
constructor(status, responseText, message) {
|
|
27
|
-
super(message);
|
|
28
|
-
this.status = status;
|
|
29
|
-
this.responseText = responseText;
|
|
30
|
-
this.message = message;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function optsFromArgs(args) {
|
|
34
|
-
let parameter;
|
|
35
|
-
let opts;
|
|
36
|
-
switch (args.length) {
|
|
37
|
-
case 0: {
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
case 1: {
|
|
41
|
-
if (args[0] instanceof Opts) {
|
|
42
|
-
opts = args[0];
|
|
43
|
-
}
|
|
44
|
-
else if (args[0] instanceof SendOpts) {
|
|
45
|
-
opts = args[0];
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
parameter = args[0];
|
|
49
|
-
}
|
|
50
|
-
break;
|
|
51
|
-
}
|
|
52
|
-
case 2: {
|
|
53
|
-
parameter = args[0];
|
|
54
|
-
if (args[1] instanceof Opts) {
|
|
55
|
-
opts = args[1];
|
|
56
|
-
}
|
|
57
|
-
else if (args[1] instanceof SendOpts) {
|
|
58
|
-
opts = args[1];
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
throw new TypeError("The second argument must be either Opts or SendOpts");
|
|
62
|
-
}
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
default: {
|
|
66
|
-
throw new TypeError("unexpected number of arguments");
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return {
|
|
70
|
-
parameter,
|
|
71
|
-
opts,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
const IDEMPOTENCY_KEY_HEADER = "idempotency-key";
|
|
75
|
-
const doComponentInvocation = async (opts, params) => {
|
|
76
|
-
let attachable = false;
|
|
77
|
-
const fragments = [];
|
|
78
|
-
//
|
|
79
|
-
// ingress URL
|
|
80
|
-
//
|
|
81
|
-
fragments.push(opts.url);
|
|
82
|
-
//
|
|
83
|
-
// component
|
|
84
|
-
//
|
|
85
|
-
fragments.push(params.component);
|
|
86
|
-
//
|
|
87
|
-
// has key?
|
|
88
|
-
//
|
|
89
|
-
if (params.key) {
|
|
90
|
-
const key = encodeURIComponent(params.key);
|
|
91
|
-
fragments.push(key);
|
|
92
|
-
}
|
|
93
|
-
//
|
|
94
|
-
// handler
|
|
95
|
-
//
|
|
96
|
-
fragments.push(params.handler);
|
|
97
|
-
if (params.send ?? false) {
|
|
98
|
-
if (params.opts instanceof SendOpts) {
|
|
99
|
-
const sendString = computeDelayAsIso(params.opts);
|
|
100
|
-
fragments.push(sendString);
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
103
|
-
fragments.push("send");
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
//
|
|
107
|
-
// request body
|
|
108
|
-
//
|
|
109
|
-
const inputSerde = params.opts?.opts.input ?? serde.json;
|
|
110
|
-
const { body, contentType } = serializeBodyWithContentType(params.parameter, inputSerde, opts.journalValueCodec);
|
|
111
|
-
//
|
|
112
|
-
// headers
|
|
113
|
-
//
|
|
114
|
-
const headers = {
|
|
115
|
-
...(opts.headers ?? {}),
|
|
116
|
-
...(params.opts?.opts?.headers ?? {}),
|
|
117
|
-
};
|
|
118
|
-
if (contentType) {
|
|
119
|
-
headers["Content-Type"] = contentType;
|
|
120
|
-
}
|
|
121
|
-
//
|
|
122
|
-
//idempotency
|
|
123
|
-
//
|
|
124
|
-
const idempotencyKey = params.opts?.opts.idempotencyKey;
|
|
125
|
-
if (idempotencyKey) {
|
|
126
|
-
headers[IDEMPOTENCY_KEY_HEADER] = idempotencyKey;
|
|
127
|
-
attachable = true;
|
|
128
|
-
}
|
|
129
|
-
// Abort signal, if any
|
|
130
|
-
let signal;
|
|
131
|
-
if (params.opts?.opts.signal !== undefined &&
|
|
132
|
-
params.opts?.opts.timeout !== undefined) {
|
|
133
|
-
throw new Error("You can't specify both signal and timeout options at the same time");
|
|
134
|
-
}
|
|
135
|
-
else if (params.opts?.opts.signal !== undefined) {
|
|
136
|
-
signal = params.opts?.opts.signal;
|
|
137
|
-
}
|
|
138
|
-
else if (params.opts?.opts.timeout !== undefined) {
|
|
139
|
-
signal = AbortSignal.timeout(params.opts?.opts.timeout);
|
|
140
|
-
}
|
|
141
|
-
//
|
|
142
|
-
// make the call
|
|
143
|
-
//
|
|
144
|
-
const url = fragments.join("/");
|
|
145
|
-
const httpResponse = await fetch(url, {
|
|
146
|
-
method: params.method ?? "POST",
|
|
147
|
-
headers,
|
|
148
|
-
body,
|
|
149
|
-
signal,
|
|
150
|
-
});
|
|
151
|
-
if (!httpResponse.ok) {
|
|
152
|
-
const body = await httpResponse.text();
|
|
153
|
-
throw new HttpCallError(httpResponse.status, body, `Request failed: ${httpResponse.status}\n${body}`);
|
|
154
|
-
}
|
|
155
|
-
const responseBuf = new Uint8Array(await httpResponse.arrayBuffer());
|
|
156
|
-
if (!params.send) {
|
|
157
|
-
const decodedBuf = opts.journalValueCodec
|
|
158
|
-
? await opts.journalValueCodec.decode(responseBuf)
|
|
159
|
-
: responseBuf;
|
|
160
|
-
const outputSerde = params.opts?.opts.output ?? serde.json;
|
|
161
|
-
return outputSerde.deserialize(decodedBuf);
|
|
162
|
-
}
|
|
163
|
-
const json = serde.json.deserialize(responseBuf);
|
|
164
|
-
return { ...json, attachable };
|
|
165
|
-
};
|
|
166
|
-
const doWorkflowHandleCall = async (opts, wfName, wfKey, op, callOpts) => {
|
|
167
|
-
const outputSerde = callOpts?.opts.output ?? serde.json;
|
|
168
|
-
//
|
|
169
|
-
// headers
|
|
170
|
-
//
|
|
171
|
-
const headers = {
|
|
172
|
-
...(opts.headers ?? {}),
|
|
173
|
-
};
|
|
174
|
-
//
|
|
175
|
-
// make the call
|
|
176
|
-
//
|
|
177
|
-
const url = `${opts.url}/restate/workflow/${wfName}/${encodeURIComponent(wfKey)}/${op}`;
|
|
178
|
-
// Abort signal, if any
|
|
179
|
-
let signal;
|
|
180
|
-
if (callOpts?.opts?.signal !== undefined &&
|
|
181
|
-
callOpts?.opts?.timeout !== undefined) {
|
|
182
|
-
throw new Error("You can't specify both signal and timeout options at the same time");
|
|
183
|
-
}
|
|
184
|
-
else if (callOpts?.opts?.signal !== undefined) {
|
|
185
|
-
signal = callOpts?.opts?.signal;
|
|
186
|
-
}
|
|
187
|
-
else if (callOpts?.opts?.timeout !== undefined) {
|
|
188
|
-
signal = AbortSignal.timeout(callOpts?.opts?.timeout);
|
|
189
|
-
}
|
|
190
|
-
const httpResponse = await fetch(url, {
|
|
191
|
-
method: "GET",
|
|
192
|
-
headers,
|
|
193
|
-
signal,
|
|
194
|
-
});
|
|
195
|
-
if (httpResponse.ok) {
|
|
196
|
-
const responseBuf = new Uint8Array(await httpResponse.arrayBuffer());
|
|
197
|
-
const decodedBuf = opts.journalValueCodec
|
|
198
|
-
? await opts.journalValueCodec.decode(responseBuf)
|
|
199
|
-
: responseBuf;
|
|
200
|
-
return outputSerde.deserialize(decodedBuf);
|
|
201
|
-
}
|
|
202
|
-
const body = await httpResponse.text();
|
|
203
|
-
throw new HttpCallError(httpResponse.status, body, `Request failed: ${httpResponse.status}\n${body}`);
|
|
204
|
-
};
|
|
205
|
-
class HttpIngress {
|
|
206
|
-
opts;
|
|
207
|
-
constructor(opts) {
|
|
208
|
-
this.opts = opts;
|
|
209
|
-
}
|
|
210
|
-
proxy(component, key, send) {
|
|
211
|
-
return new Proxy({}, {
|
|
212
|
-
get: (_target, prop) => {
|
|
213
|
-
const handler = prop;
|
|
214
|
-
return (...args) => {
|
|
215
|
-
const { parameter, opts } = optsFromArgs(args);
|
|
216
|
-
return doComponentInvocation(this.opts, {
|
|
217
|
-
component,
|
|
218
|
-
handler,
|
|
219
|
-
key,
|
|
220
|
-
parameter,
|
|
221
|
-
opts,
|
|
222
|
-
send,
|
|
223
|
-
});
|
|
224
|
-
};
|
|
225
|
-
},
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
serviceClient(opts) {
|
|
229
|
-
return this.proxy(opts.name);
|
|
230
|
-
}
|
|
231
|
-
objectClient(opts, key) {
|
|
232
|
-
return this.proxy(opts.name, key);
|
|
233
|
-
}
|
|
234
|
-
workflowClient(opts, key) {
|
|
235
|
-
const component = opts.name;
|
|
236
|
-
const conn = this.opts;
|
|
237
|
-
const workflowSubmit = async (parameter, opts) => {
|
|
238
|
-
const res = await doComponentInvocation(conn, {
|
|
239
|
-
component,
|
|
240
|
-
handler: "run",
|
|
241
|
-
key,
|
|
242
|
-
send: true,
|
|
243
|
-
parameter,
|
|
244
|
-
opts,
|
|
245
|
-
});
|
|
246
|
-
return {
|
|
247
|
-
invocationId: res.invocationId,
|
|
248
|
-
status: res.status,
|
|
249
|
-
attachable: true,
|
|
250
|
-
};
|
|
251
|
-
};
|
|
252
|
-
const workflowAttach = (opts) => doWorkflowHandleCall(conn, component, key, "attach", opts);
|
|
253
|
-
const workflowOutput = async (opts) => {
|
|
254
|
-
try {
|
|
255
|
-
const result = await doWorkflowHandleCall(conn, component, key, "output", opts);
|
|
256
|
-
return {
|
|
257
|
-
ready: true,
|
|
258
|
-
result,
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
catch (e) {
|
|
262
|
-
if (!(e instanceof HttpCallError) || e.status !== 470) {
|
|
263
|
-
throw e;
|
|
264
|
-
}
|
|
265
|
-
return {
|
|
266
|
-
ready: false,
|
|
267
|
-
get result() {
|
|
268
|
-
throw new Error("Calling result() on a non ready workflow");
|
|
269
|
-
},
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
};
|
|
273
|
-
return new Proxy({}, {
|
|
274
|
-
get: (_target, prop) => {
|
|
275
|
-
const handler = prop;
|
|
276
|
-
if (handler === "workflowSubmit") {
|
|
277
|
-
return workflowSubmit;
|
|
278
|
-
}
|
|
279
|
-
else if (handler === "workflowAttach") {
|
|
280
|
-
return workflowAttach;
|
|
281
|
-
}
|
|
282
|
-
else if (handler === "workflowOutput") {
|
|
283
|
-
return workflowOutput;
|
|
284
|
-
}
|
|
285
|
-
// shared handlers pass trough via the ingress's normal invocation form
|
|
286
|
-
// i.e. POST /<svc>/<key>/<handler>
|
|
287
|
-
return (...args) => {
|
|
288
|
-
const { parameter, opts } = optsFromArgs(args);
|
|
289
|
-
return doComponentInvocation(conn, {
|
|
290
|
-
component,
|
|
291
|
-
handler,
|
|
292
|
-
key,
|
|
293
|
-
parameter,
|
|
294
|
-
opts,
|
|
295
|
-
});
|
|
296
|
-
};
|
|
297
|
-
},
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
objectSendClient(opts, key) {
|
|
301
|
-
return this.proxy(opts.name, key, true);
|
|
302
|
-
}
|
|
303
|
-
serviceSendClient(opts) {
|
|
304
|
-
return this.proxy(opts.name, undefined, true);
|
|
305
|
-
}
|
|
306
|
-
async resolveAwakeable(id, payload, payloadSerde) {
|
|
307
|
-
const url = `${this.opts.url}/restate/a/${id}/resolve`;
|
|
308
|
-
const { body, contentType } = serializeBodyWithContentType(payload, payloadSerde ?? serde.json, this.opts.journalValueCodec);
|
|
309
|
-
const headers = {
|
|
310
|
-
...(this.opts.headers ?? {}),
|
|
311
|
-
};
|
|
312
|
-
if (contentType) {
|
|
313
|
-
headers["Content-Type"] = contentType;
|
|
314
|
-
}
|
|
315
|
-
const httpResponse = await fetch(url, {
|
|
316
|
-
method: "POST",
|
|
317
|
-
headers,
|
|
318
|
-
body,
|
|
319
|
-
});
|
|
320
|
-
if (!httpResponse.ok) {
|
|
321
|
-
const body = await httpResponse.text();
|
|
322
|
-
throw new HttpCallError(httpResponse.status, body, `Request failed: ${httpResponse.status}\n${body}`);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
async rejectAwakeable(id, reason) {
|
|
326
|
-
const url = `${this.opts.url}/restate/a/${id}/reject`;
|
|
327
|
-
const headers = {
|
|
328
|
-
"Content-Type": "text/plain",
|
|
329
|
-
...(this.opts.headers ?? {}),
|
|
330
|
-
};
|
|
331
|
-
const httpResponse = await fetch(url, {
|
|
332
|
-
method: "POST",
|
|
333
|
-
headers,
|
|
334
|
-
body: reason,
|
|
335
|
-
});
|
|
336
|
-
if (!httpResponse.ok) {
|
|
337
|
-
const body = await httpResponse.text();
|
|
338
|
-
throw new HttpCallError(httpResponse.status, body, `Request failed: ${httpResponse.status}\n${body}`);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
async result(send, resultSerde) {
|
|
342
|
-
if (!send.attachable) {
|
|
343
|
-
throw new Error(`Unable to fetch the result for ${send.invocationId}.
|
|
344
|
-
A service's result is stored only with an idempotencyKey is supplied when invocating the service.`);
|
|
345
|
-
}
|
|
346
|
-
//
|
|
347
|
-
// headers
|
|
348
|
-
//
|
|
349
|
-
const headers = {
|
|
350
|
-
...(this.opts.headers ?? {}),
|
|
351
|
-
};
|
|
352
|
-
//
|
|
353
|
-
// make the call
|
|
354
|
-
const url = `${this.opts.url}/restate/invocation/${send.invocationId}/attach`;
|
|
355
|
-
const httpResponse = await fetch(url, {
|
|
356
|
-
method: "GET",
|
|
357
|
-
headers,
|
|
358
|
-
});
|
|
359
|
-
if (httpResponse.ok) {
|
|
360
|
-
const responseBuf = new Uint8Array(await httpResponse.arrayBuffer());
|
|
361
|
-
const decodedBuf = this.opts.journalValueCodec
|
|
362
|
-
? await this.opts.journalValueCodec.decode(responseBuf)
|
|
363
|
-
: responseBuf;
|
|
364
|
-
return (resultSerde ?? serde.json).deserialize(decodedBuf);
|
|
365
|
-
}
|
|
366
|
-
const body = await httpResponse.text();
|
|
367
|
-
throw new HttpCallError(httpResponse.status, body, `Request failed: ${httpResponse.status}\n${body}`);
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
function computeDelayAsIso(opts) {
|
|
371
|
-
const delay = opts.delay();
|
|
372
|
-
if (!delay) {
|
|
373
|
-
return "send";
|
|
374
|
-
}
|
|
375
|
-
return `send?delay=${delay}ms`;
|
|
376
|
-
}
|
|
377
|
-
function serializeBodyWithContentType(body, serde, journalValueCodec) {
|
|
378
|
-
let buffer = serde.serialize(body);
|
|
379
|
-
if (journalValueCodec) {
|
|
380
|
-
buffer = journalValueCodec.encode(buffer);
|
|
381
|
-
}
|
|
382
|
-
return {
|
|
383
|
-
body: buffer,
|
|
384
|
-
contentType: serde.contentType,
|
|
385
|
-
};
|
|
386
|
-
}
|
|
387
|
-
//# sourceMappingURL=ingress.js.map
|