You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/migrating-from-feathers-hooks-common.md
+40Lines changed: 40 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,6 +46,46 @@ The old `cache` hook only worked for `get` requests and did not work with varyin
46
46
47
47
The new `cache` hook caches `get` and `find` requests and considers the `params` object when caching. This means that if you call the same `get` or `find` request with different `params`, it will cache each unique request separately.
48
48
49
+
## `checkContext`
50
+
51
+
The `checkContext` utility has been updated with an options object syntax and now supports **TypeScript type narrowing**. After calling `checkContext`, the compiler automatically narrows `context.type`, `context.method`, and `context.path` based on the options you pass.
52
+
53
+
The old positional arguments still work but the options object is recommended:
// After checkContext, TypeScript narrows the types:
71
+
context.type; // 'before'
72
+
context.method; // 'create' | 'patch'
73
+
```
74
+
75
+
You can also narrow by `path`, which was not available in the old API:
76
+
77
+
```ts
78
+
checkContext(context, {
79
+
type: ["before", "around"],
80
+
method: ["create", "patch"],
81
+
path: "users",
82
+
});
83
+
84
+
context.type; // 'before' | 'around'
85
+
context.method; // 'create' | 'patch'
86
+
context.path; // 'users'
87
+
```
88
+
49
89
## `callingParams`
50
90
51
91
The `callingParams` utility was removed. If you need it please reach out to us in this [github issue](https://github.com/feathersjs/feathers-utils/issues/1).
0 commit comments