@voltro/protocol 0.79.1 → 0.81.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 +169 -0
- package/dist/apikey.d.ts +8 -0
- package/dist/index.d.ts +394 -14
- package/dist/index.js +601 -556
- package/dist/jwt.d.ts +8 -0
- package/dist/rest.d.ts +84 -16
- package/dist/rest.js +228 -218
- package/dist/{restFormat-ChSVyufA.js → restFormat-CzdGVkuB.js} +72 -60
- package/dist/{scopes-BbIyym8y.js → scopes-CvU5QBQ4.js} +110 -79
- package/dist/session.d.ts +20 -0
- package/dist/session.js +6 -6
- package/package.json +3 -3
|
@@ -11,19 +11,24 @@ var r = (e, t, n) => `${e ?? "(global)"}|${t.toUpperCase()}|${n}`, i = (e, t, n,
|
|
|
11
11
|
get message() {
|
|
12
12
|
return "this mutation requires a live native WebSocket connection";
|
|
13
13
|
}
|
|
14
|
-
}, o = async (e, t, n, r, i) => {
|
|
15
|
-
let
|
|
16
|
-
return
|
|
14
|
+
}, o = async (e, t, n, r, i, a = s) => {
|
|
15
|
+
let o = await e.claim(t, n, i, r, a);
|
|
16
|
+
return o === "claimed" ? { kind: "fresh" } : o.status === "completed" && o.response ? {
|
|
17
17
|
kind: "replay",
|
|
18
|
-
response:
|
|
18
|
+
response: o.response
|
|
19
19
|
} : { kind: "conflict" };
|
|
20
|
-
}, s =
|
|
20
|
+
}, s = 3e4, c = (e, t, n, r = s, i = Date.now) => {
|
|
21
|
+
let a = setInterval(() => {
|
|
22
|
+
e.renew(t, n, i()).catch(() => {});
|
|
23
|
+
}, Math.max(1, Math.floor(r / 3)));
|
|
24
|
+
return a.unref?.(), () => clearInterval(a);
|
|
25
|
+
}, l = (e, t, n, r, i) => e.complete(t, n, r, i), u = (e, t, n) => e.release(t, n), d = () => {
|
|
21
26
|
let e = /* @__PURE__ */ new Map(), t = (e, t) => `${e}\u0000${t}`;
|
|
22
27
|
return {
|
|
23
28
|
get: async (n, r) => e.get(t(n, r)) ?? null,
|
|
24
|
-
claim: async (n, r, i, a) => {
|
|
25
|
-
let
|
|
26
|
-
return
|
|
29
|
+
claim: async (n, r, i, a, o) => {
|
|
30
|
+
let s = e.get(t(n, r));
|
|
31
|
+
return s && i - s.createdAt < f(s.status, a, o) ? s : (e.set(t(n, r), {
|
|
27
32
|
scope: n,
|
|
28
33
|
key: r,
|
|
29
34
|
status: "in_flight",
|
|
@@ -42,19 +47,26 @@ var r = (e, t, n) => `${e ?? "(global)"}|${t.toUpperCase()}|${n}`, i = (e, t, n,
|
|
|
42
47
|
},
|
|
43
48
|
release: async (n, r) => {
|
|
44
49
|
e.delete(t(n, r));
|
|
50
|
+
},
|
|
51
|
+
renew: async (n, r, i) => {
|
|
52
|
+
let a = e.get(t(n, r));
|
|
53
|
+
a?.status === "in_flight" && e.set(t(n, r), {
|
|
54
|
+
...a,
|
|
55
|
+
createdAt: i
|
|
56
|
+
});
|
|
45
57
|
}
|
|
46
58
|
};
|
|
47
|
-
},
|
|
59
|
+
}, f = (e, t, n) => e === "completed" ? t : Math.min(t, n), p = class extends e.TaggedError()("MutationInFlight", {
|
|
48
60
|
traceId: e.String,
|
|
49
61
|
retryAfterMs: e.Number
|
|
50
62
|
}) {
|
|
51
63
|
get message() {
|
|
52
64
|
return `a request with this idempotency key is still in flight — replay the same key after ${this.retryAfterMs}ms`;
|
|
53
65
|
}
|
|
54
|
-
},
|
|
55
|
-
if (!
|
|
56
|
-
if (t >=
|
|
57
|
-
let n = t + 1, r = (t) =>
|
|
66
|
+
}, m = 1e3, h = (e) => typeof e == "object" && !!e && typeof e._tag == "string", g = 64, _ = (e, t = 0) => {
|
|
67
|
+
if (!h(e)) return String(e);
|
|
68
|
+
if (t >= g) return "…";
|
|
69
|
+
let n = t + 1, r = (t) => _(e[t], n), i = (t) => Array.isArray(e[t]) ? e[t] : [];
|
|
58
70
|
switch (e._tag) {
|
|
59
71
|
case "Transformation": return `T(${r("from")}->${r("to")})`;
|
|
60
72
|
case "Refinement": return `R(${r("from")})`;
|
|
@@ -62,41 +74,41 @@ var r = (e, t, n) => `${e ?? "(global)"}|${t.toUpperCase()}|${n}`, i = (e, t, n,
|
|
|
62
74
|
case "TypeLiteral": {
|
|
63
75
|
let e = i("propertySignatures").map((e) => {
|
|
64
76
|
let t = e;
|
|
65
|
-
return `${String(t.name)}${t.isOptional === !0 ? "?" : ""}:${
|
|
77
|
+
return `${String(t.name)}${t.isOptional === !0 ? "?" : ""}:${_(t.type, n)}`;
|
|
66
78
|
}).join(","), t = i("indexSignatures").map((e) => {
|
|
67
79
|
let t = e;
|
|
68
|
-
return `[${
|
|
80
|
+
return `[${_(t.parameter, n)}]:${_(t.type, n)}`;
|
|
69
81
|
}).join(",");
|
|
70
82
|
return t === "" ? `{${e}}` : `{${e};${t}}`;
|
|
71
83
|
}
|
|
72
|
-
case "Union": return `U(${i("types").map((e) =>
|
|
84
|
+
case "Union": return `U(${i("types").map((e) => _(e, n)).join("|")})`;
|
|
73
85
|
case "TupleType": {
|
|
74
86
|
let e = i("elements").map((e) => {
|
|
75
87
|
let t = e;
|
|
76
|
-
return `${
|
|
77
|
-
}).join(","), t = i("rest").map((e) =>
|
|
88
|
+
return `${_(t.type, n)}${t.isOptional === !0 ? "?" : ""}`;
|
|
89
|
+
}).join(","), t = i("rest").map((e) => _(e.type, n)).join(",");
|
|
78
90
|
return `A(${e}${t === "" ? "" : `...${t}`})`;
|
|
79
91
|
}
|
|
80
|
-
case "Declaration": return `D(${i("typeParameters").map((e) =>
|
|
92
|
+
case "Declaration": return `D(${i("typeParameters").map((e) => _(e, n)).join(",")})`;
|
|
81
93
|
default: return String(e);
|
|
82
94
|
}
|
|
83
|
-
},
|
|
95
|
+
}, v = (e) => {
|
|
84
96
|
let t = 2166136261;
|
|
85
97
|
for (let n = 0; n < e.length; n++) t ^= e.charCodeAt(n), t = Math.imul(t, 16777619) >>> 0;
|
|
86
98
|
return t.toString(16).padStart(8, "0");
|
|
87
|
-
},
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
].join("\0")),
|
|
99
|
+
}, y = (e) => v([
|
|
100
|
+
_(e.payloadSchema?.ast),
|
|
101
|
+
_(e.successSchema?.ast),
|
|
102
|
+
_(e.errorSchema?.ast)
|
|
103
|
+
].join("\0")), b = (e) => {
|
|
92
104
|
let t = {}, n = e.requests, r = n instanceof Map ? n.entries() : Array.isArray(n) ? n.map((e, t) => [t, e]) : [];
|
|
93
105
|
for (let [, e] of r) {
|
|
94
106
|
if (typeof e != "object" && typeof e != "function" || e === null) continue;
|
|
95
107
|
let n = e;
|
|
96
|
-
typeof n._tag == "string" && (t[n._tag] =
|
|
108
|
+
typeof n._tag == "string" && (t[n._tag] = y(n));
|
|
97
109
|
}
|
|
98
110
|
return t;
|
|
99
|
-
},
|
|
111
|
+
}, x = (e, t) => {
|
|
100
112
|
let n = [], r = [];
|
|
101
113
|
for (let [i, a] of Object.entries(t)) {
|
|
102
114
|
let t = e[i];
|
|
@@ -106,13 +118,13 @@ var r = (e, t, n) => `${e ?? "(global)"}|${t.toUpperCase()}|${n}`, i = (e, t, n,
|
|
|
106
118
|
differing: n.sort(),
|
|
107
119
|
missingHere: r.sort()
|
|
108
120
|
};
|
|
109
|
-
},
|
|
110
|
-
for (let t of
|
|
121
|
+
}, S = /* @__PURE__ */ new Set(), C = (e) => {
|
|
122
|
+
for (let t of S) try {
|
|
111
123
|
t(e);
|
|
112
124
|
} catch {}
|
|
113
|
-
},
|
|
114
|
-
|
|
115
|
-
}),
|
|
125
|
+
}, w = (e) => (S.add(e), () => {
|
|
126
|
+
S.delete(e);
|
|
127
|
+
}), T = {
|
|
116
128
|
rpc: {
|
|
117
129
|
name: "rpc",
|
|
118
130
|
dates: "epoch-ms",
|
|
@@ -146,16 +158,16 @@ var r = (e, t, n) => `${e ?? "(global)"}|${t.toUpperCase()}|${n}`, i = (e, t, n,
|
|
|
146
158
|
naming: "camelCase",
|
|
147
159
|
etag: !0
|
|
148
160
|
}
|
|
149
|
-
},
|
|
161
|
+
}, E = [
|
|
150
162
|
"rpc",
|
|
151
163
|
"standard",
|
|
152
164
|
"jsonapi"
|
|
153
|
-
],
|
|
165
|
+
], D = (e, t = void 0) => {
|
|
154
166
|
let n = (e) => {
|
|
155
167
|
if (e?.profile !== void 0) {
|
|
156
168
|
if (typeof e.profile == "string") {
|
|
157
|
-
let t =
|
|
158
|
-
if (t === void 0) throw Error(`publicApi.profile: unknown profile '${String(e.profile)}' — one of ${
|
|
169
|
+
let t = T[e.profile];
|
|
170
|
+
if (t === void 0) throw Error(`publicApi.profile: unknown profile '${String(e.profile)}' — one of ${E.join(", ")}, or a RestFormat object`);
|
|
159
171
|
return t;
|
|
160
172
|
}
|
|
161
173
|
return e.profile;
|
|
@@ -170,14 +182,14 @@ var r = (e, t, n) => `${e ?? "(global)"}|${t.toUpperCase()}|${n}`, i = (e, t, n,
|
|
|
170
182
|
...t.cursorParam === void 0 ? {} : { cursorParam: t.cursorParam },
|
|
171
183
|
...t.naming === void 0 ? {} : { naming: t.naming },
|
|
172
184
|
...t.etag === void 0 ? {} : { etag: t.etag }
|
|
173
|
-
}, i = r(n(e) ??
|
|
185
|
+
}, i = r(n(e) ?? T.rpc, e);
|
|
174
186
|
return r(n(t) ?? i, t);
|
|
175
|
-
},
|
|
187
|
+
}, O = (e) => e.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z])([A-Z][a-z])/g, "$1_$2").toLowerCase(), k = (e, t) => {
|
|
176
188
|
if (typeof e != "object" || !e || Array.isArray(e)) return e;
|
|
177
189
|
let n = {};
|
|
178
190
|
for (let [r, i] of Object.entries(e)) n[t(r)] = i;
|
|
179
191
|
return n;
|
|
180
|
-
},
|
|
192
|
+
}, A = (e) => n.getOrUndefined(t.getIdentifierAnnotation(e)), j = (n, r) => {
|
|
181
193
|
if (r.dates === "epoch-ms" && r.naming === "camelCase") return n;
|
|
182
194
|
let i = /* @__PURE__ */ new Map(), a = (e) => {
|
|
183
195
|
let t = i.get(e);
|
|
@@ -187,7 +199,7 @@ var r = (e, t, n) => `${e ?? "(global)"}|${t.toUpperCase()}|${n}`, i = (e, t, n,
|
|
|
187
199
|
}, o = (n) => {
|
|
188
200
|
switch (n._tag) {
|
|
189
201
|
case "Transformation":
|
|
190
|
-
if (r.dates === "iso" &&
|
|
202
|
+
if (r.dates === "iso" && A(n) === "DateFromNumber") {
|
|
191
203
|
let r = e.DateFromString.ast;
|
|
192
204
|
return new t.Transformation(r.from, r.to, r.transformation, {
|
|
193
205
|
...r.annotations,
|
|
@@ -207,41 +219,41 @@ var r = (e, t, n) => `${e ?? "(global)"}|${t.toUpperCase()}|${n}`, i = (e, t, n,
|
|
|
207
219
|
case "TypeLiteral": {
|
|
208
220
|
let i = n.propertySignatures.map((e) => new t.PropertySignature(e.name, a(e.type), e.isOptional, e.isReadonly, e.annotations)), o = n.indexSignatures.map((e) => new t.IndexSignature(e.parameter, a(e.type), e.isReadonly)), s = new t.TypeLiteral(i, o, n.annotations);
|
|
209
221
|
if (r.naming !== "snake_case") return s;
|
|
210
|
-
let c = i.map((e) => typeof e.name == "string" ?
|
|
222
|
+
let c = i.map((e) => typeof e.name == "string" ? O(e.name) : e.name);
|
|
211
223
|
if (c.every((e, t) => e === i[t].name)) return s;
|
|
212
224
|
let l = new t.TypeLiteral(i.map((e, n) => new t.PropertySignature(c[n], t.encodedAST(e.type), e.isOptional, e.isReadonly, e.annotations)), o.map((e) => new t.IndexSignature(e.parameter, t.encodedAST(e.type), e.isReadonly)), n.annotations), u = new Map(i.map((e, t) => [String(c[t]), String(e.name)])), d = new Map(i.map((e, t) => [String(e.name), String(c[t])]));
|
|
213
225
|
return e.transform(e.make(l), e.make(s), {
|
|
214
226
|
strict: !1,
|
|
215
|
-
decode: (e) =>
|
|
216
|
-
encode: (e) =>
|
|
227
|
+
decode: (e) => k(e, (e) => u.get(e) ?? e),
|
|
228
|
+
encode: (e) => k(e, (e) => d.get(e) ?? e)
|
|
217
229
|
}).ast;
|
|
218
230
|
}
|
|
219
231
|
default: return n;
|
|
220
232
|
}
|
|
221
233
|
};
|
|
222
234
|
return e.make(a(n.ast));
|
|
223
|
-
},
|
|
224
|
-
type:
|
|
225
|
-
title:
|
|
235
|
+
}, M = (e) => `urn:voltro:error:${e}`, N = (e) => e.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z])([A-Z][a-z])/g, "$1 $2"), P = (e) => ({
|
|
236
|
+
type: M(e.tag),
|
|
237
|
+
title: N(e.tag),
|
|
226
238
|
status: e.status,
|
|
227
239
|
...e.message.length > 0 ? { detail: e.message } : {},
|
|
228
240
|
...e.fields
|
|
229
|
-
}),
|
|
241
|
+
}), F = "application/problem+json; charset=utf-8", I = "application/vnd.api+json; charset=utf-8", L = (e, t, n) => e.encodeError === void 0 ? e.errors === "problem-details" ? e.envelope === "jsonapi" ? {
|
|
230
242
|
body: { errors: [{
|
|
231
243
|
status: String(t.status),
|
|
232
244
|
code: t.tag,
|
|
233
|
-
title:
|
|
245
|
+
title: N(t.tag),
|
|
234
246
|
...t.message.length > 0 ? { detail: t.message } : {},
|
|
235
247
|
...Object.keys(t.fields).length > 0 ? { meta: t.fields } : {}
|
|
236
248
|
}] },
|
|
237
|
-
contentType:
|
|
249
|
+
contentType: I
|
|
238
250
|
} : {
|
|
239
|
-
body:
|
|
240
|
-
contentType:
|
|
251
|
+
body: P(t),
|
|
252
|
+
contentType: F
|
|
241
253
|
} : { body: {
|
|
242
254
|
error: t.tag === "InvalidRequest" || t.tag === "InternalServerError" || t.tag === "Unauthorized" || t.tag === "Forbidden" || t.tag === "Gone" || t.tag === "MethodNotAllowed" || t.tag === "Conflict" ? t.message : t.tag,
|
|
243
255
|
...t.fields
|
|
244
|
-
} } : e.encodeError(t, n),
|
|
256
|
+
} } : e.encodeError(t, n), R = (e, t) => {
|
|
245
257
|
if (typeof e != "object" || !e || Array.isArray(e)) return {
|
|
246
258
|
cursor: void 0,
|
|
247
259
|
rest: e
|
|
@@ -254,10 +266,10 @@ var r = (e, t, n) => `${e ?? "(global)"}|${t.toUpperCase()}|${n}`, i = (e, t, n,
|
|
|
254
266
|
cursor: String(n),
|
|
255
267
|
rest: e
|
|
256
268
|
};
|
|
257
|
-
},
|
|
269
|
+
}, z = (e, t, n) => {
|
|
258
270
|
let r = new URLSearchParams(e.query);
|
|
259
271
|
return r.set(n, t), `<${e.path}?${r.toString()}>; rel="next"`;
|
|
260
|
-
},
|
|
272
|
+
}, B = (e, t) => {
|
|
261
273
|
if (typeof e != "object" || !e || Array.isArray(e)) return e;
|
|
262
274
|
let { id: n, ...r } = e;
|
|
263
275
|
return {
|
|
@@ -265,9 +277,9 @@ var r = (e, t, n) => `${e ?? "(global)"}|${t.toUpperCase()}|${n}`, i = (e, t, n,
|
|
|
265
277
|
...n === void 0 ? {} : { id: String(n) },
|
|
266
278
|
attributes: r
|
|
267
279
|
};
|
|
268
|
-
},
|
|
280
|
+
}, V = (e, t, n) => {
|
|
269
281
|
if (e.encodeSuccess !== void 0) return e.encodeSuccess(t, n);
|
|
270
|
-
let { cursor: r } =
|
|
282
|
+
let { cursor: r } = R(t, e.cursorField), i = e.pagination === "link-header" && r !== void 0 ? { Link: z(n, r, e.cursorParam) } : void 0, a = (e, t) => ({
|
|
271
283
|
body: e,
|
|
272
284
|
...i ? { headers: i } : {},
|
|
273
285
|
...t ? { contentType: t } : {}
|
|
@@ -279,9 +291,9 @@ var r = (e, t, n) => `${e ?? "(global)"}|${t.toUpperCase()}|${n}`, i = (e, t, n,
|
|
|
279
291
|
});
|
|
280
292
|
let o = n.source ?? n.tag.split(".")[0] ?? "resource", s = Array.isArray(t) ? t : typeof t == "object" && t && Array.isArray(t.items) ? t.items : void 0;
|
|
281
293
|
return a({
|
|
282
|
-
data: s === void 0 ?
|
|
283
|
-
...r === void 0 ? {} : { links: { next:
|
|
284
|
-
},
|
|
294
|
+
data: s === void 0 ? B(t, o) : s.map((e) => B(e, o)),
|
|
295
|
+
...r === void 0 ? {} : { links: { next: z(n, r, e.cursorParam).replace(/^<|>; rel="next"$/g, "") } }
|
|
296
|
+
}, I);
|
|
285
297
|
};
|
|
286
298
|
//#endregion
|
|
287
|
-
export {
|
|
299
|
+
export { i as A, o as C, c as D, f as E, r as O, p as S, l as T, _, V as a, m as b, M as c, O as d, C as f, y as g, b as h, L as i, d as k, D as l, x as m, F as n, z as o, w as p, E as r, P as s, I as t, j as u, v, u as w, a as x, s as y };
|