import {readFileSync} from 'node:fs'; export const optimizedReadHelpers=['memberAppointmentStats','courseTeachingRows','professionalScheduleData','queryUsers','ensureVocabularyPhysicalSchema','professionalDashboardFast','payrollCanonicalSnapshot','payrollPreviewData']; // Preserve the actual deployed gateway, including unrelated fixes added after this work started. export function patchAdminReadHelpers(baseline){ const source=readFileSync(new URL('./deploy-admin-functions.mjs',import.meta.url),'utf8').match(/const operationsGatewayCode = String.raw`([\s\S]*?)\n`;/)[1]+'\n'+readFileSync(new URL('./cloud/payroll-integrity.js',import.meta.url),'utf8'); for(const name of optimizedReadHelpers){ const pattern=new RegExp('async function '+name+'\\([^]*?(?=\\n(?:async )?function |\\nconst [A-Z_])'); const replacement=[...source.matchAll(new RegExp(pattern.source,'g'))].at(-1)?.[0],match=[...baseline.matchAll(new RegExp(pattern.source,'g'))].at(-1);if(!replacement||!match)throw Error('Missing read helper '+name); baseline=baseline.slice(0,match.index)+replacement+baseline.slice(match.index+match[0].length); } new Function(baseline);return baseline; }