@voltro/protocol 0.80.0 → 0.82.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.
@@ -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 a = await e.claim(t, n, i, r);
16
- return a === "claimed" ? { kind: "fresh" } : a.status === "completed" && a.response ? {
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: a.response
18
+ response: o.response
19
19
  } : { kind: "conflict" };
20
- }, s = (e, t, n, r, i) => e.complete(t, n, r, i), c = (e, t, n) => e.release(t, n), l = () => {
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 o = e.get(t(n, r));
26
- return o && i - o.createdAt < a ? o : (e.set(t(n, r), {
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
- }, u = class extends e.TaggedError()("MutationInFlight", {
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
- }, d = 1e3, f = (e) => typeof e == "object" && !!e && typeof e._tag == "string", p = 64, m = (e, t = 0) => {
55
- if (!f(e)) return String(e);
56
- if (t >= p) return "…";
57
- let n = t + 1, r = (t) => m(e[t], n), i = (t) => Array.isArray(e[t]) ? e[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 ? "?" : ""}:${m(t.type, n)}`;
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 `[${m(t.parameter, n)}]:${m(t.type, n)}`;
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) => m(e, n)).join("|")})`;
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 `${m(t.type, n)}${t.isOptional === !0 ? "?" : ""}`;
77
- }).join(","), t = i("rest").map((e) => m(e.type, n)).join(",");
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) => m(e, n)).join(",")})`;
92
+ case "Declaration": return `D(${i("typeParameters").map((e) => _(e, n)).join(",")})`;
81
93
  default: return String(e);
82
94
  }
83
- }, h = (e) => {
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
- }, g = (e) => h([
88
- m(e.payloadSchema?.ast),
89
- m(e.successSchema?.ast),
90
- m(e.errorSchema?.ast)
91
- ].join("\0")), _ = (e) => {
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] = g(n));
108
+ typeof n._tag == "string" && (t[n._tag] = y(n));
97
109
  }
98
110
  return t;
99
- }, v = (e, t) => {
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,18 @@ 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
- }, y = /* @__PURE__ */ new Set(), b = (e) => {
110
- for (let t of y) try {
121
+ }, S = (e) => {
122
+ let t = e.error, n = t instanceof Error ? t.name : typeof t?._tag == "string" ? String(t._tag) : "Error", r = [e.name === void 0 ? e.source : `${e.source} '${e.name}'`, ...typeof e.fields?.runId == "string" ? [`run ${e.fields.runId}`] : []].join(", "), i = /* @__PURE__ */ Error(`[message withheld: ${r} is declared encrypted — read it where the run is shown]`);
123
+ i.name = n;
124
+ let a = t instanceof Error && typeof t.stack == "string" ? t.stack : "", o = a.search(/^\s+at /m);
125
+ return i.stack = `${n}: ${i.message}${o === -1 ? "" : `\n${a.slice(o)}`}`, i;
126
+ }, C = /* @__PURE__ */ new Set(), w = (e) => {
127
+ for (let t of C) try {
111
128
  t(e);
112
129
  } catch {}
113
- }, x = (e) => (y.add(e), () => {
114
- y.delete(e);
115
- }), S = {
130
+ }, T = (e) => (C.add(e), () => {
131
+ C.delete(e);
132
+ }), E = {
116
133
  rpc: {
117
134
  name: "rpc",
118
135
  dates: "epoch-ms",
@@ -146,16 +163,16 @@ var r = (e, t, n) => `${e ?? "(global)"}|${t.toUpperCase()}|${n}`, i = (e, t, n,
146
163
  naming: "camelCase",
147
164
  etag: !0
148
165
  }
149
- }, C = [
166
+ }, D = [
150
167
  "rpc",
151
168
  "standard",
152
169
  "jsonapi"
153
- ], w = (e, t = void 0) => {
170
+ ], O = (e, t = void 0) => {
154
171
  let n = (e) => {
155
172
  if (e?.profile !== void 0) {
156
173
  if (typeof e.profile == "string") {
157
- let t = S[e.profile];
158
- if (t === void 0) throw Error(`publicApi.profile: unknown profile '${String(e.profile)}' — one of ${C.join(", ")}, or a RestFormat object`);
174
+ let t = E[e.profile];
175
+ if (t === void 0) throw Error(`publicApi.profile: unknown profile '${String(e.profile)}' — one of ${D.join(", ")}, or a RestFormat object`);
159
176
  return t;
160
177
  }
161
178
  return e.profile;
@@ -170,14 +187,14 @@ var r = (e, t, n) => `${e ?? "(global)"}|${t.toUpperCase()}|${n}`, i = (e, t, n,
170
187
  ...t.cursorParam === void 0 ? {} : { cursorParam: t.cursorParam },
171
188
  ...t.naming === void 0 ? {} : { naming: t.naming },
172
189
  ...t.etag === void 0 ? {} : { etag: t.etag }
173
- }, i = r(n(e) ?? S.rpc, e);
190
+ }, i = r(n(e) ?? E.rpc, e);
174
191
  return r(n(t) ?? i, t);
175
- }, T = (e) => e.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z])([A-Z][a-z])/g, "$1_$2").toLowerCase(), E = (e, t) => {
192
+ }, k = (e) => e.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/([A-Z])([A-Z][a-z])/g, "$1_$2").toLowerCase(), A = (e, t) => {
176
193
  if (typeof e != "object" || !e || Array.isArray(e)) return e;
177
194
  let n = {};
178
195
  for (let [r, i] of Object.entries(e)) n[t(r)] = i;
179
196
  return n;
180
- }, D = (e) => n.getOrUndefined(t.getIdentifierAnnotation(e)), O = (n, r) => {
197
+ }, j = (e) => n.getOrUndefined(t.getIdentifierAnnotation(e)), M = (n, r) => {
181
198
  if (r.dates === "epoch-ms" && r.naming === "camelCase") return n;
182
199
  let i = /* @__PURE__ */ new Map(), a = (e) => {
183
200
  let t = i.get(e);
@@ -187,7 +204,7 @@ var r = (e, t, n) => `${e ?? "(global)"}|${t.toUpperCase()}|${n}`, i = (e, t, n,
187
204
  }, o = (n) => {
188
205
  switch (n._tag) {
189
206
  case "Transformation":
190
- if (r.dates === "iso" && D(n) === "DateFromNumber") {
207
+ if (r.dates === "iso" && j(n) === "DateFromNumber") {
191
208
  let r = e.DateFromString.ast;
192
209
  return new t.Transformation(r.from, r.to, r.transformation, {
193
210
  ...r.annotations,
@@ -207,41 +224,41 @@ var r = (e, t, n) => `${e ?? "(global)"}|${t.toUpperCase()}|${n}`, i = (e, t, n,
207
224
  case "TypeLiteral": {
208
225
  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
226
  if (r.naming !== "snake_case") return s;
210
- let c = i.map((e) => typeof e.name == "string" ? T(e.name) : e.name);
227
+ let c = i.map((e) => typeof e.name == "string" ? k(e.name) : e.name);
211
228
  if (c.every((e, t) => e === i[t].name)) return s;
212
229
  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
230
  return e.transform(e.make(l), e.make(s), {
214
231
  strict: !1,
215
- decode: (e) => E(e, (e) => u.get(e) ?? e),
216
- encode: (e) => E(e, (e) => d.get(e) ?? e)
232
+ decode: (e) => A(e, (e) => u.get(e) ?? e),
233
+ encode: (e) => A(e, (e) => d.get(e) ?? e)
217
234
  }).ast;
218
235
  }
219
236
  default: return n;
220
237
  }
221
238
  };
222
239
  return e.make(a(n.ast));
223
- }, k = (e) => `urn:voltro:error:${e}`, A = (e) => e.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z])([A-Z][a-z])/g, "$1 $2"), j = (e) => ({
224
- type: k(e.tag),
225
- title: A(e.tag),
240
+ }, N = (e) => `urn:voltro:error:${e}`, P = (e) => e.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Z])([A-Z][a-z])/g, "$1 $2"), F = (e) => ({
241
+ type: N(e.tag),
242
+ title: P(e.tag),
226
243
  status: e.status,
227
244
  ...e.message.length > 0 ? { detail: e.message } : {},
228
245
  ...e.fields
229
- }), M = "application/problem+json; charset=utf-8", N = "application/vnd.api+json; charset=utf-8", P = (e, t, n) => e.encodeError === void 0 ? e.errors === "problem-details" ? e.envelope === "jsonapi" ? {
246
+ }), I = "application/problem+json; charset=utf-8", L = "application/vnd.api+json; charset=utf-8", R = (e, t, n) => e.encodeError === void 0 ? e.errors === "problem-details" ? e.envelope === "jsonapi" ? {
230
247
  body: { errors: [{
231
248
  status: String(t.status),
232
249
  code: t.tag,
233
- title: A(t.tag),
250
+ title: P(t.tag),
234
251
  ...t.message.length > 0 ? { detail: t.message } : {},
235
252
  ...Object.keys(t.fields).length > 0 ? { meta: t.fields } : {}
236
253
  }] },
237
- contentType: N
254
+ contentType: L
238
255
  } : {
239
- body: j(t),
240
- contentType: M
256
+ body: F(t),
257
+ contentType: I
241
258
  } : { body: {
242
259
  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
260
  ...t.fields
244
- } } : e.encodeError(t, n), F = (e, t) => {
261
+ } } : e.encodeError(t, n), z = (e, t) => {
245
262
  if (typeof e != "object" || !e || Array.isArray(e)) return {
246
263
  cursor: void 0,
247
264
  rest: e
@@ -254,10 +271,10 @@ var r = (e, t, n) => `${e ?? "(global)"}|${t.toUpperCase()}|${n}`, i = (e, t, n,
254
271
  cursor: String(n),
255
272
  rest: e
256
273
  };
257
- }, I = (e, t, n) => {
274
+ }, B = (e, t, n) => {
258
275
  let r = new URLSearchParams(e.query);
259
276
  return r.set(n, t), `<${e.path}?${r.toString()}>; rel="next"`;
260
- }, L = (e, t) => {
277
+ }, V = (e, t) => {
261
278
  if (typeof e != "object" || !e || Array.isArray(e)) return e;
262
279
  let { id: n, ...r } = e;
263
280
  return {
@@ -265,9 +282,9 @@ var r = (e, t, n) => `${e ?? "(global)"}|${t.toUpperCase()}|${n}`, i = (e, t, n,
265
282
  ...n === void 0 ? {} : { id: String(n) },
266
283
  attributes: r
267
284
  };
268
- }, R = (e, t, n) => {
285
+ }, H = (e, t, n) => {
269
286
  if (e.encodeSuccess !== void 0) return e.encodeSuccess(t, n);
270
- let { cursor: r } = F(t, e.cursorField), i = e.pagination === "link-header" && r !== void 0 ? { Link: I(n, r, e.cursorParam) } : void 0, a = (e, t) => ({
287
+ let { cursor: r } = z(t, e.cursorField), i = e.pagination === "link-header" && r !== void 0 ? { Link: B(n, r, e.cursorParam) } : void 0, a = (e, t) => ({
271
288
  body: e,
272
289
  ...i ? { headers: i } : {},
273
290
  ...t ? { contentType: t } : {}
@@ -279,9 +296,9 @@ var r = (e, t, n) => `${e ?? "(global)"}|${t.toUpperCase()}|${n}`, i = (e, t, n,
279
296
  });
280
297
  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
298
  return a({
282
- data: s === void 0 ? L(t, o) : s.map((e) => L(e, o)),
283
- ...r === void 0 ? {} : { links: { next: I(n, r, e.cursorParam).replace(/^<|>; rel="next"$/g, "") } }
284
- }, N);
299
+ data: s === void 0 ? V(t, o) : s.map((e) => V(e, o)),
300
+ ...r === void 0 ? {} : { links: { next: B(n, r, e.cursorParam).replace(/^<|>; rel="next"$/g, "") } }
301
+ }, L);
285
302
  };
286
303
  //#endregion
287
- export { c as C, i as D, l as E, o as S, r as T, m as _, R as a, a as b, k as c, T as d, b as f, g, _ as h, P as i, w as l, v as m, M as n, I as o, x as p, C as r, j as s, N as t, O as u, h as v, s as w, u as x, d as y };
304
+ export { d as A, p as C, f as D, l as E, c as O, a as S, u as T, y as _, H as a, s as b, N as c, k as d, w as f, b as g, x as h, R as i, i as j, r as k, O as l, S as m, I as n, B as o, T as p, D as r, F as s, L as t, M as u, _ as v, o as w, m as x, v as y };