@homepages/concrete 11.0.0 → 13.0.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/CHANGELOG.md +203 -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 +17 -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 -60
- package/dist/base.css +19 -59
- 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 +48 -22
- package/dist/packages/internal/fill-bake/dist/held-rows.js +2 -0
- package/dist/packages/internal/fill-bake/dist/index.js +6 -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/format-geometry/dist/capture.js +3 -11
- package/dist/packages/internal/format-geometry/dist/format.d.ts +2 -8
- package/dist/packages/internal/format-geometry/dist/geometry.js +2 -13
- 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/primitives/FrameShell.d.ts +5 -2
- package/dist/primitives/FrameShell.js +2 -1
- package/dist/rules/registry.js +28 -4
- package/dist/schema/fact.d.ts +2 -2
- package/dist/schema/facts-view.d.ts +1 -1
- package/dist/schema/format.d.ts +0 -1
- package/dist/schema/format.js +1 -2
- package/dist/schema/manifest.js +18 -24
- 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/site-analytics.js +6 -1
- package/dist/site-runtime/window-height.js +19 -0
- package/dist/template/define-template.d.ts +25 -4
- package/dist/template/define-template.js +3 -0
- package/dist/template/logic-shim.d.ts +1 -1
- package/dist/template/materialize.js +3 -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 +9 -5
- package/package.json +14 -30
- package/dist/artifact/playground/client/assets/index-ByeGGedv.js +0 -1259
- 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 -113
- 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 -248
- 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,28 @@
|
|
|
1
|
+
//#region ../../internal/playground/dist/jobs/queue.js
|
|
2
|
+
const ENDED_STATES = /* @__PURE__ */ new Set([
|
|
3
|
+
"done",
|
|
4
|
+
"failed",
|
|
5
|
+
"cancelled"
|
|
6
|
+
]);
|
|
7
|
+
function hasEnded(job) {
|
|
8
|
+
return ENDED_STATES.has(job.state);
|
|
9
|
+
}
|
|
10
|
+
function jobAnswer(job) {
|
|
11
|
+
return {
|
|
12
|
+
id: job.id,
|
|
13
|
+
operation: job.operation,
|
|
14
|
+
subject: job.subject,
|
|
15
|
+
version: job.version,
|
|
16
|
+
state: job.state,
|
|
17
|
+
progress: job.progress,
|
|
18
|
+
log: job.log,
|
|
19
|
+
result: job.result,
|
|
20
|
+
error: job.error,
|
|
21
|
+
startedAt: job.startedAt,
|
|
22
|
+
runningAt: job.runningAt,
|
|
23
|
+
finishedAt: job.finishedAt
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
export { ENDED_STATES, hasEnded, jobAnswer };
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { hasEnded, jobAnswer } from "./queue.js";
|
|
2
|
+
import { fingerprintOf } from "../../../file-store/dist/files.js";
|
|
3
|
+
import { memoryJobQueue } from "./memory-queue.js";
|
|
4
|
+
|
|
5
|
+
//#region ../../internal/playground/dist/jobs/runner.js
|
|
6
|
+
var JobCancelled = class extends Error {
|
|
7
|
+
job;
|
|
8
|
+
constructor(job) {
|
|
9
|
+
super(`The job ${job} was cancelled.`);
|
|
10
|
+
this.job = job;
|
|
11
|
+
this.name = "JobCancelled";
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
async function inputsFingerprint(start) {
|
|
15
|
+
if (start.inputs !== void 0) return fingerprintOf(new TextEncoder().encode(JSON.stringify([start.operation, start.inputs])));
|
|
16
|
+
const { property, fixture, format, page, file } = start.subject;
|
|
17
|
+
return fingerprintOf(new TextEncoder().encode(JSON.stringify([
|
|
18
|
+
start.operation,
|
|
19
|
+
property ?? null,
|
|
20
|
+
fixture ?? null,
|
|
21
|
+
format ?? null,
|
|
22
|
+
page ?? null,
|
|
23
|
+
file ?? null,
|
|
24
|
+
start.version
|
|
25
|
+
])));
|
|
26
|
+
}
|
|
27
|
+
function createJobRunner(options) {
|
|
28
|
+
const queue = options.queue ?? memoryJobQueue();
|
|
29
|
+
const operations = new Map(options.operations.map((operation) => [operation.name, operation]));
|
|
30
|
+
if (operations.size !== options.operations.length) throw new Error("Two job operations share one name.");
|
|
31
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
32
|
+
const busy = /* @__PURE__ */ new Map();
|
|
33
|
+
const running = /* @__PURE__ */ new Map();
|
|
34
|
+
const waits = /* @__PURE__ */ new Set();
|
|
35
|
+
let closed = false;
|
|
36
|
+
function changed(job) {
|
|
37
|
+
if (job === null) return;
|
|
38
|
+
for (const listener of listeners) try {
|
|
39
|
+
listener(job);
|
|
40
|
+
} catch {}
|
|
41
|
+
}
|
|
42
|
+
function widthOf(lane) {
|
|
43
|
+
return options.widths[lane]?.value ?? 1;
|
|
44
|
+
}
|
|
45
|
+
async function pump(lane) {
|
|
46
|
+
while (!closed && (busy.get(lane) ?? 0) < widthOf(lane)) {
|
|
47
|
+
busy.set(lane, (busy.get(lane) ?? 0) + 1);
|
|
48
|
+
const job = await queue.claim(lane);
|
|
49
|
+
if (job === null) {
|
|
50
|
+
busy.set(lane, busy.get(lane) - 1);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
changed(job);
|
|
54
|
+
run(job).finally(() => {
|
|
55
|
+
busy.set(lane, busy.get(lane) - 1);
|
|
56
|
+
pump(lane);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async function run(job) {
|
|
61
|
+
const operation = operations.get(job.operation);
|
|
62
|
+
if (operation === void 0) {
|
|
63
|
+
changed(await queue.finish(job.id, {
|
|
64
|
+
state: "failed",
|
|
65
|
+
error: `No operation "${job.operation}" runs here.`
|
|
66
|
+
}));
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const controller = new AbortController();
|
|
70
|
+
running.set(job.id, controller);
|
|
71
|
+
const cap = options.timeCap;
|
|
72
|
+
const timer = cap === void 0 ? void 0 : setTimeout(() => {
|
|
73
|
+
queue.finish(job.id, {
|
|
74
|
+
state: "failed",
|
|
75
|
+
error: cap.reason
|
|
76
|
+
}).then((ended) => {
|
|
77
|
+
controller.abort();
|
|
78
|
+
changed(ended);
|
|
79
|
+
});
|
|
80
|
+
}, cap.ms);
|
|
81
|
+
const context = {
|
|
82
|
+
job,
|
|
83
|
+
signal: controller.signal,
|
|
84
|
+
report: async (report) => {
|
|
85
|
+
if (controller.signal.aborted) throw new JobCancelled(job.id);
|
|
86
|
+
const now = await queue.report(job.id, report);
|
|
87
|
+
changed(now);
|
|
88
|
+
if (now === null || now.state === "cancelled") {
|
|
89
|
+
controller.abort();
|
|
90
|
+
throw new JobCancelled(job.id);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
try {
|
|
95
|
+
const result = await operation.run(context);
|
|
96
|
+
if (!controller.signal.aborted) changed(await queue.finish(job.id, {
|
|
97
|
+
state: "done",
|
|
98
|
+
result
|
|
99
|
+
}));
|
|
100
|
+
} catch (err) {
|
|
101
|
+
if (!controller.signal.aborted) changed(await queue.finish(job.id, {
|
|
102
|
+
state: "failed",
|
|
103
|
+
error: err instanceof Error ? err.message : String(err)
|
|
104
|
+
}));
|
|
105
|
+
} finally {
|
|
106
|
+
clearTimeout(timer);
|
|
107
|
+
running.delete(job.id);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
async function readOf(template, id) {
|
|
111
|
+
const [job] = await queue.read({
|
|
112
|
+
template,
|
|
113
|
+
id
|
|
114
|
+
});
|
|
115
|
+
return job ?? null;
|
|
116
|
+
}
|
|
117
|
+
function waitFor(template, id, waitMs) {
|
|
118
|
+
return new Promise((resolve, reject) => {
|
|
119
|
+
let seen = null;
|
|
120
|
+
let settled = false;
|
|
121
|
+
const settle = () => {
|
|
122
|
+
if (settled) return;
|
|
123
|
+
settled = true;
|
|
124
|
+
clearTimeout(timer);
|
|
125
|
+
stop();
|
|
126
|
+
waits.delete(settle);
|
|
127
|
+
readOf(template, id).then(resolve, reject);
|
|
128
|
+
};
|
|
129
|
+
const timer = setTimeout(settle, waitMs);
|
|
130
|
+
const stop = onChange((job) => {
|
|
131
|
+
if (job.id === id && (seen === null || JSON.stringify(jobAnswer(job)) !== seen)) settle();
|
|
132
|
+
});
|
|
133
|
+
waits.add(settle);
|
|
134
|
+
readOf(template, id).then((job) => {
|
|
135
|
+
if (job === null || hasEnded(job)) settle();
|
|
136
|
+
else seen ??= JSON.stringify(jobAnswer(job));
|
|
137
|
+
}, reject);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
function onChange(listener) {
|
|
141
|
+
listeners.add(listener);
|
|
142
|
+
return () => listeners.delete(listener);
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
scope(template) {
|
|
146
|
+
return {
|
|
147
|
+
async start(start) {
|
|
148
|
+
if (closed) throw new Error("The job runner is closed.");
|
|
149
|
+
const operation = operations.get(start.operation);
|
|
150
|
+
if (operation === void 0) throw new Error(`No operation "${start.operation}" runs here.`);
|
|
151
|
+
const answer = await queue.start({
|
|
152
|
+
template,
|
|
153
|
+
operation: operation.name,
|
|
154
|
+
lane: operation.takes,
|
|
155
|
+
subject: start.subject,
|
|
156
|
+
version: start.version,
|
|
157
|
+
fingerprint: operation.joins ? await inputsFingerprint(start) : null,
|
|
158
|
+
replaces: operation.replaces === true
|
|
159
|
+
});
|
|
160
|
+
if (!answer.joined) {
|
|
161
|
+
if (operation.replaces === true) {
|
|
162
|
+
for (const job of await queue.read({ template })) if (job.state === "cancelled") changed(job);
|
|
163
|
+
}
|
|
164
|
+
changed(answer.job);
|
|
165
|
+
pump(operation.takes);
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
job: jobAnswer(answer.job),
|
|
169
|
+
joined: answer.joined
|
|
170
|
+
};
|
|
171
|
+
},
|
|
172
|
+
async joins(start) {
|
|
173
|
+
const operation = operations.get(start.operation);
|
|
174
|
+
if (operation === void 0 || !operation.joins) return false;
|
|
175
|
+
const fingerprint = await inputsFingerprint(start);
|
|
176
|
+
return (await queue.read({ template })).some((job) => job.fingerprint === fingerprint && !hasEnded(job));
|
|
177
|
+
},
|
|
178
|
+
async list() {
|
|
179
|
+
return (await queue.read({ template })).map(jobAnswer);
|
|
180
|
+
},
|
|
181
|
+
async read(id, waitMs) {
|
|
182
|
+
const job = waitMs === void 0 || waitMs <= 0 ? await readOf(template, id) : await waitFor(template, id, waitMs);
|
|
183
|
+
return job === null ? null : jobAnswer(job);
|
|
184
|
+
},
|
|
185
|
+
async cancel(id) {
|
|
186
|
+
if (await readOf(template, id) === null) return null;
|
|
187
|
+
const job = await queue.cancel(id);
|
|
188
|
+
running.get(id)?.abort();
|
|
189
|
+
changed(job);
|
|
190
|
+
return job === null ? null : jobAnswer(job);
|
|
191
|
+
},
|
|
192
|
+
mark: (operation) => operations.get(operation)?.mark,
|
|
193
|
+
takes: (operation) => operations.get(operation)?.takes
|
|
194
|
+
};
|
|
195
|
+
},
|
|
196
|
+
onChange,
|
|
197
|
+
close() {
|
|
198
|
+
closed = true;
|
|
199
|
+
for (const controller of running.values()) controller.abort();
|
|
200
|
+
for (const settle of [...waits]) settle();
|
|
201
|
+
return Promise.resolve();
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
//#endregion
|
|
207
|
+
export { JobCancelled, createJobRunner };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PLAYGROUND_CLIENT_DIR, PLAYGROUND_DIR } from "../../template-artifact/dist/layout.js";
|
|
2
|
+
import "../../template-artifact/dist/index.js";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
|
|
5
|
+
//#region ../../internal/playground/dist/layout.js
|
|
6
|
+
function playgroundDistDir(packageRoot) {
|
|
7
|
+
return resolve(packageRoot, "dist", "artifact", PLAYGROUND_DIR);
|
|
8
|
+
}
|
|
9
|
+
function playgroundClientDir(playgroundDir) {
|
|
10
|
+
return resolve(playgroundDir, PLAYGROUND_CLIENT_DIR);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
export { playgroundClientDir, playgroundDistDir };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import nodePath from "node:path";
|
|
2
|
+
import { rename, rm } from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
//#region ../../internal/playground/dist/platform.js
|
|
5
|
+
function isInsideRoot(root, file) {
|
|
6
|
+
const rel = nodePath.relative(root, file);
|
|
7
|
+
return rel !== "" && rel !== ".." && !rel.startsWith(`..${nodePath.sep}`) && !nodePath.isAbsolute(rel);
|
|
8
|
+
}
|
|
9
|
+
async function removeTree(path) {
|
|
10
|
+
await rm(path, {
|
|
11
|
+
recursive: true,
|
|
12
|
+
force: true,
|
|
13
|
+
maxRetries: process.platform === "win32" ? 10 : 0,
|
|
14
|
+
retryDelay: 100
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
const TRANSIENT_LOCKS = /* @__PURE__ */ new Set([
|
|
18
|
+
"EPERM",
|
|
19
|
+
"EACCES",
|
|
20
|
+
"EBUSY"
|
|
21
|
+
]);
|
|
22
|
+
async function replaceFile(from, to) {
|
|
23
|
+
for (let attempt = 0;; attempt++) try {
|
|
24
|
+
await rename(from, to);
|
|
25
|
+
return;
|
|
26
|
+
} catch (cause) {
|
|
27
|
+
if (process.platform !== "win32" || !TRANSIENT_LOCKS.has(cause.code) || attempt >= 10) throw cause;
|
|
28
|
+
await new Promise((settle) => setTimeout(settle, 100 * (attempt + 1)));
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { isInsideRoot, removeTree, replaceFile };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import "../../../template-artifact/dist/layout.js";
|
|
2
|
+
import { CHANGE_EVENTS } from "../wire.js";
|
|
3
|
+
import { jobAnswer } from "../jobs/queue.js";
|
|
4
|
+
|
|
5
|
+
//#region ../../internal/playground/dist/server/changes.js
|
|
6
|
+
const HEARTBEAT_MS = 25e3;
|
|
7
|
+
function changeChannel() {
|
|
8
|
+
const pages = /* @__PURE__ */ new Map();
|
|
9
|
+
let heartbeat = null;
|
|
10
|
+
const every = function* () {
|
|
11
|
+
for (const open of pages.values()) yield* open;
|
|
12
|
+
};
|
|
13
|
+
const send = (template, event, data) => {
|
|
14
|
+
const text = `event: ${event}\ndata: ${JSON.stringify(data)}\n\n`;
|
|
15
|
+
for (const res of pages.get(template) ?? []) res.write(text);
|
|
16
|
+
};
|
|
17
|
+
const detach = (template, res) => {
|
|
18
|
+
const open = pages.get(template);
|
|
19
|
+
open?.delete(res);
|
|
20
|
+
if (open?.size === 0) pages.delete(template);
|
|
21
|
+
if (pages.size === 0 && heartbeat !== null) {
|
|
22
|
+
clearInterval(heartbeat);
|
|
23
|
+
heartbeat = null;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
scope: (template) => ({
|
|
28
|
+
attach(res) {
|
|
29
|
+
res.writeHead(200, {
|
|
30
|
+
"content-type": "text/event-stream",
|
|
31
|
+
"cache-control": "no-cache",
|
|
32
|
+
connection: "keep-alive",
|
|
33
|
+
"x-accel-buffering": "no"
|
|
34
|
+
});
|
|
35
|
+
res.write(": hello\n\n");
|
|
36
|
+
let open = pages.get(template);
|
|
37
|
+
if (open === void 0) pages.set(template, open = /* @__PURE__ */ new Set());
|
|
38
|
+
open.add(res);
|
|
39
|
+
res.on("close", () => detach(template, res));
|
|
40
|
+
heartbeat ??= setInterval(() => {
|
|
41
|
+
for (const page of every()) page.write(": still here\n\n");
|
|
42
|
+
}, HEARTBEAT_MS).unref();
|
|
43
|
+
},
|
|
44
|
+
moved: (change) => send(template, CHANGE_EVENTS.files, change)
|
|
45
|
+
}),
|
|
46
|
+
follow: (runner) => runner.onChange((job) => send(job.template, CHANGE_EVENTS.job, jobAnswer(job))),
|
|
47
|
+
close() {
|
|
48
|
+
for (const res of [...every()]) res.end();
|
|
49
|
+
pages.clear();
|
|
50
|
+
if (heartbeat !== null) clearInterval(heartbeat);
|
|
51
|
+
heartbeat = null;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
export { changeChannel };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SHARE_IMAGE } from "../../../site-files/dist/site.js";
|
|
2
|
+
import "../../../site-files/dist/index.js";
|
|
3
|
+
import { CROP_PARAM, croppedUrl, cutRegion as cutRegion$1, encodeMatchingFormat, formatToContentType, parseCropParam } from "../../../crop-region/dist/index.js";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
|
|
6
|
+
//#region ../../internal/playground/dist/server/crop.js
|
|
7
|
+
function croppedMediaUrl(url, rect) {
|
|
8
|
+
return croppedUrl(url, rect);
|
|
9
|
+
}
|
|
10
|
+
const CUT_CODE = createHash("sha256").update([
|
|
11
|
+
cutRegion$1,
|
|
12
|
+
encodeMatchingFormat,
|
|
13
|
+
formatToContentType
|
|
14
|
+
].map(String).join("\n")).digest("hex");
|
|
15
|
+
function cropFingerprint(masterFingerprint, rect) {
|
|
16
|
+
return createHash("sha256").update([
|
|
17
|
+
"crop",
|
|
18
|
+
CUT_CODE,
|
|
19
|
+
masterFingerprint,
|
|
20
|
+
rect.nx,
|
|
21
|
+
rect.ny,
|
|
22
|
+
rect.nw,
|
|
23
|
+
rect.nh
|
|
24
|
+
].join("|")).digest("hex");
|
|
25
|
+
}
|
|
26
|
+
async function defaultLoadSharp() {
|
|
27
|
+
try {
|
|
28
|
+
return (await import("sharp")).default;
|
|
29
|
+
} catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function shareImageCutter(loadSharp = defaultLoadSharp) {
|
|
34
|
+
const sharp = await loadSharp();
|
|
35
|
+
if (sharp === null) return null;
|
|
36
|
+
return async (bytes, size) => sharp(bytes).resize(size.width, size.height, {
|
|
37
|
+
fit: "cover",
|
|
38
|
+
position: SHARE_IMAGE.position
|
|
39
|
+
}).jpeg({ quality: SHARE_IMAGE.quality }).toBuffer();
|
|
40
|
+
}
|
|
41
|
+
async function cutRegion(master, rect, loadSharp = defaultLoadSharp) {
|
|
42
|
+
const sharp = await loadSharp();
|
|
43
|
+
return sharp === null ? null : cutRegion$1(sharp, master, rect);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//#endregion
|
|
47
|
+
export { CROP_PARAM, cropFingerprint, croppedMediaUrl, cutRegion, parseCropParam, shareImageCutter };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { removeTree, replaceFile } from "../platform.js";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { mkdir, readFile, readdir, stat, utimes, writeFile } from "node:fs/promises";
|
|
4
|
+
|
|
5
|
+
//#region ../../internal/playground/dist/server/derived-files.js
|
|
6
|
+
const DERIVED_FILE_IDLE_MS = 720 * 60 * 60 * 1e3;
|
|
7
|
+
const DROP_EVERY_MS = 1440 * 60 * 1e3;
|
|
8
|
+
const FINGERPRINT = /^[0-9a-f]{16,128}$/;
|
|
9
|
+
const TEMP_SUFFIX = ".tmp";
|
|
10
|
+
function entryPath(dir, fingerprint) {
|
|
11
|
+
if (!FINGERPRINT.test(fingerprint)) throw new Error(`"${fingerprint}" is not a derived file's fingerprint.`);
|
|
12
|
+
return join(dir, fingerprint.slice(0, 2), fingerprint);
|
|
13
|
+
}
|
|
14
|
+
function derivedFolder(dir, options = {}) {
|
|
15
|
+
const idleMs = options.idleMs ?? 2592e6;
|
|
16
|
+
const now = options.now ?? Date.now;
|
|
17
|
+
async function drop() {
|
|
18
|
+
const cutoff = now() - idleMs;
|
|
19
|
+
let dropped = 0;
|
|
20
|
+
let shards;
|
|
21
|
+
try {
|
|
22
|
+
shards = await readdir(dir);
|
|
23
|
+
} catch {
|
|
24
|
+
return 0;
|
|
25
|
+
}
|
|
26
|
+
for (const shard of shards) {
|
|
27
|
+
let names;
|
|
28
|
+
try {
|
|
29
|
+
names = await readdir(join(dir, shard));
|
|
30
|
+
} catch {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
for (const name of names) {
|
|
34
|
+
const path = join(dir, shard, name);
|
|
35
|
+
try {
|
|
36
|
+
if ((await stat(path)).mtimeMs >= cutoff) continue;
|
|
37
|
+
await removeTree(path);
|
|
38
|
+
if (!name.endsWith(TEMP_SUFFIX)) dropped += 1;
|
|
39
|
+
} catch {}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return dropped;
|
|
43
|
+
}
|
|
44
|
+
const timer = options.dropOnTimer === false ? null : setInterval(() => void drop(), DROP_EVERY_MS);
|
|
45
|
+
timer?.unref();
|
|
46
|
+
if (timer !== null) drop();
|
|
47
|
+
return {
|
|
48
|
+
async kept(fingerprint) {
|
|
49
|
+
const path = entryPath(dir, fingerprint);
|
|
50
|
+
let raw;
|
|
51
|
+
try {
|
|
52
|
+
raw = await readFile(path);
|
|
53
|
+
} catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const newline = raw.indexOf(10);
|
|
57
|
+
if (newline <= 0) return null;
|
|
58
|
+
try {
|
|
59
|
+
const at = new Date(now());
|
|
60
|
+
await utimes(path, at, at);
|
|
61
|
+
} catch {}
|
|
62
|
+
return {
|
|
63
|
+
contentType: raw.subarray(0, newline).toString("utf8"),
|
|
64
|
+
bytes: new Uint8Array(raw.subarray(newline + 1))
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
async keep(fingerprint, file) {
|
|
68
|
+
const path = entryPath(dir, fingerprint);
|
|
69
|
+
if (file.contentType.includes("\n")) throw new Error(`"${file.contentType}" is not a content type.`);
|
|
70
|
+
await mkdir(join(path, ".."), { recursive: true });
|
|
71
|
+
const temp = `${path}.${String(process.pid)}-${Math.random().toString(36).slice(2)}${TEMP_SUFFIX}`;
|
|
72
|
+
try {
|
|
73
|
+
await writeFile(temp, Buffer.concat([Buffer.from(`${file.contentType}\n`, "utf8"), file.bytes]));
|
|
74
|
+
await replaceFile(temp, path);
|
|
75
|
+
} catch (err) {
|
|
76
|
+
await removeTree(temp);
|
|
77
|
+
throw err;
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
drop,
|
|
81
|
+
close() {
|
|
82
|
+
if (timer !== null) clearInterval(timer);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
export { DERIVED_FILE_IDLE_MS, derivedFolder };
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { attachmentDisposition, correctedDownloadLocation } from "../host/download.js";
|
|
2
|
+
import { makeDownloadFiles } from "../../../download-files/dist/make.js";
|
|
3
|
+
import "../../../download-files/dist/files.js";
|
|
4
|
+
import { RequestError, sendBytes, sendText } from "./http.js";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
import { Readable } from "node:stream";
|
|
7
|
+
|
|
8
|
+
//#region ../../internal/playground/dist/server/download.js
|
|
9
|
+
const DOWNLOAD_OPERATION = "download";
|
|
10
|
+
const DOWNLOAD_WAIT_MS = 6e4;
|
|
11
|
+
const ASK_AGAIN_SECONDS = 5;
|
|
12
|
+
function downloadFingerprint(input, mediaFingerprints, code) {
|
|
13
|
+
const made = [
|
|
14
|
+
DOWNLOAD_OPERATION,
|
|
15
|
+
code,
|
|
16
|
+
input.output,
|
|
17
|
+
input.shoot,
|
|
18
|
+
input.format,
|
|
19
|
+
input.pages,
|
|
20
|
+
input.media.map((media, index) => [
|
|
21
|
+
media.path,
|
|
22
|
+
media.contentType,
|
|
23
|
+
mediaFingerprints[index] ?? null
|
|
24
|
+
]),
|
|
25
|
+
input.binding,
|
|
26
|
+
input.naming,
|
|
27
|
+
input.bases,
|
|
28
|
+
input.file
|
|
29
|
+
];
|
|
30
|
+
return createHash("sha256").update(JSON.stringify(made)).digest("hex");
|
|
31
|
+
}
|
|
32
|
+
function answeredFile(files, input) {
|
|
33
|
+
const { file } = input;
|
|
34
|
+
const found = files.find((made) => made.mime === file.contentType && (file.page === null || made.pageId === file.page));
|
|
35
|
+
if (found === void 0) throw new Error(`The download was made without its ${file.contentType === "image/png" ? `image of the page "${file.page ?? ""}"` : file.contentType}.`);
|
|
36
|
+
return found;
|
|
37
|
+
}
|
|
38
|
+
function downloadOperation(host) {
|
|
39
|
+
return {
|
|
40
|
+
name: DOWNLOAD_OPERATION,
|
|
41
|
+
takes: "browser",
|
|
42
|
+
mark: "Preparing download",
|
|
43
|
+
joins: true,
|
|
44
|
+
async run({ job, report }) {
|
|
45
|
+
const { property, fixture, format, page } = job.subject;
|
|
46
|
+
if (property === void 0 || fixture === void 0) throw new Error("A download names the property and the content fixture it is of.");
|
|
47
|
+
const served = await host.served(job.template);
|
|
48
|
+
if (served === null) throw new Error("Nothing serves this template now, so its download cannot be made.");
|
|
49
|
+
const input = await served.input({
|
|
50
|
+
property,
|
|
51
|
+
fixture,
|
|
52
|
+
format: format ?? null,
|
|
53
|
+
page: page ?? null
|
|
54
|
+
});
|
|
55
|
+
const fingerprint = await served.fingerprint(input);
|
|
56
|
+
if (await host.derived.kept(fingerprint) !== null) return { file: fingerprint };
|
|
57
|
+
const pages = input.pages.length;
|
|
58
|
+
await report({ log: `Shooting ${String(pages)} ${pages === 1 ? "page" : "pages"} of ${fixture} at ${input.format.id}.` });
|
|
59
|
+
const started = Date.now();
|
|
60
|
+
const made = answeredFile(await makeDownloadFiles({
|
|
61
|
+
output: input.output,
|
|
62
|
+
shoot: input.shoot,
|
|
63
|
+
format: input.format,
|
|
64
|
+
pages: input.pages.map((p) => ({
|
|
65
|
+
id: p.id,
|
|
66
|
+
sectionHtml: p.sectionHtml,
|
|
67
|
+
...p.direction === void 0 ? {} : { direction: p.direction }
|
|
68
|
+
})),
|
|
69
|
+
media: input.media.map((media) => ({
|
|
70
|
+
source_key: media.url,
|
|
71
|
+
r2_path: media.path,
|
|
72
|
+
content_type: media.contentType
|
|
73
|
+
})),
|
|
74
|
+
binding: input.binding,
|
|
75
|
+
naming: input.naming,
|
|
76
|
+
bases: input.bases,
|
|
77
|
+
reads: served.reads,
|
|
78
|
+
browser: host.browser,
|
|
79
|
+
log: host.log ?? {
|
|
80
|
+
info: () => void 0,
|
|
81
|
+
warn: () => void 0,
|
|
82
|
+
error: () => void 0
|
|
83
|
+
}
|
|
84
|
+
}), input);
|
|
85
|
+
await report({
|
|
86
|
+
progress: `Made ${input.file.name}`,
|
|
87
|
+
log: `Made ${String(made.bytes.byteLength)} bytes in ${String(Date.now() - started)} ms.`
|
|
88
|
+
});
|
|
89
|
+
await host.derived.keep(fingerprint, {
|
|
90
|
+
contentType: input.file.contentType,
|
|
91
|
+
bytes: made.bytes
|
|
92
|
+
});
|
|
93
|
+
return { file: fingerprint };
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function storedBytes(bytes, contentType) {
|
|
98
|
+
return {
|
|
99
|
+
body: Readable.from([Buffer.from(bytes)]),
|
|
100
|
+
contentLength: bytes.byteLength,
|
|
101
|
+
...contentType === void 0 ? {} : { contentType }
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function refusalStatus(err) {
|
|
105
|
+
if (typeof err !== "object" || err === null) return null;
|
|
106
|
+
const status = err.status;
|
|
107
|
+
return typeof status === "number" && Number.isInteger(status) && status >= 400 && status < 600 ? status : null;
|
|
108
|
+
}
|
|
109
|
+
function sendFile(res, input, bytes) {
|
|
110
|
+
res.setHeader("content-disposition", attachmentDisposition(input.file.name));
|
|
111
|
+
res.setHeader("cache-control", "no-cache");
|
|
112
|
+
sendBytes(res, input.file.contentType, bytes);
|
|
113
|
+
}
|
|
114
|
+
function sameSubject(job, subject) {
|
|
115
|
+
return job.subject.property === subject.property && job.subject.fixture === subject.fixture && job.subject.format === subject.format && job.subject.page === subject.page;
|
|
116
|
+
}
|
|
117
|
+
async function answerDownload(host, method, url, ask, res) {
|
|
118
|
+
if (method !== "GET" && method !== "HEAD") throw new RequestError(405, `${url.pathname} only reads; GET it to download.`);
|
|
119
|
+
try {
|
|
120
|
+
const input = await host.downloads.input(ask);
|
|
121
|
+
if (input.subject.property !== ask.property) {
|
|
122
|
+
res.statusCode = 308;
|
|
123
|
+
res.setHeader("location", correctedDownloadLocation(url, ask.property, input.subject.property));
|
|
124
|
+
res.end();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const fingerprint = await host.downloads.fingerprint(input);
|
|
128
|
+
const kept = await host.derived.kept(fingerprint);
|
|
129
|
+
if (kept !== null) return sendFile(res, input, kept.bytes);
|
|
130
|
+
if (host.jobs?.mark("download") === void 0) throw new RequestError(501, "This playground makes no downloads: it runs no browser.");
|
|
131
|
+
const started = await host.jobs.start({
|
|
132
|
+
operation: DOWNLOAD_OPERATION,
|
|
133
|
+
subject: input.subject,
|
|
134
|
+
version: await host.version(),
|
|
135
|
+
inputs: fingerprint
|
|
136
|
+
});
|
|
137
|
+
const deadline = Date.now() + (host.waitMs ?? 6e4);
|
|
138
|
+
let job = started.job;
|
|
139
|
+
while (job !== null && (job.state === "waiting" || job.state === "running") && Date.now() < deadline) job = await host.jobs.read(job.id, deadline - Date.now());
|
|
140
|
+
if (job === null || !sameSubject(job, input.subject)) throw new RequestError(500, "The download's job is gone; ask again.");
|
|
141
|
+
if (job.state === "failed") return sendText(res, 500, `The download failed: ${job.error ?? "it gave no reason"}`);
|
|
142
|
+
if (job.state === "cancelled") return sendText(res, 409, `The download's job ${job.id} was cancelled; ask again to start another.`);
|
|
143
|
+
if (job.state !== "done") {
|
|
144
|
+
res.setHeader("retry-after", String(ASK_AGAIN_SECONDS));
|
|
145
|
+
return sendText(res, 202, `The download is not ready yet (job ${job.id}, ${job.progress ?? job.state}); ask again, which joins the same job.`);
|
|
146
|
+
}
|
|
147
|
+
const made = job.result !== null && "file" in job.result ? await host.derived.kept(job.result.file) : null;
|
|
148
|
+
if (made === null) throw new RequestError(500, "The download was made but could not be kept; ask again to make it again.");
|
|
149
|
+
sendFile(res, input, made.bytes);
|
|
150
|
+
} catch (err) {
|
|
151
|
+
const status = refusalStatus(err);
|
|
152
|
+
if (status === null || res.headersSent) throw err;
|
|
153
|
+
sendText(res, status, err instanceof Error ? err.message : String(err));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
//#endregion
|
|
158
|
+
export { DOWNLOAD_OPERATION, DOWNLOAD_WAIT_MS, answerDownload, downloadFingerprint, downloadOperation, storedBytes };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { extname } from "node:path";
|
|
2
|
-
import { readFile } from "node:fs/promises";
|
|
3
2
|
|
|
4
|
-
//#region
|
|
3
|
+
//#region ../../internal/playground/dist/server/http.js
|
|
5
4
|
const MIME = {
|
|
6
5
|
".js": "text/javascript; charset=utf-8",
|
|
7
6
|
".mjs": "text/javascript; charset=utf-8",
|
|
@@ -84,15 +83,8 @@ function parseByteRange(header, size) {
|
|
|
84
83
|
end
|
|
85
84
|
};
|
|
86
85
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
try {
|
|
90
|
-
buf = await readFile(path);
|
|
91
|
-
} catch {
|
|
92
|
-
sendText(res, 404, "not found");
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
res.setHeader("content-type", contentTypeFor(path));
|
|
86
|
+
function sendBody(req, res, contentType, buf) {
|
|
87
|
+
res.setHeader("content-type", contentType);
|
|
96
88
|
res.setHeader("accept-ranges", "bytes");
|
|
97
89
|
const range = parseByteRange(req.headers.range, buf.byteLength);
|
|
98
90
|
if (range === "unsatisfiable") {
|
|
@@ -113,4 +105,4 @@ async function sendFile(req, res, path) {
|
|
|
113
105
|
}
|
|
114
106
|
|
|
115
107
|
//#endregion
|
|
116
|
-
export { RequestError, contentTypeFor, parseByteRange, readBody,
|
|
108
|
+
export { RequestError, contentTypeFor, parseByteRange, readBody, sendBody, sendBytes, sendHtml, sendText };
|