← Files RivetARCHIVED FILE

node_modules/rivet-design/dist/services/StaticLibraryPreviews.js

2.42 KB · Nov 7, 2026 · 13:16 UTC

↓ Download file

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.StaticLibraryPreviews = void 0;
const libraryErrors_1 = require("./libraryErrors");
const path_1 = __importDefault(require("path"));
const http_1 = require("../library/http");
class StaticLibraryPreviews {
    library;
    startPreview;
    previews = new Map();
    constructor(library, startPreview) {
        this.library = library;
        this.startPreview = startPreview;
    }
    async url(reference) {
        const found = await this.library.variant(reference);
        if (!found || !found.detail.hasStaticPreview)
            throw new libraryErrors_1.LibraryError('preview_unavailable', 'This direction requires an interactive workspace preview');
        const { manifest, variantDir } = found.detail;
        let root;
        let entryPath;
        if (manifest.tree && manifest.serve?.kind === 'static') {
            root = await found.history.store.extractToCache({
                projectPath: found.projectPath,
                treeSha: manifest.tree.treeSha,
                commitish: manifest.tree.commitSha,
            });
            entryPath = manifest.serve.entryPath;
        }
        else if (manifest.preview.kind === 'static') {
            root = path_1.default.join(variantDir, manifest.preview.rootPath);
            entryPath = manifest.preview.entryPath;
        }
        else {
            throw new libraryErrors_1.LibraryError('preview_unavailable', 'This direction has no saved static preview');
        }
        const key = JSON.stringify([reference, root]);
        let pending = this.previews.get(key);
        if (!pending) {
            pending = this.startPreview(root);
            this.previews.set(key, pending);
            void pending.catch(() => this.previews.delete(key));
        }
        return `${(await pending).url}/${entryPath.split('/').map(encodeURIComponent).join('/')}`;
    }
    async close() {
        const previews = await Promise.allSettled(this.previews.values());
        await Promise.all(previews.flatMap((preview) => preview.status === 'fulfilled'
            ? [(0, http_1.closeListener)(preview.value.server)]
            : []));
        this.previews.clear();
    }
}
exports.StaticLibraryPreviews = StaticLibraryPreviews;
//# sourceMappingURL=StaticLibraryPreviews.js.map

SHA-256: 80601152e017ca6b1744d256fecec92669a099e0a94c0eec4968f5de8f3eb0d2