@vytches/ddd-value-objects 0.29.3 → 0.31.0-alpha.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/base-value-object.d.ts +46 -0
- package/dist/id.value-object.d.ts +1 -50
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +83 -113
- package/package.json +7 -6
|
@@ -3,10 +3,41 @@ export interface ValueObjectValidator<T> {
|
|
|
3
3
|
}
|
|
4
4
|
export declare abstract class BaseValueObject<T> implements ValueObjectValidator<T> {
|
|
5
5
|
protected readonly value: T;
|
|
6
|
+
/**
|
|
7
|
+
* VF-023 (D-1, AC1, BREAKING): validates `value` via the polymorphic
|
|
8
|
+
* `validate()` hook and throws synchronously on failure. This replaces
|
|
9
|
+
* the previous convention where every subclass repeated
|
|
10
|
+
* `if (!this.validate(value)) throw ...` in its own constructor after
|
|
11
|
+
* `super(value)` — that boilerplate is now centralized here and enforced
|
|
12
|
+
* for ALL subclasses, including any that previously forgot it.
|
|
13
|
+
*
|
|
14
|
+
* MIGRATION NOTE (undefined-during-super() trap): `validate()` is called
|
|
15
|
+
* via prototype dispatch from *this* base constructor, i.e. before the
|
|
16
|
+
* subclass constructor body (and therefore any subclass field
|
|
17
|
+
* initializers declared after `super(value)`) has run. A `validate()`
|
|
18
|
+
* override that reads `this.someOtherField` set up elsewhere in the
|
|
19
|
+
* subclass constructor will see `undefined` for that field. Overrides
|
|
20
|
+
* must only depend on the `value` parameter passed in, not on
|
|
21
|
+
* subclass instance state. Existing subclasses that already call
|
|
22
|
+
* `this.validate(value)` redundantly after `super(value)` are
|
|
23
|
+
* unaffected — the base class throws first, before that redundant call
|
|
24
|
+
* is ever reached.
|
|
25
|
+
*/
|
|
6
26
|
constructor(value: T);
|
|
7
27
|
/**
|
|
8
28
|
* Compares this value object with another for equality.
|
|
9
29
|
* Uses deep structural comparison for object values, === for primitives.
|
|
30
|
+
*
|
|
31
|
+
* VF-023 (D-3, AC2/AC3, BREAKING): deep comparison now uses
|
|
32
|
+
* `LibUtils.deepEqual` instead of `JSON.stringify` equality. This fixes
|
|
33
|
+
* false negatives/positives inherent to JSON-based comparison — key
|
|
34
|
+
* order sensitivity is gone (already true before, since JSON.stringify
|
|
35
|
+
* of plain objects is insertion-order, not truly key-order-independent
|
|
36
|
+
* in all engines), values like `undefined`, `Date`, `Map`, `Set`, and
|
|
37
|
+
* `NaN` inside nested structures now compare by actual value semantics
|
|
38
|
+
* instead of silently dropping (`undefined`) or losing type
|
|
39
|
+
* (`Date`/`Map`/`Set` stringify to structurally different, sometimes
|
|
40
|
+
* colliding, JSON shapes).
|
|
10
41
|
* @param valueObject - The value object to compare with
|
|
11
42
|
* @returns True if they are equal, false otherwise
|
|
12
43
|
*/
|
|
@@ -32,4 +63,19 @@ export declare abstract class BaseValueObject<T> implements ValueObjectValidator
|
|
|
32
63
|
* @returns True if valid, false otherwise
|
|
33
64
|
*/
|
|
34
65
|
abstract validate(value: unknown): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* VF-023 (D-1 regression fix): produces the message used when the
|
|
68
|
+
* constructor's synchronous `validate()` call fails. Because the base
|
|
69
|
+
* constructor now throws BEFORE the subclass constructor body runs (see
|
|
70
|
+
* the class-level doc comment), a subclass can no longer rely on its own
|
|
71
|
+
* post-`super(value)` `throw new Error('...')` — that code is
|
|
72
|
+
* unreachable, since the base class has already thrown by the time
|
|
73
|
+
* control would return to the subclass. Override this hook instead to
|
|
74
|
+
* provide a validation-error message specific to the subclass. Only
|
|
75
|
+
* `value` (the parameter, not subclass instance state — see the
|
|
76
|
+
* undefined-during-super() trap note above) is safe to use here.
|
|
77
|
+
* @param value The value that failed validation
|
|
78
|
+
* @returns The message to use for the thrown `Error`
|
|
79
|
+
*/
|
|
80
|
+
protected getInvalidValueMessage(value: T): string;
|
|
35
81
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityId as BaseEntityId,
|
|
1
|
+
import { EntityId as BaseEntityId, IdType } from '@vytches/ddd-contracts';
|
|
2
2
|
import { Result } from '@vytches/ddd-utils';
|
|
3
3
|
export declare class EntityId<T = string> extends BaseEntityId<T> {
|
|
4
4
|
constructor(value: T, type: IdType);
|
|
@@ -55,52 +55,3 @@ export declare class EntityId<T = string> extends BaseEntityId<T> {
|
|
|
55
55
|
*/
|
|
56
56
|
static tryFromText(value: string): Result<EntityId<string>, Error>;
|
|
57
57
|
}
|
|
58
|
-
/**
|
|
59
|
-
* @deprecated Use EntityId static methods directly instead. This class will be removed in the next major version.
|
|
60
|
-
* @example
|
|
61
|
-
* ```typescript
|
|
62
|
-
* // Before (deprecated):
|
|
63
|
-
* const id = EntityIdFactory.createWithRandomUUID();
|
|
64
|
-
*
|
|
65
|
-
* // After (recommended):
|
|
66
|
-
* const id = EntityId.create();
|
|
67
|
-
* ```
|
|
68
|
-
*/
|
|
69
|
-
export declare class EntityIdFactory implements IEntityIdFactory {
|
|
70
|
-
/**
|
|
71
|
-
* @deprecated Use EntityId.create() instead. Will be removed in v1.0.0.
|
|
72
|
-
*/
|
|
73
|
-
static createWithRandomUUID(): EntityId<string>;
|
|
74
|
-
/**
|
|
75
|
-
* @deprecated Use EntityId.fromUUID() instead. Will be removed in v1.0.0.
|
|
76
|
-
* @throws {MissingValueError} if value is empty
|
|
77
|
-
* @throws {InvalidParameterError} if value is empty
|
|
78
|
-
*/
|
|
79
|
-
static fromUUID(value: string): EntityId<string>;
|
|
80
|
-
/**
|
|
81
|
-
* @deprecated Use EntityId.fromInteger() instead. Will be removed in v1.0.0.
|
|
82
|
-
* @throws {InvalidParameterError} if value is empty
|
|
83
|
-
*/
|
|
84
|
-
static fromInteger(value: number): EntityId<string>;
|
|
85
|
-
/**
|
|
86
|
-
* @deprecated Use EntityId.fromBigInt() instead. Will be removed in v1.0.0.
|
|
87
|
-
* @throws {InvalidParameterError} if value is empty
|
|
88
|
-
*/
|
|
89
|
-
static fromBigInt(value: string | bigint): EntityId<string>;
|
|
90
|
-
/**
|
|
91
|
-
* @deprecated Use EntityId.fromText() instead. Will be removed in v1.0.0.
|
|
92
|
-
* @throws {MissingValueError} if value is empty
|
|
93
|
-
* @throws {InvalidParameterError} if value is empty
|
|
94
|
-
*/
|
|
95
|
-
static fromText(value: string): EntityId<string>;
|
|
96
|
-
/** @deprecated Use EntityId.create() instead */
|
|
97
|
-
createWithRandomUUID(): EntityId<string>;
|
|
98
|
-
/** @deprecated Use EntityId.fromUUID() instead */
|
|
99
|
-
fromUUID(value: string): EntityId<string>;
|
|
100
|
-
/** @deprecated Use EntityId.fromInteger() instead */
|
|
101
|
-
fromInteger(value: number): EntityId<string>;
|
|
102
|
-
/** @deprecated Use EntityId.fromBigInt() instead */
|
|
103
|
-
fromBigInt(value: string | bigint): EntityId<string>;
|
|
104
|
-
/** @deprecated Use EntityId.fromText() instead */
|
|
105
|
-
fromText(value: string): EntityId<string>;
|
|
106
|
-
}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@vytches/ddd-utils"),s=require("@vytches/ddd-contracts"),r=require("@vytches/ddd-domain-primitives");class l{constructor(t){if(this.value=t!==null&&typeof t=="object"?e.LibUtils.deepFreeze(t):t,!this.validate(this.value))throw new Error(this.getInvalidValueMessage(this.value))}equals(t){return t?this.value===t.value?!0:typeof this.value=="object"&&this.value!==null?e.LibUtils.deepEqual(this.value,t.value):!1:!1}toString(){return String(this.value)}toJSON(){return this.value}getValue(){return this.value}getInvalidValueMessage(t){return`Invalid value for ${this.constructor.name}`}}class i extends s.EntityId{constructor(t,n){super(t,n)}validate(t){switch(this.getType()){case"uuid":return e.LibUtils.isValidUUID(t);case"integer":return e.LibUtils.isValidInteger(t);case"bigint":return e.LibUtils.isValidBigInt(t);case"text":return e.LibUtils.isValidTextId(t);default:throw new r.InvalidParameterError(`Unsupported IdType: ${this.getType()}`)}}static create(){return new i(e.LibUtils.getUUID(),"uuid")}static createWithRandomUUID(){return i.create()}static fromUUID(t){if(!e.LibUtils.hasValue(t))throw r.MissingValueError.withValue("entity identifier");if(!e.LibUtils.isValidUUID(t))throw r.InvalidParameterError.withParameter("entity identifier");return new i(t,"uuid")}static fromInteger(t){if(!e.LibUtils.isValidInteger(t))throw r.InvalidParameterError.withParameter("entity identifier must be a non-negative integer");return new i(t.toString(),"integer")}static fromBigInt(t){const n=e.LibUtils.normalizeIdToString(t);if(!e.LibUtils.isValidBigInt(n))throw r.InvalidParameterError.withParameter("entity identifier must be a valid bigint");return new i(n,"bigint")}static fromText(t){if(!e.LibUtils.hasValue(t))throw r.MissingValueError.withValue("entity identifier");if(!e.LibUtils.isValidTextId(t))throw r.InvalidParameterError.withParameter("entity identifier contains invalid characters");return new i(t,"text")}static tryFromUUID(t){return e.LibUtils.hasValue(t)?e.LibUtils.isValidUUID(t)?e.Result.ok(new i(t,"uuid")):e.Result.fail(r.InvalidParameterError.withParameter("entity identifier")):e.Result.fail(r.MissingValueError.withValue("entity identifier"))}static tryFromInteger(t){return e.LibUtils.isValidInteger(t)?e.Result.ok(new i(t.toString(),"integer")):e.Result.fail(r.InvalidParameterError.withParameter("entity identifier must be a non-negative integer"))}static tryFromBigInt(t){const n=e.LibUtils.normalizeIdToString(t);return e.LibUtils.isValidBigInt(n)?e.Result.ok(new i(n,"bigint")):e.Result.fail(r.InvalidParameterError.withParameter("entity identifier must be a valid bigint"))}static tryFromText(t){return e.LibUtils.hasValue(t)?e.LibUtils.isValidTextId(t)?e.Result.ok(new i(t,"text")):e.Result.fail(r.InvalidParameterError.withParameter("entity identifier contains invalid characters")):e.Result.fail(r.MissingValueError.withValue("entity identifier"))}}function u(a){return a}function d(){return i.create()}function o(a){return i.fromUUID(a)}function f(a){return i.fromText(a)}exports.BaseValueObject=l;exports.EntityId=i;exports.brandedIdFromText=f;exports.brandedIdFromUUID=o;exports.createBrandedId=u;exports.newBrandedId=d;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { BaseValueObject, type ValueObjectValidator } from './base-value-object';
|
|
2
|
-
export { EntityId
|
|
2
|
+
export { EntityId } from './id.value-object';
|
|
3
3
|
export type { BrandedId } from './branded-id';
|
|
4
4
|
export { createBrandedId, newBrandedId, brandedIdFromUUID, brandedIdFromText } from './branded-id';
|
|
5
5
|
export type { IEntityId, IEntityIdFactory, IdType } from '@vytches/ddd-contracts';
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,50 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
class
|
|
1
|
+
import { LibUtils as e, Result as r } from "@vytches/ddd-utils";
|
|
2
|
+
import { EntityId as o } from "@vytches/ddd-contracts";
|
|
3
|
+
import { InvalidParameterError as n, MissingValueError as u } from "@vytches/ddd-domain-primitives";
|
|
4
|
+
class h {
|
|
5
|
+
/**
|
|
6
|
+
* VF-023 (D-1, AC1, BREAKING): validates `value` via the polymorphic
|
|
7
|
+
* `validate()` hook and throws synchronously on failure. This replaces
|
|
8
|
+
* the previous convention where every subclass repeated
|
|
9
|
+
* `if (!this.validate(value)) throw ...` in its own constructor after
|
|
10
|
+
* `super(value)` — that boilerplate is now centralized here and enforced
|
|
11
|
+
* for ALL subclasses, including any that previously forgot it.
|
|
12
|
+
*
|
|
13
|
+
* MIGRATION NOTE (undefined-during-super() trap): `validate()` is called
|
|
14
|
+
* via prototype dispatch from *this* base constructor, i.e. before the
|
|
15
|
+
* subclass constructor body (and therefore any subclass field
|
|
16
|
+
* initializers declared after `super(value)`) has run. A `validate()`
|
|
17
|
+
* override that reads `this.someOtherField` set up elsewhere in the
|
|
18
|
+
* subclass constructor will see `undefined` for that field. Overrides
|
|
19
|
+
* must only depend on the `value` parameter passed in, not on
|
|
20
|
+
* subclass instance state. Existing subclasses that already call
|
|
21
|
+
* `this.validate(value)` redundantly after `super(value)` are
|
|
22
|
+
* unaffected — the base class throws first, before that redundant call
|
|
23
|
+
* is ever reached.
|
|
24
|
+
*/
|
|
5
25
|
constructor(t) {
|
|
6
|
-
t !== null && typeof t == "object" ?
|
|
26
|
+
if (this.value = t !== null && typeof t == "object" ? e.deepFreeze(t) : t, !this.validate(this.value))
|
|
27
|
+
throw new Error(this.getInvalidValueMessage(this.value));
|
|
7
28
|
}
|
|
8
29
|
/**
|
|
9
30
|
* Compares this value object with another for equality.
|
|
10
31
|
* Uses deep structural comparison for object values, === for primitives.
|
|
32
|
+
*
|
|
33
|
+
* VF-023 (D-3, AC2/AC3, BREAKING): deep comparison now uses
|
|
34
|
+
* `LibUtils.deepEqual` instead of `JSON.stringify` equality. This fixes
|
|
35
|
+
* false negatives/positives inherent to JSON-based comparison — key
|
|
36
|
+
* order sensitivity is gone (already true before, since JSON.stringify
|
|
37
|
+
* of plain objects is insertion-order, not truly key-order-independent
|
|
38
|
+
* in all engines), values like `undefined`, `Date`, `Map`, `Set`, and
|
|
39
|
+
* `NaN` inside nested structures now compare by actual value semantics
|
|
40
|
+
* instead of silently dropping (`undefined`) or losing type
|
|
41
|
+
* (`Date`/`Map`/`Set` stringify to structurally different, sometimes
|
|
42
|
+
* colliding, JSON shapes).
|
|
11
43
|
* @param valueObject - The value object to compare with
|
|
12
44
|
* @returns True if they are equal, false otherwise
|
|
13
45
|
*/
|
|
14
46
|
equals(t) {
|
|
15
|
-
return t ? this.value === t.value ? !0 : typeof this.value == "object" && this.value !== null ?
|
|
47
|
+
return t ? this.value === t.value ? !0 : typeof this.value == "object" && this.value !== null ? e.deepEqual(this.value, t.value) : !1 : !1;
|
|
16
48
|
}
|
|
17
49
|
/**
|
|
18
50
|
* Returns a string representation of the value object
|
|
@@ -35,14 +67,25 @@ class l {
|
|
|
35
67
|
getValue() {
|
|
36
68
|
return this.value;
|
|
37
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* VF-023 (D-1 regression fix): produces the message used when the
|
|
72
|
+
* constructor's synchronous `validate()` call fails. Because the base
|
|
73
|
+
* constructor now throws BEFORE the subclass constructor body runs (see
|
|
74
|
+
* the class-level doc comment), a subclass can no longer rely on its own
|
|
75
|
+
* post-`super(value)` `throw new Error('...')` — that code is
|
|
76
|
+
* unreachable, since the base class has already thrown by the time
|
|
77
|
+
* control would return to the subclass. Override this hook instead to
|
|
78
|
+
* provide a validation-error message specific to the subclass. Only
|
|
79
|
+
* `value` (the parameter, not subclass instance state — see the
|
|
80
|
+
* undefined-during-super() trap note above) is safe to use here.
|
|
81
|
+
* @param value The value that failed validation
|
|
82
|
+
* @returns The message to use for the thrown `Error`
|
|
83
|
+
*/
|
|
84
|
+
getInvalidValueMessage(t) {
|
|
85
|
+
return `Invalid value for ${this.constructor.name}`;
|
|
86
|
+
}
|
|
38
87
|
}
|
|
39
|
-
|
|
40
|
-
function f(n, t) {
|
|
41
|
-
u.has(n) || (u.add(n), console.warn(
|
|
42
|
-
`[@vytches/ddd-value-objects] EntityIdFactory.${n}() is deprecated and will be removed in v1.0.0. Use ${t} instead. See https://github.com/vytches/ddd/blob/main/CHANGELOG.md for migration details.`
|
|
43
|
-
));
|
|
44
|
-
}
|
|
45
|
-
class i extends m {
|
|
88
|
+
class i extends o {
|
|
46
89
|
constructor(t, a) {
|
|
47
90
|
super(t, a);
|
|
48
91
|
}
|
|
@@ -57,7 +100,7 @@ class i extends m {
|
|
|
57
100
|
case "text":
|
|
58
101
|
return e.isValidTextId(t);
|
|
59
102
|
default:
|
|
60
|
-
throw new
|
|
103
|
+
throw new n(`Unsupported IdType: ${this.getType()}`);
|
|
61
104
|
}
|
|
62
105
|
}
|
|
63
106
|
/**
|
|
@@ -85,27 +128,27 @@ class i extends m {
|
|
|
85
128
|
*/
|
|
86
129
|
static fromUUID(t) {
|
|
87
130
|
if (!e.hasValue(t))
|
|
88
|
-
throw
|
|
131
|
+
throw u.withValue("entity identifier");
|
|
89
132
|
if (!e.isValidUUID(t))
|
|
90
|
-
throw
|
|
133
|
+
throw n.withParameter("entity identifier");
|
|
91
134
|
return new i(t, "uuid");
|
|
92
135
|
}
|
|
93
136
|
static fromInteger(t) {
|
|
94
137
|
if (!e.isValidInteger(t))
|
|
95
|
-
throw
|
|
138
|
+
throw n.withParameter("entity identifier must be a non-negative integer");
|
|
96
139
|
return new i(t.toString(), "integer");
|
|
97
140
|
}
|
|
98
141
|
static fromBigInt(t) {
|
|
99
142
|
const a = e.normalizeIdToString(t);
|
|
100
143
|
if (!e.isValidBigInt(a))
|
|
101
|
-
throw
|
|
144
|
+
throw n.withParameter("entity identifier must be a valid bigint");
|
|
102
145
|
return new i(a, "bigint");
|
|
103
146
|
}
|
|
104
147
|
static fromText(t) {
|
|
105
148
|
if (!e.hasValue(t))
|
|
106
|
-
throw
|
|
149
|
+
throw u.withValue("entity identifier");
|
|
107
150
|
if (!e.isValidTextId(t))
|
|
108
|
-
throw
|
|
151
|
+
throw n.withParameter("entity identifier contains invalid characters");
|
|
109
152
|
return new i(t, "text");
|
|
110
153
|
}
|
|
111
154
|
// --- Result-returning factory methods (non-throwing) ---
|
|
@@ -116,7 +159,7 @@ class i extends m {
|
|
|
116
159
|
* @since 0.24.0
|
|
117
160
|
*/
|
|
118
161
|
static tryFromUUID(t) {
|
|
119
|
-
return e.hasValue(t) ? e.isValidUUID(t) ?
|
|
162
|
+
return e.hasValue(t) ? e.isValidUUID(t) ? r.ok(new i(t, "uuid")) : r.fail(n.withParameter("entity identifier")) : r.fail(u.withValue("entity identifier"));
|
|
120
163
|
}
|
|
121
164
|
/**
|
|
122
165
|
* Create EntityId from integer, returning Result instead of throwing.
|
|
@@ -125,8 +168,8 @@ class i extends m {
|
|
|
125
168
|
* @since 0.24.0
|
|
126
169
|
*/
|
|
127
170
|
static tryFromInteger(t) {
|
|
128
|
-
return e.isValidInteger(t) ?
|
|
129
|
-
|
|
171
|
+
return e.isValidInteger(t) ? r.ok(new i(t.toString(), "integer")) : r.fail(
|
|
172
|
+
n.withParameter("entity identifier must be a non-negative integer")
|
|
130
173
|
);
|
|
131
174
|
}
|
|
132
175
|
/**
|
|
@@ -137,8 +180,8 @@ class i extends m {
|
|
|
137
180
|
*/
|
|
138
181
|
static tryFromBigInt(t) {
|
|
139
182
|
const a = e.normalizeIdToString(t);
|
|
140
|
-
return e.isValidBigInt(a) ?
|
|
141
|
-
|
|
183
|
+
return e.isValidBigInt(a) ? r.ok(new i(a, "bigint")) : r.fail(
|
|
184
|
+
n.withParameter("entity identifier must be a valid bigint")
|
|
142
185
|
);
|
|
143
186
|
}
|
|
144
187
|
/**
|
|
@@ -148,101 +191,28 @@ class i extends m {
|
|
|
148
191
|
* @since 0.24.0
|
|
149
192
|
*/
|
|
150
193
|
static tryFromText(t) {
|
|
151
|
-
return e.hasValue(t) ? e.isValidTextId(t) ?
|
|
152
|
-
|
|
153
|
-
) :
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
class d {
|
|
157
|
-
/**
|
|
158
|
-
* @deprecated Use EntityId.create() instead. Will be removed in v1.0.0.
|
|
159
|
-
*/
|
|
160
|
-
static createWithRandomUUID() {
|
|
161
|
-
return f("createWithRandomUUID", "EntityId.create()"), i.create();
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* @deprecated Use EntityId.fromUUID() instead. Will be removed in v1.0.0.
|
|
165
|
-
* @throws {MissingValueError} if value is empty
|
|
166
|
-
* @throws {InvalidParameterError} if value is empty
|
|
167
|
-
*/
|
|
168
|
-
static fromUUID(t) {
|
|
169
|
-
if (f("fromUUID", "EntityId.fromUUID()"), !e.hasValue(t))
|
|
170
|
-
throw o.withValue("entity identifier");
|
|
171
|
-
if (!e.isValidUUID(t))
|
|
172
|
-
throw r.withParameter("entity identifier");
|
|
173
|
-
return new i(t, "uuid");
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* @deprecated Use EntityId.fromInteger() instead. Will be removed in v1.0.0.
|
|
177
|
-
* @throws {InvalidParameterError} if value is empty
|
|
178
|
-
*/
|
|
179
|
-
static fromInteger(t) {
|
|
180
|
-
if (f("fromInteger", "EntityId.fromInteger()"), !e.isValidInteger(t))
|
|
181
|
-
throw r.withParameter("entity identifier must be a non-negative integer");
|
|
182
|
-
return new i(t.toString(), "integer");
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* @deprecated Use EntityId.fromBigInt() instead. Will be removed in v1.0.0.
|
|
186
|
-
* @throws {InvalidParameterError} if value is empty
|
|
187
|
-
*/
|
|
188
|
-
static fromBigInt(t) {
|
|
189
|
-
f("fromBigInt", "EntityId.fromBigInt()");
|
|
190
|
-
const a = e.normalizeIdToString(t);
|
|
191
|
-
if (!e.isValidBigInt(a))
|
|
192
|
-
throw r.withParameter("entity identifier must be a valid bigint");
|
|
193
|
-
return new i(a, "bigint");
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* @deprecated Use EntityId.fromText() instead. Will be removed in v1.0.0.
|
|
197
|
-
* @throws {MissingValueError} if value is empty
|
|
198
|
-
* @throws {InvalidParameterError} if value is empty
|
|
199
|
-
*/
|
|
200
|
-
static fromText(t) {
|
|
201
|
-
if (f("fromText", "EntityId.fromText()"), !e.hasValue(t))
|
|
202
|
-
throw o.withValue("entity identifier");
|
|
203
|
-
if (!e.isValidTextId(t))
|
|
204
|
-
throw r.withParameter("entity identifier contains invalid characters");
|
|
205
|
-
return new i(t, "text");
|
|
206
|
-
}
|
|
207
|
-
/** @deprecated Use EntityId.create() instead */
|
|
208
|
-
createWithRandomUUID() {
|
|
209
|
-
return i.create();
|
|
210
|
-
}
|
|
211
|
-
/** @deprecated Use EntityId.fromUUID() instead */
|
|
212
|
-
fromUUID(t) {
|
|
213
|
-
return d.fromUUID(t);
|
|
214
|
-
}
|
|
215
|
-
/** @deprecated Use EntityId.fromInteger() instead */
|
|
216
|
-
fromInteger(t) {
|
|
217
|
-
return d.fromInteger(t);
|
|
218
|
-
}
|
|
219
|
-
/** @deprecated Use EntityId.fromBigInt() instead */
|
|
220
|
-
fromBigInt(t) {
|
|
221
|
-
return d.fromBigInt(t);
|
|
222
|
-
}
|
|
223
|
-
/** @deprecated Use EntityId.fromText() instead */
|
|
224
|
-
fromText(t) {
|
|
225
|
-
return d.fromText(t);
|
|
194
|
+
return e.hasValue(t) ? e.isValidTextId(t) ? r.ok(new i(t, "text")) : r.fail(
|
|
195
|
+
n.withParameter("entity identifier contains invalid characters")
|
|
196
|
+
) : r.fail(u.withValue("entity identifier"));
|
|
226
197
|
}
|
|
227
198
|
}
|
|
228
|
-
function
|
|
229
|
-
return
|
|
199
|
+
function c(s) {
|
|
200
|
+
return s;
|
|
230
201
|
}
|
|
231
|
-
function
|
|
202
|
+
function g() {
|
|
232
203
|
return i.create();
|
|
233
204
|
}
|
|
234
|
-
function
|
|
235
|
-
return i.fromUUID(
|
|
205
|
+
function m(s) {
|
|
206
|
+
return i.fromUUID(s);
|
|
236
207
|
}
|
|
237
|
-
function
|
|
238
|
-
return i.fromText(
|
|
208
|
+
function w(s) {
|
|
209
|
+
return i.fromText(s);
|
|
239
210
|
}
|
|
240
211
|
export {
|
|
241
|
-
|
|
212
|
+
h as BaseValueObject,
|
|
242
213
|
i as EntityId,
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
I as newBrandedId
|
|
214
|
+
w as brandedIdFromText,
|
|
215
|
+
m as brandedIdFromUUID,
|
|
216
|
+
c as createBrandedId,
|
|
217
|
+
g as newBrandedId
|
|
248
218
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vytches/ddd-value-objects",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0-alpha.0",
|
|
4
4
|
"description": "Enhanced value objects and EntityId implementations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"files": [
|
|
18
18
|
"dist",
|
|
19
19
|
"README.md",
|
|
20
|
-
"LLMGUIDE.md"
|
|
20
|
+
"LLMGUIDE.md",
|
|
21
|
+
"LICENSE"
|
|
21
22
|
],
|
|
22
23
|
"keywords": [
|
|
23
24
|
"ddd",
|
|
@@ -33,15 +34,15 @@
|
|
|
33
34
|
"directory": "packages/value-objects"
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"@vytches/ddd-contracts": "0.
|
|
37
|
-
"@vytches/ddd-
|
|
38
|
-
"@vytches/ddd-
|
|
37
|
+
"@vytches/ddd-contracts": "0.31.0-alpha.0",
|
|
38
|
+
"@vytches/ddd-utils": "0.31.0-alpha.0",
|
|
39
|
+
"@vytches/ddd-domain-primitives": "0.31.0-alpha.0"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"typescript": "^5.0.0",
|
|
42
43
|
"vite": "^7.3.2",
|
|
43
44
|
"vite-plugin-dts": "^4.0.0",
|
|
44
|
-
"vitest": "^4.
|
|
45
|
+
"vitest": "^4.1.0"
|
|
45
46
|
},
|
|
46
47
|
"nx": {
|
|
47
48
|
"tags": [
|