@superutils/store 0.1.17 → 0.1.19

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/README.md CHANGED
@@ -14,14 +14,15 @@ For full API reference and example code playground check out the [docs page](htt
14
14
 
15
15
  - [Installation](#installation)
16
16
  - [Basic Usage](#basic-usage)
17
- - [Map-Based Store](#map-store)
17
+ - [Map-Based Store](#map-based-store)
18
18
  - [Object-based Store](#object-based-store)
19
19
  - [Persistent Storage (NodeJS)](#persistent-storage-nodejs)
20
20
  - [Advanced Usage](#advanced-usage)
21
+ - [Data Validation](#data-validation)
21
22
  - [Reactive Updates (RxJS & Callbacks)](#reactive-updates-rxjs--callbacks)
22
23
  - [Search and Filtering](#search-and-filtering)
23
- - [Attaching Context (Business Logic)](#attaching-context-business-logic)
24
- - [Object-based Store With Context](#object-based-store)
24
+ - [Attaching Business Logic: Store Augmentation](#attaching-business-logic-store-augmentation)
25
+ - [Object-based Store With Augmentation](#object-based-store-with-augmentation)
25
26
  - [OOP: Subclassing Store](#oop-subclassing-store)
26
27
 
27
28
  ## Installation
@@ -59,8 +60,9 @@ The `Store` class can be used just like a standard JavaScript `Map`, but with th
59
60
  ```javascript
60
61
  import { createStore } from '@superutils/store'
61
62
 
62
- // Initialize a store
63
- const userStorage = createStore('users') // or `createStore()` for in-memory store
63
+ // Initialize the store that saves the stringified data to `localStorage.users` in the browser.
64
+ // Bypassing the name or using `null` will create an in-memory store.
65
+ const userStorage = createStore({ name: 'users' })
64
66
 
65
67
  // Set and get values
66
68
  userStorage.set('alice', { name: 'Alice', age: 30 })
@@ -79,7 +81,8 @@ console.log(userStorage.size) // 1
79
81
  ```javascript
80
82
  import { createObjectStore } from '@superutils/store'
81
83
 
82
- const userStore = createObjectStore('user-profile', {
84
+ const userStore = createObjectStore({
85
+ name: 'user-profile',
83
86
  initialValue: {
84
87
  age: 25,
85
88
  name: 'Jane Doe',
@@ -106,13 +109,18 @@ globalThis.localStorage = new LocalStorage(
106
109
  1e7, // max file size
107
110
  )
108
111
 
109
- const storage = createStore('settings.json')
110
- storage.set('theme', 'dark') // Automatically saved to ./data/settings.json
112
+ // Create a store that saves the data to ./data/settings.json
113
+ // Bypassing the name or using `null` will create an in-memory store.
114
+ const store = createStore({ name: 'settings.json' })
115
+ store.set('theme', 'dark') // Automatically saved to ./data/settings.json
111
116
 
112
117
  /**
113
- * Alternatively, you can also provide a LocalStorage instance to each Store instance
118
+ * Alternatively, you can also provide a LocalStorage instance to each Store instance.
114
119
  */
115
- createStore('settings.json', { storage: new LocalStorage('./data', 1e7) })
120
+ createStore({
121
+ name: 'settings.json',
122
+ storage: new LocalStorage('./data', 1e9),
123
+ })
116
124
  ```
117
125
 
118
126
  ## Advanced Usage
@@ -121,29 +129,27 @@ createStore('settings.json', { storage: new LocalStorage('./data', 1e7) })
121
129
 
122
130
  To ensure data integrity, you can provide a `validate` object containing hooks for various operations (`set`, `setAll`, `delete`, `clear`, `write`). These hooks are executed immediately before the store's internal state is updated. If a validator throws an error, the operation is aborted.
123
131
 
124
- ```javascript
132
+ ````javascript
125
133
  import { createObjectStore } from '@superutils/store'
126
-
127
- const settingsStore = createObjectStore('app-settings', {
134
+ const settingsStore = createObjectStore({
135
+ name: 'app-settings',
128
136
  initialValue: {
129
137
  theme: 'light',
130
138
  version: '1.0.0',
131
139
  },
132
140
  validate: {
133
- set: ([key, value]) => {
141
+ set([key, value]) {
142
+ console.log(this.size) // "this" refers to the store instance
134
143
  if (key !== 'theme' || ['light', 'dark', 'system'].includes(value)) return
135
-
136
144
  // throw error to abort operation
137
145
  throw new Error(`Invalid theme: ${value}`)
138
146
  },
139
147
  delete: ([keys]) => {
140
148
  if (!keys.includes('version')) return
141
-
142
149
  throw new Error('The "version" key is protected and cannot be deleted')
143
150
  },
144
151
  },
145
152
  })
146
-
147
153
  settingsStore.set('theme', 'system')
148
154
  console.log(settingsStore.get('theme')) // 'system
149
155
  try {
@@ -160,17 +166,18 @@ You can subscribe to changes using the internal RxJS Subject or a simple `onChan
160
166
  ```javascript
161
167
  import { createStore } from '@superutils/store'
162
168
 
163
- const storage = createStore('my-data', {
169
+ const store = createStore({
170
+ name: 'my-data',
164
171
  onChange: data => console.log('Data changed!', data),
165
172
  })
166
173
 
167
174
  // Or use the RxJS subject directly
168
- const sub = storage.subject$.subscribe(data => {
175
+ const sub = store.subject$.subscribe(data => {
169
176
  console.log('Reactive update:', data)
170
177
  })
171
178
 
172
- storage.set('key', 'value')
173
- ```
179
+ store.set('key', 'value')
180
+ ````
174
181
 
175
182
  ### Search and Filtering
176
183
 
@@ -179,8 +186,9 @@ storage.set('key', 'value')
179
186
  ```javascript
180
187
  import { createStore } from '@superutils/store'
181
188
 
182
- const storage = createStore('products', {
183
- // Instantiate the storage with initial value
189
+ const store = createStore({
190
+ name: 'products',
191
+ // Pre-populate the storage with sample data
184
192
  initialValue: new Map([
185
193
  [1, { id: 1, name: 'Laptop', category: 'electronics', price: 1000 }],
186
194
  [2, { id: 2, name: 'Chair', category: 'furniture', price: 150 }],
@@ -188,42 +196,50 @@ const storage = createStore('products', {
188
196
  })
189
197
 
190
198
  // Search for items using a query object
191
- const searchResult = storage.search({
199
+ const searchResult = store.search({
192
200
  query: { category: 'electronics' },
193
201
  })
194
202
  console.log(searchResult) // [{ id: 1, name: 'Laptop', ... }]
195
203
 
196
204
  // Filter items using a predicate
197
- const expensiveItems = storage.filter(val => val.price > 500)
205
+ const expensiveItems = store.filter(val => val.price > 500)
198
206
  ```
199
207
 
200
- ### Attaching Context (Business Logic)
208
+ ### Attaching Business Logic: Store Augmentation
201
209
 
202
- Using `createStore`, you can attach custom business logic (context) to your store instance, allowing you to encapsulate operations without having to create a subclass.
210
+ Using `createStore`, you can attach custom business logic to your store instance, allowing you to encapsulate operations without having to create a subclass.
203
211
 
204
212
  ```javascript
205
213
  import { createStore } from '@superutils/store'
206
214
 
207
- const authStore = createStore('auth', {
208
- context: store => ({
209
- isAuthenticated: () => store.has('token'),
210
- login: async () => {
211
- store.set('token', 'some-token')
212
- },
213
- logout: () => store.delete('token'),
214
- }),
215
- initialValue: new Map(),
215
+ const getContext = store => ({
216
+ // Context can be an object or a function that returns an object store => ({
217
+ get isAuthenticated() {
218
+ return store.has('token')
219
+ },
220
+ login: async () => {
221
+ store.set('token', 'some-token')
222
+ },
223
+ logout: () => store.delete('token'),
216
224
  })
217
225
 
218
- // Access your custom logic via the .context property
219
- if (!authStore.context.isAuthenticated()) {
220
- authStore.context.login().then(() => console.log('Logged in'))
226
+ const authStore = createStore(
227
+ {
228
+ initialValue: new Map(),
229
+ name: 'auth',
230
+ },
231
+ getContext,
232
+ )
233
+
234
+ // Access your custom logic directly from the store instance
235
+ if (!authStore.isAuthenticated) {
236
+ authStore.login().then(() => console.log('Logged in'))
221
237
  }
222
238
  ```
223
239
 
224
- ### Object-based Store With Context
240
+ ### Object-based Store With Augmentation
225
241
 
226
- `createObjectStore` supports context the same way as `createStore`.
242
+ `createObjectStore` supports augmentation the same way as `createStore`.
227
243
 
228
244
  ```typescript
229
245
  import { createObjectStore } from '@superutils/store'
@@ -235,21 +251,24 @@ type UserProfile = {
235
251
  roles: string[]
236
252
  }
237
253
 
238
- const userStore = createObjectStore('user-profile', {
239
- initialValue: {
240
- age: 25,
241
- name: 'Jane Doe',
242
- roles: ['guest'],
243
- } as UserProfile,
244
- context: store => ({
254
+ const userStore = createObjectStore(
255
+ {
256
+ name: 'user-profile',
257
+ initialValue: {
258
+ age: 25,
259
+ name: 'Jane Doe',
260
+ roles: ['guest'],
261
+ } as UserProfile,
262
+ },
263
+ store => ({
245
264
  promoteToAdmin() {
246
265
  // Update properties with type safety
247
266
  store.set('roles', roles => [...roles, 'admin'])
248
267
  },
249
268
  }),
250
- })
269
+ )
251
270
 
252
- userStore.context.promoteToAdmin()
271
+ userStore.promoteToAdmin()
253
272
  console.log(userStore.get('roles')) // ['guest', 'admin']
254
273
  ```
255
274
 
@@ -1,4 +1,4 @@
1
- this.superutils=this.superutils||{};this.superutils.store=(function(exports){'use strict';var v=(r,e=true)=>!!r&&typeof r=="object"&&(!e||[Object.prototype,null].includes(Object.getPrototypeOf(r)));var j=r=>Array.isArray(r);var te=r=>j(r)&&r.every(j),We=r=>j(r)||r instanceof Set||r instanceof Map;var Je=r=>Number.isInteger(r);var oe=r=>typeof r=="number"&&!Number.isNaN(r)&&Number.isFinite(r),qe=r=>Je(r)&&r>0,ge=r=>oe(r)&&r>0,xe=(r,e=false,t=false)=>{if(r==null)return true;switch(typeof r){case "number":return !oe(r);case "string":return !r.replaceAll(" ","").trim().length;case "boolean":case "bigint":case "symbol":case "function":return false}if(r instanceof Date)return Number.isNaN(r.getTime());if(r instanceof Map||r instanceof Set)return !r.size;if(Array.isArray(r)||r instanceof Uint8Array)return !r.length;if(r instanceof Error)return !r.message.length;let o=typeof r=="object"&&Object.getPrototypeOf(r);return o===Object.prototype||o===null?e?!Object.getOwnPropertyNames(r).length:!Object.keys(r).length:t};var b=r=>typeof r=="function";var S=r=>r instanceof Map;var Se=r=>r!=null;var He=r=>r instanceof Promise,$=r=>r instanceof RegExp,Ge=r=>r instanceof Set,M=r=>typeof r=="string";var Ye=r=>typeof r=="symbol";var w=(r,e,t)=>{try{let o=b(r)?r(...b(e)?e():e):r;return He(o)?o.catch(n=>b(t)?t(n):t):o}catch(o){return b(t)?t(o):t}},E=w;new Date().getTime();var Xe=(r,e=true,t=true)=>E(()=>[...t&&Object.getOwnPropertySymbols(r)||[],...e?Object.keys(r).sort():Object.keys(r)],[],[]),Ze=Xe,F=(r,e="null")=>JSON.parse(E(JSON.stringify,[r],e)),we=(r,e,t,o=false,n=true)=>{let i=v(e,false)||b(e)?e:{};if(!v(r,false)&&!b(e))return i;let s=new Set(t!=null?t:[]),a=Ze(r,true,true).filter(u=>!s.has(u));for(let u of a){let c=u,l=r[c];if(i.hasOwnProperty(c)&&(o==="empty"?!xe(i[c]):b(o)?!o(c,i[c],l):true))continue;if([void 0,null,1/0,NaN].includes(l)||!v(l,false)){i[c]=l;continue}i[c]=(()=>{switch(Object.getPrototypeOf(l)){case Array.prototype:return F(l,"[]");case ArrayBuffer.prototype:return l.slice(0);case Date.prototype:return new Date(l.getTime());case Map.prototype:return new Map(F(Array.from(l),"[]"));case RegExp.prototype:return new RegExp(l);case Set.prototype:return new Set(F(Array.from(l)));case Uint8Array.prototype:return new Uint8Array([...l]);case URL.prototype:return new URL(l);}if(Ye(c)||!n)return F(l);let m=[...s].map(y=>String(y).startsWith(String(c).concat("."))&&String(y).split(String(c).concat("."))[1]).filter(Boolean);return m.length?we(l,i[c],m,o,n):F(l)})();}return i},Qe=(r=[],e=[],t)=>{v(t)||(t={});for(let o=0;o<(j(r)?r:[]).length;o++)t[r[o]]=e==null?void 0:e[o];return t};function q(r){let e=Object.entries(v(r)?r:{});return new Map(e.map(([t,o])=>[t,o]))}var ye=(r,e=true,t=false)=>j(r)?(t&&(r=[...r]),e?r.reverse():r):[];var J=(r,e=50,t={})=>{let{leading:o=J.defaults.leading,onError:n=J.defaults.onError,thisArg:i}=t,{tid:s}=t;i!==void 0&&(r=r.bind(i));let a=(...l)=>E(r,l,n),u=null,c=o==="global";return (...l)=>{clearTimeout(s),s=setTimeout(()=>{u!==l&&a(...l),u=c?true:null;},e),!(!o||u)&&(u=l,a(...l));}};J.defaults={leading:false,onError:void 0};var er=J,ne=(r,e=50,t={})=>{let{defaults:o}=ne,{onError:n=o.onError,trailing:i=o.trailing,thisArg:s}=t,{tid:a}=t,u=(...l)=>E(s!==void 0?r.bind(s):r,l,b(n)?f=>E(n,[f],void 0):void 0),c=null;return (...l)=>{if(a){c=l;return}a=setTimeout(()=>{if(a=void 0,!i)return;let f=c;c=null,f&&f!==l&&u(...f);},e),u(...l);}};ne.defaults={onError:void 0,trailing:false};var rr=ne,_e=(r,e=50,t={})=>t.throttle?rr(r,e,t):er(r,e,t),ie=(r,e,t,o,n)=>{var i;S(n)||(n=new Map),qe(t)||(t=1/0);for(let[s,a]of ((i=r==null?void 0:r.entries)==null?void 0:i.call(r))||[]){if(n.size>=t)break;E(e!=null?e:a,[a,s,r],false)&&n.set(s,a);}return o?n:[...n.values()]},tr=ie,or=r=>{if(!r)return 0;try{let e="size"in r?r.size:"length"in r?r.length:0;return oe(e)?e:0}catch(e){return 0}},nr=or,se=r=>{var e;return [...((e=r==null?void 0:r.values)==null?void 0:e.call(r))||[]]},ve=se,D=(r,e)=>{var t;let o=!nr(r)||xe(e==null?void 0:e.query),n=S(e==null?void 0:e.result)?e.result:new Map,i=(t=e==null?void 0:e.asMap)!=null?t:D.defaults.asMap;if(o)return i?n:ve(n);e=we(D.defaults,e,[],"empty");let{ignoreCase:s,limit:a=1/0,matchAll:u,matchExact:c,ranked:l}=e,{query:f}=e,h=M(f),m=$(f),y=E(Object.keys,[f],[]);if(s&&!c&&!m&&(f=h?f.toLowerCase():Qe(y,Object.values(f).map(p=>$(p)?p:`${p}`.toLowerCase()))),e.query=f,l){let p=[];for(let[d,x]of r.entries()){let O=-1;if(h||m){O=W(e,x,void 0),O>=0&&p.push([O,d,x]);continue}let be=[];y[u?"every":"some"](N=>{let z=W(e,x,N);return be.push(z),z>=0})&&(O=be.sort((N,z)=>N-z).filter(N=>N!==-1)[0],O>=0&&p.push([O,d,x]));}p.sort((d,x)=>d[0]-x[0]).slice(0,a).forEach(([d,x,O])=>n.set(x,O));}else for(let[p,d]of r.entries()){if(n.size>=a)break;(h||m?W(e,d,void 0)>=0:y[u?"every":"some"](O=>W(e,d,O)>=0))&&n.set(p,d);}return i?n:ve(n)};D.defaults={asMap:true,ignoreCase:true,limit:1/0,matchAll:false,ranked:false,transform:true};function W({query:r,ignoreCase:e,matchExact:t,transform:o=true},n,i){var s,a;let u=M(r)||$(r)||i===void 0,c=u?r:r[i],l=u||!v(n)?n:n[i],f=E(()=>b(o)?o(n,u?void 0:l,i):t&&o===!1?l:v(l,!1)?JSON.stringify(We(l)?[...l.values()]:Object.values(l)):String(l!=null?l:""),[],"");if(f===c)return 0;if(t&&!$(c))return -1;let h=String(f);return h.trim()?$(c)?(a=(s=h.match(c))==null?void 0:s.index)!=null?a:-1:(e&&(h=h.toLowerCase()),h.indexOf(String(c))):-1}var ir=D;function Oe(r,e){return (b(e)?tr(r,e,1):ir(r,{...e,asMap:true,limit:1}))[e!=null&&e.includeKey?"entries":"values"]().next().value}var Te=r=>{var e;return [...((e=r==null?void 0:r.entries)==null?void 0:e.call(r))||[]]},je=r=>{var e;return [...((e=r==null?void 0:r.keys)==null?void 0:e.call(r))||[]]};function H(r,e,t){let o=j(r)?1:S(r)?2:Ge(r)?3:0;if(!o)return r;let{asString:n,ignoreCase:i,newInstance:s,reverse:a,undefinedFirst:u}={...H.defaults,...v(t)?t:v(e)?e:{}};if(o===1&&b(e))return ye(r.sort(e),a,s);let c=n?u?"":"Z".repeat(10):u?-1/0:1/0,l=b(e)?ye([...r.entries()].sort(e),a,false):(()=>{let f=1,h=p=>{let d=v(p)&&f!==0?p[e]:p;if(!n)return d;let x=`${d!=null?d:c}`;return i?x.toLowerCase():x},[m,y]=a?[-1,1]:[1,-1];return [1,3].includes(o)?(o===3||s?[...r]:r).sort((p,d)=>h(p)>h(d)?m:y):(f=e===true?0:1,[...r.entries()].sort((p,d)=>h(p==null?void 0:p[f])>h(d==null?void 0:d[f])?m:y))})();if(o===1)return l;if(s)return o===2?new Map(l):new Set(l);r.clear();for(let f of l)o===2?r.set(...f):r.add(f);return r}H.defaults={asString:true,ignoreCase:true,newInstance:false,reverse:false,undefinedFirst:false};var Ee=(...r)=>{var e;return new Map((e=r==null?void 0:r.flatMap)==null?void 0:e.call(r,t=>S(t)?Array.from(t.entries()):te(t)?t:[]))};var ae=function(r,e){return ae=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,o){t.__proto__=o;}||function(t,o){for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(t[n]=o[n]);},ae(r,e)};function T(r,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");ae(r,e);function t(){this.constructor=r;}r.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t);}function B(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],o=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return {next:function(){return r&&o>=r.length&&(r=void 0),{value:r&&r[o++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function I(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var o=t.call(r),n,i=[],s;try{for(;(e===void 0||e-- >0)&&!(n=o.next()).done;)i.push(n.value);}catch(a){s={error:a};}finally{try{n&&!n.done&&(t=o.return)&&t.call(o);}finally{if(s)throw s.error}}return i}function K(r,e,t){if(arguments.length===2)for(var o=0,n=e.length,i;o<n;o++)(i||!(o in e))&&(i||(i=Array.prototype.slice.call(e,0,o)),i[o]=e[o]);return r.concat(i||Array.prototype.slice.call(e))}function g(r){return typeof r=="function"}function G(r){var e=function(o){Error.call(o),o.stack=new Error().stack;},t=r(e);return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}var Y=G(function(r){return function(t){r(this),this.message=t?t.length+` errors occurred during unsubscription:
1
+ this.superutils=this.superutils||{};this.superutils.store=(function(exports){'use strict';var g=(r,e=true)=>!!r&&typeof r=="object"&&(!e||[Object.prototype,null].includes(Object.getPrototypeOf(r)));var T=r=>Array.isArray(r);var te=r=>T(r)&&r.every(T),Je=r=>T(r)||r instanceof Set||r instanceof Map;var qe=r=>Number.isInteger(r);var oe=r=>typeof r=="number"&&!Number.isNaN(r)&&Number.isFinite(r),He=r=>qe(r)&&r>0,ge=r=>oe(r)&&r>0,xe=(r,e=false,t=false)=>{if(r==null)return true;switch(typeof r){case "number":return !oe(r);case "string":return !r.replaceAll(" ","").trim().length;case "boolean":case "bigint":case "symbol":case "function":return false}if(r instanceof Date)return Number.isNaN(r.getTime());if(r instanceof Map||r instanceof Set)return !r.size;if(Array.isArray(r)||r instanceof Uint8Array)return !r.length;if(r instanceof Error)return !r.message.length;let o=typeof r=="object"&&Object.getPrototypeOf(r);return o===Object.prototype||o===null?e?!Object.getOwnPropertyNames(r).length:!Object.keys(r).length:t};var b=r=>typeof r=="function";var S=r=>r instanceof Map;var Se=r=>r!=null;var Ge=r=>r instanceof Promise,B=r=>r instanceof RegExp,Ye=r=>r instanceof Set,I=r=>typeof r=="string";var Xe=r=>typeof r=="symbol";var w=(r,e,t)=>{try{let o=b(r)?r(...b(e)?e():e):r;return Ge(o)?o.catch(n=>b(t)?t(n):t):o}catch(o){return b(t)?t(o):t}},j=w;new Date().getTime();var Ze=(r,e=true,t=true)=>j(()=>[...t&&Object.getOwnPropertySymbols(r)||[],...e?Object.keys(r).sort():Object.keys(r)],[],[]),Qe=Ze,$=(r,e="null")=>JSON.parse(j(JSON.stringify,[r],e)),we=(r,e,t,o=false,n=true)=>{let i=g(e,false)||b(e)?e:{};if(!g(r,false)&&!b(e))return i;let s=new Set(t!=null?t:[]),a=Qe(r,true,true).filter(l=>!s.has(l));for(let l of a){let c=l,u=r[c];if(i.hasOwnProperty(c)&&(o==="empty"?!xe(i[c]):b(o)?!o(c,i[c],u):true))continue;if([void 0,null,1/0,NaN].includes(u)||!g(u,false)){i[c]=u;continue}i[c]=(()=>{switch(Object.getPrototypeOf(u)){case Array.prototype:return $(u,"[]");case ArrayBuffer.prototype:return u.slice(0);case Date.prototype:return new Date(u.getTime());case Map.prototype:return new Map($(Array.from(u),"[]"));case RegExp.prototype:return new RegExp(u);case Set.prototype:return new Set($(Array.from(u)));case Uint8Array.prototype:return new Uint8Array([...u]);case URL.prototype:return new URL(u);}if(Xe(c)||!n)return $(u);let m=[...s].map(y=>String(y).startsWith(String(c).concat("."))&&String(y).split(String(c).concat("."))[1]).filter(Boolean);return m.length?we(u,i[c],m,o,n):$(u)})();}return i},er=(r=[],e=[],t)=>{g(t)||(t={});for(let o=0;o<(T(r)?r:[]).length;o++)t[r[o]]=e==null?void 0:e[o];return t};function D(r){let e=Object.entries(g(r)?r:{});return new Map(e.map(([t,o])=>[t,o]))}var ye=(r,e=true,t=false)=>T(r)?(t&&(r=[...r]),e?r.reverse():r):[];var q=(r,e=50,t={})=>{let{leading:o=q.defaults.leading,onError:n=q.defaults.onError,thisArg:i}=t,{tid:s}=t;i!==void 0&&(r=r.bind(i));let a=(...u)=>j(r,u,n),l=null,c=o==="global";return (...u)=>{clearTimeout(s),s=setTimeout(()=>{l!==u&&a(...u),l=c?true:null;},e),!(!o||l)&&(l=u,a(...u));}};q.defaults={leading:false,onError:void 0};var rr=q,ne=(r,e=50,t={})=>{let{defaults:o}=ne,{onError:n=o.onError,trailing:i=o.trailing,thisArg:s}=t,{tid:a}=t,l=(...u)=>j(s!==void 0?r.bind(s):r,u,b(n)?f=>j(n,[f],void 0):void 0),c=null;return (...u)=>{if(a){c=u;return}a=setTimeout(()=>{if(a=void 0,!i)return;let f=c;c=null,f&&f!==u&&l(...f);},e),l(...u);}};ne.defaults={onError:void 0,trailing:false};var tr=ne,_e=(r,e=50,t={})=>t.throttle?tr(r,e,t):rr(r,e,t),ie=(r,e,t,o,n)=>{var i;S(n)||(n=new Map),He(t)||(t=1/0);for(let[s,a]of ((i=r==null?void 0:r.entries)==null?void 0:i.call(r))||[]){if(n.size>=t)break;j(e!=null?e:a,[a,s,r],false)&&n.set(s,a);}return o?n:[...n.values()]},or=ie,nr=r=>{if(!r)return 0;try{let e="size"in r?r.size:"length"in r?r.length:0;return oe(e)?e:0}catch(e){return 0}},ir=nr,se=r=>{var e;return [...((e=r==null?void 0:r.values)==null?void 0:e.call(r))||[]]},ve=se,M=(r,e)=>{var t;let o=!ir(r)||xe(e==null?void 0:e.query),n=S(e==null?void 0:e.result)?e.result:new Map,i=(t=e==null?void 0:e.asMap)!=null?t:M.defaults.asMap;if(o)return i?n:ve(n);e=we(M.defaults,e,[],"empty");let{ignoreCase:s,limit:a=1/0,matchAll:l,matchExact:c,ranked:u}=e,{query:f}=e,h=I(f),m=B(f),y=j(Object.keys,[f],[]);if(s&&!c&&!m&&(f=h?f.toLowerCase():er(y,Object.values(f).map(p=>B(p)?p:`${p}`.toLowerCase()))),e.query=f,u){let p=[];for(let[d,v]of r.entries()){let O=-1;if(h||m){O=J(e,v,void 0),O>=0&&p.push([O,d,v]);continue}let be=[];y[l?"every":"some"](F=>{let W=J(e,v,F);return be.push(W),W>=0})&&(O=be.sort((F,W)=>F-W).filter(F=>F!==-1)[0],O>=0&&p.push([O,d,v]));}p.sort((d,v)=>d[0]-v[0]).slice(0,a).forEach(([d,v,O])=>n.set(v,O));}else for(let[p,d]of r.entries()){if(n.size>=a)break;(h||m?J(e,d,void 0)>=0:y[l?"every":"some"](O=>J(e,d,O)>=0))&&n.set(p,d);}return i?n:ve(n)};M.defaults={asMap:true,ignoreCase:true,limit:1/0,matchAll:false,ranked:false,transform:true};function J({query:r,ignoreCase:e,matchExact:t,transform:o=true},n,i){var s,a;let l=I(r)||B(r)||i===void 0,c=l?r:r[i],u=l||!g(n)?n:n[i],f=j(()=>b(o)?o(n,l?void 0:u,i):t&&o===!1?u:g(u,!1)?JSON.stringify(Je(u)?[...u.values()]:Object.values(u)):String(u!=null?u:""),[],"");if(f===c)return 0;if(t&&!B(c))return -1;let h=String(f);return h.trim()?B(c)?(a=(s=h.match(c))==null?void 0:s.index)!=null?a:-1:(e&&(h=h.toLowerCase()),h.indexOf(String(c))):-1}var sr=M;function Oe(r,e){return (b(e)?or(r,e,1):sr(r,{...e,asMap:true,limit:1}))[e!=null&&e.includeKey?"entries":"values"]().next().value}var Ee=r=>{var e;return [...((e=r==null?void 0:r.entries)==null?void 0:e.call(r))||[]]},Te=r=>{var e;return [...((e=r==null?void 0:r.keys)==null?void 0:e.call(r))||[]]};function H(r,e,t){let o=T(r)?1:S(r)?2:Ye(r)?3:0;if(!o)return r;let{asString:n,ignoreCase:i,newInstance:s,reverse:a,undefinedFirst:l}={...H.defaults,...g(t)?t:g(e)?e:{}};if(o===1&&b(e))return ye(r.sort(e),a,s);let c=n?l?"":"Z".repeat(10):l?-1/0:1/0,u=b(e)?ye([...r.entries()].sort(e),a,false):(()=>{let f=1,h=p=>{let d=g(p)&&f!==0?p[e]:p;if(!n)return d;let v=`${d!=null?d:c}`;return i?v.toLowerCase():v},[m,y]=a?[-1,1]:[1,-1];return [1,3].includes(o)?(o===3||s?[...r]:r).sort((p,d)=>h(p)>h(d)?m:y):(f=e===true?0:1,[...r.entries()].sort((p,d)=>h(p==null?void 0:p[f])>h(d==null?void 0:d[f])?m:y))})();if(o===1)return u;if(s)return o===2?new Map(u):new Set(u);r.clear();for(let f of u)o===2?r.set(...f):r.add(f);return r}H.defaults={asString:true,ignoreCase:true,newInstance:false,reverse:false,undefinedFirst:false};var je=(...r)=>{var e;return new Map((e=r==null?void 0:r.flatMap)==null?void 0:e.call(r,t=>S(t)?Array.from(t.entries()):te(t)?t:[]))};var ae=function(r,e){return ae=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,o){t.__proto__=o;}||function(t,o){for(var n in o)Object.prototype.hasOwnProperty.call(o,n)&&(t[n]=o[n]);},ae(r,e)};function E(r,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");ae(r,e);function t(){this.constructor=r;}r.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t);}function L(r){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&r[e],o=0;if(t)return t.call(r);if(r&&typeof r.length=="number")return {next:function(){return r&&o>=r.length&&(r=void 0),{value:r&&r[o++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function R(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var o=t.call(r),n,i=[],s;try{for(;(e===void 0||e-- >0)&&!(n=o.next()).done;)i.push(n.value);}catch(a){s={error:a};}finally{try{n&&!n.done&&(t=o.return)&&t.call(o);}finally{if(s)throw s.error}}return i}function U(r,e,t){if(arguments.length===2)for(var o=0,n=e.length,i;o<n;o++)(i||!(o in e))&&(i||(i=Array.prototype.slice.call(e,0,o)),i[o]=e[o]);return r.concat(i||Array.prototype.slice.call(e))}function x(r){return typeof r=="function"}function G(r){var e=function(o){Error.call(o),o.stack=new Error().stack;},t=r(e);return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}var Y=G(function(r){return function(t){r(this),this.message=t?t.length+` errors occurred during unsubscription:
2
2
  `+t.map(function(o,n){return n+1+") "+o.toString()}).join(`
3
- `):"",this.name="UnsubscriptionError",this.errors=t;}});function k(r,e){if(r){var t=r.indexOf(e);0<=t&&r.splice(t,1);}}var V=(function(){function r(e){this.initialTeardown=e,this.closed=false,this._parentage=null,this._finalizers=null;}return r.prototype.unsubscribe=function(){var e,t,o,n,i;if(!this.closed){this.closed=true;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var a=B(s),u=a.next();!u.done;u=a.next()){var c=u.value;c.remove(this);}}catch(p){e={error:p};}finally{try{u&&!u.done&&(t=a.return)&&t.call(a);}finally{if(e)throw e.error}}else s.remove(this);var l=this.initialTeardown;if(g(l))try{l();}catch(p){i=p instanceof Y?p.errors:[p];}var f=this._finalizers;if(f){this._finalizers=null;try{for(var h=B(f),m=h.next();!m.done;m=h.next()){var y=m.value;try{Ce(y);}catch(p){i=i!=null?i:[],p instanceof Y?i=K(K([],I(i)),I(p.errors)):i.push(p);}}}catch(p){o={error:p};}finally{try{m&&!m.done&&(n=h.return)&&n.call(h);}finally{if(o)throw o.error}}}if(i)throw new Y(i)}},r.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)Ce(e);else {if(e instanceof r){if(e.closed||e._hasParent(this))return;e._addParent(this);}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(e);}},r.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},r.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e;},r.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&k(t,e);},r.prototype.remove=function(e){var t=this._finalizers;t&&k(t,e),e instanceof r&&e._removeParent(this);},r.EMPTY=(function(){var e=new r;return e.closed=true,e})(),r})();var le=V.EMPTY;function X(r){return r instanceof V||r&&"closed"in r&&g(r.remove)&&g(r.add)&&g(r.unsubscribe)}function Ce(r){g(r)?r():r.unsubscribe();}var _={Promise:void 0};var R={setTimeout:function(r,e){for(var t=[],o=2;o<arguments.length;o++)t[o-2]=arguments[o];return setTimeout.apply(void 0,K([r,e],I(t)))},clearTimeout:function(r){return (clearTimeout)(r)},delegate:void 0};function Ae(r){R.setTimeout(function(){throw r});}function ue(){}function U(r){r();}var L=(function(r){T(e,r);function e(t){var o=r.call(this)||this;return o.isStopped=false,t?(o.destination=t,X(t)&&t.add(o)):o.destination=ur,o}return e.create=function(t,o,n){return new Q(t,o,n)},e.prototype.next=function(t){this.isStopped?pe():this._next(t);},e.prototype.error=function(t){this.isStopped?pe():(this.isStopped=true,this._error(t));},e.prototype.complete=function(){this.isStopped?pe():(this.isStopped=true,this._complete());},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=true,r.prototype.unsubscribe.call(this),this.destination=null);},e.prototype._next=function(t){this.destination.next(t);},e.prototype._error=function(t){try{this.destination.error(t);}finally{this.unsubscribe();}},e.prototype._complete=function(){try{this.destination.complete();}finally{this.unsubscribe();}},e})(V);var ar=(function(){function r(e){this.partialObserver=e;}return r.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e);}catch(o){Z(o);}},r.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e);}catch(o){Z(o);}else Z(e);},r.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete();}catch(t){Z(t);}},r})(),Q=(function(r){T(e,r);function e(t,o,n){var i=r.call(this)||this,s;if(g(t)||!t)s={next:t!=null?t:void 0,error:o!=null?o:void 0,complete:n!=null?n:void 0};else {s=t;}return i.destination=new ar(s),i}return e})(L);function Z(r){Ae(r);}function lr(r){throw r}function pe(r,e){}var ur={closed:true,next:ue,error:lr,complete:ue};var Ke=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function Ve(r){return r}function Re(r){return r.length===0?Ve:r.length===1?r[0]:function(t){return r.reduce(function(o,n){return n(o)},t)}}var he=(function(){function r(e){e&&(this._subscribe=e);}return r.prototype.lift=function(e){var t=new r;return t.source=this,t.operator=e,t},r.prototype.subscribe=function(e,t,o){var n=this,i=fr(e)?e:new Q(e,t,o);return U(function(){var s=n,a=s.operator,u=s.source;i.add(a?a.call(i,u):u?n._subscribe(i):n._trySubscribe(i));}),i},r.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t);}},r.prototype.forEach=function(e,t){var o=this;return t=Ue(t),new t(function(n,i){var s=new Q({next:function(a){try{e(a);}catch(u){i(u),s.unsubscribe();}},error:i,complete:n});o.subscribe(s);})},r.prototype._subscribe=function(e){var t;return (t=this.source)===null||t===void 0?void 0:t.subscribe(e)},r.prototype[Ke]=function(){return this},r.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Re(e)(this)},r.prototype.toPromise=function(e){var t=this;return e=Ue(e),new e(function(o,n){var i;t.subscribe(function(s){return i=s},function(s){return n(s)},function(){return o(i)});})},r.create=function(e){return new r(e)},r})();function Ue(r){var e;return (e=r!=null?r:_.Promise)!==null&&e!==void 0?e:Promise}function cr(r){return r&&g(r.next)&&g(r.error)&&g(r.complete)}function fr(r){return r&&r instanceof L||cr(r)&&X(r)}function pr(r){return g(r==null?void 0:r.lift)}function Ne(r){return function(e){if(pr(e))return e.lift(function(t){try{return r(t,this)}catch(o){this.error(o);}});throw new TypeError("Unable to lift unknown Observable type")}}function Fe(r,e,t,o,n){return new hr(r,e,t,o,n)}var hr=(function(r){T(e,r);function e(t,o,n,i,s,a){var u=r.call(this,t)||this;return u.onFinalize=s,u.shouldUnsubscribe=a,u._next=o?function(c){try{o(c);}catch(l){t.error(l);}}:r.prototype._next,u._error=i?function(c){try{i(c);}catch(l){t.error(l);}finally{this.unsubscribe();}}:r.prototype._error,u._complete=n?function(){try{n();}catch(c){t.error(c);}finally{this.unsubscribe();}}:r.prototype._complete,u}return e.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var o=this.closed;r.prototype.unsubscribe.call(this),!o&&((t=this.onFinalize)===null||t===void 0||t.call(this));}},e})(L);var $e=G(function(r){return function(){r(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed";}});var A=(function(r){T(e,r);function e(){var t=r.call(this)||this;return t.closed=false,t.currentObservers=null,t.observers=[],t.isStopped=false,t.hasError=false,t.thrownError=null,t}return e.prototype.lift=function(t){var o=new Be(this,this);return o.operator=t,o},e.prototype._throwIfClosed=function(){if(this.closed)throw new $e},e.prototype.next=function(t){var o=this;U(function(){var n,i;if(o._throwIfClosed(),!o.isStopped){o.currentObservers||(o.currentObservers=Array.from(o.observers));try{for(var s=B(o.currentObservers),a=s.next();!a.done;a=s.next()){var u=a.value;u.next(t);}}catch(c){n={error:c};}finally{try{a&&!a.done&&(i=s.return)&&i.call(s);}finally{if(n)throw n.error}}}});},e.prototype.error=function(t){var o=this;U(function(){if(o._throwIfClosed(),!o.isStopped){o.hasError=o.isStopped=true,o.thrownError=t;for(var n=o.observers;n.length;)n.shift().error(t);}});},e.prototype.complete=function(){var t=this;U(function(){if(t._throwIfClosed(),!t.isStopped){t.isStopped=true;for(var o=t.observers;o.length;)o.shift().complete();}});},e.prototype.unsubscribe=function(){this.isStopped=this.closed=true,this.observers=this.currentObservers=null;},Object.defineProperty(e.prototype,"observed",{get:function(){var t;return ((t=this.observers)===null||t===void 0?void 0:t.length)>0},enumerable:false,configurable:true}),e.prototype._trySubscribe=function(t){return this._throwIfClosed(),r.prototype._trySubscribe.call(this,t)},e.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},e.prototype._innerSubscribe=function(t){var o=this,n=this,i=n.hasError,s=n.isStopped,a=n.observers;return i||s?le:(this.currentObservers=null,a.push(t),new V(function(){o.currentObservers=null,k(a,t);}))},e.prototype._checkFinalizedStatuses=function(t){var o=this,n=o.hasError,i=o.thrownError,s=o.isStopped;n?t.error(i):s&&t.complete();},e.prototype.asObservable=function(){var t=new he;return t.source=this,t},e.create=function(t,o){return new Be(t,o)},e})(he);var Be=(function(r){T(e,r);function e(t,o){var n=r.call(this)||this;return n.destination=t,n.source=o,n}return e.prototype.next=function(t){var o,n;(n=(o=this.destination)===null||o===void 0?void 0:o.next)===null||n===void 0||n.call(o,t);},e.prototype.error=function(t){var o,n;(n=(o=this.destination)===null||o===void 0?void 0:o.error)===null||n===void 0||n.call(o,t);},e.prototype.complete=function(){var t,o;(o=(t=this.destination)===null||t===void 0?void 0:t.complete)===null||o===void 0||o.call(t);},e.prototype._subscribe=function(t){var o,n;return (n=(o=this.source)===null||o===void 0?void 0:o.subscribe(t))!==null&&n!==void 0?n:le},e})(A);var ee=(function(r){T(e,r);function e(t){var o=r.call(this)||this;return o._value=t,o}return Object.defineProperty(e.prototype,"value",{get:function(){return this.getValue()},enumerable:false,configurable:true}),e.prototype._subscribe=function(t){var o=r.prototype._subscribe.call(this,t);return !o.closed&&t.next(this._value),o},e.prototype.getValue=function(){var t=this,o=t.hasError,n=t.thrownError,i=t._value;if(o)throw n;return this._throwIfClosed(),i},e.prototype.next=function(t){r.prototype.next.call(this,this._value=t);},e})(A);function ke(r,e){return Ne(function(t,o){var n=0;t.subscribe(Fe(o,function(i){return r.call(e,i,n++)&&o.next(i)}));})}function de(r){return ke(function(e,t){return r<=t})}var dr=(s=>(s.onChange="onChange",s.parse="parse",s.parse_json="parse-json",s.stringify="stringify",s.stringify_json="stringify-json",s.write="write",s))(dr||{});var Le=new A,P=class P{constructor(e,t){this.initialized=false;this.subscriptions={subject:void 0,forceUpdateCache:void 0};this.type="map";this.clear=()=>{var e,t;return (t=(e=this.validate)==null?void 0:e.clear)==null||t.call(this,[],"clear"),this.setAll(new Map,true)};this.delete=e=>{var o,n;j(e)||(e=[e]),(n=(o=this.validate)==null?void 0:o.delete)==null||n.call(this,[e],"delete");let t=this.getAll();for(let i of e)t.delete(i);return this.setAll(t,true),this};this.filter=(...e)=>ie(this.getAll(),...e);this.find=e=>Oe(this.getAll(),e);this.get=e=>this.getAll().get(e);this.getAll=(e=false)=>{let t=this.initialized;if(t||this.init(),this.cacheDisabled||this.storage&&e){let n=this.read();return (e||!t&&n.size)&&this.subject$.next(n),n}return this.subject$.value};this.handleForceUpdateCache=e=>{if(!(this.name?j(e)?e.includes(this.name):M(e)?e===this.name:e===true:false))return;let o=this.read();this.subject$.next(o);};this.handleSubjectChange=e=>{var t;if(!S(e))return this.subject$.next(new Map);w(this.write,[e],null),w((t=this.onChange)==null?void 0:t.bind(this),[e],this.triggerOnErrorCb("onChange"));};this.has=e=>this.getAll().has(e);this.init=(e,t=true)=>{var i;if(this.initialized)return false;if(this.name&&t&&(Object.defineProperty(this,"storage",{value:w(()=>{var s;return (s=this.storage)!=null?s:globalThis.localStorage},[],void 0)}),!this.storage))throw new Error(P.messages.invalidStorageOptions);Object.defineProperty(this,"initialized",{value:true});let o=e;if(e!=null&&e.size||!this.cacheDisabled){let s=this.name?(i=this.storage)==null?void 0:i.getItem(this.name):null,a=this.read(s!=null?s:null);Se(s)&&(o=a);}o!=null&&o.size&&this.subject$.next(o),this.unsubscribe(),this.cacheDisabled||(this.subscriptions.forceUpdateCache=Le.subscribe(this.handleForceUpdateCache));let n=this.subject$ instanceof ee&&(o!=null&&o.size)&&o!==e?1:0;return this.subscriptions.subject=this.subject$.pipe(de(n)).subscribe(!this.cacheDisabled&&this.delay>0?_e(this.handleSubjectChange,this.delay,{thisArg:this,...this.delayOptions}):this.handleSubjectChange),true};this.keys=()=>je(this.getAll());this.map=e=>this.toArray().map(([t,o],n,i)=>e(o,t,i,n));this.read=(e=(o=>(o=this.name&&(t=>(t=this.storage)==null?void 0:t.getItem(this.name))())!=null?o:null)())=>{var i;let n=w(this.parse,[e],this.triggerOnErrorCb("parse",void 0));return S(n)||!M(e)?(i=b(this.parse)?n:this.subject$.value)!=null?i:new Map:new Map(w(()=>{let s=JSON.parse(e);if(!te(s))throw new Error(P.messages.invalidJsonEntries);return s},[],this.triggerOnErrorCb("parse-json")))};this.search=(...e)=>D(this.getAll(),...e);this.set=(e,t)=>{var i,s;let o=this.getAll(),n=b(t)?t(o.get(e)):t;return (s=(i=this.validate)==null?void 0:i.set)==null||s.call(this,[e,n],"set"),o.set(e,n),this.setAll(o,true)};this.setAll=(e,t=false)=>{var o,n;return S(e)?((n=(o=this.validate)==null?void 0:o.setAll)==null||n.call(this,[e,t],"setAll"),e=t?e:Ee(this.getAll(),e),this.subject$.next(new Map(e)),this):this};this.sort=(...e)=>{var o;let t=H(this.getAll(),e[0],e[1]);return (o=e[1])!=null&&o.save&&this.setAll(t,true),t};this.toArray=()=>Te(this.getAll());this.toJSON=(e,t=this.spaces,o=this.getAll())=>{let n=w(this.stringify,[o],this.triggerOnErrorCb("stringify",""));return M(n)?n:w(()=>JSON.stringify(Array.from(o),e,t),[],this.triggerOnErrorCb("stringify-json",""))};this.toObject=(e=this.getAll())=>{let t={};if(!S(e))return t;for(let[o,n]of e)t[o]=n;return t};this.toString=(e=this.getAll())=>this.toJSON(void 0,void 0,e);this.triggerOnErrorCb=(e,t=void 0)=>o=>{var n;return w((n=this.onError)==null?void 0:n.bind(this),[o,e],""),t};this.unsubscribe=()=>{var e,t;(e=this.subscriptions.forceUpdateCache)==null||e.unsubscribe(),(t=this.subscriptions.subject)==null||t.unsubscribe(),this.subscriptions={forceUpdateCache:void 0,subject:void 0};};this.values=()=>se(this.getAll());this.write=e=>{var t,o,n;if(this.init(),e!=null||(e=(t=this.subject$)==null?void 0:t.value),!S(e)||!this.name||!this.storage)return false;(n=(o=this.validate)==null?void 0:o.write)==null||n.call(this,[e],"write");try{let i=this.toString(e);return this.storage.setItem(this.name,i),!0}catch(i){return this.triggerOnErrorCb("write")(i),false}};this.name=`${e!=null?e:""}`.trim()||null;let{cacheDisabled:o=false,delay:n,delayOptions:i,initialValue:s,onError:a,onChange:u,parse:c,spaces:l,storage:f=w(()=>e?globalThis.localStorage:void 0,[],void 0),stringify:h,validate:m={}}=t!=null?t:{};if(this.name&&!f&&f!==null)throw new Error(P.messages.invalidStorageOptions);this.cacheDisabled=!!f&&o,this.delay=n===0||ge(n)?n:300,this.delayOptions=i,this.onError=a,this.onChange=u,this.parse=c==null?void 0:c.bind(this),this.spaces=l,this.storage=f,this.stringify=h==null?void 0:h.bind(this),this.subject$=this.cacheDisabled?new A:new ee(new Map);let y={...m};for(let[p,d]of Object.entries(y))y[p]=d;this.validate=y,S(s)&&s.size&&this.init(s,false);}get size(){return this.getAll().size}};P.messages=Object.seal({invalidJsonEntries:"Invalid JSON format. Parsed value must be a 2D array representing key-value pairs.",invalidStorageOptions:"options.storage: LocalStorage instance or equivalent required. For NodeJS, use `node-localstorage` NPM module.",validationError:"Validation failed. Action: "}),P.forceUpdateCache=e=>{Le.next(e);};var me=P,re=me;function mr(r,e){v(r)&&(e=r,r=null);let t=new re(r,e);return Object.defineProperty(t,"context",{configurable:false,enumerable:false,value:b(e==null?void 0:e.context)?e.context(t):e==null?void 0:e.context,writable:false}),t}var ze=mr;function Wt(r,e){v(r)&&(e=r,r=null);let t=ze(r,{parse:o=>q(JSON.parse(o!=null?o:"{}")),stringify:function(o){return JSON.stringify(this.toObject(o))},...e,initialValue:v(e==null?void 0:e.initialValue,true)?q(e.initialValue):e==null?void 0:e.initialValue});return t.type="object",t}var Ht=re;exports.Store=me;exports.Store_OnErrorType=dr;exports.createObjectStore=Wt;exports.createStore=mr;exports.default=Ht;exports.forceUpdateCache$=Le;exports.objToMap=q;Object.defineProperty(exports,'__esModule',{value:true});return exports;})({});//# sourceMappingURL=index.min.js.map
3
+ `):"",this.name="UnsubscriptionError",this.errors=t;}});function z(r,e){if(r){var t=r.indexOf(e);0<=t&&r.splice(t,1);}}var V=(function(){function r(e){this.initialTeardown=e,this.closed=false,this._parentage=null,this._finalizers=null;}return r.prototype.unsubscribe=function(){var e,t,o,n,i;if(!this.closed){this.closed=true;var s=this._parentage;if(s)if(this._parentage=null,Array.isArray(s))try{for(var a=L(s),l=a.next();!l.done;l=a.next()){var c=l.value;c.remove(this);}}catch(p){e={error:p};}finally{try{l&&!l.done&&(t=a.return)&&t.call(a);}finally{if(e)throw e.error}}else s.remove(this);var u=this.initialTeardown;if(x(u))try{u();}catch(p){i=p instanceof Y?p.errors:[p];}var f=this._finalizers;if(f){this._finalizers=null;try{for(var h=L(f),m=h.next();!m.done;m=h.next()){var y=m.value;try{Ae(y);}catch(p){i=i!=null?i:[],p instanceof Y?i=U(U([],R(i)),R(p.errors)):i.push(p);}}}catch(p){o={error:p};}finally{try{m&&!m.done&&(n=h.return)&&n.call(h);}finally{if(o)throw o.error}}}if(i)throw new Y(i)}},r.prototype.add=function(e){var t;if(e&&e!==this)if(this.closed)Ae(e);else {if(e instanceof r){if(e.closed||e._hasParent(this))return;e._addParent(this);}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(e);}},r.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},r.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e;},r.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&z(t,e);},r.prototype.remove=function(e){var t=this._finalizers;t&&z(t,e),e instanceof r&&e._removeParent(this);},r.EMPTY=(function(){var e=new r;return e.closed=true,e})(),r})();var ue=V.EMPTY;function X(r){return r instanceof V||r&&"closed"in r&&x(r.remove)&&x(r.add)&&x(r.unsubscribe)}function Ae(r){x(r)?r():r.unsubscribe();}var _={Promise:void 0};var N={setTimeout:function(r,e){for(var t=[],o=2;o<arguments.length;o++)t[o-2]=arguments[o];return setTimeout.apply(void 0,U([r,e],R(t)))},clearTimeout:function(r){return (clearTimeout)(r)},delegate:void 0};function Ce(r){N.setTimeout(function(){throw r});}function le(){}function K(r){r();}var k=(function(r){E(e,r);function e(t){var o=r.call(this)||this;return o.isStopped=false,t?(o.destination=t,X(t)&&t.add(o)):o.destination=cr,o}return e.create=function(t,o,n){return new Q(t,o,n)},e.prototype.next=function(t){this.isStopped?pe():this._next(t);},e.prototype.error=function(t){this.isStopped?pe():(this.isStopped=true,this._error(t));},e.prototype.complete=function(){this.isStopped?pe():(this.isStopped=true,this._complete());},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=true,r.prototype.unsubscribe.call(this),this.destination=null);},e.prototype._next=function(t){this.destination.next(t);},e.prototype._error=function(t){try{this.destination.error(t);}finally{this.unsubscribe();}},e.prototype._complete=function(){try{this.destination.complete();}finally{this.unsubscribe();}},e})(V);var ur=(function(){function r(e){this.partialObserver=e;}return r.prototype.next=function(e){var t=this.partialObserver;if(t.next)try{t.next(e);}catch(o){Z(o);}},r.prototype.error=function(e){var t=this.partialObserver;if(t.error)try{t.error(e);}catch(o){Z(o);}else Z(e);},r.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete();}catch(t){Z(t);}},r})(),Q=(function(r){E(e,r);function e(t,o,n){var i=r.call(this)||this,s;if(x(t)||!t)s={next:t!=null?t:void 0,error:o!=null?o:void 0,complete:n!=null?n:void 0};else {s=t;}return i.destination=new ur(s),i}return e})(k);function Z(r){Ce(r);}function lr(r){throw r}function pe(r,e){}var cr={closed:true,next:le,error:lr,complete:le};var Re=(function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"})();function Ue(r){return r}function Ve(r){return r.length===0?Ue:r.length===1?r[0]:function(t){return r.reduce(function(o,n){return n(o)},t)}}var he=(function(){function r(e){e&&(this._subscribe=e);}return r.prototype.lift=function(e){var t=new r;return t.source=this,t.operator=e,t},r.prototype.subscribe=function(e,t,o){var n=this,i=pr(e)?e:new Q(e,t,o);return K(function(){var s=n,a=s.operator,l=s.source;i.add(a?a.call(i,l):l?n._subscribe(i):n._trySubscribe(i));}),i},r.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t);}},r.prototype.forEach=function(e,t){var o=this;return t=Ne(t),new t(function(n,i){var s=new Q({next:function(a){try{e(a);}catch(l){i(l),s.unsubscribe();}},error:i,complete:n});o.subscribe(s);})},r.prototype._subscribe=function(e){var t;return (t=this.source)===null||t===void 0?void 0:t.subscribe(e)},r.prototype[Re]=function(){return this},r.prototype.pipe=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return Ve(e)(this)},r.prototype.toPromise=function(e){var t=this;return e=Ne(e),new e(function(o,n){var i;t.subscribe(function(s){return i=s},function(s){return n(s)},function(){return o(i)});})},r.create=function(e){return new r(e)},r})();function Ne(r){var e;return (e=r!=null?r:_.Promise)!==null&&e!==void 0?e:Promise}function fr(r){return r&&x(r.next)&&x(r.error)&&x(r.complete)}function pr(r){return r&&r instanceof k||fr(r)&&X(r)}function hr(r){return x(r==null?void 0:r.lift)}function Ke(r){return function(e){if(hr(e))return e.lift(function(t){try{return r(t,this)}catch(o){this.error(o);}});throw new TypeError("Unable to lift unknown Observable type")}}function Fe(r,e,t,o,n){return new dr(r,e,t,o,n)}var dr=(function(r){E(e,r);function e(t,o,n,i,s,a){var l=r.call(this,t)||this;return l.onFinalize=s,l.shouldUnsubscribe=a,l._next=o?function(c){try{o(c);}catch(u){t.error(u);}}:r.prototype._next,l._error=i?function(c){try{i(c);}catch(u){t.error(u);}finally{this.unsubscribe();}}:r.prototype._error,l._complete=n?function(){try{n();}catch(c){t.error(c);}finally{this.unsubscribe();}}:r.prototype._complete,l}return e.prototype.unsubscribe=function(){var t;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var o=this.closed;r.prototype.unsubscribe.call(this),!o&&((t=this.onFinalize)===null||t===void 0||t.call(this));}},e})(k);var $e=G(function(r){return function(){r(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed";}});var C=(function(r){E(e,r);function e(){var t=r.call(this)||this;return t.closed=false,t.currentObservers=null,t.observers=[],t.isStopped=false,t.hasError=false,t.thrownError=null,t}return e.prototype.lift=function(t){var o=new Be(this,this);return o.operator=t,o},e.prototype._throwIfClosed=function(){if(this.closed)throw new $e},e.prototype.next=function(t){var o=this;K(function(){var n,i;if(o._throwIfClosed(),!o.isStopped){o.currentObservers||(o.currentObservers=Array.from(o.observers));try{for(var s=L(o.currentObservers),a=s.next();!a.done;a=s.next()){var l=a.value;l.next(t);}}catch(c){n={error:c};}finally{try{a&&!a.done&&(i=s.return)&&i.call(s);}finally{if(n)throw n.error}}}});},e.prototype.error=function(t){var o=this;K(function(){if(o._throwIfClosed(),!o.isStopped){o.hasError=o.isStopped=true,o.thrownError=t;for(var n=o.observers;n.length;)n.shift().error(t);}});},e.prototype.complete=function(){var t=this;K(function(){if(t._throwIfClosed(),!t.isStopped){t.isStopped=true;for(var o=t.observers;o.length;)o.shift().complete();}});},e.prototype.unsubscribe=function(){this.isStopped=this.closed=true,this.observers=this.currentObservers=null;},Object.defineProperty(e.prototype,"observed",{get:function(){var t;return ((t=this.observers)===null||t===void 0?void 0:t.length)>0},enumerable:false,configurable:true}),e.prototype._trySubscribe=function(t){return this._throwIfClosed(),r.prototype._trySubscribe.call(this,t)},e.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},e.prototype._innerSubscribe=function(t){var o=this,n=this,i=n.hasError,s=n.isStopped,a=n.observers;return i||s?ue:(this.currentObservers=null,a.push(t),new V(function(){o.currentObservers=null,z(a,t);}))},e.prototype._checkFinalizedStatuses=function(t){var o=this,n=o.hasError,i=o.thrownError,s=o.isStopped;n?t.error(i):s&&t.complete();},e.prototype.asObservable=function(){var t=new he;return t.source=this,t},e.create=function(t,o){return new Be(t,o)},e})(he);var Be=(function(r){E(e,r);function e(t,o){var n=r.call(this)||this;return n.destination=t,n.source=o,n}return e.prototype.next=function(t){var o,n;(n=(o=this.destination)===null||o===void 0?void 0:o.next)===null||n===void 0||n.call(o,t);},e.prototype.error=function(t){var o,n;(n=(o=this.destination)===null||o===void 0?void 0:o.error)===null||n===void 0||n.call(o,t);},e.prototype.complete=function(){var t,o;(o=(t=this.destination)===null||t===void 0?void 0:t.complete)===null||o===void 0||o.call(t);},e.prototype._subscribe=function(t){var o,n;return (n=(o=this.source)===null||o===void 0?void 0:o.subscribe(t))!==null&&n!==void 0?n:ue},e})(C);var ee=(function(r){E(e,r);function e(t){var o=r.call(this)||this;return o._value=t,o}return Object.defineProperty(e.prototype,"value",{get:function(){return this.getValue()},enumerable:false,configurable:true}),e.prototype._subscribe=function(t){var o=r.prototype._subscribe.call(this,t);return !o.closed&&t.next(this._value),o},e.prototype.getValue=function(){var t=this,o=t.hasError,n=t.thrownError,i=t._value;if(o)throw n;return this._throwIfClosed(),i},e.prototype.next=function(t){r.prototype.next.call(this,this._value=t);},e})(C);function Le(r,e){return Ke(function(t,o){var n=0;t.subscribe(Fe(o,function(i){return r.call(e,i,n++)&&o.next(i)}));})}function de(r){return Le(function(e,t){return r<=t})}var mr=(s=>(s.onChange="onChange",s.parse="parse",s.parse_json="parse-json",s.stringify="stringify",s.stringify_json="stringify-json",s.write="write",s))(mr||{});var ze=new C,P=class P{constructor(e,t){this.initialized=false;this.subscriptions={subject:void 0,forceUpdateCache:void 0};this.type="map";this.clear=()=>{var e,t;return (t=(e=this.validate)==null?void 0:e.clear)==null||t.call(this,[],"clear"),this.setAll(new Map,true)};this.delete=e=>{var o,n;T(e)||(e=[e]),(n=(o=this.validate)==null?void 0:o.delete)==null||n.call(this,[e],"delete");let t=this.getAll();for(let i of e)t.delete(i);return this.setAll(t,true),this};this.filter=(...e)=>ie(this.getAll(),...e);this.find=e=>Oe(this.getAll(),e);this.get=e=>this.getAll().get(e);this.getAll=(e=false)=>{let t=this.initialized;if(t||this.init(),this.cacheDisabled||this.storage&&e){let n=this.read();return (e||!t&&n.size)&&this.subject$.next(n),n}return this.subject$.value};this.handleForceUpdateCache=e=>{if(!(this.name?T(e)?e.includes(this.name):I(e)?e===this.name:e===true:false))return;let o=this.read();this.subject$.next(o);};this.handleSubjectChange=e=>{var t;if(!S(e))return this.subject$.next(new Map);w(this.write,[e],this.triggerOnErrorCb("write")),w((t=this.onChange)==null?void 0:t.bind(this),[e],this.triggerOnErrorCb("onChange"));};this.has=e=>this.getAll().has(e);this.init=(e,t=true)=>{var i;if(this.initialized)return false;if(this.name&&t&&(Object.defineProperty(this,"storage",{value:w(()=>{var s;return (s=this.storage)!=null?s:globalThis.localStorage},[],void 0)}),!this.storage))throw new Error(P.messages.invalidStorageOptions);Object.defineProperty(this,"initialized",{value:true});let o=e;if(e!=null&&e.size||!this.cacheDisabled){let s=this.name?(i=this.storage)==null?void 0:i.getItem(this.name):null,a=this.read(s!=null?s:null);Se(s)&&(o=a);}o!=null&&o.size&&this.subject$.next(o),this.unsubscribe(),this.cacheDisabled||(this.subscriptions.forceUpdateCache=ze.subscribe(this.handleForceUpdateCache));let n=this.subject$ instanceof ee&&(o!=null&&o.size)&&o!==e?1:0;return this.subscriptions.subject=this.subject$.pipe(de(n)).subscribe(!this.cacheDisabled&&this.delay>0?_e(this.handleSubjectChange,this.delay,{thisArg:this,...this.delayOptions}):this.handleSubjectChange),true};this.keys=()=>Te(this.getAll());this.map=e=>this.toArray().map(([t,o],n,i)=>e(o,t,i,n));this.read=(e=(o=>(o=this.name&&(t=>(t=this.storage)==null?void 0:t.getItem(this.name))())!=null?o:null)())=>{var i;let n=w(this.parse,[e],this.triggerOnErrorCb("parse",void 0));return S(n)||!I(e)?(i=b(this.parse)?n:this.subject$.value)!=null?i:new Map:new Map(w(()=>{let s=JSON.parse(e);if(!te(s))throw new Error(P.messages.invalidJsonEntries);return s},[],this.triggerOnErrorCb("parse-json")))};this.search=(...e)=>M(this.getAll(),...e);this.set=(e,t)=>{var i,s;let o=this.getAll(),n=b(t)?t(o.get(e)):t;return (s=(i=this.validate)==null?void 0:i.set)==null||s.call(this,[e,n],"set"),o.set(e,n),this.setAll(o,true)};this.setAll=(e,t=false)=>{var o,n;return S(e)?((n=(o=this.validate)==null?void 0:o.setAll)==null||n.call(this,[e,t],"setAll"),e=t?e:je(this.getAll(),e),this.subject$.next(new Map(e)),this):this};this.sort=(...e)=>{var o;let t=H(this.getAll(),e[0],e[1]);return (o=e[1])!=null&&o.save&&this.setAll(t,true),t};this.toArray=()=>Ee(this.getAll());this.toJSON=(e,t=this.spaces,o=this.getAll())=>{let n=w(this.stringify,[o],this.triggerOnErrorCb("stringify",""));return I(n)?n:w(()=>JSON.stringify(Array.from(o),e,t),[],this.triggerOnErrorCb("stringify-json",""))};this.toObject=(e=this.getAll())=>{let t={};if(!S(e))return t;for(let[o,n]of e)t[o]=n;return t};this.toString=(e=this.getAll())=>this.toJSON(void 0,void 0,e);this.triggerOnErrorCb=(e,t=void 0)=>o=>{var n;return w((n=this.onError)==null?void 0:n.bind(this),[o,e],""),t};this.unsubscribe=()=>{var e,t;(e=this.subscriptions.forceUpdateCache)==null||e.unsubscribe(),(t=this.subscriptions.subject)==null||t.unsubscribe(),this.subscriptions={forceUpdateCache:void 0,subject:void 0};};this.values=()=>se(this.getAll());this.write=e=>{var t,o,n;if(this.init(),e!=null||(e=(t=this.subject$)==null?void 0:t.value),!S(e)||!this.name||!this.storage)return false;(n=(o=this.validate)==null?void 0:o.write)==null||n.call(this,[e],"write");try{let i=this.toString(e);return this.storage.setItem(this.name,i),!0}catch(i){return this.triggerOnErrorCb("write")(i),false}};var p;this.name=`${(p=e!=null?e:t==null?void 0:t.name)!=null?p:""}`.trim()||null;let{cacheDisabled:o=false,delay:n,delayOptions:i,initialValue:s,onError:a,onChange:l,parse:c,spaces:u,storage:f=w(()=>this.name?globalThis.localStorage:void 0,[],void 0),stringify:h,validate:m={}}=t!=null?t:{};if(this.name&&!f&&f!==null)throw new Error(P.messages.invalidStorageOptions);this.cacheDisabled=!!f&&o,this.delay=n===0||ge(n)?n:300,this.delayOptions=i,this.onError=a,this.onChange=l,this.parse=c==null?void 0:c.bind(this),this.spaces=u,this.storage=f,this.stringify=h==null?void 0:h.bind(this),this.subject$=this.cacheDisabled?new C:new ee(new Map);let y={...m};for(let[d,v]of Object.entries(y))y[d]=v;this.validate=y,S(s)&&s.size&&this.init(s,false);}get size(){return this.getAll().size}};P.messages=Object.seal({invalidJsonEntries:"Invalid JSON format. Parsed value must be a 2D array representing key-value pairs.",invalidStorageOptions:"options.storage: LocalStorage instance or equivalent required. For NodeJS, use `node-localstorage` NPM module.",validationError:"Validation failed. Action: "}),P.forceUpdateCache=e=>{ze.next(e);};var me=P,re=me;var ke=(r,e)=>br.includes(e)||r[e]!==void 0,br=["delayOptions","name","onChange","onError","parse","spaces","storage","stringify","validate"];function yr(r,e){let t=new re(r==null?void 0:r.name,r),o=b(e)?e(t):e;return g(o,false)?new Proxy(t,{get:(n,i,s)=>Reflect.get(ke(n,i)?n:o,i,s),set:(n,i,s,a)=>Reflect.set(ke(n,i)?n:o,i,s,a)}):t}var We=yr;function qt(r,e){r={...(r==null?void 0:r.name)&&{parse:n=>D(JSON.parse(n!=null?n:"{}")),stringify(n){return JSON.stringify(this.toObject(n))}},...r,initialValue:g(r==null?void 0:r.initialValue,true)?D(r.initialValue):r==null?void 0:r.initialValue};let t=We(r,e);t.type="object";let o=t.setAll.bind(t);return t.setAll=(n,i)=>(n&&!S(n)&&(n=D(n)),o(n,i)),t.toMap=n=>n?D(n):t.getAll(),t}var Yt=re;exports.OPTIONAL_STORE_PROPS=br;exports.Store=me;exports.Store_OnErrorType=mr;exports.createObjectStore=qt;exports.createStore=yr;exports.default=Yt;exports.forceUpdateCache$=ze;exports.objToMap=D;Object.defineProperty(exports,'__esModule',{value:true});return exports;})({});//# sourceMappingURL=index.min.js.map
4
4
  //# sourceMappingURL=index.min.js.map