@voltro/api-client 0.89.2 → 0.91.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 +1943 -0
- package/dist/client.js +23 -23
- package/dist/index.js +8 -8
- package/dist/live.js +41 -41
- package/dist/rest.js +65 -65
- package/package.json +1 -1
package/dist/client.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { apiRoleEndpointUrl as e, captureApiRoleEndpoints as t, selectApiRoleEndpoint as n } from "./apiRoleEndpoints.js";
|
|
2
|
+
import { openLiveQueries as r } from "./live.js";
|
|
3
|
+
import { splitTag as i } from "./manifest.js";
|
|
4
|
+
import { makeRestCore as a } from "./rest.js";
|
|
5
5
|
// src/client.ts
|
|
6
|
-
var o = (
|
|
7
|
-
let
|
|
8
|
-
for (let
|
|
9
|
-
let
|
|
10
|
-
pages: (
|
|
11
|
-
subscribe: (
|
|
12
|
-
tag:
|
|
13
|
-
}), { namespace: a, method: o } =
|
|
6
|
+
var o = (e) => {
|
|
7
|
+
let t = {};
|
|
8
|
+
for (let n of e.manifest.projections) {
|
|
9
|
+
let r = Object.assign((t, r) => e.call(n.tag, t, r), {
|
|
10
|
+
pages: (t, r) => e.pages(n.tag, t, r),
|
|
11
|
+
subscribe: (t) => e.subscribe(n.tag, t),
|
|
12
|
+
tag: n.tag
|
|
13
|
+
}), { namespace: a, method: o } = i(n.tag);
|
|
14
14
|
if (a === void 0) {
|
|
15
|
-
|
|
15
|
+
t[o] = r;
|
|
16
16
|
continue;
|
|
17
17
|
}
|
|
18
|
-
let s =
|
|
19
|
-
s[o] =
|
|
18
|
+
let s = t[a] ?? {};
|
|
19
|
+
s[o] = r, t[a] = s;
|
|
20
20
|
}
|
|
21
|
-
return
|
|
21
|
+
return t;
|
|
22
22
|
}, s = (e, t, n, r) => ({ async *[Symbol.asyncIterator]() {
|
|
23
23
|
let i;
|
|
24
24
|
for (;;) {
|
|
@@ -29,23 +29,23 @@ var o = (t) => {
|
|
|
29
29
|
if (yield a.value, a.nextCursor === void 0) return;
|
|
30
30
|
i = a.nextCursor;
|
|
31
31
|
}
|
|
32
|
-
} }), c = (
|
|
33
|
-
let c =
|
|
32
|
+
} }), c = (i, o = {}) => {
|
|
33
|
+
let c = a(i.manifest, i.errors, o), l = i.manifest.profile.cursorParam, u = o.roleEndpoints === void 0 ? void 0 : t(o.roleEndpoints);
|
|
34
34
|
if (u && o.subscriptions?.wsUrl !== void 0) throw Error("Role endpoints and a fixed subscription URL are mutually exclusive");
|
|
35
35
|
let d = /* @__PURE__ */ new Map(), f = !1, p = (t) => {
|
|
36
36
|
if (f) throw Error("API client is closed");
|
|
37
|
-
let
|
|
38
|
-
return l || (l =
|
|
37
|
+
let a = u && n(u, t, "subscriptions"), s = a?.role ?? "default", l = d.get(s);
|
|
38
|
+
return l || (l = r(i.manifest, i.errors, c.baseUrl, {
|
|
39
39
|
token: o.token,
|
|
40
40
|
tenant: o.tenant,
|
|
41
41
|
headers: o.headers,
|
|
42
42
|
...o.subscriptions ?? {},
|
|
43
|
-
...
|
|
43
|
+
...a ? { wsUrl: e(c.baseUrl, a, "websocket") } : {}
|
|
44
44
|
}), d.set(s, l)), l;
|
|
45
45
|
};
|
|
46
46
|
return {
|
|
47
|
-
manifest:
|
|
48
|
-
errors:
|
|
47
|
+
manifest: i.manifest,
|
|
48
|
+
errors: i.errors,
|
|
49
49
|
call: async (e, t = {}, n) => (await c.call(e, t, n)).value,
|
|
50
50
|
callRaw: (e, t = {}, n) => c.call(e, t, n),
|
|
51
51
|
pages: (e, t = {}, n) => s((t, n) => c.call(e, t, n), l, t, n),
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { projectionOf as e, splitTag as t } from "./manifest.js";
|
|
2
2
|
import { decodeWire as n, encodeWire as r, hasRequiredField as i, rpcCodec as a, toSnakeCase as o } from "./wire.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
export {
|
|
3
|
+
import { openLiveQueries as s, wsUrlFromBase as c } from "./live.js";
|
|
4
|
+
import { applyRowPatch as l, pathToId as u } from "./rowPatch.js";
|
|
5
|
+
import { cursorFromLink as d, declaredErrorOf as f, makeRestCore as p, uuidV7 as m } from "./rest.js";
|
|
6
|
+
import { ApiClientError as h, ApiHttpError as g, DeclaredError as _, InputEncodeError as v, ProfileMismatchError as y, RateLimitedError as b, TransportError as x, defineError as S } from "./errors.js";
|
|
7
|
+
import { buildNamespaces as C, createClient as w, createPromiseClient as T, pagesOf as E } from "./client.js";
|
|
8
|
+
import { createMockClient as D } from "./mock.js";
|
|
9
|
+
import { apiRoleEndpointUrl as O, apiRoleProxyBasePath as k, captureApiRoleEndpoints as A, selectApiRoleEndpoint as j } from "./apiRoleEndpoints.js";
|
|
10
|
+
export { h as ApiClientError, g as ApiHttpError, _ as DeclaredError, v as InputEncodeError, y as ProfileMismatchError, b as RateLimitedError, x as TransportError, O as apiRoleEndpointUrl, k as apiRoleProxyBasePath, l as applyRowPatch, C as buildNamespaces, A as captureApiRoleEndpoints, w as createClient, D as createMockClient, T as createPromiseClient, d as cursorFromLink, f as declaredErrorOf, n as decodeWire, S as defineError, r as encodeWire, i as hasRequiredField, p as makeRestCore, s as openLiveQueries, E as pagesOf, u as pathToId, e as projectionOf, a as rpcCodec, j as selectApiRoleEndpoint, t as splitTag, o as toSnakeCase, m as uuidV7, c as wsUrlFromBase };
|
package/dist/live.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { TransportError as e } from "./errors.js";
|
|
2
|
+
import { projectionOf as t } from "./manifest.js";
|
|
3
|
+
import { declaredErrorOf as n } from "./rest.js";
|
|
4
|
+
import { createRowPatchApplier as r } from "./rowPatch.js";
|
|
5
|
+
import { decodeWire as i, encodeWire as a, rpcCodec as o } from "./wire.js";
|
|
6
6
|
// src/live.ts
|
|
7
7
|
var s = (e) => {
|
|
8
8
|
let t = new URL(e);
|
|
@@ -17,27 +17,27 @@ var s = (e) => {
|
|
|
17
17
|
defect: t.defect
|
|
18
18
|
};
|
|
19
19
|
}, l = (l, u, d, f = {}) => {
|
|
20
|
-
let p = f.wsUrl ?? s(d), m = f.webSocketConstructor ?? ((e) => new globalThis.WebSocket(e)), h = f.pingIntervalMs ?? 1e4, g = f.reconnect?.initialMs ?? 500, _ = f.reconnect?.maxMs ?? 5e3, v =
|
|
20
|
+
let p = f.wsUrl ?? s(d), m = f.webSocketConstructor ?? ((e) => new globalThis.WebSocket(e)), h = f.pingIntervalMs ?? 1e4, g = f.reconnect?.initialMs ?? 500, _ = f.reconnect?.maxMs ?? 5e3, v = o(l.wire.models), y = /* @__PURE__ */ new Set(), b = /* @__PURE__ */ new Map(), x, S = !1, C = !1, w = !1, T = 0, E = 1, D, O, k = !0, A = (e) => {
|
|
21
21
|
x !== void 0 && C && x.send(JSON.stringify(e));
|
|
22
22
|
}, j = async () => {
|
|
23
23
|
let e = typeof f.token == "function" ? await f.token() : f.token, t = Object.entries(f.headers ?? {});
|
|
24
24
|
return e !== void 0 && t.push(["authorization", `Bearer ${e}`]), f.tenant !== void 0 && t.push(["x-tenant", f.tenant]), t;
|
|
25
|
-
}, M = (
|
|
26
|
-
if (typeof
|
|
27
|
-
let { _tag:
|
|
28
|
-
if (u[
|
|
25
|
+
}, M = (t, r) => {
|
|
26
|
+
if (typeof r == "object" && r && "_tag" in r && typeof r._tag == "string") {
|
|
27
|
+
let { _tag: e, ...i } = r;
|
|
28
|
+
if (u[e] !== void 0) return n(l, u, t.tag, e, i, {
|
|
29
29
|
status: 0,
|
|
30
30
|
requestId: void 0,
|
|
31
|
-
detail: typeof
|
|
32
|
-
body:
|
|
31
|
+
detail: typeof i.message == "string" ? i.message : void 0,
|
|
32
|
+
body: r
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
|
-
let
|
|
36
|
-
return new
|
|
37
|
-
tag:
|
|
35
|
+
let i = typeof r == "object" && r && typeof r.message == "string" ? r.message : String(r);
|
|
36
|
+
return new e({
|
|
37
|
+
tag: t.tag,
|
|
38
38
|
reason: "network",
|
|
39
|
-
message:
|
|
40
|
-
cause:
|
|
39
|
+
message: i,
|
|
40
|
+
cause: r
|
|
41
41
|
});
|
|
42
42
|
}, N = (e, t) => {
|
|
43
43
|
if (e.waiting !== void 0) {
|
|
@@ -45,9 +45,9 @@ var s = (e) => {
|
|
|
45
45
|
e.waiting = void 0, n(t);
|
|
46
46
|
} else t.done || e.queue.push(t.value);
|
|
47
47
|
}, P = (e) => {
|
|
48
|
-
let
|
|
48
|
+
let t = l.wire.procedures[e.tag]?.output;
|
|
49
49
|
N(e, {
|
|
50
|
-
value: t
|
|
50
|
+
value: i(t, e.rawBase, v),
|
|
51
51
|
done: !1
|
|
52
52
|
});
|
|
53
53
|
}, F = (e, t) => {
|
|
@@ -63,38 +63,38 @@ var s = (e) => {
|
|
|
63
63
|
}, L = (e, t) => {
|
|
64
64
|
if (typeof t != "object" || !t) return;
|
|
65
65
|
let n = t;
|
|
66
|
-
n._tag === "snapshot" ? (e.patchApplier?.reset(), e.rawBase = n.data, typeof n.revision == "number" && (e.revision = n.revision), P(e)) : n._tag === "delta" ? (Array.isArray(e.rawBase) && (e.patchApplier ??=
|
|
67
|
-
}, R = (
|
|
68
|
-
if (
|
|
69
|
-
I(
|
|
66
|
+
n._tag === "snapshot" ? (e.patchApplier?.reset(), e.rawBase = n.data, typeof n.revision == "number" && (e.revision = n.revision), P(e)) : n._tag === "delta" ? (Array.isArray(e.rawBase) && (e.patchApplier ??= r(), e.rawBase = e.patchApplier.apply(e.rawBase, n.patch)), typeof n.revision == "number" && (e.revision = n.revision), e.rawBase !== void 0 && P(e)) : n._tag === "error" && F(e, M(e, n.error));
|
|
67
|
+
}, R = (t, n) => {
|
|
68
|
+
if (n._tag === "Success") {
|
|
69
|
+
I(t);
|
|
70
70
|
return;
|
|
71
71
|
}
|
|
72
|
-
let
|
|
73
|
-
|
|
74
|
-
tag:
|
|
72
|
+
let r = c(n.cause);
|
|
73
|
+
r === void 0 ? I(t) : F(t, r.kind === "fail" ? M(t, r.error) : new e({
|
|
74
|
+
tag: t.tag,
|
|
75
75
|
reason: "network",
|
|
76
|
-
message: `the subscription died on the server: ${String(
|
|
77
|
-
cause:
|
|
76
|
+
message: `the subscription died on the server: ${String(r.defect?.message ?? r.defect)}`,
|
|
77
|
+
cause: r.defect
|
|
78
78
|
}));
|
|
79
79
|
}, z = async (e) => {
|
|
80
80
|
let t = await j();
|
|
81
81
|
e.revision >= 0 && t.push(["voltro-resume-from", String(e.revision)]);
|
|
82
|
-
let
|
|
83
|
-
e.requestId =
|
|
84
|
-
let
|
|
82
|
+
let n = String(E++);
|
|
83
|
+
e.requestId = n, b.set(n, e);
|
|
84
|
+
let r = l.wire.procedures[e.tag]?.input;
|
|
85
85
|
A({
|
|
86
86
|
_tag: "Request",
|
|
87
|
-
id:
|
|
87
|
+
id: n,
|
|
88
88
|
tag: e.tag,
|
|
89
|
-
payload:
|
|
89
|
+
payload: a(r, e.input ?? {}, v) ?? {},
|
|
90
90
|
headers: t
|
|
91
91
|
});
|
|
92
|
-
}, B = (
|
|
93
|
-
for (let
|
|
94
|
-
tag:
|
|
92
|
+
}, B = (t, n) => {
|
|
93
|
+
for (let r of [...y]) F(r, new e({
|
|
94
|
+
tag: r.tag,
|
|
95
95
|
reason: "network",
|
|
96
|
-
message:
|
|
97
|
-
cause:
|
|
96
|
+
message: t,
|
|
97
|
+
cause: n
|
|
98
98
|
}));
|
|
99
99
|
}, V = (e) => {
|
|
100
100
|
let t;
|
|
@@ -166,10 +166,10 @@ var s = (e) => {
|
|
|
166
166
|
});
|
|
167
167
|
};
|
|
168
168
|
return {
|
|
169
|
-
subscribe: (
|
|
170
|
-
|
|
169
|
+
subscribe: (e, n = {}) => ({ [Symbol.asyncIterator]: () => {
|
|
170
|
+
t(l, e);
|
|
171
171
|
let r = {
|
|
172
|
-
tag:
|
|
172
|
+
tag: e,
|
|
173
173
|
input: n,
|
|
174
174
|
requestId: void 0,
|
|
175
175
|
rawBase: void 0,
|
package/dist/rest.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { ApiHttpError as e, InputEncodeError as t, ProfileMismatchError as n, RateLimitedError as r, TransportError as i } from "./errors.js";
|
|
2
|
+
import { projectionOf as a } from "./manifest.js";
|
|
3
|
+
import { decodeWire as o, encodeWire as s } from "./wire.js";
|
|
4
4
|
// src/rest.ts
|
|
5
5
|
var c = (e = Date.now()) => {
|
|
6
6
|
let t = /* @__PURE__ */ new Uint8Array(16);
|
|
@@ -52,50 +52,50 @@ var c = (e = Date.now()) => {
|
|
|
52
52
|
console.warn(`[@voltro/api-client] ${e.tag} (${e.path}) is deprecated${t}${e.deprecated === void 0 ? "" : `: ${e.deprecated}`}`);
|
|
53
53
|
}, h = (e) => new Promise((t) => {
|
|
54
54
|
setTimeout(t, e);
|
|
55
|
-
}), g = (
|
|
56
|
-
if (
|
|
57
|
-
let
|
|
58
|
-
if (
|
|
59
|
-
let n =
|
|
60
|
-
dates:
|
|
61
|
-
naming:
|
|
62
|
-
models:
|
|
55
|
+
}), g = (t, n, r, i, a, s) => {
|
|
56
|
+
if (i !== void 0) {
|
|
57
|
+
let e = n[i], c = t.wire.procedures[r]?.errors?.[i];
|
|
58
|
+
if (e !== void 0) {
|
|
59
|
+
let n = o(c, a, {
|
|
60
|
+
dates: t.profile.dates,
|
|
61
|
+
naming: t.profile.naming,
|
|
62
|
+
models: t.wire.models
|
|
63
63
|
});
|
|
64
|
-
return new
|
|
64
|
+
return new e(typeof n == "object" && n ? n : {}, {
|
|
65
65
|
status: s.status,
|
|
66
66
|
requestId: s.requestId,
|
|
67
67
|
detail: s.detail
|
|
68
68
|
});
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
return new
|
|
72
|
-
tag:
|
|
71
|
+
return new e({
|
|
72
|
+
tag: r,
|
|
73
73
|
status: s.status,
|
|
74
|
-
errorTag:
|
|
74
|
+
errorTag: i,
|
|
75
75
|
detail: s.detail,
|
|
76
76
|
body: s.body,
|
|
77
77
|
requestId: s.requestId
|
|
78
78
|
});
|
|
79
|
-
}, _ = (
|
|
80
|
-
let y =
|
|
79
|
+
}, _ = (e, _, v = {}) => {
|
|
80
|
+
let y = e.profile, b = (v.baseUrl ?? e.servers[0]?.url ?? "").replace(/\/+$/, "");
|
|
81
81
|
if (b === "") throw Error("@voltro/api-client: no baseUrl — pass one, or generate the client with `--base-url` or `servers`");
|
|
82
|
-
let x = v.fetch ?? globalThis.fetch, S = v.clock ?? (() => Date.now()), C = v.sleep ?? h, w = v.etagCache ?? y.etag, T = /* @__PURE__ */ new Map(), E = /* @__PURE__ */ new Set(), D = v.onSunset ?? m, O = !1, k = v.userAgent ?? (
|
|
82
|
+
let x = v.fetch ?? globalThis.fetch, S = v.clock ?? (() => Date.now()), C = v.sleep ?? h, w = v.etagCache ?? y.etag, T = /* @__PURE__ */ new Map(), E = /* @__PURE__ */ new Set(), D = v.onSunset ?? m, O = !1, k = v.userAgent ?? (e.name === void 0 ? void 0 : `${e.name}/${e.version ?? "0.0.0"} (${e.generatedBy})`), A = {
|
|
83
83
|
dates: y.dates,
|
|
84
84
|
naming: y.naming,
|
|
85
|
-
models:
|
|
86
|
-
}, j = async () => typeof v.token == "function" ? await v.token() : v.token, M = (
|
|
87
|
-
let
|
|
85
|
+
models: e.wire.models
|
|
86
|
+
}, j = async () => typeof v.token == "function" ? await v.token() : v.token, M = (n, r) => {
|
|
87
|
+
let i = e.wire.procedures[n.tag]?.input;
|
|
88
88
|
try {
|
|
89
|
-
let e =
|
|
89
|
+
let e = s(i, r ?? {}, A);
|
|
90
90
|
return typeof e == "object" && e ? e : {};
|
|
91
|
-
} catch (
|
|
92
|
-
throw new
|
|
93
|
-
tag:
|
|
94
|
-
message: String(
|
|
91
|
+
} catch (e) {
|
|
92
|
+
throw new t({
|
|
93
|
+
tag: n.tag,
|
|
94
|
+
message: String(e instanceof Error ? e.message.split("\n")[0] : e)
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
|
-
}, N = (
|
|
98
|
-
let a = typeof
|
|
97
|
+
}, N = (t, n, r, i) => {
|
|
98
|
+
let a = typeof r == "object" && r ? r : {}, o, s, c;
|
|
99
99
|
if (y.errors === "problem-details" && y.envelope !== "jsonapi") {
|
|
100
100
|
o = l(a.type);
|
|
101
101
|
let { type: e, title: t, status: n, detail: r, ...i } = a;
|
|
@@ -107,17 +107,17 @@ var c = (e = Date.now()) => {
|
|
|
107
107
|
let { error: e, ...t } = a;
|
|
108
108
|
o = typeof e == "string" ? e : void 0, s = t, c = typeof e == "string" ? e : void 0;
|
|
109
109
|
}
|
|
110
|
-
return g(
|
|
111
|
-
status:
|
|
110
|
+
return g(e, _, t.tag, o, s, {
|
|
111
|
+
status: n,
|
|
112
112
|
requestId: i,
|
|
113
113
|
detail: c,
|
|
114
|
-
body:
|
|
114
|
+
body: r
|
|
115
115
|
});
|
|
116
116
|
};
|
|
117
117
|
return {
|
|
118
|
-
manifest:
|
|
119
|
-
call: async (
|
|
120
|
-
let m = e
|
|
118
|
+
manifest: e,
|
|
119
|
+
call: async (t, s, l = {}) => {
|
|
120
|
+
let m = a(e, t), h = M(m, s), g = m.path, _ = { ...h };
|
|
121
121
|
for (let e of m.pathParams) {
|
|
122
122
|
let t = _[e];
|
|
123
123
|
delete _[e], g = g.replace(`:${e}`, encodeURIComponent(t === void 0 ? "" : String(t)));
|
|
@@ -132,45 +132,45 @@ var c = (e = Date.now()) => {
|
|
|
132
132
|
z !== void 0 && (R.traceparent = z), P || (R["content-type"] = "application/json"), P || m.idempotent !== !0 && l.idempotencyKey === void 0 || (R["idempotency-key"] = l.idempotencyKey ?? c(S()));
|
|
133
133
|
let B = P && w ? T.get(I) : void 0;
|
|
134
134
|
B !== void 0 && (R["if-none-match"] = B.etag);
|
|
135
|
-
let V = async (
|
|
136
|
-
let
|
|
135
|
+
let V = async (a) => {
|
|
136
|
+
let s;
|
|
137
137
|
try {
|
|
138
|
-
|
|
138
|
+
s = await x(I, {
|
|
139
139
|
method: m.method,
|
|
140
140
|
headers: R,
|
|
141
141
|
...P ? {} : { body: JSON.stringify(_) },
|
|
142
142
|
...l.signal === void 0 ? {} : { signal: l.signal }
|
|
143
143
|
});
|
|
144
144
|
} catch (e) {
|
|
145
|
-
throw new
|
|
146
|
-
tag:
|
|
145
|
+
throw new i({
|
|
146
|
+
tag: t,
|
|
147
147
|
reason: l.signal?.aborted ? "aborted" : "network",
|
|
148
148
|
message: String(e instanceof Error ? e.message : e),
|
|
149
149
|
cause: e
|
|
150
150
|
});
|
|
151
151
|
}
|
|
152
|
-
let c =
|
|
153
|
-
if (!O && f !== null && (O = !0, f !== y.name)) throw new
|
|
152
|
+
let c = s.headers.get("x-request-id") ?? void 0, f = s.headers.get("x-voltro-rest-profile");
|
|
153
|
+
if (!O && f !== null && (O = !0, f !== y.name)) throw new n({
|
|
154
154
|
expected: y.name,
|
|
155
155
|
actual: f
|
|
156
156
|
});
|
|
157
|
-
let h =
|
|
158
|
-
if (h === null && g === null || E.has(
|
|
159
|
-
tag:
|
|
157
|
+
let h = s.headers.get("sunset"), g = s.headers.get("deprecation");
|
|
158
|
+
if (h === null && g === null || E.has(t) || (E.add(t), D({
|
|
159
|
+
tag: t,
|
|
160
160
|
path: m.path,
|
|
161
161
|
sunset: h ?? m.sunset,
|
|
162
162
|
deprecated: m.deprecated
|
|
163
|
-
})),
|
|
163
|
+
})), s.status === 304 && B !== void 0) return {
|
|
164
164
|
...B.result,
|
|
165
165
|
fromCache: !0,
|
|
166
166
|
requestId: c
|
|
167
167
|
};
|
|
168
168
|
let k;
|
|
169
169
|
try {
|
|
170
|
-
k = await
|
|
170
|
+
k = await s.text();
|
|
171
171
|
} catch (e) {
|
|
172
|
-
throw new
|
|
173
|
-
tag:
|
|
172
|
+
throw new i({
|
|
173
|
+
tag: t,
|
|
174
174
|
reason: "network",
|
|
175
175
|
message: "the body could not be read",
|
|
176
176
|
cause: e,
|
|
@@ -181,28 +181,28 @@ var c = (e = Date.now()) => {
|
|
|
181
181
|
if (k.length > 0) try {
|
|
182
182
|
j = JSON.parse(k);
|
|
183
183
|
} catch {
|
|
184
|
-
throw new
|
|
185
|
-
tag:
|
|
184
|
+
throw new i({
|
|
185
|
+
tag: t,
|
|
186
186
|
reason: "decode",
|
|
187
|
-
message: `the answer was not JSON (${
|
|
187
|
+
message: `the answer was not JSON (${s.status})`,
|
|
188
188
|
requestId: c
|
|
189
189
|
});
|
|
190
190
|
}
|
|
191
|
-
if (
|
|
192
|
-
let
|
|
193
|
-
if (
|
|
194
|
-
throw new
|
|
195
|
-
tag:
|
|
196
|
-
retryAfterMs:
|
|
191
|
+
if (s.status === 429) {
|
|
192
|
+
let e = u(s.headers, S()), n = Number(s.headers.get("ratelimit-limit") ?? NaN), i = Number(s.headers.get("ratelimit-remaining") ?? NaN), o = v.retry?.on429?.maxWaitMs;
|
|
193
|
+
if (o !== void 0 && a + e <= o) return await C(e), V(a + e);
|
|
194
|
+
throw new r({
|
|
195
|
+
tag: t,
|
|
196
|
+
retryAfterMs: e,
|
|
197
197
|
requestId: c,
|
|
198
|
-
...Number.isFinite(
|
|
199
|
-
...Number.isFinite(
|
|
200
|
-
resetAtMs: S() +
|
|
198
|
+
...Number.isFinite(n) ? { limit: n } : {},
|
|
199
|
+
...Number.isFinite(i) ? { remaining: i } : {},
|
|
200
|
+
resetAtMs: S() + e
|
|
201
201
|
});
|
|
202
202
|
}
|
|
203
|
-
if (
|
|
203
|
+
if (s.status >= 400) throw N(m, s.status, j, c);
|
|
204
204
|
let M, F = j;
|
|
205
|
-
if (y.pagination === "link-header" && (M = d(
|
|
205
|
+
if (y.pagination === "link-header" && (M = d(s.headers.get("link"), y.cursorParam)), y.envelope === "data" && typeof j == "object" && j && "data" in j) {
|
|
206
206
|
let e = j;
|
|
207
207
|
F = e.data, M === void 0 && typeof e.next == "string" && (M = e.next);
|
|
208
208
|
} else if (y.envelope === "jsonapi") {
|
|
@@ -213,15 +213,15 @@ var c = (e = Date.now()) => {
|
|
|
213
213
|
let e = F[y.cursorField];
|
|
214
214
|
typeof e == "string" && (M = e);
|
|
215
215
|
}
|
|
216
|
-
let L =
|
|
216
|
+
let L = s.status === 204 || F === void 0 ? F : o(e.wire.procedures[t]?.output, F, A);
|
|
217
217
|
if (M === void 0 && typeof L == "object" && L) {
|
|
218
218
|
let e = L[y.cursorField];
|
|
219
219
|
typeof e == "string" && (M = e);
|
|
220
220
|
}
|
|
221
|
-
let z =
|
|
221
|
+
let z = s.headers.get("etag") ?? void 0, H = {
|
|
222
222
|
value: L,
|
|
223
223
|
nextCursor: M,
|
|
224
|
-
status:
|
|
224
|
+
status: s.status,
|
|
225
225
|
requestId: c,
|
|
226
226
|
etag: z,
|
|
227
227
|
fromCache: !1
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltro/api-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.91.0",
|
|
4
4
|
"description": "The runtime of a generated TypeScript client for a Voltro public API (`voltro build api --target typescript`): the REST surface spoken profile-aware — typed errors as plain classes, dates, envelopes, pagination, a 429 as a wait, idempotency keys — with no dependencies, not on a schema library and not on Effect. Runs in Node, Bun, Deno and the browser. The Effect flavor is `@voltro/api-client-effect`.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"voltro",
|