@selvajs/selva 4.21.0-beta.14 → 4.21.0-beta.16

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.
Files changed (60) hide show
  1. package/build/adapter-node.js +1 -1
  2. package/build/client/_app/immutable/chunks/BWnVNIyV.js +6085 -0
  3. package/build/client/_app/immutable/chunks/BWnVNIyV.js.br +0 -0
  4. package/build/client/_app/immutable/chunks/BWnVNIyV.js.gz +0 -0
  5. package/build/client/_app/immutable/chunks/Cj8nqfNF.js +1 -0
  6. package/build/client/_app/immutable/chunks/Cj8nqfNF.js.br +1 -0
  7. package/build/client/_app/immutable/chunks/Cj8nqfNF.js.gz +0 -0
  8. package/build/client/_app/immutable/entry/{app.CTLPmTNX.js → app.Dw0M74ME.js} +2 -2
  9. package/build/client/_app/immutable/entry/app.Dw0M74ME.js.br +0 -0
  10. package/build/client/_app/immutable/entry/app.Dw0M74ME.js.gz +0 -0
  11. package/build/client/_app/immutable/nodes/{15.CKO0EYPJ.js → 15.CEROqZ8B.js} +1 -1
  12. package/build/client/_app/immutable/nodes/15.CEROqZ8B.js.br +0 -0
  13. package/build/client/_app/immutable/nodes/15.CEROqZ8B.js.gz +0 -0
  14. package/build/client/_app/immutable/nodes/21.-ms9uSQh.js +1 -0
  15. package/build/client/_app/immutable/nodes/21.-ms9uSQh.js.br +0 -0
  16. package/build/client/_app/immutable/nodes/21.-ms9uSQh.js.gz +0 -0
  17. package/build/client/_app/immutable/nodes/{25.DCzT_X3a.js → 25.C7VDbaM3.js} +19 -18
  18. package/build/client/_app/immutable/nodes/25.C7VDbaM3.js.br +0 -0
  19. package/build/client/_app/immutable/nodes/{25.DCzT_X3a.js.gz → 25.C7VDbaM3.js.gz} +0 -0
  20. package/build/client/_app/version.json +1 -1
  21. package/build/client/_app/version.json.br +0 -0
  22. package/build/client/_app/version.json.gz +0 -0
  23. package/build/server/chunks/errors.js +30 -11
  24. package/build/server/chunks/errors.js.map +1 -1
  25. package/build/server/chunks/handlers.js +25 -6
  26. package/build/server/chunks/handlers.js.map +1 -1
  27. package/build/server/chunks/instance.js +3 -3
  28. package/build/server/chunks/internal.js +1 -1
  29. package/build/server/chunks/package.js +1 -1
  30. package/build/server/chunks/package.js.map +1 -1
  31. package/build/server/chunks/update-outcome.js +24 -7
  32. package/build/server/chunks/update-outcome.js.map +1 -1
  33. package/build/server/entries/endpoints/api/admin/system/update/_server.ts.js +99 -25
  34. package/build/server/entries/endpoints/api/admin/system/update/_server.ts.js.map +1 -1
  35. package/build/server/entries/pages/library/_guid_/_page.svelte.js +46 -13
  36. package/build/server/entries/pages/library/_guid_/_page.svelte.js.map +1 -1
  37. package/build/server/entries/pages/projects/_page.svelte.js +5 -0
  38. package/build/server/entries/pages/projects/_page.svelte.js.map +1 -1
  39. package/build/server/manifest-full.js +1 -1
  40. package/build/server/manifest.js +1 -1
  41. package/build/server/nodes/15.js +1 -1
  42. package/build/server/nodes/21.js +1 -1
  43. package/build/server/nodes/25.js +1 -1
  44. package/build/server/server.js +1 -1
  45. package/package.json +5 -5
  46. package/templates/ecosystem.config.cjs +2 -0
  47. package/build/client/_app/immutable/chunks/CCHz3Pcq.js +0 -1
  48. package/build/client/_app/immutable/chunks/CCHz3Pcq.js.br +0 -1
  49. package/build/client/_app/immutable/chunks/CCHz3Pcq.js.gz +0 -0
  50. package/build/client/_app/immutable/chunks/CVA0v6Z8.js +0 -6085
  51. package/build/client/_app/immutable/chunks/CVA0v6Z8.js.br +0 -0
  52. package/build/client/_app/immutable/chunks/CVA0v6Z8.js.gz +0 -0
  53. package/build/client/_app/immutable/entry/app.CTLPmTNX.js.br +0 -0
  54. package/build/client/_app/immutable/entry/app.CTLPmTNX.js.gz +0 -0
  55. package/build/client/_app/immutable/nodes/15.CKO0EYPJ.js.br +0 -0
  56. package/build/client/_app/immutable/nodes/15.CKO0EYPJ.js.gz +0 -0
  57. package/build/client/_app/immutable/nodes/21.CFGMFbJt.js +0 -1
  58. package/build/client/_app/immutable/nodes/21.CFGMFbJt.js.br +0 -1
  59. package/build/client/_app/immutable/nodes/21.CFGMFbJt.js.gz +0 -0
  60. package/build/client/_app/immutable/nodes/25.DCzT_X3a.js.br +0 -0
Binary file
@@ -1,5 +1,6 @@
1
1
  import { t as UI_SCHEMA_VERSION } from "./schema.js";
2
2
  import { a as fetchParsedDefinitionIO, o as normalizeUISchemaCasing, s as readSchemaResults$1 } from "./grasshopper.js";
3
+ import { createHash } from "node:crypto";
3
4
  // ../server/src/definitions/saved-values.ts
4
5
  function savedValuesFrom(inputs) {
5
6
  const values = /* @__PURE__ */ new Map();
@@ -180,28 +181,46 @@ function isInventory(value) {
180
181
  return !!v && typeof v === "object" && Array.isArray(v.libraries) && Array.isArray(v.components) && Array.isArray(v.values) && Array.isArray(v.scripts) && typeof v.wires?.count === "number";
181
182
  }
182
183
  /**
183
- * How long an upload waits for the saved values once the schema is in. Missing them costs only
184
- * the first render its defaults: the render path reads them behind that render.
184
+ * How long an upload waits for the saved values, counted from its start. Compute takes tens of
185
+ * seconds to open a large file, and the whole request has to stay under the 60 s many proxies
186
+ * allow. Missing them costs only the first render its defaults: the render path reads them
187
+ * behind that render.
185
188
  */
186
- var SAVED_VALUES_GRACE_MS = 5e3;
189
+ var SAVED_VALUES_WAIT_MS = 45e3;
187
190
  var SAVED_VALUES_TIMEOUT_MS = 12e4;
191
+ var savedValueReads = /* @__PURE__ */ new Map();
192
+ var SAVED_VALUE_READS_MAX = 32;
193
+ function readSavedValues(definitionBytes, server) {
194
+ const digest = createHash("sha256").update(definitionBytes).digest("hex");
195
+ const key = `${server.serverUrl}\n${digest}`;
196
+ const running = savedValueReads.get(key);
197
+ if (running) return running;
198
+ const read = fetchParsedDefinitionIO(definitionBytes, {
199
+ serverUrl: server.serverUrl,
200
+ ...server.apiKey && { apiKey: server.apiKey },
201
+ timeoutMs: SAVED_VALUES_TIMEOUT_MS
202
+ }).then((io) => savedValuesFrom(io.inputs));
203
+ read.catch(() => {
204
+ if (savedValueReads.get(key) === read) savedValueReads.delete(key);
205
+ });
206
+ if (savedValueReads.size >= SAVED_VALUE_READS_MAX) savedValueReads.delete(savedValueReads.keys().next().value);
207
+ savedValueReads.set(key, read);
208
+ return read;
209
+ }
188
210
  /**
189
211
  * `fetchSchemaFromCompute` with the values saved in the file as input defaults, so the stored
190
212
  * schema renders without asking Compute again. The values are read beside the schema,
191
213
  * best-effort: only the schema gates the upload.
192
214
  */
193
215
  async function extractSchemaForUpload(definitionBytes, server) {
194
- const values = fetchParsedDefinitionIO(definitionBytes, {
195
- serverUrl: server.serverUrl,
196
- ...server.apiKey && { apiKey: server.apiKey },
197
- timeoutMs: SAVED_VALUES_TIMEOUT_MS
198
- }).then((io) => savedValuesFrom(io.inputs));
199
- values.catch(() => {});
216
+ const startedAt = Date.now();
217
+ const values = readSavedValues(definitionBytes, server);
200
218
  const { schema, inventory } = await fetchExtraction(definitionBytes, server);
201
- const saved = await withTimeout(values, SAVED_VALUES_GRACE_MS, () => /* @__PURE__ */ new Error("saved values not read in time")).catch(() => null);
219
+ const saved = await withTimeout(values, Math.max(0, SAVED_VALUES_WAIT_MS - (Date.now() - startedAt)), () => /* @__PURE__ */ new Error("saved values not read in time")).catch(() => null);
202
220
  return {
203
221
  schema: saved ? applySavedValues(schema, saved) : schema,
204
- inventory
222
+ inventory,
223
+ defaultsPending: !saved
205
224
  };
206
225
  }
207
226
  /**
@@ -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 {\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 } 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 once the schema is in. Missing them costs only\n * the first render its defaults: the render path reads them behind that render.\n */\nconst SAVED_VALUES_GRACE_MS = 5_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/**\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<Extraction> {\n\tconst values = 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\tvalues.catch(() => {});\n\n\tconst { schema, inventory } = await fetchExtraction(definitionBytes, server);\n\tconst saved = await withTimeout(\n\t\tvalues,\n\t\tSAVED_VALUES_GRACE_MS,\n\t\t() => new Error('saved values not read in time')\n\t).catch(() => null);\n\treturn { schema: saved ? applySavedValues(schema, saved) : schema, inventory };\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,KAA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AO,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;;;;;;;;;;;;;;;;AChTA,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/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;GAAO,SAAS,OAAO,IAAI,MAAM,EAAE;EAAE,IAAI,KACtE;CACD;AACD;AAGA,SAAS,WAAW,OAAyB;CAC5C,MAAM,QAAQ,OAAO,KAAK,CAAC,CACzB,MAAM,GAAG,CAAC,CACV,KAAK,MAAM,SAAS,EAAE,KAAK,GAAG,EAAE,CAAC;CACnC,MAAM,OAAO,MAAc,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG;CACzD,IAAI,MAAM,WAAW,GAAG,OAAO,I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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"}
@@ -958,8 +958,24 @@ var refOf = (v) => v ? {
958
958
  id: v.id,
959
959
  versionNumber: v.versionNumber
960
960
  } : null;
961
- /** Null without a base, or when the base predates schema caching. */
962
- var changesFrom = (base, schema) => base?.schema && schema ? diffSchemas(base.schema, schema) : null;
961
+ /**
962
+ * Null without a base, or when the base predates schema caching. With `defaultsPending` the new
963
+ * file's saved values are unknown, not removed, so its defaults compare as the base's.
964
+ */
965
+ function changesFrom(base, schema, defaultsPending = false) {
966
+ if (!base?.schema || !schema) return null;
967
+ return diffSchemas(base.schema, defaultsPending ? withDefaultsOf(schema, base.schema) : schema);
968
+ }
969
+ function withDefaultsOf(schema, base) {
970
+ const defaults = new Map(base.inputs.map((input) => [input.id, input.default]));
971
+ return {
972
+ ...schema,
973
+ inputs: schema.inputs.map((input) => defaults.has(input.id) ? {
974
+ ...input,
975
+ default: defaults.get(input.id)
976
+ } : input)
977
+ };
978
+ }
963
979
  function inventoryReport(inventory, schema, base) {
964
980
  if (!inventory) return null;
965
981
  const formIds = [...schema?.inputs ?? [], ...base?.schema?.inputs ?? []].map((i) => i.id);
@@ -1002,7 +1018,7 @@ async function readVersionUpload(req, guid) {
1002
1018
  const { ctx, record, project } = await requireEditableDefinition(req, guid);
1003
1019
  const data = new Uint8Array(await file.arrayBuffer());
1004
1020
  const server = await resolveServerForOrg(ctx, project?.orgId ?? null, req.deps.computeServer, { definitionPin: record.computeServerId ?? null });
1005
- const { schema, inventory } = await extractSchemaForUpload(data, server);
1021
+ const { schema, inventory, defaultsPending } = await extractSchemaForUpload(data, server);
1006
1022
  return {
1007
1023
  ctx,
1008
1024
  record,
@@ -1011,6 +1027,7 @@ async function readVersionUpload(req, guid) {
1011
1027
  data,
1012
1028
  schema,
1013
1029
  inventory,
1030
+ defaultsPending,
1014
1031
  changeNote,
1015
1032
  acceptMissingPlugins
1016
1033
  };
@@ -1020,7 +1037,7 @@ async function readVersionUpload(req, guid) {
1020
1037
  * then a diff against the version it would follow. Writes nothing.
1021
1038
  */
1022
1039
  var checkVersion = async (req) => {
1023
- const { ctx, record, schema, inventory } = await readVersionUpload(req, parseParam(req.params.guid, GuidSchema, "GUID"));
1040
+ const { ctx, record, schema, inventory, defaultsPending } = await readVersionUpload(req, parseParam(req.params.guid, GuidSchema, "GUID"));
1024
1041
  const base = await loadBase(req, ctx, record);
1025
1042
  return { body: {
1026
1043
  schema: {
@@ -1029,7 +1046,8 @@ var checkVersion = async (req) => {
1029
1046
  outputs: schema.outputs?.length ?? 0
1030
1047
  },
1031
1048
  base: refOf(base),
1032
- changes: changesFrom(base, schema),
1049
+ changes: changesFrom(base, schema, defaultsPending),
1050
+ defaultsPending,
1033
1051
  inventory: inventoryReport(inventory, schema, base)
1034
1052
  } };
1035
1053
  };
@@ -1044,7 +1062,8 @@ var uploadVersion = async (req) => {
1044
1062
  return created({
1045
1063
  version,
1046
1064
  base: refOf(base),
1047
- changes: changesFrom(base, schema),
1065
+ changes: changesFrom(base, schema, upload.defaultsPending),
1066
+ defaultsPending: upload.defaultsPending,
1048
1067
  inventory: inventoryReport(inventory, schema, base)
1049
1068
  });
1050
1069
  };