1 | 'use strict';
|
2 | const _ = require('lodash');
|
3 | const builtInSlotsMap = require('./built-in-slots-map');
|
4 | const validator = require('./validator');
|
5 | const builtInSlotsValues = _.values(builtInSlotsMap);
|
6 | const parseError = require('./error-handler').parseError;
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | module.exports = (customSlots, name, samples) => {
|
15 |
|
16 | if (customSlots[name]) {
|
17 | const e = parseError(new Error(`Slot with name ${name} is already defined`));
|
18 | throw e;
|
19 | }
|
20 |
|
21 | if (builtInSlotsMap[name] || builtInSlotsValues.indexOf(name) !== -1) {
|
22 | const e = parseError(new Error(`Slot with name ${name} is already defined in built-in slots`));
|
23 | throw e;
|
24 | }
|
25 |
|
26 | if (!validator.isCustomSlotNameValid(name)) {
|
27 | const e = parseError(new Error(`Custom slot name ${name} is invalid. Only lowercase, uppercase letters and underscores are allowed`));
|
28 | throw e;
|
29 | }
|
30 |
|
31 | samples.forEach(sample => {
|
32 | if (validator.isCustomSlotValueValid(sample)) {
|
33 | const e = parseError(new Error(`Custom slot with name ${name} contains invalid special character(~, ^, *, (, ), [, ], §, !, ?, ;, :, " and |): ${sample}`));
|
34 | throw e;
|
35 | }
|
36 | });
|
37 |
|
38 | return {
|
39 | name,
|
40 | samples
|
41 | };
|
42 | };
|