Normalize term translation with Effect Match

This commit is contained in:
elpresidank 2026-06-02 09:11:33 -05:00
parent e311315556
commit 09d34fb4d4
11 changed files with 349 additions and 190 deletions

View file

@ -8,7 +8,7 @@
import { createClient, Graph } from "falkordb";
import { errorMessage, type Term, type Triple } from "@trustgraph/base";
import { Config, Context, Effect, Layer } from "effect";
import { Config, Context, Effect, Layer, Match } from "effect";
import * as Predicate from "effect/Predicate";
import * as S from "effect/Schema";
@ -41,16 +41,14 @@ export interface FalkorDBQueryConfig {
function termToValue(term: Term | undefined): string | null {
if (term === undefined) return null;
switch (term.type) {
case "IRI":
return term.iri;
case "LITERAL":
return term.value;
case "BLANK":
return term.id;
default:
return null;
}
return Match.type<Term>().pipe(
Match.discriminatorsExhaustive("type")({
IRI: (iri) => iri.iri,
LITERAL: (literal) => literal.value,
BLANK: (blank) => blank.id,
TRIPLE: () => null,
}),
)(term);
}
function createTerm(value: string): Term {