From 79141d594d14af8fe29334251530b1b44c1f9418 Mon Sep 17 00:00:00 2001 From: "glm-5.1" Date: Fri, 29 May 2026 10:55:18 +0000 Subject: [PATCH] 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. --- src/graphs/mod.ts | 5 +++++ src/graphs/modules/metagraph.ts | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 src/graphs/modules/metagraph.ts diff --git a/src/graphs/mod.ts b/src/graphs/mod.ts index 7ce8c98..2d6ac24 100644 --- a/src/graphs/mod.ts +++ b/src/graphs/mod.ts @@ -1,2 +1,7 @@ export * from "./types.ts"; export * from "./schemaBuilder.ts"; +export { + Metagraph, + GRAPH_STATUS, + GraphStatus, +} from "./modules/metagraph.ts"; \ No newline at end of file diff --git a/src/graphs/modules/metagraph.ts b/src/graphs/modules/metagraph.ts new file mode 100644 index 0000000..b1cdeee --- /dev/null +++ b/src/graphs/modules/metagraph.ts @@ -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), +]); \ No newline at end of file