Socket
Socket
Sign inDemoInstall

sswr

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sswr - npm Package Compare versions

Comparing version 1.2.1 to 1.3.0

2

dist/esm/index.js

@@ -1,1 +0,1 @@

import{SWR as W}from"swrev";import{onDestroy as v,onMount as f}from"svelte";import{writable as c}from"svelte/store";var l=class extends W{useSvelte(t,r){let e,s=c(void 0,()=>()=>e?.()),d=c(void 0,()=>()=>e?.());typeof window!="undefined"&&(f(()=>{s.set(this.get(this.resolveKey(t)));let a=o=>s.set(o),i=o=>d.set(o);e=this.use(t,a,i,{loadInitialCache:!1,...r}).unsubscribe}),v(()=>e?.()));let p=(a,i)=>this.mutate(this.resolveKey(t),a,i),S=a=>this.revalidate(this.resolveKey(t),a),D=a=>this.clear(this.resolveKey(t),a);return{data:s,error:d,mutate:p,revalidate:S,clear:D}}},R=u=>{let t=new l(u);return{useSWR:(r,e)=>t.useSvelte(r,e),mutate:(r,e,s)=>t.mutate(r,e,s),revalidate:(r,e)=>t.revalidate(r,e),clear:(r,e)=>t.clear(r,e)}},n=R(),h=n.useSWR,O=n.mutate,m=n.revalidate,y=n.clear;export{l as SSWR,y as clear,R as createSWR,O as mutate,m as revalidate,h as useSWR};
import{SWR as S}from"swrev";import{onDestroy as y,onMount as f}from"svelte";import{writable as c}from"svelte/store";var d=class extends S{useSWR(t,a){let s,i=c(void 0,()=>()=>s?.()),D=c(void 0,()=>()=>s?.());f(()=>{i.set(this.get(this.resolveKey(t)));let n=u=>i.set(u),o=u=>D.set(u);s=this.use(t,n,o,{loadInitialCache:!1,...a}).unsubscribe}),y(()=>s?.());let R=(n,o)=>this.mutate(this.resolveKey(t),n,o),W=n=>this.revalidate(this.resolveKey(t),n),p=n=>this.clear(this.resolveKey(t),n);return{data:i,error:D,mutate:R,revalidate:W,clear:p}}},l=e=>new d(e),r=l(),v=e=>(r=l(e),r),E=(e,t)=>r.subscribe(e,t),K=(e,t)=>r.subscribeErrors(e,t),O=e=>r.get(e),x=e=>r.getOrWait(e),b=(e,t,a,s)=>r.use(e,t,a,s),h=(e,t)=>r.useSWR(e,t),P=(e,t,a)=>r.mutate(e,t,a),m=(e,t)=>r.revalidate(e,t),g=(e,t)=>r.clear(e,t);export{d as SSWR,g as clear,v as createDefaultSWR,l as createSWR,O as get,x as getOrWait,P as mutate,m as revalidate,E as subscribe,K as subscribeErrors,r as swr,b as use,h as useSWR};

@@ -1,1 +0,1 @@

(()=>{var h=Object.create,d=Object.defineProperty,O=Object.getPrototypeOf,m=Object.prototype.hasOwnProperty,y=Object.getOwnPropertyNames,K=Object.getOwnPropertyDescriptor,E=t=>d(t,"__esModule",{value:!0}),P=(t,r,a)=>{if(E(t),r&&typeof r=="object"||typeof r=="function")for(let e of y(r))!m.call(t,e)&&e!=="default"&&d(t,e,{get:()=>r[e],enumerable:!(a=K(r,e))||a.enumerable});return t},c=t=>t&&t.__esModule?t:P(d(t!=null?h(O(t)):{},"default",{value:t,enumerable:!0}),t),S=c(require("swrev")),i=c(require("svelte")),R=c(require("svelte/store")),D=class extends S.SWR{useSvelte(r,a){let e,n=R.writable(void 0,()=>()=>e?.()),p=R.writable(void 0,()=>()=>e?.());typeof window!="undefined"&&(i.onMount(()=>{n.set(this.get(this.resolveKey(r)));let s=u=>n.set(u),l=u=>p.set(u);e=this.use(r,s,l,{loadInitialCache:!1,...a}).unsubscribe}),i.onDestroy(()=>e?.()));let W=(s,l)=>this.mutate(this.resolveKey(r),s,l),v=s=>this.revalidate(this.resolveKey(r),s),f=s=>this.clear(this.resolveKey(r),s);return{data:n,error:p,mutate:W,revalidate:v,clear:f}}},w=t=>{let r=new D(t);return{useSWR:(a,e)=>r.useSvelte(a,e),mutate:(a,e,n)=>r.mutate(a,e,n),revalidate:(a,e)=>r.revalidate(a,e),clear:(a,e)=>r.clear(a,e)}},o=w(),j=o.useSWR,q=o.mutate,z=o.revalidate,A=o.clear;})();
(()=>{var E=Object.create,l=Object.defineProperty,K=Object.getPrototypeOf,O=Object.prototype.hasOwnProperty,x=Object.getOwnPropertyNames,b=Object.getOwnPropertyDescriptor,h=e=>l(e,"__esModule",{value:!0}),P=(e,t,s)=>{if(h(e),t&&typeof t=="object"||typeof t=="function")for(let r of x(t))!O.call(e,r)&&r!=="default"&&l(e,r,{get:()=>t[r],enumerable:!(s=b(t,r))||s.enumerable});return e},D=e=>e&&e.__esModule?e:P(l(e!=null?E(K(e)):{},"default",{value:e,enumerable:!0}),e),W=D(require("swrev")),i=D(require("svelte")),c=D(require("svelte/store")),p=class extends W.SWR{useSWR(t,s){let r,o=c.writable(void 0,()=>()=>r?.()),R=c.writable(void 0,()=>()=>r?.());i.onMount(()=>{o.set(this.get(this.resolveKey(t)));let a=d=>o.set(d),u=d=>R.set(d);r=this.use(t,a,u,{loadInitialCache:!1,...s}).unsubscribe}),i.onDestroy(()=>r?.());let y=(a,u)=>this.mutate(this.resolveKey(t),a,u),f=a=>this.revalidate(this.resolveKey(t),a),v=a=>this.clear(this.resolveKey(t),a);return{data:o,error:R,mutate:y,revalidate:f,clear:v}}},S=e=>new p(e),n=S(),q=e=>(n=S(e),n),z=(e,t)=>n.subscribe(e,t),A=(e,t)=>n.subscribeErrors(e,t),B=e=>n.get(e),F=e=>n.getOrWait(e),G=(e,t,s,r)=>n.use(e,t,s,r),H=(e,t)=>n.useSWR(e,t),J=(e,t,s)=>n.mutate(e,t,s),L=(e,t)=>n.revalidate(e,t),N=(e,t)=>n.clear(e,t);})();

@@ -12,3 +12,3 @@ import { Writable } from 'svelte/store';

*/
useSvelte<D = any, E = Error>(key: SWRKey | undefined | (() => SWRKey | undefined), options?: Partial<SWROptions<D>>): {
useSWR<D = any, E = Error>(key: SWRKey | undefined | (() => SWRKey | undefined), options?: Partial<SWROptions<D>>): {
data: Writable<D | undefined>;

@@ -25,15 +25,51 @@ error: Writable<E | undefined>;

*/
declare const createSWR: <G = any>(options?: Partial<SWROptions<G>> | undefined) => {
useSWR: <D = G, E = Error>(key: SWRKey, options?: Partial<SWROptions<D>> | undefined) => {
data: Writable<D | undefined>;
error: Writable<E | undefined>;
mutate: (value: D, options: Partial<SWRMutateOptions<D>>) => void;
revalidate: (options: Partial<SWRRevalidateOptions<D>>) => void;
clear: (options: Partial<CacheClearOptions>) => void;
};
mutate: <D_1 = G>(key: SWRKey, value: D_1, options?: Partial<SWRMutateOptions<D_1>> | undefined) => void;
revalidate: <D_2 = G>(key: SWRKey, options?: Partial<SWRRevalidateOptions<D_2>> | undefined) => void;
clear: (keys?: string | string[] | undefined, options?: Partial<CacheClearOptions> | undefined) => void;
declare const createSWR: <D = any>(options?: Partial<SWROptions<D>> | undefined) => SSWR;
/**
* Default SWR instance. Can be replaced
* with the `createDefaultSWR` function.
*/
declare let swr: SSWR;
/**
* Creates and sets a default SWR instance given
* the options.
*/
declare const createDefaultSWR: <D = any>(options?: Partial<SWROptions<D>> | undefined) => SSWR;
/**
* Gets the data of the given key. Keep in mind
* this data will be stale and revalidate in the background
* unless specified otherwise.
*/
declare const subscribe: <D>(key: SWRKey | undefined, onData: (value: D) => any) => () => void;
/**
* Subscribes to errors on the given key.
*/
declare const subscribeErrors: <E>(key: SWRKey | undefined, onError: (error: E) => any) => () => void;
/**
* Gets the current cached data of the given key.
* This does not trigger any revalidation nor mutation
* of the data.
* - If the data has never been validated
* (there is no cache) it will return undefined.
* - If the item is pending to resolve (there is a request
* pending to resolve) it will return undefined.
*/
declare const get: <D = any>(key?: string | undefined) => D | undefined;
/**
* Gets an element from the cache. The difference
* with the get is that this method returns a promise
* that will resolve the the value. If there's no item
* in the cache, it will wait for it before resolving.
*/
declare const getOrWait: <D = any>(key: SWRKey) => Promise<D>;
/**
* Use a SWR value given the key and
* subscribe to future changes.
*/
declare const use: <D = any, E = Error>(key: SWRKey | undefined | (() => SWRKey | undefined), onData: (value: D) => void, onError: (error: E) => void, options?: Partial<SWROptions<D>> | undefined) => {
unsubscribe: () => void;
};
declare const useSWR: <D = any, E = Error>(key: SWRKey, options?: Partial<SWROptions<D>> | undefined) => {
/**
* Use the SWR with a vue application.
*/
declare const useSWR: <D = any, E = Error>(key: SWRKey | undefined | (() => SWRKey | undefined), options?: Partial<SWROptions<D>> | undefined) => {
data: Writable<D | undefined>;

@@ -45,6 +81,18 @@ error: Writable<E | undefined>;

};
/**
* Mutates the data of a given key with a new value.
* This is used to replace the cache contents of the
* given key manually.
*/
declare const mutate: <D = any>(key: SWRKey, value: D, options?: Partial<SWRMutateOptions<D>> | undefined) => void;
declare const revalidate: <D = any>(key: SWRKey, options?: Partial<SWRRevalidateOptions<D>> | undefined) => void;
/**
* Revalidates the key and mutates the cache if needed.
*/
declare const revalidate: <D>(key: SWRKey, options?: Partial<SWRRevalidateOptions<D>> | undefined) => void;
/**
* Clear the specified keys from the cache. If no keys
* are specified, it clears all the cache keys.
*/
declare const clear: (keys?: string | string[] | undefined, options?: Partial<CacheClearOptions> | undefined) => void;
export { SSWR, clear, createSWR, mutate, revalidate, useSWR };
export { SSWR, clear, createDefaultSWR, createSWR, get, getOrWait, mutate, revalidate, subscribe, subscribeErrors, swr, use, useSWR };

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _swrev = require('swrev');var _svelte = require('svelte');var _store = require('svelte/store');var l=class extends _swrev.SWR{useSvelte(t,r){let e,s=_store.writable.call(void 0, void 0,()=>()=>_optionalChain([e, 'optionalCall', _ => _()])),d=_store.writable.call(void 0, void 0,()=>()=>_optionalChain([e, 'optionalCall', _2 => _2()]));typeof window!="undefined"&&(_svelte.onMount.call(void 0, ()=>{s.set(this.get(this.resolveKey(t)));let a=o=>s.set(o),i=o=>d.set(o);e=this.use(t,a,i,{loadInitialCache:!1,...r}).unsubscribe}),_svelte.onDestroy.call(void 0, ()=>_optionalChain([e, 'optionalCall', _3 => _3()])));let p=(a,i)=>this.mutate(this.resolveKey(t),a,i),S=a=>this.revalidate(this.resolveKey(t),a),D=a=>this.clear(this.resolveKey(t),a);return{data:s,error:d,mutate:p,revalidate:S,clear:D}}},R= exports.createSWR =u=>{let t=new l(u);return{useSWR:(r,e)=>t.useSvelte(r,e),mutate:(r,e,s)=>t.mutate(r,e,s),revalidate:(r,e)=>t.revalidate(r,e),clear:(r,e)=>t.clear(r,e)}},n=R(),h= exports.useSWR =n.useSWR,O= exports.mutate =n.mutate,m= exports.revalidate =n.revalidate,y= exports.clear =n.clear;exports.SSWR = l; exports.clear = y; exports.createSWR = R; exports.mutate = O; exports.revalidate = m; exports.useSWR = h;
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _swrev = require('swrev');var _svelte = require('svelte');var _store = require('svelte/store');var d=class extends _swrev.SWR{useSWR(t,a){let s,i=_store.writable.call(void 0, void 0,()=>()=>_optionalChain([s, 'optionalCall', _ => _()])),D=_store.writable.call(void 0, void 0,()=>()=>_optionalChain([s, 'optionalCall', _2 => _2()]));_svelte.onMount.call(void 0, ()=>{i.set(this.get(this.resolveKey(t)));let n=u=>i.set(u),o=u=>D.set(u);s=this.use(t,n,o,{loadInitialCache:!1,...a}).unsubscribe}),_svelte.onDestroy.call(void 0, ()=>_optionalChain([s, 'optionalCall', _3 => _3()]));let R=(n,o)=>this.mutate(this.resolveKey(t),n,o),W=n=>this.revalidate(this.resolveKey(t),n),p=n=>this.clear(this.resolveKey(t),n);return{data:i,error:D,mutate:R,revalidate:W,clear:p}}},l= exports.createSWR =e=>new d(e),r= exports.swr =l(),v= exports.createDefaultSWR =e=>(r= exports.swr =l(e),r),E= exports.subscribe =(e,t)=>r.subscribe(e,t),K= exports.subscribeErrors =(e,t)=>r.subscribeErrors(e,t),O= exports.get =e=>r.get(e),x= exports.getOrWait =e=>r.getOrWait(e),b= exports.use =(e,t,a,s)=>r.use(e,t,a,s),h= exports.useSWR =(e,t)=>r.useSWR(e,t),P= exports.mutate =(e,t,a)=>r.mutate(e,t,a),m= exports.revalidate =(e,t)=>r.revalidate(e,t),g= exports.clear =(e,t)=>r.clear(e,t);exports.SSWR = d; exports.clear = g; exports.createDefaultSWR = v; exports.createSWR = l; exports.get = O; exports.getOrWait = x; exports.mutate = P; exports.revalidate = m; exports.subscribe = E; exports.subscribeErrors = K; exports.swr = r; exports.use = b; exports.useSWR = h;
{
"name": "sswr",
"version": "1.2.1",
"version": "1.3.0",
"description": "Svelte stale while revalidate (SWR) data fetching strategy",

@@ -5,0 +5,0 @@ "repository": "github.com/ConsoleTVs/sswr",

@@ -64,2 +64,18 @@ # SSWR (Svelte Stale While Revalidate)

### Note about usage with SvelteKit
Temporarily you need to add sswr to the Vite optimization exclusions in the `svelte.config.js` file:
```js
kit:
vite: {
optimizeDeps: {
exclude: ['sswr']
}
}
}
```
_This step will no longer be necessary soon: it's not sswr fault: they are solving a problem in Vite for SvelteKit (as explained here: https://github.com/sveltejs/kit/issues/2147#issuecomment-895909001)._
## Getting Started

@@ -66,0 +82,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc