From 32162b4f893285e6290abddb596d04ca315b197b Mon Sep 17 00:00:00 2001 From: Icebob Date: Wed, 4 Dec 2024 18:33:39 +0100 Subject: [PATCH] update changelog, migration guide --- CHANGELOG.md | 3 ++- docs/MIGRATION_GUIDE_0.15.md | 47 +++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7070d5814..b48388670 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -352,9 +352,10 @@ The Moleculer protocol supports headers in response, as well (`ctx.responseHeade #### The `getCacheKey` and `opts.keygen` signature has been changed Old signature: `getCacheKey(actionName, params, meta, keys, actionKeygen)` +Old signature: `keygen: (actionName, params, meta, keys, headers) => {}` New signature: `getCacheKey(action, opts, ctx)` - +New signature: `keygen: (action, opts, ctx) => {}` #### Added `missingResponse` option to cacher options diff --git a/docs/MIGRATION_GUIDE_0.15.md b/docs/MIGRATION_GUIDE_0.15.md index 00686fece..fed772b8e 100644 --- a/docs/MIGRATION_GUIDE_0.15.md +++ b/docs/MIGRATION_GUIDE_0.15.md @@ -245,7 +245,52 @@ module.exports = { About new configuration options, check this documentation: https://kafka.js.org/docs/configuration -## The Fastest Validator options changed. +## Custom cacher keygen signatire changed + +The old `(actionName, params, meta, keys, headers)` key generator function signature has been changed to `getCacheKey(action, opts, ctx)`. For old parameters, use `action.name`, `ctx.params`, `ctx.meta`, `opt.keys`, `ctx.headers` instead. + +### Old way in action definition + +```js +module.exports = { + name: "posts", + actions: { + list: { + cache: { + keygen: (actionName, params, meta, keys, headers) => { + return `${actionName}:${JSON.stringify(params)}`; + } + } + handler(ctx) { + // Do something... + } + } + } +}; +``` + +### New way to receive a stream + +```js +module.exports = { + name: "posts", + actions: { + list: { + cache: { + keygen: (action, opts, ctx) => { + return `${action.name}:${JSON.stringify(ctx.params)}`; + } + } + handler(ctx) { + // Do something... + } + } + } +}; +``` + + +## The Fastest Validator options changed In 0.15 the `useNewCustomCheckFunction` default value is changed from `false` to `true`. It means, if you have old custom checker function in your parameter validation schemas, you should rewrite it to the new custom check function form.