diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/data/things/thing.js | 121 | ||||
-rw-r--r-- | src/data/things/track.js | 123 |
2 files changed, 140 insertions, 104 deletions
diff --git a/src/data/things/thing.js b/src/data/things/thing.js index 6bdc897f..cd62288e 100644 --- a/src/data/things/thing.js +++ b/src/data/things/thing.js @@ -1151,20 +1151,24 @@ export default class Thing extends CacheableObject { // compositional step, the property will be exposed as undefined instead // of null. // - exposeDependency: (dependency, {update = false} = {}) => ({ - annotation: `Thing.composite.exposeDependency`, - flags: {expose: true, update: !!update}, + exposeDependency(dependency, { + update = false, + } = {}) { + return { + annotation: `Thing.composite.exposeDependency`, + flags: {expose: true, update: !!update}, - expose: { - mapDependencies: {dependency}, - compute: ({dependency}) => dependency, - }, + expose: { + mapDependencies: {dependency}, + compute: ({dependency}) => dependency, + }, - update: - (typeof update === 'object' - ? update - : null), - }), + update: + (typeof update === 'object' + ? update + : null), + }; + }, // Exposes a constant value exactly as it is; like exposeDependency, this // is typically the base of a composition serving as a particular property @@ -1172,20 +1176,24 @@ export default class Thing extends CacheableObject { // exit with some other value, with the exposeConstant base serving as the // fallback default value. Like exposeDependency, set {update} to true or // an object to indicate that the property as a whole updates. - exposeConstant: (value, {update = false} = {}) => ({ - annotation: `Thing.composite.exposeConstant`, - flags: {expose: true, update: !!update}, + exposeConstant(value, { + update = false, + } = {}) { + return { + annotation: `Thing.composite.exposeConstant`, + flags: {expose: true, update: !!update}, - expose: { - options: {value}, - compute: ({'#options': {value}}) => value, - }, + expose: { + options: {value}, + compute: ({'#options': {value}}) => value, + }, - update: - (typeof update === 'object' - ? update - : null), - }), + update: + (typeof update === 'object' + ? update + : null), + }; + }, // Checks the availability of a dependency or the update value and provides // the result to later steps under '#availability' (by default). This is @@ -1254,8 +1262,10 @@ export default class Thing extends CacheableObject { // Exposes a dependency as it is, or continues if it's unavailable. // See withResultOfAvailabilityCheck for {mode} options! - exposeDependencyOrContinue: (dependency, {mode = 'null'} = {}) => - Thing.composite.from(`Thing.composite.exposeDependencyOrContinue`, [ + exposeDependencyOrContinue(dependency, { + mode = 'null', + } = {}) { + return Thing.composite.from(`Thing.composite.exposeDependencyOrContinue`, [ Thing.composite.withResultOfAvailabilityCheck({ fromDependency: dependency, mode, @@ -1280,13 +1290,16 @@ export default class Thing extends CacheableObject { continuation.exit(dependency), }, }, - ]), + ]); + }, // Exposes the update value of an {update: true} property as it is, // or continues if it's unavailable. See withResultOfAvailabilityCheck // for {mode} options! - exposeUpdateValueOrContinue: ({mode = 'null'} = {}) => - Thing.composite.from(`Thing.composite.exposeUpdateValueOrContinue`, [ + exposeUpdateValueOrContinue({ + mode = 'null', + } = {}) { + return Thing.composite.from(`Thing.composite.exposeUpdateValueOrContinue`, [ Thing.composite.withResultOfAvailabilityCheck({ fromUpdateValue: true, mode, @@ -1310,12 +1323,16 @@ export default class Thing extends CacheableObject { continuation.exit(value), }, }, - ]), + ]); + }, // Early exits if a dependency isn't available. // See withResultOfAvailabilityCheck for {mode} options! - earlyExitWithoutDependency: (dependency, {mode = 'null', value = null} = {}) => - Thing.composite.from(`Thing.composite.earlyExitWithoutDependency`, [ + earlyExitWithoutDependency(dependency, { + mode = 'null', + value = null, + } = {}) { + return Thing.composite.from(`Thing.composite.earlyExitWithoutDependency`, [ Thing.composite.withResultOfAvailabilityCheck({ fromDependency: dependency, mode, @@ -1342,7 +1359,8 @@ export default class Thing extends CacheableObject { continuation.exit(value), }, }, - ]), + ]); + }, // -- Compositional steps for processing data -- @@ -1350,20 +1368,22 @@ export default class Thing extends CacheableObject { // providing (named by the second argument) the result. "Resolving" // means mapping the "who" reference of each contribution to an artist // object, and filtering out those whose "who" doesn't match any artist. - withResolvedContribs: ({from, to}) => ({ - annotation: `Thing.composite.withResolvedContribs`, - flags: {expose: true, compose: true}, + withResolvedContribs({from, to}) { + return { + annotation: `Thing.composite.withResolvedContribs`, + flags: {expose: true, compose: true}, - expose: { - dependencies: ['artistData'], - mapDependencies: {from}, - mapContinuation: {to}, - compute: ({artistData, from}, continuation) => - continuation({ - to: Thing.findArtistsFromContribs(from, artistData), - }), - }, - }), + expose: { + dependencies: ['artistData'], + mapDependencies: {from}, + mapContinuation: {to}, + compute: ({artistData, from}, continuation) => + continuation({ + to: Thing.findArtistsFromContribs(from, artistData), + }), + }, + }; + }, // Resolves a reference by using the provided find function to match it // within the provided thingData dependency. This will early exit if the @@ -1372,14 +1392,14 @@ export default class Thing extends CacheableObject { // Otherwise, the data object is provided on the output dependency; // or null, if the reference doesn't match anything or itself was null // to begin with. - withResolvedReference: ({ + withResolvedReference({ ref, data, to, find: findFunction, earlyExitIfNotFound = false, - }) => - Thing.composite.from(`Thing.composite.withResolvedReference`, [ + }) { + return Thing.composite.from(`Thing.composite.withResolvedReference`, [ { flags: {expose: true, compose: true}, expose: { @@ -1423,6 +1443,7 @@ export default class Thing extends CacheableObject { }, }, }, - ]), + ]); + }, }; } diff --git a/src/data/things/track.js b/src/data/things/track.js index 8ddf3624..cdc9cec3 100644 --- a/src/data/things/track.js +++ b/src/data/things/track.js @@ -366,8 +366,11 @@ export class Track extends Thing { // dependencies provided. If allowOverride is true, then the continuation // will also be called if the original release exposed the requested // property as null. - inheritFromOriginalRelease: ({property: originalProperty, allowOverride = false}) => - Thing.composite.from(`Track.composite.inheritFromOriginalRelease`, [ + inheritFromOriginalRelease({ + property: originalProperty, + allowOverride = false, + }) { + return Thing.composite.from(`Track.composite.inheritFromOriginalRelease`, [ Track.composite.withOriginalRelease(), { @@ -386,56 +389,59 @@ export class Track extends Thing { }, }, } - ]), + ]); + }, // Gets the track's album. Unless earlyExitIfNotFound is overridden false, // this will early exit with null in two cases - albumData being missing, // or not including an album whose .tracks array includes this track. - withAlbum: ({to = '#album', earlyExitIfNotFound = true} = {}) => ({ - annotation: `Track.composite.withAlbum`, - flags: {expose: true, compose: true}, - - expose: { - dependencies: ['this', 'albumData'], - mapContinuation: {to}, - options: {earlyExitIfNotFound}, - - compute({ - this: track, - albumData, - '#options': {earlyExitIfNotFound}, - }, continuation) { - if (empty(albumData)) { - return ( - (earlyExitIfNotFound - ? continuation.exit(null) - : continuation({to: null}))); - } - - const album = - albumData?.find(album => album.tracks.includes(track)); - - if (!album) { - return ( - (earlyExitIfNotFound - ? continuation.exit(null) - : continuation({to: null}))); - } + withAlbum({to = '#album', earlyExitIfNotFound = true} = {}) { + return { + annotation: `Track.composite.withAlbum`, + flags: {expose: true, compose: true}, - return continuation({to: album}); + expose: { + dependencies: ['this', 'albumData'], + mapContinuation: {to}, + options: {earlyExitIfNotFound}, + + compute({ + this: track, + albumData, + '#options': {earlyExitIfNotFound}, + }, continuation) { + if (empty(albumData)) { + return ( + (earlyExitIfNotFound + ? continuation.exit(null) + : continuation({to: null}))); + } + + const album = + albumData?.find(album => album.tracks.includes(track)); + + if (!album) { + return ( + (earlyExitIfNotFound + ? continuation.exit(null) + : continuation({to: null}))); + } + + return continuation({to: album}); + }, }, - }, - }), + }; + }, // Gets a single property from this track's album, providing it as the same // property name prefixed with '#album.' (by default). If the track's album // isn't available, and earlyExitIfNotFound hasn't been set, the property // will be provided as null. - withAlbumProperty: (property, { + withAlbumProperty(property, { to = '#album.' + property, earlyExitIfNotFound = false, - } = {}) => - Thing.composite.from(`Track.composite.withAlbumProperty`, [ + } = {}) { + return Thing.composite.from(`Track.composite.withAlbumProperty`, [ Track.composite.withAlbum({earlyExitIfNotFound}), { @@ -454,18 +460,19 @@ export class Track extends Thing { : continuation.raise({to: null})), }, }, - ]), + ]); + }, // Gets the listed properties from this track's album, providing them as // dependencies (by default) with '#album.' prefixed before each property // name. If the track's album isn't available, and earlyExitIfNotFound // hasn't been set, the same dependency names will be provided as null. - withAlbumProperties: ({ + withAlbumProperties({ properties, prefix = '#album', earlyExitIfNotFound = false, - }) => - Thing.composite.from(`Track.composite.withAlbumProperties`, [ + }) { + return Thing.composite.from(`Track.composite.withAlbumProperties`, [ Track.composite.withAlbum({earlyExitIfNotFound}), { @@ -494,17 +501,18 @@ export class Track extends Thing { }, }, }, - ]), + ]); + }, // Gets the track section containing this track from its album's track list. // Unless earlyExitIfNotFound is overridden false, this will early exit if // the album can't be found or if none of its trackSections includes the // track for some reason. - withContainingTrackSection: ({ + withContainingTrackSection({ to = '#trackSection', earlyExitIfNotFound = true, - } = {}) => - Thing.composite.from(`Track.composite.withContainingTrackSection`, [ + } = {}) { + return Thing.composite.from(`Track.composite.withContainingTrackSection`, [ Track.composite.withAlbumProperty('trackSections', {earlyExitIfNotFound}), { @@ -534,14 +542,17 @@ export class Track extends Thing { }, }, }, - ]), + ]); + }, // Just includes the original release of this track as a dependency, or // null, if it's not a rerelease. Note that this will early exit if the // original release is specified by reference and that reference doesn't // resolve to anything. Outputs to '#originalRelease' by default. - withOriginalRelease: ({to: outputDependency = '#originalRelease'} = {}) => - Thing.composite.from(`Track.composite.withOriginalRelease`, [ + withOriginalRelease({ + to = '#originalRelease', + } = {}) { + return Thing.composite.from(`Track.composite.withOriginalRelease`, [ Thing.composite.withResolvedReference({ ref: 'originalReleaseTrackByRef', data: 'trackData', @@ -553,12 +564,15 @@ export class Track extends Thing { Thing.composite.export({ [outputDependency]: '#originalRelease', }), - ]), + ]); + }, // The algorithm for checking if a track has unique cover art is used in a // couple places, so it's defined in full as a compositional step. - withHasUniqueCoverArt: ({to = '#hasUniqueCoverArt'} = {}) => - Thing.composite.from(`Track.composite.withHasUniqueCoverArt`, [ + withHasUniqueCoverArt({ + to = '#hasUniqueCoverArt', + } = {}) { + return Thing.composite.from(`Track.composite.withHasUniqueCoverArt`, [ { flags: {expose: true, compose: true}, expose: { @@ -601,7 +615,8 @@ export class Track extends Thing { : continuation.raise({to: true})), }, }, - ]), + ]); + }, }; [inspect.custom](depth) { |