@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.
- package/CHANGELOG.md +1610 -6
- package/dist/apikey.d.ts +10 -2
- package/dist/index.d.ts +949 -76
- package/dist/index.js +904 -634
- package/dist/inspect.d.ts +67 -1
- package/dist/inspect.js +95 -61
- package/dist/jwt.d.ts +9 -1
- package/dist/rest.d.ts +121 -19
- package/dist/rest.js +255 -214
- package/dist/{restFormat-ChSVyufA.js → restFormat-EZ8k9ZcQ.js} +77 -60
- package/dist/{scopes-BbIyym8y.js → scopes-Di756ENh.js} +153 -102
- package/dist/session.d.ts +31 -0
- package/dist/session.js +49 -48
- package/dist/sessionHeader-DriTZhmv.js +7 -0
- package/package.json +3 -3
package/dist/rest.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Effect as
|
|
4
|
-
import * as
|
|
1
|
+
import { H as e, V as t } from "./scopes-Di756ENh.js";
|
|
2
|
+
import { E as n, O as r, T as i, a, c as o, d as s, f as c, i as l, k as u, l as d, n as f, o as p, r as m, s as h, t as g, u as _, v, w as y, y as b } from "./restFormat-EZ8k9ZcQ.js";
|
|
3
|
+
import { Effect as x, ParseResult as S, Schema as C } from "effect";
|
|
4
|
+
import * as w from "effect/SchemaAST";
|
|
5
5
|
//#region src/publicApi.ts
|
|
6
|
-
var
|
|
6
|
+
var T = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? k("", t, n).method : void 0) ?? (e === "query" ? "GET" : "POST"), E = (e, t, n) => A(t.path ?? (t.resource !== void 0 && n !== void 0 ? k(e, t, n).path : `/${t.version ?? "v1"}/${e.replace(/\./g, "/")}`)), D = (e) => {
|
|
7
7
|
let t = e.split("/").pop() ?? e;
|
|
8
8
|
return t.endsWith("ies") ? `${t.slice(0, -3)}y` : t.endsWith("ses") || t.endsWith("xes") ? t.slice(0, -2) : t.endsWith("s") ? t.slice(0, -1) : t;
|
|
9
|
-
},
|
|
10
|
-
let n = t != null && (typeof t == "object" || typeof t == "function") && "ast" in t ?
|
|
9
|
+
}, O = (e, t) => {
|
|
10
|
+
let n = t != null && (typeof t == "object" || typeof t == "function") && "ast" in t ? B(t) : void 0;
|
|
11
11
|
if (n === void 0) return;
|
|
12
|
-
let r = `${
|
|
12
|
+
let r = `${D(e)}Id`;
|
|
13
13
|
return n.has(r) ? r : n.has("id") ? "id" : void 0;
|
|
14
|
-
},
|
|
15
|
-
let r = (t.resource ?? "").replace(/^\/+|\/+$/g, ""), i = `/${t.version ?? "v1"}/${r}`, a =
|
|
14
|
+
}, k = (e, t, n) => {
|
|
15
|
+
let r = (t.resource ?? "").replace(/^\/+|\/+$/g, ""), i = `/${t.version ?? "v1"}/${r}`, a = O(r, n.input), o = a === void 0 ? i : `${i}/:${a}`, s = e.split(".").pop() ?? e, c = n.target?.op;
|
|
16
16
|
return n.kind === "query" || n.kind === "stream" ? {
|
|
17
17
|
method: "GET",
|
|
18
18
|
path: o
|
|
@@ -29,72 +29,72 @@ var w = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? D("",
|
|
|
29
29
|
method: "POST",
|
|
30
30
|
path: `${o}/${s}`
|
|
31
31
|
};
|
|
32
|
-
},
|
|
33
|
-
if (
|
|
34
|
-
let t = e.types.filter((e) => !
|
|
32
|
+
}, A = (e) => e.replace(/\{([A-Za-z0-9_]+)\}/g, ":$1"), j = (e) => [...e.matchAll(/:([A-Za-z0-9_]+)/g)].map((e) => e[1]), M = (e) => {
|
|
33
|
+
if (w.isUnion(e)) {
|
|
34
|
+
let t = e.types.filter((e) => !w.isUndefinedKeyword(e));
|
|
35
35
|
if (t.length === 1) return t[0];
|
|
36
|
-
if (t.length !== e.types.length) return
|
|
36
|
+
if (t.length !== e.types.length) return w.Union.make(t);
|
|
37
37
|
}
|
|
38
38
|
return e;
|
|
39
|
-
},
|
|
40
|
-
let n =
|
|
41
|
-
if (
|
|
42
|
-
if (
|
|
39
|
+
}, N = /^-?(\d+\.?\d*|\.\d+)(e[+-]?\d+)?$/i, P = (e, t) => {
|
|
40
|
+
let n = M(t);
|
|
41
|
+
if (w.isRefinement(n) || w.isTransformation(n)) return P(e, n.from);
|
|
42
|
+
if (w.isUnion(n)) {
|
|
43
43
|
for (let t of n.types) {
|
|
44
|
-
let n =
|
|
44
|
+
let n = P(e, t);
|
|
45
45
|
if (n !== e) return n;
|
|
46
46
|
}
|
|
47
47
|
return e;
|
|
48
48
|
}
|
|
49
|
-
if (
|
|
49
|
+
if (w.isTupleType(n)) {
|
|
50
50
|
let t = Array.isArray(e) ? e : e === void 0 ? void 0 : [e];
|
|
51
51
|
if (t === void 0) return e;
|
|
52
52
|
let r = n.rest[0]?.type ?? n.elements[0]?.type;
|
|
53
|
-
return r === void 0 ? t : t.map((e) =>
|
|
53
|
+
return r === void 0 ? t : t.map((e) => P(e, r));
|
|
54
54
|
}
|
|
55
55
|
if (typeof e != "string") return e;
|
|
56
|
-
if (
|
|
57
|
-
if (
|
|
58
|
-
if (
|
|
56
|
+
if (w.isNumberKeyword(n)) return N.test(e.trim()) ? Number(e) : e;
|
|
57
|
+
if (w.isBooleanKeyword(n)) return e === "true" || e !== "false" && e;
|
|
58
|
+
if (w.isLiteral(n)) {
|
|
59
59
|
let t = n.literal;
|
|
60
|
-
return typeof t == "number" &&
|
|
60
|
+
return typeof t == "number" && N.test(e.trim()) && Number(e) === t || typeof t == "boolean" && String(t) === e ? t : e;
|
|
61
61
|
}
|
|
62
62
|
return e;
|
|
63
|
-
},
|
|
63
|
+
}, F = (e, t) => {
|
|
64
64
|
if (typeof e != "object" || !e || Array.isArray(e)) return e;
|
|
65
|
-
let n =
|
|
66
|
-
if (!
|
|
65
|
+
let n = M(w.encodedAST(t.ast));
|
|
66
|
+
if (!w.isTypeLiteral(n)) return e;
|
|
67
67
|
let r = { ...e };
|
|
68
68
|
for (let e of n.propertySignatures) {
|
|
69
69
|
let t = String(e.name);
|
|
70
|
-
t in r && (r[t] =
|
|
70
|
+
t in r && (r[t] = P(r[t], e.type));
|
|
71
71
|
}
|
|
72
72
|
return r;
|
|
73
|
-
},
|
|
73
|
+
}, I = (e) => {
|
|
74
74
|
let t = /* @__PURE__ */ new Set();
|
|
75
75
|
if (e === void 0) return t;
|
|
76
76
|
let n = (e) => {
|
|
77
|
-
if (
|
|
77
|
+
if (w.isUnion(e)) {
|
|
78
78
|
for (let t of e.types) n(t);
|
|
79
79
|
return;
|
|
80
80
|
}
|
|
81
|
-
if (
|
|
81
|
+
if (w.isTransformation(e)) {
|
|
82
82
|
n(e.from), n(e.to);
|
|
83
83
|
return;
|
|
84
84
|
}
|
|
85
|
-
if (
|
|
85
|
+
if (w.isRefinement(e)) {
|
|
86
86
|
n(e.from);
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
89
|
-
if (
|
|
89
|
+
if (w.isTypeLiteral(e)) {
|
|
90
90
|
let n = e.propertySignatures.find((e) => e.name === "_tag");
|
|
91
|
-
n !== void 0 &&
|
|
91
|
+
n !== void 0 && w.isLiteral(n.type) && typeof n.type.literal == "string" && t.add(n.type.literal);
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
return n(e.ast), t;
|
|
95
|
-
},
|
|
95
|
+
}, L = (e, t, n) => {
|
|
96
96
|
if (n !== void 0) try {
|
|
97
|
-
let r =
|
|
97
|
+
let r = C.encodeUnknownSync(n)(e);
|
|
98
98
|
if (typeof r == "object" && r) return {
|
|
99
99
|
error: t,
|
|
100
100
|
...r
|
|
@@ -103,23 +103,23 @@ var w = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? D("",
|
|
|
103
103
|
let r = { error: t };
|
|
104
104
|
for (let [t, n] of Object.entries(e)) t !== "stack" && t !== "_tag" && (r[t] = n);
|
|
105
105
|
return r;
|
|
106
|
-
},
|
|
106
|
+
}, R = (e, t, n, r = []) => {
|
|
107
107
|
if (typeof e != "object" || !e) return e;
|
|
108
108
|
let i = e._tag;
|
|
109
|
-
if (typeof i != "string" || i === "ScopeError") return e;
|
|
110
|
-
if (
|
|
111
|
-
let a = r.find((e) =>
|
|
109
|
+
if (typeof i != "string" || i === "ScopeError" || i === "NoSuchResource") return e;
|
|
110
|
+
if (I(t.error).has(i)) return new Y(n.errorStatus?.[i] ?? 422, L(e, i, t.error));
|
|
111
|
+
let a = r.find((e) => I(e.schema).has(i));
|
|
112
112
|
if (a === void 0) return e;
|
|
113
113
|
let o = n.errorStatus?.[i] ?? a.rest?.status ?? 422, s = a.rest?.headers?.(e);
|
|
114
|
-
return new Y(o,
|
|
115
|
-
},
|
|
116
|
-
let o =
|
|
114
|
+
return new Y(o, L(e, i, a.schema), s);
|
|
115
|
+
}, ee = (e, t, n, r, i, a) => {
|
|
116
|
+
let o = R(e, t, n, r);
|
|
117
117
|
if (!(o instanceof Y) || i.errors === "tagged" && i.encodeError === void 0) return o;
|
|
118
|
-
let { error: s, _tag: c, ...
|
|
118
|
+
let { error: s, _tag: c, ...u } = o.body, d = typeof u.message == "string" ? u.message : typeof u.reason == "string" ? u.reason : "", f = l(i, {
|
|
119
119
|
status: o.status,
|
|
120
120
|
tag: s,
|
|
121
121
|
message: d,
|
|
122
|
-
fields:
|
|
122
|
+
fields: u
|
|
123
123
|
}, {
|
|
124
124
|
...a,
|
|
125
125
|
status: o.status
|
|
@@ -128,157 +128,158 @@ var w = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? D("",
|
|
|
128
128
|
...o.headers ?? {},
|
|
129
129
|
...f.headers ?? {}
|
|
130
130
|
}, f.contentType);
|
|
131
|
-
},
|
|
131
|
+
}, z = (e, t) => {
|
|
132
132
|
if (e === void 0) return;
|
|
133
|
-
let n =
|
|
133
|
+
let n = w.isUnion(e.ast) ? e.ast.types : [e.ast];
|
|
134
134
|
for (let e of n) {
|
|
135
|
-
let n =
|
|
136
|
-
if (
|
|
135
|
+
let n = C.make(e);
|
|
136
|
+
if (I(n).has(t)) return n;
|
|
137
137
|
}
|
|
138
|
-
},
|
|
139
|
-
let t =
|
|
140
|
-
return
|
|
138
|
+
}, te = (e) => e.split(".").map((e, t) => t === 0 ? e : e.charAt(0).toUpperCase() + e.slice(1)).join("").replace(/[^A-Za-z0-9_]/g, "_"), B = (e) => {
|
|
139
|
+
let t = M(w.encodedAST(e.ast));
|
|
140
|
+
return w.isTypeLiteral(t) && t.indexSignatures.length === 0 ? new Set(t.propertySignatures.map((e) => String(e.name))) : void 0;
|
|
141
141
|
}, ne = (e, t) => e === t || JSON.stringify(e) === JSON.stringify(t), re = (e, t) => {
|
|
142
|
-
let n =
|
|
142
|
+
let n = M(w.encodedAST(t.ast)), r = {}, i = w.isTypeLiteral(n) ? new Map(n.propertySignatures.map((e) => [String(e.name), e.type])) : /* @__PURE__ */ new Map();
|
|
143
143
|
for (let [t, n] of Object.entries(e)) {
|
|
144
144
|
let e = i.get(t);
|
|
145
|
-
r[t] = e === void 0 ? n :
|
|
145
|
+
r[t] = e === void 0 ? n : P(n, e);
|
|
146
146
|
}
|
|
147
147
|
return r;
|
|
148
|
-
},
|
|
148
|
+
}, V = (e, t) => {
|
|
149
149
|
if (e !== void 0) {
|
|
150
150
|
try {
|
|
151
|
-
return
|
|
151
|
+
return C.encodeUnknownSync(t)(e);
|
|
152
152
|
} catch {}
|
|
153
153
|
try {
|
|
154
|
-
return
|
|
154
|
+
return C.decodeUnknownSync(t)(e), e;
|
|
155
155
|
} catch {}
|
|
156
156
|
return e;
|
|
157
157
|
}
|
|
158
|
-
},
|
|
159
|
-
...e.request === void 0 ? {} : { request:
|
|
160
|
-
...e.response === void 0 ? {} : { response:
|
|
161
|
-
}),
|
|
158
|
+
}, H = (e, t, n) => ({
|
|
159
|
+
...e.request === void 0 ? {} : { request: V(e.request, t) },
|
|
160
|
+
...e.response === void 0 ? {} : { response: V(e.response, n) }
|
|
161
|
+
}), ie = () => (e) => {
|
|
162
162
|
if (e.subject.type !== "anonymous") return;
|
|
163
163
|
let t = e.subject.credentialRejected;
|
|
164
164
|
return t === void 0 ? void 0 : {
|
|
165
165
|
status: 401,
|
|
166
166
|
message: t
|
|
167
167
|
};
|
|
168
|
-
},
|
|
168
|
+
}, U = (e, t, n, r = {}) => {
|
|
169
169
|
let i = e.publicApi;
|
|
170
170
|
if (i === void 0) throw Error(`publicApiRoute: descriptor '${e.name}' has no publicApi annotation`);
|
|
171
|
-
let
|
|
171
|
+
let o = d(r.profile, i.format), c = r.pluginErrors ?? [], l = {
|
|
172
172
|
kind: e.kind,
|
|
173
173
|
input: e.input,
|
|
174
174
|
target: e.target
|
|
175
|
-
}, u =
|
|
175
|
+
}, u = T(e.kind, i, l), f = (e) => o.naming === "snake_case" ? s(e) : e, p = E(e.name, i, l), m = p.replace(/:([A-Za-z0-9_]+)/g, (e, t) => `:${f(t)}`), h = j(m), g = _(e.input, o), v = B(g);
|
|
176
176
|
if (v !== void 0) {
|
|
177
177
|
for (let t of h) if (!v.has(t)) throw Error(`publicApi: descriptor '${e.name}' — path '${p}' binds ':${t}', and the input declares no field of that name` + (v.size > 0 ? ` (fields: ${[...v].join(", ")})` : " (the input declares no fields)"));
|
|
178
178
|
}
|
|
179
|
-
let y = _(e.output,
|
|
180
|
-
query:
|
|
181
|
-
params:
|
|
182
|
-
form:
|
|
183
|
-
},
|
|
184
|
-
...
|
|
185
|
-
body:
|
|
186
|
-
}) :
|
|
179
|
+
let y = _(e.output, o), b = C.Struct({ value: g }), w = u !== "GET" && (v === void 0 || [...v].some((e) => !h.includes(e))), D = {
|
|
180
|
+
query: C.Unknown,
|
|
181
|
+
params: C.Unknown,
|
|
182
|
+
form: C.Boolean
|
|
183
|
+
}, O = w ? C.Struct({
|
|
184
|
+
...D,
|
|
185
|
+
body: C.Unknown
|
|
186
|
+
}) : C.Struct(D), k = C.transformOrFail(O, b, {
|
|
187
187
|
strict: !1,
|
|
188
188
|
decode: (e, t, n) => {
|
|
189
|
-
let r = "body" in e ? e.body : void 0, i = u === "GET" ?
|
|
190
|
-
if (typeof i != "object" || !i || Array.isArray(i)) return
|
|
189
|
+
let r = "body" in e ? e.body : void 0, i = u === "GET" ? F(e.query, g) : e.form ? F(r ?? {}, g) : r ?? {}, a = typeof e.params == "object" && e.params !== null ? re(e.params, g) : {};
|
|
190
|
+
if (typeof i != "object" || !i || Array.isArray(i)) return S.succeed({ value: i });
|
|
191
191
|
let o = i, s = Object.keys(a).filter((e) => e in o && !ne(o[e], a[e]));
|
|
192
192
|
if (s.length > 0) {
|
|
193
193
|
let t = u === "GET" ? "query string" : "body";
|
|
194
|
-
return
|
|
194
|
+
return S.fail(new S.Type(n, e, `${s.map((e) => `'${e}'`).join(", ")} ${s.length === 1 ? "is" : "are"} bound by the path and sent with another value in the ${t}`));
|
|
195
195
|
}
|
|
196
|
-
return
|
|
196
|
+
return S.succeed({ value: {
|
|
197
197
|
...o,
|
|
198
198
|
...a
|
|
199
199
|
} });
|
|
200
200
|
},
|
|
201
|
-
encode: (e) =>
|
|
201
|
+
encode: (e) => S.succeed(e)
|
|
202
202
|
}), A = [
|
|
203
|
-
|
|
204
|
-
...e.openAccess === void 0 ? [
|
|
205
|
-
...(i.scopes ?? []).map((e) =>
|
|
206
|
-
],
|
|
203
|
+
ie(),
|
|
204
|
+
...e.openAccess === void 0 ? [K()] : [],
|
|
205
|
+
...(i.scopes ?? []).map((e) => q(e))
|
|
206
|
+
], M = (() => {
|
|
207
207
|
let t = e.source;
|
|
208
208
|
return typeof t == "string" ? t : Array.isArray(t) ? t[0] : void 0;
|
|
209
|
-
})(),
|
|
209
|
+
})(), N = (t, n = 200) => ({
|
|
210
210
|
tag: e.name,
|
|
211
211
|
method: t.method,
|
|
212
212
|
path: t.path,
|
|
213
213
|
query: t.query,
|
|
214
|
-
source:
|
|
214
|
+
source: M,
|
|
215
215
|
status: n
|
|
216
|
-
}),
|
|
217
|
-
r(
|
|
216
|
+
}), P = i.stream === "sse" && e.kind === "query" && n !== void 0, L = C.encodeUnknown(y), R = P ? (e, t) => ue((r) => n(e.value, t, (e) => {
|
|
217
|
+
r(de(String(e._tag ?? "message"), e));
|
|
218
218
|
})) : async (n, r) => {
|
|
219
|
-
let
|
|
219
|
+
let s;
|
|
220
220
|
try {
|
|
221
|
-
|
|
221
|
+
s = await t(n.value, r);
|
|
222
222
|
} catch (t) {
|
|
223
|
-
throw
|
|
223
|
+
throw ee(t, e, i, c, o, N(r));
|
|
224
224
|
}
|
|
225
|
-
let l = await
|
|
226
|
-
return
|
|
225
|
+
let l = await x.runPromise(L(s)), u = a(o, l, N(r));
|
|
226
|
+
return J(u.body, {
|
|
227
227
|
...u.headers === void 0 ? {} : { headers: u.headers },
|
|
228
228
|
...u.contentType === void 0 ? {} : { contentType: u.contentType }
|
|
229
229
|
});
|
|
230
|
-
}, V = e.error,
|
|
231
|
-
for (let e of
|
|
232
|
-
let t =
|
|
233
|
-
t !== void 0 &&
|
|
230
|
+
}, V = e.error, U = [...I(V)], W = [];
|
|
231
|
+
for (let e of U) {
|
|
232
|
+
let t = z(V, e);
|
|
233
|
+
t !== void 0 && W.push({
|
|
234
234
|
status: i.errorStatus?.[e] ?? 422,
|
|
235
235
|
tag: e,
|
|
236
236
|
schema: t
|
|
237
237
|
});
|
|
238
238
|
}
|
|
239
|
-
for (let e of
|
|
240
|
-
if (
|
|
239
|
+
for (let e of c) for (let t of I(e.schema)) {
|
|
240
|
+
if (U.includes(t)) continue;
|
|
241
241
|
let n = i.errorStatus?.[t] ?? e.rest?.status;
|
|
242
242
|
if (n === void 0) continue;
|
|
243
|
-
let r =
|
|
244
|
-
|
|
243
|
+
let r = z(e.schema, t) ?? e.schema;
|
|
244
|
+
W.push({
|
|
245
245
|
status: n,
|
|
246
246
|
tag: t,
|
|
247
247
|
schema: r
|
|
248
248
|
});
|
|
249
249
|
}
|
|
250
|
-
let
|
|
250
|
+
let G = i.security === !1 ? "none" : i.security ?? (e.openAccess === void 0 ? "required" : "optional"), ae = {
|
|
251
251
|
tag: e.name,
|
|
252
252
|
kind: e.kind,
|
|
253
253
|
version: i.version ?? "v1",
|
|
254
|
-
security:
|
|
254
|
+
security: G,
|
|
255
255
|
idempotent: i.idempotent === !0,
|
|
256
256
|
input: g,
|
|
257
257
|
pathParams: h,
|
|
258
258
|
output: y,
|
|
259
|
-
source:
|
|
260
|
-
errorResponses:
|
|
261
|
-
format:
|
|
259
|
+
source: M,
|
|
260
|
+
errorResponses: W,
|
|
261
|
+
format: o
|
|
262
262
|
};
|
|
263
|
-
return
|
|
263
|
+
return le({
|
|
264
264
|
method: u,
|
|
265
265
|
path: m,
|
|
266
|
-
input:
|
|
267
|
-
output:
|
|
268
|
-
handler:
|
|
269
|
-
...
|
|
266
|
+
input: k,
|
|
267
|
+
output: C.Unknown,
|
|
268
|
+
handler: R,
|
|
269
|
+
...P ? { streaming: !0 } : {},
|
|
270
270
|
guards: A,
|
|
271
|
-
operationId: i.operationId ??
|
|
271
|
+
operationId: i.operationId ?? te(e.name),
|
|
272
272
|
tags: i.tags ?? [e.name.split(".")[0] ?? e.name],
|
|
273
|
-
projection:
|
|
274
|
-
...
|
|
275
|
-
...i.
|
|
273
|
+
projection: ae,
|
|
274
|
+
...o.etag && u === "GET" && !P ? { etag: !0 } : {},
|
|
275
|
+
...i.cache !== void 0 && u === "GET" && !P ? { cache: i.cache } : {},
|
|
276
|
+
...i.example === void 0 ? {} : { example: H(i.example, g, y) },
|
|
276
277
|
...i.summary === void 0 ? {} : { summary: i.summary },
|
|
277
278
|
...i.description === void 0 ? {} : { description: i.description },
|
|
278
279
|
...i.deprecated === void 0 ? {} : { deprecated: i.deprecated },
|
|
279
280
|
...i.sunset === void 0 ? {} : { sunset: i.sunset }
|
|
280
281
|
});
|
|
281
|
-
},
|
|
282
|
+
}, W = (e, t = {}) => e.filter((e) => e.descriptor.publicApi !== void 0).map((e) => U(e.descriptor, e.invoke, e.subscribe, t)).sort((e, t) => e.path.localeCompare(t.path)), G = (e) => b(e.filter((e) => e.projection !== void 0).map((e) => {
|
|
282
283
|
let t = e.projection, n = {
|
|
283
284
|
tag: t.tag,
|
|
284
285
|
method: e.method,
|
|
@@ -288,31 +289,53 @@ var w = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? D("",
|
|
|
288
289
|
security: t.security,
|
|
289
290
|
errors: [...t.errorResponses].map((e) => `${e.status}:${e.tag}`).sort()
|
|
290
291
|
};
|
|
291
|
-
return `${JSON.stringify(n)} ${
|
|
292
|
-
}).sort().join("\n")),
|
|
292
|
+
return `${JSON.stringify(n)} ${v(t.input.ast)} ${v(t.output.ast)}`;
|
|
293
|
+
}).sort().join("\n")), K = () => (e) => {
|
|
293
294
|
if (e.subject.type === "anonymous") return {
|
|
294
295
|
status: 401,
|
|
295
296
|
message: e.subject.credentialRejected ?? "Authentication required"
|
|
296
297
|
};
|
|
297
|
-
},
|
|
298
|
+
}, q = (e) => (t) => {
|
|
298
299
|
let n = t.subject.scopes;
|
|
299
300
|
if (!(n && (n.includes(e) || n.includes("admin:full")))) return {
|
|
300
301
|
status: 403,
|
|
301
302
|
message: `Missing required scope: ${e}`
|
|
302
303
|
};
|
|
303
|
-
},
|
|
304
|
+
}, ae = (e) => (t) => {
|
|
304
305
|
let n = t.subject.scopes;
|
|
305
306
|
if (!(n && (n.includes("admin:full") || e.some((e) => n.includes(e))))) return {
|
|
306
307
|
status: 403,
|
|
307
308
|
message: `Missing required scope: one of ${e.join(", ")}`
|
|
308
309
|
};
|
|
309
|
-
},
|
|
310
|
+
}, oe = (e, t, n, r) => {
|
|
311
|
+
if (e === void 0) return {};
|
|
312
|
+
let i = { Vary: "Authorization, Cookie" };
|
|
313
|
+
if (t.headers.authorization !== void 0 || t.headers.cookie !== void 0) return {
|
|
314
|
+
"Cache-Control": "private, no-cache",
|
|
315
|
+
...i
|
|
316
|
+
};
|
|
317
|
+
let a = Math.max(0, Math.floor(e.maxAge)), o = [
|
|
318
|
+
"public",
|
|
319
|
+
`max-age=${a}`,
|
|
320
|
+
`s-maxage=${a}`
|
|
321
|
+
];
|
|
322
|
+
e.staleWhileRevalidate !== void 0 && o.push(`stale-while-revalidate=${Math.max(0, Math.floor(e.staleWhileRevalidate))}`);
|
|
323
|
+
let s = [...new Set((e.tags?.(n, r) ?? []).filter((e) => e !== "" && !/[\s,]/.test(e)))];
|
|
324
|
+
return {
|
|
325
|
+
"Cache-Control": o.join(", "),
|
|
326
|
+
...i,
|
|
327
|
+
...s.length > 0 ? {
|
|
328
|
+
"Cache-Tag": s.join(","),
|
|
329
|
+
"Surrogate-Key": s.join(" ")
|
|
330
|
+
} : {}
|
|
331
|
+
};
|
|
332
|
+
}, J = (e, t = {}) => ({
|
|
310
333
|
__voltroRestResponse: !0,
|
|
311
334
|
status: t.status ?? 200,
|
|
312
335
|
body: e,
|
|
313
336
|
...t.headers === void 0 ? {} : { headers: t.headers },
|
|
314
337
|
...t.contentType === void 0 ? {} : { contentType: t.contentType }
|
|
315
|
-
}),
|
|
338
|
+
}), se = (e) => typeof e == "object" && !!e && e.__voltroRestResponse === !0, Y = class extends Error {
|
|
316
339
|
status;
|
|
317
340
|
body;
|
|
318
341
|
headers;
|
|
@@ -320,7 +343,7 @@ var w = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? D("",
|
|
|
320
343
|
constructor(e, t, n, r) {
|
|
321
344
|
super(`REST ${e}`), this.name = "RestRouteError", this.status = e, this.body = t, this.headers = n, this.contentType = r;
|
|
322
345
|
}
|
|
323
|
-
},
|
|
346
|
+
}, ce = (e, t, n) => new Y(e, t, n), le = (e) => {
|
|
324
347
|
if (e.version === void 0) return e;
|
|
325
348
|
if (!/^v\d+$/.test(e.version)) throw Error(`defineRestRoute(${e.method} ${e.path}): version "${e.version}" must be 'v' followed by digits — 'v1', 'v2', …`);
|
|
326
349
|
if ((/* @__PURE__ */ RegExp("^/v\\d+(/|$)")).test(e.path)) throw Error(`defineRestRoute(${e.method} ${e.path}): the path already starts with a version segment AND declares version: '${e.version}'. Pick one spelling — either bake the version into the path, or declare version: and keep the path bare ('/customers'). Both would mount '/${e.version}${e.path}', which is never what the author meant.`);
|
|
@@ -328,13 +351,13 @@ var w = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? D("",
|
|
|
328
351
|
...e,
|
|
329
352
|
path: `/${e.version}${e.path}`
|
|
330
353
|
};
|
|
331
|
-
},
|
|
354
|
+
}, ue = (e, t = {}) => ({
|
|
332
355
|
__voltroRestStream: !0,
|
|
333
356
|
stream: {
|
|
334
357
|
subscribe: e,
|
|
335
358
|
...t.keepAliveMs === void 0 ? {} : { keepAliveMs: t.keepAliveMs }
|
|
336
359
|
}
|
|
337
|
-
}),
|
|
360
|
+
}), de = (e, t) => `event: ${e}\n${(typeof t == "string" ? t : JSON.stringify(t)).split("\n").map((e) => `data: ${e}`).join("\n")}\n\n`, fe = (e) => typeof e == "object" && !!e && e.__voltroRestStream === !0, pe = (e, t = {}) => ({
|
|
338
361
|
__voltroRestBytes: !0,
|
|
339
362
|
byteStream: {
|
|
340
363
|
stream: e,
|
|
@@ -344,7 +367,7 @@ var w = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? D("",
|
|
|
344
367
|
...t.contentType === void 0 ? {} : { contentType: t.contentType },
|
|
345
368
|
...t.status === void 0 ? {} : { status: t.status },
|
|
346
369
|
...t.headers === void 0 ? {} : { headers: t.headers }
|
|
347
|
-
}), X = (e) => typeof e == "object" && !!e && e.__voltroRestBytes === !0,
|
|
370
|
+
}), X = (e) => typeof e == "object" && !!e && e.__voltroRestBytes === !0, me = async (e) => {
|
|
348
371
|
let t = await globalThis.crypto.subtle.digest("SHA-1", new TextEncoder().encode(e));
|
|
349
372
|
return [...new Uint8Array(t)].map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
350
373
|
}, Z = (e, t, n, r = "application/json; charset=utf-8") => ({
|
|
@@ -365,17 +388,17 @@ var w = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? D("",
|
|
|
365
388
|
query: t.query,
|
|
366
389
|
source: s.source,
|
|
367
390
|
status: n
|
|
368
|
-
},
|
|
391
|
+
}, u = l(s.format, {
|
|
369
392
|
status: n,
|
|
370
393
|
tag: r,
|
|
371
394
|
message: i,
|
|
372
395
|
fields: a
|
|
373
396
|
}, c);
|
|
374
|
-
return Z(n,
|
|
397
|
+
return Z(n, u.body, {
|
|
375
398
|
...o,
|
|
376
|
-
...
|
|
377
|
-
},
|
|
378
|
-
},
|
|
399
|
+
...u.headers ?? {}
|
|
400
|
+
}, u.contentType);
|
|
401
|
+
}, he = (e) => (e.headers["content-type"] ?? "application/json").split(";")[0].trim().toLowerCase(), ge = (e, t) => {
|
|
379
402
|
if (e.length === 0) return;
|
|
380
403
|
let n = t === "application/x-www-form-urlencoded";
|
|
381
404
|
if (!n && t !== "application/json" && !/^application\/[^/;\s]+\+json$/.test(t)) return;
|
|
@@ -383,21 +406,21 @@ var w = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? D("",
|
|
|
383
406
|
if (r.trim() !== "") {
|
|
384
407
|
if (n) {
|
|
385
408
|
let e = (e) => decodeURIComponent(e.replace(/\+/g, " "));
|
|
386
|
-
return
|
|
409
|
+
return ve(r.split("&").filter(Boolean).map((t) => {
|
|
387
410
|
let n = t.indexOf("=");
|
|
388
411
|
return n < 0 ? [e(t), ""] : [e(t.slice(0, n)), e(t.slice(n + 1))];
|
|
389
412
|
}));
|
|
390
413
|
}
|
|
391
414
|
return JSON.parse(r);
|
|
392
415
|
}
|
|
393
|
-
},
|
|
416
|
+
}, _e = (e) => ve(new URLSearchParams(e)), ve = (e) => {
|
|
394
417
|
let t = /* @__PURE__ */ new Map();
|
|
395
418
|
for (let [n, r] of e) {
|
|
396
419
|
let e = t.get(n);
|
|
397
420
|
e === void 0 ? t.set(n, r) : Array.isArray(e) ? e.push(r) : t.set(n, [e, r]);
|
|
398
421
|
}
|
|
399
422
|
return Object.fromEntries(t);
|
|
400
|
-
},
|
|
423
|
+
}, ye = (e, t) => {
|
|
401
424
|
let n = e.split("/").filter((e) => e.length > 0), r = t.split("/").filter((e) => e.length > 0), i = {};
|
|
402
425
|
for (let e = 0; e < n.length; e++) {
|
|
403
426
|
let t = n[e];
|
|
@@ -411,7 +434,7 @@ var w = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? D("",
|
|
|
411
434
|
}
|
|
412
435
|
}
|
|
413
436
|
return i;
|
|
414
|
-
},
|
|
437
|
+
}, be = (e, t) => {
|
|
415
438
|
let n = e.path.split("/"), r = n[n.length - 1] === "*", i = r ? n.slice(0, -1) : n, a = t.split("/");
|
|
416
439
|
if (a.length < i.length) return !1;
|
|
417
440
|
for (let e = 0; e < i.length; e++) {
|
|
@@ -421,173 +444,191 @@ var w = (e, t, n) => t.method ?? (t.resource !== void 0 && n !== void 0 ? D("",
|
|
|
421
444
|
} else if (t !== n) return !1;
|
|
422
445
|
}
|
|
423
446
|
return a.length === i.length ? !0 : e.match === "exact" && !r ? !1 : a.slice(i.length).some((e) => e.length > 0);
|
|
424
|
-
},
|
|
425
|
-
query:
|
|
447
|
+
}, xe = (e, t, n) => ({
|
|
448
|
+
query: _e(e.query),
|
|
426
449
|
params: t,
|
|
427
|
-
body: n ?
|
|
428
|
-
form:
|
|
450
|
+
body: n ? ge(e.rawBody, he(e)) : void 0,
|
|
451
|
+
form: he(e) === "application/x-www-form-urlencoded"
|
|
429
452
|
}), $ = /* @__PURE__ */ new Set([
|
|
430
453
|
"POST",
|
|
431
454
|
"PUT",
|
|
432
455
|
"PATCH",
|
|
433
456
|
"DELETE"
|
|
434
|
-
]),
|
|
435
|
-
if (
|
|
457
|
+
]), Se = (e, n, r, i, a) => {
|
|
458
|
+
if (e instanceof Y) return Z(e.status, e.body, {
|
|
436
459
|
...i,
|
|
437
|
-
...
|
|
438
|
-
},
|
|
439
|
-
if (typeof
|
|
440
|
-
let o =
|
|
460
|
+
...e.headers
|
|
461
|
+
}, e.contentType);
|
|
462
|
+
if (typeof e == "object" && e) {
|
|
463
|
+
let o = e;
|
|
441
464
|
if (typeof o.status == "number") return Q(r, a, o.status, typeof o._tag == "string" ? o._tag : "Error", typeof o.message == "string" ? o.message : "Error", {}, { ...i });
|
|
442
|
-
if (o._tag === "Unauthenticated" ||
|
|
465
|
+
if (o._tag === "Unauthenticated" || e instanceof t) return Q(r, a, 401, "Unauthorized", typeof o.reason == "string" ? o.reason : "Authentication required", {}, { ...i });
|
|
443
466
|
if (o._tag === "ScopeError") {
|
|
444
467
|
let e = n.type === "anonymous" ? 401 : 403;
|
|
445
468
|
return Q(r, a, e, e === 401 ? "Unauthorized" : "Forbidden", typeof o.message == "string" ? o.message : "Forbidden", {}, { ...i });
|
|
446
469
|
}
|
|
470
|
+
if (o._tag === "NoSuchResource") {
|
|
471
|
+
let t = e;
|
|
472
|
+
return Q(r, a, 404, "NoSuchResource", typeof o.message == "string" ? o.message : "Not Found", {
|
|
473
|
+
resourceType: typeof t.resourceType == "string" ? t.resourceType : null,
|
|
474
|
+
resourceId: typeof t.resourceId == "string" ? t.resourceId : null
|
|
475
|
+
}, { ...i });
|
|
476
|
+
}
|
|
447
477
|
}
|
|
448
|
-
return
|
|
449
|
-
error:
|
|
478
|
+
return c({
|
|
479
|
+
error: e,
|
|
450
480
|
source: "rest",
|
|
451
481
|
name: `${r.method} ${r.path}`,
|
|
452
482
|
fields: { status: 500 }
|
|
453
483
|
}), {
|
|
454
484
|
...Q(r, a, 500, "InternalServerError", "Internal Server Error", {}, { ...i }),
|
|
455
|
-
cause:
|
|
485
|
+
cause: e
|
|
456
486
|
};
|
|
457
|
-
},
|
|
458
|
-
let
|
|
459
|
-
a.projection !== void 0 && (
|
|
460
|
-
let
|
|
461
|
-
return a.deprecated !== void 0 && (
|
|
462
|
-
method:
|
|
487
|
+
}, Ce = (a, o, s) => {
|
|
488
|
+
let c = a.input ? C.decodeUnknown(a.input) : void 0, l = C.encode(a.output), d = a.input === void 0 ? void 0 : w.encodedAST(a.input.ast), f = d !== void 0 && (!w.isTypeLiteral(d) || d.indexSignatures.length > 0 || d.propertySignatures.some((e) => e.name === "body")), p = {};
|
|
489
|
+
a.projection !== void 0 && (p["x-voltro-rest-profile"] = a.projection.format.name);
|
|
490
|
+
let m = (e) => e.replace(/\/$/, "").split("/").length, h = m(a.path);
|
|
491
|
+
return a.deprecated !== void 0 && (p.Deprecation = "true"), a.sunset !== void 0 && (p.Sunset = a.sunset), {
|
|
492
|
+
method: a.method,
|
|
493
|
+
answersOtherMethods: !0,
|
|
463
494
|
path: a.path,
|
|
464
495
|
match: a.path.endsWith("/*") ? "prefix" : "exact",
|
|
465
496
|
...a.maxBodyBytes === void 0 ? {} : { maxBodyBytes: a.maxBodyBytes },
|
|
466
|
-
handle: async (
|
|
467
|
-
if (!a.path.endsWith("/*") &&
|
|
468
|
-
let
|
|
469
|
-
if (!(
|
|
470
|
-
...
|
|
471
|
-
Allow:
|
|
497
|
+
handle: async (d) => {
|
|
498
|
+
if (!a.path.endsWith("/*") && m(d.path) !== h) return Q(a, d, 404, "NotFound", "Not Found", {}, { ...p });
|
|
499
|
+
let g = d.method.toUpperCase();
|
|
500
|
+
if (!(g === a.method || g === "HEAD" && a.method === "GET")) return Q(a, d, 405, "MethodNotAllowed", "Method Not Allowed", { allow: s }, {
|
|
501
|
+
...p,
|
|
502
|
+
Allow: s
|
|
472
503
|
});
|
|
473
504
|
if (a.sunset !== void 0) {
|
|
474
505
|
let e = Date.parse(a.sunset);
|
|
475
|
-
if (!Number.isNaN(e) && Date.now() >= e) return Q(a,
|
|
506
|
+
if (!Number.isNaN(e) && Date.now() >= e) return Q(a, d, 410, "Gone", "Gone", {
|
|
476
507
|
...a.version === void 0 ? {} : { version: a.version },
|
|
477
508
|
...a.deprecated === void 0 ? {} : { replacement: a.deprecated }
|
|
478
|
-
}, { ...
|
|
509
|
+
}, { ...p });
|
|
479
510
|
}
|
|
480
|
-
let
|
|
481
|
-
if (
|
|
511
|
+
let _;
|
|
512
|
+
if (c) {
|
|
482
513
|
let e;
|
|
483
514
|
try {
|
|
484
|
-
e =
|
|
515
|
+
e = xe(d, ye(a.path, d.path), f);
|
|
485
516
|
} catch {
|
|
486
|
-
return Q(a,
|
|
517
|
+
return Q(a, d, 400, "InvalidRequest", "Malformed request body", {}, { ...p });
|
|
487
518
|
}
|
|
488
|
-
let t = await
|
|
519
|
+
let t = await x.runPromise(c(e).pipe(x.map((e) => ({
|
|
489
520
|
ok: !0,
|
|
490
521
|
value: e
|
|
491
|
-
})),
|
|
522
|
+
})), x.catchAll((e) => x.succeed({
|
|
492
523
|
ok: !1,
|
|
493
524
|
cause: e
|
|
494
525
|
}))));
|
|
495
|
-
if (!t.ok) return Q(a,
|
|
496
|
-
|
|
526
|
+
if (!t.ok) return Q(a, d, 400, "InvalidRequest", "Invalid request", { detail: String(t.cause) }, { ...p });
|
|
527
|
+
_ = t.value;
|
|
497
528
|
}
|
|
498
|
-
let
|
|
529
|
+
let v;
|
|
499
530
|
try {
|
|
500
|
-
|
|
501
|
-
} catch (
|
|
502
|
-
if (
|
|
503
|
-
let
|
|
504
|
-
return Q(a,
|
|
531
|
+
v = o.resolveSubject ? await o.resolveSubject(d.headers) : e(d.headers["x-tenant"] ?? null);
|
|
532
|
+
} catch (e) {
|
|
533
|
+
if (e instanceof t || typeof e == "object" && e && e._tag === "Unauthenticated") {
|
|
534
|
+
let t = e.reason;
|
|
535
|
+
return Q(a, d, 401, "Unauthorized", t ?? "Authentication required", {}, { ...p });
|
|
505
536
|
}
|
|
506
|
-
throw
|
|
537
|
+
throw e;
|
|
507
538
|
}
|
|
508
|
-
let
|
|
539
|
+
let b;
|
|
509
540
|
try {
|
|
510
|
-
|
|
541
|
+
b = o.buildContext ? await o.buildContext(v, d.headers) : void 0;
|
|
511
542
|
} catch (e) {
|
|
512
|
-
return
|
|
543
|
+
return Se(e, v, a, p, d);
|
|
513
544
|
}
|
|
514
|
-
let
|
|
515
|
-
subject:
|
|
516
|
-
headers:
|
|
517
|
-
store:
|
|
518
|
-
method:
|
|
519
|
-
path:
|
|
520
|
-
query:
|
|
521
|
-
rawBody:
|
|
522
|
-
...
|
|
523
|
-
...
|
|
545
|
+
let S = typeof b == "object" && b && "store" in b ? b.store : o.store, C = {
|
|
546
|
+
subject: v,
|
|
547
|
+
headers: d.headers,
|
|
548
|
+
store: S,
|
|
549
|
+
method: g,
|
|
550
|
+
path: d.path,
|
|
551
|
+
query: d.query,
|
|
552
|
+
rawBody: d.rawBody,
|
|
553
|
+
...b === void 0 ? {} : { app: b },
|
|
554
|
+
...d.remoteAddr === void 0 ? {} : { remoteAddr: d.remoteAddr }
|
|
524
555
|
};
|
|
525
556
|
if (a.guards) for (let e of a.guards) {
|
|
526
|
-
let t = await e(
|
|
527
|
-
if (t) return Q(a,
|
|
557
|
+
let t = await e(C);
|
|
558
|
+
if (t) return Q(a, d, t.status, t.status === 401 ? "Unauthorized" : t.status === 403 ? "Forbidden" : "GuardRejected", t.message, {}, { ...p });
|
|
528
559
|
}
|
|
529
|
-
let
|
|
530
|
-
if (
|
|
531
|
-
let e = await
|
|
560
|
+
let w = o.idempotency, T = w && $.has(a.method) ? d.headers[w.header.toLowerCase()] : void 0, E = w && T ? u(v.tenantId, a.method, a.path) : "", D;
|
|
561
|
+
if (w && T) {
|
|
562
|
+
let e = await y(w.store, E, T, w.ttlMs, Date.now());
|
|
532
563
|
if (e.kind === "replay") return Z(e.response.status, e.response.body, {
|
|
533
|
-
...
|
|
564
|
+
...p,
|
|
534
565
|
"Idempotency-Replayed": "true"
|
|
535
566
|
});
|
|
536
|
-
if (e.kind === "conflict") return Q(a,
|
|
567
|
+
if (e.kind === "conflict") return Q(a, d, 409, "Conflict", "A request with this Idempotency-Key is already being processed", {}, { ...p });
|
|
568
|
+
D = r(w.store, E, T);
|
|
537
569
|
}
|
|
538
570
|
try {
|
|
539
|
-
let e = await a.handler(
|
|
540
|
-
if (
|
|
571
|
+
let e = await a.handler(_, C);
|
|
572
|
+
if (fe(e) || X(e)) return w && T && await i(w.store, E, T), X(e) ? {
|
|
541
573
|
status: e.status ?? 200,
|
|
542
574
|
headers: {
|
|
543
|
-
...
|
|
575
|
+
...p,
|
|
544
576
|
...e.headers
|
|
545
577
|
},
|
|
546
578
|
byteStream: e.byteStream,
|
|
547
579
|
...e.contentType === void 0 ? {} : { contentType: e.contentType }
|
|
548
580
|
} : {
|
|
549
581
|
status: 200,
|
|
550
|
-
headers:
|
|
582
|
+
headers: p,
|
|
551
583
|
stream: e.stream
|
|
552
584
|
};
|
|
553
|
-
let t =
|
|
554
|
-
...
|
|
555
|
-
...t.headers
|
|
585
|
+
let t = se(e) ? e : J(e), r = await x.runPromise(l(t.body)), o = a.method === "GET" && t.status === 200 ? oe(a.cache, d, r, _) : {}, s = {
|
|
586
|
+
...p,
|
|
587
|
+
...t.headers,
|
|
588
|
+
...o
|
|
556
589
|
};
|
|
557
|
-
if (
|
|
590
|
+
if (w && T && await n(w.store, E, T, {
|
|
558
591
|
status: t.status,
|
|
559
592
|
body: r
|
|
560
593
|
}, Date.now()), a.etag === !0 && a.method === "GET") {
|
|
561
|
-
let e = `W/"${await
|
|
594
|
+
let e = `W/"${await me(JSON.stringify(r))}"`, n = d.headers["if-none-match"];
|
|
562
595
|
return n !== void 0 && n.split(",").some((t) => t.trim() === e) ? {
|
|
563
596
|
status: 304,
|
|
564
597
|
headers: {
|
|
565
|
-
...
|
|
598
|
+
...p,
|
|
599
|
+
...o,
|
|
566
600
|
ETag: e
|
|
567
601
|
}
|
|
568
602
|
} : Z(t.status, r, {
|
|
569
|
-
...
|
|
603
|
+
...s,
|
|
570
604
|
ETag: e
|
|
571
605
|
}, t.contentType);
|
|
572
606
|
}
|
|
573
607
|
return t.status === 204 || t.status === 304 ? {
|
|
574
608
|
status: t.status,
|
|
575
|
-
headers:
|
|
576
|
-
} : Z(t.status, r,
|
|
609
|
+
headers: s
|
|
610
|
+
} : Z(t.status, r, s, t.contentType);
|
|
577
611
|
} catch (e) {
|
|
578
|
-
return
|
|
612
|
+
return w && T && await i(w.store, E, T), Se(e, v, a, p, d);
|
|
613
|
+
} finally {
|
|
614
|
+
D?.();
|
|
579
615
|
}
|
|
580
616
|
}
|
|
581
617
|
};
|
|
582
|
-
},
|
|
618
|
+
}, we = (e, t = {}) => {
|
|
583
619
|
if (t.idempotency !== void 0) {
|
|
584
620
|
for (let t of e) if (t.streaming === !0 && $.has(t.method)) throw Error(`REST route ${t.method} ${t.path} declares \`streaming: true\` on a method the idempotency binding claims (${[...$].join("/")}). A stream cannot complete an idempotency claim — there is no replayable body to cache — so a retried request would 409 until the claim's TTL. Either serve the stream on GET, or scope the idempotency binding away from this app's streaming routes.`);
|
|
585
621
|
}
|
|
586
|
-
|
|
587
|
-
|
|
622
|
+
let n = (e) => e.split("/").map((e) => e.startsWith(":") ? ":" : e).join("/"), r = /* @__PURE__ */ new Map();
|
|
623
|
+
for (let t of e) {
|
|
624
|
+
let e = r.get(n(t.path)) ?? [];
|
|
625
|
+
e.includes(t.method) || e.push(t.method), r.set(n(t.path), e);
|
|
626
|
+
}
|
|
627
|
+
return e.map((e) => Ce(e, t, r.get(n(e.path)).join(", ")));
|
|
628
|
+
}, Te = async (e, t) => {
|
|
588
629
|
let n = await e[0].handle(t);
|
|
589
630
|
for (let r = 1; r < e.length && n.status === 405; r++) n = await e[r].handle(t);
|
|
590
631
|
return n;
|
|
591
632
|
};
|
|
592
633
|
//#endregion
|
|
593
|
-
export { g as JSONAPI_MEDIA_TYPE, f as PROBLEM_JSON, m as REST_PROFILE_NAMES, Y as RestRouteError,
|
|
634
|
+
export { g as JSONAPI_MEDIA_TYPE, f as PROBLEM_JSON, m as REST_PROFILE_NAMES, Y as RestRouteError, pe as bytes, F as coerceQueryObject, P as coerceQueryValue, W as collectPublicApiRoutes, I as declaredErrorTags, le as defineRestRoute, T as derivePublicMethod, E as derivePublicPath, k as deriveResource, Te as dispatchSharedPath, l as encodeRestError, a as encodeRestSuccess, z as errorMemberSchema, X as isRestByteResponse, se as isRestResponse, fe as isRestStreamResponse, ye as matchPathParams, p as nextLink, A as normalizePathParams, te as operationIdOf, j as pathParamNames, h as problemDetails, o as problemTypeOf, R as projectedFailure, U as publicApiRoute, G as publicSurfaceDigest, ae as requireAnyScope, K as requireAuthenticated, q as requireScope, d as resolveRestFormat, O as resourceIdField, J as response, ce as restError, we as restRoutesToHttpRoutes, _ as restViewSchema, be as routeAcceptsPath, ue as sse, de as sseFrame, s as toSnakeCase, H as wireExample };
|