🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@mongoosejs/studio

Package Overview
Dependencies
Maintainers
1
Versions
99
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mongoosejs/studio - npm Package Compare versions

Comparing version

to
0.0.3

backend/actions/Model/deleteDocument.js

12

backend/actions/Model/getDocument.js
'use strict';
const Archetype = require('archetype');
const removeSpecifiedPaths = require('../../helpers/removeSpecifiedPaths');

@@ -28,4 +29,13 @@ const GetDocumentParams = new Archetype({

orFail();
let schemaPaths = {};
for (const path of Object.keys(Model.schema.paths)) {
schemaPaths[path] = {
instance: Model.schema.paths[path].instance,
path,
options: Model.schema.paths[path].options
};
}
removeSpecifiedPaths(schemaPaths, '.$*');
return { doc, schemaPaths: Model.schema.paths };
return { doc, schemaPaths };
};
'use strict';
const Archetype = require('archetype');
const removeSpecifiedPaths = require('../../helpers/removeSpecifiedPaths');
const EJSON = require('ejson');

@@ -22,2 +24,5 @@ const GetDocumentsParams = new Archetype({

$type: Archetype.Any
},
sort: {
$type: Archetype.Any
}

@@ -29,3 +34,6 @@ }).compile('GetDocumentsParams');

let { filter } = params;
const { model, limit, skip } = params;
if (filter != null && Object.keys(filter).length > 0) {
filter = EJSON.parse(filter);
}
const { model, limit, skip, sort } = params;

@@ -43,8 +51,21 @@ const Model = db.models[model];

find(filter == null ? {} : filter).
setOptions({ sanitizeFilter: true }).
limit(limit).
skip(skip).
sort({ _id: -1 });
sort(sort == null ? { _id: -1 } : sort );
let schemaPaths = {};
for (const path of Object.keys(Model.schema.paths)) {
schemaPaths[path] = {
instance: Model.schema.paths[path].instance,
path,
options: Model.schema.paths[path].options
};
}
removeSpecifiedPaths(schemaPaths, '.$*');
const numDocuments = filter == null ?
await Model.estimatedDocumentCount() :
await Model.countDocuments(filter);
return { docs, schemaPaths: Model.schema.paths };
return { docs, schemaPaths, numDocs: numDocuments };
};
'use strict';
exports.deleteDocument = require('./deleteDocument');
exports.exportQueryResults = require('./exportQueryResults');

@@ -4,0 +5,0 @@ exports.getDocument = require('./getDocument');

@@ -11,2 +11,5 @@ 'use strict';

exports.Model = {
deleteDocument(params) {
return client.post('', { action: 'Model.deleteDocument', ...params}).then(res => res.data);
},
exportQueryResults(params) {

@@ -30,2 +33,5 @@ return client.post('', { action: 'Model.exportQueryResults', ...params }).then(res => res.data);

exports.Model = {
deleteDocument: function (params) {
return client.post('/Model/deleteDocument', params).then(res => res.data);
},
exportQueryResults(params) {

@@ -32,0 +38,0 @@ const anchor = document.createElement('a');

@@ -5,2 +5,3 @@ 'use strict';

const template = require('./document.html');
const vanillatoast = require('vanillatoasts');

@@ -43,3 +44,9 @@ const appendCSS = require('../appendCSS');

},
getEditComponentForPath() {
getEditComponentForPath(path) {
if (path.instance == 'Date') {
return 'edit-date';
}
if (path.instance == 'Number') {
return 'edit-number';
}
return 'edit-default';

@@ -63,4 +70,21 @@ },

this.editting = false;
},
async remove() {
const { doc } = await api.Model.deleteDocument({
model: this.model,
documentId: this.document._id
});
if (doc.acknowledged) {
this.editting = false;
this.document = {};
vanillatoast.create({
title: 'Document Deleted!',
type: 'success',
timeout: 3000,
positionClass: 'bottomRight'
});
this.$router.push({ path: `/model/${this.model}`});
}
}
}
});

@@ -12,5 +12,8 @@ 'use strict';

require('./edit-default/edit-default')(app);
require('./edit-number/edit-number')(app);
require('./edit-date/edit-date')(app);
require('./export-query-results/export-query-results')(app);
require('./list-array/list-array')(app);
require('./list-default/list-default')(app);
require('./list-string/list-string')(app);
require('./list-subdocument/list-subdocument')(app);

@@ -17,0 +20,0 @@ require('./modal/modal')(app);

'use strict';
const template = require('./list-default.html');
const appendCSS = require('../appendCSS');
const vanillatoast = require('vanillatoasts');
appendCSS(require('./list-default.css'));
module.exports = app => app.component('list-default', {
template: template,
props: ['value'],
props: ['value', 'allude'],
methods: {
copyText(value) {
const storage = document.createElement('textarea');
storage.value = value;
const elem = this.$refs.itemData
elem.appendChild(storage);
storage.select();
storage.setSelectionRange(0, 99999);
document.execCommand('copy');
elem.removeChild(storage);
vanillatoast.create({
title: 'Text copied!',
type: 'success',
timeout: 3000,
icon: 'images/success.png',
positionClass: 'bottomRight'
});
},
goToDoc(id) {
this.$router.push({ path: `/model/${this.allude}/document/${id}`});
}
},
computed: {

@@ -17,4 +43,7 @@ displayValue() {

return this.value;
},
hasReference() {
return this.allude;
}
}
});

5

frontend/src/list-subdocument/list-subdocument.js

@@ -8,3 +8,6 @@ 'use strict';

template: template,
props: ['value']
props: ['value'],
mounted: function() {
Prism.highlightElement(this.$refs.SubDocCode);
}
});

@@ -5,2 +5,3 @@ 'use strict';

const template = require('./models.html');
const EJSON = require('ejson');

@@ -19,2 +20,3 @@ const appendCSS = require('../appendCSS');

schemaPaths: [],
numDocuments: 0,
status: 'init',

@@ -26,3 +28,4 @@ edittingDoc: null,

shouldShowExportModal: false,
shouldExport: {}
shouldExport: {},
sortBy: {}
}),

@@ -37,20 +40,10 @@ created() {

}
if (this.$route.query?.search) {
this.searchText = this.$route.query.search;
this.filter = eval(`(${this.$route.query.search})`);
this.filter = EJSON.stringify(this.filter);
}
if (this.currentModel != null) {
const { docs, schemaPaths } = await api.Model.getDocuments({ model: this.currentModel });
this.documents = docs;
this.schemaPaths = Object.keys(schemaPaths).sort((k1, k2) => {
if (k1 === '_id' && k2 !== '_id') {
return -1;
}
if (k1 !== '_id' && k2 === '_id') {
return 1;
}
return 0;
}).map(key => schemaPaths[key]);
this.shouldExport = {};
for (const { path } of this.schemaPaths) {
this.shouldExport[path] = true;
}
await this.getDocuments();
}

@@ -61,15 +54,31 @@

methods: {
async sortDocs(num, path) {
let sorted = false;
if (this.sortBy[path] == num) {
sorted = true;
}
for (const key in this.sortBy) {
delete this.sortBy[key];
}
if (!sorted) {
this.sortBy[path] = num;
}
await this.getDocuments();
},
async search() {
if (this.searchText) {
if (this.searchText && Object.keys(this.searchText).length) {
this.filter = eval(`(${this.searchText})`);
this.filter = EJSON.stringify(this.filter);
this.$router.push({ path: this.$route.path, query: { search: this.searchText }})
} else {
this.filter = {};
this.$router.push({ path: this.$route.path });
}
await this.getDocuments();
},
async getDocuments() {
const { docs, schemaPaths } = await api.Model.getDocuments({
const { docs, schemaPaths, numDocs } = await api.Model.getDocuments({
model: this.currentModel,
filter: this.filter
filter: this.filter,
sort: this.sortBy
});

@@ -86,2 +95,3 @@ this.documents = docs;

}).map(key => schemaPaths[key]);
this.numDocuments = numDocs;

@@ -97,4 +107,13 @@ this.shouldExport = {};

}
if (schemaPath.instance === 'String') {
return 'list-string';
}
if (schemaPath.instance == 'Embedded') {
return 'list-subdocument';
}
return 'list-default';
},
getReferenceModel(schemaPath) {
return schemaPath.options?.ref;
},
async saveDocEdits() {

@@ -101,0 +120,0 @@ const res = await api.Model.updateDocument({

{
"name": "@mongoosejs/studio",
"version": "0.0.2",
"version": "0.0.3",
"dependencies": {
"archetype": "0.13.0",
"csv-stringify": "6.3.0",
"extrovert": "0.0.20"
"ejson": "^2.2.3",
"extrovert": "0.0.20",
"vanillatoasts": "^1.6.0"
},
"peerDependencies": {
"express": "4.x",
"mongoose": "6.x || 7.x || 7.0.0-rc0"
"mongoose": "7.x"
},

@@ -17,6 +19,6 @@ "devDependencies": {

"mocha": "10.2.0",
"mongoose": "6.x",
"webpack": "5.75.0",
"vue": "3.x"
"mongoose": "7.x",
"vue": "3.x",
"webpack": "5.75.0"
}
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet