@koalarx/nest 1.0.1 → 1.2.1
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/constants/query-params.d.ts +6 -0
- package/core/constants/query-params.js +8 -0
- package/core/controllers/pagination.request.d.ts +10 -0
- package/core/{models/pagination-params.js → controllers/pagination.request.js} +19 -30
- package/core/controllers/schemas/boolean.schema.js +1 -3
- package/core/controllers/schemas/list-query.schema.js +3 -3
- package/core/database/entity.base.js +6 -3
- package/core/database/repository.base.d.ts +10 -7
- package/core/database/repository.base.js +60 -33
- package/core/dtos/pagination.dto.d.ts +9 -0
- package/core/dtos/pagination.dto.js +49 -0
- package/core/index.d.ts +15 -0
- package/core/index.js +2 -0
- package/core/koala-app.js +5 -3
- package/core/koala-global-vars.d.ts +2 -2
- package/core/mapping/auto-mapping-list.d.ts +7 -0
- package/core/mapping/auto-mapping-list.js +9 -0
- package/core/mapping/auto-mapping.decorator.js +2 -1
- package/core/mapping/auto-mapping.service.js +8 -4
- package/core/utils/assing-object.d.ts +2 -2
- package/core/utils/assing-object.js +2 -2
- package/core/utils/list.js +1 -0
- package/core/utils/list.spec.js +18 -0
- package/env/env.service.d.ts +3 -10
- package/package.json +1 -1
- package/test/koala-app-test-dependencies.d.ts +1 -1
- package/test/repositories/in-memory-base.repository.d.ts +5 -4
- package/test/repositories/in-memory-base.repository.js +14 -12
- package/test/utils/create-e2e-database.js +1 -1
- package/tsconfig.lib.tsbuildinfo +1 -1
- package/core/models/pagination-params.d.ts +0 -17
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { QueryDirectionType } from '..';
|
|
2
|
+
export type PaginatedRequestProps<T extends PaginationRequest> = Omit<{
|
|
3
|
+
[K in keyof T as T[K] extends Function ? never : K]: T[K];
|
|
4
|
+
}, '_id'>;
|
|
5
|
+
export declare class PaginationRequest {
|
|
6
|
+
page?: number;
|
|
7
|
+
limit?: number;
|
|
8
|
+
orderBy?: string;
|
|
9
|
+
direction?: QueryDirectionType;
|
|
10
|
+
}
|
|
@@ -9,59 +9,48 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.
|
|
12
|
+
exports.PaginationRequest = void 0;
|
|
13
13
|
const swagger_1 = require("@nestjs/swagger");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class PaginationParams {
|
|
20
|
-
page = exports.QueryFilterParams.page;
|
|
21
|
-
limit = exports.QueryFilterParams.limit;
|
|
14
|
+
const auto_mapping_decorator_1 = require("../mapping/auto-mapping.decorator");
|
|
15
|
+
const query_params_1 = require("../constants/query-params");
|
|
16
|
+
class PaginationRequest {
|
|
17
|
+
page = query_params_1.QUERY_FILTER_PARAMS.page;
|
|
18
|
+
limit = query_params_1.QUERY_FILTER_PARAMS.limit;
|
|
22
19
|
orderBy;
|
|
23
|
-
direction =
|
|
24
|
-
skip() {
|
|
25
|
-
return (this.limit ?? 0) * (this.page ?? exports.QueryFilterParams.page);
|
|
26
|
-
}
|
|
27
|
-
generateOrderBy() {
|
|
28
|
-
if (this.orderBy) {
|
|
29
|
-
const orderByField = this.orderBy.split('.');
|
|
30
|
-
return orderByField.reduceRight((acc, item, index) => ({
|
|
31
|
-
[item]: index === orderByField.length - 1 ? this.direction : acc,
|
|
32
|
-
}), {});
|
|
33
|
-
}
|
|
34
|
-
return undefined;
|
|
35
|
-
}
|
|
20
|
+
direction = query_params_1.QUERY_FILTER_PARAMS.direction;
|
|
36
21
|
}
|
|
37
|
-
exports.
|
|
22
|
+
exports.PaginationRequest = PaginationRequest;
|
|
38
23
|
__decorate([
|
|
39
24
|
(0, swagger_1.ApiProperty)({
|
|
40
25
|
required: false,
|
|
41
26
|
format: 'int32',
|
|
42
|
-
default:
|
|
27
|
+
default: query_params_1.QUERY_FILTER_PARAMS.page,
|
|
43
28
|
}),
|
|
29
|
+
(0, auto_mapping_decorator_1.AutoMap)(),
|
|
44
30
|
__metadata("design:type", Number)
|
|
45
|
-
],
|
|
31
|
+
], PaginationRequest.prototype, "page", void 0);
|
|
46
32
|
__decorate([
|
|
47
33
|
(0, swagger_1.ApiProperty)({
|
|
48
34
|
required: false,
|
|
49
35
|
format: 'int32',
|
|
50
|
-
default:
|
|
36
|
+
default: query_params_1.QUERY_FILTER_PARAMS.limit,
|
|
51
37
|
}),
|
|
38
|
+
(0, auto_mapping_decorator_1.AutoMap)(),
|
|
52
39
|
__metadata("design:type", Number)
|
|
53
|
-
],
|
|
40
|
+
], PaginationRequest.prototype, "limit", void 0);
|
|
54
41
|
__decorate([
|
|
55
42
|
(0, swagger_1.ApiProperty)({
|
|
56
43
|
required: false,
|
|
57
44
|
}),
|
|
45
|
+
(0, auto_mapping_decorator_1.AutoMap)(),
|
|
58
46
|
__metadata("design:type", String)
|
|
59
|
-
],
|
|
47
|
+
], PaginationRequest.prototype, "orderBy", void 0);
|
|
60
48
|
__decorate([
|
|
61
49
|
(0, swagger_1.ApiProperty)({
|
|
62
50
|
required: false,
|
|
63
51
|
enum: ['asc', 'desc'],
|
|
64
|
-
default:
|
|
52
|
+
default: query_params_1.QUERY_FILTER_PARAMS.direction,
|
|
65
53
|
}),
|
|
54
|
+
(0, auto_mapping_decorator_1.AutoMap)(),
|
|
66
55
|
__metadata("design:type", String)
|
|
67
|
-
],
|
|
56
|
+
], PaginationRequest.prototype, "direction", void 0);
|
|
@@ -3,9 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.booleanSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
function booleanSchema() {
|
|
6
|
-
return zod_1.z.coerce
|
|
7
|
-
.string()
|
|
8
|
-
.transform((value) => {
|
|
6
|
+
return zod_1.z.coerce.string().transform((value) => {
|
|
9
7
|
if (value !== undefined) {
|
|
10
8
|
return value === 'true';
|
|
11
9
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LIST_QUERY_SCHEMA = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
-
const
|
|
5
|
+
const query_params_1 = require("../../constants/query-params");
|
|
6
6
|
exports.LIST_QUERY_SCHEMA = zod_1.z.object({
|
|
7
7
|
page: zod_1.z.coerce
|
|
8
8
|
.number()
|
|
@@ -10,10 +10,10 @@ exports.LIST_QUERY_SCHEMA = zod_1.z.object({
|
|
|
10
10
|
if (value) {
|
|
11
11
|
return value - 1;
|
|
12
12
|
}
|
|
13
|
-
return
|
|
13
|
+
return query_params_1.QUERY_FILTER_PARAMS.page;
|
|
14
14
|
})
|
|
15
15
|
.optional(),
|
|
16
|
-
limit: zod_1.z.coerce.number().default(
|
|
16
|
+
limit: zod_1.z.coerce.number().default(query_params_1.QUERY_FILTER_PARAMS.limit).optional(),
|
|
17
17
|
orderBy: zod_1.z.string().optional(),
|
|
18
18
|
direction: zod_1.z.enum(['asc', 'desc']).default('asc').optional(),
|
|
19
19
|
});
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EntityBase = void 0;
|
|
4
|
+
const auto_mapping_list_1 = require("../mapping/auto-mapping-list");
|
|
4
5
|
const list_1 = require("../utils/list");
|
|
5
6
|
class EntityBase {
|
|
6
7
|
_id;
|
|
7
8
|
automap(props) {
|
|
8
9
|
if (props) {
|
|
9
10
|
for (const key of Object.keys(props)) {
|
|
11
|
+
const propDefinitions = auto_mapping_list_1.AutoMappingList.getPropDefinitions(this.constructor.prototype.constructor, key);
|
|
12
|
+
const EntityOnPropKey = auto_mapping_list_1.AutoMappingList.getSourceByName(propDefinitions?.type);
|
|
10
13
|
if (Array.isArray(props[key]) && this[key] instanceof list_1.List) {
|
|
11
14
|
let value = props[key];
|
|
12
15
|
if (this[key].entityType) {
|
|
@@ -18,12 +21,12 @@ class EntityBase {
|
|
|
18
21
|
}
|
|
19
22
|
this[key].setList(value);
|
|
20
23
|
}
|
|
21
|
-
else if (
|
|
22
|
-
const entity = new
|
|
24
|
+
else if (EntityOnPropKey) {
|
|
25
|
+
const entity = new EntityOnPropKey();
|
|
23
26
|
entity.automap(props[key]);
|
|
24
27
|
this[key] = entity;
|
|
25
28
|
}
|
|
26
|
-
else {
|
|
29
|
+
else if (propDefinitions) {
|
|
27
30
|
if (key === 'id') {
|
|
28
31
|
this._id = props[key];
|
|
29
32
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Type } from '@nestjs/common';
|
|
2
|
-
import { ListResponse } from '
|
|
3
|
-
import {
|
|
2
|
+
import { ListResponse } from '..';
|
|
3
|
+
import { PaginationDto } from '../dtos/pagination.dto';
|
|
4
4
|
import { IComparableId } from '../utils/interfaces/icomparable';
|
|
5
5
|
import { EntityBase } from './entity.base';
|
|
6
6
|
import { PrismaTransactionalClient } from './prisma-transactional-client';
|
|
@@ -17,17 +17,20 @@ export declare abstract class RepositoryBase<TEntity extends EntityBase<TEntity>
|
|
|
17
17
|
protected _context: PrismaTransactionalClient;
|
|
18
18
|
private readonly _modelName;
|
|
19
19
|
private readonly _include?;
|
|
20
|
-
constructor({ context, modelName, include
|
|
20
|
+
constructor({ context, modelName, include }: RepositoryInitProps<TEntity>);
|
|
21
21
|
withTransaction(fn: (prisma: PrismaTransactionalClient) => Promise<any>): Promise<any>;
|
|
22
22
|
protected findById(id: IComparableId): Promise<TEntity | null>;
|
|
23
|
-
protected
|
|
24
|
-
protected
|
|
25
|
-
protected
|
|
26
|
-
protected
|
|
23
|
+
protected findFirst<T>(where: T): Promise<any>;
|
|
24
|
+
protected findMany<T>(where: T, pagination?: PaginationDto): Promise<any>;
|
|
25
|
+
protected findManyAndCount<T>(where: T, pagination?: PaginationDto): Promise<ListResponse<TEntity>>;
|
|
26
|
+
protected insert(entity: TEntity): any;
|
|
27
|
+
protected edit<TWhere = any>(entity: TEntity, updateWhere?: TWhere): Promise<any>;
|
|
28
|
+
protected remove<TWhere = any>(where: TWhere): Promise<any>;
|
|
27
29
|
private listToRelationActionList;
|
|
28
30
|
private entityToPrisma;
|
|
29
31
|
private context;
|
|
30
32
|
private findManySchema;
|
|
31
33
|
private createEntity;
|
|
34
|
+
private orphanRemoval;
|
|
32
35
|
}
|
|
33
36
|
export {};
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RepositoryBase = void 0;
|
|
4
4
|
const string_1 = require("@koalarx/utils/operators/string");
|
|
5
|
+
const pagination_dto_1 = require("../dtos/pagination.dto");
|
|
5
6
|
const koala_global_vars_1 = require("../koala-global-vars");
|
|
6
|
-
const pagination_params_1 = require("../models/pagination-params");
|
|
7
7
|
const list_1 = require("../utils/list");
|
|
8
8
|
const entity_base_1 = require("./entity.base");
|
|
9
9
|
class RepositoryBase {
|
|
10
10
|
_context;
|
|
11
11
|
_modelName;
|
|
12
12
|
_include;
|
|
13
|
-
constructor({ context, modelName, include
|
|
13
|
+
constructor({ context, modelName, include }) {
|
|
14
14
|
this._context = context;
|
|
15
15
|
this._modelName = modelName;
|
|
16
16
|
this._include = include;
|
|
@@ -33,6 +33,19 @@ class RepositoryBase {
|
|
|
33
33
|
return null;
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
+
async findFirst(where) {
|
|
37
|
+
return this.context()
|
|
38
|
+
.findFirst({
|
|
39
|
+
include: this._include,
|
|
40
|
+
where,
|
|
41
|
+
})
|
|
42
|
+
.then((response) => {
|
|
43
|
+
if (response) {
|
|
44
|
+
return this.createEntity(response);
|
|
45
|
+
}
|
|
46
|
+
return null;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
36
49
|
async findMany(where, pagination) {
|
|
37
50
|
return this.context()
|
|
38
51
|
.findMany(this.findManySchema(where, pagination))
|
|
@@ -41,38 +54,43 @@ class RepositoryBase {
|
|
|
41
54
|
async findManyAndCount(where, pagination) {
|
|
42
55
|
const count = await this.context().count({ where });
|
|
43
56
|
if (count > 0) {
|
|
44
|
-
const items = await this.findMany(where, Object.assign(new
|
|
57
|
+
const items = await this.findMany(where, Object.assign(new pagination_dto_1.PaginationDto(), pagination));
|
|
45
58
|
return { items, count };
|
|
46
59
|
}
|
|
47
60
|
return { items: [], count };
|
|
48
61
|
}
|
|
49
|
-
|
|
50
|
-
const prismaEntity = this.entityToPrisma(entity);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
data: prismaEntity,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
return this.withTransaction((client) => this.context(client)
|
|
59
|
-
.update({
|
|
60
|
-
where: { id: entity._id },
|
|
61
|
-
data: prismaEntity,
|
|
62
|
-
})
|
|
63
|
-
.then(() => {
|
|
64
|
-
const { relationUpdates, relationDeletes } = this.listToRelationActionList(entity);
|
|
65
|
-
return Promise.all([
|
|
66
|
-
...relationUpdates.map((relation) => client[relation.modelName].updateMany(relation.schema)),
|
|
67
|
-
...relationDeletes.map((relation) => client[relation.modelName].deleteMany(relation.schema)),
|
|
68
|
-
]);
|
|
69
|
-
}));
|
|
70
|
-
}
|
|
62
|
+
insert(entity) {
|
|
63
|
+
const prismaEntity = this.entityToPrisma(entity, true);
|
|
64
|
+
return this.context().create({
|
|
65
|
+
data: prismaEntity,
|
|
66
|
+
});
|
|
71
67
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
edit(entity, updateWhere) {
|
|
69
|
+
const prismaEntity = this.entityToPrisma(entity, false);
|
|
70
|
+
return this.withTransaction((client) => this.context(client)
|
|
71
|
+
.update({
|
|
72
|
+
where: updateWhere ?? { id: entity._id },
|
|
73
|
+
data: prismaEntity,
|
|
74
|
+
})
|
|
75
|
+
.then(() => {
|
|
76
|
+
const { relationUpdates, relationDeletes } = this.listToRelationActionList(entity);
|
|
77
|
+
return Promise.all([
|
|
78
|
+
...relationUpdates.map((relation) => client[relation.modelName].updateMany(relation.schema)),
|
|
79
|
+
...relationDeletes.map((relation) => client[relation.modelName].deleteMany(relation.schema)),
|
|
80
|
+
]);
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
async remove(where) {
|
|
84
|
+
const entity = await this.findFirst(where);
|
|
85
|
+
const relationEntity = [];
|
|
86
|
+
Object.keys(entity).forEach((key) => {
|
|
87
|
+
if (entity[key] instanceof entity_base_1.EntityBase) {
|
|
88
|
+
relationEntity.push(entity[key]);
|
|
89
|
+
}
|
|
75
90
|
});
|
|
91
|
+
return this.withTransaction((client) => this.context(client)
|
|
92
|
+
.delete({ where })
|
|
93
|
+
.then((response) => Promise.all(relationEntity.map((entity) => this.orphanRemoval(client, entity))).then(() => response)));
|
|
76
94
|
}
|
|
77
95
|
listToRelationActionList(entity) {
|
|
78
96
|
const relationUpdates = [];
|
|
@@ -93,7 +111,7 @@ class RepositoryBase {
|
|
|
93
111
|
modelName: (0, string_1.toCamelCase)(modelName),
|
|
94
112
|
schema: {
|
|
95
113
|
where: { id: item._id },
|
|
96
|
-
data: this.entityToPrisma(item),
|
|
114
|
+
data: this.entityToPrisma(item, false),
|
|
97
115
|
},
|
|
98
116
|
});
|
|
99
117
|
});
|
|
@@ -102,10 +120,10 @@ class RepositoryBase {
|
|
|
102
120
|
});
|
|
103
121
|
return { relationUpdates, relationDeletes };
|
|
104
122
|
}
|
|
105
|
-
entityToPrisma(entity) {
|
|
123
|
+
entityToPrisma(entity, isCreate) {
|
|
106
124
|
const prismaSchema = {};
|
|
107
125
|
Object.keys(entity)
|
|
108
|
-
.filter((key) =>
|
|
126
|
+
.filter((key) => !['id', '_id'].includes(key))
|
|
109
127
|
.filter((key) => !(entity[key] instanceof Function))
|
|
110
128
|
.forEach((key) => {
|
|
111
129
|
if (entity[key] instanceof list_1.List) {
|
|
@@ -113,14 +131,16 @@ class RepositoryBase {
|
|
|
113
131
|
prismaSchema[key] = {
|
|
114
132
|
createMany: {
|
|
115
133
|
data: entity[key].toArray('added').map((item) => {
|
|
116
|
-
return this.entityToPrisma(item);
|
|
134
|
+
return this.entityToPrisma(item, isCreate);
|
|
117
135
|
}),
|
|
118
136
|
},
|
|
119
137
|
};
|
|
120
138
|
}
|
|
121
139
|
}
|
|
122
140
|
else if (entity[key] instanceof entity_base_1.EntityBase) {
|
|
123
|
-
prismaSchema[key] =
|
|
141
|
+
prismaSchema[key] = isCreate
|
|
142
|
+
? { create: this.entityToPrisma(entity[key], isCreate) }
|
|
143
|
+
: { update: this.entityToPrisma(entity[key], isCreate) };
|
|
124
144
|
}
|
|
125
145
|
else {
|
|
126
146
|
prismaSchema[key] = entity[key];
|
|
@@ -151,5 +171,12 @@ class RepositoryBase {
|
|
|
151
171
|
entity.automap(data);
|
|
152
172
|
return entity;
|
|
153
173
|
}
|
|
174
|
+
orphanRemoval(client, entity) {
|
|
175
|
+
const where = {};
|
|
176
|
+
Object.keys(entity)
|
|
177
|
+
.filter((key) => key === 'id' || key.includes('Id'))
|
|
178
|
+
.forEach((key) => (where[key] = entity[key]));
|
|
179
|
+
return client[(0, string_1.toCamelCase)(entity.constructor.name)].delete({ where });
|
|
180
|
+
}
|
|
154
181
|
}
|
|
155
182
|
exports.RepositoryBase = RepositoryBase;
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.PaginationDto = void 0;
|
|
13
|
+
const query_params_1 = require("../constants/query-params");
|
|
14
|
+
const auto_mapping_decorator_1 = require("../mapping/auto-mapping.decorator");
|
|
15
|
+
class PaginationDto {
|
|
16
|
+
page = 0;
|
|
17
|
+
limit = query_params_1.QUERY_FILTER_PARAMS.limit;
|
|
18
|
+
orderBy = '';
|
|
19
|
+
direction = 'asc';
|
|
20
|
+
skip() {
|
|
21
|
+
return (this.limit ?? 0) * (this.page ?? query_params_1.QUERY_FILTER_PARAMS.page);
|
|
22
|
+
}
|
|
23
|
+
generateOrderBy() {
|
|
24
|
+
if (this.orderBy) {
|
|
25
|
+
const orderByField = this.orderBy.split('.');
|
|
26
|
+
return orderByField.reduceRight((acc, item, index) => ({
|
|
27
|
+
[item]: index === orderByField.length - 1 ? this.direction : acc,
|
|
28
|
+
}), {});
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.PaginationDto = PaginationDto;
|
|
34
|
+
__decorate([
|
|
35
|
+
(0, auto_mapping_decorator_1.AutoMap)(),
|
|
36
|
+
__metadata("design:type", Number)
|
|
37
|
+
], PaginationDto.prototype, "page", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
(0, auto_mapping_decorator_1.AutoMap)(),
|
|
40
|
+
__metadata("design:type", Number)
|
|
41
|
+
], PaginationDto.prototype, "limit", void 0);
|
|
42
|
+
__decorate([
|
|
43
|
+
(0, auto_mapping_decorator_1.AutoMap)(),
|
|
44
|
+
__metadata("design:type", String)
|
|
45
|
+
], PaginationDto.prototype, "orderBy", void 0);
|
|
46
|
+
__decorate([
|
|
47
|
+
(0, auto_mapping_decorator_1.AutoMap)(),
|
|
48
|
+
__metadata("design:type", String)
|
|
49
|
+
], PaginationDto.prototype, "direction", void 0);
|
package/core/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type Optional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
2
|
+
export type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
3
|
+
export type CreatedRegister<TypeId = string> = {
|
|
4
|
+
id: TypeId;
|
|
5
|
+
};
|
|
6
|
+
export type ListResponse<TItem = any> = {
|
|
7
|
+
items: Array<TItem>;
|
|
8
|
+
count: number;
|
|
9
|
+
};
|
|
10
|
+
export type FileResponse = {
|
|
11
|
+
filename: string;
|
|
12
|
+
type: string;
|
|
13
|
+
base64: string;
|
|
14
|
+
};
|
|
15
|
+
export type QueryDirectionType = 'asc' | 'desc';
|
package/core/index.js
ADDED
package/core/koala-app.js
CHANGED
|
@@ -56,13 +56,15 @@ class KoalaApp {
|
|
|
56
56
|
useDoc(config) {
|
|
57
57
|
const credentials = {
|
|
58
58
|
username: process.env.SWAGGER_USERNAME ?? '',
|
|
59
|
-
password: process.env.SWAGGER_PASSWORD ?? ''
|
|
59
|
+
password: process.env.SWAGGER_PASSWORD ?? '',
|
|
60
60
|
};
|
|
61
|
-
if (env_config_1.EnvConfig.isEnvDevelop &&
|
|
61
|
+
if (env_config_1.EnvConfig.isEnvDevelop &&
|
|
62
|
+
credentials.username &&
|
|
63
|
+
credentials.password) {
|
|
62
64
|
this.app.use([config.endpoint], expressBasicAuth({
|
|
63
65
|
challenge: true,
|
|
64
66
|
users: {
|
|
65
|
-
[credentials.username]: credentials.password
|
|
67
|
+
[credentials.username]: credentials.password,
|
|
66
68
|
},
|
|
67
69
|
}));
|
|
68
70
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Type } from
|
|
2
|
-
import { PrismaTransactionalClient } from
|
|
1
|
+
import { Type } from '@nestjs/common';
|
|
2
|
+
import { PrismaTransactionalClient } from './database/prisma-transactional-client';
|
|
3
3
|
export declare class KoalaGlobalVars {
|
|
4
4
|
static appName: string;
|
|
5
5
|
static internalUserName: string;
|
|
@@ -12,6 +12,13 @@ export declare class AutoMappingList {
|
|
|
12
12
|
private static _mappingProfileList;
|
|
13
13
|
static add(source: Type<any>, target: Type<any>, ...forMember: ForMemberDefinition<any, any>): void;
|
|
14
14
|
static get(source: Type<any>, target: Type<any>): AutoMappingGetContext;
|
|
15
|
+
static getSourceByName(sourceName: string): Type<any> | undefined;
|
|
16
|
+
static getPropDefinitions(source: Type<any>, propName: string): {
|
|
17
|
+
name: string;
|
|
18
|
+
type: any;
|
|
19
|
+
compositionType?: Type<any> | undefined;
|
|
20
|
+
compositionAction?: "onlySet" | "addTo" | undefined;
|
|
21
|
+
} | null | undefined;
|
|
15
22
|
static getTargets(source: Type<any>): Type<any>[];
|
|
16
23
|
static addMappedProp(source: Type<any>, propName: string): void;
|
|
17
24
|
}
|
|
@@ -19,6 +19,15 @@ class AutoMappingList {
|
|
|
19
19
|
propTargetContext: this._mappedPropList.find((mp) => mp.source === target),
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
|
+
static getSourceByName(sourceName) {
|
|
23
|
+
return this._mappingProfileList.find((mp) => mp.source.name === sourceName)
|
|
24
|
+
?.source;
|
|
25
|
+
}
|
|
26
|
+
static getPropDefinitions(source, propName) {
|
|
27
|
+
return this._mappedPropList
|
|
28
|
+
.find((mp) => mp.source === source)
|
|
29
|
+
?.props.find((prop) => prop.name === propName);
|
|
30
|
+
}
|
|
22
31
|
static getTargets(source) {
|
|
23
32
|
return this._mappingProfileList
|
|
24
33
|
.filter((mp) => mp.source === source)
|
|
@@ -17,7 +17,8 @@ function AutoMap(config) {
|
|
|
17
17
|
customMetadata = Array;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
|
-
if (!Reflect.getMetadata('design:type', target, propertyKey) ||
|
|
20
|
+
if (!Reflect.getMetadata('design:type', target, propertyKey) ||
|
|
21
|
+
!isArray) {
|
|
21
22
|
Reflect.defineMetadata('design:type', customMetadata, target, propertyKey);
|
|
22
23
|
}
|
|
23
24
|
}
|
|
@@ -29,7 +29,7 @@ let AutoMappingService = exports.AutoMappingService = class AutoMappingService {
|
|
|
29
29
|
const value = data[propSource.name];
|
|
30
30
|
const compositionType = propSource.compositionType;
|
|
31
31
|
const compositionAction = propSource.compositionAction;
|
|
32
|
-
if (value) {
|
|
32
|
+
if (value !== undefined) {
|
|
33
33
|
const targetProp = propTargetContext?.props.find((tp) => tp.name === propSource.name);
|
|
34
34
|
if (targetProp) {
|
|
35
35
|
const listToArray = propSource.type === list_1.List.name &&
|
|
@@ -46,6 +46,12 @@ let AutoMappingService = exports.AutoMappingService = class AutoMappingService {
|
|
|
46
46
|
else if (arrayToList) {
|
|
47
47
|
mappedValue = this.mapArrayToList(value, compositionType, compositionAction === 'onlySet');
|
|
48
48
|
}
|
|
49
|
+
else {
|
|
50
|
+
const propSourceInstance = this._contextList.getSourceByName(propSource.type);
|
|
51
|
+
if (propSourceInstance) {
|
|
52
|
+
mappedValue = this.mapNestedProp(value, propSourceInstance);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
49
55
|
mappedTarget[targetProp.name] = mappedValue;
|
|
50
56
|
}
|
|
51
57
|
}
|
|
@@ -65,9 +71,7 @@ let AutoMappingService = exports.AutoMappingService = class AutoMappingService {
|
|
|
65
71
|
}
|
|
66
72
|
}
|
|
67
73
|
mapListToArray(value) {
|
|
68
|
-
return value
|
|
69
|
-
.toArray()
|
|
70
|
-
.map((item) => {
|
|
74
|
+
return value.toArray().map((item) => {
|
|
71
75
|
const entityOnList = value.entityType?.prototype.constructor;
|
|
72
76
|
if (entityOnList) {
|
|
73
77
|
return this.mapNestedProp(item, entityOnList) ?? {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Type } from
|
|
2
|
-
export declare function assignObject<T>(
|
|
1
|
+
import { Type } from '@nestjs/common';
|
|
2
|
+
export declare function assignObject<T>(Target: Type<T>, source: T): T;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.assignObject = void 0;
|
|
4
|
-
function assignObject(
|
|
5
|
-
return Object.assign(new
|
|
4
|
+
function assignObject(Target, source) {
|
|
5
|
+
return Object.assign(new Target(), source);
|
|
6
6
|
}
|
|
7
7
|
exports.assignObject = assignObject;
|
package/core/utils/list.js
CHANGED
package/core/utils/list.spec.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
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
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
12
|
const entity_base_1 = require("../database/entity.base");
|
|
13
|
+
const auto_mapping_decorator_1 = require("../mapping/auto-mapping.decorator");
|
|
4
14
|
const list_1 = require("./list");
|
|
5
15
|
class EntityTest extends entity_base_1.EntityBase {
|
|
6
16
|
id;
|
|
@@ -10,6 +20,14 @@ class EntityTest extends entity_base_1.EntityBase {
|
|
|
10
20
|
this.automap(props);
|
|
11
21
|
}
|
|
12
22
|
}
|
|
23
|
+
__decorate([
|
|
24
|
+
(0, auto_mapping_decorator_1.AutoMap)(),
|
|
25
|
+
__metadata("design:type", Number)
|
|
26
|
+
], EntityTest.prototype, "id", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, auto_mapping_decorator_1.AutoMap)(),
|
|
29
|
+
__metadata("design:type", Number)
|
|
30
|
+
], EntityTest.prototype, "value", void 0);
|
|
13
31
|
describe('List test', () => {
|
|
14
32
|
let entity;
|
|
15
33
|
beforeEach(() => {
|
package/env/env.service.d.ts
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { ConfigService } from '@nestjs/config';
|
|
2
2
|
import { Env } from './env';
|
|
3
|
-
export declare class EnvService {
|
|
3
|
+
export declare class EnvService<TEnv = Env> {
|
|
4
4
|
private readonly configService;
|
|
5
|
-
constructor(configService: ConfigService<
|
|
6
|
-
get<T extends keyof
|
|
7
|
-
NODE_ENV: "test" | "develop" | "staging" | "production";
|
|
8
|
-
PORT: number;
|
|
9
|
-
PRISMA_QUERY_LOG: boolean;
|
|
10
|
-
REDIS_CONNECTION_STRING: string;
|
|
11
|
-
SWAGGER_USERNAME?: string | undefined;
|
|
12
|
-
SWAGGER_PASSWORD?: string | undefined;
|
|
13
|
-
}, T>;
|
|
5
|
+
constructor(configService: ConfigService<TEnv, true>);
|
|
6
|
+
get<T extends keyof TEnv>(key: T): (string extends infer T_1 ? T_1 extends string ? T_1 extends keyof TEnv ? string extends infer T_2 ? T_2 extends string ? T_2 extends import("@nestjs/config").Path<TEnv[T_1]> ? import("@nestjs/config").PathValue<TEnv[T_1], T_2> : never : never : never : never : never : never) | (any extends infer T_3 ? T_3 extends any ? T_3 extends keyof TEnv ? TEnv[T_3] : never : never : never);
|
|
14
7
|
}
|
package/package.json
CHANGED