diff --git a/src/graphs/mod.ts b/src/graphs/mod.ts index 50546d2..697064f 100644 --- a/src/graphs/mod.ts +++ b/src/graphs/mod.ts @@ -1,6 +1,8 @@ -export * from "./types.ts"; export { Metagraph, + GraphConfig, + BaseNodeAttributes, + BaseEdgeAttributes, 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 index b1cdeee..794b796 100644 --- a/src/graphs/modules/metagraph.ts +++ b/src/graphs/modules/metagraph.ts @@ -1,4 +1,4 @@ -import { Type } from "@alkdev/typebox"; +import { type Static, Type } from "@alkdev/typebox"; export const Metagraph = Type.Module({ Config: Type.Object({ @@ -23,6 +23,15 @@ export const Metagraph = Type.Module({ }), }); +export const GraphConfig = Metagraph.Import("Config"); +export type GraphConfig = Static; + +export const BaseNodeAttributes = Metagraph.Import("BaseNode"); +export type BaseNodeAttributes = Static; + +export const BaseEdgeAttributes = Metagraph.Import("BaseEdge"); +export type BaseEdgeAttributes = Static; + export const GRAPH_STATUS = { Active: "active", Archived: "archived", diff --git a/src/graphs/types.ts b/src/graphs/types.ts deleted file mode 100644 index ac96772..0000000 --- a/src/graphs/types.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { type Static, type TSchema, Type } from "@alkdev/typebox"; - -export const BaseNodeAttributes: TSchema = 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())), -}); - -export type BaseNodeAttributes = Static; - -export const BaseEdgeAttributes: TSchema = Type.Object({ - type: Type.String(), - metadata: Type.Optional(Type.Record(Type.String(), Type.Unknown())), -}); - -export type BaseEdgeAttributes = Static; - -export const GraphConfig: TSchema = 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 }), -}); - -export type GraphConfig = Static; - -export const NodeType: TSchema = Type.Object({ - name: Type.String(), - schema: Type.Unknown(), -}); - -export type NodeType = Static; - -export const EdgeType: TSchema = Type.Object({ - name: Type.String(), - schema: Type.Unknown(), - allowedSourceTypes: Type.Optional(Type.Array(Type.String())), - allowedTargetTypes: Type.Optional(Type.Array(Type.String())), -}); - -export type EdgeType = Static; - -export const GraphSchema: TSchema = Type.Object({ - config: GraphConfig, - nodeTypes: Type.Record(Type.String(), NodeType), - edgeTypes: Type.Record(Type.String(), EdgeType), -}); - -export type GraphSchema = Static; - -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: TSchema = Type.Union([ - Type.Literal(GRAPH_STATUS.Active), - Type.Literal(GRAPH_STATUS.Archived), - Type.Literal(GRAPH_STATUS.Draft), -]); - -export const GRAPH_BASE_TYPE = { - Directed: "directed", - Undirected: "undirected", - Mixed: "mixed", -} as const; - -export type GraphBaseType = - (typeof GRAPH_BASE_TYPE)[keyof typeof GRAPH_BASE_TYPE]; -export const GraphBaseType: TSchema = Type.Union([ - Type.Literal(GRAPH_BASE_TYPE.Directed), - Type.Literal(GRAPH_BASE_TYPE.Undirected), - Type.Literal(GRAPH_BASE_TYPE.Mixed), -]); diff --git a/src/sqlite/tables/graphTypes.ts b/src/sqlite/tables/graphTypes.ts index ff69bae..5d1fcd2 100644 --- a/src/sqlite/tables/graphTypes.ts +++ b/src/sqlite/tables/graphTypes.ts @@ -2,7 +2,7 @@ import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core"; import { createInsertSchema, createSelectSchema } from "@alkdev/drizzlebox"; import { type Static, Type } from "@alkdev/typebox"; import { commonCols } from "./common.ts"; -import type { GraphConfig } from "../../graphs/types.ts"; +import type { GraphConfig } from "../../graphs/modules/metagraph.ts"; type GraphConfigType = Static; diff --git a/src/sqlite/tables/graphs.ts b/src/sqlite/tables/graphs.ts index 5c6061c..a1be551 100644 --- a/src/sqlite/tables/graphs.ts +++ b/src/sqlite/tables/graphs.ts @@ -3,7 +3,7 @@ import { createInsertSchema, createSelectSchema } from "@alkdev/drizzlebox"; import { type Static, Type } from "@alkdev/typebox"; import { commonCols } from "./common.ts"; import { graphTypes } from "./graphTypes.ts"; -import { GRAPH_STATUS } from "../../graphs/types.ts"; +import { GRAPH_STATUS } from "../../graphs/modules/metagraph.ts"; export const graphs = sqliteTable("graphs", { ...commonCols,