@cyklang/cli 0.3.1 → 0.5.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,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -36,21 +40,125 @@ const core_1 = require("@cyklang/core");
36
40
  const form_data_1 = __importDefault(require("form-data"));
37
41
  const logger = (0, loglevel_1.getLogger)('AssetCommand.ts');
38
42
  logger.setLevel('debug');
43
+ //----------------------------------------------------------------------------------------------
44
+ // scanAssets
45
+ //----------------------------------------------------------------------------------------------
46
+ const scanAssets = async (dbManager, dest) => {
47
+ const result = [];
48
+ if (dbManager === undefined)
49
+ throw 'dbManager undefined';
50
+ const dbReq = new core_1.DBExecuteRequest();
51
+ dbReq.selectFromTable = 'cyk_asset';
52
+ const pFields = dbReq.parameters.addVariable('fields', dbManager.scope.structure.stringDataType);
53
+ pFields.data = new core_1.PrimitiveData(dbManager.scope.structure.stringDataType, "asset_id,asset_route,asset_last_update,asset_mimetype");
54
+ const xmlResult = await dbManager.dbExecute(dbReq);
55
+ if (xmlResult === undefined || xmlResult === null)
56
+ throw 'xmlResult null or undefined';
57
+ const tag = (0, core_1.parseXML)('scanAssets', xmlResult);
58
+ const objResult = await dbManager.scope.structure.objectDataType.parseData(tag, dbManager.scope);
59
+ const rows = objResult.variables.getData('cyk_asset').variables;
60
+ for (let ind = 0; ind < rows.list.length; ind++) {
61
+ const { variable: row } = rows.list[ind];
62
+ const record = row.data;
63
+ const asset_id = record.variables.getData('asset_id').value;
64
+ const asset_route = record.variables.getData('asset_route').value;
65
+ const asset_last_update = record.variables.getData('asset_last_update')?.value;
66
+ // logger.debug('asset_route ' + asset_route,'asset_last_update ' + asset_last_update)
67
+ if (!dest || asset_route.startsWith(dest))
68
+ result.push({ path: asset_route, mtime: asset_last_update, id: asset_id });
69
+ }
70
+ return result;
71
+ };
39
72
  class AssetCommand extends commander_1.Command {
40
73
  constructor(name, description) {
41
74
  super(name);
42
75
  this.description(description);
43
76
  this.addCommand(new AssetList('list', 'list assets'));
44
77
  this.addCommand(new AssetList('l', '(l)ist assets'));
45
- this.addCommand(new AssetUpload('upload', 'upload assets from sources'));
46
- this.addCommand(new AssetUpload('u', '(u)pload assets'));
78
+ this.addCommand(new AssetU('upload', 'upload asset content from source files to a <destination> path'));
79
+ this.addCommand(new AssetU('update', 'update properties of asset identified by its <id>'));
80
+ this.addCommand(new AssetU('u', '(u)pload assets content from sources or (u)pdate asset properties'));
81
+ this.addCommand(new AssetDelete('delete', 'delete an asset'));
47
82
  }
48
83
  }
49
84
  exports.AssetCommand = AssetCommand;
85
+ /**
86
+ * class AssetDelete
87
+ */
88
+ class AssetDelete extends Cmd_1.Cmd {
89
+ constructor(name, description) {
90
+ super(name);
91
+ this.description(description)
92
+ .option('-i --id <id_pathname>', 'asset id or pathname to delete')
93
+ .option('-d --dest <destination>', 'delete all assets whose pathname begins with dest')
94
+ .action(async (options) => {
95
+ if (options.id)
96
+ await this.commandDeleteOne(options);
97
+ else if (options.dest) {
98
+ await this.commandDeletePathname(options);
99
+ }
100
+ else {
101
+ logger.error('one of --id or --dest options is required');
102
+ }
103
+ });
104
+ }
105
+ /**
106
+ *
107
+ * @param options
108
+ */
109
+ async commandDeleteOne(options) {
110
+ try {
111
+ await this.prologue(options);
112
+ if (this.dbManager === undefined)
113
+ throw 'dbManager undefined';
114
+ if (options.id === undefined)
115
+ throw '<id_or_pathname> of asset to delete is missing';
116
+ if (!options.id.startsWith('/'))
117
+ throw '-i --id only pathname is supported at the moment';
118
+ const dbAsset = await this.dbManager.dbAssetExist(options.id);
119
+ if (dbAsset === undefined)
120
+ throw 'Asset ' + options.id + ' not found';
121
+ await this.dbManager.dbAssetDelete(dbAsset);
122
+ logger.info('asset ' + dbAsset.id + ' ' + dbAsset.route + ' deleted');
123
+ }
124
+ catch (err) {
125
+ logger.error(err);
126
+ }
127
+ }
128
+ /**
129
+ *
130
+ * @param options
131
+ */
132
+ async commandDeletePathname(options) {
133
+ try {
134
+ await this.prologue(options);
135
+ if (!this.dbManager)
136
+ throw 'dbManager undefined';
137
+ const dbClient = new DBClient_1.DBClient(this.dbManager);
138
+ const list = await dbClient.selectFromTable('Assets to delete', 'cyk_asset', {
139
+ fields: 'asset_id,asset_route,asset_auth,asset_access,asset_mimetype,asset_last_update', sort: options.sort || '1',
140
+ where: (options.dest ? "asset_route like '" + options.dest + "%'" : undefined)
141
+ });
142
+ const reply = await inquirer_1.default.prompt({ type: 'confirm', name: 'confirm', message: 'Do you want to delete these ' + list.length + ' file(s)' });
143
+ if (reply.confirm) {
144
+ for (let ind = 0; ind < list.length; ind++) {
145
+ const asset = list[ind];
146
+ logger.info('delete ' + asset.asset_route);
147
+ const url = '/api/admin/assets/' + asset.asset_id;
148
+ await this.dbRemote?.apiServer.delete(url);
149
+ }
150
+ }
151
+ }
152
+ catch (err) {
153
+ logger.error(err);
154
+ }
155
+ }
156
+ }
50
157
  class AssetList extends Cmd_1.Cmd {
51
158
  constructor(name, description) {
52
159
  super(name);
53
160
  this.description(description)
161
+ .option('-d --dest <destination>', 'filter assets whose pathname begins with destination')
54
162
  .option('-s --sort <columns>', 'sort list by column numbers (begins by 0) separated by comma')
55
163
  .action(async (options) => { await this.commandList(options); });
56
164
  }
@@ -60,14 +168,20 @@ class AssetList extends Cmd_1.Cmd {
60
168
  if (this.dbManager === undefined)
61
169
  throw 'dbManager undefined';
62
170
  const dbClient = new DBClient_1.DBClient(this.dbManager);
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' });
171
+ dbClient.selectFromTable('List of Assets', 'cyk_asset', {
172
+ fields: 'asset_id,asset_route,asset_auth,asset_access,asset_mimetype,asset_last_update', sort: options.sort || '1',
173
+ where: (options.dest ? "asset_route like '" + options.dest + "%'" : undefined)
174
+ });
64
175
  }
65
176
  catch (err) {
66
177
  logger.error(err);
67
178
  }
68
179
  }
69
180
  }
70
- class AssetUpload extends Cmd_1.Cmd {
181
+ /**
182
+ * class AssetU
183
+ */
184
+ class AssetU extends Cmd_1.Cmd {
71
185
  constructor(name, description) {
72
186
  super(name);
73
187
  //----------------------------------------------------------------------------------------------
@@ -75,13 +189,15 @@ class AssetUpload extends Cmd_1.Cmd {
75
189
  //----------------------------------------------------------------------------------------------
76
190
  this.ignorePatterns = ['.git', 'node_modules'];
77
191
  this.description(description)
78
- .option('-a --auth <auth_schema>', 'authentication schema : basic | token | any, default is no authentication')
192
+ .option('-i --id <id>', 'asset id or pathname whose properties are updated')
193
+ .option('--auth <auth_schema>', 'authentication schema : basic | token | cookie | any | none, default is none')
194
+ .option('--access <access>', 'access rights required')
79
195
  .option('-d --dest <destination>', 'destination path, directory name')
80
196
  .option('-c --clean', 'clean destination path before uploading')
81
197
  .option('-y --yes', 'upload list is automatically confirmed')
82
198
  .argument('[sources...]', 'local files or directories to upload as assets to the server')
83
199
  .action(async (sources, options) => {
84
- await this.commandUpload(sources, options);
200
+ await this.commandU(sources, options);
85
201
  });
86
202
  }
87
203
  mimetypeLookup(filename) {
@@ -94,6 +210,50 @@ class AssetUpload extends Cmd_1.Cmd {
94
210
  }
95
211
  return result;
96
212
  }
213
+ /**
214
+ * method commandU
215
+ * @param sources
216
+ * @param options
217
+ */
218
+ async commandU(sources, options) {
219
+ if (sources.length > 0) {
220
+ // upload
221
+ // logger.debug('upload sources :', sources)
222
+ await this.commandUpload(sources, options);
223
+ }
224
+ else {
225
+ // update
226
+ // logger.debug('update', options)
227
+ await this.commandUpdate(options);
228
+ }
229
+ }
230
+ /**
231
+ * method commandUpdate
232
+ * @param options
233
+ */
234
+ async commandUpdate(options) {
235
+ try {
236
+ await this.prologue(options);
237
+ if (this.dbManager === undefined)
238
+ throw 'dbManager undefined';
239
+ if (options.id === undefined)
240
+ throw '<id_or_pathname> of asset to update is missing';
241
+ if (!options.id.startsWith('/'))
242
+ throw '-i --id only pathname is supported at the moment';
243
+ const dbAsset = await this.dbManager.dbAssetExist(options.id);
244
+ if (dbAsset === undefined)
245
+ throw 'Asset ' + options.id + ' not found';
246
+ await this.updateAuthAccess('cyk_asset', 'asset', dbAsset.id || '', options);
247
+ }
248
+ catch (err) {
249
+ logger.error(err);
250
+ }
251
+ }
252
+ /**
253
+ * method commandUpload
254
+ * @param sources
255
+ * @param options
256
+ */
97
257
  async commandUpload(sources, options) {
98
258
  try {
99
259
  await this.prologue(options);
@@ -101,11 +261,11 @@ class AssetUpload extends Cmd_1.Cmd {
101
261
  throw 'dbManager undefined';
102
262
  if (sources.length === 0)
103
263
  throw 'no source to upload';
104
- if (options.auth && ' basic | token | any '.indexOf(options.auth) === -1) {
105
- throw 'valid authentication schemas are : basic | token | any';
264
+ if (options.auth && ' basic | token | cookie | any | none'.indexOf(options.auth) === -1) {
265
+ throw 'valid authentication schemas are : basic | token | cookie | any | none';
106
266
  }
107
- logger.debug('options : ', options);
108
- logger.debug('auth : ' + options.auth);
267
+ // logger.debug('options : ', options)
268
+ // logger.debug('auth : ' + options.auth)
109
269
  let dest = "/";
110
270
  if (options.dest !== undefined)
111
271
  dest = options.dest;
@@ -139,7 +299,7 @@ class AssetUpload extends Cmd_1.Cmd {
139
299
  // cleanDestination
140
300
  //----------------------------------------------------------------------------------------------
141
301
  async cleanDestination(dest) {
142
- const remoteList = await this.scanAssets();
302
+ const remoteList = await scanAssets(this.dbManager);
143
303
  for (let ind = 0; ind < remoteList.length; ind++) {
144
304
  const fd = remoteList[ind];
145
305
  if (fd.path.startsWith(dest)) {
@@ -161,9 +321,9 @@ class AssetUpload extends Cmd_1.Cmd {
161
321
  else {
162
322
  dirName = source + '/';
163
323
  }
164
- logger.debug('options', options);
324
+ // logger.debug('options', options)
165
325
  this.scanDir(dirName, localList);
166
- const remoteList = await this.scanAssets();
326
+ const remoteList = await scanAssets(this.dbManager);
167
327
  const uploadList = this.buildUploadList(dirName, dest, localList, remoteList);
168
328
  // logger.info(fileNames.join('\n'))
169
329
  if (uploadList.length === 0)
@@ -213,34 +373,6 @@ class AssetUpload extends Cmd_1.Cmd {
213
373
  return result;
214
374
  }
215
375
  //----------------------------------------------------------------------------------------------
216
- // scanAssets
217
- //----------------------------------------------------------------------------------------------
218
- async scanAssets() {
219
- const result = [];
220
- if (this.dbManager === undefined)
221
- throw 'dbManager undefined';
222
- const dbReq = new core_1.DBExecuteRequest();
223
- dbReq.selectFromTable = 'cyk_asset';
224
- const pFields = dbReq.parameters.addVariable('fields', this.dbManager.scope.structure.stringDataType);
225
- pFields.data = new core_1.PrimitiveData(this.dbManager.scope.structure.stringDataType, "asset_id,asset_route,asset_last_update,asset_mimetype");
226
- const xmlResult = await this.dbManager.dbExecute(dbReq);
227
- if (xmlResult === undefined || xmlResult === null)
228
- throw 'xmlResult null or undefined';
229
- const tag = (0, core_1.parseXML)('scanAssets', xmlResult);
230
- const objResult = await this.dbManager.scope.structure.objectDataType.parseData(tag, this.dbManager.scope);
231
- const rows = objResult.variables.getData('cyk_asset').variables;
232
- for (let ind = 0; ind < rows.list.length; ind++) {
233
- const { variable: row } = rows.list[ind];
234
- const record = row.data;
235
- const asset_id = record.variables.getData('asset_id').value;
236
- const asset_route = record.variables.getData('asset_route').value;
237
- const asset_last_update = record.variables.getData('asset_last_update')?.value;
238
- // logger.debug('asset_route ' + asset_route,'asset_last_update ' + asset_last_update)
239
- result.push({ path: asset_route, mtime: asset_last_update, id: asset_id });
240
- }
241
- return result;
242
- }
243
- //----------------------------------------------------------------------------------------------
244
376
  // scanDir
245
377
  //----------------------------------------------------------------------------------------------
246
378
  scanDir(dirName, result) {
@@ -287,7 +419,7 @@ class AssetUpload extends Cmd_1.Cmd {
287
419
  // uploadAsset
288
420
  //----------------------------------------------------------------------------------------------
289
421
  async uploadAsset(upload, route, auth) {
290
- logger.debug('uploadAsset ' + upload.path + ' to route ' + route + ' with mimetype ' + this.mimetypeLookup(upload.path) + ', auth : ' + auth);
422
+ // logger.debug('uploadAsset ' + upload.path + ' to route ' + route + ' with mimetype ' + this.mimetypeLookup(upload.path) + ', auth : ' + auth)
291
423
  try {
292
424
  let dbAsset = await this.dbManager?.dbAssetExist(route);
293
425
  if (dbAsset === undefined) {
@@ -299,6 +431,8 @@ class AssetUpload extends Cmd_1.Cmd {
299
431
  dbAsset.mimetype = mimetype;
300
432
  dbAsset.route = route;
301
433
  dbAsset.auth = auth;
434
+ if (dbAsset.auth === 'none')
435
+ dbAsset.auth = undefined;
302
436
  // const fstat = fs.statSync(fileName)
303
437
  dbAsset.last_update = upload.mtime;
304
438
  // const contentBuffer = fs.readFileSync(fileName)
package/build/Cmd.d.ts CHANGED
@@ -5,4 +5,12 @@ export declare class Cmd extends Command {
5
5
  dbRemote: DBRemote | undefined;
6
6
  constructor(name: string);
7
7
  prologue(options: any): Promise<SigninResponse>;
8
+ /**
9
+ * method updateAuthAccess
10
+ * @param tableName
11
+ * @param prefix
12
+ * @param id
13
+ * @param options
14
+ */
15
+ updateAuthAccess(tableName: string, prefix: string, id: string, options: any): Promise<void>;
8
16
  }
package/build/Cmd.js CHANGED
@@ -9,6 +9,7 @@ const commander_1 = require("commander");
9
9
  const dotenv_1 = __importDefault(require("dotenv"));
10
10
  const loglevel_1 = __importDefault(require("loglevel"));
11
11
  const NodeCrypto_1 = require("./NodeCrypto");
12
+ const DBClient_1 = require("./DBClient");
12
13
  const logger = loglevel_1.default.getLogger('Cmd.ts');
13
14
  logger.setLevel('debug');
14
15
  class Cmd extends commander_1.Command {
@@ -32,5 +33,54 @@ class Cmd extends commander_1.Command {
32
33
  await this.dbManager.initialize();
33
34
  return login;
34
35
  }
36
+ /**
37
+ * method updateAuthAccess
38
+ * @param tableName
39
+ * @param prefix
40
+ * @param id
41
+ * @param options
42
+ */
43
+ async updateAuthAccess(tableName, prefix, id, options) {
44
+ try {
45
+ let dclAuth;
46
+ if (options.auth) {
47
+ if (' basic | token | cookie | any | none | null '.indexOf(' ' + options.auth + ' ') === -1) {
48
+ throw 'valid authentication schemas are : basic | token | cookie | any | null';
49
+ }
50
+ dclAuth = `<string name='${prefix}_auth'>`;
51
+ if (' none | null '.indexOf(' ' + options.auth + ' ') === -1)
52
+ dclAuth += ` "${options.auth}" `;
53
+ else
54
+ dclAuth += ' null ';
55
+ dclAuth += "</string>";
56
+ }
57
+ let dclAccess;
58
+ if (options.access) {
59
+ dclAccess = `<string name='${prefix}_access'> `;
60
+ if (' null | none '.indexOf(' ' + options.access + ' ') === -1)
61
+ dclAccess += `"${options.access}"`;
62
+ else
63
+ dclAccess += ' null ';
64
+ dclAccess += "</string>";
65
+ }
66
+ const inst = `
67
+ <db.update table='${tableName}'>
68
+ <object>
69
+ <number name='${prefix}_id'>${id}</number>
70
+ ${dclAuth}
71
+ ${dclAccess ? dclAccess : ''}
72
+ </object>
73
+ </db.update>
74
+ `;
75
+ if (!this.dbManager)
76
+ throw 'prologue() has not been called before';
77
+ const dbClient = new DBClient_1.DBClient(this.dbManager);
78
+ dbClient.execInstructions(inst);
79
+ }
80
+ catch (err) {
81
+ logger.error(err);
82
+ throw err;
83
+ }
84
+ }
35
85
  }
36
86
  exports.Cmd = Cmd;
@@ -2,12 +2,22 @@ import { DBManager } from "@cyklang/core";
2
2
  export declare class DBClient {
3
3
  dbManager: DBManager;
4
4
  constructor(dbManager: DBManager);
5
+ /**
6
+ * method execInstructions
7
+ * @param source
8
+ */
9
+ execInstructions(source: string): Promise<void>;
10
+ /**
11
+ * method execScript
12
+ * @param source
13
+ */
14
+ execScript(source: string): Promise<void>;
5
15
  runQuery(): Promise<void>;
6
16
  selectFromTable(title: string, tableName: string, options: {
7
17
  fields: string;
8
18
  sort?: string | undefined;
9
19
  where?: string | undefined;
10
20
  width?: string | undefined;
11
- }): Promise<void>;
21
+ }): Promise<any[]>;
12
22
  deleteModule(dbname: string): Promise<void>;
13
23
  }
package/build/DBClient.js CHANGED
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.DBClient = void 0;
7
7
  const core_1 = require("@cyklang/core");
8
8
  const loglevel_1 = __importDefault(require("loglevel"));
9
+ const console_1 = require("./console");
9
10
  const logger = loglevel_1.default.getLogger('DBClient.ts');
10
11
  logger.setLevel('debug');
11
12
  // DBManager wrapper class
@@ -13,9 +14,41 @@ class DBClient {
13
14
  constructor(dbManager) {
14
15
  this.dbManager = dbManager;
15
16
  }
17
+ /**
18
+ * method execInstructions
19
+ * @param source
20
+ */
21
+ async execInstructions(source) {
22
+ const script = `<?xml-model href="https://www.cyklang.net/schema/cyklang.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
23
+ <module>
24
+ ` + source + `
25
+ </module>`;
26
+ await this.execScript(script);
27
+ }
28
+ /**
29
+ * method execScript
30
+ * @param source
31
+ */
32
+ async execScript(source) {
33
+ try {
34
+ const script = new core_1.Script(this.dbManager.scope, '', source);
35
+ await script.parseInstructions();
36
+ await script.execute();
37
+ }
38
+ catch (err) {
39
+ console.log(source);
40
+ console.log();
41
+ if (err instanceof core_1.XmlError) {
42
+ let xmlError = err;
43
+ (0, console_1.errorconsole)(xmlError);
44
+ }
45
+ console.log(err);
46
+ }
47
+ }
16
48
  async runQuery() {
17
49
  }
18
50
  async selectFromTable(title, tableName, options) {
51
+ let result = [];
19
52
  try {
20
53
  const objectDataType = this.dbManager.scope.structure.objectDataType;
21
54
  const stringDataType = this.dbManager.scope.structure.stringDataType;
@@ -69,14 +102,19 @@ class DBClient {
69
102
  }
70
103
  const objDataset = objXmlResult.variables.getData(tableName);
71
104
  for (let ind = 0; ind < objDataset.variables.length(); ind++) {
72
- const record = objDataset.variables.at(ind)?.data;
73
- list.addObjectData(record);
105
+ const variable = objDataset.variables.at(ind);
106
+ if (variable) {
107
+ const record = variable?.data;
108
+ list.addObjectData(record);
109
+ result.push((0, core_1.variable2json)(variable));
110
+ }
74
111
  }
75
112
  logger.info(list.renderList(title));
76
113
  }
77
114
  catch (err) {
78
115
  logger.error(err);
79
116
  }
117
+ return result;
80
118
  }
81
119
  async deleteModule(dbname) {
82
120
  try {
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -2,7 +2,11 @@
2
2
  "use strict";
3
3
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
4
  if (k2 === undefined) k2 = k;
5
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
6
10
  }) : (function(o, m, k, k2) {
7
11
  if (k2 === undefined) k2 = k;
8
12
  o[k2] = m[k];
@@ -38,10 +42,10 @@ class ModuleCommand extends commander_1.Command {
38
42
  super(name);
39
43
  this.description('manage modules');
40
44
  // upload
41
- this.addCommand(new ModuleUpload('upload', `Upload local module file(s) to the database.
45
+ this.addCommand(new ModuleU('upload', `Upload local module file(s) to the database.
42
46
  Module name is the base name of the file. If a module with the same name already exists, it will be updated.
43
47
  Otherwise, a new module is inserted in the database. To rename a module, use option --id to indicate the module you want to rename`));
44
- this.addCommand(new ModuleUpload('u', 'shortcut for (u)pload'));
48
+ this.addCommand(new ModuleU('u', 'shortcut for (u)pload'));
45
49
  // download
46
50
  this.addCommand(new ModuleDownload('download', 'download module files to the current directory'));
47
51
  this.addCommand(new ModuleDownload('d', 'shortcut for (d)ownload'));
@@ -64,16 +68,52 @@ function getModuleDBName(filePath) {
64
68
  throw 'filename ' + result + ' does not match identifier syntax';
65
69
  return result;
66
70
  }
67
- class ModuleUpload extends Cmd_1.Cmd {
71
+ /**
72
+ * class ModuleU
73
+ */
74
+ class ModuleU extends Cmd_1.Cmd {
68
75
  constructor(name, description) {
69
76
  super(name);
70
77
  this.description(description)
71
- .option('-i --id <id>', 'module ID to upload')
78
+ .option('--auth <auth_schema>', 'authentication schema : basic | token | cookie | any | none, default is none')
79
+ .option('--access <access_right>', 'access rights required')
80
+ .option('-i --id <id>', 'module ID to upload or update')
72
81
  .argument('[files...]', 'local module file(s) to upload to the server')
73
82
  .action(async (files, options) => {
74
- await this.commandUpload(files, options);
83
+ await this.commandU(files, options);
75
84
  });
76
85
  }
86
+ async commandU(files, options) {
87
+ if (files.length > 0) {
88
+ await this.commandUpload(files, options);
89
+ }
90
+ else {
91
+ await this.commandUpdate(options);
92
+ }
93
+ }
94
+ /**
95
+ * method commandUpdate
96
+ * @param options
97
+ */
98
+ async commandUpdate(options) {
99
+ try {
100
+ await this.prologue(options);
101
+ if (this.dbManager === undefined)
102
+ throw 'dbManager undefined';
103
+ if (options.id === undefined)
104
+ throw '<id_or_route> of module to update is missing';
105
+ const dbModule = await this.dbManager.getModule(options.id);
106
+ await this.updateAuthAccess('cyk_module', 'module', dbModule.id || '', options);
107
+ }
108
+ catch (err) {
109
+ logger.error(err);
110
+ }
111
+ }
112
+ /**
113
+ * method commandUpload
114
+ * @param files
115
+ * @param options
116
+ */
77
117
  async commandUpload(files, options) {
78
118
  try {
79
119
  await this.prologue(options);
@@ -0,0 +1,5 @@
1
+ import { Cmd } from "./Cmd";
2
+ export declare class OpenCommand extends Cmd {
3
+ constructor();
4
+ openBrowser(module: string, options: any): Promise<void>;
5
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.OpenCommand = void 0;
7
+ const Cmd_1 = require("./Cmd");
8
+ const loglevel_1 = __importDefault(require("loglevel"));
9
+ const logger = loglevel_1.default.getLogger('OpenCommand.ts');
10
+ logger.setLevel('debug');
11
+ class OpenCommand extends Cmd_1.Cmd {
12
+ constructor() {
13
+ super('open');
14
+ this.description('open browser').version('0.1')
15
+ .argument('<module>', 'module to execute')
16
+ .action(async (module, options) => {
17
+ await this.openBrowser(module, options);
18
+ });
19
+ }
20
+ async openBrowser(module, options) {
21
+ try {
22
+ await this.prologue(options);
23
+ if (process.env.DBREMOTE_URL === undefined)
24
+ throw 'DBREMOTE_URL undefined';
25
+ const url = process.env.DBREMOTE_URL + '/cyk/#/run/' + module;
26
+ const open = await import('open');
27
+ open.default(url);
28
+ }
29
+ catch (err) {
30
+ logger.error(err);
31
+ }
32
+ }
33
+ }
34
+ exports.OpenCommand = OpenCommand;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];