legacy-direct-bundle.mjs 2.1 KB

123456789101112131415161718192021222324
  1. import {readFileSync} from 'node:fs';
  2. import {specs} from './legacy-direct-specs.mjs';
  3. import {legacyAddonFields} from './legacy-direct-projection.mjs';
  4. import {withXiaoshuRuntime} from './xiaoshu-runtime-compat.mjs';
  5. import {legacyAppointmentDefaults,legacyWritingStageSupport} from '../legacy-appointment-transform.mjs';
  6. export function buildDirectBundle(columns,windows=[],company='7pIbDBJmKx') {
  7. const definitions=structuredClone(specs);
  8. for(const [m,s] of Object.entries(definitions)){
  9. s.fields=legacyAddonFields[m]||(m==='52'?['sy','yb','lj','yp']:['content','synopsis','mp4','ico','author','source']);
  10. s.addonColumns=columns.filter(c=>c.table_name===s.className).map(c=>c.column_name);
  11. s.commonColumns=columns.filter(c=>c.table_name==='CommonModel').map(c=>c.column_name);
  12. if(!s.addonColumns.includes('id')||!s.commonColumns.includes('generalId'))throw Error('Unexpected physical schema');
  13. }
  14. const userSource=readFileSync(new URL('../backfill-legacy-users.mjs',import.meta.url),'utf8');
  15. const userProjection=userSource.slice(userSource.indexOf('function text(value)'),userSource.indexOf('function requestGroups('));
  16. const prefix='const company={__type:"Pointer",className:"Company",objectId:'+JSON.stringify(company)+'};\n'+userProjection;
  17. const cloudSource=name=>readFileSync(new URL('../cloud/'+name+'.js',import.meta.url),'utf8');
  18. const operations=readFileSync(new URL('../deploy-admin-functions.mjs',import.meta.url),'utf8')
  19. .match(/const operationsGatewayCode = String.raw`([\s\S]*?)\n`;/)?.[1];
  20. if(!operations)throw Error('Unexpected operations gateway definition');
  21. const writingSupport=legacyAppointmentDefaults(operations)+legacyWritingStageSupport(cloudSource('payroll-integrity'));
  22. const files=['legacy-finance','legacy-direct-supplement','legacy-direct-control','legacy-writing-sync-ownership','legacy-writing-sync','legacy-direct-sync'];
  23. return withXiaoshuRuntime((prefix+writingSupport+files.map(cloudSource).join('\n')).replaceAll('__SPECS__',JSON.stringify(definitions)).replaceAll('__WINDOWS__',JSON.stringify(windows)).replaceAll('__COMPANY_ID__',JSON.stringify(company)));
  24. }