Setu-TS
    Preparing search index...

    Interface IRuntimeServices

    Runtime services — every runtime-specific operation the framework needs, abstracted behind one interface. Registered under CAPABILITIES.RUNTIME by the RuntimePlugin, which is mandatory in every application.

    const runtime = ctx.services.get<IRuntimeServices>(CAPABILITIES.RUNTIME);
    const requestId = runtime.uuid();

    0.1.0

    interface IRuntimeServices {
        dns?: IDnsResolver;
        env: Readonly<Record<string, string | undefined>>;
        fs?: IFileSystem;
        subtle: SubtleCrypto;
        workers?: IWorkerHost;
        clearInterval(handle: unknown): void;
        clearTimeout(handle: unknown): void;
        exit(code?: number): never;
        hostname(): string;
        hrtime(): number;
        now(): number;
        onSignal?(signal: RuntimeSignal, handler: () => void): void;
        platform(): RuntimePlatform;
        randomBytes(length: number): Uint8Array;
        reportError?(record: Readonly<Record<string, unknown>>): void;
        setInterval(fn: () => void, ms: number): unknown;
        setTimeout(fn: () => void, ms: number): unknown;
        uuid(): string;
        version(): string;
    }
    Index

    DNS resolution; absent on runtimes with no resolver API (edge platforms).

    Cloudflare Workers omits this key entirely — its network access is fetch, which resolves names internally and exposes no lookup surface.

    0.2.0

    env: Readonly<Record<string, string | undefined>>

    Environment variables. Always read env through this, never process.env.

    Treat it as a snapshot taken when the runtime services were created: the Deno adapter materializes Deno.env.toObject() and the Workers adapter receives a per-invocation bindings object, so neither reflects a variable set after startup. (The Node and Bun adapters pass process.env through, which does.) Nothing in the framework mutates the environment at runtime.

    File system access; absent on runtimes without one (edge platforms).

    subtle: SubtleCrypto

    Web Crypto SubtleCrypto for cryptographic operations.

    workers?: IWorkerHost

    Worker-thread spawning; absent on runtimes without threads (edge platforms).

    • Terminates the process.

      Parameters

      • Optionalcode: number

        Exit code (defaults to 0)

      Returns never

      Never returns

    • Returns a high-resolution monotonic timestamp in milliseconds, suitable for measuring durations.

      Returns number

      Monotonic milliseconds

    • Returns the current wall-clock time in milliseconds since the epoch.

      Returns number

      Milliseconds since the Unix epoch

    • Registers a handler for a process-termination signal, so an application can run app.stop() before the process dies.

      Without this, an application catching SIGTERM has to reach for Deno.addSignalListener or process.on directly — a runtime API in application code, which is what AI_GUIDELINES §4.2 exists to prevent, and which forces a different entry point per target.

      Absent on two platforms, for two different reasons. Cloudflare Workers omits the key entirely: an isolate is evicted, never signalled, so there is nothing to register for. The Deno adapter omits it on Windows, where Deno.addSignalListener('SIGTERM') throws — so a caller must treat this as optional (runtime.onSignal?.(…)) rather than assuming a non-edge runtime always provides it.

      Handlers are additive: registering twice for one signal runs both, in registration order. The framework never removes them — a process that has received a termination signal is ending.

      Parameters

      • signal: RuntimeSignal

        The signal to listen for

      • handler: () => void

        Invoked when the signal arrives; must not throw

      Returns void

      runtime.onSignal?.('SIGTERM', () => {
      void app.stop().then(() => runtime.exit(0));
      });

      0.3.0

    • Generates cryptographically secure random bytes.

      Parameters

      • length: number

        Number of bytes

      Returns Uint8Array

      The random bytes

    • Last-resort error sink: writes one JSON line to standard error (the log channel on Workers). Serialization and write failures never escape.

      Parameters

      • record: Readonly<Record<string, unknown>>

        The already sanitized diagnostic

      Returns void

      0.10.0

    • Schedules a repeating callback.

      Parameters

      • fn: () => void

        Callback to invoke

      • ms: number

        Interval in milliseconds

      Returns unknown

      Handle for clearInterval

    • Schedules a one-shot callback.

      Parameters

      • fn: () => void

        Callback to invoke

      • ms: number

        Delay in milliseconds

      Returns unknown

      Handle for clearTimeout