rest-pipeline-js 1.3.5 → 1.3.6
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/CHANGELOG.md +54 -0
- package/dist/cjs/cache.js +26 -0
- package/dist/cjs/pipeline-orchestrator.js +408 -91
- package/dist/cjs/request-executor.js +44 -7
- package/dist/cjs/rest-client.js +188 -38
- package/dist/cjs/types.js +14 -0
- package/dist/esm/cache.d.ts +14 -0
- package/dist/esm/cache.js +26 -0
- package/dist/esm/pipeline-orchestrator.d.ts +14 -3
- package/dist/esm/pipeline-orchestrator.js +412 -95
- package/dist/esm/request-executor.d.ts +2 -0
- package/dist/esm/request-executor.js +44 -7
- package/dist/esm/rest-client.d.ts +9 -2
- package/dist/esm/rest-client.js +190 -41
- package/dist/esm/types.d.ts +177 -9
- package/dist/esm/types.js +13 -1
- package/dist/esm/useRestClient-react.d.ts +3 -1
- package/dist/esm/useRestClient-vue.d.ts +3 -1
- package/package.json +1 -1
- package/src/cache.ts +29 -0
- package/src/pipeline-orchestrator.ts +490 -106
- package/src/rest-client.ts +207 -51
- package/src/types.ts +168 -17
- package/tests/pipeline-orchestrator.test.ts +489 -24
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [1.3.6] - 2026-04-03
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
#### Pipeline Orchestrator
|
|
8
|
+
|
|
9
|
+
- **`continueOnError`** — per-stage and global flag to continue pipeline execution when a step fails. When enabled, failed steps are marked with `status: "error"` but do not stop the pipeline.
|
|
10
|
+
- **`next()` function** — DAG (directed acyclic graph) transitions allowing non-linear pipeline flows. After successful step execution, you can dynamically jump to any stage by its key or continue sequentially by returning `null`. Includes protection against infinite loops (max steps = stages.length × 10).
|
|
11
|
+
- **Sub-pipelines** — embed a complete `PipelineConfig` as a stage using the `subPipeline` field. Sub-pipelines run with their own context but share the parent's `sharedData` and abort signal. Results are stored under the stage key.
|
|
12
|
+
- **`pipelineRetry`** — automatic retry of the entire pipeline on failure. Supports:
|
|
13
|
+
- `attempts` — number of retry attempts
|
|
14
|
+
- `delayMs` — delay between retries
|
|
15
|
+
- `retryFrom` — resume from `"start"` (default, resets all results) or `"failed-step"` (preserves successful stage results)
|
|
16
|
+
- **`pipelineTimeoutMs`** — global timeout for the entire pipeline execution. When exceeded, the pipeline is automatically aborted via `abort()`, cancelling any in-flight HTTP requests.
|
|
17
|
+
|
|
18
|
+
#### RestClient
|
|
19
|
+
|
|
20
|
+
- **Request interceptors** — modify request configuration before sending. Supports single interceptor or array of interceptors applied in sequence.
|
|
21
|
+
- **Response interceptors** — transform response data after receiving. Applied before returning the response to the caller.
|
|
22
|
+
- **Error interceptors** — handle or modify errors before they are thrown.
|
|
23
|
+
- **Global `onError` handler** — simple callback for centralized error handling. Receives the `ApiError` and the original request configuration.
|
|
24
|
+
- **Stale-While-Revalidate cache strategy** — serves stale cached data immediately while fetching fresh data in the background. Configured via:
|
|
25
|
+
- `strategy: "stale-while-revalidate"`
|
|
26
|
+
- `staleMs` — extra time to serve stale data after TTL expires
|
|
27
|
+
- **Request deduplication** — prevents duplicate in-flight GET requests. When enabled (`deduplicateRequests: true`), multiple identical requests share the same pending Promise, reducing network traffic.
|
|
28
|
+
- **`head()` method** — execute HEAD requests to retrieve headers without the response body.
|
|
29
|
+
- **`options()` method** — execute OPTIONS requests to discover allowed HTTP methods and CORS policies.
|
|
30
|
+
|
|
31
|
+
#### Types
|
|
32
|
+
|
|
33
|
+
- Added `RequestInterceptor`, `ResponseInterceptor`, `ErrorInterceptor` types
|
|
34
|
+
- Added `SubPipelineStage` type and updated `PipelineItem` union
|
|
35
|
+
- Extended `CacheConfig` with `strategy` and `staleMs` fields
|
|
36
|
+
- Extended `HttpConfig` with `interceptors`, `onError`, `deduplicateRequests`
|
|
37
|
+
- Extended `PipelineConfig` with `options` object containing `continueOnError`, `pipelineRetry`, `pipelineTimeoutMs`
|
|
38
|
+
- Extended `PipelineStageConfig` with `continueOnError` and `next` fields
|
|
39
|
+
|
|
40
|
+
#### Cache
|
|
41
|
+
|
|
42
|
+
- **`TtlCache.getStale()`** — new method that returns cached values even after TTL expiration, as long as they are within the `staleMs` window. Returns an object with `{ value, isStale }` where `isStale: true` indicates the value is beyond TTL but still usable.
|
|
43
|
+
|
|
44
|
+
### Changed
|
|
45
|
+
|
|
46
|
+
- `PipelineOrchestrator.run()` now supports retry logic via `pipelineRetry` configuration
|
|
47
|
+
- Main `run()` logic extracted to `_runOnce()` private method to enable retry functionality
|
|
48
|
+
- `PipelineOrchestrator` constructor now properly handles `config.options` separately from constructor `options`
|
|
49
|
+
|
|
50
|
+
### Fixed
|
|
51
|
+
|
|
52
|
+
- Backward compatibility with existing `PipelineConfig` objects that do not include the new `options` field
|
|
53
|
+
- `PipelineOrchestrator` constructor no longer conflicts between `config.options` and constructor `params.options`
|
|
54
|
+
- Parallel stage groups now correctly handle `continueOnError` behavior
|
package/dist/cjs/cache.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TtlCache = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Простой TTL-кэш с ограничением размера (LRU-eviction при превышении maxSize)
|
|
6
|
+
* и поддержкой stale-while-revalidate через метод getStale().
|
|
6
7
|
*/
|
|
7
8
|
class TtlCache {
|
|
8
9
|
constructor(maxSize = 500) {
|
|
@@ -32,6 +33,31 @@ class TtlCache {
|
|
|
32
33
|
}
|
|
33
34
|
return entry.value;
|
|
34
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Возвращает значение с флагом isStale.
|
|
38
|
+
* Если запись свежая — isStale: false.
|
|
39
|
+
* Если запись устарела (TTL истёк), но находится в пределах staleMs — isStale: true.
|
|
40
|
+
* Если запись устарела и за пределами staleMs — удаляет и возвращает undefined.
|
|
41
|
+
*
|
|
42
|
+
* @param key Ключ кэша
|
|
43
|
+
* @param staleMs Дополнительное время после ttlMs, в течение которого запись считается stale (0 = бессрочно)
|
|
44
|
+
*/
|
|
45
|
+
getStale(key, staleMs) {
|
|
46
|
+
const entry = this.store.get(key);
|
|
47
|
+
if (!entry)
|
|
48
|
+
return undefined;
|
|
49
|
+
const now = Date.now();
|
|
50
|
+
if (now <= entry.expiresAt) {
|
|
51
|
+
return { value: entry.value, isStale: false };
|
|
52
|
+
}
|
|
53
|
+
// Запись устарела. Проверяем staleMs: 0 означает "бессрочно stale"
|
|
54
|
+
if (staleMs === 0 || now <= entry.expiresAt + staleMs) {
|
|
55
|
+
return { value: entry.value, isStale: true };
|
|
56
|
+
}
|
|
57
|
+
// За пределами staleMs — удаляем
|
|
58
|
+
this.store.delete(key);
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
35
61
|
has(key) {
|
|
36
62
|
return this.get(key) !== undefined;
|
|
37
63
|
}
|