59 Commits

Author SHA1 Message Date
c0d8d8c101 v7.0.0
Some checks failed
Default (tags) / security (push) Failing after 0s
Default (tags) / test (push) Failing after 0s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-03-26 14:51:17 +00:00
39ea05f2be BREAKING CHANGE(api): reduce the package to the SmartMongo memory replica set API and remove bundled TsmDB and LocalTsmDb modules 2026-03-26 14:51:17 +00:00
8d918ec03b v5.1.1
Some checks failed
Default (tags) / security (push) Failing after 0s
Default (tags) / test (push) Failing after 0s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-03-26 08:02:04 +00:00
97e8298dcd fix(build): migrate smartconfig metadata and refresh build dependencies 2026-03-26 08:02:04 +00:00
c65c285296 v5.1.0
Some checks failed
Default (tags) / security (push) Successful in 38s
Default (tags) / test (push) Failing after 4m1s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-02-03 16:48:50 +00:00
b72174ca7b feat(localtsmdb): export ILocalTsmDbConnectionInfo and expand LocalTsmDb/TsmDB documentation and examples 2026-02-03 16:48:50 +00:00
1ff4d219af v5.0.0
Some checks failed
Default (tags) / security (push) Successful in 43s
Default (tags) / test (push) Failing after 4m2s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-02-03 16:42:49 +00:00
09f60de56f BREAKING CHANGE(localtsmdb): add Unix socket support and change LocalTsmDb API to return connection info instead of a MongoClient 2026-02-03 16:42:49 +00:00
e6a36ecb5f v4.3.0
Some checks failed
Default (tags) / security (push) Successful in 41s
Default (tags) / test (push) Failing after 4m0s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-02-03 08:14:58 +00:00
6a37a773ea feat(docs): add LocalTsmDb documentation and examples; update README code samples and imports; correct examples and variable names; update package author 2026-02-03 08:14:58 +00:00
1fff277698 v4.2.1
Some checks failed
Default (tags) / security (push) Successful in 44s
Default (tags) / test (push) Failing after 4m1s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-02-03 07:29:20 +00:00
0ad7f316c4 fix(package.json): replace main and typings with exports field pointing to ./dist_ts/index.js 2026-02-03 07:29:20 +00:00
0d450e7d4e v4.2.0
Some checks failed
Default (tags) / security (push) Successful in 43s
Default (tags) / test (push) Failing after 4m2s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-02-01 23:33:35 +00:00
fff77fbd8e feat(tsmdb): implement TsmDB Mongo-wire-compatible server, add storage/engine modules and reorganize exports 2026-02-01 23:33:35 +00:00
678bf15eb4 v4.1.1
Some checks failed
Default (tags) / security (push) Successful in 31s
Default (tags) / test (push) Failing after 12m4s
Default (tags) / release (push) Has been cancelled
Default (tags) / metadata (push) Has been cancelled
2026-02-01 16:16:45 +00:00
aa45e9579b fix(tsmdb): add comprehensive unit tests for tsmdb components: checksum, query planner, index engine, session, and WAL 2026-02-01 16:16:45 +00:00
e3dc19aa7c v4.1.0
Some checks failed
Default (tags) / security (push) Successful in 29s
Default (tags) / test (push) Failing after 4m0s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-02-01 16:05:00 +00:00
316af45b5e feat(readme): expand README with storage integrity, WAL, query planner, session & transaction docs; update test script to enable verbose logging and increase timeout 2026-02-01 16:05:00 +00:00
6932059965 v4.0.0
Some checks failed
Default (tags) / security (push) Successful in 43s
Default (tags) / test (push) Failing after 4m0s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-02-01 16:02:03 +00:00
bd1764159e BREAKING CHANGE(storage,engine,server): add session & transaction management, index/query planner, WAL and checksum support; integrate index-accelerated queries and update storage API (findByIds) to enable index optimizations 2026-02-01 16:02:03 +00:00
12102255c4 v3.0.0
Some checks failed
Default (tags) / security (push) Successful in 43s
Default (tags) / test (push) Failing after 4m1s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-02-01 14:34:07 +00:00
a0df731bc0 BREAKING CHANGE(tsmdb): rename CongoDB to TsmDB and relocate/rename wire-protocol server implementation and public exports 2026-02-01 14:34:07 +00:00
28e166ee35 v2.2.0
Some checks failed
Default (tags) / security (push) Successful in 44s
Default (tags) / test (push) Failing after 4m2s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-01-31 12:13:59 +00:00
06ada11b79 feat(readme): update README with expanded documentation covering CongoDB and SmartMongo, installation, quick start examples, architecture, usage examples, and legal/company information 2026-01-31 12:13:59 +00:00
17195cfe1b v2.1.0
Some checks failed
Default (tags) / security (push) Successful in 43s
Default (tags) / test (push) Failing after 4m1s
Default (tags) / release (push) Has been skipped
Default (tags) / metadata (push) Has been skipped
2026-01-31 11:33:11 +00:00
fcc5a0e557 feat(congodb): implement CongoDB MongoDB wire-protocol compatible in-memory server and APIs 2026-01-31 11:33:11 +00:00
a01f4d83c0 v2.0.14
Some checks failed
Default (tags) / security (push) Successful in 53s
Default (tags) / test (push) Successful in 1m2s
Default (tags) / release (push) Failing after 59s
Default (tags) / metadata (push) Successful in 1m12s
2025-11-17 02:59:44 +00:00
46db52184b fix(smartmongo.plugins): Use default import for mongodb-memory-server (Deno compatibility), update hints and bump package version to 2.0.13 2025-11-17 02:59:44 +00:00
e22c0d4644 2.0.12
Some checks failed
Default (tags) / security (push) Successful in 36s
Default (tags) / test (push) Successful in 57s
Default (tags) / release (push) Failing after 51s
Default (tags) / metadata (push) Successful in 59s
2025-04-06 19:00:35 +00:00
bb838fd16f fix(ci/config): Update CI workflow environment variables, refine package metadata, and improve configuration settings 2025-04-06 19:00:35 +00:00
667357c8e4 2.0.11 2025-04-06 13:41:14 +00:00
50e62ac61a fix(dependencies): Update dependency names and versions in CI workflows and package configuration 2025-04-06 13:41:13 +00:00
e53f4fc190 update description 2024-05-29 14:14:52 +02:00
02592d5d73 update tsconfig 2024-04-14 18:00:24 +02:00
9aa907e22b update npmextra.json: githost 2024-04-01 21:36:43 +02:00
83dca60a3c update npmextra.json: githost 2024-04-01 19:59:01 +02:00
e416c42c9c update npmextra.json: githost 2024-03-30 21:48:01 +01:00
8a26128663 2.0.10 2023-08-08 16:59:47 +02:00
a5ddbd44af fix(core): update 2023-08-08 16:59:47 +02:00
2763da6efa 2.0.9 2023-08-08 16:57:55 +02:00
5ec56eb0dd fix(core): update 2023-08-08 16:57:54 +02:00
f562556d62 2.0.8 2023-08-08 14:07:06 +02:00
6f18c0d48a fix(core): update 2023-08-08 14:07:05 +02:00
4b89137721 switch to new org scheme 2023-07-11 01:13:50 +02:00
5ac9e9969d switch to new org scheme 2023-07-10 10:16:43 +02:00
5eed702631 2.0.7 2022-06-09 00:18:05 +02:00
ac5ce0346b fix(core): update 2022-06-09 00:18:05 +02:00
eabda34aca 2.0.6 2022-06-09 00:01:30 +02:00
0e41748da5 fix(core): update 2022-06-09 00:01:29 +02:00
f4586d529d 2.0.5 2022-06-06 17:38:35 +02:00
c09eaf613d fix(core): update 2022-06-06 17:38:35 +02:00
d5ff5b0ed8 2.0.4 2022-06-06 16:51:41 +02:00
1783d72395 fix(core): update 2022-06-06 16:51:41 +02:00
a01755fb9e 2.0.3 2022-06-03 17:31:05 +02:00
3ebf34ee9d fix(core): update 2022-06-03 17:31:04 +02:00
b71a238a3d 2.0.2 2022-05-19 08:48:43 +02:00
d0c7a95e16 fix(core): update 2022-05-19 08:48:43 +02:00
ed38ff50e7 2.0.1 2022-05-18 17:35:17 +02:00
0a3be3e7f4 fix(core): update 2022-05-18 17:35:16 +02:00
21 changed files with 9502 additions and 11195 deletions

View File

@@ -0,0 +1,66 @@
name: Default (not tags)
on:
push:
tags-ignore:
- '**'
env:
IMAGE: code.foss.global/host.today/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Install pnpm and npmci
run: |
pnpm install -g pnpm
pnpm install -g @ship.zone/npmci
- name: Run npm prepare
run: npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build

View File

@@ -0,0 +1,124 @@
name: Default (tags)
on:
push:
tags:
- '*'
env:
IMAGE: code.foss.global/host.today/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @ship.zone/npmci
npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @ship.zone/npmci
npmci npm prepare
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build
release:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @ship.zone/npmci
npmci npm prepare
- name: Release
run: |
npmci node install stable
npmci npm publish
metadata:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
continue-on-error: true
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @ship.zone/npmci
npmci npm prepare
- name: Code quality
run: |
npmci command npm install -g typescript
npmci npm install
- name: Trigger
run: npmci trigger
- name: Build docs and upload artifacts
run: |
npmci node install stable
npmci npm install
pnpm install -g @git.zone/tsdoc
npmci command tsdoc
continue-on-error: true

3
.gitignore vendored
View File

@@ -3,7 +3,6 @@
# artifacts
coverage/
public/
pages/
# installs
node_modules/
@@ -17,4 +16,4 @@ node_modules/
dist/
dist_*/
# custom
#------# custom

View File

@@ -1,141 +0,0 @@
# gitzone ci_default
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
cache:
paths:
- .npmci_cache/
key: '$CI_BUILD_STAGE'
stages:
- security
- test
- release
- metadata
before_script:
- npm install -g @shipzone/npmci
# ====================
# security stage
# ====================
mirror:
stage: security
script:
- npmci git mirror
only:
- tags
tags:
- lossless
- docker
- notpriv
auditProductionDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --production --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=prod --production
tags:
- docker
allow_failure: true
auditDevDependencies:
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
stage: security
script:
- npmci npm prepare
- npmci command npm install --ignore-scripts
- npmci command npm config set registry https://registry.npmjs.org
- npmci command npm audit --audit-level=high --only=dev
tags:
- docker
allow_failure: true
# ====================
# test stage
# ====================
testStable:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci npm test
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
testBuild:
stage: test
script:
- npmci npm prepare
- npmci node install stable
- npmci npm install
- npmci command npm run build
coverage: /\d+.?\d+?\%\s*coverage/
tags:
- docker
release:
stage: release
script:
- npmci node install stable
- npmci npm publish
only:
- tags
tags:
- lossless
- docker
- notpriv
# ====================
# metadata stage
# ====================
codequality:
stage: metadata
allow_failure: true
only:
- tags
script:
- npmci command npm install -g tslint typescript
- npmci npm prepare
- npmci npm install
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
tags:
- lossless
- docker
- priv
trigger:
stage: metadata
script:
- npmci trigger
only:
- tags
tags:
- lossless
- docker
- notpriv
pages:
stage: metadata
script:
- npmci node install lts
- npmci command npm install -g @gitzone/tsdoc
- npmci npm prepare
- npmci npm install
- npmci command tsdoc
tags:
- lossless
- docker
- notpriv
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
allow_failure: true

40
.smartconfig.json Normal file
View File

@@ -0,0 +1,40 @@
{
"@git.zone/cli": {
"projectType": "npm",
"module": {
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartmongo",
"description": "A MongoDB memory server toolkit for testing and development, providing real MongoDB replica sets via mongodb-memory-server.",
"npmPackagename": "@push.rocks/smartmongo",
"license": "MIT",
"projectDomain": "push.rocks",
"keywords": [
"mongodb",
"testing",
"local database",
"replica set",
"memory server",
"database management",
"typescript"
]
},
"release": {
"registries": [
"https://verdaccio.lossless.digital",
"https://registry.npmjs.org"
],
"accessLevel": "public"
},
"services": [
"mongodb",
"minio"
]
},
"@git.zone/tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
},
"@ship.zone/szci": {
"npmGlobalTools": []
}
}

View File

@@ -1,7 +1,7 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"fileMatch": ["/.smartconfig.json"],
"schema": {
"type": "object",
"properties": {

253
changelog.md Normal file
View File

@@ -0,0 +1,253 @@
# Changelog
## 2026-03-26 - 7.0.0 - BREAKING CHANGE(api)
reduce the package to the SmartMongo memory replica set API and remove bundled TsmDB and LocalTsmDb modules
- remove exports and source code for TsmDB, LocalTsmDb, and related utilities, handlers, storage adapters, and tests
- flatten SmartMongo into the main package entrypoint and keep mongodb-memory-server-based replica set startup as the core feature
- trim dependencies and documentation to focus the package on in-memory MongoDB replica sets for testing and development
## 2026-03-26 - 5.1.1 - fix(build)
migrate smartconfig metadata and refresh build dependencies
- replace npmextra.json with .smartconfig.json and update packaged config file inclusion
- switch the build script to tsbuild tsfolders
- update core build and runtime dependencies and add explicit TypeScript type annotations to satisfy newer tooling
## 2026-02-03 - 5.1.0 - feat(localtsmdb)
export ILocalTsmDbConnectionInfo and expand LocalTsmDb/TsmDB documentation and examples
- Exported new type ILocalTsmDbConnectionInfo from ts_local (ts/index.ts)
- Added LocalTsmDb configuration example, methods table, and ConnectionInfo interface to README
- Documented Unix socket vs TCP connection modes and updated usage examples (TCP and socket examples)
- Expanded TsmDB docs: additional server properties, aggregation stages, regex examples, index operations, database ops, checksums, and wire protocol commands
- Updated architecture notes to include Unix socket support and new engine components (QueryEngine, UpdateEngine, AggregationEngine)
## 2026-02-03 - 5.0.0 - BREAKING CHANGE(localtsmdb)
add Unix socket support and change LocalTsmDb API to return connection info instead of a MongoClient
- LocalTsmDb.start() now returns ILocalTsmDbConnectionInfo { socketPath, connectionUri } instead of a connected MongoClient
- Removed internal MongoClient management: consumers must create/connect/close their own MongoClient using the returned connectionUri (close client before calling db.stop())
- Added ILocalTsmDbConnectionInfo type and getConnectionInfo() (replaces getClient())
- TsmdbServer: added socketPath option to listen on Unix sockets, cleans up stale socket files on start/stop, and encodes socket paths in getConnectionUri()
- LocalTsmDb can auto-generate socket paths in the OS temp dir; LocalTsmDb no longer depends on the mongodb package internally (lightweight Unix socket wrapper)
- Updated docs and tests to use MongoClient externally and to demonstrate socketPath/connectionUri workflow
- ts_local plugins no longer export net (net usage moved to server implementation)
## 2026-02-03 - 4.3.0 - feat(docs)
add LocalTsmDb documentation and examples; update README code samples and imports; correct examples and variable names; update package author
- Introduce LocalTsmDb: zero-config local database with automatic persistence, auto port discovery, and pre-connected client (added Quick Start, API, Features, and testing examples).
- Expand comparison table to include LocalTsmDb alongside SmartMongo and TsmDB.
- Update README examples: new LocalTsmDb usage, reorder options (LocalTsmDb, TsmDB, SmartMongo), rename test DB variable (db -> testDb), and adjust test snippets for Jest/Mocha and tap.
- Adjust code snippets and API notes: switch some example imports to use tsmdb, replace FileStorageAdapter references, change planner.createPlan to await planner.plan, and use wal.getEntriesAfter(...) without awaiting.
- Update package.json author from 'Lossless GmbH' to 'Task Venture Capital GmbH'.
## 2026-02-03 - 4.2.1 - fix(package.json)
replace main and typings with exports field pointing to ./dist_ts/index.js
- Added package.json exports field mapping "." to ./dist_ts/index.js to declare the package entrypoint.
- Removed main (dist_ts/index.js) and typings (dist_ts/index.d.ts) entries.
- Note: switching to exports improves Node resolution but removing the typings entry may affect TypeScript consumers expecting index.d.ts.
## 2026-02-01 - 4.2.0 - feat(tsmdb)
implement TsmDB Mongo-wire-compatible server, add storage/engine modules and reorganize exports
- Add full TsmDB implementation under ts/ts_tsmdb: wire protocol, server, command router, handlers, engines (Query, Update, Aggregation, Index, Transaction, Session), storage adapters (Memory, File), OpLog, WAL, utils and types.
- Remove legacy ts/tsmdb implementation and replace with new ts_tsmdb module exports.
- Introduce ts/ts_mongotools module and move SmartMongo class there; update top-level exports in ts/index.ts to export SmartMongo, tsmdb (from ts_tsmdb) and LocalTsmDb.
- Add LocalTsmDb convenience class (ts/ts_local) to start a file-backed TsmDB and return a connected MongoClient.
- Refactor plugin imports into per-module plugins files and add utilities (checksum, persistence, query planner, index engine).
## 2026-02-01 - 4.1.1 - fix(tsmdb)
add comprehensive unit tests for tsmdb components: checksum, query planner, index engine, session, and WAL
- Add new tests: test.tsmdb.checksum.ts — CRC32 and document checksum utilities (add/verify/remove)
- Add new tests: test.tsmdb.queryplanner.ts — QueryPlanner plans, index usage, selectivity, explain output, and edge cases
- Add new tests: test.tsmdb.indexengine.ts — Index creation, unique/sparse options, candidate selection, and constraints
- Add new tests: test.tsmdb.session.ts — Session lifecycle, touch/refresh/close, extractSessionId handling
- Add new tests: test.tsmdb.wal.ts — WAL initialization, LSN increments, logging/recovery for inserts/updates/deletes, binary and nested data handling
- Tests only — no production API changes; increases test coverage
- Recommend patch bump from 4.1.0 to 4.1.1
## 2026-02-01 - 4.1.0 - feat(readme)
expand README with storage integrity, WAL, query planner, session & transaction docs; update test script to enable verbose logging and increase timeout
- Updated npm test script to run tstest with --verbose, --logfile and --timeout 60 to improve test output and avoid timeouts.
- Extensive README additions: file storage adapter examples with checksum options, write-ahead logging (WAL) usage and recovery, query planner examples, index and query execution details, session and transaction examples and features.
- Wire protocol / features table updated to include Transactions and Sessions and added admin commands (dbStats, collStats).
- Architecture diagram and component list updated to include QueryPlanner, SessionEngine, TransactionEngine and WAL; storage layer annotated with checksums and WAL.
- Minor example import tweak: MongoClient import now includes Db type in test examples.
## 2026-02-01 - 4.0.0 - BREAKING CHANGE(storage,engine,server)
add session & transaction management, index/query planner, WAL and checksum support; integrate index-accelerated queries and update storage API (findByIds) to enable index optimizations
- Add SessionEngine with session lifecycle, auto-abort of transactions on expiry and session tracking in CommandRouter and AdminHandler.
- Introduce TransactionEngine integrations in CommandRouter and AdminHandler; handlers now support start/commit/abort transaction workflows.
- Add IndexEngine enhancements including a simple B-tree and hash map optimizations; integrate index usage into Find/Count/Insert/Update/Delete handlers for index-accelerated queries and index maintenance on mutations.
- Add QueryPlanner to choose IXSCAN vs COLLSCAN and provide explain plans.
- Add WAL (write-ahead log) for durability, with LSNs, checkpoints and recovery APIs.
- Add checksum utilities and FileStorageAdapter support for checksums (enableChecksums/strictChecksums), with verification on read and optional strict failure behavior.
- IStorageAdapter interface changed to include findByIds; MemoryStorageAdapter and FileStorageAdapter implement findByIds to support index lookups.
- Exported API additions: WAL, QueryPlanner, SessionEngine, checksum utilities; CommandRouter now caches IndexEngines and exposes transaction/session engines.
- Breaking change: the IStorageAdapter interface change requires third-party storage adapters to implement the new findByIds method.
## 2026-02-01 - 3.0.0 - BREAKING CHANGE(tsmdb)
rename CongoDB to TsmDB and relocate/rename wire-protocol server implementation and public exports
- Project refactor renames the in-memory wire-protocol server from CongoDB -> TsmDB (identifiers, files and namespaces changed).
- ts/index.ts now exports tsmdb instead of congodb (public API change; consumers must update imports).
- All congodb sources under ts/congodb were removed and equivalent implementations added under ts/tsmdb (errors, engines, storage adapters, server, handlers, WireProtocol, types).
- Readme and usage examples updated to reference TsmDB/tsmdb and example code updated accordingly.
- Tests renamed/updated from test.congodb.ts -> test.tsmdb.ts to exercise the new tsmdb export and server.
## 2026-01-31 - 2.2.0 - feat(readme)
update README with expanded documentation covering CongoDB and SmartMongo, installation, quick start examples, architecture, usage examples, and legal/company information
- Completely expanded README: added detailed overview for SmartMongo and new CongoDB (wire-protocol server)
- Added Quick Start examples for both SmartMongo and CongoDB (TypeScript/ESM snippets)
- Included installation instructions for npm and pnpm and issue reporting/security guidance
- Added architecture diagram, example tests, and storage/engine descriptions
- Clarified license, trademark, and company contact information
- Large non-functional documentation-only change (+398 -44)
## 2026-01-31 - 2.1.0 - feat(congodb)
implement CongoDB MongoDB wire-protocol compatible in-memory server and APIs
- Add full congodb module: CongoServer, WireProtocol, CommandRouter and handlers (Hello, Insert, Find, Update, Delete, Aggregate, Index, Admin).
- Implement query/update/aggregation/index/transaction engines (QueryEngine, UpdateEngine, AggregationEngine, IndexEngine, TransactionEngine) and OpLog for change stream support.
- Add storage adapters: in-memory (MemoryStorageAdapter) and file-backed (FileStorageAdapter) with persistence and oplog support.
- Introduce types/interfaces and rich error classes (CongoErrors) plus congodb.plugins re-exports (bson, mingo, smartfs, smartpath, smartrx).
- Add many server-side utilities: IndexEngine, Aggregation helpers ($lookup, $graphLookup, $merge, $facet, $unionWith), cursor management and command routing.
- Add integration tests for CongoDB using official mongodb MongoClient (test/test.congodb.ts) and update unit test entry (test/test.ts) to use tstest tapbundle.
- Export congodb from ts/index.ts and update package.json: bump devDependencies, add runtime deps (mongodb, bson, mingo, mingo), add new @push.rocks/* deps and dev tool versions.
- Update readme.hints.md with CongoDB architecture, usage examples and supported commands.
- Update npmextra.json metadata and release/registry config and reorganize tsdoc mappings.
## 2025-11-17 - 2.0.14 - fix(smartmongo.plugins)
Use default import for mongodb-memory-server (Deno compatibility), update hints and bump package version to 2.0.13
- Replace namespace import with default import for mongodb-memory-server to ensure compatibility with Deno (ts/smartmongo.plugins.ts).
- Add readme.hints.md documenting the Deno compatibility change and the reason for using a default import.
- Bump package.json version to 2.0.13.
- Note: ts/00_commitinfo_data.ts still lists version 2.0.12 and may need to be updated to match package.json.
## 2025-04-06 - 2.0.12 - fix(ci/config)
Update CI workflow environment variables, refine package metadata, and improve configuration settings
- Updated workflow YAML files to use new IMAGE and npmci package names
- Adjusted package.json homepage, added bugs field and pnpm overrides
- Minor formatting improvements in readme.md and .gitignore
- Enhanced tsconfig with baseUrl and paths for improved module resolution
## 2025-04-06 - 2.0.11 - fix(dependencies)
Update dependency names and versions in CI workflows and package configuration
- Rename devDependency packages from '@gitzone/*' to '@git.zone/*' for consistency
- Bump '@types/node' from '^20.4.8' to '^22.14.0'
- Upgrade 'mongodb-memory-server' from '^8.14.0' to '^10.1.4'
- Add 'packageManager' field in package.json
- Introduce pnpm-workspace.yaml with 'onlyBuiltDependencies' configuration
## 2024-05-29 - 2.0.10 - misc
Various updates to project configuration and documentation.
- update description
- update tsconfig
- update npmextra.json: githost (applied on three occasions)
## 2023-08-08 - 2.0.9 - core
Core fix.
- fix(core): update
## 2023-08-08 - 2.0.8 - core
Core fix.
- fix(core): update
## 2023-08-08 - 2.0.7 - core & org
Combined changes for core stability and organization improvements.
- fix(core): update
- switch to new org scheme (recorded twice)
## 2022-06-08 - 2.0.6 - core
Core fix.
- fix(core): update
## 2022-06-08 - 2.0.5 - core
Core fix.
- fix(core): update
## 2022-06-06 - 2.0.4 - core
Core fix.
- fix(core): update
## 2022-06-06 - 2.0.3 - core
Core fix.
- fix(core): update
## 2022-06-03 - 2.0.2 - core
Core fix.
- fix(core): update
## 2022-05-19 - 2.0.1 - core
Core fix.
- fix(core): update
## 2022-05-18 - 2.0.0 - core
Core fix.
- fix(core): update
## 2022-05-17 - 1.0.9 - core
Breaking change for module format.
- BREAKING CHANGE(core): switch to esm
## 2022-05-17 - 1.0.8 - core
Core fix.
- fix(core): update
## 2021-12-21 - 1.0.7 - core
Core fix.
- fix(core): update
## 2021-12-20 - 1.0.6 - core
Core fix.
- fix(core): update
## 2021-12-20 - 1.0.5 - core
Core fix.
- fix(core): update
## 2021-12-20 - 1.0.4 - core
Core fix.
- fix(core): update
## 2021-12-20 - 1.0.3 - core
Core fix.
- fix(core): update
## 2021-12-20 - 1.0.2 - no notable changes
These version bumps did not include additional modifications.
- version update only
## 2021-12-20 - 1.0.1 - core
Core fix.
- fix(core): update

View File

@@ -1,4 +1,4 @@
Copyright (c) 2021 Lossless GmbH (hello@lossless.com)
Copyright (c) 2021 Task Venture Capital GmbH (hello@task.vc)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@@ -1,18 +0,0 @@
{
"gitzone": {
"projectType": "npm",
"module": {
"githost": "gitlab.com",
"gitscope": "pushrocks",
"gitrepo": "smartmongo",
"shortDescription": "create a local mongodb for testing",
"npmPackagename": "@pushrocks/smartmongo",
"license": "MIT",
"projectDomain": "push.rocks"
}
},
"npmci": {
"npmGlobalTools": [],
"npmAccessLevel": "public"
}
}

10924
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,28 +1,33 @@
{
"name": "@pushrocks/smartmongo",
"version": "2.0.0",
"name": "@push.rocks/smartmongo",
"version": "7.0.0",
"private": false,
"description": "create a local mongodb for testing",
"main": "dist_ts/index.js",
"typings": "dist_ts/index.d.ts",
"description": "A MongoDB memory server toolkit for testing and development, providing real MongoDB replica sets via mongodb-memory-server.",
"exports": {
".": "./dist_ts/index.js"
},
"type": "module",
"author": "Lossless GmbH",
"author": "Task Venture Capital GmbH",
"license": "MIT",
"scripts": {
"test": "(tstest test/ --web)",
"build": "(tsbuild --web)"
"test": "(tstest test/. --verbose --logfile --timeout 60)",
"build": "(tsbuild tsfolders)",
"buildDocs": "tsdoc"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.61",
"@gitzone/tsbundle": "^2.0.3",
"@gitzone/tstest": "^1.0.71",
"@pushrocks/tapbundle": "^5.0.3",
"@types/node": "^17.0.34"
"@git.zone/tsbuild": "^4.4.0",
"@git.zone/tsbundle": "^2.10.0",
"@git.zone/tsrun": "^2.0.2",
"@git.zone/tstest": "^3.6.1",
"@types/node": "^25.5.0",
"mongodb": "^7.1.1"
},
"dependencies": {
"@pushrocks/smartdata": "^4.0.27",
"@pushrocks/smartpromise": "^3.1.7",
"mongodb-memory-server": "^8.5.2"
"@push.rocks/mongodump": "^1.1.0",
"@push.rocks/smartdata": "^7.1.3",
"@push.rocks/smartpath": "^6.0.0",
"@push.rocks/smartpromise": "^4.2.3",
"mongodb-memory-server": "^11.0.1"
},
"browserslist": [
"last 1 chrome versions"
@@ -36,7 +41,27 @@
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
"npmextra.json",
".smartconfig.json",
"readme.md"
]
],
"keywords": [
"mongodb",
"testing",
"replica set",
"memory server",
"database management",
"typescript"
],
"homepage": "https://code.foss.global/push.rocks/smartmongo#readme",
"repository": {
"type": "git",
"url": "https://code.foss.global/push.rocks/smartmongo.git"
},
"packageManager": "pnpm@10.7.0+sha512.6b865ad4b62a1d9842b61d674a393903b871d9244954f652b8842c2b553c72176b278f64c463e52d40fff8aba385c235c8c9ecf5cc7de4fd78b8bb6d49633ab6",
"bugs": {
"url": "https://code.foss.global/push.rocks/smartmongo/issues"
},
"pnpm": {
"overrides": {}
}
}

8608
pnpm-lock.yaml generated Normal file

File diff suppressed because it is too large Load Diff

84
readme.hints.md Normal file
View File

@@ -0,0 +1,84 @@
# Project Hints
## Deno Compatibility
### mongodb-memory-server Import
- The package uses a **default import** for `mongodb-memory-server` in `ts/smartmongo.plugins.ts`
- Syntax: `import mongoPlugin from 'mongodb-memory-server';`
- This works in both Node.js and Deno environments
- **Why:** Deno wraps CommonJS exports in a `default` property, so default imports are required
- Fixed in version 2.0.13 (changed from `import * as mongoPlugin`)
## TsmDB - MongoDB Wire Protocol Server
### Architecture
TsmDB implements the MongoDB binary wire protocol (OP_MSG, OP_QUERY) allowing official MongoDB drivers to connect directly.
```
Official MongoClient → TCP (wire protocol) → TsmdbServer → Engines → Storage
(mongodb npm) OP_MSG/BSON (port)
```
### Module Structure
```
ts/tsmdb/
├── server/ # Wire protocol server
│ ├── TsmdbServer.ts # TCP server, connection handling
│ ├── WireProtocol.ts # OP_MSG/OP_QUERY parsing & encoding
│ ├── CommandRouter.ts # Route commands to handlers
│ └── handlers/ # Command implementations
│ ├── HelloHandler.ts # hello/isMaster handshake
│ ├── FindHandler.ts # find, getMore, killCursors, count, distinct
│ ├── InsertHandler.ts # insert
│ ├── UpdateHandler.ts # update, findAndModify
│ ├── DeleteHandler.ts # delete
│ ├── AggregateHandler.ts # aggregate
│ ├── IndexHandler.ts # createIndexes, dropIndexes, listIndexes
│ └── AdminHandler.ts # ping, listDatabases, listCollections, etc.
├── engine/ # Core logic (reused)
│ ├── QueryEngine.ts # Query filtering with mingo
│ ├── UpdateEngine.ts # Update operations
│ ├── AggregationEngine.ts # Aggregation pipelines
│ ├── IndexEngine.ts # Index management
│ └── TransactionEngine.ts # Transaction support
├── storage/ # Storage layer
│ ├── IStorageAdapter.ts # Interface
│ ├── MemoryStorageAdapter.ts
│ └── FileStorageAdapter.ts
└── types/interfaces.ts # Type definitions
```
### Usage Example
```typescript
import { TsmdbServer } from '@push.rocks/smartmongo/tsmdb';
import { MongoClient } from 'mongodb';
// Start server
const server = new TsmdbServer({ port: 27117 });
await server.start();
// Connect with official MongoDB driver
const client = new MongoClient('mongodb://127.0.0.1:27117', {
directConnection: true
});
await client.connect();
// Use like any MongoDB instance
const db = client.db('mydb');
await db.collection('users').insertOne({ name: 'John' });
const user = await db.collection('users').findOne({ name: 'John' });
// Cleanup
await client.close();
await server.stop();
```
### Supported Commands
- **Handshake**: hello, isMaster
- **CRUD**: find, insert, update, delete, findAndModify, getMore, killCursors
- **Aggregation**: aggregate, count, distinct
- **Indexes**: createIndexes, dropIndexes, listIndexes
- **Admin**: ping, listDatabases, listCollections, drop, dropDatabase, create, serverStatus, buildInfo

209
readme.md
View File

@@ -1,39 +1,190 @@
# @pushrocks/smartmongo
create a local mongodb for testing
# @push.rocks/smartmongo
## Availabililty and Links
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartmongo)
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartmongo)
* [github.com (source mirror)](https://github.com/pushrocks/smartmongo)
* [docs (typedoc)](https://pushrocks.gitlab.io/smartmongo/)
A MongoDB memory server toolkit for testing and development — spin up real MongoDB replica sets on the fly with zero configuration. 🚀
## Status for master
## Install
Status Category | Status Badge
-- | --
GitLab Pipelines | [![pipeline status](https://gitlab.com/pushrocks/smartmongo/badges/master/pipeline.svg)](https://lossless.cloud)
GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/pushrocks/smartmongo/badges/master/coverage.svg)](https://lossless.cloud)
npm | [![npm downloads per month](https://badgen.net/npm/dy/@pushrocks/smartmongo)](https://lossless.cloud)
Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/pushrocks/smartmongo)](https://lossless.cloud)
TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud)
node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/)
Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud)
PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@pushrocks/smartmongo)](https://lossless.cloud)
PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@pushrocks/smartmongo)](https://lossless.cloud)
BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@pushrocks/smartmongo)](https://lossless.cloud)
Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20Windows%2010/yes/green?icon=windows)](https://lossless.cloud) [![Supports Mac OS X](https://badgen.net/badge/supports%20Mac%20OS%20X/yes/green?icon=apple)](https://lossless.cloud)
```bash
pnpm add -D @push.rocks/smartmongo
# or
npm install @push.rocks/smartmongo --save-dev
```
## Usage
## Issue Reporting and Security
Use TypeScript for best in class intellisense
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
## Contribution
## What It Does
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
`@push.rocks/smartmongo` wraps [mongodb-memory-server](https://github.com/nodkz/mongodb-memory-server) to give you a **real MongoDB replica set** running entirely in memory. It downloads and manages the MongoDB binary for you — just `createAndStart()` and you're good to go.
For further information read the linked docs at the top of this readme.
Perfect for:
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
-**Integration tests** that need 100% MongoDB compatibility
- 🧪 **CI/CD pipelines** where you can't install MongoDB system-wide
- 🔬 **Development environments** that need a disposable database
- 📦 **Data dump/export** with built-in support for dumping collections to disk
[![repo-footer](https://lossless.gitlab.io/publicrelations/repofooter.svg)](https://maintainedby.lossless.com)
> 💡 **Looking for a lightweight, pure-TypeScript alternative?** Check out [`@push.rocks/smartdb`](https://code.foss.global/push.rocks/smartdb) — a wire-protocol-compatible MongoDB server with zero binary dependencies, instant startup, and file-based persistence.
## Quick Start
```typescript
import { SmartMongo } from '@push.rocks/smartmongo';
// Start a MongoDB replica set (downloads binary automatically on first run)
const mongo = await SmartMongo.createAndStart();
// Get connection details for your app or ORM
const descriptor = await mongo.getMongoDescriptor();
console.log(descriptor.mongoDbUrl);
// => mongodb://127.0.0.1:xxxxx/?replicaSet=testset
// Use with any MongoDB client
import { MongoClient } from 'mongodb';
const client = new MongoClient(descriptor.mongoDbUrl);
await client.connect();
const db = client.db(descriptor.mongoDbName);
await db.collection('users').insertOne({ name: 'Alice', role: 'admin' });
const user = await db.collection('users').findOne({ name: 'Alice' });
console.log(user); // { _id: ObjectId(...), name: 'Alice', role: 'admin' }
// Clean up
await client.close();
await mongo.stop();
```
## API
### `SmartMongo.createAndStart(replCount?: number)`
Static factory method that creates and starts a SmartMongo instance.
```typescript
// Single replica (default)
const mongo = await SmartMongo.createAndStart();
// Multi-replica for testing replication scenarios
const mongo = await SmartMongo.createAndStart(3);
```
### `getMongoDescriptor()`
Returns an `IMongoDescriptor` with the connection URL and database name, compatible with `@push.rocks/smartdata` and other push.rocks modules.
```typescript
const descriptor = await mongo.getMongoDescriptor();
// {
// mongoDbName: 'smartmongo_testdatabase',
// mongoDbUrl: 'mongodb://127.0.0.1:xxxxx/?replicaSet=testset'
// }
```
### `stop()`
Stops the replica set and cleans up all resources (temporary files, processes).
```typescript
await mongo.stop();
```
### `stopAndDumpToDir(dir, nameFunction?, emptyDir?)`
Stops the replica set **and** dumps all collections to a directory on disk before cleanup. Useful for debugging or archiving test data.
```typescript
// Dump all collections with default naming
await mongo.stopAndDumpToDir('./test-output');
// With custom file naming
await mongo.stopAndDumpToDir('./test-output', (doc) => `${doc.collection}-${doc._id}.bson`);
// Keep existing files in the directory (don't empty it first)
await mongo.stopAndDumpToDir('./test-output', undefined, false);
```
### `readyPromise`
A promise that resolves when the replica set is fully started and ready to accept connections.
```typescript
const mongo = new SmartMongo();
mongo.start(2); // non-blocking
await mongo.readyPromise; // wait for startup
```
## Testing Examples
### With @git.zone/tstest (tapbundle)
```typescript
import { expect, tap } from '@git.zone/tstest/tapbundle';
import { SmartMongo } from '@push.rocks/smartmongo';
import { MongoClient } from 'mongodb';
let mongo: SmartMongo;
let client: MongoClient;
tap.test('setup', async () => {
mongo = await SmartMongo.createAndStart();
const { mongoDbUrl, mongoDbName } = await mongo.getMongoDescriptor();
client = new MongoClient(mongoDbUrl);
await client.connect();
});
tap.test('should insert and query documents', async () => {
const col = client.db('test').collection('items');
await col.insertOne({ name: 'Widget', price: 9.99 });
const item = await col.findOne({ name: 'Widget' });
expect(item?.price).toEqual(9.99);
});
tap.test('teardown', async () => {
await client.close();
await mongo.stop();
});
export default tap.start();
```
### With @push.rocks/smartdata
```typescript
import { SmartMongo } from '@push.rocks/smartmongo';
import { SmartdataDb } from '@push.rocks/smartdata';
const mongo = await SmartMongo.createAndStart();
const descriptor = await mongo.getMongoDescriptor();
const db = new SmartdataDb(descriptor);
await db.init();
// Use smartdata models against the memory server...
await db.close();
await mongo.stop();
```
## License and Legal Information
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
### Company Information
Task Venture Capital GmbH
Registered at District Court Bremen HRB 35230 HB, Germany
For any legal inquiries or further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.

View File

@@ -1,4 +1,4 @@
import { expect, tap } from '@pushrocks/tapbundle';
import { tap } from '@git.zone/tstest/tapbundle';
import * as smartmongo from '../ts/index.js';
let smartmongoInstance: smartmongo.SmartMongo;
@@ -8,7 +8,7 @@ tap.test('should create a mongo instance', async () => {
});
tap.test('should stop the instance', async () => {
await smartmongoInstance.stop();
})
await smartmongoInstance.stopAndDumpToDir('.nogit/');
});
tap.start();
export default tap.start();

View File

@@ -1,8 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
* autocreated commitinfo by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '@pushrocks/smartmongo',
version: '2.0.0',
description: 'create a local mongodb for testing'
name: '@push.rocks/smartmongo',
version: '7.0.0',
description: 'A MongoDB memory server toolkit for testing and development, providing real MongoDB replica sets via mongodb-memory-server.'
}

71
ts/classes.smartmongo.ts Normal file
View File

@@ -0,0 +1,71 @@
import { commitinfo } from './00_commitinfo_data.js';
import * as plugins from './plugins.js';
export class SmartMongo {
// STATIC
public static async createAndStart(replCountArg: number = 1) {
const smartMongoInstance = new SmartMongo();
await smartMongoInstance.start(replCountArg);
return smartMongoInstance;
}
// INSTANCE
private _readyDeferred = plugins.smartpromise.defer();
public readyPromise = this._readyDeferred.promise;
public mongoReplicaSet!: plugins.mongoPlugin.MongoMemoryReplSet;
constructor() {}
public async start(countArg: number = 1) {
this.mongoReplicaSet = await plugins.mongoPlugin.MongoMemoryReplSet.create({
replSet: { count: countArg },
instanceOpts: [
{
storageEngine: 'wiredTiger',
},
],
});
this._readyDeferred.resolve();
console.log(`mongoReplicaSet with ${countArg} replicas started.`);
console.log(`@pushrocks/smartmongo version ${commitinfo.version}`);
}
/**
* returns a mongo descriptor for modules like
* @pushrocks/smartfile.
*/
public async getMongoDescriptor(): Promise<plugins.smartdata.IMongoDescriptor> {
await this.readyPromise;
return {
mongoDbName: `smartmongo_testdatabase`,
mongoDbUrl: this.mongoReplicaSet.getUri(),
};
}
/**
* stops the smartmongo instance
* and cleans up after itself
*/
public async stop() {
await this.mongoReplicaSet.stop();
await this.mongoReplicaSet.cleanup();
}
/**
* like stop() but allows you to actually store
* the database on disk
*/
public async stopAndDumpToDir(
dirArg: string,
nameFunctionArg?: (doc: any) => string,
emptyDirArg = true,
) {
const mongodumpInstance = new plugins.mongodump.MongoDump();
const mongodumpTarget = await mongodumpInstance.addMongoTargetByMongoDescriptor(
await this.getMongoDescriptor(),
);
await mongodumpTarget.dumpAllCollectionsToDir(dirArg, nameFunctionArg, emptyDirArg);
await mongodumpInstance.stop();
await this.stop();
}
}

View File

@@ -1,37 +1,4 @@
import { commitinfo } from './00_commitinfo_data.js';
import * as plugins from './smartmongo.plugins.js';
export class SmartMongo {
// STATIC
public static async createAndStart(replCountArg: number = 1) {
const smartMongoInstance = new SmartMongo();
await smartMongoInstance.start(replCountArg);
return smartMongoInstance;
}
// INSTANCE
private _readyDeferred = plugins.smartpromise.defer();
public readyPromise = this._readyDeferred.promise;
public mongoReplicaSet: plugins.mongoPlugin.MongoMemoryReplSet;
constructor() {
}
public async start(countArg: number = 1) {
this.mongoReplicaSet = await plugins.mongoPlugin.MongoMemoryReplSet.create({ replSet: { count: countArg } });
this._readyDeferred.resolve();
console.log(`mongoReplicaSet with ${countArg} replicas started.`);
console.log(`@pushrocks/smartmongo version ${commitinfo.version}`);
}
public async getMongoDescriptor(): Promise<plugins.smartdata.IMongoDescriptor> {
await this.readyPromise;
return {
mongoDbUrl: this.mongoReplicaSet.getUri(),
}
}
public async stop() {
await this.mongoReplicaSet.stop(true);
}
}
export { SmartMongo } from './classes.smartmongo.js';
export { commitinfo };

12
ts/plugins.ts Normal file
View File

@@ -0,0 +1,12 @@
// @pushrocks scope
import * as mongodump from '@push.rocks/mongodump';
import * as smartdata from '@push.rocks/smartdata';
import * as smartpath from '@push.rocks/smartpath';
import * as smartpromise from '@push.rocks/smartpromise';
export { mongodump, smartdata, smartpath, smartpromise };
// thirdparty
import mongoPlugin from 'mongodb-memory-server';
export { mongoPlugin };

View File

@@ -1,13 +0,0 @@
// @pushrocks scope
import * as smartdata from '@pushrocks/smartdata';
import * as smartpromise from '@pushrocks/smartpromise';
export {
smartdata,
smartpromise,
}
// thirdparty
import * as mongoPlugin from 'mongodb-memory-server';
export { mongoPlugin };

View File

@@ -1,9 +1,12 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "nodenext"
}
"module": "NodeNext",
"moduleResolution": "NodeNext",
"esModuleInterop": true,
"verbatimModuleSyntax": true
},
"exclude": [
"dist_*/**/*.d.ts"
]
}