@tuwaio/pulsar-react 1.0.0-fix-orbit-integration-alpha.5.7bdc032 → 1.0.0-fix-orbit-integration-alpha.6.76dee15

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/index.d.mts CHANGED
@@ -5,11 +5,11 @@ import { StoreApi } from 'zustand';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import { PersistOptions } from 'zustand/middleware';
7
7
 
8
- type PulsarSelector<TTransaction extends Transaction, TSelected> = (state: PulsarStore<TTransaction>) => TSelected;
9
- type PulsarStore<TTransaction extends Transaction> = ITxTrackingStore<TTransaction>;
10
- declare const PulsarStoreContext: react.Context<StoreApi<PulsarStore<Transaction>> | null>;
8
+ type PulsarStoreState<TTransaction extends Transaction> = ITxTrackingStore<TTransaction>;
9
+ type PulsarSelector<TTransaction extends Transaction, TSelected> = (state: PulsarStoreState<TTransaction>) => TSelected;
10
+ declare const PulsarStoreContext: react.Context<StoreApi<PulsarStoreState<Transaction>> | null>;
11
11
  declare function usePulsarStore<TTransaction extends Transaction, TRet>(selector: PulsarSelector<TTransaction, TRet>): TRet;
12
- declare function usePulsarStore<TRet>(selector: PulsarSelector<Transaction, TRet>): TRet;
12
+ declare function usePulsarStore<TSelected>(selector: PulsarSelector<Transaction, TSelected>): TSelected;
13
13
 
14
14
  /**
15
15
  * @file This file defines a React hook for initializing the transaction pool.
@@ -52,4 +52,4 @@ interface PulsarCoreProviderProps<T extends Transaction> extends PropsWithChildr
52
52
  }
53
53
  declare function PulsarCoreProvider<T extends Transaction>({ children, ...params }: PulsarCoreProviderProps<T>): react_jsx_runtime.JSX.Element;
54
54
 
55
- export { PulsarCoreProvider, type PulsarStore, PulsarStoreContext, useInitializeTransactionsPool, usePulsarStore };
55
+ export { PulsarCoreProvider, PulsarStoreContext, type PulsarStoreState, useInitializeTransactionsPool, usePulsarStore };
package/dist/index.d.ts CHANGED
@@ -5,11 +5,11 @@ import { StoreApi } from 'zustand';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  import { PersistOptions } from 'zustand/middleware';
7
7
 
8
- type PulsarSelector<TTransaction extends Transaction, TSelected> = (state: PulsarStore<TTransaction>) => TSelected;
9
- type PulsarStore<TTransaction extends Transaction> = ITxTrackingStore<TTransaction>;
10
- declare const PulsarStoreContext: react.Context<StoreApi<PulsarStore<Transaction>> | null>;
8
+ type PulsarStoreState<TTransaction extends Transaction> = ITxTrackingStore<TTransaction>;
9
+ type PulsarSelector<TTransaction extends Transaction, TSelected> = (state: PulsarStoreState<TTransaction>) => TSelected;
10
+ declare const PulsarStoreContext: react.Context<StoreApi<PulsarStoreState<Transaction>> | null>;
11
11
  declare function usePulsarStore<TTransaction extends Transaction, TRet>(selector: PulsarSelector<TTransaction, TRet>): TRet;
12
- declare function usePulsarStore<TRet>(selector: PulsarSelector<Transaction, TRet>): TRet;
12
+ declare function usePulsarStore<TSelected>(selector: PulsarSelector<Transaction, TSelected>): TSelected;
13
13
 
14
14
  /**
15
15
  * @file This file defines a React hook for initializing the transaction pool.
@@ -52,4 +52,4 @@ interface PulsarCoreProviderProps<T extends Transaction> extends PropsWithChildr
52
52
  }
53
53
  declare function PulsarCoreProvider<T extends Transaction>({ children, ...params }: PulsarCoreProviderProps<T>): react_jsx_runtime.JSX.Element;
54
54
 
55
- export { PulsarCoreProvider, type PulsarStore, PulsarStoreContext, useInitializeTransactionsPool, usePulsarStore };
55
+ export { PulsarCoreProvider, PulsarStoreContext, type PulsarStoreState, useInitializeTransactionsPool, usePulsarStore };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var react=require('react'),zustand=require('zustand'),pulsarCore=require('@tuwaio/pulsar-core'),jsxRuntime=require('react/jsx-runtime');var n=react.createContext(null);function f(o){let r=react.useContext(n);if(!r)throw new Error("usePulsarStore must be used within a PulsarProvider");return zustand.useStore(r,o)}var s=({initializeTransactionsPool:o,onError:r})=>{react.useEffect(()=>{(async()=>{try{await o();}catch(e){(r??(i=>console.error("Failed to initialize transactions pool:",i)))(e);}})();},[o,r]);};function F({children:o,...r}){let t=react.useRef(null);t.current||(t.current=pulsarCore.createPulsarStore({...r,name:r.name??"pulsar-store"}));let e=t.current;return s({initializeTransactionsPool:t.current.getState().initializeTransactionsPool,onError:a=>console.error("Failed to initialize transactions pool:",a)}),jsxRuntime.jsx(n.Provider,{value:e,children:o})}exports.PulsarCoreProvider=F;exports.PulsarStoreContext=n;exports.useInitializeTransactionsPool=s;exports.usePulsarStore=f;//# sourceMappingURL=index.js.map
1
+ 'use strict';var react=require('react'),zustand=require('zustand'),pulsarCore=require('@tuwaio/pulsar-core'),jsxRuntime=require('react/jsx-runtime');var a=react.createContext(null);function f(e){let r=react.useContext(a);if(!r)throw new Error("usePulsarStore must be used within a PulsarProvider");return zustand.useStore(r,e)}var s=({initializeTransactionsPool:e,onError:r})=>{react.useEffect(()=>{(async()=>{try{await e();}catch(o){(r??(i=>console.error("Failed to initialize transactions pool:",i)))(o);}})();},[e,r]);};function F({children:e,...r}){let t=react.useRef(null);t.current||(t.current=pulsarCore.createPulsarStore({...r,name:r.name??"pulsar-store"}));let o=t.current;return s({initializeTransactionsPool:t.current.getState().initializeTransactionsPool,onError:n=>console.error("Failed to initialize transactions pool:",n)}),jsxRuntime.jsx(a.Provider,{value:o,children:e})}exports.PulsarCoreProvider=F;exports.PulsarStoreContext=a;exports.useInitializeTransactionsPool=s;exports.usePulsarStore=f;//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hooks/pulsarHook.ts","../src/hooks/useInitializeTransactionsPool.tsx","../src/providers/PulsarCoreProvider.tsx"],"names":["PulsarStoreContext","createContext","usePulsarStore","selector","store","useContext","useStore","useInitializeTransactionsPool","initializeTransactionsPool","onError","useEffect","error","e","PulsarCoreProvider","children","params","storeRef","useRef","createPulsarStore","storeToProvide","jsx"],"mappings":"yJAQaA,CAAAA,CAAqBC,mBAAAA,CAAyD,IAAI,EAQxF,SAASC,CAAAA,CACdC,CAAAA,CACM,CACN,IAAMC,EAAQC,gBAAAA,CAAWL,CAAkB,CAAA,CAE3C,GAAI,CAACI,CAAAA,CACH,MAAM,IAAI,KAAA,CAAM,qDAAqD,CAAA,CAGvE,OAAOE,gBAAAA,CAASF,CAAAA,CAAyDD,CAAQ,CACnF,CCSO,IAAMI,CAAAA,CAAgC,CAAC,CAC5C,0BAAA,CAAAC,CAAAA,CACA,OAAA,CAAAC,CACF,CAAA,GAGM,CACJC,eAAAA,CAAU,IAAM,EACe,SAAY,CACvC,GAAI,CACF,MAAMF,CAAAA,GACR,CAAA,MAASG,CAAAA,CAAO,EACOF,CAAAA,GAAaG,CAAAA,EAAa,OAAA,CAAQ,KAAA,CAAM,0CAA2CA,CAAC,CAAA,CAAA,EAC5FD,CAAc,EAC7B,CACF,CAAA,IAOF,CAAA,CAAG,CAACH,CAAAA,CAA4BC,CAAO,CAAC,EAC1C,EC7CO,SAASI,CAAAA,CAA0C,CAAE,SAAAC,CAAAA,CAAU,GAAGC,CAAO,CAAA,CAA+B,CAC7G,IAAMC,CAAAA,CAAWC,YAAAA,CAAwC,IAAI,EAExDD,CAAAA,CAAS,OAAA,GACZA,CAAAA,CAAS,OAAA,CAAUE,6BAAqB,CACtC,GAAGH,CAAAA,CACH,IAAA,CAAMA,CAAAA,CAAO,IAAA,EAAQ,cACvB,CAAC,GAGH,IAAMI,CAAAA,CAAiBH,CAAAA,CAAS,OAAA,CAEhC,OAAAT,CAAAA,CAA8B,CAC5B,0BAAA,CAA4BS,CAAAA,CAAS,QAAQ,QAAA,EAAS,CAAE,0BAAA,CACxD,OAAA,CAAUL,GAAU,OAAA,CAAQ,KAAA,CAAM,yCAAA,CAA2CA,CAAK,CACpF,CAAC,CAAA,CAEMS,cAAAA,CAACpB,CAAAA,CAAmB,SAAnB,CAA4B,KAAA,CAAOmB,CAAAA,CAAiB,QAAA,CAAAL,EAAS,CACvE","file":"index.js","sourcesContent":["import { ITxTrackingStore, Transaction } from '@tuwaio/pulsar-core';\nimport { createContext, useContext } from 'react';\nimport { StoreApi, useStore } from 'zustand';\n\ntype PulsarSelector<TTransaction extends Transaction, TSelected> = (state: PulsarStore<TTransaction>) => TSelected;\n\nexport type PulsarStore<TTransaction extends Transaction> = ITxTrackingStore<TTransaction>;\n\nexport const PulsarStoreContext = createContext<StoreApi<PulsarStore<Transaction>> | null>(null);\n\nexport function usePulsarStore<TTransaction extends Transaction, TRet>(\n selector: PulsarSelector<TTransaction, TRet>,\n): TRet;\n\nexport function usePulsarStore<TRet>(selector: PulsarSelector<Transaction, TRet>): TRet;\n\nexport function usePulsarStore<TRet, TTransaction extends Transaction = Transaction>(\n selector: PulsarSelector<TTransaction, TRet>,\n): TRet {\n const store = useContext(PulsarStoreContext);\n\n if (!store) {\n throw new Error('usePulsarStore must be used within a PulsarProvider');\n }\n\n return useStore(store as unknown as StoreApi<PulsarStore<TTransaction>>, selector);\n}\n","/**\n * @file This file defines a React hook for initializing the transaction pool.\n * This hook is crucial for resuming the tracking of pending transactions after a page reload.\n */\n\nimport { useEffect } from 'react';\n\n/**\n * A React hook that triggers the initialization of the transaction pool when the component mounts.\n *\n * This should be used once in your application's layout or root component. It ensures that any\n * pending transactions from a previous session (stored in `localStorage`) are picked up and\n\n * their trackers are re-activated.\n *\n * @param {object} params - The parameters for the hook.\n * @param {() => Promise<void>} params.initializeTransactionsPool - The `initializeTransactionsPool` function from your Pulsar store instance.\n * @param {(error: Error) => void} [params.onError] - An optional custom function to handle any errors that occur during initialization. Defaults to `console.error`.\n *\n * @example\n * ```tsx\n * import { useInitializeTransactionsPool } from '@tuwaio/pulsar-react';\n * import { pulsarStore } from './path/to/your/store';\n *\n * function AppLayout({ children }) {\n * // This hook will run once when the layout mounts.\n * useInitializeTransactionsPool({\n * initializeTransactionsPool: pulsarStore.getState().initializeTransactionsPool,\n * onError: (err) => console.warn('Failed to re-initialize trackers:', err),\n * });\n *\n * return <div>{children}</div>;\n * }\n * ```\n */\nexport const useInitializeTransactionsPool = ({\n initializeTransactionsPool,\n onError,\n}: {\n initializeTransactionsPool: () => Promise<void>;\n onError?: (error: Error) => void;\n}) => {\n useEffect(() => {\n const reinitializeTrackers = async () => {\n try {\n await initializeTransactionsPool();\n } catch (error) {\n const errorHandler = onError ?? ((e: Error) => console.error('Failed to initialize transactions pool:', e));\n errorHandler(error as Error);\n }\n };\n\n // Run the initialization process.\n reinitializeTrackers();\n\n // The dependency array is empty to ensure this effect runs only once on mount.\n // The functions from a vanilla Zustand store are stable and do not need to be in the array.\n }, [initializeTransactionsPool, onError]);\n};\n","import { createPulsarStore, ITxTrackingStore, PulsarAdapter, Transaction } from '@tuwaio/pulsar-core';\nimport { PropsWithChildren, useRef } from 'react';\nimport { StoreApi } from 'zustand';\nimport { PersistOptions } from 'zustand/middleware';\n\nimport { PulsarStore, PulsarStoreContext } from '../hooks/pulsarHook';\nimport { useInitializeTransactionsPool } from '../hooks/useInitializeTransactionsPool';\n\ninterface PulsarCoreProviderProps<T extends Transaction>\n extends PropsWithChildren,\n PulsarAdapter<T>,\n Partial<PersistOptions<ITxTrackingStore<T>>> {}\n\nexport function PulsarCoreProvider<T extends Transaction>({ children, ...params }: PulsarCoreProviderProps<T>) {\n const storeRef = useRef<StoreApi<PulsarStore<T>> | null>(null);\n\n if (!storeRef.current) {\n storeRef.current = createPulsarStore<T>({\n ...params,\n name: params.name ?? 'pulsar-store',\n });\n }\n\n const storeToProvide = storeRef.current as unknown as StoreApi<PulsarStore<Transaction>>;\n\n useInitializeTransactionsPool({\n initializeTransactionsPool: storeRef.current.getState().initializeTransactionsPool,\n onError: (error) => console.error('Failed to initialize transactions pool:', error),\n });\n\n return <PulsarStoreContext.Provider value={storeToProvide}>{children}</PulsarStoreContext.Provider>;\n}\n"]}
1
+ {"version":3,"sources":["../src/hooks/pulsarHook.ts","../src/hooks/useInitializeTransactionsPool.tsx","../src/providers/PulsarCoreProvider.tsx"],"names":["PulsarStoreContext","createContext","usePulsarStore","selector","store","useContext","useStore","useInitializeTransactionsPool","initializeTransactionsPool","onError","useEffect","error","e","PulsarCoreProvider","children","params","storeRef","useRef","createPulsarStore","storeToProvide","jsx"],"mappings":"yJAOaA,CAAAA,CAAqBC,mBAAAA,CAA8D,IAAI,EAQ7F,SAASC,CAAAA,CACdC,CAAAA,CACW,CACX,IAAMC,EAAQC,gBAAAA,CAAWL,CAAkB,CAAA,CAE3C,GAAI,CAACI,CAAAA,CACH,MAAM,IAAI,KAAA,CAAM,qDAAqD,CAAA,CAGvE,OAAOE,gBAAAA,CAASF,CAAAA,CAA8DD,CAAQ,CACxF,CCUO,IAAMI,CAAAA,CAAgC,CAAC,CAC5C,0BAAA,CAAAC,CAAAA,CACA,OAAA,CAAAC,CACF,CAAA,GAGM,CACJC,eAAAA,CAAU,IAAM,EACe,SAAY,CACvC,GAAI,CACF,MAAMF,CAAAA,GACR,CAAA,MAASG,CAAAA,CAAO,EACOF,CAAAA,GAAaG,CAAAA,EAAa,OAAA,CAAQ,KAAA,CAAM,0CAA2CA,CAAC,CAAA,CAAA,EAC5FD,CAAc,EAC7B,CACF,CAAA,IAOF,CAAA,CAAG,CAACH,CAAAA,CAA4BC,CAAO,CAAC,EAC1C,EC7CO,SAASI,CAAAA,CAA0C,CAAE,SAAAC,CAAAA,CAAU,GAAGC,CAAO,CAAA,CAA+B,CAC7G,IAAMC,CAAAA,CAAWC,YAAAA,CAA6C,IAAI,EAE7DD,CAAAA,CAAS,OAAA,GACZA,CAAAA,CAAS,OAAA,CAAUE,6BAAqB,CACtC,GAAGH,CAAAA,CACH,IAAA,CAAMA,CAAAA,CAAO,IAAA,EAAQ,cACvB,CAAC,GAGH,IAAMI,CAAAA,CAAiBH,CAAAA,CAAS,OAAA,CAEhC,OAAAT,CAAAA,CAA8B,CAC5B,0BAAA,CAA4BS,CAAAA,CAAS,QAAQ,QAAA,EAAS,CAAE,0BAAA,CACxD,OAAA,CAAUL,GAAU,OAAA,CAAQ,KAAA,CAAM,yCAAA,CAA2CA,CAAK,CACpF,CAAC,CAAA,CAEMS,cAAAA,CAACpB,CAAAA,CAAmB,SAAnB,CAA4B,KAAA,CAAOmB,CAAAA,CAAiB,QAAA,CAAAL,EAAS,CACvE","file":"index.js","sourcesContent":["import { ITxTrackingStore, Transaction } from '@tuwaio/pulsar-core';\nimport { createContext, useContext } from 'react';\nimport { StoreApi, useStore } from 'zustand';\n\nexport type PulsarStoreState<TTransaction extends Transaction> = ITxTrackingStore<TTransaction>;\ntype PulsarSelector<TTransaction extends Transaction, TSelected> = (state: PulsarStoreState<TTransaction>) => TSelected;\n\nexport const PulsarStoreContext = createContext<StoreApi<PulsarStoreState<Transaction>> | null>(null);\n\nexport function usePulsarStore<TTransaction extends Transaction, TRet>(\n selector: PulsarSelector<TTransaction, TRet>,\n): TRet;\n\nexport function usePulsarStore<TSelected>(selector: PulsarSelector<Transaction, TSelected>): TSelected;\n\nexport function usePulsarStore<TSelected, TTransaction extends Transaction = Transaction>(\n selector: PulsarSelector<TTransaction, TSelected>,\n): TSelected {\n const store = useContext(PulsarStoreContext);\n\n if (!store) {\n throw new Error('usePulsarStore must be used within a PulsarProvider');\n }\n\n return useStore(store as unknown as StoreApi<PulsarStoreState<TTransaction>>, selector);\n}\n","/**\n * @file This file defines a React hook for initializing the transaction pool.\n * This hook is crucial for resuming the tracking of pending transactions after a page reload.\n */\n\nimport { useEffect } from 'react';\n\n/**\n * A React hook that triggers the initialization of the transaction pool when the component mounts.\n *\n * This should be used once in your application's layout or root component. It ensures that any\n * pending transactions from a previous session (stored in `localStorage`) are picked up and\n\n * their trackers are re-activated.\n *\n * @param {object} params - The parameters for the hook.\n * @param {() => Promise<void>} params.initializeTransactionsPool - The `initializeTransactionsPool` function from your Pulsar store instance.\n * @param {(error: Error) => void} [params.onError] - An optional custom function to handle any errors that occur during initialization. Defaults to `console.error`.\n *\n * @example\n * ```tsx\n * import { useInitializeTransactionsPool } from '@tuwaio/pulsar-react';\n * import { pulsarStore } from './path/to/your/store';\n *\n * function AppLayout({ children }) {\n * // This hook will run once when the layout mounts.\n * useInitializeTransactionsPool({\n * initializeTransactionsPool: pulsarStore.getState().initializeTransactionsPool,\n * onError: (err) => console.warn('Failed to re-initialize trackers:', err),\n * });\n *\n * return <div>{children}</div>;\n * }\n * ```\n */\nexport const useInitializeTransactionsPool = ({\n initializeTransactionsPool,\n onError,\n}: {\n initializeTransactionsPool: () => Promise<void>;\n onError?: (error: Error) => void;\n}) => {\n useEffect(() => {\n const reinitializeTrackers = async () => {\n try {\n await initializeTransactionsPool();\n } catch (error) {\n const errorHandler = onError ?? ((e: Error) => console.error('Failed to initialize transactions pool:', e));\n errorHandler(error as Error);\n }\n };\n\n // Run the initialization process.\n reinitializeTrackers();\n\n // The dependency array is empty to ensure this effect runs only once on mount.\n // The functions from a vanilla Zustand store are stable and do not need to be in the array.\n }, [initializeTransactionsPool, onError]);\n};\n","import { createPulsarStore, ITxTrackingStore, PulsarAdapter, Transaction } from '@tuwaio/pulsar-core';\nimport { PropsWithChildren, useRef } from 'react';\nimport { StoreApi } from 'zustand';\nimport { PersistOptions } from 'zustand/middleware';\n\nimport { PulsarStoreContext, PulsarStoreState } from '../hooks/pulsarHook';\nimport { useInitializeTransactionsPool } from '../hooks/useInitializeTransactionsPool';\n\ninterface PulsarCoreProviderProps<T extends Transaction>\n extends PropsWithChildren,\n PulsarAdapter<T>,\n Partial<PersistOptions<ITxTrackingStore<T>>> {}\n\nexport function PulsarCoreProvider<T extends Transaction>({ children, ...params }: PulsarCoreProviderProps<T>) {\n const storeRef = useRef<StoreApi<PulsarStoreState<T>> | null>(null);\n\n if (!storeRef.current) {\n storeRef.current = createPulsarStore<T>({\n ...params,\n name: params.name ?? 'pulsar-store',\n });\n }\n\n const storeToProvide = storeRef.current as unknown as StoreApi<PulsarStoreState<Transaction>>;\n\n useInitializeTransactionsPool({\n initializeTransactionsPool: storeRef.current.getState().initializeTransactionsPool,\n onError: (error) => console.error('Failed to initialize transactions pool:', error),\n });\n\n return <PulsarStoreContext.Provider value={storeToProvide}>{children}</PulsarStoreContext.Provider>;\n}\n"]}
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import {createContext,useContext,useEffect,useRef}from'react';import {useStore}from'zustand';import {createPulsarStore}from'@tuwaio/pulsar-core';import {jsx}from'react/jsx-runtime';var n=createContext(null);function f(o){let r=useContext(n);if(!r)throw new Error("usePulsarStore must be used within a PulsarProvider");return useStore(r,o)}var s=({initializeTransactionsPool:o,onError:r})=>{useEffect(()=>{(async()=>{try{await o();}catch(e){(r??(i=>console.error("Failed to initialize transactions pool:",i)))(e);}})();},[o,r]);};function F({children:o,...r}){let t=useRef(null);t.current||(t.current=createPulsarStore({...r,name:r.name??"pulsar-store"}));let e=t.current;return s({initializeTransactionsPool:t.current.getState().initializeTransactionsPool,onError:a=>console.error("Failed to initialize transactions pool:",a)}),jsx(n.Provider,{value:e,children:o})}export{F as PulsarCoreProvider,n as PulsarStoreContext,s as useInitializeTransactionsPool,f as usePulsarStore};//# sourceMappingURL=index.mjs.map
1
+ import {createContext,useContext,useEffect,useRef}from'react';import {useStore}from'zustand';import {createPulsarStore}from'@tuwaio/pulsar-core';import {jsx}from'react/jsx-runtime';var a=createContext(null);function f(e){let r=useContext(a);if(!r)throw new Error("usePulsarStore must be used within a PulsarProvider");return useStore(r,e)}var s=({initializeTransactionsPool:e,onError:r})=>{useEffect(()=>{(async()=>{try{await e();}catch(o){(r??(i=>console.error("Failed to initialize transactions pool:",i)))(o);}})();},[e,r]);};function F({children:e,...r}){let t=useRef(null);t.current||(t.current=createPulsarStore({...r,name:r.name??"pulsar-store"}));let o=t.current;return s({initializeTransactionsPool:t.current.getState().initializeTransactionsPool,onError:n=>console.error("Failed to initialize transactions pool:",n)}),jsx(a.Provider,{value:o,children:e})}export{F as PulsarCoreProvider,a as PulsarStoreContext,s as useInitializeTransactionsPool,f as usePulsarStore};//# sourceMappingURL=index.mjs.map
2
2
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hooks/pulsarHook.ts","../src/hooks/useInitializeTransactionsPool.tsx","../src/providers/PulsarCoreProvider.tsx"],"names":["PulsarStoreContext","createContext","usePulsarStore","selector","store","useContext","useStore","useInitializeTransactionsPool","initializeTransactionsPool","onError","useEffect","error","e","PulsarCoreProvider","children","params","storeRef","useRef","createPulsarStore","storeToProvide","jsx"],"mappings":"yLAQaA,CAAAA,CAAqBC,aAAAA,CAAyD,IAAI,EAQxF,SAASC,CAAAA,CACdC,CAAAA,CACM,CACN,IAAMC,EAAQC,UAAAA,CAAWL,CAAkB,CAAA,CAE3C,GAAI,CAACI,CAAAA,CACH,MAAM,IAAI,KAAA,CAAM,qDAAqD,CAAA,CAGvE,OAAOE,QAAAA,CAASF,CAAAA,CAAyDD,CAAQ,CACnF,CCSO,IAAMI,CAAAA,CAAgC,CAAC,CAC5C,0BAAA,CAAAC,CAAAA,CACA,OAAA,CAAAC,CACF,CAAA,GAGM,CACJC,SAAAA,CAAU,IAAM,EACe,SAAY,CACvC,GAAI,CACF,MAAMF,CAAAA,GACR,CAAA,MAASG,CAAAA,CAAO,EACOF,CAAAA,GAAaG,CAAAA,EAAa,OAAA,CAAQ,KAAA,CAAM,0CAA2CA,CAAC,CAAA,CAAA,EAC5FD,CAAc,EAC7B,CACF,CAAA,IAOF,CAAA,CAAG,CAACH,CAAAA,CAA4BC,CAAO,CAAC,EAC1C,EC7CO,SAASI,CAAAA,CAA0C,CAAE,SAAAC,CAAAA,CAAU,GAAGC,CAAO,CAAA,CAA+B,CAC7G,IAAMC,CAAAA,CAAWC,MAAAA,CAAwC,IAAI,EAExDD,CAAAA,CAAS,OAAA,GACZA,CAAAA,CAAS,OAAA,CAAUE,kBAAqB,CACtC,GAAGH,CAAAA,CACH,IAAA,CAAMA,CAAAA,CAAO,IAAA,EAAQ,cACvB,CAAC,GAGH,IAAMI,CAAAA,CAAiBH,CAAAA,CAAS,OAAA,CAEhC,OAAAT,CAAAA,CAA8B,CAC5B,0BAAA,CAA4BS,CAAAA,CAAS,QAAQ,QAAA,EAAS,CAAE,0BAAA,CACxD,OAAA,CAAUL,GAAU,OAAA,CAAQ,KAAA,CAAM,yCAAA,CAA2CA,CAAK,CACpF,CAAC,CAAA,CAEMS,GAAAA,CAACpB,CAAAA,CAAmB,SAAnB,CAA4B,KAAA,CAAOmB,CAAAA,CAAiB,QAAA,CAAAL,EAAS,CACvE","file":"index.mjs","sourcesContent":["import { ITxTrackingStore, Transaction } from '@tuwaio/pulsar-core';\nimport { createContext, useContext } from 'react';\nimport { StoreApi, useStore } from 'zustand';\n\ntype PulsarSelector<TTransaction extends Transaction, TSelected> = (state: PulsarStore<TTransaction>) => TSelected;\n\nexport type PulsarStore<TTransaction extends Transaction> = ITxTrackingStore<TTransaction>;\n\nexport const PulsarStoreContext = createContext<StoreApi<PulsarStore<Transaction>> | null>(null);\n\nexport function usePulsarStore<TTransaction extends Transaction, TRet>(\n selector: PulsarSelector<TTransaction, TRet>,\n): TRet;\n\nexport function usePulsarStore<TRet>(selector: PulsarSelector<Transaction, TRet>): TRet;\n\nexport function usePulsarStore<TRet, TTransaction extends Transaction = Transaction>(\n selector: PulsarSelector<TTransaction, TRet>,\n): TRet {\n const store = useContext(PulsarStoreContext);\n\n if (!store) {\n throw new Error('usePulsarStore must be used within a PulsarProvider');\n }\n\n return useStore(store as unknown as StoreApi<PulsarStore<TTransaction>>, selector);\n}\n","/**\n * @file This file defines a React hook for initializing the transaction pool.\n * This hook is crucial for resuming the tracking of pending transactions after a page reload.\n */\n\nimport { useEffect } from 'react';\n\n/**\n * A React hook that triggers the initialization of the transaction pool when the component mounts.\n *\n * This should be used once in your application's layout or root component. It ensures that any\n * pending transactions from a previous session (stored in `localStorage`) are picked up and\n\n * their trackers are re-activated.\n *\n * @param {object} params - The parameters for the hook.\n * @param {() => Promise<void>} params.initializeTransactionsPool - The `initializeTransactionsPool` function from your Pulsar store instance.\n * @param {(error: Error) => void} [params.onError] - An optional custom function to handle any errors that occur during initialization. Defaults to `console.error`.\n *\n * @example\n * ```tsx\n * import { useInitializeTransactionsPool } from '@tuwaio/pulsar-react';\n * import { pulsarStore } from './path/to/your/store';\n *\n * function AppLayout({ children }) {\n * // This hook will run once when the layout mounts.\n * useInitializeTransactionsPool({\n * initializeTransactionsPool: pulsarStore.getState().initializeTransactionsPool,\n * onError: (err) => console.warn('Failed to re-initialize trackers:', err),\n * });\n *\n * return <div>{children}</div>;\n * }\n * ```\n */\nexport const useInitializeTransactionsPool = ({\n initializeTransactionsPool,\n onError,\n}: {\n initializeTransactionsPool: () => Promise<void>;\n onError?: (error: Error) => void;\n}) => {\n useEffect(() => {\n const reinitializeTrackers = async () => {\n try {\n await initializeTransactionsPool();\n } catch (error) {\n const errorHandler = onError ?? ((e: Error) => console.error('Failed to initialize transactions pool:', e));\n errorHandler(error as Error);\n }\n };\n\n // Run the initialization process.\n reinitializeTrackers();\n\n // The dependency array is empty to ensure this effect runs only once on mount.\n // The functions from a vanilla Zustand store are stable and do not need to be in the array.\n }, [initializeTransactionsPool, onError]);\n};\n","import { createPulsarStore, ITxTrackingStore, PulsarAdapter, Transaction } from '@tuwaio/pulsar-core';\nimport { PropsWithChildren, useRef } from 'react';\nimport { StoreApi } from 'zustand';\nimport { PersistOptions } from 'zustand/middleware';\n\nimport { PulsarStore, PulsarStoreContext } from '../hooks/pulsarHook';\nimport { useInitializeTransactionsPool } from '../hooks/useInitializeTransactionsPool';\n\ninterface PulsarCoreProviderProps<T extends Transaction>\n extends PropsWithChildren,\n PulsarAdapter<T>,\n Partial<PersistOptions<ITxTrackingStore<T>>> {}\n\nexport function PulsarCoreProvider<T extends Transaction>({ children, ...params }: PulsarCoreProviderProps<T>) {\n const storeRef = useRef<StoreApi<PulsarStore<T>> | null>(null);\n\n if (!storeRef.current) {\n storeRef.current = createPulsarStore<T>({\n ...params,\n name: params.name ?? 'pulsar-store',\n });\n }\n\n const storeToProvide = storeRef.current as unknown as StoreApi<PulsarStore<Transaction>>;\n\n useInitializeTransactionsPool({\n initializeTransactionsPool: storeRef.current.getState().initializeTransactionsPool,\n onError: (error) => console.error('Failed to initialize transactions pool:', error),\n });\n\n return <PulsarStoreContext.Provider value={storeToProvide}>{children}</PulsarStoreContext.Provider>;\n}\n"]}
1
+ {"version":3,"sources":["../src/hooks/pulsarHook.ts","../src/hooks/useInitializeTransactionsPool.tsx","../src/providers/PulsarCoreProvider.tsx"],"names":["PulsarStoreContext","createContext","usePulsarStore","selector","store","useContext","useStore","useInitializeTransactionsPool","initializeTransactionsPool","onError","useEffect","error","e","PulsarCoreProvider","children","params","storeRef","useRef","createPulsarStore","storeToProvide","jsx"],"mappings":"yLAOaA,CAAAA,CAAqBC,aAAAA,CAA8D,IAAI,EAQ7F,SAASC,CAAAA,CACdC,CAAAA,CACW,CACX,IAAMC,EAAQC,UAAAA,CAAWL,CAAkB,CAAA,CAE3C,GAAI,CAACI,CAAAA,CACH,MAAM,IAAI,KAAA,CAAM,qDAAqD,CAAA,CAGvE,OAAOE,QAAAA,CAASF,CAAAA,CAA8DD,CAAQ,CACxF,CCUO,IAAMI,CAAAA,CAAgC,CAAC,CAC5C,0BAAA,CAAAC,CAAAA,CACA,OAAA,CAAAC,CACF,CAAA,GAGM,CACJC,SAAAA,CAAU,IAAM,EACe,SAAY,CACvC,GAAI,CACF,MAAMF,CAAAA,GACR,CAAA,MAASG,CAAAA,CAAO,EACOF,CAAAA,GAAaG,CAAAA,EAAa,OAAA,CAAQ,KAAA,CAAM,0CAA2CA,CAAC,CAAA,CAAA,EAC5FD,CAAc,EAC7B,CACF,CAAA,IAOF,CAAA,CAAG,CAACH,CAAAA,CAA4BC,CAAO,CAAC,EAC1C,EC7CO,SAASI,CAAAA,CAA0C,CAAE,SAAAC,CAAAA,CAAU,GAAGC,CAAO,CAAA,CAA+B,CAC7G,IAAMC,CAAAA,CAAWC,MAAAA,CAA6C,IAAI,EAE7DD,CAAAA,CAAS,OAAA,GACZA,CAAAA,CAAS,OAAA,CAAUE,kBAAqB,CACtC,GAAGH,CAAAA,CACH,IAAA,CAAMA,CAAAA,CAAO,IAAA,EAAQ,cACvB,CAAC,GAGH,IAAMI,CAAAA,CAAiBH,CAAAA,CAAS,OAAA,CAEhC,OAAAT,CAAAA,CAA8B,CAC5B,0BAAA,CAA4BS,CAAAA,CAAS,QAAQ,QAAA,EAAS,CAAE,0BAAA,CACxD,OAAA,CAAUL,GAAU,OAAA,CAAQ,KAAA,CAAM,yCAAA,CAA2CA,CAAK,CACpF,CAAC,CAAA,CAEMS,GAAAA,CAACpB,CAAAA,CAAmB,SAAnB,CAA4B,KAAA,CAAOmB,CAAAA,CAAiB,QAAA,CAAAL,EAAS,CACvE","file":"index.mjs","sourcesContent":["import { ITxTrackingStore, Transaction } from '@tuwaio/pulsar-core';\nimport { createContext, useContext } from 'react';\nimport { StoreApi, useStore } from 'zustand';\n\nexport type PulsarStoreState<TTransaction extends Transaction> = ITxTrackingStore<TTransaction>;\ntype PulsarSelector<TTransaction extends Transaction, TSelected> = (state: PulsarStoreState<TTransaction>) => TSelected;\n\nexport const PulsarStoreContext = createContext<StoreApi<PulsarStoreState<Transaction>> | null>(null);\n\nexport function usePulsarStore<TTransaction extends Transaction, TRet>(\n selector: PulsarSelector<TTransaction, TRet>,\n): TRet;\n\nexport function usePulsarStore<TSelected>(selector: PulsarSelector<Transaction, TSelected>): TSelected;\n\nexport function usePulsarStore<TSelected, TTransaction extends Transaction = Transaction>(\n selector: PulsarSelector<TTransaction, TSelected>,\n): TSelected {\n const store = useContext(PulsarStoreContext);\n\n if (!store) {\n throw new Error('usePulsarStore must be used within a PulsarProvider');\n }\n\n return useStore(store as unknown as StoreApi<PulsarStoreState<TTransaction>>, selector);\n}\n","/**\n * @file This file defines a React hook for initializing the transaction pool.\n * This hook is crucial for resuming the tracking of pending transactions after a page reload.\n */\n\nimport { useEffect } from 'react';\n\n/**\n * A React hook that triggers the initialization of the transaction pool when the component mounts.\n *\n * This should be used once in your application's layout or root component. It ensures that any\n * pending transactions from a previous session (stored in `localStorage`) are picked up and\n\n * their trackers are re-activated.\n *\n * @param {object} params - The parameters for the hook.\n * @param {() => Promise<void>} params.initializeTransactionsPool - The `initializeTransactionsPool` function from your Pulsar store instance.\n * @param {(error: Error) => void} [params.onError] - An optional custom function to handle any errors that occur during initialization. Defaults to `console.error`.\n *\n * @example\n * ```tsx\n * import { useInitializeTransactionsPool } from '@tuwaio/pulsar-react';\n * import { pulsarStore } from './path/to/your/store';\n *\n * function AppLayout({ children }) {\n * // This hook will run once when the layout mounts.\n * useInitializeTransactionsPool({\n * initializeTransactionsPool: pulsarStore.getState().initializeTransactionsPool,\n * onError: (err) => console.warn('Failed to re-initialize trackers:', err),\n * });\n *\n * return <div>{children}</div>;\n * }\n * ```\n */\nexport const useInitializeTransactionsPool = ({\n initializeTransactionsPool,\n onError,\n}: {\n initializeTransactionsPool: () => Promise<void>;\n onError?: (error: Error) => void;\n}) => {\n useEffect(() => {\n const reinitializeTrackers = async () => {\n try {\n await initializeTransactionsPool();\n } catch (error) {\n const errorHandler = onError ?? ((e: Error) => console.error('Failed to initialize transactions pool:', e));\n errorHandler(error as Error);\n }\n };\n\n // Run the initialization process.\n reinitializeTrackers();\n\n // The dependency array is empty to ensure this effect runs only once on mount.\n // The functions from a vanilla Zustand store are stable and do not need to be in the array.\n }, [initializeTransactionsPool, onError]);\n};\n","import { createPulsarStore, ITxTrackingStore, PulsarAdapter, Transaction } from '@tuwaio/pulsar-core';\nimport { PropsWithChildren, useRef } from 'react';\nimport { StoreApi } from 'zustand';\nimport { PersistOptions } from 'zustand/middleware';\n\nimport { PulsarStoreContext, PulsarStoreState } from '../hooks/pulsarHook';\nimport { useInitializeTransactionsPool } from '../hooks/useInitializeTransactionsPool';\n\ninterface PulsarCoreProviderProps<T extends Transaction>\n extends PropsWithChildren,\n PulsarAdapter<T>,\n Partial<PersistOptions<ITxTrackingStore<T>>> {}\n\nexport function PulsarCoreProvider<T extends Transaction>({ children, ...params }: PulsarCoreProviderProps<T>) {\n const storeRef = useRef<StoreApi<PulsarStoreState<T>> | null>(null);\n\n if (!storeRef.current) {\n storeRef.current = createPulsarStore<T>({\n ...params,\n name: params.name ?? 'pulsar-store',\n });\n }\n\n const storeToProvide = storeRef.current as unknown as StoreApi<PulsarStoreState<Transaction>>;\n\n useInitializeTransactionsPool({\n initializeTransactionsPool: storeRef.current.getState().initializeTransactionsPool,\n onError: (error) => console.error('Failed to initialize transactions pool:', error),\n });\n\n return <PulsarStoreContext.Provider value={storeToProvide}>{children}</PulsarStoreContext.Provider>;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuwaio/pulsar-react",
3
- "version": "1.0.0-fix-orbit-integration-alpha.5.7bdc032",
3
+ "version": "1.0.0-fix-orbit-integration-alpha.6.76dee15",
4
4
  "private": false,
5
5
  "author": "Oleksandr Tkach",
6
6
  "license": "Apache-2.0",
@@ -54,7 +54,7 @@
54
54
  "tsup": "^8.5.0",
55
55
  "typescript": "^5.9.2",
56
56
  "zustand": "^5.0.8",
57
- "@tuwaio/pulsar-core": "^1.0.0-fix-orbit-integration-alpha.5.7bdc032"
57
+ "@tuwaio/pulsar-core": "^1.0.0-fix-orbit-integration-alpha.6.76dee15"
58
58
  },
59
59
  "scripts": {
60
60
  "start": "tsup src/index.ts --watch",