dbtour-addon-explorer 0.0.0-stage → 0.2.0

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/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "dbtour-addon-explorer",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "The dbtour page: search, table view and neighbourhood diagrams in one HTML file that opens without a server.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "Victor Saly",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/victorsaly/dbtour.git",
11
+ "directory": "packages/addon-explorer"
12
+ },
13
+ "engines": {
14
+ "node": ">=22.18"
15
+ },
16
+ "exports": {
17
+ ".": "./src/index.ts"
18
+ },
19
+ "files": [
20
+ "src/index.ts",
21
+ "dist"
22
+ ],
23
+ "scripts": {
24
+ "build": "node build.mjs",
25
+ "prepack": "node build.mjs"
26
+ },
27
+ "keywords": [
28
+ "dbtour",
29
+ "database",
30
+ "documentation",
31
+ "erd",
32
+ "schema",
33
+ "explorer"
34
+ ],
35
+ "devDependencies": {
36
+ "@types/react": "^19.3.0",
37
+ "@types/react-dom": "^19.3.0",
38
+ "@xyflow/react": "^12.12.0",
39
+ "dbtour": "0.2.0",
40
+ "elkjs": "^0.12.1",
41
+ "esbuild": "^0.28.2",
42
+ "react": "^19.3.1",
43
+ "react-dom": "^19.3.1"
44
+ }
45
+ }
package/src/index.ts ADDED
@@ -0,0 +1,47 @@
1
+ // The explorer add-on: render(model) returns index.html with the page and the model inlined, so the file
2
+ // opens from disk with no server and no network. The page itself is built from src/page into dist/.
3
+ import { readFileSync } from 'node:fs';
4
+ import type { Model } from 'dbtour/model';
5
+ import { markDataUri } from './mark.ts';
6
+
7
+ export function render(model: Model): Record<string, string> {
8
+ return { 'index.html': pageHtml(model, builtFile('page.js'), builtFile('page.css')) };
9
+ }
10
+
11
+ function builtFile(name: string): string {
12
+ try {
13
+ return readFileSync(new URL(`../dist/${name}`, import.meta.url), 'utf8');
14
+ } catch (error) {
15
+ throw new Error(`dbtour-addon-explorer has no dist/${name}: in the dbtour repository run npm run build, otherwise reinstall the package`, { cause: error });
16
+ }
17
+ }
18
+
19
+ /** The HTML around the bundle and the model. Pure, so it is tested without the build. */
20
+ export function pageHtml(model: Model, js: string, css: string): string {
21
+ const title = `${model.databases.map((d) => d.name).join(', ') || 'dbtour'} · dbtour`;
22
+ // Inside a JSON string "<" is "<", so no "</script" or "<!--" can end the element early. The bundle
23
+ // gets the same treatment where "</script" could appear inside one of its strings or patterns.
24
+ const json = JSON.stringify(model).replace(/</g, '\\u003c');
25
+ const script = js.replace(/<\/(script)/gi, '<\\/$1');
26
+ return `<!doctype html>
27
+ <html lang="en">
28
+ <head>
29
+ <meta charset="utf-8">
30
+ <meta name="viewport" content="width=device-width, initial-scale=1">
31
+ <meta name="color-scheme" content="light dark">
32
+ <title>${escapeHtml(title)}</title>
33
+ <link rel="icon" href="${markDataUri()}">
34
+ <style>${css}</style>
35
+ </head>
36
+ <body>
37
+ <div id="app"></div>
38
+ <script id="dbtour-model" type="application/json">${json}</script>
39
+ <script>${script}</script>
40
+ </body>
41
+ </html>
42
+ `;
43
+ }
44
+
45
+ function escapeHtml(text: string): string {
46
+ return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
47
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.