import type { AnyElysia } from 'elysia' import type { EdenFetchError } from '../../errors' import type { EdenRequestParams } from '../../resolve' import type { Observable, Observer } from './observable' export type OperationType = 'query' | 'mutation' | 'subscription' export interface OperationContext extends Record {} export type Operation = { id: number type: OperationType params: EdenRequestParams context: OperationContext } export type OperationLink< TElysia extends AnyElysia = AnyElysia, TInput = unknown, TOutput = unknown, > = ( options: OperationLinkOptions, ) => OperationResultObservable export type OperationLinkOptions< TElysia extends AnyElysia = AnyElysia, _TInput = unknown, TOutput = unknown, > = { operation: Operation next: (operation: Operation) => OperationResultObservable } export type OperationResultObservable = Observable< OperationResultEnvelope, EdenClientError > export type OperationResultObserver = Observer< OperationResultEnvelope, EdenClientError > export type OperationResultEnvelope = (EdenResultMessage | EdenSuccessResponse) & { context?: OperationContext } export type EdenResultMessage = | { type: 'started'; data?: never } | { type: 'stopped'; data?: never } | { data: T; type: 'data' } export type EdenSuccessResponse = { data: T; type?: 'data' } export type EdenLink = (( opts: EdenClientRuntime, ) => OperationLink) & TMeta export type EdenClientRuntime = {} export type EdenClientOptions = { links: EdenLink[] } /** * Type representing errors that can occur during Eden client operations. * This is the union of all possible error types from the Elysia route schema. * * @template _T - The Elysia app type (reserved for future use with route-specific error types) */ export type EdenClientError<_T extends AnyElysia = AnyElysia> = | EdenFetchError | Error export class OperationError extends Error { constructor(message?: string) { super(message) } }