@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.
- package/coverage/src/app.ts.html +349 -0
- package/coverage/src/common/configProvider/configProvider.module.ts.html +160 -0
- package/coverage/src/common/configProvider/configProvider.service.ts.html +658 -0
- package/coverage/src/common/configProvider/index.html +146 -0
- package/coverage/src/common/configProvider/index.ts.html +94 -0
- package/coverage/src/common/definitions/common.constants.ts.html +160 -0
- package/coverage/src/common/definitions/common.errors.ts.html +124 -0
- package/coverage/src/common/definitions/index.html +146 -0
- package/coverage/src/common/definitions/index.ts.html +94 -0
- package/coverage/src/common/utils/index.html +131 -0
- package/coverage/src/common/utils/index.ts.html +88 -0
- package/coverage/src/common/utils/utils.loadDynamicModules.ts.html +265 -0
- package/coverage/src/domain/entityService/domain.entity.service.ts.html +784 -0
- package/coverage/src/domain/entityService/index.html +131 -0
- package/coverage/src/domain/entityService/index.ts.html +91 -0
- package/coverage/src/index.html +116 -0
- package/coverage/src/persistance/entityService/index.html +131 -0
- package/coverage/src/persistance/entityService/index.ts.html +91 -0
- package/coverage/src/persistance/entityService/persistance.entity.service.ts.html +268 -0
- package/dist/app.d.ts +2 -2
- package/dist/app.js +27 -15
- package/dist/app.js.map +1 -1
- package/dist/common/configProvider/configProvider.definitions.d.ts +156 -20
- package/dist/common/configProvider/configProvider.definitions.js +21 -7
- package/dist/common/configProvider/configProvider.definitions.js.map +1 -1
- package/dist/common/configProvider/configProvider.module.js +13 -2
- package/dist/common/configProvider/configProvider.module.js.map +1 -1
- package/dist/common/configProvider/configProvider.service.js +21 -18
- package/dist/common/configProvider/configProvider.service.js.map +1 -1
- package/dist/common/definitions/common.constants.d.ts +2 -1
- package/dist/common/definitions/common.constants.js +1 -0
- package/dist/common/definitions/common.constants.js.map +1 -1
- package/dist/common/utils/base64UrlEncode/base64UrlEncode.method.d.ts +1 -0
- package/dist/common/utils/base64UrlEncode/base64UrlEncode.method.js +9 -0
- package/dist/common/utils/base64UrlEncode/base64UrlEncode.method.js.map +1 -0
- package/dist/common/utils/base64UrlEncode/index.d.ts +1 -0
- package/dist/{persistance/entityService → common/utils/base64UrlEncode}/index.js +1 -2
- package/dist/common/utils/base64UrlEncode/index.js.map +1 -0
- package/dist/common/utils/getNested/getNested.definitions.d.ts +4 -0
- package/dist/common/utils/getNested/getNested.definitions.js +3 -0
- package/dist/common/utils/getNested/getNested.definitions.js.map +1 -0
- package/dist/common/utils/getNested/getNested.method.d.ts +6 -0
- package/dist/common/utils/getNested/getNested.method.js +88 -0
- package/dist/common/utils/getNested/getNested.method.js.map +1 -0
- package/dist/common/utils/getNested/index.d.ts +2 -0
- package/dist/common/utils/getNested/index.js +19 -0
- package/dist/common/utils/getNested/index.js.map +1 -0
- package/dist/common/utils/httpRequest/httpRequest.definitions.d.ts +19 -0
- package/dist/common/utils/httpRequest/httpRequest.definitions.js +3 -0
- package/dist/common/utils/httpRequest/httpRequest.definitions.js.map +1 -0
- package/dist/common/utils/httpRequest/httpRequest.method.d.ts +2 -0
- package/dist/common/utils/httpRequest/httpRequest.method.js +56 -0
- package/dist/common/utils/httpRequest/httpRequest.method.js.map +1 -0
- package/dist/common/utils/httpRequest/index.d.ts +2 -0
- package/dist/common/utils/httpRequest/index.js +19 -0
- package/dist/common/utils/httpRequest/index.js.map +1 -0
- package/dist/common/utils/index.d.ts +5 -1
- package/dist/common/utils/index.js +5 -1
- package/dist/common/utils/index.js.map +1 -1
- package/dist/common/utils/loadDynamicModules/index.d.ts +1 -0
- package/dist/common/utils/loadDynamicModules/index.js +18 -0
- package/dist/common/utils/loadDynamicModules/index.js.map +1 -0
- package/dist/common/utils/{utils.loadDynamicModules.d.ts → loadDynamicModules/utils.loadDynamicModules.d.ts} +1 -1
- package/dist/common/utils/loadDynamicModules/utils.loadDynamicModules.js.map +1 -0
- package/dist/common/utils/setNested/index.d.ts +2 -0
- package/dist/common/utils/setNested/index.js +19 -0
- package/dist/common/utils/setNested/index.js.map +1 -0
- package/dist/common/utils/setNested/setNested.definitions.d.ts +4 -0
- package/dist/common/utils/setNested/setNested.definitions.js +3 -0
- package/dist/common/utils/setNested/setNested.definitions.js.map +1 -0
- package/dist/common/utils/setNested/setNested.method.d.ts +2 -0
- package/dist/common/utils/setNested/setNested.method.js +70 -0
- package/dist/common/utils/setNested/setNested.method.js.map +1 -0
- package/dist/data/entityService/data.entity.service.d.ts +17 -0
- package/dist/data/entityService/data.entity.service.definitions.d.ts +117 -0
- package/dist/data/entityService/data.entity.service.definitions.js +28 -0
- package/dist/data/entityService/data.entity.service.definitions.js.map +1 -0
- package/dist/{persistance/entityService/persistance.entity.service.js → data/entityService/data.entity.service.js} +41 -9
- package/dist/data/entityService/data.entity.service.js.map +1 -0
- package/dist/data/entityService/index.d.ts +2 -0
- package/dist/data/entityService/index.js +19 -0
- package/dist/data/entityService/index.js.map +1 -0
- package/dist/domain/entityService/domain.entity.service.d.ts +28 -13
- package/dist/domain/entityService/domain.entity.service.definitions.d.ts +26 -19
- package/dist/domain/entityService/domain.entity.service.definitions.js +6 -6
- package/dist/domain/entityService/domain.entity.service.definitions.js.map +1 -1
- package/dist/domain/entityService/domain.entity.service.js +77 -69
- package/dist/domain/entityService/domain.entity.service.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +11 -10
- package/src/app.spec.ts +138 -0
- package/src/app.ts +115 -0
- package/src/common/configProvider/configProvider.definitions.ts +445 -0
- package/src/common/configProvider/configProvider.module.spec.ts +90 -0
- package/src/common/configProvider/configProvider.module.ts +25 -0
- package/src/common/configProvider/configProvider.service.spec.ts +206 -0
- package/src/common/configProvider/configProvider.service.ts +204 -0
- package/src/common/configProvider/index.ts +3 -0
- package/src/common/definitions/common.constants.ts +27 -0
- package/src/common/definitions/common.definitions.ts +13 -0
- package/src/common/definitions/common.errors.ts +13 -0
- package/src/common/definitions/index.ts +3 -0
- package/src/common/utils/base64UrlEncode/base64UrlEncode.method.ts +4 -0
- package/src/common/utils/base64UrlEncode/index.ts +1 -0
- package/src/common/utils/getNested/getNested.definitions.ts +4 -0
- package/src/common/utils/getNested/getNested.method.ts +108 -0
- package/src/common/utils/getNested/getNested.spec.ts +151 -0
- package/src/common/utils/getNested/index.ts +2 -0
- package/src/common/utils/httpRequest/httpRequest.definitions.ts +22 -0
- package/src/common/utils/httpRequest/httpRequest.method.ts +46 -0
- package/src/common/utils/httpRequest/index.ts +2 -0
- package/src/common/utils/index.ts +5 -0
- package/src/common/utils/loadDynamicModules/index.ts +1 -0
- package/src/common/utils/loadDynamicModules/utils.loadDynamicModules.spec.ts +111 -0
- package/src/common/utils/loadDynamicModules/utils.loadDynamicModules.ts +69 -0
- package/src/common/utils/setNested/index.ts +2 -0
- package/src/common/utils/setNested/setNested.definitions.ts +4 -0
- package/src/common/utils/setNested/setNested.method.ts +83 -0
- package/src/common/utils/setNested/setNested.spec.ts +184 -0
- package/src/data/entityService/data.entity.service.definitions.ts +154 -0
- package/src/data/entityService/data.entity.service.spec.ts +112 -0
- package/src/data/entityService/data.entity.service.ts +144 -0
- package/src/data/entityService/index.ts +2 -0
- package/src/domain/entityService/domain.entity.service.definitions.ts +142 -0
- package/src/domain/entityService/domain.entity.service.spec.ts +126 -0
- package/src/domain/entityService/domain.entity.service.ts +421 -0
- package/src/domain/entityService/index.ts +2 -0
- package/src/index.ts +6 -0
- package/src/vitest.config.ts +9 -0
- package/dist/common/utils/utils.loadDynamicModules.js.map +0 -1
- package/dist/persistance/entityService/index.d.ts +0 -2
- package/dist/persistance/entityService/index.js.map +0 -1
- package/dist/persistance/entityService/persistance.entity.service.d.ts +0 -11
- package/dist/persistance/entityService/persistance.entity.service.definitions.d.ts +0 -76
- package/dist/persistance/entityService/persistance.entity.service.definitions.js +0 -23
- package/dist/persistance/entityService/persistance.entity.service.definitions.js.map +0 -1
- package/dist/persistance/entityService/persistance.entity.service.js.map +0 -1
- /package/dist/common/utils/{utils.loadDynamicModules.js → loadDynamicModules/utils.loadDynamicModules.js} +0 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { strict as assert } from 'assert';
|
|
2
|
+
|
|
3
|
+
import { getNested } from '../../dist';
|
|
4
|
+
|
|
5
|
+
describe('getNested', function () {
|
|
6
|
+
it('should execute successfully and return undefined if an undefined parent argument is provided', function () {
|
|
7
|
+
const result = getNested(undefined, 'test');
|
|
8
|
+
assert.strictEqual(result, undefined, `bad value ${result} for the method execution result, expected undefined`);
|
|
9
|
+
});
|
|
10
|
+
it('should execute successfully and return undefined if a null parent argument is provided', function () {
|
|
11
|
+
const result = getNested(null, 'test');
|
|
12
|
+
assert.strictEqual(result, undefined, `bad value ${result} for the method execution result, expected undefined`);
|
|
13
|
+
});
|
|
14
|
+
it('should execute successfully and return undefined if an empty string field argument is provided', function () {
|
|
15
|
+
const result = getNested({}, '');
|
|
16
|
+
assert.strictEqual(result, undefined, `bad value ${result} for the method execution result, expected undefined`);
|
|
17
|
+
});
|
|
18
|
+
it('should execute successfully and return undefined if the field does not exist in the parent at the top level', function () {
|
|
19
|
+
const result = getNested({}, 'foo.bar');
|
|
20
|
+
assert.strictEqual(result, undefined, `bad value ${result} for the method execution result, expected undefined`);
|
|
21
|
+
});
|
|
22
|
+
it('should execute successfully and return the child field if the field does exist in the parent and there are no arrays in the path', function () {
|
|
23
|
+
const result = getNested({ foo: { bar: 'test' } }, 'foo.bar');
|
|
24
|
+
assert.strictEqual(result, 'test', `bad value ${result} for the method execution result, expected ${'test'}`);
|
|
25
|
+
});
|
|
26
|
+
it('should execute successfully and return the child field if the field does exist in the parent, there are arrays in the path and an index is provided', function () {
|
|
27
|
+
const result = getNested(
|
|
28
|
+
{ foo: [{ bar: 'test' }, { bar: 'test2' }, { bar: 'test' }, { bar: 'test3' }] },
|
|
29
|
+
'foo.0.bar'
|
|
30
|
+
);
|
|
31
|
+
assert.strictEqual(result, 'test', `bad value ${result} for result, expected ${'test'}`);
|
|
32
|
+
});
|
|
33
|
+
it('should execute successfully and return the child field if the field does exist in the parent, there are arrays in the path, no index is provided and arrayItemsShouldBeUnique is not provided', function () {
|
|
34
|
+
const result = getNested(
|
|
35
|
+
{ foo: [{ bar: 'test' }, { bar: 'test2' }, { bar: 'test' }, { bar: 'test3' }, { ab: 'test4' }] },
|
|
36
|
+
'foo.bar'
|
|
37
|
+
);
|
|
38
|
+
assert.strictEqual(result.length, 4, `bad value ${result.length} for result.length, expected ${4}`);
|
|
39
|
+
assert.strictEqual(result[0], 'test', `bad value ${result[0]} for result[0], expected ${'test'}`);
|
|
40
|
+
assert.strictEqual(result[1], 'test2', `bad value ${result[1]} for result[1], expected ${'test2'}`);
|
|
41
|
+
assert.strictEqual(result[2], 'test', `bad value ${result[2]} for result[2], expected ${'test'}`);
|
|
42
|
+
assert.strictEqual(result[3], 'test3', `bad value ${result[3]} for result[3], expected ${'test3'}`);
|
|
43
|
+
});
|
|
44
|
+
it('should execute successfully and return the child field if the field does exist in the parent, there are arrays in the path, no index is provided and arrayItemsShouldBeUnique is set to true', function () {
|
|
45
|
+
const result = getNested(
|
|
46
|
+
{ foo: [{ bar: 'test' }, { bar: 'test2' }, { bar: 'test' }, { bar: 'test3' }] },
|
|
47
|
+
'foo.bar',
|
|
48
|
+
{
|
|
49
|
+
arrayItemsShouldBeUnique: true
|
|
50
|
+
}
|
|
51
|
+
);
|
|
52
|
+
assert.strictEqual(result.length, 3, `bad value ${result.length} for result.length, expected ${3}`);
|
|
53
|
+
assert.strictEqual(result[0], 'test', `bad value ${result[0]} for result[0], expected ${'test'}`);
|
|
54
|
+
assert.strictEqual(result[1], 'test2', `bad value ${result[1]} for result[1], expected ${'test2'}`);
|
|
55
|
+
assert.strictEqual(result[2], 'test3', `bad value ${result[2]} for result[2], expected ${'test3'}`);
|
|
56
|
+
});
|
|
57
|
+
it('should execute successfully and return the child field if the field does exist in the parent, it has an $ in the field name and there are no arrays in the path', function () {
|
|
58
|
+
const result = getNested({ foo: { $bar: { q: 'test' } } }, 'foo.$bar.q');
|
|
59
|
+
assert.strictEqual(result, 'test', `bad value ${result} for the method execution result, expected ${'test'}`);
|
|
60
|
+
});
|
|
61
|
+
it('should execute successfully and return the child field if the field does exist in the parent, it has an $ in the field name, there are arrays in the path and arrayItemsShouldBeUnique is not provided', function () {
|
|
62
|
+
const result = getNested(
|
|
63
|
+
{ foo: [{ $bar: { q: 'test' } }, { $bar: { q: 'test2' } }, { $bar: { q: 'test' } }, { $bar: { q: 'test3' } }] },
|
|
64
|
+
'foo.$bar.q'
|
|
65
|
+
);
|
|
66
|
+
assert.strictEqual(result.length, 4, `bad value ${result.length} for result.length, expected ${4}`);
|
|
67
|
+
assert.strictEqual(result[0], 'test', `bad value ${result[0]} for result[0], expected ${'test'}`);
|
|
68
|
+
assert.strictEqual(result[1], 'test2', `bad value ${result[1]} for result[1], expected ${'test2'}`);
|
|
69
|
+
assert.strictEqual(result[2], 'test', `bad value ${result[2]} for result[2], expected ${'test'}`);
|
|
70
|
+
assert.strictEqual(result[3], 'test3', `bad value ${result[3]} for result[3], expected ${'test3'}`);
|
|
71
|
+
});
|
|
72
|
+
it('should execute successfully and return the child field if the field does exist in the parent, it has an $ in the field name, there are arrays in the path and arrayItemsShouldBeUnique is set to true', function () {
|
|
73
|
+
const result = getNested(
|
|
74
|
+
{ foo: [{ $bar: { q: 'test' } }, { $bar: { q: 'test2' } }, { $bar: { q: 'test' } }, { $bar: { q: 'test3' } }] },
|
|
75
|
+
'foo.$bar.q',
|
|
76
|
+
{ arrayItemsShouldBeUnique: true }
|
|
77
|
+
);
|
|
78
|
+
assert.strictEqual(result.length, 3, `bad value ${result.length} for result.length, expected ${3}`);
|
|
79
|
+
assert.strictEqual(result[0], 'test', `bad value ${result[0]} for result[0], expected ${'test'}`);
|
|
80
|
+
assert.strictEqual(result[1], 'test2', `bad value ${result[1]} for result[1], expected ${'test2'}`);
|
|
81
|
+
assert.strictEqual(result[2], 'test3', `bad value ${result[2]} for result[2], expected ${'test3'}`);
|
|
82
|
+
});
|
|
83
|
+
it('should execute successfully and return the child field if the field does exist in the parent, it has an $$ in the field name and there are no arrays in the path', function () {
|
|
84
|
+
const result = getNested({ foo: { '$bar.baz$': { q: 'test' } } }, 'foo.$bar.baz$.q');
|
|
85
|
+
assert.strictEqual(result, 'test', `bad value ${result} for the method execution result, expected ${'test'}`);
|
|
86
|
+
});
|
|
87
|
+
it('should execute successfully and return the child field if the field does exist in the parent, it has an $$ in the field name, there are no arrays in the path and there is a $ variable name', function () {
|
|
88
|
+
const result = getNested({ foo: { $bar: { '$p.baz$': { q: 'test' } } } }, 'foo.$bar.$p.baz$.q');
|
|
89
|
+
assert.strictEqual(result, 'test', `bad value ${result} for the method execution result, expected ${'test'}`);
|
|
90
|
+
});
|
|
91
|
+
it('should execute successfully and return the child field if the field does exist in the parent, it has an $$ in the field name, there are arrays in the path and arrayItemsShouldBeUnique is not provided', function () {
|
|
92
|
+
const result = getNested(
|
|
93
|
+
{
|
|
94
|
+
foo: [
|
|
95
|
+
{ '$bar.baz$': { q: 'test' } },
|
|
96
|
+
{ '$bar.baz$': { q: 'test2' } },
|
|
97
|
+
{ '$bar.baz$': { q: 'test' } },
|
|
98
|
+
{ '$bar.baz$': { q: 'test3' } }
|
|
99
|
+
]
|
|
100
|
+
},
|
|
101
|
+
'foo.$bar.baz$.q'
|
|
102
|
+
);
|
|
103
|
+
assert.strictEqual(result.length, 4, `bad value ${result.length} for result.length, expected ${4}`);
|
|
104
|
+
assert.strictEqual(result[0], 'test', `bad value ${result[0]} for result[0], expected ${'test'}`);
|
|
105
|
+
assert.strictEqual(result[1], 'test2', `bad value ${result[1]} for result[1], expected ${'test2'}`);
|
|
106
|
+
assert.strictEqual(result[2], 'test', `bad value ${result[2]} for result[2], expected ${'test'}`);
|
|
107
|
+
assert.strictEqual(result[3], 'test3', `bad value ${result[3]} for result[3], expected ${'test3'}`);
|
|
108
|
+
});
|
|
109
|
+
it('should execute successfully and return the child field if the field does exist in the parent, it has an $$ in the field name, there are arrays in the path and arrayItemsShouldBeUnique is set to true', function () {
|
|
110
|
+
const result = getNested(
|
|
111
|
+
{
|
|
112
|
+
foo: [
|
|
113
|
+
{ '$bar.baz$': { q: 'test' } },
|
|
114
|
+
{ '$bar.baz$': { q: 'test2' } },
|
|
115
|
+
{ '$bar.baz$': { q: 'test' } },
|
|
116
|
+
{ '$bar.baz$': { q: 'test3' } }
|
|
117
|
+
]
|
|
118
|
+
},
|
|
119
|
+
'foo.$bar.baz$.q',
|
|
120
|
+
{ arrayItemsShouldBeUnique: true }
|
|
121
|
+
);
|
|
122
|
+
assert.strictEqual(result.length, 3, `bad value ${result.length} for result.length, expected ${3}`);
|
|
123
|
+
assert.strictEqual(result[0], 'test', `bad value ${result[0]} for result[0], expected ${'test'}`);
|
|
124
|
+
assert.strictEqual(result[1], 'test2', `bad value ${result[1]} for result[1], expected ${'test2'}`);
|
|
125
|
+
assert.strictEqual(result[2], 'test3', `bad value ${result[2]} for result[2], expected ${'test3'}`);
|
|
126
|
+
});
|
|
127
|
+
it('should execute successfully and return the child field if the field does exist in the parent and the last element is an array', function () {
|
|
128
|
+
const result = getNested({ foo: { bar: [] } }, 'foo.bar');
|
|
129
|
+
assert(result instanceof Array, `bad value ${result} for the method execution result, expected an array`);
|
|
130
|
+
});
|
|
131
|
+
it('should execute successfully and return the child field if the field does exist in the parent, an inner element is an array and arrayItemsShouldBeUnique is not provided', function () {
|
|
132
|
+
const result = getNested({ foo: { bar: [{ baz: [{ q: 10 }] }, { baz: { q: 11 } }] } }, 'foo.bar.baz.q');
|
|
133
|
+
assert(result instanceof Array, `bad value ${result} for the method execution result, expected an array`);
|
|
134
|
+
assert.strictEqual(result.length, 2, `bad value ${result.length} for result.length, expected ${2}`);
|
|
135
|
+
assert.strictEqual(result[0], 10, `bad value ${result[0]} for result[0], expected ${10}`);
|
|
136
|
+
assert.strictEqual(result[1], 11, `bad value ${result[1]} for result[1], expected ${11}`);
|
|
137
|
+
});
|
|
138
|
+
it('should execute successfully and return the child field if the field does exist in the parent, an inner element is an array and arrayItemsShouldBeUnique is set to true', function () {
|
|
139
|
+
const result = getNested(
|
|
140
|
+
{ foo: { bar: [{ baz: [{ q: 10 }, { q: 12 }, { q: 13 }, { q: 12 }] }, { baz: { q: 11 } }] } },
|
|
141
|
+
'foo.bar.baz.q',
|
|
142
|
+
{ arrayItemsShouldBeUnique: true }
|
|
143
|
+
);
|
|
144
|
+
assert(result instanceof Array, `bad value ${result} for the method execution result, expected an array`);
|
|
145
|
+
assert.strictEqual(result.length, 4, `bad value ${result.length} for result.length, expected ${2}`);
|
|
146
|
+
assert.strictEqual(result[0], 10, `bad value ${result[0]} for result[0], expected ${10}`);
|
|
147
|
+
assert.strictEqual(result[1], 12, `bad value ${result[1]} for result[1], expected ${12}`);
|
|
148
|
+
assert.strictEqual(result[2], 13, `bad value ${result[2]} for result[2], expected ${13}`);
|
|
149
|
+
assert.strictEqual(result[3], 11, `bad value ${result[3]} for result[3], expected ${11}`);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
+
|
|
3
|
+
import { GenericObject, HttpMethod } from '../../definitions';
|
|
4
|
+
|
|
5
|
+
export interface HTTPRequestData {
|
|
6
|
+
axiosConfig?: Partial<AxiosRequestConfig>;
|
|
7
|
+
body?: GenericObject<unknown>;
|
|
8
|
+
headers?: GenericObject<unknown>;
|
|
9
|
+
isFormData?: boolean;
|
|
10
|
+
isJSON?: boolean;
|
|
11
|
+
method?: HttpMethod;
|
|
12
|
+
query?: GenericObject<unknown>;
|
|
13
|
+
returnFullResponse?: boolean;
|
|
14
|
+
throwOnError?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface HTTPRequestResponseData<Data = unknown> {
|
|
18
|
+
data?: Data;
|
|
19
|
+
fullResponse?: Omit<AxiosResponse, 'config' | 'request'>;
|
|
20
|
+
hasError: boolean;
|
|
21
|
+
statusCode: number;
|
|
22
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import axios, { AxiosHeaders } from 'axios';
|
|
2
|
+
import ld from 'lodash';
|
|
3
|
+
|
|
4
|
+
import { HTTPRequestData, HTTPRequestResponseData } from './httpRequest.definitions';
|
|
5
|
+
|
|
6
|
+
import { ApplicationError, GenericObject, HttpMethod } from '../../definitions';
|
|
7
|
+
|
|
8
|
+
export const httpRequest = async <ResponseData = unknown>(
|
|
9
|
+
url: string,
|
|
10
|
+
data: HTTPRequestData
|
|
11
|
+
): Promise<HTTPRequestResponseData<ResponseData>> => {
|
|
12
|
+
const { body, query } = data;
|
|
13
|
+
const headers: GenericObject<unknown> = { ...(data.headers || {}) };
|
|
14
|
+
const method = data.method || HttpMethod.GET;
|
|
15
|
+
const requestConfig = {
|
|
16
|
+
...(data.axiosConfig || {}),
|
|
17
|
+
method,
|
|
18
|
+
url
|
|
19
|
+
};
|
|
20
|
+
if (query && method === HttpMethod.GET) {
|
|
21
|
+
requestConfig.params = query;
|
|
22
|
+
} else if (body && method !== HttpMethod.GET) {
|
|
23
|
+
requestConfig.data = body;
|
|
24
|
+
}
|
|
25
|
+
if (data.isJSON) {
|
|
26
|
+
headers['Content-Type'] = 'application/json';
|
|
27
|
+
requestConfig.responseType = 'json';
|
|
28
|
+
} else if (data.isFormData) {
|
|
29
|
+
headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
30
|
+
}
|
|
31
|
+
requestConfig.headers = headers as AxiosHeaders;
|
|
32
|
+
const response = await axios(requestConfig);
|
|
33
|
+
const { status } = response;
|
|
34
|
+
const usefulResponse = ld.omit(response, ['config', 'request']);
|
|
35
|
+
const hasError = status >= 400;
|
|
36
|
+
if (hasError && data.throwOnError) {
|
|
37
|
+
throw new ApplicationError(`An httpRequest error with statusCode ${status} has occurred.`, usefulResponse);
|
|
38
|
+
}
|
|
39
|
+
const returnData: HTTPRequestResponseData<ResponseData> = { hasError, statusCode: status };
|
|
40
|
+
if (data.returnFullResponse) {
|
|
41
|
+
returnData.fullResponse = usefulResponse;
|
|
42
|
+
} else if (response.data) {
|
|
43
|
+
returnData.data = response.data;
|
|
44
|
+
}
|
|
45
|
+
return returnData;
|
|
46
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './utils.loadDynamicModules';
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { DynamicModule, Provider } from '@nestjs/common';
|
|
2
|
+
import { describe, expect, it } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { ProviderWithInjectionToken, loadDynamicModules } from './utils.loadDynamicModules';
|
|
5
|
+
|
|
6
|
+
import { GenericObject } from '../../definitions';
|
|
7
|
+
|
|
8
|
+
describe('loadDynamicModules', () => {
|
|
9
|
+
it('should return undefined for all arrays if folderData is empty', () => {
|
|
10
|
+
const result = loadDynamicModules({});
|
|
11
|
+
expect(result.controllers).toBeUndefined();
|
|
12
|
+
expect(result.entities).toBeUndefined();
|
|
13
|
+
expect(result.modules).toBeUndefined();
|
|
14
|
+
expect(result.services).toBeUndefined();
|
|
15
|
+
});
|
|
16
|
+
it('should skip keys matching /^base(.+)?$/', () => {
|
|
17
|
+
const folderData: GenericObject<unknown> = {
|
|
18
|
+
base: { name: 'base' },
|
|
19
|
+
baseExtra: { name: 'baseExtra' },
|
|
20
|
+
UserController: { name: 'UserController' }
|
|
21
|
+
};
|
|
22
|
+
const result = loadDynamicModules(folderData);
|
|
23
|
+
// Only "UserController" should be processed.
|
|
24
|
+
expect(result.controllers).toHaveLength(1);
|
|
25
|
+
});
|
|
26
|
+
it('should process keys ending with "Controller" and add injection token mapping when provided', () => {
|
|
27
|
+
const controllerWithToken = {
|
|
28
|
+
injectionToken: 'TOKEN_Controller',
|
|
29
|
+
name: 'MyController'
|
|
30
|
+
} as ProviderWithInjectionToken;
|
|
31
|
+
const controllerWithoutToken = {
|
|
32
|
+
name: 'OtherController'
|
|
33
|
+
} as ProviderWithInjectionToken;
|
|
34
|
+
const folderData: GenericObject<unknown> = {
|
|
35
|
+
MyController: controllerWithToken,
|
|
36
|
+
OtherController: controllerWithoutToken
|
|
37
|
+
};
|
|
38
|
+
const result = loadDynamicModules(folderData);
|
|
39
|
+
// For controller keys, if injectionToken is present, the function pushes a mapped provider and then the original.
|
|
40
|
+
expect(result.controllers).toHaveLength(3);
|
|
41
|
+
// Verify that one of the controllers is an object with a "provide" property matching the injection token.
|
|
42
|
+
const tokenProviders = result.controllers?.filter(c => typeof c === 'object' && 'provide' in c) as Provider[];
|
|
43
|
+
expect(tokenProviders).toHaveLength(1);
|
|
44
|
+
expect(tokenProviders[0]).toHaveProperty('provide', 'TOKEN_Controller');
|
|
45
|
+
});
|
|
46
|
+
it('should process keys ending with "Entity"', () => {
|
|
47
|
+
const entity1 = { id: 1 };
|
|
48
|
+
const entity2 = { id: 2 };
|
|
49
|
+
const folderData: GenericObject<unknown> = {
|
|
50
|
+
UserEntity: entity1,
|
|
51
|
+
OrderEntity: entity2
|
|
52
|
+
};
|
|
53
|
+
const result = loadDynamicModules(folderData);
|
|
54
|
+
expect(result.entities).toHaveLength(2);
|
|
55
|
+
expect(result.entities).toEqual([entity1, entity2]);
|
|
56
|
+
});
|
|
57
|
+
it('should process keys ending with "Module" as DynamicModule', () => {
|
|
58
|
+
const module1: DynamicModule = { module: (() => {}) as unknown as DynamicModule['module'] };
|
|
59
|
+
const module2: DynamicModule = { module: (() => {}) as unknown as DynamicModule['module'] };
|
|
60
|
+
const folderData: GenericObject<unknown> = {
|
|
61
|
+
AppModule: module1,
|
|
62
|
+
FeatureModule: module2
|
|
63
|
+
};
|
|
64
|
+
const result = loadDynamicModules(folderData);
|
|
65
|
+
expect(result.modules).toHaveLength(2);
|
|
66
|
+
expect(result.modules).toEqual([module1, module2]);
|
|
67
|
+
});
|
|
68
|
+
it('should process keys ending with "Service" and add injection token mapping when provided', () => {
|
|
69
|
+
const serviceWithToken = {
|
|
70
|
+
injectionToken: 'TOKEN_Service',
|
|
71
|
+
name: 'MyService'
|
|
72
|
+
} as ProviderWithInjectionToken;
|
|
73
|
+
const serviceWithoutToken = {
|
|
74
|
+
name: 'OtherService'
|
|
75
|
+
} as ProviderWithInjectionToken;
|
|
76
|
+
const folderData: GenericObject<unknown> = {
|
|
77
|
+
MyService: serviceWithToken,
|
|
78
|
+
OtherService: serviceWithoutToken
|
|
79
|
+
};
|
|
80
|
+
const result = loadDynamicModules(folderData);
|
|
81
|
+
// Expect two entries for MyService (mapped + original) and one for OtherService.
|
|
82
|
+
expect(result.services).toHaveLength(3);
|
|
83
|
+
const tokenProviders = result.services?.filter(s => typeof s === 'object' && 'provide' in s) as Provider[];
|
|
84
|
+
expect(tokenProviders).toHaveLength(1);
|
|
85
|
+
expect(tokenProviders[0]).toHaveProperty('provide', 'TOKEN_Service');
|
|
86
|
+
});
|
|
87
|
+
it('should ignore keys that do not match any expected pattern', () => {
|
|
88
|
+
const folderData: GenericObject<unknown> = {
|
|
89
|
+
RandomKey: { data: 123 },
|
|
90
|
+
AnotherKey: { data: 'abc' }
|
|
91
|
+
};
|
|
92
|
+
const result = loadDynamicModules(folderData);
|
|
93
|
+
expect(result.controllers).toBeUndefined();
|
|
94
|
+
expect(result.entities).toBeUndefined();
|
|
95
|
+
expect(result.modules).toBeUndefined();
|
|
96
|
+
expect(result.services).toBeUndefined();
|
|
97
|
+
});
|
|
98
|
+
it('should be case-insensitive for the first letter when matching patterns', () => {
|
|
99
|
+
const folderData: GenericObject<unknown> = {
|
|
100
|
+
usercontroller: { name: 'lowerCaseController' },
|
|
101
|
+
OrderEntity: { id: 10 },
|
|
102
|
+
Featuremodule: { module: (() => {}) as unknown as DynamicModule['module'] },
|
|
103
|
+
paymentService: { name: 'mixedService' }
|
|
104
|
+
};
|
|
105
|
+
const result = loadDynamicModules(folderData);
|
|
106
|
+
expect(result.controllers).toHaveLength(1);
|
|
107
|
+
expect(result.entities).toHaveLength(1);
|
|
108
|
+
expect(result.modules).toHaveLength(1);
|
|
109
|
+
expect(result.services).toHaveLength(1);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ClassProvider, DynamicModule, Provider } from '@nestjs/common';
|
|
2
|
+
|
|
3
|
+
import { GenericObject } from '../../definitions';
|
|
4
|
+
|
|
5
|
+
export type ProviderWithInjectionToken = Provider & {
|
|
6
|
+
injectionToken?: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const loadDynamicModules = (
|
|
10
|
+
folderData: GenericObject<unknown>,
|
|
11
|
+
options?: { moduleRegisterOptions?: unknown; registerOptionsPerModule?: GenericObject }
|
|
12
|
+
): { controllers?: Provider[]; entities?: unknown[]; modules?: DynamicModule[]; services?: Provider[] } => {
|
|
13
|
+
const { moduleRegisterOptions, registerOptionsPerModule } = options || {};
|
|
14
|
+
const controllers: Provider[] = [];
|
|
15
|
+
const entities: unknown[] = [];
|
|
16
|
+
const modules: DynamicModule[] = [];
|
|
17
|
+
const services: Provider[] = [];
|
|
18
|
+
for (const key in folderData) {
|
|
19
|
+
const actualKey = key as keyof typeof folderData;
|
|
20
|
+
if (key.match(/^base(.+)?$/)) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (key.match(/[cC]ontroller$/)) {
|
|
24
|
+
const FolderDataItem = folderData[actualKey] as ProviderWithInjectionToken;
|
|
25
|
+
if (FolderDataItem.injectionToken) {
|
|
26
|
+
controllers.push({
|
|
27
|
+
provide: FolderDataItem.injectionToken,
|
|
28
|
+
useClass: FolderDataItem as ClassProvider['useClass']
|
|
29
|
+
});
|
|
30
|
+
// continue;
|
|
31
|
+
}
|
|
32
|
+
controllers.push(FolderDataItem);
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (key.match(/[eE]ntity$/)) {
|
|
36
|
+
entities.push(folderData[actualKey]);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (key.match(/[mM]odule$/)) {
|
|
40
|
+
const moduleClass = folderData[actualKey] as DynamicModule & {
|
|
41
|
+
register?: (..._args: unknown[]) => DynamicModule;
|
|
42
|
+
};
|
|
43
|
+
modules.push(
|
|
44
|
+
moduleClass.register
|
|
45
|
+
? moduleClass.register(registerOptionsPerModule?.[key] || moduleRegisterOptions)
|
|
46
|
+
: moduleClass
|
|
47
|
+
);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
if (key.match(/[sS]ervice$/)) {
|
|
51
|
+
const FolderDataItem = folderData[actualKey] as ProviderWithInjectionToken;
|
|
52
|
+
if (FolderDataItem.injectionToken) {
|
|
53
|
+
services.push({
|
|
54
|
+
provide: FolderDataItem.injectionToken,
|
|
55
|
+
useClass: FolderDataItem as ClassProvider['useClass']
|
|
56
|
+
});
|
|
57
|
+
// continue;
|
|
58
|
+
}
|
|
59
|
+
services.push(FolderDataItem);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
controllers: controllers.length ? controllers : undefined,
|
|
65
|
+
entities: entities.length ? entities : undefined,
|
|
66
|
+
modules: modules.length ? modules : undefined,
|
|
67
|
+
services: services.length ? services : undefined
|
|
68
|
+
};
|
|
69
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { SetNestedOptions } from './setNested.definitions';
|
|
2
|
+
|
|
3
|
+
// TODO: implement setNestedArraysPerIndex
|
|
4
|
+
/**
|
|
5
|
+
* Sets a value in a deeply nested object, for example foo.bar.0.baz in {foo: {bar: [{baz: 'test'}]}}.
|
|
6
|
+
* @param parent (required) - The object to set the value in.
|
|
7
|
+
* @param field (required) - The path to the field.
|
|
8
|
+
* @param value (required) - The value to set.
|
|
9
|
+
* @returns boolean true if successful, false if not found
|
|
10
|
+
*/
|
|
11
|
+
export function setNested(parent: unknown, field: string, value: unknown, options?: SetNestedOptions): boolean {
|
|
12
|
+
const { removeNestedFieldEscapeSign } = options || {};
|
|
13
|
+
const fieldNames = field.split('.');
|
|
14
|
+
if (field === '' || !fieldNames.length) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
let currentParent = parent;
|
|
18
|
+
let finalResult = false;
|
|
19
|
+
const loopEnd = fieldNames.length - 1;
|
|
20
|
+
for (let i = 0; i <= loopEnd; i++) {
|
|
21
|
+
if (currentParent === null) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
let fieldName = fieldNames[i];
|
|
25
|
+
// TODO: setNested for specific indexes
|
|
26
|
+
// if the current parent is an array and the next field path item is not an index - set the value in all of the array's sub-items
|
|
27
|
+
if (currentParent instanceof Array && isNaN(parseInt(fieldName, 10))) {
|
|
28
|
+
let atLeastOnItemSet = false,
|
|
29
|
+
nestedFieldPath = `${fieldName}`;
|
|
30
|
+
for (let j = i + 1; j <= loopEnd; j++) {
|
|
31
|
+
nestedFieldPath += `.${fieldNames[j]}`;
|
|
32
|
+
}
|
|
33
|
+
currentParent.forEach(item => {
|
|
34
|
+
const result = setNested(item, nestedFieldPath, value);
|
|
35
|
+
if (result && !atLeastOnItemSet) {
|
|
36
|
+
atLeastOnItemSet = true;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return atLeastOnItemSet;
|
|
40
|
+
}
|
|
41
|
+
// logic for handling Sequelize-style $foo.bar$ - should be treated as a single element
|
|
42
|
+
if (fieldName.charAt(0) === '$') {
|
|
43
|
+
let closingBracketFound = false,
|
|
44
|
+
closingBracketIndex = i + 1;
|
|
45
|
+
while (closingBracketIndex <= loopEnd) {
|
|
46
|
+
const element = fieldNames[closingBracketIndex];
|
|
47
|
+
// false alarm - there's another $ opening before the current one closed - so the current one must be just a variable name, not a bracket
|
|
48
|
+
if (element.charAt(0) === '$') {
|
|
49
|
+
break;
|
|
50
|
+
}
|
|
51
|
+
// found it !
|
|
52
|
+
if (element.charAt(element.length - 1) === '$') {
|
|
53
|
+
closingBracketFound = true;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
closingBracketIndex++;
|
|
57
|
+
}
|
|
58
|
+
if (closingBracketFound) {
|
|
59
|
+
for (let j = i + 1; j <= closingBracketIndex; j++) {
|
|
60
|
+
fieldName += `.${fieldNames[j]}`;
|
|
61
|
+
}
|
|
62
|
+
if (removeNestedFieldEscapeSign) {
|
|
63
|
+
fieldName = fieldName.replace(/^\$/, '').replace(/\$$/, '');
|
|
64
|
+
}
|
|
65
|
+
if (closingBracketIndex === loopEnd) {
|
|
66
|
+
(currentParent as Record<string, unknown>)[fieldName] = value;
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
i = closingBracketIndex;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (i === loopEnd) {
|
|
73
|
+
(currentParent as Record<string, unknown>)[fieldName] = value;
|
|
74
|
+
finalResult = true;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
if (typeof (currentParent as Record<string, unknown>)[fieldName] === 'undefined') {
|
|
78
|
+
(currentParent as Record<string, unknown>)[fieldName] = {};
|
|
79
|
+
}
|
|
80
|
+
currentParent = (currentParent as Record<string, unknown>)[fieldName];
|
|
81
|
+
}
|
|
82
|
+
return finalResult;
|
|
83
|
+
}
|