/** * LearnGraph REST API Server * * Hono-based REST API for skill graphs, learners, and assessments. * * @packageDocumentation */ import { Hono } from 'hono'; import type { GraphStorage } from '../types/index.js'; import type { ApiResponse } from './types.js'; /** * API server configuration */ export interface ApiServerConfig { /** Storage backend */ storage: GraphStorage; /** Base path for API (default: /api) */ basePath?: string; /** Enable CORS (default: true) */ cors?: boolean; /** CORS origins (default: *) */ corsOrigins?: string[]; /** Enable request logging (default: true) */ logging?: boolean; /** Enable timing headers (default: true) */ timing?: boolean; /** Enable pretty JSON (default: false in production) */ prettyJson?: boolean; /** Auth middleware (optional) */ authMiddleware?: (c: unknown, next: () => Promise) => Promise; /** Get current user ID from context */ getCurrentUserId?: (c: unknown) => string | undefined; } /** * Extended storage for API with learner support * The base GraphStorage handles skill graphs; this extends it with learner operations */ export interface ExtendedStorage extends GraphStorage { createLearner?(input: { metadata?: Record; }): Promise<{ id: string; metadata?: Record; createdAt: string; updatedAt: string; }>; getLearner?(id: string): Promise<{ id: string; metadata?: Record; createdAt: string; updatedAt: string; } | null>; updateLearner?(id: string, updates: { metadata?: Record; }): Promise<{ id: string; metadata?: Record; createdAt: string; updatedAt: string; }>; deleteLearner?(id: string): Promise; getAllLearners?(): Promise; createdAt: string; updatedAt: string; }>>; getMastery?(learnerId: string, skillId: string): Promise<{ skillId: string; mastery: number; confidence?: number; lastUpdated?: string; responseHistory?: unknown[]; } | null>; getLearnerMastery?(learnerId: string): Promise>; updateMastery?(learnerId: string, skillId: string, response: { correct: boolean; responseTimeMs?: number; questionId?: string; }): Promise<{ skillId: string; mastery: number; confidence?: number; lastUpdated?: string; responseHistory?: unknown[]; }>; } /** * API context passed to route handlers */ export interface ApiContext { storage: ExtendedStorage; getCurrentUserId?: (c: unknown) => string | undefined; } /** * Create success response */ export declare function success(data: T, meta?: ApiResponse['meta']): ApiResponse; /** * Create error response */ export declare function error(code: string, message: string, details?: Record): ApiResponse; /** * Common error codes */ export declare const ErrorCodes: { readonly NOT_FOUND: "NOT_FOUND"; readonly BAD_REQUEST: "BAD_REQUEST"; readonly UNAUTHORIZED: "UNAUTHORIZED"; readonly FORBIDDEN: "FORBIDDEN"; readonly CONFLICT: "CONFLICT"; readonly INTERNAL_ERROR: "INTERNAL_ERROR"; readonly VALIDATION_ERROR: "VALIDATION_ERROR"; }; /** * Create the LearnGraph API server * * @example * ```typescript * import { createApiServer } from 'learngraph/api'; * import { MemoryStorage } from 'learngraph/storage'; * * const storage = new MemoryStorage(); * await storage.connect({ backend: 'memory' }); * * const app = createApiServer({ storage }); * * // Start with Bun * export default app; * * // Or with Node.js * import { serve } from '@hono/node-server'; * serve({ fetch: app.fetch, port: 3000 }); * ``` */ export declare function createApiServer(config: ApiServerConfig): Hono; /** * Export Hono type for type inference */ export type { Hono }; //# sourceMappingURL=server.d.ts.map