@comunica/mediator-number
Advanced tools
Comparing version 3.2.4-alpha.47.0 to 3.3.0
@@ -1,2 +0,2 @@ | ||
import type { Actor, IAction, IActorOutput, IActorReply, IActorTest, IMediatorArgs, TestResult } from '@comunica/core'; | ||
import type { Actor, IAction, IActorOutput, IActorReply, IActorTest, IMediatorArgs } from '@comunica/core'; | ||
import { Mediator } from '@comunica/core'; | ||
@@ -10,8 +10,8 @@ /** | ||
*/ | ||
export declare class MediatorNumber<A extends Actor<I, T, O, TS>, I extends IAction, T extends IActorTest, O extends IActorOutput, TS> extends Mediator<A, I, T, O, TS> implements IMediatorNumberArgs<A, I, T, O, TS> { | ||
export declare class MediatorNumber<A extends Actor<I, T, O>, I extends IAction, T extends IActorTest, O extends IActorOutput> extends Mediator<A, I, T, O> implements IMediatorNumberArgs<A, I, T, O> { | ||
readonly field: string; | ||
readonly type: 'min' | 'max'; | ||
readonly ignoreFailures: boolean; | ||
readonly ignoreErrors: boolean; | ||
readonly indexPicker: (tests: T[]) => number; | ||
constructor(args: IMediatorNumberArgs<A, I, T, O, TS>); | ||
constructor(args: IMediatorNumberArgs<A, I, T, O>); | ||
/** | ||
@@ -23,5 +23,5 @@ * @return {(tests: T[]) => number} A function that returns the index of the test result | ||
protected getOrDefault(value: number | undefined, defaultValue: number): number; | ||
protected mediateWith(action: I, testResults: IActorReply<A, I, T, O, TS>[]): Promise<TestResult<A, TS>>; | ||
protected mediateWith(action: I, testResults: IActorReply<A, I, T, O>[]): Promise<A>; | ||
} | ||
export interface IMediatorNumberArgs<A extends Actor<I, T, O, TS>, I extends IAction, T extends IActorTest, O extends IActorOutput, TS> extends IMediatorArgs<A, I, T, O, TS> { | ||
export interface IMediatorNumberArgs<A extends Actor<I, T, O>, I extends IAction, T extends IActorTest, O extends IActorOutput> extends IMediatorArgs<A, I, T, O> { | ||
/** | ||
@@ -38,5 +38,5 @@ * The field name of the test result field over which must be mediated. | ||
/** | ||
* If actors that throw fail tests should be ignored | ||
* If actors that throw test errors should be ignored | ||
*/ | ||
ignoreFailures?: boolean; | ||
ignoreErrors?: boolean; | ||
} |
@@ -43,29 +43,19 @@ "use strict"; | ||
async mediateWith(action, testResults) { | ||
let wrappedResults = await Promise.all(testResults.map(({ reply }) => reply)); | ||
// Collect failures if we want to ignore them | ||
const failures = []; | ||
if (this.ignoreFailures) { | ||
let promises = testResults.map(({ reply }) => reply); | ||
const errors = []; | ||
if (this.ignoreErrors) { | ||
const dummy = {}; | ||
dummy[this.field] = null; | ||
wrappedResults = wrappedResults.map((result) => { | ||
if (result.isFailed()) { | ||
failures.push(result.getFailMessage()); | ||
return (0, core_1.passTestWithSideData)(dummy, undefined); | ||
} | ||
return result; | ||
}); | ||
// eslint-disable-next-line ts/no-floating-promises | ||
promises = promises.map(promise => promise.catch((error) => { | ||
errors.push(error); | ||
return dummy; | ||
})); | ||
} | ||
// Resolve values | ||
const sideDatas = []; | ||
const results = wrappedResults.map((result, i) => { | ||
const value = result.getOrThrow(); | ||
sideDatas[i] = result.getSideData(); | ||
return value; | ||
}); | ||
// Determine one value | ||
const results = await Promise.all(promises); | ||
const index = this.indexPicker(results); | ||
if (index < 0) { | ||
return (0, core_1.failTest)(this.constructFailureMessage(action, failures)); | ||
throw new Error(`All actors rejected their test in ${this.name}\n${errors.map(error => error.message).join('\n')}`); | ||
} | ||
return (0, core_1.passTestWithSideData)(testResults[index].actor, sideDatas[index]); | ||
return testResults[index].actor; | ||
} | ||
@@ -72,0 +62,0 @@ } |
{ | ||
"name": "@comunica/mediator-number", | ||
"version": "3.2.4-alpha.47.0", | ||
"version": "3.3.0", | ||
"description": "A mediator for a single mediation number value", | ||
"lsd:module": true, | ||
"license": "MIT", | ||
"funding": { | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/comunica-association" | ||
}, | ||
"homepage": "https://comunica.dev/", | ||
@@ -42,5 +38,5 @@ "repository": { | ||
"dependencies": { | ||
"@comunica/core": "3.2.4-alpha.47.0" | ||
"@comunica/core": "^3.3.0" | ||
}, | ||
"gitHead": "85bd4c5cf07dfc293ebbc3a1416b70e2db8bfc48" | ||
"gitHead": "02bde397d206f1f5a523643a6a604c89e792e2f9" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
30837
119
+ Added@comunica/core@3.3.0(transitive)
+ Added@comunica/types@3.3.0(transitive)
- Removed@comunica/core@3.2.4-alpha.47.0(transitive)
- Removed@comunica/types@3.2.4-alpha.47.0(transitive)
- Removedlru-cache@10.4.3(transitive)
Updated@comunica/core@^3.3.0