chore: npm run format

This commit is contained in:
Stevan Freeborn
2025-05-12 22:23:31 -05:00
parent 586ee228ac
commit 92f00e3aa0
10 changed files with 144 additions and 129 deletions
-1
View File
@@ -76,4 +76,3 @@ jobs:
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
+4 -6
View File
@@ -56,7 +56,7 @@ import {
ServiceCollection,
createServiceIdentifier,
injectable,
inject
inject,
} from '@stevanfreeborn/netdi';
// Define interfaces
@@ -82,9 +82,7 @@ class GreetingService implements IGreetingService {
@injectable()
class Greeter implements IGreeter {
constructor(
@inject(greetingServiceIdentifier) private greetingService: IGreetingService
) {}
constructor(@inject(greetingServiceIdentifier) private greetingService: IGreetingService) {}
greet(name: string): string {
return this.greetingService.createGreeting(name);
@@ -146,7 +144,7 @@ services.addTransient(serviceIdentifier, Implementation);
For complex service instantiation, you can use factory methods:
```typescript
services.addSingleton(serviceIdentifier, (provider) => {
services.addSingleton(serviceIdentifier, provider => {
// Use the provider to get dependencies
const dependency = provider.getService(dependencyIdentifier);
@@ -192,7 +190,7 @@ Specifies a dependency for a parameter:
class MyService {
constructor(
@inject(loggerIdentifier) private logger: ILogger,
@inject(configIdentifier) private config: IConfig
@inject(configIdentifier) private config: IConfig,
) {}
}
```
+1 -1
View File
@@ -1,4 +1,4 @@
import "reflect-metadata";
import 'reflect-metadata';
export * from './serviceProvider.js';
export * from './types.js';
+5 -4
View File
@@ -120,7 +120,10 @@ export class ServiceCollection implements IServiceCollection {
implementationOrFactory: ServiceFactory<T> | Constructor<T>,
lifetime: ServiceLifetime,
): IServiceCollection {
if (typeof implementationOrFactory === 'function' && this.isConstructor(implementationOrFactory) === false) {
if (
typeof implementationOrFactory === 'function' &&
this.isConstructor(implementationOrFactory) === false
) {
const descriptor: ServiceDescriptor<T> = {
serviceType,
implementationType: Object as unknown as Constructor<T>,
@@ -149,8 +152,6 @@ export class ServiceCollection implements IServiceCollection {
* @returns True if the function is a constructor, false otherwise
*/
private isConstructor(func: unknown): func is Constructor<unknown> {
return typeof func === 'function' &&
!!func.prototype &&
func.prototype.constructor === func;
return typeof func === 'function' && !!func.prototype && func.prototype.constructor === func;
}
}
+20 -5
View File
@@ -87,7 +87,10 @@ export interface IServiceCollection {
* @param implementationType - The implementation class
* @returns The service collection for method chaining
*/
addSingleton<T>(serviceType: ServiceIdentifier<T>, implementationType: Constructor<T>): IServiceCollection;
addSingleton<T>(
serviceType: ServiceIdentifier<T>,
implementationType: Constructor<T>,
): IServiceCollection;
/**
* Registers a singleton service with a factory function
@@ -97,7 +100,10 @@ export interface IServiceCollection {
* @param factory - A factory function that creates the service instance
* @returns The service collection for method chaining
*/
addSingleton<T>(serviceType: ServiceIdentifier<T>, factory: ServiceFactory<T>): IServiceCollection;
addSingleton<T>(
serviceType: ServiceIdentifier<T>,
factory: ServiceFactory<T>,
): IServiceCollection;
/**
* Registers a scoped service with the collection
@@ -107,7 +113,10 @@ export interface IServiceCollection {
* @param implementationType - The implementation class
* @returns The service collection for method chaining
*/
addScoped<T>(serviceType: ServiceIdentifier<T>, implementationType: Constructor<T>): IServiceCollection;
addScoped<T>(
serviceType: ServiceIdentifier<T>,
implementationType: Constructor<T>,
): IServiceCollection;
/**
* Registers a scoped service with a factory function
@@ -127,7 +136,10 @@ export interface IServiceCollection {
* @param implementationType - The implementation class
* @returns The service collection for method chaining
*/
addTransient<T>(serviceType: ServiceIdentifier<T>, implementationType: Constructor<T>): IServiceCollection;
addTransient<T>(
serviceType: ServiceIdentifier<T>,
implementationType: Constructor<T>,
): IServiceCollection;
/**
* Registers a transient service with a factory function
@@ -137,7 +149,10 @@ export interface IServiceCollection {
* @param factory - A factory function that creates the service instance
* @returns The service collection for method chaining
*/
addTransient<T>(serviceType: ServiceIdentifier<T>, factory: ServiceFactory<T>): IServiceCollection;
addTransient<T>(
serviceType: ServiceIdentifier<T>,
factory: ServiceFactory<T>,
): IServiceCollection;
/**
* Builds a service provider from the registered services
+6 -4
View File
@@ -79,7 +79,6 @@ describe('ServiceCollection', () => {
expect(serviceInstance1).not.toBe(serviceInstance2);
});
it('should add a transient service with a factory', () => {
class TestService {}
const serviceIdentifier = createServiceIdentifier();
@@ -96,12 +95,12 @@ describe('ServiceCollection', () => {
});
it('should add a service with a factory and dependencies', () => {
type IDependencyService = object
type IDependencyService = object;
class DependencyService implements IDependencyService {}
type ITestService = {
dependency: IDependencyService;
}
};
class TestService implements ITestService {
constructor(public dependency: DependencyService) {}
}
@@ -111,7 +110,10 @@ describe('ServiceCollection', () => {
const collection = new ServiceCollection();
collection.addSingleton(dependencyServiceIdentifier, DependencyService);
collection.addSingleton(testServiceIdentifier, (provider) => new TestService(provider.getService(dependencyServiceIdentifier)));
collection.addSingleton(
testServiceIdentifier,
provider => new TestService(provider.getService(dependencyServiceIdentifier)),
);
const provider = collection.build();
const serviceInstance1 = provider.getService(testServiceIdentifier);
+1 -1
View File
@@ -427,7 +427,7 @@ describe('ServiceProvider', () => {
expect(initialService).toBe(newService);
});
it("should not clear the scoped instances on dispose from another scope when one scope is disposed", () => {
it('should not clear the scoped instances on dispose from another scope when one scope is disposed', () => {
type IService = {
id: string;
};