gongxiangp2/apps/detail-agent-pi/scripts/read-platform-rule-catalog.mjs
WuYongJie 1b6425b552 feat(desktop): connect native Pi sessions with scoped rules and recovery
Track the fixed PhotoCraft source baseline with the existing native client integration. Use the actual Pi SDK for normal sends, durable session recovery, demand-loaded enterprise rules and checked undoable canvas tools. Retain request identities and never resend unknown inference. Include local packaging and real-call acceptance evidence.
2026-10-22 10:49:58 +08:00

28 lines
1.7 KiB
JavaScript

import fs from 'node:fs/promises';
import path from 'node:path';
import { createRequire } from 'node:module';
// Read the platform configured in THIS repository, never another application's database.
// PostgreSQL enforces a read-only transaction; no schema change, import or seed runs here.
const require = createRequire(path.resolve('package.json'));
require('@next/env').loadEnvConfig(process.cwd(), false, { info() {}, error() {}, warn() {} });
const { PrismaClient } = require('@prisma/client');
const url = new URL(process.env.DATABASE_URL);
const prisma = new PrismaClient({ log: [] });
const output = path.resolve(process.argv[2] || 'output/pi-compatibility-20261021/platform-catalog.json');
try {
const value = await prisma.$transaction(async tx => {
await tx.$executeRawUnsafe('SET TRANSACTION READ ONLY');
const shops = await tx.category.findMany({ select: { id: true, name: true }, orderBy: { name: 'asc' } });
const categories = await tx.productCategory.findMany({ select: { id: true, name: true }, orderBy: { name: 'asc' } });
return { shops, categories };
}, { maxWait: 5000, timeout: 15000 });
const snapshot = { source: 'this-repository-configured-platform-readonly', capturedAt: new Date().toISOString(), database: { host: url.hostname, name: url.pathname.slice(1) }, ...value };
await fs.mkdir(path.dirname(output), { recursive: true });
await fs.writeFile(output, JSON.stringify(snapshot, null, 2));
console.log(JSON.stringify(snapshot, null, 2));
} catch (error) {
console.error(JSON.stringify({ error: '当前项目目录只读查询失败', code: error.code || error.name }));
process.exitCode = 1;
} finally { await prisma.$disconnect(); }