@objectql/cli 1.8.3 → 1.9.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/README.md +157 -1
- package/dist/commands/ai.js +4 -3
- package/dist/commands/ai.js.map +1 -1
- package/dist/commands/build.d.ts +12 -0
- package/dist/commands/build.js +119 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/database-push.d.ts +5 -0
- package/dist/commands/database-push.js +15 -0
- package/dist/commands/database-push.js.map +1 -0
- package/dist/commands/dev.d.ts +11 -0
- package/dist/commands/dev.js +111 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/doctor.d.ts +4 -0
- package/dist/commands/doctor.js +37 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/format.d.ts +9 -0
- package/dist/commands/format.js +137 -0
- package/dist/commands/format.js.map +1 -0
- package/dist/commands/init.js +31 -30
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/lint.d.ts +9 -0
- package/dist/commands/lint.js +120 -0
- package/dist/commands/lint.js.map +1 -0
- package/dist/commands/new.js +0 -52
- package/dist/commands/new.js.map +1 -1
- package/dist/commands/serve.d.ts +2 -0
- package/dist/commands/serve.js +122 -46
- package/dist/commands/serve.js.map +1 -1
- package/dist/commands/start.d.ts +12 -0
- package/dist/commands/start.js +134 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/commands/test.d.ts +10 -0
- package/dist/commands/test.js +120 -0
- package/dist/commands/test.js.map +1 -0
- package/dist/index.js +189 -149
- package/dist/index.js.map +1 -1
- package/package.json +13 -8
- package/templates/hello-world/.vscode/extensions.json +7 -0
- package/templates/hello-world/CHANGELOG.md +41 -0
- package/templates/hello-world/README.md +29 -0
- package/templates/hello-world/package.json +24 -0
- package/templates/hello-world/src/index.ts +58 -0
- package/templates/hello-world/tsconfig.json +10 -0
- package/templates/starter/.vscode/extensions.json +7 -0
- package/{CHANGELOG.md → templates/starter/CHANGELOG.md} +47 -41
- package/templates/starter/README.md +17 -0
- package/templates/starter/__tests__/projects-hooks-actions.test.ts +490 -0
- package/templates/starter/jest.config.js +16 -0
- package/templates/starter/package.json +52 -0
- package/templates/starter/src/README.pages.md +110 -0
- package/templates/starter/src/demo.app.yml +4 -0
- package/templates/starter/src/i18n/zh-CN/projects.json +22 -0
- package/templates/starter/src/modules/kitchen-sink/kitchen_sink.data.yml +18 -0
- package/templates/starter/src/modules/kitchen-sink/kitchen_sink.object.yml +156 -0
- package/templates/starter/src/modules/projects/project_approval.workflow.yml +51 -0
- package/templates/starter/src/modules/projects/projects.action.ts +472 -0
- package/templates/starter/src/modules/projects/projects.data.yml +13 -0
- package/templates/starter/src/modules/projects/projects.hook.ts +339 -0
- package/templates/starter/src/modules/projects/projects.object.yml +148 -0
- package/templates/starter/src/modules/projects/projects.permission.yml +141 -0
- package/templates/starter/src/modules/projects/projects.validation.yml +37 -0
- package/templates/starter/src/modules/tasks/tasks.data.yml +23 -0
- package/templates/starter/src/modules/tasks/tasks.object.yml +34 -0
- package/templates/starter/src/modules/tasks/tasks.permission.yml +167 -0
- package/templates/starter/src/seed.ts +55 -0
- package/templates/starter/src/types/index.ts +3 -0
- package/templates/starter/src/types/kitchen_sink.ts +101 -0
- package/templates/starter/src/types/projects.ts +49 -0
- package/templates/starter/src/types/tasks.ts +33 -0
- package/templates/starter/tsconfig.json +11 -0
- package/templates/starter/tsconfig.tsbuildinfo +1 -0
- package/AI_EXAMPLES.md +0 -154
- package/AI_IMPLEMENTATION_SUMMARY.md +0 -509
- package/AI_TUTORIAL.md +0 -144
- package/IMPLEMENTATION_SUMMARY.md +0 -437
- package/USAGE_EXAMPLES.md +0 -951
- package/__tests__/commands.test.ts +0 -316
- package/dist/commands/studio.d.ts +0 -5
- package/dist/commands/studio.js +0 -364
- package/dist/commands/studio.js.map +0 -1
- package/jest.config.js +0 -19
- package/src/commands/ai.ts +0 -508
- package/src/commands/generate.ts +0 -135
- package/src/commands/i18n.ts +0 -303
- package/src/commands/init.ts +0 -191
- package/src/commands/migrate.ts +0 -314
- package/src/commands/new.ts +0 -273
- package/src/commands/repl.ts +0 -120
- package/src/commands/serve.ts +0 -96
- package/src/commands/studio.ts +0 -354
- package/src/commands/sync.ts +0 -328
- package/src/index.ts +0 -274
- package/tsconfig.json +0 -15
- package/tsconfig.tsbuildinfo +0 -1
package/src/commands/serve.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { ObjectQL } from '@objectql/core';
|
|
2
|
-
import { SqlDriver } from '@objectql/driver-sql';
|
|
3
|
-
import { ObjectLoader } from '@objectql/platform-node';
|
|
4
|
-
import { createNodeHandler } from '@objectql/server';
|
|
5
|
-
import { createServer } from 'http';
|
|
6
|
-
import * as path from 'path';
|
|
7
|
-
import chalk from 'chalk';
|
|
8
|
-
|
|
9
|
-
const CONSOLE_HTML = `
|
|
10
|
-
<!DOCTYPE html>
|
|
11
|
-
<html lang="en">
|
|
12
|
-
<head>
|
|
13
|
-
<meta charset="utf-8" />
|
|
14
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
15
|
-
<title>ObjectQL Swagger UI</title>
|
|
16
|
-
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5.11.0/swagger-ui.css" />
|
|
17
|
-
<style>
|
|
18
|
-
body { margin: 0; padding: 0; }
|
|
19
|
-
</style>
|
|
20
|
-
</head>
|
|
21
|
-
<body>
|
|
22
|
-
<div id="swagger-ui"></div>
|
|
23
|
-
<script src="https://unpkg.com/swagger-ui-dist@5.11.0/swagger-ui-bundle.js" crossorigin></script>
|
|
24
|
-
<script>
|
|
25
|
-
window.onload = () => {
|
|
26
|
-
window.ui = SwaggerUIBundle({
|
|
27
|
-
url: '/openapi.json',
|
|
28
|
-
dom_id: '#swagger-ui',
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
</script>
|
|
32
|
-
</body>
|
|
33
|
-
</html>
|
|
34
|
-
`;
|
|
35
|
-
|
|
36
|
-
export async function serve(options: { port: number; dir: string }) {
|
|
37
|
-
console.log(chalk.blue('Starting ObjectQL Dev Server...'));
|
|
38
|
-
|
|
39
|
-
const rootDir = path.resolve(process.cwd(), options.dir);
|
|
40
|
-
console.log(chalk.gray(`Loading schema from: ${rootDir}`));
|
|
41
|
-
|
|
42
|
-
// 1. Init ObjectQL with in-memory SQLite for Dev
|
|
43
|
-
const app = new ObjectQL({
|
|
44
|
-
datasources: {
|
|
45
|
-
default: new SqlDriver({
|
|
46
|
-
client: 'sqlite3',
|
|
47
|
-
connection: {
|
|
48
|
-
filename: ':memory:' // Or local file './dev.db'
|
|
49
|
-
},
|
|
50
|
-
useNullAsDefault: true
|
|
51
|
-
})
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
// 2. Load Schema
|
|
56
|
-
try {
|
|
57
|
-
const loader = new ObjectLoader(app.metadata);
|
|
58
|
-
loader.load(rootDir);
|
|
59
|
-
await app.init();
|
|
60
|
-
console.log(chalk.green('✅ Schema loaded successfully.'));
|
|
61
|
-
} catch (e: any) {
|
|
62
|
-
console.error(chalk.red('❌ Failed to load schema:'), e.message);
|
|
63
|
-
process.exit(1);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// 3. Create Handler
|
|
67
|
-
const internalHandler = createNodeHandler(app);
|
|
68
|
-
|
|
69
|
-
// 4. Start Server
|
|
70
|
-
const server = createServer(async (req, res) => {
|
|
71
|
-
// Serve Swagger UI
|
|
72
|
-
if (req.method === 'GET' && (req.url === '/swagger' || req.url === '/swagger/')) {
|
|
73
|
-
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
74
|
-
res.end(CONSOLE_HTML);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Redirect / to /swagger for better DX
|
|
79
|
-
if (req.method === 'GET' && req.url === '/') {
|
|
80
|
-
res.writeHead(302, { 'Location': '/swagger' });
|
|
81
|
-
res.end();
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Delegate to API Handler
|
|
86
|
-
await internalHandler(req, res);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
server.listen(options.port, () => {
|
|
90
|
-
console.log(chalk.green(`\n🚀 Server ready at http://localhost:${options.port}`));
|
|
91
|
-
console.log(chalk.green(`📚 Swagger UI: http://localhost:${options.port}/swagger`));
|
|
92
|
-
console.log(chalk.blue(`📖 OpenAPI Spec: http://localhost:${options.port}/openapi.json`));
|
|
93
|
-
console.log(chalk.gray('\nTry a curl command:'));
|
|
94
|
-
console.log(`curl -X POST http://localhost:${options.port} -H "Content-Type: application/json" -d '{"op": "find", "object": "YourObject", "args": {}}'`);
|
|
95
|
-
});
|
|
96
|
-
}
|
package/src/commands/studio.ts
DELETED
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
import { ObjectQL } from '@objectql/core';
|
|
2
|
-
import { ObjectLoader, createDriverFromConnection } from '@objectql/platform-node';
|
|
3
|
-
import { createNodeHandler, createStudioHandler, createMetadataHandler } from '@objectql/server';
|
|
4
|
-
import { createServer } from 'http';
|
|
5
|
-
import * as path from 'path';
|
|
6
|
-
import * as fs from 'fs';
|
|
7
|
-
import chalk from 'chalk';
|
|
8
|
-
import { exec } from 'child_process';
|
|
9
|
-
import { register } from 'ts-node';
|
|
10
|
-
import glob from 'fast-glob';
|
|
11
|
-
|
|
12
|
-
const SWAGGER_HTML = `
|
|
13
|
-
<!DOCTYPE html>
|
|
14
|
-
<html lang="en">
|
|
15
|
-
<head>
|
|
16
|
-
<meta charset="utf-8" />
|
|
17
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
18
|
-
<title>ObjectQL Swagger UI</title>
|
|
19
|
-
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5.11.0/swagger-ui.css" />
|
|
20
|
-
<style>
|
|
21
|
-
body { margin: 0; padding: 0; }
|
|
22
|
-
</style>
|
|
23
|
-
</head>
|
|
24
|
-
<body>
|
|
25
|
-
<div id="swagger-ui"></div>
|
|
26
|
-
<script src="https://unpkg.com/swagger-ui-dist@5.11.0/swagger-ui-bundle.js" crossorigin></script>
|
|
27
|
-
<script>
|
|
28
|
-
window.onload = () => {
|
|
29
|
-
window.ui = SwaggerUIBundle({
|
|
30
|
-
url: '/openapi.json',
|
|
31
|
-
dom_id: '#swagger-ui',
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
</script>
|
|
35
|
-
</body>
|
|
36
|
-
</html>
|
|
37
|
-
`;
|
|
38
|
-
|
|
39
|
-
function openBrowser(url: string) {
|
|
40
|
-
const start = (process.platform == 'darwin' ? 'open' : process.platform == 'win32' ? 'start' : 'xdg-open');
|
|
41
|
-
exec(`${start} ${url}`);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export async function startStudio(options: { port: number; dir: string, open?: boolean }) {
|
|
45
|
-
const startPort = options.port || 5555;
|
|
46
|
-
const rootDir = path.resolve(process.cwd(), options.dir || '.');
|
|
47
|
-
|
|
48
|
-
console.log(chalk.blue('Starting ObjectQL Studio...'));
|
|
49
|
-
console.log(chalk.gray(`Project Root: ${rootDir}`));
|
|
50
|
-
|
|
51
|
-
// Register ts-node
|
|
52
|
-
register({
|
|
53
|
-
transpileOnly: true,
|
|
54
|
-
compilerOptions: {
|
|
55
|
-
module: "commonjs"
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
let app: ObjectQL;
|
|
60
|
-
const configTs = path.join(rootDir, 'objectql.config.ts');
|
|
61
|
-
const configJs = path.join(rootDir, 'objectql.config.js');
|
|
62
|
-
|
|
63
|
-
if (fs.existsSync(configTs)) {
|
|
64
|
-
console.log(chalk.gray(`Loading config from ${configTs}`));
|
|
65
|
-
const mod = require(configTs);
|
|
66
|
-
app = mod.default || mod;
|
|
67
|
-
} else if (fs.existsSync(configJs)) {
|
|
68
|
-
console.log(chalk.gray(`Loading config from ${configJs}`));
|
|
69
|
-
const mod = require(configJs);
|
|
70
|
-
app = mod.default || mod;
|
|
71
|
-
} else {
|
|
72
|
-
console.error(chalk.red('\n❌ Error: Configuration file (objectql.config.ts) not found.'));
|
|
73
|
-
process.exit(1);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (!app) {
|
|
77
|
-
console.error(chalk.red('\n❌ Error: No default export found in configuration file.'));
|
|
78
|
-
process.exit(1);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Initialize App if it's a configuration object
|
|
82
|
-
if (typeof (app as any).init !== 'function') {
|
|
83
|
-
const config = app as any;
|
|
84
|
-
console.log(chalk.gray('Configuration object detected. Initializing ObjectQL instance...'));
|
|
85
|
-
|
|
86
|
-
const datasources: any = {};
|
|
87
|
-
|
|
88
|
-
if (config.datasource && config.datasource.default) {
|
|
89
|
-
const dbConfig = config.datasource.default;
|
|
90
|
-
if (dbConfig.type === 'sqlite') {
|
|
91
|
-
try {
|
|
92
|
-
const { SqlDriver } = require('@objectql/driver-sql');
|
|
93
|
-
datasources.default = new SqlDriver({
|
|
94
|
-
client: 'sqlite3',
|
|
95
|
-
connection: {
|
|
96
|
-
filename: dbConfig.filename ? path.resolve(rootDir, dbConfig.filename) : ':memory:'
|
|
97
|
-
},
|
|
98
|
-
useNullAsDefault: true
|
|
99
|
-
});
|
|
100
|
-
} catch (e) {
|
|
101
|
-
console.warn(chalk.yellow('Failed to load @objectql/driver-sql. Ensure it is installed.'));
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Fallback to memory if no datasource
|
|
107
|
-
if (!datasources.default) {
|
|
108
|
-
console.warn(chalk.yellow('No valid datasource found. Using in-memory SQLite.'));
|
|
109
|
-
const { SqlDriver } = require('@objectql/driver-sql');
|
|
110
|
-
datasources.default = new SqlDriver({
|
|
111
|
-
client: 'sqlite3',
|
|
112
|
-
connection: { filename: ':memory:' },
|
|
113
|
-
useNullAsDefault: true
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
app = new ObjectQL({ datasources });
|
|
118
|
-
|
|
119
|
-
// Load Schema
|
|
120
|
-
const loader = new ObjectLoader(app.metadata);
|
|
121
|
-
|
|
122
|
-
// Load Presets
|
|
123
|
-
if (Array.isArray(config.presets)) {
|
|
124
|
-
console.log(chalk.gray(`Loading ${config.presets.length} presets...`));
|
|
125
|
-
for (const preset of config.presets) {
|
|
126
|
-
try {
|
|
127
|
-
loader.loadPackage(preset);
|
|
128
|
-
} catch (e: any) {
|
|
129
|
-
console.warn(chalk.yellow(`Failed to load preset ${preset}:`), e.message);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Load Schema from Directory
|
|
135
|
-
// In a monorepo root with presets, scanning everything is dangerous.
|
|
136
|
-
// We check if we are in a monorepo-like environment.
|
|
137
|
-
const isMonorepoRoot = fs.existsSync(path.join(rootDir, 'pnpm-workspace.yaml')) || fs.existsSync(path.join(rootDir, 'pnpm-lock.yaml'));
|
|
138
|
-
|
|
139
|
-
// If we are in a likely monorepo root AND have presets, skip recursive scan
|
|
140
|
-
if (isMonorepoRoot && config.presets && config.presets.length > 0) {
|
|
141
|
-
console.log(chalk.yellow('Monorepo root detected with presets. Skipping recursive file scan of root directory to avoid conflicts.'));
|
|
142
|
-
} else {
|
|
143
|
-
loader.load(rootDir);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// 2. Load Schema & Init
|
|
148
|
-
try {
|
|
149
|
-
await app.init();
|
|
150
|
-
} catch (e: any) {
|
|
151
|
-
console.error(chalk.red('❌ Failed to initialize application:'), e.message);
|
|
152
|
-
process.exit(1);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// 3. Setup HTTP Server
|
|
156
|
-
const nodeHandler = createNodeHandler(app);
|
|
157
|
-
const studioHandler = createStudioHandler();
|
|
158
|
-
const metadataHandler = createMetadataHandler(app);
|
|
159
|
-
|
|
160
|
-
const server = createServer(async (req, res) => {
|
|
161
|
-
// CORS
|
|
162
|
-
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
163
|
-
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
|
164
|
-
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
|
165
|
-
|
|
166
|
-
if (req.method === 'OPTIONS') {
|
|
167
|
-
res.writeHead(200);
|
|
168
|
-
res.end();
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (req.url === '/openapi.json') {
|
|
173
|
-
return nodeHandler(req, res);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (req.url === '/swagger') {
|
|
177
|
-
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
178
|
-
res.end(SWAGGER_HTML);
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// Routing
|
|
183
|
-
if (req.url?.startsWith('/studio')) {
|
|
184
|
-
return studioHandler(req, res);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (req.url?.startsWith('/api/schema/files')) {
|
|
188
|
-
// List all metadata files
|
|
189
|
-
try {
|
|
190
|
-
// Find all *.*.yml files relative to rootDir
|
|
191
|
-
// Note: User might have configured objectql with specific source paths.
|
|
192
|
-
// We ignore common build folders to avoid duplicates/editing compiled files.
|
|
193
|
-
// We broadly match all objectql-like files: *.object.yml, *.view.yml, etc.
|
|
194
|
-
const files = await glob('**/*.{object,app,view,permission,report,validation,workflow,form,data,hook,action}.yml', {
|
|
195
|
-
cwd: rootDir,
|
|
196
|
-
ignore: ['node_modules/**', 'dist/**', 'build/**', 'out/**', '.git/**', '.next/**']
|
|
197
|
-
});
|
|
198
|
-
res.setHeader('Content-Type', 'application/json');
|
|
199
|
-
res.end(JSON.stringify({ files }));
|
|
200
|
-
} catch (e: any) {
|
|
201
|
-
res.statusCode = 500;
|
|
202
|
-
res.end(JSON.stringify({ error: e.message }));
|
|
203
|
-
}
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (req.url?.startsWith('/api/schema/content')) {
|
|
208
|
-
const urlObj = new URL(req.url, `http://${req.headers.host}`);
|
|
209
|
-
const file = urlObj.searchParams.get('file');
|
|
210
|
-
|
|
211
|
-
if (!file) {
|
|
212
|
-
res.statusCode = 400;
|
|
213
|
-
res.end(JSON.stringify({ error: 'Missing file parameter' }));
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const filePath = path.join(rootDir, file);
|
|
218
|
-
// Security check
|
|
219
|
-
if (!filePath.startsWith(rootDir)) {
|
|
220
|
-
res.statusCode = 403;
|
|
221
|
-
res.end(JSON.stringify({ error: 'Access denied' }));
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
if (req.method === 'GET') {
|
|
226
|
-
try {
|
|
227
|
-
const content = fs.readFileSync(filePath, 'utf-8');
|
|
228
|
-
res.setHeader('Content-Type', 'text/plain'); // Plain text (YAML)
|
|
229
|
-
res.end(content);
|
|
230
|
-
} catch (e) {
|
|
231
|
-
res.statusCode = 404;
|
|
232
|
-
res.end(JSON.stringify({ error: 'File not found' }));
|
|
233
|
-
}
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
if (req.method === 'POST') {
|
|
238
|
-
let body = '';
|
|
239
|
-
req.on('data', chunk => body += chunk);
|
|
240
|
-
req.on('end', () => {
|
|
241
|
-
try {
|
|
242
|
-
fs.writeFileSync(filePath, body, 'utf-8');
|
|
243
|
-
res.statusCode = 200;
|
|
244
|
-
res.end(JSON.stringify({ success: true }));
|
|
245
|
-
} catch (e: any) {
|
|
246
|
-
res.statusCode = 500;
|
|
247
|
-
res.end(JSON.stringify({ error: e.message }));
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
if (req.url?.startsWith('/api/schema/find')) {
|
|
255
|
-
const urlObj = new URL(req.url, `http://${req.headers.host}`);
|
|
256
|
-
const objectName = urlObj.searchParams.get('object');
|
|
257
|
-
|
|
258
|
-
if (!objectName) {
|
|
259
|
-
res.statusCode = 400;
|
|
260
|
-
res.end(JSON.stringify({ error: 'Missing object parameter' }));
|
|
261
|
-
return;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
try {
|
|
265
|
-
// Find all object.yml files
|
|
266
|
-
const files = await glob('**/*.object.yml', {
|
|
267
|
-
cwd: rootDir,
|
|
268
|
-
ignore: ['node_modules/**', 'dist/**', 'build/**', 'out/**', '.git/**', '.next/**']
|
|
269
|
-
});
|
|
270
|
-
let foundFile = null;
|
|
271
|
-
|
|
272
|
-
// Naive parsing to find the object definition
|
|
273
|
-
// We don't use the FULL parser, just checks if "name: objectName" is present
|
|
274
|
-
for (const file of files) {
|
|
275
|
-
const content = fs.readFileSync(path.join(rootDir, file), 'utf-8');
|
|
276
|
-
// Simple check: name: <objectName> or name: "<objectName>"
|
|
277
|
-
// This creates a regex that looks for `name:` followed by the objectName
|
|
278
|
-
// Handles spaces, quotes
|
|
279
|
-
const regex = new RegExp(`^\\s*name:\\s*["']?${objectName}["']?\\s*$`, 'm');
|
|
280
|
-
if (regex.test(content)) {
|
|
281
|
-
foundFile = file;
|
|
282
|
-
break;
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
if (foundFile) {
|
|
287
|
-
res.setHeader('Content-Type', 'application/json');
|
|
288
|
-
res.end(JSON.stringify({ file: foundFile }));
|
|
289
|
-
} else {
|
|
290
|
-
res.statusCode = 404;
|
|
291
|
-
res.end(JSON.stringify({ error: 'Object definition file not found' }));
|
|
292
|
-
}
|
|
293
|
-
} catch (e: any) {
|
|
294
|
-
res.statusCode = 500;
|
|
295
|
-
res.end(JSON.stringify({ error: e.message }));
|
|
296
|
-
}
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
if (req.url?.startsWith('/api/metadata')) {
|
|
301
|
-
return metadataHandler(req, res);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
if (req.url?.startsWith('/api')) {
|
|
305
|
-
// Strip /api prefix if needed by the handler,
|
|
306
|
-
// but ObjectQL node handler usually expects full path or depends on internal routing.
|
|
307
|
-
// Actually createNodeHandler handles /objectql/v1/ etc?
|
|
308
|
-
// Let's assume standard behavior: pass to handler
|
|
309
|
-
return nodeHandler(req, res);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
// Redirect root to studio
|
|
313
|
-
if (req.url === '/') {
|
|
314
|
-
res.writeHead(302, { 'Location': '/studio' });
|
|
315
|
-
res.end();
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
res.statusCode = 404;
|
|
320
|
-
res.end('Not Found');
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
const tryListen = (port: number) => {
|
|
324
|
-
server.removeAllListeners('error');
|
|
325
|
-
server.removeAllListeners('listening'); // Prevent stacking callbacks
|
|
326
|
-
|
|
327
|
-
server.on('error', (e: any) => {
|
|
328
|
-
if (e.code === 'EADDRINUSE') {
|
|
329
|
-
if (port - startPort < 10) {
|
|
330
|
-
console.log(chalk.yellow(`Port ${port} is in use, trying ${port + 1}...`));
|
|
331
|
-
server.close();
|
|
332
|
-
tryListen(port + 1);
|
|
333
|
-
} else {
|
|
334
|
-
console.error(chalk.red(`❌ Unable to find a free port.`));
|
|
335
|
-
process.exit(1);
|
|
336
|
-
}
|
|
337
|
-
} else {
|
|
338
|
-
console.error(chalk.red('❌ Server error:'), e);
|
|
339
|
-
}
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
server.listen(port, () => {
|
|
343
|
-
const url = `http://localhost:${port}/studio`;
|
|
344
|
-
console.log(chalk.green(`\n🚀 Studio running at: ${chalk.bold(url)}`));
|
|
345
|
-
console.log(chalk.gray(` API endpoint: http://localhost:${port}/api`));
|
|
346
|
-
|
|
347
|
-
if (options.open) {
|
|
348
|
-
openBrowser(url);
|
|
349
|
-
}
|
|
350
|
-
});
|
|
351
|
-
};
|
|
352
|
-
|
|
353
|
-
tryListen(startPort);
|
|
354
|
-
}
|