fastypest 1.5.4 → 1.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +74 -0
- package/package.json +2 -2
package/AGENTS.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Fastypest Agent Handbook
|
|
2
|
+
|
|
3
|
+
## Purpose
|
|
4
|
+
This repository ships a TypeScript utility that snapshots and restores relational databases during automated tests. Any modification must preserve deterministic restores across supported engines (MySQL, MariaDB, PostgreSQL, CockroachDB) while keeping the published package consumable through `dist/`.
|
|
5
|
+
|
|
6
|
+
## Global Engineering Principles
|
|
7
|
+
- **Language & Comments**: Write code and tests in English. Do not add comments; prefer expressive naming and small pure functions.
|
|
8
|
+
- **Paradigms**: Uphold SOLID, clean code, and functional principles. Prefer pure, side-effect-free utilities. Isolate unavoidable side effects (database I/O, logging) behind well-named abstractions.
|
|
9
|
+
- **Typing**: Use full static typing—never use `any`. Leverage generics, discriminated unions, or helper types when necessary.
|
|
10
|
+
- **Magic Values**: Avoid magic strings or numbers. Extract them to constants or configuration, except when they are intentional log messages, user-facing emojis/icons, or database literals already defined in seed/query files.
|
|
11
|
+
- **Naming**: Classes use `PascalCase`, variables and functions use `camelCase`, enums and constant objects use `SCREAMING_SNAKE_CASE` when exported or reused, otherwise `camelCase`. Test descriptions use sentence case and quote literal table/entity names when relevant.
|
|
12
|
+
- **Imports & Exports**: Prefer explicit exports and maintain re-export barrels where already present (`src/index.ts`, `src/core/index.ts`, `src/core/sql-script/index.ts`, `tests/seeds/index.ts`). Keep import order stable: Node modules, third-party, internal modules.
|
|
13
|
+
- **No Console Calls**: Route runtime diagnostics through the logging layer (`createScopedLogger`).
|
|
14
|
+
|
|
15
|
+
## Repository Structure & Responsibilities
|
|
16
|
+
- `src/`: Library source. Everything here must compile with SWC + `tsc --emitDeclarationOnly`. Maintain compatibility with Node >= 18.20.3.
|
|
17
|
+
- `core/`: Fastypest orchestration, SQL script abstraction, configuration, subscribers, and shared types.
|
|
18
|
+
- `fastypest.ts`: Central class orchestrating initialization, dependency ordering, table restoration, and logging. Extend this class with pure helper methods that manipulate in-memory state, and keep transactional work inside TypeORM `EntityManager` scopes. Reuse existing constants (e.g., `PROGRESS_OFFSET`, `INDEX_OFFSET_CONFIG`) or add new constants at the top-level when necessary.
|
|
19
|
+
- `config.ts`: Holds database-specific tunables. Introduce new offsets or engine flags here rather than in-line.
|
|
20
|
+
- `types.ts`: Centralized type aliases and enums. Add new public types here to keep the public API coherent, and re-export via `src/core/index.ts`.
|
|
21
|
+
- `sql-script/`: Handles query templates. When adding queries:
|
|
22
|
+
- Update the JSON file that matches the database engine.
|
|
23
|
+
- Keep placeholders using `{{ key }}` syntax for substitution.
|
|
24
|
+
- Ensure `QueryPath` types stay valid; extend the JSON shape rather than embedding SQL inline.
|
|
25
|
+
- `subscribers/`: Contains TypeORM subscribers. Keep subscriber implementations side-effect free except for invoking provided callbacks.
|
|
26
|
+
- `logging/`: Winston-based logging utilities.
|
|
27
|
+
- Follow existing constant definitions (`LOGGING_*`). New log levels or icons belong in `constants.ts` with descriptive names.
|
|
28
|
+
- The logger API (`ScopedLogger`, `LoggerTimer`) is the approved interface. Do not bypass it.
|
|
29
|
+
- `tests/`: Integration tests executed against dockerized databases.
|
|
30
|
+
- Specs live under `tests/__tests__`. Follow Jest conventions (`describe`, `it`) and keep fixtures deterministic.
|
|
31
|
+
- Configuration (`tests/config`) bootstraps TypeORM connections and seeds. Reuse helper utilities such as `ConnectionUtil` rather than duplicating transaction logic.
|
|
32
|
+
- Seed data (`tests/seeds`) reflects current entity shapes. Update both seed arrays and entity definitions together.
|
|
33
|
+
- Utilities (`tests/utils`) may extend `Fastypest` for test purposes; preserve the inheritance hierarchy to reuse core logic.
|
|
34
|
+
- `scripts/`: Node-based CLI helpers (e.g., Docker prep). Use Node ESM-compatible syntax when editing TypeScript (`prepare-docker.ts`). Keep synchronous `spawn.sync` usage and promise wrappers intact for consistent exit handling.
|
|
35
|
+
- `docker-compose.yml`: Defines integration test services. Update environment variables and ports coherently with `tests/config/orm.config.ts`.
|
|
36
|
+
- `eslint.config.mjs`: Source of lint rules. Ensure new patterns comply; run `yarn eslint` locally before committing.
|
|
37
|
+
|
|
38
|
+
## Coding Standards by Concern
|
|
39
|
+
- **Database Access**: All database interactions should go through TypeORM repositories, query builders, or `execQuery` helpers. When introducing new raw SQL, add query templates to the appropriate JSON and expose them via `QueryPath`-compatible structures.
|
|
40
|
+
- **Transactions**: Wrap stateful DB operations in `EntityManager.transaction` blocks. Never mutate `EntityManager` outside the transaction callback.
|
|
41
|
+
- **Logging**: Construct user-facing log text with descriptive emojis and capitalize key nouns, matching existing tone (e.g., `"🧪 Temporary table prepared"`). Compose optional details as ``Progress ${current}/${total}`` etc., avoiding interpolation of undefined values.
|
|
42
|
+
- **Timers**: Prefer `logger.timer(label)` when measuring multi-step processes. Call `mark` for intermediate milestones and `end` exactly once.
|
|
43
|
+
- **Error Handling**: Throw explicit `Error` instances with clear messages. Avoid swallowing errors—propagate and rely on callers/tests to handle them.
|
|
44
|
+
- **Functional Composition**: Break down complex routines into private helper methods with single responsibilities. Maintain immutability of collections where practical; use `const` and `readonly` when possible.
|
|
45
|
+
|
|
46
|
+
## Testing Conventions
|
|
47
|
+
- Execute `yarn build` before integration tests when mimicking CI (`yarn test`). Specs should:
|
|
48
|
+
- Use `beforeAll` for expensive setup (`fastypest.init()`, seeding lookups) and `afterEach` for restoration, mirroring `tests/config/jest.setup.ts`.
|
|
49
|
+
- Prefer repository methods for data assertions. Raw SQL is acceptable only when testing raw query scenarios and must be wrapped in helper functions with extracted constants (see `insertBasicQuery`).
|
|
50
|
+
- Keep expectations explicit (`expect(value).toBe(...)`, `expect(value).toBeDefined()`). When checking nullability, use `toBeNull()` rather than `toBe(undefined)`.
|
|
51
|
+
- When randomness is required (e.g., `randomIndex`), document it via extracted constants or deterministic seeds to avoid flakiness.
|
|
52
|
+
|
|
53
|
+
## Tooling & Automation
|
|
54
|
+
- **Node/Yarn**: Use Node 20.18.0 (Volta-pinned) and Yarn 4.8.1. Add dependencies via `yarn add` so the zero-installs `.yarn` directory stays consistent.
|
|
55
|
+
- **Build**: `yarn build` runs SWC then `tsc` for declarations and copies JSON assets. Ensure new files are included by matching existing glob patterns.
|
|
56
|
+
- **Linting**: Run `yarn eslint` (auto-fix enabled) prior to committing. The pre-commit hook (`lefthook.yml`) also executes `scripts/pre-commit.js`; keep it passing.
|
|
57
|
+
- **Formatting**: Adhere to Prettier defaults implicit in existing code (two spaces for indentation, trailing commas where allowed).
|
|
58
|
+
|
|
59
|
+
## GitHub Workflows
|
|
60
|
+
- The workflow `.github/workflows/dependabot-auto-merge.workflow.yml` manages both Dependabot and auto-release pull requests. Use the default `GITHUB_TOKEN` for approvals, reviewer assignments, and comments so they remain attributed to the GitHub Actions bot. Reserve `secrets.PAT_FINE` strictly for enabling auto-merge after the approvals are in place. Avoid introducing additional secrets or inline tokens.
|
|
61
|
+
|
|
62
|
+
## Git & PR Workflow
|
|
63
|
+
- Keep commits focused and messages descriptive. Reference impacted domains (`core`, `logging`, `tests`, etc.).
|
|
64
|
+
- Update `CHANGELOG.md` only through the release process unless explicitly instructed.
|
|
65
|
+
- When introducing public API changes, update both `README.md` files (English and Spanish) and ensure exported types/functions are documented.
|
|
66
|
+
|
|
67
|
+
## Prohibited Patterns
|
|
68
|
+
- No `any`, `as unknown as`, or unchecked type assertions. When narrowing, use type guards.
|
|
69
|
+
- No inline `require` or CommonJS additions inside TypeScript sources.
|
|
70
|
+
- No side-effectful top-level execution beyond constant initialization.
|
|
71
|
+
- No global mutable singletons outside logging configuration. Use class instances and dependency injection where needed.
|
|
72
|
+
- Do not edit generated artifacts under `dist/`.
|
|
73
|
+
|
|
74
|
+
By following this handbook, you ensure Fastypest remains reliable, type-safe, and easy to maintain across databases and testing environments.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fastypest",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.5",
|
|
4
4
|
"description": "Restores the database automatically after each test. Allows serial execution of tests without having to delete and restore the database having to stop the application",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@swc/core": "^1.13.20",
|
|
60
60
|
"@swc/helpers": "^0.5.17",
|
|
61
61
|
"@types/jest": "^30.0.0",
|
|
62
|
-
"@types/node": "^24.6.
|
|
62
|
+
"@types/node": "^24.6.2",
|
|
63
63
|
"@types/winston": "^2.4.4",
|
|
64
64
|
"@typescript-eslint/eslint-plugin": "^8.45.0",
|
|
65
65
|
"@typescript-eslint/parser": "^8.45.0",
|