lexica-dialog-repository
Version:
149 lines • 3.71 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const mongoose_1 = require("mongoose");
const CRUDRepository_1 = require("./CRUDRepository");
const Intent_1 = require("lexica-dialog-model/dist/Intent");
const optionResponse = new mongoose_1.Schema({
command: {
required: true,
type: String,
},
features: {
required: true,
type: mongoose_1.Schema.Types.Mixed,
},
messages: {
required: true,
type: mongoose_1.Schema.Types.Mixed,
},
textOnlyIndicator: {
required: true,
type: String,
},
});
const itemResponse = new mongoose_1.Schema({
messages: {
required: true,
type: mongoose_1.Schema.Types.Mixed,
},
type: {
enum: [Intent_1.ItemType.AUDIO, Intent_1.ItemType.FILE, Intent_1.ItemType.IMAGE, Intent_1.ItemType.VIDEO],
required: true,
type: String,
},
url: {
required: true,
type: String,
},
});
const response = new mongoose_1.Schema({
forceShow: {
required: false,
type: Boolean,
},
items: {
required() {
return this.type === Intent_1.ResponseType.ITEMS;
},
type: [itemResponse],
},
messages: {
required: true,
type: mongoose_1.Schema.Types.Mixed,
},
options: {
type: [optionResponse],
required() {
return this.type === Intent_1.ResponseType.OPTIONS;
},
},
type: {
enum: [
Intent_1.ResponseType.TEXT,
Intent_1.ResponseType.ITEMS,
Intent_1.ResponseType.OPTIONS,
],
required: true,
type: String,
},
});
exports.response = response;
const intentSchema = new mongoose_1.Schema({
category: {
required: true,
type: String,
},
command: {
index: true,
required: true,
type: String,
},
defaultFeatures: {
required: false,
type: mongoose_1.Schema.Types.Mixed,
},
executors: {
required: false,
type: [String],
},
fallbackCommand: {
required: false,
type: String,
},
// TODO, current mongoose dose not support dynamic key value type
missingFeatures: mongoose_1.Schema.Types.Mixed,
postProcessors: {
required: false,
type: [String],
},
preProcessors: {
required: false,
type: [String],
},
requiredFeatureKeys: {
required: false,
type: [String],
},
responses: {
required: true,
type: [response],
},
sampleQuestion: {
type: String,
required() {
return this.category !== 'HIDDEN';
},
},
sessionExpire: {
required: false,
type: Number,
},
subCategory: {
required() {
return this.category !== 'HIDDEN';
},
type: String,
},
uni: {
index: true,
required: true,
type: String,
},
});
exports.intentSchema = intentSchema;
intentSchema.index({ uni: 1, command: 1 }, { unique: true });
class IntentRepository extends CRUDRepository_1.default {
constructor(mongoConnection) {
super(mongoConnection.model('Intent', intentSchema, 'Intents'));
}
async findByUniCommandName(uni, command) {
return this.model.findOne({ uni, command });
}
async findByUni(uni) {
return this.model.find({ uni });
}
}
exports.IntentRepository = IntentRepository;
const intentRepository = new IntentRepository(mongoose_1.connection);
exports.intentRepository = intentRepository;
//# sourceMappingURL=IntentRepository.js.map