|
|
@ -10,29 +10,29 @@ const { validateOptions } = require("@validatem/core");
|
|
|
|
const required = require("@validatem/required");
|
|
|
|
const required = require("@validatem/required");
|
|
|
|
const isFunction = require("@validatem/is-function");
|
|
|
|
const isFunction = require("@validatem/is-function");
|
|
|
|
const defaultTo = require("@validatem/default-to");
|
|
|
|
const defaultTo = require("@validatem/default-to");
|
|
|
|
|
|
|
|
const wrapValueAsOption = require("@validatem/wrap-value-as-option");
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME: Update other stream implementations to new API
|
|
|
|
// FIXME: Update other stream implementations to new API
|
|
|
|
module.exports = function simpleSinkStream(_options) {
|
|
|
|
module.exports = function simpleSinkStream(_options) {
|
|
|
|
let { onResult, onEnd, onAbort } = validateOptions(arguments, {
|
|
|
|
let { onResult, onEnd, onAbort } = validateOptions(arguments, [
|
|
|
|
onResult: [ required, isFunction ],
|
|
|
|
required,
|
|
|
|
onEnd: [ isFunction, defaultTo.literal(defaultOnEnd) ],
|
|
|
|
wrapValueAsOption("onResult"), {
|
|
|
|
onAbort: [ isFunction, defaultTo.literal(defaultOnAbort) ]
|
|
|
|
onResult: [ required, isFunction ],
|
|
|
|
});
|
|
|
|
onEnd: [ isFunction, defaultTo.literal(function defaultOnEnd() {
|
|
|
|
|
|
|
|
// We return whatever value we got last from the specified onResult callback.
|
|
|
|
|
|
|
|
return lastResult;
|
|
|
|
|
|
|
|
})],
|
|
|
|
|
|
|
|
onAbort: [ isFunction, defaultTo.literal(function defaultOnAbort() {
|
|
|
|
|
|
|
|
// no-op
|
|
|
|
|
|
|
|
})]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
let lastResult;
|
|
|
|
let lastResult;
|
|
|
|
let onEndCalled = false;
|
|
|
|
let onEndCalled = false;
|
|
|
|
let onEndResult;
|
|
|
|
let onEndResult;
|
|
|
|
let abortHandled = false;
|
|
|
|
let abortHandled = false;
|
|
|
|
|
|
|
|
|
|
|
|
function defaultOnEnd() {
|
|
|
|
|
|
|
|
// We return whatever value we got last from the specified onResult callback.
|
|
|
|
|
|
|
|
return lastResult;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function defaultOnAbort() {
|
|
|
|
|
|
|
|
// no-op
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
description: `simple sink stream`,
|
|
|
|
description: `simple sink stream`,
|
|
|
|
abort: propagateAbort,
|
|
|
|
abort: propagateAbort,
|
|
|
|