diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2025-01-10 22:54:54 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2025-01-10 22:54:54 -0400 |
commit | 63c57c36886e5cdfaf8facdb50f3384b24c58ebf (patch) | |
tree | 3cf935397cd1df734ec44c55335950ee97dea3fa /src/data | |
parent | 7f987f5981e20932bb9039252349ecefdc2379ef (diff) |
data: inputSoupyFind, gobbleSoupyFind
Diffstat (limited to 'src/data')
-rw-r--r-- | src/data/composite/wiki-data/gobbleSoupyFind.js | 39 | ||||
-rw-r--r-- | src/data/composite/wiki-data/index.js | 2 | ||||
-rw-r--r-- | src/data/composite/wiki-data/inputSoupyFind.js | 22 | ||||
-rw-r--r-- | src/data/composite/wiki-properties/soupyFind.js | 4 |
4 files changed, 67 insertions, 0 deletions
diff --git a/src/data/composite/wiki-data/gobbleSoupyFind.js b/src/data/composite/wiki-data/gobbleSoupyFind.js new file mode 100644 index 00000000..aec3f5b1 --- /dev/null +++ b/src/data/composite/wiki-data/gobbleSoupyFind.js @@ -0,0 +1,39 @@ +import {input, templateCompositeFrom} from '#composite'; + +import {withPropertyFromObject} from '#composite/data'; + +import inputSoupyFind, {getSoupyFindInputKey} from './inputSoupyFind.js'; + +export default templateCompositeFrom({ + annotation: `gobbleSoupyFind`, + + inputs: { + find: inputSoupyFind(), + }, + + outputs: ['#find'], + + steps: () => [ + { + dependencies: [input('find')], + compute: (continuation, { + [input('find')]: find, + }) => + (typeof find === 'function' + ? continuation.raiseOutput({ + ['#find']: find, + }) + : continuation({ + ['#key']: + getSoupyFindInputKey(find), + })), + }, + + withPropertyFromObject({ + object: 'find', + property: '#key', + }).outputs({ + '#value': '#find', + }), + ], +}); diff --git a/src/data/composite/wiki-data/index.js b/src/data/composite/wiki-data/index.js index 51d07384..294ddb2a 100644 --- a/src/data/composite/wiki-data/index.js +++ b/src/data/composite/wiki-data/index.js @@ -5,7 +5,9 @@ // export {default as exitWithoutContribs} from './exitWithoutContribs.js'; +export {default as gobbleSoupyFind} from './gobbleSoupyFind.js'; export {default as inputNotFoundMode} from './inputNotFoundMode.js'; +export {default as inputSoupyFind} from './inputSoupyFind.js'; export {default as inputWikiData} from './inputWikiData.js'; export {default as withClonedThings} from './withClonedThings.js'; export {default as withContributionListSums} from './withContributionListSums.js'; diff --git a/src/data/composite/wiki-data/inputSoupyFind.js b/src/data/composite/wiki-data/inputSoupyFind.js new file mode 100644 index 00000000..4ae7bd3b --- /dev/null +++ b/src/data/composite/wiki-data/inputSoupyFind.js @@ -0,0 +1,22 @@ +import {input} from '#composite'; +import {anyOf, isFunction, isString} from '#validators'; + +export default () => + input({ + validate: + anyOf( + isFunction, + val => { + isString(val); + + if (!val.startsWith('_soupyFind:')) { + throw new Error(`Expected soupyFind.input() token`); + } + + return true; + }), + }); + +export function getSoupyFindInputKey(value) { + return value.slice('_soupyFind:'.length); +} diff --git a/src/data/composite/wiki-properties/soupyFind.js b/src/data/composite/wiki-properties/soupyFind.js index e7d4208e..87798588 100644 --- a/src/data/composite/wiki-properties/soupyFind.js +++ b/src/data/composite/wiki-properties/soupyFind.js @@ -1,3 +1,4 @@ +import {input} from '#composite'; import {isObject} from '#validators'; function soupyFind() { @@ -7,4 +8,7 @@ function soupyFind() { }; } +soupyFind.input = key => + input.value('_soupyFind:' + key); + export default soupyFind; |