Download packages/dependency-fabric/src/index.ts from AnthropicallyHuggingFaces/ProjectOS: direct link, hf CLI and curl.
- Browser
- Download file 3.88 kB
-
https://huggingface.co/spaces/AnthropicallyHuggingFaces/ProjectOS/resolve/main/packages/dependency-fabric/src/index.ts
- Command line
-
hf download hf://spaces/AnthropicallyHuggingFaces/ProjectOS/packages/dependency-fabric/src/index.ts
-
curl -L -o index.ts https://huggingface.co/spaces/AnthropicallyHuggingFaces/ProjectOS/resolve/main/packages/dependency-fabric/src/index.ts
3.88 kB
| import { randomUUID } from 'node:crypto'; | |
| import type { DatabaseSync } from 'node:sqlite'; | |
| export const dependencyKinds = ['model', 'dataset', 'permission', 'tool', 'infrastructure'] as const; | |
| export type DependencyKind = typeof dependencyKinds[number]; | |
| export type DependencyStatus = 'open' | 'resolved' | 'waived'; | |
| export type DependencyFinding = { | |
| id: string; | |
| projectId: string; | |
| kind: DependencyKind; | |
| name: string; | |
| description: string; | |
| status: DependencyStatus; | |
| source: string; | |
| metadata: Record<string, unknown>; | |
| detectedAt: string; | |
| resolvedAt: string | null; | |
| }; | |
| export type DependencyInput = { | |
| projectId: string; | |
| kind: DependencyKind; | |
| name: string; | |
| description?: string; | |
| source?: string; | |
| metadata?: Record<string, unknown>; | |
| }; | |
| function fromRow(row: Record<string, unknown> | undefined): DependencyFinding | null { | |
| if (!row) return null; | |
| return { | |
| id: String(row.finding_id), | |
| projectId: String(row.project_id), | |
| kind: row.kind as DependencyKind, | |
| name: String(row.name), | |
| description: String(row.description), | |
| status: row.status as DependencyStatus, | |
| source: String(row.source), | |
| metadata: JSON.parse(String(row.metadata_json)) as Record<string, unknown>, | |
| detectedAt: String(row.detected_at), | |
| resolvedAt: row.resolved_at === null ? null : String(row.resolved_at) | |
| }; | |
| } | |
| export class DependencyService { | |
| constructor(private readonly db: DatabaseSync) {} | |
| record(input: DependencyInput): DependencyFinding { | |
| if (!dependencyKinds.includes(input.kind)) throw new Error(`Unsupported dependency kind: ${String(input.kind)}`); | |
| const name = input.name.trim(); | |
| if (!name) throw new Error('Dependency name is required.'); | |
| const existing = this.db.prepare(`SELECT * FROM dependency_findings | |
| WHERE project_id = ? AND kind = ? AND name = ? AND status = 'open' | |
| ORDER BY detected_at DESC LIMIT 1`).get(input.projectId, input.kind, name); | |
| if (existing) return fromRow(existing as Record<string, unknown>)!; | |
| const id = randomUUID(); | |
| this.db.prepare(`INSERT INTO dependency_findings(finding_id, project_id, kind, name, description, status, source, metadata_json) | |
| VALUES (?, ?, ?, ?, ?, 'open', ?, ?)`) | |
| .run(id, input.projectId, input.kind, name, input.description ?? '', input.source ?? 'manual', JSON.stringify(input.metadata ?? {})); | |
| return this.get(id)!; | |
| } | |
| get(findingId: string): DependencyFinding | null { | |
| return fromRow(this.db.prepare('SELECT * FROM dependency_findings WHERE finding_id = ?').get(findingId) as Record<string, unknown> | undefined); | |
| } | |
| list(projectId: string, filters: { status?: DependencyStatus; kind?: DependencyKind } = {}): DependencyFinding[] { | |
| const clauses = ['project_id = ?']; | |
| const values: string[] = [projectId]; | |
| if (filters.status) { clauses.push('status = ?'); values.push(filters.status); } | |
| if (filters.kind) { clauses.push('kind = ?'); values.push(filters.kind); } | |
| return this.db.prepare(`SELECT * FROM dependency_findings WHERE ${clauses.join(' AND ')} ORDER BY detected_at DESC, finding_id`) | |
| .all(...values) | |
| .map((row) => fromRow(row as Record<string, unknown>)!); | |
| } | |
| resolve(findingId: string, resolution: 'resolved' | 'waived' = 'resolved'): DependencyFinding { | |
| if (resolution !== 'resolved' && resolution !== 'waived') throw new Error('Resolution must be resolved or waived.'); | |
| const result = this.db.prepare(`UPDATE dependency_findings SET status = ?, resolved_at = ? | |
| WHERE finding_id = ? AND status = 'open'`).run(resolution, new Date().toISOString(), findingId); | |
| const finding = this.get(findingId); | |
| if (!finding) throw new Error(`Dependency finding "${findingId}" does not exist.`); | |
| if (result.changes === 0 && finding.status === 'open') throw new Error(`Dependency finding "${findingId}" could not be updated.`); | |
| return finding; | |
| } | |
| } | |