// Build only the new read-only metadata function; preserve every existing function. import fs from 'node:fs'; import path from 'node:path'; import crypto from 'node:crypto'; import {fileURLToPath} from 'node:url'; const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..'); const data=JSON.parse(fs.readFileSync(path.join(root,'references/runtime-data.json'),'utf8')); const dictionary=JSON.parse(fs.readFileSync(path.join(root,'references/business-data-dictionary.json'),'utf8')); const common=['postgres.mjs','core.mjs','data-dictionary.mjs'].map(n=>fs.readFileSync(path.join(root,'src',n),'utf8').replace(/^export /gm,'')).join('\n'); const entry=`async function handler(request,response){ response.setHeader('Cache-Control','no-store'); try{ const crypto=await import('node:crypto');const DATA=${JSON.stringify(data)};const DICTIONARY=${JSON.stringify(dictionary)}; if(Parse.applicationId!==DATA.appId)throw Object.assign(Error('APP_MISMATCH'),{code:'CAPABILITY_UNAVAILABLE'}); const module=await import('parse-server/lib/Config.js');const Config=module.default?.default||module.default; const pg=Config.get(DATA.appId).database?.adapter?._client; if(typeof pg?.any!=='function')throw Object.assign(Error('METADATA_UNAVAILABLE'),{code:'CAPABILITY_UNAVAILABLE'}); const store=createPostgresStore(pg,DATA.tables,crypto); const app=createApplication({store,crypto,Parse,data:DATA,settings:{masterKey:Parse.masterKey,parseUrl:'https://kangshifu.fmode.cn/parse'},files:{}}); const p=request.body?.params??{}; const result=await readAuthorizedDataDictionary({app,pg,dictionary:DICTIONARY},request.headers,p); result.schemaFingerprint=crypto.createHash('sha256').update(JSON.stringify(result.tables)).digest('hex'); return response.json({result:{ok:true,status:'ok',requestId:p.requestId||crypto.randomUUID(),data:result,errors:[]}}); }catch(e){const status=e.code==='AUTH_REQUIRED'?401:e.code==='FORBIDDEN'?403:400; return response.status(status).json({result:{ok:false,error:{code:['AUTH_REQUIRED','FORBIDDEN','VALIDATION_FAILED','REFERENCE_NOT_FOUND','CAPABILITY_UNAVAILABLE'].includes(e.code)?e.code:'DICTIONARY_READ_FAILED'},readOnly:true,databaseWrites:0}}); } }`; const code=common+'\n'+entry;new Function(code); const out=path.join(root,'dist/data-dictionary');fs.mkdirSync(out,{recursive:true}); fs.writeFileSync(path.join(out,'ksfGetDataDictionary.js'),code); const manifest={release:'ksf.data-dictionary.20261106.v1',existingFunctionsModified:false,databaseWrites:0, functions:[{name:'ksfGetDataDictionary',path:'/ksfGetDataDictionary',file:'ksfGetDataDictionary.js',sha256:crypto.createHash('sha256').update(code).digest('hex')}]}; fs.writeFileSync(path.join(out,'manifest.json'),JSON.stringify(manifest,null,2)+'\n');console.log(JSON.stringify(manifest));