fix(visitor): remove error method from context
BREAKING CHANGE: rule errors must be grouped and returned in the rule result, fixing #114 and keeping the context immutable.
This commit is contained in:
parent
247e1ab03d
commit
842006c34a
|
@ -1,6 +1,6 @@
|
||||||
import Ajv from 'ajv';
|
import Ajv from 'ajv';
|
||||||
import { JSONPath } from 'jsonpath-plus';
|
import { JSONPath } from 'jsonpath-plus';
|
||||||
import { Logger, logWithLevel } from 'noicejs';
|
import { Logger } from 'noicejs';
|
||||||
|
|
||||||
import { doesExist, hasItems } from '../utils';
|
import { doesExist, hasItems } from '../utils';
|
||||||
import { VisitorError } from './VisitorError';
|
import { VisitorError } from './VisitorError';
|
||||||
|
@ -63,14 +63,6 @@ export class VisitorContext implements VisitorContextOptions, VisitorResult {
|
||||||
return this.ajv.compile(schema);
|
return this.ajv.compile(schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
public error(...errors: Array<VisitorError>) {
|
|
||||||
for (const err of errors) {
|
|
||||||
logWithLevel(this.logger, err.level, err.data, err.msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.errorBuffer.push(...errors);
|
|
||||||
}
|
|
||||||
|
|
||||||
public mergeResult(other: VisitorResult): this {
|
public mergeResult(other: VisitorResult): this {
|
||||||
this.changeBuffer.push(...other.changes);
|
this.changeBuffer.push(...other.changes);
|
||||||
this.errorBuffer.push(...other.errors);
|
this.errorBuffer.push(...other.errors);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { ConsoleLogger } from 'noicejs';
|
import { ConsoleLogger } from 'noicejs';
|
||||||
import { mock, spy } from 'sinon';
|
import { mock } from 'sinon';
|
||||||
|
|
||||||
import { createRuleSelector, resolveRules, visitRules } from '../../src/rule';
|
import { createRuleSelector, resolveRules, visitRules } from '../../src/rule';
|
||||||
import { SchemaRule } from '../../src/rule/SchemaRule';
|
import { SchemaRule } from '../../src/rule/SchemaRule';
|
||||||
|
@ -203,7 +203,6 @@ describeLeaks('rule visitor', async () => {
|
||||||
},
|
},
|
||||||
logger: new ConsoleLogger(),
|
logger: new ConsoleLogger(),
|
||||||
});
|
});
|
||||||
const errorSpy = spy(ctx, 'error');
|
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
foo: 3,
|
foo: 3,
|
||||||
|
@ -227,6 +226,5 @@ describeLeaks('rule visitor', async () => {
|
||||||
|
|
||||||
const results = await rule.visit(ctx, data);
|
const results = await rule.visit(ctx, data);
|
||||||
expect(results.errors.length).to.equal(0);
|
expect(results.errors.length).to.equal(0);
|
||||||
expect(errorSpy).to.have.callCount(0);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue