Files
jibo-cli/node_modules/jibo-kb/lib/jibo-kb.js

10 lines
34 KiB
JavaScript
Raw Normal View History

/**
* jibo-kb - Jibo Knowledge Base
* @version v4.3.4
* @license Copyright (c) 2017, Jibo, Inc. All rights reserved.
* All use of the Jibo SDK is subject to the Jibo SDK End User License Agreement (EULA)
* distributed herewith. If you did not receive a copy of the EULA, you may view a
* copy at https://developers.jibo.com/license.
*/
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.jiboKb=t()}}(function(){return function t(e,o,r){function i(s,a){if(!o[s]){if(!e[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(n)return n(s,!0);var l=new Error("Cannot find module '"+s+"'");throw l.code="MODULE_NOT_FOUND",l}var f=o[s]={exports:{}};e[s][0].call(f.exports,function(t){var o=e[s][1][t];return i(o?o:t)},f,f.exports,t,e,o,r)}return o[s].exports}for(var n="function"==typeof require&&require,s=0;s<r.length;s++)i(r[s]);return i}({1:[function(t,e,o){"use strict";var r=this&&this.__decorate||function(t,e,o,r){var i,n=arguments.length,s=n<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,o,r);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(s=(n<3?i(s):n>3?i(e,o,s):i(e,o))||s);return n>3&&s&&Object.defineProperty(e,o,s),s},i=t("fs-extra"),n=t("path"),s=t("stream"),a=t("request"),u=t("url"),l=t("uuid"),f=t("blob-to-buffer"),c=t("./decorators"),d=t("jibo-log"),p=new d("Asset"),h=function(){function t(t,e,o){t?this.setSelfFromFilenameOrURL(t):(this._id=l.v4(),this.subtype=e||"asset",this.ext=o)}return t.prototype.setRootDir=function(t){this.rootDir=t},t.prototype.filename=function(){var t=this._id+"."+this.subtype;return this.ext&&(t+="."+this.ext),t},t.prototype.fullFilenameOrURL=function(){if(!this.rootDir)throw new Error("asset rootDir not set");var t;return this.rootDir.startsWith("http://")?t=this._url():(t=this.filename(),t=n.join(this.rootDir,"assets",t)),t},t.prototype.toString=function(){return this.fullFilenameOrURL()},t.prototype.save=function(t,e){var o=this;this.rootDir.startsWith("http://")?t instanceof Buffer||t instanceof s.Stream?this._saveViaWeb(t,e):f(t,function(t,r){p.iferr(t,"blobToBuffer"),t?e(t):o._saveViaWeb(r,e)}):t instanceof Buffer?this._saveBuffer(t,e):t instanceof s.Stream?this._saveStream(t,e):f(t,function(t,r){p.iferr(t,"blobToBuffer"),t?e(t):o._saveBuffer(r,e)})},t.prototype.setSelfFromFilenameOrURL=function(t){t.startsWith("http://")?this._setSelfFromURL(t):this._setSelfFromFilename(t)},t.prototype.load=function(t){if(this.rootDir.startsWith("http://"))this._loadBufferViaWeb(t);else{var e=this.fullFilenameOrURL();i.readFile(e,function(o,r){p.iferr(o,"readFile on",e),t(o,r)})}},t.prototype.loadStream=function(){if(this.rootDir.startsWith("http://"))return this._loadStreamViaWeb();var t=this.fullFilenameOrURL();return i.createReadStream(t)},t.prototype.loadBlob=function(t){this.load(function(e,o){var r;p.iferr(e,"could not load asset file"),e||(r=new Blob(o,{type:"application/octet-binary"})),t(e,r)})},t.prototype.remove=function(t){if(this.rootDir.startsWith("http://"))this._removeViaWeb(t);else{var e=this.fullFilenameOrURL();p.info("removing asset file",e),i.unlink(e,function(o){p.iferr(o,"fs.unlink of",e),o||p.debug("asset file",e,"removed from disk"),t(o)})}},t.prototype._url=function(){if(!this.rootDir)throw new Error("asset rootDir not set");var t=this.filename();return this.rootDir+"/asset/"+t},t.prototype._saveViaWeb=function(t,e){var o=this,r=this._url(),i={body:t,headers:{"Content-Type":"application/octet-stream"}};a.post(r,i,function(t,i,n){t=o._checkStatusCode(t,i,n),p.iferr(t,"request.post",r),e(t,r)})},t.prototype._setSelfFromFilename=function(t){n.isAbsolute(t)&&(this.rootDir=n.dirname(n.dirname(t)),t=n.basename(t));var e=new RegExp("^([^.]*)[.]([^.]*)([.]([^.]*))?$"),o=t.match(e);if(!o)throw new Error("filename did not parse");this._id=o[1],this.subtype=o[2]||"",this.ext=o[4]||""},t.prototype._setSelfFromURL=function(t){var e=u.parse(t),o=e.pathname.split("/"),r=o.slice(0,3).join("/");this.rootDir="http://"+e.hostname+":"+e.port+"/"+r;var i=o[o.length-1];this._setSelfFromFilename(i)},t.prototype._removeViaWeb=function(t){var e=this,o=this._url();a.del(o,function(r,i,n){r=e._checkStatusCode(r,i,n),p
i.get(o,{json:!0},function(r,i,n){r=e._checkStatusCode(r,i,n),u.iferr(r,"request.get",o);var s;!r&&n&&(s=e.createNodeFromObject(n)),t(r,s)})},e.prototype.save=function(t,e){var o=this,r=this._makeUrl("/node/save");i.post(r,{json:t},function(t,i,n){t=o._checkStatusCode(t,i,n),u.iferr(t,"request.post",r),e&&e(t)})},e.prototype.remove=function(t,e){var o=this,r=this.toId(t),n=this._makeUrl("/node/remove/"+r);i.del(n,function(t,r,i){t=o._checkStatusCode(t,r,i),u.iferr(t,"request.delete",n),e(t)})},e.prototype.getDirectory=function(){return this._makeUrl()},e.prototype._makeUrl=function(t){void 0===t&&(t="");var e=n.escape(this.kbName);return this.httpUrl+"/v1/kb/"+e+t},e.prototype._checkStatusCode=function(t,e,o){if(void 0===o&&(o=null),!t&&(e.statusCode<200||e.statusCode>299)){var r="HTTP Error Code "+e.statusCode;o&&(r+=o),t=new Error(r)}return t},e}(s.default);Object.defineProperty(o,"__esModule",{value:!0}),o.default=l},{"./KnowledgeDatabase":6,"jibo-log":void 0,querystring:void 0,request:void 0}],12:[function(t,e,o){"use strict";function r(t,e,o){var r=o.value;return o.value=function(){var t,e=this,o=Array.from(arguments),i=o.slice(-1)[0];return t="function"==typeof i?r.apply(this,o):new Promise(function(t,i){var n=function(e,o){e?i(e):t(o)},s=o.concat(n);r.apply(e,s)})},o}function i(t,e,o){var r=o.value;return o.value=function(){var t,e=Array.from(arguments),o=e[4];if("function"==typeof o)t=r.apply(this,e);else{var i=this;t=new Promise(function(t,o){var n=function(e,r){e?o(e):t(r)},s=e.concat(n);r.apply(i,s)})}return t},o}o.promisify=r,o.promisify_4=i},{}],13:[function(t,e,o){"use strict";function r(t){for(var e in t)o.hasOwnProperty(e)||(o[e]=t[e])}r(t("./KnowledgeBase"));var i=t("./Asset");o.Asset=i.default;var n=t("./Cache");o.Cache=n.default;var s=t("./Database");o.Database=s.default;var a=t("./DatabaseManager");o.DatabaseManager=a.default;var u=t("./KnowledgeBase");o.KnowledgeBase=u.default;var l=t("./KnowledgeDatabase");o.KnowledgeDatabase=l.default;var f=t("./LoopModel");o.LoopModel=f.default;var c=t("./Model");o.Model=c.default;var d=t("./Node");o.Node=d.default;var p=t("./UserNode");o.UserNode=p.default;var h=t("./WebClient");o.WebClient=h.default},{"./Asset":1,"./Cache":2,"./Database":3,"./DatabaseManager":4,"./KnowledgeBase":5,"./KnowledgeDatabase":6,"./LoopModel":7,"./Model":8,"./Node":9,"./UserNode":10,"./WebClient":11}]},{},[13])(13)});