Skip to main content

Client Configuration

interface ClientConfig {
  endpoint: string;
  appKey?: string;
  userKey?: string;
  appId?: string;
  timeout?: number;
  retryCount?: number;
  retryDelay?: number;
}

Store Types

interface StoreRequest {
  collection: string;
  data: Record<string, any>[];
  payment_tx_hash?: string;
  signed_payment_tx?: SignedPaymentTx;
}

interface SignedPaymentTx {
  signed_tx_bytes: string;
  user_address: string;
  broker_address: string;
  amount_utia: number;
  purpose: string;
}

interface StoreResponse {
  ticket_id: string;
  block_height?: number;
  tx_hash?: string;
  status: string;
  message: string;
}

Query Types

interface QueryRequest {
  root?: string;
  collection?: string;
  find?: any;
  select?: any;
  limit?: number;
  offset?: number;
  sort?: string[];
  quote_id?: string;
  payment_proof?: string;
}

interface QueryResponse<T = any> {
  records: T[];
  total: number;
  limit: number;
  offset: number;
}

Payment Types

interface X402Quote {
  quoteId: string;
  totalCostTia: number;
  amountRaw: string;
  brokerAddress: string;
  description: string;
  expiresAt: number;
  chainType: 'cosmos' | 'evm' | 'solana';
  network: string;
  asset: string;
  tokenSymbol: string;
  tokenDecimals: number;
  paymentMethod: 'native' | 'x402-facilitator';
  facilitator?: string;
  allOptions: X402PaymentRequirement[];
}

interface X402PaymentRequirement {
  scheme: 'exact';
  network: string;
  maxAmountRequired: string;
  payTo: string;
  asset: string;
  resource: string;
  description: string;
  mimeType: string;
  maxTimeoutSeconds: number;
  extra?: X402Extra;
}

interface PaymentResult {
  txHash: string;
  network: string;
}

interface PaymentProof {
  payment_tx_hash: string;
  user_address: string;
  broker_address: string;
  amount_utia: number;
}

Pricing Types

interface PricingQuoteRequest {
  app_id: string;
  operation_type: 'write' | 'read';
  size_kb?: number;
  collection?: string;
  monthly_volume_kb?: number;
}

interface PricingQuoteResponse {
  type: 'write_quote_with_indexing' | 'read_quote';
  base_celestia_cost: number;
  base_celestia_cost_utia: number;
  broker_fee: number;
  broker_fee_utia: number;
  indexing_costs: Record<string, number>;
  indexing_costs_utia: Record<string, number>;
  base_total_cost: number;
  base_total_cost_utia: number;
  total_cost: number;
  total_cost_utia: number;
  indexed_fields_count: number;
  request: PricingQuoteRequest;
  monthly_volume_kb: number;
  currency: string;
  creator_premium?: any;
  price?: any;
}

Blob Types

interface UploadBlobRequest {
  collection: string;
  blob: File | Blob | Buffer;
  metadata?: Record<string, any>;
  payment_tx_hash: string;
  user_address: string;
  broker_address: string;
  amount_utia: number;
}

interface UploadBlobResponse {
  ticket_id: string;
  blob_id: string;
  status: string;
  message: string;
}

interface BlobMetadata {
  blob_id: string;
  content_type: string;
  size_bytes: number;
  uploaded_at: string;
  tx_hash: string;
  celestia_height: number;
  [key: string]: any;
}

Task Types

type TaskStatus =
  | "Pending"
  | "PaymentBroadcast"
  | "PaymentConfirming"
  | "PaymentConfirmed"
  | "StoringData"
  | "Completed"
  | { Failed: { error: string } };

interface TaskStatusResponse {
  ticket_id: string;
  status: TaskStatus;
  block_height?: number;
  tx_hash?: string;
  error?: string;
}

interface UserTasksResponse {
  tasks: TaskStatusResponse[];
  total_tasks: number;
}

Index Types

interface CreateIndexRequest {
  name: string;
  collection: string;
  field_name: string;
  index_type: 'hash' | 'btree' | 'Price';
  options?: {
    unique?: boolean;
  };
}

Relation Types

interface CreateRelationRequest {
  parent_collection: string;
  parent_field: string;
  child_collection: string;
  child_field: string;
}

interface CreateRelationResponse {
  indexes_created: string[];
}

Error Types

class OnchainDBError extends Error {
  code: string;
  statusCode?: number;
  details?: any;
}

class ValidationError extends OnchainDBError {
  details: Record<string, string[]>;
}

class TransactionError extends OnchainDBError {
  transactionId?: string;
  blockHeight?: number;
}

class PaymentRequiredError extends OnchainDBError {
  quote: X402Quote;
}

class PaymentVerificationError extends OnchainDBError {
  txHash: string;
}

CRUD Types

interface CreateOptions {
  idGenerator?: () => string;
}

interface FindManyOptions {
  limit?: number;
  offset?: number;
  sort?: {
    field: string;
    order: 'asc' | 'desc';
  };
}

interface UpsertOptions {
  idGenerator?: () => string;
}