//#region src/types.d.ts
/** Polymorphic entity attach — opaque to the module. */
type CommentTarget = {
  type: string;
  id: string;
};
/**
 * standard comment author: registered user OR anonymous guest.
 * email is stored but REDACTED from non-moderator reads (spec §3 info-disclosure floor).
 */
type CommentAuthor = {
  kind: 'user';
  userId: string;
} | {
  kind: 'guest';
  name: string;
  email?: string;
  url?: string;
};
/** Moderation lifecycle (spec §3). */
type CommentStatus = 'published' | 'pending' | 'spam' | 'trashed';
type Comment = {
  id: string;
  target: CommentTarget;
  parentId: string | null;
  author: CommentAuthor;
  body: string;
  /** Sanitized HTML — render-safe; XSS hard-floor (spec §3). */
  bodyHtml: string;
  status: CommentStatus;
  /** STORED at insert (= parent.depth+1, 0 top-level); immutable (spec §3). */
  depth: number;
  /** ISO-8601 UTC, re-derived from createdAtMs (record-store lesson). */
  createdAt: string;
  editedAt: string | null;
};
type CommentInput = {
  target: CommentTarget;
  parentId?: string | null;
  author: CommentAuthor;
  body: string;
  /**
   * Default 'pending' (hard-floor #3).
   * Non-moderator caller passing anything other than 'pending' → CommentAuthzError.
   */
  initialStatus?: CommentStatus;
};
/** Host-injected HTML sanitizer — REQUIRED on post/edit; no default no-op (spec §3). */
type Sanitize = (raw: string) => string;
/** Capability-based actor — role resolution is the caller's concern (content parity). */
type Actor = {
  id: string;
  canModerate?: boolean;
};
type EntityRef = {
  id: string;
  target: CommentTarget;
};
type ListQuery = {
  /** Default 'published' only; other statuses require actor.canModerate. */
  status?: CommentStatus | CommentStatus[];
  /** Default 'oldest' (chronological thread display). */
  order?: 'oldest' | 'newest';
  /** Clamped; never throws. */
  limit?: number;
  /** Opaque base64url keyset over NUMERIC (createdAtMs, seq). */
  cursor?: string;
};
type Page<T> = {
  items: T[];
  nextCursor: string | null;
};
/** Tenancy readiness seam — no-op in public schema (content parity). */
type StoreOpts = {
  scope?: unknown;
};
//#endregion
//#region src/schema.d.ts
/**
 * Drizzle pgTable for comments — tenantless public schema (spec §4, content parity).
 * seq: bigserial (auto-incrementing tie-break for collation-safe keyset, spec §3).
 * created_at_ms: bigint stored as number (avoids string round-trip from pg drivers, advisor note).
 * depth: stored at insert (spec §3 — immutable; not recomputed on read).
 */
declare const comments: import("drizzle-orm/pg-core").PgTableWithColumns<{
  name: "comments";
  schema: undefined;
  columns: {
    seq: import("drizzle-orm/pg-core").PgColumn<{
      name: "seq";
      tableName: "comments";
      dataType: "number";
      columnType: "PgBigSerial53";
      data: number;
      driverParam: number;
      notNull: true;
      hasDefault: true;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: undefined;
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    id: import("drizzle-orm/pg-core").PgColumn<{
      name: "id";
      tableName: "comments";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: true;
      hasDefault: false;
      isPrimaryKey: true;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    targetType: import("drizzle-orm/pg-core").PgColumn<{
      name: "target_type";
      tableName: "comments";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: true;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    targetId: import("drizzle-orm/pg-core").PgColumn<{
      name: "target_id";
      tableName: "comments";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: true;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    parentId: import("drizzle-orm/pg-core").PgColumn<{
      name: "parent_id";
      tableName: "comments";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: false;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    depth: import("drizzle-orm/pg-core").PgColumn<{
      name: "depth";
      tableName: "comments";
      dataType: "number";
      columnType: "PgInteger";
      data: number;
      driverParam: string | number;
      notNull: true;
      hasDefault: true;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: undefined;
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    authorKind: import("drizzle-orm/pg-core").PgColumn<{
      name: "author_kind";
      tableName: "comments";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: true;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    authorUserId: import("drizzle-orm/pg-core").PgColumn<{
      name: "author_user_id";
      tableName: "comments";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: false;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    authorName: import("drizzle-orm/pg-core").PgColumn<{
      name: "author_name";
      tableName: "comments";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: false;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    authorEmail: import("drizzle-orm/pg-core").PgColumn<{
      name: "author_email";
      tableName: "comments";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: false;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    authorUrl: import("drizzle-orm/pg-core").PgColumn<{
      name: "author_url";
      tableName: "comments";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: false;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    body: import("drizzle-orm/pg-core").PgColumn<{
      name: "body";
      tableName: "comments";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: true;
      hasDefault: true;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    bodyHtml: import("drizzle-orm/pg-core").PgColumn<{
      name: "body_html";
      tableName: "comments";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: true;
      hasDefault: true;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    status: import("drizzle-orm/pg-core").PgColumn<{
      name: "status";
      tableName: "comments";
      dataType: "string";
      columnType: "PgText";
      data: CommentStatus;
      driverParam: string;
      notNull: true;
      hasDefault: true;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {
      $type: CommentStatus;
    }>;
    createdAtMs: import("drizzle-orm/pg-core").PgColumn<{
      name: "created_at_ms";
      tableName: "comments";
      dataType: "number";
      columnType: "PgBigInt53";
      data: number;
      driverParam: string | number;
      notNull: true;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: undefined;
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    createdAt: import("drizzle-orm/pg-core").PgColumn<{
      name: "created_at";
      tableName: "comments";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: true;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    editedAt: import("drizzle-orm/pg-core").PgColumn<{
      name: "edited_at";
      tableName: "comments";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: false;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
  };
  dialect: "pg";
}>;
declare const commentsSchema: {
  comments: import("drizzle-orm/pg-core").PgTableWithColumns<{
    name: "comments";
    schema: undefined;
    columns: {
      seq: import("drizzle-orm/pg-core").PgColumn<{
        name: "seq";
        tableName: "comments";
        dataType: "number";
        columnType: "PgBigSerial53";
        data: number;
        driverParam: number;
        notNull: true;
        hasDefault: true;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: undefined;
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      id: import("drizzle-orm/pg-core").PgColumn<{
        name: "id";
        tableName: "comments";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: true;
        hasDefault: false;
        isPrimaryKey: true;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      targetType: import("drizzle-orm/pg-core").PgColumn<{
        name: "target_type";
        tableName: "comments";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: true;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      targetId: import("drizzle-orm/pg-core").PgColumn<{
        name: "target_id";
        tableName: "comments";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: true;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      parentId: import("drizzle-orm/pg-core").PgColumn<{
        name: "parent_id";
        tableName: "comments";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: false;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      depth: import("drizzle-orm/pg-core").PgColumn<{
        name: "depth";
        tableName: "comments";
        dataType: "number";
        columnType: "PgInteger";
        data: number;
        driverParam: string | number;
        notNull: true;
        hasDefault: true;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: undefined;
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      authorKind: import("drizzle-orm/pg-core").PgColumn<{
        name: "author_kind";
        tableName: "comments";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: true;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      authorUserId: import("drizzle-orm/pg-core").PgColumn<{
        name: "author_user_id";
        tableName: "comments";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: false;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      authorName: import("drizzle-orm/pg-core").PgColumn<{
        name: "author_name";
        tableName: "comments";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: false;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      authorEmail: import("drizzle-orm/pg-core").PgColumn<{
        name: "author_email";
        tableName: "comments";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: false;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      authorUrl: import("drizzle-orm/pg-core").PgColumn<{
        name: "author_url";
        tableName: "comments";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: false;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      body: import("drizzle-orm/pg-core").PgColumn<{
        name: "body";
        tableName: "comments";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: true;
        hasDefault: true;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      bodyHtml: import("drizzle-orm/pg-core").PgColumn<{
        name: "body_html";
        tableName: "comments";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: true;
        hasDefault: true;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      status: import("drizzle-orm/pg-core").PgColumn<{
        name: "status";
        tableName: "comments";
        dataType: "string";
        columnType: "PgText";
        data: CommentStatus;
        driverParam: string;
        notNull: true;
        hasDefault: true;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {
        $type: CommentStatus;
      }>;
      createdAtMs: import("drizzle-orm/pg-core").PgColumn<{
        name: "created_at_ms";
        tableName: "comments";
        dataType: "number";
        columnType: "PgBigInt53";
        data: number;
        driverParam: string | number;
        notNull: true;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: undefined;
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      createdAt: import("drizzle-orm/pg-core").PgColumn<{
        name: "created_at";
        tableName: "comments";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: true;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      editedAt: import("drizzle-orm/pg-core").PgColumn<{
        name: "edited_at";
        tableName: "comments";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: false;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
    };
    dialect: "pg";
  }>;
};
type CommentsSchema = typeof commentsSchema;
/**
 * Pure DDL helper — returns a CREATE TABLE SQL string the host applies once (spec §4).
 * Column names + types match the drizzle table above exactly (seam-reviewed parity requirement).
 * The host owns migrations; this module never ships a migration file.
 */
declare function commentsTableSql(table?: string): string;
//#endregion
//#region src/errors.d.ts
/** Bad target / parent / author / body — carry field + detail (coding-standard §4). */
declare class CommentValidationError extends Error {
  readonly field: string;
  readonly detail: string;
  readonly name = "CommentValidationError";
  readonly code: "COMMENT_VALIDATION";
  constructor(field: string, detail: string);
}
/** No row found for the given id. */
declare class CommentNotFoundError extends Error {
  readonly selector: string;
  readonly name = "CommentNotFoundError";
  readonly code: "COMMENT_NOT_FOUND";
  constructor(selector: string);
}
/** IDOR / moderation denial — carries action + actorId + commentId for tracing. */
declare class CommentAuthzError extends Error {
  readonly action: string;
  readonly actorId: string | null;
  readonly commentId: string;
  readonly detail: string;
  readonly name = "CommentAuthzError";
  readonly code: "COMMENT_AUTHZ";
  constructor(action: string, actorId: string | null, commentId: string, detail: string);
}
/**
 * Missing or non-function sanitize argument on post/edit.
 * Hard-floor — a comment is never stored without a valid injected sanitizer (spec §3).
 */
declare class CommentSanitizationError extends Error {
  readonly detail: string;
  readonly name = "CommentSanitizationError";
  readonly code: "COMMENT_SANITIZATION";
  constructor(detail: string);
}
/**
 * Injected moderator/classifier returned an out-of-contract verdict (malformed status, or a
 * non-finite spamScore). Trust-boundary failure — the moderator is an external authority and its
 * return is untrusted. Surfaced as a typed error (no bare throw) so consumers' isCommentError()
 * handling recognizes it; on the postModerated path it is caught internally → fail-safe pending.
 */
declare class CommentModerationError extends Error {
  readonly detail: string;
  readonly name = "CommentModerationError";
  readonly code: "COMMENT_MODERATION";
  constructor(detail: string);
}
/** Opaque keyset cursor is malformed / tampered. */
declare class InvalidCursorError extends Error {
  readonly name = "InvalidCursorError";
  readonly code: "COMMENT_INVALID_CURSOR";
  constructor();
}
/**
 * Structural type-guard — instanceof-free (cross-package dedup safety, CLAUDE.md §6).
 * Matches any of the module's typed errors by structural `code` property.
 */
declare function isCommentError(e: unknown): e is {
  code: string;
};
//#endregion
export { StoreOpts as S, CommentTarget as _, CommentValidationError as a, Page as b, CommentsSchema as c, commentsTableSql as d, Actor as f, CommentStatus as g, CommentInput as h, CommentSanitizationError as i, comments as l, CommentAuthor as m, CommentModerationError as n, InvalidCursorError as o, Comment as p, CommentNotFoundError as r, isCommentError as s, CommentAuthzError as t, commentsSchema as u, EntityRef as v, Sanitize as x, ListQuery as y };