@gravito/dark-matter 1.1.1 → 1.1.2

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/README.md CHANGED
@@ -35,18 +35,30 @@ const users = await Mongo.collection('users')
35
35
  await Mongo.disconnect()
36
36
  ```
37
37
 
38
- ## Features
39
-
40
- - 🚀 **Bun Native** - Optimized for Bun runtime
41
- - 🎯 **Laravel-style API** - Familiar fluent interface
42
- - 🔍 **Query Builder** - Type-safe query building
43
- - 📊 **Aggregation Pipeline** - Fluent aggregation API
44
- - 🔌 **Multi-connection** - Named connections support
45
- - 🛡️ **Transactions** - ACID transactions with convenient API
46
- - 🗑️ **Soft Deletes** - Built-in soft delete support with restore capability
47
- - 📦 **GridFS** - Handle large file uploads/downloads
48
- - ⚡ **Change Streams** - Real-time database event listening
49
- - **Schema Validation** - Type-safe Schema Builder API for MongoDB validation
38
+ ## Features
39
+
40
+ - 🚀 **Bun Native Performance**: Optimized for the Bun runtime with zero-copy data handling.
41
+ - 🌌 **Galaxy-Ready Persistence**: Native integration with PlanetCore for universal NoSQL data management.
42
+ - 🎯 **Laravel-style API**: Familiar, fluent interface for MongoDB collections and aggregation pipelines.
43
+ - 🛡️ **Distributed Document State**: ACID transactions and robust multi-connection management across the Galaxy.
44
+ - 🗑️ **Soft Deletes**: Built-in logic for logical record deletion with restoration support.
45
+ - 📦 **GridFS & Streams**: Specialized support for large-scale file storage and real-time change listening.
46
+
47
+ ## 🌌 Role in Galaxy Architecture
48
+
49
+ In the **Gravito Galaxy Architecture**, Dark Matter acts as the **MongoDB Gravity Core (NoSQL Persistence)**.
50
+
51
+ - **Document Focus**: Provides an alternative gravity core for Satellites that require schema-less flexibility or massive-scale document storage.
52
+ - **Micro-State Bridge**: Enables real-time reactive logic via MongoDB Change Streams, allowing one Satellite to react instantly to data changes in another.
53
+ - **File Distribution**: Leverages GridFS to provide a distributed file storage layer that works alongside `@gravito/nebula`.
54
+
55
+ ```mermaid
56
+ graph TD
57
+ S1[Satellite: Analytics] -- "Save" --> DM{Dark Matter}
58
+ S2[Satellite: Logs] -- "Query" --> DM
59
+ DM -->|Native Driver| MongoDB[(MongoDB Atlas)]
60
+ DM -.->|Watch| Realtime[Real-time Events]
61
+ ```
50
62
 
51
63
  ## API Reference
52
64
 
package/dist/index.cjs CHANGED
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -1146,17 +1145,27 @@ var MongoClient = class {
1146
1145
  if (this.config.socketTimeoutMS) {
1147
1146
  options.socketTimeoutMS = this.config.socketTimeoutMS;
1148
1147
  }
1149
- this.client = new this.mongodb.MongoClient(uri, options);
1150
1148
  let lastError = null;
1151
1149
  for (let attempt = 0; attempt <= config.maxRetries; attempt++) {
1150
+ const client = new this.mongodb.MongoClient(uri, options);
1151
+ this.client = client;
1152
1152
  try {
1153
- await this.client.connect();
1153
+ await client.connect();
1154
1154
  const dbName = this.config.database ?? "test";
1155
- this.db = this.client.db(dbName);
1155
+ this.db = client.db(dbName);
1156
1156
  this.connected = true;
1157
1157
  return;
1158
1158
  } catch (error) {
1159
1159
  lastError = error;
1160
+ this.connected = false;
1161
+ this.db = null;
1162
+ try {
1163
+ await client.close();
1164
+ } catch {
1165
+ }
1166
+ if (this.client === client) {
1167
+ this.client = null;
1168
+ }
1160
1169
  if (attempt < config.maxRetries) {
1161
1170
  const delay = config.retryDelayMs * config.backoffMultiplier ** attempt;
1162
1171
  await new Promise((resolve) => setTimeout(resolve, delay));
package/dist/index.d.cts CHANGED
@@ -1035,7 +1035,7 @@ declare class MongoQueryBuilder<T = Document> implements MongoCollectionContract
1035
1035
  private limitCount;
1036
1036
  private skipCount;
1037
1037
  private softDeleteMode;
1038
- constructor(nativeCollection: MongoNativeCollection, collectionName: string, session?: unknown | undefined);
1038
+ constructor(nativeCollection: MongoNativeCollection, collectionName: string, session?: unknown);
1039
1039
  /**
1040
1040
  * Adds a basic WHERE clause to the query.
1041
1041
  *
package/dist/index.d.ts CHANGED
@@ -1035,7 +1035,7 @@ declare class MongoQueryBuilder<T = Document> implements MongoCollectionContract
1035
1035
  private limitCount;
1036
1036
  private skipCount;
1037
1037
  private softDeleteMode;
1038
- constructor(nativeCollection: MongoNativeCollection, collectionName: string, session?: unknown | undefined);
1038
+ constructor(nativeCollection: MongoNativeCollection, collectionName: string, session?: unknown);
1039
1039
  /**
1040
1040
  * Adds a basic WHERE clause to the query.
1041
1041
  *
package/dist/index.js CHANGED
@@ -1102,17 +1102,27 @@ var MongoClient = class {
1102
1102
  if (this.config.socketTimeoutMS) {
1103
1103
  options.socketTimeoutMS = this.config.socketTimeoutMS;
1104
1104
  }
1105
- this.client = new this.mongodb.MongoClient(uri, options);
1106
1105
  let lastError = null;
1107
1106
  for (let attempt = 0; attempt <= config.maxRetries; attempt++) {
1107
+ const client = new this.mongodb.MongoClient(uri, options);
1108
+ this.client = client;
1108
1109
  try {
1109
- await this.client.connect();
1110
+ await client.connect();
1110
1111
  const dbName = this.config.database ?? "test";
1111
- this.db = this.client.db(dbName);
1112
+ this.db = client.db(dbName);
1112
1113
  this.connected = true;
1113
1114
  return;
1114
1115
  } catch (error) {
1115
1116
  lastError = error;
1117
+ this.connected = false;
1118
+ this.db = null;
1119
+ try {
1120
+ await client.close();
1121
+ } catch {
1122
+ }
1123
+ if (this.client === client) {
1124
+ this.client = null;
1125
+ }
1116
1126
  if (attempt < config.maxRetries) {
1117
1127
  const delay = config.retryDelayMs * config.backoffMultiplier ** attempt;
1118
1128
  await new Promise((resolve) => setTimeout(resolve, delay));
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@gravito/dark-matter",
3
- "version": "1.1.1",
3
+ "sideEffects": false,
4
+ "version": "1.1.2",
4
5
  "description": "MongoDB client for Gravito - Bun native, Laravel-style API",
5
6
  "type": "module",
6
7
  "main": "./dist/index.js",
@@ -14,6 +15,7 @@
14
15
  },
15
16
  "scripts": {
16
17
  "build": "bun run build.ts",
18
+ "build:dts": "bun run build.ts --dts-only",
17
19
  "test": "bun test --timeout=10000",
18
20
  "typecheck": "bun tsc -p tsconfig.json --noEmit --skipLibCheck",
19
21
  "test:coverage": "bun test --timeout=10000 --coverage --coverage-reporter=lcov --coverage-dir coverage && bun run --bun scripts/check-coverage.ts",
@@ -26,7 +28,7 @@
26
28
  "bench:schema": "MONGODB_URI=mongodb://localhost:27017 bun test benchmarks/schema-validation.bench.ts",
27
29
  "bench:transactions": "MONGODB_URI=mongodb://localhost:27017 bun test benchmarks/transactions.bench.ts",
28
30
  "bench:change-streams": "MONGODB_URI=mongodb://localhost:27017 bun test benchmarks/change-streams.bench.ts",
29
- "test:unit": "bun test tests/ --timeout=10000",
31
+ "test:unit": "bun test $(find tests -name '*.test.ts' ! -name '*.integration.test.ts' 2>/dev/null | tr '\\n' ' ') --timeout=10000",
30
32
  "test:integration": "test $(find tests -name '*.integration.test.ts' 2>/dev/null | wc -l) -gt 0 && find tests -name '*.integration.test.ts' -print0 | xargs -0 bun test --timeout=10000 || echo 'No integration tests found'"
31
33
  },
32
34
  "files": [