@-0/spool
Advanced tools
Comparing version 0.2.88 to 0.2.89
@@ -1,1 +0,1 @@ | ||
export { command$, out$, run$, task$, tracer$, multiplex } from "./multiplex"; | ||
export { command$, out$, run$, task$, log$, multiplex } from "./multiplex"; |
@@ -1,1 +0,1 @@ | ||
export { command$, out$, run$, task$, tracer$, multiplex } from "./multiplex"; | ||
export { command$, out$, run$, task$, log$, multiplex } from "./multiplex"; |
@@ -1,2 +0,2 @@ | ||
import { Subscription, PubSub } from "@thi.ng/rstream"; | ||
import { Subscription, PubSub } from '@thi.ng/rstream'; | ||
export declare const run$: PubSub<any, any>; | ||
@@ -6,3 +6,3 @@ export declare const out$: PubSub<any, any>; | ||
export declare const task$: Subscription<any, any>; | ||
export declare const tracer$: Subscription<any, any>; | ||
export declare const log$: Subscription<any, any>; | ||
export declare function multiplex(task_array: any): any; |
@@ -10,41 +10,42 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { isFunction, isPromise } from "@thi.ng/checks"; | ||
import { pubsub, stream } from "@thi.ng/rstream"; | ||
import { CMD_SUB$, CMD_ARGS, CMD_RESO, CMD_ERRO, CMD_SRC$, CMD_WORK } from "@-0/keys"; | ||
import { stringify_type, xKeyError, key_index_err, diff_keys } from "@-0/utils"; | ||
import { getIn } from "@thi.ng/paths"; | ||
import { isFunction, isPromise } from '@thi.ng/checks'; | ||
import { pubsub, stream } from '@thi.ng/rstream'; | ||
import { CMD_SUB$, CMD_ARGS, CMD_RESO, CMD_ERRO, CMD_SRC$, CMD_WORK } from '@-0/keys'; | ||
import { stringify_type, xKeyError, key_index_err, diff_keys } from '@-0/utils'; | ||
import { getIn } from '@thi.ng/paths'; | ||
const log = console.log; | ||
export const run$ = pubsub({ | ||
topic: (x) => !!x[CMD_SUB$], | ||
id: "run$_stream", | ||
equiv: (res, tpc) => res === tpc || tpc == "_TRACE_STREAM", | ||
topic: x => !!x[CMD_SUB$], | ||
id: 'run$_stream', | ||
equiv: (res, tpc) => res === tpc || tpc == '_TRACE_STREAM' | ||
}); | ||
export const out$ = pubsub({ | ||
topic: (x) => x[CMD_SUB$], | ||
id: "out$_stream", | ||
equiv: (res, tpc) => res === tpc || tpc == "_TRACE_STREAM", | ||
topic: x => x[CMD_SUB$], | ||
id: 'out$_stream', | ||
equiv: (res, tpc) => res === tpc || tpc == '_TRACE_STREAM' | ||
}); | ||
export const command$ = run$.subscribeTopic(true, { | ||
next: (x) => out$.next(x), | ||
error: console.warn, | ||
}, { id: "command$_stream" }); | ||
next: x => out$.next(x), | ||
error: console.warn | ||
}, { id: 'command$_stream' }); | ||
export const task$ = run$.subscribeTopic(false, { | ||
next: multiplex, | ||
error: console.warn, | ||
}, { id: "task$_stream" }); | ||
export const tracer$ = stream(); | ||
const err_str = "Spooling Interupted"; | ||
error: console.warn | ||
}, { id: 'task$_stream' }); | ||
export const log$ = stream(); | ||
const err_str = 'Spooling Interupted'; | ||
const nosub$_err = (c, i) => console.warn(` | ||
🔥 No sub$ included for a Command with a primitive for 'args'. | ||
🔥 Ergo, nothing was done with this Command: | ||
${JSON.stringify(c)} | ||
${key_index_err(c, i)} | ||
Hope that helps! | ||
🔥 No sub$ included for a Command with a primitive for 'args'. | ||
Ergo, nothing was done with this Command: | ||
${JSON.stringify(c)} | ||
${key_index_err(c, i)} | ||
Hope that helps! | ||
`); | ||
export function multiplex(task_array) { | ||
return task_array.reduce((a, c, i) => __awaiter(this, void 0, void 0, function* () { | ||
const acc = yield a; | ||
let acc = yield a; | ||
if (isFunction(c)) { | ||
@@ -71,5 +72,2 @@ try { | ||
let result = args; | ||
if (arg_type !== "PROMISE" && reso) { | ||
result = Promise.resolve(args); | ||
} | ||
if (args !== Object(args) && !sub$) { | ||
@@ -79,6 +77,9 @@ nosub$_err(c, i); | ||
} | ||
if (arg_type === "PROMISE") { | ||
result = yield args.catch((e) => e); | ||
if (arg_type === 'OBJECT') { | ||
if (!sub$) | ||
return Object.assign(Object.assign({}, acc), args); | ||
out$.next(c); | ||
return Object.assign(Object.assign({}, acc), args); | ||
} | ||
if (arg_type === "THUNK") { | ||
if (arg_type === 'NULLARY') { | ||
result = args(); | ||
@@ -89,38 +90,44 @@ console.log(`dispatching to ad-hoc stream: ${sub$.id}`); | ||
} | ||
if (arg_type === "FUNCTION") { | ||
if (arg_type !== 'PROMISE' && reso) | ||
result = Promise.resolve(args); | ||
if (arg_type === 'PROMISE') | ||
result = yield args.catch(e => e); | ||
if (arg_type === 'UNARY') { | ||
let temp = args(acc); | ||
result = isPromise(temp) ? yield temp.catch((e) => e) : temp; | ||
result = isPromise(temp) ? yield temp.catch(e => e) : temp; | ||
} | ||
if (arg_type === "OBJECT") { | ||
if (!sub$) | ||
return Object.assign(Object.assign({}, acc), args); | ||
out$.next(c); | ||
return Object.assign(Object.assign({}, acc), args); | ||
} | ||
if (reso) { | ||
if (result instanceof Error) { | ||
if (result instanceof Error) { | ||
if (reso) { | ||
if (erro) { | ||
let error = erro(acc, result); | ||
if (getIn(error, [CMD_SUB$])) | ||
return out$.next(error); | ||
console.warn(err_str, "Promise rejected:", result); | ||
return acc; | ||
const err_type = stringify_type(erro); | ||
if (err_type === 'NULLARY') { | ||
let ERR = erro(); | ||
if (getIn(ERR, [CMD_SUB$])) | ||
out$.next(ERR); | ||
return acc; | ||
} | ||
if (getIn(erro, [CMD_SUB$])) | ||
out$.next(erro); | ||
if (err_type === 'BINARY') { | ||
if (getIn(erro(), [CMD_SUB$])) { | ||
let ERR_CMD = erro(acc, result); | ||
out$.next(ERR_CMD); | ||
} | ||
erro(acc, result); | ||
} | ||
} | ||
console.warn(`no 'erro' (Error handler) set for error in ${result}`); | ||
acc = null; | ||
} | ||
if (!(result instanceof Error)) { | ||
let resolved = reso(acc, result); | ||
if (getIn(resolved, [CMD_SUB$])) | ||
out$.next(resolved); | ||
else if (!sub$) | ||
return Object.assign(Object.assign({}, acc), resolved); | ||
result = resolved; | ||
} | ||
acc === null || | ||
console.warn(`no \`erro\` (Error) handler set for ${sub$ || 'error'} ${result}`); | ||
return acc; | ||
} | ||
if (!reso && !sub$) | ||
if (reso) { | ||
let resolved = reso(acc, result); | ||
if (getIn(resolved, [CMD_SUB$])) | ||
return out$.next(resolved); | ||
result = resolved; | ||
} | ||
if (result === Object(result) && !sub$) | ||
return Object.assign(Object.assign({}, acc), result); | ||
if (result instanceof Error) { | ||
console.warn(err_str, result); | ||
return acc; | ||
} | ||
if (result !== Object(result)) { | ||
@@ -134,2 +141,3 @@ if (!sub$) { | ||
} | ||
console.log(`NO CONDITIONS MET FOR ${sub$}`); | ||
out$.next({ [CMD_SUB$]: sub$, [CMD_ARGS]: result }); | ||
@@ -136,0 +144,0 @@ return Object.assign(Object.assign({}, acc), result); |
@@ -1,2 +0,2 @@ | ||
export { run$, command$, out$, task$, tracer$ } from "./core"; | ||
export { run$, command$, out$, task$, log$ } from "./core"; | ||
export { registerCMD } from "./registers"; |
@@ -1,2 +0,2 @@ | ||
export { run$, command$, out$, task$, tracer$ } from "./core"; | ||
export { run$, command$, out$, task$, log$ } from "./core"; | ||
export { registerCMD } from "./registers"; |
import { map } from "@thi.ng/transducers"; | ||
import { isFunction } from "@thi.ng/checks"; | ||
import { CMD_SUB$, CMD_ARGS, CMD_RESO, CMD_ERRO, CMD_SRC$, CMD_WORK } from "@-0/keys"; | ||
import { xKeyError, diff_keys } from "@-0/utils"; | ||
import { out$, tracer$ } from "../core"; | ||
import { xKeyError, diff_keys, stringify_fn } from "@-0/utils"; | ||
import { out$, log$ } from "../core"; | ||
export const supplement$CMD = (cmd, downstream) => { | ||
@@ -38,5 +38,13 @@ const upstream = cmd[CMD_SRC$]; | ||
: { [CMD_SUB$]: sub$, [CMD_ARGS]: args }; | ||
const CMD_s = reso | ||
? { | ||
[CMD_SUB$]: sub$, | ||
[CMD_ARGS]: stringify_fn(args), | ||
[CMD_RESO]: stringify_fn(reso), | ||
[CMD_ERRO]: stringify_fn(erro), | ||
} | ||
: { [CMD_SUB$]: sub$, [CMD_ARGS]: stringify_fn(args) }; | ||
out$.subscribeTopic(sub$, { | ||
next: x => { | ||
tracer$.next(Object.assign(Object.assign({}, CMD), { [CMD_ARGS]: x })); | ||
log$.next(CMD_s); | ||
return work(x); | ||
@@ -43,0 +51,0 @@ }, |
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "0.2.88", | ||
"version": "0.2.89", | ||
"description": "SPA framework built on top of http://thi.ng/umbrella ecosystem", | ||
@@ -44,4 +44,4 @@ "main": "./lib/index.js", | ||
"dependencies": { | ||
"@-0/keys": "^0.2.81", | ||
"@-0/utils": "^0.2.76" | ||
"@-0/keys": "^0.2.82", | ||
"@-0/utils": "^0.2.79" | ||
}, | ||
@@ -68,3 +68,3 @@ "devDependencies": { | ||
"prettier": "^2.2.1", | ||
"ts-jest": "^26.4.4" | ||
"ts-jest": "^26.5.0" | ||
}, | ||
@@ -71,0 +71,0 @@ "prettier": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32947
220
Updated@-0/keys@^0.2.82
Updated@-0/utils@^0.2.79