kbfetch 2.1.2-beta.3 → 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.
- package/dist/types/.test.d.ts +1 -0
- package/dist/types/help.d.ts +46 -0
- package/dist/types/index.d.ts +27 -0
- package/dist/typings/.test.d.ts +1 -0
- package/dist/typings/help.d.ts +6 -6
- package/dist/typings/index.d.ts +16 -28
- package/package.json +2 -3
|
@@ -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">;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/typings/help.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ type _KbFetchInit = Pick<DefaultKbFetch, 'baseUrl' | 'baseParams' | 'baseBody' |
|
|
|
7
7
|
export type KbFetchInit = Omit<RequestInit, 'timeout' | 'headers'> & {
|
|
8
8
|
headers?: Object;
|
|
9
9
|
} & Partial<_KbFetchInit>;
|
|
10
|
-
type Res<T> = Promise<T> & {
|
|
10
|
+
export type Res<T> = Promise<T> & {
|
|
11
11
|
abort: () => void;
|
|
12
12
|
};
|
|
13
13
|
export interface DefaultKbFetch {
|
|
@@ -15,13 +15,13 @@ export interface DefaultKbFetch {
|
|
|
15
15
|
baseHeaders?: Record<string, any>;
|
|
16
16
|
baseParams?: Record<string, any>;
|
|
17
17
|
baseBody?: Record<string, any>;
|
|
18
|
-
before: <T extends any>(init: T) => T | void
|
|
19
|
-
after: (res: Promise<Response & {
|
|
18
|
+
before: <T extends any>(init: T) => T | void | Promise<T>;
|
|
19
|
+
after: <T>(res: Promise<Response & {
|
|
20
20
|
data: any;
|
|
21
21
|
}>, req: {
|
|
22
22
|
url: string;
|
|
23
23
|
init: KbFetchInit | undefined;
|
|
24
|
-
}) =>
|
|
24
|
+
}) => Promise<T>;
|
|
25
25
|
parser: (res: Response) => any;
|
|
26
26
|
timeout: number;
|
|
27
27
|
do: <T>(url: string, init?: KbFetchInit) => Res<T>;
|
|
@@ -39,8 +39,8 @@ declare const help: {
|
|
|
39
39
|
obj2header: (obj: Object) => Headers;
|
|
40
40
|
urlWithDomain: (url: string) => boolean;
|
|
41
41
|
urlWithProtocol: (url: string) => boolean;
|
|
42
|
-
addProtocol: (url?: string) => string;
|
|
42
|
+
addProtocol: (url?: string) => string | undefined;
|
|
43
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];
|
|
44
|
+
objSetDefVal: <O extends Object, K extends keyof O, D extends Object>(obj: O, key: K, def?: D) => ({} & D & O[K]) | undefined;
|
|
45
45
|
};
|
|
46
46
|
export default help;
|
package/dist/typings/index.d.ts
CHANGED
|
@@ -1,38 +1,26 @@
|
|
|
1
|
-
import { DefaultKbFetch } from './help';
|
|
1
|
+
import { DefaultKbFetch, KbFetchInit, Res } from './help';
|
|
2
2
|
export declare const createKbFetch: (config: Partial<Pick<DefaultKbFetch, "baseUrl" | "baseParams" | "baseBody" | "timeout" | "before" | "parser" | "after">>) => {
|
|
3
|
-
after: (res: Promise<Response & {
|
|
4
|
-
data: any;
|
|
5
|
-
}>, req: {
|
|
6
|
-
url: string;
|
|
7
|
-
init: import("./help").KbFetchInit | undefined;
|
|
8
|
-
}) => any;
|
|
9
|
-
before: <T extends any>(init: T) => T | void;
|
|
10
|
-
timeout: number;
|
|
11
3
|
baseUrl?: string;
|
|
12
4
|
baseParams?: Record<string, any>;
|
|
13
5
|
baseBody?: Record<string, any>;
|
|
6
|
+
before: <T extends any>(init: T) => T | void | Promise<T>;
|
|
14
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
15
|
baseHeaders?: Record<string, any>;
|
|
16
|
-
do: <T>(url: string, init?:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
get: <T = any>(url: string, params?: Record<string, any>, init?: import("./help").KbFetchInit) => Promise<T> & {
|
|
20
|
-
abort: () => void;
|
|
21
|
-
};
|
|
22
|
-
g: <T = any>(url: string, init?: import("./help").KbFetchInit & {
|
|
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 & {
|
|
23
19
|
params?: Record<string, any>;
|
|
24
|
-
}) =>
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
abort: () => void;
|
|
29
|
-
};
|
|
30
|
-
p: <T = any>(url: string, init?: import("./help").KbFetchInit) => Promise<T> & {
|
|
31
|
-
abort: () => void;
|
|
32
|
-
};
|
|
33
|
-
uploadFile: <T = any>(url: string, file: File, init?: import("./help").KbFetchInit) => Promise<T> & {
|
|
34
|
-
abort: () => void;
|
|
35
|
-
};
|
|
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>;
|
|
36
24
|
};
|
|
37
25
|
declare const kbfetch: Omit<DefaultKbFetch, "do">;
|
|
38
26
|
export default kbfetch;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kbfetch",
|
|
3
|
-
"version": "2.1.2-beta.
|
|
3
|
+
"version": "2.1.2-beta.5",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index.js",
|
|
6
6
|
"devDependencies": {
|
|
@@ -21,10 +21,9 @@
|
|
|
21
21
|
],
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"scripts": {
|
|
24
|
-
"pub": "bun bld &&
|
|
24
|
+
"pub": "bun bld && tsc && npm publish --tag beta --registry https://registry.npmjs.org/ ",
|
|
25
25
|
"patch": "git stash && npm version patch && git stash pop",
|
|
26
26
|
"updatetaobao": "cnpm sync kbfetch",
|
|
27
|
-
"tsc": "tsc -d --emitDeclarationOnly --declarationDir ./dist/typings",
|
|
28
27
|
"bld": "bun build ./index.ts --outdir ./dist",
|
|
29
28
|
"t": "bun t.ts"
|
|
30
29
|
},
|