Create Metagraph Type.Module with Config, BaseNode, BaseEdge entries

Add src/graphs/modules/metagraph.ts exporting Metagraph as Type.Module()
with Config (Union defaults for type, Boolean defaults for multi/allowSelfLoops),
BaseNode (optional created/modified/metadata with Type.Unknown()), and
BaseEdge (type string, optional metadata with Type.Unknown()). Also export
GRAPH_STATUS const and GraphStatus TypeBox schema for sqlite host usage.
Update mod.ts to re-export from modules/metagraph.ts.
This commit is contained in:
2026-05-29 10:55:18 +00:00
parent 2b0badd501
commit 79141d594d
2 changed files with 42 additions and 0 deletions

View File

@@ -1,2 +1,7 @@
export * from "./types.ts";
export * from "./schemaBuilder.ts";
export {
Metagraph,
GRAPH_STATUS,
GraphStatus,
} from "./modules/metagraph.ts";

View File

@@ -0,0 +1,37 @@
import { Type } from "@alkdev/typebox";
export const Metagraph = Type.Module({
Config: Type.Object({
type: Type.Union([
Type.Literal("directed"),
Type.Literal("undirected"),
Type.Literal("mixed"),
], { default: "mixed" }),
multi: Type.Boolean({ default: true }),
allowSelfLoops: Type.Boolean({ default: true }),
}),
BaseNode: Type.Object({
created: Type.Optional(Type.String({ format: "date-time" })),
modified: Type.Optional(Type.String({ format: "date-time" })),
metadata: Type.Optional(Type.Record(Type.String(), Type.Unknown())),
}),
BaseEdge: Type.Object({
type: Type.String(),
metadata: Type.Optional(Type.Record(Type.String(), Type.Unknown())),
}),
});
export const GRAPH_STATUS = {
Active: "active",
Archived: "archived",
Draft: "draft",
} as const;
export type GraphStatus = (typeof GRAPH_STATUS)[keyof typeof GRAPH_STATUS];
export const GraphStatus = Type.Union([
Type.Literal(GRAPH_STATUS.Active),
Type.Literal(GRAPH_STATUS.Archived),
Type.Literal(GRAPH_STATUS.Draft),
]);