@flowlist/js-core 4.0.0-beta.0 → 4.0.1-beta.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/dist/index.d.mts +95 -37
- package/dist/index.d.ts +95 -37
- package/dist/index.global.js +243 -245
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +243 -245
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +243 -246
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -59,10 +59,21 @@ type FieldSetter = (_obj: SetterFuncParams) => void;
|
|
|
59
59
|
* 数据获取类型枚举
|
|
60
60
|
*/
|
|
61
61
|
type FetchType = 'jump' | 'sinceId' | 'page' | 'seenIds' | 'auto';
|
|
62
|
+
/**
|
|
63
|
+
* 请求参数的基础约束
|
|
64
|
+
*/
|
|
65
|
+
interface RequestParams extends KeyMap {
|
|
66
|
+
__refresh__?: boolean;
|
|
67
|
+
__reload__?: boolean;
|
|
68
|
+
is_up?: 0 | 1 | boolean;
|
|
69
|
+
page?: number;
|
|
70
|
+
sinceId?: ObjectKey;
|
|
71
|
+
}
|
|
62
72
|
/**
|
|
63
73
|
* 生成请求参数的输出
|
|
74
|
+
* 继承自 RequestParams 以确保与 ApiContract 参数兼容
|
|
64
75
|
*/
|
|
65
|
-
interface GenerateParamsResp extends
|
|
76
|
+
interface GenerateParamsResp extends RequestParams {
|
|
66
77
|
seen_ids?: string;
|
|
67
78
|
since_id?: ObjectKey;
|
|
68
79
|
is_up?: 0 | 1;
|
|
@@ -80,8 +91,8 @@ interface GenerateParamsType {
|
|
|
80
91
|
/**
|
|
81
92
|
* API 响应结构
|
|
82
93
|
*/
|
|
83
|
-
interface ApiResponse {
|
|
84
|
-
readonly result:
|
|
94
|
+
interface ApiResponse<R = ResultType> {
|
|
95
|
+
readonly result: R;
|
|
85
96
|
readonly extra?: KeyMap;
|
|
86
97
|
readonly total?: number;
|
|
87
98
|
readonly no_more?: boolean;
|
|
@@ -89,81 +100,78 @@ interface ApiResponse {
|
|
|
89
100
|
/**
|
|
90
101
|
* 获取数据后的回调函数
|
|
91
102
|
*/
|
|
92
|
-
type FetchResultCallback = (_obj: {
|
|
93
|
-
params:
|
|
94
|
-
data: ApiResponse
|
|
103
|
+
type FetchResultCallback<P, R> = (_obj: {
|
|
104
|
+
params: P;
|
|
105
|
+
data: ApiResponse<R>;
|
|
95
106
|
refresh: boolean;
|
|
96
107
|
}) => void;
|
|
97
|
-
interface CommonParams {
|
|
98
|
-
readonly func:
|
|
99
|
-
readonly type
|
|
100
|
-
readonly query?:
|
|
108
|
+
interface CommonParams<P extends RequestParams = RequestParams, R extends ResultType = ResultType> {
|
|
109
|
+
readonly func: ApiContract<P, R>;
|
|
110
|
+
readonly type?: FetchType;
|
|
111
|
+
readonly query?: P;
|
|
101
112
|
readonly uniqueKey?: string;
|
|
102
|
-
readonly callback?: FetchResultCallback
|
|
113
|
+
readonly callback?: FetchResultCallback<P, R>;
|
|
103
114
|
}
|
|
104
|
-
interface BaseFetchConfig extends CommonParams {
|
|
115
|
+
interface BaseFetchConfig<P extends RequestParams = RequestParams, R extends ResultType = ResultType> extends CommonParams<P, R> {
|
|
105
116
|
readonly getter: FieldGetter;
|
|
106
117
|
readonly setter: FieldSetter;
|
|
107
|
-
readonly api?: Record<string, ApiFunction>;
|
|
108
118
|
}
|
|
109
119
|
/**
|
|
110
120
|
* 初始化状态的参数对外接口
|
|
111
121
|
*/
|
|
112
|
-
interface InitStateParams {
|
|
113
|
-
readonly func:
|
|
122
|
+
interface InitStateParams<P extends RequestParams = RequestParams, R extends ResultType = ResultType> {
|
|
123
|
+
readonly func: ApiContract<P, R>;
|
|
114
124
|
readonly type: FetchType;
|
|
115
|
-
readonly query?:
|
|
125
|
+
readonly query?: P;
|
|
116
126
|
readonly opts?: Partial<DefaultField>;
|
|
117
127
|
}
|
|
118
128
|
/**
|
|
119
129
|
* 初始化状态的参数(内部)
|
|
120
130
|
*/
|
|
121
|
-
interface InitStateType extends InitStateParams {
|
|
131
|
+
interface InitStateType<P extends RequestParams = RequestParams, R extends ResultType = ResultType> extends InitStateParams<P, R> {
|
|
122
132
|
readonly getter: FieldGetter;
|
|
123
133
|
readonly setter: FieldSetter;
|
|
124
134
|
}
|
|
125
135
|
/**
|
|
126
136
|
* 初始化数据的参数对外接口
|
|
127
137
|
*/
|
|
128
|
-
type InitDataParams = CommonParams
|
|
138
|
+
type InitDataParams<P extends RequestParams = RequestParams, R extends ResultType = ResultType> = CommonParams<P, R>;
|
|
129
139
|
/**
|
|
130
140
|
* 初始化数据的参数(内部)
|
|
131
141
|
*/
|
|
132
|
-
type InitDataType = BaseFetchConfig
|
|
142
|
+
type InitDataType<P extends RequestParams = RequestParams, R extends ResultType = ResultType> = BaseFetchConfig<P, R>;
|
|
133
143
|
/**
|
|
134
144
|
* 加载更多的参数对外接口
|
|
135
145
|
*/
|
|
136
|
-
interface LoadMoreParams extends CommonParams {
|
|
146
|
+
interface LoadMoreParams<P extends RequestParams = RequestParams, R extends ResultType = ResultType> extends CommonParams<P, R> {
|
|
137
147
|
readonly errorRetry?: boolean;
|
|
138
148
|
}
|
|
139
149
|
/**
|
|
140
150
|
* 加载更多的参数(内部)
|
|
141
151
|
*/
|
|
142
|
-
interface LoadMoreType extends BaseFetchConfig {
|
|
152
|
+
interface LoadMoreType<P extends RequestParams = RequestParams, R extends ResultType = ResultType> extends BaseFetchConfig<P, R> {
|
|
143
153
|
readonly errorRetry?: boolean;
|
|
144
154
|
}
|
|
145
155
|
/**
|
|
146
156
|
* 更新状态的参数(内部使用)
|
|
147
157
|
*/
|
|
148
|
-
interface UpdateStateType<T = KeyMap> {
|
|
158
|
+
interface UpdateStateType<P extends RequestParams = RequestParams, R extends ResultType = ResultType, T extends KeyMap = KeyMap> {
|
|
149
159
|
readonly getter: FieldGetter;
|
|
150
160
|
readonly setter: FieldSetter;
|
|
151
|
-
readonly func:
|
|
152
|
-
readonly
|
|
153
|
-
readonly query?: KeyMap;
|
|
161
|
+
readonly func: ApiContract<P, R>;
|
|
162
|
+
readonly query?: P;
|
|
154
163
|
readonly method: string;
|
|
155
|
-
readonly value: T
|
|
164
|
+
readonly value: T;
|
|
156
165
|
readonly id?: ObjectKey | ObjectKey[];
|
|
157
166
|
readonly changeKey?: string;
|
|
158
|
-
readonly uniqueKey?: string;
|
|
159
167
|
}
|
|
160
168
|
/**
|
|
161
169
|
* 更新状态的参数(对外接口)
|
|
162
170
|
*/
|
|
163
|
-
interface UpdateStateParams<T = KeyMap> {
|
|
164
|
-
readonly func:
|
|
171
|
+
interface UpdateStateParams<P extends RequestParams = RequestParams, R extends ResultType = ResultType, T extends KeyMap = KeyMap> {
|
|
172
|
+
readonly func: ApiContract<P, R>;
|
|
165
173
|
readonly type: FetchType;
|
|
166
|
-
readonly query?:
|
|
174
|
+
readonly query?: P;
|
|
167
175
|
readonly method: string;
|
|
168
176
|
readonly value: T | ResultArrayType | ResultObjectType | KeyMap;
|
|
169
177
|
readonly id?: ObjectKey | ObjectKey[];
|
|
@@ -190,16 +198,60 @@ interface SetErrorType {
|
|
|
190
198
|
readonly fieldName: string;
|
|
191
199
|
readonly error: Error | null;
|
|
192
200
|
}
|
|
201
|
+
interface ApiContract<P extends RequestParams = RequestParams, R extends ResultType = ResultType> {
|
|
202
|
+
(params: P): Promise<ApiResponse<R>>;
|
|
203
|
+
readonly id: string;
|
|
204
|
+
readonly type: FetchType;
|
|
205
|
+
readonly uniqueKey: string;
|
|
206
|
+
readonly paramsIgnore: string[];
|
|
207
|
+
}
|
|
208
|
+
declare function createApi<P extends RequestParams, R extends ResultType>(options: {
|
|
209
|
+
id: string;
|
|
210
|
+
type?: FetchType;
|
|
211
|
+
uniqueKey?: string;
|
|
212
|
+
paramsIgnore?: string[];
|
|
213
|
+
fetcher: (params: P) => Promise<ApiResponse<R>>;
|
|
214
|
+
}): ApiContract<P, R>;
|
|
193
215
|
|
|
194
|
-
declare const initState: ({ getter, setter, func,
|
|
195
|
-
declare const initData: ({ getter, setter, func,
|
|
196
|
-
|
|
197
|
-
|
|
216
|
+
declare const initState: <P extends RequestParams = RequestParams, R extends ResultType = ResultType>({ getter, setter, func, query, opts }: InitStateType<P, R>) => Promise<void>;
|
|
217
|
+
declare const initData: <P extends RequestParams = RequestParams, R extends ResultType = ResultType>({ getter, setter, func, query, callback }: InitDataType<P, R>) => Promise<void>;
|
|
218
|
+
/**
|
|
219
|
+
* 加载更多数据
|
|
220
|
+
*/
|
|
221
|
+
declare const loadMore: <P extends RequestParams = RequestParams, R extends ResultType = ResultType>({ getter, setter, query, func, errorRetry, callback }: LoadMoreType<P, R>) => Promise<void>;
|
|
222
|
+
declare const updateState: <P extends RequestParams = RequestParams, R extends ResultType = ResultType, T extends KeyMap = KeyMap>({ getter, setter, func, query, method, value, id, changeKey }: UpdateStateType<P, R, T>) => Promise<unknown>;
|
|
198
223
|
|
|
199
224
|
declare const isArray: (data: unknown) => data is unknown[];
|
|
225
|
+
/**
|
|
226
|
+
* 检查是否为数组
|
|
227
|
+
*/
|
|
228
|
+
declare const isResultArray: (data: ResultType) => data is ResultArrayType;
|
|
229
|
+
/**
|
|
230
|
+
* 检查是否为对象结果
|
|
231
|
+
*/
|
|
232
|
+
declare const isResultObject: (data: ResultType) => data is ResultObjectType;
|
|
233
|
+
/**
|
|
234
|
+
* 检查是否为 ObjectKey
|
|
235
|
+
*/
|
|
236
|
+
declare const isObjectKey: (value: unknown) => value is ObjectKey;
|
|
237
|
+
/**
|
|
238
|
+
* 检查是否为 KeyMap
|
|
239
|
+
*/
|
|
240
|
+
declare const isKeyMap: (value: unknown) => value is KeyMap;
|
|
241
|
+
/**
|
|
242
|
+
* 检查是否为 KeyMap 数组
|
|
243
|
+
*/
|
|
244
|
+
declare const isKeyMapArray: (value: unknown) => value is KeyMap[];
|
|
245
|
+
/**
|
|
246
|
+
* 检查是否为 ObjectKey 数组
|
|
247
|
+
*/
|
|
248
|
+
declare const isObjectKeyArray: (value: unknown) => value is ObjectKey[];
|
|
200
249
|
declare const isObjectResult: (data: unknown) => data is Record<string, unknown>;
|
|
201
250
|
declare const generateDefaultField: (opts?: Partial<DefaultField>) => DefaultField;
|
|
202
|
-
declare const generateFieldName: ({ func,
|
|
251
|
+
declare const generateFieldName: <P extends RequestParams = RequestParams, R extends ResultType = ResultType>({ func, query }: {
|
|
252
|
+
func: ApiContract<P, R>;
|
|
253
|
+
query?: P;
|
|
254
|
+
}) => string;
|
|
203
255
|
declare const getObjectDeepValue: (field: unknown, keys: string | string[]) => unknown;
|
|
204
256
|
declare const updateObjectDeepValue: (field: KeyMap, changeKey: string, value: unknown) => void;
|
|
205
257
|
declare const searchValueByKey: (result: ResultArrayType | ResultObjectType, id: ObjectKey, key: string) => unknown;
|
|
@@ -217,12 +269,18 @@ declare const utils_generateFieldName: typeof generateFieldName;
|
|
|
217
269
|
declare const utils_generateRequestParams: typeof generateRequestParams;
|
|
218
270
|
declare const utils_getObjectDeepValue: typeof getObjectDeepValue;
|
|
219
271
|
declare const utils_isArray: typeof isArray;
|
|
272
|
+
declare const utils_isKeyMap: typeof isKeyMap;
|
|
273
|
+
declare const utils_isKeyMapArray: typeof isKeyMapArray;
|
|
274
|
+
declare const utils_isObjectKey: typeof isObjectKey;
|
|
275
|
+
declare const utils_isObjectKeyArray: typeof isObjectKeyArray;
|
|
220
276
|
declare const utils_isObjectResult: typeof isObjectResult;
|
|
277
|
+
declare const utils_isResultArray: typeof isResultArray;
|
|
278
|
+
declare const utils_isResultObject: typeof isResultObject;
|
|
221
279
|
declare const utils_searchValueByKey: typeof searchValueByKey;
|
|
222
280
|
declare const utils_setReactivityField: typeof setReactivityField;
|
|
223
281
|
declare const utils_updateObjectDeepValue: typeof updateObjectDeepValue;
|
|
224
282
|
declare namespace utils {
|
|
225
|
-
export { utils_combineArrayData as combineArrayData, utils_computeMatchedItemIndex as computeMatchedItemIndex, utils_computeResultLength as computeResultLength, utils_generateDefaultField as generateDefaultField, utils_generateFieldName as generateFieldName, utils_generateRequestParams as generateRequestParams, utils_getObjectDeepValue as getObjectDeepValue, utils_isArray as isArray, utils_isObjectResult as isObjectResult, utils_searchValueByKey as searchValueByKey, utils_setReactivityField as setReactivityField, utils_updateObjectDeepValue as updateObjectDeepValue };
|
|
283
|
+
export { utils_combineArrayData as combineArrayData, utils_computeMatchedItemIndex as computeMatchedItemIndex, utils_computeResultLength as computeResultLength, utils_generateDefaultField as generateDefaultField, utils_generateFieldName as generateFieldName, utils_generateRequestParams as generateRequestParams, utils_getObjectDeepValue as getObjectDeepValue, utils_isArray as isArray, utils_isKeyMap as isKeyMap, utils_isKeyMapArray as isKeyMapArray, utils_isObjectKey as isObjectKey, utils_isObjectKeyArray as isObjectKeyArray, utils_isObjectResult as isObjectResult, utils_isResultArray as isResultArray, utils_isResultObject as isResultObject, utils_searchValueByKey as searchValueByKey, utils_setReactivityField as setReactivityField, utils_updateObjectDeepValue as updateObjectDeepValue };
|
|
226
284
|
}
|
|
227
285
|
|
|
228
286
|
declare const _default: {
|
|
@@ -257,4 +315,4 @@ declare const _default: {
|
|
|
257
315
|
readonly DEFAULT_UNIQUE_KEY_NAME: "id";
|
|
258
316
|
};
|
|
259
317
|
|
|
260
|
-
export { type ApiFunction, type ApiResponse, type DataSource, type DefaultField, _default as ENUM, type FetchResultCallback, type FetchType, type FieldGetter, type FieldKeys, type FieldSetter, type GenerateParamsResp, type GenerateParamsType, type InitDataParams, type InitDataType, type InitStateParams, type InitStateType, type KeyMap, type LoadMoreParams, type LoadMoreType, type ObjectKey, type ResultArrayType, type ResultObjectType, type ResultType, type SetDataType, type SetErrorType, type SetterFuncParams, type UpdateStateParams, type UpdateStateType, initData, initState, loadMore, updateState, utils };
|
|
318
|
+
export { type ApiContract, type ApiFunction, type ApiResponse, type DataSource, type DefaultField, _default as ENUM, type FetchResultCallback, type FetchType, type FieldGetter, type FieldKeys, type FieldSetter, type GenerateParamsResp, type GenerateParamsType, type InitDataParams, type InitDataType, type InitStateParams, type InitStateType, type KeyMap, type LoadMoreParams, type LoadMoreType, type ObjectKey, type RequestParams, type ResultArrayType, type ResultObjectType, type ResultType, type SetDataType, type SetErrorType, type SetterFuncParams, type UpdateStateParams, type UpdateStateType, createApi, initData, initState, loadMore, updateState, utils };
|
package/dist/index.d.ts
CHANGED
|
@@ -59,10 +59,21 @@ type FieldSetter = (_obj: SetterFuncParams) => void;
|
|
|
59
59
|
* 数据获取类型枚举
|
|
60
60
|
*/
|
|
61
61
|
type FetchType = 'jump' | 'sinceId' | 'page' | 'seenIds' | 'auto';
|
|
62
|
+
/**
|
|
63
|
+
* 请求参数的基础约束
|
|
64
|
+
*/
|
|
65
|
+
interface RequestParams extends KeyMap {
|
|
66
|
+
__refresh__?: boolean;
|
|
67
|
+
__reload__?: boolean;
|
|
68
|
+
is_up?: 0 | 1 | boolean;
|
|
69
|
+
page?: number;
|
|
70
|
+
sinceId?: ObjectKey;
|
|
71
|
+
}
|
|
62
72
|
/**
|
|
63
73
|
* 生成请求参数的输出
|
|
74
|
+
* 继承自 RequestParams 以确保与 ApiContract 参数兼容
|
|
64
75
|
*/
|
|
65
|
-
interface GenerateParamsResp extends
|
|
76
|
+
interface GenerateParamsResp extends RequestParams {
|
|
66
77
|
seen_ids?: string;
|
|
67
78
|
since_id?: ObjectKey;
|
|
68
79
|
is_up?: 0 | 1;
|
|
@@ -80,8 +91,8 @@ interface GenerateParamsType {
|
|
|
80
91
|
/**
|
|
81
92
|
* API 响应结构
|
|
82
93
|
*/
|
|
83
|
-
interface ApiResponse {
|
|
84
|
-
readonly result:
|
|
94
|
+
interface ApiResponse<R = ResultType> {
|
|
95
|
+
readonly result: R;
|
|
85
96
|
readonly extra?: KeyMap;
|
|
86
97
|
readonly total?: number;
|
|
87
98
|
readonly no_more?: boolean;
|
|
@@ -89,81 +100,78 @@ interface ApiResponse {
|
|
|
89
100
|
/**
|
|
90
101
|
* 获取数据后的回调函数
|
|
91
102
|
*/
|
|
92
|
-
type FetchResultCallback = (_obj: {
|
|
93
|
-
params:
|
|
94
|
-
data: ApiResponse
|
|
103
|
+
type FetchResultCallback<P, R> = (_obj: {
|
|
104
|
+
params: P;
|
|
105
|
+
data: ApiResponse<R>;
|
|
95
106
|
refresh: boolean;
|
|
96
107
|
}) => void;
|
|
97
|
-
interface CommonParams {
|
|
98
|
-
readonly func:
|
|
99
|
-
readonly type
|
|
100
|
-
readonly query?:
|
|
108
|
+
interface CommonParams<P extends RequestParams = RequestParams, R extends ResultType = ResultType> {
|
|
109
|
+
readonly func: ApiContract<P, R>;
|
|
110
|
+
readonly type?: FetchType;
|
|
111
|
+
readonly query?: P;
|
|
101
112
|
readonly uniqueKey?: string;
|
|
102
|
-
readonly callback?: FetchResultCallback
|
|
113
|
+
readonly callback?: FetchResultCallback<P, R>;
|
|
103
114
|
}
|
|
104
|
-
interface BaseFetchConfig extends CommonParams {
|
|
115
|
+
interface BaseFetchConfig<P extends RequestParams = RequestParams, R extends ResultType = ResultType> extends CommonParams<P, R> {
|
|
105
116
|
readonly getter: FieldGetter;
|
|
106
117
|
readonly setter: FieldSetter;
|
|
107
|
-
readonly api?: Record<string, ApiFunction>;
|
|
108
118
|
}
|
|
109
119
|
/**
|
|
110
120
|
* 初始化状态的参数对外接口
|
|
111
121
|
*/
|
|
112
|
-
interface InitStateParams {
|
|
113
|
-
readonly func:
|
|
122
|
+
interface InitStateParams<P extends RequestParams = RequestParams, R extends ResultType = ResultType> {
|
|
123
|
+
readonly func: ApiContract<P, R>;
|
|
114
124
|
readonly type: FetchType;
|
|
115
|
-
readonly query?:
|
|
125
|
+
readonly query?: P;
|
|
116
126
|
readonly opts?: Partial<DefaultField>;
|
|
117
127
|
}
|
|
118
128
|
/**
|
|
119
129
|
* 初始化状态的参数(内部)
|
|
120
130
|
*/
|
|
121
|
-
interface InitStateType extends InitStateParams {
|
|
131
|
+
interface InitStateType<P extends RequestParams = RequestParams, R extends ResultType = ResultType> extends InitStateParams<P, R> {
|
|
122
132
|
readonly getter: FieldGetter;
|
|
123
133
|
readonly setter: FieldSetter;
|
|
124
134
|
}
|
|
125
135
|
/**
|
|
126
136
|
* 初始化数据的参数对外接口
|
|
127
137
|
*/
|
|
128
|
-
type InitDataParams = CommonParams
|
|
138
|
+
type InitDataParams<P extends RequestParams = RequestParams, R extends ResultType = ResultType> = CommonParams<P, R>;
|
|
129
139
|
/**
|
|
130
140
|
* 初始化数据的参数(内部)
|
|
131
141
|
*/
|
|
132
|
-
type InitDataType = BaseFetchConfig
|
|
142
|
+
type InitDataType<P extends RequestParams = RequestParams, R extends ResultType = ResultType> = BaseFetchConfig<P, R>;
|
|
133
143
|
/**
|
|
134
144
|
* 加载更多的参数对外接口
|
|
135
145
|
*/
|
|
136
|
-
interface LoadMoreParams extends CommonParams {
|
|
146
|
+
interface LoadMoreParams<P extends RequestParams = RequestParams, R extends ResultType = ResultType> extends CommonParams<P, R> {
|
|
137
147
|
readonly errorRetry?: boolean;
|
|
138
148
|
}
|
|
139
149
|
/**
|
|
140
150
|
* 加载更多的参数(内部)
|
|
141
151
|
*/
|
|
142
|
-
interface LoadMoreType extends BaseFetchConfig {
|
|
152
|
+
interface LoadMoreType<P extends RequestParams = RequestParams, R extends ResultType = ResultType> extends BaseFetchConfig<P, R> {
|
|
143
153
|
readonly errorRetry?: boolean;
|
|
144
154
|
}
|
|
145
155
|
/**
|
|
146
156
|
* 更新状态的参数(内部使用)
|
|
147
157
|
*/
|
|
148
|
-
interface UpdateStateType<T = KeyMap> {
|
|
158
|
+
interface UpdateStateType<P extends RequestParams = RequestParams, R extends ResultType = ResultType, T extends KeyMap = KeyMap> {
|
|
149
159
|
readonly getter: FieldGetter;
|
|
150
160
|
readonly setter: FieldSetter;
|
|
151
|
-
readonly func:
|
|
152
|
-
readonly
|
|
153
|
-
readonly query?: KeyMap;
|
|
161
|
+
readonly func: ApiContract<P, R>;
|
|
162
|
+
readonly query?: P;
|
|
154
163
|
readonly method: string;
|
|
155
|
-
readonly value: T
|
|
164
|
+
readonly value: T;
|
|
156
165
|
readonly id?: ObjectKey | ObjectKey[];
|
|
157
166
|
readonly changeKey?: string;
|
|
158
|
-
readonly uniqueKey?: string;
|
|
159
167
|
}
|
|
160
168
|
/**
|
|
161
169
|
* 更新状态的参数(对外接口)
|
|
162
170
|
*/
|
|
163
|
-
interface UpdateStateParams<T = KeyMap> {
|
|
164
|
-
readonly func:
|
|
171
|
+
interface UpdateStateParams<P extends RequestParams = RequestParams, R extends ResultType = ResultType, T extends KeyMap = KeyMap> {
|
|
172
|
+
readonly func: ApiContract<P, R>;
|
|
165
173
|
readonly type: FetchType;
|
|
166
|
-
readonly query?:
|
|
174
|
+
readonly query?: P;
|
|
167
175
|
readonly method: string;
|
|
168
176
|
readonly value: T | ResultArrayType | ResultObjectType | KeyMap;
|
|
169
177
|
readonly id?: ObjectKey | ObjectKey[];
|
|
@@ -190,16 +198,60 @@ interface SetErrorType {
|
|
|
190
198
|
readonly fieldName: string;
|
|
191
199
|
readonly error: Error | null;
|
|
192
200
|
}
|
|
201
|
+
interface ApiContract<P extends RequestParams = RequestParams, R extends ResultType = ResultType> {
|
|
202
|
+
(params: P): Promise<ApiResponse<R>>;
|
|
203
|
+
readonly id: string;
|
|
204
|
+
readonly type: FetchType;
|
|
205
|
+
readonly uniqueKey: string;
|
|
206
|
+
readonly paramsIgnore: string[];
|
|
207
|
+
}
|
|
208
|
+
declare function createApi<P extends RequestParams, R extends ResultType>(options: {
|
|
209
|
+
id: string;
|
|
210
|
+
type?: FetchType;
|
|
211
|
+
uniqueKey?: string;
|
|
212
|
+
paramsIgnore?: string[];
|
|
213
|
+
fetcher: (params: P) => Promise<ApiResponse<R>>;
|
|
214
|
+
}): ApiContract<P, R>;
|
|
193
215
|
|
|
194
|
-
declare const initState: ({ getter, setter, func,
|
|
195
|
-
declare const initData: ({ getter, setter, func,
|
|
196
|
-
|
|
197
|
-
|
|
216
|
+
declare const initState: <P extends RequestParams = RequestParams, R extends ResultType = ResultType>({ getter, setter, func, query, opts }: InitStateType<P, R>) => Promise<void>;
|
|
217
|
+
declare const initData: <P extends RequestParams = RequestParams, R extends ResultType = ResultType>({ getter, setter, func, query, callback }: InitDataType<P, R>) => Promise<void>;
|
|
218
|
+
/**
|
|
219
|
+
* 加载更多数据
|
|
220
|
+
*/
|
|
221
|
+
declare const loadMore: <P extends RequestParams = RequestParams, R extends ResultType = ResultType>({ getter, setter, query, func, errorRetry, callback }: LoadMoreType<P, R>) => Promise<void>;
|
|
222
|
+
declare const updateState: <P extends RequestParams = RequestParams, R extends ResultType = ResultType, T extends KeyMap = KeyMap>({ getter, setter, func, query, method, value, id, changeKey }: UpdateStateType<P, R, T>) => Promise<unknown>;
|
|
198
223
|
|
|
199
224
|
declare const isArray: (data: unknown) => data is unknown[];
|
|
225
|
+
/**
|
|
226
|
+
* 检查是否为数组
|
|
227
|
+
*/
|
|
228
|
+
declare const isResultArray: (data: ResultType) => data is ResultArrayType;
|
|
229
|
+
/**
|
|
230
|
+
* 检查是否为对象结果
|
|
231
|
+
*/
|
|
232
|
+
declare const isResultObject: (data: ResultType) => data is ResultObjectType;
|
|
233
|
+
/**
|
|
234
|
+
* 检查是否为 ObjectKey
|
|
235
|
+
*/
|
|
236
|
+
declare const isObjectKey: (value: unknown) => value is ObjectKey;
|
|
237
|
+
/**
|
|
238
|
+
* 检查是否为 KeyMap
|
|
239
|
+
*/
|
|
240
|
+
declare const isKeyMap: (value: unknown) => value is KeyMap;
|
|
241
|
+
/**
|
|
242
|
+
* 检查是否为 KeyMap 数组
|
|
243
|
+
*/
|
|
244
|
+
declare const isKeyMapArray: (value: unknown) => value is KeyMap[];
|
|
245
|
+
/**
|
|
246
|
+
* 检查是否为 ObjectKey 数组
|
|
247
|
+
*/
|
|
248
|
+
declare const isObjectKeyArray: (value: unknown) => value is ObjectKey[];
|
|
200
249
|
declare const isObjectResult: (data: unknown) => data is Record<string, unknown>;
|
|
201
250
|
declare const generateDefaultField: (opts?: Partial<DefaultField>) => DefaultField;
|
|
202
|
-
declare const generateFieldName: ({ func,
|
|
251
|
+
declare const generateFieldName: <P extends RequestParams = RequestParams, R extends ResultType = ResultType>({ func, query }: {
|
|
252
|
+
func: ApiContract<P, R>;
|
|
253
|
+
query?: P;
|
|
254
|
+
}) => string;
|
|
203
255
|
declare const getObjectDeepValue: (field: unknown, keys: string | string[]) => unknown;
|
|
204
256
|
declare const updateObjectDeepValue: (field: KeyMap, changeKey: string, value: unknown) => void;
|
|
205
257
|
declare const searchValueByKey: (result: ResultArrayType | ResultObjectType, id: ObjectKey, key: string) => unknown;
|
|
@@ -217,12 +269,18 @@ declare const utils_generateFieldName: typeof generateFieldName;
|
|
|
217
269
|
declare const utils_generateRequestParams: typeof generateRequestParams;
|
|
218
270
|
declare const utils_getObjectDeepValue: typeof getObjectDeepValue;
|
|
219
271
|
declare const utils_isArray: typeof isArray;
|
|
272
|
+
declare const utils_isKeyMap: typeof isKeyMap;
|
|
273
|
+
declare const utils_isKeyMapArray: typeof isKeyMapArray;
|
|
274
|
+
declare const utils_isObjectKey: typeof isObjectKey;
|
|
275
|
+
declare const utils_isObjectKeyArray: typeof isObjectKeyArray;
|
|
220
276
|
declare const utils_isObjectResult: typeof isObjectResult;
|
|
277
|
+
declare const utils_isResultArray: typeof isResultArray;
|
|
278
|
+
declare const utils_isResultObject: typeof isResultObject;
|
|
221
279
|
declare const utils_searchValueByKey: typeof searchValueByKey;
|
|
222
280
|
declare const utils_setReactivityField: typeof setReactivityField;
|
|
223
281
|
declare const utils_updateObjectDeepValue: typeof updateObjectDeepValue;
|
|
224
282
|
declare namespace utils {
|
|
225
|
-
export { utils_combineArrayData as combineArrayData, utils_computeMatchedItemIndex as computeMatchedItemIndex, utils_computeResultLength as computeResultLength, utils_generateDefaultField as generateDefaultField, utils_generateFieldName as generateFieldName, utils_generateRequestParams as generateRequestParams, utils_getObjectDeepValue as getObjectDeepValue, utils_isArray as isArray, utils_isObjectResult as isObjectResult, utils_searchValueByKey as searchValueByKey, utils_setReactivityField as setReactivityField, utils_updateObjectDeepValue as updateObjectDeepValue };
|
|
283
|
+
export { utils_combineArrayData as combineArrayData, utils_computeMatchedItemIndex as computeMatchedItemIndex, utils_computeResultLength as computeResultLength, utils_generateDefaultField as generateDefaultField, utils_generateFieldName as generateFieldName, utils_generateRequestParams as generateRequestParams, utils_getObjectDeepValue as getObjectDeepValue, utils_isArray as isArray, utils_isKeyMap as isKeyMap, utils_isKeyMapArray as isKeyMapArray, utils_isObjectKey as isObjectKey, utils_isObjectKeyArray as isObjectKeyArray, utils_isObjectResult as isObjectResult, utils_isResultArray as isResultArray, utils_isResultObject as isResultObject, utils_searchValueByKey as searchValueByKey, utils_setReactivityField as setReactivityField, utils_updateObjectDeepValue as updateObjectDeepValue };
|
|
226
284
|
}
|
|
227
285
|
|
|
228
286
|
declare const _default: {
|
|
@@ -257,4 +315,4 @@ declare const _default: {
|
|
|
257
315
|
readonly DEFAULT_UNIQUE_KEY_NAME: "id";
|
|
258
316
|
};
|
|
259
317
|
|
|
260
|
-
export { type ApiFunction, type ApiResponse, type DataSource, type DefaultField, _default as ENUM, type FetchResultCallback, type FetchType, type FieldGetter, type FieldKeys, type FieldSetter, type GenerateParamsResp, type GenerateParamsType, type InitDataParams, type InitDataType, type InitStateParams, type InitStateType, type KeyMap, type LoadMoreParams, type LoadMoreType, type ObjectKey, type ResultArrayType, type ResultObjectType, type ResultType, type SetDataType, type SetErrorType, type SetterFuncParams, type UpdateStateParams, type UpdateStateType, initData, initState, loadMore, updateState, utils };
|
|
318
|
+
export { type ApiContract, type ApiFunction, type ApiResponse, type DataSource, type DefaultField, _default as ENUM, type FetchResultCallback, type FetchType, type FieldGetter, type FieldKeys, type FieldSetter, type GenerateParamsResp, type GenerateParamsType, type InitDataParams, type InitDataType, type InitStateParams, type InitStateType, type KeyMap, type LoadMoreParams, type LoadMoreType, type ObjectKey, type RequestParams, type ResultArrayType, type ResultObjectType, type ResultType, type SetDataType, type SetErrorType, type SetterFuncParams, type UpdateStateParams, type UpdateStateType, createApi, initData, initState, loadMore, updateState, utils };
|