Skip to content
Permalink
Browse files

Add parameters to EventHandlerRegistration

Deprecate paramsMaker

[changelog:deprecated] [changelog:added]
  • Loading branch information...
cdupuis committed Feb 3, 2019
1 parent 498bc1c commit 230db78e37e669ea8065b0ee5bc788e58f9cf117
Showing with 16 additions and 11 deletions.
  1. +5 −9 lib/api-helper/machine/handlerRegistrations.ts
  2. +11 −2 lib/api/registration/EventHandlerRegistration.ts
@@ -15,6 +15,7 @@
*/

// tslint:disable:deprecation
// tslint:disable:max-file-line-count

import {
editModes,
@@ -110,8 +111,6 @@ import {
toMachineOptions,
} from "./toMachineOptions";

// tslint:disable:max-file-line-count

export const GeneratorTag = "generator";
export const InspectionTag = "inspection";
export const TransformTag = "transform";
@@ -277,6 +276,7 @@ export function commandHandlerRegistrationToCommand<P = NoParameters>(sdm: Machi
}

export function eventHandlerRegistrationToEvent(sdm: MachineOrMachineOptions, e: EventHandlerRegistration<any, any>): Maker<HandleEvent> {
addParametersDefinedInBuilder(e);
return () => eventHandlerFrom(
e.listener,
e.paramsMaker || NoParameters,
@@ -385,13 +385,8 @@ function addParametersDefinedInBuilder<PARAMS>(c: CommandRegistration<PARAMS>):
const oldMaker = c.paramsMaker || NoParameters;
if (!!c.parameters) {
c.paramsMaker = () => {
let paramsInstance;
if (!!oldMaker) {
paramsInstance = toFactory(oldMaker)();
} else {
paramsInstance = {};
paramsInstance.__kind = "command-handler";
}
const paramsInstance: any = toFactory(oldMaker)();

const paramListing = toParametersListing(c.parameters as any);
paramListing.parameters.forEach(p => {
paramsInstance[p.name] = p.defaultValue;
@@ -403,6 +398,7 @@ function addParametersDefinedInBuilder<PARAMS>(c: CommandRegistration<PARAMS>):
declareSecret(paramsInstance, s.name, s.uri));
paramListing.values.forEach(v =>
declareValue(paramsInstance, v.name, { path: v.path, required: v.required, type: v.type }));

return paramsInstance;
};
}
@@ -16,13 +16,15 @@

import {
Maker,
NoParameters,
OnEvent,
} from "@atomist/automation-client";
import { ParametersDefinition } from "./ParametersDefinition";

/**
* Type for registering event handlers.
*/
export interface EventHandlerRegistration<EVENT = any, PARAMS = any> {
export interface EventHandlerRegistration<EVENT = any, PARAMS = NoParameters> {

/**
* Name of the event handler.
@@ -41,16 +43,23 @@ export interface EventHandlerRegistration<EVENT = any, PARAMS = any> {

/**
* GraphQL subscription to subscribe this listener to.
* Note: Use subscription() methods of automation-client to create the subscription string
* Note: Use GraphQL.subscription() methods of automation-client to create the subscription string
*/
subscription: string;

/**
* Create the parameters required by this command.
* Empty parameters will be returned by default.
* @deprecated use parameters
*/
paramsMaker?: Maker<PARAMS>;

/**
* Define parameters used by this command. Alternative to using
* paramsMaker: Do not supply both.
*/
parameters?: ParametersDefinition<PARAMS>;

/**
* Listener to receive subscription matches.
*/

0 comments on commit 230db78

Please sign in to comment.
You can’t perform that action at this time.