Skip to content

Commit

Permalink
types: fix types & generics
Browse files Browse the repository at this point in the history
  • Loading branch information
nd0ut committed Dec 26, 2023
1 parent 2ebb183 commit e085be0
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 21 deletions.
1 change: 0 additions & 1 deletion abstract/ActivityBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ export class ActivityBlock extends Block {
}
}

/** @enum {String} */
ActivityBlock.activities = Object.freeze({
START_FROM: 'start-from',
CAMERA: 'camera',
Expand Down
4 changes: 2 additions & 2 deletions abstract/Block.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export class Block extends BaseComponent {
static className = '';
requireCtxName = false;
allowCustomTemplate = true;
/** @type {import('./ActivityBlock.js').ActivityType} */
activityType = null;

init$ = blockCtx();

Expand Down Expand Up @@ -57,8 +59,6 @@ export class Block extends BaseComponent {

constructor() {
super();
/** @type {import('./ActivityBlock.js').ActivityType} */
this.activityType = null;
// @ts-ignore TODO: fix this
this.addTemplateProcessor(l10nProcessor);
// TODO: inspect template on lr-* elements
Expand Down
39 changes: 26 additions & 13 deletions abstract/UploaderBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,22 +408,35 @@ export class UploaderBlock extends ActivityBlock {
* @param {import('./TypedData.js').TypedData} [internalEntry]
*/
_validateUploadError(outputEntry, internalEntry) {
/** @type {Error} */
const error = internalEntry?.getValue('uploadError');
if (!error) {
/** @type {unknown} */
const cause = internalEntry?.getValue('uploadError');
if (!cause) {
return;
}

/** @type {import('../types').OutputFileErrorType} */
const errorType =
error instanceof UploadError ? 'UPLOAD_ERROR' : error instanceof NetworkError ? 'NETWORK_ERROR' : 'UNKNOWN_ERROR';

return buildOutputFileError({
type: errorType,
entry: outputEntry,
message: error.message,
error,
});
if (cause instanceof UploadError) {
return buildOutputFileError({
type: 'UPLOAD_ERROR',
message: cause.message,
entry: outputEntry,
error: cause,
});
} else 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,
});
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions blocks/StartFrom/StartFrom.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ActivityBlock } from '../../abstract/ActivityBlock.js';

export class StartFrom extends ActivityBlock {
historyTracked = true;
/** @type {import('../../abstract/ActivityBlock.js').ActivityType} */
activityType = 'start-from';

initCallback() {
Expand Down
10 changes: 6 additions & 4 deletions types/exported.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { UploadcareFile, UploadClientError, UploadcareNetworkError, UploadcareGroup } from '@uploadcare/upload-client';

export type UploadError = import('@uploadcare/upload-client').UploadError;
export type UploadcareFile = import('@uploadcare/upload-client').UploadcareFile;
export type NetworkError = import('@uploadcare/upload-client').NetworkError;
export type UploadcareGroup = import('@uploadcare/upload-client').UploadcareGroup;
export type Metadata = import('@uploadcare/upload-client').Metadata;
export type MetadataCallback = (fileEntry: OutputFileEntry) => Promise<Metadata> | Metadata;
export type ConfigType = {
Expand Down Expand Up @@ -89,10 +91,10 @@ export type OutputErrorTypePayload = {
total: number;
};
UPLOAD_ERROR: OutputFileErrorPayload & {
error: UploadClientError;
error: UploadError;
};
NETWORK_ERROR: OutputFileErrorPayload & {
error: UploadcareNetworkError;
error: NetworkError;
};
UNKNOWN_ERROR: OutputFileErrorPayload & {
error?: Error;
Expand Down
2 changes: 1 addition & 1 deletion types/jsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ declare namespace JSX {
CloudImageEditorBlock,
JSX.IntrinsicElements['lr-cloud-image-editor-block'] & ShadowWrapperAttributes
>;
'lr-form-input': CustomElement<InstanceType<DataOutput>, CtxAttributes>;
'lr-form-input': CustomElement<FormInput, CtxAttributes>;
'lr-file-uploader-regular': CustomElement<FileUploaderRegular, CtxAttributes & ShadowWrapperAttributes>;
'lr-file-uploader-minimal': CustomElement<FileUploaderMinimal, CtxAttributes & ShadowWrapperAttributes>;
'lr-file-uploader-inline': CustomElement<FileUploaderInline, CtxAttributes & ShadowWrapperAttributes>;
Expand Down

0 comments on commit e085be0

Please sign in to comment.