diff --git a/src/modules/config/controllers/config-grpc.controller.ts b/src/modules/config/controllers/config-grpc.controller.ts index c4968af..2926c8a 100644 --- a/src/modules/config/controllers/config-grpc.controller.ts +++ b/src/modules/config/controllers/config-grpc.controller.ts @@ -2,9 +2,9 @@ import { Controller, UseInterceptors } from '@nestjs/common'; import type { ConfigController, EmptyRequest, getConfigResponse } from '../../../../src/modules/grpc/gen/ts/kraken'; import { ConfigControllerMethods } from '../../../../src/modules/grpc/gen/ts/kraken'; +import { GrpcInvalidArgumentException, GrpcToHttpInterceptor } from 'nestjs-grpc-exceptions'; import { ConfigService } from '../config.service'; import { Metadata } from '@grpc/grpc-js'; -import { GrpcInvalidArgumentException, GrpcToHttpInterceptor } from 'nestjs-grpc-exceptions'; @Controller() @ConfigControllerMethods() @@ -17,8 +17,26 @@ export class ConfigGrpcController implements ConfigController { if (!token) { throw new GrpcInvalidArgumentException("input 'x-identifier' is not valid."); } - const config = await this.configService.getNip11(); + const { url, limitations } = await this.configService.getNip11(); - return config?.toDto() as getConfigResponse; + return { + url, + limitations: { + maxMessageLength: limitations?.max_message_length, + maxSubscriptions: limitations?.max_subscriptions, + maxFilters: limitations?.max_filters, + maxSubidLength: limitations?.max_subid_length, + minPowDifficulty: limitations?.min_pow_difficulty, + authRequired: limitations?.auth_required, + paymentRequired: limitations?.payment_required, + restrictedWrites: limitations?.restricted_writes, + maxEventTags: limitations?.max_event_tags, + maxContentLength: limitations?.max_content_length, + createdAtLowerLimit: limitations?.created_at_lower_limit, + createdAtUpperLimit: limitations?.created_at_upper_limit, + defaultQueryLimit: limitations?.default_query_limit, + maxQueryLimit: limitations?.max_limit, + }, + } as getConfigResponse; } } diff --git a/src/modules/config/dto/nip11.dto.ts b/src/modules/config/dto/nip11.dto.ts index 50f9696..d605a4c 100644 --- a/src/modules/config/dto/nip11.dto.ts +++ b/src/modules/config/dto/nip11.dto.ts @@ -9,47 +9,47 @@ import { FeesDto } from './fees.dto'; export class Nip11DTO extends AbstractDto { @ApiProperty() @IsString() - name: string; + name?: string; @ApiProperty() @IsString() - description: string; + description?: string; @ApiProperty() @IsString() - banner: string; + banner?: string; @ApiProperty() @IsString() - pubkey: string; + pubkey?: string; @ApiProperty() @IsString() - contact: string; + contact?: string; @ApiProperty() @IsString() - software: string; + software?: string; @ApiProperty({ type: [Number] }) @IsArray() - supported_nips: number[]; + supported_nips?: number[]; @ApiProperty() @IsString() - version: string; + version?: string; @ApiProperty({ type: [String] }) @IsArray() - relay_countries: string[]; + relay_countries?: string[]; @ApiProperty({ type: [String] }) @IsArray() - language_tags: string[]; + language_tags?: string[]; @ApiProperty({ type: [String] }) @IsArray() - tags: string[]; + tags?: string[]; @ApiProperty({ required: false }) @IsOptional() @@ -71,9 +71,9 @@ export class Nip11DTO extends AbstractDto { @IsString() url?: string; - @ApiProperty({ type: () => RetentionDto, required: false }) + @ApiProperty({ type: () => [RetentionDto], required: false }) @IsOptional() - retention?: RetentionDto; + retention?: RetentionDto[]; @ApiProperty({ type: () => FeesDto, required: false }) @IsOptional() @@ -105,33 +105,30 @@ export class Nip11DTO extends AbstractDto { this.url = e.url ?? undefined; // Handle Retention - this.retention = e.retention && (e.retention.count || e.retention.kinds || e.retention.time) - ? { - count: e.retention.count ?? undefined, - kinds: e.retention.kinds ?? undefined, - time: e.retention.time ?? undefined, - } - : undefined; + if (e.retention) { + this.retention = e.retention ?? undefined + } // Handle Fees - this.fees = e.fees && (e.fees.admission || e.fees.publication || e.fees.subscription) - ? { - admission: e.fees.admission?.map(a => ({ - amount: a.amount ?? undefined, - unit: a.unit ?? undefined, - })), - publication: e.fees.publication?.map(p => ({ - amount: p.amount ?? undefined, - kinds: p.kinds ?? undefined, - unit: p.unit ?? undefined, - })), - subscription: e.fees.subscription?.map(s => ({ - amount: s.amount ?? undefined, - period: s.period ?? undefined, - unit: s.unit ?? undefined, - })), - } - : undefined; + this.fees = + e.fees && (e.fees.admission ?? e.fees.publication ?? e.fees.subscription) + ? { + admission: e.fees.admission?.map((a) => ({ + amount: a.amount, + unit: a.unit, + })), + publication: e.fees.publication?.map((p) => ({ + amount: p.amount, + kinds: p.kinds, + unit: p.unit, + })), + subscription: e.fees.subscription?.map((s) => ({ + amount: s.amount, + period: s.period, + unit: s.unit, + })), + } + : undefined; // Handle Limitations this.limitations = e.limitations diff --git a/src/modules/config/dto/retention.dto.ts b/src/modules/config/dto/retention.dto.ts index 0278ca4..479f77a 100644 --- a/src/modules/config/dto/retention.dto.ts +++ b/src/modules/config/dto/retention.dto.ts @@ -2,11 +2,11 @@ import { NumberFieldOptional } from '../../../../src/decorators'; export class RetentionDto { @NumberFieldOptional() - time?: number; + time: number | null; @NumberFieldOptional() - count?: number; + count: number | null; @NumberFieldOptional({ isArray: true, each: true }) - kinds?: number[]; + kinds: number[][] | null; } diff --git a/src/modules/config/entities/fees.entity.ts b/src/modules/config/entities/fees.entity.ts index a64cd51..0b7bd7d 100644 --- a/src/modules/config/entities/fees.entity.ts +++ b/src/modules/config/entities/fees.entity.ts @@ -32,11 +32,11 @@ export class AdmissionEntity { export class FeesEntity { @Column({ nullable: true }) - subscription?: SubscriptionEntity[]; + subscription?: SubscriptionEntity[] | null; @Column({ nullable: true }) - publication?: PublicationEntity[]; + publication?: PublicationEntity[] | null; @Column({ nullable: true }) - admission?: AdmissionEntity[]; + admission?: AdmissionEntity[] | null; } diff --git a/src/modules/config/entities/limitaion.entity.ts b/src/modules/config/entities/limitaion.entity.ts index b504566..cf83448 100644 --- a/src/modules/config/entities/limitaion.entity.ts +++ b/src/modules/config/entities/limitaion.entity.ts @@ -1,45 +1,45 @@ import { Column } from 'typeorm'; export class LimitationEntity { - @Column({ type: 'int' }) - max_message_length?: number; + @Column() + max_message_length?: number | null; - @Column({ type: 'int' }) - max_subscriptions?: number; + @Column() + max_subscriptions?: number | null; - @Column({ type: 'int' }) - max_filters?: number; + @Column() + max_filters?: number | null; - @Column({ type: 'int' }) - max_subid_length?: number; + @Column() + max_subid_length?: number | null; - @Column({ type: 'int' }) - min_pow_difficulty?: number; + @Column() + min_pow_difficulty?: number | null; - @Column({ type: 'boolean' }) - auth_required?: boolean; + @Column() + auth_required?: boolean | null; - @Column({ type: 'boolean' }) - payment_required?: boolean; + @Column() + payment_required?: boolean | null; - @Column({ type: 'boolean' }) - restricted_writes?: boolean; + @Column() + restricted_writes?: boolean | null; - @Column({ type: 'int' }) - max_event_tags?: number; + @Column() + max_event_tags?: number | null; - @Column({ type: 'int' }) - max_content_length?: number; + @Column() + max_content_length?: number | null; - @Column({ type: 'bigint' }) - created_at_lower_limit?: number; + @Column() + created_at_lower_limit?: number | null; - @Column({ type: 'bigint' }) - created_at_upper_limit?: number; + @Column() + created_at_upper_limit?: number | null; - @Column({ type: 'int' }) - max_limit?: number; + @Column() + max_limit?: number | null; - @Column({ type: 'int' }) - default_query_limit?: number; + @Column() + default_query_limit?: number | null; } diff --git a/src/modules/config/entities/nip11.entity.ts b/src/modules/config/entities/nip11.entity.ts index 602e301..72292d3 100644 --- a/src/modules/config/entities/nip11.entity.ts +++ b/src/modules/config/entities/nip11.entity.ts @@ -10,59 +10,59 @@ import { LimitationEntity } from './limitaion.entity'; export class Nip11Entity extends AbstractEntity { dtoClass = Nip11DTO; - @Column({ type: 'varchar' }) - name: string; + @Column() + name: string | null; - @Column({ type: 'varchar' }) - description: string; + @Column() + description: string | null; - @Column({ type: 'varchar' }) - pubkey: string; + @Column() + pubkey: string | null; - @Column({ type: 'varchar' }) - banner: string; + @Column() + banner: string | null; - @Column({ type: 'varchar' }) - contact: string; + @Column() + contact: string | null; - @Column({ type: 'varchar' }) - software: string; + @Column() + software: string | null; - @Column('simple-array') - supported_nips: number[]; + @Column() + supported_nips: number[] | null; - @Column({ type: 'varchar' }) - version: string; + @Column() + version: string | null; - @Column('simple-array') - relay_countries: string[]; + @Column() + relay_countries: string[] | null; - @Column('simple-array') - language_tags: string[]; + @Column() + language_tags: string[] | null; - @Column('simple-array') - tags: string[]; + @Column() + tags: string[] | null; - @Column({ type: 'varchar', nullable: true }) - posting_policy: string; + @Column() + posting_policy: string | null; - @Column({ type: 'varchar', nullable: true }) - payments_url: string; + @Column() + payments_url: string | null; - @Column({ type: 'varchar', nullable: true }) - icon: string; + @Column() + icon: string | null; - @Column({ type: 'varchar', nullable: true }) - url: string; + @Column() + url: string | null; - @Column({ type: 'json', nullable: true }) - retention?: RetentionEntity; + @Column() + retention?: RetentionEntity[] | null; - @Column({ type: 'json', nullable: true }) - fees?: FeesEntity; + @Column() + fees?: FeesEntity | null; - @Column({ type: 'json', nullable: true }) - limitations?: LimitationEntity; + @Column() + limitations?: LimitationEntity | null; constructor(item?: Partial>) { super(); @@ -80,6 +80,7 @@ export class Nip11Entity extends AbstractEntity { this.name = item.name ?? this.name; this.description = item.description ?? this.description; + this.pubkey = item.pubkey ?? this.pubkey; this.banner = item.banner ?? this.banner; this.contact = item.contact ?? this.contact; @@ -95,35 +96,29 @@ export class Nip11Entity extends AbstractEntity { this.url = item.url ?? this.url; // Handle Retention - this.retention = { - time: item.retention?.time ?? this.retention?.time, - count: item.retention?.count ?? this.retention?.count, - kinds: item.retention?.kinds ?? this.retention?.kinds, - }; + this.retention = item.retention ?? this.retention ?? null; // Handle Fees - this.fees = { - subscription: item.fees?.subscription ?? this.fees?.subscription, - publication: item.fees?.publication ?? this.fees?.publication, - admission: item.fees?.admission ?? this.fees?.admission, - }; + this.fees = item.fees ?? this.fees ?? null; // Handle Limitations this.limitations = { - max_message_length: item.limitations?.max_message_length ?? this.limitations?.max_message_length, - max_subscriptions: item.limitations?.max_subscriptions ?? this.limitations?.max_subscriptions, - max_filters: item.limitations?.max_filters ?? this.limitations?.max_filters, - max_subid_length: item.limitations?.max_subid_length ?? this.limitations?.max_subid_length, - min_pow_difficulty: item.limitations?.min_pow_difficulty ?? this.limitations?.min_pow_difficulty, - auth_required: item.limitations?.auth_required ?? this.limitations?.auth_required, - payment_required: item.limitations?.payment_required ?? this.limitations?.payment_required, - restricted_writes: item.limitations?.restricted_writes ?? this.limitations?.restricted_writes, - max_event_tags: item.limitations?.max_event_tags ?? this.limitations?.max_event_tags, - max_content_length: item.limitations?.max_content_length ?? this.limitations?.max_content_length, - created_at_lower_limit: item.limitations?.created_at_lower_limit ?? this.limitations?.created_at_lower_limit, - created_at_upper_limit: item.limitations?.created_at_upper_limit ?? this.limitations?.created_at_upper_limit, - max_limit: item.limitations?.max_limit ?? this.limitations?.max_limit, - default_query_limit: item.limitations?.default_query_limit ?? this.limitations?.default_query_limit, + max_message_length: item.limitations?.max_message_length ?? this.limitations?.max_message_length ?? null, + max_subscriptions: item.limitations?.max_subscriptions ?? this.limitations?.max_subscriptions ?? null, + max_filters: item.limitations?.max_filters ?? this.limitations?.max_filters ?? null, + max_subid_length: item.limitations?.max_subid_length ?? this.limitations?.max_subid_length ?? null, + min_pow_difficulty: item.limitations?.min_pow_difficulty ?? this.limitations?.min_pow_difficulty ?? null, + auth_required: item.limitations?.auth_required ?? this.limitations?.auth_required ?? null, + payment_required: item.limitations?.payment_required ?? this.limitations?.payment_required ?? null, + restricted_writes: item.limitations?.restricted_writes ?? this.limitations?.restricted_writes ?? null, + max_event_tags: item.limitations?.max_event_tags ?? this.limitations?.max_event_tags ?? null, + max_content_length: item.limitations?.max_content_length ?? this.limitations?.max_content_length ?? null, + created_at_lower_limit: + item.limitations?.created_at_lower_limit ?? this.limitations?.created_at_lower_limit ?? null, + created_at_upper_limit: + item.limitations?.created_at_upper_limit ?? this.limitations?.created_at_upper_limit ?? null, + max_limit: item.limitations?.max_limit ?? this.limitations?.max_limit ?? null, + default_query_limit: item.limitations?.default_query_limit ?? this.limitations?.default_query_limit ?? null, }; } } diff --git a/src/modules/config/entities/retention.entity.ts b/src/modules/config/entities/retention.entity.ts index bd3572e..9fa0cb2 100644 --- a/src/modules/config/entities/retention.entity.ts +++ b/src/modules/config/entities/retention.entity.ts @@ -1,12 +1,12 @@ import { Column } from 'typeorm'; export class RetentionEntity { - @Column({ nullable: true }) - time?: number; + @Column() + time: number | null; - @Column({ nullable: true }) - count?: number; + @Column() + count: number | null; - @Column({ nullable: true }) - kinds?: number[]; + @Column() + kinds: number[][] | null; }