@lowdefy/connection-mongodb 4.0.0-alpha.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.
Files changed (34) hide show
  1. package/LICENSE +201 -0
  2. package/dist/connections/MongoDBCollection/MongoDBAggregation/MongoDBAggregation.js +47 -0
  3. package/dist/connections/MongoDBCollection/MongoDBAggregation/MongoDBAggregationSchema.json +26 -0
  4. package/dist/connections/MongoDBCollection/MongoDBAggregation/index.js +24 -0
  5. package/dist/connections/MongoDBCollection/MongoDBCollection.js +39 -0
  6. package/dist/connections/MongoDBCollection/MongoDBCollectionSchema.json +52 -0
  7. package/dist/connections/MongoDBCollection/MongoDBDeleteMany/MongoDBDeleteMany.js +36 -0
  8. package/dist/connections/MongoDBCollection/MongoDBDeleteMany/MongoDBDeleteManySchema.json +26 -0
  9. package/dist/connections/MongoDBCollection/MongoDBDeleteMany/index.js +24 -0
  10. package/dist/connections/MongoDBCollection/MongoDBDeleteOne/MongoDBDeleteOne.js +36 -0
  11. package/dist/connections/MongoDBCollection/MongoDBDeleteOne/MongoDBDeleteOneSchema.json +26 -0
  12. package/dist/connections/MongoDBCollection/MongoDBDeleteOne/index.js +24 -0
  13. package/dist/connections/MongoDBCollection/MongoDBFind/MongoDBFind.js +34 -0
  14. package/dist/connections/MongoDBCollection/MongoDBFind/MongoDBFindSchema.json +26 -0
  15. package/dist/connections/MongoDBCollection/MongoDBFind/index.js +24 -0
  16. package/dist/connections/MongoDBCollection/MongoDBFindOne/MongoDBFindOne.js +33 -0
  17. package/dist/connections/MongoDBCollection/MongoDBFindOne/MongoDBFindOneSchema.json +26 -0
  18. package/dist/connections/MongoDBCollection/MongoDBFindOne/index.js +24 -0
  19. package/dist/connections/MongoDBCollection/MongoDBInsertMany/MongoDBInsertMany.js +37 -0
  20. package/dist/connections/MongoDBCollection/MongoDBInsertMany/MongoDBInsertManySchema.json +32 -0
  21. package/dist/connections/MongoDBCollection/MongoDBInsertMany/index.js +24 -0
  22. package/dist/connections/MongoDBCollection/MongoDBInsertOne/MongoDBInsertOne.js +38 -0
  23. package/dist/connections/MongoDBCollection/MongoDBInsertOne/MongoDBInsertOneSchema.json +26 -0
  24. package/dist/connections/MongoDBCollection/MongoDBInsertOne/index.js +24 -0
  25. package/dist/connections/MongoDBCollection/MongoDBUpdateMany/MongoDBUpdateMany.js +39 -0
  26. package/dist/connections/MongoDBCollection/MongoDBUpdateMany/MongoDBUpdateManySchema.json +36 -0
  27. package/dist/connections/MongoDBCollection/MongoDBUpdateMany/index.js +24 -0
  28. package/dist/connections/MongoDBCollection/MongoDBUpdateOne/MongoDBUpdateOne.js +39 -0
  29. package/dist/connections/MongoDBCollection/MongoDBUpdateOne/MongoDBUpdateOneSchema.json +36 -0
  30. package/dist/connections/MongoDBCollection/MongoDBUpdateOne/index.js +24 -0
  31. package/dist/connections/MongoDBCollection/getCollection.js +36 -0
  32. package/dist/connections/MongoDBCollection/serialize.js +73 -0
  33. package/dist/index.js +7 -0
  34. package/package.json +60 -0
@@ -0,0 +1,33 @@
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import getCollection from '../getCollection.js';
16
+ import { serialize, deserialize } from '../serialize.js';
17
+ async function mongodbFindOne({ request , connection }) {
18
+ const deserializedRequest = deserialize(request);
19
+ const { query , options } = deserializedRequest;
20
+ const { collection , client } = await getCollection({
21
+ connection
22
+ });
23
+ let res;
24
+ try {
25
+ res = await collection.findOne(query, options);
26
+ } catch (error) {
27
+ await client.close();
28
+ throw error;
29
+ }
30
+ await client.close();
31
+ return serialize(res);
32
+ }
33
+ export default mongodbFindOne;
@@ -0,0 +1,26 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "Lowdefy Request Schema - MongoDBFindOne",
4
+ "type": "object",
5
+ "required": ["query"],
6
+ "properties": {
7
+ "query": {
8
+ "type": "object",
9
+ "description": "A MongoDB query object",
10
+ "errorMessage": {
11
+ "type": "MongoDBFindOne request property \"query\" should be an object."
12
+ }
13
+ },
14
+ "options": {
15
+ "type": "object",
16
+ "description": "Optional settings.",
17
+ "errorMessage": {
18
+ "type": "MongoDBFindOne request property \"options\" should be an object."
19
+ }
20
+ }
21
+ },
22
+ "errorMessage": {
23
+ "type": "MongoDBFindOne request properties should be an object.",
24
+ "required": "MongoDBFindOne request should have required property \"query\"."
25
+ }
26
+ }
@@ -0,0 +1,24 @@
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ export default {
16
+ import: {
17
+ path: 'connections/MongoDBCollection/MongoDBFindOne/MongoDBFindOne.js',
18
+ schema: 'connections/MongoDBCollection/MongoDBFindOne/MongoDBFindOneSchema.json'
19
+ },
20
+ meta: {
21
+ checkRead: true,
22
+ checkWrite: false
23
+ }
24
+ };
@@ -0,0 +1,37 @@
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import getCollection from '../getCollection.js';
16
+ import { serialize, deserialize } from '../serialize.js';
17
+ async function mongodbInsertMany({ request , connection }) {
18
+ const deserializedRequest = deserialize(request);
19
+ const { docs , options } = deserializedRequest;
20
+ const { collection , client } = await getCollection({
21
+ connection
22
+ });
23
+ let res;
24
+ try {
25
+ res = await collection.insertMany(docs, options);
26
+ } catch (error) {
27
+ await client.close();
28
+ throw error;
29
+ }
30
+ await client.close();
31
+ const { insertedCount , ops } = serialize(res);
32
+ return {
33
+ insertedCount,
34
+ ops
35
+ };
36
+ }
37
+ export default mongodbInsertMany;
@@ -0,0 +1,32 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "Lowdefy Request Schema - MongoDBInsertMany",
4
+ "type": "object",
5
+ "required": ["docs"],
6
+ "properties": {
7
+ "docs": {
8
+ "type": "array",
9
+ "description": "The array of documents to be inserted.",
10
+ "errorMessage": {
11
+ "type": "MongoDBInsertMany request property \"docs\" should be an array."
12
+ },
13
+ "items": {
14
+ "type": "object",
15
+ "errorMessage": {
16
+ "type": "MongoDBInsertMany request property \"docs\" should be an array of documents to insert."
17
+ }
18
+ }
19
+ },
20
+ "options": {
21
+ "type": "object",
22
+ "description": "Optional settings.",
23
+ "errorMessage": {
24
+ "type": "MongoDBInsertMany request property \"options\" should be an object."
25
+ }
26
+ }
27
+ },
28
+ "errorMessage": {
29
+ "type": "MongoDBInsertMany request properties should be an object.",
30
+ "required": "MongoDBInsertMany request should have required property \"docs\"."
31
+ }
32
+ }
@@ -0,0 +1,24 @@
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ export default {
16
+ import: {
17
+ path: 'connections/MongoDBCollection/MongoDBInsertMany/MongoDBInsertMany.test.js',
18
+ schema: 'connections/MongoDBCollection/MongoDBInsertMany/MongoDBInsertManySchema.json'
19
+ },
20
+ meta: {
21
+ checkRead: false,
22
+ checkWrite: true
23
+ }
24
+ };
@@ -0,0 +1,38 @@
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import getCollection from '../getCollection.js';
16
+ import { serialize, deserialize } from '../serialize.js';
17
+ async function mongodbInsertOne({ request , connection }) {
18
+ const deserializedRequest = deserialize(request);
19
+ const { doc , options } = deserializedRequest;
20
+ const { collection , client } = await getCollection({
21
+ connection
22
+ });
23
+ let res;
24
+ try {
25
+ res = await collection.insertOne(doc, options);
26
+ } catch (error) {
27
+ await client.close();
28
+ throw error;
29
+ }
30
+ await client.close();
31
+ const { insertedCount , insertedId , ops } = serialize(res);
32
+ return {
33
+ insertedCount,
34
+ insertedId,
35
+ ops
36
+ };
37
+ }
38
+ export default mongodbInsertOne;
@@ -0,0 +1,26 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "Lowdefy Request Schema - MongoDBInsertOne",
4
+ "type": "object",
5
+ "required": ["doc"],
6
+ "properties": {
7
+ "doc": {
8
+ "type": "object",
9
+ "description": "The document to be inserted.",
10
+ "errorMessage": {
11
+ "type": "MongoDBInsertOne request property \"doc\" should be an object."
12
+ }
13
+ },
14
+ "options": {
15
+ "type": "object",
16
+ "description": "Optional settings.",
17
+ "errorMessage": {
18
+ "type": "MongoDBInsertOne request property \"options\" should be an object."
19
+ }
20
+ }
21
+ },
22
+ "errorMessage": {
23
+ "type": "MongoDBInsertOne request properties should be an object.",
24
+ "required": "MongoDBInsertOne request should have required property \"doc\"."
25
+ }
26
+ }
@@ -0,0 +1,24 @@
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ export default {
16
+ import: {
17
+ path: 'connections/MongoDBCollection/MongoDBInsertOne/MongoDBInsertOne.js',
18
+ schema: 'connections/MongoDBCollection/MongoDBInsertOne/MongoDBInsertOneSchema.json'
19
+ },
20
+ meta: {
21
+ checkRead: false,
22
+ checkWrite: true
23
+ }
24
+ };
@@ -0,0 +1,39 @@
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import getCollection from '../getCollection.js';
16
+ import { serialize, deserialize } from '../serialize.js';
17
+ async function mongodbUpdateMany({ request , connection }) {
18
+ const deserializedRequest = deserialize(request);
19
+ const { filter , update , options } = deserializedRequest;
20
+ const { collection , client } = await getCollection({
21
+ connection
22
+ });
23
+ let res;
24
+ try {
25
+ res = await collection.updateMany(filter, update, options);
26
+ } catch (error) {
27
+ await client.close();
28
+ throw error;
29
+ }
30
+ await client.close();
31
+ const { modifiedCount , upsertedId , upsertedCount , matchedCount } = serialize(res);
32
+ return {
33
+ modifiedCount,
34
+ upsertedId,
35
+ upsertedCount,
36
+ matchedCount
37
+ };
38
+ }
39
+ export default mongodbUpdateMany;
@@ -0,0 +1,36 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "Lowdefy Request Schema - MongoDBUpdateMany",
4
+ "type": "object",
5
+ "required": ["filter", "update"],
6
+ "properties": {
7
+ "filter": {
8
+ "type": "object",
9
+ "description": "The filter used to select the documents to update.",
10
+ "errorMessage": {
11
+ "type": "MongoDBUpdateMany request property \"filter\" should be an object."
12
+ }
13
+ },
14
+ "update": {
15
+ "type": ["object", "array"],
16
+ "description": "The update operations to be applied to the documents.",
17
+ "errorMessage": {
18
+ "type": "MongoDBUpdateMany request property \"update\" should be an object."
19
+ }
20
+ },
21
+ "options": {
22
+ "type": "object",
23
+ "description": "Optional settings.",
24
+ "errorMessage": {
25
+ "type": "MongoDBUpdateMany request property \"options\" should be an object."
26
+ }
27
+ }
28
+ },
29
+ "errorMessage": {
30
+ "type": "MongoDBUpdateMany request properties should be an object.",
31
+ "required": {
32
+ "filter": "MongoDBUpdateMany request should have required property \"filter\".",
33
+ "update": "MongoDBUpdateMany request should have required property \"update\"."
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,24 @@
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ export default {
16
+ import: {
17
+ path: 'connections/MongoDBCollection/MongoDBUpdateMany/MongoDBUpdateMany.js',
18
+ schema: 'connections/MongoDBCollection/MongoDBUpdateMany/MongoDBUpdateManySchema.json'
19
+ },
20
+ meta: {
21
+ checkRead: false,
22
+ checkWrite: true
23
+ }
24
+ };
@@ -0,0 +1,39 @@
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import getCollection from '../getCollection.js';
16
+ import { serialize, deserialize } from '../serialize.js';
17
+ async function mongodbUpdateOne({ request , connection }) {
18
+ const deserializedRequest = deserialize(request);
19
+ const { filter , update , options } = deserializedRequest;
20
+ const { collection , client } = await getCollection({
21
+ connection
22
+ });
23
+ let res;
24
+ try {
25
+ res = await collection.updateOne(filter, update, options);
26
+ } catch (error) {
27
+ await client.close();
28
+ throw error;
29
+ }
30
+ await client.close();
31
+ const { modifiedCount , upsertedId , upsertedCount , matchedCount } = serialize(res);
32
+ return {
33
+ modifiedCount,
34
+ upsertedId,
35
+ upsertedCount,
36
+ matchedCount
37
+ };
38
+ }
39
+ export default mongodbUpdateOne;
@@ -0,0 +1,36 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "Lowdefy Request Schema - MongoDBUpdateOne",
4
+ "type": "object",
5
+ "required": ["filter", "update"],
6
+ "properties": {
7
+ "filter": {
8
+ "type": "object",
9
+ "description": "The filter used to select the document to update.",
10
+ "errorMessage": {
11
+ "type": "MongoDBUpdateOne request property \"filter\" should be an object."
12
+ }
13
+ },
14
+ "update": {
15
+ "type": ["object", "array"],
16
+ "description": "The update operations to be applied to the document.",
17
+ "errorMessage": {
18
+ "type": "MongoDBUpdateOne request property \"update\" should be an object."
19
+ }
20
+ },
21
+ "options": {
22
+ "type": "object",
23
+ "description": "Optional settings.",
24
+ "errorMessage": {
25
+ "type": "MongoDBUpdateOne request property \"options\" should be an object."
26
+ }
27
+ }
28
+ },
29
+ "errorMessage": {
30
+ "type": "MongoDBUpdateOne request properties should be an object.",
31
+ "required": {
32
+ "filter": "MongoDBUpdateOne request should have required property \"filter\".",
33
+ "update": "MongoDBUpdateOne request should have required property \"update\"."
34
+ }
35
+ }
36
+ }
@@ -0,0 +1,24 @@
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ export default {
16
+ import: {
17
+ path: 'connections/MongoDBCollection/MongoDBUpdateOne/MongoDBUpdateOne.js',
18
+ schema: 'connections/MongoDBCollection/MongoDBUpdateOne/MongoDBUpdateOneSchema.json'
19
+ },
20
+ meta: {
21
+ checkRead: false,
22
+ checkWrite: true
23
+ }
24
+ };
@@ -0,0 +1,36 @@
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { MongoClient } from 'mongodb';
16
+ async function getCollection({ connection }) {
17
+ let client;
18
+ const { collection , databaseUri , databaseName , options } = connection;
19
+ client = new MongoClient(databaseUri, {
20
+ ...options,
21
+ useNewUrlParser: true,
22
+ useUnifiedTopology: true
23
+ });
24
+ await client.connect();
25
+ try {
26
+ const db = client.db(databaseName);
27
+ return {
28
+ client,
29
+ collection: db.collection(collection)
30
+ };
31
+ } catch (error) {
32
+ await client.close();
33
+ throw error;
34
+ }
35
+ }
36
+ export default getCollection;
@@ -0,0 +1,73 @@
1
+ /*
2
+ Copyright 2020-2021 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { ObjectID } from 'mongodb';
16
+ import { type } from '@lowdefy/helpers';
17
+ function replacer(_, value) {
18
+ if (type.isObject(value)) {
19
+ Object.keys(value).forEach((key)=>{
20
+ if (value[key] instanceof ObjectID) {
21
+ // eslint-disable-next-line no-param-reassign
22
+ value[key] = {
23
+ _oid: value[key].toHexString()
24
+ };
25
+ }
26
+ if (type.isDate(value[key])) {
27
+ // eslint-disable-next-line no-param-reassign
28
+ value[key] = {
29
+ _date: value[key].valueOf()
30
+ };
31
+ }
32
+ });
33
+ return value;
34
+ }
35
+ if (type.isArray(value)) {
36
+ return value.map((item)=>{
37
+ if (item instanceof ObjectID) {
38
+ return {
39
+ _oid: item.toHexString()
40
+ };
41
+ }
42
+ if (type.isDate(item)) {
43
+ return {
44
+ _date: item.valueOf()
45
+ };
46
+ }
47
+ return item;
48
+ });
49
+ }
50
+ return value;
51
+ }
52
+ function reviver(key, value) {
53
+ if (type.isObject(value)) {
54
+ if (value._oid) {
55
+ return ObjectID.createFromHexString(value._oid);
56
+ }
57
+ if (type.isInt(value._date) || type.isString(value._date)) {
58
+ return new Date(value._date);
59
+ }
60
+ }
61
+ return value;
62
+ }
63
+ function serialize(obj) {
64
+ if (type.isUndefined(obj)) return obj;
65
+ return JSON.parse(JSON.stringify(obj, replacer));
66
+ }
67
+ // need to use replacer here, since objects are already partially deserialised.
68
+ // otherwise dates become strings
69
+ function deserialize(obj) {
70
+ if (type.isUndefined(obj)) return obj;
71
+ return JSON.parse(JSON.stringify(obj, replacer), reviver);
72
+ }
73
+ export { serialize, deserialize };
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ import MongoDBCollection from './connections/MongoDBCollection/MongoDBCollection.js';
2
+ export const connections = {
3
+ MongoDBCollection
4
+ };
5
+ export default {
6
+ connections
7
+ };
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@lowdefy/connection-mongodb",
3
+ "version": "4.0.0-alpha.1",
4
+ "licence": "Apache-2.0",
5
+ "description": "",
6
+ "homepage": "https://lowdefy.com",
7
+ "keywords": [
8
+ "lowdefy",
9
+ "lowdefy connection"
10
+ ],
11
+ "bugs": {
12
+ "url": "https://github.com/lowdefy/lowdefy/issues"
13
+ },
14
+ "contributors": [
15
+ {
16
+ "name": "Sam Tolmay",
17
+ "url": "https://github.com/SamTolmay"
18
+ },
19
+ {
20
+ "name": "Gerrie van Wyk",
21
+ "url": "https://github.com/Gervwyk"
22
+ }
23
+ ],
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/lowdefy/lowdefy.git"
27
+ },
28
+ "type": "module",
29
+ "exports": {
30
+ ".": "./dist/index.js",
31
+ "./connections/*": "./dist/connections/*"
32
+ },
33
+ "files": [
34
+ "dist/*"
35
+ ],
36
+ "scripts": {
37
+ "build": "yarn swc",
38
+ "clean": "rm -rf dist",
39
+ "prepare": "yarn build",
40
+ "swc": "swc src --out-dir dist --config-file ../../../../.swcrc --delete-dir-on-start --copy-files",
41
+ "test": "jest --coverage"
42
+ },
43
+ "dependencies": {
44
+ "@lowdefy/helpers": "4.0.0-alpha.1",
45
+ "mongodb": "3.7.3",
46
+ "saslprep": "1.0.3"
47
+ },
48
+ "devDependencies": {
49
+ "@lowdefy/ajv": "4.0.0-alpha.1",
50
+ "@shelf/jest-mongodb": "2.1.0",
51
+ "@swc/cli": "0.1.52",
52
+ "@swc/core": "1.2.112",
53
+ "@swc/jest": "0.2.9",
54
+ "jest": "27.3.1"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public"
58
+ },
59
+ "gitHead": "c97a8fa6b5a641e7d50df09f5601a9c586eeb65a"
60
+ }