kbfetch 2.1.2-beta.4 → 2.1.2-beta.5

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 @@
1
+ export {};
@@ -0,0 +1,46 @@
1
+ type _KbFetchInit = Pick<DefaultKbFetch, 'baseUrl' | 'baseParams' | 'baseBody' | 'before' | 'parser' | 'after' | 'timeout'> & {
2
+ canAbort: boolean;
3
+ flags: Record<string, any>;
4
+ params: Record<string, any>;
5
+ body: Record<string, any>;
6
+ };
7
+ export type KbFetchInit = Omit<RequestInit, 'timeout' | 'headers'> & {
8
+ headers?: Object;
9
+ } & Partial<_KbFetchInit>;
10
+ export type Res<T> = Promise<T> & {
11
+ abort: () => void;
12
+ };
13
+ export interface DefaultKbFetch {
14
+ baseUrl?: string;
15
+ baseHeaders?: Record<string, any>;
16
+ baseParams?: Record<string, any>;
17
+ baseBody?: Record<string, any>;
18
+ before: <T extends any>(init: T) => T | void | Promise<T>;
19
+ after: <T>(res: Promise<Response & {
20
+ data: any;
21
+ }>, req: {
22
+ url: string;
23
+ init: KbFetchInit | undefined;
24
+ }) => Promise<T>;
25
+ parser: (res: Response) => any;
26
+ timeout: number;
27
+ do: <T>(url: string, init?: KbFetchInit) => Res<T>;
28
+ get: <T = any>(url: string, params?: Record<string, any>, init?: KbFetchInit) => Res<T>;
29
+ g: <T = any>(url: string, init?: KbFetchInit & {
30
+ params?: Record<string, any>;
31
+ }) => Res<T>;
32
+ post: <T = any>(url: string, body?: Record<string, any>, init?: KbFetchInit) => Res<T>;
33
+ p: <T = any>(url: string, init?: KbFetchInit) => Res<T>;
34
+ uploadFile: <T = any>(url: string, file: File, init?: KbFetchInit) => Res<T>;
35
+ }
36
+ declare const help: {
37
+ synthesizeUrlWithParams: (url: string, params?: Record<string, any>) => string;
38
+ parseResBody: (res: Response) => Promise<any>;
39
+ obj2header: (obj: Object) => Headers;
40
+ urlWithDomain: (url: string) => boolean;
41
+ urlWithProtocol: (url: string) => boolean;
42
+ addProtocol: (url?: string) => string | undefined;
43
+ objPick: <T extends Object, K extends keyof T>(obj: T, keys: K[]) => Pick<T, K>;
44
+ objSetDefVal: <O extends Object, K extends keyof O, D extends Object>(obj: O, key: K, def?: D) => ({} & D & O[K]) | undefined;
45
+ };
46
+ export default help;
@@ -0,0 +1,27 @@
1
+ import { DefaultKbFetch, KbFetchInit, Res } from './help';
2
+ export declare const createKbFetch: (config: Partial<Pick<DefaultKbFetch, "baseUrl" | "baseParams" | "baseBody" | "timeout" | "before" | "parser" | "after">>) => {
3
+ baseUrl?: string;
4
+ baseParams?: Record<string, any>;
5
+ baseBody?: Record<string, any>;
6
+ before: <T extends any>(init: T) => T | void | Promise<T>;
7
+ parser: (res: Response) => any;
8
+ after: <T>(res: Promise<Response & {
9
+ data: any;
10
+ }>, req: {
11
+ url: string;
12
+ init: KbFetchInit | undefined;
13
+ }) => Promise<T>;
14
+ timeout: number;
15
+ baseHeaders?: Record<string, any>;
16
+ do: <T>(url: string, init?: KbFetchInit) => Res<T>;
17
+ get: <T = any>(url: string, params?: Record<string, any>, init?: KbFetchInit) => Res<T>;
18
+ g: <T = any>(url: string, init?: KbFetchInit & {
19
+ params?: Record<string, any>;
20
+ }) => Res<T>;
21
+ post: <T = any>(url: string, body?: Record<string, any>, init?: KbFetchInit) => Res<T>;
22
+ p: <T = any>(url: string, init?: KbFetchInit) => Res<T>;
23
+ uploadFile: <T = any>(url: string, file: File, init?: KbFetchInit) => Res<T>;
24
+ };
25
+ declare const kbfetch: Omit<DefaultKbFetch, "do">;
26
+ export default kbfetch;
27
+ export declare const kbfc: Omit<DefaultKbFetch, "do">;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kbfetch",
3
- "version": "2.1.2-beta.4",
3
+ "version": "2.1.2-beta.5",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "devDependencies": {