@storesjs/stores 0.8.7 → 0.9.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/config.d.ts +37 -7
- package/dist/createQueryStore.d.ts +3 -19
- package/dist/createStoreWithEqualityFn.d.ts +5 -0
- package/dist/createVirtualStore.d.ts +4 -3
- package/dist/derivedStore/cascadeScheduler.d.ts +8 -0
- package/dist/derivedStore/deriveProxy.d.ts +6 -16
- package/dist/derivedStore/pathFinder.d.ts +27 -0
- package/dist/errors.d.ts +14 -0
- package/dist/hooks/useSyncExternalStoreWithSelector.d.ts +5 -0
- package/dist/index.d.ts +3 -1
- package/dist/logger.d.ts +0 -5
- package/dist/native/index.js +1 -1
- package/dist/native/index.mjs +1 -1
- package/dist/plugins/chrome/chromeExtensionSyncEngine.d.ts +3 -1
- package/dist/queryStore/queryStoreDefaults.d.ts +8 -0
- package/dist/queryStore/signalTypes.d.ts +13 -0
- package/dist/queryStore/types.d.ts +35 -30
- package/dist/signal.d.ts +2 -11
- package/dist/sync/syncEnhancer.d.ts +4 -0
- package/dist/sync/types.d.ts +53 -128
- package/dist/types/functions.d.ts +19 -2
- package/dist/types/objects.d.ts +10 -3
- package/dist/types.d.ts +26 -27
- package/dist/utils/core.d.ts +23 -4
- package/dist/utils/createStoreActions.d.ts +3 -3
- package/dist/utils/persistUtils.d.ts +2 -2
- package/dist/utils/storeUtils.d.ts +1 -1
- package/dist/utils/time.d.ts +0 -3
- package/dist/web/chrome.js +1 -1
- package/dist/web/chrome.mjs +1 -1
- package/dist/web/chunk-3U5A7HQV.mjs +1 -0
- package/dist/web/index.js +1 -1
- package/dist/web/index.mjs +1 -1
- package/package.json +10 -6
- package/dist/sync/transport.d.ts +0 -113
- package/dist/web/chunk-MMPMCVRC.mjs +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e="undefined"!=typeof window&&"undefined"!=typeof document,t=!1,r="development"===process.env.NODE_ENV,o="test"===process.env.NODE_ENV,n=e=>e();function s(){return"undefined"!=typeof window?window.localStorage:null}var i=class extends Error{constructor(e,t){super(e),this.name="StoresError",this.cause=c(t)}},a={debug:(e,t)=>{r&&console.debug(e,t)},error:(e,t)=>{r&&!o&&console.error(e,t)},info:(e,t)=>{r&&console.info(e,t)},warn:(e,t)=>{r&&console.warn(e,t)}};function c(e){return e instanceof Error?e:new Error(String(e))}var l="stores/core/sync-channel",u=`${l}:storage:`;function d(){try{return"undefined"!=typeof window?window.localStorage:null}catch{return null}}var h,y,g,f=class{constructor(e){this.broadcast=e.broadcast,this.origin=e.origin,this.storeKey=e.storeKey,this.teardown=e.teardown}destroy(){this.teardown()}publish(e){const t=Object.create(null);for(const r of Object.entries(e.values))t[r[0]]=r[1];const r={origin:this.origin,replace:e.replace,sessionId:e.sessionId,storeKey:this.storeKey,timestamp:e.timestamp,values:t};this.broadcast(r)}},p=class{constructor(){this.listeners=new Map,this.origin="undefined"!=typeof crypto&&"randomUUID"in crypto?crypto.randomUUID():`${Math.random().toString(36).slice(2)}:${Date.now().toString(36)}`,this.onChannelMessage=e=>{e.data&&this.dispatch(e.data)},this.onStorageEvent=e=>{if(e.key&&e.newValue&&e.key.startsWith(u))try{const t=JSON.parse(e.newValue);this.dispatch(t)}catch(e){a.error(new i("[sync] Failed to parse storage event payload"),{error:e})}},this.channel="undefined"==typeof BroadcastChannel?null:new BroadcastChannel(l),this.storage=d(),this.channel&&this.channel.addEventListener("message",this.onChannelMessage),e&&window.addEventListener("storage",this.onStorageEvent)}get sessionId(){return this.origin}register(e){const t=t=>{if(t.origin===this.origin||t.storeKey!==e.key)return;const r=Object.create(null);for(const o of e.fields)Object.prototype.hasOwnProperty.call(t.values,o)&&(r[o]=t.values[o]);Object.keys(r).length&&e.apply({replace:t.replace,sessionId:t.sessionId,timestamp:t.timestamp,values:r})};let r=this.listeners.get(e.key);return r||(r=new Set,this.listeners.set(e.key,r)),r.add(t),new f({broadcast:e=>this.broadcast(e),origin:this.origin,storeKey:e.key,teardown:()=>this.removeListener(e.key,t)})}broadcast(e){try{this.channel&&this.channel.postMessage(e),this.writeToStorage(e)}catch(e){a.error(new i("[sync] Failed to broadcast update"),{error:e})}}dispatch(e){if(!e.storeKey)return;const t=this.listeners.get(e.storeKey);if(t&&t.size)for(const r of t)r(e)}removeListener(e,t){const r=this.listeners.get(e);r&&(r.delete(t),r.size||this.listeners.delete(e))}writeToStorage(e){if(this.storage||(this.storage=d()),!this.storage)return;const t=`${u}${e.storeKey}`;try{this.storage.setItem(t,JSON.stringify(e))}catch(e){a.error(new i("[sync] Failed to write broadcast payload to storage"),{error:e})}}},w=class{destroy(){}publish(){}},m=class{constructor(){this.sessionId="noop"}register(e){return new w}},v="stores:",b=!1;function S(e){var t;r&&function(){if(b)throw new Error("[stores]: configureStores() called after first store creation. Call it earlier before creating any stores.")}(),e.logger&&(t=e.logger,a=t),g??(g=I(e))}function E(){return g??(g=I(void 0))}function O(){b=!0}function I(t){return{storage:t?.storage??(r=t?.storageKeyPrefix??v,{clearAll(){try{const e=s();if(!e)return;const t=[];for(let o=0;o<e.length;o++){const n=e.key(o);n?.startsWith(r)&&t.push(n)}for(const r of t)e.removeItem(r)}catch(e){console.error("Error clearing localStorage:",e)}},contains(e){const t=s();return null!==t?.getItem(`${r}${e}`)},delete(e){try{const t=s();t?.removeItem(`${r}${e}`)}catch(e){console.error("Error deleting from localStorage:",e)}},getAllKeys(){try{const e=s();return e?Array.from(e.keys()):[]}catch(e){return console.error("Error getting keys from localStorage:",e),[]}},get(e){try{const t=s();return t?t.getItem(`${r}${e}`)??void 0:void 0}catch(e){return void console.error("Error reading from localStorage:",e)}},set(e,t){try{const o=s();o?.setItem(`${r}${e}`,t)}catch(e){console.error("Error writing to localStorage:",e)}}}),syncEngine:t?.syncEngine??(e?(h||(h=new p),h):(y||(y=new m),y))};var r}function _(e,t){return t instanceof Map?{__type:"Map",entries:Array.from(t.entries())}:t instanceof Set?{__type:"Set",values:Array.from(t)}:t}function $(e,t){return function(e){return"object"==typeof e&&null!==e&&"__type"in e&&"Map"===e.__type}(t)?new Map(t.entries):function(e){return"object"==typeof e&&null!==e&&"__type"in e&&"Set"===e.__type}(t)?new Set(t.values):t}function j(e){return!!e&&"object"==typeof e&&"then"in e&&"function"==typeof e.then}var k=Object.prototype.hasOwnProperty;function K(e,t){return k.call(e,t)}function M(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}export{v as DEFAULT_STORAGE_KEY_PREFIX,e as IS_BROWSER,r as IS_DEV,t as IS_IOS,o as IS_TEST,i as StoresError,S as configureStores,c as ensureError,E as getStoresConfig,K as hasOwn,M as isPlainObject,j as isPromiseLike,a as logger,O as markStoreCreated,_ as replacer,$ as reviver,n as unstable_batchedUpdates};
|