@t4h.framework/cache 0.6.9 → 0.6.11

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.
@@ -18,14 +18,12 @@ Package path: `framework/packages/cache`. Peer dependency: `@t4h.framework/core`
18
18
 
19
19
  ## Import surface
20
20
 
21
- Only symbols exported from `src/cache.ts` exist in the public API:
21
+ Import from the package entry. Its `exports` map has only `.`, so `tsc` rejects a deep import:
22
22
 
23
23
  ```typescript
24
24
  import { CacheClaim, type CacheClaimSetOptions } from '@t4h.framework/cache'
25
25
  ```
26
26
 
27
- Do not invent additional exports or helpers not present in this package.
28
-
29
27
  ---
30
28
 
31
29
  ## API contract
@@ -58,16 +56,16 @@ abstract class CacheClaim {
58
56
 
59
57
  | Method | Behavior |
60
58
  |--------|----------|
61
- | `get` | Returns stored value or `undefined`. May be sync or async — **always `await`** at call sites. |
59
+ | `get` | Returns stored value or `undefined`. May be sync or async. |
62
60
  | `set` | Stores a `Serializable` value. Always returns `Promise<void>`. Optional `ttl` in `options`. |
63
61
 
64
- Values must satisfy `Serializable` from `@t4h.framework/core`: primitives, `null`, `undefined`, `Binary`, `SerializableClass`, and arrays/objects composed of those.
62
+ `value` is typed `Serializable` from `@t4h.framework/core` (primitives, `null`, `undefined`, `Binary`, `SerializableClass`, and arrays/objects of those), so `tsc` rejects other values.
65
63
 
66
64
  ---
67
65
 
68
66
  ## How workflows use it
69
67
 
70
- Workflows never call `CacheClaim` directly. It backs the caching built into
68
+ Workflow code does not call `CacheClaim` directly. The claim backs the caching built into
71
69
  framework-package primitives — most notably **OAuth2 token caching** in
72
70
  `@t4h.framework/http`. Your only responsibility is that the runtime **registers
73
71
  a `CacheClaim` provider** (below) so those primitives work. See **Downstream
@@ -85,7 +83,7 @@ The runtime (or test harness) must register a concrete implementation:
85
83
 
86
84
  `RedisCacheClaimImpl` is illustrative — implement `CacheClaim` in the runtime layer; this package does not ship a production backend.
87
85
 
88
- Without a provider, claim resolution fails at runtime (`ClaimProviderNotFoundException` and related errors from core).
86
+ A missing provider throws `ClaimProviderNotFoundException` (core `exceptions/ClaimException.ts`).
89
87
 
90
88
  ---
91
89
 
@@ -97,18 +95,23 @@ also needs `HttpClientRequestClaim`). An in-memory `Map` makes a good double. Se
97
95
  the **framework-workflow-testing** skill for the harness API.
98
96
 
99
97
  ```typescript
100
- import { TestWorkflowEnvironment, mockClaim } from '@t4h.framework/core/testing'
101
98
  import { CacheClaim } from '@t4h.framework/cache'
99
+ import type { Serializable } from '@t4h.framework/core'
100
+ import { TestWorkflowEnvironment, mockClaim } from '@t4h.framework/core/testing'
102
101
 
103
- const store = new Map<string, unknown>()
102
+ const store = new Map<string, Serializable>()
104
103
 
105
104
  const env = TestWorkflowEnvironment.create({ now: 0 })
106
105
 
107
106
  await env.execute(workflow, input, {
108
107
  claims: [
109
108
  mockClaim(CacheClaim, {
110
- get: key => store.get(key) as any,
111
- set: async (key, value) => { store.set(key, value) },
109
+ get: <T extends Serializable>(key: string): T | undefined | Promise<T | undefined> =>
110
+ store.get(key) as T | undefined,
111
+ set: (key, value) => {
112
+ store.set(key, value)
113
+ return Promise.resolve()
114
+ },
112
115
  }),
113
116
  // ...other claims the workflow's activities need (e.g. HttpClientRequestClaim)
114
117
  ],
@@ -169,10 +172,7 @@ Register: `{ provide: CacheClaim, value: new MyCacheClaim() }`.
169
172
 
170
173
  | Do | Don't |
171
174
  |----|-------|
172
- | `await` both `get` and `set` | Assume `get` is always synchronous |
173
- | Store only `Serializable` values | Cache class instances, functions, or `Buffer` unless wrapped as `Binary` |
174
175
  | Namespace keys (`feature:id`) | Use bare global keys like `"token"` |
175
- | Provide `CacheClaim` in runtime/test `claims` | Use cache outside `Claim` / activity context |
176
176
  | Use a test double with explicit TTL when testing expiry | Assume any in-memory mock enforces TTL unless you implement it |
177
177
  | Match OAuth2 TTL units (ms) when mirroring that pattern | Mix seconds and milliseconds for `ttl` without checking the caller |
178
178
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @t4h.framework/cache
2
2
 
3
+ ## 0.6.11
4
+
5
+ ### Patch Changes
6
+
7
+ - [#240](https://github.com/tech4humans-brasil/framework/pull/240) [`0606115`](https://github.com/tech4humans-brasil/framework/commit/0606115e2e0baa994e9f0ed3559ee54ecac88e44) Thanks [@gusteycamargo](https://github.com/gusteycamargo)! - The skills do not repeat a rule that a lint rule, `tsc` or a runtime error already enforces. Each such rule is now one line that names the gate. The examples that broke a gate (`process.env`, `as any`, an inline secret, an `EnvDesign` in a workflow file, `ref.output` before `wait()`) are correct now.
8
+
9
+ ## 0.6.10
10
+
3
11
  ## 0.6.9
4
12
 
5
13
  ## 0.6.8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@t4h.framework/cache",
3
- "version": "0.6.9",
3
+ "version": "0.6.11",
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",
@@ -26,11 +26,12 @@
26
26
  "scripts": {
27
27
  "build": "tsc --project tsconfig.build.json",
28
28
  "check-types": "tsc --noEmit",
29
- "lint": "eslint .",
29
+ "check-package": "publint --strict && attw --pack . --profile esm-only",
30
+ "lint": "eslint . --max-warnings 0",
30
31
  "prepublishOnly": "yarn build"
31
32
  },
32
33
  "devDependencies": {
33
- "@t4h.framework/core": "^0.18.0",
34
+ "@t4h.framework/core": "^0.20.0",
34
35
  "typescript": "^5.9.3"
35
36
  },
36
37
  "peerDependencies": {