Skip to content

Commit

Permalink
fix: nip 11 update
Browse files Browse the repository at this point in the history
  • Loading branch information
ZigBalthazar committed Dec 23, 2024
1 parent 75ea184 commit 9a8533b
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 141 deletions.
24 changes: 21 additions & 3 deletions src/modules/config/controllers/config-grpc.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Check failure on line 7 in src/modules/config/controllers/config-grpc.controller.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/controllers/config-grpc.controller.ts#L7

All imports in the declaration are only used as types. Use `import type` (@typescript-eslint/consistent-type-imports)
import { GrpcInvalidArgumentException, GrpcToHttpInterceptor } from 'nestjs-grpc-exceptions';

@Controller()
@ConfigControllerMethods()
Expand All @@ -17,8 +17,26 @@ export class ConfigGrpcController implements ConfigController {
if (!token) {

Check failure on line 17 in src/modules/config/controllers/config-grpc.controller.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/controllers/config-grpc.controller.ts#L17

Expected blank line before this statement (padding-line-between-statements)
throw new GrpcInvalidArgumentException("input 'x-identifier' is not valid.");
}
const config = await this.configService.getNip11();
const { url, limitations } = await this.configService.getNip11();

Check failure on line 20 in src/modules/config/controllers/config-grpc.controller.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/controllers/config-grpc.controller.ts#L20

Expected blank line before this statement (padding-line-between-statements)

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;
}
}
73 changes: 35 additions & 38 deletions src/modules/config/dto/nip11.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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

Check failure on line 109 in src/modules/config/dto/nip11.dto.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/dto/nip11.dto.ts#L109

Insert `;` (prettier/prettier)

Check failure on line 109 in src/modules/config/dto/nip11.dto.ts

View workflow job for this annotation

GitHub Actions / ESLint

src/modules/config/dto/nip11.dto.ts#L109

Missing semicolon (@typescript-eslint/semi)
}

// 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
Expand Down
6 changes: 3 additions & 3 deletions src/modules/config/dto/retention.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
6 changes: 3 additions & 3 deletions src/modules/config/entities/fees.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
56 changes: 28 additions & 28 deletions src/modules/config/entities/limitaion.entity.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Loading

0 comments on commit 9a8533b

Please sign in to comment.