Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checkObject to support checking member #1811

Merged
merged 4 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
},
]
};