Skip to content
Permalink
Browse files

Add support for latest Chooser API contract

Deprecated Chooser.pickOne and Chooser.choices

[changelog:deprecated] [changelog:changed]
  • Loading branch information...
cdupuis committed Jan 12, 2019
1 parent 9f03be4 commit 17549fdb9ba12b707898e8cfb49e1f1ba61c5d37
Showing with 54 additions and 10 deletions.
  1. +34 −3 lib/internal/metadata/metadataReading.ts
  2. +16 −3 lib/metadata/automationMetadata.ts
  3. +4 −4 lib/metadata/parameterUtils.ts
@@ -2,6 +2,8 @@ import * as _ from "lodash";
import { HandleCommand } from "../../HandleCommand";
import * as GraphQL from "../../internal/graph/graphQL";
import {
Choice,
Chooser,
CommandHandlerMetadata,
EventHandlerMetadata,
MappedParameterDeclaration,
@@ -106,7 +108,36 @@ function parametersFromInstance(r: any, prefix: string = ""): Parameter[] {
.map(nestedFieldInfo => parametersFromInstance(nestedFieldInfo[1], prefix + nestedFieldInfo[0] + ".")),
);

const allParameters = directParams.concat(nestedParameters);
const allParameters = directParams.concat(nestedParameters).map(p => {
if (!!p.type && p.type !== "boolean" && p.type !== "number" && p.type !== "string" && p.type !== "freeChoices") {
const chooser = p.type as Chooser;

let kind: "single" | "multiple" = "single";
if (chooser.pickOne !== undefined && chooser.pickOne !== null) {
kind = chooser.pickOne ? "single" : "multiple";
} else if (chooser.kind !== undefined && chooser.kind !== null) {
kind = chooser.kind;
}

let options: Choice[] = [];
if (chooser.choices !== undefined && chooser.choices !== null) {
options = chooser.choices;
} else if (chooser.options !== undefined && chooser.options !== null) {
options = chooser.options;
}

const newChooser: Chooser = {
kind,
options,
};
return {
...p,
type: newChooser,
};
} else {
return p;
}
});
return allParameters.sort((p1, p2) => {
const o1 = p1.order || Number.MAX_SAFE_INTEGER;
const o2 = p2.order || Number.MAX_SAFE_INTEGER;
@@ -143,7 +174,7 @@ function directParameters(r: any, prefix: string) {
}) : [];
}

function secretsMetadataFromInstance(r: any, prefix: string = "", visited: any[]= []): SecretDeclaration[] {
function secretsMetadataFromInstance(r: any, prefix: string = "", visited: any[] = []): SecretDeclaration[] {
visited.push(r);
const directSecrets = !!r && r.__secrets ? r.__secrets.map(s => ({ name: prefix + s.name, uri: s.uri })) : [];
const nestedParameters = _.flatten(Object.keys(r)
@@ -174,7 +205,7 @@ function mappedParameterMetadataFromInstance(r: any, prefix: string = "", visite
return directMappedParams.concat(nestedParameters);
}

function valueMetadataFromInstance(r: any, prefix: string = "", visited: any[] = []): ValueDeclaration[] {
function valueMetadataFromInstance(r: any, prefix: string = "", visited: any[] = []): ValueDeclaration[] {
visited.push(r);
const directValues = !!r && r.__values ? r.__values.map(mp =>
({
@@ -10,12 +10,25 @@ export interface Choice {
export interface Chooser {

/**
* Whether the user must pick exactly one choice. In this case,
* @deprecated use kind
*/
pickOne?: boolean;

/**
* Whether the user must select exactly one option. In this case,
* binds to string. Otherwise binds to string[]
*/
pickOne: boolean;
kind?: "single" | "multiple";

/**
* @deprecated use options
*/
choices?: Choice[];

choices: Choice[];
/**
* Possible options to select from
*/
options?: Choice[];
}

/**
@@ -2,14 +2,14 @@ import { Chooser } from "./automationMetadata";

export function someOf(...values: string[]): Chooser {
return {
pickOne: false,
choices: values.map(value => ({ value })),
kind: "multiple",
options: values.map(value => ({ value })),
};
}

export function oneOf(...values: string[]): Chooser {
return {
pickOne: true,
choices: values.map(value => ({ value })),
kind: "single",
options: values.map(value => ({ value })),
};
}

0 comments on commit 17549fd

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