@restatedev/restate-sdk-clients 1.9.1 → 1.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/_virtual/rolldown_runtime.cjs +25 -0
- package/dist/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/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ConnectionOpts, InferArgType, Ingress, IngressCallOptions, IngressClient, IngressSendClient, IngressSendOptions, IngressWorkflowClient, Opts, Output, Send, SendOpts, WorkflowSubmission, rpc } from "./api.js";
|
|
2
|
+
import { HttpCallError, connect } from "./ingress.js";
|
|
3
|
+
import { Duration, JournalValueCodec, Serde, Service, ServiceDefinition, ServiceDefinitionFrom, VirtualObject, VirtualObjectDefinition, VirtualObjectDefinitionFrom, Workflow, WorkflowDefinition, WorkflowDefinitionFrom, serde } from "@restatedev/restate-sdk-core";
|
|
4
|
+
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 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, rpc, serde };
|
|
@@ -0,0 +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,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,EAClB,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"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAiBH,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AAerD,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"}
|
package/dist/ingress.cjs
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_api = require('./api.cjs');
|
|
3
|
+
let __restatedev_restate_sdk_core = require("@restatedev/restate-sdk-core");
|
|
4
|
+
__restatedev_restate_sdk_core = require_rolldown_runtime.__toESM(__restatedev_restate_sdk_core);
|
|
5
|
+
|
|
6
|
+
//#region src/ingress.ts
|
|
7
|
+
/**
|
|
8
|
+
* Connect to the restate Ingress
|
|
9
|
+
*
|
|
10
|
+
* @param opts connection options
|
|
11
|
+
* @returns a connection the the restate ingress
|
|
12
|
+
*/
|
|
13
|
+
function connect(opts) {
|
|
14
|
+
return new HttpIngress(opts);
|
|
15
|
+
}
|
|
16
|
+
var HttpCallError = class extends Error {
|
|
17
|
+
constructor(status, responseText, message) {
|
|
18
|
+
super(message);
|
|
19
|
+
this.status = status;
|
|
20
|
+
this.responseText = responseText;
|
|
21
|
+
this.message = message;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
function optsFromArgs(args) {
|
|
25
|
+
let parameter;
|
|
26
|
+
let opts;
|
|
27
|
+
switch (args.length) {
|
|
28
|
+
case 0: break;
|
|
29
|
+
case 1:
|
|
30
|
+
if (args[0] instanceof require_api.Opts) opts = args[0];
|
|
31
|
+
else if (args[0] instanceof require_api.SendOpts) opts = args[0];
|
|
32
|
+
else parameter = args[0];
|
|
33
|
+
break;
|
|
34
|
+
case 2:
|
|
35
|
+
parameter = args[0];
|
|
36
|
+
if (args[1] instanceof require_api.Opts) opts = args[1];
|
|
37
|
+
else if (args[1] instanceof require_api.SendOpts) opts = args[1];
|
|
38
|
+
else throw new TypeError("The second argument must be either Opts or SendOpts");
|
|
39
|
+
break;
|
|
40
|
+
default: throw new TypeError("unexpected number of arguments");
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
parameter,
|
|
44
|
+
opts
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const IDEMPOTENCY_KEY_HEADER = "idempotency-key";
|
|
48
|
+
const doComponentInvocation = async (opts, params) => {
|
|
49
|
+
let attachable = false;
|
|
50
|
+
const fragments = [];
|
|
51
|
+
fragments.push(opts.url);
|
|
52
|
+
fragments.push(params.component);
|
|
53
|
+
if (params.key) {
|
|
54
|
+
const key = encodeURIComponent(params.key);
|
|
55
|
+
fragments.push(key);
|
|
56
|
+
}
|
|
57
|
+
fragments.push(params.handler);
|
|
58
|
+
if (params.send ?? false) if (params.opts instanceof require_api.SendOpts) {
|
|
59
|
+
const sendString = computeDelayAsIso(params.opts);
|
|
60
|
+
fragments.push(sendString);
|
|
61
|
+
} else fragments.push("send");
|
|
62
|
+
const inputSerde = params.opts?.opts.input ?? __restatedev_restate_sdk_core.serde.json;
|
|
63
|
+
const { body, contentType } = serializeBodyWithContentType(params.parameter, inputSerde, opts.journalValueCodec);
|
|
64
|
+
const headers = {
|
|
65
|
+
...opts.headers ?? {},
|
|
66
|
+
...params.opts?.opts?.headers ?? {}
|
|
67
|
+
};
|
|
68
|
+
if (contentType) headers["Content-Type"] = contentType;
|
|
69
|
+
const idempotencyKey = params.opts?.opts.idempotencyKey;
|
|
70
|
+
if (idempotencyKey) {
|
|
71
|
+
headers[IDEMPOTENCY_KEY_HEADER] = idempotencyKey;
|
|
72
|
+
attachable = true;
|
|
73
|
+
}
|
|
74
|
+
let signal;
|
|
75
|
+
if (params.opts?.opts.signal !== void 0 && params.opts?.opts.timeout !== void 0) throw new Error("You can't specify both signal and timeout options at the same time");
|
|
76
|
+
else if (params.opts?.opts.signal !== void 0) signal = params.opts?.opts.signal;
|
|
77
|
+
else if (params.opts?.opts.timeout !== void 0) signal = AbortSignal.timeout(params.opts?.opts.timeout);
|
|
78
|
+
const url = fragments.join("/");
|
|
79
|
+
const httpResponse = await fetch(url, {
|
|
80
|
+
method: params.method ?? "POST",
|
|
81
|
+
headers,
|
|
82
|
+
body,
|
|
83
|
+
signal
|
|
84
|
+
});
|
|
85
|
+
if (!httpResponse.ok) {
|
|
86
|
+
const body$1 = await httpResponse.text();
|
|
87
|
+
throw new HttpCallError(httpResponse.status, body$1, `Request failed: ${httpResponse.status}\n${body$1}`);
|
|
88
|
+
}
|
|
89
|
+
const responseBuf = new Uint8Array(await httpResponse.arrayBuffer());
|
|
90
|
+
if (!params.send) {
|
|
91
|
+
const decodedBuf = opts.journalValueCodec ? await opts.journalValueCodec.decode(responseBuf) : responseBuf;
|
|
92
|
+
return (params.opts?.opts.output ?? __restatedev_restate_sdk_core.serde.json).deserialize(decodedBuf);
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
...__restatedev_restate_sdk_core.serde.json.deserialize(responseBuf),
|
|
96
|
+
attachable
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
const doWorkflowHandleCall = async (opts, wfName, wfKey, op, callOpts) => {
|
|
100
|
+
const outputSerde = callOpts?.opts.output ?? __restatedev_restate_sdk_core.serde.json;
|
|
101
|
+
const headers = { ...opts.headers ?? {} };
|
|
102
|
+
const url = `${opts.url}/restate/workflow/${wfName}/${encodeURIComponent(wfKey)}/${op}`;
|
|
103
|
+
let signal;
|
|
104
|
+
if (callOpts?.opts?.signal !== void 0 && callOpts?.opts?.timeout !== void 0) throw new Error("You can't specify both signal and timeout options at the same time");
|
|
105
|
+
else if (callOpts?.opts?.signal !== void 0) signal = callOpts?.opts?.signal;
|
|
106
|
+
else if (callOpts?.opts?.timeout !== void 0) signal = AbortSignal.timeout(callOpts?.opts?.timeout);
|
|
107
|
+
const httpResponse = await fetch(url, {
|
|
108
|
+
method: "GET",
|
|
109
|
+
headers,
|
|
110
|
+
signal
|
|
111
|
+
});
|
|
112
|
+
if (httpResponse.ok) {
|
|
113
|
+
const responseBuf = new Uint8Array(await httpResponse.arrayBuffer());
|
|
114
|
+
const decodedBuf = opts.journalValueCodec ? await opts.journalValueCodec.decode(responseBuf) : responseBuf;
|
|
115
|
+
return outputSerde.deserialize(decodedBuf);
|
|
116
|
+
}
|
|
117
|
+
const body = await httpResponse.text();
|
|
118
|
+
throw new HttpCallError(httpResponse.status, body, `Request failed: ${httpResponse.status}\n${body}`);
|
|
119
|
+
};
|
|
120
|
+
var HttpIngress = class {
|
|
121
|
+
constructor(opts) {
|
|
122
|
+
this.opts = opts;
|
|
123
|
+
}
|
|
124
|
+
proxy(component, key, send) {
|
|
125
|
+
return new Proxy({}, { get: (_target, prop) => {
|
|
126
|
+
const handler = prop;
|
|
127
|
+
return (...args) => {
|
|
128
|
+
const { parameter, opts } = optsFromArgs(args);
|
|
129
|
+
return doComponentInvocation(this.opts, {
|
|
130
|
+
component,
|
|
131
|
+
handler,
|
|
132
|
+
key,
|
|
133
|
+
parameter,
|
|
134
|
+
opts,
|
|
135
|
+
send
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
} });
|
|
139
|
+
}
|
|
140
|
+
serviceClient(opts) {
|
|
141
|
+
return this.proxy(opts.name);
|
|
142
|
+
}
|
|
143
|
+
objectClient(opts, key) {
|
|
144
|
+
return this.proxy(opts.name, key);
|
|
145
|
+
}
|
|
146
|
+
workflowClient(opts, key) {
|
|
147
|
+
const component = opts.name;
|
|
148
|
+
const conn = this.opts;
|
|
149
|
+
const workflowSubmit = async (parameter, opts$1) => {
|
|
150
|
+
const res = await doComponentInvocation(conn, {
|
|
151
|
+
component,
|
|
152
|
+
handler: "run",
|
|
153
|
+
key,
|
|
154
|
+
send: true,
|
|
155
|
+
parameter,
|
|
156
|
+
opts: opts$1
|
|
157
|
+
});
|
|
158
|
+
return {
|
|
159
|
+
invocationId: res.invocationId,
|
|
160
|
+
status: res.status,
|
|
161
|
+
attachable: true
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
const workflowAttach = (opts$1) => doWorkflowHandleCall(conn, component, key, "attach", opts$1);
|
|
165
|
+
const workflowOutput = async (opts$1) => {
|
|
166
|
+
try {
|
|
167
|
+
return {
|
|
168
|
+
ready: true,
|
|
169
|
+
result: await doWorkflowHandleCall(conn, component, key, "output", opts$1)
|
|
170
|
+
};
|
|
171
|
+
} catch (e) {
|
|
172
|
+
if (!(e instanceof HttpCallError) || e.status !== 470) throw e;
|
|
173
|
+
return {
|
|
174
|
+
ready: false,
|
|
175
|
+
get result() {
|
|
176
|
+
throw new Error("Calling result() on a non ready workflow");
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
return new Proxy({}, { get: (_target, prop) => {
|
|
182
|
+
const handler = prop;
|
|
183
|
+
if (handler === "workflowSubmit") return workflowSubmit;
|
|
184
|
+
else if (handler === "workflowAttach") return workflowAttach;
|
|
185
|
+
else if (handler === "workflowOutput") return workflowOutput;
|
|
186
|
+
return (...args) => {
|
|
187
|
+
const { parameter, opts: opts$1 } = optsFromArgs(args);
|
|
188
|
+
return doComponentInvocation(conn, {
|
|
189
|
+
component,
|
|
190
|
+
handler,
|
|
191
|
+
key,
|
|
192
|
+
parameter,
|
|
193
|
+
opts: opts$1
|
|
194
|
+
});
|
|
195
|
+
};
|
|
196
|
+
} });
|
|
197
|
+
}
|
|
198
|
+
objectSendClient(opts, key) {
|
|
199
|
+
return this.proxy(opts.name, key, true);
|
|
200
|
+
}
|
|
201
|
+
serviceSendClient(opts) {
|
|
202
|
+
return this.proxy(opts.name, void 0, true);
|
|
203
|
+
}
|
|
204
|
+
async resolveAwakeable(id, payload, payloadSerde) {
|
|
205
|
+
const url = `${this.opts.url}/restate/a/${id}/resolve`;
|
|
206
|
+
const { body, contentType } = serializeBodyWithContentType(payload, payloadSerde ?? __restatedev_restate_sdk_core.serde.json, this.opts.journalValueCodec);
|
|
207
|
+
const headers = { ...this.opts.headers ?? {} };
|
|
208
|
+
if (contentType) headers["Content-Type"] = contentType;
|
|
209
|
+
const httpResponse = await fetch(url, {
|
|
210
|
+
method: "POST",
|
|
211
|
+
headers,
|
|
212
|
+
body
|
|
213
|
+
});
|
|
214
|
+
if (!httpResponse.ok) {
|
|
215
|
+
const body$1 = await httpResponse.text();
|
|
216
|
+
throw new HttpCallError(httpResponse.status, body$1, `Request failed: ${httpResponse.status}\n${body$1}`);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
async rejectAwakeable(id, reason) {
|
|
220
|
+
const url = `${this.opts.url}/restate/a/${id}/reject`;
|
|
221
|
+
const headers = {
|
|
222
|
+
"Content-Type": "text/plain",
|
|
223
|
+
...this.opts.headers ?? {}
|
|
224
|
+
};
|
|
225
|
+
const httpResponse = await fetch(url, {
|
|
226
|
+
method: "POST",
|
|
227
|
+
headers,
|
|
228
|
+
body: reason
|
|
229
|
+
});
|
|
230
|
+
if (!httpResponse.ok) {
|
|
231
|
+
const body = await httpResponse.text();
|
|
232
|
+
throw new HttpCallError(httpResponse.status, body, `Request failed: ${httpResponse.status}\n${body}`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
async result(send, resultSerde) {
|
|
236
|
+
if (!send.attachable) throw new Error(`Unable to fetch the result for ${send.invocationId}.
|
|
237
|
+
A service's result is stored only with an idempotencyKey is supplied when invocating the service.`);
|
|
238
|
+
const headers = { ...this.opts.headers ?? {} };
|
|
239
|
+
const url = `${this.opts.url}/restate/invocation/${send.invocationId}/attach`;
|
|
240
|
+
const httpResponse = await fetch(url, {
|
|
241
|
+
method: "GET",
|
|
242
|
+
headers
|
|
243
|
+
});
|
|
244
|
+
if (httpResponse.ok) {
|
|
245
|
+
const responseBuf = new Uint8Array(await httpResponse.arrayBuffer());
|
|
246
|
+
const decodedBuf = this.opts.journalValueCodec ? await this.opts.journalValueCodec.decode(responseBuf) : responseBuf;
|
|
247
|
+
return (resultSerde ?? __restatedev_restate_sdk_core.serde.json).deserialize(decodedBuf);
|
|
248
|
+
}
|
|
249
|
+
const body = await httpResponse.text();
|
|
250
|
+
throw new HttpCallError(httpResponse.status, body, `Request failed: ${httpResponse.status}\n${body}`);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
function computeDelayAsIso(opts) {
|
|
254
|
+
const delay = opts.delay();
|
|
255
|
+
if (!delay) return "send";
|
|
256
|
+
return `send?delay=${delay}ms`;
|
|
257
|
+
}
|
|
258
|
+
function serializeBodyWithContentType(body, serde$1, journalValueCodec) {
|
|
259
|
+
let buffer = serde$1.serialize(body);
|
|
260
|
+
if (journalValueCodec) buffer = journalValueCodec.encode(buffer);
|
|
261
|
+
return {
|
|
262
|
+
body: buffer,
|
|
263
|
+
contentType: serde$1.contentType
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
//#endregion
|
|
268
|
+
exports.HttpCallError = HttpCallError;
|
|
269
|
+
exports.connect = connect;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ConnectionOpts, Ingress } from "./api.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/ingress.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Connect to the restate Ingress
|
|
7
|
+
*
|
|
8
|
+
* @param opts connection options
|
|
9
|
+
* @returns a connection the the restate ingress
|
|
10
|
+
*/
|
|
11
|
+
declare function connect(opts: ConnectionOpts): Ingress;
|
|
12
|
+
declare class HttpCallError extends Error {
|
|
13
|
+
readonly status: number;
|
|
14
|
+
readonly responseText: string;
|
|
15
|
+
readonly message: string;
|
|
16
|
+
constructor(status: number, responseText: string, message: string);
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { HttpCallError, connect };
|
|
20
|
+
//# sourceMappingURL=ingress.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ingress.d.cts","names":[],"sources":["../src/ingress.ts"],"sourcesContent":[],"mappings":";;;;;;AAyCA;AAIA;;;iBAJgB,OAAA,OAAc,iBAAiB;cAIlC,aAAA,SAAsB,KAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ConnectionOpts, Ingress } from "./api.js";
|
|
2
|
+
|
|
3
|
+
//#region src/ingress.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Connect to the restate Ingress
|
|
7
|
+
*
|
|
8
|
+
* @param opts connection options
|
|
9
|
+
* @returns a connection the the restate ingress
|
|
10
|
+
*/
|
|
11
|
+
declare function connect(opts: ConnectionOpts): Ingress;
|
|
12
|
+
declare class HttpCallError extends Error {
|
|
13
|
+
readonly status: number;
|
|
14
|
+
readonly responseText: string;
|
|
15
|
+
readonly message: string;
|
|
16
|
+
constructor(status: number, responseText: string, message: string);
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { HttpCallError, connect };
|
|
20
|
+
//# sourceMappingURL=ingress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ingress.d.ts","names":[],"sources":["../src/ingress.ts"],"sourcesContent":[],"mappings":";;;;;;AAyCA;AAIA;;;iBAJgB,OAAA,OAAc,iBAAiB;cAIlC,aAAA,SAAsB,KAAA"}
|
package/dist/ingress.js
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { Opts, SendOpts } from "./api.js";
|
|
2
|
+
import { serde } from "@restatedev/restate-sdk-core";
|
|
3
|
+
|
|
4
|
+
//#region src/ingress.ts
|
|
5
|
+
/**
|
|
6
|
+
* Connect to the restate Ingress
|
|
7
|
+
*
|
|
8
|
+
* @param opts connection options
|
|
9
|
+
* @returns a connection the the restate ingress
|
|
10
|
+
*/
|
|
11
|
+
function connect(opts) {
|
|
12
|
+
return new HttpIngress(opts);
|
|
13
|
+
}
|
|
14
|
+
var HttpCallError = class extends Error {
|
|
15
|
+
constructor(status, responseText, message) {
|
|
16
|
+
super(message);
|
|
17
|
+
this.status = status;
|
|
18
|
+
this.responseText = responseText;
|
|
19
|
+
this.message = message;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
function optsFromArgs(args) {
|
|
23
|
+
let parameter;
|
|
24
|
+
let opts;
|
|
25
|
+
switch (args.length) {
|
|
26
|
+
case 0: break;
|
|
27
|
+
case 1:
|
|
28
|
+
if (args[0] instanceof Opts) opts = args[0];
|
|
29
|
+
else if (args[0] instanceof SendOpts) opts = args[0];
|
|
30
|
+
else parameter = args[0];
|
|
31
|
+
break;
|
|
32
|
+
case 2:
|
|
33
|
+
parameter = args[0];
|
|
34
|
+
if (args[1] instanceof Opts) opts = args[1];
|
|
35
|
+
else if (args[1] instanceof SendOpts) opts = args[1];
|
|
36
|
+
else throw new TypeError("The second argument must be either Opts or SendOpts");
|
|
37
|
+
break;
|
|
38
|
+
default: throw new TypeError("unexpected number of arguments");
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
parameter,
|
|
42
|
+
opts
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
const IDEMPOTENCY_KEY_HEADER = "idempotency-key";
|
|
46
|
+
const doComponentInvocation = async (opts, params) => {
|
|
47
|
+
let attachable = false;
|
|
48
|
+
const fragments = [];
|
|
49
|
+
fragments.push(opts.url);
|
|
50
|
+
fragments.push(params.component);
|
|
51
|
+
if (params.key) {
|
|
52
|
+
const key = encodeURIComponent(params.key);
|
|
53
|
+
fragments.push(key);
|
|
54
|
+
}
|
|
55
|
+
fragments.push(params.handler);
|
|
56
|
+
if (params.send ?? false) if (params.opts instanceof SendOpts) {
|
|
57
|
+
const sendString = computeDelayAsIso(params.opts);
|
|
58
|
+
fragments.push(sendString);
|
|
59
|
+
} else fragments.push("send");
|
|
60
|
+
const inputSerde = params.opts?.opts.input ?? serde.json;
|
|
61
|
+
const { body, contentType } = serializeBodyWithContentType(params.parameter, inputSerde, opts.journalValueCodec);
|
|
62
|
+
const headers = {
|
|
63
|
+
...opts.headers ?? {},
|
|
64
|
+
...params.opts?.opts?.headers ?? {}
|
|
65
|
+
};
|
|
66
|
+
if (contentType) headers["Content-Type"] = contentType;
|
|
67
|
+
const idempotencyKey = params.opts?.opts.idempotencyKey;
|
|
68
|
+
if (idempotencyKey) {
|
|
69
|
+
headers[IDEMPOTENCY_KEY_HEADER] = idempotencyKey;
|
|
70
|
+
attachable = true;
|
|
71
|
+
}
|
|
72
|
+
let signal;
|
|
73
|
+
if (params.opts?.opts.signal !== void 0 && params.opts?.opts.timeout !== void 0) throw new Error("You can't specify both signal and timeout options at the same time");
|
|
74
|
+
else if (params.opts?.opts.signal !== void 0) signal = params.opts?.opts.signal;
|
|
75
|
+
else if (params.opts?.opts.timeout !== void 0) signal = AbortSignal.timeout(params.opts?.opts.timeout);
|
|
76
|
+
const url = fragments.join("/");
|
|
77
|
+
const httpResponse = await fetch(url, {
|
|
78
|
+
method: params.method ?? "POST",
|
|
79
|
+
headers,
|
|
80
|
+
body,
|
|
81
|
+
signal
|
|
82
|
+
});
|
|
83
|
+
if (!httpResponse.ok) {
|
|
84
|
+
const body$1 = await httpResponse.text();
|
|
85
|
+
throw new HttpCallError(httpResponse.status, body$1, `Request failed: ${httpResponse.status}\n${body$1}`);
|
|
86
|
+
}
|
|
87
|
+
const responseBuf = new Uint8Array(await httpResponse.arrayBuffer());
|
|
88
|
+
if (!params.send) {
|
|
89
|
+
const decodedBuf = opts.journalValueCodec ? await opts.journalValueCodec.decode(responseBuf) : responseBuf;
|
|
90
|
+
return (params.opts?.opts.output ?? serde.json).deserialize(decodedBuf);
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
...serde.json.deserialize(responseBuf),
|
|
94
|
+
attachable
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
const doWorkflowHandleCall = async (opts, wfName, wfKey, op, callOpts) => {
|
|
98
|
+
const outputSerde = callOpts?.opts.output ?? serde.json;
|
|
99
|
+
const headers = { ...opts.headers ?? {} };
|
|
100
|
+
const url = `${opts.url}/restate/workflow/${wfName}/${encodeURIComponent(wfKey)}/${op}`;
|
|
101
|
+
let signal;
|
|
102
|
+
if (callOpts?.opts?.signal !== void 0 && callOpts?.opts?.timeout !== void 0) throw new Error("You can't specify both signal and timeout options at the same time");
|
|
103
|
+
else if (callOpts?.opts?.signal !== void 0) signal = callOpts?.opts?.signal;
|
|
104
|
+
else if (callOpts?.opts?.timeout !== void 0) signal = AbortSignal.timeout(callOpts?.opts?.timeout);
|
|
105
|
+
const httpResponse = await fetch(url, {
|
|
106
|
+
method: "GET",
|
|
107
|
+
headers,
|
|
108
|
+
signal
|
|
109
|
+
});
|
|
110
|
+
if (httpResponse.ok) {
|
|
111
|
+
const responseBuf = new Uint8Array(await httpResponse.arrayBuffer());
|
|
112
|
+
const decodedBuf = opts.journalValueCodec ? await opts.journalValueCodec.decode(responseBuf) : responseBuf;
|
|
113
|
+
return outputSerde.deserialize(decodedBuf);
|
|
114
|
+
}
|
|
115
|
+
const body = await httpResponse.text();
|
|
116
|
+
throw new HttpCallError(httpResponse.status, body, `Request failed: ${httpResponse.status}\n${body}`);
|
|
117
|
+
};
|
|
118
|
+
var HttpIngress = class {
|
|
119
|
+
constructor(opts) {
|
|
120
|
+
this.opts = opts;
|
|
121
|
+
}
|
|
122
|
+
proxy(component, key, send) {
|
|
123
|
+
return new Proxy({}, { get: (_target, prop) => {
|
|
124
|
+
const handler = prop;
|
|
125
|
+
return (...args) => {
|
|
126
|
+
const { parameter, opts } = optsFromArgs(args);
|
|
127
|
+
return doComponentInvocation(this.opts, {
|
|
128
|
+
component,
|
|
129
|
+
handler,
|
|
130
|
+
key,
|
|
131
|
+
parameter,
|
|
132
|
+
opts,
|
|
133
|
+
send
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
} });
|
|
137
|
+
}
|
|
138
|
+
serviceClient(opts) {
|
|
139
|
+
return this.proxy(opts.name);
|
|
140
|
+
}
|
|
141
|
+
objectClient(opts, key) {
|
|
142
|
+
return this.proxy(opts.name, key);
|
|
143
|
+
}
|
|
144
|
+
workflowClient(opts, key) {
|
|
145
|
+
const component = opts.name;
|
|
146
|
+
const conn = this.opts;
|
|
147
|
+
const workflowSubmit = async (parameter, opts$1) => {
|
|
148
|
+
const res = await doComponentInvocation(conn, {
|
|
149
|
+
component,
|
|
150
|
+
handler: "run",
|
|
151
|
+
key,
|
|
152
|
+
send: true,
|
|
153
|
+
parameter,
|
|
154
|
+
opts: opts$1
|
|
155
|
+
});
|
|
156
|
+
return {
|
|
157
|
+
invocationId: res.invocationId,
|
|
158
|
+
status: res.status,
|
|
159
|
+
attachable: true
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
const workflowAttach = (opts$1) => doWorkflowHandleCall(conn, component, key, "attach", opts$1);
|
|
163
|
+
const workflowOutput = async (opts$1) => {
|
|
164
|
+
try {
|
|
165
|
+
return {
|
|
166
|
+
ready: true,
|
|
167
|
+
result: await doWorkflowHandleCall(conn, component, key, "output", opts$1)
|
|
168
|
+
};
|
|
169
|
+
} catch (e) {
|
|
170
|
+
if (!(e instanceof HttpCallError) || e.status !== 470) throw e;
|
|
171
|
+
return {
|
|
172
|
+
ready: false,
|
|
173
|
+
get result() {
|
|
174
|
+
throw new Error("Calling result() on a non ready workflow");
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
return new Proxy({}, { get: (_target, prop) => {
|
|
180
|
+
const handler = prop;
|
|
181
|
+
if (handler === "workflowSubmit") return workflowSubmit;
|
|
182
|
+
else if (handler === "workflowAttach") return workflowAttach;
|
|
183
|
+
else if (handler === "workflowOutput") return workflowOutput;
|
|
184
|
+
return (...args) => {
|
|
185
|
+
const { parameter, opts: opts$1 } = optsFromArgs(args);
|
|
186
|
+
return doComponentInvocation(conn, {
|
|
187
|
+
component,
|
|
188
|
+
handler,
|
|
189
|
+
key,
|
|
190
|
+
parameter,
|
|
191
|
+
opts: opts$1
|
|
192
|
+
});
|
|
193
|
+
};
|
|
194
|
+
} });
|
|
195
|
+
}
|
|
196
|
+
objectSendClient(opts, key) {
|
|
197
|
+
return this.proxy(opts.name, key, true);
|
|
198
|
+
}
|
|
199
|
+
serviceSendClient(opts) {
|
|
200
|
+
return this.proxy(opts.name, void 0, true);
|
|
201
|
+
}
|
|
202
|
+
async resolveAwakeable(id, payload, payloadSerde) {
|
|
203
|
+
const url = `${this.opts.url}/restate/a/${id}/resolve`;
|
|
204
|
+
const { body, contentType } = serializeBodyWithContentType(payload, payloadSerde ?? serde.json, this.opts.journalValueCodec);
|
|
205
|
+
const headers = { ...this.opts.headers ?? {} };
|
|
206
|
+
if (contentType) headers["Content-Type"] = contentType;
|
|
207
|
+
const httpResponse = await fetch(url, {
|
|
208
|
+
method: "POST",
|
|
209
|
+
headers,
|
|
210
|
+
body
|
|
211
|
+
});
|
|
212
|
+
if (!httpResponse.ok) {
|
|
213
|
+
const body$1 = await httpResponse.text();
|
|
214
|
+
throw new HttpCallError(httpResponse.status, body$1, `Request failed: ${httpResponse.status}\n${body$1}`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
async rejectAwakeable(id, reason) {
|
|
218
|
+
const url = `${this.opts.url}/restate/a/${id}/reject`;
|
|
219
|
+
const headers = {
|
|
220
|
+
"Content-Type": "text/plain",
|
|
221
|
+
...this.opts.headers ?? {}
|
|
222
|
+
};
|
|
223
|
+
const httpResponse = await fetch(url, {
|
|
224
|
+
method: "POST",
|
|
225
|
+
headers,
|
|
226
|
+
body: reason
|
|
227
|
+
});
|
|
228
|
+
if (!httpResponse.ok) {
|
|
229
|
+
const body = await httpResponse.text();
|
|
230
|
+
throw new HttpCallError(httpResponse.status, body, `Request failed: ${httpResponse.status}\n${body}`);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
async result(send, resultSerde) {
|
|
234
|
+
if (!send.attachable) throw new Error(`Unable to fetch the result for ${send.invocationId}.
|
|
235
|
+
A service's result is stored only with an idempotencyKey is supplied when invocating the service.`);
|
|
236
|
+
const headers = { ...this.opts.headers ?? {} };
|
|
237
|
+
const url = `${this.opts.url}/restate/invocation/${send.invocationId}/attach`;
|
|
238
|
+
const httpResponse = await fetch(url, {
|
|
239
|
+
method: "GET",
|
|
240
|
+
headers
|
|
241
|
+
});
|
|
242
|
+
if (httpResponse.ok) {
|
|
243
|
+
const responseBuf = new Uint8Array(await httpResponse.arrayBuffer());
|
|
244
|
+
const decodedBuf = this.opts.journalValueCodec ? await this.opts.journalValueCodec.decode(responseBuf) : responseBuf;
|
|
245
|
+
return (resultSerde ?? serde.json).deserialize(decodedBuf);
|
|
246
|
+
}
|
|
247
|
+
const body = await httpResponse.text();
|
|
248
|
+
throw new HttpCallError(httpResponse.status, body, `Request failed: ${httpResponse.status}\n${body}`);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
function computeDelayAsIso(opts) {
|
|
252
|
+
const delay = opts.delay();
|
|
253
|
+
if (!delay) return "send";
|
|
254
|
+
return `send?delay=${delay}ms`;
|
|
255
|
+
}
|
|
256
|
+
function serializeBodyWithContentType(body, serde$1, journalValueCodec) {
|
|
257
|
+
let buffer = serde$1.serialize(body);
|
|
258
|
+
if (journalValueCodec) buffer = journalValueCodec.encode(buffer);
|
|
259
|
+
return {
|
|
260
|
+
body: buffer,
|
|
261
|
+
contentType: serde$1.contentType
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
//#endregion
|
|
266
|
+
export { HttpCallError, connect };
|
|
267
|
+
//# sourceMappingURL=ingress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ingress.js","names":["status: number","responseText: string","message: string","parameter: unknown","opts: Opts<unknown, unknown> | SendOpts<unknown> | undefined","signal: AbortSignal | undefined","body","opts: ConnectionOpts","res: Send","opts","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 type {\n ConnectionOpts,\n Ingress,\n IngressClient,\n IngressSendClient,\n IngressWorkflowClient,\n Output,\n Send,\n WorkflowSubmission,\n} from \"./api.js\";\n\nimport { Opts, SendOpts } from \"./api.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};\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\";\n\nconst doComponentInvocation = async <I, O>(\n opts: ConnectionOpts,\n params: InvocationParameters<I>\n): Promise<O> => {\n let attachable = false;\n const fragments = [];\n //\n // ingress URL\n //\n fragments.push(opts.url);\n //\n // component\n //\n fragments.push(params.component);\n //\n // has key?\n //\n if (params.key) {\n const key = encodeURIComponent(params.key);\n fragments.push(key);\n }\n //\n // handler\n //\n fragments.push(params.handler);\n if (params.send ?? false) {\n if (params.opts instanceof SendOpts) {\n const sendString = computeDelayAsIso(params.opts);\n fragments.push(sendString);\n } else {\n fragments.push(\"send\");\n }\n }\n //\n // request body\n //\n const inputSerde = params.opts?.opts.input ?? 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 // Abort signal, if any\n let signal: AbortSignal | undefined;\n if (\n params.opts?.opts.signal !== undefined &&\n params.opts?.opts.timeout !== undefined\n ) {\n throw new Error(\n \"You can't specify both signal and timeout options at the same time\"\n );\n } else if (params.opts?.opts.signal !== undefined) {\n signal = params.opts?.opts.signal;\n } else if (params.opts?.opts.timeout !== undefined) {\n signal = AbortSignal.timeout(params.opts?.opts.timeout);\n }\n\n //\n // make the call\n //\n const url = fragments.join(\"/\");\n const httpResponse = await fetch(url, {\n method: params.method ?? \"POST\",\n headers,\n body,\n signal,\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 const responseBuf = new Uint8Array(await httpResponse.arrayBuffer());\n if (!params.send) {\n const decodedBuf = opts.journalValueCodec\n ? await opts.journalValueCodec.decode(responseBuf)\n : responseBuf;\n const outputSerde = params.opts?.opts.output ?? 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 ?? 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\n // Abort signal, if any\n let signal: AbortSignal | undefined;\n if (\n callOpts?.opts?.signal !== undefined &&\n callOpts?.opts?.timeout !== undefined\n ) {\n throw new Error(\n \"You can't specify both signal and timeout options at the same time\"\n );\n } else if (callOpts?.opts?.signal !== undefined) {\n signal = callOpts?.opts?.signal;\n } else if (callOpts?.opts?.timeout !== undefined) {\n signal = AbortSignal.timeout(callOpts?.opts?.timeout);\n }\n\n const httpResponse = await fetch(url, {\n method: \"GET\",\n headers,\n signal,\n });\n if (httpResponse.ok) {\n const responseBuf = new Uint8Array(await httpResponse.arrayBuffer());\n const decodedBuf = opts.journalValueCodec\n ? await opts.journalValueCodec.decode(responseBuf)\n : responseBuf;\n return outputSerde.deserialize(decodedBuf) as O;\n }\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\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 parameter?: unknown,\n opts?: SendOpts<unknown>\n ): Promise<WorkflowSubmission<unknown>> => {\n const res: Send = await doComponentInvocation(conn, {\n component,\n handler: \"run\",\n key,\n send: true,\n parameter,\n opts,\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 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 ?? 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 fetch(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 fetch(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 const url = `${this.opts.url}/restate/invocation/${send.invocationId}/attach`;\n\n const httpResponse = await fetch(url, {\n method: \"GET\",\n headers,\n });\n if (httpResponse.ok) {\n const responseBuf = new Uint8Array(await httpResponse.arrayBuffer());\n const decodedBuf = this.opts.journalValueCodec\n ? await this.opts.journalValueCodec.decode(responseBuf)\n : responseBuf;\n return (resultSerde ?? serde.json).deserialize(decodedBuf) as T;\n }\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\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":";;;;;;;;;;AAyCA,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;EAC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