@hemia/db-connector 0.0.1 → 0.0.3
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/hemia-db-connector.esm.js +17 -5
- package/dist/hemia-db-connector.js +18 -12
- package/dist/types/Core/MongoDBConnector.d.ts +1 -0
- package/dist/types/abstract/NoSQLConnector.d.ts +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/types/CredentialsConnection.d.ts +1 -0
- package/package.json +2 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
export
|
|
1
|
+
import mongoose__default from 'mongoose';
|
|
2
|
+
export * from 'mongoose';
|
|
3
3
|
import { ValidationError, DatabaseError, AccessDeniedError, Sequelize } from 'sequelize';
|
|
4
4
|
export { DataTypes, Model as ModelSequelize, Op, QueryTypes, Sequelize, Transaction, fn } from 'sequelize';
|
|
5
5
|
|
|
@@ -65,7 +65,7 @@ class MongoDBConnector extends NoSQLConnector {
|
|
|
65
65
|
this.currentSession = null;
|
|
66
66
|
this.config = param;
|
|
67
67
|
this.provider = DBNoSQLType.MongoDB;
|
|
68
|
-
this.mongooseConnection =
|
|
68
|
+
this.mongooseConnection = mongoose__default.connection;
|
|
69
69
|
}
|
|
70
70
|
connect() {
|
|
71
71
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -73,12 +73,13 @@ class MongoDBConnector extends NoSQLConnector {
|
|
|
73
73
|
if (this.mongooseConnection.readyState === 1) {
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
|
-
yield
|
|
76
|
+
yield mongoose__default.connect(`mongodb://${this.config.host}:${this.config.port || 27017}`, {
|
|
77
77
|
user: this.config.user,
|
|
78
78
|
pass: this.config.password,
|
|
79
79
|
dbName: this.config.database,
|
|
80
|
+
authSource: this.config.authSource
|
|
80
81
|
});
|
|
81
|
-
this.mongooseConnection =
|
|
82
|
+
this.mongooseConnection = mongoose__default.connection;
|
|
82
83
|
console.log('Connected to MongoDB');
|
|
83
84
|
}
|
|
84
85
|
catch (error) {
|
|
@@ -277,6 +278,17 @@ class MongoDBConnector extends NoSQLConnector {
|
|
|
277
278
|
}
|
|
278
279
|
});
|
|
279
280
|
}
|
|
281
|
+
executeWithModel(model, operation, session) {
|
|
282
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
283
|
+
try {
|
|
284
|
+
return yield operation(model, session);
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
console.error('Error en operación personalizada:', error);
|
|
288
|
+
throw error;
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
}
|
|
280
292
|
}
|
|
281
293
|
|
|
282
294
|
class NoSQLConnectionManager {
|
|
@@ -77,6 +77,7 @@ class MongoDBConnector extends NoSQLConnector {
|
|
|
77
77
|
user: this.config.user,
|
|
78
78
|
pass: this.config.password,
|
|
79
79
|
dbName: this.config.database,
|
|
80
|
+
authSource: this.config.authSource
|
|
80
81
|
});
|
|
81
82
|
this.mongooseConnection = mongoose.connection;
|
|
82
83
|
console.log('Connected to MongoDB');
|
|
@@ -277,6 +278,17 @@ class MongoDBConnector extends NoSQLConnector {
|
|
|
277
278
|
}
|
|
278
279
|
});
|
|
279
280
|
}
|
|
281
|
+
executeWithModel(model, operation, session) {
|
|
282
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
283
|
+
try {
|
|
284
|
+
return yield operation(model, session);
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
console.error('Error en operación personalizada:', error);
|
|
288
|
+
throw error;
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
}
|
|
280
292
|
}
|
|
281
293
|
|
|
282
294
|
class NoSQLConnectionManager {
|
|
@@ -567,18 +579,6 @@ class DBConnector {
|
|
|
567
579
|
}
|
|
568
580
|
DBConnector.instance = null;
|
|
569
581
|
|
|
570
|
-
Object.defineProperty(exports, "Document", {
|
|
571
|
-
enumerable: true,
|
|
572
|
-
get: function () { return mongoose.Document; }
|
|
573
|
-
});
|
|
574
|
-
Object.defineProperty(exports, "Model", {
|
|
575
|
-
enumerable: true,
|
|
576
|
-
get: function () { return mongoose.Model; }
|
|
577
|
-
});
|
|
578
|
-
Object.defineProperty(exports, "Schema", {
|
|
579
|
-
enumerable: true,
|
|
580
|
-
get: function () { return mongoose.Schema; }
|
|
581
|
-
});
|
|
582
582
|
Object.defineProperty(exports, "DataTypes", {
|
|
583
583
|
enumerable: true,
|
|
584
584
|
get: function () { return sequelize.DataTypes; }
|
|
@@ -612,3 +612,9 @@ exports.DBError = DBError;
|
|
|
612
612
|
exports.MySQLConnectionError = MySQLConnectionError;
|
|
613
613
|
exports.NoSQLConnector = NoSQLConnector;
|
|
614
614
|
exports.SqlConnector = SqlConnector;
|
|
615
|
+
Object.keys(mongoose).forEach(function (k) {
|
|
616
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
617
|
+
enumerable: true,
|
|
618
|
+
get: function () { return mongoose[k]; }
|
|
619
|
+
});
|
|
620
|
+
});
|
|
@@ -27,4 +27,5 @@ export declare class MongoDBConnector extends NoSQLConnector {
|
|
|
27
27
|
deleteById<T extends Document>(model: Model<T>, id: string, session?: ClientSession): Promise<boolean>;
|
|
28
28
|
findAllFromMultipleModels<U extends Document>(models: Array<Model<U>>, filter: object): Promise<U[]>;
|
|
29
29
|
aggregate<T extends Document>(model: Model<T>, pipeline: mongoose.PipelineStage[], options?: AggregateOptions): Promise<any[]>;
|
|
30
|
+
executeWithModel<T extends Document, R>(model: Model<T>, operation: (model: Model<T>, session?: ClientSession) => Promise<R>, session?: ClientSession): Promise<R>;
|
|
30
31
|
}
|
|
@@ -37,4 +37,5 @@ export declare abstract class NoSQLConnector {
|
|
|
37
37
|
abstract findAllFromMultipleModels<U extends Document>(models: Array<Model<U>>, filter: object): Promise<U[]>;
|
|
38
38
|
abstract aggregate<T>(model: any, pipeline: PipelineStage[]): Promise<any[]>;
|
|
39
39
|
abstract aggregate<T extends Document>(model: Model<T>, pipeline: PipelineStage[], options?: AggregateOptions): Promise<any[]>;
|
|
40
|
+
abstract executeWithModel<T extends Document, R>(model: Model<T>, operation: (model: Model<T>, session?: ClientSession) => Promise<R>, session?: ClientSession): Promise<R>;
|
|
40
41
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export { DBNoSQLType } from "./types/DBNoSQLTypes";
|
|
|
7
7
|
export { NoSQLConnector } from "./abstract/NoSQLConnector";
|
|
8
8
|
export { SqlConnector, Filter } from "./abstract/SQLConnector";
|
|
9
9
|
export { NoSQLOptions } from "./types/NoSQLOptions";
|
|
10
|
-
export
|
|
10
|
+
export * from 'mongoose';
|
|
11
11
|
export { Model as ModelSequelize, Sequelize, DataTypes, CreateOptions, UpdateOptions, DestroyOptions, FindOptions, Attributes, WhereOptions, QueryOptions, InferAttributes, CreationAttributes, InferCreationAttributes, QueryTypes, QueryOptionsWithType, Transaction, Op, fn } from "sequelize";
|
|
12
12
|
export { DBError } from "./errors/DBError";
|
|
13
13
|
export { MySQLConnectionError } from "./errors/MySQLConnectionError";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hemia/db-connector",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Hemia Database Conector",
|
|
5
5
|
"main": "dist/hemia-db-connector.js",
|
|
6
6
|
"module": "dist/hemia-db-connector.esm.js",
|
|
@@ -41,8 +41,7 @@
|
|
|
41
41
|
"license": "MIT",
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"eslint": "^9.21.0",
|
|
44
|
-
"mongoose": "^8.8.2"
|
|
45
|
-
"rollup-plugin-visualizer": "^5.12.0"
|
|
44
|
+
"mongoose": "^8.8.2"
|
|
46
45
|
},
|
|
47
46
|
"devDependencies": {
|
|
48
47
|
"@rollup/plugin-commonjs": "^26.0.1",
|