@lytjs/plugin-data 6.7.0 → 6.9.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.cjs +1 -3
- package/dist/index.d.cts +131 -0
- package/dist/index.d.ts +131 -0
- package/dist/index.mjs +1 -3
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -348,9 +348,7 @@ function createDataManager(globalOptions = {}) {
|
|
|
348
348
|
return instance.fetch();
|
|
349
349
|
},
|
|
350
350
|
addRequestInterceptor(interceptor) {
|
|
351
|
-
manager.addRequestInterceptor(
|
|
352
|
-
interceptor
|
|
353
|
-
);
|
|
351
|
+
manager.addRequestInterceptor(interceptor);
|
|
354
352
|
},
|
|
355
353
|
addResponseInterceptor(interceptor) {
|
|
356
354
|
manager.addResponseInterceptor(interceptor);
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import * as _lytjs_core from '@lytjs/core';
|
|
2
|
+
import { FetchInstance, RequestOptions as RequestOptions$1, RequestInterceptor, ResponseInterceptor, ErrorInterceptor, CacheStorage, FetchPluginOptions, CacheEntry } from '@lytjs/plugin-data-fetch';
|
|
3
|
+
export { CacheEntry, CacheStorage, FetchError, generateCacheKey } from '@lytjs/plugin-data-fetch';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @lytjs/plugin-data - 类型定义
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
interface RequestOptions extends RequestOptions$1 {
|
|
10
|
+
/** 是否启用请求去重 */
|
|
11
|
+
dedupe?: boolean;
|
|
12
|
+
/** 乐观更新数据 */
|
|
13
|
+
optimisticData?: unknown;
|
|
14
|
+
/** 预取相关配置 */
|
|
15
|
+
prefetch?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface DataPluginOptions extends FetchPluginOptions {
|
|
19
|
+
/** 默认去重设置 */
|
|
20
|
+
defaultDedupe?: boolean;
|
|
21
|
+
/** 离线模式 */
|
|
22
|
+
offlineMode?: boolean;
|
|
23
|
+
/** 与 store 的集成配置 */
|
|
24
|
+
storeIntegration?: {
|
|
25
|
+
/** 数据同步时的钩子 */
|
|
26
|
+
onSync?: (key: string, data: unknown) => void;
|
|
27
|
+
/** 数据更新时的钩子 */
|
|
28
|
+
onUpdate?: (key: string, data: unknown) => void;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
interface DataManager {
|
|
32
|
+
/** 创建数据实例 */
|
|
33
|
+
createData<T = unknown>(url: string, options?: RequestOptions): DataInstance<T>;
|
|
34
|
+
/** 执行简单 GET 请求 */
|
|
35
|
+
get<T = unknown>(url: string, options?: RequestOptions): Promise<T>;
|
|
36
|
+
/** 执行简单 POST 请求 */
|
|
37
|
+
post<T = unknown>(url: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
38
|
+
/** 执行简单 PUT 请求 */
|
|
39
|
+
put<T = unknown>(url: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
40
|
+
/** 执行简单 DELETE 请求 */
|
|
41
|
+
delete<T = unknown>(url: string, options?: RequestOptions): Promise<T>;
|
|
42
|
+
/** 添加请求拦截器 */
|
|
43
|
+
addRequestInterceptor(interceptor: RequestInterceptor): void;
|
|
44
|
+
/** 添加响应拦截器 */
|
|
45
|
+
addResponseInterceptor(interceptor: ResponseInterceptor): void;
|
|
46
|
+
/** 添加错误拦截器 */
|
|
47
|
+
addErrorInterceptor(interceptor: ErrorInterceptor): void;
|
|
48
|
+
/** 获取缓存存储 */
|
|
49
|
+
getCacheStorage(): CacheStorage;
|
|
50
|
+
/** 清空缓存 */
|
|
51
|
+
clearCache(): void;
|
|
52
|
+
/** 清除特定缓存 */
|
|
53
|
+
invalidateCache(key: string): void;
|
|
54
|
+
/** 预取数据 */
|
|
55
|
+
prefetch<T = unknown>(url: string, options?: RequestOptions): Promise<T>;
|
|
56
|
+
/** 获取当前的请求队列 */
|
|
57
|
+
getPendingRequests(): Set<string>;
|
|
58
|
+
/** 取消所有请求 */
|
|
59
|
+
cancelAllRequests(): void;
|
|
60
|
+
}
|
|
61
|
+
interface DataInstance<T = unknown> extends FetchInstance<T> {
|
|
62
|
+
/** 乐观更新数据 */
|
|
63
|
+
optimisticUpdate(data: T): void;
|
|
64
|
+
/** 回滚乐观更新 */
|
|
65
|
+
rollbackOptimistic(): void;
|
|
66
|
+
/** 获取预取状态 */
|
|
67
|
+
isPrefetching: boolean;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* TTL (Time To Live) 缓存策略实现
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
declare class TTLCache implements CacheStorage {
|
|
75
|
+
private cache;
|
|
76
|
+
get<T = unknown>(key: string): CacheEntry<T> | null;
|
|
77
|
+
set<T = unknown>(key: string, value: CacheEntry<T>): void;
|
|
78
|
+
delete(key: string): void;
|
|
79
|
+
clear(): void;
|
|
80
|
+
has(key: string): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* 获取缓存大小
|
|
83
|
+
*/
|
|
84
|
+
size(): number;
|
|
85
|
+
/**
|
|
86
|
+
* 获取所有缓存键
|
|
87
|
+
*/
|
|
88
|
+
keys(): string[];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* LRU (Least Recently Used) 缓存策略实现
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
interface LRUEntry<T = unknown> extends CacheEntry<T> {
|
|
96
|
+
lastAccessed: number;
|
|
97
|
+
}
|
|
98
|
+
declare class LRUCache implements CacheStorage {
|
|
99
|
+
private cache;
|
|
100
|
+
private readonly maxSize;
|
|
101
|
+
constructor(maxSize?: number);
|
|
102
|
+
get<T = unknown>(key: string): LRUEntry<T> | null;
|
|
103
|
+
set<T = unknown>(key: string, value: CacheEntry<T>): void;
|
|
104
|
+
delete(key: string): void;
|
|
105
|
+
clear(): void;
|
|
106
|
+
has(key: string): boolean;
|
|
107
|
+
private evict;
|
|
108
|
+
/**
|
|
109
|
+
* 获取缓存大小
|
|
110
|
+
*/
|
|
111
|
+
size(): number;
|
|
112
|
+
/**
|
|
113
|
+
* 获取最大缓存大小
|
|
114
|
+
*/
|
|
115
|
+
getMaxSize(): number;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 创建数据实例
|
|
120
|
+
*/
|
|
121
|
+
declare function createData<T = unknown>(url: string, options?: RequestOptions, globalOptions?: DataPluginOptions): DataInstance<T>;
|
|
122
|
+
/**
|
|
123
|
+
* 创建数据管理器
|
|
124
|
+
*/
|
|
125
|
+
declare function createDataManager(globalOptions?: DataPluginOptions): DataManager;
|
|
126
|
+
/**
|
|
127
|
+
* 定义插件
|
|
128
|
+
*/
|
|
129
|
+
declare const pluginData: _lytjs_core.PluginDefinition<unknown>;
|
|
130
|
+
|
|
131
|
+
export { type DataInstance, type DataManager, type DataPluginOptions, LRUCache, type RequestOptions, TTLCache, createData, createDataManager, pluginData as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import * as _lytjs_core from '@lytjs/core';
|
|
2
|
+
import { FetchInstance, RequestOptions as RequestOptions$1, RequestInterceptor, ResponseInterceptor, ErrorInterceptor, CacheStorage, FetchPluginOptions, CacheEntry } from '@lytjs/plugin-data-fetch';
|
|
3
|
+
export { CacheEntry, CacheStorage, FetchError, generateCacheKey } from '@lytjs/plugin-data-fetch';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @lytjs/plugin-data - 类型定义
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
interface RequestOptions extends RequestOptions$1 {
|
|
10
|
+
/** 是否启用请求去重 */
|
|
11
|
+
dedupe?: boolean;
|
|
12
|
+
/** 乐观更新数据 */
|
|
13
|
+
optimisticData?: unknown;
|
|
14
|
+
/** 预取相关配置 */
|
|
15
|
+
prefetch?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface DataPluginOptions extends FetchPluginOptions {
|
|
19
|
+
/** 默认去重设置 */
|
|
20
|
+
defaultDedupe?: boolean;
|
|
21
|
+
/** 离线模式 */
|
|
22
|
+
offlineMode?: boolean;
|
|
23
|
+
/** 与 store 的集成配置 */
|
|
24
|
+
storeIntegration?: {
|
|
25
|
+
/** 数据同步时的钩子 */
|
|
26
|
+
onSync?: (key: string, data: unknown) => void;
|
|
27
|
+
/** 数据更新时的钩子 */
|
|
28
|
+
onUpdate?: (key: string, data: unknown) => void;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
interface DataManager {
|
|
32
|
+
/** 创建数据实例 */
|
|
33
|
+
createData<T = unknown>(url: string, options?: RequestOptions): DataInstance<T>;
|
|
34
|
+
/** 执行简单 GET 请求 */
|
|
35
|
+
get<T = unknown>(url: string, options?: RequestOptions): Promise<T>;
|
|
36
|
+
/** 执行简单 POST 请求 */
|
|
37
|
+
post<T = unknown>(url: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
38
|
+
/** 执行简单 PUT 请求 */
|
|
39
|
+
put<T = unknown>(url: string, body?: unknown, options?: RequestOptions): Promise<T>;
|
|
40
|
+
/** 执行简单 DELETE 请求 */
|
|
41
|
+
delete<T = unknown>(url: string, options?: RequestOptions): Promise<T>;
|
|
42
|
+
/** 添加请求拦截器 */
|
|
43
|
+
addRequestInterceptor(interceptor: RequestInterceptor): void;
|
|
44
|
+
/** 添加响应拦截器 */
|
|
45
|
+
addResponseInterceptor(interceptor: ResponseInterceptor): void;
|
|
46
|
+
/** 添加错误拦截器 */
|
|
47
|
+
addErrorInterceptor(interceptor: ErrorInterceptor): void;
|
|
48
|
+
/** 获取缓存存储 */
|
|
49
|
+
getCacheStorage(): CacheStorage;
|
|
50
|
+
/** 清空缓存 */
|
|
51
|
+
clearCache(): void;
|
|
52
|
+
/** 清除特定缓存 */
|
|
53
|
+
invalidateCache(key: string): void;
|
|
54
|
+
/** 预取数据 */
|
|
55
|
+
prefetch<T = unknown>(url: string, options?: RequestOptions): Promise<T>;
|
|
56
|
+
/** 获取当前的请求队列 */
|
|
57
|
+
getPendingRequests(): Set<string>;
|
|
58
|
+
/** 取消所有请求 */
|
|
59
|
+
cancelAllRequests(): void;
|
|
60
|
+
}
|
|
61
|
+
interface DataInstance<T = unknown> extends FetchInstance<T> {
|
|
62
|
+
/** 乐观更新数据 */
|
|
63
|
+
optimisticUpdate(data: T): void;
|
|
64
|
+
/** 回滚乐观更新 */
|
|
65
|
+
rollbackOptimistic(): void;
|
|
66
|
+
/** 获取预取状态 */
|
|
67
|
+
isPrefetching: boolean;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* TTL (Time To Live) 缓存策略实现
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
declare class TTLCache implements CacheStorage {
|
|
75
|
+
private cache;
|
|
76
|
+
get<T = unknown>(key: string): CacheEntry<T> | null;
|
|
77
|
+
set<T = unknown>(key: string, value: CacheEntry<T>): void;
|
|
78
|
+
delete(key: string): void;
|
|
79
|
+
clear(): void;
|
|
80
|
+
has(key: string): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* 获取缓存大小
|
|
83
|
+
*/
|
|
84
|
+
size(): number;
|
|
85
|
+
/**
|
|
86
|
+
* 获取所有缓存键
|
|
87
|
+
*/
|
|
88
|
+
keys(): string[];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* LRU (Least Recently Used) 缓存策略实现
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
interface LRUEntry<T = unknown> extends CacheEntry<T> {
|
|
96
|
+
lastAccessed: number;
|
|
97
|
+
}
|
|
98
|
+
declare class LRUCache implements CacheStorage {
|
|
99
|
+
private cache;
|
|
100
|
+
private readonly maxSize;
|
|
101
|
+
constructor(maxSize?: number);
|
|
102
|
+
get<T = unknown>(key: string): LRUEntry<T> | null;
|
|
103
|
+
set<T = unknown>(key: string, value: CacheEntry<T>): void;
|
|
104
|
+
delete(key: string): void;
|
|
105
|
+
clear(): void;
|
|
106
|
+
has(key: string): boolean;
|
|
107
|
+
private evict;
|
|
108
|
+
/**
|
|
109
|
+
* 获取缓存大小
|
|
110
|
+
*/
|
|
111
|
+
size(): number;
|
|
112
|
+
/**
|
|
113
|
+
* 获取最大缓存大小
|
|
114
|
+
*/
|
|
115
|
+
getMaxSize(): number;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 创建数据实例
|
|
120
|
+
*/
|
|
121
|
+
declare function createData<T = unknown>(url: string, options?: RequestOptions, globalOptions?: DataPluginOptions): DataInstance<T>;
|
|
122
|
+
/**
|
|
123
|
+
* 创建数据管理器
|
|
124
|
+
*/
|
|
125
|
+
declare function createDataManager(globalOptions?: DataPluginOptions): DataManager;
|
|
126
|
+
/**
|
|
127
|
+
* 定义插件
|
|
128
|
+
*/
|
|
129
|
+
declare const pluginData: _lytjs_core.PluginDefinition<unknown>;
|
|
130
|
+
|
|
131
|
+
export { type DataInstance, type DataManager, type DataPluginOptions, LRUCache, type RequestOptions, TTLCache, createData, createDataManager, pluginData as default };
|
package/dist/index.mjs
CHANGED
|
@@ -323,9 +323,7 @@ function createDataManager(globalOptions = {}) {
|
|
|
323
323
|
return instance.fetch();
|
|
324
324
|
},
|
|
325
325
|
addRequestInterceptor(interceptor) {
|
|
326
|
-
manager.addRequestInterceptor(
|
|
327
|
-
interceptor
|
|
328
|
-
);
|
|
326
|
+
manager.addRequestInterceptor(interceptor);
|
|
329
327
|
},
|
|
330
328
|
addResponseInterceptor(interceptor) {
|
|
331
329
|
manager.addResponseInterceptor(interceptor);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@lytjs/plugin-data",
|
|
4
|
-
"version": "6.
|
|
4
|
+
"version": "6.9.0",
|
|
5
5
|
"description": "LytJS official enhanced data plugin with optimistic updates, deduplication, and store integration",
|
|
6
6
|
"author": "lytjs",
|
|
7
7
|
"license": "MIT",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"clean": "rm -rf dist node_modules .turbo"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@lytjs/core": "^6.
|
|
37
|
-
"@lytjs/reactivity": "^6.
|
|
38
|
-
"@lytjs/plugin-data-fetch": "^6.
|
|
36
|
+
"@lytjs/core": "^6.9.0",
|
|
37
|
+
"@lytjs/reactivity": "^6.9.0",
|
|
38
|
+
"@lytjs/plugin-data-fetch": "^6.9.0"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"tsup": "^8.3.6",
|