@lowdefy/connection-mongodb 4.0.0-alpha.9 → 4.0.0-rc.0
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/dist/auth/adapters/MongoDBAdapter/MongoDBAdapter.js +31 -0
- package/dist/auth/adapters.js +2 -0
- package/dist/connections/MongoDBCollection/MongoDBDeleteMany/MongoDBDeleteMany.js +21 -5
- package/dist/connections/MongoDBCollection/MongoDBDeleteOne/MongoDBDeleteOne.js +23 -5
- package/dist/connections/MongoDBCollection/MongoDBInsertMany/MongoDBInsertMany.js +21 -5
- package/dist/connections/MongoDBCollection/MongoDBInsertOne/MongoDBInsertOne.js +21 -5
- package/dist/connections/MongoDBCollection/MongoDBUpdateMany/MongoDBUpdateMany.js +22 -5
- package/dist/connections/MongoDBCollection/MongoDBUpdateOne/MongoDBUpdateOne.js +28 -5
- package/dist/connections/MongoDBCollection/getCollection.js +4 -7
- package/dist/types.js +6 -3
- package/package.json +20 -15
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2022 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
|
+
import { MongoDBAdapter as NextAuthMongoDBAdapter } from '@next-auth/mongodb-adapter';
|
|
17
|
+
/*
|
|
18
|
+
Default collections are:
|
|
19
|
+
{
|
|
20
|
+
Users: "users",
|
|
21
|
+
Accounts: "accounts",
|
|
22
|
+
Sessions: "sessions",
|
|
23
|
+
VerificationTokens: "verification_tokens",
|
|
24
|
+
}
|
|
25
|
+
*/ // TODO: Docs: MongoDB database name should be in databaseUri
|
|
26
|
+
function MongoDBAdapter({ properties }) {
|
|
27
|
+
const { databaseUri , mongoDBClientOptions , collections } = properties;
|
|
28
|
+
const clientPromise = new MongoClient(databaseUri, mongoDBClientOptions).connect();
|
|
29
|
+
return NextAuthMongoDBAdapter(clientPromise, collections);
|
|
30
|
+
}
|
|
31
|
+
export default MongoDBAdapter;
|
|
@@ -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 ,
|
|
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
|
|
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: '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(
|
|
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 ,
|
|
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
|
|
24
|
+
let response;
|
|
25
25
|
try {
|
|
26
|
-
|
|
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(
|
|
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 ,
|
|
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
|
|
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
|
+
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(
|
|
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 ,
|
|
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
|
|
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
|
+
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(
|
|
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 ,
|
|
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
|
|
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
|
+
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(
|
|
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 ,
|
|
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
|
|
24
|
+
let response;
|
|
25
25
|
try {
|
|
26
|
-
|
|
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(
|
|
55
|
+
const { modifiedCount , upsertedId , upsertedCount , matchedCount } = serialize(response);
|
|
33
56
|
return {
|
|
34
57
|
modifiedCount,
|
|
35
58
|
upsertedId,
|
|
@@ -15,18 +15,15 @@
|
|
|
15
15
|
*/ import { MongoClient } from 'mongodb';
|
|
16
16
|
async function getCollection({ connection }) {
|
|
17
17
|
let client;
|
|
18
|
-
const { collection , databaseUri ,
|
|
19
|
-
client = new MongoClient(databaseUri,
|
|
20
|
-
...options,
|
|
21
|
-
useNewUrlParser: true,
|
|
22
|
-
useUnifiedTopology: true
|
|
23
|
-
});
|
|
18
|
+
const { collection , databaseName , databaseUri , changeLog , options } = connection;
|
|
19
|
+
client = new MongoClient(databaseUri, options);
|
|
24
20
|
await client.connect();
|
|
25
21
|
try {
|
|
26
22
|
const db = client.db(databaseName);
|
|
27
23
|
return {
|
|
28
24
|
client,
|
|
29
|
-
collection: db.collection(collection)
|
|
25
|
+
collection: db.collection(collection),
|
|
26
|
+
logCollection: changeLog?.collection && db.collection(changeLog.collection)
|
|
30
27
|
};
|
|
31
28
|
} catch (error) {
|
|
32
29
|
await client.close();
|
package/dist/types.js
CHANGED
|
@@ -12,9 +12,12 @@
|
|
|
12
12
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
13
|
See the License for the specific language governing permissions and
|
|
14
14
|
limitations under the License.
|
|
15
|
-
*/ import * as
|
|
15
|
+
*/ import * as adapters from './auth/adapters.js';
|
|
16
|
+
import * as connections from './connections.js';
|
|
16
17
|
export default {
|
|
18
|
+
auth: {
|
|
19
|
+
adapters: Object.keys(adapters)
|
|
20
|
+
},
|
|
17
21
|
connections: Object.keys(connections),
|
|
18
|
-
requests: Object.keys(connections).map((connection)=>Object.keys(connections[connection].requests)
|
|
19
|
-
).flat()
|
|
22
|
+
requests: Object.keys(connections).map((connection)=>Object.keys(connections[connection].requests)).flat()
|
|
20
23
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lowdefy/connection-mongodb",
|
|
3
|
-
"version": "4.0.0-
|
|
4
|
-
"
|
|
3
|
+
"version": "4.0.0-rc.0",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
5
|
"description": "",
|
|
6
6
|
"homepage": "https://lowdefy.com",
|
|
7
7
|
"keywords": [
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"type": "module",
|
|
30
30
|
"exports": {
|
|
31
|
+
"./auth/adapters": "./dist/auth/adapters.js",
|
|
31
32
|
"./connections": "./dist/connections.js",
|
|
32
33
|
"./types": "./dist/types.js"
|
|
33
34
|
},
|
|
@@ -35,27 +36,31 @@
|
|
|
35
36
|
"dist/*"
|
|
36
37
|
],
|
|
37
38
|
"scripts": {
|
|
38
|
-
"build": "
|
|
39
|
+
"build": "swc src --out-dir dist --config-file ../../../../.swcrc --delete-dir-on-start --copy-files",
|
|
39
40
|
"clean": "rm -rf dist",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"test": "jest --coverage"
|
|
41
|
+
"prepublishOnly": "pnpm build",
|
|
42
|
+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@lowdefy/helpers": "4.0.0-
|
|
46
|
-
"mongodb": "
|
|
45
|
+
"@lowdefy/helpers": "4.0.0-rc.0",
|
|
46
|
+
"@next-auth/mongodb-adapter": "1.0.3",
|
|
47
|
+
"mongodb": "4.6.0",
|
|
47
48
|
"saslprep": "1.0.3"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
50
|
-
"@lowdefy/ajv": "4.0.0-
|
|
51
|
-
"@shelf/jest-mongodb": "
|
|
52
|
-
"@swc/cli": "0.1.
|
|
53
|
-
"@swc/core": "1.2.
|
|
54
|
-
"@swc/jest": "0.2.
|
|
55
|
-
"jest": "
|
|
51
|
+
"@lowdefy/ajv": "4.0.0-rc.0",
|
|
52
|
+
"@shelf/jest-mongodb": "4.1.0",
|
|
53
|
+
"@swc/cli": "0.1.57",
|
|
54
|
+
"@swc/core": "1.2.194",
|
|
55
|
+
"@swc/jest": "0.2.21",
|
|
56
|
+
"jest": "28.1.0",
|
|
57
|
+
"jest-environment-node": "28.1.0",
|
|
58
|
+
"next-auth": "4.10.3",
|
|
59
|
+
"react": "18.2.0",
|
|
60
|
+
"react-dom": "18.2.0"
|
|
56
61
|
},
|
|
57
62
|
"publishConfig": {
|
|
58
63
|
"access": "public"
|
|
59
64
|
},
|
|
60
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "f6872d7ff6da421710096536fce7b2016ef8f35c"
|
|
61
66
|
}
|