@selvajs/selva 4.20.1-beta.3 → 4.20.1-beta.5
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/version.json +1 -1
- package/build/client/_app/version.json.br +0 -0
- package/build/client/_app/version.json.gz +0 -0
- package/build/runtime-meta.json +1 -1
- package/build/server/.vite/manifest.json +1 -0
- 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 +204 -160
- package/build/server/chunks/grasshopper.js.map +1 -1
- package/build/server/chunks/instance.js +3 -3
- package/build/server/chunks/internal.js +1 -1
- package/build/server/chunks/package.js +1 -1
- package/build/server/chunks/package.js.map +1 -1
- package/build/server/chunks/providers.server.js +77 -52
- package/build/server/chunks/providers.server.js.map +1 -1
- package/build/server/chunks/solve.server.js +27 -1
- package/build/server/chunks/solve.server.js.map +1 -1
- package/build/server/entries/hooks.server.js +21 -9
- package/build/server/entries/hooks.server.js.map +1 -1
- package/build/server/entries/pages/library/_guid_/_page.server.ts.js +2 -2
- package/build/server/entries/pages/library/_guid_/_page.server.ts.js.map +1 -1
- package/package.json +8 -8
|
@@ -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("=");
|
|
@@ -3126,6 +3156,7 @@ var SolveScheduler = class {
|
|
|
3126
3156
|
lastStateSeq = 0;
|
|
3127
3157
|
disposed = false;
|
|
3128
3158
|
constructor(executor, baseConfig, options = {}) {
|
|
3159
|
+
assertSessionId(baseConfig.sessionId);
|
|
3129
3160
|
this.executor = executor;
|
|
3130
3161
|
this.baseConfig = baseConfig;
|
|
3131
3162
|
this.mode = options.mode ?? "latest-wins";
|
|
@@ -3221,6 +3252,11 @@ var SolveScheduler = class {
|
|
|
3221
3252
|
/** {@link solve}, also resolving with whether this call hit the cache and how long it took. */
|
|
3222
3253
|
solveDetailed(definition, dataTree, options) {
|
|
3223
3254
|
if (this.disposed) return Promise.reject(new ComputeError("SolveScheduler has been disposed and cannot be used", ErrorCodes.INVALID_STATE));
|
|
3255
|
+
try {
|
|
3256
|
+
assertSessionId(options?.sessionId);
|
|
3257
|
+
} catch (error) {
|
|
3258
|
+
return Promise.reject(error);
|
|
3259
|
+
}
|
|
3224
3260
|
const hashes = new SolveInputHashes(() => this.hashDefinitionMemo(definition), dataTree);
|
|
3225
3261
|
let key = "";
|
|
3226
3262
|
if (this.cache.enabled || this.onStart || this.onSettle || this.onSuperseded) try {
|
|
@@ -3268,6 +3304,8 @@ var SolveScheduler = class {
|
|
|
3268
3304
|
reject,
|
|
3269
3305
|
externalSignal: options?.signal,
|
|
3270
3306
|
selvaevents: options?.selvaevents,
|
|
3307
|
+
sessionId: options?.sessionId,
|
|
3308
|
+
headers: options?.headers,
|
|
3271
3309
|
onServerTiming: options?.onServerTiming
|
|
3272
3310
|
};
|
|
3273
3311
|
if (item.externalSignal) {
|
|
@@ -3377,7 +3415,9 @@ var SolveScheduler = class {
|
|
|
3377
3415
|
signal: controller.signal,
|
|
3378
3416
|
...this.timeoutMs !== void 0 && { timeoutMs: this.timeoutMs },
|
|
3379
3417
|
...this.retry !== void 0 && { retry: this.retry },
|
|
3380
|
-
...item.selvaevents !== void 0 && { selvaevents: item.selvaevents }
|
|
3418
|
+
...item.selvaevents !== void 0 && { selvaevents: item.selvaevents },
|
|
3419
|
+
...item.sessionId !== void 0 && { sessionId: item.sessionId },
|
|
3420
|
+
...item.headers !== void 0 && { headers: mergeUnder(this.baseConfig.headers, item.headers) }
|
|
3381
3421
|
};
|
|
3382
3422
|
const callTiming = item.onServerTiming;
|
|
3383
3423
|
if (callTiming) {
|
|
@@ -3625,6 +3665,7 @@ var GrasshopperClient = class GrasshopperClient {
|
|
|
3625
3665
|
*/
|
|
3626
3666
|
static CREATE_PROBE_TIMEOUT_MS = 2e3;
|
|
3627
3667
|
constructor(config) {
|
|
3668
|
+
assertSessionId(config.sessionId);
|
|
3628
3669
|
this.config = {
|
|
3629
3670
|
...config,
|
|
3630
3671
|
serverUrl: validateServerUrl(config.serverUrl),
|
|
@@ -3714,12 +3755,15 @@ var GrasshopperClient = class GrasshopperClient {
|
|
|
3714
3755
|
if (typeof definition === "string" && !definition.trim()) throw new ComputeError("Definition URL/content is required", ErrorCodes.INVALID_INPUT, { context: { receivedUrl: definition } });
|
|
3715
3756
|
else if (definition instanceof Uint8Array && definition.length === 0) throw new ComputeError("Definition content is empty", ErrorCodes.INVALID_INPUT);
|
|
3716
3757
|
else if (isDefinitionRef(definition) && !definition.key.trim()) throw new ComputeError("DefinitionRef key is empty", ErrorCodes.INVALID_INPUT);
|
|
3758
|
+
assertSessionId(options?.sessionId);
|
|
3717
3759
|
const result = await solveGrasshopperDefinition(dataTree, definition, {
|
|
3718
3760
|
...this.config,
|
|
3719
3761
|
...options?.signal !== void 0 && { signal: options.signal },
|
|
3720
3762
|
...options?.timeoutMs !== void 0 && { timeoutMs: options.timeoutMs },
|
|
3721
3763
|
...options?.retry !== void 0 && { retry: options.retry },
|
|
3722
|
-
...options?.selvaevents !== void 0 && { selvaevents: options.selvaevents }
|
|
3764
|
+
...options?.selvaevents !== void 0 && { selvaevents: options.selvaevents },
|
|
3765
|
+
...options?.sessionId !== void 0 && { sessionId: options.sessionId },
|
|
3766
|
+
...options?.headers !== void 0 && { headers: mergeUnder(this.config.headers, options.headers) }
|
|
3723
3767
|
});
|
|
3724
3768
|
const solveErrors = readField(result, "errors");
|
|
3725
3769
|
if (Array.isArray(solveErrors) && solveErrors.length > 0) throw new ComputeError(solveErrors.map(String).join("; ") || "Computation failed", ErrorCodes.COMPUTATION_ERROR, { context: {
|