'use strict';

var chunk67M7TOOV_cjs = require('./chunk-67M7TOOV.cjs');
var chunkAF3E2D32_cjs = require('./chunk-AF3E2D32.cjs');

// src/prepare/runtime/runtime/shared/response.ts
function writeResponse() {
  return `${chunk67M7TOOV_cjs.getFileHeader()}

import type { IStormResponse } from "@storm-stack/types/response";
import { isStormError, StormError } from "./error";
import { useStorm } from "./context";

/**
 * A base response class used by the Storm Stack runtime.
 */
export class StormResponse<
  TData extends any | StormError = any | StormError
> implements IStormResponse<TData>
{
  /**
   * Create a new response.
   *
   * @remarks
   * **IMPORTANT:** This function uses the \`$storm\` context object - never use this function outside of the context wrapper/tree since the context will not be available.
   *
   * @param data - The response data
   */
  public static create<TData>(
    data: TData
  ): StormResponse<TData> {
    return new StormResponse(
      useStorm().request.id,
      useStorm().meta,
      data
    );
  }

  /**
   * The response meta.
   */
  public readonly meta: Record<string, any>;

  /**
   * The response data.
   */
  public data: TData;

  /**
   * The request identifier.
   */
  public readonly requestId: string;

  /**
   * The response created timestamp.
   */
  public readonly timestamp = Date.now();

  /**
   * An indicator of whether the response was successful.
   */
  public get success() {
    return !isStormError(this.data);
  }

  /**
   * Create a new response.
   *
   * @param requestId - The request identifier.
   * @param meta - The current context's metadata.
   * @param data - The response data
   */
  public constructor(
    requestId: string,
    meta: Record<string, any>,
    data: TData
  ) {
    this.requestId = requestId;
    this.meta = meta;
    this.data = data;
  }
}

  `;
}
chunkAF3E2D32_cjs.__name(writeResponse, "writeResponse");

exports.writeResponse = writeResponse;
//# sourceMappingURL=chunk-QSKSKZ22.cjs.map
//# sourceMappingURL=chunk-QSKSKZ22.cjs.map