@cyklang/cli 0.2.2 → 0.3.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.
@@ -30,7 +30,8 @@ const DBClient_1 = require("./DBClient");
30
30
  const fs = __importStar(require("fs"));
31
31
  const path_1 = __importDefault(require("path"));
32
32
  const mime_types_1 = __importDefault(require("mime-types"));
33
- const readline_1 = __importDefault(require("readline"));
33
+ const inquirer_1 = __importDefault(require("inquirer"));
34
+ // import readline from 'readline'
34
35
  const core_1 = require("@cyklang/core");
35
36
  const form_data_1 = __importDefault(require("form-data"));
36
37
  const logger = (0, loglevel_1.getLogger)('AssetCommand.ts');
@@ -59,7 +60,7 @@ class AssetList extends Cmd_1.Cmd {
59
60
  if (this.dbManager === undefined)
60
61
  throw 'dbManager undefined';
61
62
  const dbClient = new DBClient_1.DBClient(this.dbManager);
62
- dbClient.selectFromTable('List of Assets', 'cyk_asset', { fields: 'asset_id,asset_route,asset_last_update,asset_mimetype', sort: options.sort || '1' });
63
+ dbClient.selectFromTable('List of Assets', 'cyk_asset', { fields: 'asset_id,asset_route,asset_auth,asset_access,asset_mimetype,asset_last_update', sort: options.sort || '1' });
63
64
  }
64
65
  catch (err) {
65
66
  logger.error(err);
@@ -74,12 +75,24 @@ class AssetUpload extends Cmd_1.Cmd {
74
75
  //----------------------------------------------------------------------------------------------
75
76
  this.ignorePatterns = ['.git', 'node_modules'];
76
77
  this.description(description)
77
- .option('-d --dest <destination>', 'route of destination')
78
+ .option('-d --dest <destination>', 'destination path, directory name')
79
+ .option('-c --clean', 'clean destination path before uploading')
80
+ .option('-y --yes', 'upload list is automatically confirmed')
78
81
  .argument('[sources...]', 'local files or directories to upload as assets to the server')
79
82
  .action(async (sources, options) => {
80
83
  await this.commandUpload(sources, options);
81
84
  });
82
85
  }
86
+ mimetypeLookup(filename) {
87
+ let result;
88
+ if (path_1.default.extname(filename) === '.cyk') {
89
+ result = 'application/xml';
90
+ }
91
+ else {
92
+ result = mime_types_1.default.lookup(filename);
93
+ }
94
+ return result;
95
+ }
83
96
  async commandUpload(sources, options) {
84
97
  try {
85
98
  await this.prologue(options);
@@ -94,13 +107,16 @@ class AssetUpload extends Cmd_1.Cmd {
94
107
  dest = '/' + dest;
95
108
  if (dest.substring(dest.length - 1) !== '/')
96
109
  dest = dest + '/';
110
+ if (options.clean) {
111
+ await this.cleanDestination(dest);
112
+ }
97
113
  for (let ind = 0; ind < sources.length; ind++) {
98
114
  const source = sources[ind];
99
115
  if (fs.existsSync(source) === false)
100
116
  throw 'source ' + source + ' does not exist';
101
117
  const filestat = fs.lstatSync(source);
102
118
  if (filestat.isDirectory() === true) {
103
- await this.uploadDirectory(source, dest);
119
+ await this.uploadDirectory(source, dest, options);
104
120
  }
105
121
  else if (filestat.isFile() === true) {
106
122
  const base = path_1.default.parse(source).base;
@@ -114,9 +130,22 @@ class AssetUpload extends Cmd_1.Cmd {
114
130
  }
115
131
  }
116
132
  //----------------------------------------------------------------------------------------------
133
+ // cleanDestination
134
+ //----------------------------------------------------------------------------------------------
135
+ async cleanDestination(dest) {
136
+ const remoteList = await this.scanAssets();
137
+ for (let ind = 0; ind < remoteList.length; ind++) {
138
+ const fd = remoteList[ind];
139
+ if (fd.path.startsWith(dest)) {
140
+ const url = '/api/admin/assets/' + fd.id;
141
+ await this.dbRemote?.apiServer.delete(url);
142
+ }
143
+ }
144
+ }
145
+ //----------------------------------------------------------------------------------------------
117
146
  // uploadDirectory
118
147
  //----------------------------------------------------------------------------------------------
119
- async uploadDirectory(source, dest) {
148
+ async uploadDirectory(source, dest, options) {
120
149
  const localList = [];
121
150
  let dirName;
122
151
  if (source.substring(source.length - 1) === '/') {
@@ -126,23 +155,31 @@ class AssetUpload extends Cmd_1.Cmd {
126
155
  else {
127
156
  dirName = source + '/';
128
157
  }
129
- logger.debug('dirName', dirName);
158
+ logger.debug('options', options);
130
159
  this.scanDir(dirName, localList);
131
- const remoteList = [];
132
- await this.scanAssets(remoteList);
160
+ const remoteList = await this.scanAssets();
133
161
  const uploadList = this.buildUploadList(dirName, dest, localList, remoteList);
134
162
  // logger.info(fileNames.join('\n'))
135
163
  if (uploadList.length === 0)
136
164
  throw 'None file to upload';
137
- const rl = readline_1.default.createInterface(process.stdin, process.stdout);
138
- rl.question('Do you want to upload this(these) ' + uploadList.length + ' file(s) (Y/N/y/n) ?', async (reply) => {
139
- rl.close();
140
- if (reply !== 'Y' && reply !== 'y') {
141
- logger.info('upload cancelled');
142
- return;
143
- }
165
+ let uploadConfirmed = (options.yes !== undefined);
166
+ if (uploadConfirmed === false) {
167
+ const reply = await inquirer_1.default.prompt({ type: 'confirm', name: 'confirm', message: 'Do you want to upload this(these) ' + uploadList.length + ' file(s) ?' });
168
+ if (reply.confirm === true)
169
+ uploadConfirmed = true;
170
+ }
171
+ if (uploadConfirmed === true) {
144
172
  await this.uploadFiles(dirName, uploadList, dest);
145
- });
173
+ }
174
+ // const rl = readline.createInterface(process.stdin, process.stdout)
175
+ // rl.question('Do you want to upload this(these) ' + uploadList.length + ' file(s) (Y/N/y/n) ?', async (reply) => {
176
+ // rl.close()
177
+ // if (reply !== 'Y' && reply !== 'y') {
178
+ // logger.info('upload cancelled')
179
+ // return
180
+ // }
181
+ // await this.uploadFiles(dirName, uploadList, dest)
182
+ // })
146
183
  }
147
184
  //----------------------------------------------------------------------------------------------
148
185
  // buildUploadList
@@ -172,7 +209,8 @@ class AssetUpload extends Cmd_1.Cmd {
172
209
  //----------------------------------------------------------------------------------------------
173
210
  // scanAssets
174
211
  //----------------------------------------------------------------------------------------------
175
- async scanAssets(result) {
212
+ async scanAssets() {
213
+ const result = [];
176
214
  if (this.dbManager === undefined)
177
215
  throw 'dbManager undefined';
178
216
  const dbReq = new core_1.DBExecuteRequest();
@@ -188,11 +226,13 @@ class AssetUpload extends Cmd_1.Cmd {
188
226
  for (let ind = 0; ind < rows.list.length; ind++) {
189
227
  const { variable: row } = rows.list[ind];
190
228
  const record = row.data;
229
+ const asset_id = record.variables.getData('asset_id').value;
191
230
  const asset_route = record.variables.getData('asset_route').value;
192
- const asset_last_update = record.variables.getData('asset_last_update').value;
231
+ const asset_last_update = record.variables.getData('asset_last_update')?.value;
193
232
  // logger.debug('asset_route ' + asset_route,'asset_last_update ' + asset_last_update)
194
- result.push({ path: asset_route, mtime: asset_last_update });
233
+ result.push({ path: asset_route, mtime: asset_last_update, id: asset_id });
195
234
  }
235
+ return result;
196
236
  }
197
237
  //----------------------------------------------------------------------------------------------
198
238
  // scanDir
@@ -208,7 +248,7 @@ class AssetUpload extends Cmd_1.Cmd {
208
248
  this.scanDir(dirName + fileName + '/', result);
209
249
  }
210
250
  else {
211
- if (mime_types_1.default.lookup(fileName) === false) {
251
+ if (this.mimetypeLookup(fileName) === false) {
212
252
  logger.info(fileName + ' file extension is unknown and will not be uploaded');
213
253
  continue;
214
254
  }
@@ -241,13 +281,13 @@ class AssetUpload extends Cmd_1.Cmd {
241
281
  // uploadAsset
242
282
  //----------------------------------------------------------------------------------------------
243
283
  async uploadAsset(upload, route) {
244
- logger.debug('uploadAsset ' + upload.path + ' to route ' + route + ' with mimetype ' + mime_types_1.default.lookup(upload.path));
284
+ logger.debug('uploadAsset ' + upload.path + ' to route ' + route + ' with mimetype ' + this.mimetypeLookup(upload.path));
245
285
  try {
246
286
  let dbAsset = await this.dbManager?.dbAssetExist(route);
247
287
  if (dbAsset === undefined) {
248
288
  dbAsset = new core_1.DBAsset();
249
289
  }
250
- const mimetype = mime_types_1.default.lookup(upload.path);
290
+ const mimetype = this.mimetypeLookup(upload.path);
251
291
  if (mimetype === false)
252
292
  throw 'mimetype false for ' + upload;
253
293
  dbAsset.mimetype = mimetype;
@@ -280,7 +320,7 @@ class AssetUpload extends Cmd_1.Cmd {
280
320
  const file = fs.createReadStream(fileName);
281
321
  const form = new form_data_1.default();
282
322
  form.append('uploadFile', file);
283
- const route = '/upload/cyk_asset/asset_content?asset_id=' + dbAsset.id;
323
+ const route = '/api/upload/cyk_asset/asset_content?asset_id=' + dbAsset.id;
284
324
  const resp = await this.dbRemote?.apiServer.post(route, form);
285
325
  if (resp.status === 200) {
286
326
  logger.info(fileName + ' uploaded');
package/build/Cmd.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { DBManager, DBRemote } from "@cyklang/core";
1
+ import { DBManager, DBRemote, SigninResponse } from "@cyklang/core";
2
2
  import { Command } from "commander";
3
3
  export declare class Cmd extends Command {
4
4
  dbManager: DBManager | undefined;
5
5
  dbRemote: DBRemote | undefined;
6
6
  constructor(name: string);
7
- prologue(options: any): Promise<void>;
7
+ prologue(options: any): Promise<SigninResponse>;
8
8
  }
package/build/Cmd.js CHANGED
@@ -23,13 +23,14 @@ class Cmd extends commander_1.Command {
23
23
  const structure = new core_1.Structure();
24
24
  if (process.env.DBREMOTE_URL === undefined)
25
25
  throw 'DBREMOTE_URL undefined';
26
- logger.debug('DBREMOTE_URL ' + process.env.DBREMOTE_URL);
26
+ logger.debug('Cmd.DBREMOTE_URL ' + process.env.DBREMOTE_URL);
27
27
  const nodeCrypto = new NodeCrypto_1.NodeCrypto();
28
28
  this.dbRemote = new core_1.DBRemote(structure.scope, process.env.DBREMOTE_URL, nodeCrypto);
29
29
  const login = await this.dbRemote.signin(process.env.USER_NAME, undefined, process.env.USER_PASSWORD);
30
30
  // logger.debug(login)
31
31
  this.dbManager = new core_1.DBManager(structure.scope, this.dbRemote);
32
32
  await this.dbManager.initialize();
33
+ return login;
33
34
  }
34
35
  }
35
36
  exports.Cmd = Cmd;
@@ -2,10 +2,12 @@ import { DBManager } from "@cyklang/core";
2
2
  export declare class DBClient {
3
3
  dbManager: DBManager;
4
4
  constructor(dbManager: DBManager);
5
+ runQuery(): Promise<void>;
5
6
  selectFromTable(title: string, tableName: string, options: {
6
7
  fields: string;
7
8
  sort?: string | undefined;
8
9
  where?: string | undefined;
9
10
  width?: string | undefined;
10
11
  }): Promise<void>;
12
+ deleteModule(dbname: string): Promise<void>;
11
13
  }
package/build/DBClient.js CHANGED
@@ -13,6 +13,8 @@ class DBClient {
13
13
  constructor(dbManager) {
14
14
  this.dbManager = dbManager;
15
15
  }
16
+ async runQuery() {
17
+ }
16
18
  async selectFromTable(title, tableName, options) {
17
19
  try {
18
20
  const objectDataType = this.dbManager.scope.structure.objectDataType;
@@ -76,6 +78,18 @@ class DBClient {
76
78
  logger.error(err);
77
79
  }
78
80
  }
81
+ async deleteModule(dbname) {
82
+ try {
83
+ const dbModule = await this.dbManager.dbModuleExist(dbname);
84
+ if (dbModule === undefined) {
85
+ throw ('Module ' + dbname + ' not found');
86
+ }
87
+ await this.dbManager.dbModuleDelete(dbModule);
88
+ }
89
+ catch (err) {
90
+ logger.error(err);
91
+ }
92
+ }
79
93
  }
80
94
  exports.DBClient = DBClient;
81
95
  class List {
@@ -203,6 +217,8 @@ class List {
203
217
  else {
204
218
  result = value.toString();
205
219
  }
220
+ // replace \n with a space
221
+ result = result.replace(/\n/, ' ');
206
222
  if (width !== undefined && width !== 0) {
207
223
  if (result.length >= width) {
208
224
  result = result.substring(0, width);
@@ -48,7 +48,9 @@ Otherwise, a new module is inserted in the database. To rename a module, use opt
48
48
  // list
49
49
  this.addCommand(new ModuleList('list', 'List modules'));
50
50
  this.addCommand(new ModuleList('l', 'shortcut for (l)ist'));
51
- // rename
51
+ // rename **TODO**
52
+ // delete
53
+ this.addCommand(new ModuleDelete('delete', 'delete module from database'));
52
54
  }
53
55
  }
54
56
  exports.ModuleCommand = ModuleCommand;
@@ -57,7 +59,7 @@ function getModuleDBName(filePath) {
57
59
  // if (filePath.endsWith('.xml') === false) throw filePath + ' does not have .xml extension'
58
60
  // result = path.basename(filePath, '.xml')
59
61
  const result = path_1.default.parse(filePath).name;
60
- const identifierRegex = /^[_a-zA-Z][_a-zA-Z0-9]*$/;
62
+ const identifierRegex = /^[_a-zA-Z][-_a-zA-Z0-9]*$/;
61
63
  if (result.match(identifierRegex) === null)
62
64
  throw 'filename ' + result + ' does not match identifier syntax';
63
65
  return result;
@@ -194,7 +196,7 @@ class ModuleList extends Cmd_1.Cmd {
194
196
  if (this.dbManager === undefined)
195
197
  throw 'dbManager undefined';
196
198
  const dbClient = new DBClient_1.DBClient(this.dbManager);
197
- dbClient.selectFromTable('List of Modules', 'cyk_module', { fields: 'module_id,module_dbname,module_access,module_description', sort: options.sort || '1' });
199
+ dbClient.selectFromTable('List of Modules', 'cyk_module', { fields: 'module_id,module_dbname,module_auth,module_access,module_description', sort: options.sort || '1' });
198
200
  }
199
201
  catch (err) {
200
202
  logger.error(err);
@@ -217,6 +219,12 @@ class ModuleDelete extends Cmd_1.Cmd {
217
219
  throw 'dbManager undefined';
218
220
  if (files.length === 0)
219
221
  throw 'no module to delete';
222
+ const dbClient = new DBClient_1.DBClient(this.dbManager);
223
+ for (let ind = 0; ind < files.length; ind++) {
224
+ const dbname = files.at(ind);
225
+ if (dbname !== undefined)
226
+ dbClient.deleteModule(dbname);
227
+ }
220
228
  }
221
229
  catch (err) {
222
230
  logger.error(err);
@@ -5,58 +5,68 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.QueryCommand = void 0;
8
- const core_1 = require("@cyklang/core");
9
8
  const loglevel_1 = __importDefault(require("loglevel"));
9
+ const Cmd_1 = require("./Cmd");
10
10
  const commander_1 = require("commander");
11
+ const DBClient_1 = require("./DBClient");
11
12
  const logger = loglevel_1.default.getLogger("QueryCommand.ts");
12
13
  logger.setLevel("debug");
13
14
  class QueryCommand extends commander_1.Command {
14
15
  constructor(name) {
15
16
  super(name);
17
+ this.description('query management');
18
+ this.addCommand(new QueryList('list', 'list queries'));
19
+ this.addCommand(new QueryList('l', 'list queries'));
16
20
  }
17
21
  }
18
22
  exports.QueryCommand = QueryCommand;
19
- function parseXmlFile(filepath, basename, xmlSource) {
20
- const tag = (0, core_1.parseXML)(filepath, xmlSource);
21
- if (tag.name !== 'DB.QUERY') {
22
- throw Error('tag ' + tag.name + ', should be <db.query>');
23
- }
24
- const name = tag.attributes.NAME;
25
- if (name === undefined) {
26
- throw Error('name attribute is missing');
23
+ //--------------------------------------------------------------------------------------------------------------------
24
+ // class TableList
25
+ //--------------------------------------------------------------------------------------------------------------------
26
+ class QueryList extends Cmd_1.Cmd {
27
+ constructor(name, description) {
28
+ super(name);
29
+ this.description(description)
30
+ .option('-s --sort <columns>', 'sort list by column numbers (begins with 0) separated by comma')
31
+ .action(async (options) => {
32
+ await this.commandList(options);
33
+ });
27
34
  }
28
- if (basename !== name + '.xml') {
29
- throw Error('filename ' + filepath + ' and name ' + name + ' do not correspond');
35
+ async commandList(options) {
36
+ await this.prologue(options);
37
+ if (this.dbManager === undefined)
38
+ throw 'dbManager undefined';
39
+ const dbClient = new DBClient_1.DBClient(this.dbManager);
40
+ dbClient.selectFromTable('List of Queries', 'cyk_query', { fields: 'query_id,query_name,query_auth,query_access,query_description', sort: options.sort || '1' });
30
41
  }
31
- return tag;
32
42
  }
33
- async function executeXml(structure, tag, xmlSource) {
34
- try {
35
- logger.debug('executeXml ' + tag.attributes.NAME);
36
- // structure.setInstructionType("print", new PrintInstructionType(logfilename))
37
- const dbQueryInstructionType = structure.scope.getInstructionType('db.query');
38
- if (dbQueryInstructionType === undefined) {
39
- throw Error('dbQueryInstructionType not found');
40
- }
41
- const scopeParse = new core_1.Scope(structure, structure.scope, undefined);
42
- const dbQueryInst = await dbQueryInstructionType.parseInstruction(tag, scopeParse);
43
- dbQueryInst.source = xmlSource;
44
- const scopeExecute = new core_1.Scope(structure, structure.scope, undefined);
45
- await dbQueryInst.execute(scopeExecute);
43
+ //--------------------------------------------------------------------------------------------------------------------
44
+ // class queryData
45
+ //--------------------------------------------------------------------------------------------------------------------
46
+ class queryData extends Cmd_1.Cmd {
47
+ constructor(name, description) {
48
+ super(name);
49
+ this.description(description)
50
+ .argument('<query>', 'query name')
51
+ .option('--where <clause_where_sql>', 'criteria in SQL syntax')
52
+ .option('-s --sort <columns>', 'sort by columns positions (begins by 0) separated by comma')
53
+ .option('-w --width <colwidth>', 'columns widths separated by comma')
54
+ .action(async (query, options) => {
55
+ this.commandData(query, options);
56
+ });
46
57
  }
47
- catch (err) {
48
- logger.error(err);
58
+ async commandData(query, options) {
59
+ try {
60
+ await this.prologue(options);
61
+ if (this.dbManager === undefined)
62
+ throw 'dbManager undefined';
63
+ const dbQuery = await this.dbManager.dbQueryExist(query);
64
+ if (dbQuery === undefined)
65
+ throw 'query ' + query + ' not found';
66
+ //DBClient
67
+ }
68
+ catch (err) {
69
+ logger.error(err);
70
+ }
49
71
  }
50
72
  }
51
- async function testQuery(structure, queryName) {
52
- const xmlScript = `
53
- <block>
54
- <object name='result'/>
55
- <db.execute query='${queryName}' result='result' />
56
- <print>string(result)</print>
57
- </block>
58
- `;
59
- const script = new core_1.Script(structure.scope, 'test', xmlScript);
60
- await script.parseInstructions();
61
- await script.execute();
62
- }
@@ -61,11 +61,11 @@ async function runFile(filename) {
61
61
  if (filename.indexOf(".") !== -1) {
62
62
  filename = filename.substring(0, filename.indexOf("."));
63
63
  }
64
+ // skip filename with double underscore
65
+ if (filename.indexOf("__") !== -1)
66
+ return;
64
67
  let xmlfilename = filename + ".xml";
65
- // let logfilename = filename + ".log"
66
- // let outfilename = filename + ".output"
67
68
  let xml = fs.readFileSync(xmlfilename);
68
- // fs.writeFileSync(logfilename, "")
69
69
  try {
70
70
  if (process.env.DBREMOTE_URL === undefined)
71
71
  throw 'DBREMOTE_URL undefined';
@@ -76,14 +76,24 @@ async function runFile(filename) {
76
76
  const login = await dbRemote.signin(process.env.USER_NAME, undefined, process.env.USER_PASSWORD);
77
77
  const dbManager = new core_1.DBManager(structure.scope, dbRemote);
78
78
  await dbManager.initialize();
79
- const tag = (0, core_1.parseXML)(xmlfilename, xml.toString());
80
- const moduleInstruction = new core_1.ModuleInstruction(tag, dbManager);
81
- await moduleInstruction.parse(structure.scope);
82
- await moduleInstruction.execute(structure.scope);
83
- // structure.scope.addInstructionType(new PrintInstructionType(logfilename))
84
- // let script = new Script(structure.scope, xmlfilename, xml.toString())
85
- // await script.parseInstructions()
86
- // await script.execute()
79
+ const user_lang = login.content.user_lang;
80
+ if (user_lang && user_lang.trim() !== '') {
81
+ const langfilename = filename + "__" + user_lang + ".xml";
82
+ if (fs.existsSync(langfilename)) {
83
+ const langXml = fs.readFileSync(langfilename);
84
+ const tag = (0, core_1.parseXML)(xmlfilename, langXml.toString());
85
+ const modLang = new core_1.ModuleInstruction(tag, dbManager);
86
+ await modLang.parse(structure.scope);
87
+ await modLang.execute(structure.scope);
88
+ const langMap = modLang.objectData?.variables.getData(user_lang);
89
+ if (langMap !== null && langMap !== undefined) {
90
+ structure.mapLang = langMap;
91
+ }
92
+ }
93
+ }
94
+ let script = new core_1.Script(structure.scope, xmlfilename, xml.toString());
95
+ await script.parseInstructions();
96
+ await script.execute();
87
97
  }
88
98
  catch (err) {
89
99
  if (err instanceof core_1.XmlError) {
@@ -92,21 +102,4 @@ async function runFile(filename) {
92
102
  }
93
103
  console.log(err);
94
104
  }
95
- // let log = fs.readFileSync(logfilename)
96
- // if (fs.existsSync(outfilename) === true ) {
97
- // let out = fs.readFileSync(outfilename)
98
- // if (log.toString() === out.toString()) {
99
- // console.log("test " + xmlfilename + " SUCCESS")
100
- // result = true
101
- // }
102
- // else {
103
- // console.log("test " + xmlfilename + " FAILURE")
104
- // result = false
105
- // }
106
- // }
107
- // else {
108
- // console.log("test " + xmlfilename + " output file not found ")
109
- // result = false
110
- // }
111
- // return result
112
105
  }
@@ -41,8 +41,8 @@ class TableCommand extends commander_1.Command {
41
41
  this.addCommand(new TableImportCmd());
42
42
  this.addCommand(new TableList('list', 'list database tables'));
43
43
  this.addCommand(new TableList('l', '(l)ist database tables'));
44
- this.addCommand(new TableQuery('query', 'query select table content'));
45
- this.addCommand(new TableQuery('q', 'query select table content'));
44
+ this.addCommand(new TableData('data', 'table (d)ata'));
45
+ this.addCommand(new TableData('d', 'table (d)ata'));
46
46
  }
47
47
  }
48
48
  exports.TableCommand = TableCommand;
@@ -271,25 +271,25 @@ class TableList extends Cmd_1.Cmd {
271
271
  if (this.dbManager === undefined)
272
272
  throw 'dbManager undefined';
273
273
  const dbClient = new DBClient_1.DBClient(this.dbManager);
274
- dbClient.selectFromTable('List of Tables', 'cyk_table', { fields: 'table_id,table_name,table_description,table_access', sort: options.sort || '1' });
274
+ dbClient.selectFromTable('List of Tables', 'cyk_table', { fields: 'table_id,table_name,table_auth,table_access,table_description', sort: options.sort || '1' });
275
275
  }
276
276
  }
277
277
  //--------------------------------------------------------------------------------------------------------------------
278
- // class TableQuery
278
+ // class TableData
279
279
  //--------------------------------------------------------------------------------------------------------------------
280
- class TableQuery extends Cmd_1.Cmd {
280
+ class TableData extends Cmd_1.Cmd {
281
281
  constructor(name, description) {
282
282
  super(name);
283
283
  this.description(description)
284
- .argument('<table>', 'table to query')
284
+ .argument('<table>', 'table name')
285
285
  .option('--where <clause_where_sql>', 'criteria in SQL syntax')
286
286
  .option('-s --sort <columns>', 'sort by columns positions (begins by 0) separated by comma')
287
287
  .option('-w --width <colwidth>', 'columns widths separated by comma')
288
288
  .action(async (table, options) => {
289
- this.commandQuery(table, options);
289
+ this.commandData(table, options);
290
290
  });
291
291
  }
292
- async commandQuery(table, options) {
292
+ async commandData(table, options) {
293
293
  try {
294
294
  await this.prologue(options);
295
295
  if (this.dbManager === undefined)
@@ -42,11 +42,11 @@ class TestCommand extends Cmd_1.Cmd {
42
42
  }
43
43
  async testRun(files, options) {
44
44
  try {
45
- await this.prologue(options);
45
+ const signinResponse = await this.prologue(options);
46
46
  for (let ind = 0; ind < files.length; ind++) {
47
47
  const result = await testfile(files[ind]);
48
48
  if (result === false) {
49
- logger.debug('*********** FAILURE ' + process.argv[ind] + ' ***************');
49
+ logger.debug('*********** FAILURE ' + files[ind] + ' ***************');
50
50
  }
51
51
  }
52
52
  }
@@ -61,6 +61,9 @@ async function testfile(filename) {
61
61
  if (filename.indexOf(".") !== -1) {
62
62
  filename = filename.substring(0, filename.indexOf("."));
63
63
  }
64
+ // skip filename with double underscore
65
+ if (filename.indexOf("__") !== -1)
66
+ return true;
64
67
  let xmlfilename = filename + ".xml";
65
68
  let logfilename = filename + ".log";
66
69
  let outfilename = filename + ".output";
@@ -80,6 +83,22 @@ async function testfile(filename) {
80
83
  await dbManager.initialize();
81
84
  structure.scope.addInstructionType(new console_1.PrintInstructionType(logfilename));
82
85
  let script = new core_1.Script(structure.scope, xmlfilename, xml.toString());
86
+ const user_lang = login.content.user_lang;
87
+ if (user_lang && user_lang.trim() !== '') {
88
+ const langfilename = filename + "__" + user_lang + ".xml";
89
+ if (fs.existsSync(langfilename)) {
90
+ const langXml = fs.readFileSync(langfilename);
91
+ const tag = (0, core_1.parseXML)(xmlfilename, langXml.toString());
92
+ const modLang = new core_1.ModuleInstruction(tag, dbManager);
93
+ await modLang.parse(structure.scope);
94
+ await modLang.execute(structure.scope);
95
+ const langMap = modLang.objectData?.variables.getData(user_lang);
96
+ if (langMap !== null && langMap !== undefined) {
97
+ structure.mapLang = langMap;
98
+ outfilename = filename + "__" + user_lang + ".output";
99
+ }
100
+ }
101
+ }
83
102
  await script.parseInstructions();
84
103
  await script.execute();
85
104
  // console.log(JSON.stringify(script.block.toString()))
@@ -36,6 +36,7 @@ class UserAddCmd extends Cmd_1.Cmd {
36
36
  .option('-a --access <acl>', 'access control list')
37
37
  .option('-m --module <module_name>', 'module to launch by default')
38
38
  .option('-d --disable', 'user not abled to connect')
39
+ .option('-l --lang <language>', 'user language')
39
40
  .action(async (options) => {
40
41
  const dbUser = new core_1.DBUser();
41
42
  dbUser.name = options.name;
@@ -44,6 +45,7 @@ class UserAddCmd extends Cmd_1.Cmd {
44
45
  dbUser.access = options.access;
45
46
  dbUser.appli = options.module;
46
47
  dbUser.disable = options.disable || false;
48
+ dbUser.lang = options.lang;
47
49
  await this.commandAdd(dbUser, options);
48
50
  });
49
51
  }
@@ -75,7 +77,7 @@ class UserListCmd extends Cmd_1.Cmd {
75
77
  if (this.dbManager === undefined)
76
78
  throw 'dbManager undefined';
77
79
  const dbClient = new DBClient_1.DBClient(this.dbManager);
78
- dbClient.selectFromTable('List of users', 'cyk_user', { fields: 'user_id,user_name,user_email,user_access,user_appli,user_disable', sort: options.sort || '1' });
80
+ dbClient.selectFromTable('List of users', 'cyk_user', { fields: 'user_id,user_name,user_email,user_access,user_appli,user_lang,user_disable', sort: options.sort || '1' });
79
81
  }
80
82
  catch (err) {
81
83
  logger.error(err);
@@ -91,6 +93,7 @@ class UserUpdateCmd extends Cmd_1.Cmd {
91
93
  .option('-e --email <email>', 'user email address')
92
94
  .option('-a --access <acl>', 'access control list')
93
95
  .option('-m --module <module_name>', 'module to launch by default')
96
+ .option('-l --lang <language>', 'user language')
94
97
  .option('-d --disable', 'user not able to connect')
95
98
  .action(async (options) => {
96
99
  const dbUser = new core_1.DBUser();
@@ -99,6 +102,7 @@ class UserUpdateCmd extends Cmd_1.Cmd {
99
102
  dbUser.email = options.email;
100
103
  dbUser.access = options.access;
101
104
  dbUser.appli = options.module;
105
+ dbUser.lang = options.lang;
102
106
  dbUser.disable = options.disable;
103
107
  await this.commandUpdate(dbUser, options);
104
108
  });
@@ -122,6 +126,8 @@ class UserUpdateCmd extends Cmd_1.Cmd {
122
126
  dbUser1.access = dbUser2.access;
123
127
  if (dbUser2.appli !== undefined)
124
128
  dbUser1.appli = dbUser2.appli;
129
+ if (dbUser2.lang !== undefined)
130
+ dbUser1.lang = dbUser2.lang;
125
131
  if (dbUser2.disable !== undefined)
126
132
  dbUser1.disable = dbUser2.disable;
127
133
  // logger.debug('dbUser1 before dbUserUpdate : ', dbUser1)
package/docker.env CHANGED
@@ -33,6 +33,6 @@ LOGIN_APPLI="accounting"
33
33
 
34
34
  USER_NAME=cyk
35
35
  USER_PASSWORD=cyk
36
- CYK_PORT="3000"
37
- DBREMOTE_URL="http://localhost:3000"
36
+ CYK_PORT="3100"
37
+ DBREMOTE_URL="http://localhost:3100"
38
38