Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

natty-db

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

natty-db - npm Package Compare versions

Comparing version 0.3.0 to 0.3.2

30

dist/natty-db.js

@@ -324,6 +324,9 @@ (function webpackUniversalModuleDefinition(root, factory) {

// 请求标记
config.mark = {};
if (config.mock) {
config.data.m = '1';
config.mark.m = '1';
}
config.data['__' + t.name + '.' + config.API + '()__'] = '';
config.mark['__' + t.name + '.' + config.API + '()__'] = '';

@@ -441,6 +444,7 @@ return config;

// 更新的请求标记
config.mark.retryTime = retryTime;
// `data`必须在请求发生时实时创建
data = extend({}, config.data, runAsFn(data, {
retryTime: retryTime
}));
data = extend({}, config.data, runAsFn(data));

@@ -460,7 +464,7 @@ // 根据`config`的差别 请求对象分为`ajax`和`jsonp`两种

//} else
if (config.jsonp) {
if (config.request) {
requester = config.request(data, config, defer, retryTime);
} else if (config.jsonp) {
requester = t.sendJSONP(data, config, defer, retryTime);
} else {
//C.log('send ajax');
requester = t.sendAjax(data, config, defer, retryTime);

@@ -560,2 +564,3 @@ }

cache: config.cache,
mark: config.mark,
log: config.log,

@@ -619,2 +624,3 @@ url: config.mock ? config.mockUrl : config.url,

log: config.log,
mark: config.mark,
url: config.mock ? config.mockUrl : config.url,

@@ -683,3 +689,3 @@ data: data,

var VERSION = undefined;
(VERSION = "0.3.0");
(VERSION = "0.3.2");

@@ -898,2 +904,3 @@ var NattyDB = {

url: '',
mark: {},
method: GET,

@@ -942,3 +949,3 @@ accept: TEXT,

xhr.open(options.method, appendQueryString(options.url, options.data, options.cache));
xhr.open(options.method, appendQueryString(options.url, extend({}, options.mark, options.method === GET ? options.data : {}), options.cache));

@@ -1169,2 +1176,3 @@ // NOTE 生产环境的Server端, `Access-Control-Allow-Origin`的值一定不要配置成`*`!!! 而且`Access-Control-Allow-Credentials`应该是true!!!

url: '',
mark: {},
data: {},

@@ -1205,3 +1213,3 @@ cache: true,

// 生成`url`
var url = appendQueryString(options.url, extend(_defineProperty({}, options.flag, callbackName), options.data), options.cache);
var url = appendQueryString(options.url, extend(_defineProperty({}, options.flag, callbackName), options.mark, options.data), options.cache);

@@ -1208,0 +1216,0 @@ // 插入脚本

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("RSVP")):"function"==typeof define&&define.amd?define(["RSVP"],t):"object"==typeof exports?exports.NattyDB=t(require("RSVP")):e.NattyDB=t(e.RSVP)}(this,function(e){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";e.exports=window.NattyDB=n(1)},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),a=n(2),i=n(3),s=n(5),c=n(4),u=c.extend,l=c.runAsFn,f=c.isAbsoluteUrl,p=c.isRelativeUrl,d=c.noop,m=c.isBoolean,h=c.isNumber,v=c.isArray;c.isCrossDomain;a.on("error",function(e){if(!window.console)throw new Error(e);console.error(e)});var g=null,y="",b=!0,x=!b,j={dummy:b};j.then=j["catch"]=j["finally"]=function(){return j};var k={cache:!1,data:{},fit:d,header:{},ignoreSelfConcurrent:x,jsonp:x,log:x,method:"GET",mock:x,mockUrl:y,mockUrlPrefix:y,process:d,retry:0,timeout:0,url:y,urlPrefix:y,withCredentials:g},w=u({},k),N=function(){function e(t,n,o){r(this,e);var a=this;a.context=o,a.cache={},a.name=t;for(var i in n)a[i]=a.createAPI(u({DBName:t,API:i},l(n[i])))}return o(e,[{key:"processAPIOptions",value:function(e){var t=this,n=u({},t.context,e);return n.pending=x,n.mock&&(n.method="GET",n.mockUrl=t.getFullUrl(n.mockUrl,!0)),n.url=t.getFullUrl(e.url),v(e.jsonp)&&(n.jsonp=m(e.jsonp[0])?e.jsonp[0]:x,n.jsonp&&(n.jsonpFlag=e.jsonp[1],n.jsonpCallbackName=e.jsonp[2])),n.url.match(/\.jsonp(\?.*)?$/)&&(n.jsonp=!0),n.mock&&(n.data.m="1"),n.data["__"+t.name+"."+n.API+"()__"]="",n}},{key:"createAPI",value:function(e){var t=this,n=t.processAPIOptions(e),r=function(e){return n.ignoreSelfConcurrent&&n.pending?j:0===n.retry?t.request(e,n):t.tryRequest(e,n)};return r.config=n,t.addLoopSupport(r),r}},{key:"addLoopSupport",value:function(e){var t=null;e.looping=x,e.startLoop=function(n){var r=arguments.length<=1||void 0===arguments[1]?d:arguments[1],o=arguments.length<=2||void 0===arguments[2]?d:arguments[2];if(!n.duration||!h(n.duration))throw new Error("Illegal `duration` value for `startLoop` method.");var a=function i(){e.looping=b,t=setTimeout(function(){e(n.data).then(r,o),i()},n.duration)};e(n.data).then(r,o),a()},e.stopLoop=function(){clearTimeout(t),e.looping=x,t=null}}},{key:"getFullUrl",value:function(e,t){if(!e)return y;var n=t?"mockUrlPrefix":"urlPrefix";return!this.context[n]||f(e)||p(e)?e:this.context[n]+e}},{key:"request",value:function(e,t,n){var r=this;e=u({},t.data,l(e,{retryTime:n}));var o=void 0;t.pending=b;var i=a.defer();return o=t.jsonp?r.sendJSONP(e,t,i,n):r.sendAjax(e,t,i,n),0!==t.timeout&&setTimeout(function(){t.pending&&(o.abort(),i.reject({timeout:b,message:"Timeout By "+t.timeout+"ms."}))},t.timeout),i.promise}},{key:"tryRequest",value:function(e,t){var n=this,r=a.defer(),o=0,i=function s(){n.request(e,t,o).then(function(e){r.resolve(e)},function(e){o===t.retry?r.reject(e):(o++,s())})};return i(),r.promise}},{key:"processResponse",value:function(e,t,n){if(t=e.fit(t),t.success){var r=e.process(t.content);n.resolve(r)}else n.reject(u({message:"Processing Failed Within "+e.DBName+"."+e.API},t.error))}},{key:"sendAjax",value:function(e,t,n,r){var o=this;return i({cache:t.cache,log:t.log,url:t.mock?t.mockUrl:t.url,method:t.method,data:e,header:t.header,withCredentials:t.withCredentials,accept:"json",success:function(e){o.processResponse(t,e,n)},error:function(e){var t=void 0;switch(e){case 404:t="Not Found";break;case 500:t="Internal Server Error";break;default:t="Unknown Server Error"}n.reject({status:e,message:t})},complete:function(){(void 0===r||r===t.retry)&&(t.pending=x)}})}},{key:"sendJSONP",value:function(e,t,n,r){var o=this;return s({log:t.log,url:t.mock?t.mockUrl:t.url,data:e,cache:t.cache,flag:t.jsonpFlag,callbackName:t.jsonpCallbackName,success:function(e){o.processResponse(t,e,n)},error:function(e){n.reject({message:"Not Accessable JSONP `"})},complete:function(){(void 0===r||r===t.retry)&&(t.pending=x)}})}}]),e}(),P=function(){function e(t){r(this,e);var n=this;n.config=u({},w,t)}return o(e,[{key:"create",value:function(e,t){var n=this;if(n[e])throw new Error('DB: "'+e+'" is existed! ');return n[e]=new N(e,t,n.config)}}]),e}(),C=void 0;C="0.3.0";var R={onlyForHTML5:b,version:C,Context:P,_util:c,ajax:i,jsonp:s,setGlobal:function(e){w=u({},k,e)},getGlobal:function(e){return e?w[e]:w}};R.setGlobal(k),e.exports=R},function(e,t){e.exports=RSVP},function(e,t,n){"use strict";var r=n(4),o=r.extend,a=r.appendQueryString,i=r.noop,s=r.isCrossDomain,c=r.isBoolean,u=(document,!1),l=null,f="GET",p="script",d="xml",m="text",h="json",v="application/json",g="text/html",y="withCredentials"in new XMLHttpRequest,b={script:"text/javascript, application/javascript, application/x-javascript",json:v,xml:"application/xml, text/xml",html:g,text:"text/plain"},x=function(e,t){s(t.url)||e.setRequestHeader("X-Requested-With","XMLHttpRequest"),e.setRequestHeader("Accept",b[t.accept]||"*/*");for(var n in t.header)e.setRequestHeader(n,t.header[n]);"POST"!==t.method||t.header["Content-Type"]||e.setRequestHeader("Content-Type","application/x-www-form-urlencoded")},j=function(e,t){e.__finished=u;var n=function(n){if(4===e.readyState)if(e.status>=200&&e.status<300||304===e.status){var r=e.responseText;switch(t.accept){case h:try{r=JSON.parse(r)}catch(n){console.warn("The response can NOT be parsed to JSON object.",r)}break;case p:(1,eval)(r);break;case d:r=e.responseXML}t.success(r,e)}else!e.__aborted&&t.error(e.status,e)};e.addEventListener("readystatechange",n);var r=function(){e.__finished||t.abort(e.status,e)};e.addEventListener("abort",r);var o=function(){e.__finished||(e.__finished=!0,t.complete(e.status,e),delete e.__aborted)};e.addEventListener("loadend",o)},k={url:"",method:f,accept:m,data:null,header:{},withCredentials:l,cache:!0,success:i,error:i,complete:i,abort:i,log:u},w=function(e){e=o({},k,e),s(e.url)&&(e.header={});var t=new XMLHttpRequest;j(t,e),t.open(e.method,a(e.url,e.data,e.cache)),t.withCredentials=c(e.withCredentials)?e.withCredentials:s(e.url),x(t,e),t.send(e.method===f?l:e.data!==l?JSON.stringify(e.data):l);var n=t.abort;return t.abort=function(){t.__aborted=!0,n.call(t)},t};w.fallback=!1,w.supportCORS=y,e.exports=w},function(e,t,n){"use strict";var r=document,o=function(e){return e},a=function(e){return function(){for(var t=arguments,n=e(t[0],t[1]),r=2,o=t.length;o>r;r++)n=e(n,t[r]);return n}},i=Math.random,s=Math.floor,c=function(){return s(9e9*i())},u=encodeURIComponent,l=function(e,t,n){var r=[];!n&&r.push("noCache="+c());for(var o in t)t.hasOwnProperty(o)&&r.push(u(o)+"="+u(t[o]));return r.length?e+(~e.indexOf("?")?"&":"?")+r.join("&"):e},f=/^(https?:)?\/\//,p=function(e){return!!e.match(f)},d=/^[\.\/]/,m=function(e){return!!e.match(d)},h="boolean",v=function(e){return typeof e===h},g="function",y=function(e){return typeof e===g},b=function(e,t){return y(e)?e(t):e},x="number",j=function(e){return!isNaN(e)&&typeof e===x},k=Array.isArray,w=r.createElement("a");w.href=window.location.href;var N=function(e){var t=r.createElement("a");return t.href=e,w.protocol+"//"+w.host!=t.protocol+"//"+t.host},P=function C(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];for(var n in t)t.hasOwnProperty(n)&&void 0!==t[n]&&(k(t[n])?e[n]=[].concat(t[n]):"object"==typeof t[n]?e[n]=C({},t[n]):e[n]=t[n]);return e};e.exports={extend:a(P),makeRandom:c,appendQueryString:l,noop:o,isCrossDomain:N,isAbsoluteUrl:p,isRelativeUrl:m,isBoolean:v,isFunction:y,isNumber:j,isArray:k,runAsFn:b}},function(e,t,n){"use strict";function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var o=n(4),a=o.appendQueryString,i=o.noop,s=o.extend,c=o.makeRandom,u=window,l=document,f=null,p="script",d=function(e){e.onerror=f,e.parentNode.removeChild(e),e=f},m=f,h=function(e,t){var n=l.createElement(p);return n.src=e,n.async=!0,n.onerror=function(e){u[t.callbackName]=f,t.error(e),t.complete()},m=m||l.getElementsByTagName("head")[0],m.insertBefore(n,m.firstChild),n},v={url:"",data:{},cache:!0,success:i,error:i,complete:i,log:!1,flag:"callback",callbackName:"jsonp{id}"},g=function(e){e=s({},v,e);var t=e.callbackName=e.callbackName.replace(/\{id\}/,c()),n=e.complete,o=void 0;e.complete=function(){d(o),n()},u[t]=function(n){u[t]=f,e.success(n),e.complete()};var i=a(e.url,s(r({},e.flag,t),e.data),e.cache);return o=h(i,e),{abort:function(){u[t]=function(){u[t]=f},d(o)}}};e.exports=g}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("RSVP")):"function"==typeof define&&define.amd?define(["RSVP"],t):"object"==typeof exports?exports.NattyDB=t(require("RSVP")):e.NattyDB=t(e.RSVP)}(this,function(e){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";e.exports=window.NattyDB=r(1)},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=r(2),i=r(3),s=r(5),c=r(4),u=c.extend,l=c.runAsFn,f=c.isAbsoluteUrl,p=c.isRelativeUrl,d=c.noop,m=c.isBoolean,h=c.isNumber,v=c.isArray;c.isCrossDomain;a.on("error",function(e){if(!window.console)throw new Error(e);console.error(e)});var g=null,y="",k=!0,b=!k,x={dummy:k};x.then=x["catch"]=x["finally"]=function(){return x};var j={cache:!1,data:{},fit:d,header:{},ignoreSelfConcurrent:b,jsonp:b,log:b,method:"GET",mock:b,mockUrl:y,mockUrlPrefix:y,process:d,retry:0,timeout:0,url:y,urlPrefix:y,withCredentials:g},w=u({},j),N=function(){function e(t,r,o){n(this,e);var a=this;a.context=o,a.cache={},a.name=t;for(var i in r)a[i]=a.createAPI(u({DBName:t,API:i},l(r[i])))}return o(e,[{key:"processAPIOptions",value:function(e){var t=this,r=u({},t.context,e);return r.pending=b,r.mock&&(r.method="GET",r.mockUrl=t.getFullUrl(r.mockUrl,!0)),r.url=t.getFullUrl(e.url),v(e.jsonp)&&(r.jsonp=m(e.jsonp[0])?e.jsonp[0]:b,r.jsonp&&(r.jsonpFlag=e.jsonp[1],r.jsonpCallbackName=e.jsonp[2])),r.url.match(/\.jsonp(\?.*)?$/)&&(r.jsonp=!0),r.mark={},r.mock&&(r.mark.m="1"),r.mark["__"+t.name+"."+r.API+"()__"]="",r}},{key:"createAPI",value:function(e){var t=this,r=t.processAPIOptions(e),n=function(e){return r.ignoreSelfConcurrent&&r.pending?x:0===r.retry?t.request(e,r):t.tryRequest(e,r)};return n.config=r,t.addLoopSupport(n),n}},{key:"addLoopSupport",value:function(e){var t=null;e.looping=b,e.startLoop=function(r){var n=arguments.length<=1||void 0===arguments[1]?d:arguments[1],o=arguments.length<=2||void 0===arguments[2]?d:arguments[2];if(!r.duration||!h(r.duration))throw new Error("Illegal `duration` value for `startLoop` method.");var a=function i(){e.looping=k,t=setTimeout(function(){e(r.data).then(n,o),i()},r.duration)};e(r.data).then(n,o),a()},e.stopLoop=function(){clearTimeout(t),e.looping=b,t=null}}},{key:"getFullUrl",value:function(e,t){if(!e)return y;var r=t?"mockUrlPrefix":"urlPrefix";return!this.context[r]||f(e)||p(e)?e:this.context[r]+e}},{key:"request",value:function(e,t,r){var n=this;t.mark.retryTime=r,e=u({},t.data,l(e));var o=void 0;t.pending=k;var i=a.defer();return o=t.request?t.request(e,t,i,r):t.jsonp?n.sendJSONP(e,t,i,r):n.sendAjax(e,t,i,r),0!==t.timeout&&setTimeout(function(){t.pending&&(o.abort(),i.reject({timeout:k,message:"Timeout By "+t.timeout+"ms."}))},t.timeout),i.promise}},{key:"tryRequest",value:function(e,t){var r=this,n=a.defer(),o=0,i=function s(){r.request(e,t,o).then(function(e){n.resolve(e)},function(e){o===t.retry?n.reject(e):(o++,s())})};return i(),n.promise}},{key:"processResponse",value:function(e,t,r){if(t=e.fit(t),t.success){var n=e.process(t.content);r.resolve(n)}else r.reject(u({message:"Processing Failed Within "+e.DBName+"."+e.API},t.error))}},{key:"sendAjax",value:function(e,t,r,n){var o=this;return i({cache:t.cache,mark:t.mark,log:t.log,url:t.mock?t.mockUrl:t.url,method:t.method,data:e,header:t.header,withCredentials:t.withCredentials,accept:"json",success:function(e){o.processResponse(t,e,r)},error:function(e){var t=void 0;switch(e){case 404:t="Not Found";break;case 500:t="Internal Server Error";break;default:t="Unknown Server Error"}r.reject({status:e,message:t})},complete:function(){(void 0===n||n===t.retry)&&(t.pending=b)}})}},{key:"sendJSONP",value:function(e,t,r,n){var o=this;return s({log:t.log,mark:t.mark,url:t.mock?t.mockUrl:t.url,data:e,cache:t.cache,flag:t.jsonpFlag,callbackName:t.jsonpCallbackName,success:function(e){o.processResponse(t,e,r)},error:function(e){r.reject({message:"Not Accessable JSONP `"})},complete:function(){(void 0===n||n===t.retry)&&(t.pending=b)}})}}]),e}(),P=function(){function e(t){n(this,e);var r=this;r.config=u({},w,t)}return o(e,[{key:"create",value:function(e,t){var r=this;if(r[e])throw new Error('DB: "'+e+'" is existed! ');return r[e]=new N(e,t,r.config)}}]),e}(),C=void 0;C="0.3.2";var R={onlyForHTML5:k,version:C,Context:P,_util:c,ajax:i,jsonp:s,setGlobal:function(e){w=u({},j,e)},getGlobal:function(e){return e?w[e]:w}};R.setGlobal(j),e.exports=R},function(e,t){e.exports=RSVP},function(e,t,r){"use strict";var n=r(4),o=n.extend,a=n.appendQueryString,i=n.noop,s=n.isCrossDomain,c=n.isBoolean,u=(document,!1),l=null,f="GET",p="script",d="xml",m="text",h="json",v="application/json",g="text/html",y="withCredentials"in new XMLHttpRequest,k={script:"text/javascript, application/javascript, application/x-javascript",json:v,xml:"application/xml, text/xml",html:g,text:"text/plain"},b=function(e,t){s(t.url)||e.setRequestHeader("X-Requested-With","XMLHttpRequest"),e.setRequestHeader("Accept",k[t.accept]||"*/*");for(var r in t.header)e.setRequestHeader(r,t.header[r]);"POST"!==t.method||t.header["Content-Type"]||e.setRequestHeader("Content-Type","application/x-www-form-urlencoded")},x=function(e,t){e.__finished=u;var r=function(r){if(4===e.readyState)if(e.status>=200&&e.status<300||304===e.status){var n=e.responseText;switch(t.accept){case h:try{n=JSON.parse(n)}catch(r){console.warn("The response can NOT be parsed to JSON object.",n)}break;case p:(1,eval)(n);break;case d:n=e.responseXML}t.success(n,e)}else!e.__aborted&&t.error(e.status,e)};e.addEventListener("readystatechange",r);var n=function(){e.__finished||t.abort(e.status,e)};e.addEventListener("abort",n);var o=function(){e.__finished||(e.__finished=!0,t.complete(e.status,e),delete e.__aborted)};e.addEventListener("loadend",o)},j={url:"",mark:{},method:f,accept:m,data:null,header:{},withCredentials:l,cache:!0,success:i,error:i,complete:i,abort:i,log:u},w=function(e){e=o({},j,e),s(e.url)&&(e.header={});var t=new XMLHttpRequest;x(t,e),t.open(e.method,a(e.url,o({},e.mark,e.method===f?e.data:{}),e.cache)),t.withCredentials=c(e.withCredentials)?e.withCredentials:s(e.url),b(t,e),t.send(e.method===f?l:e.data!==l?JSON.stringify(e.data):l);var r=t.abort;return t.abort=function(){t.__aborted=!0,r.call(t)},t};w.fallback=!1,w.supportCORS=y,e.exports=w},function(e,t,r){"use strict";var n=document,o=function(e){return e},a=function(e){return function(){for(var t=arguments,r=e(t[0],t[1]),n=2,o=t.length;o>n;n++)r=e(r,t[n]);return r}},i=Math.random,s=Math.floor,c=function(){return s(9e9*i())},u=encodeURIComponent,l=function(e,t,r){var n=[];!r&&n.push("noCache="+c());for(var o in t)t.hasOwnProperty(o)&&n.push(u(o)+"="+u(t[o]));return n.length?e+(~e.indexOf("?")?"&":"?")+n.join("&"):e},f=/^(https?:)?\/\//,p=function(e){return!!e.match(f)},d=/^[\.\/]/,m=function(e){return!!e.match(d)},h="boolean",v=function(e){return typeof e===h},g="function",y=function(e){return typeof e===g},k=function(e,t){return y(e)?e(t):e},b="number",x=function(e){return!isNaN(e)&&typeof e===b},j=Array.isArray,w=n.createElement("a");w.href=window.location.href;var N=function(e){var t=n.createElement("a");return t.href=e,w.protocol+"//"+w.host!=t.protocol+"//"+t.host},P=function C(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];for(var r in t)t.hasOwnProperty(r)&&void 0!==t[r]&&(j(t[r])?e[r]=[].concat(t[r]):"object"==typeof t[r]?e[r]=C({},t[r]):e[r]=t[r]);return e};e.exports={extend:a(P),makeRandom:c,appendQueryString:l,noop:o,isCrossDomain:N,isAbsoluteUrl:p,isRelativeUrl:m,isBoolean:v,isFunction:y,isNumber:x,isArray:j,runAsFn:k}},function(e,t,r){"use strict";function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var o=r(4),a=o.appendQueryString,i=o.noop,s=o.extend,c=o.makeRandom,u=window,l=document,f=null,p="script",d=function(e){e.onerror=f,e.parentNode.removeChild(e),e=f},m=f,h=function(e,t){var r=l.createElement(p);return r.src=e,r.async=!0,r.onerror=function(e){u[t.callbackName]=f,t.error(e),t.complete()},m=m||l.getElementsByTagName("head")[0],m.insertBefore(r,m.firstChild),r},v={url:"",mark:{},data:{},cache:!0,success:i,error:i,complete:i,log:!1,flag:"callback",callbackName:"jsonp{id}"},g=function(e){e=s({},v,e);var t=e.callbackName=e.callbackName.replace(/\{id\}/,c()),r=e.complete,o=void 0;e.complete=function(){d(o),r()},u[t]=function(r){u[t]=f,e.success(r),e.complete()};var i=a(e.url,s(n({},e.flag,t),e.mark,e.data),e.cache);return o=h(i,e),{abort:function(){u[t]=function(){u[t]=f},d(o)}}};e.exports=g}])});

@@ -324,6 +324,9 @@ (function webpackUniversalModuleDefinition(root, factory) {

// 请求标记
config.mark = {};
if (config.mock) {
config.data.m = '1';
config.mark.m = '1';
}
config.data['__' + t.name + '.' + config.API + '()__'] = '';
config.mark['__' + t.name + '.' + config.API + '()__'] = '';

@@ -441,6 +444,7 @@ return config;

// 更新的请求标记
config.mark.retryTime = retryTime;
// `data`必须在请求发生时实时创建
data = extend({}, config.data, runAsFn(data, {
retryTime: retryTime
}));
data = extend({}, config.data, runAsFn(data));

@@ -460,7 +464,7 @@ // 根据`config`的差别 请求对象分为`ajax`和`jsonp`两种

//} else
if (config.jsonp) {
if (config.request) {
requester = config.request(data, config, defer, retryTime);
} else if (config.jsonp) {
requester = t.sendJSONP(data, config, defer, retryTime);
} else {
//C.log('send ajax');
requester = t.sendAjax(data, config, defer, retryTime);

@@ -560,2 +564,3 @@ }

cache: config.cache,
mark: config.mark,
log: config.log,

@@ -619,2 +624,3 @@ url: config.mock ? config.mockUrl : config.url,

log: config.log,
mark: config.mark,
url: config.mock ? config.mockUrl : config.url,

@@ -683,3 +689,3 @@ data: data,

var VERSION = undefined;
(VERSION = "0.3.0");
(VERSION = "0.3.2");

@@ -921,2 +927,3 @@ var NattyDB = {

url: '',
mark: {},
method: GET,

@@ -968,3 +975,3 @@ accept: TEXT,

xhr.open(options.method, appendQueryString(options.url, options.data, options.cache));
xhr.open(options.method, appendQueryString(options.url, extend({}, options.mark, options.method === GET ? options.data : {}), options.cache));

@@ -1211,2 +1218,3 @@ // NOTE 生产环境的Server端, `Access-Control-Allow-Origin`的值一定不要配置成`*`!!! 而且`Access-Control-Allow-Credentials`应该是true!!!

url: '',
mark: {},
data: {},

@@ -1248,3 +1256,3 @@ cache: true,

// 生成`url`
var url = appendQueryString(options.url, extend(_defineProperty({}, options.flag, callbackName), options.data), options.cache);
var url = appendQueryString(options.url, extend(_defineProperty({}, options.flag, callbackName), options.mark, options.data), options.cache);

@@ -1251,0 +1259,0 @@ // 插入脚本

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("RSVP")):"function"==typeof define&&define.amd?define(["RSVP"],t):"object"==typeof exports?exports.NattyDB=t(require("RSVP")):e.NattyDB=t(e.RSVP)}(this,function(e){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";e.exports=window.NattyDB=n(1)},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(t,n,r){return n&&e(t.prototype,n),r&&e(t,r),t}}(),a=n(2),c=n(3),i=n(5),s=n(4),u=s.extend,l=s.runAsFn,f=s.isAbsoluteUrl,p=s.isRelativeUrl,d=s.noop,m=s.isBoolean,h=s.isNumber,v=s.isArray;s.isCrossDomain;a.on("error",function(e){if(!window.console)throw new Error(e);console.error(e)});var g=null,y="",b=!0,k=!b,j={dummy:b};j.then=j["catch"]=j["finally"]=function(){return j};var x={cache:!1,data:{},fit:d,header:{},ignoreSelfConcurrent:k,jsonp:k,log:k,method:"GET",mock:k,mockUrl:y,mockUrlPrefix:y,process:d,retry:0,timeout:0,url:y,urlPrefix:y,withCredentials:g},w=u({},x),N=function(){function e(t,n,o){r(this,e);var a=this;a.context=o,a.cache={},a.name=t;for(var c in n)a[c]=a.createAPI(u({DBName:t,API:c},l(n[c])))}return o(e,[{key:"processAPIOptions",value:function(e){var t=this,n=u({},t.context,e);return n.pending=k,n.mock&&(n.method="GET",n.mockUrl=t.getFullUrl(n.mockUrl,!0)),n.url=t.getFullUrl(e.url),v(e.jsonp)&&(n.jsonp=m(e.jsonp[0])?e.jsonp[0]:k,n.jsonp&&(n.jsonpFlag=e.jsonp[1],n.jsonpCallbackName=e.jsonp[2])),n.url.match(/\.jsonp(\?.*)?$/)&&(n.jsonp=!0),n.mock&&(n.data.m="1"),n.data["__"+t.name+"."+n.API+"()__"]="",n}},{key:"createAPI",value:function(e){var t=this,n=t.processAPIOptions(e),r=function(e){return n.ignoreSelfConcurrent&&n.pending?j:0===n.retry?t.request(e,n):t.tryRequest(e,n)};return r.config=n,t.addLoopSupport(r),r}},{key:"addLoopSupport",value:function(e){var t=null;e.looping=k,e.startLoop=function(n){var r=arguments.length<=1||void 0===arguments[1]?d:arguments[1],o=arguments.length<=2||void 0===arguments[2]?d:arguments[2];if(!n.duration||!h(n.duration))throw new Error("Illegal `duration` value for `startLoop` method.");var a=function c(){e.looping=b,t=setTimeout(function(){e(n.data).then(r,o),c()},n.duration)};e(n.data).then(r,o),a()},e.stopLoop=function(){clearTimeout(t),e.looping=k,t=null}}},{key:"getFullUrl",value:function(e,t){if(!e)return y;var n=t?"mockUrlPrefix":"urlPrefix";return!this.context[n]||f(e)||p(e)?e:this.context[n]+e}},{key:"request",value:function(e,t,n){var r=this;e=u({},t.data,l(e,{retryTime:n}));var o=void 0;t.pending=b;var c=a.defer();return o=t.jsonp?r.sendJSONP(e,t,c,n):r.sendAjax(e,t,c,n),0!==t.timeout&&setTimeout(function(){t.pending&&(o.abort(),c.reject({timeout:b,message:"Timeout By "+t.timeout+"ms."}))},t.timeout),c.promise}},{key:"tryRequest",value:function(e,t){var n=this,r=a.defer(),o=0,c=function i(){n.request(e,t,o).then(function(e){r.resolve(e)},function(e){o===t.retry?r.reject(e):(o++,i())})};return c(),r.promise}},{key:"processResponse",value:function(e,t,n){if(t=e.fit(t),t.success){var r=e.process(t.content);n.resolve(r)}else n.reject(u({message:"Processing Failed Within "+e.DBName+"."+e.API},t.error))}},{key:"sendAjax",value:function(e,t,n,r){var o=this;return c({cache:t.cache,log:t.log,url:t.mock?t.mockUrl:t.url,method:t.method,data:e,header:t.header,withCredentials:t.withCredentials,accept:"json",success:function(e){o.processResponse(t,e,n)},error:function(e){var t=void 0;switch(e){case 404:t="Not Found";break;case 500:t="Internal Server Error";break;default:t="Unknown Server Error"}n.reject({status:e,message:t})},complete:function(){(void 0===r||r===t.retry)&&(t.pending=k)}})}},{key:"sendJSONP",value:function(e,t,n,r){var o=this;return i({log:t.log,url:t.mock?t.mockUrl:t.url,data:e,cache:t.cache,flag:t.jsonpFlag,callbackName:t.jsonpCallbackName,success:function(e){o.processResponse(t,e,n)},error:function(e){n.reject({message:"Not Accessable JSONP `"})},complete:function(){(void 0===r||r===t.retry)&&(t.pending=k)}})}}]),e}(),S=function(){function e(t){r(this,e);var n=this;n.config=u({},w,t)}return o(e,[{key:"create",value:function(e,t){var n=this;if(n[e])throw new Error('DB: "'+e+'" is existed! ');return n[e]=new N(e,t,n.config)}}]),e}(),P=void 0;P="0.3.0";var C={onlyForHTML5:k,version:P,Context:S,_util:s,ajax:c,jsonp:i,setGlobal:function(e){w=u({},x,e)},getGlobal:function(e){return e?w[e]:w}};C.setGlobal(x),e.exports=C},function(e,t){e.exports=RSVP},function(e,t,n){"use strict";var r=n(4),o=r.extend,a=r.appendQueryString,c=r.noop,i=r.isCrossDomain,s=r.isBoolean,u=(document,!1),l=void 0,f=null,p="GET",d="script",m="xml",h="text",v="json",g=new XMLHttpRequest,y=typeof XDomainRequest!=l,b=!("withCredentials"in g)&&y,k="withCredentials"in g||y,j=function(e,t){var n=function(){e.__completed||(e.__completed=!0,t.complete(e.status,e),e.__aborted=null,delete e.__aborted)},r=function(){var r=e.responseText;switch(t.accept){case v:try{r=JSON.parse(r)}catch(o){console.warn("The response can NOT be parsed to JSON object.",r)}break;case d:(1,eval)(r);break;case m:r=e.responseXML}t.success(r,e),n()},o=function(){t.error(e.status,e),n()},a=function(){e.__completed||(t.abort(e.status,e),n())};b?e.onload=r:e.onreadystatechange=function(){4===e.readyState&&(e.status>=200&&e.status<300||304===e.status?r():!e.__aborted&&o())},e.onerror=o;var i=e.abort;e.abort=function(){e.__aborted=!0,i.call(e),a()},e.onprogress=e.ontimeout=c},x={url:"",method:p,accept:h,data:null,header:{},withCredentials:f,cache:!0,success:c,error:c,complete:c,abort:c,log:u},w=function(e){e=o({},x,e),i(e.url)&&(e.header={});var t=new XMLHttpRequest;return b&&(t=new XDomainRequest),t.__completed=u,j(t,e),t.open(e.method,a(e.url,e.data,e.cache)),b||(t.withCredentials=s(e.withCredentials)?e.withCredentials:i(e.url)),t.send(e.method===p?f:e.data!==f?JSON.stringify(e.data):f),t};w.fallback=b,w.supportCORS=k,e.exports=w},function(e,t,n){"use strict";var r=document,o=function(e){return e},a=function(e){return function(){for(var t=arguments,n=e(t[0],t[1]),r=2,o=t.length;o>r;r++)n=e(n,t[r]);return n}},c=Math.random,i=Math.floor,s=function(){return i(9e9*c())},u=encodeURIComponent,l=function(e,t,n){var r=[];!n&&r.push("noCache="+s());for(var o in t)t.hasOwnProperty(o)&&r.push(u(o)+"="+u(t[o]));return r.length?e+(~e.indexOf("?")?"&":"?")+r.join("&"):e},f=/^(https?:)?\/\//,p=function(e){return!!e.match(f)},d=/^[\.\/]/,m=function(e){return!!e.match(d)},h="boolean",v=function(e){return typeof e===h},g="function",y=function(e){return typeof e===g},b=function(e,t){return y(e)?e(t):e},k="number",j=function(e){return!isNaN(e)&&typeof e===k},x=Array.isArray;x||!function(){var e=Object.prototype.toString,t="[object Array]";x=function(n){return e.call(n)===t}}();var w=r.createElement("a");w.href=window.location.href;var N=function(e){var t=r.createElement("a");return t.href=e,w.protocol+"//"+w.host!=t.protocol+"//"+t.host},S=function P(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];for(var n in t)t.hasOwnProperty(n)&&void 0!==t[n]&&(x(t[n])?e[n]=[].concat(t[n]):"object"==typeof t[n]?e[n]=P({},t[n]):e[n]=t[n]);return e};e.exports={extend:a(S),makeRandom:s,appendQueryString:l,noop:o,isCrossDomain:N,isAbsoluteUrl:p,isRelativeUrl:m,isBoolean:v,isFunction:y,isNumber:j,isArray:x,runAsFn:b}},function(e,t,n){"use strict";function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var o=n(4),a=o.appendQueryString,c=o.noop,i=o.extend,s=o.makeRandom,u=window,l=document,f=null,p="script",d=navigator.userAgent.indexOf("MSIE 8.0")>-1,m=function(e){d&&e.readyState?e.onreadystatechange=f:e.onerror=f,e.parentNode.removeChild(e),e=f},h=f,v=function(e,t){var n=l.createElement(p);return n.type="text/javascript",n.src=e,n.async=!0,d&&n.readyState?n.onreadystatechange=function(){"loaded"===n.readyState&&u[t.callbackName]&&(u[t.callbackName]=f,t.error(),t.complete())}:n.onerror=function(e){u[t.callbackName]=f,t.error(e),t.complete()},h=h||l.getElementsByTagName("head")[0],h.insertBefore(n,h.firstChild),n},g={url:"",data:{},cache:!0,success:c,error:c,complete:c,log:!1,flag:"callback",callbackName:"jsonp{id}"},y=function(e){e=i({},g,e);var t=e.callbackName=e.callbackName.replace(/\{id\}/,s()),n=e.complete,o=void 0;e.complete=function(){m(o),n()},u[t]=function(n){u[t]=f,e.success(n),e.complete()};var c=a(e.url,i(r({},e.flag,t),e.data),e.cache);return o=v(c,e),{abort:function(){u[t]=function(){u[t]=f},m(o)}}};e.exports=y}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("RSVP")):"function"==typeof define&&define.amd?define(["RSVP"],t):"object"==typeof exports?exports.NattyDB=t(require("RSVP")):e.NattyDB=t(e.RSVP)}(this,function(e){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var r={};return t.m=e,t.c=r,t.p="",t(0)}([function(e,t,r){"use strict";e.exports=window.NattyDB=r(1)},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}var o=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}(),a=r(2),c=r(3),i=r(5),s=r(4),u=s.extend,l=s.runAsFn,f=s.isAbsoluteUrl,p=s.isRelativeUrl,d=s.noop,m=s.isBoolean,h=s.isNumber,v=s.isArray;s.isCrossDomain;a.on("error",function(e){if(!window.console)throw new Error(e);console.error(e)});var g=null,y="",k=!0,b=!k,j={dummy:k};j.then=j["catch"]=j["finally"]=function(){return j};var x={cache:!1,data:{},fit:d,header:{},ignoreSelfConcurrent:b,jsonp:b,log:b,method:"GET",mock:b,mockUrl:y,mockUrlPrefix:y,process:d,retry:0,timeout:0,url:y,urlPrefix:y,withCredentials:g},w=u({},x),N=function(){function e(t,r,o){n(this,e);var a=this;a.context=o,a.cache={},a.name=t;for(var c in r)a[c]=a.createAPI(u({DBName:t,API:c},l(r[c])))}return o(e,[{key:"processAPIOptions",value:function(e){var t=this,r=u({},t.context,e);return r.pending=b,r.mock&&(r.method="GET",r.mockUrl=t.getFullUrl(r.mockUrl,!0)),r.url=t.getFullUrl(e.url),v(e.jsonp)&&(r.jsonp=m(e.jsonp[0])?e.jsonp[0]:b,r.jsonp&&(r.jsonpFlag=e.jsonp[1],r.jsonpCallbackName=e.jsonp[2])),r.url.match(/\.jsonp(\?.*)?$/)&&(r.jsonp=!0),r.mark={},r.mock&&(r.mark.m="1"),r.mark["__"+t.name+"."+r.API+"()__"]="",r}},{key:"createAPI",value:function(e){var t=this,r=t.processAPIOptions(e),n=function(e){return r.ignoreSelfConcurrent&&r.pending?j:0===r.retry?t.request(e,r):t.tryRequest(e,r)};return n.config=r,t.addLoopSupport(n),n}},{key:"addLoopSupport",value:function(e){var t=null;e.looping=b,e.startLoop=function(r){var n=arguments.length<=1||void 0===arguments[1]?d:arguments[1],o=arguments.length<=2||void 0===arguments[2]?d:arguments[2];if(!r.duration||!h(r.duration))throw new Error("Illegal `duration` value for `startLoop` method.");var a=function c(){e.looping=k,t=setTimeout(function(){e(r.data).then(n,o),c()},r.duration)};e(r.data).then(n,o),a()},e.stopLoop=function(){clearTimeout(t),e.looping=b,t=null}}},{key:"getFullUrl",value:function(e,t){if(!e)return y;var r=t?"mockUrlPrefix":"urlPrefix";return!this.context[r]||f(e)||p(e)?e:this.context[r]+e}},{key:"request",value:function(e,t,r){var n=this;t.mark.retryTime=r,e=u({},t.data,l(e));var o=void 0;t.pending=k;var c=a.defer();return o=t.request?t.request(e,t,c,r):t.jsonp?n.sendJSONP(e,t,c,r):n.sendAjax(e,t,c,r),0!==t.timeout&&setTimeout(function(){t.pending&&(o.abort(),c.reject({timeout:k,message:"Timeout By "+t.timeout+"ms."}))},t.timeout),c.promise}},{key:"tryRequest",value:function(e,t){var r=this,n=a.defer(),o=0,c=function i(){r.request(e,t,o).then(function(e){n.resolve(e)},function(e){o===t.retry?n.reject(e):(o++,i())})};return c(),n.promise}},{key:"processResponse",value:function(e,t,r){if(t=e.fit(t),t.success){var n=e.process(t.content);r.resolve(n)}else r.reject(u({message:"Processing Failed Within "+e.DBName+"."+e.API},t.error))}},{key:"sendAjax",value:function(e,t,r,n){var o=this;return c({cache:t.cache,mark:t.mark,log:t.log,url:t.mock?t.mockUrl:t.url,method:t.method,data:e,header:t.header,withCredentials:t.withCredentials,accept:"json",success:function(e){o.processResponse(t,e,r)},error:function(e){var t=void 0;switch(e){case 404:t="Not Found";break;case 500:t="Internal Server Error";break;default:t="Unknown Server Error"}r.reject({status:e,message:t})},complete:function(){(void 0===n||n===t.retry)&&(t.pending=b)}})}},{key:"sendJSONP",value:function(e,t,r,n){var o=this;return i({log:t.log,mark:t.mark,url:t.mock?t.mockUrl:t.url,data:e,cache:t.cache,flag:t.jsonpFlag,callbackName:t.jsonpCallbackName,success:function(e){o.processResponse(t,e,r)},error:function(e){r.reject({message:"Not Accessable JSONP `"})},complete:function(){(void 0===n||n===t.retry)&&(t.pending=b)}})}}]),e}(),S=function(){function e(t){n(this,e);var r=this;r.config=u({},w,t)}return o(e,[{key:"create",value:function(e,t){var r=this;if(r[e])throw new Error('DB: "'+e+'" is existed! ');return r[e]=new N(e,t,r.config)}}]),e}(),P=void 0;P="0.3.2";var C={onlyForHTML5:b,version:P,Context:S,_util:s,ajax:c,jsonp:i,setGlobal:function(e){w=u({},x,e)},getGlobal:function(e){return e?w[e]:w}};C.setGlobal(x),e.exports=C},function(e,t){e.exports=RSVP},function(e,t,r){"use strict";var n=r(4),o=n.extend,a=n.appendQueryString,c=n.noop,i=n.isCrossDomain,s=n.isBoolean,u=(document,!1),l=void 0,f=null,p="GET",d="script",m="xml",h="text",v="json",g=new XMLHttpRequest,y=typeof XDomainRequest!=l,k=!("withCredentials"in g)&&y,b="withCredentials"in g||y,j=function(e,t){var r=function(){e.__completed||(e.__completed=!0,t.complete(e.status,e),e.__aborted=null,delete e.__aborted)},n=function(){var n=e.responseText;switch(t.accept){case v:try{n=JSON.parse(n)}catch(o){console.warn("The response can NOT be parsed to JSON object.",n)}break;case d:(1,eval)(n);break;case m:n=e.responseXML}t.success(n,e),r()},o=function(){t.error(e.status,e),r()},a=function(){e.__completed||(t.abort(e.status,e),r())};k?e.onload=n:e.onreadystatechange=function(){4===e.readyState&&(e.status>=200&&e.status<300||304===e.status?n():!e.__aborted&&o())},e.onerror=o;var i=e.abort;e.abort=function(){e.__aborted=!0,i.call(e),a()},e.onprogress=e.ontimeout=c},x={url:"",mark:{},method:p,accept:h,data:null,header:{},withCredentials:f,cache:!0,success:c,error:c,complete:c,abort:c,log:u},w=function(e){e=o({},x,e),i(e.url)&&(e.header={});var t=new XMLHttpRequest;return k&&(t=new XDomainRequest),t.__completed=u,j(t,e),t.open(e.method,a(e.url,o({},e.mark,e.method===p?e.data:{}),e.cache)),k||(t.withCredentials=s(e.withCredentials)?e.withCredentials:i(e.url)),t.send(e.method===p?f:e.data!==f?JSON.stringify(e.data):f),t};w.fallback=k,w.supportCORS=b,e.exports=w},function(e,t,r){"use strict";var n=document,o=function(e){return e},a=function(e){return function(){for(var t=arguments,r=e(t[0],t[1]),n=2,o=t.length;o>n;n++)r=e(r,t[n]);return r}},c=Math.random,i=Math.floor,s=function(){return i(9e9*c())},u=encodeURIComponent,l=function(e,t,r){var n=[];!r&&n.push("noCache="+s());for(var o in t)t.hasOwnProperty(o)&&n.push(u(o)+"="+u(t[o]));return n.length?e+(~e.indexOf("?")?"&":"?")+n.join("&"):e},f=/^(https?:)?\/\//,p=function(e){return!!e.match(f)},d=/^[\.\/]/,m=function(e){return!!e.match(d)},h="boolean",v=function(e){return typeof e===h},g="function",y=function(e){return typeof e===g},k=function(e,t){return y(e)?e(t):e},b="number",j=function(e){return!isNaN(e)&&typeof e===b},x=Array.isArray;x||!function(){var e=Object.prototype.toString,t="[object Array]";x=function(r){return e.call(r)===t}}();var w=n.createElement("a");w.href=window.location.href;var N=function(e){var t=n.createElement("a");return t.href=e,w.protocol+"//"+w.host!=t.protocol+"//"+t.host},S=function P(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1];for(var r in t)t.hasOwnProperty(r)&&void 0!==t[r]&&(x(t[r])?e[r]=[].concat(t[r]):"object"==typeof t[r]?e[r]=P({},t[r]):e[r]=t[r]);return e};e.exports={extend:a(S),makeRandom:s,appendQueryString:l,noop:o,isCrossDomain:N,isAbsoluteUrl:p,isRelativeUrl:m,isBoolean:v,isFunction:y,isNumber:j,isArray:x,runAsFn:k}},function(e,t,r){"use strict";function n(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var o=r(4),a=o.appendQueryString,c=o.noop,i=o.extend,s=o.makeRandom,u=window,l=document,f=null,p="script",d=navigator.userAgent.indexOf("MSIE 8.0")>-1,m=function(e){d&&e.readyState?e.onreadystatechange=f:e.onerror=f,e.parentNode.removeChild(e),e=f},h=f,v=function(e,t){var r=l.createElement(p);return r.type="text/javascript",r.src=e,r.async=!0,d&&r.readyState?r.onreadystatechange=function(){"loaded"===r.readyState&&u[t.callbackName]&&(u[t.callbackName]=f,t.error(),t.complete())}:r.onerror=function(e){u[t.callbackName]=f,t.error(e),t.complete()},h=h||l.getElementsByTagName("head")[0],h.insertBefore(r,h.firstChild),r},g={url:"",mark:{},data:{},cache:!0,success:c,error:c,complete:c,log:!1,flag:"callback",callbackName:"jsonp{id}"},y=function(e){e=i({},g,e);var t=e.callbackName=e.callbackName.replace(/\{id\}/,s()),r=e.complete,o=void 0;e.complete=function(){m(o),r()},u[t]=function(r){u[t]=f,e.success(r),e.complete()};var c=a(e.url,i(n({},e.flag,t),e.mark,e.data),e.cache);return o=v(c,e),{abort:function(){u[t]=function(){u[t]=f},m(o)}}};e.exports=y}])});
## Next TODO
* 增加缓存机制:以相同的参数调用相同的API时,在配置指定的时间内,不发出网络请求。
* 和其他的异步功能可以对接,如对接Native的地理位置接口。
#### 增加缓存机制
以相同的参数调用相同的`API`时,在配置指定的时间内,不发出网络请求。
```js
DBContext.create('Address', {
search: {
cacheLevel: 'session', // session/localstorage
url: 'api/for/searchAddress'
}
});
```
#### 和已有的异步功能对接
和已有的异步功能可以对接,如对接`Native`的地理位置接口。
```js
// 已有的异步功能:获取地理位置
JSAPI.get('GPS',function (data) {
// 成功
}, function (error) {
// 失败
});
// 使用NattyDB对接
let User = DBContext.create('User', {
getGPS: {
promise: function (RSVP) {
let defer = RSVP.defer();
JSAPI.get('GPS',function (data) {
defer.resolev(data);
}, function (error) {
defer.reject(error);
});
return defer.promise;
}
}
});
// 使用场景
User.getGPS().then(function (content) {
// 成功
}, function (error) {
// 失败
});
```
## History
#### v0.3.0 / 2015-12-10
#### v0.3.2 / 2016-01-05
* 修復: `POST`请求时`url`参数追加了多余`data`数据被修复。
* 能够和已有的异步功能进行对接
#### v0.3.0 / 2015-12-11
* 修复:接口(API)的`jsonp`配置的值没有正确继承上下文(Context)的配置。
* 增强:轮询设计得更加友好。
* 当`ajax`跨域时,允许自定义`withCredentials`的值。(之前只要跨域,就强制`withCredentials`为true)

@@ -13,0 +64,0 @@ #### v0.2.2 / 2015-12-06

{
"name": "natty-db",
"version": "0.3.0",
"version": "0.3.2",
"description": "A natty semantic data-fetching tool for project that no longer needs to use jQuery/Zepto's Ajax.",

@@ -5,0 +5,0 @@ "repository": "https://github.com/Jias/natty-db.git",

@@ -167,2 +167,3 @@ /**

url: '',
mark: {},
method: GET,

@@ -212,3 +213,3 @@ accept: TEXT,

xhr.open(options.method, appendQueryString(options.url, options.data, options.cache));
xhr.open(options.method, appendQueryString(options.url, extend({}, options.mark, options.method === GET ? options.data : {}), options.cache));

@@ -215,0 +216,0 @@ // NOTE 生产环境的Server端, `Access-Control-Allow-Origin`的值一定不要配置成`*`!!! 而且`Access-Control-Allow-Credentials`应该是true!!!

@@ -189,2 +189,3 @@ /**

url: '',
mark: {},
method: GET,

@@ -237,3 +238,3 @@ accept: TEXT,

xhr.open(options.method, appendQueryString(options.url, options.data, options.cache));
xhr.open(options.method, appendQueryString(options.url, extend({}, options.mark, options.method === GET ? options.data : {}), options.cache));

@@ -240,0 +241,0 @@ // NOTE 生产环境的Server端, `Access-Control-Allow-Origin`的值一定不要配置成`*`!!! 而且`Access-Control-Allow-Credentials`应该是true!!!

@@ -31,2 +31,3 @@ const {appendQueryString, noop, extend, makeRandom} = require('./util');

url: '',
mark: {},
data: {},

@@ -69,3 +70,3 @@ cache: true,

[options.flag]: callbackName
}, options.data), options.cache);
}, options.mark, options.data), options.cache);

@@ -72,0 +73,0 @@ // 插入脚本

@@ -55,2 +55,3 @@ const {appendQueryString, noop, extend, makeRandom} = require('./util');

url: '',
mark: {},
data: {},

@@ -94,3 +95,3 @@ cache: true,

[options.flag]: callbackName
}, options.data), options.cache);
}, options.mark, options.data), options.cache);

@@ -111,2 +112,2 @@ // 插入脚本

module.exports = jsonp;
module.exports = jsonp;

@@ -153,7 +153,9 @@ "use strict";

// 请求标记
config.mark = {};
if (config.mock) {
config.data.m = '1';
config.mark.m = '1';
}
config.data['__' + t.name + '.' + config.API + '()__'] = '';
config.mark['__' + t.name + '.' + config.API + '()__'] = '';

@@ -260,6 +262,7 @@ return config;

// 更新的请求标记
config.mark.retryTime = retryTime;
// `data`必须在请求发生时实时创建
data = extend({}, config.data, runAsFn(data, {
retryTime
}));
data = extend({}, config.data, runAsFn(data));

@@ -279,7 +282,7 @@ // 根据`config`的差别 请求对象分为`ajax`和`jsonp`两种

//} else
if (config.jsonp) {
if (config.request) {
requester = config.request(data, config, defer, retryTime);
} else if (config.jsonp) {
requester = t.sendJSONP(data, config, defer, retryTime);
} else {
//C.log('send ajax');
requester = t.sendAjax(data, config, defer, retryTime);

@@ -373,2 +376,3 @@ }

cache: config.cache,
mark: config.mark,
log: config.log,

@@ -430,2 +434,3 @@ url: config.mock ? config.mockUrl : config.url,

log: config.log,
mark: config.mark,
url: config.mock ? config.mockUrl : config.url,

@@ -432,0 +437,0 @@ data: data,

@@ -153,7 +153,9 @@ "use strict";

// 请求标记
config.mark = {};
if (config.mock) {
config.data.m = '1';
config.mark.m = '1';
}
config.data['__' + t.name + '.' + config.API + '()__'] = '';
config.mark['__' + t.name + '.' + config.API + '()__'] = '';

@@ -260,6 +262,7 @@ return config;

// 更新的请求标记
config.mark.retryTime = retryTime;
// `data`必须在请求发生时实时创建
data = extend({}, config.data, runAsFn(data, {
retryTime
}));
data = extend({}, config.data, runAsFn(data));

@@ -279,7 +282,7 @@ // 根据`config`的差别 请求对象分为`ajax`和`jsonp`两种

//} else
if (config.jsonp) {
if (config.request) {
requester = config.request(data, config, defer, retryTime);
} else if (config.jsonp) {
requester = t.sendJSONP(data, config, defer, retryTime);
} else {
//C.log('send ajax');
requester = t.sendAjax(data, config, defer, retryTime);

@@ -373,2 +376,3 @@ }

cache: config.cache,
mark: config.mark,
log: config.log,

@@ -430,2 +434,3 @@ url: config.mock ? config.mockUrl : config.url,

log: config.log,
mark: config.mark,
url: config.mock ? config.mockUrl : config.url,

@@ -432,0 +437,0 @@ data: data,

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc