@anjianshi/utils 3.4.0 → 3.5.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anjianshi/utils",
3
- "version": "3.4.0",
3
+ "version": "3.5.0",
4
4
  "description": "Common JavaScript Utils",
5
5
  "homepage": "https://github.com/anjianshi/js-packages/utils",
6
6
  "bugs": {
@@ -31,11 +31,11 @@
31
31
  "redis": "^5.5.6",
32
32
  "typescript": "^5.8.3",
33
33
  "vconsole": "^3.15.1",
34
- "@anjianshi/presets-eslint-base": "6.0.0",
35
34
  "@anjianshi/presets-eslint-node": "6.0.0",
35
+ "@anjianshi/presets-eslint-base": "6.0.0",
36
36
  "@anjianshi/presets-eslint-typescript": "6.0.0",
37
- "@anjianshi/presets-eslint-react": "6.0.0",
38
37
  "@anjianshi/presets-prettier": "3.0.5",
38
+ "@anjianshi/presets-eslint-react": "6.0.0",
39
39
  "@anjianshi/presets-typescript": "3.2.5"
40
40
  },
41
41
  "peerDependencies": {
@@ -10,9 +10,9 @@ export declare abstract class BaseRequestClient<FailedT extends Failed> {
10
10
  loggerName?: string;
11
11
  });
12
12
  /** 生成一个快捷方式函数,调用它相当于调用 client.request() */
13
- asFunction(): <T>(inputUrl: string, inputOptions?: Options) => Promise<Result<T, FailedT>>;
14
- request<T>(inputUrl: string, inputOptions?: Options): Promise<Result<T, FailedT>>;
15
- formatOptions(input: Options): Promise<FormattedOptions>;
13
+ asFunction(): <T>(inputUrl: string, inputOptions?: Options<T>) => Promise<Result<T, FailedT>>;
14
+ request<T>(inputUrl: string, inputOptions?: Options<T>): Promise<Result<T, FailedT>>;
15
+ formatOptions<T>(input: Options<T>): Promise<FormattedOptions<T>>;
16
16
  /** 请求发起前调用此方法补充 Headers 内容 */
17
17
  protected getHeaders(options: FormattedOptions, inputOptions: Options): Record<string, string> | undefined | Promise<Record<string, string> | undefined>;
18
18
  /**
@@ -1,4 +1,4 @@
1
1
  import { RequestClient } from './client.js';
2
2
  /** 提供一个即取即用的 RequestClient 实例及其函数版本 */
3
3
  export declare const client: RequestClient;
4
- export declare const request: <T>(inputUrl: string, inputOptions?: import("./options.js").Options) => Promise<import("../index.js").Result<T, import("./error.js").RequestFailed>>;
4
+ export declare const request: <T>(inputUrl: string, inputOptions?: import("./options.js").Options<T> | undefined) => Promise<import("../index.js").Result<T, import("./error.js").RequestFailed>>;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 请求参数
3
3
  */
4
- export interface Options {
4
+ export interface Options<T = unknown> {
5
5
  urlPrefix?: string;
6
6
  url?: string;
7
7
  query?: Record<string, string | number | undefined>;
@@ -20,9 +20,9 @@ export interface Options {
20
20
  /** 可通过此信号手动终止请求 */
21
21
  signal?: AbortSignal;
22
22
  /** 对请求成功时得到的数据进行最终格式化 */
23
- format?: (responseData: any) => any;
23
+ format?: (responseData: any) => T;
24
24
  }
25
25
  /** 可预指定的请求参数 */
26
26
  export type PredefinedOptions = Pick<Options, 'urlPrefix' | 'method' | 'headers' | 'timeout'>;
27
27
  /** 经过整理的请求参数(client 内部使用) */
28
- export type FormattedOptions = Required<Pick<Options, 'url' | 'method' | 'headers' | 'body' | 'timeout' | 'binary'>> & Pick<Options, 'signal' | 'format'>;
28
+ export type FormattedOptions<T = unknown> = Required<Pick<Options, 'url' | 'method' | 'headers' | 'body' | 'timeout' | 'binary'>> & Pick<Options<T>, 'signal' | 'format'>;