@builderbot/database-mongo 0.1.3-alpha.22
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 +11 -0
- package/dist/index.cjs +41 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/mongoAdapter.d.ts +14 -0
- package/dist/mongoAdapter.d.ts.map +1 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +50 -0
package/README.md
ADDED
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var mongodb = require('mongodb');
|
|
4
|
+
|
|
5
|
+
class MongoAdapter {
|
|
6
|
+
constructor(_credentials) {
|
|
7
|
+
this.db = null;
|
|
8
|
+
this.listHistory = [];
|
|
9
|
+
this.credentials = { dbUri: null, dbName: null };
|
|
10
|
+
this.init = async () => {
|
|
11
|
+
try {
|
|
12
|
+
const client = new mongodb.MongoClient(this.credentials.dbUri, {});
|
|
13
|
+
await client.connect();
|
|
14
|
+
console.log('🆗 Conexión Correcta DB');
|
|
15
|
+
const db = client.db(this.credentials.dbName);
|
|
16
|
+
this.db = db;
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
console.log('Error', e);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
this.getPrevByNumber = async (from) => {
|
|
25
|
+
const result = await this.db.collection('history').find({ from }).sort({ _id: -1 }).limit(1).toArray();
|
|
26
|
+
return result[0];
|
|
27
|
+
};
|
|
28
|
+
this.save = async (ctx) => {
|
|
29
|
+
const ctxWithDate = {
|
|
30
|
+
...ctx,
|
|
31
|
+
date: new Date(),
|
|
32
|
+
};
|
|
33
|
+
await this.db.collection('history').insertOne(ctxWithDate);
|
|
34
|
+
this.listHistory.push(ctx);
|
|
35
|
+
};
|
|
36
|
+
this.credentials = _credentials;
|
|
37
|
+
this.init().then();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exports.MongoAdapter = MongoAdapter;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Db } from 'mongodb';
|
|
2
|
+
|
|
3
|
+
import { History, MongoAdapterCredentials } from './types';
|
|
4
|
+
declare class MongoAdapter {
|
|
5
|
+
db: Db | null;
|
|
6
|
+
listHistory: History[];
|
|
7
|
+
credentials: MongoAdapterCredentials;
|
|
8
|
+
constructor(_credentials: MongoAdapterCredentials);
|
|
9
|
+
init: () => Promise<boolean>;
|
|
10
|
+
getPrevByNumber: (from: string) => Promise<any>;
|
|
11
|
+
save: (ctx: History) => Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export { MongoAdapter };
|
|
14
|
+
//# sourceMappingURL=mongoAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mongoAdapter.d.ts","sourceRoot":"","sources":["../src/mongoAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,EAAE,EAAE,MAAM,SAAS,CAAA;AAEzC,OAAO,EAAE,OAAO,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAA;AAE1D,cAAM,YAAY;IACd,EAAE,EAAE,EAAE,GAAG,IAAI,CAAO;IACpB,WAAW,EAAE,OAAO,EAAE,CAAK;IAC3B,WAAW,EAAE,uBAAuB,CAAgC;gBACxD,YAAY,EAAE,uBAAuB;IAKjD,IAAI,QAAa,QAAQ,OAAO,CAAC,CAahC;IAED,eAAe,SAAgB,MAAM,KAAG,QAAQ,GAAG,CAAC,CAGnD;IAED,IAAI,QAAe,OAAO,KAAG,QAAQ,IAAI,CAAC,CAQzC;CACJ;AAED,OAAO,EAAE,YAAY,EAAE,CAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ObjectId } from 'mongodb';
|
|
2
|
+
export interface MongoAdapterCredentials {
|
|
3
|
+
dbUri: string;
|
|
4
|
+
dbName: string;
|
|
5
|
+
}
|
|
6
|
+
export interface History {
|
|
7
|
+
from: string;
|
|
8
|
+
body: any;
|
|
9
|
+
keyword: string[];
|
|
10
|
+
_id?: ObjectId;
|
|
11
|
+
date?: Date;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAElC,MAAM,WAAW,uBAAuB;IACpC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,OAAO;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,GAAG,CAAA;IACT,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,GAAG,CAAC,EAAE,QAAQ,CAAA;IACd,IAAI,CAAC,EAAE,IAAI,CAAA;CACd"}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@builderbot/database-mongo",
|
|
3
|
+
"version": "0.1.3-alpha.22",
|
|
4
|
+
"description": "Esto es el conector a mongo DB",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"author": "Leifer Mendez <leifer33@gmail.com>",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"main": "dist/index.cjs",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"type": "module",
|
|
11
|
+
"directories": {
|
|
12
|
+
"src": "src",
|
|
13
|
+
"test": "__tests__"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"./dist/"
|
|
17
|
+
],
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/codigoencasa/bot-whatsapp.git"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "rimraf dist && rollup --config",
|
|
24
|
+
"test": " npx uvu -r tsm ./__tests__ .test.ts",
|
|
25
|
+
"test:coverage": "npx c8 npm run test",
|
|
26
|
+
"test:debug": " npx tsm --inspect-brk ../../node_modules/uvu/bin.js ./__tests__ .test.ts"
|
|
27
|
+
},
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/codigoencasa/bot-whatsapp/issues"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/codigoencasa/bot-whatsapp#readme",
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"mongodb": "^4.17.2"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
37
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
38
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
39
|
+
"@types/node": "^20.11.0",
|
|
40
|
+
"@types/sinon": "^17.0.3",
|
|
41
|
+
"kleur": "^4.1.5",
|
|
42
|
+
"mongodb-memory-server": "^9.1.6",
|
|
43
|
+
"rimraf": "^3.0.2",
|
|
44
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
45
|
+
"sinon": "^17.0.1",
|
|
46
|
+
"tslib": "^2.6.2",
|
|
47
|
+
"tsm": "^2.3.0"
|
|
48
|
+
},
|
|
49
|
+
"gitHead": "0fb50a130573d7a1f6b1cd7fcfa0fdf1b8f9d578"
|
|
50
|
+
}
|