/* tslint:disable */
/* eslint-disable */

/* auto-generated by NAPI-RS */

export interface JsActorKeySegment {
  kind: string
  stringValue?: string
  numberValue?: number
}
export interface JsHttpRequest {
  method: string
  uri: string
  headers?: Record<string, string>
  body?: Buffer
}
export interface StateDeltaConnHibernationEntry {
  connId: string
  bytes: Buffer
}
export interface StateDeltaPayload {
  state?: Buffer
  connHibernation: Array<StateDeltaConnHibernationEntry>
  connHibernationRemoved: Array<string>
}
export interface JsRequestSaveOpts {
  immediate?: boolean
  maxWaitMs?: number
}
export interface JsInspectorSnapshot {
  stateRevision: number
  connectionsRevision: number
  queueRevision: number
  activeConnections: number
  queueSize: number
  connectedClients: number
}
export interface JsHttpResponse {
  status?: number
  headers?: Record<string, string>
  body?: Buffer
}
export interface JsQueueSendResult {
  status: string
  response?: Buffer
}
export interface JsActionDefinition {
  name: string
}
export interface JsActorConfig {
  name?: string
  icon?: string
  hasDatabase?: boolean
  remoteSqlite?: boolean
  hasState?: boolean
  canHibernateWebsocket?: boolean
  stateSaveIntervalMs?: number
  createStateTimeoutMs?: number
  onCreateTimeoutMs?: number
  createVarsTimeoutMs?: number
  createConnStateTimeoutMs?: number
  onBeforeConnectTimeoutMs?: number
  onConnectTimeoutMs?: number
  onMigrateTimeoutMs?: number
  onWakeTimeoutMs?: number
  onBeforeActorStartTimeoutMs?: number
  actionTimeoutMs?: number
  onRequestTimeoutMs?: number
  sleepTimeoutMs?: number
  noSleep?: boolean
  sleepGracePeriodMs?: number
  connectionLivenessTimeoutMs?: number
  connectionLivenessIntervalMs?: number
  maxQueueSize?: number
  maxQueueMessageSize?: number
  maxIncomingMessageSize?: number
  maxOutgoingMessageSize?: number
  preloadMaxWorkflowBytes?: number
  preloadMaxConnectionsBytes?: number
  actions?: Array<JsActionDefinition>
}
export interface JsBindParam {
  kind: string
  intValue?: number
  floatValue?: number
  textValue?: string
  blobValue?: Buffer
}
export interface ExecuteResult {
  changes: number
}
export interface QueryResult {
  columns: Array<string>
  rows: Array<Array<any>>
}
export interface NativeExecuteResult {
  columns: Array<string>
  rows: Array<Array<any>>
  changes: number
  lastInsertRowId?: number
}
export interface JsSqliteVfsMetrics {
  requestBuildNs: number
  serializeNs: number
  transportNs: number
  stateUpdateNs: number
  totalNs: number
  commitCount: number
  pageCacheEntries: number
  pageCacheWeightedSize: number
  pageCacheCapacityPages: number
  writeBufferDirtyPages: number
  dbSizePages: number
}
export interface JsQueueNextOptions {
  names?: Array<string>
  timeoutMs?: number
  completable?: boolean
}
export interface JsQueueNextBatchOptions {
  names?: Array<string>
  count?: number
  timeoutMs?: number
  completable?: boolean
}
export interface JsQueueWaitOptions {
  timeoutMs?: number
  completable?: boolean
}
export interface JsQueueEnqueueAndWaitOptions {
  timeoutMs?: number
}
export interface JsQueueTryNextOptions {
  names?: Array<string>
  completable?: boolean
}
export interface JsQueueTryNextBatchOptions {
  names?: Array<string>
  count?: number
  completable?: boolean
}
export interface JsQueueInspectMessage {
  /**
   * Queue message id. Stored as the raw u64 reinterpreted as i64 so JS
   * sees a plain number; ids are monotonic and fit comfortably in i64.
   */
  id: number
  name: string
  createdAtMs: number
}
export interface JsServeConfig {
  version: number
  endpoint: string
  token?: string
  namespace: string
  poolName: string
  engineBinaryPath?: string
  handleInspectorHttpInRuntime?: boolean
  serverlessBasePath?: string
  serverlessPackageVersion: string
  serverlessClientEndpoint?: string
  serverlessClientNamespace?: string
  serverlessClientToken?: string
  serverlessValidateEndpoint: boolean
  serverlessMaxStartPayloadBytes: number
}
export interface JsServerlessRequest {
  method: string
  url: string
  headers: Record<string, string>
  body: Buffer
}
export interface JsServerlessResponseHead {
  status: number
  headers: Record<string, string>
}
export interface JsRegistryRouteResponse {
  status: number
  headers: Record<string, string>
  body: Buffer
}
export interface JsServerlessStreamError {
  group: string
  code: string
  message: string
}
/** Options for KV list operations. */
export interface JsKvListOptions {
  reverse?: boolean
  limit?: number
}
/** A key-value entry returned from KV list operations. */
export interface JsKvEntry {
  key: Buffer
  value: Buffer
}
/** N-API wrapper around `rivetkit-core::ActorContext`. */
export declare class ActorContext {
  constructor(actorId: string, name: string, region: string)
  state(): Buffer
  beginOnStateChange(): void
  endOnStateChange(): void
  kv(): Kv
  sql(): JsNativeDatabase
  schedule(): Schedule
  queue(): Queue
  setAlarm(timestampMs?: number | undefined | null): void
  requestSave(opts?: JsRequestSaveOpts | undefined | null): void
  requestSaveAndWait(opts?: JsRequestSaveOpts | undefined | null): Promise<void>
  decodeInspectorRequest(bytes: Buffer, advertisedVersion: number): Buffer
  encodeInspectorResponse(bytes: Buffer, targetVersion: number): Buffer
  inspectorSnapshot(): JsInspectorSnapshot
  verifyInspectorAuth(bearerToken?: string | undefined | null): Promise<void>
  queueHibernationRemoval(connId: string): void
  hasPendingHibernationChanges(): boolean
  takePendingHibernationChanges(): Array<string>
  dirtyHibernatableConns(): Array<ConnHandle>
  saveState(payload: StateDeltaPayload): Promise<void>
  actorId(): string
  name(): string
  key(): Array<JsActorKeySegment>
  region(): string
  sleep(): void
  destroy(): void
  destroyRequested(): boolean
  waitForDestroyCompletion(): Promise<void>
  setPreventSleep(preventSleep: boolean): void
  preventSleep(): boolean
  aborted(): boolean
  runHandlerActive(): boolean
  restartRunHandler(): void
  beginKeepAwake(): number
  endKeepAwake(regionId: number): void
  keepAwake(promise: Promise<any>): void
  beginWebsocketCallback(): number
  endWebsocketCallback(regionId: number): void
  abortSignal(): AbortSignal
  conns(): Array<ConnHandle>
  connectConn(params: Buffer, request?: JsHttpRequest | undefined | null): Promise<ConnHandle>
  disconnectConn(id: string): Promise<void>
  disconnectConns(predicate: (...args: any[]) => any): Promise<void>
  broadcast(name: string, args: Buffer): void
  waitUntil(promise: Promise<any>): void
  waitForTrackedShutdownWork(): Promise<boolean>
  waitForTrackedShutdownWorkUnbounded(): Promise<void>
  registerTask(promise: Promise<any>): void
  runtimeState(): object
  clearRuntimeState(): void
}
export declare class NapiActorFactory {
  constructor(callbacks: object, config?: JsActorConfig | undefined | null)
}
export declare class CancellationToken {
  constructor()
  aborted(): boolean
  cancel(): void
  onCancelled(callback: (...args: any[]) => any): void
}
export declare class ConnHandle {
  id(): string
  params(): Buffer
  state(): Buffer
  setState(state: Buffer): void
  isHibernatable(): boolean
  send(name: string, args: Buffer): void
  disconnect(reason?: string | undefined | null): Promise<void>
}
export declare class JsNativeDatabase {
  takeLastKvError(): string | null
  metrics(): JsSqliteVfsMetrics | null
  run(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<ExecuteResult>
  query(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<QueryResult>
  execute(sql: string, params?: Array<JsBindParam> | undefined | null): Promise<NativeExecuteResult>
  exec(sql: string): Promise<QueryResult>
  close(): Promise<void>
}
export declare class Kv {
  get(key: Buffer): Promise<Buffer | null>
  put(key: Buffer, value: Buffer): Promise<void>
  delete(key: Buffer): Promise<void>
  deleteRange(start: Buffer, end: Buffer): Promise<void>
  listPrefix(prefix: Buffer, options?: JsKvListOptions | undefined | null): Promise<Array<JsKvEntry>>
  listRange(start: Buffer, end: Buffer, options?: JsKvListOptions | undefined | null): Promise<Array<JsKvEntry>>
  batchGet(keys: Array<Buffer>): Promise<Array<Buffer | undefined | null>>
  batchPut(entries: Array<JsKvEntry>): Promise<void>
  batchDelete(keys: Array<Buffer>): Promise<void>
}
export declare class Queue {
  send(name: string, body: Buffer): Promise<QueueMessage>
  next(options?: JsQueueNextOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<QueueMessage | null>
  nextBatch(options?: JsQueueNextBatchOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<Array<QueueMessage>>
  waitForNames(names: Array<string>, options?: JsQueueWaitOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<QueueMessage>
  waitForNamesAvailable(names: Array<string>, options?: JsQueueWaitOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<void>
  enqueueAndWait(name: string, body: Buffer, options?: JsQueueEnqueueAndWaitOptions | undefined | null, signal?: CancellationToken | undefined | null): Promise<Buffer | null>
  tryNext(options?: JsQueueTryNextOptions | undefined | null): QueueMessage | null
  tryNextBatch(options?: JsQueueTryNextBatchOptions | undefined | null): Array<QueueMessage>
  maxSize(): number
  inspectMessages(): Promise<Array<JsQueueInspectMessage>>
}
export declare class QueueMessage {
  id(): bigint
  name(): string
  body(): Buffer
  createdAt(): number
  isCompletable(): boolean
  complete(response?: Buffer | undefined | null): Promise<void>
}
export declare class CoreRegistry {
  constructor()
  register(name: string, factory: NapiActorFactory): void
  serve(config: JsServeConfig): Promise<void>
  /**
   * Trip the shutdown token and tear down any live serverless runtime.
   *
   * Idempotent. Safe to call when neither mode has been activated.
   * Does not block on the `serve()` future; TS awaits that promise
   * separately to avoid re-entrancy.
   */
  shutdown(): Promise<void>
  actorStopThresholdMs(): Promise<number | null>
  health(): Promise<JsRegistryRouteResponse>
  metadata(): JsRegistryRouteResponse
  metrics(): JsRegistryRouteResponse
  handleServerlessRequest(req: JsServerlessRequest, onStreamEvent: (...args: any[]) => any, cancelToken: CancellationToken, config: JsServeConfig): Promise<JsServerlessResponseHead>
}
export declare class Schedule {
  after(durationMs: number, actionName: string, args: Buffer): void
  at(timestampMs: number, actionName: string, args: Buffer): void
}
export declare class WebSocket {
  send(data: Buffer, binary: boolean): void
  close(code?: number | undefined | null, reason?: string | undefined | null): Promise<void>
  setEventCallback(callback: (...args: any[]) => any): void
}
