@mediacubeco/base 1.2.0 → 2.0.0

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/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";const t=t=>void 0===t,e=t=>null===t,s=s=>t(s)||e(s),r=t=>"string"==typeof t,i=t=>"object"==typeof t,o=t=>{const e=[n,a,c,u,l,f,p,h,g,m,d].some(e=>e(t));return!!t&&"object"==typeof t&&!e},n=t=>Array.isArray(t),a=t=>t instanceof ArrayBuffer,c=t=>t instanceof Map,u=t=>t instanceof Set,l=t=>t instanceof Map,f=t=>t instanceof Set,p=t=>t instanceof Date,h=t=>t instanceof Error,g=t=>t instanceof RegExp,m=t=>t instanceof Promise,d=t=>t instanceof Function;const x=(t,...e)=>{if(d(t))return t(...e)};function y(t,e){return!(!i(e)||!(t in e))}function b(t,e){return t.filter(t=>e.includes(t))}class E{isDefaultPrevented=!1;constructor(){this.preventDefault=this.preventDefault.bind(this),this.overrideDefault=this.overrideDefault.bind(this)}preventDefault(){this.isDefaultPrevented=!0}overrideDefault(){this.isDefaultPrevented=!1}}class v{subscriptions={};constructor(){this.emit=this.emit.bind(this),this.on=this.on.bind(this),this.off=this.off.bind(this),this.clear=this.clear.bind(this)}emit(t,e,s){const r=this.subscriptions[t];if(r){const{event:t,listenerList:i}=r;i.forEach(s=>x(s,Object.assign(t,e))),t.isDefaultPrevented||x(s)}else x(s)}on(t,e){const s=this.subscriptions[t];return s?s.listenerList.push(e):this.subscriptions[t]={event:new E,listenerList:[e]},()=>this.off(t,e)}off(t,e){const s=this.subscriptions[t];if(s){const{event:r,listenerList:i}=s;this.subscriptions[t]={event:r,listenerList:i.filter(t=>t!==e)},r.overrideDefault()}}clear(t){delete this.subscriptions[t]}}const w=(t="?",...e)=>[`[${(t&&r(t)?t:"?").toUpperCase()}]`,...e.reduce((t,e,s,{length:r})=>{const i=s===r-1?[]:["|"];return t.push(e,...i),t},e.length?["-"]:[])];var D,N,k;!function(t){t.StartGroup="group",t.EndGroup="groupEnd",t.Default="log"}(D||(D={})),function(t){t.Info="%s",t.Success="%s",t.Warning="%s",t.Danger="%s"}(N||(N={}));class S{static formatted={info:(...t)=>S.info(...w(...t)),success:(...t)=>S.success(...w(...t)),warning:(...t)=>S.warning(...w(...t)),danger:(...t)=>S.danger(...w(...t))};static#t(t,...e){console[t](...e)}static startGroup(t,e,...s){S.#t(D.StartGroup,...((t,...e)=>["%c%s",t,...e])(`font-size: 16px;${e}`,...w(t,...s)))}static endGroup(){S.#t(D.EndGroup)}static info(...t){S.#t(D.Default,N.Info,...t)}static success(...t){S.#t(D.Default,N.Success,...t)}static warning(...t){S.#t(D.Default,N.Warning,...t)}static danger(...t){S.#t(D.Default,N.Danger,...t)}}exports.ErrorHandlerEventName=void 0,(k=exports.ErrorHandlerEventName||(exports.ErrorHandlerEventName={})).Capture="capture",k.Forward="forward";class L{static eventEmitter=new v;static caseList=[];static log(t,e={signal:"unknown"}){const{signal:s,message:r,payload:i,stack:o}=e,n=[r,h(t)?t.message:void 0].filter(Boolean);S.formatted.danger(s,...n,{error:t,payload:i,stack:o})}static get on(){return L.eventEmitter.on}static get off(){return L.eventEmitter.off}static get clear(){return L.eventEmitter.clear}static create(t,e){return new Error(t,{cause:e})}static throw(t,e){throw L.create(t,e)}static capture(t,e){L.log(t,e),L.eventEmitter.emit(exports.ErrorHandlerEventName.Capture,{error:t,config:e})}static forward(t,e){throw L.log(t,e),L.eventEmitter.emit(exports.ErrorHandlerEventName.Capture,{error:t,config:e}),t}static case(t){L.caseList.push(t)}static parse(t){const e={message:"Error!",status:0,errors:{},isExternal:!0};for(const{check:s,parse:r}of L.caseList)if(s(t,e))return r(t,e);return!0===h(t)?{message:t.message,status:e.status,errors:e.errors,isExternal:e.isExternal}:{message:e.message,status:e.status,errors:e.errors,isExternal:e.isExternal}}}class j{key;model;config;constructor(t,e,s){this.key=t,this.model=e,this.config=s}async get(t){const{defaultValue:e,withDebug:s}={...this.config,...t},r=await this.model.get(this.key),i=r&&JSON.parse(r)||e;return s&&S.formatted.info("get",this.key,i),i}async set(t,e){const{withDebug:s}={...this.config,...e};await this.model.set(this.key,JSON.stringify(t)),s&&S.formatted.info("set",this.key,t)}async delete(t){const{withDebug:e}={...this.config,...t},s=await this.get({...t,withDebug:!1});await this.model.delete(this.key),e&&S.formatted.info("delete",this.key,s)}async has(t){const{withDebug:e}={...this.config,...t},s=await this.get({...t,withDebug:!1});return e&&S.formatted.info("has",this.key,s),!!s}}exports.ErrorHandler=L,exports.EventEmitter=v,exports.Log=S,exports.Storage=class{model;config;constructor(t,e){this.model=t,this.config=e}async all(){L.throw("Not implemented")}async clear(){L.throw("Not implemented")}create(t){const e={[t]:new j(t,this.model,this.config)};return Object.assign(this,e)}},exports.chunkList=function(t,e){const s=[];for(let r=0;r<t.length;r+=e)s.push(t.slice(r,r+e));return s},exports.compose=function(t,e,r){const i=!o(t);return!s(r)&&{...e,...i?{[r]:t}:t}||!s(e)&&{...e,...t}||{...t}},exports.debounce=(t,e)=>{let s;return(...r)=>{s&&clearTimeout(s),s=setTimeout(()=>x(t,...r),e)}},exports.filterByKey=function(t,e="isVisible"){return t.filter(t=>!y(e,t)||t[e])},exports.filterDuplicateByKey=function(t,e){return t.reduce((t,s)=>t.some(t=>t[e]===s[e])?t:[...t,s],[])},exports.filterEqualValues=b,exports.filterNullableValues=function(t){return t.filter(t=>!s(t))},exports.forceList=function(t){return n(t)?t:[t]},exports.getValueByKey=function(t,e,r){return s(t)?r:2===arguments.length?e[t]:e[t]??r},exports.hasEqualValues=function(t,e){return!!b(t,e).length},exports.hasKey=y,exports.isAnyObject=i,exports.isArray=n,exports.isArrayBuffer=a,exports.isArrayEmpty=function(t){return 0===t.length},exports.isBigint=t=>"bigint"==typeof t,exports.isBoolean=t=>"boolean"==typeof t,exports.isDate=p,exports.isError=h,exports.isFunction=d,exports.isMap=c,exports.isNaN=t=>Number.isNaN(t),exports.isNull=e,exports.isNullable=s,exports.isNumber=t=>"number"==typeof t,exports.isObject=o,exports.isObjectEmpty=function(t){for(const e in t)return!1;return!0},exports.isPromise=m,exports.isProxy=t=>t instanceof Proxy,exports.isRegExp=g,exports.isSet=u,exports.isString=r,exports.isSymbol=t=>"symbol"==typeof t,exports.isUndefined=t,exports.isWeakMap=l,exports.isWeakSet=f,exports.mapRecord=(t,e)=>{const s=Object.entries(t);return Object.fromEntries(s.map(([t,s],r,i)=>[t,e(t,s,r,i)]))},exports.runCallback=x,exports.throttle=(t,e)=>{let s=!0;return(...r)=>{s&&(x(t,...r),s=!1),setTimeout(()=>s=!0,e)}},exports.wait=t=>new Promise(e=>setTimeout(e,t));
1
+ "use strict";const t=t=>void 0===t,e=t=>null===t,s=s=>t(s)||e(s),r=t=>"string"==typeof t,i=t=>"object"==typeof t,o=t=>{const e=[n,a,c,u,l,f,p,h,g,m,d].some(e=>e(t));return!!t&&"object"==typeof t&&!e},n=t=>Array.isArray(t),a=t=>t instanceof ArrayBuffer,c=t=>t instanceof Map,u=t=>t instanceof Set,l=t=>t instanceof Map,f=t=>t instanceof Set,p=t=>t instanceof Date,h=t=>t instanceof Error,g=t=>t instanceof RegExp,m=t=>t instanceof Promise,d=t=>t instanceof Function;const x=(t,...e)=>{if(d(t))return t(...e)};function y(t,e){return!(!i(e)||!(t in e))}function b(t,e){return t.filter(t=>e.includes(t))}class E{isDefaultPrevented=!1;constructor(){this.preventDefault=this.preventDefault.bind(this),this.overrideDefault=this.overrideDefault.bind(this)}preventDefault(){this.isDefaultPrevented=!0}overrideDefault(){this.isDefaultPrevented=!1}}class v{subscriptions={};constructor(){this.emit=this.emit.bind(this),this.on=this.on.bind(this),this.off=this.off.bind(this),this.clear=this.clear.bind(this)}emit(t,e,s){const r=this.subscriptions[t];if(r){const{event:t,listenerList:i}=r;i.forEach(s=>x(s,Object.assign(t,e))),t.isDefaultPrevented||x(s)}else x(s)}on(t,e){const s=this.subscriptions[t];return s?s.listenerList.push(e):this.subscriptions[t]={event:new E,listenerList:[e]},()=>this.off(t,e)}off(t,e){const s=this.subscriptions[t];if(s){const{event:r,listenerList:i}=s;this.subscriptions[t]={event:r,listenerList:i.filter(t=>t!==e)},r.overrideDefault()}}clear(t){delete this.subscriptions[t]}}const w=(t="?",...e)=>[`[${(t&&r(t)?t:"?").toUpperCase()}]`,...e.reduce((t,e,s,{length:r})=>{const i=s===r-1?[]:["|"];return t.push(e,...i),t},e.length?["-"]:[])];var D,N,k;!function(t){t.StartGroup="group",t.EndGroup="groupEnd",t.Default="log"}(D||(D={})),function(t){t.Info="%s",t.Success="%s",t.Warning="%s",t.Danger="%s"}(N||(N={}));class S{static formatted={info:(...t)=>S.info(...w(...t)),success:(...t)=>S.success(...w(...t)),warning:(...t)=>S.warning(...w(...t)),danger:(...t)=>S.danger(...w(...t))};static#t(t,...e){console[t](...e)}static startGroup(t,e,...s){S.#t(D.StartGroup,...((t,...e)=>["%c%s",t,...e])(`font-size: 16px;${e}`,...w(t,...s)))}static endGroup(){S.#t(D.EndGroup)}static info(...t){S.#t(D.Default,N.Info,...t)}static success(...t){S.#t(D.Default,N.Success,...t)}static warning(...t){S.#t(D.Default,N.Warning,...t)}static danger(...t){S.#t(D.Default,N.Danger,...t)}}exports.ErrorHandlerEventName=void 0,(k=exports.ErrorHandlerEventName||(exports.ErrorHandlerEventName={})).Capture="capture",k.Forward="forward";class L{static eventEmitter=new v;static caseList=[];static log(t,e={signal:"unknown"}){const{signal:s,message:r,payload:i,stack:o}=e,n=[r,h(t)?t.message:void 0].filter(Boolean);S.formatted.danger(s,...n,{error:t,payload:i,stack:o})}static get on(){return L.eventEmitter.on}static get off(){return L.eventEmitter.off}static get clear(){return L.eventEmitter.clear}static create(t,e){return new Error(t,{cause:e})}static throw(t,e){throw L.create(t,e)}static capture(t,e){L.log(t,e),L.eventEmitter.emit(exports.ErrorHandlerEventName.Capture,{error:t,config:e})}static forward(t,e){throw L.log(t,e),L.eventEmitter.emit(exports.ErrorHandlerEventName.Capture,{error:t,config:e}),t}static case(t){L.caseList.push(t)}static parse(t){const e={message:"Error!",status:0,errors:{},isExternal:!0};for(const{check:s,parse:r}of L.caseList)if(s(t,e))return r(t,e);return!0===h(t)?{message:t.message,status:e.status,errors:e.errors,isExternal:e.isExternal}:{message:e.message,status:e.status,errors:e.errors,isExternal:e.isExternal}}}class j{key;model;config;constructor(t,e,s){this.key=t,this.model=e,this.config=s}async get(t){const{defaultValue:e,withDebug:s}={...this.config,...t},r=await this.model.get(this.key),i=r&&JSON.parse(r)||e;return s&&S.formatted.info("get",this.key,i),i}async set(t,e){const{withDebug:s}={...this.config,...e};await this.model.set(this.key,JSON.stringify(t)),s&&S.formatted.info("set",this.key,t)}async delete(t){const{withDebug:e}={...this.config,...t},s=await this.get({...t,withDebug:!1});await this.model.delete(this.key),e&&S.formatted.info("delete",this.key,s)}async has(t){const{withDebug:e}={...this.config,...t},s=await this.get({...t,withDebug:!1});return e&&S.formatted.info("has",this.key,s),!!s}}exports.ErrorHandler=L,exports.EventEmitter=v,exports.Log=S,exports.Storage=class{model;config;constructor(t,e){this.model=t,this.config=e}async all(){L.throw("Not implemented")}async clear(){L.throw("Not implemented")}create(t){const e={[t]:new j(t,this.model,this.config)};return Object.assign(this,e)}},exports.chunkList=function(t,e){const s=[];for(let r=0;r<t.length;r+=e)s.push(t.slice(r,r+e));return s},exports.compose=function(t,e,r){const i=!o(t);return!s(r)&&{...e,...i?{[r]:t}:t}||!s(e)&&{...e,...t}||{...t}},exports.debounce=(t,e)=>{let s;return(...r)=>{s&&clearTimeout(s),s=setTimeout(()=>x(t,...r),e)}},exports.filterByKey=function(t,e="isVisible"){return t.filter(t=>!y(e,t)||t[e])},exports.filterDuplicateByKey=function(t,e){return t.reduce((t,s)=>t.some(t=>t[e]===s[e])?t:[...t,s],[])},exports.filterEqualValues=b,exports.filterNullableValues=function(t){return t.filter(t=>!s(t))},exports.forceList=function(t){return n(t)?t:[t]},exports.getValueByKey=function(t,e,r){return s(t)?r:2===arguments.length?e[t]:e[t]??r},exports.hasEqualValues=function(t,e){return!!b(t,e).length},exports.hasKey=y,exports.isAnyObject=i,exports.isArray=n,exports.isArrayBuffer=a,exports.isArrayEmpty=function(t){return 0===t.length},exports.isBigint=t=>"bigint"==typeof t,exports.isBoolean=t=>"boolean"==typeof t,exports.isDate=p,exports.isError=h,exports.isFunction=d,exports.isMap=c,exports.isNaN=t=>Number.isNaN(t),exports.isNull=e,exports.isNullable=s,exports.isNumber=t=>"number"==typeof t,exports.isObject=o,exports.isObjectEmpty=function(t){for(const e in t)return!1;return!0},exports.isPromise=m,exports.isProxy=t=>t instanceof Proxy,exports.isRegExp=g,exports.isSet=u,exports.isString=r,exports.isSymbol=t=>"symbol"==typeof t,exports.isUndefined=t,exports.isWeakMap=l,exports.isWeakSet=f,exports.mapRecord=(t,e)=>{const s=Object.entries(t);return Object.fromEntries(s.map(([t,s],r,i)=>[t,e(t,s,r,i)]))},exports.runCallback=x,exports.throttle=(t,e)=>{let s=!0;return(...r)=>{s&&(x(t,...r),s=!1),setTimeout(()=>s=!0,e)}},exports.wait=(t=0)=>new Promise(e=>setTimeout(e,t));
package/dist/index.d.ts CHANGED
@@ -762,7 +762,7 @@ declare class Storage {
762
762
  * await wait(300)
763
763
  * ```
764
764
  */
765
- declare const wait: (delay: number) => Promise<unknown>;
765
+ declare const wait: (delay?: number) => Promise<unknown>;
766
766
  /**
767
767
  * Собирает объект из переданного значения и опционального исходного объекта.
768
768
  * Поддерживает три сценария: вернуть объект как есть, слить два объекта или записать примитив по ключу.
@@ -883,7 +883,7 @@ declare function filterByKey<Key extends KeyOf<Item>, Item extends object & Base
883
883
  * filterDuplicateByKey([{ id: 1 }, { id: 1 }, { id: 2 }], 'id') // [{ id: 1 }, { id: 2 }]
884
884
  * ```
885
885
  */
886
- declare function filterDuplicateByKey<Key extends BaseKey, Item extends object & BaseRecord<any, Key>>(data: Item[], key: Key): Item[];
886
+ declare function filterDuplicateByKey<Key extends BaseKey, Item extends object & BaseRecord<unknown, Key>>(data: Item[], key: Key): Item[];
887
887
  /**
888
888
  * Возвращает элементы первого списка, которые присутствуют во втором.
889
889
  *
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- const t=t=>void 0===t,e=t=>null===t,s=s=>t(s)||e(s),n=t=>"string"==typeof t,i=t=>"number"==typeof t,r=t=>"bigint"==typeof t,o=t=>Number.isNaN(t),a=t=>"boolean"==typeof t,c=t=>"symbol"==typeof t,u=t=>"object"==typeof t,f=t=>{const e=[l,h,g,m,d,p,b,y,D,v,E].some(e=>e(t));return!!t&&"object"==typeof t&&!e},l=t=>Array.isArray(t),h=t=>t instanceof ArrayBuffer,g=t=>t instanceof Map,m=t=>t instanceof Set,d=t=>t instanceof Map,p=t=>t instanceof Set,b=t=>t instanceof Date,y=t=>t instanceof Error,w=t=>t instanceof Proxy,D=t=>t instanceof RegExp,v=t=>t instanceof Promise,E=t=>t instanceof Function,k=t=>new Promise(e=>setTimeout(e,t));function x(t,e,n){const i=!f(t);return!s(n)&&{...e,...i?{[n]:t}:t}||!s(e)&&{...e,...t}||{...t}}function L(t,e,n){return s(t)?n:2===arguments.length?e[t]:e[t]??n}const S=(t,e)=>{const s=Object.entries(t);return Object.fromEntries(s.map(([t,s],n,i)=>[t,e(t,s,n,i)]))},N=(t,...e)=>{if(E(t))return t(...e)},P=(t,e)=>{let s;return(...n)=>{s&&clearTimeout(s),s=setTimeout(()=>N(t,...n),e)}},j=(t,e)=>{let s=!0;return(...n)=>{s&&(N(t,...n),s=!1),setTimeout(()=>s=!0,e)}};function G(t){for(const e in t)return!1;return!0}function O(t){return 0===t.length}function C(t,e){return!(!u(e)||!(t in e))}function T(t,e){return!!F(t,e).length}function A(t,e="isVisible"){return t.filter(t=>!C(e,t)||t[e])}function B(t,e){return t.reduce((t,s)=>t.some(t=>t[e]===s[e])?t:[...t,s],[])}function F(t,e){return t.filter(t=>e.includes(t))}function I(t){return t.filter(t=>!s(t))}function J(t){return l(t)?t:[t]}function M(t,e){const s=[];for(let n=0;n<t.length;n+=e)s.push(t.slice(n,n+e));return s}class V{isDefaultPrevented=!1;constructor(){this.preventDefault=this.preventDefault.bind(this),this.overrideDefault=this.overrideDefault.bind(this)}preventDefault(){this.isDefaultPrevented=!0}overrideDefault(){this.isDefaultPrevented=!1}}class W{subscriptions={};constructor(){this.emit=this.emit.bind(this),this.on=this.on.bind(this),this.off=this.off.bind(this),this.clear=this.clear.bind(this)}emit(t,e,s){const n=this.subscriptions[t];if(n){const{event:t,listenerList:i}=n;i.forEach(s=>N(s,Object.assign(t,e))),t.isDefaultPrevented||N(s)}else N(s)}on(t,e){const s=this.subscriptions[t];return s?s.listenerList.push(e):this.subscriptions[t]={event:new V,listenerList:[e]},()=>this.off(t,e)}off(t,e){const s=this.subscriptions[t];if(s){const{event:n,listenerList:i}=s;this.subscriptions[t]={event:n,listenerList:i.filter(t=>t!==e)},n.overrideDefault()}}clear(t){delete this.subscriptions[t]}}const $=(t="?",...e)=>[`[${(t&&n(t)?t:"?").toUpperCase()}]`,...e.reduce((t,e,s,{length:n})=>{const i=s===n-1?[]:["|"];return t.push(e,...i),t},e.length?["-"]:[])];var z,R,U;!function(t){t.StartGroup="group",t.EndGroup="groupEnd",t.Default="log"}(z||(z={})),function(t){t.Info="%s",t.Success="%s",t.Warning="%s",t.Danger="%s"}(R||(R={}));class q{static formatted={info:(...t)=>q.info(...$(...t)),success:(...t)=>q.success(...$(...t)),warning:(...t)=>q.warning(...$(...t)),danger:(...t)=>q.danger(...$(...t))};static#t(t,...e){console[t](...e)}static startGroup(t,e,...s){q.#t(z.StartGroup,...((t,...e)=>["%c%s",t,...e])(`font-size: 16px;${e}`,...$(t,...s)))}static endGroup(){q.#t(z.EndGroup)}static info(...t){q.#t(z.Default,R.Info,...t)}static success(...t){q.#t(z.Default,R.Success,...t)}static warning(...t){q.#t(z.Default,R.Warning,...t)}static danger(...t){q.#t(z.Default,R.Danger,...t)}}!function(t){t.Capture="capture",t.Forward="forward"}(U||(U={}));class H{static eventEmitter=new W;static caseList=[];static log(t,e={signal:"unknown"}){const{signal:s,message:n,payload:i,stack:r}=e,o=[n,y(t)?t.message:void 0].filter(Boolean);q.formatted.danger(s,...o,{error:t,payload:i,stack:r})}static get on(){return H.eventEmitter.on}static get off(){return H.eventEmitter.off}static get clear(){return H.eventEmitter.clear}static create(t,e){return new Error(t,{cause:e})}static throw(t,e){throw H.create(t,e)}static capture(t,e){H.log(t,e),H.eventEmitter.emit(U.Capture,{error:t,config:e})}static forward(t,e){throw H.log(t,e),H.eventEmitter.emit(U.Capture,{error:t,config:e}),t}static case(t){H.caseList.push(t)}static parse(t){const e={message:"Error!",status:0,errors:{},isExternal:!0};for(const{check:s,parse:n}of H.caseList)if(s(t,e))return n(t,e);return!0===y(t)?{message:t.message,status:e.status,errors:e.errors,isExternal:e.isExternal}:{message:e.message,status:e.status,errors:e.errors,isExternal:e.isExternal}}}class K{key;model;config;constructor(t,e,s){this.key=t,this.model=e,this.config=s}async get(t){const{defaultValue:e,withDebug:s}={...this.config,...t},n=await this.model.get(this.key),i=n&&JSON.parse(n)||e;return s&&q.formatted.info("get",this.key,i),i}async set(t,e){const{withDebug:s}={...this.config,...e};await this.model.set(this.key,JSON.stringify(t)),s&&q.formatted.info("set",this.key,t)}async delete(t){const{withDebug:e}={...this.config,...t},s=await this.get({...t,withDebug:!1});await this.model.delete(this.key),e&&q.formatted.info("delete",this.key,s)}async has(t){const{withDebug:e}={...this.config,...t},s=await this.get({...t,withDebug:!1});return e&&q.formatted.info("has",this.key,s),!!s}}class Q{model;config;constructor(t,e){this.model=t,this.config=e}async all(){H.throw("Not implemented")}async clear(){H.throw("Not implemented")}create(t){const e={[t]:new K(t,this.model,this.config)};return Object.assign(this,e)}}export{H as ErrorHandler,U as ErrorHandlerEventName,W as EventEmitter,q as Log,Q as Storage,M as chunkList,x as compose,P as debounce,A as filterByKey,B as filterDuplicateByKey,F as filterEqualValues,I as filterNullableValues,J as forceList,L as getValueByKey,T as hasEqualValues,C as hasKey,u as isAnyObject,l as isArray,h as isArrayBuffer,O as isArrayEmpty,r as isBigint,a as isBoolean,b as isDate,y as isError,E as isFunction,g as isMap,o as isNaN,e as isNull,s as isNullable,i as isNumber,f as isObject,G as isObjectEmpty,v as isPromise,w as isProxy,D as isRegExp,m as isSet,n as isString,c as isSymbol,t as isUndefined,d as isWeakMap,p as isWeakSet,S as mapRecord,N as runCallback,j as throttle,k as wait};
1
+ const t=t=>void 0===t,e=t=>null===t,s=s=>t(s)||e(s),n=t=>"string"==typeof t,i=t=>"number"==typeof t,r=t=>"bigint"==typeof t,o=t=>Number.isNaN(t),a=t=>"boolean"==typeof t,c=t=>"symbol"==typeof t,u=t=>"object"==typeof t,f=t=>{const e=[l,h,g,m,d,p,b,y,D,v,E].some(e=>e(t));return!!t&&"object"==typeof t&&!e},l=t=>Array.isArray(t),h=t=>t instanceof ArrayBuffer,g=t=>t instanceof Map,m=t=>t instanceof Set,d=t=>t instanceof Map,p=t=>t instanceof Set,b=t=>t instanceof Date,y=t=>t instanceof Error,w=t=>t instanceof Proxy,D=t=>t instanceof RegExp,v=t=>t instanceof Promise,E=t=>t instanceof Function,k=(t=0)=>new Promise(e=>setTimeout(e,t));function x(t,e,n){const i=!f(t);return!s(n)&&{...e,...i?{[n]:t}:t}||!s(e)&&{...e,...t}||{...t}}function L(t,e,n){return s(t)?n:2===arguments.length?e[t]:e[t]??n}const S=(t,e)=>{const s=Object.entries(t);return Object.fromEntries(s.map(([t,s],n,i)=>[t,e(t,s,n,i)]))},N=(t,...e)=>{if(E(t))return t(...e)},P=(t,e)=>{let s;return(...n)=>{s&&clearTimeout(s),s=setTimeout(()=>N(t,...n),e)}},j=(t,e)=>{let s=!0;return(...n)=>{s&&(N(t,...n),s=!1),setTimeout(()=>s=!0,e)}};function G(t){for(const e in t)return!1;return!0}function O(t){return 0===t.length}function C(t,e){return!(!u(e)||!(t in e))}function T(t,e){return!!F(t,e).length}function A(t,e="isVisible"){return t.filter(t=>!C(e,t)||t[e])}function B(t,e){return t.reduce((t,s)=>t.some(t=>t[e]===s[e])?t:[...t,s],[])}function F(t,e){return t.filter(t=>e.includes(t))}function I(t){return t.filter(t=>!s(t))}function J(t){return l(t)?t:[t]}function M(t,e){const s=[];for(let n=0;n<t.length;n+=e)s.push(t.slice(n,n+e));return s}class V{isDefaultPrevented=!1;constructor(){this.preventDefault=this.preventDefault.bind(this),this.overrideDefault=this.overrideDefault.bind(this)}preventDefault(){this.isDefaultPrevented=!0}overrideDefault(){this.isDefaultPrevented=!1}}class W{subscriptions={};constructor(){this.emit=this.emit.bind(this),this.on=this.on.bind(this),this.off=this.off.bind(this),this.clear=this.clear.bind(this)}emit(t,e,s){const n=this.subscriptions[t];if(n){const{event:t,listenerList:i}=n;i.forEach(s=>N(s,Object.assign(t,e))),t.isDefaultPrevented||N(s)}else N(s)}on(t,e){const s=this.subscriptions[t];return s?s.listenerList.push(e):this.subscriptions[t]={event:new V,listenerList:[e]},()=>this.off(t,e)}off(t,e){const s=this.subscriptions[t];if(s){const{event:n,listenerList:i}=s;this.subscriptions[t]={event:n,listenerList:i.filter(t=>t!==e)},n.overrideDefault()}}clear(t){delete this.subscriptions[t]}}const $=(t="?",...e)=>[`[${(t&&n(t)?t:"?").toUpperCase()}]`,...e.reduce((t,e,s,{length:n})=>{const i=s===n-1?[]:["|"];return t.push(e,...i),t},e.length?["-"]:[])];var z,R,U;!function(t){t.StartGroup="group",t.EndGroup="groupEnd",t.Default="log"}(z||(z={})),function(t){t.Info="%s",t.Success="%s",t.Warning="%s",t.Danger="%s"}(R||(R={}));class q{static formatted={info:(...t)=>q.info(...$(...t)),success:(...t)=>q.success(...$(...t)),warning:(...t)=>q.warning(...$(...t)),danger:(...t)=>q.danger(...$(...t))};static#t(t,...e){console[t](...e)}static startGroup(t,e,...s){q.#t(z.StartGroup,...((t,...e)=>["%c%s",t,...e])(`font-size: 16px;${e}`,...$(t,...s)))}static endGroup(){q.#t(z.EndGroup)}static info(...t){q.#t(z.Default,R.Info,...t)}static success(...t){q.#t(z.Default,R.Success,...t)}static warning(...t){q.#t(z.Default,R.Warning,...t)}static danger(...t){q.#t(z.Default,R.Danger,...t)}}!function(t){t.Capture="capture",t.Forward="forward"}(U||(U={}));class H{static eventEmitter=new W;static caseList=[];static log(t,e={signal:"unknown"}){const{signal:s,message:n,payload:i,stack:r}=e,o=[n,y(t)?t.message:void 0].filter(Boolean);q.formatted.danger(s,...o,{error:t,payload:i,stack:r})}static get on(){return H.eventEmitter.on}static get off(){return H.eventEmitter.off}static get clear(){return H.eventEmitter.clear}static create(t,e){return new Error(t,{cause:e})}static throw(t,e){throw H.create(t,e)}static capture(t,e){H.log(t,e),H.eventEmitter.emit(U.Capture,{error:t,config:e})}static forward(t,e){throw H.log(t,e),H.eventEmitter.emit(U.Capture,{error:t,config:e}),t}static case(t){H.caseList.push(t)}static parse(t){const e={message:"Error!",status:0,errors:{},isExternal:!0};for(const{check:s,parse:n}of H.caseList)if(s(t,e))return n(t,e);return!0===y(t)?{message:t.message,status:e.status,errors:e.errors,isExternal:e.isExternal}:{message:e.message,status:e.status,errors:e.errors,isExternal:e.isExternal}}}class K{key;model;config;constructor(t,e,s){this.key=t,this.model=e,this.config=s}async get(t){const{defaultValue:e,withDebug:s}={...this.config,...t},n=await this.model.get(this.key),i=n&&JSON.parse(n)||e;return s&&q.formatted.info("get",this.key,i),i}async set(t,e){const{withDebug:s}={...this.config,...e};await this.model.set(this.key,JSON.stringify(t)),s&&q.formatted.info("set",this.key,t)}async delete(t){const{withDebug:e}={...this.config,...t},s=await this.get({...t,withDebug:!1});await this.model.delete(this.key),e&&q.formatted.info("delete",this.key,s)}async has(t){const{withDebug:e}={...this.config,...t},s=await this.get({...t,withDebug:!1});return e&&q.formatted.info("has",this.key,s),!!s}}class Q{model;config;constructor(t,e){this.model=t,this.config=e}async all(){H.throw("Not implemented")}async clear(){H.throw("Not implemented")}create(t){const e={[t]:new K(t,this.model,this.config)};return Object.assign(this,e)}}export{H as ErrorHandler,U as ErrorHandlerEventName,W as EventEmitter,q as Log,Q as Storage,M as chunkList,x as compose,P as debounce,A as filterByKey,B as filterDuplicateByKey,F as filterEqualValues,I as filterNullableValues,J as forceList,L as getValueByKey,T as hasEqualValues,C as hasKey,u as isAnyObject,l as isArray,h as isArrayBuffer,O as isArrayEmpty,r as isBigint,a as isBoolean,b as isDate,y as isError,E as isFunction,g as isMap,o as isNaN,e as isNull,s as isNullable,i as isNumber,f as isObject,G as isObjectEmpty,v as isPromise,w as isProxy,D as isRegExp,m as isSet,n as isString,c as isSymbol,t as isUndefined,d as isWeakMap,p as isWeakSet,S as mapRecord,N as runCallback,j as throttle,k as wait};
@@ -1 +1 @@
1
- "use strict";const e=e=>void 0===e,t=e=>null===e,r=r=>e(r)||t(r),s=e=>"object"==typeof e,o=e=>{const t=[n,i,p,u,c,f,a,x,l,y,m].some(t=>t(e));return!!e&&"object"==typeof e&&!t},n=e=>Array.isArray(e),i=e=>e instanceof ArrayBuffer,p=e=>e instanceof Map,u=e=>e instanceof Set,c=e=>e instanceof Map,f=e=>e instanceof Set,a=e=>e instanceof Date,x=e=>e instanceof Error,l=e=>e instanceof RegExp,y=e=>e instanceof Promise,m=e=>e instanceof Function;const b=(e,...t)=>{if(m(e))return e(...t)};function g(e,t){return!(!s(t)||!(e in t))}function h(e,t){return e.filter(e=>t.includes(e))}exports.chunkList=function(e,t){const r=[];for(let s=0;s<e.length;s+=t)r.push(e.slice(s,s+t));return r},exports.compose=function(e,t,s){const n=!o(e);return!r(s)&&{...t,...n?{[s]:e}:e}||!r(t)&&{...t,...e}||{...e}},exports.debounce=(e,t)=>{let r;return(...s)=>{r&&clearTimeout(r),r=setTimeout(()=>b(e,...s),t)}},exports.filterByKey=function(e,t="isVisible"){return e.filter(e=>!g(t,e)||e[t])},exports.filterDuplicateByKey=function(e,t){return e.reduce((e,r)=>e.some(e=>e[t]===r[t])?e:[...e,r],[])},exports.filterEqualValues=h,exports.filterNullableValues=function(e){return e.filter(e=>!r(e))},exports.forceList=function(e){return n(e)?e:[e]},exports.getValueByKey=function(e,t,s){return r(e)?s:2===arguments.length?t[e]:t[e]??s},exports.hasEqualValues=function(e,t){return!!h(e,t).length},exports.hasKey=g,exports.isAnyObject=s,exports.isArray=n,exports.isArrayBuffer=i,exports.isArrayEmpty=function(e){return 0===e.length},exports.isBigint=e=>"bigint"==typeof e,exports.isBoolean=e=>"boolean"==typeof e,exports.isDate=a,exports.isError=x,exports.isFunction=m,exports.isMap=p,exports.isNaN=e=>Number.isNaN(e),exports.isNull=t,exports.isNullable=r,exports.isNumber=e=>"number"==typeof e,exports.isObject=o,exports.isObjectEmpty=function(e){for(const t in e)return!1;return!0},exports.isPromise=y,exports.isProxy=e=>e instanceof Proxy,exports.isRegExp=l,exports.isSet=u,exports.isString=e=>"string"==typeof e,exports.isSymbol=e=>"symbol"==typeof e,exports.isUndefined=e,exports.isWeakMap=c,exports.isWeakSet=f,exports.mapRecord=(e,t)=>{const r=Object.entries(e);return Object.fromEntries(r.map(([e,r],s,o)=>[e,t(e,r,s,o)]))},exports.runCallback=b,exports.throttle=(e,t)=>{let r=!0;return(...s)=>{r&&(b(e,...s),r=!1),setTimeout(()=>r=!0,t)}},exports.wait=e=>new Promise(t=>setTimeout(t,e));
1
+ "use strict";const e=e=>void 0===e,t=e=>null===e,r=r=>e(r)||t(r),s=e=>"object"==typeof e,o=e=>{const t=[n,i,p,u,c,f,a,x,l,y,m].some(t=>t(e));return!!e&&"object"==typeof e&&!t},n=e=>Array.isArray(e),i=e=>e instanceof ArrayBuffer,p=e=>e instanceof Map,u=e=>e instanceof Set,c=e=>e instanceof Map,f=e=>e instanceof Set,a=e=>e instanceof Date,x=e=>e instanceof Error,l=e=>e instanceof RegExp,y=e=>e instanceof Promise,m=e=>e instanceof Function;const b=(e,...t)=>{if(m(e))return e(...t)};function g(e,t){return!(!s(t)||!(e in t))}function h(e,t){return e.filter(e=>t.includes(e))}exports.chunkList=function(e,t){const r=[];for(let s=0;s<e.length;s+=t)r.push(e.slice(s,s+t));return r},exports.compose=function(e,t,s){const n=!o(e);return!r(s)&&{...t,...n?{[s]:e}:e}||!r(t)&&{...t,...e}||{...e}},exports.debounce=(e,t)=>{let r;return(...s)=>{r&&clearTimeout(r),r=setTimeout(()=>b(e,...s),t)}},exports.filterByKey=function(e,t="isVisible"){return e.filter(e=>!g(t,e)||e[t])},exports.filterDuplicateByKey=function(e,t){return e.reduce((e,r)=>e.some(e=>e[t]===r[t])?e:[...e,r],[])},exports.filterEqualValues=h,exports.filterNullableValues=function(e){return e.filter(e=>!r(e))},exports.forceList=function(e){return n(e)?e:[e]},exports.getValueByKey=function(e,t,s){return r(e)?s:2===arguments.length?t[e]:t[e]??s},exports.hasEqualValues=function(e,t){return!!h(e,t).length},exports.hasKey=g,exports.isAnyObject=s,exports.isArray=n,exports.isArrayBuffer=i,exports.isArrayEmpty=function(e){return 0===e.length},exports.isBigint=e=>"bigint"==typeof e,exports.isBoolean=e=>"boolean"==typeof e,exports.isDate=a,exports.isError=x,exports.isFunction=m,exports.isMap=p,exports.isNaN=e=>Number.isNaN(e),exports.isNull=t,exports.isNullable=r,exports.isNumber=e=>"number"==typeof e,exports.isObject=o,exports.isObjectEmpty=function(e){for(const t in e)return!1;return!0},exports.isPromise=y,exports.isProxy=e=>e instanceof Proxy,exports.isRegExp=l,exports.isSet=u,exports.isString=e=>"string"==typeof e,exports.isSymbol=e=>"symbol"==typeof e,exports.isUndefined=e,exports.isWeakMap=c,exports.isWeakSet=f,exports.mapRecord=(e,t)=>{const r=Object.entries(e);return Object.fromEntries(r.map(([e,r],s,o)=>[e,t(e,r,s,o)]))},exports.runCallback=b,exports.throttle=(e,t)=>{let r=!0;return(...s)=>{r&&(b(e,...s),r=!1),setTimeout(()=>r=!0,t)}},exports.wait=(e=0)=>new Promise(t=>setTimeout(t,e));
@@ -107,7 +107,7 @@ type CallbackParamList<Callback> = Callback extends (...args: infer ParamList) =
107
107
  * await wait(300)
108
108
  * ```
109
109
  */
110
- declare const wait: (delay: number) => Promise<unknown>;
110
+ declare const wait: (delay?: number) => Promise<unknown>;
111
111
  /**
112
112
  * Собирает объект из переданного значения и опционального исходного объекта.
113
113
  * Поддерживает три сценария: вернуть объект как есть, слить два объекта или записать примитив по ключу.
@@ -228,7 +228,7 @@ declare function filterByKey<Key extends KeyOf<Item>, Item extends object & Base
228
228
  * filterDuplicateByKey([{ id: 1 }, { id: 1 }, { id: 2 }], 'id') // [{ id: 1 }, { id: 2 }]
229
229
  * ```
230
230
  */
231
- declare function filterDuplicateByKey<Key extends BaseKey, Item extends object & BaseRecord<any, Key>>(data: Item[], key: Key): Item[];
231
+ declare function filterDuplicateByKey<Key extends BaseKey, Item extends object & BaseRecord<unknown, Key>>(data: Item[], key: Key): Item[];
232
232
  /**
233
233
  * Возвращает элементы первого списка, которые присутствуют во втором.
234
234
  *
@@ -1 +1 @@
1
- const n=n=>void 0===n,t=n=>null===n,e=e=>n(e)||t(e),r=n=>"string"==typeof n,o=n=>"number"==typeof n,i=n=>"bigint"==typeof n,u=n=>Number.isNaN(n),c=n=>"boolean"==typeof n,f=n=>"symbol"==typeof n,s=n=>"object"==typeof n,a=n=>{const t=[l,m,p,y,b,g,h,j,d,x,A].some(t=>t(n));return!!n&&"object"==typeof n&&!t},l=n=>Array.isArray(n),m=n=>n instanceof ArrayBuffer,p=n=>n instanceof Map,y=n=>n instanceof Set,b=n=>n instanceof Map,g=n=>n instanceof Set,h=n=>n instanceof Date,j=n=>n instanceof Error,T=n=>n instanceof Proxy,d=n=>n instanceof RegExp,x=n=>n instanceof Promise,A=n=>n instanceof Function,E=n=>new Promise(t=>setTimeout(t,n));function N(n,t,r){const o=!a(n);return!e(r)&&{...t,...o?{[r]:n}:n}||!e(t)&&{...t,...n}||{...n}}function P(n,t,r){return e(n)?r:2===arguments.length?t[n]:t[n]??r}const M=(n,t)=>{const e=Object.entries(n);return Object.fromEntries(e.map(([n,e],r,o)=>[n,t(n,e,r,o)]))},O=(n,...t)=>{if(A(n))return n(...t)},S=(n,t)=>{let e;return(...r)=>{e&&clearTimeout(e),e=setTimeout(()=>O(n,...r),t)}},v=(n,t)=>{let e=!0;return(...r)=>{e&&(O(n,...r),e=!1),setTimeout(()=>e=!0,t)}};function w(n){for(const t in n)return!1;return!0}function B(n){return 0===n.length}function D(n,t){return!(!s(t)||!(n in t))}function F(n,t){return!!k(n,t).length}function R(n,t="isVisible"){return n.filter(n=>!D(t,n)||n[t])}function V(n,t){return n.reduce((n,e)=>n.some(n=>n[t]===e[t])?n:[...n,e],[])}function k(n,t){return n.filter(n=>t.includes(n))}function q(n){return n.filter(n=>!e(n))}function z(n){return l(n)?n:[n]}function C(n,t){const e=[];for(let r=0;r<n.length;r+=t)e.push(n.slice(r,r+t));return e}export{C as chunkList,N as compose,S as debounce,R as filterByKey,V as filterDuplicateByKey,k as filterEqualValues,q as filterNullableValues,z as forceList,P as getValueByKey,F as hasEqualValues,D as hasKey,s as isAnyObject,l as isArray,m as isArrayBuffer,B as isArrayEmpty,i as isBigint,c as isBoolean,h as isDate,j as isError,A as isFunction,p as isMap,u as isNaN,t as isNull,e as isNullable,o as isNumber,a as isObject,w as isObjectEmpty,x as isPromise,T as isProxy,d as isRegExp,y as isSet,r as isString,f as isSymbol,n as isUndefined,b as isWeakMap,g as isWeakSet,M as mapRecord,O as runCallback,v as throttle,E as wait};
1
+ const n=n=>void 0===n,t=n=>null===n,e=e=>n(e)||t(e),r=n=>"string"==typeof n,o=n=>"number"==typeof n,i=n=>"bigint"==typeof n,u=n=>Number.isNaN(n),c=n=>"boolean"==typeof n,f=n=>"symbol"==typeof n,s=n=>"object"==typeof n,a=n=>{const t=[l,m,p,y,b,g,h,j,d,x,A].some(t=>t(n));return!!n&&"object"==typeof n&&!t},l=n=>Array.isArray(n),m=n=>n instanceof ArrayBuffer,p=n=>n instanceof Map,y=n=>n instanceof Set,b=n=>n instanceof Map,g=n=>n instanceof Set,h=n=>n instanceof Date,j=n=>n instanceof Error,T=n=>n instanceof Proxy,d=n=>n instanceof RegExp,x=n=>n instanceof Promise,A=n=>n instanceof Function,E=(n=0)=>new Promise(t=>setTimeout(t,n));function N(n,t,r){const o=!a(n);return!e(r)&&{...t,...o?{[r]:n}:n}||!e(t)&&{...t,...n}||{...n}}function P(n,t,r){return e(n)?r:2===arguments.length?t[n]:t[n]??r}const M=(n,t)=>{const e=Object.entries(n);return Object.fromEntries(e.map(([n,e],r,o)=>[n,t(n,e,r,o)]))},O=(n,...t)=>{if(A(n))return n(...t)},S=(n,t)=>{let e;return(...r)=>{e&&clearTimeout(e),e=setTimeout(()=>O(n,...r),t)}},v=(n,t)=>{let e=!0;return(...r)=>{e&&(O(n,...r),e=!1),setTimeout(()=>e=!0,t)}};function w(n){for(const t in n)return!1;return!0}function B(n){return 0===n.length}function D(n,t){return!(!s(t)||!(n in t))}function F(n,t){return!!k(n,t).length}function R(n,t="isVisible"){return n.filter(n=>!D(t,n)||n[t])}function V(n,t){return n.reduce((n,e)=>n.some(n=>n[t]===e[t])?n:[...n,e],[])}function k(n,t){return n.filter(n=>t.includes(n))}function q(n){return n.filter(n=>!e(n))}function z(n){return l(n)?n:[n]}function C(n,t){const e=[];for(let r=0;r<n.length;r+=t)e.push(n.slice(r,r+t));return e}export{C as chunkList,N as compose,S as debounce,R as filterByKey,V as filterDuplicateByKey,k as filterEqualValues,q as filterNullableValues,z as forceList,P as getValueByKey,F as hasEqualValues,D as hasKey,s as isAnyObject,l as isArray,m as isArrayBuffer,B as isArrayEmpty,i as isBigint,c as isBoolean,h as isDate,j as isError,A as isFunction,p as isMap,u as isNaN,t as isNull,e as isNullable,o as isNumber,a as isObject,w as isObjectEmpty,x as isPromise,T as isProxy,d as isRegExp,y as isSet,r as isString,f as isSymbol,n as isUndefined,b as isWeakMap,g as isWeakSet,M as mapRecord,O as runCallback,v as throttle,E as wait};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "private": false,
3
- "version": "1.2.0",
3
+ "version": "2.0.0",
4
4
  "name": "@mediacubeco/base",
5
5
  "description": "Base by Mediacube developers",
6
6
  "license": "MIT",
@@ -17,9 +17,9 @@
17
17
  "eslint": "^9.39.1",
18
18
  "prettier": "^3.8.1",
19
19
  "typescript": "^5.9.3",
20
- "@mediacubeco/eslint-config": "1.2.0",
21
- "@mediacubeco/prettier-config": "1.2.0",
22
- "@mediacubeco/typescript-config": "1.2.0"
20
+ "@mediacubeco/eslint-config": "2.0.0",
21
+ "@mediacubeco/typescript-config": "2.0.0",
22
+ "@mediacubeco/prettier-config": "2.0.0"
23
23
  },
24
24
  "exports": {
25
25
  ".": {