@mongoosejs/studio 0.0.28 → 0.0.30

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 (31) hide show
  1. package/backend/actions/Dashboard/createDashboard.js +22 -0
  2. package/backend/actions/Dashboard/getDashboard.js +41 -8
  3. package/backend/actions/Dashboard/index.js +1 -0
  4. package/backend/db/dashboardSchema.js +4 -1
  5. package/backend/index.js +1 -1
  6. package/frontend/public/app.js +381 -46
  7. package/frontend/public/index.html +1 -0
  8. package/frontend/public/tw.css +323 -0
  9. package/frontend/src/api.js +6 -0
  10. package/frontend/src/create-dashboard/create-dashboard.html +43 -0
  11. package/frontend/src/create-dashboard/create-dashboard.js +40 -0
  12. package/frontend/src/dashboard/dashboard.html +16 -7
  13. package/frontend/src/dashboard/dashboard.js +4 -4
  14. package/frontend/src/dashboard-result/dashboard-chart/dashboard-chart.html +8 -0
  15. package/frontend/src/dashboard-result/dashboard-chart/dashboard-chart.js +20 -0
  16. package/frontend/src/dashboard-result/dashboard-document/dashboard-document.html +8 -0
  17. package/frontend/src/dashboard-result/dashboard-document/dashboard-document.js +29 -0
  18. package/frontend/src/dashboard-result/dashboard-primitive/dashboard-primitive.html +8 -0
  19. package/frontend/src/dashboard-result/dashboard-primitive/dashboard-primitive.js +24 -0
  20. package/frontend/src/dashboard-result/dashboard-result.html +18 -0
  21. package/frontend/src/dashboard-result/dashboard-result.js +30 -0
  22. package/frontend/src/dashboards/dashboards.html +77 -3
  23. package/frontend/src/dashboards/dashboards.js +2 -3
  24. package/frontend/src/document/document.css +0 -16
  25. package/frontend/src/document/document.html +5 -34
  26. package/frontend/src/document/document.js +0 -34
  27. package/frontend/src/document-details/document-details.css +18 -0
  28. package/frontend/src/document-details/document-details.html +36 -0
  29. package/frontend/src/document-details/document-details.js +59 -0
  30. package/frontend/src/index.js +6 -0
  31. package/package.json +1 -1
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+ const Archetype = require('archetype');
3
+
4
+ const CreateDashboardParams = new Archetype({
5
+ title: {
6
+ $type: 'string',
7
+ $required: true
8
+ },
9
+ code: {
10
+ $type: 'string',
11
+ $required: true
12
+ }
13
+ }).compile('CreateDashboardParams');
14
+
15
+ module.exports = ({ db }) => async function createDashboard(params) {
16
+ const { title, code } = new CreateDashboardParams(params);
17
+ const Dashboard = db.model('__Studio_Dashboard');
18
+
19
+ const dashboard = await Dashboard.create({ title, code });
20
+
21
+ return { dashboard };
22
+ };
@@ -1,18 +1,51 @@
1
1
  'use strict';
2
+
2
3
  const Archetype = require('archetype');
4
+ const vm = require('vm');
3
5
 
4
6
  const GetDashboardParams = new Archetype({
5
- dashboardId: {
6
- $type: 'string',
7
- $required: true
8
- }
9
- }).compile('GetDashboardParams');
7
+ dashboardId: {
8
+ $type: 'string',
9
+ $required: true
10
+ },
11
+ evaluate: {
12
+ $type: 'boolean'
13
+ }
14
+ }).compile('GetDashboardParams');
10
15
 
11
16
  module.exports = ({ db }) => async function getDashboard(params) {
12
- const { dashboardId } = new GetDashboardParams(params);
17
+ const { dashboardId, evaluate } = new GetDashboardParams(params);
13
18
  const Dashboard = db.model('__Studio_Dashboard');
14
19
 
15
20
  const dashboard = await Dashboard.findOne({ _id: dashboardId });
21
+ if (evaluate) {
22
+ const context = vm.createContext({ db });
23
+ let result = null;
24
+ try {
25
+ result = await vm.runInContext(formatFunction(dashboard.code), context);
26
+ if (result.$document?.model) {
27
+ let schemaPaths = {};
28
+ const Model = Dashboard.db.model(result.$document?.model);
29
+ for (const path of Object.keys(Model.schema.paths)) {
30
+ schemaPaths[path] = {
31
+ instance: Model.schema.paths[path].instance,
32
+ path,
33
+ ref: Model.schema.paths[path].options?.ref,
34
+ required: Model.schema.paths[path].options?.required
35
+ };
36
+ }
37
+ result.$document.schemaPaths = schemaPaths;
38
+ }
39
+ } catch (error) {
40
+ return { dashboard, error: { message: error.message } };
41
+ }
42
+
43
+ return { dashboard, result };
44
+ }
45
+
46
+ return { dashboard };
47
+ };
16
48
 
17
- return { dashboard }
18
- };
49
+ const formatFunction = code => `(async function() {
50
+ ${code}
51
+ })();`
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ exports.createDashboard = require('./createDashboard');
3
4
  exports.getDashboard = require('./getDashboard');
4
5
  exports.getDashboards = require('./getDashboards');
5
6
  exports.updateDashboard = require('./updateDashboard');
@@ -3,13 +3,16 @@
3
3
  const mongoose = require('mongoose');
4
4
 
5
5
  const dashboardSchema = new mongoose.Schema({
6
- name: {
6
+ title: {
7
7
  type: String,
8
8
  required: true
9
9
  },
10
10
  code: {
11
11
  type: String,
12
12
  required: true
13
+ },
14
+ description: {
15
+ type: String
13
16
  }
14
17
  });
15
18
 
package/backend/index.js CHANGED
@@ -9,7 +9,7 @@ const dashboardSchema = require('./db/dashboardSchema');
9
9
  module.exports = function backend(db) {
10
10
  db = db || mongoose.connection;
11
11
 
12
- const Dashboard = db.model('Studio_Dashboard', dashboardSchema, 'studio__dashboards');
12
+ const Dashboard = db.model('__Studio_Dashboard', dashboardSchema, 'studio__dashboards');
13
13
  const actions = applySpec(Actions, { db });
14
14
  return actions;
15
15
  };