Skip to content

Commit

Permalink
fix: update types
Browse files Browse the repository at this point in the history
  • Loading branch information
Wroud committed Jun 4, 2024
1 parent 3239144 commit eeee11c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/di/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wroud/di",
"version": "0.0.5",
"version": "0.0.6",
"packageManager": "[email protected]",
"type": "module",
"license": "MIT",
Expand Down Expand Up @@ -32,7 +32,7 @@
"@types/node": "^20",
"concurrently": "^8",
"rimraf": "^5",
"tslib": "^2.6.2",
"tslib": "^2",
"typescript": "^5"
}
}
4 changes: 1 addition & 3 deletions packages/di/src/di/ServicesRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ export class ServicesRegistry {
new WeakMap();

static register<
TClass extends abstract new (
...args: MapToServicesType<TServices>
) => any | Function,
TClass extends abstract new (...args: MapToServicesType<TServices>) => any,
TServices extends ServiceType<any>[] = [],
>(service: TClass, metadata: IServiceMetadata<TServices>) {
const existing = this.services.get(service);
Expand Down
27 changes: 22 additions & 5 deletions packages/di/src/di/injectable.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
import type { MapToServicesType } from "./MapToServicesType.js";
import type { ServiceType } from "./ServiceType.js";
import { ServicesRegistry } from "./ServicesRegistry.js";

export function injectable<TServices extends any[] = []>(
function injectable(): <
TClass extends abstract new (...args: MapToServicesType<[]>) => any,
>(
target: TClass,
context?: ClassDecoratorContext<TClass> | undefined,
) => TClass;
function injectable<TServices extends ServiceType<any>[]>(
dependencies: () => [...TServices],
): <TClass extends abstract new (...args: MapToServicesType<TServices>) => any>(
target: TClass,
context?: ClassDecoratorContext<TClass> | undefined,
) => TClass;
function injectable<TServices extends ServiceType<any>[]>(
dependencies: () => [...TServices],
): <TClass extends new (...args: MapToServicesType<TServices>) => any>(
target: TClass,
) => TClass;
function injectable<TServices extends ServiceType<any>[]>(
dependencies: () => [...TServices] = () => [] as any,
) {
return <
TClass extends abstract new (
...args: MapToServicesType<TServices>
) => any | Function,
TClass extends abstract new (...args: MapToServicesType<TServices>) => any,
>(
target: TClass,
context?: ClassDecoratorContext<TClass> | undefined,
...rest: any[]
): TClass => {
let name = target.name;

Expand All @@ -32,3 +47,5 @@ export function injectable<TServices extends any[] = []>(
return target;
};
}

export { injectable };
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2473,7 +2473,7 @@ __metadata:
"@types/node": "npm:^20"
concurrently: "npm:^8"
rimraf: "npm:^5"
tslib: "npm:^2.6.2"
tslib: "npm:^2"
typescript: "npm:^5"
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -6184,7 +6184,7 @@ __metadata:
languageName: node
linkType: hard

"tslib@npm:^2, tslib@npm:^2.1.0, tslib@npm:^2.6.2":
"tslib@npm:^2, tslib@npm:^2.1.0":
version: 2.6.2
resolution: "tslib@npm:2.6.2"
checksum: 10c0/e03a8a4271152c8b26604ed45535954c0a45296e32445b4b87f8a5abdb2421f40b59b4ca437c4346af0f28179780d604094eb64546bee2019d903d01c6c19bdb
Expand Down

1 comment on commit eeee11c

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 97.55% 517/530
🟢 Branches 96.12% 99/103
🟢 Functions 100% 35/35
🟢 Lines 97.55% 517/530

Test suite run success

85 tests passing in 8 suites.

Report generated by 🧪jest coverage report action from eeee11c

Please sign in to comment.