Skip to content

Commit

Permalink
Merge pull request #729 from contember/refactor/upload-client
Browse files Browse the repository at this point in the history
Refactor/upload client
  • Loading branch information
matej21 authored Jun 20, 2024
2 parents 7d74fd5 + ae7f557 commit 979ec6a
Show file tree
Hide file tree
Showing 52 changed files with 47 additions and 1,484 deletions.
91 changes: 0 additions & 91 deletions build/api/client.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,47 +24,6 @@ export namespace CrudQueryBuilder {
export type OrderDirection = CrudQueryBuilderTmp.OrderDirection;
}

// @public (undocumented)
export interface FileUploader<Result = any, Error extends FileUploadError = FileUploadError> {
// (undocumented)
destroy?: (files: Result[]) => Promise<void>;
// (undocumented)
upload: (files: Map<File, UploadedFileMetadata>, options: FileUploaderInitializeOptions<Result, Error>) => Promise<void>;
}

// @public (undocumented)
export interface FileUploaderInitializeOptions<Result = any, Error extends FileUploadError = FileUploadError> {
// (undocumented)
contentApiClient: GraphQlClient;
// (undocumented)
onError: (error: Iterable<File | [File, Error]>) => void;
// (undocumented)
onProgress: (progress: Iterable<[File, FileUploadProgress]>) => void;
// (undocumented)
onSuccess: (result: Iterable<[File, Result]>) => void;
}

// @public (undocumented)
export class FileUploadError extends Error {
constructor(options?: FileUploadErrorOptions);
// (undocumented)
readonly options: FileUploadErrorOptions;
}

// @public (undocumented)
export interface FileUploadErrorOptions {
// (undocumented)
developerMessage?: string;
// (undocumented)
endUserMessage?: string;
}

// @public (undocumented)
export interface FileUploadProgress {
// (undocumented)
progress?: number;
}

// @public (undocumented)
export const formatContentApiRelativeUrl: (projectSlug: string, stageSlug: string) => string;

Expand Down Expand Up @@ -217,50 +176,6 @@ export const replaceGraphQlLiteral: <T>(input: T) => ReplaceGraphQlLiteral<T>;

export { Result }

// @public (undocumented)
export class S3FileUploader implements FileUploader<S3FileUploader.SuccessMetadata> {
constructor(options?: S3FileUploader.Options);
// (undocumented)
readonly options: S3FileUploader.Options;
// (undocumented)
upload(files: Map<File, UploadedFileMetadata>, options: FileUploaderInitializeOptions): Promise<void>;
}

// @public (undocumented)
export namespace S3FileUploader {
// (undocumented)
export interface Options {
// (undocumented)
concurrency?: number;
// (undocumented)
getUploadOptions?: (file: File) => S3UploadOptions;
}
// (undocumented)
export interface S3UploadOptions {
// (undocumented)
fileAcl?: GenerateUploadUrlMutationBuilder.Acl;
// (undocumented)
fileExpiration?: number;
// (undocumented)
fileExtension?: string;
// (undocumented)
fileName?: string;
// (undocumented)
filePrefix?: string;
// (undocumented)
fileSize?: number;
// (undocumented)
fileSuffix?: string;
// (undocumented)
fileType?: GenerateUploadUrlMutationBuilder.FileParameters['contentType'];
}
// (undocumented)
export interface SuccessMetadata {
// (undocumented)
fileUrl: string;
}
}

// @public (undocumented)
export interface SystemEvent {
// (undocumented)
Expand Down Expand Up @@ -297,12 +212,6 @@ export interface TreeFilter {
relations: RelationFilter[];
}

// @public (undocumented)
export interface UploadedFileMetadata {
// (undocumented)
abortSignal: AbortSignal;
}

export { Value }

// @public (undocumented)
Expand Down
116 changes: 0 additions & 116 deletions build/api/react-client.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
```ts

import { Context } from 'react';
import type { FileUploader } from '@contember/client';
import type { FileUploadError } from '@contember/client';
import { GraphQlClient } from '@contember/client';
import type { GraphQlClientFailedRequestMetadata } from '@contember/client';
import type { GraphQlClientRequestOptions } from '@contember/client';
Expand Down Expand Up @@ -79,69 +77,12 @@ export interface ContemberClientProps {
stage?: string;
}

// @public (undocumented)
export type FailUpload = (files: Iterable<FileId | File | [FileId | File, any]>) => void;

// @public (undocumented)
export type FileId = string | number;

// @public (undocumented)
export type FileUpload<Result = unknown, Metadata = undefined> = [
FileUploadCompoundState<Result, Metadata>,
FileUploadOperations<Metadata>
];

// @public (undocumented)
export type FileUploadCompoundState<Result = unknown, Metadata = undefined> = Map<FileId, SingleFileUploadState<Result, Metadata>>;

// @public (undocumented)
export interface FileUploadMetadata<Metadata = undefined> {
// (undocumented)
metadata: Metadata | undefined;
// (undocumented)
uploader: FileUploader;
}

// @public (undocumented)
export interface FileUploadOperations<Metadata = undefined> {
// (undocumented)
failUpload: FailUpload;
// (undocumented)
initializeUpload: InitializeUpload;
// (undocumented)
purgeUpload: PurgeUpload;
// (undocumented)
startUpload: StartUpload<Metadata>;
}

// @public (undocumented)
export interface FileUploadOptions {
}

// @public (undocumented)
export interface FileWithMetadata {
// (undocumented)
abortController: AbortController;
// (undocumented)
file: File;
// (undocumented)
fileId: FileId;
// (undocumented)
previewUrl: string;
}

// @public (undocumented)
export type InitializeUpload = (files: Iterable<[FileId, File] | File>) => Map<FileId, FileWithMetadata>;

// @public (undocumented)
export const LoginTokenContext: Context<string | undefined>;

// @public (undocumented)
export const ProjectSlugContext: Context<string | undefined>;

// @public (undocumented)
export type PurgeUpload = (files: Iterable<FileId | File>) => void;

// @public (undocumented)
export const SessionTokenContext: Context<SessionTokenContextValue>;

Expand All @@ -158,63 +99,9 @@ export interface SessionTokenContextValue {
// @public (undocumented)
export const SetSessionTokenContext: Context<(token: string | undefined) => void>;

// @public (undocumented)
export type SingleFileUploadErrorState<Metadata = undefined> = {
readyState: 'error';
errors: FileUploadError[] | undefined;
rawError: any;
file: File;
metadata: Metadata | undefined;
previewUrl: string;
uploader: FileUploader | undefined;
};

// @public (undocumented)
export type SingleFileUploadInitializingState = {
readyState: 'initializing';
abortController: AbortController;
file: File;
previewUrl: string;
};

// @public (undocumented)
export type SingleFileUploadState<Result = unknown, Metadata = undefined> = SingleFileUploadInitializingState | SingleFileUploadUploadingState<Metadata> | SingleFileUploadSuccessState<Metadata, Result> | SingleFileUploadErrorState<Metadata>;

// @public (undocumented)
export type SingleFileUploadSuccessState<Metadata = undefined, Result = unknown> = {
readyState: 'success';
file: File;
metadata: Metadata;
previewUrl: string;
result: Result;
uploader: FileUploader;
};

// @public (undocumented)
export type SingleFileUploadUploadingState<Metadata = undefined> = {
readyState: 'uploading';
abortController: AbortController;
file: File;
metadata: Metadata;
previewUrl: string;
progress: number | undefined;
uploader: FileUploader;
};

// @public (undocumented)
export const StageSlugContext: Context<string | undefined>;

// @public (undocumented)
export type StartUpload<Metadata = undefined> = (files: Iterable<FileId | File | [FileId | File, StartUploadFileOptions<Metadata>]>) => void;

// @public (undocumented)
export interface StartUploadFileOptions<Metadata = undefined> {
// (undocumented)
metadata?: Metadata;
// (undocumented)
uploader?: FileUploader;
}

// @public (undocumented)
export const useApiBaseUrl: () => string | undefined;

Expand All @@ -239,9 +126,6 @@ export const useCurrentContentGraphQlClient: () => GraphQlClient;
// @public (undocumented)
export const useCurrentSystemGraphQlClient: () => GraphQlClient;

// @public (undocumented)
export const useFileUpload: <Result = unknown, Metadata = undefined>({}?: FileUploadOptions) => FileUpload<Result, Metadata>;

// @public (undocumented)
export const useGraphQlClient: (path: string) => GraphQlClient;

Expand Down
70 changes: 14 additions & 56 deletions build/api/react-uploader.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

import { ComponentType } from 'react';
import { Context } from 'react';
import { EntityAccessor } from '@contember/binding';
import type { EntityAccessor } from '@contember/binding';
import type { Environment } from '@contember/binding';
import { Environment as Environment_2 } from '@contember/react-binding';
import { ErrorAccessor } from '@contember/binding';
import { ErrorAccessorHolder } from '@contember/binding';
import type { ErrorAccessorHolder } from '@contember/binding';
import { GenerateUploadUrlMutationBuilder } from '@contember/client';
import { GraphQlClient } from '@contember/graphql-client';
import { JSX as JSX_2 } from 'react/jsx-runtime';
import { JSXElementConstructor } from 'react';
import { NamedExoticComponent } from 'react';
Expand Down Expand Up @@ -53,6 +53,9 @@ export const createAnyFileType: ({ fileSizeField, fileTypeField, lastModifiedFie
// @public (undocumented)
export const createAudioFileType: ({ durationField, fileSizeField, fileTypeField, lastModifiedField, fileNameField, urlField, uploader, extractors, acceptFile, accept, }: AudioFileTypeProps) => FileType;

// @public (undocumented)
export const createContentApiS3Signer: (client: GraphQlClient) => (parameters: GenerateUploadUrlMutationBuilder.FileParameters) => Promise<GenerateUploadUrlMutationBuilder.ResponseBody>;

// @public (undocumented)
export const createImageFileType: ({ uploader, urlField, fileSizeField, fileTypeField, lastModifiedField, fileNameField, heightField, widthField, accept, acceptFile, extractors, }: ImageFileTypeProps) => FileType;

Expand Down Expand Up @@ -133,38 +136,6 @@ export interface FileType {
uploader?: UploadClient<any>;
}

// @public (undocumented)
export interface FileUploadHandler<FileOptions = {}, Result extends FileUploadResult = FileUploadResult> {
// (undocumented)
getErrorsHolders: (args: FileUploadHandlerGetErrorHoldersArgs) => ErrorAccessorHolder[];
// (undocumented)
populateEntity: (args: FileUploadHandlerPopulateEntityArgs) => void;
// (undocumented)
staticRender: (args: FileUploadHandlerStaticRenderArgs) => React.ReactNode;
}

// @public (undocumented)
export interface FileUploadHandlerGetErrorHoldersArgs {
// (undocumented)
entity: EntityAccessor;
// (undocumented)
environment: Environment_2;
}

// @public (undocumented)
export interface FileUploadHandlerPopulateEntityArgs<Result extends FileUploadResult = FileUploadResult> {
// (undocumented)
entity: EntityAccessor;
// (undocumented)
uploadResult: Result;
}

// @public (undocumented)
export interface FileUploadHandlerStaticRenderArgs {
// (undocumented)
environment: Environment_2;
}

// @public (undocumented)
export interface FileUploadProgress {
// (undocumented)
Expand Down Expand Up @@ -251,28 +222,11 @@ type ProgressEvent_2 = {
export { ProgressEvent_2 as ProgressEvent }

// @public (undocumented)
export interface S3FileOptions {
// (undocumented)
acl?: GenerateUploadUrlMutationBuilder.Acl;
// (undocumented)
contentType?: GenerateUploadUrlMutationBuilder.FileParameters['contentType'];
// (undocumented)
expiration?: number;
// (undocumented)
extension?: string;
// (undocumented)
fileName?: string;
// (undocumented)
prefix?: string;
// (undocumented)
size?: number;
// (undocumented)
suffix?: string;
}
export type S3FileOptions = Partial<GenerateUploadUrlMutationBuilder.FileParameters>;

// @public (undocumented)
export class S3UploadClient implements UploadClient<S3FileOptions> {
constructor(s3UrlSigner: S3UrlSigner, options?: S3UploadClientOptions);
constructor(options: S3UploadClientOptions);
// (undocumented)
readonly options: S3UploadClientOptions;
// (undocumented)
Expand All @@ -287,10 +241,14 @@ export interface S3UploadClientOptions {
concurrency?: number;
// (undocumented)
getUploadOptions?: (file: File) => S3FileOptions;
// (undocumented)
signUrl: S3UrlSigner;
}

// @public (undocumented)
export type S3UrlSigner = (parameters: GenerateUploadUrlMutationBuilder.FileParameters) => Promise<GenerateUploadUrlMutationBuilder.ResponseBody>;
export type S3UrlSigner = (args: GenerateUploadUrlMutationBuilder.FileParameters & {
file: File;
}) => Promise<GenerateUploadUrlMutationBuilder.ResponseBody>;

// @public (undocumented)
export type StartUploadEvent = {
Expand Down Expand Up @@ -478,7 +436,7 @@ export const UploaderStateContext: Context<UploaderState>;
export const UploaderUploadFilesContext: Context<(files: File[]) => void>;

// @public (undocumented)
export const useS3Client: () => S3UploadClient;
export const useS3Client: (options?: Partial<S3UploadClientOptions>) => S3UploadClient;

// @public (undocumented)
export const useUploaderClient: () => UploadClient<any, FileUploadResult> | null;
Expand Down
Loading

0 comments on commit 979ec6a

Please sign in to comment.