Files
storage/src/sqlite/tables/nodes.ts
glm-5.1 aad9636150 Replace Type.Any() with Type.Unknown() across all source files
Type.Unknown() is canonical per ADR-012. Both produce identical JSON Schema
output but Unknown communicates intent. Changed in src/graphs/types.ts (metadata,
schema fields) and src/sqlite/tables/{nodes,edges}.ts (AttributesSchema).
2026-05-29 10:53:18 +00:00

35 lines
1.1 KiB
TypeScript

import { sqliteTable, text, unique } from "drizzle-orm/sqlite-core";
import { createInsertSchema, createSelectSchema } from "@alkdev/drizzlebox";
import { type Static, Type } from "@alkdev/typebox";
import { commonCols } from "./common.ts";
import { graphs } from "./graphs.ts";
const AttributesSchema = Type.Record(Type.String(), Type.Unknown());
export const nodes = sqliteTable("nodes", {
...commonCols,
graphId: text("graph_id").notNull().references(() => graphs.id, {
onDelete: "cascade",
}),
key: text("key").notNull(),
attributes: text("attributes", { mode: "json" }).notNull().default({}),
}, (table) => ({
graphKeyIdx: unique().on(table.graphId, table.key),
}));
export const SelectNodeSchema = createSelectSchema(nodes, {
attributes: AttributesSchema,
metadata: Type.Object({}, { additionalProperties: true }),
createdAt: Type.Date(),
updatedAt: Type.Date(),
});
export type SelectNode = Static<typeof SelectNodeSchema>;
export const InsertNodeSchema = createInsertSchema(nodes, {
key: Type.String({ minLength: 1 }),
attributes: AttributesSchema,
});
export type InsertNode = Static<typeof InsertNodeSchema>;