Skip to content

Commit 57f1a9e

Browse files
committed
Pass ctx to include precondition
1 parent c97f328 commit 57f1a9e

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
55
The format is based on Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
66
and this project adheres to Semantic Versioning](https://semver.org/spec/v2.0.0.html)
77

8+
## 5.0.2
9+
10+
- Fixed bug where include precondition was not passed the ctx
11+
812
## 5.0.1
913

1014
- structuredClone throws on unclonable properties (like functions). Replaced with rfdc.

lib/processors/include.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ module.exports = (params = {}) => {
1212

1313
function include(params) {
1414
const { paths = [], precondition = ALWAYS_PASS } = params;
15-
return ({ level, message, context, record }) => {
16-
if (!precondition({ level, message, context, record })) return record;
15+
return ({ level, message, ctx, record }) => {
16+
if (!precondition({ level, message, ctx, record })) return record;
1717
return getPatch(paths, record);
1818
};
1919
}
2020

2121
function includeBasePath(params) {
2222
const { basePath, paths = [], precondition = ALWAYS_PASS } = params;
23-
return ({ level, message, context, record }) => {
24-
if (!precondition({ level, message, context, record })) return record;
23+
return ({ level, message, ctx, record }) => {
24+
if (!precondition({ level, message, ctx, record })) return record;
2525
if (!has(record, basePath, { split: objectsAndArrays })) return record;
2626

2727
const target = get(record, basePath, { split: objectsAndArrays });

test/processors/include.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe('include', () => {
109109

110110
describe('with precondition', () => {
111111
it('should run the processor the precondition passes', () => {
112-
const fn = include({ precondition: ({ record }) => record.a.b === 1, paths: ['a.b', 'x'] });
112+
const fn = include({ precondition: () => true, paths: ['a.b', 'x'] });
113113
const result = fn({ record: { a: { b: 1, c: 2 }, m: 1, x: { y: 1, z: 2 } } });
114114
eq(result, { a: { b: 1 }, x: { y: 1, z: 2 } });
115115
});

0 commit comments

Comments
 (0)