@node-c/core 1.0.0-alpha9 → 1.0.0-beta0

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.
Files changed (140) hide show
  1. package/coverage/src/app.ts.html +349 -0
  2. package/coverage/src/common/configProvider/configProvider.module.ts.html +160 -0
  3. package/coverage/src/common/configProvider/configProvider.service.ts.html +658 -0
  4. package/coverage/src/common/configProvider/index.html +146 -0
  5. package/coverage/src/common/configProvider/index.ts.html +94 -0
  6. package/coverage/src/common/definitions/common.constants.ts.html +160 -0
  7. package/coverage/src/common/definitions/common.errors.ts.html +124 -0
  8. package/coverage/src/common/definitions/index.html +146 -0
  9. package/coverage/src/common/definitions/index.ts.html +94 -0
  10. package/coverage/src/common/utils/index.html +131 -0
  11. package/coverage/src/common/utils/index.ts.html +88 -0
  12. package/coverage/src/common/utils/utils.loadDynamicModules.ts.html +265 -0
  13. package/coverage/src/domain/entityService/domain.entity.service.ts.html +784 -0
  14. package/coverage/src/domain/entityService/index.html +131 -0
  15. package/coverage/src/domain/entityService/index.ts.html +91 -0
  16. package/coverage/src/index.html +116 -0
  17. package/coverage/src/persistance/entityService/index.html +131 -0
  18. package/coverage/src/persistance/entityService/index.ts.html +91 -0
  19. package/coverage/src/persistance/entityService/persistance.entity.service.ts.html +268 -0
  20. package/dist/app.d.ts +2 -2
  21. package/dist/app.js +27 -15
  22. package/dist/app.js.map +1 -1
  23. package/dist/common/configProvider/configProvider.definitions.d.ts +156 -20
  24. package/dist/common/configProvider/configProvider.definitions.js +21 -7
  25. package/dist/common/configProvider/configProvider.definitions.js.map +1 -1
  26. package/dist/common/configProvider/configProvider.module.js +13 -2
  27. package/dist/common/configProvider/configProvider.module.js.map +1 -1
  28. package/dist/common/configProvider/configProvider.service.js +21 -18
  29. package/dist/common/configProvider/configProvider.service.js.map +1 -1
  30. package/dist/common/definitions/common.constants.d.ts +2 -1
  31. package/dist/common/definitions/common.constants.js +1 -0
  32. package/dist/common/definitions/common.constants.js.map +1 -1
  33. package/dist/common/utils/base64UrlEncode/base64UrlEncode.method.d.ts +1 -0
  34. package/dist/common/utils/base64UrlEncode/base64UrlEncode.method.js +9 -0
  35. package/dist/common/utils/base64UrlEncode/base64UrlEncode.method.js.map +1 -0
  36. package/dist/common/utils/base64UrlEncode/index.d.ts +1 -0
  37. package/dist/{persistance/entityService → common/utils/base64UrlEncode}/index.js +1 -2
  38. package/dist/common/utils/base64UrlEncode/index.js.map +1 -0
  39. package/dist/common/utils/getNested/getNested.definitions.d.ts +4 -0
  40. package/dist/common/utils/getNested/getNested.definitions.js +3 -0
  41. package/dist/common/utils/getNested/getNested.definitions.js.map +1 -0
  42. package/dist/common/utils/getNested/getNested.method.d.ts +6 -0
  43. package/dist/common/utils/getNested/getNested.method.js +88 -0
  44. package/dist/common/utils/getNested/getNested.method.js.map +1 -0
  45. package/dist/common/utils/getNested/index.d.ts +2 -0
  46. package/dist/common/utils/getNested/index.js +19 -0
  47. package/dist/common/utils/getNested/index.js.map +1 -0
  48. package/dist/common/utils/httpRequest/httpRequest.definitions.d.ts +19 -0
  49. package/dist/common/utils/httpRequest/httpRequest.definitions.js +3 -0
  50. package/dist/common/utils/httpRequest/httpRequest.definitions.js.map +1 -0
  51. package/dist/common/utils/httpRequest/httpRequest.method.d.ts +2 -0
  52. package/dist/common/utils/httpRequest/httpRequest.method.js +56 -0
  53. package/dist/common/utils/httpRequest/httpRequest.method.js.map +1 -0
  54. package/dist/common/utils/httpRequest/index.d.ts +2 -0
  55. package/dist/common/utils/httpRequest/index.js +19 -0
  56. package/dist/common/utils/httpRequest/index.js.map +1 -0
  57. package/dist/common/utils/index.d.ts +5 -1
  58. package/dist/common/utils/index.js +5 -1
  59. package/dist/common/utils/index.js.map +1 -1
  60. package/dist/common/utils/loadDynamicModules/index.d.ts +1 -0
  61. package/dist/common/utils/loadDynamicModules/index.js +18 -0
  62. package/dist/common/utils/loadDynamicModules/index.js.map +1 -0
  63. package/dist/common/utils/{utils.loadDynamicModules.d.ts → loadDynamicModules/utils.loadDynamicModules.d.ts} +1 -1
  64. package/dist/common/utils/loadDynamicModules/utils.loadDynamicModules.js.map +1 -0
  65. package/dist/common/utils/setNested/index.d.ts +2 -0
  66. package/dist/common/utils/setNested/index.js +19 -0
  67. package/dist/common/utils/setNested/index.js.map +1 -0
  68. package/dist/common/utils/setNested/setNested.definitions.d.ts +4 -0
  69. package/dist/common/utils/setNested/setNested.definitions.js +3 -0
  70. package/dist/common/utils/setNested/setNested.definitions.js.map +1 -0
  71. package/dist/common/utils/setNested/setNested.method.d.ts +2 -0
  72. package/dist/common/utils/setNested/setNested.method.js +70 -0
  73. package/dist/common/utils/setNested/setNested.method.js.map +1 -0
  74. package/dist/data/entityService/data.entity.service.d.ts +17 -0
  75. package/dist/data/entityService/data.entity.service.definitions.d.ts +117 -0
  76. package/dist/data/entityService/data.entity.service.definitions.js +28 -0
  77. package/dist/data/entityService/data.entity.service.definitions.js.map +1 -0
  78. package/dist/{persistance/entityService/persistance.entity.service.js → data/entityService/data.entity.service.js} +41 -9
  79. package/dist/data/entityService/data.entity.service.js.map +1 -0
  80. package/dist/data/entityService/index.d.ts +2 -0
  81. package/dist/data/entityService/index.js +19 -0
  82. package/dist/data/entityService/index.js.map +1 -0
  83. package/dist/domain/entityService/domain.entity.service.d.ts +28 -13
  84. package/dist/domain/entityService/domain.entity.service.definitions.d.ts +26 -19
  85. package/dist/domain/entityService/domain.entity.service.definitions.js +6 -6
  86. package/dist/domain/entityService/domain.entity.service.definitions.js.map +1 -1
  87. package/dist/domain/entityService/domain.entity.service.js +77 -69
  88. package/dist/domain/entityService/domain.entity.service.js.map +1 -1
  89. package/dist/index.d.ts +1 -1
  90. package/dist/index.js +1 -1
  91. package/dist/index.js.map +1 -1
  92. package/package.json +11 -10
  93. package/src/app.spec.ts +138 -0
  94. package/src/app.ts +115 -0
  95. package/src/common/configProvider/configProvider.definitions.ts +445 -0
  96. package/src/common/configProvider/configProvider.module.spec.ts +90 -0
  97. package/src/common/configProvider/configProvider.module.ts +25 -0
  98. package/src/common/configProvider/configProvider.service.spec.ts +206 -0
  99. package/src/common/configProvider/configProvider.service.ts +204 -0
  100. package/src/common/configProvider/index.ts +3 -0
  101. package/src/common/definitions/common.constants.ts +27 -0
  102. package/src/common/definitions/common.definitions.ts +13 -0
  103. package/src/common/definitions/common.errors.ts +13 -0
  104. package/src/common/definitions/index.ts +3 -0
  105. package/src/common/utils/base64UrlEncode/base64UrlEncode.method.ts +4 -0
  106. package/src/common/utils/base64UrlEncode/index.ts +1 -0
  107. package/src/common/utils/getNested/getNested.definitions.ts +4 -0
  108. package/src/common/utils/getNested/getNested.method.ts +108 -0
  109. package/src/common/utils/getNested/getNested.spec.ts +151 -0
  110. package/src/common/utils/getNested/index.ts +2 -0
  111. package/src/common/utils/httpRequest/httpRequest.definitions.ts +22 -0
  112. package/src/common/utils/httpRequest/httpRequest.method.ts +46 -0
  113. package/src/common/utils/httpRequest/index.ts +2 -0
  114. package/src/common/utils/index.ts +5 -0
  115. package/src/common/utils/loadDynamicModules/index.ts +1 -0
  116. package/src/common/utils/loadDynamicModules/utils.loadDynamicModules.spec.ts +111 -0
  117. package/src/common/utils/loadDynamicModules/utils.loadDynamicModules.ts +69 -0
  118. package/src/common/utils/setNested/index.ts +2 -0
  119. package/src/common/utils/setNested/setNested.definitions.ts +4 -0
  120. package/src/common/utils/setNested/setNested.method.ts +83 -0
  121. package/src/common/utils/setNested/setNested.spec.ts +184 -0
  122. package/src/data/entityService/data.entity.service.definitions.ts +154 -0
  123. package/src/data/entityService/data.entity.service.spec.ts +112 -0
  124. package/src/data/entityService/data.entity.service.ts +144 -0
  125. package/src/data/entityService/index.ts +2 -0
  126. package/src/domain/entityService/domain.entity.service.definitions.ts +142 -0
  127. package/src/domain/entityService/domain.entity.service.spec.ts +126 -0
  128. package/src/domain/entityService/domain.entity.service.ts +421 -0
  129. package/src/domain/entityService/index.ts +2 -0
  130. package/src/index.ts +6 -0
  131. package/src/vitest.config.ts +9 -0
  132. package/dist/common/utils/utils.loadDynamicModules.js.map +0 -1
  133. package/dist/persistance/entityService/index.d.ts +0 -2
  134. package/dist/persistance/entityService/index.js.map +0 -1
  135. package/dist/persistance/entityService/persistance.entity.service.d.ts +0 -11
  136. package/dist/persistance/entityService/persistance.entity.service.definitions.d.ts +0 -76
  137. package/dist/persistance/entityService/persistance.entity.service.definitions.js +0 -23
  138. package/dist/persistance/entityService/persistance.entity.service.definitions.js.map +0 -1
  139. package/dist/persistance/entityService/persistance.entity.service.js.map +0 -1
  140. /package/dist/common/utils/{utils.loadDynamicModules.js → loadDynamicModules/utils.loadDynamicModules.js} +0 -0
@@ -0,0 +1,184 @@
1
+ import { strict as assert } from 'assert';
2
+
3
+ import { setNested } from '../../dist';
4
+
5
+ describe('setNested', function () {
6
+ it('should execute successfully and return false if an empty string field argument is provided', function () {
7
+ const result = setNested({}, '', true);
8
+ assert.strictEqual(result, false, `bad value ${result} for the method execution result, expected false`);
9
+ });
10
+ it('should execute successfully and return false if a step in the path does not exist in the parent', function () {
11
+ const result = setNested({}, 'foo.bar', true);
12
+ assert.strictEqual(result, false, `bad value ${result} for the method execution result, expected false`);
13
+ });
14
+ it('should execute successfully, set the child field and return true if the field does exist in the parent and there are no arrays in the path', function () {
15
+ const inputObject = { foo: {} } as any,
16
+ result = setNested(inputObject, 'foo.bar', 'test');
17
+ assert.strictEqual(result, true, `bad value ${result} for the method execution result, expected ${true}`);
18
+ assert.strictEqual(
19
+ inputObject.foo.bar,
20
+ 'test',
21
+ `bad value ${inputObject.foo.bar} for the method execution inputObject.foo.bar, expected ${'test'}`
22
+ );
23
+ });
24
+ it('should execute successfully, set the child field and return true if the field exists in the parent and there are no arrays in the path', function () {
25
+ const inputObject = { foo: { bar: 'oldTest' } } as any,
26
+ result = setNested(inputObject, 'foo.bar', 'test');
27
+ assert.strictEqual(result, true, `bad value ${result} for the method execution result, expected ${true}`);
28
+ assert.strictEqual(
29
+ inputObject.foo.bar,
30
+ 'test',
31
+ `bad value ${inputObject.foo.bar} for the method execution inputObject.foo.bar, expected ${'test'}`
32
+ );
33
+ });
34
+ it('should execute successfully, set the child field and return true if the field exists in the parent, there are arrays in the path and an index for them is provided', function () {
35
+ const inputObject = { foo: [{ bar: 'test1' }, { bar: 'test2' }] },
36
+ result = setNested(inputObject, 'foo.0.bar', 'test');
37
+ assert.strictEqual(result, true, `bad value ${result} for the method execution result, expected ${true}`);
38
+ assert.strictEqual(
39
+ inputObject.foo[0].bar,
40
+ 'test',
41
+ `bad value ${inputObject.foo[0].bar} for the method execution inputObject.foo[0].bar, expected ${'test'}`
42
+ );
43
+ assert.strictEqual(
44
+ inputObject.foo[1].bar,
45
+ 'test2',
46
+ `bad value ${inputObject.foo[1].bar} for the method execution inputObject.foo[1].bar, expected ${'test2'}`
47
+ );
48
+ });
49
+ it('should execute successfully, set the child field and return true if the field exists in the parent, there are arrays in the path and an index for them is not provided', function () {
50
+ const inputObject = { foo: [{ bar: 'test1' }, { bar: 'test2' }] },
51
+ result = setNested(inputObject, 'foo.bar', 'test');
52
+ assert.strictEqual(result, true, `bad value ${result} for the method execution result, expected ${true}`);
53
+ assert.strictEqual(
54
+ inputObject.foo[0].bar,
55
+ 'test',
56
+ `bad value ${inputObject.foo[0].bar} for the method execution inputObject.foo[0].bar, expected ${'test'}`
57
+ );
58
+ assert.strictEqual(
59
+ inputObject.foo[1].bar,
60
+ 'test',
61
+ `bad value ${inputObject.foo[1].bar} for the method execution inputObject.foo[1].bar, expected ${'test'}`
62
+ );
63
+ });
64
+ it('should execute successfully, set the child field and return true if the field does exist in the parent, there is an $ in the path and there are no arrays in the path', function () {
65
+ const inputObject = { foo: {} } as any,
66
+ result = setNested(inputObject, 'foo.$bar', 'test');
67
+ assert.strictEqual(result, true, `bad value ${result} for the method execution result, expected ${true}`);
68
+ assert.strictEqual(
69
+ inputObject.foo['$bar'],
70
+ 'test',
71
+ `bad value ${inputObject.foo['$bar']} for the method execution inputObject.foo['$bar'], expected ${'test'}`
72
+ );
73
+ });
74
+ it('should execute successfully, set the child field and return true if the field exists in the parent, there is an $ in the path and there are no arrays in the path', function () {
75
+ const inputObject = { foo: { $bar: 'oldTest' } } as any,
76
+ result = setNested(inputObject, 'foo.$bar', 'test');
77
+ assert.strictEqual(result, true, `bad value ${result} for the method execution result, expected ${true}`);
78
+ assert.strictEqual(
79
+ inputObject.foo['$bar'],
80
+ 'test',
81
+ `bad value ${inputObject.foo['$bar']} for the method execution inputObject.foo['$bar'], expected ${'test'}`
82
+ );
83
+ });
84
+ it('should execute successfully, set the child field and return true if the field exists in the parent, there is an $ in the path, there are arrays in the path and an index for them is provided', function () {
85
+ const inputObject = { foo: [{ $bar: 'test1' }, { $bar: 'test2' }] },
86
+ result = setNested(inputObject, 'foo.0.$bar', 'test');
87
+ assert.strictEqual(result, true, `bad value ${result} for the method execution result, expected ${true}`);
88
+ assert.strictEqual(
89
+ inputObject.foo[0]['$bar'],
90
+ 'test',
91
+ `bad value ${inputObject.foo[0]['$bar']} for the method execution inputObject.foo[0]['$bar'], expected ${'test'}`
92
+ );
93
+ assert.strictEqual(
94
+ inputObject.foo[1]['$bar'],
95
+ 'test2',
96
+ `bad value ${inputObject.foo[1]['$bar']} for the method execution inputObject.foo[1]['$bar'], expected ${'test2'}`
97
+ );
98
+ });
99
+ it('should execute successfully, set the child field and return true if the field exists in the parent, there is an $ in the path, there are arrays in the path and an index for them is not provided', function () {
100
+ const inputObject = { foo: [{ $bar: 'test1' }, { $bar: 'test2' }] },
101
+ result = setNested(inputObject, 'foo.$bar', 'test');
102
+ assert.strictEqual(result, true, `bad value ${result} for the method execution result, expected ${true}`);
103
+ assert.strictEqual(
104
+ inputObject.foo[0]['$bar'],
105
+ 'test',
106
+ `bad value ${inputObject.foo[0]['$bar']} for the method execution inputObject.foo[0]['$bar'], expected ${'test'}`
107
+ );
108
+ assert.strictEqual(
109
+ inputObject.foo[1]['$bar'],
110
+ 'test',
111
+ `bad value ${inputObject.foo[1]['$bar']} for the method execution inputObject.foo[1]['$bar'], expected ${'test'}`
112
+ );
113
+ });
114
+ it('should execute successfully, set the child field and return true if the field does exist in the parent, there is an $$ in the path and an $ in the path, and there are no arrays in the path', function () {
115
+ const inputObject = { foo: { $bar: {} } } as any,
116
+ result = setNested(inputObject, 'foo.$bar.$q.boo.baz$', 'test');
117
+ assert.strictEqual(result, true, `bad value ${result} for the method execution result, expected ${true}`);
118
+ assert.strictEqual(
119
+ inputObject.foo['$bar']['$q.boo.baz$'],
120
+ 'test',
121
+ `bad value ${inputObject.foo['$bar']['$q.boo.baz$']} for the method execution inputObject.foo['$bar']['$q.boo.baz$'], expected ${'test'}`
122
+ );
123
+ });
124
+ it('should execute successfully, set the child field and return true if the field does exist in the parent, there is an $$ in the path and there are no arrays in the path', function () {
125
+ const inputObject = { foo: {} } as any,
126
+ result = setNested(inputObject, 'foo.$bar.baz$', 'test');
127
+ assert.strictEqual(result, true, `bad value ${result} for the method execution result, expected ${true}`);
128
+ assert.strictEqual(
129
+ inputObject.foo['$bar.baz$'],
130
+ 'test',
131
+ `bad value ${inputObject.foo['$bar.baz$']} for the method execution inputObject.foo['$bar.baz$'], expected ${'test'}`
132
+ );
133
+ });
134
+ it('should execute successfully, set the child field and return true if the field exists in the parent, there is an $$ in the path, there are no arrays in the path and the $$ item is the last item', function () {
135
+ const inputObject = { foo: { '$bar.baz$': 'oldTest' } } as any,
136
+ result = setNested(inputObject, 'foo.$bar.baz$', 'test');
137
+ assert.strictEqual(result, true, `bad value ${result} for the method execution result, expected ${true}`);
138
+ assert.strictEqual(
139
+ inputObject.foo['$bar.baz$'],
140
+ 'test',
141
+ `bad value ${inputObject.foo['$bar.baz$']} for the method execution inputObject.foo['$bar.baz$'], expected ${'test'}`
142
+ );
143
+ });
144
+ it('should execute successfully, set the child field and return true if the field exists in the parent, there is an $$ in the path, there are no arrays in the path and the $$ item is not the last item', function () {
145
+ const inputObject = { foo: { '$bar.baz$': { boo: 'oldTest' } } } as any,
146
+ result = setNested(inputObject, 'foo.$bar.baz$.boo', 'test');
147
+ assert.strictEqual(result, true, `bad value ${result} for the method execution result, expected ${true}`);
148
+ assert.strictEqual(
149
+ inputObject.foo['$bar.baz$'].boo,
150
+ 'test',
151
+ `bad value ${inputObject.foo['$bar.baz$'].boo} for the method execution inputObject.foo['$bar.baz$'].boo, expected ${'test'}`
152
+ );
153
+ });
154
+ it('should execute successfully, set the child field and return true if the field exists in the parent, there is an $$ in the path, there are arrays in the path and an index for them is provided', function () {
155
+ const inputObject = { foo: [{ '$bar.baz$': 'test1' }, { '$bar.baz$': 'test2' }] },
156
+ result = setNested(inputObject, 'foo.0.$bar.baz$', 'test');
157
+ assert.strictEqual(result, true, `bad value ${result} for the method execution result, expected ${true}`);
158
+ assert.strictEqual(
159
+ inputObject.foo[0]['$bar.baz$'],
160
+ 'test',
161
+ `bad value ${inputObject.foo[0]['$bar.baz$']} for the method execution inputObject.foo[0]['$bar.baz$'], expected ${'test'}`
162
+ );
163
+ assert.strictEqual(
164
+ inputObject.foo[1]['$bar.baz$'],
165
+ 'test2',
166
+ `bad value ${inputObject.foo[1]['$bar.baz$']} for the method execution inputObject.foo[1]['$bar.baz$'], expected ${'test2'}`
167
+ );
168
+ });
169
+ it('should execute successfully, set the child field and return true if the field exists in the parent, there is an $$ in the path, there are arrays in the path and an index for them is not provided', function () {
170
+ const inputObject = { foo: [{ '$bar.baz$': 'test1' }, { '$bar.baz$': 'test2' }] },
171
+ result = setNested(inputObject, 'foo.$bar.baz$', 'test');
172
+ assert.strictEqual(result, true, `bad value ${result} for the method execution result, expected ${true}`);
173
+ assert.strictEqual(
174
+ inputObject.foo[0]['$bar.baz$'],
175
+ 'test',
176
+ `bad value ${inputObject.foo[0]['$bar.baz$']} for the method execution inputObject.foo[0]['$bar.baz$'], expected ${'test'}`
177
+ );
178
+ assert.strictEqual(
179
+ inputObject.foo[1]['$bar.baz$'],
180
+ 'test',
181
+ `bad value ${inputObject.foo[1]['$bar.baz$']} for the method execution inputObject.foo[1]['$bar.baz$'], expected ${'test'}`
182
+ );
183
+ });
184
+ });
@@ -0,0 +1,154 @@
1
+ import { GenericObject } from '../../common/definitions';
2
+
3
+ export interface DataBulkCreatePrivateOptions extends GenericObject {
4
+ processInputAllowedFieldsEnabled?: boolean;
5
+ }
6
+
7
+ export interface DataCountOptions {
8
+ filters?: GenericObject;
9
+ findAll?: boolean;
10
+ include?: string[];
11
+ withDeleted?: boolean;
12
+ }
13
+
14
+ export interface DataCountPrivateOptions extends GenericObject {
15
+ allowCountWithoutFilters?: boolean;
16
+ processFiltersAllowedFieldsEnabled?: boolean;
17
+ }
18
+
19
+ export interface DataCreatePrivateOptions {
20
+ processInputAllowedFieldsEnabled?: boolean;
21
+ }
22
+
23
+ export interface DataDefaultData<Entity> {
24
+ BulkCreate: Partial<Entity>[];
25
+ Create: Partial<Entity>;
26
+ Update: Partial<Entity>;
27
+ }
28
+
29
+ export interface DataDeleteOptions {
30
+ filters: GenericObject;
31
+ returnOriginalItems?: boolean;
32
+ softDelete?: boolean;
33
+ }
34
+
35
+ export interface DataDeletePrivateOptions extends GenericObject {
36
+ processFiltersAllowedFieldsEnabled?: boolean;
37
+ requirePrimaryKeys?: boolean;
38
+ }
39
+
40
+ export interface DataDeleteResult<Item> {
41
+ count?: number;
42
+ originalItems?: Item[];
43
+ }
44
+
45
+ export interface DataFindOneOptions {
46
+ filters: GenericObject;
47
+ include?: string[];
48
+ orderBy?: GenericObject<DataOrderByDirection>;
49
+ select?: string[];
50
+ selectOperator?: DataSelectOperator;
51
+ withDeleted?: boolean;
52
+ }
53
+
54
+ export interface DataFindOnePrivateOptions extends GenericObject {
55
+ processFiltersAllowedFieldsEnabled?: boolean;
56
+ }
57
+
58
+ export interface DataFindOptions {
59
+ filters?: GenericObject;
60
+ findAll?: boolean;
61
+ getTotalCount?: boolean;
62
+ include?: string[];
63
+ individualSearch?: boolean;
64
+ orderBy?: GenericObject<DataOrderByDirection>;
65
+ page?: number;
66
+ perPage?: number;
67
+ select?: string[];
68
+ withDeleted?: boolean;
69
+ }
70
+
71
+ export interface DataFindPrivateOptions extends GenericObject {
72
+ processFiltersAllowedFieldsEnabled?: boolean;
73
+ }
74
+
75
+ export interface DataFindResults<Item> {
76
+ items: Item[];
77
+ more: boolean;
78
+ page: number;
79
+ perPage: number;
80
+ totalCount?: number;
81
+ }
82
+
83
+ export type DataRelationItem<Data> = {
84
+ deleted?: boolean;
85
+ } & Data;
86
+
87
+ export interface DataOrderBy {
88
+ field: string;
89
+ direction: DataOrderByDirection;
90
+ }
91
+
92
+ export enum DataOrderByDirection {
93
+ // eslint-disable-next-line no-unused-vars
94
+ Asc = 'ASC',
95
+ // eslint-disable-next-line no-unused-vars
96
+ Desc = 'DESC'
97
+ }
98
+
99
+ export enum DataSelectOperator {
100
+ // eslint-disable-next-line no-unused-vars
101
+ Between = '$between',
102
+ // eslint-disable-next-line no-unused-vars
103
+ Contains = '$contains',
104
+ // eslint-disable-next-line no-unused-vars
105
+ Equals = '$eq',
106
+ // eslint-disable-next-line no-unused-vars
107
+ GreaterThan = '$gt',
108
+ // eslint-disable-next-line no-unused-vars
109
+ GreaterThanOrEqual = '$gte',
110
+ // eslint-disable-next-line no-unused-vars
111
+ LessThan = '$lt',
112
+ // eslint-disable-next-line no-unused-vars
113
+ LessThanOrEqual = '$lte',
114
+ // eslint-disable-next-line no-unused-vars
115
+ Like = '$like',
116
+ // eslint-disable-next-line no-unused-vars
117
+ ILike = '$ilike',
118
+ // eslint-disable-next-line no-unused-vars
119
+ Not = '$not',
120
+ // eslint-disable-next-line no-unused-vars
121
+ Or = '$or'
122
+ }
123
+
124
+ export interface DataUpdateOptions {
125
+ filters: GenericObject;
126
+ returnData?: boolean;
127
+ returnOriginalItems?: boolean;
128
+ }
129
+
130
+ export interface DataUpdatePrivateOptions extends GenericObject {
131
+ processFiltersAllowedFieldsEnabled?: boolean;
132
+ processInputAllowedFieldsEnabled?: boolean;
133
+ requirePrimaryKeys?: boolean;
134
+ withDeleted?: boolean;
135
+ }
136
+
137
+ export interface DataUpdateResult<Item> {
138
+ count?: number;
139
+ items?: Item[];
140
+ originalItems?: Item[];
141
+ }
142
+
143
+ export interface ProcessObjectAllowedFieldsOptions {
144
+ allowedFields: string[];
145
+ isEnabled?: boolean;
146
+ objectType: string;
147
+ }
148
+
149
+ export enum ProcessObjectAllowedFieldsType {
150
+ // eslint-disable-next-line no-unused-vars
151
+ Filters = 'processFiltersAllowedFieldsEnabled',
152
+ // eslint-disable-next-line no-unused-vars
153
+ Input = 'processInputAllowedFieldsEnabled'
154
+ }
@@ -0,0 +1,112 @@
1
+ import { beforeEach, describe, expect, it } from 'vitest';
2
+
3
+ import { DataEntityService } from './data.entity.service';
4
+ import {
5
+ DataDeleteOptions,
6
+ DataFindOneOptions,
7
+ DataFindOptions,
8
+ DataUpdateOptions
9
+ } from './data.entity.service.definitions';
10
+
11
+ import { ApplicationError } from '../../common/definitions';
12
+
13
+ // Define a dummy entity interface for testing.
14
+ interface DummyEntity {
15
+ id: number;
16
+ value: string;
17
+ }
18
+
19
+ // Optionally, define a subclass that does not override the methods.
20
+ class DummyDataEntityService extends DataEntityService<DummyEntity> {}
21
+
22
+ describe('DataEntityService Base Class', () => {
23
+ let service: DataEntityService<DummyEntity>;
24
+
25
+ beforeEach(() => {
26
+ service = new DataEntityService<DummyEntity>();
27
+ });
28
+
29
+ describe('bulkCreate', () => {
30
+ it('should throw an ApplicationError with "bulkCreate" in the message', async () => {
31
+ await expect(service.bulkCreate([{ id: 1, value: 'test' }])).rejects.toThrow(ApplicationError);
32
+ await expect(service.bulkCreate([{ id: 1, value: 'test' }])).rejects.toThrow(/bulkCreate/);
33
+ });
34
+ });
35
+
36
+ describe('create', () => {
37
+ it('should throw an ApplicationError with "create" in the message', async () => {
38
+ await expect(service.create({ id: 2, value: 'test' })).rejects.toThrow(ApplicationError);
39
+ await expect(service.create({ id: 2, value: 'test' })).rejects.toThrow(/create/);
40
+ });
41
+ });
42
+
43
+ describe('count', () => {
44
+ it('should throw an ApplicationError with "count" in the message', async () => {
45
+ const dummyOptions: DataFindOptions = {} as DataFindOptions;
46
+ await expect(service.count(dummyOptions)).rejects.toThrow(ApplicationError);
47
+ await expect(service.count(dummyOptions)).rejects.toThrow(/count/);
48
+ });
49
+ });
50
+
51
+ describe('delete', () => {
52
+ it('should throw an ApplicationError with "delete" in the message', () => {
53
+ const dummyOptions: DataDeleteOptions = {} as DataDeleteOptions;
54
+ expect(() => service.delete(dummyOptions)).toThrow(ApplicationError);
55
+ expect(() => service.delete(dummyOptions)).toThrow(/delete/);
56
+ });
57
+ });
58
+
59
+ describe('find', () => {
60
+ it('should throw an ApplicationError with "find" in the message', () => {
61
+ const dummyOptions: DataFindOptions = {} as DataFindOptions;
62
+ expect(() => service.find(dummyOptions)).toThrow(ApplicationError);
63
+ expect(() => service.find(dummyOptions)).toThrow(/find/);
64
+ });
65
+ });
66
+
67
+ describe('findOne', () => {
68
+ it('should throw an ApplicationError with "findOne" in the message', () => {
69
+ const dummyOptions: DataFindOneOptions = {} as DataFindOneOptions;
70
+ expect(() => service.findOne(dummyOptions)).toThrow(ApplicationError);
71
+ expect(() => service.findOne(dummyOptions)).toThrow(/findOne/);
72
+ });
73
+ });
74
+
75
+ describe('update', () => {
76
+ it('should throw an ApplicationError with "update" in the message', async () => {
77
+ const dummyData: DummyEntity = { id: 3, value: 'test' };
78
+ const dummyOptions: DataUpdateOptions = {} as DataUpdateOptions;
79
+ await expect(service.update(dummyData, dummyOptions)).rejects.toThrow(ApplicationError);
80
+ await expect(service.update(dummyData, dummyOptions)).rejects.toThrow(/update/);
81
+ });
82
+ });
83
+ });
84
+
85
+ describe('DummyDataEntityService Subclass', () => {
86
+ let service: DummyDataEntityService;
87
+
88
+ beforeEach(() => {
89
+ service = new DummyDataEntityService();
90
+ });
91
+ it('bulkCreate should throw an error with "bulkCreate" in the message', async () => {
92
+ await expect(service.bulkCreate([{ id: 10, value: 'dummy' }])).rejects.toThrow(/bulkCreate/);
93
+ });
94
+ it('create should throw an error with "create" in the message', async () => {
95
+ await expect(service.create({ id: 11, value: 'dummy' })).rejects.toThrow(/create/);
96
+ });
97
+ it('count should throw an error with "count" in the message', async () => {
98
+ await expect(service.count({} as DataFindOptions)).rejects.toThrow(/count/);
99
+ });
100
+ it('delete should throw an error with "delete" in the message', () => {
101
+ expect(() => service.delete({} as DataDeleteOptions)).toThrow(/delete/);
102
+ });
103
+ it('find should throw an error with "find" in the message', () => {
104
+ expect(() => service.find({} as DataFindOptions)).toThrow(/find/);
105
+ });
106
+ it('findOne should throw an error with "findOne" in the message', () => {
107
+ expect(() => service.findOne({} as DataFindOneOptions)).toThrow(/findOne/);
108
+ });
109
+ it('update should throw an error with "update" in the message', async () => {
110
+ await expect(service.update({ id: 12, value: 'dummy' }, {} as DataUpdateOptions)).rejects.toThrow(/update/);
111
+ });
112
+ });
@@ -0,0 +1,144 @@
1
+ import {
2
+ DataBulkCreatePrivateOptions,
3
+ DataCountPrivateOptions,
4
+ DataCreatePrivateOptions,
5
+ DataDefaultData,
6
+ DataDeleteOptions,
7
+ DataDeletePrivateOptions,
8
+ DataDeleteResult,
9
+ DataFindOneOptions,
10
+ DataFindOnePrivateOptions,
11
+ DataFindOptions,
12
+ DataFindPrivateOptions,
13
+ DataFindResults,
14
+ DataUpdateOptions,
15
+ DataUpdatePrivateOptions,
16
+ DataUpdateResult,
17
+ ProcessObjectAllowedFieldsOptions
18
+ } from './data.entity.service.definitions';
19
+
20
+ import {
21
+ AppConfigCommonData,
22
+ AppConfigCommonDataEntityServiceSettings,
23
+ ConfigProviderService
24
+ } from '../../common/configProvider';
25
+ import { ApplicationError } from '../../common/definitions';
26
+
27
+ /*
28
+ * This class is used as a unifying abstraction between RDB and non-RDB entities. It can be used
29
+ * to define classes that are agnostic of the type of persitance.
30
+ */
31
+ export abstract class DataEntityService<Entity, Data extends DataDefaultData<Entity> = DataDefaultData<Entity>> {
32
+ protected settings: AppConfigCommonDataEntityServiceSettings;
33
+
34
+ constructor(
35
+ protected configProvider: ConfigProviderService,
36
+ protected dataModuleName: string
37
+ ) {
38
+ const { settingsPerEntity } = configProvider.config.data[dataModuleName] as AppConfigCommonData;
39
+ this.settings = settingsPerEntity || {};
40
+ }
41
+
42
+ public async bulkCreate(
43
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
44
+ _data: Data['BulkCreate'],
45
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
46
+ _options?: unknown,
47
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
48
+ _privateOptions?: DataBulkCreatePrivateOptions
49
+ ): Promise<Entity[]> {
50
+ throw new ApplicationError(`Method bulkCreate not implemented for class ${typeof this}.`);
51
+ }
52
+
53
+ public async count(
54
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
55
+ _options: DataFindOptions,
56
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
57
+ _privateOptions?: DataCountPrivateOptions
58
+ ): Promise<number | undefined> {
59
+ throw new ApplicationError(`Method count not implemented for class ${typeof this}.`);
60
+ }
61
+
62
+ public async create(
63
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
64
+ _data: Data['Create'],
65
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
66
+ _options?: unknown,
67
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
68
+ _privateOptions?: DataCreatePrivateOptions
69
+ ): Promise<Entity> {
70
+ throw new ApplicationError(`Method create not implemented for class ${typeof this}.`);
71
+ }
72
+
73
+ public delete(
74
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
75
+ _options: DataDeleteOptions,
76
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
77
+ _privateOptions?: DataDeletePrivateOptions
78
+ ): Promise<DataDeleteResult<Entity>> {
79
+ throw new ApplicationError(`Method delete not implemented for class ${typeof this}.`);
80
+ }
81
+
82
+ public find(
83
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
84
+ _options: DataFindOptions,
85
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
86
+ _privateOptions?: DataFindPrivateOptions
87
+ ): Promise<DataFindResults<Entity>> {
88
+ throw new ApplicationError(`Method find not implemented for class ${typeof this}.`);
89
+ }
90
+
91
+ public findOne(
92
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
93
+ _options: DataFindOneOptions,
94
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
95
+ _privateOptions?: DataFindOnePrivateOptions
96
+ ): Promise<Entity | null> {
97
+ throw new ApplicationError(`Method findOne not implemented for class ${typeof this}.`);
98
+ }
99
+
100
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
101
+ public getEntityName(noError?: boolean): string | null {
102
+ if (noError) {
103
+ return null;
104
+ }
105
+ throw new ApplicationError(`Method getEntityName not implemented for class ${typeof this}.`);
106
+ }
107
+
108
+ // TODO: handle relations' fields
109
+ protected async processObjectAllowedFields<Data = Partial<Entity>>(
110
+ data: Data | Data[],
111
+ options: ProcessObjectAllowedFieldsOptions
112
+ ): Promise<Data | Data[]> {
113
+ const { settings } = this;
114
+ const { allowedFields, isEnabled, objectType } = options;
115
+ if (isEnabled === false || (typeof isEnabled === 'undefined' && !settings[objectType as keyof typeof settings])) {
116
+ return data;
117
+ }
118
+ const actualData = data instanceof Array ? data : [data];
119
+ const processedData: Data[] = [];
120
+ actualData.forEach(dataItem => {
121
+ const processedDataItem = {} as Data;
122
+ allowedFields.forEach(fieldName => {
123
+ const typedFieldName = fieldName as unknown as keyof Data;
124
+ const value = dataItem[typedFieldName];
125
+ if (typeof value !== 'undefined') {
126
+ processedDataItem[typedFieldName] = value;
127
+ }
128
+ });
129
+ processedData.push(processedDataItem);
130
+ });
131
+ return processedData.length === 1 ? processedData[0] : processedData;
132
+ }
133
+
134
+ public async update(
135
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
136
+ _data: Data['Update'],
137
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
138
+ _options: DataUpdateOptions,
139
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
140
+ _privateOptions?: DataUpdatePrivateOptions
141
+ ): Promise<DataUpdateResult<Entity>> {
142
+ throw new ApplicationError(`Method update not implemented for class ${typeof this}.`);
143
+ }
144
+ }
@@ -0,0 +1,2 @@
1
+ export * from './data.entity.service';
2
+ export * from './data.entity.service.definitions';