Skip to content

Commit

Permalink
chore(npm): update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jlenon7 committed Feb 9, 2024
1 parent 3ef32b3 commit c5b1c2a
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 185 deletions.
362 changes: 220 additions & 142 deletions package-lock.json

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/config",
"version": "4.13.0",
"version": "4.14.0",
"description": "Cache and handle environment variables and config files of Athenna.",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand Down Expand Up @@ -58,8 +58,8 @@
"syntax-error": "^1.4.0"
},
"devDependencies": {
"@athenna/common": "^4.27.0",
"@athenna/test": "^4.18.0",
"@athenna/common": "^4.32.0",
"@athenna/test": "^4.21.0",
"@athenna/tsconfig": "^4.12.0",
"@types/lodash": "^4.14.191",
"@types/syntax-error": "^1.4.2",
Expand Down
19 changes: 3 additions & 16 deletions src/annotations/Value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,13 @@

import 'reflect-metadata'

import { Is } from '@athenna/common'
import { NotFoundConfigException } from '#src/exceptions/NotFoundConfigException'

/**
* Set the value of some configuration in your class property.
*/
export function Value(key: string, defaultValue?: any): PropertyDecorator {
return (target: any, propKey: string | symbol) => {
if (Is.Defined(defaultValue) || defaultValue === null) {
Object.defineProperty(target, propKey, {
value: Config.get(key, defaultValue)
})

return
}

if (!Config.exists(key)) {
throw new NotFoundConfigException(key)
}

Object.defineProperty(target, propKey, { value: Config.get(key) })
Object.defineProperty(target, propKey, {
value: Config.get(key, defaultValue)
})
}
}
9 changes: 0 additions & 9 deletions tests/fixtures/classes/DoesNotThrowNotFound.ts

This file was deleted.

9 changes: 9 additions & 0 deletions tests/fixtures/classes/NotFoundConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Value } from '#src/annotations/Value'

export class NotFoundConfig {
@Value('app.notFound', 'Athenna')
public defined: any

@Value('app.notFound')
public undefined: any
}
6 changes: 0 additions & 6 deletions tests/fixtures/classes/ThrowNotFound.ts

This file was deleted.

18 changes: 10 additions & 8 deletions tests/unit/annotations/ValueAnnotationTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import { Path } from '@athenna/common'
import { Test, BeforeEach, AfterEach, type Context } from '@athenna/test'
import { NotFoundConfigException } from '#src/exceptions/NotFoundConfigException'

export default class ValueAnnotationTest {
@BeforeEach()
Expand All @@ -33,18 +32,21 @@ export default class ValueAnnotationTest {
}

@Test()
public async shouldThrowAnExceptionIfTryingToLoadAConfigurationValueThatDoesNotExist({ assert }: Context) {
await assert.rejects(() => import('#tests/fixtures/classes/ThrowNotFound'), NotFoundConfigException)
public async shouldSetAsUndefinedIfTryingToLoadAConfigurationValueThatDoesNotExist({ assert }: Context) {
const { NotFoundConfig } = await import('#tests/fixtures/classes/NotFoundConfig')

const notFoundConfig = new NotFoundConfig()

assert.equal(notFoundConfig.undefined, undefined)
}

@Test()
public async shouldNotThrowExceptionIfDefaultValueIsSetWhenTryingToLoadAUndefinedConfiguration({ assert }: Context) {
const { DoesNotThrowNotFound } = await import('#tests/fixtures/classes/DoesNotThrowNotFound')
public async shouldTheDefaultValueIfTryingToLoadAConfigurationValueThatDoesNotExist({ assert }: Context) {
const { NotFoundConfig } = await import('#tests/fixtures/classes/NotFoundConfig')

const doesNotThrowNotFound = new DoesNotThrowNotFound()
const notFoundConfig = new NotFoundConfig()

assert.equal(doesNotThrowNotFound.defined, null)
assert.equal(doesNotThrowNotFound.definedApp, 'Athenna')
assert.equal(notFoundConfig.defined, 'Athenna')
}

@Test()
Expand Down
7 changes: 6 additions & 1 deletion tests/unit/config/ConfigTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
*/

import { sep } from 'node:path'
import { File, Folder, Path } from '@athenna/common'
import { File, Json, Folder, Path } from '@athenna/common'
import { Test, Cleanup, BeforeEach, AfterEach, type Context } from '@athenna/test'
import { RecursiveConfigException } from '#src/exceptions/RecursiveConfigException'
import { NotSupportedKeyException } from '#src/exceptions/NotSupportedKeyException'
import { NotValidArrayConfigException } from '#src/exceptions/NotValidArrayConfigException'

export default class ConfigTest {
public env: any = Json.copy(process.env)
public argv: string[] = Json.copy(process.argv)

@BeforeEach()
public async beforeEach() {
await Config.load(Path.fixtures('config/app.ts'))
Expand All @@ -24,6 +27,8 @@ export default class ConfigTest {
@AfterEach()
public async afterEach() {
Config.clear()
process.env = this.env
process.argv = this.argv
await Folder.safeRemove(Path.fixtures('recursive-copy'))
}

Expand Down

0 comments on commit c5b1c2a

Please sign in to comment.