import ts from 'typescript'; import {readFileSync} from 'node:fs'; const gateway=readFileSync(new URL('./deploy-admin-functions.mjs',import.meta.url),'utf8').match(/const operationsGatewayCode = String.raw`([\s\S]*?)\n`;/)[1]; const sources=readFileSync(new URL('./cloud/lesson-records.js',import.meta.url),'utf8')+'\n'+gateway+'\n'+readFileSync(new URL('./cloud/payroll-integrity.js',import.meta.url),'utf8'); export const speedHelpers=['businessDate','payrollBusinessDate','queryUsers','coachRows','allAppointmentRows','appointmentRowsInRange','professionalScheduleData','professionalDashboardFast','scheduleTrendFast','learningReportQueryParts','vocabularyTree','vocabularyRows','specialRows','lessonHistoryBase','lessonHistoryPage','payrollOverviewData','payrollCanonicalSnapshot','professionalCoachRows','storeRows','usersPage']; function functions(code){const file=ts.createSourceFile('gateway.js',code,ts.ScriptTarget.Latest,true,ts.ScriptKind.JS);return new Map(file.statements.filter(ts.isFunctionDeclaration).map(node=>[node.name?.text,{start:node.getStart(file),end:node.end,text:node.getText(file)}]));} export function patchAdminSpeed(original){ const current=functions(original),next=functions(sources); const edits=speedHelpers.map(name=>{if(!current.has(name)||!next.has(name))throw Error('Missing helper '+name);return {...current.get(name),text:next.get(name).text};}).sort((a,b)=>b.start-a.start); let result=original;for(const edit of edits)result=result.slice(0,edit.start)+edit.text+result.slice(edit.end); for(const name of ['lessonHistoryLabelColumns','lessonHistoryLabelJoins']){if(current.has(name))throw Error('Unexpected existing helper '+name);result+='\n'+next.get(name).text;} new Function(result);return result; }