@selvajs/selva 4.21.0-beta.24 → 4.21.0-beta.26
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/assets/0.Ct4dsf2W.css +2 -0
- package/build/client/_app/immutable/assets/0.Ct4dsf2W.css.br +0 -0
- package/build/client/_app/immutable/assets/0.Ct4dsf2W.css.gz +0 -0
- package/build/client/_app/immutable/chunks/BUxAHI7i.js +1 -0
- package/build/client/_app/immutable/chunks/BUxAHI7i.js.br +1 -0
- package/build/client/_app/immutable/chunks/BUxAHI7i.js.gz +0 -0
- package/build/client/_app/immutable/chunks/C4PDTpD1.js +6085 -0
- package/build/client/_app/immutable/chunks/C4PDTpD1.js.br +0 -0
- package/build/client/_app/immutable/chunks/C4PDTpD1.js.gz +0 -0
- package/build/client/_app/immutable/entry/{app.Dl3HM1mx.js → app.Bqmne5hV.js} +2 -2
- package/build/client/_app/immutable/entry/app.Bqmne5hV.js.br +0 -0
- package/build/client/_app/immutable/entry/app.Bqmne5hV.js.gz +0 -0
- package/build/client/_app/immutable/nodes/21.Dv262ba8.js +1 -0
- package/build/client/_app/immutable/nodes/21.Dv262ba8.js.br +1 -0
- package/build/client/_app/immutable/nodes/21.Dv262ba8.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/runtime-meta.json +1 -1
- package/build/server/.vite/manifest.json +24 -21
- package/build/server/_app/immutable/assets/_layout.Ct4dsf2W.css +2 -0
- package/build/server/chunks/capture.js +1 -1
- package/build/server/chunks/compute-profile-D3g1Tuyd.js +92 -0
- package/build/server/chunks/compute-profile-D3g1Tuyd.js.map +1 -0
- package/build/server/chunks/compute.js +1 -1
- package/build/server/chunks/engine.server.js +1 -1
- package/build/server/chunks/errors.js +7 -30
- package/build/server/chunks/errors.js.map +1 -1
- package/build/server/chunks/grasshopper.js +6 -1
- package/build/server/chunks/grasshopper.js.map +1 -1
- package/build/server/chunks/handlers.js +5 -4
- package/build/server/chunks/handlers.js.map +1 -1
- package/build/server/chunks/instance.js +3 -3
- package/build/server/chunks/internal.js +1 -1
- package/build/server/chunks/ops.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 +48 -15
- package/build/server/chunks/providers.server.js.map +1 -1
- package/build/server/chunks/{limits.js → saved-values.js} +35 -2
- package/build/server/chunks/saved-values.js.map +1 -0
- package/build/server/chunks/server.js +134 -17
- package/build/server/chunks/server.js.map +1 -1
- package/build/server/chunks/solve.js +1 -1
- package/build/server/chunks/solve.server.js +8 -3
- package/build/server/chunks/solve.server.js.map +1 -1
- package/build/server/chunks/types2.js.map +1 -1
- package/build/server/entries/endpoints/api/v1/compute/_server.ts.js +1 -1
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/solve/_server.ts.js +5 -2
- package/build/server/entries/endpoints/api/v1/definitions/_guid_/solve/_server.ts.js.map +1 -1
- package/build/server/entries/endpoints/api/v1/solves/_solveId_/_server.ts.js +1 -1
- package/build/server/entries/pages/library/_guid_/_page.server.ts.js +14 -3
- package/build/server/entries/pages/library/_guid_/_page.server.ts.js.map +1 -1
- package/build/server/entries/pages/library/_guid_/_page.svelte.js +164 -38
- 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/0.js +2 -2
- package/build/server/nodes/21.js +1 -1
- package/build/server/server.js +1 -1
- package/package.json +11 -11
- package/build/client/_app/immutable/assets/0.DOeouCe4.css +0 -2
- package/build/client/_app/immutable/assets/0.DOeouCe4.css.br +0 -0
- package/build/client/_app/immutable/assets/0.DOeouCe4.css.gz +0 -0
- package/build/client/_app/immutable/chunks/B58dPMPq.js +0 -1
- package/build/client/_app/immutable/chunks/B58dPMPq.js.br +0 -1
- package/build/client/_app/immutable/chunks/B58dPMPq.js.gz +0 -0
- package/build/client/_app/immutable/chunks/DtmN00GS.js +0 -6085
- package/build/client/_app/immutable/chunks/DtmN00GS.js.br +0 -0
- package/build/client/_app/immutable/chunks/DtmN00GS.js.gz +0 -0
- package/build/client/_app/immutable/entry/app.Dl3HM1mx.js.br +0 -0
- package/build/client/_app/immutable/entry/app.Dl3HM1mx.js.gz +0 -0
- package/build/client/_app/immutable/nodes/21.BZJQikE5.js +0 -1
- package/build/client/_app/immutable/nodes/21.BZJQikE5.js.br +0 -0
- package/build/client/_app/immutable/nodes/21.BZJQikE5.js.gz +0 -0
- package/build/server/_app/immutable/assets/_layout.DOeouCe4.css +0 -2
- package/build/server/chunks/async-solve-Doflh4BJ.js +0 -27
- package/build/server/chunks/async-solve-Doflh4BJ.js.map +0 -1
- package/build/server/chunks/limits.js.map +0 -1
- /package/build/client/_app/immutable/nodes/{0.BQ4J6cqX.js → 0.BsaBi01M.js} +0 -0
- /package/build/client/_app/immutable/nodes/{0.BQ4J6cqX.js.br → 0.BsaBi01M.js.br} +0 -0
- /package/build/client/_app/immutable/nodes/{0.BQ4J6cqX.js.gz → 0.BsaBi01M.js.gz} +0 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { n as getInputItems } from "./traversal.js";
|
|
2
|
+
// ../solve/dist/binary-response-CcX2wou-.js
|
|
3
|
+
var BINARY_SOLVE_MEDIA_TYPE = "application/vnd.selva.solve+binary";
|
|
4
|
+
/** ASCII "SLVR", read as a little-endian u32. */
|
|
5
|
+
var BINARY_SOLVE_MAGIC = 1381387347;
|
|
6
|
+
var FIXED_HEADER_BYTES = 16;
|
|
7
|
+
function isBlobRef(value) {
|
|
8
|
+
return typeof value === "object" && value !== null && typeof value.$blob === "number";
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* True when a wire `type` names a Display payload: one dot-separated token is exactly `Display` or
|
|
12
|
+
* `DisplayBatch`. Must match `isDisplayItemType` in `@selvajs/visualization`'s webdisplay parser,
|
|
13
|
+
* which can't share this one: visualization takes no dependency on this package.
|
|
14
|
+
*/
|
|
15
|
+
function isDisplayItemType(type) {
|
|
16
|
+
const tokens = type.split(".");
|
|
17
|
+
return tokens.includes("Display") || tokens.includes("DisplayBatch");
|
|
18
|
+
}
|
|
19
|
+
var align8 = (n) => n + 7 & -8;
|
|
20
|
+
function headerBytes(blobCount) {
|
|
21
|
+
return align8(FIXED_HEADER_BYTES + 4 * blobCount);
|
|
22
|
+
}
|
|
23
|
+
function writeHeader(target, flags, jsonBytes, blobLengths) {
|
|
24
|
+
const view = new DataView(target.buffer, target.byteOffset, target.byteLength);
|
|
25
|
+
view.setUint32(0, BINARY_SOLVE_MAGIC, true);
|
|
26
|
+
view.setUint16(4, 1, true);
|
|
27
|
+
view.setUint16(6, flags, true);
|
|
28
|
+
view.setUint32(8, jsonBytes, true);
|
|
29
|
+
view.setUint32(12, blobLengths.length, true);
|
|
30
|
+
blobLengths.forEach((length, i) => view.setUint32(FIXED_HEADER_BYTES + 4 * i, length, true));
|
|
31
|
+
}
|
|
32
|
+
/** Splits a frame into views over `bytes`; nothing is copied. Throws on a malformed frame. */
|
|
33
|
+
function readFrame(bytes) {
|
|
34
|
+
const fail = (why) => {
|
|
35
|
+
throw new Error(`Malformed binary solve response: ${why}`);
|
|
36
|
+
};
|
|
37
|
+
if (bytes.byteLength < FIXED_HEADER_BYTES) fail("shorter than its header");
|
|
38
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
39
|
+
if (view.getUint32(0, true) !== 1381387347) fail("bad magic");
|
|
40
|
+
const version = view.getUint16(4, true);
|
|
41
|
+
if (version !== 1) fail(`unsupported version ${version}`);
|
|
42
|
+
const flags = view.getUint16(6, true);
|
|
43
|
+
const jsonBytes = view.getUint32(8, true);
|
|
44
|
+
const blobCount = view.getUint32(12, true);
|
|
45
|
+
if (FIXED_HEADER_BYTES + 4 * blobCount > bytes.byteLength) fail("blob table runs past the end");
|
|
46
|
+
let offset = headerBytes(blobCount);
|
|
47
|
+
const take = (length) => {
|
|
48
|
+
if (offset + length > bytes.byteLength) fail("truncated");
|
|
49
|
+
const section = bytes.subarray(offset, offset + length);
|
|
50
|
+
offset = align8(offset + length);
|
|
51
|
+
return section;
|
|
52
|
+
};
|
|
53
|
+
const json = take(jsonBytes);
|
|
54
|
+
const blobs = [];
|
|
55
|
+
for (let i = 0; i < blobCount; i++) blobs.push(take(view.getUint32(FIXED_HEADER_BYTES + 4 * i, true)));
|
|
56
|
+
return {
|
|
57
|
+
flags,
|
|
58
|
+
json,
|
|
59
|
+
blobs
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
// ../solve/dist/compute-profile-D3g1Tuyd.js
|
|
63
|
+
/**
|
|
64
|
+
* Inputs the schema marks `source.kind === 'server'`. Only the host fills them, through
|
|
65
|
+
* `SolveEngine.solve`'s `boundValues`; without a value there they solve on their schema default.
|
|
66
|
+
* The client sends no value for them, and the server refuses one.
|
|
67
|
+
*/
|
|
68
|
+
function serverSourcedInputIds(schema) {
|
|
69
|
+
return new Set(getInputItems(schema).filter((item) => item.source?.kind === "server").map((item) => item.paramId));
|
|
70
|
+
}
|
|
71
|
+
/** `promise`'s outcome, or a rejection with `signal`'s reason if that fires first. */
|
|
72
|
+
function raceAbort(promise, signal) {
|
|
73
|
+
return new Promise((resolve, reject) => {
|
|
74
|
+
const onAbort = () => reject(signal.reason);
|
|
75
|
+
if (signal.aborted) onAbort();
|
|
76
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
77
|
+
promise.then(resolve, reject).finally(() => signal.removeEventListener("abort", onAbort));
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
var KEEPALIVE_PREFERENCE = "selva-keepalive";
|
|
81
|
+
/** Under the 30 s many load balancers allow an idle upstream. */
|
|
82
|
+
var KEEPALIVE_INTERVAL_MS = 15e3;
|
|
83
|
+
/** RFC 7240's own preference, so a generic proxy or client already knows what it means. */
|
|
84
|
+
var ASYNC_PREFERENCE = "respond-async";
|
|
85
|
+
/**
|
|
86
|
+
* The VektorNode fork's slowest-objects profile, a JSON array of `{ name, nick, ms }`. Selva passes
|
|
87
|
+
* it on to a signed-in browser under the same name.
|
|
88
|
+
*/
|
|
89
|
+
var COMPUTE_PROFILE_HEADER = "X-Compute-Profile";
|
|
90
|
+
export { raceAbort as a, align8 as c, isDisplayItemType as d, readFrame as f, KEEPALIVE_PREFERENCE as i, headerBytes as l, COMPUTE_PROFILE_HEADER as n, serverSourcedInputIds as o, writeHeader as p, KEEPALIVE_INTERVAL_MS as r, BINARY_SOLVE_MEDIA_TYPE as s, ASYNC_PREFERENCE as t, isBlobRef as u };
|
|
91
|
+
|
|
92
|
+
//# sourceMappingURL=compute-profile-D3g1Tuyd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compute-profile-D3g1Tuyd.js","names":[],"sources":["../../../../solve/dist/binary-response-CcX2wou-.js","../../../../solve/dist/compute-profile-D3g1Tuyd.js"],"sourcesContent":["// src/shared/binary-response.ts\nconst BINARY_SOLVE_MEDIA_TYPE = \"application/vnd.selva.solve+binary\";\n/** ASCII \"SLVR\", read as a little-endian u32. */\nconst BINARY_SOLVE_MAGIC = 1381387347;\nconst FIXED_HEADER_BYTES = 16;\nfunction isBlobRef(value) {\n\treturn typeof value === \"object\" && value !== null && typeof value.$blob === \"number\";\n}\n/**\n* True when a wire `type` names a Display payload: one dot-separated token is exactly `Display` or\n* `DisplayBatch`. Must match `isDisplayItemType` in `@selvajs/visualization`'s webdisplay parser,\n* which can't share this one: visualization takes no dependency on this package.\n*/\nfunction isDisplayItemType(type) {\n\tconst tokens = type.split(\".\");\n\treturn tokens.includes(\"Display\") || tokens.includes(\"DisplayBatch\");\n}\nconst align8 = (n) => n + 7 & -8;\nfunction headerBytes(blobCount) {\n\treturn align8(FIXED_HEADER_BYTES + 4 * blobCount);\n}\nfunction writeHeader(target, flags, jsonBytes, blobLengths) {\n\tconst view = new DataView(target.buffer, target.byteOffset, target.byteLength);\n\tview.setUint32(0, BINARY_SOLVE_MAGIC, true);\n\tview.setUint16(4, 1, true);\n\tview.setUint16(6, flags, true);\n\tview.setUint32(8, jsonBytes, true);\n\tview.setUint32(12, blobLengths.length, true);\n\tblobLengths.forEach((length, i) => view.setUint32(FIXED_HEADER_BYTES + 4 * i, length, true));\n}\n/** Splits a frame into views over `bytes`; nothing is copied. Throws on a malformed frame. */\nfunction readFrame(bytes) {\n\tconst fail = (why) => {\n\t\tthrow new Error(`Malformed binary solve response: ${why}`);\n\t};\n\tif (bytes.byteLength < FIXED_HEADER_BYTES) fail(\"shorter than its header\");\n\tconst view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);\n\tif (view.getUint32(0, true) !== 1381387347) fail(\"bad magic\");\n\tconst version = view.getUint16(4, true);\n\tif (version !== 1) fail(`unsupported version ${version}`);\n\tconst flags = view.getUint16(6, true);\n\tconst jsonBytes = view.getUint32(8, true);\n\tconst blobCount = view.getUint32(12, true);\n\tif (FIXED_HEADER_BYTES + 4 * blobCount > bytes.byteLength) fail(\"blob table runs past the end\");\n\tlet offset = headerBytes(blobCount);\n\tconst take = (length) => {\n\t\tif (offset + length > bytes.byteLength) fail(\"truncated\");\n\t\tconst section = bytes.subarray(offset, offset + length);\n\t\toffset = align8(offset + length);\n\t\treturn section;\n\t};\n\tconst json = take(jsonBytes);\n\tconst blobs = [];\n\tfor (let i = 0; i < blobCount; i++) blobs.push(take(view.getUint32(FIXED_HEADER_BYTES + 4 * i, true)));\n\treturn {\n\t\tflags,\n\t\tjson,\n\t\tblobs\n\t};\n}\nexport { isDisplayItemType as a, isBlobRef as i, align8 as n, readFrame as o, headerBytes as r, writeHeader as s, BINARY_SOLVE_MEDIA_TYPE as t };\n\n//# sourceMappingURL=binary-response-CcX2wou-.js.map","import { getInputItems } from \"@selvajs/schemas\";\n// src/shared/server-sourced.ts\n/**\n* Inputs the schema marks `source.kind === 'server'`. Only the host fills them, through\n* `SolveEngine.solve`'s `boundValues`; without a value there they solve on their schema default.\n* The client sends no value for them, and the server refuses one.\n*/\nfunction serverSourcedInputIds(schema) {\n\treturn new Set(getInputItems(schema).filter((item) => item.source?.kind === \"server\").map((item) => item.paramId));\n}\n// src/shared/abort.ts\n/** `promise`'s outcome, or a rejection with `signal`'s reason if that fires first. */\nfunction raceAbort(promise, signal) {\n\treturn new Promise((resolve, reject) => {\n\t\tconst onAbort = () => reject(signal.reason);\n\t\tif (signal.aborted) onAbort();\n\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t\tpromise.then(resolve, reject).finally(() => signal.removeEventListener(\"abort\", onAbort));\n\t});\n}\n// src/shared/keepalive.ts\nconst KEEPALIVE_PREFERENCE = \"selva-keepalive\";\n/** Under the 30 s many load balancers allow an idle upstream. */\nconst KEEPALIVE_INTERVAL_MS = 15e3;\n// src/shared/async-solve.ts\n/** RFC 7240's own preference, so a generic proxy or client already knows what it means. */\nconst ASYNC_PREFERENCE = \"respond-async\";\n/** Seconds one poll may wait. Under the 30 s many load balancers allow an idle upstream. */\nconst ASYNC_POLL_WAIT_S = 25;\n// src/shared/compute-profile.ts\n/**\n* The VektorNode fork's slowest-objects profile, a JSON array of `{ name, nick, ms }`. Selva passes\n* it on to a signed-in browser under the same name.\n*/\nconst COMPUTE_PROFILE_HEADER = \"X-Compute-Profile\";\nexport { KEEPALIVE_PREFERENCE as a, KEEPALIVE_INTERVAL_MS as i, ASYNC_POLL_WAIT_S as n, raceAbort as o, ASYNC_PREFERENCE as r, serverSourcedInputIds as s, COMPUTE_PROFILE_HEADER as t };\n\n//# sourceMappingURL=compute-profile-D3g1Tuyd.js.map"],"mappings":";;AACA,IAAM,0BAA0B;;AAEhC,IAAM,qBAAqB;AAC3B,IAAM,qBAAqB;AAC3B,SAAS,UAAU,OAAO;CACzB,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,OAAO,MAAM,UAAU;AAC9E;;;;;;AAMA,SAAS,kBAAkB,MAAM;CAChC,MAAM,SAA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W;EACxD,MAAM,UAAU,MAAM,SAAS,QAAQ,SAAS,MAAM;EACtD,SAAS,OAAO,SAAS,MAAM;EAC/B,OAAO;CACR;CACA,MAAM,OAAO,KAAK,SAAS;CAC3B,MAAM,QAAQ,CAAC;CACf,KAAK,IAAI,IAAI,GAAG,IAAI,WAAW,KAAK,MAAM,KAAK,KAAK,KAAK,UAAU,qBAAqB,IAAI,GAAG,IAAI,CAAC,CAAC;CACrG,OAAO;EACN;EACA;EACA;CACD;AACD;;;;;;;ACpDA,SAAS,sBAAsB,QAAQ;CACtC,OAAO,IAAI,IAAI,cAAc,MAAM,CAAC,CAAC,QAAQ,SAAS,KAAK,QAAQ,SAAS,QAAQ,CAAC,CAAC,KAAK,SAAS,KAAK,OAAO,CAAC;AAClH;;AAGA,SAAS,UAAU,SAAS,QAAQ;CACnC,OAAO,IAAI,SAAS,SAAS,WAAW;EACvC,MAAM,gBAAgB,OAAO,OAAO,MAAM;EAC1C,IAAI,OAAO,SAAS,QAAQ;EAC5B,OAAO,iBAAiB,SAAS,SAAS,EAAE,MAAM,KAAK,CAAC;EACxD,QAAQ,KAAK,SAAS,MAAM,CAAC,CAAC,cAAc,OAAO,oBAAoB,SAAS,OAAO,CAAC;CACzF,CAAC;AACF;AAEA,IAAM,uBAAuB;;AAE7B,IAAM,wBAAwB;;AAG9B,IAAM,mBAAmB;;;;;AAQzB,IAAM,yBAAyB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import "./
|
|
1
|
+
import "./saved-values.js";
|
|
2
2
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { i as SolveEngine, n as DEFAULT_SOLVE_DEADLINE_MS } from "./server.js";
|
|
2
2
|
import { n as env } from "./previous-key.js";
|
|
3
3
|
import { D as computeDebugMode, f as getLogger, w as lazyLogger } from "./providers.server.js";
|
|
4
|
-
import {
|
|
4
|
+
import { s as resolveComputeLimits } from "./saved-values.js";
|
|
5
5
|
import "./compute.js";
|
|
6
6
|
// src/lib/server/computeLimits.ts
|
|
7
7
|
/**
|
|
@@ -1,32 +1,7 @@
|
|
|
1
|
+
import { n as savedValuesFrom, t as applySavedValues } from "./saved-values.js";
|
|
1
2
|
import { t as UI_SCHEMA_VERSION } from "./schema.js";
|
|
2
3
|
import { a as fetchParsedDefinitionIO, o as normalizeUISchemaCasing, s as readSchemaResults$1 } from "./grasshopper.js";
|
|
3
4
|
import { createHash } from "node:crypto";
|
|
4
|
-
// ../server/src/definitions/saved-values.ts
|
|
5
|
-
function savedValuesFrom(inputs) {
|
|
6
|
-
const values = /* @__PURE__ */ new Map();
|
|
7
|
-
for (const input of inputs) {
|
|
8
|
-
if (input.id === void 0 || input.default === void 0) continue;
|
|
9
|
-
values.set(input.id, input.paramType === "Color" ? colorToHex(input.default) : input.default);
|
|
10
|
-
}
|
|
11
|
-
return values;
|
|
12
|
-
}
|
|
13
|
-
/** `schema` with each input's `default` replaced by its saved value, where it has one. */
|
|
14
|
-
function applySavedValues(schema, values) {
|
|
15
|
-
return {
|
|
16
|
-
...schema,
|
|
17
|
-
inputs: schema.inputs.map((input) => values.has(input.id) ? {
|
|
18
|
-
...input,
|
|
19
|
-
default: values.get(input.id)
|
|
20
|
-
} : input)
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
function colorToHex(value) {
|
|
24
|
-
const parts = String(value).split(",").map((s) => parseInt(s.trim(), 10));
|
|
25
|
-
const hex = (n) => n.toString(16).padStart(2, "0");
|
|
26
|
-
if (parts.length === 3) return `#${hex(parts[0])}${hex(parts[1])}${hex(parts[2])}`;
|
|
27
|
-
if (parts.length === 4) return `#${hex(parts[1])}${hex(parts[2])}${hex(parts[3])}`;
|
|
28
|
-
return value;
|
|
29
|
-
}
|
|
30
5
|
// ../server/src/definitions/with-timeout.ts
|
|
31
6
|
/**
|
|
32
7
|
* Settles with `work`, or rejects with `onTimeout()` after `ms`. `work` is not cancelled: it runs
|
|
@@ -183,8 +158,8 @@ function isInventory(value) {
|
|
|
183
158
|
/**
|
|
184
159
|
* How long an upload waits for the saved values, counted from its start. Compute takes tens of
|
|
185
160
|
* seconds to open a large file, and the whole request has to stay under the 60 s many proxies
|
|
186
|
-
* allow.
|
|
187
|
-
*
|
|
161
|
+
* allow. A read still running when the upload answers keeps going, and `savedValuesLater` stores
|
|
162
|
+
* its values on the version when it lands.
|
|
188
163
|
*/
|
|
189
164
|
var SAVED_VALUES_WAIT_MS = 45e3;
|
|
190
165
|
var SAVED_VALUES_TIMEOUT_MS = 12e4;
|
|
@@ -220,7 +195,9 @@ async function extractSchemaForUpload(definitionBytes, server) {
|
|
|
220
195
|
return {
|
|
221
196
|
schema: saved ? applySavedValues(schema, saved) : schema,
|
|
222
197
|
inventory,
|
|
223
|
-
defaultsPending: !saved
|
|
198
|
+
defaultsPending: !saved,
|
|
199
|
+
savedValues: saved,
|
|
200
|
+
savedValuesLater: values
|
|
224
201
|
};
|
|
225
202
|
}
|
|
226
203
|
/**
|
|
@@ -270,6 +247,6 @@ var ComputeServerUnconfiguredError = class extends Error {
|
|
|
270
247
|
this.name = "ComputeServerUnconfiguredError";
|
|
271
248
|
}
|
|
272
249
|
};
|
|
273
|
-
export { extractSchemaForUpload as a, fetchScriptSources as c, withTimeout as d,
|
|
250
|
+
export { extractSchemaForUpload as a, fetchScriptSources as c, withTimeout as d, compareSchemaVersion as i, isOlderMinorSchemaVersion as l, SchemaExtractionError as n, fetchExtraction as o, assertCamelCaseSchema as r, fetchSchemaFromCompute as s, ComputeServerUnconfiguredError as t, postSchemaFormData as u };
|
|
274
251
|
|
|
275
252
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":["readWrapper"],"sources":["../../../../server/src/definitions/saved-values.ts","../../../../server/src/definitions/with-timeout.ts","../../../../server/src/definitions/schema-extraction.ts","../../../../server/src/compute/errors.ts"],"sourcesContent":["// The embedded schema carries input values from the author's last schema sync. Compute's `/io`\n// reads the values saved in the file, which can be newer, and those are what a form must start\n// from. A version's bytes never change, so neither do its saved values.\n\nimport type { UISchema } from '@selvajs/schemas';\n\n/** Each input's saved value, keyed by param id. */\nexport type SavedValues = ReadonlyMap<string, unknown>;\n\nexport function savedValuesFrom(\n\tinputs: ReadonlyArray<{ id?: string; paramType?: string; default?: unknown }>\n): SavedValues {\n\tconst values = new Map<string, unknown>();\n\tfor (const input of inputs) {\n\t\tif (input.id === undefined || input.default === undefined) continue;\n\t\tvalues.set(input.id, input.paramType === 'Color' ? colorToHex(input.default) : input.default);\n\t}\n\treturn values;\n}\n\n/** `schema` with each input's `default` replaced by its saved value, where it has one. */\nexport function applySavedValues(schema: UISchema, values: SavedValues): UISchema {\n\treturn {\n\t\t...schema,\n\t\tinputs: schema.inputs.map((input) =>\n\t\t\tvalues.has(input.id) ? { ...input, default: values.get(input.id) } : input\n\t\t)\n\t};\n}\n\n// Compute sends colors as \"r,g,b\" or \"a,r,g,b\"; the color picker takes hex.\nfunction colorToHex(value: unknown): unknown {\n\tconst parts = String(value)\n\t\t.split(',')\n\t\t.map((s) => parseInt(s.trim(), 10));\n\tconst hex = (n: number) => n.toString(16).padStart(2, '0');\n\tif (parts.length === 3) return `#${hex(parts[0])}${hex(parts[1])}${hex(parts[2])}`;\n\tif (parts.length === 4) return `#${hex(parts[1])}${hex(parts[2])}${hex(parts[3])}`;\n\treturn value;\n}\n","/**\n * Settles with `work`, or rejects with `onTimeout()` after `ms`. `work` is not cancelled: it runs\n * on, and its later rejection stays handled.\n */\nexport function withTimeout<T>(work: Promise<T>, ms: number, onTimeout: () => Error): Promise<T> {\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\tconst timeout = new Promise<never>((_, reject) => {\n\t\ttimer = setTimeout(() => reject(onTimeout()), ms);\n\t});\n\treturn Promise.race([work, timeout]).finally(() => clearTimeout(timer));\n}\n","// Extraction IS validation: a `.gh` with no valid \"Schema\" output, or an\n// unreachable compute server, throws here — which is what makes this the upload\n// gate as well as the render path's fallback for un-cached or stale versions.\n\nimport { createHash } from 'node:crypto';\nimport {\n\tfetchParsedDefinitionIO,\n\tnormalizeUISchemaCasing,\n\treadSchemaResults as readWrapper,\n\ttype SchemaEndpointResult\n} from '@selvajs/compute/grasshopper';\nimport {\n\tUI_SCHEMA_VERSION,\n\ttype DocumentInventory,\n\ttype ScriptSource,\n\ttype UISchema\n} from '@selvajs/schemas';\nimport type { ComputeServerConfig } from '@selvajs/platform';\nimport { applySavedValues, savedValuesFrom, type SavedValues } from './saved-values.js';\nimport { withTimeout } from './with-timeout.js';\n\n/** One entry of the compute schema endpoint's response, typed to our `UISchema`. */\nexport type SchemaExtractionResult = SchemaEndpointResult<UISchema>;\n\n/** Thin re-export of @selvajs/compute's unwrap, typed to `UISchema`. */\nexport function readSchemaResults(raw: unknown): SchemaExtractionResult[] {\n\treturn readWrapper<UISchema>(raw);\n}\n\n/** Thrown when compute is reachable but the definition yields no usable schema. */\nexport class SchemaExtractionError extends Error {\n\tconstructor(\n\t\tpublic readonly kind: 'unreachable' | 'invalid' | 'unsupported' | 'malformed',\n\t\tmessage: string\n\t) {\n\t\tsuper(message);\n\t\tthis.name = 'SchemaExtractionError';\n\t}\n}\n\n/**\n * Rejects a schema whose keys are not camelCase by the time it reaches a consumer.\n *\n * Compute serializes the plugin's `UISchema` POCO, whose camelCase names live in\n * `[JsonProperty]` attributes. `Selva.gha` ILRepack-merges Newtonsoft, so those\n * attributes have type `Selva!Newtonsoft.Json.JsonPropertyAttribute`; a compute\n * server serializing with its OWN Newtonsoft does not recognize them, reads no\n * attributes, and falls back to raw CLR member names — `Inputs`, `Layout`.\n * Nothing throws on the wire: every consumer just reads `schema.inputs` as\n * undefined and renders a definition with no inputs.\n *\n * `postSchemaFormData` repairs that casing via `normalizeUISchemaCasing`, so a\n * schema fresh off the wire never trips this. It stays because schemas are also\n * PERSISTED: a row cached before the normalizer existed still holds PascalCase,\n * and it reaches consumers without passing through `postSchemaFormData` again.\n * A schema with no `inputs` in any casing lands here too. It is a backstop, not\n * the primary defense — which is why it names the missing key rather than telling\n * the operator to go update their compute server.\n *\n * Checked structurally rather than by plugin version, because the casing depends\n * on which assembly serialized the schema, not on any version number.\n */\nexport function assertCamelCaseSchema(schema: UISchema): void {\n\tconst raw = schema as unknown as Record<string, unknown>;\n\tif (Array.isArray(raw.inputs)) return;\n\n\tconst pascalKeys = ['Inputs', 'Outputs', 'Layout', 'SchemaVersion'].filter((k) => k in raw);\n\tif (pascalKeys.length > 0) {\n\t\tthrow new SchemaExtractionError(\n\t\t\t'malformed',\n\t\t\t`Schema keys are PascalCase (found ${pascalKeys.join(', ')}), so every property name ` +\n\t\t\t\t`is wrong and the definition would render with no inputs. Compute serialized it with ` +\n\t\t\t\t`its own Newtonsoft instead of the one merged into Selva.gha. Fresh responses are ` +\n\t\t\t\t`normalized, so this is most likely a schema cached before that fix — re-save the ` +\n\t\t\t\t`definition version to re-extract it.`\n\t\t);\n\t}\n\n\tthrow new SchemaExtractionError(\n\t\t'malformed',\n\t\t`Compute returned a schema with no 'inputs' array (got keys: ${Object.keys(raw)\n\t\t\t.slice(0, 12)\n\t\t\t.join(', ')}).`\n\t);\n}\n\nfunction parseSemver(version: string): [number, number, number] | null {\n\tconst m = /^(\\d+)\\.(\\d+)\\.(\\d+)$/.exec(version);\n\treturn m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;\n}\n\n/**\n * Orders a schema format version against the app's `UI_SCHEMA_VERSION`: -1 older, 0 current,\n * 1 newer, null unparseable. A missing version is older: plugins before 2.12.0 emitted none.\n */\nexport function compareSchemaVersion(version: string | undefined): -1 | 0 | 1 | null {\n\tif (!version) return -1;\n\tconst extracted = parseSemver(version);\n\tconst supported = parseSemver(UI_SCHEMA_VERSION);\n\tif (!extracted || !supported) return null;\n\tfor (let i = 0; i < 3; i++) {\n\t\tif (extracted[i] !== supported[i]) return extracted[i] < supported[i] ? -1 : 1;\n\t}\n\treturn 0;\n}\n\n/** An older minor or patch of the app's own major: a minor bump only adds optional constructs. */\nexport function isOlderMinorSchemaVersion(version: string | undefined): boolean {\n\tconst extracted = version ? parseSemver(version) : null;\n\tconst supported = parseSemver(UI_SCHEMA_VERSION);\n\tif (!extracted || !supported || extracted[0] !== supported[0]) return false;\n\treturn compareSchemaVersion(version) === -1;\n}\n\n/**\n * Rejects a schema from a NEWER plugin than this app was built against — its\n * shape may contain constructs the renderer doesn't know. Older (or missing)\n * versions pass: the compute-side C# migrator always emits its own current\n * version, and an older shape only lacks optional additions.\n */\nexport function assertSupportedSchemaVersion(schema: UISchema): void {\n\tif (compareSchemaVersion(schema.schemaVersion) === 1) {\n\t\tthrow new SchemaExtractionError(\n\t\t\t'unsupported',\n\t\t\t`This definition was authored with a newer Selva plugin (schema format ${schema.schemaVersion}); ` +\n\t\t\t\t`this server supports schema format ≤ ${UI_SCHEMA_VERSION}. Update the server, or ` +\n\t\t\t\t`re-save the definition with a matching plugin version.`\n\t\t);\n\t}\n}\n\n/**\n * POSTs a multipart form to Rhino Compute's `/grasshopper/schema` endpoint (no\n * solve required). Throws 'unreachable' on a network failure or non-2xx. The\n * per-file `error` Compute reports on its 200-with-no-schemas case is left to\n * the caller — single-file and multi-file callers want different messages.\n */\nexport async function postSchemaFormData(\n\tformData: FormData,\n\tserver: ComputeServerConfig\n): Promise<SchemaExtractionResult[]> {\n\tconst schemaUrl = new URL('/grasshopper/schema', server.serverUrl).toString();\n\n\tconst headers: Record<string, string> = {};\n\tif (server.apiKey) {\n\t\theaders['RhinoComputeKey'] = server.apiKey;\n\t}\n\n\tlet response: Response;\n\ttry {\n\t\tresponse = await fetch(schemaUrl, { method: 'POST', headers, body: formData });\n\t} catch (err) {\n\t\tthrow new SchemaExtractionError(\n\t\t\t'unreachable',\n\t\t\t`Compute server is unreachable: ${err instanceof Error ? err.message : String(err)}`\n\t\t);\n\t}\n\n\tif (!response.ok) {\n\t\tthrow new SchemaExtractionError(\n\t\t\t'unreachable',\n\t\t\t`Schema endpoint returned ${response.status}: ${response.statusText}`\n\t\t);\n\t}\n\n\t// Normalize here rather than in each caller: the upload/validation route reads\n\t// `postSchemaFormData` directly, so a fix applied only inside\n\t// `fetchSchemaFromCompute` would leave that path serving PascalCase schemas.\n\tconst results = readSchemaResults(await response.json());\n\treturn results.map((result) => ({\n\t\t...result,\n\t\tschemas: result.schemas?.map((schema) => normalizeUISchemaCasing(schema))\n\t}));\n}\n\n/**\n * Throws `SchemaExtractionError` so callers can map to the right HTTP status:\n * 503 unreachable / 422 invalid or unsupported.\n */\nexport async function fetchSchemaFromCompute(\n\tdefinitionBytes: Uint8Array,\n\tserver: ComputeServerConfig\n): Promise<UISchema> {\n\treturn (await fetchExtraction(definitionBytes, server)).schema;\n}\n\n/** A file's schema and, from a plugin that builds one, its inventory. */\nexport interface Extraction {\n\tschema: UISchema;\n\tinventory: DocumentInventory | null;\n}\n\n/** `fetchSchemaFromCompute` with the inventory Compute returns beside the schema. */\nexport async function fetchExtraction(\n\tdefinitionBytes: Uint8Array,\n\tserver: ComputeServerConfig\n): Promise<Extraction> {\n\tconst formData = new FormData();\n\tconst blob = new Blob([new Uint8Array(definitionBytes)], { type: 'application/octet-stream' });\n\tformData.append('file', blob, 'definition.gh');\n\n\tconst results = await postSchemaFormData(formData, server);\n\tconst schemas = results.flatMap((r) => r.schemas ?? []);\n\n\tif (schemas.length === 0) {\n\t\t// Compute answers 200 while reporting a per-file `error`, so the\n\t\t// !response.ok guard never fires for it. Surface that message verbatim: it\n\t\t// names the actual cause (bad Schema source, no embedded schema, ...),\n\t\t// which the generic fallback below cannot.\n\t\tconst diagnosis = results.map((r) => r.error).filter(Boolean);\n\t\tif (diagnosis.length > 0) {\n\t\t\tthrow new SchemaExtractionError('invalid', diagnosis.join('\\n'));\n\t\t}\n\n\t\tthrow new SchemaExtractionError(\n\t\t\t'invalid',\n\t\t\t'No schemas found in definition.\\n\\n' +\n\t\t\t\t'In Grasshopper, verify a Context Bake component with the output name \"Schema\" is present and wired to the solver.'\n\t\t);\n\t}\n\n\tassertSupportedSchemaVersion(schemas[0]);\n\tassertCamelCaseSchema(schemas[0]);\n\tconst inventory = results.find((r) => r.schemas?.length)?.inventory;\n\treturn { schema: schemas[0], inventory: isInventory(inventory) ? inventory : null };\n}\n\n// Shape check only: the plugin built it from the same wire schema. A malformed one is dropped, not\n// fatal, because the schema alone still gates the upload.\nfunction isInventory(value: unknown): value is DocumentInventory {\n\tconst v = value as Partial<DocumentInventory> | null;\n\treturn (\n\t\t!!v &&\n\t\ttypeof v === 'object' &&\n\t\tArray.isArray(v.libraries) &&\n\t\tArray.isArray(v.components) &&\n\t\tArray.isArray(v.values) &&\n\t\tArray.isArray(v.scripts) &&\n\t\ttypeof v.wires?.count === 'number'\n\t);\n}\n\n/**\n * How long an upload waits for the saved values, counted from its start. Compute takes tens of\n * seconds to open a large file, and the whole request has to stay under the 60 s many proxies\n * allow. Missing them costs only the first render its defaults: the render path reads them\n * behind that render.\n */\nconst SAVED_VALUES_WAIT_MS = 45_000;\n\n// Bounds the `/io` request itself, which outlives an upload that stopped waiting for it.\nconst SAVED_VALUES_TIMEOUT_MS = 120_000;\n\n// A check and the upload that follows send the same bytes, so they share one `/io` read: a file\n// too slow for the check's wait is read by the time the upload asks. Keyed by server and content.\nconst savedValueReads = new Map<string, Promise<SavedValues>>();\nconst SAVED_VALUE_READS_MAX = 32;\n\nfunction readSavedValues(\n\tdefinitionBytes: Uint8Array,\n\tserver: ComputeServerConfig\n): Promise<SavedValues> {\n\tconst digest = createHash('sha256').update(definitionBytes).digest('hex');\n\tconst key = `${server.serverUrl}\\n${digest}`;\n\tconst running = savedValueReads.get(key);\n\tif (running) return running;\n\n\tconst read = fetchParsedDefinitionIO(definitionBytes, {\n\t\tserverUrl: server.serverUrl,\n\t\t...(server.apiKey && { apiKey: server.apiKey }),\n\t\ttimeoutMs: SAVED_VALUES_TIMEOUT_MS\n\t}).then((io) => savedValuesFrom(io.inputs));\n\t// A failed read is forgotten, so the next upload of the file asks again.\n\tread.catch(() => {\n\t\tif (savedValueReads.get(key) === read) savedValueReads.delete(key);\n\t});\n\tif (savedValueReads.size >= SAVED_VALUE_READS_MAX)\n\t\tsavedValueReads.delete(savedValueReads.keys().next().value!);\n\tsavedValueReads.set(key, read);\n\treturn read;\n}\n\nexport interface UploadExtraction extends Extraction {\n\t/** The saved values were not read, so `schema` carries the embedded defaults instead. */\n\tdefaultsPending: boolean;\n}\n\n/**\n * `fetchSchemaFromCompute` with the values saved in the file as input defaults, so the stored\n * schema renders without asking Compute again. The values are read beside the schema,\n * best-effort: only the schema gates the upload.\n */\nexport async function extractSchemaForUpload(\n\tdefinitionBytes: Uint8Array,\n\tserver: ComputeServerConfig\n): Promise<UploadExtraction> {\n\tconst startedAt = Date.now();\n\tconst values = readSavedValues(definitionBytes, server);\n\n\tconst { schema, inventory } = await fetchExtraction(definitionBytes, server);\n\tconst saved = await withTimeout(\n\t\tvalues,\n\t\tMath.max(0, SAVED_VALUES_WAIT_MS - (Date.now() - startedAt)),\n\t\t() => new Error('saved values not read in time')\n\t).catch(() => null);\n\treturn {\n\t\tschema: saved ? applySavedValues(schema, saved) : schema,\n\t\tinventory,\n\t\tdefaultsPending: !saved\n\t};\n}\n\n/**\n * The source of the named script components, read by Compute from a stored file. The inventory\n * keeps fingerprints only, so this is how a code diff gets the code. Throws 'unsupported' when the\n * server's plugin cannot read scripts.\n */\nexport async function fetchScriptSources(\n\tdefinitionBytes: Uint8Array,\n\tids: readonly string[],\n\tserver: ComputeServerConfig\n): Promise<ScriptSource[]> {\n\tconst form = new FormData();\n\tform.append('file', new Blob([new Uint8Array(definitionBytes)]), 'definition.gh');\n\tform.append('ids', ids.join(','));\n\tconst headers: Record<string, string> = {};\n\tif (server.apiKey) headers['RhinoComputeKey'] = server.apiKey;\n\n\tlet response: Response;\n\ttry {\n\t\tresponse = await fetch(new URL('/grasshopper/scripts', server.serverUrl), {\n\t\t\tmethod: 'POST',\n\t\t\theaders,\n\t\t\tbody: form\n\t\t});\n\t} catch (err) {\n\t\tthrow new SchemaExtractionError(\n\t\t\t'unreachable',\n\t\t\t`Compute server is unreachable: ${err instanceof Error ? err.message : String(err)}`\n\t\t);\n\t}\n\t// A server without the endpoint answers 404; one whose plugin predates it, 422.\n\tif (response.status === 404 || response.status === 422) {\n\t\tthrow new SchemaExtractionError(\n\t\t\t'unsupported',\n\t\t\t'This Compute server cannot read script source. Update the server and its Selva plugin.'\n\t\t);\n\t}\n\tif (!response.ok) {\n\t\tthrow new SchemaExtractionError(\n\t\t\t'unreachable',\n\t\t\t`Scripts endpoint returned ${response.status}: ${response.statusText}`\n\t\t);\n\t}\n\tconst body = (await response.json()) as ScriptSource[];\n\treturn Array.isArray(body) ? body : [];\n}\n","/**\n * Compute error types, kept in a leaf module with no imports.\n *\n * Separate from the function that throws them on purpose: an error mapper needs\n * nothing but the class to `instanceof` against, and importing it from beside\n * the throw site drags that module's dependencies into every mapper. Anything\n * an error mapper imports belongs here.\n */\n\n/**\n * Thrown when no compute server is configured or visible for the org — a\n * misconfiguration an operator must fix in `/admin/compute`, not a bug. Routes\n * map this to 503 instead of letting the pure helper's plain `Error` surface as\n * a generic 500.\n */\nexport class ComputeServerUnconfiguredError extends Error {\n\tconstructor(\n\t\tmessage = 'No compute server configured. Ask an admin to add one in /admin/compute.'\n\t) {\n\t\tsuper(message);\n\t\tthis.name = 'ComputeServerUnconfiguredError';\n\t}\n}\n"],"mappings":";;;;AASA,SAAgB,gBACf,QACc;CACd,MAAM,yBAAS,IAAI,IAAqB;CACxC,KAAK,MAAM,SAAS,QAAQ;EAC3B,IAAI,MAAM,OAAO,KAAA,KAAa,MAAM,YAAY,KAAA,GAAW;EAC3D,OAAO,IAAI,MAAM,IAAI,MAAM,cAAc,UAAU,WAAW,MAAM,OAAO,IAAI,MAAM,OAAO;CAC7F;CACA,OAAO;AACR;;AAGA,SAAgB,iBAAiB,QAAkB,QAA+B;CACjF,OAAO;EACN,GAAG;EACH,QAAQ,OAAO,OAAO,KAAK,UAC1B,OAAO,IAAI,MAAM,EAAE,IAAI;GAAE,GAAG;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AAI,IAAI,UAAU,yBACrD,IAAI,MAAM,+BAA+B,CAChD,CAAC,CAAC,YAAY,IAAI;CAClB,OAAO;EACN,QAAQ,QAAQ,iBAAiB,QAAQ,KAAK,IAAI;EAClD;EACA,iBAAiB,CAAC;CACnB;AACD;;;;;;AAOA,eAAsB,mBACrB,iBACA,KACA,QAC0B;CAC1B,MAAM,OAAO,IAAI,SAAS;CAC1B,KAAK,OAAO,QAAQ,IAAI,KAAK,CAAC,IAAI,WAAW,eAAe,CAAC,CAAC,GAAG,eAAe;CAChF,KAAK,OAAO,OAAO,IAAI,KAAK,GAAG,CAAC;CAChC,MAAM,UAAkC,CAAC;CACzC,IAAI,OAAO,QAAQ,QAAQ,qBAAqB,OAAO;CAEvD,IAAI;CACJ,IAAI;EACH,WAAW,MAAM,MAAM,IAAI,IAAI,wBAAwB,OAAO,SAAS,GAAG;GACzE,QAAQ;GACR;GACA,MAAM;EACP,CAAC;CACF,SAAS,KAAK;EACb,MAAM,IAAI,sBACT,eACA,kCAAkC,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,GAClF;CACD;CAEA,IAAI,SAAS,WAAW,OAAO,SAAS,WAAW,KAClD,MAAM,IAAI,sBACT,eACA,wFACD;CAED,IAAI,CAAC,SAAS,IACb,MAAM,IAAI,sBACT,eACA,6BAA6B,SAAS,OAAO,IAAI,SAAS,YAC3D;CAED,MAAM,OAAQ,MAAM,SAAS,KAAK;CAClC,OAAO,MAAM,QAAQ,IAAI,IAAI,OAAO,CAAC;AACtC;;;;;;;;;;;;;;;;ACrVA,IAAa,iCAAb,cAAoD,MAAM;CACzD,YACC,UAAU,4EACT;EACD,MAAM,OAAO;EACb,KAAK,OAAO;CACb;AACD"}
|
|
1
|
+
{"version":3,"file":"errors.js","names":["readWrapper"],"sources":["../../../../server/src/definitions/with-timeout.ts","../../../../server/src/definitions/schema-extraction.ts","../../../../server/src/compute/errors.ts"],"sourcesContent":["/**\n * Settles with `work`, or rejects with `onTimeout()` after `ms`. `work` is not cancelled: it runs\n * on, and its later rejection stays handled.\n */\nexport function withTimeout<T>(work: Promise<T>, ms: number, onTimeout: () => Error): Promise<T> {\n\tlet timer: ReturnType<typeof setTimeout> | undefined;\n\tconst timeout = new Promise<never>((_, reject) => {\n\t\ttimer = setTimeout(() => reject(onTimeout()), ms);\n\t});\n\treturn Promise.race([work, timeout]).finally(() => clearTimeout(timer));\n}\n","// Extraction IS validation: a `.gh` with no valid \"Schema\" output, or an\n// unreachable compute server, throws here — which is what makes this the upload\n// gate as well as the render path's fallback for un-cached or stale versions.\n\nimport { createHash } from 'node:crypto';\nimport {\n\tfetchParsedDefinitionIO,\n\tnormalizeUISchemaCasing,\n\treadSchemaResults as readWrapper,\n\ttype SchemaEndpointResult\n} from '@selvajs/compute/grasshopper';\nimport {\n\tUI_SCHEMA_VERSION,\n\ttype DocumentInventory,\n\ttype ScriptSource,\n\ttype UISchema\n} from '@selvajs/schemas';\nimport type { ComputeServerConfig } from '@selvajs/platform';\nimport { applySavedValues, savedValuesFrom, type SavedValues } from './saved-values.js';\nimport { withTimeout } from './with-timeout.js';\n\n/** One entry of the compute schema endpoint's response, typed to our `UISchema`. */\nexport type SchemaExtractionResult = SchemaEndpointResult<UISchema>;\n\n/** Thin re-export of @selvajs/compute's unwrap, typed to `UISchema`. */\nexport function readSchemaResults(raw: unknown): SchemaExtractionResult[] {\n\treturn readWrapper<UISchema>(raw);\n}\n\n/** Thrown when compute is reachable but the definition yields no usable schema. */\nexport class SchemaExtractionError extends Error {\n\tconstructor(\n\t\tpublic readonly kind: 'unreachable' | 'invalid' | 'unsupported' | 'malformed',\n\t\tmessage: string\n\t) {\n\t\tsuper(message);\n\t\tthis.name = 'SchemaExtractionError';\n\t}\n}\n\n/**\n * Rejects a schema whose keys are not camelCase by the time it reaches a consumer.\n *\n * Compute serializes the plugin's `UISchema` POCO, whose camelCase names live in\n * `[JsonProperty]` attributes. `Selva.gha` ILRepack-merges Newtonsoft, so those\n * attributes have type `Selva!Newtonsoft.Json.JsonPropertyAttribute`; a compute\n * server serializing with its OWN Newtonsoft does not recognize them, reads no\n * attributes, and falls back to raw CLR member names — `Inputs`, `Layout`.\n * Nothing throws on the wire: every consumer just reads `schema.inputs` as\n * undefined and renders a definition with no inputs.\n *\n * `postSchemaFormData` repairs that casing via `normalizeUISchemaCasing`, so a\n * schema fresh off the wire never trips this. It stays because schemas are also\n * PERSISTED: a row cached before the normalizer existed still holds PascalCase,\n * and it reaches consumers without passing through `postSchemaFormData` again.\n * A schema with no `inputs` in any casing lands here too. It is a backstop, not\n * the primary defense — which is why it names the missing key rather than telling\n * the operator to go update their compute server.\n *\n * Checked structurally rather than by plugin version, because the casing depends\n * on which assembly serialized the schema, not on any version number.\n */\nexport function assertCamelCaseSchema(schema: UISchema): void {\n\tconst raw = schema as unknown as Record<string, unknown>;\n\tif (Array.isArray(raw.inputs)) return;\n\n\tconst pascalKeys = ['Inputs', 'Outputs', 'Layout', 'SchemaVersion'].filter((k) => k in raw);\n\tif (pascalKeys.length > 0) {\n\t\tthrow new SchemaExtractionError(\n\t\t\t'malformed',\n\t\t\t`Schema keys are PascalCase (found ${pascalKeys.join(', ')}), so every property name ` +\n\t\t\t\t`is wrong and the definition would render with no inputs. Compute serialized it with ` +\n\t\t\t\t`its own Newtonsoft instead of the one merged into Selva.gha. Fresh responses are ` +\n\t\t\t\t`normalized, so this is most likely a schema cached before that fix — re-save the ` +\n\t\t\t\t`definition version to re-extract it.`\n\t\t);\n\t}\n\n\tthrow new SchemaExtractionError(\n\t\t'malformed',\n\t\t`Compute returned a schema with no 'inputs' array (got keys: ${Object.keys(raw)\n\t\t\t.slice(0, 12)\n\t\t\t.join(', ')}).`\n\t);\n}\n\nfunction parseSemver(version: string): [number, number, number] | null {\n\tconst m = /^(\\d+)\\.(\\d+)\\.(\\d+)$/.exec(version);\n\treturn m ? [Number(m[1]), Number(m[2]), Number(m[3])] : null;\n}\n\n/**\n * Orders a schema format version against the app's `UI_SCHEMA_VERSION`: -1 older, 0 current,\n * 1 newer, null unparseable. A missing version is older: plugins before 2.12.0 emitted none.\n */\nexport function compareSchemaVersion(version: string | undefined): -1 | 0 | 1 | null {\n\tif (!version) return -1;\n\tconst extracted = parseSemver(version);\n\tconst supported = parseSemver(UI_SCHEMA_VERSION);\n\tif (!extracted || !supported) return null;\n\tfor (let i = 0; i < 3; i++) {\n\t\tif (extracted[i] !== supported[i]) return extracted[i] < supported[i] ? -1 : 1;\n\t}\n\treturn 0;\n}\n\n/** An older minor or patch of the app's own major: a minor bump only adds optional constructs. */\nexport function isOlderMinorSchemaVersion(version: string | undefined): boolean {\n\tconst extracted = version ? parseSemver(version) : null;\n\tconst supported = parseSemver(UI_SCHEMA_VERSION);\n\tif (!extracted || !supported || extracted[0] !== supported[0]) return false;\n\treturn compareSchemaVersion(version) === -1;\n}\n\n/**\n * Rejects a schema from a NEWER plugin than this app was built against — its\n * shape may contain constructs the renderer doesn't know. Older (or missing)\n * versions pass: the compute-side C# migrator always emits its own current\n * version, and an older shape only lacks optional additions.\n */\nexport function assertSupportedSchemaVersion(schema: UISchema): void {\n\tif (compareSchemaVersion(schema.schemaVersion) === 1) {\n\t\tthrow new SchemaExtractionError(\n\t\t\t'unsupported',\n\t\t\t`This definition was authored with a newer Selva plugin (schema format ${schema.schemaVersion}); ` +\n\t\t\t\t`this server supports schema format ≤ ${UI_SCHEMA_VERSION}. Update the server, or ` +\n\t\t\t\t`re-save the definition with a matching plugin version.`\n\t\t);\n\t}\n}\n\n/**\n * POSTs a multipart form to Rhino Compute's `/grasshopper/schema` endpoint (no\n * solve required). Throws 'unreachable' on a network failure or non-2xx. The\n * per-file `error` Compute reports on its 200-with-no-schemas case is left to\n * the caller — single-file and multi-file callers want different messages.\n */\nexport async function postSchemaFormData(\n\tformData: FormData,\n\tserver: ComputeServerConfig\n): Promise<SchemaExtractionResult[]> {\n\tconst schemaUrl = new URL('/grasshopper/schema', server.serverUrl).toString();\n\n\tconst headers: Record<string, string> = {};\n\tif (server.apiKey) {\n\t\theaders['RhinoComputeKey'] = server.apiKey;\n\t}\n\n\tlet response: Response;\n\ttry {\n\t\tresponse = await fetch(schemaUrl, { method: 'POST', headers, body: formData });\n\t} catch (err) {\n\t\tthrow new SchemaExtractionError(\n\t\t\t'unreachable',\n\t\t\t`Compute server is unreachable: ${err instanceof Error ? err.message : String(err)}`\n\t\t);\n\t}\n\n\tif (!response.ok) {\n\t\tthrow new SchemaExtractionError(\n\t\t\t'unreachable',\n\t\t\t`Schema endpoint returned ${response.status}: ${response.statusText}`\n\t\t);\n\t}\n\n\t// Normalize here rather than in each caller: the upload/validation route reads\n\t// `postSchemaFormData` directly, so a fix applied only inside\n\t// `fetchSchemaFromCompute` would leave that path serving PascalCase schemas.\n\tconst results = readSchemaResults(await response.json());\n\treturn results.map((result) => ({\n\t\t...result,\n\t\tschemas: result.schemas?.map((schema) => normalizeUISchemaCasing(schema))\n\t}));\n}\n\n/**\n * Throws `SchemaExtractionError` so callers can map to the right HTTP status:\n * 503 unreachable / 422 invalid or unsupported.\n */\nexport async function fetchSchemaFromCompute(\n\tdefinitionBytes: Uint8Array,\n\tserver: ComputeServerConfig\n): Promise<UISchema> {\n\treturn (await fetchExtraction(definitionBytes, server)).schema;\n}\n\n/** A file's schema and, from a plugin that builds one, its inventory. */\nexport interface Extraction {\n\tschema: UISchema;\n\tinventory: DocumentInventory | null;\n}\n\n/** `fetchSchemaFromCompute` with the inventory Compute returns beside the schema. */\nexport async function fetchExtraction(\n\tdefinitionBytes: Uint8Array,\n\tserver: ComputeServerConfig\n): Promise<Extraction> {\n\tconst formData = new FormData();\n\tconst blob = new Blob([new Uint8Array(definitionBytes)], { type: 'application/octet-stream' });\n\tformData.append('file', blob, 'definition.gh');\n\n\tconst results = await postSchemaFormData(formData, server);\n\tconst schemas = results.flatMap((r) => r.schemas ?? []);\n\n\tif (schemas.length === 0) {\n\t\t// Compute answers 200 while reporting a per-file `error`, so the\n\t\t// !response.ok guard never fires for it. Surface that message verbatim: it\n\t\t// names the actual cause (bad Schema source, no embedded schema, ...),\n\t\t// which the generic fallback below cannot.\n\t\tconst diagnosis = results.map((r) => r.error).filter(Boolean);\n\t\tif (diagnosis.length > 0) {\n\t\t\tthrow new SchemaExtractionError('invalid', diagnosis.join('\\n'));\n\t\t}\n\n\t\tthrow new SchemaExtractionError(\n\t\t\t'invalid',\n\t\t\t'No schemas found in definition.\\n\\n' +\n\t\t\t\t'In Grasshopper, verify a Context Bake component with the output name \"Schema\" is present and wired to the solver.'\n\t\t);\n\t}\n\n\tassertSupportedSchemaVersion(schemas[0]);\n\tassertCamelCaseSchema(schemas[0]);\n\tconst inventory = results.find((r) => r.schemas?.length)?.inventory;\n\treturn { schema: schemas[0], inventory: isInventory(inventory) ? inventory : null };\n}\n\n// Shape check only: the plugin built it from the same wire schema. A malformed one is dropped, not\n// fatal, because the schema alone still gates the upload.\nfunction isInventory(value: unknown): value is DocumentInventory {\n\tconst v = value as Partial<DocumentInventory> | null;\n\treturn (\n\t\t!!v &&\n\t\ttypeof v === 'object' &&\n\t\tArray.isArray(v.libraries) &&\n\t\tArray.isArray(v.components) &&\n\t\tArray.isArray(v.values) &&\n\t\tArray.isArray(v.scripts) &&\n\t\ttypeof v.wires?.count === 'number'\n\t);\n}\n\n/**\n * How long an upload waits for the saved values, counted from its start. Compute takes tens of\n * seconds to open a large file, and the whole request has to stay under the 60 s many proxies\n * allow. A read still running when the upload answers keeps going, and `savedValuesLater` stores\n * its values on the version when it lands.\n */\nconst SAVED_VALUES_WAIT_MS = 45_000;\n\n// Bounds the `/io` request itself, which outlives an upload that stopped waiting for it.\nconst SAVED_VALUES_TIMEOUT_MS = 120_000;\n\n// A check and the upload that follows send the same bytes, so they share one `/io` read: a file\n// too slow for the check's wait is read by the time the upload asks. Keyed by server and content.\nconst savedValueReads = new Map<string, Promise<SavedValues>>();\nconst SAVED_VALUE_READS_MAX = 32;\n\nfunction readSavedValues(\n\tdefinitionBytes: Uint8Array,\n\tserver: ComputeServerConfig\n): Promise<SavedValues> {\n\tconst digest = createHash('sha256').update(definitionBytes).digest('hex');\n\tconst key = `${server.serverUrl}\\n${digest}`;\n\tconst running = savedValueReads.get(key);\n\tif (running) return running;\n\n\tconst read = fetchParsedDefinitionIO(definitionBytes, {\n\t\tserverUrl: server.serverUrl,\n\t\t...(server.apiKey && { apiKey: server.apiKey }),\n\t\ttimeoutMs: SAVED_VALUES_TIMEOUT_MS\n\t}).then((io) => savedValuesFrom(io.inputs));\n\t// A failed read is forgotten, so the next upload of the file asks again.\n\tread.catch(() => {\n\t\tif (savedValueReads.get(key) === read) savedValueReads.delete(key);\n\t});\n\tif (savedValueReads.size >= SAVED_VALUE_READS_MAX)\n\t\tsavedValueReads.delete(savedValueReads.keys().next().value!);\n\tsavedValueReads.set(key, read);\n\treturn read;\n}\n\nexport interface UploadExtraction extends Extraction {\n\t/** The saved values were not read, so `schema` carries the embedded defaults instead. */\n\tdefaultsPending: boolean;\n\t/** The values saved in the file, to store on the version. Null while `defaultsPending`. */\n\tsavedValues: SavedValues | null;\n\t/** The read still running when `defaultsPending`, to store its values once it lands. */\n\tsavedValuesLater: Promise<SavedValues>;\n}\n\n/**\n * `fetchSchemaFromCompute` with the values saved in the file as input defaults, so the stored\n * schema renders without asking Compute again. The values are read beside the schema,\n * best-effort: only the schema gates the upload.\n */\nexport async function extractSchemaForUpload(\n\tdefinitionBytes: Uint8Array,\n\tserver: ComputeServerConfig\n): Promise<UploadExtraction> {\n\tconst startedAt = Date.now();\n\tconst values = readSavedValues(definitionBytes, server);\n\n\tconst { schema, inventory } = await fetchExtraction(definitionBytes, server);\n\tconst saved = await withTimeout(\n\t\tvalues,\n\t\tMath.max(0, SAVED_VALUES_WAIT_MS - (Date.now() - startedAt)),\n\t\t() => new Error('saved values not read in time')\n\t).catch(() => null);\n\treturn {\n\t\tschema: saved ? applySavedValues(schema, saved) : schema,\n\t\tinventory,\n\t\tdefaultsPending: !saved,\n\t\tsavedValues: saved,\n\t\tsavedValuesLater: values\n\t};\n}\n\n/**\n * The source of the named script components, read by Compute from a stored file. The inventory\n * keeps fingerprints only, so this is how a code diff gets the code. Throws 'unsupported' when the\n * server's plugin cannot read scripts.\n */\nexport async function fetchScriptSources(\n\tdefinitionBytes: Uint8Array,\n\tids: readonly string[],\n\tserver: ComputeServerConfig\n): Promise<ScriptSource[]> {\n\tconst form = new FormData();\n\tform.append('file', new Blob([new Uint8Array(definitionBytes)]), 'definition.gh');\n\tform.append('ids', ids.join(','));\n\tconst headers: Record<string, string> = {};\n\tif (server.apiKey) headers['RhinoComputeKey'] = server.apiKey;\n\n\tlet response: Response;\n\ttry {\n\t\tresponse = await fetch(new URL('/grasshopper/scripts', server.serverUrl), {\n\t\t\tmethod: 'POST',\n\t\t\theaders,\n\t\t\tbody: form\n\t\t});\n\t} catch (err) {\n\t\tthrow new SchemaExtractionError(\n\t\t\t'unreachable',\n\t\t\t`Compute server is unreachable: ${err instanceof Error ? err.message : String(err)}`\n\t\t);\n\t}\n\t// A server without the endpoint answers 404; one whose plugin predates it, 422.\n\tif (response.status === 404 || response.status === 422) {\n\t\tthrow new SchemaExtractionError(\n\t\t\t'unsupported',\n\t\t\t'This Compute server cannot read script source. Update the server and its Selva plugin.'\n\t\t);\n\t}\n\tif (!response.ok) {\n\t\tthrow new SchemaExtractionError(\n\t\t\t'unreachable',\n\t\t\t`Scripts endpoint returned ${response.status}: ${response.statusText}`\n\t\t);\n\t}\n\tconst body = (await response.json()) as ScriptSource[];\n\treturn Array.isArray(body) ? body : [];\n}\n","/**\n * Compute error types, kept in a leaf module with no imports.\n *\n * Separate from the function that throws them on purpose: an error mapper needs\n * nothing but the class to `instanceof` against, and importing it from beside\n * the throw site drags that module's dependencies into every mapper. Anything\n * an error mapper imports belongs here.\n */\n\n/**\n * Thrown when no compute server is configured or visible for the org — a\n * misconfiguration an operator must fix in `/admin/compute`, not a bug. Routes\n * map this to 503 instead of letting the pure helper's plain `Error` surface as\n * a generic 500.\n */\nexport class ComputeServerUnconfiguredError extends Error {\n\tconstructor(\n\t\tmessage = 'No compute server configured. Ask an admin to add one in /admin/compute.'\n\t) {\n\t\tsuper(message);\n\t\tthis.name = 'ComputeServerUnconfiguredError';\n\t}\n}\n"],"mappings":";;;;;;;;;AAIA,SAAgB,YAAe,MAAkB,IAAY,WAAoC;CAChG,IAAI;CACJ,MAAM,UAAU,IAAI,SAAgB,GAAG,WAAW;EACjD,QAAQ,iBAAiB,OAAO,UAAU,CAAC,GAAG,EAAE;CACjD,CAAC;CACD,OAAO,QAAQ,KAAK,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,cAAc,aAAa,KAAK,CAAC;AACvE;;;ACeA,SAAgB,kBAAkB,KAAwC;CACzE,OAAOA,oBAAsB,GAAG;AACjC;;AAGA,IAAa,wBAAb,cAA2C,MAAM;CAE/B;CADjB,YACC,MACA,SACC;EACD,MAAM,OAAO;EAHG,KAAA,OAAA;EAIhB,KAAK,OAAO;CACb;AACD;;;;;;;;;;;;;;;;;;;;;;;AAwBA,SAAgB,sBAAsB,QAAwB;CAC7D,MAAM,MAAM;CACZ,IAAI,MAAM,QAAQ,IAAI,MAAM,GAAG;CAE/B,MAAM,aAAa;EAAC;EAAU;EAAW;EAAU;CAAe,CAAC,CAAC,QAAQ,MAAM,KAAK,GAAG;CAC1F,IAAI,WAAW,SAAS,GACvB,MAAM,IAAI,sBACT,aACA,qCAAqC,WAAW,KAAK,IAAI,EAAE,qTAK5D;CAGD,MAAM,IAAI,sBACT,aACA,+DAA+D,OAAO,KAAK,GAAG,CAAC,CAC7E,MAAM,GAAG,EAAE,CAAC,CACZ,KAAK,IAAI,EAAE,GACd;AACD;AAEA,SAAS,YAAY,SAAkD;CACtE,MAAM,IAAI,wBAAwB,KAAK,OAAO;CAC9C,OAAO,IAAI;EAAC,OAAO,EAAE,EAAE;EAAG,OAAO,EAAE,EAAE;EAAG,OAAO,EAAE,EAAE;CAAC,IAAI;AACzD;;;;;AAMA,SAAgB,qBAAqB,SAAgD;CACpF,IAAI,CAAC,SAA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IAAI,KAAK,GAAG,CAAC;CAChC,MAAM,UAAkC,CAAC;CACzC,IAAI,OAAO,QAAQ,QAAQ,qBAAqB,OAAO;CAEvD,IAAI;CACJ,IAAI;EACH,WAAW,MAAM,MAAM,IAAI,IAAI,wBAAwB,OAAO,SAAS,GAAG;GACzE,QAAQ;GACR;GACA,MAAM;EACP,CAAC;CACF,SAAS,KAAK;EACb,MAAM,IAAI,sBACT,eACA,kCAAkC,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,GAClF;CACD;CAEA,IAAI,SAAS,WAAW,OAAO,SAAS,WAAW,KAClD,MAAM,IAAI,sBACT,eACA,wFACD;CAED,IAAI,CAAC,SAAS,IACb,MAAM,IAAI,sBACT,eACA,6BAA6B,SAAS,OAAO,IAAI,SAAS,YAC3D;CAED,MAAM,OAAQ,MAAM,SAAS,KAAK;CAClC,OAAO,MAAM,QAAQ,IAAI,IAAI,OAAO,CAAC;AACtC;;;;;;;;;;;;;;;;AC3VA,IAAa,iCAAb,cAAoD,MAAM;CACzD,YACC,UAAU,4EACT;EACD,MAAM,OAAO;EACb,KAAK,OAAO;CACb;AACD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// ../compute/dist/handle-files-
|
|
1
|
+
// ../compute/dist/handle-files-BCg3fhxD.js
|
|
2
2
|
var ErrorCodes = {
|
|
3
3
|
/** Connection failure, a gateway status (502/503/504), or a 2xx body cut off mid-stream. */
|
|
4
4
|
NETWORK_ERROR: "NETWORK_ERROR",
|
|
@@ -563,6 +563,11 @@ function parseServerTiming(headerValue) {
|
|
|
563
563
|
if (!Number.isFinite(dur)) continue;
|
|
564
564
|
timing[name] = dur;
|
|
565
565
|
sawMetric = true;
|
|
566
|
+
} else if (name === "proxy_wait") {
|
|
567
|
+
const dur = Number(param(params, "dur"));
|
|
568
|
+
if (!Number.isFinite(dur)) continue;
|
|
569
|
+
timing.wait = dur;
|
|
570
|
+
sawMetric = true;
|
|
566
571
|
} else if (name === "recomputed") {
|
|
567
572
|
const [ran, total] = (param(params, "desc") ?? "").split("/").map(Number);
|
|
568
573
|
if (!Number.isInteger(ran) || !Number.isInteger(total)) continue;
|