Skip to content

Commit 979ec6a

Browse files
authored
Merge pull request #729 from contember/refactor/upload-client
Refactor/upload client
2 parents 7d74fd5 + ae7f557 commit 979ec6a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+47
-1484
lines changed

build/api/client.api.md

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -24,47 +24,6 @@ export namespace CrudQueryBuilder {
2424
export type OrderDirection = CrudQueryBuilderTmp.OrderDirection;
2525
}
2626

27-
// @public (undocumented)
28-
export interface FileUploader<Result = any, Error extends FileUploadError = FileUploadError> {
29-
// (undocumented)
30-
destroy?: (files: Result[]) => Promise<void>;
31-
// (undocumented)
32-
upload: (files: Map<File, UploadedFileMetadata>, options: FileUploaderInitializeOptions<Result, Error>) => Promise<void>;
33-
}
34-
35-
// @public (undocumented)
36-
export interface FileUploaderInitializeOptions<Result = any, Error extends FileUploadError = FileUploadError> {
37-
// (undocumented)
38-
contentApiClient: GraphQlClient;
39-
// (undocumented)
40-
onError: (error: Iterable<File | [File, Error]>) => void;
41-
// (undocumented)
42-
onProgress: (progress: Iterable<[File, FileUploadProgress]>) => void;
43-
// (undocumented)
44-
onSuccess: (result: Iterable<[File, Result]>) => void;
45-
}
46-
47-
// @public (undocumented)
48-
export class FileUploadError extends Error {
49-
constructor(options?: FileUploadErrorOptions);
50-
// (undocumented)
51-
readonly options: FileUploadErrorOptions;
52-
}
53-
54-
// @public (undocumented)
55-
export interface FileUploadErrorOptions {
56-
// (undocumented)
57-
developerMessage?: string;
58-
// (undocumented)
59-
endUserMessage?: string;
60-
}
61-
62-
// @public (undocumented)
63-
export interface FileUploadProgress {
64-
// (undocumented)
65-
progress?: number;
66-
}
67-
6827
// @public (undocumented)
6928
export const formatContentApiRelativeUrl: (projectSlug: string, stageSlug: string) => string;
7029

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

218177
export { Result }
219178

220-
// @public (undocumented)
221-
export class S3FileUploader implements FileUploader<S3FileUploader.SuccessMetadata> {
222-
constructor(options?: S3FileUploader.Options);
223-
// (undocumented)
224-
readonly options: S3FileUploader.Options;
225-
// (undocumented)
226-
upload(files: Map<File, UploadedFileMetadata>, options: FileUploaderInitializeOptions): Promise<void>;
227-
}
228-
229-
// @public (undocumented)
230-
export namespace S3FileUploader {
231-
// (undocumented)
232-
export interface Options {
233-
// (undocumented)
234-
concurrency?: number;
235-
// (undocumented)
236-
getUploadOptions?: (file: File) => S3UploadOptions;
237-
}
238-
// (undocumented)
239-
export interface S3UploadOptions {
240-
// (undocumented)
241-
fileAcl?: GenerateUploadUrlMutationBuilder.Acl;
242-
// (undocumented)
243-
fileExpiration?: number;
244-
// (undocumented)
245-
fileExtension?: string;
246-
// (undocumented)
247-
fileName?: string;
248-
// (undocumented)
249-
filePrefix?: string;
250-
// (undocumented)
251-
fileSize?: number;
252-
// (undocumented)
253-
fileSuffix?: string;
254-
// (undocumented)
255-
fileType?: GenerateUploadUrlMutationBuilder.FileParameters['contentType'];
256-
}
257-
// (undocumented)
258-
export interface SuccessMetadata {
259-
// (undocumented)
260-
fileUrl: string;
261-
}
262-
}
263-
264179
// @public (undocumented)
265180
export interface SystemEvent {
266181
// (undocumented)
@@ -297,12 +212,6 @@ export interface TreeFilter {
297212
relations: RelationFilter[];
298213
}
299214

300-
// @public (undocumented)
301-
export interface UploadedFileMetadata {
302-
// (undocumented)
303-
abortSignal: AbortSignal;
304-
}
305-
306215
export { Value }
307216

308217
// @public (undocumented)

build/api/react-client.api.md

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
```ts
66

77
import { Context } from 'react';
8-
import type { FileUploader } from '@contember/client';
9-
import type { FileUploadError } from '@contember/client';
108
import { GraphQlClient } from '@contember/client';
119
import type { GraphQlClientFailedRequestMetadata } from '@contember/client';
1210
import type { GraphQlClientRequestOptions } from '@contember/client';
@@ -79,69 +77,12 @@ export interface ContemberClientProps {
7977
stage?: string;
8078
}
8179

82-
// @public (undocumented)
83-
export type FailUpload = (files: Iterable<FileId | File | [FileId | File, any]>) => void;
84-
85-
// @public (undocumented)
86-
export type FileId = string | number;
87-
88-
// @public (undocumented)
89-
export type FileUpload<Result = unknown, Metadata = undefined> = [
90-
FileUploadCompoundState<Result, Metadata>,
91-
FileUploadOperations<Metadata>
92-
];
93-
94-
// @public (undocumented)
95-
export type FileUploadCompoundState<Result = unknown, Metadata = undefined> = Map<FileId, SingleFileUploadState<Result, Metadata>>;
96-
97-
// @public (undocumented)
98-
export interface FileUploadMetadata<Metadata = undefined> {
99-
// (undocumented)
100-
metadata: Metadata | undefined;
101-
// (undocumented)
102-
uploader: FileUploader;
103-
}
104-
105-
// @public (undocumented)
106-
export interface FileUploadOperations<Metadata = undefined> {
107-
// (undocumented)
108-
failUpload: FailUpload;
109-
// (undocumented)
110-
initializeUpload: InitializeUpload;
111-
// (undocumented)
112-
purgeUpload: PurgeUpload;
113-
// (undocumented)
114-
startUpload: StartUpload<Metadata>;
115-
}
116-
117-
// @public (undocumented)
118-
export interface FileUploadOptions {
119-
}
120-
121-
// @public (undocumented)
122-
export interface FileWithMetadata {
123-
// (undocumented)
124-
abortController: AbortController;
125-
// (undocumented)
126-
file: File;
127-
// (undocumented)
128-
fileId: FileId;
129-
// (undocumented)
130-
previewUrl: string;
131-
}
132-
133-
// @public (undocumented)
134-
export type InitializeUpload = (files: Iterable<[FileId, File] | File>) => Map<FileId, FileWithMetadata>;
135-
13680
// @public (undocumented)
13781
export const LoginTokenContext: Context<string | undefined>;
13882

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

142-
// @public (undocumented)
143-
export type PurgeUpload = (files: Iterable<FileId | File>) => void;
144-
14586
// @public (undocumented)
14687
export const SessionTokenContext: Context<SessionTokenContextValue>;
14788

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

161-
// @public (undocumented)
162-
export type SingleFileUploadErrorState<Metadata = undefined> = {
163-
readyState: 'error';
164-
errors: FileUploadError[] | undefined;
165-
rawError: any;
166-
file: File;
167-
metadata: Metadata | undefined;
168-
previewUrl: string;
169-
uploader: FileUploader | undefined;
170-
};
171-
172-
// @public (undocumented)
173-
export type SingleFileUploadInitializingState = {
174-
readyState: 'initializing';
175-
abortController: AbortController;
176-
file: File;
177-
previewUrl: string;
178-
};
179-
180-
// @public (undocumented)
181-
export type SingleFileUploadState<Result = unknown, Metadata = undefined> = SingleFileUploadInitializingState | SingleFileUploadUploadingState<Metadata> | SingleFileUploadSuccessState<Metadata, Result> | SingleFileUploadErrorState<Metadata>;
182-
183-
// @public (undocumented)
184-
export type SingleFileUploadSuccessState<Metadata = undefined, Result = unknown> = {
185-
readyState: 'success';
186-
file: File;
187-
metadata: Metadata;
188-
previewUrl: string;
189-
result: Result;
190-
uploader: FileUploader;
191-
};
192-
193-
// @public (undocumented)
194-
export type SingleFileUploadUploadingState<Metadata = undefined> = {
195-
readyState: 'uploading';
196-
abortController: AbortController;
197-
file: File;
198-
metadata: Metadata;
199-
previewUrl: string;
200-
progress: number | undefined;
201-
uploader: FileUploader;
202-
};
203-
204102
// @public (undocumented)
205103
export const StageSlugContext: Context<string | undefined>;
206104

207-
// @public (undocumented)
208-
export type StartUpload<Metadata = undefined> = (files: Iterable<FileId | File | [FileId | File, StartUploadFileOptions<Metadata>]>) => void;
209-
210-
// @public (undocumented)
211-
export interface StartUploadFileOptions<Metadata = undefined> {
212-
// (undocumented)
213-
metadata?: Metadata;
214-
// (undocumented)
215-
uploader?: FileUploader;
216-
}
217-
218105
// @public (undocumented)
219106
export const useApiBaseUrl: () => string | undefined;
220107

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

242-
// @public (undocumented)
243-
export const useFileUpload: <Result = unknown, Metadata = undefined>({}?: FileUploadOptions) => FileUpload<Result, Metadata>;
244-
245129
// @public (undocumented)
246130
export const useGraphQlClient: (path: string) => GraphQlClient;
247131

build/api/react-uploader.api.md

Lines changed: 14 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
import { ComponentType } from 'react';
88
import { Context } from 'react';
9-
import { EntityAccessor } from '@contember/binding';
9+
import type { EntityAccessor } from '@contember/binding';
1010
import type { Environment } from '@contember/binding';
11-
import { Environment as Environment_2 } from '@contember/react-binding';
1211
import { ErrorAccessor } from '@contember/binding';
13-
import { ErrorAccessorHolder } from '@contember/binding';
12+
import type { ErrorAccessorHolder } from '@contember/binding';
1413
import { GenerateUploadUrlMutationBuilder } from '@contember/client';
14+
import { GraphQlClient } from '@contember/graphql-client';
1515
import { JSX as JSX_2 } from 'react/jsx-runtime';
1616
import { JSXElementConstructor } from 'react';
1717
import { NamedExoticComponent } from 'react';
@@ -53,6 +53,9 @@ export const createAnyFileType: ({ fileSizeField, fileTypeField, lastModifiedFie
5353
// @public (undocumented)
5454
export const createAudioFileType: ({ durationField, fileSizeField, fileTypeField, lastModifiedField, fileNameField, urlField, uploader, extractors, acceptFile, accept, }: AudioFileTypeProps) => FileType;
5555

56+
// @public (undocumented)
57+
export const createContentApiS3Signer: (client: GraphQlClient) => (parameters: GenerateUploadUrlMutationBuilder.FileParameters) => Promise<GenerateUploadUrlMutationBuilder.ResponseBody>;
58+
5659
// @public (undocumented)
5760
export const createImageFileType: ({ uploader, urlField, fileSizeField, fileTypeField, lastModifiedField, fileNameField, heightField, widthField, accept, acceptFile, extractors, }: ImageFileTypeProps) => FileType;
5861

@@ -133,38 +136,6 @@ export interface FileType {
133136
uploader?: UploadClient<any>;
134137
}
135138

136-
// @public (undocumented)
137-
export interface FileUploadHandler<FileOptions = {}, Result extends FileUploadResult = FileUploadResult> {
138-
// (undocumented)
139-
getErrorsHolders: (args: FileUploadHandlerGetErrorHoldersArgs) => ErrorAccessorHolder[];
140-
// (undocumented)
141-
populateEntity: (args: FileUploadHandlerPopulateEntityArgs) => void;
142-
// (undocumented)
143-
staticRender: (args: FileUploadHandlerStaticRenderArgs) => React.ReactNode;
144-
}
145-
146-
// @public (undocumented)
147-
export interface FileUploadHandlerGetErrorHoldersArgs {
148-
// (undocumented)
149-
entity: EntityAccessor;
150-
// (undocumented)
151-
environment: Environment_2;
152-
}
153-
154-
// @public (undocumented)
155-
export interface FileUploadHandlerPopulateEntityArgs<Result extends FileUploadResult = FileUploadResult> {
156-
// (undocumented)
157-
entity: EntityAccessor;
158-
// (undocumented)
159-
uploadResult: Result;
160-
}
161-
162-
// @public (undocumented)
163-
export interface FileUploadHandlerStaticRenderArgs {
164-
// (undocumented)
165-
environment: Environment_2;
166-
}
167-
168139
// @public (undocumented)
169140
export interface FileUploadProgress {
170141
// (undocumented)
@@ -251,28 +222,11 @@ type ProgressEvent_2 = {
251222
export { ProgressEvent_2 as ProgressEvent }
252223

253224
// @public (undocumented)
254-
export interface S3FileOptions {
255-
// (undocumented)
256-
acl?: GenerateUploadUrlMutationBuilder.Acl;
257-
// (undocumented)
258-
contentType?: GenerateUploadUrlMutationBuilder.FileParameters['contentType'];
259-
// (undocumented)
260-
expiration?: number;
261-
// (undocumented)
262-
extension?: string;
263-
// (undocumented)
264-
fileName?: string;
265-
// (undocumented)
266-
prefix?: string;
267-
// (undocumented)
268-
size?: number;
269-
// (undocumented)
270-
suffix?: string;
271-
}
225+
export type S3FileOptions = Partial<GenerateUploadUrlMutationBuilder.FileParameters>;
272226

273227
// @public (undocumented)
274228
export class S3UploadClient implements UploadClient<S3FileOptions> {
275-
constructor(s3UrlSigner: S3UrlSigner, options?: S3UploadClientOptions);
229+
constructor(options: S3UploadClientOptions);
276230
// (undocumented)
277231
readonly options: S3UploadClientOptions;
278232
// (undocumented)
@@ -287,10 +241,14 @@ export interface S3UploadClientOptions {
287241
concurrency?: number;
288242
// (undocumented)
289243
getUploadOptions?: (file: File) => S3FileOptions;
244+
// (undocumented)
245+
signUrl: S3UrlSigner;
290246
}
291247

292248
// @public (undocumented)
293-
export type S3UrlSigner = (parameters: GenerateUploadUrlMutationBuilder.FileParameters) => Promise<GenerateUploadUrlMutationBuilder.ResponseBody>;
249+
export type S3UrlSigner = (args: GenerateUploadUrlMutationBuilder.FileParameters & {
250+
file: File;
251+
}) => Promise<GenerateUploadUrlMutationBuilder.ResponseBody>;
294252

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

480438
// @public (undocumented)
481-
export const useS3Client: () => S3UploadClient;
439+
export const useS3Client: (options?: Partial<S3UploadClientOptions>) => S3UploadClient;
482440

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

0 commit comments

Comments
 (0)