@koalarx/nest 0.0.8 → 0.1.0
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/common/backgroud-services/event-service/event-queue.js +2 -2
- package/common/controllers/created-registre-response.base.js +5 -1
- package/common/controllers/list-response.base.js +5 -1
- package/common/mediator/request-validator.base.js +1 -1
- package/common/models/pagination-params.js +11 -4
- package/core/database/entity.d.ts +3 -3
- package/core/database/entity.js +12 -15
- package/core/database/repository.base.d.ts +26 -5
- package/core/database/repository.base.js +140 -15
- package/core/koala-nest-database.module.d.ts +2 -2
- package/core/koala-nest-database.module.js +16 -16
- package/core/koala-nest-http.module.d.ts +2 -2
- package/core/koala-nest-http.module.js +9 -11
- package/core/koala-nest.module.d.ts +1 -3
- package/core/koala-nest.module.js +9 -14
- package/core/utils/interfaces/icomparable.d.ts +1 -1
- package/core/utils/list.d.ts +9 -1
- package/core/utils/list.js +32 -7
- package/filters/global-exception.filter.js +5 -1
- package/package.json +1 -1
- package/services/env/env.service.js +6 -1
- package/services/prisma/prisma-transactional-client.d.ts +1 -2
- package/services/prisma/prisma.service.js +5 -1
- package/services/redis/redis.service.js +6 -1
- package/services/redlock/red-lock.service.js +6 -1
- package/tsconfig.lib.tsbuildinfo +1 -0
- package/services/prisma/prisma.types.d.ts +0 -36
- package/services/prisma/prisma.types.js +0 -15
|
@@ -5,7 +5,7 @@ class EventQueue {
|
|
|
5
5
|
static handlersMap = {};
|
|
6
6
|
static markedAggregates = [];
|
|
7
7
|
static markAggregateForDispatch(aggregate) {
|
|
8
|
-
const aggregateFound = !!this.findMarkedAggregateByID(aggregate.
|
|
8
|
+
const aggregateFound = !!this.findMarkedAggregateByID(aggregate._id);
|
|
9
9
|
if (!aggregateFound) {
|
|
10
10
|
this.markedAggregates.push(aggregate);
|
|
11
11
|
}
|
|
@@ -39,7 +39,7 @@ class EventQueue {
|
|
|
39
39
|
this.markedAggregates.splice(index, 1);
|
|
40
40
|
}
|
|
41
41
|
static findMarkedAggregateByID(id) {
|
|
42
|
-
return this.markedAggregates.find((aggregate) => aggregate.
|
|
42
|
+
return this.markedAggregates.find((aggregate) => aggregate._id === id);
|
|
43
43
|
}
|
|
44
44
|
static dispatch(event) {
|
|
45
45
|
const eventClassName = event.constructor.name;
|
|
@@ -5,6 +5,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
8
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
12
|
exports.CreatedRegistreResponseBase = void 0;
|
|
10
13
|
const swagger_1 = require("@nestjs/swagger");
|
|
@@ -13,5 +16,6 @@ class CreatedRegistreResponseBase {
|
|
|
13
16
|
}
|
|
14
17
|
exports.CreatedRegistreResponseBase = CreatedRegistreResponseBase;
|
|
15
18
|
__decorate([
|
|
16
|
-
(0, swagger_1.ApiProperty)()
|
|
19
|
+
(0, swagger_1.ApiProperty)({ type: 'string' }),
|
|
20
|
+
__metadata("design:type", Object)
|
|
17
21
|
], CreatedRegistreResponseBase.prototype, "id", void 0);
|
|
@@ -5,6 +5,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
8
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
12
|
exports.ListResponseBase = void 0;
|
|
10
13
|
const swagger_1 = require("@nestjs/swagger");
|
|
@@ -13,5 +16,6 @@ class ListResponseBase {
|
|
|
13
16
|
}
|
|
14
17
|
exports.ListResponseBase = ListResponseBase;
|
|
15
18
|
__decorate([
|
|
16
|
-
(0, swagger_1.ApiProperty)()
|
|
19
|
+
(0, swagger_1.ApiProperty)(),
|
|
20
|
+
__metadata("design:type", Number)
|
|
17
21
|
], ListResponseBase.prototype, "count", void 0);
|
|
@@ -9,7 +9,7 @@ class RequestValidatorBase {
|
|
|
9
9
|
validate() {
|
|
10
10
|
const requestParsed = this.schema.safeParse(this._request);
|
|
11
11
|
if (requestParsed.success) {
|
|
12
|
-
return requestParsed.data;
|
|
12
|
+
return Object.assign(this._request, requestParsed.data);
|
|
13
13
|
}
|
|
14
14
|
throw requestParsed.error;
|
|
15
15
|
}
|
|
@@ -5,6 +5,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
5
5
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
6
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
7
|
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
8
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
12
|
exports.PaginationParams = exports.QueryFilterParams = void 0;
|
|
10
13
|
const swagger_1 = require("@nestjs/swagger");
|
|
@@ -37,24 +40,28 @@ __decorate([
|
|
|
37
40
|
required: false,
|
|
38
41
|
format: 'int32',
|
|
39
42
|
default: exports.QueryFilterParams.page,
|
|
40
|
-
})
|
|
43
|
+
}),
|
|
44
|
+
__metadata("design:type", Number)
|
|
41
45
|
], PaginationParams.prototype, "page", void 0);
|
|
42
46
|
__decorate([
|
|
43
47
|
(0, swagger_1.ApiProperty)({
|
|
44
48
|
required: false,
|
|
45
49
|
format: 'int32',
|
|
46
50
|
default: exports.QueryFilterParams.limit,
|
|
47
|
-
})
|
|
51
|
+
}),
|
|
52
|
+
__metadata("design:type", Number)
|
|
48
53
|
], PaginationParams.prototype, "limit", void 0);
|
|
49
54
|
__decorate([
|
|
50
55
|
(0, swagger_1.ApiProperty)({
|
|
51
56
|
required: false,
|
|
52
|
-
})
|
|
57
|
+
}),
|
|
58
|
+
__metadata("design:type", String)
|
|
53
59
|
], PaginationParams.prototype, "orderBy", void 0);
|
|
54
60
|
__decorate([
|
|
55
61
|
(0, swagger_1.ApiProperty)({
|
|
56
62
|
required: false,
|
|
57
63
|
enum: ['asc', 'desc'],
|
|
58
64
|
default: exports.QueryFilterParams.direction,
|
|
59
|
-
})
|
|
65
|
+
}),
|
|
66
|
+
__metadata("design:type", String)
|
|
60
67
|
], PaginationParams.prototype, "direction", void 0);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Optional } from '../@types';
|
|
2
2
|
import { IComparable, IComparableId } from '../utils/interfaces/icomparable';
|
|
3
|
-
export type EntityProps<T extends IComparable<T>> = Omit<Optional<T, '
|
|
3
|
+
export type EntityProps<T extends IComparable<T>> = Omit<Optional<T, '_id'>, 'equals'>;
|
|
4
4
|
export declare abstract class Entity<T extends IComparable<T>> implements IComparable<T> {
|
|
5
|
-
|
|
6
|
-
protected
|
|
5
|
+
_id: IComparableId;
|
|
6
|
+
protected automap(props: EntityProps<T>): void;
|
|
7
7
|
equals(obj: Entity<T>): boolean;
|
|
8
8
|
}
|
package/core/database/entity.js
CHANGED
|
@@ -1,31 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
3
|
exports.Entity = void 0;
|
|
10
|
-
const automapper_classes_1 = require("automapper-classes");
|
|
11
4
|
const list_1 = require("../utils/list");
|
|
12
5
|
class Entity {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Object.keys(props).forEach((key) => {
|
|
6
|
+
_id;
|
|
7
|
+
automap(props) {
|
|
8
|
+
Object.keys(props ?? {}).forEach((key) => {
|
|
16
9
|
if (Array.isArray(props[key]) && this[key] instanceof list_1.List) {
|
|
17
|
-
|
|
10
|
+
let value = props[key];
|
|
11
|
+
if (this[key].entityType) {
|
|
12
|
+
value = value.map((item) => new this[key].entityType(item));
|
|
13
|
+
}
|
|
14
|
+
this[key].setList(value);
|
|
18
15
|
}
|
|
19
16
|
else {
|
|
17
|
+
if (key === 'id') {
|
|
18
|
+
this._id = props[key];
|
|
19
|
+
}
|
|
20
20
|
this[key] = props[key];
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
equals(obj) {
|
|
25
|
-
return obj.
|
|
25
|
+
return obj._id === this._id;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
exports.Entity = Entity;
|
|
29
|
-
__decorate([
|
|
30
|
-
(0, automapper_classes_1.AutoMap)()
|
|
31
|
-
], Entity.prototype, "id", void 0);
|
|
@@ -1,17 +1,38 @@
|
|
|
1
|
+
import { Type } from '@nestjs/common';
|
|
1
2
|
import { PaginationParams } from '../../common/models/pagination-params';
|
|
2
|
-
import { PrismaClientWithCustomTransaction } from '../../services/prisma/prisma-client-with-custom-transaction.interface';
|
|
3
3
|
import { PrismaTransactionalClient } from '../../services/prisma/prisma-transactional-client';
|
|
4
|
-
import {
|
|
4
|
+
import { ListResponse } from '../@types';
|
|
5
|
+
import { IComparableId } from '../utils/interfaces/icomparable';
|
|
5
6
|
import { Entity } from './entity';
|
|
6
7
|
export interface FindAllProps<TPaginateAndOrdering extends PaginationParams, TWhere, TInclude = any> {
|
|
7
8
|
where: TWhere;
|
|
8
9
|
paginateAndOrderingProps?: TPaginateAndOrdering;
|
|
9
10
|
include?: TInclude;
|
|
10
11
|
}
|
|
12
|
+
type RepositoryInclude<TEntity> = {
|
|
13
|
+
[key in keyof TEntity]?: boolean | RepositoryInclude<TEntity[keyof TEntity]>;
|
|
14
|
+
};
|
|
15
|
+
interface RepositoryInitProps<TEntity> {
|
|
16
|
+
context: PrismaTransactionalClient;
|
|
17
|
+
modelName: Type<TEntity>;
|
|
18
|
+
transactionContext?: Type<PrismaTransactionalClient>;
|
|
19
|
+
include?: RepositoryInclude<TEntity>;
|
|
20
|
+
}
|
|
11
21
|
export declare abstract class RepositoryBase<TEntity extends Entity<TEntity>> {
|
|
12
|
-
protected
|
|
22
|
+
protected _context: PrismaTransactionalClient;
|
|
23
|
+
private _transactionContext?;
|
|
13
24
|
private readonly _modelName;
|
|
14
|
-
|
|
25
|
+
private readonly _include?;
|
|
26
|
+
constructor({ context, transactionContext, modelName, include, }: RepositoryInitProps<TEntity>);
|
|
15
27
|
withTransaction(fn: (prisma: PrismaTransactionalClient) => Promise<any>): Promise<any>;
|
|
16
|
-
protected
|
|
28
|
+
protected findById(id: IComparableId): Promise<TEntity | null>;
|
|
29
|
+
protected findMany<T>(where: T, pagination?: PaginationParams): Promise<any>;
|
|
30
|
+
protected findManyAndCount<T>(where: T, pagination?: PaginationParams): Promise<ListResponse<TEntity>>;
|
|
31
|
+
protected saveChanges(entity: TEntity): any;
|
|
32
|
+
protected delete(id: IComparableId): any;
|
|
33
|
+
private listToRelationActionList;
|
|
34
|
+
private entityToPrisma;
|
|
35
|
+
private context;
|
|
36
|
+
private findManySchema;
|
|
17
37
|
}
|
|
38
|
+
export {};
|
|
@@ -1,27 +1,152 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RepositoryBase = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const string_1 = require("@koalarx/utils/operators/string");
|
|
5
|
+
const pagination_params_1 = require("../../common/models/pagination-params");
|
|
6
|
+
const list_1 = require("../utils/list");
|
|
7
|
+
const entity_1 = require("./entity");
|
|
6
8
|
class RepositoryBase {
|
|
7
|
-
|
|
9
|
+
_context;
|
|
10
|
+
_transactionContext;
|
|
8
11
|
_modelName;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
this.
|
|
12
|
+
_include;
|
|
13
|
+
constructor({ context, transactionContext, modelName, include, }) {
|
|
14
|
+
this._context = context;
|
|
15
|
+
this._transactionContext = transactionContext;
|
|
16
|
+
this._modelName = modelName;
|
|
17
|
+
this._include = include;
|
|
12
18
|
}
|
|
13
19
|
withTransaction(fn) {
|
|
14
|
-
return this.
|
|
15
|
-
return fn(new
|
|
20
|
+
return this._context.withTransaction(async (client) => {
|
|
21
|
+
return fn(new this._transactionContext(client));
|
|
16
22
|
});
|
|
17
23
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
async findById(id) {
|
|
25
|
+
return this.context()
|
|
26
|
+
.findFirst({
|
|
27
|
+
include: this._include,
|
|
28
|
+
where: { id },
|
|
29
|
+
})
|
|
30
|
+
.then((response) => {
|
|
31
|
+
if (response) {
|
|
32
|
+
return new this._modelName(response);
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
async findMany(where, pagination) {
|
|
38
|
+
return this.context()
|
|
39
|
+
.findMany(this.findManySchema(where, pagination))
|
|
40
|
+
.then((result) => {
|
|
41
|
+
return result.map((response) => {
|
|
42
|
+
return new this._modelName(response);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async findManyAndCount(where, pagination) {
|
|
47
|
+
const count = await this.context().count({ where });
|
|
48
|
+
if (count > 0) {
|
|
49
|
+
const items = await this.findMany(where, Object.assign(new pagination_params_1.PaginationParams(), pagination));
|
|
50
|
+
return { items, count };
|
|
51
|
+
}
|
|
52
|
+
return { items: [], count };
|
|
53
|
+
}
|
|
54
|
+
saveChanges(entity) {
|
|
55
|
+
const prismaEntity = this.entityToPrisma(entity);
|
|
56
|
+
const isCreate = !entity._id;
|
|
57
|
+
if (isCreate) {
|
|
58
|
+
return this.context().create({
|
|
59
|
+
data: prismaEntity,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return this.withTransaction((client) => this.context(client)
|
|
64
|
+
.update({
|
|
65
|
+
where: { id: entity._id },
|
|
66
|
+
data: prismaEntity,
|
|
67
|
+
})
|
|
68
|
+
.then(() => {
|
|
69
|
+
const { relationUpdates, relationDeletes } = this.listToRelationActionList(entity);
|
|
70
|
+
return Promise.all([
|
|
71
|
+
...relationUpdates.map((relation) => client[relation.modelName].updateMany(relation.schema)),
|
|
72
|
+
...relationDeletes.map((relation) => client[relation.modelName].deleteMany(relation.schema)),
|
|
73
|
+
]);
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
delete(id) {
|
|
78
|
+
return this.context().delete({
|
|
79
|
+
where: { id },
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
listToRelationActionList(entity) {
|
|
83
|
+
const relationUpdates = [];
|
|
84
|
+
const relationDeletes = [];
|
|
85
|
+
Object.keys(entity).forEach((key) => {
|
|
86
|
+
if (entity[key] instanceof list_1.List) {
|
|
87
|
+
const list = entity[key];
|
|
88
|
+
const modelName = list.entityType?.name;
|
|
89
|
+
if (modelName) {
|
|
90
|
+
list.toArray('removed').forEach((item) => {
|
|
91
|
+
relationDeletes.push({
|
|
92
|
+
modelName: (0, string_1.toCamelCase)(modelName),
|
|
93
|
+
schema: { where: { id: item._id } },
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
list.toArray('updated').forEach((item) => {
|
|
97
|
+
relationUpdates.push({
|
|
98
|
+
modelName: (0, string_1.toCamelCase)(modelName),
|
|
99
|
+
schema: {
|
|
100
|
+
where: { id: item._id },
|
|
101
|
+
data: this.entityToPrisma(item),
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
return { relationUpdates, relationDeletes };
|
|
109
|
+
}
|
|
110
|
+
entityToPrisma(entity) {
|
|
111
|
+
const prismaSchema = {};
|
|
112
|
+
Object.keys(entity)
|
|
113
|
+
.filter((key) => key !== 'id' && key !== '_id')
|
|
114
|
+
.forEach((key) => {
|
|
115
|
+
if (entity[key] instanceof list_1.List) {
|
|
116
|
+
prismaSchema[key] = {
|
|
117
|
+
createMany: {
|
|
118
|
+
data: entity[key].toArray('added').map((item) => {
|
|
119
|
+
return this.entityToPrisma(item);
|
|
120
|
+
}),
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
else if (entity[key] instanceof entity_1.Entity) {
|
|
125
|
+
prismaSchema[key] = this.entityToPrisma(entity[key]);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
prismaSchema[key] = entity[key];
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
return prismaSchema;
|
|
132
|
+
}
|
|
133
|
+
context(transactionalClient) {
|
|
134
|
+
const modelName = this._modelName?.name;
|
|
135
|
+
if (!modelName)
|
|
136
|
+
throw new Error('modelName não informado no contrutor do repositorio');
|
|
137
|
+
if (transactionalClient) {
|
|
138
|
+
return transactionalClient[(0, string_1.toCamelCase)(modelName)];
|
|
139
|
+
}
|
|
140
|
+
return this._context[modelName];
|
|
141
|
+
}
|
|
142
|
+
findManySchema(where, pagination) {
|
|
143
|
+
return {
|
|
144
|
+
include: this._include,
|
|
145
|
+
where,
|
|
146
|
+
orderBy: pagination?.generateOrderBy(),
|
|
147
|
+
skip: pagination?.skip(),
|
|
148
|
+
take: (pagination?.limit ?? 0) > 0 ? pagination?.limit : undefined,
|
|
149
|
+
};
|
|
25
150
|
}
|
|
26
151
|
}
|
|
27
152
|
exports.RepositoryBase = RepositoryBase;
|
|
@@ -6,9 +6,9 @@ export interface KoalaNestDatabaseRepositoryConfig {
|
|
|
6
6
|
class: Type<RepositoryBase<any>>;
|
|
7
7
|
}
|
|
8
8
|
interface KoalaNestDatabaseModuleConfig {
|
|
9
|
-
repositories
|
|
9
|
+
repositories: KoalaNestDatabaseRepositoryConfig[];
|
|
10
10
|
}
|
|
11
11
|
export declare class KoalaNestDatabaseModule {
|
|
12
|
-
static
|
|
12
|
+
static register(config: KoalaNestDatabaseModuleConfig): DynamicModule;
|
|
13
13
|
}
|
|
14
14
|
export {};
|
|
@@ -13,26 +13,26 @@ const env_service_1 = require("../services/env/env.service");
|
|
|
13
13
|
const prisma_service_1 = require("../services/prisma/prisma.service");
|
|
14
14
|
exports.PRISMA_TOKEN = 'PRISMA_SERVICE_TOKEN';
|
|
15
15
|
let KoalaNestDatabaseModule = exports.KoalaNestDatabaseModule = KoalaNestDatabaseModule_1 = class KoalaNestDatabaseModule {
|
|
16
|
-
static
|
|
16
|
+
static register(config) {
|
|
17
|
+
const repositoriesToExport = config.repositories?.map((repository) => repository.interface) ?? [];
|
|
18
|
+
const repositoriesToProvide = config.repositories?.map((repository) => ({
|
|
19
|
+
provide: repository.interface,
|
|
20
|
+
useClass: repository.class,
|
|
21
|
+
})) ?? [];
|
|
17
22
|
return {
|
|
18
23
|
module: KoalaNestDatabaseModule_1,
|
|
19
|
-
providers:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
providers: [
|
|
25
|
+
{
|
|
26
|
+
provide: exports.PRISMA_TOKEN,
|
|
27
|
+
useClass: prisma_service_1.PrismaService,
|
|
28
|
+
},
|
|
29
|
+
...repositoriesToProvide,
|
|
30
|
+
env_service_1.EnvService,
|
|
31
|
+
],
|
|
32
|
+
exports: [exports.PRISMA_TOKEN, ...repositoriesToExport],
|
|
24
33
|
};
|
|
25
34
|
}
|
|
26
35
|
};
|
|
27
36
|
exports.KoalaNestDatabaseModule = KoalaNestDatabaseModule = KoalaNestDatabaseModule_1 = __decorate([
|
|
28
|
-
(0, common_1.Module)({
|
|
29
|
-
providers: [
|
|
30
|
-
{
|
|
31
|
-
provide: exports.PRISMA_TOKEN,
|
|
32
|
-
useClass: prisma_service_1.PrismaService,
|
|
33
|
-
},
|
|
34
|
-
env_service_1.EnvService,
|
|
35
|
-
],
|
|
36
|
-
exports: [exports.PRISMA_TOKEN],
|
|
37
|
-
})
|
|
37
|
+
(0, common_1.Module)({})
|
|
38
38
|
], KoalaNestDatabaseModule);
|
|
@@ -2,11 +2,11 @@ import { DynamicModule, MiddlewareConsumer, NestMiddleware, NestModule, Provider
|
|
|
2
2
|
import { AutomapperProfile } from 'automapper-nestjs';
|
|
3
3
|
interface KoalaNestHttpModuleConfig {
|
|
4
4
|
automapperProfile: Provider<AutomapperProfile>;
|
|
5
|
-
middlewares
|
|
5
|
+
middlewares?: Type<NestMiddleware>[];
|
|
6
6
|
}
|
|
7
7
|
export declare class KoalaNestHttpModule implements NestModule {
|
|
8
8
|
private static _config;
|
|
9
|
-
static
|
|
9
|
+
static register(config: KoalaNestHttpModuleConfig): DynamicModule;
|
|
10
10
|
configure(consumer: MiddlewareConsumer): void;
|
|
11
11
|
}
|
|
12
12
|
export {};
|
|
@@ -15,24 +15,22 @@ const env_service_1 = require("../services/env/env.service");
|
|
|
15
15
|
let KoalaNestHttpModule = exports.KoalaNestHttpModule = class KoalaNestHttpModule {
|
|
16
16
|
static { KoalaNestHttpModule_1 = this; }
|
|
17
17
|
static _config;
|
|
18
|
-
static
|
|
18
|
+
static register(config) {
|
|
19
19
|
this._config = config;
|
|
20
20
|
return {
|
|
21
21
|
module: KoalaNestHttpModule_1,
|
|
22
|
-
|
|
22
|
+
imports: [
|
|
23
|
+
automapper_nestjs_1.AutomapperModule.forRoot({
|
|
24
|
+
strategyInitializer: (0, automapper_classes_1.classes)(),
|
|
25
|
+
}),
|
|
26
|
+
],
|
|
27
|
+
providers: [config.automapperProfile, env_service_1.EnvService],
|
|
23
28
|
};
|
|
24
29
|
}
|
|
25
30
|
configure(consumer) {
|
|
26
|
-
KoalaNestHttpModule_1._config.middlewares
|
|
31
|
+
KoalaNestHttpModule_1._config.middlewares?.forEach((middleware) => consumer.apply(middleware).forRoutes('*'));
|
|
27
32
|
}
|
|
28
33
|
};
|
|
29
34
|
exports.KoalaNestHttpModule = KoalaNestHttpModule = KoalaNestHttpModule_1 = __decorate([
|
|
30
|
-
(0, common_1.Module)({
|
|
31
|
-
imports: [
|
|
32
|
-
automapper_nestjs_1.AutomapperModule.forRoot({
|
|
33
|
-
strategyInitializer: (0, automapper_classes_1.classes)(),
|
|
34
|
-
}),
|
|
35
|
-
],
|
|
36
|
-
providers: [env_service_1.EnvService],
|
|
37
|
-
})
|
|
35
|
+
(0, common_1.Module)({})
|
|
38
36
|
], KoalaNestHttpModule);
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { DynamicModule, Provider } from '@nestjs/common';
|
|
2
2
|
import { ZodType } from 'zod';
|
|
3
3
|
import { ILoggingService } from '../services/logging/ilogging.service';
|
|
4
|
-
import { KoalaNestDatabaseRepositoryConfig } from './koala-nest-database.module';
|
|
5
4
|
interface KoalaNestModuleConfig {
|
|
6
5
|
logging?: Provider<ILoggingService>;
|
|
7
6
|
env?: ZodType;
|
|
8
|
-
repositories?: KoalaNestDatabaseRepositoryConfig[];
|
|
9
7
|
}
|
|
10
8
|
export declare class KoalaNestModule {
|
|
11
|
-
static
|
|
9
|
+
static register(config?: KoalaNestModuleConfig): DynamicModule;
|
|
12
10
|
}
|
|
13
11
|
export {};
|
|
@@ -11,6 +11,7 @@ exports.KoalaNestModule = void 0;
|
|
|
11
11
|
const common_1 = require("@nestjs/common");
|
|
12
12
|
const config_1 = require("@nestjs/config");
|
|
13
13
|
const env_1 = require("../services/env/env");
|
|
14
|
+
const env_module_1 = require("../services/env/env.module");
|
|
14
15
|
const env_service_1 = require("../services/env/env.service");
|
|
15
16
|
const ilogging_service_1 = require("../services/logging/ilogging.service");
|
|
16
17
|
const logging_service_1 = require("../services/logging/logging.service");
|
|
@@ -18,35 +19,29 @@ const iredis_service_1 = require("../services/redis/iredis.service");
|
|
|
18
19
|
const redis_service_1 = require("../services/redis/redis.service");
|
|
19
20
|
const ired_lock_service_1 = require("../services/redlock/ired-lock.service");
|
|
20
21
|
const red_lock_service_1 = require("../services/redlock/red-lock.service");
|
|
21
|
-
const koala_nest_database_module_1 = require("./koala-nest-database.module");
|
|
22
22
|
let KoalaNestModule = exports.KoalaNestModule = KoalaNestModule_1 = class KoalaNestModule {
|
|
23
|
-
static
|
|
23
|
+
static register(config) {
|
|
24
24
|
return {
|
|
25
25
|
module: KoalaNestModule_1,
|
|
26
26
|
imports: [
|
|
27
27
|
config_1.ConfigModule.forRoot({
|
|
28
|
-
validate: (envData) => (env ?? env_1.envSchema).parse(envData),
|
|
28
|
+
validate: (envData) => (config?.env ?? env_1.envSchema).parse(envData),
|
|
29
29
|
isGlobal: true,
|
|
30
30
|
}),
|
|
31
|
-
|
|
32
|
-
repositories,
|
|
33
|
-
}),
|
|
31
|
+
env_module_1.EnvModule,
|
|
34
32
|
],
|
|
35
33
|
providers: [
|
|
36
34
|
{
|
|
37
35
|
provide: ilogging_service_1.ILoggingService,
|
|
38
|
-
useValue: logging ?? logging_service_1.LoggingService,
|
|
36
|
+
useValue: config?.logging ?? logging_service_1.LoggingService,
|
|
39
37
|
},
|
|
38
|
+
{ provide: iredis_service_1.IRedisService, useClass: redis_service_1.RedisService },
|
|
39
|
+
{ provide: ired_lock_service_1.IRedLockService, useClass: red_lock_service_1.RedLockService },
|
|
40
|
+
env_service_1.EnvService,
|
|
40
41
|
],
|
|
41
42
|
};
|
|
42
43
|
}
|
|
43
44
|
};
|
|
44
45
|
exports.KoalaNestModule = KoalaNestModule = KoalaNestModule_1 = __decorate([
|
|
45
|
-
(0, common_1.Module)({
|
|
46
|
-
providers: [
|
|
47
|
-
{ provide: iredis_service_1.IRedisService, useClass: redis_service_1.RedisService },
|
|
48
|
-
{ provide: ired_lock_service_1.IRedLockService, useClass: red_lock_service_1.RedLockService },
|
|
49
|
-
env_service_1.EnvService,
|
|
50
|
-
],
|
|
51
|
-
})
|
|
46
|
+
(0, common_1.Module)({})
|
|
52
47
|
], KoalaNestModule);
|
package/core/utils/list.d.ts
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
|
+
import { Type } from '@nestjs/common';
|
|
1
2
|
import { IComparableId } from './interfaces/icomparable';
|
|
2
3
|
export type ListActionType = 'added' | 'updated' | 'removed';
|
|
4
|
+
export interface ListProps<T> {
|
|
5
|
+
list?: T[];
|
|
6
|
+
entityType?: Type<T>;
|
|
7
|
+
}
|
|
3
8
|
export declare class List<T> {
|
|
9
|
+
readonly entityType?: Type<T> | undefined;
|
|
4
10
|
private _list;
|
|
5
11
|
private _addedItemsList;
|
|
6
12
|
private _updatedItemsList;
|
|
7
13
|
private _removedItemsList;
|
|
8
|
-
constructor(
|
|
14
|
+
constructor(entityType?: Type<T> | undefined);
|
|
9
15
|
get length(): number;
|
|
10
16
|
findById(id: IComparableId): T | null;
|
|
11
17
|
findByValue(value: any): T | null;
|
|
18
|
+
setList(list: T[]): void;
|
|
12
19
|
add(item: T): void;
|
|
13
20
|
remove(item: T): void;
|
|
21
|
+
update(items: T[]): void;
|
|
14
22
|
clear(): void;
|
|
15
23
|
forEach(callback: (item: T, index: number) => void): void;
|
|
16
24
|
forEachAsync(callback: (item: T, index: number) => Promise<void>): Promise<void[]>;
|