@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.
@@ -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];
@@ -43,9 +47,47 @@ class TableCommand extends commander_1.Command {
43
47
  this.addCommand(new TableList('l', '(l)ist database tables'));
44
48
  this.addCommand(new TableData('data', 'table (d)ata'));
45
49
  this.addCommand(new TableData('d', 'table (d)ata'));
50
+ this.addCommand(new TableUpdate('update', 'update table properties'));
51
+ this.addCommand(new TableUpdate('u', 'shortcut for (u)pdate table properties'));
46
52
  }
47
53
  }
48
54
  exports.TableCommand = TableCommand;
55
+ /**
56
+ * class TableUpdate
57
+ */
58
+ class TableUpdate extends Cmd_1.Cmd {
59
+ /**
60
+ *
61
+ * @param name
62
+ * @param description
63
+ */
64
+ constructor(name, description) {
65
+ super(name);
66
+ this.description(description)
67
+ .option('-n --name <table_name>', 'name of the table whose properties are to be changed')
68
+ .option('--auth <auth_schema>', 'authentication schema : basic | token | cookie | any | none, default is none')
69
+ .option('--access <access>', 'access rights required')
70
+ .action(async (options) => {
71
+ await this.commandUpdate(options);
72
+ });
73
+ }
74
+ async commandUpdate(options) {
75
+ try {
76
+ await this.prologue(options);
77
+ if (this.dbManager === undefined)
78
+ throw 'dbManager undefined';
79
+ if (!options.name)
80
+ throw '<table_name> is missing';
81
+ const dbTable = await this.dbManager.dbTableExist(options.name);
82
+ if (!dbTable)
83
+ throw 'Table ' + options.name + ' not found';
84
+ await this.updateAuthAccess('cyk_table', 'table', dbTable.id || '', options);
85
+ }
86
+ catch (err) {
87
+ logger.error(err);
88
+ }
89
+ }
90
+ }
49
91
  class TableExportCmd extends Cmd_1.Cmd {
50
92
  constructor() {
51
93
  super('export');
@@ -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];
@@ -22,6 +22,7 @@ class UserCommand extends commander_1.Command {
22
22
  this.addCommand(new UserUpdateCmd('u', 'shortcut for (u)pdate'));
23
23
  this.addCommand(new UserDeleteCmd('delete', 'delete user by id and name. Both options are mandatory to avoid typing error'));
24
24
  this.addCommand(new UserPasswdCmd('passwd', 'change user password'));
25
+ this.addCommand(new UserPasswdCmd('p', 'shortcut for (p)asswd'));
25
26
  this.addCommand(new UserListCmd('list', 'list users'));
26
27
  this.addCommand(new UserListCmd('l', 'shortcut for (l)ist'));
27
28
  }
@@ -33,7 +34,7 @@ class UserAddCmd extends Cmd_1.Cmd {
33
34
  this.description(description)
34
35
  .requiredOption('-n --name <name>', 'user name')
35
36
  .option('-e --email <email>', 'user email address')
36
- .option('-p --passwd <password>', 'initial password')
37
+ .option('-p --password <password>', 'initial password')
37
38
  .option('-a --access <acl>', 'access control list')
38
39
  .option('-m --module <module_name>', 'module to launch by default')
39
40
  .option('-d --disable', 'user not abled to connect')
@@ -56,7 +57,11 @@ class UserAddCmd extends Cmd_1.Cmd {
56
57
  if (this.dbManager === undefined)
57
58
  throw 'dbManager undefined';
58
59
  const result = await this.dbManager.dbUserInsert(dbUser);
59
- logger.debug(result);
60
+ logger.debug('ID', result);
61
+ if (dbUser.password) {
62
+ await this.dbManager.dbUserPasswd(result, dbUser.password);
63
+ logger.info('password changed for user ' + dbUser.name);
64
+ }
60
65
  }
61
66
  catch (err) {
62
67
  logger.error(err);
@@ -173,7 +178,7 @@ class UserDeleteCmd extends Cmd_1.Cmd {
173
178
  }
174
179
  class UserPasswdCmd extends Cmd_1.Cmd {
175
180
  constructor(name, description) {
176
- super('passwd');
181
+ super(name);
177
182
  this.description(description)
178
183
  .requiredOption('-i --id <id>', 'user ID')
179
184
  .requiredOption('-n --name <name>', 'user name')
package/build/console.js CHANGED
@@ -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];
package/build/index.js CHANGED
@@ -14,6 +14,7 @@ const TestCommand_1 = require("./TestCommand");
14
14
  const RunCommand_1 = require("./RunCommand");
15
15
  const InitCommand_1 = require("./InitCommand");
16
16
  const AssetCommand_1 = require("./AssetCommand");
17
+ const OpenCommand_1 = require("./OpenCommand");
17
18
  const logger = loglevel_1.default.getLogger("index.ts");
18
19
  logger.setLevel("debug");
19
20
  const program = new commander_1.Command();
@@ -32,4 +33,5 @@ program.addCommand(new TableCommand_1.TableCommand('table'));
32
33
  program.addCommand(new TableCommand_1.TableCommand('t'));
33
34
  program.addCommand(new TestCommand_1.TestCommand());
34
35
  program.addCommand(new RunCommand_1.RunCommand());
36
+ program.addCommand(new OpenCommand_1.OpenCommand());
35
37
  program.parse();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cyklang/cli",
3
- "version": "0.3.1",
3
+ "version": "0.5.0",
4
4
  "description": "cyklang CLI",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
@@ -17,13 +17,14 @@
17
17
  "author": "",
18
18
  "license": "ISC",
19
19
  "dependencies": {
20
- "@cyklang/core": "^0.5.0",
20
+ "@cyklang/core": "^0.5.2",
21
21
  "commander": "^9.4.0",
22
22
  "dotenv": "^16.0.1",
23
23
  "form-data": "^4.0.0",
24
24
  "inquirer": "^8.2.5",
25
25
  "loglevel": "^1.8.0",
26
26
  "mime-types": "^2.1.35",
27
+ "open": "^9.1.0",
27
28
  "pako": "^2.0.4"
28
29
  },
29
30
  "devDependencies": {
@@ -32,8 +33,8 @@
32
33
  "@types/pako": "^2.0.0",
33
34
  "@types/sax": "^1.2.4",
34
35
  "nodemon": "^2.0.16",
35
- "ts-node": "^10.7.0",
36
- "typescript": "4.5.2"
36
+ "ts-node": "^10.9.1",
37
+ "typescript": "^5.2.2"
37
38
  },
38
39
  "bin": {
39
40
  "cyk": "build/index.js"
@@ -7,27 +7,144 @@ import path from "path"
7
7
  import mime from 'mime-types'
8
8
  import inquirer from 'inquirer'
9
9
  // import readline from 'readline'
10
- import { DBAsset, DBExecuteRequest, ObjectData, parseXML, PrimitiveData } from "@cyklang/core"
10
+ import { DBAsset, DBExecuteRequest, DBManager, ObjectData, parseXML, PrimitiveData } from "@cyklang/core"
11
11
  import FormData from 'form-data'
12
12
 
13
13
  const logger = getLogger('AssetCommand.ts')
14
14
  logger.setLevel('debug')
15
15
 
16
+
17
+ //----------------------------------------------------------------------------------------------
18
+ // scanAssets
19
+ //----------------------------------------------------------------------------------------------
20
+
21
+ const scanAssets = async (dbManager: DBManager | undefined, dest?: string): Promise<FileDescriptor[]> => {
22
+
23
+ const result: FileDescriptor[] = []
24
+ if (dbManager === undefined) throw 'dbManager undefined'
25
+ const dbReq = new DBExecuteRequest()
26
+ dbReq.selectFromTable = 'cyk_asset'
27
+ const pFields = dbReq.parameters.addVariable('fields', dbManager.scope.structure.stringDataType)
28
+ pFields.data = new PrimitiveData(dbManager.scope.structure.stringDataType, "asset_id,asset_route,asset_last_update,asset_mimetype")
29
+ const xmlResult = await dbManager.dbExecute(dbReq)
30
+ if (xmlResult === undefined || xmlResult === null) throw 'xmlResult null or undefined'
31
+ const tag = parseXML('scanAssets', xmlResult)
32
+ const objResult = await dbManager.scope.structure.objectDataType.parseData(tag, dbManager.scope) as ObjectData
33
+ const rows = (objResult.variables.getData('cyk_asset') as ObjectData).variables
34
+ for (let ind = 0; ind < rows.list.length; ind++) {
35
+ const { variable: row } = rows.list[ind]
36
+ const record = row.data as ObjectData
37
+ const asset_id = (record.variables.getData('asset_id') as PrimitiveData).value as number
38
+ const asset_route = (record.variables.getData('asset_route') as PrimitiveData).value as string
39
+ const asset_last_update = (record.variables.getData('asset_last_update') as PrimitiveData)?.value as Date
40
+ // logger.debug('asset_route ' + asset_route,'asset_last_update ' + asset_last_update)
41
+
42
+ if (!dest || asset_route.startsWith(dest))
43
+ result.push({ path: asset_route, mtime: asset_last_update, id: asset_id })
44
+ }
45
+ return result
46
+ }
47
+
16
48
  export class AssetCommand extends Command {
17
49
  constructor(name: string, description: string) {
18
50
  super(name)
19
51
  this.description(description)
20
52
  this.addCommand(new AssetList('list', 'list assets'))
21
53
  this.addCommand(new AssetList('l', '(l)ist assets'))
22
- this.addCommand(new AssetUpload('upload', 'upload assets from sources'))
23
- this.addCommand(new AssetUpload('u', '(u)pload assets'))
54
+ this.addCommand(new AssetU('upload', 'upload asset content from source files to a <destination> path'))
55
+ this.addCommand(new AssetU('update', 'update properties of asset identified by its <id>'))
56
+ this.addCommand(new AssetU('u', '(u)pload assets content from sources or (u)pdate asset properties'))
57
+ this.addCommand(new AssetDelete('delete', 'delete an asset'))
58
+ }
59
+ }
60
+
61
+ /**
62
+ * class AssetDelete
63
+ */
64
+ class AssetDelete extends Cmd {
65
+ constructor(name: string, description: string) {
66
+ super(name)
67
+ this.description(description)
68
+ .option('-i --id <id_pathname>', 'asset id or pathname to delete')
69
+ .option('-d --dest <destination>', 'delete all assets whose pathname begins with dest')
70
+ .action(async (options: any) => {
71
+ if (options.id)
72
+ await this.commandDeleteOne(options)
73
+ else if (options.dest) {
74
+ await this.commandDeletePathname(options)
75
+ }
76
+ else {
77
+ logger.error('one of --id or --dest options is required')
78
+ }
79
+ })
80
+ }
81
+
82
+ /**
83
+ *
84
+ * @param options
85
+ */
86
+ async commandDeleteOne(options: any) {
87
+ try {
88
+ await this.prologue(options)
89
+ if (this.dbManager === undefined) throw 'dbManager undefined'
90
+
91
+ if (options.id === undefined) throw '<id_or_pathname> of asset to delete is missing'
92
+
93
+ if (!options.id.startsWith('/')) throw '-i --id only pathname is supported at the moment'
94
+
95
+ const dbAsset = await this.dbManager.dbAssetExist(options.id)
96
+ if (dbAsset === undefined) throw 'Asset ' + options.id + ' not found'
97
+
98
+ await this.dbManager.dbAssetDelete(dbAsset)
99
+
100
+ logger.info('asset ' + dbAsset.id + ' ' + dbAsset.route + ' deleted')
101
+ }
102
+ catch (err) {
103
+ logger.error(err)
104
+ }
105
+ }
106
+
107
+ /**
108
+ *
109
+ * @param options
110
+ */
111
+ async commandDeletePathname(options: any) {
112
+
113
+ try {
114
+ await this.prologue(options)
115
+ if (! this.dbManager) throw 'dbManager undefined'
116
+ const dbClient = new DBClient(this.dbManager)
117
+ const list = await dbClient.selectFromTable('Assets to delete', 'cyk_asset',
118
+ {
119
+ fields: 'asset_id,asset_route,asset_auth,asset_access,asset_mimetype,asset_last_update', sort: options.sort || '1',
120
+ where: (options.dest ? "asset_route like '" + options.dest + "%'" : undefined)
121
+ }
122
+
123
+ );
124
+ const reply = await inquirer.prompt({type: 'confirm', name: 'confirm', message: 'Do you want to delete these ' + list.length + ' file(s)'})
125
+ if (reply.confirm) {
126
+ for(let ind = 0; ind < list.length; ind++) {
127
+ const asset = list[ind]
128
+ logger.info('delete ' + asset.asset_route)
129
+ const url = '/api/admin/assets/' + asset.asset_id
130
+ await this.dbRemote?.apiServer.delete(url)
131
+ }
132
+ }
133
+
134
+ }
135
+ catch (err) {
136
+ logger.error(err)
137
+ }
138
+
24
139
  }
140
+
25
141
  }
26
142
 
27
143
  class AssetList extends Cmd {
28
144
  constructor(name: string, description: string) {
29
145
  super(name)
30
146
  this.description(description)
147
+ .option('-d --dest <destination>', 'filter assets whose pathname begins with destination')
31
148
  .option('-s --sort <columns>', 'sort list by column numbers (begins by 0) separated by comma')
32
149
  .action(async (options: any) => { await this.commandList(options) })
33
150
  }
@@ -38,7 +155,11 @@ class AssetList extends Cmd {
38
155
 
39
156
  const dbClient = new DBClient(this.dbManager)
40
157
  dbClient.selectFromTable('List of Assets', 'cyk_asset',
41
- { fields: 'asset_id,asset_route,asset_auth,asset_access,asset_mimetype,asset_last_update', sort: options.sort || '1' }
158
+ {
159
+ fields: 'asset_id,asset_route,asset_auth,asset_access,asset_mimetype,asset_last_update', sort: options.sort || '1',
160
+ where: (options.dest ? "asset_route like '" + options.dest + "%'" : undefined)
161
+ }
162
+
42
163
  )
43
164
  }
44
165
  catch (err) {
@@ -47,27 +168,28 @@ class AssetList extends Cmd {
47
168
  }
48
169
  }
49
170
 
50
- //----------------------------------------------------------------------------------------------
51
- // class AssetUpload
52
- //----------------------------------------------------------------------------------------------
53
-
54
171
  interface FileDescriptor {
55
172
  path: string
56
173
  mtime: Date
57
174
  id?: number
58
175
  }
59
- class AssetUpload extends Cmd {
176
+ /**
177
+ * class AssetU
178
+ */
179
+ class AssetU extends Cmd {
60
180
 
61
181
  constructor(name: string, description: string) {
62
182
  super(name)
63
183
  this.description(description)
64
- .option('-a --auth <auth_schema>', 'authentication schema : basic | token | any, default is no authentication')
184
+ .option('-i --id <id>', 'asset id or pathname whose properties are updated')
185
+ .option('--auth <auth_schema>', 'authentication schema : basic | token | cookie | any | none, default is none')
186
+ .option('--access <access>', 'access rights required')
65
187
  .option('-d --dest <destination>', 'destination path, directory name')
66
188
  .option('-c --clean', 'clean destination path before uploading')
67
189
  .option('-y --yes', 'upload list is automatically confirmed')
68
190
  .argument('[sources...]', 'local files or directories to upload as assets to the server')
69
191
  .action(async (sources: any, options: any) => {
70
- await this.commandUpload(sources, options)
192
+ await this.commandU(sources, options)
71
193
  })
72
194
  }
73
195
 
@@ -82,6 +204,53 @@ class AssetUpload extends Cmd {
82
204
  return result
83
205
  }
84
206
 
207
+ /**
208
+ * method commandU
209
+ * @param sources
210
+ * @param options
211
+ */
212
+ async commandU(sources: string[], options: any) {
213
+ if (sources.length > 0) {
214
+ // upload
215
+ // logger.debug('upload sources :', sources)
216
+ await this.commandUpload(sources, options)
217
+ }
218
+ else {
219
+ // update
220
+ // logger.debug('update', options)
221
+ await this.commandUpdate(options)
222
+ }
223
+ }
224
+
225
+ /**
226
+ * method commandUpdate
227
+ * @param options
228
+ */
229
+ async commandUpdate(options: any) {
230
+ try {
231
+ await this.prologue(options)
232
+ if (this.dbManager === undefined) throw 'dbManager undefined'
233
+
234
+ if (options.id === undefined) throw '<id_or_pathname> of asset to update is missing'
235
+
236
+ if (!options.id.startsWith('/')) throw '-i --id only pathname is supported at the moment'
237
+
238
+ const dbAsset = await this.dbManager.dbAssetExist(options.id)
239
+ if (dbAsset === undefined) throw 'Asset ' + options.id + ' not found'
240
+
241
+ await this.updateAuthAccess('cyk_asset', 'asset', dbAsset.id || '', options)
242
+
243
+ }
244
+ catch (err) {
245
+ logger.error(err)
246
+ }
247
+ }
248
+
249
+ /**
250
+ * method commandUpload
251
+ * @param sources
252
+ * @param options
253
+ */
85
254
  async commandUpload(sources: string[], options: any) {
86
255
 
87
256
  try {
@@ -90,11 +259,11 @@ class AssetUpload extends Cmd {
90
259
 
91
260
  if (sources.length === 0) throw 'no source to upload'
92
261
 
93
- if ( options.auth && ' basic | token | any '.indexOf(options.auth) === -1 ) {
94
- throw 'valid authentication schemas are : basic | token | any'
262
+ if (options.auth && ' basic | token | cookie | any | none'.indexOf(options.auth) === -1) {
263
+ throw 'valid authentication schemas are : basic | token | cookie | any | none'
95
264
  }
96
- logger.debug('options : ', options)
97
- logger.debug('auth : ' + options.auth)
265
+ // logger.debug('options : ', options)
266
+ // logger.debug('auth : ' + options.auth)
98
267
 
99
268
  let dest = "/"
100
269
  if (options.dest !== undefined) dest = options.dest
@@ -130,8 +299,8 @@ class AssetUpload extends Cmd {
130
299
 
131
300
  async cleanDestination(dest: string) {
132
301
 
133
- const remoteList = await this.scanAssets()
134
- for(let ind = 0; ind < remoteList.length; ind++) {
302
+ const remoteList = await scanAssets(this.dbManager)
303
+ for (let ind = 0; ind < remoteList.length; ind++) {
135
304
  const fd = remoteList[ind]
136
305
  if (fd.path.startsWith(dest)) {
137
306
  const url = '/api/admin/assets/' + fd.id
@@ -156,11 +325,11 @@ class AssetUpload extends Cmd {
156
325
  dirName = source + '/'
157
326
  }
158
327
 
159
- logger.debug('options', options)
328
+ // logger.debug('options', options)
160
329
 
161
330
  this.scanDir(dirName, localList)
162
331
 
163
- const remoteList = await this.scanAssets()
332
+ const remoteList = await scanAssets(this.dbManager)
164
333
 
165
334
  const uploadList = this.buildUploadList(dirName, dest, localList, remoteList)
166
335
 
@@ -216,35 +385,6 @@ class AssetUpload extends Cmd {
216
385
  return result
217
386
  }
218
387
 
219
-
220
- //----------------------------------------------------------------------------------------------
221
- // scanAssets
222
- //----------------------------------------------------------------------------------------------
223
-
224
- async scanAssets() {
225
- const result: FileDescriptor[] = []
226
- if (this.dbManager === undefined) throw 'dbManager undefined'
227
- const dbReq = new DBExecuteRequest()
228
- dbReq.selectFromTable = 'cyk_asset'
229
- const pFields = dbReq.parameters.addVariable('fields', this.dbManager.scope.structure.stringDataType)
230
- pFields.data = new PrimitiveData(this.dbManager.scope.structure.stringDataType, "asset_id,asset_route,asset_last_update,asset_mimetype")
231
- const xmlResult = await this.dbManager.dbExecute(dbReq)
232
- if (xmlResult === undefined || xmlResult === null) throw 'xmlResult null or undefined'
233
- const tag = parseXML('scanAssets', xmlResult)
234
- const objResult = await this.dbManager.scope.structure.objectDataType.parseData(tag, this.dbManager.scope) as ObjectData
235
- const rows = (objResult.variables.getData('cyk_asset') as ObjectData).variables
236
- for (let ind = 0; ind < rows.list.length; ind++) {
237
- const { variable: row } = rows.list[ind]
238
- const record = row.data as ObjectData
239
- const asset_id = (record.variables.getData('asset_id') as PrimitiveData).value as number
240
- const asset_route = (record.variables.getData('asset_route') as PrimitiveData).value as string
241
- const asset_last_update = (record.variables.getData('asset_last_update') as PrimitiveData)?.value as Date
242
- // logger.debug('asset_route ' + asset_route,'asset_last_update ' + asset_last_update)
243
- result.push({ path: asset_route, mtime: asset_last_update, id: asset_id })
244
- }
245
- return result
246
- }
247
-
248
388
  //----------------------------------------------------------------------------------------------
249
389
  // scanDir
250
390
  //----------------------------------------------------------------------------------------------
@@ -302,7 +442,7 @@ class AssetUpload extends Cmd {
302
442
  //----------------------------------------------------------------------------------------------
303
443
 
304
444
  async uploadAsset(upload: FileDescriptor, route: string, auth?: string) {
305
- logger.debug('uploadAsset ' + upload.path + ' to route ' + route + ' with mimetype ' + this.mimetypeLookup(upload.path) + ', auth : ' + auth)
445
+ // logger.debug('uploadAsset ' + upload.path + ' to route ' + route + ' with mimetype ' + this.mimetypeLookup(upload.path) + ', auth : ' + auth)
306
446
 
307
447
  try {
308
448
  let dbAsset: DBAsset | undefined = await this.dbManager?.dbAssetExist(route)
@@ -314,7 +454,8 @@ class AssetUpload extends Cmd {
314
454
  dbAsset.mimetype = mimetype
315
455
  dbAsset.route = route
316
456
  dbAsset.auth = auth
317
-
457
+ if (dbAsset.auth === 'none') dbAsset.auth = undefined
458
+
318
459
  // const fstat = fs.statSync(fileName)
319
460
  dbAsset.last_update = upload.mtime
320
461
 
package/src/Cmd.ts CHANGED
@@ -3,6 +3,7 @@ import { Command } from "commander";
3
3
  import dotenv from 'dotenv'
4
4
  import loglevel from 'loglevel'
5
5
  import { NodeCrypto } from "./NodeCrypto";
6
+ import { DBClient } from "./DBClient";
6
7
  const logger = loglevel.getLogger('Cmd.ts')
7
8
  logger.setLevel('debug')
8
9
 
@@ -35,4 +36,62 @@ export class Cmd extends Command {
35
36
 
36
37
 
37
38
  }
39
+
40
+ /**
41
+ * method updateAuthAccess
42
+ * @param tableName
43
+ * @param prefix
44
+ * @param id
45
+ * @param options
46
+ */
47
+ async updateAuthAccess(tableName: string, prefix: string, id: string, options: any) {
48
+
49
+ try {
50
+
51
+ let dclAuth: string | undefined
52
+
53
+ if (options.auth) {
54
+ if (' basic | token | cookie | any | none | null '.indexOf(' ' + options.auth + ' ') === -1) {
55
+ throw 'valid authentication schemas are : basic | token | cookie | any | null'
56
+ }
57
+ dclAuth = `<string name='${prefix}_auth'>`
58
+ if (' none | null '.indexOf(' ' + options.auth + ' ') === -1)
59
+ dclAuth += ` "${options.auth}" `
60
+ else
61
+ dclAuth += ' null '
62
+ dclAuth += "</string>"
63
+ }
64
+
65
+ let dclAccess: string | undefined
66
+
67
+ if (options.access) {
68
+
69
+ dclAccess = `<string name='${prefix}_access'> `
70
+ if (' null | none '.indexOf(' ' + options.access + ' ') === -1)
71
+ dclAccess += `"${options.access}"`
72
+ else
73
+ dclAccess += ' null '
74
+ dclAccess += "</string>"
75
+ }
76
+
77
+ const inst = `
78
+ <db.update table='${tableName}'>
79
+ <object>
80
+ <number name='${prefix}_id'>${id}</number>
81
+ ${dclAuth}
82
+ ${dclAccess ? dclAccess : ''}
83
+ </object>
84
+ </db.update>
85
+ `
86
+
87
+ if (! this.dbManager) throw 'prologue() has not been called before'
88
+
89
+ const dbClient = new DBClient(this.dbManager)
90
+ dbClient.execInstructions(inst)
91
+ }
92
+ catch (err) {
93
+ logger.error(err)
94
+ throw err
95
+ }
96
+ }
38
97
  }