@mostajs/setup 2.0.1 → 2.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.
- package/dist/api/routes.d.ts +46 -0
- package/dist/api/routes.js +121 -0
- package/dist/components/ReconfigPanel.js +2 -2
- package/dist/components/SetupWizard.js +3 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -1
- package/dist/lib/setup.js +2 -1
- package/package.json +6 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { MostaSetupConfig } from '../types/index.js';
|
|
2
|
+
type NeedsSetupFn = () => Promise<boolean>;
|
|
3
|
+
type GetSetupConfigFn = () => Promise<MostaSetupConfig>;
|
|
4
|
+
export interface SetupRoutesConfig {
|
|
5
|
+
needsSetup: NeedsSetupFn;
|
|
6
|
+
getSetupConfig: GetSetupConfigFn;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Creates GET, POST, DELETE, PATCH handlers for a catch-all [...slug] route.
|
|
10
|
+
*
|
|
11
|
+
* Dispatch table (11 slugs):
|
|
12
|
+
* status GET
|
|
13
|
+
* test-db POST
|
|
14
|
+
* create-db POST
|
|
15
|
+
* preflight GET
|
|
16
|
+
* detect-modules GET
|
|
17
|
+
* install-modules POST
|
|
18
|
+
* setup-json GET POST
|
|
19
|
+
* upload-jar GET POST DELETE PATCH
|
|
20
|
+
* wire-module GET POST
|
|
21
|
+
* reconfig GET POST
|
|
22
|
+
* install POST
|
|
23
|
+
*/
|
|
24
|
+
export declare function createSetupRoutes(config: SetupRoutesConfig): {
|
|
25
|
+
GET: (req: Request, { params }: {
|
|
26
|
+
params: Promise<{
|
|
27
|
+
slug: string[];
|
|
28
|
+
}>;
|
|
29
|
+
}) => Promise<Response>;
|
|
30
|
+
POST: (req: Request, { params }: {
|
|
31
|
+
params: Promise<{
|
|
32
|
+
slug: string[];
|
|
33
|
+
}>;
|
|
34
|
+
}) => Promise<Response>;
|
|
35
|
+
DELETE: (req: Request, { params }: {
|
|
36
|
+
params: Promise<{
|
|
37
|
+
slug: string[];
|
|
38
|
+
}>;
|
|
39
|
+
}) => Promise<Response>;
|
|
40
|
+
PATCH: (req: Request, { params }: {
|
|
41
|
+
params: Promise<{
|
|
42
|
+
slug: string[];
|
|
43
|
+
}>;
|
|
44
|
+
}) => Promise<Response>;
|
|
45
|
+
};
|
|
46
|
+
export {};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// @mostajs/setup — Catch-all route factory
|
|
2
|
+
// Author: Dr Hamid MADANI drmdh@msn.com
|
|
3
|
+
//
|
|
4
|
+
// Replaces 6+ individual route files with a single [...slug] handler.
|
|
5
|
+
// Usage:
|
|
6
|
+
// export const { GET, POST, DELETE, PATCH } = createSetupRoutes({
|
|
7
|
+
// needsSetup: appNeedsSetup,
|
|
8
|
+
// getSetupConfig,
|
|
9
|
+
// })
|
|
10
|
+
/**
|
|
11
|
+
* Creates GET, POST, DELETE, PATCH handlers for a catch-all [...slug] route.
|
|
12
|
+
*
|
|
13
|
+
* Dispatch table (11 slugs):
|
|
14
|
+
* status GET
|
|
15
|
+
* test-db POST
|
|
16
|
+
* create-db POST
|
|
17
|
+
* preflight GET
|
|
18
|
+
* detect-modules GET
|
|
19
|
+
* install-modules POST
|
|
20
|
+
* setup-json GET POST
|
|
21
|
+
* upload-jar GET POST DELETE PATCH
|
|
22
|
+
* wire-module GET POST
|
|
23
|
+
* reconfig GET POST
|
|
24
|
+
* install POST
|
|
25
|
+
*/
|
|
26
|
+
export function createSetupRoutes(config) {
|
|
27
|
+
const { needsSetup, getSetupConfig } = config;
|
|
28
|
+
// Lazy-init: handlers are created on first request, not at import time
|
|
29
|
+
let table = null;
|
|
30
|
+
async function buildTable() {
|
|
31
|
+
if (table)
|
|
32
|
+
return table;
|
|
33
|
+
// Import all factories
|
|
34
|
+
const [{ createStatusHandler }, { createTestDbHandler }, { createCreateDbHandler }, { createPreflightHandler }, { createDetectModulesHandler }, { createInstallModulesHandler }, { createSetupJsonHandler }, { createUploadJarHandlers }, { createWireModuleHandler }, { createReconfigHandlers }, { createInstallHandler },] = await Promise.all([
|
|
35
|
+
import('./status.route.js'),
|
|
36
|
+
import('./test-db.route.js'),
|
|
37
|
+
import('./create-db.route.js'),
|
|
38
|
+
import('./preflight.route.js'),
|
|
39
|
+
import('./detect-modules.route.js'),
|
|
40
|
+
import('./install-modules.route.js'),
|
|
41
|
+
import('./upload-setup-json.route.js'),
|
|
42
|
+
import('./upload-jar.route.js'),
|
|
43
|
+
import('./wire-module.route.js'),
|
|
44
|
+
import('./reconfig.route.js'),
|
|
45
|
+
import('./install.route.js'),
|
|
46
|
+
]);
|
|
47
|
+
// Build handlers — pass needsSetup / config where required
|
|
48
|
+
const status = createStatusHandler(needsSetup);
|
|
49
|
+
const testDb = createTestDbHandler(needsSetup);
|
|
50
|
+
const createDb = createCreateDbHandler();
|
|
51
|
+
const preflight = createPreflightHandler();
|
|
52
|
+
const detectModules = createDetectModulesHandler();
|
|
53
|
+
const installModules = createInstallModulesHandler(needsSetup);
|
|
54
|
+
const setupJson = createSetupJsonHandler(needsSetup);
|
|
55
|
+
const uploadJar = createUploadJarHandlers();
|
|
56
|
+
const wireModule = createWireModuleHandler();
|
|
57
|
+
const reconfig = createReconfigHandlers();
|
|
58
|
+
// install handler needs async setupConfig — wrap it
|
|
59
|
+
const installHandlers = {
|
|
60
|
+
POST: async (req) => {
|
|
61
|
+
const setupConfig = await getSetupConfig();
|
|
62
|
+
const { POST: installPOST } = createInstallHandler(needsSetup, setupConfig);
|
|
63
|
+
return installPOST(req);
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
table = {
|
|
67
|
+
'status': { GET: status.GET },
|
|
68
|
+
'test-db': { POST: testDb.POST },
|
|
69
|
+
'create-db': { POST: createDb.POST },
|
|
70
|
+
'preflight': { GET: preflight.GET },
|
|
71
|
+
'detect-modules': { GET: detectModules.GET },
|
|
72
|
+
'install-modules': { POST: installModules.POST },
|
|
73
|
+
'setup-json': { GET: setupJson.GET, POST: setupJson.POST },
|
|
74
|
+
'upload-jar': { GET: uploadJar.GET, POST: uploadJar.POST, DELETE: uploadJar.DELETE, PATCH: uploadJar.PATCH },
|
|
75
|
+
'wire-module': { GET: wireModule.GET, POST: wireModule.POST },
|
|
76
|
+
'reconfig': { GET: reconfig.GET, POST: reconfig.POST },
|
|
77
|
+
'install': installHandlers,
|
|
78
|
+
};
|
|
79
|
+
return table;
|
|
80
|
+
}
|
|
81
|
+
function notFound(slug, method) {
|
|
82
|
+
return Response.json({ error: `Setup route not found: ${method} /api/setup/${slug}` }, { status: 404 });
|
|
83
|
+
}
|
|
84
|
+
async function GET(req, { params }) {
|
|
85
|
+
const { slug } = await params;
|
|
86
|
+
const key = slug?.[0] || '';
|
|
87
|
+
const t = await buildTable();
|
|
88
|
+
const handler = t[key]?.GET;
|
|
89
|
+
if (!handler)
|
|
90
|
+
return notFound(key, 'GET');
|
|
91
|
+
return handler(req);
|
|
92
|
+
}
|
|
93
|
+
async function POST(req, { params }) {
|
|
94
|
+
const { slug } = await params;
|
|
95
|
+
const key = slug?.[0] || '';
|
|
96
|
+
const t = await buildTable();
|
|
97
|
+
const handler = t[key]?.POST;
|
|
98
|
+
if (!handler)
|
|
99
|
+
return notFound(key, 'POST');
|
|
100
|
+
return handler(req);
|
|
101
|
+
}
|
|
102
|
+
async function DELETE(req, { params }) {
|
|
103
|
+
const { slug } = await params;
|
|
104
|
+
const key = slug?.[0] || '';
|
|
105
|
+
const t = await buildTable();
|
|
106
|
+
const handler = t[key]?.DELETE;
|
|
107
|
+
if (!handler)
|
|
108
|
+
return notFound(key, 'DELETE');
|
|
109
|
+
return handler(req);
|
|
110
|
+
}
|
|
111
|
+
async function PATCH(req, { params }) {
|
|
112
|
+
const { slug } = await params;
|
|
113
|
+
const key = slug?.[0] || '';
|
|
114
|
+
const t = await buildTable();
|
|
115
|
+
const handler = t[key]?.PATCH;
|
|
116
|
+
if (!handler)
|
|
117
|
+
return notFound(key, 'PATCH');
|
|
118
|
+
return handler(req);
|
|
119
|
+
}
|
|
120
|
+
return { GET, POST, DELETE, PATCH };
|
|
121
|
+
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
5
|
import { useState, useEffect, useCallback } from 'react';
|
|
6
6
|
/** Dialects that require a JDBC bridge JAR */
|
|
7
|
-
const JDBC_DIALECTS = ['hsqldb', '
|
|
7
|
+
const JDBC_DIALECTS = ['hsqldb', 'db2', 'sybase', 'hana'];
|
|
8
8
|
const DIALECTS = [
|
|
9
9
|
{ key: 'mongodb', name: 'MongoDB', icon: '🍃', defaultPort: 27017, defaultUser: '', defaultHost: 'localhost', requiresAuth: false },
|
|
10
10
|
{ key: 'sqlite', name: 'SQLite', icon: '📄', defaultPort: 0, defaultUser: '', defaultHost: '', requiresAuth: false },
|
|
@@ -12,7 +12,7 @@ const DIALECTS = [
|
|
|
12
12
|
{ key: 'mysql', name: 'MySQL', icon: '🐬', defaultPort: 3306, defaultUser: 'root', defaultHost: 'localhost', requiresAuth: true },
|
|
13
13
|
{ key: 'mariadb', name: 'MariaDB', icon: '🦭', defaultPort: 3306, defaultUser: 'root', defaultHost: 'localhost', requiresAuth: true },
|
|
14
14
|
{ key: 'mssql', name: 'SQL Server', icon: '🟦', defaultPort: 1433, defaultUser: 'sa', defaultHost: 'localhost', requiresAuth: true },
|
|
15
|
-
{ key: 'oracle', name: 'Oracle', icon: '🔴', defaultPort: 1521, defaultUser: 'system', defaultHost: 'localhost', requiresAuth: true
|
|
15
|
+
{ key: 'oracle', name: 'Oracle', icon: '🔴', defaultPort: 1521, defaultUser: 'system', defaultHost: 'localhost', requiresAuth: true },
|
|
16
16
|
{ key: 'cockroachdb', name: 'CockroachDB', icon: '🪳', defaultPort: 26257, defaultUser: 'root', defaultHost: 'localhost', requiresAuth: true },
|
|
17
17
|
{ key: 'db2', name: 'IBM DB2', icon: '🏢', defaultPort: 50000, defaultUser: 'db2inst1', defaultHost: 'localhost', requiresAuth: true, premium: true, jdbc: true },
|
|
18
18
|
{ key: 'hana', name: 'SAP HANA', icon: '💎', defaultPort: 39013, defaultUser: 'SYSTEM', defaultHost: 'localhost', requiresAuth: true, premium: true, jdbc: true },
|
|
@@ -11,7 +11,7 @@ const DIALECT_DEFAULTS = {
|
|
|
11
11
|
postgres: { host: 'localhost', port: 5432, name: 'mydb', user: 'postgres', password: '' },
|
|
12
12
|
mysql: { host: 'localhost', port: 3306, name: 'mydb', user: 'root', password: '' },
|
|
13
13
|
mariadb: { host: 'localhost', port: 3306, name: 'mydb', user: 'root', password: '' },
|
|
14
|
-
oracle: { host: 'localhost', port: 1521, name: '
|
|
14
|
+
oracle: { host: 'localhost', port: 1521, name: 'XEPDB1', user: 'system', password: '' },
|
|
15
15
|
mssql: { host: 'localhost', port: 1433, name: 'mydb', user: 'sa', password: '' },
|
|
16
16
|
cockroachdb: { host: 'localhost', port: 26257, name: 'mydb', user: 'root', password: '' },
|
|
17
17
|
db2: { host: 'localhost', port: 50000, name: 'mydb', user: 'db2inst1', password: '' },
|
|
@@ -27,7 +27,7 @@ const DIALECT_INFO = [
|
|
|
27
27
|
{ key: 'mysql', name: 'MySQL', icon: '🐬' },
|
|
28
28
|
{ key: 'mariadb', name: 'MariaDB', icon: '🦭' },
|
|
29
29
|
{ key: 'mssql', name: 'SQL Server', icon: '🟦' },
|
|
30
|
-
{ key: 'oracle', name: 'Oracle', icon: '🔴'
|
|
30
|
+
{ key: 'oracle', name: 'Oracle', icon: '🔴' },
|
|
31
31
|
{ key: 'cockroachdb', name: 'CockroachDB', icon: '🪳' },
|
|
32
32
|
{ key: 'db2', name: 'IBM DB2', icon: '🏢', premium: true, jdbc: true },
|
|
33
33
|
{ key: 'hana', name: 'SAP HANA', icon: '💎', premium: true, jdbc: true },
|
|
@@ -35,7 +35,7 @@ const DIALECT_INFO = [
|
|
|
35
35
|
{ key: 'spanner', name: 'Cloud Spanner', icon: '☁️', premium: true },
|
|
36
36
|
{ key: 'sybase', name: 'Sybase ASE', icon: '🔷', premium: true, jdbc: true },
|
|
37
37
|
];
|
|
38
|
-
const JDBC_DIALECTS = ['hsqldb', '
|
|
38
|
+
const JDBC_DIALECTS = ['hsqldb', 'db2', 'hana', 'sybase'];
|
|
39
39
|
const DRIVER_HINTS = {
|
|
40
40
|
mongodb: 'npm install mongoose',
|
|
41
41
|
sqlite: 'npm install better-sqlite3',
|
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ export { MODULES, resolveModuleDependencies } from './data/module-definitions.js
|
|
|
7
7
|
export { discoverNpmModules } from './lib/discover-modules.js';
|
|
8
8
|
export { loadSetupJson } from './lib/load-setup-json.js';
|
|
9
9
|
export type { SetupJson, SetupJsonRbac, SetupJsonSeed, SetupJsonCategory, SetupJsonPermission, SetupJsonRole } from './lib/load-setup-json.js';
|
|
10
|
+
export { createSetupRoutes } from './api/routes.js';
|
|
11
|
+
export type { SetupRoutesConfig } from './api/routes.js';
|
|
10
12
|
export { createTestDbHandler } from './api/test-db.route.js';
|
|
11
13
|
export { createInstallHandler } from './api/install.route.js';
|
|
12
14
|
export { createStatusHandler } from './api/status.route.js';
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,9 @@ export { MODULES, resolveModuleDependencies } from './data/module-definitions.js
|
|
|
11
11
|
// Lib
|
|
12
12
|
export { discoverNpmModules } from './lib/discover-modules.js';
|
|
13
13
|
export { loadSetupJson } from './lib/load-setup-json.js';
|
|
14
|
-
//
|
|
14
|
+
// Catch-all route factory (replaces individual route files in host app)
|
|
15
|
+
export { createSetupRoutes } from './api/routes.js';
|
|
16
|
+
// API route factories (individual — still available for granular use)
|
|
15
17
|
export { createTestDbHandler } from './api/test-db.route.js';
|
|
16
18
|
export { createInstallHandler } from './api/install.route.js';
|
|
17
19
|
export { createStatusHandler } from './api/status.route.js';
|
package/dist/lib/setup.js
CHANGED
|
@@ -40,7 +40,8 @@ export async function runInstall(installConfig, setupConfig) {
|
|
|
40
40
|
port: setupConfig.defaultPort,
|
|
41
41
|
});
|
|
42
42
|
// 2. For JDBC dialects, persist bridge port so app always reconnects to the same bridge
|
|
43
|
-
|
|
43
|
+
// Note: Oracle uses native oracledb driver, not JDBC bridge
|
|
44
|
+
const JDBC_DIALECTS = ['hsqldb', 'db2', 'hana', 'sybase'];
|
|
44
45
|
if (JDBC_DIALECTS.includes(installConfig.dialect)) {
|
|
45
46
|
const bridgePort = process.env.MOSTA_BRIDGE_PORT_BASE || '8765';
|
|
46
47
|
extraVars['MOSTA_BRIDGE_PORT_BASE'] = bridgePort;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mostajs/setup",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Reusable setup wizard module — multi-dialect DB configuration, .env.local writer, seed runner",
|
|
5
5
|
"author": "Dr Hamid MADANI <drmdh@msn.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,6 +43,11 @@
|
|
|
43
43
|
"import": "./dist/components/SetupWizard.js",
|
|
44
44
|
"default": "./dist/components/SetupWizard.js"
|
|
45
45
|
},
|
|
46
|
+
"./api/routes": {
|
|
47
|
+
"types": "./dist/api/routes.d.ts",
|
|
48
|
+
"import": "./dist/api/routes.js",
|
|
49
|
+
"default": "./dist/api/routes.js"
|
|
50
|
+
},
|
|
46
51
|
"./api/reconfig": {
|
|
47
52
|
"types": "./dist/api/reconfig.route.d.ts",
|
|
48
53
|
"import": "./dist/api/reconfig.route.js",
|