@carbonbox/domain 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/build/carbonbox/emission-calculation-process/calculation-processes/domain/entity/CalculationProcess.js +11 -0
  2. package/build/carbonbox/shared/either/domain/contracts/IEither.js +2 -0
  3. package/build/carbonbox/shared/either/domain/contracts/IFunctor.js +2 -0
  4. package/build/carbonbox/shared/either/domain/contracts/ILeftEither.js +2 -0
  5. package/build/carbonbox/shared/either/domain/contracts/IMonad.js +2 -0
  6. package/build/carbonbox/shared/either/domain/contracts/IRightEither.js +2 -0
  7. package/build/carbonbox/shared/either/domain/exceptions/FilterOperationNotImplementedError.js +17 -0
  8. package/build/carbonbox/shared/either/domain/exceptions/SwapOperationNotImplementedError.js +17 -0
  9. package/build/carbonbox/shared/either/domain/factories/EitherFactory.js +88 -0
  10. package/build/carbonbox/shared/either/domain/factories/ResultFactory.js +123 -0
  11. package/build/carbonbox/shared/either/domain/implementations/LeftEitherImpl.js +92 -0
  12. package/build/carbonbox/shared/either/domain/implementations/RightEitherImpl.js +97 -0
  13. package/build/carbonbox/shared/either/domain/implementations/RightEitherImplNew.js +97 -0
  14. package/build/carbonbox/shared/either/domain/implementations/RightEitherImplOld.js +89 -0
  15. package/build/carbonbox/shared/either/domain/types/Result.js +4 -4
  16. package/build/carbonbox/shared/either/domain/utils/EitherUtils.js +91 -0
  17. package/build/carbonbox/shared/either/index.js +81 -0
  18. package/build/main/index.js +15 -12
  19. package/build/types/carbonbox/shared/either/domain/contracts/Functor.d.ts +2 -2
  20. package/build/types/carbonbox/shared/either/domain/contracts/Functor.d.ts.map +1 -1
  21. package/build/types/carbonbox/shared/either/domain/contracts/IEither.d.ts +45 -0
  22. package/build/types/carbonbox/shared/either/domain/contracts/IEither.d.ts.map +1 -0
  23. package/build/types/carbonbox/shared/either/domain/contracts/IFunctor.d.ts +4 -0
  24. package/build/types/carbonbox/shared/either/domain/contracts/IFunctor.d.ts.map +1 -0
  25. package/build/types/carbonbox/shared/either/domain/contracts/ILeftEither.d.ts +22 -0
  26. package/build/types/carbonbox/shared/either/domain/contracts/ILeftEither.d.ts.map +1 -0
  27. package/build/types/carbonbox/shared/either/domain/contracts/IMonad.d.ts +5 -0
  28. package/build/types/carbonbox/shared/either/domain/contracts/IMonad.d.ts.map +1 -0
  29. package/build/types/carbonbox/shared/either/domain/contracts/IRightEither.d.ts +22 -0
  30. package/build/types/carbonbox/shared/either/domain/contracts/IRightEither.d.ts.map +1 -0
  31. package/build/types/carbonbox/shared/either/domain/contracts/Monad.d.ts +10 -3
  32. package/build/types/carbonbox/shared/either/domain/contracts/Monad.d.ts.map +1 -1
  33. package/build/types/carbonbox/shared/either/domain/exceptions/FilterOperationNotImplementedError.d.ts +7 -0
  34. package/build/types/carbonbox/shared/either/domain/exceptions/FilterOperationNotImplementedError.d.ts.map +1 -0
  35. package/build/types/carbonbox/shared/either/domain/exceptions/SwapOperationNotImplementedError.d.ts +7 -0
  36. package/build/types/carbonbox/shared/either/domain/exceptions/SwapOperationNotImplementedError.d.ts.map +1 -0
  37. package/build/types/carbonbox/shared/either/domain/factories/EitherFactory.d.ts +36 -0
  38. package/build/types/carbonbox/shared/either/domain/factories/EitherFactory.d.ts.map +1 -0
  39. package/build/types/carbonbox/shared/either/domain/factories/ResultFactory.d.ts +44 -0
  40. package/build/types/carbonbox/shared/either/domain/factories/ResultFactory.d.ts.map +1 -0
  41. package/build/types/carbonbox/shared/either/domain/implementations/LeftEitherImpl.d.ts +29 -0
  42. package/build/types/carbonbox/shared/either/domain/implementations/LeftEitherImpl.d.ts.map +1 -0
  43. package/build/types/carbonbox/shared/either/domain/implementations/RightEitherImpl.d.ts +29 -0
  44. package/build/types/carbonbox/shared/either/domain/implementations/RightEitherImpl.d.ts.map +1 -0
  45. package/build/types/carbonbox/shared/either/domain/implementations/RightEitherImplNew.d.ts +29 -0
  46. package/build/types/carbonbox/shared/either/domain/implementations/RightEitherImplNew.d.ts.map +1 -0
  47. package/build/types/carbonbox/shared/either/domain/implementations/RightEitherImplOld.d.ts +29 -0
  48. package/build/types/carbonbox/shared/either/domain/implementations/RightEitherImplOld.d.ts.map +1 -0
  49. package/build/types/carbonbox/shared/either/domain/models/Either.d.ts.map +1 -1
  50. package/build/types/carbonbox/shared/either/domain/types/Result.d.ts +4 -4
  51. package/build/types/carbonbox/shared/either/domain/types/Result.d.ts.map +1 -1
  52. package/build/types/carbonbox/shared/either/domain/utils/EitherUtils.d.ts +31 -1
  53. package/build/types/carbonbox/shared/either/domain/utils/EitherUtils.d.ts.map +1 -1
  54. package/build/types/carbonbox/shared/either/index.d.ts +57 -0
  55. package/build/types/carbonbox/shared/either/index.d.ts.map +1 -0
  56. package/build/types/main/index.d.ts +7 -10
  57. package/build/types/main/index.d.ts.map +1 -1
  58. package/package.json +1 -1
@@ -218,3 +218,14 @@ exports.CalculationProcess = CalculationProcess;
218
218
  _CalculationProcess_carbonClient = new WeakMap(), _CalculationProcess_footprintConfiguration = new WeakMap(), _CalculationProcess_scheduledAt = new WeakMap(), _CalculationProcess_estimatedDuration = new WeakMap(), _CalculationProcess_priority = new WeakMap(), _CalculationProcess_dependencies = new WeakMap(), _CalculationProcess_executedByStakeholder = new WeakMap(), _CalculationProcess_startedAt = new WeakMap(), _CalculationProcess_completedAt = new WeakMap(), _CalculationProcess_actualDuration = new WeakMap(), _CalculationProcess_status = new WeakMap(), _CalculationProcess_errorMessage = new WeakMap(), _CalculationProcess_progressPercentage = new WeakMap(), _CalculationProcess_submissionsToProcess = new WeakMap(), _CalculationProcess_calculationsGenerated = new WeakMap(), _CalculationProcess_totalEmissionsCalculated = new WeakMap(), _CalculationProcess_processNotes = new WeakMap(), _CalculationProcess_retryCount = new WeakMap(), _CalculationProcess_maxRetries = new WeakMap();
219
219
  // TODO: Validar que todo lo que herede de String, Boolean, Numeric, PositiveInteger, DateTimeString
220
220
  // AggregateId, AggregateIdList, Code, CodeList, tenga guardas en el create
221
+ // TODO: Auditar proyecto con
222
+ /*
223
+ Auditar y corregir negaciones implícitas (!)
224
+ Convertir métodos privados a sintaxis # en módulo
225
+ Todo método público , ya sea estático o no debe de tener la palabra clave public
226
+ Eliminar todos los 'any' y mejorar tipado en módulo
227
+ Implementar null safety apropiado en módulo
228
+ Verificar tipado fuerte y corregir type assertions
229
+
230
+ Tampoco usamos new Error, creamos las expetions específicas para el caso y ser lanzadas, por favor valida lo que has planteado y corríge según sea necesario
231
+ */
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FilterOperationNotImplementedError = void 0;
4
+ const RootError_1 = require("../../../domain/exceptions/RootError");
5
+ class FilterOperationNotImplementedError extends RootError_1.RootError {
6
+ constructor(message) {
7
+ super(message);
8
+ this.name = 'FilterOperationNotImplementedError';
9
+ }
10
+ static create(context) {
11
+ return new FilterOperationNotImplementedError(`Filter operation must be implemented via EitherUtils${context ? ` in ${context}` : ''}`);
12
+ }
13
+ logError() {
14
+ return `${this.name}: ${this.message}`;
15
+ }
16
+ }
17
+ exports.FilterOperationNotImplementedError = FilterOperationNotImplementedError;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SwapOperationNotImplementedError = void 0;
4
+ const RootError_1 = require("../../../domain/exceptions/RootError");
5
+ class SwapOperationNotImplementedError extends RootError_1.RootError {
6
+ constructor(message) {
7
+ super(message);
8
+ this.name = 'SwapOperationNotImplementedError';
9
+ }
10
+ static create(context) {
11
+ return new SwapOperationNotImplementedError(`Swap operation must be implemented via EitherUtils${context ? ` in ${context}` : ''}`);
12
+ }
13
+ logError() {
14
+ return `${this.name}: ${this.message}`;
15
+ }
16
+ }
17
+ exports.SwapOperationNotImplementedError = SwapOperationNotImplementedError;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EitherFactory = void 0;
4
+ const LeftEitherImpl_1 = require("../implementations/LeftEitherImpl");
5
+ const RightEitherImpl_1 = require("../implementations/RightEitherImpl");
6
+ const EitherUtils_1 = require("../utils/EitherUtils");
7
+ /**
8
+ * Factory para crear instancias de Either
9
+ * Resuelve las dependencias circulares al separar la creación de la implementación
10
+ */
11
+ class EitherFactory {
12
+ // ─── Factory Methods ─────────────────────────────────────────────────────────
13
+ /** Crea un Either Left que contiene un valor de error */
14
+ static left(value) {
15
+ return new LeftEitherImpl_1.LeftEitherImpl(value);
16
+ }
17
+ /** Crea un Either Right que contiene un valor de éxito */
18
+ static right(value) {
19
+ return new RightEitherImpl_1.RightEitherImpl(value);
20
+ }
21
+ // ─── Factory Methods para manejo de errores ─────────────────────────────────
22
+ /** Factory method para manejo seguro de operaciones que pueden fallar */
23
+ static fromTryCatch(operation, errorMapper) {
24
+ try {
25
+ return EitherFactory.right(operation());
26
+ }
27
+ catch (error) {
28
+ return EitherFactory.left(errorMapper(error));
29
+ }
30
+ }
31
+ /** Factory method para promesas */
32
+ static async fromPromise(promise, errorMapper) {
33
+ try {
34
+ const result = await promise;
35
+ return EitherFactory.right(result);
36
+ }
37
+ catch (error) {
38
+ return EitherFactory.left(errorMapper(error));
39
+ }
40
+ }
41
+ /** Factory method para valores que pueden ser null o undefined */
42
+ static fromNullable(value, errorFactory) {
43
+ return value !== null && value !== undefined
44
+ ? EitherFactory.right(value)
45
+ : EitherFactory.left(errorFactory());
46
+ }
47
+ /** Factory method para operaciones condicionales */
48
+ static fromCondition(condition, rightValue, leftValue) {
49
+ return condition === true
50
+ ? EitherFactory.right(rightValue())
51
+ : EitherFactory.left(leftValue());
52
+ }
53
+ // ─── Factory Methods para colecciones ───────────────────────────────────────
54
+ /** Combina múltiples Either en uno solo - falla en el primer Left */
55
+ static sequence(eithers) {
56
+ return EitherUtils_1.EitherUtils.sequence(eithers);
57
+ }
58
+ /** Aplica una función que puede fallar a cada elemento */
59
+ static traverse(items, fn) {
60
+ return EitherUtils_1.EitherUtils.traverse(items, fn);
61
+ }
62
+ /** Combina dos Either con una función */
63
+ static lift2(fn, eitherA, eitherB) {
64
+ return EitherUtils_1.EitherUtils.lift2(fn, eitherA, eitherB);
65
+ }
66
+ /** Combina tres Either con una función */
67
+ static lift3(fn, eitherA, eitherB, eitherC) {
68
+ return EitherUtils_1.EitherUtils.lift3(fn, eitherA, eitherB, eitherC);
69
+ }
70
+ /** Acumula errores en lugar de fallar en el primero */
71
+ static accumulate(eithers) {
72
+ return EitherUtils_1.EitherUtils.accumulate(eithers);
73
+ }
74
+ /** Ejecuta Either en paralelo y acumula todos los errores */
75
+ static async parallel(operations) {
76
+ return EitherUtils_1.EitherUtils.parallel(operations);
77
+ }
78
+ // ─── Factory Methods para transformaciones complejas ────────────────────────
79
+ /** Aplica una transformación solo si se cumple una condición */
80
+ static when(condition, transform) {
81
+ return EitherUtils_1.EitherUtils.when(condition, transform);
82
+ }
83
+ /** Aplica una transformación solo si NO se cumple una condición */
84
+ static unless(condition, transform) {
85
+ return EitherUtils_1.EitherUtils.unless(condition, transform);
86
+ }
87
+ }
88
+ exports.EitherFactory = EitherFactory;
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ResultFactory = void 0;
4
+ const EitherFactory_1 = require("./EitherFactory");
5
+ /**
6
+ * Factory especializado para crear Result (Either con DomainFailure)
7
+ * Proporciona métodos específicos para el manejo de errores de dominio
8
+ */
9
+ class ResultFactory {
10
+ // ─── Factory Methods básicos ─────────────────────────────────────────────────
11
+ /** Crea un Result de fallo con un solo error */
12
+ static fail(error) {
13
+ return EitherFactory_1.EitherFactory.left({ type: 'single', error });
14
+ }
15
+ /** Crea un Result de fallo con múltiples errores */
16
+ static failMultiple(errors) {
17
+ return EitherFactory_1.EitherFactory.left({ type: 'multiple', errors });
18
+ }
19
+ /** Crea un Result de éxito */
20
+ static ok(value) {
21
+ return EitherFactory_1.EitherFactory.right(value);
22
+ }
23
+ // ─── Factory Methods para conversiones ───────────────────────────────────────
24
+ /** Convierte un Either simple a Result */
25
+ static fromEither(either) {
26
+ return either.mapLeft((error) => ({ type: 'single', error }));
27
+ }
28
+ /** Convierte un Either con múltiples errores a Result */
29
+ static fromEitherMultiple(either) {
30
+ return either.mapLeft((errors) => ({ type: 'multiple', errors }));
31
+ }
32
+ /** Convierte un valor nullable a Result */
33
+ static fromNullable(value, errorFactory) {
34
+ return value !== null && value !== undefined
35
+ ? ResultFactory.ok(value)
36
+ : ResultFactory.fail(errorFactory());
37
+ }
38
+ /** Convierte una condición a Result */
39
+ static fromCondition(condition, valueFactory, errorFactory) {
40
+ return condition === true
41
+ ? ResultFactory.ok(valueFactory())
42
+ : ResultFactory.fail(errorFactory());
43
+ }
44
+ // ─── Factory Methods para operaciones complejas ─────────────────────────────
45
+ /** Ejecuta una operación que puede fallar */
46
+ static fromTryCatch(operation, errorMapper) {
47
+ return EitherFactory_1.EitherFactory.fromTryCatch(operation, errorMapper).mapLeft((error) => ({ type: 'single', error }));
48
+ }
49
+ /** Ejecuta una promesa que puede fallar */
50
+ static async fromPromise(promise, errorMapper) {
51
+ const result = await EitherFactory_1.EitherFactory.fromPromise(promise, errorMapper);
52
+ return result.mapLeft((error) => ({ type: 'single', error }));
53
+ }
54
+ // ─── Factory Methods para colecciones ───────────────────────────────────────
55
+ /** Combina múltiples Result en uno solo - falla en el primer error */
56
+ static sequence(results) {
57
+ return EitherFactory_1.EitherFactory.sequence(results);
58
+ }
59
+ /** Aplica una función que puede fallar a cada elemento */
60
+ static traverse(items, fn) {
61
+ return EitherFactory_1.EitherFactory.traverse(items, fn);
62
+ }
63
+ /** Acumula todos los errores en lugar de fallar en el primero */
64
+ static accumulate(results) {
65
+ const lefts = [];
66
+ const rights = [];
67
+ for (const result of results) {
68
+ result.fold((failure) => lefts.push(failure), (value) => rights.push(value));
69
+ }
70
+ if (lefts.length === 0) {
71
+ return ResultFactory.ok(rights);
72
+ }
73
+ // Combinar todos los errores
74
+ const allErrors = [];
75
+ for (const failure of lefts) {
76
+ if (failure.type === 'single') {
77
+ allErrors.push(failure.error);
78
+ }
79
+ else {
80
+ allErrors.push(...failure.errors);
81
+ }
82
+ }
83
+ return ResultFactory.failMultiple(allErrors);
84
+ }
85
+ /** Ejecuta validaciones en paralelo */
86
+ static async parallel(operations) {
87
+ const results = await Promise.all(operations.map((op) => op()));
88
+ return ResultFactory.accumulate(results);
89
+ }
90
+ // ─── Factory Methods para validaciones ──────────────────────────────────────
91
+ /** Crea una cadena de validaciones */
92
+ static chain(...validations) {
93
+ return (value) => {
94
+ let result = ResultFactory.ok(value);
95
+ for (const validation of validations) {
96
+ result = result.flatMap(validation);
97
+ if (result.isLeft === true) {
98
+ break;
99
+ }
100
+ }
101
+ return result;
102
+ };
103
+ }
104
+ /** Aplica múltiples validaciones y acumula errores */
105
+ static validate(value, ...validations) {
106
+ const results = validations.map((validation) => validation(value));
107
+ return ResultFactory.accumulate(results).map(() => value);
108
+ }
109
+ /** Crea un validador condicional */
110
+ static when(condition, validation) {
111
+ return (value) => {
112
+ if (condition(value) === true) {
113
+ return validation(value);
114
+ }
115
+ return ResultFactory.ok(value);
116
+ };
117
+ }
118
+ /** Crea un validador que se ejecuta solo si NO se cumple la condición */
119
+ static unless(condition, validation) {
120
+ return ResultFactory.when((value) => condition(value) !== true, validation);
121
+ }
122
+ }
123
+ exports.ResultFactory = ResultFactory;
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _LeftEitherImpl_value;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.LeftEitherImpl = void 0;
16
+ const CannotAccessRightOnLeftValueError_1 = require("../exceptions/CannotAccessRightOnLeftValueError");
17
+ const SwapOperationNotImplementedError_1 = require("../exceptions/SwapOperationNotImplementedError");
18
+ /**
19
+ * Implementación concreta de LeftEither
20
+ * Representa el estado de fallo en el patrón Either
21
+ */
22
+ class LeftEitherImpl {
23
+ constructor(value) {
24
+ this.state = 'left';
25
+ _LeftEitherImpl_value.set(this, void 0);
26
+ __classPrivateFieldSet(this, _LeftEitherImpl_value, value, "f");
27
+ }
28
+ // ─── Predicados tipo-seguros ─────────────────────────────────────────────────
29
+ get isLeft() {
30
+ return true;
31
+ }
32
+ get isRight() {
33
+ return false;
34
+ }
35
+ // ─── Métodos de acceso seguros ───────────────────────────────────────────────
36
+ getLeft() {
37
+ return __classPrivateFieldGet(this, _LeftEitherImpl_value, "f");
38
+ }
39
+ getRight() {
40
+ return undefined;
41
+ }
42
+ // ─── Métodos de acceso que lanzan excepción ──────────────────────────────────
43
+ left() {
44
+ return __classPrivateFieldGet(this, _LeftEitherImpl_value, "f");
45
+ }
46
+ right() {
47
+ throw CannotAccessRightOnLeftValueError_1.CannotAccessRightOnLeftValueError.create(__classPrivateFieldGet(this, _LeftEitherImpl_value, "f"));
48
+ }
49
+ // ─── Transformaciones funcionales ────────────────────────────────────────────
50
+ map() {
51
+ // No se ejecuta la transformación en Left, solo cambia el tipo
52
+ return new LeftEitherImpl(__classPrivateFieldGet(this, _LeftEitherImpl_value, "f"));
53
+ }
54
+ mapLeft(fn) {
55
+ // Aplica la transformación al valor Left
56
+ return new LeftEitherImpl(fn(__classPrivateFieldGet(this, _LeftEitherImpl_value, "f")));
57
+ }
58
+ flatMap() {
59
+ // No se ejecuta la transformación en Left, solo cambia el tipo
60
+ return new LeftEitherImpl(__classPrivateFieldGet(this, _LeftEitherImpl_value, "f"));
61
+ }
62
+ // ─── Métodos de utilidad ─────────────────────────────────────────────────────
63
+ fold(onLeft) {
64
+ return onLeft(__classPrivateFieldGet(this, _LeftEitherImpl_value, "f"));
65
+ }
66
+ getOrElse(fallback) {
67
+ return typeof fallback === 'function' ? fallback() : fallback;
68
+ }
69
+ // ─── Validaciones y filtros ──────────────────────────────────────────────────
70
+ filter() {
71
+ // No se aplica filtro en Left
72
+ return this;
73
+ }
74
+ chain() {
75
+ // Alias para flatMap
76
+ return this.flatMap();
77
+ }
78
+ // ─── Conversiones ────────────────────────────────────────────────────────────
79
+ toOptional() {
80
+ return undefined;
81
+ }
82
+ swap() {
83
+ // Implementación delegada al factory para evitar dependencia circular
84
+ throw SwapOperationNotImplementedError_1.SwapOperationNotImplementedError.create('LeftEitherImpl');
85
+ }
86
+ // ─── Debugging ───────────────────────────────────────────────────────────────
87
+ inspect() {
88
+ return `Left(${JSON.stringify(__classPrivateFieldGet(this, _LeftEitherImpl_value, "f"))})`;
89
+ }
90
+ }
91
+ exports.LeftEitherImpl = LeftEitherImpl;
92
+ _LeftEitherImpl_value = new WeakMap();
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _RightEitherImpl_value;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.RightEitherImpl = void 0;
16
+ const CannotAccessLeftOnRightValueError_1 = require("../exceptions/CannotAccessLeftOnRightValueError");
17
+ const SwapOperationNotImplementedError_1 = require("../exceptions/SwapOperationNotImplementedError");
18
+ const FilterOperationNotImplementedError_1 = require("../exceptions/FilterOperationNotImplementedError");
19
+ /**
20
+ * Implementación concreta de RightEither
21
+ * Representa el estado de éxito en el patrón Either
22
+ */
23
+ class RightEitherImpl {
24
+ constructor(value) {
25
+ this.state = 'right';
26
+ _RightEitherImpl_value.set(this, void 0);
27
+ __classPrivateFieldSet(this, _RightEitherImpl_value, value, "f");
28
+ }
29
+ // ─── Predicados tipo-seguros ─────────────────────────────────────────────────
30
+ get isLeft() {
31
+ return false;
32
+ }
33
+ get isRight() {
34
+ return true;
35
+ }
36
+ // ─── Métodos de acceso seguros ───────────────────────────────────────────────
37
+ getLeft() {
38
+ return undefined;
39
+ }
40
+ getRight() {
41
+ return __classPrivateFieldGet(this, _RightEitherImpl_value, "f");
42
+ }
43
+ // ─── Métodos de acceso que lanzan excepción ──────────────────────────────────
44
+ left() {
45
+ throw CannotAccessLeftOnRightValueError_1.CannotAccessLeftOnRightValueError.create(__classPrivateFieldGet(this, _RightEitherImpl_value, "f"));
46
+ }
47
+ right() {
48
+ return __classPrivateFieldGet(this, _RightEitherImpl_value, "f");
49
+ }
50
+ // ─── Transformaciones funcionales ────────────────────────────────────────────
51
+ map(fn) {
52
+ // Aplica la transformación al valor Right
53
+ return new RightEitherImpl(fn(__classPrivateFieldGet(this, _RightEitherImpl_value, "f")));
54
+ }
55
+ mapLeft() {
56
+ // No se ejecuta la transformación en Right, solo cambia el tipo
57
+ return new RightEitherImpl(__classPrivateFieldGet(this, _RightEitherImpl_value, "f"));
58
+ }
59
+ flatMap(fn) {
60
+ // Ejecuta la transformación monádica
61
+ return fn(__classPrivateFieldGet(this, _RightEitherImpl_value, "f"));
62
+ }
63
+ // ─── Métodos de utilidad ─────────────────────────────────────────────────────
64
+ fold(_onLeft, onRight) {
65
+ return onRight(__classPrivateFieldGet(this, _RightEitherImpl_value, "f"));
66
+ }
67
+ getOrElse() {
68
+ // Retorna el valor Right directamente
69
+ return __classPrivateFieldGet(this, _RightEitherImpl_value, "f");
70
+ }
71
+ // ─── Validaciones y filtros ──────────────────────────────────────────────────
72
+ filter(predicate) {
73
+ // Implementación delegada al factory para evitar dependencia circular
74
+ if (predicate(__classPrivateFieldGet(this, _RightEitherImpl_value, "f")) === true) {
75
+ return this;
76
+ }
77
+ throw FilterOperationNotImplementedError_1.FilterOperationNotImplementedError.create('RightEitherImpl');
78
+ }
79
+ chain(fn) {
80
+ // Alias para flatMap
81
+ return this.flatMap(fn);
82
+ }
83
+ // ─── Conversiones ────────────────────────────────────────────────────────────
84
+ toOptional() {
85
+ return __classPrivateFieldGet(this, _RightEitherImpl_value, "f");
86
+ }
87
+ swap() {
88
+ // Implementación delegada al factory para evitar dependencia circular
89
+ throw SwapOperationNotImplementedError_1.SwapOperationNotImplementedError.create('RightEitherImpl');
90
+ }
91
+ // ─── Debugging ───────────────────────────────────────────────────────────────
92
+ inspect() {
93
+ return `Right(${JSON.stringify(__classPrivateFieldGet(this, _RightEitherImpl_value, "f"))})`;
94
+ }
95
+ }
96
+ exports.RightEitherImpl = RightEitherImpl;
97
+ _RightEitherImpl_value = new WeakMap();
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _RightEitherImpl_value;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.RightEitherImpl = void 0;
16
+ const CannotAccessLeftOnRightValueError_1 = require("../exceptions/CannotAccessLeftOnRightValueError");
17
+ const SwapOperationNotImplementedError_1 = require("../exceptions/SwapOperationNotImplementedError");
18
+ const FilterOperationNotImplementedError_1 = require("../exceptions/FilterOperationNotImplementedError");
19
+ /**
20
+ * Implementación concreta de RightEither
21
+ * Representa el estado de éxito en el patrón Either
22
+ */
23
+ class RightEitherImpl {
24
+ constructor(value) {
25
+ this.state = 'right';
26
+ _RightEitherImpl_value.set(this, void 0);
27
+ __classPrivateFieldSet(this, _RightEitherImpl_value, value, "f");
28
+ }
29
+ // ─── Predicados tipo-seguros ─────────────────────────────────────────────────
30
+ get isLeft() {
31
+ return false;
32
+ }
33
+ get isRight() {
34
+ return true;
35
+ }
36
+ // ─── Métodos de acceso seguros ───────────────────────────────────────────────
37
+ getLeft() {
38
+ return undefined;
39
+ }
40
+ getRight() {
41
+ return __classPrivateFieldGet(this, _RightEitherImpl_value, "f");
42
+ }
43
+ // ─── Métodos de acceso que lanzan excepción ──────────────────────────────────
44
+ left() {
45
+ throw CannotAccessLeftOnRightValueError_1.CannotAccessLeftOnRightValueError.create(__classPrivateFieldGet(this, _RightEitherImpl_value, "f"));
46
+ }
47
+ right() {
48
+ return __classPrivateFieldGet(this, _RightEitherImpl_value, "f");
49
+ }
50
+ // ─── Transformaciones funcionales ────────────────────────────────────────────
51
+ map(fn) {
52
+ // Aplica la transformación al valor Right
53
+ return new RightEitherImpl(fn(__classPrivateFieldGet(this, _RightEitherImpl_value, "f")));
54
+ }
55
+ mapLeft() {
56
+ // No se ejecuta la transformación en Right, solo cambia el tipo
57
+ return new RightEitherImpl(__classPrivateFieldGet(this, _RightEitherImpl_value, "f"));
58
+ }
59
+ flatMap(fn) {
60
+ // Ejecuta la transformación monádica
61
+ return fn(__classPrivateFieldGet(this, _RightEitherImpl_value, "f"));
62
+ }
63
+ // ─── Métodos de utilidad ─────────────────────────────────────────────────────
64
+ fold(_onLeft, onRight) {
65
+ return onRight(__classPrivateFieldGet(this, _RightEitherImpl_value, "f"));
66
+ }
67
+ getOrElse() {
68
+ // Retorna el valor Right directamente
69
+ return __classPrivateFieldGet(this, _RightEitherImpl_value, "f");
70
+ }
71
+ // ─── Validaciones y filtros ──────────────────────────────────────────────────
72
+ filter(predicate) {
73
+ // Implementación delegada al factory para evitar dependencia circular
74
+ if (predicate(__classPrivateFieldGet(this, _RightEitherImpl_value, "f")) === true) {
75
+ return this;
76
+ }
77
+ throw FilterOperationNotImplementedError_1.FilterOperationNotImplementedError.create('RightEitherImpl');
78
+ }
79
+ chain(fn) {
80
+ // Alias para flatMap
81
+ return this.flatMap(fn);
82
+ }
83
+ // ─── Conversiones ────────────────────────────────────────────────────────────
84
+ toOptional() {
85
+ return __classPrivateFieldGet(this, _RightEitherImpl_value, "f");
86
+ }
87
+ swap() {
88
+ // Implementación delegada al factory para evitar dependencia circular
89
+ throw SwapOperationNotImplementedError_1.SwapOperationNotImplementedError.create('RightEitherImpl');
90
+ }
91
+ // ─── Debugging ───────────────────────────────────────────────────────────────
92
+ inspect() {
93
+ return `Right(${JSON.stringify(__classPrivateFieldGet(this, _RightEitherImpl_value, "f"))})`;
94
+ }
95
+ }
96
+ exports.RightEitherImpl = RightEitherImpl;
97
+ _RightEitherImpl_value = new WeakMap();