@mongoosejs/studio 0.0.128 → 0.0.129
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/backend/actions/Model/addField.js +54 -0
- package/backend/actions/Model/getDocument.js +3 -1
- package/backend/actions/Model/getDocuments.js +14 -5
- package/backend/actions/Model/getDocumentsStream.js +14 -5
- package/backend/actions/Model/index.js +1 -0
- package/backend/actions/Model/updateDocument.js +23 -6
- package/backend/actions/Model/updateDocuments.js +23 -5
- package/frontend/public/app.js +613 -45
- package/frontend/public/tw.css +219 -2
- package/frontend/src/api.js +6 -0
- package/frontend/src/document/document.css +8 -0
- package/frontend/src/document/document.html +102 -8
- package/frontend/src/document/document.js +34 -1
- package/frontend/src/document-details/document-details.css +98 -0
- package/frontend/src/document-details/document-details.html +231 -19
- package/frontend/src/document-details/document-details.js +328 -3
- package/frontend/src/document-details/document-property/document-property.css +15 -0
- package/frontend/src/document-details/document-property/document-property.html +75 -31
- package/frontend/src/document-details/document-property/document-property.js +43 -2
- package/frontend/src/edit-boolean/edit-boolean.html +47 -0
- package/frontend/src/edit-boolean/edit-boolean.js +38 -0
- package/frontend/src/models/models.js +79 -30
- package/frontend/src/mothership.js +4 -0
- package/frontend/src/navbar/navbar.html +1 -1
- package/frontend/src/team/team.html +63 -4
- package/frontend/src/team/team.js +47 -1
- package/package.json +1 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Archetype = require('archetype');
|
|
4
|
+
const authorize = require('../../authorize');
|
|
5
|
+
|
|
6
|
+
const AddFieldParams = new Archetype({
|
|
7
|
+
model: {
|
|
8
|
+
$type: 'string',
|
|
9
|
+
$required: true
|
|
10
|
+
},
|
|
11
|
+
_id: {
|
|
12
|
+
$type: Archetype.Any,
|
|
13
|
+
$required: true
|
|
14
|
+
},
|
|
15
|
+
fieldName: {
|
|
16
|
+
$type: 'string',
|
|
17
|
+
$required: true
|
|
18
|
+
},
|
|
19
|
+
fieldValue: {
|
|
20
|
+
$type: Archetype.Any,
|
|
21
|
+
$required: true
|
|
22
|
+
},
|
|
23
|
+
roles: {
|
|
24
|
+
$type: ['string']
|
|
25
|
+
}
|
|
26
|
+
}).compile('AddFieldParams');
|
|
27
|
+
|
|
28
|
+
module.exports = ({ db }) => async function addField(params) {
|
|
29
|
+
const { model, _id, fieldName, fieldValue, roles } = new AddFieldParams(params);
|
|
30
|
+
|
|
31
|
+
await authorize('Model.updateDocument', roles);
|
|
32
|
+
|
|
33
|
+
const Model = db.models[model];
|
|
34
|
+
if (Model == null) {
|
|
35
|
+
throw new Error(`Model ${model} not found`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Create update object with the new field
|
|
39
|
+
const update = { $set: { [fieldName]: fieldValue } };
|
|
40
|
+
|
|
41
|
+
const doc = await Model.findByIdAndUpdate(
|
|
42
|
+
_id,
|
|
43
|
+
update,
|
|
44
|
+
{
|
|
45
|
+
sanitizeFilter: true,
|
|
46
|
+
returnDocument: 'after',
|
|
47
|
+
overwriteImmutable: true,
|
|
48
|
+
runValidators: false,
|
|
49
|
+
strict: false
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
return { doc };
|
|
54
|
+
};
|
|
@@ -42,5 +42,7 @@ module.exports = ({ db }) => async function getDocument(params) {
|
|
|
42
42
|
}
|
|
43
43
|
removeSpecifiedPaths(schemaPaths, '.$*');
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
const virtualPaths = Object.keys(Model.schema.virtuals);
|
|
46
|
+
|
|
47
|
+
return { doc: doc.toJSON({ virtuals: true, getters: false, transform: false }), schemaPaths, virtualPaths };
|
|
46
48
|
};
|
|
@@ -23,8 +23,11 @@ const GetDocumentsParams = new Archetype({
|
|
|
23
23
|
searchText: {
|
|
24
24
|
$type: 'string'
|
|
25
25
|
},
|
|
26
|
-
|
|
27
|
-
$type:
|
|
26
|
+
sortKey: {
|
|
27
|
+
$type: 'string'
|
|
28
|
+
},
|
|
29
|
+
sortDirection: {
|
|
30
|
+
$type: 'number'
|
|
28
31
|
},
|
|
29
32
|
roles: {
|
|
30
33
|
$type: ['string']
|
|
@@ -36,7 +39,7 @@ module.exports = ({ db }) => async function getDocuments(params) {
|
|
|
36
39
|
const { roles } = params;
|
|
37
40
|
await authorize('Model.getDocuments', roles);
|
|
38
41
|
|
|
39
|
-
const { model, limit, skip,
|
|
42
|
+
const { model, limit, skip, sortKey, sortDirection, searchText } = params;
|
|
40
43
|
|
|
41
44
|
const Model = db.models[model];
|
|
42
45
|
if (Model == null) {
|
|
@@ -46,8 +49,14 @@ module.exports = ({ db }) => async function getDocuments(params) {
|
|
|
46
49
|
const parsedFilter = evaluateFilter(searchText);
|
|
47
50
|
const filter = parsedFilter == null ? {} : parsedFilter;
|
|
48
51
|
|
|
49
|
-
const
|
|
50
|
-
|
|
52
|
+
const sortObj = {};
|
|
53
|
+
|
|
54
|
+
if (typeof sortKey === 'string' && sortKey.trim().length > 0) {
|
|
55
|
+
if (sortDirection !== 1 && sortDirection !== -1) {
|
|
56
|
+
throw new Error('Invalid sortDirection. Must be 1 or -1');
|
|
57
|
+
}
|
|
58
|
+
sortObj[sortKey.trim()] = sortDirection;
|
|
59
|
+
}
|
|
51
60
|
if (!sortObj.hasOwnProperty('_id')) {
|
|
52
61
|
sortObj._id = -1;
|
|
53
62
|
}
|
|
@@ -23,8 +23,11 @@ const GetDocumentsParams = new Archetype({
|
|
|
23
23
|
searchText: {
|
|
24
24
|
$type: 'string'
|
|
25
25
|
},
|
|
26
|
-
|
|
27
|
-
$type:
|
|
26
|
+
sortKey: {
|
|
27
|
+
$type: 'string'
|
|
28
|
+
},
|
|
29
|
+
sortDirection: {
|
|
30
|
+
$type: 'number'
|
|
28
31
|
},
|
|
29
32
|
roles: {
|
|
30
33
|
$type: ['string']
|
|
@@ -36,7 +39,7 @@ module.exports = ({ db }) => async function* getDocumentsStream(params) {
|
|
|
36
39
|
const { roles } = params;
|
|
37
40
|
await authorize('Model.getDocumentsStream', roles);
|
|
38
41
|
|
|
39
|
-
const { model, limit, skip,
|
|
42
|
+
const { model, limit, skip, sortKey, sortDirection, searchText } = params;
|
|
40
43
|
|
|
41
44
|
const Model = db.models[model];
|
|
42
45
|
if (Model == null) {
|
|
@@ -46,8 +49,14 @@ module.exports = ({ db }) => async function* getDocumentsStream(params) {
|
|
|
46
49
|
const parsedFilter = evaluateFilter(searchText);
|
|
47
50
|
const filter = parsedFilter == null ? {} : parsedFilter;
|
|
48
51
|
|
|
49
|
-
const
|
|
50
|
-
|
|
52
|
+
const sortObj = {};
|
|
53
|
+
|
|
54
|
+
if (typeof sortKey === 'string' && sortKey.trim().length > 0) {
|
|
55
|
+
if (sortDirection !== 1 && sortDirection !== -1) {
|
|
56
|
+
throw new Error('Invalid sortDirection. Must be 1 or -1');
|
|
57
|
+
}
|
|
58
|
+
sortObj[sortKey.trim()] = sortDirection;
|
|
59
|
+
}
|
|
51
60
|
if (!sortObj.hasOwnProperty('_id')) {
|
|
52
61
|
sortObj._id = -1;
|
|
53
62
|
}
|
|
@@ -31,15 +31,32 @@ module.exports = ({ db }) => async function updateDocument(params) {
|
|
|
31
31
|
throw new Error(`Model ${model} not found`);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
let
|
|
34
|
+
let setFields = {};
|
|
35
|
+
let unsetFields = {};
|
|
36
|
+
|
|
35
37
|
if (Object.keys(update).length > 0) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
Object.entries(update).forEach(([key, value]) => {
|
|
39
|
+
if (value === 'null') {
|
|
40
|
+
setFields[key] = null;
|
|
41
|
+
} else if (value === 'undefined') {
|
|
42
|
+
// Use $unset to remove the field for undefined values
|
|
43
|
+
unsetFields[key] = 1;
|
|
44
|
+
} else {
|
|
45
|
+
setFields[key] = value;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
39
48
|
}
|
|
40
49
|
|
|
41
|
-
|
|
42
|
-
|
|
50
|
+
// Build the update operation with both $set and $unset
|
|
51
|
+
const updateOperation = {};
|
|
52
|
+
if (Object.keys(setFields).length > 0) {
|
|
53
|
+
updateOperation.$set = setFields;
|
|
54
|
+
}
|
|
55
|
+
if (Object.keys(unsetFields).length > 0) {
|
|
56
|
+
updateOperation.$unset = unsetFields;
|
|
57
|
+
}
|
|
43
58
|
|
|
59
|
+
const doc = await Model.
|
|
60
|
+
findByIdAndUpdate(_id, updateOperation, { sanitizeFilter: true, returnDocument: 'after', overwriteImmutable: true, runValidators: false });
|
|
44
61
|
return { doc };
|
|
45
62
|
};
|
|
@@ -31,15 +31,33 @@ module.exports = ({ db }) => async function updateDocuments(params) {
|
|
|
31
31
|
throw new Error(`Model ${model} not found`);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
let
|
|
34
|
+
let setFields = {};
|
|
35
|
+
let unsetFields = {};
|
|
36
|
+
|
|
35
37
|
if (Object.keys(update).length > 0) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
Object.entries(update).forEach(([key, value]) => {
|
|
39
|
+
if (value === 'null') {
|
|
40
|
+
setFields[key] = null;
|
|
41
|
+
} else if (value === 'undefined') {
|
|
42
|
+
// Use $unset to remove the field for undefined values
|
|
43
|
+
unsetFields[key] = 1;
|
|
44
|
+
} else {
|
|
45
|
+
setFields[key] = value;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Build the update operation with both $set and $unset
|
|
51
|
+
const updateOperation = {};
|
|
52
|
+
if (Object.keys(setFields).length > 0) {
|
|
53
|
+
updateOperation.$set = setFields;
|
|
54
|
+
}
|
|
55
|
+
if (Object.keys(unsetFields).length > 0) {
|
|
56
|
+
updateOperation.$unset = unsetFields;
|
|
39
57
|
}
|
|
40
58
|
|
|
41
59
|
const result = await Model.
|
|
42
|
-
updateMany({ _id: { $in: _id } },
|
|
60
|
+
updateMany({ _id: { $in: _id } }, updateOperation, { overwriteImmutable: true, runValidators: false });
|
|
43
61
|
|
|
44
62
|
return { result };
|
|
45
63
|
};
|