@recats/cdeebee 2.3.1 → 2.3.2
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/dist/actions.d.ts +24 -0
- package/dist/cdeebee.js +1175 -0
- package/dist/cdeebee.umd.cjs +3 -0
- package/dist/definition.d.ts +208 -0
- package/dist/helpers.d.ts +22 -0
- package/dist/index.d.ts +6 -0
- package/dist/reducer.d.ts +8 -0
- package/dist/request.d.ts +8 -0
- package/package.json +6 -2
- package/.editorconfig +0 -8
- package/.travis.yml +0 -17
- package/eslint.config.mjs +0 -26
- package/lib/actions.ts +0 -65
- package/lib/definition.ts +0 -250
- package/lib/helpers.ts +0 -138
- package/lib/index.ts +0 -26
- package/lib/reducer.ts +0 -93
- package/lib/request.ts +0 -200
- package/tsconfig.json +0 -13
- package/tslint.json +0 -20
- package/vite.config.mjs +0 -26
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
(function(R,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(R=typeof globalThis<"u"?globalThis:R||self,d(R.cdeebee={}))})(this,function(R){"use strict";function d(e){return e!=null&&typeof e=="object"&&e["@@functional/placeholder"]===!0}function B(e){return function t(r){return arguments.length===0||d(r)?t:e.apply(this,arguments)}}function P(e){return function t(r,n){switch(arguments.length){case 0:return t;case 1:return d(r)?t:B(function(s){return e(r,s)});default:return d(r)&&d(n)?t:d(r)?B(function(s){return e(s,n)}):d(n)?B(function(s){return e(r,s)}):e(r,n)}}}function j(e){return function t(r,n,s){switch(arguments.length){case 0:return t;case 1:return d(r)?t:P(function(i,l){return e(r,i,l)});case 2:return d(r)&&d(n)?t:d(r)?P(function(i,l){return e(i,n,l)}):d(n)?P(function(i,l){return e(r,i,l)}):B(function(i){return e(r,n,i)});default:return d(r)&&d(n)&&d(s)?t:d(r)&&d(n)?P(function(i,l){return e(i,l,s)}):d(r)&&d(s)?P(function(i,l){return e(i,n,l)}):d(n)&&d(s)?P(function(i,l){return e(r,i,l)}):d(r)?B(function(i){return e(i,n,s)}):d(n)?B(function(i){return e(r,i,s)}):d(s)?B(function(i){return e(r,n,i)}):e(r,n,s)}}}const G=Array.isArray||function(t){return t!=null&&t.length>=0&&Object.prototype.toString.call(t)==="[object Array]"};function k(e,t){return Object.prototype.hasOwnProperty.call(t,e)}function ce(e){return Object.prototype.toString.call(e)==="[object Object]"}const Y=Number.isInteger||function(t){return t<<0===t};function we(e,t,r){if(Y(e)&&G(r)){var n=[].concat(r);return n[e]=t,n}var s={};for(var i in r)s[i]=r[i];return s[e]=t,s}var Oe=B(function(t){return t==null}),I=j(function e(t,r,n){if(t.length===0)return r;var s=t[0];if(t.length>1){var i=!Oe(n)&&k(s,n)&&typeof n[s]=="object"?n[s]:Y(t[1])?[]:{};r=e(Array.prototype.slice.call(t,1),r,i)}return we(s,r,n)}),De=j(function(t,r,n){return I([t],r,n)});function Pe(e,t){return function(){var r=arguments.length;if(r===0)return t();var n=arguments[r-1];return G(n)||typeof n[e]!="function"?t.apply(this,arguments):n[e].apply(n,Array.prototype.slice.call(arguments,0,r-1))}}var Se=j(Pe("slice",function(t,r,n){return Array.prototype.slice.call(n,t,r)})),Be=j(function(t,r,n){var s=Array.prototype.slice.call(n,0);return s.splice(t,r),s});function Ce(e,t){if(t==null)return t;if(Y(e)&&G(t))return Be(e,1,t);var r={};for(var n in t)r[n]=t[n];return delete r[e],r}function Ie(e,t){if(Y(e)&&G(t))return[].concat(t);var r={};for(var n in t)r[n]=t[n];return r}var Ne=P(function e(t,r){if(r==null)return r;switch(t.length){case 0:return r;case 1:return Ce(t[0],r);default:var n=t[0],s=Array.prototype.slice.call(t,1);return r[n]==null?Ie(n,r):De(n,e(s,r[n]),r)}}),le=P(function(t,r){return Ne([t],r)}),Ue=j(function(t,r,n){var s={},i;r=r||{},n=n||{};for(i in r)k(i,r)&&(s[i]=k(i,n)?t(i,r[i],n[i]):r[i]);for(i in n)k(i,n)&&!k(i,s)&&(s[i]=n[i]);return s}),Le=j(function e(t,r,n){return Ue(function(s,i,l){return ce(i)&&ce(l)?e(t,i,l):t(s,i,l)},r,n)}),K=P(function(t,r){return Le(function(n,s,i){return i},t,r)}),Z=P(function(t,r){for(var n={},s={},i=0,l=t.length;i<l;)s[t[i]]=1,i+=1;for(var m in r)s.hasOwnProperty(m)||(n[m]=r[m]);return n}),y=(e=>(e.CDEEBEE_REQUESTMANAGER_SHIFT="@@cdeebee/REQUESTMANAGER_SHIFT",e.CDEEBEE_REQUESTMANAGER_SET="@@cdeebee/REQUESTMANAGER_SET",e.CDEEBEE_ERRORHANDLER_SET="@@cdeebee/ERRORHANDLER_SET",e.CDEEBEE_ENTITY_CHANGE_FIELD="@@cdeebee/ENTITY_CHANGE_FIELD",e.CDEEBEE_ENTITY_UNSAFE_UPDATE_STORE="@@cdeebee/ENTITY_UNSAFE_UPDATE_STORE",e.CDEEBEE_RESET_ENTITY="@@cdeebee/RESET_ENTITY",e.CDEEBEE_SET_ENTITY="@@cdeebee/SET_ENTITY",e.CDEEBEEE_UPDATE="@@cdeebee/UPDATE",e.CDEEBEEE_DROP="@@cdeebee/DROP",e.CDEEBEEE_DROP_PATH="@@cdeebee/DROP_PATH",e.CDEEBEE_INTERNAL_ERROR="@@cdeebee/INTERNAL_ERROR",e.CDEEBEE_REQUEST_ABORTED="@@cdeebee/REQUEST_ABORTED",e.CDEEBEEE_DROP_REQUEST_BY_API_URL="@@cdeebee/DROP_REQUEST_BY_API_URL",e.CDEEBEEE_DROP_ERROR_BY_API_URL="@@cdeebee/DROP_ERROR_BY_API_URL",e.CHANGE_ROUTE="@@router/LOCATION_CHANGE",e))(y||{}),C=(e=>(e.NEW="NEW",e.EDITING="EDITING",e.NORMAL="NORMAL",e))(C||{}),ee=(e=>(e.merge="merge",e.replace="replace",e))(ee||{});const fe=e=>Z(["__entity","__state"],e),Ee=e=>e.filter(t=>t.requestCancel?(ye(t),!1):!0),ye=e=>{e.controller&&e.controller.abort instanceof Function&&e.controller.abort()},qe=(e,t)=>{if(!t||e.length===0)return!1;const r=t instanceof Array?t:[t],n=e.map(s=>s.api);for(let s=0;s<r.length;s+=1)if(n.includes(r[s]))return!0;return!1},je=e=>Object.prototype.hasOwnProperty.call(e,"__entity")?e.__entity:e,Q=e=>{var r;const t=((r=e==null?void 0:e.__entity)==null?void 0:r.__state)||(e==null?void 0:e.__state);return t||C.NORMAL},He=e=>(e.__state=C.NEW,e),ke=e=>Q(e)===C.NORMAL?(console.warn("commit works only in editing and new states"),e):fe(e),de=e=>Q(e)===C.NORMAL?(console.warn("reset works only in editing and new states"),e):fe(e),pe=(e,t,r)=>{const n=e[t];if(Q(n[r])===C.EDITING)return e;const i=I([t,r,"__entity"],n[r],e);return I([t,r,"__entity","__state"],C.EDITING,i)},he=(e,t,r)=>{const n=r||[];let s=e;for(let i=0;i<t.length;i++){const l=t[i];s=I([...n,...l.key],l.value,s)}return s},_e=({response:{responseStatus:e,...t},cdeebee:r,mergeListStrategy:n,primaryKey:s})=>{const i=Object.keys(t);for(const l of i){const m={};if(t[l]instanceof Object&&Object.prototype.hasOwnProperty.call(t[l],s)){for(const g of t[l].data)m[g[t[l][s]]]=g;n[l]===ee.replace?t[l]=m:t[l]=K(r[l],m)}else(t[l]===null||t[l]===void 0||typeof t[l]=="string")&&(t=Z([l],t))}return t},Fe=Object.freeze(Object.defineProperty({__proto__:null,batchingUpdate:he,checkNetworkActivity:qe,commitEntity:ke,defaultNormalize:_e,dropRequestFromArray:Ee,editEntity:pe,getEntityState:Q,getSubEntity:je,insertEntity:He,requestCancel:ye,resetEntity:de},Symbol.toStringTag,{value:"Module"})),be={},xe=(e=be,t)=>{const{type:r,payload:n}=t;switch(r){case y.CDEEBEEE_UPDATE:return{...e,...n.response};case y.CDEEBEE_ENTITY_CHANGE_FIELD:{const s=pe(e,n.entityList,n.entityID);return he(s,n.valueList,[n.entityList,n.entityID,"__entity"])}case y.CDEEBEE_ENTITY_UNSAFE_UPDATE_STORE:return I([n.entityList,n.entityID],n.value,e);case y.CDEEBEE_SET_ENTITY:return I([n.entityList,n.entityID],n.entity,e);case y.CDEEBEE_RESET_ENTITY:{const s=e[n.entityList];return I([n.entityList,n.entityID],de(s[n.entityID]),e)}case y.CDEEBEEE_DROP:return be;case y.CDEEBEEE_DROP_PATH:return Z(n.path,e);default:return e}},ve={activeRequest:[],requestByApiUrl:{},errorHandler:{}},Me=(e=ve,t)=>{const{type:r,payload:n}=t;switch(r){case y.CDEEBEE_REQUESTMANAGER_SET:return{...e,activeRequest:[...e.activeRequest,n]};case y.CDEEBEE_REQUESTMANAGER_SHIFT:return{...e,activeRequest:Se(1,1/0,e.activeRequest)};case y.CDEEBEEE_UPDATE:return{...e,requestByApiUrl:{...e.requestByApiUrl,[n.api]:n.cleanResponse}};case y.CDEEBEEE_DROP_REQUEST_BY_API_URL:return{...e,requestByApiUrl:le(n.api,e.requestByApiUrl)};case y.CDEEBEEE_DROP_ERROR_BY_API_URL:return{...e,errorHandler:le(n.api,e.errorHandler)};case y.CDEEBEE_ERRORHANDLER_SET:return{...e,errorHandler:{...e.errorHandler,[n.api]:n.cleanResponse}};case y.CDEEBEE_INTERNAL_ERROR:return{...e,activeRequest:[],requestByApiUrl:{}};case y.CHANGE_ROUTE:return{...ve,activeRequest:Ee(e.activeRequest)};default:return e}};var Ge=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},me={},Ae;function Ye(){return Ae||(Ae=1,function(e){e()}(function(){function e(o,a){(a==null||a>o.length)&&(a=o.length);for(var u=0,c=Array(a);u<a;u++)c[u]=o[u];return c}function t(o){if(o===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return o}function r(o,a,u){return a=g(a),x(o,T()?Reflect.construct(a,[],g(o).constructor):a.apply(o,u))}function n(o,a){if(!(o instanceof a))throw new TypeError("Cannot call a class as a function")}function s(o,a){for(var u=0;u<a.length;u++){var c=a[u];c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(o,se(c.key),c)}}function i(o,a,u){return a&&s(o.prototype,a),u&&s(o,u),Object.defineProperty(o,"prototype",{writable:!1}),o}function l(o,a){var u=typeof Symbol<"u"&&o[Symbol.iterator]||o["@@iterator"];if(!u){if(Array.isArray(o)||(u=W(o))||a){u&&(o=u);var c=0,E=function(){};return{s:E,n:function(){return c>=o.length?{done:!0}:{done:!1,value:o[c++]}},e:function(f){throw f},f:E}}throw new TypeError(`Invalid attempt to iterate non-iterable instance.
|
|
2
|
+
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}var _,w=!0,b=!1;return{s:function(){u=u.call(o)},n:function(){var f=u.next();return w=f.done,f},e:function(f){b=!0,_=f},f:function(){try{w||u.return==null||u.return()}finally{if(b)throw _}}}}function m(){return m=typeof Reflect<"u"&&Reflect.get?Reflect.get.bind():function(o,a,u){var c=z(o,a);if(c){var E=Object.getOwnPropertyDescriptor(c,a);return E.get?E.get.call(arguments.length<3?o:u):E.value}},m.apply(null,arguments)}function g(o){return g=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(a){return a.__proto__||Object.getPrototypeOf(a)},g(o)}function p(o,a){if(typeof a!="function"&&a!==null)throw new TypeError("Super expression must either be null or a function");o.prototype=Object.create(a&&a.prototype,{constructor:{value:o,writable:!0,configurable:!0}}),Object.defineProperty(o,"prototype",{writable:!1}),a&&L(o,a)}function T(){try{var o=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(T=function(){return!!o})()}function x(o,a){if(a&&(typeof a=="object"||typeof a=="function"))return a;if(a!==void 0)throw new TypeError("Derived constructors may only return object or undefined");return t(o)}function L(o,a){return L=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(u,c){return u.__proto__=c,u},L(o,a)}function z(o,a){for(;!{}.hasOwnProperty.call(o,a)&&(o=g(o))!==null;);return o}function ie(o,a,u,c){var E=m(g(o.prototype),a,u);return typeof E=="function"?function(_){return E.apply(u,_)}:E}function $(o,a){if(typeof o!="object"||!o)return o;var u=o[Symbol.toPrimitive];if(u!==void 0){var c=u.call(o,a);if(typeof c!="object")return c;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(o)}function se(o){var a=$(o,"string");return typeof a=="symbol"?a:a+""}function W(o,a){if(o){if(typeof o=="string")return e(o,a);var u={}.toString.call(o).slice(8,-1);return u==="Object"&&o.constructor&&(u=o.constructor.name),u==="Map"||u==="Set"?Array.from(o):u==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(u)?e(o,a):void 0}}function ae(o){var a;try{a=new Event("abort")}catch{typeof document<"u"?document.createEvent?(a=document.createEvent("Event"),a.initEvent("abort",!1,!1)):(a=document.createEventObject(),a.type="abort"):a={type:"abort",bubbles:!1,cancelable:!1}}return a.reason=o,a}function ue(o){if(o===void 0)if(typeof document>"u")o=new Error("This operation was aborted"),o.name="AbortError";else try{o=new DOMException("signal is aborted without reason"),Object.defineProperty(o,"name",{value:"AbortError"})}catch{o=new Error("This operation was aborted"),o.name="AbortError"}return o}var V=function(){function o(){n(this,o),Object.defineProperty(this,"listeners",{value:{},writable:!0,configurable:!0})}return i(o,[{key:"addEventListener",value:function(u,c,E){u in this.listeners||(this.listeners[u]=[]),this.listeners[u].push({callback:c,options:E})}},{key:"removeEventListener",value:function(u,c){if(u in this.listeners){for(var E=this.listeners[u],_=0,w=E.length;_<w;_++)if(E[_].callback===c){E.splice(_,1);return}}}},{key:"dispatchEvent",value:function(u){var c=this;if(u.type in this.listeners){for(var E=this.listeners[u.type],_=E.slice(),w=function(){var D=_[b];try{D.callback.call(c,u)}catch(J){Promise.resolve().then(function(){throw J})}D.options&&D.options.once&&c.removeEventListener(u.type,D.callback)},b=0,f=_.length;b<f;b++)w();return!u.defaultPrevented}}}])}(),M=function(o){function a(){var u;return n(this,a),u=r(this,a),u.listeners||V.call(u),Object.defineProperty(u,"aborted",{value:!1,writable:!0,configurable:!0}),Object.defineProperty(u,"onabort",{value:null,writable:!0,configurable:!0}),Object.defineProperty(u,"reason",{value:void 0,writable:!0,configurable:!0}),u}return p(a,o),i(a,[{key:"toString",value:function(){return"[object AbortSignal]"}},{key:"dispatchEvent",value:function(c){c.type==="abort"&&(this.aborted=!0,typeof this.onabort=="function"&&this.onabort.call(this,c)),ie(a,"dispatchEvent",this)([c])}},{key:"throwIfAborted",value:function(){var c=this.aborted,E=this.reason,_=E===void 0?"Aborted":E;if(c)throw _}}],[{key:"timeout",value:function(c){var E=new q;return setTimeout(function(){return E.abort(new DOMException("This signal is timeout in ".concat(c,"ms"),"TimeoutError"))},c),E.signal}},{key:"any",value:function(c){var E=new q;function _(){E.abort(this.reason),w()}function w(){var D=l(c),J;try{for(D.s();!(J=D.n()).done;){var Et=J.value;Et.removeEventListener("abort",_)}}catch(yt){D.e(yt)}finally{D.f()}}var b=l(c),f;try{for(b.s();!(f=b.n()).done;){var X=f.value;if(X.aborted){E.abort(X.reason);break}else X.addEventListener("abort",_)}}catch(D){b.e(D)}finally{b.f()}return E.signal}}])}(V),q=function(){function o(){n(this,o),Object.defineProperty(this,"signal",{value:new M,writable:!0,configurable:!0})}return i(o,[{key:"abort",value:function(u){var c=ue(u),E=ae(c);this.signal.reason=c,this.signal.dispatchEvent(E)}},{key:"toString",value:function(){return"[object AbortController]"}}])}();typeof Symbol<"u"&&Symbol.toStringTag&&(q.prototype[Symbol.toStringTag]="AbortController",M.prototype[Symbol.toStringTag]="AbortSignal");function O(o){return o.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL?(console.log("__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill"),!0):typeof o.Request=="function"&&!o.Request.prototype.hasOwnProperty("signal")||!o.AbortController}(function(o){O(o)&&(o.AbortController=q,o.AbortSignal=M)})(typeof self<"u"?self:Ge)})),me}Ye();var v=typeof globalThis<"u"&&globalThis||typeof self<"u"&&self||typeof global<"u"&&global||{},A={searchParams:"URLSearchParams"in v,iterable:"Symbol"in v&&"iterator"in Symbol,blob:"FileReader"in v&&"Blob"in v&&function(){try{return new Blob,!0}catch{return!1}}(),formData:"FormData"in v,arrayBuffer:"ArrayBuffer"in v};function Ke(e){return e&&DataView.prototype.isPrototypeOf(e)}if(A.arrayBuffer)var Qe=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],ze=ArrayBuffer.isView||function(e){return e&&Qe.indexOf(Object.prototype.toString.call(e))>-1};function H(e){if(typeof e!="string"&&(e=String(e)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(e)||e==="")throw new TypeError('Invalid character in header field name: "'+e+'"');return e.toLowerCase()}function te(e){return typeof e!="string"&&(e=String(e)),e}function re(e){var t={next:function(){var r=e.shift();return{done:r===void 0,value:r}}};return A.iterable&&(t[Symbol.iterator]=function(){return t}),t}function h(e){this.map={},e instanceof h?e.forEach(function(t,r){this.append(r,t)},this):Array.isArray(e)?e.forEach(function(t){if(t.length!=2)throw new TypeError("Headers constructor: expected name/value pair to be length 2, found"+t.length);this.append(t[0],t[1])},this):e&&Object.getOwnPropertyNames(e).forEach(function(t){this.append(t,e[t])},this)}h.prototype.append=function(e,t){e=H(e),t=te(t);var r=this.map[e];this.map[e]=r?r+", "+t:t},h.prototype.delete=function(e){delete this.map[H(e)]},h.prototype.get=function(e){return e=H(e),this.has(e)?this.map[e]:null},h.prototype.has=function(e){return this.map.hasOwnProperty(H(e))},h.prototype.set=function(e,t){this.map[H(e)]=te(t)},h.prototype.forEach=function(e,t){for(var r in this.map)this.map.hasOwnProperty(r)&&e.call(t,this.map[r],r,this)},h.prototype.keys=function(){var e=[];return this.forEach(function(t,r){e.push(r)}),re(e)},h.prototype.values=function(){var e=[];return this.forEach(function(t){e.push(t)}),re(e)},h.prototype.entries=function(){var e=[];return this.forEach(function(t,r){e.push([r,t])}),re(e)},A.iterable&&(h.prototype[Symbol.iterator]=h.prototype.entries);function ne(e){if(!e._noBody){if(e.bodyUsed)return Promise.reject(new TypeError("Already read"));e.bodyUsed=!0}}function ge(e){return new Promise(function(t,r){e.onload=function(){t(e.result)},e.onerror=function(){r(e.error)}})}function $e(e){var t=new FileReader,r=ge(t);return t.readAsArrayBuffer(e),r}function We(e){var t=new FileReader,r=ge(t),n=/charset=([A-Za-z0-9_-]+)/.exec(e.type),s=n?n[1]:"utf-8";return t.readAsText(e,s),r}function Ve(e){for(var t=new Uint8Array(e),r=new Array(t.length),n=0;n<t.length;n++)r[n]=String.fromCharCode(t[n]);return r.join("")}function Re(e){if(e.slice)return e.slice(0);var t=new Uint8Array(e.byteLength);return t.set(new Uint8Array(e)),t.buffer}function Te(){return this.bodyUsed=!1,this._initBody=function(e){this.bodyUsed=this.bodyUsed,this._bodyInit=e,e?typeof e=="string"?this._bodyText=e:A.blob&&Blob.prototype.isPrototypeOf(e)?this._bodyBlob=e:A.formData&&FormData.prototype.isPrototypeOf(e)?this._bodyFormData=e:A.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)?this._bodyText=e.toString():A.arrayBuffer&&A.blob&&Ke(e)?(this._bodyArrayBuffer=Re(e.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):A.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(e)||ze(e))?this._bodyArrayBuffer=Re(e):this._bodyText=e=Object.prototype.toString.call(e):(this._noBody=!0,this._bodyText=""),this.headers.get("content-type")||(typeof e=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):A.searchParams&&URLSearchParams.prototype.isPrototypeOf(e)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},A.blob&&(this.blob=function(){var e=ne(this);if(e)return e;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))}),this.arrayBuffer=function(){if(this._bodyArrayBuffer){var e=ne(this);return e||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer))}else{if(A.blob)return this.blob().then($e);throw new Error("could not read as ArrayBuffer")}},this.text=function(){var e=ne(this);if(e)return e;if(this._bodyBlob)return We(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(Ve(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},A.formData&&(this.formData=function(){return this.text().then(Ze)}),this.json=function(){return this.text().then(JSON.parse)},this}var Xe=["CONNECT","DELETE","GET","HEAD","OPTIONS","PATCH","POST","PUT","TRACE"];function Je(e){var t=e.toUpperCase();return Xe.indexOf(t)>-1?t:e}function N(e,t){if(!(this instanceof N))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');t=t||{};var r=t.body;if(e instanceof N){if(e.bodyUsed)throw new TypeError("Already read");this.url=e.url,this.credentials=e.credentials,t.headers||(this.headers=new h(e.headers)),this.method=e.method,this.mode=e.mode,this.signal=e.signal,!r&&e._bodyInit!=null&&(r=e._bodyInit,e.bodyUsed=!0)}else this.url=String(e);if(this.credentials=t.credentials||this.credentials||"same-origin",(t.headers||!this.headers)&&(this.headers=new h(t.headers)),this.method=Je(t.method||this.method||"GET"),this.mode=t.mode||this.mode||null,this.signal=t.signal||this.signal||function(){if("AbortController"in v){var i=new AbortController;return i.signal}}(),this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&r)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(r),(this.method==="GET"||this.method==="HEAD")&&(t.cache==="no-store"||t.cache==="no-cache")){var n=/([?&])_=[^&]*/;if(n.test(this.url))this.url=this.url.replace(n,"$1_="+new Date().getTime());else{var s=/\?/;this.url+=(s.test(this.url)?"&":"?")+"_="+new Date().getTime()}}}N.prototype.clone=function(){return new N(this,{body:this._bodyInit})};function Ze(e){var t=new FormData;return e.trim().split("&").forEach(function(r){if(r){var n=r.split("="),s=n.shift().replace(/\+/g," "),i=n.join("=").replace(/\+/g," ");t.append(decodeURIComponent(s),decodeURIComponent(i))}}),t}function et(e){var t=new h,r=e.replace(/\r?\n[\t ]+/g," ");return r.split("\r").map(function(n){return n.indexOf(`
|
|
3
|
+
`)===0?n.substr(1,n.length):n}).forEach(function(n){var s=n.split(":"),i=s.shift().trim();if(i){var l=s.join(":").trim();try{t.append(i,l)}catch(m){console.warn("Response "+m.message)}}}),t}Te.call(N.prototype);function S(e,t){if(!(this instanceof S))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');if(t||(t={}),this.type="default",this.status=t.status===void 0?200:t.status,this.status<200||this.status>599)throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].");this.ok=this.status>=200&&this.status<300,this.statusText=t.statusText===void 0?"":""+t.statusText,this.headers=new h(t.headers),this.url=t.url||"",this._initBody(e)}Te.call(S.prototype),S.prototype.clone=function(){return new S(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},S.error=function(){var e=new S(null,{status:200,statusText:""});return e.ok=!1,e.status=0,e.type="error",e};var tt=[301,302,303,307,308];S.redirect=function(e,t){if(tt.indexOf(t)===-1)throw new RangeError("Invalid status code");return new S(null,{status:t,headers:{location:e}})};var U=v.DOMException;try{new U}catch{U=function(t,r){this.message=t,this.name=r;var n=Error(t);this.stack=n.stack},U.prototype=Object.create(Error.prototype),U.prototype.constructor=U}function oe(e,t){return new Promise(function(r,n){var s=new N(e,t);if(s.signal&&s.signal.aborted)return n(new U("Aborted","AbortError"));var i=new XMLHttpRequest;function l(){i.abort()}i.onload=function(){var p={statusText:i.statusText,headers:et(i.getAllResponseHeaders()||"")};s.url.indexOf("file://")===0&&(i.status<200||i.status>599)?p.status=200:p.status=i.status,p.url="responseURL"in i?i.responseURL:p.headers.get("X-Request-URL");var T="response"in i?i.response:i.responseText;setTimeout(function(){r(new S(T,p))},0)},i.onerror=function(){setTimeout(function(){n(new TypeError("Network request failed"))},0)},i.ontimeout=function(){setTimeout(function(){n(new TypeError("Network request timed out"))},0)},i.onabort=function(){setTimeout(function(){n(new U("Aborted","AbortError"))},0)};function m(p){try{return p===""&&v.location.href?v.location.href:p}catch{return p}}if(i.open(s.method,m(s.url),!0),s.credentials==="include"?i.withCredentials=!0:s.credentials==="omit"&&(i.withCredentials=!1),"responseType"in i&&(A.blob?i.responseType="blob":A.arrayBuffer&&(i.responseType="arraybuffer")),t&&typeof t.headers=="object"&&!(t.headers instanceof h||v.Headers&&t.headers instanceof v.Headers)){var g=[];Object.getOwnPropertyNames(t.headers).forEach(function(p){g.push(H(p)),i.setRequestHeader(p,te(t.headers[p]))}),s.headers.forEach(function(p,T){g.indexOf(T)===-1&&i.setRequestHeader(T,p)})}else s.headers.forEach(function(p,T){i.setRequestHeader(T,p)});s.signal&&(s.signal.addEventListener("abort",l),i.onreadystatechange=function(){i.readyState===4&&s.signal.removeEventListener("abort",l)}),i.send(typeof s._bodyInit>"u"?null:s._bodyInit)})}oe.polyfill=!0,v.fetch||(v.fetch=oe,v.Headers=h,v.Request=N,v.Response=S);let F={};const rt=typeof window<"u"?"signal"in new Request("")?window.fetch:oe:fetch;class nt{constructor(t,r){this.send=n=>async(s,i)=>{var a,u;const{api:l,preUpdate:m,postUpdate:g,preError:p,postError:T,data:x,files:L,requestCancel:z=!0,updateStore:ie=!0,fileKey:$=this.options.fileKey,primaryKey:se=this.options.primaryKey,bodyKey:W=this.options.bodyKey,method:ae=this.options.method,normalize:ue=this.options.normalize,mergeListStrategy:V=this.options.mergeListStrategy,headers:M=this.options.headers,responseKeyCode:q=this.options.responseKeyCode}=K(this.requestObject,n),O=Math.random().toString(36).substr(2),o=new Date;try{let c=JSON.stringify({...x,requestID:O});const E=new AbortController,{signal:_}=E;if(s({type:y.CDEEBEE_REQUESTMANAGER_SET,payload:{requestID:O,api:l,controller:E,data:x,requestCancel:z,requestStartTime:o,requestEndTime:void 0}}),L){const b=new FormData;for(let f=0;f<L.length;f+=1)$&&b.append($,L[f]);W&&b.append(W,c),c=b}const w=await(await rt(l,{method:ae,signal:_,headers:{"ui-request-id":O,...M},body:c})).json();if(w)for(F=Object.assign({[O]:{requestID:O,response:w,requestApi:l,requestStartTime:o,preUpdate:m,postUpdate:g,normalize:ue,preError:p,postError:T,mergeListStrategy:V,updateStore:ie,data:x,requestCancel:z,controller:E}},F);F[(u=(a=i().requestManager.activeRequest)==null?void 0:a[0])==null?void 0:u.requestID];){const b=i().requestManager.activeRequest[0].requestID,f=F[b];q&&f.response[q]===0?(f.preUpdate&&f.preUpdate(f.response),f.updateStore&&s({type:y.CDEEBEEE_UPDATE,payload:{response:f.normalize instanceof Function&&f.normalize({response:f.response,cdeebee:i().cdeebee,mergeListStrategy:f.mergeListStrategy,primaryKey:se}),cleanResponse:f.response,api:f.requestApi,mergeListStrategy:f.mergeListStrategy}}),f.postUpdate&&f.postUpdate(f.response)):(f.preError&&f.preError(f.response),s({type:y.CDEEBEE_ERRORHANDLER_SET,payload:{api:f.requestApi,cleanResponse:f.response}}),f.postError&&f.postError(w)),s({type:y.CDEEBEE_REQUESTMANAGER_SHIFT,payload:{requestID:f.requestID,api:f.requestApi,controller:f.controller,data:f.data,requestCancel:f.requestCancel,requestStartTime:f.requestStartTime,requestEndTime:new Date}}),delete F[b]}}catch(c){if(c.name==="AbortError")s({type:y.CDEEBEE_REQUEST_ABORTED,payload:{requestID:O,api:l}});else{const E=new Date;s({type:y.CDEEBEE_INTERNAL_ERROR,payload:{requestStartTime:o,requestEndTime:E,requestID:O,api:l}}),console.warn("@@makeRequest-error",c),console.warn("@@makeRequest-object",K(this.requestObject,n)),console.warn("@@makeRequest-info",{requestStartTime:o,requestEndTime:E,requestID:O}),Object.prototype.hasOwnProperty.call(this.options,"globalErrorHandler")&&this.options.globalErrorHandler instanceof Function&&this.options.globalErrorHandler(c,K(this.requestObject,n),{requestStartTime:o,requestEndTime:E,requestID:O})(s,i)}}},this.requestObject=t,this.options={fileKey:"files",bodyKey:"body",method:"POST",primaryKey:"primaryKey",normalize:_e,responseKeyCode:"responseStatus",headers:{"content-type":"application/json"},...r}}}function ot(e,t,r){return n=>{n({type:y.CDEEBEE_ENTITY_UNSAFE_UPDATE_STORE,payload:{entityList:e,entityID:t,value:r}})}}function it(e,t,r){return n=>{n({type:y.CDEEBEE_ENTITY_CHANGE_FIELD,payload:{entityList:e,entityID:t,valueList:r}})}}function st(e,t,r){return n=>{n({type:y.CDEEBEE_SET_ENTITY,payload:{entityList:e,entityID:t,entity:r}})}}function at(e,t){return r=>{r({type:y.CDEEBEE_RESET_ENTITY,payload:{entityList:e,entityID:t}})}}function ut(e){return t=>t({type:y.CDEEBEEE_DROP_PATH,payload:{path:e}})}function ct(e){return t=>t({type:y.CDEEBEEE_DROP_REQUEST_BY_API_URL,payload:{api:e}})}function lt(e){return t=>t({type:y.CDEEBEEE_DROP_ERROR_BY_API_URL,payload:{api:e}})}const ft=Object.freeze(Object.defineProperty({__proto__:null,commitEntity:st,dropCdeebeePath:ut,dropErrorsByApiUrl:lt,dropRequestByApiUrl:ct,resetEntity:at,setKeyValue:it,unsafe_updateStore:ot},Symbol.toStringTag,{value:"Module"}));R.CdeebeeRequest=nt,R.cdeebee=xe,R.cdeebeeActions=ft,R.cdeebeeEntityState=C,R.cdeebeeHelpers=Fe,R.cdeebeeMergeStrategy=ee,R.cdeebeeTypes=y,R.requestManager=Me,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"})});
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { Dispatch } from 'redux';
|
|
2
|
+
export declare enum cdeebeeTypes {
|
|
3
|
+
CDEEBEE_REQUESTMANAGER_SHIFT = "@@cdeebee/REQUESTMANAGER_SHIFT",
|
|
4
|
+
CDEEBEE_REQUESTMANAGER_SET = "@@cdeebee/REQUESTMANAGER_SET",
|
|
5
|
+
CDEEBEE_ERRORHANDLER_SET = "@@cdeebee/ERRORHANDLER_SET",
|
|
6
|
+
CDEEBEE_ENTITY_CHANGE_FIELD = "@@cdeebee/ENTITY_CHANGE_FIELD",
|
|
7
|
+
CDEEBEE_ENTITY_UNSAFE_UPDATE_STORE = "@@cdeebee/ENTITY_UNSAFE_UPDATE_STORE",
|
|
8
|
+
CDEEBEE_RESET_ENTITY = "@@cdeebee/RESET_ENTITY",
|
|
9
|
+
CDEEBEE_SET_ENTITY = "@@cdeebee/SET_ENTITY",
|
|
10
|
+
CDEEBEEE_UPDATE = "@@cdeebee/UPDATE",
|
|
11
|
+
CDEEBEEE_DROP = "@@cdeebee/DROP",
|
|
12
|
+
CDEEBEEE_DROP_PATH = "@@cdeebee/DROP_PATH",
|
|
13
|
+
CDEEBEE_INTERNAL_ERROR = "@@cdeebee/INTERNAL_ERROR",
|
|
14
|
+
CDEEBEE_REQUEST_ABORTED = "@@cdeebee/REQUEST_ABORTED",
|
|
15
|
+
CDEEBEEE_DROP_REQUEST_BY_API_URL = "@@cdeebee/DROP_REQUEST_BY_API_URL",
|
|
16
|
+
CDEEBEEE_DROP_ERROR_BY_API_URL = "@@cdeebee/DROP_ERROR_BY_API_URL",
|
|
17
|
+
CHANGE_ROUTE = "@@router/LOCATION_CHANGE"
|
|
18
|
+
}
|
|
19
|
+
export declare enum cdeebeeEntityState {
|
|
20
|
+
NEW = "NEW",
|
|
21
|
+
EDITING = "EDITING",
|
|
22
|
+
NORMAL = "NORMAL"
|
|
23
|
+
}
|
|
24
|
+
export declare enum cdeebeeMergeStrategy {
|
|
25
|
+
merge = "merge",
|
|
26
|
+
replace = "replace"
|
|
27
|
+
}
|
|
28
|
+
export type IDefaultOption = {
|
|
29
|
+
headers?: object;
|
|
30
|
+
files?: File[];
|
|
31
|
+
fileKey?: string;
|
|
32
|
+
bodyKey?: string;
|
|
33
|
+
primaryKey?: string;
|
|
34
|
+
responseKeyCode?: string;
|
|
35
|
+
requestCancel?: boolean;
|
|
36
|
+
updateStore?: boolean;
|
|
37
|
+
mergeListStrategy?: {
|
|
38
|
+
[key: string]: cdeebeeMergeStrategy;
|
|
39
|
+
};
|
|
40
|
+
normalize?: (t: any) => void;
|
|
41
|
+
preUpdate?: (payload: object) => void;
|
|
42
|
+
postUpdate?: (payload: object) => void;
|
|
43
|
+
preError?: (payload: object) => void;
|
|
44
|
+
postError?: (payload: object) => void;
|
|
45
|
+
method?: 'POST' | 'GET' | 'PUT' | 'DELETE';
|
|
46
|
+
globalErrorHandler?: (error: object, request: object, meta: {
|
|
47
|
+
requestStartTime: Date;
|
|
48
|
+
requestEndTime: Date;
|
|
49
|
+
requestID: string;
|
|
50
|
+
}) => (dispatch: Dispatch, getState: () => object) => void;
|
|
51
|
+
};
|
|
52
|
+
export type IResponsePropObject = {
|
|
53
|
+
requestID: string;
|
|
54
|
+
controller: AbortController;
|
|
55
|
+
updateStore: boolean;
|
|
56
|
+
data: object;
|
|
57
|
+
requestCancel: boolean;
|
|
58
|
+
requestApi: string;
|
|
59
|
+
response: {
|
|
60
|
+
[params: string]: unknown;
|
|
61
|
+
};
|
|
62
|
+
requestStartTime?: Date;
|
|
63
|
+
mergeListStrategy?: {
|
|
64
|
+
[key: string]: cdeebeeMergeStrategy;
|
|
65
|
+
};
|
|
66
|
+
normalize?: (t: any) => void;
|
|
67
|
+
preUpdate?: (payload: object) => void;
|
|
68
|
+
postUpdate?: (payload: object) => void;
|
|
69
|
+
preError?: (payload: object) => void;
|
|
70
|
+
postError?: (payload: object) => void;
|
|
71
|
+
};
|
|
72
|
+
export interface IRequestOptions extends IDefaultOption {
|
|
73
|
+
api: string;
|
|
74
|
+
data?: object;
|
|
75
|
+
}
|
|
76
|
+
export interface IEntity {
|
|
77
|
+
__entity?: {
|
|
78
|
+
__state: cdeebeeEntityState;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export type cdeebeeValueList = {
|
|
82
|
+
key: (string | number)[];
|
|
83
|
+
value: any;
|
|
84
|
+
};
|
|
85
|
+
export type cdeebeActiveRequest = {
|
|
86
|
+
api: string;
|
|
87
|
+
requestCancel: object;
|
|
88
|
+
controller: {
|
|
89
|
+
abort: () => void;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
export type EntityID = string | number;
|
|
93
|
+
export interface cdeebeeIActions {
|
|
94
|
+
dropRequestByApiUrl: (api: string) => void;
|
|
95
|
+
dropErrorsByApiUrl: (api: string) => void;
|
|
96
|
+
dropCdeebeePath: (path: (string | number)[]) => void;
|
|
97
|
+
setKeyValue: (entityList: string, entityID: EntityID, valueList: cdeebeeValueList[]) => void;
|
|
98
|
+
unsafe_updateStore: (entityList: string, entityID: EntityID, value: any) => void;
|
|
99
|
+
commitEntity: (entityList: string, entityID: EntityID, entity: object) => void;
|
|
100
|
+
resetEntity: (entityList: string, entityID: EntityID) => void;
|
|
101
|
+
}
|
|
102
|
+
export type ActionCreator<A> = (...args: any[]) => A;
|
|
103
|
+
export declare class CdeebeeRequest {
|
|
104
|
+
requestObject: any;
|
|
105
|
+
constructor(defaultRequest: object, options: {
|
|
106
|
+
fileKey?: string;
|
|
107
|
+
bodyKey?: string;
|
|
108
|
+
method?: string;
|
|
109
|
+
primaryKey?: string;
|
|
110
|
+
normalize?: (data: object) => object;
|
|
111
|
+
mergeListStrategy?: {
|
|
112
|
+
[key: string]: cdeebeeMergeStrategy;
|
|
113
|
+
};
|
|
114
|
+
responseKeyCode?: string;
|
|
115
|
+
header?: object;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
export interface CDEEBEERequestManager {
|
|
119
|
+
readonly type: cdeebeeTypes.CDEEBEE_REQUESTMANAGER_SET;
|
|
120
|
+
readonly payload: object;
|
|
121
|
+
}
|
|
122
|
+
export interface CDEEBEERequestShift {
|
|
123
|
+
readonly type: cdeebeeTypes.CDEEBEE_REQUESTMANAGER_SHIFT;
|
|
124
|
+
readonly payload?: any;
|
|
125
|
+
}
|
|
126
|
+
export interface CDEEBEEUpdate {
|
|
127
|
+
readonly type: cdeebeeTypes.CDEEBEEE_UPDATE;
|
|
128
|
+
readonly payload: {
|
|
129
|
+
api: string;
|
|
130
|
+
cleanResponse: object;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
export interface CDEEBEEErrorSet {
|
|
134
|
+
readonly type: cdeebeeTypes.CDEEBEE_ERRORHANDLER_SET;
|
|
135
|
+
readonly payload: {
|
|
136
|
+
api: string;
|
|
137
|
+
cleanResponse: object;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
export interface CDEEBEEChangeRoute {
|
|
141
|
+
readonly type?: any;
|
|
142
|
+
readonly payload?: any;
|
|
143
|
+
}
|
|
144
|
+
export type IRequestAction = CDEEBEERequestManager | CDEEBEERequestShift | CDEEBEEUpdate | CDEEBEEErrorSet | CDEEBEEChangeRoute;
|
|
145
|
+
export interface IRequestState {
|
|
146
|
+
activeRequest: cdeebeActiveRequest[];
|
|
147
|
+
requestByApiUrl: object;
|
|
148
|
+
errorHandler: object;
|
|
149
|
+
}
|
|
150
|
+
export interface CDEEBEEUpadte {
|
|
151
|
+
readonly type: cdeebeeTypes.CDEEBEEE_UPDATE;
|
|
152
|
+
readonly payload: {
|
|
153
|
+
response: object;
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
export interface CDEEBEEChangeField {
|
|
157
|
+
readonly type: cdeebeeTypes.CDEEBEE_ENTITY_CHANGE_FIELD;
|
|
158
|
+
readonly payload: {
|
|
159
|
+
valueList: cdeebeeValueList[];
|
|
160
|
+
entityList: string;
|
|
161
|
+
entityID: number | string;
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
export interface CDEEBEESetEntity {
|
|
165
|
+
readonly type: cdeebeeTypes.CDEEBEE_SET_ENTITY;
|
|
166
|
+
readonly payload: {
|
|
167
|
+
entityList: string;
|
|
168
|
+
entityID: number | string;
|
|
169
|
+
entity: any;
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
export interface CDEEBEEUnsafeUpdateStore {
|
|
173
|
+
readonly type: cdeebeeTypes.CDEEBEE_ENTITY_UNSAFE_UPDATE_STORE;
|
|
174
|
+
readonly payload: {
|
|
175
|
+
entityList: string;
|
|
176
|
+
entityID: number | string;
|
|
177
|
+
value: any;
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
export interface CDEEBEEResetEntity {
|
|
181
|
+
readonly type: cdeebeeTypes.CDEEBEE_RESET_ENTITY;
|
|
182
|
+
readonly payload: {
|
|
183
|
+
entityList: string;
|
|
184
|
+
entityID: number | string;
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
export interface CDEEBEEDrop {
|
|
188
|
+
readonly type: cdeebeeTypes.CDEEBEEE_DROP;
|
|
189
|
+
readonly payload?: any;
|
|
190
|
+
}
|
|
191
|
+
export interface CDEEBEEDropPath {
|
|
192
|
+
readonly type: cdeebeeTypes.CDEEBEEE_DROP_PATH;
|
|
193
|
+
readonly payload: {
|
|
194
|
+
path: (string | number)[];
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
export type ICdeebee = CDEEBEEUpadte | CDEEBEEChangeField | CDEEBEESetEntity | CDEEBEEResetEntity | CDEEBEEDrop | CDEEBEEDropPath | CDEEBEEUnsafeUpdateStore;
|
|
198
|
+
export interface IDefaultNormalize {
|
|
199
|
+
response: {
|
|
200
|
+
responseStatus: string;
|
|
201
|
+
[params: string]: any;
|
|
202
|
+
};
|
|
203
|
+
cdeebee: object;
|
|
204
|
+
primaryKey: string;
|
|
205
|
+
mergeListStrategy: {
|
|
206
|
+
[key: string]: cdeebeeMergeStrategy;
|
|
207
|
+
};
|
|
208
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { cdeebeActiveRequest, cdeebeeEntityState, cdeebeeValueList, IDefaultNormalize, IEntity } from './definition';
|
|
2
|
+
export declare const dropRequestFromArray: (activeRequest: cdeebeActiveRequest[]) => cdeebeActiveRequest[];
|
|
3
|
+
export declare const requestCancel: (request: cdeebeActiveRequest) => void;
|
|
4
|
+
export declare const checkNetworkActivity: (activeRequest: cdeebeActiveRequest[], apiUrl: string | string[]) => boolean;
|
|
5
|
+
export declare const getSubEntity: <T>(entity: T & IEntity) => {
|
|
6
|
+
__state: cdeebeeEntityState;
|
|
7
|
+
} | (T & IEntity);
|
|
8
|
+
export declare const getEntityState: <T>(entity: T & IEntity) => cdeebeeEntityState;
|
|
9
|
+
export declare const insertEntity: (entity: {
|
|
10
|
+
__state: string;
|
|
11
|
+
}) => {
|
|
12
|
+
__state: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const commitEntity: <T>(entity: T & IEntity) => T;
|
|
15
|
+
export declare const resetEntity: <T>(entity: T & IEntity) => T;
|
|
16
|
+
export declare const editEntity: (store: IEntity & {
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
}, list: string, id: number | string) => IEntity & {
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
};
|
|
21
|
+
export declare const batchingUpdate: (state: object, valueList: cdeebeeValueList[], prePath?: (string | number)[]) => object;
|
|
22
|
+
export declare const defaultNormalize: (d: IDefaultNormalize) => object;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { cdeebee, requestManager } from './reducer';
|
|
2
|
+
import { default as CdeebeeRequest } from './request';
|
|
3
|
+
import { cdeebeeTypes, cdeebeeMergeStrategy, cdeebeeEntityState, cdeebeeValueList, cdeebeActiveRequest, cdeebeeIActions } from './definition';
|
|
4
|
+
import * as cdeebeeHelpers from './helpers';
|
|
5
|
+
import * as cdeebeeActions from './actions';
|
|
6
|
+
export { cdeebeeValueList, cdeebee, cdeebeeHelpers, requestManager, CdeebeeRequest, cdeebeeTypes, cdeebeeEntityState, cdeebeeMergeStrategy, cdeebeeActions, cdeebeActiveRequest, cdeebeeIActions, };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ICdeebee, IRequestAction, IRequestState } from './definition';
|
|
2
|
+
export declare const INITIAL_STORAGE: any;
|
|
3
|
+
export declare const cdeebee: (state: any | undefined, action: ICdeebee) => any;
|
|
4
|
+
export declare const requestManager: (state: IRequestState | undefined, action: IRequestAction) => {
|
|
5
|
+
activeRequest: any[];
|
|
6
|
+
requestByApiUrl: object;
|
|
7
|
+
errorHandler: object;
|
|
8
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Dispatch } from 'redux';
|
|
2
|
+
import { IDefaultOption, IRequestOptions } from './definition';
|
|
3
|
+
export default class requestManager {
|
|
4
|
+
requestObject: object;
|
|
5
|
+
private options;
|
|
6
|
+
constructor(requestObject: object, options: IDefaultOption);
|
|
7
|
+
send: (rq: IRequestOptions) => (dispatch: Dispatch, getState: () => any) => Promise<void>;
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@recats/cdeebee",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"description": "React Redux data-logic library",
|
|
5
5
|
"repository": "git@github.com:recats/cdeebee.git",
|
|
6
|
-
"type": "module",
|
|
7
6
|
"author": "recats",
|
|
8
7
|
"license": "MIT",
|
|
9
8
|
"scripts": {
|
|
@@ -17,10 +16,15 @@
|
|
|
17
16
|
"data",
|
|
18
17
|
"server"
|
|
19
18
|
],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
20
23
|
"types": "./dist/index.d.ts",
|
|
21
24
|
"module": "./dist/cdeebee.js",
|
|
22
25
|
"exports": {
|
|
23
26
|
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
24
28
|
"import": "./dist/cdeebee.js",
|
|
25
29
|
"require": "./dist/cdeebee.umd.cjs"
|
|
26
30
|
}
|
package/.editorconfig
DELETED
package/.travis.yml
DELETED
package/eslint.config.mjs
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import eslint from '@eslint/js';
|
|
2
|
-
import tseslint from 'typescript-eslint';
|
|
3
|
-
import { FlatCompat } from '@eslint/eslintrc'
|
|
4
|
-
|
|
5
|
-
const compat = new FlatCompat()
|
|
6
|
-
|
|
7
|
-
export default tseslint.config(
|
|
8
|
-
{
|
|
9
|
-
ignores: ['**/dist/**', '**/.storybook/**'],
|
|
10
|
-
},
|
|
11
|
-
eslint.configs.recommended,
|
|
12
|
-
...tseslint.configs.recommended,
|
|
13
|
-
...compat.config(),
|
|
14
|
-
{
|
|
15
|
-
files: ['**/*.ts', '**/*.tsx', '**/*.mts'],
|
|
16
|
-
rules: {
|
|
17
|
-
'semi': ['error', 'always'],
|
|
18
|
-
'arrow-parens': ['error', 'as-needed'],
|
|
19
|
-
'no-multiple-empty-lines': ['error', { 'max': 1 }],
|
|
20
|
-
'@typescript-eslint/no-explicit-any': 'warn',
|
|
21
|
-
'object-curly-spacing': [2, 'always'],
|
|
22
|
-
'quotes': [2, 'single', { 'avoidEscape': true }],
|
|
23
|
-
'jsx-quotes': [2, 'prefer-single'],
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
);
|
package/lib/actions.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { Dispatch } from 'redux';
|
|
2
|
-
import { cdeebeeTypes, cdeebeeValueList, EntityID } from './definition';
|
|
3
|
-
|
|
4
|
-
export function unsafe_updateStore(
|
|
5
|
-
entityList: string,
|
|
6
|
-
entityID: EntityID,
|
|
7
|
-
value: unknown,
|
|
8
|
-
) {
|
|
9
|
-
return (dispatch: Dispatch) => {
|
|
10
|
-
dispatch({
|
|
11
|
-
type: cdeebeeTypes.CDEEBEE_ENTITY_UNSAFE_UPDATE_STORE,
|
|
12
|
-
payload: { entityList, entityID, value },
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function setKeyValue(
|
|
18
|
-
entityList: string,
|
|
19
|
-
entityID: EntityID,
|
|
20
|
-
valueList: cdeebeeValueList[],
|
|
21
|
-
) {
|
|
22
|
-
return (dispatch: Dispatch) => {
|
|
23
|
-
dispatch({
|
|
24
|
-
type: cdeebeeTypes.CDEEBEE_ENTITY_CHANGE_FIELD,
|
|
25
|
-
payload: { entityList, entityID, valueList },
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function commitEntity(
|
|
31
|
-
entityList: string,
|
|
32
|
-
entityID: EntityID,
|
|
33
|
-
entity: object,
|
|
34
|
-
) {
|
|
35
|
-
return (dispatch: Dispatch) => {
|
|
36
|
-
dispatch({
|
|
37
|
-
type: cdeebeeTypes.CDEEBEE_SET_ENTITY,
|
|
38
|
-
payload: { entityList, entityID, entity },
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function resetEntity(
|
|
44
|
-
entityList: string,
|
|
45
|
-
entityID: string | number,
|
|
46
|
-
) {
|
|
47
|
-
return (dispatch: Dispatch) => {
|
|
48
|
-
dispatch({
|
|
49
|
-
type: cdeebeeTypes.CDEEBEE_RESET_ENTITY,
|
|
50
|
-
payload: { entityList, entityID },
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function dropCdeebeePath(path: (string | number)[]) {
|
|
56
|
-
return (dispatch: Dispatch) => dispatch({ type: cdeebeeTypes.CDEEBEEE_DROP_PATH, payload: { path } });
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function dropRequestByApiUrl(api: string) {
|
|
60
|
-
return (dispatch: Dispatch) => dispatch({ type: cdeebeeTypes.CDEEBEEE_DROP_REQUEST_BY_API_URL, payload: { api } });
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function dropErrorsByApiUrl(api: string) {
|
|
64
|
-
return (dispatch: Dispatch) => dispatch({ type: cdeebeeTypes.CDEEBEEE_DROP_ERROR_BY_API_URL, payload: { api } });
|
|
65
|
-
}
|