@digipair/skill-mongodb 0.94.0-4 → 0.95.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/index.cjs.js +86 -0
- package/index.d.ts +1 -0
- package/{dist/index.esm.js → index.esm.js} +116788 -117838
- package/{dist → libs/skill-mongodb}/src/index.d.ts +0 -1
- package/{dist → libs/skill-mongodb}/src/lib/skill-mongodb.d.ts +0 -1
- package/package.json +6 -20
- package/README.md +0 -7
- package/dist/index.cjs.js +0 -251949
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/lib/skill-mongodb.d.ts.map +0 -1
- package/dist/src/lib/skill-mongodb.spec.d.ts +0 -2
- package/dist/src/lib/skill-mongodb.spec.d.ts.map +0 -1
- /package/{dist/index.d.ts → index.cjs.d.ts} +0 -0
- /package/{dist/schema.fr.json → schema.fr.json} +0 -0
- /package/{dist/schema.json → schema.json} +0 -0
package/index.cjs.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var engine = require('@digipair/engine');
|
|
6
|
+
var mongodb = require('mongodb');
|
|
7
|
+
|
|
8
|
+
let MongoDBService = class MongoDBService {
|
|
9
|
+
async database(params, _pins, context) {
|
|
10
|
+
var _context_privates_MONGODB_URL, _ref, _context_privates_MONGODB_DATABASE, _ref1;
|
|
11
|
+
const { url = (_ref = (_context_privates_MONGODB_URL = context.privates.MONGODB_URL) != null ? _context_privates_MONGODB_URL : params == null ? void 0 : params.MONGODB_URL) != null ? _ref : process.env['MONGODB_URL'], database = (_ref1 = (_context_privates_MONGODB_DATABASE = context.privates.MONGODB_DATABASE) != null ? _context_privates_MONGODB_DATABASE : params == null ? void 0 : params.MONGODB_DATABASE) != null ? _ref1 : process.env['MONGODB_DATABASE'] } = params;
|
|
12
|
+
const client = new mongodb.MongoClient(url);
|
|
13
|
+
await client.connect();
|
|
14
|
+
return {
|
|
15
|
+
client,
|
|
16
|
+
database: client.db(database)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
async find(params, _pins, context) {
|
|
20
|
+
const { client = context.privates.CLIENT_MONGODB, options = {}, collection, filter } = params;
|
|
21
|
+
const clientInstance = await engine.executePinsList(client, context, `${context.__PATH__}.client`);
|
|
22
|
+
const instance = clientInstance.database.collection(collection);
|
|
23
|
+
const values = await instance.find(filter, options).toArray();
|
|
24
|
+
await clientInstance.client.close();
|
|
25
|
+
return values;
|
|
26
|
+
}
|
|
27
|
+
async findOne(params, _pins, context) {
|
|
28
|
+
const { client = context.privates.CLIENT_MONGODB, options = {}, collection, filter } = params;
|
|
29
|
+
const clientInstance = await engine.executePinsList(client, context, `${context.__PATH__}.client`);
|
|
30
|
+
const instance = clientInstance.database.collection(collection);
|
|
31
|
+
const value = await instance.findOne(filter, options);
|
|
32
|
+
await clientInstance.client.close();
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
async findById(params, _pins, context) {
|
|
36
|
+
const { client = context.privates.CLIENT_MONGODB, options = {}, collection, id } = params;
|
|
37
|
+
const clientInstance = await engine.executePinsList(client, context, `${context.__PATH__}.client`);
|
|
38
|
+
const instance = clientInstance.database.collection(collection);
|
|
39
|
+
const value = await instance.findOne({
|
|
40
|
+
_id: new mongodb.ObjectId(id)
|
|
41
|
+
}, options);
|
|
42
|
+
await clientInstance.client.close();
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
async insertOne(params, _pins, context) {
|
|
46
|
+
const { client = context.privates.CLIENT_MONGODB, options = {}, collection, document } = params;
|
|
47
|
+
const clientInstance = await engine.executePinsList(client, context, `${context.__PATH__}.client`);
|
|
48
|
+
const instance = clientInstance.database.collection(collection);
|
|
49
|
+
const value = await instance.insertOne(document, options);
|
|
50
|
+
await clientInstance.client.close();
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
async updateOne(params, _pins, context) {
|
|
54
|
+
const { client = context.privates.CLIENT_MONGODB, options = {}, collection, filter, update } = params;
|
|
55
|
+
const clientInstance = await engine.executePinsList(client, context, `${context.__PATH__}.client`);
|
|
56
|
+
const instance = clientInstance.database.collection(collection);
|
|
57
|
+
const value = await instance.updateOne(filter, update, options);
|
|
58
|
+
await clientInstance.client.close();
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
async updateById(params, _pins, context) {
|
|
62
|
+
const { client = context.privates.CLIENT_MONGODB, options = {}, id, collection, update } = params;
|
|
63
|
+
const clientInstance = await engine.executePinsList(client, context, `${context.__PATH__}.client`);
|
|
64
|
+
const instance = clientInstance.database.collection(collection);
|
|
65
|
+
const value = await instance.updateOne({
|
|
66
|
+
_id: new mongodb.ObjectId(id)
|
|
67
|
+
}, update, options);
|
|
68
|
+
await clientInstance.client.close();
|
|
69
|
+
return value;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const database = (params, pins, context)=>new MongoDBService().database(params, pins, context);
|
|
73
|
+
const find = (params, pins, context)=>new MongoDBService().find(params, pins, context);
|
|
74
|
+
const findOne = (params, pins, context)=>new MongoDBService().findOne(params, pins, context);
|
|
75
|
+
const findById = (params, pins, context)=>new MongoDBService().findById(params, pins, context);
|
|
76
|
+
const insertOne = (params, pins, context)=>new MongoDBService().insertOne(params, pins, context);
|
|
77
|
+
const updateOne = (params, pins, context)=>new MongoDBService().updateOne(params, pins, context);
|
|
78
|
+
const updateById = (params, pins, context)=>new MongoDBService().updateById(params, pins, context);
|
|
79
|
+
|
|
80
|
+
exports.database = database;
|
|
81
|
+
exports.find = find;
|
|
82
|
+
exports.findById = findById;
|
|
83
|
+
exports.findOne = findOne;
|
|
84
|
+
exports.insertOne = insertOne;
|
|
85
|
+
exports.updateById = updateById;
|
|
86
|
+
exports.updateOne = updateOne;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './libs/skill-mongodb/src/index';
|