-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
556 additions
and
193 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { ManifestInterface } from './manifest.interface'; | ||
import { Token } from './internal-types'; | ||
import { ManifestInterface as publicManifestInterface } from './public-interfaces/manifest.interface'; | ||
|
||
export interface ContainerInterface { | ||
loadManifests(manifests: ManifestInterface[]); | ||
loadManifests(manifests: publicManifestInterface[]); | ||
compile(); | ||
get(moduleName: string, token: Token); | ||
} |
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 |
---|---|---|
@@ -1,50 +1,21 @@ | ||
import 'reflect-metadata'; | ||
import { Container } from './container'; | ||
import { Module } from './module'; | ||
import { AlreadyCompiledError } from './errors/already-compiled.error'; | ||
|
||
class TestServiceA {} | ||
class TestServiceB { | ||
constructor(testServiceA) { | ||
describe('IoC container', function() { | ||
beforeEach(() => { | ||
// @ts-ignore | ||
this.testServiceA = testServiceA; | ||
} | ||
} | ||
|
||
describe('IoC container', () => { | ||
it('should parse manifest to module', () => { | ||
const container = new Container(); | ||
const diManifest = { | ||
moduleName: 'tesModule', | ||
providers: [ | ||
{ | ||
token: 'testServiceA', | ||
useClass: TestServiceA, | ||
}, | ||
], | ||
}; | ||
|
||
container.loadManifests([diManifest]); | ||
// @ts-ignore | ||
expect(container.modules.size).toEqual(1); | ||
// @ts-ignore | ||
expect([...container.modules.values()][0]).toBeInstanceOf(Module); | ||
this.container = new Container({}, {}); | ||
}); | ||
|
||
it('Should throw error if has already compiled', () => { | ||
const container = new Container(); | ||
const diManifest = { | ||
moduleName: 'tesModule', | ||
providers: [ | ||
{ | ||
token: 'testServiceA', | ||
useClass: TestServiceA, | ||
}, | ||
], | ||
}; | ||
container.loadManifests([diManifest]); | ||
container.compile(); | ||
expect(() => { | ||
container.compile(); | ||
}).toThrow(AlreadyCompiledError); | ||
expect.assertions(1); | ||
this.container.applyPublicProviders = () => {}; | ||
this.container.compile(); | ||
try { | ||
this.container.compile(); | ||
} catch (e) { | ||
expect(e).toBeInstanceOf(AlreadyCompiledError); | ||
} | ||
}); | ||
}); |
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 was deleted.
Oops, something went wrong.
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,32 @@ | ||
import { IsBoolean, IsNotEmpty, IsOptional, IsString } from 'class-validator'; | ||
import { buildPublicToken } from '../helpers'; | ||
import { DependencyInterface, Token } from '../internal-types'; | ||
import { DependencyType } from '../public-interfaces/dependency.interface'; | ||
|
||
export class DependencyDto implements DependencyInterface { | ||
@IsString() | ||
@IsNotEmpty() | ||
public readonly token: Token; | ||
|
||
@IsOptional() | ||
@IsString() | ||
public readonly fromModule: string | null = null; | ||
|
||
@IsBoolean() | ||
public readonly autoFactory: boolean = false; | ||
|
||
public constructor(config: DependencyType) { | ||
if (Array.isArray(config)) { | ||
const [token, dependencyOptions] = config; | ||
this.token = token; | ||
this.autoFactory = | ||
(dependencyOptions && dependencyOptions.autoFactory) || false; | ||
this.fromModule = dependencyOptions && dependencyOptions.fromModule; | ||
if (this.fromModule) { | ||
this.token = buildPublicToken(this.fromModule, this.token); | ||
} | ||
} else { | ||
this.token = config; | ||
} | ||
} | ||
} |
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,23 @@ | ||
import { Type } from 'class-transformer'; | ||
import { | ||
ArrayNotEmpty, | ||
IsArray, | ||
IsNotEmpty, | ||
IsString, | ||
ValidateNested, | ||
} from 'class-validator'; | ||
import { ManifestInterface } from './manifest.interface'; | ||
import { ProviderInterface } from './provider.interface'; | ||
import { ProviderDto } from './provider.dto'; | ||
|
||
export class ManifestDto implements ManifestInterface { | ||
@IsNotEmpty() | ||
@IsString() | ||
public moduleName: string; | ||
|
||
@IsArray() | ||
@ArrayNotEmpty() | ||
@ValidateNested() | ||
@Type(() => ProviderDto) | ||
public providers: ProviderInterface[]; | ||
} |
File renamed without changes.
Oops, something went wrong.