@johnhenry/mallory-cli 0.0.0-stage → 0.1.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.
- package/README.md +60 -2
- package/bin/mallory.mjs +51 -0
- package/package.json +51 -4
- package/src/a2a/client.js +511 -0
- package/src/a2a/demo-agent.js +396 -0
- package/src/a2a/hub.js +578 -0
- package/src/a2a/settings.js +88 -0
- package/src/a2a/task.js +358 -0
- package/src/acp/client.js +573 -0
- package/src/acp/demo-agent.js +332 -0
- package/src/acp/hub.js +632 -0
- package/src/acp/settings.js +78 -0
- package/src/actions/map.js +524 -0
- package/src/agent/cloud.js +77 -0
- package/src/agent/compact.js +84 -0
- package/src/agent/constants.js +39 -0
- package/src/agent/diff.js +101 -0
- package/src/agent/fork.js +159 -0
- package/src/agent/grounding.js +73 -0
- package/src/agent/guards.js +129 -0
- package/src/agent/local-transport.js +152 -0
- package/src/agent/loop.js +479 -0
- package/src/agent/park-store.js +77 -0
- package/src/agent/park.js +76 -0
- package/src/agent/ports.js +28 -0
- package/src/agent/providers.js +591 -0
- package/src/agent/restart.js +51 -0
- package/src/agent/router.js +380 -0
- package/src/agent/run.js +861 -0
- package/src/agent/tools.js +247 -0
- package/src/agent-library/engine.js +43 -0
- package/src/ai/bridge.js +155 -0
- package/src/ai/policy.js +131 -0
- package/src/aimatey/vendor.js +18 -0
- package/src/audio/container-duration.js +35 -0
- package/src/audio/instruments.js +776 -0
- package/src/audio/lanes.js +230 -0
- package/src/audio/patch.js +1410 -0
- package/src/audio/plan.js +276 -0
- package/src/audio/rack.js +1006 -0
- package/src/audio/sample-trim.js +293 -0
- package/src/audio/soundfont.js +243 -0
- package/src/audio/take-store.js +87 -0
- package/src/audio/takes.js +129 -0
- package/src/audio/wav.js +170 -0
- package/src/audio/zzfx.js +333 -0
- package/src/autonomy/bundle.js +207 -0
- package/src/autonomy/confine.js +61 -0
- package/src/autonomy/enforce.js +155 -0
- package/src/autonomy/file-kv.js +88 -0
- package/src/autonomy/ledger.js +203 -0
- package/src/autonomy/pins.js +50 -0
- package/src/autonomy/psl/index.js +32 -0
- package/src/autonomy/psl/suffixes.json +1 -0
- package/src/autonomy/record.js +28 -0
- package/src/autonomy/routines.js +107 -0
- package/src/autonomy/server.js +175 -0
- package/src/autonomy/signer-node.js +167 -0
- package/src/autonomy/store.js +43 -0
- package/src/autonomy/unattended.js +13 -0
- package/src/bytes/bytes.js +378 -0
- package/src/calc/syntax.js +125 -0
- package/src/calc/tex.js +28 -0
- package/src/calendar/vendor.js +2 -0
- package/src/clipboard.js +130 -0
- package/src/clsh/clsh.js +3417 -0
- package/src/codec/capnp.js +1804 -0
- package/src/codec/core.js +2043 -0
- package/src/codec/vendor/avro.js +136 -0
- package/src/codec/vendor/cbor.js +25 -0
- package/src/codec/vendor/flatbuffers.js +206 -0
- package/src/codec/vendor/msgpack.js +9 -0
- package/src/codec/vendor/protobuf.js +53 -0
- package/src/delegation/caps.js +60 -0
- package/src/delegation/config.js +32 -0
- package/src/device/model.js +246 -0
- package/src/device/recording.js +198 -0
- package/src/device/stream-model.js +151 -0
- package/src/documents/documents.js +1224 -0
- package/src/effects/catalog.js +63 -0
- package/src/effects/extras.js +133 -0
- package/src/effects/parse.js +339 -0
- package/src/embed/protocol.js +131 -0
- package/src/env/env.js +159 -0
- package/src/exact/vendor.js +45 -0
- package/src/example-meta.js +164 -0
- package/src/examples.js +94 -0
- package/src/export/canvas-image.js +217 -0
- package/src/export/expr-latex-lazy.js +8 -0
- package/src/export/formats.js +322 -0
- package/src/export/latex.js +183 -0
- package/src/export/pane.js +184 -0
- package/src/export/value.js +452 -0
- package/src/export/zip.js +214 -0
- package/src/ext/access.js +58 -0
- package/src/ext/btasks.js +225 -0
- package/src/ext/client.js +209 -0
- package/src/ext/tools.js +69 -0
- package/src/ext/view.js +105 -0
- package/src/ext/webmcp-tabs.js +299 -0
- package/src/files/archive.js +232 -0
- package/src/files/files.js +317 -0
- package/src/formats/json.js +24 -0
- package/src/formats/jupyter.js +188 -0
- package/src/formats/markdown.js +254 -0
- package/src/formats/n8n.js +276 -0
- package/src/formats/node-red.js +363 -0
- package/src/formats/registry.js +177 -0
- package/src/formats/rivet.js +259 -0
- package/src/formats/shared.js +98 -0
- package/src/formats/structure.js +182 -0
- package/src/formats/yaml.js +127 -0
- package/src/frame/frame.js +962 -0
- package/src/frame/vendor.js +1484 -0
- package/src/gate/audit.js +116 -0
- package/src/gate/gate.js +365 -0
- package/src/gate/policy.js +295 -0
- package/src/gate/scripted.js +110 -0
- package/src/gate/seams.js +32 -0
- package/src/gate/store.js +66 -0
- package/src/geometry/model.js +533 -0
- package/src/grant-key.js +149 -0
- package/src/graph/model.js +381 -0
- package/src/headless/a2a-push.js +123 -0
- package/src/headless/channels/config.js +142 -0
- package/src/headless/channels/connectors.js +283 -0
- package/src/headless/channels/index.js +257 -0
- package/src/headless/channels/mail.js +197 -0
- package/src/headless/channels/mailnet.js +223 -0
- package/src/headless/channels/platforms.js +194 -0
- package/src/headless/channels/replay.js +49 -0
- package/src/headless/cli.js +1397 -0
- package/src/headless/companion-client.js +182 -0
- package/src/headless/cost-cli.js +177 -0
- package/src/headless/deprecations-cli.js +102 -0
- package/src/headless/examples.js +48 -0
- package/src/headless/ffmpeg-exec.js +217 -0
- package/src/headless/gateways/config.js +213 -0
- package/src/headless/gateways/homeassistant.js +159 -0
- package/src/headless/gateways/index.js +121 -0
- package/src/headless/gateways/matter.js +150 -0
- package/src/headless/gateways/mqtt-client.js +177 -0
- package/src/headless/gateways/mqtt.js +70 -0
- package/src/headless/gateways/netway.js +226 -0
- package/src/headless/gateways/serverpod-worker.mjs +16 -0
- package/src/headless/gateways/serverpod.js +71 -0
- package/src/headless/gateways/util.js +27 -0
- package/src/headless/grant-cli.js +208 -0
- package/src/headless/guard.js +125 -0
- package/src/headless/guards.js +124 -0
- package/src/headless/machine-cli.js +853 -0
- package/src/headless/mcp-endpoint.js +287 -0
- package/src/headless/mcp-roots.js +38 -0
- package/src/headless/model-endpoint.js +88 -0
- package/src/headless/net.js +151 -0
- package/src/headless/node.js +263 -0
- package/src/headless/npm-tarball.js +29 -0
- package/src/headless/operator-page.js +112 -0
- package/src/headless/operator.js +242 -0
- package/src/headless/people.js +34 -0
- package/src/headless/pkg-cli.js +1103 -0
- package/src/headless/pkg-serve.js +138 -0
- package/src/headless/process-worker.js +88 -0
- package/src/headless/runner-remote.js +477 -0
- package/src/headless/sandbox-child.mjs +21 -0
- package/src/headless/scheduled.js +557 -0
- package/src/headless/serve-stream.js +97 -0
- package/src/headless/serve.js +2238 -0
- package/src/headless/short-links.js +158 -0
- package/src/headless/static-dirs.js +207 -0
- package/src/headless/trust-file.js +51 -0
- package/src/headless/watch.js +291 -0
- package/src/headless/ws-connect.js +65 -0
- package/src/headless/ws-connections.js +44 -0
- package/src/headless/ws-echo.js +150 -0
- package/src/headless/ws-proxy.js +354 -0
- package/src/headless/ws-ticket.js +48 -0
- package/src/hooks/config.js +50 -0
- package/src/hooks/engine.js +189 -0
- package/src/input/log.js +613 -0
- package/src/input/player.js +217 -0
- package/src/input/replay.js +209 -0
- package/src/jth/vendor.js +28 -0
- package/src/ledger/tx.js +94 -0
- package/src/machine/apply.js +193 -0
- package/src/machine/diff.js +168 -0
- package/src/machine/drive.js +296 -0
- package/src/machine/engine.js +478 -0
- package/src/machine/files-tool.js +76 -0
- package/src/machine/lint.js +139 -0
- package/src/machine/llmtm-trace.js +117 -0
- package/src/machine/llmtm.js +475 -0
- package/src/machine/otel.js +80 -0
- package/src/machine/pane-provider.js +51 -0
- package/src/machine/propose.js +159 -0
- package/src/machine/random.js +52 -0
- package/src/machine/risk.js +107 -0
- package/src/machine/session.js +1017 -0
- package/src/machine/shell-tool.js +45 -0
- package/src/machine/tape.js +349 -0
- package/src/machine/templates.js +104 -0
- package/src/machine/trace.js +664 -0
- package/src/machine/view.js +73 -0
- package/src/machine/vm-tool.js +47 -0
- package/src/machine/watchdog.js +46 -0
- package/src/mcp/app-args.js +51 -0
- package/src/mcp/app-run.js +56 -0
- package/src/mcp/apps.js +468 -0
- package/src/mcp/cache.js +232 -0
- package/src/mcp/client.js +507 -0
- package/src/mcp/demo-app.js +183 -0
- package/src/mcp/demo-server.js +602 -0
- package/src/mcp/elicitation.js +116 -0
- package/src/mcp/hub.js +1326 -0
- package/src/mcp/roots.js +139 -0
- package/src/mcp/sampling.js +105 -0
- package/src/mcp/settings.js +125 -0
- package/src/mcp/tape.js +292 -0
- package/src/mcp/uri-template.js +156 -0
- package/src/mcp/wsh-client.js +164 -0
- package/src/media/animated-codec.js +7 -0
- package/src/media/animated.js +623 -0
- package/src/media/compare-agent.js +70 -0
- package/src/media/compare-job.js +63 -0
- package/src/media/compare-page.js +296 -0
- package/src/media/compare-worker.js +14 -0
- package/src/media/compare.js +600 -0
- package/src/media/contract.js +62 -0
- package/src/media/decode-frame.js +57 -0
- package/src/media/decode-pool.js +188 -0
- package/src/media/ffmpeg-edit.js +344 -0
- package/src/media/ffmpeg-wasm-client.js +121 -0
- package/src/media/ffmpeg-wasm-session.js +79 -0
- package/src/media/ffmpeg-wasm.js +139 -0
- package/src/media/ffmpeg-worker.js +23 -0
- package/src/media/ffmpeg.js +903 -0
- package/src/media/helpers.js +419 -0
- package/src/media/keep.js +108 -0
- package/src/media/metadata-worker.js +16 -0
- package/src/media/metadata.js +2518 -0
- package/src/media/mime.js +102 -0
- package/src/media/page-decode.js +74 -0
- package/src/media/persist.js +114 -0
- package/src/media/png.js +226 -0
- package/src/media/sample-input.js +67 -0
- package/src/media/store.js +86 -0
- package/src/media/wav.js +109 -0
- package/src/midi/mappings.js +250 -0
- package/src/midi/message.js +125 -0
- package/src/model/action-hub.js +143 -0
- package/src/model/adapters.js +284 -0
- package/src/model/agent-runs.js +12 -0
- package/src/model/arrange.js +308 -0
- package/src/model/automation-clock.js +494 -0
- package/src/model/automation.js +653 -0
- package/src/model/batches.js +78 -0
- package/src/model/binary-view.js +195 -0
- package/src/model/breakpoints.js +392 -0
- package/src/model/calc-settings.js +65 -0
- package/src/model/calendar.js +254 -0
- package/src/model/canvas-id.js +5 -0
- package/src/model/canvas.js +5048 -0
- package/src/model/channel-names.js +29 -0
- package/src/model/channels.js +692 -0
- package/src/model/chart-clock.js +631 -0
- package/src/model/chart-code.js +69 -0
- package/src/model/codecs.js +60 -0
- package/src/model/companion-access.js +271 -0
- package/src/model/companion-pane.js +50 -0
- package/src/model/composite.js +324 -0
- package/src/model/context.js +380 -0
- package/src/model/controls.js +231 -0
- package/src/model/converter-presets.js +368 -0
- package/src/model/cost.js +580 -0
- package/src/model/curve-transform.js +122 -0
- package/src/model/cycles.js +176 -0
- package/src/model/debug-log.js +168 -0
- package/src/model/decision-clock.js +100 -0
- package/src/model/decisions.js +265 -0
- package/src/model/desk.js +87 -0
- package/src/model/device-hub.js +400 -0
- package/src/model/diff.js +445 -0
- package/src/model/emit-events.js +179 -0
- package/src/model/errors.js +238 -0
- package/src/model/event-presets.js +297 -0
- package/src/model/events.js +1303 -0
- package/src/model/explicit-setters.js +139 -0
- package/src/model/field-mapping.js +623 -0
- package/src/model/files-pane.js +263 -0
- package/src/model/flow-idle.js +89 -0
- package/src/model/foreach.js +549 -0
- package/src/model/frame-loop.js +71 -0
- package/src/model/frame-pressure.js +180 -0
- package/src/model/function-scaffold.js +1000 -0
- package/src/model/geometry-settings.js +54 -0
- package/src/model/goals.js +176 -0
- package/src/model/graph-settings.js +76 -0
- package/src/model/grid-widget.js +175 -0
- package/src/model/groups.js +332 -0
- package/src/model/hash.js +21 -0
- package/src/model/history.js +259 -0
- package/src/model/http-copy.js +88 -0
- package/src/model/http-send-companion.js +110 -0
- package/src/model/http-send.js +163 -0
- package/src/model/http-tap.js +521 -0
- package/src/model/http-tools.js +1138 -0
- package/src/model/import-lock.js +78 -0
- package/src/model/imports.js +258 -0
- package/src/model/infer-outputs.js +822 -0
- package/src/model/ink-connect.js +150 -0
- package/src/model/ink-diff.js +75 -0
- package/src/model/ink-gone.js +71 -0
- package/src/model/ink-route.js +120 -0
- package/src/model/ink-svg.js +206 -0
- package/src/model/ink.js +739 -0
- package/src/model/input-log-hub.js +456 -0
- package/src/model/input-split.js +69 -0
- package/src/model/json-schema-host.js +9 -0
- package/src/model/json-schema.js +368 -0
- package/src/model/jth.js +78 -0
- package/src/model/latex-expr.js +528 -0
- package/src/model/layout-history.js +120 -0
- package/src/model/lazy-map.js +88 -0
- package/src/model/ledger-pane.js +101 -0
- package/src/model/legacy-viaframe.js +90 -0
- package/src/model/lessons.js +448 -0
- package/src/model/links.js +981 -0
- package/src/model/live.js +411 -0
- package/src/model/math-widget.js +53 -0
- package/src/model/memory-settings.js +33 -0
- package/src/model/midi-controls.js +350 -0
- package/src/model/nl-time.js +408 -0
- package/src/model/notebook.js +137 -0
- package/src/model/pane-view-store.js +15 -0
- package/src/model/partial.js +115 -0
- package/src/model/pause-clock.js +53 -0
- package/src/model/peer-pane.js +32 -0
- package/src/model/persist-state.js +290 -0
- package/src/model/person-only.js +122 -0
- package/src/model/pin.js +209 -0
- package/src/model/plot-3d.js +213 -0
- package/src/model/plot-series.js +157 -0
- package/src/model/plot-settings.js +531 -0
- package/src/model/ports.js +312 -0
- package/src/model/presentation.js +222 -0
- package/src/model/preset-apply.js +316 -0
- package/src/model/preset-banks.js +335 -0
- package/src/model/preset-morph.js +263 -0
- package/src/model/preset-ops.js +205 -0
- package/src/model/preset-player.js +283 -0
- package/src/model/preset-states.js +172 -0
- package/src/model/profile-settings.js +109 -0
- package/src/model/promote.js +103 -0
- package/src/model/protected.js +10 -0
- package/src/model/proxy-log.js +230 -0
- package/src/model/proxy.js +367 -0
- package/src/model/quantity-widget.js +61 -0
- package/src/model/queue-book.js +359 -0
- package/src/model/quick-add.js +224 -0
- package/src/model/rate-limit.js +313 -0
- package/src/model/rate.js +95 -0
- package/src/model/recovery.js +216 -0
- package/src/model/rename-follow.js +113 -0
- package/src/model/repeater.js +1126 -0
- package/src/model/retention.js +664 -0
- package/src/model/route-edit.js +132 -0
- package/src/model/router.js +155 -0
- package/src/model/runaway.js +232 -0
- package/src/model/runlog.js +1033 -0
- package/src/model/runners/a2a.js +2 -0
- package/src/model/runners/acp.js +2 -0
- package/src/model/runners/actions.js +4 -0
- package/src/model/runners/agent.js +4 -0
- package/src/model/runners/audio.js +21 -0
- package/src/model/runners/automation.js +2 -0
- package/src/model/runners/calc.js +23 -0
- package/src/model/runners/catch.js +10 -0
- package/src/model/runners/codec.js +24 -0
- package/src/model/runners/companion-run.js +2 -0
- package/src/model/runners/device.js +7 -0
- package/src/model/runners/dom.js +13 -0
- package/src/model/runners/effects.js +2 -0
- package/src/model/runners/embed.js +11 -0
- package/src/model/runners/eval.js +2 -0
- package/src/model/runners/files.js +19 -0
- package/src/model/runners/geometry.js +23 -0
- package/src/model/runners/goals.js +18 -0
- package/src/model/runners/graph.js +23 -0
- package/src/model/runners/html.js +2 -0
- package/src/model/runners/http-proxy.js +185 -0
- package/src/model/runners/http-send.js +61 -0
- package/src/model/runners/http-static.js +83 -0
- package/src/model/runners/http-tap.js +26 -0
- package/src/model/runners/http.js +40 -0
- package/src/model/runners/import.js +2 -0
- package/src/model/runners/index.js +74 -0
- package/src/model/runners/input.js +14 -0
- package/src/model/runners/inputlog.js +7 -0
- package/src/model/runners/ledger.js +15 -0
- package/src/model/runners/machine.js +4 -0
- package/src/model/runners/mcp.js +2 -0
- package/src/model/runners/mcpapp.js +2 -0
- package/src/model/runners/media.js +18 -0
- package/src/model/runners/memory.js +28 -0
- package/src/model/runners/mesh-inspect.js +13 -0
- package/src/model/runners/peer.js +14 -0
- package/src/model/runners/plot.js +22 -0
- package/src/model/runners/render.js +14 -0
- package/src/model/runners/respond.js +2 -0
- package/src/model/runners/sample-soundfont.js +85 -0
- package/src/model/runners/sample.js +159 -0
- package/src/model/runners/scene.js +8 -0
- package/src/model/runners/score.js +24 -0
- package/src/model/runners/secret.js +10 -0
- package/src/model/runners/select.js +2 -0
- package/src/model/runners/shared.js +4 -0
- package/src/model/runners/shares.js +15 -0
- package/src/model/runners/shell.js +7 -0
- package/src/model/runners/skill.js +26 -0
- package/src/model/runners/state.js +2 -0
- package/src/model/runners/statechart.js +4 -0
- package/src/model/runners/subgraph.js +9 -0
- package/src/model/runners/tabs.js +25 -0
- package/src/model/runners/terminal.js +5 -0
- package/src/model/runners/text.js +4 -0
- package/src/model/runners/timer.js +7 -0
- package/src/model/runners/traffic.js +65 -0
- package/src/model/runners/trigger.js +2 -0
- package/src/model/runners/verdict.js +29 -0
- package/src/model/runners/vm.js +7 -0
- package/src/model/runners/wait.js +4 -0
- package/src/model/runners/ws-client.js +57 -0
- package/src/model/safe-regex.js +719 -0
- package/src/model/sample-settings.js +43 -0
- package/src/model/sample-source.js +47 -0
- package/src/model/saved-mapping.js +153 -0
- package/src/model/score-controllers.js +87 -0
- package/src/model/score-edit.js +399 -0
- package/src/model/score-instruments.js +300 -0
- package/src/model/score-library.js +407 -0
- package/src/model/score-markup.js +235 -0
- package/src/model/score-mix.js +248 -0
- package/src/model/score-patterns.js +276 -0
- package/src/model/score-selection.js +34 -0
- package/src/model/score-time.js +139 -0
- package/src/model/score-transforms.js +336 -0
- package/src/model/score-transport.js +192 -0
- package/src/model/selection.js +351 -0
- package/src/model/serial-controls.js +328 -0
- package/src/model/shares-pane.js +17 -0
- package/src/model/shell-pane.js +106 -0
- package/src/model/signature.js +1122 -0
- package/src/model/size-hints.js +106 -0
- package/src/model/size-ratio.js +12 -0
- package/src/model/skill-settings.js +23 -0
- package/src/model/snapping.js +466 -0
- package/src/model/split.js +375 -0
- package/src/model/spring-player.js +222 -0
- package/src/model/statecharts.js +1369 -0
- package/src/model/states-preset.js +208 -0
- package/src/model/static-route.js +100 -0
- package/src/model/step-words.js +45 -0
- package/src/model/subgraph.js +1042 -0
- package/src/model/switch.js +98 -0
- package/src/model/tabs-store.js +10 -0
- package/src/model/tensor-view.js +146 -0
- package/src/model/timer-clock.js +361 -0
- package/src/model/timers.js +422 -0
- package/src/model/timing.js +212 -0
- package/src/model/traffic-agent.js +111 -0
- package/src/model/traffic-store.js +20 -0
- package/src/model/traffic.js +665 -0
- package/src/model/transport.js +364 -0
- package/src/model/turns.js +86 -0
- package/src/model/types.js +425 -0
- package/src/model/value-path.js +138 -0
- package/src/model/versions.js +535 -0
- package/src/model/view-outputs.js +144 -0
- package/src/model/viewport-bookmarks.js +194 -0
- package/src/model/virtual-clock.js +85 -0
- package/src/model/vm-pane.js +258 -0
- package/src/model/wait-clock.js +715 -0
- package/src/model/wait-persist.js +248 -0
- package/src/model/waits.js +431 -0
- package/src/model/watch.js +80 -0
- package/src/model/webhook.js +496 -0
- package/src/model/when.js +48 -0
- package/src/model/widget-values.js +392 -0
- package/src/model/window-commands.js +278 -0
- package/src/model/windows.js +348 -0
- package/src/model/wire-inspect.js +343 -0
- package/src/model/wire-ops.js +324 -0
- package/src/model/wire-pipeline.js +378 -0
- package/src/model/wire-route.js +637 -0
- package/src/model/workspaces.js +122 -0
- package/src/model/ws-client.js +155 -0
- package/src/model/ws-demo.js +31 -0
- package/src/model/ws-frames.js +141 -0
- package/src/model/ws-hub.js +219 -0
- package/src/model/ws-served.js +13 -0
- package/src/model/xstate.js +374 -0
- package/src/narrative/narrative.js +1557 -0
- package/src/network/auth.js +224 -0
- package/src/network/csp-frame.js +197 -0
- package/src/network/declarative-shadow.js +27 -0
- package/src/network/frame-net-shim.js +962 -0
- package/src/network/hosts.js +157 -0
- package/src/network/policy.js +520 -0
- package/src/network/rtc-shim.js +418 -0
- package/src/network/secret-gate.js +78 -0
- package/src/network/secrets.js +261 -0
- package/src/network/sockets.js +287 -0
- package/src/network/store.js +186 -0
- package/src/network/streams.js +99 -0
- package/src/packages/asset-values.js +50 -0
- package/src/packages/assets.js +99 -0
- package/src/packages/deprecation.js +203 -0
- package/src/packages/fetch.js +152 -0
- package/src/packages/function-canvas.js +73 -0
- package/src/packages/module.js +120 -0
- package/src/packages/package.js +474 -0
- package/src/packages/published.js +27 -0
- package/src/packages/requires.js +83 -0
- package/src/packages/signing.js +145 -0
- package/src/packages/trust.js +107 -0
- package/src/panes/a2a.js +51 -0
- package/src/panes/acp.js +60 -0
- package/src/panes/actions.js +54 -0
- package/src/panes/agent.js +83 -0
- package/src/panes/audio.js +103 -0
- package/src/panes/automation.js +112 -0
- package/src/panes/calc.js +67 -0
- package/src/panes/catch.js +52 -0
- package/src/panes/codec.js +59 -0
- package/src/panes/colors.js +12 -0
- package/src/panes/companion.js +54 -0
- package/src/panes/decision.js +65 -0
- package/src/panes/device.js +56 -0
- package/src/panes/dom.js +37 -0
- package/src/panes/effects.js +118 -0
- package/src/panes/embed.js +30 -0
- package/src/panes/eval.js +186 -0
- package/src/panes/fields.js +299 -0
- package/src/panes/files.js +45 -0
- package/src/panes/gate.js +70 -0
- package/src/panes/geometry.js +64 -0
- package/src/panes/goals.js +75 -0
- package/src/panes/graph.js +66 -0
- package/src/panes/html.js +54 -0
- package/src/panes/http.js +82 -0
- package/src/panes/import.js +38 -0
- package/src/panes/input.js +124 -0
- package/src/panes/inputlog.js +66 -0
- package/src/panes/ledger.js +56 -0
- package/src/panes/machine.js +138 -0
- package/src/panes/mcp.js +85 -0
- package/src/panes/mcpapp.js +64 -0
- package/src/panes/media.js +38 -0
- package/src/panes/memory.js +46 -0
- package/src/panes/mesh-inspect.js +49 -0
- package/src/panes/note.js +38 -0
- package/src/panes/peer.js +44 -0
- package/src/panes/plot.js +196 -0
- package/src/panes/registry.js +475 -0
- package/src/panes/render.js +87 -0
- package/src/panes/respond.js +44 -0
- package/src/panes/router.js +84 -0
- package/src/panes/sample.js +75 -0
- package/src/panes/scene.js +55 -0
- package/src/panes/score.js +87 -0
- package/src/panes/secret.js +38 -0
- package/src/panes/select.js +67 -0
- package/src/panes/shader.js +166 -0
- package/src/panes/shared.js +33 -0
- package/src/panes/shares.js +43 -0
- package/src/panes/shell.js +47 -0
- package/src/panes/skill.js +44 -0
- package/src/panes/state.js +91 -0
- package/src/panes/statechart.js +63 -0
- package/src/panes/story.js +33 -0
- package/src/panes/subgraph.js +94 -0
- package/src/panes/tabs.js +52 -0
- package/src/panes/terminal.js +57 -0
- package/src/panes/text.js +36 -0
- package/src/panes/timer.js +55 -0
- package/src/panes/traffic.js +59 -0
- package/src/panes/verdict.js +62 -0
- package/src/panes/vm.js +46 -0
- package/src/panes/wait.js +61 -0
- package/src/panes/watch.js +57 -0
- package/src/panes/webhook.js +67 -0
- package/src/panes/ws-client.js +67 -0
- package/src/persist.js +281 -0
- package/src/plot/tex.js +19 -0
- package/src/plot/vendor.js +59 -0
- package/src/plot/view-vendor.js +5 -0
- package/src/privacy/levels.js +108 -0
- package/src/protocol/devtools.js +116 -0
- package/src/protocol/inspector.js +368 -0
- package/src/render/time.js +381 -0
- package/src/rooms/mesh-metrics.js +162 -0
- package/src/run/companion.js +355 -0
- package/src/run/describe.js +114 -0
- package/src/run/local-model.js +150 -0
- package/src/run/monitor.js +208 -0
- package/src/run/publish.js +360 -0
- package/src/run/respond-outcome.js +12 -0
- package/src/run/run.js +820 -0
- package/src/run/runner-pairing.js +243 -0
- package/src/run/values.js +122 -0
- package/src/runtime/compile.js +122 -0
- package/src/runtime/console-tag.js +64 -0
- package/src/runtime/frame-signals.js +126 -0
- package/src/runtime/iteration-push.js +19 -0
- package/src/runtime/keys.js +474 -0
- package/src/runtime/midi-input.js +170 -0
- package/src/runtime/person-waits.js +140 -0
- package/src/runtime/resource-timing.js +56 -0
- package/src/runtime/runtime.js +2150 -0
- package/src/runtime/sandbox-modules.js +163 -0
- package/src/runtime/spring.js +246 -0
- package/src/runtime/strict.js +215 -0
- package/src/runtime/transfer.js +75 -0
- package/src/runtime/tween.js +158 -0
- package/src/runtime/wasm-fuel.js +596 -0
- package/src/runtime/worker/00-prelude.js +88 -0
- package/src/runtime/worker/10-helpers.js +295 -0
- package/src/runtime/worker/20-io.js +645 -0
- package/src/runtime/worker/30-previews.js +210 -0
- package/src/runtime/worker/40-profile-lineage.js +278 -0
- package/src/runtime/worker/50-own-worker.js +233 -0
- package/src/runtime/worker/60-timers.js +172 -0
- package/src/runtime/worker/70-state-keyed.js +193 -0
- package/src/runtime/worker/80-each-compile-generators.js +619 -0
- package/src/runtime/worker/90-events-operators.js +655 -0
- package/src/runtime/worker/95-agents-batches.js +1820 -0
- package/src/runtime/worker/96-plot.js +47 -0
- package/src/runtime/worker/97-calc.js +28 -0
- package/src/runtime/worker/98-geometry.js +24 -0
- package/src/runtime/worker/99-graph.js +30 -0
- package/src/runtime/worker/99-shell.js +30 -0
- package/src/safety/config.js +57 -0
- package/src/safety/engine.js +324 -0
- package/src/scene/pixi-scene.js +806 -0
- package/src/scene/scene-assets.js +241 -0
- package/src/scene/scene-edit.js +319 -0
- package/src/secret/settings.js +41 -0
- package/src/security/multipart.js +257 -0
- package/src/security/redact.js +261 -0
- package/src/serial/broker.js +473 -0
- package/src/serial/config.js +185 -0
- package/src/serial/framers.js +389 -0
- package/src/serial/packets.js +64 -0
- package/src/shader/audio-texture.js +87 -0
- package/src/shader/channels.js +496 -0
- package/src/shader/common.js +90 -0
- package/src/shader/model.js +867 -0
- package/src/shader/passes.js +150 -0
- package/src/shader/shadertoy.js +198 -0
- package/src/shell/hub.js +287 -0
- package/src/sim/checkpoints.js +850 -0
- package/src/sim/compile.js +37 -0
- package/src/sim/fixed.js +377 -0
- package/src/sim/headless.js +205 -0
- package/src/sim/physics.js +399 -0
- package/src/smf-helper/vendor.js +2 -0
- package/src/sources/config.js +435 -0
- package/src/storage.js +153 -0
- package/src/table/table-geo.js +2344 -0
- package/src/table/table-lineage.js +808 -0
- package/src/table/table-quality.js +355 -0
- package/src/table/table-schema.js +392 -0
- package/src/table/table-sql.js +1650 -0
- package/src/table/table-stats.js +480 -0
- package/src/table/table.js +2102 -0
- package/src/tensor/tensor.js +1153 -0
- package/src/terminal/hub.js +715 -0
- package/src/terminal/screen.js +516 -0
- package/src/tests/capture.js +88 -0
- package/src/tests/compare.js +480 -0
- package/src/tests/dataset.js +170 -0
- package/src/tests/evaluate.js +286 -0
- package/src/tests/from-runs.js +99 -0
- package/src/tests/judge.js +134 -0
- package/src/tests/matchers.js +263 -0
- package/src/tests/matrix-spec.js +87 -0
- package/src/tests/matrix.js +397 -0
- package/src/tests/metrics.js +369 -0
- package/src/tests/no-value.js +42 -0
- package/src/tests/pane-check.js +45 -0
- package/src/tests/report.js +124 -0
- package/src/tests/reporters.js +140 -0
- package/src/tests/run.js +155 -0
- package/src/tilemap/tilemap.js +1122 -0
- package/src/units/units.js +3 -0
- package/src/util/bytes-text.js +21 -0
- package/src/util/num.js +10 -0
- package/src/util/regexp.js +2 -0
- package/src/util/text.js +38 -0
- package/src/verdict/engine.js +154 -0
- package/src/vm/guest-wsh.js +108 -0
- package/src/vm/hub.js +457 -0
- package/src/vm/image-files.js +4 -0
- package/src/vm/image.js +33 -0
- package/src/vm/image.lock.json +13 -0
- package/src/vm/link.js +266 -0
- package/src/vm/mount.js +212 -0
- package/src/vm/net.js +85 -0
- package/src/vm/pipe-ws.js +187 -0
- package/src/vm/v86-loader.js +11 -0
- package/src/webmcp/args.js +212 -0
- package/src/webmcp/hidden.js +218 -0
- package/src/webmcp/text.js +250 -0
- package/src/webmcp/tools/bookmark-tools.js +106 -0
- package/src/webmcp/tools/breakpoint-tools.js +48 -0
- package/src/webmcp/tools/canvases.js +208 -0
- package/src/webmcp/tools/context-tools.js +84 -0
- package/src/webmcp/tools/core.js +170 -0
- package/src/webmcp/tools/devices.js +41 -0
- package/src/webmcp/tools/edit.js +357 -0
- package/src/webmcp/tools/event-tools.js +145 -0
- package/src/webmcp/tools/image-tools.js +173 -0
- package/src/webmcp/tools/ink-tools.js +247 -0
- package/src/webmcp/tools/input-log-tools.js +163 -0
- package/src/webmcp/tools/live.js +166 -0
- package/src/webmcp/tools/machine-tools.js +74 -0
- package/src/webmcp/tools/media.js +161 -0
- package/src/webmcp/tools/midi-tools.js +32 -0
- package/src/webmcp/tools/preset-tools.js +184 -0
- package/src/webmcp/tools/quick-add-tools.js +95 -0
- package/src/webmcp/tools/reshape.js +152 -0
- package/src/webmcp/tools/run-tools.js +309 -0
- package/src/webmcp/tools/runs.js +101 -0
- package/src/webmcp/tools/scaffold-tools.js +161 -0
- package/src/webmcp/tools/serial-tools.js +36 -0
- package/src/webmcp/tools/shared.js +338 -0
- package/src/webmcp/tools/subgraphs.js +360 -0
- package/src/webmcp/tools/tests.js +170 -0
- package/src/webmcp/tools/traffic-tools.js +70 -0
- package/src/webmcp/tools/transport-tools.js +65 -0
- package/src/webmcp/tools/version-tools.js +126 -0
- package/src/webmcp/tools/versions.js +11 -0
- package/src/webmcp/tools/wire-tools.js +90 -0
- package/src/webmcp/tools/workspace-tools.js +93 -0
- package/src/webmcp/tools.js +1323 -0
- package/src/wsh/connect.js +347 -0
- package/src/wsh/demo-host.js +361 -0
- package/src/wsh/e2e.js +27 -0
- package/src/wsh/keys.js +154 -0
- package/src/wsh/known-hosts.js +39 -0
- package/src/wsh/private-key.js +95 -0
- package/src/wsh/reverse.js +34 -0
- package/src/wsh/settings.js +118 -0
- package/src/wsh/transfer.js +62 -0
- package/src/wsh/vendor.js +5 -0
- package/src/x402/challenge.js +171 -0
- package/src/x402/demo-server.js +127 -0
- package/src/x402/pay.js +125 -0
- package/src/x402/retry.js +95 -0
- package/src/x402/store.js +76 -0
|
@@ -0,0 +1,623 @@
|
|
|
1
|
+
// Field mapping: the fields of a sample value, a mapping from them
|
|
2
|
+
// into a pane's parameter, and a preview of that mapping on several fixtures
|
|
3
|
+
// before anything is committed.
|
|
4
|
+
//
|
|
5
|
+
// 1. Fields. `fieldsOfPreview(preview)` (a value's preview tree, the
|
|
6
|
+
// @johnhenry/inspectable serialize format every pane already holds) or
|
|
7
|
+
// `fieldsOfValue(json)` (a pinned value, a pasted sample) list the nested
|
|
8
|
+
// fields with their types, a sample, and whether they may be missing.
|
|
9
|
+
// Arrays are one field `users[]` standing for any item (its accessor reads
|
|
10
|
+
// item 0). `mergeFieldSets` joins the fields of several samples: a field is
|
|
11
|
+
// optional when some sample lacks it or holds null there.
|
|
12
|
+
//
|
|
13
|
+
// 2. A mapping is plain data (the field picker keeps it on its pane in the bounded
|
|
14
|
+
// form of src/model/saved-mapping.js, beside the code it made):
|
|
15
|
+
// { parts: [ { text: "Hello " },
|
|
16
|
+
// { field: { input: "user", steps: [{ key: "name" }], safe? },
|
|
17
|
+
// fallback?: "'there'", // JavaScript, used when the field is missing/null/undefined
|
|
18
|
+
// expect?: "string" } ], // the type the parameter wants
|
|
19
|
+
// expect?: "string" }
|
|
20
|
+
// `fieldRef` makes a field part's `field` from a field; `compileMapping`
|
|
21
|
+
// turns the mapping into JavaScript (`` `Hello ${user?.name ?? 'there'}` ``;
|
|
22
|
+
// a lone field is the bare expression, so its type is kept).
|
|
23
|
+
//
|
|
24
|
+
// 3. `previewMapping(mapping, fixtures)` evaluates the parts on each fixture
|
|
25
|
+
// (`{ label, inputs: { user: {…} } }`) without running any pane: fields are
|
|
26
|
+
// read by their steps, a fallback that is a literal or a path over the same
|
|
27
|
+
// fixture is evaluated here, any other fallback only by the `evaluate`
|
|
28
|
+
// callback the caller passes (else it is reported as not previewed);
|
|
29
|
+
// `previewMappingAsync` takes an asynchronous one, which the picker backs
|
|
30
|
+
// with a Worker that has no variables, secrets or network (fallback-eval.js). Each
|
|
31
|
+
// problem names the source path and the fixture.
|
|
32
|
+
//
|
|
33
|
+
// 4. `fieldCompletions(fieldSet, before)` offers a field's children while
|
|
34
|
+
// someone types `users[0].na`.
|
|
35
|
+
//
|
|
36
|
+
// Mapping code only ever reads the pane's inputs; nothing here touches
|
|
37
|
+
// secrets, env or the network. Pure: no DOM, no canvas (src/model/field-sources.js
|
|
38
|
+
// is the canvas side); it runs under node --test.
|
|
39
|
+
import { stepFor, pathExpression, previewToJSON } from "./value-path.js";
|
|
40
|
+
import { checkInputName } from "../runtime/compile.js";
|
|
41
|
+
import { plural } from "../util/text.js";
|
|
42
|
+
|
|
43
|
+
export const FIELD_LIMITS = { depth: 8, fields: 400, items: 100 };
|
|
44
|
+
|
|
45
|
+
const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
|
|
46
|
+
const NULLISH = new Set(["null", "undefined"]);
|
|
47
|
+
|
|
48
|
+
/** A value's type name for fields: null, undefined, string, number, boolean, array, object, or typeof's. */
|
|
49
|
+
export function typeOfValue(v) {
|
|
50
|
+
if (v === null) return "null";
|
|
51
|
+
if (Array.isArray(v)) return "array";
|
|
52
|
+
return typeof v === "object" ? "object" : typeof v;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const clip = (s, n = 60) => (s.length > n ? `${s.slice(0, n - 1)}…` : s);
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
function valueSample(v) {
|
|
59
|
+
switch (typeOfValue(v)) {
|
|
60
|
+
case "string":
|
|
61
|
+
return clip(JSON.stringify(v));
|
|
62
|
+
case "array":
|
|
63
|
+
return `[${plural(v.length, "item")}]`;
|
|
64
|
+
case "object":
|
|
65
|
+
return `{${plural(Object.keys(v).length, "key")}}`;
|
|
66
|
+
default:
|
|
67
|
+
return String(v);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// ── the two ways to look inside a sample ─────────────────────────────────────
|
|
72
|
+
// Each adapter gives a node's `type`, `sample` and `children(node)`:
|
|
73
|
+
// null a leaf
|
|
74
|
+
// { items: [node], step, truncated } an array or set: one field for any item
|
|
75
|
+
// { entries: [{ id, label, step, node }], truncated } an object or map
|
|
76
|
+
|
|
77
|
+
const valueAdapter = {
|
|
78
|
+
type: typeOfValue,
|
|
79
|
+
sample: valueSample,
|
|
80
|
+
children(v) {
|
|
81
|
+
if (Array.isArray(v)) return { items: v.slice(0, FIELD_LIMITS.items), step: { index: 0 }, truncated: v.length > FIELD_LIMITS.items };
|
|
82
|
+
if (v && typeof v === "object") {
|
|
83
|
+
return { entries: Object.keys(v).map((key) => ({ id: key, label: key, step: { key }, node: v[key] })), truncated: false };
|
|
84
|
+
}
|
|
85
|
+
return null;
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const PREVIEW_TYPES = { typedarray: "array", set: "array", map: "object", module: "object", error: "object" };
|
|
90
|
+
|
|
91
|
+
const previewAdapter = {
|
|
92
|
+
type: (node) => PREVIEW_TYPES[node?.type] ?? node?.type ?? "undefined",
|
|
93
|
+
sample(node) {
|
|
94
|
+
switch (node?.type) {
|
|
95
|
+
case "string":
|
|
96
|
+
return "value" in node ? clip(JSON.stringify(node.value)) : clip(node.text ?? "''");
|
|
97
|
+
case "array":
|
|
98
|
+
case "typedarray":
|
|
99
|
+
case "set":
|
|
100
|
+
return `[${plural(node.size ?? node.entries?.length ?? 0, "item")}]`;
|
|
101
|
+
case "object":
|
|
102
|
+
case "map":
|
|
103
|
+
case "module":
|
|
104
|
+
case "error":
|
|
105
|
+
return `{${plural(node.size ?? node.entries?.length ?? 0, "key")}}`;
|
|
106
|
+
default:
|
|
107
|
+
return clip(String(node?.text ?? node?.type));
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
children(node) {
|
|
111
|
+
const cut = Boolean(node.more) || (!node.entries && (node.handle || node.size > 0));
|
|
112
|
+
switch (node.type) {
|
|
113
|
+
case "array":
|
|
114
|
+
case "typedarray":
|
|
115
|
+
case "set": {
|
|
116
|
+
const items = (node.entries ?? []).filter((e) => typeof e.key === "string" && /^\d+$/.test(e.key));
|
|
117
|
+
return { items: items.map((e) => e.value), step: items[0] ? stepFor(node, items[0]) : node.type === "set" ? { setIndex: 0 } : { index: 0 }, truncated: cut };
|
|
118
|
+
}
|
|
119
|
+
case "object":
|
|
120
|
+
case "map":
|
|
121
|
+
case "module":
|
|
122
|
+
case "error": {
|
|
123
|
+
const entries = [];
|
|
124
|
+
for (const e of node.entries ?? []) {
|
|
125
|
+
const step = stepFor(node, e);
|
|
126
|
+
if (!step) continue; // no expression reaches it (a symbol key)
|
|
127
|
+
const key = typeof e.key === "string" ? e.key : (e.key?.value ?? e.key?.text);
|
|
128
|
+
entries.push({ id: String(key), label: String(key), step, node: e.value });
|
|
129
|
+
}
|
|
130
|
+
return { entries, truncated: cut };
|
|
131
|
+
}
|
|
132
|
+
default:
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/** The text of a key as it appears in a field's id: `.name` or `["a b"]`; `[]` for any item. */
|
|
139
|
+
const keyText = (step, label) => (label === "[]" ? "[]" : "mapKey" in step ? `.get(${JSON.stringify(step.mapKey)})` : IDENTIFIER.test(label) ? `.${label}` : `[${JSON.stringify(label)}]`);
|
|
140
|
+
|
|
141
|
+
/** A child field's id: `parent` + its key text (no leading dot at the top). */
|
|
142
|
+
const childId = (parent, step, label) => {
|
|
143
|
+
const t = keyText(step, label);
|
|
144
|
+
return parent === "" && t.startsWith(".") ? t.slice(1) : parent + t;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
function collect(root, adapter) {
|
|
148
|
+
const fields = new Map();
|
|
149
|
+
let truncated = false;
|
|
150
|
+
const top = { id: "", types: new Set(), sample: undefined, instances: 0 };
|
|
151
|
+
|
|
152
|
+
const visit = (acc, node, depth) => {
|
|
153
|
+
const type = adapter.type(node);
|
|
154
|
+
acc.types.add(type);
|
|
155
|
+
const sample = adapter.sample(node);
|
|
156
|
+
if (acc.sample === undefined || (NULLISH.has(acc.sampleType) && !NULLISH.has(type))) {
|
|
157
|
+
acc.sample = sample;
|
|
158
|
+
acc.sampleType = type;
|
|
159
|
+
}
|
|
160
|
+
const kids = adapter.children(node);
|
|
161
|
+
if (!kids) return;
|
|
162
|
+
acc.container = true;
|
|
163
|
+
acc.instances++;
|
|
164
|
+
if (kids.truncated) truncated = true;
|
|
165
|
+
if (depth >= FIELD_LIMITS.depth) {
|
|
166
|
+
if (kids.items?.length || kids.entries?.length) truncated = true;
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const child = (id, label, step) => {
|
|
170
|
+
let f = fields.get(id);
|
|
171
|
+
if (!f) {
|
|
172
|
+
if (fields.size >= FIELD_LIMITS.fields) {
|
|
173
|
+
truncated = true;
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
f = { id, parentId: acc.id, label, steps: [...(acc.steps ?? []), step], depth: depth + 1, types: new Set(), sample: undefined, container: false, instances: 0, seen: 0 };
|
|
177
|
+
fields.set(id, f);
|
|
178
|
+
}
|
|
179
|
+
return f;
|
|
180
|
+
};
|
|
181
|
+
if (kids.items) {
|
|
182
|
+
if (!kids.items.length) return;
|
|
183
|
+
const f = child(childId(acc.id, kids.step, "[]"), "[]", kids.step);
|
|
184
|
+
if (!f) return;
|
|
185
|
+
f.seen++;
|
|
186
|
+
for (const item of kids.items) visit(f, item, depth + 1);
|
|
187
|
+
} else {
|
|
188
|
+
for (const e of kids.entries) {
|
|
189
|
+
const f = child(childId(acc.id, e.step, e.label), e.label, e.step);
|
|
190
|
+
if (!f) continue;
|
|
191
|
+
f.seen++;
|
|
192
|
+
visit(f, e.node, depth + 1);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
visit(top, root, 0);
|
|
197
|
+
return { root: top, fields, truncated };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const finishRaw = ({ root, fields, truncated }) => ({
|
|
201
|
+
root: { types: [...root.types], sample: root.sample },
|
|
202
|
+
truncated,
|
|
203
|
+
samples: 1,
|
|
204
|
+
raw: [...fields.values()].map((f) => ({ ...f, types: [...f.types], parentInstances: f.parentId === "" ? root.instances : fields.get(f.parentId)?.instances ?? 0, present: 1 })),
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Join field sets (one per sample) and compute each field's `optional` and
|
|
209
|
+
* `safe`. A field is optional when some sample lacks it (its parent present
|
|
210
|
+
* but not it), or holds null/undefined there; `safe` (its accessor needs `?.`)
|
|
211
|
+
* when an ancestor is optional.
|
|
212
|
+
*/
|
|
213
|
+
export function mergeFieldSets(sets) {
|
|
214
|
+
const list = sets.filter(Boolean);
|
|
215
|
+
const merged = new Map();
|
|
216
|
+
const order = [];
|
|
217
|
+
let truncated = false;
|
|
218
|
+
const rootTypes = new Set();
|
|
219
|
+
let rootSample;
|
|
220
|
+
for (const set of list) {
|
|
221
|
+
truncated ||= set.truncated;
|
|
222
|
+
set.root.types.forEach((t) => rootTypes.add(t));
|
|
223
|
+
if (rootSample === undefined && set.root.sample !== undefined) rootSample = set.root.sample;
|
|
224
|
+
for (const f of set.fields ?? set.raw) {
|
|
225
|
+
let m = merged.get(f.id);
|
|
226
|
+
if (!m) {
|
|
227
|
+
m = { id: f.id, parentId: f.parentId, label: f.label, steps: f.steps, depth: f.depth, types: new Set(), sample: undefined, sampleType: undefined, container: false, missingIn: 0, presentIn: 0, sets: new Set() };
|
|
228
|
+
merged.set(f.id, m);
|
|
229
|
+
order.push(m);
|
|
230
|
+
}
|
|
231
|
+
f.types.forEach((t) => m.types.add(t));
|
|
232
|
+
if (m.sample === undefined || (NULLISH.has(m.sampleType) && f.sampleType && !NULLISH.has(f.sampleType))) {
|
|
233
|
+
m.sample = f.sample;
|
|
234
|
+
m.sampleType = f.sampleType ?? f.types.find((t) => !NULLISH.has(t)) ?? f.types[0];
|
|
235
|
+
}
|
|
236
|
+
m.container ||= f.container;
|
|
237
|
+
m.sets.add(set);
|
|
238
|
+
// Missing from some of the parent's instances inside one sample, or (below) from a sample whose parent is there.
|
|
239
|
+
if (f.seen < f.parentInstances) m.partial = true;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
// Present in a set whose parent is present but the field is not.
|
|
243
|
+
for (const m of order) {
|
|
244
|
+
const parentSets = m.parentId === "" ? new Set(list.filter((s) => s.root.types.some((t) => t === "object" || t === "array"))) : merged.get(m.parentId)?.sets;
|
|
245
|
+
m.absentFrom = parentSets ? [...parentSets].filter((s) => !m.sets.has(s)).length : 0;
|
|
246
|
+
}
|
|
247
|
+
const nullable = (m) => [...m.types].some((t) => NULLISH.has(t));
|
|
248
|
+
const fields = order.map((m) => ({
|
|
249
|
+
id: m.id,
|
|
250
|
+
parentId: m.parentId,
|
|
251
|
+
label: m.label,
|
|
252
|
+
steps: m.steps,
|
|
253
|
+
depth: m.depth,
|
|
254
|
+
types: [...m.types].sort(),
|
|
255
|
+
sample: m.sample ?? "",
|
|
256
|
+
container: m.container,
|
|
257
|
+
optional: Boolean(m.partial) || m.absentFrom > 0 || nullable(m),
|
|
258
|
+
samples: m.sets.size,
|
|
259
|
+
}));
|
|
260
|
+
const byId = new Map(fields.map((f) => [f.id, f]));
|
|
261
|
+
for (const f of fields) {
|
|
262
|
+
let safe = false;
|
|
263
|
+
for (let p = byId.get(f.parentId); p && !safe; p = byId.get(p.parentId)) safe = p.optional;
|
|
264
|
+
f.safe = safe || [...rootTypes].some((t) => NULLISH.has(t));
|
|
265
|
+
}
|
|
266
|
+
return { root: { types: [...rootTypes].sort(), sample: rootSample ?? "" }, fields, truncated, samples: list.length };
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/** The fields of a JSON-like value (a pin, a pasted sample). */
|
|
270
|
+
export const fieldsOfValue = (value) => mergeFieldSets([finishRaw(collect(value, valueAdapter))]);
|
|
271
|
+
|
|
272
|
+
/** The fields of a value's preview tree (@johnhenry/inspectable serialize format): what a pane's value showed, with no run. */
|
|
273
|
+
export const fieldsOfPreview = (preview) => mergeFieldSets([finishRaw(collect(preview, previewAdapter))]);
|
|
274
|
+
|
|
275
|
+
/** A field by id. */
|
|
276
|
+
export const fieldById = (set, id) => set?.fields?.find((f) => f.id === id);
|
|
277
|
+
|
|
278
|
+
/** The JavaScript that reads `field` from input `root`: `users[0].name`, `config?.["max-size"]`. */
|
|
279
|
+
export const fieldExpression = (root, field, { safe = field?.safe } = {}) => pathExpression(root, field?.steps ?? [], { safe });
|
|
280
|
+
|
|
281
|
+
/** A field part's `field`: which input, which steps, and whether the accessor needs `?.`. */
|
|
282
|
+
export const fieldRef = (input, field, { safe = field.safe } = {}) => ({ input, steps: field.steps, id: field.id, ...(safe ? { safe: true } : {}) });
|
|
283
|
+
|
|
284
|
+
// ── reading a path from a value ──────────────────────────────────────────────
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Read `steps` from a JSON value. `{ found, value }`, or `{ found: false, at }`
|
|
288
|
+
* with `at` the number of steps that worked (the gap is the next one). A key
|
|
289
|
+
* that is there with the value undefined or null is found.
|
|
290
|
+
*/
|
|
291
|
+
export function readPath(value, steps) {
|
|
292
|
+
let at = 0;
|
|
293
|
+
let v = value;
|
|
294
|
+
for (const step of steps) {
|
|
295
|
+
let next;
|
|
296
|
+
if (v === null || v === undefined || typeof v !== "object") return { found: false, at };
|
|
297
|
+
if ("index" in step || "setIndex" in step) {
|
|
298
|
+
const i = "index" in step ? step.index : step.setIndex;
|
|
299
|
+
if (!Array.isArray(v) || i >= v.length) return { found: false, at };
|
|
300
|
+
next = v[i];
|
|
301
|
+
} else {
|
|
302
|
+
const key = "mapKey" in step ? String(step.mapKey) : step.key;
|
|
303
|
+
if (!Object.hasOwn(v, key)) return { found: false, at };
|
|
304
|
+
next = v[key];
|
|
305
|
+
}
|
|
306
|
+
v = next;
|
|
307
|
+
at++;
|
|
308
|
+
}
|
|
309
|
+
return { found: true, value: v };
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** A path's source text up to `count` steps, for messages (`user.address`). */
|
|
313
|
+
const pathText = (input, steps, count = steps.length) => pathExpression(input, steps.slice(0, count)) ?? input;
|
|
314
|
+
|
|
315
|
+
// ── parsing paths and literals typed as text ─────────────────────────────────
|
|
316
|
+
|
|
317
|
+
/** `a.b[0]["c d"]?.e` → `{ root: "a", steps }`, or null when the text isn't only a path. Used for fallbacks and completion. */
|
|
318
|
+
export function parsePath(text) {
|
|
319
|
+
const s = String(text ?? "").trim();
|
|
320
|
+
const head = /^[A-Za-z_$][A-Za-z0-9_$]*/.exec(s);
|
|
321
|
+
if (!head) return null;
|
|
322
|
+
const steps = [];
|
|
323
|
+
let i = head[0].length;
|
|
324
|
+
while (i < s.length) {
|
|
325
|
+
const rest = s.slice(i);
|
|
326
|
+
let m;
|
|
327
|
+
if ((m = /^\??\.([A-Za-z_$][A-Za-z0-9_$]*)/.exec(rest))) steps.push({ key: m[1] });
|
|
328
|
+
else if ((m = /^\??\.?\[(\d+)\]/.exec(rest))) steps.push({ index: Number(m[1]) });
|
|
329
|
+
else if ((m = /^\??\.?\[("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*')\]/.exec(rest))) steps.push({ key: m[1][0] === '"' ? JSON.parse(m[1]) : m[1].slice(1, -1).replace(/\\(.)/g, "$1") });
|
|
330
|
+
else return null;
|
|
331
|
+
i += m[0].length;
|
|
332
|
+
}
|
|
333
|
+
return { root: head[0], steps };
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** A literal typed as text → `{ value }`, or null. Numbers, true/false/null/undefined, quoted strings, `[]` and `{}`. */
|
|
337
|
+
export function parseLiteral(text) {
|
|
338
|
+
const s = String(text ?? "").trim();
|
|
339
|
+
if (!s) return null;
|
|
340
|
+
if (/^-?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/.test(s)) return { value: Number(s) };
|
|
341
|
+
if (s === "true") return { value: true };
|
|
342
|
+
if (s === "false") return { value: false };
|
|
343
|
+
if (s === "null") return { value: null };
|
|
344
|
+
if (s === "undefined") return { value: undefined };
|
|
345
|
+
if (s === "[]") return { value: [] };
|
|
346
|
+
if (s === "{}") return { value: {} };
|
|
347
|
+
if (s.length >= 2 && s[0] === s.at(-1)) {
|
|
348
|
+
const inner = s.slice(1, -1);
|
|
349
|
+
if (s[0] === '"') {
|
|
350
|
+
try {
|
|
351
|
+
const v = JSON.parse(s);
|
|
352
|
+
if (typeof v === "string") return { value: v };
|
|
353
|
+
} catch {
|
|
354
|
+
return null;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
if (s[0] === "'" && !/['\\]/.test(inner)) return { value: inner };
|
|
358
|
+
if (s[0] === "`" && !/[`\\]|\$\{/.test(inner)) return { value: inner };
|
|
359
|
+
}
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/** Why a fallback expression can't be put in a mapping (unbalanced brackets or quotes, `;`, a comment), or "". */
|
|
364
|
+
export function fallbackProblem(src) {
|
|
365
|
+
const s = String(src ?? "");
|
|
366
|
+
if (!s.trim()) return "";
|
|
367
|
+
const stack = [];
|
|
368
|
+
const pairs = { ")": "(", "]": "[", "}": "{" };
|
|
369
|
+
for (let i = 0; i < s.length; i++) {
|
|
370
|
+
const c = s[i];
|
|
371
|
+
if (c === '"' || c === "'" || c === "`") {
|
|
372
|
+
let j = i + 1;
|
|
373
|
+
while (j < s.length && s[j] !== c) j += s[j] === "\\" ? 2 : 1;
|
|
374
|
+
if (j >= s.length) return `a ${c} quote isn't closed`;
|
|
375
|
+
i = j;
|
|
376
|
+
} else if ("([{".includes(c)) stack.push(c);
|
|
377
|
+
else if (c in pairs) {
|
|
378
|
+
if (stack.pop() !== pairs[c]) return `a ${c} has no matching opener`;
|
|
379
|
+
} else if (c === ";") return "a fallback is one expression: no ;";
|
|
380
|
+
else if (c === "/" && (s[i + 1] === "/" || s[i + 1] === "*")) return "a fallback can't hold a comment";
|
|
381
|
+
else if (c === "\n") return "a fallback is one line";
|
|
382
|
+
}
|
|
383
|
+
return stack.length ? `a ${stack.at(-1)} isn't closed` : "";
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
const isSimple = (src) => parseLiteral(src) !== null || parsePath(src) !== null;
|
|
387
|
+
|
|
388
|
+
// ── mappings ─────────────────────────────────────────────────────────────────
|
|
389
|
+
|
|
390
|
+
const escapeTemplate = (text) => text.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$\{/g, "\\${");
|
|
391
|
+
|
|
392
|
+
const isField = (part) => Boolean(part && typeof part === "object" && part.field);
|
|
393
|
+
|
|
394
|
+
/** The inputs a mapping reads, once each, in order. */
|
|
395
|
+
export const mappingInputs = (mapping) => [...new Set((mapping?.parts ?? []).filter(isField).map((p) => p.field.input))];
|
|
396
|
+
|
|
397
|
+
/** Every field part of a mapping as `{ index, input, id, steps, path }` (a -style review walks these). */
|
|
398
|
+
export const mappingRefs = (mapping) => (mapping?.parts ?? []).flatMap((part, index) => (isField(part) ? [{ index, input: part.field.input, id: part.field.id, steps: part.field.steps, path: pathText(part.field.input, part.field.steps), fallback: part.fallback, expect: part.expect }] : []));
|
|
399
|
+
|
|
400
|
+
/** A mapping with input `from` called `to` (a renamed source or wire follows). */
|
|
401
|
+
export const renameMappingInput = (mapping, from, to) => ({ ...mapping, parts: (mapping.parts ?? []).map((p) => (isField(p) && p.field.input === from ? { ...p, field: { ...p.field, input: to } } : p)) });
|
|
402
|
+
|
|
403
|
+
/** What is wrong with a mapping's shape, as `{ part, message }` (an empty list when it can be compiled). */
|
|
404
|
+
export function mappingProblems(mapping) {
|
|
405
|
+
const out = [];
|
|
406
|
+
const parts = mapping?.parts;
|
|
407
|
+
if (!Array.isArray(parts) || !parts.length) return [{ part: -1, message: "A mapping needs at least one part: text or a field." }];
|
|
408
|
+
parts.forEach((p, part) => {
|
|
409
|
+
if (isField(p)) {
|
|
410
|
+
const { input, steps } = p.field;
|
|
411
|
+
if (typeof input !== "string" || !IDENTIFIER.test(input) || checkInputName(input)) out.push({ part, message: `"${input}" isn't a name a pane can read an input by.` });
|
|
412
|
+
if (!Array.isArray(steps) || steps.some((s) => !s)) out.push({ part, message: "That field has no JavaScript accessor (a symbol key, or an object as a Map key)." });
|
|
413
|
+
if (p.fallback !== undefined && p.fallback !== "") {
|
|
414
|
+
const why = typeof p.fallback === "string" ? fallbackProblem(p.fallback) : "a fallback is JavaScript text";
|
|
415
|
+
if (why) out.push({ part, message: `Fallback of ${pathText(input ?? "?", steps ?? [])}: ${why}.` });
|
|
416
|
+
}
|
|
417
|
+
} else if (typeof p?.text !== "string") out.push({ part, message: "A part is { text } or { field }." });
|
|
418
|
+
});
|
|
419
|
+
return out;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function partExpression(part) {
|
|
423
|
+
const base = pathExpression(part.field.input, part.field.steps, { safe: Boolean(part.field.safe) });
|
|
424
|
+
const fb = typeof part.fallback === "string" ? part.fallback.trim() : "";
|
|
425
|
+
return fb ? `${base} ?? ${isSimple(fb) ? fb : `(${fb})`}` : base;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* The JavaScript for a mapping: `{ code, inputs, kind, problems }`. `kind`:
|
|
430
|
+
* "field" (one field and nothing else: the bare expression, so its type is
|
|
431
|
+
* kept), "text" (static text only: a string literal) or "template" (a template
|
|
432
|
+
* literal; static text is escaped so it can't close the template or start a
|
|
433
|
+
* `${`). `code` is "" when there are problems.
|
|
434
|
+
*/
|
|
435
|
+
export function compileMapping(mapping) {
|
|
436
|
+
const problems = mappingProblems(mapping);
|
|
437
|
+
const inputs = mappingInputs(mapping);
|
|
438
|
+
if (problems.length) return { code: "", inputs, kind: "template", problems };
|
|
439
|
+
const parts = mapping.parts.filter((p) => isField(p) || p.text !== "");
|
|
440
|
+
if (!parts.length) return { code: '""', inputs, kind: "text", problems };
|
|
441
|
+
if (parts.length === 1 && isField(parts[0])) {
|
|
442
|
+
const e = partExpression(parts[0]);
|
|
443
|
+
return { code: e, inputs, kind: "field", problems };
|
|
444
|
+
}
|
|
445
|
+
if (!parts.some(isField)) return { code: JSON.stringify(parts.map((p) => p.text).join("")), inputs, kind: "text", problems };
|
|
446
|
+
const body = parts.map((p) => (isField(p) ? `\${${partExpression(p)}}` : escapeTemplate(p.text))).join("");
|
|
447
|
+
return { code: `\`${body}\``, inputs, kind: "template", problems };
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// ── previewing a mapping on fixtures ─────────────────────────────────────────
|
|
451
|
+
|
|
452
|
+
/** The text a value shows as inside a template literal, or as a result. */
|
|
453
|
+
function showValue(v) {
|
|
454
|
+
if (v === undefined) return "undefined";
|
|
455
|
+
return typeof v === "string" ? v : typeof v === "object" ? JSON.stringify(v) : String(v);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
function fallbackValue(src, scope, evaluate) {
|
|
459
|
+
const literal = parseLiteral(src);
|
|
460
|
+
if (literal) return { ok: true, value: literal.value };
|
|
461
|
+
const path = parsePath(src);
|
|
462
|
+
if (path) {
|
|
463
|
+
if (!Object.hasOwn(scope, path.root)) return { ok: false, why: `${path.root} has no value in this fixture` };
|
|
464
|
+
const r = readPath(scope[path.root], path.steps);
|
|
465
|
+
return r.found ? { ok: true, value: r.value } : { ok: false, why: `${pathText(path.root, path.steps)} is missing too` };
|
|
466
|
+
}
|
|
467
|
+
if (!evaluate) return { ok: false, unchecked: true };
|
|
468
|
+
try {
|
|
469
|
+
return { ok: true, value: evaluate(src, scope) };
|
|
470
|
+
} catch (error) {
|
|
471
|
+
return { ok: false, why: error?.message ?? String(error) };
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
function previewOne(mapping, fixture, evaluate) {
|
|
476
|
+
const label = fixture.label ?? "fixture";
|
|
477
|
+
const scope = fixture.inputs ?? {};
|
|
478
|
+
const problems = [];
|
|
479
|
+
const types = new Map(); // part index -> type found here
|
|
480
|
+
const note = (severity, kind, ref, message) => problems.push({ severity, kind, fixture: label, input: ref?.input, path: ref?.path, message: `${ref?.path ? `${ref.path}: ` : ""}${message} (fixture "${label}")` });
|
|
481
|
+
const pieces = [];
|
|
482
|
+
const parts = mapping.parts.filter((p) => isField(p) || p.text !== "");
|
|
483
|
+
const lone = parts.length === 1 && isField(parts[0]);
|
|
484
|
+
parts.forEach((part, index) => {
|
|
485
|
+
if (!isField(part)) return void pieces.push(part.text);
|
|
486
|
+
const { input, steps } = part.field;
|
|
487
|
+
const ref = { input, path: pathText(input, steps) };
|
|
488
|
+
let value;
|
|
489
|
+
let gap = null; // why there is no usable value
|
|
490
|
+
if (!Object.hasOwn(scope, input)) gap = { kind: "missing", message: `input "${input}" has no value here` };
|
|
491
|
+
else {
|
|
492
|
+
const r = readPath(scope[input], steps);
|
|
493
|
+
if (!r.found) gap = { kind: "missing", message: r.at === 0 ? `missing: ${input} is ${showValue(scope[input])}, no ${pathText(input, steps, 1).slice(input.length) || "field"} in it` : `missing: stopped at ${pathText(input, steps, r.at)} (${showValue(readPath(scope[input], steps.slice(0, r.at)).value)})` };
|
|
494
|
+
else if (r.value === null || r.value === undefined) gap = { kind: "null", message: `is ${r.value === null ? "null" : "undefined"}`, value: r.value };
|
|
495
|
+
else value = r.value;
|
|
496
|
+
}
|
|
497
|
+
if (gap) {
|
|
498
|
+
const fb = typeof part.fallback === "string" ? part.fallback.trim() : "";
|
|
499
|
+
const used = fb ? fallbackValue(fb, scope, evaluate) : null;
|
|
500
|
+
if (used?.ok) {
|
|
501
|
+
value = used.value;
|
|
502
|
+
note("info", "fallback", ref, `${gap.message}; used the fallback ${fb}`);
|
|
503
|
+
} else if (used?.unchecked) {
|
|
504
|
+
value = undefined;
|
|
505
|
+
note("info", "unchecked", ref, `${gap.message}; the fallback ${fb} runs in the worker and isn't previewed`);
|
|
506
|
+
} else {
|
|
507
|
+
value = gap.value;
|
|
508
|
+
note(gap.kind === "null" ? "warn" : "error", gap.kind, ref, used?.why ? `${gap.message}, and the fallback ${fb} failed: ${used.why}` : gap.message);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
const type = typeOfValue(value);
|
|
512
|
+
types.set(index, type);
|
|
513
|
+
const want = part.expect ?? (lone ? mapping.expect : undefined);
|
|
514
|
+
if (want && value !== undefined && type !== want && !(want === "any")) note("error", "type", ref, `expected ${want}, found ${type} ${clip(showValue(value), 40)}`);
|
|
515
|
+
if (!lone && (type === "object" || type === "array") && value !== null) note("warn", "type", ref, `${type === "array" ? "an array" : "an object"} in text becomes ${type === "array" ? "a comma-joined list" : "[object Object]"}`);
|
|
516
|
+
pieces.push(value);
|
|
517
|
+
});
|
|
518
|
+
const value = lone ? pieces[0] : pieces.map((p) => (typeof p === "string" ? p : p === undefined ? "undefined" : p === null ? "null" : typeof p === "object" ? (Array.isArray(p) ? p.join(",") : "[object Object]") : String(p))).join("");
|
|
519
|
+
return { fixture: label, id: fixture.id, value, text: clip(lone ? (value === undefined ? "undefined" : JSON.stringify(value) ?? String(value)) : value, 200), type: typeOfValue(value), problems, ok: !problems.some((p) => p.severity === "error"), types };
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* Evaluate a mapping on every fixture: `{ results, ok, problems, varies }`.
|
|
524
|
+
* Each result: `{ fixture, value, text, type, problems, ok }`; `problems` (all
|
|
525
|
+
* of them): `{ severity: "error" | "warn" | "info", kind: "missing" | "null"
|
|
526
|
+
* | "type" | "fallback" | "unchecked", fixture, input, path, message }`. A
|
|
527
|
+
* field whose type differs between fixtures is in `varies` (`{ path, types }`)
|
|
528
|
+
* and a `type` warning on the fixtures that differ from the first.
|
|
529
|
+
* @param {object} mapping
|
|
530
|
+
* @param {{ label: string, id?: string, inputs: Record<string, unknown> }[]} fixtures
|
|
531
|
+
* @param {{ evaluate?: (source: string, scope: object) => unknown }} [options] runs a fallback that is neither a literal nor a path
|
|
532
|
+
*/
|
|
533
|
+
export function previewMapping(mapping, fixtures, { evaluate } = {}) {
|
|
534
|
+
const shape = mappingProblems(mapping);
|
|
535
|
+
if (shape.length) return { results: [], ok: false, problems: shape.map((p) => ({ severity: "error", kind: "shape", fixture: "", message: p.message })), varies: [] };
|
|
536
|
+
const results = fixtures.map((f) => previewOne(mapping, f, evaluate));
|
|
537
|
+
const varies = [];
|
|
538
|
+
mappingRefs(mapping).forEach((ref) => {
|
|
539
|
+
const found = results.map((r) => [r.fixture, r.types.get(ref.index)]).filter(([, t]) => t && !NULLISH.has(t));
|
|
540
|
+
const kinds = [...new Set(found.map(([, t]) => t))];
|
|
541
|
+
if (kinds.length < 2) return;
|
|
542
|
+
varies.push({ path: ref.path, types: kinds });
|
|
543
|
+
const [firstFixture, firstType] = found[0];
|
|
544
|
+
for (const [fixture, type] of found.slice(1)) {
|
|
545
|
+
if (type === firstType) continue;
|
|
546
|
+
const result = results.find((r) => r.fixture === fixture);
|
|
547
|
+
result.problems.push({ severity: "warn", kind: "type", fixture, input: ref.input, path: ref.path, message: `${ref.path}: ${type} here, ${firstType} in "${firstFixture}" (fixture "${fixture}")` });
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
for (const r of results) delete r.types;
|
|
551
|
+
const problems = results.flatMap((r) => r.problems);
|
|
552
|
+
return { results, ok: results.every((r) => r.ok), problems, varies };
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* previewMapping with an `evaluate` that is asynchronous (the fallbacks that are neither a
|
|
557
|
+
* literal nor a path run in a Worker, with the variables and secrets withheld; see fallback-eval.js).
|
|
558
|
+
* Every such fallback is evaluated once per fixture first, then the preview is read as usual, so
|
|
559
|
+
* the result has the same shape. A fallback that throws or times out is reported like a sync one.
|
|
560
|
+
* `signal` stops the evaluations (the preview rejects with the signal's reason).
|
|
561
|
+
* @param {{ evaluate?: (source: string, scope: object) => unknown, signal?: AbortSignal }} [options]
|
|
562
|
+
*/
|
|
563
|
+
export async function previewMappingAsync(mapping, fixtures, { evaluate, signal } = {}) {
|
|
564
|
+
if (!evaluate) return previewMapping(mapping, fixtures);
|
|
565
|
+
const fx = fixtures.map((f) => ({ ...f, inputs: f.inputs ?? {} }));
|
|
566
|
+
const wanted = new Map(); // scope -> Map(source -> { value } | { error })
|
|
567
|
+
previewMapping(mapping, fx, {
|
|
568
|
+
evaluate: (src, scope) => {
|
|
569
|
+
if (!wanted.has(scope)) wanted.set(scope, new Map());
|
|
570
|
+
wanted.get(scope).set(src, undefined);
|
|
571
|
+
},
|
|
572
|
+
});
|
|
573
|
+
for (const [scope, sources] of wanted) {
|
|
574
|
+
for (const src of sources.keys()) {
|
|
575
|
+
signal?.throwIfAborted?.();
|
|
576
|
+
try {
|
|
577
|
+
sources.set(src, { value: await evaluate(src, scope) });
|
|
578
|
+
} catch (error) {
|
|
579
|
+
signal?.throwIfAborted?.();
|
|
580
|
+
sources.set(src, { error });
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
return previewMapping(mapping, fx, {
|
|
585
|
+
evaluate: (src, scope) => {
|
|
586
|
+
const r = wanted.get(scope)?.get(src);
|
|
587
|
+
if (!r) throw new Error("not evaluated");
|
|
588
|
+
if ("error" in r) throw r.error;
|
|
589
|
+
return r.value;
|
|
590
|
+
},
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
// ── fixtures ─────────────────────────────────────────────────────────────────
|
|
595
|
+
|
|
596
|
+
/** A fixture's fields-ready value from a preview tree: the JSON a "copy value" would give, and whether it was cut short. */
|
|
597
|
+
export const valueOfPreview = (preview) => previewToJSON(preview);
|
|
598
|
+
|
|
599
|
+
// ── completion ───────────────────────────────────────────────────────────────
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Field names to offer after `before` (the code before the caret) when it ends
|
|
603
|
+
* in `input.partial` or `input[0].partial`, from `sets` (`{ [input]: fieldSet }`).
|
|
604
|
+
* `{ start, items: [{ name, kind: "field", detail }] }` with `start` the offset
|
|
605
|
+
* in `before` where the partial word begins; null when `before` isn't such a path.
|
|
606
|
+
* Only names a `.name` accessor can reach are offered.
|
|
607
|
+
*/
|
|
608
|
+
export function fieldCompletions(sets, before) {
|
|
609
|
+
const m = /(?<![\w$.])([A-Za-z_$][\w$]*(?:\??\.[A-Za-z_$][\w$]*|\?\.\[\d+\]|\[\d+\])*)\??\.([A-Za-z_$][\w$]*)?$/.exec(String(before ?? ""));
|
|
610
|
+
if (!m) return null;
|
|
611
|
+
const path = parsePath(m[1]);
|
|
612
|
+
const set = path && sets?.[path.root];
|
|
613
|
+
if (!set) return null;
|
|
614
|
+
const partial = m[2] ?? "";
|
|
615
|
+
let parent = "";
|
|
616
|
+
for (const step of path.steps) {
|
|
617
|
+
parent = childId(parent, step, "index" in step ? "[]" : step.key);
|
|
618
|
+
}
|
|
619
|
+
const items = set.fields
|
|
620
|
+
.filter((f) => f.parentId === parent && f.label !== "[]" && IDENTIFIER.test(f.label) && f.label.startsWith(partial) && f.label !== partial)
|
|
621
|
+
.map((f) => ({ name: f.label, kind: "field", detail: `${f.types.join(" | ")}${f.optional ? " (optional)" : ""} · ${f.sample}` }));
|
|
622
|
+
return items.length ? { start: before.length - partial.length, items } : null;
|
|
623
|
+
}
|