Skip to content

Commit

Permalink
Merge pull request #1811 from codefori/feature/check_object_member
Browse files Browse the repository at this point in the history
`checkObject` to support checking member
  • Loading branch information
worksofliam committed Feb 2, 2024
2 parents 807080a + 422c15f commit ae417cb
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 4 deletions.
40 changes: 38 additions & 2 deletions src/api/IBMiContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -853,9 +853,14 @@ export default class IBMiContent {
})).code === 0;
}

async checkObject(object: { library: string, name: string, type: string }, authorities: Authority[] = [`*NONE`]) {
async checkObject(object: { library: string, name: string, type: string, member?: string }, authorities: Authority[] = [`*NONE`]) {
return (await this.ibmi.runCommand({
command: `CHKOBJ OBJ(${object.library.toLocaleUpperCase()}/${object.name.toLocaleUpperCase()}) OBJTYPE(${object.type.toLocaleUpperCase()}) AUT(${authorities.join(" ")})`,
command: IBMiContent.toCl(`CHKOBJ`, {
obj: `${object.library.toLocaleUpperCase()}/${object.name.toLocaleUpperCase()}`,
objtype: object.type.toLocaleUpperCase(),
aut: authorities.join(" "),
mbr: object.member
}),
noLibList: true
})).code === 0;
}
Expand All @@ -873,4 +878,35 @@ export default class IBMiContent {
return this.config.protectedPaths.includes(qsysObject.library.toLocaleUpperCase());
}
}

/**
*
* @param command Optionally qualified CL command
* @param parameters A key/value object of parameters
* @returns Formatted CL string
*/
static toCl(command: string, parameters: {[parameter: string]: string|number|undefined}) {
let cl = command;

for (const [key, value] of Object.entries(parameters)) {
let parmValue;

if (value !== undefined) {
if (typeof value === 'string') {
if (value === value.toLocaleUpperCase()) {
parmValue = value;
} else {
parmValue = value.replace(/'/g, `''`);
parmValue = `'${parmValue}'`;
}
} else {
parmValue = String(value);
}

cl += ` ${key.toUpperCase()}(${parmValue})`;
}
}

return cl;
}
}
43 changes: 41 additions & 2 deletions src/testing/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import tmp from 'tmp';
import util from 'util';
import { Uri, workspace } from "vscode";
import { TestSuite } from ".";
import IBMiContent from "../api/IBMiContent";
import { Tools } from "../api/Tools";
import { instance } from "../instantiate";
import { CommandResult } from "../typings";

export const ContentSuite: TestSuite = {
name: `Content API tests`,
tests: [
tests: [
{
name: `Test memberResolve`, test: async () => {
const content = instance.getContent();
Expand Down Expand Up @@ -550,7 +551,45 @@ export const ContentSuite: TestSuite = {
assert.notStrictEqual(qrpglesrc, undefined);
assert.strictEqual(qrpglesrc?.attribute === "PF", true);
assert.strictEqual(qrpglesrc?.type === "*FILE", true);
},
},
{
name: `To CL`, test: async () => {
const command = IBMiContent.toCl("TEST", {
ZERO: 0,
NONE:'*NONE',
EMPTY: `''`,
OBJNAME: `OBJECT`,
OBJCHAR: `ObJect`,
IFSPATH: `/hello/world`
});

assert.strictEqual(command, "TEST ZERO(0) NONE(*NONE) EMPTY('') OBJNAME(OBJECT) OBJCHAR('ObJect') IFSPATH('/hello/world')");
}
},
{
name: `Check object (file)`, test: async () => {
const content = instance.getContent();

const exists = await content?.checkObject({ library: `QSYSINC`, name: `MIH`, type: `*FILE` });
assert.ok(exists);
}
},
{
name: `Check object (no exist)`, test: async () => {
const content = instance.getContent();

const exists = await content?.checkObject({ library: `QSYSINC`, name: `BOOOP`, type: `*FILE` });
assert.strictEqual(exists, false);
}
},
{
name: `Check object (source member)`, test: async () => {
const content = instance.getContent();

const exists = await content?.checkObject({ library: `QSYSINC`, name: `H`, type: `*FILE`, member: `MATH` });
assert.ok(exists);
}
}
},
]
};

0 comments on commit ae417cb

Please sign in to comment.