@qlover/fe-corekit 1.2.2 → 1.2.5
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.es.js +7421 -1
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +7446 -1
- package/dist/index.umd.js.map +1 -0
- package/dist/interface/index.es.js +269 -1
- package/dist/interface/index.es.js.map +1 -0
- package/dist/interface/index.umd.js +279 -1
- package/dist/interface/index.umd.js.map +1 -0
- package/dist/server/index.cjs.js +170 -1
- package/dist/server/index.cjs.js.map +1 -0
- package/dist/server/index.es.js +167 -1
- package/dist/server/index.es.js.map +1 -0
- package/package.json +2 -2
|
@@ -1 +1,269 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Base executor class providing plugin management and execution pipeline
|
|
3
|
+
*
|
|
4
|
+
* The Executor pattern implements a pluggable execution pipeline that allows:
|
|
5
|
+
* 1. Pre-processing of input data
|
|
6
|
+
* 2. Post-processing of results
|
|
7
|
+
* 3. Error handling
|
|
8
|
+
* 4. Custom execution logic
|
|
9
|
+
*
|
|
10
|
+
* execNoError returns all errors as they are., and if there is a plugin onerror handler chain in which an error occurs, it will also return the error instead of throwing it.
|
|
11
|
+
*
|
|
12
|
+
* @abstract
|
|
13
|
+
* @class Executor
|
|
14
|
+
* @category Executor
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* // Create an executor instance
|
|
18
|
+
* const executor = new AsyncExecutor();
|
|
19
|
+
*
|
|
20
|
+
* // Add plugins
|
|
21
|
+
* executor.use(new LoggerPlugin());
|
|
22
|
+
* executor.use(new RetryPlugin({ maxAttempts: 3 }));
|
|
23
|
+
*
|
|
24
|
+
* // Execute a task
|
|
25
|
+
* const result = await executor.exec(async (data) => {
|
|
26
|
+
* return await someAsyncOperation(data);
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
var Executor = /** @class */ (function () {
|
|
31
|
+
/**
|
|
32
|
+
* Creates a new Executor instance
|
|
33
|
+
*
|
|
34
|
+
* - Purpose: Initialize executor with optional configuration
|
|
35
|
+
* - Core Concept: Configurable executor setup
|
|
36
|
+
* - Main Features: Configuration injection
|
|
37
|
+
* - Primary Use: Executor instantiation
|
|
38
|
+
*
|
|
39
|
+
* @param {ExecutorConfig} config - Optional configuration object
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const executor = new Executor({
|
|
44
|
+
* // config options
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
function Executor(config) {
|
|
49
|
+
this.config = config;
|
|
50
|
+
/**
|
|
51
|
+
* Array of active plugins
|
|
52
|
+
*
|
|
53
|
+
* - Purpose: Stores and manages executor plugins
|
|
54
|
+
* - Core Concept: Ordered plugin pipeline
|
|
55
|
+
* - Main Features:
|
|
56
|
+
* - Maintains plugin execution order
|
|
57
|
+
* - Supports plugin lifecycle management
|
|
58
|
+
* - Primary Use: Plugin orchestration and execution
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* protected plugins = [
|
|
63
|
+
* new LoggerPlugin(),
|
|
64
|
+
* new RetryPlugin()
|
|
65
|
+
* ];
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
this.plugins = [];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Add a plugin to the executor
|
|
72
|
+
*
|
|
73
|
+
* - Purpose: Extends executor functionality through plugins
|
|
74
|
+
* - Core Concept: Plugin registration and deduplication
|
|
75
|
+
* - Main Features:
|
|
76
|
+
* - Prevents duplicate plugins if onlyOne is true
|
|
77
|
+
* - Maintains plugin execution order
|
|
78
|
+
* - Primary Use: Adding new capabilities to executor
|
|
79
|
+
*
|
|
80
|
+
* @param plugin - Plugin instance to add
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* executor.use(new LoggerPlugin());
|
|
85
|
+
* executor.use(new RetryPlugin({ maxAttempts: 3 }));
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
*
|
|
90
|
+
* Use a plain object as a plugin
|
|
91
|
+
* ```typescript
|
|
92
|
+
* executor.use({
|
|
93
|
+
* onBefore: (data) => ({ ...data, modified: true })
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
Executor.prototype.use = function (plugin) {
|
|
98
|
+
if (this.plugins.find(function (p) {
|
|
99
|
+
return p === plugin ||
|
|
100
|
+
p.pluginName === plugin.pluginName ||
|
|
101
|
+
p.constructor === plugin.constructor;
|
|
102
|
+
}) &&
|
|
103
|
+
plugin.onlyOne) {
|
|
104
|
+
console.warn("Plugin ".concat(plugin.pluginName, " is already used, skip adding"));
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
this.plugins.push(plugin);
|
|
108
|
+
};
|
|
109
|
+
return Executor;
|
|
110
|
+
}());
|
|
111
|
+
|
|
112
|
+
/******************************************************************************
|
|
113
|
+
Copyright (c) Microsoft Corporation.
|
|
114
|
+
|
|
115
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
116
|
+
purpose with or without fee is hereby granted.
|
|
117
|
+
|
|
118
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
119
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
120
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
121
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
122
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
123
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
124
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
125
|
+
***************************************************************************** */
|
|
126
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
127
|
+
|
|
128
|
+
var extendStatics = function(d, b) {
|
|
129
|
+
extendStatics = Object.setPrototypeOf ||
|
|
130
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
131
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
132
|
+
return extendStatics(d, b);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
function __extends(d, b) {
|
|
136
|
+
if (typeof b !== "function" && b !== null)
|
|
137
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
138
|
+
extendStatics(d, b);
|
|
139
|
+
function __() { this.constructor = d; }
|
|
140
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
144
|
+
var e = new Error(message);
|
|
145
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Custom error class for executor operations.
|
|
150
|
+
*
|
|
151
|
+
* This class provides a structured way to handle errors that occur during executor operations.
|
|
152
|
+
* It extends the standard Error class to include an error identification string, which can be used
|
|
153
|
+
* to categorize and manage errors more effectively.
|
|
154
|
+
*
|
|
155
|
+
* @category Executor
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* try {
|
|
160
|
+
* // some executor operation
|
|
161
|
+
* } catch (error) {
|
|
162
|
+
* throw new ExecutorError('EXECUTOR_ERROR', error);
|
|
163
|
+
* }
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
*
|
|
168
|
+
* create an error with a message from a string
|
|
169
|
+
*
|
|
170
|
+
* ```typescript
|
|
171
|
+
* const error = new ExecutorError('ERROR_ID', 'This is an error message');
|
|
172
|
+
*
|
|
173
|
+
* // => error.message is 'This is an error message'
|
|
174
|
+
* // => error.id is 'ERROR_ID'
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
var ExecutorError = /** @class */ (function (_super) {
|
|
178
|
+
__extends(ExecutorError, _super);
|
|
179
|
+
/**
|
|
180
|
+
* Constructs a new ExecutorError.
|
|
181
|
+
*
|
|
182
|
+
* if originalError is a string, it will be used as the error message.
|
|
183
|
+
* if originalError is an Error object, its message will be used as the error message.
|
|
184
|
+
* if originalError is not provided, the error message will be the id.
|
|
185
|
+
*
|
|
186
|
+
* @param id - A unique identifier for the error, used for categorization and tracking.
|
|
187
|
+
* @param originalError - The original error message or Error object that triggered this error.
|
|
188
|
+
* This parameter is optional.
|
|
189
|
+
*/
|
|
190
|
+
function ExecutorError(id, originalError) {
|
|
191
|
+
var _newTarget = this.constructor;
|
|
192
|
+
var _this = _super.call(this, originalError instanceof Error
|
|
193
|
+
? originalError.message
|
|
194
|
+
: originalError || id) || this;
|
|
195
|
+
_this.id = id;
|
|
196
|
+
// if originalError is an Error object, use its stack
|
|
197
|
+
if (originalError instanceof Error && 'stack' in originalError) {
|
|
198
|
+
_this.stack = originalError.stack;
|
|
199
|
+
}
|
|
200
|
+
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
201
|
+
return _this;
|
|
202
|
+
}
|
|
203
|
+
return ExecutorError;
|
|
204
|
+
}(Error));
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Represents a custom error class for handling request-related errors in the application
|
|
208
|
+
*
|
|
209
|
+
* RequestError extends the base ExecutorError class to provide specific error handling
|
|
210
|
+
* for HTTP requests and fetch operations. It works in conjunction with RequestErrorID
|
|
211
|
+
* to categorize different types of request failures.
|
|
212
|
+
*
|
|
213
|
+
* @since 1.0.14
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```typescript
|
|
217
|
+
* try {
|
|
218
|
+
* await fetchData(url);
|
|
219
|
+
* } catch (error) {
|
|
220
|
+
* if (error instanceof RequestError) {
|
|
221
|
+
* // Handle request specific error
|
|
222
|
+
* console.error('Request failed:', error.message);
|
|
223
|
+
* }
|
|
224
|
+
* }
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
var RequestError = /** @class */ (function (_super) {
|
|
228
|
+
__extends(RequestError, _super);
|
|
229
|
+
function RequestError() {
|
|
230
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
231
|
+
}
|
|
232
|
+
return RequestError;
|
|
233
|
+
}(ExecutorError));
|
|
234
|
+
/**
|
|
235
|
+
* Error IDs for different fetch request failure scenarios
|
|
236
|
+
* Used to identify specific error types in error handling
|
|
237
|
+
*
|
|
238
|
+
* @description
|
|
239
|
+
* This enum provides a standardized set of error identifiers that can be used
|
|
240
|
+
* to categorize and handle different types of request failures in a consistent manner.
|
|
241
|
+
* Each error ID represents a specific failure scenario that might occur during HTTP requests.
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```typescript
|
|
245
|
+
* if (error.id === RequestErrorID.RESPONSE_NOT_OK) {
|
|
246
|
+
* // Handle non-200 response
|
|
247
|
+
* } else if (error.id === RequestErrorID.ABORT_ERROR) {
|
|
248
|
+
* // Handle aborted request
|
|
249
|
+
* }
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
var RequestErrorID;
|
|
253
|
+
(function (RequestErrorID) {
|
|
254
|
+
/** Generic fetch request error */
|
|
255
|
+
RequestErrorID["REQUEST_ERROR"] = "REQUEST_ERROR";
|
|
256
|
+
/** Environment doesn't support fetch API */
|
|
257
|
+
RequestErrorID["ENV_FETCH_NOT_SUPPORT"] = "ENV_FETCH_NOT_SUPPORT";
|
|
258
|
+
/** No fetcher function provided */
|
|
259
|
+
RequestErrorID["FETCHER_NONE"] = "FETCHER_NONE";
|
|
260
|
+
/** Response status is not OK (not in 200-299 range) */
|
|
261
|
+
RequestErrorID["RESPONSE_NOT_OK"] = "RESPONSE_NOT_OK";
|
|
262
|
+
/** Request was aborted */
|
|
263
|
+
RequestErrorID["ABORT_ERROR"] = "ABORT_ERROR";
|
|
264
|
+
/** URL is not provided */
|
|
265
|
+
RequestErrorID["URL_NONE"] = "URL_NONE";
|
|
266
|
+
})(RequestErrorID || (RequestErrorID = {}));
|
|
267
|
+
|
|
268
|
+
export { Executor, ExecutorError, RequestError, RequestErrorID };
|
|
269
|
+
//# sourceMappingURL=index.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../../interface/executor/Executor.ts","../../interface/executor/ExecutorError.ts","../../interface/request/RequestError.ts"],"sourcesContent":["import { ExecutorError } from './ExecutorError';\nimport { ExecutorPlugin, Task } from './ExecutorPlugin';\n\n/**\n * Base executor class providing plugin management and execution pipeline\n *\n * The Executor pattern implements a pluggable execution pipeline that allows:\n * 1. Pre-processing of input data\n * 2. Post-processing of results\n * 3. Error handling\n * 4. Custom execution logic\n *\n * execNoError returns all errors as they are., and if there is a plugin onerror handler chain in which an error occurs, it will also return the error instead of throwing it.\n *\n * @abstract\n * @class Executor\n * @category Executor\n * @example\n * ```typescript\n * // Create an executor instance\n * const executor = new AsyncExecutor();\n *\n * // Add plugins\n * executor.use(new LoggerPlugin());\n * executor.use(new RetryPlugin({ maxAttempts: 3 }));\n *\n * // Execute a task\n * const result = await executor.exec(async (data) => {\n * return await someAsyncOperation(data);\n * });\n * ```\n */\nexport abstract class Executor<ExecutorConfig = unknown> {\n /**\n * Array of active plugins\n *\n * - Purpose: Stores and manages executor plugins\n * - Core Concept: Ordered plugin pipeline\n * - Main Features:\n * - Maintains plugin execution order\n * - Supports plugin lifecycle management\n * - Primary Use: Plugin orchestration and execution\n *\n * @example\n * ```typescript\n * protected plugins = [\n * new LoggerPlugin(),\n * new RetryPlugin()\n * ];\n * ```\n */\n protected plugins: ExecutorPlugin[] = [];\n\n /**\n * Creates a new Executor instance\n *\n * - Purpose: Initialize executor with optional configuration\n * - Core Concept: Configurable executor setup\n * - Main Features: Configuration injection\n * - Primary Use: Executor instantiation\n *\n * @param {ExecutorConfig} config - Optional configuration object\n *\n * @example\n * ```typescript\n * const executor = new Executor({\n * // config options\n * });\n * ```\n */\n constructor(protected config?: ExecutorConfig) {}\n\n /**\n * Add a plugin to the executor\n *\n * - Purpose: Extends executor functionality through plugins\n * - Core Concept: Plugin registration and deduplication\n * - Main Features:\n * - Prevents duplicate plugins if onlyOne is true\n * - Maintains plugin execution order\n * - Primary Use: Adding new capabilities to executor\n *\n * @param plugin - Plugin instance to add\n *\n * @example\n * ```typescript\n * executor.use(new LoggerPlugin());\n * executor.use(new RetryPlugin({ maxAttempts: 3 }));\n * ```\n *\n * @example\n *\n * Use a plain object as a plugin\n * ```typescript\n * executor.use({\n * onBefore: (data) => ({ ...data, modified: true })\n * });\n * ```\n */\n use(plugin: ExecutorPlugin): void {\n if (\n this.plugins.find(\n (p) =>\n p === plugin ||\n p.pluginName === plugin.pluginName ||\n p.constructor === plugin.constructor\n ) &&\n plugin.onlyOne\n ) {\n console.warn(`Plugin ${plugin.pluginName} is already used, skip adding`);\n return;\n }\n\n this.plugins.push(plugin);\n }\n\n /**\n * Execute a plugin hook\n *\n * - Purpose: Provides plugin hook execution mechanism\n * - Core Concept: Plugin lifecycle management\n * - Main Features:\n * - Dynamic hook execution\n * - Support for async and sync hooks\n * - Primary Use: Running plugin lifecycle methods\n *\n * @param plugins - Plugins to execute\n * @param name - Hook name to execute\n * @param args - Arguments for the hook\n *\n * @example\n * ```typescript\n * await executor.runHook(plugins, 'beforeExec', data);\n * ```\n */\n abstract runHooks(\n plugins: ExecutorPlugin[],\n name: keyof ExecutorPlugin,\n ...args: unknown[]\n ): void | unknown | Promise<void | unknown>;\n\n /**\n * Execute a task with plugin pipeline\n *\n * - Purpose: Core task execution with plugin support\n * - Core Concept: Task execution pipeline\n * - Main Features:\n * - Plugin hook integration\n * - Error handling\n * - Primary Use: Running tasks through the executor pipeline\n *\n * @param task - Task to execute\n * @param data - Optional input data for task\n * @throws {ExecutorError} If task execution fails\n *\n * @example\n * ```typescript\n * const result = await executor.exec(async (data) => {\n * return await processData(data);\n * });\n * ```\n */\n abstract exec<Result, Params = unknown>(\n task: Task<Result, Params>\n ): Promise<Result> | Result;\n\n /**\n * Execute a task with plugin pipeline and input data\n *\n * - Purpose: Core task execution with plugin support and input data\n * - Core Concept: Task execution pipeline with data\n * - Main Features:\n * - Plugin hook integration\n * - Error handling\n * - Primary Use: Running tasks with input data through the executor pipeline\n *\n * @param data - Input data for task\n * @param task - Task to execute\n * @throws {ExecutorError} If task execution fails\n *\n * @example\n * ```typescript\n * const result = await executor.exec(data, async (data) => {\n * return await processData(data);\n * });\n * ```\n */\n abstract exec<Result, Params = unknown>(\n data: unknown,\n task: Task<Result, Params>\n ): Promise<Result> | Result;\n\n /**\n * Execute a task without throwing errors\n *\n * - Purpose: Safe task execution with error wrapping\n * - Core Concept: Error-safe execution pipeline\n * - Main Features:\n * - Error wrapping in ExecutorError\n * - Non-throwing execution\n * - Primary Use: When error handling is preferred over exceptions\n *\n * @param task - Task to execute\n *\n * @example\n * ```typescript\n * const result = await executor.execNoError(async (data) => {\n * return await riskyOperation(data);\n * });\n * if (result instanceof ExecutorError) {\n * console.error('Task failed:', result);\n * }\n * ```\n */\n abstract execNoError<Result, Params = unknown>(\n task: Task<Result, Params>\n ): Promise<Result | ExecutorError> | Result | ExecutorError;\n\n /**\n * Execute a task with input data without throwing errors\n *\n * - Purpose: Safe task execution with error wrapping and input data\n * - Core Concept: Error-safe execution pipeline with data\n * - Main Features:\n * - Error wrapping in ExecutorError\n * - Non-throwing execution\n * - Primary Use: When error handling is preferred over exceptions with input data\n *\n * @param data - Input data for task\n * @param task - Task to execute\n *\n * @example\n * ```typescript\n * const result = await executor.execNoError(data, async (data) => {\n * return await riskyOperation(data);\n * });\n * if (result instanceof ExecutorError) {\n * console.error('Task failed:', result);\n * }\n * ```\n */\n abstract execNoError<Result, Params = unknown>(\n data: unknown,\n task: Task<Result, Params>\n ): Promise<Result | ExecutorError> | Result | ExecutorError;\n}\n","/**\n * Custom error class for executor operations.\n *\n * This class provides a structured way to handle errors that occur during executor operations.\n * It extends the standard Error class to include an error identification string, which can be used\n * to categorize and manage errors more effectively.\n *\n * @category Executor\n *\n * @example\n * ```typescript\n * try {\n * // some executor operation\n * } catch (error) {\n * throw new ExecutorError('EXECUTOR_ERROR', error);\n * }\n * ```\n *\n * @example\n *\n * create an error with a message from a string\n *\n * ```typescript\n * const error = new ExecutorError('ERROR_ID', 'This is an error message');\n *\n * // => error.message is 'This is an error message'\n * // => error.id is 'ERROR_ID'\n * ```\n */\nexport class ExecutorError extends Error {\n /**\n * Constructs a new ExecutorError.\n *\n * if originalError is a string, it will be used as the error message.\n * if originalError is an Error object, its message will be used as the error message.\n * if originalError is not provided, the error message will be the id.\n *\n * @param id - A unique identifier for the error, used for categorization and tracking.\n * @param originalError - The original error message or Error object that triggered this error.\n * This parameter is optional.\n */\n constructor(\n public id: string,\n originalError?: string | Error\n ) {\n super(\n originalError instanceof Error\n ? originalError.message\n : originalError || id\n );\n\n // if originalError is an Error object, use its stack\n if (originalError instanceof Error && 'stack' in originalError) {\n this.stack = originalError.stack;\n }\n\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n","import { ExecutorError } from '../executor';\n\n/**\n * Represents a custom error class for handling request-related errors in the application\n *\n * RequestError extends the base ExecutorError class to provide specific error handling\n * for HTTP requests and fetch operations. It works in conjunction with RequestErrorID\n * to categorize different types of request failures.\n *\n * @since 1.0.14\n *\n * @example\n * ```typescript\n * try {\n * await fetchData(url);\n * } catch (error) {\n * if (error instanceof RequestError) {\n * // Handle request specific error\n * console.error('Request failed:', error.message);\n * }\n * }\n * ```\n */\nexport class RequestError extends ExecutorError {}\n\n/**\n * Error IDs for different fetch request failure scenarios\n * Used to identify specific error types in error handling\n *\n * @description\n * This enum provides a standardized set of error identifiers that can be used\n * to categorize and handle different types of request failures in a consistent manner.\n * Each error ID represents a specific failure scenario that might occur during HTTP requests.\n *\n * @example\n * ```typescript\n * if (error.id === RequestErrorID.RESPONSE_NOT_OK) {\n * // Handle non-200 response\n * } else if (error.id === RequestErrorID.ABORT_ERROR) {\n * // Handle aborted request\n * }\n * ```\n */\nexport enum RequestErrorID {\n /** Generic fetch request error */\n REQUEST_ERROR = 'REQUEST_ERROR',\n /** Environment doesn't support fetch API */\n ENV_FETCH_NOT_SUPPORT = 'ENV_FETCH_NOT_SUPPORT',\n /** No fetcher function provided */\n FETCHER_NONE = 'FETCHER_NONE',\n /** Response status is not OK (not in 200-299 range) */\n RESPONSE_NOT_OK = 'RESPONSE_NOT_OK',\n /** Request was aborted */\n ABORT_ERROR = 'ABORT_ERROR',\n /** URL is not provided */\n URL_NONE = 'URL_NONE'\n}\n"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BG;AACH,IAAA,QAAA,kBAAA,YAAA;AAqBE;;;;;;;;;;;;;;;;AAgBG;AACH,IAAA,SAAA,QAAA,CAAsB,MAAuB,EAAA;QAAvB,IAAM,CAAA,MAAA,GAAN,MAAM;AArC5B;;;;;;;;;;;;;;;;;AAiBG;QACO,IAAO,CAAA,OAAA,GAAqB,EAAE;;AAqBxC;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BG;IACH,QAAG,CAAA,SAAA,CAAA,GAAA,GAAH,UAAI,MAAsB,EAAA;AACxB,QAAA,IACE,IAAI,CAAC,OAAO,CAAC,IAAI,CACf,UAAC,CAAC,EAAA;YACA,OAAA,CAAC,KAAK,MAAM;AACZ,gBAAA,CAAC,CAAC,UAAU,KAAK,MAAM,CAAC,UAAU;AAClC,gBAAA,CAAC,CAAC,WAAW,KAAK,MAAM,CAAC,WAAW;AAFpC,SAEoC,CACvC;YACD,MAAM,CAAC,OAAO,EACd;YACA,OAAO,CAAC,IAAI,CAAC,SAAA,CAAA,MAAA,CAAU,MAAM,CAAC,UAAU,EAA+B,+BAAA,CAAA,CAAC;YACxE;;AAGF,QAAA,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;KAC1B;IAmIH,OAAC,QAAA;AAAD,CAAC,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACrPD;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BG;AACH,IAAA,aAAA,kBAAA,UAAA,MAAA,EAAA;IAAmC,SAAK,CAAA,aAAA,EAAA,MAAA,CAAA;AACtC;;;;;;;;;;AAUG;IACH,SACS,aAAA,CAAA,EAAU,EACjB,aAA8B,EAAA;;AAE9B,QAAA,IAAA,KAAA,GAAA,MAAK,CAAA,IAAA,CAAA,IAAA,EACH,aAAa,YAAY;cACrB,aAAa,CAAC;AAChB,cAAE,aAAa,IAAI,EAAE,CACxB,IAAC,IAAA;QAPK,KAAE,CAAA,EAAA,GAAF,EAAE;;QAUT,IAAI,aAAa,YAAY,KAAK,IAAI,OAAO,IAAI,aAAa,EAAE;AAC9D,YAAA,KAAI,CAAC,KAAK,GAAG,aAAa,CAAC,KAAK;;QAGlC,MAAM,CAAC,cAAc,CAAC,KAAI,EAAE,UAAW,CAAA,SAAS,CAAC;;;IAErD,OAAC,aAAA;AAAD,CA7BA,CAAmC,KAAK,CA6BvC;;ACxDD;;;;;;;;;;;;;;;;;;;;AAoBG;AACH,IAAA,YAAA,kBAAA,UAAA,MAAA,EAAA;IAAkC,SAAa,CAAA,YAAA,EAAA,MAAA,CAAA;AAA/C,IAAA,SAAA,YAAA,GAAA;;;IAAiD,OAAC,YAAA;AAAD,CAAjD,CAAkC,aAAa,CAAG;AAElD;;;;;;;;;;;;;;;;;AAiBG;IACS;AAAZ,CAAA,UAAY,cAAc,EAAA;;AAExB,IAAA,cAAA,CAAA,eAAA,CAAA,GAAA,eAA+B;;AAE/B,IAAA,cAAA,CAAA,uBAAA,CAAA,GAAA,uBAA+C;;AAE/C,IAAA,cAAA,CAAA,cAAA,CAAA,GAAA,cAA6B;;AAE7B,IAAA,cAAA,CAAA,iBAAA,CAAA,GAAA,iBAAmC;;AAEnC,IAAA,cAAA,CAAA,aAAA,CAAA,GAAA,aAA2B;;AAE3B,IAAA,cAAA,CAAA,UAAA,CAAA,GAAA,UAAqB;AACvB,CAAC,EAbW,cAAc,KAAd,cAAc,GAazB,EAAA,CAAA,CAAA;;;;"}
|
|
@@ -1 +1,279 @@
|
|
|
1
|
-
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.FeUtilsInterface = {}));
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Base executor class providing plugin management and execution pipeline
|
|
9
|
+
*
|
|
10
|
+
* The Executor pattern implements a pluggable execution pipeline that allows:
|
|
11
|
+
* 1. Pre-processing of input data
|
|
12
|
+
* 2. Post-processing of results
|
|
13
|
+
* 3. Error handling
|
|
14
|
+
* 4. Custom execution logic
|
|
15
|
+
*
|
|
16
|
+
* execNoError returns all errors as they are., and if there is a plugin onerror handler chain in which an error occurs, it will also return the error instead of throwing it.
|
|
17
|
+
*
|
|
18
|
+
* @abstract
|
|
19
|
+
* @class Executor
|
|
20
|
+
* @category Executor
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* // Create an executor instance
|
|
24
|
+
* const executor = new AsyncExecutor();
|
|
25
|
+
*
|
|
26
|
+
* // Add plugins
|
|
27
|
+
* executor.use(new LoggerPlugin());
|
|
28
|
+
* executor.use(new RetryPlugin({ maxAttempts: 3 }));
|
|
29
|
+
*
|
|
30
|
+
* // Execute a task
|
|
31
|
+
* const result = await executor.exec(async (data) => {
|
|
32
|
+
* return await someAsyncOperation(data);
|
|
33
|
+
* });
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
var Executor = /** @class */ (function () {
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new Executor instance
|
|
39
|
+
*
|
|
40
|
+
* - Purpose: Initialize executor with optional configuration
|
|
41
|
+
* - Core Concept: Configurable executor setup
|
|
42
|
+
* - Main Features: Configuration injection
|
|
43
|
+
* - Primary Use: Executor instantiation
|
|
44
|
+
*
|
|
45
|
+
* @param {ExecutorConfig} config - Optional configuration object
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const executor = new Executor({
|
|
50
|
+
* // config options
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
function Executor(config) {
|
|
55
|
+
this.config = config;
|
|
56
|
+
/**
|
|
57
|
+
* Array of active plugins
|
|
58
|
+
*
|
|
59
|
+
* - Purpose: Stores and manages executor plugins
|
|
60
|
+
* - Core Concept: Ordered plugin pipeline
|
|
61
|
+
* - Main Features:
|
|
62
|
+
* - Maintains plugin execution order
|
|
63
|
+
* - Supports plugin lifecycle management
|
|
64
|
+
* - Primary Use: Plugin orchestration and execution
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* protected plugins = [
|
|
69
|
+
* new LoggerPlugin(),
|
|
70
|
+
* new RetryPlugin()
|
|
71
|
+
* ];
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
this.plugins = [];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Add a plugin to the executor
|
|
78
|
+
*
|
|
79
|
+
* - Purpose: Extends executor functionality through plugins
|
|
80
|
+
* - Core Concept: Plugin registration and deduplication
|
|
81
|
+
* - Main Features:
|
|
82
|
+
* - Prevents duplicate plugins if onlyOne is true
|
|
83
|
+
* - Maintains plugin execution order
|
|
84
|
+
* - Primary Use: Adding new capabilities to executor
|
|
85
|
+
*
|
|
86
|
+
* @param plugin - Plugin instance to add
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* executor.use(new LoggerPlugin());
|
|
91
|
+
* executor.use(new RetryPlugin({ maxAttempts: 3 }));
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
*
|
|
96
|
+
* Use a plain object as a plugin
|
|
97
|
+
* ```typescript
|
|
98
|
+
* executor.use({
|
|
99
|
+
* onBefore: (data) => ({ ...data, modified: true })
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
Executor.prototype.use = function (plugin) {
|
|
104
|
+
if (this.plugins.find(function (p) {
|
|
105
|
+
return p === plugin ||
|
|
106
|
+
p.pluginName === plugin.pluginName ||
|
|
107
|
+
p.constructor === plugin.constructor;
|
|
108
|
+
}) &&
|
|
109
|
+
plugin.onlyOne) {
|
|
110
|
+
console.warn("Plugin ".concat(plugin.pluginName, " is already used, skip adding"));
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
this.plugins.push(plugin);
|
|
114
|
+
};
|
|
115
|
+
return Executor;
|
|
116
|
+
}());
|
|
117
|
+
|
|
118
|
+
/******************************************************************************
|
|
119
|
+
Copyright (c) Microsoft Corporation.
|
|
120
|
+
|
|
121
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
122
|
+
purpose with or without fee is hereby granted.
|
|
123
|
+
|
|
124
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
125
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
126
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
127
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
128
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
129
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
130
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
131
|
+
***************************************************************************** */
|
|
132
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
133
|
+
|
|
134
|
+
var extendStatics = function(d, b) {
|
|
135
|
+
extendStatics = Object.setPrototypeOf ||
|
|
136
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
137
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
138
|
+
return extendStatics(d, b);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
function __extends(d, b) {
|
|
142
|
+
if (typeof b !== "function" && b !== null)
|
|
143
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
144
|
+
extendStatics(d, b);
|
|
145
|
+
function __() { this.constructor = d; }
|
|
146
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
150
|
+
var e = new Error(message);
|
|
151
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Custom error class for executor operations.
|
|
156
|
+
*
|
|
157
|
+
* This class provides a structured way to handle errors that occur during executor operations.
|
|
158
|
+
* It extends the standard Error class to include an error identification string, which can be used
|
|
159
|
+
* to categorize and manage errors more effectively.
|
|
160
|
+
*
|
|
161
|
+
* @category Executor
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```typescript
|
|
165
|
+
* try {
|
|
166
|
+
* // some executor operation
|
|
167
|
+
* } catch (error) {
|
|
168
|
+
* throw new ExecutorError('EXECUTOR_ERROR', error);
|
|
169
|
+
* }
|
|
170
|
+
* ```
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
*
|
|
174
|
+
* create an error with a message from a string
|
|
175
|
+
*
|
|
176
|
+
* ```typescript
|
|
177
|
+
* const error = new ExecutorError('ERROR_ID', 'This is an error message');
|
|
178
|
+
*
|
|
179
|
+
* // => error.message is 'This is an error message'
|
|
180
|
+
* // => error.id is 'ERROR_ID'
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
var ExecutorError = /** @class */ (function (_super) {
|
|
184
|
+
__extends(ExecutorError, _super);
|
|
185
|
+
/**
|
|
186
|
+
* Constructs a new ExecutorError.
|
|
187
|
+
*
|
|
188
|
+
* if originalError is a string, it will be used as the error message.
|
|
189
|
+
* if originalError is an Error object, its message will be used as the error message.
|
|
190
|
+
* if originalError is not provided, the error message will be the id.
|
|
191
|
+
*
|
|
192
|
+
* @param id - A unique identifier for the error, used for categorization and tracking.
|
|
193
|
+
* @param originalError - The original error message or Error object that triggered this error.
|
|
194
|
+
* This parameter is optional.
|
|
195
|
+
*/
|
|
196
|
+
function ExecutorError(id, originalError) {
|
|
197
|
+
var _newTarget = this.constructor;
|
|
198
|
+
var _this = _super.call(this, originalError instanceof Error
|
|
199
|
+
? originalError.message
|
|
200
|
+
: originalError || id) || this;
|
|
201
|
+
_this.id = id;
|
|
202
|
+
// if originalError is an Error object, use its stack
|
|
203
|
+
if (originalError instanceof Error && 'stack' in originalError) {
|
|
204
|
+
_this.stack = originalError.stack;
|
|
205
|
+
}
|
|
206
|
+
Object.setPrototypeOf(_this, _newTarget.prototype);
|
|
207
|
+
return _this;
|
|
208
|
+
}
|
|
209
|
+
return ExecutorError;
|
|
210
|
+
}(Error));
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Represents a custom error class for handling request-related errors in the application
|
|
214
|
+
*
|
|
215
|
+
* RequestError extends the base ExecutorError class to provide specific error handling
|
|
216
|
+
* for HTTP requests and fetch operations. It works in conjunction with RequestErrorID
|
|
217
|
+
* to categorize different types of request failures.
|
|
218
|
+
*
|
|
219
|
+
* @since 1.0.14
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* try {
|
|
224
|
+
* await fetchData(url);
|
|
225
|
+
* } catch (error) {
|
|
226
|
+
* if (error instanceof RequestError) {
|
|
227
|
+
* // Handle request specific error
|
|
228
|
+
* console.error('Request failed:', error.message);
|
|
229
|
+
* }
|
|
230
|
+
* }
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
var RequestError = /** @class */ (function (_super) {
|
|
234
|
+
__extends(RequestError, _super);
|
|
235
|
+
function RequestError() {
|
|
236
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
237
|
+
}
|
|
238
|
+
return RequestError;
|
|
239
|
+
}(ExecutorError));
|
|
240
|
+
/**
|
|
241
|
+
* Error IDs for different fetch request failure scenarios
|
|
242
|
+
* Used to identify specific error types in error handling
|
|
243
|
+
*
|
|
244
|
+
* @description
|
|
245
|
+
* This enum provides a standardized set of error identifiers that can be used
|
|
246
|
+
* to categorize and handle different types of request failures in a consistent manner.
|
|
247
|
+
* Each error ID represents a specific failure scenario that might occur during HTTP requests.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```typescript
|
|
251
|
+
* if (error.id === RequestErrorID.RESPONSE_NOT_OK) {
|
|
252
|
+
* // Handle non-200 response
|
|
253
|
+
* } else if (error.id === RequestErrorID.ABORT_ERROR) {
|
|
254
|
+
* // Handle aborted request
|
|
255
|
+
* }
|
|
256
|
+
* ```
|
|
257
|
+
*/
|
|
258
|
+
exports.RequestErrorID = void 0;
|
|
259
|
+
(function (RequestErrorID) {
|
|
260
|
+
/** Generic fetch request error */
|
|
261
|
+
RequestErrorID["REQUEST_ERROR"] = "REQUEST_ERROR";
|
|
262
|
+
/** Environment doesn't support fetch API */
|
|
263
|
+
RequestErrorID["ENV_FETCH_NOT_SUPPORT"] = "ENV_FETCH_NOT_SUPPORT";
|
|
264
|
+
/** No fetcher function provided */
|
|
265
|
+
RequestErrorID["FETCHER_NONE"] = "FETCHER_NONE";
|
|
266
|
+
/** Response status is not OK (not in 200-299 range) */
|
|
267
|
+
RequestErrorID["RESPONSE_NOT_OK"] = "RESPONSE_NOT_OK";
|
|
268
|
+
/** Request was aborted */
|
|
269
|
+
RequestErrorID["ABORT_ERROR"] = "ABORT_ERROR";
|
|
270
|
+
/** URL is not provided */
|
|
271
|
+
RequestErrorID["URL_NONE"] = "URL_NONE";
|
|
272
|
+
})(exports.RequestErrorID || (exports.RequestErrorID = {}));
|
|
273
|
+
|
|
274
|
+
exports.Executor = Executor;
|
|
275
|
+
exports.ExecutorError = ExecutorError;
|
|
276
|
+
exports.RequestError = RequestError;
|
|
277
|
+
|
|
278
|
+
}));
|
|
279
|
+
//# sourceMappingURL=index.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../../interface/executor/Executor.ts","../../interface/executor/ExecutorError.ts","../../interface/request/RequestError.ts"],"sourcesContent":["import { ExecutorError } from './ExecutorError';\nimport { ExecutorPlugin, Task } from './ExecutorPlugin';\n\n/**\n * Base executor class providing plugin management and execution pipeline\n *\n * The Executor pattern implements a pluggable execution pipeline that allows:\n * 1. Pre-processing of input data\n * 2. Post-processing of results\n * 3. Error handling\n * 4. Custom execution logic\n *\n * execNoError returns all errors as they are., and if there is a plugin onerror handler chain in which an error occurs, it will also return the error instead of throwing it.\n *\n * @abstract\n * @class Executor\n * @category Executor\n * @example\n * ```typescript\n * // Create an executor instance\n * const executor = new AsyncExecutor();\n *\n * // Add plugins\n * executor.use(new LoggerPlugin());\n * executor.use(new RetryPlugin({ maxAttempts: 3 }));\n *\n * // Execute a task\n * const result = await executor.exec(async (data) => {\n * return await someAsyncOperation(data);\n * });\n * ```\n */\nexport abstract class Executor<ExecutorConfig = unknown> {\n /**\n * Array of active plugins\n *\n * - Purpose: Stores and manages executor plugins\n * - Core Concept: Ordered plugin pipeline\n * - Main Features:\n * - Maintains plugin execution order\n * - Supports plugin lifecycle management\n * - Primary Use: Plugin orchestration and execution\n *\n * @example\n * ```typescript\n * protected plugins = [\n * new LoggerPlugin(),\n * new RetryPlugin()\n * ];\n * ```\n */\n protected plugins: ExecutorPlugin[] = [];\n\n /**\n * Creates a new Executor instance\n *\n * - Purpose: Initialize executor with optional configuration\n * - Core Concept: Configurable executor setup\n * - Main Features: Configuration injection\n * - Primary Use: Executor instantiation\n *\n * @param {ExecutorConfig} config - Optional configuration object\n *\n * @example\n * ```typescript\n * const executor = new Executor({\n * // config options\n * });\n * ```\n */\n constructor(protected config?: ExecutorConfig) {}\n\n /**\n * Add a plugin to the executor\n *\n * - Purpose: Extends executor functionality through plugins\n * - Core Concept: Plugin registration and deduplication\n * - Main Features:\n * - Prevents duplicate plugins if onlyOne is true\n * - Maintains plugin execution order\n * - Primary Use: Adding new capabilities to executor\n *\n * @param plugin - Plugin instance to add\n *\n * @example\n * ```typescript\n * executor.use(new LoggerPlugin());\n * executor.use(new RetryPlugin({ maxAttempts: 3 }));\n * ```\n *\n * @example\n *\n * Use a plain object as a plugin\n * ```typescript\n * executor.use({\n * onBefore: (data) => ({ ...data, modified: true })\n * });\n * ```\n */\n use(plugin: ExecutorPlugin): void {\n if (\n this.plugins.find(\n (p) =>\n p === plugin ||\n p.pluginName === plugin.pluginName ||\n p.constructor === plugin.constructor\n ) &&\n plugin.onlyOne\n ) {\n console.warn(`Plugin ${plugin.pluginName} is already used, skip adding`);\n return;\n }\n\n this.plugins.push(plugin);\n }\n\n /**\n * Execute a plugin hook\n *\n * - Purpose: Provides plugin hook execution mechanism\n * - Core Concept: Plugin lifecycle management\n * - Main Features:\n * - Dynamic hook execution\n * - Support for async and sync hooks\n * - Primary Use: Running plugin lifecycle methods\n *\n * @param plugins - Plugins to execute\n * @param name - Hook name to execute\n * @param args - Arguments for the hook\n *\n * @example\n * ```typescript\n * await executor.runHook(plugins, 'beforeExec', data);\n * ```\n */\n abstract runHooks(\n plugins: ExecutorPlugin[],\n name: keyof ExecutorPlugin,\n ...args: unknown[]\n ): void | unknown | Promise<void | unknown>;\n\n /**\n * Execute a task with plugin pipeline\n *\n * - Purpose: Core task execution with plugin support\n * - Core Concept: Task execution pipeline\n * - Main Features:\n * - Plugin hook integration\n * - Error handling\n * - Primary Use: Running tasks through the executor pipeline\n *\n * @param task - Task to execute\n * @param data - Optional input data for task\n * @throws {ExecutorError} If task execution fails\n *\n * @example\n * ```typescript\n * const result = await executor.exec(async (data) => {\n * return await processData(data);\n * });\n * ```\n */\n abstract exec<Result, Params = unknown>(\n task: Task<Result, Params>\n ): Promise<Result> | Result;\n\n /**\n * Execute a task with plugin pipeline and input data\n *\n * - Purpose: Core task execution with plugin support and input data\n * - Core Concept: Task execution pipeline with data\n * - Main Features:\n * - Plugin hook integration\n * - Error handling\n * - Primary Use: Running tasks with input data through the executor pipeline\n *\n * @param data - Input data for task\n * @param task - Task to execute\n * @throws {ExecutorError} If task execution fails\n *\n * @example\n * ```typescript\n * const result = await executor.exec(data, async (data) => {\n * return await processData(data);\n * });\n * ```\n */\n abstract exec<Result, Params = unknown>(\n data: unknown,\n task: Task<Result, Params>\n ): Promise<Result> | Result;\n\n /**\n * Execute a task without throwing errors\n *\n * - Purpose: Safe task execution with error wrapping\n * - Core Concept: Error-safe execution pipeline\n * - Main Features:\n * - Error wrapping in ExecutorError\n * - Non-throwing execution\n * - Primary Use: When error handling is preferred over exceptions\n *\n * @param task - Task to execute\n *\n * @example\n * ```typescript\n * const result = await executor.execNoError(async (data) => {\n * return await riskyOperation(data);\n * });\n * if (result instanceof ExecutorError) {\n * console.error('Task failed:', result);\n * }\n * ```\n */\n abstract execNoError<Result, Params = unknown>(\n task: Task<Result, Params>\n ): Promise<Result | ExecutorError> | Result | ExecutorError;\n\n /**\n * Execute a task with input data without throwing errors\n *\n * - Purpose: Safe task execution with error wrapping and input data\n * - Core Concept: Error-safe execution pipeline with data\n * - Main Features:\n * - Error wrapping in ExecutorError\n * - Non-throwing execution\n * - Primary Use: When error handling is preferred over exceptions with input data\n *\n * @param data - Input data for task\n * @param task - Task to execute\n *\n * @example\n * ```typescript\n * const result = await executor.execNoError(data, async (data) => {\n * return await riskyOperation(data);\n * });\n * if (result instanceof ExecutorError) {\n * console.error('Task failed:', result);\n * }\n * ```\n */\n abstract execNoError<Result, Params = unknown>(\n data: unknown,\n task: Task<Result, Params>\n ): Promise<Result | ExecutorError> | Result | ExecutorError;\n}\n","/**\n * Custom error class for executor operations.\n *\n * This class provides a structured way to handle errors that occur during executor operations.\n * It extends the standard Error class to include an error identification string, which can be used\n * to categorize and manage errors more effectively.\n *\n * @category Executor\n *\n * @example\n * ```typescript\n * try {\n * // some executor operation\n * } catch (error) {\n * throw new ExecutorError('EXECUTOR_ERROR', error);\n * }\n * ```\n *\n * @example\n *\n * create an error with a message from a string\n *\n * ```typescript\n * const error = new ExecutorError('ERROR_ID', 'This is an error message');\n *\n * // => error.message is 'This is an error message'\n * // => error.id is 'ERROR_ID'\n * ```\n */\nexport class ExecutorError extends Error {\n /**\n * Constructs a new ExecutorError.\n *\n * if originalError is a string, it will be used as the error message.\n * if originalError is an Error object, its message will be used as the error message.\n * if originalError is not provided, the error message will be the id.\n *\n * @param id - A unique identifier for the error, used for categorization and tracking.\n * @param originalError - The original error message or Error object that triggered this error.\n * This parameter is optional.\n */\n constructor(\n public id: string,\n originalError?: string | Error\n ) {\n super(\n originalError instanceof Error\n ? originalError.message\n : originalError || id\n );\n\n // if originalError is an Error object, use its stack\n if (originalError instanceof Error && 'stack' in originalError) {\n this.stack = originalError.stack;\n }\n\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n","import { ExecutorError } from '../executor';\n\n/**\n * Represents a custom error class for handling request-related errors in the application\n *\n * RequestError extends the base ExecutorError class to provide specific error handling\n * for HTTP requests and fetch operations. It works in conjunction with RequestErrorID\n * to categorize different types of request failures.\n *\n * @since 1.0.14\n *\n * @example\n * ```typescript\n * try {\n * await fetchData(url);\n * } catch (error) {\n * if (error instanceof RequestError) {\n * // Handle request specific error\n * console.error('Request failed:', error.message);\n * }\n * }\n * ```\n */\nexport class RequestError extends ExecutorError {}\n\n/**\n * Error IDs for different fetch request failure scenarios\n * Used to identify specific error types in error handling\n *\n * @description\n * This enum provides a standardized set of error identifiers that can be used\n * to categorize and handle different types of request failures in a consistent manner.\n * Each error ID represents a specific failure scenario that might occur during HTTP requests.\n *\n * @example\n * ```typescript\n * if (error.id === RequestErrorID.RESPONSE_NOT_OK) {\n * // Handle non-200 response\n * } else if (error.id === RequestErrorID.ABORT_ERROR) {\n * // Handle aborted request\n * }\n * ```\n */\nexport enum RequestErrorID {\n /** Generic fetch request error */\n REQUEST_ERROR = 'REQUEST_ERROR',\n /** Environment doesn't support fetch API */\n ENV_FETCH_NOT_SUPPORT = 'ENV_FETCH_NOT_SUPPORT',\n /** No fetcher function provided */\n FETCHER_NONE = 'FETCHER_NONE',\n /** Response status is not OK (not in 200-299 range) */\n RESPONSE_NOT_OK = 'RESPONSE_NOT_OK',\n /** Request was aborted */\n ABORT_ERROR = 'ABORT_ERROR',\n /** URL is not provided */\n URL_NONE = 'URL_NONE'\n}\n"],"names":["RequestErrorID"],"mappings":";;;;;;EAGA;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4BG;AACH,MAAA,QAAA,kBAAA,YAAA;EAqBE;;;;;;;;;;;;;;;;EAgBG;EACH,IAAA,SAAA,QAAA,CAAsB,MAAuB,EAAA;UAAvB,IAAM,CAAA,MAAA,GAAN,MAAM;EArC5B;;;;;;;;;;;;;;;;;EAiBG;UACO,IAAO,CAAA,OAAA,GAAqB,EAAE;;EAqBxC;;;;;;;;;;;;;;;;;;;;;;;;;;EA0BG;MACH,QAAG,CAAA,SAAA,CAAA,GAAA,GAAH,UAAI,MAAsB,EAAA;EACxB,QAAA,IACE,IAAI,CAAC,OAAO,CAAC,IAAI,CACf,UAAC,CAAC,EAAA;cACA,OAAA,CAAC,KAAK,MAAM;EACZ,gBAAA,CAAC,CAAC,UAAU,KAAK,MAAM,CAAC,UAAU;EAClC,gBAAA,CAAC,CAAC,WAAW,KAAK,MAAM,CAAC,WAAW;EAFpC,SAEoC,CACvC;cACD,MAAM,CAAC,OAAO,EACd;cACA,OAAO,CAAC,IAAI,CAAC,SAAA,CAAA,MAAA,CAAU,MAAM,CAAC,UAAU,EAA+B,+BAAA,CAAA,CAAC;cACxE;;EAGF,QAAA,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;OAC1B;MAmIH,OAAC,QAAA;EAAD,CAAC,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ECrPD;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4BG;AACH,MAAA,aAAA,kBAAA,UAAA,MAAA,EAAA;MAAmC,SAAK,CAAA,aAAA,EAAA,MAAA,CAAA;EACtC;;;;;;;;;;EAUG;MACH,SACS,aAAA,CAAA,EAAU,EACjB,aAA8B,EAAA;;EAE9B,QAAA,IAAA,KAAA,GAAA,MAAK,CAAA,IAAA,CAAA,IAAA,EACH,aAAa,YAAY;gBACrB,aAAa,CAAC;EAChB,cAAE,aAAa,IAAI,EAAE,CACxB,IAAC,IAAA;UAPK,KAAE,CAAA,EAAA,GAAF,EAAE;;UAUT,IAAI,aAAa,YAAY,KAAK,IAAI,OAAO,IAAI,aAAa,EAAE;EAC9D,YAAA,KAAI,CAAC,KAAK,GAAG,aAAa,CAAC,KAAK;;UAGlC,MAAM,CAAC,cAAc,CAAC,KAAI,EAAE,UAAW,CAAA,SAAS,CAAC;;;MAErD,OAAC,aAAA;EAAD,CA7BA,CAAmC,KAAK,CA6BvC;;ECxDD;;;;;;;;;;;;;;;;;;;;EAoBG;AACH,MAAA,YAAA,kBAAA,UAAA,MAAA,EAAA;MAAkC,SAAa,CAAA,YAAA,EAAA,MAAA,CAAA;EAA/C,IAAA,SAAA,YAAA,GAAA;;;MAAiD,OAAC,YAAA;EAAD,CAAjD,CAAkC,aAAa,CAAG;EAElD;;;;;;;;;;;;;;;;;EAiBG;AACSA;EAAZ,CAAA,UAAY,cAAc,EAAA;;EAExB,IAAA,cAAA,CAAA,eAAA,CAAA,GAAA,eAA+B;;EAE/B,IAAA,cAAA,CAAA,uBAAA,CAAA,GAAA,uBAA+C;;EAE/C,IAAA,cAAA,CAAA,cAAA,CAAA,GAAA,cAA6B;;EAE7B,IAAA,cAAA,CAAA,iBAAA,CAAA,GAAA,iBAAmC;;EAEnC,IAAA,cAAA,CAAA,aAAA,CAAA,GAAA,aAA2B;;EAE3B,IAAA,cAAA,CAAA,UAAA,CAAA,GAAA,UAAqB;EACvB,CAAC,EAbWA,sBAAc,KAAdA,sBAAc,GAazB,EAAA,CAAA,CAAA;;;;;;;;;;"}
|