Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getOldLogs (appId, beforeDate, afterDate, filter, deployment_id) {
const limit = (beforeDate == null && afterDate == null) ? 300 : null;
const before = (beforeDate != null) ? beforeDate.toISOString() : null;
const after = (afterDate != null) ? afterDate.toISOString() : null;
const logsProm = fetchOldLogs({ appId, limit, before, after, filter, deployment_id }).then(sendToApi);
return Bacon.fromPromise(logsProm)
.flatMapLatest((logs) => Bacon.fromArray(logs.reverse()));
};
function getNewLogs (appId, before, after, filter, deploymentId) {
Logger.println('Waiting for application logs…');
Logger.debug('Opening a websocket in order to fetch logs…');
return Bacon
.fromPromise(getHostAndTokens())
.flatMapLatest(({ apiHost, tokens }) => {
return Bacon.fromBinder((sink) => {
const logsStream = new LogsStream({ apiHost, tokens, appId, filter, deploymentId });
return logsStream.openResilientStream({
onMessage: sink,
onError: (error) => sink(new Bacon.Error(error)),
infinite: false,
retryDelay: 2000,
retryTimeout: 30000,
});
});
})
.filter((line) => {
const lineDate = Date.parse(line._source['@timestamp']);
const isBefore = !before || lineDate < before.getTime();
export function send(fetch, { url, method, headers, body }) {
const s_res = Bacon.fromPromise(
fetch(url, {
method,
headers: Map.prototype.isPrototypeOf(headers)
? _.zipObject(Array.from(headers.entries()))
: headers || {},
body
})
);
const s_body = s_res.flatMapLatest(parseResponse);
return s_body.toProperty();
}
function resolveFullCommitId (commitId) {
if (commitId == null) {
return Bacon.constant(null);
}
const fullCommitIdPromise = getRepo()
.then((repo) => git.expandOid({ ...repo, oid: commitId }));
return Bacon.fromPromise(fullCommitIdPromise)
.flatMapError((e) => {
if (e.code === 'ShortOidNotFound') {
return new Bacon.Error(`Commit id ${commitId} is ambiguous`);
}
return e;
});
}
var streamWithResolvedPromises = rawValues.flatMap(function(x) {
if (p.isThenable(x)) {
return Bacon.fromPromise(x);
} else {
return x;
}
});
var stream = this.stream = streamWithResolvedPromises.skipDuplicates().withHandler(function(event) {
function getByName (api, name) {
return Bacon.fromPromise(getByNameProm(name));
}
'use strict'
var Bacon = require('baconjs')
var _ = require('lodash')
require('es6-promise').polyfill()
require('isomorphic-fetch')
var LiveDataActions = require('../actions/LiveDataActions.js')
var METADATA_URL = 'http://rata.digitraffic.fi/api/v1/metadata/station'
var stations = Bacon.fromPromise(fetch(METADATA_URL))
.flatMap(response => Bacon.fromPromise(response.json()))
.toProperty()
var stationsByCode = stations.map(stations =>
_(stations)
.map(station => {
station.stationName = station.stationName.replace(' asema', '')
return station
})
.indexBy('stationShortCode')
.value()
)
var metadataForStation =
Bacon.zipAsArray(stationsByCode, LiveDataActions.station)
.map(params => {
function openPage (url) {
Logger.debug('Opening browser');
return Bacon.fromPromise(open(url, { wait: false }));
}
function get({url}) {
const request = fetch(url, {credentials: 'include'})
.then(checkStatus)
.then(parseJSON)
return Bacon.fromPromise(request)
}
function httpGet(url) {
const abortOnUnsubscribe = true
return Bacon.fromPromise(http({url, method: "get", crossOrigin: true, type: "json"}), abortOnUnsubscribe)
}