@homepages/concrete 12.0.0 → 13.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +192 -0
- package/README.md +8 -10
- package/codemods/fixtures-are-data.mjs +7 -0
- package/codemods/fixtures-list-properties.mjs +6 -0
- package/codemods/manifest.json +15 -0
- package/codemods/steps/fixtures-list-properties.mjs +16 -0
- package/codemods/steps/fixtures-to-data.mjs +41 -0
- package/dist/artifact/playground/client/assets/archivo-latin-ext-wght-normal-C4zznr8T.woff2 +0 -0
- package/dist/artifact/playground/client/assets/archivo-latin-wght-normal-E0tuGl4L.woff2 +0 -0
- package/dist/artifact/playground/client/assets/archivo-vietnamese-wght-normal-XAtsl5Q_.woff2 +0 -0
- package/dist/artifact/playground/client/assets/index-Bmvcss4B.js +1338 -0
- package/dist/artifact/playground/client/assets/index-C01UCAWD.css +1 -0
- package/dist/artifact/playground/client/index.html +2 -2
- package/dist/artifact/playground/client/island-canvas-host.mjs +1 -1
- package/dist/artifact/playground/host.mjs +110 -59
- package/dist/base.css +2 -2
- package/dist/cli/build/icons.js +1 -1
- package/dist/cli/build/index.js +11 -10
- package/dist/cli/build/manifest.js +44 -0
- package/dist/cli/build/record.js +123 -0
- package/dist/cli/build/sections.js +28 -18
- package/dist/cli/build/source.js +1 -1
- package/dist/cli/build/static.js +8 -5
- package/dist/cli/build/template-build.js +614 -0
- package/dist/cli/check/analyze.js +18 -1
- package/dist/cli/check/load-workspace.js +2 -2
- package/dist/cli/check/portable-names.js +1 -1
- package/dist/cli/check/render/corpus.js +119 -0
- package/dist/cli/check/render/invariants.js +1 -0
- package/dist/cli/check/stages/bundles.js +15 -18
- package/dist/cli/check/stages/composition.js +8 -25
- package/dist/cli/check/stages/fixtures.js +14 -10
- package/dist/cli/check/stages/logic.js +7 -23
- package/dist/cli/check/stages/render.js +12 -14
- package/dist/cli/check/stages/sections.js +22 -66
- package/dist/cli/check/stages/stylesheet.js +4 -26
- package/dist/cli/check/stages/workspace.js +27 -22
- package/dist/cli/commands.js +51 -23
- package/dist/cli/currency/preamble.js +1 -1
- package/dist/cli/currency/resolve-latest.js +3 -2
- package/dist/cli/dev/capture-browser.js +26 -0
- package/dist/cli/dev/fixture-schema.js +441 -0
- package/dist/cli/dev/folder-files.js +244 -0
- package/dist/cli/dev/index.js +7 -3
- package/dist/cli/dev/playground-server.js +34 -0
- package/dist/cli/dev/section-ladders.js +76 -0
- package/dist/cli/dev/server.js +120 -304
- package/dist/cli/install/background.js +16 -0
- package/dist/cli/install/index.js +45 -0
- package/dist/cli/install/tools.js +27 -0
- package/dist/cli/media/derive.js +19 -13
- package/dist/cli/media/deriver-plugin.js +14 -3
- package/dist/cli/property/fixture-list.js +46 -0
- package/dist/cli/property/index.js +12 -9
- package/dist/cli/property/library.js +12 -10
- package/dist/cli/publish/artifact.js +90 -0
- package/dist/cli/publish/captures.js +61 -0
- package/dist/cli/publish/fixtures.js +17 -0
- package/dist/cli/publish/index.js +10 -18
- package/dist/cli/{build → publish}/playground.js +3 -3
- package/dist/cli/publish/report.js +15 -33
- package/dist/cli/upgrade/codemod.d.ts +14 -0
- package/dist/cli/upgrade/fixture-conversion.d.ts +11 -0
- package/dist/cli/upgrade/fixture-conversion.js +54 -0
- package/dist/cli/upgrade/fixture-modules.js +125 -0
- package/dist/cli/upgrade/fixtures-to-data.d.ts +40 -0
- package/dist/cli/upgrade/fixtures-to-data.js +498 -0
- package/dist/cli/upgrade/index.js +18 -2
- package/dist/cli/upgrade/legacy-fixtures.d.ts +34 -0
- package/dist/cli/upgrade/legacy-fixtures.js +22 -0
- package/dist/cli/upgrade/stage.js +1 -1
- package/dist/cli/workspace-fixtures.js +80 -0
- package/dist/cli.js +1 -0
- package/dist/css/compile.js +9 -3
- package/dist/fixtures/bundle-rule.js +16 -16
- package/dist/fixtures/media-plugin.js +12 -33
- package/dist/fixtures/synthesize-empties.js +3 -2
- package/dist/index.d.ts +7 -7
- package/dist/{playground-island-runtime.d.ts → island-runtime.d.ts} +1 -2
- package/dist/{playground-island-runtime.js → island-runtime.js} +1 -2
- package/dist/islands/client-module.js +1 -1
- package/dist/{cli/dev → islands}/tsconfig-paths.js +2 -14
- package/dist/islands/wrap.js +40 -0
- package/dist/node_modules/.pnpm/acorn@8.18.0/node_modules/acorn/dist/acorn.js +5119 -0
- package/dist/packages/external/concrete/package.js +1 -1
- package/dist/packages/internal/bundle-evaluation/dist/cache.js +36 -0
- package/dist/packages/internal/bundle-evaluation/dist/evaluate.js +174 -0
- package/dist/packages/internal/bundle-evaluation/dist/index.js +5 -0
- package/dist/packages/internal/bundle-evaluation/dist/section-code.js +10 -0
- package/dist/packages/internal/capture-settle/dist/index.js +2 -2
- package/dist/packages/internal/capture-settle/dist/settle.js +88 -13
- package/dist/packages/internal/code-fingerprint/dist/index.js +57 -0
- package/dist/packages/internal/content-doc-ops/dist/index.js +176 -0
- package/dist/packages/internal/content-doc-ops/dist/made-rows.js +15 -0
- package/dist/packages/internal/deliverable-reads/dist/bootstrap.js +81 -0
- package/dist/packages/internal/deliverable-reads/dist/display.js +21 -0
- package/dist/packages/internal/deliverable-reads/dist/format.js +15 -0
- package/dist/packages/internal/deliverable-reads/dist/index.js +7 -0
- package/dist/packages/internal/deliverable-reads/dist/pages.js +29 -0
- package/dist/packages/internal/deliverable-reads/dist/requirements.js +72 -0
- package/dist/{cli/capture → packages/internal/download-files/dist}/bundle.js +8 -4
- package/dist/packages/internal/download-files/dist/capture-origin.js +126 -0
- package/dist/packages/internal/download-files/dist/capture-routes.js +139 -0
- package/dist/packages/internal/download-files/dist/capture-shell.js +38 -0
- package/dist/packages/internal/download-files/dist/capture.js +74 -0
- package/dist/packages/internal/download-files/dist/egress-watch.js +38 -0
- package/dist/packages/internal/download-files/dist/files.js +7 -0
- package/dist/packages/internal/download-files/dist/finish.js +35 -0
- package/dist/packages/internal/download-files/dist/fleet.js +94 -0
- package/dist/packages/internal/download-files/dist/format.js +40 -0
- package/dist/packages/internal/download-files/dist/make.js +105 -0
- package/dist/packages/internal/download-files/dist/master-tally.js +32 -0
- package/dist/packages/internal/download-files/dist/names.js +24 -0
- package/dist/packages/internal/download-files/dist/pdf-boxes.js +33 -0
- package/dist/packages/internal/download-files/dist/pdf-image-placements.js +194 -0
- package/dist/packages/internal/download-files/dist/pdf-images.js +289 -0
- package/dist/packages/internal/file-store/dist/files.js +8 -0
- package/dist/packages/internal/file-store/dist/lru.js +40 -0
- package/dist/packages/internal/file-store/dist/refusal.js +12 -0
- package/dist/packages/internal/file-store/dist/trees.js +151 -0
- package/dist/packages/internal/fill-bake/dist/bake-property-ref.js +1 -1
- package/dist/packages/internal/fill-bake/dist/compute-reads.js +47 -21
- package/dist/packages/internal/fill-bake/dist/index.js +5 -1
- package/dist/packages/internal/fill-bake/dist/item-merge.js +4 -3
- package/dist/packages/internal/fill-bake/dist/resolve-instance.js +9 -0
- package/dist/packages/internal/fill-bake/dist/resolve.js +3 -0
- package/dist/packages/internal/fill-bake/dist/round-trip.js +2 -0
- package/dist/packages/internal/fill-bake/dist/strip.js +6 -0
- package/dist/packages/internal/fill-vocabulary/dist/holder.js +1 -1
- package/dist/packages/internal/fill-vocabulary/dist/resolved-decision.js +1 -1
- package/dist/packages/internal/fill-vocabulary/dist/verbs.js +1 -1
- package/dist/packages/internal/island-runtime/dist/index.js +1 -10
- package/dist/packages/internal/island-runtime/dist/use-capture-ready.d.ts +5 -0
- package/dist/packages/internal/lead-fields/dist/ingest.js +72 -0
- package/dist/packages/internal/media-resolution/dist/video.js +6 -2
- package/dist/packages/internal/page-render/dist/addresses.js +57 -0
- package/dist/packages/internal/page-render/dist/index.js +6 -0
- package/dist/packages/internal/page-render/dist/kept.js +30 -0
- package/dist/packages/internal/page-render/dist/nav.js +42 -0
- package/dist/packages/internal/page-render/dist/render.js +152 -0
- package/dist/packages/internal/page-shell/dist/assemble.js +161 -0
- package/dist/packages/internal/page-shell/dist/escape.js +10 -0
- package/dist/packages/internal/page-shell/dist/frame.js +23 -0
- package/dist/packages/internal/page-shell/dist/index.js +26 -0
- package/dist/packages/internal/playground/dist/build-fingerprint.js +18 -0
- package/dist/packages/internal/playground/dist/fixture-conversions/list-names-properties.js +76 -0
- package/dist/packages/internal/playground/dist/fixture-formats.d.ts +37 -0
- package/dist/packages/internal/playground/dist/fixture-formats.js +20 -0
- package/dist/packages/internal/playground/dist/host/bootstrap.js +108 -0
- package/dist/packages/internal/playground/dist/host/built.js +202 -0
- package/dist/packages/internal/playground/dist/host/catalog-fixture.js +53 -0
- package/dist/packages/internal/playground/dist/host/download.js +34 -0
- package/dist/packages/internal/playground/dist/host/env.js +11 -0
- package/dist/packages/internal/playground/dist/host/everywhere-saves.js +353 -0
- package/dist/packages/internal/playground/dist/host/fixture-addresses.js +52 -0
- package/dist/packages/internal/playground/dist/host/fixture-documents.js +494 -0
- package/dist/packages/internal/playground/dist/host/fixture-operations.js +364 -0
- package/dist/packages/internal/playground/dist/host/fixture-units.js +93 -0
- package/dist/{fixtures → packages/internal/playground/dist/host}/image-dimensions.js +1 -1
- package/dist/packages/internal/playground/dist/host/leads.js +41 -0
- package/dist/packages/internal/playground/dist/host/media-saves.js +309 -0
- package/dist/{fixtures → packages/internal/playground/dist/host}/media-store.js +79 -26
- package/dist/packages/internal/playground/dist/host/overridable.js +9 -0
- package/dist/packages/internal/playground/dist/host/owned-saves.js +203 -0
- package/dist/{playground → packages/internal/playground/dist}/host/page-state.js +1 -1
- package/dist/packages/internal/playground/dist/host/program.js +54 -0
- package/dist/packages/internal/playground/dist/host/property-derive.js +216 -0
- package/dist/packages/internal/playground/dist/host/property-saves.js +74 -0
- package/dist/{fixtures → packages/internal/playground/dist/host}/property.js +88 -229
- package/dist/packages/internal/playground/dist/host/provenance.js +49 -0
- package/dist/packages/internal/playground/dist/host/resolve.js +553 -0
- package/dist/packages/internal/playground/dist/host/row-images.js +41 -0
- package/dist/{fixtures → packages/internal/playground/dist/host}/rows.js +1 -1
- package/dist/packages/internal/playground/dist/host/save.js +429 -0
- package/dist/packages/internal/playground/dist/host/serve.js +952 -0
- package/dist/packages/internal/playground/dist/host/site.js +79 -0
- package/dist/packages/internal/playground/dist/host/slots.js +202 -0
- package/dist/packages/internal/playground/dist/host/stated-content.js +93 -0
- package/dist/packages/internal/playground/dist/host/stored-fixtures.js +135 -0
- package/dist/packages/internal/playground/dist/host/violations.js +7 -0
- package/dist/packages/internal/playground/dist/jobs/lanes.js +24 -0
- package/dist/packages/internal/playground/dist/jobs/memory-queue.js +112 -0
- package/dist/packages/internal/playground/dist/jobs/probe.js +37 -0
- package/dist/packages/internal/playground/dist/jobs/queue.js +28 -0
- package/dist/packages/internal/playground/dist/jobs/runner.js +207 -0
- package/dist/packages/internal/playground/dist/layout.js +14 -0
- package/dist/packages/internal/playground/dist/platform.js +33 -0
- package/dist/packages/internal/playground/dist/server/changes.js +57 -0
- package/dist/packages/internal/playground/dist/server/crop.js +47 -0
- package/dist/packages/internal/playground/dist/server/derived-files.js +88 -0
- package/dist/packages/internal/playground/dist/server/download.js +158 -0
- package/dist/{cli/dev → packages/internal/playground/dist/server}/http.js +4 -12
- package/dist/packages/internal/playground/dist/server/jobs.js +29 -0
- package/dist/{cli/dev → packages/internal/playground/dist/server}/listen.js +4 -11
- package/dist/packages/internal/playground/dist/server/playground-server.js +424 -0
- package/dist/{cli/dev → packages/internal/playground/dist/server}/request-error.js +1 -1
- package/dist/packages/internal/playground/dist/server/size-ladders.js +170 -0
- package/dist/packages/internal/playground/dist/server/verification.js +75 -0
- package/dist/packages/internal/playground/dist/server/verify-build.js +139 -0
- package/dist/packages/internal/playground/dist/wire.js +78 -0
- package/dist/packages/internal/property-facts/dist/registry-facts.js +1 -1
- package/dist/packages/internal/section-contracts/dist/fill-verb-contract.js +1 -1
- package/dist/packages/internal/section-contracts/dist/reads-acyclic-contract.js +1 -1
- package/dist/packages/internal/section-contracts/dist/row-fill-contract.js +1 -1
- package/dist/packages/internal/site-files/dist/head.js +59 -0
- package/dist/packages/internal/site-files/dist/index.js +4 -0
- package/dist/packages/internal/site-files/dist/site.js +211 -0
- package/dist/packages/internal/static-assets-binding/dist/index.js +32 -0
- package/dist/packages/internal/static-assets-binding/dist/section-asset-url.js +38 -5
- package/dist/packages/internal/template-artifact/dist/asset-mime.js +8 -1
- package/dist/packages/internal/template-artifact/dist/build.js +148 -0
- package/dist/packages/internal/template-artifact/dist/composition.js +62 -0
- package/dist/packages/internal/template-artifact/dist/index.js +2 -2
- package/dist/packages/internal/template-artifact/dist/layout.js +48 -12
- package/dist/packages/internal/template-artifact/dist/manifest.js +3 -10
- package/dist/packages/internal/template-artifact/dist/verify.js +51 -31
- package/dist/packages/internal/template-contracts/dist/address-value.js +6 -1
- package/dist/packages/internal/template-contracts/dist/content-categories.js +10 -1
- package/dist/packages/internal/template-contracts/dist/fact-compute.d.ts +1 -1
- package/dist/packages/internal/template-contracts/dist/fact-keys.d.ts +1 -1
- package/dist/packages/internal/template-contracts/dist/fact-registry.d.ts +3 -3
- package/dist/packages/internal/template-contracts/dist/fact-registry.js +59 -32
- package/dist/packages/internal/template-contracts/dist/fill-spec.js +14 -1
- package/dist/packages/internal/template-contracts/dist/list.d.ts +3 -3
- package/dist/packages/internal/template-contracts/dist/media-candidates.js +67 -2
- package/dist/packages/internal/template-contracts/dist/media-offer.js +180 -0
- package/dist/packages/internal/template-contracts/dist/object.d.ts +2 -2
- package/dist/packages/internal/template-contracts/dist/primitive-descriptors.js +9 -2
- package/dist/packages/internal/template-contracts/dist/read-graph.js +36 -2
- package/dist/packages/internal/template-contracts/dist/ref-locate.js +16 -1
- package/dist/packages/internal/template-contracts/dist/registry-facts.d.ts +9 -10
- package/dist/packages/internal/template-contracts/dist/registry-facts.js +12 -1
- package/dist/packages/internal/template-contracts/dist/registry-graph.js +112 -0
- package/dist/packages/internal/template-contracts/dist/registry-shape.js +15 -2
- package/dist/packages/internal/template-contracts/dist/require-graph.js +300 -0
- package/dist/packages/internal/template-contracts/dist/row-ref.d.ts +3 -3
- package/dist/packages/internal/template-contracts/dist/row.d.ts +3 -3
- package/dist/packages/internal/template-contracts/dist/runtime-values.d.ts +1 -1
- package/dist/{schema → packages/internal/template-contracts/dist}/section-nav.d.ts +1 -1
- package/dist/packages/internal/template-contracts/dist/slot-builders.d.ts +4 -4
- package/dist/packages/internal/template-contracts/dist/slot-catalog.d.ts +3 -1
- package/dist/packages/internal/template-contracts/dist/slot-catalog.js +24 -1
- package/dist/packages/internal/template-contracts/dist/slot-overrides.js +26 -1
- package/dist/packages/internal/template-contracts/dist/slot-ref.d.ts +1 -1
- package/dist/packages/internal/template-contracts/dist/slot-types.js +1 -1
- package/dist/packages/internal/template-contracts/dist/slot-value.d.ts +1 -1
- package/dist/packages/internal/template-contracts/dist/table-members.js +7 -2
- package/dist/packages/internal/template-contracts/dist/video-value.d.ts +1 -1
- package/dist/packages/internal/upload-formats/dist/heic.js +35 -0
- package/dist/packages/internal/upload-formats/dist/index.js +80 -0
- package/dist/packages/internal/upload-formats/dist/magic-bytes.js +293 -0
- package/dist/platform/paths.js +1 -0
- package/dist/platform/process.js +49 -1
- package/dist/rules/registry.js +27 -3
- package/dist/schema/fact.d.ts +2 -2
- package/dist/schema/facts-view.d.ts +1 -1
- package/dist/schema/section-props.d.ts +1 -1
- package/dist/schema/section-schema.d.ts +1 -1
- package/dist/schema/section-schema.js +1 -0
- package/dist/section/declare.d.ts +1 -1
- package/dist/section/discovery.js +6 -2
- package/dist/section/publish-shape.js +38 -0
- package/dist/section/section.d.ts +1 -1
- package/dist/template/define-template.d.ts +14 -4
- package/dist/template/define-template.js +2 -0
- package/dist/template/logic-shim.d.ts +1 -1
- package/dist/template/materialize.js +1 -1
- package/dist/template/running-copy.js +0 -1
- package/dist/template/section-reads.js +1 -1
- package/guide/reference/cli/INDEX.md +6 -5
- package/guide/reference/cli/build.md +10 -8
- package/guide/reference/cli/check.md +4 -2
- package/guide/reference/cli/dev.md +6 -2
- package/guide/reference/cli/install.md +41 -0
- package/guide/reference/cli/property-add.md +5 -4
- package/guide/reference/cli/property-list.md +2 -2
- package/guide/reference/cli/publish.md +5 -5
- package/guide/reference/cli/upgrade.md +1 -1
- package/guide/reference/rules/INDEX.md +8 -4
- package/package.json +14 -30
- package/dist/artifact/playground/client/assets/index-BcLGpWLR.js +0 -1266
- package/dist/artifact/playground/client/assets/index-CxWPYOH2.css +0 -1
- package/dist/cli/build/artifact.js +0 -220
- package/dist/cli/build/captures.js +0 -48
- package/dist/cli/build/fixtures.js +0 -92
- package/dist/cli/capture/capture-browser.js +0 -37
- package/dist/cli/capture/capture.js +0 -115
- package/dist/cli/check/render/inputs.js +0 -60
- package/dist/cli/check/render/nav.js +0 -31
- package/dist/cli/dev/crop.js +0 -20
- package/dist/cli/dev/fixture-ladders.js +0 -96
- package/dist/cli/dev/hmr.js +0 -26
- package/dist/cli/dev/islands.js +0 -234
- package/dist/cli/dev/load-template.js +0 -52
- package/dist/cli/dev/vite.js +0 -114
- package/dist/cli/dev/workspace-reader.js +0 -249
- package/dist/cli/publish/freshness.js +0 -64
- package/dist/fixtures/brand.d.ts +0 -4
- package/dist/fixtures/brand.js +0 -8
- package/dist/fixtures/load.js +0 -159
- package/dist/fixtures/resolve.js +0 -392
- package/dist/fixtures.d.ts +0 -429
- package/dist/fixtures.js +0 -23
- package/dist/packages/internal/canvas-core/dist/island-host.js +0 -62
- package/dist/packages/internal/canvas-core/dist/island-shields.js +0 -30
- package/dist/playground/canvas-island-host.d.ts +0 -11
- package/dist/playground/canvas-island-host.js +0 -29
- package/dist/playground/canvas-markers.js +0 -14
- package/dist/playground/host/paths.js +0 -8
- package/dist/playground/layout.js +0 -17
- package/dist/playground/wire.js +0 -28
|
@@ -0,0 +1,952 @@
|
|
|
1
|
+
import { resolveFormatGeometry } from "../../../format-geometry/dist/geometry.js";
|
|
2
|
+
import { frameTokens } from "../../../format-geometry/dist/capture.js";
|
|
3
|
+
import { fileUrlOf, fixtureMediaAddressKey } from "./property-derive.js";
|
|
4
|
+
import { MAX_UPLOAD_BYTES } from "../../../upload-formats/dist/index.js";
|
|
5
|
+
import { keptInProcess } from "../../../page-render/dist/kept.js";
|
|
6
|
+
import { SETTLED_FILL_HOLDERS, assembleBootstrap } from "../../../deliverable-reads/dist/bootstrap.js";
|
|
7
|
+
import { answerRequirements, deliverableRequirements, requirementsResponseOf } from "../../../deliverable-reads/dist/requirements.js";
|
|
8
|
+
import "../../../deliverable-reads/dist/index.js";
|
|
9
|
+
import { renderPage, renderPageSection } from "../../../page-render/dist/render.js";
|
|
10
|
+
import "../../../page-render/dist/index.js";
|
|
11
|
+
import { sha256Hex } from "../../../template-artifact/dist/sha256.js";
|
|
12
|
+
import { HostRefusal } from "./env.js";
|
|
13
|
+
import { ownedLinkSave, ownedUploadSave, stagedUploadSave } from "./owned-saves.js";
|
|
14
|
+
import { rowImageUploadSave } from "./row-images.js";
|
|
15
|
+
import { fixtureMedia, fixtureOwnedMedia, laidValues, propertyContacts, propertyMediaItems, propertyMediaLists, settledComputed, slotProvenance } from "./slots.js";
|
|
16
|
+
import { parseSaveRequest, saveDocuments } from "./save.js";
|
|
17
|
+
import { linkSave, parseLibraryRequest, removeSave, uploadSave } from "./media-saves.js";
|
|
18
|
+
import { attachmentDisposition, correctedDownloadLocation, parseDownloadPath, propertyAddressOf, shippedDownloadPath } from "./download.js";
|
|
19
|
+
import { OUTPUT_FOLDERS, ROUTES, parseOutputPath } from "../wire.js";
|
|
20
|
+
import { fixtureOperation, parseFixtureOperation } from "./fixture-operations.js";
|
|
21
|
+
import { downloadFilename, downloadStem } from "../../../download-files/dist/names.js";
|
|
22
|
+
import { PROBE_OPERATION } from "../jobs/probe.js";
|
|
23
|
+
import { bootstrapComposition, bootstrapFormat, bootstrapSection, fixtureContentDoc, fixtureDeliverable, fixtureSubject, sectionVersions, templateSubject } from "./bootstrap.js";
|
|
24
|
+
import { enabledPages, pageEnabled } from "./page-state.js";
|
|
25
|
+
import { catalogFixture, catalogProperty, fixturesOn } from "./catalog-fixture.js";
|
|
26
|
+
import { answerLead } from "./leads.js";
|
|
27
|
+
import { playgroundSites, siteFileResponse } from "./site.js";
|
|
28
|
+
import { violationText } from "./violations.js";
|
|
29
|
+
|
|
30
|
+
//#region ../../internal/playground/dist/host/serve.js
|
|
31
|
+
const MAX_BODY_BYTES = 1024 * 1024;
|
|
32
|
+
const ASSETS = "assets";
|
|
33
|
+
const LISTED_ADDRESSES = 8192;
|
|
34
|
+
const sha256Text = (text) => sha256Hex(new TextEncoder().encode(text));
|
|
35
|
+
const MAX_SAVE_ATTEMPTS = 5;
|
|
36
|
+
function catalogFormat(format) {
|
|
37
|
+
const geometry = resolveFormatGeometry(format);
|
|
38
|
+
const physical = typeof format.width === "string" ? `${format.width} × ${String(format.height)}` : void 0;
|
|
39
|
+
return {
|
|
40
|
+
id: format.id,
|
|
41
|
+
label: format.label,
|
|
42
|
+
cssWidth: geometry.viewportWidth,
|
|
43
|
+
cssHeight: geometry.viewportHeight,
|
|
44
|
+
bleed: geometry.bleed,
|
|
45
|
+
pixelWidth: geometry.pixelWidth,
|
|
46
|
+
pixelHeight: geometry.pixelHeight,
|
|
47
|
+
...physical === void 0 ? {} : { physical },
|
|
48
|
+
tokens: { ...frameTokens(format) }
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function textResponse(status, body) {
|
|
52
|
+
return new Response(body, {
|
|
53
|
+
status,
|
|
54
|
+
headers: { "content-type": "text/plain; charset=utf-8" }
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function jsonResponse(body) {
|
|
58
|
+
return new Response(JSON.stringify(body), { headers: { "content-type": "application/json; charset=utf-8" } });
|
|
59
|
+
}
|
|
60
|
+
function acceptedResponse(body) {
|
|
61
|
+
return new Response(JSON.stringify(body), {
|
|
62
|
+
status: 202,
|
|
63
|
+
headers: { "content-type": "application/json; charset=utf-8" }
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function refusalStatus(err) {
|
|
67
|
+
if (typeof err !== "object" || err === null) return null;
|
|
68
|
+
const status = err.status;
|
|
69
|
+
return typeof status === "number" && Number.isInteger(status) && status >= 400 && status < 600 ? status : null;
|
|
70
|
+
}
|
|
71
|
+
function parseRenderRequest(text) {
|
|
72
|
+
let body;
|
|
73
|
+
try {
|
|
74
|
+
body = text === "" ? void 0 : JSON.parse(text);
|
|
75
|
+
} catch (err) {
|
|
76
|
+
throw new HostRefusal(400, `request body is not JSON: ${err instanceof Error ? err.message : String(err)}`);
|
|
77
|
+
}
|
|
78
|
+
const record = typeof body === "object" && body !== null && !Array.isArray(body) ? body : null;
|
|
79
|
+
const slots = record?.slots;
|
|
80
|
+
if (record === null || typeof record.fixture !== "string" || typeof record.section_key !== "string" || typeof slots !== "object" || slots === null || Array.isArray(slots)) throw new HostRefusal(400, "A render request names a fixture and a section, and carries the section's slots.");
|
|
81
|
+
for (const key of [
|
|
82
|
+
"instance_id",
|
|
83
|
+
"page_id",
|
|
84
|
+
"variant"
|
|
85
|
+
]) if (record[key] !== void 0 && typeof record[key] !== "string") throw new HostRefusal(400, `A render request's ${key} is a string.`);
|
|
86
|
+
return {
|
|
87
|
+
fixture: record.fixture,
|
|
88
|
+
section_key: record.section_key,
|
|
89
|
+
slots,
|
|
90
|
+
...typeof record.instance_id === "string" ? { instance_id: record.instance_id } : {},
|
|
91
|
+
...typeof record.page_id === "string" ? { page_id: record.page_id } : {},
|
|
92
|
+
...typeof record.variant === "string" ? { variant: record.variant } : {}
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
async function boundedText(request) {
|
|
96
|
+
const text = await request.text();
|
|
97
|
+
if (new TextEncoder().encode(text).byteLength > MAX_BODY_BYTES) throw new HostRefusal(413, `request body exceeds ${MAX_BODY_BYTES} bytes`);
|
|
98
|
+
return text;
|
|
99
|
+
}
|
|
100
|
+
function requiredParam(url, name, route) {
|
|
101
|
+
const value = url.searchParams.get(name);
|
|
102
|
+
if (value === null || value === "") throw new HostRefusal(400, `${route} needs a ${name} parameter.`);
|
|
103
|
+
return value;
|
|
104
|
+
}
|
|
105
|
+
function isHostRead(path) {
|
|
106
|
+
if (parseOutputPath(path) !== null) return true;
|
|
107
|
+
return path === ROUTES.catalog || path === ROUTES.problems || path === "api/media" || path === "api/owned" || path === "api/bootstrap" || path === "api/requirements" || path === "api/facts";
|
|
108
|
+
}
|
|
109
|
+
function requestOrigin(request, url) {
|
|
110
|
+
const host = request.headers.get("x-forwarded-host") ?? request.headers.get("host");
|
|
111
|
+
if (host === null) return url.origin;
|
|
112
|
+
return `${request.headers.get("x-forwarded-proto")?.split(",")[0]?.trim() ?? url.protocol.replace(/:$/, "")}://${host.split(",")[0].trim()}`;
|
|
113
|
+
}
|
|
114
|
+
function jobKey(job) {
|
|
115
|
+
return JSON.stringify([
|
|
116
|
+
job.operation,
|
|
117
|
+
job.subject.property ?? null,
|
|
118
|
+
job.subject.fixture ?? null,
|
|
119
|
+
job.subject.format ?? null,
|
|
120
|
+
job.subject.page ?? null,
|
|
121
|
+
job.subject.file ?? null
|
|
122
|
+
]);
|
|
123
|
+
}
|
|
124
|
+
function standingFailures(jobs) {
|
|
125
|
+
const decided = /* @__PURE__ */ new Set();
|
|
126
|
+
const problems = [];
|
|
127
|
+
const ended = jobs.filter((job) => job.finishedAt !== null).sort((a, b) => Date.parse(b.finishedAt) - Date.parse(a.finishedAt));
|
|
128
|
+
for (const job of ended) {
|
|
129
|
+
const key = jobKey(job);
|
|
130
|
+
if (decided.has(key)) continue;
|
|
131
|
+
decided.add(key);
|
|
132
|
+
if (job.state === "failed") problems.push({
|
|
133
|
+
kind: "job",
|
|
134
|
+
job: job.id,
|
|
135
|
+
operation: job.operation,
|
|
136
|
+
subject: job.subject,
|
|
137
|
+
message: job.error ?? "It failed."
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return problems;
|
|
141
|
+
}
|
|
142
|
+
function markedProperties(properties, jobs, markOf) {
|
|
143
|
+
const fixtures = /* @__PURE__ */ new Map();
|
|
144
|
+
const owners = /* @__PURE__ */ new Map();
|
|
145
|
+
for (const job of jobs) {
|
|
146
|
+
if (job.state !== "waiting" && job.state !== "running") continue;
|
|
147
|
+
const label = markOf(job.operation);
|
|
148
|
+
if (label === void 0) continue;
|
|
149
|
+
const { fixture, property } = job.subject;
|
|
150
|
+
if (fixture !== void 0) {
|
|
151
|
+
if (!fixtures.has(fixture)) fixtures.set(fixture, { label });
|
|
152
|
+
} else if (property !== void 0 && !owners.has(property)) owners.set(property, { label });
|
|
153
|
+
}
|
|
154
|
+
if (fixtures.size === 0 && owners.size === 0) return properties;
|
|
155
|
+
return properties.map((property) => {
|
|
156
|
+
const own = owners.get(property.name);
|
|
157
|
+
return {
|
|
158
|
+
...property,
|
|
159
|
+
...own === void 0 ? {} : { progress: own },
|
|
160
|
+
content: property.content.map((fixture) => {
|
|
161
|
+
const mark = fixtures.get(fixture.name);
|
|
162
|
+
return mark === void 0 ? fixture : {
|
|
163
|
+
...fixture,
|
|
164
|
+
progress: mark
|
|
165
|
+
};
|
|
166
|
+
})
|
|
167
|
+
};
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function waitParam(url) {
|
|
171
|
+
const value = url.searchParams.get("wait");
|
|
172
|
+
if (value === null || value === "") return void 0;
|
|
173
|
+
const seconds = Number(value);
|
|
174
|
+
if (!Number.isFinite(seconds) || seconds < 0) throw new HostRefusal(400, `A job's wait is a number of seconds, not "${value}".`);
|
|
175
|
+
return Math.min(seconds, 60) * 1e3;
|
|
176
|
+
}
|
|
177
|
+
function serveHost(mount, mountedAt = "/") {
|
|
178
|
+
const { reader, assetUrl, renderer, saves, stylesheets, fixtures, jobs, downloads } = mount;
|
|
179
|
+
const sites = playgroundSites(mount.site);
|
|
180
|
+
const base = mountedAt.endsWith("/") ? mountedAt : `${mountedAt}/`;
|
|
181
|
+
const kept = keptInProcess(sha256Text);
|
|
182
|
+
const addressHash = (text) => sha256Text(fixtureMediaAddressKey(text, mount.fixtureMediaPath));
|
|
183
|
+
const listed = /* @__PURE__ */ new Map();
|
|
184
|
+
const list = (address, file) => {
|
|
185
|
+
listed.delete(address);
|
|
186
|
+
listed.set(address, file);
|
|
187
|
+
if (listed.size > LISTED_ADDRESSES) listed.delete(listed.keys().next().value);
|
|
188
|
+
};
|
|
189
|
+
async function fixtureById(id) {
|
|
190
|
+
return fixtureIn(await fixtures(), id);
|
|
191
|
+
}
|
|
192
|
+
function fixtureIn(held, id) {
|
|
193
|
+
const listed = held.fixtures;
|
|
194
|
+
const fixture = listed.find((f) => f.id === id);
|
|
195
|
+
if (fixture === void 0) throw new HostRefusal(404, `There is no content fixture "${id}" (have: ${listed.map((f) => f.id).join(", ") || "none"}).`);
|
|
196
|
+
return fixture;
|
|
197
|
+
}
|
|
198
|
+
async function propertyByName(name) {
|
|
199
|
+
return propertyIn(await fixtures(), name);
|
|
200
|
+
}
|
|
201
|
+
function propertyIn(held, name) {
|
|
202
|
+
const property = held.properties.find((p) => p.name === name);
|
|
203
|
+
if (property === void 0) throw new HostRefusal(404, `There is no property "${name}" (have: ${held.properties.map((p) => p.name).join(", ") || "none"}).`);
|
|
204
|
+
return property;
|
|
205
|
+
}
|
|
206
|
+
function propertyOf(held, fixture) {
|
|
207
|
+
const property = held.properties.find((p) => p.file === fixture.property);
|
|
208
|
+
if (property === void 0) throw new Error(`The content fixture "${fixture.id}" is on "${fixture.property}", which did not load.`);
|
|
209
|
+
return property;
|
|
210
|
+
}
|
|
211
|
+
function propertyTarget(held, property) {
|
|
212
|
+
const media = { ...property.media };
|
|
213
|
+
for (const fixture of fixturesOn(held, property)) Object.assign(media, fixture.media);
|
|
214
|
+
return {
|
|
215
|
+
property: property.file,
|
|
216
|
+
media
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function subjectIn(held, subject) {
|
|
220
|
+
const fixture = subject.fixture === void 0 ? void 0 : fixtureIn(held, subject.fixture);
|
|
221
|
+
const property = subject.property === void 0 ? propertyOf(held, fixture) : propertyIn(held, subject.property);
|
|
222
|
+
if (fixture !== void 0 && fixture.property !== property.file) throw new HostRefusal(400, `The content fixture "${fixture.id}" is on the property "${propertyOf(held, fixture).name}", not "${property.name}".`);
|
|
223
|
+
return {
|
|
224
|
+
property,
|
|
225
|
+
target: propertyTarget(held, property),
|
|
226
|
+
fixture
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function instanceOf(fixture, instanceId) {
|
|
230
|
+
const instance = fixture.instances.find((i) => i.instance_id === instanceId);
|
|
231
|
+
if (instance === void 0) throw new HostRefusal(400, `The composition places no instance "${instanceId}".`);
|
|
232
|
+
return instance;
|
|
233
|
+
}
|
|
234
|
+
function snapshotOf(template, fixture, bases, named) {
|
|
235
|
+
return {
|
|
236
|
+
output: template.output,
|
|
237
|
+
pages: template.pages,
|
|
238
|
+
instances: fixture.instances.map((i) => ({
|
|
239
|
+
instanceId: i.instance_id,
|
|
240
|
+
values: i.slots,
|
|
241
|
+
variant: i.variant,
|
|
242
|
+
enabled: i.enabled
|
|
243
|
+
})),
|
|
244
|
+
pageEnabled: (pageId) => pageEnabled(fixture, pageId),
|
|
245
|
+
section: async (key) => {
|
|
246
|
+
const declared = template.instances.find((i) => i.section === key);
|
|
247
|
+
if (declared === void 0) throw new Error(`The composition places no section "${key}".`);
|
|
248
|
+
const anchor = declared.version?.schema.anchor;
|
|
249
|
+
const { variant } = declared.display;
|
|
250
|
+
return {
|
|
251
|
+
schema: {
|
|
252
|
+
slots: declared.sectionSchema.slots,
|
|
253
|
+
anchor: typeof anchor === "string" ? anchor : declared.section,
|
|
254
|
+
...variant === null ? {} : { display: { variant: { cases: variant.cases } } }
|
|
255
|
+
},
|
|
256
|
+
component: await renderer.section(key)
|
|
257
|
+
};
|
|
258
|
+
},
|
|
259
|
+
media: () => fixtureMedia(fixture, assetUrl, {
|
|
260
|
+
contentBase: bases.content,
|
|
261
|
+
hash: addressHash,
|
|
262
|
+
listed: (address, file) => {
|
|
263
|
+
list(address, file);
|
|
264
|
+
named?.(address, file);
|
|
265
|
+
}
|
|
266
|
+
})
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
function basesOf(template, held, fixture) {
|
|
270
|
+
const content = `${base}${ROUTES.output(propertyOf(held, fixture).name, fixture.id, template.output)}`;
|
|
271
|
+
return {
|
|
272
|
+
content,
|
|
273
|
+
build: `${content}${ASSETS}/`
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
function pageRequest(template, fixture, bases) {
|
|
277
|
+
return {
|
|
278
|
+
react: renderer,
|
|
279
|
+
snapshot: snapshotOf(template, fixture, bases),
|
|
280
|
+
contentBase: bases.content,
|
|
281
|
+
buildBase: bases.build,
|
|
282
|
+
kept
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
async function renderForCanvas(template, fixture, bases, pageId, resolved, over) {
|
|
286
|
+
const declared = template.instances.find((i) => i.instanceId === resolved.instance_id);
|
|
287
|
+
if (declared === void 0) throw new Error(`The composition places no section "${resolved.section_key}".`);
|
|
288
|
+
const laid = over === void 0 ? void 0 : {
|
|
289
|
+
values: laidValues({}, declared.sectionSchema.slots, over.values),
|
|
290
|
+
variant: over.variant
|
|
291
|
+
};
|
|
292
|
+
return (await renderPageSection({
|
|
293
|
+
...pageRequest(template, fixture, bases),
|
|
294
|
+
pageId,
|
|
295
|
+
...laid === void 0 ? {} : { over: { [resolved.instance_id]: laid } }
|
|
296
|
+
}, resolved.instance_id)).html;
|
|
297
|
+
}
|
|
298
|
+
async function contentFile(pathname) {
|
|
299
|
+
if (!pathname.startsWith(base)) return null;
|
|
300
|
+
const at = parseOutputPath(pathname.slice(base.length));
|
|
301
|
+
if (at === null || at.rest[0] !== ASSETS || at.rest.length < 2 || at.rest.includes("")) return null;
|
|
302
|
+
const template = await reader.template();
|
|
303
|
+
const held = await fixtures();
|
|
304
|
+
const fixture = held.fixtures.find((f) => f.id === at.fixture);
|
|
305
|
+
if (fixture === void 0) return null;
|
|
306
|
+
const bases = basesOf(template, held, fixture);
|
|
307
|
+
if (bases.content !== `${base}${ROUTES.output(at.property, at.fixture, template.output)}` || at.output !== OUTPUT_FOLDERS[template.output === "website" ? "site" : "download"]) return null;
|
|
308
|
+
const below = at.rest.slice(1);
|
|
309
|
+
if (below.length === 1) return { url: assetUrl(`${ROUTES.build}${encodeURIComponent(below[0])}`) };
|
|
310
|
+
const address = `${bases.content}${ASSETS}/${below.map(encodeURIComponent).join("/")}`;
|
|
311
|
+
const named = listed.get(address);
|
|
312
|
+
if (named !== void 0) return named;
|
|
313
|
+
for (const page of enabledPages(fixture, template.pages)) await renderPage({
|
|
314
|
+
...pageRequest(template, fixture, bases),
|
|
315
|
+
pageId: page.id
|
|
316
|
+
}).catch(() => void 0);
|
|
317
|
+
return listed.get(address) ?? null;
|
|
318
|
+
}
|
|
319
|
+
function pageById(template, pageId, status) {
|
|
320
|
+
const page = template.pages.find((p) => p.id === pageId);
|
|
321
|
+
if (page === void 0) throw new HostRefusal(status, `The template declares no page "${pageId}".`);
|
|
322
|
+
return page;
|
|
323
|
+
}
|
|
324
|
+
function addressPlan(template) {
|
|
325
|
+
return {
|
|
326
|
+
template,
|
|
327
|
+
downloads: template.output === "website" ? null : downloads === true ? "made" : reader.shipped !== void 0 ? "shipped" : null
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
async function catalog() {
|
|
331
|
+
const shared = await Promise.all([reader.islands(), stylesheets()]).then(([islands, hrefs]) => ({
|
|
332
|
+
wire: 7,
|
|
333
|
+
islands: {
|
|
334
|
+
map: { ...islands.map },
|
|
335
|
+
hostScript: islands.canvasHost,
|
|
336
|
+
importMap: { ...islands.importMap }
|
|
337
|
+
},
|
|
338
|
+
stylesheets: [...hrefs]
|
|
339
|
+
}), () => ({
|
|
340
|
+
wire: 7,
|
|
341
|
+
islands: {
|
|
342
|
+
map: {},
|
|
343
|
+
hostScript: null,
|
|
344
|
+
importMap: {}
|
|
345
|
+
},
|
|
346
|
+
stylesheets: []
|
|
347
|
+
}));
|
|
348
|
+
let template;
|
|
349
|
+
let listed;
|
|
350
|
+
try {
|
|
351
|
+
template = await reader.template();
|
|
352
|
+
listed = await fixtures();
|
|
353
|
+
} catch (err) {
|
|
354
|
+
return {
|
|
355
|
+
...shared,
|
|
356
|
+
template: {
|
|
357
|
+
key: "",
|
|
358
|
+
name: "",
|
|
359
|
+
output: "website",
|
|
360
|
+
formats: [],
|
|
361
|
+
pages: [],
|
|
362
|
+
canvases: []
|
|
363
|
+
},
|
|
364
|
+
properties: [],
|
|
365
|
+
capabilities: {
|
|
366
|
+
download: false,
|
|
367
|
+
save: false,
|
|
368
|
+
upload: false
|
|
369
|
+
},
|
|
370
|
+
error: err instanceof Error ? err.message : String(err)
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
const error = listed.violations.length > 0 && listed.properties.length === 0 ? `No fixture could be loaded:\n${violationText(listed.violations)}` : void 0;
|
|
374
|
+
return {
|
|
375
|
+
...shared,
|
|
376
|
+
template: {
|
|
377
|
+
key: template.key,
|
|
378
|
+
name: template.name,
|
|
379
|
+
output: template.output,
|
|
380
|
+
formats: template.output === "website" ? [] : template.formats.map(catalogFormat),
|
|
381
|
+
pages: template.pages.map((page) => ({
|
|
382
|
+
id: page.id,
|
|
383
|
+
label: page.label,
|
|
384
|
+
...page.path === void 0 ? {} : { path: page.path },
|
|
385
|
+
...page.direction === void 0 ? {} : { direction: page.direction },
|
|
386
|
+
instanceIds: page.sections.map((s) => s.instanceId)
|
|
387
|
+
})),
|
|
388
|
+
canvases: template.canvases.map((canvas) => ({
|
|
389
|
+
id: canvas.id,
|
|
390
|
+
label: canvas.label,
|
|
391
|
+
pages: [...canvas.pages]
|
|
392
|
+
}))
|
|
393
|
+
},
|
|
394
|
+
properties: markedProperties(listed.properties.map((property) => catalogProperty(addressPlan(template), listed, property)), jobs === void 0 ? [] : await jobs.list(), (operation) => jobs?.mark(operation)),
|
|
395
|
+
capabilities: {
|
|
396
|
+
download: addressPlan(template).downloads !== null,
|
|
397
|
+
save: saves !== void 0,
|
|
398
|
+
upload: saves !== void 0
|
|
399
|
+
},
|
|
400
|
+
...error === void 0 ? {} : { error }
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
async function problems() {
|
|
404
|
+
const failures = jobs === void 0 ? [] : standingFailures(await jobs.list());
|
|
405
|
+
let listed;
|
|
406
|
+
try {
|
|
407
|
+
await reader.template();
|
|
408
|
+
listed = await fixtures();
|
|
409
|
+
} catch (err) {
|
|
410
|
+
return { problems: [{
|
|
411
|
+
kind: "template",
|
|
412
|
+
file: null,
|
|
413
|
+
message: err instanceof Error ? err.message : String(err)
|
|
414
|
+
}, ...failures] };
|
|
415
|
+
}
|
|
416
|
+
return { problems: [...listed.violations.map((v) => ({
|
|
417
|
+
kind: "fixture",
|
|
418
|
+
rule: v.rule,
|
|
419
|
+
file: v.file,
|
|
420
|
+
...v.line === void 0 ? {} : { line: v.line },
|
|
421
|
+
message: v.message
|
|
422
|
+
})), ...failures] };
|
|
423
|
+
}
|
|
424
|
+
function runner() {
|
|
425
|
+
if (jobs === void 0) throw new HostRefusal(501, "This playground runs no jobs.");
|
|
426
|
+
return jobs;
|
|
427
|
+
}
|
|
428
|
+
async function jobRoute(request, url, path) {
|
|
429
|
+
if (path === ROUTES.jobs) {
|
|
430
|
+
if (request.method !== "GET" && request.method !== "HEAD") throw new HostRefusal(405, `${ROUTES.jobs} only lists; an operation starts a job at its own address.`);
|
|
431
|
+
return jsonResponse({ jobs: jobs === void 0 ? [] : await jobs.list() });
|
|
432
|
+
}
|
|
433
|
+
const id = decodeURIComponent(path.slice(`${ROUTES.jobs}/`.length));
|
|
434
|
+
if (id === "" || id.includes("/")) throw new HostRefusal(404, `There is no route at ${url.pathname}.`);
|
|
435
|
+
let job;
|
|
436
|
+
if (request.method === "DELETE") job = jobs === void 0 ? null : await jobs.cancel(id);
|
|
437
|
+
else if (request.method === "GET" || request.method === "HEAD") job = jobs === void 0 ? null : await jobs.read(id, waitParam(url));
|
|
438
|
+
else throw new HostRefusal(405, `GET a job to read it, or DELETE it to cancel it.`);
|
|
439
|
+
if (job === null) throw new HostRefusal(404, `There is no job "${id}".`);
|
|
440
|
+
return jsonResponse(job);
|
|
441
|
+
}
|
|
442
|
+
async function probe(request, url) {
|
|
443
|
+
if (request.method !== "POST") throw new HostRefusal(405, "POST to start a probe.");
|
|
444
|
+
const started = runner();
|
|
445
|
+
const fixture = await fixtureById(requiredParam(url, "fixture", "api/probe"));
|
|
446
|
+
return acceptedResponse(await started.start({
|
|
447
|
+
operation: PROBE_OPERATION,
|
|
448
|
+
subject: { fixture: fixture.id },
|
|
449
|
+
version: await mount.version()
|
|
450
|
+
}));
|
|
451
|
+
}
|
|
452
|
+
async function render(request) {
|
|
453
|
+
if (request.method !== "POST") throw new HostRefusal(405, `POST a render request to ${ROUTES.render}.`);
|
|
454
|
+
const body = parseRenderRequest(await boundedText(request));
|
|
455
|
+
const template = await reader.template();
|
|
456
|
+
const held = await fixtures();
|
|
457
|
+
const fixture = fixtureIn(held, body.fixture);
|
|
458
|
+
const resolved = body.instance_id === void 0 ? fixture.instances.find((i) => i.section_key === body.section_key) : instanceOf(fixture, body.instance_id);
|
|
459
|
+
if (resolved === void 0 || resolved.section_key !== body.section_key) throw new HostRefusal(400, `The composition places no section "${body.section_key}"${body.instance_id === void 0 ? "" : ` as "${body.instance_id}"`}.`);
|
|
460
|
+
const pageId = body.page_id ?? (template.pages.length === 1 ? template.pages[0].id : null);
|
|
461
|
+
if (pageId === null) throw new HostRefusal(400, "A render of a template with several pages names the page it renders on.");
|
|
462
|
+
const page = pageById(template, pageId, 400);
|
|
463
|
+
return { html: await renderForCanvas(template, fixture, basesOf(template, held, fixture), page.id, resolved, {
|
|
464
|
+
values: body.slots,
|
|
465
|
+
variant: body.variant
|
|
466
|
+
}) };
|
|
467
|
+
}
|
|
468
|
+
async function save(request) {
|
|
469
|
+
if (request.method !== "POST") throw new HostRefusal(405, `POST a save to ${ROUTES.save}.`);
|
|
470
|
+
if (saves === void 0) throw new HostRefusal(501, "This playground does not save: an edit stays in this browser until it reloads.");
|
|
471
|
+
const body = parseSaveRequest(await boundedText(request));
|
|
472
|
+
const subject = body.batch === "content" ? { fixture: body.fixture } : {
|
|
473
|
+
property: body.property,
|
|
474
|
+
fixture: body.fixture
|
|
475
|
+
};
|
|
476
|
+
return persist(saves, subject, (base, at) => saveDocuments({
|
|
477
|
+
template: base.template,
|
|
478
|
+
property: at.target,
|
|
479
|
+
fixture: at.fixture,
|
|
480
|
+
store: base.reads,
|
|
481
|
+
ops: body.ops
|
|
482
|
+
}));
|
|
483
|
+
}
|
|
484
|
+
async function library(request) {
|
|
485
|
+
if (request.method !== "POST") throw new HostRefusal(405, `POST a library change to ${ROUTES.library}.`);
|
|
486
|
+
if (saves === void 0) throw new HostRefusal(501, "This playground does not save: its library cannot change.");
|
|
487
|
+
const body = parseLibraryRequest(await boundedText(request));
|
|
488
|
+
if (body.kind === "remove") return persist(saves, { property: body.property }, ({ reads }, at) => removeSave(at.target, reads, body));
|
|
489
|
+
if ("list" in body) return persist(saves, { property: body.property }, ({ reads }, at) => linkSave(at.target, reads, body));
|
|
490
|
+
return persist(saves, { fixture: body.fixture }, ({ template, reads }, at) => ownedLinkSave(template, at.fixture, reads, body));
|
|
491
|
+
}
|
|
492
|
+
async function changeFixtures(request) {
|
|
493
|
+
if (request.method !== "POST") throw new HostRefusal(405, `POST a fixture operation to ${ROUTES.fixtures}.`);
|
|
494
|
+
if (saves === void 0) throw new HostRefusal(501, "This playground does not save, so its fixtures cannot change here.");
|
|
495
|
+
const operation = parseFixtureOperation(await boundedText(request));
|
|
496
|
+
for (let attempt = 1;; attempt += 1) {
|
|
497
|
+
const base = await saves.current();
|
|
498
|
+
const { writes, at } = await fixtureOperation(base.list, base.reads, operation);
|
|
499
|
+
if ("moved" in await saves.change(base.version, writes)) {
|
|
500
|
+
if (attempt < MAX_SAVE_ATTEMPTS) continue;
|
|
501
|
+
throw new HostRefusal(409, "The template kept changing while this change was made; reload the playground and try again.");
|
|
502
|
+
}
|
|
503
|
+
const after = await fixtures();
|
|
504
|
+
const plan = addressPlan(await reader.template());
|
|
505
|
+
if (at !== null && (!after.properties.some((p) => p.name === at.property) || at.content !== void 0 && !after.fixtures.some((f) => f.id === at.content))) throw new HostRefusal(500, `The change was written, but the ${at.content === void 0 ? `property "${at.property}"` : `content fixture "${at.content}"`} does not load:\n${after.violations.length > 0 ? violationText(after.violations) : "it is not listed"}`);
|
|
506
|
+
const first = after.properties[0];
|
|
507
|
+
return {
|
|
508
|
+
properties: after.properties.map((p) => catalogProperty(plan, after, p)),
|
|
509
|
+
at: at ?? (first === void 0 ? null : { property: first.name })
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
async function upload(request, url) {
|
|
514
|
+
if (request.method !== "POST") throw new HostRefusal(405, "POST a file to api/upload.");
|
|
515
|
+
if (saves === void 0) throw new HostRefusal(501, "This playground does not save: an upload has nowhere to land.");
|
|
516
|
+
const name = requiredParam(url, "name", "api/upload");
|
|
517
|
+
const param = (key) => url.searchParams.get(key);
|
|
518
|
+
const property = param("property");
|
|
519
|
+
const fixture = param("fixture");
|
|
520
|
+
const list = param("list");
|
|
521
|
+
const owner = param("owner");
|
|
522
|
+
const instance = param("instance");
|
|
523
|
+
const slot = param("slot");
|
|
524
|
+
const target = property !== null && list !== null ? {
|
|
525
|
+
property,
|
|
526
|
+
list
|
|
527
|
+
} : property !== null && owner !== null ? {
|
|
528
|
+
property,
|
|
529
|
+
owner,
|
|
530
|
+
...fixture === null ? {} : { fixture }
|
|
531
|
+
} : fixture !== null && instance !== null && slot !== null ? {
|
|
532
|
+
fixture,
|
|
533
|
+
instance,
|
|
534
|
+
slot
|
|
535
|
+
} : null;
|
|
536
|
+
if (target === null) throw new HostRefusal(400, "An upload names where the file lands: a property and its list, a property's row owner (and the content fixture a slot stages it in), or a content fixture, an instance and its slot.");
|
|
537
|
+
const declared = Number(request.headers.get("content-length") ?? "0");
|
|
538
|
+
if (declared > 524288e3) throw new HostRefusal(413, `Got ${String(declared)} bytes; the cap is ${String(MAX_UPLOAD_BYTES)} bytes (500 MB).`);
|
|
539
|
+
const file = {
|
|
540
|
+
target,
|
|
541
|
+
name,
|
|
542
|
+
type: request.headers.get("content-type") ?? "",
|
|
543
|
+
bytes: new Uint8Array(await request.arrayBuffer())
|
|
544
|
+
};
|
|
545
|
+
if ("instance" in target) return persist(saves, { fixture: target.fixture }, ({ template, reads }, at) => ownedUploadSave(template, at.fixture, reads, {
|
|
546
|
+
...file,
|
|
547
|
+
target
|
|
548
|
+
}));
|
|
549
|
+
if ("owner" in target && target.fixture !== void 0) return persist(saves, {
|
|
550
|
+
property: target.property,
|
|
551
|
+
fixture: target.fixture
|
|
552
|
+
}, ({ reads }, at) => stagedUploadSave(at.fixture, reads, {
|
|
553
|
+
...file,
|
|
554
|
+
target
|
|
555
|
+
}));
|
|
556
|
+
if ("owner" in target) return persist(saves, { property: target.property }, ({ reads }, at) => rowImageUploadSave(at.target, reads, {
|
|
557
|
+
...file,
|
|
558
|
+
target
|
|
559
|
+
}));
|
|
560
|
+
return persist(saves, { property: target.property }, ({ reads }, at) => uploadSave(at.target, reads, file));
|
|
561
|
+
}
|
|
562
|
+
async function persist(files, subject, compute) {
|
|
563
|
+
for (let attempt = 1;; attempt += 1) {
|
|
564
|
+
const base = await files.current();
|
|
565
|
+
const plan = addressPlan(base.template);
|
|
566
|
+
const listing = (held, f) => catalogFixture(plan, propertyOf(held, f).name, f);
|
|
567
|
+
const state = (held, f) => JSON.stringify([
|
|
568
|
+
listing(held, f),
|
|
569
|
+
f.facts,
|
|
570
|
+
Object.keys(f.media).sort()
|
|
571
|
+
]);
|
|
572
|
+
const propertyState = (held, p) => JSON.stringify([
|
|
573
|
+
catalogProperty(plan, held, p),
|
|
574
|
+
p.facts,
|
|
575
|
+
Object.keys(p.media).sort()
|
|
576
|
+
]);
|
|
577
|
+
const before = new Map(base.fixtures.fixtures.map((f) => [f.id, state(base.fixtures, f)]));
|
|
578
|
+
const beforeProperties = new Map(base.fixtures.properties.map((p) => [p.name, propertyState(base.fixtures, p)]));
|
|
579
|
+
const at = subjectIn(base.fixtures, subject);
|
|
580
|
+
const computed = await compute(base, at);
|
|
581
|
+
const { writes, media: added, rowIds } = "writes" in computed ? computed : { writes: computed };
|
|
582
|
+
const made = rowIds === void 0 || rowIds.size === 0 ? {} : { row_ids: Object.fromEntries(rowIds) };
|
|
583
|
+
if (writes.length === 0) return {
|
|
584
|
+
changed: [],
|
|
585
|
+
properties: [],
|
|
586
|
+
...made
|
|
587
|
+
};
|
|
588
|
+
if ("moved" in await files.change(base.version, writes)) {
|
|
589
|
+
if (attempt < MAX_SAVE_ATTEMPTS) continue;
|
|
590
|
+
throw new HostRefusal(409, "The template kept changing while this save was made; reload the playground and edit again.");
|
|
591
|
+
}
|
|
592
|
+
const after = await fixtures();
|
|
593
|
+
const saved = at.fixture === void 0 ? void 0 : after.fixtures.find((f) => f.id === at.fixture.id);
|
|
594
|
+
const property = after.properties.find((p) => p.name === at.property.name);
|
|
595
|
+
if (property === void 0 || at.fixture !== void 0 && saved === void 0) throw new HostRefusal(500, `The save was written, but the ${at.fixture === void 0 ? `property "${at.property.name}"` : `content fixture "${at.fixture.id}"`} no longer resolves:\n${after.violations.length > 0 ? violationText(after.violations) : "it is gone"}`);
|
|
596
|
+
const changed = after.fixtures.filter((f) => before.get(f.id) !== state(after, f)).map((f) => listing(after, f));
|
|
597
|
+
const properties = after.properties.filter((p) => beforeProperties.get(p.name) !== propertyState(after, p)).map((p) => catalogProperty(plan, after, p));
|
|
598
|
+
const file = ("file" in computed ? await files.served(computed.file) : void 0) ?? (added === void 0 ? void 0 : (saved?.media[added] ?? property.media[added])?.file);
|
|
599
|
+
const savedName = at.fixture?.id;
|
|
600
|
+
return {
|
|
601
|
+
changed: [...changed.filter((f) => f.name === savedName), ...changed.filter((f) => f.name !== savedName)],
|
|
602
|
+
properties,
|
|
603
|
+
...made,
|
|
604
|
+
...added === void 0 ? {} : { media: added },
|
|
605
|
+
...file === void 0 || file === null ? {} : { url: assetUrl(fileUrlOf(file)) }
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
async function bootstrap(url) {
|
|
610
|
+
const template = await reader.template();
|
|
611
|
+
const held = await fixtures();
|
|
612
|
+
const fixture = fixtureIn(held, requiredParam(url, "fixture", "api/bootstrap"));
|
|
613
|
+
const bases = basesOf(template, held, fixture);
|
|
614
|
+
const format = bootstrapFormat(template, url.searchParams.get("format"));
|
|
615
|
+
const versions = sectionVersions(template);
|
|
616
|
+
const doc = new Map(fixture.instances.map((i) => [i.instance_id, i]));
|
|
617
|
+
const islands = await reader.islands(bases.build);
|
|
618
|
+
const provenance = Object.fromEntries(template.instances.map((instance) => [instance.instanceId, slotProvenance(fixture, instance.instanceId, instance.sectionSchema.slots)]));
|
|
619
|
+
return {
|
|
620
|
+
...await assembleBootstrap({
|
|
621
|
+
deliverable: fixtureDeliverable(template, fixture, format),
|
|
622
|
+
format,
|
|
623
|
+
composition: bootstrapComposition(template),
|
|
624
|
+
contentDoc: fixtureContentDoc(fixture),
|
|
625
|
+
facts: fixture.facts,
|
|
626
|
+
by: {},
|
|
627
|
+
fillHolders: SETTLED_FILL_HOLDERS,
|
|
628
|
+
contentFingerprint: null,
|
|
629
|
+
sectionOf: (key) => {
|
|
630
|
+
const entry = versions.get(key);
|
|
631
|
+
if (entry === void 0) throw new HostRefusal(500, `The composition places the section "${key}", which the template does not declare.`);
|
|
632
|
+
return bootstrapSection(key, entry.instance, entry.version);
|
|
633
|
+
},
|
|
634
|
+
computedOf: (entry) => {
|
|
635
|
+
const declared = template.instances.find((i) => i.instanceId === entry.instance_id);
|
|
636
|
+
const resolved = doc.get(entry.instance_id);
|
|
637
|
+
return Promise.resolve(declared === void 0 || resolved === void 0 ? {} : settledComputed(declared.sectionSchema.slots, resolved.slots));
|
|
638
|
+
},
|
|
639
|
+
render: async (entry, _section, at) => {
|
|
640
|
+
try {
|
|
641
|
+
const resolved = instanceOf(fixture, entry.instance_id);
|
|
642
|
+
return {
|
|
643
|
+
html: await renderForCanvas(template, fixture, bases, at.pageId, resolved),
|
|
644
|
+
render_error: null
|
|
645
|
+
};
|
|
646
|
+
} catch (err) {
|
|
647
|
+
return {
|
|
648
|
+
html: null,
|
|
649
|
+
render_error: {
|
|
650
|
+
code: "render_failed",
|
|
651
|
+
message: err instanceof Error ? err.message : String(err)
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
}),
|
|
657
|
+
template: {
|
|
658
|
+
key: template.key,
|
|
659
|
+
display_name: template.name
|
|
660
|
+
},
|
|
661
|
+
bases: {
|
|
662
|
+
content: bases.content,
|
|
663
|
+
build: bases.build
|
|
664
|
+
},
|
|
665
|
+
islands: {
|
|
666
|
+
map: { ...islands.map },
|
|
667
|
+
hostScript: islands.canvasHost,
|
|
668
|
+
importMap: { ...islands.importMap }
|
|
669
|
+
},
|
|
670
|
+
stylesheets: [...await stylesheets(bases.build)],
|
|
671
|
+
provenance
|
|
672
|
+
};
|
|
673
|
+
}
|
|
674
|
+
async function requirements(url) {
|
|
675
|
+
const template = await reader.template();
|
|
676
|
+
const named = url.searchParams.get("property");
|
|
677
|
+
if (named !== null) {
|
|
678
|
+
if (url.searchParams.has("fixture")) throw new HostRefusal(400, "api/requirements answers a property or a content fixture; name one.");
|
|
679
|
+
const property = await propertyByName(named);
|
|
680
|
+
const subjects = [templateSubject(template)];
|
|
681
|
+
return requirementsResponseOf("property", subjects, answerRequirements(subjects, property.facts));
|
|
682
|
+
}
|
|
683
|
+
const fixture = await fixtureById(requiredParam(url, "fixture", "api/requirements"));
|
|
684
|
+
return deliverableRequirements(fixtureSubject(template, fixture), fixture.facts);
|
|
685
|
+
}
|
|
686
|
+
async function facts(url) {
|
|
687
|
+
const property = await propertyByName(requiredParam(url, "property", "api/facts"));
|
|
688
|
+
const home = url.searchParams.get("home") ?? "property";
|
|
689
|
+
if (home === "property") return {
|
|
690
|
+
facts: property.facts,
|
|
691
|
+
by: {}
|
|
692
|
+
};
|
|
693
|
+
if (home === "library") return {
|
|
694
|
+
facts: {
|
|
695
|
+
files: property.facts.files,
|
|
696
|
+
contacts: property.facts.contacts
|
|
697
|
+
},
|
|
698
|
+
by: {}
|
|
699
|
+
};
|
|
700
|
+
throw new HostRefusal(400, `api/facts reads the property or the library, not "${home}".`);
|
|
701
|
+
}
|
|
702
|
+
async function media(url) {
|
|
703
|
+
const property = await propertyByName(requiredParam(url, "property", "api/media"));
|
|
704
|
+
return {
|
|
705
|
+
items: propertyMediaItems(property, assetUrl),
|
|
706
|
+
contacts: propertyContacts(property, assetUrl),
|
|
707
|
+
lists: propertyMediaLists(property)
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
async function owned(url) {
|
|
711
|
+
return { owned: fixtureOwnedMedia(await fixtureById(requiredParam(url, "fixture", "api/owned")), assetUrl) };
|
|
712
|
+
}
|
|
713
|
+
async function siteOf(template, held, fixture, origin) {
|
|
714
|
+
const bases = basesOf(template, held, fixture);
|
|
715
|
+
const pages = [];
|
|
716
|
+
for (const page of enabledPages(fixture, template.pages)) {
|
|
717
|
+
const sections = await renderPage({
|
|
718
|
+
...pageRequest(template, fixture, bases),
|
|
719
|
+
pageId: page.id
|
|
720
|
+
});
|
|
721
|
+
pages.push({
|
|
722
|
+
id: page.id,
|
|
723
|
+
label: page.label,
|
|
724
|
+
href: page.path === void 0 || page.path === "/" ? "/" : `${page.path}/`,
|
|
725
|
+
sections: sections.map((section) => section.html),
|
|
726
|
+
media: [],
|
|
727
|
+
buildFiles: [...new Set(sections.flatMap((section) => section.buildFiles))]
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
return sites({
|
|
731
|
+
pages,
|
|
732
|
+
contentBase: bases.content,
|
|
733
|
+
buildBase: bases.build,
|
|
734
|
+
siteUrl: `${origin}${bases.content}`,
|
|
735
|
+
ingestBase: `${base}api`,
|
|
736
|
+
facts: fixture.facts,
|
|
737
|
+
templateName: template.name,
|
|
738
|
+
coverUrl: (mediaId) => {
|
|
739
|
+
const file = fixture.media[mediaId]?.file;
|
|
740
|
+
const key = typeof file === "string" ? file : file?.url ?? null;
|
|
741
|
+
return key === null ? null : assetUrl(key);
|
|
742
|
+
},
|
|
743
|
+
hash: addressHash
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
async function siteFile(request, url, at) {
|
|
747
|
+
const template = await reader.template();
|
|
748
|
+
if (template.output !== "website") throw new HostRefusal(404, `"${template.key}" is a ${template.output} template and has no site; its output is its download.`);
|
|
749
|
+
const held = await fixtures();
|
|
750
|
+
const fixture = fixtureIn(held, at.fixture);
|
|
751
|
+
const owner = propertyOf(held, fixture);
|
|
752
|
+
if (at.property !== owner.name) throw new HostRefusal(404, `The content fixture "${fixture.id}" is on the property "${owner.name}", not "${at.property}".`);
|
|
753
|
+
const { rest } = at;
|
|
754
|
+
if (rest.length === 0 || rest.length === 1 && rest[0] !== "" && rest[0] !== "favicon.ico") return new Response(null, {
|
|
755
|
+
status: 308,
|
|
756
|
+
headers: { location: `${url.pathname}/${url.search}` }
|
|
757
|
+
});
|
|
758
|
+
const site = await siteOf(template, held, fixture, requestOrigin(request, url));
|
|
759
|
+
const path = rest.join("/");
|
|
760
|
+
const file = site.files.find((f) => f.path === (path === "" || path.endsWith("/") ? `${path}index.html` : path));
|
|
761
|
+
if (file !== void 0) return siteFileResponse(file);
|
|
762
|
+
if (rest[0] === ASSETS) return null;
|
|
763
|
+
const pagePath = rest.length === 2 && rest[1] === "" ? `/${rest[0]}` : null;
|
|
764
|
+
const page = pagePath === null ? void 0 : template.pages.find((p) => p.path === pagePath);
|
|
765
|
+
if (page !== void 0) throw new HostRefusal(404, `The fixture "${fixture.id}" switches the page "${page.id}" off, so its site has no page at "${pagePath}".`);
|
|
766
|
+
const paths = enabledPages(fixture, template.pages).map((p) => p.path ?? p.id).join(", ");
|
|
767
|
+
throw new HostRefusal(404, `The site has no page at ${url.pathname} (it has: ${paths}).`);
|
|
768
|
+
}
|
|
769
|
+
async function askedDownload(ask) {
|
|
770
|
+
const template = await reader.template();
|
|
771
|
+
if (template.output === "website") throw new HostRefusal(404, `"${template.key}" is a website: it has no download. Open its site instead.`);
|
|
772
|
+
const output = template.output;
|
|
773
|
+
const held = await fixtures();
|
|
774
|
+
const fixture = fixtureIn(held, ask.fixture);
|
|
775
|
+
const owner = propertyOf(held, fixture);
|
|
776
|
+
const format = ask.format === null ? template.formats[0] : template.formats.find((f) => f.id === ask.format);
|
|
777
|
+
if (format === void 0) throw new HostRefusal(404, `The template declares no format "${ask.format ?? ""}" (have: ${template.formats.map((f) => f.id).join(", ") || "none"}).`);
|
|
778
|
+
let pages;
|
|
779
|
+
if (ask.page !== null) {
|
|
780
|
+
const page = pageById(template, ask.page, 404);
|
|
781
|
+
if (!pageEnabled(fixture, page.id)) throw new HostRefusal(404, `The fixture "${fixture.id}" switches the page "${page.id}" off, so it has no image.`);
|
|
782
|
+
pages = [page];
|
|
783
|
+
} else {
|
|
784
|
+
pages = enabledPages(fixture, template.pages);
|
|
785
|
+
if (pages.length === 0) throw new HostRefusal(404, `The fixture "${fixture.id}" switches every page off, so it has no download.`);
|
|
786
|
+
}
|
|
787
|
+
const names = {
|
|
788
|
+
propertyAddress: propertyAddressOf(fixture.facts),
|
|
789
|
+
templateDisplayName: template.name
|
|
790
|
+
};
|
|
791
|
+
const pageFilenames = Object.fromEntries(template.pages.map((page) => [page.id, downloadFilename({
|
|
792
|
+
...names,
|
|
793
|
+
pageLabel: page.label,
|
|
794
|
+
mime: "image/png"
|
|
795
|
+
})]));
|
|
796
|
+
const naming = {
|
|
797
|
+
title: downloadStem({
|
|
798
|
+
...names,
|
|
799
|
+
pageLabel: null
|
|
800
|
+
}),
|
|
801
|
+
pageFilenames
|
|
802
|
+
};
|
|
803
|
+
const one = pages.length === 1 ? pages[0].id : null;
|
|
804
|
+
const file = ask.page === null && output === "document" ? {
|
|
805
|
+
name: downloadFilename({
|
|
806
|
+
...names,
|
|
807
|
+
pageLabel: null,
|
|
808
|
+
mime: "application/pdf"
|
|
809
|
+
}),
|
|
810
|
+
contentType: "application/pdf",
|
|
811
|
+
page: null
|
|
812
|
+
} : ask.page === null && one === null ? {
|
|
813
|
+
name: downloadFilename({
|
|
814
|
+
...names,
|
|
815
|
+
pageLabel: null,
|
|
816
|
+
mime: "application/zip"
|
|
817
|
+
}),
|
|
818
|
+
contentType: "application/zip",
|
|
819
|
+
page: null
|
|
820
|
+
} : {
|
|
821
|
+
name: pageFilenames[one],
|
|
822
|
+
contentType: "image/png",
|
|
823
|
+
page: one
|
|
824
|
+
};
|
|
825
|
+
const subject = {
|
|
826
|
+
property: owner.name,
|
|
827
|
+
fixture: fixture.id,
|
|
828
|
+
format: format.id,
|
|
829
|
+
...ask.page === null ? {} : { page: ask.page }
|
|
830
|
+
};
|
|
831
|
+
return {
|
|
832
|
+
template,
|
|
833
|
+
held,
|
|
834
|
+
fixture,
|
|
835
|
+
format,
|
|
836
|
+
output,
|
|
837
|
+
pages,
|
|
838
|
+
naming,
|
|
839
|
+
file,
|
|
840
|
+
subject
|
|
841
|
+
};
|
|
842
|
+
}
|
|
843
|
+
async function downloadInput(ask) {
|
|
844
|
+
const asked = await askedDownload(ask);
|
|
845
|
+
const { template, fixture } = asked;
|
|
846
|
+
const bases = basesOf(template, asked.held, fixture);
|
|
847
|
+
const named = /* @__PURE__ */ new Map();
|
|
848
|
+
const request = {
|
|
849
|
+
react: renderer,
|
|
850
|
+
snapshot: snapshotOf(template, fixture, bases, (address, file) => named.set(address, file)),
|
|
851
|
+
contentBase: bases.content,
|
|
852
|
+
buildBase: bases.build,
|
|
853
|
+
kept
|
|
854
|
+
};
|
|
855
|
+
const pages = [];
|
|
856
|
+
for (const page of asked.pages) {
|
|
857
|
+
const sections = await renderPage({
|
|
858
|
+
...request,
|
|
859
|
+
pageId: page.id
|
|
860
|
+
});
|
|
861
|
+
pages.push({
|
|
862
|
+
id: page.id,
|
|
863
|
+
sectionHtml: sections.map((section) => section.html),
|
|
864
|
+
...page.direction === void 0 ? {} : { direction: page.direction }
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
const media = [...named].filter(([address]) => address.startsWith(bases.content)).map(([address, file]) => ({
|
|
868
|
+
path: address.slice(bases.content.length),
|
|
869
|
+
url: (file.master ?? file).url,
|
|
870
|
+
contentType: (file.master ?? file).contentType
|
|
871
|
+
}));
|
|
872
|
+
return {
|
|
873
|
+
subject: asked.subject,
|
|
874
|
+
output: asked.output,
|
|
875
|
+
shoot: ask.page === null ? "download" : "pages",
|
|
876
|
+
format: asked.format,
|
|
877
|
+
pages,
|
|
878
|
+
media,
|
|
879
|
+
binding: await reader.binding(),
|
|
880
|
+
naming: asked.naming,
|
|
881
|
+
bases,
|
|
882
|
+
file: asked.file
|
|
883
|
+
};
|
|
884
|
+
}
|
|
885
|
+
async function shippedDownload(at, url) {
|
|
886
|
+
const named = parseDownloadPath(at.rest);
|
|
887
|
+
if (named === null) throw new HostRefusal(404, `There is no download at ${url.pathname}.`);
|
|
888
|
+
const asked = await askedDownload({
|
|
889
|
+
property: at.property,
|
|
890
|
+
fixture: at.fixture,
|
|
891
|
+
format: url.searchParams.get("format"),
|
|
892
|
+
page: named.page
|
|
893
|
+
});
|
|
894
|
+
if (asked.subject.property !== at.property) return new Response(null, {
|
|
895
|
+
status: 308,
|
|
896
|
+
headers: { location: correctedDownloadLocation(url, at.property, asked.subject.property) }
|
|
897
|
+
});
|
|
898
|
+
if (reader.shipped === void 0) throw new HostRefusal(501, "This playground makes no downloads.");
|
|
899
|
+
const path = shippedDownloadPath({
|
|
900
|
+
fixture: asked.fixture.id,
|
|
901
|
+
format: asked.format.id,
|
|
902
|
+
file: asked.file
|
|
903
|
+
});
|
|
904
|
+
const bytes = await reader.shipped(path);
|
|
905
|
+
if (bytes === null) throw new HostRefusal(404, `This publish shipped no ${path.slice(path.indexOf("/") + 1)} for the fixture "${asked.fixture.id}", or a save since has changed it.`);
|
|
906
|
+
return new Response(new Uint8Array(bytes), { headers: {
|
|
907
|
+
"content-type": asked.file.contentType,
|
|
908
|
+
"content-disposition": attachmentDisposition(asked.file.name)
|
|
909
|
+
} });
|
|
910
|
+
}
|
|
911
|
+
async function route(request, url, path) {
|
|
912
|
+
if (path === ROUTES.jobs || path.startsWith(`${ROUTES.jobs}/`)) return jobRoute(request, url, path);
|
|
913
|
+
if (path === "api/probe") return probe(request, url);
|
|
914
|
+
if (path === ROUTES.render) return jsonResponse(await render(request));
|
|
915
|
+
if (path === ROUTES.save) return jsonResponse(await save(request));
|
|
916
|
+
if (path === ROUTES.library) return jsonResponse(await library(request));
|
|
917
|
+
if (path === ROUTES.fixtures) return jsonResponse(await changeFixtures(request));
|
|
918
|
+
if (path === "api/upload") return jsonResponse(await upload(request, url));
|
|
919
|
+
if (path === ROUTES.leads) return answerLead(request);
|
|
920
|
+
if (request.method !== "GET" && request.method !== "HEAD" && isHostRead(path)) throw new HostRefusal(405, `${path} only reads; a change saves through ${ROUTES.save}.`);
|
|
921
|
+
if (path === ROUTES.catalog) return jsonResponse(await catalog());
|
|
922
|
+
if (path === ROUTES.problems) return jsonResponse(await problems());
|
|
923
|
+
if (path === "api/media") return jsonResponse(await media(url));
|
|
924
|
+
if (path === "api/owned") return jsonResponse(await owned(url));
|
|
925
|
+
if (path === "api/bootstrap") return jsonResponse(await bootstrap(url));
|
|
926
|
+
if (path === "api/requirements") return jsonResponse(await requirements(url));
|
|
927
|
+
if (path === "api/facts") return jsonResponse(await facts(url));
|
|
928
|
+
const site = parseOutputPath(path);
|
|
929
|
+
if (site?.output === OUTPUT_FOLDERS.download && site.rest[0] !== ASSETS) return shippedDownload(site, url);
|
|
930
|
+
if (site?.output === OUTPUT_FOLDERS.site) return siteFile(request, url, site);
|
|
931
|
+
return null;
|
|
932
|
+
}
|
|
933
|
+
return {
|
|
934
|
+
downloadInput,
|
|
935
|
+
contentFile,
|
|
936
|
+
async handle(request) {
|
|
937
|
+
const url = new URL(request.url);
|
|
938
|
+
if (!url.pathname.startsWith(base) && `${url.pathname}/` !== base) return null;
|
|
939
|
+
const path = url.pathname.slice(base.length);
|
|
940
|
+
try {
|
|
941
|
+
return await route(request, url, path);
|
|
942
|
+
} catch (err) {
|
|
943
|
+
const status = refusalStatus(err);
|
|
944
|
+
if (status === null) throw err;
|
|
945
|
+
return textResponse(status, err instanceof Error ? err.message : String(err));
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
//#endregion
|
|
952
|
+
export { serveHost };
|