@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,115 +0,0 @@
|
|
|
1
|
-
import { expectTypeOf } from "expect-type";
|
|
2
|
-
|
|
3
|
-
import { ValueObject, IntegerValue } from "../../src/value-objects";
|
|
4
|
-
|
|
5
|
-
class TestIntegerValue extends IntegerValue {
|
|
6
|
-
readonly attributeName = "test";
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
describe("IntegerValue", () => {
|
|
10
|
-
it('should implement "ValueObject" interface', () => {
|
|
11
|
-
expectTypeOf<IntegerValue>().toExtend<ValueObject>();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('should have a "valueType" with "Integer" as value', () => {
|
|
15
|
-
const testIntegerValue = new TestIntegerValue(0);
|
|
16
|
-
|
|
17
|
-
expect(testIntegerValue.valueType).toEqual("Integer");
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should have a "value" property of type number', () => {
|
|
21
|
-
expectTypeOf<IntegerValue["value"]>().toBeNumber();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('should have a "min" property of type number or undefined', () => {
|
|
25
|
-
expectTypeOf<IntegerValue["min"]>().toEqualTypeOf<number | undefined>();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should have a "max" property of type number or undefined', () => {
|
|
29
|
-
expectTypeOf<IntegerValue["max"]>().toEqualTypeOf<number | undefined>()
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('should define the "equals" method', () => {
|
|
33
|
-
expectTypeOf<IntegerValue["equals"]>().toEqualTypeOf<(valueObject: unknown) => boolean>();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe('when "min" is not present', () => {
|
|
37
|
-
it('should allow any negative integer as valid', () => {
|
|
38
|
-
const testIntegerValue = new TestIntegerValue(-1);
|
|
39
|
-
|
|
40
|
-
expect(testIntegerValue.isValid).toBeTruthy();
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
describe('when "min" is present', () => {
|
|
45
|
-
it('should assign the provided value', () => {
|
|
46
|
-
const min = 1;
|
|
47
|
-
const testIntegerValue = new TestIntegerValue(0, min);
|
|
48
|
-
|
|
49
|
-
expect(testIntegerValue.min).toEqual(min);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('should return false if the value provided is less than the "min"', () => {
|
|
53
|
-
const min = 1;
|
|
54
|
-
const testIntegerValue = new TestIntegerValue(-1, min);
|
|
55
|
-
|
|
56
|
-
expect(testIntegerValue.isValid).toBeFalsy();
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it('should return true if the value provided is greather or equal than the "min', () => {
|
|
60
|
-
const min = 1;
|
|
61
|
-
const testIntegerValue = new TestIntegerValue(1, min);
|
|
62
|
-
|
|
63
|
-
expect(testIntegerValue.isValid).toBeTruthy();
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('when "max" is not present', () => {
|
|
68
|
-
it('should assign a default value of undefined', () => {
|
|
69
|
-
const testIntegerValue = new TestIntegerValue(0);
|
|
70
|
-
|
|
71
|
-
expect(testIntegerValue.max).toBeUndefined();
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
describe('when "max" is present', () => {
|
|
76
|
-
it('should assign the provided value', () => {
|
|
77
|
-
const max = 1;
|
|
78
|
-
const testIntegerValue = new TestIntegerValue(0, undefined, max);
|
|
79
|
-
|
|
80
|
-
expect(testIntegerValue.max).toEqual(max);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('should return false if the value provided is greather than the "max"', () => {
|
|
84
|
-
const max = 1;
|
|
85
|
-
const testIntegerValue = new TestIntegerValue(2, undefined, max);
|
|
86
|
-
|
|
87
|
-
expect(testIntegerValue.isValid).toBeFalsy();
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it('should return true if the value provided is less or equal than the "max', () => {
|
|
91
|
-
const max = 1;
|
|
92
|
-
const testIntegerValue = new TestIntegerValue(1, undefined, max);
|
|
93
|
-
|
|
94
|
-
expect(testIntegerValue.isValid).toBeTruthy();
|
|
95
|
-
});
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
describe('when "min" and "max" is present', () => {
|
|
99
|
-
it('should return false if the value provided is not between the "min" and "max"', () => {
|
|
100
|
-
const min = -1;
|
|
101
|
-
const max = 1;
|
|
102
|
-
const testIntegerValue = new TestIntegerValue(2, min, max);
|
|
103
|
-
|
|
104
|
-
expect(testIntegerValue.isValid).toBeFalsy();
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it('should return true if the value provided is not between the "min" and "max"', () => {
|
|
108
|
-
const min = -1;
|
|
109
|
-
const max = 1;
|
|
110
|
-
const testIntegerValue = new TestIntegerValue(0, min, max);
|
|
111
|
-
|
|
112
|
-
expect(testIntegerValue.isValid).toBeTruthy();
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
});
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { expectTypeOf } from "expect-type";
|
|
2
|
-
|
|
3
|
-
import { ValueObject, PhoneValue } from "../../src/value-objects";
|
|
4
|
-
|
|
5
|
-
class TestPhoneValue extends PhoneValue {
|
|
6
|
-
readonly attributeName = "test";
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
describe("PhoneValue", () => {
|
|
10
|
-
it('should implement "ValueObject" interface', () => {
|
|
11
|
-
expectTypeOf<PhoneValue>().toExtend<ValueObject>();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('should have a "valueType" with "Phone" as value', () => {
|
|
15
|
-
const testPhoneValue = new TestPhoneValue("");
|
|
16
|
-
|
|
17
|
-
expect(testPhoneValue.valueType).toEqual("Phone");
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should have a "value" property of type string', () => {
|
|
21
|
-
expectTypeOf<PhoneValue["value"]>().toBeString();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('should have a "countryCode" property of type string', () => {
|
|
25
|
-
expectTypeOf<PhoneValue["countryCode"]>().toEqualTypeOf<string | null>();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should have a "phoneNumber" property of type string', () => {
|
|
29
|
-
expectTypeOf<PhoneValue["phoneNumber"]>().toEqualTypeOf<string | null>();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('should have a "formattedPhone" property of type string', () => {
|
|
33
|
-
expectTypeOf<PhoneValue["formattedPhone"]>().toEqualTypeOf<string | null>();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('should define the "equals" method', () => {
|
|
37
|
-
expectTypeOf<PhoneValue["equals"]>().toEqualTypeOf<(valueObject: unknown) => boolean>();
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe('when "value" is a phone', () => {
|
|
41
|
-
const countryCode = "+52";
|
|
42
|
-
const phoneNumber = "1234567890";
|
|
43
|
-
const formattedPhone = `${countryCode} (123) 456-7890`;
|
|
44
|
-
const testPhoneValue = new TestPhoneValue(`${countryCode}${phoneNumber}`);
|
|
45
|
-
|
|
46
|
-
it('should return true the "isValid" getter', () => {
|
|
47
|
-
expect(testPhoneValue.isValid).toBeTruthy();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('should return the "countryCode" property', () => {
|
|
51
|
-
expect(testPhoneValue.countryCode).toEqual(countryCode);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('should return the "phoneNumber" property', () => {
|
|
55
|
-
expect(testPhoneValue.phoneNumber).toEqual(phoneNumber);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should return the "formattedPhone" property', () => {
|
|
59
|
-
expect(testPhoneValue.formattedPhone).toEqual(formattedPhone);
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
describe('when "value" is not a phone', () => {
|
|
64
|
-
const testPhoneValue = new TestPhoneValue("+112345678901241");
|
|
65
|
-
|
|
66
|
-
it('should return false the "isValid" getter', () => {
|
|
67
|
-
expect(testPhoneValue.isValid).toBeFalsy();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('should return null for the "countryCode" property', () => {
|
|
71
|
-
expect(testPhoneValue.countryCode).toBeNull();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('should return null for the "phoneNumber" property', () => {
|
|
75
|
-
expect(testPhoneValue.phoneNumber).toBeNull();
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('should return null for the "formattedPhone" property', () => {
|
|
79
|
-
expect(testPhoneValue.formattedPhone).toBeNull();
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
});
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { expectTypeOf } from "expect-type";
|
|
2
|
-
|
|
3
|
-
import { ValueObject, SlugValue } from "../../src/value-objects";
|
|
4
|
-
|
|
5
|
-
class TestSlugValue extends SlugValue {
|
|
6
|
-
readonly attributeName = "test";
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
describe("SlugValue", () => {
|
|
10
|
-
it('should implement "ValueObject" interface', () => {
|
|
11
|
-
expectTypeOf<TestSlugValue>().toExtend<ValueObject>();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('should have a "valueType" with "Slug" as value', () => {
|
|
15
|
-
const testSlugValue = new TestSlugValue("");
|
|
16
|
-
|
|
17
|
-
expect(testSlugValue.valueType).toEqual("Slug");
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should have a "value" property of type string', () => {
|
|
21
|
-
expectTypeOf<SlugValue["value"]>().toBeString();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('should define the "equals" method', () => {
|
|
25
|
-
expectTypeOf<SlugValue["equals"]>().toEqualTypeOf<(valueObject: unknown) => boolean>();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
describe('when "value" is an slug', () => {
|
|
29
|
-
it('should return true the "isValid" getter', () => {
|
|
30
|
-
const testSlugValue = new TestSlugValue("schorts");
|
|
31
|
-
|
|
32
|
-
expect(testSlugValue.isValid).toBeTruthy();
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe('when "value" is not an slug', () => {
|
|
37
|
-
it('should return false the "isValid" getter', () => {
|
|
38
|
-
const testSlugValue = new TestSlugValue("-schorts");
|
|
39
|
-
|
|
40
|
-
expect(testSlugValue.isValid).toBeFalsy();
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
});
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { expectTypeOf } from "expect-type";
|
|
2
|
-
|
|
3
|
-
import { ValueObject, StringValue } from "../../src/value-objects";
|
|
4
|
-
|
|
5
|
-
class TestStringalue extends StringValue {
|
|
6
|
-
readonly attributeName = "test";
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
describe("StringValue", () => {
|
|
10
|
-
it('should implement "ValueObject" interface', () => {
|
|
11
|
-
expectTypeOf<TestStringalue>().toExtend<ValueObject>();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('should have a "valueType" with "String" as value', () => {
|
|
15
|
-
const testStringValue = new TestStringalue("");
|
|
16
|
-
|
|
17
|
-
expect(testStringValue.valueType).toEqual("String");
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should have a "value" property of type string', () => {
|
|
21
|
-
expectTypeOf<StringValue["value"]>().toBeString();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('should have a "minLength" property of type number', () => {
|
|
25
|
-
expectTypeOf<StringValue["minLength"]>().toBeNumber();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should have a "maxLength" property of type number or undefined', () => {
|
|
29
|
-
expectTypeOf<StringValue["maxLength"]>().toEqualTypeOf<number | undefined>()
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('should define the "equals" method', () => {
|
|
33
|
-
expectTypeOf<StringValue["equals"]>().toEqualTypeOf<(valueObject: unknown) => boolean>();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe('when "minLength" is not present', () => {
|
|
37
|
-
it('should assign a default value of 0', () => {
|
|
38
|
-
const testStringValue = new TestStringalue("");
|
|
39
|
-
|
|
40
|
-
expect(testStringValue.minLength).toEqual(0);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should allow an empty string as valid', () => {
|
|
44
|
-
const testStringValue = new TestStringalue("");
|
|
45
|
-
|
|
46
|
-
expect(testStringValue.isValid).toBeTruthy();
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
describe('when "minLength" is present', () => {
|
|
51
|
-
it('should assign the provided value', () => {
|
|
52
|
-
const minLength = 1;
|
|
53
|
-
const testStringValue = new TestStringalue("", minLength);
|
|
54
|
-
|
|
55
|
-
expect(testStringValue.minLength).toEqual(minLength);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('should return false if the value provided length is less than the "minLength"', () => {
|
|
59
|
-
const minLength = 1;
|
|
60
|
-
const testStringValue = new TestStringalue("", minLength);
|
|
61
|
-
|
|
62
|
-
expect(testStringValue.isValid).toBeFalsy();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('should return true if the value provided length is greather or equal than the "minLength', () => {
|
|
66
|
-
const minLength = 1;
|
|
67
|
-
const testStringValue = new TestStringalue("1", minLength);
|
|
68
|
-
|
|
69
|
-
expect(testStringValue.isValid).toBeTruthy();
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe('when "maxLength" is not present', () => {
|
|
74
|
-
it('should assign a default value of undefined', () => {
|
|
75
|
-
const testStringValue = new TestStringalue("");
|
|
76
|
-
|
|
77
|
-
expect(testStringValue.maxLength).toBeUndefined();
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
describe('when "maxLength" is present', () => {
|
|
82
|
-
it('should assign the provided value', () => {
|
|
83
|
-
const maxLength = 1;
|
|
84
|
-
const testStringValue = new TestStringalue("", 0, maxLength);
|
|
85
|
-
|
|
86
|
-
expect(testStringValue.maxLength).toEqual(maxLength);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('should return false if the value provided length is greather than the "maxLength"', () => {
|
|
90
|
-
const maxLength = 1;
|
|
91
|
-
const testStringValue = new TestStringalue("12", 0, maxLength);
|
|
92
|
-
|
|
93
|
-
expect(testStringValue.isValid).toBeFalsy();
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('should return true if the value provided length is less or equal than the "maxLength', () => {
|
|
97
|
-
const maxLength = 2;
|
|
98
|
-
const testStringValue = new TestStringalue("1", 0, maxLength);
|
|
99
|
-
|
|
100
|
-
expect(testStringValue.isValid).toBeTruthy();
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
describe('when "minLength" and "maxLength" is present', () => {
|
|
105
|
-
it('should return false if the value provided length is not between the "minLength" and "maxLength"', () => {
|
|
106
|
-
const minLength = 1;
|
|
107
|
-
const maxLength = 2;
|
|
108
|
-
const testStringValue = new TestStringalue("123", minLength, maxLength);
|
|
109
|
-
|
|
110
|
-
expect(testStringValue.isValid).toBeFalsy();
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('should return true if the value provided length is not between the "minLength" and "maxLength"', () => {
|
|
114
|
-
const minLength = 1;
|
|
115
|
-
const maxLength = 2;
|
|
116
|
-
const testStringValue = new TestStringalue("12", minLength, maxLength);
|
|
117
|
-
|
|
118
|
-
expect(testStringValue.isValid).toBeTruthy();
|
|
119
|
-
});
|
|
120
|
-
});
|
|
121
|
-
});
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import { expectTypeOf } from "expect-type";
|
|
2
|
-
|
|
3
|
-
import { ValueObject, UUIDValue } from "../../src/value-objects";
|
|
4
|
-
|
|
5
|
-
class TestUUIDValue extends UUIDValue {
|
|
6
|
-
readonly attributeName = "test";
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
describe("UUIDValue", () => {
|
|
10
|
-
it('should implement "ValueObject" interface', () => {
|
|
11
|
-
expectTypeOf<UUIDValue>().toExtend<ValueObject>();
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('should have a "valueType" with "UUID" as value', () => {
|
|
15
|
-
const testUUIDvalue = new TestUUIDValue();
|
|
16
|
-
|
|
17
|
-
expect(testUUIDvalue.valueType).toEqual("UUID");
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it('should have a "value" property of type string | undefined', () => {
|
|
21
|
-
expectTypeOf<UUIDValue["value"]>().toEqualTypeOf<string | undefined>();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it('should have a "optional" property of type boolean', () => {
|
|
25
|
-
expectTypeOf<UUIDValue["optional"]>().toBeBoolean();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('should define the "equals" method', () => {
|
|
29
|
-
expectTypeOf<UUIDValue["equals"]>().toEqualTypeOf<(valueObject: unknown) => boolean>();
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe('when "value" is present', () => {
|
|
33
|
-
describe('when "value" is valid', () => {
|
|
34
|
-
it('should have a getter "isValid" that returns true', () => {
|
|
35
|
-
const testUUIDvalue = new TestUUIDValue("87a00bc1-c586-4d23-bfc7-dd637628777c");
|
|
36
|
-
|
|
37
|
-
expect(testUUIDvalue.isValid).toBeTruthy();
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe('when "value" is not valid', () => {
|
|
42
|
-
it('should have a getter "isValid" that returns false', () => {
|
|
43
|
-
const testUUIDvalue = new TestUUIDValue("dummy-uuid-12346-5734");
|
|
44
|
-
|
|
45
|
-
expect(testUUIDvalue.isValid).toBeFalsy();
|
|
46
|
-
});
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
describe('when "value" is not present', () => {
|
|
51
|
-
describe('when "value" is optional', () => {
|
|
52
|
-
it('should have a getter "isValid" that returns true', () => {
|
|
53
|
-
const testUUIDvalue = new TestUUIDValue(undefined, true);
|
|
54
|
-
|
|
55
|
-
expect(testUUIDvalue.isValid).toBeTruthy();
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
describe('when "value" is not optional', () => {
|
|
60
|
-
it('should have a getter "isValid" that runs the validations normally and returns false', () => {
|
|
61
|
-
const testUUIDvalue = new TestUUIDValue(undefined, false);
|
|
62
|
-
|
|
63
|
-
expect(testUUIDvalue.isValid).toBeFalsy();
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
});
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { expectTypeOf } from "expect-type";
|
|
2
|
-
|
|
3
|
-
import { ValueObject } from "../../src/value-objects";
|
|
4
|
-
|
|
5
|
-
describe("ValueObject", () => {
|
|
6
|
-
it('should have a "value" property of type unknown', () => {
|
|
7
|
-
expectTypeOf<ValueObject>().toHaveProperty("value");
|
|
8
|
-
expectTypeOf<ValueObject['value']>().toBeUnknown();
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('should have a "isValid" property of type boolean', () => {
|
|
12
|
-
expectTypeOf<ValueObject>().toHaveProperty("isValid");
|
|
13
|
-
expectTypeOf<ValueObject['isValid']>().toBeBoolean();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('should have a "valueType" property of type string', () => {
|
|
17
|
-
expectTypeOf<ValueObject>().toHaveProperty("valueType");
|
|
18
|
-
expectTypeOf<ValueObject['valueType']>().toBeString();
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it('should have a "attributeName" property of type string', () => {
|
|
22
|
-
expectTypeOf<ValueObject>().toHaveProperty("attributeName");
|
|
23
|
-
expectTypeOf<ValueObject['attributeName']>().toBeString();
|
|
24
|
-
});
|
|
25
|
-
});
|
package/jest.config.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// jest.config.js
|
|
2
|
-
const { defaults: tsjPreset } = require("ts-jest/presets");
|
|
3
|
-
const { transform } = require("typescript");
|
|
4
|
-
|
|
5
|
-
module.exports = {
|
|
6
|
-
preset: "ts-jest/presets/default-esm",
|
|
7
|
-
testEnvironment: "node",
|
|
8
|
-
extensionsToTreatAsEsm: [".ts"],
|
|
9
|
-
transform: {
|
|
10
|
-
'^.+\\.(ts|tsx)$': ['ts-jest', { useESM: true }],
|
|
11
|
-
},
|
|
12
|
-
moduleFileExtensions: ["ts", "js", "json", "node"],
|
|
13
|
-
testMatch: ["**/__tests__/**/*.ts", "**/?(*.)+(spec|test).ts"],
|
|
14
|
-
collectCoverageFrom: [
|
|
15
|
-
"src/**/*.ts",
|
|
16
|
-
"!src/**/*.d.ts",
|
|
17
|
-
"!src/index.ts",
|
|
18
|
-
],
|
|
19
|
-
coverageDirectory: "coverage",
|
|
20
|
-
coverageReporters: ["text", "lcov", "html"],
|
|
21
|
-
moduleNameMapper: {
|
|
22
|
-
"^@schorts/shared-kernel/(.*)$": "<rootDir>/src/$1",
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
|
package/src/abac/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type { Predicate } from "./predicate";
|
package/src/abac/predicate.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Entity } from "../entities";
|
|
2
|
-
import { BaseModel } from "../models";
|
|
3
|
-
import { ValueObject } from "../value-objects";
|
|
4
|
-
|
|
5
|
-
export interface AuthProvider<UserEntity extends Entity<ValueObject, BaseModel>> {
|
|
6
|
-
authenticate(...args: any[]): Promise<string>;
|
|
7
|
-
logout(): Promise<void>;
|
|
8
|
-
isAuthenticated(): Promise<boolean>;
|
|
9
|
-
getCurrentUser(): Promise<UserEntity | null>;
|
|
10
|
-
onAuthChange(callback: (user: UserEntity | null) => void): () => void;
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { TranslationResolver } from "../../i18n";
|
|
2
|
-
|
|
3
|
-
export class NotAuthenticated extends Error {
|
|
4
|
-
constructor(translationResolver?: TranslationResolver) {
|
|
5
|
-
const message = translationResolver
|
|
6
|
-
? translationResolver.resolve("auth.errors.not_authenticated")
|
|
7
|
-
: "Not Authenticated";
|
|
8
|
-
|
|
9
|
-
super(message);
|
|
10
|
-
}
|
|
11
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { TranslationResolver } from "../../i18n";
|
|
2
|
-
|
|
3
|
-
export class RequireAuthNotImplementedCorrectly extends Error {
|
|
4
|
-
constructor(translationResolver?: TranslationResolver) {
|
|
5
|
-
const message = translationResolver
|
|
6
|
-
? translationResolver.resolve("auth.errors.require_auth_not_implemented_correctly")
|
|
7
|
-
: "RequireAuth decorator not implemented correctly";
|
|
8
|
-
|
|
9
|
-
super(message);
|
|
10
|
-
}
|
|
11
|
-
}
|
package/src/auth/index.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { AuthProvider } from "./auth-provider";
|
|
2
|
-
import { NotAuthenticated, RequireAuthNotImplementedCorrectly } from './exceptions';
|
|
3
|
-
import { TranslationResolver } from "../i18n";
|
|
4
|
-
|
|
5
|
-
export function RequireAuth(onFail?: () => any) {
|
|
6
|
-
function wrapper<T extends { authProvider?: AuthProvider<any>, translationResolver?: TranslationResolver }, A extends any[], R>(
|
|
7
|
-
originalMethod: (this: T, ...args: A) => Promise<R>
|
|
8
|
-
): (this: T, ...args: A) => Promise<R> {
|
|
9
|
-
return async function (this: T, ...args: A): Promise<R> {
|
|
10
|
-
if (!this.authProvider) {
|
|
11
|
-
throw new Error("authProvider: AuthProvider is required on this instance");
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const isAuthenticated = await this.authProvider.isAuthenticated();
|
|
15
|
-
|
|
16
|
-
if (!isAuthenticated) {
|
|
17
|
-
if (onFail) {
|
|
18
|
-
return onFail();
|
|
19
|
-
} else {
|
|
20
|
-
throw new NotAuthenticated(this.translationResolver);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return await originalMethod.apply(this, args);
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return function (...args: any[]) {
|
|
29
|
-
if (args.length === 3 && typeof args[2] === 'object') {
|
|
30
|
-
const descriptor = args[2] as PropertyDescriptor;
|
|
31
|
-
descriptor.value = wrapper(descriptor.value);
|
|
32
|
-
return descriptor;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (args.length === 2 && typeof args[1] === 'object' && 'kind' in args[1]) {
|
|
36
|
-
const [originalMethod] = args;
|
|
37
|
-
return wrapper(originalMethod);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
throw new RequireAuthNotImplementedCorrectly();
|
|
41
|
-
};
|
|
42
|
-
}
|
package/src/converters/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { RemoteFileToBase64 } from "./remote-file-to-base64";
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { HTTPProvider } from "../http";
|
|
2
|
-
|
|
3
|
-
export class RemoteFileToBase64 {
|
|
4
|
-
constructor(
|
|
5
|
-
private readonly httpProvider: HTTPProvider,
|
|
6
|
-
) {}
|
|
7
|
-
|
|
8
|
-
async convert(url: URL): Promise<string> {
|
|
9
|
-
const blob = await this.httpProvider.get<Blob>(url);
|
|
10
|
-
|
|
11
|
-
return new Promise((resolve, reject) => {
|
|
12
|
-
const reader = new FileReader();
|
|
13
|
-
|
|
14
|
-
reader.readAsDataURL(blob);
|
|
15
|
-
reader.onload = () => resolve(reader.result as string);
|
|
16
|
-
reader.onerror = (error) => reject(error);
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
}
|
package/src/criteria/criteria.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Order } from "./order";
|
|
2
|
-
import { Operator } from "./operator";
|
|
3
|
-
import { Direction } from "./direction";
|
|
4
|
-
import { OffsetNotValid, LimitNotValid } from "./exceptions";
|
|
5
|
-
|
|
6
|
-
export class Criteria {
|
|
7
|
-
readonly filters: Array<{ field: string; operator: Operator; value: any }> = [];
|
|
8
|
-
readonly orders: Array<Order> = [];
|
|
9
|
-
limit?: number;
|
|
10
|
-
offset?: number;
|
|
11
|
-
|
|
12
|
-
where(field: string, operator: Operator, value: any): Criteria {
|
|
13
|
-
this.filters.push({ field, operator, value });
|
|
14
|
-
|
|
15
|
-
return this;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
orderBy(
|
|
19
|
-
field: string,
|
|
20
|
-
direction: Direction = "ASC",
|
|
21
|
-
): Criteria {
|
|
22
|
-
this.orders.push({ field, direction });
|
|
23
|
-
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
limitResults(limit: number): Criteria {
|
|
28
|
-
if (limit < 1) {
|
|
29
|
-
throw new LimitNotValid(limit);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
this.limit = limit;
|
|
33
|
-
|
|
34
|
-
return this;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
offsetResults(offset: number): Criteria {
|
|
38
|
-
if (offset < 1) {
|
|
39
|
-
throw new OffsetNotValid(offset);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
this.offset = offset;
|
|
43
|
-
|
|
44
|
-
return this;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type Direction = "ASC" | "DESC";
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { TranslationResolver } from "../../i18n";
|
|
2
|
-
|
|
3
|
-
export class LimitNotValid extends Error {
|
|
4
|
-
constructor(limit: number, translationResolver?: TranslationResolver) {
|
|
5
|
-
const message = translationResolver
|
|
6
|
-
? translationResolver.resolve("criteria.errors.limit_not_valid", { limit })
|
|
7
|
-
: `Limit Not Valid: ${limit}`;
|
|
8
|
-
|
|
9
|
-
super(message);
|
|
10
|
-
}
|
|
11
|
-
}
|