Skip to content

Commit

Permalink
feat(validators): improved code style and types
Browse files Browse the repository at this point in the history
  • Loading branch information
Egor Didenko committed May 29, 2024
1 parent 2741c59 commit 8412b19
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
6 changes: 3 additions & 3 deletions blocks/Config/normalizeConfigValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const asFunction = (value) => {
};

/**
* @template {Array<T>}T
* @template {Function[]} T
* @param {unknown} value
* @returns {T}
*/
Expand Down Expand Up @@ -153,8 +153,8 @@ const mapping = {
secureDeliveryProxyUrlResolver:
/** @type {typeof asFunction<import('../../types').SecureDeliveryProxyUrlResolver>} */ (asFunction),
iconHrefResolver: /** @type {typeof asFunction<import('../../types').IconHrefResolver>} */ (asFunction),
fileValidators: /** @type {typeof asValidators<import('../../types').FileValidator[]>} */ (asValidators),
collectionValidators: /** @type {typeof asValidators<import('../../types').CollectionValidator[]>} */ (asValidators),
fileValidators: /** @type {typeof asValidators<import('../../types').FileValidator>} */ (asValidators),
collectionValidators: /** @type {typeof asValidators<import('../../types').CollectionValidator>} */ (asValidators),
};

/**
Expand Down
14 changes: 7 additions & 7 deletions types/exported.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LocaleDefinition } from '../abstract/localeRegistry';
import { complexConfigKeys } from '../blocks/Config/Config';
import { FuncFileValidator, FuncCollectionValidator } from '../abstract/ValidationManager';
import type { LocaleDefinition } from '../abstract/localeRegistry';
import type { complexConfigKeys } from '../blocks/Config/Config';
import type { FuncFileValidator, FuncCollectionValidator } from '../abstract/ValidationManager';

export type UploadError = import('@uploadcare/upload-client').UploadError;
export type UploadcareFile = import('@uploadcare/upload-client').UploadcareFile;
Expand All @@ -16,8 +16,8 @@ export type SecureDeliveryProxyUrlResolver = (
export type SecureUploadsSignatureAndExpire = { secureSignature: string; secureExpire: string };
export type SecureUploadsSignatureResolver = () => Promise<SecureUploadsSignatureAndExpire | null>;
export type IconHrefResolver = (iconName: string) => string;
export type FileValidator = FuncFileValidator | any;
export type CollectionValidator = FuncCollectionValidator | any;
export type FileValidator = FuncFileValidator[];
export type CollectionValidator = FuncCollectionValidator[];

export type ConfigType = {
pubkey: string;
Expand Down Expand Up @@ -72,8 +72,8 @@ export type ConfigType = {
secureDeliveryProxyUrlResolver: SecureDeliveryProxyUrlResolver | null;
iconHrefResolver: IconHrefResolver | null;

fileValidators: FileValidator[] | null;
collectionValidators: CollectionValidator[] | null;
fileValidators: FileValidator | null;
collectionValidators: CollectionValidator | null;
};
export type ConfigComplexType = Pick<ConfigType, (typeof complexConfigKeys)[number]>;
export type ConfigPlainType = Omit<ConfigType, keyof ConfigComplexType>;
Expand Down
20 changes: 11 additions & 9 deletions utils/validators/file/validateUploadError.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,22 @@ export const validateUploadError = (outputEntry, internalEntry, block) => {
entry: outputEntry,
error: cause,
});
} else if (cause instanceof NetworkError) {
}

if (cause instanceof NetworkError) {
return buildOutputFileError({
type: 'NETWORK_ERROR',
message: cause.message,
entry: outputEntry,
error: cause,
});
} else {
const error = cause instanceof Error ? cause : new Error('Unknown error', { cause });
return buildOutputFileError({
type: 'UNKNOWN_ERROR',
message: error.message,
entry: outputEntry,
error,
});
}

const error = cause instanceof Error ? cause : new Error('Unknown error', { cause });
return buildOutputFileError({
type: 'UNKNOWN_ERROR',
message: error.message,
entry: outputEntry,
error,
});
};

0 comments on commit 8412b19

Please sign in to comment.