Permalink
Browse files

use interfaces instead of concrete implementation

  • Loading branch information...
Novaal committed Jul 18, 2018
1 parent a8f2a91 commit 0d1b2c8522d2f4817624d8dc54d3c418fa73d7a8
Showing with 96 additions and 83 deletions.
  1. +0 −3 .vscode/launch.json
  2. +1 −1 spec/components/integration/multiple-requests.spec.ts
  3. +2 −2 spec/components/services/session-factories/crypted-platform-session-factory.spec.ts
  4. +3 −2 spec/components/services/session-factories/crypted-platform-session.spec.ts
  5. +2 −3 spec/components/state-machine/base-state.spec.ts
  6. +2 −2 spec/components/state-machine/execute-filters-hook.spec.ts
  7. +3 −4 spec/components/unifier/response-handler/handler-proxy-factory.spec.ts
  8. +2 −2 spec/support/mocks/states/context/context-a.ts
  9. +2 −2 spec/support/mocks/states/context/context-b.ts
  10. +2 −2 spec/support/mocks/states/context/context-c.ts
  11. +2 −2 spec/support/mocks/states/context/context-d.ts
  12. +2 −2 spec/support/mocks/states/filter-a.ts
  13. +2 −2 spec/support/mocks/states/filter-b.ts
  14. +2 −2 spec/support/mocks/states/filter-c.ts
  15. +2 −2 spec/support/mocks/states/main.ts
  16. +2 −3 spec/support/mocks/states/sub.ts
  17. +2 −2 spec/support/mocks/states/unhandled-error.ts
  18. +4 −5 spec/support/util/setup.ts
  19. +3 −3 src/components/services/session-factories/crypted-platform-session-factory.ts
  20. +2 −2 src/components/services/session-factories/crypted-platform-session.ts
  21. +4 −5 src/components/services/session-factories/platform-session-factory.ts
  22. +2 −2 src/components/services/session-factories/platform-session-mirror.ts
  23. +2 −2 src/components/services/session-factories/platform-session.ts
  24. +6 −6 src/components/state-machine/base-state.ts
  25. +2 −2 src/components/state-machine/descriptor.ts
  26. +2 −3 src/components/state-machine/public-interfaces.ts
  27. +3 −3 src/components/unifier/descriptor.ts
  28. +2 −2 src/components/unifier/public-interfaces.ts
  29. +2 −2 src/components/unifier/response-handler/after-state-handler.ts
  30. +3 −3 src/components/unifier/response-handler/basic-handler.ts
  31. +0 −1 src/components/unifier/response-handler/handler-proxy-factory.ts
  32. +23 −0 src/components/unifier/response-handler/handler-types.ts
  33. +3 −4 src/spec-setup.ts
@@ -6,9 +6,6 @@
"request": "launch",
"name": "Specs",
"program": "${workspaceRoot}/node_modules/jasmine-ts/lib/index.js",
"env": {
"DEBUG": "*"
},
"args": [
"**/*.spec.ts"
],
@@ -20,7 +20,7 @@ describe("with child containers enabled", function() {
});
describe("when multiple requests fired", function() {
const FIRE_AMOUNT = 1;
const FIRE_AMOUNT = 50;
const extractionData = { intent: "answer", message: "My message", platform: extraction.platform };
let request: RequestProxy;
@@ -1,14 +1,14 @@
import { BasicHandler } from "../../../../src/assistant-source";
import { SessionConfiguration } from "../../../../src/components/services/private-interfaces";
import { CryptedPlatformSessionFactory } from "../../../../src/components/services/session-factories/crypted-platform-session-factory";
import { MinimalRequestExtraction, OptionalExtractions } from "../../../../src/components/unifier/public-interfaces";
import { BasicSessionHandable } from "../../../../src/components/unifier/response-handler";
import { injectionNames } from "../../../../src/injection-names";
import { createRequestScope } from "../../../support/util/setup";
import { ThisContext } from "../../../this-context";
interface CurrentThisContext extends ThisContext {
extraction: MinimalRequestExtraction & OptionalExtractions.SessionData;
handler: BasicHandler<any>;
handler: BasicSessionHandable<any>;
sessionFactory: CryptedPlatformSessionFactory;
}
@@ -1,11 +1,12 @@
import { BasicHandler, injectionNames } from "../../../../src/assistant-source";
import { injectionNames } from "../../../../src/assistant-source";
import { CryptedPlatformSession } from "../../../../src/components/services/session-factories/crypted-platform-session";
import { OptionalExtractions } from "../../../../src/components/unifier/public-interfaces";
import { BasicSessionHandable } from "../../../../src/components/unifier/response-handler";
import { createRequestScope } from "../../../support/util/setup";
import { ThisContext } from "../../../this-context";
interface CurrentThisContext extends ThisContext {
handler: BasicHandler<any>;
handler: BasicSessionHandable<any>;
extractionData: OptionalExtractions.SessionData;
session: CryptedPlatformSession;
params: any;
@@ -1,7 +1,6 @@
import { BasicHandler } from "../../../src/assistant-source";
import { BaseState } from "../../../src/components/state-machine/base-state";
import { State } from "../../../src/components/state-machine/public-interfaces";
import { Voiceable } from "../../../src/components/unifier/public-interfaces";
import { BasicHandable } from "../../../src/components/unifier/public-interfaces";
import { injectionNames } from "../../../src/injection-names";
import { SpecSetup } from "../../../src/spec-setup";
import { PLATFORM } from "../../support/mocks/unifier/extraction";
@@ -12,7 +11,7 @@ import { ThisContext } from "../../this-context";
interface CurrentThisContext extends ThisContext {
state: BaseState;
specHelper: SpecSetup;
handler: BasicHandler<any>;
handler: BasicHandable<any>;
}
describe("BaseState", function() {
@@ -1,11 +1,11 @@
import { Container } from "inversify-components";
import { BasicAnswerTypes, BasicHandler, injectionNames, SpecSetup, TranslateHelper } from "../../../src/assistant-source";
import { BasicAnswerTypes, BasicHandable, injectionNames, SpecSetup, TranslateHelper } from "../../../src/assistant-source";
import { StateMachine } from "../../../src/components/state-machine/state-machine";
import { configureI18nLocale } from "../../support/util/i18n-configuration";
import { createRequestScope } from "../../support/util/setup";
interface CurrentThisContext {
responseHandler: BasicHandler<any>;
responseHandler: BasicHandable<any>;
resultHolder: HandlerHasResults;
specHelper: SpecSetup;
stateMachine: StateMachine;
@@ -1,9 +1,8 @@
import { Container } from "inversify";
import { BasicHandable, BasicHandler, injectionNames } from "../../../../src/assistant-source";
import { BasicHandable } from "../../../../src/components/unifier/response-handler";
import { HandlerProxyFactory } from "../../../../src/components/unifier/response-handler/handler-proxy-factory";
import { PLATFORM } from "../../../support/mocks/unifier/extraction";
import { MockHandlerA, MockHandlerASpecificHandable, MockHandlerASpecificTypes } from "../../../support/mocks/unifier/response-handler/mock-handler-a";
import { MockHandlerB, MockHandlerBSpecificHandable, MockHandlerBSpecificTypes } from "../../../support/mocks/unifier/response-handler/mock-handler-b";
import { MockHandlerASpecificHandable, MockHandlerASpecificTypes } from "../../../support/mocks/unifier/response-handler/mock-handler-a";
import { MockHandlerBSpecificHandable, MockHandlerBSpecificTypes } from "../../../support/mocks/unifier/response-handler/mock-handler-b";
import { createRequestScope } from "../../../support/util/setup";
import { ThisContext } from "../../../this-context";
@@ -1,5 +1,5 @@
import { inject, injectable, optional } from "inversify";
import { BasicHandler } from "../../../../../src/assistant-source";
import { BasicHandable } from "../../../../../src/assistant-source";
import { TranslateHelper } from "../../../../../src/components/i18n/public-interfaces";
import { Logger } from "../../../../../src/components/root/public-interfaces";
import { BaseState } from "../../../../../src/components/state-machine/base-state";
@@ -14,7 +14,7 @@ export class ContextAState extends BaseState implements State.Required {
public extraction: any;
constructor(
@inject(injectionNames.current.responseHandler) responseHandler: BasicHandler<any>,
@inject(injectionNames.current.responseHandler) responseHandler: BasicHandable<any>,
@inject("core:unifier:current-extraction") extraction: any,
@inject("core:i18n:current-translate-helper") translateHelper: TranslateHelper,
@inject("core:root:current-logger") logger: Logger
@@ -1,5 +1,5 @@
import { inject, injectable, optional } from "inversify";
import { BasicHandler } from "../../../../../src/assistant-source";
import { BasicHandable } from "../../../../../src/assistant-source";
import { TranslateHelper } from "../../../../../src/components/i18n/public-interfaces";
import { Logger } from "../../../../../src/components/root/public-interfaces";
import { BaseState } from "../../../../../src/components/state-machine/base-state";
@@ -13,7 +13,7 @@ export class ContextBState extends BaseState implements State.Required {
public extraction: any;
constructor(
@inject(injectionNames.current.responseHandler) responseHandler: BasicHandler<any>,
@inject(injectionNames.current.responseHandler) responseHandler: BasicHandable<any>,
@inject("core:unifier:current-extraction") extraction: any,
@inject("core:i18n:current-translate-helper") translateHelper: TranslateHelper,
@inject("core:root:current-logger") logger: Logger
@@ -1,5 +1,5 @@
import { inject, injectable, optional } from "inversify";
import { BasicHandler } from "../../../../../src/assistant-source";
import { BasicHandable } from "../../../../../src/assistant-source";
import { TranslateHelper } from "../../../../../src/components/i18n/public-interfaces";
import { Logger } from "../../../../../src/components/root/public-interfaces";
import { BaseState } from "../../../../../src/components/state-machine/base-state";
@@ -16,7 +16,7 @@ export class ContextCState extends BaseState implements State.Required {
public extraction: any;
constructor(
@inject(injectionNames.current.responseHandler) responseHandler: BasicHandler<any>,
@inject(injectionNames.current.responseHandler) responseHandler: BasicHandable<any>,
@inject("core:unifier:current-extraction") extraction: any,
@inject("core:i18n:current-translate-helper") translateHelper: TranslateHelper,
@inject("core:root:current-logger") logger: Logger
@@ -1,5 +1,5 @@
import { inject, injectable, optional } from "inversify";
import { BasicHandler } from "../../../../../src/assistant-source";
import { BasicHandable } from "../../../../../src/assistant-source";
import { TranslateHelper } from "../../../../../src/components/i18n/public-interfaces";
import { Logger } from "../../../../../src/components/root/public-interfaces";
import { BaseState } from "../../../../../src/components/state-machine/base-state";
@@ -15,7 +15,7 @@ export class ContextDState extends BaseState implements State.Required {
public extraction: any;
constructor(
@inject(injectionNames.current.responseHandler) responseHandler: BasicHandler<any>,
@inject(injectionNames.current.responseHandler) responseHandler: BasicHandable<any>,
@inject("core:unifier:current-extraction") extraction: any,
@inject("core:i18n:current-translate-helper") translateHelper: TranslateHelper,
@inject("core:root:current-logger") logger: Logger
@@ -1,5 +1,5 @@
import { inject, injectable, optional } from "inversify";
import { BasicHandler } from "../../../../src/assistant-source";
import { BasicHandable } from "../../../../src/assistant-source";
import { TranslateHelper } from "../../../../src/components/i18n/public-interfaces";
import { Logger } from "../../../../src/components/root/public-interfaces";
import { BaseState } from "../../../../src/components/state-machine/base-state";
@@ -15,7 +15,7 @@ export class FilterAState extends BaseState implements State.Required {
public extraction: any;
constructor(
@inject(injectionNames.current.responseHandler) responseHandler: BasicHandler<any>,
@inject(injectionNames.current.responseHandler) responseHandler: BasicHandable<any>,
@inject("core:unifier:current-extraction") extraction: any,
@inject("core:i18n:current-translate-helper") translateHelper: TranslateHelper,
@inject("core:root:current-logger") logger: Logger
@@ -4,7 +4,7 @@ import { Logger } from "../../../../src/components/root/public-interfaces";
import { BaseState } from "../../../../src/components/state-machine/base-state";
import { filter } from "../../../../src/components/state-machine/filter-decorator";
import { State } from "../../../../src/components/state-machine/public-interfaces";
import { BasicHandler } from "../../../../src/components/unifier/response-handler/basic-handler";
import { BasicHandable } from "../../../../src/components/unifier/response-handler";
import { injectionNames } from "../../../../src/injection-names";
import { TestFilterA } from "../filters/test-filter-a";
import { TestFilterB } from "../filters/test-filter-b";
@@ -15,7 +15,7 @@ export class FilterBState extends BaseState implements State.Required {
public extraction: any;
constructor(
@inject(injectionNames.current.responseHandler) responseHandler: BasicHandler<any>,
@inject(injectionNames.current.responseHandler) responseHandler: BasicHandable<any>,
@inject("core:unifier:current-extraction") extraction: any,
@inject("core:i18n:current-translate-helper") translateHelper: TranslateHelper,
@inject("core:root:current-logger") logger: Logger
@@ -4,7 +4,7 @@ import { Logger } from "../../../../src/components/root/public-interfaces";
import { BaseState } from "../../../../src/components/state-machine/base-state";
import { filter } from "../../../../src/components/state-machine/filter-decorator";
import { State } from "../../../../src/components/state-machine/public-interfaces";
import { BasicHandler } from "../../../../src/components/unifier/response-handler/basic-handler";
import { BasicHandable } from "../../../../src/components/unifier/response-handler";
import { injectionNames } from "../../../../src/injection-names";
import { TestFilterB } from "../filters/test-filter-b";
import { TestFilterC } from "../filters/test-filter-c";
@@ -14,7 +14,7 @@ export class FilterCState extends BaseState implements State.Required {
public extraction: any;
constructor(
@inject(injectionNames.current.responseHandler) responseHandler: BasicHandler<any>,
@inject(injectionNames.current.responseHandler) responseHandler: BasicHandable<any>,
@inject("core:unifier:current-extraction") extraction: any,
@inject("core:i18n:current-translate-helper") translateHelper: TranslateHelper,
@inject("core:root:current-logger") logger: Logger
@@ -1,9 +1,9 @@
import { inject, injectable, optional } from "inversify";
import { BasicHandler } from "../../../../src/assistant-source";
import { TranslateHelper } from "../../../../src/components/i18n/public-interfaces";
import { Logger } from "../../../../src/components/root/public-interfaces";
import { BaseState } from "../../../../src/components/state-machine/base-state";
import { State } from "../../../../src/components/state-machine/public-interfaces";
import { BasicHandable } from "../../../../src/components/unifier/response-handler";
import { injectionNames } from "../../../../src/injection-names";
@injectable()
@@ -12,7 +12,7 @@ export class MainState extends BaseState implements State.Required {
public spy?: (...args: any[]) => void;
constructor(
@inject(injectionNames.current.responseHandler) responseHandler: BasicHandler<any>,
@inject(injectionNames.current.responseHandler) responseHandler: BasicHandable<any>,
@inject("core:unifier:current-extraction") extraction: any,
@inject("core:i18n:current-translate-helper") translateHelper: TranslateHelper,
@inject("core:root:current-logger") logger: Logger,
@@ -1,14 +1,13 @@
import { inject, injectable, optional } from "inversify";
import { Logger } from "../../../../src/components/root/public-interfaces";
import { BasicHandler } from "../../../../src/assistant-source";
import { BasicHandable } from "../../../../src/components/unifier/response-handler";
import { injectionNames } from "../../../../src/injection-names";
import { MainState } from "./main";
@injectable()
export class SubState extends MainState {
constructor(
@inject(injectionNames.current.responseHandler) responseHandler: BasicHandler<any>,
@inject(injectionNames.current.responseHandler) responseHandler: BasicHandable<any>,
@inject("core:unifier:current-extraction") extraction: any,
@inject("core:i18n:current-translate-helper") tHelper: any,
@inject("core:root:current-logger") logger: Logger,
@@ -1,6 +1,6 @@
import { inject, injectable, optional } from "inversify";
import { BasicHandler } from "../../../../src/assistant-source";
import { State } from "../../../../src/components/state-machine/public-interfaces";
import { BasicHandable } from "../../../../src/components/unifier/response-handler";
import { injectionNames } from "../../../../src/injection-names";
@injectable()
@@ -9,7 +9,7 @@ export class UnhandledErrorState implements State.Required {
public spy?: (...args: any[]) => void;
constructor(
@inject(injectionNames.current.responseHandler) responsehandler: BasicHandler<any>,
@inject(injectionNames.current.responseHandler) responsehandler: BasicHandable<any>,
@inject("core:unifier:current-extraction") extraction: any,
@optional()
@inject("mocks:states:call-spy")
@@ -1,12 +1,11 @@
import { ContainerImpl } from "inversify-components";
import { RequestContext } from "../../../src/components/root/public-interfaces";
import { MinimalRequestExtraction } from "../../../src/components/unifier/public-interfaces";
import { BasicHandable, MinimalRequestExtraction } from "../../../src/components/unifier/public-interfaces";
import { AssistantJSSetup } from "../../../src/setup";
import { SpecSetup } from "../../../src/spec-setup";
import { BasicHandler } from "../../../src/assistant-source";
import { TestFilterA } from "../mocks/filters/test-filter-a";
import { TestFilterB } from "../mocks/filters/test-filter-b";
import { TestFilterC } from "../mocks/filters/test-filter-c";
@@ -45,8 +44,8 @@ export function createSpecHelper(useMockStates = true, useChilds = false, autoBi
UnhandledErrorWithFallbackState,
PlainState,
IntentCallbackState,
FilterAState,
FilterBState,
FilterAState,
FilterBState,
FilterCState,
ContextAState,
ContextBState,
@@ -72,7 +71,7 @@ export function createRequestScope(
specSetup: SpecSetup,
minimalExtraction: MinimalRequestExtraction | null = JSON.parse(JSON.stringify(extraction)),
requestContext: RequestContext = context,
responseHandler: { new (...args: any[]): BasicHandler<any> } = ResponseHandler
responseHandler: { new (...args: any[]): BasicHandable<any> } = ResponseHandler
) {
specSetup.createRequestScope(minimalExtraction, requestContext, responseHandler);
}
@@ -1,7 +1,7 @@
import { inject, injectable } from "inversify";
import { injectionNames } from "../../../injection-names";
import { MinimalRequestExtraction, OptionalExtractions } from "../../unifier/public-interfaces";
import { BasicHandler } from "../../unifier/response-handler";
import { BasicSessionHandable } from "../../unifier/response-handler";
import { SessionConfiguration } from "../private-interfaces";
import { Session } from "../public-interfaces";
import { CryptedPlatformSession } from "./crypted-platform-session";
@@ -13,14 +13,14 @@ import { PlatformSessionFactory } from "./platform-session-factory";
export class CryptedPlatformSessionFactory extends PlatformSessionFactory {
constructor(
@inject(injectionNames.current.extraction) extraction: MinimalRequestExtraction,
@inject(injectionNames.current.responseHandler) handler: BasicHandler<any>
@inject(injectionNames.current.responseHandler) handler: BasicSessionHandable<any>
) {
super(extraction, handler);
}
protected createSession(
extraction: OptionalExtractions.SessionData,
handler: BasicHandler<any>,
handler: BasicSessionHandable<any>,
configuration?: SessionConfiguration.CryptedPlatform
): Session {
return new CryptedPlatformSession(extraction, handler, configuration ? configuration.encryptionKey : undefined);
@@ -1,6 +1,6 @@
import * as crypto from "crypto";
import { OptionalExtractions } from "../../unifier/public-interfaces";
import { BasicHandler } from "../../unifier/response-handler";
import { BasicSessionHandable } from "../../unifier/response-handler";
import { PlatformSession } from "./platform-session";
/**
@@ -20,7 +20,7 @@ export class CryptedPlatformSession extends PlatformSession {
* @param handler See PlatformSession
* @param configuredEncryptionKey Encryption key to use. If left out, a auto-generated one will be taken, which will live as long as the app runs
*/
constructor(extraction: OptionalExtractions.SessionData, handler: BasicHandler<any>, configuredEncryptionKey?: string) {
constructor(extraction: OptionalExtractions.SessionData, handler: BasicSessionHandable<any>, configuredEncryptionKey?: string) {
super(extraction, handler);
if (typeof configuredEncryptionKey === "string") {
Oops, something went wrong.

0 comments on commit 0d1b2c8

Please sign in to comment.