flowshield 1.0.2 → 1.0.4
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/cjs/compose.js +2 -2
- package/dist/cjs/policies/bulkhead.js +1 -1
- package/dist/cjs/policies/cache.js +1 -1
- package/dist/cjs/policies/circuit-breaker.js +1 -1
- package/dist/cjs/policies/fallback.js +1 -3
- package/dist/cjs/policies/fallback.js.map +1 -1
- package/dist/cjs/policies/hedge.js +1 -3
- package/dist/cjs/policies/hedge.js.map +1 -1
- package/dist/cjs/policies/rate-limiter.js +1 -1
- package/dist/cjs/policies/retry.js +1 -1
- package/dist/cjs/policies/timeout.js +1 -1
- package/dist/esm/compose.js +2 -2
- package/dist/esm/policies/bulkhead.js +1 -1
- package/dist/esm/policies/cache.js +1 -1
- package/dist/esm/policies/circuit-breaker.js +1 -1
- package/dist/esm/policies/fallback.js +1 -3
- package/dist/esm/policies/fallback.js.map +1 -1
- package/dist/esm/policies/hedge.js +1 -3
- package/dist/esm/policies/hedge.js.map +1 -1
- package/dist/esm/policies/rate-limiter.js +1 -1
- package/dist/esm/policies/retry.js +1 -1
- package/dist/esm/policies/timeout.js +1 -1
- package/dist/types/compose.d.ts +2 -2
- package/dist/types/policies/bulkhead.d.ts +1 -1
- package/dist/types/policies/cache.d.ts +1 -1
- package/dist/types/policies/circuit-breaker.d.ts +1 -1
- package/dist/types/policies/fallback.d.ts +1 -3
- package/dist/types/policies/fallback.d.ts.map +1 -1
- package/dist/types/policies/hedge.d.ts +1 -3
- package/dist/types/policies/hedge.d.ts.map +1 -1
- package/dist/types/policies/rate-limiter.d.ts +1 -1
- package/dist/types/policies/retry.d.ts +1 -1
- package/dist/types/policies/timeout.d.ts +1 -1
- package/package.json +1 -1
package/dist/cjs/compose.js
CHANGED
|
@@ -14,7 +14,7 @@ exports.wrap = wrap;
|
|
|
14
14
|
* timeout({ ms: 5000 }),
|
|
15
15
|
* retry({ maxAttempts: 3 }),
|
|
16
16
|
* );
|
|
17
|
-
* const result = await resilient(() =>
|
|
17
|
+
* const result = await resilient(() => callApi());
|
|
18
18
|
* ```
|
|
19
19
|
*/
|
|
20
20
|
function pipe(...policies) {
|
|
@@ -42,7 +42,7 @@ function pipe(...policies) {
|
|
|
42
42
|
* timeout({ ms: 5000 }),
|
|
43
43
|
* retry({ maxAttempts: 3 }),
|
|
44
44
|
* );
|
|
45
|
-
* const result = await policy(() =>
|
|
45
|
+
* const result = await policy(() => callApi());
|
|
46
46
|
* ```
|
|
47
47
|
*/
|
|
48
48
|
function wrap(outer, inner) {
|
|
@@ -17,7 +17,7 @@ const DEFAULTS = {
|
|
|
17
17
|
* @example
|
|
18
18
|
* ```ts
|
|
19
19
|
* const bh = bulkhead({ maxConcurrent: 5, maxQueue: 10 });
|
|
20
|
-
|
|
20
|
+
* const result = await bh.execute(() => callApi());
|
|
21
21
|
* console.log(bh.handle.running); // number of active calls
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
@@ -16,7 +16,7 @@ const DEFAULTS = {
|
|
|
16
16
|
* @example
|
|
17
17
|
* ```ts
|
|
18
18
|
* const c = cache({ ttl: 10_000 });
|
|
19
|
-
* const result = await c.execute(() =>
|
|
19
|
+
* const result = await c.execute(() => callApi());
|
|
20
20
|
* ```
|
|
21
21
|
*/
|
|
22
22
|
function cache(options = {}) {
|
|
@@ -17,7 +17,7 @@ const DEFAULTS = {
|
|
|
17
17
|
* @example
|
|
18
18
|
* ```ts
|
|
19
19
|
* const cb = circuitBreaker({ failureThreshold: 3, resetTimeout: 10_000 });
|
|
20
|
-
|
|
20
|
+
* const result = await cb.execute(() => callApi());
|
|
21
21
|
* console.log(cb.handle.state); // 'closed'
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
@@ -7,9 +7,7 @@ exports.fallback = fallback;
|
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
9
|
* ```ts
|
|
10
|
-
|
|
11
|
-
* () => fetch('/api/items').then(r => r.json()),
|
|
12
|
-
* );
|
|
10
|
+
* const result = await fallback({ fallback: [] })(() => callApi());
|
|
13
11
|
* ```
|
|
14
12
|
*/
|
|
15
13
|
function fallback(options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fallback.js","sourceRoot":"","sources":["../../../src/policies/fallback.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"fallback.js","sourceRoot":"","sources":["../../../src/policies/fallback.ts"],"names":[],"mappings":";;AAWA,4BAkBC;AA3BD;;;;;;;;GAQG;AACH,SAAgB,QAAQ,CAAI,OAA2B;IACrD,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;IAE9D,OAAO,KAAK,EAAK,EAAoB,EAAkB,EAAE;QACvD,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,EAAE,CAAC;QACpB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC3B,MAAM,KAAK,CAAC;YACd,CAAC;YAED,MAAM,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC;YAC5B,IAAI,OAAO,EAAE,KAAK,UAAU,EAAE,CAAC;gBAC7B,OAAO,MAAO,EAAyC,CAAC,KAAK,CAAC,CAAC;YACjE,CAAC;YACD,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -12,9 +12,7 @@ const DEFAULTS = {
|
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```ts
|
|
15
|
-
|
|
16
|
-
* () => fetch('/api/data').then(r => r.json()),
|
|
17
|
-
* );
|
|
15
|
+
* const result = await hedge({ hedgeDelay: 1000 })(() => callApi());
|
|
18
16
|
* ```
|
|
19
17
|
*/
|
|
20
18
|
function hedge(options = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hedge.js","sourceRoot":"","sources":["../../../src/policies/hedge.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"hedge.js","sourceRoot":"","sources":["../../../src/policies/hedge.ts"],"names":[],"mappings":";;AAiBA,sBAsEC;AAtFD,0CAA6C;AAE7C,MAAM,QAAQ,GAAG;IACf,UAAU,EAAE,IAAI;CACjB,CAAC;AAEF;;;;;;;;;GASG;AACH,SAAgB,KAAK,CAAC,UAAwB,EAAE;IAC9C,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,QAAQ,CAAC,UAAU,CAAC;IAE7D,IAAA,yBAAc,EAAC,UAAU,EAAE,YAAY,CAAC,CAAC;IAEzC,OAAO,KAAK,EAAK,EAAoB,EAAc,EAAE;QACnD,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACxC,IAAI,OAAO,GAAG,KAAK,CAAC;YACpB,IAAI,WAAW,GAAG,KAAK,CAAC;YACxB,IAAI,SAAS,GAAG,KAAK,CAAC;YACtB,IAAI,YAAqB,CAAC;YAC1B,IAAI,aAAa,GAAG,KAAK,CAAC;YAE1B,MAAM,SAAS,GAAG,CAAC,KAAQ,EAAE,EAAE;gBAC7B,IAAI,CAAC,OAAO,EAAE,CAAC;oBACb,OAAO,GAAG,IAAI,CAAC;oBACf,YAAY,CAAC,UAAU,CAAC,CAAC;oBACzB,OAAO,CAAC,KAAK,CAAC,CAAC;gBACjB,CAAC;YACH,CAAC,CAAC;YAEF,MAAM,aAAa,GAAG,GAAG,EAAE;gBACzB,IAAI,WAAW,IAAI,SAAS,IAAI,CAAC,OAAO,EAAE,CAAC;oBACzC,OAAO,GAAG,IAAI,CAAC;oBACf,MAAM,CAAC,YAAY,CAAC,CAAC;gBACvB,CAAC;YACH,CAAC,CAAC;YAEF,MAAM,aAAa,GAAG,GAAG,EAAE;gBACzB,aAAa,GAAG,IAAI,CAAC;gBACrB,MAAM,YAAY,GAAG,EAAE,EAAE,CAAC;gBAC1B,6EAA6E;gBAC7E,KAAK,YAAY,CAAC,IAAI,CACpB,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,EAC3B,GAAG,EAAE;oBACH,SAAS,GAAG,IAAI,CAAC;oBACjB,IAAI,CAAC,WAAW,IAAI,CAAC,OAAO,EAAE,CAAC;wBAC7B,OAAO;oBACT,CAAC;oBACD,aAAa,EAAE,CAAC;gBAClB,CAAC,CACF,CAAC;YACJ,CAAC,CAAC;YAEF,kBAAkB;YAClB,MAAM,OAAO,GAAG,EAAE,EAAE,CAAC;YACrB,6EAA6E;YAC7E,KAAK,OAAO,CAAC,IAAI,CACf,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,EAC3B,CAAC,GAAY,EAAE,EAAE;gBACf,WAAW,GAAG,IAAI,CAAC;gBACnB,YAAY,GAAG,GAAG,CAAC;gBAEnB,IAAI,CAAC,aAAa,EAAE,CAAC;oBACnB,YAAY,CAAC,UAAU,CAAC,CAAC;oBACzB,aAAa,EAAE,CAAC;gBAClB,CAAC;gBAED,aAAa,EAAE,CAAC;YAClB,CAAC,CACF,CAAC;YAEF,0BAA0B;YAC1B,MAAM,UAAU,GAAG,UAAU,CAAC,GAAG,EAAE;gBACjC,IAAI,CAAC,OAAO,EAAE,CAAC;oBACb,aAAa,EAAE,CAAC;gBAClB,CAAC;YACH,CAAC,EAAE,UAAU,CAAC,CAAC;QACjB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -18,7 +18,7 @@ const DEFAULTS = {
|
|
|
18
18
|
* @example
|
|
19
19
|
* ```ts
|
|
20
20
|
* const rl = rateLimiter({ tokensPerInterval: 5, interval: 1000 });
|
|
21
|
-
|
|
21
|
+
* const result = await rl.execute(() => callApi());
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
24
|
function rateLimiter(options = {}) {
|
package/dist/esm/compose.js
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* timeout({ ms: 5000 }),
|
|
11
11
|
* retry({ maxAttempts: 3 }),
|
|
12
12
|
* );
|
|
13
|
-
* const result = await resilient(() =>
|
|
13
|
+
* const result = await resilient(() => callApi());
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
16
|
export function pipe(...policies) {
|
|
@@ -38,7 +38,7 @@ export function pipe(...policies) {
|
|
|
38
38
|
* timeout({ ms: 5000 }),
|
|
39
39
|
* retry({ maxAttempts: 3 }),
|
|
40
40
|
* );
|
|
41
|
-
* const result = await policy(() =>
|
|
41
|
+
* const result = await policy(() => callApi());
|
|
42
42
|
* ```
|
|
43
43
|
*/
|
|
44
44
|
export function wrap(outer, inner) {
|
|
@@ -14,7 +14,7 @@ const DEFAULTS = {
|
|
|
14
14
|
* @example
|
|
15
15
|
* ```ts
|
|
16
16
|
* const bh = bulkhead({ maxConcurrent: 5, maxQueue: 10 });
|
|
17
|
-
|
|
17
|
+
* const result = await bh.execute(() => callApi());
|
|
18
18
|
* console.log(bh.handle.running); // number of active calls
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
@@ -13,7 +13,7 @@ const DEFAULTS = {
|
|
|
13
13
|
* @example
|
|
14
14
|
* ```ts
|
|
15
15
|
* const c = cache({ ttl: 10_000 });
|
|
16
|
-
* const result = await c.execute(() =>
|
|
16
|
+
* const result = await c.execute(() => callApi());
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
19
|
export function cache(options = {}) {
|
|
@@ -14,7 +14,7 @@ const DEFAULTS = {
|
|
|
14
14
|
* @example
|
|
15
15
|
* ```ts
|
|
16
16
|
* const cb = circuitBreaker({ failureThreshold: 3, resetTimeout: 10_000 });
|
|
17
|
-
|
|
17
|
+
* const result = await cb.execute(() => callApi());
|
|
18
18
|
* console.log(cb.handle.state); // 'closed'
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fallback.js","sourceRoot":"","sources":["../../../src/policies/fallback.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"fallback.js","sourceRoot":"","sources":["../../../src/policies/fallback.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CAAI,OAA2B;IACrD,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;IAE9D,OAAO,KAAK,EAAK,EAAoB,EAAkB,EAAE;QACvD,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,EAAE,CAAC;QACpB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC3B,MAAM,KAAK,CAAC;YACd,CAAC;YAED,MAAM,EAAE,GAAG,OAAO,CAAC,QAAQ,CAAC;YAC5B,IAAI,OAAO,EAAE,KAAK,UAAU,EAAE,CAAC;gBAC7B,OAAO,MAAO,EAAyC,CAAC,KAAK,CAAC,CAAC;YACjE,CAAC;YACD,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -9,9 +9,7 @@ const DEFAULTS = {
|
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
12
|
-
|
|
13
|
-
* () => fetch('/api/data').then(r => r.json()),
|
|
14
|
-
* );
|
|
12
|
+
* const result = await hedge({ hedgeDelay: 1000 })(() => callApi());
|
|
15
13
|
* ```
|
|
16
14
|
*/
|
|
17
15
|
export function hedge(options = {}) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hedge.js","sourceRoot":"","sources":["../../../src/policies/hedge.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,QAAQ,GAAG;IACf,UAAU,EAAE,IAAI;CACjB,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"hedge.js","sourceRoot":"","sources":["../../../src/policies/hedge.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,MAAM,QAAQ,GAAG;IACf,UAAU,EAAE,IAAI;CACjB,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,UAAU,KAAK,CAAC,UAAwB,EAAE;IAC9C,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,QAAQ,CAAC,UAAU,CAAC;IAE7D,cAAc,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;IAEzC,OAAO,KAAK,EAAK,EAAoB,EAAc,EAAE;QACnD,OAAO,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACxC,IAAI,OAAO,GAAG,KAAK,CAAC;YACpB,IAAI,WAAW,GAAG,KAAK,CAAC;YACxB,IAAI,SAAS,GAAG,KAAK,CAAC;YACtB,IAAI,YAAqB,CAAC;YAC1B,IAAI,aAAa,GAAG,KAAK,CAAC;YAE1B,MAAM,SAAS,GAAG,CAAC,KAAQ,EAAE,EAAE;gBAC7B,IAAI,CAAC,OAAO,EAAE,CAAC;oBACb,OAAO,GAAG,IAAI,CAAC;oBACf,YAAY,CAAC,UAAU,CAAC,CAAC;oBACzB,OAAO,CAAC,KAAK,CAAC,CAAC;gBACjB,CAAC;YACH,CAAC,CAAC;YAEF,MAAM,aAAa,GAAG,GAAG,EAAE;gBACzB,IAAI,WAAW,IAAI,SAAS,IAAI,CAAC,OAAO,EAAE,CAAC;oBACzC,OAAO,GAAG,IAAI,CAAC;oBACf,MAAM,CAAC,YAAY,CAAC,CAAC;gBACvB,CAAC;YACH,CAAC,CAAC;YAEF,MAAM,aAAa,GAAG,GAAG,EAAE;gBACzB,aAAa,GAAG,IAAI,CAAC;gBACrB,MAAM,YAAY,GAAG,EAAE,EAAE,CAAC;gBAC1B,6EAA6E;gBAC7E,KAAK,YAAY,CAAC,IAAI,CACpB,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,EAC3B,GAAG,EAAE;oBACH,SAAS,GAAG,IAAI,CAAC;oBACjB,IAAI,CAAC,WAAW,IAAI,CAAC,OAAO,EAAE,CAAC;wBAC7B,OAAO;oBACT,CAAC;oBACD,aAAa,EAAE,CAAC;gBAClB,CAAC,CACF,CAAC;YACJ,CAAC,CAAC;YAEF,kBAAkB;YAClB,MAAM,OAAO,GAAG,EAAE,EAAE,CAAC;YACrB,6EAA6E;YAC7E,KAAK,OAAO,CAAC,IAAI,CACf,CAAC,KAAK,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,EAC3B,CAAC,GAAY,EAAE,EAAE;gBACf,WAAW,GAAG,IAAI,CAAC;gBACnB,YAAY,GAAG,GAAG,CAAC;gBAEnB,IAAI,CAAC,aAAa,EAAE,CAAC;oBACnB,YAAY,CAAC,UAAU,CAAC,CAAC;oBACzB,aAAa,EAAE,CAAC;gBAClB,CAAC;gBAED,aAAa,EAAE,CAAC;YAClB,CAAC,CACF,CAAC;YAEF,0BAA0B;YAC1B,MAAM,UAAU,GAAG,UAAU,CAAC,GAAG,EAAE;gBACjC,IAAI,CAAC,OAAO,EAAE,CAAC;oBACb,aAAa,EAAE,CAAC;gBAClB,CAAC;YACH,CAAC,EAAE,UAAU,CAAC,CAAC;QACjB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -15,7 +15,7 @@ const DEFAULTS = {
|
|
|
15
15
|
* @example
|
|
16
16
|
* ```ts
|
|
17
17
|
* const rl = rateLimiter({ tokensPerInterval: 5, interval: 1000 });
|
|
18
|
-
|
|
18
|
+
* const result = await rl.execute(() => callApi());
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
21
|
export function rateLimiter(options = {}) {
|
|
@@ -9,7 +9,7 @@ import { assertPositive } from '../utils.js';
|
|
|
9
9
|
*
|
|
10
10
|
* @example
|
|
11
11
|
* ```ts
|
|
12
|
-
|
|
12
|
+
* const result = await timeout({ ms: 5000 })(() => callApi());
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
15
|
export function timeout(options) {
|
package/dist/types/compose.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type { Policy } from './types.js';
|
|
|
11
11
|
* timeout({ ms: 5000 }),
|
|
12
12
|
* retry({ maxAttempts: 3 }),
|
|
13
13
|
* );
|
|
14
|
-
* const result = await resilient(() =>
|
|
14
|
+
* const result = await resilient(() => callApi());
|
|
15
15
|
* ```
|
|
16
16
|
*/
|
|
17
17
|
export declare function pipe(...policies: Policy[]): Policy;
|
|
@@ -25,7 +25,7 @@ export declare function pipe(...policies: Policy[]): Policy;
|
|
|
25
25
|
* timeout({ ms: 5000 }),
|
|
26
26
|
* retry({ maxAttempts: 3 }),
|
|
27
27
|
* );
|
|
28
|
-
* const result = await policy(() =>
|
|
28
|
+
* const result = await policy(() => callApi());
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
31
|
export declare function wrap(outer: Policy, inner: Policy): Policy;
|
|
@@ -9,7 +9,7 @@ import type { BulkheadOptions, BulkheadHandle } from '../types.js';
|
|
|
9
9
|
* @example
|
|
10
10
|
* ```ts
|
|
11
11
|
* const bh = bulkhead({ maxConcurrent: 5, maxQueue: 10 });
|
|
12
|
-
|
|
12
|
+
* const result = await bh.execute(() => callApi());
|
|
13
13
|
* console.log(bh.handle.running); // number of active calls
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
@@ -9,7 +9,7 @@ import type { CacheOptions, CacheHandle } from '../types.js';
|
|
|
9
9
|
* @example
|
|
10
10
|
* ```ts
|
|
11
11
|
* const c = cache({ ttl: 10_000 });
|
|
12
|
-
* const result = await c.execute(() =>
|
|
12
|
+
* const result = await c.execute(() => callApi());
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
15
|
export declare function cache<V = unknown>(options?: CacheOptions<V>): {
|
|
@@ -8,7 +8,7 @@ import type { CircuitBreakerOptions, CircuitBreakerHandle } from '../types.js';
|
|
|
8
8
|
* @example
|
|
9
9
|
* ```ts
|
|
10
10
|
* const cb = circuitBreaker({ failureThreshold: 3, resetTimeout: 10_000 });
|
|
11
|
-
|
|
11
|
+
* const result = await cb.execute(() => callApi());
|
|
12
12
|
* console.log(cb.handle.state); // 'closed'
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
@@ -5,9 +5,7 @@ import type { FallbackOptions } from '../types.js';
|
|
|
5
5
|
*
|
|
6
6
|
* @example
|
|
7
7
|
* ```ts
|
|
8
|
-
|
|
9
|
-
* () => fetch('/api/items').then(r => r.json()),
|
|
10
|
-
* );
|
|
8
|
+
* const result = await fallback({ fallback: [] })(() => callApi());
|
|
11
9
|
* ```
|
|
12
10
|
*/
|
|
13
11
|
export declare function fallback<F>(options: FallbackOptions<F>): <T>(fn: () => Promise<T>) => Promise<T | F>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fallback.d.ts","sourceRoot":"","sources":["../../../src/policies/fallback.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD
|
|
1
|
+
{"version":3,"file":"fallback.d.ts","sourceRoot":"","sources":["../../../src/policies/fallback.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEnD;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC,CAAC,IAGvC,CAAC,EAAE,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAevD"}
|
|
@@ -6,9 +6,7 @@ import type { HedgeOptions } from '../types.js';
|
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```ts
|
|
9
|
-
|
|
10
|
-
* () => fetch('/api/data').then(r => r.json()),
|
|
11
|
-
* );
|
|
9
|
+
* const result = await hedge({ hedgeDelay: 1000 })(() => callApi());
|
|
12
10
|
* ```
|
|
13
11
|
*/
|
|
14
12
|
export declare function hedge(options?: HedgeOptions): <T>(fn: () => Promise<T>) => Promise<T>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hedge.d.ts","sourceRoot":"","sources":["../../../src/policies/hedge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAOhD
|
|
1
|
+
{"version":3,"file":"hedge.d.ts","sourceRoot":"","sources":["../../../src/policies/hedge.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAOhD;;;;;;;;;GASG;AACH,wBAAgB,KAAK,CAAC,OAAO,GAAE,YAAiB,IAKhC,CAAC,EAAE,IAAI,MAAM,OAAO,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,CAAC,CAiEnD"}
|
|
@@ -9,7 +9,7 @@ import type { RateLimiterOptions, RateLimiterHandle } from '../types.js';
|
|
|
9
9
|
* @example
|
|
10
10
|
* ```ts
|
|
11
11
|
* const rl = rateLimiter({ tokensPerInterval: 5, interval: 1000 });
|
|
12
|
-
|
|
12
|
+
* const result = await rl.execute(() => callApi());
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
15
|
export declare function rateLimiter(options?: RateLimiterOptions): {
|
|
@@ -8,7 +8,7 @@ import type { TimeoutOptions } from '../types.js';
|
|
|
8
8
|
*
|
|
9
9
|
* @example
|
|
10
10
|
* ```ts
|
|
11
|
-
|
|
11
|
+
* const result = await timeout({ ms: 5000 })(() => callApi());
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
14
|
export declare function timeout(options: TimeoutOptions): <T>(fn: () => Promise<T>) => Promise<T>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flowshield",
|
|
3
|
-
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Zero-dependency, TypeScript-first resilience & fault-tolerance toolkit. Composable policies: retry, circuit breaker, timeout, bulkhead, fallback, rate limiter, hedge, cache.",
|
|
6
6
|
"main": "./dist/cjs/index.js",
|