@koalarx/nest 3.0.3 → 3.0.4
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/core/backgroud-services/cron-service/cron-job.handler.base.d.ts +16 -0
- package/core/backgroud-services/cron-service/cron-job.handler.base.js +49 -0
- package/core/backgroud-services/event-service/event-class.d.ts +5 -0
- package/core/backgroud-services/event-service/event-class.js +11 -0
- package/core/backgroud-services/event-service/event-handler.base.d.ts +8 -0
- package/core/backgroud-services/event-service/event-handler.base.js +14 -0
- package/core/backgroud-services/event-service/event-is-trigger.d.ts +3 -0
- package/core/backgroud-services/event-service/event-is-trigger.js +7 -0
- package/core/backgroud-services/event-service/event-job.d.ts +13 -0
- package/core/backgroud-services/event-service/event-job.js +21 -0
- package/core/backgroud-services/event-service/event-queue.d.ts +17 -0
- package/core/backgroud-services/event-service/event-queue.js +62 -0
- package/core/constants/query-params.d.ts +6 -0
- package/core/constants/query-params.js +8 -0
- package/core/controllers/base.controller.d.ts +4 -0
- package/core/controllers/base.controller.js +6 -0
- package/core/controllers/controller.decorator.d.ts +2 -0
- package/core/controllers/controller.decorator.js +11 -0
- package/core/controllers/created-registre-response.base.d.ts +10 -0
- package/core/controllers/created-registre-response.base.js +35 -0
- package/core/controllers/list-response.base.d.ts +4 -0
- package/core/controllers/list-response.base.js +21 -0
- package/core/controllers/pagination.request.d.ts +10 -0
- package/core/controllers/pagination.request.js +56 -0
- package/core/controllers/router-config.base.d.ts +7 -0
- package/core/controllers/router-config.base.js +18 -0
- package/core/controllers/schemas/boolean.schema.d.ts +2 -0
- package/core/controllers/schemas/boolean.schema.js +12 -0
- package/core/controllers/schemas/document-number.schema.d.ts +1 -0
- package/core/controllers/schemas/document-number.schema.js +26 -0
- package/core/controllers/schemas/email.schema.d.ts +1 -0
- package/core/controllers/schemas/email.schema.js +13 -0
- package/core/controllers/schemas/list-query.schema.d.ts +17 -0
- package/core/controllers/schemas/list-query.schema.js +19 -0
- package/core/controllers/schemas/native-enum.schema.d.ts +7 -0
- package/core/controllers/schemas/native-enum.schema.js +28 -0
- package/core/controllers/schemas/set-mask-document-number.schema.d.ts +1 -0
- package/core/controllers/schemas/set-mask-document-number.schema.js +13 -0
- package/core/database/entity.base.d.ts +20 -0
- package/core/database/entity.base.js +71 -0
- package/core/database/entity.decorator.d.ts +13 -0
- package/core/database/entity.decorator.js +23 -0
- package/core/database/prisma-client-with-custom-transaction.interface.d.ts +8 -0
- package/core/database/prisma-client-with-custom-transaction.interface.js +2 -0
- package/core/database/prisma-resolver.d.ts +2 -0
- package/core/database/prisma-resolver.js +74 -0
- package/core/database/prisma-transactional-client.d.ts +11 -0
- package/core/database/prisma-transactional-client.js +25 -0
- package/core/database/prisma.service.d.ts +24 -0
- package/core/database/prisma.service.js +104 -0
- package/core/database/repository.base.d.ts +44 -0
- package/core/database/repository.base.js +360 -0
- package/core/dtos/pagination.dto.d.ts +9 -0
- package/core/dtos/pagination.dto.js +49 -0
- package/core/errors/bad-request.error.d.ts +5 -0
- package/core/errors/bad-request.error.js +10 -0
- package/core/errors/conflict.error.d.ts +4 -0
- package/core/errors/conflict.error.js +10 -0
- package/core/errors/error.base.d.ts +4 -0
- package/core/errors/error.base.js +11 -0
- package/core/errors/no-content.error.d.ts +5 -0
- package/core/errors/no-content.error.js +10 -0
- package/core/errors/not-allowed.error.d.ts +5 -0
- package/core/errors/not-allowed.error.js +10 -0
- package/core/errors/resource-not-found.error.d.ts +5 -0
- package/core/errors/resource-not-found.error.js +10 -0
- package/{src/core/errors/use-case-error.ts → core/errors/use-case-error.d.ts} +1 -1
- package/core/errors/use-case-error.js +2 -0
- package/core/errors/user-already-exist.error.d.ts +4 -0
- package/core/errors/user-already-exist.error.js +10 -0
- package/core/errors/wrong-credentials.error.d.ts +4 -0
- package/core/errors/wrong-credentials.error.js +10 -0
- package/core/health-check/health-check.controller.d.ts +5 -0
- package/core/health-check/health-check.controller.js +32 -0
- package/core/health-check/health-check.module.d.ts +2 -0
- package/core/health-check/health-check.module.js +19 -0
- package/core/index.d.ts +18 -0
- package/core/index.js +7 -0
- package/core/koala-app.d.ts +64 -0
- package/core/koala-app.js +252 -0
- package/core/koala-global-vars.d.ts +7 -0
- package/core/koala-global-vars.js +9 -0
- package/core/koala-nest-database.module.d.ts +16 -0
- package/core/koala-nest-database.module.js +52 -0
- package/core/koala-nest-http.module.d.ts +13 -0
- package/core/koala-nest-http.module.js +37 -0
- package/core/koala-nest.module.d.ts +17 -0
- package/core/koala-nest.module.js +66 -0
- package/core/mapping/auto-mapping-class-context.d.ts +16 -0
- package/core/mapping/auto-mapping-class-context.js +18 -0
- package/core/mapping/auto-mapping-context.d.ts +11 -0
- package/core/mapping/auto-mapping-context.js +24 -0
- package/core/mapping/auto-mapping-list.d.ts +27 -0
- package/core/mapping/auto-mapping-list.js +94 -0
- package/core/mapping/auto-mapping-profile.d.ts +3 -0
- package/core/mapping/auto-mapping-profile.js +6 -0
- package/core/mapping/auto-mapping.decorator.d.ts +9 -0
- package/core/mapping/auto-mapping.decorator.js +27 -0
- package/core/mapping/auto-mapping.module.d.ts +5 -0
- package/core/mapping/auto-mapping.module.js +29 -0
- package/core/mapping/auto-mapping.service.d.ts +14 -0
- package/core/mapping/auto-mapping.service.js +140 -0
- package/core/mapping/create-map.d.ts +3 -0
- package/core/mapping/create-map.js +7 -0
- package/core/mapping/for-member.d.ts +5 -0
- package/core/mapping/for-member.js +8 -0
- package/core/request-overflow/request-handler.base.d.ts +4 -0
- package/core/request-overflow/request-handler.base.js +6 -0
- package/core/request-overflow/request-result.d.ts +15 -0
- package/core/request-overflow/request-result.js +37 -0
- package/core/request-overflow/request-validator.base.d.ts +7 -0
- package/core/request-overflow/request-validator.base.js +26 -0
- package/core/security/strategies/api-key.strategy.d.ts +16 -0
- package/core/security/strategies/api-key.strategy.js +31 -0
- package/core/utils/assing-object.d.ts +5 -0
- package/core/utils/assing-object.js +6 -0
- package/core/utils/env.config.d.ts +6 -0
- package/core/utils/env.config.js +18 -0
- package/core/utils/filter-request-params.d.ts +13 -0
- package/core/utils/filter-request-params.js +22 -0
- package/core/utils/find-on-list.d.ts +2 -0
- package/core/utils/find-on-list.js +13 -0
- package/core/utils/get-type-by-prop.d.ts +2 -0
- package/core/utils/get-type-by-prop.js +11 -0
- package/core/utils/instanciate-class-with-dependencies-injection.d.ts +2 -0
- package/core/utils/instanciate-class-with-dependencies-injection.js +10 -0
- package/core/utils/interfaces/icomparable.d.ts +5 -0
- package/core/utils/interfaces/icomparable.js +6 -0
- package/core/utils/list.d.ts +39 -0
- package/core/utils/list.js +168 -0
- package/core/utils/promise-all.d.ts +7 -0
- package/core/utils/promise-all.js +19 -0
- package/core/utils/set-mask-document-number.d.ts +1 -0
- package/core/utils/set-mask-document-number.js +13 -0
- package/core/validators/file-validator.d.ts +27 -0
- package/core/validators/file-validator.js +94 -0
- package/decorators/api-exclude-endpoint-diff-develop.decorator.d.ts +1 -0
- package/decorators/api-exclude-endpoint-diff-develop.decorator.js +9 -0
- package/decorators/api-property-enum.decorator.d.ts +8 -0
- package/decorators/api-property-enum.decorator.js +21 -0
- package/decorators/api-property-only-develop.decorator.d.ts +2 -0
- package/decorators/api-property-only-develop.decorator.js +9 -0
- package/decorators/cookies.decorator.d.ts +1 -0
- package/decorators/cookies.decorator.js +8 -0
- package/decorators/is-public.decorator.d.ts +2 -0
- package/decorators/is-public.decorator.js +7 -0
- package/decorators/upload.decorator.d.ts +1 -0
- package/decorators/upload.decorator.js +18 -0
- package/env/env.d.ts +25 -0
- package/env/env.js +14 -0
- package/env/env.module.d.ts +2 -0
- package/env/env.module.js +20 -0
- package/env/env.service.d.ts +7 -0
- package/env/env.service.js +28 -0
- package/filters/domain-errors.filter.d.ts +18 -0
- package/filters/domain-errors.filter.js +92 -0
- package/filters/global-exception.filter.d.ts +8 -0
- package/filters/global-exception.filter.js +68 -0
- package/filters/prisma-validation-exception.filter.d.ts +10 -0
- package/filters/prisma-validation-exception.filter.js +82 -0
- package/filters/zod-errors.filter.d.ts +9 -0
- package/filters/zod-errors.filter.js +60 -0
- package/package.json +4 -1
- package/services/logging/ilogging.service.d.ts +16 -0
- package/services/logging/ilogging.service.js +6 -0
- package/services/logging/logging.service.d.ts +4 -0
- package/services/logging/logging.service.js +20 -0
- package/services/redis/iredis.service.d.ts +6 -0
- package/services/redis/iredis.service.js +6 -0
- package/services/redis/redis.service.d.ts +14 -0
- package/services/redis/redis.service.js +65 -0
- package/services/redlock/ired-lock.service.d.ts +4 -0
- package/services/redlock/ired-lock.service.js +6 -0
- package/services/redlock/red-lock.service.d.ts +9 -0
- package/services/redlock/red-lock.service.js +46 -0
- package/test/koala-app-test-dependencies.d.ts +10 -0
- package/test/koala-app-test-dependencies.js +13 -0
- package/test/koala-app-test.d.ts +22 -0
- package/test/koala-app-test.js +77 -0
- package/test/repositories/in-memory-base.repository.d.ts +17 -0
- package/test/repositories/in-memory-base.repository.js +65 -0
- package/test/services/fake-logging.service.d.ts +4 -0
- package/test/services/fake-logging.service.js +9 -0
- package/test/services/fake-red-lock.service.d.ts +5 -0
- package/test/services/fake-red-lock.service.js +11 -0
- package/test/utils/create-e2e-database.d.ts +2 -0
- package/test/utils/create-e2e-database.js +47 -0
- package/test/utils/drop-e2e-database.d.ts +2 -0
- package/test/utils/drop-e2e-database.js +33 -0
- package/test/utils/wait-for.d.ts +1 -0
- package/test/utils/wait-for.js +21 -0
- package/tsconfig.lib.tsbuildinfo +1 -0
- package/CHANGELOG.md +0 -27
- package/src/core/backgroud-services/cron-service/cron-job.handler.base.ts +0 -66
- package/src/core/backgroud-services/cron-service/cron-job.handler.spec.ts +0 -38
- package/src/core/backgroud-services/event-service/event-class.ts +0 -5
- package/src/core/backgroud-services/event-service/event-handler.base.ts +0 -17
- package/src/core/backgroud-services/event-service/event-is-trigger.ts +0 -3
- package/src/core/backgroud-services/event-service/event-job.ts +0 -28
- package/src/core/backgroud-services/event-service/event-queue.spec.ts +0 -47
- package/src/core/backgroud-services/event-service/event-queue.ts +0 -107
- package/src/core/constants/query-params.ts +0 -7
- package/src/core/controllers/base.controller.ts +0 -9
- package/src/core/controllers/controller.decorator.ts +0 -10
- package/src/core/controllers/created-registre-response.base.ts +0 -17
- package/src/core/controllers/list-response.base.ts +0 -8
- package/src/core/controllers/pagination.request.ts +0 -41
- package/src/core/controllers/router-config.base.ts +0 -14
- package/src/core/controllers/schemas/boolean.schema.ts +0 -10
- package/src/core/controllers/schemas/document-number.schema.ts +0 -23
- package/src/core/controllers/schemas/email.schema.ts +0 -13
- package/src/core/controllers/schemas/list-query.schema.ts +0 -17
- package/src/core/controllers/schemas/native-enum.schema.ts +0 -34
- package/src/core/controllers/schemas/set-mask-document-number.schema.ts +0 -13
- package/src/core/database/entity.base.ts +0 -95
- package/src/core/database/entity.decorator.spec.ts +0 -71
- package/src/core/database/entity.decorator.ts +0 -39
- package/src/core/database/prisma-client-with-custom-transaction.interface.ts +0 -13
- package/src/core/database/prisma-resolver.ts +0 -99
- package/src/core/database/prisma-transactional-client.ts +0 -43
- package/src/core/database/prisma.service.ts +0 -136
- package/src/core/database/repository.base.ts +0 -548
- package/src/core/dtos/pagination.dto.ts +0 -35
- package/src/core/errors/bad-request.error.ts +0 -8
- package/src/core/errors/conflict.error.ts +0 -7
- package/src/core/errors/error.base.ts +0 -5
- package/src/core/errors/no-content.error.ts +0 -8
- package/src/core/errors/not-allowed.error.ts +0 -8
- package/src/core/errors/resource-not-found.error.ts +0 -8
- package/src/core/errors/user-already-exist.error.ts +0 -7
- package/src/core/errors/wrong-credentials.error.ts +0 -7
- package/src/core/health-check/health-check.controller.ts +0 -13
- package/src/core/health-check/health-check.module.ts +0 -7
- package/src/core/index.ts +0 -56
- package/src/core/koala-app.ts +0 -379
- package/src/core/koala-global-vars.ts +0 -8
- package/src/core/koala-nest-database.module.ts +0 -65
- package/src/core/koala-nest-http.module.ts +0 -44
- package/src/core/koala-nest.module.ts +0 -67
- package/src/core/mapping/auto-mapping-class-context.ts +0 -28
- package/src/core/mapping/auto-mapping-context.ts +0 -26
- package/src/core/mapping/auto-mapping-list.ts +0 -154
- package/src/core/mapping/auto-mapping-profile.ts +0 -3
- package/src/core/mapping/auto-mapping.decorator.ts +0 -54
- package/src/core/mapping/auto-mapping.module.ts +0 -17
- package/src/core/mapping/auto-mapping.service.ts +0 -187
- package/src/core/mapping/create-map.ts +0 -11
- package/src/core/mapping/for-member.ts +0 -16
- package/src/core/request-overflow/request-handler.base.ts +0 -8
- package/src/core/request-overflow/request-result.spec.ts +0 -23
- package/src/core/request-overflow/request-result.ts +0 -41
- package/src/core/request-overflow/request-validator.base.ts +0 -33
- package/src/core/security/strategies/api-key.strategy.ts +0 -45
- package/src/core/utils/assing-object.ts +0 -9
- package/src/core/utils/env.config.ts +0 -17
- package/src/core/utils/filter-request-params.ts +0 -23
- package/src/core/utils/find-on-list.ts +0 -18
- package/src/core/utils/get-type-by-prop.ts +0 -9
- package/src/core/utils/instanciate-class-with-dependencies-injection.ts +0 -12
- package/src/core/utils/interfaces/icomparable.ts +0 -6
- package/src/core/utils/list.spec.ts +0 -81
- package/src/core/utils/list.ts +0 -223
- package/src/core/utils/promise-all.ts +0 -24
- package/src/core/utils/set-mask-document-number.ts +0 -13
- package/src/core/validators/file-validator.ts +0 -113
- package/src/decorators/api-exclude-endpoint-diff-develop.decorator.ts +0 -15
- package/src/decorators/api-property-enum.decorator.ts +0 -58
- package/src/decorators/api-property-only-develop.decorator.ts +0 -6
- package/src/decorators/cookies.decorator.ts +0 -8
- package/src/decorators/is-public.decorator.ts +0 -5
- package/src/decorators/upload.decorator.ts +0 -31
- package/src/env/env.module.ts +0 -8
- package/src/env/env.service.ts +0 -12
- package/src/env/env.ts +0 -14
- package/src/filters/domain-errors.filter.ts +0 -97
- package/src/filters/global-exception.filter.ts +0 -60
- package/src/filters/prisma-validation-exception.filter.ts +0 -73
- package/src/filters/zod-errors.filter.ts +0 -48
- package/src/services/logging/ilogging.service.ts +0 -17
- package/src/services/logging/logging.service.ts +0 -10
- package/src/services/redis/iredis.service.ts +0 -11
- package/src/services/redis/redis.service.ts +0 -70
- package/src/services/redlock/ired-lock.service.ts +0 -4
- package/src/services/redlock/red-lock.service.ts +0 -36
- package/src/test/koala-app-test-dependencies.ts +0 -15
- package/src/test/koala-app-test.ts +0 -103
- package/src/test/repositories/in-memory-base.repository.ts +0 -90
- package/src/test/services/fake-logging.service.ts +0 -7
- package/src/test/services/fake-red-lock.service.ts +0 -11
- package/src/test/utils/create-e2e-database.ts +0 -55
- package/src/test/utils/drop-e2e-database.ts +0 -36
- package/src/test/utils/wait-for.ts +0 -31
- package/tsconfig.lib.json +0 -11
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { INestApplication } from '@nestjs/common'
|
|
2
|
-
|
|
3
|
-
export function instanciateClassWithDependenciesInjection(
|
|
4
|
-
app: INestApplication,
|
|
5
|
-
Target: any,
|
|
6
|
-
) {
|
|
7
|
-
const dependencies = Reflect.getMetadata('design:paramtypes', Target) ?? []
|
|
8
|
-
const injections = dependencies.map((dependency: any) => {
|
|
9
|
-
return app.get(dependency)
|
|
10
|
-
})
|
|
11
|
-
return new Target(...injections)
|
|
12
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { EntityBase } from '../database/entity.base'
|
|
2
|
-
import { Entity } from '../database/entity.decorator'
|
|
3
|
-
import { AutoMap } from '../mapping/auto-mapping.decorator'
|
|
4
|
-
import { List } from './list'
|
|
5
|
-
|
|
6
|
-
@Entity()
|
|
7
|
-
class EntityTest extends EntityBase<EntityTest> {
|
|
8
|
-
@AutoMap()
|
|
9
|
-
id: number
|
|
10
|
-
|
|
11
|
-
@AutoMap()
|
|
12
|
-
value: number
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
describe('List test', () => {
|
|
16
|
-
let entity: EntityTest
|
|
17
|
-
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
entity = new EntityTest({ id: 1, value: 1 })
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('should add item on list', () => {
|
|
23
|
-
const list = new List<number>()
|
|
24
|
-
list.add(1)
|
|
25
|
-
|
|
26
|
-
expect(list.toArray('added').length).toBe(1)
|
|
27
|
-
expect(list.toArray('added')[0]).toEqual(1)
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('should update item on list', () => {
|
|
31
|
-
const list = new List(EntityTest).setList([entity])
|
|
32
|
-
|
|
33
|
-
entity.value = 2
|
|
34
|
-
|
|
35
|
-
list.add(entity)
|
|
36
|
-
|
|
37
|
-
expect(list.toArray('updated').length).toBe(1)
|
|
38
|
-
expect(list.toArray('updated')[0].value).toEqual(2)
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it('should remove item on list', () => {
|
|
42
|
-
const list = new List(EntityTest).setList([entity])
|
|
43
|
-
|
|
44
|
-
list.remove(entity)
|
|
45
|
-
|
|
46
|
-
expect(list.toArray().length).toBe(0)
|
|
47
|
-
expect(list.toArray('removed').length).toBe(1)
|
|
48
|
-
expect(list.toArray('removed')[0].value).toEqual(1)
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
it('should get item by id', () => {
|
|
52
|
-
const list = new List(EntityTest).setList([entity])
|
|
53
|
-
|
|
54
|
-
expect(list.findById(entity.id)).toEqual(entity)
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
it('should order items', () => {
|
|
58
|
-
const list = new List(EntityTest).setList([
|
|
59
|
-
new EntityTest({ id: 1, value: 3 }),
|
|
60
|
-
new EntityTest({ id: 2, value: 1 }),
|
|
61
|
-
new EntityTest({ id: 3, value: 2 }),
|
|
62
|
-
])
|
|
63
|
-
|
|
64
|
-
list.orderBy('value', 'asc')
|
|
65
|
-
|
|
66
|
-
const orderedValues = list.toArray().map((item) => item.value)
|
|
67
|
-
|
|
68
|
-
expect(orderedValues).toEqual([1, 2, 3])
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('should get first and last items', () => {
|
|
72
|
-
const list = new List(EntityTest).setList([
|
|
73
|
-
new EntityTest({ id: 1, value: 1 }),
|
|
74
|
-
new EntityTest({ id: 2, value: 2 }),
|
|
75
|
-
new EntityTest({ id: 3, value: 3 }),
|
|
76
|
-
])
|
|
77
|
-
|
|
78
|
-
expect(list.first()!.value).toBe(1)
|
|
79
|
-
expect(list.last()!.value).toBe(3)
|
|
80
|
-
})
|
|
81
|
-
})
|
package/src/core/utils/list.ts
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import { Type } from '@nestjs/common'
|
|
2
|
-
import 'reflect-metadata'
|
|
3
|
-
import { EntityBase } from '../database/entity.base'
|
|
4
|
-
import { IComparableId } from './interfaces/icomparable'
|
|
5
|
-
|
|
6
|
-
export type OrderDirection = 'asc' | 'desc'
|
|
7
|
-
export type ListActionType = 'added' | 'updated' | 'removed'
|
|
8
|
-
export interface ListProps<T> {
|
|
9
|
-
list?: T[]
|
|
10
|
-
entityType?: Type<T>
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export class List<T> {
|
|
14
|
-
private _list: T[] = []
|
|
15
|
-
private _addedItemsList: T[] = []
|
|
16
|
-
private _updatedItemsList: T[] = []
|
|
17
|
-
private _removedItemsList: T[] = []
|
|
18
|
-
|
|
19
|
-
constructor(public readonly entityType?: Type<T>) {}
|
|
20
|
-
|
|
21
|
-
private indexOf(item: T, list = this._list) {
|
|
22
|
-
if (item instanceof EntityBase) {
|
|
23
|
-
return list
|
|
24
|
-
.filter((i) => i instanceof EntityBase)
|
|
25
|
-
.filter((i) => !!i._id)
|
|
26
|
-
.findIndex(
|
|
27
|
-
(i) =>
|
|
28
|
-
(item as any)._id === (i as any)._id ||
|
|
29
|
-
(item as any).id === (i as any).id,
|
|
30
|
-
)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return list
|
|
34
|
-
.filter((i) => !(i instanceof EntityBase))
|
|
35
|
-
.findIndex((i) => item === i)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
private contains(item: T, list = this._list): boolean {
|
|
39
|
-
return this.indexOf(item, list) > -1
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
private mapInternalIdIfIsEmpty(list: T[]) {
|
|
43
|
-
return list.map((item) => {
|
|
44
|
-
if (item instanceof EntityBase && !item._id) {
|
|
45
|
-
item._id = (item as any).id
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return item
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
get length() {
|
|
53
|
-
return this._list.length
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
orderBy(by: keyof T, direction: OrderDirection = 'asc') {
|
|
57
|
-
const inverse = direction === 'desc'
|
|
58
|
-
|
|
59
|
-
this._list.sort((a: any, b: any) => {
|
|
60
|
-
if (typeof a !== 'string' && typeof b !== 'string') {
|
|
61
|
-
if ((!inverse && a[by] > b[by]) || (inverse && a[by] < b[by])) {
|
|
62
|
-
return 1
|
|
63
|
-
} else if ((!inverse && a[by] < b[by]) || (inverse && a[by] > b[by])) {
|
|
64
|
-
return -1
|
|
65
|
-
} else {
|
|
66
|
-
return 0
|
|
67
|
-
}
|
|
68
|
-
} else {
|
|
69
|
-
return 0
|
|
70
|
-
}
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
return this
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
first() {
|
|
77
|
-
return this._list[0] ?? null
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
last() {
|
|
81
|
-
return this._list[this._list.length - 1] ?? null
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
findById(id: IComparableId): T | null {
|
|
85
|
-
return (
|
|
86
|
-
this._list
|
|
87
|
-
.filter((item) => item instanceof EntityBase)
|
|
88
|
-
.find((item) => (item as any)._id === id || (item as any).id === id) ??
|
|
89
|
-
null
|
|
90
|
-
)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
findByValue(value: any): T | null {
|
|
94
|
-
return this._list.find((item) => item === value) ?? null
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
setList(list: T[]) {
|
|
98
|
-
this._list = this.mapInternalIdIfIsEmpty(list)
|
|
99
|
-
return this
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
add(item: T) {
|
|
103
|
-
if (this.contains(item)) {
|
|
104
|
-
this._list[this.indexOf(item)] = item
|
|
105
|
-
|
|
106
|
-
if (!this.contains(item, this._updatedItemsList)) {
|
|
107
|
-
this._updatedItemsList.push(item)
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
this._list.push(item)
|
|
114
|
-
this._addedItemsList.push(item)
|
|
115
|
-
|
|
116
|
-
return this
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
remove(item: T) {
|
|
120
|
-
const index = this.indexOf(item)
|
|
121
|
-
|
|
122
|
-
if (index > -1) {
|
|
123
|
-
this._list.splice(index, 1)
|
|
124
|
-
|
|
125
|
-
if (!this.contains(item, this._removedItemsList)) {
|
|
126
|
-
this._removedItemsList.push(item)
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return this
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
update(items: T[]) {
|
|
134
|
-
items = this.mapInternalIdIfIsEmpty(items)
|
|
135
|
-
|
|
136
|
-
items.forEach((item) => this.add(item))
|
|
137
|
-
|
|
138
|
-
this._list
|
|
139
|
-
.filter((item) => !this.contains(item, items))
|
|
140
|
-
.forEach((item) => this.remove(item))
|
|
141
|
-
|
|
142
|
-
return this
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
clear() {
|
|
146
|
-
this._addedItemsList = []
|
|
147
|
-
this._updatedItemsList = []
|
|
148
|
-
this._removedItemsList = this._list
|
|
149
|
-
this._list = []
|
|
150
|
-
|
|
151
|
-
return this
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
forEach(callback: (item: T, index: number) => void) {
|
|
155
|
-
this._list.forEach(callback)
|
|
156
|
-
return this
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
async forEachAsync(callback: (item: T, index: number) => Promise<void>) {
|
|
160
|
-
return Promise.all(this._list.map(callback)).then(() => this)
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
map<U>(callback: (item: T, index: number) => U): List<U> {
|
|
164
|
-
const mappedItems = this._list.map(callback)
|
|
165
|
-
const list = new List<U>()
|
|
166
|
-
|
|
167
|
-
list.setList(mappedItems)
|
|
168
|
-
|
|
169
|
-
return list
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
async mapAsync<U>(
|
|
173
|
-
callback: (item: T, index: number) => Promise<U>,
|
|
174
|
-
): Promise<List<U>> {
|
|
175
|
-
return Promise.all(this._list.map(callback)).then((mappedItems) => {
|
|
176
|
-
const mappedList = new List<U>()
|
|
177
|
-
|
|
178
|
-
mappedList.setList(mappedItems)
|
|
179
|
-
|
|
180
|
-
return mappedList
|
|
181
|
-
})
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
filter(callback: (item: T, index: number) => boolean): List<T> {
|
|
185
|
-
const filteredItems = this._list.filter(callback)
|
|
186
|
-
const list = new List<T>()
|
|
187
|
-
|
|
188
|
-
list.setList(filteredItems)
|
|
189
|
-
|
|
190
|
-
return list
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
async filterAsync(
|
|
194
|
-
callback: (item: T, index: number) => Promise<boolean>,
|
|
195
|
-
): Promise<List<T>> {
|
|
196
|
-
return Promise.all(this._list.filter(callback))
|
|
197
|
-
.then((list) => list.filter((item) => item))
|
|
198
|
-
.then((filteredItems) => {
|
|
199
|
-
const list = new List<T>()
|
|
200
|
-
|
|
201
|
-
list.setList(filteredItems)
|
|
202
|
-
|
|
203
|
-
return list
|
|
204
|
-
})
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
find(callback: (item: T, index: number) => boolean): T | null {
|
|
208
|
-
return this._list.find(callback) ?? null
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
toArray(type?: ListActionType): T[] {
|
|
212
|
-
switch (type) {
|
|
213
|
-
case 'added':
|
|
214
|
-
return this._addedItemsList
|
|
215
|
-
case 'updated':
|
|
216
|
-
return this._updatedItemsList
|
|
217
|
-
case 'removed':
|
|
218
|
-
return this._removedItemsList
|
|
219
|
-
default:
|
|
220
|
-
return this._list
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
type PromisesResponseType<T> = {
|
|
2
|
-
[K in keyof T]: Awaited<T[K]>
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export class Promises {
|
|
6
|
-
static async result<T>(requests: T): Promise<PromisesResponseType<T>> {
|
|
7
|
-
const promises: Array<any> = []
|
|
8
|
-
|
|
9
|
-
Object.values(requests as any).forEach((promise) => promises.push(promise))
|
|
10
|
-
|
|
11
|
-
return Promise.all(promises).then((result) => {
|
|
12
|
-
let currentIndex = 0
|
|
13
|
-
|
|
14
|
-
const response = {} as PromisesResponseType<T>
|
|
15
|
-
|
|
16
|
-
Object.keys(requests as any).forEach((propName) => {
|
|
17
|
-
response[propName] = result[currentIndex]
|
|
18
|
-
currentIndex++
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
return response
|
|
22
|
-
})
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { maskCnpj, maskCpf } from '@koalarx/utils/KlString'
|
|
2
|
-
|
|
3
|
-
export function setMaskDocumentNumber(document?: string) {
|
|
4
|
-
if (!document) {
|
|
5
|
-
return ''
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const documentWithoutMask = document.replace(/[^0-9]/g, '')
|
|
9
|
-
|
|
10
|
-
return documentWithoutMask.length === 11
|
|
11
|
-
? maskCpf(documentWithoutMask)
|
|
12
|
-
: maskCnpj(documentWithoutMask)
|
|
13
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { FileValidator } from '@nestjs/common'
|
|
2
|
-
import { FileType } from '..'
|
|
3
|
-
|
|
4
|
-
type FileTypeInternal = FileType | FileType[] | Record<string, FileType[]>
|
|
5
|
-
type Result = { errorFileName?: string; isValid: boolean }
|
|
6
|
-
|
|
7
|
-
const runFileValidation = async (args: {
|
|
8
|
-
multiple: boolean
|
|
9
|
-
file: FileTypeInternal
|
|
10
|
-
validator: (file: FileType) => Promise<boolean> | boolean
|
|
11
|
-
}): Promise<Result> => {
|
|
12
|
-
if (args.multiple) {
|
|
13
|
-
const fileFields = Object.keys(args.file)
|
|
14
|
-
for (const field of fileFields) {
|
|
15
|
-
const fieldFile = args.file[field]
|
|
16
|
-
if (Array.isArray(fieldFile)) {
|
|
17
|
-
for (const f of fieldFile) {
|
|
18
|
-
if (!args.validator(f)) {
|
|
19
|
-
return { errorFileName: f.originalname, isValid: false }
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
} else {
|
|
23
|
-
if (!args.validator(fieldFile)) {
|
|
24
|
-
return { errorFileName: fieldFile.originalname, isValid: false }
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return { isValid: true }
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (Array.isArray(args.file)) {
|
|
32
|
-
for (const f of args.file) {
|
|
33
|
-
if (!args.validator(f)) {
|
|
34
|
-
return { errorFileName: f.originalname, isValid: false }
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
return { isValid: true }
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (args.validator(args.file as any)) {
|
|
41
|
-
return { errorFileName: args.file.originalname as string, isValid: false }
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return { isValid: true }
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export class FileSizeValidator extends FileValidator {
|
|
48
|
-
private maxSizeBytes: number
|
|
49
|
-
private multiple: boolean
|
|
50
|
-
private errorFileName: string
|
|
51
|
-
|
|
52
|
-
constructor(args: { maxSizeBytes: number; multiple: boolean }) {
|
|
53
|
-
super({})
|
|
54
|
-
this.maxSizeBytes = args.maxSizeBytes
|
|
55
|
-
this.multiple = args.multiple
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async isValid(file?: FileTypeInternal): Promise<boolean> {
|
|
59
|
-
if (!file) {
|
|
60
|
-
return true
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const result = await runFileValidation({
|
|
64
|
-
file,
|
|
65
|
-
multiple: this.multiple,
|
|
66
|
-
validator: (f) => f.size < this.maxSizeBytes,
|
|
67
|
-
})
|
|
68
|
-
this.errorFileName = result.errorFileName ?? ''
|
|
69
|
-
return result.isValid
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
buildErrorMessage(file: any): string {
|
|
73
|
-
return (
|
|
74
|
-
`file ${this.errorFileName || ''} exceeded the size limit ` +
|
|
75
|
-
parseFloat((this.maxSizeBytes / 1024 / 1024).toFixed(2)) +
|
|
76
|
-
'MB'
|
|
77
|
-
)
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export class FileTypeValidator extends FileValidator {
|
|
82
|
-
private multiple: boolean
|
|
83
|
-
private errorFileName: string
|
|
84
|
-
private filetype: RegExp | string
|
|
85
|
-
|
|
86
|
-
constructor(args: { multiple: boolean; filetype: RegExp | string }) {
|
|
87
|
-
super({})
|
|
88
|
-
this.multiple = args.multiple
|
|
89
|
-
this.filetype = args.filetype
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
isMimeTypeValid(file: FileType) {
|
|
93
|
-
return file.mimetype.search(this.filetype) === 0
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
async isValid(file?: FileTypeInternal): Promise<boolean> {
|
|
97
|
-
if (!file) {
|
|
98
|
-
return true
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const result = await runFileValidation({
|
|
102
|
-
multiple: this.multiple,
|
|
103
|
-
file,
|
|
104
|
-
validator: (f) => this.isMimeTypeValid(f),
|
|
105
|
-
})
|
|
106
|
-
this.errorFileName = result.errorFileName ?? ''
|
|
107
|
-
return result.isValid
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
buildErrorMessage(file: any): string {
|
|
111
|
-
return `file ${this.errorFileName || ''} must be of type ${this.filetype}`
|
|
112
|
-
}
|
|
113
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { ApiExcludeEndpoint } from '@nestjs/swagger'
|
|
2
|
-
import { EnvConfig } from '../core/utils/env.config'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Um decorator personalizado que utiliza o `ApiExcludeEndpoint` do NestJS Swagger
|
|
6
|
-
* para excluir endpoints da documentação da API com base no ambiente de execução.
|
|
7
|
-
*
|
|
8
|
-
* Este decorator verifica se o ambiente atual não é de desenvolvimento (`!EnvConfig.isEnvDevelop`).
|
|
9
|
-
* Se o ambiente não for de desenvolvimento, o endpoint será excluído da documentação.
|
|
10
|
-
*
|
|
11
|
-
* @returns Um decorator que aplica a exclusão condicional do endpoint na documentação da API.
|
|
12
|
-
*/
|
|
13
|
-
export const ApiExcludeEndpointDiffDevelop = () => {
|
|
14
|
-
return ApiExcludeEndpoint(!EnvConfig.isEnvDevelop)
|
|
15
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { ApiProperty } from '@nestjs/swagger'
|
|
2
|
-
import { EnumAllowedTypes } from '@nestjs/swagger/dist/interfaces/schema-object-metadata.interface'
|
|
3
|
-
|
|
4
|
-
interface ApiPropertyEnumOptions {
|
|
5
|
-
enum: EnumAllowedTypes
|
|
6
|
-
isArray?: boolean
|
|
7
|
-
required?: boolean
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Um decorator personalizado para documentar propriedades de enumeração em classes do NestJS
|
|
12
|
-
* usando o Swagger.
|
|
13
|
-
*
|
|
14
|
-
* @param options - As opções para configurar o decorator.
|
|
15
|
-
* @param options.enum - O enum que será documentado. Deve ser um tipo permitido pelo Swagger.
|
|
16
|
-
* @param options.isArray - Indica se a propriedade é um array de enums. Por padrão, é falso.
|
|
17
|
-
* @param options.required - Indica se a propriedade é obrigatória. Por padrão, é opcional.
|
|
18
|
-
*
|
|
19
|
-
* @description
|
|
20
|
-
* Este decorator é usado para gerar automaticamente a documentação de propriedades
|
|
21
|
-
* que utilizam enums. Ele cria uma descrição detalhada com os valores e suas respectivas
|
|
22
|
-
* descrições, formatada em Markdown para exibição no Swagger UI.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```typescript
|
|
26
|
-
* import { ApiPropertyEnum } from './api-property-enum.decorator';
|
|
27
|
-
*
|
|
28
|
-
* enum Status {
|
|
29
|
-
* ACTIVE = 1,
|
|
30
|
-
* INACTIVE = 2,
|
|
31
|
-
* }
|
|
32
|
-
*
|
|
33
|
-
* class ExampleDto {
|
|
34
|
-
* \@ApiPropertyEnum({ enum: Status, required: true })
|
|
35
|
-
* status: Status;
|
|
36
|
-
* }
|
|
37
|
-
* ```
|
|
38
|
-
*
|
|
39
|
-
* No exemplo acima, o Swagger exibirá a propriedade `status` com uma descrição detalhada
|
|
40
|
-
* dos valores possíveis do enum `Status` (e.g., "ACTIVE: 1\nINACTIVE: 2").
|
|
41
|
-
*/
|
|
42
|
-
export function ApiPropertyEnum(options: ApiPropertyEnumOptions) {
|
|
43
|
-
return function (target: any, propertyKey: string) {
|
|
44
|
-
const enumValues = Object.values(options.enum)
|
|
45
|
-
.filter((value) => typeof value === 'number')
|
|
46
|
-
.map((value) => ({
|
|
47
|
-
value,
|
|
48
|
-
description: options.enum[value],
|
|
49
|
-
}))
|
|
50
|
-
const description = enumValues
|
|
51
|
-
.map((enumValue) => `${enumValue.description}: ${enumValue.value}`)
|
|
52
|
-
.join('\n')
|
|
53
|
-
ApiProperty({
|
|
54
|
-
...options,
|
|
55
|
-
description: ['```', description, '```'].join('\n'),
|
|
56
|
-
})(target, propertyKey)
|
|
57
|
-
}
|
|
58
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { ApiProperty, ApiPropertyOptions } from '@nestjs/swagger'
|
|
2
|
-
import { EnvConfig } from '../core/utils/env.config'
|
|
3
|
-
|
|
4
|
-
export const ApiPropertyOnlyDevelop = (propertyOptions: ApiPropertyOptions) => {
|
|
5
|
-
return EnvConfig.isEnvDevelop ? ApiProperty(propertyOptions) : () => {}
|
|
6
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { createParamDecorator, ExecutionContext } from '@nestjs/common'
|
|
2
|
-
|
|
3
|
-
export const Cookies = createParamDecorator(
|
|
4
|
-
(data: string, ctx: ExecutionContext) => {
|
|
5
|
-
const request = ctx.switchToHttp().getRequest()
|
|
6
|
-
return data ? request.cookies?.[data] : request.cookies
|
|
7
|
-
},
|
|
8
|
-
)
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { ParseFilePipe, UploadedFiles } from '@nestjs/common'
|
|
2
|
-
import {
|
|
3
|
-
FileSizeValidator,
|
|
4
|
-
FileTypeValidator,
|
|
5
|
-
} from '../core/validators/file-validator'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Um decorator personalizado para lidar com o upload de arquivos em um controlador NestJS.
|
|
9
|
-
*
|
|
10
|
-
* @param {number} maxSizeInKb - O tamanho máximo permitido para os arquivos em kilobytes.
|
|
11
|
-
* @param {RegExp} filetype - Um padrão de expressão regular para validar os tipos de arquivo permitidos.
|
|
12
|
-
*
|
|
13
|
-
* Este decorator utiliza o `UploadedFiles` do NestJS para processar múltiplos arquivos enviados em uma requisição.
|
|
14
|
-
* Ele valida os arquivos com base no tamanho máximo permitido e no tipo de arquivo especificado.
|
|
15
|
-
*/
|
|
16
|
-
export function UploadDecorator(maxSizeInKb: number, filetype: RegExp) {
|
|
17
|
-
const maxSizeBytes = maxSizeInKb * 1024
|
|
18
|
-
|
|
19
|
-
return UploadedFiles(
|
|
20
|
-
new ParseFilePipe({
|
|
21
|
-
validators: [
|
|
22
|
-
new FileSizeValidator({ maxSizeBytes, multiple: true }),
|
|
23
|
-
new FileTypeValidator({
|
|
24
|
-
filetype,
|
|
25
|
-
multiple: true,
|
|
26
|
-
}),
|
|
27
|
-
],
|
|
28
|
-
fileIsRequired: false,
|
|
29
|
-
}),
|
|
30
|
-
)
|
|
31
|
-
}
|
package/src/env/env.module.ts
DELETED
package/src/env/env.service.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common'
|
|
2
|
-
import { ConfigService } from '@nestjs/config'
|
|
3
|
-
import { Env } from './env'
|
|
4
|
-
|
|
5
|
-
@Injectable()
|
|
6
|
-
export class EnvService<TEnv extends Env = Env> {
|
|
7
|
-
constructor(private readonly configService: ConfigService<TEnv, true>) {}
|
|
8
|
-
|
|
9
|
-
get<T extends keyof TEnv>(key: T) {
|
|
10
|
-
return this.configService.get(key as any, { infer: true })
|
|
11
|
-
}
|
|
12
|
-
}
|
package/src/env/env.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import 'dotenv/config'
|
|
2
|
-
import { z } from 'zod'
|
|
3
|
-
import { booleanSchema } from '../core/controllers/schemas/boolean.schema'
|
|
4
|
-
|
|
5
|
-
export const envSchema = z.object({
|
|
6
|
-
PORT: z.coerce.number().default(3000),
|
|
7
|
-
NODE_ENV: z.enum(['test', 'develop', 'staging', 'production']),
|
|
8
|
-
PRISMA_QUERY_LOG: booleanSchema().optional(),
|
|
9
|
-
SWAGGER_USERNAME: z.string().optional(),
|
|
10
|
-
SWAGGER_PASSWORD: z.string().optional(),
|
|
11
|
-
REDIS_CONNECTION_STRING: z.string().optional(),
|
|
12
|
-
})
|
|
13
|
-
|
|
14
|
-
export type Env = z.infer<typeof envSchema>
|