Skip to content

Commit

Permalink
test code
Browse files Browse the repository at this point in the history
  • Loading branch information
lae0901 committed Jun 17, 2020
1 parent 4b1dbde commit 484c3da
Show file tree
Hide file tree
Showing 5 changed files with 317 additions and 8 deletions.
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "lib/main.js",
"types": "lib/main.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "node ./lib/tests/as400_tests.js",
"build": "tsc"
},
"files": [
Expand Down Expand Up @@ -33,6 +33,7 @@
"typescript": "^3.9.2"
},
"dependencies": {
"axios": "^0.19.2"
"axios": "^0.19.2",
"sr_core_ts": "^1.46.7"
}
}
16 changes: 11 additions & 5 deletions src/browser-path.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

// ------------------------- path_getFileName ------------------------

import { object_toQueryString, scan_revCharEqAny, string_rtrim } from "./main";
import { object_toQueryString, scan_revCharEqAny, string_rtrim } from "sr_core_ts";
import axios from 'axios';

// return the part of the path that follows the last "/" in the string.
Expand Down Expand Up @@ -39,13 +39,19 @@ export function path_splitBaseName( path: string ) : { coreName:string, extName:
return { coreName, extName } ;
}

interface iCompileLine
{
SKIPBFR:string,
SPACEB:string,
LINE:string
}

// --------------------- steve_compile -----------------------
export async function steve_compile(config: { CURLIB: string, LIBL: string },
export async function steve_compile(config: { serverUrl:string, CURLIB: string, LIBL: string },
srcfName: string, srcfLib: string, srcmbr: string):
Promise<{ compMsg: string, compile: string[], joblog: string[] }>
Promise<{ compMsg: string, compile: iCompileLine[], joblog: string[] }>
{
const promise = new Promise<{ compMsg: string, compile: string[], joblog: string[] }>
const promise = new Promise<{ compMsg: string, compile: iCompileLine[], joblog: string[] }>
(async (resolve, reject) =>
{
srcfName = srcfName || '';
Expand All @@ -54,7 +60,7 @@ export async function steve_compile(config: { CURLIB: string, LIBL: string },
const libl = string_rtrim(config.LIBL);
const curlib = config.CURLIB;
let compMsg = '';
let compile: string[] = [];
let compile: iCompileLine[] = [];
let joblog: string[] = [];

const url = 'http://173.54.20.170:10080/coder/common/json_getManyRows.php';
Expand Down
222 changes: 222 additions & 0 deletions src/ibmi-common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
// media/ibmi_common.ts

import { object_toQueryString, string_rtrim, string_matchGeneric } from 'sr_core_ts';
import axios from 'axios';

export interface iDspfd_mbrlist
{
FILENAME: string,
LIBNAME: string,
MBRNAME: string,
NUMRCDS: number,
CRTDATE: string,
CHGDATE: string,
CHGTIME: string,
MBRTEXT: string,
SRCTYPE: string
};

// --------------------- as400_compile -----------------------
export async function as400_compile(config:{ serverUrl:string, CURLIB:string, LIBL:string},
srcfName:string, srcfLib:string, srcmbr:string) :
Promise<{compMsg:string, compile:string[], joblog:string[]}>
{
const promise = new Promise<{ compMsg: string, compile: string[], joblog: string[] }>
( async (resolve, reject) =>
{
srcfName = srcfName || '';
srcfLib = srcfLib || '';
srcmbr = srcmbr || '';
const libl = string_rtrim(config.LIBL);
const curlib = config.CURLIB;
let compMsg = '';
let compile:string[] = [] ;
let joblog:string[] = [] ;

const url = `${config.serverUrl}/coder/common/json_getManyRows.php`;
const params =
{
libl, proc: 'utl7960_compile',
outParm1: compMsg, parm2: srcfName,
parm3: srcfLib, parm4: srcmbr, parm5: curlib
}
const query = object_toQueryString(params) ;
const url_query = url + '?' + query ;

const response = await axios({
method: 'get', url: url_query, responseType: 'json'
});

let data = await response.data;
let outSet = data.outSet;
compMsg = outSet.outParm1;
compile = data.set1 || [] ;
joblog = data.set2 || [] ;
resolve( { compMsg, compile, joblog });
});

return promise;
}

// --------------------- as400_srcfList -----------------------
export function as400_srcfList(objName: string, libName: string) : Promise<{}[]>
{
const promise = new Promise<{}[]> (async (resolve, reject) =>
{
const libl = 'couri7 aplusb1fcc qtemp';
const url = 'http://173.54.20.170:10080/coder/common/json_getManyRows.php';
const params =
{
libl, proc: 'utl8020_srcfList',
parm1: objName, parm2: libName, debug: 'N'
};
// const query = object_toQueryString(params);
// const url_query = url + '?' + query;

const response = await axios({
method: 'get', url, data: params, responseType: 'json'
});

const respText = await response.data;
const rows = JSON.parse(respText);

resolve(rows);
});

return promise;
}

// --------------------- as400_routines -----------------------
export function as400_routines(libName: string, routineName: string): Promise<{}[]>
{
const promise = new Promise<{}[]>(async (resolve, reject) =>
{
const libl = 'couri7 aplusb1fcc qtemp';
const url = 'http://173.54.20.170:10080/coder/common/json_getManyRows.php';
const params =
{
libl, proc: 'utl8020_routines',
parm1: libName, parm2: routineName, debug: 'N'
};

const response = await axios({
method: 'get', url, data: params, responseType: 'json'
});

const respText = await response.data;
const rows = JSON.parse(respText);

resolve(rows);
});

return promise;
}

// --------------------- as400_srcmbrLines -----------------------
export async function as400_srcmbrLines(libName: string, fileName: string, mbrName: string)
: Promise<{ SEQNBR: string, CHGDATE: string, TEXT: string }[]>
{
const promise = new Promise < { SEQNBR: string, CHGDATE: string, TEXT: string }[] >(async (resolve, reject) =>
{

const libl = 'couri7 aplusb1fcc qtemp';
const url = 'http://173.54.20.170:10080/coder/common/json_getManyRows.php';
const sql = 'select a.seqnbr, char(a.chgdate,iso) chgdate, a.text ' +
'from table(system_srcmbr_lines(?,?,?)) a ' +
'order by a.seqnbr ';

const params =
{
libl, sql,
parm1: fileName, parm2: libName, parm3: mbrName, debug: 'N'
};

const query = object_toQueryString(params);
const url_query = url + '?' + query;

const response = await axios({
method: 'get', url: url_query, responseType: 'json'
});

const rows = await response.data;

resolve(rows);
}) ;
return promise ;
}

// --------------------- as400_srcmbrList -----------------------
// return array of srcmbrs of a srcfile.
export async function as400_srcmbrList(libName: string, fileName: string, mbrName: string = '')
: Promise<iDspfd_mbrlist[]>
{
const promise = new Promise< iDspfd_mbrlist[]>(async (resolve, reject) =>
{
const libl = 'couri7 aplusb1fcc qtemp';
const url = 'http://173.54.20.170:10080/coder/common/json_getManyRows.php';
const sql = 'select a.* ' +
'from table(system_dspfd_mbrlist(?,?)) a ' +
'order by a.mbrname ';
const params =
{
libl, sql,
parm1: fileName, parm2: libName, debug: 'N'
};

const query = object_toQueryString(params);
const url_query = url + '?' + query;

const response = await axios({
method: 'get', url: url_query, responseType: 'json'
});

let rows = await response.data;

// filter on member name.
if (mbrName)
{
// mbrName as generic name.

rows = rows.filter((item: any) =>
{
const item_mbrName = item.MBRNAME.trimRight();
if (mbrName.endsWith('*'))
{
return string_matchGeneric(item_mbrName, mbrName);
}
else
{
return (string_rtrim(item.MBRNAME).indexOf(mbrName) >= 0);
}
});
}
resolve(rows) ;
}) ;
return promise ;
}

// --------------------- as400_tablesAndViews_select -----------------------
export async function as400_tablesAndViews_select(schema: string, collName: string, maxRows: number = 500)
: Promise<[{ SCHEMA: string, COLLNAME: string, COLLTYPE: string }]>
{
const libl = 'couri7 aplusb1fcc qtemp';
const url = 'http://173.54.20.170:10080/coder/common/json_getManyRows.php';
const sql = 'call system_tablesAndViews_select(?,?,?) ';

const params =
{
libl, sql,
parm1: schema, parm2: collName, parm3: maxRows, debug: 'N'
};

const query = object_toQueryString(params);
const url_query = url + '?' + query;

const response = await axios({
method: 'get', url: url_query, responseType: 'json'
});

const rows = await response.data;

return rows;
}
75 changes: 75 additions & 0 deletions src/tests/as400_tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { string_matchGeneric } from '../main';
import { steve_compile } from '../browser-path';
import axios from 'axios';
import { object_toQueryString, string_rtrim, string_head } from 'sr_core_ts';

as400_compile_test( ) ;

async function as400_compile_test()
{
const config = {serverUrl:'http://192.168.1.170:10080', CURLIB:'couri7', LIBL:'couri7 qgpl'};
const srcfName = 'QRPGLESRC' ;
const srcfLib = 'COURI7' ;
const srcmbr = 'UTL7140R' ;

const ch5 = string_head(srcfName,5) ;


const rv = await as400_compile(config, srcfName, srcfLib, srcmbr) ;
console.log( rv.compMsg) ;
for( let ix = 0 ; ix < rv.compile.length && ix < 25 ; ++ix )
{
const line = rv.compile[ix] ;
console.log( line.LINE ) ;
}
}


interface iCompileLine
{
SKIPBFR: string,
SPACEB: string,
LINE: string
}

// --------------------- as400_compile -----------------------
export async function as400_compile(config: { serverUrl: string, CURLIB: string, LIBL: string },
srcfName: string, srcfLib: string, srcmbr: string):
Promise<{ compMsg: string, compile: iCompileLine[], joblog: string[] }>
{
const promise = new Promise<{ compMsg: string, compile: iCompileLine[], joblog: string[] }>
(async (resolve, reject) =>
{
srcfName = srcfName || '';
srcfLib = srcfLib || '';
srcmbr = srcmbr || '';
const libl = string_rtrim(config.LIBL);
const curlib = config.CURLIB;
let compMsg = '';
let compile: iCompileLine[] = [];
let joblog: string[] = [];

const url = `${config.serverUrl}/coder/common/json_getManyRows.php`;
const params =
{
libl, proc: 'utl7960_compile',
outParm1: compMsg, parm2: srcfName,
parm3: srcfLib, parm4: srcmbr, parm5: curlib
}
const query = object_toQueryString(params);
const url_query = url + '?' + query;

const response = await axios({
method: 'get', url: url_query, responseType: 'json'
});

let data = await response.data;
let outSet = data.outSet;
compMsg = outSet.outParm1;
compile = data.set1 || [];
joblog = data.set2 || [];
resolve({ compMsg, compile, joblog });
});

return promise;
}

0 comments on commit 484c3da

Please sign in to comment.