/** * Pub/Sub System - Lightweight wrapper for fetchff's subscribe functionality * * @module pubsub */ import { subscribe as fetchffSubscribe, mutate, revalidate, type FetchResponse } from 'fetchff'; import type { DefaultResponse, EventEmitter, SubscriptionCallback } from '@plyaz/types/api'; import { PUB_SUB_EVENT } from '@plyaz/types/api'; export type { EventEmitter, SubscriptionCallback, DefaultResponse, PubSubEvent, Serializable, } from '@plyaz/types/api'; export { PUB_SUB_EVENT }; /** * Subscribe to cache updates for a specific key or pattern * Direct export from fetchff for vendor abstraction * * @param key - Cache key or URL pattern to subscribe to * @param callback - Function called when cache updates * @returns Unsubscribe function * * @example * ```typescript * const unsubscribe = subscribe('/api/users', (response) => { * console.log('Cache updated:', response.data); * }); * * // Cleanup when done * unsubscribe(); * ``` */ export declare const subscribe: typeof fetchffSubscribe; /** * Trigger cache update and notify subscribers * Direct export from fetchff * * @param key - Cache key to update * @param data - New data or updater function * @param options - Optional configuration * * @example * ```typescript * // Update cache and notify subscribers * mutate('/api/user', newUserData); * * // Optimistic update with rollback * mutate('/api/user', updatedData, { * optimistic: true, * rollbackOnError: true * }); * ``` */ export { mutate }; /** * Revalidate cache and notify subscribers * Direct export from fetchff * * @param key - Cache key(s) to revalidate * @returns Promise that resolves when revalidation completes * * @example * ```typescript * // Revalidate specific endpoint * await revalidate('/api/user'); * * // Revalidate multiple endpoints * await revalidate(['/api/user', '/api/posts']); * ``` */ export { revalidate }; /** * Create a typed subscription for better type safety * * @param key - Cache key to subscribe to * @param callback - Typed callback function * @returns Unsubscribe function * * @example * ```typescript * interface User { * id: string; * name: string; * } * * const unsubscribe = createTypedSubscription( * '/api/user', * (response) => { * if (response.data) { * console.log(response.data.name); // TypeScript knows this is a User * } * } * ); * ``` */ export declare function createTypedSubscription(key: string, callback: SubscriptionCallback): () => void; /** * Subscribe to multiple cache keys with a single handler * * @param keys - Array of cache keys to subscribe to * @param callback - Function called when any cache updates * @returns Function to unsubscribe from all * * @example * ```typescript * const unsubscribe = subscribeMultiple( * ['/api/users', '/api/posts', '/api/comments'], * (key, response) => { * console.log(`${key} updated:`, response.data); * } * ); * ``` */ export declare function subscribeMultiple(keys: string[], callback: (key: string, response: FetchResponse) => void): () => void; /** * Subscribe with automatic cleanup after timeout * * @param key - Cache key to subscribe to * @param callback - Subscription callback * @param timeout - Timeout in milliseconds * @returns Unsubscribe function * * @example * ```typescript * // Subscribe for 30 seconds only * const unsubscribe = subscribeWithTimeout( * '/api/live-data', * (response) => console.log('Update:', response), * 30000 * ); * ``` */ export declare function subscribeWithTimeout(key: string, callback: SubscriptionCallback, timeout: number): () => void; /** * Subscribe once - automatically unsubscribes after first update * * @param key - Cache key to subscribe to * @param callback - Subscription callback * @returns Unsubscribe function * * @example * ```typescript * subscribeOnce('/api/user', (response) => { * console.log('User updated once:', response.data); * // Automatically unsubscribed after this * }); * ``` */ export declare function subscribeOnce(key: string, callback: SubscriptionCallback): () => void; export declare function createEventEmitter(): EventEmitter; //# sourceMappingURL=index.d.ts.map