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

Update deprecated API usage and fix code issues #2579

Merged
merged 6 commits into from
Mar 28, 2025
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
4 changes: 2 additions & 2 deletions src/api/IBMiContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default class IBMiContent {
* @param content Raw content
* @param encoding Optional encoding to write.
*/
async writeStreamfileRaw(originalPath: string, content: Uint8Array, encoding?: string) {
async writeStreamfileRaw(originalPath: string, content: string|Uint8Array, encoding?: string) {
const client = this.ibmi.client!;
const features = this.ibmi.remoteFeatures;
const tmpobj = await tmpFile();
Expand Down Expand Up @@ -338,7 +338,7 @@ export default class IBMiContent {
});

if (copyResult.code === 0) {
let result = await this.downloadStreamfile(tempRmt);
let result = await this.downloadStreamfileRaw(tempRmt);

if (this.config.autoClearTempData) {
Promise.allSettled([
Expand Down
2 changes: 1 addition & 1 deletion src/api/components/copyToImport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class CopyToImport implements IBMiComponent {
newStatements.push(`CREATE TABLE ${library}.${table} AS (${statement}) WITH DATA`);
}

newStatements.push(`Call QSYS2.QCMDEXC('` + connection.content.toCl(`CPYTOIMPF`, {
newStatements.push(`Call QSYS2.QCMDEXC('` + connection.getContent().toCl(`CPYTOIMPF`, {
FROMFILE: `${library!}/${table!} *FIRST`,
TOSTMF: outStmf,
MBROPT: `*REPLACE`,
Expand Down
2 changes: 1 addition & 1 deletion src/api/components/cqsh/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class CustomQSh implements IBMiComponent {

async getRemoteState(connection: IBMi, installDirectory: string): Promise<ComponentState> {
this.installPath = path.posix.join(installDirectory, this.getFileName());
const result = await connection.content.testStreamFile(this.installPath, "x");
const result = await connection.getContent().testStreamFile(this.installPath, "x");

if (!result) {
return `NotInstalled`;
Expand Down
10 changes: 5 additions & 5 deletions src/api/components/getMemberInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class GetMemberInfo implements IBMiComponent {
}

async getRemoteState(connection: IBMi): Promise<ComponentState> {
const [result] = await connection.runSQL(`select cast(LONG_COMMENT as VarChar(200)) LONG_COMMENT from qsys2.sysroutines where routine_schema = '${connection.config?.tempLibrary.toUpperCase()}' and routine_name = '${this.procedureName}'`);
const [result] = await connection.runSQL(`select cast(LONG_COMMENT as VarChar(200)) LONG_COMMENT from qsys2.sysroutines where routine_schema = '${connection.getConfig().tempLibrary.toUpperCase()}' and routine_name = '${this.procedureName}'`);
if (result?.LONG_COMMENT) {
const comment = result.LONG_COMMENT as string;
const dash = comment.indexOf('-');
Expand Down Expand Up @@ -72,7 +72,7 @@ export class GetMemberInfo implements IBMiComponent {
}

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

Expand All @@ -83,7 +83,7 @@ export class GetMemberInfo implements IBMiComponent {
} catch (e) { } // Ignore errors, will return undefined.
}
else {
results = await connection.content.getQTempTable([`create table QTEMP.MEMBERINFO as (${statement}) with data`], "MEMBERINFO");
results = await connection.getContent().getQTempTable([`create table QTEMP.MEMBERINFO as (${statement}) with data`], "MEMBERINFO");
}

if (results.length === 1 && results[0].ISSOURCE === 'Y') {
Expand All @@ -103,7 +103,7 @@ export class GetMemberInfo implements IBMiComponent {
}

async getMultipleMemberInfo(connection: IBMi, members: IBMiMember[]): Promise<IBMiMember[] | undefined> {
const config = connection.config!;
const config = connection.getConfig();
const tempLib = config.tempLibrary;
const statement = members
.map(member => `select * from table(${tempLib}.${this.procedureName}('${member.library}', '${member.file}', '${member.name}'))`)
Expand All @@ -116,7 +116,7 @@ export class GetMemberInfo implements IBMiComponent {
} catch (e) { }; // Ignore errors, will return undefined.
}
else {
results = await connection.content.getQTempTable([`create table QTEMP.MEMBERINFO as (${statement}) with data`], "MEMBERINFO");
results = await connection.getContent().getQTempTable([`create table QTEMP.MEMBERINFO as (${statement}) with data`], "MEMBERINFO");
}

return results.filter(row => row.ISSOURCE === 'Y').map(result => {
Expand Down
2 changes: 1 addition & 1 deletion src/api/components/getNewLibl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class GetNewLibl implements IBMiComponent {
}

async getLibraryListFromCommand(connection: IBMi, ileCommand: string) {
const tempLib = connection.config!.tempLibrary;
const tempLib = connection.getConfig().tempLibrary;
const resultSet = await connection.runSQL(`CALL ${tempLib}.${this.procedureName}('${ileCommand.replace(new RegExp(`'`, 'g'), `''`)}')`);

const result = {
Expand Down
4 changes: 2 additions & 2 deletions src/api/tests/suites/content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ describe('Content Tests', {concurrent: true}, () => {
it('Test @clCommand + select statement', async () => {
const content = connection.getContent();

const [resultA] = await content.runSQL(`@CRTSAVF FILE(QTEMP/UNITTEST) TEXT('Code for i test');\nSelect * From Table(QSYS2.OBJECT_STATISTICS('QTEMP', '*FILE')) Where OBJATTRIBUTE = 'SAVF';`);
const [resultA] = await connection.runSQL(`@CRTSAVF FILE(QTEMP/UNITTEST) TEXT('Code for i test');\nSelect * From Table(QSYS2.OBJECT_STATISTICS('QTEMP', '*FILE')) Where OBJATTRIBUTE = 'SAVF';`);

expect(resultA.OBJNAME).toBe('UNITTEST');
expect(resultA.OBJTEXT).toBe('Code for i test');
Expand Down Expand Up @@ -573,7 +573,7 @@ describe('Content Tests', {concurrent: true}, () => {

it('should count members', async () => {
const content = connection.getContent()
const tempLib = connection.config?.tempLibrary;
const tempLib = connection.getConfig().tempLibrary;
if (tempLib) {
const file = Tools.makeid(8);
const deleteSPF = async () => await connection.runCommand({ command: `DLTF FILE(${tempLib}/${file})`, noLibList: true });
Expand Down
34 changes: 17 additions & 17 deletions src/api/tests/suites/encoding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const SHELL_CHARS = [`$`, `#`];

async function runCommandsWithCCSID(connection: IBMi, commands: string[], ccsid: number) {
const testPgmSrcFile = Tools.makeid(6).toUpperCase();
const config = connection.config!;
const config = connection.getConfig();

const tempLib = config.tempLibrary;
const testPgmName = `T${commands.length}${ccsid}${Tools.makeid(2)}`.toUpperCase();
Expand All @@ -28,7 +28,7 @@ async function runCommandsWithCCSID(connection: IBMi, commands: string[], ccsid:

const sourceFileCreated = await connection!.runCommand({ command: `CRTSRCPF FILE(${tempLib}/${testPgmSrcFile}) RCDLEN(112) CCSID(${ccsid})`, noLibList: true });

await connection.content.uploadMemberContent(tempLib, testPgmSrcFile, testPgmName, commands.join(`\n`));
await connection.getContent().uploadMemberContent(tempLib, testPgmSrcFile, testPgmName, commands.join(`\n`));

const compileCommand = `CRTBNDCL PGM(${tempLib}/${testPgmName}) SRCFILE(${tempLib}/${testPgmSrcFile}) SRCMBR(${testPgmName}) REPLACE(*YES)`;
const compileResult = await connection.runCommand({ command: compileCommand, noLibList: true });
Expand Down Expand Up @@ -118,9 +118,9 @@ describe('Encoding tests', { concurrent: true }, () => {
it('streamfileResolve with dollar', async () => {
await connection.withTempDirectory(async tempDir => {
const tempFile = path.posix.join(tempDir, `$hello`);
await connection.content.createStreamFile(tempFile);
await connection.getContent().createStreamFile(tempFile);

const resolved = await connection.content.streamfileResolve([tempFile], [`/`]);
const resolved = await connection.getContent().streamfileResolve([tempFile], [`/`]);

expect(resolved).toBe(tempFile);
});
Expand All @@ -133,12 +133,12 @@ describe('Encoding tests', { concurrent: true }, () => {
await connection.withTempDirectory(async tempDir => {
for (const name of nameCombos) {
const tempFile = path.posix.join(tempDir, `${name}.txt`);
await connection.content.createStreamFile(tempFile);
await connection.getContent().createStreamFile(tempFile);

const resolved = await connection.content.streamfileResolve([tempFile], [`/`]);
const resolved = await connection.getContent().streamfileResolve([tempFile], [`/`]);
expect(resolved).toBe(tempFile);

const attributes = await connection.content.getAttributes(resolved!, `CCSID`);
const attributes = await connection.getContent().getAttributes(resolved!, `CCSID`);
expect(attributes).toBeTruthy();
}
});
Expand Down Expand Up @@ -182,7 +182,7 @@ describe('Encoding tests', { concurrent: true }, () => {
it('Listing objects with variants', { timeout: 15000 }, async () => {
const content = connection.getContent();
if (connection && content) {
const tempLib = connection.config?.tempLibrary!;
const tempLib = connection.getConfig().tempLibrary!;
const ccsid = connection.getCcsid();

let library = `TESTLIB${connection.variantChars.local}`;
Expand Down Expand Up @@ -220,7 +220,7 @@ describe('Encoding tests', { concurrent: true }, () => {
expect(expectedLibrary).toBeTruthy();
expect(library).toBe(expectedLibrary.name);

const validated = await connection.content.validateLibraryList([tempLib, library]);
const validated = await connection.getContent().validateLibraryList([tempLib, library]);
expect(validated.length).toBe(0);

const libl = await content.getLibraryList([library]);
Expand Down Expand Up @@ -281,7 +281,7 @@ describe('Encoding tests', { concurrent: true }, () => {
const addPf = await connection.runCommand({ command: `ADDPFM FILE(${library}/${sourceFile}) MBR(${member}) SRCTYPE(TXT)`, noLibList: true });
expect(addPf.code).toBe(0);

await connection.content.uploadMemberContent(library, sourceFile, member, [`**free`, `dsply 'Hello world';`, `return;`].join(`\n`));
await connection.getContent().uploadMemberContent(library, sourceFile, member, [`**free`, `dsply 'Hello world';`, `return;`].join(`\n`));

const compileResultA = await connection.runCommand({ command: `CRTBNDRPG PGM(${library}/${member}) SRCFILE(${library}/${sourceFile}) SRCMBR(${member})`, env: { '&CURLIB': library } });
expect(compileResultA.code).toBe(0);
Expand Down Expand Up @@ -309,35 +309,35 @@ describe('Encoding tests', { concurrent: true }, () => {
const addPf = await connection.runCommand({ command: `ADDPFM FILE(${tempLib}/${testFile}) MBR(${testMember}) SRCTYPE(TXT)`, noLibList: true });
expect(addPf.code).toBe(0);

const attributes = await connection.content.getAttributes({ library: tempLib, name: testFile, member: testMember }, `CCSID`);
const attributes = await connection.getContent().getAttributes({ library: tempLib, name: testFile, member: testMember }, `CCSID`);
expect(attributes).toBeTruthy();
expect(attributes![`CCSID`]).toBe(String(ccsidData.userDefaultCCSID));

const addPfB = await connection.runCommand({ command: `ADDPFM FILE(${tempLib}/${testFile}) MBR(${variantMember}) SRCTYPE(TXT)`, noLibList: true });
expect(addPfB.code).toBe(0);

const attributesB = await connection.content.getAttributes({ library: tempLib, name: testFile, member: variantMember }, `CCSID`);
const attributesB = await connection.getContent().getAttributes({ library: tempLib, name: testFile, member: variantMember }, `CCSID`);
expect(attributesB).toBeTruthy();
expect(attributesB![`CCSID`]).toBe(String(ccsidData.userDefaultCCSID));

const objects = await connection.content.getObjectList({ library: tempLib, types: [`*SRCPF`] });
const objects = await connection.getContent().getObjectList({ library: tempLib, types: [`*SRCPF`] });
expect(objects.length).toBeTruthy();
expect(objects.some(obj => obj.name === testFile)).toBeTruthy();

const members = await connection.content.getMemberList({ library: tempLib, sourceFile: testFile });
const members = await connection.getContent().getMemberList({ library: tempLib, sourceFile: testFile });
expect(members.length).toBeTruthy();
expect(members.some(m => m.name === testMember)).toBeTruthy();
expect(members.some(m => m.file === testFile)).toBeTruthy();

const smallFilter = await connection.content.getMemberList({ library: tempLib, sourceFile: testFile, members: `${varChar}*` });
const smallFilter = await connection.getContent().getMemberList({ library: tempLib, sourceFile: testFile, members: `${varChar}*` });
expect(smallFilter.length).toBeTruthy();

const files = await connection.content.getFileList(`/QSYS.LIB/${tempLib}.LIB/${connection.sysNameInAmerican(testFile)}.FILE`);
const files = await connection.getContent().getFileList(`/QSYS.LIB/${tempLib}.LIB/${connection.sysNameInAmerican(testFile)}.FILE`);
expect(files.length).toBeTruthy();
expect(files.some(f => f.name === connection.sysNameInAmerican(variantMember) + `.MBR`)).toBeTruthy();
expect(files.some(f => f.name === connection.sysNameInAmerican(testMember) + `.MBR`)).toBeTruthy();

await connection.content.uploadMemberContent(tempLib, testFile, testMember, [`**free`, `dsply 'Hello world';`, ` `, ` `, `return;`].join(`\n`));
await connection.getContent().uploadMemberContent(tempLib, testFile, testMember, [`**free`, `dsply 'Hello world';`, ` `, ` `, `return;`].join(`\n`));

const compileResult = await connection.runCommand({ command: `CRTBNDRPG PGM(${tempLib}/${testMember}) SRCFILE(${tempLib}/${testFile}) SRCMBR(${testMember})`, noLibList: true });
console.log(compileResult);
Expand Down
4 changes: 2 additions & 2 deletions src/commands/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export function registerOpenCommands(instance: Instance): Disposable[] {
},
]

resultSet = await content!.runSQL(`
resultSet = await connection.runSQL(`
select ifnull( cast( SYSTEM_TABLE_NAME as char( 10 ) for bit data ), '' ) as SYSTEM_TABLE_NAME
, ifnull( TABLE_TEXT, '' ) as TABLE_TEXT
from QSYS2.SYSTABLES
Expand Down Expand Up @@ -286,7 +286,7 @@ export function registerOpenCommands(instance: Instance): Disposable[] {

filterText = filterText.endsWith(`.`) ? filterText.substring(0, filterText.length - 1) : filterText;

resultSet = await content!.runSQL(`
resultSet = await connection.runSQL(`
select cast( SYSTEM_TABLE_MEMBER as char( 10 ) for bit data ) as SYSTEM_TABLE_MEMBER
, ifnull( PARTITION_TEXT, '' ) as PARTITION_TEXT
, ifnull( SOURCE_TYPE, '' ) as SOURCE_TYPE
Expand Down
4 changes: 2 additions & 2 deletions src/debug/certificates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export async function setup(connection: IBMi, imported?: ImportedCertificate) {
});
try {
if (!clientCertificate.code) {
instance.getContent()!.writeStreamfileRaw(debugConfig.getRemoteClientCertificatePath(), Buffer.from(clientCertificate.stdout), "utf-8");
connection.getContent().writeStreamfileRaw(debugConfig.getRemoteClientCertificatePath(), Buffer.from(clientCertificate.stdout), "utf-8");
}
else {
throw clientCertificate.stderr;
Expand Down Expand Up @@ -183,7 +183,7 @@ export async function setup(connection: IBMi, imported?: ImportedCertificate) {
});

//Check if encryption key exists too...because the encryption script can return 0 and an error in stdout in some cases.
if (!encryptResult.code && await instance.getContent()?.testStreamFile(posix.join(debugConfig.getRemoteServiceWorkDir(), "key.properties"), "r")) {
if (!encryptResult.code && await connection.getContent().testStreamFile(posix.join(debugConfig.getRemoteServiceWorkDir(), "key.properties"), "r")) {
//After the certificates are generated/imported and the password is encrypted, we make a copy of the encryption key
//because it gets deleted each time the service starts. The CODE4IDEBUG variable is here to run the script that will restore the key
//when the service starts.
Expand Down
12 changes: 6 additions & 6 deletions src/debug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export async function initialize(context: ExtensionContext) {
const startDebugging = async (type: DebugType, objectType: DebugObjectType, objectLibrary: string, objectName: string, env?: Env) => {
if (debugExtensionAvailable()) {
const connection = instance.getConnection();
const config = instance.getConfig();
if (connection && config) {
if (connection) {
const config = connection.getConfig();
if (connection.remoteFeatures[`startDebugService.sh`]) {
const password = await getPassword();

Expand Down Expand Up @@ -120,9 +120,9 @@ export async function initialize(context: ExtensionContext) {
if (cachedResolvedTypes[path]) {
return cachedResolvedTypes[path];
} else {
const content = instance.getContent()!;
const connection = instance.getConnection()!;

const [row] = await content.runSQL(`select OBJTYPE from table(qsys2.object_statistics('${library}', '*PGM *SRVPGM', '${objectName}')) X`) as { OBJTYPE: DebugObjectType }[];
const [row] = await connection.runSQL(`select OBJTYPE from table(qsys2.object_statistics('${library}', '*PGM *SRVPGM', '${objectName}')) X`) as { OBJTYPE: DebugObjectType }[];

if (row) {
cachedResolvedTypes[path] = row.OBJTYPE;
Expand All @@ -133,14 +133,14 @@ export async function initialize(context: ExtensionContext) {

const getObjectFromUri = (uri: Uri, env?: Env) => {
const connection = instance.getConnection();
const configuration = instance.getConfig();

const qualifiedPath: {
library: string | undefined,
object: string | undefined
} = { library: undefined, object: undefined };

if (connection && configuration) {
if (connection) {
const configuration = connection.getConfig();

switch (uri.scheme) {
case `member`:
Expand Down
2 changes: 1 addition & 1 deletion src/debug/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export async function stopService(connection: IBMi) {
export async function getDebugServiceJob() {
const connection = instance.getConnection();
if (connection) {
const rows = await connection.runSQL(`select job_name, local_port from qsys2.netstat_job_info j where job_name = (select job_name from qsys2.netstat_job_info j where local_port = ${connection.config?.debugPort || 8005} and remote_address = '0.0.0.0' fetch first row only) and remote_address = '0.0.0.0'`);
const rows = await connection.runSQL(`select job_name, local_port from qsys2.netstat_job_info j where job_name = (select job_name from qsys2.netstat_job_info j where local_port = ${connection.getConfig().debugPort || 8005} and remote_address = '0.0.0.0' fetch first row only) and remote_address = '0.0.0.0'`);
if (rows && rows.length) {
return {
name: String(rows[0].JOB_NAME),
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export async function activate(context: ExtensionContext): Promise<CodeForIBMi>
onCodeForIBMiConfigurationChange("connectionSettings", async () => {
const connection = instance.getConnection();
if (connection) {
const config = instance.getConfig();
const config = connection.getConfig();
if (config) {
Object.assign(config, (await IBMi.connectionManager.load(config.name)));
}
Expand Down
Loading
Loading