@selvajs/solve 2.0.0-beta.9 → 2.0.1
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/README.md +17 -11
- package/dist/abort-CNJ8Sn4g.js +13 -0
- package/dist/abort-CNJ8Sn4g.js.map +1 -0
- package/dist/client.d.ts +34 -135
- package/dist/client.js +968 -1
- package/dist/client.js.map +1 -1
- package/dist/{outcome-DsNmx27P.d.ts → outcome-Bk9mnMi0.d.ts} +9 -28
- package/dist/outcome-DNrffAXp.js +169 -0
- package/dist/outcome-DNrffAXp.js.map +1 -0
- package/dist/server.d.ts +100 -227
- package/dist/server.js +1017 -1
- package/dist/server.js.map +1 -1
- package/dist/shared.d.ts +2 -2
- package/dist/shared.js +1 -1
- package/package.json +16 -41
- package/dist/client.cjs +0 -2
- package/dist/client.cjs.map +0 -1
- package/dist/client.d.cts +0 -429
- package/dist/outcome-BOrAeRAQ.js +0 -2
- package/dist/outcome-BOrAeRAQ.js.map +0 -1
- package/dist/outcome-DUHQoZqq.cjs +0 -2
- package/dist/outcome-DUHQoZqq.cjs.map +0 -1
- package/dist/outcome-DsNmx27P.d.cts +0 -92
- package/dist/server.cjs +0 -2
- package/dist/server.cjs.map +0 -1
- package/dist/server.d.cts +0 -416
- package/dist/shared.cjs +0 -1
- package/dist/shared.d.cts +0 -3
- package/dist/solve-input-CUjVGYPC.d.cts +0 -11
package/dist/server.d.ts
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
import { t as SolveInput } from "./solve-input-CUjVGYPC.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { UISchema } from "@selvajs/schemas";
|
|
3
|
+
import { GrasshopperClient, GrasshopperComputeResponse, SelvaEventTarget, SolveScheduler } from "@selvajs/compute/grasshopper";
|
|
4
|
+
import { DefinitionRef, DefinitionRef as DefinitionRef$1, ServerTiming, SolveDefinition } from "@selvajs/compute/core";
|
|
5
|
+
/** Rhino.Compute's own default `--timeout`, for a server that can't report its own. */
|
|
6
|
+
export declare const DEFAULT_SOLVE_DEADLINE_MS = 100000;
|
|
5
7
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
+
* Ceiling on any solve deadline, whatever the server reports. Bounds how long a request, its
|
|
9
|
+
* live-event token and a delegated session stay open; past an hour a solve belongs in a job.
|
|
8
10
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
export declare const MAX_SOLVE_DEADLINE_MS: number;
|
|
12
|
+
/** What Selva holds a solve to on one compute server. */
|
|
13
|
+
interface SolveLimits {
|
|
14
|
+
solveDeadlineMs: number;
|
|
15
|
+
/** `null` when the server didn't say: its own 413 is then the only check. */
|
|
16
|
+
maxRequestBytes: number | null;
|
|
17
|
+
/**
|
|
18
|
+
* Send a pointer to the server's cached definition instead of the `.gh`. Only on a server that
|
|
19
|
+
* answers a stale pointer with `definition_not_cached`: one that doesn't returns empty geometry.
|
|
20
|
+
*/
|
|
21
|
+
reuseDefinitionCache: boolean;
|
|
22
|
+
/** The server's deployment (`ServerLimits.deploymentId`); another one may solve differently. */
|
|
23
|
+
deploymentId: string | null;
|
|
24
|
+
}
|
|
12
25
|
/** Minimal resolved-server shape the cache needs (a subset of the app's `ComputeServerConfig`). */
|
|
13
26
|
interface ResolvedServer {
|
|
14
27
|
id: string;
|
|
@@ -16,10 +29,11 @@ interface ResolvedServer {
|
|
|
16
29
|
/** Sent as the `RhinoComputeKey` header. */
|
|
17
30
|
apiKey?: string;
|
|
18
31
|
}
|
|
19
|
-
export declare function serverIdentity(server: Pick<ResolvedServer, 'id'>): ServerIdentity;
|
|
20
32
|
interface CachedClient {
|
|
21
33
|
client: GrasshopperClient;
|
|
22
34
|
scheduler: SolveScheduler;
|
|
35
|
+
/** Read from the server when the client was built; a changed server rebuilds the client. */
|
|
36
|
+
limits: SolveLimits;
|
|
23
37
|
}
|
|
24
38
|
/**
|
|
25
39
|
* Debug verbosity: `false` is silent, `true` gives concise cache/timing logs
|
|
@@ -27,68 +41,6 @@ interface CachedClient {
|
|
|
27
41
|
* dumps (incl. geometry) — a superset of `true`, not an independent setting.
|
|
28
42
|
*/
|
|
29
43
|
type ClientCacheDebug = boolean | 'verbose';
|
|
30
|
-
/** Config injected by the consuming app, so this module stays env-agnostic and testable. */
|
|
31
|
-
interface ClientCacheConfig {
|
|
32
|
-
/** Per-solve timeout forwarded to the scheduler (`ComputeLimits.solveDeadlineMs`). */
|
|
33
|
-
solveDeadlineMs: number;
|
|
34
|
-
cachesolve: boolean;
|
|
35
|
-
/** Reference large definitions by server cache key instead of re-uploading. */
|
|
36
|
-
reuseServerDefinitionCache: boolean;
|
|
37
|
-
/**
|
|
38
|
-
* Max solves that may wait in the FIFO queue, excluding in-flight solves
|
|
39
|
-
* (capped at `maxConcurrent`, itself driven by the server's probed child
|
|
40
|
-
* count). `0` = unbounded (`ComputeLimits.computeMaxQueueDepth`); a full
|
|
41
|
-
* queue rejects new solves with `QUEUE_FULL`.
|
|
42
|
-
*/
|
|
43
|
-
maxQueueDepth: number;
|
|
44
|
-
/**
|
|
45
|
-
* Max ms a solve may sit queued before executing; `0` = no deadline
|
|
46
|
-
* (`ComputeLimits.computeQueueWaitMs`). Too long a wait rejects with
|
|
47
|
-
* `QUEUE_TIMEOUT`.
|
|
48
|
-
*/
|
|
49
|
-
queueWaitMs: number;
|
|
50
|
-
/**
|
|
51
|
-
* Byte budget for this client's in-process solve cache. Applies per warm
|
|
52
|
-
* client — worst-case heap is this × `maxWarmComputeServers`. `0` disables
|
|
53
|
-
* the cache (`ComputeLimits.computeSolveCacheBytes`, env `COMPUTE_SOLVE_CACHE_MB`).
|
|
54
|
-
*/
|
|
55
|
-
responseCacheMaxBytes: number;
|
|
56
|
-
/**
|
|
57
|
-
* Largest compute response body read; past it the download is cancelled (`too_large`).
|
|
58
|
-
* Default: no limit.
|
|
59
|
-
*/
|
|
60
|
-
maxResponseBytes?: number;
|
|
61
|
-
debug: ClientCacheDebug;
|
|
62
|
-
/** Max distinct warm compute servers before the LRU evicts the oldest. Default 16. */
|
|
63
|
-
maxWarmComputeServers?: number;
|
|
64
|
-
/** Sink for the debug lines. `onDebugLog` only fires when `debug` is not `false`. */
|
|
65
|
-
onDebugLog?: (message: string) => void;
|
|
66
|
-
}
|
|
67
|
-
interface ClientCache {
|
|
68
|
-
/**
|
|
69
|
-
* Get (or create) the warm client + scheduler for a resolved compute server,
|
|
70
|
-
* keyed by its `id`. `definitionGuid`, when present, is stamped as the
|
|
71
|
-
* `X-Selva-Definition` header on this client's outbound solve/IO requests —
|
|
72
|
-
* inert routing/telemetry metadata until a pool router exists.
|
|
73
|
-
*/
|
|
74
|
-
getClient(server: ResolvedServer, opts?: {
|
|
75
|
-
definitionGuid?: string;
|
|
76
|
-
}): Promise<CachedClient>;
|
|
77
|
-
/** Dispose and drop the warm client for `id`, so the next request rebuilds against fresh connection details. */
|
|
78
|
-
evict(id: string | ServerIdentity): void;
|
|
79
|
-
/** Solve-cache counters summed across every warm client. Counters die with the client that owns them, so totals can fall over time. */
|
|
80
|
-
solveCacheStats(): SolveCacheStats;
|
|
81
|
-
/**
|
|
82
|
-
* Drop every retained solve result, keeping the warm clients (and their
|
|
83
|
-
* connections and server-side definition pointers) intact. Nothing expires
|
|
84
|
-
* these on its own — the byte budget is the only other pressure — so this is
|
|
85
|
-
* the operator's release valve when a definition's inputs no longer describe
|
|
86
|
-
* its output, e.g. it reads an external source that has since changed.
|
|
87
|
-
*/
|
|
88
|
-
clearSolveCaches(): void;
|
|
89
|
-
/** Dispose every warm client. Test seam / shutdown hook. */
|
|
90
|
-
disposeAll(): void;
|
|
91
|
-
}
|
|
92
44
|
interface SolveCacheStats {
|
|
93
45
|
warmClients: number;
|
|
94
46
|
entries: number;
|
|
@@ -98,7 +50,6 @@ interface SolveCacheStats {
|
|
|
98
50
|
/** Entries dropped under size/byte pressure (not replacement or manual clears). */
|
|
99
51
|
evictions: number;
|
|
100
52
|
}
|
|
101
|
-
export declare function createClientCache(config: ClientCacheConfig): ClientCache;
|
|
102
53
|
/**
|
|
103
54
|
* In-process cache of `.gh` definition bytes, keyed by immutable **version id**.
|
|
104
55
|
*
|
|
@@ -131,7 +82,7 @@ interface ByteRefOutcome {
|
|
|
131
82
|
/** A definition reference shaped for `@selvajs/compute`'s `DefinitionRef`. */
|
|
132
83
|
interface ByteCacheRef {
|
|
133
84
|
key: string;
|
|
134
|
-
load: () => Promise<Uint8Array>;
|
|
85
|
+
load: (signal?: AbortSignal) => Promise<Uint8Array>;
|
|
135
86
|
outcome: ByteRefOutcome;
|
|
136
87
|
}
|
|
137
88
|
interface ByteCacheStats {
|
|
@@ -141,65 +92,23 @@ interface ByteCacheStats {
|
|
|
141
92
|
entries: number;
|
|
142
93
|
bytes: number;
|
|
143
94
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
95
|
+
/** A pre-solve prep sub-phase: `[label, ms]`, surfaced as a `p_*` Server-Timing entry. */
|
|
96
|
+
type PrepMark = [string, number];
|
|
97
|
+
interface CacheVerdict {
|
|
98
|
+
fromCache: boolean;
|
|
99
|
+
definitionReuploaded?: boolean;
|
|
148
100
|
}
|
|
149
101
|
/**
|
|
150
|
-
*
|
|
151
|
-
*
|
|
102
|
+
* skipped = scheduler never materialized bytes (pointer-known solve, the whole point of this
|
|
103
|
+
* path); hit = warm byte cache; miss = fell through to storage.
|
|
152
104
|
*/
|
|
153
|
-
|
|
105
|
+
type DefBytesVerdict = 'skipped' | 'hit' | 'miss';
|
|
154
106
|
/** Compute-response contract version. Bump (and document the change) whenever the envelope's shape changes in a way a consumer could observe. */
|
|
155
107
|
export declare const COMPUTE_CONTRACT_VERSION: 1;
|
|
156
108
|
export declare const COMPUTE_VERSION_HEADER = "X-Selva-Compute-Version";
|
|
157
|
-
|
|
158
|
-
interface SolvePipelineArgs {
|
|
159
|
-
/**
|
|
160
|
-
* Raw `.gh` bytes, or a byte-cache `DefinitionRef` whose bytes the scheduler
|
|
161
|
-
* materializes only when an upload is unavoidable — a pointer-known solve
|
|
162
|
-
* moves zero bytes.
|
|
163
|
-
*/
|
|
164
|
-
definitionSource: SolveDefinition$1;
|
|
165
|
-
/** Mutable load outcome for a `DefinitionRef` source, so the `def_bytes` Server-Timing verdict can be emitted. Omit for raw-bytes solves. */
|
|
166
|
-
byteRefOutcome?: ByteRefOutcome;
|
|
167
|
-
/** Persisted input params; only those with a `paramType` are sent to the solve. */
|
|
168
|
-
inputs: PipelineInput[];
|
|
169
|
-
/**
|
|
170
|
-
* A tree the caller already built with {@link buildSolveInputTree}; skips the
|
|
171
|
-
* pipeline's own build and solves this object directly.
|
|
172
|
-
*
|
|
173
|
-
* A caller coalescing concurrent solves needs this: a single-flight key
|
|
174
|
-
* derived from raw `{inputs, values}` would split two requests that transform
|
|
175
|
-
* to the same tree, which is the identity the scheduler actually caches on.
|
|
176
|
-
*/
|
|
177
|
-
inputTree?: DataTree[];
|
|
178
|
-
/** User-chosen values keyed by input id; missing keys fall back to the schema default. */
|
|
179
|
-
values: Record<string, unknown>;
|
|
180
|
-
client: CachedClient;
|
|
181
|
-
responseMaxBytes: number;
|
|
182
|
-
/** Only phrases the timeout message — the scheduler enforces the deadline itself. */
|
|
183
|
-
solveDeadlineMs: number;
|
|
184
|
-
/** Client's `Accept-Encoding`; gzip is applied only when it advertises `gzip`. */
|
|
185
|
-
acceptEncoding: string;
|
|
186
|
-
/** Per-solve live-event callback the compute server hands to the definition; absent when the caller opened no stream. */
|
|
187
|
-
selvaEvents?: SelvaEventTarget;
|
|
188
|
-
/**
|
|
189
|
-
* Forwarded to the scheduler so a client disconnect cancels the upstream
|
|
190
|
-
* compute call. Its `aborted` flag also distinguishes a client disconnect
|
|
191
|
-
* from the scheduler's own deadline firing.
|
|
192
|
-
*/
|
|
193
|
-
signal: AbortSignal;
|
|
194
|
-
/** Wall-clock origin (`performance.now()` at the top of the request) so `load`/`total` phase timings line up with the caller's pre-solve prep. */
|
|
195
|
-
loadStartMs: number;
|
|
196
|
-
/** Pre-solve "load" phase duration the caller already measured (auth + DB + fetch). */
|
|
197
|
-
defLoadMs: number;
|
|
198
|
-
/** Pre-solve prep sub-phase marks (`[label, ms]`), surfaced verbatim as `p_*` Server-Timing entries. */
|
|
199
|
-
prepMarks?: [string, number][];
|
|
200
|
-
}
|
|
201
|
-
/** Phase timings the pipeline measured; the caller uses them for debug logging. */
|
|
109
|
+
/** What the `Server-Timing` header carries for one caller, as data: read this, don't parse that. */
|
|
202
110
|
interface SolvePhaseMetrics {
|
|
111
|
+
defLoadMs: number;
|
|
203
112
|
treeBuildMs: number;
|
|
204
113
|
solveMs: number;
|
|
205
114
|
serializeMs: number;
|
|
@@ -208,6 +117,11 @@ interface SolvePhaseMetrics {
|
|
|
208
117
|
serializedBytes: number;
|
|
209
118
|
/** Null when compression was skipped. */
|
|
210
119
|
compressedBytes: number | null;
|
|
120
|
+
/** The compute server's own timing; null when it reports none. */
|
|
121
|
+
rhino: ServerTiming | null;
|
|
122
|
+
settle: CacheVerdict;
|
|
123
|
+
/** Absent for raw-bytes solves. */
|
|
124
|
+
defBytes?: DefBytesVerdict;
|
|
211
125
|
}
|
|
212
126
|
/** A ready-to-send response: body + headers + the solve result + phase metrics. */
|
|
213
127
|
interface SolveEnvelope {
|
|
@@ -218,20 +132,21 @@ interface SolveEnvelope {
|
|
|
218
132
|
result: GrasshopperComputeResponse;
|
|
219
133
|
metrics: SolvePhaseMetrics;
|
|
220
134
|
}
|
|
135
|
+
/** Whether an `Accept-Encoding` header takes gzip. `gzip;q=0` is a client refusing it. */
|
|
136
|
+
export declare function acceptsGzip(acceptEncoding: string): boolean;
|
|
221
137
|
/**
|
|
222
|
-
* `ok` carries the envelope; every other variant names an expected failure
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
* `durationMs` on error variants is the solve wall time up to the failure, for
|
|
226
|
-
* the metric record.
|
|
138
|
+
* `ok` carries the envelope; every other variant names an expected failure:
|
|
139
|
+
* `SolveEngine.toWebResponse` maps each to a status. `durationMs` on error variants is the solve
|
|
140
|
+
* wall time up to the failure, for the metric record.
|
|
227
141
|
*/
|
|
228
|
-
type
|
|
142
|
+
type SolveEngineOutcome = {
|
|
229
143
|
kind: 'ok';
|
|
230
144
|
envelope: SolveEnvelope;
|
|
231
145
|
solveMs: number;
|
|
232
146
|
errorCount: number;
|
|
233
147
|
warningCount: number;
|
|
234
|
-
} |
|
|
148
|
+
} | SolveFailure;
|
|
149
|
+
type SolveFailure = {
|
|
235
150
|
kind: 'timeout';
|
|
236
151
|
durationMs: number;
|
|
237
152
|
message: string;
|
|
@@ -241,11 +156,21 @@ type SolveOutcome = {
|
|
|
241
156
|
} | {
|
|
242
157
|
kind: 'too_large';
|
|
243
158
|
} |
|
|
244
|
-
/**
|
|
159
|
+
/** The compute server refused the request body (its `RHINO_COMPUTE_MAX_REQUEST_SIZE`). */
|
|
160
|
+
{
|
|
161
|
+
kind: 'request_too_large';
|
|
162
|
+
durationMs: number;
|
|
163
|
+
message: string;
|
|
164
|
+
} |
|
|
165
|
+
/**
|
|
166
|
+
* Retryable: no result, through no fault of the request, and `retryAfterSeconds` is a backoff
|
|
167
|
+
* hint. Scheduler backpressure rejected the solve before it ran (`queue_full`,
|
|
168
|
+
* `queue_timeout`), or its client was shut down under it (`interrupted`).
|
|
169
|
+
*/
|
|
245
170
|
{
|
|
246
171
|
kind: 'shed';
|
|
247
172
|
durationMs: number;
|
|
248
|
-
reason: 'queue_full' | 'queue_timeout';
|
|
173
|
+
reason: 'queue_full' | 'queue_timeout' | 'interrupted';
|
|
249
174
|
retryAfterSeconds: number;
|
|
250
175
|
message: string;
|
|
251
176
|
} | {
|
|
@@ -253,71 +178,12 @@ type SolveOutcome = {
|
|
|
253
178
|
durationMs: number;
|
|
254
179
|
error: unknown;
|
|
255
180
|
};
|
|
256
|
-
export declare function runSolvePipeline(args: SolvePipelineArgs): Promise<SolveOutcome>;
|
|
257
|
-
/**
|
|
258
|
-
* Re-key a coalesced envelope to a single waiter's `Accept-Encoding`.
|
|
259
|
-
*
|
|
260
|
-
* The single-flight coalescer runs ONE pipeline execution for N identical
|
|
261
|
-
* concurrent solves and hands every waiter the same {@link SolveEnvelope},
|
|
262
|
-
* baked from the FIRST caller's `Accept-Encoding`. A later waiter with a
|
|
263
|
-
* different `Accept-Encoding` would otherwise get a body labelled with the
|
|
264
|
-
* wrong encoding — `Vary` can't help here, since it's one shared object, not a
|
|
265
|
-
* cache lookup. Encoding is deliberately left out of the coalesce key so mixed
|
|
266
|
-
* clients still coalesce; this adapts the shared result to each waiter instead.
|
|
267
|
-
*
|
|
268
|
-
* Only the correctness-critical direction is adapted: a gzip envelope served to
|
|
269
|
-
* a non-gzip waiter is gunzipped back to JSON. The reverse (plain JSON to a
|
|
270
|
-
* gzip-capable waiter) is left uncompressed — correct, just not maximally small.
|
|
271
|
-
*/
|
|
272
|
-
export declare function adaptEnvelopeToEncoding(envelope: SolveEnvelope, acceptEncoding: string): {
|
|
273
|
-
body: string | Uint8Array;
|
|
274
|
-
headers: Record<string, string>;
|
|
275
|
-
};
|
|
276
|
-
/** The input tree a solve sends: each input's value, or its schema default when it has none. */
|
|
277
|
-
export declare function buildSolveInputTree(inputs: SolveInput[], values: Record<string, unknown>): DataTree[];
|
|
278
|
-
/**
|
|
279
|
-
* In-process single-flight — dogpile protection for every solve.
|
|
280
|
-
*
|
|
281
|
-
* Always on, not gated behind a result cache being configured: the dogpile is worst
|
|
282
|
-
* when nothing else is caching, since N concurrent identical solves each pay a full
|
|
283
|
-
* Rhino round trip (the scheduler doesn't coalesce in-flight requests itself, and
|
|
284
|
-
* Rhino's `cachesolve` still costs a round trip per repeat). An earlier version
|
|
285
|
-
* gated this on cache config and so disabled it in exactly the deployments most
|
|
286
|
-
* exposed to a cold-key stampede — hot public definition plus a deploy.
|
|
287
|
-
*
|
|
288
|
-
* Per app instance, above `ISolveResultCache`. No cross-instance lease (Redis
|
|
289
|
-
* `SET NX`) yet.
|
|
290
|
-
*
|
|
291
|
-
* The shared promise resolves to one value for every waiter, so `work` must return
|
|
292
|
-
* something safe to share by reference — the solve pipeline's envelope qualifies
|
|
293
|
-
* because the app serializes it per response.
|
|
294
|
-
*/
|
|
295
|
-
interface SolveCacheSingleFlight {
|
|
296
|
-
/**
|
|
297
|
-
* Coalesces concurrent calls under the same key: the first caller runs `work`,
|
|
298
|
-
* later callers for that key await the same promise, and the key frees as soon
|
|
299
|
-
* as it settles.
|
|
300
|
-
*
|
|
301
|
-
* `onWaiterJoined` fires only on the owner's call, only while `work` is still
|
|
302
|
-
* running, each time another caller joins. Ownership changes what the owner's
|
|
303
|
-
* abort signal should mean: a solo run can cancel on its own client's
|
|
304
|
-
* disconnect, but a shared run can't without 499-ing every waiter.
|
|
305
|
-
*/
|
|
306
|
-
run<T>(key: string, work: () => Promise<T>, onWaiterJoined?: () => void): Promise<T>;
|
|
307
|
-
inFlight(): number;
|
|
308
|
-
}
|
|
309
|
-
interface SolveCacheSingleFlightOptions {
|
|
310
|
-
onJoin?: (key: string) => void;
|
|
311
|
-
}
|
|
312
|
-
export declare function createSolveCacheSingleFlight(options?: SolveCacheSingleFlightOptions): SolveCacheSingleFlight;
|
|
313
181
|
/**
|
|
314
182
|
* Subset of `ComputeLimits` (`@selvajs/server/compute`) the engine needs.
|
|
315
183
|
* Pass the resolved object through as-is — extra fields are ignored.
|
|
316
184
|
*/
|
|
317
185
|
interface SolveEngineLimits {
|
|
318
|
-
solveDeadlineMs: number;
|
|
319
186
|
computeResponseMaxBytes: number;
|
|
320
|
-
computeReuseDefinitionCache: boolean;
|
|
321
187
|
computeServerCachesolve: boolean;
|
|
322
188
|
computeMaxQueueDepth: number;
|
|
323
189
|
computeQueueWaitMs: number;
|
|
@@ -326,26 +192,20 @@ interface SolveEngineLimits {
|
|
|
326
192
|
}
|
|
327
193
|
interface SolveEngineOptions {
|
|
328
194
|
limits: SolveEngineLimits;
|
|
329
|
-
|
|
330
|
-
/** Max distinct warm compute servers before the LRU evicts the oldest. Default 16. */
|
|
195
|
+
/** Max distinct warm compute servers before the LRU evicts the oldest. */
|
|
331
196
|
maxWarmComputeServers?: number;
|
|
332
197
|
/** Concise cache/timing logs when truthy; `'verbose'` also dumps full lib-level requests/responses. Default off. */
|
|
333
198
|
debug?: ClientCacheDebug;
|
|
199
|
+
/** Sink for the debug lines. Without it they go nowhere. */
|
|
334
200
|
onDebugLog?: (message: string) => void;
|
|
335
201
|
/** Fired when a caller joins an already-in-flight solve instead of running its own. */
|
|
336
202
|
onSolveCoalesced?: (key: string) => void;
|
|
337
203
|
}
|
|
338
204
|
/**
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
* obtained ahead of time from `engine.definitionRef()` (e.g. to read bytes for
|
|
342
|
-
* schema extraction before solving) is passed through as-is — detected by its
|
|
343
|
-
* `outcome` field, which a plain `DefinitionRef` never has.
|
|
205
|
+
* A `ByteCacheRef` obtained ahead of time from `engine.definitionRef()` (e.g. to
|
|
206
|
+
* read bytes for schema extraction before solving) is passed through as-is.
|
|
344
207
|
*/
|
|
345
|
-
type SolveEngineDefinitionSource = Uint8Array | string | DefinitionRef$1 | ByteCacheRef
|
|
346
|
-
versionId: string;
|
|
347
|
-
load: () => Promise<Uint8Array>;
|
|
348
|
-
};
|
|
208
|
+
type SolveEngineDefinitionSource = Uint8Array | string | DefinitionRef$1 | ByteCacheRef;
|
|
349
209
|
interface SolveEngineSolveArgs {
|
|
350
210
|
server: ResolvedServer;
|
|
351
211
|
definitionSource: SolveEngineDefinitionSource;
|
|
@@ -356,27 +216,26 @@ interface SolveEngineSolveArgs {
|
|
|
356
216
|
* Ignored for the other source forms.
|
|
357
217
|
*/
|
|
358
218
|
definitionKey?: string;
|
|
359
|
-
|
|
219
|
+
/**
|
|
220
|
+
* The definition's inputs, from the schema you stored, never from the request: `id`, `nickname`,
|
|
221
|
+
* `paramType` and the bounds decide what reaches the definition, so a body that supplies them
|
|
222
|
+
* can drop a limit or fill a slot your host reserved.
|
|
223
|
+
*/
|
|
224
|
+
inputs: SolveInput[];
|
|
360
225
|
values: Record<string, unknown>;
|
|
361
226
|
signal: AbortSignal;
|
|
362
227
|
acceptEncoding?: string;
|
|
363
|
-
/**
|
|
228
|
+
/**
|
|
229
|
+
* Stamped as `X-Selva-Definition` when this solve builds the server's warm client. The header
|
|
230
|
+
* is fixed per client, so later solves on that server carry the first definition's guid.
|
|
231
|
+
*/
|
|
364
232
|
definitionGuid?: string;
|
|
365
233
|
loadStartMs?: number;
|
|
366
234
|
defLoadMs?: number;
|
|
367
|
-
prepMarks?: [
|
|
368
|
-
/**
|
|
369
|
-
* Per-solve live-event callback. A coalesced waiter shares the first caller's
|
|
370
|
-
* compute call, so only that caller's target reaches the definition; the
|
|
371
|
-
* others still get the server-emitted start/end events on their own stream.
|
|
372
|
-
*/
|
|
235
|
+
prepMarks?: PrepMark[];
|
|
236
|
+
/** Per-solve live-event callback. A solve carrying one runs its own compute call, never a shared one. */
|
|
373
237
|
selvaEvents?: SelvaEventTarget;
|
|
374
238
|
}
|
|
375
|
-
interface FrameworkAgnosticResponse {
|
|
376
|
-
status: number;
|
|
377
|
-
headers: Record<string, string>;
|
|
378
|
-
body: string | Uint8Array;
|
|
379
|
-
}
|
|
380
239
|
interface SolveEngineStats {
|
|
381
240
|
client: SolveCacheStats;
|
|
382
241
|
definitionBytes: ByteCacheStats;
|
|
@@ -389,11 +248,17 @@ export declare class SolveEngine {
|
|
|
389
248
|
private readonly clientCache;
|
|
390
249
|
private readonly byteCache;
|
|
391
250
|
private readonly singleFlight;
|
|
251
|
+
private readonly clientGenerations;
|
|
252
|
+
private lastClientGeneration;
|
|
392
253
|
constructor(options: SolveEngineOptions);
|
|
393
254
|
getClient(server: ResolvedServer, opts?: {
|
|
394
255
|
definitionGuid?: string;
|
|
395
256
|
}): Promise<CachedClient>;
|
|
396
|
-
definitionRef(versionId: string, load: () => Promise<Uint8Array>): ByteCacheRef;
|
|
257
|
+
definitionRef(versionId: string, load: (signal: AbortSignal) => Promise<Uint8Array>): ByteCacheRef;
|
|
258
|
+
/**
|
|
259
|
+
* Drops the warm client for `id`; call it when the server's URL or key changes. Solves already
|
|
260
|
+
* running finish on the old connection details first, so a revoked key stays in use until then.
|
|
261
|
+
*/
|
|
397
262
|
evictServer(id: string): void;
|
|
398
263
|
clearSolveCaches(): void;
|
|
399
264
|
/**
|
|
@@ -402,15 +267,23 @@ export declare class SolveEngine {
|
|
|
402
267
|
*/
|
|
403
268
|
clearDefinitionCache(): void;
|
|
404
269
|
stats(): SolveEngineStats;
|
|
405
|
-
solve(args: SolveEngineSolveArgs): Promise<
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
270
|
+
solve(args: SolveEngineSolveArgs): Promise<SolveEngineOutcome>;
|
|
271
|
+
/**
|
|
272
|
+
* The response for an outcome; the mapping from outcome to status lives here. Throws
|
|
273
|
+
* `compute_error`'s error: what it means for the caller is the host's to decide.
|
|
274
|
+
*/
|
|
275
|
+
toWebResponse(outcome: SolveEngineOutcome): Response;
|
|
276
|
+
/**
|
|
277
|
+
* Part of the coalesce key: after an eviction the id stays and the client changes, and a new
|
|
278
|
+
* caller joining a draining flight would get an answer from the old URL or key.
|
|
279
|
+
*/
|
|
280
|
+
private clientGeneration;
|
|
413
281
|
private resolveDefinitionSource;
|
|
414
282
|
}
|
|
415
|
-
|
|
283
|
+
/**
|
|
284
|
+
* What `SolveEngine.solve` takes as `inputs`, from a schema the host stored. The bounds live on
|
|
285
|
+
* the number widgets in the layout, not on `schema.inputs`, so without them nothing clamps.
|
|
286
|
+
*/
|
|
287
|
+
export declare function solveInputsFromSchema(schema: UISchema): SolveInput[];
|
|
288
|
+
export type { ByteCacheRef, ByteCacheStats, ByteRefOutcome, CachedClient, DefinitionRef, ResolvedServer, SolveCacheStats, SolveDefinition, SolveEngineDefinitionSource, SolveEngineLimits, SolveEngineOptions, SolveEngineOutcome, SolveEngineSolveArgs, SolveEngineStats, SolveEnvelope, SolveInput, SolveLimits, SolvePhaseMetrics };
|
|
416
289
|
//# sourceMappingURL=server.d.ts.map
|