Skip to content

Commit

Permalink
resolve strict typecheck errors
Browse files Browse the repository at this point in the history
  • Loading branch information
audreyality committed Jan 15, 2025
1 parent 7bb4e43 commit 25bdae9
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 49 deletions.
9 changes: 0 additions & 9 deletions libs/common/src/tools/extension.ts

This file was deleted.

2 changes: 1 addition & 1 deletion libs/tools/generator/core/src/metadata/data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deepFreeze } from "../util";
import { deepFreeze } from "@bitwarden/common/tools/util";

/** algorithms for generating credentials */
export const Algorithm = Object.freeze({
Expand Down
4 changes: 2 additions & 2 deletions libs/tools/generator/core/src/metadata/email/catchall.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { GENERATOR_DISK } from "@bitwarden/common/platform/state";
import { PublicClassifier } from "@bitwarden/common/tools/public-classifier";
import { deepFreeze } from "@bitwarden/common/tools/util";

import { EmailRandomizer } from "../../engine";
import { CatchallConstraints } from "../../policies/catchall-constraints";
Expand All @@ -8,7 +9,6 @@ import {
CredentialGenerator,
GeneratorDependencyProvider,
} from "../../types";
import { deepFreeze } from "../../util";
import { Algorithm, Type, Profile } from "../data";
import { GeneratorMetadata } from "../generator-metadata";

Expand Down Expand Up @@ -58,7 +58,7 @@ const catchall: GeneratorMetadata<CatchallGenerationOptions> = deepFreeze({
constraints: {
default: { catchallDomain: { minLength: 1 } },
create(_policies, context) {
return new CatchallConstraints(context.email);
return new CatchallConstraints(context.email ?? "");
},
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { GENERATOR_DISK } from "@bitwarden/common/platform/state";
import { PublicClassifier } from "@bitwarden/common/tools/public-classifier";
import { deepFreeze } from "@bitwarden/common/tools/util";

import { EmailRandomizer } from "../../engine";
import { SubaddressConstraints } from "../../policies/subaddress-constraints";
Expand All @@ -8,7 +9,6 @@ import {
GeneratorDependencyProvider,
SubaddressGenerationOptions,
} from "../../types";
import { deepFreeze } from "../../util";
import { Algorithm, Profile, Type } from "../data";
import { GeneratorMetadata } from "../generator-metadata";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { PolicyType } from "@bitwarden/common/admin-console/enums";
import { GENERATOR_DISK } from "@bitwarden/common/platform/state";
import { PublicClassifier } from "@bitwarden/common/tools/public-classifier";
import { deepFreeze } from "@bitwarden/common/tools/util";

import { PasswordRandomizer } from "../../engine";
import { DynamicPasswordPolicyConstraints, passwordLeastPrivilege } from "../../policies";
import {
CredentialGenerator,
GeneratorDependencyProvider,
PasswordGenerationOptions,
PasswordGeneratorSettings,
} from "../../types";
import { deepFreeze } from "../../util";
import { Algorithm, Profile, Type } from "../data";
import { GeneratorMetadata } from "../generator-metadata";

const password: GeneratorMetadata<PasswordGenerationOptions> = deepFreeze({
const password: GeneratorMetadata<PasswordGeneratorSettings> = deepFreeze({
id: Algorithm.password,
category: Type.password,
weight: 100,
Expand All @@ -30,7 +30,7 @@ const password: GeneratorMetadata<PasswordGenerationOptions> = deepFreeze({
engine: {
create(
dependencies: GeneratorDependencyProvider,
): CredentialGenerator<PasswordGenerationOptions> {
): CredentialGenerator<PasswordGeneratorSettings> {
return new PasswordRandomizer(dependencies.randomizer);
},
},
Expand All @@ -41,7 +41,7 @@ const password: GeneratorMetadata<PasswordGenerationOptions> = deepFreeze({
key: "passwordGeneratorSettings",
target: "object",
format: "plain",
classifier: new PublicClassifier<PasswordGenerationOptions>([
classifier: new PublicClassifier<PasswordGeneratorSettings>([
"length",
"ambiguous",
"uppercase",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { GENERATOR_DISK } from "@bitwarden/common/platform/state";
import { PublicClassifier } from "@bitwarden/common/tools/public-classifier";
import { IdentityConstraint } from "@bitwarden/common/tools/state/identity-state-constraint";
import { deepFreeze } from "@bitwarden/common/tools/util";

import { UsernameRandomizer } from "../../engine";
import {
CredentialGenerator,
EffUsernameGenerationOptions,
GeneratorDependencyProvider,
} from "../../types";
import { deepFreeze } from "../../util";
import { Algorithm, Profile, Type } from "../data";
import { GeneratorMetadata } from "../generator-metadata";

Expand Down
20 changes: 10 additions & 10 deletions libs/tools/generator/core/src/types/password-generation-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,58 @@
*/
export type PasswordGeneratorSettings = {
/** The length of the password selected by the user */
length: number;
length?: number;

/** `true` when ambiguous characters may be included in the output.
* `false` when ambiguous characters should not be included in the output.
*/
ambiguous: boolean;
ambiguous?: boolean;

/** `true` when uppercase ASCII characters should be included in the output
* This value defaults to `false.
*/
uppercase: boolean;
uppercase?: boolean;

/** The minimum number of uppercase characters to include in the output.
* The value is ignored when `uppercase` is `false`.
* The value defaults to 1 when `uppercase` is `true`.
*/
minUppercase: number;
minUppercase?: number;

/** `true` when lowercase ASCII characters should be included in the output.
* This value defaults to `false`.
*/
lowercase: boolean;
lowercase?: boolean;

/** The minimum number of lowercase characters to include in the output.
* The value defaults to 1 when `lowercase` is `true`.
* The value defaults to 0 when `lowercase` is `false`.
*/
minLowercase: number;
minLowercase?: number;

/** Whether or not to include ASCII digits in the output
* This value defaults to `true` when `minNumber` is at least 1.
* This value defaults to `false` when `minNumber` is less than 1.
*/
number: boolean;
number?: boolean;

/** The minimum number of digits to include in the output.
* The value defaults to 1 when `number` is `true`.
* The value defaults to 0 when `number` is `false`.
*/
minNumber: number;
minNumber?: number;

/** Whether or not to include special characters in the output.
* This value defaults to `true` when `minSpecial` is at least 1.
* This value defaults to `false` when `minSpecial` is less than 1.
*/
special: boolean;
special?: boolean;

/** The minimum number of special characters to include in the output.
* This value defaults to 1 when `special` is `true`.
* This value defaults to 0 when `special` is `false`.
*/
minSpecial: number;
minSpecial?: number;
};

/** Request format for password credential generation.
Expand Down
20 changes: 0 additions & 20 deletions libs/tools/generator/core/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,3 @@ export function optionsToEffWordListRequest(options: PassphraseGenerationOptions

return request;
}

/** Recursively freeze an object's own keys
* @param value the value to freeze
* @returns `value`
* @remarks this function is derived from MDN's `deepFreeze`, which
* has been committed to the public domain.
*/
export function deepFreeze<T extends object>(value: T): Readonly<T> {
const keys = Reflect.ownKeys(value) as (keyof T)[];

for (const key of keys) {
const own = value[key];

if ((own && typeof own === "object") || typeof own === "function") {
deepFreeze(own);
}
}

return Object.freeze(value);
}

0 comments on commit 25bdae9

Please sign in to comment.