Skip to content

Scaffold minimalistic MongoDB-like in-memory document database#1

Open
mhamas wants to merge 2 commits into
mainfrom
claude/clever-wright-3rl05l
Open

Scaffold minimalistic MongoDB-like in-memory document database#1
mhamas wants to merge 2 commits into
mainfrom
claude/clever-wright-3rl05l

Conversation

@mhamas

@mhamas mhamas commented Jun 25, 2026

Copy link
Copy Markdown

A schema-less, in-memory document database in TypeScript — a clean, minimalistic interface for the hiring task (not a Mongo clone). Pure in-memory, no persistence.

What's included

Area Surface
Database newCollection, removeCollection, collection, hasCollection, listCollections
Collection insert (auto-_id), get, list (async iterator), update, delete, ensureIndex, listIndexes
Filters equality by default + gt/gte/lt/lte/ne helpers, AND-ed across keys
Errors DuplicateKeyError, CollectionAlreadyExistsError, CollectionNotFoundError, ImmutableFieldError

Design decisions

  • Equality-only filters + comparison helperslist({ age: gt(18), country: 'CZ' }). Bare value = deep equality; helpers express ordering.
  • Fully async API — every method returns a Promise; list returns an AsyncIterableIterator for for await … of.
  • Indexes = uniqueness + scaffolding1/-1 direction recorded, { unique: true } enforced (single & compound, including missing-field collisions); queries still scan (index-accelerated lookups are out of scope).
  • Atomic writes — a write that would violate a unique index throws DuplicateKeyError and leaves the collection unchanged.
  • Copy at the boundary (structuredClone) — callers can't mutate stored state through a returned reference.
  • _id is a string, auto-generated via UUID when absent, and immutable.
  • update applies to all documents matching the filter and adds missing fields.

Packaging

Built for direct git-dependency import into a NestJS app (no npm publish needed):

"@apify/imdb": "github:apify/hiring-in-memory-document-database#claude/clever-wright-3rl05l"

A prepare script builds on install, emitting dual ESM + CommonJS output with .d.ts via the exports map — works with CommonJS (NestJS default) or ESM consumers. Both compiled outputs were smoke-tested under require() and import.

Tests

40 vitest cases, written red-green / TDD-style, covering every operation and its edge cases (atomicity, uniqueness, snapshot iteration, deep equality, immutability). The suite doubles as the behavioural spec for the task.

npm test       # 40 passing
npm run build  # dual CJS + ESM with declarations
npm run typecheck

Note on the base branch

The repository was empty at session start, so an empty main was created as the PR base — the diff shows the full scaffolding.

🤖 Generated with Claude Code

https://claude.ai/code/session_01JzrSQVAQRL5Y7vgS72xVJr


Generated by Claude Code

claude added 2 commits June 25, 2026 14:52
Implements a schema-less, in-memory document store in TypeScript with a fully
async API, intended for direct git-dependency import into a NestJS app.

- Database: newCollection / removeCollection / collection accessors
- Collection: insert (auto _id), get, list (async iterator), update, delete
- Filters: equality by default + gt/gte/lt/lte/ne comparison helpers, AND-ed
- ensureIndex: 1/-1 direction, enforced unique constraint (single & compound)
- Atomic writes, structuredClone boundaries, immutable _id
- Dual ESM + CommonJS build with .d.ts, built on install via prepare script
- 40 vitest cases covering the behaviour as a red-green spec

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JzrSQVAQRL5Y7vgS72xVJr
- Rename package and update docs to present a general (limited) document
  database; trim install/distribution notes and expand filtering examples
- Add npm test/build/typecheck commands to the README
- Grow the test suite to 79 cases: unit coverage for deepEqual / matchesFilter
  / isMatcher / id generation, plus more CRUD, filtering and index edge cases
  (atomic batch unique collisions, key freeing on delete, multi-index
  enforcement, value deep-copying, collection isolation)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01JzrSQVAQRL5Y7vgS72xVJr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants