@pawover/kit 0.2.1 → 0.3.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
@@ -6,7 +6,7 @@
6
6
  "url": "https://github.com/pawover"
7
7
  },
8
8
  "description": "一个基于 TypeScript 的开发工具包",
9
- "version": "0.2.1",
9
+ "version": "0.3.0",
10
10
  "type": "module",
11
11
  "engines": {
12
12
  "node": ">=22.20.0"
@@ -51,34 +51,34 @@
51
51
  "./zod/*": "./packages/zod/dist/*"
52
52
  },
53
53
  "devDependencies": {
54
- "@commitlint/cli": "^21.1.0",
55
- "@commitlint/config-conventional": "^21.1.0",
56
- "@eslint-react/eslint-plugin": "^5.10.0",
57
- "@pawover/eslint-rules": "^0.2.1",
54
+ "@commitlint/cli": "^21.2.1",
55
+ "@commitlint/config-conventional": "^21.2.0",
56
+ "@eslint-react/eslint-plugin": "^5.14.8",
57
+ "@pawover/eslint-rules": "^0.2.3",
58
58
  "@playwright/test": "^1.61.1",
59
59
  "@stylistic/eslint-plugin": "^6.0.0-beta.5",
60
60
  "@types/fs-extra": "^11.0.4",
61
- "@types/node": "^26.0.1",
61
+ "@types/node": "^26.1.1",
62
62
  "@vitejs/plugin-react": "^6.0.3",
63
- "@vitest/browser-playwright": "^4.1.9",
63
+ "@vitest/browser-playwright": "^4.1.10",
64
64
  "commitizen": "^4.3.2",
65
65
  "cz-customizable": "^7.5.4",
66
- "eslint": "^10.6.0",
66
+ "eslint": "^10.7.0",
67
67
  "eslint-plugin-antfu": "^3.2.3",
68
68
  "eslint-plugin-import-lite": "^0.6.0",
69
69
  "eslint-plugin-react-hooks": "^7.1.1",
70
- "fs-extra": "^11.3.5",
70
+ "fs-extra": "^11.3.6",
71
71
  "husky": "^9.1.7",
72
72
  "jsdom": "^29.1.1",
73
73
  "lint-staged": "^17.0.8",
74
- "prettier": "^3.9.1",
74
+ "prettier": "^3.9.5",
75
75
  "rimraf": "^6.1.3",
76
76
  "taze": "^19.14.1",
77
- "tsdown": "^0.22.3",
78
- "turbo": "^2.10.0",
77
+ "tsdown": "^0.22.7",
78
+ "turbo": "^2.10.5",
79
79
  "typescript": "^6.0.3",
80
- "typescript-eslint": "^8.62.1",
81
- "vitest": "^4.1.9"
80
+ "typescript-eslint": "^8.64.0",
81
+ "vitest": "^4.1.10"
82
82
  },
83
83
  "peerDependencies": {
84
84
  "alova": "^3.3.0",
@@ -1,9 +1,8 @@
1
1
  import { AlovaFrontMiddlewareContext, AlovaMethodHandler, CompleteHandler, ErrorHandler, PaginationHookConfig, RequestHookConfig, SuccessHandler, WatcherHookConfig } from "alova/client";
2
2
  import { AlovaGenerics, Method } from "alova";
3
-
4
3
  //#region src/alova/useAlovaPagination.d.ts
5
4
  interface HookOptions$2<AG extends AlovaGenerics, L extends any[], Args extends any[]> extends PaginationHookConfig<AG, L> {
6
- onBeforeRequest?: ((context: AlovaFrontMiddlewareContext<AG, any[]>) => void) | undefined;
5
+ onBeforeRequest?: BeforeRequestHandler<AG, any[]> | undefined;
7
6
  onSuccess?: SuccessHandler<AG, Args> | undefined;
8
7
  onError?: ErrorHandler<AG, Args> | undefined;
9
8
  onComplete?: CompleteHandler<AG, Args> | undefined;
@@ -12,7 +11,7 @@ declare function useAlovaPagination<AG extends AlovaGenerics, L extends any[], A
12
11
  //#endregion
13
12
  //#region src/alova/useAlovaRequest.d.ts
14
13
  interface HookOptions$1<AG extends AlovaGenerics, Args extends any[]> extends RequestHookConfig<AG, Args> {
15
- onBeforeRequest?: ((context: AlovaFrontMiddlewareContext<AG, Args>) => void) | undefined;
14
+ onBeforeRequest?: BeforeRequestHandler<AG, Args> | undefined;
16
15
  onSuccess?: SuccessHandler<AG, Args> | undefined;
17
16
  onError?: ErrorHandler<AG, Args> | undefined;
18
17
  onComplete?: CompleteHandler<AG, Args> | undefined;
@@ -21,10 +20,14 @@ declare function useAlovaRequest<AG extends AlovaGenerics, Args extends any[] =
21
20
  //#endregion
22
21
  //#region src/alova/useAlovaWatcher.d.ts
23
22
  interface HookOptions<AG extends AlovaGenerics, Args extends any[]> extends WatcherHookConfig<AG, Args> {
23
+ onBeforeRequest?: BeforeRequestHandler<AG, Args> | undefined;
24
24
  onSuccess?: SuccessHandler<AG, Args> | undefined;
25
25
  onError?: ErrorHandler<AG, Args> | undefined;
26
26
  onComplete?: CompleteHandler<AG, Args> | undefined;
27
27
  }
28
28
  declare function useAlovaWatcher<AG extends AlovaGenerics, Args extends any[] = any[]>(methodHandler: Method<AG> | AlovaMethodHandler<AG, Args>, watchingStates: AG["StatesExport"]["Watched"][], hookOptions?: HookOptions<AG, Args>): import("alova/client").UseHookExposure<AG, Args, unknown>;
29
29
  //#endregion
30
- export { useAlovaPagination, useAlovaRequest, useAlovaWatcher };
30
+ //#region src/alova/index.d.ts
31
+ type BeforeRequestHandler<AG extends AlovaGenerics, Args extends any[] = any[]> = (context: AlovaFrontMiddlewareContext<AG, Args>) => void;
32
+ //#endregion
33
+ export { BeforeRequestHandler, useAlovaPagination, useAlovaRequest, useAlovaWatcher };
@@ -1,23 +1,20 @@
1
1
  import { usePagination, useRequest, useWatcher } from "alova/client";
2
+ //#region src/alova/createBeforeRequestMiddleware.ts
3
+ function createBeforeRequestMiddleware(middleware, onBeforeRequest) {
4
+ return async (context, next) => {
5
+ onBeforeRequest?.(context);
6
+ if (middleware) return middleware(context, next);
7
+ return next();
8
+ };
9
+ }
10
+ //#endregion
2
11
  //#region src/alova/useAlovaPagination.ts
3
12
  function useAlovaPagination(methodHandler, hookOptions) {
4
13
  const options = {
5
14
  ...hookOptions,
6
15
  immediate: hookOptions?.immediate ?? true
7
16
  };
8
- let isBeforeExecuted = false;
9
- let isMiddlewareExecuted = false;
10
- if (options.onBeforeRequest) {
11
- const middleware = options.middleware;
12
- options.middleware = async (context, next) => {
13
- !isBeforeExecuted && options.onBeforeRequest?.(context);
14
- isBeforeExecuted = true;
15
- if (middleware && !isMiddlewareExecuted) {
16
- isMiddlewareExecuted = true;
17
- await middleware?.(context, next);
18
- } else await next();
19
- };
20
- }
17
+ if (options.onBeforeRequest) options.middleware = createBeforeRequestMiddleware(options.middleware, options.onBeforeRequest);
21
18
  const exposure = usePagination(methodHandler, options);
22
19
  if (options.onSuccess) exposure.onSuccess(options.onSuccess);
23
20
  if (options.onError) exposure.onError(options.onError);
@@ -31,19 +28,7 @@ function useAlovaRequest(methodHandler, hookOptions) {
31
28
  ...hookOptions,
32
29
  immediate: hookOptions?.immediate ?? true
33
30
  };
34
- let isBeforeExecuted = false;
35
- let isMiddlewareExecuted = false;
36
- if (options.onBeforeRequest) {
37
- const middleware = options.middleware;
38
- options.middleware = async (context, next) => {
39
- !isBeforeExecuted && options.onBeforeRequest?.(context);
40
- isBeforeExecuted = true;
41
- if (middleware && !isMiddlewareExecuted) {
42
- isMiddlewareExecuted = true;
43
- await middleware?.(context, next);
44
- } else await next();
45
- };
46
- }
31
+ if (options.onBeforeRequest) options.middleware = createBeforeRequestMiddleware(options.middleware, options.onBeforeRequest);
47
32
  const exposure = useRequest(methodHandler, options);
48
33
  if (options.onSuccess) exposure.onSuccess(options.onSuccess);
49
34
  if (options.onError) exposure.onError(options.onError);
@@ -53,7 +38,8 @@ function useAlovaRequest(methodHandler, hookOptions) {
53
38
  //#endregion
54
39
  //#region src/alova/useAlovaWatcher.ts
55
40
  function useAlovaWatcher(methodHandler, watchingStates, hookOptions = {}) {
56
- const options = hookOptions || {};
41
+ const options = { ...hookOptions };
42
+ if (options.onBeforeRequest) options.middleware = createBeforeRequestMiddleware(options.middleware, options.onBeforeRequest);
57
43
  const exposure = useWatcher(methodHandler, watchingStates, options);
58
44
  if (options.onSuccess) exposure.onSuccess(options.onSuccess);
59
45
  if (options.onError) exposure.onError(options.onError);
@@ -1,5 +1,4 @@
1
1
  import { EffectCallback, RefObject } from "react";
2
-
3
2
  //#region src/react/useLatest.d.ts
4
3
  /**
5
4
  * 返回当前最新值的 Hook
@@ -13,7 +12,6 @@ declare function useLatest<T>(value: T): RefObject<T>;
13
12
  type AnyFunction<P extends any[] = any[], R = any> = (...arg: P) => R;
14
13
  /** 描述异步函数类型 */
15
14
  type AnyAsyncFunction<P extends any[] = any[], R = any> = (...args: P) => Promise<R>;
16
- /** 描述生成器函数类型 */
17
15
  //#endregion
18
16
  //#region src/react/useMount.d.ts
19
17
  /**
@@ -36,7 +34,7 @@ type AnyAsyncFunction<P extends any[] = any[], R = any> = (...args: P) => Promis
36
34
  */
37
35
  declare function useMount(effect: EffectCallback | AnyAsyncFunction): void;
38
36
  //#endregion
39
- //#region ../../node_modules/.pnpm/type-fest@5.7.0/node_modules/type-fest/source/tuple-to-union.d.ts
37
+ //#region ../../node_modules/.pnpm/type-fest@5.8.0/node_modules/type-fest/source/tuple-to-union.d.ts
40
38
  /**
41
39
  Convert a tuple/array into a union type of its elements.
42
40
 
@@ -1666,6 +1666,23 @@ function useMount(effect) {
1666
1666
  }, [effectRef]);
1667
1667
  }
1668
1668
  //#endregion
1669
+ //#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/_internal/globalThis.mjs
1670
+ const globalThis_ = typeof globalThis === "object" && globalThis || typeof window === "object" && window || typeof self === "object" && self || typeof global === "object" && global || (function() {
1671
+ return this;
1672
+ })();
1673
+ //#endregion
1674
+ //#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/function/noop.mjs
1675
+ /**
1676
+ * A no-operation function that does nothing.
1677
+ * This can be used as a placeholder or default function.
1678
+ *
1679
+ * @example
1680
+ * noop(); // Does nothing
1681
+ *
1682
+ * @returns This function does not return anything.
1683
+ */
1684
+ function noop() {}
1685
+ //#endregion
1669
1686
  //#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/predicate/isPrimitive.mjs
1670
1687
  /**
1671
1688
  * Checks whether a value is a JavaScript primitive.
@@ -1770,17 +1787,28 @@ function clone(obj) {
1770
1787
  return obj;
1771
1788
  }
1772
1789
  //#endregion
1773
- //#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/function/noop.mjs
1790
+ //#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/predicate/isBuffer.mjs
1774
1791
  /**
1775
- * A no-operation function that does nothing.
1776
- * This can be used as a placeholder or default function.
1792
+ * Checks if the given value is a Buffer instance.
1793
+ *
1794
+ * This function tests whether the provided value is an instance of Buffer.
1795
+ * It returns `true` if the value is a Buffer, and `false` otherwise.
1796
+ *
1797
+ * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Buffer`.
1798
+ *
1799
+ * @param x - The value to check if it is a Buffer.
1800
+ * @returns Returns `true` if `x` is a Buffer, else `false`.
1777
1801
  *
1778
1802
  * @example
1779
- * noop(); // Does nothing
1803
+ * const buffer = Buffer.from("test");
1804
+ * console.log(isBuffer(buffer)); // true
1780
1805
  *
1781
- * @returns This function does not return anything.
1806
+ * const notBuffer = "not a buffer";
1807
+ * console.log(isBuffer(notBuffer)); // false
1782
1808
  */
1783
- function noop() {}
1809
+ function isBuffer(x) {
1810
+ return typeof globalThis_.Buffer !== "undefined" && globalThis_.Buffer.isBuffer(x);
1811
+ }
1784
1812
  //#endregion
1785
1813
  //#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/compat/_internal/getSymbols.mjs
1786
1814
  function getSymbols(object) {
@@ -1827,34 +1855,6 @@ const bigInt64ArrayTag = "[object BigInt64Array]";
1827
1855
  const float32ArrayTag = "[object Float32Array]";
1828
1856
  const float64ArrayTag = "[object Float64Array]";
1829
1857
  //#endregion
1830
- //#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/_internal/globalThis.mjs
1831
- const globalThis_ = typeof globalThis === "object" && globalThis || typeof window === "object" && window || typeof self === "object" && self || typeof global === "object" && global || (function() {
1832
- return this;
1833
- })();
1834
- //#endregion
1835
- //#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/predicate/isBuffer.mjs
1836
- /**
1837
- * Checks if the given value is a Buffer instance.
1838
- *
1839
- * This function tests whether the provided value is an instance of Buffer.
1840
- * It returns `true` if the value is a Buffer, and `false` otherwise.
1841
- *
1842
- * This function can also serve as a type predicate in TypeScript, narrowing the type of the argument to `Buffer`.
1843
- *
1844
- * @param x - The value to check if it is a Buffer.
1845
- * @returns Returns `true` if `x` is a Buffer, else `false`.
1846
- *
1847
- * @example
1848
- * const buffer = Buffer.from("test");
1849
- * console.log(isBuffer(buffer)); // true
1850
- *
1851
- * const notBuffer = "not a buffer";
1852
- * console.log(isBuffer(notBuffer)); // false
1853
- */
1854
- function isBuffer(x) {
1855
- return typeof globalThis_.Buffer !== "undefined" && globalThis_.Buffer.isBuffer(x);
1856
- }
1857
- //#endregion
1858
1858
  //#region ../../node_modules/.pnpm/es-toolkit@1.49.0/node_modules/es-toolkit/dist/predicate/isPlainObject.mjs
1859
1859
  /**
1860
1860
  * Checks if a given value is a plain object.