quar 1.2.6 → 1.2.7
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/index.js +1 -1
- package/package.json +3 -3
- package/public/scripts/main.js +2 -2
- package/server.js +22 -22
- package/utils/loadModels.js +3 -3
- package/views/base.zare +1 -1
- package/views/components/insertTab.zare +2 -2
- package/views/components/popup.zare +2 -2
- package/views/pages/index.zare +2 -2
package/index.js
CHANGED
|
@@ -51,7 +51,7 @@ try {
|
|
|
51
51
|
(async () => {
|
|
52
52
|
|
|
53
53
|
await mongoose.connect(`${args.uri || "mongodb://localhost:27017/"}${args.db}`)
|
|
54
|
-
console.log(
|
|
54
|
+
console.log(chalk.blue.bold('[INFO]'), chalk.gray("Quar: Database connection established"))
|
|
55
55
|
|
|
56
56
|
app.listen(app.get('port'), () => {
|
|
57
57
|
const url = `http://127.0.0.1:${app.get('port')}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quar",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.7",
|
|
4
4
|
"description": "This will load all Mongoose models from the folder and start a local web UI to Create, view, update, and delete documents.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"minimist": "^1.2.8",
|
|
20
20
|
"mongoose": "^8.14.1",
|
|
21
21
|
"open": "^10.1.2",
|
|
22
|
-
"zare": "
|
|
22
|
+
"zare": "2.6.0"
|
|
23
23
|
},
|
|
24
24
|
"repository": {
|
|
25
25
|
"type": "git",
|
|
@@ -29,4 +29,4 @@
|
|
|
29
29
|
"url": "https://github.com/IsmailBinMujeeb/quar-studio/issues"
|
|
30
30
|
},
|
|
31
31
|
"homepage": "https://github.com/IsmailBinMujeeb/quar-studio#readme"
|
|
32
|
-
}
|
|
32
|
+
}
|
package/public/scripts/main.js
CHANGED
|
@@ -35,7 +35,7 @@ async function activateTab(modelName) {
|
|
|
35
35
|
|
|
36
36
|
content.dataset.modelName = modelName;
|
|
37
37
|
document.getElementById("page-value").innerText = 1;
|
|
38
|
-
document.querySelectorAll(".operations .btn")?.forEach(
|
|
38
|
+
document.querySelectorAll(".operations .btn")?.forEach(btn => btn.disabled = false)
|
|
39
39
|
document.querySelector(".operations select").disabled = false;
|
|
40
40
|
|
|
41
41
|
const insertTab = document.querySelector('.insert-tab');
|
|
@@ -71,7 +71,7 @@ function closeTab(event, modelName) {
|
|
|
71
71
|
function disableAllOptions() {
|
|
72
72
|
content.dataset.modelName = '';
|
|
73
73
|
|
|
74
|
-
document.querySelectorAll(".operations .btn")?.forEach(
|
|
74
|
+
document.querySelectorAll(".operations .btn")?.forEach(btn => btn.disabled = true);
|
|
75
75
|
document.getElementById("document-count").innerText = 0;
|
|
76
76
|
document.querySelector(".operations select").disabled = true;
|
|
77
77
|
}
|
package/server.js
CHANGED
|
@@ -42,7 +42,7 @@ app.get("/models", async (_, res) => {
|
|
|
42
42
|
loadModels(app.locals.modelPath)
|
|
43
43
|
const modelNames = mongoose.modelNames();
|
|
44
44
|
modelNames.sort((a, b) => a.localeCompare(b));
|
|
45
|
-
|
|
45
|
+
|
|
46
46
|
const result = await Promise.all(
|
|
47
47
|
modelNames.map(async name => {
|
|
48
48
|
const model = mongoose.model(name);
|
|
@@ -50,7 +50,7 @@ app.get("/models", async (_, res) => {
|
|
|
50
50
|
return { name, count };
|
|
51
51
|
})
|
|
52
52
|
);
|
|
53
|
-
|
|
53
|
+
|
|
54
54
|
res.status(200).json({ models: result });
|
|
55
55
|
} catch (error) {
|
|
56
56
|
res.status(500).json({ error: error.message || "Internal server error" });
|
|
@@ -138,56 +138,56 @@ app.post("/insert/:modelName", async (req, res) => {
|
|
|
138
138
|
try {
|
|
139
139
|
const { modelName } = req.params;
|
|
140
140
|
const body = req.body;
|
|
141
|
-
|
|
141
|
+
|
|
142
142
|
const Model = mongoose.model(modelName);
|
|
143
|
-
|
|
143
|
+
|
|
144
144
|
if (!Model) return res.status(404).json({ error: "model not found" });
|
|
145
|
-
|
|
145
|
+
|
|
146
146
|
const paths = Model.schema.paths;
|
|
147
|
-
|
|
147
|
+
|
|
148
148
|
function getSchema(paths) {
|
|
149
|
-
|
|
149
|
+
|
|
150
150
|
let schema = {};
|
|
151
151
|
for (const path in paths) {
|
|
152
|
-
|
|
152
|
+
|
|
153
153
|
if (path === '_id' || path === '__v') continue;
|
|
154
|
-
|
|
154
|
+
|
|
155
155
|
if (paths[path].instance === 'Embedded') {
|
|
156
156
|
schema[path] = getSchema(paths[path].schema.paths);
|
|
157
157
|
continue;
|
|
158
158
|
};
|
|
159
|
-
|
|
159
|
+
|
|
160
160
|
schema[path] = paths[path].instance;
|
|
161
161
|
}
|
|
162
|
-
|
|
162
|
+
|
|
163
163
|
return schema;
|
|
164
164
|
}
|
|
165
|
-
|
|
165
|
+
|
|
166
166
|
const schema = getSchema(paths)
|
|
167
|
-
|
|
167
|
+
|
|
168
168
|
function getData(body, schema) {
|
|
169
|
-
|
|
169
|
+
|
|
170
170
|
let data = {};
|
|
171
|
-
|
|
171
|
+
|
|
172
172
|
for (const key in schema) {
|
|
173
173
|
if (typeof schema[key] === 'object' && schema[key] !== null) {
|
|
174
|
-
|
|
174
|
+
|
|
175
175
|
data[key] = getData(body, schema[key]);
|
|
176
176
|
continue;
|
|
177
177
|
}
|
|
178
|
-
|
|
178
|
+
|
|
179
179
|
if (Object.keys(body).includes(key)) {
|
|
180
180
|
data[key] = body[key];
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
|
-
|
|
183
|
+
|
|
184
184
|
return data;
|
|
185
185
|
}
|
|
186
|
-
|
|
186
|
+
|
|
187
187
|
const data = getData(body, schema)
|
|
188
|
-
|
|
188
|
+
|
|
189
189
|
const result = await Model.create(data)
|
|
190
|
-
|
|
190
|
+
|
|
191
191
|
res.status(200).json(result)
|
|
192
192
|
} catch (error) {
|
|
193
193
|
res.status(500).json({ error: error.message || "Internal server error" })
|
|
@@ -199,7 +199,7 @@ app.put("/update/:modelName/:id", async (req, res) => {
|
|
|
199
199
|
const { modelName, id } = req.params;
|
|
200
200
|
const model = mongoose.model(modelName);
|
|
201
201
|
const updatedDoc = req.body;
|
|
202
|
-
|
|
202
|
+
|
|
203
203
|
delete updatedDoc._id;
|
|
204
204
|
const result = await model.findByIdAndUpdate(id, updatedDoc, { new: true });
|
|
205
205
|
|
package/utils/loadModels.js
CHANGED
|
@@ -8,13 +8,13 @@ export default (modelPath) => {
|
|
|
8
8
|
if (!fs.existsSync(modelPath)) {
|
|
9
9
|
console.log(
|
|
10
10
|
chalk.red.bold('[ERROR]') +
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
' The specified model path does not exist:\n ' +
|
|
12
|
+
chalk.gray(modelPath)
|
|
13
13
|
);
|
|
14
14
|
console.log('Tip: Check the path or create the folder first.');
|
|
15
15
|
process.exit(1);
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
fs.readdirSync(modelPath).forEach(async (file) => {
|
|
19
19
|
if (file.endsWith('.js')) {
|
|
20
20
|
const filePath = path.join(modelPath, file);
|
package/views/base.zare
CHANGED
package/views/pages/index.zare
CHANGED
|
@@ -3,8 +3,8 @@ as Base import "../base.zare"
|
|
|
3
3
|
as Popup import "../components/popup.zare"
|
|
4
4
|
as InsertTab import "../components/insertTab.zare"\
|
|
5
5
|
|
|
6
|
-
link
|
|
7
|
-
import
|
|
6
|
+
link "/styles/style"
|
|
7
|
+
import "/scripts/main"
|
|
8
8
|
|
|
9
9
|
serve (
|
|
10
10
|
<Base>
|