feat: persist metafield resolutions across sessions
Les associations colonne→métachamp sont sauvegardées dans data/metafield-resolutions.json et rechargées automatiquement à la prochaine création de produits. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import { readFile, writeFile, mkdir } from 'fs/promises'
|
||||
import { join } from 'path'
|
||||
import type { MetafieldResolution } from '@/types/creation'
|
||||
|
||||
const CACHE_DIR = join(process.cwd(), 'data')
|
||||
const CACHE_FILE = join(CACHE_DIR, 'metafield-resolutions.json')
|
||||
|
||||
export async function loadResolutionCache(): Promise<Record<string, MetafieldResolution>> {
|
||||
try {
|
||||
const raw = await readFile(CACHE_FILE, 'utf-8')
|
||||
return JSON.parse(raw) as Record<string, MetafieldResolution>
|
||||
} catch {
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
export async function saveResolutionCache(cache: Record<string, MetafieldResolution>): Promise<void> {
|
||||
await mkdir(CACHE_DIR, { recursive: true })
|
||||
await writeFile(CACHE_FILE, JSON.stringify(cache, null, 2), 'utf-8')
|
||||
}
|
||||
Reference in New Issue
Block a user