@hile/redis-idempotency 2.1.2 → 3.0.1
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/README.md +17 -14
- package/SKILL.md +2 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -170,26 +170,29 @@ await pipeline.dispatch(ctx)
|
|
|
170
170
|
console.log(ctx.state.result)
|
|
171
171
|
```
|
|
172
172
|
|
|
173
|
-
|
|
173
|
+
With `@hile/model@3.0.0+`, `defineModel()` returns `ctx.state.result` after the pipeline finishes, so `idempotent()` can be used directly as model middleware when the middleware is created with an already available Redis client. A cached idempotency hit can short-circuit the pipeline and still become the model result:
|
|
174
174
|
|
|
175
175
|
```typescript
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
{
|
|
176
|
+
function createDebitModel(redis: Redis) {
|
|
177
|
+
return defineModel({
|
|
178
|
+
pipelines: [
|
|
179
|
+
idempotent({
|
|
180
|
+
redis,
|
|
181
|
+
key: (input: DebitInput) => `idem:prod:wallet:debit:${input.tenantId}:${input.requestId}`,
|
|
182
|
+
fingerprint: stableHash,
|
|
184
183
|
lockTtl: 60_000,
|
|
185
184
|
resultTtl: 86_400_000,
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
)
|
|
189
|
-
|
|
190
|
-
}
|
|
185
|
+
}),
|
|
186
|
+
],
|
|
187
|
+
async main(input: DebitInput) {
|
|
188
|
+
return performDebit(input, redis)
|
|
189
|
+
},
|
|
190
|
+
})
|
|
191
|
+
}
|
|
191
192
|
```
|
|
192
193
|
|
|
194
|
+
For normal Hile models that load Redis through `services: [redisService]`, or for code that needs a narrower critical section than the whole model, use function-level `withIdempotency()` inside `main()` instead.
|
|
195
|
+
|
|
193
196
|
## Error Types
|
|
194
197
|
|
|
195
198
|
| Error | When it happens | Recommended handling |
|
package/SKILL.md
CHANGED
|
@@ -44,9 +44,9 @@ Build `stableHash()` fingerprints from plain DTOs. It rejects unsupported object
|
|
|
44
44
|
|
|
45
45
|
Default cached results must be plain JSON values. If the wrapped function returns `Date`, `BigInt`, class instances, `Map` / `Set`, or any other rich type, pass `resultCodec` so cache hits deserialize to the same shape as the first call.
|
|
46
46
|
|
|
47
|
-
##
|
|
47
|
+
## Model Guidance
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
With `@hile/model@3.0.0+`, `defineModel()` returns `ctx.state.result` after the pipeline finishes, so `idempotent()` can short-circuit model execution when the middleware is created with an already available Redis client. Prefer function-level `withIdempotency()` inside `defineModel().main` when Redis is loaded through model `services`, or when only a smaller part of `main()` needs duplicate-execution protection.
|
|
50
50
|
|
|
51
51
|
## Failure Policy
|
|
52
52
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hile/redis-idempotency",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"vitest": "^4.0.18"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@hile/model": "^
|
|
25
|
+
"@hile/model": "^3.0.1"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "ffc9f14ed2591075290c77c1bcc0afc67ecf1794"
|
|
28
28
|
}
|