# HG changeset patch # User cin # Date 2020-06-18 23:26:20 # Node ID 3725cefc8f982db44e9df840682747f96a0dee6c # Parent c6d15f5d0e651830ecccfaff1f84e1eb625f40ec Initial work on typescript support for the container configuration diff --git a/.settings/org.eclipse.buildship.core.prefs b/.settings/org.eclipse.buildship.core.prefs --- a/.settings/org.eclipse.buildship.core.prefs +++ b/.settings/org.eclipse.buildship.core.prefs @@ -1,2 +1,13 @@ +arguments= +auto.sync=false +build.scans.enabled=false +connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) connection.project.dir= eclipse.preferences.version=1 +gradle.user.home= +java.home=/usr/lib64/jvm/java +jvm.arguments= +offline.mode=false +override.workspace.settings=true +show.console.view=true +show.executions.view=true diff --git a/build.gradle b/build.gradle --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id "org.implab.gradle-typescript" version "1.3.0" + id "org.implab.gradle-typescript" version "1.3.3" id "org.implab.gradle-hg" id "ivy-publish" } @@ -52,7 +52,7 @@ typescript { if(symbols != 'none') { sourceMap = true - sourceRoot = "_src" + sourceRoot = packageName } if (flavour == 'node') { diff --git a/src/main/ts/di/Annotations.ts b/src/main/ts/di/Annotations.ts new file mode 100644 --- /dev/null +++ b/src/main/ts/di/Annotations.ts @@ -0,0 +1,11 @@ +import { Constructor } from "../interfaces"; + +export interface InjectOptions { + lazy?: boolean; +} + +export function inject void } >(dependency: string) { + return (target: any, memberName: M, descriptor: TypedPropertyDescriptor ) => { + + }; +} diff --git a/src/main/ts/di/Container.ts b/src/main/ts/di/Container.ts --- a/src/main/ts/di/Container.ts +++ b/src/main/ts/di/Container.ts @@ -113,15 +113,15 @@ export class Container { return new Container(this); } - has(id) { + has(id: string | number) { return id in this._cache; } - get(id) { + get(id: string | number) { return this._cache[id]; } - store(id, value) { + store(id: string | number, value: any) { return (this._cache[id] = value); } diff --git a/src/test/ts/mock/Box.ts b/src/test/ts/mock/Box.ts new file mode 100644 --- /dev/null +++ b/src/test/ts/mock/Box.ts @@ -0,0 +1,18 @@ +import { inject } from "../di/Annotations"; + +export interface Injector { + setValue(value: T); +} + +export class Box implements Injector { + private _value: T; + + @inject>("bar") + setValue(value: T) { + this._value = value; + } + + getValue() { + return this._value; + } +} diff --git a/src/test/ts/tests/ConfigurationBuilderTests.ts b/src/test/ts/tests/ConfigurationBuilderTests.ts new file mode 100644 --- /dev/null +++ b/src/test/ts/tests/ConfigurationBuilderTests.ts @@ -0,0 +1,36 @@ +import { Constructor } from "../interfaces"; +import { ActivationType } from "../di/interfaces"; + +namespace MyLib { + interface Resolver { + (name: K): S[K]; + (lazy: K): (overrides?: {}) => S[K]; + } + + interface RegistrationOptions { + activation?: ActivationType; + services?: BuilderContext; + } + + interface BuilderContext { + registerType( + name: K, + constructor: T, + options?: RegistrationOptions + ): BuilderContext; + + registerFactory( + name: K, + factory: (resolver: Resolver) => T, + options?: RegistrationOptions + ): BuilderContext; + + registerInstance( + name: K, + instance: T, + ownership?: boolean + ): BuilderContext; + } +} + +export = MyLib; diff --git a/src/tsconfig.json b/src/tsconfig.json --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -1,9 +1,11 @@ { "compilerOptions": { "moduleResolution": "node", + "experimentalDecorators": true, "noEmitOnError": true, "listFiles": true, "types": [], + "target": "ES5", "lib": ["es5", "es2015.promise", "es2015.symbol", "es2015.iterable", "dom", "scripthost"] } } \ No newline at end of file