Skip to content

Commit

Permalink
chore(deps): update dependency dprint-plugin-typescript to v0.80.2 (#653
Browse files Browse the repository at this point in the history
)

* chore(deps): update dependency dprint-plugin-typescript to v0.80.2

    We just noticed that we haven't updated this plugin.

* style(dprint): automatic formatting of all JS / TS files
  • Loading branch information
sounisi5011 authored Jan 9, 2023
1 parent 60263cc commit aabdf70
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 156 deletions.
2 changes: 1 addition & 1 deletion .dprint.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"taggedTemplate.spaceBeforeLiteral": false,
"typeAssertion.spaceBeforeExpression": false
},
"plugins": ["https://plugins.dprint.dev/typescript-0.69.0.wasm"]
"plugins": ["https://plugins.dprint.dev/typescript-0.80.2.wasm"]
}
6 changes: 3 additions & 3 deletions .lintstagedrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ module.exports = async filenames => {
// ESLint will find the configuration files based on cwd.
// If inside submodule directories, ESLint will fail because cwd is not the project root.
// To avoid this, run ESLint using the "pnpm exec" command with the "--workspace-root" option.
const eslintCommand = (
`pnpm --workspace-root exec eslint --cache --report-unused-disable-directives --fix ${tsOrJsFiles.join(' ')}`
);
const eslintCommand = `pnpm --workspace-root exec eslint --cache --report-unused-disable-directives --fix ${
tsOrJsFiles.join(' ')
}`;
const dprintCommand = (
await Promise.all([
dprintCommandList(tsFiles, './.dprint.json'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,65 +55,62 @@ export function validateNumberOptionInRange<T extends number | bigint>(
return value;
}

export function createEnum2value<TValue>(): (
<TEnumKey extends string, TEnum>(enumRecord: Record<TEnumKey, TEnum>) => (
<TEnum2 extends TEnum, TValue2 extends TValue>(
/**
* Type checking asserts that all enum combinations are specified
* @see https://stackoverflow.com/a/60132060/4907315
*/
pair:
& OneOrMoreReadonlyArray<readonly [TEnum2, TValue2]>
& Cond2<{
cond1: {
actual: TEnum2;
expected: TEnum;
onlyMatch: 'Invalid: All value types must be specified';
};
cond2: {
actual: TValue2;
expected: TValue;
onlyMatch: 'Invalid: All Enum type values must be specified';
};
allMatch: unknown;
notAllMatch: 'Invalid: All Enum type values and all value types must be specified';
}>,
) => {
enum2value: (
builtin: BuiltinInspectRecord,
enumItem: Nullable<TEnum2>,
exists: boolean,
opts: { fieldName: string; dataName: string },
) => TValue2;
value2enum: (builtin: BuiltinInspectRecord, value: TValue2) => TEnum2;
}
)
) {
return enumRecord =>
pair => {
const enum2valueMap = new Map(pair.map(([e, v]) => [e, { data: v }]));
const value2enumMap = new Map(pair.map(([e, v]) => [v, { data: e }]));
export function createEnum2value<TValue>(): <TEnumKey extends string, TEnum>(
enumRecord: Record<TEnumKey, TEnum>,
) => <TEnum2 extends TEnum, TValue2 extends TValue>(
/**
* Type checking asserts that all enum combinations are specified
* @see https://stackoverflow.com/a/60132060/4907315
*/
pair:
& OneOrMoreReadonlyArray<readonly [TEnum2, TValue2]>
& Cond2<{
cond1: {
actual: TEnum2;
expected: TEnum;
onlyMatch: 'Invalid: All value types must be specified';
};
cond2: {
actual: TValue2;
expected: TValue;
onlyMatch: 'Invalid: All Enum type values must be specified';
};
allMatch: unknown;
notAllMatch: 'Invalid: All Enum type values and all value types must be specified';
}>,
) => {
enum2value: (
builtin: BuiltinInspectRecord,
enumItem: Nullable<TEnum2>,
exists: boolean,
opts: { fieldName: string; dataName: string },
) => TValue2;
value2enum: (builtin: BuiltinInspectRecord, value: TValue2) => TEnum2;
} {
return enumRecord => pair => {
const enum2valueMap = new Map(pair.map(([e, v]) => [e, { data: v }]));
const value2enumMap = new Map(pair.map(([e, v]) => [v, { data: e }]));

type TEnum2 = (typeof enum2valueMap) extends Map<infer U, unknown> ? U : never;
const isEnumType = enum2valueMap.has.bind(enum2valueMap) as (value: unknown) => value is TEnum2;
type TEnum2 = (typeof enum2valueMap) extends Map<infer U, unknown> ? U : never;
const isEnumType = enum2valueMap.has.bind(enum2valueMap) as (value: unknown) => value is TEnum2;

return {
enum2value: (builtin, enumItem, exists, { fieldName, dataName }) => {
if (!exists || (!isEnumType(enumItem) && (enumItem === undefined || enumItem === null))) {
reportNonDefinedField({ fieldName, dataName });
}
const value = enum2valueMap.get(enumItem);
if (value) return value.data;
throw new Error(
`The value in the ${fieldName} field in the ${dataName} is unknown.`
+ ` Received: ${getPropFromValue(enumRecord, enumItem) ?? builtin.inspect(enumItem)}`,
);
},
value2enum: (builtin, value) => {
const enumItem = value2enumMap.get(value);
if (enumItem) return enumItem.data;
throw new Error(`Unknown Argon2 algorithm received: ${builtin.inspect(value)}`);
},
};
return {
enum2value: (builtin, enumItem, exists, { fieldName, dataName }) => {
if (!exists || (!isEnumType(enumItem) && (enumItem === undefined || enumItem === null))) {
reportNonDefinedField({ fieldName, dataName });
}
const value = enum2valueMap.get(enumItem);
if (value) return value.data;
throw new Error(
`The value in the ${fieldName} field in the ${dataName} is unknown.`
+ ` Received: ${getPropFromValue(enumRecord, enumItem) ?? builtin.inspect(enumItem)}`,
);
},
value2enum: (builtin, value) => {
const enumItem = value2enumMap.get(value);
if (enumItem) return enumItem.data;
throw new Error(`Unknown Argon2 algorithm received: ${builtin.inspect(value)}`);
},
};
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ export function isArgon2Options<T>(options: T): options is T extends Argon2Optio
}

function validatePositiveInteger(builtin: BuiltinInspectRecord, optionName: string, value: unknown): asserts value {
const messageSuffix = (
`The "${optionName}" option must be of positive integers without 0, but received: ${builtin.inspect(value)}`
);
const messageSuffix = `The "${optionName}" option must be of positive integers without 0, but received: ${
builtin.inspect(value)
}`;
if (!(Number.isInteger as isInteger)(value)) {
throw new TypeError(`Invalid type value received for Argon2's option "${optionName}". ${messageSuffix}`);
}
Expand Down Expand Up @@ -256,27 +256,27 @@ const createDeriveKeyFunc = (
builtin: { argon2Hash: Argon2HashFn } & BuiltinInspectRecord,
options: NormalizedArgon2Options,
): GetArgon2KDFResult['deriveKey'] =>
async (password, salt, keyLengthBytes) => {
validateBetweenByteLength(
'password',
password,
{ min: ARGON2_PASSWORD.MIN, max: ARGON2_PASSWORD.MAX },
);
validateBetweenByteLength('salt', salt, { min: ARGON2_SALT.MIN, max: ARGON2_SALT.MAX });
validateBetweenLength(
'keyLengthBytes',
keyLengthBytes,
{ shortName: 'key', min: ARGON2_OUTPUT.MIN, max: ARGON2_OUTPUT.MAX },
);
async (password, salt, keyLengthBytes) => {
validateBetweenByteLength(
'password',
password,
{ min: ARGON2_PASSWORD.MIN, max: ARGON2_PASSWORD.MAX },
);
validateBetweenByteLength('salt', salt, { min: ARGON2_SALT.MIN, max: ARGON2_SALT.MAX });
validateBetweenLength(
'keyLengthBytes',
keyLengthBytes,
{ shortName: 'key', min: ARGON2_OUTPUT.MIN, max: ARGON2_OUTPUT.MAX },
);

return await builtin.argon2Hash({
...options,
password,
salt,
hashLength: keyLengthBytes,
})
.catch(normalizeInternalError(builtin));
};
return await builtin.argon2Hash({
...options,
password,
salt,
hashLength: keyLengthBytes,
})
.catch(normalizeInternalError(builtin));
};

export function getArgon2KDF(builtin: { argon2Hash: Argon2HashFn } & BuiltinInspectRecord) {
return (options: Readonly<Argon2Options>): GetArgon2KDFResult => {
Expand Down
8 changes: 3 additions & 5 deletions packages/encrypted-archive/src/core/types/compress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ export interface CreateCompressorResult<TCompressOptions extends BaseCompressOpt
compressAlgorithmName: TCompressOptions['algorithm'] | undefined;
compressIterable: CompressIteratorConverter;
}
export type TryCreateCompressor = (
<TCompressOptions extends BaseCompressOptions>(
options: TCompressOptions | Pick<TCompressOptions, 'algorithm'>,
) => CreateCompressorResult<TCompressOptions> | undefined
);
export type TryCreateCompressor = <TCompressOptions extends BaseCompressOptions>(
options: TCompressOptions | Pick<TCompressOptions, 'algorithm'>,
) => CreateCompressorResult<TCompressOptions> | undefined;
export interface CompressionAlgorithmBuiltinAPI {
algorithmRecord: BaseCompressorRecord;
tryCreateCompressor: TryCreateCompressor;
Expand Down
8 changes: 3 additions & 5 deletions packages/encrypted-archive/src/core/types/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ export type objectEntries = <T extends string, U>(o: Record<T, U>) => Array<[T,

export type objectFromEntries = <K extends PropertyKey, T>(entries: Iterable<readonly [K, T]>) => Record<K, T>;

export type GetOptions<T extends (options: never) => unknown> = (
T extends ((options?: infer U) => unknown) ? U
: T extends ((options: infer U) => unknown) ? U
: never
);
export type GetOptions<T extends (options: never) => unknown> = T extends ((options?: infer U) => unknown) ? U
: T extends ((options: infer U) => unknown) ? U
: never;

/**
* @see https://github.com/sindresorhus/type-fest/blob/v3.5.0/source/require-at-least-one.d.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,32 @@ const nodeVersionMatch = /^v(\d+)\.(\d+)\./.exec(nodeVersion);
* Because argon2-browser fails in Node.js 18.1.0 or later.
* @see https://github.com/antelle/argon2-browser/issues/81
*/
export const argon2Hash: Argon2HashFn = (
(Number(nodeVersionMatch?.[1]) >= 18 && Number(nodeVersionMatch?.[2]) >= 1)
? // In Node.js >=18.1.0, use node-argon2
(() => {
const argon2Mod = import('argon2'); // eslint-disable-line node/no-unsupported-features/es-syntax
return async options => {
const argon2 = await argon2Mod;
const typeRecord = {
argon2d: argon2.argon2d,
argon2id: argon2.argon2id,
} as const;
const password = typeof options.password === 'string'
? options.password
: bufferFrom(options.password);
return await argon2.hash(password, {
salt: Buffer.from(options.salt),
timeCost: options.iterations,
memoryCost: options.memory,
hashLength: options.hashLength,
parallelism: options.parallelism,
type: typeRecord[options.algorithm],
raw: true,
});
};
})()
: // For Node.js <18.1.0, use argon2-browser
(() => {
const mod = import('../../web-interoperable/key-derivation-function/argon2.js'); // eslint-disable-line node/no-unsupported-features/es-syntax
return async options => await (await mod).argon2Hash(options);
})()
);
export const argon2Hash: Argon2HashFn = (Number(nodeVersionMatch?.[1]) >= 18 && Number(nodeVersionMatch?.[2]) >= 1)
// In Node.js >=18.1.0, use node-argon2
? (() => {
const argon2Mod = import('argon2'); // eslint-disable-line node/no-unsupported-features/es-syntax
return async options => {
const argon2 = await argon2Mod;
const typeRecord = {
argon2d: argon2.argon2d,
argon2id: argon2.argon2id,
} as const;
const password = typeof options.password === 'string'
? options.password
: bufferFrom(options.password);
return await argon2.hash(password, {
salt: Buffer.from(options.salt),
timeCost: options.iterations,
memoryCost: options.memory,
hashLength: options.hashLength,
parallelism: options.parallelism,
type: typeRecord[options.algorithm],
raw: true,
});
};
})()
// For Node.js <18.1.0, use argon2-browser
: (() => {
const mod = import('../../web-interoperable/key-derivation-function/argon2.js'); // eslint-disable-line node/no-unsupported-features/es-syntax
return async options => await (await mod).argon2Hash(options);
})();
2 changes: 1 addition & 1 deletion packages/jest-matchers/binary-data/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function padTextColumns(
.join('\n');
}

export function toMessageFn(func: () => (string | ReadonlyArray<string | null>)): jest.CustomMatcherResult['message'] {
export function toMessageFn(func: () => string | ReadonlyArray<string | null>): jest.CustomMatcherResult['message'] {
return () => {
const lines: string[] = toArray(func()).filter(isNotNull);
return lines.join('\n');
Expand Down
35 changes: 14 additions & 21 deletions packages/stream-transform-from/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ type IfNeverThenUnknown<T> = [T] extends [never] ? unknown : T;
* If the `objectMode` and `writableObjectMode` options is not `true`,
* the chunk value is always an instance of Buffer.
*/
export type InputChunkType<T extends stream.TransformOptions> = (
true extends GetPropValue<T, 'objectMode' | 'writableObjectMode'> ? unknown : Buffer
);
export type InputChunkType<T extends stream.TransformOptions> = true extends
GetPropValue<T, 'objectMode' | 'writableObjectMode'> ? unknown : Buffer;

/**
* If the `objectMode` and `readableObjectMode` options is not `true`,
Expand All @@ -24,18 +23,14 @@ export type OutputChunkType<T extends stream.TransformOptions> = IfNeverThenUnkn
: string | Buffer | Uint8Array
>;

export type SourceIterator<TOpts extends stream.TransformOptions> = (
AsyncIterableIterator<{
chunk: InputChunkType<TOpts>;
encoding: BufferEncoding;
}>
);
export type SourceIterator<TOpts extends stream.TransformOptions> = AsyncIterableIterator<{
chunk: InputChunkType<TOpts>;
encoding: BufferEncoding;
}>;

export type TransformFunction<TOpts extends stream.TransformOptions> = (
(source: SourceIterator<TOpts>) =>
| Iterable<OutputChunkType<TOpts>>
| AsyncIterable<OutputChunkType<TOpts>>
);
export type TransformFunction<TOpts extends stream.TransformOptions> = (source: SourceIterator<TOpts>) =>
| Iterable<OutputChunkType<TOpts>>
| AsyncIterable<OutputChunkType<TOpts>>;

type ReceivedData<TOpts extends stream.TransformOptions> =
| { chunk: InputChunkType<TOpts>; encoding: BufferEncoding; done?: false }
Expand Down Expand Up @@ -160,13 +155,11 @@ export class TransformFromAsyncIterable<

private async *createSource(): SourceIterator<TOpts> {
while (true) {
const data: ReceivedData<TOpts> = (
this.receivedDataList.shift()
?? await new Promise(resolve => {
this.receiveData = resolve;
this.callTransformCallback();
})
);
const data: ReceivedData<TOpts> = this.receivedDataList.shift()
?? await new Promise(resolve => {
this.receiveData = resolve;
this.callTransformCallback();
});
if (data.done) break;
const { done: _, ...chunkData } = data;
yield chunkData;
Expand Down
4 changes: 2 additions & 2 deletions packages/ts-utils/is-property-accessible/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function isPropertyAccessible<T>(value: T): value is (
export function isPropertyAccessible<T>(value: T): value is
& Exclude<T, null | undefined>
& Record<PropertyKey, unknown>
) {
{
return value !== null && value !== undefined;
}

Expand Down
Loading

0 comments on commit aabdf70

Please sign in to comment.