Skip to content

Commit

Permalink
feat(config): better configuration class
Browse files Browse the repository at this point in the history
  • Loading branch information
NedcloarBR committed Sep 17, 2024
1 parent c2889d2 commit b245d7e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 45 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"postinstall": "prisma generate && husky || true"
},
"dependencies": {
"@necord/localization": "^3.1.3",
"@necord/pagination": "^1.3.1",
"@necord/localization": "^4.0.0",
"@necord/pagination": "^2.0.0",
"@nestjs/common": "^10.4.1",
"@nestjs/config": "^3.2.3",
"@nestjs/core": "^10.4.1",
Expand Down
30 changes: 29 additions & 1 deletion src/modules/config/NecordConfig.service.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import {
GuildResolver,
NecordLocalizationOptions,
NestedLocalizationAdapter,
} from "@necord/localization";
import { NecordPaginationOptions } from "@necord/pagination";
import { Injectable } from "@nestjs/common";
import type { ConfigService } from "@nestjs/config";
import { ConfigService } from "@nestjs/config";
import {
GatewayIntentBits,
GatewayVersion,
Options,
Partials,
} from "discord.js";
import type { NecordModuleOptions } from "necord";
import { JSONLocaleLoader } from "./JSONLocale.loader";
import type { Config } from "./types";

@Injectable()
Expand Down Expand Up @@ -79,4 +86,25 @@ export class NecordConfigService {
],
};
}

public createNecordPaginationOptions(): NecordPaginationOptions {
return {
allowSkip: false,
allowTraversal: false,
buttonsPosition: "end",
};
}

public async createNecordLocalizationOptions(): Promise<NecordLocalizationOptions> {
return {
adapter: new NestedLocalizationAdapter({
fallbackLocale:
this.config.getOrThrow<Config["FallbackLocale"]>("FallbackLocale"),
locales: await new JSONLocaleLoader(
"./src/common/Languages/",
).loadTranslations(),
}),
resolvers: GuildResolver,
};
}
}
30 changes: 6 additions & 24 deletions src/modules/core/NDB.module.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,24 @@
import * as Modules from "@/modules";
import {
GuildResolver,
NecordLocalizationModule,
NestedLocalizationAdapter,
} from "@necord/localization";
import { NecordLocalizationModule } from "@necord/localization";
import { NecordPaginationModule } from "@necord/pagination";
import { Module } from "@nestjs/common";
import { ConfigModule, ConfigService } from "@nestjs/config";
import { NecordModule } from "necord";
import { JSONLocaleLoader, NecordConfigService, config } from "../config";
import type { Config } from "../config/types";
import { NecordConfigService, config } from "../config";
import { NDBServiceProvider } from "./provider/NDBService.provider";

@Module({
imports: [
NecordModule.forRootAsync({
inject: [ConfigService],
useFactory: async (config: ConfigService) => ({
...new NecordConfigService(config).createNecordOptions(),
}),
useClass: NecordConfigService,
}),
NecordPaginationModule.forRoot({
allowSkip: false,
allowTraversal: false,
buttonsPosition: "end",
NecordPaginationModule.forRootAsync({
useClass: NecordConfigService,
}),
NecordLocalizationModule.forRootAsync({
inject: [ConfigService],
useFactory: async (config: ConfigService) => ({
adapter: new NestedLocalizationAdapter({
fallbackLocale:
config.getOrThrow<Config["FallbackLocale"]>("FallbackLocale"),
locales: await new JSONLocaleLoader(
"./src/common/Languages/",
).loadTranslations(),
}),
resolvers: GuildResolver,
}),
useClass: NecordConfigService,
}),
ConfigModule.forRoot({
isGlobal: true,
Expand Down
36 changes: 18 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -990,31 +990,31 @@ __metadata:
languageName: node
linkType: hard

"@necord/localization@npm:^3.1.3":
version: 3.1.3
resolution: "@necord/localization@npm:3.1.3"
"@necord/localization@npm:^4.0.0":
version: 4.0.0
resolution: "@necord/localization@npm:4.0.0"
peerDependencies:
"@nestjs/common": ^8.0.0 || ^9.0.0 || ^10.0.0
"@nestjs/core": ^8.0.0 || ^9.0.0 || ^10.0.0
discord.js: ^14.0.0
"@nestjs/common": ^10.2.0
"@nestjs/core": ^10.2.0
discord.js: ^14.0.1
necord: ^6.0.0
reflect-metadata: ^0.1.13
reflect-metadata: ^0.2.1
rxjs: ^7.2.0
checksum: 10c0/143399a3c9724014589090b01678b608abcf9356f1174d46935c1f9af6842b6c140fa3135bc71ec42f1872a3610df058c62e2983c3d11781e0ea2dcb35798a27
checksum: 10c0/82cf04ef21859a6343c9f88108bb95e1295fd893e4b3e901450c2043d99afd8afe5a63ff6a9601f756efe0e496858619286f30c8ea8194b9aca6dbf1a12c2b32
languageName: node
linkType: hard

"@necord/pagination@npm:^1.3.1":
version: 1.3.1
resolution: "@necord/pagination@npm:1.3.1"
"@necord/pagination@npm:^2.0.0":
version: 2.0.0
resolution: "@necord/pagination@npm:2.0.0"
peerDependencies:
"@nestjs/common": ^8.0.0 || ^9.0.0 || ^10.0.0
"@nestjs/core": ^8.0.0 || ^9.0.0 || ^10.0.0
discord.js: ^14.0.0
"@nestjs/common": ^10.2.0
"@nestjs/core": ^10.2.0
discord.js: ^14.0.1
necord: ^6.0.0
reflect-metadata: ^0.1.13
reflect-metadata: ^0.2.1
rxjs: ^7.2.0
checksum: 10c0/a8eba81f6383df3bd33133403544de70ad9e2c4eb609e018a283b78839a2ad89250ac7b19f4c2a9809fa0b35efeef64d5d30ec29119358960f8eea17940bc9ff
checksum: 10c0/3156703cb6f944ff1256916df93818d51d2746ba176ed5e717a4907ea05c9aadbc7d83dd21ad5a1a0f8371da37fad43f2b2868f886a08200181da15c13f4909d
languageName: node
linkType: hard

Expand Down Expand Up @@ -6374,8 +6374,8 @@ __metadata:
"@commitlint/cli": "npm:^19.4.1"
"@commitlint/config-angular": "npm:^19.4.1"
"@commitlint/config-conventional": "npm:^19.4.1"
"@necord/localization": "npm:^3.1.3"
"@necord/pagination": "npm:^1.3.1"
"@necord/localization": "npm:^4.0.0"
"@necord/pagination": "npm:^2.0.0"
"@nedcloarbr/biome-config": "npm:^1.4.0"
"@nestjs/cli": "npm:^10.4.5"
"@nestjs/common": "npm:^10.4.1"
Expand Down

0 comments on commit b245d7e

Please sign in to comment.