@amaabca/aws-lex-custom-resources
Version:
AWS Lex infrastructure as code via the CDK
54 lines (53 loc) • 1.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const __1 = require("..");
class default_1 {
constructor(props) {
this.props = props;
this.intents = [];
this.slotTypes = [];
}
addSlotType(slotTypeProps) {
// check if a slottype with this name already exists
let exists = false;
for (let i = 0; i < this.slotTypes.length; i++) {
if (this.slotTypes[i].props.slotTypeName === slotTypeProps.slotTypeName) {
exists = true;
break;
}
}
if (exists) {
throw new Error(`A slot type with the name ${slotTypeProps.slotTypeName} already exists!`);
}
else {
const slotType = new __1.LexSlotType(slotTypeProps);
this.slotTypes.push(slotType);
return slotType;
}
}
addIntent(intentProps) {
// check if a slottype with this name already exists
let exists = false;
for (let i = 0; i < this.intents.length; i++) {
if (this.intents[i].props.intentName === intentProps.intentName) {
exists = true;
break;
}
}
if (exists) {
throw new Error(`An intent with the name ${intentProps.intentName} already exists!`);
}
else {
const intent = new __1.LexIntent(intentProps);
this.intents.push(intent);
return intent;
}
}
definition() {
const configuration = { ...this.props };
configuration['CR.slotTypes'] = this.slotTypes.map((s) => s.definition());
configuration['CR.intents'] = this.intents.map((i) => i.definition());
return configuration;
}
}
exports.default = default_1;