fix: use import type for GraphConfig, remove verbatim-module-syntax exclusion

The verbatim-module-syntax lint rule was correctly flagging that
GraphConfig is only used in a type position (typeof GraphConfig). Since
typeof resolves purely at the type level, import type works fine here
and is the correct form. No lint exclusion needed.

Also: deno fmt across all files (markdown line wrapping).
This commit is contained in:
2026-05-28 13:38:42 +00:00
parent b0298663dc
commit bb544469fd
34 changed files with 1279 additions and 617 deletions

View File

@@ -1,2 +1,2 @@
export * from "./types.ts";
export * from "./schemaBuilder.ts";
export * from "./schemaBuilder.ts";

View File

@@ -1,7 +1,7 @@
import { KindGuard, type TSchema } from "@alkdev/typebox";
import { Value } from "@alkdev/typebox/value";
import { assert } from "@std/assert";
import { GraphSchema, GraphConfig, NodeType, EdgeType } from "./types.ts";
import { EdgeType, GraphConfig, GraphSchema, NodeType } from "./types.ts";
export class SchemaBuilder {
private schema: {
@@ -22,7 +22,10 @@ export class SchemaBuilder {
}
nodeType(name: string, schema: TSchema): SchemaBuilder {
assert(KindGuard.IsSchema(schema), `type '${name}' is not a valid json schema.`);
assert(
KindGuard.IsSchema(schema),
`type '${name}' is not a valid json schema.`,
);
if (!this.schema.nodeTypes) this.schema.nodeTypes = {};
const nodeTypeObj: NodeType = { name, schema };
@@ -37,7 +40,10 @@ export class SchemaBuilder {
schema: TSchema,
options?: { allowedSourceTypes?: string[]; allowedTargetTypes?: string[] },
): SchemaBuilder {
assert(KindGuard.IsSchema(schema), `type '${name}' is not a valid json schema.`);
assert(
KindGuard.IsSchema(schema),
`type '${name}' is not a valid json schema.`,
);
if (!this.schema.edgeTypes) this.schema.edgeTypes = {};
const edgeTypeObj: EdgeType = { name, schema, ...options };
@@ -51,7 +57,9 @@ export class SchemaBuilder {
if (!Value.Check(schema, value)) {
const errors = [...Value.Errors(schema, value)];
throw new Error(
`Invalid schema structure: ${JSON.stringify(errors.map((e) => `${e.path}: ${e.message}`))}`,
`Invalid schema structure: ${
JSON.stringify(errors.map((e) => `${e.path}: ${e.message}`))
}`,
);
}
}
@@ -60,4 +68,4 @@ export class SchemaBuilder {
this.check(GraphSchema, this.schema);
return this.schema as GraphSchema;
}
}
}

View File

@@ -1,4 +1,4 @@
import { Type, type Static, type TSchema } from "@alkdev/typebox";
import { type Static, type TSchema, Type } from "@alkdev/typebox";
export const BaseNodeAttributes: TSchema = Type.Object({
created: Type.Optional(Type.String({ format: "date-time" })),
@@ -70,9 +70,10 @@ export const GRAPH_BASE_TYPE = {
Mixed: "mixed",
} as const;
export type GraphBaseType = (typeof GRAPH_BASE_TYPE)[keyof typeof GRAPH_BASE_TYPE];
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),
]);
]);

View File

@@ -1,3 +1,3 @@
// Postgres host — not yet implemented
// Will mirror sqlite/ structure with pgTable, jsonb(), timestamp(), pgEnum, etc.
// Import pattern: import { ... } from "@alkdev/storage/pg"
// Import pattern: import { ... } from "@alkdev/storage/pg"

View File

@@ -8,4 +8,4 @@ export type SqliteDatabase = LibSQLDatabase<SqliteSchema>;
export function createSqliteDatabase(client: Client): SqliteDatabase {
return drizzle(client, { schema }) as SqliteDatabase;
}
}

View File

@@ -1,2 +1,2 @@
export * from "./schema.ts";
export * from "./client.ts";
export * from "./client.ts";

View File

@@ -1,11 +1,11 @@
import { relations } from "drizzle-orm";
import {
graphTypes,
nodeTypes,
edges,
edgeTypes,
graphs,
graphTypes,
nodes,
edges,
nodeTypes,
} from "./tables/index.ts";
export const graphTypeRelations = relations(graphTypes, ({ many }) => ({
@@ -65,4 +65,4 @@ export const nodesRelations = relations(nodes, ({ one, many }) => ({
incomingEdges: many(edges, {
relationName: "targetNode",
}),
}));
}));

View File

@@ -1,2 +1,2 @@
export * from "./tables/index.ts";
export * from "./relations.ts";
export * from "./relations.ts";

View File

@@ -1,7 +1,7 @@
import { sqliteTable, text } from "drizzle-orm/sqlite-core";
import { createInsertSchema, createSelectSchema } from "@alkdev/drizzlebox";
import { Type, type Static } from "@alkdev/typebox";
import { commonCols, ACTOR_TYPE } from "./common.ts";
import { type Static, Type } from "@alkdev/typebox";
import { ACTOR_TYPE, commonCols } from "./common.ts";
export const actors = sqliteTable("actors", {
...commonCols,
@@ -27,4 +27,4 @@ export const InsertActor = createInsertSchema(actors, {
metadata: Type.Optional(Type.Object({}, { additionalProperties: true })),
});
export type InsertActor = Static<typeof InsertActor>;
export type InsertActor = Static<typeof InsertActor>;

View File

@@ -1,9 +1,10 @@
import { sql } from "drizzle-orm";
import { text, integer } from "drizzle-orm/sqlite-core";
import { integer, text } from "drizzle-orm/sqlite-core";
export const commonCols = {
id: text("id").primaryKey(),
metadata: text("metadata", { mode: "json" }).$type<Record<string, unknown>>().default({}),
metadata: text("metadata", { mode: "json" }).$type<Record<string, unknown>>()
.default({}),
createdAt: integer("created_at", { mode: "timestamp" })
.default(sql`(strftime('%s', 'now'))`)
.notNull(),
@@ -18,4 +19,4 @@ export const ACTOR_TYPE = {
Agent: "agent",
} as const;
export type EnumValues<T extends Record<string, string>> = T[keyof T];
export type EnumValues<T extends Record<string, string>> = T[keyof T];

View File

@@ -1,17 +1,24 @@
import { sqliteTable, text, unique } from "drizzle-orm/sqlite-core";
import { createInsertSchema, createSelectSchema } from "@alkdev/drizzlebox";
import { Type, type Static } from "@alkdev/typebox";
import { type Static, Type } from "@alkdev/typebox";
import { commonCols } from "./common.ts";
import { graphTypes } from "./graphTypes.ts";
export const edgeTypes = sqliteTable("edge_types", {
...commonCols,
graphTypeId: text("graph_type_id").notNull().references(() => graphTypes.id, { onDelete: "cascade" }),
graphTypeId: text("graph_type_id").notNull().references(() => graphTypes.id, {
onDelete: "cascade",
}),
name: text("name").notNull(),
description: text("description").default(""),
schema: text("schema", { mode: "json" }).$type<Record<string, unknown>>().notNull(),
allowedSourceTypes: text("allowed_source_types", { mode: "json" }).$type<string[]>().default([]),
allowedTargetTypes: text("allowed_target_types", { mode: "json" }).$type<string[]>().default([]),
schema: text("schema", { mode: "json" }).$type<Record<string, unknown>>()
.notNull(),
allowedSourceTypes: text("allowed_source_types", { mode: "json" }).$type<
string[]
>().default([]),
allowedTargetTypes: text("allowed_target_types", { mode: "json" }).$type<
string[]
>().default([]),
}, (table) => ({
graphTypeNameIdx: unique().on(table.graphTypeId, table.name),
}));
@@ -34,4 +41,4 @@ export const InsertEdgeType = createInsertSchema(edgeTypes, {
allowedTargetTypes: Type.Optional(Type.Array(Type.String())),
});
export type InsertEdgeType = Static<typeof InsertEdgeType>;
export type InsertEdgeType = Static<typeof InsertEdgeType>;

View File

@@ -1,6 +1,12 @@
import { sqliteTable, text, integer, unique, foreignKey } from "drizzle-orm/sqlite-core";
import {
foreignKey,
integer,
sqliteTable,
text,
unique,
} from "drizzle-orm/sqlite-core";
import { createInsertSchema, createSelectSchema } from "@alkdev/drizzlebox";
import { Type, type Static } from "@alkdev/typebox";
import { type Static, Type } from "@alkdev/typebox";
import { commonCols } from "./common.ts";
import { graphs } from "./graphs.ts";
import { nodes } from "./nodes.ts";
@@ -9,7 +15,9 @@ const AttributesSchema = Type.Record(Type.String(), Type.Any());
export const edges = sqliteTable("edges", {
...commonCols,
graphId: text("graph_id").notNull().references(() => graphs.id, { onDelete: "cascade" }),
graphId: text("graph_id").notNull().references(() => graphs.id, {
onDelete: "cascade",
}),
key: text("key"),
sourceNodeKey: text("source_node_key").notNull(),
targetNodeKey: text("target_node_key").notNull(),
@@ -41,4 +49,4 @@ export const InsertEdge = createInsertSchema(edges, {
attributes: AttributesSchema,
});
export type InsertEdge = Static<typeof InsertEdge>;
export type InsertEdge = Static<typeof InsertEdge>;

View File

@@ -1,8 +1,8 @@
import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core";
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
import { createInsertSchema, createSelectSchema } from "@alkdev/drizzlebox";
import { Type, type Static } from "@alkdev/typebox";
import { type Static, Type } from "@alkdev/typebox";
import { commonCols } from "./common.ts";
import { GraphConfig } from "../../graphs/types.ts";
import type { GraphConfig } from "../../graphs/types.ts";
type GraphConfigType = Static<typeof GraphConfig>;
@@ -27,4 +27,4 @@ export const InsertGraphType = createInsertSchema(graphTypes, {
description: Type.Optional(Type.String()),
});
export type InsertGraphType = Static<typeof InsertGraphType>;
export type InsertGraphType = Static<typeof InsertGraphType>;

View File

@@ -1,13 +1,15 @@
import { sqliteTable, text } from "drizzle-orm/sqlite-core";
import { createInsertSchema, createSelectSchema } from "@alkdev/drizzlebox";
import { Type, type Static } from "@alkdev/typebox";
import { type Static, Type } from "@alkdev/typebox";
import { commonCols } from "./common.ts";
import { graphTypes } from "./graphTypes.ts";
import { GRAPH_STATUS } from "../../graphs/types.ts";
export const graphs = sqliteTable("graphs", {
...commonCols,
graphTypeId: text("graph_type_id").references(() => graphTypes.id, { onDelete: "set null" }),
graphTypeId: text("graph_type_id").references(() => graphTypes.id, {
onDelete: "set null",
}),
name: text("name").notNull(),
description: text("description").default(""),
status: text("status", { enum: ["active", "archived", "draft"] })
@@ -32,4 +34,4 @@ export const InsertGraph = createInsertSchema(graphs, {
])),
});
export type InsertGraph = Static<typeof InsertGraph>;
export type InsertGraph = Static<typeof InsertGraph>;

View File

@@ -1,23 +1,41 @@
export { graphs } from "./graphs.ts";
export type { SelectGraph, InsertGraph } from "./graphs.ts";
export { SelectGraph as SelectGraphSchema, InsertGraph as InsertGraphSchema } from "./graphs.ts";
export type { InsertGraph, SelectGraph } from "./graphs.ts";
export {
InsertGraph as InsertGraphSchema,
SelectGraph as SelectGraphSchema,
} from "./graphs.ts";
export { nodes } from "./nodes.ts";
export type { SelectNode, InsertNode } from "./nodes.ts";
export { SelectNodeSchema, InsertNodeSchema } from "./nodes.ts";
export type { InsertNode, SelectNode } from "./nodes.ts";
export { InsertNodeSchema, SelectNodeSchema } from "./nodes.ts";
export { edges } from "./edges.ts";
export type { SelectEdge, InsertEdge } from "./edges.ts";
export { SelectEdge as SelectEdgeSchema, InsertEdge as InsertEdgeSchema } from "./edges.ts";
export type { InsertEdge, SelectEdge } from "./edges.ts";
export {
InsertEdge as InsertEdgeSchema,
SelectEdge as SelectEdgeSchema,
} from "./edges.ts";
export { graphTypes } from "./graphTypes.ts";
export type { SelectGraphType, InsertGraphType } from "./graphTypes.ts";
export { SelectGraphType as SelectGraphTypeSchema, InsertGraphType as InsertGraphTypeSchema } from "./graphTypes.ts";
export type { InsertGraphType, SelectGraphType } from "./graphTypes.ts";
export {
InsertGraphType as InsertGraphTypeSchema,
SelectGraphType as SelectGraphTypeSchema,
} from "./graphTypes.ts";
export { nodeTypes } from "./nodeTypes.ts";
export type { SelectNodeType, InsertNodeType } from "./nodeTypes.ts";
export { SelectNodeType as SelectNodeTypeSchema, InsertNodeType as InsertNodeTypeSchema } from "./nodeTypes.ts";
export type { InsertNodeType, SelectNodeType } from "./nodeTypes.ts";
export {
InsertNodeType as InsertNodeTypeSchema,
SelectNodeType as SelectNodeTypeSchema,
} from "./nodeTypes.ts";
export { edgeTypes } from "./edgeTypes.ts";
export type { SelectEdgeType, InsertEdgeType } from "./edgeTypes.ts";
export { SelectEdgeType as SelectEdgeTypeSchema, InsertEdgeType as InsertEdgeTypeSchema } from "./edgeTypes.ts";
export type { InsertEdgeType, SelectEdgeType } from "./edgeTypes.ts";
export {
InsertEdgeType as InsertEdgeTypeSchema,
SelectEdgeType as SelectEdgeTypeSchema,
} from "./edgeTypes.ts";
export { actors } from "./actors.ts";
export type { SelectActor, InsertActor } from "./actors.ts";
export { SelectActor as SelectActorSchema, InsertActor as InsertActorSchema } from "./actors.ts";
export { commonCols, ACTOR_TYPE } from "./common.ts";
export type { EnumValues } from "./common.ts";
export type { InsertActor, SelectActor } from "./actors.ts";
export {
InsertActor as InsertActorSchema,
SelectActor as SelectActorSchema,
} from "./actors.ts";
export { ACTOR_TYPE, commonCols } from "./common.ts";
export type { EnumValues } from "./common.ts";

View File

@@ -1,15 +1,18 @@
import { sqliteTable, text, unique } from "drizzle-orm/sqlite-core";
import { createInsertSchema, createSelectSchema } from "@alkdev/drizzlebox";
import { Type, type Static } from "@alkdev/typebox";
import { type Static, Type } from "@alkdev/typebox";
import { commonCols } from "./common.ts";
import { graphTypes } from "./graphTypes.ts";
export const nodeTypes = sqliteTable("node_types", {
...commonCols,
graphTypeId: text("graph_type_id").notNull().references(() => graphTypes.id, { onDelete: "cascade" }),
graphTypeId: text("graph_type_id").notNull().references(() => graphTypes.id, {
onDelete: "cascade",
}),
name: text("name").notNull(),
description: text("description").default(""),
schema: text("schema", { mode: "json" }).$type<Record<string, unknown>>().notNull(),
schema: text("schema", { mode: "json" }).$type<Record<string, unknown>>()
.notNull(),
}, (table) => ({
graphTypeNameIdx: unique().on(table.graphTypeId, table.name),
}));
@@ -28,4 +31,4 @@ export const InsertNodeType = createInsertSchema(nodeTypes, {
schema: Type.Unknown(),
});
export type InsertNodeType = Static<typeof InsertNodeType>;
export type InsertNodeType = Static<typeof InsertNodeType>;

View File

@@ -1,6 +1,6 @@
import { sqliteTable, text, unique } from "drizzle-orm/sqlite-core";
import { createInsertSchema, createSelectSchema } from "@alkdev/drizzlebox";
import { Type, type Static } from "@alkdev/typebox";
import { type Static, Type } from "@alkdev/typebox";
import { commonCols } from "./common.ts";
import { graphs } from "./graphs.ts";
@@ -8,7 +8,9 @@ const AttributesSchema = Type.Record(Type.String(), Type.Any());
export const nodes = sqliteTable("nodes", {
...commonCols,
graphId: text("graph_id").notNull().references(() => graphs.id, { onDelete: "cascade" }),
graphId: text("graph_id").notNull().references(() => graphs.id, {
onDelete: "cascade",
}),
key: text("key").notNull(),
attributes: text("attributes", { mode: "json" }).notNull().default({}),
}, (table) => ({
@@ -29,4 +31,4 @@ export const InsertNodeSchema = createInsertSchema(nodes, {
attributes: AttributesSchema,
});
export type InsertNode = Static<typeof InsertNodeSchema>;
export type InsertNode = Static<typeof InsertNodeSchema>;