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).
35 lines
1.1 KiB
TypeScript
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>;
|