@intecoag/inteco-cli 0.5.1 → 1.0.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.
@@ -1,226 +1,226 @@
1
- import { DB } from "../utils/db/DB.js";
2
- import prompts from "prompts";
3
- import CliTable3 from "cli-table3";
4
- import readline from "readline";
5
- import chalk from "chalk";
6
- import fuzzysort from "fuzzysort";
7
-
8
- // Entry point
9
- export default async function extdSearch() {
10
- const responses = await configureDB();
11
-
12
- if (!responses.dbName) return;
13
-
14
- let currentSearchType = configs[0];
15
- let lastQuery = '';
16
-
17
- const baseData = await loadData(responses.dbName, responses.tables);
18
- const rl = createReadline();
19
-
20
- console.log(chalk.green("Interactive Search Started."));
21
- rl.prompt();
22
-
23
- rl.on('line', async (input) => {
24
- const query = input.trim();
25
-
26
- if (handleBuiltInCommands(query, rl)) return;
27
-
28
- const matchedConfig = configs.find(c => query === `:${c.cmd}`);
29
- if (matchedConfig) {
30
- currentSearchType = matchedConfig;
31
- } else {
32
- lastQuery = query;
33
- }
34
-
35
- const results = await fuzzySearch(baseData, lastQuery, currentSearchType);
36
- renderTable(results, currentSearchType);
37
- rl.prompt();
38
- });
39
-
40
- rl.on('close', () => {
41
- console.log(chalk.yellow("Search session ended."));
42
- process.exit(0);
43
- });
44
- }
45
-
46
- function createReadline() {
47
- return readline.createInterface({
48
- input: process.stdin,
49
- output: process.stdout,
50
- prompt: 'Search query (show help with :?)> '
51
- });
52
- }
53
-
54
- function handleBuiltInCommands(query, rl) {
55
- switch (query) {
56
- case ':q':
57
- rl.close();
58
- return true;
59
- case ':?':
60
- printHelp();
61
- rl.prompt();
62
- return true;
63
- default:
64
- return false;
65
- }
66
- }
67
-
68
- function printHelp() {
69
- console.log("\n" + chalk.cyan("Available Commands:"));
70
- console.log(chalk.yellow(":q") + " - Exit the application");
71
- console.log(chalk.yellow(":?") + " - Show this help");
72
- configs.forEach(config =>
73
- console.log(`${chalk.yellow(`:${config.cmd}`)} - Switch to ${config.name}`)
74
- );
75
- console.log();
76
- }
77
-
78
- async function configureDB() {
79
- console.log();
80
- const databaseNames = await DB.getDatabaseNames();
81
-
82
- return await prompts([
83
- {
84
- type: 'autocomplete',
85
- name: 'dbName',
86
- message: 'DB-Name?',
87
- choices: databaseNames.map(db => ({ title: db.name }))
88
- },
89
- {
90
- type: 'select',
91
- name: 'tables',
92
- message: 'Search-Type?',
93
- choices: [
94
- { title: 'EXTD/EXTI', value: 'EXTD/EXTI' },
95
- { title: 'EXTI only', value: 'EXTI' },
96
- { title: 'EXTD only', value: 'EXTD' }
97
- ]
98
- }
99
- ], {
100
- onCancel: () => {
101
- console.log("\n" + chalk.red("Cancelled Search!\n"));
102
- }
103
- });
104
- }
105
-
106
- async function loadData(db, tableChoice) {
107
- const extd = await getTableData('extd', db);
108
- const exti = await getTableData('exti', db);
109
-
110
- const cleaned = [
111
- ...cleanData(extd, 'extd'),
112
- ...cleanData(exti, 'exti')
113
- ];
114
-
115
- if (tableChoice === 'EXTD') return cleaned.filter(e => e.table === 'extd');
116
- if (tableChoice === 'EXTI') return cleaned.filter(e => e.table === 'exti');
117
- return cleaned;
118
- }
119
-
120
- function cleanData(entries, tableName) {
121
- return entries.map(entry => {
122
- const stripped = Object.fromEntries(Object.entries(entry).map(([k, v]) => {
123
- return [k.replace(/^ext[di]_/, ''), v];
124
- }));
125
- return { ...stripped, table: tableName };
126
- });
127
- }
128
-
129
- async function getTableData(table, db) {
130
- const query = `SELECT * FROM ${table};`;
131
- return await DB.executeQueryOnDB(query, db);
132
- }
133
-
134
- async function fuzzySearch(data, query, config) {
135
- if (!query) return data.slice(0, 1000);
136
- return fuzzysort.go(query, data, {
137
- keys: config.searchKeys,
138
- limit: 1000,
139
- threshold: config.threshold
140
- }).map(r => ({ ...r.obj, score: r.score }));
141
- }
142
-
143
- function renderTable(data, config) {
144
- const table = new CliTable3({ head: config.tableHeader });
145
- data.forEach(row => table.push(config.tableFormatter(row)));
146
- console.log(table.toString());
147
- }
148
-
149
- // ---------- Configurations & Helpers ----------
150
-
151
- const configs = [
152
- {
153
- name: "Overview",
154
- cmd: "ow",
155
- searchKeys: ['name', 'bez_d', 'bez_f', 'bez_i'],
156
- threshold: 0.7,
157
- tableHeader: ['Table', 'Name', 'Bezeichnung Deutsch', 'Bezeichnung Französisch', 'Bezeichnung Italieniesch'],
158
- tableFormatter: p => [p.table, p.name, p.bez_d, p.bez_f, p.bez_i]
159
- },
160
- {
161
- name: "Field-Information",
162
- cmd: "fi",
163
- searchKeys: [
164
- 'name', 'bez_d', 'bez_f', 'bez_i',
165
- 'b_dtext_1', 'b_dtext_2', 'b_dtext_3',
166
- 'b_dtext_4', 'b_dtext_5', 'b_dtext_6',
167
- 'b_dtext_7', 'b_dtext_8', 'b_dtext_9'
168
- ],
169
- threshold: 0.7,
170
- tableHeader: ['Table', 'Name', 'Feldtyp', 'Flag', 'Testflag', 'Wert 1', 'Wert 2', 'Wert 3', 'Wert 4', 'Wert 5', 'Wert 6', 'Wert 7', 'Wert 8', 'Wert 9'],
171
- tableFormatter: p => [
172
- p.table, p.name,
173
- formatFieldType(p.special),
174
- formatFlag(p.flag),
175
- formatTestFlag(p.testflag),
176
- ...Array.from({ length: 9 }, (_, i) => formatWert(p[`b_value_${i + 1}`], p[`b_dtext_${i + 1}`]))
177
- ]
178
- },
179
- {
180
- name: "Disp-Fields",
181
- cmd: "df",
182
- searchKeys: [
183
- 'name', 'bez_d', 'testfeld',
184
- 'disp_feld_1', 'disp_feld_2', 'disp_feld_3',
185
- 'disp_feld_4', 'disp_feld_5', 'disp_feld_6',
186
- 'disp_feld_7', 'disp_feld_8', 'disp_feld_9'
187
- ],
188
- threshold: 0.7,
189
- tableHeader: ['Table', 'Name', 'Test-Feld', 'Dispmask', 'Dispfeld 1', 'Dispfeld 2', 'Dispfeld 3', 'Dispfeld 4', 'Dispfeld 5', 'Dispfeld 6', 'Dispfeld 7', 'Dispfeld 8', 'Dispfeld 9'],
190
- tableFormatter: p => [
191
- p.table, p.name, p.testfeld, p.dispmask,
192
- p.disp_feld_1, p.disp_feld_2, p.disp_feld_3,
193
- p.disp_feld_4, p.disp_feld_5, p.disp_feld_6,
194
- p.disp_feld_7, p.disp_feld_8, p.disp_feld_9
195
- ]
196
- }
197
- ];
198
-
199
- function formatWert(value, bez) {
200
- return value || bez ? `'${value}'='${bez}'` : '';
201
- }
202
-
203
- function formatFieldType(type) {
204
- return {
205
- '0': 'Custom',
206
- '1': 'Checkbox',
207
- '2': 'Radiobutton',
208
- '4': 'Text'
209
- }[type] || '';
210
- }
211
-
212
- function formatFlag(flag) {
213
- return {
214
- '0': 'Optional',
215
- '1': 'Zwingend',
216
- '2': 'Aus',
217
- '3': 'Dialog aus'
218
- }[flag] || '';
219
- }
220
-
221
- function formatTestFlag(flag) {
222
- return {
223
- '0': 'Zwingend',
224
- '1': 'Null/Space erlaubt'
225
- }[flag] || '';
226
- }
1
+ import { DB } from "../utils/db/DB.js";
2
+ import prompts from "prompts";
3
+ import CliTable3 from "cli-table3";
4
+ import readline from "readline";
5
+ import chalk from "chalk";
6
+ import fuzzysort from "fuzzysort";
7
+
8
+ // Entry point
9
+ export default async function extdSearch() {
10
+ const responses = await configureDB();
11
+
12
+ if (!responses.dbName) return;
13
+
14
+ let currentSearchType = configs[0];
15
+ let lastQuery = '';
16
+
17
+ const baseData = await loadData(responses.dbName, responses.tables);
18
+ const rl = createReadline();
19
+
20
+ console.log(chalk.green("Interactive Search Started."));
21
+ rl.prompt();
22
+
23
+ rl.on('line', async (input) => {
24
+ const query = input.trim();
25
+
26
+ if (handleBuiltInCommands(query, rl)) return;
27
+
28
+ const matchedConfig = configs.find(c => query === `:${c.cmd}`);
29
+ if (matchedConfig) {
30
+ currentSearchType = matchedConfig;
31
+ } else {
32
+ lastQuery = query;
33
+ }
34
+
35
+ const results = await fuzzySearch(baseData, lastQuery, currentSearchType);
36
+ renderTable(results, currentSearchType);
37
+ rl.prompt();
38
+ });
39
+
40
+ rl.on('close', () => {
41
+ console.log(chalk.yellow("Search session ended."));
42
+ process.exit(0);
43
+ });
44
+ }
45
+
46
+ function createReadline() {
47
+ return readline.createInterface({
48
+ input: process.stdin,
49
+ output: process.stdout,
50
+ prompt: 'Search query (show help with :?)> '
51
+ });
52
+ }
53
+
54
+ function handleBuiltInCommands(query, rl) {
55
+ switch (query) {
56
+ case ':q':
57
+ rl.close();
58
+ return true;
59
+ case ':?':
60
+ printHelp();
61
+ rl.prompt();
62
+ return true;
63
+ default:
64
+ return false;
65
+ }
66
+ }
67
+
68
+ function printHelp() {
69
+ console.log("\n" + chalk.cyan("Available Commands:"));
70
+ console.log(chalk.yellow(":q") + " - Exit the application");
71
+ console.log(chalk.yellow(":?") + " - Show this help");
72
+ configs.forEach(config =>
73
+ console.log(`${chalk.yellow(`:${config.cmd}`)} - Switch to ${config.name}`)
74
+ );
75
+ console.log();
76
+ }
77
+
78
+ async function configureDB() {
79
+ console.log();
80
+ const databaseNames = await DB.getDatabaseNames();
81
+
82
+ return await prompts([
83
+ {
84
+ type: 'autocomplete',
85
+ name: 'dbName',
86
+ message: 'DB-Name?',
87
+ choices: databaseNames.map(db => ({ title: db.name }))
88
+ },
89
+ {
90
+ type: 'select',
91
+ name: 'tables',
92
+ message: 'Search-Type?',
93
+ choices: [
94
+ { title: 'EXTD/EXTI', value: 'EXTD/EXTI' },
95
+ { title: 'EXTI only', value: 'EXTI' },
96
+ { title: 'EXTD only', value: 'EXTD' }
97
+ ]
98
+ }
99
+ ], {
100
+ onCancel: () => {
101
+ console.log("\n" + chalk.red("Cancelled Search!\n"));
102
+ }
103
+ });
104
+ }
105
+
106
+ async function loadData(db, tableChoice) {
107
+ const extd = await getTableData('extd', db);
108
+ const exti = await getTableData('exti', db);
109
+
110
+ const cleaned = [
111
+ ...cleanData(extd, 'extd'),
112
+ ...cleanData(exti, 'exti')
113
+ ];
114
+
115
+ if (tableChoice === 'EXTD') return cleaned.filter(e => e.table === 'extd');
116
+ if (tableChoice === 'EXTI') return cleaned.filter(e => e.table === 'exti');
117
+ return cleaned;
118
+ }
119
+
120
+ function cleanData(entries, tableName) {
121
+ return entries.map(entry => {
122
+ const stripped = Object.fromEntries(Object.entries(entry).map(([k, v]) => {
123
+ return [k.replace(/^ext[di]_/, ''), v];
124
+ }));
125
+ return { ...stripped, table: tableName };
126
+ });
127
+ }
128
+
129
+ async function getTableData(table, db) {
130
+ const query = `SELECT * FROM ${table};`;
131
+ return await DB.executeQueryOnDB(query, db);
132
+ }
133
+
134
+ async function fuzzySearch(data, query, config) {
135
+ if (!query) return data.slice(0, 1000);
136
+ return fuzzysort.go(query, data, {
137
+ keys: config.searchKeys,
138
+ limit: 1000,
139
+ threshold: config.threshold
140
+ }).map(r => ({ ...r.obj, score: r.score }));
141
+ }
142
+
143
+ function renderTable(data, config) {
144
+ const table = new CliTable3({ head: config.tableHeader });
145
+ data.forEach(row => table.push(config.tableFormatter(row)));
146
+ console.log(table.toString());
147
+ }
148
+
149
+ // ---------- Configurations & Helpers ----------
150
+
151
+ const configs = [
152
+ {
153
+ name: "Overview",
154
+ cmd: "ow",
155
+ searchKeys: ['name', 'bez_d', 'bez_f', 'bez_i'],
156
+ threshold: 0.7,
157
+ tableHeader: ['Table', 'Name', 'Bezeichnung Deutsch', 'Bezeichnung Französisch', 'Bezeichnung Italieniesch'],
158
+ tableFormatter: p => [p.table, p.name, p.bez_d, p.bez_f, p.bez_i]
159
+ },
160
+ {
161
+ name: "Field-Information",
162
+ cmd: "fi",
163
+ searchKeys: [
164
+ 'name', 'bez_d', 'bez_f', 'bez_i',
165
+ 'b_dtext_1', 'b_dtext_2', 'b_dtext_3',
166
+ 'b_dtext_4', 'b_dtext_5', 'b_dtext_6',
167
+ 'b_dtext_7', 'b_dtext_8', 'b_dtext_9'
168
+ ],
169
+ threshold: 0.7,
170
+ tableHeader: ['Table', 'Name', 'Feldtyp', 'Flag', 'Testflag', 'Wert 1', 'Wert 2', 'Wert 3', 'Wert 4', 'Wert 5', 'Wert 6', 'Wert 7', 'Wert 8', 'Wert 9'],
171
+ tableFormatter: p => [
172
+ p.table, p.name,
173
+ formatFieldType(p.special),
174
+ formatFlag(p.flag),
175
+ formatTestFlag(p.testflag),
176
+ ...Array.from({ length: 9 }, (_, i) => formatWert(p[`b_value_${i + 1}`], p[`b_dtext_${i + 1}`]))
177
+ ]
178
+ },
179
+ {
180
+ name: "Disp-Fields",
181
+ cmd: "df",
182
+ searchKeys: [
183
+ 'name', 'bez_d', 'testfeld',
184
+ 'disp_feld_1', 'disp_feld_2', 'disp_feld_3',
185
+ 'disp_feld_4', 'disp_feld_5', 'disp_feld_6',
186
+ 'disp_feld_7', 'disp_feld_8', 'disp_feld_9'
187
+ ],
188
+ threshold: 0.7,
189
+ tableHeader: ['Table', 'Name', 'Test-Feld', 'Dispmask', 'Dispfeld 1', 'Dispfeld 2', 'Dispfeld 3', 'Dispfeld 4', 'Dispfeld 5', 'Dispfeld 6', 'Dispfeld 7', 'Dispfeld 8', 'Dispfeld 9'],
190
+ tableFormatter: p => [
191
+ p.table, p.name, p.testfeld, p.dispmask,
192
+ p.disp_feld_1, p.disp_feld_2, p.disp_feld_3,
193
+ p.disp_feld_4, p.disp_feld_5, p.disp_feld_6,
194
+ p.disp_feld_7, p.disp_feld_8, p.disp_feld_9
195
+ ]
196
+ }
197
+ ];
198
+
199
+ function formatWert(value, bez) {
200
+ return value || bez ? `'${value}'='${bez}'` : '';
201
+ }
202
+
203
+ function formatFieldType(type) {
204
+ return {
205
+ '0': 'Custom',
206
+ '1': 'Checkbox',
207
+ '2': 'Radiobutton',
208
+ '4': 'Text'
209
+ }[type] || '';
210
+ }
211
+
212
+ function formatFlag(flag) {
213
+ return {
214
+ '0': 'Optional',
215
+ '1': 'Zwingend',
216
+ '2': 'Aus',
217
+ '3': 'Dialog aus'
218
+ }[flag] || '';
219
+ }
220
+
221
+ function formatTestFlag(flag) {
222
+ return {
223
+ '0': 'Zwingend',
224
+ '1': 'Null/Space erlaubt'
225
+ }[flag] || '';
226
+ }
@@ -1,61 +1,61 @@
1
- import prompts from "prompts";
2
- import chalk from "chalk";
3
- import graphql from "graphql"
4
- import { writeFileSync, readFileSync, readdirSync, writeFile, unlinkSync, mkdirSync, renameSync, rmSync } from "fs";
5
-
6
- export default async function qraphqlSchemaExport(){
7
- console.log()
8
-
9
- let success = true;
10
-
11
- const responses = await prompts([{
12
- type: 'text',
13
- name: 'url',
14
- message: 'URL?',
15
- initial: "http://localhost:8080/graphql"
16
- },
17
- {
18
- type: 'text',
19
- name: 'token',
20
- message: 'AUTH-Token?'
21
- },
22
- {
23
- type: 'text',
24
- name: 'file',
25
- message: 'File-Name?',
26
- initial: 'schema.graphqls'
27
- }], {
28
- onCancel: () => {
29
- console.log()
30
- console.log(chalk.red("Cancelled GraphQL-Schema-Export!"))
31
- console.log()
32
- success = false
33
- }
34
- })
35
-
36
- if(success){
37
- console.log()
38
-
39
- try{
40
- const {data, errors} = await fetch(responses.url, {
41
- method: "POST",
42
- headers: {
43
- "Content-Type": "application/json",
44
- "Accept": "application/json",
45
- "Authorization": "Bearer "+responses.token
46
- },
47
- body: JSON.stringify({query: graphql.getIntrospectionQuery()})
48
- }).then(res => res.json())
49
-
50
- const schema = graphql.buildClientSchema(data)
51
-
52
-
53
- writeFileSync(responses.file, graphql.printSchema(schema))
54
- console.log(chalk.green("Schema loaded: "+responses.file))
55
- console.log();
56
- }catch(e){
57
- console.log(chalk.red("Error loading schema: "+e))
58
- console.log();
59
- }
60
- }
1
+ import prompts from "prompts";
2
+ import chalk from "chalk";
3
+ import graphql from "graphql"
4
+ import { writeFileSync, readFileSync, readdirSync, writeFile, unlinkSync, mkdirSync, renameSync, rmSync } from "fs";
5
+
6
+ export default async function qraphqlSchemaExport(){
7
+ console.log()
8
+
9
+ let success = true;
10
+
11
+ const responses = await prompts([{
12
+ type: 'text',
13
+ name: 'url',
14
+ message: 'URL?',
15
+ initial: "http://localhost:8080/graphql"
16
+ },
17
+ {
18
+ type: 'text',
19
+ name: 'token',
20
+ message: 'AUTH-Token?'
21
+ },
22
+ {
23
+ type: 'text',
24
+ name: 'file',
25
+ message: 'File-Name?',
26
+ initial: 'schema.graphqls'
27
+ }], {
28
+ onCancel: () => {
29
+ console.log()
30
+ console.log(chalk.red("Cancelled GraphQL-Schema-Export!"))
31
+ console.log()
32
+ success = false
33
+ }
34
+ })
35
+
36
+ if(success){
37
+ console.log()
38
+
39
+ try{
40
+ const {data, errors} = await fetch(responses.url, {
41
+ method: "POST",
42
+ headers: {
43
+ "Content-Type": "application/json",
44
+ "Accept": "application/json",
45
+ "Authorization": "Bearer "+responses.token
46
+ },
47
+ body: JSON.stringify({query: graphql.getIntrospectionQuery()})
48
+ }).then(res => res.json())
49
+
50
+ const schema = graphql.buildClientSchema(data)
51
+
52
+
53
+ writeFileSync(responses.file, graphql.printSchema(schema))
54
+ console.log(chalk.green("Schema loaded: "+responses.file))
55
+ console.log();
56
+ }catch(e){
57
+ console.log(chalk.red("Error loading schema: "+e))
58
+ console.log();
59
+ }
60
+ }
61
61
  }