@t4h.framework/cache 0.4.0 → 0.6.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.
@@ -2,15 +2,15 @@
2
2
  name: framework-cache
3
3
  description: >-
4
4
  Guides correct use of @t4h.framework/cache in T4H Framework workflows:
5
- CacheClaim for key-value storage inside activities, Serializable values, TTL
6
- on set, runtime Claim providers, and OAuth2 token caching via @t4h.framework/http.
7
- Use when implementing cache-backed activities, wiring CacheClaim providers,
8
- testing cache get/set, or working in packages/cache.
5
+ CacheClaim that backs package caching (OAuth2 token caching via
6
+ @t4h.framework/http), Serializable values, TTL semantics, and runtime Claim
7
+ providers. Use when a workflow relies on cache-backed package primitives,
8
+ wiring CacheClaim providers, or testing cache behavior in workflow tests.
9
9
  ---
10
10
 
11
11
  # @t4h.framework/cache
12
12
 
13
- Abstract **CacheClaim** for serializable key-value storage inside activities. The package defines the claim contract only; runtimes supply concrete backends (e.g. Redis).
13
+ Abstract **CacheClaim** for serializable key-value storage used by framework-package primitives (e.g. OAuth2 token caching). The package defines the claim contract only; runtimes supply concrete backends (e.g. Redis).
14
14
 
15
15
  Package path: `framework/packages/cache`. Peer dependency: `@t4h.framework/core` (`Serializable`, `Claim`, activities).
16
16
 
@@ -65,53 +65,13 @@ Values must satisfy `Serializable` from `@t4h.framework/core`: primitives, `null
65
65
 
66
66
  ---
67
67
 
68
- ## Declaring CacheClaim in an activity
68
+ ## How workflows use it
69
69
 
70
- Follow the same `Claim` pattern as other framework claims (see `framework-core` skill). Declare the claim on the activity, access it only inside activity methods while the claim context is active (`Claim.run` stack).
71
-
72
- ```typescript
73
- import { SyncActivity, Claim } from '@t4h.framework/core'
74
- import { CacheClaim } from '@t4h.framework/cache'
75
-
76
- class GetCachedConfigActivity extends SyncActivity<
77
- [key: string],
78
- { key: string },
79
- any,
80
- any
81
- > {
82
- private readonly claims = new Claim({
83
- cache: CacheClaim,
84
- })
85
-
86
- public async toInput(key: string) {
87
- return { key }
88
- }
89
-
90
- public async run(input: { key: string }) {
91
- const cached = await this.claims.cache.get(input.key)
92
-
93
- if (cached) return cached
94
-
95
- const value = { setting: 'default' }
96
- await this.claims.cache.set(input.key, value, { ttl: 3600 })
97
-
98
- return value
99
- }
100
-
101
- public toOutput(output: any) {
102
- return output
103
- }
104
- }
105
- ```
106
-
107
- ### Cache-aside pattern
108
-
109
- 1. `await cache.get(key)` — if hit, return.
110
- 2. Compute or fetch the value.
111
- 3. `await cache.set(key, value, { ttl })` — store for later runs/replays.
112
- 4. Return the value.
113
-
114
- Use **stable, namespaced keys** (prefix + id) to avoid collisions across features or tenants.
70
+ Workflows never call `CacheClaim` directly. It backs the caching built into
71
+ framework-package primitives — most notably **OAuth2 token caching** in
72
+ `@t4h.framework/http`. Your only responsibility is that the runtime **registers
73
+ a `CacheClaim` provider** (below) so those primitives work. See **Downstream
74
+ consumer: OAuth2**.
115
75
 
116
76
  ---
117
77
 
@@ -131,46 +91,38 @@ Without a provider, claim resolution fails at runtime (`ClaimProviderNotFoundExc
131
91
 
132
92
  ## Testing cache behavior
133
93
 
134
- There are no unit tests under `packages/cache/`. Test with an in-memory `CacheClaim` double or `Claim.run`:
94
+ Test the **workflow** with `TestWorkflowEnvironment` from
95
+ `@t4h.framework/core/testing`, mocking `CacheClaim` (a workflow that uses OAuth2
96
+ also needs `HttpClientRequestClaim`). An in-memory `Map` makes a good double. See
97
+ the **framework-workflow-testing** skill for the harness API.
135
98
 
136
99
  ```typescript
137
- import { describe, expect, it, vi } from 'vitest'
138
- import { Claim } from '@t4h.framework/core'
100
+ import { TestWorkflowEnvironment, mockClaim } from '@t4h.framework/core/testing'
139
101
  import { CacheClaim } from '@t4h.framework/cache'
140
102
 
141
103
  const store = new Map<string, unknown>()
142
104
 
143
- const mockCache: CacheClaim = {
144
- get: key => store.get(key) as any,
145
- set: async (key, value) => { store.set(key, value) },
146
- } as CacheClaim
105
+ const env = TestWorkflowEnvironment.create({ now: 0 })
147
106
 
148
- await Claim.run(
149
- [{ provide: CacheClaim, value: mockCache }],
150
- () => myActivity.run(input),
151
- )
107
+ await env.execute(workflow, input, {
108
+ claims: [
109
+ mockClaim(CacheClaim, {
110
+ get: key => store.get(key) as any,
111
+ set: async (key, value) => { store.set(key, value) },
112
+ }),
113
+ // ...other claims the workflow's activities need (e.g. HttpClientRequestClaim)
114
+ ],
115
+ })
152
116
  ```
153
117
 
154
- For full workflows, pass the same provider via `WorkflowTesting.run` (see **framework-core** skill). When testing TTL-dependent logic, implement `set` with TTL semantics in the test double.
118
+ When testing TTL-dependent logic, implement `set` with TTL semantics in the test double.
155
119
 
156
120
  ---
157
121
 
158
122
  ## Downstream consumer: OAuth2 (`@t4h.framework/http`)
159
123
 
160
- `@t4h.framework/http` depends on this package for token caching only. `HttpAuth` and `OAuth2` declare `CacheClaim` via `Claim`:
161
-
162
- ```typescript
163
- // HttpAuth — Symbol-keyed claims bag
164
- public readonly [HTTP_AUTH_CLAIMS_KEY] = new Claim({ cache: CacheClaim })
165
-
166
- // OAuth2
167
- protected readonly claims = new Claim({
168
- http: HttpClientRequestClaim,
169
- cache: CacheClaim,
170
- })
171
- ```
172
-
173
- OAuth2 cache usage (`packages/http/src/models/OAuth2.ts`):
124
+ `@t4h.framework/http` depends on this package for token caching only — the
125
+ `HttpAuth` / `OAuth2` grant classes use `CacheClaim` internally to store tokens:
174
126
 
175
127
  | Concern | Implementation |
176
128
  |---------|----------------|
@@ -230,7 +182,7 @@ Register: `{ provide: CacheClaim, value: new MyCacheClaim() }`.
230
182
 
231
183
  | Package | Role |
232
184
  |---------|------|
233
- | `@t4h.framework/core` | `Claim`, `Serializable`, activities, `WorkflowTesting`, `Internals` |
185
+ | `@t4h.framework/core` | `Claim`, `Serializable`, and the `TestWorkflowEnvironment` testing harness |
234
186
  | `@t4h.framework/http` | OAuth2 token caching via `CacheClaim` |
235
187
 
236
- For claim wiring, activity structure, and testing harnesses, use the **framework-core** skill. For HTTP and OAuth2, use the **framework-http** skill.
188
+ For claim wiring use the **framework-core** skill; for the testing harness use **framework-workflow-testing**. For HTTP and OAuth2, use the **framework-http** skill.
package/CHANGELOG.md ADDED
@@ -0,0 +1,36 @@
1
+ # @t4h.framework/cache
2
+
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Updated dependencies [[`8098041`](https://github.com/tech4humans-brasil/framework/commit/80980419d59a987378b7c94372ee2f7b7dcc00f5)]:
8
+ - @t4h.framework/core@0.10.0
9
+
10
+ ## 0.5.0
11
+
12
+ ### Patch Changes
13
+
14
+ - Update skills ([`6d7e7bc`](https://github.com/tech4humans-brasil/framework/commit/6d7e7bca0c780a9c53a0c9e5aa0a865c5af67959))
15
+
16
+ ## 0.4.0
17
+
18
+ ### Patch Changes
19
+
20
+ - Internal dependency updates
21
+
22
+ ## 0.3.0
23
+
24
+ ### Minor Changes
25
+
26
+ - Adds .ai/skills in packages ([#88](https://github.com/tech4humans-brasil/framework/pull/88))
27
+
28
+ ### Patch Changes
29
+
30
+ - Remove activity prefix from cache claim class name ([`4fa4ec9`](https://github.com/tech4humans-brasil/framework/commit/4fa4ec9e319fffeae0b5c96e0ec0e9cfa4e22c22))
31
+ - Adds github workflow to run, build, tests and lint ([#18](https://github.com/tech4humans-brasil/framework/pull/18))
32
+ - Adds readme ([`d810413`](https://github.com/tech4humans-brasil/framework/commit/d810413e79a04425013c836f76a2dd72ccaf4252))
33
+ - Update package metadata and author information across multiple packages ([`2ca73df`](https://github.com/tech4humans-brasil/framework/commit/2ca73df42dc63c86ed44717b50d5402fca45b4e7))
34
+ - Improve repository info ([`1fad92d`](https://github.com/tech4humans-brasil/framework/commit/1fad92d959b804189fd1486d047115995ac81eb0))
35
+ - Fix resolve module resolution issues in check-types ([`c97a0d2`](https://github.com/tech4humans-brasil/framework/commit/c97a0d2747f38e561cc5c7d592b20de0459bc1ee))
36
+ - Update package dependencies across multiple packages ([`8b4fc1d`](https://github.com/tech4humans-brasil/framework/commit/8b4fc1d0e92d6bd880ddf4c8119fb68c49c53760))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t4h.framework/cache",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "Cache module for the T4H Framework",
5
5
  "homepage": "https://github.com/tech4humans-brasil/framework/tree/main/packages/cache",
6
6
  "bugs": "https://github.com/tech4humans-brasil/framework/issues",
@@ -30,11 +30,11 @@
30
30
  "prepublishOnly": "yarn build"
31
31
  },
32
32
  "devDependencies": {
33
- "@t4h.framework/core": "^0.6.0",
33
+ "@t4h.framework/core": "^0.10.0",
34
34
  "typescript": "^5.9.3"
35
35
  },
36
36
  "peerDependencies": {
37
- "@t4h.framework/core": "^0.6.0"
37
+ "@t4h.framework/core": "^0.10.0"
38
38
  },
39
39
  "packageManager": "yarn@4.12.0",
40
40
  "engines": {
@@ -1,9 +0,0 @@
1
- import type { Serializable } from '@t4h.framework/core';
2
- export interface ActivityCacheClaimSetOptions {
3
- ttl?: number;
4
- }
5
- export declare abstract class ActivityCacheClaim {
6
- abstract get<T extends Serializable>(key: string): T | undefined | Promise<T | undefined>;
7
- abstract set(key: string, value: Serializable, options?: ActivityCacheClaimSetOptions): Promise<void>;
8
- }
9
- //# sourceMappingURL=ActivityCacheClaim.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ActivityCacheClaim.d.ts","sourceRoot":"","sources":["../src/ActivityCacheClaim.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAEvD,MAAM,WAAW,4BAA4B;IAC3C,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,8BAAsB,kBAAkB;aACtB,GAAG,CAAC,CAAC,SAAS,YAAY,EACxC,GAAG,EAAE,MAAM,GACV,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;aAEzB,GAAG,CACjB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,YAAY,EACnB,OAAO,CAAC,EAAE,4BAA4B,GACrC,OAAO,CAAC,IAAI,CAAC;CACjB"}
@@ -1,3 +0,0 @@
1
- export class ActivityCacheClaim {
2
- }
3
- //# sourceMappingURL=ActivityCacheClaim.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ActivityCacheClaim.js","sourceRoot":"","sources":["../src/ActivityCacheClaim.ts"],"names":[],"mappings":"AAMA,MAAM,OAAgB,kBAAkB;CAUvC"}