Coding
PromptBeginner5 minmarkdown
Markdown Converter
Agent skill for markdown-converter
21
This document provides guidelines for AI coding agents working on the `@uscreen.de/fastify-mongo-crud` project.
Sign in to like and favorite skills
This document provides guidelines for AI coding agents working on the
@uscreen.de/fastify-mongo-crud project.
A tiny MongoDB decorator for Fastify providing CRUD-style database methods. This is an ESM-only package that requires Fastify >= 2.x and integrates with
@fastify/mongodb and @fastify/sensible.
This project uses pnpm exclusively. The
preinstall script enforces this.
pnpm install # Install dependencies
pnpm test # Run all tests with spec reporter pnpm test:cov # Run tests with coverage (html + text) pnpm test:ci # Run tests with coverage for CI (lcov + text) make test # Alternative: run tests via Makefile make test.coverage # Alternative: run tests with coverage # Run a single test file node --test test/crud.test.js node --test test/noop.test.js # Run tests with specific reporter node --test --test-reporter spec test/crud.test.js
Test Requirements:
127.0.0.1:27017 (default)mongoServer environment variable to override: mongoServer=localhost:27018 pnpm testnode:test)ulid to avoid conflictspnpm lint # Run ESLint with auto-fix
ESLint will automatically fix issues where possible. Pre-commit hooks run lint-staged on changed files.
The project extends
@uscreen.de/eslint-config-prettystandard-node which combines:
semi: false)singleQuote: true)trailingComma: 'none')bracketSpacing: true)node: prefix:
import { test } from 'node:test' import assert from 'node:assert/strict'
.js extension for local imports:
import crud from '../index.js' import { build } from './helper.js'
ObjectId, Fastify)crud.test.js)(_t) => { ... }const fastifyMongoCrud = (fastify, opts, next) => { ... }
const uuid = (prefix = '') => { ... }
async/await over promises and callbacksawait for database operations:
const result = await collection.findOne(query)
fastify.httpErrors from @fastify/sensible for HTTP errors:
throw fastify.httpErrors.notFound()
if (result) return result throw fastify.httpErrors.notFound()
let thrown = false try { await accounts.read(unknownId) } catch (error) { thrown = true assert.equal(error.name, 'NotFoundError') assert.equal(error.statusCode, Number(404)) } assert.ok(thrown)
Object.assign() to add fields to objects:
Object.assign(data, { created: new Date() })
await t.test('feature()', async (t) => { await t.test('should do something', async (_t) => { // test code }) })
node:assert/strict for assertionsbuild(t) function that returns configured Fastify instancet.after() for database cleanupfastify-plugin:
export default fp(fastifyMongoCrud, { fastify: '>=2.x', name: 'fastify-mongo-crud', decorators: { fastify: ['httpErrors', 'mongo'] }, dependencies: ['@fastify/sensible', '@fastify/mongodb'] })
fastify.decorate() to add properties to Fastify instancenext() callback after synchronous plugin setupmain and legacy branches and PRs├── index.js # Main plugin implementation ├── test/ │ ├── crud.test.js # Main CRUD functionality tests │ ├── helper.js # Test setup and utilities │ └── noop.test.js # Basic test runner validation ├── examples/ │ └── plain-fastify/ # Example application └── services/ └── .compose/ # MongoDB docker-compose setup
created timestamp to passed object)created on insert, modified on updateupdate() method performs upsert by default (creates if not found)read() and findOne() methods throw 404 errors for not foundlist() method returns empty array (not error) when nothing found