@rdyl/request 0.0.1 → 0.0.3
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/CHANGELOG.md +1 -1
- package/package.json +4 -6
- package/types/index.d.ts +13 -0
- package/types/taro/index.d.ts +2 -0
- package/types/taro/url.d.ts +25 -0
- package/types/type.d.ts +25 -0
- package/types/utils.d.ts +8 -0
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rdyl/request",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"license": "MIT",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./types/index.d.ts",
|
|
5
7
|
"publishConfig": {
|
|
6
8
|
"access": "public"
|
|
7
9
|
},
|
|
@@ -11,10 +13,6 @@
|
|
|
11
13
|
"CHANGELOG.md",
|
|
12
14
|
"README.md"
|
|
13
15
|
],
|
|
14
|
-
"exports": {
|
|
15
|
-
".": "./dist/index.js",
|
|
16
|
-
"./taro": "./dist/taro/index.js"
|
|
17
|
-
},
|
|
18
16
|
"scripts": {
|
|
19
17
|
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
|
|
20
18
|
"build": "tsc && copyfiles -u 1 src/**/*.d.ts src/*.d.ts types && npm run changelog && git add CHANGELOG.md"
|
|
@@ -28,6 +26,6 @@
|
|
|
28
26
|
"conventional-changelog-cli": "^5.0.0"
|
|
29
27
|
},
|
|
30
28
|
"dependencies": {
|
|
31
|
-
"axios": "
|
|
29
|
+
"axios": "1.12.2"
|
|
32
30
|
}
|
|
33
31
|
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CreateReqParams, ReqInstance } from "./type";
|
|
2
|
+
export declare function CreateRequest<C extends Record<string, unknown> = {}>(baseURL: string, opts: CreateReqParams): {
|
|
3
|
+
request: ReqInstance<C>;
|
|
4
|
+
toRestful(path: string): {
|
|
5
|
+
getList(params?: Record<string, unknown>, c?: Partial<import("./type").RequestConfig>): Promise<unknown[]>;
|
|
6
|
+
get(id: string, c?: import("./type").RequestConfig): Promise<unknown>;
|
|
7
|
+
update<P = Partial<unknown>, D = unknown>(id: string, data?: P | undefined, c?: import("./type").RequestConfig): Promise<D>;
|
|
8
|
+
insert<P = Partial<unknown>, D = unknown>(data?: P | undefined, c?: import("./type").RequestConfig): Promise<D>;
|
|
9
|
+
delete(ids: string[], c?: import("./type").RequestConfig): Promise<unknown[]>;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export * from "./utils";
|
|
13
|
+
export * from "./type";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare class URLSearchParams {
|
|
2
|
+
constructor(str: string);
|
|
3
|
+
private values;
|
|
4
|
+
get keys(): string[];
|
|
5
|
+
get size(): number;
|
|
6
|
+
append(k: string, n: string | number): void;
|
|
7
|
+
assign(pay: Record<string, unknown>): void;
|
|
8
|
+
get(k: string): string | string[];
|
|
9
|
+
delete(...arr: string[]): void;
|
|
10
|
+
forEach(fn: (k: string, v: string | string[]) => unknown): void;
|
|
11
|
+
toString(): string;
|
|
12
|
+
}
|
|
13
|
+
export declare class URL {
|
|
14
|
+
href: string;
|
|
15
|
+
static pattern: RegExp;
|
|
16
|
+
searchParams: URLSearchParams;
|
|
17
|
+
host: string;
|
|
18
|
+
port: string | number;
|
|
19
|
+
protocol: string;
|
|
20
|
+
pathname: string;
|
|
21
|
+
hash: string;
|
|
22
|
+
constructor(href: string);
|
|
23
|
+
get origin(): string;
|
|
24
|
+
toString(): string;
|
|
25
|
+
}
|
package/types/type.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { AxiosError, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from "axios";
|
|
2
|
+
export type RequestConfig<T extends Record<string, unknown> = {}> = AxiosRequestConfig & {
|
|
3
|
+
ignore?: boolean;
|
|
4
|
+
upload?: boolean;
|
|
5
|
+
} & T;
|
|
6
|
+
export type ConfigCallback = (config: InternalAxiosRequestConfig<unknown>) => InternalAxiosRequestConfig<unknown> | Promise<InternalAxiosRequestConfig<unknown>>;
|
|
7
|
+
export interface CreateReqParams {
|
|
8
|
+
beforeRequest: ConfigCallback;
|
|
9
|
+
success(res: AxiosResponse): any;
|
|
10
|
+
fail(res: AxiosError): any;
|
|
11
|
+
adapter?(config: RequestConfig): Promise<any>;
|
|
12
|
+
}
|
|
13
|
+
export type ReqInstance<C extends Record<string, unknown> = {}> = <T = void>(config: RequestConfig<C>) => Promise<T>;
|
|
14
|
+
export declare enum HttpStatus {
|
|
15
|
+
ok = 200,// 成功
|
|
16
|
+
okCreated = 201,// 成功创建已完成
|
|
17
|
+
okAccept = 202,// 成功接受 处理等待
|
|
18
|
+
notFound = 404,// 参数未找到
|
|
19
|
+
parameterError = 400,// 参数错误
|
|
20
|
+
unauthorized = 401,// 验证不通过
|
|
21
|
+
inaccessible = 403,// 过期 |不可访问 |权限不足
|
|
22
|
+
exception = 500,// 服务器错误
|
|
23
|
+
unavailable = 503
|
|
24
|
+
}
|
|
25
|
+
export type HttpStatusCode = keyof typeof HttpStatus;
|
package/types/utils.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ReqInstance, RequestConfig } from "./type";
|
|
2
|
+
export declare function ParserRestful<T>(request: ReqInstance, url: string): {
|
|
3
|
+
getList(params?: Record<string, unknown>, c?: Partial<RequestConfig>): Promise<T[]>;
|
|
4
|
+
get(id: string, c?: RequestConfig): Promise<T>;
|
|
5
|
+
update<P = Partial<T>, D = T>(id: string, data?: P, c?: RequestConfig): Promise<D>;
|
|
6
|
+
insert<P = Partial<T>, D = T>(data?: P, c?: RequestConfig): Promise<D>;
|
|
7
|
+
delete(ids: string[], c?: RequestConfig): Promise<T[]>;
|
|
8
|
+
};
|