2026-04-05 21:09:33 -05:00
|
|
|
/**
|
2026-05-12 08:06:58 -05:00
|
|
|
* Schema-backed core data types mirroring the Python schema primitives.
|
2026-04-05 21:09:33 -05:00
|
|
|
*
|
|
|
|
|
* Python reference: trustgraph-base/trustgraph/schema/core/primitives.py
|
|
|
|
|
*/
|
|
|
|
|
|
2026-05-12 08:06:58 -05:00
|
|
|
import * as S from "effect/Schema";
|
2026-04-05 21:09:33 -05:00
|
|
|
|
2026-05-12 08:06:58 -05:00
|
|
|
export const TgError = S.Struct({
|
|
|
|
|
type: S.String,
|
|
|
|
|
message: S.String,
|
|
|
|
|
});
|
|
|
|
|
export type TgError = typeof TgError.Type;
|
2026-04-05 21:09:33 -05:00
|
|
|
|
2026-05-12 08:06:58 -05:00
|
|
|
export const TermType = S.Literals([
|
|
|
|
|
"IRI",
|
|
|
|
|
"BLANK",
|
|
|
|
|
"LITERAL",
|
|
|
|
|
"TRIPLE",
|
|
|
|
|
]);
|
|
|
|
|
export type TermType = typeof TermType.Type;
|
2026-04-05 21:09:33 -05:00
|
|
|
|
2026-05-12 08:06:58 -05:00
|
|
|
export const IriTerm = S.Struct({
|
|
|
|
|
type: S.tag("IRI"),
|
|
|
|
|
iri: S.String,
|
|
|
|
|
});
|
|
|
|
|
export type IriTerm = typeof IriTerm.Type;
|
2026-04-05 21:09:33 -05:00
|
|
|
|
2026-05-12 08:06:58 -05:00
|
|
|
export const BlankTerm = S.Struct({
|
|
|
|
|
type: S.tag("BLANK"),
|
|
|
|
|
id: S.String,
|
|
|
|
|
});
|
|
|
|
|
export type BlankTerm = typeof BlankTerm.Type;
|
2026-04-05 21:09:33 -05:00
|
|
|
|
2026-05-12 08:06:58 -05:00
|
|
|
export const LiteralTerm = S.Struct({
|
|
|
|
|
type: S.tag("LITERAL"),
|
|
|
|
|
value: S.String,
|
|
|
|
|
datatype: S.optionalKey(S.String),
|
|
|
|
|
language: S.optionalKey(S.String),
|
|
|
|
|
});
|
|
|
|
|
export type LiteralTerm = typeof LiteralTerm.Type;
|
2026-04-05 21:09:33 -05:00
|
|
|
|
|
|
|
|
export type Term = IriTerm | BlankTerm | LiteralTerm | TripleTerm;
|
2026-05-12 08:06:58 -05:00
|
|
|
export type Triple = {
|
|
|
|
|
readonly s: Term;
|
|
|
|
|
readonly p: Term;
|
|
|
|
|
readonly o: Term;
|
2026-06-02 09:11:33 -05:00
|
|
|
readonly g?: string;
|
2026-05-12 08:06:58 -05:00
|
|
|
};
|
2026-04-05 21:09:33 -05:00
|
|
|
|
2026-06-02 09:11:33 -05:00
|
|
|
export const Triple: S.Codec<Triple, Triple> = S.Struct({
|
|
|
|
|
s: S.suspend((): S.Codec<Term, Term> => Term),
|
|
|
|
|
p: S.suspend((): S.Codec<Term, Term> => Term),
|
|
|
|
|
o: S.suspend((): S.Codec<Term, Term> => Term),
|
|
|
|
|
g: S.optionalKey(S.String),
|
|
|
|
|
});
|
2026-04-05 21:09:33 -05:00
|
|
|
|
2026-06-02 09:11:33 -05:00
|
|
|
export const TripleTerm: S.Codec<TripleTerm, TripleTerm> = S.Struct({
|
|
|
|
|
type: S.tag("TRIPLE"),
|
|
|
|
|
triple: S.suspend((): S.Codec<Triple, Triple> => Triple),
|
|
|
|
|
});
|
2026-05-12 08:06:58 -05:00
|
|
|
export interface TripleTerm {
|
|
|
|
|
readonly type: "TRIPLE";
|
|
|
|
|
readonly triple: Triple;
|
2026-04-05 21:09:33 -05:00
|
|
|
}
|
|
|
|
|
|
2026-06-02 09:11:33 -05:00
|
|
|
export const Term = S.Union([IriTerm, BlankTerm, LiteralTerm, TripleTerm]).pipe(
|
|
|
|
|
S.toTaggedUnion("type"),
|
|
|
|
|
);
|
2026-04-05 21:09:33 -05:00
|
|
|
|
2026-05-12 08:06:58 -05:00
|
|
|
export const Field = S.Struct({
|
|
|
|
|
name: S.String,
|
|
|
|
|
type: S.String,
|
|
|
|
|
description: S.optionalKey(S.String),
|
|
|
|
|
});
|
|
|
|
|
export type Field = typeof Field.Type;
|
2026-04-05 21:09:33 -05:00
|
|
|
|
2026-05-12 08:06:58 -05:00
|
|
|
export const RowSchema = S.Struct({
|
|
|
|
|
name: S.String,
|
|
|
|
|
description: S.optionalKey(S.String),
|
|
|
|
|
fields: S.Array(Field).pipe(S.mutable),
|
|
|
|
|
});
|
|
|
|
|
export type RowSchema = typeof RowSchema.Type;
|
|
|
|
|
|
|
|
|
|
export const LlmResult = S.Struct({
|
|
|
|
|
text: S.String,
|
2026-06-06 10:33:10 -05:00
|
|
|
inToken: S.Finite,
|
|
|
|
|
outToken: S.Finite,
|
2026-05-12 08:06:58 -05:00
|
|
|
model: S.String,
|
|
|
|
|
});
|
|
|
|
|
export type LlmResult = typeof LlmResult.Type;
|
|
|
|
|
|
|
|
|
|
export const LlmChunk = S.Struct({
|
|
|
|
|
text: S.String,
|
2026-06-06 10:33:10 -05:00
|
|
|
inToken: S.NullOr(S.Finite),
|
|
|
|
|
outToken: S.NullOr(S.Finite),
|
2026-05-12 08:06:58 -05:00
|
|
|
model: S.String,
|
|
|
|
|
isFinal: S.Boolean,
|
|
|
|
|
});
|
|
|
|
|
export type LlmChunk = typeof LlmChunk.Type;
|