Skip to content
Draft
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
6 changes: 3 additions & 3 deletions src/accountExporter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe("accountExporter", () => {
",false,,," +
userList[j].displayName +
Array(22).join(",") + // A lot of empty fields...
userList[j].disabled;
String(userList[j].disabled);
if (j === 6) {
expectedEntry +=
",,,,,,123234234,test@test.org,,https://example.com/photo.jpg" + Array(18).join(",");
Expand Down Expand Up @@ -184,7 +184,7 @@ describe("accountExporter", () => {
singleUser.displayName +
'"' +
Array(22).join(",") + // A lot of empty fields.
singleUser.disabled;
String(singleUser.disabled);
expect(spyWrite.getCall(0).args[0]).to.eq(expectedEntry + Array(27).join(",") + os.EOL);
expect(nock.isDone()).to.be.true;
});
Expand Down Expand Up @@ -229,7 +229,7 @@ describe("accountExporter", () => {
",false,,," +
'"Foo ""Bar"" Baz"' +
Array(22).join(",") + // A lot of empty fields.
singleUser.disabled;
String(singleUser.disabled);
expect(spyWrite.getCall(0).args[0]).to.eq(expectedEntry + Array(27).join(",") + os.EOL);
expect(nock.isDone()).to.be.true;
});
Expand Down
2 changes: 1 addition & 1 deletion src/accountExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@
return data.replace(/_/g, "/").replace(/-/g, "+");
}

function addProviderUserInfo(providerInfo: any, arr: any[], startPos: number): void {

Check warning on line 65 in src/accountExporter.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unexpected any. Specify a different type

Check warning on line 65 in src/accountExporter.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unexpected any. Specify a different type
arr[startPos] = providerInfo.rawId;

Check warning on line 66 in src/accountExporter.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe member access .rawId on an `any` value

Check warning on line 66 in src/accountExporter.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe assignment of an `any` value
arr[startPos + 1] = providerInfo.email || "";

Check warning on line 67 in src/accountExporter.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe member access .email on an `any` value

Check warning on line 67 in src/accountExporter.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe assignment of an `any` value
arr[startPos + 2] = escapeCsv(providerInfo.displayName || "");

Check warning on line 68 in src/accountExporter.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe member access .displayName on an `any` value

Check warning on line 68 in src/accountExporter.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe argument of type `any` assigned to a parameter of type `string`
arr[startPos + 3] = providerInfo.photoUrl || "";

Check warning on line 69 in src/accountExporter.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe member access .photoUrl on an `any` value

Check warning on line 69 in src/accountExporter.ts

View workflow job for this annotation

GitHub Actions / lint (24)

Unsafe assignment of an `any` value
}

function transUserToArray(user: any): any[] {
Expand Down Expand Up @@ -204,7 +204,7 @@
const userList = ret.body.users;
if (userList && userList.length > 0) {
options.writeUsersToFile(userList, options.format, options.writeStream);
utils.logSuccess("Exported " + userList.length + " account(s) successfully.");
utils.logSuccess(`Exported ${String(userList.length)} account(s) successfully.`);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Wrapping userList.length in String() is redundant inside a template literal, as template literals automatically convert numbers to strings. Removing it simplifies the code.

Suggested change
utils.logSuccess(`Exported ${String(userList.length)} account(s) successfully.`);
utils.logSuccess(`Exported ${userList.length} account(s) successfully.`);

// The identitytoolkit API do not return a nextPageToken value
// consistently when the last page is reached
if (!ret.body.nextPageToken) {
Expand Down
13 changes: 7 additions & 6 deletions src/accountImporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ function validateRequiredParameters(options: any): any {
return { valid: true };
}
const hashAlgo = options.hashAlgo.toUpperCase();
const hashAlgoName = String(options.hashAlgo);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Instead of introducing the temporary hashAlgoName variable and using string concatenation with +, you can use template literals directly in the FirebaseError constructors. This is much more idiomatic in TypeScript and avoids the need for hashAlgoName entirely.\n\nFor example, you can refactor the error throws like this:\n\ntypescript\nthrow new FirebaseError(`Must provide hash key(base64 encoded) for hash algorithm ${options.hashAlgo}`);\n

let roundsNum;
switch (hashAlgo) {
case "HMAC_SHA512":
Expand All @@ -192,7 +193,7 @@ function validateRequiredParameters(options: any): any {
case "HMAC_MD5":
if (!options.hashKey || options.hashKey === "") {
throw new FirebaseError(
"Must provide hash key(base64 encoded) for hash algorithm " + options.hashAlgo,
"Must provide hash key(base64 encoded) for hash algorithm " + hashAlgoName,
);
}
return { hashAlgo: hashAlgo, hashKey: options.hashKey, valid: true };
Expand All @@ -215,26 +216,26 @@ function validateRequiredParameters(options: any): any {
roundsNum = parseInt(options.rounds, 10);
if (isNaN(roundsNum) || roundsNum < 0 || roundsNum > 120000) {
throw new FirebaseError(
"Must provide valid rounds(0..120000) for hash algorithm " + options.hashAlgo,
"Must provide valid rounds(0..120000) for hash algorithm " + hashAlgoName,
);
}
return { hashAlgo: hashAlgo, rounds: options.rounds, valid: true };
case "SCRYPT": {
if (!options.hashKey || options.hashKey === "") {
throw new FirebaseError(
"Must provide hash key(base64 encoded) for hash algorithm " + options.hashAlgo,
"Must provide hash key(base64 encoded) for hash algorithm " + hashAlgoName,
);
}
roundsNum = parseInt(options.rounds, 10);
if (isNaN(roundsNum) || roundsNum <= 0 || roundsNum > 8) {
throw new FirebaseError(
"Must provide valid rounds(1..8) for hash algorithm " + options.hashAlgo,
"Must provide valid rounds(1..8) for hash algorithm " + hashAlgoName,
);
}
const memCost = parseInt(options.memCost, 10);
if (isNaN(memCost) || memCost <= 0 || memCost > 14) {
throw new FirebaseError(
"Must provide valid memory cost(1..14) for hash algorithm " + options.hashAlgo,
"Must provide valid memory cost(1..14) for hash algorithm " + hashAlgoName,
);
}
let saltSeparator = "";
Expand Down Expand Up @@ -321,7 +322,7 @@ export function validateUserJson(userJson: any): { error?: string } {
}

async function sendRequest(projectId: string, userList: any[], hashOptions: any): Promise<void> {
logger.info("Starting importing " + userList.length + " account(s).");
logger.info(`Starting importing ${userList.length} account(s).`);
const postData = genUploadAccountPostBody(projectId, userList, hashOptions);
return apiClient
.post<any, any>("/identitytoolkit/v3/relyingparty/uploadAccount", postData, {
Expand Down
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as fs from "fs-extra";
import * as path from "path";

import { detectProjectRoot } from "./detectProjectRoot";
import { FirebaseError } from "./error";
import { FirebaseError, getErrMsg } from "./error";
import * as fsutils from "./fsutils";
import { confirm } from "./prompt";
import { resolveProjectPath } from "./projectPath";
Expand Down Expand Up @@ -371,7 +371,7 @@ export class Config {

return new Config(data, options);
} catch (e: any) {
throw new FirebaseError(`There was an error loading ${filename}:\n\n` + e.message, {
throw new FirebaseError(`There was an error loading ${filename}:\n\n${getErrMsg(e)}`, {
exit: 1,
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/localFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class LocalFunction {
return resource.replace(this.paramWildcardRegex, (wildcard: string) => {
const wildcardNoBraces = wildcard.slice(1, -1); // .slice removes '{' and '}' from wildcard
const sub = params?.[wildcardNoBraces];
return sub || wildcardNoBraces + utils.randomInt(1, 9);
return sub || `${wildcardNoBraces}${utils.randomInt(1, 9)}`;
});
}

Expand Down Expand Up @@ -219,9 +219,9 @@ export default class LocalFunction {

private requestCallBack<T>(err: unknown, response?: ClientResponse<T>, body?: string | object) {
if (err) {
return console.warn("\nERROR SENDING REQUEST: " + err);
return console.warn(`\nERROR SENDING REQUEST: ${String(err)}`);
}
const status = response ? response.status + ", " : "";
const status = response ? `${response.status}, ` : "";

// If the body is a string we want to check if we can parse it as JSON
// and pretty-print it. We can't blindly stringify because stringifying
Expand Down
2 changes: 1 addition & 1 deletion src/profileReport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as stream from "stream";
import { extractJSON, extractReadableIndex, formatNumber, ProfileReport } from "./profileReport";
import { SAMPLE_INPUT_PATH, SAMPLE_OUTPUT_PATH } from "./test/fixtures/profiler-data";

function combinerFunc(obj1: any, obj2: any): any {
function combinerFunc(obj1: { count: number }, obj2: { count: number }): { count: number } {
return { count: obj1.count + obj2.count };
}

Expand Down
16 changes: 12 additions & 4 deletions src/profileReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function formatNumber(num: number) {
export function formatBytes(bytes: number) {
const threshold = 1000;
if (Math.round(bytes) < threshold) {
return bytes + " B";
return `${bytes} B`;
}
const units = ["kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
let u = -1;
Expand Down Expand Up @@ -359,7 +359,7 @@ export class ProfileReport {
},
});
const unindexed = this.collapsePaths(this.state.unindexed, (u1: any, u2: any) => {
_.mergeWith(u1, u2, (p1, p2) => {
_.mergeWith(u1, u2, (p1: { times: number; query: unknown }, p2: { times: number }) => {
return {
times: p1.times + p2.times,
query: p1.query,
Expand All @@ -386,7 +386,8 @@ export class ProfileReport {
border: this.options.isFile ? [] : ["grey"],
},
});
const data = this.collapsePaths(pureData, (b1: any, b2: any) => {
type Bandwidth = { bytes: number; times: number };
const data = this.collapsePaths(pureData, (b1: Bandwidth, b2: Bandwidth) => {
return {
bytes: b1.bytes + b2.bytes,
times: b1.times + b2.times,
Expand Down Expand Up @@ -468,7 +469,14 @@ export class ProfileReport {
border: this.options.isFile ? [] : ["grey"],
},
});
const data = this.collapsePaths(pureData, (s1: any, s2: any) => {
type SpeedStats = {
times: number;
millis: number;
pendingCount: number;
pendingTime: number;
rejected: number;
};
const data = this.collapsePaths(pureData, (s1: SpeedStats, s2: SpeedStats) => {
return {
times: s1.times + s2.times,
millis: s1.millis + s2.millis,
Expand Down
2 changes: 1 addition & 1 deletion src/profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export async function profiler(options: any): Promise<unknown> {
// If the response stream is closed, this handler is called (not
// necessarially an error condition).
res.body.on("end", () => {
spinner.text = counter + " operations recorded.\n";
spinner.text = `${counter} operations recorded.\n`;
});
// If the duration passes or another exception happens, this handler is
// called.
Expand Down
5 changes: 3 additions & 2 deletions src/projectUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function needProjectId({
const aliasCount = Object.keys(aliases).length;

if (aliasCount === 0) {
// marked returns a string unless called with { async: true }.
throw new FirebaseError(
"No currently active project.\n" +
"To run this command, you need to specify a project. You have two options:\n" +
Expand All @@ -56,9 +57,9 @@ export function needProjectId({
"To list all the Firebase projects to which you have access, run " +
clc.bold("firebase projects:list") +
".\n" +
marked(
(marked(
"To learn about active projects for the CLI, visit https://firebase.google.com/docs/cli#project_aliases",
),
) as string),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ export function formatFilesize(bytes: number, decimals = 2): string {
const dm = decimals < 0 ? 0 : decimals;
const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
const i = Math.min(Math.floor(Math.log(bytes) / Math.log(k)), sizes.length - 1);
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
}

export type Limit = <T>(fn: () => Promise<T>) => Promise<T>;
Expand Down
Loading