@gravito/dark-matter 1.1.2 → 2.0.0

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/dist/index.cjs CHANGED
@@ -29,6 +29,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  // src/index.ts
30
30
  var index_exports = {};
31
31
  __export(index_exports, {
32
+ DarkMatterError: () => DarkMatterError,
33
+ DarkMatterErrorCodes: () => DarkMatterErrorCodes,
32
34
  Mongo: () => Mongo,
33
35
  MongoAggregateBuilder: () => MongoAggregateBuilder,
34
36
  MongoClient: () => MongoClient,
@@ -41,6 +43,25 @@ __export(index_exports, {
41
43
  });
42
44
  module.exports = __toCommonJS(index_exports);
43
45
 
46
+ // src/errors/DarkMatterError.ts
47
+ var import_core = require("@gravito/core");
48
+ var DarkMatterError = class extends import_core.InfrastructureException {
49
+ constructor(status, code, options = {}) {
50
+ super(status, code, options);
51
+ this.name = "DarkMatterError";
52
+ Object.setPrototypeOf(this, new.target.prototype);
53
+ }
54
+ };
55
+
56
+ // src/errors/codes.ts
57
+ var DarkMatterErrorCodes = {
58
+ CONNECTION_FAILED: "dark_matter.connection_failed",
59
+ NOT_CONNECTED: "dark_matter.not_connected",
60
+ CONNECTION_NOT_CONFIGURED: "dark_matter.connection_not_configured",
61
+ GRIDFS_NOT_INITIALIZED: "dark_matter.gridfs_not_initialized",
62
+ OPERATION_FAILED: "dark_matter.operation_failed"
63
+ };
64
+
44
65
  // src/MongoQueryBuilder.ts
45
66
  var MongoQueryBuilder = class _MongoQueryBuilder {
46
67
  constructor(nativeCollection, collectionName, session) {
@@ -1172,9 +1193,11 @@ var MongoClient = class {
1172
1193
  }
1173
1194
  }
1174
1195
  }
1175
- throw new Error(
1176
- `Failed to connect to MongoDB after ${config.maxRetries + 1} attempts: ${lastError?.message}`
1177
- );
1196
+ throw new DarkMatterError(503, DarkMatterErrorCodes.CONNECTION_FAILED, {
1197
+ message: `Failed to connect to MongoDB after ${config.maxRetries + 1} attempts: ${lastError?.message}`,
1198
+ cause: lastError,
1199
+ retryable: true
1200
+ });
1178
1201
  }
1179
1202
  /**
1180
1203
  * Closes the connection to the MongoDB server.
@@ -1364,20 +1387,24 @@ var MongoClient = class {
1364
1387
  const mongodb = await import("mongodb");
1365
1388
  return mongodb;
1366
1389
  } catch {
1367
- throw new Error(
1368
- 'MongoDB client requires the "mongodb" package. Please install it: bun add mongodb'
1369
- );
1390
+ throw new DarkMatterError(500, DarkMatterErrorCodes.CONNECTION_FAILED, {
1391
+ message: 'MongoDB client requires the "mongodb" package. Please install it: bun add mongodb'
1392
+ });
1370
1393
  }
1371
1394
  }
1372
1395
  getClient() {
1373
1396
  if (!this.client) {
1374
- throw new Error("MongoDB client not connected. Call connect() first.");
1397
+ throw new DarkMatterError(503, DarkMatterErrorCodes.NOT_CONNECTED, {
1398
+ message: "MongoDB client not connected. Call connect() first."
1399
+ });
1375
1400
  }
1376
1401
  return this.client;
1377
1402
  }
1378
1403
  getDatabase() {
1379
1404
  if (!this.db) {
1380
- throw new Error("MongoDB client not connected. Call connect() first.");
1405
+ throw new DarkMatterError(503, DarkMatterErrorCodes.NOT_CONNECTED, {
1406
+ message: "MongoDB client not connected. Call connect() first."
1407
+ });
1381
1408
  }
1382
1409
  return this.db;
1383
1410
  }
@@ -1500,7 +1527,9 @@ var MongoManager = class {
1500
1527
  if (!this.connections.has(connectionName)) {
1501
1528
  const config = this.configs.get(connectionName);
1502
1529
  if (!config) {
1503
- throw new Error(`MongoDB connection "${connectionName}" not configured`);
1530
+ throw new DarkMatterError(500, DarkMatterErrorCodes.CONNECTION_NOT_CONFIGURED, {
1531
+ message: `MongoDB connection "${connectionName}" not configured`
1532
+ });
1504
1533
  }
1505
1534
  this.connections.set(connectionName, new MongoClient(config));
1506
1535
  }
@@ -2004,7 +2033,10 @@ var MongoGridFS = class {
2004
2033
  }
2005
2034
  async ensureBucket() {
2006
2035
  if (!this.bucket) {
2007
- throw new Error("GridFS bucket not initialized. Please wait a moment after creation.");
2036
+ throw new DarkMatterError(503, DarkMatterErrorCodes.GRIDFS_NOT_INITIALIZED, {
2037
+ message: "GridFS bucket not initialized. Please wait a moment after creation.",
2038
+ retryable: true
2039
+ });
2008
2040
  }
2009
2041
  }
2010
2042
  };
@@ -2314,6 +2346,8 @@ function schema() {
2314
2346
  }
2315
2347
  // Annotate the CommonJS export names for ESM import in node:
2316
2348
  0 && (module.exports = {
2349
+ DarkMatterError,
2350
+ DarkMatterErrorCodes,
2317
2351
  Mongo,
2318
2352
  MongoAggregateBuilder,
2319
2353
  MongoClient,
package/dist/index.d.cts CHANGED
@@ -1,3 +1,27 @@
1
+ import { InfrastructureException, InfrastructureExceptionOptions } from '@gravito/core';
2
+
3
+ /**
4
+ * Error codes for the dark-matter package.
5
+ * @public
6
+ */
7
+ declare const DarkMatterErrorCodes: {
8
+ readonly CONNECTION_FAILED: "dark_matter.connection_failed";
9
+ readonly NOT_CONNECTED: "dark_matter.not_connected";
10
+ readonly CONNECTION_NOT_CONFIGURED: "dark_matter.connection_not_configured";
11
+ readonly GRIDFS_NOT_INITIALIZED: "dark_matter.gridfs_not_initialized";
12
+ readonly OPERATION_FAILED: "dark_matter.operation_failed";
13
+ };
14
+ type DarkMatterErrorCode = (typeof DarkMatterErrorCodes)[keyof typeof DarkMatterErrorCodes];
15
+
16
+ /**
17
+ * Concrete error class for the dark-matter (MongoDB) package.
18
+ * Extends InfrastructureException to participate in the GravitoException hierarchy.
19
+ * @public
20
+ */
21
+ declare class DarkMatterError extends InfrastructureException {
22
+ constructor(status: number, code: DarkMatterErrorCode, options?: InfrastructureExceptionOptions);
23
+ }
24
+
1
25
  /**
2
26
  * @gravito/dark-matter - Type Definitions
3
27
  */
@@ -1953,4 +1977,4 @@ declare class MongoSchemaBuilder {
1953
1977
  */
1954
1978
  declare function schema(): MongoSchemaBuilder;
1955
1979
 
1956
- export { type BulkWriteOperation, type BulkWriteResult, type DeleteResult, type Document$1 as Document, type FilterDocument, type FilterOperator, type GridFSFile, type GridFSUploadOptions, type GridFSUploadProgress, type InsertManyResult, type InsertResult, type LookupOptions, Mongo, MongoAggregateBuilder, type MongoAggregateContract, MongoClient, type MongoClientContract, type MongoCollectionContract, type MongoConfig, type MongoDatabaseContract, MongoGridFS, MongoManager, type MongoManagerConfig, MongoPoolMonitor, MongoQueryBuilder, MongoSchemaBuilder, type MongoSession, type PipelineStage, type PoolMetrics, type Projection, type RetryConfig, type SchemaValidationOptions, type SoftDeletableDocument, type SortDirection, type SortSpec, type TransactionOptions, type UpdateDocument, type UpdateResult, schema };
1980
+ export { type BulkWriteOperation, type BulkWriteResult, DarkMatterError, type DarkMatterErrorCode, DarkMatterErrorCodes, type DeleteResult, type Document$1 as Document, type FilterDocument, type FilterOperator, type GridFSFile, type GridFSUploadOptions, type GridFSUploadProgress, type InsertManyResult, type InsertResult, type LookupOptions, Mongo, MongoAggregateBuilder, type MongoAggregateContract, MongoClient, type MongoClientContract, type MongoCollectionContract, type MongoConfig, type MongoDatabaseContract, MongoGridFS, MongoManager, type MongoManagerConfig, MongoPoolMonitor, MongoQueryBuilder, MongoSchemaBuilder, type MongoSession, type PipelineStage, type PoolMetrics, type Projection, type RetryConfig, type SchemaValidationOptions, type SoftDeletableDocument, type SortDirection, type SortSpec, type TransactionOptions, type UpdateDocument, type UpdateResult, schema };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,27 @@
1
+ import { InfrastructureException, InfrastructureExceptionOptions } from '@gravito/core';
2
+
3
+ /**
4
+ * Error codes for the dark-matter package.
5
+ * @public
6
+ */
7
+ declare const DarkMatterErrorCodes: {
8
+ readonly CONNECTION_FAILED: "dark_matter.connection_failed";
9
+ readonly NOT_CONNECTED: "dark_matter.not_connected";
10
+ readonly CONNECTION_NOT_CONFIGURED: "dark_matter.connection_not_configured";
11
+ readonly GRIDFS_NOT_INITIALIZED: "dark_matter.gridfs_not_initialized";
12
+ readonly OPERATION_FAILED: "dark_matter.operation_failed";
13
+ };
14
+ type DarkMatterErrorCode = (typeof DarkMatterErrorCodes)[keyof typeof DarkMatterErrorCodes];
15
+
16
+ /**
17
+ * Concrete error class for the dark-matter (MongoDB) package.
18
+ * Extends InfrastructureException to participate in the GravitoException hierarchy.
19
+ * @public
20
+ */
21
+ declare class DarkMatterError extends InfrastructureException {
22
+ constructor(status: number, code: DarkMatterErrorCode, options?: InfrastructureExceptionOptions);
23
+ }
24
+
1
25
  /**
2
26
  * @gravito/dark-matter - Type Definitions
3
27
  */
@@ -1953,4 +1977,4 @@ declare class MongoSchemaBuilder {
1953
1977
  */
1954
1978
  declare function schema(): MongoSchemaBuilder;
1955
1979
 
1956
- export { type BulkWriteOperation, type BulkWriteResult, type DeleteResult, type Document$1 as Document, type FilterDocument, type FilterOperator, type GridFSFile, type GridFSUploadOptions, type GridFSUploadProgress, type InsertManyResult, type InsertResult, type LookupOptions, Mongo, MongoAggregateBuilder, type MongoAggregateContract, MongoClient, type MongoClientContract, type MongoCollectionContract, type MongoConfig, type MongoDatabaseContract, MongoGridFS, MongoManager, type MongoManagerConfig, MongoPoolMonitor, MongoQueryBuilder, MongoSchemaBuilder, type MongoSession, type PipelineStage, type PoolMetrics, type Projection, type RetryConfig, type SchemaValidationOptions, type SoftDeletableDocument, type SortDirection, type SortSpec, type TransactionOptions, type UpdateDocument, type UpdateResult, schema };
1980
+ export { type BulkWriteOperation, type BulkWriteResult, DarkMatterError, type DarkMatterErrorCode, DarkMatterErrorCodes, type DeleteResult, type Document$1 as Document, type FilterDocument, type FilterOperator, type GridFSFile, type GridFSUploadOptions, type GridFSUploadProgress, type InsertManyResult, type InsertResult, type LookupOptions, Mongo, MongoAggregateBuilder, type MongoAggregateContract, MongoClient, type MongoClientContract, type MongoCollectionContract, type MongoConfig, type MongoDatabaseContract, MongoGridFS, MongoManager, type MongoManagerConfig, MongoPoolMonitor, MongoQueryBuilder, MongoSchemaBuilder, type MongoSession, type PipelineStage, type PoolMetrics, type Projection, type RetryConfig, type SchemaValidationOptions, type SoftDeletableDocument, type SortDirection, type SortSpec, type TransactionOptions, type UpdateDocument, type UpdateResult, schema };
package/dist/index.js CHANGED
@@ -1,3 +1,22 @@
1
+ // src/errors/DarkMatterError.ts
2
+ import { InfrastructureException } from "@gravito/core";
3
+ var DarkMatterError = class extends InfrastructureException {
4
+ constructor(status, code, options = {}) {
5
+ super(status, code, options);
6
+ this.name = "DarkMatterError";
7
+ Object.setPrototypeOf(this, new.target.prototype);
8
+ }
9
+ };
10
+
11
+ // src/errors/codes.ts
12
+ var DarkMatterErrorCodes = {
13
+ CONNECTION_FAILED: "dark_matter.connection_failed",
14
+ NOT_CONNECTED: "dark_matter.not_connected",
15
+ CONNECTION_NOT_CONFIGURED: "dark_matter.connection_not_configured",
16
+ GRIDFS_NOT_INITIALIZED: "dark_matter.gridfs_not_initialized",
17
+ OPERATION_FAILED: "dark_matter.operation_failed"
18
+ };
19
+
1
20
  // src/MongoQueryBuilder.ts
2
21
  var MongoQueryBuilder = class _MongoQueryBuilder {
3
22
  constructor(nativeCollection, collectionName, session) {
@@ -1129,9 +1148,11 @@ var MongoClient = class {
1129
1148
  }
1130
1149
  }
1131
1150
  }
1132
- throw new Error(
1133
- `Failed to connect to MongoDB after ${config.maxRetries + 1} attempts: ${lastError?.message}`
1134
- );
1151
+ throw new DarkMatterError(503, DarkMatterErrorCodes.CONNECTION_FAILED, {
1152
+ message: `Failed to connect to MongoDB after ${config.maxRetries + 1} attempts: ${lastError?.message}`,
1153
+ cause: lastError,
1154
+ retryable: true
1155
+ });
1135
1156
  }
1136
1157
  /**
1137
1158
  * Closes the connection to the MongoDB server.
@@ -1321,20 +1342,24 @@ var MongoClient = class {
1321
1342
  const mongodb = await import("mongodb");
1322
1343
  return mongodb;
1323
1344
  } catch {
1324
- throw new Error(
1325
- 'MongoDB client requires the "mongodb" package. Please install it: bun add mongodb'
1326
- );
1345
+ throw new DarkMatterError(500, DarkMatterErrorCodes.CONNECTION_FAILED, {
1346
+ message: 'MongoDB client requires the "mongodb" package. Please install it: bun add mongodb'
1347
+ });
1327
1348
  }
1328
1349
  }
1329
1350
  getClient() {
1330
1351
  if (!this.client) {
1331
- throw new Error("MongoDB client not connected. Call connect() first.");
1352
+ throw new DarkMatterError(503, DarkMatterErrorCodes.NOT_CONNECTED, {
1353
+ message: "MongoDB client not connected. Call connect() first."
1354
+ });
1332
1355
  }
1333
1356
  return this.client;
1334
1357
  }
1335
1358
  getDatabase() {
1336
1359
  if (!this.db) {
1337
- throw new Error("MongoDB client not connected. Call connect() first.");
1360
+ throw new DarkMatterError(503, DarkMatterErrorCodes.NOT_CONNECTED, {
1361
+ message: "MongoDB client not connected. Call connect() first."
1362
+ });
1338
1363
  }
1339
1364
  return this.db;
1340
1365
  }
@@ -1457,7 +1482,9 @@ var MongoManager = class {
1457
1482
  if (!this.connections.has(connectionName)) {
1458
1483
  const config = this.configs.get(connectionName);
1459
1484
  if (!config) {
1460
- throw new Error(`MongoDB connection "${connectionName}" not configured`);
1485
+ throw new DarkMatterError(500, DarkMatterErrorCodes.CONNECTION_NOT_CONFIGURED, {
1486
+ message: `MongoDB connection "${connectionName}" not configured`
1487
+ });
1461
1488
  }
1462
1489
  this.connections.set(connectionName, new MongoClient(config));
1463
1490
  }
@@ -1961,7 +1988,10 @@ var MongoGridFS = class {
1961
1988
  }
1962
1989
  async ensureBucket() {
1963
1990
  if (!this.bucket) {
1964
- throw new Error("GridFS bucket not initialized. Please wait a moment after creation.");
1991
+ throw new DarkMatterError(503, DarkMatterErrorCodes.GRIDFS_NOT_INITIALIZED, {
1992
+ message: "GridFS bucket not initialized. Please wait a moment after creation.",
1993
+ retryable: true
1994
+ });
1965
1995
  }
1966
1996
  }
1967
1997
  };
@@ -2270,6 +2300,8 @@ function schema() {
2270
2300
  return new MongoSchemaBuilder();
2271
2301
  }
2272
2302
  export {
2303
+ DarkMatterError,
2304
+ DarkMatterErrorCodes,
2273
2305
  Mongo,
2274
2306
  MongoAggregateBuilder,
2275
2307
  MongoClient,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gravito/dark-matter",
3
3
  "sideEffects": false,
4
- "version": "1.1.2",
4
+ "version": "2.0.0",
5
5
  "description": "MongoDB client for Gravito - Bun native, Laravel-style API",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",