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>
69 lines
1.9 KiB
TypeScript
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
|
|
}
|