- ✅ Ticket 1.1: Estructura Clean Architecture en backend - ✅ Ticket 1.2: Schemas Zod compartidos - ✅ Ticket 1.3: Refactorización drugs.ts (1362 → 8 archivos modulares) - ✅ Ticket 1.4: Refactorización procedures.ts (3583 → 6 archivos modulares) - ✅ Ticket 1.5: Eliminación de duplicidades (~50 líneas) Cambios principales: - Creada estructura Clean Architecture en backend/src/ - Schemas Zod compartidos en backend/src/shared/schemas/ - Refactorización modular de drugs y procedures - Utilidades genéricas en src/utils/ (filter, validation) - Eliminados scripts obsoletos y documentación antigua - Corregidos errores: QueryClient, import test-error-handling - Build verificado y funcionando correctamente
60 lines
2.2 KiB
JavaScript
60 lines
2.2 KiB
JavaScript
import CSSModule from '../../module/CSSModule.js';
|
|
import ECMAScriptModule from '../../module/ECMAScriptModule.js';
|
|
import JSONModule from '../../module/JSONModule.js';
|
|
import ModuleFactory from '../../module/ModuleFactory.js';
|
|
import { Script } from 'vm';
|
|
/**
|
|
* Browser frame script evaluator.
|
|
*/
|
|
export default class BrowserFrameScriptEvaluator {
|
|
/**
|
|
* Evaluates code or a VM Script in the frame's context.
|
|
*
|
|
* @param frame Frame.
|
|
* @param script Script.
|
|
* @returns Result.
|
|
*/
|
|
static evaluate(frame, script) {
|
|
if (!frame.window) {
|
|
throw new Error('The frame has been destroyed, the "window" property is not set.');
|
|
}
|
|
script = typeof script === 'string' ? new Script(script) : script;
|
|
return script.runInContext(frame.window);
|
|
}
|
|
/**
|
|
* Evaluates a module in the frame's context.
|
|
*
|
|
* @param frame Frame.
|
|
* @param options Options.
|
|
* @param options.url URL.
|
|
* @param options.type Module type.
|
|
* @param options.code Code.
|
|
* @returns Exports.
|
|
*/
|
|
static async evaluateModule(frame, options) {
|
|
if (!frame.window) {
|
|
throw new Error('The frame has been destroyed, the "window" property is not set.');
|
|
}
|
|
const window = frame.window;
|
|
if (options?.code) {
|
|
const url = options.url ? new URL(options.url, window.location.href) : window.location;
|
|
const source = options.code;
|
|
switch (options?.type || 'esm') {
|
|
case 'esm':
|
|
return await new ECMAScriptModule({ window, url, source }).evaluate();
|
|
case 'json':
|
|
return await new JSONModule({ window, url, source }).evaluate();
|
|
case 'css':
|
|
return await new CSSModule({ window, url, source }).evaluate();
|
|
}
|
|
}
|
|
if (options?.url) {
|
|
const module = await new ModuleFactory(window, window.location).getModule(options.url, {
|
|
with: { type: options.type || 'esm' }
|
|
});
|
|
return await module.evaluate();
|
|
}
|
|
return {};
|
|
}
|
|
}
|
|
//# sourceMappingURL=BrowserFrameScriptEvaluator.js.map
|