@lowdefy/connection-mongodb 4.0.0-alpha.33 → 4.0.0-alpha.34

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.
@@ -15,21 +15,37 @@
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({ request , connection }) {
18
+ async function MongodbDeleteMany({ blockId , connection , pageId , request , requestId , payload }) {
19
19
  const deserializedRequest = deserialize(request);
20
20
  const { filter , options } = deserializedRequest;
21
- const { collection , client } = await getCollection({
21
+ const { collection , client , logCollection } = await getCollection({
22
22
  connection
23
23
  });
24
- let res;
24
+ let response;
25
25
  try {
26
- res = await collection.deleteMany(filter, options);
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: 'MongoDBInsertMany',
40
+ user: connection.changeLog?.user
41
+ });
42
+ }
27
43
  } catch (error) {
28
44
  await client.close();
29
45
  throw error;
30
46
  }
31
47
  await client.close();
32
- const { acknowledged , deletedCount } = serialize(res);
48
+ const { acknowledged , deletedCount } = serialize(response);
33
49
  return {
34
50
  acknowledged,
35
51
  deletedCount
@@ -15,21 +15,39 @@
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({ request , connection }) {
18
+ async function MongodbDeleteOne({ blockId , connection , pageId , request , requestId , payload }) {
19
19
  const deserializedRequest = deserialize(request);
20
20
  const { filter , options } = deserializedRequest;
21
- const { collection , client } = await getCollection({
21
+ const { collection , client , logCollection } = await getCollection({
22
22
  connection
23
23
  });
24
- let res;
24
+ let response;
25
25
  try {
26
- res = await collection.deleteOne(filter, options);
26
+ if (logCollection) {
27
+ response = await collection.findOneAndDelete(filter, options);
28
+ await logCollection.insertOne({
29
+ args: {
30
+ filter,
31
+ options
32
+ },
33
+ blockId,
34
+ pageId,
35
+ payload,
36
+ requestId,
37
+ before: response,
38
+ timestamp: new Date(),
39
+ type: 'MongoDBDeleteOne',
40
+ user: connection.changeLog?.user
41
+ });
42
+ } else {
43
+ response = await collection.deleteOne(filter, options);
44
+ }
27
45
  } catch (error) {
28
46
  await client.close();
29
47
  throw error;
30
48
  }
31
49
  await client.close();
32
- const { acknowledged , deletedCount } = serialize(res);
50
+ const { acknowledged , deletedCount } = serialize(response);
33
51
  return {
34
52
  acknowledged,
35
53
  deletedCount
@@ -15,21 +15,37 @@
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({ request , connection }) {
18
+ async function MongodbInsertMany({ blockId , connection , pageId , request , requestId , payload }) {
19
19
  const deserializedRequest = deserialize(request);
20
20
  const { docs , options } = deserializedRequest;
21
- const { collection , client } = await getCollection({
21
+ const { collection , client , logCollection } = await getCollection({
22
22
  connection
23
23
  });
24
- let res;
24
+ let response;
25
25
  try {
26
- res = await collection.insertMany(docs, options);
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
+ user: connection.changeLog?.user
41
+ });
42
+ }
27
43
  } catch (error) {
28
44
  await client.close();
29
45
  throw error;
30
46
  }
31
47
  await client.close();
32
- const { acknowledged , insertedCount } = serialize(res);
48
+ const { acknowledged , insertedCount } = serialize(response);
33
49
  return {
34
50
  acknowledged,
35
51
  insertedCount
@@ -15,21 +15,37 @@
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({ request , connection }) {
18
+ async function MongodbInsertOne({ blockId , connection , pageId , request , requestId , payload }) {
19
19
  const deserializedRequest = deserialize(request);
20
20
  const { doc , options } = deserializedRequest;
21
- const { collection , client } = await getCollection({
21
+ const { collection , client , logCollection } = await getCollection({
22
22
  connection
23
23
  });
24
- let res;
24
+ let response;
25
25
  try {
26
- res = await collection.insertOne(doc, options);
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
+ user: connection.changeLog?.user
41
+ });
42
+ }
27
43
  } catch (error) {
28
44
  await client.close();
29
45
  throw error;
30
46
  }
31
47
  await client.close();
32
- const { acknowledged , insertedId } = serialize(res);
48
+ const { acknowledged , insertedId } = serialize(response);
33
49
  return {
34
50
  acknowledged,
35
51
  insertedId
@@ -15,21 +15,38 @@
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({ request , connection }) {
18
+ async function MongodbUpdateMany({ blockId , connection , pageId , request , requestId , payload }) {
19
19
  const deserializedRequest = deserialize(request);
20
20
  const { filter , update , options } = deserializedRequest;
21
- const { collection , client } = await getCollection({
21
+ const { collection , client , logCollection } = await getCollection({
22
22
  connection
23
23
  });
24
- let res;
24
+ let response;
25
25
  try {
26
- res = await collection.updateMany(filter, update, options);
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
+ user: connection.changeLog?.user
42
+ });
43
+ }
27
44
  } catch (error) {
28
45
  await client.close();
29
46
  throw error;
30
47
  }
31
48
  await client.close();
32
- const { modifiedCount , upsertedId , upsertedCount , matchedCount } = serialize(res);
49
+ const { modifiedCount , upsertedId , upsertedCount , matchedCount } = serialize(response);
33
50
  return {
34
51
  modifiedCount,
35
52
  upsertedId,
@@ -15,21 +15,44 @@
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({ request , connection }) {
18
+ async function MongodbUpdateOne({ blockId , connection , pageId , request , requestId , payload }) {
19
19
  const deserializedRequest = deserialize(request);
20
20
  const { filter , update , options } = deserializedRequest;
21
- const { collection , client } = await getCollection({
21
+ const { collection , client , logCollection } = await getCollection({
22
22
  connection
23
23
  });
24
- let res;
24
+ let response;
25
25
  try {
26
- res = await collection.updateOne(filter, update, options);
26
+ if (logCollection) {
27
+ response = await collection.findOneAndUpdate(filter, update, options);
28
+ const after = await collection.findOne({
29
+ _id: response._id
30
+ });
31
+ await logCollection.insertOne({
32
+ args: {
33
+ filter,
34
+ update,
35
+ options
36
+ },
37
+ blockId,
38
+ pageId,
39
+ payload,
40
+ requestId,
41
+ before: response,
42
+ after,
43
+ timestamp: new Date(),
44
+ type: 'MongoDBUpdateOne',
45
+ user: connection.changeLog?.user
46
+ });
47
+ } else {
48
+ response = await collection.updateOne(filter, update, options);
49
+ }
27
50
  } catch (error) {
28
51
  await client.close();
29
52
  throw error;
30
53
  }
31
54
  await client.close();
32
- const { modifiedCount , upsertedId , upsertedCount , matchedCount } = serialize(res);
55
+ const { modifiedCount , upsertedId , upsertedCount , matchedCount } = serialize(response);
33
56
  return {
34
57
  modifiedCount,
35
58
  upsertedId,
@@ -15,14 +15,15 @@
15
15
  */ import { MongoClient } from 'mongodb';
16
16
  async function getCollection({ connection }) {
17
17
  let client;
18
- const { collection , databaseUri , databaseName , options } = connection;
18
+ const { collection , databaseName , databaseUri , changeLog , 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)
25
+ collection: db.collection(collection),
26
+ logCollection: changeLog?.collection && db.collection(changeLog.collection)
26
27
  };
27
28
  } catch (error) {
28
29
  await client.close();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/connection-mongodb",
3
- "version": "4.0.0-alpha.33",
3
+ "version": "4.0.0-alpha.34",
4
4
  "license": "Apache-2.0",
5
5
  "description": "",
6
6
  "homepage": "https://lowdefy.com",
@@ -42,13 +42,13 @@
42
42
  "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
43
43
  },
44
44
  "dependencies": {
45
- "@lowdefy/helpers": "4.0.0-alpha.33",
45
+ "@lowdefy/helpers": "4.0.0-alpha.34",
46
46
  "@next-auth/mongodb-adapter": "1.0.3",
47
47
  "mongodb": "4.6.0",
48
48
  "saslprep": "1.0.3"
49
49
  },
50
50
  "devDependencies": {
51
- "@lowdefy/ajv": "4.0.0-alpha.33",
51
+ "@lowdefy/ajv": "4.0.0-alpha.34",
52
52
  "@shelf/jest-mongodb": "4.1.0",
53
53
  "@swc/cli": "0.1.57",
54
54
  "@swc/core": "1.2.194",
@@ -62,5 +62,5 @@
62
62
  "publishConfig": {
63
63
  "access": "public"
64
64
  },
65
- "gitHead": "0aa1d1126108b835a6e3e3f57bbef53658777f21"
65
+ "gitHead": "5e801532cef950b947c0069a5ba1a8f5ed6bb66f"
66
66
  }