import { ClientInstance } from '../client'; import { RequestInstance } from '../request'; import { ExtractEndpointType } from '../types'; export type RecursiveSchemaType = Record; /** * Per-request defaults that can be applied via SDK configuration. * These mirror the chainable setters on Request (headers, cache, retry, etc.). */ export type SdkRequestDefaults = { headers?: HeadersInit; auth?: boolean; cache?: boolean; cacheTime?: number; staleTime?: number; retry?: number; retryTime?: number; cancelable?: boolean; queued?: boolean; offline?: boolean; deduplicate?: boolean; deduplicateTime?: number | null; }; /** * Recursively extracts all endpoint strings from an SDK schema type. * Leaf nodes (keys starting with $) are RequestInstance — extract endpoint from those. * Other keys are nested schema segments to recurse into. */ type ExtractSdkEndpoints = Depth["length"] extends 10 ? never : { [K in keyof T]: K extends `$${string}` ? T[K] extends RequestInstance ? ExtractEndpointType : never : T[K] extends Record ? ExtractSdkEndpoints : never; }[keyof T]; /** * Builds the set of valid configuration keys from an SDK schema: * - "*" (global wildcard) * - exact endpoint paths extracted from RequestInstance nodes * - wildcard patterns like "/users/*" */ type SdkConfigurationKeys = "*" | ExtractSdkEndpoints | `${ExtractSdkEndpoints & string}/*`; /** * Maps endpoint paths or wildcard patterns to request defaults. * Keys are validated against the SDK schema — only known endpoints, their wildcard * variants, and "*" are accepted. */ export type SdkConfigurationMap = Partial, SdkRequestDefaults>>; export type CreateSdkOptions = { /** @default true */ camelCaseToKebabCase?: boolean; /** @default (method) => method.toUpperCase() */ methodTransform?: (method: string) => string; /** Per-endpoint request defaults */ defaults?: SdkConfigurationMap; }; export type SdkInstance = Schema & { /** * Apply request defaults to the SDK. Returns a new SDK instance with the configuration applied. * Use "*" to match all endpoints, or specific endpoint strings / wildcard patterns. */ $configure: (defaults: SdkConfigurationMap) => SdkInstance; }; export declare const createSdk: (client: Client, options?: CreateSdkOptions) => SdkInstance; /** * Type-safe factory for creating SDK configuration maps. * * @example * const config = createConfiguration()({ "*": { retry: 3 } }) */ export declare const createConfiguration: () => (defaults: SdkConfigurationMap) => SdkConfigurationMap; export {}; //# sourceMappingURL=sdk.d.ts.map