ddd-node 15.0.0 → 15.0.1

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.
@@ -7,7 +7,8 @@ export interface EnumProps {
7
7
  }
8
8
  export declare class EnumBase extends ModelBase<EnumProps> {
9
9
  static values(): EnumBase[];
10
- static parse<T extends EnumBase>(this: EnumClass<T>, providedValue: EnumValue): T | undefined;
10
+ static parseSafe<T extends EnumBase>(this: EnumClass<T>, providedValue: EnumValue): T | undefined;
11
+ static parse<T extends EnumBase>(this: EnumClass<T>, providedValue: EnumValue): T;
11
12
  constructor(value: EnumValue);
12
13
  props(): EnumProps;
13
14
  get value(): EnumValue;
package/dist/core/enum.js CHANGED
@@ -3,7 +3,7 @@ export class EnumBase extends ModelBase {
3
3
  static values() {
4
4
  return Array.from(this.ownStaticValues().values()).map((staticValue) => staticValue.value);
5
5
  }
6
- static parse(providedValue) {
6
+ static parseSafe(providedValue) {
7
7
  let key;
8
8
  this.ownStaticValues().forEach((staticValue, staticValueKey) => {
9
9
  if (staticValue.value instanceof this) {
@@ -17,6 +17,12 @@ export class EnumBase extends ModelBase {
17
17
  return this.ownStaticValues().get(key)?.value;
18
18
  return undefined;
19
19
  }
20
+ static parse(providedValue) {
21
+ const parsedEnum = this.parseSafe(providedValue);
22
+ if (!parsedEnum)
23
+ throw new Error(`Invalid provided value for enum ${this.modelName()}`);
24
+ return parsedEnum;
25
+ }
20
26
  constructor(value) {
21
27
  super();
22
28
  this.initializeProps({ value });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ddd-node",
3
- "version": "15.0.0",
3
+ "version": "15.0.1",
4
4
  "type": "module",
5
5
  "description": "Domain Driven Design base for NodeJs",
6
6
  "main": "dist/index.js",