flobase-editor 0.0.0-stage → 0.1.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.
@@ -0,0 +1,18 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" fill="none">
2
+ <!-- Minimalist Flobase Geometric Stack & Stylized F -->
3
+ <!-- Top Stack / Database Layer -->
4
+ <rect x="10" y="10" width="44" height="10" rx="4" fill="#b8f34a"/>
5
+
6
+ <!-- Middle Arm & Database Layer -->
7
+ <rect x="10" y="26" width="32" height="9" rx="3.5" fill="#b8f34a"/>
8
+
9
+ <!-- Vertical Pillar forming the F spine -->
10
+ <rect x="10" y="10" width="10" height="44" rx="4" fill="#b8f34a"/>
11
+
12
+ <!-- Bottom Foundation / Base Layer -->
13
+ <rect x="10" y="45" width="22" height="9" rx="3.5" fill="#8fca32"/>
14
+
15
+ <!-- High-tech circuit / relational anchor dot -->
16
+ <circle cx="48" cy="49" r="4.5" fill="#b8f34a"/>
17
+ <path d="M32 49.5H43.5" stroke="#b8f34a" stroke-width="2.5" stroke-linecap="round"/>
18
+ </svg>
@@ -0,0 +1,18 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" fill="none">
2
+ <!-- Minimalist Flobase Geometric Stack & Stylized F -->
3
+ <!-- Top Stack / Database Layer -->
4
+ <rect x="10" y="10" width="44" height="10" rx="4" fill="#b8f34a"/>
5
+
6
+ <!-- Middle Arm & Database Layer -->
7
+ <rect x="10" y="26" width="32" height="9" rx="3.5" fill="#b8f34a"/>
8
+
9
+ <!-- Vertical Pillar forming the F spine -->
10
+ <rect x="10" y="10" width="10" height="44" rx="4" fill="#b8f34a"/>
11
+
12
+ <!-- Bottom Foundation / Base Layer -->
13
+ <rect x="10" y="45" width="22" height="9" rx="3.5" fill="#8fca32"/>
14
+
15
+ <!-- High-tech circuit / relational anchor dot -->
16
+ <circle cx="48" cy="49" r="4.5" fill="#b8f34a"/>
17
+ <path d="M32 49.5H43.5" stroke="#b8f34a" stroke-width="2.5" stroke-linecap="round"/>
18
+ </svg>
@@ -0,0 +1,95 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Flobase Editor</title>
7
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
8
+ <link rel="alternate icon" href="/favicon.ico" />
9
+ <!-- Google Fonts Typography -->
10
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
11
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
12
+ <link
13
+ href="https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,400;0,500;1,400&family=Manrope:wght@400;500;600;700;800&display=swap"
14
+ rel="stylesheet"
15
+ />
16
+ <style>
17
+ :root {
18
+ --bg: #10120f;
19
+ --surface: #151814;
20
+ --surface-2: #1c221b;
21
+ --surface-3: #242c22;
22
+ --text: #f4f5ef;
23
+ --text-2: #9ba697;
24
+ --muted: #6f7a6b;
25
+ --line: #262f25;
26
+ --line-highlight: #334131;
27
+ --lime: #b8f34a;
28
+ --lime-hover: #c8fa67;
29
+ --lime-muted: #8fca32;
30
+ --lime-ink: #10120f;
31
+ --success: #86d9a0;
32
+ --font-sans: "Manrope", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
33
+ --font-mono: "DM Mono", Menlo, Consolas, Monaco, monospace;
34
+ }
35
+
36
+ * {
37
+ box-sizing: border-box;
38
+ }
39
+
40
+ body {
41
+ margin: 0;
42
+ padding: 0;
43
+ font-family: var(--font-sans);
44
+ background: var(--bg);
45
+ color: var(--text);
46
+ overflow: hidden;
47
+ -webkit-font-smoothing: antialiased;
48
+ }
49
+
50
+ /* Custom scrollbars */
51
+ ::-webkit-scrollbar {
52
+ width: 8px;
53
+ height: 8px;
54
+ }
55
+ ::-webkit-scrollbar-track {
56
+ background: var(--surface);
57
+ }
58
+ ::-webkit-scrollbar-thumb {
59
+ background: var(--line);
60
+ border-radius: 4px;
61
+ }
62
+ ::-webkit-scrollbar-thumb:hover {
63
+ background: var(--line-highlight);
64
+ }
65
+
66
+ /* ReactFlow Controls & Attribution overrides */
67
+ .react-flow__controls {
68
+ box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4) !important;
69
+ border: 1px solid var(--line) !important;
70
+ border-radius: 8px !important;
71
+ overflow: hidden !important;
72
+ background: var(--surface) !important;
73
+ }
74
+ .react-flow__controls-button {
75
+ background: var(--surface) !important;
76
+ border-bottom: 1px solid var(--line) !important;
77
+ color: var(--text-2) !important;
78
+ fill: var(--text-2) !important;
79
+ }
80
+ .react-flow__controls-button:hover {
81
+ background: var(--surface-2) !important;
82
+ color: var(--lime) !important;
83
+ fill: var(--lime) !important;
84
+ }
85
+ .react-flow__attribution {
86
+ display: none !important;
87
+ }
88
+ </style>
89
+ <script type="module" crossorigin src="/assets/index-C3FoJn2U.js"></script>
90
+ <link rel="stylesheet" crossorigin href="/assets/index-B5DZHykP.css">
91
+ </head>
92
+ <body>
93
+ <div id="root"></div>
94
+ </body>
95
+ </html>
package/package.json CHANGED
@@ -1,6 +1,43 @@
1
1
  {
2
2
  "name": "flobase-editor",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "files": [
10
+ "dist",
11
+ "server.ts",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "description": "Visual drag-and-drop canvas editor for Flobase schemas",
16
+ "scripts": {
17
+ "dev": "vite",
18
+ "build": "tsc && vite build",
19
+ "preview": "vite preview",
20
+ "server": "node --loader ts-node/esm server.ts"
21
+ },
22
+ "dependencies": {
23
+ "cors": "^2.8.5",
24
+ "express": "^4.21.2",
25
+ "picocolors": "^1.1.1",
26
+ "react": "^18.3.1",
27
+ "react-dom": "^18.3.1",
28
+ "reactflow": "^11.11.4",
29
+ "yaml": "^2.7.0",
30
+ "zod": "^3.24.2",
31
+ "zustand": "^4.5.5"
32
+ },
33
+ "devDependencies": {
34
+ "@types/cors": "^2.8.17",
35
+ "@types/express": "^5.0.0",
36
+ "@types/node": "^22.13.9",
37
+ "@types/react": "^18.3.18",
38
+ "@types/react-dom": "^18.3.5",
39
+ "@vitejs/plugin-react": "^4.3.4",
40
+ "typescript": "^5.8.2",
41
+ "vite": "^6.2.0"
42
+ }
43
+ }
package/server.ts ADDED
@@ -0,0 +1,194 @@
1
+ import express from "express";
2
+ import cors from "cors";
3
+ import * as fs from "fs/promises";
4
+ import * as path from "path";
5
+ import * as yaml from "yaml";
6
+ import { parseAndValidateSchema } from "../cli/src/schema.js";
7
+ import { generateOpenApiSpec } from "../cli/src/openapi-generator.js";
8
+
9
+ const app = express();
10
+ const PORT = parseInt(process.env.PORT || "3001", 10);
11
+
12
+ app.use(cors());
13
+ app.use(express.json({ limit: "10mb" }));
14
+
15
+ // Target schema path passed from CLI or default to schema.yaml in current directory
16
+ const targetSchemaPath = path.resolve(
17
+ process.cwd(),
18
+ process.env.FLOBASE_SCHEMA_PATH || process.env.UNISCHEMA_SCHEMA_PATH || "schema.yaml"
19
+ );
20
+
21
+ /**
22
+ * Updates a yaml.Document AST granularly using setIn to keep all existing comments intact
23
+ */
24
+ export function updateDocGranularly(doc: yaml.Document, schema: any): void {
25
+ doc.setIn(["version"], schema.version || "0.1.0");
26
+ if (schema.name) doc.setIn(["name"], schema.name);
27
+ if (schema.description) doc.setIn(["description"], schema.description);
28
+
29
+ if (schema.models) {
30
+ for (const [modelName, modelDef] of Object.entries<any>(schema.models)) {
31
+ if (modelDef.tableName) {
32
+ doc.setIn(["models", modelName, "tableName"], modelDef.tableName);
33
+ }
34
+ if (modelDef.fields) {
35
+ for (const [fieldName, fieldDef] of Object.entries<any>(modelDef.fields)) {
36
+ doc.setIn(["models", modelName, "fields", fieldName], fieldDef);
37
+ }
38
+ }
39
+ if (modelDef.relationships) {
40
+ doc.setIn(["models", modelName, "relationships"], modelDef.relationships);
41
+ }
42
+ }
43
+ }
44
+
45
+ if (schema.endpoints) {
46
+ doc.setIn(["endpoints"], schema.endpoints);
47
+ }
48
+ }
49
+
50
+ /**
51
+ * GET /api/schema
52
+ * Reads schema.yaml from disk and returns parsed JSON object
53
+ */
54
+ app.get("/api/schema", async (_req, res) => {
55
+ try {
56
+ const rawYaml = await fs.readFile(targetSchemaPath, "utf-8");
57
+ const parsedDoc = yaml.parseDocument(rawYaml);
58
+ res.json({
59
+ success: true,
60
+ path: targetSchemaPath,
61
+ schema: parsedDoc.toJS()
62
+ });
63
+ } catch (err: any) {
64
+ if (err.code === "ENOENT") {
65
+ res.status(404).json({
66
+ success: false,
67
+ error: `Schema file not found at '${targetSchemaPath}'. Run 'flobase init' first.`
68
+ });
69
+ return;
70
+ }
71
+ res.status(500).json({
72
+ success: false,
73
+ error: `Failed to read schema file: ${err.message}`
74
+ });
75
+ }
76
+ });
77
+
78
+ /**
79
+ * PUT /api/schema
80
+ * Validates and writes updated schema back to disk while preserving comments
81
+ */
82
+ app.put("/api/schema", async (req, res) => {
83
+ const { schema, sequence } = req.body;
84
+ if (!schema || typeof schema !== "object") {
85
+ res.status(400).json({
86
+ success: false,
87
+ error: "Invalid request payload: 'schema' object is required.",
88
+ sequence
89
+ });
90
+ return;
91
+ }
92
+
93
+ // 1. Validate with existing Zod schema
94
+ const validation = parseAndValidateSchema(yaml.stringify(schema));
95
+ if (!validation.success) {
96
+ res.status(422).json({
97
+ success: false,
98
+ errors: validation.errors,
99
+ sequence
100
+ });
101
+ return;
102
+ }
103
+
104
+ // 2. High-fidelity comment-preserving write using yaml.parseDocument and setIn
105
+ try {
106
+ let doc: yaml.Document;
107
+ try {
108
+ const existingYaml = await fs.readFile(targetSchemaPath, "utf-8");
109
+ doc = yaml.parseDocument(existingYaml);
110
+ updateDocGranularly(doc, schema);
111
+ } catch {
112
+ doc = new yaml.Document(schema);
113
+ }
114
+
115
+ await fs.writeFile(targetSchemaPath, doc.toString(), "utf-8");
116
+ res.json({
117
+ success: true,
118
+ message: "Schema updated successfully.",
119
+ sequence
120
+ });
121
+ } catch (err: any) {
122
+ res.status(500).json({
123
+ success: false,
124
+ error: `Failed to write schema to '${targetSchemaPath}': ${err.message}`,
125
+ sequence
126
+ });
127
+ }
128
+ });
129
+
130
+ /**
131
+ * POST /api/validate
132
+ * Validates a schema object against the official Zod and semantic checks
133
+ */
134
+ app.post("/api/validate", (req, res) => {
135
+ const { schema } = req.body;
136
+ if (!schema || typeof schema !== "object") {
137
+ res.status(400).json({ valid: false, errors: ["Missing schema payload"] });
138
+ return;
139
+ }
140
+
141
+ const validation = parseAndValidateSchema(yaml.stringify(schema));
142
+ res.json({
143
+ valid: validation.success,
144
+ errors: validation.errors
145
+ });
146
+ });
147
+
148
+ /**
149
+ * POST /api/openapi
150
+ * Generates OpenAPI 3.1 YAML contract directly using the CLI generator
151
+ */
152
+ app.post("/api/openapi", (req, res) => {
153
+ const { schema } = req.body;
154
+ if (!schema || typeof schema !== "object") {
155
+ res.status(400).json({ openapi: "", errors: ["Missing schema payload"] });
156
+ return;
157
+ }
158
+
159
+ const validation = parseAndValidateSchema(yaml.stringify(schema));
160
+ if (!validation.success || !validation.data) {
161
+ res.json({
162
+ openapi: "",
163
+ errors: validation.errors
164
+ });
165
+ return;
166
+ }
167
+
168
+ try {
169
+ const spec = generateOpenApiSpec(validation.data);
170
+ const openapiYaml = "# Generated OpenAPI 3.1 Contract\n" + yaml.stringify(spec, { indent: 2 });
171
+ res.json({
172
+ openapi: openapiYaml,
173
+ errors: []
174
+ });
175
+ } catch (err: any) {
176
+ res.status(500).json({
177
+ openapi: "",
178
+ errors: [`OpenAPI generation failed: ${err.message}`]
179
+ });
180
+ }
181
+ });
182
+
183
+ // Avoid port collision: fail-fast on port in use or allow environment override
184
+ const server = app.listen(PORT, () => {
185
+ console.log(`[Flobase Editor Server] Ready at http://localhost:${PORT}`);
186
+ console.log(`[Flobase Editor Server] Bound to: ${targetSchemaPath}`);
187
+ });
188
+
189
+ server.on("error", (err: any) => {
190
+ if (err.code === "EADDRINUSE") {
191
+ console.error(`[ERROR] Port ${PORT} is already in use. Please free port ${PORT} or specify PORT=xxx.`);
192
+ process.exit(1);
193
+ }
194
+ });