Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const startup: Delta = (action$, state$) =>
Kefir.concat([
// @TODO(mAAdhaTTah) use `constant` when useDelta is fixed.
Kefir.later(0, actions.startup.request()),
state$.take(1).flatMap(
(state): Observable => {
const ret = toObs(state.e2e.startup?.())
.map(msg => actions.startup.success({ msg }))
.flatMapErrors(err => Kefir.constant(actions.startup.failure(err)));
return state.e2e.shutdown == null
? ret.takeUntilBy(action$.thru(ofType(actions.shutdown.request)))
: ret;
}
)
]);
.flatMapLatest(state => Kefir.concat([
Kefir.constant(ajaxStarted()),
optionsAjax$(state)
.flatMap((response: ObsResponse) => response.json())
.map(ajaxFinished)
.mapErrors(ajaxFailed)
]));
}
.flatMapLatest(({ route, runs, globals, jobs }: JobProps): Kefir.Observable => {
if (typeof route.parts.run === 'string') {
const run = runs.find((run: Run) => route.parts.run === run.ID);
if (!run) {
return Kefir.never();
}
return Kefir.concat([
Kefir.constant(messagesFetchStarted()),
ajax$(run.console_url, {
method: 'GET',
credentials: 'include',
headers: {
'X-WP-Nonce': globals.nonce,
'Content-Type': 'application/json'
}
})
.flatMap((response: ObsResponse) => response.json())
.map((response: GetConsoleResponse) => messagesFetchSucceeded(response))
.flatMapErrors((err: TypeError) => Kefir.constant(messagesFetchFailed(err))),
]);
}
if (typeof route.parts.job === 'string') {
.flatMapErrors(err => Kefir.constant(messagesFetchFailed(err))),
]);
}
if (typeof route.parts.job === 'string') {
const job = jobs[route.parts.job];
if (Nullable.isNone(job)) {
return Kefir.never();
}
if (!jobIsSuccess(job)) {
return Kefir.never();
}
const job$ = Kefir.concat([
Kefir.constant(jobFetchStarted()),
ajax$(job.response.rest_url, {
method: 'GET',
credentials: 'include',
headers: {
'X-WP-Nonce': globals.nonce,
'Content-Type': 'application/json',
},
})
.flatMap(response =>
response.json().mapErrors(err => new JsonError(err)),
)
.flatMap(response =>
jobResponse
.validate(response, [])
.fold>(
const job$ = Kefir.concat([
Kefir.constant(jobFetchStarted()),
ajax$(job.rest_url, {
method: 'GET',
credentials: 'include',
headers: {
'X-WP-Nonce': globals.nonce,
'Content-Type': 'application/json'
}
})
.flatMap((response: ObsResponse) => response.json())
.map((response: GetJobResponse) => jobFetchSucceeded(response))
.flatMapErrors((err: TypeError) => Kefir.constant(jobFetchFailed(err))),
]);
const runs$ = Kefir.concat([
Kefir.constant(runsFetchStarted()),
ajax$(job.runs_url, {
method: 'GET',
credentials: 'include',
headers: {
'X-WP-Nonce': globals.nonce,
'Content-Type': 'application/json'
}
})
.flatMap((response: ObsResponse) => response.json())
.map((response: GetRunsResponse) => runsFetchSucceeded(response))
.flatMapErrors((err: TypeError) => Kefir.constant(runsFetchFailed(err))),
]);
return Kefir.merge([job$, runs$]);
}
export const serially = xs => K.concat(xs.map(toObservable))
export const parallel = xs => K.merge(xs.map(toObservable))
}
})
.flatMap((response: ObsResponse) => response.json())
.map((response: GetConsoleResponse) => messagesFetchSucceeded(response))
.flatMapErrors((err: TypeError) => Kefir.constant(messagesFetchFailed(err))),
]);
}
if (typeof route.parts.job === 'string') {
const job = jobs[route.parts.job];
if (!job) {
return Kefir.never();
}
const job$ = Kefir.concat([
Kefir.constant(jobFetchStarted()),
ajax$(job.rest_url, {
method: 'GET',
credentials: 'include',
headers: {
'X-WP-Nonce': globals.nonce,
'Content-Type': 'application/json'
}
})
.flatMap((response: ObsResponse) => response.json())
.map((response: GetJobResponse) => jobFetchSucceeded(response))
.flatMapErrors((err: TypeError) => Kefir.constant(jobFetchFailed(err))),
]);
const runs$ = Kefir.concat([
Kefir.constant(runsFetchStarted()),
var serially = function serially(xs) {
return concat(xs.map(toObservable));
};
var parallel = function parallel(xs) {
.flatMapFirst((state: CommitsProps) =>
Kefir.concat([
Kefir.constant(commitsFetchStarted()),
ajax$(state.repo.commits_url, {
method: 'GET',
credentials: 'include',
headers: {
'X-WP-Nonce': state.globals.nonce,
'Content-Type': 'application/json'
}
})
.flatMap((response: ObsResponse) => response.json())
.map((response: GetCommitsResponse) => commitsFetchSucceeded(response))
.flatMapErrors((err: TypeError) => commitsFetchFailed(err)),
])
);
const error$ = actions$.flatMap(({ type, payload }) => {
switch (type) {
case SCAFFOLD_ERROR:
return Kefir.concat([
ui.error(`error scaffolding file: ${payload.error.message}`),
setExitCode(1)
]);
case READ_RC_FILE_ERROR:
return Kefir.concat([
ui.error(`error reading .beaverrc.js: ${payload.error.message}`),
setExitCode(1)
]);
default:
return Kefir.never();
}
});