Skip to content

Commit

Permalink
refactor: interface => type
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Apr 9, 2024
1 parent 396c5ea commit 938d4fe
Show file tree
Hide file tree
Showing 31 changed files with 152 additions and 173 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"messageTransformer/messageTransformer.ts"
],
"dependencies": {
"@jsforce/jsforce-node": "^3.0.0-next.3",
"@jsforce/jsforce-node": "^3.1.0",
"@salesforce/kit": "^3.1.0",
"@salesforce/schemas": "^1.7.0",
"@salesforce/ts-types": "^2.0.9",
Expand All @@ -119,7 +119,7 @@
"ts-retry-promise": "^0.7.1"
},
"devDependencies": {
"@salesforce/dev-scripts": "^8.4.2",
"@salesforce/dev-scripts": "^8.5.0",
"@salesforce/ts-sinon": "^1.4.19",
"@types/benchmark": "^2.1.5",
"@types/chai-string": "^1.4.5",
Expand Down
8 changes: 4 additions & 4 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const CONFIG_FILE_NAME = 'config.json';
/**
* Interface for meta information about config properties
*/
export interface ConfigPropertyMeta {
export type ConfigPropertyMeta = {
/**
* The config property name.
*/
Expand Down Expand Up @@ -65,12 +65,12 @@ export interface ConfigPropertyMeta {
* Is only used if deprecated is set to true.
*/
newKey?: string;
}
};

/**
* Config property input validation
*/
export interface ConfigPropertyMetaInput {
export type ConfigPropertyMetaInput = {
/**
* Tests if the input value is valid and returns true if the input data is valid.
*
Expand All @@ -82,7 +82,7 @@ export interface ConfigPropertyMetaInput {
* The message to return in the error if the validation fails.
*/
failedMessage: string | ((value: ConfigValue) => string);
}
};

export enum SfConfigProperties {
/**
Expand Down
4 changes: 2 additions & 2 deletions src/config/configAggregator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const messages = Messages.loadMessages('@salesforce/core', 'config');
/**
* Information about a config property.
*/
export interface ConfigInfo {
export type ConfigInfo = {
/**
* key The config key.
*/
Expand Down Expand Up @@ -57,7 +57,7 @@ export interface ConfigInfo {
* True if the config property is deprecated.
*/
deprecated?: boolean;
}
};

/**
* Aggregate global and local project config files, as well as environment variables for
Expand Down
4 changes: 2 additions & 2 deletions src/config/configFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export namespace ConfigFile {
/**
* The interface for Config options.
*/
export interface Options extends BaseConfigStore.Options {
export type Options = {
/**
* The root folder where the config file is stored.
*/
Expand Down Expand Up @@ -435,5 +435,5 @@ export namespace ConfigFile {
* Indicates if init should throw if the corresponding config file is not found.
*/
throwOnNotFound?: boolean;
}
} & BaseConfigStore.Options;
}
8 changes: 4 additions & 4 deletions src/config/configStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ConfigContents, ConfigEntry, ConfigValue, Key } from './configStackType
/**
* An interface for a config object with a persistent store.
*/
export interface ConfigStore<P extends ConfigContents = ConfigContents> {
export type ConfigStore<P extends ConfigContents = ConfigContents> = {
// Map manipulation methods
entries(): ConfigEntry[];
// NEXT_RELEASE: update types to specify return can be P[K] | undefined
Expand All @@ -40,7 +40,7 @@ export interface ConfigStore<P extends ConfigContents = ConfigContents> {

// Content methods
getContents(): P;
}
};

/**
* An abstract class that implements all the config management functions but
Expand Down Expand Up @@ -433,7 +433,7 @@ export namespace BaseConfigStore {
/**
* Options for the config store.
*/
export interface Options {
export type Options = {
/**
* Keys to encrypt.
*
Expand All @@ -443,5 +443,5 @@ export namespace BaseConfigStore {
* defining a new class.
*/
encryptedKeys?: Array<string | RegExp>;
}
};
}
4 changes: 2 additions & 2 deletions src/config/orgUsersConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ export namespace OrgUsersConfig {
/**
* The config file options.
*/
export interface Options extends ConfigFile.Options {
export type Options = {
/**
* The org id associated with this user.
*/
orgId: string;
}
} & ConfigFile.Options;
}
4 changes: 2 additions & 2 deletions src/config/sandboxOrgConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ export namespace SandboxOrgConfig {
/**
* The config file options.
*/
export interface Options extends ConfigFile.Options {
export type Options = {
/**
* The org id associated with this sandbox.
*/
orgId: string;
}
} & ConfigFile.Options;

export enum Fields {
/**
Expand Down
8 changes: 4 additions & 4 deletions src/crypto/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ const detectCryptoVersion = (pwd?: string): void => {
Messages.importMessagesDirectory(pathJoin(__dirname));
const messages = Messages.loadMessages('@salesforce/core', 'encryption');

interface CredType {
type CredType = {
username: string;
password: string;
}
};

const makeSecureBuffer = (password: string, encoding: CryptoEncoding): SecureBuffer<string> => {
const newSb = new SecureBuffer<string>();
Expand Down Expand Up @@ -179,12 +179,12 @@ const keychainPromises = {
},
};

interface CryptoOptions {
type CryptoOptions = {
keychain?: KeyChain;
platform?: string;
retryStatus?: string;
noResetOnClose?: boolean;
}
};

/**
* Class for managing encrypting and decrypting private auth information.
Expand Down
12 changes: 6 additions & 6 deletions src/crypto/keyChainImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const _validateProgram = async (
/**
* Basic keychain interface.
*/
export interface PasswordStore {
export type PasswordStore = {
/**
* Gets a password
*
Expand All @@ -106,7 +106,7 @@ export interface PasswordStore {
* @param fn function callback for password.
*/
setPassword(opts: ProgramOpts, fn: (error: Nullable<Error>, contents?: SecretContents) => void): Promise<void>;
}
};

/**
* @private
Expand Down Expand Up @@ -247,13 +247,13 @@ export class KeychainAccess implements PasswordStore {
}
}

interface ProgramOpts {
type ProgramOpts = {
account: string;
service: string;
password?: string;
}
};

interface OsImpl {
type OsImpl = {
getProgram(): string;
getProgramOptions(opts: ProgramOpts): string[];
getCommandFunc(
Expand All @@ -279,7 +279,7 @@ interface OsImpl {
opts: ProgramOpts,
fn: (err: Nullable<Error>) => void
): Promise<void>;
}
};

/**
* Linux implementation.
Expand Down
12 changes: 6 additions & 6 deletions src/deviceOauthService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import { Messages } from './messages';
Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/core', 'auth');

export interface DeviceCodeResponse extends JsonMap {
export type DeviceCodeResponse = {
device_code: string;
interval: number;
user_code: string;
verification_uri: string;
}
} & JsonMap;

export interface DeviceCodePollingResponse extends JsonMap {
export type DeviceCodePollingResponse = {
access_token: string;
refresh_token: string;
signature: string;
Expand All @@ -37,13 +37,13 @@ export interface DeviceCodePollingResponse extends JsonMap {
id: string;
token_type: string;
issued_at: string;
}
} & JsonMap;

interface DeviceCodeAuthError extends SfError {
type DeviceCodeAuthError = {
error: string;
error_description: string;
status: number;
}
} & SfError;

async function makeRequest<T extends JsonMap>(options: HttpRequest): Promise<T> {
const rawResponse = await new Transport().httpRequest(options);
Expand Down
8 changes: 4 additions & 4 deletions src/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { cleanup } from './cleanup';
/**
* The common set of `Logger` options.
*/
export interface LoggerOptions {
export type LoggerOptions = {
/**
* The logger name.
*/
Expand All @@ -37,7 +37,7 @@ export interface LoggerOptions {

/** log to memory instead of to a file. Intended for Unit Testing */
useMemoryLogger?: boolean;
}
};

/**
* Standard `Logger` levels.
Expand Down Expand Up @@ -71,7 +71,7 @@ export type FieldValue = string | number | boolean | Fields;
/**
* Log line interface
*/
export interface LogLine {
export type LogLine = {
name: string;
hostname: string;
pid: string;
Expand All @@ -80,7 +80,7 @@ export interface LogLine {
msg: string;
time: string;
v: number;
}
};

/**
* A logging abstraction powered by {@link https://github.com/pinojs/pino | Pino} that provides both a default
Expand Down
8 changes: 4 additions & 4 deletions src/org/authInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ export type OrgAuthorization = {
/**
* Options for access token flow.
*/
export interface AccessTokenOptions {
export type AccessTokenOptions = {
accessToken?: string;
loginUrl?: string;
instanceUrl?: string;
}
};

export type AuthSideEffects = {
alias?: string;
Expand Down Expand Up @@ -1246,7 +1246,7 @@ export namespace AuthInfo {
/**
* Constructor options for AuthInfo.
*/
export interface Options {
export type Options = {
/**
* Org signup username.
*/
Expand All @@ -1270,5 +1270,5 @@ export namespace AuthInfo {
parentUsername?: string;

isDevHub?: boolean;
}
};
}
10 changes: 6 additions & 4 deletions src/org/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export const SFDX_HTTP_HEADERS = {
export const DNS_ERROR_NAME = 'DomainNotFoundError';
export type DeployOptionsWithRest = Partial<DeployOptions> & { rest?: boolean };

// preserving interface since it extends a class
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
export interface Tooling<S extends Schema = Schema> extends JSForceTooling<S> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
_logger: any;
Expand Down Expand Up @@ -466,17 +468,17 @@ export const SingleRecordQueryErrors = {
NoRecords: 'SingleRecordQuery_NoRecords',
MultipleRecords: 'SingleRecordQuery_MultipleRecords',
};
export interface SingleRecordQueryOptions {
export type SingleRecordQueryOptions = {
tooling?: boolean;
returnChoicesOnMultiple?: boolean;
choiceField?: string; // defaults to Name
}
};

export namespace Connection {
/**
* Connection Options.
*/
export interface Options<S extends Schema> {
export type Options<S extends Schema> = {
/**
* AuthInfo instance.
*/
Expand All @@ -489,7 +491,7 @@ export namespace Connection {
* Additional connection parameters.
*/
connectionOptions?: ConnectionConfig<S>;
}
};
}

const getOptionsVersion = async <S extends Schema>(options: Connection.Options<S>): Promise<string | undefined> => {
Expand Down
Loading

3 comments on commit 938d4fe

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - ubuntu-latest

Benchmark suite Current: 938d4fe Previous: 396c5ea Ratio
Child logger creation 464749 ops/sec (±1.29%) 476360 ops/sec (±1.20%) 1.02
Logging a string on root logger 841174 ops/sec (±9.66%) 830372 ops/sec (±8.33%) 0.99
Logging an object on root logger 620394 ops/sec (±7.81%) 616532 ops/sec (±7.56%) 0.99
Logging an object with a message on root logger 32191 ops/sec (±181.29%) 6365 ops/sec (±209.63%) 0.20
Logging an object with a redacted prop on root logger 504109 ops/sec (±7.14%) 519411 ops/sec (±7.39%) 1.03
Logging a nested 3-level object on root logger 23025 ops/sec (±184.39%) 380800 ops/sec (±7.25%) 16.54

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Logger Benchmarks - ubuntu-latest'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 938d4fe Previous: 396c5ea Ratio
Logging a nested 3-level object on root logger 23025 ops/sec (±184.39%) 380800 ops/sec (±7.25%) 16.54

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logger Benchmarks - windows-latest

Benchmark suite Current: 938d4fe Previous: 396c5ea Ratio
Child logger creation 317808 ops/sec (±0.74%) 315291 ops/sec (±1.12%) 0.99
Logging a string on root logger 734050 ops/sec (±6.71%) 740438 ops/sec (±5.65%) 1.01
Logging an object on root logger 610083 ops/sec (±6.10%) 527221 ops/sec (±6.53%) 0.86
Logging an object with a message on root logger 10501 ops/sec (±200.35%) 13267 ops/sec (±187.74%) 1.26
Logging an object with a redacted prop on root logger 427980 ops/sec (±16.50%) 393010 ops/sec (±10.00%) 0.92
Logging a nested 3-level object on root logger 323028 ops/sec (±4.63%) 302363 ops/sec (±6.09%) 0.94

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.