From 63c57c36886e5cdfaf8facdb50f3384b24c58ebf Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 10 Jan 2025 22:54:54 -0400 Subject: data: inputSoupyFind, gobbleSoupyFind --- src/data/composite/wiki-data/gobbleSoupyFind.js | 39 +++++++++++++++++++++++++ src/data/composite/wiki-data/index.js | 2 ++ src/data/composite/wiki-data/inputSoupyFind.js | 22 ++++++++++++++ src/data/composite/wiki-properties/soupyFind.js | 4 +++ 4 files changed, 67 insertions(+) create mode 100644 src/data/composite/wiki-data/gobbleSoupyFind.js create mode 100644 src/data/composite/wiki-data/inputSoupyFind.js (limited to 'src/data') 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; -- cgit 1.3.0-6-gf8a5