@mongoosejs/studio 0.0.11 → 0.0.13
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/createChart.js +60 -0
- package/backend/actions/Model/getDocument.js +1 -1
- package/backend/actions/Model/index.js +1 -0
- package/backend/actions/Script/execute.js +20 -0
- package/backend/actions/Script/index.js +3 -0
- package/backend/actions/index.js +2 -1
- package/frontend/public/index.html +1 -0
- package/frontend/src/api.js +9 -0
- package/frontend/src/charts/charts.css +17 -0
- package/frontend/src/charts/charts.html +14 -0
- package/frontend/src/charts/charts.js +19 -0
- package/frontend/src/document/document.html +2 -2
- package/frontend/src/document/document.js +6 -2
- package/frontend/src/index.js +2 -0
- package/frontend/src/list-array/list-array.css +2 -2
- package/frontend/src/list-array/list-array.js +2 -7
- package/frontend/src/list-default/list-default.css +4 -0
- package/frontend/src/list-default/list-default.html +2 -2
- package/frontend/src/list-default/list-default.js +3 -0
- package/frontend/src/list-mixed/list-mixed.css +5 -0
- package/frontend/src/list-mixed/list-mixed.html +4 -0
- package/frontend/src/list-mixed/list-mixed.js +19 -0
- package/frontend/src/list-subdocument/list-subdocument.css +4 -0
- package/frontend/src/list-subdocument/list-subdocument.html +3 -3
- package/frontend/src/list-subdocument/list-subdocument.js +8 -1
- package/frontend/src/models/models.js +3 -0
- package/frontend/src/navbar/navbar.html +2 -0
- package/frontend/src/routes.js +5 -0
- package/osogolf.js +20 -0
- package/package.json +3 -2
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Archetype = require('archetype');
|
|
4
|
+
const { Configuration, OpenAIApi } = require('openai');
|
|
5
|
+
|
|
6
|
+
const apiKey = process.env.OPEN_AI_KEY;
|
|
7
|
+
|
|
8
|
+
let openai;
|
|
9
|
+
if (apiKey) {
|
|
10
|
+
const configuration = new Configuration({
|
|
11
|
+
apiKey
|
|
12
|
+
});
|
|
13
|
+
openai = new OpenAIApi(configuration);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const prePrompt = `
|
|
17
|
+
You are a software developer answering user queries using Mongoose.
|
|
18
|
+
Write Node.js code using Mongoose that answers the user's query.
|
|
19
|
+
Do not write any import statements.
|
|
20
|
+
|
|
21
|
+
Input:
|
|
22
|
+
How many users where created yesterday?
|
|
23
|
+
Output:
|
|
24
|
+
const yesterday = new Date();
|
|
25
|
+
yesterday.setHours(0, 0, 0);
|
|
26
|
+
yesterday.setDate(yesterday.getDate() - 1);
|
|
27
|
+
await User.countDocuments({ createdAt: { $gte: yesterday } });
|
|
28
|
+
`.trim();
|
|
29
|
+
|
|
30
|
+
const CreateChartParams = new Archetype({
|
|
31
|
+
description: {
|
|
32
|
+
$type: 'string',
|
|
33
|
+
$required: true
|
|
34
|
+
}
|
|
35
|
+
}).compile('CreateChartParams');
|
|
36
|
+
|
|
37
|
+
module.exports = ({ db }) => async function createChart(params) {
|
|
38
|
+
const { description } = new CreateChartParams(params);
|
|
39
|
+
|
|
40
|
+
const response = await openai.createChatCompletion({
|
|
41
|
+
model: 'gpt-4',
|
|
42
|
+
messages: [
|
|
43
|
+
{
|
|
44
|
+
role: 'system',
|
|
45
|
+
content: prePrompt
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
role: 'user',
|
|
49
|
+
content: description
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
temperature: 0.1
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
console.log('F', response.data.choices[0].message.content);
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
content: response.data.choices[0].message.content
|
|
59
|
+
};
|
|
60
|
+
};
|
|
@@ -36,5 +36,5 @@ module.exports = ({ db }) => async function getDocument(params) {
|
|
|
36
36
|
}
|
|
37
37
|
removeSpecifiedPaths(schemaPaths, '.$*');
|
|
38
38
|
|
|
39
|
-
return { doc: doc.toJSON({ virtuals:
|
|
39
|
+
return { doc: doc.toJSON({ virtuals: true, getters: false, transform: false }), schemaPaths };
|
|
40
40
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const Archetype = require('archetype');
|
|
4
|
+
|
|
5
|
+
const ExecuteParams = new Archetype({
|
|
6
|
+
code: {
|
|
7
|
+
$type: 'string',
|
|
8
|
+
$required: true
|
|
9
|
+
}
|
|
10
|
+
}).compile('ExecuteParams');
|
|
11
|
+
|
|
12
|
+
module.exports = ({ db }) => async function execute(params) {
|
|
13
|
+
const { code } = new ExecuteParams(params);
|
|
14
|
+
|
|
15
|
+
const res = eval(code);
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
res
|
|
19
|
+
};
|
|
20
|
+
};
|
package/backend/actions/index.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
<link rel="stylesheet" href="vanillatoasts/vanillatoasts.css">
|
|
12
12
|
<script src="https://unpkg.com/vue@3.x"></script>
|
|
13
13
|
<script src="https://unpkg.com/vue-router@4.0.10"></script>
|
|
14
|
+
<script src="https://unpkg.com/chart.js@4.2.0/dist/chart.umd.js"></script>
|
|
14
15
|
</head>
|
|
15
16
|
|
|
16
17
|
<body>
|
package/frontend/src/api.js
CHANGED
|
@@ -20,6 +20,9 @@ if (typeof config__setAuthorizationHeaderFrom === 'string' && config__setAuthori
|
|
|
20
20
|
|
|
21
21
|
if (config__isLambda) {
|
|
22
22
|
exports.Model = {
|
|
23
|
+
createChart(params) {
|
|
24
|
+
return client.post('', { action: 'Model.createChart', ...params}).then(res => res.data);
|
|
25
|
+
},
|
|
23
26
|
deleteDocument(params) {
|
|
24
27
|
return client.post('', { action: 'Model.deleteDocument', ...params}).then(res => res.data);
|
|
25
28
|
},
|
|
@@ -41,6 +44,9 @@ if (config__isLambda) {
|
|
|
41
44
|
};
|
|
42
45
|
} else {
|
|
43
46
|
exports.Model = {
|
|
47
|
+
createChart: function (params) {
|
|
48
|
+
return client.post('/Model/createChart', params).then(res => res.data);
|
|
49
|
+
},
|
|
44
50
|
deleteDocument: function (params) {
|
|
45
51
|
return client.post('/Model/deleteDocument', params).then(res => res.data);
|
|
46
52
|
},
|
|
@@ -65,4 +71,7 @@ if (config__isLambda) {
|
|
|
65
71
|
return client.post('/Model/updateDocument', params).then(res => res.data);
|
|
66
72
|
}
|
|
67
73
|
};
|
|
74
|
+
exports.Script = {
|
|
75
|
+
|
|
76
|
+
};
|
|
68
77
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
.charts {
|
|
2
|
+
padding: 10px;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.charts .chart-description textarea {
|
|
6
|
+
width: 100%;
|
|
7
|
+
height: 4em;
|
|
8
|
+
border-radius: 4px;
|
|
9
|
+
border: 1px solid #ddd;
|
|
10
|
+
margin-top: 0.5em;
|
|
11
|
+
padding: 0.5em;
|
|
12
|
+
line-height: 1.5em;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.charts .chart-description button {
|
|
16
|
+
margin-top: 0.5em;
|
|
17
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<div class="charts">
|
|
2
|
+
<h1>Charts</h1>
|
|
3
|
+
<div>
|
|
4
|
+
Describe your chart
|
|
5
|
+
</div>
|
|
6
|
+
<div class="chart-description">
|
|
7
|
+
<textarea
|
|
8
|
+
v-model="description"
|
|
9
|
+
placeholder="Please create a bar chart showing users createdAt per day" />
|
|
10
|
+
<div>
|
|
11
|
+
<async-button @click="createChart">Create Chart</async-button>
|
|
12
|
+
</div>
|
|
13
|
+
</div>
|
|
14
|
+
</div>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const api = require('../api');
|
|
4
|
+
const template = require('./charts.html');
|
|
5
|
+
|
|
6
|
+
const appendCSS = require('../appendCSS');
|
|
7
|
+
|
|
8
|
+
appendCSS(require('./charts.css'));
|
|
9
|
+
|
|
10
|
+
module.exports = app => app.component('charts', {
|
|
11
|
+
template: template,
|
|
12
|
+
data: () => ({ description: '', code: '' }),
|
|
13
|
+
methods: {
|
|
14
|
+
async createChart() {
|
|
15
|
+
const data = await api.Model.createChart({ description: this.description });
|
|
16
|
+
this.code = data.content;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
</component>
|
|
39
39
|
</div>
|
|
40
40
|
<div v-else>
|
|
41
|
-
<component :is="getComponentForPath(path)" :value="
|
|
41
|
+
<component :is="getComponentForPath(path)" :value="getValueForPath(path.path)"></component>
|
|
42
42
|
</div>
|
|
43
43
|
</div>
|
|
44
44
|
</div>
|
|
45
|
-
</div>
|
|
45
|
+
</div>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const api = require('../api');
|
|
4
|
+
const mpath = require('mpath');
|
|
4
5
|
const template = require('./document.html');
|
|
5
6
|
const vanillatoast = require('vanillatoasts');
|
|
6
7
|
|
|
@@ -52,8 +53,11 @@ module.exports = app => app.component('document', {
|
|
|
52
53
|
}
|
|
53
54
|
return 'edit-default';
|
|
54
55
|
},
|
|
56
|
+
getValueForPath(path) {
|
|
57
|
+
return mpath.get(path, this.document);
|
|
58
|
+
},
|
|
55
59
|
getEditValueForPath({ path }) {
|
|
56
|
-
return path in this.changes ? this.changes[path] : this.document
|
|
60
|
+
return path in this.changes ? this.changes[path] : mpath.get(path, this.document);
|
|
57
61
|
},
|
|
58
62
|
cancelEdit() {
|
|
59
63
|
this.changes = {};
|
|
@@ -87,4 +91,4 @@ module.exports = app => app.component('document', {
|
|
|
87
91
|
}
|
|
88
92
|
}
|
|
89
93
|
}
|
|
90
|
-
});
|
|
94
|
+
});
|
package/frontend/src/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const app = Vue.createApp({
|
|
|
5
5
|
});
|
|
6
6
|
|
|
7
7
|
require('./async-button/async-button')(app);
|
|
8
|
+
require('./charts/charts')(app);
|
|
8
9
|
require('./detail-array/detail-array')(app);
|
|
9
10
|
require('./detail-default/detail-default')(app);
|
|
10
11
|
require('./document/document')(app);
|
|
@@ -15,6 +16,7 @@ require('./edit-date/edit-date')(app);
|
|
|
15
16
|
require('./export-query-results/export-query-results')(app);
|
|
16
17
|
require('./list-array/list-array')(app);
|
|
17
18
|
require('./list-default/list-default')(app);
|
|
19
|
+
require('./list-mixed/list-mixed')(app);
|
|
18
20
|
require('./list-string/list-string')(app);
|
|
19
21
|
require('./list-subdocument/list-subdocument')(app);
|
|
20
22
|
require('./modal/modal')(app);
|
|
@@ -9,15 +9,10 @@ module.exports = app => app.component('list-array', {
|
|
|
9
9
|
props: ['value'],
|
|
10
10
|
computed: {
|
|
11
11
|
displayValue() {
|
|
12
|
-
return
|
|
13
|
-
if (typeof value === 'string' && value.length > 30) {
|
|
14
|
-
return value.slice(0, 27) + '...';
|
|
15
|
-
}
|
|
16
|
-
return value;
|
|
17
|
-
}, ' ').trim();
|
|
12
|
+
return this.value;
|
|
18
13
|
}
|
|
19
14
|
},
|
|
20
15
|
mounted() {
|
|
21
16
|
Prism.highlightElement(this.$refs.code);
|
|
22
17
|
}
|
|
23
|
-
});
|
|
18
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
<div ref="itemData" class="tooltip">
|
|
1
|
+
<div class="list-default" ref="itemData" class="tooltip">
|
|
2
2
|
{{displayValue}}
|
|
3
3
|
<div class="tooltiptext" style="display:flex; width: 100%; justify-content: space-around; align-items: center; min-width: 180px;">
|
|
4
4
|
<div class="tooltiptextchild" v-if="allude" @click.stop="goToDoc(value)">View Document</div>
|
|
5
5
|
<div class="tooltiptextchild" @click.stop="copyText(value)">copy 📋</div>
|
|
6
6
|
</div>
|
|
7
|
-
</div>
|
|
7
|
+
</div>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const api = require('../api');
|
|
4
|
+
const template = require('./list-mixed.html');
|
|
5
|
+
|
|
6
|
+
require('../appendCSS')(require('./list-mixed.css'));
|
|
7
|
+
|
|
8
|
+
module.exports = app => app.component('list-mixed', {
|
|
9
|
+
template: template,
|
|
10
|
+
props: ['value'],
|
|
11
|
+
computed: {
|
|
12
|
+
shortenValue() {
|
|
13
|
+
return this.value;
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
mounted: function() {
|
|
17
|
+
Prism.highlightElement(this.$refs.MixedCode);
|
|
18
|
+
}
|
|
19
|
+
});
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
<div>
|
|
2
|
-
<pre><code ref="SubDocCode" class="language-javascript">{{
|
|
3
|
-
</div>
|
|
1
|
+
<div class="list-subdocument">
|
|
2
|
+
<pre><code ref="SubDocCode" class="language-javascript">{{shortenValue}}</code></pre>
|
|
3
|
+
</div>
|
|
@@ -3,10 +3,17 @@
|
|
|
3
3
|
const api = require('../api');
|
|
4
4
|
const template = require('./list-subdocument.html');
|
|
5
5
|
|
|
6
|
+
require('../appendCSS')(require('./list-subdocument.css'));
|
|
7
|
+
|
|
6
8
|
module.exports = app => app.component('list-subdocument', {
|
|
7
9
|
template: template,
|
|
8
10
|
props: ['value'],
|
|
11
|
+
computed: {
|
|
12
|
+
shortenValue() {
|
|
13
|
+
return this.value;
|
|
14
|
+
}
|
|
15
|
+
},
|
|
9
16
|
mounted: function() {
|
|
10
17
|
Prism.highlightElement(this.$refs.SubDocCode);
|
|
11
18
|
}
|
|
12
|
-
});
|
|
19
|
+
});
|
|
@@ -154,6 +154,9 @@ module.exports = app => app.component('models', {
|
|
|
154
154
|
if (schemaPath.instance == 'Embedded') {
|
|
155
155
|
return 'list-subdocument';
|
|
156
156
|
}
|
|
157
|
+
if (schemaPath.instance == 'Mixed') {
|
|
158
|
+
return 'list-mixed';
|
|
159
|
+
}
|
|
157
160
|
return 'list-default';
|
|
158
161
|
},
|
|
159
162
|
getReferenceModel(schemaPath) {
|
package/frontend/src/routes.js
CHANGED
package/osogolf.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const db = require('../../voltmobile/core-api/backend/db');
|
|
4
|
+
const express = require('express');
|
|
5
|
+
const studio = require('./express');
|
|
6
|
+
|
|
7
|
+
run().catch(err => {
|
|
8
|
+
console.error(err);
|
|
9
|
+
process.exit(-1);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
async function run() {
|
|
13
|
+
const app = express();
|
|
14
|
+
const conn = await db();
|
|
15
|
+
|
|
16
|
+
app.use('/studio', studio('/studio/api', conn));
|
|
17
|
+
|
|
18
|
+
await app.listen(3002);
|
|
19
|
+
console.log('Listening on port 3002');
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mongoosejs/studio",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"archetype": "0.13.0",
|
|
6
6
|
"csv-stringify": "6.3.0",
|
|
7
7
|
"ejson": "^2.2.3",
|
|
8
8
|
"extrovert": "0.0.20",
|
|
9
|
+
"openai": "3.2.1",
|
|
9
10
|
"vanillatoasts": "^1.6.0"
|
|
10
11
|
},
|
|
11
12
|
"peerDependencies": {
|
|
12
13
|
"express": "4.x",
|
|
13
|
-
"mongoose": "7.x"
|
|
14
|
+
"mongoose": "7.x || 8.0.0-rc0 || 8.x"
|
|
14
15
|
},
|
|
15
16
|
"devDependencies": {
|
|
16
17
|
"axios": "1.2.2",
|