From 1830bce7da9d1624b8dfc215ad8f8d600ddff5d6 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Mon, 4 Dec 2023 10:13:56 -0600 Subject: [PATCH] refactor: parallel awaits, remove optional --- src/org/org.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/org/org.ts b/src/org/org.ts index 7d7fc3996b..78fa75a00c 100644 --- a/src/org/org.ts +++ b/src/org/org.ts @@ -15,13 +15,11 @@ import { ensure, ensureJsonArray, ensureString, - isArray, isBoolean, isString, JsonArray, JsonMap, Nullable, - Optional, } from '@salesforce/ts-types'; import { HttpRequest, SaveResult } from 'jsforce'; import { Config } from '../config/config'; @@ -458,7 +456,7 @@ export class Org extends AsyncOptionalCreatable { /** * Returns the Org object or null if this org is not affiliated with a Dev Hub (according to the local config). */ - public async getDevHubOrg(): Promise> { + public async getDevHubOrg(): Promise { if (this.isDevHubOrg()) { return this; } else if (this.getField(Org.Fields.DEV_HUB_USERNAME)) { @@ -682,7 +680,10 @@ export class Org extends AsyncOptionalCreatable { > { const username = this.getUsername(); if (username) { - const organization = await this.retrieveOrganizationInformation(); + const [stateAggregator, organization] = await Promise.all([ + StateAggregator.getInstance(), + this.retrieveOrganizationInformation(), + ]); const updateFields = { [Org.Fields.NAME]: organization.Name, [Org.Fields.INSTANCE_NAME]: organization.InstanceName, @@ -691,7 +692,6 @@ export class Org extends AsyncOptionalCreatable { [Org.Fields.IS_SCRATCH]: organization.IsSandbox && Boolean(organization.TrialExpirationDate), [Org.Fields.TRIAL_EXPIRATION_DATE]: organization.TrialExpirationDate, }; - const stateAggregator = await StateAggregator.getInstance(); stateAggregator.orgs.update(username, updateFields); await stateAggregator.orgs.write(username); return updateFields; @@ -708,8 +708,7 @@ export class Org extends AsyncOptionalCreatable { method: 'GET', }; - const conn = this.getConnection(); - await conn.request(requestInfo); + await this.getConnection().request(requestInfo); } /** @@ -761,7 +760,7 @@ export class Org extends AsyncOptionalCreatable { // needs config refactoring to improve const usernames = contents.usernames ?? []; - if (!isArray(usernames)) { + if (!Array.isArray(usernames)) { throw new SfError('Usernames is not an array', 'UnexpectedDataFormat'); } @@ -847,7 +846,7 @@ export class Org extends AsyncOptionalCreatable { /** * Returns the admin username used to create the org. */ - public getUsername(): Optional { + public getUsername(): string | undefined { return this.getConnection().getUsername(); }