Permalink
Browse files

merges with develop

  • Loading branch information...
JanTrotnow committed Jan 7, 2019
2 parents fe62e43 + 7342b4d commit 7db29f1fa2426c9f0ec65f429d97150964a17849
Showing with 958 additions and 216 deletions.
  1. +6 −0 CHANGELOG
  2. +5 −6 scaffold/application-initializer.ts.scaffold
  3. +1 −1 scaffold/jasmine.json.scaffold
  4. +23 −0 scaffold/main.spec.ts.scaffold
  5. +1 −1 scaffold/main.ts.scaffold
  6. +1 −1 scaffold/package.json.scaffold
  7. +0 −20 scaffold/setup.js.scaffold
  8. +20 −0 scaffold/setup.ts.scaffold
  9. +31 −0 scaffold/this-context.ts.scaffold
  10. +1 −1 spec/components/integration/multiple-requests.spec.ts
  11. +1 −1 spec/components/state-machine/base-state.spec.ts
  12. +1 −1 spec/components/state-machine/filter-setup.spec.ts
  13. +1 −1 spec/components/state-machine/state-intent-setup.spec.ts
  14. +157 −2 spec/components/unifier/entity-dictionary.spec.ts
  15. +146 −0 spec/components/unifier/locales-loader.spec.ts
  16. +9 −2 spec/components/unifier/response-handler/handler-proxy-factory.spec.ts
  17. +15 −4 spec/components/unifier/response-handler/handler.spec.ts
  18. +1 −1 spec/helpers/setup.js
  19. +16 −0 spec/support/mocks/i18n/locale/de/entities.json
  20. +6 −0 spec/support/mocks/i18n/locale/de/utterances.json
  21. +16 −0 spec/support/mocks/i18n/locale/en/entities.js
  22. +3 −0 spec/support/mocks/i18n/locale/en/entities.json
  23. +3 −0 spec/support/mocks/i18n/locale/en/utterances.json
  24. +3 −0 spec/support/mocks/i18n/locale/en/utterances.ts
  25. +30 −0 spec/support/mocks/unifier/mock-locale-loader.ts
  26. +2 −1 spec/support/util/requester.ts
  27. +5 −3 spec/support/util/setup.ts
  28. +1 −1 src/assistant-source.ts
  29. +5 −1 src/cli.ts
  30. +4 −1 src/components/state-machine/execute-filters-hook.ts
  31. +8 −2 src/components/unifier/descriptor.ts
  32. +79 −16 src/components/unifier/entity-dictionary.ts
  33. +8 −58 src/components/unifier/generator.ts
  34. +102 −0 src/components/unifier/locales-loader.ts
  35. +1 −1 src/components/unifier/private-interfaces.ts
  36. +23 −5 src/components/unifier/public-interfaces.ts
  37. +7 −0 src/components/unifier/response-handler/basic-handler.ts
  38. +15 −14 src/components/unifier/response-handler/handler-proxy-factory.ts
  39. +13 −0 src/components/unifier/response-handler/handler-types.ts
  40. +1 −0 src/injection-names.ts
  41. +1 −4 src/setup.ts
  42. +186 −67 src/spec-helper.ts
@@ -1,4 +1,8 @@
version 0.4.0
- changes default behaviour of AssistantJSSetup's constructor to create a new container instead of using a global one. Removes global container.
- changes get() and getRaw() methods of entity dictionary: Now casting returned numbers to strings, aligning both methods to the already specified return type (string|undefined). Previously, if entities in request/extraction have been numbers, dictionary did not return them as string, resulting in unexpected/untyped behaviour.
- changes get() method of entity dictionary: If you are getting an assistantjs-configured custom entitiy and user passed a synonym of an entity value, get() automatically resolves to the entity value. Use getRaw() f you want to get the original passed value.
- changes get() method of entity dictionary: If you are getting an assistantjs-configured custom entitiy, get() now always return the value with the nearest levenshtein distance instead of the original value. If you want the original value, use getRaw() instead. For non-custom-entities, get() returns the regular value.
- adds listKeys and getSubset to session interface
- introduces translateHelper's getAllAlternatives() method which returns all alternatives instead of a sample one. Useful for suggestion chips etc and as an alternative to getTranslationValuesFor.
- changed the "assistant" binary to load the new application-initializer.js instead of index.js. To migrate, install the new assistant-source version globally.
@@ -8,6 +12,8 @@ version 0.4.0
- Remember that you need to set up a type mapping in your unifier configuration in config/components/unifier for your custom entities, too.
- You do not need to set up platform specific mappings (for dialogflow, alexa, ...) for your custom entities.
- On the other hand, if you set up a platform specific mapping, our generators will use this platform specific mapping instead of your custom entity. This enables you to use custom entities as a fallback for missing platform specific types. For example, if you use the AMAZON.US_CITY slot type, but don't find a corresponding dialogflow entity for it, you are able to create a custom entity as a dialogflow fallback.
- changed spec setup and made spec-helper more powerful. To make use of the improved spec setup in your 0.3.x project, create a new assistant js application and have a look at the generated spec setup.
- renames "specSetup" to "specHelper" and removes autoStart option of pretendIntentCalled() in PlatformSpecHelper interface (unifierInterfaces)
- removed index.ts and replaced it with application-initializer.ts to make the AssitantJS initialization process more adaptable. To migrate easily, create a new AssistantJS application, copy the created application-initializer.ts, paste it into your application and merge all locally made changes of your index.ts into your new application-initializer.ts
- renamed SpecSetup to SpecHelper
- new ResponsHandler: ResponseFactory and old Response-Types are obsolete now. A new ResponseHandler is introduced, which allows you the following:
@@ -52,6 +52,7 @@ export class ApplicationInitializer implements AssistantJSApplicationInitializer

// Create and prepare setup instances
const setups = this.createAndPrepareSetups();
setups.assistantJs.autobind();

// Create ServerApplication instance - you might want to pass your own express instance here!
const serverApplication = new ServerApplication(port);
@@ -67,6 +68,7 @@ export class ApplicationInitializer implements AssistantJSApplicationInitializer

// Create and prepare setup instances
const setups = this.createAndPrepareSetups();
setups.assistantJs.autobind();

// Create ServerApplication instance - you might want to pass your own express instance here!
const serverApplication = new GeneratorApplication(`${process.cwd()}/builds`);
@@ -81,24 +83,21 @@ export class ApplicationInitializer implements AssistantJSApplicationInitializer
return new AssistantJSSetup();
}

/** HELPER METHODS */

/** Creates all relevant setup instances for preparing our AssistantJS application */
private createAndPrepareSetups(): { assistantJs: AssistantJSSetup; stateMachine: StateMachineSetup; filter: FilterSetup } {
public createAndPrepareSetups(): { assistantJs: AssistantJSSetup; stateMachine: StateMachineSetup; filter: FilterSetup } {
// Create setup instances
const assistantJs = this.createAssistantJsSetup();
const setups = { assistantJs, stateMachine: new StateMachineSetup(assistantJs), filter: new FilterSetup(assistantJs) };

// Register all descriptors
this.initializeSetups(setups.assistantJs, setups.stateMachine, setups.filter);

// Bind everything to container
setups.assistantJs.autobind();

// Return all instances
return setups;
}

/** HELPER METHODS */

/**
* Configures current node process to print all unhandledRejections to console.
* You possibly want to set up your own behaviour here.
@@ -4,6 +4,6 @@
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
"helpers/**/*.ts"
]
}
@@ -0,0 +1,23 @@
import { MainState } from "../../../app/states/main";
import { ThisContext } from "../../support/this-context";

interface CurrentThisContext extends ThisContext {
currentState: MainState;
}

describe("MainState", function() {
beforeEach(async function(this: CurrentThisContext) {
this.specHelper.prepareSpec(this.defaultSpecOptions);
});

describe("#invokeGenericIntent", function() {
beforeEach(async function(this: CurrentThisContext) {
await this.specHelper.prepareIntentCall(this.platforms.alexa, "invokeGenericIntent"); // TODO: this.platforms.alexa doesn't exist yet, see setup.js!
this.responseResults = await this.specHelper.runMachineAndGetResults("MainState");
});

it("returns 'helloWorld'", async function(this: CurrentThisContext) {
expect(this.responseResults.voiceMessage!.text).toEqual("Hello World");
});
});
});
@@ -21,6 +21,6 @@ export class MainState extends ApplicationState {
* It is called as soon as the application is launched, e. g. if user says "launch xxxxx".
*/
public invokeGenericIntent(machine: Transitionable) {

this.endSessionWith("Hello World");
}
}
@@ -2,7 +2,7 @@
"name": "{{__NAME__}}",
"version": "0.1.0",
"description": "AssistantJS implementation of {{__NAME__}}",
"main": "js/index.js",
"main": "js/application-initializer.js",
"scripts": {
"test": "jasmine-ts spec/**/*.spec.ts"
},

This file was deleted.

Oops, something went wrong.
@@ -0,0 +1,20 @@
//tslint:disable-next-line
require("reflect-metadata");

import { SpecHelper } from "assistant-source";
import { ThisContext } from "../support/this-context";
import { ApplicationInitializer } from "../../application-initializer";

beforeEach(function(this: ThisContext) {
// Get application initializer and initializer main variables
this.applicationInitializer = new ApplicationInitializer();
this.setups = this.applicationInitializer.createAndPrepareSetups();
this.specHelper = new SpecHelper(this.setups.assistantJs, this.setups.stateMachine);
this.inversify = this.specHelper.assistantJs.container.inversifyInstance;

// Register all platforms. For every platform you install, you want to add an entry here.
this.platforms = {};

// Your default spec options which are passed into this.specHelper.prepareSpec()
this.defaultSpecOptions = {};
});
@@ -0,0 +1,31 @@
import { PlatformSpecHelper, SpecHelper, SpecHelperOptions } from "assistant-source";
import { interfaces as inversifyInterfaces } from "inversify";
import { ApplicationInitializer } from "../../application-initializer";
import { MergedAnswerTypes, MergedHandler } from "../../config/handler";

/** Use this context to describe your "this" in jasmine specs */
export interface ThisContext {
/** AssistantJS's spec helper, enables you to execute the state machine, prepare intent calls, and so on */
specHelper: SpecHelper;

/** References our ./application-initializer, useful for starting servers etc. */
applicationInitializer: ApplicationInitializer;

/** References different setup instances, equals the return of our ApplicationInitializer.createAndPrepareSetups method */
setups: ReturnType<ApplicationInitializer["createAndPrepareSetups"]>;

/** References our inversify container instance for easy dependency injection mocking. Abbrevation for setups.assistantJs.container.inversifyInstance */
inversify: inversifyInterfaces.Container;

/** References a platform spec helper for every platform you'd like to use. Use this as the first parameter for this.specHelper.prepareIntentCall() */
platforms: { [platformName: string]: PlatformSpecHelper<MergedAnswerTypes, MergedHandler> };

/** Default spec options to pass into specHelper.prepareSpec(). You might want to override some options per spec. */
defaultSpecOptions: Partial<SpecHelperOptions>;

/** Result of current intent call. Usage: this.responseResults = this.specHelper.runMachineAndGetResults(stateName) */
responseResults: Partial<MergedAnswerTypes>;

/** Use this for any untyped test params */
params: any;
}
@@ -13,7 +13,7 @@ describe("with child containers enabled", function() {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20000;

this.specHelper = createSpecHelper(true, true);
this.assistantJs = this.specHelper.setup;
this.assistantJs = this.specHelper.assistantJs;
this.container = this.assistantJs.container;

configureI18nLocale((this as any).container, false);
@@ -27,7 +27,7 @@ describe("BaseState", function() {
this.container.inversifyInstance.unbind(PLATFORM + ":current-response-handler");
this.container.inversifyInstance.bind(PLATFORM + ":current-response-handler").toDynamicValue(context => this.handler);

this.state = this.specHelper.setup.container.inversifyInstance.get<State.Factory>(injectionNames.stateFactory)<
this.state = this.specHelper.assistantJs.container.inversifyInstance.get<State.Factory>(injectionNames.stateFactory)<
BaseState<MockHandlerASpecificTypes, MockHandlerA<MockHandlerASpecificTypes>>
>("PlainState");
});
@@ -9,7 +9,7 @@ describe("FilterSetup", function() {

beforeEach(function() {
this.specHelper = createSpecHelper(false);
this.assistantJs = this.specHelper.setup;
this.assistantJs = this.specHelper.assistantJs;
this.container = this.assistantJs.container;

createRequestScope(this.specHelper);
@@ -14,7 +14,7 @@ describe("StateMachineSetup", function() {

beforeEach(function() {
this.specHelper = createSpecHelper(false);
this.assistantJs = this.specHelper.setup;
this.assistantJs = this.specHelper.assistantJs;
this.container = this.assistantJs.container;

createRequestScope(this.specHelper);
Oops, something went wrong.

0 comments on commit 7db29f1

Please sign in to comment.