actly 1.1.0 → 1.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/LICENSE +0 -0
- package/README.md +262 -232
- package/dist/core/act.cjs +505 -39
- package/dist/core/act.d.ts +81 -10
- package/dist/core/act.d.ts.map +1 -1
- package/dist/core/act.js +504 -40
- package/dist/core/act.js.map +1 -1
- package/dist/core/executor.cjs +21 -9
- package/dist/core/executor.d.ts +31 -6
- package/dist/core/executor.d.ts.map +1 -1
- package/dist/core/executor.js +21 -9
- package/dist/core/executor.js.map +1 -1
- package/dist/core/health.cjs +34 -0
- package/dist/core/health.d.ts +18 -0
- package/dist/core/health.d.ts.map +1 -0
- package/dist/core/health.js +28 -0
- package/dist/core/health.js.map +1 -0
- package/dist/core/shutdown.cjs +60 -0
- package/dist/core/shutdown.d.ts +8 -0
- package/dist/core/shutdown.d.ts.map +1 -0
- package/dist/core/shutdown.js +56 -0
- package/dist/core/shutdown.js.map +1 -0
- package/dist/core/tenant.cjs +71 -0
- package/dist/core/tenant.d.ts +29 -0
- package/dist/core/tenant.d.ts.map +1 -0
- package/dist/core/tenant.js +68 -0
- package/dist/core/tenant.js.map +1 -0
- package/dist/errors.cjs +182 -0
- package/dist/errors.d.ts +151 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +171 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.cjs +56 -6
- package/dist/index.d.ts +22 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -4
- package/dist/index.js.map +1 -1
- package/dist/observability.cjs +45 -0
- package/dist/observability.d.ts +145 -0
- package/dist/observability.d.ts.map +1 -0
- package/dist/observability.js +43 -0
- package/dist/observability.js.map +1 -0
- package/dist/policies/bulkhead.cjs +97 -0
- package/dist/policies/bulkhead.d.ts +3 -0
- package/dist/policies/bulkhead.d.ts.map +1 -0
- package/dist/policies/bulkhead.js +95 -0
- package/dist/policies/bulkhead.js.map +1 -0
- package/dist/policies/cache.cjs +223 -22
- package/dist/policies/cache.d.ts +42 -7
- package/dist/policies/cache.d.ts.map +1 -1
- package/dist/policies/cache.js +223 -22
- package/dist/policies/cache.js.map +1 -1
- package/dist/policies/circuitBreaker.cjs +85 -0
- package/dist/policies/circuitBreaker.d.ts +3 -0
- package/dist/policies/circuitBreaker.d.ts.map +1 -0
- package/dist/policies/circuitBreaker.js +83 -0
- package/dist/policies/circuitBreaker.js.map +1 -0
- package/dist/policies/dedupe.cjs +98 -21
- package/dist/policies/dedupe.d.ts +20 -13
- package/dist/policies/dedupe.d.ts.map +1 -1
- package/dist/policies/dedupe.js +98 -21
- package/dist/policies/dedupe.js.map +1 -1
- package/dist/policies/rateLimit.cjs +35 -0
- package/dist/policies/rateLimit.d.ts +3 -0
- package/dist/policies/rateLimit.d.ts.map +1 -0
- package/dist/policies/rateLimit.js +33 -0
- package/dist/policies/rateLimit.js.map +1 -0
- package/dist/policies/retry.cjs +103 -26
- package/dist/policies/retry.d.ts +25 -2
- package/dist/policies/retry.d.ts.map +1 -1
- package/dist/policies/retry.js +103 -26
- package/dist/policies/retry.js.map +1 -1
- package/dist/policies/timeout.cjs +78 -36
- package/dist/policies/timeout.d.ts +7 -18
- package/dist/policies/timeout.d.ts.map +1 -1
- package/dist/policies/timeout.js +84 -31
- package/dist/policies/timeout.js.map +1 -1
- package/dist/state/store.cjs +9 -2
- package/dist/state/store.d.ts +9 -0
- package/dist/state/store.d.ts.map +1 -1
- package/dist/state/store.js +9 -2
- package/dist/state/store.js.map +1 -1
- package/dist/stores/base.cjs +4 -4
- package/dist/stores/base.d.ts +32 -56
- package/dist/stores/base.d.ts.map +1 -1
- package/dist/stores/base.js +4 -4
- package/dist/stores/base.js.map +1 -1
- package/dist/stores/memory.cjs +161 -39
- package/dist/stores/memory.d.ts +64 -24
- package/dist/stores/memory.d.ts.map +1 -1
- package/dist/stores/memory.js +160 -39
- package/dist/stores/memory.js.map +1 -1
- package/dist/types/index.d.ts +315 -37
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/abort.cjs +212 -0
- package/dist/utils/abort.d.ts +79 -0
- package/dist/utils/abort.d.ts.map +1 -0
- package/dist/utils/abort.js +206 -0
- package/dist/utils/abort.js.map +1 -0
- package/dist/utils/abortPool.cjs +26 -0
- package/dist/utils/abortPool.d.ts +4 -0
- package/dist/utils/abortPool.d.ts.map +1 -0
- package/dist/utils/abortPool.js +22 -0
- package/dist/utils/abortPool.js.map +1 -0
- package/dist/utils/backoff.cjs +54 -0
- package/dist/utils/backoff.d.ts +14 -0
- package/dist/utils/backoff.d.ts.map +1 -0
- package/dist/utils/backoff.js +52 -0
- package/dist/utils/backoff.js.map +1 -0
- package/dist/utils/key.cjs +77 -0
- package/dist/utils/key.d.ts +29 -0
- package/dist/utils/key.d.ts.map +1 -0
- package/dist/utils/key.js +75 -0
- package/dist/utils/key.js.map +1 -0
- package/dist/utils/limits.cjs +40 -0
- package/dist/utils/limits.d.ts +39 -0
- package/dist/utils/limits.d.ts.map +1 -0
- package/dist/utils/limits.js +38 -0
- package/dist/utils/limits.js.map +1 -0
- package/dist/utils/sanitize.cjs +29 -0
- package/dist/utils/sanitize.d.ts +3 -0
- package/dist/utils/sanitize.d.ts.map +1 -0
- package/dist/utils/sanitize.js +26 -0
- package/dist/utils/sanitize.js.map +1 -0
- package/dist/utils/validate.cjs +153 -0
- package/dist/utils/validate.d.ts +26 -0
- package/dist/utils/validate.d.ts.map +1 -0
- package/dist/utils/validate.js +141 -0
- package/dist/utils/validate.js.map +1 -0
- package/package.json +20 -37
package/dist/core/act.d.ts
CHANGED
|
@@ -1,20 +1,26 @@
|
|
|
1
|
-
import type { ActFn, ActOptions, ActResult } from '../types/index.js';
|
|
1
|
+
import type { ActFn, ActOptions, ActResult, AnyStateStore, SyncStateStore, AsyncStateStore } from '../types/index.js';
|
|
2
2
|
/**
|
|
3
|
-
* Execute fn with the given reliability policies.
|
|
3
|
+
* Execute `fn` with the given reliability policies.
|
|
4
4
|
*
|
|
5
5
|
* @param key Stable identifier for this action. Scopes dedupe + cache.
|
|
6
|
-
* @param fn The async work to run.
|
|
6
|
+
* @param fn The async work to run. Receives an `AbortSignal` for
|
|
7
|
+
* cooperative cancellation (legacy `() => Promise<T>` is
|
|
8
|
+
* still accepted — the signal is simply ignored).
|
|
7
9
|
* @param options Which policies to apply and how. All fields are optional.
|
|
8
10
|
*
|
|
9
|
-
* @returns ActResult<T
|
|
10
|
-
* Check result.ok before reading result.value
|
|
11
|
+
* @returns `ActResult<T>` — always resolves, never throws.
|
|
12
|
+
* Check `result.ok` before reading `result.value`.
|
|
11
13
|
*
|
|
12
14
|
* @example
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
15
|
+
* // With cooperative cancellation
|
|
16
|
+
* const result = await act('user:42', async (signal) => {
|
|
17
|
+
* return fetch(`/api/users/42`, { signal })
|
|
18
|
+
* }, {
|
|
19
|
+
* retry: { attempts: 3, delayMs: 200, backoff: 'exponential' },
|
|
20
|
+
* timeout: { ms: 5_000 },
|
|
21
|
+
* totalTimeout: { ms: 12_000 },
|
|
22
|
+
* dedupe: true,
|
|
23
|
+
* cache: { ttl: 60_000 },
|
|
18
24
|
* })
|
|
19
25
|
*
|
|
20
26
|
* if (result.ok) {
|
|
@@ -24,4 +30,69 @@ import type { ActFn, ActOptions, ActResult } from '../types/index.js';
|
|
|
24
30
|
* }
|
|
25
31
|
*/
|
|
26
32
|
export declare function act<T>(key: string, fn: ActFn<T>, options?: ActOptions): Promise<ActResult<T>>;
|
|
33
|
+
/**
|
|
34
|
+
* Invalidate the cached value for `key` on the default module-level store.
|
|
35
|
+
*
|
|
36
|
+
* Only clears the cache slot — does not affect in-flight dedupe entries
|
|
37
|
+
* (those will settle on their own). Returns `true` if a cache entry was
|
|
38
|
+
* removed, `false` otherwise.
|
|
39
|
+
*
|
|
40
|
+
* Useful when you know the underlying data has changed and you want the
|
|
41
|
+
* next `act()` call to re-run `fn` instead of serving stale cache:
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* await act('user:42', () => fetchUser(42), { cache: { ttl: 60_000 } })
|
|
45
|
+
* // ... user updates their profile ...
|
|
46
|
+
* invalidate('user:42') // next call will re-fetch
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function invalidate(key: string): boolean;
|
|
50
|
+
/** Result of `withStore()` for a sync store: `act` + sync `invalidate`. */
|
|
51
|
+
export interface ScopedActSync {
|
|
52
|
+
<T>(key: string, fn: ActFn<T>, options?: ActOptions): Promise<ActResult<T>>;
|
|
53
|
+
invalidate(key: string): boolean;
|
|
54
|
+
/** The store this scope is bound to. Useful for `store.destroy()` etc. */
|
|
55
|
+
readonly store: AnyStateStore;
|
|
56
|
+
}
|
|
57
|
+
/** Result of `withStore()` for an async store: `act` + async `invalidate`. */
|
|
58
|
+
export interface ScopedActAsync {
|
|
59
|
+
<T>(key: string, fn: ActFn<T>, options?: ActOptions): Promise<ActResult<T>>;
|
|
60
|
+
invalidate(key: string): Promise<boolean>;
|
|
61
|
+
readonly store: AnyStateStore;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create a scoped `act` function bound to an explicit store.
|
|
65
|
+
*
|
|
66
|
+
* Use this for:
|
|
67
|
+
* - **SSR request isolation**: one store per request, no cross-request
|
|
68
|
+
* cache/dedupe leakage.
|
|
69
|
+
* - **Multi-tenant scenarios**: one store per tenant, no cross-tenant
|
|
70
|
+
* data leakage.
|
|
71
|
+
* - **Test isolation**: each test gets a fresh store, no shared state.
|
|
72
|
+
*
|
|
73
|
+
* The returned function has the same signature as `act()`. It also exposes
|
|
74
|
+
* an `invalidate(key)` method and a `store` reference for cleanup.
|
|
75
|
+
*
|
|
76
|
+
* For sync stores, `invalidate` returns `boolean` synchronously.
|
|
77
|
+
* For async stores, `invalidate` returns `Promise<boolean>`.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* import { withStore, InMemoryStore } from 'actly'
|
|
82
|
+
*
|
|
83
|
+
* const store = new InMemoryStore({ maxSize: 1000, autoCleanup: true })
|
|
84
|
+
* const act = withStore(store)
|
|
85
|
+
*
|
|
86
|
+
* try {
|
|
87
|
+
* await act('user:42', () => fetchUser(42), { cache: { ttl: 60_000 } })
|
|
88
|
+
* // ... user updates their profile ...
|
|
89
|
+
* act.invalidate('user:42') // next call re-fetches
|
|
90
|
+
* } finally {
|
|
91
|
+
* store.destroy()
|
|
92
|
+
* }
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare function withStore(store: SyncStateStore): ScopedActSync;
|
|
96
|
+
export declare function withStore(store: AsyncStateStore): ScopedActAsync;
|
|
97
|
+
export declare function withStore(store: AnyStateStore): ScopedActSync | ScopedActAsync;
|
|
27
98
|
//# sourceMappingURL=act.d.ts.map
|
package/dist/core/act.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"act.d.ts","sourceRoot":"","sources":["../../src/core/act.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"act.d.ts","sourceRoot":"","sources":["../../src/core/act.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,UAAU,EACV,SAAS,EAGT,aAAa,EACb,cAAc,EACd,eAAe,EAEhB,MAAM,mBAAmB,CAAA;AA4L1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAsB,GAAG,CAAC,CAAC,EACzB,GAAG,EAAE,MAAM,EACX,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC,EACZ,OAAO,GAAE,UAAe,GACvB,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CA8JvB;AA+BD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAM/C;AAID,2EAA2E;AAC3E,MAAM,WAAW,aAAa;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