@acrool/react-fetcher 0.0.2-alpha.9 → 0.0.2

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.
@@ -2,7 +2,8 @@ import { AxiosInstance } from 'axios';
2
2
  import { IUseFetcherArgs } from './types';
3
3
  import { TFileMapVariables } from './utils';
4
4
  /**
5
- * GrqpahQL 的查詢器
5
+ * GraphQL 的查詢器
6
+ * https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-react-query#usage-example-isreacthook-true
6
7
  * @param axiosInstance
7
8
  * @param query
8
9
  */
@@ -1,5 +1,12 @@
1
- export declare enum ERequestHeaderContentType {
1
+ export declare enum ERequestContentType {
2
2
  formData = "multipart/form-data",
3
3
  formUrlDecode = "application/x-www-form-urlencoded",
4
4
  json = "application/json"
5
5
  }
6
+ export declare enum ERequestMethod {
7
+ GET = "GET",
8
+ POST = "POST",
9
+ PUT = "PUT",
10
+ DELETE = "DELETE",
11
+ PATCH = "PATCH"
12
+ }
@@ -1,9 +1,11 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { IDocument, IUseFetcherArgs, TFileMapVariables } from './types';
2
+ import { IDocument, IUseFetcherArgs, TContentTypeResolver, TFileMapVariables } from './types';
3
3
  /**
4
4
  * RestFul 的查詢器
5
+ * https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-react-query#usage-example-isreacthook-true
5
6
  * @param axiosInstance
6
7
  * @param document
8
+ * @param contentTypeResolver
7
9
  */
8
- declare const createRestFulFetcher: <TData, TArgs extends IUseFetcherArgs<TFileMapVariables>>(axiosInstance: AxiosInstance, document: IDocument) => ((args?: TArgs) => Promise<TData>);
10
+ declare const createRestFulFetcher: <TData, TArgs extends IUseFetcherArgs<TFileMapVariables>>(axiosInstance: AxiosInstance, document: IDocument, contentTypeResolver?: TContentTypeResolver) => ((args?: TArgs) => Promise<TData>);
9
11
  export default createRestFulFetcher;
@@ -1,3 +1,3 @@
1
1
  export { default as createRestFulFetcher } from './createRestFulFetcher';
2
- export type { IUseFetcherArgs as IUseRestFulFetcherArgs } from './types';
3
- export type { ERequestHeaderContentType } from './config';
2
+ export type { IUseFetcherArgs as IUseRestFulFetcherArgs, TContentTypeResolver } from './types';
3
+ export * from './config';
@@ -1,4 +1,5 @@
1
1
  import { IRequestConfig } from '../types';
2
+ import { ERequestMethod } from './config';
2
3
  export type IUseFetcherArgs<TVariables> = TVariables | (TVariables & {
3
4
  fetchOptions?: IRequestConfig;
4
5
  });
@@ -7,3 +8,5 @@ export interface IDocument {
7
8
  method?: string;
8
9
  }
9
10
  export type TFileMapVariables = Record<string, any>;
11
+ export type TBody = Record<string, any> | FormData | File[] | File;
12
+ export type TContentTypeResolver = (method: ERequestMethod) => string;
@@ -1,10 +1,13 @@
1
- import { ERequestHeaderContentType } from './config';
1
+ import { ERequestContentType } from './config';
2
+ import { TBody, TContentTypeResolver } from './types';
2
3
  /**
3
- *
4
- * @param obj 送出物件
4
+ * 依據 Content-Type 處理 body
5
+ * @param data
5
6
  * @param contentType
6
7
  */
7
- export declare function flattenObjectToFormData(obj: Record<string, any>, contentType: ERequestHeaderContentType): {
8
- body: FormData | string;
9
- contentType: string;
10
- };
8
+ export declare const getDataWithContentType: (contentType: ERequestContentType, data?: TBody) => FormData | string;
9
+ /**
10
+ * 根據 method 取得 Content-Type
11
+ * @param method
12
+ */
13
+ export declare const getContentTypeWithMethod: TContentTypeResolver;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acrool/react-fetcher",
3
- "version": "0.0.2-alpha.9",
3
+ "version": "0.0.2",
4
4
  "description": "Fetcher library based for Reactjs",
5
5
  "keywords": [
6
6
  "acrool",