import { Plugin } from "vite"; import { Collection } from "@msw/data"; import { StandardSchemaV1 } from "@standard-schema/spec"; //#region src/fakepoints/collect-fakepoints-vite-plugin.d.ts type CollectFakepointsPluginOptions = { /** * Directories to scan for fakepoints files. * Values can be absolute paths, or relative to workspaceRoot. * When provided, only these directories are scanned. * * Note: workspaceRoot is required when rootsToScan is provided. */ rootsToScan?: string[]; /** * The root directory (absolute path) to search for fakepoints files. * Defaults to process.cwd() */ workspaceRoot?: string; /** * Directories to ignore when scanning for fakepoints files during initial collection. * * Note: Vite's watcher automatically ignores .git, node_modules, test-results, cache, and configured out directories. * This option is only used for the initial file scan at startup. * * Common directories to ignore: 'tmp', '.nx', 'coverage', 'build', 'out', 'dist', '.cache' * * @example ['tmp', '.nx', 'coverage', 'build', 'out'] */ ignoreDirs?: string[]; /** * Enable file watching for fakepoints files. * When enabled, adding/deleting/changing fakepoints files will trigger test reruns. * Disable this if you experience performance issues with large workspaces. * * @default true */ watch?: boolean; /** * The file pattern to match fakepoints files. * Files matching this pattern will be collected and imported. * * @default '.fakepoints.ts' * @example '.fakes.ts' * @example '.test-data.ts' */ filePattern?: string; /** * Enable debug mode to see detailed logging about plugin operations. * When enabled, logs information about: * - Watcher ignore patterns being configured * - Virtual module loading * - Number of fakepoints files loaded * - File watcher setup status * - All file system events for fakepoints files (add, change, unlink) * * Useful for troubleshooting issues with file discovery, watching, or test reruns. * * @default false */ debug?: boolean; }; declare function collectFakepointsPlugin(options?: CollectFakepointsPluginOptions): Plugin[]; //#endregion //#region src/fakepoints/fakepoints-registry.d.ts /** * Registers a fakepoints function to be executed later. * The function can optionally return a value that will be collected by runAllFakepoints. * * @template T - The type of value returned by the fakepoints function * @param fakepointsFn - The function to register, can return void or a value * * @example * ```typescript * // Register fakepoints without a return value * registerFakepoints(() => { * console.log('Setting up fakes'); * }); * ``` */ declare function registerFakepoints(fakepointsFn: () => T$1): void; /** * Executes all registered fakepoints and collects their return values. * If fakepoints returns an array, it will be automatically flattened. * * @template T - The type of individual items in the returned array * @returns An array of collected values from all fakepoints (empty if fakepoints return void) * * @example * ```typescript * // Simple execution without collecting values * runAllFakepoints(); * * // Collect return values with type safety * const results = runAllFakepoints(); * * ``` */ declare function runAllFakepoints(): T$1[]; /** * Clears all registered fakepoints. * Primarily used for testing purposes to reset the registry state. * * @internal */ declare function clearAllFakepoints(): void; //#endregion //#region src/faketories/faketories.d.ts /** * Creates a factory object with generateOne/generateMany and seedOne/seedMany methods for generating fake data. * * @template T - The entity type * @template Schema - The schema type (StandardSchemaV1) * * **generateOne()** - Generates a single standalone entity (not stored in DB) * - `generateOne()` - Generates one entity with all defaults * - `generateOne(partial)` - Generates one entity merging partial with defaults (auto-merged!) * * **generateMany()** - Generates multiple standalone entities (not stored in DB) * - `generateMany(count)` - Generates N entities with defaults (index passed to faketory) * - `generateMany(partials[])` - Generates entities merging each partial with defaults (auto-merged!) * - `generateMany(count, partials[])` - Generates N entities, merges partials by index (auto-merged!) * * **seedOne()** - Creates and inserts a single entity into the collection (DB) * - `seedOne()` - Creates and stores 1 entity in DB (returns single entity) * - `seedOne(partial)` - Creates and stores 1 entity with partial data in DB (auto-merged!) * * **seedMany()** - Creates and inserts multiple entities into the collection (DB) * - `seedMany(count)` - Creates and stores N entities in DB (returns array) * - `seedMany(partials[])` - Creates and stores entities with partial data merged (returns array, auto-merged!) * - `seedMany(count, partials[])` - Creates N entities, merges partials by index (returns array, auto-merged!) * * **store** - Direct access to the MSW Data collection for queries and updates * - Use `store.findMany()`, `store.findFirst()`, `store.update()`, etc. * - Exposed to avoid wrapping the entire Collection API * * **Note:** Partial data is automatically merged with defaults - no need to spread `...partial` in your entity faketory! * * @example * ```typescript * // Entity faketory - just return defaults, partial is auto-merged! * const messageFaketory = createFaketory(messageCollection, async ({ partial }) => { * return { * id: faker.string.uuid(), * content: faker.lorem.sentence(), * // No need for ...partial here! It's auto-merged by createFaketory * }; * }); * * // Generate standalone (not in DB) * const msg = await messageFaketory.generateOne(); * const customMsg = await messageFaketory.generateOne({ content: 'Custom' }); // ✅ Auto-merged! * const msgs = await messageFaketory.generateMany(5); * const msgs = await messageFaketory.generateMany([{ content: 'First' }, { content: 'Second' }]); * const msgs = await messageFaketory.generateMany(3, [{ content: 'First' }]); // ✅ Merges partial with first, others use defaults * * // Seed into DB * const msg = await messageFaketory.seedOne(); // seeds 1 entity, returns T * const msg = await messageFaketory.seedOne({ content: 'Custom' }); // ✅ Auto-merged! * const msgs = await messageFaketory.seedMany(10); // seeds 10 entities, returns T[] * const msgs = await messageFaketory.seedMany([{ content: 'First' }, { content: 'Second' }]); // ✅ Auto-merged! * const msgs = await messageFaketory.seedMany(3, [{ content: 'First' }]); // ✅ Merges partial with first, others use defaults * * // Query the store directly * const messages = messageFaketory.store.findMany(); * const msg = messageFaketory.store.findFirst(q => q.where({ id: '123' })); * ``` */ interface Faketory { /** * Generates a single standalone entity (not stored in DB). * @param partial - Optional partial data to merge with defaults (auto-merged!) */ generateOne(partial?: Partial): Promise; /** * Generates multiple standalone entities (not stored in DB). * @param count - Number of entities to generate */ generateMany(count: number): Promise; /** * Generates multiple standalone entities (not stored in DB). * @param partials - Array of partial data to merge with defaults (auto-merged!) */ generateMany(partials: Partial[]): Promise; /** * Generates multiple standalone entities (not stored in DB). * @param count - Number of entities to generate * @param partials - Array of partial data to merge with defaults by index (auto-merged!) */ generateMany(count: number, partials: Partial[]): Promise; generateMany(input: number | Partial[], partials?: Partial[]): Promise; /** * @deprecated Use `generateOne()` instead. This method will be removed in a future version. */ createOne(partial?: Partial): Promise; /** * @deprecated Use `generateMany()` instead. This method will be removed in a future version. */ createMany(count: number): Promise; /** * @deprecated Use `generateMany()` instead. This method will be removed in a future version. */ createMany(partials: Partial[]): Promise; createMany(input: number | Partial[]): Promise; seedOne(partial?: Partial): Promise; /** * Creates and inserts multiple entities into the collection (DB). * @param count - Number of entities to seed */ seedMany(count: number): Promise; /** * Creates and inserts multiple entities into the collection (DB). * @param partials - Array of partial data to merge with defaults (auto-merged!) */ seedMany(partials: Partial[]): Promise; /** * Creates and inserts multiple entities into the collection (DB). * @param count - Number of entities to seed * @param partials - Array of partial data to merge with defaults by index (auto-merged!) */ seedMany(count: number, partials: Partial[]): Promise; seedMany(input: number | Partial[], partials?: Partial[]): Promise; reset(): void; /** * Direct access to the MSW Data collection for this entity. * * Named `store` because it's shorter than `collection` and reads better in code. * * Use for queries, updates, and direct data manipulation in tests: * - `store.findMany()` - Query multiple entities * - `store.findFirst()` - Find single entity * - `store.update()` - Update entities * - `store.delete()` - Delete entities */ readonly store: Collection; } type EntityFaketoryProps = { seedingMode: boolean; partial?: Partial; index?: number; }; type EntityFaketory = { (props: EntityFaketoryProps): Promise; }; type InferSchemaOutput = Schema extends StandardSchemaV1 ? T : never; declare function createFaketory>(fakeDbCollection: Collection, entityFaketory: EntityFaketory>): Faketory, Schema>; /** * Resets all faketories that have been created. * Call this in a global beforeEach to ensure a clean state for each test. */ declare function resetAllFaketories(): void; //#endregion export { CollectFakepointsPluginOptions, EntityFaketory, EntityFaketoryProps, Faketory, clearAllFakepoints, collectFakepointsPlugin, createFaketory, registerFakepoints, resetAllFaketories, runAllFakepoints };