@voltro/api-client 0.71.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/CHANGELOG.md +13518 -0
- package/LICENSE +61 -0
- package/README.md +26 -0
- package/SECURITY.md +56 -0
- package/THIRD-PARTY-NOTICES.md +11 -0
- package/dist/index.d.ts +566 -0
- package/dist/index.js +787 -0
- package/package.json +38 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,787 @@
|
|
|
1
|
+
//#region src/manifest.ts
|
|
2
|
+
var e = (e) => {
|
|
3
|
+
let t = e.indexOf(".");
|
|
4
|
+
return t < 0 ? {
|
|
5
|
+
namespace: void 0,
|
|
6
|
+
method: e
|
|
7
|
+
} : {
|
|
8
|
+
namespace: e.slice(0, t),
|
|
9
|
+
method: e.slice(t + 1).split(".").map((e, t) => t === 0 ? e : e.charAt(0).toUpperCase() + e.slice(1)).join("")
|
|
10
|
+
};
|
|
11
|
+
}, t = (e, t) => {
|
|
12
|
+
let n = e.projections.find((e) => e.tag === t);
|
|
13
|
+
if (n === void 0) throw Error(`@voltro/api-client: no projection for tag '${t}' in the manifest (${e.projections.length} projection(s))`);
|
|
14
|
+
return n;
|
|
15
|
+
}, n = (e) => e.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z])([A-Z][a-z])/g, "$1_$2").toLowerCase(), r = (e) => ({
|
|
16
|
+
dates: "rpc",
|
|
17
|
+
naming: "camelCase",
|
|
18
|
+
models: e
|
|
19
|
+
}), i = (e, t, n = 0) => {
|
|
20
|
+
let r = e;
|
|
21
|
+
for (let e = 0; r.kind === "ref" && e < 32; e++) {
|
|
22
|
+
let e = t[r.name];
|
|
23
|
+
if (e === void 0) return { kind: "unknown" };
|
|
24
|
+
r = e;
|
|
25
|
+
}
|
|
26
|
+
return n > 64 ? { kind: "unknown" } : r;
|
|
27
|
+
}, a = (e) => typeof e == "object" && !!e && !Array.isArray(e), o = (e, t, n) => {
|
|
28
|
+
let r = e.map((e) => i(e, n));
|
|
29
|
+
if (t instanceof Date || typeof t == "string" || typeof t == "number") {
|
|
30
|
+
let e = r.find((e) => e.kind === "date");
|
|
31
|
+
return e !== void 0 && (t instanceof Date || typeof t == "string" && /^\d{4}-\d{2}-\d{2}T/.test(t) || typeof t == "number") ? r.find((e) => e.kind === "literal" && e.value === t) ?? e : r.find((e) => e.kind === "literal" ? e.value === t : e.kind === (typeof t == "string" ? "string" : "number") || e.kind === "integer" && typeof t == "number");
|
|
32
|
+
}
|
|
33
|
+
if (Array.isArray(t)) return r.find((e) => e.kind === "array" || e.kind === "tuple");
|
|
34
|
+
if (a(t)) {
|
|
35
|
+
let e = r.filter((e) => e.kind === "object" || e.kind === "record");
|
|
36
|
+
for (let n of e) {
|
|
37
|
+
if (n.kind !== "object") continue;
|
|
38
|
+
let e = n.fields.filter((e) => e.type.kind === "literal");
|
|
39
|
+
if (e.length > 0 && e.every((e) => t[e.name] === e.type.value)) return n;
|
|
40
|
+
}
|
|
41
|
+
return e.find((e) => e.kind === "object" && e.fields.every((e) => e.type.kind !== "literal")) ?? e[0];
|
|
42
|
+
}
|
|
43
|
+
}, s = (e, t) => e instanceof Date ? t === "iso" ? e.toISOString() : e.getTime() : e, c = (e, t) => {
|
|
44
|
+
if (typeof e == "string" && t === "iso") {
|
|
45
|
+
let t = new Date(e);
|
|
46
|
+
return Number.isNaN(t.getTime()) ? e : t;
|
|
47
|
+
}
|
|
48
|
+
return typeof e == "number" && t === "epoch-ms" ? new Date(e) : e;
|
|
49
|
+
}, l = (e, t, r, u, d) => {
|
|
50
|
+
if (t == null || d > 64) return t;
|
|
51
|
+
let f = i(e, r.models);
|
|
52
|
+
switch (f.kind) {
|
|
53
|
+
case "date": {
|
|
54
|
+
let e = r.dates === "rpc" ? f.rpc === "number" ? "epoch-ms" : "iso" : r.dates;
|
|
55
|
+
return u === "encode" ? s(t, e) : c(t, e);
|
|
56
|
+
}
|
|
57
|
+
case "array": return Array.isArray(t) ? t.map((e) => l(f.element, e, r, u, d + 1)) : t;
|
|
58
|
+
case "tuple": return Array.isArray(t) ? t.map((e, t) => l(f.elements[t] ?? f.rest ?? { kind: "unknown" }, e, r, u, d + 1)) : t;
|
|
59
|
+
case "record": {
|
|
60
|
+
if (!a(t)) return t;
|
|
61
|
+
let e = {};
|
|
62
|
+
for (let [n, i] of Object.entries(t)) e[n] = l(f.value, i, r, u, d + 1);
|
|
63
|
+
return e;
|
|
64
|
+
}
|
|
65
|
+
case "object": {
|
|
66
|
+
if (!a(t)) return t;
|
|
67
|
+
let e = {}, i = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map();
|
|
68
|
+
for (let e of f.fields) o.set(e.name, e), i.set(r.naming === "snake_case" ? n(e.name) : e.name, e);
|
|
69
|
+
for (let [a, s] of Object.entries(t)) {
|
|
70
|
+
let t = u === "encode" ? o.get(a) : i.get(a);
|
|
71
|
+
if (t === void 0) {
|
|
72
|
+
e[a] = s;
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (s === void 0) continue;
|
|
76
|
+
let c = u === "encode" && r.naming === "snake_case" ? n(t.name) : t.name;
|
|
77
|
+
e[c] = l(t.type, s, r, u, d + 1);
|
|
78
|
+
}
|
|
79
|
+
return e;
|
|
80
|
+
}
|
|
81
|
+
case "union": {
|
|
82
|
+
let e = o(f.members, t, r.models);
|
|
83
|
+
return e === void 0 ? t : l(e, t, r, u, d + 1);
|
|
84
|
+
}
|
|
85
|
+
default: return t;
|
|
86
|
+
}
|
|
87
|
+
}, u = (e, t, n) => e === void 0 ? t : l(e, t, n, "encode", 0), d = (e, t, n) => e === void 0 ? t : l(e, t, n, "decode", 0), f = (e, t) => {
|
|
88
|
+
if (e === void 0) return !1;
|
|
89
|
+
let n = i(e, t);
|
|
90
|
+
return n.kind === "object" ? n.fields.some((e) => !e.optional) : n.kind !== "undefined";
|
|
91
|
+
}, p = class extends Error {
|
|
92
|
+
status;
|
|
93
|
+
requestId;
|
|
94
|
+
constructor(e, t = {}, n) {
|
|
95
|
+
super(e, n), this.status = t.status, this.requestId = t.requestId;
|
|
96
|
+
}
|
|
97
|
+
get name() {
|
|
98
|
+
return this._tag;
|
|
99
|
+
}
|
|
100
|
+
}, m = class extends p {
|
|
101
|
+
_tag = "TransportError";
|
|
102
|
+
tag;
|
|
103
|
+
reason;
|
|
104
|
+
constructor(e) {
|
|
105
|
+
super(e.message, { requestId: e.requestId }, e.cause === void 0 ? void 0 : { cause: e.cause }), this.tag = e.tag, this.reason = e.reason;
|
|
106
|
+
}
|
|
107
|
+
}, h = class extends p {
|
|
108
|
+
_tag = "ApiHttpError";
|
|
109
|
+
tag;
|
|
110
|
+
status;
|
|
111
|
+
errorTag;
|
|
112
|
+
detail;
|
|
113
|
+
body;
|
|
114
|
+
constructor(e) {
|
|
115
|
+
super(`${e.tag}: ${e.status}${e.errorTag === void 0 ? "" : ` ${e.errorTag}`}${e.detail === void 0 ? "" : ` — ${e.detail}`}`, {
|
|
116
|
+
status: e.status,
|
|
117
|
+
requestId: e.requestId
|
|
118
|
+
}), this.tag = e.tag, this.status = e.status, this.errorTag = e.errorTag, this.detail = e.detail, this.body = e.body;
|
|
119
|
+
}
|
|
120
|
+
}, g = class extends p {
|
|
121
|
+
_tag = "RateLimitedError";
|
|
122
|
+
tag;
|
|
123
|
+
retryAfterMs;
|
|
124
|
+
limit;
|
|
125
|
+
remaining;
|
|
126
|
+
resetAtMs;
|
|
127
|
+
constructor(e) {
|
|
128
|
+
super(`${e.tag}: rate limited — retry after ${e.retryAfterMs} ms`, {
|
|
129
|
+
status: 429,
|
|
130
|
+
requestId: e.requestId
|
|
131
|
+
}), this.tag = e.tag, this.retryAfterMs = e.retryAfterMs, this.limit = e.limit, this.remaining = e.remaining, this.resetAtMs = e.resetAtMs;
|
|
132
|
+
}
|
|
133
|
+
}, _ = class extends p {
|
|
134
|
+
_tag = "ProfileMismatchError";
|
|
135
|
+
expected;
|
|
136
|
+
actual;
|
|
137
|
+
constructor(e) {
|
|
138
|
+
super(`the API speaks the '${e.actual}' profile; this client was generated for '${e.expected}' — regenerate it`), this.expected = e.expected, this.actual = e.actual;
|
|
139
|
+
}
|
|
140
|
+
}, v = class extends p {
|
|
141
|
+
_tag = "InputEncodeError";
|
|
142
|
+
tag;
|
|
143
|
+
constructor(e) {
|
|
144
|
+
super(`${e.tag}: ${e.message}`), this.tag = e.tag;
|
|
145
|
+
}
|
|
146
|
+
}, y = class extends p {
|
|
147
|
+
_tag;
|
|
148
|
+
detail;
|
|
149
|
+
constructor(e, t, n = {}) {
|
|
150
|
+
super(n.detail ?? `${e}${Object.keys(t).length > 0 ? ` ${JSON.stringify(t)}` : ""}`, n), this._tag = e, this.detail = n.detail;
|
|
151
|
+
}
|
|
152
|
+
toJSON() {
|
|
153
|
+
let e = { _tag: this._tag };
|
|
154
|
+
for (let [t, n] of Object.entries(this)) t !== "status" && t !== "requestId" && t !== "detail" && t !== "_tag" && (e[t] = n);
|
|
155
|
+
return e;
|
|
156
|
+
}
|
|
157
|
+
}, b = (e) => {
|
|
158
|
+
class t extends y {
|
|
159
|
+
constructor(t = {}, n = {}) {
|
|
160
|
+
super(e, t, n), Object.assign(this, t);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return Object.defineProperty(t, "name", { value: e }), t;
|
|
164
|
+
}, x = (e = Date.now()) => {
|
|
165
|
+
let t = /* @__PURE__ */ new Uint8Array(16);
|
|
166
|
+
crypto.getRandomValues(t);
|
|
167
|
+
let n = BigInt(e);
|
|
168
|
+
t[0] = Number(n >> 40n & 255n), t[1] = Number(n >> 32n & 255n), t[2] = Number(n >> 24n & 255n), t[3] = Number(n >> 16n & 255n), t[4] = Number(n >> 8n & 255n), t[5] = Number(n & 255n), t[6] = t[6] & 15 | 112, t[8] = t[8] & 63 | 128;
|
|
169
|
+
let r = [...t].map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
170
|
+
return `${r.slice(0, 8)}-${r.slice(8, 12)}-${r.slice(12, 16)}-${r.slice(16, 20)}-${r.slice(20)}`;
|
|
171
|
+
}, S = (e) => typeof e == "string" && e.startsWith("urn:voltro:error:") ? e.slice(17) : void 0, C = (e, t) => {
|
|
172
|
+
let n = e.get("retry-after");
|
|
173
|
+
if (n !== null) {
|
|
174
|
+
let e = Number(n);
|
|
175
|
+
if (Number.isFinite(e)) return Math.max(0, e * 1e3);
|
|
176
|
+
let r = Date.parse(n);
|
|
177
|
+
if (Number.isFinite(r)) return Math.max(0, r - t);
|
|
178
|
+
}
|
|
179
|
+
let r = e.get("ratelimit-reset"), i = r === null ? NaN : Number(r);
|
|
180
|
+
return Number.isFinite(i) ? Math.max(0, i * 1e3) : 1e3;
|
|
181
|
+
}, w = (e, t) => {
|
|
182
|
+
if (e !== null) for (let n of e.split(",")) {
|
|
183
|
+
let e = /<([^>]+)>\s*;\s*rel="?next"?/.exec(n.trim());
|
|
184
|
+
if (e === null) continue;
|
|
185
|
+
let r = e[1].split("?")[1] ?? "", i = new URLSearchParams(r).get(t);
|
|
186
|
+
if (i !== null) return i;
|
|
187
|
+
}
|
|
188
|
+
}, T = (e) => {
|
|
189
|
+
let t = new URLSearchParams();
|
|
190
|
+
for (let [n, r] of Object.entries(e)) if (r !== void 0) {
|
|
191
|
+
if (Array.isArray(r)) for (let e of r) t.append(n, typeof e == "object" && e ? JSON.stringify(e) : String(e));
|
|
192
|
+
else t.set(n, typeof r == "object" && r ? JSON.stringify(r) : String(r));
|
|
193
|
+
}
|
|
194
|
+
return t.toString();
|
|
195
|
+
}, E = (e, t, n) => {
|
|
196
|
+
if (typeof e != "object" || !e) return e;
|
|
197
|
+
let r = e, i = (e) => {
|
|
198
|
+
if (typeof e != "object" || !e) return e;
|
|
199
|
+
let { id: t, attributes: n } = e;
|
|
200
|
+
return {
|
|
201
|
+
...t === void 0 ? {} : { id: t },
|
|
202
|
+
...n ?? {}
|
|
203
|
+
};
|
|
204
|
+
};
|
|
205
|
+
return Array.isArray(r.data) ? {
|
|
206
|
+
items: r.data.map(i),
|
|
207
|
+
[t]: n ?? null
|
|
208
|
+
} : i(r.data);
|
|
209
|
+
}, D = (e) => {
|
|
210
|
+
let t = e.sunset === void 0 ? "" : ` — sunset ${e.sunset}`;
|
|
211
|
+
console.warn(`[@voltro/api-client] ${e.tag} (${e.path}) is deprecated${t}${e.deprecated === void 0 ? "" : `: ${e.deprecated}`}`);
|
|
212
|
+
}, O = (e) => new Promise((t) => {
|
|
213
|
+
setTimeout(t, e);
|
|
214
|
+
}), k = (e, t, n, r, i, a) => {
|
|
215
|
+
if (r !== void 0) {
|
|
216
|
+
let o = t[r], s = e.wire.procedures[n]?.errors?.[r];
|
|
217
|
+
if (o !== void 0) {
|
|
218
|
+
let t = d(s, i, {
|
|
219
|
+
dates: e.profile.dates,
|
|
220
|
+
naming: e.profile.naming,
|
|
221
|
+
models: e.wire.models
|
|
222
|
+
});
|
|
223
|
+
return new o(typeof t == "object" && t ? t : {}, {
|
|
224
|
+
status: a.status,
|
|
225
|
+
requestId: a.requestId,
|
|
226
|
+
detail: a.detail
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return new h({
|
|
231
|
+
tag: n,
|
|
232
|
+
status: a.status,
|
|
233
|
+
errorTag: r,
|
|
234
|
+
detail: a.detail,
|
|
235
|
+
body: a.body,
|
|
236
|
+
requestId: a.requestId
|
|
237
|
+
});
|
|
238
|
+
}, A = (e, n, r = {}) => {
|
|
239
|
+
let i = e.profile, a = (r.baseUrl ?? e.servers[0]?.url ?? "").replace(/\/+$/, "");
|
|
240
|
+
if (a === "") throw Error("@voltro/api-client: no baseUrl — pass one, or generate the client with `--base-url` or `servers`");
|
|
241
|
+
let o = r.fetch ?? globalThis.fetch, s = r.clock ?? (() => Date.now()), c = r.sleep ?? O, l = r.etagCache ?? i.etag, f = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Set(), h = r.onSunset ?? D, y = !1, b = r.userAgent ?? (e.name === void 0 ? void 0 : `${e.name}/${e.version ?? "0.0.0"} (${e.generatedBy})`), A = {
|
|
242
|
+
dates: i.dates,
|
|
243
|
+
naming: i.naming,
|
|
244
|
+
models: e.wire.models
|
|
245
|
+
}, j = async () => typeof r.token == "function" ? await r.token() : r.token, M = (t, n) => {
|
|
246
|
+
let r = e.wire.procedures[t.tag]?.input;
|
|
247
|
+
try {
|
|
248
|
+
let e = u(r, n ?? {}, A);
|
|
249
|
+
return typeof e == "object" && e ? e : {};
|
|
250
|
+
} catch (e) {
|
|
251
|
+
throw new v({
|
|
252
|
+
tag: t.tag,
|
|
253
|
+
message: String(e instanceof Error ? e.message.split("\n")[0] : e)
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}, N = (t, r, a, o) => {
|
|
257
|
+
let s = typeof a == "object" && a ? a : {}, c, l, u;
|
|
258
|
+
if (i.errors === "problem-details" && i.envelope !== "jsonapi") {
|
|
259
|
+
c = S(s.type);
|
|
260
|
+
let { type: e, title: t, status: n, detail: r, ...i } = s;
|
|
261
|
+
u = typeof r == "string" ? r : void 0, l = i;
|
|
262
|
+
} else if (i.envelope === "jsonapi") {
|
|
263
|
+
let e = Array.isArray(s.errors) ? s.errors[0] : void 0;
|
|
264
|
+
c = typeof e?.code == "string" ? e.code : void 0, u = typeof e?.detail == "string" ? e.detail : void 0, l = typeof e?.meta == "object" && e.meta !== null ? e.meta : {};
|
|
265
|
+
} else {
|
|
266
|
+
let { error: e, ...t } = s;
|
|
267
|
+
c = typeof e == "string" ? e : void 0, l = t, u = typeof e == "string" ? e : void 0;
|
|
268
|
+
}
|
|
269
|
+
return k(e, n, t.tag, c, l, {
|
|
270
|
+
status: r,
|
|
271
|
+
requestId: o,
|
|
272
|
+
detail: u,
|
|
273
|
+
body: a
|
|
274
|
+
});
|
|
275
|
+
};
|
|
276
|
+
return {
|
|
277
|
+
manifest: e,
|
|
278
|
+
call: async (n, u, v = {}) => {
|
|
279
|
+
let S = t(e, n), D = M(S, u), O = S.path, k = { ...D };
|
|
280
|
+
for (let e of S.pathParams) {
|
|
281
|
+
let t = k[e];
|
|
282
|
+
delete k[e], O = O.replace(`:${e}`, encodeURIComponent(t === void 0 ? "" : String(t)));
|
|
283
|
+
}
|
|
284
|
+
let P = S.method === "GET", F = P ? T(k) : "", I = `${a}${O}${F.length > 0 ? `?${F}` : ""}`, L = await j(), R = {
|
|
285
|
+
accept: i.envelope === "jsonapi" ? "application/vnd.api+json, application/json" : "application/json, application/problem+json",
|
|
286
|
+
...r.headers ?? {},
|
|
287
|
+
...v.headers ?? {}
|
|
288
|
+
};
|
|
289
|
+
L !== void 0 && (R.authorization = `Bearer ${L}`), r.tenant !== void 0 && (R["x-tenant"] = r.tenant), b !== void 0 && (R["user-agent"] = b);
|
|
290
|
+
let z = r.traceparent?.();
|
|
291
|
+
z !== void 0 && (R.traceparent = z), P || (R["content-type"] = "application/json"), !P && (S.idempotent === !0 || v.idempotencyKey !== void 0) && (R["idempotency-key"] = v.idempotencyKey ?? x(s()));
|
|
292
|
+
let B = P && l ? f.get(I) : void 0;
|
|
293
|
+
B !== void 0 && (R["if-none-match"] = B.etag);
|
|
294
|
+
let V = async (t) => {
|
|
295
|
+
let u;
|
|
296
|
+
try {
|
|
297
|
+
u = await o(I, {
|
|
298
|
+
method: S.method,
|
|
299
|
+
headers: R,
|
|
300
|
+
...P ? {} : { body: JSON.stringify(k) },
|
|
301
|
+
...v.signal === void 0 ? {} : { signal: v.signal }
|
|
302
|
+
});
|
|
303
|
+
} catch (e) {
|
|
304
|
+
throw new m({
|
|
305
|
+
tag: n,
|
|
306
|
+
reason: v.signal?.aborted ? "aborted" : "network",
|
|
307
|
+
message: String(e instanceof Error ? e.message : e),
|
|
308
|
+
cause: e
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
let b = u.headers.get("x-request-id") ?? void 0, x = u.headers.get("x-voltro-rest-profile");
|
|
312
|
+
if (!y && x !== null && (y = !0, x !== i.name)) throw new _({
|
|
313
|
+
expected: i.name,
|
|
314
|
+
actual: x
|
|
315
|
+
});
|
|
316
|
+
let T = u.headers.get("sunset"), D = u.headers.get("deprecation");
|
|
317
|
+
if ((T !== null || D !== null) && !p.has(n) && (p.add(n), h({
|
|
318
|
+
tag: n,
|
|
319
|
+
path: S.path,
|
|
320
|
+
sunset: T ?? S.sunset,
|
|
321
|
+
deprecated: S.deprecated
|
|
322
|
+
})), u.status === 304 && B !== void 0) return {
|
|
323
|
+
...B.result,
|
|
324
|
+
fromCache: !0,
|
|
325
|
+
requestId: b
|
|
326
|
+
};
|
|
327
|
+
let O;
|
|
328
|
+
try {
|
|
329
|
+
O = await u.text();
|
|
330
|
+
} catch (e) {
|
|
331
|
+
throw new m({
|
|
332
|
+
tag: n,
|
|
333
|
+
reason: "network",
|
|
334
|
+
message: "the body could not be read",
|
|
335
|
+
cause: e,
|
|
336
|
+
requestId: b
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
let j;
|
|
340
|
+
if (O.length > 0) try {
|
|
341
|
+
j = JSON.parse(O);
|
|
342
|
+
} catch {
|
|
343
|
+
throw new m({
|
|
344
|
+
tag: n,
|
|
345
|
+
reason: "decode",
|
|
346
|
+
message: `the answer was not JSON (${u.status})`,
|
|
347
|
+
requestId: b
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
if (u.status === 429) {
|
|
351
|
+
let e = C(u.headers, s()), i = Number(u.headers.get("ratelimit-limit") ?? NaN), a = Number(u.headers.get("ratelimit-remaining") ?? NaN), o = r.retry?.on429?.maxWaitMs;
|
|
352
|
+
if (o !== void 0 && t + e <= o) return await c(e), V(t + e);
|
|
353
|
+
throw new g({
|
|
354
|
+
tag: n,
|
|
355
|
+
retryAfterMs: e,
|
|
356
|
+
requestId: b,
|
|
357
|
+
...Number.isFinite(i) ? { limit: i } : {},
|
|
358
|
+
...Number.isFinite(a) ? { remaining: a } : {},
|
|
359
|
+
resetAtMs: s() + e
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
if (u.status >= 400) throw N(S, u.status, j, b);
|
|
363
|
+
let M, F = j;
|
|
364
|
+
if (i.pagination === "link-header" && (M = w(u.headers.get("link"), i.cursorParam)), i.envelope === "data" && typeof j == "object" && j && "data" in j) {
|
|
365
|
+
let e = j;
|
|
366
|
+
F = e.data, M === void 0 && typeof e.next == "string" && (M = e.next);
|
|
367
|
+
} else if (i.envelope === "jsonapi") {
|
|
368
|
+
let e = j?.links;
|
|
369
|
+
M === void 0 && typeof e?.next == "string" && (M = new URL(e.next, a).searchParams.get(i.cursorParam) ?? void 0), F = E(j, i.cursorField, M);
|
|
370
|
+
}
|
|
371
|
+
if (i.pagination === "body-cursor" && typeof F == "object" && F) {
|
|
372
|
+
let e = F[i.cursorField];
|
|
373
|
+
typeof e == "string" && (M = e);
|
|
374
|
+
}
|
|
375
|
+
let L = u.status === 204 || F === void 0 ? F : d(e.wire.procedures[n]?.output, F, A);
|
|
376
|
+
if (M === void 0 && typeof L == "object" && L) {
|
|
377
|
+
let e = L[i.cursorField];
|
|
378
|
+
typeof e == "string" && (M = e);
|
|
379
|
+
}
|
|
380
|
+
let z = u.headers.get("etag") ?? void 0, H = {
|
|
381
|
+
value: L,
|
|
382
|
+
nextCursor: M,
|
|
383
|
+
status: u.status,
|
|
384
|
+
requestId: b,
|
|
385
|
+
etag: z,
|
|
386
|
+
fromCache: !1
|
|
387
|
+
};
|
|
388
|
+
return P && l && z !== void 0 && f.set(I, {
|
|
389
|
+
etag: z,
|
|
390
|
+
result: H
|
|
391
|
+
}), H;
|
|
392
|
+
};
|
|
393
|
+
return V(0);
|
|
394
|
+
},
|
|
395
|
+
baseUrl: a
|
|
396
|
+
};
|
|
397
|
+
}, j = (e) => (e.startsWith("/") ? e.slice(1) : e).replace(/~1/g, "/").replace(/~0/g, "~"), M = (e, t, n = {}) => {
|
|
398
|
+
let r = /* @__PURE__ */ new Map();
|
|
399
|
+
for (let t of e) r.set(t.id, t);
|
|
400
|
+
for (let e of t.ops) {
|
|
401
|
+
if (e.op === "mergeCells") {
|
|
402
|
+
let t = j(e.path), i = r.get(t) ?? r.get(Number(t)), a = r.has(t) ? t : Number(t);
|
|
403
|
+
if (i === void 0) continue;
|
|
404
|
+
let o = { ...i };
|
|
405
|
+
for (let [t, r] of Object.entries(e.value)) o[t] = n.mergeCell === void 0 ? r : n.mergeCell(t, i[t], r);
|
|
406
|
+
r.set(a, o);
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
(e.op === "add" || e.op === "replace") && r.set(e.value.id, e.value);
|
|
410
|
+
}
|
|
411
|
+
let i = [];
|
|
412
|
+
for (let e of t.order) {
|
|
413
|
+
let t = r.get(e);
|
|
414
|
+
t !== void 0 && i.push(t);
|
|
415
|
+
}
|
|
416
|
+
return i;
|
|
417
|
+
}, N = (e) => {
|
|
418
|
+
let t = new URL(e);
|
|
419
|
+
return t.protocol = t.protocol === "https:" ? "wss:" : "ws:", t.pathname = "/ws", t.search = "", t.toString();
|
|
420
|
+
}, P = (e) => {
|
|
421
|
+
switch (e._tag) {
|
|
422
|
+
case "Fail": return {
|
|
423
|
+
kind: "fail",
|
|
424
|
+
error: e.error
|
|
425
|
+
};
|
|
426
|
+
case "Die": return {
|
|
427
|
+
kind: "die",
|
|
428
|
+
defect: e.defect
|
|
429
|
+
};
|
|
430
|
+
case "Sequential":
|
|
431
|
+
case "Parallel": return P(e.left) ?? P(e.right);
|
|
432
|
+
default: return;
|
|
433
|
+
}
|
|
434
|
+
}, F = (e, n, i, a = {}) => {
|
|
435
|
+
let o = a.wsUrl ?? N(i), s = a.webSocketConstructor ?? ((e) => new globalThis.WebSocket(e)), c = a.pingIntervalMs ?? 1e4, l = a.reconnect?.initialMs ?? 500, f = a.reconnect?.maxMs ?? 5e3, p = r(e.wire.models), h = /* @__PURE__ */ new Set(), g = /* @__PURE__ */ new Map(), _, v = !1, y = !1, b = !1, x = 0, S = 1, C, w, T = !0, E = (e) => {
|
|
436
|
+
_ !== void 0 && y && _.send(JSON.stringify(e));
|
|
437
|
+
}, D = async () => {
|
|
438
|
+
let e = typeof a.token == "function" ? await a.token() : a.token, t = Object.entries(a.headers ?? {});
|
|
439
|
+
return e !== void 0 && t.push(["authorization", `Bearer ${e}`]), a.tenant !== void 0 && t.push(["x-tenant", a.tenant]), t;
|
|
440
|
+
}, O = (t, r) => {
|
|
441
|
+
if (typeof r == "object" && r && "_tag" in r && typeof r._tag == "string") {
|
|
442
|
+
let { _tag: i, ...a } = r;
|
|
443
|
+
if (n[i] !== void 0) return k(e, n, t.tag, i, a, {
|
|
444
|
+
status: 0,
|
|
445
|
+
requestId: void 0,
|
|
446
|
+
detail: typeof a.message == "string" ? a.message : void 0,
|
|
447
|
+
body: r
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
let i = typeof r == "object" && r && typeof r.message == "string" ? r.message : String(r);
|
|
451
|
+
return new m({
|
|
452
|
+
tag: t.tag,
|
|
453
|
+
reason: "network",
|
|
454
|
+
message: i,
|
|
455
|
+
cause: r
|
|
456
|
+
});
|
|
457
|
+
}, A = (e, t) => {
|
|
458
|
+
if (e.waiting !== void 0) {
|
|
459
|
+
let n = e.waiting;
|
|
460
|
+
e.waiting = void 0, n(t);
|
|
461
|
+
} else t.done || e.queue.push(t.value);
|
|
462
|
+
}, j = (t) => {
|
|
463
|
+
let n = e.wire.procedures[t.tag]?.output;
|
|
464
|
+
A(t, {
|
|
465
|
+
value: d(n, t.rawBase, p),
|
|
466
|
+
done: !1
|
|
467
|
+
});
|
|
468
|
+
}, F = (e, t) => {
|
|
469
|
+
e.failure = t, e.ended = !0, h.delete(e), A(e, {
|
|
470
|
+
value: void 0,
|
|
471
|
+
done: !0
|
|
472
|
+
}), W();
|
|
473
|
+
}, I = (e) => {
|
|
474
|
+
e.ended = !0, h.delete(e), A(e, {
|
|
475
|
+
value: void 0,
|
|
476
|
+
done: !0
|
|
477
|
+
}), W();
|
|
478
|
+
}, L = (e, t) => {
|
|
479
|
+
if (typeof t != "object" || !t) return;
|
|
480
|
+
let n = t;
|
|
481
|
+
n._tag === "snapshot" ? (e.rawBase = n.data, typeof n.revision == "number" && (e.revision = n.revision), j(e)) : n._tag === "delta" ? (Array.isArray(e.rawBase) && (e.rawBase = M(e.rawBase, n.patch)), typeof n.revision == "number" && (e.revision = n.revision), e.rawBase !== void 0 && j(e)) : n._tag === "error" && F(e, O(e, n.error));
|
|
482
|
+
}, R = (e, t) => {
|
|
483
|
+
if (t._tag === "Success") {
|
|
484
|
+
I(e);
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
let n = P(t.cause);
|
|
488
|
+
if (n === void 0) {
|
|
489
|
+
I(e);
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
F(e, n.kind === "fail" ? O(e, n.error) : new m({
|
|
493
|
+
tag: e.tag,
|
|
494
|
+
reason: "network",
|
|
495
|
+
message: `the subscription died on the server: ${String(n.defect?.message ?? n.defect)}`,
|
|
496
|
+
cause: n.defect
|
|
497
|
+
}));
|
|
498
|
+
}, z = async (t) => {
|
|
499
|
+
let n = await D();
|
|
500
|
+
t.revision >= 0 && n.push(["voltro-resume-from", String(t.revision)]);
|
|
501
|
+
let r = String(S++);
|
|
502
|
+
t.requestId = r, g.set(r, t);
|
|
503
|
+
let i = e.wire.procedures[t.tag]?.input;
|
|
504
|
+
E({
|
|
505
|
+
_tag: "Request",
|
|
506
|
+
id: r,
|
|
507
|
+
tag: t.tag,
|
|
508
|
+
payload: u(i, t.input ?? {}, p) ?? {},
|
|
509
|
+
headers: n
|
|
510
|
+
});
|
|
511
|
+
}, B = (e, t) => {
|
|
512
|
+
for (let n of [...h]) F(n, new m({
|
|
513
|
+
tag: n.tag,
|
|
514
|
+
reason: "network",
|
|
515
|
+
message: e,
|
|
516
|
+
cause: t
|
|
517
|
+
}));
|
|
518
|
+
}, V = (e) => {
|
|
519
|
+
let t;
|
|
520
|
+
try {
|
|
521
|
+
t = JSON.parse(typeof e == "string" ? e : String(e));
|
|
522
|
+
} catch {
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
switch (t._tag) {
|
|
526
|
+
case "Chunk": {
|
|
527
|
+
let e = g.get(String(t.requestId));
|
|
528
|
+
if (e !== void 0 && Array.isArray(t.values)) for (let n of t.values) L(e, n);
|
|
529
|
+
E({
|
|
530
|
+
_tag: "Ack",
|
|
531
|
+
requestId: String(t.requestId)
|
|
532
|
+
});
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
case "Exit": {
|
|
536
|
+
let e = g.get(String(t.requestId));
|
|
537
|
+
g.delete(String(t.requestId)), e !== void 0 && R(e, t.exit);
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
case "Pong":
|
|
541
|
+
T = !0;
|
|
542
|
+
return;
|
|
543
|
+
case "Defect":
|
|
544
|
+
B("the socket died on a defect", t.defect);
|
|
545
|
+
return;
|
|
546
|
+
case "ClientProtocolError":
|
|
547
|
+
B("the socket answered with a protocol error", t.error);
|
|
548
|
+
return;
|
|
549
|
+
default: return;
|
|
550
|
+
}
|
|
551
|
+
}, H = () => {
|
|
552
|
+
C !== void 0 && (clearInterval(C), C = void 0);
|
|
553
|
+
}, U = () => {
|
|
554
|
+
if (_ !== void 0 || v || b) return;
|
|
555
|
+
v = !0, a.onStatus?.({
|
|
556
|
+
kind: "connecting",
|
|
557
|
+
attempt: x
|
|
558
|
+
});
|
|
559
|
+
let e = s(o);
|
|
560
|
+
_ = e, e.onopen = () => {
|
|
561
|
+
v = !1, y = !0, x = 0, T = !0, a.onStatus?.({ kind: "open" }), H(), C = setInterval(() => {
|
|
562
|
+
if (!T) {
|
|
563
|
+
e.close(4e3, "ping timeout");
|
|
564
|
+
return;
|
|
565
|
+
}
|
|
566
|
+
T = !1, E({ _tag: "Ping" });
|
|
567
|
+
}, c);
|
|
568
|
+
for (let e of h) z(e);
|
|
569
|
+
}, e.onmessage = (e) => {
|
|
570
|
+
V(e.data);
|
|
571
|
+
}, e.onerror = () => {}, e.onclose = () => {
|
|
572
|
+
if (_ !== e) return;
|
|
573
|
+
_ = void 0, v = !1, y = !1, H(), g.clear();
|
|
574
|
+
for (let e of h) e.requestId = void 0;
|
|
575
|
+
let t = !b && h.size > 0 ? Math.min(f, l * 1.5 ** x) : void 0;
|
|
576
|
+
a.onStatus?.({
|
|
577
|
+
kind: "closed",
|
|
578
|
+
reconnectInMs: t
|
|
579
|
+
}), t !== void 0 && (x += 1, w = setTimeout(() => {
|
|
580
|
+
w = void 0, U();
|
|
581
|
+
}, t));
|
|
582
|
+
};
|
|
583
|
+
}, W = () => {
|
|
584
|
+
if (h.size > 0 || _ === void 0) return;
|
|
585
|
+
let e = _;
|
|
586
|
+
_ = void 0, y = !1, H(), e.close(1e3, "no subscriptions"), a.onStatus?.({
|
|
587
|
+
kind: "closed",
|
|
588
|
+
reconnectInMs: void 0
|
|
589
|
+
});
|
|
590
|
+
};
|
|
591
|
+
return {
|
|
592
|
+
subscribe: (n, r = {}) => ({ [Symbol.asyncIterator]: () => {
|
|
593
|
+
t(e, n);
|
|
594
|
+
let i = {
|
|
595
|
+
tag: n,
|
|
596
|
+
input: r,
|
|
597
|
+
requestId: void 0,
|
|
598
|
+
rawBase: void 0,
|
|
599
|
+
revision: -1,
|
|
600
|
+
ended: !1,
|
|
601
|
+
failure: void 0,
|
|
602
|
+
queue: [],
|
|
603
|
+
waiting: void 0
|
|
604
|
+
};
|
|
605
|
+
return h.add(i), y ? z(i) : U(), {
|
|
606
|
+
next: async () => {
|
|
607
|
+
if (i.queue.length > 0) return {
|
|
608
|
+
value: i.queue.shift(),
|
|
609
|
+
done: !1
|
|
610
|
+
};
|
|
611
|
+
if (i.failure !== void 0) {
|
|
612
|
+
let e = i.failure;
|
|
613
|
+
throw i.failure = void 0, e;
|
|
614
|
+
}
|
|
615
|
+
if (i.ended) return {
|
|
616
|
+
value: void 0,
|
|
617
|
+
done: !0
|
|
618
|
+
};
|
|
619
|
+
let e = await new Promise((e) => {
|
|
620
|
+
i.waiting = e;
|
|
621
|
+
});
|
|
622
|
+
if (e.done && i.failure !== void 0) {
|
|
623
|
+
let e = i.failure;
|
|
624
|
+
throw i.failure = void 0, e;
|
|
625
|
+
}
|
|
626
|
+
return e;
|
|
627
|
+
},
|
|
628
|
+
return: async () => (i.ended || (i.ended = !0, h.delete(i), i.requestId !== void 0 && (E({
|
|
629
|
+
_tag: "Interrupt",
|
|
630
|
+
requestId: i.requestId
|
|
631
|
+
}), g.delete(i.requestId)), A(i, {
|
|
632
|
+
value: void 0,
|
|
633
|
+
done: !0
|
|
634
|
+
}), W()), {
|
|
635
|
+
value: void 0,
|
|
636
|
+
done: !0
|
|
637
|
+
})
|
|
638
|
+
};
|
|
639
|
+
} }),
|
|
640
|
+
close: async () => {
|
|
641
|
+
b = !0, w !== void 0 && (clearTimeout(w), w = void 0);
|
|
642
|
+
for (let e of [...h]) I(e);
|
|
643
|
+
H();
|
|
644
|
+
let e = _;
|
|
645
|
+
_ = void 0, y = !1, e !== void 0 && (e.close(1e3, "closed"), a.onStatus?.({
|
|
646
|
+
kind: "closed",
|
|
647
|
+
reconnectInMs: void 0
|
|
648
|
+
}));
|
|
649
|
+
}
|
|
650
|
+
};
|
|
651
|
+
}, I = (t) => {
|
|
652
|
+
let n = {};
|
|
653
|
+
for (let r of t.manifest.projections) {
|
|
654
|
+
let i = Object.assign((e, n) => t.call(r.tag, e, n), {
|
|
655
|
+
pages: (e, n) => t.pages(r.tag, e, n),
|
|
656
|
+
subscribe: (e) => t.subscribe(r.tag, e),
|
|
657
|
+
tag: r.tag
|
|
658
|
+
}), { namespace: a, method: o } = e(r.tag);
|
|
659
|
+
if (a === void 0) {
|
|
660
|
+
n[o] = i;
|
|
661
|
+
continue;
|
|
662
|
+
}
|
|
663
|
+
let s = n[a] ?? {};
|
|
664
|
+
s[o] = i, n[a] = s;
|
|
665
|
+
}
|
|
666
|
+
return n;
|
|
667
|
+
}, L = (e, t, n, r) => ({ async *[Symbol.asyncIterator]() {
|
|
668
|
+
let i;
|
|
669
|
+
for (;;) {
|
|
670
|
+
let a = await e(i === void 0 ? n : {
|
|
671
|
+
...typeof n == "object" && n ? n : {},
|
|
672
|
+
[t]: i
|
|
673
|
+
}, r);
|
|
674
|
+
if (yield a.value, a.nextCursor === void 0) return;
|
|
675
|
+
i = a.nextCursor;
|
|
676
|
+
}
|
|
677
|
+
} }), R = (e, t = {}) => {
|
|
678
|
+
let n = A(e.manifest, e.errors, t), r = e.manifest.profile.cursorParam, i, a = () => i ??= F(e.manifest, e.errors, n.baseUrl, {
|
|
679
|
+
token: t.token,
|
|
680
|
+
tenant: t.tenant,
|
|
681
|
+
headers: t.headers,
|
|
682
|
+
...t.subscriptions ?? {}
|
|
683
|
+
});
|
|
684
|
+
return {
|
|
685
|
+
manifest: e.manifest,
|
|
686
|
+
errors: e.errors,
|
|
687
|
+
call: async (e, t = {}, r) => (await n.call(e, t, r)).value,
|
|
688
|
+
callRaw: (e, t = {}, r) => n.call(e, t, r),
|
|
689
|
+
pages: (e, t = {}, i) => L((t, r) => n.call(e, t, r), r, t, i),
|
|
690
|
+
subscribe: (e, t = {}) => a().subscribe(e, t),
|
|
691
|
+
close: async () => {
|
|
692
|
+
await i?.close();
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
}, z = (e, t = {}) => {
|
|
696
|
+
let n = R(e, t);
|
|
697
|
+
return Object.assign(I(n), n);
|
|
698
|
+
}, B = (e) => e instanceof Error || typeof e == "object" && !!e && "_tag" in e && typeof e._tag == "string" && e._tag.endsWith("Error"), V = (e, t = {}) => {
|
|
699
|
+
let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = /* @__PURE__ */ new Map(), a = /* @__PURE__ */ new Map(), o = [], s = async (e, t) => {
|
|
700
|
+
o.push({
|
|
701
|
+
tag: e,
|
|
702
|
+
input: t
|
|
703
|
+
});
|
|
704
|
+
let i = r.get(e);
|
|
705
|
+
if (i !== void 0) throw i.times !== Infinity && (--i.times, i.times <= 0 && r.delete(e)), i.error;
|
|
706
|
+
return {
|
|
707
|
+
value: n.get(e),
|
|
708
|
+
nextCursor: void 0,
|
|
709
|
+
status: 200,
|
|
710
|
+
requestId: void 0,
|
|
711
|
+
etag: void 0,
|
|
712
|
+
fromCache: !1
|
|
713
|
+
};
|
|
714
|
+
}, c = {
|
|
715
|
+
manifest: e,
|
|
716
|
+
errors: t,
|
|
717
|
+
call: async (e, t = {}) => (await s(e, t)).value,
|
|
718
|
+
callRaw: (e, t = {}) => s(e, t),
|
|
719
|
+
pages: (e, t = {}) => ({ async *[Symbol.asyncIterator]() {
|
|
720
|
+
let n = i.get(e);
|
|
721
|
+
if (n === void 0) {
|
|
722
|
+
yield (await s(e, t)).value;
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
o.push({
|
|
726
|
+
tag: e,
|
|
727
|
+
input: t
|
|
728
|
+
});
|
|
729
|
+
for (let e of n) {
|
|
730
|
+
if (B(e)) throw e;
|
|
731
|
+
yield e;
|
|
732
|
+
}
|
|
733
|
+
} }),
|
|
734
|
+
subscribe: (e) => ({ [Symbol.asyncIterator]: () => {
|
|
735
|
+
let t = [], r, i = !1, o = (e) => {
|
|
736
|
+
if (r !== void 0) {
|
|
737
|
+
let t = r;
|
|
738
|
+
r = void 0, t({
|
|
739
|
+
value: e,
|
|
740
|
+
done: !1
|
|
741
|
+
});
|
|
742
|
+
} else t.push(e);
|
|
743
|
+
}, s = a.get(e) ?? /* @__PURE__ */ new Set();
|
|
744
|
+
return s.add(o), a.set(e, s), n.has(e) && o(n.get(e)), {
|
|
745
|
+
next: async () => t.length > 0 ? {
|
|
746
|
+
value: t.shift(),
|
|
747
|
+
done: !1
|
|
748
|
+
} : i ? {
|
|
749
|
+
value: void 0,
|
|
750
|
+
done: !0
|
|
751
|
+
} : new Promise((e) => {
|
|
752
|
+
r = e;
|
|
753
|
+
}),
|
|
754
|
+
return: async () => (i = !0, s.delete(o), r?.({
|
|
755
|
+
value: void 0,
|
|
756
|
+
done: !0
|
|
757
|
+
}), r = void 0, {
|
|
758
|
+
value: void 0,
|
|
759
|
+
done: !0
|
|
760
|
+
})
|
|
761
|
+
};
|
|
762
|
+
} }),
|
|
763
|
+
close: async () => {},
|
|
764
|
+
setData: (e, t) => {
|
|
765
|
+
n.set(e, t);
|
|
766
|
+
for (let n of a.get(e) ?? []) n(t);
|
|
767
|
+
},
|
|
768
|
+
setError: (e, t, n = Infinity) => {
|
|
769
|
+
r.set(e, {
|
|
770
|
+
error: t,
|
|
771
|
+
times: n
|
|
772
|
+
});
|
|
773
|
+
},
|
|
774
|
+
setPages: (e, t) => {
|
|
775
|
+
i.set(e, t);
|
|
776
|
+
},
|
|
777
|
+
push: (e, t) => {
|
|
778
|
+
for (let n of a.get(e) ?? []) n(t);
|
|
779
|
+
},
|
|
780
|
+
get calls() {
|
|
781
|
+
return o;
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
return Object.assign(I(c), c);
|
|
785
|
+
};
|
|
786
|
+
//#endregion
|
|
787
|
+
export { p as ApiClientError, h as ApiHttpError, y as DeclaredError, v as InputEncodeError, _ as ProfileMismatchError, g as RateLimitedError, m as TransportError, M as applyRowPatch, I as buildNamespaces, z as createClient, V as createMockClient, R as createPromiseClient, w as cursorFromLink, k as declaredErrorOf, d as decodeWire, b as defineError, u as encodeWire, f as hasRequiredField, A as makeRestCore, F as openLiveQueries, L as pagesOf, j as pathToId, t as projectionOf, r as rpcCodec, e as splitTag, n as toSnakeCase, x as uuidV7, N as wsUrlFromBase };
|