@cosider.construction/eapp 1.0.3 → 1.0.4
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 +1 -1
- package/src/generators/entity.js +28 -11
- package/src/generators/menu.js +24 -21
- package/src/generators/module.js +8 -7
- package/src/generators/sql.js +118 -0
- package/src/generators/view.js +11 -3
- package/src/index.js +6 -2
- package/src/tui/engine.js +2 -1
- package/src/utils/naming.js +40 -16
package/package.json
CHANGED
package/src/generators/entity.js
CHANGED
|
@@ -28,8 +28,8 @@ const AUDIT_WIDTHS = { field: 20, type: 10 };
|
|
|
28
28
|
|
|
29
29
|
// ─── Code generators ──────────────────────────────────────────────────────────
|
|
30
30
|
|
|
31
|
-
function buildModelJs({ module, entity, schema, fields, auditFields, pkField }) {
|
|
32
|
-
const TABLE = toUpper(entity);
|
|
31
|
+
function buildModelJs({ module, entity, table, schema, fields, auditFields, pkField }) {
|
|
32
|
+
const TABLE = toUpper(table || entity);
|
|
33
33
|
const dbAlias = schema === 'dbo' ? 'dbo' : schema;
|
|
34
34
|
const importPath = module === 'shared' ? '../../../engine/db.js' : '../../engine/db.js';
|
|
35
35
|
|
|
@@ -85,7 +85,7 @@ export async function remove(${pkField}) { return model.remove(${pkField}); }
|
|
|
85
85
|
`;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
function buildIpcJson({ module, entity, schema }) {
|
|
88
|
+
function buildIpcJson({ module, entity, table, schema }) {
|
|
89
89
|
const route = ipcRoute(module, entity);
|
|
90
90
|
const mod = module === 'shared' ? 'shared' : module;
|
|
91
91
|
const ent = toLower(entity);
|
|
@@ -121,9 +121,17 @@ function buildMetaJson({ module, entity, schema, fields, auditFields, pkField })
|
|
|
121
121
|
|
|
122
122
|
// ─── Write entity files ───────────────────────────────────────────────────────
|
|
123
123
|
|
|
124
|
-
async function writeEntity({ module, entity, schema, fields, auditFields, pkField, opts, dryRun }) {
|
|
124
|
+
async function writeEntity({ module, entity, table, schema, fields, auditFields, pkField, opts, dryRun }) {
|
|
125
125
|
const cwd = process.cwd();
|
|
126
|
-
|
|
126
|
+
// If user typed POLE.dbo it means entity=pole, schema=dbo — show confirmation
|
|
127
|
+
const displayPath = `${module}/${entity}` + (parsedTable !== entity ? `:${parsedTable}` : '') + `.${schema}`;
|
|
128
|
+
console.log('');
|
|
129
|
+
console.log(chalk.bold.white(' Entity ') + chalk.cyan(displayPath));
|
|
130
|
+
if (parsedTable !== entity) {
|
|
131
|
+
console.log(chalk.dim(` table name in DB will be: ${toUpper(parsedTable)}`));
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const backendBase = module === 'shared'
|
|
127
135
|
? path.join(cwd, 'src', 'backend', 'shared', toUpper(entity))
|
|
128
136
|
: path.join(cwd, 'src', 'backend', 'modules', toUpper(module), toUpper(entity));
|
|
129
137
|
|
|
@@ -131,7 +139,7 @@ async function writeEntity({ module, entity, schema, fields, auditFields, pkFiel
|
|
|
131
139
|
|
|
132
140
|
if (o.model) {
|
|
133
141
|
await writeFile(path.join(backendBase, 'model.js'),
|
|
134
|
-
buildModelJs({ module, entity, schema, fields, auditFields, pkField }), { dryRun });
|
|
142
|
+
buildModelJs({ module, entity, table: table || entity, schema, fields, auditFields, pkField }), { dryRun });
|
|
135
143
|
}
|
|
136
144
|
if (o.controller) {
|
|
137
145
|
await writeFile(path.join(backendBase, 'controller.js'),
|
|
@@ -139,7 +147,7 @@ async function writeEntity({ module, entity, schema, fields, auditFields, pkFiel
|
|
|
139
147
|
}
|
|
140
148
|
if (o.ipc) {
|
|
141
149
|
await writeFile(path.join(backendBase, 'ipc.json'),
|
|
142
|
-
buildIpcJson({ module, entity, schema }), { dryRun });
|
|
150
|
+
buildIpcJson({ module, entity, table: table || entity, schema }), { dryRun });
|
|
143
151
|
}
|
|
144
152
|
// Always write meta so registry can read it
|
|
145
153
|
await writeJson(path.join(backendBase, 'entity.meta.json'),
|
|
@@ -186,12 +194,21 @@ export async function generateEntity(args, rawArgs) {
|
|
|
186
194
|
catch (e) { log.error(e.message); process.exit(1); }
|
|
187
195
|
}
|
|
188
196
|
|
|
189
|
-
const { module, entity, schema } = parsed;
|
|
197
|
+
const { module, entity, table: parsedTable, schema } = parsed;
|
|
190
198
|
const pkField = `${entity}_id`;
|
|
199
|
+
let tableOverride = parsedTable !== entity ? parsedTable : null;
|
|
191
200
|
|
|
192
201
|
// ── Check if exists ───────────────────────────────────────────────────────
|
|
193
202
|
const cwd = process.cwd();
|
|
194
|
-
|
|
203
|
+
// If user typed POLE.dbo it means entity=pole, schema=dbo — show confirmation
|
|
204
|
+
const displayPath = `${module}/${entity}` + (parsedTable !== entity ? `:${parsedTable}` : '') + `.${schema}`;
|
|
205
|
+
console.log('');
|
|
206
|
+
console.log(chalk.bold.white(' Entity ') + chalk.cyan(displayPath));
|
|
207
|
+
if (parsedTable !== entity) {
|
|
208
|
+
console.log(chalk.dim(` table name in DB will be: ${toUpper(parsedTable)}`));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const backendBase = module === 'shared'
|
|
195
212
|
? path.join(cwd, 'src', 'backend', 'shared', toUpper(entity))
|
|
196
213
|
: path.join(cwd, 'src', 'backend', 'modules', toUpper(module), toUpper(entity));
|
|
197
214
|
|
|
@@ -204,7 +221,7 @@ export async function generateEntity(args, rawArgs) {
|
|
|
204
221
|
// ── --default: skip all prompts ───────────────────────────────────────────
|
|
205
222
|
if (useDefault) {
|
|
206
223
|
await writeEntity({
|
|
207
|
-
module, entity, schema,
|
|
224
|
+
module, entity, table: parsedTable || entity, schema,
|
|
208
225
|
fields: defaultFillableRows(entity),
|
|
209
226
|
auditFields: DEFAULT_AUDIT_ROWS,
|
|
210
227
|
pkField,
|
|
@@ -246,7 +263,7 @@ export async function generateEntity(args, rawArgs) {
|
|
|
246
263
|
const resolvedPk = pkRow ? pkRow.field : pkField;
|
|
247
264
|
|
|
248
265
|
await writeEntity({
|
|
249
|
-
module, entity, schema,
|
|
266
|
+
module, entity, table: tableOverride || entity, schema,
|
|
250
267
|
fields: fillableRows,
|
|
251
268
|
auditFields: auditRows,
|
|
252
269
|
pkField: resolvedPk,
|
package/src/generators/menu.js
CHANGED
|
@@ -12,11 +12,12 @@ function flattenItems(items = [], parentLabel = '') {
|
|
|
12
12
|
const rows = [];
|
|
13
13
|
for (const item of items) {
|
|
14
14
|
rows.push({
|
|
15
|
-
label: item.label
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
label: item.label || '',
|
|
16
|
+
icon: item.icon || '',
|
|
17
|
+
path: parentLabel,
|
|
18
|
+
route: item.route || '',
|
|
19
|
+
dot: item.dot ? 'on' : 'off',
|
|
20
|
+
nbr: item.nbr || '',
|
|
20
21
|
});
|
|
21
22
|
if (item.children?.length) {
|
|
22
23
|
rows.push(...flattenItems(item.children, item.label));
|
|
@@ -28,17 +29,19 @@ function flattenItems(items = [], parentLabel = '') {
|
|
|
28
29
|
// ─── Rebuild nested menu items from flat rows ─────────────────────────────────
|
|
29
30
|
|
|
30
31
|
function nestItems(rows) {
|
|
31
|
-
const top = rows.filter(r => !r.
|
|
32
|
-
const children = rows.filter(r =>
|
|
32
|
+
const top = rows.filter(r => !r.path);
|
|
33
|
+
const children = rows.filter(r => r.path);
|
|
33
34
|
|
|
34
35
|
return top.map(r => {
|
|
35
|
-
const item = { label: r.label,
|
|
36
|
-
if (r.
|
|
37
|
-
|
|
36
|
+
const item = { label: r.label, icon: r.icon, route: r.route };
|
|
37
|
+
if (r.dot === 'on') item.dot = true;
|
|
38
|
+
if (r.nbr) item.nbr = r.nbr;
|
|
39
|
+
const kids = children.filter(c => c.path === r.label);
|
|
38
40
|
if (kids.length) {
|
|
39
41
|
item.children = kids.map(c => ({
|
|
40
|
-
label: c.label,
|
|
41
|
-
...(c.
|
|
42
|
+
label: c.label, icon: c.icon, route: c.route,
|
|
43
|
+
...(c.dot === 'on' ? { dot: true } : {}),
|
|
44
|
+
...(c.nbr ? { nbr: c.nbr } : {}),
|
|
42
45
|
}));
|
|
43
46
|
}
|
|
44
47
|
return item;
|
|
@@ -59,7 +62,7 @@ async function editViewMenu(menuFile, existing) {
|
|
|
59
62
|
// Classic — same item table as module menu
|
|
60
63
|
const existing_items = flattenItems(existing?.hMenu?.items || []);
|
|
61
64
|
if (!existing_items.length) {
|
|
62
|
-
existing_items.push({ label: 'Action',
|
|
65
|
+
existing_items.push({ label: 'Action', icon: '', path: '', route: '', dot: 'off', nbr: '' });
|
|
63
66
|
}
|
|
64
67
|
console.log('');
|
|
65
68
|
const rows = await fieldsTable(
|
|
@@ -185,14 +188,14 @@ export async function generateMenu(args, rawArgs) {
|
|
|
185
188
|
console.log(chalk.bold.white(` ${toPascal(module)} — hMenu`));
|
|
186
189
|
const hRows = flattenItems(existing.hMenu?.items || []);
|
|
187
190
|
if (!hRows.length) {
|
|
188
|
-
hRows.push({ label: `${toPascal(module)} Home`, route: `/${module}`,
|
|
191
|
+
hRows.push({ label: `${toPascal(module)} Home`, icon: '', path: '', route: `/${module}`, dot: 'off', nbr: '' });
|
|
189
192
|
}
|
|
190
193
|
|
|
191
194
|
const updatedH = await fieldsTable(
|
|
192
195
|
hRows,
|
|
193
|
-
['label', '
|
|
194
|
-
{ label: 16,
|
|
195
|
-
'hMenu (
|
|
196
|
+
['label', 'icon', 'path', 'route', 'dot', 'nbr'],
|
|
197
|
+
{ label: 16, icon: 5, path: 14, route: 20, dot: 5, nbr: 6 },
|
|
198
|
+
'hMenu (path = parent group label, dot = show dot indicator, nbr = badge)'
|
|
196
199
|
);
|
|
197
200
|
|
|
198
201
|
// Pass 2 — vMenu
|
|
@@ -200,14 +203,14 @@ export async function generateMenu(args, rawArgs) {
|
|
|
200
203
|
console.log(chalk.bold.white(` ${toPascal(module)} — vMenu`));
|
|
201
204
|
const vRows = flattenItems(existing.vMenu?.items || []);
|
|
202
205
|
if (!vRows.length) {
|
|
203
|
-
vRows.push({ label: toPascal(module), route: `/${module}`,
|
|
206
|
+
vRows.push({ label: toPascal(module), icon: '', path: '', route: `/${module}`, dot: 'off', nbr: '' });
|
|
204
207
|
}
|
|
205
208
|
|
|
206
209
|
const updatedV = await fieldsTable(
|
|
207
210
|
vRows,
|
|
208
|
-
['label', '
|
|
209
|
-
{ label: 16,
|
|
210
|
-
'vMenu (
|
|
211
|
+
['label', 'icon', 'path', 'route', 'dot', 'nbr'],
|
|
212
|
+
{ label: 16, icon: 5, path: 14, route: 20, dot: 5, nbr: 6 },
|
|
213
|
+
'vMenu (path = collapsible group label, dot = show dot indicator, nbr = badge)'
|
|
211
214
|
);
|
|
212
215
|
|
|
213
216
|
// Also check hMenu style
|
package/src/generators/module.js
CHANGED
|
@@ -121,7 +121,7 @@ export async function generateModule(args, rawArgs) {
|
|
|
121
121
|
return {
|
|
122
122
|
module: lower,
|
|
123
123
|
layout: `${toPascal(lower)}Layout`,
|
|
124
|
-
|
|
124
|
+
hmenu: 'own',
|
|
125
125
|
home: 'on',
|
|
126
126
|
grid: 'on',
|
|
127
127
|
};
|
|
@@ -138,7 +138,7 @@ export async function generateModule(args, rawArgs) {
|
|
|
138
138
|
newName = toLower(newName.trim());
|
|
139
139
|
if (!isValidName(newName)) { log.error('Invalid module name.'); process.exit(1); }
|
|
140
140
|
if (!existing.find(e => toLower(e) === newName)) {
|
|
141
|
-
rows.push({ module: newName, layout: `${toPascal(newName)}Layout`,
|
|
141
|
+
rows.push({ module: newName, layout: `${toPascal(newName)}Layout`, hmenu: 'own', home: 'on', grid: '3x2' });
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
|
|
@@ -146,17 +146,18 @@ export async function generateModule(args, rawArgs) {
|
|
|
146
146
|
console.log('');
|
|
147
147
|
const updated = await fieldsTable(
|
|
148
148
|
rows,
|
|
149
|
-
['module', 'layout', '
|
|
150
|
-
{ module: 14, layout: 18,
|
|
151
|
-
'Modules (
|
|
149
|
+
['module', 'layout', 'hmenu', 'home', 'grid'],
|
|
150
|
+
{ module: 14, layout: 18, hmenu: 8, home: 6, grid: 8 },
|
|
151
|
+
'Modules (hmenu: own|share|none home: on|off grid: 0 or NxM e.g. 3x2 enter to save)'
|
|
152
152
|
);
|
|
153
153
|
|
|
154
154
|
// ── Write new/updated modules ──────────────────────────────────────────────
|
|
155
155
|
for (const row of updated) {
|
|
156
156
|
const name = toLower(row.module);
|
|
157
157
|
const hasHome = row.home !== 'off';
|
|
158
|
-
const
|
|
159
|
-
const
|
|
158
|
+
const gridVal = row.grid || '0'; // '0' = no grid, 'NxM' = N cols x M rows
|
|
159
|
+
const hasGrid = gridVal !== '0' && gridVal !== 'off';
|
|
160
|
+
const hMenuScope = row.hmenu || 'own'; // own | share | none
|
|
160
161
|
const layoutName = row.layout || `${toPascal(name)}Layout`;
|
|
161
162
|
|
|
162
163
|
const backendDir = path.join(cwd, 'src', 'backend', 'modules', toUpper(name));
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import { toUpper, toLower, toPascal } from '../utils/naming.js';
|
|
5
|
+
import { writeFile, assertProjectRoot, loadEntityRegistry } from '../utils/fs.js';
|
|
6
|
+
import { log } from '../utils/log.js';
|
|
7
|
+
import { radioLine, textInput } from '../tui/engine.js';
|
|
8
|
+
|
|
9
|
+
// ─── SQL generators ───────────────────────────────────────────────────────────
|
|
10
|
+
|
|
11
|
+
function sqlTypeMap(appType) {
|
|
12
|
+
const map = {
|
|
13
|
+
varchar: 'NVARCHAR(255)',
|
|
14
|
+
int: 'INT',
|
|
15
|
+
decimal: 'DECIMAL(18,2)',
|
|
16
|
+
date: 'DATE',
|
|
17
|
+
datetime: 'DATETIME2',
|
|
18
|
+
bit: 'BIT',
|
|
19
|
+
text: 'NVARCHAR(MAX)',
|
|
20
|
+
float: 'FLOAT',
|
|
21
|
+
enum: 'NVARCHAR(50)',
|
|
22
|
+
};
|
|
23
|
+
return map[appType] || 'NVARCHAR(255)';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function buildCreateTable({ entity, table, schema, fields, auditFields, pkField }) {
|
|
27
|
+
const TABLE = toUpper(table || entity);
|
|
28
|
+
const SCHEMA = schema || 'dbo';
|
|
29
|
+
const allCols = [...(fields || []), ...(auditFields || [])];
|
|
30
|
+
|
|
31
|
+
const colLines = allCols.map(f => {
|
|
32
|
+
const nullable = f.pk ? 'NOT NULL' : 'NULL';
|
|
33
|
+
const identity = f.pk ? ' IDENTITY(1,1)' : '';
|
|
34
|
+
return ` [${f.field}] ${sqlTypeMap(f.type)}${identity} ${nullable}`;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const pkLine = ` CONSTRAINT [PK_${TABLE}] PRIMARY KEY ([${pkField || `${entity}_id`}])`;
|
|
38
|
+
|
|
39
|
+
return `-- Generated by eapp — ${new Date().toISOString().slice(0, 10)}
|
|
40
|
+
-- Entity : ${toLower(entity)}
|
|
41
|
+
-- Table : [${SCHEMA}].[${TABLE}]
|
|
42
|
+
|
|
43
|
+
CREATE TABLE [${SCHEMA}].[${TABLE}] (
|
|
44
|
+
${[...colLines, pkLine].join(',\n')}
|
|
45
|
+
);
|
|
46
|
+
GO
|
|
47
|
+
`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function buildAlterTable({ entity, table, schema, fields }) {
|
|
51
|
+
const TABLE = toUpper(table || entity);
|
|
52
|
+
const SCHEMA = schema || 'dbo';
|
|
53
|
+
|
|
54
|
+
const lines = (fields || []).map(f =>
|
|
55
|
+
`ALTER TABLE [${SCHEMA}].[${TABLE}] ADD [${f.field}] ${sqlTypeMap(f.type)} NULL;`
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
return `-- Alter: add missing columns to [${SCHEMA}].[${TABLE}]
|
|
59
|
+
${lines.join('\n')}
|
|
60
|
+
GO
|
|
61
|
+
`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ─── Main generator ───────────────────────────────────────────────────────────
|
|
65
|
+
|
|
66
|
+
export async function generateSql(args, rawArgs) {
|
|
67
|
+
assertProjectRoot();
|
|
68
|
+
|
|
69
|
+
const cwd = process.cwd();
|
|
70
|
+
const registry = await loadEntityRegistry(cwd);
|
|
71
|
+
|
|
72
|
+
if (!registry.size) {
|
|
73
|
+
log.warn('No entities found. Run eapp entity first.');
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Pick entity from registry
|
|
78
|
+
const entries = [...registry.entries()];
|
|
79
|
+
console.log('');
|
|
80
|
+
console.log(chalk.bold.white(' Generate SQL for entity'));
|
|
81
|
+
const key = await textInput('module/entity (or "all"):');
|
|
82
|
+
|
|
83
|
+
const targets = key.trim() === 'all'
|
|
84
|
+
? entries
|
|
85
|
+
: entries.filter(([k]) => k.endsWith(key.trim().toLowerCase()) || k === key.trim().toLowerCase());
|
|
86
|
+
|
|
87
|
+
if (!targets.length) {
|
|
88
|
+
log.error(`Entity "${key}" not found in registry.`);
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Pick statement type
|
|
93
|
+
console.log('');
|
|
94
|
+
console.log(chalk.bold.white(' Statement type'));
|
|
95
|
+
const stmtType = await radioLine('', [
|
|
96
|
+
{ label: 'CREATE TABLE', value: 'create' },
|
|
97
|
+
{ label: 'ALTER (add cols)', value: 'alter' },
|
|
98
|
+
]);
|
|
99
|
+
|
|
100
|
+
const sqlDir = path.join(cwd, 'src', 'backend', 'sql');
|
|
101
|
+
await fs.ensureDir(sqlDir);
|
|
102
|
+
|
|
103
|
+
for (const [, meta] of targets) {
|
|
104
|
+
const { module, entity, table, schema, fields, auditFields, pkField } = meta;
|
|
105
|
+
const fileName = stmtType === 'create'
|
|
106
|
+
? `${schema}_${toUpper(table || entity)}_create.sql`
|
|
107
|
+
: `${schema}_${toUpper(table || entity)}_alter.sql`;
|
|
108
|
+
const filePath = path.join(sqlDir, fileName);
|
|
109
|
+
const content = stmtType === 'create'
|
|
110
|
+
? buildCreateTable({ entity, table, schema, fields, auditFields, pkField })
|
|
111
|
+
: buildAlterTable({ entity, table, schema, fields });
|
|
112
|
+
|
|
113
|
+
await writeFile(filePath, content);
|
|
114
|
+
log.success(`${fileName}`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
log.info(`SQL files written to src/backend/sql/`);
|
|
118
|
+
}
|
package/src/generators/view.js
CHANGED
|
@@ -349,11 +349,19 @@ export async function generateView(args, rawArgs) {
|
|
|
349
349
|
defaultComps,
|
|
350
350
|
COMP_COLS,
|
|
351
351
|
COMP_WIDTHS,
|
|
352
|
-
'Components (+ add - remove
|
|
352
|
+
'Components (+ add - remove \u2190 \u2192 cols space menu toggle enter done)'
|
|
353
353
|
);
|
|
354
354
|
|
|
355
|
-
|
|
356
|
-
|
|
355
|
+
// List render mode — explicit radio (table / card / both) so user can't mistype
|
|
356
|
+
console.log('');
|
|
357
|
+
console.log(chalk.bold.white(' List render'));
|
|
358
|
+
const listRender = await radioLine('', [
|
|
359
|
+
{ label: 'Table (row)', value: 'table' },
|
|
360
|
+
{ label: 'Card', value: 'card' },
|
|
361
|
+
{ label: 'Both', value: 'both' },
|
|
362
|
+
]);
|
|
363
|
+
const hasRow = listRender === 'table' || listRender === 'both';
|
|
364
|
+
const hasCard = listRender === 'card' || listRender === 'both';
|
|
357
365
|
|
|
358
366
|
// ── Step 4: slaves ────────────────────────────────────────────────────────
|
|
359
367
|
let slaveConfigs = [];
|
package/src/index.js
CHANGED
|
@@ -41,11 +41,12 @@ Options:
|
|
|
41
41
|
|
|
42
42
|
const MAIN_MENU = [
|
|
43
43
|
{ label: 'Entity', value: 'entity' },
|
|
44
|
+
{ label: 'Pivot', value: 'pivot' },
|
|
44
45
|
{ label: 'View', value: 'view' },
|
|
45
46
|
{ label: 'Module', value: 'module' },
|
|
46
47
|
{ label: 'Menu', value: 'menu' },
|
|
48
|
+
{ label: 'Sql', value: 'sql' },
|
|
47
49
|
{ label: 'Config', value: 'config' },
|
|
48
|
-
{ label: 'Pivot', value: 'pivot' },
|
|
49
50
|
{ label: 'Layout', value: 'layout' },
|
|
50
51
|
{ label: 'List', value: 'list' },
|
|
51
52
|
{ label: 'Quit', value: 'quit' },
|
|
@@ -72,7 +73,10 @@ async function launchInteractive() {
|
|
|
72
73
|
break;
|
|
73
74
|
}
|
|
74
75
|
|
|
75
|
-
if (chosen === '
|
|
76
|
+
if (chosen === 'sql') {
|
|
77
|
+
const { generateSql } = await import('./generators/sql.js');
|
|
78
|
+
await generateSql([], []);
|
|
79
|
+
} else if (chosen === 'list') {
|
|
76
80
|
await listModules();
|
|
77
81
|
console.log('');
|
|
78
82
|
await listEntities([]);
|
package/src/tui/engine.js
CHANGED
|
@@ -161,8 +161,9 @@ const BOOL_COLS = new Set(['pk', 'fk']);
|
|
|
161
161
|
// Columns where space cycles between string values
|
|
162
162
|
const CYCLE_COLS = {
|
|
163
163
|
vmenu: ['own', 'share'],
|
|
164
|
+
hmenu: ['own', 'share', 'none'],
|
|
164
165
|
home: ['on', 'off'],
|
|
165
|
-
grid
|
|
166
|
+
// 'grid' is free-text (NxM), not cycled
|
|
166
167
|
};
|
|
167
168
|
|
|
168
169
|
// Strip ANSI escape codes to get the true printable length of a string.
|
package/src/utils/naming.js
CHANGED
|
@@ -27,15 +27,25 @@ export function parseEntityPath(input) {
|
|
|
27
27
|
|
|
28
28
|
let raw = input.trim();
|
|
29
29
|
|
|
30
|
-
// Handle
|
|
30
|
+
// Handle dot notation ONLY when the part before the dot could be a module name
|
|
31
|
+
// and the part after is NOT a schema keyword (dbo, etc.) — i.e. "rh.employee" → "rh/employee"
|
|
32
|
+
// BUT "POLE.dbo" must NOT be rewritten — POLE is the entity, dbo is the schema.
|
|
33
|
+
// Rule: rewrite "x.y" only when x contains no uppercase and y is not a known schema.
|
|
34
|
+
const SCHEMA_NAMES = new Set(['dbo', 'dbo2', 'hr', 'rh', 'stk', 'fin', 'crm', 'adm', 'sec', 'shared']);
|
|
31
35
|
if (!raw.includes('/') && raw.includes('.') && raw.split('.').length === 2) {
|
|
32
|
-
const [
|
|
33
|
-
|
|
36
|
+
const [left, right] = raw.split('.');
|
|
37
|
+
const looksLikeSchema = SCHEMA_NAMES.has(right.toLowerCase()) || /^[a-z]+$/.test(right);
|
|
38
|
+
const looksLikeModule = /^[a-z][a-z0-9_-]*$/.test(left);
|
|
39
|
+
// Only rewrite if left looks like a lowercase module AND right does NOT look like a schema
|
|
40
|
+
if (looksLikeModule && !looksLikeSchema) {
|
|
41
|
+
raw = `${left}/${right}`;
|
|
42
|
+
}
|
|
34
43
|
}
|
|
35
44
|
|
|
36
45
|
// No slash at all → shared
|
|
37
46
|
if (!raw.includes('/')) {
|
|
38
|
-
|
|
47
|
+
const _e = toLower(raw);
|
|
48
|
+
return { module: 'shared', entity: _e, table: _e, schema: 'dbo' };
|
|
39
49
|
}
|
|
40
50
|
|
|
41
51
|
// Split on /
|
|
@@ -49,20 +59,34 @@ export function parseEntityPath(input) {
|
|
|
49
59
|
const dotIdx = rest.indexOf('.');
|
|
50
60
|
let entity, schema;
|
|
51
61
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
62
|
+
// Also parse optional table alias: entity:tableName
|
|
63
|
+
// e.g. rh/agent:agentx.dbo → entity=agent, table=agentx, schema=dbo
|
|
64
|
+
let tableAlias = null;
|
|
65
|
+
if (rest.includes(':')) {
|
|
66
|
+
const colonIdx = rest.indexOf(':');
|
|
67
|
+
tableAlias = rest.slice(colonIdx + 1).split('.')[0]; // strip schema part
|
|
68
|
+
// rewrite rest without the alias for further parsing
|
|
69
|
+
// keep the .schema part after the alias if any
|
|
70
|
+
const afterColon = rest.slice(colonIdx + 1);
|
|
71
|
+
const schemaInAlias = afterColon.includes('.') ? afterColon.slice(afterColon.indexOf('.')) : '';
|
|
72
|
+
// rest becomes "entity.schema"
|
|
73
|
+
// rest = rest.slice(0, colonIdx) + schemaInAlias; — handled below
|
|
74
|
+
}
|
|
75
|
+
const cleanRest = rest.replace(/:([^.]+)/, ''); // strip :alias for entity/schema parsing
|
|
76
|
+
|
|
77
|
+
const dotIdx2 = cleanRest.indexOf('.');
|
|
78
|
+
let entity, schema;
|
|
79
|
+
if (dotIdx2 === -1) {
|
|
80
|
+
entity = toLower(cleanRest);
|
|
55
81
|
schema = module === 'shared' ? 'dbo' : module;
|
|
56
82
|
} else {
|
|
57
|
-
entity = toLower(
|
|
58
|
-
const schemaPart =
|
|
59
|
-
|
|
60
|
-
// Trailing dot → schema = module
|
|
61
|
-
schema = module === 'shared' ? 'dbo' : module;
|
|
62
|
-
} else {
|
|
63
|
-
schema = toLower(schemaPart);
|
|
64
|
-
}
|
|
83
|
+
entity = toLower(cleanRest.slice(0, dotIdx2));
|
|
84
|
+
const schemaPart = cleanRest.slice(dotIdx2 + 1);
|
|
85
|
+
schema = schemaPart === '' ? (module === 'shared' ? 'dbo' : module) : toLower(schemaPart);
|
|
65
86
|
}
|
|
87
|
+
const table = tableAlias ? toLower(tableAlias) : entity;
|
|
88
|
+
// (keep legacy variable for code below that uses dotIdx)
|
|
89
|
+
const dotIdx = dotIdx2;
|
|
66
90
|
|
|
67
91
|
if (!isValidName(entity)) {
|
|
68
92
|
throw new Error(`Invalid entity name "${entity}". Use alphanumeric, hyphens, underscores only.`);
|
|
@@ -71,7 +95,7 @@ export function parseEntityPath(input) {
|
|
|
71
95
|
throw new Error(`Invalid module name "${module}".`);
|
|
72
96
|
}
|
|
73
97
|
|
|
74
|
-
return { module, entity, schema };
|
|
98
|
+
return { module, entity, table: table || entity, schema };
|
|
75
99
|
}
|
|
76
100
|
|
|
77
101
|
/**
|