UNPKG

4.68 kBTypeScriptView Raw
1/**
2 * Storage instance options
3 */
4import { ICredentials } from '@aws-amplify/core';
5import { StorageProvider, StorageProviderApi, AWSS3Provider, StorageProviderWithCopy, S3ProviderGetOuput, S3ProviderRemoveOutput, S3ProviderListOutput, S3ProviderCopyOutput, S3ProviderPutOutput } from '../';
6declare type Tail<T extends any[]> = ((...t: T) => void) extends (h: any, ...r: infer R) => void ? R : never;
7declare type Last<T extends any[]> = T[Exclude<keyof T, keyof Tail<T>>];
8declare type LastParameter<F extends (...args: any) => any> = Last<Parameters<F>>;
9export interface StorageOptions {
10 credentials?: ICredentials;
11 region?: string;
12 level?: StorageAccessLevel;
13 bucket?: string;
14 provider?: string;
15 /**
16 * Custom mapping of your prefixes.
17 * For example, customPrefix: { public: 'myPublicPrefix' } will make public level operations access 'myPublicPrefix/'
18 * instead of the default 'public/'.
19 */
20 customPrefix?: CustomPrefix;
21 /**
22 * if set to true, automatically sends Storage Events to Amazon Pinpoint
23 **/
24 track?: boolean;
25 dangerouslyConnectToHttpEndpointForTesting?: boolean;
26}
27export declare type StorageAccessLevel = 'public' | 'protected' | 'private';
28export declare type CustomPrefix = {
29 [key in StorageAccessLevel]?: string;
30};
31export declare type StorageCopyTarget = {
32 key: string;
33 level?: string;
34 identityId?: string;
35};
36export declare type StorageCopySource = StorageCopyTarget;
37export declare type StorageCopyDestination = Omit<StorageCopyTarget, 'identityId'>;
38/**
39 * If provider is AWSS3, provider doesn't have to be specified since it's the default, else it has to be passed into
40 * config.
41 */
42declare type StorageOperationConfig<T extends StorageProvider | StorageProviderWithCopy, U extends StorageProviderApi> = ReturnType<T['getProviderName']> extends 'AWSS3' ? LastParameter<AWSS3Provider[U]> : T extends StorageProviderWithCopy ? LastParameter<T[U]> & {
43 provider: ReturnType<T['getProviderName']>;
44} : LastParameter<T[Exclude<U, 'copy'>]> & {
45 provider: ReturnType<T['getProviderName']>;
46};
47export declare type StorageGetConfig<T> = T extends StorageProvider ? StorageOperationConfig<T, 'get'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'get'>, T>;
48export declare type StoragePutConfig<T> = T extends StorageProvider ? StorageOperationConfig<T, 'put'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'put'>, T>;
49export declare type StorageRemoveConfig<T> = T extends StorageProvider ? StorageOperationConfig<T, 'remove'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'remove'>, T>;
50export declare type StorageListConfig<T> = T extends StorageProvider ? StorageOperationConfig<T, 'list'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'list'>, T>;
51export declare type StorageCopyConfig<T> = T extends StorageProviderWithCopy ? StorageOperationConfig<T, 'copy'> : StorageOperationConfigMap<StorageOperationConfig<AWSS3Provider, 'copy'>, T>;
52/**
53 * Utility type for checking if the generic type is a provider or a Record that has the key 'provider'.
54 * If it's a provider, check if it's the S3 Provider, use the default type else use the generic's 'get' method
55 * return type.
56 * If it's a Record, check if provider is 'AWSS3', use the default type else use any.
57 */
58declare type PickProviderOutput<DefaultOutput, T, api extends StorageProviderApi> = T extends StorageProvider ? T['getProviderName'] extends 'AWSS3' ? DefaultOutput : T extends StorageProviderWithCopy ? ReturnType<T[api]> : ReturnType<T[Exclude<api, 'copy'>]> : T extends {
59 provider: string;
60} ? T extends {
61 provider: 'AWSS3';
62} ? DefaultOutput : Promise<any> : DefaultOutput;
63export declare type StorageGetOutput<T extends StorageProvider | Record<string, any>> = PickProviderOutput<Promise<S3ProviderGetOuput<T>>, T, 'get'>;
64export declare type StoragePutOutput<T> = PickProviderOutput<S3ProviderPutOutput<T>, T, 'put'>;
65export declare type StorageRemoveOutput<T> = PickProviderOutput<Promise<S3ProviderRemoveOutput>, T, 'remove'>;
66export declare type StorageListOutput<T> = PickProviderOutput<Promise<S3ProviderListOutput>, T, 'list'>;
67export declare type StorageCopyOutput<T> = PickProviderOutput<Promise<S3ProviderCopyOutput>, T, 'copy'>;
68/**
69 * Utility type to allow custom provider to use any config keys, if provider is set to AWSS3 then it should use
70 * AWSS3Provider's config.
71 */
72export declare type StorageOperationConfigMap<Default, T extends Record<string, any>> = T extends {
73 provider: string;
74} ? T extends {
75 provider: 'AWSS3';
76} ? Default : T & {
77 provider: string;
78} : Default;
79export {};