@serene-dev/la-nest-library 0.0.171 → 0.0.173
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/dist/libs/la-library/src/modules/authentication/authentication.guard.d.ts +1 -1
- package/dist/libs/la-library/src/modules/authentication/authentication.guard.js +2 -2
- package/dist/libs/la-library/src/modules/authentication/authentication.guard.js.map +1 -1
- package/dist/libs/la-library/src/modules/category/category.service.d.ts +3 -3
- package/dist/libs/la-library/src/modules/category/category.service.js +1 -2
- package/dist/libs/la-library/src/modules/category/category.service.js.map +1 -1
- package/dist/libs/la-library/src/services/custom-repository.service.d.ts +5 -3
- package/dist/libs/la-library/src/services/custom-repository.service.js +10 -32
- package/dist/libs/la-library/src/services/custom-repository.service.js.map +1 -1
- package/dist/libs/la-library/src/services/shared-repository.service.d.ts +11 -0
- package/dist/libs/la-library/src/services/shared-repository.service.js +43 -0
- package/dist/libs/la-library/src/services/shared-repository.service.js.map +1 -0
- package/package.json +1 -1
|
@@ -14,7 +14,7 @@ export declare class AuthenticationGuard<TEntity extends AuthEntity = AuthEntity
|
|
|
14
14
|
extraCheck?: (context: ExecutionContext, payload: IAuthParam) => Promise<boolean>;
|
|
15
15
|
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
16
16
|
private extractTokenFromHeader;
|
|
17
|
-
requestPatcher: (request: any, payload: any) => void
|
|
17
|
+
requestPatcher: (request: any, payload: any) => Promise<void>;
|
|
18
18
|
static provideGuard(): {
|
|
19
19
|
provide: string;
|
|
20
20
|
useClass: typeof AuthenticationGuard;
|
|
@@ -24,7 +24,7 @@ let AuthenticationGuard = AuthenticationGuard_1 = class AuthenticationGuard {
|
|
|
24
24
|
this.authS = authS;
|
|
25
25
|
this.reflector = reflector;
|
|
26
26
|
this.skipEnvironment = 'dev';
|
|
27
|
-
this.requestPatcher = (request, payload) => {
|
|
27
|
+
this.requestPatcher = async (request, payload) => {
|
|
28
28
|
request['user'] = payload;
|
|
29
29
|
};
|
|
30
30
|
}
|
|
@@ -46,7 +46,7 @@ let AuthenticationGuard = AuthenticationGuard_1 = class AuthenticationGuard {
|
|
|
46
46
|
payload = await this.tokenService.decryptToken(token);
|
|
47
47
|
payload.token = token;
|
|
48
48
|
await this.authS.verifyAuthToken(token);
|
|
49
|
-
this.requestPatcher(request, payload);
|
|
49
|
+
await this.requestPatcher(request, payload);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authentication.guard.js","sourceRoot":"","sources":["../../../../../../libs/la-library/src/modules/authentication/authentication.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAMwB;AAExB,gEAA4D;AAC5D,qEAAiE;AACjE,+DAAuD;AACvD,2CAA6C;AAC7C,uCAAoD;AACpD,4EAAyD;AAMlD,IAAM,mBAAmB,2BAAzB,MAAM,mBAAmB;IAI9B,YACY,YAA0B,EAC1B,KAAqC,EACrC,SAAoB;QAFpB,iBAAY,GAAZ,YAAY,CAAc;QAC1B,UAAK,GAAL,KAAK,CAAgC;QACrC,cAAS,GAAT,SAAS,CAAW;QAJhC,oBAAe,GAA2B,KAAK,CAAC;QA+ChD,mBAAc,GAAG,
|
|
1
|
+
{"version":3,"file":"authentication.guard.js","sourceRoot":"","sources":["../../../../../../libs/la-library/src/modules/authentication/authentication.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAMwB;AAExB,gEAA4D;AAC5D,qEAAiE;AACjE,+DAAuD;AACvD,2CAA6C;AAC7C,uCAAoD;AACpD,4EAAyD;AAMlD,IAAM,mBAAmB,2BAAzB,MAAM,mBAAmB;IAI9B,YACY,YAA0B,EAC1B,KAAqC,EACrC,SAAoB;QAFpB,iBAAY,GAAZ,YAAY,CAAc;QAC1B,UAAK,GAAL,KAAK,CAAgC;QACrC,cAAS,GAAT,SAAS,CAAW;QAJhC,oBAAe,GAA2B,KAAK,CAAC;QA+ChD,mBAA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C,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC1E,CAAC;IAEO,sBAAsB,CAAC,OAAgB;QAC7C,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,aAAa,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;QACtE,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/C,CAAC;IAMD,MAAM,CAAC,YAAY;QACjB,OAAO;YACL,OAAO,EAAE,gBAAS;YAClB,QAAQ,EAAE,qBAAmB;SAC9B,CAAC;IACJ,CAAC;CACF,CAAA;AA5DY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;qCAMe,4BAAY;QACnB,8CAAqB;QACjB,gBAAS;GAPrB,mBAAmB,CA4D/B;AAED,MAAM,aAAa,GAAG,UAAU,CAAC;AAC1B,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,IAAA,oBAAW,EAAC,aAAa,EAAE,IAAI,CAAC,CAAC;AAApD,QAAA,UAAU,cAA0C;AAEpD,QAAA,SAAS,GAAG,IAAA,6BAAoB,EAC3C,CAAC,IAAI,EAAE,GAAyB,EAAE,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAC/D,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { BaseService } from '../../services/base.service';
|
|
2
2
|
import { CategoryEntity } from './category.entity';
|
|
3
|
+
import { Repository } from 'typeorm';
|
|
3
4
|
import { CreateCategoryDto, GetCategoryBySlugDto, GetCategoryBySlugQueryDto, SearchCategoryDto, UpdateCategoryDto } from './category.dto';
|
|
4
|
-
import { CustomRepositoryService } from '../../services/custom-repository.service';
|
|
5
5
|
export declare class CategoryService extends BaseService<CategoryEntity, SearchCategoryDto> {
|
|
6
|
-
repo:
|
|
7
|
-
constructor(repo:
|
|
6
|
+
repo: Repository<CategoryEntity>;
|
|
7
|
+
constructor(repo: Repository<CategoryEntity>);
|
|
8
8
|
_createChecks(data: CreateCategoryDto): Promise<void>;
|
|
9
9
|
_updateChecks(id: string, data: UpdateCategoryDto): Promise<void>;
|
|
10
10
|
_deleteChecks(ids: string[]): Promise<void>;
|
|
@@ -20,7 +20,6 @@ const typeorm_1 = require("typeorm");
|
|
|
20
20
|
const typeorm_2 = require("@nestjs/typeorm");
|
|
21
21
|
const base_enum_1 = require("../../enums/base.enum");
|
|
22
22
|
const search_enum_1 = require("../../enums/search.enum");
|
|
23
|
-
const custom_repository_service_1 = require("../../services/custom-repository.service");
|
|
24
23
|
let CategoryService = class CategoryService extends base_service_1.BaseService {
|
|
25
24
|
constructor(repo) {
|
|
26
25
|
super(repo, base_enum_1.ETableName.category);
|
|
@@ -66,6 +65,6 @@ exports.CategoryService = CategoryService;
|
|
|
66
65
|
exports.CategoryService = CategoryService = __decorate([
|
|
67
66
|
(0, common_1.Injectable)(),
|
|
68
67
|
__param(0, (0, typeorm_2.InjectRepository)(category_entity_1.CategoryEntity)),
|
|
69
|
-
__metadata("design:paramtypes", [
|
|
68
|
+
__metadata("design:paramtypes", [typeorm_1.Repository])
|
|
70
69
|
], CategoryService);
|
|
71
70
|
//# sourceMappingURL=category.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"category.service.js","sourceRoot":"","sources":["../../../../../../libs/la-library/src/modules/category/category.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,8DAA0D;AAC1D,uDAAmD;AACnD,
|
|
1
|
+
{"version":3,"file":"category.service.js","sourceRoot":"","sources":["../../../../../../libs/la-library/src/modules/category/category.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA4C;AAC5C,8DAA0D;AAC1D,uDAAmD;AACnD,qCAA8C;AAC9C,6CAAmD;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YAAY,EAAE,uBAAuB,EAAE,CAC1C,CAAC;QACJ,MAAM,IAAI,CAAC,eAAe,CACxB,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,IAAA,aAAG,EAAC,EAAE,CAAC,EAAE,EACzD,EAAE,YAAY,EAAE,QAAQ,IAAI,CAAC,IAAI,iBAAiB,EAAE,CACrD,CAAC;IACJ,CAAC;IAEQ,KAAK,CAAC,aAAa,CAAC,GAAa;QACxC,MAAM,IAAI,CAAC,gBAAgB,CAAC,EAAE,EAAE,EAAE,IAAA,YAAE,EAAC,GAAG,CAAC,EAAE,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,CAAC,CAAC;IAC9E,CAAC;IAED,SAAS,CAAC,KAAgC;QACxC,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YACpB,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,UAAU,EAAE,EAAE;YAC/D,MAAM,EAAE;gBACN,KAAK,EAAE,IAAI;gBACX,EAAE,EAAE,IAAI;gBACR,IAAI,EAAE,IAAI;gBACV,WAAW,EAAE,IAAI;aAClB;SACF,CAAoC,CAAC;IACxC,CAAC;CACF,CAAA;AA9DY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;IAMR,WAAA,IAAA,0BAAgB,EAAC,gCAAc,CAAC,CAAA;qCACX,oBAAU;GANvB,eAAe,CA8D3B"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DataSource, EntityTarget, FindOptionsWhere, QueryRunner, Repository } from 'typeorm';
|
|
2
2
|
import { BaseEntity } from '../entities/base.entity';
|
|
3
3
|
import { ICheckByParams } from '../interfaces/base.interface';
|
|
4
4
|
import { ToggleActiveDTO } from '../dtos/base.dto';
|
|
5
|
+
import { SharedRepositoryService } from './shared-repository.service';
|
|
5
6
|
export declare class CustomRepositoryService<TEntity extends BaseEntity> extends Repository<BaseEntity & TEntity> {
|
|
6
7
|
target: EntityTarget<TEntity>;
|
|
7
|
-
|
|
8
|
+
dataSource: DataSource;
|
|
8
9
|
queryRunner?: QueryRunner;
|
|
9
|
-
|
|
10
|
+
protected sharedRepositoryService: SharedRepositoryService<TEntity>;
|
|
11
|
+
constructor(target: EntityTarget<TEntity>, dataSource: DataSource, queryRunner?: QueryRunner);
|
|
10
12
|
_checkIfExistsById(id: string, config?: Pick<ICheckByParams<TEntity>['config'], 'throwError' | 'errorMessage'>): Promise<boolean>;
|
|
11
13
|
_checkExistenceBy(where: FindOptionsWhere<TEntity> | FindOptionsWhere<TEntity>[], config: ICheckByParams<TEntity>['config']): Promise<boolean>;
|
|
12
14
|
_getAllIDs(where?: FindOptionsWhere<TEntity> | FindOptionsWhere<TEntity>[]): Promise<string[]>;
|
|
@@ -12,53 +12,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.CustomRepositoryService = void 0;
|
|
13
13
|
const common_1 = require("@nestjs/common");
|
|
14
14
|
const typeorm_1 = require("typeorm");
|
|
15
|
-
const
|
|
15
|
+
const shared_repository_service_1 = require("./shared-repository.service");
|
|
16
16
|
let CustomRepositoryService = class CustomRepositoryService extends typeorm_1.Repository {
|
|
17
|
-
constructor(target,
|
|
18
|
-
super(target,
|
|
17
|
+
constructor(target, dataSource, queryRunner) {
|
|
18
|
+
super(target, dataSource.createEntityManager(), queryRunner);
|
|
19
19
|
this.target = target;
|
|
20
|
-
this.
|
|
20
|
+
this.dataSource = dataSource;
|
|
21
21
|
this.queryRunner = queryRunner;
|
|
22
|
+
this.sharedRepositoryService = new shared_repository_service_1.SharedRepositoryService();
|
|
22
23
|
}
|
|
23
24
|
async _checkIfExistsById(id, config) {
|
|
24
|
-
return this.
|
|
25
|
-
shouldExist: true,
|
|
26
|
-
...(config || {}),
|
|
27
|
-
});
|
|
25
|
+
return this.sharedRepositoryService.checkIfExistsById(this, id, config);
|
|
28
26
|
}
|
|
29
27
|
async _checkExistenceBy(where, config) {
|
|
30
|
-
|
|
31
|
-
where: where,
|
|
32
|
-
});
|
|
33
|
-
if (exists != config.shouldExist &&
|
|
34
|
-
((config.errorMessage && config.throwError !== false) ||
|
|
35
|
-
config.throwError === true))
|
|
36
|
-
utility_service_1.UtilityClass.throwError({
|
|
37
|
-
statusCode: config.shouldExist ? 404 : 409,
|
|
38
|
-
message: config.errorMessage ||
|
|
39
|
-
(config.shouldExist ? `It does not exist` : `It already exists`),
|
|
40
|
-
});
|
|
41
|
-
return exists;
|
|
28
|
+
return this.sharedRepositoryService.checkExistenceBy(this, where, config);
|
|
42
29
|
}
|
|
43
30
|
async _getAllIDs(where) {
|
|
44
|
-
return
|
|
45
|
-
select: { id: true },
|
|
46
|
-
where: where,
|
|
47
|
-
})).map((x) => x.id);
|
|
31
|
+
return this.sharedRepositoryService.getAllIDs(this, where);
|
|
48
32
|
}
|
|
49
33
|
async _toggleActive(id, body) {
|
|
50
|
-
|
|
51
|
-
utility_service_1.UtilityClass.throwError({
|
|
52
|
-
message: `ID does not exist`,
|
|
53
|
-
statusCode: 404,
|
|
54
|
-
});
|
|
55
|
-
await this.update({ id: id }, body);
|
|
56
|
-
return true;
|
|
34
|
+
return this.sharedRepositoryService.toggleActive(this, id, body);
|
|
57
35
|
}
|
|
58
36
|
};
|
|
59
37
|
exports.CustomRepositoryService = CustomRepositoryService;
|
|
60
38
|
exports.CustomRepositoryService = CustomRepositoryService = __decorate([
|
|
61
39
|
(0, common_1.Injectable)(),
|
|
62
|
-
__metadata("design:paramtypes", [Object, typeorm_1.
|
|
40
|
+
__metadata("design:paramtypes", [Object, typeorm_1.DataSource, Object])
|
|
63
41
|
], CustomRepositoryService);
|
|
64
42
|
//# sourceMappingURL=custom-repository.service.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-repository.service.js","sourceRoot":"","sources":["../../../../../libs/la-library/src/services/custom-repository.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,
|
|
1
|
+
{"version":3,"file":"custom-repository.service.js","sourceRoot":"","sources":["../../../../../libs/la-library/src/services/custom-repository.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,qCAMiB;AAIjB,2EAAsE;AAG/D,IAAM,uBAAuB,GAA7B,MAAM,uBAEX,SAAQ,oBAAgC;IAExC,YACkB,MAA6B,EACtC,UAAsB,EACb,WAAyB;QAEzC,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,mBAAmB,EAAE,EAAE,WAAW,CAAC,CAAC;QAJ7C,WAAM,GAAN,MAAM,CAAuB;QACtC,eAAU,GAAV,UAAU,CAAY;QACb,gBAAW,GAAX,WAAW,CAAc;QAJjC,4BAAuB,GAAG,IAAI,mDAAuB,EAAW,CAAC;IAO3E,CAAC;IACD,KAAK,CAAC,kBAAkB,CACtB,EAAU,EACV,MAGC;QAED,OAAO,IAAI,CAAC,uBAAuB,CAAC,iBAAiB,CACnD,IAA2B,EAC3B,EAAE,EACF,MAAM,CACP,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,iBAAiB,CACrB,KAA8D,EAC9D,MAAyC;QAEzC,OAAO,IAAI,CAAC,uBAAuB,CAAC,gBAAgB,CAClD,IAA2B,EAC3B,KAAK,EACL,MAAM,CACP,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,UAAU,CACd,KAA+D;QAE/D,OAAO,IAAI,CAAC,uBAAuB,CAAC,SAAS,CAC3C,IAA2B,EAC3B,KAAK,CACN,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,EAAU,EAAE,IAAqB;QACnD,OAAO,IAAI,CAAC,uBAAuB,CAAC,YAAY,CAC9C,IAA2B,EAC3B,EAAE,EACF,IAAI,CACL,CAAC;IACJ,CAAC;CACF,CAAA;AApDY,0DAAuB;kCAAvB,uBAAuB;IADnC,IAAA,mBAAU,GAAE;6CAOU,oBAAU;GANpB,uBAAuB,CAoDnC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FindOptionsWhere, Repository } from 'typeorm';
|
|
2
|
+
import { ICheckByParams } from '../interfaces/base.interface';
|
|
3
|
+
import { ToggleActiveDTO } from '../dtos/base.dto';
|
|
4
|
+
export declare class SharedRepositoryService<TEntity extends {
|
|
5
|
+
id?: string;
|
|
6
|
+
}> {
|
|
7
|
+
checkIfExistsById(repo: Repository<TEntity>, id: string, config?: Pick<ICheckByParams<TEntity>['config'], 'throwError' | 'errorMessage'>): Promise<boolean>;
|
|
8
|
+
checkExistenceBy(repo: Repository<TEntity>, where: FindOptionsWhere<TEntity> | FindOptionsWhere<TEntity>[], config: ICheckByParams<TEntity>['config']): Promise<boolean>;
|
|
9
|
+
getAllIDs(repo: Repository<TEntity>, where?: FindOptionsWhere<TEntity> | FindOptionsWhere<TEntity>[]): Promise<string[]>;
|
|
10
|
+
toggleActive(repo: Repository<TEntity>, id: string, body: ToggleActiveDTO): Promise<boolean>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SharedRepositoryService = void 0;
|
|
4
|
+
const utility_service_1 = require("./utility.service");
|
|
5
|
+
class SharedRepositoryService {
|
|
6
|
+
async checkIfExistsById(repo, id, config) {
|
|
7
|
+
return this.checkExistenceBy(repo, { id }, {
|
|
8
|
+
shouldExist: true,
|
|
9
|
+
...(config || {}),
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
async checkExistenceBy(repo, where, config) {
|
|
13
|
+
const exists = await repo.exist({
|
|
14
|
+
where: where,
|
|
15
|
+
});
|
|
16
|
+
if (exists != config.shouldExist &&
|
|
17
|
+
((config.errorMessage && config.throwError !== false) ||
|
|
18
|
+
config.throwError === true))
|
|
19
|
+
utility_service_1.UtilityClass.throwError({
|
|
20
|
+
statusCode: config.shouldExist ? 404 : 409,
|
|
21
|
+
message: config.errorMessage ||
|
|
22
|
+
(config.shouldExist ? `It does not exist` : `It already exists`),
|
|
23
|
+
});
|
|
24
|
+
return exists;
|
|
25
|
+
}
|
|
26
|
+
async getAllIDs(repo, where) {
|
|
27
|
+
return (await repo.find({
|
|
28
|
+
select: { id: true },
|
|
29
|
+
where: where,
|
|
30
|
+
})).map((x) => x.id);
|
|
31
|
+
}
|
|
32
|
+
async toggleActive(repo, id, body) {
|
|
33
|
+
if (!(await this.checkIfExistsById(repo, id)))
|
|
34
|
+
utility_service_1.UtilityClass.throwError({
|
|
35
|
+
message: `ID does not exist`,
|
|
36
|
+
statusCode: 404,
|
|
37
|
+
});
|
|
38
|
+
await repo.update({ id: id }, body);
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.SharedRepositoryService = SharedRepositoryService;
|
|
43
|
+
//# sourceMappingURL=shared-repository.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-repository.service.js","sourceRoot":"","sources":["../../../../../libs/la-library/src/services/shared-repository.service.ts"],"names":[],"mappings":";;;AAEA,uDAAiD;AAIjD,MAAa,uBAAuB;IAClC,KAAK,CAAC,iBAAiB,CACrB,IAAyB,EACzB,EAAU,EACV,MAGC;QAED,OAAO,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,EAAE,EAAE,EAAS,EAAE;YAChD,WAAW,EAAE,IAAI;YACjB,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC;SAClB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,gBAAgB,CACpB,IAAyB,EACzB,KAA8D,EAC9D,MAAyC;QAEzC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC;YAC9B,KAAK,EAAE,KAAK;SACb,CAAC,CAAC;QACH,IACE,MAAM,IAAI,MAAM,CAAC,WAAW;YAC5B,CAAC,CAAC,MAAM,CAAC,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