@mongoosejs/studio 0.0.77 → 0.0.79

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/README.md CHANGED
@@ -1,2 +1,86 @@
1
- # admin
2
- WIP Mongoose admin panel
1
+ # Mongoose Studio
2
+
3
+ A sleek, powerful MongoDB UI with built-in dashboarding and auth, seamlessly integrated with your Express, Vercel, or Netlify app.
4
+
5
+ ![NPM Version](https://img.shields.io/npm/v/@mongoosejs/studio)
6
+
7
+ ## Getting Started
8
+
9
+ Mongoose Studio is meant to run as a [sidecar](https://learn.microsoft.com/en-us/azure/architecture/patterns/sidecar) to your Node.js application, using the same Mongoose connection config.
10
+ If your app runs on `acme.app`, Studio will be on `acme.app/studio` or whichever path you prefer.
11
+ For local dev, if your app runs on `localhost:3000`, Studio will be on `localhost:3000/studio`.
12
+
13
+ By default, Mongoose Studio does **not** provide any authentication or authorization.
14
+ You can use Mongoose Studio for free for local development, but we recommend [Mongoose Studio Pro](https://studio.mongoosejs.io/#pricing) for when you want to go into production.
15
+
16
+ First, `npm install @mongoosejs/studio`.
17
+
18
+ ### Express
19
+
20
+ Mongoose Studio can be mounted as Express middleware as follows.
21
+
22
+ ```javascript
23
+ const mongoose = require('mongoose');
24
+ const studio = require('@mongoosejs/studio/express');
25
+
26
+ // Mount Mongoose Studio on '/studio'
27
+ // If your models are registered on a different connection, pass in the connection instead of `mongoose`
28
+ app.use('/studio', await studio('/studio/api', mongoose));
29
+ ````
30
+
31
+ If you have a Mongoose Studio Pro API key, you can set it as follows:
32
+
33
+ ```javascript
34
+ const opts = process.env.MONGOOSE_STUDIO_API_KEY ? { apiKey: process.env.MONGOOSE_STUDIO_API_KEY } : {};
35
+
36
+ // Mount Mongoose Studio on '/studio'
37
+ app.use('/studio', await studio('/studio/api', mongoose, opts));
38
+ ```
39
+
40
+ ### Netlify
41
+
42
+ [Here is a full example of how to add Mongoose Studio to a Netlify repo](https://github.com/mongoosejs/studio.mongoosejs.io/commit/8b02ea367c8a1b7b4bcab290708f57d58f08210b).
43
+
44
+ 1) Copy the Mongoose Studio frontend into `public/studio` automatically in `npm run build`.
45
+
46
+ ```javascript
47
+ const { execSync } = require('child_process');
48
+
49
+ // Sign up for Mongoose Studio Pro to get an API key, or omit `apiKey` for local dev.
50
+ const opts = {
51
+ apiKey: process.env.MONGOOSE_STUDIO_API_KEY
52
+ };
53
+ console.log('Creating Mongoose studio', opts);
54
+ require('@mongoosejs/studio/frontend')(`/.netlify/functions/studio`, true, opts).then(() => {
55
+ execSync(`
56
+ mkdir -p ./public/imdb
57
+ cp -r ./node_modules/@mongoosejs/studio/frontend/public/* ./public/imdb/
58
+ `);
59
+ });
60
+ ```
61
+
62
+ 2) Create a `/studio` Netlify function in `netlify/functions/studio.js`, or wherever your Netlify functions directory is. The function path should match the `/.netlify/functions/studio` parameter in the build script above.
63
+
64
+ ```javascript
65
+ const mongoose = require('mongoose');
66
+
67
+ const handler = require('@mongoosejs/studio/backend/netlify')({
68
+ apiKey: process.env.MONGOOSE_STUDIO_API_KEY
69
+ }).handler;
70
+
71
+ let conn = null;
72
+
73
+ module.exports = {
74
+ handler: async function studioHandler(params) {
75
+ if (conn == null) {
76
+ conn = await mongoose.connect(process.env.MONGODB_CONNECTION_STRING, { serverSelectionTimeoutMS: 3000 });
77
+ }
78
+
79
+ return handler.apply(null, arguments);
80
+ }
81
+ };
82
+ ```
83
+
84
+ 3) Redeploy and you're live!
85
+
86
+ Try [our IMDB demo](https://studio.mongoosejs.io/imdb/#/) for an example of Mongoose Studio running on Netlify, or check out the [studio.mongoosejs.io GitHub repo](https://github.com/mongoosejs/studio.mongoosejs.io) for the full source code.
@@ -27,7 +27,7 @@ module.exports = ({ db }) => async function executeScript(params) {
27
27
 
28
28
  // Create a sandbox with the db object
29
29
  const logs = [];
30
- const sandbox = { db, console: {} };
30
+ const sandbox = { db, console: {}, ObjectId: mongoose.Types.ObjectId };
31
31
 
32
32
  // Capture console logs
33
33
  sandbox.console.log = function() {
@@ -27,6 +27,8 @@ Keep scripts concise. Avoid unnecessary comments, error handling, and temporary
27
27
 
28
28
  Do not write any imports or require() statements, that will cause the script to break.
29
29
 
30
+ If the user approves the script, the script will run in the Node.js server and then send the response via JSON to the client. Be aware that the result of the query will be serialized to JSON before being displayed to the user.
31
+
30
32
  Assume the user has pre-defined schemas and models. Do not define any new schemas or models for the user.
31
33
 
32
34
  Use async/await where possible. Assume top-level await is allowed.
@@ -37,7 +39,7 @@ Format output as Markdown, including code fences for any scripts the user reques
37
39
 
38
40
  Add a brief text description of what the script does.
39
41
 
40
- If the user's query is best answered with a chart, return a Chart.js 4 configuration as \`return { $chart: chartJSConfig };\`. Disable ChartJS animation by default unless user asks for it.
42
+ If the user's query is best answered with a chart, return a Chart.js 4 configuration as \`return { $chart: chartJSConfig };\`. Disable ChartJS animation by default unless user asks for it. Set responsive: true, maintainAspectRatio: false options unless the user explicitly asks.
41
43
 
42
44
  Example output:
43
45
 
@@ -3767,7 +3767,7 @@ module.exports = "<div>\n <div class=\"mb-2\">\n <textarea class=\"border bo
3767
3767
  /***/ ((module) => {
3768
3768
 
3769
3769
  "use strict";
3770
- module.exports = "<div class=\"py-2\">\n <div v-if=\"header\" class=\"border-b border-gray-100 px-2 pb-2 text-xl font-bold\">\n {{header}}\n </div>\n <div class=\"text-xl py-2\">\n <canvas ref=\"chart\"></canvas>\n </div>\n</div>";
3770
+ module.exports = "<div class=\"py-2 h-full\">\n <div v-if=\"header\" class=\"border-b border-gray-100 px-2 pb-2 text-xl font-bold\">\n {{header}}\n </div>\n <div class=\"text-xl py-2 h-full\">\n <canvas ref=\"chart\"></canvas>\n </div>\n</div>\n";
3771
3771
 
3772
3772
  /***/ }),
3773
3773
 
@@ -1,8 +1,8 @@
1
- <div class="py-2">
1
+ <div class="py-2 h-full">
2
2
  <div v-if="header" class="border-b border-gray-100 px-2 pb-2 text-xl font-bold">
3
3
  {{header}}
4
4
  </div>
5
- <div class="text-xl py-2">
5
+ <div class="text-xl py-2 h-full">
6
6
  <canvas ref="chart"></canvas>
7
7
  </div>
8
- </div>
8
+ </div>
package/package.json CHANGED
@@ -1,6 +1,12 @@
1
1
  {
2
2
  "name": "@mongoosejs/studio",
3
- "version": "0.0.77",
3
+ "version": "0.0.79",
4
+ "description": "A sleek, powerful MongoDB UI with built-in dashboarding and auth, seamlessly integrated with your Express, Vercel, or Netlify app.",
5
+ "homepage": "https://studio.mongoosejs.io/",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/mongoosejs/studio"
9
+ },
4
10
  "dependencies": {
5
11
  "archetype": "0.13.1",
6
12
  "csv-stringify": "6.3.0",