@nuxt-atelier/devtools 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +6 -2
- package/dist/module.d.mts +6 -0
- package/dist/module.json +12 -0
- package/dist/module.mjs +109 -0
- package/dist/types.d.mts +7 -0
- package/package.json +46 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ano Rebel
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @nuxt-atelier/devtools
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Nuxt DevTools panels for Nuxt Atelier: schema, migrations, jobs and the admin
|
|
4
|
+
|
|
5
|
+
Part of [Nuxt Atelier](https://nuxt-atelier.anorebel.net), a visual CMS for Nuxt. See the [documentation](https://nuxt-atelier.anorebel.net) to get started, or try the [live demo](https://nuxt-atelier-demo.anorebel.net).
|
|
6
|
+
|
|
7
|
+
MIT License
|
package/dist/module.json
ADDED
package/dist/module.mjs
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { defineNuxtModule, addDevServerHandler } from '@nuxt/kit';
|
|
2
|
+
import { defineEventHandler, getRouterParam, setResponseHeader } from 'h3';
|
|
3
|
+
import { buildTables, projectMigrationStatus, blockedSchemaChanges, listJobs, projectFromNuxt, withMigrationLock, applyProjectMigrations, retryJob } from 'nuxt-atelier/project';
|
|
4
|
+
|
|
5
|
+
const escape = (value) => String(value).replace(/[&<>"']/g, (c) => `&#${c.charCodeAt(0)};`);
|
|
6
|
+
const list = (items, empty) => items.length ? `<ul>${items.map((i) => `<li>${i}</li>`).join("")}</ul>` : `<p class="muted">${empty}</p>`;
|
|
7
|
+
function typeRows(kind, types, tables) {
|
|
8
|
+
return Object.entries(types).map(([name, definition]) => {
|
|
9
|
+
const table = tables.find((t) => t === `atelier_c_${name.replaceAll("-", "_")}`);
|
|
10
|
+
const fields = Object.entries(definition.fields).map(([key, field]) => `<code>${escape(key)}</code> ${escape(field.type)}${field.required ? ' <span class="muted">required</span>' : ""}`).join(", ");
|
|
11
|
+
return `<tr><td><strong>${escape(name)}</strong><br><span class="muted">${kind}${definition.versioned ? ", versioned" : ""}${definition.route ? ", routable" : ""}</span></td><td>${fields || '<span class="muted">none</span>'}</td><td>${table ? `<code>${escape(table)}</code>` : '<span class="muted">shared tables</span>'}</td></tr>`;
|
|
12
|
+
}).join("");
|
|
13
|
+
}
|
|
14
|
+
async function renderPanel(project, section) {
|
|
15
|
+
let body;
|
|
16
|
+
if (section === "schema") {
|
|
17
|
+
const tables = Object.keys(buildTables(project.databaseUrl.startsWith("postgres") ? "postgres" : project.databaseUrl.startsWith("mysql") || project.databaseUrl.startsWith("mariadb") ? "mysql" : "sqlite", project.schema));
|
|
18
|
+
body = `<h1>Schema</h1>
|
|
19
|
+
<table><thead><tr><th>Type</th><th>Fields</th><th>Table</th></tr></thead><tbody>
|
|
20
|
+
${typeRows("collection", project.schema.collections, tables)}${typeRows("singleton", project.schema.singletons, tables)}
|
|
21
|
+
</tbody></table>
|
|
22
|
+
<h2>Tables</h2>${list(tables.map((t) => `<code>${escape(t)}</code>`), "None.")}`;
|
|
23
|
+
} else if (section === "migrations") {
|
|
24
|
+
const status = await projectMigrationStatus(project).catch((error) => error);
|
|
25
|
+
const blocked = blockedSchemaChanges();
|
|
26
|
+
body = `<h1>Migrations</h1>
|
|
27
|
+
<p class="muted">Database: <code>${escape(project.databaseUrl.replace(/\/\/[^@/]*@/, "//\u2026@"))}</code></p>
|
|
28
|
+
${status instanceof Error ? `<p class="error">${escape(status.message)}</p>` : `<h2>Pending</h2>${list(status.pending.map((n) => `<code>${escape(n)}</code>`), "None: the database is up to date.")}
|
|
29
|
+
<h2>Applied</h2>${list(status.applied.toReversed().map((n) => `<code>${escape(n)}</code>`), "None yet.")}`}
|
|
30
|
+
<h2>Waiting for you</h2>${blocked.length ? `<p>A schema change would delete data, so <code>nuxt dev</code> didn't apply it. Confirm it with <code>npx atelier migrate generate</code> and the flag it needs:</p>${list(blocked.map(escape), "")}` : '<p class="muted">Nothing: every schema change is applied.</p>'}
|
|
31
|
+
<p class="muted">Apply pending migrations from the <strong>Atelier: actions</strong> tab.</p>`;
|
|
32
|
+
} else {
|
|
33
|
+
const jobs = await listJobs(project).catch((error) => error);
|
|
34
|
+
body = `<h1>Jobs</h1>${jobs instanceof Error ? `<p class="error">${escape(jobs.message)}</p>` : jobs.length ? `<table><thead><tr><th>Job</th><th>Status</th><th>Due</th><th>Attempts</th></tr></thead><tbody>${jobs.map((j) => `<tr><td><code>${escape(j.name)}</code><br><span class="muted">${escape(j.id)}</span>${j.lastError ? `<br><span class="error">${escape(j.lastError)}</span>` : ""}</td><td>${escape(j.status)}</td><td>${escape(j.runAt)}</td><td>${j.attempts}/${j.maxAttempts}</td></tr>`).join("")}</tbody></table>` : '<p class="muted">No jobs.</p>'}
|
|
35
|
+
<p class="muted">Retry a failed one from the <strong>Atelier: actions</strong> tab.</p>`;
|
|
36
|
+
}
|
|
37
|
+
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><title>Nuxt Atelier: ${section}</title><style>
|
|
38
|
+
:root{color-scheme:light dark;font:14px/1.5 system-ui,sans-serif}body{margin:1.5rem}h1{font-size:1.25rem}h2{font-size:1rem;margin-top:1.5rem}
|
|
39
|
+
table{border-collapse:collapse;width:100%}th,td{text-align:left;vertical-align:top;padding:.4rem .6rem;border-bottom:1px solid #8884}
|
|
40
|
+
code{font-size:.9em}.muted{opacity:.65}.error{color:#d33}ul{padding-left:1.2rem}
|
|
41
|
+
</style></head><body>${body}</body></html>`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const PANEL = "/__atelier_devtools";
|
|
45
|
+
const SECTIONS = ["schema", "migrations", "jobs"];
|
|
46
|
+
const module$1 = defineNuxtModule({
|
|
47
|
+
meta: { name: "@nuxt-atelier/devtools", configKey: "atelierDevtools", compatibility: { nuxt: ">=4.6.0" } },
|
|
48
|
+
setup(_, nuxt) {
|
|
49
|
+
const devtools = nuxt.options.devtools;
|
|
50
|
+
if (!nuxt.options.dev || devtools === false || typeof devtools === "object" && devtools.enabled === false)
|
|
51
|
+
return;
|
|
52
|
+
const authorized = !(typeof devtools === "object" && devtools.disableAuthorization);
|
|
53
|
+
const project = () => projectFromNuxt(nuxt);
|
|
54
|
+
const adminBase = () => nuxt.options.runtimeConfig.public.atelier?.admin?.base ?? "/admin";
|
|
55
|
+
addDevServerHandler({
|
|
56
|
+
route: `${PANEL}/:section`,
|
|
57
|
+
handler: defineEventHandler(async (event) => {
|
|
58
|
+
const section = getRouterParam(event, "section");
|
|
59
|
+
if (!SECTIONS.includes(section))
|
|
60
|
+
return new Response("Not found", { status: 404 });
|
|
61
|
+
setResponseHeader(event, "content-type", "text/html; charset=utf-8");
|
|
62
|
+
return renderPanel(await project(), section);
|
|
63
|
+
})
|
|
64
|
+
});
|
|
65
|
+
const guarded = (action) => async () => {
|
|
66
|
+
if (!authorized)
|
|
67
|
+
throw new Error("[nuxt-atelier] Actions are off while devtools.disableAuthorization is set: any browser reaching the dev server could run them");
|
|
68
|
+
return action();
|
|
69
|
+
};
|
|
70
|
+
const applyMigrations = guarded(async () => {
|
|
71
|
+
const p = await project();
|
|
72
|
+
return withMigrationLock(p.databaseUrl, () => applyProjectMigrations(p));
|
|
73
|
+
});
|
|
74
|
+
const docks = [
|
|
75
|
+
...SECTIONS.map((section) => ({ id: `atelier:${section}`, title: `Atelier: ${section}`, icon: section === "schema" ? "i-lucide-database" : section === "migrations" ? "i-lucide-git-merge" : "i-lucide-list-checks", url: `${PANEL}/${section}` })),
|
|
76
|
+
{ id: "atelier:admin", title: "Atelier: admin", icon: "i-lucide-layout-dashboard", url: adminBase() }
|
|
77
|
+
];
|
|
78
|
+
let ready = false;
|
|
79
|
+
nuxt.hook("devtools:ready", (ctx) => {
|
|
80
|
+
ready = true;
|
|
81
|
+
for (const dock of docks)
|
|
82
|
+
ctx.docks.register({ ...dock, type: "iframe", url: dock.id === "atelier:admin" ? adminBase() : dock.url, groupId: "nuxt" });
|
|
83
|
+
ctx.commands?.register({ id: "atelier:apply-migrations", title: "Atelier: apply pending migrations", handler: applyMigrations });
|
|
84
|
+
});
|
|
85
|
+
nuxt.hook("devtools:customTabs", async (tabs) => {
|
|
86
|
+
if (ready)
|
|
87
|
+
return;
|
|
88
|
+
for (const dock of docks)
|
|
89
|
+
tabs.push({ name: dock.id.replace(":", "-"), title: dock.title, icon: dock.icon.replace("i-lucide-", "lucide:"), category: "modules", view: { type: "iframe", src: dock.id === "atelier:admin" ? adminBase() : dock.url } });
|
|
90
|
+
const failed = await listJobs(await project(), "failed").catch(() => []);
|
|
91
|
+
tabs.push({
|
|
92
|
+
name: "atelier-actions",
|
|
93
|
+
title: "Atelier: actions",
|
|
94
|
+
icon: "lucide:play",
|
|
95
|
+
category: "modules",
|
|
96
|
+
view: {
|
|
97
|
+
type: "launch",
|
|
98
|
+
description: authorized ? "Apply the pending migrations to the dev database, or queue a failed background job again." : "Actions are off while devtools.disableAuthorization is set.",
|
|
99
|
+
actions: authorized ? [
|
|
100
|
+
{ label: "Apply pending migrations", handle: async () => void await applyMigrations() },
|
|
101
|
+
...failed.slice(0, 10).map((job) => ({ label: `Retry ${job.name} (${job.id.slice(0, 8)})`, handle: guarded(async () => retryJob(await project(), job.id)) }))
|
|
102
|
+
] : []
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
export { PANEL, module$1 as default };
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { NuxtModule } from '@nuxt/schema'
|
|
2
|
+
|
|
3
|
+
import type { default as Module } from './module.mjs'
|
|
4
|
+
|
|
5
|
+
export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
|
|
6
|
+
|
|
7
|
+
export { type PANEL, default } from './module.mjs'
|
package/package.json
CHANGED
|
@@ -1,6 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt-atelier/devtools",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/AnoRebel/nuxt-atelier.git",
|
|
9
|
+
"directory": "packages/devtools"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://nuxt-atelier.anorebel.net",
|
|
12
|
+
"description": "Nuxt DevTools panels for Nuxt Atelier: schema, migrations, jobs and the admin",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/types.d.mts",
|
|
16
|
+
"import": "./dist/module.mjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"main": "./dist/module.mjs",
|
|
20
|
+
"typesVersions": {
|
|
21
|
+
"*": {
|
|
22
|
+
".": [
|
|
23
|
+
"./dist/types.d.mts"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "nuxt-module-build build",
|
|
32
|
+
"prepack": "nuxt-module-build build",
|
|
33
|
+
"check:pkg": "publint --pack bun && attw --pack . --profile esm-only"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"nuxt": ">=4.6.0",
|
|
37
|
+
"nuxt-atelier": "^0.2.0"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@nuxt/kit": "^4.6.3",
|
|
41
|
+
"h3": "^1.15.11"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@nuxt/devtools-kit": "4.1.0",
|
|
45
|
+
"@nuxt/schema": "4.7.0",
|
|
46
|
+
"nuxt-atelier": "0.2.0"
|
|
47
|
+
}
|
|
48
|
+
}
|