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

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,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 MongodbDeleteMany({ blockId , connection , pageId , request , requestId , payload }) {
18
+ async function MongodbDeleteMany({ blockId, connection, pageId, request, requestId, payload }) {
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, logCollection } = await getCollection({
22
22
  connection
23
23
  });
24
24
  let response;
@@ -45,7 +45,7 @@ async function MongodbDeleteMany({ blockId , connection , pageId , request , req
45
45
  throw error;
46
46
  }
47
47
  await client.close();
48
- const { acknowledged , deletedCount } = serialize(response);
48
+ const { acknowledged, deletedCount } = serialize(response);
49
49
  return {
50
50
  acknowledged,
51
51
  deletedCount
@@ -15,16 +15,16 @@
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({ blockId, connection, pageId, request, requestId, payload }) {
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, logCollection } = await getCollection({
22
22
  connection
23
23
  });
24
24
  let response;
25
25
  try {
26
26
  if (logCollection) {
27
- const { value , ...responseWithoutValue } = await collection.findOneAndDelete(filter, options);
27
+ const { value, ...responseWithoutValue } = await collection.findOneAndDelete(filter, options);
28
28
  response = responseWithoutValue;
29
29
  await logCollection.insertOne({
30
30
  args: {
@@ -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,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 MongodbInsertMany({ blockId , connection , pageId , request , requestId , payload }) {
18
+ async function MongodbInsertMany({ blockId, connection, pageId, request, requestId, payload }) {
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, logCollection } = await getCollection({
22
22
  connection
23
23
  });
24
24
  let response;
@@ -45,7 +45,7 @@ async function MongodbInsertMany({ blockId , connection , pageId , request , req
45
45
  throw error;
46
46
  }
47
47
  await client.close();
48
- const { acknowledged , insertedCount } = serialize(response);
48
+ const { acknowledged, insertedCount } = serialize(response);
49
49
  return {
50
50
  acknowledged,
51
51
  insertedCount
@@ -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 MongodbInsertOne({ blockId , connection , pageId , request , requestId , payload }) {
18
+ async function MongodbInsertOne({ blockId, connection, pageId, request, requestId, payload }) {
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, logCollection } = await getCollection({
22
22
  connection
23
23
  });
24
24
  let response;
@@ -45,7 +45,7 @@ async function MongodbInsertOne({ blockId , connection , pageId , request , requ
45
45
  throw error;
46
46
  }
47
47
  await client.close();
48
- const { acknowledged , insertedId } = serialize(response);
48
+ const { acknowledged, insertedId } = serialize(response);
49
49
  return {
50
50
  acknowledged,
51
51
  insertedId
@@ -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 MongodbUpdateMany({ blockId , connection , pageId , request , requestId , payload }) {
18
+ async function MongodbUpdateMany({ blockId, connection, pageId, request, requestId, payload }) {
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, logCollection } = await getCollection({
22
22
  connection
23
23
  });
24
24
  let response;
@@ -46,7 +46,7 @@ async function MongodbUpdateMany({ blockId , connection , pageId , request , req
46
46
  throw error;
47
47
  }
48
48
  await client.close();
49
- const { modifiedCount , upsertedId , upsertedCount , matchedCount } = serialize(response);
49
+ const { modifiedCount, upsertedId, upsertedCount, matchedCount } = serialize(response);
50
50
  return {
51
51
  modifiedCount,
52
52
  upsertedId,
@@ -15,19 +15,19 @@
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({ blockId, connection, pageId, request, requestId, payload }) {
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, logCollection } = await getCollection({
22
22
  connection
23
23
  });
24
24
  let response;
25
25
  try {
26
26
  if (logCollection) {
27
- const { value , ...responseWithoutValue } = await collection.findOneAndUpdate(filter, update, options);
27
+ const { value, ...responseWithoutValue } = await collection.findOneAndUpdate(filter, update, options);
28
28
  response = responseWithoutValue;
29
29
  const after = await collection.findOne({
30
- _id: value._id
30
+ _id: value ? value._id : response.lastErrorObject?.upserted
31
31
  });
32
32
  await logCollection.insertOne({
33
33
  args: {
@@ -13,9 +13,9 @@
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, changeLog, options } = connection;
19
19
  client = new MongoClient(databaseUri, options);
20
20
  await client.connect();
21
21
  try {
@@ -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.10",
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",
45
+ "@lowdefy/helpers": "4.0.0-rc.10",
46
46
  "@next-auth/mongodb-adapter": "1.1.1",
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",
51
+ "@lowdefy/ajv": "4.0.0-rc.10",
52
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",
53
+ "@swc/cli": "0.1.62",
54
+ "@swc/core": "1.3.70",
55
+ "@swc/jest": "0.2.27",
56
+ "jest": "28.1.3",
57
+ "jest-environment-node": "28.1.3",
58
+ "next": "12.3.4",
59
+ "next-auth": "4.20.1",
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": "537af074f27770e32da9da8d48490f2eda94b406"
66
67
  }