@cyklang/cli 0.8.0 → 0.8.3

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/test/t27.output CHANGED
@@ -1,2 +1,4 @@
1
1
  150
2
2
  {"user_id":1,"user_name":"cyk","user_email":"cyk@gmail.com","user_password":"$2b$10$Et1b0DodTNKxW/jvUFC8be8JrRXULHWC5RnwOjVhUXmVKv.CyfFW.","user_access":"admin","user_appli":null,"user_disable":false,"user_lang":null}
3
+ Paris coordinates : <number name="lon">2.3488</number>
4
+ <number name="lat">48.8534</number>
package/test/t27.xml CHANGED
@@ -1,4 +1,4 @@
1
- <?xml-model href="https://www.cyklang.net/schema/cyklang.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
1
+ <?xml-model href="../../../../VueProjects/docs-vuepress/docs/.vuepress/public/cyklang.xsd" type="application/xml" schematypens="http://www.w3.org/2001/XMLSchema"?>
2
2
  <module>
3
3
  <print>objson('150')</print>
4
4
  <string name="chaine" literal=""><![CDATA[
@@ -15,4 +15,25 @@
15
15
  ]]>
16
16
  </string>
17
17
  <print>json(objson(chaine))</print>
18
+
19
+ <object name="resp"/>
20
+
21
+ <fetch method="get" returns="resp" >
22
+ <string name="origin">"https://api.openweathermap.org"</string>
23
+ <string name="pathname">"/data/2.5/weather"</string>
24
+ <object name="search">
25
+ <string name="q">"paris,fr"</string>
26
+ <string name="units">"metric"</string>
27
+ <string name="lang">"fr"</string>
28
+ <string name="APPID">env("OPENWEATHER_API_KEY")</string>
29
+ </object>
30
+ </fetch>
31
+ <print>'Paris coordinates : ' + string(resp.json.coord)</print>
32
+ <!--
33
+ <print>"icon: " + resp.json.weather.at(0).icon
34
+ + ", description: "
35
+ + resp.json.weather.at(0).description
36
+ + ", temp: " + resp.json.main.temp + "°C"
37
+ </print> -->
38
+
18
39
  </module>
@@ -1,5 +0,0 @@
1
- import { Cmd } from "./Cmd";
2
- export declare class TableDataCommand extends Cmd {
3
- constructor(name: string, description: string);
4
- commandData(table: string, options: any): Promise<void>;
5
- }
@@ -1,61 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TableDataCommand = void 0;
4
- const Cmd_1 = require("./Cmd");
5
- const DBClient_1 = require("./DBClient");
6
- const TableCommand_1 = require("./TableCommand");
7
- //--------------------------------------------------------------------------------------------------------------------
8
- // class TableData
9
- //--------------------------------------------------------------------------------------------------------------------
10
- class TableDataCommand extends Cmd_1.Cmd {
11
- constructor(name, description) {
12
- super(name);
13
- this.description(description)
14
- .argument('<table>', 'table name')
15
- .option('--where <clause_where_sql>', 'criteria in SQL syntax')
16
- .option('-s --sort <columns>', 'sort by columns positions (begins by 0) separated by comma')
17
- .option('-w --width <colwidth>', 'columns widths separated by comma')
18
- .action(async (table, options) => {
19
- this.commandData(table, options);
20
- });
21
- }
22
- async commandData(table, options) {
23
- try {
24
- await this.prologue(options);
25
- if (this.dbManager === undefined)
26
- throw 'dbManager undefined';
27
- const dbTable = await this.dbManager.dbTableExist(table);
28
- if (dbTable === undefined)
29
- throw 'table ' + table + ' not found';
30
- let fields = '';
31
- for (let ind = 0; ind < dbTable.columns.length; ind++) {
32
- const dbColumn = dbTable.columns[ind];
33
- let ok = false;
34
- let fieldName = dbColumn.name;
35
- if (dbColumn.dbType === 'text' || dbColumn.dbType === 'bytea') {
36
- ok = false;
37
- fieldName = 'length(' + dbColumn.name + ')';
38
- }
39
- else {
40
- ok = true;
41
- }
42
- if (ok === true) {
43
- if (fields !== '')
44
- fields += ',';
45
- fields += fieldName;
46
- }
47
- }
48
- TableCommand_1.logger.debug('commandQuery', table);
49
- const dbClient = new DBClient_1.DBClient(this.dbManager);
50
- let title = 'Table ' + table;
51
- if (options.where !== undefined) {
52
- title += ' where ' + options.where;
53
- }
54
- dbClient.selectFromTable(title, table, { fields: fields, width: options.width, sort: options.sort || '1', where: options.where });
55
- }
56
- catch (err) {
57
- TableCommand_1.logger.error(err);
58
- }
59
- }
60
- }
61
- exports.TableDataCommand = TableDataCommand;
@@ -1,5 +0,0 @@
1
- import { Cmd } from "./Cmd";
2
- export declare class TestCommand extends Cmd {
3
- constructor();
4
- testRun(files: string[], options: any): Promise<void>;
5
- }
@@ -1,111 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.TestCommand = void 0;
26
- const core_1 = require("@cyklang/core");
27
- const fs = __importStar(require("fs"));
28
- const console_1 = require("./console");
29
- const loglevel_1 = __importDefault(require("loglevel"));
30
- const NodeCrypto_1 = require("./NodeCrypto");
31
- const Cmd_1 = require("./Cmd");
32
- loglevel_1.default.setLevel('debug');
33
- const logger = loglevel_1.default.getLogger('TestCommand.ts');
34
- class TestCommand extends Cmd_1.Cmd {
35
- constructor() {
36
- super('test');
37
- this.description('test script').version('0.1')
38
- .argument('<files...>', 'local module file(s) to test run')
39
- .action(async (files, options) => {
40
- await this.testRun(files, options);
41
- });
42
- }
43
- async testRun(files, options) {
44
- try {
45
- await this.prologue(options);
46
- for (let ind = 0; ind < files.length; ind++) {
47
- const result = await testfile(files[ind]);
48
- if (result === false) {
49
- logger.debug('*********** FAILURE ' + process.argv[ind] + ' ***************');
50
- }
51
- }
52
- }
53
- catch (err) {
54
- logger.error(err);
55
- }
56
- }
57
- }
58
- exports.TestCommand = TestCommand;
59
- async function testfile(filename) {
60
- let result;
61
- if (filename.indexOf(".") !== -1) {
62
- filename = filename.substring(0, filename.indexOf("."));
63
- }
64
- let xmlfilename = filename + ".xml";
65
- let logfilename = filename + ".log";
66
- let outfilename = filename + ".output";
67
- let xml = fs.readFileSync(xmlfilename);
68
- fs.writeFileSync(logfilename, "");
69
- //console.log(xml.toString())
70
- try {
71
- if (process.env.DBREMOTE_URL === undefined)
72
- throw 'DBREMOTE_URL undefined';
73
- logger.trace('DBREMOTE_URL ' + process.env.DBREMOTE_URL);
74
- const structure = new core_1.Structure();
75
- const nodeCrypto = new NodeCrypto_1.NodeCrypto();
76
- const dbRemote = new core_1.DBRemote(structure.scope, process.env.DBREMOTE_URL, nodeCrypto);
77
- const login = await dbRemote.signin(process.env.USER_NAME, undefined, process.env.USER_PASSWORD);
78
- //const dbRemote = new DBRemote(structure, 'https://cyk-postgres.herokuapp.com')
79
- const dbManager = new core_1.DBManager(structure.scope, dbRemote);
80
- await dbManager.initialize();
81
- structure.scope.addInstructionType(new console_1.PrintInstructionType(logfilename));
82
- let script = new core_1.Script(structure.scope, xmlfilename, xml.toString());
83
- await script.parseInstructions();
84
- await script.execute();
85
- // console.log(JSON.stringify(script.block.toString()))
86
- }
87
- catch (err) {
88
- if (err instanceof core_1.XmlError) {
89
- let xmlError = err;
90
- (0, console_1.errorconsole)(xmlError);
91
- }
92
- console.log(err);
93
- }
94
- let log = fs.readFileSync(logfilename);
95
- if (fs.existsSync(outfilename) === true) {
96
- let out = fs.readFileSync(outfilename);
97
- if (log.toString() === out.toString()) {
98
- console.log("test " + xmlfilename + " SUCCESS");
99
- result = true;
100
- }
101
- else {
102
- console.log("test " + xmlfilename + " FAILURE");
103
- result = false;
104
- }
105
- }
106
- else {
107
- console.log("test " + xmlfilename + " output file not found ");
108
- result = false;
109
- }
110
- return result;
111
- }
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env ts-node
2
- export {};
package/build/cykquery.js DELETED
@@ -1,145 +0,0 @@
1
- #!/usr/bin/env ts-node
2
- "use strict";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
6
- }) : (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- o[k2] = m[k];
9
- }));
10
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
11
- Object.defineProperty(o, "default", { enumerable: true, value: v });
12
- }) : function(o, v) {
13
- o["default"] = v;
14
- });
15
- var __importStar = (this && this.__importStar) || function (mod) {
16
- if (mod && mod.__esModule) return mod;
17
- var result = {};
18
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
19
- __setModuleDefault(result, mod);
20
- return result;
21
- };
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const cyk_core_1 = require("@cyk-language/cyk-core");
27
- const fs = __importStar(require("fs"));
28
- const loglevel_1 = __importDefault(require("loglevel"));
29
- const path_1 = __importDefault(require("path"));
30
- const dotenv_1 = __importDefault(require("dotenv"));
31
- const logger = loglevel_1.default.getLogger("model.ts");
32
- logger.setLevel("debug");
33
- dotenv_1.default.config();
34
- const main = async () => {
35
- const structure = new cyk_core_1.Structure();
36
- if (process.env.DBREMOTE_URL === undefined)
37
- throw 'DBREMOTE_URL undefined';
38
- logger.debug('DBREMOTE_URL ' + process.env.DBREMOTE_URL);
39
- const dbRemote = new cyk_core_1.DBRemote(structure.scope, process.env.DBREMOTE_URL);
40
- const login = await dbRemote.signin(process.env.USER_NAME, undefined, process.env.USER_PASSWORD);
41
- logger.debug(login);
42
- const dbManager = new cyk_core_1.DBManager(structure.scope, dbRemote);
43
- await dbManager.initialize();
44
- const { command, filepath, basename } = parseCommandLine();
45
- const xmlSource = fs.readFileSync(filepath).toString();
46
- let tag = parseXmlFile(filepath, basename, xmlSource);
47
- if (command === Command.Exec || command === Command.ExecTest) {
48
- await executeXml(structure, tag, xmlSource);
49
- }
50
- if (command === Command.Test || command === Command.ExecTest) {
51
- await testQuery(structure, tag.attributes.NAME);
52
- }
53
- };
54
- main().then(() => logger.debug('finished'));
55
- var Command;
56
- (function (Command) {
57
- Command["Exec"] = "exec";
58
- Command["ExecTest"] = "exectest";
59
- Command["Test"] = "test";
60
- })(Command || (Command = {}));
61
- function syntax() {
62
- console.log(`
63
- ----------------------------------------------------------------------------------
64
- cykquery executes a <db.query> to the server (DBREMOTE_URL environment variable)
65
- syntax :
66
- cykquery [ exec | test | exectest ] filename
67
- cykquery filename (option exectest by default)
68
- ----------------------------------------------------------------------------------
69
- `);
70
- }
71
- function parseCommandLine() {
72
- let command;
73
- let filepath;
74
- if (process.argv.length < 3 || process.argv.length > 4) {
75
- syntax();
76
- throw Error('nb of command line arguments : ' + process.argv.length);
77
- }
78
- if (process.argv.length === 3) {
79
- filepath = process.argv[2];
80
- command = Command.ExecTest;
81
- }
82
- else {
83
- const option = process.argv[2].toLowerCase();
84
- if (option === 'test' || option === 'exec' || option === 'exectest') {
85
- command = option;
86
- }
87
- else {
88
- syntax();
89
- throw Error('command unknown ' + process.argv[2]);
90
- }
91
- filepath = process.argv[3];
92
- }
93
- logger.trace('cykquery filepath : ' + filepath);
94
- const basename = path_1.default.basename(filepath);
95
- const extname = path_1.default.extname(filepath);
96
- logger.trace('basename ' + basename + ', extname ' + extname);
97
- if (extname.toLowerCase() !== '.xml') {
98
- throw Error('filepath argument ' + filepath + ' should have xml extension');
99
- }
100
- return { command, filepath, basename };
101
- }
102
- function parseXmlFile(filepath, basename, xmlSource) {
103
- const tag = (0, cyk_core_1.parseXML)(filepath, xmlSource);
104
- if (tag.name !== 'DB.QUERY') {
105
- throw Error('tag ' + tag.name + ', should be <db.query>');
106
- }
107
- const name = tag.attributes.NAME;
108
- if (name === undefined) {
109
- throw Error('name attribute is missing');
110
- }
111
- if (basename !== name + '.xml') {
112
- throw Error('filename ' + filepath + ' and name ' + name + ' do not correspond');
113
- }
114
- return tag;
115
- }
116
- async function executeXml(structure, tag, xmlSource) {
117
- try {
118
- logger.debug('executeXml ' + tag.attributes.NAME);
119
- // structure.setInstructionType("print", new PrintInstructionType(logfilename))
120
- const dbQueryInstructionType = structure.scope.getInstructionType('db.query');
121
- if (dbQueryInstructionType === undefined) {
122
- throw Error('dbQueryInstructionType not found');
123
- }
124
- const scopeParse = new cyk_core_1.Scope(structure, structure.scope, undefined);
125
- const dbQueryInst = await dbQueryInstructionType.parseInstruction(tag, scopeParse);
126
- dbQueryInst.source = xmlSource;
127
- const scopeExecute = new cyk_core_1.Scope(structure, structure.scope, undefined);
128
- await dbQueryInst.execute(scopeExecute);
129
- }
130
- catch (err) {
131
- logger.error(err);
132
- }
133
- }
134
- async function testQuery(structure, queryName) {
135
- const xmlScript = `
136
- <block>
137
- <object name='result'/>
138
- <db.execute query='${queryName}' result='result' />
139
- <print>string(result)</print>
140
- </block>
141
- `;
142
- const script = new cyk_core_1.Script(structure.scope, 'test', xmlScript);
143
- await script.parseInstructions();
144
- await script.execute();
145
- }
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env ts-node
2
- export {};
package/build/cyktable.js DELETED
@@ -1,133 +0,0 @@
1
- #!/usr/bin/env ts-node
2
- "use strict";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
6
- }) : (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- o[k2] = m[k];
9
- }));
10
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
11
- Object.defineProperty(o, "default", { enumerable: true, value: v });
12
- }) : function(o, v) {
13
- o["default"] = v;
14
- });
15
- var __importStar = (this && this.__importStar) || function (mod) {
16
- if (mod && mod.__esModule) return mod;
17
- var result = {};
18
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
19
- __setModuleDefault(result, mod);
20
- return result;
21
- };
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const cyk_core_1 = require("@cyk-language/cyk-core");
27
- const fs = __importStar(require("fs"));
28
- const loglevel_1 = __importDefault(require("loglevel"));
29
- const dotenv_1 = __importDefault(require("dotenv"));
30
- const commander_1 = require("commander");
31
- const child_process_1 = require("child_process");
32
- const logger = loglevel_1.default.getLogger("cyktable.ts");
33
- logger.setLevel("debug");
34
- const program = new commander_1.Command();
35
- program.name('cyktable').description('import/export table rows')
36
- .version('0.2');
37
- program.command('export').description('export to CSV file(s)')
38
- .argument('<tables...>', 'table(s) to export')
39
- .option('-e --env <env>', 'path to the environment variables file')
40
- .option('-f --file <file>', 'name of the file to create, defaults to <table_name>.csv')
41
- .option('-d --dir <directory>', 'name of the directory where to create exported files')
42
- .action(async (tables, options) => commandImportExport('to', tables, options));
43
- program.command('import').description('export to CSV file(s)')
44
- .argument('<tables...>', 'table(s) to export')
45
- .option('-e --env <env>', 'path to the environment variables file')
46
- .option('-f --file <file>', 'name of the file to create, defaults to <table_name>.csv')
47
- .option('-d --dir <directory>', 'name of the directory where to create exported files')
48
- .action(async (tables, options) => commandImportExport('from', tables, options));
49
- const getDBManager = async () => {
50
- const structure = new cyk_core_1.Structure();
51
- if (process.env.DBREMOTE_URL === undefined)
52
- throw 'DBREMOTE_URL undefined';
53
- logger.debug('DBREMOTE_URL ' + process.env.DBREMOTE_URL);
54
- const dbRemote = new cyk_core_1.DBRemote(structure.scope, process.env.DBREMOTE_URL);
55
- const login = await dbRemote.signin(process.env.USER_NAME, undefined, process.env.USER_PASSWORD);
56
- // logger.debug(login)
57
- const dbManager = new cyk_core_1.DBManager(structure.scope, dbRemote);
58
- await dbManager.initialize();
59
- return dbManager;
60
- };
61
- const commandImportExport = async (direction, tables, options) => {
62
- logger.debug('tables : ', tables, 'options : ', options);
63
- try {
64
- const dotenvOutput = dotenv_1.default.config({ path: options.env });
65
- if (dotenvOutput.error !== undefined)
66
- throw dotenvOutput.error;
67
- if (options.file === undefined && options.dir === undefined)
68
- throw '--file or --dir mandatory';
69
- if (options.file !== undefined && options.dir !== undefined)
70
- throw '--file and --dir are mutually exclusive';
71
- if (tables.length === 0)
72
- throw 'at least one table name is mandatory';
73
- if (tables.length > 1 && options.dir === undefined)
74
- throw 'for multiple tables, --dir is mandatory';
75
- const dbManager = await getDBManager();
76
- for (let indi = 0; indi < tables.length; indi++) {
77
- const tableName = tables[indi];
78
- const dbTable = await dbManager.dbTableExist(tableName);
79
- if (dbTable === undefined) {
80
- logger.info('table ' + tableName + ' not found');
81
- continue;
82
- }
83
- let lcols;
84
- for (let indj = 0; indj < dbTable.columns.length; indj++) {
85
- const dbColumn = dbTable.columns[indj];
86
- if (lcols === undefined) {
87
- lcols = "(";
88
- }
89
- else {
90
- lcols += ",";
91
- }
92
- lcols += dbColumn.name;
93
- }
94
- lcols += ")";
95
- let psql_cmd = "psql -c";
96
- if (process.env.HEROKU_CLI !== undefined) {
97
- psql_cmd = process.env.HEROKU_CLI + ' -c ';
98
- }
99
- let filename;
100
- if (options.file !== undefined) {
101
- if (fs.existsSync(options.file) && fs.lstatSync(options.file).isDirectory())
102
- throw '--file ' + options.file + ' is a directory';
103
- filename = options.file;
104
- }
105
- else if (options.dir === undefined)
106
- throw '--file and --dir unspecified';
107
- else if (fs.existsSync(options.dir) === false)
108
- throw 'directory ' + options.dir + ' does not exist';
109
- else if (fs.lstatSync(options.dir).isFile()) {
110
- logger.debug("--dir " + options.dir + " is a file ");
111
- }
112
- else {
113
- let directory = options.dir.trim();
114
- if (directory[directory.length - 1] !== '/') {
115
- directory += '/';
116
- }
117
- filename = directory + tableName + '.csv';
118
- }
119
- let copy_cmd = "\\copy " + tableName + lcols + direction + " '" + filename + "' csv header";
120
- const shell_cmd = psql_cmd + '"' + copy_cmd + '"';
121
- logger.debug(shell_cmd);
122
- const child = (0, child_process_1.spawn)(shell_cmd.trim(), { stdio: 'inherit', shell: true });
123
- // exec(shell_cmd.trim(), (error, stdout, stderr) => {
124
- // if (error) throw error
125
- // logger.debug(stdout, stderr)
126
- // })
127
- }
128
- }
129
- catch (err) {
130
- logger.error(err);
131
- }
132
- };
133
- program.parse();
package/build/module.d.ts DELETED
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env ts-node
2
- export {};