Files
Momento/memento-note/lib/structured-views/schema-serialize.ts
Antigravity 0784c94242
Some checks failed
CI / Lint, Test & Build (push) Failing after 57s
CI / Deploy production (on server) (push) Has been skipped
feat(notes): vues structurées tableau/kanban, flashcards et MCP robuste
Ajoute la base organisable par carnet (schéma, champs partagés, valeurs par note)
avec activation guidée, tableau éditable, kanban et suppression de colonnes.
Corrige le multiselect en vue tableau et enrichit sidebar, grille et i18n FR/EN.
Inclut aussi les améliorations flashcards SM-2, l'audit consentement IA et la
robustesse du serveur MCP (config, validation, rate-limit, métriques).

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-24 23:03:16 +00:00

69 lines
1.9 KiB
TypeScript

import type { NotebookViewSettings, NotebookSchemaPayload, SchemaProperty } from './types'
import { parsePropertyOptions, parseStoredPropertyValue } from './property-utils'
import { isValidPropertyType } from './property-utils'
type RawSchema = {
id: string
notebookId: string
viewSettings: string | null
properties: Array<{
id: string
name: string
type: string
options: string | null
position: number
}>
}
export function parseViewSettings(raw: string | null | undefined): NotebookViewSettings {
if (!raw) return {}
try {
const parsed = JSON.parse(raw) as NotebookViewSettings
return {
kanbanGroupPropertyId: parsed.kanbanGroupPropertyId ?? null,
}
} catch {
return {}
}
}
export function serializeSchema(raw: RawSchema | null): NotebookSchemaPayload | null {
if (!raw) return null
const properties: SchemaProperty[] = raw.properties
.filter((p) => isValidPropertyType(p.type))
.sort((a, b) => a.position - b.position)
.map((p) => ({
id: p.id,
name: p.name,
type: p.type as SchemaProperty['type'],
options: parsePropertyOptions(p.options),
position: p.position,
}))
return {
id: raw.id,
notebookId: raw.notebookId,
viewSettings: parseViewSettings(raw.viewSettings),
properties,
}
}
export function buildNoteValuesMap(
noteIds: string[],
rows: Array<{ noteId: string; propertyId: string; value: string | null; property: { type: string } }>,
): Record<string, Record<string, unknown>> {
const map: Record<string, Record<string, unknown>> = {}
for (const id of noteIds) {
map[id] = {}
}
for (const row of rows) {
if (!map[row.noteId]) map[row.noteId] = {}
if (!isValidPropertyType(row.property.type)) continue
map[row.noteId][row.propertyId] = parseStoredPropertyValue(
row.property.type,
row.value,
)
}
return map
}