This commit is contained in:
Ladd Hoffman 2024-12-23 23:36:38 -06:00
parent 74cd5536af
commit 165732d7cd
2 changed files with 3 additions and 3 deletions

View File

@ -1,6 +1,6 @@
import Debug from "debug"; import Debug from "debug";
import {Lossless, LosslessViewMany} from "../src/lossless"; import {Lossless, LosslessViewMany} from "../src/lossless";
import {Lossy, firstValueFromLosslessViewOne, firstValueFromCollapsedDelta} from "../src/lossy"; import {Lossy, firstValueFromLosslessViewOne, valueFromCollapsedDelta} from "../src/lossy";
const debug = Debug('test:lossy'); const debug = Debug('test:lossy');
describe('Lossy', () => { describe('Lossy', () => {
@ -53,7 +53,7 @@ describe('Lossy', () => {
const {delta, value: actor} = firstValueFromLosslessViewOne(ent, "actor") ?? {}; const {delta, value: actor} = firstValueFromLosslessViewOne(ent, "actor") ?? {};
if (!delta) continue; // TODO: panic if (!delta) continue; // TODO: panic
if (!actor) continue; // TODO: panic if (!actor) continue; // TODO: panic
const film = firstValueFromCollapsedDelta(delta, "film"); const film = valueFromCollapsedDelta(delta, "film");
debug(`role ${id}`, {actor, film}); debug(`role ${id}`, {actor, film});
if (!film) continue; // TODO: panic if (!film) continue; // TODO: panic
roles.push({ roles.push({

View File

@ -24,7 +24,7 @@ export function valueFromCollapsedDelta(delta: CollapsedDelta, key: string): str
// Example function for resolving a value for an entity by taking the first value we find // Example function for resolving a value for an entity by taking the first value we find
export function firstValueFromLosslessViewOne(ent: LosslessViewOne, key: string): {delta: CollapsedDelta, value: string} | undefined { export function firstValueFromLosslessViewOne(ent: LosslessViewOne, key: string): {delta: CollapsedDelta, value: string} | undefined {
for (const delta of ent.properties[key] || []) { for (const delta of ent.properties[key] || []) {
const value = firstValueFromCollapsedDelta(delta, key); const value = valueFromCollapsedDelta(delta, key);
if (value) return {delta, value}; if (value) return {delta, value};
} }
} }