"use strict";
/**
 * Copyright: (c) Myia SAS 2026.
 * This file and its contents are licensed under the AGPLv3 License.
 * Please see the LICENSE file at the root of this repository
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.SCHEMA_VERSION = exports.clock = exports.getStartedAt = exports.getCurrentStepPath = exports.getCurrentStatementSeq = exports.setExporter = exports.setCurrentStatementScreenshot = exports.popStep = exports.pushStep = exports.setPage = exports.setContext = exports.reset = void 0;
// Composition root for the process-wide trace-event-recorder singleton.
//
// `domain/.../factory.ts` exports the `TraceEventRecorder` class —
// a pure service that requires exporter + clock + staticContext. This
// file is the thin wrapper that:
//
//   1. Wires the default Clock (PerfHooksClock) and the default
//      SystemInfoProvider (SystemInfoAdapter — reads pid/os/git).
//   2. Builds one trace-event-recorder wired to `BOOTSTRAP_EXPORTER`
//      (a no-op that silently swallows any events fired before the
//      fixture swaps in a real projector via `setExporter(...)` at
//      the start of every test).
//   3. Installs `globalThis.__heal_enter/__heal_ok/__heal_throw` so the
//      Babel-inserted calls find them at runtime.
//   4. Re-exports the public API (`reset`, `setContext`, `setPage`,
//      `pushStep`, `popStep`, `setCurrentStatementScreenshot`,
//      `setExporter`) for the fixture and infrastructure adapters to
//      import. The singleton shape is the integration surface between
//      the always-on domain recorder and the per-test fixture.
//
// Tests do NOT import this file — they import the domain factory
// directly and inject stubs + a fake clock.
const service_1 = require("../../domain/trace-event-recorder/service");
Object.defineProperty(exports, "SCHEMA_VERSION", { enumerable: true, get: function () { return service_1.SCHEMA_VERSION; } });
const perf_hooks_clock_adapter_1 = require("../../infrastructure/perf-hooks-clock-adapter");
const system_info_adapter_1 = require("../../infrastructure/system-info-adapter");
const global_names_1 = require("../../domain/trace-event-recorder/model/global-names");
// See the header comment: the recorder is constructed at module load
// and MUST have an exporter from that moment so any pre-fixture
// `__heal_enter` call doesn't crash. The fixture replaces this with
// the real per-test projector via `setExporter(...)`.
const BOOTSTRAP_EXPORTER = {
    write() { },
    clear() { },
};
const systemInfo = new system_info_adapter_1.SystemInfoAdapter().getStaticContext();
const staticContext = {
    schemaVersion: service_1.SCHEMA_VERSION,
    ...systemInfo,
};
const traceEventRecorder = new service_1.TraceEventRecorder({
    exporter: BOOTSTRAP_EXPORTER,
    clock: new perf_hooks_clock_adapter_1.PerfHooksClock(),
    staticContext,
});
// Global-name contract lives in `domain/.../model/global-names.ts`,
// shared with the Babel plugin that emits calls to these names. The
// factory's internal method names (`__enter`, `__ok`, `__throw`) are
// unchanged — they never leak into user-facing code.
const g = globalThis;
g[global_names_1.HEAL_ENTER] = traceEventRecorder.__enter;
g[global_names_1.HEAL_OK] = traceEventRecorder.__ok;
g[global_names_1.HEAL_THROW] = traceEventRecorder.__throw;
exports.reset = traceEventRecorder.reset;
exports.setContext = traceEventRecorder.setContext;
exports.setPage = traceEventRecorder.setPage;
exports.pushStep = traceEventRecorder.pushStep;
exports.popStep = traceEventRecorder.popStep;
exports.setCurrentStatementScreenshot = traceEventRecorder.setCurrentStatementScreenshot;
exports.setExporter = traceEventRecorder.setExporter;
// Read accessors for sidecar adapters (network, console). These
// expose just enough of the recorder's runtime state for the
// adapters to correlate an out-of-band Playwright event with the
// statement that triggered it, without giving them a reference to
// the recorder itself.
exports.getCurrentStatementSeq = traceEventRecorder.getCurrentStatementSeq;
exports.getCurrentStepPath = traceEventRecorder.getCurrentStepPath;
exports.getStartedAt = traceEventRecorder.getStartedAt;
/** The recorder's monotonic clock — sidecar adapters use it to compute `t = now() - startedAt`. */
exports.clock = traceEventRecorder.clock;
