@cclr/service 0.1.49 → 0.1.50

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.
package/lib/cjs/index.js CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";var t=require("@cclr/utils"),e=require("@cclr/lang"),r=require("@cclr/logger");function n(t,e,r,n,o,i,u){try{var c=t[i](u),a=c.value}catch(t){return void r(t)}c.done?e(a):Promise.resolve(a).then(n,o)}function o(t,e,r){return e=s(e),function(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,f()?Reflect.construct(e,[],s(t).constructor):e.apply(t,r))}function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function u(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,h(n.key),n)}}function c(t,e,r){return e&&u(t.prototype,e),r&&u(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function a(t,e,r){return(e=h(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function s(t){return s=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},s(t)}function f(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(f=function(){return!!t})()}function p(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function l(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?p(Object(r),!0).forEach(function(e){a(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):p(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function y(){
1
+ "use strict";var e=require("@cclr/utils"),t=require("@cclr/lang"),r=require("@cclr/logger");function n(e,t,r,n,o,i,u){try{var c=e[i](u),a=c.value}catch(e){return void r(e)}c.done?t(a):Promise.resolve(a).then(n,o)}function o(e,t,r){return t=s(t),function(e,t){if(t&&("object"==typeof t||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e)}(e,p()?Reflect.construct(t,[],s(e).constructor):t.apply(e,r))}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(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,d(n.key),n)}}function c(e,t,r){return t&&u(e.prototype,t),r&&u(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function a(e,t,r){return(t=d(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function s(e){return s=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},s(e)}function f(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&h(e,t)}function p(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(p=function(){return!!e})()}function l(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function y(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?l(Object(r),!0).forEach(function(t){a(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):l(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function v(){
2
2
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
3
- var t,e,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var a=n&&n.prototype instanceof c?n:c,s=Object.create(a.prototype);return v(s,"_invoke",function(r,n,o){var i,c,a,s=0,f=o||[],p=!1,l={p:0,n:0,v:t,a:y,f:y.bind(t,4),d:function(e,r){return i=e,c=0,a=t,l.n=r,u}};function y(r,n){for(c=r,a=n,e=0;!p&&s&&!o&&e<f.length;e++){var o,i=f[e],y=l.p,v=i[2];r>3?(o=v===n)&&(a=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=y&&((o=r<2&&y<i[1])?(c=0,l.v=n,l.n=i[1]):y<v&&(o=r<3||i[0]>n||n>v)&&(i[4]=r,i[5]=n,l.n=v,c=0))}if(o||r>1)return u;throw p=!0,n}return function(o,f,v){if(s>1)throw TypeError("Generator is already running");for(p&&1===f&&y(f,v),c=f,a=v;(e=c<2?t:a)||!p;){i||(c?c<3?(c>1&&(l.n=-1),y(c,a)):l.n=a:l.v=a);try{if(s=2,i){if(c||(o="next"),e=i[o]){if(!(e=e.call(i,a)))throw TypeError("iterator result is not an object");if(!e.done)return e;a=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(a=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=t}else if((e=(p=l.n<0)?a:r.call(n,l))!==u)break}catch(e){i=t,c=1,a=e}finally{s=1}}return{value:e,done:p}}}(r,o,i),!0),s}var u={};function c(){}function a(){}function s(){}e=Object.getPrototypeOf;var f=[][n]?e(e([][n]())):(v(e={},n,function(){return this}),e),p=s.prototype=c.prototype=Object.create(f);function l(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,s):(t.__proto__=s,v(t,o,"GeneratorFunction")),t.prototype=Object.create(p),t}return a.prototype=s,v(p,"constructor",s),v(s,"constructor",a),a.displayName="GeneratorFunction",v(s,o,"GeneratorFunction"),v(p),v(p,o,"Generator"),v(p,n,function(){return this}),v(p,"toString",function(){return"[object Generator]"}),(y=function(){return{w:i,m:l}})()}function v(t,e,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}v=function(t,e,r,n){function i(e,r){v(t,e,function(t){return this._invoke(e,r,t)})}e?o?o(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n}):t[e]=r:(i("next",0),i("throw",1),i("return",2))},v(t,e,r,n)}function b(t,e){return b=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},b(t,e)}function h(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}var d={baseURL:"",method:"get",headers:{"Content-Type":"application/json"},adapter:function(e){var r=e.baseURL,n=e.headers,o=e.method,i=e.data,u=e.params,c=t.uri.parseUrl(r);c.query=t.uri.toQueryString(u||{});var a="get"===o,s={config:e};return fetch(t.uri.combine(c),{method:o,headers:n,body:!a&&i?JSON.stringify(i):void 0}).then(function(t){return t.ok?(s.status=t.status,s.statusText=t.statusText,s.config=e,s.response=t,t.text()):Promise.reject(t)}).then(function(t){return s.data=t,s})}},O=function(){return c(function e(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:d;i(this,e),a(this,"defaultRequestConfig",void 0),a(this,"interceptors",{request:new t.Interceptor,response:new t.Interceptor}),this.defaultRequestConfig=r},[{key:"request",value:(e=y().m(function t(e){var r,n,o,i=this;return y().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,this.interceptors.request.run(function(){return l(l({},i.defaultRequestConfig),e)},!0);case 1:return r=t.v,t.n=2,r.adapter(r);case 2:return n=t.v,t.n=3,this.interceptors.response.run(function(){return n});case 3:return o=t.v,t.a(2,o.data)}},t,this)}),r=function(){var t=this,r=arguments;return new Promise(function(o,i){var u=e.apply(t,r);function c(t){n(u,o,i,c,a,"next",t)}function a(t){n(u,o,i,c,a,"throw",t)}c(void 0)})},function(t){return r.apply(this,arguments)})},{key:"get",value:function(e,r,n){var o=l(l({},t.uri.getQueryObj(e)),r);return this.request({method:"get",baseURL:e,params:o,headers:l({"Content-Type":"application/json"},n)})}},{key:"post",value:function(t,e,r){return this.request({baseURL:t,method:"post",data:e,headers:l({"Content-Type":"application/json"},r)})}}]);var e,r}(),g=function(){function t(){var n;return i(this,t),(n=o(this,t)).interceptors.response.use(function(t){var n=t.data;if(e.isString(n))try{t.data=JSON.parse(n)}catch(t){r.logger.warn("response data is not json",n)}return t}),n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&b(t,e)}(t,O),c(t,null,[{key:"create",value:function(){return t.service||(t.service=new t),t.service}}])}();a(g,"service",void 0),exports.Axios=O,exports.ServiceBase=g;
3
+ var e,t,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var a=n&&n.prototype instanceof c?n:c,s=Object.create(a.prototype);return b(s,"_invoke",function(r,n,o){var i,c,a,s=0,f=o||[],p=!1,l={p:0,n:0,v:e,a:y,f:y.bind(e,4),d:function(t,r){return i=t,c=0,a=e,l.n=r,u}};function y(r,n){for(c=r,a=n,t=0;!p&&s&&!o&&t<f.length;t++){var o,i=f[t],y=l.p,v=i[2];r>3?(o=v===n)&&(a=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=e):i[0]<=y&&((o=r<2&&y<i[1])?(c=0,l.v=n,l.n=i[1]):y<v&&(o=r<3||i[0]>n||n>v)&&(i[4]=r,i[5]=n,l.n=v,c=0))}if(o||r>1)return u;throw p=!0,n}return function(o,f,v){if(s>1)throw TypeError("Generator is already running");for(p&&1===f&&y(f,v),c=f,a=v;(t=c<2?e:a)||!p;){i||(c?c<3?(c>1&&(l.n=-1),y(c,a)):l.n=a:l.v=a);try{if(s=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,a)))throw TypeError("iterator result is not an object");if(!t.done)return t;a=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(a=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=e}else if((t=(p=l.n<0)?a:r.call(n,l))!==u)break}catch(t){i=e,c=1,a=t}finally{s=1}}return{value:t,done:p}}}(r,o,i),!0),s}var u={};function c(){}function a(){}function s(){}t=Object.getPrototypeOf;var f=[][n]?t(t([][n]())):(b(t={},n,function(){return this}),t),p=s.prototype=c.prototype=Object.create(f);function l(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,s):(e.__proto__=s,b(e,o,"GeneratorFunction")),e.prototype=Object.create(p),e}return a.prototype=s,b(p,"constructor",s),b(s,"constructor",a),a.displayName="GeneratorFunction",b(s,o,"GeneratorFunction"),b(p),b(p,o,"Generator"),b(p,n,function(){return this}),b(p,"toString",function(){return"[object Generator]"}),(v=function(){return{w:i,m:l}})()}function b(e,t,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(e){o=0}b=function(e,t,r,n){function i(t,r){b(e,t,function(e){return this._invoke(t,r,e)})}t?o?o(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(i("next",0),i("throw",1),i("return",2))},b(e,t,r,n)}function h(e,t){return h=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},h(e,t)}function d(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}var O={baseURL:"",method:"get",headers:{"Content-Type":"application/json"},adapter:function(t){var r=t.baseURL,n=t.headers,o=t.method,i=t.data,u=t.params,c=e.uri.parseUrl(r);c.query=e.uri.toQueryString(u||{});var a="get"===o,s={config:t},f=function(){if(!a&&i)return"string"==typeof i||i instanceof FormData||i instanceof Blob?i:JSON.stringify(i)}();return fetch(e.uriCombine(c),{method:o,headers:n,body:f}).then(function(e){return e.ok?(s.status=e.status,s.statusText=e.statusText,s.config=t,s.response=e,e.text()):Promise.reject(e)}).then(function(e){return s.data=e,s})}},g=function(){return c(function t(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:O;i(this,t),a(this,"defaultRequestConfig",void 0),a(this,"interceptors",{request:new e.Interceptor,response:new e.Interceptor}),this.defaultRequestConfig=r},[{key:"request",value:(t=v().m(function e(t){var r,n,o,i=this;return v().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,this.interceptors.request.run(function(){return y(y({},i.defaultRequestConfig),t)},!0);case 1:return r=e.v,e.n=2,r.adapter(r);case 2:return n=e.v,e.n=3,this.interceptors.response.run(function(){return n});case 3:return o=e.v,e.a(2,o.data)}},e,this)}),r=function(){var e=this,r=arguments;return new Promise(function(o,i){var u=t.apply(e,r);function c(e){n(u,o,i,c,a,"next",e)}function a(e){n(u,o,i,c,a,"throw",e)}c(void 0)})},function(e){return r.apply(this,arguments)})},{key:"get",value:function(t,r,n){var o=y(y({},e.uri.getQueryObj(t)),r);return this.request({method:"get",baseURL:t,params:o,headers:y({"Content-Type":"application/json"},n)})}},{key:"post",value:function(e,t,r){return this.request({baseURL:e,method:"post",data:t,headers:y({"Content-Type":"application/json"},r)})}}]);var t,r}(),j=function(){function e(){var n;return i(this,e),(n=o(this,e)).interceptors.response.use(function(e){var n=e.data;if(t.isString(n))try{e.data=JSON.parse(n)}catch(e){r.logger.warn("response data is not json",n)}return e}),n}return f(e,g),c(e,[{key:"postFormdata",value:function(e,t,r){return this.request({baseURL:e,method:"post",data:t,headers:y({},r)})}}],[{key:"create",value:function(){return e.service||(e.service=new e),e.service}}])}();a(j,"service",void 0);var m=function(){function e(){var t;return i(this,e),(t=o(this,e)).interceptors.response.use(function(e){return e}),t}return f(e,g),c(e,null,[{key:"create",value:function(){return e.service||(e.service=new e),e.service}}])}();a(m,"service",void 0),exports.Axios=g,exports.ServiceBase=j,exports.ServiceFile=m;
package/lib/esm/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import{uri as t,Interceptor as e}from"@cclr/utils";import{isString as r}from"@cclr/lang";import{logger as n}from"@cclr/logger";function o(t,e,r,n,o,i,u){try{var c=t[i](u),a=c.value}catch(t){return void r(t)}c.done?e(a):Promise.resolve(a).then(n,o)}function i(t,e,r){return e=s(e),function(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,p()?Reflect.construct(e,[],s(t).constructor):e.apply(t,r))}function u(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function c(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,d(n.key),n)}}function a(t,e,r){return e&&c(t.prototype,e),r&&c(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function f(t,e,r){return(e=d(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function s(t){return s=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},s(t)}function p(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(p=function(){return!!t})()}function l(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function y(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?l(Object(r),!0).forEach(function(e){f(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):l(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function b(){
1
+ import{uri as t,uriCombine as e,Interceptor as r}from"@cclr/utils";import{isString as n}from"@cclr/lang";import{logger as o}from"@cclr/logger";function i(t,e,r,n,o,i,u){try{var c=t[i](u),a=c.value}catch(t){return void r(t)}c.done?e(a):Promise.resolve(a).then(n,o)}function u(t,e,r){return e=p(e),function(t,e){if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,y()?Reflect.construct(e,[],p(t).constructor):e.apply(t,r))}function c(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function a(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,g(n.key),n)}}function s(t,e,r){return e&&a(t.prototype,e),r&&a(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function f(t,e,r){return(e=g(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function p(t){return p=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},p(t)}function l(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&O(t,e)}function y(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(t){}return(y=function(){return!!t})()}function v(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function b(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?v(Object(r),!0).forEach(function(e){f(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):v(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function h(){
2
2
  /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
3
- var t,e,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var a=n&&n.prototype instanceof c?n:c,f=Object.create(a.prototype);return v(f,"_invoke",function(r,n,o){var i,c,a,f=0,s=o||[],p=!1,l={p:0,n:0,v:t,a:y,f:y.bind(t,4),d:function(e,r){return i=e,c=0,a=t,l.n=r,u}};function y(r,n){for(c=r,a=n,e=0;!p&&f&&!o&&e<s.length;e++){var o,i=s[e],y=l.p,b=i[2];r>3?(o=b===n)&&(a=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=y&&((o=r<2&&y<i[1])?(c=0,l.v=n,l.n=i[1]):y<b&&(o=r<3||i[0]>n||n>b)&&(i[4]=r,i[5]=n,l.n=b,c=0))}if(o||r>1)return u;throw p=!0,n}return function(o,s,b){if(f>1)throw TypeError("Generator is already running");for(p&&1===s&&y(s,b),c=s,a=b;(e=c<2?t:a)||!p;){i||(c?c<3?(c>1&&(l.n=-1),y(c,a)):l.n=a:l.v=a);try{if(f=2,i){if(c||(o="next"),e=i[o]){if(!(e=e.call(i,a)))throw TypeError("iterator result is not an object");if(!e.done)return e;a=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(a=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=t}else if((e=(p=l.n<0)?a:r.call(n,l))!==u)break}catch(e){i=t,c=1,a=e}finally{f=1}}return{value:e,done:p}}}(r,o,i),!0),f}var u={};function c(){}function a(){}function f(){}e=Object.getPrototypeOf;var s=[][n]?e(e([][n]())):(v(e={},n,function(){return this}),e),p=f.prototype=c.prototype=Object.create(s);function l(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,f):(t.__proto__=f,v(t,o,"GeneratorFunction")),t.prototype=Object.create(p),t}return a.prototype=f,v(p,"constructor",f),v(f,"constructor",a),a.displayName="GeneratorFunction",v(f,o,"GeneratorFunction"),v(p),v(p,o,"Generator"),v(p,n,function(){return this}),v(p,"toString",function(){return"[object Generator]"}),(b=function(){return{w:i,m:l}})()}function v(t,e,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}v=function(t,e,r,n){function i(e,r){v(t,e,function(t){return this._invoke(e,r,t)})}e?o?o(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n}):t[e]=r:(i("next",0),i("throw",1),i("return",2))},v(t,e,r,n)}function h(t,e){return h=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},h(t,e)}function d(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}var O={baseURL:"",method:"get",headers:{"Content-Type":"application/json"},adapter:function(e){var r=e.baseURL,n=e.headers,o=e.method,i=e.data,u=e.params,c=t.parseUrl(r);c.query=t.toQueryString(u||{});var a="get"===o,f={config:e};return fetch(t.combine(c),{method:o,headers:n,body:!a&&i?JSON.stringify(i):void 0}).then(function(t){return t.ok?(f.status=t.status,f.statusText=t.statusText,f.config=e,f.response=t,t.text()):Promise.reject(t)}).then(function(t){return f.data=t,f})}},g=function(){return a(function t(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:O;u(this,t),f(this,"defaultRequestConfig",void 0),f(this,"interceptors",{request:new e,response:new e}),this.defaultRequestConfig=r},[{key:"request",value:(r=b().m(function t(e){var r,n,o,i=this;return b().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,this.interceptors.request.run(function(){return y(y({},i.defaultRequestConfig),e)},!0);case 1:return r=t.v,t.n=2,r.adapter(r);case 2:return n=t.v,t.n=3,this.interceptors.response.run(function(){return n});case 3:return o=t.v,t.a(2,o.data)}},t,this)}),n=function(){var t=this,e=arguments;return new Promise(function(n,i){var u=r.apply(t,e);function c(t){o(u,n,i,c,a,"next",t)}function a(t){o(u,n,i,c,a,"throw",t)}c(void 0)})},function(t){return n.apply(this,arguments)})},{key:"get",value:function(e,r,n){var o=y(y({},t.getQueryObj(e)),r);return this.request({method:"get",baseURL:e,params:o,headers:y({"Content-Type":"application/json"},n)})}},{key:"post",value:function(t,e,r){return this.request({baseURL:t,method:"post",data:e,headers:y({"Content-Type":"application/json"},r)})}}]);var r,n}(),j=function(){function t(){var e;return u(this,t),(e=i(this,t)).interceptors.response.use(function(t){var e=t.data;if(r(e))try{t.data=JSON.parse(e)}catch(t){n.warn("response data is not json",e)}return t}),e}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&h(t,e)}(t,g),a(t,null,[{key:"create",value:function(){return t.service||(t.service=new t),t.service}}])}();f(j,"service",void 0);export{g as Axios,j as ServiceBase};
3
+ var t,e,r="function"==typeof Symbol?Symbol:{},n=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,n,o,i){var a=n&&n.prototype instanceof c?n:c,s=Object.create(a.prototype);return d(s,"_invoke",function(r,n,o){var i,c,a,s=0,f=o||[],p=!1,l={p:0,n:0,v:t,a:y,f:y.bind(t,4),d:function(e,r){return i=e,c=0,a=t,l.n=r,u}};function y(r,n){for(c=r,a=n,e=0;!p&&s&&!o&&e<f.length;e++){var o,i=f[e],y=l.p,v=i[2];r>3?(o=v===n)&&(a=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=t):i[0]<=y&&((o=r<2&&y<i[1])?(c=0,l.v=n,l.n=i[1]):y<v&&(o=r<3||i[0]>n||n>v)&&(i[4]=r,i[5]=n,l.n=v,c=0))}if(o||r>1)return u;throw p=!0,n}return function(o,f,v){if(s>1)throw TypeError("Generator is already running");for(p&&1===f&&y(f,v),c=f,a=v;(e=c<2?t:a)||!p;){i||(c?c<3?(c>1&&(l.n=-1),y(c,a)):l.n=a:l.v=a);try{if(s=2,i){if(c||(o="next"),e=i[o]){if(!(e=e.call(i,a)))throw TypeError("iterator result is not an object");if(!e.done)return e;a=e.value,c<2&&(c=0)}else 1===c&&(e=i.return)&&e.call(i),c<2&&(a=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=t}else if((e=(p=l.n<0)?a:r.call(n,l))!==u)break}catch(e){i=t,c=1,a=e}finally{s=1}}return{value:e,done:p}}}(r,o,i),!0),s}var u={};function c(){}function a(){}function s(){}e=Object.getPrototypeOf;var f=[][n]?e(e([][n]())):(d(e={},n,function(){return this}),e),p=s.prototype=c.prototype=Object.create(f);function l(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,s):(t.__proto__=s,d(t,o,"GeneratorFunction")),t.prototype=Object.create(p),t}return a.prototype=s,d(p,"constructor",s),d(s,"constructor",a),a.displayName="GeneratorFunction",d(s,o,"GeneratorFunction"),d(p),d(p,o,"Generator"),d(p,n,function(){return this}),d(p,"toString",function(){return"[object Generator]"}),(h=function(){return{w:i,m:l}})()}function d(t,e,r,n){var o=Object.defineProperty;try{o({},"",{})}catch(t){o=0}d=function(t,e,r,n){function i(e,r){d(t,e,function(t){return this._invoke(e,r,t)})}e?o?o(t,e,{value:r,enumerable:!n,configurable:!n,writable:!n}):t[e]=r:(i("next",0),i("throw",1),i("return",2))},d(t,e,r,n)}function O(t,e){return O=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},O(t,e)}function g(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}var m={baseURL:"",method:"get",headers:{"Content-Type":"application/json"},adapter:function(r){var n=r.baseURL,o=r.headers,i=r.method,u=r.data,c=r.params,a=t.parseUrl(n);a.query=t.toQueryString(c||{});var s="get"===i,f={config:r},p=function(){if(!s&&u)return"string"==typeof u||u instanceof FormData||u instanceof Blob?u:JSON.stringify(u)}();return fetch(e(a),{method:i,headers:o,body:p}).then(function(t){return t.ok?(f.status=t.status,f.statusText=t.statusText,f.config=r,f.response=t,t.text()):Promise.reject(t)}).then(function(t){return f.data=t,f})}},j=function(){return s(function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:m;c(this,t),f(this,"defaultRequestConfig",void 0),f(this,"interceptors",{request:new r,response:new r}),this.defaultRequestConfig=e},[{key:"request",value:(e=h().m(function t(e){var r,n,o,i=this;return h().w(function(t){for(;;)switch(t.n){case 0:return t.n=1,this.interceptors.request.run(function(){return b(b({},i.defaultRequestConfig),e)},!0);case 1:return r=t.v,t.n=2,r.adapter(r);case 2:return n=t.v,t.n=3,this.interceptors.response.run(function(){return n});case 3:return o=t.v,t.a(2,o.data)}},t,this)}),n=function(){var t=this,r=arguments;return new Promise(function(n,o){var u=e.apply(t,r);function c(t){i(u,n,o,c,a,"next",t)}function a(t){i(u,n,o,c,a,"throw",t)}c(void 0)})},function(t){return n.apply(this,arguments)})},{key:"get",value:function(e,r,n){var o=b(b({},t.getQueryObj(e)),r);return this.request({method:"get",baseURL:e,params:o,headers:b({"Content-Type":"application/json"},n)})}},{key:"post",value:function(t,e,r){return this.request({baseURL:t,method:"post",data:e,headers:b({"Content-Type":"application/json"},r)})}}]);var e,n}(),w=function(){function t(){var e;return c(this,t),(e=u(this,t)).interceptors.response.use(function(t){var e=t.data;if(n(e))try{t.data=JSON.parse(e)}catch(t){o.warn("response data is not json",e)}return t}),e}return l(t,j),s(t,[{key:"postFormdata",value:function(t,e,r){return this.request({baseURL:t,method:"post",data:e,headers:b({},r)})}}],[{key:"create",value:function(){return t.service||(t.service=new t),t.service}}])}();f(w,"service",void 0);var P=function(){function t(){var e;return c(this,t),(e=u(this,t)).interceptors.response.use(function(t){return t}),e}return l(t,j),s(t,null,[{key:"create",value:function(){return t.service||(t.service=new t),t.service}}])}();f(P,"service",void 0);export{j as Axios,w as ServiceBase,P as ServiceFile};
@@ -44,18 +44,32 @@ declare class Axios {
44
44
  request: Interceptor<TAxiosConfig>;
45
45
  response: Interceptor<TAxiosResponse<any>>;
46
46
  };
47
- request<T>(options: Partial<TAxiosConfig>): Promise<any>;
48
- get<T>(url: string, params?: TPlainObject, headers?: TPlainObject): Promise<any>;
49
- post<T>(url: string, data?: TPlainObject, headers?: TPlainObject): Promise<any>;
47
+ request<T>(options: Partial<TAxiosConfig>): Promise<T>;
48
+ get<T>(url: string, params?: TPlainObject, headers?: TPlainObject): Promise<T>;
49
+ post<T>(url: string, data?: TPlainObject, headers?: TPlainObject): Promise<T>;
50
50
  }
51
51
 
52
52
  /** 定义一个抽象类 */
53
53
 
54
54
  declare class ServiceBase extends Axios {
55
55
  constructor();
56
+ /**
57
+ * formdata 请求
58
+ * @param url - 请求地址
59
+ * @param data - 请求数据
60
+ * @param headers - 请求头
61
+ * @returns
62
+ */
63
+ postFormdata<T>(url: string, data?: FormData, headers?: TPlainObject): Promise<T>;
56
64
  private static service;
57
65
  static create(): ServiceBase;
58
66
  }
59
67
 
60
- export { Axios, ServiceBase };
68
+ declare class ServiceFile extends Axios {
69
+ constructor();
70
+ private static service;
71
+ static create(): ServiceFile;
72
+ }
73
+
74
+ export { Axios, ServiceBase, ServiceFile };
61
75
  export type { Method, TAxiosConfig, TAxiosResponse };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cclr/service",
3
- "version": "0.1.49",
3
+ "version": "0.1.50",
4
4
  "description": "接口请求服务",
5
5
  "author": "cclr <18843152354@163.com>",
6
6
  "homepage": "",
@@ -27,10 +27,10 @@
27
27
  "g:test": "vitest run",
28
28
  "g:build": "drr build"
29
29
  },
30
- "gitHead": "0c9e3e0a9af9996dcaca0f0249abe698152e4dd7",
30
+ "gitHead": "d35827a9380709a9fbfb9630860dcc2739e0bb8e",
31
31
  "dependencies": {
32
- "@cclr/lang": "0.1.49",
33
- "@cclr/logger": "0.1.49",
34
- "@cclr/utils": "0.1.49"
32
+ "@cclr/lang": "0.1.50",
33
+ "@cclr/logger": "0.1.50",
34
+ "@cclr/utils": "0.1.50"
35
35
  }
36
36
  }