Spaces:
Running
Running
Download lib/db-mappers.ts from Jacksuyu/demandsolution-codex: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/spaces/Jacksuyu/demandsolution-codex/resolve/main/lib/db-mappers.ts
- Command line
-
hf download hf://spaces/Jacksuyu/demandsolution-codex/lib/db-mappers.ts
-
curl -L -o db-mappers.ts https://huggingface.co/spaces/Jacksuyu/demandsolution-codex/resolve/main/lib/db-mappers.ts
1.16 kB
| import type { Idea, Task, TaskLink } from "@prisma/client"; | |
| import { normalizeIdeaCopy } from "@/lib/idea-copy"; | |
| import { buildMeaningfulTitle } from "@/lib/title"; | |
| export function parseJsonArray<T>(value: string, fallback: T[] = []): T[] { | |
| try { | |
| return JSON.parse(value) as T[]; | |
| } catch { | |
| return fallback; | |
| } | |
| } | |
| export function mapIdea(idea: Idea) { | |
| const normalizedCopy = normalizeIdeaCopy({ | |
| rawInputText: idea.rawInputText, | |
| problemStatement: idea.problemStatement, | |
| }); | |
| return { | |
| ...idea, | |
| title: buildMeaningfulTitle({ | |
| rawInputText: normalizedCopy.rawInputText, | |
| title: idea.title, | |
| problemStatement: normalizedCopy.problemStatement, | |
| }), | |
| rawInputText: normalizedCopy.rawInputText, | |
| problemStatement: normalizedCopy.problemStatement, | |
| tags: parseJsonArray<string>(idea.tags), | |
| features: parseJsonArray<string>(idea.features), | |
| open_questions: parseJsonArray<string>(idea.openQuestions), | |
| }; | |
| } | |
| export function mapTask(task: Task & { links?: TaskLink[] }) { | |
| return { | |
| ...task, | |
| acceptance_criteria: parseJsonArray<string>(task.acceptance), | |
| links: task.links ?? [], | |
| }; | |
| } | |