@qlover/fe-corekit 3.1.0 → 3.2.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/common.d.ts +193 -0
- package/dist/common.js +0 -0
- package/dist/index.cjs +188 -308
- package/dist/index.d.ts +351 -697
- package/dist/index.iife.js +8348 -0
- package/dist/index.iife.min.js +2 -8440
- package/dist/index.js +175 -300
- package/package.json +31 -1
package/dist/index.js
CHANGED
|
@@ -2809,6 +2809,9 @@ var RequestAdapterFetch = class {
|
|
|
2809
2809
|
if (!baseURL) {
|
|
2810
2810
|
return url;
|
|
2811
2811
|
}
|
|
2812
|
+
if (url.startsWith(baseURL)) {
|
|
2813
|
+
return url;
|
|
2814
|
+
}
|
|
2812
2815
|
if (baseURL.endsWith("/") && url.startsWith("/")) {
|
|
2813
2816
|
return baseURL.slice(0, -1) + url;
|
|
2814
2817
|
}
|
|
@@ -3755,12 +3758,18 @@ var SimpleUrlBuilder = class {
|
|
|
3755
3758
|
basePath = "/" + basePath;
|
|
3756
3759
|
}
|
|
3757
3760
|
let combinedPath = basePath;
|
|
3758
|
-
if (!combinedPath.endsWith("/")
|
|
3759
|
-
combinedPath
|
|
3761
|
+
if (!combinedPath.endsWith("/") || !url.startsWith("/")) {
|
|
3762
|
+
if (!combinedPath.endsWith("/")) {
|
|
3763
|
+
combinedPath += "/";
|
|
3764
|
+
}
|
|
3760
3765
|
}
|
|
3761
3766
|
combinedPath += url.replace(/^\//, "");
|
|
3762
3767
|
urlObject = new URL(combinedPath, "http://temp");
|
|
3763
3768
|
shouldReturnPathOnly = true;
|
|
3769
|
+
} else if (base && base === "api") {
|
|
3770
|
+
const combinedPath = "/api/" + url.replace(/^\//, "");
|
|
3771
|
+
urlObject = new URL(combinedPath, "http://temp");
|
|
3772
|
+
shouldReturnPathOnly = true;
|
|
3764
3773
|
} else if (base) {
|
|
3765
3774
|
urlObject = new URL(url, "http://temp");
|
|
3766
3775
|
shouldReturnPathOnly = true;
|
|
@@ -3909,6 +3918,7 @@ var SimpleUrlBuilder = class {
|
|
|
3909
3918
|
};
|
|
3910
3919
|
|
|
3911
3920
|
// src/request/impl/RequestPlugin.ts
|
|
3921
|
+
import { clone as clone2 } from "lodash-es";
|
|
3912
3922
|
var RequestPlugin = class {
|
|
3913
3923
|
pluginName = "RequestPlugin";
|
|
3914
3924
|
config;
|
|
@@ -3963,13 +3973,29 @@ var RequestPlugin = class {
|
|
|
3963
3973
|
* @override
|
|
3964
3974
|
*/
|
|
3965
3975
|
onBefore(ctx) {
|
|
3966
|
-
|
|
3976
|
+
ctx.setParameters(this.mergeConfig(ctx.parameters));
|
|
3977
|
+
}
|
|
3978
|
+
startsWith(url, baseUrl) {
|
|
3979
|
+
return url.startsWith(baseUrl);
|
|
3980
|
+
}
|
|
3981
|
+
/**
|
|
3982
|
+
* Main request handler
|
|
3983
|
+
*
|
|
3984
|
+
* This is the core of the plugin. It merges default plugin configuration with request context configuration,
|
|
3985
|
+
* processes request data, builds the URL, and injects headers.
|
|
3986
|
+
*
|
|
3987
|
+
* @param config - Request configuration
|
|
3988
|
+
* @returns Merged configuration with processed data, built URL, and injected headers
|
|
3989
|
+
*/
|
|
3990
|
+
mergeConfig(config) {
|
|
3991
|
+
const mergedConfig = this.createConfig(config);
|
|
3967
3992
|
const processedData = this.processRequestData(mergedConfig);
|
|
3968
3993
|
const builtUrl = this.buildUrl(mergedConfig);
|
|
3994
|
+
if (builtUrl && mergedConfig.baseURL && this.startsWith(builtUrl, mergedConfig.baseURL)) {
|
|
3995
|
+
delete mergedConfig.baseURL;
|
|
3996
|
+
}
|
|
3969
3997
|
const injectedHeaders = this.injectHeaders(mergedConfig);
|
|
3970
|
-
|
|
3971
|
-
...ctx.parameters,
|
|
3972
|
-
...mergedConfig,
|
|
3998
|
+
return Object.assign(mergedConfig, {
|
|
3973
3999
|
data: processedData,
|
|
3974
4000
|
url: builtUrl,
|
|
3975
4001
|
headers: injectedHeaders
|
|
@@ -3987,8 +4013,8 @@ var RequestPlugin = class {
|
|
|
3987
4013
|
* @param contextConfig - Configuration from request context
|
|
3988
4014
|
* @returns Merged configuration
|
|
3989
4015
|
*/
|
|
3990
|
-
|
|
3991
|
-
const merged =
|
|
4016
|
+
createConfig(contextConfig) {
|
|
4017
|
+
const merged = Object.assign(clone2(this.config), contextConfig);
|
|
3992
4018
|
if (!("data" in contextConfig) && "data" in this.config) {
|
|
3993
4019
|
merged.data = this.config.data;
|
|
3994
4020
|
}
|
|
@@ -4002,13 +4028,10 @@ var RequestPlugin = class {
|
|
|
4002
4028
|
* @throws {Error} If the built URL is empty or invalid
|
|
4003
4029
|
*/
|
|
4004
4030
|
buildUrl(config) {
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
throw new Error(
|
|
4008
|
-
`RequestPlugin: Invalid URL. URL cannot be empty. baseURL: ${config.baseURL ?? "undefined"}, url: ${config.url ?? "undefined"}`
|
|
4009
|
-
);
|
|
4031
|
+
if (config.allowEmptyUrl === false && !config.url && !config.baseURL) {
|
|
4032
|
+
throw new Error("Empty URL is not allowed");
|
|
4010
4033
|
}
|
|
4011
|
-
return
|
|
4034
|
+
return this.urlBuilder.buildUrl(config);
|
|
4012
4035
|
}
|
|
4013
4036
|
/**
|
|
4014
4037
|
* Inject default headers into request configuration
|
|
@@ -4143,18 +4166,17 @@ var ResponsePlugin = class {
|
|
|
4143
4166
|
async onSuccess(context) {
|
|
4144
4167
|
const returnValue = context.returnValue;
|
|
4145
4168
|
const config = context.parameters;
|
|
4169
|
+
const result = await this.handleResponse(returnValue, config);
|
|
4170
|
+
if (result) {
|
|
4171
|
+
context.setReturnValue(result);
|
|
4172
|
+
}
|
|
4173
|
+
}
|
|
4174
|
+
handleResponse(returnValue, config) {
|
|
4146
4175
|
if (returnValue instanceof Response) {
|
|
4147
|
-
|
|
4148
|
-
context.setReturnValue(processedResponse);
|
|
4149
|
-
return;
|
|
4176
|
+
return this.processResponse(returnValue, config);
|
|
4150
4177
|
}
|
|
4151
4178
|
if (isRequestAdapterResponse(returnValue)) {
|
|
4152
|
-
|
|
4153
|
-
returnValue,
|
|
4154
|
-
config
|
|
4155
|
-
);
|
|
4156
|
-
context.setReturnValue(processedResponse);
|
|
4157
|
-
return;
|
|
4179
|
+
return this.processAdapterResponse(returnValue, config);
|
|
4158
4180
|
}
|
|
4159
4181
|
}
|
|
4160
4182
|
/**
|
|
@@ -4832,71 +4854,45 @@ var Base64Serializer = class {
|
|
|
4832
4854
|
|
|
4833
4855
|
// src/storage/impl/KeyStorage.ts
|
|
4834
4856
|
var KeyStorage = class {
|
|
4835
|
-
constructor(key,
|
|
4857
|
+
constructor(key, storage) {
|
|
4836
4858
|
this.key = key;
|
|
4837
|
-
this.
|
|
4838
|
-
try {
|
|
4839
|
-
const localValue = options.storage?.getItem(key);
|
|
4840
|
-
this.value = localValue ?? null;
|
|
4841
|
-
} catch {
|
|
4842
|
-
this.value = null;
|
|
4843
|
-
}
|
|
4859
|
+
this.storage = storage;
|
|
4844
4860
|
}
|
|
4845
4861
|
value;
|
|
4846
|
-
mergeOptions(options) {
|
|
4847
|
-
return {
|
|
4848
|
-
...this.options,
|
|
4849
|
-
...options
|
|
4850
|
-
};
|
|
4851
|
-
}
|
|
4852
|
-
/**
|
|
4853
|
-
* @override
|
|
4854
|
-
*/
|
|
4855
|
-
getKey() {
|
|
4856
|
-
return this.key;
|
|
4857
|
-
}
|
|
4858
|
-
/**
|
|
4859
|
-
* @override
|
|
4860
|
-
*/
|
|
4861
|
-
getValue() {
|
|
4862
|
-
return this.value;
|
|
4863
|
-
}
|
|
4864
4862
|
/**
|
|
4865
4863
|
* @override
|
|
4866
4864
|
*/
|
|
4867
4865
|
get(options) {
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
return this.value;
|
|
4866
|
+
if (!this.storage) {
|
|
4867
|
+
return this.value ?? null;
|
|
4871
4868
|
}
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4876
|
-
return null;
|
|
4877
|
-
}
|
|
4878
|
-
this.value = val;
|
|
4879
|
-
return val;
|
|
4869
|
+
const val = this.storage.getItem(this.key, options);
|
|
4870
|
+
if (val == null) {
|
|
4871
|
+
this.remove();
|
|
4872
|
+
return null;
|
|
4880
4873
|
}
|
|
4881
|
-
|
|
4874
|
+
this.value = val;
|
|
4875
|
+
return val;
|
|
4882
4876
|
}
|
|
4883
4877
|
/**
|
|
4884
4878
|
* @override
|
|
4885
4879
|
*/
|
|
4886
|
-
set(
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
|
|
4890
|
-
storage.setItem(this.key, token, reset);
|
|
4880
|
+
set(value, options) {
|
|
4881
|
+
if (!this.storage) {
|
|
4882
|
+
this.value = value;
|
|
4883
|
+
return;
|
|
4891
4884
|
}
|
|
4885
|
+
this.storage.setItem(this.key, value, options);
|
|
4892
4886
|
}
|
|
4893
4887
|
/**
|
|
4894
4888
|
* @override
|
|
4895
4889
|
*/
|
|
4896
4890
|
remove(options) {
|
|
4897
|
-
|
|
4898
|
-
|
|
4899
|
-
|
|
4891
|
+
if (!this.storage) {
|
|
4892
|
+
this.value = null;
|
|
4893
|
+
return;
|
|
4894
|
+
}
|
|
4895
|
+
this.storage.removeItem(this.key, options);
|
|
4900
4896
|
}
|
|
4901
4897
|
};
|
|
4902
4898
|
|
|
@@ -4931,7 +4927,6 @@ var ObjectStorage = class {
|
|
|
4931
4927
|
/**
|
|
4932
4928
|
* Gets the number of items stored in the memory cache
|
|
4933
4929
|
*
|
|
4934
|
-
* @override
|
|
4935
4930
|
* @returns The number of stored items in memory
|
|
4936
4931
|
*
|
|
4937
4932
|
* @example
|
|
@@ -5009,12 +5004,9 @@ var ObjectStorage = class {
|
|
|
5009
5004
|
if (!storeValue) {
|
|
5010
5005
|
return _dv;
|
|
5011
5006
|
}
|
|
5012
|
-
const value = this.serializer ? this.serializer.deserialize(storeValue, _dv) : storeValue;
|
|
5007
|
+
const value = typeof storeValue === "string" && this.serializer ? this.serializer.deserialize(storeValue, _dv) : storeValue;
|
|
5013
5008
|
return this.getRawValue(value, _dv);
|
|
5014
5009
|
}
|
|
5015
|
-
/**
|
|
5016
|
-
* @override
|
|
5017
|
-
*/
|
|
5018
5010
|
getRawValue(value, defaultValue) {
|
|
5019
5011
|
if (this.isStorageValue(value)) {
|
|
5020
5012
|
if (this.isExpired(value)) {
|
|
@@ -5108,268 +5100,146 @@ var ObjectStorage = class {
|
|
|
5108
5100
|
isStorageValue(value) {
|
|
5109
5101
|
return typeof value === "object" && value !== null && "key" in value && "value" in value;
|
|
5110
5102
|
}
|
|
5111
|
-
/**
|
|
5112
|
-
* Gets the serializer instance
|
|
5113
|
-
*
|
|
5114
|
-
* Significance: Provides access to the serialization logic
|
|
5115
|
-
* Core idea: Expose serializer for advanced use cases
|
|
5116
|
-
* Main function: Return the serializer instance
|
|
5117
|
-
* Main purpose: Enable direct access to serialization when needed
|
|
5118
|
-
*
|
|
5119
|
-
* @returns The serializer instance
|
|
5120
|
-
*
|
|
5121
|
-
* @example
|
|
5122
|
-
* ```typescript
|
|
5123
|
-
* const serializer = storage.getSerializer();
|
|
5124
|
-
* if (serializer) {
|
|
5125
|
-
* // Direct access to serializer
|
|
5126
|
-
* }
|
|
5127
|
-
* ```
|
|
5128
|
-
*/
|
|
5129
|
-
getSerializer() {
|
|
5130
|
-
return this.serializer;
|
|
5131
|
-
}
|
|
5132
5103
|
};
|
|
5133
5104
|
|
|
5134
|
-
// src/storage/
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
|
|
5138
|
-
|
|
5139
|
-
if ("serialize" in pipe && "deserialize" in pipe) {
|
|
5140
|
-
return { pipe, type: "serialize" };
|
|
5141
|
-
}
|
|
5142
|
-
if ("encrypt" in pipe && "decrypt" in pipe) {
|
|
5143
|
-
return { pipe, type: "encrypt" };
|
|
5105
|
+
// src/storage/utils/isStorage.ts
|
|
5106
|
+
var storageMethods = ["setItem", "getItem", "removeItem", "clear"];
|
|
5107
|
+
function isStorage(storage) {
|
|
5108
|
+
if (storage == null || typeof storage !== "object") {
|
|
5109
|
+
return false;
|
|
5144
5110
|
}
|
|
5145
|
-
|
|
5146
|
-
|
|
5111
|
+
for (const method of storageMethods) {
|
|
5112
|
+
if (storage[method] == null || typeof storage[method] !== "function") {
|
|
5113
|
+
return false;
|
|
5114
|
+
}
|
|
5147
5115
|
}
|
|
5148
|
-
return
|
|
5116
|
+
return true;
|
|
5149
5117
|
}
|
|
5150
|
-
|
|
5151
|
-
|
|
5152
|
-
|
|
5153
|
-
|
|
5154
|
-
|
|
5155
|
-
|
|
5156
|
-
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
|
|
5177
|
-
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
5190
|
-
|
|
5191
|
-
* // Data stored as-is without transformation
|
|
5192
|
-
* ```
|
|
5193
|
-
*/
|
|
5194
|
-
constructor(storage, pipes = []) {
|
|
5195
|
-
this.storage = storage;
|
|
5196
|
-
this.pipes = (Array.isArray(pipes) ? pipes : [pipes]).map((p) => toPipeValue(p)).filter((p) => p != null);
|
|
5118
|
+
|
|
5119
|
+
// src/storage/utils/createStoragePlugin.ts
|
|
5120
|
+
function createStoragePluginWithStorage(storage) {
|
|
5121
|
+
return {
|
|
5122
|
+
get: storage.getItem.bind(storage),
|
|
5123
|
+
set: storage.setItem.bind(storage),
|
|
5124
|
+
remove: storage.removeItem.bind(storage),
|
|
5125
|
+
clear: storage.clear.bind(storage),
|
|
5126
|
+
type: "storage"
|
|
5127
|
+
};
|
|
5128
|
+
}
|
|
5129
|
+
function isSerializer(plugin) {
|
|
5130
|
+
return typeof plugin === "object" && plugin !== null && "serialize" in plugin && "deserialize" in plugin;
|
|
5131
|
+
}
|
|
5132
|
+
function isEncryptor(plugin) {
|
|
5133
|
+
return typeof plugin === "object" && plugin !== null && "encrypt" in plugin && "decrypt" in plugin;
|
|
5134
|
+
}
|
|
5135
|
+
function createStoragePlugin(plugins) {
|
|
5136
|
+
if (Array.isArray(plugins)) {
|
|
5137
|
+
return plugins.map((plugin) => {
|
|
5138
|
+
if (isSerializer(plugin)) {
|
|
5139
|
+
return {
|
|
5140
|
+
get: (_key, value) => plugin.deserialize(
|
|
5141
|
+
value
|
|
5142
|
+
),
|
|
5143
|
+
set: (_key, value) => plugin.serialize(value),
|
|
5144
|
+
type: "serializer"
|
|
5145
|
+
};
|
|
5146
|
+
} else if (isEncryptor(plugin)) {
|
|
5147
|
+
return {
|
|
5148
|
+
get: (_key, value) => plugin.decrypt(
|
|
5149
|
+
value
|
|
5150
|
+
),
|
|
5151
|
+
set: (_key, value) => plugin.encrypt(value),
|
|
5152
|
+
type: "encryptor"
|
|
5153
|
+
};
|
|
5154
|
+
} else if (isStorage(plugin)) {
|
|
5155
|
+
return createStoragePluginWithStorage(plugin);
|
|
5156
|
+
}
|
|
5157
|
+
return plugin;
|
|
5158
|
+
});
|
|
5197
5159
|
}
|
|
5160
|
+
return [createStoragePluginWithStorage(plugins)];
|
|
5161
|
+
}
|
|
5162
|
+
|
|
5163
|
+
// src/storage/impl/StorageExecutor.ts
|
|
5164
|
+
var StorageExecutor = class {
|
|
5165
|
+
plugins = [];
|
|
5198
5166
|
/**
|
|
5199
|
-
*
|
|
5200
|
-
*
|
|
5201
|
-
* Stores the processed pipeline of transformations that will be
|
|
5202
|
-
* applied to data during storage and retrieval operations.
|
|
5203
|
-
*
|
|
5204
|
-
* @protected
|
|
5205
|
-
*/
|
|
5206
|
-
pipes;
|
|
5207
|
-
/**
|
|
5208
|
-
* Get the number of items in the primary storage
|
|
5209
|
-
*
|
|
5210
|
-
* Returns the count of items in the primary storage backend only.
|
|
5211
|
-
* Does not include items in intermediate storage layers.
|
|
5212
|
-
*
|
|
5213
|
-
* @override
|
|
5214
|
-
* @returns Number of items in primary storage
|
|
5167
|
+
* Builds the plugin list from either a single `StorageInterface` or an array whose last element
|
|
5168
|
+
* is the backing storage and preceding elements are transformers (e.g. serializer, encryptor).
|
|
5215
5169
|
*
|
|
5216
|
-
* @
|
|
5217
|
-
* ```typescript
|
|
5218
|
-
* console.log(storage.length); // 5
|
|
5219
|
-
* storage.setItem('newKey', 'value');
|
|
5220
|
-
* console.log(storage.length); // 6
|
|
5221
|
-
* ```
|
|
5170
|
+
* @param plugins - Single storage instance or tuple of `[ ...transformers, storage ]`
|
|
5222
5171
|
*/
|
|
5223
|
-
|
|
5224
|
-
|
|
5172
|
+
constructor(plugins) {
|
|
5173
|
+
this.plugins = createStoragePlugin(plugins);
|
|
5225
5174
|
}
|
|
5226
5175
|
/**
|
|
5227
|
-
*
|
|
5228
|
-
*
|
|
5229
|
-
* Processes the value through the configured pipeline (serialization,
|
|
5230
|
-
* encryption, intermediate storage) before storing in the primary storage.
|
|
5231
|
-
*
|
|
5232
|
-
* Pipeline execution:
|
|
5233
|
-
* 1. Apply serialization (if configured)
|
|
5234
|
-
* 2. Apply encryption (if configured)
|
|
5235
|
-
* 3. Store in intermediate storage layers (if configured)
|
|
5236
|
-
* 4. Store in primary storage
|
|
5176
|
+
* Writes value through the plugin chain (forward). Each plugin may return a transformed value for the next.
|
|
5237
5177
|
*
|
|
5238
5178
|
* @override
|
|
5239
|
-
* @template T - Type of value to store
|
|
5240
|
-
* @param key - Storage key
|
|
5241
|
-
* @param value - Value to store
|
|
5242
|
-
* @param options - Optional storage options (e.g., expiration)
|
|
5243
|
-
*
|
|
5244
|
-
* @example Basic storage
|
|
5245
|
-
* ```typescript
|
|
5246
|
-
* storage.setItem('user', { id: 1, name: 'John' });
|
|
5247
|
-
* ```
|
|
5248
|
-
*
|
|
5249
|
-
* @example With options
|
|
5250
|
-
* ```typescript
|
|
5251
|
-
* storage.setItem('session', { token: 'abc' }, { expire: 3600 });
|
|
5252
|
-
* ```
|
|
5253
5179
|
*/
|
|
5254
5180
|
setItem(key, value, options) {
|
|
5255
|
-
let
|
|
5256
|
-
for (const
|
|
5257
|
-
const
|
|
5258
|
-
if (
|
|
5259
|
-
|
|
5260
|
-
key,
|
|
5261
|
-
processedValue,
|
|
5262
|
-
options
|
|
5263
|
-
);
|
|
5264
|
-
} else {
|
|
5265
|
-
const result = operationMaps.setItem[type](
|
|
5266
|
-
// @ts-expect-error
|
|
5267
|
-
pipe,
|
|
5268
|
-
[processedValue]
|
|
5269
|
-
);
|
|
5270
|
-
if (result != null) {
|
|
5271
|
-
processedValue = result;
|
|
5272
|
-
}
|
|
5181
|
+
let finalValue = value;
|
|
5182
|
+
for (const plugin of this.plugins) {
|
|
5183
|
+
const result = plugin.set(key, finalValue, options);
|
|
5184
|
+
if (result !== void 0) {
|
|
5185
|
+
finalValue = result;
|
|
5273
5186
|
}
|
|
5274
5187
|
}
|
|
5275
|
-
this.storage.setItem(key, processedValue, options);
|
|
5276
5188
|
}
|
|
5277
5189
|
/**
|
|
5278
|
-
*
|
|
5190
|
+
* Reads value through the plugin chain in reverse order.
|
|
5279
5191
|
*
|
|
5280
|
-
*
|
|
5281
|
-
*
|
|
5192
|
+
* **Multiple storage plugins:** When the pipeline contains more than one storage plugin (e.g.
|
|
5193
|
+
* `[sessionStorage, localStorage]`), getItem **only uses the value from the last storage** (the
|
|
5194
|
+
* plugin at the end of the array). The iteration runs from tail to head; the first storage plugin
|
|
5195
|
+
* encountered (which is the last in the array) is the only one whose `get` result is used. All
|
|
5196
|
+
* other storage plugins are skipped and their values are ignored. This ensures a single, well-defined
|
|
5197
|
+
* read source (e.g. prefer localStorage over sessionStorage when both are in the chain).
|
|
5282
5198
|
*
|
|
5283
|
-
*
|
|
5284
|
-
*
|
|
5285
|
-
* 2. If not found, try intermediate storage layers (in reverse order)
|
|
5286
|
-
* 3. Apply decryption (if configured)
|
|
5287
|
-
* 4. Apply deserialization (if configured)
|
|
5288
|
-
* 5. Return processed value or default
|
|
5199
|
+
* Pipe plugins (serializer, encryptor, etc.) are always applied to transform the value read from
|
|
5200
|
+
* that single storage. If no value is found, returns `defaultValue` when provided, otherwise `null`.
|
|
5289
5201
|
*
|
|
5290
5202
|
* @override
|
|
5291
|
-
* @template T - Type of value to retrieve
|
|
5292
|
-
* @param key - Storage key
|
|
5293
|
-
* @param defaultValue - Default value if key not found
|
|
5294
|
-
* @param options - Optional retrieval options
|
|
5295
|
-
* @returns Retrieved value or default, `null` if not found and no default
|
|
5296
|
-
*
|
|
5297
|
-
* @example Basic retrieval
|
|
5298
|
-
* ```typescript
|
|
5299
|
-
* const user = storage.getItem('user');
|
|
5300
|
-
* if (user) {
|
|
5301
|
-
* console.log(user.name);
|
|
5302
|
-
* }
|
|
5303
|
-
* ```
|
|
5304
|
-
*
|
|
5305
|
-
* @example With default value
|
|
5306
|
-
* ```typescript
|
|
5307
|
-
* const config = storage.getItem('config', { theme: 'light' });
|
|
5308
|
-
* console.log(config.theme); // 'light' if not found
|
|
5309
|
-
* ```
|
|
5310
5203
|
*/
|
|
5311
5204
|
getItem(key, defaultValue, options) {
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
5317
|
-
|
|
5318
|
-
|
|
5319
|
-
}
|
|
5320
|
-
const res = operationMaps.getItem[type](pipe, [
|
|
5321
|
-
key,
|
|
5322
|
-
processedValue,
|
|
5323
|
-
options
|
|
5324
|
-
]);
|
|
5325
|
-
if (res != null) {
|
|
5326
|
-
processedValue = res;
|
|
5327
|
-
break;
|
|
5328
|
-
}
|
|
5329
|
-
}
|
|
5330
|
-
}
|
|
5331
|
-
if (processedValue == null) {
|
|
5332
|
-
return defaultValue ?? null;
|
|
5333
|
-
}
|
|
5334
|
-
const reversedPipes = [...this.pipes].reverse();
|
|
5335
|
-
for (const currentPipe of reversedPipes) {
|
|
5336
|
-
const { type, pipe } = currentPipe;
|
|
5337
|
-
if (type === "storage") {
|
|
5205
|
+
const lastIndex = this.plugins.length - 1;
|
|
5206
|
+
let finalValue;
|
|
5207
|
+
let storageHasValue = false;
|
|
5208
|
+
for (let i = lastIndex; i >= 0; i--) {
|
|
5209
|
+
const plugin = this.plugins[i];
|
|
5210
|
+
const isStoragePlugin = plugin.type === "storage";
|
|
5211
|
+
if (isStoragePlugin && storageHasValue) {
|
|
5338
5212
|
continue;
|
|
5339
5213
|
}
|
|
5340
|
-
|
|
5341
|
-
|
|
5342
|
-
|
|
5343
|
-
|
|
5344
|
-
|
|
5345
|
-
|
|
5346
|
-
|
|
5214
|
+
const result = plugin.get(key, finalValue, options);
|
|
5215
|
+
if (result !== void 0) {
|
|
5216
|
+
finalValue = result;
|
|
5217
|
+
if (isStoragePlugin) {
|
|
5218
|
+
storageHasValue = true;
|
|
5219
|
+
}
|
|
5220
|
+
}
|
|
5347
5221
|
}
|
|
5348
|
-
return
|
|
5222
|
+
return finalValue ?? defaultValue ?? null;
|
|
5349
5223
|
}
|
|
5350
5224
|
/**
|
|
5351
|
-
*
|
|
5225
|
+
* Removes item for the given key from all plugins that implement `remove`.
|
|
5352
5226
|
*
|
|
5353
5227
|
* @override
|
|
5354
|
-
* @param key - Storage key
|
|
5355
|
-
* @param options - Delete options
|
|
5356
5228
|
*/
|
|
5357
5229
|
removeItem(key, options) {
|
|
5358
|
-
this.
|
|
5359
|
-
|
|
5360
|
-
|
|
5361
|
-
});
|
|
5230
|
+
for (const plugin of this.plugins) {
|
|
5231
|
+
plugin.remove?.(key, options);
|
|
5232
|
+
}
|
|
5362
5233
|
}
|
|
5363
5234
|
/**
|
|
5364
|
-
|
|
5365
|
-
|
|
5366
|
-
|
|
5367
|
-
|
|
5235
|
+
* Clears data in all plugins that implement `clear`.
|
|
5236
|
+
*
|
|
5237
|
+
* @override
|
|
5238
|
+
*/
|
|
5368
5239
|
clear() {
|
|
5369
|
-
this.
|
|
5370
|
-
|
|
5371
|
-
|
|
5372
|
-
});
|
|
5240
|
+
for (const plugin of this.plugins) {
|
|
5241
|
+
plugin.clear?.();
|
|
5242
|
+
}
|
|
5373
5243
|
}
|
|
5374
5244
|
};
|
|
5375
5245
|
export {
|
|
@@ -5404,15 +5274,20 @@ export {
|
|
|
5404
5274
|
ResponsePlugin,
|
|
5405
5275
|
RetryPlugin,
|
|
5406
5276
|
SimpleUrlBuilder,
|
|
5407
|
-
|
|
5277
|
+
StorageExecutor,
|
|
5408
5278
|
appendHeaders,
|
|
5409
5279
|
createAbortPromise,
|
|
5280
|
+
createStoragePlugin,
|
|
5281
|
+
createStoragePluginWithStorage,
|
|
5410
5282
|
hasObjectKey,
|
|
5411
5283
|
hasObjectKeyWithValue,
|
|
5412
5284
|
isAbortError,
|
|
5413
5285
|
isAbsoluteUrl,
|
|
5414
5286
|
isAsString,
|
|
5287
|
+
isEncryptor,
|
|
5415
5288
|
isRequestAdapterResponse,
|
|
5289
|
+
isSerializer,
|
|
5290
|
+
isStorage,
|
|
5416
5291
|
normalizeHookNames,
|
|
5417
5292
|
raceWithAbort,
|
|
5418
5293
|
runPluginHook,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qlover/fe-corekit",
|
|
3
3
|
"description": "A corekit for frontwork",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.2.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
@@ -20,6 +20,36 @@
|
|
|
20
20
|
"import": "./dist/index.js",
|
|
21
21
|
"browser": "./dist/index.iife.js",
|
|
22
22
|
"require": "./dist/index.cjs"
|
|
23
|
+
},
|
|
24
|
+
"./aborter": {
|
|
25
|
+
"types": "./dist/aborter/index.d.ts",
|
|
26
|
+
"import": "./dist/aborter/index.js",
|
|
27
|
+
"require": "./dist/aborter/index.cjs"
|
|
28
|
+
},
|
|
29
|
+
"./encrypt": {
|
|
30
|
+
"types": "./dist/encrypt/index.d.ts",
|
|
31
|
+
"import": "./dist/encrypt/index.js",
|
|
32
|
+
"require": "./dist/encrypt/index.cjs"
|
|
33
|
+
},
|
|
34
|
+
"./executor": {
|
|
35
|
+
"types": "./dist/executor/index.d.ts",
|
|
36
|
+
"import": "./dist/executor/index.js",
|
|
37
|
+
"require": "./dist/executor/index.cjs"
|
|
38
|
+
},
|
|
39
|
+
"./request": {
|
|
40
|
+
"types": "./dist/request/index.d.ts",
|
|
41
|
+
"import": "./dist/request/index.js",
|
|
42
|
+
"require": "./dist/request/index.cjs"
|
|
43
|
+
},
|
|
44
|
+
"./serializer": {
|
|
45
|
+
"types": "./dist/serializer/index.d.ts",
|
|
46
|
+
"import": "./dist/serializer/index.js",
|
|
47
|
+
"require": "./dist/serializer/index.cjs"
|
|
48
|
+
},
|
|
49
|
+
"./storage": {
|
|
50
|
+
"types": "./dist/storage/index.d.ts",
|
|
51
|
+
"import": "./dist/storage/index.js",
|
|
52
|
+
"require": "./dist/storage/index.cjs"
|
|
23
53
|
}
|
|
24
54
|
},
|
|
25
55
|
"repository": {
|