@mongoosejs/studio 0.0.93 → 0.0.95

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.
Files changed (45) hide show
  1. package/.github/workflows/lint.yml +18 -0
  2. package/backend/actions/ChatThread/createChatMessage.js +1 -1
  3. package/backend/actions/ChatThread/createChatThread.js +2 -2
  4. package/backend/actions/Dashboard/getDashboards.js +1 -1
  5. package/backend/actions/Dashboard/updateDashboard.js +1 -1
  6. package/backend/actions/Model/createDocument.js +1 -1
  7. package/backend/actions/Model/deleteDocument.js +3 -3
  8. package/backend/actions/Model/deleteDocuments.js +2 -2
  9. package/backend/actions/Model/exportQueryResults.js +1 -1
  10. package/backend/actions/Model/getDocument.js +1 -1
  11. package/backend/actions/Model/getDocuments.js +2 -2
  12. package/backend/actions/Model/getIndexes.js +1 -1
  13. package/backend/actions/Model/index.js +1 -1
  14. package/backend/actions/Model/updateDocument.js +1 -1
  15. package/backend/actions/Model/updateDocuments.js +1 -1
  16. package/backend/authorize.js +1 -3
  17. package/backend/db/dashboardSchema.js +2 -2
  18. package/backend/helpers/removeSpecifiedPaths.js +1 -1
  19. package/backend/netlify.js +3 -3
  20. package/backend/next.js +1 -1
  21. package/eslint.config.js +46 -0
  22. package/frontend/index.js +1 -1
  23. package/frontend/public/app.js +122 -115
  24. package/frontend/src/api.js +16 -16
  25. package/frontend/src/chat/chat-message/chat-message.js +1 -1
  26. package/frontend/src/chat/chat.js +1 -1
  27. package/frontend/src/clone-document/clone-document.js +8 -8
  28. package/frontend/src/create-dashboard/create-dashboard.js +7 -7
  29. package/frontend/src/create-document/create-document.js +10 -10
  30. package/frontend/src/dashboard/dashboard.js +1 -1
  31. package/frontend/src/dashboard/edit-dashboard/edit-dashboard.js +3 -3
  32. package/frontend/src/dashboards/dashboards.js +1 -1
  33. package/frontend/src/document/confirm-changes/confirm-changes.js +2 -2
  34. package/frontend/src/document/confirm-delete/confirm-delete.js +2 -2
  35. package/frontend/src/document/document.js +2 -2
  36. package/frontend/src/document-details/document-details.js +3 -3
  37. package/frontend/src/document-details/document-property/document-property.js +3 -3
  38. package/frontend/src/edit-array/edit-array.js +1 -1
  39. package/frontend/src/edit-subdocument/edit-subdocument.js +1 -1
  40. package/frontend/src/index.js +3 -1
  41. package/frontend/src/list-default/list-default.js +3 -3
  42. package/frontend/src/models/models.js +11 -11
  43. package/frontend/src/navbar/navbar.js +3 -3
  44. package/frontend/src/update-document/update-document.js +25 -25
  45. package/package.json +4 -1
@@ -0,0 +1,18 @@
1
+ name: Lint
2
+ on:
3
+ pull_request:
4
+ push:
5
+ jobs:
6
+ lint:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v3
10
+ - name: Setting up the node version
11
+ uses: actions/setup-node@v3
12
+ with:
13
+ node-version: 20.19.0
14
+ - name: setup project
15
+ run: npm i
16
+ - name: run lint
17
+ run: |
18
+ npm run lint
@@ -20,7 +20,7 @@ const CreateChatMessageParams = new Archetype({
20
20
  $required: true
21
21
  },
22
22
  roles: {
23
- $type: ['string'],
23
+ $type: ['string']
24
24
  }
25
25
  }).compile('CreateChatMessageParams');
26
26
 
@@ -9,12 +9,12 @@ const CreateChatThreadParams = new Archetype({
9
9
  $type: mongoose.Types.ObjectId
10
10
  },
11
11
  roles: {
12
- $type: ['string'],
12
+ $type: ['string']
13
13
  }
14
14
  }).compile('CreateChatThreadParams');
15
15
 
16
16
  module.exports = ({ studioConnection }) => async function createChatThread(params) {
17
- const { userId } = new CreateChatThreadParams(params);
17
+ const { userId, roles } = new CreateChatThreadParams(params);
18
18
  const ChatThread = studioConnection.model('__Studio_ChatThread');
19
19
 
20
20
  await authorize('ChatThread.createChatThread', roles);
@@ -17,5 +17,5 @@ module.exports = ({ db }) => async function getDashboards(params) {
17
17
 
18
18
  const dashboards = await Dashboard.find();
19
19
 
20
- return { dashboards }
20
+ return { dashboards };
21
21
  };
@@ -26,7 +26,7 @@ const UpdateDashboardParams = new Archetype({
26
26
  module.exports = ({ db }) => async function updateDashboard(params) {
27
27
  const { dashboardId, code, title, description, roles } = new UpdateDashboardParams(params);
28
28
 
29
- const Dashboard = db.models[`__Studio_Dashboard`];
29
+ const Dashboard = db.models['__Studio_Dashboard'];
30
30
 
31
31
  await authorize('Dashboard.updateDashboard', roles);
32
32
 
@@ -14,7 +14,7 @@ const CreateDocumentParams = new Archetype({
14
14
  $required: true
15
15
  },
16
16
  roles: {
17
- $type: ['string'],
17
+ $type: ['string']
18
18
  }
19
19
  }).compile('CreateDocumentParams');
20
20
 
@@ -13,7 +13,7 @@ const DeleteDocumentParams = new Archetype({
13
13
  $required: true
14
14
  },
15
15
  roles: {
16
- $type: ['string'],
16
+ $type: ['string']
17
17
  }
18
18
  }).compile('DeleteDocumentParams');
19
19
 
@@ -29,10 +29,10 @@ module.exports = ({ db }) => async function DeleteDocument(params) {
29
29
  }
30
30
 
31
31
  const doc = await Model.
32
- deleteOne({_id: documentId}).
32
+ deleteOne({ _id: documentId }).
33
33
  setOptions({ sanitizeFilter: true }).
34
34
  orFail();
35
- console.log('what is doc', doc);
35
+ console.log('what is doc', doc);
36
36
 
37
37
  return { doc };
38
38
  };
@@ -13,7 +13,7 @@ const DeleteDocumentsParams = new Archetype({
13
13
  $required: true
14
14
  },
15
15
  roles: {
16
- $type: ['string'],
16
+ $type: ['string']
17
17
  }
18
18
  }).compile('DeleteDocumentsParams');
19
19
 
@@ -29,7 +29,7 @@ module.exports = ({ db }) => async function DeleteDocuments(params) {
29
29
  }
30
30
 
31
31
  await Model.
32
- deleteMany({_id: { $in: documentIds }}).
32
+ deleteMany({ _id: { $in: documentIds } }).
33
33
  setOptions({ sanitizeFilter: true }).
34
34
  orFail();
35
35
 
@@ -66,7 +66,7 @@ module.exports = ({ db }) => async function exportQueryResults(params, req, res)
66
66
 
67
67
  res.set({
68
68
  'Content-Type': 'text/csv',
69
- 'Content-Disposition': `attachment; filename="${model.toLowerCase()}-export.csv"`,
69
+ 'Content-Disposition': `attachment; filename="${model.toLowerCase()}-export.csv"`
70
70
  });
71
71
  return csv;
72
72
  };
@@ -32,7 +32,7 @@ module.exports = ({ db }) => async function getDocument(params) {
32
32
  findById(documentId).
33
33
  setOptions({ sanitizeFilter: true }).
34
34
  orFail();
35
- let schemaPaths = {};
35
+ const schemaPaths = {};
36
36
  for (const path of Object.keys(Model.schema.paths)) {
37
37
  schemaPaths[path] = {
38
38
  instance: Model.schema.paths[path].instance,
@@ -2,7 +2,7 @@
2
2
 
3
3
  const Archetype = require('archetype');
4
4
  const removeSpecifiedPaths = require('../../helpers/removeSpecifiedPaths');
5
- const { EJSON } = require('bson')
5
+ const { EJSON } = require('bson');
6
6
  const authorize = require('../../authorize');
7
7
 
8
8
  const GetDocumentsParams = new Archetype({
@@ -58,7 +58,7 @@ module.exports = ({ db }) => async function getDocuments(params) {
58
58
  skip(skip).
59
59
  sort(hasSort ? sort : { _id: -1 });
60
60
 
61
- let schemaPaths = {};
61
+ const schemaPaths = {};
62
62
  for (const path of Object.keys(Model.schema.paths)) {
63
63
  schemaPaths[path] = {
64
64
  instance: Model.schema.paths[path].instance,
@@ -26,7 +26,7 @@ module.exports = ({ db }) => async function getIndexes(params) {
26
26
  const mongoDBIndexes = await Model.listIndexes();
27
27
  const schemaIndexes = Model.schema.indexes().map(([fields, options]) => ({
28
28
  key: fields,
29
- name: Object.keys(fields).map(key => `${key}_${fields[key]}`).join("_")
29
+ name: Object.keys(fields).map(key => `${key}_${fields[key]}`).join('_')
30
30
  }));
31
31
  const diffIndexes = await Model.diffIndexes();
32
32
  return {
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- exports.createDocument = require('./createDocument')
3
+ exports.createDocument = require('./createDocument');
4
4
  exports.deleteDocument = require('./deleteDocument');
5
5
  exports.deleteDocuments = require('./deleteDocuments');
6
6
  exports.dropIndex = require('./dropIndex');
@@ -17,7 +17,7 @@ const UpdateDocumentsParams = new Archetype({
17
17
  $required: true
18
18
  },
19
19
  roles: {
20
- $type: ['string'],
20
+ $type: ['string']
21
21
  }
22
22
  }).compile('UpdateDocumentsParams');
23
23
 
@@ -17,7 +17,7 @@ const UpdateDocumentsParams = new Archetype({
17
17
  $required: true
18
18
  },
19
19
  roles: {
20
- $type: ['string'],
20
+ $type: ['string']
21
21
  }
22
22
  }).compile('UpdateDocumentsParams');
23
23
 
@@ -10,7 +10,6 @@ const actionsToRequiredRoles = {
10
10
  'Dashboard.deleteDashboard': ['owner', 'admin', 'member'],
11
11
  'Dashboard.getDashboard': ['owner', 'admin', 'member', 'readonly', 'dashboards'],
12
12
  'Dashboard.getDashboards': ['owner', 'admin', 'member', 'readonly', 'dashboards'],
13
- 'Dashboard.getDashboard': ['owner', 'admin', 'member', 'readonly', 'dashboards'],
14
13
  'Dashboard.updateDashboard': ['owner', 'admin', 'member'],
15
14
  'Model.createDocument': ['owner', 'admin', 'member'],
16
15
  'Model.updateDocument': ['owner', 'admin', 'member'],
@@ -21,7 +20,6 @@ const actionsToRequiredRoles = {
21
20
  'Model.getDocuments': ['owner', 'admin', 'member', 'readonly'],
22
21
  'Model.getIndexes': ['owner', 'admin', 'member', 'readonly'],
23
22
  'Model.listModels': ['owner', 'admin', 'member', 'readonly'],
24
- 'Model.updateDocument': ['owner', 'admin', 'member'],
25
23
  'Model.updateDocuments': ['owner', 'admin', 'member']
26
24
  };
27
25
 
@@ -33,4 +31,4 @@ module.exports = function authorize(action, roles) {
33
31
  if (!authorized) {
34
32
  throw new Error(`Unauthorized to take action ${action}`);
35
33
  }
36
- }
34
+ };
@@ -22,7 +22,7 @@ dashboardSchema.methods.evaluate = async function evaluate() {
22
22
  let result = null;
23
23
  result = await vm.runInContext(formatFunction(this.code), context);
24
24
  if (result.$document?.constructor?.modelName) {
25
- let schemaPaths = {};
25
+ const schemaPaths = {};
26
26
  const Model = this.constructor.db.model(result.$document?.constructor?.modelName);
27
27
  for (const path of Object.keys(Model.schema.paths)) {
28
28
  schemaPaths[path] = {
@@ -42,4 +42,4 @@ module.exports = dashboardSchema;
42
42
 
43
43
  const formatFunction = code => `(async function() {
44
44
  ${code}
45
- })();`
45
+ })();`;
@@ -6,4 +6,4 @@ module.exports = function removeSpecifiedPaths(obj, paths) {
6
6
  delete obj[key];
7
7
  }
8
8
  }
9
- }
9
+ };
@@ -22,7 +22,7 @@ module.exports = function netlify(conn, options) {
22
22
  method: 'POST',
23
23
  body: JSON.stringify({ apiKey: options.apiKey }),
24
24
  headers: {
25
- 'Authorization': `Bearer ${options.apiKey}`,
25
+ Authorization: `Bearer ${options.apiKey}`,
26
26
  'Content-Type': 'application/json'
27
27
  }
28
28
  })
@@ -41,7 +41,7 @@ module.exports = function netlify(conn, options) {
41
41
  method: 'POST',
42
42
  body: JSON.stringify({ workspaceId: workspace._id }),
43
43
  headers: {
44
- 'Authorization': authorization,
44
+ Authorization: authorization,
45
45
  'Content-Type': 'application/json'
46
46
  }
47
47
  })
@@ -79,4 +79,4 @@ module.exports = function netlify(conn, options) {
79
79
 
80
80
  return actionFn(params);
81
81
  });
82
- }
82
+ };
package/backend/next.js CHANGED
@@ -28,4 +28,4 @@ module.exports = function next() {
28
28
  .then(result => res.status(200).json(result))
29
29
  .catch(error => res.status(500).json({ message: error.message }));
30
30
  };
31
- }
31
+ };
@@ -0,0 +1,46 @@
1
+ 'use strict';
2
+
3
+ const config = require('@masteringjs/eslint-config');
4
+ const { defineConfig } = require('eslint/config');
5
+
6
+ module.exports = defineConfig([
7
+ {
8
+ ignores: ['frontend/public/*', 'frontend/public/**']
9
+ },
10
+ {
11
+ files: ['backend/**/*.js'],
12
+ languageOptions: {
13
+ sourceType: 'commonjs',
14
+ globals: {
15
+ fetch: true,
16
+ setTimeout: true,
17
+ process: true,
18
+ console: true
19
+ }
20
+ },
21
+ extends: [config]
22
+ },
23
+ {
24
+ files: ['frontend/src/**/*.js', 'frontend/src/*.js', 'frontend/index.js'],
25
+ languageOptions: {
26
+ globals: {
27
+ Prism: true,
28
+ window: true,
29
+ document: true,
30
+ console: true,
31
+ Vue: true,
32
+ VueRouter: true,
33
+ CodeMirror: true,
34
+ Chart: true,
35
+ URLSearchParams: true,
36
+ fetch: true,
37
+ __dirname: true,
38
+ process: true,
39
+ setTimeout: true,
40
+ navigator: true
41
+ },
42
+ sourceType: 'commonjs'
43
+ },
44
+ extends: [config]
45
+ }
46
+ ]);
package/frontend/index.js CHANGED
@@ -14,7 +14,7 @@ module.exports = async function frontend(apiUrl, isLambda, options, workspace) {
14
14
  method: 'POST',
15
15
  body: JSON.stringify({ apiKey: options.apiKey }),
16
16
  headers: {
17
- 'Authorization': `Bearer ${options.apiKey}`,
17
+ Authorization: `Bearer ${options.apiKey}`,
18
18
  'Content-Type': 'application/json'
19
19
  }
20
20
  })