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

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 (160) 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 +10 -9
  21. package/dist/app.js +30 -15
  22. package/dist/app.js.map +1 -1
  23. package/dist/common/configProvider/configProvider.definitions.d.ts +158 -21
  24. package/dist/common/configProvider/configProvider.definitions.js +22 -8
  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 +23 -20
  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/logger/index.d.ts +3 -0
  34. package/dist/common/logger/index.js +20 -0
  35. package/dist/common/logger/index.js.map +1 -0
  36. package/dist/common/logger/logger.definitions.d.ts +4 -0
  37. package/dist/common/logger/logger.definitions.js +3 -0
  38. package/dist/common/logger/logger.definitions.js.map +1 -0
  39. package/dist/common/logger/logger.module.d.ts +5 -0
  40. package/dist/common/logger/logger.module.js +34 -0
  41. package/dist/common/logger/logger.module.js.map +1 -0
  42. package/dist/common/logger/logger.service.d.ts +6 -0
  43. package/dist/common/logger/logger.service.js +56 -0
  44. package/dist/common/logger/logger.service.js.map +1 -0
  45. package/dist/common/utils/base64UrlEncode/base64UrlEncode.method.d.ts +1 -0
  46. package/dist/common/utils/base64UrlEncode/base64UrlEncode.method.js +9 -0
  47. package/dist/common/utils/base64UrlEncode/base64UrlEncode.method.js.map +1 -0
  48. package/dist/common/utils/base64UrlEncode/index.d.ts +1 -0
  49. package/dist/{persistance/entityService → common/utils/base64UrlEncode}/index.js +1 -2
  50. package/dist/common/utils/base64UrlEncode/index.js.map +1 -0
  51. package/dist/common/utils/getNested/getNested.definitions.d.ts +4 -0
  52. package/dist/common/utils/getNested/getNested.definitions.js +3 -0
  53. package/dist/common/utils/getNested/getNested.definitions.js.map +1 -0
  54. package/dist/common/utils/getNested/getNested.method.d.ts +6 -0
  55. package/dist/common/utils/getNested/getNested.method.js +88 -0
  56. package/dist/common/utils/getNested/getNested.method.js.map +1 -0
  57. package/dist/common/utils/getNested/index.d.ts +2 -0
  58. package/dist/common/utils/getNested/index.js +19 -0
  59. package/dist/common/utils/getNested/index.js.map +1 -0
  60. package/dist/common/utils/httpRequest/httpRequest.definitions.d.ts +19 -0
  61. package/dist/common/utils/httpRequest/httpRequest.definitions.js +3 -0
  62. package/dist/common/utils/httpRequest/httpRequest.definitions.js.map +1 -0
  63. package/dist/common/utils/httpRequest/httpRequest.method.d.ts +2 -0
  64. package/dist/common/utils/httpRequest/httpRequest.method.js +56 -0
  65. package/dist/common/utils/httpRequest/httpRequest.method.js.map +1 -0
  66. package/dist/common/utils/httpRequest/index.d.ts +2 -0
  67. package/dist/common/utils/httpRequest/index.js +19 -0
  68. package/dist/common/utils/httpRequest/index.js.map +1 -0
  69. package/dist/common/utils/index.d.ts +5 -1
  70. package/dist/common/utils/index.js +5 -1
  71. package/dist/common/utils/index.js.map +1 -1
  72. package/dist/common/utils/loadDynamicModules/index.d.ts +1 -0
  73. package/dist/common/utils/loadDynamicModules/index.js +18 -0
  74. package/dist/common/utils/loadDynamicModules/index.js.map +1 -0
  75. package/dist/common/utils/{utils.loadDynamicModules.d.ts → loadDynamicModules/utils.loadDynamicModules.d.ts} +1 -1
  76. package/dist/common/utils/loadDynamicModules/utils.loadDynamicModules.js.map +1 -0
  77. package/dist/common/utils/setNested/index.d.ts +2 -0
  78. package/dist/common/utils/setNested/index.js +19 -0
  79. package/dist/common/utils/setNested/index.js.map +1 -0
  80. package/dist/common/utils/setNested/setNested.definitions.d.ts +4 -0
  81. package/dist/common/utils/setNested/setNested.definitions.js +3 -0
  82. package/dist/common/utils/setNested/setNested.definitions.js.map +1 -0
  83. package/dist/common/utils/setNested/setNested.method.d.ts +2 -0
  84. package/dist/common/utils/setNested/setNested.method.js +70 -0
  85. package/dist/common/utils/setNested/setNested.method.js.map +1 -0
  86. package/dist/data/entityService/data.entity.service.d.ts +19 -0
  87. package/dist/data/entityService/data.entity.service.definitions.d.ts +117 -0
  88. package/dist/data/entityService/data.entity.service.definitions.js +28 -0
  89. package/dist/data/entityService/data.entity.service.definitions.js.map +1 -0
  90. package/dist/{persistance/entityService/persistance.entity.service.js → data/entityService/data.entity.service.js} +42 -9
  91. package/dist/data/entityService/data.entity.service.js.map +1 -0
  92. package/dist/data/entityService/index.d.ts +2 -0
  93. package/dist/data/entityService/index.js +19 -0
  94. package/dist/data/entityService/index.js.map +1 -0
  95. package/dist/domain/entityService/domain.entity.service.d.ts +30 -13
  96. package/dist/domain/entityService/domain.entity.service.definitions.d.ts +26 -19
  97. package/dist/domain/entityService/domain.entity.service.definitions.js +6 -6
  98. package/dist/domain/entityService/domain.entity.service.definitions.js.map +1 -1
  99. package/dist/domain/entityService/domain.entity.service.js +78 -69
  100. package/dist/domain/entityService/domain.entity.service.js.map +1 -1
  101. package/dist/index.d.ts +2 -1
  102. package/dist/index.js +2 -1
  103. package/dist/index.js.map +1 -1
  104. package/dist/scripts/generateDatasourceFiles.d.ts +1 -0
  105. package/dist/scripts/generateDatasourceFiles.js +94 -0
  106. package/dist/scripts/generateDatasourceFiles.js.map +1 -0
  107. package/package.json +17 -9
  108. package/src/app.spec.ts +138 -0
  109. package/src/app.ts +120 -0
  110. package/src/common/configProvider/configProvider.definitions.ts +444 -0
  111. package/src/common/configProvider/configProvider.module.spec.ts +90 -0
  112. package/src/common/configProvider/configProvider.module.ts +25 -0
  113. package/src/common/configProvider/configProvider.service.spec.ts +206 -0
  114. package/src/common/configProvider/configProvider.service.ts +204 -0
  115. package/src/common/configProvider/index.ts +3 -0
  116. package/src/common/definitions/common.constants.ts +27 -0
  117. package/src/common/definitions/common.definitions.ts +13 -0
  118. package/src/common/definitions/common.errors.ts +13 -0
  119. package/src/common/definitions/index.ts +3 -0
  120. package/src/common/logger/index.ts +3 -0
  121. package/src/common/logger/logger.definitions.ts +5 -0
  122. package/src/common/logger/logger.module.ts +21 -0
  123. package/src/common/logger/logger.service.ts +40 -0
  124. package/src/common/utils/base64UrlEncode/base64UrlEncode.method.ts +4 -0
  125. package/src/common/utils/base64UrlEncode/index.ts +1 -0
  126. package/src/common/utils/getNested/getNested.definitions.ts +4 -0
  127. package/src/common/utils/getNested/getNested.method.ts +108 -0
  128. package/src/common/utils/getNested/getNested.spec.ts +151 -0
  129. package/src/common/utils/getNested/index.ts +2 -0
  130. package/src/common/utils/httpRequest/httpRequest.definitions.ts +22 -0
  131. package/src/common/utils/httpRequest/httpRequest.method.ts +46 -0
  132. package/src/common/utils/httpRequest/index.ts +2 -0
  133. package/src/common/utils/index.ts +5 -0
  134. package/src/common/utils/loadDynamicModules/index.ts +1 -0
  135. package/src/common/utils/loadDynamicModules/utils.loadDynamicModules.spec.ts +111 -0
  136. package/src/common/utils/loadDynamicModules/utils.loadDynamicModules.ts +69 -0
  137. package/src/common/utils/setNested/index.ts +2 -0
  138. package/src/common/utils/setNested/setNested.definitions.ts +4 -0
  139. package/src/common/utils/setNested/setNested.method.ts +83 -0
  140. package/src/common/utils/setNested/setNested.spec.ts +184 -0
  141. package/src/data/entityService/data.entity.service.definitions.ts +154 -0
  142. package/src/data/entityService/data.entity.service.spec.ts +112 -0
  143. package/src/data/entityService/data.entity.service.ts +147 -0
  144. package/src/data/entityService/index.ts +2 -0
  145. package/src/domain/entityService/domain.entity.service.definitions.ts +142 -0
  146. package/src/domain/entityService/domain.entity.service.spec.ts +126 -0
  147. package/src/domain/entityService/domain.entity.service.ts +424 -0
  148. package/src/domain/entityService/index.ts +2 -0
  149. package/src/index.ts +7 -0
  150. package/src/scripts/generateDatasourceFiles.ts +59 -0
  151. package/src/vitest.config.ts +9 -0
  152. package/dist/common/utils/utils.loadDynamicModules.js.map +0 -1
  153. package/dist/persistance/entityService/index.d.ts +0 -2
  154. package/dist/persistance/entityService/index.js.map +0 -1
  155. package/dist/persistance/entityService/persistance.entity.service.d.ts +0 -11
  156. package/dist/persistance/entityService/persistance.entity.service.definitions.d.ts +0 -76
  157. package/dist/persistance/entityService/persistance.entity.service.definitions.js +0 -23
  158. package/dist/persistance/entityService/persistance.entity.service.definitions.js.map +0 -1
  159. package/dist/persistance/entityService/persistance.entity.service.js.map +0 -1
  160. /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,147 @@
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
+ import { LoggerService } from '../../common/logger';
27
+
28
+ /*
29
+ * This class is used as a unifying abstraction between RDB and non-RDB entities. It can be used
30
+ * to define classes that are agnostic of the type of persitance.
31
+ */
32
+ export abstract class DataEntityService<Entity, Data extends DataDefaultData<Entity> = DataDefaultData<Entity>> {
33
+ protected settings: AppConfigCommonDataEntityServiceSettings;
34
+
35
+ constructor(
36
+ protected configProvider: ConfigProviderService,
37
+ protected dataModuleName: string,
38
+ // eslint-disable-next-line no-unused-vars
39
+ protected logger: LoggerService
40
+ ) {
41
+ const { settingsPerEntity } = configProvider.config.data[dataModuleName] as AppConfigCommonData;
42
+ this.settings = settingsPerEntity || {};
43
+ }
44
+
45
+ public async bulkCreate(
46
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
47
+ _data: Data['BulkCreate'],
48
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
49
+ _options?: unknown,
50
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
51
+ _privateOptions?: DataBulkCreatePrivateOptions
52
+ ): Promise<Entity[]> {
53
+ throw new ApplicationError(`Method bulkCreate not implemented for class ${typeof this}.`);
54
+ }
55
+
56
+ public async count(
57
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
58
+ _options: DataFindOptions,
59
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
60
+ _privateOptions?: DataCountPrivateOptions
61
+ ): Promise<number | undefined> {
62
+ throw new ApplicationError(`Method count not implemented for class ${typeof this}.`);
63
+ }
64
+
65
+ public async create(
66
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
67
+ _data: Data['Create'],
68
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
69
+ _options?: unknown,
70
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
71
+ _privateOptions?: DataCreatePrivateOptions
72
+ ): Promise<Entity> {
73
+ throw new ApplicationError(`Method create not implemented for class ${typeof this}.`);
74
+ }
75
+
76
+ public delete(
77
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
78
+ _options: DataDeleteOptions,
79
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
80
+ _privateOptions?: DataDeletePrivateOptions
81
+ ): Promise<DataDeleteResult<Entity>> {
82
+ throw new ApplicationError(`Method delete not implemented for class ${typeof this}.`);
83
+ }
84
+
85
+ public find(
86
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
87
+ _options: DataFindOptions,
88
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
89
+ _privateOptions?: DataFindPrivateOptions
90
+ ): Promise<DataFindResults<Entity>> {
91
+ throw new ApplicationError(`Method find not implemented for class ${typeof this}.`);
92
+ }
93
+
94
+ public findOne(
95
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
96
+ _options: DataFindOneOptions,
97
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
98
+ _privateOptions?: DataFindOnePrivateOptions
99
+ ): Promise<Entity | null> {
100
+ throw new ApplicationError(`Method findOne not implemented for class ${typeof this}.`);
101
+ }
102
+
103
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
104
+ public getEntityName(noError?: boolean): string | null {
105
+ if (noError) {
106
+ return null;
107
+ }
108
+ throw new ApplicationError(`Method getEntityName not implemented for class ${typeof this}.`);
109
+ }
110
+
111
+ // TODO: handle relations' fields
112
+ protected async processObjectAllowedFields<Data = Partial<Entity>>(
113
+ data: Data | Data[],
114
+ options: ProcessObjectAllowedFieldsOptions
115
+ ): Promise<Data | Data[]> {
116
+ const { settings } = this;
117
+ const { allowedFields, isEnabled, objectType } = options;
118
+ if (isEnabled === false || (typeof isEnabled === 'undefined' && !settings[objectType as keyof typeof settings])) {
119
+ return data;
120
+ }
121
+ const actualData = data instanceof Array ? data : [data];
122
+ const processedData: Data[] = [];
123
+ actualData.forEach(dataItem => {
124
+ const processedDataItem = {} as Data;
125
+ allowedFields.forEach(fieldName => {
126
+ const typedFieldName = fieldName as unknown as keyof Data;
127
+ const value = dataItem[typedFieldName];
128
+ if (typeof value !== 'undefined') {
129
+ processedDataItem[typedFieldName] = value;
130
+ }
131
+ });
132
+ processedData.push(processedDataItem);
133
+ });
134
+ return processedData.length === 1 ? processedData[0] : processedData;
135
+ }
136
+
137
+ public async update(
138
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
139
+ _data: Data['Update'],
140
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
141
+ _options: DataUpdateOptions,
142
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
143
+ _privateOptions?: DataUpdatePrivateOptions
144
+ ): Promise<DataUpdateResult<Entity>> {
145
+ throw new ApplicationError(`Method update not implemented for class ${typeof this}.`);
146
+ }
147
+ }
@@ -0,0 +1,2 @@
1
+ export * from './data.entity.service';
2
+ export * from './data.entity.service.definitions';