@-0/spool
Advanced tools
Comparing version
@@ -1,1 +0,1 @@ | ||
export { cmd$, out$, run$, task$, multiplex } from "./multiplex"; | ||
export { cmd$, out$, run$, task$, keys_match, multiplex } from "./multiplex"; |
@@ -1,1 +0,1 @@ | ||
export { cmd$, out$, run$, task$, multiplex } from "./multiplex"; | ||
export { cmd$, out$, run$, task$, keys_match, multiplex } from "./multiplex"; |
import { Subscription, PubSub } from "@thi.ng/rstream"; | ||
export declare const keys_match: (C: any) => string; | ||
export declare const process_args: (acc: any, args: any) => any; | ||
export declare const multiplex: (out$: any) => (task_array: any) => any; | ||
@@ -3,0 +5,0 @@ export declare const run$: PubSub<any, any>; |
@@ -12,13 +12,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import { pubsub } 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 { EquivMap } from "@thi.ng/associative"; | ||
import { CMD_SUB$, CMD_ARGS, CMD_RESO, CMD_ERRO } from "@-0/keys"; | ||
import { stringify_type, xKeyError, key_index_err, diff_keys, stringify_fn } from "@-0/utils"; | ||
import { getIn } from "@thi.ng/paths"; | ||
const log = console.log; | ||
const err_str = "Spooling Interupted"; | ||
const err_str = "🔥 Multiplex Spooling Interrupted 🔥"; | ||
const nosub$_err = (c, i) => console.warn(` | ||
🔥 No sub$ included for a Command with a primitive for 'args'. | ||
${err_str} | ||
>> No \`${CMD_SUB$}\` included for a Command with primitive \`${CMD_ARGS}\` << | ||
Ergo, nothing was done with this Command: | ||
${JSON.stringify(c)} | ||
${stringify_fn(c)} | ||
@@ -28,11 +31,61 @@ ${key_index_err(c, i)} | ||
Hope that helps! | ||
`); | ||
const task_not_array_error = x => ` | ||
You may have either: | ||
1. Tried to run a Command that has no \`${CMD_ARGS}\` key (and thus does nothing) | ||
2. Tried to run a Sub/Task that is not in [] (Array) form | ||
${err_str} | ||
You may have: | ||
1. Ran a Command that has no \`${CMD_ARGS}\` key and thus does nothing | ||
2. Ran a Subtask - a unary Function that accepts an inter-Task accumulator | ||
and returns an Array - outside of a Task and has thus starved | ||
Please check this payload for issues: | ||
${JSON.stringify(x)} | ||
${stringify_fn(x)} | ||
`; | ||
const no_args_error = (C, i) => ` | ||
${err_str} | ||
You have ran a Command that has no \`${CMD_ARGS}\` key and thus does nothing | ||
Please check this payload for issues: | ||
${stringify_fn(C)} | ||
//${key_index_err(C, i)} | ||
`; | ||
export const keys_match = C => new EquivMap([ | ||
[[], "NO_ARGS"], | ||
[[CMD_SUB$], "NO_ARGS"], | ||
[[CMD_RESO], "NO_ARGS"], | ||
[[CMD_ERRO], "NO_ARGS"], | ||
[[CMD_RESO, CMD_SUB$], "NO_ARGS"], | ||
[[CMD_ERRO, CMD_SUB$], "NO_ARGS"], | ||
[[CMD_ERRO, CMD_RESO], "NO_ARGS"], | ||
[[CMD_ERRO, CMD_RESO, CMD_SUB$], "NO_ARGS"], | ||
[[CMD_ARGS], "A"], | ||
[[CMD_ARGS, CMD_ERRO], "AE"], | ||
[[CMD_ARGS, CMD_RESO], "AR"], | ||
[[CMD_ARGS, CMD_SUB$], "AS"], | ||
[[CMD_ARGS, CMD_ERRO, CMD_SUB$], "AER"], | ||
[[CMD_ARGS, CMD_ERRO, CMD_RESO], "AES"], | ||
[[CMD_ARGS, CMD_RESO, CMD_SUB$], "ARS"], | ||
[[CMD_ARGS, CMD_ERRO, CMD_RESO, CMD_SUB$], "AERS"] | ||
]).get(Object.keys(C).sort()) || "UNKNOWN"; | ||
export const process_args = (acc, args) => __awaiter(void 0, void 0, void 0, function* () { | ||
const args_type = stringify_type(args); | ||
switch (args_type) { | ||
case "PRIMITIVE": | ||
case "OBJECT": | ||
case "ARRAY": | ||
return args; | ||
case "UNARY": | ||
return yield process_args(acc, args(acc)); | ||
case "PROMISE": | ||
let resolved = yield args.catch(e => e); | ||
return yield process_args(acc, resolved); | ||
case "NULLARY": | ||
return yield process_args(acc, args()); | ||
default: | ||
return "UNDEFINED"; | ||
} | ||
}); | ||
export const multiplex = out$ => task_array => isArray(task_array) | ||
@@ -43,5 +96,5 @@ ? task_array.reduce((a, c, i) => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
const recur = c(acc); | ||
recur.unshift({ [CMD_ARGS]: acc }); | ||
return multiplex(out$)(recur); | ||
const queue = c(acc); | ||
queue.unshift({ [CMD_ARGS]: acc }); | ||
return multiplex(out$)(queue); | ||
} | ||
@@ -53,2 +106,7 @@ catch (e) { | ||
} | ||
const props_type = keys_match(c); | ||
if (props_type === "NO_ARGS") { | ||
console.warn(no_args_error(c, i)); | ||
return (acc = null); | ||
} | ||
const sub$ = c[CMD_SUB$]; | ||
@@ -58,3 +116,3 @@ const args = c[CMD_ARGS]; | ||
const reso = c[CMD_RESO]; | ||
const knowns = [CMD_SUB$, CMD_ARGS, CMD_RESO, CMD_ERRO, CMD_SRC$, CMD_WORK]; | ||
const knowns = [CMD_SUB$, CMD_ARGS, CMD_RESO, CMD_ERRO]; | ||
const [unknowns, unknown_kvs] = diff_keys(knowns, c); | ||
@@ -65,3 +123,3 @@ if (unknowns.length > 0) | ||
let result = args; | ||
if (args !== Object(args) && !sub$) { | ||
if (arg_type === "PRIMITIVE" && !sub$) { | ||
nosub$_err(c, i); | ||
@@ -68,0 +126,0 @@ return acc; |
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "0.2.93", | ||
"version": "0.2.94", | ||
"description": "SPA framework built on top of http://thi.ng/umbrella ecosystem", | ||
@@ -44,7 +44,7 @@ "main": "./lib/index.js", | ||
"dependencies": { | ||
"@-0/keys": "^0.2.86", | ||
"@-0/utils": "^0.2.83" | ||
"@-0/keys": "^0.2.87", | ||
"@-0/utils": "^0.2.85" | ||
}, | ||
"devDependencies": { | ||
"@babel/plugin-transform-modules-commonjs": "^7.12.1", | ||
"@babel/plugin-transform-modules-commonjs": "^7.12.13", | ||
"@thi.ng/arrays": "^0.10.1", | ||
@@ -51,0 +51,0 @@ "@thi.ng/associative": "5.0.17", |
36483
5.83%308
21.26%Updated
Updated