@electric-sql/pglite-react
Advanced tools
Comparing version 0.2.13 to 0.2.14
import React from 'react'; | ||
import { PGliteWithLive, LiveQuery } from '@electric-sql/pglite/live'; | ||
import { Results } from '@electric-sql/pglite'; | ||
import { PGliteWithLive, LiveQueryResults, LiveQuery } from '@electric-sql/pglite/live'; | ||
@@ -24,18 +23,18 @@ interface Props<T extends PGliteWithLive> { | ||
[key: string]: unknown; | ||
}>(query: string, params?: unknown[] | null): Results<T> | undefined; | ||
}>(query: string, params?: unknown[] | null): LiveQueryResults<T> | undefined; | ||
declare function useLiveQuery<T = { | ||
[key: string]: unknown; | ||
}>(liveQuery: LiveQuery<T>): Results<T>; | ||
}>(liveQuery: LiveQuery<T>): LiveQueryResults<T>; | ||
declare function useLiveQuery<T = { | ||
[key: string]: unknown; | ||
}>(liveQueryPromise: Promise<LiveQuery<T>>): Results<T> | undefined; | ||
}>(liveQueryPromise: Promise<LiveQuery<T>>): LiveQueryResults<T> | undefined; | ||
declare namespace useLiveQuery { | ||
var sql: <T = { | ||
[key: string]: unknown; | ||
}>(strings: TemplateStringsArray, ...values: any[]) => Results<T> | undefined; | ||
}>(strings: TemplateStringsArray, ...values: any[]) => LiveQueryResults<T> | undefined; | ||
} | ||
declare function useLiveIncrementalQuery<T = { | ||
[key: string]: unknown; | ||
}>(query: string, params: unknown[] | undefined | null, key: string): Results<T> | undefined; | ||
}>(query: string, params: unknown[] | undefined | null, key: string): LiveQueryResults<T> | undefined; | ||
export { PGliteProvider, makePGliteProvider, useLiveIncrementalQuery, useLiveQuery, usePGlite }; |
@@ -1,2 +0,2 @@ | ||
import{createContext as a,useContext as y}from"react";import{jsx as L}from"react/jsx-runtime";function G(){let e=a(void 0);return{usePGlite:n=>{let t=y(e);if(n!==void 0)return n;if(!t)throw new Error("No PGlite instance found, use PGliteProvider to provide one");return t},PGliteProvider:({children:n,db:t})=>L(e.Provider,{value:t,children:n})}}var{PGliteProvider:b,usePGlite:v}=G();import{useEffect as R,useState as g,useRef as p}from"react";import{query as w}from"@electric-sql/pglite/template";function k(e,n){if(!e&&!n)return!0;if(e?.length!==n?.length)return!1;for(let t=0;t<e.length;t++)if(!Object.is(e[t],n[t]))return!1;return!0}function P(e,n,t){let s=v(),f=p(n),T=p(),r;typeof e!="string"&&!(e instanceof Promise)&&(r=e);let[d,c]=g(r?.initialResults),l=f.current;return k(f.current,n)||(f.current=n,l=n),R(()=>{let o=!1,u=i=>{o||c(i)};if(typeof e=="string"){let i=t!==void 0?s.live.incrementalQuery(e,l,t,u):s.live.query(e,l,u);return()=>{o=!0,i.then(({unsubscribe:m})=>m())}}else{if(e instanceof Promise)return e.then(i=>{o||(T.current=i,c(i.initialResults),i.subscribe(u))}),()=>{o=!0,T.current?.unsubscribe(u)};if(r)return c(r.initialResults),r.subscribe(u),()=>{o=!0,r.unsubscribe(u)};throw new Error("Should never happen")}},[s,t,e,l,r]),d&&{rows:d.rows,fields:d.fields}}function Q(e,n){return P(e,n)}Q.sql=function(e,...n){let{query:t,params:s}=w(e,...n);return P(t,s)};function I(e,n,t){return P(e,n,t)}export{b as PGliteProvider,G as makePGliteProvider,I as useLiveIncrementalQuery,Q as useLiveQuery,v as usePGlite}; | ||
import{createContext as p,useContext as m}from"react";import{jsx as G}from"react/jsx-runtime";function Q(){let e=p(void 0);return{usePGlite:t=>{let n=m(e);if(t!==void 0)return t;if(!n)throw new Error("No PGlite instance found, use PGliteProvider to provide one");return n},PGliteProvider:({children:t,db:n})=>G(e.Provider,{value:n,children:t})}}var{PGliteProvider:W,usePGlite:y}=Q();import{query as R}from"@electric-sql/pglite/template";import{useEffect as g,useRef as a,useState as w}from"react";function k(e,t){if(!e&&!t)return!0;if(e?.length!==t?.length)return!1;for(let n=0;n<e.length;n++)if(!Object.is(e[n],t[n]))return!1;return!0}function P(e,t,n){let o=y(),v=a(t),f=a(),i,T=!1;typeof e!="string"&&!(e instanceof Promise)&&(i=e,T=f.current!==i,f.current=i);let[u,c]=w(i?.initialResults),d=v.current;return k(v.current,t)||(v.current=t,d=t),g(()=>{let l=!1,s=r=>{l||c(r)};if(typeof e=="string"){let r=n!==void 0?o.live.incrementalQuery(e,d,n,s):o.live.query(e,d,s);return()=>{l=!0,r.then(({unsubscribe:L})=>L())}}else{if(e instanceof Promise)return e.then(r=>{l||(f.current=r,c(r.initialResults),r.subscribe(s))}),()=>{l=!0,f.current?.unsubscribe(s)};if(i)return c(i.initialResults),i.subscribe(s),()=>{l=!0,i.unsubscribe(s)};throw new Error("Should never happen")}},[o,n,e,d,i]),T&&i?i.initialResults:u&&{rows:u.rows,fields:u.fields,totalCount:u.totalCount,offset:u.offset,limit:u.limit}}function h(e,t){return P(e,t)}h.sql=function(e,...t){let{query:n,params:o}=R(e,...t);return P(n,o)};function N(e,t,n){return P(e,t,n)}export{W as PGliteProvider,Q as makePGliteProvider,N as useLiveIncrementalQuery,h as useLiveQuery,y as usePGlite}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@electric-sql/pglite-react", | ||
"version": "0.2.13", | ||
"version": "0.2.14", | ||
"description": "Hooks for using PGlite", | ||
@@ -51,7 +51,7 @@ "type": "module", | ||
"vitest": "^2.1.2", | ||
"@electric-sql/pglite": "0.2.13" | ||
"@electric-sql/pglite": "0.2.14" | ||
}, | ||
"peerDependencies": { | ||
"react": "^18.0.0", | ||
"@electric-sql/pglite": "^0.2.13" | ||
"@electric-sql/pglite": "^0.2.14" | ||
}, | ||
@@ -58,0 +58,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
37109
52