diff --git a/build.gradle b/build.gradle --- a/build.gradle +++ b/build.gradle @@ -56,7 +56,7 @@ typescript { if(symbols != 'none') { sourceMap = true - sourceRoot = packageName + sourceRoot = "pack:${packageName}" } if (flavour == 'node') { diff --git a/src/main/ts/Uuid.ts b/src/main/ts/Uuid.ts --- a/src/main/ts/Uuid.ts +++ b/src/main/ts/Uuid.ts @@ -14,6 +14,10 @@ declare const Buffer: any; const _window: any = "undefined" !== typeof window ? window : null; +function noop(): never { + throw new Error(); +} + interface WritableArrayLike { length: number; [n: number]: T; @@ -24,13 +28,13 @@ interface WritableArrayLike { // detect to determine the best RNG source, normalizing to a function // that // returns 128-bits of randomness, since that's what's usually required -let _rng: () => WritableArrayLike = () => []; +let _rng: () => WritableArrayLike = noop; function setupBrowser() { // Allow for MSIE11 msCrypto const _crypto = _window.crypto || _window.msCrypto; - if (!_rng && _crypto && _crypto.getRandomValues) { + if (_rng === noop && _crypto && _crypto.getRandomValues) { // WHATWG crypto-based RNG - http://wiki.whatwg.org/wiki/Crypto // // Moderately fast, high quality @@ -44,7 +48,7 @@ function setupBrowser() { } catch (e) { /**/ } } - if (!_rng) { + if (_rng === noop) { // Math.random()-based (RNG) // // If all else fails, use Math.random(). It's fast, but is of 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 @@ -5,7 +5,7 @@ import { ServiceMap, Descriptor, Partial import { TraceSource } from "../log/TraceSource"; import { Configuration, RegistrationMap } from "./Configuration"; import { Cancellation } from "../Cancellation"; -import { IDestroyable, ICancellation } from "../interfaces"; +import { ICancellation } from "../interfaces"; import { isDescriptor } from "./traits"; import { LifetimeManager } from "./LifetimeManager"; import { each, isString } from "../safe"; @@ -14,7 +14,7 @@ import { FluentConfiguration } from "./f const trace = TraceSource.get("@implab/core/di/ActivationContext"); -export class Container implements ServiceContainer, IDestroyable { +export class Container implements ServiceContainer { readonly _services: ContainerServiceMap; readonly _lifetimeManager: LifetimeManager; @@ -29,10 +29,11 @@ export class Container) { this._parent = parent; - this._services = parent ? Object.create(parent._services) : {}; + this._services = Object.create(parent ? parent._services : null); this._cleanup = []; this._root = parent ? parent.getRootContainer() : this; this._services.container = new ValueDescriptor(this) as any; + this._services.childContainer = { activate: () => this.createChildContainer() }; this._disposed = false; this._lifetimeManager = new LifetimeManager(); } diff --git a/src/main/ts/di/interfaces.ts b/src/main/ts/di/interfaces.ts --- a/src/main/ts/di/interfaces.ts +++ b/src/main/ts/di/interfaces.ts @@ -1,3 +1,4 @@ +import { IDestroyable } from "../interfaces"; import { ActivationContext } from "./ActivationContext"; import { LifetimeManager } from "./LifetimeManager"; @@ -27,7 +28,7 @@ export interface ServiceLocator>(name: K, def?: TypeOfService): TypeOfService; } -export interface ServiceContainer extends ServiceLocator { +export interface ServiceContainer extends ServiceLocator, IDestroyable { getLifetimeManager(): LifetimeManager; register(name: K, service: Descriptor): this; register(services: PartialServiceMap): this; @@ -37,6 +38,8 @@ export interface ServiceContainer { container: ServiceLocator; + + childContainer: ServiceContainer; } export type ContainerRegistered = /*{ diff --git a/src/test/ts/tests/TextTests.ts b/src/test/ts/tests/TextTests.ts --- a/src/test/ts/tests/TextTests.ts +++ b/src/test/ts/tests/TextTests.ts @@ -2,6 +2,7 @@ import { StringBuilder } from "../text/S import { test } from "./TestTraits"; import { MockConsole } from "../mock/MockConsole"; import { ConsoleWriter } from "../log/ConsoleWriter"; +import { Uuid } from "../Uuid"; test("String builder", async t => { const sb = new StringBuilder(); @@ -84,3 +85,11 @@ test("ConsoleWriter", t => { t.deepEqual(mockConsole.getBuffer()[0].data, ["25 or 6 to 4! Let's have some ", { product: "tee" }], "Should handle many text chunks and object at the end"); }); + +test("Uuid test", (t, log) => { + const id = Uuid(); + log.log("uuid = {0}", id); + t.assert(id, "Should generate uuid"); + t.notEqual(id, Uuid(), "uuid should never match"); + +});