@resin/pinejs
Version:
Pine.js is a sophisticated rules-driven API engine that enables you to define rules in a structured subset of English. Those rules are used in order for Pine.js to generate a database schema and the associated [OData](http://www.odata.org/) API. This make
50 lines • 1.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const _ = require("lodash");
const Promise = require("bluebird");
exports.liftP = (fn) => {
return (a) => {
if (_.isArray(a)) {
return Promise.mapSeries(a, fn);
}
else {
return Promise.resolve(a).then(fn);
}
};
};
exports.settleMapSeries = (a, fn) => {
const runF = Promise.method(fn);
return Promise.mapSeries(a, _.flow(runF, wrap));
};
const ensureError = (err) => {
if (_.isError(err)) {
return err;
}
return new Error(err);
};
const wrap = (p) => {
return p.then(_.identity, ensureError);
};
const mapTill = (a, fn) => {
const runF = Promise.method(fn);
const results = [];
return Promise.each(a, (p) => {
return runF(p)
.then((result) => {
results.push(result);
}).tapCatch((err) => {
results.push(ensureError(err));
});
})
.return(results)
.catchReturn(results);
};
exports.getMappingFn = (headers) => {
if (headers != null && headers.prefer == 'odata.continue-on-error') {
return exports.settleMapSeries;
}
else {
return mapTill;
}
};
//# sourceMappingURL=control-flow.js.map