Skip to content

Commit

Permalink
Merge fix-781-multer-options
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Mar 30, 2020
2 parents a75121c + ab72c27 commit 32a1e54
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {Env} from "@tsed/core";
import {$log} from "@tsed/logger";
import {expect} from "chai";
import * as Sinon from "sinon";
import {$log} from "@tsed/logger";
import {ProviderScope, ProviderType} from "../../../../di/src/interfaces";
import {ServerSettingsService} from "../../../src/config/services/ServerSettingsService";

Expand Down Expand Up @@ -197,6 +197,23 @@ describe("ServerSettingsService", () => {
expect(settings.resolve("${rootDir}")).to.eq(process.cwd());
});

it("should preserve class", () => {
class Storage {
static _path = "${rootDir}";
}

const store = new Storage();
const result = settings.resolve({
path: "${rootDir}",
storage: store
});

expect(result).to.deep.eq({
path: process.cwd(),
storage: new Storage()
});
});

it("should replace rootDir", () => {
expect(settings.resolve({other: null, resolve: "${rootDir}"})).to.deep.eq({
other: null,
Expand Down
10 changes: 8 additions & 2 deletions packages/di/src/services/DIConfiguration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {deepExtends, getValue, setValue} from "@tsed/core";
import {classOf, deepExtends, getValue, setValue} from "@tsed/core";
import {IDIConfigurationOptions} from "../interfaces/IDIConfigurationOptions";
import {ProviderScope} from "../interfaces/ProviderScope";

Expand Down Expand Up @@ -89,7 +89,9 @@ export class DIConfiguration {
if (typeof propertyKey === "string") {
this.setRaw(propertyKey, value);
} else {
Object.assign(this, propertyKey);
Object.entries(propertyKey).forEach(([key, value]) => {
this[key] = value;
});
}

return this;
Expand Down Expand Up @@ -139,6 +141,10 @@ export class DIConfiguration {
*/
resolve(value: any) {
if (typeof value === "object" && value !== null) {
if (![Array, Object].includes(classOf(value))) {
return value;
}

return Object.entries(value).reduce(
(o, [k, v]) => {
// @ts-ignore
Expand Down

0 comments on commit 32a1e54

Please sign in to comment.