@lowdefy/connection-mongodb 4.0.0-rc.1 → 4.0.0-rc.11

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.
@@ -23,8 +23,8 @@ Default collections are:
23
23
  VerificationTokens: "verification_tokens",
24
24
  }
25
25
  */ // TODO: Docs: MongoDB database name should be in databaseUri
26
- function MongoDBAdapter({ properties }) {
27
- const { databaseUri , mongoDBClientOptions , options } = properties;
26
+ function MongoDBAdapter({ properties }) {
27
+ const { databaseUri, mongoDBClientOptions, options } = properties;
28
28
  const clientPromise = new MongoClient(databaseUri, mongoDBClientOptions).connect();
29
29
  return NextAuthMongoDBAdapter(clientPromise, options);
30
30
  }
@@ -15,7 +15,7 @@
15
15
  */ import getCollection from '../getCollection.js';
16
16
  import { serialize, deserialize } from '../serialize.js';
17
17
  import schema from './schema.js';
18
- function checkOutAndMerge({ pipeline , connection }) {
18
+ function checkOutAndMerge({ pipeline, connection }) {
19
19
  if (connection.write !== true) {
20
20
  pipeline.forEach((stage)=>{
21
21
  if (stage.$out != null || stage.$merge != null) {
@@ -24,14 +24,14 @@ function checkOutAndMerge({ pipeline , connection }) {
24
24
  });
25
25
  }
26
26
  }
27
- async function MongodbAggregation({ request , connection }) {
27
+ async function MongodbAggregation({ request, connection }) {
28
28
  const deserializedRequest = deserialize(request);
29
- const { pipeline , options } = deserializedRequest;
29
+ const { pipeline, options } = deserializedRequest;
30
30
  checkOutAndMerge({
31
31
  pipeline,
32
32
  connection
33
33
  });
34
- const { collection , client } = await getCollection({
34
+ const { collection, client } = await getCollection({
35
35
  connection
36
36
  });
37
37
  let res;
@@ -15,37 +15,21 @@
15
15
  */ import getCollection from '../getCollection.js';
16
16
  import { serialize, deserialize } from '../serialize.js';
17
17
  import schema from './schema.js';
18
- async function MongodbDeleteMany({ blockId , connection , pageId , request , requestId , payload }) {
18
+ async function MongodbDeleteMany({ connection, request }) {
19
19
  const deserializedRequest = deserialize(request);
20
- const { filter , options } = deserializedRequest;
21
- const { collection , client , logCollection } = await getCollection({
20
+ const { filter, options } = deserializedRequest;
21
+ const { collection, client } = await getCollection({
22
22
  connection
23
23
  });
24
24
  let response;
25
25
  try {
26
26
  response = await collection.deleteMany(filter, options);
27
- if (logCollection) {
28
- await logCollection.insertOne({
29
- args: {
30
- filter,
31
- options
32
- },
33
- blockId,
34
- pageId,
35
- payload,
36
- requestId,
37
- response,
38
- timestamp: new Date(),
39
- type: 'MongoDBDeleteMany',
40
- meta: connection.changeLog?.meta
41
- });
42
- }
43
27
  } catch (error) {
44
28
  await client.close();
45
29
  throw error;
46
30
  }
47
31
  await client.close();
48
- const { acknowledged , deletedCount } = serialize(response);
32
+ const { acknowledged, deletedCount } = serialize(response);
49
33
  return {
50
34
  acknowledged,
51
35
  deletedCount
@@ -15,34 +15,15 @@
15
15
  */ import getCollection from '../getCollection.js';
16
16
  import { serialize, deserialize } from '../serialize.js';
17
17
  import schema from './schema.js';
18
- async function MongodbDeleteOne({ blockId , connection , pageId , request , requestId , payload }) {
18
+ async function MongodbDeleteOne({ connection, request }) {
19
19
  const deserializedRequest = deserialize(request);
20
- const { filter , options } = deserializedRequest;
21
- const { collection , client , logCollection } = await getCollection({
20
+ const { filter, options } = deserializedRequest;
21
+ const { collection, client } = await getCollection({
22
22
  connection
23
23
  });
24
24
  let response;
25
25
  try {
26
- if (logCollection) {
27
- const { value , ...responseWithoutValue } = await collection.findOneAndDelete(filter, options);
28
- response = responseWithoutValue;
29
- await logCollection.insertOne({
30
- args: {
31
- filter,
32
- options
33
- },
34
- blockId,
35
- pageId,
36
- payload,
37
- requestId,
38
- before: value,
39
- timestamp: new Date(),
40
- type: 'MongoDBDeleteOne',
41
- meta: connection.changeLog?.meta
42
- });
43
- } else {
44
- response = await collection.deleteOne(filter, options);
45
- }
26
+ response = await collection.deleteOne(filter, options);
46
27
  } catch (error) {
47
28
  await client.close();
48
29
  throw error;
@@ -15,10 +15,10 @@
15
15
  */ import getCollection from '../getCollection.js';
16
16
  import { serialize, deserialize } from '../serialize.js';
17
17
  import schema from './schema.js';
18
- async function MongodbFind({ request , connection }) {
18
+ async function MongodbFind({ request, connection }) {
19
19
  const deserializedRequest = deserialize(request);
20
- const { query , options } = deserializedRequest;
21
- const { collection , client } = await getCollection({
20
+ const { query, options } = deserializedRequest;
21
+ const { collection, client } = await getCollection({
22
22
  connection
23
23
  });
24
24
  let res;
@@ -15,10 +15,10 @@
15
15
  */ import getCollection from '../getCollection.js';
16
16
  import { serialize, deserialize } from '../serialize.js';
17
17
  import schema from './schema.js';
18
- async function MongodbFindOne({ request , connection }) {
18
+ async function MongodbFindOne({ request, connection }) {
19
19
  const deserializedRequest = deserialize(request);
20
- const { query , options } = deserializedRequest;
21
- const { collection , client } = await getCollection({
20
+ const { query, options } = deserializedRequest;
21
+ const { collection, client } = await getCollection({
22
22
  connection
23
23
  });
24
24
  let res;
@@ -15,37 +15,21 @@
15
15
  */ import getCollection from '../getCollection.js';
16
16
  import { serialize, deserialize } from '../serialize.js';
17
17
  import schema from './schema.js';
18
- async function MongodbInsertMany({ blockId , connection , pageId , request , requestId , payload }) {
18
+ async function MongodbInsertMany({ connection, request }) {
19
19
  const deserializedRequest = deserialize(request);
20
- const { docs , options } = deserializedRequest;
21
- const { collection , client , logCollection } = await getCollection({
20
+ const { docs, options } = deserializedRequest;
21
+ const { collection, client } = await getCollection({
22
22
  connection
23
23
  });
24
24
  let response;
25
25
  try {
26
26
  response = await collection.insertMany(docs, options);
27
- if (logCollection) {
28
- await logCollection.insertOne({
29
- args: {
30
- docs,
31
- options
32
- },
33
- blockId,
34
- pageId,
35
- payload,
36
- requestId,
37
- response,
38
- timestamp: new Date(),
39
- type: 'MongoDBInsertMany',
40
- meta: connection.changeLog?.meta
41
- });
42
- }
43
27
  } catch (error) {
44
28
  await client.close();
45
29
  throw error;
46
30
  }
47
31
  await client.close();
48
- const { acknowledged , insertedCount } = serialize(response);
32
+ const { acknowledged, insertedCount } = serialize(response);
49
33
  return {
50
34
  acknowledged,
51
35
  insertedCount
@@ -15,37 +15,21 @@
15
15
  */ import getCollection from '../getCollection.js';
16
16
  import { serialize, deserialize } from '../serialize.js';
17
17
  import schema from './schema.js';
18
- async function MongodbInsertOne({ blockId , connection , pageId , request , requestId , payload }) {
18
+ async function MongodbInsertOne({ connection, request }) {
19
19
  const deserializedRequest = deserialize(request);
20
- const { doc , options } = deserializedRequest;
21
- const { collection , client , logCollection } = await getCollection({
20
+ const { doc, options } = deserializedRequest;
21
+ const { collection, client } = await getCollection({
22
22
  connection
23
23
  });
24
24
  let response;
25
25
  try {
26
26
  response = await collection.insertOne(doc, options);
27
- if (logCollection) {
28
- await logCollection.insertOne({
29
- args: {
30
- doc,
31
- options
32
- },
33
- blockId,
34
- pageId,
35
- payload,
36
- requestId,
37
- response,
38
- timestamp: new Date(),
39
- type: 'MongoDBInsertOne',
40
- meta: connection.changeLog?.meta
41
- });
42
- }
43
27
  } catch (error) {
44
28
  await client.close();
45
29
  throw error;
46
30
  }
47
31
  await client.close();
48
- const { acknowledged , insertedId } = serialize(response);
32
+ const { acknowledged, insertedId } = serialize(response);
49
33
  return {
50
34
  acknowledged,
51
35
  insertedId
@@ -15,38 +15,21 @@
15
15
  */ import getCollection from '../getCollection.js';
16
16
  import { serialize, deserialize } from '../serialize.js';
17
17
  import schema from './schema.js';
18
- async function MongodbUpdateMany({ blockId , connection , pageId , request , requestId , payload }) {
18
+ async function MongodbUpdateMany({ connection, request }) {
19
19
  const deserializedRequest = deserialize(request);
20
- const { filter , update , options } = deserializedRequest;
21
- const { collection , client , logCollection } = await getCollection({
20
+ const { filter, update, options } = deserializedRequest;
21
+ const { collection, client } = await getCollection({
22
22
  connection
23
23
  });
24
24
  let response;
25
25
  try {
26
26
  response = await collection.updateMany(filter, update, options);
27
- if (logCollection) {
28
- await logCollection.insertOne({
29
- args: {
30
- filter,
31
- update,
32
- options
33
- },
34
- blockId,
35
- pageId,
36
- payload,
37
- requestId,
38
- response,
39
- timestamp: new Date(),
40
- type: 'MongoDBUpdateMany',
41
- meta: connection.changeLog?.meta
42
- });
43
- }
44
27
  } catch (error) {
45
28
  await client.close();
46
29
  throw error;
47
30
  }
48
31
  await client.close();
49
- const { modifiedCount , upsertedId , upsertedCount , matchedCount } = serialize(response);
32
+ const { modifiedCount, upsertedId, upsertedCount, matchedCount } = serialize(response);
50
33
  return {
51
34
  modifiedCount,
52
35
  upsertedId,
@@ -15,39 +15,15 @@
15
15
  */ import getCollection from '../getCollection.js';
16
16
  import { serialize, deserialize } from '../serialize.js';
17
17
  import schema from './schema.js';
18
- async function MongodbUpdateOne({ blockId , connection , pageId , request , requestId , payload }) {
18
+ async function MongodbUpdateOne({ connection, request }) {
19
19
  const deserializedRequest = deserialize(request);
20
- const { filter , update , options } = deserializedRequest;
21
- const { collection , client , logCollection } = await getCollection({
20
+ const { filter, update, options } = deserializedRequest;
21
+ const { collection, client } = await getCollection({
22
22
  connection
23
23
  });
24
24
  let response;
25
25
  try {
26
- if (logCollection) {
27
- const { value , ...responseWithoutValue } = await collection.findOneAndUpdate(filter, update, options);
28
- response = responseWithoutValue;
29
- const after = await collection.findOne({
30
- _id: value._id
31
- });
32
- await logCollection.insertOne({
33
- args: {
34
- filter,
35
- update,
36
- options
37
- },
38
- blockId,
39
- pageId,
40
- payload,
41
- requestId,
42
- before: value,
43
- after,
44
- timestamp: new Date(),
45
- type: 'MongoDBUpdateOne',
46
- meta: connection.changeLog?.meta
47
- });
48
- } else {
49
- response = await collection.updateOne(filter, update, options);
50
- }
26
+ response = await collection.updateOne(filter, update, options);
51
27
  } catch (error) {
52
28
  await client.close();
53
29
  throw error;
@@ -13,17 +13,16 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { MongoClient } from 'mongodb';
16
- async function getCollection({ connection }) {
16
+ async function getCollection({ connection }) {
17
17
  let client;
18
- const { collection , databaseName , databaseUri , changeLog , options } = connection;
18
+ const { collection, databaseName, databaseUri, options } = connection;
19
19
  client = new MongoClient(databaseUri, options);
20
20
  await client.connect();
21
21
  try {
22
22
  const db = client.db(databaseName);
23
23
  return {
24
24
  client,
25
- collection: db.collection(collection),
26
- logCollection: changeLog?.collection && db.collection(changeLog.collection)
25
+ collection: db.collection(collection)
27
26
  };
28
27
  } catch (error) {
29
28
  await client.close();
@@ -30,14 +30,14 @@
30
30
  },
31
31
  databaseName: {
32
32
  type: 'string',
33
- description: 'AWS IAM secret access key with s3 access.',
33
+ description: 'Database name.',
34
34
  errorMessage: {
35
35
  type: 'MongoDBCollection connection property "databaseName" should be a string.'
36
36
  }
37
37
  },
38
38
  collection: {
39
39
  type: 'string',
40
- description: 'AWS region the bucket is located in.',
40
+ description: 'Collection name.',
41
41
  errorMessage: {
42
42
  type: 'MongoDBCollection connection property "collection" should be a string.'
43
43
  }
@@ -13,7 +13,7 @@
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */ import { ObjectId } from 'mongodb';
16
- import { type } from '@lowdefy/helpers';
16
+ import { serializer, type } from '@lowdefy/helpers';
17
17
  function replacer(_, value) {
18
18
  if (type.isObject(value)) {
19
19
  Object.keys(value).forEach((key)=>{
@@ -23,12 +23,6 @@ function replacer(_, value) {
23
23
  _oid: value[key].toHexString()
24
24
  };
25
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
26
  });
33
27
  return value;
34
28
  }
@@ -39,11 +33,6 @@ function replacer(_, value) {
39
33
  _oid: item.toHexString()
40
34
  };
41
35
  }
42
- if (type.isDate(item)) {
43
- return {
44
- _date: item.valueOf()
45
- };
46
- }
47
36
  return item;
48
37
  });
49
38
  }
@@ -54,20 +43,17 @@ function reviver(key, value) {
54
43
  if (value._oid) {
55
44
  return ObjectId.createFromHexString(value._oid);
56
45
  }
57
- if (type.isInt(value._date) || type.isString(value._date)) {
58
- return new Date(value._date);
59
- }
60
46
  }
61
47
  return value;
62
48
  }
63
49
  function serialize(obj) {
64
- if (type.isUndefined(obj)) return obj;
65
- return JSON.parse(JSON.stringify(obj, replacer));
50
+ return serializer.copy(obj, {
51
+ replacer
52
+ });
66
53
  }
67
- // need to use replacer here, since objects are already partially deserialised.
68
- // otherwise dates become strings
69
54
  function deserialize(obj) {
70
- if (type.isUndefined(obj)) return obj;
71
- return JSON.parse(JSON.stringify(obj, replacer), reviver);
55
+ return serializer.copy(obj, {
56
+ reviver
57
+ });
72
58
  }
73
59
  export { serialize, deserialize };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/connection-mongodb",
3
- "version": "4.0.0-rc.1",
3
+ "version": "4.0.0-rc.11",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -42,25 +42,26 @@
42
42
  "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
43
43
  },
44
44
  "dependencies": {
45
- "@lowdefy/helpers": "4.0.0-rc.1",
46
- "@next-auth/mongodb-adapter": "1.1.1",
45
+ "@lowdefy/helpers": "4.0.0-rc.11",
46
+ "@next-auth/mongodb-adapter": "1.1.3",
47
47
  "mongodb": "4.13.0",
48
48
  "saslprep": "1.0.3"
49
49
  },
50
50
  "devDependencies": {
51
- "@lowdefy/ajv": "4.0.0-rc.1",
52
- "@shelf/jest-mongodb": "4.1.4",
53
- "@swc/cli": "0.1.59",
54
- "@swc/core": "1.3.24",
55
- "@swc/jest": "0.2.24",
56
- "jest": "28.1.0",
57
- "jest-environment-node": "28.1.0",
58
- "next-auth": "4.18.8",
51
+ "@lowdefy/ajv": "4.0.0-rc.11",
52
+ "@shelf/jest-mongodb": "4.1.7",
53
+ "@swc/cli": "0.1.62",
54
+ "@swc/core": "1.3.92",
55
+ "@swc/jest": "0.2.29",
56
+ "jest": "28.1.3",
57
+ "jest-environment-node": "28.1.3",
58
+ "next": "13.5.4",
59
+ "next-auth": "4.23.2",
59
60
  "react": "18.2.0",
60
61
  "react-dom": "18.2.0"
61
62
  },
62
63
  "publishConfig": {
63
64
  "access": "public"
64
65
  },
65
- "gitHead": "ecc4f16c19eede929eda177db524cf13a8053379"
66
+ "gitHead": "dbc49d3688a6d2f44de25cc3f4bc071627f7ebfa"
66
67
  }