@selvajs/selva 4.20.1-beta.4 → 4.21.0-beta.6
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/build/adapter-node.js +1 -1
- package/build/client/_app/immutable/chunks/{CzfnuBzq.js → BAhtiTKe.js} +1 -1
- package/build/client/_app/immutable/chunks/BAhtiTKe.js.br +0 -0
- package/build/client/_app/immutable/chunks/BAhtiTKe.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{D-uUm_OB.js → BepzH9eI.js} +4 -4
- package/build/client/_app/immutable/chunks/BepzH9eI.js.br +0 -0
- package/build/client/_app/immutable/chunks/{D-uUm_OB.js.gz → BepzH9eI.js.gz} +0 -0
- package/build/client/_app/immutable/chunks/BmoT9ksD.js +1 -0
- package/build/client/_app/immutable/chunks/BmoT9ksD.js.br +1 -0
- package/build/client/_app/immutable/chunks/BmoT9ksD.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{qi43d-TM.js → CKbHmAlc.js} +1 -1
- package/build/client/_app/immutable/chunks/CKbHmAlc.js.br +0 -0
- package/build/client/_app/immutable/chunks/CKbHmAlc.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{C6Y_BUwr.js → CmlXAF26.js} +1 -1
- package/build/client/_app/immutable/chunks/CmlXAF26.js.br +0 -0
- package/build/client/_app/immutable/chunks/CmlXAF26.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{BDYCH-_Q.js → D5j4-ZO1.js} +1 -1
- package/build/client/_app/immutable/chunks/D5j4-ZO1.js.br +0 -0
- package/build/client/_app/immutable/chunks/D5j4-ZO1.js.gz +0 -0
- package/build/client/_app/immutable/chunks/DW5EJMC7.js +1 -0
- package/build/client/_app/immutable/chunks/DW5EJMC7.js.br +0 -0
- package/build/client/_app/immutable/chunks/DW5EJMC7.js.gz +0 -0
- package/build/client/_app/immutable/chunks/{DzxE3j6C.js → qXnHMKD9.js} +1 -1
- package/build/client/_app/immutable/chunks/qXnHMKD9.js.br +0 -0
- package/build/client/_app/immutable/chunks/qXnHMKD9.js.gz +0 -0
- package/build/client/_app/immutable/entry/{app.BpT6WkO1.js → app.DblLep9O.js} +2 -2
- package/build/client/_app/immutable/entry/app.DblLep9O.js.br +0 -0
- package/build/client/_app/immutable/entry/app.DblLep9O.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{1.D3kiiIk_.js → 1.DWd6YbcT.js} +1 -1
- package/build/client/_app/immutable/nodes/1.DWd6YbcT.js.br +0 -0
- package/build/client/_app/immutable/nodes/1.DWd6YbcT.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{2.CUNbzjI_.js → 2.CS32Eh9m.js} +1 -1
- package/build/client/_app/immutable/nodes/2.CS32Eh9m.js.br +0 -0
- package/build/client/_app/immutable/nodes/2.CS32Eh9m.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{20.9OIre0ah.js → 20.CUK41A3B.js} +1 -1
- package/build/client/_app/immutable/nodes/20.CUK41A3B.js.br +0 -0
- package/build/client/_app/immutable/nodes/20.CUK41A3B.js.gz +0 -0
- package/build/client/_app/immutable/nodes/21.DvC40Ypm.js +1 -0
- package/build/client/_app/immutable/nodes/21.DvC40Ypm.js.br +0 -0
- package/build/client/_app/immutable/nodes/21.DvC40Ypm.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{25.DW1_vMxq.js → 25.D6EkgNRa.js} +1 -1
- package/build/client/_app/immutable/nodes/25.D6EkgNRa.js.br +0 -0
- package/build/client/_app/immutable/nodes/25.D6EkgNRa.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{3.3Z4QUsQQ.js → 3.Ctd9OGCk.js} +1 -1
- package/build/client/_app/immutable/nodes/3.Ctd9OGCk.js.br +0 -0
- package/build/client/_app/immutable/nodes/3.Ctd9OGCk.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{5.DmA9lTA-.js → 5.Wh_w3RkZ.js} +1 -1
- package/build/client/_app/immutable/nodes/5.Wh_w3RkZ.js.br +2 -0
- package/build/client/_app/immutable/nodes/5.Wh_w3RkZ.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{6.D6WLqCgl.js → 6.C-DiUI5R.js} +1 -1
- package/build/client/_app/immutable/nodes/6.C-DiUI5R.js.br +0 -0
- package/build/client/_app/immutable/nodes/6.C-DiUI5R.js.gz +0 -0
- package/build/client/_app/immutable/nodes/{7.CNuRjkv2.js → 7.B8yubYrv.js} +1 -1
- package/build/client/_app/immutable/nodes/7.B8yubYrv.js.br +0 -0
- package/build/client/_app/immutable/nodes/7.B8yubYrv.js.gz +0 -0
- package/build/client/_app/version.json +1 -1
- package/build/client/_app/version.json.br +0 -0
- package/build/client/_app/version.json.gz +0 -0
- package/build/server/.vite/manifest.json +7 -5
- package/build/server/chunks/api.js +9 -2
- package/build/server/chunks/api.js.map +1 -1
- package/build/server/chunks/computeRateLimit.server.js +1 -1
- package/build/server/chunks/engine.server.js +2 -2
- package/build/server/chunks/engine.server.js.map +1 -1
- package/build/server/chunks/grasshopper.js +217 -162
- package/build/server/chunks/grasshopper.js.map +1 -1
- package/build/server/chunks/handlers.js +1 -1
- package/build/server/chunks/instance.js +3 -3
- package/build/server/chunks/internal.js +1 -1
- package/build/server/chunks/liveSolve.server.js +1 -1
- package/build/server/chunks/localeContext.svelte.js +14 -0
- package/build/server/chunks/localeContext.svelte.js.map +1 -1
- package/build/server/chunks/{outcome-DNrffAXp.js → outcome-D28FgvFK.js} +9 -6
- package/build/server/chunks/outcome-D28FgvFK.js.map +1 -0
- package/build/server/chunks/package.js +1 -1
- package/build/server/chunks/package.js.map +1 -1
- package/build/server/chunks/providers.server.js +59 -40
- package/build/server/chunks/providers.server.js.map +1 -1
- package/build/server/chunks/registry.js +1 -1
- package/build/server/chunks/schema.js +1 -1
- package/build/server/chunks/schema.js.map +1 -1
- package/build/server/chunks/serverStats.server.js +1 -1
- package/build/server/chunks/solve.server.js +31 -4
- package/build/server/chunks/solve.server.js.map +1 -1
- package/build/server/chunks/sveltekit.js +1 -1
- package/build/server/entries/endpoints/api/admin/compute/status/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/orgs/_id_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/orgs/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/projects/_id_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/projects/_id_/grants/_grantId_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/projects/_id_/grants/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/projects/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/users/_id_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/users/_id_/disable/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/admin/users/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/compute/_server.ts.js +5 -1
- package/build/server/entries/endpoints/api/v1/compute/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/api/v1/compute/schema/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/image/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/publish/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/schema/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/share-links/_linkId_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/share-links/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/solve/_server.ts.js +2 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/solve/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/versions/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/versions/_versionId_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/versions/_versionId_/schema/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/projects/_id_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/projects/_id_/members/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/projects/_id_/members/_userId_/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/projects/_id_/reclaim/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/solve/_solveId_/cancel/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/solve-events/_server.ts.js +1 -1
- package/build/server/entries/endpoints/docs/api/openapi.yaml/_server.ts.js +1 -1
- package/build/server/entries/pages/library/_guid_/_page.server.ts.js +4 -4
- package/build/server/entries/pages/library/_guid_/_page.server.ts.js.map +1 -1
- package/build/server/entries/pages/library/_guid_/_page.svelte.js +232 -11
- package/build/server/entries/pages/library/_guid_/_page.svelte.js.map +1 -1
- package/build/server/manifest-full.js +1 -1
- package/build/server/manifest.js +1 -1
- package/build/server/nodes/1.js +1 -1
- package/build/server/nodes/2.js +1 -1
- package/build/server/nodes/20.js +1 -1
- package/build/server/nodes/21.js +1 -1
- package/build/server/nodes/25.js +1 -1
- package/build/server/nodes/3.js +1 -1
- package/build/server/nodes/5.js +1 -1
- package/build/server/nodes/6.js +1 -1
- package/build/server/nodes/7.js +1 -1
- package/build/server/server.js +1 -1
- package/package.json +10 -10
- package/build/client/_app/immutable/chunks/BDYCH-_Q.js.br +0 -0
- package/build/client/_app/immutable/chunks/BDYCH-_Q.js.gz +0 -0
- package/build/client/_app/immutable/chunks/C6Y_BUwr.js.br +0 -0
- package/build/client/_app/immutable/chunks/C6Y_BUwr.js.gz +0 -0
- package/build/client/_app/immutable/chunks/CzfnuBzq.js.br +0 -0
- package/build/client/_app/immutable/chunks/CzfnuBzq.js.gz +0 -0
- package/build/client/_app/immutable/chunks/D-uUm_OB.js.br +0 -0
- package/build/client/_app/immutable/chunks/D84F7w9g.js +0 -1
- package/build/client/_app/immutable/chunks/D84F7w9g.js.br +0 -1
- package/build/client/_app/immutable/chunks/D84F7w9g.js.gz +0 -0
- package/build/client/_app/immutable/chunks/DQsP4nZb.js +0 -1
- package/build/client/_app/immutable/chunks/DQsP4nZb.js.br +0 -0
- package/build/client/_app/immutable/chunks/DQsP4nZb.js.gz +0 -0
- package/build/client/_app/immutable/chunks/DzxE3j6C.js.br +0 -0
- package/build/client/_app/immutable/chunks/DzxE3j6C.js.gz +0 -0
- package/build/client/_app/immutable/chunks/qi43d-TM.js.br +0 -0
- package/build/client/_app/immutable/chunks/qi43d-TM.js.gz +0 -0
- package/build/client/_app/immutable/entry/app.BpT6WkO1.js.br +0 -0
- package/build/client/_app/immutable/entry/app.BpT6WkO1.js.gz +0 -0
- package/build/client/_app/immutable/nodes/1.D3kiiIk_.js.br +0 -0
- package/build/client/_app/immutable/nodes/1.D3kiiIk_.js.gz +0 -0
- package/build/client/_app/immutable/nodes/2.CUNbzjI_.js.br +0 -0
- package/build/client/_app/immutable/nodes/2.CUNbzjI_.js.gz +0 -0
- package/build/client/_app/immutable/nodes/20.9OIre0ah.js.br +0 -0
- package/build/client/_app/immutable/nodes/20.9OIre0ah.js.gz +0 -0
- package/build/client/_app/immutable/nodes/21.BkNlRItr.js +0 -1
- package/build/client/_app/immutable/nodes/21.BkNlRItr.js.br +0 -0
- package/build/client/_app/immutable/nodes/21.BkNlRItr.js.gz +0 -0
- package/build/client/_app/immutable/nodes/25.DW1_vMxq.js.br +0 -0
- package/build/client/_app/immutable/nodes/25.DW1_vMxq.js.gz +0 -0
- package/build/client/_app/immutable/nodes/3.3Z4QUsQQ.js.br +0 -0
- package/build/client/_app/immutable/nodes/3.3Z4QUsQQ.js.gz +0 -0
- package/build/client/_app/immutable/nodes/5.DmA9lTA-.js.br +0 -1
- package/build/client/_app/immutable/nodes/5.DmA9lTA-.js.gz +0 -0
- package/build/client/_app/immutable/nodes/6.D6WLqCgl.js.br +0 -0
- package/build/client/_app/immutable/nodes/6.D6WLqCgl.js.gz +0 -0
- package/build/client/_app/immutable/nodes/7.CNuRjkv2.js.br +0 -0
- package/build/client/_app/immutable/nodes/7.CNuRjkv2.js.gz +0 -0
- package/build/server/chunks/outcome-DNrffAXp.js.map +0 -1
|
@@ -1,72 +1,4 @@
|
|
|
1
|
-
// ../compute/dist/handle-files-
|
|
2
|
-
var DEFAULT_RETRY = {
|
|
3
|
-
attempts: 0,
|
|
4
|
-
baseDelayMs: 500,
|
|
5
|
-
maxDelayMs: 3e4,
|
|
6
|
-
retryOn429: true
|
|
7
|
-
};
|
|
8
|
-
var RETRYABLE_STATUS = /* @__PURE__ */ new Set([
|
|
9
|
-
502,
|
|
10
|
-
503,
|
|
11
|
-
504
|
|
12
|
-
]);
|
|
13
|
-
/**
|
|
14
|
-
* Ceiling on a server-sent `Retry-After` wait. The server's window outranks
|
|
15
|
-
* `RetryPolicy.maxDelayMs` (retrying sooner all but guarantees another 429), but a bad or hostile
|
|
16
|
-
* header must not park the client for minutes. A `maxDelayMs` above this cap raises it.
|
|
17
|
-
*/
|
|
18
|
-
var RETRY_AFTER_CAP_MS = 6e4;
|
|
19
|
-
function resolveRetryPolicy(policy) {
|
|
20
|
-
if (!policy) return DEFAULT_RETRY;
|
|
21
|
-
return {
|
|
22
|
-
attempts: policy.attempts ?? DEFAULT_RETRY.attempts,
|
|
23
|
-
baseDelayMs: policy.baseDelayMs ?? DEFAULT_RETRY.baseDelayMs,
|
|
24
|
-
maxDelayMs: policy.maxDelayMs ?? DEFAULT_RETRY.maxDelayMs,
|
|
25
|
-
retryOn429: policy.retryOn429 ?? DEFAULT_RETRY.retryOn429
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
function isRetryableStatus(status, policy) {
|
|
29
|
-
return RETRYABLE_STATUS.has(status) || policy.retryOn429 && status === 429;
|
|
30
|
-
}
|
|
31
|
-
/** Delay before the next attempt: the server's `Retry-After` when it sent one, else backoff. */
|
|
32
|
-
function retryDelay(retryAfter, attempt, policy) {
|
|
33
|
-
const retryAfterMs = parseRetryAfter(retryAfter);
|
|
34
|
-
return retryAfterMs === null ? backoffDelay(attempt, policy) : Math.min(retryAfterMs, Math.max(policy.maxDelayMs, RETRY_AFTER_CAP_MS));
|
|
35
|
-
}
|
|
36
|
-
/** A `Retry-After` value (seconds or HTTP-date) in ms; null when missing or unparseable. */
|
|
37
|
-
function parseRetryAfter(headerValue) {
|
|
38
|
-
if (!headerValue) return null;
|
|
39
|
-
const seconds = Number(headerValue);
|
|
40
|
-
if (Number.isFinite(seconds) && seconds >= 0) return seconds * 1e3;
|
|
41
|
-
const dateMs = Date.parse(headerValue);
|
|
42
|
-
if (Number.isFinite(dateMs)) {
|
|
43
|
-
const delta = dateMs - Date.now();
|
|
44
|
-
return delta > 0 ? delta : 0;
|
|
45
|
-
}
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
function backoffDelay(attempt, policy) {
|
|
49
|
-
const exponential = policy.baseDelayMs * Math.pow(2, attempt);
|
|
50
|
-
const jitter = Math.random() * policy.baseDelayMs;
|
|
51
|
-
return Math.min(exponential + jitter, policy.maxDelayMs);
|
|
52
|
-
}
|
|
53
|
-
function sleep(ms, signal) {
|
|
54
|
-
return new Promise((resolve, reject) => {
|
|
55
|
-
if (signal?.aborted) {
|
|
56
|
-
reject(new DOMException("Aborted", "AbortError"));
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
const id = setTimeout(() => {
|
|
60
|
-
signal?.removeEventListener("abort", onAbort);
|
|
61
|
-
resolve();
|
|
62
|
-
}, ms);
|
|
63
|
-
const onAbort = () => {
|
|
64
|
-
clearTimeout(id);
|
|
65
|
-
reject(new DOMException("Aborted", "AbortError"));
|
|
66
|
-
};
|
|
67
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
68
|
-
});
|
|
69
|
-
}
|
|
1
|
+
// ../compute/dist/handle-files-CzqBN3MP.js
|
|
70
2
|
var ErrorCodes = {
|
|
71
3
|
/** Connection failure, a gateway status (502/503/504), or a 2xx body cut off mid-stream. */
|
|
72
4
|
NETWORK_ERROR: "NETWORK_ERROR",
|
|
@@ -206,6 +138,176 @@ function setLogger(logger) {
|
|
|
206
138
|
function enableDebugLogging() {
|
|
207
139
|
setLogger(console);
|
|
208
140
|
}
|
|
141
|
+
var warned = /* @__PURE__ */ new Set();
|
|
142
|
+
/** Log `message` the first time `key` is seen: what it reports doesn't change per call. */
|
|
143
|
+
function warnOnce(key, message) {
|
|
144
|
+
if (warned.has(key)) return;
|
|
145
|
+
warned.add(key);
|
|
146
|
+
getLogger().warn(message);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* True only in a real browser, where an API key in the config is exposed to users. jsdom defines
|
|
150
|
+
* `window` too, so Node is ruled out by `process.versions.node`, and by jsdom's user-agent marker
|
|
151
|
+
* for setups that hide `process`.
|
|
152
|
+
*/
|
|
153
|
+
function isRealBrowser() {
|
|
154
|
+
if (typeof window === "undefined") return false;
|
|
155
|
+
if (globalThis.process?.versions?.node != null) return false;
|
|
156
|
+
const nav = globalThis.navigator;
|
|
157
|
+
const userAgent = typeof nav?.userAgent === "string" ? nav.userAgent : "";
|
|
158
|
+
if (/jsdom/i.test(userAgent)) return false;
|
|
159
|
+
return true;
|
|
160
|
+
}
|
|
161
|
+
function warnIfClientSide(functionName, suppress) {
|
|
162
|
+
if (suppress || !isRealBrowser()) return;
|
|
163
|
+
warnOnce(`client-side:${functionName}`, `Warning: ${functionName} is running on the client side. For better performance and security, consider running this on the server side.`);
|
|
164
|
+
}
|
|
165
|
+
/** `serverUrl` as `validateServerUrl` returns it: no trailing slash. */
|
|
166
|
+
function buildUrl(endpoint, serverUrl) {
|
|
167
|
+
return `${serverUrl}/${endpoint.replace(/^\/+/, "")}`;
|
|
168
|
+
}
|
|
169
|
+
function isLocalhost(serverUrl) {
|
|
170
|
+
const hostname = new URL(serverUrl).hostname.toLowerCase();
|
|
171
|
+
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]";
|
|
172
|
+
}
|
|
173
|
+
var DEFAULT_API_KEY_HEADER = "RhinoComputeKey";
|
|
174
|
+
/**
|
|
175
|
+
* Caller headers plus credentials. Every request to the server builds its headers here,
|
|
176
|
+
* so a liveness probe authenticates exactly like the solve it gates.
|
|
177
|
+
*/
|
|
178
|
+
function buildAuthHeaders(auth) {
|
|
179
|
+
return assertSendable(mergeUnder(auth.headers, credentialHeaders(auth)));
|
|
180
|
+
}
|
|
181
|
+
function buildHeaders(requestId, config) {
|
|
182
|
+
const headers = assertSendable(mergeUnder(config.headers, {
|
|
183
|
+
...credentialHeaders(config),
|
|
184
|
+
...sessionHeader(config.sessionId),
|
|
185
|
+
"X-Request-ID": requestId,
|
|
186
|
+
"Content-Type": "application/json"
|
|
187
|
+
}));
|
|
188
|
+
if (!config.apiKey && !config.authToken && !isLocalhost(config.serverUrl)) warnOnce(`no-auth:${config.serverUrl}`, `[Compute] Request [${requestId}] targets remote server (${config.serverUrl}) but no API key or auth token is configured. Requests may fail or be rate-limited. (warned once per server)`);
|
|
189
|
+
return headers;
|
|
190
|
+
}
|
|
191
|
+
/** `headers` with a JSON `Content-Type` that replaces one of any casing already there. */
|
|
192
|
+
function withJsonContentType(headers) {
|
|
193
|
+
return mergeUnder(headers, { "Content-Type": "application/json" });
|
|
194
|
+
}
|
|
195
|
+
function credentialHeaders(auth) {
|
|
196
|
+
return {
|
|
197
|
+
...auth.authToken && { Authorization: auth.authToken },
|
|
198
|
+
...auth.apiKey && { [auth.apiKeyHeader ?? DEFAULT_API_KEY_HEADER]: auth.apiKey }
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
var SESSION_ID = /^[!-~]{1,128}$/;
|
|
202
|
+
/**
|
|
203
|
+
* Compute drops a malformed id without an error, so the request would quietly lose its routing.
|
|
204
|
+
* The client and scheduler call this on entry too: by `buildHeaders` a solve has already taken a
|
|
205
|
+
* slot and loaded its definition.
|
|
206
|
+
*/
|
|
207
|
+
function assertSessionId(sessionId) {
|
|
208
|
+
if (sessionId === void 0 || SESSION_ID.test(sessionId)) return;
|
|
209
|
+
throw new ComputeError("sessionId must be 1 to 128 characters from \"!\" to \"~\"", ErrorCodes.INVALID_CONFIG, { context: { length: sessionId.length } });
|
|
210
|
+
}
|
|
211
|
+
function sessionHeader(sessionId) {
|
|
212
|
+
assertSessionId(sessionId);
|
|
213
|
+
return sessionId === void 0 ? {} : { "X-Session-Id": sessionId };
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Header names are case-insensitive and fetch joins duplicates, so a caller key
|
|
217
|
+
* matching a transport key in any case is dropped rather than sent alongside it.
|
|
218
|
+
*/
|
|
219
|
+
function mergeUnder(caller, transport) {
|
|
220
|
+
const taken = new Set(Object.keys(transport).map((name) => name.toLowerCase()));
|
|
221
|
+
const kept = Object.entries(caller ?? {}).filter(([name]) => !taken.has(name.toLowerCase()));
|
|
222
|
+
return {
|
|
223
|
+
...Object.fromEntries(kept),
|
|
224
|
+
...transport
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Left to fetch, a bad value becomes a retried TypeError that quotes it, and the value may be the
|
|
229
|
+
* API key. `Headers` throws the same message, so its error is not kept as the cause.
|
|
230
|
+
*/
|
|
231
|
+
function assertSendable(headers) {
|
|
232
|
+
const check = new Headers();
|
|
233
|
+
for (const [name, value] of Object.entries(headers)) try {
|
|
234
|
+
check.set(name, value);
|
|
235
|
+
} catch {
|
|
236
|
+
throw new ComputeError(`Header "${name}" has an invalid name or value`, ErrorCodes.INVALID_CONFIG, { context: { header: name } });
|
|
237
|
+
}
|
|
238
|
+
return headers;
|
|
239
|
+
}
|
|
240
|
+
function generateRequestId() {
|
|
241
|
+
return `${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;
|
|
242
|
+
}
|
|
243
|
+
var DEFAULT_RETRY = {
|
|
244
|
+
attempts: 0,
|
|
245
|
+
baseDelayMs: 500,
|
|
246
|
+
maxDelayMs: 3e4,
|
|
247
|
+
retryOn429: true
|
|
248
|
+
};
|
|
249
|
+
var RETRYABLE_STATUS = /* @__PURE__ */ new Set([
|
|
250
|
+
502,
|
|
251
|
+
503,
|
|
252
|
+
504
|
|
253
|
+
]);
|
|
254
|
+
/**
|
|
255
|
+
* Ceiling on a server-sent `Retry-After` wait. The server's window outranks
|
|
256
|
+
* `RetryPolicy.maxDelayMs` (retrying sooner all but guarantees another 429), but a bad or hostile
|
|
257
|
+
* header must not park the client for minutes. A `maxDelayMs` above this cap raises it.
|
|
258
|
+
*/
|
|
259
|
+
var RETRY_AFTER_CAP_MS = 6e4;
|
|
260
|
+
function resolveRetryPolicy(policy) {
|
|
261
|
+
if (!policy) return DEFAULT_RETRY;
|
|
262
|
+
return {
|
|
263
|
+
attempts: policy.attempts ?? DEFAULT_RETRY.attempts,
|
|
264
|
+
baseDelayMs: policy.baseDelayMs ?? DEFAULT_RETRY.baseDelayMs,
|
|
265
|
+
maxDelayMs: policy.maxDelayMs ?? DEFAULT_RETRY.maxDelayMs,
|
|
266
|
+
retryOn429: policy.retryOn429 ?? DEFAULT_RETRY.retryOn429
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
function isRetryableStatus(status, policy) {
|
|
270
|
+
return RETRYABLE_STATUS.has(status) || policy.retryOn429 && status === 429;
|
|
271
|
+
}
|
|
272
|
+
/** Delay before the next attempt: the server's `Retry-After` when it sent one, else backoff. */
|
|
273
|
+
function retryDelay(retryAfter, attempt, policy) {
|
|
274
|
+
const retryAfterMs = parseRetryAfter(retryAfter);
|
|
275
|
+
return retryAfterMs === null ? backoffDelay(attempt, policy) : Math.min(retryAfterMs, Math.max(policy.maxDelayMs, RETRY_AFTER_CAP_MS));
|
|
276
|
+
}
|
|
277
|
+
/** A `Retry-After` value (seconds or HTTP-date) in ms; null when missing or unparseable. */
|
|
278
|
+
function parseRetryAfter(headerValue) {
|
|
279
|
+
if (!headerValue) return null;
|
|
280
|
+
const seconds = Number(headerValue);
|
|
281
|
+
if (Number.isFinite(seconds) && seconds >= 0) return seconds * 1e3;
|
|
282
|
+
const dateMs = Date.parse(headerValue);
|
|
283
|
+
if (Number.isFinite(dateMs)) {
|
|
284
|
+
const delta = dateMs - Date.now();
|
|
285
|
+
return delta > 0 ? delta : 0;
|
|
286
|
+
}
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
function backoffDelay(attempt, policy) {
|
|
290
|
+
const exponential = policy.baseDelayMs * Math.pow(2, attempt);
|
|
291
|
+
const jitter = Math.random() * policy.baseDelayMs;
|
|
292
|
+
return Math.min(exponential + jitter, policy.maxDelayMs);
|
|
293
|
+
}
|
|
294
|
+
function sleep(ms, signal) {
|
|
295
|
+
return new Promise((resolve, reject) => {
|
|
296
|
+
if (signal?.aborted) {
|
|
297
|
+
reject(new DOMException("Aborted", "AbortError"));
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
const id = setTimeout(() => {
|
|
301
|
+
signal?.removeEventListener("abort", onAbort);
|
|
302
|
+
resolve();
|
|
303
|
+
}, ms);
|
|
304
|
+
const onAbort = () => {
|
|
305
|
+
clearTimeout(id);
|
|
306
|
+
reject(new DOMException("Aborted", "AbortError"));
|
|
307
|
+
};
|
|
308
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
309
|
+
});
|
|
310
|
+
}
|
|
209
311
|
/**
|
|
210
312
|
* Case-insensitive field reads for wire payloads.
|
|
211
313
|
*
|
|
@@ -301,93 +403,6 @@ function trimTrailing(value, char) {
|
|
|
301
403
|
while (end > 0 && value[end - 1] === char) end--;
|
|
302
404
|
return value.slice(0, end);
|
|
303
405
|
}
|
|
304
|
-
var warned = /* @__PURE__ */ new Set();
|
|
305
|
-
/** Log `message` the first time `key` is seen: what it reports doesn't change per call. */
|
|
306
|
-
function warnOnce(key, message) {
|
|
307
|
-
if (warned.has(key)) return;
|
|
308
|
-
warned.add(key);
|
|
309
|
-
getLogger().warn(message);
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* True only in a real browser, where an API key in the config is exposed to users. jsdom defines
|
|
313
|
-
* `window` too, so Node is ruled out by `process.versions.node`, and by jsdom's user-agent marker
|
|
314
|
-
* for setups that hide `process`.
|
|
315
|
-
*/
|
|
316
|
-
function isRealBrowser() {
|
|
317
|
-
if (typeof window === "undefined") return false;
|
|
318
|
-
if (globalThis.process?.versions?.node != null) return false;
|
|
319
|
-
const nav = globalThis.navigator;
|
|
320
|
-
const userAgent = typeof nav?.userAgent === "string" ? nav.userAgent : "";
|
|
321
|
-
if (/jsdom/i.test(userAgent)) return false;
|
|
322
|
-
return true;
|
|
323
|
-
}
|
|
324
|
-
function warnIfClientSide(functionName, suppress) {
|
|
325
|
-
if (suppress || !isRealBrowser()) return;
|
|
326
|
-
warnOnce(`client-side:${functionName}`, `Warning: ${functionName} is running on the client side. For better performance and security, consider running this on the server side.`);
|
|
327
|
-
}
|
|
328
|
-
/** `serverUrl` as `validateServerUrl` returns it: no trailing slash. */
|
|
329
|
-
function buildUrl(endpoint, serverUrl) {
|
|
330
|
-
return `${serverUrl}/${endpoint.replace(/^\/+/, "")}`;
|
|
331
|
-
}
|
|
332
|
-
function isLocalhost(serverUrl) {
|
|
333
|
-
const hostname = new URL(serverUrl).hostname.toLowerCase();
|
|
334
|
-
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]";
|
|
335
|
-
}
|
|
336
|
-
var DEFAULT_API_KEY_HEADER = "RhinoComputeKey";
|
|
337
|
-
/**
|
|
338
|
-
* Caller headers plus credentials. Every request to the server builds its headers here,
|
|
339
|
-
* so a liveness probe authenticates exactly like the solve it gates.
|
|
340
|
-
*/
|
|
341
|
-
function buildAuthHeaders(auth) {
|
|
342
|
-
return assertSendable(mergeUnder(auth.headers, credentialHeaders(auth)));
|
|
343
|
-
}
|
|
344
|
-
function buildHeaders(requestId, config) {
|
|
345
|
-
const headers = assertSendable(mergeUnder(config.headers, {
|
|
346
|
-
...credentialHeaders(config),
|
|
347
|
-
"X-Request-ID": requestId,
|
|
348
|
-
"Content-Type": "application/json"
|
|
349
|
-
}));
|
|
350
|
-
if (!config.apiKey && !config.authToken && !isLocalhost(config.serverUrl)) warnOnce(`no-auth:${config.serverUrl}`, `[Compute] Request [${requestId}] targets remote server (${config.serverUrl}) but no API key or auth token is configured. Requests may fail or be rate-limited. (warned once per server)`);
|
|
351
|
-
return headers;
|
|
352
|
-
}
|
|
353
|
-
/** `headers` with a JSON `Content-Type` that replaces one of any casing already there. */
|
|
354
|
-
function withJsonContentType(headers) {
|
|
355
|
-
return mergeUnder(headers, { "Content-Type": "application/json" });
|
|
356
|
-
}
|
|
357
|
-
function credentialHeaders(auth) {
|
|
358
|
-
return {
|
|
359
|
-
...auth.authToken && { Authorization: auth.authToken },
|
|
360
|
-
...auth.apiKey && { [auth.apiKeyHeader ?? DEFAULT_API_KEY_HEADER]: auth.apiKey }
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* Header names are case-insensitive and fetch joins duplicates, so a caller key
|
|
365
|
-
* matching a transport key in any case is dropped rather than sent alongside it.
|
|
366
|
-
*/
|
|
367
|
-
function mergeUnder(caller, transport) {
|
|
368
|
-
const taken = new Set(Object.keys(transport).map((name) => name.toLowerCase()));
|
|
369
|
-
const kept = Object.entries(caller ?? {}).filter(([name]) => !taken.has(name.toLowerCase()));
|
|
370
|
-
return {
|
|
371
|
-
...Object.fromEntries(kept),
|
|
372
|
-
...transport
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
/**
|
|
376
|
-
* Left to fetch, a bad value becomes a retried TypeError that quotes it, and the value may be the
|
|
377
|
-
* API key. `Headers` throws the same message, so its error is not kept as the cause.
|
|
378
|
-
*/
|
|
379
|
-
function assertSendable(headers) {
|
|
380
|
-
const check = new Headers();
|
|
381
|
-
for (const [name, value] of Object.entries(headers)) try {
|
|
382
|
-
check.set(name, value);
|
|
383
|
-
} catch {
|
|
384
|
-
throw new ComputeError(`Header "${name}" has an invalid name or value`, ErrorCodes.INVALID_CONFIG, { context: { header: name } });
|
|
385
|
-
}
|
|
386
|
-
return headers;
|
|
387
|
-
}
|
|
388
|
-
function generateRequestId() {
|
|
389
|
-
return `${Date.now()}-${Math.random().toString(36).substring(2, 11)}`;
|
|
390
|
-
}
|
|
391
406
|
function getNodeBuffer() {
|
|
392
407
|
const buf = globalThis.Buffer;
|
|
393
408
|
return typeof buf === "function" ? buf : void 0;
|
|
@@ -523,11 +538,18 @@ async function readBodyText(response, limit = Infinity) {
|
|
|
523
538
|
truncated: false
|
|
524
539
|
};
|
|
525
540
|
}
|
|
541
|
+
/** Routing outcomes the VektorNode fork reports in `Server-Timing`; the parser drops any other. */
|
|
542
|
+
var AFFINITY_OUTCOMES = [
|
|
543
|
+
"hit",
|
|
544
|
+
"claimed",
|
|
545
|
+
"spilled",
|
|
546
|
+
"none"
|
|
547
|
+
];
|
|
526
548
|
/**
|
|
527
549
|
* Parse a W3C Server Timing header, as the solve endpoint emits it:
|
|
528
550
|
* `decode;dur=3, solve;dur=120, gh;dur=110, encode;dur=8, recomputed;desc="4/97"`, or
|
|
529
|
-
* `cache;desc="hit"` when the server answered from its result cache.
|
|
530
|
-
* recognised
|
|
551
|
+
* `cache;desc="hit"` when the server answered from its result cache. A proxy's `affinity` can
|
|
552
|
+
* arrive alone, with no durations. Null when it carries no recognised entry.
|
|
531
553
|
*/
|
|
532
554
|
function parseServerTiming(headerValue) {
|
|
533
555
|
if (!headerValue) return null;
|
|
@@ -552,10 +574,18 @@ function parseServerTiming(headerValue) {
|
|
|
552
574
|
} else if (name === "cache" && param(params, "desc") === "hit") {
|
|
553
575
|
timing.cacheHit = true;
|
|
554
576
|
sawMetric = true;
|
|
577
|
+
} else if (name === "affinity") {
|
|
578
|
+
const outcome = param(params, "desc");
|
|
579
|
+
if (!isAffinity(outcome)) continue;
|
|
580
|
+
timing.affinity = outcome;
|
|
581
|
+
sawMetric = true;
|
|
555
582
|
}
|
|
556
583
|
}
|
|
557
584
|
return sawMetric ? timing : null;
|
|
558
585
|
}
|
|
586
|
+
function isAffinity(value) {
|
|
587
|
+
return AFFINITY_OUTCOMES.includes(value);
|
|
588
|
+
}
|
|
559
589
|
function param(params, key) {
|
|
560
590
|
for (const p of params) {
|
|
561
591
|
const [k, ...v] = p.split("=");
|
|
@@ -2014,6 +2044,7 @@ function applyOptionalComputeSettings(arglist, options) {
|
|
|
2014
2044
|
if (options.absolutetolerance != null) arglist.absolutetolerance = options.absolutetolerance;
|
|
2015
2045
|
if (options.dataversion != null) arglist.dataversion = options.dataversion;
|
|
2016
2046
|
if (options.selvaevents != null) arglist.selvaevents = options.selvaevents;
|
|
2047
|
+
if (options.solveMode === "preview") arglist.selvamode = "preview";
|
|
2017
2048
|
}
|
|
2018
2049
|
/**
|
|
2019
2050
|
* `obj[key] = value` for a key taken from a wire payload. Assigning `__proto__` would call the
|
|
@@ -2733,6 +2764,13 @@ var ResponseCache = class {
|
|
|
2733
2764
|
this.bytes -= entry.sizeBytes;
|
|
2734
2765
|
}
|
|
2735
2766
|
};
|
|
2767
|
+
/**
|
|
2768
|
+
* Appends the mode to a solve key. A preview response has no deferred files, so it must never
|
|
2769
|
+
* share a cache or single-flight entry with a full solve of the same inputs.
|
|
2770
|
+
*/
|
|
2771
|
+
function withSolveMode(key, mode) {
|
|
2772
|
+
return mode === "preview" ? `${key}:preview` : key;
|
|
2773
|
+
}
|
|
2736
2774
|
var nodeCrypto = globalThis.process?.getBuiltinModule?.("node:crypto");
|
|
2737
2775
|
/** Lowercase hex SHA-256 of `input`. */
|
|
2738
2776
|
function sha256Hex(input) {
|
|
@@ -3126,6 +3164,7 @@ var SolveScheduler = class {
|
|
|
3126
3164
|
lastStateSeq = 0;
|
|
3127
3165
|
disposed = false;
|
|
3128
3166
|
constructor(executor, baseConfig, options = {}) {
|
|
3167
|
+
assertSessionId(baseConfig.sessionId);
|
|
3129
3168
|
this.executor = executor;
|
|
3130
3169
|
this.baseConfig = baseConfig;
|
|
3131
3170
|
this.mode = options.mode ?? "latest-wins";
|
|
@@ -3221,10 +3260,15 @@ var SolveScheduler = class {
|
|
|
3221
3260
|
/** {@link solve}, also resolving with whether this call hit the cache and how long it took. */
|
|
3222
3261
|
solveDetailed(definition, dataTree, options) {
|
|
3223
3262
|
if (this.disposed) return Promise.reject(new ComputeError("SolveScheduler has been disposed and cannot be used", ErrorCodes.INVALID_STATE));
|
|
3263
|
+
try {
|
|
3264
|
+
assertSessionId(options?.sessionId);
|
|
3265
|
+
} catch (error) {
|
|
3266
|
+
return Promise.reject(error);
|
|
3267
|
+
}
|
|
3224
3268
|
const hashes = new SolveInputHashes(() => this.hashDefinitionMemo(definition), dataTree);
|
|
3225
3269
|
let key = "";
|
|
3226
3270
|
if (this.cache.enabled || this.onStart || this.onSettle || this.onSuperseded) try {
|
|
3227
|
-
key = hashes.key;
|
|
3271
|
+
key = withSolveMode(hashes.key, options?.solveMode);
|
|
3228
3272
|
} catch (error) {
|
|
3229
3273
|
return Promise.reject(new ComputeError("Solve input could not be hashed", ErrorCodes.INVALID_INPUT, { originalError: error }));
|
|
3230
3274
|
}
|
|
@@ -3268,6 +3312,9 @@ var SolveScheduler = class {
|
|
|
3268
3312
|
reject,
|
|
3269
3313
|
externalSignal: options?.signal,
|
|
3270
3314
|
selvaevents: options?.selvaevents,
|
|
3315
|
+
sessionId: options?.sessionId,
|
|
3316
|
+
solveMode: options?.solveMode,
|
|
3317
|
+
headers: options?.headers,
|
|
3271
3318
|
onServerTiming: options?.onServerTiming
|
|
3272
3319
|
};
|
|
3273
3320
|
if (item.externalSignal) {
|
|
@@ -3377,7 +3424,10 @@ var SolveScheduler = class {
|
|
|
3377
3424
|
signal: controller.signal,
|
|
3378
3425
|
...this.timeoutMs !== void 0 && { timeoutMs: this.timeoutMs },
|
|
3379
3426
|
...this.retry !== void 0 && { retry: this.retry },
|
|
3380
|
-
...item.selvaevents !== void 0 && { selvaevents: item.selvaevents }
|
|
3427
|
+
...item.selvaevents !== void 0 && { selvaevents: item.selvaevents },
|
|
3428
|
+
...item.sessionId !== void 0 && { sessionId: item.sessionId },
|
|
3429
|
+
...item.solveMode !== void 0 && { solveMode: item.solveMode },
|
|
3430
|
+
...item.headers !== void 0 && { headers: mergeUnder(this.baseConfig.headers, item.headers) }
|
|
3381
3431
|
};
|
|
3382
3432
|
const callTiming = item.onServerTiming;
|
|
3383
3433
|
if (callTiming) {
|
|
@@ -3625,6 +3675,7 @@ var GrasshopperClient = class GrasshopperClient {
|
|
|
3625
3675
|
*/
|
|
3626
3676
|
static CREATE_PROBE_TIMEOUT_MS = 2e3;
|
|
3627
3677
|
constructor(config) {
|
|
3678
|
+
assertSessionId(config.sessionId);
|
|
3628
3679
|
this.config = {
|
|
3629
3680
|
...config,
|
|
3630
3681
|
serverUrl: validateServerUrl(config.serverUrl),
|
|
@@ -3714,12 +3765,16 @@ var GrasshopperClient = class GrasshopperClient {
|
|
|
3714
3765
|
if (typeof definition === "string" && !definition.trim()) throw new ComputeError("Definition URL/content is required", ErrorCodes.INVALID_INPUT, { context: { receivedUrl: definition } });
|
|
3715
3766
|
else if (definition instanceof Uint8Array && definition.length === 0) throw new ComputeError("Definition content is empty", ErrorCodes.INVALID_INPUT);
|
|
3716
3767
|
else if (isDefinitionRef(definition) && !definition.key.trim()) throw new ComputeError("DefinitionRef key is empty", ErrorCodes.INVALID_INPUT);
|
|
3768
|
+
assertSessionId(options?.sessionId);
|
|
3717
3769
|
const result = await solveGrasshopperDefinition(dataTree, definition, {
|
|
3718
3770
|
...this.config,
|
|
3719
3771
|
...options?.signal !== void 0 && { signal: options.signal },
|
|
3720
3772
|
...options?.timeoutMs !== void 0 && { timeoutMs: options.timeoutMs },
|
|
3721
3773
|
...options?.retry !== void 0 && { retry: options.retry },
|
|
3722
|
-
...options?.selvaevents !== void 0 && { selvaevents: options.selvaevents }
|
|
3774
|
+
...options?.selvaevents !== void 0 && { selvaevents: options.selvaevents },
|
|
3775
|
+
...options?.sessionId !== void 0 && { sessionId: options.sessionId },
|
|
3776
|
+
...options?.solveMode !== void 0 && { solveMode: options.solveMode },
|
|
3777
|
+
...options?.headers !== void 0 && { headers: mergeUnder(this.config.headers, options.headers) }
|
|
3723
3778
|
});
|
|
3724
3779
|
const solveErrors = readField(result, "errors");
|
|
3725
3780
|
if (Array.isArray(solveErrors) && solveErrors.length > 0) throw new ComputeError(solveErrors.map(String).join("; ") || "Computation failed", ErrorCodes.COMPUTATION_ERROR, { context: {
|
|
@@ -4386,6 +4441,6 @@ var TreeBuilder = class TreeBuilder {
|
|
|
4386
4441
|
return result;
|
|
4387
4442
|
}
|
|
4388
4443
|
};
|
|
4389
|
-
export { normalizeUISchemaCasing as a,
|
|
4444
|
+
export { normalizeUISchemaCasing as a, withSolveMode as c, classifyProbeFailure as d, decodeBase64ToBinary as f, subFolderSegments as g, isDefinitionRef as h, TreeBuilder as i, ComputeError as l, enableDebugLogging as m, GrasshopperClient as n, readSchemaResults as o, downloadFileDataByRoot as p, GrasshopperResponseProcessor as r, stableStringify as s, ComputeServerStats as t, ErrorCodes as u };
|
|
4390
4445
|
|
|
4391
4446
|
//# sourceMappingURL=grasshopper.js.map
|