This commit is contained in:
seb
2026-07-31 04:48:13 +02:00
parent fdd9e684d8
commit 10d1d472fd
6 changed files with 1035 additions and 959 deletions

View File

@@ -49,35 +49,93 @@ async function shutdown(pool, code = 0) {
process.exit(code);
}
const METHODS = [
{
value: 'setup.company',
label: chalk.cyan('setup company'),
hint: 'email + name + lang',
const MENU = {
setup: {
label: chalk.cyan('setup'),
hint: 'guided flows',
items: [
{ value: 'setup.company', label: 'company', hint: 'email + name + lang' },
],
},
{ value: 'company.create', label: 'company.create', hint: '{name} → id' },
{ value: 'company.list', label: 'company.list', hint: '→ rows' },
{ value: 'company.setDefaultLang', label: 'company.setDefaultLang', hint: 'companyId, langId' },
{ value: 'company.setRootCategory', label: 'company.setRootCategory', hint: 'companyId, categoryId' },
{ value: 'company.delete', label: 'company.delete', hint: 'companyId' },
{ value: 'company.getByCompanyUserId', label: 'company.getByCompanyUserId', hint: 'id → tuple' },
{ value: 'lang.create', label: 'lang.create', hint: 'iso639 → id' },
{ value: 'lang.list', label: 'lang.list', hint: '→ rows' },
{ value: 'lang.delete', label: 'lang.delete', hint: 'id' },
{ value: 'category.create', label: 'category.create', hint: '{parent_id, sort} → id' },
{ value: 'category.updateParentId', label: 'category.updateParentId', hint: 'id, parentId' },
{ value: 'category.delete', label: 'category.delete', hint: 'id' },
{ value: 'category.getTree', label: 'category.getTree', hint: 'rootId → rows' },
{ value: 'companyuser.add', label: 'companyuser.add', hint: 'companyId, authId → id' },
{ value: 'companyuser.delete', label: 'companyuser.delete', hint: 'id' },
{ value: 'companyuser.getByEmail', label: 'companyuser.getByEmail', hint: 'email → ids' },
{ value: 'google_auth.add', label: 'google_auth.add', hint: 'email → authId' },
{ value: 'google_auth.list', label: 'google_auth.list', hint: '→ rows' },
{ value: 'google_auth.del', label: 'google_auth.del', hint: 'id' },
{ value: 'initialize', label: 'initialize', hint: 'ensure schema (no purge)' },
{ value: 'purge', label: chalk.red('purge'), hint: 'drop all · exit' },
{ value: 'exit', label: 'exit', hint: 'quit without purge' },
];
company: {
label: 'company',
items: [
{ value: 'company.create', label: 'create', hint: '{name} → id' },
{ value: 'company.list', label: 'list', hint: '→ rows' },
{ value: 'company.setDefaultLang', label: 'setDefaultLang', hint: 'companyId, langId' },
{ value: 'company.setRootCategory', label: 'setRootCategory', hint: 'companyId, categoryId' },
{ value: 'company.delete', label: 'delete', hint: 'companyId' },
{ value: 'company.getByCompanyUserId', label: 'getByCompanyUserId', hint: 'id → tuple' },
],
},
lang: {
label: 'lang',
items: [
{ value: 'lang.create', label: 'create', hint: 'iso639 → id' },
{ value: 'lang.list', label: 'list', hint: '→ rows' },
{ value: 'lang.delete', label: 'delete', hint: 'id' },
],
},
category: {
label: 'category',
items: [
{ value: 'category.create', label: 'create', hint: '{parent_id, sort} → id' },
{ value: 'category.updateParentId', label: 'updateParentId', hint: 'id, parentId' },
{ value: 'category.delete', label: 'delete', hint: 'id' },
{ value: 'category.getTree', label: 'getTree', hint: 'rootId → rows' },
],
},
companyuser: {
label: 'companyuser',
items: [
{ value: 'companyuser.add', label: 'add', hint: 'companyId, authId → id' },
{ value: 'companyuser.delete', label: 'delete', hint: 'id' },
{ value: 'companyuser.getByEmail', label: 'getByEmail', hint: 'email → ids' },
],
},
google_auth: {
label: 'google_auth',
items: [
{ value: 'google_auth.add', label: 'add', hint: 'email → authId' },
{ value: 'google_auth.list', label: 'list', hint: '→ rows' },
{ value: 'google_auth.del', label: 'del', hint: 'id' },
],
},
schema: {
label: 'schema',
items: [
{ value: 'initialize', label: 'initialize', hint: 'ensure schema (no purge)' },
{ value: 'purge', label: chalk.red('purge'), hint: 'drop all · exit' },
],
},
};
async function pickAction() {
const group = await p.select({
message: 'Group',
options: [
...Object.entries(MENU).map(([value, group]) => ({
value,
label: group.label,
hint: group.hint,
})),
{ value: 'exit', label: 'exit', hint: 'quit without purge' },
],
});
if (p.isCancel(group) || group === 'exit') return 'exit';
const action = await p.select({
message: MENU[group].label,
options: [
...MENU[group].items,
{ value: 'back', label: chalk.dim('← back') },
],
});
if (p.isCancel(action) || action === 'back') return null;
return action;
}
async function runMethod(client, action) {
switch (action) {
@@ -308,16 +366,15 @@ async function main() {
);
while (true) {
const action = await p.select({
message: 'API method',
options: METHODS,
});
const action = await pickAction();
if (p.isCancel(action) || action === 'exit') {
if (action === 'exit') {
p.outro(chalk.dim('Bye'));
await shutdown(pool, 0);
}
if (action == null) continue;
if (action === 'purge') {
const confirm1 = await p.confirm({
message: chalk.red('Drop ALL tables?'),