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

Refactor component handling and improve user input management #2525

Merged
merged 9 commits into from
Feb 24, 2025
7 changes: 6 additions & 1 deletion src/api/IBMiContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,12 @@ export default class IBMiContent {
*/
getMemberInfo(library: string, sourceFile: string, member: string) {
const component = this.ibmi.getComponent<GetMemberInfo>(GetMemberInfo.ID)!;
return component.getMemberInfo(this.ibmi, library, sourceFile, member);

if (component) {
return component.getMemberInfo(this.ibmi, library, sourceFile, member);
} else {
return Promise.resolve(undefined);
}
}

/**
Expand Down
30 changes: 24 additions & 6 deletions src/api/components/getMemberInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,31 @@ export class GetMemberInfo implements IBMiComponent {
});
}

private static parseDateString(tsString: string|undefined): Date | undefined {
if (!tsString) {
return undefined;
}

const dateParts = tsString.split('-');
const timeParts = dateParts[3].split('.');

const year = parseInt(dateParts[0], 10);
const month = parseInt(dateParts[1], 10) - 1; // Months are zero-based in JavaScript
const day = parseInt(dateParts[2], 10);
const hours = parseInt(timeParts[0], 10);
const minutes = parseInt(timeParts[1], 10);
const seconds = parseInt(timeParts[2], 10);

return new Date(year, month, day, hours, minutes, seconds);
}

async getMemberInfo(connection: IBMi, library: string, sourceFile: string, member: string): Promise<IBMiMember | undefined> {
const config = connection.config!;
const tempLib = config.tempLibrary;
const statement = `select * from table(${tempLib}.${this.procedureName}('${library}', '${sourceFile}', '${member}'))`;

let results: Tools.DB2Row[] = [];
if (config.enableSQL) {
if (connection.enableSQL) {
try {
results = await connection.runSQL(statement);
} catch (e) { } // Ignore errors, will return undefined.
Expand All @@ -78,8 +96,8 @@ export class GetMemberInfo implements IBMiComponent {
name: result.MEMBER,
extension: result.EXTENSION,
text: result.DESCRIPTION,
created: new Date(result.CREATED ? Number(result.CREATED) : 0),
changed: new Date(result.CHANGED ? Number(result.CHANGED) : 0)
created: GetMemberInfo.parseDateString(String(result.CREATED)),
changed: GetMemberInfo.parseDateString(String(result.CHANGED))
} as IBMiMember
}
}
Expand All @@ -92,7 +110,7 @@ export class GetMemberInfo implements IBMiComponent {
.join(' union all ');

let results: Tools.DB2Row[] = [];
if (config.enableSQL) {
if (connection.enableSQL) {
try {
results = await connection.runSQL(statement);
} catch (e) { }; // Ignore errors, will return undefined.
Expand All @@ -110,8 +128,8 @@ export class GetMemberInfo implements IBMiComponent {
name: result.MEMBER,
extension: result.EXTENSION,
text: result.DESCRIPTION,
created: new Date(result.CREATED ? Number(result.CREATED) : 0),
changed: new Date(result.CHANGED ? Number(result.CHANGED) : 0)
created: GetMemberInfo.parseDateString(String(result.CREATED)),
changed: GetMemberInfo.parseDateString(String(result.CHANGED))
} as IBMiMember
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/api/components/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ export class ComponentManager {
const installed = lastInstalled.find(i => i.id.name === component.getIdentification().name);
const sameVersion = installed && (installed.id.version === component.getIdentification().version);

if (!installed || !sameVersion) {
if (!installed || !sameVersion || installed.state === `NotChecked`) {
await newComponent.check();
} else {
newComponent.overrideState(installed.state);
await newComponent.overrideState(installed.state);
}

this.registered.set(component.getIdentification().name, newComponent);
Expand Down
4 changes: 2 additions & 2 deletions src/api/tests/suites/components.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ describe('Component Tests', () => {
expect(memberInfoC?.library).toBe(tempLib);
expect(memberInfoC?.file).toBe(tempSPF);
expect(memberInfoC?.name).toBe(tempMbr);
expect(memberInfoC?.created).toBeTypeOf('number');
expect(memberInfoC?.changed).toBeTypeOf('number');
expect(memberInfoC?.created).toBeTypeOf('object');
expect(memberInfoC?.changed).toBeTypeOf('object');

// Cleanup...
await connection!.runCommand({
Expand Down
2 changes: 1 addition & 1 deletion src/api/tests/suites/content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ describe('Content Tests', {concurrent: true}, () => {
expect(error).toBeInstanceOf(Tools.SqlError);
expect(error.sqlstate).toBe('38501');
}
});
}, {timeout: 25000});

it('Test @clCommand + select statement', async () => {
const content = connection.getContent();
Expand Down
3 changes: 1 addition & 2 deletions src/api/tests/suites/encoding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ describe('Encoding tests', {concurrent: true} ,() => {
});

it('Run variants through shells', async () => {

const text = `Hello${connection?.variantChars.local}world`;
const basicCommandA = `echo "${IBMi.escapeForShell(text)}"`;
const basicCommandB = `echo '${text}'`;
Expand Down Expand Up @@ -110,7 +109,7 @@ describe('Encoding tests', {concurrent: true} ,() => {
expect(paseTextResultA?.stdout).toBe(text);
expect(qshTextResultB?.stdout).toBe(text);
expect(paseTextResultB?.stdout).toBe(text);
});
}, {timeout: 25000});

it('streamfileResolve with dollar', async () => {
await connection.withTempDirectory(async tempDir => {
Expand Down
Loading