@schorts/shared-kernel 4.2.1 → 4.2.3
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/README.md +2 -0
- package/dist/cjs/value-objects/array-value.js +8 -0
- package/dist/cjs/value-objects/array-value.js.map +1 -1
- package/dist/cjs/value-objects/index.js +3 -1
- package/dist/cjs/value-objects/index.js.map +1 -1
- package/dist/cjs/value-objects/object-value.js +2 -0
- package/dist/cjs/value-objects/object-value.js.map +1 -1
- package/dist/cjs/value-objects/url-value.js +23 -0
- package/dist/cjs/value-objects/url-value.js.map +1 -0
- package/dist/esm/value-objects/array-value.js +8 -0
- package/dist/esm/value-objects/array-value.js.map +1 -1
- package/dist/esm/value-objects/index.js +3 -1
- package/dist/esm/value-objects/index.js.map +1 -1
- package/dist/esm/value-objects/object-value.js +2 -0
- package/dist/esm/value-objects/object-value.js.map +1 -1
- package/dist/esm/value-objects/url-value.js +23 -0
- package/dist/esm/value-objects/url-value.js.map +1 -0
- package/dist/types/value-objects/array-value.d.ts +5 -1
- package/dist/types/value-objects/array-value.d.ts.map +1 -1
- package/dist/types/value-objects/index.d.ts +1 -0
- package/dist/types/value-objects/index.d.ts.map +1 -1
- package/dist/types/value-objects/object-value.d.ts +2 -0
- package/dist/types/value-objects/object-value.d.ts.map +1 -1
- package/dist/types/value-objects/url-value.d.ts +11 -0
- package/dist/types/value-objects/url-value.d.ts.map +1 -0
- package/package.json +11 -3
- package/.idx/airules.md +0 -186
- package/.idx/dev.nix +0 -54
- package/.vscode/settings.json +0 -7
- package/CHANGELOG +0 -363
- package/__tests__/auth/auth-provider.test.ts +0 -50
- package/__tests__/auth/require-auth.decorator.test.ts +0 -88
- package/__tests__/criteria/criteria.test.ts +0 -159
- package/__tests__/criteria/direction.test.ts +0 -11
- package/__tests__/criteria/filter-criterion.test.ts +0 -15
- package/__tests__/criteria/operator.test.ts +0 -22
- package/__tests__/criteria/order.test.ts +0 -14
- package/__tests__/dao/dao.test.ts +0 -126
- package/__tests__/domain-events/domain-event-primitives.test.ts +0 -34
- package/__tests__/domain-events/domain-event.test.ts +0 -50
- package/__tests__/entities/entity-registry.test.ts +0 -71
- package/__tests__/entities/entity.test.ts +0 -114
- package/__tests__/entities/register-entity.decorator.test.ts +0 -54
- package/__tests__/formatters/pascal-camel-to-snake.test.ts +0 -19
- package/__tests__/http/fetch-http-provider.test.ts +0 -155
- package/__tests__/http/http-provider.test.ts +0 -55
- package/__tests__/json-api/json-api-connector.test.ts +0 -78
- package/__tests__/json-api/json-api-list.test.ts +0 -24
- package/__tests__/json-api/json-api-single.test.ts +0 -24
- package/__tests__/json-api/url-criteria-builder.test.ts +0 -74
- package/__tests__/messages/message.test.ts +0 -16
- package/__tests__/models/base-model.test.ts +0 -10
- package/__tests__/state-manager/state-manager.test.ts +0 -101
- package/__tests__/unit-of-work/unit-of-work.test.ts +0 -47
- package/__tests__/utils/url/url-with-params-builder.test.ts +0 -39
- package/__tests__/value-objects/coordinates-value.test.ts +0 -68
- package/__tests__/value-objects/email-value.test.ts +0 -43
- package/__tests__/value-objects/enum-value.test.ts +0 -51
- package/__tests__/value-objects/integer-value.test.ts +0 -115
- package/__tests__/value-objects/phone-value.test.ts +0 -82
- package/__tests__/value-objects/slug-value.test.ts +0 -43
- package/__tests__/value-objects/string-value.test.ts +0 -121
- package/__tests__/value-objects/uuid-value.test.ts +0 -67
- package/__tests__/value-objects/value-object.test.ts +0 -25
- package/jest.config.js +0 -25
- package/src/abac/index.ts +0 -1
- package/src/abac/predicate.ts +0 -3
- package/src/auth/auth-provider.ts +0 -11
- package/src/auth/exceptions/index.ts +0 -2
- package/src/auth/exceptions/not-authenticated.ts +0 -11
- package/src/auth/exceptions/require-auth-not-implemented-correctly.ts +0 -11
- package/src/auth/index.ts +0 -3
- package/src/auth/require-auth.decorator.ts +0 -42
- package/src/converters/index.ts +0 -1
- package/src/converters/remote-file-to-base64.ts +0 -19
- package/src/criteria/criteria.ts +0 -46
- package/src/criteria/direction.ts +0 -1
- package/src/criteria/exceptions/index.ts +0 -2
- package/src/criteria/exceptions/limit-not-valid.ts +0 -11
- package/src/criteria/exceptions/offset-not-valid.ts +0 -11
- package/src/criteria/index.ts +0 -5
- package/src/criteria/operator.ts +0 -12
- package/src/criteria/order.ts +0 -4
- package/src/dao/dao.ts +0 -16
- package/src/dao/index.ts +0 -1
- package/src/domain-events/domain-event-primitives.ts +0 -10
- package/src/domain-events/domain-event-registry.ts +0 -40
- package/src/domain-events/domain-event.ts +0 -29
- package/src/domain-events/exceptions/domain-event-not-registered.ts +0 -11
- package/src/domain-events/exceptions/index.ts +0 -1
- package/src/domain-events/index.ts +0 -4
- package/src/entities/entity-registry.ts +0 -30
- package/src/entities/entity.ts +0 -25
- package/src/entities/exceptions/entity-not-registered.ts +0 -11
- package/src/entities/exceptions/index.ts +0 -1
- package/src/entities/index.ts +0 -4
- package/src/entities/register-entity.decorator.ts +0 -16
- package/src/event-bus/event-store.ts +0 -9
- package/src/event-bus/event-subscriber.ts +0 -5
- package/src/event-bus/in-memory/async-in-memory-event-bus.ts +0 -67
- package/src/event-bus/in-memory/in-memory-event-store.ts +0 -28
- package/src/event-bus/in-memory/index.ts +0 -2
- package/src/event-bus/index.ts +0 -3
- package/src/formatters/index.ts +0 -1
- package/src/formatters/pascal-camel-to-snake.ts +0 -8
- package/src/http/exceptions/http-exception.ts +0 -8
- package/src/http/exceptions/index.ts +0 -1
- package/src/http/fetch-http-provider.ts +0 -151
- package/src/http/http-interceptor.ts +0 -3
- package/src/http/http-provider.ts +0 -7
- package/src/http/index.ts +0 -5
- package/src/i18n/index.ts +0 -2
- package/src/i18n/shared-kernel-translation-keys.ts +0 -19
- package/src/i18n/translation-resolver.ts +0 -3
- package/src/index.ts +0 -21
- package/src/json-api/exceptions/index.ts +0 -1
- package/src/json-api/exceptions/json-api-errors.ts +0 -17
- package/src/json-api/index.ts +0 -5
- package/src/json-api/json-api-connector.ts +0 -97
- package/src/json-api/json-api-list.ts +0 -13
- package/src/json-api/json-api-single.ts +0 -13
- package/src/json-api/url-criteria-builder.ts +0 -49
- package/src/messages/index.ts +0 -1
- package/src/messages/message.ts +0 -3
- package/src/models/base-model.ts +0 -3
- package/src/models/index.ts +0 -1
- package/src/pub-sub/index.ts +0 -2
- package/src/pub-sub/publisher.ts +0 -3
- package/src/pub-sub/subscription.ts +0 -6
- package/src/rbac/base-resource.ts +0 -3
- package/src/rbac/exceptions/index.ts +0 -1
- package/src/rbac/exceptions/not-authorized.ts +0 -1
- package/src/rbac/index.ts +0 -5
- package/src/rbac/permission.ts +0 -4
- package/src/rbac/rbac-policy.ts +0 -41
- package/src/result/index.ts +0 -1
- package/src/result/result.ts +0 -35
- package/src/state-manager/in-memory-state-manager.ts +0 -22
- package/src/state-manager/index.ts +0 -3
- package/src/state-manager/session-storage-state-manager.ts +0 -47
- package/src/state-manager/state-manager.ts +0 -28
- package/src/telemetry/console-telemetry.ts +0 -27
- package/src/telemetry/index.ts +0 -2
- package/src/telemetry/telemetry.ts +0 -5
- package/src/unit-of-work/index.ts +0 -1
- package/src/unit-of-work/unit-of-work.ts +0 -5
- package/src/utils/index.ts +0 -2
- package/src/utils/url/index.ts +0 -1
- package/src/utils/url/url-with-params-builder.ts +0 -19
- package/src/utils/value-objects/index.ts +0 -1
- package/src/utils/value-objects/rule.ts +0 -3
- package/src/value-objects/array-value.ts +0 -92
- package/src/value-objects/boolean-value.ts +0 -23
- package/src/value-objects/coordinates-value.ts +0 -50
- package/src/value-objects/date-value.ts +0 -36
- package/src/value-objects/email-value.ts +0 -25
- package/src/value-objects/enum-value.ts +0 -27
- package/src/value-objects/exceptions/index.ts +0 -2
- package/src/value-objects/exceptions/value-not-valid.ts +0 -3
- package/src/value-objects/exceptions/values-not-valid.ts +0 -11
- package/src/value-objects/float-valuet.ts +0 -39
- package/src/value-objects/index.ts +0 -17
- package/src/value-objects/integer-value.ts +0 -29
- package/src/value-objects/object-value.ts +0 -84
- package/src/value-objects/phone-value.ts +0 -53
- package/src/value-objects/slug-value.ts +0 -25
- package/src/value-objects/string-value.ts +0 -27
- package/src/value-objects/uuid-value.ts +0 -34
- package/src/value-objects/value-object.ts +0 -7
- package/tsconfig.cjs.json +0 -13
- package/tsconfig.esm.json +0 -12
- package/tsconfig.json +0 -47
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { ValueObject } from "./value-object";
|
|
2
|
-
|
|
3
|
-
type DateInput<Required extends boolean> =
|
|
4
|
-
Required extends true ? Date : Date | null;
|
|
5
|
-
|
|
6
|
-
export abstract class DateValue<Required extends boolean = true> implements ValueObject {
|
|
7
|
-
readonly valueType = "Date";
|
|
8
|
-
readonly value: DateInput<Required>;
|
|
9
|
-
readonly beforeDate: Date | undefined;
|
|
10
|
-
readonly afterDate: Date | undefined;
|
|
11
|
-
private readonly optional: boolean;
|
|
12
|
-
|
|
13
|
-
constructor(value: DateInput<Required>, beforeDate?: Date, afterDate?: Date, optional = false) {
|
|
14
|
-
this.value = value;
|
|
15
|
-
this.beforeDate = beforeDate;
|
|
16
|
-
this.afterDate = afterDate;
|
|
17
|
-
this.optional = optional;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
get isValid(): boolean {
|
|
21
|
-
if (!this.value) return this.optional;
|
|
22
|
-
if (this.beforeDate && this.value > this.beforeDate) return false;
|
|
23
|
-
if (this.afterDate && this.value < this.afterDate) return false;
|
|
24
|
-
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
equals(valueObject: unknown): boolean {
|
|
29
|
-
if (!(valueObject instanceof DateValue)) return false;
|
|
30
|
-
if (!this.isValid || !valueObject.isValid) return false;
|
|
31
|
-
|
|
32
|
-
return this.value?.getTime() === valueObject.value?.getTime();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
abstract readonly attributeName: string;
|
|
36
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { ValueObject } from "./";
|
|
2
|
-
|
|
3
|
-
const REGEX = /^([A-Za-z0-9_\-\.])+\@(?!(?:[A-Za-z0-9_\-\.]+\.)?com\.com)([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
|
|
4
|
-
|
|
5
|
-
export abstract class EmailValue implements ValueObject {
|
|
6
|
-
readonly valueType = "Email";
|
|
7
|
-
readonly value: string;
|
|
8
|
-
|
|
9
|
-
constructor(value: string) {
|
|
10
|
-
this.value = value;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
get isValid(): boolean {
|
|
14
|
-
return REGEX.test(this.value);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
equals(valueObject: unknown): boolean {
|
|
18
|
-
if (!(valueObject instanceof EmailValue)) return false;
|
|
19
|
-
if (!this.isValid || !valueObject.isValid) return false;
|
|
20
|
-
|
|
21
|
-
return this.value === valueObject.value;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
abstract readonly attributeName: string;
|
|
25
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ValueObject } from "./value-object";
|
|
2
|
-
|
|
3
|
-
export abstract class EnumValue<Allowed extends readonly (string | null)[]> implements ValueObject {
|
|
4
|
-
readonly valueType = 'Enum';
|
|
5
|
-
readonly allowedValues: Allowed;
|
|
6
|
-
readonly value: Allowed[number];
|
|
7
|
-
|
|
8
|
-
constructor(allowedValues: Allowed, value: Allowed[number]) {
|
|
9
|
-
this.allowedValues = allowedValues;
|
|
10
|
-
this.value = value;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
get isValid(): boolean {
|
|
14
|
-
return this.allowedValues.includes(this.value);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
equals(valueObject: unknown): boolean {
|
|
18
|
-
return (
|
|
19
|
-
valueObject instanceof EnumValue &&
|
|
20
|
-
this.isValid &&
|
|
21
|
-
valueObject.isValid &&
|
|
22
|
-
this.value === valueObject.value
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
abstract readonly attributeName: string;
|
|
27
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { ValueObject } from "./value-object";
|
|
2
|
-
|
|
3
|
-
export abstract class FloatValue implements ValueObject {
|
|
4
|
-
readonly valueType = "Float";
|
|
5
|
-
readonly value: number;
|
|
6
|
-
readonly min: number | undefined;
|
|
7
|
-
readonly max: number | undefined;
|
|
8
|
-
readonly decimals: number | undefined;
|
|
9
|
-
|
|
10
|
-
constructor(value: number, decimals?: number, min?: number, max?: number) {
|
|
11
|
-
this.decimals = decimals;
|
|
12
|
-
this.min = min;
|
|
13
|
-
this.max = max;
|
|
14
|
-
this.value = this.transform(value);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
get isValid(): boolean {
|
|
18
|
-
return !isNaN(this.value)
|
|
19
|
-
&& (this.min !== undefined ? this.value >= this.min : true)
|
|
20
|
-
&& (this.max !== undefined ? this.value <= this.max : true);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
equals(valueObject: unknown): boolean {
|
|
24
|
-
if (!(valueObject instanceof FloatValue)) return false;
|
|
25
|
-
if (!this.isValid || !valueObject.isValid) return false;
|
|
26
|
-
|
|
27
|
-
return this.value === valueObject.value;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
abstract readonly attributeName: string;
|
|
31
|
-
|
|
32
|
-
private transform(value: number): number {
|
|
33
|
-
if (this.decimals === undefined) return value;
|
|
34
|
-
|
|
35
|
-
const factor = Math.pow(10, this.decimals);
|
|
36
|
-
|
|
37
|
-
return Math.round(value * factor) / factor;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export type { ValueObject } from "./value-object";
|
|
2
|
-
|
|
3
|
-
export { UUIDValue } from "./uuid-value";
|
|
4
|
-
export { StringValue } from "./string-value";
|
|
5
|
-
export { EnumValue } from "./enum-value";
|
|
6
|
-
export { EmailValue } from "./email-value";
|
|
7
|
-
export { PhoneValue } from "./phone-value";
|
|
8
|
-
export { SlugValue } from "./slug-value";
|
|
9
|
-
export { IntegerValue } from "./integer-value";
|
|
10
|
-
export { CoordinatesValue } from "./coordinates-value";
|
|
11
|
-
export { BooleanValue } from "./boolean-value";
|
|
12
|
-
export { DateValue } from "./date-value";
|
|
13
|
-
export { FloatValue } from "./float-valuet";
|
|
14
|
-
export { ArrayValue } from "./array-value";
|
|
15
|
-
export { ObjectValue } from "./object-value";
|
|
16
|
-
|
|
17
|
-
export * from "./exceptions";
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { ValueObject } from "./";
|
|
2
|
-
|
|
3
|
-
export abstract class IntegerValue implements ValueObject {
|
|
4
|
-
readonly valueType = "Integer";
|
|
5
|
-
readonly min: number | undefined;
|
|
6
|
-
readonly max: number | undefined;
|
|
7
|
-
readonly value: number;
|
|
8
|
-
|
|
9
|
-
constructor(value: number, min?: number, max?: number) {
|
|
10
|
-
this.min = min;
|
|
11
|
-
this.max = max;
|
|
12
|
-
this.value = value;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
get isValid(): boolean {
|
|
16
|
-
return (this.min !== undefined ? this.value >= this.min : true)
|
|
17
|
-
&& (this.max !== undefined ? this.value <= this.max : true)
|
|
18
|
-
&& Number.isInteger(this.value);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
equals(valueObject: unknown): boolean {
|
|
22
|
-
if (!(valueObject instanceof IntegerValue)) return false;
|
|
23
|
-
if (!this.isValid || !valueObject.isValid) return false;
|
|
24
|
-
|
|
25
|
-
return this.value === valueObject.value;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
abstract readonly attributeName: string;
|
|
29
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { ValueObject } from "./value-object";
|
|
2
|
-
|
|
3
|
-
type Primitive = string | number | boolean | null | undefined;
|
|
4
|
-
|
|
5
|
-
export type ValidationRule<Type> =
|
|
6
|
-
| { required: true }
|
|
7
|
-
| { greater_than: number }
|
|
8
|
-
| { greater_than_or_equal: number }
|
|
9
|
-
| { less_than: number }
|
|
10
|
-
| { less_than_or_equal: number }
|
|
11
|
-
| { type: "string" | "number" | "boolean" }
|
|
12
|
-
| { custom: (value: Type) => boolean };
|
|
13
|
-
|
|
14
|
-
export type ObjectSchema<Type> = {
|
|
15
|
-
[Key in keyof Type]?: Type[Key] extends Primitive
|
|
16
|
-
? ValidationRule<Type[Key]>[]
|
|
17
|
-
: ObjectSchema<Type[Key]>;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export abstract class ObjectValue<Type = any> implements ValueObject {
|
|
21
|
-
readonly valueType = "Object";
|
|
22
|
-
readonly value: Type;
|
|
23
|
-
readonly schema: ObjectSchema<Type>;
|
|
24
|
-
abstract readonly attributeName: string;
|
|
25
|
-
|
|
26
|
-
constructor(value: Type, schema: ObjectSchema<Type>) {
|
|
27
|
-
this.value = this.deepFreeze(value);
|
|
28
|
-
this.schema = schema;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
get isValid(): boolean {
|
|
32
|
-
return this.validateObject(this.value, this.schema);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
equals(valueObject: unknown): boolean {
|
|
36
|
-
if (!(valueObject instanceof ObjectValue)) return false;
|
|
37
|
-
if (!this.isValid || !valueObject.isValid) return false;
|
|
38
|
-
|
|
39
|
-
return JSON.stringify(this.value) === JSON.stringify(valueObject.value);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
private validateObject(obj: any, schema: ObjectSchema<any>): boolean {
|
|
43
|
-
return Object.entries(schema).every(([key, rulesOrNested]) => {
|
|
44
|
-
const value = obj[key];
|
|
45
|
-
|
|
46
|
-
if (Array.isArray(rulesOrNested)) {
|
|
47
|
-
return rulesOrNested.every(rule => this.validateRule(value, rule));
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (typeof rulesOrNested === "object" && value !== null && typeof value === "object") {
|
|
51
|
-
return this.validateObject(value, rulesOrNested as ObjectSchema<any>);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return true;
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
private validateRule(value: any, rule: ValidationRule<any>): boolean {
|
|
59
|
-
if ("required" in rule) return value !== undefined && value !== null;
|
|
60
|
-
if ("greater_than" in rule) return typeof value === "number" && value > rule.greater_than;
|
|
61
|
-
if ("greater_than_or_equal" in rule) return typeof value === "number" && value >= rule.greater_than_or_equal;
|
|
62
|
-
if ("less_than" in rule) return typeof value === "number" && value < rule.less_than;
|
|
63
|
-
if ("less_than_or_equal" in rule) return typeof value === "number" && value <= rule.less_than_or_equal;
|
|
64
|
-
if ("type" in rule) return typeof value === rule.type;
|
|
65
|
-
if ("custom" in rule) return rule.custom(value);
|
|
66
|
-
|
|
67
|
-
return true;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
private deepFreeze<T>(obj: T): T {
|
|
71
|
-
if (Array.isArray(obj)) {
|
|
72
|
-
obj.forEach(item => this.deepFreeze(item));
|
|
73
|
-
} else if (obj && typeof obj === "object") {
|
|
74
|
-
Object.getOwnPropertyNames(obj).forEach(prop => {
|
|
75
|
-
const value = (obj as any)[prop];
|
|
76
|
-
if (value && typeof value === "object") {
|
|
77
|
-
this.deepFreeze(value);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return Object.freeze(obj);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { ValueObject } from "./";
|
|
2
|
-
|
|
3
|
-
const REGEX = /\+(9[976]\d|8[987530]\d|6[987]\d|5[90]\d|42\d|3[875]\d|2[98654321]\d|9[8543210]|8[6421]|6[6543210]|5[87654321]|4[987654310]|3[9643210]|2[70]|7|1)\d{10,12}$/;
|
|
4
|
-
|
|
5
|
-
export abstract class PhoneValue implements ValueObject {
|
|
6
|
-
readonly valueType = "Phone";
|
|
7
|
-
readonly value: string;
|
|
8
|
-
|
|
9
|
-
constructor(value: string) {
|
|
10
|
-
this.value = value;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
get isValid(): boolean {
|
|
14
|
-
return REGEX.test(this.value);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
get countryCode(): string | null {
|
|
18
|
-
if (this.isValid) {
|
|
19
|
-
const countryCodeLength = this.value.length - 10;
|
|
20
|
-
|
|
21
|
-
return this.value.slice(0, countryCodeLength);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
get phoneNumber(): string | null {
|
|
28
|
-
if (this.isValid) {
|
|
29
|
-
return this.value.slice(-10);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
get formattedPhone(): string | null {
|
|
36
|
-
if (this.isValid) {
|
|
37
|
-
const phoneNumber = this.phoneNumber!.replace(/(\d{3})(\d{3})(\d{4})/, "($1) $2-$3");
|
|
38
|
-
|
|
39
|
-
return `${this.countryCode} ${phoneNumber}`;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
equals(valueObject: unknown): boolean {
|
|
46
|
-
if (!(valueObject instanceof PhoneValue)) return false;
|
|
47
|
-
if (!this.isValid || !valueObject.isValid) return false;
|
|
48
|
-
|
|
49
|
-
return this.value === valueObject.value;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
abstract readonly attributeName: string;
|
|
53
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { ValueObject } from "./";
|
|
2
|
-
|
|
3
|
-
const REGEX = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
4
|
-
|
|
5
|
-
export abstract class SlugValue implements ValueObject {
|
|
6
|
-
readonly valueType = "Slug";
|
|
7
|
-
readonly value: string;
|
|
8
|
-
|
|
9
|
-
constructor(value: string) {
|
|
10
|
-
this.value = value;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
get isValid(): boolean {
|
|
14
|
-
return REGEX.test(this.value);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
equals(valueObject: unknown): boolean {
|
|
18
|
-
if (!(valueObject instanceof SlugValue)) return false;
|
|
19
|
-
if (!this.isValid || !valueObject.isValid) return false;
|
|
20
|
-
|
|
21
|
-
return this.value === valueObject.value;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
abstract readonly attributeName: string;
|
|
25
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ValueObject } from "./";
|
|
2
|
-
|
|
3
|
-
export abstract class StringValue implements ValueObject {
|
|
4
|
-
readonly valueType = "String";
|
|
5
|
-
readonly value: string;
|
|
6
|
-
readonly minLength: number;
|
|
7
|
-
readonly maxLength: number | undefined;
|
|
8
|
-
|
|
9
|
-
constructor(value: string, minLength = 0, maxLength?: number) {
|
|
10
|
-
this.value = value;
|
|
11
|
-
this.minLength = minLength;
|
|
12
|
-
this.maxLength = maxLength;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
get isValid(): boolean {
|
|
16
|
-
return this.value.length >= this.minLength && (this.maxLength ? this.value.length <= this.maxLength : true);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
equals(valueObject: unknown): boolean {
|
|
20
|
-
if (!(valueObject instanceof StringValue)) return false;
|
|
21
|
-
if (!this.isValid || !valueObject.isValid) return false;
|
|
22
|
-
|
|
23
|
-
return this.value === valueObject.value;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
abstract readonly attributeName: string;
|
|
27
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { ValueObject } from "./";
|
|
2
|
-
|
|
3
|
-
const REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
4
|
-
|
|
5
|
-
type UUIDInput<Required extends boolean> =
|
|
6
|
-
Required extends true ? string : string | null;
|
|
7
|
-
|
|
8
|
-
export abstract class UUIDValue<Required extends boolean = true> implements ValueObject {
|
|
9
|
-
readonly valueType = "UUID";
|
|
10
|
-
readonly value: UUIDInput<Required>;
|
|
11
|
-
private readonly optional: boolean;
|
|
12
|
-
|
|
13
|
-
constructor(value: UUIDInput<Required>, optional = false) {
|
|
14
|
-
this.value = value;
|
|
15
|
-
this.optional = optional;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
get isValid(): boolean {
|
|
19
|
-
return this.optional
|
|
20
|
-
? this.value
|
|
21
|
-
? REGEX.test(this.value)
|
|
22
|
-
: true
|
|
23
|
-
: REGEX.test(this.value!);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
equals(valueObject: unknown): boolean {
|
|
27
|
-
if (!(valueObject instanceof UUIDValue)) return false;
|
|
28
|
-
if (!this.isValid || !valueObject.isValid) return false;
|
|
29
|
-
|
|
30
|
-
return this.value === valueObject.value;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
abstract readonly attributeName: string;
|
|
34
|
-
}
|
package/tsconfig.cjs.json
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "./dist/cjs",
|
|
5
|
-
"module": "CommonJS",
|
|
6
|
-
"moduleResolution": "node",
|
|
7
|
-
"declaration": true,
|
|
8
|
-
"declarationMap": true,
|
|
9
|
-
"declarationDir": "./dist/types"
|
|
10
|
-
},
|
|
11
|
-
"include": ["src/**/*"],
|
|
12
|
-
"exclude": ["node_modules", "dist"]
|
|
13
|
-
}
|
package/tsconfig.esm.json
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "./dist/esm",
|
|
5
|
-
"module": "nodenext",
|
|
6
|
-
"moduleResolution": "nodenext",
|
|
7
|
-
"declaration": false,
|
|
8
|
-
"declarationMap": false
|
|
9
|
-
},
|
|
10
|
-
"include": ["src/**/*"],
|
|
11
|
-
"exclude": ["node_modules", "dist"]
|
|
12
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Visit https://aka.ms/tsconfig to read more about this file
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
// File Layout
|
|
5
|
-
"rootDir": "./src",
|
|
6
|
-
"outDir": "./dist",
|
|
7
|
-
|
|
8
|
-
// Environment Settings
|
|
9
|
-
// See also https://aka.ms/tsconfig/module
|
|
10
|
-
"target": "esnext",
|
|
11
|
-
"types": [],
|
|
12
|
-
"module": "nodenext",
|
|
13
|
-
"moduleResolution": "nodenext",
|
|
14
|
-
// For nodejs:
|
|
15
|
-
// "lib": ["esnext"],
|
|
16
|
-
// "types": ["node"],
|
|
17
|
-
// and npm install -D @types/node
|
|
18
|
-
|
|
19
|
-
// Other Outputs
|
|
20
|
-
"sourceMap": true,
|
|
21
|
-
"declaration": true,
|
|
22
|
-
"declarationMap": true,
|
|
23
|
-
|
|
24
|
-
// Stricter Typechecking Options
|
|
25
|
-
"noUncheckedIndexedAccess": true,
|
|
26
|
-
"exactOptionalPropertyTypes": true,
|
|
27
|
-
|
|
28
|
-
// Style Options
|
|
29
|
-
// "noImplicitReturns": true,
|
|
30
|
-
// "noImplicitOverride": true,
|
|
31
|
-
// "noUnusedLocals": true,
|
|
32
|
-
// "noUnusedParameters": true,
|
|
33
|
-
// "noFallthroughCasesInSwitch": true,
|
|
34
|
-
// "noPropertyAccessFromIndexSignature": true,
|
|
35
|
-
|
|
36
|
-
// Recommended Options
|
|
37
|
-
"strict": true,
|
|
38
|
-
"jsx": "react-jsx",
|
|
39
|
-
// "verbatimModuleSyntax": true,
|
|
40
|
-
"isolatedModules": true,
|
|
41
|
-
"noUncheckedSideEffectImports": true,
|
|
42
|
-
"moduleDetection": "force",
|
|
43
|
-
"skipLibCheck": true,
|
|
44
|
-
},
|
|
45
|
-
"include": ["src/**/*"],
|
|
46
|
-
"exclude": ["node_modules", "dist"]
|
|
47
|
-
}
|