@sisques-labs/nestjs-kit 0.6.0 → 0.7.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/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/shared/domain/events/base-event.interface.d.ts +3 -0
- package/dist/shared/domain/events/base-event.interface.js +3 -0
- package/dist/shared/domain/events/base-event.interface.js.map +1 -1
- package/dist/shared/domain/interfaces/event-metadata.interface.d.ts +3 -0
- package/dist/shared/infrastructure/kafka/schema-registry/schema-registry-options.interface.d.ts +8 -0
- package/dist/shared/infrastructure/kafka/schema-registry/schema-registry-options.interface.js +3 -0
- package/dist/shared/infrastructure/kafka/schema-registry/schema-registry-options.interface.js.map +1 -0
- package/dist/shared/infrastructure/kafka/schema-registry/schema-registry.constants.d.ts +1 -0
- package/dist/shared/infrastructure/kafka/schema-registry/schema-registry.constants.js +5 -0
- package/dist/shared/infrastructure/kafka/schema-registry/schema-registry.constants.js.map +1 -0
- package/dist/shared/infrastructure/kafka/schema-registry/schema-registry.module.d.ts +6 -0
- package/dist/shared/infrastructure/kafka/schema-registry/schema-registry.module.js +47 -0
- package/dist/shared/infrastructure/kafka/schema-registry/schema-registry.module.js.map +1 -0
- package/dist/shared/infrastructure/kafka/schema-registry/schema-registry.service.d.ts +30 -0
- package/dist/shared/infrastructure/kafka/schema-registry/schema-registry.service.js +89 -0
- package/dist/shared/infrastructure/kafka/schema-registry/schema-registry.service.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +11 -1
package/dist/index.d.ts
CHANGED
|
@@ -84,6 +84,9 @@ export * from './shared/infrastructure/database/typeorm/services/typeorm-master/
|
|
|
84
84
|
export * from './shared/infrastructure/database/typeorm/typeorm-module-options.factory';
|
|
85
85
|
export * from './shared/infrastructure/database/typeorm/typeorm.module';
|
|
86
86
|
export * from './shared/infrastructure/kafka/interfaces/kafka-event-publisher.interface';
|
|
87
|
+
export * from './shared/infrastructure/kafka/schema-registry/schema-registry.module';
|
|
88
|
+
export * from './shared/infrastructure/kafka/schema-registry/schema-registry.service';
|
|
89
|
+
export * from './shared/infrastructure/kafka/schema-registry/schema-registry-options.interface';
|
|
87
90
|
export * from './shared/transport/graphql/register-shared-graphql-enums';
|
|
88
91
|
export * from './shared/transport/graphql/dtos/requests/base-filter/base-filter.input';
|
|
89
92
|
export * from './shared/transport/graphql/dtos/requests/base-find-by-criteria/base-find-by-criteria.input';
|
package/dist/index.js
CHANGED
|
@@ -100,6 +100,9 @@ __exportStar(require("./shared/infrastructure/database/typeorm/services/typeorm-
|
|
|
100
100
|
__exportStar(require("./shared/infrastructure/database/typeorm/typeorm-module-options.factory"), exports);
|
|
101
101
|
__exportStar(require("./shared/infrastructure/database/typeorm/typeorm.module"), exports);
|
|
102
102
|
__exportStar(require("./shared/infrastructure/kafka/interfaces/kafka-event-publisher.interface"), exports);
|
|
103
|
+
__exportStar(require("./shared/infrastructure/kafka/schema-registry/schema-registry.module"), exports);
|
|
104
|
+
__exportStar(require("./shared/infrastructure/kafka/schema-registry/schema-registry.service"), exports);
|
|
105
|
+
__exportStar(require("./shared/infrastructure/kafka/schema-registry/schema-registry-options.interface"), exports);
|
|
103
106
|
__exportStar(require("./shared/transport/graphql/register-shared-graphql-enums"), exports);
|
|
104
107
|
__exportStar(require("./shared/transport/graphql/dtos/requests/base-filter/base-filter.input"), exports);
|
|
105
108
|
__exportStar(require("./shared/transport/graphql/dtos/requests/base-find-by-criteria/base-find-by-criteria.input"), exports);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAEA,0FAAwE;AACxE,0GAAwF;AACxF,+GAA6F;AAC7F,+FAA6E;AAC7E,kHAAgG;AAChG,+FAA6E;AAC7E,gHAA8F;AAC9F,oGAAkF;AAClF,oGAAkF;AA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AA+E;AAC/E,wGAAsF;AACtF,0HAAwG;AACxG,0GAAwF;AACxF,0FAAwE;AAGxE,2GAAyF;AAGzF,uGAAqF;AACrF,wGAAsF;AACtF,kHAAgG;AAKhG,2FAAyE;AAGzE,yGAAuF;AACvF,6HAA2G;AAC3G,iHAA+F;AAC/F,qGAAmF;AACnF,6GAA2F;AAG3F,4HAA0G;AAC1G,4GAA0F;AAC1F,kHAAgG;AAChG,6FAA2E;AAG3E,yFAAuE;AACvE,gHAA8F;AAG9F,uFAAqE"}
|
|
@@ -7,6 +7,9 @@ export declare abstract class BaseEvent<TData> {
|
|
|
7
7
|
readonly ocurredAt: Date;
|
|
8
8
|
readonly entityId: string;
|
|
9
9
|
readonly entityType: string;
|
|
10
|
+
readonly schemaVersion: string;
|
|
11
|
+
readonly correlationId: string | null;
|
|
12
|
+
readonly causationId: string | null;
|
|
10
13
|
protected readonly _data: TData;
|
|
11
14
|
constructor(metadata: IEventMetadata, data: TData);
|
|
12
15
|
get data(): TData;
|
|
@@ -11,6 +11,9 @@ class BaseEvent {
|
|
|
11
11
|
this.entityId = metadata.entityId;
|
|
12
12
|
this.entityType = metadata.entityType;
|
|
13
13
|
this.ocurredAt = new Date();
|
|
14
|
+
this.schemaVersion = metadata.schemaVersion ?? '1.0.0';
|
|
15
|
+
this.correlationId = metadata.correlationId ?? null;
|
|
16
|
+
this.causationId = metadata.causationId ?? null;
|
|
14
17
|
this._data = data;
|
|
15
18
|
}
|
|
16
19
|
get data() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-event.interface.js","sourceRoot":"","sources":["../../../../src/shared/domain/events/base-event.interface.ts"],"names":[],"mappings":";;;AACA,mCAAoC;AAOpC,MAAsB,SAAS;
|
|
1
|
+
{"version":3,"file":"base-event.interface.js","sourceRoot":"","sources":["../../../../src/shared/domain/events/base-event.interface.ts"],"names":[],"mappings":";;;AACA,mCAAoC;AAOpC,MAAsB,SAAS;IAgE7B,YAAY,QAAwB,EAAE,IAAW;QAC/C,IAAI,CAAC,OAAO,GAAG,IAAA,mBAAU,GAAE,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC;QACpC,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAC,eAAe,CAAC;QAChD,IAAI,CAAC,iBAAiB,GAAG,QAAQ,CAAC,iBAAiB,CAAC;QACpD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC,QAAQ,CAAC;QAClC,IAAI,CAAC,UAAU,GAAG,QAAQ,CAAC,UAAU,CAAC;QACtC,IAAI,CAAC,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC;QAC5B,IAAI,CAAC,aAAa,GAAG,QAAQ,CAAC,aAAa,IAAI,OAAO,CAAC;QACvD,IAAI,CAAC,aAAa,GAAG,QAAQ,CAAC,aAAa,IAAI,IAAI,CAAC;QACpD,IAAI,CAAC,WAAW,GAAG,QAAQ,CAAC,WAAW,IAAI,IAAI,CAAC;QAChD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAKD,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF;AApFD,8BAoFC"}
|
package/dist/shared/infrastructure/kafka/schema-registry/schema-registry-options.interface.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-registry-options.interface.js","sourceRoot":"","sources":["../../../../../src/shared/infrastructure/kafka/schema-registry/schema-registry-options.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SCHEMA_REGISTRY_OPTIONS = "SCHEMA_REGISTRY_OPTIONS";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-registry.constants.js","sourceRoot":"","sources":["../../../../../src/shared/infrastructure/kafka/schema-registry/schema-registry.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,uBAAuB,GAAG,yBAAyB,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { DynamicModule } from '@nestjs/common';
|
|
2
|
+
import { ISchemaRegistryAsyncOptions, ISchemaRegistryOptions } from './schema-registry-options.interface';
|
|
3
|
+
export declare class SchemaRegistryModule {
|
|
4
|
+
static forRoot(options: ISchemaRegistryOptions): DynamicModule;
|
|
5
|
+
static forRootAsync(options: ISchemaRegistryAsyncOptions): DynamicModule;
|
|
6
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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 SchemaRegistryModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.SchemaRegistryModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const axios_1 = require("@nestjs/axios");
|
|
13
|
+
const schema_registry_service_1 = require("./schema-registry.service");
|
|
14
|
+
const schema_registry_constants_1 = require("./schema-registry.constants");
|
|
15
|
+
let SchemaRegistryModule = SchemaRegistryModule_1 = class SchemaRegistryModule {
|
|
16
|
+
static forRoot(options) {
|
|
17
|
+
return {
|
|
18
|
+
module: SchemaRegistryModule_1,
|
|
19
|
+
imports: [axios_1.HttpModule],
|
|
20
|
+
providers: [
|
|
21
|
+
{ provide: schema_registry_constants_1.SCHEMA_REGISTRY_OPTIONS, useValue: options },
|
|
22
|
+
schema_registry_service_1.SchemaRegistryService,
|
|
23
|
+
],
|
|
24
|
+
exports: [schema_registry_service_1.SchemaRegistryService],
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
static forRootAsync(options) {
|
|
28
|
+
return {
|
|
29
|
+
module: SchemaRegistryModule_1,
|
|
30
|
+
imports: [axios_1.HttpModule, ...(options.imports ?? [])],
|
|
31
|
+
providers: [
|
|
32
|
+
{
|
|
33
|
+
provide: schema_registry_constants_1.SCHEMA_REGISTRY_OPTIONS,
|
|
34
|
+
inject: options.inject ?? [],
|
|
35
|
+
useFactory: options.useFactory,
|
|
36
|
+
},
|
|
37
|
+
schema_registry_service_1.SchemaRegistryService,
|
|
38
|
+
],
|
|
39
|
+
exports: [schema_registry_service_1.SchemaRegistryService],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
exports.SchemaRegistryModule = SchemaRegistryModule;
|
|
44
|
+
exports.SchemaRegistryModule = SchemaRegistryModule = SchemaRegistryModule_1 = __decorate([
|
|
45
|
+
(0, common_1.Module)({})
|
|
46
|
+
], SchemaRegistryModule);
|
|
47
|
+
//# sourceMappingURL=schema-registry.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-registry.module.js","sourceRoot":"","sources":["../../../../../src/shared/infrastructure/kafka/schema-registry/schema-registry.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuD;AACvD,yCAA2C;AAC3C,uEAAkE;AAClE,2EAAsE;AAO/D,IAAM,oBAAoB,4BAA1B,MAAM,oBAAoB;IAC/B,MAAM,CAAC,OAAO,CAAC,OAA+B;QAC5C,OAAO;YACL,MAAM,EAAE,sBAAoB;YAC5B,OAAO,EAAE,CAAC,kBAAU,CAAC;YACrB,SAAS,EAAE;gBACT,EAAE,OAAO,EAAE,mDAAuB,EAAE,QAAQ,EAAE,OAAO,EAAE;gBACvD,+CAAqB;aACtB;YACD,OAAO,EAAE,CAAC,+CAAqB,CAAC;SACjC,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,YAAY,CAAC,OAAoC;QACtD,OAAO;YACL,MAAM,EAAE,sBAAoB;YAC5B,OAAO,EAAE,CAAC,kBAAU,EAAE,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;YACjD,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,mDAAuB;oBAChC,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE;oBAC5B,UAAU,EAAE,OAAO,CAAC,UAAU;iBAC/B;gBACD,+CAAqB;aACtB;YACD,OAAO,EAAE,CAAC,+CAAqB,CAAC;SACjC,CAAC;IACJ,CAAC;CACF,CAAA;AA5BY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,oBAAoB,CA4BhC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { HttpService } from '@nestjs/axios';
|
|
2
|
+
import { OnModuleInit } from '@nestjs/common';
|
|
3
|
+
import { ISchemaRegistryOptions } from './schema-registry-options.interface';
|
|
4
|
+
export interface IAvroSchema {
|
|
5
|
+
type: string;
|
|
6
|
+
name: string;
|
|
7
|
+
namespace?: string;
|
|
8
|
+
fields: Array<{
|
|
9
|
+
name: string;
|
|
10
|
+
type: unknown;
|
|
11
|
+
default?: unknown;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
14
|
+
export declare class SchemaRegistryService implements OnModuleInit {
|
|
15
|
+
private readonly options;
|
|
16
|
+
private readonly httpService;
|
|
17
|
+
private readonly logger;
|
|
18
|
+
private registry;
|
|
19
|
+
constructor(options: ISchemaRegistryOptions, httpService: HttpService);
|
|
20
|
+
onModuleInit(): Promise<void>;
|
|
21
|
+
registerSchema(subject: string, schema: IAvroSchema): Promise<{
|
|
22
|
+
id: number;
|
|
23
|
+
}>;
|
|
24
|
+
encodeById(registryId: number, data: Record<string, unknown>): Promise<Buffer>;
|
|
25
|
+
encodeBySubject(subject: string, data: Record<string, unknown>): Promise<Buffer>;
|
|
26
|
+
decode<T = Record<string, unknown>>(buffer: Buffer): Promise<T>;
|
|
27
|
+
getLatestSchemaId(subject: string): Promise<number>;
|
|
28
|
+
getAllSubjects(): Promise<string[]>;
|
|
29
|
+
getVersions(subject: string): Promise<number[]>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var SchemaRegistryService_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.SchemaRegistryService = void 0;
|
|
17
|
+
const confluent_schema_registry_1 = require("@kafkajs/confluent-schema-registry");
|
|
18
|
+
const axios_1 = require("@nestjs/axios");
|
|
19
|
+
const common_1 = require("@nestjs/common");
|
|
20
|
+
const rxjs_1 = require("rxjs");
|
|
21
|
+
const schema_registry_constants_1 = require("./schema-registry.constants");
|
|
22
|
+
let SchemaRegistryService = SchemaRegistryService_1 = class SchemaRegistryService {
|
|
23
|
+
constructor(options, httpService) {
|
|
24
|
+
this.options = options;
|
|
25
|
+
this.httpService = httpService;
|
|
26
|
+
this.logger = new common_1.Logger(SchemaRegistryService_1.name);
|
|
27
|
+
this.registry = new confluent_schema_registry_1.SchemaRegistry({ host: options.host });
|
|
28
|
+
}
|
|
29
|
+
async onModuleInit() {
|
|
30
|
+
this.logger.log(`Schema Registry connected: ${this.options.host}`);
|
|
31
|
+
}
|
|
32
|
+
async registerSchema(subject, schema) {
|
|
33
|
+
try {
|
|
34
|
+
const { id } = await this.registry.register({ type: confluent_schema_registry_1.SchemaType.AVRO, schema: JSON.stringify(schema) }, { subject });
|
|
35
|
+
this.logger.log(`Schema registered: subject="${subject}" id=${id}`);
|
|
36
|
+
return { id };
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
this.logger.error(`Failed to register schema for subject "${subject}"`, error);
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async encodeById(registryId, data) {
|
|
44
|
+
try {
|
|
45
|
+
return await this.registry.encode(registryId, data);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
this.logger.error(`Failed to encode data with schema ID ${registryId}`, error);
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async encodeBySubject(subject, data) {
|
|
53
|
+
try {
|
|
54
|
+
const id = await this.registry.getLatestSchemaId(subject);
|
|
55
|
+
return await this.registry.encode(id, data);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
this.logger.error(`Failed to encode data for subject "${subject}"`, error);
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async decode(buffer) {
|
|
63
|
+
try {
|
|
64
|
+
return (await this.registry.decode(buffer));
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
this.logger.error('Failed to decode Avro message', error);
|
|
68
|
+
throw error;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async getLatestSchemaId(subject) {
|
|
72
|
+
return this.registry.getLatestSchemaId(subject);
|
|
73
|
+
}
|
|
74
|
+
async getAllSubjects() {
|
|
75
|
+
const { data } = await (0, rxjs_1.firstValueFrom)(this.httpService.get(`${this.options.host}/subjects`));
|
|
76
|
+
return data;
|
|
77
|
+
}
|
|
78
|
+
async getVersions(subject) {
|
|
79
|
+
const { data } = await (0, rxjs_1.firstValueFrom)(this.httpService.get(`${this.options.host}/subjects/${encodeURIComponent(subject)}/versions`));
|
|
80
|
+
return data;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
exports.SchemaRegistryService = SchemaRegistryService;
|
|
84
|
+
exports.SchemaRegistryService = SchemaRegistryService = SchemaRegistryService_1 = __decorate([
|
|
85
|
+
(0, common_1.Injectable)(),
|
|
86
|
+
__param(0, (0, common_1.Inject)(schema_registry_constants_1.SCHEMA_REGISTRY_OPTIONS)),
|
|
87
|
+
__metadata("design:paramtypes", [Object, axios_1.HttpService])
|
|
88
|
+
], SchemaRegistryService);
|
|
89
|
+
//# sourceMappingURL=schema-registry.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-registry.service.js","sourceRoot":"","sources":["../../../../../src/shared/infrastructure/kafka/schema-registry/schema-registry.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kFAAgF;AAChF,yCAA4C;AAC5C,2CAA0E;AAC1E,+BAAsC;AAEtC,2EAAsE;AAU/D,IAAM,qBAAqB,6BAA3B,MAAM,qBAAqB;IAIhC,YAEE,OAAgD,EAC/B,WAAwB;QADxB,YAAO,GAAP,OAAO,CAAwB;QAC/B,gBAAW,GAAX,WAAW,CAAa;QAN1B,WAAM,GAAG,IAAI,eAAM,CAAC,uBAAqB,CAAC,IAAI,CAAC,CAAC;QAQ/D,IAAI,CAAC,QAAQ,GAAG,IAAI,0CAAc,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,KAAK,CAAC,YAAY;QAChB,IAAI,CAAC,MAAM,CA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