codigo0/node_modules/happy-dom/lib/browser/BrowserSettingsFactory.js
planetazuzu 5d7a6500fe refactor: Fase 1 - Clean Architecture, refactorización modular y eliminación de duplicidades
-  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
2026-01-25 21:09:47 +01:00

88 lines
3.2 KiB
JavaScript

import DefaultBrowserSettings from './DefaultBrowserSettings.js';
/**
* Browser settings utility.
*/
export default class BrowserSettingsFactory {
/**
* Returns browser settings.
*
* @param [settings] Browser settings.
* @returns Settings.
*/
static createSettings(settings) {
if (settings) {
this.validate(DefaultBrowserSettings, settings);
}
return {
...DefaultBrowserSettings,
...settings,
navigation: {
...DefaultBrowserSettings.navigation,
...settings?.navigation
},
navigator: {
...DefaultBrowserSettings.navigator,
...settings?.navigator
},
timer: {
...DefaultBrowserSettings.timer,
...settings?.timer
},
fetch: {
...DefaultBrowserSettings.fetch,
...settings?.fetch
},
module: {
...DefaultBrowserSettings.module,
...settings?.module
},
device: {
...DefaultBrowserSettings.device,
...settings?.device
},
debug: {
...DefaultBrowserSettings.debug,
...settings?.debug
},
viewport: {
...DefaultBrowserSettings.viewport,
...settings?.viewport
}
};
}
/**
* Validates settings.
*
* @param target Target.
* @param source Source.
* @param [parentNamespace] Parent namespace.
*/
static validate(target, source, parentNamespace) {
for (const key of Object.keys(source)) {
if (target[key] === undefined) {
const namespace = parentNamespace ? parentNamespace + '.' + key : key;
throw new Error(`Unknown browser setting "${namespace}"`);
}
if (typeof target[key] === 'object' && !Array.isArray(target[key]) && target[key] !== null) {
const namespace = parentNamespace ? parentNamespace + '.' + key : key;
if (typeof source[key] !== 'object' || Array.isArray(source[key]) || source[key] === null) {
throw new Error(`Browser setting "${namespace}" cannot be null`);
}
this.validate(target[key], source[key], namespace);
}
else {
if ((typeof target[key] === 'boolean' ||
typeof target[key] === 'number' ||
typeof target[key] === 'string') &&
typeof source[key] !== typeof target[key]) {
const isValidPreventTimerLoops = key === 'preventTimerLoops' && typeof source[key] === 'object' && source[key] !== null;
if (!isValidPreventTimerLoops) {
const namespace = parentNamespace ? parentNamespace + '.' + key : key;
throw new Error(`Browser setting "${namespace}" must be of type "${typeof target[key]}"`);
}
}
}
}
}
}
//# sourceMappingURL=BrowserSettingsFactory.js.map