@htkimura/files-storage-backend.rest-client 0.0.23 → 0.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Generated by orval v7.4.1 🍺
3
+ * Do not edit manually.
4
+ * files-storage
5
+ * This API is for storing files for different users
6
+ * OpenAPI spec version: 1.0
7
+ */
8
+ export type DeleteBulkFilesByIdsParams = {
9
+ ids: string[];
10
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Generated by orval v7.4.1 🍺
3
+ * Do not edit manually.
4
+ * files-storage
5
+ * This API is for storing files for different users
6
+ * OpenAPI spec version: 1.0
7
+ */
8
+ export {};
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Generated by orval v7.4.1 🍺
3
+ * Do not edit manually.
4
+ * files-storage
5
+ * This API is for storing files for different users
6
+ * OpenAPI spec version: 1.0
7
+ */
8
+ export interface DeleteBulkFilesOutput {
9
+ deleted: string[];
10
+ failed: string[];
11
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Generated by orval v7.4.1 🍺
3
+ * Do not edit manually.
4
+ * files-storage
5
+ * This API is for storing files for different users
6
+ * OpenAPI spec version: 1.0
7
+ */
8
+ export {};
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Generated by orval v7.4.1 🍺
3
+ * Do not edit manually.
4
+ * files-storage
5
+ * This API is for storing files for different users
6
+ * OpenAPI spec version: 1.0
7
+ */
8
+ export type GetPresignedUploadUrlParams = {
9
+ fileName: string;
10
+ fileType: string;
11
+ fileSize: number;
12
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Generated by orval v7.4.1 🍺
3
+ * Do not edit manually.
4
+ * files-storage
5
+ * This API is for storing files for different users
6
+ * OpenAPI spec version: 1.0
7
+ */
8
+ export {};
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Generated by orval v7.4.1 🍺
3
+ * Do not edit manually.
4
+ * files-storage
5
+ * This API is for storing files for different users
6
+ * OpenAPI spec version: 1.0
7
+ */
8
+ import type { File } from './file';
9
+ export interface GetUserFilesOutput {
10
+ data: File[];
11
+ page: number;
12
+ size: number;
13
+ total: number;
14
+ hasMore: boolean;
15
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -6,11 +6,16 @@
6
6
  * OpenAPI spec version: 1.0
7
7
  */
8
8
  export * from './createUserDto';
9
+ export * from './deleteBulkFilesByIdsParams';
10
+ export * from './deleteBulkFilesOutput';
9
11
  export * from './file';
10
12
  export * from './fileWithPresignedUrl';
11
13
  export * from './getBulkFilesByIdsParams';
12
- export * from './getPresignedUrlParams';
14
+ export * from './getPresignedUploadUrlParams';
15
+ export * from './getUserFilesOutput';
13
16
  export * from './loginDto';
17
+ export * from './myFilesParams';
14
18
  export * from './refreshTokenDto';
19
+ export * from './uploadFileOutput';
15
20
  export * from './user';
16
21
  export * from './userLogin';
@@ -6,11 +6,16 @@
6
6
  * OpenAPI spec version: 1.0
7
7
  */
8
8
  export * from './createUserDto';
9
+ export * from './deleteBulkFilesByIdsParams';
10
+ export * from './deleteBulkFilesOutput';
9
11
  export * from './file';
10
12
  export * from './fileWithPresignedUrl';
11
13
  export * from './getBulkFilesByIdsParams';
12
- export * from './getPresignedUrlParams';
14
+ export * from './getPresignedUploadUrlParams';
15
+ export * from './getUserFilesOutput';
13
16
  export * from './loginDto';
17
+ export * from './myFilesParams';
14
18
  export * from './refreshTokenDto';
19
+ export * from './uploadFileOutput';
15
20
  export * from './user';
16
21
  export * from './userLogin';
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Generated by orval v7.4.1 🍺
3
+ * Do not edit manually.
4
+ * files-storage
5
+ * This API is for storing files for different users
6
+ * OpenAPI spec version: 1.0
7
+ */
8
+ export type MyFilesParams = {
9
+ page?: number;
10
+ size?: number;
11
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Generated by orval v7.4.1 🍺
3
+ * Do not edit manually.
4
+ * files-storage
5
+ * This API is for storing files for different users
6
+ * OpenAPI spec version: 1.0
7
+ */
8
+ export {};
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Generated by orval v7.4.1 🍺
3
+ * Do not edit manually.
4
+ * files-storage
5
+ * This API is for storing files for different users
6
+ * OpenAPI spec version: 1.0
7
+ */
8
+ import type { File } from './file';
9
+ export interface UploadFileOutput {
10
+ file: File;
11
+ presignedUploadUrl: string;
12
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,25 +1,25 @@
1
- import type { QueryKey, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
1
+ import type { QueryKey, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
2
2
  import type { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios';
3
- import type { FileWithPresignedUrl, GetBulkFilesByIdsParams, GetPresignedUrlParams } from '.././model';
3
+ import type { DeleteBulkFilesByIdsParams, DeleteBulkFilesOutput, FileWithPresignedUrl, GetBulkFilesByIdsParams, GetPresignedUploadUrlParams, UploadFileOutput } from '.././model';
4
4
  /**
5
5
  * Returns presigned url to upload file
6
6
  * @summary Get presigned url to upload file
7
7
  */
8
- export declare const getPresignedUrl: (params: GetPresignedUrlParams, options?: AxiosRequestConfig) => Promise<AxiosResponse<string>>;
9
- export declare const getGetPresignedUrlQueryKey: (params: GetPresignedUrlParams) => readonly ["/uploads/presigned-url", ...GetPresignedUrlParams[]];
10
- export declare const getGetPresignedUrlQueryOptions: <TData = AxiosResponse<string, any>, TError = AxiosError<unknown, any>>(params: GetPresignedUrlParams, options?: {
11
- query?: UseQueryOptions<Awaited<ReturnType<typeof getPresignedUrl>>, TError, TData>;
8
+ export declare const getPresignedUploadUrl: (params: GetPresignedUploadUrlParams, options?: AxiosRequestConfig) => Promise<AxiosResponse<UploadFileOutput>>;
9
+ export declare const getGetPresignedUploadUrlQueryKey: (params: GetPresignedUploadUrlParams) => readonly ["/uploads/presigned-url", ...GetPresignedUploadUrlParams[]];
10
+ export declare const getGetPresignedUploadUrlQueryOptions: <TData = AxiosResponse<UploadFileOutput, any>, TError = AxiosError<unknown, any>>(params: GetPresignedUploadUrlParams, options?: {
11
+ query?: UseQueryOptions<Awaited<ReturnType<typeof getPresignedUploadUrl>>, TError, TData>;
12
12
  axios?: AxiosRequestConfig;
13
- }) => UseQueryOptions<Awaited<ReturnType<typeof getPresignedUrl>>, TError, TData> & {
13
+ }) => UseQueryOptions<Awaited<ReturnType<typeof getPresignedUploadUrl>>, TError, TData> & {
14
14
  queryKey: QueryKey;
15
15
  };
16
- export type GetPresignedUrlQueryResult = NonNullable<Awaited<ReturnType<typeof getPresignedUrl>>>;
17
- export type GetPresignedUrlQueryError = AxiosError<unknown>;
16
+ export type GetPresignedUploadUrlQueryResult = NonNullable<Awaited<ReturnType<typeof getPresignedUploadUrl>>>;
17
+ export type GetPresignedUploadUrlQueryError = AxiosError<unknown>;
18
18
  /**
19
19
  * @summary Get presigned url to upload file
20
20
  */
21
- export declare function useGetPresignedUrl<TData = Awaited<ReturnType<typeof getPresignedUrl>>, TError = AxiosError<unknown>>(params: GetPresignedUrlParams, options?: {
22
- query?: UseQueryOptions<Awaited<ReturnType<typeof getPresignedUrl>>, TError, TData>;
21
+ export declare function useGetPresignedUploadUrl<TData = Awaited<ReturnType<typeof getPresignedUploadUrl>>, TError = AxiosError<unknown>>(params: GetPresignedUploadUrlParams, options?: {
22
+ query?: UseQueryOptions<Awaited<ReturnType<typeof getPresignedUploadUrl>>, TError, TData>;
23
23
  axios?: AxiosRequestConfig;
24
24
  }): UseQueryResult<TData, TError> & {
25
25
  queryKey: QueryKey;
@@ -48,9 +48,35 @@ export declare function useGetBulkFilesByIds<TData = Awaited<ReturnType<typeof g
48
48
  queryKey: QueryKey;
49
49
  };
50
50
  /**
51
- * Returns file by id with presigned url
52
- * @summary Get file by id with presigned url
51
+ * Delete files on database and storage service by ids
52
+ * @summary Delete files by ids
53
53
  */
54
+ export declare const deleteBulkFilesByIds: (params: DeleteBulkFilesByIdsParams, options?: AxiosRequestConfig) => Promise<AxiosResponse<DeleteBulkFilesOutput>>;
55
+ export declare const getDeleteBulkFilesByIdsMutationOptions: <TData = AxiosResponse<DeleteBulkFilesOutput, any>, TError = AxiosError<unknown, any>, TContext = unknown>(options?: {
56
+ mutation?: UseMutationOptions<TData, TError, {
57
+ params: DeleteBulkFilesByIdsParams;
58
+ }, TContext>;
59
+ axios?: AxiosRequestConfig;
60
+ }) => UseMutationOptions<TData, TError, {
61
+ params: DeleteBulkFilesByIdsParams;
62
+ }, TContext>;
63
+ export type DeleteBulkFilesByIdsMutationResult = NonNullable<Awaited<ReturnType<typeof deleteBulkFilesByIds>>>;
64
+ export type DeleteBulkFilesByIdsMutationError = AxiosError<unknown>;
65
+ /**
66
+ * @summary Delete files by ids
67
+ */
68
+ export declare const useDeleteBulkFilesByIds: <TData = AxiosResponse<DeleteBulkFilesOutput, any>, TError = AxiosError<unknown, any>, TContext = unknown>(options?: {
69
+ mutation?: UseMutationOptions<TData, TError, {
70
+ params: DeleteBulkFilesByIdsParams;
71
+ }, TContext>;
72
+ axios?: AxiosRequestConfig;
73
+ }) => UseMutationResult<TData, TError, {
74
+ params: DeleteBulkFilesByIdsParams;
75
+ }, TContext>;
76
+ /**
77
+ * Returns file by id with presigned url
78
+ * @summary Get file by id with presigned url
79
+ */
54
80
  export declare const getFileById: (id: string, options?: AxiosRequestConfig) => Promise<AxiosResponse<FileWithPresignedUrl>>;
55
81
  export declare const getGetFileByIdQueryKey: (id: string) => readonly [`/files/${string}`];
56
82
  export declare const getGetFileByIdQueryOptions: <TData = AxiosResponse<FileWithPresignedUrl, any>, TError = AxiosError<unknown, any>>(id: string, options?: {
@@ -70,3 +96,29 @@ export declare function useGetFileById<TData = Awaited<ReturnType<typeof getFile
70
96
  }): UseQueryResult<TData, TError> & {
71
97
  queryKey: QueryKey;
72
98
  };
99
+ /**
100
+ * Delete file on database and storage service by id
101
+ * @summary Delete file by id
102
+ */
103
+ export declare const deleteFileById: (id: string, options?: AxiosRequestConfig) => Promise<AxiosResponse<boolean>>;
104
+ export declare const getDeleteFileByIdMutationOptions: <TData = AxiosResponse<boolean, any>, TError = AxiosError<unknown, any>, TContext = unknown>(options?: {
105
+ mutation?: UseMutationOptions<TData, TError, {
106
+ id: string;
107
+ }, TContext>;
108
+ axios?: AxiosRequestConfig;
109
+ }) => UseMutationOptions<TData, TError, {
110
+ id: string;
111
+ }, TContext>;
112
+ export type DeleteFileByIdMutationResult = NonNullable<Awaited<ReturnType<typeof deleteFileById>>>;
113
+ export type DeleteFileByIdMutationError = AxiosError<unknown>;
114
+ /**
115
+ * @summary Delete file by id
116
+ */
117
+ export declare const useDeleteFileById: <TData = AxiosResponse<boolean, any>, TError = AxiosError<unknown, any>, TContext = unknown>(options?: {
118
+ mutation?: UseMutationOptions<TData, TError, {
119
+ id: string;
120
+ }, TContext>;
121
+ axios?: AxiosRequestConfig;
122
+ }) => UseMutationResult<TData, TError, {
123
+ id: string;
124
+ }, TContext>;
@@ -5,32 +5,32 @@
5
5
  * This API is for storing files for different users
6
6
  * OpenAPI spec version: 1.0
7
7
  */
8
- import { useQuery } from '@tanstack/react-query';
8
+ import { useMutation, useQuery } from '@tanstack/react-query';
9
9
  import axios from 'axios';
10
10
  /**
11
11
  * Returns presigned url to upload file
12
12
  * @summary Get presigned url to upload file
13
13
  */
14
- export const getPresignedUrl = (params, options) => {
14
+ export const getPresignedUploadUrl = (params, options) => {
15
15
  return axios.get(`/uploads/presigned-url`, {
16
16
  ...options,
17
17
  params: { ...params, ...options?.params },
18
18
  });
19
19
  };
20
- export const getGetPresignedUrlQueryKey = (params) => {
20
+ export const getGetPresignedUploadUrlQueryKey = (params) => {
21
21
  return [`/uploads/presigned-url`, ...(params ? [params] : [])];
22
22
  };
23
- export const getGetPresignedUrlQueryOptions = (params, options) => {
23
+ export const getGetPresignedUploadUrlQueryOptions = (params, options) => {
24
24
  const { query: queryOptions, axios: axiosOptions } = options ?? {};
25
- const queryKey = queryOptions?.queryKey ?? getGetPresignedUrlQueryKey(params);
26
- const queryFn = ({ signal }) => getPresignedUrl(params, { signal, ...axiosOptions });
25
+ const queryKey = queryOptions?.queryKey ?? getGetPresignedUploadUrlQueryKey(params);
26
+ const queryFn = ({ signal }) => getPresignedUploadUrl(params, { signal, ...axiosOptions });
27
27
  return { queryKey, queryFn, ...queryOptions };
28
28
  };
29
29
  /**
30
30
  * @summary Get presigned url to upload file
31
31
  */
32
- export function useGetPresignedUrl(params, options) {
33
- const queryOptions = getGetPresignedUrlQueryOptions(params, options);
32
+ export function useGetPresignedUploadUrl(params, options) {
33
+ const queryOptions = getGetPresignedUploadUrlQueryOptions(params, options);
34
34
  const query = useQuery(queryOptions);
35
35
  query.queryKey = queryOptions.queryKey;
36
36
  return query;
@@ -64,9 +64,39 @@ export function useGetBulkFilesByIds(params, options) {
64
64
  return query;
65
65
  }
66
66
  /**
67
- * Returns file by id with presigned url
68
- * @summary Get file by id with presigned url
67
+ * Delete files on database and storage service by ids
68
+ * @summary Delete files by ids
69
69
  */
70
+ export const deleteBulkFilesByIds = (params, options) => {
71
+ return axios.delete(`/files/bulk`, {
72
+ ...options,
73
+ params: { ...params, ...options?.params },
74
+ });
75
+ };
76
+ export const getDeleteBulkFilesByIdsMutationOptions = (options) => {
77
+ const mutationKey = ['deleteBulkFilesByIds'];
78
+ const { mutation: mutationOptions, axios: axiosOptions } = options ?
79
+ options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
80
+ options
81
+ : { ...options, mutation: { ...options.mutation, mutationKey } }
82
+ : { mutation: { mutationKey, }, axios: undefined };
83
+ const mutationFn = (props) => {
84
+ const { params } = props ?? {};
85
+ return deleteBulkFilesByIds(params, axiosOptions);
86
+ };
87
+ return { mutationFn, ...mutationOptions };
88
+ };
89
+ /**
90
+ * @summary Delete files by ids
91
+ */
92
+ export const useDeleteBulkFilesByIds = (options) => {
93
+ const mutationOptions = getDeleteBulkFilesByIdsMutationOptions(options);
94
+ return useMutation(mutationOptions);
95
+ };
96
+ /**
97
+ * Returns file by id with presigned url
98
+ * @summary Get file by id with presigned url
99
+ */
70
100
  export const getFileById = (id, options) => {
71
101
  return axios.get(`/files/${id}`, options);
72
102
  };
@@ -88,3 +118,30 @@ export function useGetFileById(id, options) {
88
118
  query.queryKey = queryOptions.queryKey;
89
119
  return query;
90
120
  }
121
+ /**
122
+ * Delete file on database and storage service by id
123
+ * @summary Delete file by id
124
+ */
125
+ export const deleteFileById = (id, options) => {
126
+ return axios.delete(`/files/${id}`, options);
127
+ };
128
+ export const getDeleteFileByIdMutationOptions = (options) => {
129
+ const mutationKey = ['deleteFileById'];
130
+ const { mutation: mutationOptions, axios: axiosOptions } = options ?
131
+ options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
132
+ options
133
+ : { ...options, mutation: { ...options.mutation, mutationKey } }
134
+ : { mutation: { mutationKey, }, axios: undefined };
135
+ const mutationFn = (props) => {
136
+ const { id } = props ?? {};
137
+ return deleteFileById(id, axiosOptions);
138
+ };
139
+ return { mutationFn, ...mutationOptions };
140
+ };
141
+ /**
142
+ * @summary Delete file by id
143
+ */
144
+ export const useDeleteFileById = (options) => {
145
+ const mutationOptions = getDeleteFileByIdMutationOptions(options);
146
+ return useMutation(mutationOptions);
147
+ };
@@ -1,6 +1,6 @@
1
1
  import type { QueryKey, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
2
2
  import type { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios';
3
- import type { CreateUserDto, File, LoginDto, RefreshTokenDto, User, UserLogin } from '.././model';
3
+ import type { CreateUserDto, GetUserFilesOutput, LoginDto, MyFilesParams, RefreshTokenDto, User, UserLogin } from '.././model';
4
4
  /**
5
5
  * Creates a new user and returns the created user. We don't have plans for now to implement this on frontend, but it's here for testing purposes
6
6
  * @summary Sign up route where a user is created
@@ -109,9 +109,9 @@ export declare function useMe<TData = Awaited<ReturnType<typeof me>>, TError = A
109
109
  * Returns the authenticated user files URLs
110
110
  * @summary Get the authenticated user files URLs
111
111
  */
112
- export declare const myFiles: (options?: AxiosRequestConfig) => Promise<AxiosResponse<File[]>>;
113
- export declare const getMyFilesQueryKey: () => readonly ["/users/me/files"];
114
- export declare const getMyFilesQueryOptions: <TData = AxiosResponse<File[], any>, TError = AxiosError<unknown, any>>(options?: {
112
+ export declare const myFiles: (params: MyFilesParams, options?: AxiosRequestConfig) => Promise<AxiosResponse<GetUserFilesOutput>>;
113
+ export declare const getMyFilesQueryKey: (params: MyFilesParams) => readonly ["/users/me/files", ...MyFilesParams[]];
114
+ export declare const getMyFilesQueryOptions: <TData = AxiosResponse<GetUserFilesOutput, any>, TError = AxiosError<unknown, any>>(params: MyFilesParams, options?: {
115
115
  query?: UseQueryOptions<Awaited<ReturnType<typeof myFiles>>, TError, TData>;
116
116
  axios?: AxiosRequestConfig;
117
117
  }) => UseQueryOptions<Awaited<ReturnType<typeof myFiles>>, TError, TData> & {
@@ -122,7 +122,7 @@ export type MyFilesQueryError = AxiosError<unknown>;
122
122
  /**
123
123
  * @summary Get the authenticated user files URLs
124
124
  */
125
- export declare function useMyFiles<TData = Awaited<ReturnType<typeof myFiles>>, TError = AxiosError<unknown>>(options?: {
125
+ export declare function useMyFiles<TData = Awaited<ReturnType<typeof myFiles>>, TError = AxiosError<unknown>>(params: MyFilesParams, options?: {
126
126
  query?: UseQueryOptions<Awaited<ReturnType<typeof myFiles>>, TError, TData>;
127
127
  axios?: AxiosRequestConfig;
128
128
  }): UseQueryResult<TData, TError> & {
@@ -117,23 +117,26 @@ export function useMe(options) {
117
117
  * Returns the authenticated user files URLs
118
118
  * @summary Get the authenticated user files URLs
119
119
  */
120
- export const myFiles = (options) => {
121
- return axios.get(`/users/me/files`, options);
120
+ export const myFiles = (params, options) => {
121
+ return axios.get(`/users/me/files`, {
122
+ ...options,
123
+ params: { ...params, ...options?.params },
124
+ });
122
125
  };
123
- export const getMyFilesQueryKey = () => {
124
- return [`/users/me/files`];
126
+ export const getMyFilesQueryKey = (params) => {
127
+ return [`/users/me/files`, ...(params ? [params] : [])];
125
128
  };
126
- export const getMyFilesQueryOptions = (options) => {
129
+ export const getMyFilesQueryOptions = (params, options) => {
127
130
  const { query: queryOptions, axios: axiosOptions } = options ?? {};
128
- const queryKey = queryOptions?.queryKey ?? getMyFilesQueryKey();
129
- const queryFn = ({ signal }) => myFiles({ signal, ...axiosOptions });
131
+ const queryKey = queryOptions?.queryKey ?? getMyFilesQueryKey(params);
132
+ const queryFn = ({ signal }) => myFiles(params, { signal, ...axiosOptions });
130
133
  return { queryKey, queryFn, ...queryOptions };
131
134
  };
132
135
  /**
133
136
  * @summary Get the authenticated user files URLs
134
137
  */
135
- export function useMyFiles(options) {
136
- const queryOptions = getMyFilesQueryOptions(options);
138
+ export function useMyFiles(params, options) {
139
+ const queryOptions = getMyFilesQueryOptions(params, options);
137
140
  const query = useQuery(queryOptions);
138
141
  query.queryKey = queryOptions.queryKey;
139
142
  return query;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htkimura/files-storage-backend.rest-client",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "description": "REST client of files-storage-backend",
5
5
  "author": "Henry Kimura",
6
6
  "license": "MIT",