qortex-core 0.3.0-beta.7 → 0.3.1
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 +3 -4
- package/index.d.ts +8 -8
- package/package.json +1 -1
- package/persister.d.ts +3 -0
- package/persister.js +1 -1
- package/persister.mjs +1 -1
package/README.md
CHANGED
|
@@ -13,11 +13,10 @@
|
|
|
13
13
|
|
|
14
14
|
- 🔐 **App core data** - Authentication, user profiles accessible from anywhere
|
|
15
15
|
- 🎯 **Cross-framework** - Share data between React, Vue, vanilla JS, Node.js
|
|
16
|
-
- 🔄 **Background services** - WebSocket updates, timers, external events
|
|
17
16
|
- ⚡ **Real-time apps** - Push changes from anywhere, see them everywhere instantly
|
|
18
17
|
|
|
19
18
|
```bash
|
|
20
|
-
|
|
19
|
+
npm install qortex-core
|
|
21
20
|
```
|
|
22
21
|
|
|
23
22
|
## 📚 Documentation
|
|
@@ -28,7 +27,7 @@ pnpm add qortex-core
|
|
|
28
27
|
|
|
29
28
|
## 📄 License
|
|
30
29
|
|
|
31
|
-
|
|
30
|
+
LGPL-3.0 License - see [LICENSE](../../LICENSE) file for details.
|
|
32
31
|
|
|
33
32
|
## 🎯 Support
|
|
34
33
|
|
|
@@ -45,4 +44,4 @@ Need help? Have questions? Want to chat about data fetching strategies?
|
|
|
45
44
|
<div align="center">
|
|
46
45
|
<p>Made with ❤️ by <a href="https://darshannaik.com">Darshan</a></p>
|
|
47
46
|
<p>⭐ Star this repo if you found it helpful!</p>
|
|
48
|
-
</div>
|
|
47
|
+
</div>
|
package/index.d.ts
CHANGED
|
@@ -179,14 +179,14 @@ declare const subscribeQuery: {
|
|
|
179
179
|
* Sets default configuration that applies to all queries
|
|
180
180
|
*
|
|
181
181
|
* @param config - Default configuration object
|
|
182
|
-
* @param config.enabled - Default enabled state for all queries
|
|
183
|
-
* @param config.staleTime - Default stale time in milliseconds
|
|
184
|
-
* @param config.refetchOnSubscribe - Default refetch behavior on subscription
|
|
185
|
-
* @param config.equalityStrategy - Default equality comparison strategy
|
|
186
|
-
* @param config.equalityFn - Default equality function
|
|
187
|
-
* @param config.usePreviousDataOnError - Default behavior for previous data on error
|
|
188
|
-
* @param config.usePlaceholderOnError - Default behavior for placeholder data on error
|
|
189
|
-
* @param config.throttleTime - Time in ms to throttle fetch requests
|
|
182
|
+
* @param config.enabled - Default enabled state for all queries. Default: `true`
|
|
183
|
+
* @param config.staleTime - Default stale time in milliseconds. Default: `0` (data becomes stale immediately after fetch)
|
|
184
|
+
* @param config.refetchOnSubscribe - Default refetch behavior on subscription. Default: `"stale"`
|
|
185
|
+
* @param config.equalityStrategy - Default equality comparison strategy. Default: `"shallow"`
|
|
186
|
+
* @param config.equalityFn - Default equality function. Default: `Object.is`
|
|
187
|
+
* @param config.usePreviousDataOnError - Default behavior for previous data on error. Default: `false`
|
|
188
|
+
* @param config.usePlaceholderOnError - Default behavior for placeholder data on error. Default: `false`
|
|
189
|
+
* @param config.throttleTime - Time in ms to throttle fetch requests. Default: `50`
|
|
190
190
|
* @param config.persister - Persister instance for data persistence
|
|
191
191
|
*
|
|
192
192
|
* These defaults will be merged with individual query options. Useful for setting global behavior
|
package/package.json
CHANGED
package/persister.d.ts
CHANGED
|
@@ -12,6 +12,9 @@ export { e as Persister } from './types-61b54557.js';
|
|
|
12
12
|
* - `'local'`: Uses localStorage for persistent data across browser sessions
|
|
13
13
|
* - `'session'`: Uses sessionStorage for data that persists only during the current session
|
|
14
14
|
* @param {PersisterConfig} [config] - Optional configuration for the persister
|
|
15
|
+
* - `burstKey`: Default `"package version"`
|
|
16
|
+
* - `prefix`: Default `"qortex"`
|
|
17
|
+
* - `debounceTime`: Default `100` (ms)
|
|
15
18
|
* @returns {Persister | undefined} A persister instance, or undefined if storage is not available
|
|
16
19
|
*
|
|
17
20
|
* @example
|
package/persister.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
function g(e){return typeof e=="string"&&["idle","fetching","success","error"].includes(e)}function h(e){return typeof e=="string"&&["shallow","deep"].includes(e)}function b(e){return e===!1||typeof e=="string"&&["always","stale"].includes(e)}function P(e){return !(!e||typeof e!="object"||!g(e.status)||typeof e.staleTime!="number"||e.staleTime<0||typeof e.isInvalidated!="boolean"||!h(e.equalityStrategy)||!b(e.refetchOnSubscribe))}function l(e){if(!e||typeof e!="object"||!e.queries||typeof e.queries!="object")return !1;for(let[t,r]of Object.entries(e.queries))if(typeof t!="string"||!P(r))return !1;return !(typeof e.burstKey!="string"||typeof e.timestamp!="number"||e.timestamp<0)}function u(e){let{fetcher:t,equalityFn:r,fetchPromise:s,refetch:i,fromPersisterCache:o,...n}=e;return n}function f(e,t){return {...t??{},...e,fromPersisterCache:!t}}function y(e){try{let t=JSON.parse(e);return l(t)?t:null}catch{return null}}var c=()=>{console.warn("[Qortex] No storage found, persister will not be able to persist data");},p=()=>{console.warn("[Qortex] Persister is being set after queries have been used. This may cause data inconsistency. It is recommended to set the persister before any query usage.");};var a=class{constructor(t,r){this.syncTimeout=null;this.debounceTime=100;this.burstKey="0.3.
|
|
3
|
+
function g(e){return typeof e=="string"&&["idle","fetching","success","error"].includes(e)}function h(e){return typeof e=="string"&&["shallow","deep"].includes(e)}function b(e){return e===!1||typeof e=="string"&&["always","stale"].includes(e)}function P(e){return !(!e||typeof e!="object"||!g(e.status)||typeof e.staleTime!="number"||e.staleTime<0||typeof e.isInvalidated!="boolean"||!h(e.equalityStrategy)||!b(e.refetchOnSubscribe))}function l(e){if(!e||typeof e!="object"||!e.queries||typeof e.queries!="object")return !1;for(let[t,r]of Object.entries(e.queries))if(typeof t!="string"||!P(r))return !1;return !(typeof e.burstKey!="string"||typeof e.timestamp!="number"||e.timestamp<0)}function u(e){let{fetcher:t,equalityFn:r,fetchPromise:s,refetch:i,fromPersisterCache:o,...n}=e;return n}function f(e,t){return {...t??{},...e,fromPersisterCache:!t}}function y(e){try{let t=JSON.parse(e);return l(t)?t:null}catch{return null}}var c=()=>{console.warn("[Qortex] No storage found, persister will not be able to persist data");},p=()=>{console.warn("[Qortex] Persister is being set after queries have been used. This may cause data inconsistency. It is recommended to set the persister before any query usage.");};var a=class{constructor(t,r){this.syncTimeout=null;this.debounceTime=100;this.burstKey="0.3.1";this.storageKey="qortex";this.storage=t,this.burstKey=r?.burstKey??this.burstKey,this.storageKey=r?.prefix??this.storageKey,this.debounceTime=r?.debounceTime??this.debounceTime;}save(t){try{let r={queries:{},burstKey:this.burstKey,timestamp:Date.now()};for(let[i,o]of Object.entries(t))r.queries[i]=o;let s=JSON.stringify(r);this.storage.setItem(this.storageKey,s);}catch(r){console.warn("[Qortex] Failed to persist state:",r);}}load(t,r){r&&p();try{let s=this.storage.getItem(this.storageKey);if(!s)return;let i=y(s);if(!i){console.warn("[Qortex] Invalid persisted state format, clearing cache"),this.clear();return}if(i.burstKey!==this.burstKey){console.warn("[Qortex] Burst key mismatch, clearing cache"),this.clear();return}for(let[o,n]of Object.entries(i.queries)){let S=n,m=t.get(o),d=f(S,m);t.set(o,d);}}catch(s){console.warn("[Qortex] Failed to load persisted state:",s),this.clear();}}clear(){try{this.storage.removeItem(this.storageKey);}catch(t){console.warn("[Qortex] Failed to clear persisted data:",t);}}sync(t){this.syncTimeout&&clearTimeout(this.syncTimeout),this.syncTimeout=setTimeout(()=>{let r={};for(let[s,i]of t.entries())r[s]=u(i);this.save(r);},this.debounceTime);}};var Q=e=>{switch(e){case"local":if(typeof localStorage<"u")return window.localStorage;break;case"session":if(typeof sessionStorage<"u")return window.sessionStorage;break;default:throw new Error(`Invalid storage type: ${e}`)}},w=(e,t)=>{let r=Q(e);if(!r){c();return}return new a(r,t)};
|
|
4
4
|
|
|
5
5
|
exports.createPersister = w;
|
package/persister.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
function g(e){return typeof e=="string"&&["idle","fetching","success","error"].includes(e)}function h(e){return typeof e=="string"&&["shallow","deep"].includes(e)}function b(e){return e===!1||typeof e=="string"&&["always","stale"].includes(e)}function P(e){return !(!e||typeof e!="object"||!g(e.status)||typeof e.staleTime!="number"||e.staleTime<0||typeof e.isInvalidated!="boolean"||!h(e.equalityStrategy)||!b(e.refetchOnSubscribe))}function l(e){if(!e||typeof e!="object"||!e.queries||typeof e.queries!="object")return !1;for(let[t,r]of Object.entries(e.queries))if(typeof t!="string"||!P(r))return !1;return !(typeof e.burstKey!="string"||typeof e.timestamp!="number"||e.timestamp<0)}function u(e){let{fetcher:t,equalityFn:r,fetchPromise:s,refetch:i,fromPersisterCache:o,...n}=e;return n}function f(e,t){return {...t??{},...e,fromPersisterCache:!t}}function y(e){try{let t=JSON.parse(e);return l(t)?t:null}catch{return null}}var c=()=>{console.warn("[Qortex] No storage found, persister will not be able to persist data");},p=()=>{console.warn("[Qortex] Persister is being set after queries have been used. This may cause data inconsistency. It is recommended to set the persister before any query usage.");};var a=class{constructor(t,r){this.syncTimeout=null;this.debounceTime=100;this.burstKey="0.3.
|
|
1
|
+
function g(e){return typeof e=="string"&&["idle","fetching","success","error"].includes(e)}function h(e){return typeof e=="string"&&["shallow","deep"].includes(e)}function b(e){return e===!1||typeof e=="string"&&["always","stale"].includes(e)}function P(e){return !(!e||typeof e!="object"||!g(e.status)||typeof e.staleTime!="number"||e.staleTime<0||typeof e.isInvalidated!="boolean"||!h(e.equalityStrategy)||!b(e.refetchOnSubscribe))}function l(e){if(!e||typeof e!="object"||!e.queries||typeof e.queries!="object")return !1;for(let[t,r]of Object.entries(e.queries))if(typeof t!="string"||!P(r))return !1;return !(typeof e.burstKey!="string"||typeof e.timestamp!="number"||e.timestamp<0)}function u(e){let{fetcher:t,equalityFn:r,fetchPromise:s,refetch:i,fromPersisterCache:o,...n}=e;return n}function f(e,t){return {...t??{},...e,fromPersisterCache:!t}}function y(e){try{let t=JSON.parse(e);return l(t)?t:null}catch{return null}}var c=()=>{console.warn("[Qortex] No storage found, persister will not be able to persist data");},p=()=>{console.warn("[Qortex] Persister is being set after queries have been used. This may cause data inconsistency. It is recommended to set the persister before any query usage.");};var a=class{constructor(t,r){this.syncTimeout=null;this.debounceTime=100;this.burstKey="0.3.1";this.storageKey="qortex";this.storage=t,this.burstKey=r?.burstKey??this.burstKey,this.storageKey=r?.prefix??this.storageKey,this.debounceTime=r?.debounceTime??this.debounceTime;}save(t){try{let r={queries:{},burstKey:this.burstKey,timestamp:Date.now()};for(let[i,o]of Object.entries(t))r.queries[i]=o;let s=JSON.stringify(r);this.storage.setItem(this.storageKey,s);}catch(r){console.warn("[Qortex] Failed to persist state:",r);}}load(t,r){r&&p();try{let s=this.storage.getItem(this.storageKey);if(!s)return;let i=y(s);if(!i){console.warn("[Qortex] Invalid persisted state format, clearing cache"),this.clear();return}if(i.burstKey!==this.burstKey){console.warn("[Qortex] Burst key mismatch, clearing cache"),this.clear();return}for(let[o,n]of Object.entries(i.queries)){let S=n,m=t.get(o),d=f(S,m);t.set(o,d);}}catch(s){console.warn("[Qortex] Failed to load persisted state:",s),this.clear();}}clear(){try{this.storage.removeItem(this.storageKey);}catch(t){console.warn("[Qortex] Failed to clear persisted data:",t);}}sync(t){this.syncTimeout&&clearTimeout(this.syncTimeout),this.syncTimeout=setTimeout(()=>{let r={};for(let[s,i]of t.entries())r[s]=u(i);this.save(r);},this.debounceTime);}};var Q=e=>{switch(e){case"local":if(typeof localStorage<"u")return window.localStorage;break;case"session":if(typeof sessionStorage<"u")return window.sessionStorage;break;default:throw new Error(`Invalid storage type: ${e}`)}},w=(e,t)=>{let r=Q(e);if(!r){c();return}return new a(r,t)};
|
|
2
2
|
|
|
3
3
|
export { w as createPersister };
|