@pipelex/mthds-form 0.13.0 → 0.14.0

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 (40) hide show
  1. package/README.md +11 -0
  2. package/dist/{chunk-IR3OFSGD.js → chunk-2EGRONBV.js} +3 -3
  3. package/dist/{chunk-IR3OFSGD.js.map → chunk-2EGRONBV.js.map} +1 -1
  4. package/dist/{chunk-D2EQVWGN.js → chunk-7JRT6ZII.js} +1631 -171
  5. package/dist/chunk-7JRT6ZII.js.map +1 -0
  6. package/dist/{chunk-7KQXGG6J.js → chunk-ICUEHNEH.js} +19 -6
  7. package/dist/chunk-ICUEHNEH.js.map +1 -0
  8. package/dist/{chunk-DARLDVJM.js → chunk-JIGRWJTV.js} +2 -2
  9. package/dist/chunk-JIGRWJTV.js.map +1 -0
  10. package/dist/chunk-VH5CDQDR.js +41 -0
  11. package/dist/chunk-VH5CDQDR.js.map +1 -0
  12. package/dist/{chunk-G6SFMTL4.js → chunk-VT5E5W4E.js} +4 -3
  13. package/dist/chunk-VT5E5W4E.js.map +1 -0
  14. package/dist/{chunk-MJQ7CXUB.js → chunk-XO5OENNF.js} +25 -4
  15. package/dist/chunk-XO5OENNF.js.map +1 -0
  16. package/dist/core/gate.js +2 -2
  17. package/dist/core/index.d.ts +2 -1
  18. package/dist/core/index.js +6 -5
  19. package/dist/core/output-form.d.ts +5 -4
  20. package/dist/core/output-form.js +1 -1
  21. package/dist/core/readiness.d.ts +47 -2
  22. package/dist/core/readiness.js +1 -1
  23. package/dist/core/save-plan.d.ts +31 -1
  24. package/dist/core/save-plan.js +1 -1
  25. package/dist/core/seed.d.ts +56 -0
  26. package/dist/core/seed.js +5 -0
  27. package/dist/core/seed.js.map +1 -0
  28. package/dist/core/values.js +2 -2
  29. package/dist/generative/index.d.ts +2 -11
  30. package/dist/generative/index.js +11 -17
  31. package/dist/generative/index.js.map +1 -1
  32. package/dist/react/index.d.ts +699 -192
  33. package/dist/react/index.js +9 -3
  34. package/dist/styles.css +1 -1
  35. package/package.json +3 -1
  36. package/dist/chunk-7KQXGG6J.js.map +0 -1
  37. package/dist/chunk-D2EQVWGN.js.map +0 -1
  38. package/dist/chunk-DARLDVJM.js.map +0 -1
  39. package/dist/chunk-G6SFMTL4.js.map +0 -1
  40. package/dist/chunk-MJQ7CXUB.js.map +0 -1
@@ -106,12 +106,25 @@ function pathOf(url) {
106
106
  return url.split(/[?#]/)[0] ?? url;
107
107
  }
108
108
  function safeName(name) {
109
- const printable = Array.from(name).filter((character) => {
109
+ const trimmed = (printable(name).split(/[/\\]/).pop() ?? "").trim();
110
+ return trimmed === "." || trimmed === ".." ? "" : trimmed;
111
+ }
112
+ function printable(name) {
113
+ return Array.from(name).filter((character) => {
110
114
  const code = character.charCodeAt(0);
111
115
  return code > 31 && code !== 127;
112
116
  }).join("");
113
- const trimmed = (printable.split(/[/\\]/).pop() ?? "").trim();
114
- return trimmed === "." || trimmed === ".." ? "" : trimmed;
117
+ }
118
+ function splitFileName(name) {
119
+ const extension = name.match(/\.[A-Za-z0-9]{1,8}$/)?.[0] ?? "";
120
+ return extension && extension.length < name.length ? { stem: name.slice(0, -extension.length), extension } : { stem: name, extension: "" };
121
+ }
122
+ function typedFileStem(typed, extension) {
123
+ let stem = printable(typed).replace(/[/\\:*?"<>|]/g, "-").trim();
124
+ if (extension && stem.toLowerCase().endsWith(extension.toLowerCase())) {
125
+ stem = stem.slice(0, -extension.length);
126
+ }
127
+ return stem.replace(/^[.\s]+/, "").replace(/[.\s]+$/, "").trim();
115
128
  }
116
129
  function jsonCopy(value) {
117
130
  const text = JSON.stringify(
@@ -122,6 +135,6 @@ function jsonCopy(value) {
122
135
  return text ?? "null";
123
136
  }
124
137
 
125
- export { planFileSave, planStuffSave };
126
- //# sourceMappingURL=chunk-7KQXGG6J.js.map
127
- //# sourceMappingURL=chunk-7KQXGG6J.js.map
138
+ export { planFileSave, planStuffSave, splitFileName, typedFileStem };
139
+ //# sourceMappingURL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CAAA,EAAG,CAAC,SAAA,CAAU,MAAM,GAAG,SAAA,EAAU,GACpD,EAAE,IAAA,EAAM,IAAA,EAAM,WAAW,EAAA,EAAG;AAClC;AAoBO,SAAS,aAAA,CAAc,OAAe,SAAA,EAA2B;AACtE,EAAA,IAAI,IAAA,GAAO,UAAU,KAAK,CAAA,CACvB,QAAQ,eAAA,EAAiB,GAAG,EAC5B,IAAA,EAAK;AACR,EAAA,IAAI,SAAA,IAAa,KAAK,WAAA,EAAY,CAAE,SAAS,SAAA,CAAU,WAAA,EAAa,CAAA,EAAG;AACrE,IAAA,IAAA,GAAO,IAAA,CAAK,KAAA,CAAM,CAAA,EAAG,CAAC,UAAU,MAAM,CAAA;AAAA,EACxC;AACA,EAAA,OAAO,IAAA,CACJ,QAAQ,SAAA,EAAW,EAAE,EACrB,OAAA,CAAQ,SAAA,EAAW,EAAE,CAAA,CACrB,IAAA,EAAK;AACV;AAOA,SAAS,SAAS,KAAA,EAAwB;AACxC,EAAA,MAAM,OAAO,IAAA,CAAK,SAAA;AAAA,IAChB,KAAA;AAAA,IACA,CAAC,MAAM,MAAA,KAAqB,OAAO,WAAW,QAAA,GAAW,MAAA,CAAO,UAAS,GAAI,MAAA;AAAA,IAC7E;AAAA,GACF;AACA,EAAA,OAAO,IAAA,IAAQ,MAAA;AACjB","file":"chunk-ICUEHNEH.js","sourcesContent":["import { dataUrlExtensions, readDataUrl, viewableUrl } from './native-content';\nimport { collectStuffFiles, type StuffFile, type StuffFileKind } from './stuff-files';\nimport type { RunField } from './descriptor';\n\n/**\n * What saving a result MEANS, decided with no DOM: which files, what each is\n * called, what type it is, and where its bytes are.\n *\n * ## Why the plan is separate from the delivery\n *\n * Handing bytes to a reader is the part that depends on where the view runs.\n * An ordinary browser tab saves through an object URL and a clicked link; a\n * view inside a sandboxed frame is refused all of that and has to ask its host\n * to do it, typically by passing links and inline contents across a bridge that\n * fetches the links itself. What to save is the same answer in both places, so\n * it is computed once, here, and a delivery only has to carry it out. The\n * default browser delivery lives in `./react`; a host supplies its own through\n * `ResultEnvProvider`'s `saveFiles`. See docs/result-view.md § \"Saving a\n * result\".\n *\n * ## Why a planned file carries a URL rather than bytes\n *\n * A host's download bridge takes links and fetches them itself, which is also\n * what keeps a cross-origin fetch out of a frame that cannot make one. So a\n * stored file is planned as the URL the gate admitted, and only the default\n * browser delivery fetches it. Content the stuff carries inline (the JSON copy\n * of the data, an HTML page) is planned as its text.\n */\n\n/** What a planned file is: one of the stuff's own files, or the JSON copy of its data. */\nexport type SaveFileKind = StuffFileKind | 'data';\n\ninterface SaveFileCommon {\n /**\n * What to save it as: a bare file name, never a path. The file's own\n * `filename` when it states one, else the base name and the file's place\n * below the result's root (`report-figures-0-image.png`), or the base name\n * alone for a file that is the whole result (`output.png`). No two files in\n * one plan share a name, compared without case.\n */\n name: string;\n /**\n * The media type. For a `data:` URL it is the type the gate admitted; for any\n * other URL it is what the payload states, or what the name's extension\n * implies, or `application/octet-stream` when nothing says.\n */\n mimeType: string;\n kind: SaveFileKind;\n /** Where it sat in the result, dotted (`output.figures.0.image`); the root's name for the JSON copy. */\n path: string;\n}\n\n/**\n * One file to hand to the reader: exactly one of `url` and `text` is set.\n *\n * `url` is the string the URL gate returned, after the host's resolver was\n * asked first, so a delivery never acts on a member nothing judged. It may be a\n * root-relative path, which a planner with no document cannot resolve; the\n * result view makes one absolute against its own document before a delivery\n * sees it. `text` is content the result carries inline.\n */\nexport type SaveFile =\n | (SaveFileCommon & { url: string; text?: undefined })\n | (SaveFileCommon & { text: string; url?: undefined });\n\n/** A file the result holds that cannot be saved, because no URL the gate admits was found for it. */\nexport interface UnavailableFile {\n /** What it would have been saved as, so the reader can be told which one. */\n name: string;\n kind: StuffFileKind;\n path: string;\n}\n\n/** Everything saving a whole result involves. */\nexport interface SavePlan {\n /** What to deliver, in the order the result shows it, the JSON copy last. */\n files: SaveFile[];\n /**\n * What the result holds and cannot be delivered. The JSON copy still carries\n * each one's reference, so the reader keeps it even without the bytes.\n */\n unavailable: UnavailableFile[];\n}\n\n/** A file a delivery did not hand over, and why when it knows. */\nexport interface SaveFailure {\n file: SaveFile;\n reason?: string;\n}\n\n/**\n * What a delivery reports. Every planned file not listed in `failed` was\n * delivered, so an empty list means everything went out.\n */\nexport interface SaveResult {\n failed: SaveFailure[];\n}\n\n/**\n * How files reach the reader. The default saves them in the browser; a host\n * whose view runs in a sandboxed frame supplies one that asks the host to.\n *\n * It resolves rather than rejects when a file does not go out, and names that\n * file in `failed`, so the control that asked can tell the reader. A throw or\n * a rejection is read as every file having failed.\n */\nexport type SaveFiles = (files: readonly SaveFile[]) => Promise<SaveResult>;\n\nexport interface SavePlanOptions {\n /**\n * Names the whole stuff: the JSON copy is `<baseName>.json`, a file with no\n * name of its own below the root is `<baseName>-<place>`, and a file that is\n * the whole stuff is `<baseName>.<ext>`.\n */\n baseName: string;\n /** The same resolver the result view paints through, asked before the payload's own URLs. */\n resolveUrl?: (url: string) => string | undefined;\n}\n\n/**\n * Everything a stuff contains, planned for saving.\n *\n * The data goes down as JSON, and any image, document or HTML page inside it\n * goes down as ITSELF: a JSON file holding a URL to a picture is not the\n * picture, and a reader who saves a report with three attachments wants the\n * three attachments.\n *\n * The JSON copy is planned whenever the stuff is anything more than one file. A\n * result that IS one image has nothing left over once the image is saved, so\n * `{\"url\": …}` beside it would be a second file saying less than the first. That\n * holds only when the image can be saved: a bare file the gate refuses leaves\n * the JSON copy as the one thing the reader gets, because it still carries the\n * reference.\n */\nexport function planStuffSave(field: RunField, value: unknown, options: SavePlanOptions): SavePlan {\n const found = collectStuffFiles(field, value);\n const files: SaveFile[] = [];\n const unavailable: UnavailableFile[] = [];\n for (const file of found) {\n const planned = planFileSave(file, options);\n if (planned) files.push(planned);\n else\n unavailable.push({ name: nameFor(file, options.baseName), kind: file.kind, path: file.path });\n }\n\n // A stuff that is nothing BUT one file, read from the collector rather than\n // from `field.kind`: a `native.Html` node's kind is `object`, and the whole\n // stuff is still the page.\n const isBareFile = found.length === 1 && found[0]?.path === field.name;\n if (isBareFile && files.length === 1) return { files, unavailable };\n\n const jsonName = `${safeName(options.baseName) || 'result'}.json`;\n return {\n files: [\n ...distinctNames(files, jsonName),\n {\n name: jsonName,\n mimeType: 'application/json',\n kind: 'data',\n path: field.name,\n text: jsonCopy(value),\n },\n ],\n unavailable,\n };\n}\n\n/**\n * The plan's files with no two sharing a name, and none taking the JSON copy's.\n *\n * A name derived from a file's place is unique by construction, but a name the\n * payload states is not: two documents a method wrote as `scan.pdf`, or one it\n * called `report.json` beside the JSON copy of `report`. A browser suffixes a\n * duplicate download itself, but a host's delivery may write the names as given,\n * into a folder or an archive, where the second file silently replaces the\n * first. So the first file keeps its name and each later one gets a number\n * before its extension (`scan-2.pdf`), compared without case, as the file\n * systems readers mostly use compare them.\n *\n * That is the whole plan's concern: a file's own button saves one file, which\n * collides with nothing, under its own name.\n */\nfunction distinctNames(files: readonly SaveFile[], reserved: string): SaveFile[] {\n const taken = new Set([reserved.toLowerCase()]);\n return files.map((file) => {\n let name = file.name;\n for (let count = 2; taken.has(name.toLowerCase()); count += 1) {\n name = numbered(file.name, count);\n }\n taken.add(name.toLowerCase());\n return name === file.name ? file : { ...file, name };\n });\n}\n\n/** `scan.pdf` as `scan-2.pdf`: the number before the extension, so the type still reads. */\nfunction numbered(name: string, count: number): string {\n const extension = extensionOf(name);\n return extension\n ? `${name.slice(0, -(extension.length + 1))}-${count}.${name.slice(-extension.length)}`\n : `${name}-${count}`;\n}\n\n/**\n * One file, planned on its own — what a file's own download button saves.\n *\n * The file's `path` starts at the root's name, as `collectStuffFiles` builds\n * it: the name leaves that first segment out, because the base name already\n * stands for the root.\n *\n * `undefined` when the file cannot be saved: a stored reference the host's\n * resolver does not answer and no URL the gate admits beside it. The button is\n * not drawn then, so a reader is never offered a download that cannot happen.\n */\nexport function planFileSave(file: StuffFile, options: SavePlanOptions): SaveFile | undefined {\n const common = { kind: file.kind, path: file.path };\n if (file.text !== undefined) {\n return {\n ...common,\n name: nameFor(file, options.baseName),\n mimeType: 'text/html',\n text: file.text,\n };\n }\n // Judged by the same gate the result view paints through, in the same\n // durability order: the host's resolver over the durable reference first,\n // then `public_url`, then the reference itself. What the gate returns is what\n // is planned, never the raw member.\n const url =\n viewableUrl(options.resolveUrl?.(file.url ?? '')) ??\n viewableUrl(file.publicUrl) ??\n viewableUrl(file.url);\n if (!url) return undefined;\n const encoded = readDataUrl(url);\n if (encoded) {\n // A `data:` URL is its own file, and the gate admitted it for its declared\n // type alone. That type names it: the payload's `filename` and the tail of\n // the payload are both the payload's say, and a `data:image/png` URL saved\n // under `image.html` is a page that runs when the reader opens it.\n return {\n ...common,\n name: nameFor(file, options.baseName, dataUrlExtensions(encoded.mediaType)),\n mimeType: encoded.mediaType,\n url,\n };\n }\n const name = nameFor(file, options.baseName);\n return { ...common, name, mimeType: file.mimeType ?? typeForName(name), url };\n}\n\n/** The type a name's extension implies, for a stored file whose payload states none. */\nconst TYPE_FOR_EXTENSION: Readonly<Record<string, string>> = {\n png: 'image/png',\n jpg: 'image/jpeg',\n jpeg: 'image/jpeg',\n gif: 'image/gif',\n webp: 'image/webp',\n avif: 'image/avif',\n svg: 'image/svg+xml',\n pdf: 'application/pdf',\n html: 'text/html',\n};\n\nfunction typeForName(name: string): string {\n const extension = name.match(/\\.([A-Za-z0-9]{1,8})$/)?.[1]?.toLowerCase();\n return (extension && TYPE_FOR_EXTENSION[extension]) || 'application/octet-stream';\n}\n\n/**\n * What a saved file is called.\n *\n * The file's own `filename` wins when it has one: it is the name the producer\n * chose and the reader recognises. Otherwise the base name and the file's place\n * below the root name it (`report-attachments-2`), which is unlovely but\n * unambiguous, since two images from one result must not both land as\n * `image.png` and overwrite each other in the download folder.\n *\n * The path's first segment is left out because it is always the root's name,\n * and the base name already stands for the root, as it does in `<base>.json`:\n * keeping it would save the one image a pipe outputs as `output-output.png`. A\n * file that IS the root has no place below it and is named by the base name\n * alone. Every segment is a field's name or an index, neither of which holds a\n * dot, so splitting on dots recovers them.\n *\n * `allowed` is set for a `data:` URL, whose admitted type is the only thing\n * allowed to decide the extension: a name carrying one of those extensions\n * keeps it, and any other extension is replaced by the type's own.\n */\nfunction nameFor(file: StuffFile, base: string, allowed?: readonly string[]): string {\n const own = file.filename ? safeName(file.filename) : '';\n const place = file.path.split('.').slice(1).join('-');\n const named = safeName(base) || 'result';\n const stem = own || (place ? `${named}-${place}` : named);\n const stated = own ? extensionOf(own) : '';\n if (allowed) {\n if (stated && allowed.includes(stated)) return stem;\n const bare = stated ? stem.slice(0, -(stated.length + 1)) : stem;\n const extension = allowed[0];\n return extension ? `${bare}.${extension}` : bare;\n }\n if (own) return own;\n const extension = file.extension ?? extensionOf(pathOf(file.url ?? ''));\n return extension ? `${stem}.${extension}` : stem;\n}\n\n/** The extension a name ends in, lowercased, or none. Never guessed from the bytes. */\nfunction extensionOf(name: string): string {\n return name.match(/\\.([A-Za-z0-9]{1,8})$/)?.[1]?.toLowerCase() ?? '';\n}\n\n/** A URL without its query and fragment, so `x.png?sig=…` still ends in `.png`. */\nfunction pathOf(url: string): string {\n return url.split(/[?#]/)[0] ?? url;\n}\n\n/**\n * A name safe to hand a delivery: its last path segment, without control\n * characters, trimmed. A browser sanitises a download name itself, but a host's\n * bridge may write it to disk as given, and a payload's `filename` is the\n * payload's say. Empty when nothing is left.\n */\nfunction safeName(name: string): string {\n const trimmed = (printable(name).split(/[/\\\\]/).pop() ?? '').trim();\n return trimmed === '.' || trimmed === '..' ? '' : trimmed;\n}\n\n/** The name without its control characters, which no file system wants in a name. */\nfunction printable(name: string): string {\n return Array.from(name)\n .filter((character) => {\n const code = character.charCodeAt(0);\n return code > 0x1f && code !== 0x7f;\n })\n .join('');\n}\n\n/**\n * A planned name split at its extension, the way the plan reads one:\n * `devis.pdf` is `devis` and `.pdf`, `report.final.html` is `report.final` and\n * `.html`, and a name with no extension of one to eight letters and digits is\n * all stem. The extension keeps its dot, so a name rebuilt from the two halves\n * is the name.\n */\nexport function splitFileName(name: string): { stem: string; extension: string } {\n const extension = name.match(/\\.[A-Za-z0-9]{1,8}$/)?.[0] ?? '';\n return extension && extension.length < name.length\n ? { stem: name.slice(0, -extension.length), extension }\n : { stem: name, extension: '' };\n}\n\n/**\n * The name a reader typed for a file, made safe the way a planned name is, and\n * a little stricter, since this one is typed rather than produced.\n *\n * Control characters go, as from every planned name. A path separator is\n * REPLACED rather than cut at: a planned name keeps its last path segment\n * because a payload's `filename` may be a path, but a reader who types\n * `Devis 12/2026` means a name, and keeping `2026` alone would throw away what\n * they wrote. The characters a common file system refuses in a name\n * (`: * ? \" < > |`) are replaced the same way, with a hyphen, because a host's\n * bridge may write the name to disk as given. Leading dots go, so the file is\n * not hidden, and trailing dots and spaces, which one file system drops\n * silently. A copy of the extension the reader typed at the end is dropped,\n * since the extension is added back after it: `devis.pdf` stays `devis.pdf`\n * rather than becoming `devis.pdf.pdf`.\n *\n * Empty when nothing is left, which the caller reads as \"keep the planned name\".\n */\nexport function typedFileStem(typed: string, extension: string): string {\n let stem = printable(typed)\n .replace(/[/\\\\:*?\"<>|]/g, '-')\n .trim();\n if (extension && stem.toLowerCase().endsWith(extension.toLowerCase())) {\n stem = stem.slice(0, -extension.length);\n }\n return stem\n .replace(/^[.\\s]+/, '')\n .replace(/[.\\s]+$/, '')\n .trim();\n}\n\n/**\n * The data as JSON, the way the JSON view shows it. A BigInt, which a JSON\n * parser configured to produce one can hand over, is written as its digits\n * rather than failing the whole save.\n */\nfunction jsonCopy(value: unknown): string {\n const text = JSON.stringify(\n value,\n (_key, member: unknown) => (typeof member === 'bigint' ? member.toString() : member),\n 2,\n );\n return text ?? 'null';\n}\n"]}
@@ -12,5 +12,5 @@ function getPipeOutputForm(outputForm, domain, pipeCode) {
12
12
  }
13
13
 
14
14
  export { getPipeOutputForm };
15
- //# sourceMappingURL=chunk-DARLDVJM.js.map
16
- //# sourceMappingURL=chunk-DARLDVJM.js.map
15
+ //# sourceMappingURL=chunk-JIGRWJTV.js.map
16
+ //# sourceMappingURL=chunk-JIGRWJTV.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/output-form.ts"],"names":[],"mappings":";;;;AA8CO,SAAS,iBAAA,CACd,UAAA,EACA,MAAA,EACA,QAAA,EACsC;AACtC,EAAA,IAAI,CAAC,UAAA,IAAc,CAAC,QAAA,EAAU,OAAO,MAAA;AACrC,EAAA,IAAI,MAAA,EAAQ;AACV,IAAA,MAAM,QAAQ,OAAA,CAAQ,UAAA,EAAY,YAAA,CAAa,MAAA,EAAQ,QAAQ,CAAC,CAAA;AAChE,IAAA,IAAI,OAAO,OAAO,KAAA;AAAA,EACpB;AACA,EAAA,OAAO,OAAA,CAAQ,YAAY,QAAQ,CAAA;AACrC","file":"chunk-JIGRWJTV.js","sourcesContent":["/**\n * The output-form descriptor lookup.\n *\n * **This module used to declare the artifact; now it only addresses it.** The\n * types come from `mthds/protocol`, exactly as the input side's do — the\n * protocol package grew `output_form` and `json_schema` on the output contract\n * in the same version, `mthds` 0.25.0, so a renderer reads both off the wire\n * instead of having them supplied beside it. What is left here is the twin of\n * `getPipeInputForm`: the lookup, and the tolerance for the same two key\n * conventions. [docs/contract-mirror.md](../../docs/contract-mirror.md) states\n * the rule this now obeys — the contract types are the standard's, not this\n * package's, and a member this package wants on one is a change to the standard\n * before it is a change here.\n *\n * **An output is a concept ref exactly like an input is.** Same concept, same\n * structure, same field kinds, same nesting; what differs is only the three SLOT\n * facts an output has none of (an authored `name`, the three-valued `presence`,\n * `gating`), all three optional on the standard's node precisely so a node can\n * exist without them. That is why `buildResultField` maps an output node through\n * the very mapper `buildRunFields` uses, and why there is no second node union\n * anywhere in this package.\n *\n * | | Inputs | Outputs |\n * | --- | --- | --- |\n * | identity, plurality, optionality | `pipe_io_contracts` | `pipe_io_contracts` |\n * | shape / JSON Schema | `json_schema` on the input contract | `json_schema` on the output contract |\n * | presentation view | `input_form` | `output_form` |\n *\n * The two rows that used to read \"nothing\" are the change this package was built\n * against while it was still a proposal. The standard has the `output_form`\n * page and has yet to write `json_schema` into its output contract\n * (L-260902-d45673). The one asymmetry the language keeps is\n * `presence` versus `optional`: `!` MUST NOT appear on an output, so a\n * three-valued output marker would have an arm nothing could ever produce.\n */\n\nimport type { OutputForm, PipeOutputFormDescriptor } from 'mthds/protocol';\nimport { buildPipeRef } from './contracts';\nimport { ownProp } from './own-property';\n\nexport type { OutputForm, PipeOutputFormDescriptor };\n\n/**\n * Look a pipe's output descriptor up by code — the exact twin of\n * `getPipeInputForm`, tolerant of the same two key conventions.\n */\nexport function getPipeOutputForm(\n outputForm: OutputForm | null | undefined,\n domain: string | null | undefined,\n pipeCode: string | null | undefined,\n): PipeOutputFormDescriptor | undefined {\n if (!outputForm || !pipeCode) return undefined;\n if (domain) {\n const byRef = ownProp(outputForm, buildPipeRef(domain, pipeCode));\n if (byRef) return byRef;\n }\n return ownProp(outputForm, pipeCode);\n}\n"]}
@@ -0,0 +1,41 @@
1
+ import { isOptionalStructure, optionalStructureOpen } from './chunk-XO5OENNF.js';
2
+ import { ownProp } from './chunk-V3OV2XQT.js';
3
+
4
+ // src/core/seed.ts
5
+ function isRecord(value) {
6
+ return typeof value === "object" && value !== null && !Array.isArray(value);
7
+ }
8
+ function seedInputs(fields) {
9
+ const seed = {};
10
+ for (const field of fields) {
11
+ if (field.defaultValue !== void 0) {
12
+ seed[field.name] = field.defaultValue;
13
+ } else if (field.kind === "object" && field.required) {
14
+ const nested = seedInputs(field.fields);
15
+ if (Object.keys(nested).length > 0) seed[field.name] = nested;
16
+ }
17
+ }
18
+ return seed;
19
+ }
20
+ function seedObjectValue(field) {
21
+ if (isRecord(field.defaultValue)) return { ...field.defaultValue };
22
+ return seedInputs(field.fields);
23
+ }
24
+ function openOptionalStructures(fields, values) {
25
+ const out = { ...values };
26
+ for (const field of fields) {
27
+ if (isOptionalStructure(field) && !optionalStructureOpen(ownProp(values, field.name))) {
28
+ out[field.name] = seedObjectValue(field);
29
+ }
30
+ }
31
+ return out;
32
+ }
33
+ function closeOptionalStructures(fields, values) {
34
+ const out = { ...values };
35
+ for (const field of fields) if (isOptionalStructure(field)) out[field.name] = void 0;
36
+ return out;
37
+ }
38
+
39
+ export { closeOptionalStructures, openOptionalStructures, seedInputs, seedObjectValue };
40
+ //# sourceMappingURL=chunk-VH5CDQDR.js.map
41
+ //# sourceMappingURL=chunk-VH5CDQDR.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/seed.ts"],"names":[],"mappings":";;;;AAWA,SAAS,SAAS,KAAA,EAAkD;AAClE,EAAA,OAAO,OAAO,UAAU,QAAA,IAAY,KAAA,KAAU,QAAQ,CAAC,KAAA,CAAM,QAAQ,KAAK,CAAA;AAC5E;AAoBO,SAAS,WAAW,MAAA,EAAsD;AAC/E,EAAA,MAAM,OAAgC,EAAC;AACvC,EAAA,KAAA,MAAW,SAAS,MAAA,EAAQ;AAC1B,IAAA,IAAI,KAAA,CAAM,iBAAiB,MAAA,EAAW;AACpC,MAAA,IAAA,CAAK,KAAA,CAAM,IAAI,CAAA,GAAI,KAAA,CAAM,YAAA;AAAA,IAC3B,CAAA,MAAA,IAAW,KAAA,CAAM,IAAA,KAAS,QAAA,IAAY,MAAM,QAAA,EAAU;AACpD,MAAA,MAAM,MAAA,GAAS,UAAA,CAAW,KAAA,CAAM,MAAM,CAAA;AACtC,MAAA,IAAI,MAAA,CAAO,KAAK,MAAM,CAAA,CAAE,SAAS,CAAA,EAAG,IAAA,CAAK,KAAA,CAAM,IAAI,CAAA,GAAI,MAAA;AAAA,IACzD;AAAA,EACF;AACA,EAAA,OAAO,IAAA;AACT;AAYO,SAAS,gBAAgB,KAAA,EAAgD;AAC9E,EAAA,IAAI,QAAA,CAAS,MAAM,YAAY,CAAA,SAAU,EAAE,GAAG,MAAM,YAAA,EAAa;AACjE,EAAA,OAAO,UAAA,CAAW,MAAM,MAAM,CAAA;AAChC;AAOO,SAAS,sBAAA,CACd,QACA,MAAA,EACyB;AACzB,EAAA,MAAM,GAAA,GAA+B,EAAE,GAAG,MAAA,EAAO;AACjD,EAAA,KAAA,MAAW,SAAS,MAAA,EAAQ;AAC1B,IAAA,IAAI,mBAAA,CAAoB,KAAK,CAAA,IAAK,CAAC,qBAAA,CAAsB,QAAQ,MAAA,EAAQ,KAAA,CAAM,IAAI,CAAC,CAAA,EAAG;AACrF,MAAA,GAAA,CAAI,KAAA,CAAM,IAAI,CAAA,GAAI,eAAA,CAAgB,KAAK,CAAA;AAAA,IACzC;AAAA,EACF;AACA,EAAA,OAAO,GAAA;AACT;AAOO,SAAS,uBAAA,CACd,QACA,MAAA,EACyB;AACzB,EAAA,MAAM,GAAA,GAA+B,EAAE,GAAG,MAAA,EAAO;AACjD,EAAA,KAAA,MAAW,KAAA,IAAS,QAAQ,IAAI,mBAAA,CAAoB,KAAK,CAAA,EAAG,GAAA,CAAI,KAAA,CAAM,IAAI,CAAA,GAAI,MAAA;AAC9E,EAAA,OAAO,GAAA;AACT","file":"chunk-VH5CDQDR.js","sourcesContent":["/**\n * Seeding a form from the method's authored defaults.\n *\n * Pure module: no React, no DOM - a server building a payload and a control\n * opening an optional structure read the same answer from here.\n */\n\nimport type { ObjectRunField, RunField } from './descriptor';\nimport { ownProp } from './own-property';\nimport { isOptionalStructure, optionalStructureOpen } from './readiness';\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * The `/inputs` seed: the authored defaults, and nothing else.\n *\n * A defaulted field carries `defaultValue` (never the `null` a schema\n * projection attaches to an optional field); a structure's defaults sit inside\n * it. What is NOT seeded is an empty string or a zero for an unfilled field -\n * the kernel's readiness treats an absent value as absent, and a seeded\n * placeholder would count as filled.\n *\n * **An optional structure is not descended into.** Its presence is a choice the\n * person makes with the \"+ N optional\" disclosure it folds behind (see\n * `isOptionalStructure`), so a seed that put its children's defaults inside it would make that choice\n * for them: the structure would arrive open and be sent, merely because its\n * concept declares defaults. It is seeded only when the structure itself\n * carries an authored default; otherwise it stays absent, and turning it on\n * seeds it then, through `seedObjectValue`. A host that wants it open from the\n * start puts `seedObjectValue(field)` at its path.\n */\nexport function seedInputs(fields: readonly RunField[]): Record<string, unknown> {\n const seed: Record<string, unknown> = {};\n for (const field of fields) {\n if (field.defaultValue !== undefined) {\n seed[field.name] = field.defaultValue;\n } else if (field.kind === 'object' && field.required) {\n const nested = seedInputs(field.fields);\n if (Object.keys(nested).length > 0) seed[field.name] = nested;\n }\n }\n return seed;\n}\n\n/**\n * The value a structured field holds the moment it is opened: the\n * structure's own authored default when it carries an object one, otherwise\n * an object seeded from its children's defaults by `seedInputs` - which is `{}`\n * when none of them declares one. Always a plain object, so the disclosure that\n * reads the value back (`optionalStructureOpen`) reads open.\n *\n * Optional structures beneath it stay absent, by `seedInputs`' own rule: each\n * opens with its own container's disclosure.\n */\nexport function seedObjectValue(field: ObjectRunField): Record<string, unknown> {\n if (isRecord(field.defaultValue)) return { ...field.defaultValue };\n return seedInputs(field.fields);\n}\n\n/**\n * What expanding a \"+ N optional\" disclosure writes: `values` with every\n * CLOSED optional structure among `fields` opened to `seedObjectValue(field)`.\n * Open ones and every other field are kept as they are. Returns a new object.\n */\nexport function openOptionalStructures(\n fields: readonly RunField[],\n values: Record<string, unknown> | undefined,\n): Record<string, unknown> {\n const out: Record<string, unknown> = { ...values };\n for (const field of fields) {\n if (isOptionalStructure(field) && !optionalStructureOpen(ownProp(values, field.name))) {\n out[field.name] = seedObjectValue(field);\n }\n }\n return out;\n}\n\n/**\n * What collapsing a \"+ N optional\" disclosure writes: `values` with every\n * optional structure among `fields` closed to `undefined`, so each leaves the\n * payload. Every other field is kept as it is. Returns a new object.\n */\nexport function closeOptionalStructures(\n fields: readonly RunField[],\n values: Record<string, unknown> | undefined,\n): Record<string, unknown> {\n const out: Record<string, unknown> = { ...values };\n for (const field of fields) if (isOptionalStructure(field)) out[field.name] = undefined;\n return out;\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { buildRunFields } from './chunk-ZB4RYUKV.js';
2
2
  import { inflateAllInputs, deflateAllInputs } from './chunk-GCXV76WU.js';
3
- import { isFilled } from './chunk-MJQ7CXUB.js';
3
+ import { isFilled, isOptionalStructure, optionalStructureOpen } from './chunk-XO5OENNF.js';
4
4
  import { isOptionalInput, isPluralInput } from './chunk-WYH56SOZ.js';
5
5
  import { ownProp } from './chunk-V3OV2XQT.js';
6
6
 
@@ -63,6 +63,7 @@ function fromRjsf(field, value) {
63
63
  return typeof value === "string" && value ? { url: value } : void 0;
64
64
  }
65
65
  case "object": {
66
+ if (isOptionalStructure(field) && !optionalStructureOpen(value)) return void 0;
66
67
  const obj = value && typeof value === "object" ? value : {};
67
68
  const out = {};
68
69
  for (const child of field.fields) out[child.name] = fromRjsf(child, ownProp(obj, child.name));
@@ -197,5 +198,5 @@ function setValueAtPath(root, path, value) {
197
198
  }
198
199
 
199
200
  export { apiInputsFromRunValues, fieldsForContract, inputDataFromWorkingMemory, outputsFromPipeOutput, rjsfDataFromRunValues, runValuesFromStore, setValueAtPath, storeInputDataFromRunValues };
200
- //# sourceMappingURL=chunk-G6SFMTL4.js.map
201
- //# sourceMappingURL=chunk-G6SFMTL4.js.map
201
+ //# sourceMappingURL=chunk-VT5E5W4E.js.map
202
+ //# sourceMappingURL=chunk-VT5E5W4E.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/values.ts"],"names":[],"mappings":";;;;;;;AA+CA,SAAS,WAAA,CAAY,OAAiB,KAAA,EAAyB;AAC7D,EAAA,OAAO,KAAA,CAAM,eAAe,MAAA,GAAY,KAAA,GAAQ,EAAE,CAAC,KAAA,CAAM,UAAU,GAAG,KAAA,EAAM;AAC9E;AAOA,SAAS,aAAA,CAAc,OAAiB,KAAA,EAAyB;AAC/D,EAAA,MAAM,MAAM,KAAA,CAAM,UAAA;AAClB,EAAA,IAAI,GAAA,KAAQ,UAAa,CAAC,KAAA,IAAS,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA;AACjF,IAAA,OAAO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AAC/E","file":"chunk-VT5E5W4E.js","sourcesContent":["/**\n * Bridges the `MethodRunner`'s field values to the rest of the host.\n *\n * The method-store keeps inputs in the *simplified* format and runs send the\n * *full* RJSF form shape - both already handled by `inflate/deflateAllInputs`.\n * The only gap is that a few field controls use a friendlier value than RJSF: a\n * scalar is the bare scalar where the full shape is the content model its\n * concept declares (`{ text }`, `{ number }`, `{ yes_no }`), and a file is\n * `{ url, filename }`. `fromRjsf`/`toRjsf` translate just those, so store\n * reads/writes and run payloads stay byte-for-byte compatible with the proven\n * playground path.\n *\n * Which property a scalar wraps into is NOT decided here - it arrives on the\n * descriptor as `contentKey`, derived from the contract by `buildRunFields`.\n *\n * Pure module - no React, unit-tested.\n */\nimport type { PipeInputFormDescriptor } from 'mthds/protocol';\n\nimport type { RunField } from './descriptor';\nimport { buildRunFields } from './derive';\nimport { ownProp } from './own-property';\nimport { isFilled, isOptionalStructure, optionalStructureOpen } from './readiness';\nimport { isOptionalInput, isPluralInput } from './contracts';\nimport { deflateAllInputs, inflateAllInputs } from './wire-format';\nimport type { PipeIOContract, PipeInputContract } from './contracts';\n\ntype Dict = Record<string, unknown>;\ntype InputSchemas = Record<string, PipeInputContract>;\n\n// ─── RJSF full shape ↔ RunField value ──────────────────────────────────────\n\n/**\n * Put a scalar back inside the content model its concept declares:\n * `\"hi\"` → `{ text: \"hi\" }`, `2` → `{ number: 2 }`, `false` → `{ yes_no: false }`.\n *\n * The property name comes from the DESCRIPTOR (`contentKey`, stamped by\n * `buildRunFields` - the only reader of JSON Schema). This module holds no\n * taxonomy of its own, which is the point: the version that did held a list of\n * concepts that wrap, `native.Number` was missing from it, and every run\n * carrying a number was rejected by the gate against `NumberContent`.\n *\n * A field with no `contentKey` keeps its value plain. That is not an oversight\n * either - a child property of a structured concept, or a custom concept whose\n * schema is a bare string, IS its value, and wrapping it double-nests it\n * (`{ text: { text } }`) into a payload no schema accepts.\n */\nfunction wrapContent(field: RunField, value: unknown): unknown {\n return field.contentKey === undefined ? value : { [field.contentKey]: value };\n}\n\n/**\n * The inverse. A value that is already bare passes through untouched: persisted\n * `inputData` predates the number and yes/no wrappers, and an inputs.json\n * written by hand or by an agent says `2`, not `{number: 2}`.\n */\nfunction unwrapContent(field: RunField, value: unknown): unknown {\n const key = field.contentKey;\n if (key === undefined || !value || typeof value !== 'object' || Array.isArray(value))\n return value;\n return ownProp(value as Record<string, unknown>, key);\n}\n\n/** How deep a nested `{ text: … }` / `{ content: … }` chain we bother unwrapping. */\nconst MAX_UNWRAP_DEPTH = 8;\n\n/**\n * Pull a plain string out of whatever the store hands a text field.\n *\n * Persisted `inputData` carries historical corruptions - a double-wrapped\n * `{ text: { text } }`, a `{ concept, content }` envelope that was never\n * deflated - and the old fallback ran `String()` over them, which renders the\n * literal `\"[object Object]\"` into the textarea. That is worse than showing\n * nothing: it looks exactly like content the user typed, and one keystroke\n * later it is content the user typed. So unwrap the envelopes we know, and give\n * up with `undefined` (an empty field) rather than displaying garbage.\n *\n * Genuine primitives still stringify - a number or a boolean in a text slot is\n * a value, not a wrapper.\n *\n * The envelope names here are the HISTORICAL corruptions, not the wrapper key:\n * the declared wrapper is stripped by `unwrapContent` first, off the field's\n * `contentKey`, exactly as the number and boolean paths do. A text wrapper\n * whose property is not literally `text` would otherwise read back empty - and\n * one save later, BE empty.\n */\nfunction textFromStored(value: unknown, depth = 0): string | undefined {\n if (value == null) return undefined;\n if (typeof value === 'string') return value;\n if (typeof value === 'number' || typeof value === 'boolean') return String(value);\n if (typeof value !== 'object' || depth >= MAX_UNWRAP_DEPTH) return undefined;\n const envelope = value as { text?: unknown; content?: unknown };\n if ('text' in envelope) return textFromStored(envelope.text, depth + 1);\n if ('content' in envelope) return textFromStored(envelope.content, depth + 1);\n return undefined;\n}\n\n/** RJSF full form value → the runner's field value. */\nfunction fromRjsf(field: RunField, value: unknown): unknown {\n switch (field.kind) {\n case 'text':\n case 'prose':\n return textFromStored(unwrapContent(field, value));\n case 'number': {\n // The control holds `number | undefined`. A numeric STRING is tolerated\n // because that is what a hand-written inputs.json tends to carry; anything\n // else empties the field rather than feeding NaN to a number input.\n const raw = unwrapContent(field, value);\n if (typeof raw === 'number') return Number.isFinite(raw) ? raw : undefined;\n if (typeof raw === 'string' && raw.trim() !== '') {\n const parsed = Number(raw);\n return Number.isFinite(parsed) ? parsed : undefined;\n }\n return undefined;\n }\n case 'boolean': {\n // Strictly a real boolean, deliberately: pipelex declares `YesNoContent.\n // yes_no` with `strict=True` precisely to refuse \"yes\"/1/\"true\", and\n // coercing here would smuggle back in what the runtime closed off.\n const raw = unwrapContent(field, value);\n return typeof raw === 'boolean' ? raw : undefined;\n }\n case 'unknown':\n // The escape hatch is a raw-JSON textarea, so a structured value belongs\n // there as JSON - `String(value)` would have shown \"[object Object]\" and\n // thrown the actual value away.\n if (typeof value === 'string') return value;\n if (value == null) return undefined;\n if (typeof value === 'object') {\n try {\n return JSON.stringify(value, null, 2);\n } catch {\n return undefined;\n }\n }\n return String(value);\n case 'document':\n case 'image': {\n if (value && typeof value === 'object') {\n const o = value as { url?: unknown; filename?: unknown };\n return o.url\n ? { url: String(o.url), filename: o.filename as string | undefined }\n : undefined;\n }\n return typeof value === 'string' && value ? { url: value } : undefined;\n }\n case 'object': {\n // An optional structure the store holds no object for - absent, or the\n // `null` a stored run writes for a structure it went without - stays\n // CLOSED. Materializing a shell of `undefined` children here reopened it:\n // `optionalStructureOpen` reads any plain object as open, so a run reloaded\n // from the store showed every structure it had left out as opened and\n // blank. A required structure has no closed state, and keeps its shell.\n if (isOptionalStructure(field) && !optionalStructureOpen(value)) return undefined;\n const obj = (value && typeof value === 'object' ? value : {}) as Dict;\n const out: Dict = {};\n for (const child of field.fields) out[child.name] = fromRjsf(child, ownProp(obj, child.name));\n return out;\n }\n case 'list': {\n const arr = Array.isArray(value) ? value : [];\n return arr.map((item) => fromRjsf(field.item, item));\n }\n default:\n return value;\n }\n}\n\n/**\n * The runner's field value → RJSF full form value (what runs/store expect).\n *\n * `collapseEmpty` is what a SINGULAR slot does and a LIST ITEM must not: an\n * untouched structure in a singular slot is absent, but an item exists only\n * because the user added it, so adding IS the touch. Only the structure case\n * reads the flag.\n */\nfunction toRjsf(field: RunField, value: unknown, collapseEmpty = true): unknown {\n switch (field.kind) {\n case 'text':\n case 'prose':\n return wrapContent(field, typeof value === 'string' ? value : '');\n case 'number':\n // An untouched number stays ABSENT rather than becoming an empty wrapper.\n // The gate then does the right thing on both counts: it prunes an absent\n // optional input, and it reports a required one as missing by name -\n // where `{number: undefined}` would read as a malformed value instead.\n return typeof value === 'number' && Number.isFinite(value)\n ? wrapContent(field, value)\n : undefined;\n case 'boolean':\n // `false` is a value, not an absence - hence the type test rather than a\n // truthiness one.\n return typeof value === 'boolean' ? wrapContent(field, value) : undefined;\n case 'unknown':\n return typeof value === 'string' ? value : '';\n case 'document':\n case 'image': {\n const url = value && typeof value === 'object' ? (value as { url?: unknown }).url : value;\n const filename =\n value && typeof value === 'object' ? (value as { filename?: unknown }).filename : undefined;\n return { url: url ? String(url) : '', ...(filename ? { filename } : {}) };\n }\n case 'object': {\n const obj = (value && typeof value === 'object' ? value : {}) as Dict;\n const out: Dict = {};\n for (const child of field.fields) out[child.name] = toRjsf(child, ownProp(obj, child.name));\n // A structure nobody put anything into stays ABSENT, exactly as an\n // untouched number does above - it does NOT become a shell of empty\n // children. Materializing that shell made an OPTIONAL structured input\n // unrunnable whenever its concept declared a required child: readiness\n // ignored the input (correctly - the method said it may be omitted), Run\n // lit up, and the gate then judged an object the kernel had invented\n // against the concept's full schema and rejected the run for a child the\n // user was never asked to fill.\n //\n // Emptiness is `isFilled`, the SAME predicate readiness and the wire\n // payload use, so the three cannot disagree about whether this input is\n // there. Which also says what the touch is NOT: opening the optional\n // disclosure is local view state the value never sees, so a section\n // opened and left blank collapses exactly like one never opened. What\n // keeps a structure is a VALUE in it - and then the whole shell survives,\n // empty children and all, so a required child left blank still fails, and\n // loudly.\n return collapseEmpty && !isFilled(out) ? undefined : out;\n }\n case 'list': {\n const arr = Array.isArray(value) ? value : [];\n // An item is NEVER absent: it is in the array because the user added it,\n // and `ListField`'s \"Add\" seeds an object item with `{}`. Letting it\n // collapse the way an untouched singular slot does put `undefined` in the\n // array, which ajv rejects as `must be object` - blocking an empty item\n // the item schema allowed, and turning a required-child complaint into a\n // type error that names nothing the user can act on.\n return arr.map((item) => toRjsf(field.item, item, false));\n }\n default:\n return value;\n }\n}\n\n// ─── Store ↔ RunField values ──────────────────────────────────────────────\n\n/** Seed the runner's form values from the method-store's simplified inputData. */\nexport function runValuesFromStore(\n inputData: Dict | undefined,\n fields: RunField[],\n inputSchemas: InputSchemas,\n): Dict {\n const full = inflateAllInputs(inputData ?? {}, inputSchemas);\n const out: Dict = {};\n for (const field of fields) out[field.name] = fromRjsf(field, ownProp(full, field.name));\n return out;\n}\n\n/**\n * The runner's form values in **schema shape** - the same shape an RJSF panel\n * holds, and therefore the shape `gate.ts` validates against the per-input\n * JSON Schemas.\n *\n * Deliberately stops short of `deflateAllInputs`: deflation is the STORE's\n * compact form, and ajv validates the full one.\n */\nexport function rjsfDataFromRunValues(values: Dict, fields: RunField[]): Dict {\n const full: Dict = {};\n for (const field of fields) full[field.name] = toRjsf(field, ownProp(values, field.name));\n return full;\n}\n\n/** Convert the runner's form values back to the store's simplified inputData. */\nexport function storeInputDataFromRunValues(\n values: Dict,\n fields: RunField[],\n inputSchemas: InputSchemas,\n): Dict {\n return deflateAllInputs(rjsfDataFromRunValues(values, fields), inputSchemas);\n}\n\n/**\n * Build the `{ concept, content }` map a run expects from the form values.\n *\n * The two ways a method says \"this may be nothing\" land differently on the wire,\n * and both matter:\n * - an **optional (`?`)** input left blank is OMITTED, so the runtime records a\n * real absence the method can branch on - sending `{ text: \"\" }` would look\n * like the caller supplied an empty string;\n * - a **plural (`[]`)** input keeps its key, because a plural slot is never\n * absent - its empty form IS the empty list, and the runtime requires the key.\n * When that list is EMPTY it is sent BARE, without the envelope: the envelope\n * is the runtime's \"explicit form\", which bypasses the top-down shaper and\n * hands the value to the bottom-up factory, and that factory types a list from\n * its first item - so an empty list there raises \"Cannot create Stuff from\n * empty list in content\". The bare form keeps the shaper, which reads the\n * DECLARED concept and builds the empty list correctly. (pipelex/#1096 makes\n * the envelope agree; the bare form runs today and stays correct after.)\n */\nexport function apiInputsFromRunValues(\n values: Dict,\n fields: RunField[],\n inputSchemas: InputSchemas,\n): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n for (const field of fields) {\n const schema = ownProp(inputSchemas, field.name);\n if (!schema) continue;\n const value = ownProp(values, field.name);\n if (isOptionalInput(schema) && !isFilled(value)) continue;\n if (isPluralInput(schema) && !isFilled(value)) {\n out[field.name] = [];\n continue;\n }\n out[field.name] = { concept: schema.concept_ref, content: toRjsf(field, value) };\n }\n return out;\n}\n\n// ─── Pipe output → result entries ────────────────────────────────────────────\n\n/** One named output pulled out of a run's working memory, ready to render. */\nexport interface OutputEntry {\n /** The output variable key (mono). */\n key: string;\n conceptRef?: string;\n value: unknown;\n}\n\n/**\n * The slice of a serialized pipe output this module actually reads. Structural\n * on purpose: the SDK's `DictPipeOutput` is the host's wire type, and the kernel\n * must not depend on `@pipelex/sdk` - the guard below verifies the shape at\n * runtime anyway.\n */\ninterface PipeOutputWithWorkingMemory {\n working_memory: {\n root: Record<string, unknown>;\n aliases?: Record<string, string>;\n };\n}\n\nfunction hasWorkingMemoryRoot(value: unknown): value is PipeOutputWithWorkingMemory {\n return (\n !!value &&\n typeof value === 'object' &&\n 'working_memory' in value &&\n !!(value as { working_memory?: { root?: unknown } }).working_memory &&\n typeof (value as { working_memory: { root?: unknown } }).working_memory.root === 'object'\n );\n}\n\n/** The concept code of a working-memory entry (`{concept}` may be obj/str/absent). */\nfunction entryConceptRef(data: unknown): string | undefined {\n if (!data || typeof data !== 'object') return undefined;\n const raw = (data as { concept?: unknown; concept_code?: unknown }).concept;\n if (raw && typeof raw === 'object')\n return (\n ((raw as { concept_code?: string }).concept_code ?? (raw as { code?: string }).code) ||\n undefined\n );\n if (typeof raw === 'string') return raw;\n return (data as { concept_code?: string }).concept_code || undefined;\n}\n\n/**\n * Split a run's pipe output into the main result and any intermediate outputs,\n * excluding the inputs. The main output's identity comes from the working\n * memory's `main_stuff` alias (the authoritative pointer to the output variable)\n * - so its label is the REAL stuff name, not a positional guess. Falls back to\n * the last produced stuff only when the alias is absent.\n */\nexport function outputsFromPipeOutput(\n pipeOutput: unknown,\n inputKeys: string[],\n): { main: OutputEntry; intermediates: OutputEntry[] } | null {\n if (!hasWorkingMemoryRoot(pipeOutput)) return null;\n const wm = pipeOutput.working_memory as {\n root: Record<string, unknown>;\n aliases?: Record<string, string>;\n };\n const entries = Object.entries(wm.root).filter(([key]) => !inputKeys.includes(key));\n if (entries.length === 0) return null;\n\n const toEntry = ([key, data]: [string, unknown]): OutputEntry => ({\n key,\n conceptRef: entryConceptRef(data),\n value: (data as { content?: unknown })?.content ?? data,\n });\n\n // The real main-output name: `aliases.main_stuff` → its root key.\n const mainKey = wm.aliases?.['main_stuff'];\n const mainEntry: [string, unknown] =\n mainKey && Object.prototype.hasOwnProperty.call(wm.root, mainKey)\n ? [mainKey, wm.root[mainKey]]\n : entries[entries.length - 1]!;\n const intermediates = entries.filter(([key]) => key !== mainEntry[0]).map(toEntry);\n\n return { main: toEntry(mainEntry), intermediates };\n}\n\n/**\n * Recover the inputs a run was executed with from its working memory. The run's\n * `working_memory.root` holds every named stuff - inputs AND outputs - keyed by\n * variable name; we pull the entries whose keys are declared inputs and deflate\n * their `content` (the full form shape) back into the store's simplified\n * `inputData`. Lets the runner repopulate the form for a past/shared run - the\n * inputs that produced the result. Returns `null` when no inputs are present.\n */\nexport function inputDataFromWorkingMemory(\n workingMemory: unknown,\n inputSchemas: InputSchemas,\n): Dict | null {\n const root = (workingMemory as { root?: Record<string, unknown> } | null | undefined)?.root;\n if (!root || typeof root !== 'object') return null;\n const full: Dict = {};\n let found = false;\n for (const key of Object.keys(inputSchemas)) {\n const entry = ownProp(root, key);\n if (entry && typeof entry === 'object' && 'content' in entry) {\n full[key] = (entry as { content: unknown }).content;\n found = true;\n }\n }\n if (!found) return null;\n return deflateAllInputs(full, inputSchemas);\n}\n\n/**\n * Field descriptors for a method's main pipe - the wire descriptor mapped over\n * the contract, or `[]` while either artifact has not arrived yet. The\n * descriptor comes back from `validate` beside `pipe_io_contracts` when the\n * request opts in with `views: [\"input_form\"]`; `getPipeInputForm` is the\n * lookup that matches `getPipeIOContract`.\n */\nexport function fieldsForContract(\n contract: PipeIOContract | undefined,\n descriptor: PipeInputFormDescriptor | undefined,\n): RunField[] {\n return contract?.inputs && descriptor ? buildRunFields(descriptor, contract.inputs) : [];\n}\n\n/**\n * Immutably set a value at a dotted/indexed path (`a.0.b`). Used to write an\n * uploaded file's URL back to a field anywhere in the (possibly nested) tree.\n */\nexport function setValueAtPath(root: Dict, path: string[], value: unknown): Dict {\n const head = path[0];\n if (head === undefined) return root;\n const rest = path.slice(1);\n if (rest.length === 0) return { ...root, [head]: value };\n\n const nextSeg = rest[0] as string;\n const child = root[head];\n if (/^\\d+$/.test(nextSeg)) {\n const arr = Array.isArray(child) ? child.slice() : [];\n const idx = Number(nextSeg);\n arr[idx] =\n rest.length === 1 ? value : setValueAtPath((arr[idx] as Dict) ?? {}, rest.slice(1), value);\n return { ...root, [head]: arr };\n }\n return { ...root, [head]: setValueAtPath((child as Dict) ?? {}, rest, value) };\n}\n"]}
@@ -24,7 +24,10 @@ function fieldFilled(field, value) {
24
24
  if (field.kind === "object") {
25
25
  if (!isFilled(value)) return false;
26
26
  const obj = value ?? {};
27
- return field.fields.every((f) => !f.required || fieldFilled(f, ownProp(obj, f.name)));
27
+ return field.fields.every((f) => {
28
+ const child = ownProp(obj, f.name);
29
+ return f.required ? fieldFilled(f, child) : !isFilled(child) || fieldFilled(f, child);
30
+ });
28
31
  }
29
32
  if (field.kind === "list") {
30
33
  if (field.maxItemCount !== void 0 && Array.isArray(value) && value.length > field.maxItemCount)
@@ -49,7 +52,25 @@ function computeReadiness(fields, values) {
49
52
  function shownAsOptional(field) {
50
53
  return !field.required && field.defaultValue === void 0;
51
54
  }
55
+ function isOptionalStructure(field) {
56
+ return field.kind === "object" && !field.required;
57
+ }
58
+ function optionalStructureOpen(value) {
59
+ return typeof value === "object" && value !== null && !Array.isArray(value);
60
+ }
61
+ function foldsBehindOptionalDisclosure(field) {
62
+ return shownAsOptional(field) || isOptionalStructure(field);
63
+ }
64
+ function isFoldedOptional(field, value) {
65
+ if (!foldsBehindOptionalDisclosure(field)) return false;
66
+ return isOptionalStructure(field) ? !optionalStructureOpen(value) : !isFilled(value);
67
+ }
68
+ function anyOptionalStructureOpen(fields, values) {
69
+ return fields.some(
70
+ (f) => isOptionalStructure(f) && optionalStructureOpen(ownProp(values, f.name))
71
+ );
72
+ }
52
73
 
53
- export { computeReadiness, fieldFilled, isFilled, mustBeFilled, shownAsOptional };
54
- //# sourceMappingURL=chunk-MJQ7CXUB.js.map
55
- //# sourceMappingURL=chunk-MJQ7CXUB.js.map
74
+ export { anyOptionalStructureOpen, computeReadiness, fieldFilled, foldsBehindOptionalDisclosure, isFilled, isFoldedOptional, isOptionalStructure, mustBeFilled, optionalStructureOpen, shownAsOptional };
75
+ //# sourceMappingURL=chunk-XO5OENNF.js.map
76
+ //# sourceMappingURL=chunk-XO5OENNF.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/core/readiness.ts"],"names":[],"mappings":";;;AA8BA,IAAM,gBAAA,GAAmB,EAAA;AAGlB,SAAS,SAAS,KAAA,EAAyB;AAChD,EAAA,OAAO,UAAA,CAAW,KAAA,EAAO,CAAA,EAAG,MAAS,CAAA;AACvC;AA0BA,SAAS,UAAA,CAAW,KAAA,EAAgB,KAAA,EAAe,IAAA,EAAgD;AACjG,EAAA,IAAI,KAAA,IAAS,MAAM,OAAO,KAAA;AAM1B,EAAA,IAAI,OAAO,KAAA,KAAU,QAAA,EAAU,OAAO,KAAA,CAAM,MAAK,KAAM,EAAA;AAMvD,EAAA,IAAI,OAAO,KAAA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S;AACT,EAAA,OAAO,MAAA,CAAO,IAAA;AAAA,IACZ,CAAC,CAAA,KAAM,mBAAA,CAAoB,CAAC,CAAA,IAAK,sBAAsB,OAAA,CAAQ,MAAA,EAAQ,CAAA,CAAE,IAAI,CAAC;AAAA,GAChF;AACF","file":"chunk-XO5OENNF.js","sourcesContent":["/**\n * Value readiness - the helpers the runner uses to decide whether the Run\n * button may fire and which inputs are still missing.\n */\n\nimport type { ObjectRunField, RunField } from './descriptor';\nimport { hasOwnProp, ownProp } from './own-property';\n\n/**\n * How deep `isFilled` walks a value before it stops looking, and the answer it\n * gives when it does.\n *\n * The walk is over CALLER-SUPPLIED data - a request body on a public run\n * endpoint, or a form's state - so its depth is whatever the caller sent, and\n * the schema is no bound on it: `pruneEmptyOptionals` copies a property the\n * schema does not declare straight through, so a key ajv never walks reaches\n * this function unwalked. Unbounded, a value a few thousand levels deep threw\n * `RangeError` out of the middle of a host's server gate - a gate whose whole\n * contract is that it returns a verdict instead of throwing.\n *\n * **The cap answers `false`, and that direction is the deliberate half.** Past\n * the cap this function cannot tell whether there is anything down there, and\n * the kernel's rule throughout is that an unanswerable absence fails closed.\n * The cost of the other choice is a run the method cannot use, started (and\n * billed) on a payload no schema validated. The cost of this one is nearly\n * nothing: `isFilled` combines branches with `some`, so a refused over-deep\n * branch only loses its own vote - a real value anywhere beside it still reads\n * filled - and no concept structure declares nesting anywhere near this deep,\n * so a value that reaches the cap is not one the method had a slot for.\n */\nconst MAX_FILLED_DEPTH = 64;\n\n/** True when a value is meaningfully filled (not empty / blank / empty container). */\nexport function isFilled(value: unknown): boolean {\n return walkFilled(value, 0, undefined);\n}\n\n/**\n * `isFilled`'s walk, carrying the depth and the objects already judged.\n *\n * `seen` is a cycle guard first - a value that references itself would\n * otherwise recurse to the cap on every branch - and a memo second. Both uses\n * rest on the same fact: an object reached twice within ONE call answered\n * `false` the first time, because a `true` short-circuits every `some` above it\n * and the walk never gets back down here. So the map can only ever hold empty\n * subtrees, which is what makes it safe to keep entries after unwinding -\n * without that, a value shaped like a diamond chain costs exponential time.\n *\n * **It records the DEPTH each object was judged at, and that is not a detail.**\n * A `false` here has two causes - nothing was down there, or the cap stopped\n * the walk - and only the first travels. An object whose children sit one level\n * past the cap answers `false` at depth 63 and is perfectly filled at depth 5;\n * memoizing identity alone then reported a genuinely filled input as missing\n * the moment a shallower path reached the same object second. So a recorded\n * answer is reused only for a revisit at the SAME depth or deeper, where the\n * walk could see no more than the first one did, and a strictly shallower\n * arrival walks again. That keeps the cycle guard exact (depth rises along\n * every path, so a cycle always revisits deeper) and keeps the memo bounded:\n * an object's recorded depth strictly falls each time it is re-walked, over a\n * range the cap fixes, so the diamond stays linear in all but a constant.\n */\nfunction walkFilled(value: unknown, depth: number, seen: Map<object, number> | undefined): boolean {\n if (value == null) return false;\n // Whitespace is not a value. The Run button lit up over a required text input\n // holding three spaces, ajv passed it (a content model carries no\n // `minLength`), and the run reached the runtime with nothing in it. The same\n // test is what makes a blank OPTIONAL input a real absence on the wire rather\n // than a supplied empty string - see `apiInputsFromSchemaData`.\n if (typeof value === 'string') return value.trim() !== '';\n // No concept in the taxonomy holds a function, so one here arrived by a route\n // that is already wrong - most plausibly an inherited `Object.prototype`\n // member read off a plain object by a colliding input name. `ownProp` closes\n // that route at every lookup; this branch is the backstop for the ones that\n // arrive by another.\n if (typeof value === 'function') return false;\n if (typeof value !== 'object') return true;\n\n if (depth >= MAX_FILLED_DEPTH) return false;\n const visited = seen ?? new Map<object, number>();\n const judgedAt = visited.get(value);\n if (judgedAt !== undefined && judgedAt <= depth) return false;\n visited.set(value, depth);\n\n if (Array.isArray(value)) return value.some((item) => walkFilled(item, depth + 1, visited));\n const obj = value as Record<string, unknown>;\n // A file value is { url } - filled when the url is set.\n if (hasOwnProp(obj, 'url')) return walkFilled(obj.url, depth + 1, visited);\n return Object.values(obj).some((child) => walkFilled(child, depth + 1, visited));\n}\n\n/**\n * True when a slot holds something AND every required field inside it has a\n * value.\n *\n * The two halves are both load-bearing, and the first one is the one that is\n * easy to leave out. A structure is satisfied only if there is something in it:\n * a struct whose concept declares no required child used to be *vacuously*\n * satisfied by an absent value - every child passed the `!f.required` test, so\n * `every` returned true over a value that was not there. Readiness reported\n * nothing missing and the Run button lit up, while the value bridge omitted the\n * untouched structure and the gate then rejected the run on the combined\n * schema's `required` list, naming an input the form had just declared ready.\n *\n * `isFilled` is the SAME predicate `toRjsf` uses to decide whether a structure\n * collapses to an absence (`values.ts`), which is what makes the two halves\n * agree by construction rather than by parallel edits: readiness calls an input\n * present exactly when the bridge keeps it. Absence is what a singular slot\n * expresses, so a required one has to be touched - the button stays dark until\n * the user puts a value somewhere inside, and then the whole shell travels,\n * empty children and all, so a required child left blank still fails loudly.\n *\n * Its own recursion follows the DESCRIPTOR, not the value, so it needs no depth\n * cap of its own: a `RunField` tree only exists because `buildRunFields`\n * finished walking a contract's schema, which bounds it. `isFilled` is where\n * the caller's data is walked, and where the cap lives.\n */\nexport function fieldFilled(field: RunField, value: unknown): boolean {\n if (field.kind === 'object') {\n if (!isFilled(value)) return false;\n const obj = (value ?? {}) as Record<string, unknown>;\n // A required child must be filled. An OPTIONAL child the value holds\n // something in owes its own concept the same - the rule a touched optional\n // input follows at the top level (`computeReadiness`) and a started list\n // row follows below, applied at every depth. Asking required children\n // alone let a half-filled optional structure INSIDE a structure through:\n // `{bank: {holder: 'x', iban: ''}}` satisfied ajv (a present empty string\n // is present, a content model carries no `minLength`) and readiness never\n // looked below `bank`, so the button stayed live and the run went out with\n // a required child blank. An optional child that holds nothing is absent,\n // and absence blocks nothing - which is what closing it writes.\n return field.fields.every((f) => {\n const child = ownProp(obj, f.name);\n return f.required ? fieldFilled(f, child) : !isFilled(child) || fieldFilled(f, child);\n });\n }\n if (field.kind === 'list') {\n // Too many items is not filled, and this is asked of EVERY list, not only\n // one carrying a lower bound. `ListField` will not add past the bound, so\n // it answers the list that arrived from somewhere else - a restored draft,\n // a host seeding values, a bespoke surface calling these predicates over\n // data it did not render. Asking it only inside the `itemCount` branch\n // meant a model stating `maxItems` alone published its ceiling on the\n // descriptor and enforced it nowhere: the button stayed live on a list ajv\n // was about to refuse. Naming it in `missing` is a small stretch of that\n // word, and the alternative is the disagreement.\n if (\n field.maxItemCount !== undefined &&\n Array.isArray(value) &&\n value.length > field.maxItemCount\n )\n return false;\n // A list the method gave a count to (`Concept[N]`) is satisfied only by that\n // many items, each of them filled. Answering it by `isFilled` alone - \"is\n // there anything in the array?\" - left the button live on a `[3]` slot\n // holding two, and the gate then refused it on the very count the method\n // declared. `itemCount` comes off the same `minItems` ajv reads, so the two\n // halves phrase one rule.\n if (field.itemCount !== undefined) {\n if (!Array.isArray(value) || value.length < field.itemCount) return false;\n return value.every((item) => fieldFilled(field.item, item));\n }\n // A VARIABLE list never gates on being empty (see `mustBeFilled`) - a plural\n // slot's empty form IS the empty list. But a row the user STARTED owes its\n // concept every field the concept declares, which is the same rule a touched\n // optional input follows one level up, and `isFilled` alone does not say it:\n // a row holding `{name: 'x', other: ''}` reads filled by `some`, satisfies\n // ajv's `required` (a present empty string is present), and went out as an\n // item the runtime cannot use. An untouched row stays an absence and still\n // blocks nothing.\n if (Array.isArray(value))\n return (\n value.every((item) => !isFilled(item) || fieldFilled(field.item, item)) && isFilled(value)\n );\n }\n return isFilled(value);\n}\n\nexport interface Readiness {\n total: number;\n ready: number;\n missing: string[];\n}\n\n/**\n * True when the user must put a value in this field before the run can start.\n *\n * Distinct from `required`, which also drives layout (a required field always\n * shows; an optional one may collapse). A **variable-plural** field stays\n * required - it is a first-class input and keeps its place in the form - but it\n * never gates: a plural slot is never \"absent\" in MTHDS, its empty form IS the\n * empty list, and no method can declare \"at least one item\". A **fixed-count**\n * list (`[N]`) is the exception the wire now states, and it gates like any other\n * slot - there the method HAS ruled the empty form out.\n *\n * **For a field this package built, the answer comes from `inputMustBeFilled`**\n * (`contracts.ts`) - the SAME predicate the method viewer's Run button, its ajv\n * `required` list and its missing-inputs toast all read. `buildRunFields`\n * stamps it onto `gating`. This used to be re-derived here as\n * `required && kind !== 'list'`: the same rule expressed against the MAPPED\n * field instead of the contract, and the two could disagree - `kind` is `'list'`\n * for a `conceptRef` ending in `[]` OR an array schema, while the contract's\n * plural test is the array schema alone, so a plural input carrying a non-array\n * schema gated on one surface and not the other.\n *\n * The shape heuristic survives only as the fallback for a **hand-authored**\n * `RunField` - story fixtures and unit tests, which have no contract to consult\n * and therefore nothing to disagree with. Every field a host renders comes from\n * `buildRunFields` and carries `gating`, so a host is on the contract's answer\n * alone. (The fallback cannot see a fixed count either - one more thing only the\n * contract knows.)\n */\nexport function mustBeFilled(field: RunField): boolean {\n return field.gating ?? (field.required && field.kind !== 'list');\n}\n\n/**\n * How many top-level inputs stand between the current values and a run.\n *\n * Two kinds count, and the second is easy to miss. An input the method DEMANDS\n * counts always (`mustBeFilled`). An input the method left optional counts once\n * the user has put something in it - because a structure that has been touched\n * owes its concept every field the concept declares, and the gate enforces\n * exactly that. Left out, an optional struct opened and half-filled was ignored\n * here and refused there: the button stayed live and the run came back rejected\n * on a required child, which is the same disagreement the demanded case had.\n *\n * So an optional input moves INTO the denominator the moment it is touched, and\n * out of `missing` as soon as it is complete: 3 of 3 while it is untouched, 3\n * of 4 once it is started, 4 of 4 once it is done. `total` answers \"how many\n * things stand between me and Run\", which is the number a host is displaying.\n */\nexport function computeReadiness(fields: RunField[], values: Record<string, unknown>): Readiness {\n const gating = fields.filter((f) => mustBeFilled(f) || isFilled(ownProp(values, f.name)));\n const missing = gating\n .filter((f) => !fieldFilled(f, ownProp(values, f.name)))\n .map((f) => f.title ?? f.name);\n return { total: gating.length, ready: gating.length - missing.length, missing };\n}\n\n/**\n * Whether a person should see this field as optional: not required AND carrying no authored\n * default. The standard marks a defaulted field `required: false` (it can never be missing), but it\n * is always filled, so presenting it as optional — the badge, the fold behind the optional toggle —\n * misreads it: a choice defaulted to one of its options is still a choice the user must see.\n * Presentation only; what gates a run is `mustBeFilled`.\n */\nexport function shownAsOptional(field: RunField): boolean {\n return !field.required && field.defaultValue === undefined;\n}\n\n/**\n * Whether a field is an optional structure: an OPTIONAL structured concept, at\n * any depth - a structure inside a structure, or an optional structured input\n * at the top level.\n *\n * Its value is either absent (closed) or an object (open), and closing it is\n * the one way a person says \"none of this\" once the structure's children carry\n * defaults - a half-filled optional structure otherwise reads as a choice\n * nobody made. It folds behind its container's \"+ N optional\" disclosure while\n * closed, and that disclosure opens and closes it\n * (`openOptionalStructures`, `closeOptionalStructures`).\n *\n * An item of a list is never one: a row is in the array because the person\n * added it.\n */\nexport function isOptionalStructure(field: RunField): field is ObjectRunField {\n return field.kind === 'object' && !field.required;\n}\n\n/**\n * Whether an optional structure reads open for this value: a plain object,\n * even `{}`. `undefined` and `null` read closed.\n *\n * Derived from the value, never held beside it, so a host that seeds the value\n * (`seedObjectValue`) has opened the structure, and one that clears it has\n * closed it. Open is presentation; what the run makes of the value is\n * `isFilled`'s answer as everywhere else - an open structure holding nothing\n * at all is still absent on the wire, exactly as an opened optional section\n * left blank always was, while one holding anything owes its concept every\n * required child (`fieldFilled`).\n */\nexport function optionalStructureOpen(value: unknown): boolean {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\n/**\n * Whether a field takes part in its container's \"+ N optional\" disclosure:\n * shown as optional (`shownAsOptional`), or an optional structure\n * (`isOptionalStructure`) whatever its defaults.\n */\nexport function foldsBehindOptionalDisclosure(field: RunField): boolean {\n return shownAsOptional(field) || isOptionalStructure(field);\n}\n\n/**\n * Whether a field is folded behind the disclosure right now, for this value:\n * it takes part in the disclosure and is empty - for an optional structure,\n * closed (`optionalStructureOpen`); for any other field, not `isFilled`. The\n * disclosure's count, \"+ N optional\", is the number of fields this answers\n * `true` for while it is collapsed.\n */\nexport function isFoldedOptional(field: RunField, value: unknown): boolean {\n if (!foldsBehindOptionalDisclosure(field)) return false;\n return isOptionalStructure(field) ? !optionalStructureOpen(value) : !isFilled(value);\n}\n\n/** Whether any optional structure among `fields` is open in `values`. */\nexport function anyOptionalStructureOpen(\n fields: readonly RunField[],\n values: Record<string, unknown> | undefined,\n): boolean {\n return fields.some(\n (f) => isOptionalStructure(f) && optionalStructureOpen(ownProp(values, f.name)),\n );\n}\n"]}
package/dist/core/gate.js CHANGED
@@ -1,7 +1,7 @@
1
- export { apiInputsFromSchemaData, buildRunInputsSchema, gateRunInputs, prepareRunInputs, validateRunInputs } from '../chunk-IR3OFSGD.js';
1
+ export { apiInputsFromSchemaData, buildRunInputsSchema, gateRunInputs, prepareRunInputs, validateRunInputs } from '../chunk-2EGRONBV.js';
2
2
  import '../chunk-GCXV76WU.js';
3
3
  import '../chunk-LBFZXYCY.js';
4
- import '../chunk-MJQ7CXUB.js';
4
+ import '../chunk-XO5OENNF.js';
5
5
  import '../chunk-VTPUDBSJ.js';
6
6
  import '../chunk-GKV77RAS.js';
7
7
  import '../chunk-Y2ND6W4W.js';
@@ -7,7 +7,8 @@ export { SaveFailure, SaveFile, SaveFileKind, SaveFiles, SavePlan, SavePlanOptio
7
7
  export { DOCUMENT_FORMATS, FileFormat, IMAGE_FORMATS, acceptLabel, acceptMap, formatsForKind, isAcceptedFile } from './file-formats.js';
8
8
  export { narrowFileFormats } from './narrow-file-formats.js';
9
9
  export { CompositeMember, DataUrlView, DateContentView, DocumentContentView, HtmlContentView, ImageContentView, NATIVE_COMPOSITE_CONCEPT_REF, NATIVE_DATE_CONCEPT_REF, NATIVE_HTML_CONCEPT_REF, TYPED_SCALAR_MARKERS, formatDateContent, hasTypedScalarMarkers, isNativeCompositeNode, isNativeDateNode, isNativeHtmlNode, isViewableUrl, readCompositeContent, readDataUrl, readDateContent, readDocumentContent, readHtmlContent, readImageContent, viewableUrl } from './native-content.js';
10
- export { Readiness, computeReadiness, fieldFilled, isFilled, mustBeFilled, shownAsOptional } from './readiness.js';
10
+ export { Readiness, anyOptionalStructureOpen, computeReadiness, fieldFilled, foldsBehindOptionalDisclosure, isFilled, isFoldedOptional, isOptionalStructure, mustBeFilled, optionalStructureOpen, shownAsOptional } from './readiness.js';
11
+ export { closeOptionalStructures, openOptionalStructures, seedInputs, seedObjectValue } from './seed.js';
11
12
  export { InputPresence, buildPipeRef, getPipeIOContract, inputMustBeFilled, isFixedCountInput, isOptionalInput, isPluralInput } from './contracts.js';
12
13
  export { RunInputsGateResult, RunInputsVerdict, apiInputsFromSchemaData, buildRunInputsSchema, gateRunInputs, prepareRunInputs, validateRunInputs } from './gate.js';
13
14
  export { RunInputError, validateRunInputsSchema } from './gate-validator.js';
@@ -1,17 +1,18 @@
1
1
  export { describeValidationError, displayValue, valueAtProperty } from '../chunk-RPA7DNSK.js';
2
- export { apiInputsFromRunValues, fieldsForContract, inputDataFromWorkingMemory, outputsFromPipeOutput, rjsfDataFromRunValues, runValuesFromStore, setValueAtPath, storeInputDataFromRunValues } from '../chunk-G6SFMTL4.js';
2
+ export { closeOptionalStructures, openOptionalStructures, seedInputs, seedObjectValue } from '../chunk-VH5CDQDR.js';
3
+ export { apiInputsFromRunValues, fieldsForContract, inputDataFromWorkingMemory, outputsFromPipeOutput, rjsfDataFromRunValues, runValuesFromStore, setValueAtPath, storeInputDataFromRunValues } from '../chunk-VT5E5W4E.js';
3
4
  export { narrowFileFormats } from '../chunk-CAKQ5VFT.js';
4
- export { getPipeOutputForm } from '../chunk-DARLDVJM.js';
5
- export { planFileSave, planStuffSave } from '../chunk-7KQXGG6J.js';
5
+ export { getPipeOutputForm } from '../chunk-JIGRWJTV.js';
6
+ export { planFileSave, planStuffSave } from '../chunk-ICUEHNEH.js';
6
7
  export { collectStuffFiles } from '../chunk-RRTI7AIR.js';
7
8
  export { NATIVE_COMPOSITE_CONCEPT_REF, NATIVE_DATE_CONCEPT_REF, NATIVE_HTML_CONCEPT_REF, TYPED_SCALAR_MARKERS, formatDateContent, hasTypedScalarMarkers, isNativeCompositeNode, isNativeDateNode, isNativeHtmlNode, isViewableUrl, readCompositeContent, readDataUrl, readDateContent, readDocumentContent, readHtmlContent, readImageContent, viewableUrl } from '../chunk-CM4KVG53.js';
8
9
  export { buildResultField, buildRunFields, getPipeInputForm } from '../chunk-ZB4RYUKV.js';
9
10
  export { conceptCategory } from '../chunk-FABY3DEY.js';
10
11
  export { DOCUMENT_FORMATS, IMAGE_FORMATS, acceptLabel, acceptMap, formatsForKind, isAcceptedFile } from '../chunk-XCO6GTEC.js';
11
- export { apiInputsFromSchemaData, buildRunInputsSchema, gateRunInputs, prepareRunInputs, validateRunInputs } from '../chunk-IR3OFSGD.js';
12
+ export { apiInputsFromSchemaData, buildRunInputsSchema, gateRunInputs, prepareRunInputs, validateRunInputs } from '../chunk-2EGRONBV.js';
12
13
  export { deflateAllInputs, deflateInput, healStringWrappers, inflateAllInputs, inflateInput, pruneEmptyOptionals, resolveConceptCode } from '../chunk-GCXV76WU.js';
13
14
  export { normalizeSchemaForRjsf, prepareSchemaForRjsf } from '../chunk-LBFZXYCY.js';
14
- export { computeReadiness, fieldFilled, isFilled, mustBeFilled, shownAsOptional } from '../chunk-MJQ7CXUB.js';
15
+ export { anyOptionalStructureOpen, computeReadiness, fieldFilled, foldsBehindOptionalDisclosure, isFilled, isFoldedOptional, isOptionalStructure, mustBeFilled, optionalStructureOpen, shownAsOptional } from '../chunk-XO5OENNF.js';
15
16
  export { validateRunInputsSchema } from '../chunk-VTPUDBSJ.js';
16
17
  export { asCalendarDate, dayWithinDateTime, isAcceptableDate, isAcceptableDateTime, toDateInputValue, toStoredDateValue } from '../chunk-GKV77RAS.js';
17
18
  import '../chunk-Y2ND6W4W.js';
@@ -6,8 +6,8 @@ export { OutputForm, PipeOutputFormDescriptor } from 'mthds/protocol';
6
6
  *
7
7
  * **This module used to declare the artifact; now it only addresses it.** The
8
8
  * types come from `mthds/protocol`, exactly as the input side's do — the
9
- * standard grew `output_form` as a page of its own, and grew `json_schema` on
10
- * the output contract in the same version, so a renderer reads both off the wire
9
+ * protocol package grew `output_form` and `json_schema` on the output contract
10
+ * in the same version, `mthds` 0.25.0, so a renderer reads both off the wire
11
11
  * instead of having them supplied beside it. What is left here is the twin of
12
12
  * `getPipeInputForm`: the lookup, and the tolerance for the same two key
13
13
  * conventions. [docs/contract-mirror.md](../../docs/contract-mirror.md) states
@@ -30,8 +30,9 @@ export { OutputForm, PipeOutputFormDescriptor } from 'mthds/protocol';
30
30
  * | presentation view | `input_form` | `output_form` |
31
31
  *
32
32
  * The two rows that used to read "nothing" are the change this package was built
33
- * against while it was still a proposal; `wip/output-form-standard-change.md` is
34
- * the argument that landed it. The one asymmetry the language keeps is
33
+ * against while it was still a proposal. The standard has the `output_form`
34
+ * page and has yet to write `json_schema` into its output contract
35
+ * (L-260902-d45673). The one asymmetry the language keeps is
35
36
  * `presence` versus `optional`: `!` MUST NOT appear on an output, so a
36
37
  * three-valued output marker would have an arm nothing could ever produce.
37
38
  */
@@ -1,4 +1,4 @@
1
- export { getPipeOutputForm } from '../chunk-DARLDVJM.js';
1
+ export { getPipeOutputForm } from '../chunk-JIGRWJTV.js';
2
2
  import '../chunk-WYH56SOZ.js';
3
3
  import '../chunk-V3OV2XQT.js';
4
4
  //# sourceMappingURL=output-form.js.map
@@ -1,4 +1,4 @@
1
- import { RunField } from './descriptor.js';
1
+ import { RunField, ObjectRunField } from './descriptor.js';
2
2
  import './contracts.js';
3
3
  import 'mthds/protocol';
4
4
  import './file-formats.js';
@@ -96,5 +96,50 @@ declare function computeReadiness(fields: RunField[], values: Record<string, unk
96
96
  * Presentation only; what gates a run is `mustBeFilled`.
97
97
  */
98
98
  declare function shownAsOptional(field: RunField): boolean;
99
+ /**
100
+ * Whether a field is an optional structure: an OPTIONAL structured concept, at
101
+ * any depth - a structure inside a structure, or an optional structured input
102
+ * at the top level.
103
+ *
104
+ * Its value is either absent (closed) or an object (open), and closing it is
105
+ * the one way a person says "none of this" once the structure's children carry
106
+ * defaults - a half-filled optional structure otherwise reads as a choice
107
+ * nobody made. It folds behind its container's "+ N optional" disclosure while
108
+ * closed, and that disclosure opens and closes it
109
+ * (`openOptionalStructures`, `closeOptionalStructures`).
110
+ *
111
+ * An item of a list is never one: a row is in the array because the person
112
+ * added it.
113
+ */
114
+ declare function isOptionalStructure(field: RunField): field is ObjectRunField;
115
+ /**
116
+ * Whether an optional structure reads open for this value: a plain object,
117
+ * even `{}`. `undefined` and `null` read closed.
118
+ *
119
+ * Derived from the value, never held beside it, so a host that seeds the value
120
+ * (`seedObjectValue`) has opened the structure, and one that clears it has
121
+ * closed it. Open is presentation; what the run makes of the value is
122
+ * `isFilled`'s answer as everywhere else - an open structure holding nothing
123
+ * at all is still absent on the wire, exactly as an opened optional section
124
+ * left blank always was, while one holding anything owes its concept every
125
+ * required child (`fieldFilled`).
126
+ */
127
+ declare function optionalStructureOpen(value: unknown): boolean;
128
+ /**
129
+ * Whether a field takes part in its container's "+ N optional" disclosure:
130
+ * shown as optional (`shownAsOptional`), or an optional structure
131
+ * (`isOptionalStructure`) whatever its defaults.
132
+ */
133
+ declare function foldsBehindOptionalDisclosure(field: RunField): boolean;
134
+ /**
135
+ * Whether a field is folded behind the disclosure right now, for this value:
136
+ * it takes part in the disclosure and is empty - for an optional structure,
137
+ * closed (`optionalStructureOpen`); for any other field, not `isFilled`. The
138
+ * disclosure's count, "+ N optional", is the number of fields this answers
139
+ * `true` for while it is collapsed.
140
+ */
141
+ declare function isFoldedOptional(field: RunField, value: unknown): boolean;
142
+ /** Whether any optional structure among `fields` is open in `values`. */
143
+ declare function anyOptionalStructureOpen(fields: readonly RunField[], values: Record<string, unknown> | undefined): boolean;
99
144
 
100
- export { type Readiness, computeReadiness, fieldFilled, isFilled, mustBeFilled, shownAsOptional };
145
+ export { type Readiness, anyOptionalStructureOpen, computeReadiness, fieldFilled, foldsBehindOptionalDisclosure, isFilled, isFoldedOptional, isOptionalStructure, mustBeFilled, optionalStructureOpen, shownAsOptional };
@@ -1,4 +1,4 @@
1
- export { computeReadiness, fieldFilled, isFilled, mustBeFilled, shownAsOptional } from '../chunk-MJQ7CXUB.js';
1
+ export { anyOptionalStructureOpen, computeReadiness, fieldFilled, foldsBehindOptionalDisclosure, isFilled, isFoldedOptional, isOptionalStructure, mustBeFilled, optionalStructureOpen, shownAsOptional } from '../chunk-XO5OENNF.js';
2
2
  import '../chunk-V3OV2XQT.js';
3
3
  //# sourceMappingURL=readiness.js.map
4
4
  //# sourceMappingURL=readiness.js.map
@@ -141,5 +141,35 @@ declare function planStuffSave(field: RunField, value: unknown, options: SavePla
141
141
  * not drawn then, so a reader is never offered a download that cannot happen.
142
142
  */
143
143
  declare function planFileSave(file: StuffFile, options: SavePlanOptions): SaveFile | undefined;
144
+ /**
145
+ * A planned name split at its extension, the way the plan reads one:
146
+ * `devis.pdf` is `devis` and `.pdf`, `report.final.html` is `report.final` and
147
+ * `.html`, and a name with no extension of one to eight letters and digits is
148
+ * all stem. The extension keeps its dot, so a name rebuilt from the two halves
149
+ * is the name.
150
+ */
151
+ declare function splitFileName(name: string): {
152
+ stem: string;
153
+ extension: string;
154
+ };
155
+ /**
156
+ * The name a reader typed for a file, made safe the way a planned name is, and
157
+ * a little stricter, since this one is typed rather than produced.
158
+ *
159
+ * Control characters go, as from every planned name. A path separator is
160
+ * REPLACED rather than cut at: a planned name keeps its last path segment
161
+ * because a payload's `filename` may be a path, but a reader who types
162
+ * `Devis 12/2026` means a name, and keeping `2026` alone would throw away what
163
+ * they wrote. The characters a common file system refuses in a name
164
+ * (`: * ? " < > |`) are replaced the same way, with a hyphen, because a host's
165
+ * bridge may write the name to disk as given. Leading dots go, so the file is
166
+ * not hidden, and trailing dots and spaces, which one file system drops
167
+ * silently. A copy of the extension the reader typed at the end is dropped,
168
+ * since the extension is added back after it: `devis.pdf` stays `devis.pdf`
169
+ * rather than becoming `devis.pdf.pdf`.
170
+ *
171
+ * Empty when nothing is left, which the caller reads as "keep the planned name".
172
+ */
173
+ declare function typedFileStem(typed: string, extension: string): string;
144
174
 
145
- export { type SaveFailure, type SaveFile, type SaveFileKind, type SaveFiles, type SavePlan, type SavePlanOptions, type SaveResult, type UnavailableFile, planFileSave, planStuffSave };
175
+ export { type SaveFailure, type SaveFile, type SaveFileKind, type SaveFiles, type SavePlan, type SavePlanOptions, type SaveResult, type UnavailableFile, planFileSave, planStuffSave, splitFileName, typedFileStem };
@@ -1,4 +1,4 @@
1
- export { planFileSave, planStuffSave } from '../chunk-7KQXGG6J.js';
1
+ export { planFileSave, planStuffSave, splitFileName, typedFileStem } from '../chunk-ICUEHNEH.js';
2
2
  import '../chunk-RRTI7AIR.js';
3
3
  import '../chunk-CM4KVG53.js';
4
4
  import '../chunk-V3OV2XQT.js';
@@ -0,0 +1,56 @@
1
+ import { RunField, ObjectRunField } from './descriptor.js';
2
+ import './contracts.js';
3
+ import 'mthds/protocol';
4
+ import './file-formats.js';
5
+
6
+ /**
7
+ * Seeding a form from the method's authored defaults.
8
+ *
9
+ * Pure module: no React, no DOM - a server building a payload and a control
10
+ * opening an optional structure read the same answer from here.
11
+ */
12
+
13
+ /**
14
+ * The `/inputs` seed: the authored defaults, and nothing else.
15
+ *
16
+ * A defaulted field carries `defaultValue` (never the `null` a schema
17
+ * projection attaches to an optional field); a structure's defaults sit inside
18
+ * it. What is NOT seeded is an empty string or a zero for an unfilled field -
19
+ * the kernel's readiness treats an absent value as absent, and a seeded
20
+ * placeholder would count as filled.
21
+ *
22
+ * **An optional structure is not descended into.** Its presence is a choice the
23
+ * person makes with the "+ N optional" disclosure it folds behind (see
24
+ * `isOptionalStructure`), so a seed that put its children's defaults inside it would make that choice
25
+ * for them: the structure would arrive open and be sent, merely because its
26
+ * concept declares defaults. It is seeded only when the structure itself
27
+ * carries an authored default; otherwise it stays absent, and turning it on
28
+ * seeds it then, through `seedObjectValue`. A host that wants it open from the
29
+ * start puts `seedObjectValue(field)` at its path.
30
+ */
31
+ declare function seedInputs(fields: readonly RunField[]): Record<string, unknown>;
32
+ /**
33
+ * The value a structured field holds the moment it is opened: the
34
+ * structure's own authored default when it carries an object one, otherwise
35
+ * an object seeded from its children's defaults by `seedInputs` - which is `{}`
36
+ * when none of them declares one. Always a plain object, so the disclosure that
37
+ * reads the value back (`optionalStructureOpen`) reads open.
38
+ *
39
+ * Optional structures beneath it stay absent, by `seedInputs`' own rule: each
40
+ * opens with its own container's disclosure.
41
+ */
42
+ declare function seedObjectValue(field: ObjectRunField): Record<string, unknown>;
43
+ /**
44
+ * What expanding a "+ N optional" disclosure writes: `values` with every
45
+ * CLOSED optional structure among `fields` opened to `seedObjectValue(field)`.
46
+ * Open ones and every other field are kept as they are. Returns a new object.
47
+ */
48
+ declare function openOptionalStructures(fields: readonly RunField[], values: Record<string, unknown> | undefined): Record<string, unknown>;
49
+ /**
50
+ * What collapsing a "+ N optional" disclosure writes: `values` with every
51
+ * optional structure among `fields` closed to `undefined`, so each leaves the
52
+ * payload. Every other field is kept as it is. Returns a new object.
53
+ */
54
+ declare function closeOptionalStructures(fields: readonly RunField[], values: Record<string, unknown> | undefined): Record<string, unknown>;
55
+
56
+ export { closeOptionalStructures, openOptionalStructures, seedInputs, seedObjectValue };