@acrool/react-fetcher 0.0.2-alpha.1 → 0.0.2-alpha.11

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,2 +1 @@
1
- export declare const axiosInstance: import('axios').AxiosInstance;
2
1
  export declare const defaultI18nDict: Record<string, Record<string, string>>;
@@ -0,0 +1,2 @@
1
+ import { CreateAxiosDefaults } from 'axios';
2
+ export declare const createAxiosInstance: (config?: CreateAxiosDefaults) => import('axios').AxiosInstance;
@@ -0,0 +1 @@
1
+ export declare const fetcherLeastTime = 400;
@@ -0,0 +1,11 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { IUseFetcherArgs } from './types';
3
+ import { TFileMapVariables } from './utils';
4
+ /**
5
+ * GraphQL 的查詢器
6
+ * https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-react-query#usage-example-isreacthook-true
7
+ * @param axiosInstance
8
+ * @param query
9
+ */
10
+ declare const createGraphQLFetcher: <TData, TArgs extends IUseFetcherArgs<TFileMapVariables>>(axiosInstance: AxiosInstance, query: string) => ((args?: TArgs) => Promise<TData>);
11
+ export default createGraphQLFetcher;
@@ -0,0 +1,2 @@
1
+ export { default as createGraphQLFetcher } from './createGraphQLFetcher';
2
+ export type { IUseFetcherArgs as IUseGraphQLFetcherArgs } from './types';
@@ -0,0 +1,8 @@
1
+ import { IRequestConfig } from '../types';
2
+ export interface IUseFetcherArgs<TVariables = {}> {
3
+ variables?: TVariables;
4
+ fetchOptions?: IRequestConfig;
5
+ }
6
+ export interface IUseSubscriptionArgs<TVariables> {
7
+ variables?: TVariables;
8
+ }
@@ -0,0 +1,11 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { IDocument, IUseFetcherArgs, TContentTypeResolver, TFileMapVariables } from './types';
3
+ /**
4
+ * RestFul 的查詢器
5
+ * https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-react-query#usage-example-isreacthook-true
6
+ * @param axiosInstance
7
+ * @param document
8
+ * @param contentTypeResolver
9
+ */
10
+ declare const createRestFulFetcher: <TData, TArgs extends IUseFetcherArgs<TFileMapVariables>>(axiosInstance: AxiosInstance, document: IDocument, contentTypeResolver?: TContentTypeResolver) => ((args?: TArgs) => Promise<TData>);
11
+ export default createRestFulFetcher;
@@ -0,0 +1,2 @@
1
+ export { default as createRestFulFetcher } from './createRestFulFetcher';
2
+ export type { IUseFetcherArgs as IUseRestFulFetcherArgs, TContentTypeResolver, ERequestHeaderContentType } from './types';
@@ -0,0 +1,16 @@
1
+ import { IRequestConfig } from '../types';
2
+ export type IUseFetcherArgs<TVariables> = TVariables | (TVariables & {
3
+ fetchOptions?: IRequestConfig;
4
+ });
5
+ export interface IDocument {
6
+ url: string;
7
+ method?: string;
8
+ }
9
+ export type TFileMapVariables = Record<string, any>;
10
+ export type TBody = Record<string, any> | FormData | File[] | File;
11
+ export type TContentTypeResolver = (method: string) => string;
12
+ export declare enum ERequestHeaderContentType {
13
+ formData = "multipart/form-data",
14
+ formUrlDecode = "application/x-www-form-urlencoded",
15
+ json = "application/json"
16
+ }
@@ -0,0 +1,12 @@
1
+ import { TBody, TContentTypeResolver, ERequestHeaderContentType } from './types';
2
+ /**
3
+ * 依據 Content-Type 處理 body
4
+ * @param data
5
+ * @param contentType
6
+ */
7
+ export declare const getDataWithContentType: (contentType: ERequestHeaderContentType, data?: TBody) => FormData | string;
8
+ /**
9
+ * 根據 method 取得 Content-Type
10
+ * @param method
11
+ */
12
+ export declare const getContentTypeWithMethod: TContentTypeResolver;
@@ -1,2 +1,3 @@
1
- export { default as graphqlFetcher } from './graphqlFetcher';
2
- export type { IFetchOptions, IUseFetcherArgs, IUseSubscriptionArgs } from './types';
1
+ export * from './createGraphQLFetcher';
2
+ export * from './createRestFulFetcher';
3
+ export type { IRequestConfig } from './types';
@@ -1,11 +1,13 @@
1
- import { InternalAxiosRequestConfig } from 'axios';
2
- export interface IFetchOptions extends InternalAxiosRequestConfig {
1
+ import { AxiosRequestConfig, InternalAxiosRequestConfig } from 'axios';
2
+ interface IFetchOptions {
3
+ pendingRequest?: boolean;
3
4
  requestCode?: string;
5
+ forceGuest?: boolean;
6
+ leastTime?: number;
7
+ timeout?: number;
4
8
  }
5
- export interface IUseFetcherArgs<TVariables = {}> {
6
- variables?: TVariables;
7
- fetchOptions?: IFetchOptions;
9
+ export interface IInternalRequestConfig extends InternalAxiosRequestConfig, IFetchOptions {
8
10
  }
9
- export interface IUseSubscriptionArgs<TVariables> {
10
- variables?: TVariables;
11
+ export interface IRequestConfig extends AxiosRequestConfig, IFetchOptions {
11
12
  }
13
+ export {};
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './fetchers';
2
2
  export * from './FetcherProvider';
3
3
  export * from './AuthStateProvider';
4
+ export * from './createAxios';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@acrool/react-fetcher",
3
- "version": "0.0.2-alpha.1",
3
+ "version": "0.0.2-alpha.11",
4
4
  "description": "Fetcher library based for Reactjs",
5
5
  "keywords": [
6
6
  "acrool",
@@ -1,4 +0,0 @@
1
- import { IUseFetcherArgs } from './types';
2
- import { TFileMapVariables } from './utils';
3
- declare const graphqlFetcher: <TData, TArgs extends IUseFetcherArgs<TFileMapVariables>>(query: string) => ((args?: TArgs) => Promise<TData>);
4
- export default graphqlFetcher;