botbuilder-dialogs-adaptive
Version:
Rule system for the Microsoft BotBuilder dialog system.
83 lines • 3.43 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.EntityAssignment = void 0;
/**
* @module botbuilder-dialogs-adaptive
*/
/**
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
const isEqual_1 = __importDefault(require("lodash/isEqual"));
const entityInfo_1 = require("./entityInfo");
/**
* Static methods for working with `EntityAssignment` objects.
*/
class EntityAssignment {
/**
* Initializes a new instance of the [EntityAssignment](xref:botbuilder-dialogs-adaptive.EntityAssignment) class.
*
* @param assignment The entity assignment properties to set for this instance.
*/
constructor(assignment) {
var _a, _b, _c, _d, _e, _f, _g, _h;
// Some properties are defined by `<prop> ?? undefined` in order to pass object equality checks.
// Specifically, lodash's isEqual() will treat `{ a: undefined }` as not equal to `{ }`, so we explicitly add
// the properties as `undefined` in order to pass equality checks when the instances are semantically equal.
const newEntity = {
alternative: (_a = assignment.alternative) !== null && _a !== void 0 ? _a : undefined,
event: (_b = assignment.event) !== null && _b !== void 0 ? _b : undefined,
expectedProperties: (_c = assignment.expectedProperties) !== null && _c !== void 0 ? _c : [],
isExpected: (_d = assignment.isExpected) !== null && _d !== void 0 ? _d : undefined,
operation: (_e = assignment.operation) !== null && _e !== void 0 ? _e : undefined,
property: (_f = assignment.property) !== null && _f !== void 0 ? _f : undefined,
raisedCount: (_g = assignment.raisedCount) !== null && _g !== void 0 ? _g : undefined,
value: (_h = assignment.value) !== null && _h !== void 0 ? _h : undefined,
};
Object.assign(this, newEntity);
}
/**
* Gets the alternative entity assignments.
*
* @returns The alternative entity assigment.
*/
get alternatives() {
const alternatives = [];
// eslint-disable-next-line @typescript-eslint/no-this-alias
let current = this;
while (current) {
alternatives.push(current);
current = current.alternative;
}
return alternatives;
}
/**
* Add alternatives to a single assignment.
*
* @param alternatives Alternatives to add.
*/
addAlternatives(alternatives) {
// eslint-disable-next-line @typescript-eslint/no-this-alias
let current = this;
this.alternative = undefined;
alternatives.forEach((alternative) => {
if (!(0, isEqual_1.default)(this, alternative)) {
current.alternative = alternative;
current = alternative;
}
});
}
/**
* Print an assignment as a string.
*
* @returns A string that represents the current object.
*/
toString() {
return `${this.isExpected ? '+' : ''}${this.event}: ${this.property} = ${this.operation}(${entityInfo_1.EntityInfo.toString(this.value)})`;
}
}
exports.EntityAssignment = EntityAssignment;
//# sourceMappingURL=entityAssignment.js.map