@pawover/kit 0.0.0-alpha.16 → 0.0.0-alpha.18
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/hooks-alova.d.ts +22 -0
- package/dist/hooks-alova.js +38 -0
- package/dist/index.d.ts +27 -4
- package/dist/index.js +49 -10
- package/metadata.json +6 -1
- package/package.json +12 -5
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as alova_client0 from "alova/client";
|
|
2
|
+
import { AlovaFrontMiddlewareContext, AlovaMethodHandler, CompleteHandler, ErrorHandler, RequestHookConfig, SuccessHandler, WatcherHookConfig } from "alova/client";
|
|
3
|
+
import { AlovaGenerics, Method } from "alova";
|
|
4
|
+
|
|
5
|
+
//#region src/hooks/alova/useAlovaRequest.d.ts
|
|
6
|
+
interface HookConfig$1<AG extends AlovaGenerics, Args extends any[]> extends RequestHookConfig<AG, Args> {
|
|
7
|
+
onBeforeRequest?: (context: AlovaFrontMiddlewareContext<AG, Args>) => void;
|
|
8
|
+
onSuccess?: SuccessHandler<AG, Args>;
|
|
9
|
+
onError?: ErrorHandler<AG, Args>;
|
|
10
|
+
onComplete?: CompleteHandler<AG, Args>;
|
|
11
|
+
}
|
|
12
|
+
declare function useAlovaRequest<AG extends AlovaGenerics, Args extends any[] = any[]>(methodHandler: Method<AG> | AlovaMethodHandler<AG, Args>, hookConfig?: HookConfig$1<AG, Args> | undefined): alova_client0.UseHookExposure<AG, Args, unknown>;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/hooks/alova/useAlovaWatcher.d.ts
|
|
15
|
+
interface HookConfig<AG extends AlovaGenerics, Args extends any[]> extends WatcherHookConfig<AG, Args> {
|
|
16
|
+
onSuccess?: SuccessHandler<AG, Args>;
|
|
17
|
+
onError?: ErrorHandler<AG, Args>;
|
|
18
|
+
onComplete?: CompleteHandler<AG, Args>;
|
|
19
|
+
}
|
|
20
|
+
declare function useAlovaWatcher<AG extends AlovaGenerics, Args extends any[] = any[]>(methodHandler: Method<AG> | AlovaMethodHandler<AG, Args>, watchingStates: AG["StatesExport"]["Watched"][], hookConfig?: HookConfig<AG, Args>): alova_client0.UseHookExposure<AG, Args, unknown>;
|
|
21
|
+
//#endregion
|
|
22
|
+
export { useAlovaRequest, useAlovaWatcher };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useRequest, useWatcher } from "alova/client";
|
|
2
|
+
|
|
3
|
+
//#region src/hooks/alova/useAlovaRequest.ts
|
|
4
|
+
function useAlovaRequest(methodHandler, hookConfig) {
|
|
5
|
+
const config = hookConfig || {};
|
|
6
|
+
config.immediate ?? (config.immediate = true);
|
|
7
|
+
if (config.onBeforeRequest) {
|
|
8
|
+
const middleware = config.middleware;
|
|
9
|
+
config.middleware = async (context, next) => {
|
|
10
|
+
config.onBeforeRequest?.(context);
|
|
11
|
+
if (middleware) {
|
|
12
|
+
async function run() {
|
|
13
|
+
await next();
|
|
14
|
+
}
|
|
15
|
+
await middleware?.(context, run);
|
|
16
|
+
} else await next();
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const exposure = useRequest(methodHandler, config);
|
|
20
|
+
if (config.onSuccess) exposure.onSuccess(config.onSuccess);
|
|
21
|
+
if (config.onError) exposure.onError(config.onError);
|
|
22
|
+
if (config.onComplete) exposure.onComplete(config.onComplete);
|
|
23
|
+
return exposure;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/hooks/alova/useAlovaWatcher.ts
|
|
28
|
+
function useAlovaWatcher(methodHandler, watchingStates, hookConfig = {}) {
|
|
29
|
+
const config = hookConfig || {};
|
|
30
|
+
const exposure = useWatcher(methodHandler, watchingStates, config);
|
|
31
|
+
if (config.onSuccess) exposure.onSuccess(config.onSuccess);
|
|
32
|
+
if (config.onError) exposure.onError(config.onError);
|
|
33
|
+
if (config.onComplete) exposure.onComplete(config.onComplete);
|
|
34
|
+
return exposure;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
38
|
+
export { useAlovaRequest, useAlovaWatcher };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,12 @@ import { Class, NonEmptyObject, Replace, SetOptional, UnionToTuple, ValueOf } fr
|
|
|
2
2
|
import { assign } from "radashi";
|
|
3
3
|
|
|
4
4
|
//#region src/utils/array/arrayCast.d.ts
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 构造数组
|
|
8
|
+
* @param candidate 待构造项
|
|
9
|
+
* @param checkEmpty 是否检查 `undefined` 和 `null`
|
|
10
|
+
*/
|
|
5
11
|
declare function arrayCast<T>(candidate: T | T[], checkEmpty?: boolean): T[];
|
|
6
12
|
//#endregion
|
|
7
13
|
//#region src/utils/array/arrayCompete.d.ts
|
|
@@ -24,8 +30,15 @@ declare function arrayCompete<T>(initialList: readonly T[], match: (a: T, b: T)
|
|
|
24
30
|
*/
|
|
25
31
|
declare function arrayCounting<T, K extends PropertyKey>(initialList: readonly T[], match: (row: T) => K): Record<string, number>;
|
|
26
32
|
//#endregion
|
|
27
|
-
//#region src/utils/array/
|
|
28
|
-
|
|
33
|
+
//#region src/utils/array/arrayDifference.d.ts
|
|
34
|
+
/**
|
|
35
|
+
* 求数组差集
|
|
36
|
+
*
|
|
37
|
+
* @param initialList 初始数组
|
|
38
|
+
* @param diffList 对比数组
|
|
39
|
+
* @param match 匹配函数
|
|
40
|
+
*/
|
|
41
|
+
declare function arrayDifference<T>(initialList: readonly T[], diffList: readonly T[], match?: (row: T) => unknown): T[];
|
|
29
42
|
//#endregion
|
|
30
43
|
//#region src/utils/array/arrayFirst.d.ts
|
|
31
44
|
/**
|
|
@@ -46,6 +59,16 @@ declare function arrayFirst<T>(initialList: readonly T[], saveValue?: T): T | un
|
|
|
46
59
|
*/
|
|
47
60
|
declare function arrayFork<T>(initialList: readonly T[], match: (item: T) => boolean): [T[], T[]];
|
|
48
61
|
//#endregion
|
|
62
|
+
//#region src/utils/array/arrayIntersection.d.ts
|
|
63
|
+
/**
|
|
64
|
+
* 求数组交集
|
|
65
|
+
*
|
|
66
|
+
* @param initialList 初始数组
|
|
67
|
+
* @param diffList 对比数组
|
|
68
|
+
* @param match 匹配函数
|
|
69
|
+
*/
|
|
70
|
+
declare function arrayIntersection<T>(initialList: readonly T[], diffList: readonly T[], match?: (row: T) => unknown): T[];
|
|
71
|
+
//#endregion
|
|
49
72
|
//#region src/utils/array/arrayLast.d.ts
|
|
50
73
|
/**
|
|
51
74
|
* 获取数组最后一项
|
|
@@ -64,7 +87,7 @@ declare function arrayLast<T>(initialList: readonly T[], saveValue?: T): T | und
|
|
|
64
87
|
* @param mergeList 待合并数组
|
|
65
88
|
* @param match 匹配函数
|
|
66
89
|
*/
|
|
67
|
-
declare function arrayMerge<T>(initialList: readonly T[], mergeList: readonly T[], match
|
|
90
|
+
declare function arrayMerge<T>(initialList: readonly T[], mergeList: readonly T[], match?: (item: T) => unknown): T[];
|
|
68
91
|
//#endregion
|
|
69
92
|
//#region src/utils/array/arrayPick.d.ts
|
|
70
93
|
/**
|
|
@@ -385,4 +408,4 @@ declare const prototypeStrings: {
|
|
|
385
408
|
};
|
|
386
409
|
declare function resolvePrototypeString(value: unknown): string;
|
|
387
410
|
//#endregion
|
|
388
|
-
export { arrayCast, arrayCompete, arrayCounting,
|
|
411
|
+
export { arrayCast, arrayCompete, arrayCounting, arrayDifference, arrayFirst, arrayFork, arrayIntersection, arrayLast, arrayMerge, arrayPick, arrayReplace, arraySplit, cloneDeep, enumEntries, enumKeys, enumTypeCheck, enumValues, isArray, isAsyncFunction, isBigInt, isBoolean, isClass, isDate, isEqual, isError, isFile, isFunction, isGeneratorFunction, isInteger, isIterable, isMap, isNull, isNumber, isObject, isPromise, isPromiseLike, isRegExp, isSet, isString, isSymbol, isURLSearchParams, isUndefined, isWeakMap, isWeakSet, isWebSocket, isWindow, mapEntries, objectAssign, objectEntries, objectKeys, objectPick, objectSwitch, objectValues, prototypeStrings, resolvePrototypeString, rowsToTree, stringInitialCase, stringReplace, stringToJson, stringToValues, to, treeFilter, treeFind, treeForEach, treeMap, treeToRows };
|
package/dist/index.js
CHANGED
|
@@ -227,6 +227,11 @@ function isWindow(value) {
|
|
|
227
227
|
|
|
228
228
|
//#endregion
|
|
229
229
|
//#region src/utils/array/arrayCast.ts
|
|
230
|
+
/**
|
|
231
|
+
* 构造数组
|
|
232
|
+
* @param candidate 待构造项
|
|
233
|
+
* @param checkEmpty 是否检查 `undefined` 和 `null`
|
|
234
|
+
*/
|
|
230
235
|
function arrayCast(candidate, checkEmpty = true) {
|
|
231
236
|
if (checkEmpty && (isUndefined(candidate) || isNull(candidate))) return [];
|
|
232
237
|
return isArray(candidate) ? [...candidate] : [candidate];
|
|
@@ -265,17 +270,27 @@ function arrayCounting(initialList, match) {
|
|
|
265
270
|
}
|
|
266
271
|
|
|
267
272
|
//#endregion
|
|
268
|
-
//#region src/utils/array/
|
|
269
|
-
|
|
273
|
+
//#region src/utils/array/arrayDifference.ts
|
|
274
|
+
/**
|
|
275
|
+
* 求数组差集
|
|
276
|
+
*
|
|
277
|
+
* @param initialList 初始数组
|
|
278
|
+
* @param diffList 对比数组
|
|
279
|
+
* @param match 匹配函数
|
|
280
|
+
*/
|
|
281
|
+
function arrayDifference(initialList, diffList, match) {
|
|
270
282
|
if (!isArray(initialList) && !isArray(diffList)) return [];
|
|
271
283
|
if (!isArray(initialList) || !initialList.length) return [...diffList];
|
|
272
284
|
if (!isArray(diffList) || !diffList.length) return [...initialList];
|
|
273
|
-
if (!isFunction(match))
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
285
|
+
if (!isFunction(match)) {
|
|
286
|
+
const arraySet = new Set(diffList);
|
|
287
|
+
return Array.from(new Set(initialList.filter((item) => !arraySet.has(item))));
|
|
288
|
+
}
|
|
289
|
+
const map = /* @__PURE__ */ new Map();
|
|
290
|
+
diffList.forEach((item) => {
|
|
291
|
+
map.set(match(item), true);
|
|
292
|
+
});
|
|
293
|
+
return initialList.filter((a) => !map.get(match(a)));
|
|
279
294
|
}
|
|
280
295
|
|
|
281
296
|
//#endregion
|
|
@@ -306,6 +321,30 @@ function arrayFork(initialList, match) {
|
|
|
306
321
|
return forked;
|
|
307
322
|
}
|
|
308
323
|
|
|
324
|
+
//#endregion
|
|
325
|
+
//#region src/utils/array/arrayIntersection.ts
|
|
326
|
+
/**
|
|
327
|
+
* 求数组交集
|
|
328
|
+
*
|
|
329
|
+
* @param initialList 初始数组
|
|
330
|
+
* @param diffList 对比数组
|
|
331
|
+
* @param match 匹配函数
|
|
332
|
+
*/
|
|
333
|
+
function arrayIntersection(initialList, diffList, match) {
|
|
334
|
+
if (!isArray(initialList) && !isArray(diffList)) return [];
|
|
335
|
+
if (!isArray(initialList) || !initialList.length) return [...diffList];
|
|
336
|
+
if (!isArray(diffList) || !diffList.length) return [...initialList];
|
|
337
|
+
if (!isFunction(match)) {
|
|
338
|
+
const arraySet = new Set(diffList);
|
|
339
|
+
return Array.from(new Set(initialList.filter((item) => arraySet.has(item))));
|
|
340
|
+
}
|
|
341
|
+
const map = /* @__PURE__ */ new Map();
|
|
342
|
+
diffList.forEach((item) => {
|
|
343
|
+
map.set(match(item), true);
|
|
344
|
+
});
|
|
345
|
+
return initialList.filter((a) => map.get(match(a)));
|
|
346
|
+
}
|
|
347
|
+
|
|
309
348
|
//#endregion
|
|
310
349
|
//#region src/utils/array/arrayLast.ts
|
|
311
350
|
/**
|
|
@@ -332,7 +371,7 @@ function arrayLast(initialList, saveValue) {
|
|
|
332
371
|
function arrayMerge(initialList, mergeList, match) {
|
|
333
372
|
if (!isArray(initialList)) return [];
|
|
334
373
|
if (!isArray(mergeList)) return [...initialList];
|
|
335
|
-
if (!isFunction(match)) return [...initialList];
|
|
374
|
+
if (!isFunction(match)) return Array.from(new Set([...initialList, ...mergeList]));
|
|
336
375
|
const keys = /* @__PURE__ */ new Map();
|
|
337
376
|
for (const item of mergeList) keys.set(match(item), item);
|
|
338
377
|
return initialList.map((prevItem) => {
|
|
@@ -1133,4 +1172,4 @@ function treeToRows(tree, options = {}) {
|
|
|
1133
1172
|
}
|
|
1134
1173
|
|
|
1135
1174
|
//#endregion
|
|
1136
|
-
export { arrayCast, arrayCompete, arrayCounting,
|
|
1175
|
+
export { arrayCast, arrayCompete, arrayCounting, arrayDifference, arrayFirst, arrayFork, arrayIntersection, arrayLast, arrayMerge, arrayPick, arrayReplace, arraySplit, cloneDeep, enumEntries, enumKeys, enumTypeCheck, enumValues, isArray, isAsyncFunction, isBigInt, isBoolean, isClass, isDate, isEqual, isError, isFile, isFunction, isGeneratorFunction, isInteger, isIterable, isMap, isNull, isNumber, isObject, isPromise, isPromiseLike, isRegExp, isSet, isString, isSymbol, isURLSearchParams, isUndefined, isWeakMap, isWeakSet, isWebSocket, isWindow, mapEntries, objectAssign, objectEntries, objectKeys, objectPick, objectSwitch, objectValues, prototypeStrings, resolvePrototypeString, rowsToTree, stringInitialCase, stringReplace, stringToJson, stringToValues, to, treeFilter, treeFind, treeForEach, treeMap, treeToRows };
|
package/metadata.json
CHANGED
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
"arrayCast",
|
|
4
4
|
"arrayCompete",
|
|
5
5
|
"arrayCounting",
|
|
6
|
-
"
|
|
6
|
+
"arrayDifference",
|
|
7
7
|
"arrayFirst",
|
|
8
8
|
"arrayFork",
|
|
9
|
+
"arrayIntersection",
|
|
9
10
|
"arrayLast",
|
|
10
11
|
"arrayMerge",
|
|
11
12
|
"arrayPick",
|
|
@@ -122,6 +123,10 @@
|
|
|
122
123
|
"BREAK_POINT_TOKENS"
|
|
123
124
|
],
|
|
124
125
|
"hooks": {
|
|
126
|
+
"alova": [
|
|
127
|
+
"useAlovaRequest",
|
|
128
|
+
"useAlovaWatcher"
|
|
129
|
+
],
|
|
125
130
|
"react": [
|
|
126
131
|
"useCreation",
|
|
127
132
|
"useLatest",
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"description": "pawover's kit",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"version": "0.0.0-alpha.
|
|
7
|
+
"version": "0.0.0-alpha.18",
|
|
8
8
|
"packageManager": "pnpm@10.20.0",
|
|
9
9
|
"engines": {
|
|
10
10
|
"node": ">=22.20.0"
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
".": "./dist/index.js",
|
|
30
30
|
"./enums": "./dist/enums.js",
|
|
31
31
|
"./zod": "./dist/zod.js",
|
|
32
|
+
"./hooks-alova": "./dist/hooks-alova.js",
|
|
32
33
|
"./hooks-react": "./dist/hooks-react.js",
|
|
33
34
|
"./metadata.json": "./metadata.json",
|
|
34
35
|
"./package.json": "./package.json"
|
|
@@ -48,6 +49,11 @@
|
|
|
48
49
|
"clean:output": "rimraf dist",
|
|
49
50
|
"lib:up": "taze -I -r --exclude pnpm"
|
|
50
51
|
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"alova": "^3.3.4",
|
|
54
|
+
"vue": "^3.5.24",
|
|
55
|
+
"zod": "^4.1.12"
|
|
56
|
+
},
|
|
51
57
|
"devDependencies": {
|
|
52
58
|
"@pawover/eslint-rules": "0.0.0-alpha.8",
|
|
53
59
|
"@pawover/types": "0.0.0-alpha.6",
|
|
@@ -61,22 +67,23 @@
|
|
|
61
67
|
"globals": "^16.5.0",
|
|
62
68
|
"prettier": "^3.6.2",
|
|
63
69
|
"radashi": "^12.7.0",
|
|
64
|
-
"react": "^19.2.0",
|
|
65
70
|
"rimraf": "^6.1.0",
|
|
66
71
|
"taze": "^19.9.0",
|
|
67
72
|
"tsdown": "^0.16.5",
|
|
68
73
|
"type-fest": "^5.2.0",
|
|
69
74
|
"typescript": "^5.9.3",
|
|
70
|
-
"typescript-eslint": "^8.46.4"
|
|
71
|
-
"vue": "^3.5.24",
|
|
72
|
-
"zod": "^4.1.12"
|
|
75
|
+
"typescript-eslint": "^8.46.4"
|
|
73
76
|
},
|
|
74
77
|
"peerDependencies": {
|
|
78
|
+
"alova": ">=3.3.4",
|
|
75
79
|
"react": ">=19.2.0",
|
|
76
80
|
"vue": ">=3.5.24",
|
|
77
81
|
"zod": ">=4.1.12"
|
|
78
82
|
},
|
|
79
83
|
"peerDependenciesMeta": {
|
|
84
|
+
"alova": {
|
|
85
|
+
"optional": true
|
|
86
|
+
},
|
|
80
87
|
"react": {
|
|
81
88
|
"optional": true
|
|
82
89
|
},
|