@tuwaio/pulsar-react 0.3.2 → 0.4.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/dist/index.d.mts CHANGED
@@ -1,38 +1,48 @@
1
1
  /**
2
- * @file This file defines a React hook for initializing the transaction pool.
3
- * This hook is crucial for resuming the tracking of pending transactions after a page reload.
2
+ * @file React hook for bootstrapping the Pulsar transaction lifecycle on app start.
3
+ * It rehydrates pending transaction trackers and can optionally perform an initial
4
+ * remote history fetch right after tracker initialization.
4
5
  */
5
6
  /**
6
- * A React hook that triggers the initialization of the transaction pool when the component mounts.
7
+ * Configuration for {@link useInitializeTransactionsPool}.
8
+ */
9
+ type UseInitializeTransactionsPoolParams = {
10
+ /**
11
+ * Re-initializes background trackers for all pending transactions stored in the Pulsar store.
12
+ */
13
+ initializeTransactionsPool: () => Promise<void>;
14
+ /**
15
+ * Optional error handler called when initialization or the optional initial fetch fails.
16
+ *
17
+ * @defaultValue `console.error`
18
+ */
19
+ onError?: (error: Error) => void;
20
+ };
21
+ /**
22
+ * Re-initializes pending transaction trackers when the component mounts.
7
23
  *
8
- * This should be used once in your application's layout or root component. It ensures that any
9
- * pending transactions from a previous session (stored in `localStorage`) are picked up and
10
-
11
- * their trackers are re-activated.
24
+ * Use this hook once in your application's root layout or top-level provider.
25
+ * It restores tracker activity after reloads and can optionally fetch the initial
26
+ * remote transaction history right after restoration.
12
27
  *
13
- * @param {object} params - The parameters for the hook.
14
- * @param {() => Promise<void>} params.initializeTransactionsPool - The `initializeTransactionsPool` function from your Pulsar store instance.
15
- * @param {(error: Error) => void} [params.onError] - An optional custom function to handle any errors that occur during initialization. Defaults to `console.error`.
28
+ * @param params Hook configuration.
29
+ * @param params.initializeTransactionsPool Function that restores trackers for pending transactions.
30
+ * @param params.onError Optional custom error handler.
16
31
  *
17
32
  * @example
18
33
  * ```tsx
19
34
  * import { useInitializeTransactionsPool } from '@tuwaio/pulsar-react';
20
- * import { pulsarStore } from './path/to/your/store';
21
35
  *
22
- * function AppLayout({ children }) {
23
- * // This hook will run once when the layout mounts.
24
- * useInitializeTransactionsPool({
25
- * initializeTransactionsPool: pulsarStore.getState().initializeTransactionsPool,
26
- * onError: (err) => console.warn('Failed to re-initialize trackers:', err),
27
- * });
36
+ * function AppLayout() {
37
+ * useInitializeTransactionsPool({
38
+ * initializeTransactionsPool: store.getState().initializeTransactionsPool,
39
+ * onError: (error) => console.warn('Failed to restore transactions:', error),
40
+ * });
28
41
  *
29
- * return <div>{children}</div>;
42
+ * return <div>...</div>;
30
43
  * }
31
44
  * ```
32
45
  */
33
- declare const useInitializeTransactionsPool: ({ initializeTransactionsPool, onError, }: {
34
- initializeTransactionsPool: () => Promise<void>;
35
- onError?: (error: Error) => void;
36
- }) => void;
46
+ declare const useInitializeTransactionsPool: ({ initializeTransactionsPool, onError, }: UseInitializeTransactionsPoolParams) => void;
37
47
 
38
- export { useInitializeTransactionsPool };
48
+ export { type UseInitializeTransactionsPoolParams, useInitializeTransactionsPool };
package/dist/index.d.ts CHANGED
@@ -1,38 +1,48 @@
1
1
  /**
2
- * @file This file defines a React hook for initializing the transaction pool.
3
- * This hook is crucial for resuming the tracking of pending transactions after a page reload.
2
+ * @file React hook for bootstrapping the Pulsar transaction lifecycle on app start.
3
+ * It rehydrates pending transaction trackers and can optionally perform an initial
4
+ * remote history fetch right after tracker initialization.
4
5
  */
5
6
  /**
6
- * A React hook that triggers the initialization of the transaction pool when the component mounts.
7
+ * Configuration for {@link useInitializeTransactionsPool}.
8
+ */
9
+ type UseInitializeTransactionsPoolParams = {
10
+ /**
11
+ * Re-initializes background trackers for all pending transactions stored in the Pulsar store.
12
+ */
13
+ initializeTransactionsPool: () => Promise<void>;
14
+ /**
15
+ * Optional error handler called when initialization or the optional initial fetch fails.
16
+ *
17
+ * @defaultValue `console.error`
18
+ */
19
+ onError?: (error: Error) => void;
20
+ };
21
+ /**
22
+ * Re-initializes pending transaction trackers when the component mounts.
7
23
  *
8
- * This should be used once in your application's layout or root component. It ensures that any
9
- * pending transactions from a previous session (stored in `localStorage`) are picked up and
10
-
11
- * their trackers are re-activated.
24
+ * Use this hook once in your application's root layout or top-level provider.
25
+ * It restores tracker activity after reloads and can optionally fetch the initial
26
+ * remote transaction history right after restoration.
12
27
  *
13
- * @param {object} params - The parameters for the hook.
14
- * @param {() => Promise<void>} params.initializeTransactionsPool - The `initializeTransactionsPool` function from your Pulsar store instance.
15
- * @param {(error: Error) => void} [params.onError] - An optional custom function to handle any errors that occur during initialization. Defaults to `console.error`.
28
+ * @param params Hook configuration.
29
+ * @param params.initializeTransactionsPool Function that restores trackers for pending transactions.
30
+ * @param params.onError Optional custom error handler.
16
31
  *
17
32
  * @example
18
33
  * ```tsx
19
34
  * import { useInitializeTransactionsPool } from '@tuwaio/pulsar-react';
20
- * import { pulsarStore } from './path/to/your/store';
21
35
  *
22
- * function AppLayout({ children }) {
23
- * // This hook will run once when the layout mounts.
24
- * useInitializeTransactionsPool({
25
- * initializeTransactionsPool: pulsarStore.getState().initializeTransactionsPool,
26
- * onError: (err) => console.warn('Failed to re-initialize trackers:', err),
27
- * });
36
+ * function AppLayout() {
37
+ * useInitializeTransactionsPool({
38
+ * initializeTransactionsPool: store.getState().initializeTransactionsPool,
39
+ * onError: (error) => console.warn('Failed to restore transactions:', error),
40
+ * });
28
41
  *
29
- * return <div>{children}</div>;
42
+ * return <div>...</div>;
30
43
  * }
31
44
  * ```
32
45
  */
33
- declare const useInitializeTransactionsPool: ({ initializeTransactionsPool, onError, }: {
34
- initializeTransactionsPool: () => Promise<void>;
35
- onError?: (error: Error) => void;
36
- }) => void;
46
+ declare const useInitializeTransactionsPool: ({ initializeTransactionsPool, onError, }: UseInitializeTransactionsPoolParams) => void;
37
47
 
38
- export { useInitializeTransactionsPool };
48
+ export { type UseInitializeTransactionsPoolParams, useInitializeTransactionsPool };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var react=require('react');var c=({initializeTransactionsPool:r,onError:o})=>{react.useEffect(()=>{(async()=>{try{await r();}catch(e){(o??(i=>console.error("Failed to initialize transactions pool:",i)))(e);}})();},[r,o]);};exports.useInitializeTransactionsPool=c;
1
+ 'use strict';var react=require('react');var c=({initializeTransactionsPool:r,onError:o})=>{react.useEffect(()=>{let i=true;return (async()=>{try{if(await r(),!i)return}catch(a){(o??(t=>{console.error("[Pulsar] Failed to initialize transactions pool:",t);}))(a);}})(),()=>{i=false;}},[r,o]);};exports.useInitializeTransactionsPool=c;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import {useEffect}from'react';var c=({initializeTransactionsPool:r,onError:o})=>{useEffect(()=>{(async()=>{try{await r();}catch(e){(o??(i=>console.error("Failed to initialize transactions pool:",i)))(e);}})();},[r,o]);};export{c as useInitializeTransactionsPool};
1
+ import {useEffect}from'react';var c=({initializeTransactionsPool:r,onError:o})=>{useEffect(()=>{let i=true;return (async()=>{try{if(await r(),!i)return}catch(a){(o??(t=>{console.error("[Pulsar] Failed to initialize transactions pool:",t);}))(a);}})(),()=>{i=false;}},[r,o]);};export{c as useInitializeTransactionsPool};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tuwaio/pulsar-react",
3
- "version": "0.3.2",
3
+ "version": "0.4.1",
4
4
  "private": false,
5
5
  "author": "Oleksandr Tkach",
6
6
  "license": "Apache-2.0",
@@ -42,9 +42,9 @@
42
42
  },
43
43
  "devDependencies": {
44
44
  "@types/react": "^19.2.14",
45
- "react": "^19.2.4",
45
+ "react": "^19.2.6",
46
46
  "tsup": "^8.5.1",
47
- "typescript": "^5.9.3"
47
+ "typescript": "^6.0.3"
48
48
  },
49
49
  "scripts": {
50
50
  "start": "tsup src/index.ts --watch",