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

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.
@@ -1,10 +1,11 @@
1
1
  import { AxiosInstance } from 'axios';
2
- import { IUseFetcherArgs } from './types';
2
+ import { IUseGraphQLFetcherArgs } 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
  */
9
- declare const createGraphQLFetcher: <TData, TArgs extends IUseFetcherArgs<TFileMapVariables>>(axiosInstance: AxiosInstance, query: string) => ((args?: TArgs) => Promise<TData>);
10
+ declare const createGraphQLFetcher: <TData, TArgs extends IUseGraphQLFetcherArgs<TFileMapVariables>>(axiosInstance: AxiosInstance, query: string) => ((args?: TArgs) => Promise<TData>);
10
11
  export default createGraphQLFetcher;
@@ -1,2 +1,2 @@
1
1
  export { default as createGraphQLFetcher } from './createGraphQLFetcher';
2
- export type { IUseFetcherArgs as IUseGraphQLFetcherArgs } from './types';
2
+ export type { IUseGraphQLFetcherArgs } from './types';
@@ -1,5 +1,5 @@
1
1
  import { IRequestConfig } from '../types';
2
- export interface IUseFetcherArgs<TVariables = {}> {
2
+ export interface IUseGraphQLFetcherArgs<TVariables = {}> {
3
3
  variables?: TVariables;
4
4
  fetchOptions?: IRequestConfig;
5
5
  }
@@ -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, IUseRestFulFetcherArgs, 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 IUseRestFulFetcherArgs<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 { IUseRestFulFetcherArgs, TContentTypeResolver } from './types';
3
+ export * from './config';
@@ -1,9 +1,17 @@
1
1
  import { IRequestConfig } from '../types';
2
- export type IUseFetcherArgs<TVariables> = TVariables | (TVariables & {
2
+ import { ERequestMethod } from './config';
3
+ export type IUseRestFulFetcherArgs<TVariables> = [
4
+ TVariables
5
+ ] extends [void] ? void | {
3
6
  fetchOptions?: IRequestConfig;
4
- });
7
+ } : {
8
+ variables: TVariables;
9
+ fetchOptions?: IRequestConfig;
10
+ };
5
11
  export interface IDocument {
6
12
  url: string;
7
13
  method?: string;
8
14
  }
9
15
  export type TFileMapVariables = Record<string, any>;
16
+ export type TBody = Record<string, any> | FormData | File[] | File;
17
+ 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.3-alpha.0",
4
4
  "description": "Fetcher library based for Reactjs",
5
5
  "keywords": [
6
6
  "acrool",