@xapp/stentor-validation 1.32.145 → 1.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,18 @@
1
1
  /*! Copyright (c) 2021, XAPPmedia */
2
2
  import { Validator, ValidationResult } from "lakmus";
3
- import { Intent } from "stentor-models";
3
+ import { Intent, Slot } from "stentor-models";
4
+ export interface IntentValidatorState {
5
+ /**
6
+ * Slots that have been saved from previous Intents.
7
+ *
8
+ * @type {Slot}
9
+ * @memberof IntentValidatorState
10
+ */
11
+ slots: Slot[];
12
+ }
4
13
  export declare class IntentValidator extends Validator<Intent> {
5
- constructor();
14
+ private readonly slots;
15
+ constructor(state?: IntentValidatorState);
16
+ get state(): IntentValidatorState;
6
17
  validate(intent: Intent): ValidationResult;
7
18
  }
@@ -6,14 +6,21 @@ const lakmus_1 = require("lakmus");
6
6
  const stentor_interaction_model_1 = require("stentor-interaction-model");
7
7
  const UtteranceValidator_1 = require("./UtteranceValidator");
8
8
  class IntentValidator extends lakmus_1.Validator {
9
- constructor() {
9
+ constructor(state) {
10
10
  super();
11
+ this.slots = (state === null || state === void 0 ? void 0 : state.slots) || [];
11
12
  // Required fields
12
13
  this.ruleFor(x => x.intentId)
13
14
  .notNull()
14
15
  .notEmpty();
15
16
  }
17
+ get state() {
18
+ return {
19
+ slots: this.slots.slice()
20
+ };
21
+ }
16
22
  validate(intent) {
23
+ // ******************* validations for only the intent ***************
17
24
  const result = super.validate(intent);
18
25
  const utterances = new stentor_interaction_model_1.UtteranceGenerator().forIntent(intent);
19
26
  const slotNames = [];
@@ -26,22 +33,35 @@ class IntentValidator extends lakmus_1.Validator {
26
33
  slotNames.push(...stentor_interaction_model_1.getSlotNames(utterance));
27
34
  });
28
35
  }
29
- const slots = intent.slots || [];
36
+ const intentSlots = intent.slots || [];
30
37
  // Make sure we don't have any duplicate definitions
31
- const slotMap = {};
32
- slots.forEach((slot) => {
38
+ const slotMap = intentSlots.reduce((previous, slot) => {
33
39
  const name = slot.name;
34
- if (slotMap[name]) {
40
+ if (previous[name]) {
35
41
  result.errors.push(new lakmus_1.ValidationError(`Slot ${name} is defined more than once.`, "slots"));
36
42
  }
37
- slotMap[name] = slot;
38
- });
43
+ previous[name] = slot;
44
+ return previous;
45
+ }, {});
39
46
  // Every slot name needs a defined slot
40
47
  slotNames.forEach((slotName) => {
41
48
  if (!slotMap[slotName]) {
42
49
  result.errors.push(new lakmus_1.ValidationError(`Slot ${slotName} does not have a defined type.`));
43
50
  }
44
51
  });
52
+ // ******************************************************************
53
+ // ******************* validations across all intents ***************
54
+ this.slots.push(...intentSlots);
55
+ // eslint:disable
56
+ this.slots.forEach(slot => {
57
+ // Good news, everyone! We get to use the slot map from the previous validations
58
+ if (slotMap[slot.name]) {
59
+ if (slotMap[slot.name].type !== slot.type) {
60
+ result.errors.push(new lakmus_1.ValidationError(`Slot ${slot.name} is defined as two different types: Type 1: ${slotMap[slot.name].type} - Type 2: ${slot.type}`, "slots"));
61
+ }
62
+ }
63
+ });
64
+ // ******************************************************************
45
65
  return result;
46
66
  }
47
67
  }
@@ -1 +1 @@
1
- {"version":3,"file":"IntentValidator.js","sourceRoot":"","sources":["../src/IntentValidator.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;AAEpC,mCAAsE;AACtE,yEAA6E;AAE7E,6DAA0D;AAE1D,MAAa,eAAgB,SAAQ,kBAAiB;IAClD;QACI,KAAK,EAAE,CAAC;QAER,kBAAkB;QAClB,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;aACxB,OAAO,EAAE;aACT,QAAQ,EAAE,CAAC;IACpB,CAAC;IAEM,QAAQ,CAAC,MAAc;QAE1B,MAAM,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAEtC,MAAM,UAAU,GAAG,IAAI,8CAAkB,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAE9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AAC,CAAC,CAAC;QACH,qEAAqE;QAErE,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ;AA5ED,0CA4EC"}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "restricted"
6
6
  },
7
- "version": "1.32.145",
7
+ "version": "1.33.0",
8
8
  "description": "Model validation for Stentor",
9
9
  "types": "lib/index",
10
10
  "main": "lib/index",
@@ -15,16 +15,16 @@
15
15
  "node": "^10 || ^12 || ^14"
16
16
  },
17
17
  "devDependencies": {
18
- "@types/chai": "4.2.17",
18
+ "@types/chai": "4.2.19",
19
19
  "@types/mocha": "8.2.2",
20
20
  "@xapp/config": "0.2.3",
21
21
  "chai": "4.3.4",
22
- "mocha": "9.0.0",
23
- "stentor-guards": "1.42.15",
24
- "stentor-interaction-model": "1.42.16",
25
- "stentor-logger": "1.42.16",
22
+ "mocha": "9.0.1",
23
+ "stentor-guards": "1.42.17",
24
+ "stentor-interaction-model": "1.42.17",
25
+ "stentor-logger": "1.42.17",
26
26
  "stentor-models": "1.42.15",
27
- "stentor-utils": "1.42.16",
27
+ "stentor-utils": "1.42.17",
28
28
  "ts-node": "9.1.1",
29
29
  "typescript": "4.3.4"
30
30
  },
@@ -43,5 +43,5 @@
43
43
  "clean": "rm -rf ./lib/*",
44
44
  "test": "mocha --recursive -r ts-node/register \"./src/**/*.test.ts\""
45
45
  },
46
- "gitHead": "8003034a2d108ca26185855b1babe06d9deea22e"
46
+ "gitHead": "64e52de066b4bbc9fc91417bc758616620c39a65"
47
47
  }