Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.flatMap(response => {
// Can't guarantee any type of response on 500s
if (response.status >= 500) {
return Kefir.constantError(new ServerError(response));
}
if (response.status >= 400) {
return Kefir.constantError(new ClientError(response));
}
return response.json().mapErrors(error => new JsonError(error));
})
.flatMap(body =>
let precheck$ = Kefir.constant('Configuration correct');
if (typeof el === 'function') {
el = el(document);
if (!(el instanceof Kefir.Observable)) {
precheck$ = Kefir.constantError(new TypeError(`type ${typeof el} returned from el is not valid`));
}
} else if (el instanceof Element) {
el = Kefir.constant(el);
} else {
precheck$ = Kefir.constantError(new TypeError(`el of type ${typeof el} is not valid`));
}
if (typeof view !== 'function') {
precheck$ = Kefir.constantError(new TypeError(`component of type ${typeof el} is not valid`));
}
if (typeof selectProps !== 'function') {
precheck$ = Kefir.constantError(new TypeError(`selectProps of type ${typeof el} is not valid`));
}
return (actions$, state$) => precheck$
.flatMap(documentIsLoaded)
.flatMap(isLoaded =>
isLoaded ?
// ensures async consistency
Kefir.later(0, true) :
Kefir.fromEvents(document, 'DOMContentLoaded')
)
.flatMap(() => el)
.take(1).takeErrors(1)
export function parseQueryAsync(query: string): Kefir.Property {
try {
return Kefir.constant(parseQuery(query));
} catch (e) {
console.error('Error while parsing the query: ' + e);
return Kefir.constantError(e);
}
}
.flatMap<output>(result => {
if (result.batch) {
return Kefir.constant(result.batch.get(input));
} else {
return Kefir.constantError(result.error);
}
}).take(1).takeErrors(1).toProperty();
}</output>
function getImageBindings(
imageOrRegion: Rdf.Iri,
imageIdPattern: string,
repository: string
): Kefir.Property {
const query = cloneQuery(IMAGE_REGION_INFO_QUERY);
let imageIdPatterns: SparqlJs.Pattern[];
try {
imageIdPatterns = SparqlUtil.parsePatterns(imageIdPattern, query.prefixes);
} catch (err) {
return Kefir.constantError(new WrappingError(
`Failed to parse image ID patterns '${imageIdPattern}':`, err));
}
new PatternBinder('__imageIdPattern__', imageIdPatterns).sparqlQuery(query);
const parametrizedQuery = SparqlClient.setBindings(query, {'__iri__': imageOrRegion});
return SparqlClient.select(parametrizedQuery, {context: {repository: repository}})
}
errs => Kefir.constantError(new ValidationError(errs)),
body => Kefir.constant(success(body)),
deleteAnnotation(annotationId: string, onSuccess: () => void, onError: () => void) {
const task = this.endpoint.remove
? this.endpoint.remove(Rdf.iri(annotationId))
: Kefir.constantError(new Error(
'AnnotationEndpoint.delete is not implemented'));
task.onValue(onSuccess).onError(onError);
}
}
let timeoutError = (delayMs) =>
K.later(delayMs, K.constantError(new Error("timeout"))).flatMap()
const exec = callback => {
if (typeof spec.content === 'string') {
return callback(selectPath(state, spec), spec.content)
.map(() => fileCreated(spec.path));
}
if (typeof spec.template === 'string') {
return template(spec.template)
.map(tmpl => tmpl(selectContext(state, spec)))
.flatMap(content => callback(selectPath(state, spec), content))
.map(() => fileCreated(spec.path));
}
return Kefir.constantError(new TypeError(`Invalid spec: ${spec.path}. No content or template.`));
};
errs => Kefir.constantError(new ValidationError(errs)),
Kefir.constant,