UNPKG

@scalar/api-client

Version:

the open source API testing client

30 lines 1.49 kB
import type { WorkspaceStore } from '@scalar/workspace-store/client'; import { type MaybeRefOrGetter } from 'vue'; /** * Watches the specified document in the workspace store and periodically rebases it with its remote source. * * This utility sets up a watcher on the given document. If the document specifies an 'x-scalar-original-source-url' * and watch mode is enabled, this hook polls the remote source and calls `store.rebaseDocument`. * If rebase conflicts are detected, it applies automatic conflict resolution by preferring remote changes. * Uses exponential backoff on failures to avoid overwhelming the server. * * @param params - Configuration object for the document watcher. * @param params.documentName - The name/key of the document to watch and rebase. * @param params.store - The WorkspaceStore instance. * @param params.initialTimeout - Initial delay before the first poll attempt (default: 5000ms). * * @example * ```ts * import { useDocumentWatcher } from '@/hooks/use-document-watcher' * import { useScalarWorkspaceStore } from '@scalar/workspace-store' * * const store = useScalarWorkspaceStore() * useDocumentWatcher({ documentName: 'myApi', store }) * ``` */ export declare const useDocumentWatcher: ({ documentName, store, initialTimeout, }: { documentName: MaybeRefOrGetter<string | undefined>; store: MaybeRefOrGetter<WorkspaceStore | null>; initialTimeout?: number; }) => void; //# sourceMappingURL=use-document-watcher.d.ts.map