@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.
- package/build/AssetCommand.js +177 -43
- package/build/Cmd.d.ts +8 -0
- package/build/Cmd.js +50 -0
- package/build/DBClient.d.ts +11 -1
- package/build/DBClient.js +40 -2
- package/build/InitCommand.js +5 -1
- package/build/ModuleCommand.js +46 -6
- package/build/OpenCommand.d.ts +5 -0
- package/build/OpenCommand.js +34 -0
- package/build/RunCommand.js +5 -1
- package/build/TableCommand.js +43 -1
- package/build/TestCommand.js +5 -1
- package/build/UserCommand.js +8 -3
- package/build/console.js +5 -1
- package/build/index.js +2 -0
- package/package.json +5 -4
- package/src/AssetCommand.ts +191 -50
- package/src/Cmd.ts +59 -0
- package/src/DBClient.ts +50 -8
- package/src/ModuleCommand.ts +46 -5
- package/src/OpenCommand.ts +31 -0
- package/src/TableCommand.ts +41 -0
- package/src/UserCommand.ts +8 -3
- package/src/index.ts +2 -0
- package/test/t26.output +7 -0
- package/test/t26.xml +37 -0
- package/test/t27.output +2 -0
- package/test/t27.xml +18 -0
- package/tsconfig.json +1 -1
package/src/DBClient.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { BasicType, DBColumn, DBExecuteRequest, DBManager, DBTable, ObjectData, parseXML, PrimitiveData } from "@cyklang/core";
|
|
1
|
+
import { BasicType, DBColumn, DBExecuteRequest, DBManager, DBTable, ObjectData, parseXML, PrimitiveData, Script, variable2json, XmlError } from "@cyklang/core";
|
|
2
2
|
import loglevel from "loglevel";
|
|
3
|
+
import { errorconsole } from "./console";
|
|
3
4
|
const logger = loglevel.getLogger('DBClient.ts')
|
|
4
5
|
logger.setLevel('debug')
|
|
5
6
|
// DBManager wrapper class
|
|
@@ -10,12 +11,47 @@ export class DBClient {
|
|
|
10
11
|
this.dbManager = dbManager
|
|
11
12
|
}
|
|
12
13
|
|
|
14
|
+
/**
|
|
15
|
+
* method execInstructions
|
|
16
|
+
* @param source
|
|
17
|
+
*/
|
|
18
|
+
async execInstructions(source: string) {
|
|
19
|
+
const script = `<?xml-model href="https://www.cyklang.net/schema/cyklang.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
|
|
20
|
+
<module>
|
|
21
|
+
` + source + `
|
|
22
|
+
</module>`
|
|
23
|
+
await this.execScript(script)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* method execScript
|
|
28
|
+
* @param source
|
|
29
|
+
*/
|
|
30
|
+
async execScript(source: string) {
|
|
31
|
+
try {
|
|
32
|
+
const script = new Script(this.dbManager.scope, '', source)
|
|
33
|
+
await script.parseInstructions()
|
|
34
|
+
await script.execute()
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
console.log(source)
|
|
38
|
+
console.log()
|
|
39
|
+
if (err instanceof XmlError) {
|
|
40
|
+
let xmlError = <XmlError>err
|
|
41
|
+
errorconsole(xmlError)
|
|
42
|
+
}
|
|
43
|
+
console.log(err)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
13
47
|
async runQuery() {
|
|
14
48
|
|
|
15
49
|
}
|
|
16
|
-
|
|
50
|
+
|
|
17
51
|
async selectFromTable(title: string, tableName: string, options:
|
|
18
|
-
{ fields: string, sort?: string | undefined, where?: string | undefined, width?: string | undefined }) {
|
|
52
|
+
{ fields: string, sort?: string | undefined, where?: string | undefined, width?: string | undefined }): Promise<any[]> {
|
|
53
|
+
|
|
54
|
+
let result: any[] = []
|
|
19
55
|
|
|
20
56
|
try {
|
|
21
57
|
|
|
@@ -73,8 +109,13 @@ export class DBClient {
|
|
|
73
109
|
|
|
74
110
|
const objDataset = objXmlResult.variables.getData(tableName) as ObjectData
|
|
75
111
|
for (let ind = 0; ind < objDataset.variables.length(); ind++) {
|
|
76
|
-
const
|
|
77
|
-
|
|
112
|
+
const variable = objDataset.variables.at(ind)
|
|
113
|
+
if (variable) {
|
|
114
|
+
const record = (variable?.data as ObjectData)
|
|
115
|
+
list.addObjectData(record)
|
|
116
|
+
result.push(variable2json(variable))
|
|
117
|
+
}
|
|
118
|
+
|
|
78
119
|
}
|
|
79
120
|
logger.info(list.renderList(title))
|
|
80
121
|
|
|
@@ -82,6 +123,7 @@ export class DBClient {
|
|
|
82
123
|
catch (err) {
|
|
83
124
|
logger.error(err)
|
|
84
125
|
}
|
|
126
|
+
return result
|
|
85
127
|
}
|
|
86
128
|
|
|
87
129
|
async deleteModule(dbname: string) {
|
|
@@ -90,7 +132,7 @@ export class DBClient {
|
|
|
90
132
|
const dbModule = await this.dbManager.dbModuleExist(dbname)
|
|
91
133
|
|
|
92
134
|
if (dbModule === undefined) {
|
|
93
|
-
|
|
135
|
+
throw ('Module ' + dbname + ' not found')
|
|
94
136
|
}
|
|
95
137
|
await this.dbManager.dbModuleDelete(dbModule)
|
|
96
138
|
}
|
|
@@ -183,7 +225,7 @@ class List {
|
|
|
183
225
|
}
|
|
184
226
|
this.lines.push(this.renderSeparator())
|
|
185
227
|
this.lines.push('Number of lines : ' + this.rows.length)
|
|
186
|
-
|
|
228
|
+
|
|
187
229
|
return this.lines.join('\n')
|
|
188
230
|
}
|
|
189
231
|
|
|
@@ -238,7 +280,7 @@ class List {
|
|
|
238
280
|
}
|
|
239
281
|
|
|
240
282
|
// replace \n with a space
|
|
241
|
-
result = result.replace(/\n/, ' ')
|
|
283
|
+
result = result.replace(/\n/, ' ')
|
|
242
284
|
|
|
243
285
|
if (width !== undefined && width !== 0) {
|
|
244
286
|
if (result.length >= width) {
|
package/src/ModuleCommand.ts
CHANGED
|
@@ -14,11 +14,11 @@ export class ModuleCommand extends Command {
|
|
|
14
14
|
super(name)
|
|
15
15
|
this.description('manage modules')
|
|
16
16
|
// upload
|
|
17
|
-
this.addCommand(new
|
|
17
|
+
this.addCommand(new ModuleU('upload', `Upload local module file(s) to the database.
|
|
18
18
|
Module name is the base name of the file. If a module with the same name already exists, it will be updated.
|
|
19
19
|
Otherwise, a new module is inserted in the database. To rename a module, use option --id to indicate the module you want to rename`)
|
|
20
20
|
)
|
|
21
|
-
this.addCommand(new
|
|
21
|
+
this.addCommand(new ModuleU('u', 'shortcut for (u)pload'))
|
|
22
22
|
// download
|
|
23
23
|
this.addCommand(new ModuleDownload('download', 'download module files to the current directory'))
|
|
24
24
|
this.addCommand(new ModuleDownload('d', 'shortcut for (d)ownload'))
|
|
@@ -45,16 +45,57 @@ interface UploadOptions {
|
|
|
45
45
|
id: string | undefined
|
|
46
46
|
env: string | undefined
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* class ModuleU
|
|
51
|
+
*/
|
|
52
|
+
class ModuleU extends Cmd {
|
|
49
53
|
constructor(name: string, description: string) {
|
|
50
54
|
super(name)
|
|
51
55
|
this.description(description)
|
|
52
|
-
.option('
|
|
56
|
+
.option('--auth <auth_schema>', 'authentication schema : basic | token | cookie | any | none, default is none')
|
|
57
|
+
.option('--access <access_right>', 'access rights required')
|
|
58
|
+
.option('-i --id <id>', 'module ID to upload or update')
|
|
53
59
|
.argument('[files...]', 'local module file(s) to upload to the server')
|
|
54
60
|
.action(async (files: any, options: any) => {
|
|
55
|
-
await this.
|
|
61
|
+
await this.commandU(files, options)
|
|
56
62
|
})
|
|
57
63
|
}
|
|
64
|
+
|
|
65
|
+
async commandU(files: string[], options: any) {
|
|
66
|
+
if (files.length > 0) {
|
|
67
|
+
await this.commandUpload(files, options)
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
await this.commandUpdate(options)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* method commandUpdate
|
|
76
|
+
* @param options
|
|
77
|
+
*/
|
|
78
|
+
async commandUpdate(options: any) {
|
|
79
|
+
try {
|
|
80
|
+
await this.prologue(options)
|
|
81
|
+
if (this.dbManager === undefined) throw 'dbManager undefined'
|
|
82
|
+
|
|
83
|
+
if (options.id === undefined) throw '<id_or_route> of module to update is missing'
|
|
84
|
+
|
|
85
|
+
const dbModule = await this.dbManager.getModule(options.id)
|
|
86
|
+
|
|
87
|
+
await this.updateAuthAccess('cyk_module', 'module', dbModule.id || '', options)
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
logger.error(err)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* method commandUpload
|
|
96
|
+
* @param files
|
|
97
|
+
* @param options
|
|
98
|
+
*/
|
|
58
99
|
async commandUpload(files: string[], options: UploadOptions) {
|
|
59
100
|
try {
|
|
60
101
|
await this.prologue(options)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Cmd } from "./Cmd";
|
|
2
|
+
|
|
3
|
+
import loglevel from 'loglevel'
|
|
4
|
+
const logger = loglevel.getLogger('OpenCommand.ts')
|
|
5
|
+
logger.setLevel('debug')
|
|
6
|
+
|
|
7
|
+
export class OpenCommand extends Cmd {
|
|
8
|
+
constructor() {
|
|
9
|
+
super('open')
|
|
10
|
+
this.description('open browser').version('0.1')
|
|
11
|
+
.argument('<module>', 'module to execute')
|
|
12
|
+
.action(async (module: any, options: any) => {
|
|
13
|
+
await this.openBrowser(module, options)
|
|
14
|
+
})
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async openBrowser(module: string, options: any) {
|
|
18
|
+
try {
|
|
19
|
+
await this.prologue(options)
|
|
20
|
+
|
|
21
|
+
if (process.env.DBREMOTE_URL === undefined) throw 'DBREMOTE_URL undefined'
|
|
22
|
+
const url = process.env.DBREMOTE_URL + '/cyk/#/run/' + module;
|
|
23
|
+
const open = await import('open');
|
|
24
|
+
open.default(url)
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
logger.error(err)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
}
|
package/src/TableCommand.ts
CHANGED
|
@@ -22,6 +22,47 @@ export class TableCommand extends Command {
|
|
|
22
22
|
this.addCommand(new TableList('l', '(l)ist database tables'))
|
|
23
23
|
this.addCommand(new TableData('data', 'table (d)ata'))
|
|
24
24
|
this.addCommand(new TableData('d', 'table (d)ata'))
|
|
25
|
+
this.addCommand(new TableUpdate('update', 'update table properties'))
|
|
26
|
+
this.addCommand(new TableUpdate('u', 'shortcut for (u)pdate table properties'))
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* class TableUpdate
|
|
32
|
+
*/
|
|
33
|
+
class TableUpdate extends Cmd {
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @param name
|
|
38
|
+
* @param description
|
|
39
|
+
*/
|
|
40
|
+
constructor(name: string, description: string) {
|
|
41
|
+
super(name)
|
|
42
|
+
this.description(description)
|
|
43
|
+
.option('-n --name <table_name>', 'name of the table whose properties are to be changed')
|
|
44
|
+
.option('--auth <auth_schema>', 'authentication schema : basic | token | cookie | any | none, default is none')
|
|
45
|
+
.option('--access <access>', 'access rights required')
|
|
46
|
+
.action(async (options: any) => {
|
|
47
|
+
await this.commandUpdate(options)
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async commandUpdate(options: any) {
|
|
52
|
+
try {
|
|
53
|
+
await this.prologue(options)
|
|
54
|
+
if (this.dbManager === undefined) throw 'dbManager undefined'
|
|
55
|
+
|
|
56
|
+
if ( ! options.name ) throw '<table_name> is missing'
|
|
57
|
+
|
|
58
|
+
const dbTable = await this.dbManager.dbTableExist(options.name)
|
|
59
|
+
if ( ! dbTable ) throw 'Table ' + options.name + ' not found'
|
|
60
|
+
|
|
61
|
+
await this.updateAuthAccess('cyk_table', 'table', dbTable.id || '', options)
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
logger.error(err)
|
|
65
|
+
}
|
|
25
66
|
}
|
|
26
67
|
}
|
|
27
68
|
|
package/src/UserCommand.ts
CHANGED
|
@@ -17,6 +17,7 @@ export class UserCommand extends Command {
|
|
|
17
17
|
this.addCommand(new UserUpdateCmd('u', 'shortcut for (u)pdate'))
|
|
18
18
|
this.addCommand(new UserDeleteCmd('delete', 'delete user by id and name. Both options are mandatory to avoid typing error'))
|
|
19
19
|
this.addCommand(new UserPasswdCmd('passwd', 'change user password'))
|
|
20
|
+
this.addCommand(new UserPasswdCmd('p', 'shortcut for (p)asswd'))
|
|
20
21
|
this.addCommand(new UserListCmd('list', 'list users'))
|
|
21
22
|
this.addCommand(new UserListCmd('l', 'shortcut for (l)ist'))
|
|
22
23
|
}
|
|
@@ -41,7 +42,7 @@ class UserAddCmd extends Cmd {
|
|
|
41
42
|
this.description(description)
|
|
42
43
|
.requiredOption('-n --name <name>', 'user name')
|
|
43
44
|
.option('-e --email <email>', 'user email address')
|
|
44
|
-
.option('-p --
|
|
45
|
+
.option('-p --password <password>', 'initial password')
|
|
45
46
|
.option('-a --access <acl>', 'access control list')
|
|
46
47
|
.option('-m --module <module_name>', 'module to launch by default')
|
|
47
48
|
.option('-d --disable', 'user not abled to connect')
|
|
@@ -63,7 +64,11 @@ class UserAddCmd extends Cmd {
|
|
|
63
64
|
await this.prologue(options)
|
|
64
65
|
if (this.dbManager === undefined) throw 'dbManager undefined'
|
|
65
66
|
const result = await this.dbManager.dbUserInsert(dbUser)
|
|
66
|
-
logger.debug(result)
|
|
67
|
+
logger.debug('ID', result)
|
|
68
|
+
if (dbUser.password) {
|
|
69
|
+
await this.dbManager.dbUserPasswd(result, dbUser.password)
|
|
70
|
+
logger.info('password changed for user ' + dbUser.name)
|
|
71
|
+
}
|
|
67
72
|
}
|
|
68
73
|
catch (err) {
|
|
69
74
|
logger.error(err)
|
|
@@ -174,7 +179,7 @@ class UserDeleteCmd extends Cmd {
|
|
|
174
179
|
|
|
175
180
|
class UserPasswdCmd extends Cmd {
|
|
176
181
|
constructor(name: string, description: string) {
|
|
177
|
-
super(
|
|
182
|
+
super(name)
|
|
178
183
|
|
|
179
184
|
this.description(description)
|
|
180
185
|
.requiredOption('-i --id <id>', 'user ID')
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { TestCommand } from './TestCommand'
|
|
|
9
9
|
import { RunCommand } from './RunCommand'
|
|
10
10
|
import { InitCommand } from './InitCommand'
|
|
11
11
|
import { AssetCommand } from './AssetCommand'
|
|
12
|
+
import { OpenCommand } from './OpenCommand'
|
|
12
13
|
const logger = loglevel.getLogger("index.ts")
|
|
13
14
|
logger.setLevel("debug")
|
|
14
15
|
|
|
@@ -29,5 +30,6 @@ program.addCommand(new TableCommand('table'))
|
|
|
29
30
|
program.addCommand(new TableCommand('t'))
|
|
30
31
|
program.addCommand(new TestCommand())
|
|
31
32
|
program.addCommand(new RunCommand())
|
|
33
|
+
program.addCommand(new OpenCommand())
|
|
32
34
|
|
|
33
35
|
program.parse()
|
package/test/t26.output
CHANGED
|
@@ -3,3 +3,10 @@ date : <b>Gras</b> <i>Italic </i>
|
|
|
3
3
|
format 1 : Format sans paramètre
|
|
4
4
|
format 2 : Nom : CYK Final
|
|
5
5
|
format 3 : Nom : { CYK Prénom Philippe }
|
|
6
|
+
{"name":"CYK","surname":"Philippe","adresses":[{"town":"Saint-Denis","department":"Reunion"},{"town":"Paris","department":"Paris"}]}
|
|
7
|
+
var1 = undefined
|
|
8
|
+
var2 = undefined
|
|
9
|
+
var1 == var2
|
|
10
|
+
after set var2 from var1
|
|
11
|
+
var1 == var2
|
|
12
|
+
var1 == var3
|
package/test/t26.xml
CHANGED
|
@@ -31,5 +31,42 @@
|
|
|
31
31
|
</object>
|
|
32
32
|
|
|
33
33
|
<print>json(person)</print>
|
|
34
|
+
|
|
35
|
+
<string name="var1"/>
|
|
36
|
+
<string name="var2"/>
|
|
37
|
+
<print>"var1 = " + var1</print>
|
|
38
|
+
<print>"var2 = " + var2</print>
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
<if>
|
|
42
|
+
<condition>var1 == var2</condition>
|
|
43
|
+
<then>
|
|
44
|
+
<print>"var1 == var2"</print>
|
|
45
|
+
</then>
|
|
46
|
+
</if>
|
|
47
|
+
|
|
48
|
+
<set name="var2">var1</set>
|
|
49
|
+
<print>"after set var2 from var1"</print>
|
|
50
|
+
|
|
51
|
+
<if>
|
|
52
|
+
<condition>var1 == var2</condition>
|
|
53
|
+
<then>
|
|
54
|
+
<print>"var1 == var2"</print>
|
|
55
|
+
</then>
|
|
56
|
+
</if>
|
|
57
|
+
|
|
58
|
+
<string name="var3">var1</string>
|
|
59
|
+
|
|
60
|
+
<if>
|
|
61
|
+
<condition>var1 == var3</condition>
|
|
62
|
+
<then>
|
|
63
|
+
<print>"var1 == var3"</print>
|
|
64
|
+
</then>
|
|
65
|
+
<else>
|
|
66
|
+
<print>"var1 !== var3"</print>
|
|
67
|
+
</else>
|
|
68
|
+
</if>
|
|
69
|
+
|
|
70
|
+
|
|
34
71
|
|
|
35
72
|
</module>
|
package/test/t27.output
ADDED
package/test/t27.xml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<?xml-model href="https://www.cyklang.net/schema/cyklang.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
|
|
2
|
+
<module>
|
|
3
|
+
<print>objson('150')</print>
|
|
4
|
+
<string name="chaine" literal=""><![CDATA[
|
|
5
|
+
{
|
|
6
|
+
"user_id": 1,
|
|
7
|
+
"user_name": "cyk",
|
|
8
|
+
"user_email": "cyk@gmail.com",
|
|
9
|
+
"user_password": "$2b$10$Et1b0DodTNKxW/jvUFC8be8JrRXULHWC5RnwOjVhUXmVKv.CyfFW.",
|
|
10
|
+
"user_access": "admin",
|
|
11
|
+
"user_appli": null,
|
|
12
|
+
"user_disable": false,
|
|
13
|
+
"user_lang": null
|
|
14
|
+
}
|
|
15
|
+
]]>
|
|
16
|
+
</string>
|
|
17
|
+
<print>json(objson(chaine))</print>
|
|
18
|
+
</module>
|