-
-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(oidc-provider): use functional DI Api to inject services
- Loading branch information
Showing
11 changed files
with
127 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import {DITest} from "../../node/index.js"; | ||
import {refValue} from "./refValue.js"; | ||
|
||
describe("refValue()", () => { | ||
beforeEach(() => | ||
DITest.create({ | ||
logger: { | ||
level: "off" | ||
} | ||
}) | ||
); | ||
afterEach(() => DITest.reset()); | ||
describe("when decorator is used as property decorator", () => { | ||
it("should create a getter", async () => { | ||
// WHEN | ||
class Test { | ||
test = refValue("logger.level", "default value"); | ||
} | ||
|
||
// THEN | ||
|
||
const test = await DITest.invoke<Test>(Test); | ||
|
||
expect(test.test.value).toEqual("off"); | ||
}); | ||
it("should create a getter with default value", async () => { | ||
expect(DITest.injector.settings.get("logger.test")).toEqual(undefined); | ||
|
||
// WHEN | ||
class Test { | ||
test = refValue("logger.test", "default value"); | ||
} | ||
|
||
// THEN | ||
|
||
const test = await DITest.invoke<Test>(Test); | ||
|
||
expect(test.test.value).toEqual("default value"); | ||
expect(DITest.injector.settings.get("logger.test")).toEqual(undefined); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {injector} from "./injector.js"; | ||
|
||
/** | ||
* Get a value from the `injector.settings`. | ||
* | ||
* ## Example | ||
* | ||
* ```ts | ||
* import {refValue, Injectable} from "@tsed/di"; | ||
* | ||
* @Injectable() | ||
* class Test { | ||
* test = refValue("logger.level", "default value"); | ||
* | ||
* constructor() { | ||
* console.log(this.test.value); // "off" | ||
* } | ||
* } | ||
* | ||
* @param expression The expression to get the value from the `injector.settings`. | ||
*/ | ||
export function refValue<Type>(expression: string): {value: Type | undefined}; | ||
export function refValue<Type>(expression: string, defaultValue: Type | undefined): {value: Type}; | ||
export function refValue<Type>(expression: string, defaultValue?: Type | undefined): {value: Type | undefined} { | ||
return Object.freeze({ | ||
get value() { | ||
return injector().settings.get(expression, defaultValue); | ||
}, | ||
set value(value: Type) { | ||
injector().settings.set(expression, value); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 5 additions & 12 deletions
17
packages/security/oidc-provider/src/services/OidcInteractions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters