@cosmneo/onion-lasagna 0.1.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.
- package/dist/backend/core/global.cjs +283 -0
- package/dist/backend/core/global.cjs.map +1 -0
- package/dist/backend/core/global.d.cts +294 -0
- package/dist/backend/core/global.d.ts +294 -0
- package/dist/backend/core/global.js +39 -0
- package/dist/backend/core/global.js.map +1 -0
- package/dist/backend/core/onion-layers.cjs +2302 -0
- package/dist/backend/core/onion-layers.cjs.map +1 -0
- package/dist/backend/core/onion-layers.d.cts +1675 -0
- package/dist/backend/core/onion-layers.d.ts +1675 -0
- package/dist/backend/core/onion-layers.js +1158 -0
- package/dist/backend/core/onion-layers.js.map +1 -0
- package/dist/backend/core/presentation.cjs +573 -0
- package/dist/backend/core/presentation.cjs.map +1 -0
- package/dist/backend/core/presentation.d.cts +5 -0
- package/dist/backend/core/presentation.d.ts +5 -0
- package/dist/backend/core/presentation.js +28 -0
- package/dist/backend/core/presentation.js.map +1 -0
- package/dist/backend/core/validators/arktype.cjs +947 -0
- package/dist/backend/core/validators/arktype.cjs.map +1 -0
- package/dist/backend/core/validators/arktype.d.cts +188 -0
- package/dist/backend/core/validators/arktype.d.ts +188 -0
- package/dist/backend/core/validators/arktype.js +287 -0
- package/dist/backend/core/validators/arktype.js.map +1 -0
- package/dist/backend/core/validators/typebox.cjs +939 -0
- package/dist/backend/core/validators/typebox.cjs.map +1 -0
- package/dist/backend/core/validators/typebox.d.cts +189 -0
- package/dist/backend/core/validators/typebox.d.ts +189 -0
- package/dist/backend/core/validators/typebox.js +281 -0
- package/dist/backend/core/validators/typebox.js.map +1 -0
- package/dist/backend/core/validators/valibot.cjs +942 -0
- package/dist/backend/core/validators/valibot.cjs.map +1 -0
- package/dist/backend/core/validators/valibot.d.cts +160 -0
- package/dist/backend/core/validators/valibot.d.ts +160 -0
- package/dist/backend/core/validators/valibot.js +294 -0
- package/dist/backend/core/validators/valibot.js.map +1 -0
- package/dist/backend/core/validators/zod.cjs +934 -0
- package/dist/backend/core/validators/zod.cjs.map +1 -0
- package/dist/backend/core/validators/zod.d.cts +188 -0
- package/dist/backend/core/validators/zod.d.ts +188 -0
- package/dist/backend/core/validators/zod.js +278 -0
- package/dist/backend/core/validators/zod.js.map +1 -0
- package/dist/backend/frameworks/elysia.cjs +715 -0
- package/dist/backend/frameworks/elysia.cjs.map +1 -0
- package/dist/backend/frameworks/elysia.d.cts +208 -0
- package/dist/backend/frameworks/elysia.d.ts +208 -0
- package/dist/backend/frameworks/elysia.js +251 -0
- package/dist/backend/frameworks/elysia.js.map +1 -0
- package/dist/backend/frameworks/fastify.cjs +677 -0
- package/dist/backend/frameworks/fastify.cjs.map +1 -0
- package/dist/backend/frameworks/fastify.d.cts +201 -0
- package/dist/backend/frameworks/fastify.d.ts +201 -0
- package/dist/backend/frameworks/fastify.js +213 -0
- package/dist/backend/frameworks/fastify.js.map +1 -0
- package/dist/backend/frameworks/hono.cjs +715 -0
- package/dist/backend/frameworks/hono.cjs.map +1 -0
- package/dist/backend/frameworks/hono.d.cts +163 -0
- package/dist/backend/frameworks/hono.d.ts +163 -0
- package/dist/backend/frameworks/hono.js +249 -0
- package/dist/backend/frameworks/hono.js.map +1 -0
- package/dist/backend/frameworks/nestjs.cjs +260 -0
- package/dist/backend/frameworks/nestjs.cjs.map +1 -0
- package/dist/backend/frameworks/nestjs.d.cts +168 -0
- package/dist/backend/frameworks/nestjs.d.ts +168 -0
- package/dist/backend/frameworks/nestjs.js +193 -0
- package/dist/backend/frameworks/nestjs.js.map +1 -0
- package/dist/base-dto.class-D7W9iqoU.d.cts +146 -0
- package/dist/base-dto.class-D7W9iqoU.d.ts +146 -0
- package/dist/base-uuid-v7.vo-BPGEIWLM.d.ts +799 -0
- package/dist/base-uuid-v7.vo-BjqKX44G.d.cts +799 -0
- package/dist/chunk-74IKUOSE.js +116 -0
- package/dist/chunk-74IKUOSE.js.map +1 -0
- package/dist/chunk-BKZOLGQW.js +29 -0
- package/dist/chunk-BKZOLGQW.js.map +1 -0
- package/dist/chunk-CGZBV6BD.js +54 -0
- package/dist/chunk-CGZBV6BD.js.map +1 -0
- package/dist/chunk-DDAHJZVK.js +258 -0
- package/dist/chunk-DDAHJZVK.js.map +1 -0
- package/dist/chunk-MQD5GXMT.js +171 -0
- package/dist/chunk-MQD5GXMT.js.map +1 -0
- package/dist/chunk-OKFXZHBC.js +43 -0
- package/dist/chunk-OKFXZHBC.js.map +1 -0
- package/dist/chunk-RLLWYFPI.js +168 -0
- package/dist/chunk-RLLWYFPI.js.map +1 -0
- package/dist/chunk-VCHFXT5W.js +425 -0
- package/dist/chunk-VCHFXT5W.js.map +1 -0
- package/dist/chunk-ZWLYNGO3.js +40 -0
- package/dist/chunk-ZWLYNGO3.js.map +1 -0
- package/dist/http-response-BAhi8lF4.d.cts +124 -0
- package/dist/http-response-BAhi8lF4.d.ts +124 -0
- package/dist/index-DingXh7B.d.cts +1187 -0
- package/dist/index-tOH7XBa3.d.ts +1187 -0
- package/dist/routing.type-DB4pt-d9.d.ts +184 -0
- package/dist/routing.type-DF2BIL7x.d.cts +184 -0
- package/dist/validation-error.type-kD4_qNZ9.d.cts +199 -0
- package/dist/validation-error.type-kD4_qNZ9.d.ts +199 -0
- package/package.json +191 -0
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DomainError
|
|
3
|
+
} from "./chunk-ZWLYNGO3.js";
|
|
4
|
+
import {
|
|
5
|
+
ErrorCodes
|
|
6
|
+
} from "./chunk-MQD5GXMT.js";
|
|
7
|
+
|
|
8
|
+
// src/backend/core/onion-layers/domain/classes/base-value-object.class.ts
|
|
9
|
+
var SKIP_VALUE_OBJECT_VALIDATION = "skip value object validation";
|
|
10
|
+
function deepEquals(a, b) {
|
|
11
|
+
if (a === b) return true;
|
|
12
|
+
if (a === null || a === void 0 || b === null || b === void 0) {
|
|
13
|
+
return a === b;
|
|
14
|
+
}
|
|
15
|
+
if (a instanceof Date && b instanceof Date) {
|
|
16
|
+
return a.getTime() === b.getTime();
|
|
17
|
+
}
|
|
18
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
19
|
+
if (a.length !== b.length) return false;
|
|
20
|
+
return a.every((item, index) => deepEquals(item, b[index]));
|
|
21
|
+
}
|
|
22
|
+
if (typeof a === "object" && typeof b === "object") {
|
|
23
|
+
const aObj = a;
|
|
24
|
+
const bObj = b;
|
|
25
|
+
const aKeys = Object.keys(aObj);
|
|
26
|
+
const bKeys = Object.keys(bObj);
|
|
27
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
28
|
+
return aKeys.every((key) => deepEquals(aObj[key], bObj[key]));
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
var BaseValueObject = class {
|
|
33
|
+
_value;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a new Value Object instance.
|
|
36
|
+
*
|
|
37
|
+
* @param value - The raw value to wrap
|
|
38
|
+
* @param validator - A bound validator or SKIP_VALUE_OBJECT_VALIDATION to bypass
|
|
39
|
+
* @throws {ObjectValidationError} When validation fails
|
|
40
|
+
*/
|
|
41
|
+
constructor(value, validator) {
|
|
42
|
+
this._value = validator === SKIP_VALUE_OBJECT_VALIDATION ? value : validator.validate(value);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Compares this Value Object with another for equality.
|
|
46
|
+
*
|
|
47
|
+
* Uses deep equality comparison to handle nested objects, arrays, and dates.
|
|
48
|
+
* Two Value Objects are equal if their underlying values are deeply equal.
|
|
49
|
+
*
|
|
50
|
+
* @param other - The Value Object to compare with
|
|
51
|
+
* @returns `true` if the values are deeply equal, `false` otherwise
|
|
52
|
+
*/
|
|
53
|
+
equals(other) {
|
|
54
|
+
if (this === other) return true;
|
|
55
|
+
return deepEquals(this.value, other.value);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The underlying immutable value.
|
|
59
|
+
*
|
|
60
|
+
* @returns The wrapped value of type T
|
|
61
|
+
*/
|
|
62
|
+
get value() {
|
|
63
|
+
return this._value;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// src/backend/core/onion-layers/domain/exceptions/invariant-violation.error.ts
|
|
68
|
+
var InvariantViolationError = class _InvariantViolationError extends DomainError {
|
|
69
|
+
/**
|
|
70
|
+
* Creates a new InvariantViolationError instance.
|
|
71
|
+
*
|
|
72
|
+
* @param options - Error configuration
|
|
73
|
+
* @param options.message - Description of the violated invariant
|
|
74
|
+
* @param options.code - Machine-readable error code (default: 'INVARIANT_VIOLATION')
|
|
75
|
+
* @param options.cause - Optional underlying error
|
|
76
|
+
*/
|
|
77
|
+
constructor({
|
|
78
|
+
message,
|
|
79
|
+
code = ErrorCodes.Domain.INVARIANT_VIOLATION,
|
|
80
|
+
cause
|
|
81
|
+
}) {
|
|
82
|
+
super({ message, code, cause });
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Creates an InvariantViolationError from a caught error.
|
|
86
|
+
*
|
|
87
|
+
* @param cause - The original caught error
|
|
88
|
+
* @returns A new InvariantViolationError instance with the cause attached
|
|
89
|
+
*/
|
|
90
|
+
static fromError(cause) {
|
|
91
|
+
return new _InvariantViolationError({
|
|
92
|
+
message: cause instanceof Error ? cause.message : "Invariant violation",
|
|
93
|
+
cause
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// src/backend/core/onion-layers/domain/value-objects/base-audit-by.vo.ts
|
|
99
|
+
var BaseAuditByVo = class extends BaseValueObject {
|
|
100
|
+
/**
|
|
101
|
+
* Creates a new BaseAuditByVo instance.
|
|
102
|
+
*
|
|
103
|
+
* @param value - The user tracking values
|
|
104
|
+
* @param value.createdBy - User who created the entity (optional for system ops)
|
|
105
|
+
* @param value.updatedBy - User who last updated the entity (optional)
|
|
106
|
+
* @param validator - Bound validator or skip validation symbol
|
|
107
|
+
*/
|
|
108
|
+
constructor(value, validator) {
|
|
109
|
+
super(value, validator);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The user ID who created the entity.
|
|
113
|
+
* Returns `undefined` for system-created entities.
|
|
114
|
+
*/
|
|
115
|
+
get createdBy() {
|
|
116
|
+
return this.value.createdBy;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The user ID who last updated the entity.
|
|
120
|
+
* Returns `undefined` for system-updated entities.
|
|
121
|
+
*/
|
|
122
|
+
get updatedBy() {
|
|
123
|
+
return this.value.updatedBy;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// src/backend/core/onion-layers/domain/value-objects/base-audit-info.vo.ts
|
|
128
|
+
var BaseAuditInfoVo = class extends BaseValueObject {
|
|
129
|
+
/**
|
|
130
|
+
* Creates a new BaseAuditInfoVo instance.
|
|
131
|
+
*
|
|
132
|
+
* @param value - Composite value containing audit by and on VOs
|
|
133
|
+
* @param value.by - User tracking value object
|
|
134
|
+
* @param value.on - Timestamp tracking value object
|
|
135
|
+
* @param validator - Bound validator or skip validation symbol
|
|
136
|
+
*/
|
|
137
|
+
constructor(value, validator) {
|
|
138
|
+
super(value, validator);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The user ID who created the entity.
|
|
142
|
+
* Returns `undefined` for system-created entities.
|
|
143
|
+
*/
|
|
144
|
+
get createdBy() {
|
|
145
|
+
return this.value.by.createdBy;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The timestamp when the entity was created.
|
|
149
|
+
* Returns a cloned Date to prevent mutation.
|
|
150
|
+
*/
|
|
151
|
+
get createdAt() {
|
|
152
|
+
return new Date(this.value.on.createdAt.getTime());
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* The user ID who last updated the entity.
|
|
156
|
+
* Returns `undefined` for system-updated entities.
|
|
157
|
+
*/
|
|
158
|
+
get updatedBy() {
|
|
159
|
+
return this.value.by.updatedBy;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* The timestamp when the entity was last updated.
|
|
163
|
+
* Returns a cloned Date to prevent mutation.
|
|
164
|
+
*/
|
|
165
|
+
get updatedAt() {
|
|
166
|
+
return new Date(this.value.on.updatedAt.getTime());
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Whether the entity has been modified since creation.
|
|
170
|
+
*
|
|
171
|
+
* Compares both timestamps and user IDs. Returns `true` if either:
|
|
172
|
+
* - The updatedAt timestamp differs from createdAt
|
|
173
|
+
* - The updatedBy user differs from createdBy
|
|
174
|
+
*
|
|
175
|
+
* Note: When both createdBy and updatedBy are undefined (system-created
|
|
176
|
+
* entities), this correctly returns false for the user comparison.
|
|
177
|
+
*/
|
|
178
|
+
get isModified() {
|
|
179
|
+
const timestampChanged = this.updatedAt.getTime() !== this.createdAt.getTime();
|
|
180
|
+
const userChanged = this.updatedBy?.value !== this.createdBy?.value;
|
|
181
|
+
return timestampChanged || userChanged;
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Alias for `updatedBy` for semantic clarity.
|
|
185
|
+
*/
|
|
186
|
+
get lastModifiedBy() {
|
|
187
|
+
return this.updatedBy;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Alias for `updatedAt` for semantic clarity.
|
|
191
|
+
*/
|
|
192
|
+
get lastModifiedAt() {
|
|
193
|
+
return this.updatedAt;
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// src/backend/core/onion-layers/domain/value-objects/base-audit-on.vo.ts
|
|
198
|
+
var BaseAuditOnVo = class extends BaseValueObject {
|
|
199
|
+
/**
|
|
200
|
+
* Creates a new BaseAuditOnVo instance.
|
|
201
|
+
*
|
|
202
|
+
* @param value - The timestamp values
|
|
203
|
+
* @param value.createdAt - When the entity was created
|
|
204
|
+
* @param value.updatedAt - When the entity was last updated
|
|
205
|
+
* @param validator - Bound validator or skip validation symbol
|
|
206
|
+
* @throws {InvariantViolationError} When `updatedAt < createdAt`
|
|
207
|
+
*/
|
|
208
|
+
constructor(value, validator) {
|
|
209
|
+
if (value.updatedAt < value.createdAt) {
|
|
210
|
+
throw new InvariantViolationError({
|
|
211
|
+
message: "UpdatedAt cannot be earlier than createdAt",
|
|
212
|
+
code: "INVALID_AUDIT_TIMESTAMPS"
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
super(value, validator);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* When the entity was created.
|
|
219
|
+
* Returns a cloned Date to prevent mutation.
|
|
220
|
+
*/
|
|
221
|
+
get createdAt() {
|
|
222
|
+
return new Date(this.value.createdAt);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* When the entity was last updated.
|
|
226
|
+
* Returns a cloned Date to prevent mutation.
|
|
227
|
+
*/
|
|
228
|
+
get updatedAt() {
|
|
229
|
+
return new Date(this.value.updatedAt);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
// src/backend/core/onion-layers/domain/value-objects/base-email.vo.ts
|
|
234
|
+
var BaseEmailVo = class extends BaseValueObject {
|
|
235
|
+
/**
|
|
236
|
+
* Creates a new BaseEmailVo instance.
|
|
237
|
+
*
|
|
238
|
+
* @param value - The email address string
|
|
239
|
+
* @param validator - Bound validator or skip validation symbol
|
|
240
|
+
*/
|
|
241
|
+
constructor(value, validator) {
|
|
242
|
+
super(value, validator);
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
// src/backend/core/onion-layers/domain/value-objects/base-long-text.vo.ts
|
|
247
|
+
var BaseLongTextVo = class extends BaseValueObject {
|
|
248
|
+
/**
|
|
249
|
+
* Creates a new BaseLongTextVo instance.
|
|
250
|
+
*
|
|
251
|
+
* @param value - The long text string
|
|
252
|
+
* @param validator - Bound validator or skip validation symbol
|
|
253
|
+
*/
|
|
254
|
+
constructor(value, validator) {
|
|
255
|
+
super(value, validator);
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
// src/backend/core/onion-layers/domain/value-objects/base-medium-text.vo.ts
|
|
260
|
+
var BaseMediumTextVo = class extends BaseValueObject {
|
|
261
|
+
/**
|
|
262
|
+
* Creates a new BaseMediumTextVo instance.
|
|
263
|
+
*
|
|
264
|
+
* @param value - The medium text string
|
|
265
|
+
* @param validator - Bound validator or skip validation symbol
|
|
266
|
+
*/
|
|
267
|
+
constructor(value, validator) {
|
|
268
|
+
super(value, validator);
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
// src/backend/core/onion-layers/domain/value-objects/base-pagination.vo.ts
|
|
273
|
+
var BasePaginationVo = class extends BaseValueObject {
|
|
274
|
+
/**
|
|
275
|
+
* Creates a new BasePaginationVo instance.
|
|
276
|
+
*
|
|
277
|
+
* @param value - The pagination parameters
|
|
278
|
+
* @param value.page - The page number (typically 1-indexed)
|
|
279
|
+
* @param value.pageSize - The number of items per page
|
|
280
|
+
* @param validator - Bound validator or skip validation symbol
|
|
281
|
+
*/
|
|
282
|
+
constructor(value, validator) {
|
|
283
|
+
super(value, validator);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* The current page number.
|
|
287
|
+
*/
|
|
288
|
+
get page() {
|
|
289
|
+
return this.value.page;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* The number of items per page.
|
|
293
|
+
*/
|
|
294
|
+
get pageSize() {
|
|
295
|
+
return this.value.pageSize;
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
// src/backend/core/onion-layers/domain/value-objects/base-short-text.vo.ts
|
|
300
|
+
var BaseShortTextVo = class extends BaseValueObject {
|
|
301
|
+
/**
|
|
302
|
+
* Creates a new BaseShortTextVo instance.
|
|
303
|
+
*
|
|
304
|
+
* @param value - The short text string
|
|
305
|
+
* @param validator - Bound validator or skip validation symbol
|
|
306
|
+
*/
|
|
307
|
+
constructor(value, validator) {
|
|
308
|
+
super(value, validator);
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
// src/backend/core/onion-layers/domain/value-objects/base-uuid-v4.vo.ts
|
|
313
|
+
import { v4 } from "uuid";
|
|
314
|
+
var BaseUuidV4Vo = class extends BaseValueObject {
|
|
315
|
+
/**
|
|
316
|
+
* Creates a new BaseUuidV4Vo instance.
|
|
317
|
+
*
|
|
318
|
+
* @param value - The UUID v4 string value
|
|
319
|
+
* @param validator - Bound validator or skip validation symbol
|
|
320
|
+
*/
|
|
321
|
+
constructor(value, validator) {
|
|
322
|
+
super(value, validator);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Generates a new UUID v4 value object.
|
|
326
|
+
*
|
|
327
|
+
* Creates a random UUID, skipping validation since the
|
|
328
|
+
* `uuid` library guarantees format.
|
|
329
|
+
*
|
|
330
|
+
* @returns A new BaseUuidV4Vo with a freshly generated UUID
|
|
331
|
+
*/
|
|
332
|
+
static generate() {
|
|
333
|
+
return new this(v4(), SKIP_VALUE_OBJECT_VALIDATION);
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Creates a UUID v4 value object from an existing string.
|
|
337
|
+
*
|
|
338
|
+
* **Important:** This base implementation skips validation and accepts
|
|
339
|
+
* any string value. Subclasses should override this method with a
|
|
340
|
+
* validator to ensure UUID format correctness.
|
|
341
|
+
*
|
|
342
|
+
* @param value - The UUID v4 string value (not validated at base level)
|
|
343
|
+
* @returns A new BaseUuidV4Vo with the provided value
|
|
344
|
+
*
|
|
345
|
+
* @example Subclass with validation (recommended)
|
|
346
|
+
* ```typescript
|
|
347
|
+
* class UserId extends BaseUuidV4Vo {
|
|
348
|
+
* static override create(value: string): UserId {
|
|
349
|
+
* return new UserId(value, uuidV4Validator);
|
|
350
|
+
* }
|
|
351
|
+
* }
|
|
352
|
+
* ```
|
|
353
|
+
*
|
|
354
|
+
* @see generate - For creating new UUIDs (always valid)
|
|
355
|
+
*/
|
|
356
|
+
static create(value) {
|
|
357
|
+
return new this(value, SKIP_VALUE_OBJECT_VALIDATION);
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
// src/backend/core/onion-layers/domain/value-objects/base-uuid-v7.vo.ts
|
|
362
|
+
import { v7 } from "uuid";
|
|
363
|
+
var BaseUuidV7Vo = class extends BaseValueObject {
|
|
364
|
+
/**
|
|
365
|
+
* Creates a new BaseUuidV7Vo instance.
|
|
366
|
+
*
|
|
367
|
+
* @param value - The UUID v7 string value
|
|
368
|
+
* @param validator - Bound validator or skip validation symbol
|
|
369
|
+
*/
|
|
370
|
+
constructor(value, validator) {
|
|
371
|
+
super(value, validator);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Generates a new UUID v7 value object.
|
|
375
|
+
*
|
|
376
|
+
* Creates a time-ordered UUID using the current timestamp,
|
|
377
|
+
* skipping validation since the `uuid` library guarantees format.
|
|
378
|
+
*
|
|
379
|
+
* @returns A new BaseUuidV7Vo with a freshly generated UUID
|
|
380
|
+
*/
|
|
381
|
+
static generate() {
|
|
382
|
+
return new this(v7(), SKIP_VALUE_OBJECT_VALIDATION);
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Creates a UUID v7 value object from an existing string.
|
|
386
|
+
*
|
|
387
|
+
* **Important:** This base implementation skips validation and accepts
|
|
388
|
+
* any string value. Subclasses should override this method with a
|
|
389
|
+
* validator to ensure UUID format correctness.
|
|
390
|
+
*
|
|
391
|
+
* @param value - The UUID v7 string value (not validated at base level)
|
|
392
|
+
* @returns A new BaseUuidV7Vo with the provided value
|
|
393
|
+
*
|
|
394
|
+
* @example Subclass with validation (recommended)
|
|
395
|
+
* ```typescript
|
|
396
|
+
* class OrderId extends BaseUuidV7Vo {
|
|
397
|
+
* static override create(value: string): OrderId {
|
|
398
|
+
* return new OrderId(value, uuidV7Validator);
|
|
399
|
+
* }
|
|
400
|
+
* }
|
|
401
|
+
* ```
|
|
402
|
+
*
|
|
403
|
+
* @see generate - For creating new UUIDs (always valid)
|
|
404
|
+
*/
|
|
405
|
+
static create(value) {
|
|
406
|
+
return new this(value, SKIP_VALUE_OBJECT_VALIDATION);
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
|
|
410
|
+
export {
|
|
411
|
+
SKIP_VALUE_OBJECT_VALIDATION,
|
|
412
|
+
BaseValueObject,
|
|
413
|
+
InvariantViolationError,
|
|
414
|
+
BaseAuditByVo,
|
|
415
|
+
BaseAuditInfoVo,
|
|
416
|
+
BaseAuditOnVo,
|
|
417
|
+
BaseEmailVo,
|
|
418
|
+
BaseLongTextVo,
|
|
419
|
+
BaseMediumTextVo,
|
|
420
|
+
BasePaginationVo,
|
|
421
|
+
BaseShortTextVo,
|
|
422
|
+
BaseUuidV4Vo,
|
|
423
|
+
BaseUuidV7Vo
|
|
424
|
+
};
|
|
425
|
+
//# sourceMappingURL=chunk-VCHFXT5W.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/backend/core/onion-layers/domain/classes/base-value-object.class.ts","../src/backend/core/onion-layers/domain/exceptions/invariant-violation.error.ts","../src/backend/core/onion-layers/domain/value-objects/base-audit-by.vo.ts","../src/backend/core/onion-layers/domain/value-objects/base-audit-info.vo.ts","../src/backend/core/onion-layers/domain/value-objects/base-audit-on.vo.ts","../src/backend/core/onion-layers/domain/value-objects/base-email.vo.ts","../src/backend/core/onion-layers/domain/value-objects/base-long-text.vo.ts","../src/backend/core/onion-layers/domain/value-objects/base-medium-text.vo.ts","../src/backend/core/onion-layers/domain/value-objects/base-pagination.vo.ts","../src/backend/core/onion-layers/domain/value-objects/base-short-text.vo.ts","../src/backend/core/onion-layers/domain/value-objects/base-uuid-v4.vo.ts","../src/backend/core/onion-layers/domain/value-objects/base-uuid-v7.vo.ts"],"sourcesContent":["import type { BoundValidator } from '../../../global/interfaces/ports/object-validator.port';\n\n/**\n * Sentinel value to skip validation in Value Object constructors.\n *\n * Use this when creating a Value Object from already-validated data,\n * such as when reconstituting from a database or creating derived VOs.\n *\n * @example\n * ```typescript\n * // In a VO that wraps a validated value\n * class Email extends BaseValueObject<string> {\n * private constructor(value: string, validator: BoundValidator<string> | SkipValueObjectValidation) {\n * super(value, validator);\n * }\n *\n * // Public factory validates\n * static create(value: string): Email {\n * return new Email(value, emailValidator);\n * }\n *\n * // Internal factory skips validation (data already validated)\n * static fromPersistence(value: string): Email {\n * return new Email(value, SKIP_VALUE_OBJECT_VALIDATION);\n * }\n * }\n * ```\n */\nexport const SKIP_VALUE_OBJECT_VALIDATION = 'skip value object validation' as const;\n\n/** Type for the skip validation sentinel. */\nexport type SkipValueObjectValidation = typeof SKIP_VALUE_OBJECT_VALIDATION;\n\n/**\n * Deep equality comparison for value objects.\n * Handles primitives, Dates, Arrays, and nested Objects.\n * @internal\n */\nfunction deepEquals(a: unknown, b: unknown): boolean {\n // Same reference or both primitives with same value\n if (a === b) return true;\n\n // Handle null/undefined\n if (a === null || a === undefined || b === null || b === undefined) {\n return a === b;\n }\n\n // Handle Date objects\n if (a instanceof Date && b instanceof Date) {\n return a.getTime() === b.getTime();\n }\n\n // Handle Arrays\n if (Array.isArray(a) && Array.isArray(b)) {\n if (a.length !== b.length) return false;\n return a.every((item, index) => deepEquals(item, b[index]));\n }\n\n // Handle Objects\n if (typeof a === 'object' && typeof b === 'object') {\n const aObj = a as Record<string, unknown>;\n const bObj = b as Record<string, unknown>;\n\n const aKeys = Object.keys(aObj);\n const bKeys = Object.keys(bObj);\n\n if (aKeys.length !== bKeys.length) return false;\n\n return aKeys.every((key) => deepEquals(aObj[key], bObj[key]));\n }\n\n // Different types or values\n return false;\n}\n\n/**\n * Base class for Domain-Driven Design Value Objects.\n *\n * Value Objects are immutable domain primitives that are compared by value,\n * not by reference. They encapsulate validation and domain logic for\n * primitive concepts like Email, Money, Address, etc.\n *\n * Key characteristics:\n * - **Immutable**: Value cannot be changed after construction\n * - **Equality by value**: Two VOs with the same value are considered equal\n * - **Self-validating**: Validation runs at construction time\n *\n * @typeParam T - The underlying value type\n *\n * @example\n * ```typescript\n * class Email extends BaseValueObject<string> {\n * private constructor(value: string, validator: BoundValidator<string> | SkipValueObjectValidation) {\n * super(value, validator);\n * }\n *\n * static create(value: string): Email {\n * return new Email(value, emailValidator);\n * }\n *\n * get domain(): string {\n * return this.value.split('@')[1];\n * }\n * }\n *\n * const email1 = Email.create('user@example.com');\n * const email2 = Email.create('user@example.com');\n * email1.equals(email2); // true\n * ```\n */\nexport class BaseValueObject<T> {\n private readonly _value: T;\n\n /**\n * Creates a new Value Object instance.\n *\n * @param value - The raw value to wrap\n * @param validator - A bound validator or SKIP_VALUE_OBJECT_VALIDATION to bypass\n * @throws {ObjectValidationError} When validation fails\n */\n protected constructor(\n value: T,\n validator: BoundValidator<T> | typeof SKIP_VALUE_OBJECT_VALIDATION,\n ) {\n this._value = validator === SKIP_VALUE_OBJECT_VALIDATION ? value : validator.validate(value);\n }\n\n /**\n * Compares this Value Object with another for equality.\n *\n * Uses deep equality comparison to handle nested objects, arrays, and dates.\n * Two Value Objects are equal if their underlying values are deeply equal.\n *\n * @param other - The Value Object to compare with\n * @returns `true` if the values are deeply equal, `false` otherwise\n */\n public equals(other: BaseValueObject<T>): boolean {\n // Fast path: same reference\n if (this === other) return true;\n\n // Deep equality comparison\n return deepEquals(this.value, other.value);\n }\n\n /**\n * The underlying immutable value.\n *\n * @returns The wrapped value of type T\n */\n public get value(): T {\n return this._value;\n }\n}\n","import { ErrorCodes, type DomainErrorCode } from '../../../global/exceptions/error-codes.const';\nimport { DomainError } from './domain.error';\n\n/**\n * Error thrown when a domain invariant is violated.\n *\n * Invariants are business rules that must always be true. This error\n * indicates a programming error or corrupted state—if inputs are\n * properly validated, this should never occur in production.\n *\n * **When to throw:**\n * - Business rule violations (e.g., `updatedAt < createdAt`)\n * - Assert-style guards in domain logic\n * - Invalid state transitions\n *\n * @example\n * ```typescript\n * if (order.status === 'shipped' && order.items.length === 0) {\n * throw new InvariantViolationError({\n * message: 'Shipped order must have at least one item',\n * code: 'EMPTY_SHIPPED_ORDER',\n * });\n * }\n * ```\n *\n * @extends DomainError\n */\nexport class InvariantViolationError extends DomainError {\n /**\n * Creates a new InvariantViolationError instance.\n *\n * @param options - Error configuration\n * @param options.message - Description of the violated invariant\n * @param options.code - Machine-readable error code (default: 'INVARIANT_VIOLATION')\n * @param options.cause - Optional underlying error\n */\n constructor({\n message,\n code = ErrorCodes.Domain.INVARIANT_VIOLATION,\n cause,\n }: {\n message: string;\n code?: DomainErrorCode | string;\n cause?: unknown;\n }) {\n super({ message, code, cause });\n }\n\n /**\n * Creates an InvariantViolationError from a caught error.\n *\n * @param cause - The original caught error\n * @returns A new InvariantViolationError instance with the cause attached\n */\n static override fromError(cause: unknown): InvariantViolationError {\n return new InvariantViolationError({\n message: cause instanceof Error ? cause.message : 'Invariant violation',\n cause,\n });\n }\n}\n","/**\n * Base audit user tracking value object.\n *\n * Tracks which user created and last updated an entity. User IDs are\n * optional to support system-initiated operations where no user context\n * is available.\n *\n * @example Extending for a validator-specific implementation\n * ```typescript\n * class AuditByVo extends BaseAuditByVo {\n * static create(opts?: {\n * createdBy?: UuidV4Vo;\n * updatedBy?: UuidV4Vo;\n * }): AuditByVo {\n * return new AuditByVo({\n * createdBy: opts?.createdBy,\n * updatedBy: opts?.updatedBy ?? opts?.createdBy,\n * }, SKIP_VALUE_OBJECT_VALIDATION);\n * }\n *\n * update(updatedBy: UuidV4Vo): AuditByVo {\n * return new AuditByVo({\n * createdBy: this.createdBy,\n * updatedBy,\n * }, SKIP_VALUE_OBJECT_VALIDATION);\n * }\n * }\n * ```\n */\nimport type { BoundValidator } from '../../../global/interfaces/ports/object-validator.port';\nimport type { SkipValueObjectValidation } from '../classes/base-value-object.class';\nimport { BaseValueObject } from '../classes/base-value-object.class';\nimport type { BaseUuidV4Vo } from './base-uuid-v4.vo';\n\n/**\n * Abstract base class for audit user tracking value objects.\n *\n * @extends BaseValueObject\n */\nexport abstract class BaseAuditByVo extends BaseValueObject<{\n createdBy?: BaseUuidV4Vo;\n updatedBy?: BaseUuidV4Vo;\n}> {\n /**\n * Creates a new BaseAuditByVo instance.\n *\n * @param value - The user tracking values\n * @param value.createdBy - User who created the entity (optional for system ops)\n * @param value.updatedBy - User who last updated the entity (optional)\n * @param validator - Bound validator or skip validation symbol\n */\n protected constructor(\n value: { createdBy?: BaseUuidV4Vo; updatedBy?: BaseUuidV4Vo },\n validator:\n | BoundValidator<{ createdBy?: BaseUuidV4Vo; updatedBy?: BaseUuidV4Vo }>\n | SkipValueObjectValidation,\n ) {\n super(value, validator);\n }\n\n /**\n * Creates a new audit user tracking with updated user ID.\n *\n * @param updatedBy - The user ID performing the update\n * @returns A new immutable audit user tracking instance\n */\n abstract update(updatedBy: BaseUuidV4Vo): BaseAuditByVo;\n\n /**\n * The user ID who created the entity.\n * Returns `undefined` for system-created entities.\n */\n get createdBy(): BaseUuidV4Vo | undefined {\n return this.value.createdBy;\n }\n\n /**\n * The user ID who last updated the entity.\n * Returns `undefined` for system-updated entities.\n */\n get updatedBy(): BaseUuidV4Vo | undefined {\n return this.value.updatedBy;\n }\n}\n","/**\n * Base audit info value object for entity tracking.\n *\n * Composite value object that combines timestamp tracking ({@link BaseAuditOnVo})\n * and user tracking ({@link BaseAuditByVo}) into a single immutable audit record.\n * Used for tracking entity creation and modification history.\n *\n * **Composition:**\n * - `on`: {@link BaseAuditOnVo} - timestamps (createdAt, updatedAt)\n * - `by`: {@link BaseAuditByVo} - user IDs (createdBy, updatedBy)\n *\n * **Immutability:**\n * Date getters return cloned Date objects to prevent external mutation.\n *\n * @example Extending for a validator-specific implementation\n * ```typescript\n * class AuditInfoVo extends BaseAuditInfoVo {\n * static create(createdBy?: UuidV4Vo): AuditInfoVo {\n * const now = new Date();\n * return new AuditInfoVo({\n * by: AuditByVo.create({ createdBy, updatedBy: createdBy }),\n * on: AuditOnVo.create({ createdAt: now, updatedAt: now }),\n * }, SKIP_VALUE_OBJECT_VALIDATION);\n * }\n *\n * update(updatedBy: UuidV4Vo): AuditInfoVo {\n * return new AuditInfoVo({\n * by: this.value.by.update(updatedBy),\n * on: this.value.on.update(),\n * }, SKIP_VALUE_OBJECT_VALIDATION);\n * }\n * }\n * ```\n *\n * @example Using with an entity\n * ```typescript\n * class User {\n * constructor(\n * public readonly id: UuidV7Vo,\n * public readonly name: string,\n * public readonly audit: AuditInfoVo,\n * ) {}\n *\n * updateName(name: string, updatedBy: UuidV4Vo): User {\n * return new User(this.id, name, this.audit.update(updatedBy));\n * }\n * }\n * ```\n */\nimport type { BoundValidator } from '../../../global/interfaces/ports/object-validator.port';\nimport type { SkipValueObjectValidation } from '../classes/base-value-object.class';\nimport { BaseValueObject } from '../classes/base-value-object.class';\nimport type { BaseAuditByVo } from './base-audit-by.vo';\nimport type { BaseAuditOnVo } from './base-audit-on.vo';\nimport type { BaseUuidV4Vo } from './base-uuid-v4.vo';\n\n/**\n * Abstract base class for audit information value objects.\n *\n * Extend this class and implement the `update()` method with your\n * validator-specific child VOs.\n *\n * @extends BaseValueObject\n */\nexport abstract class BaseAuditInfoVo extends BaseValueObject<{\n by: BaseAuditByVo;\n on: BaseAuditOnVo;\n}> {\n /**\n * Creates a new BaseAuditInfoVo instance.\n *\n * @param value - Composite value containing audit by and on VOs\n * @param value.by - User tracking value object\n * @param value.on - Timestamp tracking value object\n * @param validator - Bound validator or skip validation symbol\n */\n protected constructor(\n value: { by: BaseAuditByVo; on: BaseAuditOnVo },\n validator: BoundValidator<{ by: BaseAuditByVo; on: BaseAuditOnVo }> | SkipValueObjectValidation,\n ) {\n super(value, validator);\n }\n\n /**\n * Creates a new audit info with updated timestamp and user.\n *\n * @param updatedBy - The user ID performing the update\n * @returns A new immutable audit info instance\n */\n abstract update(updatedBy: BaseUuidV4Vo): BaseAuditInfoVo;\n\n /**\n * The user ID who created the entity.\n * Returns `undefined` for system-created entities.\n */\n get createdBy(): BaseUuidV4Vo | undefined {\n return this.value.by.createdBy;\n }\n\n /**\n * The timestamp when the entity was created.\n * Returns a cloned Date to prevent mutation.\n */\n get createdAt(): Date {\n return new Date(this.value.on.createdAt.getTime());\n }\n\n /**\n * The user ID who last updated the entity.\n * Returns `undefined` for system-updated entities.\n */\n get updatedBy(): BaseUuidV4Vo | undefined {\n return this.value.by.updatedBy;\n }\n\n /**\n * The timestamp when the entity was last updated.\n * Returns a cloned Date to prevent mutation.\n */\n get updatedAt(): Date {\n return new Date(this.value.on.updatedAt.getTime());\n }\n\n /**\n * Whether the entity has been modified since creation.\n *\n * Compares both timestamps and user IDs. Returns `true` if either:\n * - The updatedAt timestamp differs from createdAt\n * - The updatedBy user differs from createdBy\n *\n * Note: When both createdBy and updatedBy are undefined (system-created\n * entities), this correctly returns false for the user comparison.\n */\n get isModified(): boolean {\n const timestampChanged = this.updatedAt.getTime() !== this.createdAt.getTime();\n const userChanged = this.updatedBy?.value !== this.createdBy?.value;\n return timestampChanged || userChanged;\n }\n\n /**\n * Alias for `updatedBy` for semantic clarity.\n */\n get lastModifiedBy(): BaseUuidV4Vo | undefined {\n return this.updatedBy;\n }\n\n /**\n * Alias for `updatedAt` for semantic clarity.\n */\n get lastModifiedAt(): Date {\n return this.updatedAt;\n }\n}\n","/**\n * Base audit timestamp value object.\n *\n * Tracks when an entity was created and last updated. Enforces the\n * domain invariant that `updatedAt` cannot be earlier than `createdAt`.\n *\n * **Domain Invariant:**\n * The constructor throws {@link InvariantViolationError} if\n * `updatedAt < createdAt`, ensuring timestamps are always valid.\n *\n * **Immutability:**\n * Date getters return cloned Date objects to prevent external mutation.\n *\n * @example Extending for a validator-specific implementation\n * ```typescript\n * class AuditOnVo extends BaseAuditOnVo {\n * static create(opts?: { createdAt?: Date; updatedAt?: Date }): AuditOnVo {\n * const now = new Date();\n * return new AuditOnVo({\n * createdAt: opts?.createdAt ?? now,\n * updatedAt: opts?.updatedAt ?? now,\n * }, SKIP_VALUE_OBJECT_VALIDATION);\n * }\n *\n * update(): AuditOnVo {\n * return new AuditOnVo({\n * createdAt: this.createdAt,\n * updatedAt: new Date(),\n * }, SKIP_VALUE_OBJECT_VALIDATION);\n * }\n * }\n * ```\n */\nimport type { BoundValidator } from '../../../global/interfaces/ports/object-validator.port';\nimport type { SkipValueObjectValidation } from '../classes/base-value-object.class';\nimport { BaseValueObject } from '../classes/base-value-object.class';\nimport { InvariantViolationError } from '../exceptions/invariant-violation.error';\n\n/**\n * Abstract base class for audit timestamp value objects.\n *\n * @extends BaseValueObject\n * @throws {InvariantViolationError} When `updatedAt` is earlier than `createdAt`\n */\nexport abstract class BaseAuditOnVo extends BaseValueObject<{\n createdAt: Date;\n updatedAt: Date;\n}> {\n /**\n * Creates a new BaseAuditOnVo instance.\n *\n * @param value - The timestamp values\n * @param value.createdAt - When the entity was created\n * @param value.updatedAt - When the entity was last updated\n * @param validator - Bound validator or skip validation symbol\n * @throws {InvariantViolationError} When `updatedAt < createdAt`\n */\n protected constructor(\n value: { createdAt: Date; updatedAt: Date },\n validator: BoundValidator<{ createdAt: Date; updatedAt: Date }> | SkipValueObjectValidation,\n ) {\n // Domain enforces its own invariant\n if (value.updatedAt < value.createdAt) {\n throw new InvariantViolationError({\n message: 'UpdatedAt cannot be earlier than createdAt',\n code: 'INVALID_AUDIT_TIMESTAMPS',\n });\n }\n super(value, validator);\n }\n\n /**\n * Creates a new audit timestamp with current time as updatedAt.\n *\n * @returns A new immutable audit timestamp instance\n */\n abstract update(): BaseAuditOnVo;\n\n /**\n * When the entity was created.\n * Returns a cloned Date to prevent mutation.\n */\n get createdAt(): Date {\n return new Date(this.value.createdAt);\n }\n\n /**\n * When the entity was last updated.\n * Returns a cloned Date to prevent mutation.\n */\n get updatedAt(): Date {\n return new Date(this.value.updatedAt);\n }\n}\n","/**\n * Base email value object.\n *\n * Represents a validated email address. Extend this class and provide\n * a validator that enforces email format rules.\n *\n * @example Extending with Zod validation\n * ```typescript\n * import { z } from 'zod';\n * import { createZodValidator } from '@cosmneo/onion-lasagna/backend/core/validators/zod';\n *\n * const emailSchema = z.string().email();\n * const emailValidator = createZodValidator(emailSchema);\n *\n * class EmailVo extends BaseEmailVo {\n * static create(value: string): EmailVo {\n * return new EmailVo(value, emailValidator);\n * }\n * }\n * ```\n *\n * @example Usage\n * ```typescript\n * const email = EmailVo.create('user@example.com');\n * console.log(email.value); // \"user@example.com\"\n * ```\n */\nimport type { BoundValidator } from '../../../global/interfaces/ports/object-validator.port';\nimport type { SKIP_VALUE_OBJECT_VALIDATION } from '../classes/base-value-object.class';\nimport { BaseValueObject } from '../classes/base-value-object.class';\n\n/**\n * Value object for email addresses.\n *\n * @extends BaseValueObject<string>\n */\nexport class BaseEmailVo extends BaseValueObject<string> {\n /**\n * Creates a new BaseEmailVo instance.\n *\n * @param value - The email address string\n * @param validator - Bound validator or skip validation symbol\n */\n protected constructor(\n value: string,\n validator: BoundValidator<string> | typeof SKIP_VALUE_OBJECT_VALIDATION,\n ) {\n super(value, validator);\n }\n}\n","/**\n * Base long text value object.\n *\n * Represents long-form text fields like articles, content bodies, or notes.\n * Typically validated with a maximum length constraint (e.g., 5000+ chars).\n *\n * **Suggested Length:** 1-5000+ characters\n *\n * **Use Cases:**\n * - Article content\n * - Blog posts\n * - Detailed notes\n * - Rich text content\n *\n * @example Extending with length validation\n * ```typescript\n * import { z } from 'zod';\n * import { createZodValidator } from '@cosmneo/onion-lasagna/backend/core/validators/zod';\n *\n * const longTextSchema = z.string().min(1).max(10000);\n * const longTextValidator = createZodValidator(longTextSchema);\n *\n * class ArticleContentVo extends BaseLongTextVo {\n * static create(value: string): ArticleContentVo {\n * return new ArticleContentVo(value, longTextValidator);\n * }\n * }\n * ```\n */\nimport type { BoundValidator } from '../../../global/interfaces/ports/object-validator.port';\nimport type { SKIP_VALUE_OBJECT_VALIDATION } from '../classes/base-value-object.class';\nimport { BaseValueObject } from '../classes/base-value-object.class';\n\n/**\n * Value object for long-form text strings.\n *\n * @extends BaseValueObject<string>\n */\nexport class BaseLongTextVo extends BaseValueObject<string> {\n /**\n * Creates a new BaseLongTextVo instance.\n *\n * @param value - The long text string\n * @param validator - Bound validator or skip validation symbol\n */\n protected constructor(\n value: string,\n validator: BoundValidator<string> | typeof SKIP_VALUE_OBJECT_VALIDATION,\n ) {\n super(value, validator);\n }\n}\n","/**\n * Base medium text value object.\n *\n * Represents medium-length text fields like descriptions or summaries.\n * Typically validated with a maximum length constraint (e.g., 500 chars).\n *\n * **Suggested Length:** 1-500 characters\n *\n * **Use Cases:**\n * - Product descriptions\n * - User bios\n * - Short summaries\n * - Comments\n *\n * @example Extending with length validation\n * ```typescript\n * import { z } from 'zod';\n * import { createZodValidator } from '@cosmneo/onion-lasagna/backend/core/validators/zod';\n *\n * const mediumTextSchema = z.string().min(1).max(500);\n * const mediumTextValidator = createZodValidator(mediumTextSchema);\n *\n * class DescriptionVo extends BaseMediumTextVo {\n * static create(value: string): DescriptionVo {\n * return new DescriptionVo(value, mediumTextValidator);\n * }\n * }\n * ```\n */\nimport type { BoundValidator } from '../../../global/interfaces/ports/object-validator.port';\nimport type { SKIP_VALUE_OBJECT_VALIDATION } from '../classes/base-value-object.class';\nimport { BaseValueObject } from '../classes/base-value-object.class';\n\n/**\n * Value object for medium-length text strings.\n *\n * @extends BaseValueObject<string>\n */\nexport class BaseMediumTextVo extends BaseValueObject<string> {\n /**\n * Creates a new BaseMediumTextVo instance.\n *\n * @param value - The medium text string\n * @param validator - Bound validator or skip validation symbol\n */\n protected constructor(\n value: string,\n validator: BoundValidator<string> | typeof SKIP_VALUE_OBJECT_VALIDATION,\n ) {\n super(value, validator);\n }\n}\n","/**\n * Base pagination value object.\n *\n * Represents pagination parameters for list queries. Validates that\n * page numbers and page sizes are positive integers within bounds.\n *\n * **Properties:**\n * - `page`: The current page number (typically 1-indexed)\n * - `pageSize`: Number of items per page\n *\n * @example Extending with validation\n * ```typescript\n * import { z } from 'zod';\n * import { createZodValidator } from '@cosmneo/onion-lasagna/backend/core/validators/zod';\n *\n * const paginationSchema = z.object({\n * page: z.number().int().min(1),\n * pageSize: z.number().int().min(1).max(100),\n * });\n * const paginationValidator = createZodValidator(paginationSchema);\n *\n * class PaginationVo extends BasePaginationVo {\n * static create(page: number, pageSize: number): PaginationVo {\n * return new PaginationVo({ page, pageSize }, paginationValidator);\n * }\n * }\n * ```\n *\n * @example Usage in a use case\n * ```typescript\n * class ListUsersUseCase {\n * async execute(pagination: PaginationVo): Promise<User[]> {\n * const offset = (pagination.page - 1) * pagination.pageSize;\n * return this.userRepo.findAll({\n * offset,\n * limit: pagination.pageSize,\n * });\n * }\n * }\n * ```\n */\nimport type { BoundValidator } from '../../../global/interfaces/ports/object-validator.port';\nimport type { SKIP_VALUE_OBJECT_VALIDATION } from '../classes/base-value-object.class';\nimport { BaseValueObject } from '../classes/base-value-object.class';\n\n/**\n * Value object for pagination parameters.\n *\n * @extends BaseValueObject<{ page: number; pageSize: number }>\n */\nexport class BasePaginationVo extends BaseValueObject<{ page: number; pageSize: number }> {\n /**\n * Creates a new BasePaginationVo instance.\n *\n * @param value - The pagination parameters\n * @param value.page - The page number (typically 1-indexed)\n * @param value.pageSize - The number of items per page\n * @param validator - Bound validator or skip validation symbol\n */\n protected constructor(\n value: { page: number; pageSize: number },\n validator:\n | BoundValidator<{ page: number; pageSize: number }>\n | typeof SKIP_VALUE_OBJECT_VALIDATION,\n ) {\n super(value, validator);\n }\n\n /**\n * The current page number.\n */\n get page(): number {\n return this.value.page;\n }\n\n /**\n * The number of items per page.\n */\n get pageSize(): number {\n return this.value.pageSize;\n }\n}\n","/**\n * Base short text value object.\n *\n * Represents short text fields like names, titles, or labels.\n * Typically validated with a maximum length constraint (e.g., 100 chars).\n *\n * **Suggested Length:** 1-100 characters\n *\n * **Use Cases:**\n * - User names\n * - Product titles\n * - Category names\n * - Short labels\n *\n * @example Extending with length validation\n * ```typescript\n * import { z } from 'zod';\n * import { createZodValidator } from '@cosmneo/onion-lasagna/backend/core/validators/zod';\n *\n * const shortTextSchema = z.string().min(1).max(100);\n * const shortTextValidator = createZodValidator(shortTextSchema);\n *\n * class UserNameVo extends BaseShortTextVo {\n * static create(value: string): UserNameVo {\n * return new UserNameVo(value, shortTextValidator);\n * }\n * }\n * ```\n */\nimport type { BoundValidator } from '../../../global/interfaces/ports/object-validator.port';\nimport type { SKIP_VALUE_OBJECT_VALIDATION } from '../classes/base-value-object.class';\nimport { BaseValueObject } from '../classes/base-value-object.class';\n\n/**\n * Value object for short text strings.\n *\n * @extends BaseValueObject<string>\n */\nexport class BaseShortTextVo extends BaseValueObject<string> {\n /**\n * Creates a new BaseShortTextVo instance.\n *\n * @param value - The short text string\n * @param validator - Bound validator or skip validation symbol\n */\n protected constructor(\n value: string,\n validator: BoundValidator<string> | typeof SKIP_VALUE_OBJECT_VALIDATION,\n ) {\n super(value, validator);\n }\n}\n","/**\n * Base UUID v4 value object for random entity identifiers.\n *\n * UUID v4 is a randomly generated UUID, suitable for identifiers where\n * time-ordering is not required. For time-sortable IDs, use {@link BaseUuidV7Vo}.\n *\n * **Use Cases:**\n * - User IDs (for audit tracking)\n * - Session tokens\n * - Correlation IDs\n * - Any identifier where time-ordering doesn't matter\n *\n * @example Generating a new ID\n * ```typescript\n * const id = BaseUuidV4Vo.generate();\n * console.log(id.value); // e.g., \"550e8400-e29b-41d4-a716-446655440000\"\n * ```\n *\n * @example Extending for validation\n * ```typescript\n * class UserIdVo extends BaseUuidV4Vo {\n * static create(value: string): UserIdVo {\n * return new UserIdVo(value, uuidValidator);\n * }\n *\n * static generate(): UserIdVo {\n * return new UserIdVo(v4(), SKIP_VALUE_OBJECT_VALIDATION);\n * }\n * }\n * ```\n */\nimport type { BoundValidator } from '../../../global/interfaces/ports/object-validator.port';\nimport { BaseValueObject, SKIP_VALUE_OBJECT_VALIDATION } from '../classes/base-value-object.class';\nimport { v4 } from 'uuid';\n\n/**\n * Value object for UUID v4 identifiers.\n *\n * Provides a `generate()` factory method that creates new random UUIDs.\n *\n * @extends BaseValueObject<string>\n */\nexport class BaseUuidV4Vo extends BaseValueObject<string> {\n /**\n * Creates a new BaseUuidV4Vo instance.\n *\n * @param value - The UUID v4 string value\n * @param validator - Bound validator or skip validation symbol\n */\n protected constructor(\n value: string,\n validator: BoundValidator<string> | typeof SKIP_VALUE_OBJECT_VALIDATION,\n ) {\n super(value, validator);\n }\n\n /**\n * Generates a new UUID v4 value object.\n *\n * Creates a random UUID, skipping validation since the\n * `uuid` library guarantees format.\n *\n * @returns A new BaseUuidV4Vo with a freshly generated UUID\n */\n static generate(): BaseUuidV4Vo {\n return new this(v4(), SKIP_VALUE_OBJECT_VALIDATION);\n }\n\n /**\n * Creates a UUID v4 value object from an existing string.\n *\n * **Important:** This base implementation skips validation and accepts\n * any string value. Subclasses should override this method with a\n * validator to ensure UUID format correctness.\n *\n * @param value - The UUID v4 string value (not validated at base level)\n * @returns A new BaseUuidV4Vo with the provided value\n *\n * @example Subclass with validation (recommended)\n * ```typescript\n * class UserId extends BaseUuidV4Vo {\n * static override create(value: string): UserId {\n * return new UserId(value, uuidV4Validator);\n * }\n * }\n * ```\n *\n * @see generate - For creating new UUIDs (always valid)\n */\n static create(value: string): BaseUuidV4Vo {\n return new this(value, SKIP_VALUE_OBJECT_VALIDATION);\n }\n}\n","/**\n * Base UUID v7 value object for time-sortable entity identifiers.\n *\n * UUID v7 is a time-ordered UUID that combines a Unix timestamp with\n * random bits, making it ideal for database primary keys because:\n *\n * **Benefits:**\n * - **Time-sortable**: IDs created later sort after earlier ones\n * - **Database-friendly**: Sequential nature reduces B-tree fragmentation\n * - **Globally unique**: Same uniqueness guarantees as other UUID versions\n * - **Timestamp extractable**: Creation time can be derived from the ID\n *\n * @example Generating a new ID\n * ```typescript\n * const id = BaseUuidV7Vo.generate();\n * console.log(id.value); // e.g., \"018f3b1c-5e7d-7000-8000-000000000001\"\n * ```\n *\n * @example Extending for validation\n * ```typescript\n * class EntityIdVo extends BaseUuidV7Vo {\n * static create(value: string): EntityIdVo {\n * return new EntityIdVo(value, uuidValidator);\n * }\n *\n * static generate(): EntityIdVo {\n * return new EntityIdVo(v7(), SKIP_VALUE_OBJECT_VALIDATION);\n * }\n * }\n * ```\n *\n * @example Using as entity primary key\n * ```typescript\n * class User {\n * constructor(\n * public readonly id: EntityIdVo,\n * public readonly name: string,\n * ) {}\n *\n * static create(name: string): User {\n * return new User(EntityIdVo.generate(), name);\n * }\n * }\n * ```\n */\nimport type { BoundValidator } from '../../../global/interfaces/ports/object-validator.port';\nimport { BaseValueObject, SKIP_VALUE_OBJECT_VALIDATION } from '../classes/base-value-object.class';\nimport { v7 } from 'uuid';\n\n/**\n * Value object for UUID v7 identifiers.\n *\n * Provides a `generate()` factory method that creates new time-ordered UUIDs.\n *\n * @extends BaseValueObject<string>\n */\nexport class BaseUuidV7Vo extends BaseValueObject<string> {\n /**\n * Creates a new BaseUuidV7Vo instance.\n *\n * @param value - The UUID v7 string value\n * @param validator - Bound validator or skip validation symbol\n */\n protected constructor(\n value: string,\n validator: BoundValidator<string> | typeof SKIP_VALUE_OBJECT_VALIDATION,\n ) {\n super(value, validator);\n }\n\n /**\n * Generates a new UUID v7 value object.\n *\n * Creates a time-ordered UUID using the current timestamp,\n * skipping validation since the `uuid` library guarantees format.\n *\n * @returns A new BaseUuidV7Vo with a freshly generated UUID\n */\n static generate(): BaseUuidV7Vo {\n return new this(v7(), SKIP_VALUE_OBJECT_VALIDATION);\n }\n\n /**\n * Creates a UUID v7 value object from an existing string.\n *\n * **Important:** This base implementation skips validation and accepts\n * any string value. Subclasses should override this method with a\n * validator to ensure UUID format correctness.\n *\n * @param value - The UUID v7 string value (not validated at base level)\n * @returns A new BaseUuidV7Vo with the provided value\n *\n * @example Subclass with validation (recommended)\n * ```typescript\n * class OrderId extends BaseUuidV7Vo {\n * static override create(value: string): OrderId {\n * return new OrderId(value, uuidV7Validator);\n * }\n * }\n * ```\n *\n * @see generate - For creating new UUIDs (always valid)\n */\n static create(value: string): BaseUuidV7Vo {\n return new this(value, SKIP_VALUE_OBJECT_VALIDATION);\n }\n}\n"],"mappings":";;;;;;;;AA4BO,IAAM,+BAA+B;AAU5C,SAAS,WAAW,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AA;AAAA;AAAA;AAAA;AAAA,EAUA,OAAO,WAAyB;AAC9B,WAAO,IAAI,KAAK,GAAG,GAAG,4BAA4B;AAAA,EACpD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAuBA,OAAO,OAAO,OAA6B;AACzC,WAAO,IAAI,KAAK,OAAO,4BAA4B;AAAA,EACrD;AACF;","names":[]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CodedError,
|
|
3
|
+
ErrorCodes
|
|
4
|
+
} from "./chunk-MQD5GXMT.js";
|
|
5
|
+
|
|
6
|
+
// src/backend/core/onion-layers/domain/exceptions/domain.error.ts
|
|
7
|
+
var DomainError = class _DomainError extends CodedError {
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new DomainError instance.
|
|
10
|
+
*
|
|
11
|
+
* @param options - Error configuration
|
|
12
|
+
* @param options.message - Human-readable error description
|
|
13
|
+
* @param options.code - Machine-readable error code (default: 'DOMAIN_ERROR')
|
|
14
|
+
* @param options.cause - Optional underlying error
|
|
15
|
+
*/
|
|
16
|
+
constructor({
|
|
17
|
+
message,
|
|
18
|
+
code = ErrorCodes.Domain.DOMAIN_ERROR,
|
|
19
|
+
cause
|
|
20
|
+
}) {
|
|
21
|
+
super({ message, code, cause });
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Creates a DomainError from a caught error.
|
|
25
|
+
*
|
|
26
|
+
* @param cause - The original caught error
|
|
27
|
+
* @returns A new DomainError instance with the cause attached
|
|
28
|
+
*/
|
|
29
|
+
static fromError(cause) {
|
|
30
|
+
return new _DomainError({
|
|
31
|
+
message: cause instanceof Error ? cause.message : "Domain error",
|
|
32
|
+
cause
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export {
|
|
38
|
+
DomainError
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=chunk-ZWLYNGO3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/backend/core/onion-layers/domain/exceptions/domain.error.ts"],"sourcesContent":["import { CodedError } from '../../../global/exceptions/coded-error.error';\nimport { ErrorCodes, type DomainErrorCode } from '../../../global/exceptions/error-codes.const';\n\n/**\n * Base error class for domain layer failures.\n *\n * Domain errors represent violations of business rules, invariants,\n * or aggregate consistency. They originate from the core domain logic\n * and should be caught and handled by the application layer.\n *\n * **When to throw:**\n * - Business rule violations (e.g., \"Cannot withdraw more than balance\")\n * - Invariant violations (e.g., \"Email format invalid\")\n * - Aggregate consistency failures\n *\n * **Child classes:**\n * - {@link InvariantViolationError} - Value object or entity invariant failures\n * - {@link PartialLoadError} - Incomplete aggregate reconstitution\n *\n * @example\n * ```typescript\n * if (account.balance < amount) {\n * throw new DomainError({\n * message: 'Insufficient funds for withdrawal',\n * code: 'INSUFFICIENT_FUNDS',\n * });\n * }\n * ```\n */\nexport class DomainError extends CodedError {\n /**\n * Creates a new DomainError instance.\n *\n * @param options - Error configuration\n * @param options.message - Human-readable error description\n * @param options.code - Machine-readable error code (default: 'DOMAIN_ERROR')\n * @param options.cause - Optional underlying error\n */\n constructor({\n message,\n code = ErrorCodes.Domain.DOMAIN_ERROR,\n cause,\n }: {\n message: string;\n code?: DomainErrorCode | string;\n cause?: unknown;\n }) {\n super({ message, code, cause });\n }\n\n /**\n * Creates a DomainError from a caught error.\n *\n * @param cause - The original caught error\n * @returns A new DomainError instance with the cause attached\n */\n static override fromError(cause: unknown): DomainError {\n return new DomainError({\n message: cause instanceof Error ? cause.message : 'Domain error',\n cause,\n });\n }\n}\n"],"mappings":";;;;;;AA6BO,IAAM,cAAN,MAAM,qBAAoB,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS1C,YAAY;AAAA,IACV;AAAA,IACA,OAAO,WAAW,OAAO;AAAA,IACzB;AAAA,EACF,GAIG;AACD,UAAM,EAAE,SAAS,MAAM,MAAM,CAAC;AAAA,EAChC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,OAAgB,UAAU,OAA6B;AACrD,WAAO,IAAI,aAAY;AAAA,MACrB,SAAS,iBAAiB,QAAQ,MAAM,UAAU;AAAA,MAClD;AAAA,IACF,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base controller interface for the presentation layer.
|
|
3
|
+
*
|
|
4
|
+
* All controllers must implement this interface. The {@link BaseController} class
|
|
5
|
+
* provides a standard request/response pipeline implementation.
|
|
6
|
+
*
|
|
7
|
+
* @typeParam TInput - The input type the controller accepts
|
|
8
|
+
* @typeParam TOutput - The output type the controller returns
|
|
9
|
+
*
|
|
10
|
+
* @example Using BaseController (recommended)
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const controller = BaseController.create({
|
|
13
|
+
* requestMapper: (req) => CreateUserInputDto.create(req.body),
|
|
14
|
+
* useCase: createUserUseCase,
|
|
15
|
+
* responseMapper: (output) => ({ statusCode: 201, body: output.value }),
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @example Custom implementation
|
|
20
|
+
* ```typescript
|
|
21
|
+
* class MyController implements Controller<MyInput, MyOutput> {
|
|
22
|
+
* async execute(input: MyInput): Promise<MyOutput> {
|
|
23
|
+
* // custom logic
|
|
24
|
+
* }
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
interface Controller<TInput = unknown, TOutput = unknown> {
|
|
29
|
+
/**
|
|
30
|
+
* Executes the controller with the given input.
|
|
31
|
+
*
|
|
32
|
+
* @param input - The input to process
|
|
33
|
+
* @returns Promise resolving to the output
|
|
34
|
+
*/
|
|
35
|
+
execute(input: TInput): Promise<TOutput>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Basic HTTP request structure for any HTTP-based framework.
|
|
40
|
+
*
|
|
41
|
+
* This is the foundation type representing the data extracted from an HTTP request.
|
|
42
|
+
* Frameworks (AWS API Gateway, Cloudflare Workers, Express, etc.) map their native
|
|
43
|
+
* request types to this common interface.
|
|
44
|
+
*
|
|
45
|
+
* @example Complete request
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const request: HttpRequest = {
|
|
48
|
+
* body: { name: 'John', email: 'john@example.com' },
|
|
49
|
+
* headers: { 'content-type': 'application/json', 'authorization': 'Bearer ...' },
|
|
50
|
+
* pathParams: { id: '123' },
|
|
51
|
+
* queryParams: { include: 'profile' },
|
|
52
|
+
* };
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
interface HttpRequest {
|
|
56
|
+
/**
|
|
57
|
+
* Parsed request body.
|
|
58
|
+
* For JSON requests, this is the deserialized object.
|
|
59
|
+
* For form data, this contains the parsed form fields.
|
|
60
|
+
*/
|
|
61
|
+
body?: unknown;
|
|
62
|
+
/**
|
|
63
|
+
* HTTP request headers (normalized to lowercase keys).
|
|
64
|
+
* Common headers include authorization, content-type, accept, etc.
|
|
65
|
+
*/
|
|
66
|
+
headers?: Record<string, string>;
|
|
67
|
+
/**
|
|
68
|
+
* Query string parameters from the URL.
|
|
69
|
+
* For `/users?page=1&limit=10`, this would be `{ page: '1', limit: '10' }`.
|
|
70
|
+
* When a key appears multiple times (e.g., `?tag=a&tag=b`), the value is an array.
|
|
71
|
+
*/
|
|
72
|
+
queryParams?: Record<string, string | string[]>;
|
|
73
|
+
/**
|
|
74
|
+
* Path parameters extracted from the URL pattern.
|
|
75
|
+
* For route `/users/:id` and URL `/users/123`, this would be `{ id: '123' }`.
|
|
76
|
+
*/
|
|
77
|
+
pathParams?: Record<string, string>;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Basic HTTP response structure for any HTTP-based framework.
|
|
82
|
+
*
|
|
83
|
+
* This is the foundation type representing the data to send as an HTTP response.
|
|
84
|
+
* Frameworks (AWS API Gateway, Cloudflare Workers, Express, etc.) map this common
|
|
85
|
+
* interface to their native response types.
|
|
86
|
+
*
|
|
87
|
+
* @example Success response
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const response: HttpResponse = {
|
|
90
|
+
* statusCode: 200,
|
|
91
|
+
* body: { id: '123', name: 'John' },
|
|
92
|
+
* };
|
|
93
|
+
* ```
|
|
94
|
+
*
|
|
95
|
+
* @example Response with headers
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const response: HttpResponse = {
|
|
98
|
+
* statusCode: 201,
|
|
99
|
+
* headers: {
|
|
100
|
+
* 'Location': '/users/123',
|
|
101
|
+
* 'X-Request-Id': 'req-abc',
|
|
102
|
+
* },
|
|
103
|
+
* body: { id: '123' },
|
|
104
|
+
* };
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
interface HttpResponse {
|
|
108
|
+
/**
|
|
109
|
+
* HTTP status code (e.g., 200, 201, 400, 404, 500).
|
|
110
|
+
*/
|
|
111
|
+
statusCode: number;
|
|
112
|
+
/**
|
|
113
|
+
* Optional response headers.
|
|
114
|
+
* Common headers include Content-Type, Location, Cache-Control, etc.
|
|
115
|
+
*/
|
|
116
|
+
headers?: Record<string, unknown>;
|
|
117
|
+
/**
|
|
118
|
+
* Optional response body.
|
|
119
|
+
* Will be serialized to JSON by framework adapters if it's an object.
|
|
120
|
+
*/
|
|
121
|
+
body?: unknown;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export type { Controller as C, HttpRequest as H, HttpResponse as a };
|