« get me outta code hell

data: constituteFrom, constituteOrContinue - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2025-11-26 21:35:39 -0400
committer(quasar) nebula <qznebula@protonmail.com>2025-11-26 21:35:39 -0400
commit320ea651bdb2ed58d79e7f5fc11c6a65f88ad047 (patch)
treed3267aa203095769f20c3e18918233568429c03e
parent3ec014c234ae8979a32989d9acbc0ac360914abb (diff)
data: constituteFrom, constituteOrContinue
-rw-r--r--src/data/composite/control-flow/index.js1
-rw-r--r--src/data/composite/wiki-data/constituteFrom.js31
-rw-r--r--src/data/composite/wiki-data/constituteOrContinue.js34
-rw-r--r--src/data/composite/wiki-data/index.js2
-rw-r--r--src/data/things/artwork.js127
5 files changed, 91 insertions, 104 deletions
diff --git a/src/data/composite/control-flow/index.js b/src/data/composite/control-flow/index.js
index 778dc66b..61bfa08e 100644
--- a/src/data/composite/control-flow/index.js
+++ b/src/data/composite/control-flow/index.js
@@ -11,6 +11,7 @@ export {default as exposeDependencyOrContinue} from './exposeDependencyOrContinu
 export {default as exposeUpdateValueOrContinue} from './exposeUpdateValueOrContinue.js';
 export {default as exposeWhetherDependencyAvailable} from './exposeWhetherDependencyAvailable.js';
 export {default as flipFilter} from './flipFilter.js';
+export {default as inputAvailabilityCheckMode} from './inputAvailabilityCheckMode.js'; // A helper, technically...
 export {default as raiseOutputWithoutDependency} from './raiseOutputWithoutDependency.js';
 export {default as raiseOutputWithoutUpdateValue} from './raiseOutputWithoutUpdateValue.js';
 export {default as withAvailabilityFilter} from './withAvailabilityFilter.js';
diff --git a/src/data/composite/wiki-data/constituteFrom.js b/src/data/composite/wiki-data/constituteFrom.js
new file mode 100644
index 00000000..12c36c78
--- /dev/null
+++ b/src/data/composite/wiki-data/constituteFrom.js
@@ -0,0 +1,31 @@
+import {input, templateCompositeFrom} from '#composite';
+
+import {inputAvailabilityCheckMode,} from '#composite/control-flow';
+
+import constituteOrContinue from './constituteOrContinue.js';
+
+export default templateCompositeFrom({
+  annotation: `constituteFrom`,
+
+  inputs: {
+    property: input({type: 'string', acceptsNull: true}),
+    from: input({type: 'object', acceptsNull: true}),
+    else: input({defaultValue: null}),
+    mode: inputAvailabilityCheckMode(),
+  },
+
+  compose: false,
+
+  steps: () => [
+    constituteOrContinue({
+      property: input('property'),
+      from: input('from'),
+      mode: input('mode'),
+    }),
+
+    {
+      dependencies: [input('else')],
+      compute: ({[input('else')]: fallback}) => fallback,
+    },
+  ],
+});
diff --git a/src/data/composite/wiki-data/constituteOrContinue.js b/src/data/composite/wiki-data/constituteOrContinue.js
new file mode 100644
index 00000000..3527976e
--- /dev/null
+++ b/src/data/composite/wiki-data/constituteOrContinue.js
@@ -0,0 +1,34 @@
+import {input, templateCompositeFrom} from '#composite';
+
+import {withPropertyFromObject} from '#composite/data';
+
+import {
+  exposeDependencyOrContinue,
+  inputAvailabilityCheckMode,
+  raiseOutputWithoutDependency,
+} from '#composite/control-flow';
+
+export default templateCompositeFrom({
+  annotation: `constituteFrom`,
+
+  inputs: {
+    property: input({type: 'string', acceptsNull: true}),
+    from: input({type: 'object', acceptsNull: true}),
+    mode: inputAvailabilityCheckMode(),
+  },
+
+  steps: () => [
+    raiseOutputWithoutDependency({
+      dependency: input('property'),
+    }),
+
+    withPropertyFromObject({
+      property: input('property'),
+      object: input('from'),
+    }),
+
+    exposeDependencyOrContinue({
+      dependency: '#value',
+    }),
+  ],
+});
diff --git a/src/data/composite/wiki-data/index.js b/src/data/composite/wiki-data/index.js
index d70d7c56..beb6f3b8 100644
--- a/src/data/composite/wiki-data/index.js
+++ b/src/data/composite/wiki-data/index.js
@@ -4,6 +4,8 @@
 // #composite/data.
 //
 
+export {default as constituteFrom} from './constituteFrom.js';
+export {default as constituteOrContinue} from './constituteOrContinue.js';
 export {default as exitWithoutContribs} from './exitWithoutContribs.js';
 export {default as exitWithoutArtwork} from './exitWithoutArtwork.js';
 export {default as gobbleSoupyFind} from './gobbleSoupyFind.js';
diff --git a/src/data/things/artwork.js b/src/data/things/artwork.js
index 8958bf80..688cccb3 100644
--- a/src/data/things/artwork.js
+++ b/src/data/things/artwork.js
@@ -42,6 +42,8 @@ import {
 } from '#composite/data';
 
 import {
+  constituteFrom,
+  constituteOrContinue,
   withRecontextualizedContributionList,
   withResolvedAnnotatedReferenceList,
   withResolvedContribs,
@@ -90,47 +92,27 @@ export class Artwork extends Thing {
     dateFromThingProperty: simpleString(),
 
     date: [
-      withDate({
-        from: input.updateValue({validate: isDate}),
+      exposeUpdateValueOrContinue({
+        validate: input.value(isDate),
       }),
 
-      exposeDependency({dependency: '#date'}),
+      constituteFrom({
+        property: 'dateFromThingProperty',
+        from: 'thing',
+      }),
     ],
 
     fileExtensionFromThingProperty: simpleString(),
 
     fileExtension: [
-      {
-        compute: (continuation) => continuation({
-          ['#default']: 'jpg',
-        }),
-      },
-
       exposeUpdateValueOrContinue({
         validate: input.value(isFileExtension),
       }),
 
-      exitWithoutDependency({
-        dependency: 'thing',
-        value: '#default',
-      }),
-
-      exitWithoutDependency({
-        dependency: 'fileExtensionFromThingProperty',
-        value: '#default',
-      }),
-
-      withPropertyFromObject({
-        object: 'thing',
+      constituteFrom({
         property: 'fileExtensionFromThingProperty',
-      }),
-
-      exposeDependencyOrContinue({
-        dependency: '#value',
-      }),
-
-      exposeDependency({
-        dependency: '#default',
+        from: 'thing',
+        else: input.value('jpg'),
       }),
     ],
 
@@ -141,29 +123,9 @@ export class Artwork extends Thing {
         validate: input.value(isDimensions),
       }),
 
-      exitWithoutDependency({
-        dependency: 'dimensionsFromThingProperty',
-        value: input.value(null),
-      }),
-
-      withPropertyFromObject({
-        object: 'thing',
+      constituteFrom({
         property: 'dimensionsFromThingProperty',
-      }).outputs({
-        ['#value']: '#dimensionsFromThing',
-      }),
-
-      exitWithoutDependency({
-        dependency: 'dimensionsFromThingProperty',
-        value: input.value(null),
-      }),
-
-      exposeDependencyOrContinue({
-        dependency: '#dimensionsFromThing',
-      }),
-
-      exposeConstant({
-        value: input.value(null),
+        from: 'thing',
       }),
     ],
 
@@ -200,24 +162,9 @@ export class Artwork extends Thing {
         dependency: '#attachedArtwork.artistContribs',
       }),
 
-      exitWithoutDependency({
-        dependency: 'artistContribsFromThingProperty',
-        value: input.value([]),
-      }),
-
-      withPropertyFromObject({
-        object: 'thing',
+      constituteFrom({
         property: 'artistContribsFromThingProperty',
-      }).outputs({
-        ['#value']: '#artistContribs',
-      }),
-
-      withRecontextualizedContributionList({
-        list: '#artistContribs',
-      }),
-
-      exposeDependency({
-        dependency: '#artistContribs',
+        from: 'thing',
       }),
     ],
 
@@ -239,30 +186,16 @@ export class Artwork extends Thing {
         mode: input.value('empty'),
       }),
 
-      withPropertyFromObject({
-        object: 'attachedArtwork',
+      constituteOrContinue({
         property: input.value('artTags'),
-      }),
-
-      exposeDependencyOrContinue({
-        dependency: '#attachedArtwork.artTags',
+        from: 'attachedArtwork',
         mode: input.value('empty'),
       }),
 
-      exitWithoutDependency({
-        dependency: 'artTagsFromThingProperty',
-        value: input.value([]),
-      }),
-
-      withPropertyFromObject({
-        object: 'thing',
+      constituteFrom({
         property: 'artTagsFromThingProperty',
-      }).outputs({
-        ['#value']: '#thing.artTags',
-      }),
-
-      exposeDependency({
-        dependency: '#thing.artTags'
+        from: 'thing',
+        else: input.value([]),
       }),
     ],
 
@@ -304,24 +237,10 @@ export class Artwork extends Thing {
         mode: input.value('empty'),
       }),
 
-      exitWithoutDependency({
-        dependency: 'referencedArtworksFromThingProperty',
-        value: input.value([]),
-      }),
-
-      withPropertyFromObject({
-        object: 'thing',
+      constituteFrom({
         property: 'referencedArtworksFromThingProperty',
-      }).outputs({
-        ['#value']: '#referencedArtworks',
-      }),
-
-      exposeDependencyOrContinue({
-        dependency: '#referencedArtworks',
-      }),
-
-      exposeConstant({
-        value: input.value([]),
+        from: 'thing',
+        else: input.value([]),
       }),
     ],