Scaffold minimalistic MongoDB-like in-memory document database#1
Open
mhamas wants to merge 2 commits into
Open
Scaffold minimalistic MongoDB-like in-memory document database#1mhamas wants to merge 2 commits into
mhamas wants to merge 2 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
DatabasenewCollection,removeCollection,collection,hasCollection,listCollectionsCollectioninsert(auto-_id),get,list(async iterator),update,delete,ensureIndex,listIndexesgt/gte/lt/lte/nehelpers, AND-ed across keysDuplicateKeyError,CollectionAlreadyExistsError,CollectionNotFoundError,ImmutableFieldErrorDesign decisions
list({ age: gt(18), country: 'CZ' }). Bare value = deep equality; helpers express ordering.listreturns anAsyncIterableIteratorforfor await … of.1/-1direction recorded,{ unique: true }enforced (single & compound, including missing-field collisions); queries still scan (index-accelerated lookups are out of scope).DuplicateKeyErrorand leaves the collection unchanged.structuredClone) — callers can't mutate stored state through a returned reference._idis a string, auto-generated via UUID when absent, and immutable.updateapplies 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):
A
preparescript builds on install, emitting dual ESM + CommonJS output with.d.tsvia theexportsmap — works with CommonJS (NestJS default) or ESM consumers. Both compiled outputs were smoke-tested underrequire()andimport.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.
Note on the base branch
The repository was empty at session start, so an empty
mainwas 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