UNPKG

@proofkit/fmodata

Version:

FileMaker OData API client

74 lines (73 loc) 3.99 kB
import { FFetchOptions } from '@fetchkit/ffetch'; import { Effect, Schedule } from 'effect'; import { DatabaseNameNormalizationMode } from './client/database-name.js'; import { FMODataErrorType } from './errors.js'; import { FMODataLayer, HttpClient as HttpClientService, ODataConfig as ODataConfigService, ODataLogger as ODataLoggerService, HttpClient, ODataConfig } from './services.js'; import { Result, RetryPolicy } from './types.js'; type FMODataServices = HttpClientService | ODataConfigService | ODataLoggerService; /** * Converts a Promise<Result<T>> into an Effect with typed error channel. * This is the bridge between the existing Result pattern and Effect pipelines. */ export declare function fromResult<T>(promise: Promise<Result<T>>): Effect.Effect<T, FMODataErrorType>; /** * Creates an Effect that yields the HttpClient service and makes a request. * This is the primary way builders should make HTTP requests. */ export declare function requestFromService<T>(url: string, options?: RequestInit & FFetchOptions & { normalizeDatabaseName?: boolean; databaseNameNormalizationMode?: DatabaseNameNormalizationMode; useEntityIds?: boolean; includeSpecialColumns?: boolean; includeODataAnnotations?: boolean; retryPolicy?: RetryPolicy; }): Effect.Effect<T, FMODataErrorType, HttpClient | ODataConfig>; /** * Runs an Effect pipeline and converts the result back to the fmodata Result type. * This is the exit point from Effect back to the public API. */ export declare function runAsResult<T>(effect: Effect.Effect<T, FMODataErrorType>): Promise<Result<T>>; /** * Runs an Effect by providing the shared DI layer and returns fmodata Result<T>. */ export declare function runLayerResult<T>(layer: FMODataLayer, effect: Effect.Effect<T, FMODataErrorType, FMODataServices>, spanName?: string, attributes?: Record<string, string>): Promise<Result<T>>; /** * Runs an Effect by providing the shared DI layer and throws on fmodata errors. */ export declare function runLayerOrThrow<T>(layer: FMODataLayer, effect: Effect.Effect<T, FMODataErrorType, FMODataServices>, spanName?: string, attributes?: Record<string, string>): Promise<T>; /** * Convenience wrapper for request-like effects where span instrumentation is always desired. */ export declare function requestWithSpan<T>(layer: FMODataLayer, spanName: string, requestEffect: Effect.Effect<T, FMODataErrorType, FMODataServices>, attributes?: Record<string, string>): Promise<Result<T>>; /** * Wraps a sync/async function that may throw into an Effect that captures * the error as a typed FMODataErrorType. */ export declare function tryEffect<T>(fn: () => T | Promise<T>, mapError: (e: unknown) => FMODataErrorType): Effect.Effect<T, FMODataErrorType>; /** * Wraps a function that returns a validation-style result * ({ valid: true, data } | { valid: false, error }) into an Effect. */ export declare function fromValidation<T>(fn: () => Promise<{ valid: true; data: T; } | { valid: false; error: FMODataErrorType; }>): Effect.Effect<T, FMODataErrorType>; /** * Builds an Effect Schedule from a RetryPolicy configuration. * Uses exponential backoff with optional jitter, only retrying transient errors. */ export declare function buildRetrySchedule(policy: RetryPolicy): Schedule.Schedule<[import('effect/Duration').Duration, number], FMODataErrorType, never>; /** * Applies a retry policy to an Effect if the policy is defined. * Only retries transient errors (SchemaLockedError, NetworkError, TimeoutError, HTTP 5xx). */ export declare function withRetryPolicy<T>(effect: Effect.Effect<T, FMODataErrorType>, retryPolicy?: RetryPolicy): Effect.Effect<T, FMODataErrorType>; /** * Wraps an Effect with a tracing span for observability. * Zero overhead when no OpenTelemetry tracer is configured. */ export declare function withSpan<T, E, R>(effect: Effect.Effect<T, E, R>, name: string, attributes?: Record<string, string>): Effect.Effect<T, E, R>; export {};