@paultaku/node-mock-server
Version:
A TypeScript-based mock server with automatic Swagger-based mock file generation
76 lines • 2.34 kB
TypeScript
/**
* ScenarioRepository Implementation
*
* File-based persistence layer for scenarios using fs-extra.
* Implements the IScenarioRepository interface for CRUD operations.
*
* @see specs/004-scenario-management/data-model.md
* @see tests/unit/scenario-repository.test.ts
*/
import { Scenario, IScenarioRepository } from '../../shared/types/scenario-types';
/**
* File-based repository for scenario persistence
*
* Stores scenarios as individual JSON files in the configured directory.
* Each scenario is saved as {scenarioName}.json with 2-space indentation.
*
* Directory structure:
* mock/scenario/
* ├── scenario-1.json
* ├── scenario-2.json
* └── _active.json (managed by ActiveScenarioTracker)
*/
export declare class ScenarioRepository implements IScenarioRepository {
private readonly scenarioDir;
/**
* @param scenarioDir Absolute path to scenario storage directory (default: mock/scenario)
*/
constructor(scenarioDir?: string);
/**
* Save a new scenario to the file system
*
* @throws DuplicateScenarioError if scenario with same name already exists
*/
save(scenario: Scenario): Promise<void>;
/**
* Find a scenario by name
*
* @returns Scenario if found, null otherwise
*/
findByName(name: string): Promise<Scenario | null>;
/**
* Find all scenarios in the directory
*
* Ignores files that:
* - Don't have .json extension
* - Start with underscore (e.g., _active.json)
* - Are not valid scenario files
*
* @returns Array of all scenarios (empty if directory doesn't exist)
*/
findAll(): Promise<Scenario[]>;
/**
* Check if a scenario exists by name
*
* @returns true if scenario file exists, false otherwise
*/
exists(name: string): Promise<boolean>;
/**
* Update an existing scenario
*
* @throws ScenarioNotFoundError if scenario doesn't exist
*/
update(scenario: Scenario): Promise<void>;
/**
* Delete a scenario by name
*
* @throws ScenarioNotFoundError if scenario doesn't exist
*/
delete(name: string): Promise<void>;
/**
* Get the file path for a scenario name
* @private
*/
private getFilePath;
}
//# sourceMappingURL=scenario-repository.d.ts.map