Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clean code #2861

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
"browser": "./lib/browser/core.umd.min.js",
"import": "./lib/esm/index.js",
"default": "./lib/esm/index.js"
},
"./**/*.js": {
"types": "./lib/types/**/*.d.ts",
"import": "./lib/esm/**/*.js",
"default": "./lib/esm/**/*.js"
}
},
"scripts": {
Expand Down
11 changes: 1 addition & 10 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
/**
* @file Automatically generated by @tsed/barrels.
*/
export * from "./decorators/configurable.js";
export * from "./decorators/deprecated.js";
export * from "./decorators/enumerable.js";
export * from "./decorators/notConfigurable.js";
export * from "./decorators/notEnumerable.js";
export * from "./decorators/readOnly.js";
export * from "./decorators/storeFn.js";
export * from "./decorators/storeMerge.js";
export * from "./decorators/storeSet.js";
export * from "./decorators/writable.js";
export * from "./domain/AnyToPromise.js";
export * from "./domain/DecoratorTypes.js";
export * from "./domain/Env.js";
Expand Down Expand Up @@ -45,7 +38,6 @@ export * from "./utils/objects/deepMerge.js";
export * from "./utils/objects/descriptorOf.js";
export * from "./utils/objects/getClassOrSymbol.js";
export * from "./utils/objects/getConstructorArgNames.js";
export * from "./utils/objects/getEnumerableKeys.js";
export * from "./utils/objects/getValue.js";
export * from "./utils/objects/hasJsonMethod.js";
export * from "./utils/objects/isArray.js";
Expand Down Expand Up @@ -82,5 +74,4 @@ export * from "./utils/objects/prototypeOf.js";
export * from "./utils/objects/setValue.js";
export * from "./utils/objects/toMap.js";
export * from "./utils/objects/toStringConstructor.js";
export * from "./utils/proxyDelegation.js";
export * from "./utils/uniq.js";
export * from "./utils/objects/uniq.js";
48 changes: 0 additions & 48 deletions packages/core/src/utils/proxyDelegation.spec.ts

This file was deleted.

91 changes: 0 additions & 91 deletions packages/core/src/utils/proxyDelegation.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/di/src/common/decorators/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ export function Configuration(configuration: Partial<TsED.Configuration> = {}):
};
}

export type Configuration = TsED.Configuration & DIConfiguration;
export type Configuration = TsED.DIConfiguration & DIConfiguration;
2 changes: 1 addition & 1 deletion packages/di/src/common/fn/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import {DIConfiguration} from "../services/DIConfiguration.js";
import {injector} from "./injector.js";

export function configuration() {
return injector().settings as TsED.Configuration & DIConfiguration;
return injector().settings as TsED.DIConfiguration & DIConfiguration;
}
14 changes: 1 addition & 13 deletions packages/di/src/common/fn/injectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,7 @@ export function providerBuilder<Provider, Picked extends keyof Provider>(props:
};
}

type PickedProps =
| "scope"
| "path"
| "alias"
| "useFactory"
| "useAsyncFactory"
| "useValue"
| "useClass"
| "hooks"
| "deps"
| "resolvers"
| "imports"
| "configuration";
type PickedProps = "scope" | "path" | "alias" | "hooks" | "deps" | "resolvers" | "imports" | "configuration";

const Props = ["type", "scope", "path", "alias", "hooks", "deps", "resolvers", "imports", "configuration"];
export const injectable = providerBuilder<Provider, PickedProps | "type">(Props);
Expand Down
5 changes: 5 additions & 0 deletions packages/di/src/common/interfaces/DIConfigurationOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ declare global {
// @ts-ignore
interface Context {}

/**
* Here to allow extension on DIConfiguration base service
*/
interface DIConfiguration {}

interface Configuration extends Record<string, any> {
scopes: {[key: string]: ProviderScope};
/**
Expand Down
8 changes: 0 additions & 8 deletions packages/di/src/common/services/DIConfiguration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,4 @@ describe("DIConfiguration", () => {
expect(configuration.resolvers).toEqual([]);
});
});

describe("rootDir()", () => {
it("should replace rootDir", () => {
const configuration = new DIConfiguration();
configuration.set("rootDir", "/root");
expect(configuration.resolve("${rootDir}")).toEqual("/root");
});
});
});
17 changes: 1 addition & 16 deletions packages/di/src/common/services/DIConfiguration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Env, getValue, proxyDelegation, setValue} from "@tsed/core";
import {Env, getValue, setValue} from "@tsed/core";

import type {ProviderScope} from "../domain/ProviderScope.js";
import type {DILoggerOptions} from "../interfaces/DILoggerOptions.js";
Expand All @@ -22,12 +22,6 @@ export class DIConfiguration {
}).forEach(([key, value]) => {
this.default.set(key, value);
});

return proxyDelegation<DIConfiguration>(this, {
ownKeys(target) {
return [...target.default.keys(), ...target.map.keys()];
}
});
}

get version() {
Expand Down Expand Up @@ -152,15 +146,6 @@ export class DIConfiguration {
return this.getRaw(propertyKey, defaultValue);
}

/**
*
* @param value
* @returns {any}
*/
resolve(value: any) {
return value.replace("${rootDir}", this.rootDir);
}

protected getRaw(propertyKey: string, defaultValue?: any): any {
const value = getValue(this.map, propertyKey);

Expand Down
6 changes: 3 additions & 3 deletions packages/graphql/apollo/src/ApolloModule.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Configuration, Inject, InjectorService, Module} from "@tsed/di";
import {Logger} from "@tsed/logger";
import {AfterListen, OnRoutesInit} from "@tsed/platform-http";
import {AfterListen, OnRoutesInit, PlatformConfiguration} from "@tsed/platform-http";

import {ApolloSettings} from "./interfaces/ApolloSettings.js";
import {ApolloService} from "./services/ApolloService.js";
Expand All @@ -14,7 +14,7 @@ export class ApolloModule implements OnRoutesInit, AfterListen {
protected service: ApolloService;

@Configuration()
protected configuration: Configuration;
protected configuration: PlatformConfiguration;

@Inject(InjectorService)
protected injector: InjectorService;
Expand All @@ -41,7 +41,7 @@ export class ApolloModule implements OnRoutesInit, AfterListen {
const host = this.configuration.getBestHost();

const displayLog = (key: string, path: string) => {
const url = typeof host.port === "number" ? `${host.protocol}://${host.address}:${host.port}` : "";
const url = "port" in host && typeof host.port === "number" ? `${host.protocol}://${host.address}:${host.port}` : "";

this.logger.info(`[${key}] Apollo server is available on ${url}/${path.replace(/^\//, "")}`);
};
Expand Down
6 changes: 3 additions & 3 deletions packages/graphql/apollo/vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ export default defineConfig(
coverage: {
...presets.test.coverage,
thresholds: {
statements: 83.48,
statements: 83.11,
branches: 87.17,
functions: 94.11,
lines: 83.48
lines: 83.11
}
}
}
}
);
);
1 change: 1 addition & 0 deletions packages/platform/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from "@tsed/platform-middlewares";
export * from "@tsed/platform-params";
export * from "@tsed/platform-response-filter";
export * from "@tsed/platform-router";
export {AcceptMime, All, Delete, Get, Head, Location, Options, Patch, Post, Put, Redirect, View} from "@tsed/schema";
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,15 @@ export class PlatformConfiguration extends DIConfiguration {
};
}
}

declare global {
namespace TsED {
// @ts-ignore
interface Context {}

/**
* Here to allow extension on DIConfiguration base service
*/
interface DIConfiguration extends PlatformConfiguration {}
}
}
13 changes: 5 additions & 8 deletions packages/specs/swagger/src/services/SwaggerService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {Type} from "@tsed/core";
import {Configuration, Injectable, InjectorService} from "@tsed/di";
import {constant, Injectable} from "@tsed/di";
import {OpenSpec2, OpenSpec3} from "@tsed/openspec";
import {Platform} from "@tsed/platform-http";
import {generateSpec} from "@tsed/schema";
Expand All @@ -11,11 +11,7 @@ import {includeRoute} from "../utils/includeRoute.js";
export class SwaggerService {
#specs: Map<string, OpenSpec3 | OpenSpec2> = new Map();

constructor(
private injectorService: InjectorService,
private platform: Platform,
@Configuration() private configuration: Configuration
) {}
constructor(private platform: Platform) {}

/**
* Generate Spec for the given configuration
Expand All @@ -26,8 +22,9 @@ export class SwaggerService {
public async getOpenAPISpec(conf: SwaggerSettings): Promise<OpenSpec2>;
public async getOpenAPISpec(conf: SwaggerSettings) {
if (!this.#specs.has(conf.path)) {
const {version = "1.0.0", acceptMimes} = this.configuration;
const specPath = conf.specPath ? this.configuration.resolve(conf.specPath) : conf.specPath;
const version = constant("version", "1.0.0");
const acceptMimes = constant<string>("acceptMimes");
const specPath = conf.specPath;

const tokens = this.platform
.getMountedControllers()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {Configuration, Inject, Injectable, OnDestroy} from "@tsed/di";
import {Logger} from "@tsed/logger";
import {PlatformConfiguration} from "@tsed/platform-http";
import {io, Socket} from "socket.io-client";

@Injectable()
export class SocketClientService implements OnDestroy {
@Configuration()
private settings: Configuration;
private settings: PlatformConfiguration;

@Inject()
private logger: Logger;
Expand Down
Loading
Loading