@cocreate/mongodb 1.24.1 → 1.25.1
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/CHANGELOG.md +20 -0
- package/README.md +141 -51
- package/package.json +1 -43
- package/src/array.js +201 -0
- package/src/database.js +110 -0
- package/src/index.js +20 -918
- package/src/object.js +509 -0
- package/src/utilities.js +296 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
## [1.25.1](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.25.0...v1.25.1) (2026-07-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* revert package.json version and description to previous state ([35ac67c](https://github.com/CoCreate-app/CoCreate-mongodb/commit/35ac67c4ea3aa1ed044aab14879fd95bf7f4666b))
|
|
7
|
+
|
|
8
|
+
# [1.25.0](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.24.1...v1.25.0) (2026-07-18)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* update bandwidth event types to 'ingress' and 'egress' ([5ed0df9](https://github.com/CoCreate-app/CoCreate-mongodb/commit/5ed0df9cd4547315bfb1652300e458350bc858c2))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* add isolated CRUD processors for array, database, and object management ([b8b50e9](https://github.com/CoCreate-app/CoCreate-mongodb/commit/b8b50e986aa3668a4163e3678e4dce4c8d2b1eb7))
|
|
19
|
+
* enhance MongoDB client connection management with improved caching and cleanup on org deletion ([ad8fa09](https://github.com/CoCreate-app/CoCreate-mongodb/commit/ad8fa09b8110152fee829b70e145516c19955f86))
|
|
20
|
+
|
|
1
21
|
## [1.24.1](https://github.com/CoCreate-app/CoCreate-mongodb/compare/v1.24.0...v1.24.1) (2026-07-17)
|
|
2
22
|
|
|
3
23
|
|
package/README.md
CHANGED
|
@@ -1,88 +1,178 @@
|
|
|
1
|
-
#
|
|
1
|
+
# mongodb
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A highly efficient, enterprise-grade MongoDB document database CRUD wrapper and state-routing backend client for the collaborative CoCreate ecosystem. This wrapper exposes MongoDB's native, highly flexible JSON-based document storage capabilities directly to CoCreate's unified state-routing infrastructure.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-

|
|
7
|
-

|
|
5
|
+
## Documentation
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
For a complete guide and working integration examples, refer to the [CoCreate MongoDB Documentation](https://www.google.com/search?q=https://cocreatejs.com/docs/mongodb).
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
---
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
## Table of Contents
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
* [The Power of the CoCreate Unified Ecosystem](https://www.google.com/search?q=%23the-power-of-the-cocreate-unified-ecosystem)
|
|
14
|
+
* [Why MongoDB?](https://www.google.com/search?q=%23why-mongodb)
|
|
15
|
+
* [Installation](https://www.google.com/search?q=%23installation)
|
|
16
|
+
* [Unified JSON Payload Examples](https://www.google.com/search?q=%23unified-json-payload-examples)
|
|
17
|
+
* [Announcements](https://www.google.com/search?q=%23announcements)
|
|
18
|
+
* [Roadmap](https://www.google.com/search?q=%23roadmap)
|
|
19
|
+
* [How to Contribute](https://www.google.com/search?q=%23how-to-contribute)
|
|
20
|
+
* [About](https://www.google.com/search?q=%23about)
|
|
16
21
|
|
|
17
|
-
|
|
18
|
-
<script src="https://cdn.cocreate.app/mongodb/latest/CoCreate-mongodb.min.js"></script>
|
|
19
|
-
```
|
|
22
|
+
---
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
<script src="https://cdn.cocreate.app/mongodb/latest/CoCreate-mongodb.min.css"></script>
|
|
23
|
-
```
|
|
24
|
+
## The Power of the CoCreate Unified Ecosystem
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
This is not just another database driver. By wrapping MongoDB into the CoCreate state-routing pipeline, you unlock the full power of a multi-cloud, multi-model data orchestration mesh:
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
* **Unified JSON Interface (MongoDB-like Syntax):** Because CoCreate's data-routing abstraction layer natively speaks a MongoDB-influenced query language, this wrapper offers zero structural translation overhead for standard NoSQL JSON CRUD operations (such as `object.create` or `object.read`).
|
|
29
|
+
* **Parallel Multi-Database Writing:** Write to many target databases simultaneously with a single API call. You can stream transactional data to MongoDB (for native operational document persistence), vectorize it into Qdrant (for real-time semantic search), and persist it in MariaDB (for enterprise relational warehousing) in perfect parallel harmony:
|
|
30
|
+
|
|
31
|
+
$$\text{Write Command} \xrightarrow{\text{Parallel Mesh}} \begin{cases} \text{MongoDB} & \text{(ACID Transaction Store)} \\ \text{Qdrant} & \text{(Semantic Vector Search)} \\ \text{MariaDB} & \text{(Enterprise Relational Core)} \end{cases}$$
|
|
32
|
+
|
|
33
|
+
* **Dynamic State-Routing:** Isolate multi-tenant environments effortlessly. The routing mesh automatically injects tenant metadata and organization boundaries, ensuring isolated database processing within your shared MongoDB cluster infrastructure.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Why MongoDB?
|
|
38
|
+
|
|
39
|
+
MongoDB is the leading document database designed for modern application developers and the cloud era. By storing data in flexible, JSON-like BSON documents, it maps naturally to application code and objects. It features powerful indexing, ad-hoc queries, real-time aggregation frameworks, and fully distributed horizontal scaling out of the box.
|
|
30
40
|
|
|
31
|
-
|
|
41
|
+
By using MongoDB as a core anchor inside your CoCreate mesh, you achieve lightning-fast operational reads, rich document schemas, and native database compatibility across any complex cloud environment.
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
### NPM Installation
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
npm i @cocreate/mongodb
|
|
32
51
|
|
|
33
|
-
```shell
|
|
34
|
-
$ yarn install @cocreate/mongodb
|
|
35
52
|
```
|
|
36
53
|
|
|
37
|
-
|
|
54
|
+
### Yarn Installation
|
|
38
55
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
- [Roadmap](#roadmap)
|
|
42
|
-
- [How to Contribute](#how-to-contribute)
|
|
43
|
-
- [About](#about)
|
|
44
|
-
- [License](#license)
|
|
56
|
+
```bash
|
|
57
|
+
yarn add @cocreate/mongodb
|
|
45
58
|
|
|
46
|
-
|
|
59
|
+
```
|
|
47
60
|
|
|
48
|
-
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Unified JSON Payload Examples
|
|
64
|
+
|
|
65
|
+
Here are the complete, real-world JSON objects representing raw payloads routed through the CoCreate system. By declaring an array in the `storage` key, CoCreate fires the write operations to all specified backends simultaneously in parallel.
|
|
66
|
+
|
|
67
|
+
### 1. Writing a Full Transaction Object (`object.create`)
|
|
68
|
+
|
|
69
|
+
When this operational payload is sent, CoCreate registers it, processes the nested JSON fields, and automatically warehouses it across all listed parallel storage platforms.
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
{
|
|
73
|
+
"method": "object.create",
|
|
74
|
+
"storage": ["mongodb", "qdrant", "mariadb"], // Array of storages to store in parallel!
|
|
75
|
+
"database": "sales_analytics",
|
|
76
|
+
"array": "order_events",
|
|
77
|
+
"object": {
|
|
78
|
+
"_id": "order_77c8f2a9_3b01",
|
|
79
|
+
"customer": {
|
|
80
|
+
"id": "cust_88301",
|
|
81
|
+
"email": "customer@example.com",
|
|
82
|
+
"region": "North America",
|
|
83
|
+
"acquisition_channel": "Google Search"
|
|
84
|
+
},
|
|
85
|
+
"transaction": {
|
|
86
|
+
"payment_method": "Credit Card",
|
|
87
|
+
"currency": "USD",
|
|
88
|
+
"subtotal": 249.99,
|
|
89
|
+
"discount": 15.00,
|
|
90
|
+
"tax": 18.80,
|
|
91
|
+
"total": 253.79
|
|
92
|
+
},
|
|
93
|
+
"items": [
|
|
94
|
+
{
|
|
95
|
+
"product_id": "prod_head_009",
|
|
96
|
+
"name": "Wireless Noise-Cancelling Headphones",
|
|
97
|
+
"category": "Electronics",
|
|
98
|
+
"quantity": 1,
|
|
99
|
+
"unit_price": 199.99
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"product_id": "prod_stand_012",
|
|
103
|
+
"name": "Aluminum Headphone Stand",
|
|
104
|
+
"category": "Accessories",
|
|
105
|
+
"quantity": 2,
|
|
106
|
+
"unit_price": 25.00
|
|
107
|
+
}
|
|
108
|
+
],
|
|
109
|
+
"shipping": {
|
|
110
|
+
"carrier": "FedEx",
|
|
111
|
+
"service": "2-Day Air",
|
|
112
|
+
"estimated_delivery": "2026-07-20T12:00:00.000Z"
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
"organization_id": "org_enterprise_99x",
|
|
116
|
+
"user_id": "usr_sales_runner_402",
|
|
117
|
+
"timeStamp": "2026-07-18T18:40:43.000Z"
|
|
118
|
+
}
|
|
49
119
|
|
|
50
|
-
|
|
120
|
+
```
|
|
51
121
|
|
|
52
|
-
|
|
122
|
+
### 2. Reading and Filtering Warehoused Data (`object.read`)
|
|
123
|
+
|
|
124
|
+
Querying targets a single database engine via a string filter syntax. The query below retrieves high-value orders handled by a specific shipping carrier from MongoDB, sorting them by total sale volume.
|
|
125
|
+
|
|
126
|
+
```json
|
|
127
|
+
{
|
|
128
|
+
"method": "object.read",
|
|
129
|
+
"storage": "mongodb",
|
|
130
|
+
"database": "sales_analytics",
|
|
131
|
+
"array": "order_events",
|
|
132
|
+
"$filter": {
|
|
133
|
+
"query": {
|
|
134
|
+
"transaction.total": { "$gte": 100.00 },
|
|
135
|
+
"shipping.carrier": "FedEx"
|
|
136
|
+
},
|
|
137
|
+
"sort": [
|
|
138
|
+
{ "key": "transaction.total", "direction": "desc" }
|
|
139
|
+
],
|
|
140
|
+
"limit": 50,
|
|
141
|
+
"index": 0
|
|
142
|
+
},
|
|
143
|
+
"organization_id": "org_enterprise_99x"
|
|
144
|
+
}
|
|
53
145
|
|
|
54
|
-
|
|
146
|
+
```
|
|
55
147
|
|
|
56
|
-
|
|
148
|
+
---
|
|
57
149
|
|
|
58
|
-
|
|
150
|
+
## Announcements
|
|
59
151
|
|
|
60
|
-
|
|
152
|
+
All updates to this library are documented in our `CHANGELOG` and releases. You may also subscribe to email for releases and breaking changes.
|
|
61
153
|
|
|
62
|
-
|
|
154
|
+
---
|
|
63
155
|
|
|
64
|
-
|
|
156
|
+
## Roadmap
|
|
65
157
|
|
|
66
|
-
|
|
158
|
+
If you are interested in the future direction of this project, please take a look at our open issues and pull requests. We would love to hear your feedback.
|
|
67
159
|
|
|
68
|
-
|
|
160
|
+
---
|
|
69
161
|
|
|
70
|
-
|
|
162
|
+
## How to Contribute
|
|
71
163
|
|
|
72
|
-
We encourage contribution to our libraries (you might even score some nifty swag), please see our
|
|
164
|
+
We encourage contribution to our libraries (you might even score some nifty swag), please see our `CONTRIBUTING` guide for details.
|
|
73
165
|
|
|
74
|
-
We want this library to be community-driven, and CoCreate led. We need your help to realize this goal. To help make sure we are building the right things in the right order, we ask that you create
|
|
166
|
+
We want this library to be community-driven, and CoCreate led. We need your help to realize this goal. To help make sure we are building the right things in the right order, we ask that you create issues and pull requests or merely upvote or comment on existing issues or pull requests.
|
|
75
167
|
|
|
76
168
|
We appreciate your continued support, thank you!
|
|
77
169
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
# License
|
|
170
|
+
---
|
|
81
171
|
|
|
82
|
-
|
|
172
|
+
## About
|
|
83
173
|
|
|
84
|
-
-
|
|
174
|
+
`CoCreate-mongodb` is guided and supported by the **CoCreate Developer Experience Team**.
|
|
85
175
|
|
|
86
|
-
|
|
176
|
+
> Please Email the Developer Experience Team here in case of any queries.
|
|
87
177
|
|
|
88
|
-
|
|
178
|
+
`CoCreate-mongodb` is maintained and funded by CoCreate. The names and logos for CoCreate are trademarks of CoCreate, LLC.
|
package/package.json
CHANGED
|
@@ -1,43 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@cocreate/mongodb",
|
|
3
|
-
"version": "1.24.1",
|
|
4
|
-
"description": "A simple mongodb component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"mongodb",
|
|
7
|
-
"low-code",
|
|
8
|
-
"realtime",
|
|
9
|
-
"realtime-framework",
|
|
10
|
-
"collaboration",
|
|
11
|
-
"shared-editing",
|
|
12
|
-
"html5-framework",
|
|
13
|
-
"javascript-framework"
|
|
14
|
-
],
|
|
15
|
-
"publishConfig": {
|
|
16
|
-
"access": "public"
|
|
17
|
-
},
|
|
18
|
-
"scripts": {
|
|
19
|
-
"start": "webpack --config webpack.config.js",
|
|
20
|
-
"build": "webpack --mode=production --config webpack.config.js",
|
|
21
|
-
"dev": "webpack --config webpack.config.js --watch"
|
|
22
|
-
},
|
|
23
|
-
"repository": {
|
|
24
|
-
"type": "git",
|
|
25
|
-
"url": "git+https://github.com/CoCreate-app/CoCreate-mongodb.git"
|
|
26
|
-
},
|
|
27
|
-
"author": "CoCreate LLC",
|
|
28
|
-
"license": "AGPL-3.0",
|
|
29
|
-
"bugs": {
|
|
30
|
-
"url": "https://github.com/CoCreate-app/CoCreate-mongodb/issues"
|
|
31
|
-
},
|
|
32
|
-
"homepage": "https://cocreate.app/docs/mongodb",
|
|
33
|
-
"funding": {
|
|
34
|
-
"type": "GitHub Sponsors ❤",
|
|
35
|
-
"url": "https://github.com/sponsors/CoCreate-app"
|
|
36
|
-
},
|
|
37
|
-
"type": "module",
|
|
38
|
-
"main": "./src/index.js",
|
|
39
|
-
"dependencies": {
|
|
40
|
-
"@cocreate/utils": "^1.44.0",
|
|
41
|
-
"mongodb": "^7.5.0"
|
|
42
|
-
}
|
|
43
|
-
}
|
|
1
|
+
{"name":"@cocreate/mongodb","version":"1.25.1","description":"Lightweight, real-time MongoDB CRUD wrapper and multi-tenant state routing client for the collaborative CoCreate ecosystem.","keywords":["mongodb","nosql","crud-api","abstract-crud","database-abstraction","multi-tenant","multi-tenant-routing","realtime-sync","state-synchronization","shared-editing","collaborative-editing","websocket-mesh","peer-to-peer-sync","p2p-database"],"publishConfig":{"access":"public"},"scripts":{"start":"webpack --config webpack.config.js","build":"webpack --mode=production --config webpack.config.js","dev":"webpack --config webpack.config.js --watch"},"repository":{"type":"git","url":"git+https://github.com/CoCreate-app/CoCreate-mongodb.git"},"author":"CoCreate LLC","license":"AGPL-3.0","bugs":{"url":"https://github.com/CoCreate-app/CoCreate-mongodb/issues"},"homepage":"https://cocreate.app/docs/mongodb","funding":{"type":"GitHub Sponsors ❤","url":"https://github.com/sponsors/CoCreate-app"},"type":"module","main":"./src/index.js","dependencies":{"@cocreate/utils":"^1.44.0","mongodb":"^7.5.0"}}
|
package/src/array.js
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (C) 2023 CoCreate and Contributors.
|
|
3
|
+
*
|
|
4
|
+
* This program is free software: you can redistribute it and/or modify
|
|
5
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
6
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
7
|
+
* (at your option) any later version.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
********************************************************************************/
|
|
17
|
+
|
|
18
|
+
import { queryData } from "@cocreate/utils";
|
|
19
|
+
import {
|
|
20
|
+
dbClient,
|
|
21
|
+
createFilter,
|
|
22
|
+
createData,
|
|
23
|
+
errorHandler
|
|
24
|
+
} from "./utilities.js";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Isolated CRUD Processor for Array/Collection Management.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} method - Operation targeting database collections (read, create, update, delete)
|
|
30
|
+
* @param {Object} data - Context query details containing database and collection matrices
|
|
31
|
+
*/
|
|
32
|
+
function array(method, data) {
|
|
33
|
+
return new Promise(
|
|
34
|
+
async (resolve, reject) => {
|
|
35
|
+
let type = "array";
|
|
36
|
+
let arrayArray = [];
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
const client = await dbClient(data);
|
|
40
|
+
if (!client || client.status === false) return resolve(data);
|
|
41
|
+
|
|
42
|
+
if (data.request) data.array = data.request;
|
|
43
|
+
|
|
44
|
+
let databases = data.database;
|
|
45
|
+
if (!Array.isArray(databases)) databases = [databases];
|
|
46
|
+
|
|
47
|
+
for (let database of databases) {
|
|
48
|
+
const db = client.db(database);
|
|
49
|
+
|
|
50
|
+
if (method == "read") {
|
|
51
|
+
let { query, sort } = await createFilter(data);
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
const result = await db.listCollections().toArray();
|
|
55
|
+
if (result) {
|
|
56
|
+
process.emit("usage", {
|
|
57
|
+
type: "ingress",
|
|
58
|
+
data: result,
|
|
59
|
+
organization_id: data.organization_id
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
for (let res of result) {
|
|
63
|
+
if (data.$filter && data.$filter.query) {
|
|
64
|
+
let isFilter = queryData(
|
|
65
|
+
res,
|
|
66
|
+
data.$filter.query
|
|
67
|
+
);
|
|
68
|
+
if (isFilter)
|
|
69
|
+
arrayArray.push({
|
|
70
|
+
name: res.name,
|
|
71
|
+
database,
|
|
72
|
+
storage: data.storageName
|
|
73
|
+
});
|
|
74
|
+
} else
|
|
75
|
+
arrayArray.push({
|
|
76
|
+
name: res.name,
|
|
77
|
+
database,
|
|
78
|
+
storage: data.storageName
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
} catch (error) {
|
|
83
|
+
errorHandler(data, error, database);
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
let arrays;
|
|
87
|
+
let value;
|
|
88
|
+
if (method == "update")
|
|
89
|
+
arrays = Object.entries(data.array);
|
|
90
|
+
else arrays = data.array;
|
|
91
|
+
|
|
92
|
+
if (!Array.isArray(arrays)) arrays = [arrays];
|
|
93
|
+
|
|
94
|
+
for (let array of arrays) {
|
|
95
|
+
if (method == "create") {
|
|
96
|
+
process.emit("usage", {
|
|
97
|
+
type: "egress",
|
|
98
|
+
data: array,
|
|
99
|
+
organization_id: data.organization_id
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
try {
|
|
103
|
+
const result = await db.createCollection(array);
|
|
104
|
+
if (result) {
|
|
105
|
+
process.emit("usage", {
|
|
106
|
+
type: "ingress",
|
|
107
|
+
data: { status: "created", name: array },
|
|
108
|
+
organization_id: data.organization_id
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
arrayArray.push({
|
|
112
|
+
name: array,
|
|
113
|
+
database,
|
|
114
|
+
storage: data.storageName
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
} catch (error) {
|
|
118
|
+
errorHandler(data, error, database, array);
|
|
119
|
+
}
|
|
120
|
+
} else {
|
|
121
|
+
if (method == "update") {
|
|
122
|
+
[array, value] = array;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const arrayObj = db.collection(array);
|
|
126
|
+
|
|
127
|
+
if (method == "update") {
|
|
128
|
+
process.emit("usage", {
|
|
129
|
+
type: "egress",
|
|
130
|
+
data: { rename: value },
|
|
131
|
+
organization_id: data.organization_id
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
const result = await arrayObj.rename(value);
|
|
136
|
+
if (result) {
|
|
137
|
+
process.emit("usage", {
|
|
138
|
+
type: "ingress",
|
|
139
|
+
data: { status: "renamed", from: array, to: value },
|
|
140
|
+
organization_id: data.organization_id
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
arrayArray.push({
|
|
144
|
+
name: value,
|
|
145
|
+
oldName: array,
|
|
146
|
+
database,
|
|
147
|
+
storage: data.storageName
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
} catch (error) {
|
|
151
|
+
errorHandler(data, error, database, array);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (method == "delete") {
|
|
156
|
+
process.emit("usage", {
|
|
157
|
+
type: "egress",
|
|
158
|
+
data: { drop: array },
|
|
159
|
+
organization_id: data.organization_id
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
try {
|
|
163
|
+
const result = await arrayObj.drop();
|
|
164
|
+
if (result) {
|
|
165
|
+
process.emit("usage", {
|
|
166
|
+
type: "ingress",
|
|
167
|
+
data: { status: "dropped", name: array },
|
|
168
|
+
organization_id: data.organization_id
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
arrayArray.push({
|
|
172
|
+
name: array,
|
|
173
|
+
database,
|
|
174
|
+
storage: data.storageName
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
} catch (error) {
|
|
178
|
+
errorHandler(data, error, database, array);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
data = createData(
|
|
187
|
+
data,
|
|
188
|
+
arrayArray,
|
|
189
|
+
type
|
|
190
|
+
);
|
|
191
|
+
resolve(data);
|
|
192
|
+
} catch (error) {
|
|
193
|
+
errorHandler(data, error);
|
|
194
|
+
console.log(method, "error", error);
|
|
195
|
+
resolve(data);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export default array;
|
package/src/database.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (C) 2023 CoCreate and Contributors.
|
|
3
|
+
*
|
|
4
|
+
* This program is free software: you can redistribute it and/or modify
|
|
5
|
+
* it under the terms of the GNU Affero General Public License as published
|
|
6
|
+
* by the Free Software Foundation, either version 3 of the License, or
|
|
7
|
+
* (at your option) any later version.
|
|
8
|
+
*
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU Affero General Public License for more details.
|
|
13
|
+
*
|
|
14
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
15
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
|
+
********************************************************************************/
|
|
17
|
+
|
|
18
|
+
import { queryData } from "@cocreate/utils";
|
|
19
|
+
import {
|
|
20
|
+
dbClient,
|
|
21
|
+
createData,
|
|
22
|
+
errorHandler
|
|
23
|
+
} from "./utilities.js";
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Isolated CRUD Processor for Database Management.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} method - Operation targeting database layers (read, delete)
|
|
29
|
+
* @param {Object} data - Context query details and transactional metrics
|
|
30
|
+
*/
|
|
31
|
+
function database(method, data) {
|
|
32
|
+
return new Promise(
|
|
33
|
+
async (resolve, reject) => {
|
|
34
|
+
let type = "database";
|
|
35
|
+
let databaseArray = [];
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
const client = await dbClient(data);
|
|
39
|
+
if (!client || client.status === false) return resolve(data);
|
|
40
|
+
|
|
41
|
+
if (method == "read") {
|
|
42
|
+
const db = client.db().admin();
|
|
43
|
+
|
|
44
|
+
// List all the available databases
|
|
45
|
+
try {
|
|
46
|
+
const dbs = await db.listDatabases();
|
|
47
|
+
|
|
48
|
+
// Emit ingress telemetry with raw list databases payload
|
|
49
|
+
process.emit("usage", {
|
|
50
|
+
type: "ingress",
|
|
51
|
+
data: dbs,
|
|
52
|
+
organization_id: data.organization_id
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
for (let database of dbs.databases) {
|
|
56
|
+
if (data.$filter && data.$filter.query) {
|
|
57
|
+
let isFilter = queryData(
|
|
58
|
+
database,
|
|
59
|
+
data.$filter.query
|
|
60
|
+
);
|
|
61
|
+
if (isFilter)
|
|
62
|
+
databaseArray.push({
|
|
63
|
+
database,
|
|
64
|
+
storage: data.storageName
|
|
65
|
+
});
|
|
66
|
+
} else
|
|
67
|
+
databaseArray.push({
|
|
68
|
+
database,
|
|
69
|
+
storage: data.storageName
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
resolve(createData(data, databaseArray, type));
|
|
74
|
+
} catch (error) {
|
|
75
|
+
errorHandler(data, error);
|
|
76
|
+
resolve(data);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (method == "delete") {
|
|
81
|
+
const db = client.db(data.database);
|
|
82
|
+
try {
|
|
83
|
+
const result = await db.dropDatabase();
|
|
84
|
+
|
|
85
|
+
// Emit ingress telemetry with raw deletion success payload
|
|
86
|
+
process.emit("usage", {
|
|
87
|
+
type: "ingress",
|
|
88
|
+
data: result,
|
|
89
|
+
organization_id: data.organization_id
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
resolve(result);
|
|
93
|
+
} catch(error) {
|
|
94
|
+
errorHandler(data, error);
|
|
95
|
+
resolve(data);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
} catch (error) {
|
|
99
|
+
errorHandler(data, error);
|
|
100
|
+
console.log(method, "error", error);
|
|
101
|
+
resolve(data);
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
(error) => {
|
|
105
|
+
errorHandler(data, error);
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export default database;
|