UNPKG

histoire

Version:

A fast story book powered by Vite

61 lines • 2.99 kB
import type { ServerStoryFile } from '@histoire/shared'; import type { ViteDevServer } from 'vite'; import type { CollectionCache } from '../collect/catalog-cache.js'; import type { useCollectStories } from '../collect/index.js'; import type { StoryCollectionOutcome } from '../collect/outcome.js'; import type { Context } from '../context.js'; export interface StoryCollectorOptions { /** Project context owned by this generation. */ ctx: Context; /** Client-facing Vite dev server, used to push progress/HMR messages. */ server: ViteDevServer; /** Story executor + cache control bound to the node-side collection server. */ collectStories: Pick<ReturnType<typeof useCollectStories>, 'clearCache' | 'executeStoryFile'>; invalidateModule: (id: string) => void; invalidateModuleSilently: (id: string) => void; /** Additional generation guard supplied by the runtime controller. */ isActive?: () => boolean; /** Catalog of the previous run, restored by `restore()`; rewritten after each batch. */ cache?: Pick<CollectionCache, 'read' | 'write'>; /** Observes loaded/total story files of every full collection, including background revalidation. */ onProgress?: (progress: { loaded: number; total: number; revalidate: boolean; }) => void; } /** Collection lifecycle observed by generation-owned catalog publishers. */ export interface CollectionEvent { /** Completed events run after virtual module invalidation. */ phase: 'started' | 'completed' | 'failed'; /** Captured files executed in this batch, including the initial full scan. */ files: ServerStoryFile[]; /** Executor exception, when a batch cannot complete. */ error?: unknown; /** Last completed status of every still-registered file, including unchanged files. */ outcomes: ReadonlyMap<string, StoryCollectionOutcome>; /** * Background collection of a restored catalog: the restored catalog stays * executable while it runs, as it was complete when published. */ revalidate?: boolean; } /** * Owns the dev-mode story collection loop: debounces file changes, re-executes * the story files, invalidates the virtual modules and announces the result to * the connected clients. * * Registers its own `onStoryChange` listener; call the returned `collect` once * to run the initial full collection. */ export declare function createStoryCollector(options: StoryCollectorOptions): { collect: () => Promise<void>; restore: () => Promise<boolean>; revalidate: () => Promise<void>; stop: () => Promise<void>; /** Private typed status snapshot used when initial collection finished before subscription. */ readonly outcomes: Map<string, StoryCollectionOutcome>; /** Observes completed batches without coupling collection to an MCP SDK. */ onCollection(handler: (event: CollectionEvent) => void | Promise<void>): () => void; }; //# sourceMappingURL=collect.d.ts.map