@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
|
@@ -1,16 +1,17 @@
|
|
|
1
|
+
import { PaginationDto } from '@koalarx/nest/core/dtos/pagination.dto';
|
|
1
2
|
import { CreatedRegistreResponseBase } from '../../core/controllers/created-registre-response.base';
|
|
2
3
|
import { ListResponseBase } from '../../core/controllers/list-response.base';
|
|
3
4
|
import { EntityBase } from '../../core/database/entity.base';
|
|
4
|
-
import { PaginationParams } from '../../core/models/pagination-params';
|
|
5
5
|
import { IComparableId } from '../../core/utils/interfaces/icomparable';
|
|
6
6
|
export declare abstract class InMemoryBaseRepository<TClass extends EntityBase<any>> {
|
|
7
7
|
private readonly typeId;
|
|
8
8
|
protected items: TClass[];
|
|
9
9
|
constructor(typeId?: 'number' | 'string');
|
|
10
10
|
protected findById(id: IComparableId): Promise<TClass | null>;
|
|
11
|
-
protected findMany<T extends
|
|
12
|
-
protected findManyAndCount<T extends
|
|
13
|
-
protected
|
|
11
|
+
protected findMany<T extends PaginationDto>(query: T, predicate?: (value: TClass, index: number, array: TClass[]) => unknown): Promise<TClass[]>;
|
|
12
|
+
protected findManyAndCount<T extends PaginationDto>(query: T, predicate?: (value: TClass, index: number, array: TClass[]) => unknown): Promise<ListResponseBase<TClass>>;
|
|
13
|
+
protected insert(item: TClass): Promise<CreatedRegistreResponseBase<any>>;
|
|
14
|
+
protected edit(item: TClass, updateWhere?: (item: TClass) => boolean): Promise<void>;
|
|
14
15
|
protected remove(predicate: (value: TClass, index: number, obj: TClass[]) => unknown): Promise<void>;
|
|
15
16
|
private getNewId;
|
|
16
17
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.InMemoryBaseRepository = void 0;
|
|
4
|
+
const query_params_1 = require("../../core/constants/query-params");
|
|
4
5
|
const array_1 = require("@koalarx/utils/operators/array");
|
|
5
|
-
const pagination_params_1 = require("../../core/models/pagination-params");
|
|
6
6
|
const node_crypto_1 = require("node:crypto");
|
|
7
7
|
class InMemoryBaseRepository {
|
|
8
8
|
typeId;
|
|
@@ -14,8 +14,8 @@ class InMemoryBaseRepository {
|
|
|
14
14
|
return this.items.find((item) => item._id === id) ?? null;
|
|
15
15
|
}
|
|
16
16
|
async findMany(query, predicate) {
|
|
17
|
-
const page = query.page ??
|
|
18
|
-
const limit = query.limit ??
|
|
17
|
+
const page = query.page ?? query_params_1.QUERY_FILTER_PARAMS.page;
|
|
18
|
+
const limit = query.limit ?? query_params_1.QUERY_FILTER_PARAMS.limit;
|
|
19
19
|
return (0, array_1.klArray)(predicate ? this.items.filter(predicate) : this.items)
|
|
20
20
|
.orderBy(query.orderBy ?? '', query.direction === 'desc')
|
|
21
21
|
.getValue()
|
|
@@ -28,18 +28,19 @@ class InMemoryBaseRepository {
|
|
|
28
28
|
count: items.length,
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
-
async
|
|
32
|
-
const
|
|
33
|
-
if (itemIndex > -1) {
|
|
34
|
-
this.items[itemIndex] = item;
|
|
35
|
-
}
|
|
36
|
-
const id = this.typeId === 'number'
|
|
37
|
-
? this.getNewId()
|
|
38
|
-
: (0, node_crypto_1.randomUUID)();
|
|
31
|
+
async insert(item) {
|
|
32
|
+
const id = this.typeId === 'number' ? this.getNewId() : (0, node_crypto_1.randomUUID)();
|
|
39
33
|
item.automap({ ...item, id });
|
|
40
34
|
this.items.push(item);
|
|
41
35
|
return { id: item._id };
|
|
42
36
|
}
|
|
37
|
+
async edit(item, updateWhere) {
|
|
38
|
+
const predicate = updateWhere ?? ((itemDB) => itemDB.equals(item));
|
|
39
|
+
const itemIndex = this.items.findIndex(predicate);
|
|
40
|
+
if (itemIndex > -1) {
|
|
41
|
+
this.items[itemIndex] = item;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
43
44
|
async remove(predicate) {
|
|
44
45
|
const itemIndex = this.items.findIndex(predicate);
|
|
45
46
|
if (itemIndex > -1) {
|
|
@@ -48,7 +49,8 @@ class InMemoryBaseRepository {
|
|
|
48
49
|
}
|
|
49
50
|
getNewId() {
|
|
50
51
|
return this.typeId === 'number'
|
|
51
|
-
? (0, array_1.klArray)(this.items).orderBy('_id', true).getValue()[0]
|
|
52
|
+
? (0, array_1.klArray)(this.items).orderBy('_id', true).getValue()[0]
|
|
53
|
+
?._id ?? 0 + 1
|
|
52
54
|
: (0, node_crypto_1.randomUUID)();
|
|
53
55
|
}
|
|
54
56
|
}
|